3 Copyright (c) 2006, 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
25 // Get Device Descriptor
29 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
32 IN UINT16 DescriptorLength
,
44 UsbIo - EFI_USB_IO_PROTOCOL
45 Value - Device Request Value
46 Index - Device Request Index
47 DescriptorLength - Descriptor Length
48 Descriptor - Descriptor buffer to contain result
49 Status - Transfer Status
51 EFI_INVALID_PARAMETER - Parameter is error
53 EFI_TIMEOUT - Device has no response
57 EFI_USB_DEVICE_REQUEST DevReq
;
60 return EFI_INVALID_PARAMETER
;
63 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
65 DevReq
.RequestType
= USB_DEV_GET_DESCRIPTOR_REQ_TYPE
;
66 DevReq
.Request
= USB_DEV_GET_DESCRIPTOR
;
69 DevReq
.Length
= DescriptorLength
;
71 return UsbIo
->UsbControlTransfer (
82 // Set Device Descriptor
86 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
89 IN UINT16 DescriptorLength
,
101 UsbIo - EFI_USB_IO_PROTOCOL
102 Value - Device Request Value
103 Index - Device Request Index
104 DescriptorLength - Descriptor Length
105 Descriptor - Descriptor buffer to set
106 Status - Transfer Status
108 EFI_INVALID_PARAMETER - Parameter is error
109 EFI_SUCCESS - Success
110 EFI_TIMEOUT - Device has no response
114 EFI_USB_DEVICE_REQUEST DevReq
;
117 return EFI_INVALID_PARAMETER
;
120 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
122 DevReq
.RequestType
= USB_DEV_SET_DESCRIPTOR_REQ_TYPE
;
123 DevReq
.Request
= USB_DEV_SET_DESCRIPTOR
;
124 DevReq
.Value
= Value
;
125 DevReq
.Index
= Index
;
126 DevReq
.Length
= DescriptorLength
;
128 return UsbIo
->UsbControlTransfer (
140 // Get device Interface
143 UsbGetDeviceInterface (
144 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
146 OUT UINT8
*AltSetting
,
153 Usb Get Device Interface
157 UsbIo - EFI_USB_IO_PROTOCOL
158 Index - Interface index value
159 AltSetting - Alternate setting
160 Status - Trasnsfer status
164 EFI_INVALID_PARAMETER - Parameter is error
165 EFI_SUCCESS - Success
166 EFI_TIMEOUT - Device has no response
171 EFI_USB_DEVICE_REQUEST DevReq
;
174 return EFI_INVALID_PARAMETER
;
177 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
179 DevReq
.RequestType
= USB_DEV_GET_INTERFACE_REQ_TYPE
;
180 DevReq
.Request
= USB_DEV_GET_INTERFACE
;
181 DevReq
.Index
= Index
;
184 return UsbIo
->UsbControlTransfer (
195 // Set device interface
198 UsbSetDeviceInterface (
199 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
200 IN UINT16 InterfaceNo
,
201 IN UINT16 AltSetting
,
208 Usb Set Device Interface
212 UsbIo - EFI_USB_IO_PROTOCOL
213 InterfaceNo - Interface Number
214 AltSetting - Alternate setting
215 Status - Trasnsfer status
219 EFI_INVALID_PARAMETER - Parameter is error
220 EFI_SUCCESS - Success
221 EFI_TIMEOUT - Device has no response
225 EFI_USB_DEVICE_REQUEST DevReq
;
228 return EFI_INVALID_PARAMETER
;
231 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
233 DevReq
.RequestType
= USB_DEV_SET_INTERFACE_REQ_TYPE
;
234 DevReq
.Request
= USB_DEV_SET_INTERFACE
;
235 DevReq
.Value
= AltSetting
;
236 DevReq
.Index
= InterfaceNo
;
239 return UsbIo
->UsbControlTransfer (
250 // Get device configuration
253 UsbGetDeviceConfiguration (
254 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
255 OUT UINT8
*ConfigValue
,
262 Usb Get Device Configuration
266 UsbIo - EFI_USB_IO_PROTOCOL
267 ConfigValue - Config Value
268 Status - Transfer Status
272 EFI_INVALID_PARAMETER - Parameter is error
273 EFI_SUCCESS - Success
274 EFI_TIMEOUT - Device has no response
278 EFI_USB_DEVICE_REQUEST DevReq
;
281 return EFI_INVALID_PARAMETER
;
284 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
286 DevReq
.RequestType
= USB_DEV_GET_CONFIGURATION_REQ_TYPE
;
287 DevReq
.Request
= USB_DEV_GET_CONFIGURATION
;
290 return UsbIo
->UsbControlTransfer (
301 // Set device configuration
304 UsbSetDeviceConfiguration (
305 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
313 Usb Set Device Configuration
317 UsbIo - EFI_USB_IO_PROTOCOL
318 Value - Configuration Value to set
319 Status - Transfer status
323 EFI_INVALID_PARAMETER - Parameter is error
324 EFI_SUCCESS - Success
325 EFI_TIMEOUT - Device has no response
329 EFI_USB_DEVICE_REQUEST DevReq
;
332 return EFI_INVALID_PARAMETER
;
335 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
337 DevReq
.RequestType
= USB_DEV_SET_CONFIGURATION_REQ_TYPE
;
338 DevReq
.Request
= USB_DEV_SET_CONFIGURATION
;
339 DevReq
.Value
= Value
;
341 return UsbIo
->UsbControlTransfer (
352 // Set Device Feature
355 UsbSetDeviceFeature (
356 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
357 IN EFI_USB_RECIPIENT Recipient
,
366 Usb Set Device Feature
370 UsbIo - EFI_USB_IO_PROTOCOL
371 Recipient - Interface/Device/Endpoint
372 Value - Request value
373 Target - Request Index
374 Status - Transfer status
378 EFI_INVALID_PARAMETER - Parameter is error
379 EFI_SUCCESS - Success
380 EFI_TIMEOUT - Device has no response
384 EFI_USB_DEVICE_REQUEST DevReq
;
387 return EFI_INVALID_PARAMETER
;
390 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
395 DevReq
.RequestType
= 0x00;
398 case EfiUsbInterface
:
399 DevReq
.RequestType
= 0x01;
403 DevReq
.RequestType
= 0x02;
407 // Fill device request, see USB1.1 spec
409 DevReq
.Request
= USB_DEV_SET_FEATURE
;
410 DevReq
.Value
= Value
;
411 DevReq
.Index
= Target
;
414 return UsbIo
->UsbControlTransfer (
425 // Clear Device Feature
428 UsbClearDeviceFeature (
429 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
430 IN EFI_USB_RECIPIENT Recipient
,
439 Usb Clear Device Feature
443 UsbIo - EFI_USB_IO_PROTOCOL
444 Recipient - Interface/Device/Endpoint
445 Value - Request value
446 Target - Request Index
447 Status - Transfer status
451 EFI_INVALID_PARAMETER - Parameter is error
452 EFI_SUCCESS - Success
453 EFI_TIMEOUT - Device has no response
457 EFI_USB_DEVICE_REQUEST DevReq
;
460 return EFI_INVALID_PARAMETER
;
463 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
468 DevReq
.RequestType
= 0x00;
471 case EfiUsbInterface
:
472 DevReq
.RequestType
= 0x01;
476 DevReq
.RequestType
= 0x02;
480 // Fill device request, see USB1.1 spec
482 DevReq
.Request
= USB_DEV_CLEAR_FEATURE
;
483 DevReq
.Value
= Value
;
484 DevReq
.Index
= Target
;
487 return UsbIo
->UsbControlTransfer (
502 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
503 IN EFI_USB_RECIPIENT Recipient
,
505 OUT UINT16
*DevStatus
,
512 Usb Get Device Status
516 UsbIo - EFI_USB_IO_PROTOCOL
517 Recipient - Interface/Device/Endpoint
518 Target - Request index
519 DevStatus - Device status
520 Status - Transfer status
524 EFI_INVALID_PARAMETER - Parameter is error
525 EFI_SUCCESS - Success
526 EFI_TIMEOUT - Device has no response
530 EFI_USB_DEVICE_REQUEST DevReq
;
533 return EFI_INVALID_PARAMETER
;
536 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
541 DevReq
.RequestType
= 0x80;
544 case EfiUsbInterface
:
545 DevReq
.RequestType
= 0x81;
549 DevReq
.RequestType
= 0x82;
553 // Fill device request, see USB1.1 spec
555 DevReq
.Request
= USB_DEV_GET_STATUS
;
557 DevReq
.Index
= Target
;
560 return UsbIo
->UsbControlTransfer (
575 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
590 UsbIo - EFI_USB_IO_PROTOCOL
592 Index - Request index
593 Buf - Buffer to store string
594 BufSize - Buffer size
595 Status - Transfer status
599 EFI_INVALID_PARAMETER - Parameter is error
600 EFI_SUCCESS - Success
601 EFI_TIMEOUT - Device has no response
608 return EFI_INVALID_PARAMETER
;
611 // Fill value, see USB1.1 spec
613 Value
= (UINT16
) ((USB_DT_STRING
<< 8) | Index
);
615 return UsbGetDescriptor (
626 UsbClearEndpointHalt (
627 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
639 UsbIo - EFI_USB_IO_PROTOCOL
640 EndpointNo - Endpoint Number
641 Status - Transfer Status
645 EFI_NOT_FOUND - Can't find the Endpoint
646 EFI_DEVICE_ERROR - Hardware error
647 EFI_SUCCESS - Success
652 EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor
;
653 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor
;
656 ZeroMem (&EndpointDescriptor
, sizeof (EFI_USB_ENDPOINT_DESCRIPTOR
));
658 // First seach the endpoint descriptor for that endpoint addr
660 Result
= UsbIo
->UsbGetInterfaceDescriptor (
664 if (EFI_ERROR (Result
)) {
668 for (Index
= 0; Index
< InterfaceDescriptor
.NumEndpoints
; Index
++) {
669 Result
= UsbIo
->UsbGetEndpointDescriptor (
674 if (EFI_ERROR (Result
)) {
678 if (EndpointDescriptor
.EndpointAddress
== EndpointNo
) {
683 if (Index
== InterfaceDescriptor
.NumEndpoints
) {
687 return EFI_NOT_FOUND
;
690 Result
= UsbClearDeviceFeature (
694 EndpointDescriptor
.EndpointAddress
,