void HIDUniversal::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *pep) { // If the first configuration satisfies, the others are not concidered. if (bNumEP > 1 && conf != bConfNum) return; ErrorMessage<uint8_t>(PSTR("\r\nConf.Val"), conf); ErrorMessage<uint8_t>(PSTR("Iface Num"), iface); ErrorMessage<uint8_t>(PSTR("Alt.Set"), alt); bConfNum = conf; uint8_t index = 0; HIDInterface *piface = FindInterface(iface, alt, proto); // Fill in interface structure in case of new interface if (!piface) { piface = hidInterfaces + bNumIface; piface->bmInterface = iface; piface->bmAltSet = alt; piface->bmProtocol = proto; bNumIface ++; } if ((pep->bmAttributes & 0x03) == 3 && (pep->bEndpointAddress & 0x80) == 0x80) { USBTRACE("I8\r\n"); index = epInterruptInIndex; } else { USBTRACE("I0\r\n"); index = epInterruptOutIndex; } if (index) { USBTRACE2("Ind:", index); // Fill in the endpoint info structure epInfo[bNumEP].epAddr = (pep->bEndpointAddress & 0x0F); epInfo[bNumEP].maxPktSize = (uint8_t)pep->wMaxPacketSize; epInfo[bNumEP].epAttribs = 0; // Fill in the endpoint index list piface->epIndex[index] = bNumEP; //(pep->bEndpointAddress & 0x0F); bNumEP ++; } PrintEndpointDescriptor(pep); }
uint8_t HIDUniversal::Init(uint8_t parent, uint8_t port, bool lowspeed) { const uint8_t constBufSize = sizeof (USB_DEVICE_DESCRIPTOR); uint8_t buf[constBufSize]; USB_DEVICE_DESCRIPTOR * udd = reinterpret_cast<USB_DEVICE_DESCRIPTOR*>(buf); uint8_t rcode; UsbDevice *p = NULL; EpInfo *oldep_ptr = NULL; uint8_t len = 0; uint8_t num_of_conf; // number of configurations //uint8_t num_of_intf; // number of interfaces AddressPool &addrPool = pUsb->GetAddressPool(); USBTRACE("HU Init\r\n"); if(bAddress) return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; // Get pointer to pseudo device with address 0 assigned p = addrPool.GetUsbDevicePtr(0); if(!p) return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; if(!p->epinfo) { USBTRACE("epinfo\r\n"); return USB_ERROR_EPINFO_IS_NULL; } // Save old pointer to EP_RECORD of address 0 oldep_ptr = p->epinfo; // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence p->epinfo = epInfo; p->lowspeed = lowspeed; // Get device descriptor rcode = pUsb->getDevDescr(0, 0, 8, (uint8_t*)buf); if(!rcode) len = (buf[0] > constBufSize) ? constBufSize : buf[0]; if(rcode) { // Restore p->epinfo p->epinfo = oldep_ptr; goto FailGetDevDescr; } // Restore p->epinfo p->epinfo = oldep_ptr; // Allocate new address according to device class bAddress = addrPool.AllocAddress(parent, false, port); if(!bAddress) return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL; // Extract Max Packet Size from the device descriptor epInfo[0].maxPktSize = udd->bMaxPacketSize0; // Assign new address to the device rcode = pUsb->setAddr(0, 0, bAddress); if(rcode) { p->lowspeed = false; addrPool.FreeAddress(bAddress); bAddress = 0; USBTRACE2("setAddr:", rcode); return rcode; } //delay(2); //per USB 2.0 sect.9.2.6.3 USBTRACE2("Addr:", bAddress); p->lowspeed = false; p = addrPool.GetUsbDevicePtr(bAddress); if(!p) return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; p->lowspeed = lowspeed; if(len) rcode = pUsb->getDevDescr(bAddress, 0, len, (uint8_t*)buf); if(rcode) goto FailGetDevDescr; VID = udd->idVendor; // Can be used by classes that inherits this class to check the VID and PID of the connected device PID = udd->idProduct; num_of_conf = udd->bNumConfigurations; // Assign epInfo to epinfo pointer rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); if(rcode) goto FailSetDevTblEntry; USBTRACE2("NC:", num_of_conf); for(uint8_t i = 0; i < num_of_conf; i++) { //HexDumper<USBReadParser, uint16_t, uint16_t> HexDump; ConfigDescParser<USB_CLASS_HID, 0, 0, CP_MASK_COMPARE_CLASS> confDescrParser(this); //rcode = pUsb->getConfDescr(bAddress, 0, i, &HexDump); rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser); if(rcode) goto FailGetConfDescr; if(bNumEP > 1) break; } // for if(bNumEP < 2) return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; // Assign epInfo to epinfo pointer rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo); USBTRACE2("Cnf:", bConfNum); // Set Configuration Value rcode = pUsb->setConf(bAddress, 0, bConfNum); if(rcode) goto FailSetConfDescr; for(uint8_t i = 0; i < bNumIface; i++) { if(hidInterfaces[i].epIndex[epInterruptInIndex] == 0) continue; rcode = SetIdle(hidInterfaces[i].bmInterface, 0, 0); if(rcode && rcode != hrSTALL) goto FailSetIdle; } USBTRACE("HU configured\r\n"); OnInitSuccessful(); bPollEnable = true; return 0; FailGetDevDescr: #ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: #ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: #ifdef DEBUG_USB_HOST NotifyFailGetConfDescr(); goto Fail; #endif FailSetConfDescr: #ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailSetIdle: #ifdef DEBUG_USB_HOST USBTRACE("SetIdle:"); #endif #ifdef DEBUG_USB_HOST Fail: NotifyFail(rcode); #endif Release(); return rcode; }
uint8_t ACM::Init(uint8_t parent, uint8_t port, bool lowspeed) { const uint8_t constBufSize = sizeof(USB_DEVICE_DESCRIPTOR); uint8_t buf[constBufSize]; uint8_t rcode; UsbDevice *p = NULL; EpInfo *oldep_ptr = NULL; uint8_t num_of_conf; // number of configurations AddressPool &addrPool = pUsb->GetAddressPool(); USBTRACE("ACM Init\r\n"); if (bAddress) return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; // Get pointer to pseudo device with address 0 assigned p = addrPool.GetUsbDevicePtr(0); if (!p) return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; if (!p->epinfo) { USBTRACE("epinfo\r\n"); return USB_ERROR_EPINFO_IS_NULL; } // Save old pointer to EP_RECORD of address 0 oldep_ptr = p->epinfo; // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence p->epinfo = epInfo; p->lowspeed = lowspeed; // Get device descriptor rcode = pUsb->getDevDescr( 0, 0, constBufSize, (uint8_t*)buf ); // Restore p->epinfo p->epinfo = oldep_ptr; if( rcode ) goto FailGetDevDescr; // Allocate new address according to device class bAddress = addrPool.AllocAddress(parent, false, port); if (!bAddress) return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL; // Extract Max Packet Size from the device descriptor epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0; // Assign new address to the device rcode = pUsb->setAddr( 0, 0, bAddress ); if (rcode) { p->lowspeed = false; addrPool.FreeAddress(bAddress); bAddress = 0; USBTRACE2("setAddr:",rcode); return rcode; } USBTRACE2("Addr:", bAddress); p->lowspeed = false; p = addrPool.GetUsbDevicePtr(bAddress); if (!p) return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; p->lowspeed = lowspeed; num_of_conf = ((USB_DEVICE_DESCRIPTOR*)buf)->bNumConfigurations; // Assign epInfo to epinfo pointer rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); if (rcode) goto FailSetDevTblEntry; USBTRACE2("NC:", num_of_conf); for (uint8_t i=0; i<num_of_conf; i++) { ConfigDescParser< USB_CLASS_COM_AND_CDC_CTRL, CDC_SUBCLASS_ACM, CDC_PROTOCOL_ITU_T_V_250, CP_MASK_COMPARE_CLASS | CP_MASK_COMPARE_SUBCLASS | CP_MASK_COMPARE_PROTOCOL> CdcControlParser(this); ConfigDescParser<USB_CLASS_CDC_DATA, 0, 0, CP_MASK_COMPARE_CLASS> CdcDataParser(this); rcode = pUsb->getConfDescr(bAddress, 0, i, &CdcControlParser); rcode = pUsb->getConfDescr(bAddress, 0, i, &CdcDataParser); if (bNumEP > 1) break; } // for if (bNumEP < 4) return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; // Assign epInfo to epinfo pointer rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo); USBTRACE2("Conf:", bConfNum); // Set Configuration Value rcode = pUsb->setConf(bAddress, 0, bConfNum); if (rcode) goto FailSetConf; rcode = pAsync->OnInit(this); if (rcode) goto FailOnInit; USBTRACE("ACM configured\r\n"); ready = true; //bPollEnable = true; //USBTRACE("Poll enabled\r\n"); return 0; FailGetDevDescr: USBTRACE("getDevDescr:"); goto Fail; FailSetDevTblEntry: USBTRACE("setDevTblEn:"); goto Fail; FailGetConfDescr: USBTRACE("getConf:"); goto Fail; FailSetConf: USBTRACE("setConf:"); goto Fail; FailOnInit: USBTRACE("OnInit:"); goto Fail; Fail: //Serial.println(rcode, HEX); Release(); return rcode; }
uint8_t FTDI::Init(uint8_t parent, uint8_t port, bool lowspeed) { const uint8_t constBufSize = sizeof (USB_DEVICE_DESCRIPTOR); uint8_t buf[constBufSize]; uint8_t rcode; UsbDevice *p = NULL; EpInfo *oldep_ptr = NULL; //uint8_t len = 0; //uint16_t cd_len = 0; uint8_t num_of_conf; // number of configurations //uint8_t num_of_intf; // number of interfaces AddressPool &addrPool = pUsb->GetAddressPool(); USBTRACE("FTDI Init\r\n"); if (bAddress) return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; // Get pointer to pseudo device with address 0 assigned p = addrPool.GetUsbDevicePtr(0); if (!p) return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; if (!p->epinfo) { USBTRACE("epinfo\r\n"); return USB_ERROR_EPINFO_IS_NULL; } // Save old pointer to EP_RECORD of address 0 oldep_ptr = p->epinfo; // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence p->epinfo = epInfo; p->lowspeed = lowspeed; // Get device descriptor rcode = pUsb->getDevDescr(0, 0, sizeof (USB_DEVICE_DESCRIPTOR), (uint8_t*)buf); // Restore p->epinfo p->epinfo = oldep_ptr; if (rcode) goto FailGetDevDescr; if (((USB_DEVICE_DESCRIPTOR*)buf)->idVendor != FTDI_VID || ((USB_DEVICE_DESCRIPTOR*)buf)->idProduct != FTDI_PID) return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; // Save type of FTDI chip wFTDIType = ((USB_DEVICE_DESCRIPTOR*)buf)->bcdDevice; // Allocate new address according to device class bAddress = addrPool.AllocAddress(parent, false, port); if (!bAddress) return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL; // Extract Max Packet Size from the device descriptor epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0; // Assign new address to the device rcode = pUsb->setAddr(0, 0, bAddress); if (rcode) { p->lowspeed = false; addrPool.FreeAddress(bAddress); bAddress = 0; USBTRACE2("setAddr:", rcode); return rcode; } USBTRACE2("Addr:", bAddress); p->lowspeed = false; p = addrPool.GetUsbDevicePtr(bAddress); if (!p) return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; p->lowspeed = lowspeed; num_of_conf = ((USB_DEVICE_DESCRIPTOR*)buf)->bNumConfigurations; // Assign epInfo to epinfo pointer rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); if (rcode) goto FailSetDevTblEntry; USBTRACE2("NC:", num_of_conf); for (uint8_t i = 0; i < num_of_conf; i++) { HexDumper<USBReadParser, uint16_t, uint16_t> HexDump; ConfigDescParser < 0xFF, 0xFF, 0xFF, CP_MASK_COMPARE_ALL> confDescrParser(this); rcode = pUsb->getConfDescr(bAddress, 0, i, &HexDump); if (rcode) goto FailGetConfDescr; rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser); if (rcode) goto FailGetConfDescr; if (bNumEP > 1) break; } // for if (bNumEP < 2) return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; USBTRACE2("NumEP:", bNumEP); // Assign epInfo to epinfo pointer rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo); USBTRACE2("Conf:", bConfNum); // Set Configuration Value rcode = pUsb->setConf(bAddress, 0, bConfNum); if (rcode) goto FailSetConfDescr; rcode = pAsync->OnInit(this); if (rcode) goto FailOnInit; USBTRACE("FTDI configured\r\n"); bPollEnable = true; return 0; FailGetDevDescr: #ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: #ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: #ifdef DEBUG_USB_HOST NotifyFailGetConfDescr(); goto Fail; #endif FailSetConfDescr: #ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailOnInit: #ifdef DEBUG_USB_HOST USBTRACE("OnInit:"); #endif Fail: #ifdef DEBUG_USB_HOST NotifyFail(rcode); #endif Release(); return rcode; }
/* Connection initialization of an Android phone */ uint32_t ADK::Init(uint32_t parent, uint32_t port, uint32_t lowspeed) { uint8_t buf[sizeof (USB_DEVICE_DESCRIPTOR)]; USB_DEVICE_DESCRIPTOR * udd = reinterpret_cast<USB_DEVICE_DESCRIPTOR*>(buf); uint32_t rcode; uint32_t num_of_conf; // number of configurations UsbDeviceDefinition *p = NULL; EpInfo *oldep_ptr = NULL; // get memory address of USB device address pool AddressPool &addrPool = pUsb->GetAddressPool(); USBTRACE("\r\nADK Init"); // check if address has already been assigned to an instance if(bAddress) { USBTRACE("\r\nAddress in use"); return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; } // Get pointer to pseudo device with address 0 assigned p = addrPool.GetUsbDevicePtr(0); if(!p) { USBTRACE("\r\nAddress not found"); return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; } if(!p->epinfo) { USBTRACE("epinfo is null\r\n"); return USB_ERROR_EPINFO_IS_NULL; } // Save old pointer to EP_RECORD of address 0 oldep_ptr = p->epinfo; // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence p->epinfo = epInfo; p->lowspeed = lowspeed; // Get device descriptor GET_DESCRIPTOR rcode = pUsb->getDevDescr(0, 0, sizeof(USB_DEVICE_DESCRIPTOR), (uint8_t*)buf); // Restore p->epinfo p->epinfo = oldep_ptr; if(rcode) { USBTRACE("\r\nGetDevDesc1 Error "); goto FailGetDevDescr; } // Reset UHD_BusReset(); while( Is_uhd_starting_reset() ) {} // Allocate new address according to device class bAddress = addrPool.AllocAddress(parent, false, port); if (!bAddress) return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL; // Extract Max Packet Size from device descriptor epInfo[0].maxPktSize = udd->bMaxPacketSize0; // Assign new address to the device SET_ADDRESS rcode = pUsb->setAddr(0, 0, bAddress); if(rcode) { USBTRACE("\r\nsetAddr Error "); p->lowspeed = false; addrPool.FreeAddress(bAddress); bAddress = 0; TRACE_USBHOST(printf("ADK::Init : setAddr failed with rcode %lu\r\n", rcode);) return rcode; }//if (rcode...
uint8_t XR21B1411::Init(uint8_t parent, uint8_t port, bool lowspeed) { const uint8_t constBufSize = sizeof (USB_DEVICE_DESCRIPTOR); uint8_t buf[constBufSize]; USB_DEVICE_DESCRIPTOR * udd = reinterpret_cast<USB_DEVICE_DESCRIPTOR*>(buf); uint8_t rcode; UsbDevice *p = NULL; EpInfo *oldep_ptr = NULL; uint8_t num_of_conf; // number of configurations AddressPool &addrPool = pUsb->GetAddressPool(); USBTRACE("XR Init\r\n"); if(bAddress) return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; // Get pointer to pseudo device with address 0 assigned p = addrPool.GetUsbDevicePtr(0); if(!p) return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; if(!p->epinfo) { USBTRACE("epinfo\r\n"); return USB_ERROR_EPINFO_IS_NULL; } // Save old pointer to EP_RECORD of address 0 oldep_ptr = p->epinfo; // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence p->epinfo = epInfo; p->lowspeed = lowspeed; // Get device descriptor rcode = pUsb->getDevDescr(0, 0, constBufSize, (uint8_t*)buf); // Restore p->epinfo p->epinfo = oldep_ptr; if(rcode) goto FailGetDevDescr; // Allocate new address according to device class bAddress = addrPool.AllocAddress(parent, false, port); if(!bAddress) return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL; // Extract Max Packet Size from the device descriptor epInfo[0].maxPktSize = udd->bMaxPacketSize0; // Assign new address to the device rcode = pUsb->setAddr(0, 0, bAddress); if(rcode) { p->lowspeed = false; addrPool.FreeAddress(bAddress); bAddress = 0; USBTRACE2("setAddr:", rcode); return rcode; } USBTRACE2("Addr:", bAddress); p->lowspeed = false; p = addrPool.GetUsbDevicePtr(bAddress); if(!p) return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; p->lowspeed = lowspeed; num_of_conf = udd->bNumConfigurations; if((((udd->idVendor != 0x2890U) || (udd->idProduct != 0x0201U)) && ((udd->idVendor != 0x04e2U) || (udd->idProduct != 0x1411U)))) return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; // Assign epInfo to epinfo pointer rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); if(rcode) goto FailSetDevTblEntry; USBTRACE2("NC:", num_of_conf); for(uint8_t i = 0; i < num_of_conf; i++) { ConfigDescParser< USB_CLASS_COM_AND_CDC_CTRL, CDC_SUBCLASS_ACM, CDC_PROTOCOL_ITU_T_V_250, CP_MASK_COMPARE_CLASS | CP_MASK_COMPARE_SUBCLASS | CP_MASK_COMPARE_PROTOCOL > CdcControlParser(this); ConfigDescParser<USB_CLASS_CDC_DATA, 0, 0, CP_MASK_COMPARE_CLASS> CdcDataParser(this); rcode = pUsb->getConfDescr(bAddress, 0, i, &CdcControlParser); if(rcode) goto FailGetConfDescr; rcode = pUsb->getConfDescr(bAddress, 0, i, &CdcDataParser); if(rcode) goto FailGetConfDescr; if(bNumEP > 1) break; } // for if(bNumEP < 4) return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; // Assign epInfo to epinfo pointer rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo); USBTRACE2("Conf:", bConfNum); // Set Configuration Value rcode = pUsb->setConf(bAddress, 0, bConfNum); if(rcode) goto FailSetConfDescr; // Set up features status _enhanced_status = enhanced_features(); half_duplex(false); autoflowRTS(false); autoflowDSR(false); autoflowXON(false); wide(false); // Always false, because this is only available in custom mode. rcode = pAsync->OnInit(this); if(rcode) goto FailOnInit; USBTRACE("XR configured\r\n"); ready = true; //bPollEnable = true; //USBTRACE("Poll enabled\r\n"); return 0; FailGetDevDescr: #ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: #ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: #ifdef DEBUG_USB_HOST NotifyFailGetConfDescr(); goto Fail; #endif FailSetConfDescr: #ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailOnInit: #ifdef DEBUG_USB_HOST USBTRACE("OnInit:"); #endif #ifdef DEBUG_USB_HOST Fail: NotifyFail(rcode); #endif Release(); return rcode; }
/** * * @param parent (not used) * @param port (not used) * @param lowspeed true if device is low speed * @return 0 for success */ uint8_t BulkOnly::Init(uint8_t parent, uint8_t port, bool lowspeed) { uint8_t rcode; uint8_t num_of_conf = epInfo[1].epAddr; // number of configurations epInfo[1].epAddr = 0; USBTRACE("MS Init\r\n"); AddressPool &addrPool = pUsb->GetAddressPool(); UsbDevice *p = addrPool.GetUsbDevicePtr(bAddress); if(!p) return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; // Assign new address to the device delay(2000); rcode = pUsb->setAddr(0, 0, bAddress); if(rcode) { p->lowspeed = false; addrPool.FreeAddress(bAddress); bAddress = 0; USBTRACE2("setAddr:", rcode); return rcode; } USBTRACE2("Addr:", bAddress); p->lowspeed = false; p = addrPool.GetUsbDevicePtr(bAddress); if(!p) return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; p->lowspeed = lowspeed; // Assign epInfo to epinfo pointer rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); if(rcode) goto FailSetDevTblEntry; USBTRACE2("NC:", num_of_conf); for(uint8_t i = 0; i < num_of_conf; i++) { ConfigDescParser< USB_CLASS_MASS_STORAGE, MASS_SUBCLASS_SCSI, MASS_PROTO_BBB, CP_MASK_COMPARE_CLASS | CP_MASK_COMPARE_SUBCLASS | CP_MASK_COMPARE_PROTOCOL > BulkOnlyParser(this); rcode = pUsb->getConfDescr(bAddress, 0, i, &BulkOnlyParser); if(rcode) goto FailGetConfDescr; if(bNumEP > 1) break; } if(bNumEP < 3) return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; // Assign epInfo to epinfo pointer pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo); USBTRACE2("Conf:", bConfNum); // Set Configuration Value rcode = pUsb->setConf(bAddress, 0, bConfNum); if(rcode) goto FailSetConfDescr; //Linux does a 1sec delay after this. delay(1000); rcode = GetMaxLUN(&bMaxLUN); if(rcode) goto FailGetMaxLUN; if(bMaxLUN >= MASS_MAX_SUPPORTED_LUN) bMaxLUN = MASS_MAX_SUPPORTED_LUN - 1; ErrorMessage<uint8_t > (PSTR("MaxLUN"), bMaxLUN); delay(1000); // Delay a bit for slow firmware. for(uint8_t lun = 0; lun <= bMaxLUN; lun++) { InquiryResponse response; rcode = Inquiry(lun, sizeof (InquiryResponse), (uint8_t*) & response); if(rcode) { ErrorMessage<uint8_t > (PSTR("Inquiry"), rcode); } else { #if 0 printf("LUN %i `", lun); uint8_t *buf = response.VendorID; for(int i = 0; i < 28; i++) printf("%c", buf[i]); printf("'\r\nQualifier %1.1X ", response.PeripheralQualifier); printf("Device type %2.2X ", response.DeviceType); printf("RMB %1.1X ", response.Removable); printf("SSCS %1.1X ", response.SCCS); uint8_t sv = response.Version; printf("SCSI version %2.2X\r\nDevice conforms to ", sv); switch(sv) { case 0: printf("No specific"); break; case 1: printf("ANSI X3.131-1986 (ANSI 1)"); break; case 2: printf("ANSI X3.131-1994 (ANSI 2)"); break; case 3: printf("ANSI INCITS 301-1997 (SPC)"); break; case 4: printf("ANSI INCITS 351-2001 (SPC-2)"); break; case 5: printf("ANSI INCITS 408-2005 (SPC-4)"); break; case 6: printf("T10/1731-D (SPC-4)"); break; default: printf("unknown"); } printf(" standards.\r\n"); #endif uint8_t tries = 0xf0; while((rcode = TestUnitReady(lun))) { if(rcode == 0x08) break; // break on no media, this is OK to do. // try to lock media and spin up if(tries < 14) { LockMedia(lun, 1); MediaCTL(lun, 1); // I actually have a USB stick that needs this! } else delay(2 * (tries + 1)); tries++; if(!tries) break; } if(!rcode) { delay(1000); LUNOk[lun] = CheckLUN(lun); if(!LUNOk[lun]) LUNOk[lun] = CheckLUN(lun); } } } CheckMedia(); rcode = OnInit(); if(rcode) goto FailOnInit; #ifdef DEBUG_USB_HOST USBTRACE("MS configured\r\n\r\n"); #endif bPollEnable = true; //USBTRACE("Poll enabled\r\n"); return 0; FailSetConfDescr: #ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailOnInit: #ifdef DEBUG_USB_HOST USBTRACE("OnInit:"); goto Fail; #endif FailGetMaxLUN: #ifdef DEBUG_USB_HOST USBTRACE("GetMaxLUN:"); goto Fail; #endif //#ifdef DEBUG_USB_HOST //FailInvalidSectorSize: // USBTRACE("Sector Size is NOT VALID: "); // goto Fail; //#endif FailSetDevTblEntry: #ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: #ifdef DEBUG_USB_HOST NotifyFailGetConfDescr(); #endif #ifdef DEBUG_USB_HOST Fail: NotifyFail(rcode); #endif Release(); return rcode; }
uint8_t BulkOnly::Init(uint8_t parent, uint8_t port, bool lowspeed) { const uint8_t constBufSize = sizeof(USB_DEVICE_DESCRIPTOR); uint8_t buf[constBufSize]; uint8_t rcode; UsbDevice *p = NULL; EpInfo *oldep_ptr = NULL; uint8_t num_of_conf; // number of configurations AddressPool &addrPool = pUsb->GetAddressPool(); USBTRACE("MS Init\r\n"); if (bAddress) return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; // Get pointer to pseudo device with address 0 assigned p = addrPool.GetUsbDevicePtr(0); if (!p) return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; if (!p->epinfo) { USBTRACE("epinfo\r\n"); return USB_ERROR_EPINFO_IS_NULL; } // Save old pointer to EP_RECORD of address 0 oldep_ptr = p->epinfo; // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence p->epinfo = epInfo; p->lowspeed = lowspeed; // Get device descriptor rcode = pUsb->getDevDescr( 0, 0, constBufSize, (uint8_t*)buf ); // Restore p->epinfo p->epinfo = oldep_ptr; if( rcode ) goto FailGetDevDescr; // Allocate new address according to device class bAddress = addrPool.AllocAddress(parent, false, port); if (!bAddress) return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL; // Extract Max Packet Size from the device descriptor epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0; // Assign new address to the device rcode = pUsb->setAddr( 0, 0, bAddress ); if (rcode) { p->lowspeed = false; addrPool.FreeAddress(bAddress); bAddress = 0; USBTRACE2("setAddr:",rcode); return rcode; } USBTRACE2("Addr:", bAddress); p->lowspeed = false; p = addrPool.GetUsbDevicePtr(bAddress); if (!p) return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; p->lowspeed = lowspeed; num_of_conf = ((USB_DEVICE_DESCRIPTOR*)buf)->bNumConfigurations; // Assign epInfo to epinfo pointer rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); if (rcode) goto FailSetDevTblEntry; USBTRACE2("NC:", num_of_conf); for (uint8_t i=0; i<num_of_conf; i++) { HexDumper<USBReadParser, uint16_t, uint16_t> HexDump; ConfigDescParser< USB_CLASS_MASS_STORAGE, MASS_SUBCLASS_SCSI, MASS_PROTO_BBB, CP_MASK_COMPARE_CLASS | CP_MASK_COMPARE_SUBCLASS | CP_MASK_COMPARE_PROTOCOL> BulkOnlyParser(this); rcode = pUsb->getConfDescr(bAddress, 0, i, &HexDump); rcode = pUsb->getConfDescr(bAddress, 0, i, &BulkOnlyParser); if (bNumEP > 1) break; } // for if (bNumEP < 3) return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; // Assign epInfo to epinfo pointer rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo); USBTRACE2("Conf:", bConfNum); // Set Configuration Value rcode = pUsb->setConf(bAddress, 0, bConfNum); if (rcode) goto FailSetConf; delay(5000); //rcode = pAsync->OnInit(this); //if (rcode) // goto FailOnInit; rcode = GetMaxLUN(&bMaxLUN); if (rcode) goto FailGetMaxLUN; delay(10); { InquiryResponse response; rcode = Inquiry(bMaxLUN, sizeof(InquiryResponse), (uint8_t*)&response); if (rcode) goto FailInquiry; //if (response.DeviceType != 0) // goto FailInvalidDevice; } delay(10); USBTRACE("MS configured\r\n"); bPollEnable = true; //USBTRACE("Poll enabled\r\n"); return 0; FailGetDevDescr: USBTRACE("getDevDescr:"); goto Fail; FailSetDevTblEntry: USBTRACE("setDevTblEn:"); goto Fail; FailGetConfDescr: USBTRACE("getConf:"); goto Fail; FailSetConf: USBTRACE("setConf:"); goto Fail; FailOnInit: USBTRACE("OnInit:"); goto Fail; FailGetMaxLUN: USBTRACE("GetMaxLUN:"); goto Fail; FailInquiry: USBTRACE("Inquiry:"); goto Fail; Fail: Serial.println(rcode, HEX); Release(); return rcode; }
uint8_t HIDUniversal::Init(uint8_t parent, uint8_t port, bool lowspeed) { const uint8_t constBufSize = sizeof(USB_DEVICE_DESCRIPTOR); uint8_t buf[constBufSize]; uint8_t rcode; UsbDevice *p = NULL; EpInfo *oldep_ptr = NULL; uint8_t len = 0; uint16_t cd_len = 0; uint8_t num_of_conf; // number of configurations uint8_t num_of_intf; // number of interfaces AddressPool &addrPool = pUsb->GetAddressPool(); USBTRACE("HU Init\r\n"); if (bAddress) return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; // Get pointer to pseudo device with address 0 assigned p = addrPool.GetUsbDevicePtr(0); if (!p) return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; if (!p->epinfo) { USBTRACE("epinfo\r\n"); return USB_ERROR_EPINFO_IS_NULL; } // Save old pointer to EP_RECORD of address 0 oldep_ptr = p->epinfo; // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence p->epinfo = epInfo; p->lowspeed = lowspeed; // Get device descriptor rcode = pUsb->getDevDescr( 0, 0, 8, (uint8_t*)buf ); if (!rcode) len = (buf[0] > constBufSize) ? constBufSize : buf[0]; if( rcode ) { // Restore p->epinfo p->epinfo = oldep_ptr; goto FailGetDevDescr; } // Restore p->epinfo p->epinfo = oldep_ptr; // Allocate new address according to device class bAddress = addrPool.AllocAddress(parent, false, port); if (!bAddress) return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL; // Extract Max Packet Size from the device descriptor epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0; // Assign new address to the device rcode = pUsb->setAddr( 0, 0, bAddress ); if (rcode) { p->lowspeed = false; addrPool.FreeAddress(bAddress); bAddress = 0; USBTRACE2("setAddr:",rcode); return rcode; } USBTRACE2("Addr:", bAddress); p->lowspeed = false; p = addrPool.GetUsbDevicePtr(bAddress); if (!p) return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; p->lowspeed = lowspeed; if (len) rcode = pUsb->getDevDescr( bAddress, 0, len, (uint8_t*)buf ); if(rcode) goto FailGetDevDescr; num_of_conf = ((USB_DEVICE_DESCRIPTOR*)buf)->bNumConfigurations; // Assign epInfo to epinfo pointer rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); if (rcode) goto FailSetDevTblEntry; USBTRACE2("NC:", num_of_conf); for (uint8_t i=0; i<num_of_conf; i++) { HexDumper<USBReadParser, uint16_t, uint16_t> HexDump; ConfigDescParser<USB_CLASS_HID, 0, 0, CP_MASK_COMPARE_CLASS> confDescrParser(this); rcode = pUsb->getConfDescr(bAddress, 0, i, &HexDump); rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser); if (bNumEP > 1) break; } // for if (bNumEP < 2) return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; // Assign epInfo to epinfo pointer rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo); USBTRACE2("\r\nCnf:", bConfNum); // Set Configuration Value //rcode = pUsb->setConf(bAddress, 0, 0); rcode = pUsb->setConf(bAddress, 0, bConfNum); if (rcode) goto FailSetConfDescr; for (uint8_t i=0; i<bNumIface; i++) { if (hidInterfaces[i].epIndex[epInterruptInIndex] == 0) continue; USBTRACE("Proto\r\n"); //rcode = SetProtocol(hidInterfaces[i].bmInterface, HID_RPT_PROTOCOL); //if (rcode) // goto FailSetProtocol; rcode = SetIdle(hidInterfaces[i].bmInterface, 0, 0); if (rcode) goto FailSetIdle; } USBTRACE("HU configured\r\n"); { HexDumper<USBReadParser, uint16_t, uint16_t> Hex; ReportDescParser Rpt; if (rcode = GetReportDescr(0, &Hex)) goto FailGetReportDescr; if (rcode = GetReportDescr(0, &Rpt)) goto FailGetReportDescr; } bPollEnable = true; return 0; FailGetDevDescr: USBTRACE("getDevDescr:"); goto Fail; FailSetDevTblEntry: USBTRACE("setDevTblEn:"); goto Fail; FailGetConfDescr: USBTRACE("getConf:"); goto Fail; FailSetConfDescr: USBTRACE("setConf:"); goto Fail; FailSetProtocol: USBTRACE("SetProto:"); goto Fail; FailSetIdle: USBTRACE("SetIdle:"); goto Fail; FailGetReportDescr: USBTRACE("GetReportDescr:"); goto Fail; Fail: Serial.println(rcode, HEX); Release(); return rcode; }
/* Connection initialization of an MIDI Device */ uint8_t GLUCODUINO::Init(uint8_t parent, uint8_t port, bool lowspeed) { uint8_t buf[DESC_BUFF_SIZE]; uint8_t rcode; UsbDevice *p = NULL; EpInfo *oldep_ptr = NULL; uint8_t num_of_conf; // number of configurations // get memory address of USB device address pool AddressPool &addrPool = pUsb->GetAddressPool(); #ifdef DEBUG USBTRACE("\rMIDI Init\r\n"); #endif //Serial.print("AddressPool"); //Serial.println(addrPool); // check if address has already been assigned to an instance if (bAddress) { return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; } // Get pointer to pseudo device with address 0 assigned p = addrPool.GetUsbDevicePtr(0); if (!p) { return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; } if (!p->epinfo) { return USB_ERROR_EPINFO_IS_NULL; } // Save old pointer to EP_RECORD of address 0 oldep_ptr = p->epinfo; // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence p->epinfo = epInfo; p->lowspeed = lowspeed; // Get device descriptor rcode = pUsb->getDevDescr( 0, 0, sizeof(USB_DEVICE_DESCRIPTOR), (uint8_t*)buf ); vid = (uint16_t)buf[8] + ((uint16_t)buf[9] << 8); pid = (uint16_t)buf[10] + ((uint16_t)buf[11] << 8); // Restore p->epinfo p->epinfo = oldep_ptr; if( rcode ){ goto FailGetDevDescr; } // Allocate new address according to device class //Serial.print("port = "); //Serial.println(port); //Serial.print("parent = "); //Serial.println(parent); bAddress = addrPool.AllocAddress(parent, false, port); if (!bAddress) { return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL; } //Serial.print("bAddress = "); //Serial.println(bAddress); // Extract Max Packet Size from device descriptor epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0; // Assign new address to the device rcode = pUsb->setAddr( 0, 0, bAddress ); if (rcode) { p->lowspeed = false; addrPool.FreeAddress(bAddress); bAddress = 0; return rcode; }//if (rcode... #ifdef DEBUG USBTRACE2("Addr:", bAddress); #endif p->lowspeed = false; //get pointer to assigned address record p = addrPool.GetUsbDevicePtr(bAddress); if (!p) { return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; } p->lowspeed = lowspeed; num_of_conf = ((USB_DEVICE_DESCRIPTOR*)buf)->bNumConfigurations; // Assign epInfo to epinfo pointer rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); if (rcode) { #ifdef DEBUG USBTRACE("setEpInfoEntry failed"); #endif goto FailSetDevTblEntry; } #ifdef DEBUG USBTRACE2("NC:", num_of_conf); #endif for (uint8_t i=0; i<num_of_conf; i++) { parseConfigDescr(bAddress, i); if (bNumEP > 1) break; } // for #ifdef DEBUG USBTRACE2("NumEP:", bNumEP); #endif if( bConfNum == 0 ){ //Device not found. goto FailGetConfDescr; } if( !isMidiFound ){ //MIDI Device not found. Try first Bulk transfer device epInfo[epDataInIndex].epAddr = 0x03;//03 instead of 83 as USB Host Sheild is low speed epInfo[epDataInIndex].maxPktSize = epInfo[epDataInIndexVSP].maxPktSize; epInfo[epDataOutIndex].epAddr = 0x04; epInfo[epDataOutIndex].maxPktSize = epInfo[epDataOutIndexVSP].maxPktSize; } // Assign epInfo to epinfo pointer rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo); #ifdef DEBUG USBTRACE2("Conf:", bConfNum); #endif // Set Configuration Value rcode = pUsb->setConf(bAddress, 0, bConfNum); if (rcode) { goto FailSetConfDescr; } #ifdef DEBUG USBTRACE("Init done."); #endif bPollEnable = true; return 0; FailGetDevDescr: FailSetDevTblEntry: FailGetConfDescr: FailSetConfDescr: Release(); return rcode; }
uint8_t PL2303::Init(uint8_t parent, uint8_t port, bool lowspeed) { const uint8_t constBufSize = sizeof (USB_DEVICE_DESCRIPTOR); uint8_t buf[constBufSize]; USB_DEVICE_DESCRIPTOR * udd = reinterpret_cast<USB_DEVICE_DESCRIPTOR*>(buf); uint8_t rcode; UsbDevice *p = NULL; EpInfo *oldep_ptr = NULL; uint8_t num_of_conf; // number of configurations enum pl2303_type pltype = unknown; AddressPool &addrPool = pUsb->GetAddressPool(); USBTRACE("PL Init\r\n"); if(bAddress) return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; // Get pointer to pseudo device with address 0 assigned p = addrPool.GetUsbDevicePtr(0); if(!p) return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; if(!p->epinfo) { USBTRACE("epinfo\r\n"); return USB_ERROR_EPINFO_IS_NULL; } // Save old pointer to EP_RECORD of address 0 oldep_ptr = p->epinfo; // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence p->epinfo = epInfo; p->lowspeed = lowspeed; // Get device descriptor rcode = pUsb->getDevDescr(0, 0, sizeof (USB_DEVICE_DESCRIPTOR), (uint8_t*)buf); // Restore p->epinfo p->epinfo = oldep_ptr; if(rcode) goto FailGetDevDescr; if(udd->idVendor != PL_VID && udd->idProduct != PL_PID) return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; /* determine chip variant */ if (udd->bDeviceClass == 0x02 ) { pltype = type_0; } else if (udd->bMaxPacketSize0 == 0x40 ) { pltype = rev_HX; } else if (udd->bDeviceClass == 0x00) { pltype = type_1; } else if (udd->bDeviceClass == 0xff) { pltype = type_1; } // Save type of PL chip wPLType = udd->bcdDevice; // Allocate new address according to device class bAddress = addrPool.AllocAddress(parent, false, port); if(!bAddress) return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL; // Extract Max Packet Size from the device descriptor epInfo[0].maxPktSize = udd->bMaxPacketSize0; // Assign new address to the device rcode = pUsb->setAddr(0, 0, bAddress); if(rcode) { p->lowspeed = false; addrPool.FreeAddress(bAddress); bAddress = 0; USBTRACE2("setAddr:", rcode); return rcode; } USBTRACE2("Addr:", bAddress); p->lowspeed = false; p = addrPool.GetUsbDevicePtr(bAddress); if(!p) return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; p->lowspeed = lowspeed; num_of_conf = udd->bNumConfigurations; // Assign epInfo to epinfo pointer rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); if(rcode) goto FailSetDevTblEntry; USBTRACE2("NC:", num_of_conf); for(uint8_t i = 0; i < num_of_conf; i++) { HexDumper<USBReadParser, uint16_t, uint16_t> HexDump; ConfigDescParser < 0xFF, 0, 0, CP_MASK_COMPARE_CLASS> confDescrParser(this); rcode = pUsb->getConfDescr(bAddress, 0, i, &HexDump); if(rcode) goto FailGetConfDescr; rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser); if(rcode) goto FailGetConfDescr; if(bNumEP > 1) break; } // for if(bNumEP < 2) return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; // Assign epInfo to epinfo pointer rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo); USBTRACE2("Conf:", bConfNum); // Set Configuration Value rcode = pUsb->setConf(bAddress, 0, bConfNum); if(rcode) goto FailSetConfDescr; #if defined(PL2303_COMPAT) /* shamanic dance - sending Prolific init data as-is */ vendorRead( 0x84, 0x84, 0, buf ); vendorWrite( 0x04, 0x04, 0 ); vendorRead( 0x84, 0x84, 0, buf ); vendorRead( 0x83, 0x83, 0, buf ); vendorRead( 0x84, 0x84, 0, buf ); vendorWrite( 0x04, 0x04, 1 ); vendorRead( 0x84, 0x84, 0, buf); vendorRead( 0x83, 0x83, 0, buf); vendorWrite( 0, 0, 1 ); vendorWrite( 1, 0, 0 ); if ( pltype == rev_HX ) { vendorWrite( 2, 0, 0x44 ); vendorWrite( 0x06, 0x06, 0 ); //from W7 init } else { vendorWrite( 2, 0, 0x24 ); } /* shamanic dance end */ #endif /* calling post-init callback */ rcode = pAsync->OnInit(this); if(rcode) goto FailOnInit; USBTRACE("PL configured\r\n"); //bPollEnable = true; ready = true; return 0; FailGetDevDescr: #ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: #ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: #ifdef DEBUG_USB_HOST NotifyFailGetConfDescr(); goto Fail; #endif FailSetConfDescr: #ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailOnInit: #ifdef DEBUG_USB_HOST USBTRACE("OnInit:"); #endif #ifdef DEBUG_USB_HOST Fail: NotifyFail(rcode); #endif Release(); return rcode; }
uint8_t ReportDescParser2::ParseItem(uint8_t **pp, uint16_t *pcntdn) { //uint8_t ret = enErrorSuccess; switch (itemParseState) { case 0: if (**pp == HID_LONG_ITEM_PREFIX) USBTRACE("\r\nLONG\r\n"); else { uint8_t size = ((**pp) & DATA_SIZE_MASK); itemPrefix = (**pp); itemSize = 1 + ((size == DATA_SIZE_4) ? 4 : size); } (*pp)++; (*pcntdn)--; itemSize--; itemParseState = 1; if (!itemSize) break; if (!pcntdn) return enErrorIncomplete; case 1: theBuffer.valueSize = itemSize; valParser.Initialize(&theBuffer); itemParseState = 2; case 2: if (!valParser.Parse(pp, pcntdn)) return enErrorIncomplete; itemParseState = 3; case 3: { uint8_t data = *((uint8_t*)varBuffer); switch (itemPrefix & (TYPE_MASK | TAG_MASK)) { case (TYPE_LOCAL | TAG_LOCAL_USAGE): if (pfUsage) { if (theBuffer.valueSize > 1) pfUsage(*((uint16_t*)varBuffer)); else pfUsage(data); } break; case (TYPE_GLOBAL | TAG_GLOBAL_REPORTSIZE): rptSize = data; break; case (TYPE_GLOBAL | TAG_GLOBAL_REPORTCOUNT): rptCount = data; break; case (TYPE_GLOBAL | TAG_GLOBAL_REPORTID): rptId = data; break; case (TYPE_LOCAL | TAG_LOCAL_USAGEMIN): useMin = data; break; case (TYPE_LOCAL | TAG_LOCAL_USAGEMAX): useMax = data; break; case (TYPE_GLOBAL | TAG_GLOBAL_USAGEPAGE): SetUsagePage(data); break; case (TYPE_MAIN | TAG_MAIN_OUTPUT): case (TYPE_MAIN | TAG_MAIN_FEATURE): rptSize = 0; rptCount = 0; useMin = 0; useMax = 0; break; case (TYPE_MAIN | TAG_MAIN_INPUT): OnInputItem(data); totalSize += (uint16_t)rptSize * (uint16_t)rptCount; rptSize = 0; rptCount = 0; useMin = 0; useMax = 0; break; } // switch (**pp & (TYPE_MASK | TAG_MASK)) } } // switch (itemParseState) itemParseState = 0; return enErrorSuccess; }
uint8_t ReportDescParserBase::ParseItem(uint8_t **pp, uint16_t *pcntdn) { //uint8_t ret = enErrorSuccess; switch (itemParseState) { case 0: if (**pp == HID_LONG_ITEM_PREFIX) USBTRACE("\r\nLONG\r\n"); else { uint8_t size = ((**pp) & DATA_SIZE_MASK); itemPrefix = (**pp); itemSize = 1 + ((size == DATA_SIZE_4) ? 4 : size); PrintItemTitle(itemPrefix); } (*pp)++; (*pcntdn)--; itemSize--; itemParseState = 1; if (!itemSize) break; if (!pcntdn) return enErrorIncomplete; case 1: //USBTRACE2("\r\niSz:",itemSize); theBuffer.valueSize = itemSize; valParser.Initialize(&theBuffer); itemParseState = 2; case 2: if (!valParser.Parse(pp, pcntdn)) return enErrorIncomplete; itemParseState = 3; case 3: { uint8_t data = *((uint8_t*)varBuffer); switch (itemPrefix & (TYPE_MASK | TAG_MASK)) { case (TYPE_LOCAL | TAG_LOCAL_USAGE): if (pfUsage) { if (theBuffer.valueSize > 1) pfUsage(*((uint16_t*)varBuffer)); else pfUsage(data); } break; case (TYPE_GLOBAL | TAG_GLOBAL_REPORTSIZE): rptSize = data; PrintByteValue(data); break; case (TYPE_GLOBAL | TAG_GLOBAL_REPORTCOUNT): rptCount = data; PrintByteValue(data); break; case (TYPE_GLOBAL | TAG_GLOBAL_LOGICALMIN): case (TYPE_GLOBAL | TAG_GLOBAL_LOGICALMAX): case (TYPE_GLOBAL | TAG_GLOBAL_PHYSMIN): case (TYPE_GLOBAL | TAG_GLOBAL_PHYSMAX): case (TYPE_GLOBAL | TAG_GLOBAL_REPORTID): case (TYPE_LOCAL | TAG_LOCAL_USAGEMIN): case (TYPE_LOCAL | TAG_LOCAL_USAGEMAX): case (TYPE_GLOBAL | TAG_GLOBAL_UNITEXP): case (TYPE_GLOBAL | TAG_GLOBAL_UNIT): PrintValue(varBuffer, theBuffer.valueSize); break; case (TYPE_GLOBAL | TAG_GLOBAL_PUSH): case (TYPE_GLOBAL | TAG_GLOBAL_POP): break; case (TYPE_GLOBAL | TAG_GLOBAL_USAGEPAGE): SetUsagePage(data); PrintUsagePage(data); PrintByteValue(data); break; case (TYPE_MAIN | TAG_MAIN_COLLECTION): case (TYPE_MAIN | TAG_MAIN_ENDCOLLECTION): switch (data) { case 0x00: E_Notify(PSTR(" Physical"), 0x80); break; case 0x01: E_Notify(PSTR(" Application"), 0x80); break; case 0x02: E_Notify(PSTR(" Logical"), 0x80); break; case 0x03: E_Notify(PSTR(" Report"), 0x80); break; case 0x04: E_Notify(PSTR(" Named Array"), 0x80); break; case 0x05: E_Notify(PSTR(" Usage Switch"), 0x80); break; case 0x06: E_Notify(PSTR(" Usage Modifier"), 0x80); break; default: E_Notify(PSTR(" Vendor Defined("), 0x80); PrintHex<uint8_t > (data, 0x80); E_Notify(PSTR(")"), 0x80); } break; case (TYPE_MAIN | TAG_MAIN_INPUT): case (TYPE_MAIN | TAG_MAIN_OUTPUT): case (TYPE_MAIN | TAG_MAIN_FEATURE): totalSize += (uint16_t)rptSize * (uint16_t)rptCount; rptSize = 0; rptCount = 0; E_Notify(PSTR("("), 0x80); PrintBin<uint8_t > (data, 0x80); E_Notify(PSTR(")"), 0x80); break; } // switch (**pp & (TYPE_MASK | TAG_MASK)) } } // switch (itemParseState) itemParseState = 0; return enErrorSuccess; }
uint32_t USBHub::Init(uint32_t parent, uint32_t port, uint32_t lowspeed) { uint8_t buf[32]; USB_DEVICE_DESCRIPTOR * udd = reinterpret_cast<USB_DEVICE_DESCRIPTOR*>(buf); HubDescriptor* hd = reinterpret_cast<HubDescriptor*>(buf); USB_CONFIGURATION_DESCRIPTOR * ucd = reinterpret_cast<USB_CONFIGURATION_DESCRIPTOR*>(buf); uint32_t rcode; UsbDeviceDefinition *p = NULL; EpInfo *oldep_ptr = NULL; uint32_t len = 0; uint32_t cd_len = 0; //USBTRACE("\r\nHub Init Start "); //D_PrintHex<uint8_t > (bInitState, 0x80); AddressPool &addrPool = pUsb->GetAddressPool(); //switch (bInitState) { // case 0: if(bAddress) return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; // Get pointer to pseudo device with address 0 assigned p = addrPool.GetUsbDevicePtr(0); if(!p) return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; if(!p->epinfo) return USB_ERROR_EPINFO_IS_NULL; // Save old pointer to EP_RECORD of address 0 oldep_ptr = p->epinfo; // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence p->epinfo = epInfo; p->lowspeed = lowspeed; // Get device descriptor rcode = pUsb->getDevDescr(0, 0, 8, (uint8_t*)buf); p->lowspeed = false; if(!rcode) len = (buf[0] > 32) ? 32 : buf[0]; if(rcode) { // Restore p->epinfo p->epinfo = oldep_ptr; return rcode; } // Extract device class from device descriptor // If device class is not a hub return if(udd->bDeviceClass != 0x09) return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; // Allocate new address according to device class bAddress = addrPool.AllocAddress(parent, (udd->bDeviceClass == 0x09) ? true : false, port); if(!bAddress) return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL; // Extract Max Packet Size from the device descriptor epInfo[0].maxPktSize = udd->bMaxPacketSize0; // Assign new address to the device rcode = pUsb->setAddr(0, 0, bAddress); if(rcode) { // Restore p->epinfo p->epinfo = oldep_ptr; addrPool.FreeAddress(bAddress); bAddress = 0; return rcode; } //USBTRACE2("\r\nHub address: ", bAddress ); // Restore p->epinfo p->epinfo = oldep_ptr; if(len) rcode = pUsb->getDevDescr(bAddress, 0, len, (uint8_t*)buf); if(rcode) goto FailGetDevDescr; // Assign epInfo to epinfo pointer rcode = pUsb->setEpInfoEntry(bAddress, 2, epInfo); if(rcode) goto FailSetDevTblEntry; // bInitState = 1; // case 1: // Get hub descriptor rcode = GetHubDescriptor(0, 8, buf); if(rcode) goto FailGetHubDescr; // Save number of ports for future use bNbrPorts = hd->bNbrPorts; // bInitState = 2; // case 2: // Read configuration Descriptor in Order To Obtain Proper Configuration Value rcode = pUsb->getConfDescr(bAddress, 0, 8, 0, buf); if(!rcode) { cd_len = ucd->wTotalLength; rcode = pUsb->getConfDescr(bAddress, 0, cd_len, 0, buf); } if(rcode) goto FailGetConfDescr; // The following code is of no practical use in real life applications. // It only intended for the usb protocol sniffer to properly parse hub-class requests. { uint8_t buf2[24]; rcode = pUsb->getConfDescr(bAddress, 0, buf[0], 0, buf2); if(rcode) goto FailGetConfDescr; } // Set Configuration Value rcode = pUsb->setConf(bAddress, 0, buf[5]); if(rcode) goto FailSetConfDescr; // bInitState = 3; // case 3: // Power on all ports for(uint32_t j = 1; j <= bNbrPorts; j++) SetPortFeature(HUB_FEATURE_PORT_POWER, j, 0); //HubPortPowerOn(j); pUsb->SetHubPreMask(); bPollEnable = true; // bInitState = 0; //} //bInitState = 0; //USBTRACE("...OK\r\n"); return 0; // Oleg, No debugging?? -- xxxajk FailGetDevDescr: goto Fail; FailSetDevTblEntry: goto Fail; FailGetHubDescr: goto Fail; FailGetConfDescr: goto Fail; FailSetConfDescr: goto Fail; Fail: USBTRACE("...FAIL\r\n"); return rcode; }
/** * USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET == success * We need to standardize either the rcode, or change the API to return values * so a signal that additional actions are required can be produced. * Some of these codes do exist already. * * TECHNICAL: We could do most of this code elsewhere, with the exception of checking the class instance. * Doing so would save some program memory when using multiple drivers. * * @param parent USB address of parent * @param port address of port on parent * @param lowspeed true if device is low speed * @return */ uint8_t BulkOnly::ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed) { const uint8_t constBufSize = sizeof (USB_DEVICE_DESCRIPTOR); uint8_t buf[constBufSize]; USB_DEVICE_DESCRIPTOR * udd = reinterpret_cast<USB_DEVICE_DESCRIPTOR*>(buf); uint8_t rcode; UsbDevice *p = NULL; EpInfo *oldep_ptr = NULL; USBTRACE("MS ConfigureDevice\r\n"); ClearAllEP(); AddressPool &addrPool = pUsb->GetAddressPool(); if(bAddress) return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; // <TECHNICAL> // Get pointer to pseudo device with address 0 assigned p = addrPool.GetUsbDevicePtr(0); if(!p) { return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; } if(!p->epinfo) { USBTRACE("epinfo\r\n"); return USB_ERROR_EPINFO_IS_NULL; } // Save old pointer to EP_RECORD of address 0 oldep_ptr = p->epinfo; // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence p->epinfo = epInfo; p->lowspeed = lowspeed; // Get device descriptor rcode = pUsb->getDevDescr(0, 0, constBufSize, (uint8_t*)buf); // Restore p->epinfo p->epinfo = oldep_ptr; if(rcode) { goto FailGetDevDescr; } // Allocate new address according to device class bAddress = addrPool.AllocAddress(parent, false, port); if(!bAddress) return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL; // Extract Max Packet Size from the device descriptor epInfo[0].maxPktSize = udd->bMaxPacketSize0; // Steal and abuse from epInfo structure to save on memory. epInfo[1].epAddr = udd->bNumConfigurations; // </TECHNICAL> return USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET; FailGetDevDescr: #ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(rcode); #endif rcode = USB_ERROR_FailGetDevDescr; Release(); return rcode; };
/* Connection initialization of an Android phone */ uint8_t ADK::Init(uint8_t parent, uint8_t port, bool lowspeed) { uint8_t buf[sizeof (USB_DEVICE_DESCRIPTOR)]; uint8_t rcode; uint8_t num_of_conf; // number of configurations UsbDevice *p = NULL; EpInfo *oldep_ptr = NULL; // get memory address of USB device address pool AddressPool &addrPool = pUsb->GetAddressPool(); USBTRACE("\r\nADK Init"); // check if address has already been assigned to an instance if (bAddress) { USBTRACE("\r\nAddress in use"); return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; } // Get pointer to pseudo device with address 0 assigned p = addrPool.GetUsbDevicePtr(0); if (!p) { USBTRACE("\r\nAddress not found"); return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; } if (!p->epinfo) { USBTRACE("epinfo is null\r\n"); return USB_ERROR_EPINFO_IS_NULL; } // Save old pointer to EP_RECORD of address 0 oldep_ptr = p->epinfo; // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence p->epinfo = epInfo; p->lowspeed = lowspeed; // Get device descriptor rcode = pUsb->getDevDescr(0, 0, sizeof (USB_DEVICE_DESCRIPTOR), (uint8_t*)buf); // Restore p->epinfo p->epinfo = oldep_ptr; if (rcode) { goto FailGetDevDescr; } // Allocate new address according to device class bAddress = addrPool.AllocAddress(parent, false, port); // Extract Max Packet Size from device descriptor epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0; // Assign new address to the device rcode = pUsb->setAddr(0, 0, bAddress); if (rcode) { p->lowspeed = false; addrPool.FreeAddress(bAddress); bAddress = 0; //USBTRACE2("setAddr:",rcode); return rcode; }//if (rcode... //USBTRACE2("\r\nAddr:", bAddress); // Spec says you should wait at least 200ms. delay(300); p->lowspeed = false; //get pointer to assigned address record p = addrPool.GetUsbDevicePtr(bAddress); if (!p) { return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; } p->lowspeed = lowspeed; // Assign epInfo to epinfo pointer - only EP0 is known rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); if (rcode) { goto FailSetDevTblEntry; } //check if ADK device is already in accessory mode; if yes, configure and exit if (((USB_DEVICE_DESCRIPTOR*)buf)->idVendor == ADK_VID && (((USB_DEVICE_DESCRIPTOR*)buf)->idProduct == ADK_PID || ((USB_DEVICE_DESCRIPTOR*)buf)->idProduct == ADB_PID)) { USBTRACE("\r\nAcc.mode device detected"); /* go through configurations, find first bulk-IN, bulk-OUT EP, fill epInfo and quit */ num_of_conf = ((USB_DEVICE_DESCRIPTOR*)buf)->bNumConfigurations; //USBTRACE2("\r\nNC:",num_of_conf); for (uint8_t i = 0; i < num_of_conf; i++) { ConfigDescParser < 0, 0, 0, 0 > confDescrParser(this); rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser); if (rcode) { goto FailGetConfDescr; } if (bNumEP > 2) { break; } } // for (uint8_t i=0; i<num_of_conf; i++... if (bNumEP == 3) { // Assign epInfo to epinfo pointer - this time all 3 endpoins rcode = pUsb->setEpInfoEntry(bAddress, 3, epInfo); if (rcode) { goto FailSetDevTblEntry; } } // Set Configuration Value rcode = pUsb->setConf(bAddress, 0, bConfNum); if (rcode) { goto FailSetConfDescr; } /* print endpoint structure */ // USBTRACE("\r\nEndpoint Structure:"); // USBTRACE("\r\nEP0:"); // USBTRACE2("\r\nAddr: ", epInfo[0].epAddr ); // USBTRACE2("\r\nMax.pkt.size: ", epInfo[0].maxPktSize ); // USBTRACE2("\r\nAttr: ", epInfo[0].epAttribs ); // USBTRACE("\r\nEpout:"); // USBTRACE2("\r\nAddr: ", epInfo[epDataOutIndex].epAddr ); // USBTRACE2("\r\nMax.pkt.size: ", epInfo[epDataOutIndex].maxPktSize ); // USBTRACE2("\r\nAttr: ", epInfo[epDataOutIndex].epAttribs ); // USBTRACE("\r\nEpin:"); // USBTRACE2("\r\nAddr: ", epInfo[epDataInIndex].epAddr ); // USBTRACE2("\r\nMax.pkt.size: ", epInfo[epDataInIndex].maxPktSize ); // USBTRACE2("\r\nAttr: ", epInfo[epDataInIndex].epAttribs ); USBTRACE("\r\nConfiguration successful"); ready = true; return 0; //successful configuration }//if( buf->idVendor == ADK_VID... //probe device - get accessory protocol revision { uint16_t adkproto = -1; rcode = getProto((uint8_t*) & adkproto); if (rcode) { goto FailGetProto; //init fails } USBTRACE2("\r\nADK protocol rev. ", adkproto); } //sending ID strings sendStr(ACCESSORY_STRING_MANUFACTURER, manufacturer); sendStr(ACCESSORY_STRING_MODEL, model); sendStr(ACCESSORY_STRING_DESCRIPTION, description); sendStr(ACCESSORY_STRING_VERSION, version); sendStr(ACCESSORY_STRING_URI, uri); sendStr(ACCESSORY_STRING_SERIAL, serial); //switch to accessory mode //the Android phone will reset rcode = switchAcc(); if (rcode) { goto FailSwAcc; //init fails } rcode = USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET; delay(1000); // Give Android a chance to do its reset. This is a guess, and possibly could be lower. goto SwAttempt; //switch to accessory mode attempted /* diagnostic messages */ FailGetDevDescr: #ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(rcode); goto Fail; #endif FailSetDevTblEntry: #ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(rcode); goto Fail; #endif FailGetConfDescr: #ifdef DEBUG_USB_HOST NotifyFailGetConfDescr(rcode); goto Fail; #endif FailSetConfDescr: #ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(rcode); goto Fail; #endif FailGetProto: #ifdef DEBUG_USB_HOST USBTRACE("\r\ngetProto:"); goto Fail; #endif FailSwAcc: #ifdef DEBUG_USB_HOST USBTRACE("\r\nswAcc:"); goto Fail; #endif SwAttempt: #ifdef DEBUG_USB_HOST USBTRACE("\r\nAccessory mode switch attempt"); #endif //FailOnInit: // USBTRACE("OnInit:"); // goto Fail; // Fail: //USBTRACE2("\r\nADK Init Failed, error code: ", rcode); //NotifyFail(rcode); Release(); return rcode; }
/** * * @param parent (not used) * @param port (not used) * @param lowspeed true if device is low speed * @return 0 for success */ uint8_t BulkOnly::Init(uint8_t parent, uint8_t port, bool lowspeed) { uint8_t rcode; uint8_t num_of_conf = epInfo[1].epAddr; // number of configurations epInfo[1].epAddr = 0; USBTRACE("MS Init\r\n"); AddressPool &addrPool = pUsb->GetAddressPool(); UsbDevice *p = addrPool.GetUsbDevicePtr(bAddress); if (!p) return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; // Assign new address to the device delay(2000); rcode = pUsb->setAddr(0, 0, bAddress); if (rcode) { p->lowspeed = false; addrPool.FreeAddress(bAddress); bAddress = 0; USBTRACE2("setAddr:", rcode); return rcode; } USBTRACE2("Addr:", bAddress); p->lowspeed = false; p = addrPool.GetUsbDevicePtr(bAddress); if (!p) return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; p->lowspeed = lowspeed; // Assign epInfo to epinfo pointer rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); if (rcode) goto FailSetDevTblEntry; USBTRACE2("NC:", num_of_conf); for (uint8_t i = 0; i < num_of_conf; i++) { ConfigDescParser< USB_CLASS_MASS_STORAGE, MASS_SUBCLASS_SCSI, MASS_PROTO_BBB, CP_MASK_COMPARE_CLASS | CP_MASK_COMPARE_SUBCLASS | CP_MASK_COMPARE_PROTOCOL > BulkOnlyParser(this); rcode = pUsb->getConfDescr(bAddress, 0, i, &BulkOnlyParser); if (rcode) goto FailGetConfDescr; if (bNumEP > 1) break; } // for if (bNumEP < 3) return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; // Assign epInfo to epinfo pointer pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo); USBTRACE2("Conf:", bConfNum); // Set Configuration Value rcode = pUsb->setConf(bAddress, 0, bConfNum); if (rcode) goto FailSetConfDescr; //Linux does a 1sec delay after this. delay(1000); rcode = GetMaxLUN(&bMaxLUN); if (rcode) goto FailGetMaxLUN; if (bMaxLUN >= MASS_MAX_SUPPORTED_LUN) bMaxLUN = MASS_MAX_SUPPORTED_LUN - 1; ErrorMessage<uint8_t > (PSTR("MaxLUN"), bMaxLUN); delay(1000); // Delay a bit for slow firmware. //bTheLUN = bMaxLUN; for (uint8_t lun = 0; lun <= bMaxLUN; lun++) { InquiryResponse response; rcode = Inquiry(lun, sizeof (InquiryResponse), (uint8_t*) & response); if (rcode) { ErrorMessage<uint8_t > (PSTR("Inquiry"), rcode); } else { uint8_t tries = 0xf0; while (rcode = TestUnitReady(lun)) { if (rcode == 0x08) break; // break on no media, this is OK to do. // try to lock media and spin up if (tries < 14) { LockMedia(lun, 1); MediaCTL(lun, 1); // I actually have a USB stick that needs this! } else delay(2 * (tries + 1)); tries++; if (!tries) break; } if (!rcode) { delay(1000); LUNOk[lun] = CheckLUN(lun); if (!LUNOk[lun]) LUNOk[lun] = CheckLUN(lun); } } } #if 0 { bool good; for (uint8_t i = 1; i == 0; i++) { good = false; CheckMedia(); for (uint8_t lun = 0; lun <= bMaxLUN; lun++) good |= LUNOk[lun]; if (good) break; delay(118); // 255 loops =~ 30 seconds to allow for spin up, as per SCSI spec. } } #else CheckMedia(); #endif rcode = OnInit(); if (rcode) goto FailOnInit; USBTRACE("MS configured\r\n\r\n"); bPollEnable = true; //USBTRACE("Poll enabled\r\n"); return 0; FailSetConfDescr: #ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailOnInit: #ifdef DEBUG_USB_HOST USBTRACE("OnInit:"); goto Fail; #endif FailGetMaxLUN: #ifdef DEBUG_USB_HOST USBTRACE("GetMaxLUN:"); goto Fail; #endif FailInvalidSectorSize: #ifdef DEBUG_USB_HOST USBTRACE("Sector Size is NOT VALID: "); goto Fail; #endif FailSetDevTblEntry: #ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: #ifdef DEBUG_USB_HOST NotifyFailGetConfDescr(); #endif Fail: #ifdef DEBUG_USB_HOST NotifyFail(rcode); #endif Release(); return rcode; }