summaryrefslogtreecommitdiff
path: root/EdkModulePkg/Library/EdkUsbLib
diff options
context:
space:
mode:
authorbbahnsen <bbahnsen@6f19259b-4bc3-4df7-8a09-765794883524>2006-04-21 22:54:32 +0000
committerbbahnsen <bbahnsen@6f19259b-4bc3-4df7-8a09-765794883524>2006-04-21 22:54:32 +0000
commit878ddf1fc3540a715f63594ed22b6929e881afb4 (patch)
treec56c44dac138137b510e1fba7c3efe5e4d84bea2 /EdkModulePkg/Library/EdkUsbLib
downloadedk2-platforms-878ddf1fc3540a715f63594ed22b6929e881afb4.tar.xz
Initial import.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@3 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'EdkModulePkg/Library/EdkUsbLib')
-rw-r--r--EdkModulePkg/Library/EdkUsbLib/EdkUsbLib.mbd30
-rw-r--r--EdkModulePkg/Library/EdkUsbLib/EdkUsbLib.msa46
-rw-r--r--EdkModulePkg/Library/EdkUsbLib/UsbDxeLib.c699
-rw-r--r--EdkModulePkg/Library/EdkUsbLib/build.xml47
-rw-r--r--EdkModulePkg/Library/EdkUsbLib/hid.c459
5 files changed, 1281 insertions, 0 deletions
diff --git a/EdkModulePkg/Library/EdkUsbLib/EdkUsbLib.mbd b/EdkModulePkg/Library/EdkUsbLib/EdkUsbLib.mbd
new file mode 100644
index 0000000000..79fa4b10fc
--- /dev/null
+++ b/EdkModulePkg/Library/EdkUsbLib/EdkUsbLib.mbd
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<LibraryModuleBuildDescription xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.TianoCore.org/2006/Edk2.0 http://www.TianoCore.org/2006/Edk2.0/SurfaceArea.xsd">
+ <MbdLibHeader>
+ <BaseName>EdkUsbLib</BaseName>
+ <Guid>87eb5df9-722a-4241-ad7f-370d0b3a56d7</Guid>
+ <Version>0</Version>
+ <Description>FIX ME!</Description>
+ <Copyright>Copyright (c) 2004-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>
+ <Created>2006-03-12 17:09</Created>
+ <Modified>2006-03-19 15:19</Modified>
+ </MbdLibHeader>
+</LibraryModuleBuildDescription>
diff --git a/EdkModulePkg/Library/EdkUsbLib/EdkUsbLib.msa b/EdkModulePkg/Library/EdkUsbLib/EdkUsbLib.msa
new file mode 100644
index 0000000000..f2aa74b28f
--- /dev/null
+++ b/EdkModulePkg/Library/EdkUsbLib/EdkUsbLib.msa
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<LibraryModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.TianoCore.org/2006/Edk2.0 http://www.TianoCore.org/2006/Edk2.0/SurfaceArea.xsd">
+ <MsaLibHeader>
+ <BaseName>EdkUsbLib</BaseName>
+ <ModuleType>DXE_DRIVER</ModuleType>
+ <ComponentType>LIBRARY</ComponentType>
+ <Guid>87eb5df9-722a-4241-ad7f-370d0b3a56d7</Guid>
+ <Version>0</Version>
+ <Abstract>Component description file for UsbDxeLib module</Abstract>
+ <Description>FIX ME!</Description>
+ <Copyright>Copyright (c) 2004-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>0</Specification>
+ <Created>2006-03-12 17:09</Created>
+ <Updated>2006-03-19 15:19</Updated>
+ </MsaLibHeader>
+ <LibraryClassDefinitions>
+ <LibraryClass Usage="ALWAYS_PRODUCED">EdkUsbLib</LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">BaseMemoryLib</LibraryClass>
+ </LibraryClassDefinitions>
+ <SourceFiles>
+ <Filename>UsbDxelib.c</Filename>
+ <Filename>hid.c</Filename>
+ </SourceFiles>
+ <Includes>
+ <PackageName>MdePkg</PackageName>
+ <PackageName>EdkModulePkg</PackageName>
+ </Includes>
+</LibraryModuleSurfaceArea>
diff --git a/EdkModulePkg/Library/EdkUsbLib/UsbDxeLib.c b/EdkModulePkg/Library/EdkUsbLib/UsbDxeLib.c
new file mode 100644
index 0000000000..8bbd0893ae
--- /dev/null
+++ b/EdkModulePkg/Library/EdkUsbLib/UsbDxeLib.c
@@ -0,0 +1,699 @@
+/*++
+
+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
+
+--*/
+
+//
+// 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/EdkModulePkg/Library/EdkUsbLib/build.xml b/EdkModulePkg/Library/EdkUsbLib/build.xml
new file mode 100644
index 0000000000..0b9eaade6b
--- /dev/null
+++ b/EdkModulePkg/Library/EdkUsbLib/build.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?><!-- 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.-->
+<project basedir="." default="EdkUsbLib"><!--Apply external ANT tasks-->
+ <taskdef resource="GenBuild.tasks"/>
+ <taskdef resource="net/sf/antcontrib/antlib.xml"/>
+ <property environment="env"/>
+ <property name="WORKSPACE_DIR" value="${env.WORKSPACE}"/>
+ <import file="${WORKSPACE_DIR}\Tools\Conf\BuildMacro.xml"/><!--MODULE_RELATIVE PATH is relative to PACKAGE_DIR-->
+ <property name="MODULE_RELATIVE_PATH" value="Library\EdkUsbLib"/>
+ <property name="MODULE_DIR" value="${PACKAGE_DIR}\${MODULE_RELATIVE_PATH}"/>
+ <property name="COMMON_FILE" value="${WORKSPACE_DIR}\Tools\Conf\Common.xml"/>
+ <target name="EdkUsbLib">
+ <GenBuild baseName="EdkUsbLib" mbdFilename="${MODULE_DIR}\EdkUsbLib.mbd" msaFilename="${MODULE_DIR}\EdkUsbLib.msa"/>
+ </target>
+ <target depends="EdkUsbLib_clean" name="clean"/>
+ <target depends="EdkUsbLib_cleanall" name="cleanall"/>
+ <target name="EdkUsbLib_clean">
+ <OutputDirSetup baseName="EdkUsbLib" mbdFilename="${MODULE_DIR}\EdkUsbLib.mbd" msaFilename="${MODULE_DIR}\EdkUsbLib.msa"/>
+ <if>
+ <available file="${DEST_DIR_OUTPUT}\EdkUsbLib_build.xml"/>
+ <then>
+ <ant antfile="${DEST_DIR_OUTPUT}\EdkUsbLib_build.xml" target="clean"/>
+ </then>
+ </if>
+ <delete dir="${DEST_DIR_OUTPUT}" excludes="*.xml"/>
+ </target>
+ <target name="EdkUsbLib_cleanall">
+ <OutputDirSetup baseName="EdkUsbLib" mbdFilename="${MODULE_DIR}\EdkUsbLib.mbd" msaFilename="${MODULE_DIR}\EdkUsbLib.msa"/>
+ <if>
+ <available file="${DEST_DIR_OUTPUT}\EdkUsbLib_build.xml"/>
+ <then>
+ <ant antfile="${DEST_DIR_OUTPUT}\EdkUsbLib_build.xml" target="cleanall"/>
+ </then>
+ </if>
+ <delete dir="${DEST_DIR_OUTPUT}"/>
+ <delete dir="${DEST_DIR_DEBUG}"/>
+ <delete>
+ <fileset dir="${BIN_DIR}" includes="**EdkUsbLib*"/>
+ </delete>
+ </target>
+</project> \ No newline at end of file
diff --git a/EdkModulePkg/Library/EdkUsbLib/hid.c b/EdkModulePkg/Library/EdkUsbLib/hid.c
new file mode 100644
index 0000000000..edf9a94efc
--- /dev/null
+++ b/EdkModulePkg/Library/EdkUsbLib/hid.c
@@ -0,0 +1,459 @@
+/*++
+
+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
+
+--*/
+
+//
+// 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;
+}