]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/UefiUsbLib/UsbDxeLib.c
Fix GCC build break.
[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 406 break;\r
563353b7 407\r
408 default:\r
409 break;\r
7bc232b2
LG
410 }\r
411 //\r
412 // Fill device request, see USB1.1 spec\r
413 //\r
ed838d0c 414 DevReq.Request = USB_REQ_SET_FEATURE;\r
7bc232b2
LG
415 DevReq.Value = Value;\r
416 DevReq.Index = Target;\r
417\r
418\r
419 return UsbIo->UsbControlTransfer (\r
420 UsbIo,\r
421 &DevReq,\r
422 EfiUsbNoData,\r
423 TIMEOUT_VALUE,\r
424 NULL,\r
425 0,\r
426 Status\r
427 );\r
428}\r
7bc232b2 429\r
7bc232b2 430\r
ed838d0c 431/**\r
d5954c61 432 Clear the specified feature of the specified device.\r
433\r
434 Submit a USB clear device feature request for the USB device specified by UsbIo,\r
435 Recipient, and Target to the value specified by Value. The status of the transfer\r
436 is returned in Status.\r
437 If UsbIo is NULL, then ASSERT().\r
438 If Status is NULL, then ASSERT().\r
439\r
440 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
441 @param Recipient The USB data recipient type (i.e. Device, Interface, Endpoint).\r
442 Type USB_TYPES_DEFINITION is defined in the MDE Package Industry Standard\r
443 include file Usb.h.\r
444 @param Value The value of the feature to be cleared.\r
445 @param Target The index of the device to be cleared.\r
446 @param Status A pointer to the status of the transfer.\r
447\r
448 @retval EFI_SUCCESS The request executed successfully.\r
449 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
450 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
451 The transfer status is returned in Status.\r
7bc232b2 452\r
ed838d0c 453**/\r
454EFI_STATUS\r
f1787349 455EFIAPI\r
ed838d0c 456UsbClearFeature (\r
457 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
d5954c61 458 IN USB_TYPES_DEFINITION Recipient,\r
ed838d0c 459 IN UINT16 Value,\r
460 IN UINT16 Target,\r
461 OUT UINT32 *Status\r
462 )\r
7bc232b2
LG
463{\r
464 EFI_USB_DEVICE_REQUEST DevReq;\r
465\r
d5954c61 466 ASSERT (UsbIo != NULL);\r
467 ASSERT (Status != NULL);\r
468\r
7bc232b2
LG
469\r
470 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
471\r
472 switch (Recipient) {\r
473\r
ed838d0c 474 case USB_TARGET_DEVICE:\r
475 DevReq.RequestType = USB_DEV_CLEAR_FEATURE_REQ_TYPE_D;\r
7bc232b2
LG
476 break;\r
477\r
ed838d0c 478 case USB_TARGET_INTERFACE:\r
479 DevReq.RequestType = USB_DEV_CLEAR_FEATURE_REQ_TYPE_I;\r
7bc232b2
LG
480 break;\r
481\r
ed838d0c 482 case USB_TARGET_ENDPOINT:\r
483 DevReq.RequestType = USB_DEV_CLEAR_FEATURE_REQ_TYPE_E;\r
7bc232b2 484 break;\r
563353b7 485\r
486 default:\r
487 break;\r
7bc232b2
LG
488 }\r
489 //\r
490 // Fill device request, see USB1.1 spec\r
491 //\r
ed838d0c 492 DevReq.Request = USB_REQ_CLEAR_FEATURE;\r
7bc232b2
LG
493 DevReq.Value = Value;\r
494 DevReq.Index = Target;\r
495\r
496\r
497 return UsbIo->UsbControlTransfer (\r
498 UsbIo,\r
499 &DevReq,\r
500 EfiUsbNoData,\r
501 TIMEOUT_VALUE,\r
502 NULL,\r
503 0,\r
504 Status\r
505 );\r
506}\r
7bc232b2 507\r
7bc232b2 508\r
ed838d0c 509/**\r
d5954c61 510 Get the status of the specified device.\r
511\r
512 Submit a USB device get status request for the USB device specified by UsbIo,\r
513 Recipient, and Target and place the result in the buffer specified by DeviceStatus.\r
514 The status of the transfer is returned in Status.\r
515 If UsbIo is NULL, then ASSERT().\r
516 If DeviceStatus is NULL, then ASSERT().\r
517 If Status is NULL, then ASSERT().\r
518\r
519 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
520 @param Recipient The USB data recipient type (i.e. Device, Interface, Endpoint).\r
521 Type USB_TYPES_DEFINITION is defined in the MDE Package Industry Standard\r
522 include file Usb.h.\r
523 @param Target The index of the device to be get the status of.\r
524 @param DeviceStatus A pointer to the device status to be retrieved.\r
525 @param Status A pointer to the status of the transfer.\r
526\r
527 @retval EFI_SUCCESS The request executed successfully.\r
528 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
529 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
530 The transfer status is returned in Status.\r
7bc232b2 531\r
ed838d0c 532**/\r
533EFI_STATUS\r
f1787349 534EFIAPI\r
ed838d0c 535UsbGetStatus (\r
536 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
d5954c61 537 IN USB_TYPES_DEFINITION Recipient,\r
ed838d0c 538 IN UINT16 Target,\r
d5954c61 539 OUT UINT16 *DeviceStatus,\r
ed838d0c 540 OUT UINT32 *Status\r
541 )\r
7bc232b2
LG
542{\r
543 EFI_USB_DEVICE_REQUEST DevReq;\r
544\r
d5954c61 545 ASSERT (UsbIo != NULL);\r
546 ASSERT (DeviceStatus != NULL);\r
547 ASSERT (Status != NULL);\r
7bc232b2
LG
548\r
549 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
550\r
551 switch (Recipient) {\r
552\r
ed838d0c 553 case USB_TARGET_DEVICE:\r
554 DevReq.RequestType = USB_DEV_GET_STATUS_REQ_TYPE_D;\r
7bc232b2
LG
555 break;\r
556\r
ed838d0c 557 case USB_TARGET_INTERFACE:\r
558 DevReq.RequestType = USB_DEV_GET_STATUS_REQ_TYPE_I;\r
7bc232b2
LG
559 break;\r
560\r
ed838d0c 561 case USB_TARGET_ENDPOINT:\r
562 DevReq.RequestType = USB_DEV_GET_STATUS_REQ_TYPE_E;\r
7bc232b2 563 break;\r
563353b7 564\r
565 default:\r
566 break;\r
7bc232b2
LG
567 }\r
568 //\r
569 // Fill device request, see USB1.1 spec\r
570 //\r
ed838d0c 571 DevReq.Request = USB_REQ_GET_STATUS;\r
7bc232b2
LG
572 DevReq.Value = 0;\r
573 DevReq.Index = Target;\r
574 DevReq.Length = 2;\r
575\r
576 return UsbIo->UsbControlTransfer (\r
577 UsbIo,\r
578 &DevReq,\r
579 EfiUsbDataIn,\r
580 TIMEOUT_VALUE,\r
d5954c61 581 DeviceStatus,\r
7bc232b2
LG
582 2,\r
583 Status\r
584 );\r
585}\r
7bc232b2 586\r
7bc232b2 587\r
ed838d0c 588/**\r
d5954c61 589 Clear halt feature of the specified usb endpoint.\r
590\r
591 Retrieve the USB endpoint descriptor specified by UsbIo and EndPoint.\r
592 If the USB endpoint descriptor can not be retrieved, then return EFI_NOT_FOUND.\r
593 If the endpoint descriptor is found, then clear the halt fature of this USB endpoint.\r
594 The status of the transfer is returned in Status.\r
595 If UsbIo is NULL, then ASSERT().\r
596 If Status is NULL, then ASSERT().\r
7bc232b2 597\r
d5954c61 598 @param UsbIo A pointer to the USB I/O Protocol instance for the specific USB target.\r
599 @param Endpoint The endpoint address.\r
600 @param Status A pointer to the status of the transfer.\r
7bc232b2 601\r
d5954c61 602 @retval EFI_SUCCESS The request executed successfully.\r
603 @retval EFI_TIMEOUT A timeout occurred executing the request.\r
604 @retval EFI_DEVICE_ERROR The request failed due to a device error.\r
605 The transfer status is returned in Status.\r
606 @retval EFI_NOT_FOUND The specified USB endpoint descriptor can not be found\r
7bc232b2 607\r
ed838d0c 608**/\r
7bc232b2 609EFI_STATUS\r
f1787349 610EFIAPI\r
7bc232b2
LG
611UsbClearEndpointHalt (\r
612 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
d5954c61 613 IN UINT8 Endpoint,\r
7bc232b2
LG
614 OUT UINT32 *Status\r
615 )\r
7bc232b2
LG
616{\r
617 EFI_STATUS Result;\r
618 EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor;\r
619 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;\r
620 UINT8 Index;\r
621\r
d5954c61 622 ASSERT (UsbIo != NULL);\r
623 ASSERT (Status != NULL);\r
8069d49e 624\r
7bc232b2
LG
625 ZeroMem (&EndpointDescriptor, sizeof (EFI_USB_ENDPOINT_DESCRIPTOR));\r
626 //\r
627 // First seach the endpoint descriptor for that endpoint addr\r
628 //\r
629 Result = UsbIo->UsbGetInterfaceDescriptor (\r
630 UsbIo,\r
631 &InterfaceDescriptor\r
632 );\r
633 if (EFI_ERROR (Result)) {\r
634 return Result;\r
635 }\r
636\r
637 for (Index = 0; Index < InterfaceDescriptor.NumEndpoints; Index++) {\r
638 Result = UsbIo->UsbGetEndpointDescriptor (\r
639 UsbIo,\r
640 Index,\r
641 &EndpointDescriptor\r
642 );\r
643 if (EFI_ERROR (Result)) {\r
644 continue;\r
645 }\r
646\r
d5954c61 647 if (EndpointDescriptor.EndpointAddress == Endpoint) {\r
7bc232b2
LG
648 break;\r
649 }\r
650 }\r
651\r
652 if (Index == InterfaceDescriptor.NumEndpoints) {\r
653 //\r
654 // No such endpoint\r
655 //\r
656 return EFI_NOT_FOUND;\r
657 }\r
658\r
ed838d0c 659 Result = UsbClearFeature (\r
7bc232b2 660 UsbIo,\r
ed838d0c 661 USB_TARGET_ENDPOINT,\r
d35be2a4 662 USB_FEATURE_ENDPOINT_HALT,\r
7bc232b2
LG
663 EndpointDescriptor.EndpointAddress,\r
664 Status\r
665 );\r
666\r
667 return Result;\r
668}\r