3 The library provides the USB Standard Device Requests defined
4 in Usb specification 9.4 section.
6 Copyright (c) 2004 - 2007, Intel Corporation All rights
7 reserved. This program and the accompanying materials are
8 licensed and made available under the terms and conditions of
9 the BSD License which accompanies this distribution. The full
10 text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include "UefiUsbLibInternal.h"
22 Get the descriptor of the specified USB device.
24 Submit a USB get descriptor request for the USB device specified by UsbIo, Value,
25 and Index, and return the descriptor in the buffer specified by Descriptor.
26 The status of the transfer is returned in Status.
27 If UsbIo is NULL, then ASSERT().
28 If Descriptor is NULL, then ASSERT().
29 If Status is NULL, then ASSERT().
31 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
32 @param Value The device request value.
33 @param Index The device request index.
34 @param DescriptorLength The size, in bytes, of Descriptor.
35 @param Descriptor A pointer to the descriptor buffer to get.
36 @param Status A pointer to the status of the transfer.
38 @retval EFI_SUCCESS The request executed successfully.
39 @retval EFI_OUT_OF_RESOURCES The request could not be completed because the
40 buffer specifed by DescriptorLength and Descriptor
41 is not large enough to hold the result of the request.
42 @retval EFI_TIMEOUT A timeout occurred executing the request.
43 @retval EFI_DEVICE_ERROR The request failed due to a device error. The transfer
44 status is returned in Status.
50 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
53 IN UINT16 DescriptorLength
,
58 EFI_USB_DEVICE_REQUEST DevReq
;
60 ASSERT (UsbIo
!= NULL
);
61 ASSERT (Descriptor
!= NULL
);
62 ASSERT (Status
!= NULL
);
64 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
66 DevReq
.RequestType
= USB_DEV_GET_DESCRIPTOR_REQ_TYPE
;
67 DevReq
.Request
= USB_REQ_GET_DESCRIPTOR
;
70 DevReq
.Length
= DescriptorLength
;
72 return UsbIo
->UsbControlTransfer (
85 Set the descriptor of the specified USB device.
87 Submit a USB set descriptor request for the USB device specified by UsbIo,
88 Value, and Index, and set the descriptor using the buffer specified by DesriptorLength
89 and Descriptor. The status of the transfer is returned in Status.
90 If UsbIo is NULL, then ASSERT().
91 If Descriptor is NULL, then ASSERT().
92 If Status is NULL, then ASSERT().
94 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
95 @param Value The device request value.
96 @param Index The device request index.
97 @param DescriptorLength The size, in bytes, of Descriptor.
98 @param Descriptor A pointer to the descriptor buffer to set.
99 @param Status A pointer to the status of the transfer.
101 @retval EFI_SUCCESS The request executed successfully.
102 @retval EFI_TIMEOUT A timeout occurred executing the request.
103 @retval EFI_DEVICE_ERROR The request failed due to a device error.
104 The transfer status is returned in Status.
110 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
113 IN UINT16 DescriptorLength
,
118 EFI_USB_DEVICE_REQUEST DevReq
;
120 ASSERT (UsbIo
!= NULL
);
121 ASSERT (Descriptor
!= NULL
);
122 ASSERT (Status
!= NULL
);
124 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
126 DevReq
.RequestType
= USB_DEV_SET_DESCRIPTOR_REQ_TYPE
;
127 DevReq
.Request
= USB_REQ_SET_DESCRIPTOR
;
128 DevReq
.Value
= Value
;
129 DevReq
.Index
= Index
;
130 DevReq
.Length
= DescriptorLength
;
132 return UsbIo
->UsbControlTransfer (
145 Get the interface setting of the specified USB device.
147 Submit a USB get interface request for the USB device specified by UsbIo,
148 and Interface, and place the result in the buffer specified by AlternateSetting.
149 The status of the transfer is returned in Status.
150 If UsbIo is NULL, then ASSERT().
151 If AlternateSetting is NULL, then ASSERT().
152 If Status 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 interface index value.
156 @param AlternateSetting A pointer to the alternate setting to be retrieved.
157 @param Status A pointer to the status of the transfer.
159 @retval EFI_SUCCESS The request executed successfully.
160 @retval EFI_TIMEOUT A timeout occurred executing the request.
161 @retval EFI_DEVICE_ERROR The request failed due to a device error.
162 The transfer status is returned in Status.
168 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
170 OUT UINT8
*AlternateSetting
,
174 EFI_USB_DEVICE_REQUEST DevReq
;
176 ASSERT (UsbIo
!= NULL
);
177 ASSERT (AlternateSetting
!= NULL
);
178 ASSERT (Status
!= NULL
);
180 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
182 DevReq
.RequestType
= USB_DEV_GET_INTERFACE_REQ_TYPE
;
183 DevReq
.Request
= USB_REQ_GET_INTERFACE
;
184 DevReq
.Index
= Interface
;
187 return UsbIo
->UsbControlTransfer (
200 Set the interface setting of the specified USB device.
202 Submit a USB set interface request for the USB device specified by UsbIo, and
203 Interface, and set the alternate setting to the value specified by AlternateSetting.
204 The status of the transfer is returned in Status.
205 If UsbIo is NULL, then ASSERT().
206 If Status is NULL, then ASSERT().
208 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
209 @param Interface The interface index value.
210 @param AlternateSetting The alternate setting to be set.
211 @param Status A pointer to the status of the transfer.
213 @retval EFI_SUCCESS The request executed successfully.
214 @retval EFI_TIMEOUT A timeout occurred executing the request.
215 @retval EFI_SUCCESS The request failed due to a device error.
216 The transfer status is returned in Status.
222 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
224 IN UINT16 AlternateSetting
,
228 EFI_USB_DEVICE_REQUEST DevReq
;
230 ASSERT (UsbIo
!= NULL
);
231 ASSERT (Status
!= NULL
);
233 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
235 DevReq
.RequestType
= USB_DEV_SET_INTERFACE_REQ_TYPE
;
236 DevReq
.Request
= USB_REQ_SET_INTERFACE
;
237 DevReq
.Value
= AlternateSetting
;
238 DevReq
.Index
= Interface
;
240 return UsbIo
->UsbControlTransfer (
253 Get the device configuration.
255 Submit a USB get configuration request for the USB device specified by UsbIo
256 and place the result in the buffer specified by ConfigurationValue. The status
257 of the transfer is returned in Status.
258 If UsbIo is NULL, then ASSERT().
259 If ConfigurationValue is NULL, then ASSERT().
260 If Status is NULL, then ASSERT().
262 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
263 @param ConfigurationValue A pointer to the device configuration to be retrieved.
264 @param Status A pointer to the status of the transfer.
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.
269 The transfer status is returned in Status.
274 UsbGetConfiguration (
275 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
276 OUT UINT8
*ConfigurationValue
,
280 EFI_USB_DEVICE_REQUEST DevReq
;
282 ASSERT (UsbIo
!= NULL
);
283 ASSERT (ConfigurationValue
!= NULL
);
284 ASSERT (Status
!= NULL
);
286 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
288 DevReq
.RequestType
= USB_DEV_GET_CONFIGURATION_REQ_TYPE
;
289 DevReq
.Request
= USB_REQ_GET_CONFIG
;
292 return UsbIo
->UsbControlTransfer (
305 Set the device configuration.
307 Submit a USB set configuration request for the USB device specified by UsbIo
308 and set the device configuration to the value specified by ConfigurationValue.
309 The status of the transfer is returned in Status.
310 If UsbIo is NULL, then ASSERT().
311 If Status is NULL, then ASSERT().
313 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
314 @param ConfigurationValue The device configuration value to be set.
315 @param Status A pointer to the status of the transfer.
317 @retval EFI_SUCCESS The request executed successfully.
318 @retval EFI_TIMEOUT A timeout occurred executing the request.
319 @retval EFI_DEVICE_ERROR The request failed due to a device error.
320 The transfer status is returned in Status.
325 UsbSetConfiguration (
326 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
327 IN UINT16 ConfigurationValue
,
331 EFI_USB_DEVICE_REQUEST DevReq
;
333 ASSERT (UsbIo
!= NULL
);
334 ASSERT (Status
!= NULL
);
336 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
338 DevReq
.RequestType
= USB_DEV_SET_CONFIGURATION_REQ_TYPE
;
339 DevReq
.Request
= USB_REQ_SET_CONFIG
;
340 DevReq
.Value
= ConfigurationValue
;
342 return UsbIo
->UsbControlTransfer (
355 Set the specified feature of the specified device.
357 Submit a USB set device feature request for the USB device specified by UsbIo,
358 Recipient, and Target to the value specified by Value. The status of the
359 transfer is returned in Status.
360 If UsbIo is NULL, then ASSERT().
361 If Status is NULL, then ASSERT().
363 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
364 @param Recipient The USB data recipient type (i.e. Device, Interface, Endpoint).
365 Type USB_TYPES_DEFINITION is defined in the MDE Package Industry
366 Standard include file Usb.h.
367 @param Value The value of the feature to be set.
368 @param Target The index of the device to be set.
369 @param Status A pointer to the status of the transfer.
371 @retval EFI_SUCCESS The request executed successfully.
372 @retval EFI_TIMEOUT A timeout occurred executing the request.
373 @retval EFI_DEVICE_ERROR The request failed due to a device error.
374 The transfer status is returned in Status.
380 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
381 IN USB_TYPES_DEFINITION Recipient
,
387 EFI_USB_DEVICE_REQUEST DevReq
;
389 ASSERT (UsbIo
!= NULL
);
390 ASSERT (Status
!= NULL
);
392 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
396 case USB_TARGET_DEVICE
:
397 DevReq
.RequestType
= USB_DEV_SET_FEATURE_REQ_TYPE_D
;
400 case USB_TARGET_INTERFACE
:
401 DevReq
.RequestType
= USB_DEV_SET_FEATURE_REQ_TYPE_I
;
404 case USB_TARGET_ENDPOINT
:
405 DevReq
.RequestType
= USB_DEV_SET_FEATURE_REQ_TYPE_E
;
412 // Fill device request, see USB1.1 spec
414 DevReq
.Request
= USB_REQ_SET_FEATURE
;
415 DevReq
.Value
= Value
;
416 DevReq
.Index
= Target
;
419 return UsbIo
->UsbControlTransfer (
432 Clear the specified feature of the specified device.
434 Submit a USB clear device feature request for the USB device specified by UsbIo,
435 Recipient, and Target to the value specified by Value. The status of the transfer
436 is returned in Status.
437 If UsbIo is NULL, then ASSERT().
438 If Status is NULL, then ASSERT().
440 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
441 @param Recipient The USB data recipient type (i.e. Device, Interface, Endpoint).
442 Type USB_TYPES_DEFINITION is defined in the MDE Package Industry Standard
444 @param Value The value of the feature to be cleared.
445 @param Target The index of the device to be cleared.
446 @param Status A pointer to the status of the transfer.
448 @retval EFI_SUCCESS The request executed successfully.
449 @retval EFI_TIMEOUT A timeout occurred executing the request.
450 @retval EFI_DEVICE_ERROR The request failed due to a device error.
451 The transfer status is returned in Status.
457 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
458 IN USB_TYPES_DEFINITION Recipient
,
464 EFI_USB_DEVICE_REQUEST DevReq
;
466 ASSERT (UsbIo
!= NULL
);
467 ASSERT (Status
!= NULL
);
470 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
474 case USB_TARGET_DEVICE
:
475 DevReq
.RequestType
= USB_DEV_CLEAR_FEATURE_REQ_TYPE_D
;
478 case USB_TARGET_INTERFACE
:
479 DevReq
.RequestType
= USB_DEV_CLEAR_FEATURE_REQ_TYPE_I
;
482 case USB_TARGET_ENDPOINT
:
483 DevReq
.RequestType
= USB_DEV_CLEAR_FEATURE_REQ_TYPE_E
;
490 // Fill device request, see USB1.1 spec
492 DevReq
.Request
= USB_REQ_CLEAR_FEATURE
;
493 DevReq
.Value
= Value
;
494 DevReq
.Index
= Target
;
497 return UsbIo
->UsbControlTransfer (
510 Get the status of the specified device.
512 Submit a USB device get status request for the USB device specified by UsbIo,
513 Recipient, and Target and place the result in the buffer specified by DeviceStatus.
514 The status of the transfer is returned in Status.
515 If UsbIo is NULL, then ASSERT().
516 If DeviceStatus is NULL, then ASSERT().
517 If Status is NULL, then ASSERT().
519 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
520 @param Recipient The USB data recipient type (i.e. Device, Interface, Endpoint).
521 Type USB_TYPES_DEFINITION is defined in the MDE Package Industry Standard
523 @param Target The index of the device to be get the status of.
524 @param DeviceStatus A pointer to the device status to be retrieved.
525 @param Status A pointer to the status of the transfer.
527 @retval EFI_SUCCESS The request executed successfully.
528 @retval EFI_TIMEOUT A timeout occurred executing the request.
529 @retval EFI_DEVICE_ERROR The request failed due to a device error.
530 The transfer status is returned in Status.
536 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
537 IN USB_TYPES_DEFINITION Recipient
,
539 OUT UINT16
*DeviceStatus
,
543 EFI_USB_DEVICE_REQUEST DevReq
;
545 ASSERT (UsbIo
!= NULL
);
546 ASSERT (DeviceStatus
!= NULL
);
547 ASSERT (Status
!= NULL
);
549 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
553 case USB_TARGET_DEVICE
:
554 DevReq
.RequestType
= USB_DEV_GET_STATUS_REQ_TYPE_D
;
557 case USB_TARGET_INTERFACE
:
558 DevReq
.RequestType
= USB_DEV_GET_STATUS_REQ_TYPE_I
;
561 case USB_TARGET_ENDPOINT
:
562 DevReq
.RequestType
= USB_DEV_GET_STATUS_REQ_TYPE_E
;
569 // Fill device request, see USB1.1 spec
571 DevReq
.Request
= USB_REQ_GET_STATUS
;
573 DevReq
.Index
= Target
;
576 return UsbIo
->UsbControlTransfer (
589 Clear halt feature of the specified usb endpoint.
591 Retrieve the USB endpoint descriptor specified by UsbIo and EndPoint.
592 If the USB endpoint descriptor can not be retrieved, then return EFI_NOT_FOUND.
593 If the endpoint descriptor is found, then clear the halt fature of this USB endpoint.
594 The status of the transfer is returned in Status.
595 If UsbIo is NULL, then ASSERT().
596 If Status is NULL, then ASSERT().
598 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.
599 @param Endpoint The endpoint address.
600 @param Status A pointer to the status of the transfer.
602 @retval EFI_SUCCESS The request executed successfully.
603 @retval EFI_TIMEOUT A timeout occurred executing the request.
604 @retval EFI_DEVICE_ERROR The request failed due to a device error.
605 The transfer status is returned in Status.
606 @retval EFI_NOT_FOUND The specified USB endpoint descriptor can not be found
611 UsbClearEndpointHalt (
612 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
618 EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor
;
619 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor
;
622 ASSERT (UsbIo
!= NULL
);
623 ASSERT (Status
!= NULL
);
625 ZeroMem (&EndpointDescriptor
, sizeof (EFI_USB_ENDPOINT_DESCRIPTOR
));
627 // First seach the endpoint descriptor for that endpoint addr
629 Result
= UsbIo
->UsbGetInterfaceDescriptor (
633 if (EFI_ERROR (Result
)) {
637 for (Index
= 0; Index
< InterfaceDescriptor
.NumEndpoints
; Index
++) {
638 Result
= UsbIo
->UsbGetEndpointDescriptor (
643 if (EFI_ERROR (Result
)) {
647 if (EndpointDescriptor
.EndpointAddress
== Endpoint
) {
652 if (Index
== InterfaceDescriptor
.NumEndpoints
) {
656 return EFI_NOT_FOUND
;
659 Result
= UsbClearFeature (
662 USB_FEATURE_ENDPOINT_HALT
,
663 EndpointDescriptor
.EndpointAddress
,