]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/UefiUsbLib/UsbDxeLib.c
Code Scrub:
[mirror_edk2.git] / MdePkg / Library / UefiUsbLib / UsbDxeLib.c
CommitLineData
ed838d0c 1/** @file\r
7bc232b2 2\r
11ceade4
LG
3 The library provides the USB Standard Device Requests defined \r
4 in Usb specification 9.4 section.\r
c311f86b 5 \r
6 Copyright (c) 2004 - 2007, Intel Corporation All rights\r
7 reserved. This program and the accompanying materials are\r
8 licensed and made available under the terms and conditions of\r
9 the BSD License which accompanies this distribution. The full\r
10 text of the license may be found at\r
11 http://opensource.org/licenses/bsd-license.php\r
12 \r
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
7bc232b2 15\r
ed838d0c 16**/\r
7bc232b2 17\r
6c401377 18#include "UefiUsbLibInternal.h"\r
dad203ec 19\r
ed838d0c 20\r
21/**\r
d5954c61 22 Get the descriptor of the specified USB device.\r
23\r
24 Submit a USB get descriptor request for the USB device specified by UsbIo, Value,\r
25 and Index, and return the descriptor in the buffer specified by Descriptor.\r
26 The status of the transfer is returned in Status.\r
27 If UsbIo is NULL, then ASSERT().\r
28 If Descriptor is NULL, then ASSERT().\r
29 If Status is NULL, then ASSERT().\r
30\r
31 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
32 @param Value The device request value.\r
33 @param Index The device request index.\r
34 @param DescriptorLength The size, in bytes, of Descriptor.\r
35 @param Descriptor A pointer to the descriptor buffer to get.\r
36 @param Status A pointer to the status of the transfer.\r
37\r
38 @retval EFI_SUCCESS The request executed successfully.\r
39 @retval EFI_OUT_OF_RESOURCES The request could not be completed because the\r
40 buffer specifed by DescriptorLength and Descriptor\r
41 is not large enough to hold the result of the request.\r
42 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
43 @retval EFI_DEVICE_ERROR The request failed due to a device error. The transfer\r
44 status is returned in Status.\r
ed838d0c 45\r
46**/\r
7bc232b2 47EFI_STATUS\r
f1787349 48EFIAPI\r
7bc232b2
LG
49UsbGetDescriptor (\r
50 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
51 IN UINT16 Value,\r
52 IN UINT16 Index,\r
53 IN UINT16 DescriptorLength,\r
54 OUT VOID *Descriptor,\r
55 OUT UINT32 *Status\r
56 )\r
7bc232b2
LG
57{\r
58 EFI_USB_DEVICE_REQUEST DevReq;\r
59\r
d5954c61 60 ASSERT (UsbIo != NULL);\r
61 ASSERT (Descriptor != NULL);\r
62 ASSERT (Status != NULL);\r
7bc232b2
LG
63\r
64 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
65\r
66 DevReq.RequestType = USB_DEV_GET_DESCRIPTOR_REQ_TYPE;\r
ed838d0c 67 DevReq.Request = USB_REQ_GET_DESCRIPTOR;\r
7bc232b2
LG
68 DevReq.Value = Value;\r
69 DevReq.Index = Index;\r
70 DevReq.Length = DescriptorLength;\r
71\r
72 return UsbIo->UsbControlTransfer (\r
73 UsbIo,\r
74 &DevReq,\r
75 EfiUsbDataIn,\r
76 TIMEOUT_VALUE,\r
77 Descriptor,\r
78 DescriptorLength,\r
79 Status\r
80 );\r
81}\r
ed838d0c 82\r
83\r
84/**\r
d5954c61 85 Set the descriptor of the specified USB device.\r
86\r
87 Submit a USB set descriptor request for the USB device specified by UsbIo,\r
88 Value, and Index, and set the descriptor using the buffer specified by DesriptorLength\r
89 and Descriptor. The status of the transfer is returned in Status.\r
90 If UsbIo is NULL, then ASSERT().\r
91 If Descriptor is NULL, then ASSERT().\r
92 If Status is NULL, then ASSERT().\r
93\r
94 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
95 @param Value The device request value.\r
96 @param Index The device request index.\r
97 @param DescriptorLength The size, in bytes, of Descriptor.\r
98 @param Descriptor A pointer to the descriptor buffer to set.\r
99 @param Status A pointer to the status of the transfer.\r
100\r
101 @retval EFI_SUCCESS The request executed successfully.\r
102 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
103 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
104 The transfer status is returned in Status.\r
ed838d0c 105\r
106**/\r
7bc232b2 107EFI_STATUS\r
f1787349 108EFIAPI\r
7bc232b2
LG
109UsbSetDescriptor (\r
110 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
111 IN UINT16 Value,\r
112 IN UINT16 Index,\r
113 IN UINT16 DescriptorLength,\r
114 IN VOID *Descriptor,\r
115 OUT UINT32 *Status\r
116 )\r
7bc232b2
LG
117{\r
118 EFI_USB_DEVICE_REQUEST DevReq;\r
119\r
d5954c61 120 ASSERT (UsbIo != NULL);\r
121 ASSERT (Descriptor != NULL);\r
122 ASSERT (Status != NULL);\r
7bc232b2
LG
123\r
124 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
125\r
126 DevReq.RequestType = USB_DEV_SET_DESCRIPTOR_REQ_TYPE;\r
ed838d0c 127 DevReq.Request = USB_REQ_SET_DESCRIPTOR;\r
7bc232b2
LG
128 DevReq.Value = Value;\r
129 DevReq.Index = Index;\r
130 DevReq.Length = DescriptorLength;\r
131\r
132 return UsbIo->UsbControlTransfer (\r
133 UsbIo,\r
134 &DevReq,\r
135 EfiUsbDataOut,\r
136 TIMEOUT_VALUE,\r
137 Descriptor,\r
138 DescriptorLength,\r
139 Status\r
140 );\r
141}\r
142\r
ed838d0c 143\r
144/**\r
d5954c61 145 Get the interface setting of the specified USB device.\r
ed838d0c 146\r
d5954c61 147 Submit a USB get interface request for the USB device specified by UsbIo,\r
148 and Interface, and place the result in the buffer specified by AlternateSetting.\r
149 The status of the transfer is returned in Status.\r
150 If UsbIo is NULL, then ASSERT().\r
151 If AlternateSetting is NULL, then ASSERT().\r
152 If Status is NULL, then ASSERT().\r
ed838d0c 153\r
d5954c61 154 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
155 @param Interface The interface index value.\r
156 @param AlternateSetting A pointer to the alternate setting to be retrieved.\r
157 @param Status A pointer to the status of the transfer.\r
158\r
159 @retval EFI_SUCCESS The request executed successfully.\r
160 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
161 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
162 The transfer status is returned in Status.\r
ed838d0c 163\r
164**/\r
7bc232b2 165EFI_STATUS\r
f1787349 166EFIAPI\r
ed838d0c 167UsbGetInterface (\r
7bc232b2 168 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
d5954c61 169 IN UINT16 Interface,\r
170 OUT UINT8 *AlternateSetting,\r
7bc232b2
LG
171 OUT UINT32 *Status\r
172 )\r
7bc232b2
LG
173{\r
174 EFI_USB_DEVICE_REQUEST DevReq;\r
175\r
d5954c61 176 ASSERT (UsbIo != NULL);\r
177 ASSERT (AlternateSetting != NULL);\r
178 ASSERT (Status != NULL);\r
7bc232b2
LG
179\r
180 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
181\r
182 DevReq.RequestType = USB_DEV_GET_INTERFACE_REQ_TYPE;\r
ed838d0c 183 DevReq.Request = USB_REQ_GET_INTERFACE;\r
d5954c61 184 DevReq.Index = Interface;\r
7bc232b2
LG
185 DevReq.Length = 1;\r
186\r
187 return UsbIo->UsbControlTransfer (\r
188 UsbIo,\r
189 &DevReq,\r
190 EfiUsbDataIn,\r
191 TIMEOUT_VALUE,\r
d5954c61 192 AlternateSetting,\r
7bc232b2
LG
193 1,\r
194 Status\r
195 );\r
196}\r
7bc232b2 197\r
7bc232b2 198\r
ed838d0c 199/**\r
d5954c61 200 Set the interface setting of the specified USB device.\r
7bc232b2 201\r
d5954c61 202 Submit a USB set interface request for the USB device specified by UsbIo, and\r
203 Interface, and set the alternate setting to the value specified by AlternateSetting.\r
204 The status of the transfer is returned in Status.\r
205 If UsbIo is NULL, then ASSERT().\r
206 If Status is NULL, then ASSERT().\r
7bc232b2 207\r
d5954c61 208 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
209 @param Interface The interface index value.\r
210 @param AlternateSetting The alternate setting to be set.\r
211 @param Status A pointer to the status of the transfer.\r
212\r
213 @retval EFI_SUCCESS The request executed successfully.\r
214 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
215 @retval EFI_SUCCESS The request failed due to a device error.\r
216 The transfer status is returned in Status.\r
7bc232b2 217\r
ed838d0c 218**/\r
219EFI_STATUS\r
f1787349 220EFIAPI\r
ed838d0c 221UsbSetInterface (\r
222 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
d5954c61 223 IN UINT16 Interface,\r
224 IN UINT16 AlternateSetting,\r
ed838d0c 225 OUT UINT32 *Status\r
226 )\r
7bc232b2
LG
227{\r
228 EFI_USB_DEVICE_REQUEST DevReq;\r
229\r
d5954c61 230 ASSERT (UsbIo != NULL);\r
231 ASSERT (Status != NULL);\r
7bc232b2
LG
232\r
233 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
234\r
235 DevReq.RequestType = USB_DEV_SET_INTERFACE_REQ_TYPE;\r
ed838d0c 236 DevReq.Request = USB_REQ_SET_INTERFACE;\r
d5954c61 237 DevReq.Value = AlternateSetting;\r
238 DevReq.Index = Interface;\r
7bc232b2
LG
239\r
240 return UsbIo->UsbControlTransfer (\r
241 UsbIo,\r
242 &DevReq,\r
243 EfiUsbNoData,\r
244 TIMEOUT_VALUE,\r
245 NULL,\r
246 0,\r
247 Status\r
248 );\r
249}\r
7bc232b2 250\r
7bc232b2 251\r
ed838d0c 252/**\r
d5954c61 253 Get the device configuration.\r
254\r
255 Submit a USB get configuration request for the USB device specified by UsbIo\r
256 and place the result in the buffer specified by ConfigurationValue. The status\r
257 of the transfer is returned in Status.\r
258 If UsbIo is NULL, then ASSERT().\r
259 If ConfigurationValue is NULL, then ASSERT().\r
260 If Status is NULL, then ASSERT().\r
7bc232b2 261\r
d5954c61 262 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
263 @param ConfigurationValue A pointer to the device configuration to be retrieved.\r
264 @param Status A pointer to the status of the transfer.\r
7bc232b2 265\r
d5954c61 266 @retval EFI_SUCCESS The request executed successfully.\r
267 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
268 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
269 The transfer status is returned in Status.\r
7bc232b2 270\r
ed838d0c 271**/\r
272EFI_STATUS\r
f1787349 273EFIAPI\r
ed838d0c 274UsbGetConfiguration (\r
275 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
d5954c61 276 OUT UINT8 *ConfigurationValue,\r
ed838d0c 277 OUT UINT32 *Status\r
278 )\r
7bc232b2
LG
279{\r
280 EFI_USB_DEVICE_REQUEST DevReq;\r
281\r
d5954c61 282 ASSERT (UsbIo != NULL);\r
283 ASSERT (ConfigurationValue != NULL);\r
284 ASSERT (Status != NULL);\r
7bc232b2
LG
285\r
286 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
287\r
288 DevReq.RequestType = USB_DEV_GET_CONFIGURATION_REQ_TYPE;\r
ed838d0c 289 DevReq.Request = USB_REQ_GET_CONFIG;\r
7bc232b2
LG
290 DevReq.Length = 1;\r
291\r
292 return UsbIo->UsbControlTransfer (\r
293 UsbIo,\r
294 &DevReq,\r
295 EfiUsbDataIn,\r
296 TIMEOUT_VALUE,\r
d5954c61 297 ConfigurationValue,\r
7bc232b2
LG
298 1,\r
299 Status\r
300 );\r
301}\r
7bc232b2 302\r
7bc232b2 303\r
ed838d0c 304/**\r
d5954c61 305 Set the device configuration.\r
306\r
307 Submit a USB set configuration request for the USB device specified by UsbIo\r
308 and set the device configuration to the value specified by ConfigurationValue.\r
309 The status of the transfer is returned in Status.\r
310 If UsbIo is NULL, then ASSERT().\r
311 If Status is NULL, then ASSERT().\r
7bc232b2 312\r
d5954c61 313 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
314 @param ConfigurationValue The device configuration value to be set.\r
315 @param Status A pointer to the status of the transfer.\r
7bc232b2 316\r
d5954c61 317 @retval EFI_SUCCESS The request executed successfully.\r
318 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
319 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
320 The transfer status is returned in Status.\r
7bc232b2 321\r
ed838d0c 322**/\r
323EFI_STATUS\r
f1787349 324EFIAPI\r
ed838d0c 325UsbSetConfiguration (\r
326 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
d5954c61 327 IN UINT16 ConfigurationValue,\r
ed838d0c 328 OUT UINT32 *Status\r
329 )\r
7bc232b2
LG
330{\r
331 EFI_USB_DEVICE_REQUEST DevReq;\r
332\r
d5954c61 333 ASSERT (UsbIo != NULL);\r
334 ASSERT (Status != NULL);\r
7bc232b2
LG
335\r
336 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
337\r
338 DevReq.RequestType = USB_DEV_SET_CONFIGURATION_REQ_TYPE;\r
ed838d0c 339 DevReq.Request = USB_REQ_SET_CONFIG;\r
d5954c61 340 DevReq.Value = ConfigurationValue;\r
ed838d0c 341\r
7bc232b2
LG
342 return UsbIo->UsbControlTransfer (\r
343 UsbIo,\r
344 &DevReq,\r
345 EfiUsbNoData,\r
346 TIMEOUT_VALUE,\r
347 NULL,\r
348 0,\r
349 Status\r
350 );\r
351}\r
7bc232b2 352\r
7bc232b2 353\r
ed838d0c 354/**\r
d5954c61 355 Set the specified feature of the specified device.\r
356\r
357 Submit a USB set device feature request for the USB device specified by UsbIo,\r
358 Recipient, and Target to the value specified by Value. The status of the\r
359 transfer is returned in Status.\r
360 If UsbIo is NULL, then ASSERT().\r
361 If Status is NULL, then ASSERT().\r
362\r
363 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
364 @param Recipient The USB data recipient type (i.e. Device, Interface, Endpoint).\r
365 Type USB_TYPES_DEFINITION is defined in the MDE Package Industry\r
366 Standard include file Usb.h.\r
367 @param Value The value of the feature to be set.\r
368 @param Target The index of the device to be set.\r
369 @param Status A pointer to the status of the transfer.\r
370\r
371 @retval EFI_SUCCESS The request executed successfully.\r
372 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
373 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
374 The transfer status is returned in Status.\r
7bc232b2 375\r
ed838d0c 376**/\r
377EFI_STATUS\r
f1787349 378EFIAPI\r
ed838d0c 379UsbSetFeature (\r
380 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
d5954c61 381 IN USB_TYPES_DEFINITION Recipient,\r
ed838d0c 382 IN UINT16 Value,\r
383 IN UINT16 Target,\r
384 OUT UINT32 *Status\r
385 )\r
7bc232b2
LG
386{\r
387 EFI_USB_DEVICE_REQUEST DevReq;\r
388\r
d5954c61 389 ASSERT (UsbIo != NULL);\r
390 ASSERT (Status != NULL);\r
7bc232b2
LG
391\r
392 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
393\r
394 switch (Recipient) {\r
395\r
ed838d0c 396 case USB_TARGET_DEVICE:\r
397 DevReq.RequestType = USB_DEV_SET_FEATURE_REQ_TYPE_D;\r
7bc232b2
LG
398 break;\r
399\r
ed838d0c 400 case USB_TARGET_INTERFACE:\r
401 DevReq.RequestType = USB_DEV_SET_FEATURE_REQ_TYPE_I;\r
7bc232b2
LG
402 break;\r
403\r
ed838d0c 404 case USB_TARGET_ENDPOINT:\r
405 DevReq.RequestType = USB_DEV_SET_FEATURE_REQ_TYPE_E;\r
7bc232b2
LG
406 break;\r
407 }\r
408 //\r
409 // Fill device request, see USB1.1 spec\r
410 //\r
ed838d0c 411 DevReq.Request = USB_REQ_SET_FEATURE;\r
7bc232b2
LG
412 DevReq.Value = Value;\r
413 DevReq.Index = Target;\r
414\r
415\r
416 return UsbIo->UsbControlTransfer (\r
417 UsbIo,\r
418 &DevReq,\r
419 EfiUsbNoData,\r
420 TIMEOUT_VALUE,\r
421 NULL,\r
422 0,\r
423 Status\r
424 );\r
425}\r
7bc232b2 426\r
7bc232b2 427\r
ed838d0c 428/**\r
d5954c61 429 Clear the specified feature of the specified device.\r
430\r
431 Submit a USB clear device feature request for the USB device specified by UsbIo,\r
432 Recipient, and Target to the value specified by Value. The status of the transfer\r
433 is returned in Status.\r
434 If UsbIo is NULL, then ASSERT().\r
435 If Status is NULL, then ASSERT().\r
436\r
437 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
438 @param Recipient The USB data recipient type (i.e. Device, Interface, Endpoint).\r
439 Type USB_TYPES_DEFINITION is defined in the MDE Package Industry Standard\r
440 include file Usb.h.\r
441 @param Value The value of the feature to be cleared.\r
442 @param Target The index of the device to be cleared.\r
443 @param Status A pointer to the status of the transfer.\r
444\r
445 @retval EFI_SUCCESS The request executed successfully.\r
446 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
447 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
448 The transfer status is returned in Status.\r
7bc232b2 449\r
ed838d0c 450**/\r
451EFI_STATUS\r
f1787349 452EFIAPI\r
ed838d0c 453UsbClearFeature (\r
454 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
d5954c61 455 IN USB_TYPES_DEFINITION Recipient,\r
ed838d0c 456 IN UINT16 Value,\r
457 IN UINT16 Target,\r
458 OUT UINT32 *Status\r
459 )\r
7bc232b2
LG
460{\r
461 EFI_USB_DEVICE_REQUEST DevReq;\r
462\r
d5954c61 463 ASSERT (UsbIo != NULL);\r
464 ASSERT (Status != NULL);\r
465\r
7bc232b2
LG
466\r
467 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
468\r
469 switch (Recipient) {\r
470\r
ed838d0c 471 case USB_TARGET_DEVICE:\r
472 DevReq.RequestType = USB_DEV_CLEAR_FEATURE_REQ_TYPE_D;\r
7bc232b2
LG
473 break;\r
474\r
ed838d0c 475 case USB_TARGET_INTERFACE:\r
476 DevReq.RequestType = USB_DEV_CLEAR_FEATURE_REQ_TYPE_I;\r
7bc232b2
LG
477 break;\r
478\r
ed838d0c 479 case USB_TARGET_ENDPOINT:\r
480 DevReq.RequestType = USB_DEV_CLEAR_FEATURE_REQ_TYPE_E;\r
7bc232b2
LG
481 break;\r
482 }\r
483 //\r
484 // Fill device request, see USB1.1 spec\r
485 //\r
ed838d0c 486 DevReq.Request = USB_REQ_CLEAR_FEATURE;\r
7bc232b2
LG
487 DevReq.Value = Value;\r
488 DevReq.Index = Target;\r
489\r
490\r
491 return UsbIo->UsbControlTransfer (\r
492 UsbIo,\r
493 &DevReq,\r
494 EfiUsbNoData,\r
495 TIMEOUT_VALUE,\r
496 NULL,\r
497 0,\r
498 Status\r
499 );\r
500}\r
7bc232b2 501\r
7bc232b2 502\r
ed838d0c 503/**\r
d5954c61 504 Get the status of the specified device.\r
505\r
506 Submit a USB device get status request for the USB device specified by UsbIo,\r
507 Recipient, and Target and place the result in the buffer specified by DeviceStatus.\r
508 The status of the transfer is returned in Status.\r
509 If UsbIo is NULL, then ASSERT().\r
510 If DeviceStatus is NULL, then ASSERT().\r
511 If Status is NULL, then ASSERT().\r
512\r
513 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
514 @param Recipient The USB data recipient type (i.e. Device, Interface, Endpoint).\r
515 Type USB_TYPES_DEFINITION is defined in the MDE Package Industry Standard\r
516 include file Usb.h.\r
517 @param Target The index of the device to be get the status of.\r
518 @param DeviceStatus A pointer to the device status to be retrieved.\r
519 @param Status A pointer to the status of the transfer.\r
520\r
521 @retval EFI_SUCCESS The request executed successfully.\r
522 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
523 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
524 The transfer status is returned in Status.\r
7bc232b2 525\r
ed838d0c 526**/\r
527EFI_STATUS\r
f1787349 528EFIAPI\r
ed838d0c 529UsbGetStatus (\r
530 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
d5954c61 531 IN USB_TYPES_DEFINITION Recipient,\r
ed838d0c 532 IN UINT16 Target,\r
d5954c61 533 OUT UINT16 *DeviceStatus,\r
ed838d0c 534 OUT UINT32 *Status\r
535 )\r
7bc232b2
LG
536{\r
537 EFI_USB_DEVICE_REQUEST DevReq;\r
538\r
d5954c61 539 ASSERT (UsbIo != NULL);\r
540 ASSERT (DeviceStatus != NULL);\r
541 ASSERT (Status != NULL);\r
7bc232b2
LG
542\r
543 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
544\r
545 switch (Recipient) {\r
546\r
ed838d0c 547 case USB_TARGET_DEVICE:\r
548 DevReq.RequestType = USB_DEV_GET_STATUS_REQ_TYPE_D;\r
7bc232b2
LG
549 break;\r
550\r
ed838d0c 551 case USB_TARGET_INTERFACE:\r
552 DevReq.RequestType = USB_DEV_GET_STATUS_REQ_TYPE_I;\r
7bc232b2
LG
553 break;\r
554\r
ed838d0c 555 case USB_TARGET_ENDPOINT:\r
556 DevReq.RequestType = USB_DEV_GET_STATUS_REQ_TYPE_E;\r
7bc232b2
LG
557 break;\r
558 }\r
559 //\r
560 // Fill device request, see USB1.1 spec\r
561 //\r
ed838d0c 562 DevReq.Request = USB_REQ_GET_STATUS;\r
7bc232b2
LG
563 DevReq.Value = 0;\r
564 DevReq.Index = Target;\r
565 DevReq.Length = 2;\r
566\r
567 return UsbIo->UsbControlTransfer (\r
568 UsbIo,\r
569 &DevReq,\r
570 EfiUsbDataIn,\r
571 TIMEOUT_VALUE,\r
d5954c61 572 DeviceStatus,\r
7bc232b2
LG
573 2,\r
574 Status\r
575 );\r
576}\r
7bc232b2 577\r
7bc232b2 578\r
ed838d0c 579/**\r
d5954c61 580 Clear halt feature of the specified usb endpoint.\r
581\r
582 Retrieve the USB endpoint descriptor specified by UsbIo and EndPoint.\r
583 If the USB endpoint descriptor can not be retrieved, then return EFI_NOT_FOUND.\r
584 If the endpoint descriptor is found, then clear the halt fature of this USB endpoint.\r
585 The status of the transfer is returned in Status.\r
586 If UsbIo is NULL, then ASSERT().\r
587 If Status is NULL, then ASSERT().\r
7bc232b2 588\r
d5954c61 589 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
590 @param Endpoint The endpoint address.\r
591 @param Status A pointer to the status of the transfer.\r
7bc232b2 592\r
d5954c61 593 @retval EFI_SUCCESS The request executed successfully.\r
594 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
595 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
596 The transfer status is returned in Status.\r
597 @retval EFI_NOT_FOUND The specified USB endpoint descriptor can not be found\r
7bc232b2 598\r
ed838d0c 599**/\r
7bc232b2 600EFI_STATUS\r
f1787349 601EFIAPI\r
7bc232b2
LG
602UsbClearEndpointHalt (\r
603 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
d5954c61 604 IN UINT8 Endpoint,\r
7bc232b2
LG
605 OUT UINT32 *Status\r
606 )\r
7bc232b2
LG
607{\r
608 EFI_STATUS Result;\r
609 EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor;\r
610 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;\r
611 UINT8 Index;\r
612\r
d5954c61 613 ASSERT (UsbIo != NULL);\r
614 ASSERT (Status != NULL);\r
8069d49e 615\r
7bc232b2
LG
616 ZeroMem (&EndpointDescriptor, sizeof (EFI_USB_ENDPOINT_DESCRIPTOR));\r
617 //\r
618 // First seach the endpoint descriptor for that endpoint addr\r
619 //\r
620 Result = UsbIo->UsbGetInterfaceDescriptor (\r
621 UsbIo,\r
622 &InterfaceDescriptor\r
623 );\r
624 if (EFI_ERROR (Result)) {\r
625 return Result;\r
626 }\r
627\r
628 for (Index = 0; Index < InterfaceDescriptor.NumEndpoints; Index++) {\r
629 Result = UsbIo->UsbGetEndpointDescriptor (\r
630 UsbIo,\r
631 Index,\r
632 &EndpointDescriptor\r
633 );\r
634 if (EFI_ERROR (Result)) {\r
635 continue;\r
636 }\r
637\r
d5954c61 638 if (EndpointDescriptor.EndpointAddress == Endpoint) {\r
7bc232b2
LG
639 break;\r
640 }\r
641 }\r
642\r
643 if (Index == InterfaceDescriptor.NumEndpoints) {\r
644 //\r
645 // No such endpoint\r
646 //\r
647 return EFI_NOT_FOUND;\r
648 }\r
649\r
ed838d0c 650 Result = UsbClearFeature (\r
7bc232b2 651 UsbIo,\r
ed838d0c 652 USB_TARGET_ENDPOINT,\r
d35be2a4 653 USB_FEATURE_ENDPOINT_HALT,\r
7bc232b2
LG
654 EndpointDescriptor.EndpointAddress,\r
655 Status\r
656 );\r
657\r
658 return Result;\r
659}\r