]>
Commit | Line | Data |
---|---|---|
7bc232b2 LG |
1 | /*++\r |
2 | \r | |
3 | Copyright (c) 2006, Intel Corporation \r | |
4 | All rights reserved. This program and the accompanying materials \r | |
5 | are licensed and made available under the terms and conditions of the BSD License \r | |
6 | which accompanies this distribution. The full text of the license may be found at \r | |
7 | http://opensource.org/licenses/bsd-license.php \r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
11 | \r | |
12 | Module Name:\r | |
13 | \r | |
14 | UsbDxeLib.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | Common Dxe Libarary for USB\r | |
19 | \r | |
20 | Revision History\r | |
21 | \r | |
22 | --*/\r | |
23 | \r | |
24 | //\r | |
25 | // Include common header file for this module.\r | |
26 | //\r | |
27 | #include "CommonHeader.h"\r | |
28 | \r | |
29 | //\r | |
30 | // Get Device Descriptor\r | |
31 | //\r | |
32 | EFI_STATUS\r | |
33 | UsbGetDescriptor (\r | |
34 | IN EFI_USB_IO_PROTOCOL *UsbIo,\r | |
35 | IN UINT16 Value,\r | |
36 | IN UINT16 Index,\r | |
37 | IN UINT16 DescriptorLength,\r | |
38 | OUT VOID *Descriptor,\r | |
39 | OUT UINT32 *Status\r | |
40 | )\r | |
41 | /*++\r | |
42 | \r | |
43 | Routine Description:\r | |
44 | \r | |
45 | Usb Get Descriptor\r | |
46 | \r | |
47 | Arguments:\r | |
48 | \r | |
49 | UsbIo - EFI_USB_IO_PROTOCOL\r | |
50 | Value - Device Request Value\r | |
51 | Index - Device Request Index \r | |
52 | DescriptorLength - Descriptor Length\r | |
53 | Descriptor - Descriptor buffer to contain result\r | |
54 | Status - Transfer Status\r | |
55 | Returns:\r | |
56 | EFI_INVALID_PARAMETER - Parameter is error\r | |
57 | EFI_SUCCESS - Success\r | |
58 | EFI_TIMEOUT - Device has no response \r | |
59 | \r | |
60 | --*/\r | |
61 | {\r | |
62 | EFI_USB_DEVICE_REQUEST DevReq;\r | |
63 | \r | |
64 | if (UsbIo == NULL) {\r | |
65 | return EFI_INVALID_PARAMETER;\r | |
66 | }\r | |
67 | \r | |
68 | ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r | |
69 | \r | |
70 | DevReq.RequestType = USB_DEV_GET_DESCRIPTOR_REQ_TYPE;\r | |
71 | DevReq.Request = USB_DEV_GET_DESCRIPTOR;\r | |
72 | DevReq.Value = Value;\r | |
73 | DevReq.Index = Index;\r | |
74 | DevReq.Length = DescriptorLength;\r | |
75 | \r | |
76 | return UsbIo->UsbControlTransfer (\r | |
77 | UsbIo,\r | |
78 | &DevReq,\r | |
79 | EfiUsbDataIn,\r | |
80 | TIMEOUT_VALUE,\r | |
81 | Descriptor,\r | |
82 | DescriptorLength,\r | |
83 | Status\r | |
84 | );\r | |
85 | }\r | |
86 | //\r | |
87 | // Set Device Descriptor\r | |
88 | //\r | |
89 | EFI_STATUS\r | |
90 | UsbSetDescriptor (\r | |
91 | IN EFI_USB_IO_PROTOCOL *UsbIo,\r | |
92 | IN UINT16 Value,\r | |
93 | IN UINT16 Index,\r | |
94 | IN UINT16 DescriptorLength,\r | |
95 | IN VOID *Descriptor,\r | |
96 | OUT UINT32 *Status\r | |
97 | )\r | |
98 | /*++\r | |
99 | \r | |
100 | Routine Description:\r | |
101 | \r | |
102 | Usb Set Descriptor\r | |
103 | \r | |
104 | Arguments:\r | |
105 | \r | |
106 | UsbIo - EFI_USB_IO_PROTOCOL\r | |
107 | Value - Device Request Value\r | |
108 | Index - Device Request Index \r | |
109 | DescriptorLength - Descriptor Length\r | |
110 | Descriptor - Descriptor buffer to set\r | |
111 | Status - Transfer Status\r | |
112 | Returns:\r | |
113 | EFI_INVALID_PARAMETER - Parameter is error\r | |
114 | EFI_SUCCESS - Success\r | |
115 | EFI_TIMEOUT - Device has no response \r | |
116 | \r | |
117 | --*/\r | |
118 | {\r | |
119 | EFI_USB_DEVICE_REQUEST DevReq;\r | |
120 | \r | |
121 | if (UsbIo == NULL) {\r | |
122 | return EFI_INVALID_PARAMETER;\r | |
123 | }\r | |
124 | \r | |
125 | ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r | |
126 | \r | |
127 | DevReq.RequestType = USB_DEV_SET_DESCRIPTOR_REQ_TYPE;\r | |
128 | DevReq.Request = USB_DEV_SET_DESCRIPTOR;\r | |
129 | DevReq.Value = Value;\r | |
130 | DevReq.Index = Index;\r | |
131 | DevReq.Length = DescriptorLength;\r | |
132 | \r | |
133 | return UsbIo->UsbControlTransfer (\r | |
134 | UsbIo,\r | |
135 | &DevReq,\r | |
136 | EfiUsbDataOut,\r | |
137 | TIMEOUT_VALUE,\r | |
138 | Descriptor,\r | |
139 | DescriptorLength,\r | |
140 | Status\r | |
141 | );\r | |
142 | }\r | |
143 | \r | |
144 | //\r | |
145 | // Get device Interface\r | |
146 | //\r | |
147 | EFI_STATUS\r | |
148 | UsbGetDeviceInterface (\r | |
149 | IN EFI_USB_IO_PROTOCOL *UsbIo,\r | |
150 | IN UINT16 Index,\r | |
151 | OUT UINT8 *AltSetting,\r | |
152 | OUT UINT32 *Status\r | |
153 | )\r | |
154 | /*++\r | |
155 | \r | |
156 | Routine Description:\r | |
157 | \r | |
158 | Usb Get Device Interface\r | |
159 | \r | |
160 | Arguments:\r | |
161 | \r | |
162 | UsbIo - EFI_USB_IO_PROTOCOL\r | |
163 | Index - Interface index value\r | |
164 | AltSetting - Alternate setting\r | |
165 | Status - Trasnsfer status\r | |
166 | \r | |
167 | Returns:\r | |
168 | \r | |
169 | EFI_INVALID_PARAMETER - Parameter is error\r | |
170 | EFI_SUCCESS - Success\r | |
171 | EFI_TIMEOUT - Device has no response \r | |
172 | \r | |
173 | \r | |
174 | --*/\r | |
175 | {\r | |
176 | EFI_USB_DEVICE_REQUEST DevReq;\r | |
177 | \r | |
178 | if (UsbIo == NULL) {\r | |
179 | return EFI_INVALID_PARAMETER;\r | |
180 | }\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_DEV_GET_INTERFACE;\r | |
186 | DevReq.Index = Index;\r | |
187 | DevReq.Length = 1;\r | |
188 | \r | |
189 | return UsbIo->UsbControlTransfer (\r | |
190 | UsbIo,\r | |
191 | &DevReq,\r | |
192 | EfiUsbDataIn,\r | |
193 | TIMEOUT_VALUE,\r | |
194 | AltSetting,\r | |
195 | 1,\r | |
196 | Status\r | |
197 | );\r | |
198 | }\r | |
199 | //\r | |
200 | // Set device interface\r | |
201 | //\r | |
202 | EFI_STATUS\r | |
203 | UsbSetDeviceInterface (\r | |
204 | IN EFI_USB_IO_PROTOCOL *UsbIo,\r | |
205 | IN UINT16 InterfaceNo,\r | |
206 | IN UINT16 AltSetting,\r | |
207 | OUT UINT32 *Status\r | |
208 | )\r | |
209 | /*++\r | |
210 | \r | |
211 | Routine Description:\r | |
212 | \r | |
213 | Usb Set Device Interface\r | |
214 | \r | |
215 | Arguments:\r | |
216 | \r | |
217 | UsbIo - EFI_USB_IO_PROTOCOL\r | |
218 | InterfaceNo - Interface Number\r | |
219 | AltSetting - Alternate setting\r | |
220 | Status - Trasnsfer status\r | |
221 | \r | |
222 | Returns:\r | |
223 | \r | |
224 | EFI_INVALID_PARAMETER - Parameter is error\r | |
225 | EFI_SUCCESS - Success\r | |
226 | EFI_TIMEOUT - Device has no response \r | |
227 | \r | |
228 | --*/\r | |
229 | {\r | |
230 | EFI_USB_DEVICE_REQUEST DevReq;\r | |
231 | \r | |
232 | if (UsbIo == NULL) {\r | |
233 | return EFI_INVALID_PARAMETER;\r | |
234 | }\r | |
235 | \r | |
236 | ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r | |
237 | \r | |
238 | DevReq.RequestType = USB_DEV_SET_INTERFACE_REQ_TYPE;\r | |
239 | DevReq.Request = USB_DEV_SET_INTERFACE;\r | |
240 | DevReq.Value = AltSetting;\r | |
241 | DevReq.Index = InterfaceNo;\r | |
242 | \r | |
243 | \r | |
244 | return UsbIo->UsbControlTransfer (\r | |
245 | UsbIo,\r | |
246 | &DevReq,\r | |
247 | EfiUsbNoData,\r | |
248 | TIMEOUT_VALUE,\r | |
249 | NULL,\r | |
250 | 0,\r | |
251 | Status\r | |
252 | );\r | |
253 | }\r | |
254 | //\r | |
255 | // Get device configuration\r | |
256 | //\r | |
257 | EFI_STATUS\r | |
258 | UsbGetDeviceConfiguration (\r | |
259 | IN EFI_USB_IO_PROTOCOL *UsbIo,\r | |
260 | OUT UINT8 *ConfigValue,\r | |
261 | OUT UINT32 *Status\r | |
262 | )\r | |
263 | /*++\r | |
264 | \r | |
265 | Routine Description:\r | |
266 | \r | |
267 | Usb Get Device Configuration\r | |
268 | \r | |
269 | Arguments:\r | |
270 | \r | |
271 | UsbIo - EFI_USB_IO_PROTOCOL\r | |
272 | ConfigValue - Config Value\r | |
273 | Status - Transfer Status\r | |
274 | \r | |
275 | Returns:\r | |
276 | \r | |
277 | EFI_INVALID_PARAMETER - Parameter is error\r | |
278 | EFI_SUCCESS - Success\r | |
279 | EFI_TIMEOUT - Device has no response \r | |
280 | \r | |
281 | --*/\r | |
282 | {\r | |
283 | EFI_USB_DEVICE_REQUEST DevReq;\r | |
284 | \r | |
285 | if (UsbIo == NULL) {\r | |
286 | return EFI_INVALID_PARAMETER;\r | |
287 | }\r | |
288 | \r | |
289 | ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r | |
290 | \r | |
291 | DevReq.RequestType = USB_DEV_GET_CONFIGURATION_REQ_TYPE;\r | |
292 | DevReq.Request = USB_DEV_GET_CONFIGURATION;\r | |
293 | DevReq.Length = 1;\r | |
294 | \r | |
295 | return UsbIo->UsbControlTransfer (\r | |
296 | UsbIo,\r | |
297 | &DevReq,\r | |
298 | EfiUsbDataIn,\r | |
299 | TIMEOUT_VALUE,\r | |
300 | ConfigValue,\r | |
301 | 1,\r | |
302 | Status\r | |
303 | );\r | |
304 | }\r | |
305 | //\r | |
306 | // Set device configuration\r | |
307 | //\r | |
308 | EFI_STATUS\r | |
309 | UsbSetDeviceConfiguration (\r | |
310 | IN EFI_USB_IO_PROTOCOL *UsbIo,\r | |
311 | IN UINT16 Value,\r | |
312 | OUT UINT32 *Status\r | |
313 | )\r | |
314 | /*++\r | |
315 | \r | |
316 | Routine Description:\r | |
317 | \r | |
318 | Usb Set Device Configuration\r | |
319 | \r | |
320 | Arguments:\r | |
321 | \r | |
322 | UsbIo - EFI_USB_IO_PROTOCOL\r | |
323 | Value - Configuration Value to set\r | |
324 | Status - Transfer status\r | |
325 | \r | |
326 | Returns:\r | |
327 | \r | |
328 | EFI_INVALID_PARAMETER - Parameter is error\r | |
329 | EFI_SUCCESS - Success\r | |
330 | EFI_TIMEOUT - Device has no response \r | |
331 | \r | |
332 | --*/\r | |
333 | {\r | |
334 | EFI_USB_DEVICE_REQUEST DevReq;\r | |
335 | \r | |
336 | if (UsbIo == NULL) {\r | |
337 | return EFI_INVALID_PARAMETER;\r | |
338 | }\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_DEV_SET_CONFIGURATION;\r | |
344 | DevReq.Value = Value;\r | |
345 | \r | |
346 | return UsbIo->UsbControlTransfer (\r | |
347 | UsbIo,\r | |
348 | &DevReq,\r | |
349 | EfiUsbNoData,\r | |
350 | TIMEOUT_VALUE,\r | |
351 | NULL,\r | |
352 | 0,\r | |
353 | Status\r | |
354 | );\r | |
355 | }\r | |
356 | //\r | |
357 | // Set Device Feature\r | |
358 | //\r | |
359 | EFI_STATUS\r | |
360 | UsbSetDeviceFeature (\r | |
361 | IN EFI_USB_IO_PROTOCOL *UsbIo,\r | |
362 | IN EFI_USB_RECIPIENT Recipient,\r | |
363 | IN UINT16 Value,\r | |
364 | IN UINT16 Target,\r | |
365 | OUT UINT32 *Status\r | |
366 | )\r | |
367 | /*++\r | |
368 | \r | |
369 | Routine Description:\r | |
370 | \r | |
371 | Usb Set Device Feature\r | |
372 | \r | |
373 | Arguments:\r | |
374 | \r | |
375 | UsbIo - EFI_USB_IO_PROTOCOL\r | |
376 | Recipient - Interface/Device/Endpoint\r | |
377 | Value - Request value\r | |
378 | Target - Request Index\r | |
379 | Status - Transfer status\r | |
380 | \r | |
381 | Returns:\r | |
382 | \r | |
383 | EFI_INVALID_PARAMETER - Parameter is error\r | |
384 | EFI_SUCCESS - Success\r | |
385 | EFI_TIMEOUT - Device has no response \r | |
386 | \r | |
387 | --*/\r | |
388 | {\r | |
389 | EFI_USB_DEVICE_REQUEST DevReq;\r | |
390 | \r | |
391 | if (UsbIo == NULL) {\r | |
392 | return EFI_INVALID_PARAMETER;\r | |
393 | }\r | |
394 | \r | |
395 | ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r | |
396 | \r | |
397 | switch (Recipient) {\r | |
398 | \r | |
399 | case EfiUsbDevice:\r | |
400 | DevReq.RequestType = 0x00;\r | |
401 | break;\r | |
402 | \r | |
403 | case EfiUsbInterface:\r | |
404 | DevReq.RequestType = 0x01;\r | |
405 | break;\r | |
406 | \r | |
407 | case EfiUsbEndpoint:\r | |
408 | DevReq.RequestType = 0x02;\r | |
409 | break;\r | |
410 | }\r | |
411 | //\r | |
412 | // Fill device request, see USB1.1 spec\r | |
413 | //\r | |
414 | DevReq.Request = USB_DEV_SET_FEATURE;\r | |
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 | |
429 | //\r | |
430 | // Clear Device Feature\r | |
431 | //\r | |
432 | EFI_STATUS\r | |
433 | UsbClearDeviceFeature (\r | |
434 | IN EFI_USB_IO_PROTOCOL *UsbIo,\r | |
435 | IN EFI_USB_RECIPIENT Recipient,\r | |
436 | IN UINT16 Value,\r | |
437 | IN UINT16 Target,\r | |
438 | OUT UINT32 *Status\r | |
439 | )\r | |
440 | /*++\r | |
441 | \r | |
442 | Routine Description:\r | |
443 | \r | |
444 | Usb Clear Device Feature\r | |
445 | \r | |
446 | Arguments:\r | |
447 | \r | |
448 | UsbIo - EFI_USB_IO_PROTOCOL\r | |
449 | Recipient - Interface/Device/Endpoint\r | |
450 | Value - Request value\r | |
451 | Target - Request Index\r | |
452 | Status - Transfer status\r | |
453 | \r | |
454 | Returns:\r | |
455 | \r | |
456 | EFI_INVALID_PARAMETER - Parameter is error\r | |
457 | EFI_SUCCESS - Success\r | |
458 | EFI_TIMEOUT - Device has no response \r | |
459 | \r | |
460 | --*/\r | |
461 | {\r | |
462 | EFI_USB_DEVICE_REQUEST DevReq;\r | |
463 | \r | |
464 | if (UsbIo == NULL) {\r | |
465 | return EFI_INVALID_PARAMETER;\r | |
466 | }\r | |
467 | \r | |
468 | ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r | |
469 | \r | |
470 | switch (Recipient) {\r | |
471 | \r | |
472 | case EfiUsbDevice:\r | |
473 | DevReq.RequestType = 0x00;\r | |
474 | break;\r | |
475 | \r | |
476 | case EfiUsbInterface:\r | |
477 | DevReq.RequestType = 0x01;\r | |
478 | break;\r | |
479 | \r | |
480 | case EfiUsbEndpoint:\r | |
481 | DevReq.RequestType = 0x02;\r | |
482 | break;\r | |
483 | }\r | |
484 | //\r | |
485 | // Fill device request, see USB1.1 spec\r | |
486 | //\r | |
487 | DevReq.Request = USB_DEV_CLEAR_FEATURE;\r | |
488 | DevReq.Value = Value;\r | |
489 | DevReq.Index = Target;\r | |
490 | \r | |
491 | \r | |
492 | return UsbIo->UsbControlTransfer (\r | |
493 | UsbIo,\r | |
494 | &DevReq,\r | |
495 | EfiUsbNoData,\r | |
496 | TIMEOUT_VALUE,\r | |
497 | NULL,\r | |
498 | 0,\r | |
499 | Status\r | |
500 | );\r | |
501 | }\r | |
502 | //\r | |
503 | // Get Device Status\r | |
504 | //\r | |
505 | EFI_STATUS\r | |
506 | UsbGetDeviceStatus (\r | |
507 | IN EFI_USB_IO_PROTOCOL *UsbIo,\r | |
508 | IN EFI_USB_RECIPIENT Recipient,\r | |
509 | IN UINT16 Target,\r | |
510 | OUT UINT16 *DevStatus,\r | |
511 | OUT UINT32 *Status\r | |
512 | )\r | |
513 | /*++\r | |
514 | \r | |
515 | Routine Description:\r | |
516 | \r | |
517 | Usb Get Device Status\r | |
518 | \r | |
519 | Arguments:\r | |
520 | \r | |
521 | UsbIo - EFI_USB_IO_PROTOCOL\r | |
522 | Recipient - Interface/Device/Endpoint\r | |
523 | Target - Request index\r | |
524 | DevStatus - Device status\r | |
525 | Status - Transfer status\r | |
526 | \r | |
527 | Returns:\r | |
528 | \r | |
529 | EFI_INVALID_PARAMETER - Parameter is error\r | |
530 | EFI_SUCCESS - Success\r | |
531 | EFI_TIMEOUT - Device has no response \r | |
532 | \r | |
533 | --*/\r | |
534 | {\r | |
535 | EFI_USB_DEVICE_REQUEST DevReq;\r | |
536 | \r | |
537 | if (UsbIo == NULL) {\r | |
538 | return EFI_INVALID_PARAMETER;\r | |
539 | }\r | |
540 | \r | |
541 | ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r | |
542 | \r | |
543 | switch (Recipient) {\r | |
544 | \r | |
545 | case EfiUsbDevice:\r | |
546 | DevReq.RequestType = 0x80;\r | |
547 | break;\r | |
548 | \r | |
549 | case EfiUsbInterface:\r | |
550 | DevReq.RequestType = 0x81;\r | |
551 | break;\r | |
552 | \r | |
553 | case EfiUsbEndpoint:\r | |
554 | DevReq.RequestType = 0x82;\r | |
555 | break;\r | |
556 | }\r | |
557 | //\r | |
558 | // Fill device request, see USB1.1 spec\r | |
559 | //\r | |
560 | DevReq.Request = USB_DEV_GET_STATUS;\r | |
561 | DevReq.Value = 0;\r | |
562 | DevReq.Index = Target;\r | |
563 | DevReq.Length = 2;\r | |
564 | \r | |
565 | return UsbIo->UsbControlTransfer (\r | |
566 | UsbIo,\r | |
567 | &DevReq,\r | |
568 | EfiUsbDataIn,\r | |
569 | TIMEOUT_VALUE,\r | |
570 | DevStatus,\r | |
571 | 2,\r | |
572 | Status\r | |
573 | );\r | |
574 | }\r | |
575 | //\r | |
576 | // Usb Get String\r | |
577 | //\r | |
578 | EFI_STATUS\r | |
579 | UsbGetString (\r | |
580 | IN EFI_USB_IO_PROTOCOL *UsbIo,\r | |
581 | IN UINT16 LangID,\r | |
582 | IN UINT8 Index,\r | |
583 | IN VOID *Buf,\r | |
584 | IN UINTN BufSize,\r | |
585 | OUT UINT32 *Status\r | |
586 | )\r | |
587 | /*++\r | |
588 | \r | |
589 | Routine Description:\r | |
590 | \r | |
591 | Usb Get String\r | |
592 | \r | |
593 | Arguments:\r | |
594 | \r | |
595 | UsbIo - EFI_USB_IO_PROTOCOL\r | |
596 | LangID - Language ID\r | |
597 | Index - Request index\r | |
598 | Buf - Buffer to store string\r | |
599 | BufSize - Buffer size\r | |
600 | Status - Transfer status\r | |
601 | \r | |
602 | Returns:\r | |
603 | \r | |
604 | EFI_INVALID_PARAMETER - Parameter is error\r | |
605 | EFI_SUCCESS - Success\r | |
606 | EFI_TIMEOUT - Device has no response \r | |
607 | \r | |
608 | --*/\r | |
609 | {\r | |
610 | UINT16 Value;\r | |
611 | \r | |
612 | if (UsbIo == NULL) {\r | |
613 | return EFI_INVALID_PARAMETER;\r | |
614 | }\r | |
615 | //\r | |
616 | // Fill value, see USB1.1 spec\r | |
617 | //\r | |
618 | Value = (UINT16) ((USB_DT_STRING << 8) | Index);\r | |
619 | \r | |
620 | return UsbGetDescriptor (\r | |
621 | UsbIo,\r | |
622 | Value,\r | |
623 | LangID,\r | |
624 | (UINT16) BufSize,\r | |
625 | Buf,\r | |
626 | Status\r | |
627 | );\r | |
628 | }\r | |
629 | \r | |
630 | EFI_STATUS\r | |
631 | UsbClearEndpointHalt (\r | |
632 | IN EFI_USB_IO_PROTOCOL *UsbIo,\r | |
633 | IN UINT8 EndpointNo,\r | |
634 | OUT UINT32 *Status\r | |
635 | )\r | |
636 | /*++\r | |
637 | \r | |
638 | Routine Description:\r | |
639 | \r | |
640 | Clear endpoint stall\r | |
641 | \r | |
642 | Arguments:\r | |
643 | \r | |
644 | UsbIo - EFI_USB_IO_PROTOCOL\r | |
645 | EndpointNo - Endpoint Number\r | |
646 | Status - Transfer Status\r | |
647 | \r | |
648 | Returns:\r | |
649 | \r | |
650 | EFI_NOT_FOUND - Can't find the Endpoint\r | |
651 | EFI_DEVICE_ERROR - Hardware error\r | |
652 | EFI_SUCCESS - Success\r | |
653 | \r | |
654 | --*/\r | |
655 | {\r | |
656 | EFI_STATUS Result;\r | |
657 | EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor;\r | |
658 | EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;\r | |
659 | UINT8 Index;\r | |
660 | \r | |
661 | ZeroMem (&EndpointDescriptor, sizeof (EFI_USB_ENDPOINT_DESCRIPTOR));\r | |
662 | //\r | |
663 | // First seach the endpoint descriptor for that endpoint addr\r | |
664 | //\r | |
665 | Result = UsbIo->UsbGetInterfaceDescriptor (\r | |
666 | UsbIo,\r | |
667 | &InterfaceDescriptor\r | |
668 | );\r | |
669 | if (EFI_ERROR (Result)) {\r | |
670 | return Result;\r | |
671 | }\r | |
672 | \r | |
673 | for (Index = 0; Index < InterfaceDescriptor.NumEndpoints; Index++) {\r | |
674 | Result = UsbIo->UsbGetEndpointDescriptor (\r | |
675 | UsbIo,\r | |
676 | Index,\r | |
677 | &EndpointDescriptor\r | |
678 | );\r | |
679 | if (EFI_ERROR (Result)) {\r | |
680 | continue;\r | |
681 | }\r | |
682 | \r | |
683 | if (EndpointDescriptor.EndpointAddress == EndpointNo) {\r | |
684 | break;\r | |
685 | }\r | |
686 | }\r | |
687 | \r | |
688 | if (Index == InterfaceDescriptor.NumEndpoints) {\r | |
689 | //\r | |
690 | // No such endpoint\r | |
691 | //\r | |
692 | return EFI_NOT_FOUND;\r | |
693 | }\r | |
694 | \r | |
695 | Result = UsbClearDeviceFeature (\r | |
696 | UsbIo,\r | |
697 | EfiUsbEndpoint,\r | |
698 | EfiUsbEndpointHalt,\r | |
699 | EndpointDescriptor.EndpointAddress,\r | |
700 | Status\r | |
701 | );\r | |
702 | \r | |
703 | return Result;\r | |
704 | }\r |