3 Copyright (c) 2004 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 Common Dxe Libarary for USB
16 #include <UefiUsbLibInternal.h>
22 @param UsbIo EFI_USB_IO_PROTOCOL
23 @param Value Device Request Value
24 @param Index Device Request Index
25 @param DescriptorLength Descriptor Length
26 @param Descriptor Descriptor buffer to contain result
27 @param Status Transfer Status
29 @retval EFI_INVALID_PARAMETER Parameter is error
30 @retval EFI_SUCCESS Success
31 @retval EFI_TIMEOUT Device has no response
36 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
39 IN UINT16 DescriptorLength
,
44 EFI_USB_DEVICE_REQUEST DevReq
;
47 return EFI_INVALID_PARAMETER
;
50 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
52 DevReq
.RequestType
= USB_DEV_GET_DESCRIPTOR_REQ_TYPE
;
53 DevReq
.Request
= USB_REQ_GET_DESCRIPTOR
;
56 DevReq
.Length
= DescriptorLength
;
58 return UsbIo
->UsbControlTransfer (
73 @param UsbIo EFI_USB_IO_PROTOCOL
74 @param Value Device Request Value
75 @param Index Device Request Index
76 @param DescriptorLength Descriptor Length
77 @param Descriptor Descriptor buffer to set
78 @param Status Transfer Status
80 @retval EFI_INVALID_PARAMETER Parameter is error
81 @retval EFI_SUCCESS Success
82 @retval EFI_TIMEOUT Device has no response
87 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
90 IN UINT16 DescriptorLength
,
95 EFI_USB_DEVICE_REQUEST DevReq
;
98 return EFI_INVALID_PARAMETER
;
101 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
103 DevReq
.RequestType
= USB_DEV_SET_DESCRIPTOR_REQ_TYPE
;
104 DevReq
.Request
= USB_REQ_SET_DESCRIPTOR
;
105 DevReq
.Value
= Value
;
106 DevReq
.Index
= Index
;
107 DevReq
.Length
= DescriptorLength
;
109 return UsbIo
->UsbControlTransfer (
122 Usb Get Device Interface
124 @param UsbIo EFI_USB_IO_PROTOCOL
125 @param Index Interface index value
126 @param AltSetting Alternate setting
127 @param Status Trasnsfer status
129 @retval EFI_INVALID_PARAMETER Parameter is error
130 @retval EFI_SUCCESS Success
131 @retval EFI_TIMEOUT Device has no response
136 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
138 OUT UINT8
*AltSetting
,
142 EFI_USB_DEVICE_REQUEST DevReq
;
145 return EFI_INVALID_PARAMETER
;
148 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
150 DevReq
.RequestType
= USB_DEV_GET_INTERFACE_REQ_TYPE
;
151 DevReq
.Request
= USB_REQ_GET_INTERFACE
;
152 DevReq
.Index
= Index
;
155 return UsbIo
->UsbControlTransfer (
168 Usb Set Device Interface
170 @param UsbIo EFI_USB_IO_PROTOCOL
171 @param InterfaceNo Interface Number
172 @param AltSetting Alternate setting
173 @param Status Trasnsfer status
175 @retval EFI_INVALID_PARAMETER Parameter is error
176 @retval EFI_SUCCESS Success
177 @retval EFI_TIMEOUT Device has no response
182 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
183 IN UINT16 InterfaceNo
,
184 IN UINT16 AltSetting
,
188 EFI_USB_DEVICE_REQUEST DevReq
;
191 return EFI_INVALID_PARAMETER
;
194 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
196 DevReq
.RequestType
= USB_DEV_SET_INTERFACE_REQ_TYPE
;
197 DevReq
.Request
= USB_REQ_SET_INTERFACE
;
198 DevReq
.Value
= AltSetting
;
199 DevReq
.Index
= InterfaceNo
;
202 return UsbIo
->UsbControlTransfer (
215 Usb Get Device Configuration
217 @param UsbIo EFI_USB_IO_PROTOCOL
218 @param ConfigValue Config Value
219 @param Status Transfer Status
221 @retval EFI_INVALID_PARAMETER Parameter is error
222 @retval EFI_SUCCESS Success
223 @retval EFI_TIMEOUT Device has no response
227 UsbGetConfiguration (
228 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
229 OUT UINT8
*ConfigValue
,
233 EFI_USB_DEVICE_REQUEST DevReq
;
236 return EFI_INVALID_PARAMETER
;
239 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
241 DevReq
.RequestType
= USB_DEV_GET_CONFIGURATION_REQ_TYPE
;
242 DevReq
.Request
= USB_REQ_GET_CONFIG
;
245 return UsbIo
->UsbControlTransfer (
258 Usb Set Device Configuration
260 @param UsbIo EFI_USB_IO_PROTOCOL
261 @param Value Configuration Value to set
262 @param Status Transfer status
264 @retval EFI_INVALID_PARAMETER Parameter is error
265 @retval EFI_SUCCESS Success
266 @retval EFI_TIMEOUT Device has no response
270 UsbSetConfiguration (
271 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
276 EFI_USB_DEVICE_REQUEST DevReq
;
279 return EFI_INVALID_PARAMETER
;
282 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
284 DevReq
.RequestType
= USB_DEV_SET_CONFIGURATION_REQ_TYPE
;
285 DevReq
.Request
= USB_REQ_SET_CONFIG
;
286 DevReq
.Value
= Value
;
288 return UsbIo
->UsbControlTransfer (
301 Usb Set Device Feature
303 @param UsbIo EFI_USB_IO_PROTOCOL
304 @param Recipient Interface/Device/Endpoint
305 @param Value Request value
306 @param Target Request Index
307 @param Status Transfer status
309 @retval EFI_INVALID_PARAMETER Parameter is error
310 @retval EFI_SUCCESS Success
311 @retval EFI_TIMEOUT Device has no response
316 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
323 EFI_USB_DEVICE_REQUEST DevReq
;
326 return EFI_INVALID_PARAMETER
;
329 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
333 case USB_TARGET_DEVICE
:
334 DevReq
.RequestType
= USB_DEV_SET_FEATURE_REQ_TYPE_D
;
337 case USB_TARGET_INTERFACE
:
338 DevReq
.RequestType
= USB_DEV_SET_FEATURE_REQ_TYPE_I
;
341 case USB_TARGET_ENDPOINT
:
342 DevReq
.RequestType
= USB_DEV_SET_FEATURE_REQ_TYPE_E
;
346 // Fill device request, see USB1.1 spec
348 DevReq
.Request
= USB_REQ_SET_FEATURE
;
349 DevReq
.Value
= Value
;
350 DevReq
.Index
= Target
;
353 return UsbIo
->UsbControlTransfer (
366 Usb Clear Device Feature
368 @param UsbIo EFI_USB_IO_PROTOCOL
369 @param Recipient Interface/Device/Endpoint
370 @param Value Request value
371 @param Target Request Index
372 @param Status Transfer status
374 @retval EFI_INVALID_PARAMETER Parameter is error
375 @retval EFI_SUCCESS Success
376 @retval EFI_TIMEOUT Device has no response
381 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
388 EFI_USB_DEVICE_REQUEST DevReq
;
391 return EFI_INVALID_PARAMETER
;
394 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
398 case USB_TARGET_DEVICE
:
399 DevReq
.RequestType
= USB_DEV_CLEAR_FEATURE_REQ_TYPE_D
;
402 case USB_TARGET_INTERFACE
:
403 DevReq
.RequestType
= USB_DEV_CLEAR_FEATURE_REQ_TYPE_I
;
406 case USB_TARGET_ENDPOINT
:
407 DevReq
.RequestType
= USB_DEV_CLEAR_FEATURE_REQ_TYPE_E
;
411 // Fill device request, see USB1.1 spec
413 DevReq
.Request
= USB_REQ_CLEAR_FEATURE
;
414 DevReq
.Value
= Value
;
415 DevReq
.Index
= Target
;
418 return UsbIo
->UsbControlTransfer (
431 Usb Get Device Status
433 @param UsbIo EFI_USB_IO_PROTOCOL
434 @param Recipient Interface/Device/Endpoint
435 @param Target Request index
436 @param DevStatus Device status
437 @param Status Transfer status
439 @retval EFI_INVALID_PARAMETER Parameter is error
440 @retval EFI_SUCCESS Success
441 @retval EFI_TIMEOUT Device has no response
446 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
449 OUT UINT16
*DevStatus
,
453 EFI_USB_DEVICE_REQUEST DevReq
;
456 return EFI_INVALID_PARAMETER
;
459 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
463 case USB_TARGET_DEVICE
:
464 DevReq
.RequestType
= USB_DEV_GET_STATUS_REQ_TYPE_D
;
467 case USB_TARGET_INTERFACE
:
468 DevReq
.RequestType
= USB_DEV_GET_STATUS_REQ_TYPE_I
;
471 case USB_TARGET_ENDPOINT
:
472 DevReq
.RequestType
= USB_DEV_GET_STATUS_REQ_TYPE_E
;
476 // Fill device request, see USB1.1 spec
478 DevReq
.Request
= USB_REQ_GET_STATUS
;
480 DevReq
.Index
= Target
;
483 return UsbIo
->UsbControlTransfer (
499 @param UsbIo EFI_USB_IO_PROTOCOL
500 @param EndpointNo Endpoint Number
501 @param Status Transfer Status
503 @retval EFI_NOT_FOUND Can't find the Endpoint
504 @retval EFI_DEVICE_ERROR Hardware error
505 @retval EFI_SUCCESS Success
509 UsbClearEndpointHalt (
510 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
516 EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor
;
517 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor
;
520 ZeroMem (&EndpointDescriptor
, sizeof (EFI_USB_ENDPOINT_DESCRIPTOR
));
522 // First seach the endpoint descriptor for that endpoint addr
524 Result
= UsbIo
->UsbGetInterfaceDescriptor (
528 if (EFI_ERROR (Result
)) {
532 for (Index
= 0; Index
< InterfaceDescriptor
.NumEndpoints
; Index
++) {
533 Result
= UsbIo
->UsbGetEndpointDescriptor (
538 if (EFI_ERROR (Result
)) {
542 if (EndpointDescriptor
.EndpointAddress
== EndpointNo
) {
547 if (Index
== InterfaceDescriptor
.NumEndpoints
) {
551 return EFI_NOT_FOUND
;
554 Result
= UsbClearFeature (
558 EndpointDescriptor
.EndpointAddress
,