3 The library provides USB HID Class standard and specific requests defined
4 in USB HID Firmware Specification 7 section : Requests.
6 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php.
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "UefiUsbLibInternal.h"
20 // Hid RequestType Bits specifying characteristics of request.
21 // Valid values are 10100001b (0xa1) or 00100001b (0x21).
22 // The following description:
23 // 7 Data transfer direction
33 Get the descriptor of the specified USB HID interface.
35 Submit a USB get HID descriptor request for the USB device specified by UsbIo
36 and Interface and return the HID descriptor in HidDescriptor.
37 If UsbIo is NULL, then ASSERT().
38 If HidDescriptor is NULL, then ASSERT().
40 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
41 @param Interface The index of the HID interface on the USB target.
42 @param HidDescriptor The pointer to the USB HID descriptor that was retrieved from
43 the specified USB target and interface. Type EFI_USB_HID_DESCRIPTOR
44 is defined in the MDE Package Industry Standard include file Usb.h.
46 @retval EFI_SUCCESS The request executed successfully.
47 @retval EFI_TIMEOUT A timeout occurred executing the request.
48 @retval EFI_DEVICE_ERROR The request failed due to a device error.
54 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
56 OUT EFI_USB_HID_DESCRIPTOR
*HidDescriptor
61 EFI_USB_DEVICE_REQUEST Request
;
63 ASSERT(UsbIo
!= NULL
);
64 ASSERT(HidDescriptor
!= NULL
);
66 Request
.RequestType
= USB_HID_GET_DESCRIPTOR_REQ_TYPE
;
67 Request
.Request
= USB_REQ_GET_DESCRIPTOR
;
68 Request
.Value
= (UINT16
) (USB_DESC_TYPE_HID
<< 8);
69 Request
.Index
= Interface
;
70 Request
.Length
= (UINT16
) sizeof (EFI_USB_HID_DESCRIPTOR
);
72 Result
= UsbIo
->UsbControlTransfer (
76 PcdGet32 (PcdUsbTransferTimeoutValue
),
78 sizeof (EFI_USB_HID_DESCRIPTOR
),
87 Get the report descriptor of the specified USB HID interface.
89 Submit a USB get HID report descriptor request for the USB device specified by
90 UsbIo and Interface and return the report descriptor in DescriptorBuffer.
91 If UsbIo is NULL, then ASSERT().
92 If DescriptorBuffer is NULL, then ASSERT().
94 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
95 @param Interface The index of the report interface on the USB target.
96 @param DescriptorLength The size, in bytes, of DescriptorBuffer.
97 @param DescriptorBuffer A pointer to the buffer to store the report class descriptor.
99 @retval EFI_SUCCESS The request executed successfully.
100 @retval EFI_OUT_OF_RESOURCES The request could not be completed because the
101 buffer specified by DescriptorLength and DescriptorBuffer
102 is not large enough to hold the result of the request.
103 @retval EFI_TIMEOUT A timeout occurred executing the request.
104 @retval EFI_DEVICE_ERROR The request failed due to a device error.
109 UsbGetReportDescriptor (
110 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
112 IN UINT16 DescriptorLength
,
113 OUT UINT8
*DescriptorBuffer
118 EFI_USB_DEVICE_REQUEST Request
;
120 ASSERT (UsbIo
!= NULL
);
121 ASSERT (DescriptorBuffer
!= NULL
);
124 // Fill Device request packet
126 Request
.RequestType
= USB_HID_GET_DESCRIPTOR_REQ_TYPE
;
127 Request
.Request
= USB_REQ_GET_DESCRIPTOR
;
128 Request
.Value
= (UINT16
) (USB_DESC_TYPE_REPORT
<< 8);
129 Request
.Index
= Interface
;
130 Request
.Length
= DescriptorLength
;
132 Result
= UsbIo
->UsbControlTransfer (
136 PcdGet32 (PcdUsbTransferTimeoutValue
),
147 Get the HID protocol of the specified USB HID interface.
149 Submit a USB get HID protocol request for the USB device specified by UsbIo
150 and Interface and return the protocol retrieved in Protocol.
151 If UsbIo is NULL, then ASSERT().
152 If Protocol is NULL, then ASSERT().
154 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
155 @param Interface The index of the report interface on the USB target.
156 @param Protocol A pointer to the protocol for the specified USB target.
158 @retval EFI_SUCCESS The request executed successfully.
159 @retval EFI_TIMEOUT A timeout occurred executing the request.
160 @retval EFI_DEVICE_ERROR The request failed due to a device error.
165 UsbGetProtocolRequest (
166 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
173 EFI_USB_DEVICE_REQUEST Request
;
175 ASSERT (UsbIo
!= NULL
);
176 ASSERT (Protocol
!= NULL
);
179 // Fill Device request packet
181 Request
.RequestType
= USB_HID_CLASS_GET_REQ_TYPE
;
182 Request
.Request
= EFI_USB_GET_PROTOCOL_REQUEST
;
184 Request
.Index
= Interface
;
187 Result
= UsbIo
->UsbControlTransfer (
191 PcdGet32 (PcdUsbTransferTimeoutValue
),
203 Set the HID protocol of the specified USB HID interface.
205 Submit a USB set HID protocol request for the USB device specified by UsbIo
206 and Interface and set the protocol to the value specified by Protocol.
207 If UsbIo is NULL, then ASSERT().
209 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
210 @param Interface The index of the report interface on the USB target.
211 @param Protocol The protocol value to set for the specified USB target.
213 @retval EFI_SUCCESS The request executed successfully.
214 @retval EFI_TIMEOUT A timeout occurred executing the request.
215 @retval EFI_DEVICE_ERROR The request failed due to a device error.
220 UsbSetProtocolRequest (
221 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
228 EFI_USB_DEVICE_REQUEST Request
;
230 ASSERT (UsbIo
!= NULL
);
233 // Fill Device request packet
235 Request
.RequestType
= USB_HID_CLASS_SET_REQ_TYPE
;
236 Request
.Request
= EFI_USB_SET_PROTOCOL_REQUEST
;
237 Request
.Value
= Protocol
;
238 Request
.Index
= Interface
;
241 Result
= UsbIo
->UsbControlTransfer (
245 PcdGet32 (PcdUsbTransferTimeoutValue
),
255 Set the idle rate of the specified USB HID report.
257 Submit a USB set HID report idle request for the USB device specified by UsbIo,
258 Interface, and ReportId, and set the idle rate to the value specified by Duration.
259 If UsbIo is NULL, then ASSERT().
261 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
262 @param Interface The index of the report interface on the USB target.
263 @param ReportId The identifier of the report to retrieve.
264 @param Duration The idle rate to set for the specified USB target.
266 @retval EFI_SUCCESS The request executed successfully.
267 @retval EFI_TIMEOUT A timeout occurred executing the request.
268 @retval EFI_DEVICE_ERROR The request failed due to a device error.
274 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
282 EFI_USB_DEVICE_REQUEST Request
;
284 ASSERT (UsbIo
!= NULL
);
286 // Fill Device request packet
288 Request
.RequestType
= USB_HID_CLASS_SET_REQ_TYPE
;
289 Request
.Request
= EFI_USB_SET_IDLE_REQUEST
;
290 Request
.Value
= (UINT16
) ((Duration
<< 8) | ReportId
);
291 Request
.Index
= Interface
;
294 Result
= UsbIo
->UsbControlTransfer (
298 PcdGet32 (PcdUsbTransferTimeoutValue
),
308 Get the idle rate of the specified USB HID report.
310 Submit a USB get HID report idle request for the USB device specified by UsbIo,
311 Interface, and ReportId, and return the ide rate in Duration.
312 If UsbIo is NULL, then ASSERT().
313 If Duration is NULL, then ASSERT().
315 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
316 @param Interface The index of the report interface on the USB target.
317 @param ReportId The identifier of the report to retrieve.
318 @param Duration A pointer to the idle rate retrieved from the specified USB target.
320 @retval EFI_SUCCESS The request executed successfully.
321 @retval EFI_TIMEOUT A timeout occurred executing the request.
322 @retval EFI_DEVICE_ERROR The request failed due to a device error.
328 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
336 EFI_USB_DEVICE_REQUEST Request
;
338 ASSERT (UsbIo
!= NULL
);
339 ASSERT (Duration
!= NULL
);
341 // Fill Device request packet
343 Request
.RequestType
= USB_HID_CLASS_GET_REQ_TYPE
;
344 Request
.Request
= EFI_USB_GET_IDLE_REQUEST
;
345 Request
.Value
= ReportId
;
346 Request
.Index
= Interface
;
349 Result
= UsbIo
->UsbControlTransfer (
353 PcdGet32 (PcdUsbTransferTimeoutValue
),
365 Set the report descriptor of the specified USB HID interface.
367 Submit a USB set HID report request for the USB device specified by UsbIo,
368 Interface, ReportId, and ReportType, and set the report descriptor using the
369 buffer specified by ReportLength and Report.
370 If UsbIo is NULL, then ASSERT().
371 If Report is NULL, then ASSERT().
373 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
374 @param Interface The index of the report interface on the USB target.
375 @param ReportId The identifier of the report to retrieve.
376 @param ReportType The type of report to retrieve.
377 @param ReportLength The size, in bytes, of Report.
378 @param Report A pointer to the report descriptor buffer to set.
380 @retval EFI_SUCCESS The request executed successfully.
381 @retval EFI_TIMEOUT A timeout occurred executing the request.
382 @retval EFI_DEVICE_ERROR The request failed due to a device error.
387 UsbSetReportRequest (
388 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
398 EFI_USB_DEVICE_REQUEST Request
;
400 ASSERT (UsbIo
!= NULL
);
401 ASSERT (Report
!= NULL
);
404 // Fill Device request packet
406 Request
.RequestType
= USB_HID_CLASS_SET_REQ_TYPE
;
407 Request
.Request
= EFI_USB_SET_REPORT_REQUEST
;
408 Request
.Value
= (UINT16
) ((ReportType
<< 8) | ReportId
);
409 Request
.Index
= Interface
;
410 Request
.Length
= ReportLen
;
412 Result
= UsbIo
->UsbControlTransfer (
416 PcdGet32 (PcdUsbTransferTimeoutValue
),
427 Get the report descriptor of the specified USB HID interface.
429 Submit a USB get HID report request for the USB device specified by UsbIo,
430 Interface, ReportId, and ReportType, and return the report in the buffer
432 If UsbIo is NULL, then ASSERT().
433 If Report is NULL, then ASSERT().
435 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
436 @param Interface The index of the report interface on the USB target.
437 @param ReportId The identifier of the report to retrieve.
438 @param ReportType The type of report to retrieve.
439 @param ReportLength The size, in bytes, of Report.
440 @param Report A pointer to the buffer to store the report descriptor.
442 @retval EFI_SUCCESS The request executed successfully.
443 @retval EFI_OUT_OF_RESOURCES The request could not be completed because the
444 buffer specified by ReportLength and Report is not
445 large enough to hold the result of the request.
446 @retval EFI_TIMEOUT A timeout occurred executing the request.
447 @retval EFI_DEVICE_ERROR The request failed due to a device error.
452 UsbGetReportRequest (
453 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
463 EFI_USB_DEVICE_REQUEST Request
;
465 ASSERT (UsbIo
!= NULL
);
466 ASSERT (Report
!= NULL
);
469 // Fill Device request packet
471 Request
.RequestType
= USB_HID_CLASS_GET_REQ_TYPE
;
472 Request
.Request
= EFI_USB_GET_REPORT_REQUEST
;
473 Request
.Value
= (UINT16
) ((ReportType
<< 8) | ReportId
);
474 Request
.Index
= Interface
;
475 Request
.Length
= ReportLen
;
477 Result
= UsbIo
->UsbControlTransfer (
481 PcdGet32 (PcdUsbTransferTimeoutValue
),