Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: CAN HTTPClient MODSERIAL MyThings Pyrn3GModem Socket TinyGPS MyUSBHost lwip-sys lwip mbed-rtos mbed-src
HuaweiE372DongleInitializer.cpp
00001 00002 #include "HuaweiE372DongleInitializer.h" 00003 00004 #define __DEBUG__ 5 00005 #ifndef __MODULE__ 00006 #define __MODULE__ "MyThread.cpp" 00007 #endif 00008 #include "MyDebug.h" 00009 00010 #define VENDSPEC_CLASS 0xFF 00011 00012 //Huawei E372 (Vodafone) 00013 00014 // switch string => "55 53 42 43 00 00 00 00 00 00 00 00 00 00 00 11 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00" 00015 static uint8_t huawei_E372_switch_packet[] = { 00016 0x55, 0x53, 0x42, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00017 0x11, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 00018 0x00 00019 }; 00020 00021 HuaweiE372DongleInitializer::HuaweiE372DongleInitializer(USBHost *h): WANDongleInitializer(h) { 00022 00023 } 00024 00025 bool HuaweiE372DongleInitializer::switchMode(USBDeviceConnected* pDev) { 00026 for (int i = 0; i < pDev->getNbIntf(); i++) { 00027 if (pDev->getInterface(i)->intf_class == MSD_CLASS) { 00028 USBEndpoint* pEp = pDev->getEndpoint(i, BULK_ENDPOINT, OUT); 00029 if ( pEp != NULL ) { 00030 USB_DBG("MSD descriptor found on device %p, intf %d, will now try to switch into serial mode", (void *)pDev, i); 00031 m_pHost->bulkWrite(pDev, pEp, huawei_E372_switch_packet, 31); 00032 return true; 00033 } 00034 } 00035 } 00036 return false; 00037 } 00038 00039 USBEndpoint* HuaweiE372DongleInitializer::getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx) { 00040 return pDev->getEndpoint(serialPortNumber, BULK_ENDPOINT, tx ? OUT : IN, 0); 00041 } 00042 00043 void HuaweiE372DongleInitializer::setVidPid(uint16_t vid, uint16_t pid) { 00044 if( (vid == getSerialVid()) && (pid == getSerialPid()) ) { 00045 m_hasSwitched = true; 00046 m_currentSerialIntf = 0; 00047 m_endpointsToFetch = 4*2; 00048 } else { 00049 m_hasSwitched = false; 00050 m_endpointsToFetch = 1; 00051 } 00052 } 00053 00054 bool HuaweiE372DongleInitializer::parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) { 00055 if( m_hasSwitched ) { 00056 USB_DBG("Interface #%d; Class:%02x; SubClass:%02x; Protocol:%02x", intf_nb, intf_class, intf_subclass, intf_protocol); 00057 if( intf_class == VENDSPEC_CLASS ) { 00058 // The first 4 Interfaces are parsable. 00059 if( m_currentSerialIntf <4 ) { 00060 m_currentSerialIntf++; 00061 return true; 00062 } 00063 m_currentSerialIntf++; 00064 } 00065 } else { 00066 // The first 2 Interface are parsable. 00067 if( ((intf_nb == 0) || (intf_nb == 1)) && (intf_class == MSD_CLASS) ) { 00068 return true; 00069 } 00070 } 00071 return false; 00072 } 00073 00074 bool HuaweiE372DongleInitializer::useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) {//Must return true if the endpoint will be used 00075 if( m_hasSwitched ) { 00076 USB_DBG("USBEndpoint on Inteface #%d; Type:%d; Direction:%d", intf_nb, type, dir); 00077 if( (type == BULK_ENDPOINT) && m_endpointsToFetch ) { 00078 m_endpointsToFetch--; 00079 return true; 00080 } 00081 } else { 00082 if( (type == BULK_ENDPOINT) && (dir == OUT) && m_endpointsToFetch ) { 00083 m_endpointsToFetch--; 00084 return true; 00085 } 00086 } 00087 return false; 00088 }
Generated on Wed Jul 13 2022 02:07:11 by
1.7.2