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
),
80 Get the report descriptor of the specified USB HID interface.
82 Submit a USB get HID report descriptor request for the USB device specified by
83 UsbIo and Interface and return the report descriptor in DescriptorBuffer.
84 If UsbIo is NULL, then ASSERT().
85 If DescriptorBuffer is NULL, then ASSERT().
87 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
88 @param Interface The index of the report interface on the USB target.
89 @param DescriptorLength The size, in bytes, of DescriptorBuffer.
90 @param DescriptorBuffer A pointer to the buffer to store the report class descriptor.
92 @retval EFI_SUCCESS The request executed successfully.
93 @retval EFI_OUT_OF_RESOURCES The request could not be completed because the
94 buffer specified by DescriptorLength and DescriptorBuffer
95 is not large enough to hold the result of the request.
96 @retval EFI_TIMEOUT A timeout occurred executing the request.
97 @retval EFI_DEVICE_ERROR The request failed due to a device error.
102 UsbGetReportDescriptor (
103 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
105 IN UINT16 DescriptorLength
,
106 OUT UINT8
*DescriptorBuffer
111 EFI_USB_DEVICE_REQUEST Request
;
113 ASSERT (UsbIo
!= NULL
);
114 ASSERT (DescriptorBuffer
!= NULL
);
117 // Fill Device request packet
119 Request
.RequestType
= USB_HID_GET_DESCRIPTOR_REQ_TYPE
;
120 Request
.Request
= USB_REQ_GET_DESCRIPTOR
;
121 Request
.Value
= (UINT16
)(USB_DESC_TYPE_REPORT
<< 8);
122 Request
.Index
= Interface
;
123 Request
.Length
= DescriptorLength
;
125 Result
= UsbIo
->UsbControlTransfer (
129 PcdGet32 (PcdUsbTransferTimeoutValue
),
139 Get the HID protocol of the specified USB HID interface.
141 Submit a USB get HID protocol request for the USB device specified by UsbIo
142 and Interface and return the protocol retrieved in Protocol.
143 If UsbIo is NULL, then ASSERT().
144 If Protocol is NULL, then ASSERT().
146 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
147 @param Interface The index of the report interface on the USB target.
148 @param Protocol A pointer to the protocol for the specified USB target.
150 @retval EFI_SUCCESS The request executed successfully.
151 @retval EFI_TIMEOUT A timeout occurred executing the request.
152 @retval EFI_DEVICE_ERROR The request failed due to a device error.
157 UsbGetProtocolRequest (
158 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
165 EFI_USB_DEVICE_REQUEST Request
;
167 ASSERT (UsbIo
!= NULL
);
168 ASSERT (Protocol
!= NULL
);
171 // Fill Device request packet
173 Request
.RequestType
= USB_HID_CLASS_GET_REQ_TYPE
;
174 Request
.Request
= EFI_USB_GET_PROTOCOL_REQUEST
;
176 Request
.Index
= Interface
;
179 Result
= UsbIo
->UsbControlTransfer (
183 PcdGet32 (PcdUsbTransferTimeoutValue
),
193 Set the HID protocol of the specified USB HID interface.
195 Submit a USB set HID protocol request for the USB device specified by UsbIo
196 and Interface and set the protocol to the value specified by Protocol.
197 If UsbIo is NULL, then ASSERT().
199 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
200 @param Interface The index of the report interface on the USB target.
201 @param Protocol The protocol value to set for the specified USB target.
203 @retval EFI_SUCCESS The request executed successfully.
204 @retval EFI_TIMEOUT A timeout occurred executing the request.
205 @retval EFI_DEVICE_ERROR The request failed due to a device error.
210 UsbSetProtocolRequest (
211 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
218 EFI_USB_DEVICE_REQUEST Request
;
220 ASSERT (UsbIo
!= NULL
);
223 // Fill Device request packet
225 Request
.RequestType
= USB_HID_CLASS_SET_REQ_TYPE
;
226 Request
.Request
= EFI_USB_SET_PROTOCOL_REQUEST
;
227 Request
.Value
= Protocol
;
228 Request
.Index
= Interface
;
231 Result
= UsbIo
->UsbControlTransfer (
235 PcdGet32 (PcdUsbTransferTimeoutValue
),
244 Set the idle rate of the specified USB HID report.
246 Submit a USB set HID report idle request for the USB device specified by UsbIo,
247 Interface, and ReportId, and set the idle rate to the value specified by Duration.
248 If UsbIo is NULL, then ASSERT().
250 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
251 @param Interface The index of the report interface on the USB target.
252 @param ReportId The identifier of the report to retrieve.
253 @param Duration The idle rate to set for the specified USB target.
255 @retval EFI_SUCCESS The request executed successfully.
256 @retval EFI_TIMEOUT A timeout occurred executing the request.
257 @retval EFI_DEVICE_ERROR The request failed due to a device error.
263 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
271 EFI_USB_DEVICE_REQUEST Request
;
273 ASSERT (UsbIo
!= NULL
);
275 // Fill Device request packet
277 Request
.RequestType
= USB_HID_CLASS_SET_REQ_TYPE
;
278 Request
.Request
= EFI_USB_SET_IDLE_REQUEST
;
279 Request
.Value
= (UINT16
)((Duration
<< 8) | ReportId
);
280 Request
.Index
= Interface
;
283 Result
= UsbIo
->UsbControlTransfer (
287 PcdGet32 (PcdUsbTransferTimeoutValue
),
296 Get the idle rate of the specified USB HID report.
298 Submit a USB get HID report idle request for the USB device specified by UsbIo,
299 Interface, and ReportId, and return the ide rate in Duration.
300 If UsbIo is NULL, then ASSERT().
301 If Duration is NULL, then ASSERT().
303 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
304 @param Interface The index of the report interface on the USB target.
305 @param ReportId The identifier of the report to retrieve.
306 @param Duration A pointer to the idle rate retrieved from the specified USB target.
308 @retval EFI_SUCCESS The request executed successfully.
309 @retval EFI_TIMEOUT A timeout occurred executing the request.
310 @retval EFI_DEVICE_ERROR The request failed due to a device error.
316 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
324 EFI_USB_DEVICE_REQUEST Request
;
326 ASSERT (UsbIo
!= NULL
);
327 ASSERT (Duration
!= NULL
);
329 // Fill Device request packet
331 Request
.RequestType
= USB_HID_CLASS_GET_REQ_TYPE
;
332 Request
.Request
= EFI_USB_GET_IDLE_REQUEST
;
333 Request
.Value
= ReportId
;
334 Request
.Index
= Interface
;
337 Result
= UsbIo
->UsbControlTransfer (
341 PcdGet32 (PcdUsbTransferTimeoutValue
),
351 Set the report descriptor of the specified USB HID interface.
353 Submit a USB set HID report request for the USB device specified by UsbIo,
354 Interface, ReportId, and ReportType, and set the report descriptor using the
355 buffer specified by ReportLength and Report.
356 If UsbIo is NULL, then ASSERT().
357 If Report is NULL, then ASSERT().
359 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
360 @param Interface The index of the report interface on the USB target.
361 @param ReportId The identifier of the report to retrieve.
362 @param ReportType The type of report to retrieve.
363 @param ReportLength The size, in bytes, of Report.
364 @param Report A pointer to the report descriptor buffer to set.
366 @retval EFI_SUCCESS The request executed successfully.
367 @retval EFI_TIMEOUT A timeout occurred executing the request.
368 @retval EFI_DEVICE_ERROR The request failed due to a device error.
373 UsbSetReportRequest (
374 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
384 EFI_USB_DEVICE_REQUEST Request
;
386 ASSERT (UsbIo
!= NULL
);
387 ASSERT (Report
!= NULL
);
390 // Fill Device request packet
392 Request
.RequestType
= USB_HID_CLASS_SET_REQ_TYPE
;
393 Request
.Request
= EFI_USB_SET_REPORT_REQUEST
;
394 Request
.Value
= (UINT16
)((ReportType
<< 8) | ReportId
);
395 Request
.Index
= Interface
;
396 Request
.Length
= ReportLen
;
398 Result
= UsbIo
->UsbControlTransfer (
402 PcdGet32 (PcdUsbTransferTimeoutValue
),
412 Get the report descriptor of the specified USB HID interface.
414 Submit a USB get HID report request for the USB device specified by UsbIo,
415 Interface, ReportId, and ReportType, and return the report in the buffer
417 If UsbIo is NULL, then ASSERT().
418 If Report is NULL, then ASSERT().
420 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
421 @param Interface The index of the report interface on the USB target.
422 @param ReportId The identifier of the report to retrieve.
423 @param ReportType The type of report to retrieve.
424 @param ReportLength The size, in bytes, of Report.
425 @param Report A pointer to the buffer to store the report descriptor.
427 @retval EFI_SUCCESS The request executed successfully.
428 @retval EFI_OUT_OF_RESOURCES The request could not be completed because the
429 buffer specified by ReportLength and Report is not
430 large enough to hold the result of the request.
431 @retval EFI_TIMEOUT A timeout occurred executing the request.
432 @retval EFI_DEVICE_ERROR The request failed due to a device error.
437 UsbGetReportRequest (
438 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
448 EFI_USB_DEVICE_REQUEST Request
;
450 ASSERT (UsbIo
!= NULL
);
451 ASSERT (Report
!= NULL
);
454 // Fill Device request packet
456 Request
.RequestType
= USB_HID_CLASS_GET_REQ_TYPE
;
457 Request
.Request
= EFI_USB_GET_REPORT_REQUEST
;
458 Request
.Value
= (UINT16
)((ReportType
<< 8) | ReportId
);
459 Request
.Index
= Interface
;
460 Request
.Length
= ReportLen
;
462 Result
= UsbIo
->UsbControlTransfer (
466 PcdGet32 (PcdUsbTransferTimeoutValue
),