]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/UefiUsbLib/Hid.c
MdePkg: Clean up source files
[mirror_edk2.git] / MdePkg / Library / UefiUsbLib / Hid.c
index 0e9be352067bc59e7cb78abcd2e948b220f442c5..fca02838f112704fda63e228819e49274cf859d5 100644 (file)
@@ -2,13 +2,13 @@
 \r
   The library provides USB HID Class standard and specific requests defined\r
   in USB HID Firmware Specification 7 section : Requests.\r
-  \r
-  Copyright (c) 2004, Intel Corporation\r
-  All rights reserved. This program and the accompanying materials\r
+\r
+  Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  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
+  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
@@ -16,7 +16,7 @@
 \r
 #include "UefiUsbLibInternal.h"\r
 \r
-//  \r
+//\r
 //  Hid RequestType Bits specifying characteristics of request.\r
 //  Valid values are 10100001b (0xa1) or 00100001b (0x21).\r
 //  The following description:\r
 //\r
 \r
 /**\r
-  Get Hid Descriptor.\r
+  Get the descriptor of the specified USB HID interface.\r
+\r
+  Submit a USB get HID descriptor request for the USB device specified by UsbIo\r
+  and Interface and return the HID descriptor in HidDescriptor.\r
+  If UsbIo is NULL, then ASSERT().\r
+  If HidDescriptor is NULL, then ASSERT().\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
+  @param  UsbIo          A pointer to the USB I/O Protocol instance for the specific USB target.\r
+  @param  Interface      The index of the HID interface on the USB target.\r
+  @param  HidDescriptor  The pointer to the USB HID descriptor that was retrieved from\r
+                         the specified USB target and interface. Type EFI_USB_HID_DESCRIPTOR\r
+                         is defined in the MDE Package Industry Standard include file Usb.h.\r
 \r
-  @return Status of getting HID descriptor through USB I/O\r
-          protocol's UsbControlTransfer().\r
+  @retval EFI_SUCCESS       The request executed successfully.\r
+  @retval EFI_TIMEOUT       A timeout occurred executing the request.\r
+  @retval EFI_DEVICE_ERROR  The request failed due to a device error.\r
 \r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 UsbGetHidDescriptor (\r
   IN  EFI_USB_IO_PROTOCOL        *UsbIo,\r
-  IN  UINT8                      InterfaceNum,\r
+  IN  UINT8                      Interface,\r
   OUT EFI_USB_HID_DESCRIPTOR     *HidDescriptor\r
   )\r
 {\r
   UINT32                  Status;\r
   EFI_STATUS              Result;\r
   EFI_USB_DEVICE_REQUEST  Request;\r
-  \r
-  if (UsbIo == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
+\r
+  ASSERT(UsbIo != NULL);\r
+  ASSERT(HidDescriptor != NULL);\r
 \r
   Request.RequestType = USB_HID_GET_DESCRIPTOR_REQ_TYPE;\r
   Request.Request     = USB_REQ_GET_DESCRIPTOR;\r
   Request.Value       = (UINT16) (USB_DESC_TYPE_HID << 8);\r
-  Request.Index       = InterfaceNum;\r
-  Request.Length      = sizeof (EFI_USB_HID_DESCRIPTOR);\r
+  Request.Index       = Interface;\r
+  Request.Length      = (UINT16) sizeof (EFI_USB_HID_DESCRIPTOR);\r
 \r
   Result = UsbIo->UsbControlTransfer (\r
                     UsbIo,\r
                     &Request,\r
                     EfiUsbDataIn,\r
-                    TIMEOUT_VALUE,\r
+                    PcdGet32 (PcdUsbTransferTimeoutValue),\r
                     HidDescriptor,\r
                     sizeof (EFI_USB_HID_DESCRIPTOR),\r
                     &Status\r
@@ -78,24 +84,32 @@ UsbGetHidDescriptor (
 }\r
 \r
 /**\r
-  Get Report Class descriptor.\r
+  Get the report descriptor of the specified USB HID interface.\r
+\r
+  Submit a USB get HID report descriptor request for the USB device specified by\r
+  UsbIo and Interface and return the report descriptor in DescriptorBuffer.\r
+  If UsbIo is NULL, then ASSERT().\r
+  If DescriptorBuffer is NULL, then ASSERT().\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
+  @param  UsbIo             A pointer to the USB I/O Protocol instance for the specific USB target.\r
+  @param  Interface         The index of the report interface on the USB target.\r
+  @param  DescriptorLength  The size, in bytes, of DescriptorBuffer.\r
+  @param  DescriptorBuffer  A pointer to the buffer to store the report class descriptor.\r
 \r
-  @return Status of getting Report Class descriptor through USB\r
-          I/O protocol's UsbControlTransfer().\r
+  @retval  EFI_SUCCESS           The request executed successfully.\r
+  @retval  EFI_OUT_OF_RESOURCES  The request could not be completed because the\r
+                                 buffer specified by DescriptorLength and DescriptorBuffer\r
+                                 is not large enough to hold the result of the request.\r
+  @retval  EFI_TIMEOUT           A timeout occurred executing the request.\r
+  @retval  EFI_DEVICE_ERROR      The request failed due to a device error.\r
 \r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 UsbGetReportDescriptor (\r
   IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
-  IN  UINT8                   InterfaceNum,\r
-  IN  UINT16                  DescriptorSize,\r
+  IN  UINT8                   Interface,\r
+  IN  UINT16                  DescriptorLength,\r
   OUT UINT8                   *DescriptorBuffer\r
   )\r
 {\r
@@ -103,25 +117,25 @@ UsbGetReportDescriptor (
   EFI_STATUS              Result;\r
   EFI_USB_DEVICE_REQUEST  Request;\r
 \r
-  if (UsbIo == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
+  ASSERT (UsbIo != NULL);\r
+  ASSERT (DescriptorBuffer != NULL);\r
+\r
   //\r
   // Fill Device request packet\r
   //\r
   Request.RequestType = USB_HID_GET_DESCRIPTOR_REQ_TYPE;\r
   Request.Request     = USB_REQ_GET_DESCRIPTOR;\r
   Request.Value       = (UINT16) (USB_DESC_TYPE_REPORT << 8);\r
-  Request.Index       = InterfaceNum;\r
-  Request.Length      = DescriptorSize;\r
+  Request.Index       = Interface;\r
+  Request.Length      = DescriptorLength;\r
 \r
   Result = UsbIo->UsbControlTransfer (\r
                     UsbIo,\r
                     &Request,\r
                     EfiUsbDataIn,\r
-                    TIMEOUT_VALUE,\r
+                    PcdGet32 (PcdUsbTransferTimeoutValue),\r
                     DescriptorBuffer,\r
-                    DescriptorSize,\r
+                    DescriptorLength,\r
                     &Status\r
                     );\r
 \r
@@ -130,14 +144,20 @@ UsbGetReportDescriptor (
 }\r
 \r
 /**\r
-  Get Hid Protocol Request\r
+  Get the HID protocol of the specified USB HID interface.\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
+  Submit a USB get HID protocol request for the USB device specified by UsbIo\r
+  and Interface and return the protocol retrieved in Protocol.\r
+  If UsbIo is NULL, then ASSERT().\r
+  If Protocol is NULL, then ASSERT().\r
 \r
-  @return Status of getting Protocol Request through USB I/O\r
-          protocol's UsbControlTransfer().\r
+  @param  UsbIo      A pointer to the USB I/O Protocol instance for the specific USB target.\r
+  @param  Interface  The index of the report interface on the USB target.\r
+  @param  Protocol   A pointer to the protocol for the specified USB target.\r
+\r
+  @retval  EFI_SUCCESS       The request executed successfully.\r
+  @retval  EFI_TIMEOUT       A timeout occurred executing the request.\r
+  @retval  EFI_DEVICE_ERROR  The request failed due to a device error.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -145,16 +165,16 @@ EFIAPI
 UsbGetProtocolRequest (\r
   IN EFI_USB_IO_PROTOCOL     *UsbIo,\r
   IN UINT8                   Interface,\r
-  IN UINT8                   *Protocol\r
+  OUT UINT8                   *Protocol\r
   )\r
 {\r
   UINT32                  Status;\r
   EFI_STATUS              Result;\r
   EFI_USB_DEVICE_REQUEST  Request;\r
 \r
-  if (UsbIo == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
+  ASSERT (UsbIo != NULL);\r
+  ASSERT (Protocol != NULL);\r
+\r
   //\r
   // Fill Device request packet\r
   //\r
@@ -168,7 +188,7 @@ UsbGetProtocolRequest (
                     UsbIo,\r
                     &Request,\r
                     EfiUsbDataIn,\r
-                    TIMEOUT_VALUE,\r
+                    PcdGet32 (PcdUsbTransferTimeoutValue),\r
                     Protocol,\r
                     sizeof (UINT8),\r
                     &Status\r
@@ -180,15 +200,19 @@ UsbGetProtocolRequest (
 \r
 \r
 /**\r
-  Set Hid Protocol Request.\r
+  Set the HID protocol of the specified USB HID interface.\r
 \r
-  @param  UsbIo             EFI_USB_IO_PROTOCOL.\r
-  @param  Interface         Which interface the caller wants to\r
-                            set protocol.\r
-  @param  Protocol          Protocol value the caller wants to set.\r
+  Submit a USB set HID protocol request for the USB device specified by UsbIo\r
+  and Interface and set the protocol to the value specified by Protocol.\r
+  If UsbIo is NULL, then ASSERT().\r
 \r
-  @return Status of setting Protocol Request through USB I/O\r
-          protocol's UsbControlTransfer().\r
+  @param  UsbIo      A pointer to the USB I/O Protocol instance for the specific USB target.\r
+  @param  Interface  The index of the report interface on the USB target.\r
+  @param  Protocol   The protocol value to set for the specified USB target.\r
+\r
+  @retval  EFI_SUCCESS       The request executed successfully.\r
+  @retval  EFI_TIMEOUT       A timeout occurred executing the request.\r
+  @retval  EFI_DEVICE_ERROR  The request failed due to a device error.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -203,9 +227,8 @@ UsbSetProtocolRequest (
   EFI_STATUS              Result;\r
   EFI_USB_DEVICE_REQUEST  Request;\r
 \r
-  if (UsbIo == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
+  ASSERT (UsbIo != NULL);\r
+\r
   //\r
   // Fill Device request packet\r
   //\r
@@ -219,7 +242,7 @@ UsbSetProtocolRequest (
                     UsbIo,\r
                     &Request,\r
                     EfiUsbNoData,\r
-                    TIMEOUT_VALUE,\r
+                    PcdGet32 (PcdUsbTransferTimeoutValue),\r
                     NULL,\r
                     0,\r
                     &Status\r
@@ -229,15 +252,20 @@ UsbSetProtocolRequest (
 \r
 \r
 /**\r
-  Set Idel request.\r
+  Set the idle rate of the specified USB HID report.\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
+  Submit a USB set HID report idle request for the USB device specified by UsbIo,\r
+  Interface, and ReportId, and set the idle rate to the value specified by Duration.\r
+  If UsbIo is NULL, then ASSERT().\r
 \r
-  @return Status of setting IDLE Request through USB I/O\r
-          protocol's UsbControlTransfer().\r
+  @param  UsbIo      A pointer to the USB I/O Protocol instance for the specific USB target.\r
+  @param  Interface  The index of the report interface on the USB target.\r
+  @param  ReportId   The identifier of the report to retrieve.\r
+  @param  Duration   The idle rate to set for the specified USB target.\r
+\r
+  @retval  EFI_SUCCESS       The request executed successfully.\r
+  @retval  EFI_TIMEOUT       A timeout occurred executing the request.\r
+  @retval  EFI_DEVICE_ERROR  The request failed due to a device error.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -253,9 +281,7 @@ UsbSetIdleRequest (
   EFI_STATUS              Result;\r
   EFI_USB_DEVICE_REQUEST  Request;\r
 \r
-  if (UsbIo == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
+  ASSERT (UsbIo != NULL);\r
   //\r
   // Fill Device request packet\r
   //\r
@@ -269,7 +295,7 @@ UsbSetIdleRequest (
                     UsbIo,\r
                     &Request,\r
                     EfiUsbNoData,\r
-                    TIMEOUT_VALUE,\r
+                    PcdGet32 (PcdUsbTransferTimeoutValue),\r
                     NULL,\r
                     0,\r
                     &Status\r
@@ -279,15 +305,21 @@ UsbSetIdleRequest (
 \r
 \r
 /**\r
-  Get Idel request.\r
+  Get the idle rate of the specified USB HID report.\r
+\r
+  Submit a USB get HID report idle request for the USB device specified by UsbIo,\r
+  Interface, and ReportId, and return the ide rate in Duration.\r
+  If UsbIo is NULL, then ASSERT().\r
+  If Duration is NULL, then ASSERT().\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
+  @param  UsbIo      A pointer to the USB I/O Protocol instance for the specific USB target.\r
+  @param  Interface  The index of the report interface on the USB target.\r
+  @param  ReportId   The identifier of the report to retrieve.\r
+  @param  Duration   A pointer to the idle rate retrieved from the specified USB target.\r
 \r
-  @return Status of getting IDLE Request through USB I/O\r
-          protocol's UsbControlTransfer().\r
+  @retval  EFI_SUCCESS       The request executed successfully.\r
+  @retval  EFI_TIMEOUT       A timeout occurred executing the request.\r
+  @retval  EFI_DEVICE_ERROR  The request failed due to a device error.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -302,10 +334,9 @@ UsbGetIdleRequest (
   UINT32                  Status;\r
   EFI_STATUS              Result;\r
   EFI_USB_DEVICE_REQUEST  Request;\r
-  \r
-  if (UsbIo == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
+\r
+  ASSERT (UsbIo != NULL);\r
+  ASSERT (Duration != NULL);\r
   //\r
   // Fill Device request packet\r
   //\r
@@ -319,7 +350,7 @@ UsbGetIdleRequest (
                     UsbIo,\r
                     &Request,\r
                     EfiUsbDataIn,\r
-                    TIMEOUT_VALUE,\r
+                    PcdGet32 (PcdUsbTransferTimeoutValue),\r
                     Duration,\r
                     1,\r
                     &Status\r
@@ -331,17 +362,24 @@ UsbGetIdleRequest (
 \r
 \r
 /**\r
-  Hid Set Report request.\r
+  Set the report descriptor of the specified USB HID interface.\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
+  Submit a USB set HID report request for the USB device specified by UsbIo,\r
+  Interface, ReportId, and ReportType, and set the report descriptor using the\r
+  buffer specified by ReportLength and Report.\r
+  If UsbIo is NULL, then ASSERT().\r
+  If Report is NULL, then ASSERT().\r
 \r
-  @return Status of setting Report Request through USB I/O\r
-          protocol's UsbControlTransfer().\r
+  @param  UsbIo         A pointer to the USB I/O Protocol instance for the specific USB target.\r
+  @param  Interface     The index of the report interface on the USB target.\r
+  @param  ReportId      The identifier of the report to retrieve.\r
+  @param  ReportType    The type of report to retrieve.\r
+  @param  ReportLength  The size, in bytes, of Report.\r
+  @param  Report        A pointer to the report descriptor buffer to set.\r
+\r
+  @retval  EFI_SUCCESS       The request executed successfully.\r
+  @retval  EFI_TIMEOUT       A timeout occurred executing the request.\r
+  @retval  EFI_DEVICE_ERROR  The request failed due to a device error.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -359,9 +397,9 @@ UsbSetReportRequest (
   EFI_STATUS              Result;\r
   EFI_USB_DEVICE_REQUEST  Request;\r
 \r
-  if (UsbIo == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
+  ASSERT (UsbIo != NULL);\r
+  ASSERT (Report != NULL);\r
+\r
   //\r
   // Fill Device request packet\r
   //\r
@@ -375,7 +413,7 @@ UsbSetReportRequest (
                     UsbIo,\r
                     &Request,\r
                     EfiUsbDataOut,\r
-                    TIMEOUT_VALUE,\r
+                    PcdGet32 (PcdUsbTransferTimeoutValue),\r
                     Report,\r
                     ReportLen,\r
                     &Status\r
@@ -386,37 +424,47 @@ UsbSetReportRequest (
 \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 Status of getting Report Request through USB I/O\r
-          protocol's UsbControlTransfer().\r
+  Get the report descriptor of the specified USB HID interface.\r
+\r
+  Submit a USB get HID report request for the USB device specified by UsbIo,\r
+  Interface, ReportId, and ReportType, and return the report in the buffer\r
+  specified by Report.\r
+  If UsbIo is NULL, then ASSERT().\r
+  If Report is NULL, then ASSERT().\r
+\r
+  @param  UsbIo         A pointer to the USB I/O Protocol instance for the specific USB target.\r
+  @param  Interface     The index of the report interface on the USB target.\r
+  @param  ReportId      The identifier of the report to retrieve.\r
+  @param  ReportType    The type of report to retrieve.\r
+  @param  ReportLength  The size, in bytes, of Report.\r
+  @param  Report        A pointer to the buffer to store the report descriptor.\r
+\r
+  @retval  EFI_SUCCESS           The request executed successfully.\r
+  @retval  EFI_OUT_OF_RESOURCES  The request could not be completed because the\r
+                                 buffer specified by ReportLength and Report is not\r
+                                 large enough to hold the result of the request.\r
+  @retval  EFI_TIMEOUT           A timeout occurred executing the request.\r
+  @retval  EFI_DEVICE_ERROR      The request failed due to a device error.\r
 \r
 **/\r
 EFI_STATUS\r
 EFIAPI\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
+  IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
+  IN  UINT8                   Interface,\r
+  IN  UINT8                   ReportId,\r
+  IN  UINT8                   ReportType,\r
+  IN  UINT16                  ReportLen,\r
+  OUT UINT8                   *Report\r
   )\r
 {\r
   UINT32                  Status;\r
   EFI_STATUS              Result;\r
   EFI_USB_DEVICE_REQUEST  Request;\r
 \r
-  if (UsbIo == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
+  ASSERT (UsbIo != NULL);\r
+  ASSERT (Report != NULL);\r
+\r
   //\r
   // Fill Device request packet\r
   //\r
@@ -430,7 +478,7 @@ UsbGetReportRequest (
                     UsbIo,\r
                     &Request,\r
                     EfiUsbDataIn,\r
-                    TIMEOUT_VALUE,\r
+                    PcdGet32 (PcdUsbTransferTimeoutValue),\r
                     Report,\r
                     ReportLen,\r
                     &Status\r