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.
18 Common Dxe Libarary for USB
26 // The package level header files this module uses
30 // The Library classes this module consumes
32 #include <Library/BaseMemoryLib.h>
33 #include <Library/UsbLib.h>
38 @param UsbIo EFI_USB_IO_PROTOCOL
39 @param Value Device Request Value
40 @param Index Device Request Index
41 @param DescriptorLength Descriptor Length
42 @param Descriptor Descriptor buffer to contain result
43 @param Status Transfer Status
45 @retval EFI_INVALID_PARAMETER Parameter is error
46 @retval EFI_SUCCESS Success
47 @retval EFI_TIMEOUT Device has no response
52 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
55 IN UINT16 DescriptorLength
,
60 EFI_USB_DEVICE_REQUEST DevReq
;
63 return EFI_INVALID_PARAMETER
;
66 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
68 DevReq
.RequestType
= USB_DEV_GET_DESCRIPTOR_REQ_TYPE
;
69 DevReq
.Request
= USB_REQ_GET_DESCRIPTOR
;
72 DevReq
.Length
= DescriptorLength
;
74 return UsbIo
->UsbControlTransfer (
89 @param UsbIo EFI_USB_IO_PROTOCOL
90 @param Value Device Request Value
91 @param Index Device Request Index
92 @param DescriptorLength Descriptor Length
93 @param Descriptor Descriptor buffer to set
94 @param Status Transfer Status
96 @retval EFI_INVALID_PARAMETER Parameter is error
97 @retval EFI_SUCCESS Success
98 @retval EFI_TIMEOUT Device has no response
103 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
106 IN UINT16 DescriptorLength
,
111 EFI_USB_DEVICE_REQUEST DevReq
;
114 return EFI_INVALID_PARAMETER
;
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 (
138 Usb Get Device Interface
140 @param UsbIo EFI_USB_IO_PROTOCOL
141 @param Index Interface index value
142 @param AltSetting Alternate setting
143 @param Status Trasnsfer status
145 @retval EFI_INVALID_PARAMETER Parameter is error
146 @retval EFI_SUCCESS Success
147 @retval EFI_TIMEOUT Device has no response
152 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
154 OUT UINT8
*AltSetting
,
158 EFI_USB_DEVICE_REQUEST DevReq
;
161 return EFI_INVALID_PARAMETER
;
164 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
166 DevReq
.RequestType
= USB_DEV_GET_INTERFACE_REQ_TYPE
;
167 DevReq
.Request
= USB_REQ_GET_INTERFACE
;
168 DevReq
.Index
= Index
;
171 return UsbIo
->UsbControlTransfer (
184 Usb Set Device Interface
186 @param UsbIo EFI_USB_IO_PROTOCOL
187 @param InterfaceNo Interface Number
188 @param AltSetting Alternate setting
189 @param Status Trasnsfer status
191 @retval EFI_INVALID_PARAMETER Parameter is error
192 @retval EFI_SUCCESS Success
193 @retval EFI_TIMEOUT Device has no response
198 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
199 IN UINT16 InterfaceNo
,
200 IN UINT16 AltSetting
,
204 EFI_USB_DEVICE_REQUEST DevReq
;
207 return EFI_INVALID_PARAMETER
;
210 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
212 DevReq
.RequestType
= USB_DEV_SET_INTERFACE_REQ_TYPE
;
213 DevReq
.Request
= USB_REQ_SET_INTERFACE
;
214 DevReq
.Value
= AltSetting
;
215 DevReq
.Index
= InterfaceNo
;
218 return UsbIo
->UsbControlTransfer (
231 Usb Get Device Configuration
233 @param UsbIo EFI_USB_IO_PROTOCOL
234 @param ConfigValue Config Value
235 @param Status Transfer Status
237 @retval EFI_INVALID_PARAMETER Parameter is error
238 @retval EFI_SUCCESS Success
239 @retval EFI_TIMEOUT Device has no response
243 UsbGetConfiguration (
244 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
245 OUT UINT8
*ConfigValue
,
249 EFI_USB_DEVICE_REQUEST DevReq
;
252 return EFI_INVALID_PARAMETER
;
255 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
257 DevReq
.RequestType
= USB_DEV_GET_CONFIGURATION_REQ_TYPE
;
258 DevReq
.Request
= USB_REQ_GET_CONFIG
;
261 return UsbIo
->UsbControlTransfer (
274 Usb Set Device Configuration
276 @param UsbIo EFI_USB_IO_PROTOCOL
277 @param Value Configuration Value to set
278 @param Status Transfer status
280 @retval EFI_INVALID_PARAMETER Parameter is error
281 @retval EFI_SUCCESS Success
282 @retval EFI_TIMEOUT Device has no response
286 UsbSetConfiguration (
287 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
292 EFI_USB_DEVICE_REQUEST DevReq
;
295 return EFI_INVALID_PARAMETER
;
298 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
300 DevReq
.RequestType
= USB_DEV_SET_CONFIGURATION_REQ_TYPE
;
301 DevReq
.Request
= USB_REQ_SET_CONFIG
;
302 DevReq
.Value
= Value
;
304 return UsbIo
->UsbControlTransfer (
317 Usb Set Device Feature
319 @param UsbIo EFI_USB_IO_PROTOCOL
320 @param Recipient Interface/Device/Endpoint
321 @param Value Request value
322 @param Target Request Index
323 @param Status Transfer status
325 @retval EFI_INVALID_PARAMETER Parameter is error
326 @retval EFI_SUCCESS Success
327 @retval EFI_TIMEOUT Device has no response
332 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
339 EFI_USB_DEVICE_REQUEST DevReq
;
342 return EFI_INVALID_PARAMETER
;
345 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
349 case USB_TARGET_DEVICE
:
350 DevReq
.RequestType
= USB_DEV_SET_FEATURE_REQ_TYPE_D
;
353 case USB_TARGET_INTERFACE
:
354 DevReq
.RequestType
= USB_DEV_SET_FEATURE_REQ_TYPE_I
;
357 case USB_TARGET_ENDPOINT
:
358 DevReq
.RequestType
= USB_DEV_SET_FEATURE_REQ_TYPE_E
;
362 // Fill device request, see USB1.1 spec
364 DevReq
.Request
= USB_REQ_SET_FEATURE
;
365 DevReq
.Value
= Value
;
366 DevReq
.Index
= Target
;
369 return UsbIo
->UsbControlTransfer (
382 Usb Clear Device Feature
384 @param UsbIo EFI_USB_IO_PROTOCOL
385 @param Recipient Interface/Device/Endpoint
386 @param Value Request value
387 @param Target Request Index
388 @param Status Transfer status
390 @retval EFI_INVALID_PARAMETER Parameter is error
391 @retval EFI_SUCCESS Success
392 @retval EFI_TIMEOUT Device has no response
397 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
404 EFI_USB_DEVICE_REQUEST DevReq
;
407 return EFI_INVALID_PARAMETER
;
410 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
414 case USB_TARGET_DEVICE
:
415 DevReq
.RequestType
= USB_DEV_CLEAR_FEATURE_REQ_TYPE_D
;
418 case USB_TARGET_INTERFACE
:
419 DevReq
.RequestType
= USB_DEV_CLEAR_FEATURE_REQ_TYPE_I
;
422 case USB_TARGET_ENDPOINT
:
423 DevReq
.RequestType
= USB_DEV_CLEAR_FEATURE_REQ_TYPE_E
;
427 // Fill device request, see USB1.1 spec
429 DevReq
.Request
= USB_REQ_CLEAR_FEATURE
;
430 DevReq
.Value
= Value
;
431 DevReq
.Index
= Target
;
434 return UsbIo
->UsbControlTransfer (
447 Usb Get Device Status
449 @param UsbIo EFI_USB_IO_PROTOCOL
450 @param Recipient Interface/Device/Endpoint
451 @param Target Request index
452 @param DevStatus Device status
453 @param Status Transfer status
455 @retval EFI_INVALID_PARAMETER Parameter is error
456 @retval EFI_SUCCESS Success
457 @retval EFI_TIMEOUT Device has no response
462 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
465 OUT UINT16
*DevStatus
,
469 EFI_USB_DEVICE_REQUEST DevReq
;
472 return EFI_INVALID_PARAMETER
;
475 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
479 case USB_TARGET_DEVICE
:
480 DevReq
.RequestType
= USB_DEV_GET_STATUS_REQ_TYPE_D
;
483 case USB_TARGET_INTERFACE
:
484 DevReq
.RequestType
= USB_DEV_GET_STATUS_REQ_TYPE_I
;
487 case USB_TARGET_ENDPOINT
:
488 DevReq
.RequestType
= USB_DEV_GET_STATUS_REQ_TYPE_E
;
492 // Fill device request, see USB1.1 spec
494 DevReq
.Request
= USB_REQ_GET_STATUS
;
496 DevReq
.Index
= Target
;
499 return UsbIo
->UsbControlTransfer (
515 @param UsbIo EFI_USB_IO_PROTOCOL
516 @param EndpointNo Endpoint Number
517 @param Status Transfer Status
519 @retval EFI_NOT_FOUND Can't find the Endpoint
520 @retval EFI_DEVICE_ERROR Hardware error
521 @retval EFI_SUCCESS Success
525 UsbClearEndpointHalt (
526 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
532 EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor
;
533 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor
;
536 ZeroMem (&EndpointDescriptor
, sizeof (EFI_USB_ENDPOINT_DESCRIPTOR
));
538 // First seach the endpoint descriptor for that endpoint addr
540 Result
= UsbIo
->UsbGetInterfaceDescriptor (
544 if (EFI_ERROR (Result
)) {
548 for (Index
= 0; Index
< InterfaceDescriptor
.NumEndpoints
; Index
++) {
549 Result
= UsbIo
->UsbGetEndpointDescriptor (
554 if (EFI_ERROR (Result
)) {
558 if (EndpointDescriptor
.EndpointAddress
== EndpointNo
) {
563 if (Index
== InterfaceDescriptor
.NumEndpoints
) {
567 return EFI_NOT_FOUND
;
570 Result
= UsbClearFeature (
574 EndpointDescriptor
.EndpointAddress
,