]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/UefiUsbLib/UsbDxeLib.c
MdePkg: Clean up source files
[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
19388d29 7 This program and the accompanying materials are\r
c311f86b 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
2fc59a00 11 http://opensource.org/licenses/bsd-license.php.\r
9095d37b 12\r
c311f86b 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
28d3e14f 40 buffer specified by DescriptorLength and Descriptor\r
d5954c61 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
65442978 76 PcdGet32 (PcdUsbTransferTimeoutValue),\r
7bc232b2
LG
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
65442978 136 PcdGet32 (PcdUsbTransferTimeoutValue),\r
7bc232b2
LG
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
2d8a3c13 170 OUT UINT16 *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 179\r
134c1f33 180 *AlternateSetting = 0;\r
181\r
7bc232b2
LG
182 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
183\r
184 DevReq.RequestType = USB_DEV_GET_INTERFACE_REQ_TYPE;\r
ed838d0c 185 DevReq.Request = USB_REQ_GET_INTERFACE;\r
d5954c61 186 DevReq.Index = Interface;\r
7bc232b2
LG
187 DevReq.Length = 1;\r
188\r
189 return UsbIo->UsbControlTransfer (\r
190 UsbIo,\r
191 &DevReq,\r
192 EfiUsbDataIn,\r
65442978 193 PcdGet32 (PcdUsbTransferTimeoutValue),\r
d5954c61 194 AlternateSetting,\r
c255449e 195 1,\r
7bc232b2
LG
196 Status\r
197 );\r
198}\r
7bc232b2 199\r
7bc232b2 200\r
ed838d0c 201/**\r
d5954c61 202 Set the interface setting of the specified USB device.\r
7bc232b2 203\r
d5954c61 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
7bc232b2 209\r
d5954c61 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
7bc232b2 219\r
ed838d0c 220**/\r
221EFI_STATUS\r
f1787349 222EFIAPI\r
ed838d0c 223UsbSetInterface (\r
224 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
d5954c61 225 IN UINT16 Interface,\r
226 IN UINT16 AlternateSetting,\r
ed838d0c 227 OUT UINT32 *Status\r
228 )\r
7bc232b2
LG
229{\r
230 EFI_USB_DEVICE_REQUEST DevReq;\r
231\r
d5954c61 232 ASSERT (UsbIo != NULL);\r
233 ASSERT (Status != NULL);\r
7bc232b2
LG
234\r
235 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
236\r
237 DevReq.RequestType = USB_DEV_SET_INTERFACE_REQ_TYPE;\r
ed838d0c 238 DevReq.Request = USB_REQ_SET_INTERFACE;\r
d5954c61 239 DevReq.Value = AlternateSetting;\r
240 DevReq.Index = Interface;\r
7bc232b2
LG
241\r
242 return UsbIo->UsbControlTransfer (\r
243 UsbIo,\r
244 &DevReq,\r
245 EfiUsbNoData,\r
65442978 246 PcdGet32 (PcdUsbTransferTimeoutValue),\r
7bc232b2
LG
247 NULL,\r
248 0,\r
249 Status\r
250 );\r
251}\r
7bc232b2 252\r
7bc232b2 253\r
ed838d0c 254/**\r
d5954c61 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
7bc232b2 263\r
d5954c61 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
7bc232b2 267\r
d5954c61 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
7bc232b2 272\r
ed838d0c 273**/\r
274EFI_STATUS\r
f1787349 275EFIAPI\r
ed838d0c 276UsbGetConfiguration (\r
277 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
2d8a3c13 278 OUT UINT16 *ConfigurationValue,\r
ed838d0c 279 OUT UINT32 *Status\r
280 )\r
7bc232b2
LG
281{\r
282 EFI_USB_DEVICE_REQUEST DevReq;\r
283\r
d5954c61 284 ASSERT (UsbIo != NULL);\r
285 ASSERT (ConfigurationValue != NULL);\r
286 ASSERT (Status != NULL);\r
7bc232b2 287\r
134c1f33 288 *ConfigurationValue = 0;\r
289\r
7bc232b2
LG
290 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
291\r
292 DevReq.RequestType = USB_DEV_GET_CONFIGURATION_REQ_TYPE;\r
ed838d0c 293 DevReq.Request = USB_REQ_GET_CONFIG;\r
7bc232b2
LG
294 DevReq.Length = 1;\r
295\r
296 return UsbIo->UsbControlTransfer (\r
297 UsbIo,\r
298 &DevReq,\r
299 EfiUsbDataIn,\r
65442978 300 PcdGet32 (PcdUsbTransferTimeoutValue),\r
d5954c61 301 ConfigurationValue,\r
c255449e 302 1,\r
7bc232b2
LG
303 Status\r
304 );\r
305}\r
7bc232b2 306\r
7bc232b2 307\r
ed838d0c 308/**\r
d5954c61 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
7bc232b2 316\r
d5954c61 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
7bc232b2 320\r
d5954c61 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
7bc232b2 325\r
ed838d0c 326**/\r
327EFI_STATUS\r
f1787349 328EFIAPI\r
ed838d0c 329UsbSetConfiguration (\r
330 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
d5954c61 331 IN UINT16 ConfigurationValue,\r
ed838d0c 332 OUT UINT32 *Status\r
333 )\r
7bc232b2
LG
334{\r
335 EFI_USB_DEVICE_REQUEST DevReq;\r
336\r
d5954c61 337 ASSERT (UsbIo != NULL);\r
338 ASSERT (Status != NULL);\r
7bc232b2
LG
339\r
340 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
341\r
342 DevReq.RequestType = USB_DEV_SET_CONFIGURATION_REQ_TYPE;\r
ed838d0c 343 DevReq.Request = USB_REQ_SET_CONFIG;\r
d5954c61 344 DevReq.Value = ConfigurationValue;\r
ed838d0c 345\r
7bc232b2
LG
346 return UsbIo->UsbControlTransfer (\r
347 UsbIo,\r
348 &DevReq,\r
349 EfiUsbNoData,\r
65442978 350 PcdGet32 (PcdUsbTransferTimeoutValue),\r
7bc232b2
LG
351 NULL,\r
352 0,\r
353 Status\r
354 );\r
355}\r
7bc232b2 356\r
7bc232b2 357\r
ed838d0c 358/**\r
d5954c61 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
7bc232b2 379\r
ed838d0c 380**/\r
381EFI_STATUS\r
f1787349 382EFIAPI\r
ed838d0c 383UsbSetFeature (\r
384 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
d5954c61 385 IN USB_TYPES_DEFINITION Recipient,\r
ed838d0c 386 IN UINT16 Value,\r
387 IN UINT16 Target,\r
388 OUT UINT32 *Status\r
389 )\r
7bc232b2
LG
390{\r
391 EFI_USB_DEVICE_REQUEST DevReq;\r
392\r
d5954c61 393 ASSERT (UsbIo != NULL);\r
394 ASSERT (Status != NULL);\r
7bc232b2
LG
395\r
396 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
397\r
398 switch (Recipient) {\r
399\r
ed838d0c 400 case USB_TARGET_DEVICE:\r
401 DevReq.RequestType = USB_DEV_SET_FEATURE_REQ_TYPE_D;\r
7bc232b2
LG
402 break;\r
403\r
ed838d0c 404 case USB_TARGET_INTERFACE:\r
405 DevReq.RequestType = USB_DEV_SET_FEATURE_REQ_TYPE_I;\r
7bc232b2
LG
406 break;\r
407\r
ed838d0c 408 case USB_TARGET_ENDPOINT:\r
409 DevReq.RequestType = USB_DEV_SET_FEATURE_REQ_TYPE_E;\r
7bc232b2 410 break;\r
563353b7 411\r
412 default:\r
413 break;\r
7bc232b2
LG
414 }\r
415 //\r
416 // Fill device request, see USB1.1 spec\r
417 //\r
ed838d0c 418 DevReq.Request = USB_REQ_SET_FEATURE;\r
7bc232b2
LG
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
65442978 427 PcdGet32 (PcdUsbTransferTimeoutValue),\r
7bc232b2
LG
428 NULL,\r
429 0,\r
430 Status\r
431 );\r
432}\r
7bc232b2 433\r
7bc232b2 434\r
ed838d0c 435/**\r
d5954c61 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
7bc232b2 456\r
ed838d0c 457**/\r
458EFI_STATUS\r
f1787349 459EFIAPI\r
ed838d0c 460UsbClearFeature (\r
461 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
d5954c61 462 IN USB_TYPES_DEFINITION Recipient,\r
ed838d0c 463 IN UINT16 Value,\r
464 IN UINT16 Target,\r
465 OUT UINT32 *Status\r
466 )\r
7bc232b2
LG
467{\r
468 EFI_USB_DEVICE_REQUEST DevReq;\r
469\r
d5954c61 470 ASSERT (UsbIo != NULL);\r
471 ASSERT (Status != NULL);\r
472\r
7bc232b2
LG
473\r
474 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
475\r
476 switch (Recipient) {\r
477\r
ed838d0c 478 case USB_TARGET_DEVICE:\r
479 DevReq.RequestType = USB_DEV_CLEAR_FEATURE_REQ_TYPE_D;\r
7bc232b2
LG
480 break;\r
481\r
ed838d0c 482 case USB_TARGET_INTERFACE:\r
483 DevReq.RequestType = USB_DEV_CLEAR_FEATURE_REQ_TYPE_I;\r
7bc232b2
LG
484 break;\r
485\r
ed838d0c 486 case USB_TARGET_ENDPOINT:\r
487 DevReq.RequestType = USB_DEV_CLEAR_FEATURE_REQ_TYPE_E;\r
7bc232b2 488 break;\r
563353b7 489\r
490 default:\r
491 break;\r
7bc232b2
LG
492 }\r
493 //\r
494 // Fill device request, see USB1.1 spec\r
495 //\r
ed838d0c 496 DevReq.Request = USB_REQ_CLEAR_FEATURE;\r
7bc232b2
LG
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
65442978 505 PcdGet32 (PcdUsbTransferTimeoutValue),\r
7bc232b2
LG
506 NULL,\r
507 0,\r
508 Status\r
509 );\r
510}\r
7bc232b2 511\r
7bc232b2 512\r
ed838d0c 513/**\r
d5954c61 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
7bc232b2 535\r
ed838d0c 536**/\r
537EFI_STATUS\r
f1787349 538EFIAPI\r
ed838d0c 539UsbGetStatus (\r
540 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
d5954c61 541 IN USB_TYPES_DEFINITION Recipient,\r
ed838d0c 542 IN UINT16 Target,\r
d5954c61 543 OUT UINT16 *DeviceStatus,\r
ed838d0c 544 OUT UINT32 *Status\r
545 )\r
7bc232b2
LG
546{\r
547 EFI_USB_DEVICE_REQUEST DevReq;\r
548\r
d5954c61 549 ASSERT (UsbIo != NULL);\r
550 ASSERT (DeviceStatus != NULL);\r
551 ASSERT (Status != NULL);\r
7bc232b2
LG
552\r
553 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
554\r
555 switch (Recipient) {\r
556\r
ed838d0c 557 case USB_TARGET_DEVICE:\r
558 DevReq.RequestType = USB_DEV_GET_STATUS_REQ_TYPE_D;\r
7bc232b2
LG
559 break;\r
560\r
ed838d0c 561 case USB_TARGET_INTERFACE:\r
562 DevReq.RequestType = USB_DEV_GET_STATUS_REQ_TYPE_I;\r
7bc232b2
LG
563 break;\r
564\r
ed838d0c 565 case USB_TARGET_ENDPOINT:\r
566 DevReq.RequestType = USB_DEV_GET_STATUS_REQ_TYPE_E;\r
7bc232b2 567 break;\r
563353b7 568\r
569 default:\r
570 break;\r
7bc232b2
LG
571 }\r
572 //\r
573 // Fill device request, see USB1.1 spec\r
574 //\r
ed838d0c 575 DevReq.Request = USB_REQ_GET_STATUS;\r
7bc232b2
LG
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
65442978 584 PcdGet32 (PcdUsbTransferTimeoutValue),\r
d5954c61 585 DeviceStatus,\r
7bc232b2
LG
586 2,\r
587 Status\r
588 );\r
589}\r
7bc232b2 590\r
7bc232b2 591\r
ed838d0c 592/**\r
d5954c61 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
070a76b1 597 If the endpoint descriptor is found, then clear the halt feature of this USB endpoint.\r
d5954c61 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
7bc232b2 601\r
d5954c61 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
7bc232b2 605\r
d5954c61 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
7bc232b2 611\r
ed838d0c 612**/\r
7bc232b2 613EFI_STATUS\r
f1787349 614EFIAPI\r
7bc232b2
LG
615UsbClearEndpointHalt (\r
616 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
d5954c61 617 IN UINT8 Endpoint,\r
7bc232b2
LG
618 OUT UINT32 *Status\r
619 )\r
7bc232b2
LG
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
d5954c61 626 ASSERT (UsbIo != NULL);\r
627 ASSERT (Status != NULL);\r
8069d49e 628\r
7bc232b2
LG
629 ZeroMem (&EndpointDescriptor, sizeof (EFI_USB_ENDPOINT_DESCRIPTOR));\r
630 //\r
3868d06d 631 // First search the endpoint descriptor for that endpoint addr\r
7bc232b2
LG
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
d5954c61 651 if (EndpointDescriptor.EndpointAddress == Endpoint) {\r
7bc232b2
LG
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
ed838d0c 663 Result = UsbClearFeature (\r
7bc232b2 664 UsbIo,\r
ed838d0c 665 USB_TARGET_ENDPOINT,\r
d35be2a4 666 USB_FEATURE_ENDPOINT_HALT,\r
7bc232b2
LG
667 EndpointDescriptor.EndpointAddress,\r
668 Status\r
669 );\r
670\r
671 return Result;\r
672}\r