]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdePkg/Library/UefiUsbLib/UsbDxeLib.c
MdePkg/BaseLib: Add AsciiStrToGuid/HexToBytes/ToIpv[4/6]Address
[mirror_edk2.git] / MdePkg / Library / UefiUsbLib / UsbDxeLib.c
... / ...
CommitLineData
1/** @file\r
2\r
3 The library provides the USB Standard Device Requests defined \r
4 in Usb specification 9.4 section.\r
5 \r
6 Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>\r
7 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
15\r
16**/\r
17\r
18#include "UefiUsbLibInternal.h"\r
19\r
20\r
21/**\r
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 specified 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
45\r
46**/\r
47EFI_STATUS\r
48EFIAPI\r
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
57{\r
58 EFI_USB_DEVICE_REQUEST DevReq;\r
59\r
60 ASSERT (UsbIo != NULL);\r
61 ASSERT (Descriptor != NULL);\r
62 ASSERT (Status != NULL);\r
63\r
64 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
65\r
66 DevReq.RequestType = USB_DEV_GET_DESCRIPTOR_REQ_TYPE;\r
67 DevReq.Request = USB_REQ_GET_DESCRIPTOR;\r
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 PcdGet32 (PcdUsbTransferTimeoutValue),\r
77 Descriptor,\r
78 DescriptorLength,\r
79 Status\r
80 );\r
81}\r
82\r
83\r
84/**\r
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
105\r
106**/\r
107EFI_STATUS\r
108EFIAPI\r
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
117{\r
118 EFI_USB_DEVICE_REQUEST DevReq;\r
119\r
120 ASSERT (UsbIo != NULL);\r
121 ASSERT (Descriptor != NULL);\r
122 ASSERT (Status != NULL);\r
123\r
124 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
125\r
126 DevReq.RequestType = USB_DEV_SET_DESCRIPTOR_REQ_TYPE;\r
127 DevReq.Request = USB_REQ_SET_DESCRIPTOR;\r
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 PcdGet32 (PcdUsbTransferTimeoutValue),\r
137 Descriptor,\r
138 DescriptorLength,\r
139 Status\r
140 );\r
141}\r
142\r
143\r
144/**\r
145 Get the interface setting of the specified USB device.\r
146\r
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
153\r
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
163\r
164**/\r
165EFI_STATUS\r
166EFIAPI\r
167UsbGetInterface (\r
168 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
169 IN UINT16 Interface,\r
170 OUT UINT16 *AlternateSetting,\r
171 OUT UINT32 *Status\r
172 )\r
173{\r
174 EFI_USB_DEVICE_REQUEST DevReq;\r
175\r
176 ASSERT (UsbIo != NULL);\r
177 ASSERT (AlternateSetting != NULL);\r
178 ASSERT (Status != NULL);\r
179\r
180 *AlternateSetting = 0;\r
181\r
182 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
183\r
184 DevReq.RequestType = USB_DEV_GET_INTERFACE_REQ_TYPE;\r
185 DevReq.Request = USB_REQ_GET_INTERFACE;\r
186 DevReq.Index = Interface;\r
187 DevReq.Length = 1;\r
188\r
189 return UsbIo->UsbControlTransfer (\r
190 UsbIo,\r
191 &DevReq,\r
192 EfiUsbDataIn,\r
193 PcdGet32 (PcdUsbTransferTimeoutValue),\r
194 AlternateSetting,\r
195 1,\r
196 Status\r
197 );\r
198}\r
199\r
200\r
201/**\r
202 Set the interface setting of the specified USB device.\r
203\r
204 Submit a USB set interface request for the USB device specified by UsbIo, and\r
205 Interface, and set the alternate setting to the value specified by AlternateSetting.\r
206 The status of the transfer is returned in Status.\r
207 If UsbIo is NULL, then ASSERT().\r
208 If Status is NULL, then ASSERT().\r
209\r
210 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
211 @param Interface The interface index value.\r
212 @param AlternateSetting The alternate setting to be set.\r
213 @param Status A pointer to the status of the transfer.\r
214\r
215 @retval EFI_SUCCESS The request executed successfully.\r
216 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
217 @retval EFI_SUCCESS The request failed due to a device error.\r
218 The transfer status is returned in Status.\r
219\r
220**/\r
221EFI_STATUS\r
222EFIAPI\r
223UsbSetInterface (\r
224 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
225 IN UINT16 Interface,\r
226 IN UINT16 AlternateSetting,\r
227 OUT UINT32 *Status\r
228 )\r
229{\r
230 EFI_USB_DEVICE_REQUEST DevReq;\r
231\r
232 ASSERT (UsbIo != NULL);\r
233 ASSERT (Status != NULL);\r
234\r
235 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
236\r
237 DevReq.RequestType = USB_DEV_SET_INTERFACE_REQ_TYPE;\r
238 DevReq.Request = USB_REQ_SET_INTERFACE;\r
239 DevReq.Value = AlternateSetting;\r
240 DevReq.Index = Interface;\r
241\r
242 return UsbIo->UsbControlTransfer (\r
243 UsbIo,\r
244 &DevReq,\r
245 EfiUsbNoData,\r
246 PcdGet32 (PcdUsbTransferTimeoutValue),\r
247 NULL,\r
248 0,\r
249 Status\r
250 );\r
251}\r
252\r
253\r
254/**\r
255 Get the device configuration.\r
256\r
257 Submit a USB get configuration request for the USB device specified by UsbIo\r
258 and place the result in the buffer specified by ConfigurationValue. The status\r
259 of the transfer is returned in Status.\r
260 If UsbIo is NULL, then ASSERT().\r
261 If ConfigurationValue is NULL, then ASSERT().\r
262 If Status is NULL, then ASSERT().\r
263\r
264 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
265 @param ConfigurationValue A pointer to the device configuration to be retrieved.\r
266 @param Status A pointer to the status of the transfer.\r
267\r
268 @retval EFI_SUCCESS The request executed successfully.\r
269 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
270 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
271 The transfer status is returned in Status.\r
272\r
273**/\r
274EFI_STATUS\r
275EFIAPI\r
276UsbGetConfiguration (\r
277 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
278 OUT UINT16 *ConfigurationValue,\r
279 OUT UINT32 *Status\r
280 )\r
281{\r
282 EFI_USB_DEVICE_REQUEST DevReq;\r
283\r
284 ASSERT (UsbIo != NULL);\r
285 ASSERT (ConfigurationValue != NULL);\r
286 ASSERT (Status != NULL);\r
287\r
288 *ConfigurationValue = 0;\r
289\r
290 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
291\r
292 DevReq.RequestType = USB_DEV_GET_CONFIGURATION_REQ_TYPE;\r
293 DevReq.Request = USB_REQ_GET_CONFIG;\r
294 DevReq.Length = 1;\r
295\r
296 return UsbIo->UsbControlTransfer (\r
297 UsbIo,\r
298 &DevReq,\r
299 EfiUsbDataIn,\r
300 PcdGet32 (PcdUsbTransferTimeoutValue),\r
301 ConfigurationValue,\r
302 1,\r
303 Status\r
304 );\r
305}\r
306\r
307\r
308/**\r
309 Set the device configuration.\r
310\r
311 Submit a USB set configuration request for the USB device specified by UsbIo\r
312 and set the device configuration to the value specified by ConfigurationValue.\r
313 The status of the transfer is returned in Status.\r
314 If UsbIo is NULL, then ASSERT().\r
315 If Status is NULL, then ASSERT().\r
316\r
317 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
318 @param ConfigurationValue The device configuration value to be set.\r
319 @param Status A pointer to the status of the transfer.\r
320\r
321 @retval EFI_SUCCESS The request executed successfully.\r
322 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
323 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
324 The transfer status is returned in Status.\r
325\r
326**/\r
327EFI_STATUS\r
328EFIAPI\r
329UsbSetConfiguration (\r
330 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
331 IN UINT16 ConfigurationValue,\r
332 OUT UINT32 *Status\r
333 )\r
334{\r
335 EFI_USB_DEVICE_REQUEST DevReq;\r
336\r
337 ASSERT (UsbIo != NULL);\r
338 ASSERT (Status != NULL);\r
339\r
340 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
341\r
342 DevReq.RequestType = USB_DEV_SET_CONFIGURATION_REQ_TYPE;\r
343 DevReq.Request = USB_REQ_SET_CONFIG;\r
344 DevReq.Value = ConfigurationValue;\r
345\r
346 return UsbIo->UsbControlTransfer (\r
347 UsbIo,\r
348 &DevReq,\r
349 EfiUsbNoData,\r
350 PcdGet32 (PcdUsbTransferTimeoutValue),\r
351 NULL,\r
352 0,\r
353 Status\r
354 );\r
355}\r
356\r
357\r
358/**\r
359 Set the specified feature of the specified device.\r
360\r
361 Submit a USB set device feature request for the USB device specified by UsbIo,\r
362 Recipient, and Target to the value specified by Value. The status of the\r
363 transfer is returned in Status.\r
364 If UsbIo is NULL, then ASSERT().\r
365 If Status is NULL, then ASSERT().\r
366\r
367 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
368 @param Recipient The USB data recipient type (i.e. Device, Interface, Endpoint).\r
369 Type USB_TYPES_DEFINITION is defined in the MDE Package Industry\r
370 Standard include file Usb.h.\r
371 @param Value The value of the feature to be set.\r
372 @param Target The index of the device to be set.\r
373 @param Status A pointer to the status of the transfer.\r
374\r
375 @retval EFI_SUCCESS The request executed successfully.\r
376 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
377 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
378 The transfer status is returned in Status.\r
379\r
380**/\r
381EFI_STATUS\r
382EFIAPI\r
383UsbSetFeature (\r
384 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
385 IN USB_TYPES_DEFINITION Recipient,\r
386 IN UINT16 Value,\r
387 IN UINT16 Target,\r
388 OUT UINT32 *Status\r
389 )\r
390{\r
391 EFI_USB_DEVICE_REQUEST DevReq;\r
392\r
393 ASSERT (UsbIo != NULL);\r
394 ASSERT (Status != NULL);\r
395\r
396 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
397\r
398 switch (Recipient) {\r
399\r
400 case USB_TARGET_DEVICE:\r
401 DevReq.RequestType = USB_DEV_SET_FEATURE_REQ_TYPE_D;\r
402 break;\r
403\r
404 case USB_TARGET_INTERFACE:\r
405 DevReq.RequestType = USB_DEV_SET_FEATURE_REQ_TYPE_I;\r
406 break;\r
407\r
408 case USB_TARGET_ENDPOINT:\r
409 DevReq.RequestType = USB_DEV_SET_FEATURE_REQ_TYPE_E;\r
410 break;\r
411\r
412 default:\r
413 break;\r
414 }\r
415 //\r
416 // Fill device request, see USB1.1 spec\r
417 //\r
418 DevReq.Request = USB_REQ_SET_FEATURE;\r
419 DevReq.Value = Value;\r
420 DevReq.Index = Target;\r
421\r
422\r
423 return UsbIo->UsbControlTransfer (\r
424 UsbIo,\r
425 &DevReq,\r
426 EfiUsbNoData,\r
427 PcdGet32 (PcdUsbTransferTimeoutValue),\r
428 NULL,\r
429 0,\r
430 Status\r
431 );\r
432}\r
433\r
434\r
435/**\r
436 Clear the specified feature of the specified device.\r
437\r
438 Submit a USB clear device feature request for the USB device specified by UsbIo,\r
439 Recipient, and Target to the value specified by Value. The status of the transfer\r
440 is returned in Status.\r
441 If UsbIo is NULL, then ASSERT().\r
442 If Status is NULL, then ASSERT().\r
443\r
444 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
445 @param Recipient The USB data recipient type (i.e. Device, Interface, Endpoint).\r
446 Type USB_TYPES_DEFINITION is defined in the MDE Package Industry Standard\r
447 include file Usb.h.\r
448 @param Value The value of the feature to be cleared.\r
449 @param Target The index of the device to be cleared.\r
450 @param Status A pointer to the status of the transfer.\r
451\r
452 @retval EFI_SUCCESS The request executed successfully.\r
453 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
454 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
455 The transfer status is returned in Status.\r
456\r
457**/\r
458EFI_STATUS\r
459EFIAPI\r
460UsbClearFeature (\r
461 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
462 IN USB_TYPES_DEFINITION Recipient,\r
463 IN UINT16 Value,\r
464 IN UINT16 Target,\r
465 OUT UINT32 *Status\r
466 )\r
467{\r
468 EFI_USB_DEVICE_REQUEST DevReq;\r
469\r
470 ASSERT (UsbIo != NULL);\r
471 ASSERT (Status != NULL);\r
472\r
473\r
474 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
475\r
476 switch (Recipient) {\r
477\r
478 case USB_TARGET_DEVICE:\r
479 DevReq.RequestType = USB_DEV_CLEAR_FEATURE_REQ_TYPE_D;\r
480 break;\r
481\r
482 case USB_TARGET_INTERFACE:\r
483 DevReq.RequestType = USB_DEV_CLEAR_FEATURE_REQ_TYPE_I;\r
484 break;\r
485\r
486 case USB_TARGET_ENDPOINT:\r
487 DevReq.RequestType = USB_DEV_CLEAR_FEATURE_REQ_TYPE_E;\r
488 break;\r
489\r
490 default:\r
491 break;\r
492 }\r
493 //\r
494 // Fill device request, see USB1.1 spec\r
495 //\r
496 DevReq.Request = USB_REQ_CLEAR_FEATURE;\r
497 DevReq.Value = Value;\r
498 DevReq.Index = Target;\r
499\r
500\r
501 return UsbIo->UsbControlTransfer (\r
502 UsbIo,\r
503 &DevReq,\r
504 EfiUsbNoData,\r
505 PcdGet32 (PcdUsbTransferTimeoutValue),\r
506 NULL,\r
507 0,\r
508 Status\r
509 );\r
510}\r
511\r
512\r
513/**\r
514 Get the status of the specified device.\r
515\r
516 Submit a USB device get status request for the USB device specified by UsbIo,\r
517 Recipient, and Target and place the result in the buffer specified by DeviceStatus.\r
518 The status of the transfer is returned in Status.\r
519 If UsbIo is NULL, then ASSERT().\r
520 If DeviceStatus is NULL, then ASSERT().\r
521 If Status is NULL, then ASSERT().\r
522\r
523 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
524 @param Recipient The USB data recipient type (i.e. Device, Interface, Endpoint).\r
525 Type USB_TYPES_DEFINITION is defined in the MDE Package Industry Standard\r
526 include file Usb.h.\r
527 @param Target The index of the device to be get the status of.\r
528 @param DeviceStatus A pointer to the device status to be retrieved.\r
529 @param Status A pointer to the status of the transfer.\r
530\r
531 @retval EFI_SUCCESS The request executed successfully.\r
532 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
533 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
534 The transfer status is returned in Status.\r
535\r
536**/\r
537EFI_STATUS\r
538EFIAPI\r
539UsbGetStatus (\r
540 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
541 IN USB_TYPES_DEFINITION Recipient,\r
542 IN UINT16 Target,\r
543 OUT UINT16 *DeviceStatus,\r
544 OUT UINT32 *Status\r
545 )\r
546{\r
547 EFI_USB_DEVICE_REQUEST DevReq;\r
548\r
549 ASSERT (UsbIo != NULL);\r
550 ASSERT (DeviceStatus != NULL);\r
551 ASSERT (Status != NULL);\r
552\r
553 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
554\r
555 switch (Recipient) {\r
556\r
557 case USB_TARGET_DEVICE:\r
558 DevReq.RequestType = USB_DEV_GET_STATUS_REQ_TYPE_D;\r
559 break;\r
560\r
561 case USB_TARGET_INTERFACE:\r
562 DevReq.RequestType = USB_DEV_GET_STATUS_REQ_TYPE_I;\r
563 break;\r
564\r
565 case USB_TARGET_ENDPOINT:\r
566 DevReq.RequestType = USB_DEV_GET_STATUS_REQ_TYPE_E;\r
567 break;\r
568\r
569 default:\r
570 break;\r
571 }\r
572 //\r
573 // Fill device request, see USB1.1 spec\r
574 //\r
575 DevReq.Request = USB_REQ_GET_STATUS;\r
576 DevReq.Value = 0;\r
577 DevReq.Index = Target;\r
578 DevReq.Length = 2;\r
579\r
580 return UsbIo->UsbControlTransfer (\r
581 UsbIo,\r
582 &DevReq,\r
583 EfiUsbDataIn,\r
584 PcdGet32 (PcdUsbTransferTimeoutValue),\r
585 DeviceStatus,\r
586 2,\r
587 Status\r
588 );\r
589}\r
590\r
591\r
592/**\r
593 Clear halt feature of the specified usb endpoint.\r
594\r
595 Retrieve the USB endpoint descriptor specified by UsbIo and EndPoint.\r
596 If the USB endpoint descriptor can not be retrieved, then return EFI_NOT_FOUND.\r
597 If the endpoint descriptor is found, then clear the halt feature of this USB endpoint.\r
598 The status of the transfer is returned in Status.\r
599 If UsbIo is NULL, then ASSERT().\r
600 If Status is NULL, then ASSERT().\r
601\r
602 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
603 @param Endpoint The endpoint address.\r
604 @param Status A pointer to the status of the transfer.\r
605\r
606 @retval EFI_SUCCESS The request executed successfully.\r
607 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
608 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
609 The transfer status is returned in Status.\r
610 @retval EFI_NOT_FOUND The specified USB endpoint descriptor can not be found\r
611\r
612**/\r
613EFI_STATUS\r
614EFIAPI\r
615UsbClearEndpointHalt (\r
616 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
617 IN UINT8 Endpoint,\r
618 OUT UINT32 *Status\r
619 )\r
620{\r
621 EFI_STATUS Result;\r
622 EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor;\r
623 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;\r
624 UINT8 Index;\r
625\r
626 ASSERT (UsbIo != NULL);\r
627 ASSERT (Status != NULL);\r
628\r
629 ZeroMem (&EndpointDescriptor, sizeof (EFI_USB_ENDPOINT_DESCRIPTOR));\r
630 //\r
631 // First search the endpoint descriptor for that endpoint addr\r
632 //\r
633 Result = UsbIo->UsbGetInterfaceDescriptor (\r
634 UsbIo,\r
635 &InterfaceDescriptor\r
636 );\r
637 if (EFI_ERROR (Result)) {\r
638 return Result;\r
639 }\r
640\r
641 for (Index = 0; Index < InterfaceDescriptor.NumEndpoints; Index++) {\r
642 Result = UsbIo->UsbGetEndpointDescriptor (\r
643 UsbIo,\r
644 Index,\r
645 &EndpointDescriptor\r
646 );\r
647 if (EFI_ERROR (Result)) {\r
648 continue;\r
649 }\r
650\r
651 if (EndpointDescriptor.EndpointAddress == Endpoint) {\r
652 break;\r
653 }\r
654 }\r
655\r
656 if (Index == InterfaceDescriptor.NumEndpoints) {\r
657 //\r
658 // No such endpoint\r
659 //\r
660 return EFI_NOT_FOUND;\r
661 }\r
662\r
663 Result = UsbClearFeature (\r
664 UsbIo,\r
665 USB_TARGET_ENDPOINT,\r
666 USB_FEATURE_ENDPOINT_HALT,\r
667 EndpointDescriptor.EndpointAddress,\r
668 Status\r
669 );\r
670\r
671 return Result;\r
672}\r