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.
Fork of USBHostWANDongle by
Diff: USB3GModule/WANDongleInitializer.cpp
- Revision:
- 8:0d1ec493842c
- Parent:
- 6:075e36a3463e
- Child:
- 9:c9e9817c398c
--- a/USB3GModule/WANDongleInitializer.cpp Sat Jul 28 14:15:14 2012 +0000 +++ b/USB3GModule/WANDongleInitializer.cpp Mon Jul 30 13:51:34 2012 +0000 @@ -16,7 +16,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#define __DEBUG__ 4 //Maximum verbosity +#define __DEBUG__ 0 //Maximum verbosity #ifndef __MODULE__ #define __MODULE__ "WANDongleInitializer.cpp" #endif @@ -36,7 +36,8 @@ WANDongleInitializer** WANDongleInitializer::getInitializers(USBHost* pHost) { static VodafoneK3770Initializer vodafoneK3770(pHost); - const static WANDongleInitializer* list[] = { &vodafoneK3770, NULL }; + static VodafoneK3772ZInitializer vodafoneK3772Z(pHost); + const static WANDongleInitializer* list[] = { &vodafoneK3770, &vodafoneK3772Z, NULL }; return (WANDongleInitializer**)list; } @@ -46,14 +47,6 @@ 0x55, 0x53, 0x42, 0x43, 0x12, 0x34, 0x56, 0x78, 0, 0, 0, 0, 0, 0, 0, 0x11, 0x06, 0x20, 0, 0, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -// NVIDIA (ICERA) /ZTE K3772-Z (Vodafone) -// Switching from mass storage device string is: "55 53 42 43 12 34 56 78 00 00 00 00 00 00 06 1b 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00" -static uint8_t vodafone_k3772_z_switch_packet[] = { - 0x55, 0x53, 0x42, 0x43, 0x12, 0x34, 0x56, 0x78, 0, 0, 0, 0, 0, 0, 0x06, 0x1b, 0, 0, 0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - - - VodafoneK3770Initializer::VodafoneK3770Initializer(USBHost* pHost) : WANDongleInitializer(pHost) { @@ -152,3 +145,121 @@ } return false; } + +/*virtual*/ WAN_DONGLE_TYPE VodafoneK3770Initializer::getType() +{ + return WAN_DONGLE_TYPE_VODAFONEK3770; +} + +// NVIDIA (ICERA) /ZTE K3772-Z (Vodafone) +// Switching from mass storage device string is: "55 53 42 43 12 34 56 78 00 00 00 00 00 00 06 1b 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00" +static uint8_t vodafone_k3772_z_switch_packet[] = { + 0x55, 0x53, 0x42, 0x43, 0x12, 0x34, 0x56, 0x78, 0, 0, 0, 0, 0, 0, 0x06, 0x1b, 0, 0, 0, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +VodafoneK3772ZInitializer::VodafoneK3772ZInitializer(USBHost* pHost) : WANDongleInitializer(pHost) +{ + +} + +uint16_t VodafoneK3772ZInitializer::getMSDVid() { return 0x19D2; } +uint16_t VodafoneK3772ZInitializer::getMSDPid() { return 0x1179; } + +uint16_t VodafoneK3772ZInitializer::getSerialVid() { return 0x19D2; } +uint16_t VodafoneK3772ZInitializer::getSerialPid() { return 0x1181; } + +bool VodafoneK3772ZInitializer::switchMode(USBDeviceConnected* pDev) +{ + for (int i = 0; i < pDev->getNbInterface(); i++) + { + if (pDev->getInterface(i)->intf_class == MSD_CLASS) + { + Endpoint* pEp = pDev->getEndpoint(i, BULK_ENDPOINT, OUT); + if ( pEp != NULL ) + { + DBG("MSD descriptor found on device %p, intf %d, will now try to switch into serial mode", (void *)pDev, i); + m_pHost->bulkWrite(pDev, pEp, vodafone_k3772_z_switch_packet, 31); + return true; + } + } + } + return false; +} + +Endpoint* VodafoneK3772ZInitializer::getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx) +{ + return pDev->getEndpoint((serialPortNumber==1)?0:1, BULK_ENDPOINT, tx?OUT:IN, 0); +} + +int VodafoneK3772ZInitializer::getSerialPortCount() +{ + return 2; +} + +/*virtual*/ void VodafoneK3772ZInitializer::setVidPid(uint16_t vid, uint16_t pid) +{ + if( (vid == getSerialVid() ) && ( pid == getSerialPid() ) ) + { + m_hasSwitched = true; + m_currentSerialIntf = 0; + m_endpointsToFetch = 4; + } + else + { + m_hasSwitched = false; + m_endpointsToFetch = 1; + } +} + +/*virtual*/ bool VodafoneK3772ZInitializer::parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) //Must return true if the interface should be parsed +{ + if( m_hasSwitched ) + { + DBG("Interface #%d; Class:%02x; SubClass:%02x; Protocol:%02x", intf_nb, intf_class, intf_subclass, intf_protocol); + if( intf_class == 0x0A ) + { + if( (m_currentSerialIntf == 0) || (m_currentSerialIntf == 1) ) + { + m_currentSerialIntf++; + return true; + } + m_currentSerialIntf++; + } + } + else + { + if( (intf_nb == 0) && (intf_class == MSD_CLASS) ) + { + return true; + } + } + return false; +} + +/*virtual*/ bool VodafoneK3772ZInitializer::useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) //Must return true if the endpoint will be used +{ + if( m_hasSwitched ) + { + DBG("Endpoint on Inteface #%d; Type:%d; Direction:%d", intf_nb, type, dir); + if( (type == BULK_ENDPOINT) && m_endpointsToFetch ) + { + m_endpointsToFetch--; + return true; + } + } + else + { + if( (type == BULK_ENDPOINT) && (dir == OUT) && m_endpointsToFetch ) + { + m_endpointsToFetch--; + return true; + } + } + return false; +} + + +/*virtual*/ WAN_DONGLE_TYPE VodafoneK3772ZInitializer::getType() +{ + return WAN_DONGLE_TYPE_VODAFONEK3772Z; +}