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 // Include common header file for this module.
27 #include "CommonHeader.h"
30 // Get Device Descriptor
34 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
37 IN UINT16 DescriptorLength
,
49 UsbIo - EFI_USB_IO_PROTOCOL
50 Value - Device Request Value
51 Index - Device Request Index
52 DescriptorLength - Descriptor Length
53 Descriptor - Descriptor buffer to contain result
54 Status - Transfer Status
56 EFI_INVALID_PARAMETER - Parameter is error
58 EFI_TIMEOUT - Device has no response
62 EFI_USB_DEVICE_REQUEST DevReq
;
65 return EFI_INVALID_PARAMETER
;
68 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
70 DevReq
.RequestType
= USB_DEV_GET_DESCRIPTOR_REQ_TYPE
;
71 DevReq
.Request
= USB_DEV_GET_DESCRIPTOR
;
74 DevReq
.Length
= DescriptorLength
;
76 return UsbIo
->UsbControlTransfer (
87 // Set Device Descriptor
91 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
94 IN UINT16 DescriptorLength
,
106 UsbIo - EFI_USB_IO_PROTOCOL
107 Value - Device Request Value
108 Index - Device Request Index
109 DescriptorLength - Descriptor Length
110 Descriptor - Descriptor buffer to set
111 Status - Transfer Status
113 EFI_INVALID_PARAMETER - Parameter is error
114 EFI_SUCCESS - Success
115 EFI_TIMEOUT - Device has no response
119 EFI_USB_DEVICE_REQUEST DevReq
;
122 return EFI_INVALID_PARAMETER
;
125 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
127 DevReq
.RequestType
= USB_DEV_SET_DESCRIPTOR_REQ_TYPE
;
128 DevReq
.Request
= USB_DEV_SET_DESCRIPTOR
;
129 DevReq
.Value
= Value
;
130 DevReq
.Index
= Index
;
131 DevReq
.Length
= DescriptorLength
;
133 return UsbIo
->UsbControlTransfer (
145 // Get device Interface
148 UsbGetDeviceInterface (
149 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
151 OUT UINT8
*AltSetting
,
158 Usb Get Device Interface
162 UsbIo - EFI_USB_IO_PROTOCOL
163 Index - Interface index value
164 AltSetting - Alternate setting
165 Status - Trasnsfer status
169 EFI_INVALID_PARAMETER - Parameter is error
170 EFI_SUCCESS - Success
171 EFI_TIMEOUT - Device has no response
176 EFI_USB_DEVICE_REQUEST DevReq
;
179 return EFI_INVALID_PARAMETER
;
182 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
184 DevReq
.RequestType
= USB_DEV_GET_INTERFACE_REQ_TYPE
;
185 DevReq
.Request
= USB_DEV_GET_INTERFACE
;
186 DevReq
.Index
= Index
;
189 return UsbIo
->UsbControlTransfer (
200 // Set device interface
203 UsbSetDeviceInterface (
204 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
205 IN UINT16 InterfaceNo
,
206 IN UINT16 AltSetting
,
213 Usb Set Device Interface
217 UsbIo - EFI_USB_IO_PROTOCOL
218 InterfaceNo - Interface Number
219 AltSetting - Alternate setting
220 Status - Trasnsfer status
224 EFI_INVALID_PARAMETER - Parameter is error
225 EFI_SUCCESS - Success
226 EFI_TIMEOUT - Device has no response
230 EFI_USB_DEVICE_REQUEST DevReq
;
233 return EFI_INVALID_PARAMETER
;
236 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
238 DevReq
.RequestType
= USB_DEV_SET_INTERFACE_REQ_TYPE
;
239 DevReq
.Request
= USB_DEV_SET_INTERFACE
;
240 DevReq
.Value
= AltSetting
;
241 DevReq
.Index
= InterfaceNo
;
244 return UsbIo
->UsbControlTransfer (
255 // Get device configuration
258 UsbGetDeviceConfiguration (
259 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
260 OUT UINT8
*ConfigValue
,
267 Usb Get Device Configuration
271 UsbIo - EFI_USB_IO_PROTOCOL
272 ConfigValue - Config Value
273 Status - Transfer Status
277 EFI_INVALID_PARAMETER - Parameter is error
278 EFI_SUCCESS - Success
279 EFI_TIMEOUT - Device has no response
283 EFI_USB_DEVICE_REQUEST DevReq
;
286 return EFI_INVALID_PARAMETER
;
289 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
291 DevReq
.RequestType
= USB_DEV_GET_CONFIGURATION_REQ_TYPE
;
292 DevReq
.Request
= USB_DEV_GET_CONFIGURATION
;
295 return UsbIo
->UsbControlTransfer (
306 // Set device configuration
309 UsbSetDeviceConfiguration (
310 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
318 Usb Set Device Configuration
322 UsbIo - EFI_USB_IO_PROTOCOL
323 Value - Configuration Value to set
324 Status - Transfer status
328 EFI_INVALID_PARAMETER - Parameter is error
329 EFI_SUCCESS - Success
330 EFI_TIMEOUT - Device has no response
334 EFI_USB_DEVICE_REQUEST DevReq
;
337 return EFI_INVALID_PARAMETER
;
340 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
342 DevReq
.RequestType
= USB_DEV_SET_CONFIGURATION_REQ_TYPE
;
343 DevReq
.Request
= USB_DEV_SET_CONFIGURATION
;
344 DevReq
.Value
= Value
;
346 return UsbIo
->UsbControlTransfer (
357 // Set Device Feature
360 UsbSetDeviceFeature (
361 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
362 IN EFI_USB_RECIPIENT Recipient
,
371 Usb Set Device Feature
375 UsbIo - EFI_USB_IO_PROTOCOL
376 Recipient - Interface/Device/Endpoint
377 Value - Request value
378 Target - Request Index
379 Status - Transfer status
383 EFI_INVALID_PARAMETER - Parameter is error
384 EFI_SUCCESS - Success
385 EFI_TIMEOUT - Device has no response
389 EFI_USB_DEVICE_REQUEST DevReq
;
392 return EFI_INVALID_PARAMETER
;
395 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
400 DevReq
.RequestType
= 0x00;
403 case EfiUsbInterface
:
404 DevReq
.RequestType
= 0x01;
408 DevReq
.RequestType
= 0x02;
412 // Fill device request, see USB1.1 spec
414 DevReq
.Request
= USB_DEV_SET_FEATURE
;
415 DevReq
.Value
= Value
;
416 DevReq
.Index
= Target
;
419 return UsbIo
->UsbControlTransfer (
430 // Clear Device Feature
433 UsbClearDeviceFeature (
434 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
435 IN EFI_USB_RECIPIENT Recipient
,
444 Usb Clear Device Feature
448 UsbIo - EFI_USB_IO_PROTOCOL
449 Recipient - Interface/Device/Endpoint
450 Value - Request value
451 Target - Request Index
452 Status - Transfer status
456 EFI_INVALID_PARAMETER - Parameter is error
457 EFI_SUCCESS - Success
458 EFI_TIMEOUT - Device has no response
462 EFI_USB_DEVICE_REQUEST DevReq
;
465 return EFI_INVALID_PARAMETER
;
468 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
473 DevReq
.RequestType
= 0x00;
476 case EfiUsbInterface
:
477 DevReq
.RequestType
= 0x01;
481 DevReq
.RequestType
= 0x02;
485 // Fill device request, see USB1.1 spec
487 DevReq
.Request
= USB_DEV_CLEAR_FEATURE
;
488 DevReq
.Value
= Value
;
489 DevReq
.Index
= Target
;
492 return UsbIo
->UsbControlTransfer (
507 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
508 IN EFI_USB_RECIPIENT Recipient
,
510 OUT UINT16
*DevStatus
,
517 Usb Get Device Status
521 UsbIo - EFI_USB_IO_PROTOCOL
522 Recipient - Interface/Device/Endpoint
523 Target - Request index
524 DevStatus - Device status
525 Status - Transfer status
529 EFI_INVALID_PARAMETER - Parameter is error
530 EFI_SUCCESS - Success
531 EFI_TIMEOUT - Device has no response
535 EFI_USB_DEVICE_REQUEST DevReq
;
538 return EFI_INVALID_PARAMETER
;
541 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
546 DevReq
.RequestType
= 0x80;
549 case EfiUsbInterface
:
550 DevReq
.RequestType
= 0x81;
554 DevReq
.RequestType
= 0x82;
558 // Fill device request, see USB1.1 spec
560 DevReq
.Request
= USB_DEV_GET_STATUS
;
562 DevReq
.Index
= Target
;
565 return UsbIo
->UsbControlTransfer (
580 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
595 UsbIo - EFI_USB_IO_PROTOCOL
597 Index - Request index
598 Buf - Buffer to store string
599 BufSize - Buffer size
600 Status - Transfer status
604 EFI_INVALID_PARAMETER - Parameter is error
605 EFI_SUCCESS - Success
606 EFI_TIMEOUT - Device has no response
613 return EFI_INVALID_PARAMETER
;
616 // Fill value, see USB1.1 spec
618 Value
= (UINT16
) ((USB_DT_STRING
<< 8) | Index
);
620 return UsbGetDescriptor (
631 UsbClearEndpointHalt (
632 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
644 UsbIo - EFI_USB_IO_PROTOCOL
645 EndpointNo - Endpoint Number
646 Status - Transfer Status
650 EFI_NOT_FOUND - Can't find the Endpoint
651 EFI_DEVICE_ERROR - Hardware error
652 EFI_SUCCESS - Success
657 EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor
;
658 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor
;
661 ZeroMem (&EndpointDescriptor
, sizeof (EFI_USB_ENDPOINT_DESCRIPTOR
));
663 // First seach the endpoint descriptor for that endpoint addr
665 Result
= UsbIo
->UsbGetInterfaceDescriptor (
669 if (EFI_ERROR (Result
)) {
673 for (Index
= 0; Index
< InterfaceDescriptor
.NumEndpoints
; Index
++) {
674 Result
= UsbIo
->UsbGetEndpointDescriptor (
679 if (EFI_ERROR (Result
)) {
683 if (EndpointDescriptor
.EndpointAddress
== EndpointNo
) {
688 if (Index
== InterfaceDescriptor
.NumEndpoints
) {
692 return EFI_NOT_FOUND
;
695 Result
= UsbClearDeviceFeature (
699 EndpointDescriptor
.EndpointAddress
,