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
37 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
40 IN UINT16 DescriptorLength
,
45 EFI_USB_DEVICE_REQUEST DevReq
;
48 return EFI_INVALID_PARAMETER
;
51 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
53 DevReq
.RequestType
= USB_DEV_GET_DESCRIPTOR_REQ_TYPE
;
54 DevReq
.Request
= USB_REQ_GET_DESCRIPTOR
;
57 DevReq
.Length
= DescriptorLength
;
59 return UsbIo
->UsbControlTransfer (
74 @param UsbIo EFI_USB_IO_PROTOCOL
75 @param Value Device Request Value
76 @param Index Device Request Index
77 @param DescriptorLength Descriptor Length
78 @param Descriptor Descriptor buffer to set
79 @param Status Transfer Status
81 @retval EFI_INVALID_PARAMETER Parameter is error
82 @retval EFI_SUCCESS Success
83 @retval EFI_TIMEOUT Device has no response
89 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
92 IN UINT16 DescriptorLength
,
97 EFI_USB_DEVICE_REQUEST DevReq
;
100 return EFI_INVALID_PARAMETER
;
103 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
105 DevReq
.RequestType
= USB_DEV_SET_DESCRIPTOR_REQ_TYPE
;
106 DevReq
.Request
= USB_REQ_SET_DESCRIPTOR
;
107 DevReq
.Value
= Value
;
108 DevReq
.Index
= Index
;
109 DevReq
.Length
= DescriptorLength
;
111 return UsbIo
->UsbControlTransfer (
124 Usb Get Device Interface
126 @param UsbIo EFI_USB_IO_PROTOCOL
127 @param Index Interface index value
128 @param AltSetting Alternate setting
129 @param Status Trasnsfer status
131 @retval EFI_INVALID_PARAMETER Parameter is error
132 @retval EFI_SUCCESS Success
133 @retval EFI_TIMEOUT Device has no response
139 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
141 OUT UINT8
*AltSetting
,
145 EFI_USB_DEVICE_REQUEST DevReq
;
148 return EFI_INVALID_PARAMETER
;
151 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
153 DevReq
.RequestType
= USB_DEV_GET_INTERFACE_REQ_TYPE
;
154 DevReq
.Request
= USB_REQ_GET_INTERFACE
;
155 DevReq
.Index
= Index
;
158 return UsbIo
->UsbControlTransfer (
171 Usb Set Device Interface
173 @param UsbIo EFI_USB_IO_PROTOCOL
174 @param InterfaceNo Interface Number
175 @param AltSetting Alternate setting
176 @param Status Trasnsfer status
178 @retval EFI_INVALID_PARAMETER Parameter is error
179 @retval EFI_SUCCESS Success
180 @retval EFI_TIMEOUT Device has no response
186 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
187 IN UINT16 InterfaceNo
,
188 IN UINT16 AltSetting
,
192 EFI_USB_DEVICE_REQUEST DevReq
;
195 return EFI_INVALID_PARAMETER
;
198 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
200 DevReq
.RequestType
= USB_DEV_SET_INTERFACE_REQ_TYPE
;
201 DevReq
.Request
= USB_REQ_SET_INTERFACE
;
202 DevReq
.Value
= AltSetting
;
203 DevReq
.Index
= InterfaceNo
;
206 return UsbIo
->UsbControlTransfer (
219 Usb Get Device Configuration
221 @param UsbIo EFI_USB_IO_PROTOCOL
222 @param ConfigValue Config Value
223 @param Status Transfer Status
225 @retval EFI_INVALID_PARAMETER Parameter is error
226 @retval EFI_SUCCESS Success
227 @retval EFI_TIMEOUT Device has no response
232 UsbGetConfiguration (
233 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
234 OUT UINT8
*ConfigValue
,
238 EFI_USB_DEVICE_REQUEST DevReq
;
241 return EFI_INVALID_PARAMETER
;
244 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
246 DevReq
.RequestType
= USB_DEV_GET_CONFIGURATION_REQ_TYPE
;
247 DevReq
.Request
= USB_REQ_GET_CONFIG
;
250 return UsbIo
->UsbControlTransfer (
263 Usb Set Device Configuration
265 @param UsbIo EFI_USB_IO_PROTOCOL
266 @param Value Configuration Value to set
267 @param Status Transfer status
269 @retval EFI_INVALID_PARAMETER Parameter is error
270 @retval EFI_SUCCESS Success
271 @retval EFI_TIMEOUT Device has no response
276 UsbSetConfiguration (
277 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
282 EFI_USB_DEVICE_REQUEST DevReq
;
285 return EFI_INVALID_PARAMETER
;
288 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
290 DevReq
.RequestType
= USB_DEV_SET_CONFIGURATION_REQ_TYPE
;
291 DevReq
.Request
= USB_REQ_SET_CONFIG
;
292 DevReq
.Value
= Value
;
294 return UsbIo
->UsbControlTransfer (
307 Usb Set Device Feature
309 @param UsbIo EFI_USB_IO_PROTOCOL
310 @param Recipient Interface/Device/Endpoint
311 @param Value Request value
312 @param Target Request Index
313 @param Status Transfer status
315 @retval EFI_INVALID_PARAMETER Parameter is error
316 @retval EFI_SUCCESS Success
317 @retval EFI_TIMEOUT Device has no response
323 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
330 EFI_USB_DEVICE_REQUEST DevReq
;
333 return EFI_INVALID_PARAMETER
;
336 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
340 case USB_TARGET_DEVICE
:
341 DevReq
.RequestType
= USB_DEV_SET_FEATURE_REQ_TYPE_D
;
344 case USB_TARGET_INTERFACE
:
345 DevReq
.RequestType
= USB_DEV_SET_FEATURE_REQ_TYPE_I
;
348 case USB_TARGET_ENDPOINT
:
349 DevReq
.RequestType
= USB_DEV_SET_FEATURE_REQ_TYPE_E
;
353 // Fill device request, see USB1.1 spec
355 DevReq
.Request
= USB_REQ_SET_FEATURE
;
356 DevReq
.Value
= Value
;
357 DevReq
.Index
= Target
;
360 return UsbIo
->UsbControlTransfer (
373 Usb Clear Device Feature
375 @param UsbIo EFI_USB_IO_PROTOCOL
376 @param Recipient Interface/Device/Endpoint
377 @param Value Request value
378 @param Target Request Index
379 @param Status Transfer status
381 @retval EFI_INVALID_PARAMETER Parameter is error
382 @retval EFI_SUCCESS Success
383 @retval EFI_TIMEOUT Device has no response
389 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
396 EFI_USB_DEVICE_REQUEST DevReq
;
399 return EFI_INVALID_PARAMETER
;
402 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
406 case USB_TARGET_DEVICE
:
407 DevReq
.RequestType
= USB_DEV_CLEAR_FEATURE_REQ_TYPE_D
;
410 case USB_TARGET_INTERFACE
:
411 DevReq
.RequestType
= USB_DEV_CLEAR_FEATURE_REQ_TYPE_I
;
414 case USB_TARGET_ENDPOINT
:
415 DevReq
.RequestType
= USB_DEV_CLEAR_FEATURE_REQ_TYPE_E
;
419 // Fill device request, see USB1.1 spec
421 DevReq
.Request
= USB_REQ_CLEAR_FEATURE
;
422 DevReq
.Value
= Value
;
423 DevReq
.Index
= Target
;
426 return UsbIo
->UsbControlTransfer (
439 Usb Get Device Status
441 @param UsbIo EFI_USB_IO_PROTOCOL
442 @param Recipient Interface/Device/Endpoint
443 @param Target Request index
444 @param DevStatus Device status
445 @param Status Transfer status
447 @retval EFI_INVALID_PARAMETER Parameter is error
448 @retval EFI_SUCCESS Success
449 @retval EFI_TIMEOUT Device has no response
455 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
458 OUT UINT16
*DevStatus
,
462 EFI_USB_DEVICE_REQUEST DevReq
;
465 return EFI_INVALID_PARAMETER
;
468 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
472 case USB_TARGET_DEVICE
:
473 DevReq
.RequestType
= USB_DEV_GET_STATUS_REQ_TYPE_D
;
476 case USB_TARGET_INTERFACE
:
477 DevReq
.RequestType
= USB_DEV_GET_STATUS_REQ_TYPE_I
;
480 case USB_TARGET_ENDPOINT
:
481 DevReq
.RequestType
= USB_DEV_GET_STATUS_REQ_TYPE_E
;
485 // Fill device request, see USB1.1 spec
487 DevReq
.Request
= USB_REQ_GET_STATUS
;
489 DevReq
.Index
= Target
;
492 return UsbIo
->UsbControlTransfer (
508 @param UsbIo EFI_USB_IO_PROTOCOL
509 @param EndpointNo Endpoint Number
510 @param Status Transfer Status
512 @retval EFI_NOT_FOUND Can't find the Endpoint
513 @retval EFI_DEVICE_ERROR Hardware error
514 @retval EFI_SUCCESS Success
519 UsbClearEndpointHalt (
520 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
526 EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor
;
527 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor
;
530 ZeroMem (&EndpointDescriptor
, sizeof (EFI_USB_ENDPOINT_DESCRIPTOR
));
532 // First seach the endpoint descriptor for that endpoint addr
534 Result
= UsbIo
->UsbGetInterfaceDescriptor (
538 if (EFI_ERROR (Result
)) {
542 for (Index
= 0; Index
< InterfaceDescriptor
.NumEndpoints
; Index
++) {
543 Result
= UsbIo
->UsbGetEndpointDescriptor (
548 if (EFI_ERROR (Result
)) {
552 if (EndpointDescriptor
.EndpointAddress
== EndpointNo
) {
557 if (Index
== InterfaceDescriptor
.NumEndpoints
) {
561 return EFI_NOT_FOUND
;
564 Result
= UsbClearFeature (
567 USB_FEATURE_ENDPOINT_HALT
,
568 EndpointDescriptor
.EndpointAddress
,