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
24 #include "UefiUsbLibInternal.h"
27 // Get Device Descriptor
31 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
34 IN UINT16 DescriptorLength
,
46 UsbIo - EFI_USB_IO_PROTOCOL
47 Value - Device Request Value
48 Index - Device Request Index
49 DescriptorLength - Descriptor Length
50 Descriptor - Descriptor buffer to contain result
51 Status - Transfer Status
53 EFI_INVALID_PARAMETER - Parameter is error
55 EFI_TIMEOUT - Device has no response
59 EFI_USB_DEVICE_REQUEST DevReq
;
62 return EFI_INVALID_PARAMETER
;
65 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
67 DevReq
.RequestType
= USB_DEV_GET_DESCRIPTOR_REQ_TYPE
;
68 DevReq
.Request
= USB_DEV_GET_DESCRIPTOR
;
71 DevReq
.Length
= DescriptorLength
;
73 return UsbIo
->UsbControlTransfer (
84 // Set Device Descriptor
88 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
91 IN UINT16 DescriptorLength
,
103 UsbIo - EFI_USB_IO_PROTOCOL
104 Value - Device Request Value
105 Index - Device Request Index
106 DescriptorLength - Descriptor Length
107 Descriptor - Descriptor buffer to set
108 Status - Transfer Status
110 EFI_INVALID_PARAMETER - Parameter is error
111 EFI_SUCCESS - Success
112 EFI_TIMEOUT - Device has no response
116 EFI_USB_DEVICE_REQUEST DevReq
;
119 return EFI_INVALID_PARAMETER
;
122 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
124 DevReq
.RequestType
= USB_DEV_SET_DESCRIPTOR_REQ_TYPE
;
125 DevReq
.Request
= USB_DEV_SET_DESCRIPTOR
;
126 DevReq
.Value
= Value
;
127 DevReq
.Index
= Index
;
128 DevReq
.Length
= DescriptorLength
;
130 return UsbIo
->UsbControlTransfer (
142 // Get device Interface
145 UsbGetDeviceInterface (
146 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
148 OUT UINT8
*AltSetting
,
155 Usb Get Device Interface
159 UsbIo - EFI_USB_IO_PROTOCOL
160 Index - Interface index value
161 AltSetting - Alternate setting
162 Status - Trasnsfer status
166 EFI_INVALID_PARAMETER - Parameter is error
167 EFI_SUCCESS - Success
168 EFI_TIMEOUT - Device has no response
173 EFI_USB_DEVICE_REQUEST DevReq
;
176 return EFI_INVALID_PARAMETER
;
179 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
181 DevReq
.RequestType
= USB_DEV_GET_INTERFACE_REQ_TYPE
;
182 DevReq
.Request
= USB_DEV_GET_INTERFACE
;
183 DevReq
.Index
= Index
;
186 return UsbIo
->UsbControlTransfer (
197 // Set device interface
200 UsbSetDeviceInterface (
201 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
202 IN UINT16 InterfaceNo
,
203 IN UINT16 AltSetting
,
210 Usb Set Device Interface
214 UsbIo - EFI_USB_IO_PROTOCOL
215 InterfaceNo - Interface Number
216 AltSetting - Alternate setting
217 Status - Trasnsfer status
221 EFI_INVALID_PARAMETER - Parameter is error
222 EFI_SUCCESS - Success
223 EFI_TIMEOUT - Device has no response
227 EFI_USB_DEVICE_REQUEST DevReq
;
230 return EFI_INVALID_PARAMETER
;
233 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
235 DevReq
.RequestType
= USB_DEV_SET_INTERFACE_REQ_TYPE
;
236 DevReq
.Request
= USB_DEV_SET_INTERFACE
;
237 DevReq
.Value
= AltSetting
;
238 DevReq
.Index
= InterfaceNo
;
241 return UsbIo
->UsbControlTransfer (
252 // Get device configuration
255 UsbGetDeviceConfiguration (
256 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
257 OUT UINT8
*ConfigValue
,
264 Usb Get Device Configuration
268 UsbIo - EFI_USB_IO_PROTOCOL
269 ConfigValue - Config Value
270 Status - Transfer Status
274 EFI_INVALID_PARAMETER - Parameter is error
275 EFI_SUCCESS - Success
276 EFI_TIMEOUT - Device has no response
280 EFI_USB_DEVICE_REQUEST DevReq
;
283 return EFI_INVALID_PARAMETER
;
286 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
288 DevReq
.RequestType
= USB_DEV_GET_CONFIGURATION_REQ_TYPE
;
289 DevReq
.Request
= USB_DEV_GET_CONFIGURATION
;
292 return UsbIo
->UsbControlTransfer (
303 // Set device configuration
306 UsbSetDeviceConfiguration (
307 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
315 Usb Set Device Configuration
319 UsbIo - EFI_USB_IO_PROTOCOL
320 Value - Configuration Value to set
321 Status - Transfer status
325 EFI_INVALID_PARAMETER - Parameter is error
326 EFI_SUCCESS - Success
327 EFI_TIMEOUT - Device has no response
331 EFI_USB_DEVICE_REQUEST DevReq
;
334 return EFI_INVALID_PARAMETER
;
337 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
339 DevReq
.RequestType
= USB_DEV_SET_CONFIGURATION_REQ_TYPE
;
340 DevReq
.Request
= USB_DEV_SET_CONFIGURATION
;
341 DevReq
.Value
= Value
;
343 return UsbIo
->UsbControlTransfer (
354 // Set Device Feature
357 UsbSetDeviceFeature (
358 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
359 IN EFI_USB_RECIPIENT Recipient
,
368 Usb Set Device Feature
372 UsbIo - EFI_USB_IO_PROTOCOL
373 Recipient - Interface/Device/Endpoint
374 Value - Request value
375 Target - Request Index
376 Status - Transfer status
380 EFI_INVALID_PARAMETER - Parameter is error
381 EFI_SUCCESS - Success
382 EFI_TIMEOUT - Device has no response
386 EFI_USB_DEVICE_REQUEST DevReq
;
389 return EFI_INVALID_PARAMETER
;
392 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
397 DevReq
.RequestType
= 0x00;
400 case EfiUsbInterface
:
401 DevReq
.RequestType
= 0x01;
405 DevReq
.RequestType
= 0x02;
409 // Fill device request, see USB1.1 spec
411 DevReq
.Request
= USB_DEV_SET_FEATURE
;
412 DevReq
.Value
= Value
;
413 DevReq
.Index
= Target
;
416 return UsbIo
->UsbControlTransfer (
427 // Clear Device Feature
430 UsbClearDeviceFeature (
431 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
432 IN EFI_USB_RECIPIENT Recipient
,
441 Usb Clear Device Feature
445 UsbIo - EFI_USB_IO_PROTOCOL
446 Recipient - Interface/Device/Endpoint
447 Value - Request value
448 Target - Request Index
449 Status - Transfer status
453 EFI_INVALID_PARAMETER - Parameter is error
454 EFI_SUCCESS - Success
455 EFI_TIMEOUT - Device has no response
459 EFI_USB_DEVICE_REQUEST DevReq
;
462 return EFI_INVALID_PARAMETER
;
465 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
470 DevReq
.RequestType
= 0x00;
473 case EfiUsbInterface
:
474 DevReq
.RequestType
= 0x01;
478 DevReq
.RequestType
= 0x02;
482 // Fill device request, see USB1.1 spec
484 DevReq
.Request
= USB_DEV_CLEAR_FEATURE
;
485 DevReq
.Value
= Value
;
486 DevReq
.Index
= Target
;
489 return UsbIo
->UsbControlTransfer (
504 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
505 IN EFI_USB_RECIPIENT Recipient
,
507 OUT UINT16
*DevStatus
,
514 Usb Get Device Status
518 UsbIo - EFI_USB_IO_PROTOCOL
519 Recipient - Interface/Device/Endpoint
520 Target - Request index
521 DevStatus - Device status
522 Status - Transfer status
526 EFI_INVALID_PARAMETER - Parameter is error
527 EFI_SUCCESS - Success
528 EFI_TIMEOUT - Device has no response
532 EFI_USB_DEVICE_REQUEST DevReq
;
535 return EFI_INVALID_PARAMETER
;
538 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
543 DevReq
.RequestType
= 0x80;
546 case EfiUsbInterface
:
547 DevReq
.RequestType
= 0x81;
551 DevReq
.RequestType
= 0x82;
555 // Fill device request, see USB1.1 spec
557 DevReq
.Request
= USB_DEV_GET_STATUS
;
559 DevReq
.Index
= Target
;
562 return UsbIo
->UsbControlTransfer (
577 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
592 UsbIo - EFI_USB_IO_PROTOCOL
594 Index - Request index
595 Buf - Buffer to store string
596 BufSize - Buffer size
597 Status - Transfer status
601 EFI_INVALID_PARAMETER - Parameter is error
602 EFI_SUCCESS - Success
603 EFI_TIMEOUT - Device has no response
610 return EFI_INVALID_PARAMETER
;
613 // Fill value, see USB1.1 spec
615 Value
= (UINT16
) ((USB_DT_STRING
<< 8) | Index
);
617 return UsbGetDescriptor (
628 UsbClearEndpointHalt (
629 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
641 UsbIo - EFI_USB_IO_PROTOCOL
642 EndpointNo - Endpoint Number
643 Status - Transfer Status
647 EFI_NOT_FOUND - Can't find the Endpoint
648 EFI_DEVICE_ERROR - Hardware error
649 EFI_SUCCESS - Success
654 EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor
;
655 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor
;
658 ZeroMem (&EndpointDescriptor
, sizeof (EFI_USB_ENDPOINT_DESCRIPTOR
));
660 // First seach the endpoint descriptor for that endpoint addr
662 Result
= UsbIo
->UsbGetInterfaceDescriptor (
666 if (EFI_ERROR (Result
)) {
670 for (Index
= 0; Index
< InterfaceDescriptor
.NumEndpoints
; Index
++) {
671 Result
= UsbIo
->UsbGetEndpointDescriptor (
676 if (EFI_ERROR (Result
)) {
680 if (EndpointDescriptor
.EndpointAddress
== EndpointNo
) {
685 if (Index
== InterfaceDescriptor
.NumEndpoints
) {
689 return EFI_NOT_FOUND
;
692 Result
= UsbClearDeviceFeature (
696 EndpointDescriptor
.EndpointAddress
,