TianoCore EDK2 master
Loading...
Searching...
No Matches
UsbDxeLib.c
Go to the documentation of this file.
1
11#include "UefiUsbLibInternal.h"
12
40EFIAPI
43 IN UINT16 Value,
44 IN UINT16 Index,
45 IN UINT16 DescriptorLength,
46 OUT VOID *Descriptor,
47 OUT UINT32 *Status
48 )
49{
51
52 ASSERT (UsbIo != NULL);
53 ASSERT (Descriptor != NULL);
54 ASSERT (Status != NULL);
55
56 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
57
58 DevReq.RequestType = USB_DEV_GET_DESCRIPTOR_REQ_TYPE;
59 DevReq.Request = USB_REQ_GET_DESCRIPTOR;
60 DevReq.Value = Value;
61 DevReq.Index = Index;
62 DevReq.Length = DescriptorLength;
63
64 return UsbIo->UsbControlTransfer (
65 UsbIo,
66 &DevReq,
67 EfiUsbDataIn,
68 PcdGet32 (PcdUsbTransferTimeoutValue),
69 Descriptor,
70 DescriptorLength,
71 Status
72 );
73}
74
99EFIAPI
101 IN EFI_USB_IO_PROTOCOL *UsbIo,
102 IN UINT16 Value,
103 IN UINT16 Index,
104 IN UINT16 DescriptorLength,
105 IN VOID *Descriptor,
106 OUT UINT32 *Status
107 )
108{
110
111 ASSERT (UsbIo != NULL);
112 ASSERT (Descriptor != NULL);
113 ASSERT (Status != NULL);
114
115 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
116
117 DevReq.RequestType = USB_DEV_SET_DESCRIPTOR_REQ_TYPE;
118 DevReq.Request = USB_REQ_SET_DESCRIPTOR;
119 DevReq.Value = Value;
120 DevReq.Index = Index;
121 DevReq.Length = DescriptorLength;
122
123 return UsbIo->UsbControlTransfer (
124 UsbIo,
125 &DevReq,
126 EfiUsbDataOut,
127 PcdGet32 (PcdUsbTransferTimeoutValue),
128 Descriptor,
129 DescriptorLength,
130 Status
131 );
132}
133
156EFIAPI
158 IN EFI_USB_IO_PROTOCOL *UsbIo,
159 IN UINT16 Interface,
160 OUT UINT16 *AlternateSetting,
161 OUT UINT32 *Status
162 )
163{
165
166 ASSERT (UsbIo != NULL);
167 ASSERT (AlternateSetting != NULL);
168 ASSERT (Status != NULL);
169
170 *AlternateSetting = 0;
171
172 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
173
174 DevReq.RequestType = USB_DEV_GET_INTERFACE_REQ_TYPE;
175 DevReq.Request = USB_REQ_GET_INTERFACE;
176 DevReq.Index = Interface;
177 DevReq.Length = 1;
178
179 return UsbIo->UsbControlTransfer (
180 UsbIo,
181 &DevReq,
182 EfiUsbDataIn,
183 PcdGet32 (PcdUsbTransferTimeoutValue),
184 AlternateSetting,
185 1,
186 Status
187 );
188}
189
211EFIAPI
213 IN EFI_USB_IO_PROTOCOL *UsbIo,
214 IN UINT16 Interface,
215 IN UINT16 AlternateSetting,
216 OUT UINT32 *Status
217 )
218{
220
221 ASSERT (UsbIo != NULL);
222 ASSERT (Status != NULL);
223
224 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
225
226 DevReq.RequestType = USB_DEV_SET_INTERFACE_REQ_TYPE;
227 DevReq.Request = USB_REQ_SET_INTERFACE;
228 DevReq.Value = AlternateSetting;
229 DevReq.Index = Interface;
230
231 return UsbIo->UsbControlTransfer (
232 UsbIo,
233 &DevReq,
234 EfiUsbNoData,
235 PcdGet32 (PcdUsbTransferTimeoutValue),
236 NULL,
237 0,
238 Status
239 );
240}
241
263EFIAPI
265 IN EFI_USB_IO_PROTOCOL *UsbIo,
266 OUT UINT16 *ConfigurationValue,
267 OUT UINT32 *Status
268 )
269{
271
272 ASSERT (UsbIo != NULL);
273 ASSERT (ConfigurationValue != NULL);
274 ASSERT (Status != NULL);
275
276 *ConfigurationValue = 0;
277
278 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
279
280 DevReq.RequestType = USB_DEV_GET_CONFIGURATION_REQ_TYPE;
281 DevReq.Request = USB_REQ_GET_CONFIG;
282 DevReq.Length = 1;
283
284 return UsbIo->UsbControlTransfer (
285 UsbIo,
286 &DevReq,
287 EfiUsbDataIn,
288 PcdGet32 (PcdUsbTransferTimeoutValue),
289 ConfigurationValue,
290 1,
291 Status
292 );
293}
294
315EFIAPI
317 IN EFI_USB_IO_PROTOCOL *UsbIo,
318 IN UINT16 ConfigurationValue,
319 OUT UINT32 *Status
320 )
321{
323
324 ASSERT (UsbIo != NULL);
325 ASSERT (Status != NULL);
326
327 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
328
329 DevReq.RequestType = USB_DEV_SET_CONFIGURATION_REQ_TYPE;
330 DevReq.Request = USB_REQ_SET_CONFIG;
331 DevReq.Value = ConfigurationValue;
332
333 return UsbIo->UsbControlTransfer (
334 UsbIo,
335 &DevReq,
336 EfiUsbNoData,
337 PcdGet32 (PcdUsbTransferTimeoutValue),
338 NULL,
339 0,
340 Status
341 );
342}
343
368EFIAPI
370 IN EFI_USB_IO_PROTOCOL *UsbIo,
371 IN USB_TYPES_DEFINITION Recipient,
372 IN UINT16 Value,
373 IN UINT16 Target,
374 OUT UINT32 *Status
375 )
376{
378
379 ASSERT (UsbIo != NULL);
380 ASSERT (Status != NULL);
381
382 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
383
384 switch (Recipient) {
385 case USB_TARGET_DEVICE:
386 DevReq.RequestType = USB_DEV_SET_FEATURE_REQ_TYPE_D;
387 break;
388
389 case USB_TARGET_INTERFACE:
390 DevReq.RequestType = USB_DEV_SET_FEATURE_REQ_TYPE_I;
391 break;
392
393 case USB_TARGET_ENDPOINT:
394 DevReq.RequestType = USB_DEV_SET_FEATURE_REQ_TYPE_E;
395 break;
396
397 default:
398 break;
399 }
400
401 //
402 // Fill device request, see USB1.1 spec
403 //
404 DevReq.Request = USB_REQ_SET_FEATURE;
405 DevReq.Value = Value;
406 DevReq.Index = Target;
407
408 return UsbIo->UsbControlTransfer (
409 UsbIo,
410 &DevReq,
411 EfiUsbNoData,
412 PcdGet32 (PcdUsbTransferTimeoutValue),
413 NULL,
414 0,
415 Status
416 );
417}
418
443EFIAPI
445 IN EFI_USB_IO_PROTOCOL *UsbIo,
446 IN USB_TYPES_DEFINITION Recipient,
447 IN UINT16 Value,
448 IN UINT16 Target,
449 OUT UINT32 *Status
450 )
451{
453
454 ASSERT (UsbIo != NULL);
455 ASSERT (Status != NULL);
456
457 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
458
459 switch (Recipient) {
460 case USB_TARGET_DEVICE:
461 DevReq.RequestType = USB_DEV_CLEAR_FEATURE_REQ_TYPE_D;
462 break;
463
464 case USB_TARGET_INTERFACE:
465 DevReq.RequestType = USB_DEV_CLEAR_FEATURE_REQ_TYPE_I;
466 break;
467
468 case USB_TARGET_ENDPOINT:
469 DevReq.RequestType = USB_DEV_CLEAR_FEATURE_REQ_TYPE_E;
470 break;
471
472 default:
473 break;
474 }
475
476 //
477 // Fill device request, see USB1.1 spec
478 //
479 DevReq.Request = USB_REQ_CLEAR_FEATURE;
480 DevReq.Value = Value;
481 DevReq.Index = Target;
482
483 return UsbIo->UsbControlTransfer (
484 UsbIo,
485 &DevReq,
486 EfiUsbNoData,
487 PcdGet32 (PcdUsbTransferTimeoutValue),
488 NULL,
489 0,
490 Status
491 );
492}
493
519EFIAPI
521 IN EFI_USB_IO_PROTOCOL *UsbIo,
522 IN USB_TYPES_DEFINITION Recipient,
523 IN UINT16 Target,
524 OUT UINT16 *DeviceStatus,
525 OUT UINT32 *Status
526 )
527{
529
530 ASSERT (UsbIo != NULL);
531 ASSERT (DeviceStatus != NULL);
532 ASSERT (Status != NULL);
533
534 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
535
536 switch (Recipient) {
537 case USB_TARGET_DEVICE:
538 DevReq.RequestType = USB_DEV_GET_STATUS_REQ_TYPE_D;
539 break;
540
541 case USB_TARGET_INTERFACE:
542 DevReq.RequestType = USB_DEV_GET_STATUS_REQ_TYPE_I;
543 break;
544
545 case USB_TARGET_ENDPOINT:
546 DevReq.RequestType = USB_DEV_GET_STATUS_REQ_TYPE_E;
547 break;
548
549 default:
550 break;
551 }
552
553 //
554 // Fill device request, see USB1.1 spec
555 //
556 DevReq.Request = USB_REQ_GET_STATUS;
557 DevReq.Value = 0;
558 DevReq.Index = Target;
559 DevReq.Length = 2;
560
561 return UsbIo->UsbControlTransfer (
562 UsbIo,
563 &DevReq,
564 EfiUsbDataIn,
565 PcdGet32 (PcdUsbTransferTimeoutValue),
566 DeviceStatus,
567 2,
568 Status
569 );
570}
571
594EFIAPI
596 IN EFI_USB_IO_PROTOCOL *UsbIo,
597 IN UINT8 Endpoint,
598 OUT UINT32 *Status
599 )
600{
601 EFI_STATUS Result;
602 EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor;
603 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
604 UINT8 Index;
605
606 ASSERT (UsbIo != NULL);
607 ASSERT (Status != NULL);
608
609 ZeroMem (&EndpointDescriptor, sizeof (EFI_USB_ENDPOINT_DESCRIPTOR));
610 //
611 // First search the endpoint descriptor for that endpoint addr
612 //
613 Result = UsbIo->UsbGetInterfaceDescriptor (
614 UsbIo,
615 &InterfaceDescriptor
616 );
617 if (EFI_ERROR (Result)) {
618 return Result;
619 }
620
621 for (Index = 0; Index < InterfaceDescriptor.NumEndpoints; Index++) {
622 Result = UsbIo->UsbGetEndpointDescriptor (
623 UsbIo,
624 Index,
625 &EndpointDescriptor
626 );
627 if (EFI_ERROR (Result)) {
628 continue;
629 }
630
631 if (EndpointDescriptor.EndpointAddress == Endpoint) {
632 break;
633 }
634 }
635
636 if (Index == InterfaceDescriptor.NumEndpoints) {
637 //
638 // No such endpoint
639 //
640 return EFI_NOT_FOUND;
641 }
642
643 Result = UsbClearFeature (
644 UsbIo,
645 USB_TARGET_ENDPOINT,
646 USB_FEATURE_ENDPOINT_HALT,
647 EndpointDescriptor.EndpointAddress,
648 Status
649 );
650
651 return Result;
652}
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define PcdGet32(TokenName)
Definition: PcdLib.h:362
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
EFI_STATUS EFIAPI UsbGetConfiguration(IN EFI_USB_IO_PROTOCOL *UsbIo, OUT UINT16 *ConfigurationValue, OUT UINT32 *Status)
Definition: UsbDxeLib.c:264
EFI_STATUS EFIAPI UsbSetDescriptor(IN EFI_USB_IO_PROTOCOL *UsbIo, IN UINT16 Value, IN UINT16 Index, IN UINT16 DescriptorLength, IN VOID *Descriptor, OUT UINT32 *Status)
Definition: UsbDxeLib.c:100
EFI_STATUS EFIAPI UsbClearFeature(IN EFI_USB_IO_PROTOCOL *UsbIo, IN USB_TYPES_DEFINITION Recipient, IN UINT16 Value, IN UINT16 Target, OUT UINT32 *Status)
Definition: UsbDxeLib.c:444
EFI_STATUS EFIAPI UsbSetInterface(IN EFI_USB_IO_PROTOCOL *UsbIo, IN UINT16 Interface, IN UINT16 AlternateSetting, OUT UINT32 *Status)
Definition: UsbDxeLib.c:212
EFI_STATUS EFIAPI UsbClearEndpointHalt(IN EFI_USB_IO_PROTOCOL *UsbIo, IN UINT8 Endpoint, OUT UINT32 *Status)
Definition: UsbDxeLib.c:595
EFI_STATUS EFIAPI UsbGetInterface(IN EFI_USB_IO_PROTOCOL *UsbIo, IN UINT16 Interface, OUT UINT16 *AlternateSetting, OUT UINT32 *Status)
Definition: UsbDxeLib.c:157
EFI_STATUS EFIAPI UsbSetConfiguration(IN EFI_USB_IO_PROTOCOL *UsbIo, IN UINT16 ConfigurationValue, OUT UINT32 *Status)
Definition: UsbDxeLib.c:316
EFI_STATUS EFIAPI UsbSetFeature(IN EFI_USB_IO_PROTOCOL *UsbIo, IN USB_TYPES_DEFINITION Recipient, IN UINT16 Value, IN UINT16 Target, OUT UINT32 *Status)
Definition: UsbDxeLib.c:369
EFI_STATUS EFIAPI UsbGetStatus(IN EFI_USB_IO_PROTOCOL *UsbIo, IN USB_TYPES_DEFINITION Recipient, IN UINT16 Target, OUT UINT16 *DeviceStatus, OUT UINT32 *Status)
Definition: UsbDxeLib.c:520
EFI_STATUS EFIAPI UsbGetDescriptor(IN EFI_USB_IO_PROTOCOL *UsbIo, IN UINT16 Value, IN UINT16 Index, IN UINT16 DescriptorLength, OUT VOID *Descriptor, OUT UINT32 *Status)
Definition: UsbDxeLib.c:41