14static UINT8 *mConfigData =
NULL;
49 IN UINT16 DescriptorLength,
56 ASSERT (UsbIo !=
NULL);
57 ASSERT (Descriptor !=
NULL);
58 ASSERT (Status !=
NULL);
62 DevReq.RequestType = USB_DEV_GET_DESCRIPTOR_REQ_TYPE;
63 DevReq.Request = USB_REQ_GET_DESCRIPTOR;
66 DevReq.Length = DescriptorLength;
68 return UsbIo->UsbControlTransfer (
72 PcdGet32 (PcdUsbTransferTimeoutValue),
108 IN UINT16 DescriptorLength,
115 ASSERT (UsbIo !=
NULL);
116 ASSERT (Descriptor !=
NULL);
117 ASSERT (Status !=
NULL);
121 DevReq.RequestType = USB_DEV_SET_DESCRIPTOR_REQ_TYPE;
122 DevReq.Request = USB_REQ_SET_DESCRIPTOR;
123 DevReq.Value = Value;
124 DevReq.Index = Index;
125 DevReq.Length = DescriptorLength;
127 return UsbIo->UsbControlTransfer (
131 PcdGet32 (PcdUsbTransferTimeoutValue),
164 OUT UINT16 *AlternateSetting,
170 ASSERT (UsbIo !=
NULL);
171 ASSERT (AlternateSetting !=
NULL);
172 ASSERT (Status !=
NULL);
174 *AlternateSetting = 0;
178 DevReq.RequestType = USB_DEV_GET_INTERFACE_REQ_TYPE;
179 DevReq.Request = USB_REQ_GET_INTERFACE;
180 DevReq.Index = Interface;
183 return UsbIo->UsbControlTransfer (
187 PcdGet32 (PcdUsbTransferTimeoutValue),
219 IN UINT16 AlternateSetting,
225 ASSERT (UsbIo !=
NULL);
226 ASSERT (Status !=
NULL);
230 DevReq.RequestType = USB_DEV_SET_INTERFACE_REQ_TYPE;
231 DevReq.Request = USB_REQ_SET_INTERFACE;
232 DevReq.Value = AlternateSetting;
233 DevReq.Index = Interface;
235 return UsbIo->UsbControlTransfer (
239 PcdGet32 (PcdUsbTransferTimeoutValue),
270 OUT UINT16 *ConfigurationValue,
276 ASSERT (UsbIo !=
NULL);
277 ASSERT (ConfigurationValue !=
NULL);
278 ASSERT (Status !=
NULL);
280 *ConfigurationValue = 0;
284 DevReq.RequestType = USB_DEV_GET_CONFIGURATION_REQ_TYPE;
285 DevReq.Request = USB_REQ_GET_CONFIG;
288 return UsbIo->UsbControlTransfer (
292 PcdGet32 (PcdUsbTransferTimeoutValue),
322 IN UINT16 ConfigurationValue,
328 ASSERT (UsbIo !=
NULL);
329 ASSERT (Status !=
NULL);
333 DevReq.RequestType = USB_DEV_SET_CONFIGURATION_REQ_TYPE;
334 DevReq.Request = USB_REQ_SET_CONFIG;
335 DevReq.Value = ConfigurationValue;
337 return UsbIo->UsbControlTransfer (
341 PcdGet32 (PcdUsbTransferTimeoutValue),
375 IN USB_TYPES_DEFINITION Recipient,
383 ASSERT (UsbIo !=
NULL);
384 ASSERT (Status !=
NULL);
389 case USB_TARGET_DEVICE:
390 DevReq.RequestType = USB_DEV_SET_FEATURE_REQ_TYPE_D;
393 case USB_TARGET_INTERFACE:
394 DevReq.RequestType = USB_DEV_SET_FEATURE_REQ_TYPE_I;
397 case USB_TARGET_ENDPOINT:
398 DevReq.RequestType = USB_DEV_SET_FEATURE_REQ_TYPE_E;
408 DevReq.Request = USB_REQ_SET_FEATURE;
409 DevReq.Value = Value;
410 DevReq.Index = Target;
412 return UsbIo->UsbControlTransfer (
416 PcdGet32 (PcdUsbTransferTimeoutValue),
450 IN USB_TYPES_DEFINITION Recipient,
458 ASSERT (UsbIo !=
NULL);
459 ASSERT (Status !=
NULL);
464 case USB_TARGET_DEVICE:
465 DevReq.RequestType = USB_DEV_CLEAR_FEATURE_REQ_TYPE_D;
468 case USB_TARGET_INTERFACE:
469 DevReq.RequestType = USB_DEV_CLEAR_FEATURE_REQ_TYPE_I;
472 case USB_TARGET_ENDPOINT:
473 DevReq.RequestType = USB_DEV_CLEAR_FEATURE_REQ_TYPE_E;
483 DevReq.Request = USB_REQ_CLEAR_FEATURE;
484 DevReq.Value = Value;
485 DevReq.Index = Target;
487 return UsbIo->UsbControlTransfer (
491 PcdGet32 (PcdUsbTransferTimeoutValue),
526 IN USB_TYPES_DEFINITION Recipient,
528 OUT UINT16 *DeviceStatus,
534 ASSERT (UsbIo !=
NULL);
535 ASSERT (DeviceStatus !=
NULL);
536 ASSERT (Status !=
NULL);
541 case USB_TARGET_DEVICE:
542 DevReq.RequestType = USB_DEV_GET_STATUS_REQ_TYPE_D;
545 case USB_TARGET_INTERFACE:
546 DevReq.RequestType = USB_DEV_GET_STATUS_REQ_TYPE_I;
549 case USB_TARGET_ENDPOINT:
550 DevReq.RequestType = USB_DEV_GET_STATUS_REQ_TYPE_E;
560 DevReq.Request = USB_REQ_GET_STATUS;
562 DevReq.Index = Target;
565 return UsbIo->UsbControlTransfer (
569 PcdGet32 (PcdUsbTransferTimeoutValue),
610 ASSERT (UsbIo !=
NULL);
611 ASSERT (Status !=
NULL);
617 Result = UsbIo->UsbGetInterfaceDescriptor (
621 if (EFI_ERROR (Result)) {
625 for (Index = 0; Index < InterfaceDescriptor.NumEndpoints; Index++) {
626 Result = UsbIo->UsbGetEndpointDescriptor (
631 if (EFI_ERROR (Result)) {
635 if (EndpointDescriptor.EndpointAddress == Endpoint) {
640 if (Index == InterfaceDescriptor.NumEndpoints) {
644 return EFI_NOT_FOUND;
650 USB_FEATURE_ENDPOINT_HALT,
651 EndpointDescriptor.EndpointAddress,
672InitUsbConfigDescriptorData (
686 Status = UsbIo->UsbGetDeviceDescriptor (UsbIo, &DevDesc);
689 Status = UsbIo->UsbGetConfigDescriptor (UsbIo, &CnfDesc);
692 if (mConfigData !=
NULL) {
699 gBS->FreePool (mConfigData);
712 ConfigValue = CnfDesc.ConfigurationValue;
713 for (ConfigNum = 0; ConfigNum < DevDesc.NumConfigurations; ConfigNum++) {
716 (USB_DESC_TYPE_CONFIG << 8) | ConfigNum,
724 if (CnfDesc.ConfigurationValue == ConfigValue) {
729 ASSERT (ConfigNum < DevDesc.NumConfigurations);
730 if (ConfigNum == DevDesc.NumConfigurations) {
731 return EFI_NOT_FOUND;
743 (USB_DESC_TYPE_CONFIG << 8) | ConfigNum,
795 Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &IntfDesc);
800 for (BufferPtr = mConfigData; BufferPtr < ConfigEnd; BufferPtr += BufferPtr[0]) {
801 if (BufferPtr[1] == USB_DESC_TYPE_INTERFACE) {
802 if ((BufferPtr[2] == IntfDesc.InterfaceNumber) && (BufferPtr[3] == (UINT8)Setting)) {
808 if (BufferPtr >= ConfigEnd) {
809 return EFI_UNSUPPORTED;
815 for (BufferEnd = BufferPtr + BufferPtr[0]; BufferEnd < ConfigEnd; BufferEnd += BufferEnd[0]) {
816 if (BufferEnd[1] == USB_DESC_TYPE_INTERFACE) {
823 if (DescType == USB_DESC_TYPE_INTERFACE) {
828 if ((DescType == USB_DESC_TYPE_ENDPOINT) || (DescType == USB_DESC_TYPE_CS_ENDPOINT)) {
829 while (BufferPtr < BufferEnd) {
830 BufferPtr += BufferPtr[0];
831 if (BufferPtr[1] == USB_DESC_TYPE_ENDPOINT) {
833 if (DescType == USB_DESC_TYPE_CS_ENDPOINT) {
834 BufferPtr += BufferPtr[0];
835 if (BufferPtr[1] != USB_DESC_TYPE_CS_ENDPOINT) {
849 if (DescType == USB_DESC_TYPE_CS_INTERFACE) {
850 while (BufferPtr < BufferEnd) {
851 BufferPtr += BufferPtr[0];
852 if (BufferPtr[1] == USB_DESC_TYPE_CS_INTERFACE) {
863 return EFI_NOT_FOUND;
876FindNumberOfCsInterfaces (
889 for (Buffer += Buffer[0]; Buffer < ConfigEnd; Buffer += Buffer[0]) {
890 if (Buffer[1] == USB_DESC_TYPE_INTERFACE) {
894 if (Buffer[1] == USB_DESC_TYPE_CS_INTERFACE) {
927 IN UINT16 AlternateSetting,
936 if ((Descriptor ==
NULL) || (CsInterfacesNumber ==
NULL)) {
937 return EFI_INVALID_PARAMETER;
940 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
942 Status = InitUsbConfigDescriptorData (This);
943 if (EFI_ERROR (Status)) {
944 Status = EFI_DEVICE_ERROR;
948 Status = FindUsbDescriptor (This, USB_DESC_TYPE_INTERFACE, AlternateSetting, 0, &Data);
949 if (EFI_ERROR (Status)) {
953 *CsInterfacesNumber = FindNumberOfCsInterfaces (Data);
957 gBS->RestoreTPL (OldTpl);
988 IN UINT16 AlternateSetting,
997 if (Descriptor ==
NULL) {
998 return EFI_INVALID_PARAMETER;
1001 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
1003 Status = InitUsbConfigDescriptorData (This);
1004 if (EFI_ERROR (Status)) {
1005 Status = EFI_DEVICE_ERROR;
1009 Status = FindUsbDescriptor (This, USB_DESC_TYPE_ENDPOINT, AlternateSetting, Index, &Data);
1010 if (EFI_ERROR (Status)) {
1017 gBS->RestoreTPL (OldTpl);
1049 IN UINT16 AlternateSetting,
1060 if ((BufferSize ==
NULL) || ((Buffer ==
NULL) && (*BufferSize != 0))) {
1061 return EFI_INVALID_PARAMETER;
1064 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
1066 Status = InitUsbConfigDescriptorData (This);
1067 if (EFI_ERROR (Status)) {
1068 Status = EFI_DEVICE_ERROR;
1072 Status = FindUsbDescriptor (This, USB_DESC_TYPE_CS_INTERFACE, AlternateSetting, Index, &Data);
1073 if (EFI_ERROR (Status)) {
1077 DescLength = ((UINT8 *)Data)[0];
1079 if ((Buffer ==
NULL) || (DescLength > *BufferSize)) {
1080 *BufferSize = DescLength;
1081 Status = EFI_BUFFER_TOO_SMALL;
1085 CopyMem (Buffer, Data, DescLength);
1088 gBS->RestoreTPL (OldTpl);
1121 IN UINT16 AlternateSetting,
1132 if ((BufferSize ==
NULL) || ((Buffer ==
NULL) && (*BufferSize != 0))) {
1133 return EFI_INVALID_PARAMETER;
1136 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
1138 Status = InitUsbConfigDescriptorData (This);
1139 if (EFI_ERROR (Status)) {
1140 Status = EFI_DEVICE_ERROR;
1144 Status = FindUsbDescriptor (This, USB_DESC_TYPE_CS_ENDPOINT, AlternateSetting, Index, &Data);
1145 if (EFI_ERROR (Status)) {
1149 DescLength = ((UINT8 *)Data)[0];
1151 if ((Buffer ==
NULL) || (DescLength > *BufferSize)) {
1152 *BufferSize = DescLength;
1153 Status = EFI_BUFFER_TOO_SMALL;
1157 CopyMem (Buffer, Data, DescLength);
1160 gBS->RestoreTPL (OldTpl);
1180 if (mConfigData !=
NULL) {
1181 gBS->FreePool (mConfigData);
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#define ASSERT_EFI_ERROR(StatusParameter)
#define PcdGet32(TokenName)
EFI_STATUS EFIAPI UsbGetConfiguration(IN EFI_USB_IO_PROTOCOL *UsbIo, OUT UINT16 *ConfigurationValue, OUT UINT32 *Status)
EFI_STATUS EFIAPI UsbGetCsInterfaceDescriptor(IN EFI_USB_IO_PROTOCOL *This, IN UINT16 AlternateSetting, IN UINTN Index, IN OUT UINTN *BufferSize, OUT VOID *Buffer)
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)
EFI_STATUS EFIAPI UefiUsbLibDestructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS EFIAPI UsbClearFeature(IN EFI_USB_IO_PROTOCOL *UsbIo, IN USB_TYPES_DEFINITION Recipient, IN UINT16 Value, IN UINT16 Target, OUT UINT32 *Status)
EFI_STATUS EFIAPI UsbSetInterface(IN EFI_USB_IO_PROTOCOL *UsbIo, IN UINT16 Interface, IN UINT16 AlternateSetting, OUT UINT32 *Status)
EFI_STATUS EFIAPI UsbClearEndpointHalt(IN EFI_USB_IO_PROTOCOL *UsbIo, IN UINT8 Endpoint, OUT UINT32 *Status)
EFI_STATUS EFIAPI UsbGetInterface(IN EFI_USB_IO_PROTOCOL *UsbIo, IN UINT16 Interface, OUT UINT16 *AlternateSetting, OUT UINT32 *Status)
EFI_STATUS EFIAPI UsbGetEndpointDescriptorSetting(IN EFI_USB_IO_PROTOCOL *This, IN UINT16 AlternateSetting, IN UINTN Index, OUT EFI_USB_ENDPOINT_DESCRIPTOR *Descriptor)
EFI_STATUS EFIAPI UsbSetConfiguration(IN EFI_USB_IO_PROTOCOL *UsbIo, IN UINT16 ConfigurationValue, OUT UINT32 *Status)
EFI_STATUS EFIAPI UsbSetFeature(IN EFI_USB_IO_PROTOCOL *UsbIo, IN USB_TYPES_DEFINITION Recipient, IN UINT16 Value, IN UINT16 Target, OUT UINT32 *Status)
EFI_STATUS EFIAPI UsbGetStatus(IN EFI_USB_IO_PROTOCOL *UsbIo, IN USB_TYPES_DEFINITION Recipient, IN UINT16 Target, OUT UINT16 *DeviceStatus, OUT UINT32 *Status)
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)
EFI_STATUS EFIAPI UsbGetInterfaceDescriptorSetting(IN EFI_USB_IO_PROTOCOL *This, IN UINT16 AlternateSetting, OUT EFI_USB_INTERFACE_DESCRIPTOR *Descriptor, OUT UINTN *CsInterfacesNumber)
EFI_STATUS EFIAPI UsbGetCsEndpointDescriptor(IN EFI_USB_IO_PROTOCOL *This, IN UINT16 AlternateSetting, IN UINTN Index, IN OUT UINTN *BufferSize, OUT VOID *Buffer)