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 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include "UefiUsbLibInternal.h"
14 // Hid RequestType Bits specifying characteristics of request.
15 // Valid values are 10100001b (0xa1) or 00100001b (0x21).
16 // The following description:
17 // 7 Data transfer direction
27 Get the descriptor of the specified USB HID interface.
29 Submit a USB get HID descriptor request for the USB device specified by UsbIo
30 and Interface and return the HID descriptor in HidDescriptor.
31 If UsbIo is NULL, then ASSERT().
32 If HidDescriptor is NULL, then ASSERT().
34 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
35 @param Interface The index of the HID interface on the USB target.
36 @param HidDescriptor The pointer to the USB HID descriptor that was retrieved from
37 the specified USB target and interface. Type EFI_USB_HID_DESCRIPTOR
38 is defined in the MDE Package Industry Standard include file Usb.h.
40 @retval EFI_SUCCESS The request executed successfully.
41 @retval EFI_TIMEOUT A timeout occurred executing the request.
42 @retval EFI_DEVICE_ERROR The request failed due to a device error.
48 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
50 OUT EFI_USB_HID_DESCRIPTOR
*HidDescriptor
55 EFI_USB_DEVICE_REQUEST Request
;
57 ASSERT(UsbIo
!= NULL
);
58 ASSERT(HidDescriptor
!= NULL
);
60 Request
.RequestType
= USB_HID_GET_DESCRIPTOR_REQ_TYPE
;
61 Request
.Request
= USB_REQ_GET_DESCRIPTOR
;
62 Request
.Value
= (UINT16
) (USB_DESC_TYPE_HID
<< 8);
63 Request
.Index
= Interface
;
64 Request
.Length
= (UINT16
) sizeof (EFI_USB_HID_DESCRIPTOR
);
66 Result
= UsbIo
->UsbControlTransfer (
70 PcdGet32 (PcdUsbTransferTimeoutValue
),
72 sizeof (EFI_USB_HID_DESCRIPTOR
),
81 Get the report descriptor of the specified USB HID interface.
83 Submit a USB get HID report descriptor request for the USB device specified by
84 UsbIo and Interface and return the report descriptor in DescriptorBuffer.
85 If UsbIo is NULL, then ASSERT().
86 If DescriptorBuffer is NULL, then ASSERT().
88 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
89 @param Interface The index of the report interface on the USB target.
90 @param DescriptorLength The size, in bytes, of DescriptorBuffer.
91 @param DescriptorBuffer A pointer to the buffer to store the report class descriptor.
93 @retval EFI_SUCCESS The request executed successfully.
94 @retval EFI_OUT_OF_RESOURCES The request could not be completed because the
95 buffer specified by DescriptorLength and DescriptorBuffer
96 is not large enough to hold the result of the request.
97 @retval EFI_TIMEOUT A timeout occurred executing the request.
98 @retval EFI_DEVICE_ERROR The request failed due to a device error.
103 UsbGetReportDescriptor (
104 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
106 IN UINT16 DescriptorLength
,
107 OUT UINT8
*DescriptorBuffer
112 EFI_USB_DEVICE_REQUEST Request
;
114 ASSERT (UsbIo
!= NULL
);
115 ASSERT (DescriptorBuffer
!= NULL
);
118 // Fill Device request packet
120 Request
.RequestType
= USB_HID_GET_DESCRIPTOR_REQ_TYPE
;
121 Request
.Request
= USB_REQ_GET_DESCRIPTOR
;
122 Request
.Value
= (UINT16
) (USB_DESC_TYPE_REPORT
<< 8);
123 Request
.Index
= Interface
;
124 Request
.Length
= DescriptorLength
;
126 Result
= UsbIo
->UsbControlTransfer (
130 PcdGet32 (PcdUsbTransferTimeoutValue
),
141 Get the HID protocol of the specified USB HID interface.
143 Submit a USB get HID protocol request for the USB device specified by UsbIo
144 and Interface and return the protocol retrieved in Protocol.
145 If UsbIo is NULL, then ASSERT().
146 If Protocol is NULL, then ASSERT().
148 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
149 @param Interface The index of the report interface on the USB target.
150 @param Protocol A pointer to the protocol for the specified USB target.
152 @retval EFI_SUCCESS The request executed successfully.
153 @retval EFI_TIMEOUT A timeout occurred executing the request.
154 @retval EFI_DEVICE_ERROR The request failed due to a device error.
159 UsbGetProtocolRequest (
160 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
167 EFI_USB_DEVICE_REQUEST Request
;
169 ASSERT (UsbIo
!= NULL
);
170 ASSERT (Protocol
!= NULL
);
173 // Fill Device request packet
175 Request
.RequestType
= USB_HID_CLASS_GET_REQ_TYPE
;
176 Request
.Request
= EFI_USB_GET_PROTOCOL_REQUEST
;
178 Request
.Index
= Interface
;
181 Result
= UsbIo
->UsbControlTransfer (
185 PcdGet32 (PcdUsbTransferTimeoutValue
),
197 Set the HID protocol of the specified USB HID interface.
199 Submit a USB set HID protocol request for the USB device specified by UsbIo
200 and Interface and set the protocol to the value specified by Protocol.
201 If UsbIo is NULL, then ASSERT().
203 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
204 @param Interface The index of the report interface on the USB target.
205 @param Protocol The protocol value to set for the specified USB target.
207 @retval EFI_SUCCESS The request executed successfully.
208 @retval EFI_TIMEOUT A timeout occurred executing the request.
209 @retval EFI_DEVICE_ERROR The request failed due to a device error.
214 UsbSetProtocolRequest (
215 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
222 EFI_USB_DEVICE_REQUEST Request
;
224 ASSERT (UsbIo
!= NULL
);
227 // Fill Device request packet
229 Request
.RequestType
= USB_HID_CLASS_SET_REQ_TYPE
;
230 Request
.Request
= EFI_USB_SET_PROTOCOL_REQUEST
;
231 Request
.Value
= Protocol
;
232 Request
.Index
= Interface
;
235 Result
= UsbIo
->UsbControlTransfer (
239 PcdGet32 (PcdUsbTransferTimeoutValue
),
249 Set the idle rate of the specified USB HID report.
251 Submit a USB set HID report idle request for the USB device specified by UsbIo,
252 Interface, and ReportId, and set the idle rate to the value specified by Duration.
253 If UsbIo is NULL, then ASSERT().
255 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
256 @param Interface The index of the report interface on the USB target.
257 @param ReportId The identifier of the report to retrieve.
258 @param Duration The idle rate to set for the specified USB target.
260 @retval EFI_SUCCESS The request executed successfully.
261 @retval EFI_TIMEOUT A timeout occurred executing the request.
262 @retval EFI_DEVICE_ERROR The request failed due to a device error.
268 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
276 EFI_USB_DEVICE_REQUEST Request
;
278 ASSERT (UsbIo
!= NULL
);
280 // Fill Device request packet
282 Request
.RequestType
= USB_HID_CLASS_SET_REQ_TYPE
;
283 Request
.Request
= EFI_USB_SET_IDLE_REQUEST
;
284 Request
.Value
= (UINT16
) ((Duration
<< 8) | ReportId
);
285 Request
.Index
= Interface
;
288 Result
= UsbIo
->UsbControlTransfer (
292 PcdGet32 (PcdUsbTransferTimeoutValue
),
302 Get the idle rate of the specified USB HID report.
304 Submit a USB get HID report idle request for the USB device specified by UsbIo,
305 Interface, and ReportId, and return the ide rate in Duration.
306 If UsbIo is NULL, then ASSERT().
307 If Duration is NULL, then ASSERT().
309 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
310 @param Interface The index of the report interface on the USB target.
311 @param ReportId The identifier of the report to retrieve.
312 @param Duration A pointer to the idle rate retrieved from the specified USB target.
314 @retval EFI_SUCCESS The request executed successfully.
315 @retval EFI_TIMEOUT A timeout occurred executing the request.
316 @retval EFI_DEVICE_ERROR The request failed due to a device error.
322 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
330 EFI_USB_DEVICE_REQUEST Request
;
332 ASSERT (UsbIo
!= NULL
);
333 ASSERT (Duration
!= NULL
);
335 // Fill Device request packet
337 Request
.RequestType
= USB_HID_CLASS_GET_REQ_TYPE
;
338 Request
.Request
= EFI_USB_GET_IDLE_REQUEST
;
339 Request
.Value
= ReportId
;
340 Request
.Index
= Interface
;
343 Result
= UsbIo
->UsbControlTransfer (
347 PcdGet32 (PcdUsbTransferTimeoutValue
),
359 Set the report descriptor of the specified USB HID interface.
361 Submit a USB set HID report request for the USB device specified by UsbIo,
362 Interface, ReportId, and ReportType, and set the report descriptor using the
363 buffer specified by ReportLength and Report.
364 If UsbIo is NULL, then ASSERT().
365 If Report is NULL, then ASSERT().
367 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
368 @param Interface The index of the report interface on the USB target.
369 @param ReportId The identifier of the report to retrieve.
370 @param ReportType The type of report to retrieve.
371 @param ReportLength The size, in bytes, of Report.
372 @param Report A pointer to the report descriptor buffer to set.
374 @retval EFI_SUCCESS The request executed successfully.
375 @retval EFI_TIMEOUT A timeout occurred executing the request.
376 @retval EFI_DEVICE_ERROR The request failed due to a device error.
381 UsbSetReportRequest (
382 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
392 EFI_USB_DEVICE_REQUEST Request
;
394 ASSERT (UsbIo
!= NULL
);
395 ASSERT (Report
!= NULL
);
398 // Fill Device request packet
400 Request
.RequestType
= USB_HID_CLASS_SET_REQ_TYPE
;
401 Request
.Request
= EFI_USB_SET_REPORT_REQUEST
;
402 Request
.Value
= (UINT16
) ((ReportType
<< 8) | ReportId
);
403 Request
.Index
= Interface
;
404 Request
.Length
= ReportLen
;
406 Result
= UsbIo
->UsbControlTransfer (
410 PcdGet32 (PcdUsbTransferTimeoutValue
),
421 Get the report descriptor of the specified USB HID interface.
423 Submit a USB get HID report request for the USB device specified by UsbIo,
424 Interface, ReportId, and ReportType, and return the report in the buffer
426 If UsbIo is NULL, then ASSERT().
427 If Report is NULL, then ASSERT().
429 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
430 @param Interface The index of the report interface on the USB target.
431 @param ReportId The identifier of the report to retrieve.
432 @param ReportType The type of report to retrieve.
433 @param ReportLength The size, in bytes, of Report.
434 @param Report A pointer to the buffer to store the report descriptor.
436 @retval EFI_SUCCESS The request executed successfully.
437 @retval EFI_OUT_OF_RESOURCES The request could not be completed because the
438 buffer specified by ReportLength and Report is not
439 large enough to hold the result of the request.
440 @retval EFI_TIMEOUT A timeout occurred executing the request.
441 @retval EFI_DEVICE_ERROR The request failed due to a device error.
446 UsbGetReportRequest (
447 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
457 EFI_USB_DEVICE_REQUEST Request
;
459 ASSERT (UsbIo
!= NULL
);
460 ASSERT (Report
!= NULL
);
463 // Fill Device request packet
465 Request
.RequestType
= USB_HID_CLASS_GET_REQ_TYPE
;
466 Request
.Request
= EFI_USB_GET_REPORT_REQUEST
;
467 Request
.Value
= (UINT16
) ((ReportType
<< 8) | ReportId
);
468 Request
.Index
= Interface
;
469 Request
.Length
= ReportLen
;
471 Result
= UsbIo
->UsbControlTransfer (
475 PcdGet32 (PcdUsbTransferTimeoutValue
),