rename
authorvanjeff <vanjeff@de2fecce-e211-0410-80a6-f3fac2684e05>
Wed, 20 Feb 2008 08:33:51 +0000 (08:33 +0000)
committervanjeff <vanjeff@de2fecce-e211-0410-80a6-f3fac2684e05>
Wed, 20 Feb 2008 08:33:51 +0000 (08:33 +0000)
git-svn-id: https://edk2.tianocore.org/svn/edk2/trunk@4737 de2fecce-e211-0410-80a6-f3fac2684e05

edk2/MdePkg/Library/UefiUsbLib/Hid.c [new file with mode: 0644]

diff --git a/edk2/MdePkg/Library/UefiUsbLib/Hid.c b/edk2/MdePkg/Library/UefiUsbLib/Hid.c
new file mode 100644 (file)
index 0000000..7c0ee14
--- /dev/null
@@ -0,0 +1,425 @@
+/** @file\r
+\r
+Copyright (c) 2004, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+\r
+**/\r
+\r
+#include <UefiUsbLibInternal.h>\r
+\r
+\r
+/**\r
+  Get Hid Descriptor\r
+\r
+  @param  UsbIo             EFI_USB_IO_PROTOCOL\r
+  @param  InterfaceNum      Hid interface number\r
+  @param  HidDescriptor     Caller allocated buffer to store Usb hid descriptor if\r
+                            successfully returned.\r
+\r
+  @return EFI_SUCCESS\r
+  @return EFI_DEVICE_ERROR\r
+  @return EFI_TIMEOUT\r
+\r
+**/\r
+EFI_STATUS\r
+UsbGetHidDescriptor (\r
+  IN  EFI_USB_IO_PROTOCOL        *UsbIo,\r
+  IN  UINT8                      InterfaceNum,\r
+  OUT EFI_USB_HID_DESCRIPTOR     *HidDescriptor\r
+  )\r
+{\r
+  UINT32                  Status;\r
+  EFI_STATUS              Result;\r
+  EFI_USB_DEVICE_REQUEST  Request;\r
+\r
+  Request.RequestType = 0x81;\r
+  Request.Request     = 0x06;\r
+  Request.Value       = (UINT16) (0x21 << 8);\r
+  Request.Index       = InterfaceNum;\r
+  Request.Length      = sizeof (EFI_USB_HID_DESCRIPTOR);\r
+\r
+  Result = UsbIo->UsbControlTransfer (\r
+                    UsbIo,\r
+                    &Request,\r
+                    EfiUsbDataIn,\r
+                    TIMEOUT_VALUE,\r
+                    HidDescriptor,\r
+                    sizeof (EFI_USB_HID_DESCRIPTOR),\r
+                    &Status\r
+                    );\r
+\r
+  return Result;\r
+\r
+}\r
+//\r
+// Function to get Report Class descriptor\r
+//\r
+\r
+/**\r
+  get Report Class descriptor\r
+\r
+  @param  UsbIo             EFI_USB_IO_PROTOCOL.\r
+  @param  InterfaceNum      Report interface number.\r
+  @param  DescriptorSize    Length of DescriptorBuffer.\r
+  @param  DescriptorBuffer  Caller allocated buffer to store Usb report descriptor\r
+                            if successfully returned.\r
+\r
+  @return EFI_SUCCESS\r
+  @return EFI_DEVICE_ERROR\r
+  @return EFI_TIMEOUT\r
+\r
+**/\r
+EFI_STATUS\r
+UsbGetReportDescriptor (\r
+  IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
+  IN  UINT8                   InterfaceNum,\r
+  IN  UINT16                  DescriptorSize,\r
+  OUT UINT8                   *DescriptorBuffer\r
+  )\r
+{\r
+  UINT32                  Status;\r
+  EFI_STATUS              Result;\r
+  EFI_USB_DEVICE_REQUEST  Request;\r
+\r
+  //\r
+  // Fill Device request packet\r
+  //\r
+  Request.RequestType = 0x81;\r
+  Request.Request     = 0x06;\r
+  Request.Value       = (UINT16) (0x22 << 8);\r
+  Request.Index       = InterfaceNum;\r
+  Request.Length      = DescriptorSize;\r
+\r
+  Result = UsbIo->UsbControlTransfer (\r
+                    UsbIo,\r
+                    &Request,\r
+                    EfiUsbDataIn,\r
+                    TIMEOUT_VALUE,\r
+                    DescriptorBuffer,\r
+                    DescriptorSize,\r
+                    &Status\r
+                    );\r
+\r
+  return Result;\r
+\r
+}\r
+//\r
+// Following are HID class request\r
+//\r
+\r
+/**\r
+  Get Hid Protocol Request\r
+\r
+  @param  UsbIo             EFI_USB_IO_PROTOCOL\r
+  @param  Interface         Which interface the caller wants to get protocol\r
+  @param  Protocol          Protocol value returned.\r
+\r
+  @return EFI_SUCCESS\r
+  @return EFI_DEVICE_ERROR\r
+  @return EFI_TIMEOUT\r
+\r
+**/\r
+EFI_STATUS\r
+UsbGetProtocolRequest (\r
+  IN EFI_USB_IO_PROTOCOL     *UsbIo,\r
+  IN UINT8                   Interface,\r
+  IN UINT8                   *Protocol\r
+  )\r
+{\r
+  UINT32                  Status;\r
+  EFI_STATUS              Result;\r
+  EFI_USB_DEVICE_REQUEST  Request;\r
+\r
+  //\r
+  // Fill Device request packet\r
+  //\r
+  Request.RequestType = 0xa1;\r
+  //\r
+  // 10100001b;\r
+  //\r
+  Request.Request = EFI_USB_GET_PROTOCOL_REQUEST;\r
+  Request.Value   = 0;\r
+  Request.Index   = Interface;\r
+  Request.Length  = 1;\r
+\r
+  Result = UsbIo->UsbControlTransfer (\r
+                    UsbIo,\r
+                    &Request,\r
+                    EfiUsbDataIn,\r
+                    TIMEOUT_VALUE,\r
+                    Protocol,\r
+                    sizeof (UINT8),\r
+                    &Status\r
+                    );\r
+\r
+  return Result;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Set Hid Protocol Request\r
+\r
+  @param  UsbIo             EFI_USB_IO_PROTOCOL\r
+  @param  Interface         Which interface the caller wants to set protocol\r
+  @param  Protocol          Protocol value the caller wants to set.\r
+\r
+  @return EFI_SUCCESS\r
+  @return EFI_DEVICE_ERROR\r
+  @return EFI_TIMEOUT\r
+\r
+**/\r
+EFI_STATUS\r
+UsbSetProtocolRequest (\r
+  IN EFI_USB_IO_PROTOCOL     *UsbIo,\r
+  IN UINT8                   Interface,\r
+  IN UINT8                   Protocol\r
+  )\r
+{\r
+  UINT32                  Status;\r
+  EFI_STATUS              Result;\r
+  EFI_USB_DEVICE_REQUEST  Request;\r
+\r
+  //\r
+  // Fill Device request packet\r
+  //\r
+  Request.RequestType = 0x21;\r
+  //\r
+  // 00100001b;\r
+  //\r
+  Request.Request = EFI_USB_SET_PROTOCOL_REQUEST;\r
+  Request.Value   = Protocol;\r
+  Request.Index   = Interface;\r
+  Request.Length  = 0;\r
+\r
+  Result = UsbIo->UsbControlTransfer (\r
+                    UsbIo,\r
+                    &Request,\r
+                    EfiUsbNoData,\r
+                    TIMEOUT_VALUE,\r
+                    NULL,\r
+                    0,\r
+                    &Status\r
+                    );\r
+  return Result;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Set Idel request.\r
+\r
+  @param  UsbIo             EFI_USB_IO_PROTOCOL\r
+  @param  Interface         Which interface the caller wants to set.\r
+  @param  ReportId          Which report the caller wants to set.\r
+  @param  Duration          Idle rate the caller wants to set.\r
+\r
+  @return EFI_SUCCESS\r
+  @return EFI_DEVICE_ERROR\r
+  @return EFI_TIMEOUT\r
+\r
+**/\r
+EFI_STATUS\r
+UsbSetIdleRequest (\r
+  IN EFI_USB_IO_PROTOCOL     *UsbIo,\r
+  IN UINT8                   Interface,\r
+  IN UINT8                   ReportId,\r
+  IN UINT8                   Duration\r
+  )\r
+{\r
+  UINT32                  Status;\r
+  EFI_STATUS              Result;\r
+  EFI_USB_DEVICE_REQUEST  Request;\r
+\r
+  //\r
+  // Fill Device request packet\r
+  //\r
+  Request.RequestType = 0x21;\r
+  //\r
+  // 00100001b;\r
+  //\r
+  Request.Request = EFI_USB_SET_IDLE_REQUEST;\r
+  Request.Value   = (UINT16) ((Duration << 8) | ReportId);\r
+  Request.Index   = Interface;\r
+  Request.Length  = 0;\r
+\r
+  Result = UsbIo->UsbControlTransfer (\r
+                    UsbIo,\r
+                    &Request,\r
+                    EfiUsbNoData,\r
+                    TIMEOUT_VALUE,\r
+                    NULL,\r
+                    0,\r
+                    &Status\r
+                    );\r
+  return Result;\r
+}\r
+\r
+\r
+/**\r
+  Get Idel request.\r
+\r
+  @param  UsbIo             EFI_USB_IO_PROTOCOL\r
+  @param  Interface         Which interface the caller wants to get.\r
+  @param  ReportId          Which report the caller wants to get.\r
+  @param  Duration          Idle rate the caller wants to get.\r
+\r
+  @return EFI_SUCCESS\r
+  @return EFI_DEVICE_ERROR\r
+  @return EFI_TIMEOUT\r
+\r
+**/\r
+EFI_STATUS\r
+UsbGetIdleRequest (\r
+  IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
+  IN  UINT8                   Interface,\r
+  IN  UINT8                   ReportId,\r
+  OUT UINT8                   *Duration\r
+  )\r
+{\r
+  UINT32                  Status;\r
+  EFI_STATUS              Result;\r
+  EFI_USB_DEVICE_REQUEST  Request;\r
+\r
+  //\r
+  // Fill Device request packet\r
+  //\r
+  Request.RequestType = 0xa1;\r
+  //\r
+  // 10100001b;\r
+  //\r
+  Request.Request = EFI_USB_GET_IDLE_REQUEST;\r
+  Request.Value   = ReportId;\r
+  Request.Index   = Interface;\r
+  Request.Length  = 1;\r
+\r
+  Result = UsbIo->UsbControlTransfer (\r
+                    UsbIo,\r
+                    &Request,\r
+                    EfiUsbDataIn,\r
+                    TIMEOUT_VALUE,\r
+                    Duration,\r
+                    1,\r
+                    &Status\r
+                    );\r
+\r
+  return Result;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Hid Set Report request.\r
+\r
+  @param  UsbIo             EFI_USB_IO_PROTOCOL\r
+  @param  Interface         Which interface the caller wants to set.\r
+  @param  ReportId          Which report the caller wants to set.\r
+  @param  ReportType        Type of report.\r
+  @param  ReportLen         Length of report descriptor.\r
+  @param  Report            Report Descriptor buffer.\r
+\r
+  @return EFI_SUCCESS\r
+  @return EFI_DEVICE_ERROR\r
+  @return EFI_TIMEOUT\r
+\r
+**/\r
+EFI_STATUS\r
+UsbSetReportRequest (\r
+  IN EFI_USB_IO_PROTOCOL     *UsbIo,\r
+  IN UINT8                   Interface,\r
+  IN UINT8                   ReportId,\r
+  IN UINT8                   ReportType,\r
+  IN UINT16                  ReportLen,\r
+  IN UINT8                   *Report\r
+  )\r
+{\r
+  UINT32                  Status;\r
+  EFI_STATUS              Result;\r
+  EFI_USB_DEVICE_REQUEST  Request;\r
+\r
+  //\r
+  // Fill Device request packet\r
+  //\r
+  Request.RequestType = 0x21;\r
+  //\r
+  // 00100001b;\r
+  //\r
+  Request.Request = EFI_USB_SET_REPORT_REQUEST;\r
+  Request.Value   = (UINT16) ((ReportType << 8) | ReportId);\r
+  Request.Index   = Interface;\r
+  Request.Length  = ReportLen;\r
+\r
+  Result = UsbIo->UsbControlTransfer (\r
+                    UsbIo,\r
+                    &Request,\r
+                    EfiUsbDataOut,\r
+                    TIMEOUT_VALUE,\r
+                    Report,\r
+                    ReportLen,\r
+                    &Status\r
+                    );\r
+\r
+  return Result;\r
+}\r
+\r
+\r
+/**\r
+  Hid Set Report request.\r
+\r
+  @param  UsbIo             EFI_USB_IO_PROTOCOL\r
+  @param  Interface         Which interface the caller wants to set.\r
+  @param  ReportId          Which report the caller wants to set.\r
+  @param  ReportType        Type of report.\r
+  @param  ReportLen         Length of report descriptor.\r
+  @param  Report            Caller allocated buffer to store Report Descriptor.\r
+\r
+  @return EFI_SUCCESS\r
+  @return EFI_DEVICE_ERROR\r
+  @return EFI_TIMEOUT\r
+\r
+**/\r
+EFI_STATUS\r
+UsbGetReportRequest (\r
+  IN EFI_USB_IO_PROTOCOL     *UsbIo,\r
+  IN UINT8                   Interface,\r
+  IN UINT8                   ReportId,\r
+  IN UINT8                   ReportType,\r
+  IN UINT16                  ReportLen,\r
+  IN UINT8                   *Report\r
+  )\r
+{\r
+  UINT32                  Status;\r
+  EFI_STATUS              Result;\r
+  EFI_USB_DEVICE_REQUEST  Request;\r
+\r
+  //\r
+  // Fill Device request packet\r
+  //\r
+  Request.RequestType = 0xa1;\r
+  //\r
+  // 10100001b;\r
+  //\r
+  Request.Request = EFI_USB_GET_REPORT_REQUEST;\r
+  Request.Value   = (UINT16) ((ReportType << 8) | ReportId);\r
+  Request.Index   = Interface;\r
+  Request.Length  = ReportLen;\r
+\r
+  Result = UsbIo->UsbControlTransfer (\r
+                    UsbIo,\r
+                    &Request,\r
+                    EfiUsbDataIn,\r
+                    TIMEOUT_VALUE,\r
+                    Report,\r
+                    ReportLen,\r
+                    &Status\r
+                    );\r
+\r
+  return Result;\r
+}\r