summaryrefslogtreecommitdiff
path: root/MdePkg/Library/UefiUsbLib
diff options
context:
space:
mode:
authorlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>2007-07-03 09:57:29 +0000
committerlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>2007-07-03 09:57:29 +0000
commit7bc232b2072cac6adf3f6d1ad0c09bbb506422bb (patch)
tree3f0a1138378b58af35445363ae4112e927443904 /MdePkg/Library/UefiUsbLib
parentfc26ff846e59de96bb75f394e390822d9d7e0464 (diff)
downloadedk2-platforms-7bc232b2072cac6adf3f6d1ad0c09bbb506422bb.tar.xz
Add BaseCustomDecompressLibNull, DxeDebugLibSerialPort and UefiUsbLib library instance into MdePkg.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@3004 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdePkg/Library/UefiUsbLib')
-rw-r--r--MdePkg/Library/UefiUsbLib/CommonHeader.h29
-rw-r--r--MdePkg/Library/UefiUsbLib/UefiUsbLib.inf71
-rw-r--r--MdePkg/Library/UefiUsbLib/UefiUsbLib.msa44
-rw-r--r--MdePkg/Library/UefiUsbLib/UsbDxeLib.c704
-rw-r--r--MdePkg/Library/UefiUsbLib/hid.c464
5 files changed, 1312 insertions, 0 deletions
diff --git a/MdePkg/Library/UefiUsbLib/CommonHeader.h b/MdePkg/Library/UefiUsbLib/CommonHeader.h
new file mode 100644
index 0000000000..83a6a4301f
--- /dev/null
+++ b/MdePkg/Library/UefiUsbLib/CommonHeader.h
@@ -0,0 +1,29 @@
+/**@file
+ Common header file shared by all source files.
+
+ This file includes package header files, library classes and protocol, PPI & GUID definitions.
+
+ Copyright (c) 2006, Intel Corporation.
+ All rights reserved. This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+
+#ifndef __COMMON_HEADER_H_
+#define __COMMON_HEADER_H_
+
+
+//
+// The package level header files this module uses
+//
+#include <PiDxe.h>
+//
+// The Library classes this module consumes
+//
+#include <Library/UsbLib.h>
+#include <Library/BaseMemoryLib.h>
+
+#endif
diff --git a/MdePkg/Library/UefiUsbLib/UefiUsbLib.inf b/MdePkg/Library/UefiUsbLib/UefiUsbLib.inf
new file mode 100644
index 0000000000..e0c46aeb59
--- /dev/null
+++ b/MdePkg/Library/UefiUsbLib/UefiUsbLib.inf
@@ -0,0 +1,71 @@
+#/** @file
+# Component description file for UefiUsb library.
+#
+# This library provides supports for common USB functions.
+# Copyright (c) 2006, Intel Corporation.
+#
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+#**/
+
+################################################################################
+#
+# Defines Section - statements that will be processed to create a Makefile.
+#
+################################################################################
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = UefiUsbLib
+ FILE_GUID = 87eb5df9-722a-4241-ad7f-370d0b3a56d7
+ MODULE_TYPE = UEFI_DRIVER
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = UsbLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+################################################################################
+#
+# Sources Section - list of files that are required for the build to succeed.
+#
+################################################################################
+
+[Sources.common]
+ hid.c
+ UsbDxeLib.c
+ CommonHeader.h
+
+
+################################################################################
+#
+# Package Dependency Section - list of Package files that are required for
+# this module.
+#
+################################################################################
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+
+################################################################################
+#
+# Library Class Section - list of Library Classes that are required for
+# this module.
+#
+################################################################################
+
+[LibraryClasses]
+ BaseMemoryLib
+
diff --git a/MdePkg/Library/UefiUsbLib/UefiUsbLib.msa b/MdePkg/Library/UefiUsbLib/UefiUsbLib.msa
new file mode 100644
index 0000000000..d552426156
--- /dev/null
+++ b/MdePkg/Library/UefiUsbLib/UefiUsbLib.msa
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <MsaHeader>
+ <ModuleName>UefiUsbLib</ModuleName>
+ <ModuleType>DXE_DRIVER</ModuleType>
+ <GuidValue>87eb5df9-722a-4241-ad7f-370d0b3a56d7</GuidValue>
+ <Version>1.0</Version>
+ <Abstract>Component description file for UsbDxeLib module</Abstract>
+ <Description>This library provides supports for common USB functions.</Description>
+ <Copyright>Copyright (c) 2006, Intel Corporation.</Copyright>
+ <License>All rights reserved. This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>
+ <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052</Specification>
+ </MsaHeader>
+ <ModuleDefinitions>
+ <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>
+ <BinaryModule>false</BinaryModule>
+ <OutputFileBasename>UefiUsbLib</OutputFileBasename>
+ </ModuleDefinitions>
+ <LibraryClassDefinitions>
+ <LibraryClass Usage="ALWAYS_PRODUCED" SupModuleList="DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER">
+ <Keyword>UefiUsbLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseMemoryLib</Keyword>
+ </LibraryClass>
+ </LibraryClassDefinitions>
+ <SourceFiles>
+ <Filename>UsbDxeLib.c</Filename>
+ <Filename>hid.c</Filename>
+ </SourceFiles>
+ <PackageDependencies>
+ <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>
+ <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>
+ </PackageDependencies>
+ <Externs>
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
+ </Externs>
+</ModuleSurfaceArea> \ No newline at end of file
diff --git a/MdePkg/Library/UefiUsbLib/UsbDxeLib.c b/MdePkg/Library/UefiUsbLib/UsbDxeLib.c
new file mode 100644
index 0000000000..6686291aa2
--- /dev/null
+++ b/MdePkg/Library/UefiUsbLib/UsbDxeLib.c
@@ -0,0 +1,704 @@
+/*++
+
+Copyright (c) 2006, Intel Corporation
+All rights reserved. This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Module Name:
+
+ UsbDxeLib.c
+
+ Abstract:
+
+ Common Dxe Libarary for USB
+
+ Revision History
+
+--*/
+
+//
+// Include common header file for this module.
+//
+#include "CommonHeader.h"
+
+//
+// Get Device Descriptor
+//
+EFI_STATUS
+UsbGetDescriptor (
+ IN EFI_USB_IO_PROTOCOL *UsbIo,
+ IN UINT16 Value,
+ IN UINT16 Index,
+ IN UINT16 DescriptorLength,
+ OUT VOID *Descriptor,
+ OUT UINT32 *Status
+ )
+/*++
+
+Routine Description:
+
+ Usb Get Descriptor
+
+Arguments:
+
+ UsbIo - EFI_USB_IO_PROTOCOL
+ Value - Device Request Value
+ Index - Device Request Index
+ DescriptorLength - Descriptor Length
+ Descriptor - Descriptor buffer to contain result
+ Status - Transfer Status
+Returns:
+ EFI_INVALID_PARAMETER - Parameter is error
+ EFI_SUCCESS - Success
+ EFI_TIMEOUT - Device has no response
+
+--*/
+{
+ EFI_USB_DEVICE_REQUEST DevReq;
+
+ if (UsbIo == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
+
+ DevReq.RequestType = USB_DEV_GET_DESCRIPTOR_REQ_TYPE;
+ DevReq.Request = USB_DEV_GET_DESCRIPTOR;
+ DevReq.Value = Value;
+ DevReq.Index = Index;
+ DevReq.Length = DescriptorLength;
+
+ return UsbIo->UsbControlTransfer (
+ UsbIo,
+ &DevReq,
+ EfiUsbDataIn,
+ TIMEOUT_VALUE,
+ Descriptor,
+ DescriptorLength,
+ Status
+ );
+}
+//
+// Set Device Descriptor
+//
+EFI_STATUS
+UsbSetDescriptor (
+ IN EFI_USB_IO_PROTOCOL *UsbIo,
+ IN UINT16 Value,
+ IN UINT16 Index,
+ IN UINT16 DescriptorLength,
+ IN VOID *Descriptor,
+ OUT UINT32 *Status
+ )
+/*++
+
+Routine Description:
+
+ Usb Set Descriptor
+
+Arguments:
+
+ UsbIo - EFI_USB_IO_PROTOCOL
+ Value - Device Request Value
+ Index - Device Request Index
+ DescriptorLength - Descriptor Length
+ Descriptor - Descriptor buffer to set
+ Status - Transfer Status
+Returns:
+ EFI_INVALID_PARAMETER - Parameter is error
+ EFI_SUCCESS - Success
+ EFI_TIMEOUT - Device has no response
+
+--*/
+{
+ EFI_USB_DEVICE_REQUEST DevReq;
+
+ if (UsbIo == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
+
+ DevReq.RequestType = USB_DEV_SET_DESCRIPTOR_REQ_TYPE;
+ DevReq.Request = USB_DEV_SET_DESCRIPTOR;
+ DevReq.Value = Value;
+ DevReq.Index = Index;
+ DevReq.Length = DescriptorLength;
+
+ return UsbIo->UsbControlTransfer (
+ UsbIo,
+ &DevReq,
+ EfiUsbDataOut,
+ TIMEOUT_VALUE,
+ Descriptor,
+ DescriptorLength,
+ Status
+ );
+}
+
+//
+// Get device Interface
+//
+EFI_STATUS
+UsbGetDeviceInterface (
+ IN EFI_USB_IO_PROTOCOL *UsbIo,
+ IN UINT16 Index,
+ OUT UINT8 *AltSetting,
+ OUT UINT32 *Status
+ )
+/*++
+
+Routine Description:
+
+ Usb Get Device Interface
+
+Arguments:
+
+ UsbIo - EFI_USB_IO_PROTOCOL
+ Index - Interface index value
+ AltSetting - Alternate setting
+ Status - Trasnsfer status
+
+Returns:
+
+ EFI_INVALID_PARAMETER - Parameter is error
+ EFI_SUCCESS - Success
+ EFI_TIMEOUT - Device has no response
+
+
+--*/
+{
+ EFI_USB_DEVICE_REQUEST DevReq;
+
+ if (UsbIo == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
+
+ DevReq.RequestType = USB_DEV_GET_INTERFACE_REQ_TYPE;
+ DevReq.Request = USB_DEV_GET_INTERFACE;
+ DevReq.Index = Index;
+ DevReq.Length = 1;
+
+ return UsbIo->UsbControlTransfer (
+ UsbIo,
+ &DevReq,
+ EfiUsbDataIn,
+ TIMEOUT_VALUE,
+ AltSetting,
+ 1,
+ Status
+ );
+}
+//
+// Set device interface
+//
+EFI_STATUS
+UsbSetDeviceInterface (
+ IN EFI_USB_IO_PROTOCOL *UsbIo,
+ IN UINT16 InterfaceNo,
+ IN UINT16 AltSetting,
+ OUT UINT32 *Status
+ )
+/*++
+
+Routine Description:
+
+ Usb Set Device Interface
+
+Arguments:
+
+ UsbIo - EFI_USB_IO_PROTOCOL
+ InterfaceNo - Interface Number
+ AltSetting - Alternate setting
+ Status - Trasnsfer status
+
+Returns:
+
+ EFI_INVALID_PARAMETER - Parameter is error
+ EFI_SUCCESS - Success
+ EFI_TIMEOUT - Device has no response
+
+--*/
+{
+ EFI_USB_DEVICE_REQUEST DevReq;
+
+ if (UsbIo == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
+
+ DevReq.RequestType = USB_DEV_SET_INTERFACE_REQ_TYPE;
+ DevReq.Request = USB_DEV_SET_INTERFACE;
+ DevReq.Value = AltSetting;
+ DevReq.Index = InterfaceNo;
+
+
+ return UsbIo->UsbControlTransfer (
+ UsbIo,
+ &DevReq,
+ EfiUsbNoData,
+ TIMEOUT_VALUE,
+ NULL,
+ 0,
+ Status
+ );
+}
+//
+// Get device configuration
+//
+EFI_STATUS
+UsbGetDeviceConfiguration (
+ IN EFI_USB_IO_PROTOCOL *UsbIo,
+ OUT UINT8 *ConfigValue,
+ OUT UINT32 *Status
+ )
+/*++
+
+Routine Description:
+
+ Usb Get Device Configuration
+
+Arguments:
+
+ UsbIo - EFI_USB_IO_PROTOCOL
+ ConfigValue - Config Value
+ Status - Transfer Status
+
+Returns:
+
+ EFI_INVALID_PARAMETER - Parameter is error
+ EFI_SUCCESS - Success
+ EFI_TIMEOUT - Device has no response
+
+--*/
+{
+ EFI_USB_DEVICE_REQUEST DevReq;
+
+ if (UsbIo == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
+
+ DevReq.RequestType = USB_DEV_GET_CONFIGURATION_REQ_TYPE;
+ DevReq.Request = USB_DEV_GET_CONFIGURATION;
+ DevReq.Length = 1;
+
+ return UsbIo->UsbControlTransfer (
+ UsbIo,
+ &DevReq,
+ EfiUsbDataIn,
+ TIMEOUT_VALUE,
+ ConfigValue,
+ 1,
+ Status
+ );
+}
+//
+// Set device configuration
+//
+EFI_STATUS
+UsbSetDeviceConfiguration (
+ IN EFI_USB_IO_PROTOCOL *UsbIo,
+ IN UINT16 Value,
+ OUT UINT32 *Status
+ )
+/*++
+
+Routine Description:
+
+ Usb Set Device Configuration
+
+Arguments:
+
+ UsbIo - EFI_USB_IO_PROTOCOL
+ Value - Configuration Value to set
+ Status - Transfer status
+
+Returns:
+
+ EFI_INVALID_PARAMETER - Parameter is error
+ EFI_SUCCESS - Success
+ EFI_TIMEOUT - Device has no response
+
+--*/
+{
+ EFI_USB_DEVICE_REQUEST DevReq;
+
+ if (UsbIo == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
+
+ DevReq.RequestType = USB_DEV_SET_CONFIGURATION_REQ_TYPE;
+ DevReq.Request = USB_DEV_SET_CONFIGURATION;
+ DevReq.Value = Value;
+
+ return UsbIo->UsbControlTransfer (
+ UsbIo,
+ &DevReq,
+ EfiUsbNoData,
+ TIMEOUT_VALUE,
+ NULL,
+ 0,
+ Status
+ );
+}
+//
+// Set Device Feature
+//
+EFI_STATUS
+UsbSetDeviceFeature (
+ IN EFI_USB_IO_PROTOCOL *UsbIo,
+ IN EFI_USB_RECIPIENT Recipient,
+ IN UINT16 Value,
+ IN UINT16 Target,
+ OUT UINT32 *Status
+ )
+/*++
+
+Routine Description:
+
+ Usb Set Device Feature
+
+Arguments:
+
+ UsbIo - EFI_USB_IO_PROTOCOL
+ Recipient - Interface/Device/Endpoint
+ Value - Request value
+ Target - Request Index
+ Status - Transfer status
+
+Returns:
+
+ EFI_INVALID_PARAMETER - Parameter is error
+ EFI_SUCCESS - Success
+ EFI_TIMEOUT - Device has no response
+
+--*/
+{
+ EFI_USB_DEVICE_REQUEST DevReq;
+
+ if (UsbIo == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
+
+ switch (Recipient) {
+
+ case EfiUsbDevice:
+ DevReq.RequestType = 0x00;
+ break;
+
+ case EfiUsbInterface:
+ DevReq.RequestType = 0x01;
+ break;
+
+ case EfiUsbEndpoint:
+ DevReq.RequestType = 0x02;
+ break;
+ }
+ //
+ // Fill device request, see USB1.1 spec
+ //
+ DevReq.Request = USB_DEV_SET_FEATURE;
+ DevReq.Value = Value;
+ DevReq.Index = Target;
+
+
+ return UsbIo->UsbControlTransfer (
+ UsbIo,
+ &DevReq,
+ EfiUsbNoData,
+ TIMEOUT_VALUE,
+ NULL,
+ 0,
+ Status
+ );
+}
+//
+// Clear Device Feature
+//
+EFI_STATUS
+UsbClearDeviceFeature (
+ IN EFI_USB_IO_PROTOCOL *UsbIo,
+ IN EFI_USB_RECIPIENT Recipient,
+ IN UINT16 Value,
+ IN UINT16 Target,
+ OUT UINT32 *Status
+ )
+/*++
+
+Routine Description:
+
+ Usb Clear Device Feature
+
+Arguments:
+
+ UsbIo - EFI_USB_IO_PROTOCOL
+ Recipient - Interface/Device/Endpoint
+ Value - Request value
+ Target - Request Index
+ Status - Transfer status
+
+Returns:
+
+ EFI_INVALID_PARAMETER - Parameter is error
+ EFI_SUCCESS - Success
+ EFI_TIMEOUT - Device has no response
+
+--*/
+{
+ EFI_USB_DEVICE_REQUEST DevReq;
+
+ if (UsbIo == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
+
+ switch (Recipient) {
+
+ case EfiUsbDevice:
+ DevReq.RequestType = 0x00;
+ break;
+
+ case EfiUsbInterface:
+ DevReq.RequestType = 0x01;
+ break;
+
+ case EfiUsbEndpoint:
+ DevReq.RequestType = 0x02;
+ break;
+ }
+ //
+ // Fill device request, see USB1.1 spec
+ //
+ DevReq.Request = USB_DEV_CLEAR_FEATURE;
+ DevReq.Value = Value;
+ DevReq.Index = Target;
+
+
+ return UsbIo->UsbControlTransfer (
+ UsbIo,
+ &DevReq,
+ EfiUsbNoData,
+ TIMEOUT_VALUE,
+ NULL,
+ 0,
+ Status
+ );
+}
+//
+// Get Device Status
+//
+EFI_STATUS
+UsbGetDeviceStatus (
+ IN EFI_USB_IO_PROTOCOL *UsbIo,
+ IN EFI_USB_RECIPIENT Recipient,
+ IN UINT16 Target,
+ OUT UINT16 *DevStatus,
+ OUT UINT32 *Status
+ )
+/*++
+
+Routine Description:
+
+ Usb Get Device Status
+
+Arguments:
+
+ UsbIo - EFI_USB_IO_PROTOCOL
+ Recipient - Interface/Device/Endpoint
+ Target - Request index
+ DevStatus - Device status
+ Status - Transfer status
+
+Returns:
+
+ EFI_INVALID_PARAMETER - Parameter is error
+ EFI_SUCCESS - Success
+ EFI_TIMEOUT - Device has no response
+
+--*/
+{
+ EFI_USB_DEVICE_REQUEST DevReq;
+
+ if (UsbIo == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
+
+ switch (Recipient) {
+
+ case EfiUsbDevice:
+ DevReq.RequestType = 0x80;
+ break;
+
+ case EfiUsbInterface:
+ DevReq.RequestType = 0x81;
+ break;
+
+ case EfiUsbEndpoint:
+ DevReq.RequestType = 0x82;
+ break;
+ }
+ //
+ // Fill device request, see USB1.1 spec
+ //
+ DevReq.Request = USB_DEV_GET_STATUS;
+ DevReq.Value = 0;
+ DevReq.Index = Target;
+ DevReq.Length = 2;
+
+ return UsbIo->UsbControlTransfer (
+ UsbIo,
+ &DevReq,
+ EfiUsbDataIn,
+ TIMEOUT_VALUE,
+ DevStatus,
+ 2,
+ Status
+ );
+}
+//
+// Usb Get String
+//
+EFI_STATUS
+UsbGetString (
+ IN EFI_USB_IO_PROTOCOL *UsbIo,
+ IN UINT16 LangID,
+ IN UINT8 Index,
+ IN VOID *Buf,
+ IN UINTN BufSize,
+ OUT UINT32 *Status
+ )
+/*++
+
+Routine Description:
+
+ Usb Get String
+
+Arguments:
+
+ UsbIo - EFI_USB_IO_PROTOCOL
+ LangID - Language ID
+ Index - Request index
+ Buf - Buffer to store string
+ BufSize - Buffer size
+ Status - Transfer status
+
+Returns:
+
+ EFI_INVALID_PARAMETER - Parameter is error
+ EFI_SUCCESS - Success
+ EFI_TIMEOUT - Device has no response
+
+--*/
+{
+ UINT16 Value;
+
+ if (UsbIo == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+ //
+ // Fill value, see USB1.1 spec
+ //
+ Value = (UINT16) ((USB_DT_STRING << 8) | Index);
+
+ return UsbGetDescriptor (
+ UsbIo,
+ Value,
+ LangID,
+ (UINT16) BufSize,
+ Buf,
+ Status
+ );
+}
+
+EFI_STATUS
+UsbClearEndpointHalt (
+ IN EFI_USB_IO_PROTOCOL *UsbIo,
+ IN UINT8 EndpointNo,
+ OUT UINT32 *Status
+ )
+/*++
+
+Routine Description:
+
+ Clear endpoint stall
+
+Arguments:
+
+ UsbIo - EFI_USB_IO_PROTOCOL
+ EndpointNo - Endpoint Number
+ Status - Transfer Status
+
+Returns:
+
+ EFI_NOT_FOUND - Can't find the Endpoint
+ EFI_DEVICE_ERROR - Hardware error
+ EFI_SUCCESS - Success
+
+--*/
+{
+ EFI_STATUS Result;
+ EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor;
+ EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
+ UINT8 Index;
+
+ ZeroMem (&EndpointDescriptor, sizeof (EFI_USB_ENDPOINT_DESCRIPTOR));
+ //
+ // First seach the endpoint descriptor for that endpoint addr
+ //
+ Result = UsbIo->UsbGetInterfaceDescriptor (
+ UsbIo,
+ &InterfaceDescriptor
+ );
+ if (EFI_ERROR (Result)) {
+ return Result;
+ }
+
+ for (Index = 0; Index < InterfaceDescriptor.NumEndpoints; Index++) {
+ Result = UsbIo->UsbGetEndpointDescriptor (
+ UsbIo,
+ Index,
+ &EndpointDescriptor
+ );
+ if (EFI_ERROR (Result)) {
+ continue;
+ }
+
+ if (EndpointDescriptor.EndpointAddress == EndpointNo) {
+ break;
+ }
+ }
+
+ if (Index == InterfaceDescriptor.NumEndpoints) {
+ //
+ // No such endpoint
+ //
+ return EFI_NOT_FOUND;
+ }
+
+ Result = UsbClearDeviceFeature (
+ UsbIo,
+ EfiUsbEndpoint,
+ EfiUsbEndpointHalt,
+ EndpointDescriptor.EndpointAddress,
+ Status
+ );
+
+ return Result;
+}
diff --git a/MdePkg/Library/UefiUsbLib/hid.c b/MdePkg/Library/UefiUsbLib/hid.c
new file mode 100644
index 0000000000..a98fbfb9a1
--- /dev/null
+++ b/MdePkg/Library/UefiUsbLib/hid.c
@@ -0,0 +1,464 @@
+/*++
+
+Copyright (c) 2006, Intel Corporation
+All rights reserved. This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ Module Name:
+
+ hid.c
+
+ Abstract:
+
+ HID class request
+
+ Revision History
+
+--*/
+
+//
+// Include common header file for this module.
+//
+#include "CommonHeader.h"
+
+//
+// Function to get HID descriptor
+//
+EFI_STATUS
+UsbGetHidDescriptor (
+ IN EFI_USB_IO_PROTOCOL *UsbIo,
+ IN UINT8 InterfaceNum,
+ OUT EFI_USB_HID_DESCRIPTOR *HidDescriptor
+ )
+/*++
+
+ Routine Description:
+ Get Hid Descriptor
+
+ Arguments:
+ UsbIo - EFI_USB_IO_PROTOCOL
+ InterfaceNum - Hid interface number
+ HidDescriptor - Caller allocated buffer to store Usb hid descriptor
+ if successfully returned.
+
+ Returns:
+ EFI_SUCCESS
+ EFI_DEVICE_ERROR
+ EFI_TIMEOUT
+
+--*/
+{
+ UINT32 Status;
+ EFI_STATUS Result;
+ EFI_USB_DEVICE_REQUEST Request;
+
+ Request.RequestType = 0x81;
+ Request.Request = 0x06;
+ Request.Value = (UINT16) (0x21 << 8);
+ Request.Index = InterfaceNum;
+ Request.Length = sizeof (EFI_USB_HID_DESCRIPTOR);
+
+ Result = UsbIo->UsbControlTransfer (
+ UsbIo,
+ &Request,
+ EfiUsbDataIn,
+ TIMEOUT_VALUE,
+ HidDescriptor,
+ sizeof (EFI_USB_HID_DESCRIPTOR),
+ &Status
+ );
+
+ return Result;
+
+}
+//
+// Function to get Report Class descriptor
+//
+EFI_STATUS
+UsbGetReportDescriptor (
+ IN EFI_USB_IO_PROTOCOL *UsbIo,
+ IN UINT8 InterfaceNum,
+ IN UINT16 DescriptorSize,
+ OUT UINT8 *DescriptorBuffer
+ )
+/*++
+
+ Routine Description:
+ get Report Class descriptor
+
+ Arguments:
+ UsbIo - EFI_USB_IO_PROTOCOL.
+ InterfaceNum - Report interface number.
+ DescriptorSize - Length of DescriptorBuffer.
+ DescriptorBuffer - Caller allocated buffer to store Usb report descriptor
+ if successfully returned.
+
+ Returns:
+ EFI_SUCCESS
+ EFI_DEVICE_ERROR
+ EFI_TIMEOUT
+
+--*/
+{
+ UINT32 Status;
+ EFI_STATUS Result;
+ EFI_USB_DEVICE_REQUEST Request;
+
+ //
+ // Fill Device request packet
+ //
+ Request.RequestType = 0x81;
+ Request.Request = 0x06;
+ Request.Value = (UINT16) (0x22 << 8);
+ Request.Index = InterfaceNum;
+ Request.Length = DescriptorSize;
+
+ Result = UsbIo->UsbControlTransfer (
+ UsbIo,
+ &Request,
+ EfiUsbDataIn,
+ TIMEOUT_VALUE,
+ DescriptorBuffer,
+ DescriptorSize,
+ &Status
+ );
+
+ return Result;
+
+}
+//
+// Following are HID class request
+//
+EFI_STATUS
+UsbGetProtocolRequest (
+ IN EFI_USB_IO_PROTOCOL *UsbIo,
+ IN UINT8 Interface,
+ IN UINT8 *Protocol
+ )
+/*++
+
+ Routine Description:
+ Get Hid Protocol Request
+
+ Arguments:
+ UsbIo - EFI_USB_IO_PROTOCOL
+ Interface - Which interface the caller wants to get protocol
+ Protocol - Protocol value returned.
+
+ Returns:
+ EFI_SUCCESS
+ EFI_DEVICE_ERROR
+ EFI_TIMEOUT
+
+--*/
+{
+ UINT32 Status;
+ EFI_STATUS Result;
+ EFI_USB_DEVICE_REQUEST Request;
+
+ //
+ // Fill Device request packet
+ //
+ Request.RequestType = 0xa1;
+ //
+ // 10100001b;
+ //
+ Request.Request = EFI_USB_GET_PROTOCOL_REQUEST;
+ Request.Value = 0;
+ Request.Index = Interface;
+ Request.Length = 1;
+
+ Result = UsbIo->UsbControlTransfer (
+ UsbIo,
+ &Request,
+ EfiUsbDataIn,
+ TIMEOUT_VALUE,
+ Protocol,
+ sizeof (UINT8),
+ &Status
+ );
+
+ return Result;
+}
+
+
+EFI_STATUS
+UsbSetProtocolRequest (
+ IN EFI_USB_IO_PROTOCOL *UsbIo,
+ IN UINT8 Interface,
+ IN UINT8 Protocol
+ )
+/*++
+
+ Routine Description:
+ Set Hid Protocol Request
+
+ Arguments:
+ UsbIo - EFI_USB_IO_PROTOCOL
+ Interface - Which interface the caller wants to set protocol
+ Protocol - Protocol value the caller wants to set.
+
+ Returns:
+ EFI_SUCCESS
+ EFI_DEVICE_ERROR
+ EFI_TIMEOUT
+
+--*/
+{
+ UINT32 Status;
+ EFI_STATUS Result;
+ EFI_USB_DEVICE_REQUEST Request;
+
+ //
+ // Fill Device request packet
+ //
+ Request.RequestType = 0x21;
+ //
+ // 00100001b;
+ //
+ Request.Request = EFI_USB_SET_PROTOCOL_REQUEST;
+ Request.Value = Protocol;
+ Request.Index = Interface;
+ Request.Length = 0;
+
+ Result = UsbIo->UsbControlTransfer (
+ UsbIo,
+ &Request,
+ EfiUsbNoData,
+ TIMEOUT_VALUE,
+ NULL,
+ 0,
+ &Status
+ );
+ return Result;
+}
+
+
+EFI_STATUS
+UsbSetIdleRequest (
+ IN EFI_USB_IO_PROTOCOL *UsbIo,
+ IN UINT8 Interface,
+ IN UINT8 ReportId,
+ IN UINT8 Duration
+ )
+/*++
+
+ Routine Description:
+ Set Idel request.
+
+ Arguments:
+ UsbIo - EFI_USB_IO_PROTOCOL
+ Interface - Which interface the caller wants to set.
+ ReportId - Which report the caller wants to set.
+ Duration - Idle rate the caller wants to set.
+
+ Returns:
+ EFI_SUCCESS
+ EFI_DEVICE_ERROR
+ EFI_TIMEOUT
+
+--*/
+{
+ UINT32 Status;
+ EFI_STATUS Result;
+ EFI_USB_DEVICE_REQUEST Request;
+
+ //
+ // Fill Device request packet
+ //
+ Request.RequestType = 0x21;
+ //
+ // 00100001b;
+ //
+ Request.Request = EFI_USB_SET_IDLE_REQUEST;
+ Request.Value = (UINT16) ((Duration << 8) | ReportId);
+ Request.Index = Interface;
+ Request.Length = 0;
+
+ Result = UsbIo->UsbControlTransfer (
+ UsbIo,
+ &Request,
+ EfiUsbNoData,
+ TIMEOUT_VALUE,
+ NULL,
+ 0,
+ &Status
+ );
+ return Result;
+}
+
+EFI_STATUS
+UsbGetIdleRequest (
+ IN EFI_USB_IO_PROTOCOL *UsbIo,
+ IN UINT8 Interface,
+ IN UINT8 ReportId,
+ OUT UINT8 *Duration
+ )
+/*++
+
+ Routine Description:
+ Get Idel request.
+
+ Arguments:
+ UsbIo - EFI_USB_IO_PROTOCOL
+ Interface - Which interface the caller wants to get.
+ ReportId - Which report the caller wants to get.
+ Duration - Idle rate the caller wants to get.
+
+ Returns:
+ EFI_SUCCESS
+ EFI_DEVICE_ERROR
+ EFI_TIMEOUT
+
+--*/
+{
+ UINT32 Status;
+ EFI_STATUS Result;
+ EFI_USB_DEVICE_REQUEST Request;
+
+ //
+ // Fill Device request packet
+ //
+ Request.RequestType = 0xa1;
+ //
+ // 10100001b;
+ //
+ Request.Request = EFI_USB_GET_IDLE_REQUEST;
+ Request.Value = ReportId;
+ Request.Index = Interface;
+ Request.Length = 1;
+
+ Result = UsbIo->UsbControlTransfer (
+ UsbIo,
+ &Request,
+ EfiUsbDataIn,
+ TIMEOUT_VALUE,
+ Duration,
+ 1,
+ &Status
+ );
+
+ return Result;
+}
+
+
+EFI_STATUS
+UsbSetReportRequest (
+ IN EFI_USB_IO_PROTOCOL *UsbIo,
+ IN UINT8 Interface,
+ IN UINT8 ReportId,
+ IN UINT8 ReportType,
+ IN UINT16 ReportLen,
+ IN UINT8 *Report
+ )
+/*++
+
+ Routine Description:
+ Hid Set Report request.
+
+ Arguments:
+ UsbIo - EFI_USB_IO_PROTOCOL
+ Interface - Which interface the caller wants to set.
+ ReportId - Which report the caller wants to set.
+ ReportType - Type of report.
+ ReportLen - Length of report descriptor.
+ Report - Report Descriptor buffer.
+
+ Returns:
+ EFI_SUCCESS
+ EFI_DEVICE_ERROR
+ EFI_TIMEOUT
+
+--*/
+{
+ UINT32 Status;
+ EFI_STATUS Result;
+ EFI_USB_DEVICE_REQUEST Request;
+
+ //
+ // Fill Device request packet
+ //
+ Request.RequestType = 0x21;
+ //
+ // 00100001b;
+ //
+ Request.Request = EFI_USB_SET_REPORT_REQUEST;
+ Request.Value = (UINT16) ((ReportType << 8) | ReportId);
+ Request.Index = Interface;
+ Request.Length = ReportLen;
+
+ Result = UsbIo->UsbControlTransfer (
+ UsbIo,
+ &Request,
+ EfiUsbDataOut,
+ TIMEOUT_VALUE,
+ Report,
+ ReportLen,
+ &Status
+ );
+
+ return Result;
+}
+
+EFI_STATUS
+UsbGetReportRequest (
+ IN EFI_USB_IO_PROTOCOL *UsbIo,
+ IN UINT8 Interface,
+ IN UINT8 ReportId,
+ IN UINT8 ReportType,
+ IN UINT16 ReportLen,
+ IN UINT8 *Report
+ )
+/*++
+
+ Routine Description:
+ Hid Set Report request.
+
+ Arguments:
+ UsbIo - EFI_USB_IO_PROTOCOL
+ Interface - Which interface the caller wants to set.
+ ReportId - Which report the caller wants to set.
+ ReportType - Type of report.
+ ReportLen - Length of report descriptor.
+ Report - Caller allocated buffer to store Report Descriptor.
+
+ Returns:
+ EFI_SUCCESS
+ EFI_DEVICE_ERROR
+ EFI_TIMEOUT
+
+--*/
+{
+ UINT32 Status;
+ EFI_STATUS Result;
+ EFI_USB_DEVICE_REQUEST Request;
+
+ //
+ // Fill Device request packet
+ //
+ Request.RequestType = 0xa1;
+ //
+ // 10100001b;
+ //
+ Request.Request = EFI_USB_GET_REPORT_REQUEST;
+ Request.Value = (UINT16) ((ReportType << 8) | ReportId);
+ Request.Index = Interface;
+ Request.Length = ReportLen;
+
+ Result = UsbIo->UsbControlTransfer (
+ UsbIo,
+ &Request,
+ EfiUsbDataIn,
+ TIMEOUT_VALUE,
+ Report,
+ ReportLen,
+ &Status
+ );
+
+ return Result;
+}