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