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:
- 20:3abcf818be31
- Parent:
- 13:c154e7f2e42f
- Child:
- 21:dcc8c866ccbb
--- a/USB3GModule/WANDongleInitializer.cpp Tue Nov 13 12:00:11 2012 +0000 +++ b/USB3GModule/WANDongleInitializer.cpp Thu Dec 13 14:56:55 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__ 0 +#define __DEBUG__ 4 #ifndef __MODULE__ #define __MODULE__ "WANDongleInitializer.cpp" #endif @@ -37,7 +37,8 @@ { static VodafoneK3770Initializer vodafoneK3770(pHost); static VodafoneK3772ZInitializer vodafoneK3772Z(pHost); - const static WANDongleInitializer* list[] = { &vodafoneK3770, &vodafoneK3772Z, NULL }; + static VodafoneK3773Initializer vodafoneK3773(pHost); + const static WANDongleInitializer* list[] = { &vodafoneK3770, &vodafoneK3772Z, &vodafoneK3773, NULL }; return (WANDongleInitializer**)list; } @@ -151,6 +152,116 @@ return WAN_DONGLE_TYPE_VODAFONEK3770; } +//Huawei K3773 (Vodafone) +// Switching from mass storage device string is: "55 53 42 43 12 34 56 78 00 00 00 00 00 00 00 11 06 20 00 00 01 00 00 00 00 00 00 00 00 00 00" +static uint8_t vodafone_k3773_switch_packet[] = { + 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 +}; + +VodafoneK3773Initializer::VodafoneK3773Initializer(USBHost* pHost) : WANDongleInitializer(pHost) +{ + +} + +uint16_t VodafoneK3773Initializer::getMSDVid() { return 0x12D1; } +uint16_t VodafoneK3773Initializer::getMSDPid() { return 0x1506; } + +uint16_t VodafoneK3773Initializer::getSerialVid() { return 0x12D1; } +uint16_t VodafoneK3773Initializer::getSerialPid() { return 0x1506; } + +bool VodafoneK3773Initializer::switchMode(USBDeviceConnected* pDev) +{ + for (int i = 0; i < pDev->getNbInterface(); i++) + { + if (pDev->getInterface(i)->intf_class == MSD_CLASS) + { + USBEndpoint* 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_k3773_switch_packet, 31); + return true; + } + } + } + return false; +} + +USBEndpoint* VodafoneK3773Initializer::getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx) +{ + return pDev->getEndpoint(serialPortNumber, BULK_ENDPOINT, tx?OUT:IN, 0); +} + +int VodafoneK3773Initializer::getSerialPortCount() +{ + return 2; +} + +/*virtual*/ void VodafoneK3773Initializer::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 VodafoneK3773Initializer::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 ) + { + if( intf_class == 0xFF ) + { + if( (m_currentSerialIntf == 0) || (m_currentSerialIntf == 4) ) + { + m_currentSerialIntf++; + return true; + } + m_currentSerialIntf++; + } + } + else + { + if( (intf_nb == 0) && (intf_class == MSD_CLASS) ) + { + return true; + } + } + return false; +} + +/*virtual*/ bool VodafoneK3773Initializer::useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) //Must return true if the endpoint will be used +{ + if( m_hasSwitched ) + { + 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 VodafoneK3773Initializer::getType() +{ + return WAN_DONGLE_TYPE_VODAFONEK3773; +} + // 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[] = {