26 if (Setting->Endpoints !=
NULL) {
30 for (Index = 0; Index < Setting->Desc.NumEndpoints; Index++) {
31 Ep = Setting->Endpoints[Index];
41 if (Setting->Desc.NumEndpoints > 0) {
65 if (Config->Interfaces !=
NULL) {
69 for (Index = 0; Index < Config->Desc.NumInterfaces; Index++) {
70 Interface = Config->Interfaces[Index];
72 if (Interface ==
NULL) {
79 for (SetIndex = 0; SetIndex < Interface->NumOfSetting; SetIndex++) {
80 if (Interface->Settings[SetIndex] !=
NULL) {
107 if (DevDesc->Configs !=
NULL) {
108 for (Index = 0; Index < DevDesc->Desc.NumConfigurations; Index++) {
109 if (DevDesc->Configs[Index] !=
NULL) {
150 case USB_DESC_TYPE_DEVICE:
155 case USB_DESC_TYPE_CONFIG:
160 case USB_DESC_TYPE_INTERFACE:
165 case USB_DESC_TYPE_ENDPOINT:
179 DEBUG ((DEBUG_ERROR,
"UsbCreateDesc: met mal-format descriptor, total length = %d!\n", Len));
195 if (Head->Len == 0) {
196 DEBUG ((DEBUG_ERROR,
"UsbCreateDesc: met mal-format descriptor, Head->Len = 0!\n"));
203 if (Head->Len > MAX_UINTN - Offset) {
204 DEBUG ((DEBUG_ERROR,
"UsbCreateDesc: met mal-format descriptor, Head->Len = %d!\n", Head->Len));
210 if (Head->Type == Type) {
220 DEBUG ((DEBUG_ERROR,
"UsbCreateDesc: met mal-format descriptor, Offset/Len = %d/%d!\n", Offset, Len));
224 if ((Head->Type != Type) || (Head->Len < DescLen)) {
225 DEBUG ((DEBUG_ERROR,
"UsbCreateDesc: descriptor cannot be found, Header(T/L) = %d/%d!\n", Head->Type, Head->Len));
266 Setting =
UsbCreateDesc (DescBuf, Len, USB_DESC_TYPE_INTERFACE, &Used);
268 if (Setting ==
NULL) {
269 DEBUG ((DEBUG_ERROR,
"UsbParseInterfaceDesc: failed to create interface descriptor\n"));
278 NumEp = Setting->Desc.NumEndpoints;
282 "UsbParseInterfaceDesc: interface %d(setting %d) has %d endpoints\n",
283 Setting->Desc.InterfaceNumber,
284 Setting->Desc.AlternateSetting,
294 if (Setting->Endpoints ==
NULL) {
301 for (Index = 0; (Index < NumEp) && (Offset < Len); Index++) {
302 Ep =
UsbCreateDesc (DescBuf + Offset, Len - Offset, USB_DESC_TYPE_ENDPOINT, &Used);
305 DEBUG ((DEBUG_ERROR,
"UsbParseInterfaceDesc: failed to create endpoint(index %d)\n", (UINT32)Index));
309 Setting->Endpoints[Index] = Ep;
344 ASSERT (DescBuf !=
NULL);
346 Config =
UsbCreateDesc (DescBuf, Len, USB_DESC_TYPE_CONFIG, &Consumed);
348 if (Config ==
NULL) {
355 NumIf = Config->Desc.NumInterfaces;
358 if (Config->Interfaces ==
NULL) {
364 "UsbParseConfigDesc: config %d has %d interfaces\n",
365 Config->Desc.ConfigurationValue,
369 for (Index = 0; Index < NumIf; Index++) {
372 if (Interface ==
NULL) {
376 Config->Interfaces[Index] = Interface;
397 if (Setting ==
NULL) {
398 DEBUG ((DEBUG_ERROR,
"UsbParseConfigDesc: warning: failed to get interface setting, stop parsing now.\n"));
400 }
else if (Setting->Desc.InterfaceNumber >= NumIf) {
401 DEBUG ((DEBUG_ERROR,
"UsbParseConfigDesc: malformatted interface descriptor\n"));
410 Interface = Config->Interfaces[Setting->Desc.InterfaceNumber];
412 if (Interface->NumOfSetting >= USB_MAX_INTERFACE_SETTING) {
416 Interface->Settings[Interface->NumOfSetting] = Setting;
417 Interface->NumOfSetting++;
468 ASSERT ((UsbDev !=
NULL) && (UsbDev->Bus !=
NULL));
470 DevReq.RequestType = USB_REQUEST_TYPE (Direction, Type, Target);
471 DevReq.Request = (UINT8)Request;
472 DevReq.Value = Value;
473 DevReq.Index = Index;
474 DevReq.Length = (UINT16)Length;
486 USB_GENERAL_DEVICE_REQUEST_TIMEOUT,
524 USB_REQ_TYPE_STANDARD,
526 USB_REQ_GET_DESCRIPTOR,
527 (UINT16)((DescType << 8) | DescIndex),
560 for (Index = 0; Index < 3; Index++) {
561 Status =
UsbCtrlGetDesc (UsbDev, USB_DESC_TYPE_DEVICE, 0, 0, &DevDesc, 8);
563 if (!EFI_ERROR (Status)) {
564 if ((DevDesc.BcdUSB >= 0x0300) && (DevDesc.MaxPacketSize0 == 9)) {
565 UsbDev->MaxPacket0 = 1 << 9;
569 UsbDev->MaxPacket0 = DevDesc.MaxPacketSize0;
573 gBS->Stall (USB_RETRY_MAX_PACK_SIZE_STALL);
576 return EFI_DEVICE_ERROR;
598 if (DevDesc ==
NULL) {
599 return EFI_OUT_OF_RESOURCES;
604 USB_DESC_TYPE_DEVICE,
611 if (EFI_ERROR (Status)) {
612 gBS->FreePool (DevDesc);
614 UsbDev->DevDesc = DevDesc;
646 Status =
UsbCtrlGetDesc (UsbDev, USB_DESC_TYPE_STRING, Index, LangId, &Desc, 2);
651 if (EFI_ERROR (Status) ||
653 (Desc.Length % 2 != 0)
667 USB_DESC_TYPE_STRING,
674 if (EFI_ERROR (Status)) {
707 return EFI_UNSUPPORTED;
710 if (Desc->Length < 4) {
711 Status = EFI_UNSUPPORTED;
717 Max = (Desc->Length - 2) / 2;
718 Max =
MIN (Max, USB_MAX_LANG_ID);
720 Point = Desc->String;
721 for (Index = 0; Index < Max; Index++) {
722 UsbDev->LangId[Index] = *Point;
726 UsbDev->TotalLangId = (UINT16)Max;
729 gBS->FreePool (Desc);
759 Status =
UsbCtrlGetDesc (UsbDev, USB_DESC_TYPE_CONFIG, Index, 0, &Desc, 8);
761 if (EFI_ERROR (Status)) {
764 "UsbGetOneConfig: failed to get descript length(%d) - %r\n",
772 DEBUG ((DEBUG_INFO,
"UsbGetOneConfig: total length is %d\n", Desc.TotalLength));
787 Status =
UsbCtrlGetDesc (UsbDev, USB_DESC_TYPE_CONFIG, Index, 0, Buf, Desc.TotalLength);
789 if (EFI_ERROR (Status)) {
790 DEBUG ((DEBUG_ERROR,
"UsbGetOneConfig: failed to get full descript - %r\n", Status));
828 if (EFI_ERROR (Status)) {
829 DEBUG ((DEBUG_ERROR,
"UsbBuildDescTable: failed to get device descriptor - %r\n", Status));
833 DevDesc = UsbDev->DevDesc;
834 NumConfig = DevDesc->Desc.NumConfigurations;
835 if (NumConfig == 0) {
836 return EFI_DEVICE_ERROR;
840 if (DevDesc->Configs ==
NULL) {
841 return EFI_OUT_OF_RESOURCES;
844 DEBUG ((DEBUG_INFO,
"UsbBuildDescTable: device has %d configures\n", NumConfig));
849 for (Index = 0; Index < NumConfig; Index++) {
852 if (Config ==
NULL) {
853 DEBUG ((DEBUG_ERROR,
"UsbBuildDescTable: failed to get configure (index %d)\n", Index));
860 return EFI_DEVICE_ERROR;
870 if (ConfigDesc ==
NULL) {
871 DEBUG ((DEBUG_ERROR,
"UsbBuildDescTable: failed to parse configure (index %d)\n", Index));
878 return EFI_DEVICE_ERROR;
884 DevDesc->Configs[Index] = ConfigDesc;
893 if (EFI_ERROR (Status)) {
894 DEBUG ((DEBUG_INFO,
"UsbBuildDescTable: get language ID table - %r\n", Status));
921 USB_REQ_TYPE_STANDARD,
956 USB_REQ_TYPE_STANDARD,
994 DevReq.RequestType = USB_REQUEST_TYPE (EfiUsbNoData, USB_REQ_TYPE_STANDARD, Target);
995 DevReq.Request = USB_REQ_CLEAR_FEATURE;
996 DevReq.Value = Feature;
997 DevReq.Index = Index;
1000 Status = UsbIo->UsbControlTransfer (
1004 USB_CLEAR_FEATURE_REQUEST_TIMEOUT,
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define OFFSET_OF(TYPE, Field)
#define DEBUG(Expression)
EFI_STATUS UsbIoClearFeature(IN EFI_USB_IO_PROTOCOL *UsbIo, IN UINTN Target, IN UINT16 Feature, IN UINT16 Index)
VOID UsbFreeConfigDesc(IN USB_CONFIG_DESC *Config)
VOID * UsbCreateDesc(IN UINT8 *DescBuf, IN UINTN Len, IN UINT8 Type, OUT UINTN *Consumed)
VOID UsbFreeInterfaceDesc(IN USB_INTERFACE_SETTING *Setting)
EFI_STATUS UsbBuildDescTable(IN USB_DEVICE *UsbDev)
EFI_USB_CONFIG_DESCRIPTOR * UsbGetOneConfig(IN USB_DEVICE *UsbDev, IN UINT8 Index)
EFI_STATUS UsbBuildLangTable(IN USB_DEVICE *UsbDev)
EFI_USB_STRING_DESCRIPTOR * UsbGetOneString(IN USB_DEVICE *UsbDev, IN UINT8 Index, IN UINT16 LangId)
EFI_STATUS UsbGetDevDesc(IN USB_DEVICE *UsbDev)
EFI_STATUS UsbSetConfig(IN USB_DEVICE *UsbDev, IN UINT8 ConfigIndex)
EFI_STATUS UsbSetAddress(IN USB_DEVICE *UsbDev, IN UINT8 Address)
EFI_STATUS UsbCtrlRequest(IN USB_DEVICE *UsbDev, IN EFI_USB_DATA_DIRECTION Direction, IN UINTN Type, IN UINTN Target, IN UINTN Request, IN UINT16 Value, IN UINT16 Index, IN OUT VOID *Buf, IN UINTN Length)
USB_INTERFACE_SETTING * UsbParseInterfaceDesc(IN UINT8 *DescBuf, IN UINTN Len, OUT UINTN *Consumed)
EFI_STATUS UsbGetMaxPacketSize0(IN USB_DEVICE *UsbDev)
EFI_STATUS UsbCtrlGetDesc(IN USB_DEVICE *UsbDev, IN UINTN DescType, IN UINTN DescIndex, IN UINT16 LangId, OUT VOID *Buf, IN UINTN Length)
USB_CONFIG_DESC * UsbParseConfigDesc(IN UINT8 *DescBuf, IN UINTN Len)
VOID UsbFreeDevDesc(IN USB_DEVICE_DESC *DevDesc)
EFI_STATUS UsbHcControlTransfer(IN USB_BUS *UsbBus, IN UINT8 DevAddr, IN UINT8 DevSpeed, IN UINTN MaxPacket, IN EFI_USB_DEVICE_REQUEST *Request, IN EFI_USB_DATA_DIRECTION Direction, IN OUT VOID *Data, IN OUT UINTN *DataLength, IN UINTN TimeOut, IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Translator, OUT UINT32 *UsbResult)