3 The library provides the USB descritor, interface and protocol
6 Copyright (c) 2004 - 2007, Intel Corporation All rights
7 reserved. This program and the accompanying materials are
8 licensed and made available under the terms and conditions of
9 the BSD License which accompanies this distribution. The full
10 text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #include <UefiUsbLibInternal.h>
25 @param UsbIo EFI_USB_IO_PROTOCOL.
26 @param Value Device Request Value.
27 @param Index Device Request Index.
28 @param DescriptorLength Descriptor Length.
29 @param Descriptor Descriptor buffer to contain result.
30 @param Status Transfer Status.
32 @retval EFI_INVALID_PARAMETER Parameter is error.
33 @retval EFI_SUCCESS Success.
34 @retval EFI_TIMEOUT Device has no response.
40 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
43 IN UINT16 DescriptorLength
,
48 EFI_USB_DEVICE_REQUEST DevReq
;
51 return EFI_INVALID_PARAMETER
;
54 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
56 DevReq
.RequestType
= USB_DEV_GET_DESCRIPTOR_REQ_TYPE
;
57 DevReq
.Request
= USB_REQ_GET_DESCRIPTOR
;
60 DevReq
.Length
= DescriptorLength
;
62 return UsbIo
->UsbControlTransfer (
77 @param UsbIo EFI_USB_IO_PROTOCOL.
78 @param Value Device Request Value.
79 @param Index Device Request Index.
80 @param DescriptorLength Descriptor Length.
81 @param Descriptor Descriptor buffer to set.
82 @param Status Transfer Status.
84 @retval EFI_INVALID_PARAMETER Parameter is error.
85 @retval EFI_SUCCESS Success.
86 @retval EFI_TIMEOUT Device has no response.
92 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
95 IN UINT16 DescriptorLength
,
100 EFI_USB_DEVICE_REQUEST DevReq
;
103 return EFI_INVALID_PARAMETER
;
106 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
108 DevReq
.RequestType
= USB_DEV_SET_DESCRIPTOR_REQ_TYPE
;
109 DevReq
.Request
= USB_REQ_SET_DESCRIPTOR
;
110 DevReq
.Value
= Value
;
111 DevReq
.Index
= Index
;
112 DevReq
.Length
= DescriptorLength
;
114 return UsbIo
->UsbControlTransfer (
127 Usb Get Device Interface.
129 @param UsbIo EFI_USB_IO_PROTOCOL.
130 @param Index Interface index value.
131 @param AltSetting Alternate setting.
132 @param Status Trasnsfer status.
134 @retval EFI_INVALID_PARAMETER Parameter is error.
135 @retval EFI_SUCCESS Success.
136 @retval EFI_TIMEOUT Device has no response.
142 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
144 OUT UINT8
*AltSetting
,
148 EFI_USB_DEVICE_REQUEST DevReq
;
151 return EFI_INVALID_PARAMETER
;
154 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
156 DevReq
.RequestType
= USB_DEV_GET_INTERFACE_REQ_TYPE
;
157 DevReq
.Request
= USB_REQ_GET_INTERFACE
;
158 DevReq
.Index
= Index
;
161 return UsbIo
->UsbControlTransfer (
174 Usb Set Device Interface.
176 @param UsbIo EFI_USB_IO_PROTOCOL.
177 @param InterfaceNo Interface Number.
178 @param AltSetting Alternate setting.
179 @param Status Trasnsfer status.
181 @retval EFI_INVALID_PARAMETER Parameter is error.
182 @retval EFI_SUCCESS Success.
183 @retval EFI_TIMEOUT Device has no response.
189 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
190 IN UINT16 InterfaceNo
,
191 IN UINT16 AltSetting
,
195 EFI_USB_DEVICE_REQUEST DevReq
;
198 return EFI_INVALID_PARAMETER
;
201 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
203 DevReq
.RequestType
= USB_DEV_SET_INTERFACE_REQ_TYPE
;
204 DevReq
.Request
= USB_REQ_SET_INTERFACE
;
205 DevReq
.Value
= AltSetting
;
206 DevReq
.Index
= InterfaceNo
;
209 return UsbIo
->UsbControlTransfer (
222 Usb Get Device Configuration.
224 @param UsbIo EFI_USB_IO_PROTOCOL.
225 @param ConfigValue Config Value.
226 @param Status Transfer Status.
228 @retval EFI_INVALID_PARAMETER Parameter is error.
229 @retval EFI_SUCCESS Success.
230 @retval EFI_TIMEOUT Device has no response.
235 UsbGetConfiguration (
236 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
237 OUT UINT8
*ConfigValue
,
241 EFI_USB_DEVICE_REQUEST DevReq
;
244 return EFI_INVALID_PARAMETER
;
247 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
249 DevReq
.RequestType
= USB_DEV_GET_CONFIGURATION_REQ_TYPE
;
250 DevReq
.Request
= USB_REQ_GET_CONFIG
;
253 return UsbIo
->UsbControlTransfer (
266 Usb Set Device Configuration.
268 @param UsbIo EFI_USB_IO_PROTOCOL.
269 @param Value Configuration Value to set.
270 @param Status Transfer status.
272 @retval EFI_INVALID_PARAMETER Parameter is error.
273 @retval EFI_SUCCESS Success.
274 @retval EFI_TIMEOUT Device has no response.
279 UsbSetConfiguration (
280 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
285 EFI_USB_DEVICE_REQUEST DevReq
;
288 return EFI_INVALID_PARAMETER
;
291 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
293 DevReq
.RequestType
= USB_DEV_SET_CONFIGURATION_REQ_TYPE
;
294 DevReq
.Request
= USB_REQ_SET_CONFIG
;
295 DevReq
.Value
= Value
;
297 return UsbIo
->UsbControlTransfer (
310 Usb Set Device Feature.
312 @param UsbIo EFI_USB_IO_PROTOCOL.
313 @param Recipient Interface/Device/Endpoint.
314 @param Value Request value.
315 @param Target Request Index.
316 @param Status Transfer status.
318 @retval EFI_INVALID_PARAMETER Parameter is error.
319 @retval EFI_SUCCESS Success.
320 @retval EFI_TIMEOUT Device has no response.
326 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
333 EFI_USB_DEVICE_REQUEST DevReq
;
336 return EFI_INVALID_PARAMETER
;
339 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
343 case USB_TARGET_DEVICE
:
344 DevReq
.RequestType
= USB_DEV_SET_FEATURE_REQ_TYPE_D
;
347 case USB_TARGET_INTERFACE
:
348 DevReq
.RequestType
= USB_DEV_SET_FEATURE_REQ_TYPE_I
;
351 case USB_TARGET_ENDPOINT
:
352 DevReq
.RequestType
= USB_DEV_SET_FEATURE_REQ_TYPE_E
;
356 // Fill device request, see USB1.1 spec
358 DevReq
.Request
= USB_REQ_SET_FEATURE
;
359 DevReq
.Value
= Value
;
360 DevReq
.Index
= Target
;
363 return UsbIo
->UsbControlTransfer (
376 Usb Clear Device Feature.
378 @param UsbIo EFI_USB_IO_PROTOCOL.
379 @param Recipient Interface/Device/Endpoint.
380 @param Value Request value.
381 @param Target Request Index.
382 @param Status Transfer status.
384 @retval EFI_INVALID_PARAMETER Parameter is error.
385 @retval EFI_SUCCESS Success.
386 @retval EFI_TIMEOUT Device has no response.
392 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
399 EFI_USB_DEVICE_REQUEST DevReq
;
402 return EFI_INVALID_PARAMETER
;
405 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
409 case USB_TARGET_DEVICE
:
410 DevReq
.RequestType
= USB_DEV_CLEAR_FEATURE_REQ_TYPE_D
;
413 case USB_TARGET_INTERFACE
:
414 DevReq
.RequestType
= USB_DEV_CLEAR_FEATURE_REQ_TYPE_I
;
417 case USB_TARGET_ENDPOINT
:
418 DevReq
.RequestType
= USB_DEV_CLEAR_FEATURE_REQ_TYPE_E
;
422 // Fill device request, see USB1.1 spec
424 DevReq
.Request
= USB_REQ_CLEAR_FEATURE
;
425 DevReq
.Value
= Value
;
426 DevReq
.Index
= Target
;
429 return UsbIo
->UsbControlTransfer (
442 Usb Get Device Status.
444 @param UsbIo EFI_USB_IO_PROTOCOL.
445 @param Recipient Interface/Device/Endpoint.
446 @param Target Request index.
447 @param DevStatus Device status.
448 @param Status Transfer status.
450 @retval EFI_INVALID_PARAMETER Parameter is error.
451 @retval EFI_SUCCESS Success.
452 @retval EFI_TIMEOUT Device has no response.
458 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
461 OUT UINT16
*DevStatus
,
465 EFI_USB_DEVICE_REQUEST DevReq
;
468 return EFI_INVALID_PARAMETER
;
471 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
475 case USB_TARGET_DEVICE
:
476 DevReq
.RequestType
= USB_DEV_GET_STATUS_REQ_TYPE_D
;
479 case USB_TARGET_INTERFACE
:
480 DevReq
.RequestType
= USB_DEV_GET_STATUS_REQ_TYPE_I
;
483 case USB_TARGET_ENDPOINT
:
484 DevReq
.RequestType
= USB_DEV_GET_STATUS_REQ_TYPE_E
;
488 // Fill device request, see USB1.1 spec
490 DevReq
.Request
= USB_REQ_GET_STATUS
;
492 DevReq
.Index
= Target
;
495 return UsbIo
->UsbControlTransfer (
508 Clear endpoint stall.
510 @param UsbIo EFI_USB_IO_PROTOCOL.
511 @param EndpointNo Endpoint Number.
512 @param Status Transfer Status.
514 @retval EFI_NOT_FOUND Can't find the Endpoint.
515 @retval EFI_DEVICE_ERROR Hardware error.
516 @retval EFI_SUCCESS Success.
521 UsbClearEndpointHalt (
522 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
528 EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor
;
529 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor
;
533 return EFI_INVALID_PARAMETER
;
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 (
573 USB_FEATURE_ENDPOINT_HALT
,
574 EndpointDescriptor
.EndpointAddress
,