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"
14 Get the descriptor of the specified USB device.
16 Submit a USB get descriptor request for the USB device specified by UsbIo, Value,
17 and Index, and return the descriptor in the buffer specified by Descriptor.
18 The status of the transfer is returned in Status.
19 If UsbIo is NULL, then ASSERT().
20 If Descriptor is NULL, then ASSERT().
21 If Status is NULL, then ASSERT().
23 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
24 @param Value The device request value.
25 @param Index The device request index.
26 @param DescriptorLength The size, in bytes, of Descriptor.
27 @param Descriptor A pointer to the descriptor buffer to get.
28 @param Status A pointer to the status of the transfer.
30 @retval EFI_SUCCESS The request executed successfully.
31 @retval EFI_OUT_OF_RESOURCES The request could not be completed because the
32 buffer specified by DescriptorLength and Descriptor
33 is not large enough to hold the result of the request.
34 @retval EFI_TIMEOUT A timeout occurred executing the request.
35 @retval EFI_DEVICE_ERROR The request failed due to a device error. The transfer
36 status is returned in Status.
42 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
45 IN UINT16 DescriptorLength
,
50 EFI_USB_DEVICE_REQUEST DevReq
;
52 ASSERT (UsbIo
!= NULL
);
53 ASSERT (Descriptor
!= NULL
);
54 ASSERT (Status
!= NULL
);
56 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
58 DevReq
.RequestType
= USB_DEV_GET_DESCRIPTOR_REQ_TYPE
;
59 DevReq
.Request
= USB_REQ_GET_DESCRIPTOR
;
62 DevReq
.Length
= DescriptorLength
;
64 return UsbIo
->UsbControlTransfer (
68 PcdGet32 (PcdUsbTransferTimeoutValue
),
76 Set the descriptor of the specified USB device.
78 Submit a USB set descriptor request for the USB device specified by UsbIo,
79 Value, and Index, and set the descriptor using the buffer specified by DesriptorLength
80 and Descriptor. The status of the transfer is returned in Status.
81 If UsbIo is NULL, then ASSERT().
82 If Descriptor is NULL, then ASSERT().
83 If Status is NULL, then ASSERT().
85 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
86 @param Value The device request value.
87 @param Index The device request index.
88 @param DescriptorLength The size, in bytes, of Descriptor.
89 @param Descriptor A pointer to the descriptor buffer to set.
90 @param Status A pointer to the status of the transfer.
92 @retval EFI_SUCCESS The request executed successfully.
93 @retval EFI_TIMEOUT A timeout occurred executing the request.
94 @retval EFI_DEVICE_ERROR The request failed due to a device error.
95 The transfer status is returned in Status.
101 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
104 IN UINT16 DescriptorLength
,
109 EFI_USB_DEVICE_REQUEST DevReq
;
111 ASSERT (UsbIo
!= NULL
);
112 ASSERT (Descriptor
!= NULL
);
113 ASSERT (Status
!= NULL
);
115 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
117 DevReq
.RequestType
= USB_DEV_SET_DESCRIPTOR_REQ_TYPE
;
118 DevReq
.Request
= USB_REQ_SET_DESCRIPTOR
;
119 DevReq
.Value
= Value
;
120 DevReq
.Index
= Index
;
121 DevReq
.Length
= DescriptorLength
;
123 return UsbIo
->UsbControlTransfer (
127 PcdGet32 (PcdUsbTransferTimeoutValue
),
135 Get the interface setting of the specified USB device.
137 Submit a USB get interface request for the USB device specified by UsbIo,
138 and Interface, and place the result in the buffer specified by AlternateSetting.
139 The status of the transfer is returned in Status.
140 If UsbIo is NULL, then ASSERT().
141 If AlternateSetting is NULL, then ASSERT().
142 If Status is NULL, then ASSERT().
144 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
145 @param Interface The interface index value.
146 @param AlternateSetting A pointer to the alternate setting to be retrieved.
147 @param Status A pointer to the status of the transfer.
149 @retval EFI_SUCCESS The request executed successfully.
150 @retval EFI_TIMEOUT A timeout occurred executing the request.
151 @retval EFI_DEVICE_ERROR The request failed due to a device error.
152 The transfer status is returned in Status.
158 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
160 OUT UINT16
*AlternateSetting
,
164 EFI_USB_DEVICE_REQUEST DevReq
;
166 ASSERT (UsbIo
!= NULL
);
167 ASSERT (AlternateSetting
!= NULL
);
168 ASSERT (Status
!= NULL
);
170 *AlternateSetting
= 0;
172 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
174 DevReq
.RequestType
= USB_DEV_GET_INTERFACE_REQ_TYPE
;
175 DevReq
.Request
= USB_REQ_GET_INTERFACE
;
176 DevReq
.Index
= Interface
;
179 return UsbIo
->UsbControlTransfer (
183 PcdGet32 (PcdUsbTransferTimeoutValue
),
191 Set the interface setting of the specified USB device.
193 Submit a USB set interface request for the USB device specified by UsbIo, and
194 Interface, and set the alternate setting to the value specified by AlternateSetting.
195 The status of the transfer is returned in Status.
196 If UsbIo is NULL, then ASSERT().
197 If Status 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 interface index value.
201 @param AlternateSetting The alternate setting to be set.
202 @param Status A pointer to the status of the transfer.
204 @retval EFI_SUCCESS The request executed successfully.
205 @retval EFI_TIMEOUT A timeout occurred executing the request.
206 @retval EFI_SUCCESS The request failed due to a device error.
207 The transfer status is returned in Status.
213 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
215 IN UINT16 AlternateSetting
,
219 EFI_USB_DEVICE_REQUEST DevReq
;
221 ASSERT (UsbIo
!= NULL
);
222 ASSERT (Status
!= NULL
);
224 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
226 DevReq
.RequestType
= USB_DEV_SET_INTERFACE_REQ_TYPE
;
227 DevReq
.Request
= USB_REQ_SET_INTERFACE
;
228 DevReq
.Value
= AlternateSetting
;
229 DevReq
.Index
= Interface
;
231 return UsbIo
->UsbControlTransfer (
235 PcdGet32 (PcdUsbTransferTimeoutValue
),
243 Get the device configuration.
245 Submit a USB get configuration request for the USB device specified by UsbIo
246 and place the result in the buffer specified by ConfigurationValue. The status
247 of the transfer is returned in Status.
248 If UsbIo is NULL, then ASSERT().
249 If ConfigurationValue is NULL, then ASSERT().
250 If Status is NULL, then ASSERT().
252 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
253 @param ConfigurationValue A pointer to the device configuration to be retrieved.
254 @param Status A pointer to the status of the transfer.
256 @retval EFI_SUCCESS The request executed successfully.
257 @retval EFI_TIMEOUT A timeout occurred executing the request.
258 @retval EFI_DEVICE_ERROR The request failed due to a device error.
259 The transfer status is returned in Status.
264 UsbGetConfiguration (
265 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
266 OUT UINT16
*ConfigurationValue
,
270 EFI_USB_DEVICE_REQUEST DevReq
;
272 ASSERT (UsbIo
!= NULL
);
273 ASSERT (ConfigurationValue
!= NULL
);
274 ASSERT (Status
!= NULL
);
276 *ConfigurationValue
= 0;
278 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
280 DevReq
.RequestType
= USB_DEV_GET_CONFIGURATION_REQ_TYPE
;
281 DevReq
.Request
= USB_REQ_GET_CONFIG
;
284 return UsbIo
->UsbControlTransfer (
288 PcdGet32 (PcdUsbTransferTimeoutValue
),
296 Set the device configuration.
298 Submit a USB set configuration request for the USB device specified by UsbIo
299 and set the device configuration to the value specified by ConfigurationValue.
300 The status of the transfer is returned in Status.
301 If UsbIo is NULL, then ASSERT().
302 If Status is NULL, then ASSERT().
304 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
305 @param ConfigurationValue The device configuration value to be set.
306 @param Status A pointer to the status of the transfer.
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.
311 The transfer status is returned in Status.
316 UsbSetConfiguration (
317 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
318 IN UINT16 ConfigurationValue
,
322 EFI_USB_DEVICE_REQUEST DevReq
;
324 ASSERT (UsbIo
!= NULL
);
325 ASSERT (Status
!= NULL
);
327 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
329 DevReq
.RequestType
= USB_DEV_SET_CONFIGURATION_REQ_TYPE
;
330 DevReq
.Request
= USB_REQ_SET_CONFIG
;
331 DevReq
.Value
= ConfigurationValue
;
333 return UsbIo
->UsbControlTransfer (
337 PcdGet32 (PcdUsbTransferTimeoutValue
),
345 Set the specified feature of the specified device.
347 Submit a USB set device feature request for the USB device specified by UsbIo,
348 Recipient, and Target to the value specified by Value. The status of the
349 transfer is returned in Status.
350 If UsbIo is NULL, then ASSERT().
351 If Status is NULL, then ASSERT().
353 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
354 @param Recipient The USB data recipient type (i.e. Device, Interface, Endpoint).
355 Type USB_TYPES_DEFINITION is defined in the MDE Package Industry
356 Standard include file Usb.h.
357 @param Value The value of the feature to be set.
358 @param Target The index of the device to be set.
359 @param Status A pointer to the status of the transfer.
361 @retval EFI_SUCCESS The request executed successfully.
362 @retval EFI_TIMEOUT A timeout occurred executing the request.
363 @retval EFI_DEVICE_ERROR The request failed due to a device error.
364 The transfer status is returned in Status.
370 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
371 IN USB_TYPES_DEFINITION Recipient
,
377 EFI_USB_DEVICE_REQUEST DevReq
;
379 ASSERT (UsbIo
!= NULL
);
380 ASSERT (Status
!= NULL
);
382 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
385 case USB_TARGET_DEVICE
:
386 DevReq
.RequestType
= USB_DEV_SET_FEATURE_REQ_TYPE_D
;
389 case USB_TARGET_INTERFACE
:
390 DevReq
.RequestType
= USB_DEV_SET_FEATURE_REQ_TYPE_I
;
393 case USB_TARGET_ENDPOINT
:
394 DevReq
.RequestType
= USB_DEV_SET_FEATURE_REQ_TYPE_E
;
402 // Fill device request, see USB1.1 spec
404 DevReq
.Request
= USB_REQ_SET_FEATURE
;
405 DevReq
.Value
= Value
;
406 DevReq
.Index
= Target
;
408 return UsbIo
->UsbControlTransfer (
412 PcdGet32 (PcdUsbTransferTimeoutValue
),
420 Clear the specified feature of the specified device.
422 Submit a USB clear device feature request for the USB device specified by UsbIo,
423 Recipient, and Target to the value specified by Value. The status of the transfer
424 is returned in Status.
425 If UsbIo is NULL, then ASSERT().
426 If Status is NULL, then ASSERT().
428 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
429 @param Recipient The USB data recipient type (i.e. Device, Interface, Endpoint).
430 Type USB_TYPES_DEFINITION is defined in the MDE Package Industry Standard
432 @param Value The value of the feature to be cleared.
433 @param Target The index of the device to be cleared.
434 @param Status A pointer to the status of the transfer.
436 @retval EFI_SUCCESS The request executed successfully.
437 @retval EFI_TIMEOUT A timeout occurred executing the request.
438 @retval EFI_DEVICE_ERROR The request failed due to a device error.
439 The transfer status is returned in Status.
445 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
446 IN USB_TYPES_DEFINITION Recipient
,
452 EFI_USB_DEVICE_REQUEST DevReq
;
454 ASSERT (UsbIo
!= NULL
);
455 ASSERT (Status
!= NULL
);
457 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
460 case USB_TARGET_DEVICE
:
461 DevReq
.RequestType
= USB_DEV_CLEAR_FEATURE_REQ_TYPE_D
;
464 case USB_TARGET_INTERFACE
:
465 DevReq
.RequestType
= USB_DEV_CLEAR_FEATURE_REQ_TYPE_I
;
468 case USB_TARGET_ENDPOINT
:
469 DevReq
.RequestType
= USB_DEV_CLEAR_FEATURE_REQ_TYPE_E
;
477 // Fill device request, see USB1.1 spec
479 DevReq
.Request
= USB_REQ_CLEAR_FEATURE
;
480 DevReq
.Value
= Value
;
481 DevReq
.Index
= Target
;
483 return UsbIo
->UsbControlTransfer (
487 PcdGet32 (PcdUsbTransferTimeoutValue
),
495 Get the status of the specified device.
497 Submit a USB device get status request for the USB device specified by UsbIo,
498 Recipient, and Target and place the result in the buffer specified by DeviceStatus.
499 The status of the transfer is returned in Status.
500 If UsbIo is NULL, then ASSERT().
501 If DeviceStatus is NULL, then ASSERT().
502 If Status is NULL, then ASSERT().
504 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
505 @param Recipient The USB data recipient type (i.e. Device, Interface, Endpoint).
506 Type USB_TYPES_DEFINITION is defined in the MDE Package Industry Standard
508 @param Target The index of the device to be get the status of.
509 @param DeviceStatus A pointer to the device status to be retrieved.
510 @param Status A pointer to the status of the transfer.
512 @retval EFI_SUCCESS The request executed successfully.
513 @retval EFI_TIMEOUT A timeout occurred executing the request.
514 @retval EFI_DEVICE_ERROR The request failed due to a device error.
515 The transfer status is returned in Status.
521 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
522 IN USB_TYPES_DEFINITION Recipient
,
524 OUT UINT16
*DeviceStatus
,
528 EFI_USB_DEVICE_REQUEST DevReq
;
530 ASSERT (UsbIo
!= NULL
);
531 ASSERT (DeviceStatus
!= NULL
);
532 ASSERT (Status
!= NULL
);
534 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
537 case USB_TARGET_DEVICE
:
538 DevReq
.RequestType
= USB_DEV_GET_STATUS_REQ_TYPE_D
;
541 case USB_TARGET_INTERFACE
:
542 DevReq
.RequestType
= USB_DEV_GET_STATUS_REQ_TYPE_I
;
545 case USB_TARGET_ENDPOINT
:
546 DevReq
.RequestType
= USB_DEV_GET_STATUS_REQ_TYPE_E
;
554 // Fill device request, see USB1.1 spec
556 DevReq
.Request
= USB_REQ_GET_STATUS
;
558 DevReq
.Index
= Target
;
561 return UsbIo
->UsbControlTransfer (
565 PcdGet32 (PcdUsbTransferTimeoutValue
),
573 Clear halt feature of the specified usb endpoint.
575 Retrieve the USB endpoint descriptor specified by UsbIo and EndPoint.
576 If the USB endpoint descriptor can not be retrieved, then return EFI_NOT_FOUND.
577 If the endpoint descriptor is found, then clear the halt feature of this USB endpoint.
578 The status of the transfer is returned in Status.
579 If UsbIo is NULL, then ASSERT().
580 If Status is NULL, then ASSERT().
582 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
583 @param Endpoint The endpoint address.
584 @param Status A pointer to the status of the transfer.
586 @retval EFI_SUCCESS The request executed successfully.
587 @retval EFI_TIMEOUT A timeout occurred executing the request.
588 @retval EFI_DEVICE_ERROR The request failed due to a device error.
589 The transfer status is returned in Status.
590 @retval EFI_NOT_FOUND The specified USB endpoint descriptor can not be found
595 UsbClearEndpointHalt (
596 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
602 EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor
;
603 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor
;
606 ASSERT (UsbIo
!= NULL
);
607 ASSERT (Status
!= NULL
);
609 ZeroMem (&EndpointDescriptor
, sizeof (EFI_USB_ENDPOINT_DESCRIPTOR
));
611 // First search the endpoint descriptor for that endpoint addr
613 Result
= UsbIo
->UsbGetInterfaceDescriptor (
617 if (EFI_ERROR (Result
)) {
621 for (Index
= 0; Index
< InterfaceDescriptor
.NumEndpoints
; Index
++) {
622 Result
= UsbIo
->UsbGetEndpointDescriptor (
627 if (EFI_ERROR (Result
)) {
631 if (EndpointDescriptor
.EndpointAddress
== Endpoint
) {
636 if (Index
== InterfaceDescriptor
.NumEndpoints
) {
640 return EFI_NOT_FOUND
;
643 Result
= UsbClearFeature (
646 USB_FEATURE_ENDPOINT_HALT
,
647 EndpointDescriptor
.EndpointAddress
,