3 The library provides the USB Standard Device Requests defined
4 in Usb specification 9.4 section.
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.
18 #include "UefiUsbLibInternal.h"
24 @param UsbIo EFI_USB_IO_PROTOCOL.
25 @param Value Device Request Value.
26 @param Index Device Request Index.
27 @param DescriptorLength Descriptor Length.
28 @param Descriptor Descriptor buffer to contain result.
29 @param Status Transfer Status.
31 @retval EFI_INVALID_PARAMETER Parameter is error.
32 @retval EFI_SUCCESS Success.
33 @retval EFI_TIMEOUT Device has no response.
39 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
42 IN UINT16 DescriptorLength
,
47 EFI_USB_DEVICE_REQUEST DevReq
;
50 return EFI_INVALID_PARAMETER
;
53 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
55 DevReq
.RequestType
= USB_DEV_GET_DESCRIPTOR_REQ_TYPE
;
56 DevReq
.Request
= USB_REQ_GET_DESCRIPTOR
;
59 DevReq
.Length
= DescriptorLength
;
61 return UsbIo
->UsbControlTransfer (
76 @param UsbIo EFI_USB_IO_PROTOCOL.
77 @param Value Device Request Value.
78 @param Index Device Request Index.
79 @param DescriptorLength Descriptor Length.
80 @param Descriptor Descriptor buffer to set.
81 @param Status Transfer Status.
83 @retval EFI_INVALID_PARAMETER Parameter is error.
84 @retval EFI_SUCCESS Success.
85 @retval EFI_TIMEOUT Device has no response.
91 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
94 IN UINT16 DescriptorLength
,
99 EFI_USB_DEVICE_REQUEST DevReq
;
102 return EFI_INVALID_PARAMETER
;
105 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
107 DevReq
.RequestType
= USB_DEV_SET_DESCRIPTOR_REQ_TYPE
;
108 DevReq
.Request
= USB_REQ_SET_DESCRIPTOR
;
109 DevReq
.Value
= Value
;
110 DevReq
.Index
= Index
;
111 DevReq
.Length
= DescriptorLength
;
113 return UsbIo
->UsbControlTransfer (
126 Usb Get Device Interface.
128 @param UsbIo EFI_USB_IO_PROTOCOL.
129 @param Index Interface index value.
130 @param AltSetting Alternate setting.
131 @param Status Trasnsfer status.
133 @retval EFI_INVALID_PARAMETER Parameter is error.
134 @retval EFI_SUCCESS Success.
135 @retval EFI_TIMEOUT Device has no response.
141 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
143 OUT UINT8
*AltSetting
,
147 EFI_USB_DEVICE_REQUEST DevReq
;
150 return EFI_INVALID_PARAMETER
;
153 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
155 DevReq
.RequestType
= USB_DEV_GET_INTERFACE_REQ_TYPE
;
156 DevReq
.Request
= USB_REQ_GET_INTERFACE
;
157 DevReq
.Index
= Index
;
160 return UsbIo
->UsbControlTransfer (
173 Usb Set Device Interface.
175 @param UsbIo EFI_USB_IO_PROTOCOL.
176 @param InterfaceNo Interface Number.
177 @param AltSetting Alternate setting.
178 @param Status Trasnsfer status.
180 @retval EFI_INVALID_PARAMETER Parameter is error.
181 @retval EFI_SUCCESS Success.
182 @retval EFI_TIMEOUT Device has no response.
188 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
189 IN UINT16 InterfaceNo
,
190 IN UINT16 AltSetting
,
194 EFI_USB_DEVICE_REQUEST DevReq
;
197 return EFI_INVALID_PARAMETER
;
200 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
202 DevReq
.RequestType
= USB_DEV_SET_INTERFACE_REQ_TYPE
;
203 DevReq
.Request
= USB_REQ_SET_INTERFACE
;
204 DevReq
.Value
= AltSetting
;
205 DevReq
.Index
= InterfaceNo
;
208 return UsbIo
->UsbControlTransfer (
221 Usb Get Device Configuration.
223 @param UsbIo EFI_USB_IO_PROTOCOL.
224 @param ConfigValue Config Value.
225 @param Status Transfer Status.
227 @retval EFI_INVALID_PARAMETER Parameter is error.
228 @retval EFI_SUCCESS Success.
229 @retval EFI_TIMEOUT Device has no response.
234 UsbGetConfiguration (
235 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
236 OUT UINT8
*ConfigValue
,
240 EFI_USB_DEVICE_REQUEST DevReq
;
243 return EFI_INVALID_PARAMETER
;
246 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
248 DevReq
.RequestType
= USB_DEV_GET_CONFIGURATION_REQ_TYPE
;
249 DevReq
.Request
= USB_REQ_GET_CONFIG
;
252 return UsbIo
->UsbControlTransfer (
265 Usb Set Device Configuration.
267 @param UsbIo EFI_USB_IO_PROTOCOL.
268 @param Value Configuration Value to set.
269 @param Status Transfer status.
271 @retval EFI_INVALID_PARAMETER Parameter is error.
272 @retval EFI_SUCCESS Success.
273 @retval EFI_TIMEOUT Device has no response.
278 UsbSetConfiguration (
279 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
284 EFI_USB_DEVICE_REQUEST DevReq
;
287 return EFI_INVALID_PARAMETER
;
290 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
292 DevReq
.RequestType
= USB_DEV_SET_CONFIGURATION_REQ_TYPE
;
293 DevReq
.Request
= USB_REQ_SET_CONFIG
;
294 DevReq
.Value
= Value
;
296 return UsbIo
->UsbControlTransfer (
309 Usb Set Device Feature.
311 @param UsbIo EFI_USB_IO_PROTOCOL.
312 @param Recipient Interface/Device/Endpoint.
313 @param Value Request value.
314 @param Target Request Index.
315 @param Status Transfer status.
317 @retval EFI_INVALID_PARAMETER Parameter is error.
318 @retval EFI_SUCCESS Success.
319 @retval EFI_TIMEOUT Device has no response.
325 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
332 EFI_USB_DEVICE_REQUEST DevReq
;
335 return EFI_INVALID_PARAMETER
;
338 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
342 case USB_TARGET_DEVICE
:
343 DevReq
.RequestType
= USB_DEV_SET_FEATURE_REQ_TYPE_D
;
346 case USB_TARGET_INTERFACE
:
347 DevReq
.RequestType
= USB_DEV_SET_FEATURE_REQ_TYPE_I
;
350 case USB_TARGET_ENDPOINT
:
351 DevReq
.RequestType
= USB_DEV_SET_FEATURE_REQ_TYPE_E
;
355 // Fill device request, see USB1.1 spec
357 DevReq
.Request
= USB_REQ_SET_FEATURE
;
358 DevReq
.Value
= Value
;
359 DevReq
.Index
= Target
;
362 return UsbIo
->UsbControlTransfer (
375 Usb Clear Device Feature.
377 @param UsbIo EFI_USB_IO_PROTOCOL.
378 @param Recipient Interface/Device/Endpoint.
379 @param Value Request value.
380 @param Target Request Index.
381 @param Status Transfer status.
383 @retval EFI_INVALID_PARAMETER Parameter is error.
384 @retval EFI_SUCCESS Success.
385 @retval EFI_TIMEOUT Device has no response.
391 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
398 EFI_USB_DEVICE_REQUEST DevReq
;
401 return EFI_INVALID_PARAMETER
;
404 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
408 case USB_TARGET_DEVICE
:
409 DevReq
.RequestType
= USB_DEV_CLEAR_FEATURE_REQ_TYPE_D
;
412 case USB_TARGET_INTERFACE
:
413 DevReq
.RequestType
= USB_DEV_CLEAR_FEATURE_REQ_TYPE_I
;
416 case USB_TARGET_ENDPOINT
:
417 DevReq
.RequestType
= USB_DEV_CLEAR_FEATURE_REQ_TYPE_E
;
421 // Fill device request, see USB1.1 spec
423 DevReq
.Request
= USB_REQ_CLEAR_FEATURE
;
424 DevReq
.Value
= Value
;
425 DevReq
.Index
= Target
;
428 return UsbIo
->UsbControlTransfer (
441 Usb Get Device Status.
443 @param UsbIo EFI_USB_IO_PROTOCOL.
444 @param Recipient Interface/Device/Endpoint.
445 @param Target Request index.
446 @param DevStatus Device status.
447 @param Status Transfer status.
449 @retval EFI_INVALID_PARAMETER Parameter is error.
450 @retval EFI_SUCCESS Success.
451 @retval EFI_TIMEOUT Device has no response.
457 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
460 OUT UINT16
*DevStatus
,
464 EFI_USB_DEVICE_REQUEST DevReq
;
467 return EFI_INVALID_PARAMETER
;
470 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
474 case USB_TARGET_DEVICE
:
475 DevReq
.RequestType
= USB_DEV_GET_STATUS_REQ_TYPE_D
;
478 case USB_TARGET_INTERFACE
:
479 DevReq
.RequestType
= USB_DEV_GET_STATUS_REQ_TYPE_I
;
482 case USB_TARGET_ENDPOINT
:
483 DevReq
.RequestType
= USB_DEV_GET_STATUS_REQ_TYPE_E
;
487 // Fill device request, see USB1.1 spec
489 DevReq
.Request
= USB_REQ_GET_STATUS
;
491 DevReq
.Index
= Target
;
494 return UsbIo
->UsbControlTransfer (
507 Clear endpoint stall.
509 @param UsbIo EFI_USB_IO_PROTOCOL.
510 @param EndpointNo Endpoint Number.
511 @param Status Transfer Status.
513 @retval EFI_NOT_FOUND Can't find the Endpoint.
514 @retval EFI_DEVICE_ERROR Hardware error.
515 @retval EFI_SUCCESS Success.
520 UsbClearEndpointHalt (
521 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
527 EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor
;
528 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor
;
532 return EFI_INVALID_PARAMETER
;
535 ZeroMem (&EndpointDescriptor
, sizeof (EFI_USB_ENDPOINT_DESCRIPTOR
));
537 // First seach the endpoint descriptor for that endpoint addr
539 Result
= UsbIo
->UsbGetInterfaceDescriptor (
543 if (EFI_ERROR (Result
)) {
547 for (Index
= 0; Index
< InterfaceDescriptor
.NumEndpoints
; Index
++) {
548 Result
= UsbIo
->UsbGetEndpointDescriptor (
553 if (EFI_ERROR (Result
)) {
557 if (EndpointDescriptor
.EndpointAddress
== EndpointNo
) {
562 if (Index
== InterfaceDescriptor
.NumEndpoints
) {
566 return EFI_NOT_FOUND
;
569 Result
= UsbClearFeature (
572 USB_FEATURE_ENDPOINT_HALT
,
573 EndpointDescriptor
.EndpointAddress
,