3 The library provides the USB Standard Device Requests defined
4 in Usb specification 9.4 section.
6 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include "UefiUsbLibInternal.h"
15 Get the descriptor of the specified USB device.
17 Submit a USB get descriptor request for the USB device specified by UsbIo, Value,
18 and Index, and return the descriptor in the buffer specified by Descriptor.
19 The status of the transfer is returned in Status.
20 If UsbIo is NULL, then ASSERT().
21 If Descriptor is NULL, then ASSERT().
22 If Status is NULL, then ASSERT().
24 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
25 @param Value The device request value.
26 @param Index The device request index.
27 @param DescriptorLength The size, in bytes, of Descriptor.
28 @param Descriptor A pointer to the descriptor buffer to get.
29 @param Status A pointer to the status of the transfer.
31 @retval EFI_SUCCESS The request executed successfully.
32 @retval EFI_OUT_OF_RESOURCES The request could not be completed because the
33 buffer specified by DescriptorLength and Descriptor
34 is not large enough to hold the result of the request.
35 @retval EFI_TIMEOUT A timeout occurred executing the request.
36 @retval EFI_DEVICE_ERROR The request failed due to a device error. The transfer
37 status is returned in Status.
43 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
46 IN UINT16 DescriptorLength
,
51 EFI_USB_DEVICE_REQUEST DevReq
;
53 ASSERT (UsbIo
!= NULL
);
54 ASSERT (Descriptor
!= NULL
);
55 ASSERT (Status
!= NULL
);
57 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
59 DevReq
.RequestType
= USB_DEV_GET_DESCRIPTOR_REQ_TYPE
;
60 DevReq
.Request
= USB_REQ_GET_DESCRIPTOR
;
63 DevReq
.Length
= DescriptorLength
;
65 return UsbIo
->UsbControlTransfer (
69 PcdGet32 (PcdUsbTransferTimeoutValue
),
78 Set the descriptor of the specified USB device.
80 Submit a USB set descriptor request for the USB device specified by UsbIo,
81 Value, and Index, and set the descriptor using the buffer specified by DesriptorLength
82 and Descriptor. The status of the transfer is returned in Status.
83 If UsbIo is NULL, then ASSERT().
84 If Descriptor is NULL, then ASSERT().
85 If Status is NULL, then ASSERT().
87 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
88 @param Value The device request value.
89 @param Index The device request index.
90 @param DescriptorLength The size, in bytes, of Descriptor.
91 @param Descriptor A pointer to the descriptor buffer to set.
92 @param Status A pointer to the status of the transfer.
94 @retval EFI_SUCCESS The request executed successfully.
95 @retval EFI_TIMEOUT A timeout occurred executing the request.
96 @retval EFI_DEVICE_ERROR The request failed due to a device error.
97 The transfer status is returned in Status.
103 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
106 IN UINT16 DescriptorLength
,
111 EFI_USB_DEVICE_REQUEST DevReq
;
113 ASSERT (UsbIo
!= NULL
);
114 ASSERT (Descriptor
!= NULL
);
115 ASSERT (Status
!= NULL
);
117 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
119 DevReq
.RequestType
= USB_DEV_SET_DESCRIPTOR_REQ_TYPE
;
120 DevReq
.Request
= USB_REQ_SET_DESCRIPTOR
;
121 DevReq
.Value
= Value
;
122 DevReq
.Index
= Index
;
123 DevReq
.Length
= DescriptorLength
;
125 return UsbIo
->UsbControlTransfer (
129 PcdGet32 (PcdUsbTransferTimeoutValue
),
138 Get the interface setting of the specified USB device.
140 Submit a USB get interface request for the USB device specified by UsbIo,
141 and Interface, and place the result in the buffer specified by AlternateSetting.
142 The status of the transfer is returned in Status.
143 If UsbIo is NULL, then ASSERT().
144 If AlternateSetting is NULL, then ASSERT().
145 If Status is NULL, then ASSERT().
147 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
148 @param Interface The interface index value.
149 @param AlternateSetting A pointer to the alternate setting to be retrieved.
150 @param Status A pointer to the status of the transfer.
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.
155 The transfer status is returned in Status.
161 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
163 OUT UINT16
*AlternateSetting
,
167 EFI_USB_DEVICE_REQUEST DevReq
;
169 ASSERT (UsbIo
!= NULL
);
170 ASSERT (AlternateSetting
!= NULL
);
171 ASSERT (Status
!= NULL
);
173 *AlternateSetting
= 0;
175 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
177 DevReq
.RequestType
= USB_DEV_GET_INTERFACE_REQ_TYPE
;
178 DevReq
.Request
= USB_REQ_GET_INTERFACE
;
179 DevReq
.Index
= Interface
;
182 return UsbIo
->UsbControlTransfer (
186 PcdGet32 (PcdUsbTransferTimeoutValue
),
195 Set the interface setting of the specified USB device.
197 Submit a USB set interface request for the USB device specified by UsbIo, and
198 Interface, and set the alternate setting to the value specified by AlternateSetting.
199 The status of the transfer is returned in Status.
200 If UsbIo is NULL, then ASSERT().
201 If Status 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 interface index value.
205 @param AlternateSetting The alternate setting to be set.
206 @param Status A pointer to the status of the transfer.
208 @retval EFI_SUCCESS The request executed successfully.
209 @retval EFI_TIMEOUT A timeout occurred executing the request.
210 @retval EFI_SUCCESS The request failed due to a device error.
211 The transfer status is returned in Status.
217 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
219 IN UINT16 AlternateSetting
,
223 EFI_USB_DEVICE_REQUEST DevReq
;
225 ASSERT (UsbIo
!= NULL
);
226 ASSERT (Status
!= NULL
);
228 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
230 DevReq
.RequestType
= USB_DEV_SET_INTERFACE_REQ_TYPE
;
231 DevReq
.Request
= USB_REQ_SET_INTERFACE
;
232 DevReq
.Value
= AlternateSetting
;
233 DevReq
.Index
= Interface
;
235 return UsbIo
->UsbControlTransfer (
239 PcdGet32 (PcdUsbTransferTimeoutValue
),
248 Get the device configuration.
250 Submit a USB get configuration request for the USB device specified by UsbIo
251 and place the result in the buffer specified by ConfigurationValue. The status
252 of the transfer is returned in Status.
253 If UsbIo is NULL, then ASSERT().
254 If ConfigurationValue is NULL, then ASSERT().
255 If Status is NULL, then ASSERT().
257 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
258 @param ConfigurationValue A pointer to the device configuration to be retrieved.
259 @param Status A pointer to the status of the transfer.
261 @retval EFI_SUCCESS The request executed successfully.
262 @retval EFI_TIMEOUT A timeout occurred executing the request.
263 @retval EFI_DEVICE_ERROR The request failed due to a device error.
264 The transfer status is returned in Status.
269 UsbGetConfiguration (
270 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
271 OUT UINT16
*ConfigurationValue
,
275 EFI_USB_DEVICE_REQUEST DevReq
;
277 ASSERT (UsbIo
!= NULL
);
278 ASSERT (ConfigurationValue
!= NULL
);
279 ASSERT (Status
!= NULL
);
281 *ConfigurationValue
= 0;
283 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
285 DevReq
.RequestType
= USB_DEV_GET_CONFIGURATION_REQ_TYPE
;
286 DevReq
.Request
= USB_REQ_GET_CONFIG
;
289 return UsbIo
->UsbControlTransfer (
293 PcdGet32 (PcdUsbTransferTimeoutValue
),
302 Set the device configuration.
304 Submit a USB set configuration request for the USB device specified by UsbIo
305 and set the device configuration to the value specified by ConfigurationValue.
306 The status of the transfer is returned in Status.
307 If UsbIo is NULL, then ASSERT().
308 If Status is NULL, then ASSERT().
310 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
311 @param ConfigurationValue The device configuration value to be set.
312 @param Status A pointer to the status of the transfer.
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.
317 The transfer status is returned in Status.
322 UsbSetConfiguration (
323 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
324 IN UINT16 ConfigurationValue
,
328 EFI_USB_DEVICE_REQUEST DevReq
;
330 ASSERT (UsbIo
!= NULL
);
331 ASSERT (Status
!= NULL
);
333 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
335 DevReq
.RequestType
= USB_DEV_SET_CONFIGURATION_REQ_TYPE
;
336 DevReq
.Request
= USB_REQ_SET_CONFIG
;
337 DevReq
.Value
= ConfigurationValue
;
339 return UsbIo
->UsbControlTransfer (
343 PcdGet32 (PcdUsbTransferTimeoutValue
),
352 Set the specified feature of the specified device.
354 Submit a USB set device feature request for the USB device specified by UsbIo,
355 Recipient, and Target to the value specified by Value. The status of the
356 transfer is returned in Status.
357 If UsbIo is NULL, then ASSERT().
358 If Status is NULL, then ASSERT().
360 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
361 @param Recipient The USB data recipient type (i.e. Device, Interface, Endpoint).
362 Type USB_TYPES_DEFINITION is defined in the MDE Package Industry
363 Standard include file Usb.h.
364 @param Value The value of the feature to be set.
365 @param Target The index of the device to be set.
366 @param Status A pointer to the status of the transfer.
368 @retval EFI_SUCCESS The request executed successfully.
369 @retval EFI_TIMEOUT A timeout occurred executing the request.
370 @retval EFI_DEVICE_ERROR The request failed due to a device error.
371 The transfer status is returned in Status.
377 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
378 IN USB_TYPES_DEFINITION Recipient
,
384 EFI_USB_DEVICE_REQUEST DevReq
;
386 ASSERT (UsbIo
!= NULL
);
387 ASSERT (Status
!= NULL
);
389 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
393 case USB_TARGET_DEVICE
:
394 DevReq
.RequestType
= USB_DEV_SET_FEATURE_REQ_TYPE_D
;
397 case USB_TARGET_INTERFACE
:
398 DevReq
.RequestType
= USB_DEV_SET_FEATURE_REQ_TYPE_I
;
401 case USB_TARGET_ENDPOINT
:
402 DevReq
.RequestType
= USB_DEV_SET_FEATURE_REQ_TYPE_E
;
409 // Fill device request, see USB1.1 spec
411 DevReq
.Request
= USB_REQ_SET_FEATURE
;
412 DevReq
.Value
= Value
;
413 DevReq
.Index
= Target
;
416 return UsbIo
->UsbControlTransfer (
420 PcdGet32 (PcdUsbTransferTimeoutValue
),
429 Clear the specified feature of the specified device.
431 Submit a USB clear device feature request for the USB device specified by UsbIo,
432 Recipient, and Target to the value specified by Value. The status of the transfer
433 is returned in Status.
434 If UsbIo is NULL, then ASSERT().
435 If Status is NULL, then ASSERT().
437 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
438 @param Recipient The USB data recipient type (i.e. Device, Interface, Endpoint).
439 Type USB_TYPES_DEFINITION is defined in the MDE Package Industry Standard
441 @param Value The value of the feature to be cleared.
442 @param Target The index of the device to be cleared.
443 @param Status A pointer to the status of the transfer.
445 @retval EFI_SUCCESS The request executed successfully.
446 @retval EFI_TIMEOUT A timeout occurred executing the request.
447 @retval EFI_DEVICE_ERROR The request failed due to a device error.
448 The transfer status is returned in Status.
454 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
455 IN USB_TYPES_DEFINITION Recipient
,
461 EFI_USB_DEVICE_REQUEST DevReq
;
463 ASSERT (UsbIo
!= NULL
);
464 ASSERT (Status
!= NULL
);
467 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
471 case USB_TARGET_DEVICE
:
472 DevReq
.RequestType
= USB_DEV_CLEAR_FEATURE_REQ_TYPE_D
;
475 case USB_TARGET_INTERFACE
:
476 DevReq
.RequestType
= USB_DEV_CLEAR_FEATURE_REQ_TYPE_I
;
479 case USB_TARGET_ENDPOINT
:
480 DevReq
.RequestType
= USB_DEV_CLEAR_FEATURE_REQ_TYPE_E
;
487 // Fill device request, see USB1.1 spec
489 DevReq
.Request
= USB_REQ_CLEAR_FEATURE
;
490 DevReq
.Value
= Value
;
491 DevReq
.Index
= Target
;
494 return UsbIo
->UsbControlTransfer (
498 PcdGet32 (PcdUsbTransferTimeoutValue
),
507 Get the status of the specified device.
509 Submit a USB device get status request for the USB device specified by UsbIo,
510 Recipient, and Target and place the result in the buffer specified by DeviceStatus.
511 The status of the transfer is returned in Status.
512 If UsbIo is NULL, then ASSERT().
513 If DeviceStatus is NULL, then ASSERT().
514 If Status is NULL, then ASSERT().
516 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
517 @param Recipient The USB data recipient type (i.e. Device, Interface, Endpoint).
518 Type USB_TYPES_DEFINITION is defined in the MDE Package Industry Standard
520 @param Target The index of the device to be get the status of.
521 @param DeviceStatus A pointer to the device status to be retrieved.
522 @param Status A pointer to the status of the transfer.
524 @retval EFI_SUCCESS The request executed successfully.
525 @retval EFI_TIMEOUT A timeout occurred executing the request.
526 @retval EFI_DEVICE_ERROR The request failed due to a device error.
527 The transfer status is returned in Status.
533 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
534 IN USB_TYPES_DEFINITION Recipient
,
536 OUT UINT16
*DeviceStatus
,
540 EFI_USB_DEVICE_REQUEST DevReq
;
542 ASSERT (UsbIo
!= NULL
);
543 ASSERT (DeviceStatus
!= NULL
);
544 ASSERT (Status
!= NULL
);
546 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
550 case USB_TARGET_DEVICE
:
551 DevReq
.RequestType
= USB_DEV_GET_STATUS_REQ_TYPE_D
;
554 case USB_TARGET_INTERFACE
:
555 DevReq
.RequestType
= USB_DEV_GET_STATUS_REQ_TYPE_I
;
558 case USB_TARGET_ENDPOINT
:
559 DevReq
.RequestType
= USB_DEV_GET_STATUS_REQ_TYPE_E
;
566 // Fill device request, see USB1.1 spec
568 DevReq
.Request
= USB_REQ_GET_STATUS
;
570 DevReq
.Index
= Target
;
573 return UsbIo
->UsbControlTransfer (
577 PcdGet32 (PcdUsbTransferTimeoutValue
),
586 Clear halt feature of the specified usb endpoint.
588 Retrieve the USB endpoint descriptor specified by UsbIo and EndPoint.
589 If the USB endpoint descriptor can not be retrieved, then return EFI_NOT_FOUND.
590 If the endpoint descriptor is found, then clear the halt feature of this USB endpoint.
591 The status of the transfer is returned in Status.
592 If UsbIo is NULL, then ASSERT().
593 If Status is NULL, then ASSERT().
595 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
596 @param Endpoint The endpoint address.
597 @param Status A pointer to the status of the transfer.
599 @retval EFI_SUCCESS The request executed successfully.
600 @retval EFI_TIMEOUT A timeout occurred executing the request.
601 @retval EFI_DEVICE_ERROR The request failed due to a device error.
602 The transfer status is returned in Status.
603 @retval EFI_NOT_FOUND The specified USB endpoint descriptor can not be found
608 UsbClearEndpointHalt (
609 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
615 EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor
;
616 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor
;
619 ASSERT (UsbIo
!= NULL
);
620 ASSERT (Status
!= NULL
);
622 ZeroMem (&EndpointDescriptor
, sizeof (EFI_USB_ENDPOINT_DESCRIPTOR
));
624 // First search the endpoint descriptor for that endpoint addr
626 Result
= UsbIo
->UsbGetInterfaceDescriptor (
630 if (EFI_ERROR (Result
)) {
634 for (Index
= 0; Index
< InterfaceDescriptor
.NumEndpoints
; Index
++) {
635 Result
= UsbIo
->UsbGetEndpointDescriptor (
640 if (EFI_ERROR (Result
)) {
644 if (EndpointDescriptor
.EndpointAddress
== Endpoint
) {
649 if (Index
== InterfaceDescriptor
.NumEndpoints
) {
653 return EFI_NOT_FOUND
;
656 Result
= UsbClearFeature (
659 USB_FEATURE_ENDPOINT_HALT
,
660 EndpointDescriptor
.EndpointAddress
,