Changes to support Vodafone K4606
Fork of USBHostWANDongle by
Diff: USB3GModule/WANDongleInitializer.cpp
- Revision:
- 3:4394986752db
- Parent:
- 2:a8b2d0cd9bbd
- Child:
- 5:3189db174f6b
diff -r a8b2d0cd9bbd -r 4394986752db USB3GModule/WANDongleInitializer.cpp --- a/USB3GModule/WANDongleInitializer.cpp Tue Jun 26 13:43:54 2012 +0000 +++ b/USB3GModule/WANDongleInitializer.cpp Fri Jul 06 08:53:17 2012 +0000 @@ -1,85 +1,87 @@ -/* Copyright (c) 2010-2011 mbed.org, MIT License -* -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or -* substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -#define __DEBUG__ 4 //Maximum verbosity -#ifndef __MODULE__ -#define __MODULE__ "WANDongleInitializer.cpp" -#endif - -#include "dbg.h" - -#include <cstdint> -using std::uint16_t; - -#include "WANDongleInitializer.h" - -WANDongleInitializer::WANDongleInitializer(USBHost* pHost) : m_pHost(pHost) -{ - -} - -WANDongleInitializer[] WANDongleInitializer::getInitializers() -{ - static VodafoneK3770Initializer vodafoneK3770; - const static WANDongleInitializer list[] = { &vodafoneK3770, NULL }; - return list; -} - -//Huawei K3770 (Vodafone) -const static uint8_t vodafone_k3770_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 -}; - -VodafoneK3770Initializer::VodafoneK3770Initializer(USBHost* pHost) : WANDongleInitializer(pHost) -{ - -} - -uint16_t VodafoneK3770Initializer::getMSDVid() { return 0x12D1; } -uint16_t VodafoneK3770Initializer::getMSDPid() { return 0x14D1; } - -uint16_t VodafoneK3770Initializer::getSerialVid() { return 0x12D1; } -uint16_t VodafoneK3770Initializer::getSerialPid() { return 0x14C9; } - -bool VodafoneK3770Initializer::switchMode(USBDeviceConnected* pDev) -{ - for (int i = 0; i < pDev->getNbInterface(); i++) - { - if (pDev->getInterface(j)->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_k3770_switch_packet, 31); - return true; - } - } - return false; -} - -Endpoint* VodafoneK3770Initializer::getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx) -{ - return dev->getEndpoint(0, BULK_ENDPOINT, tx?OUT:IN, serialPortNumber); -} - -int VodafoneK3770Initializer::getSerialPortCount() -{ - return 3; -} - +/* Copyright (c) 2010-2011 mbed.org, MIT License +* +* Permission is hereby granted, free of charge, to any person obtaining a copy of this software +* and associated documentation files (the "Software"), to deal in the Software without +* restriction, including without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all copies or +* substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#define __DEBUG__ 4 //Maximum verbosity +#ifndef __MODULE__ +#define __MODULE__ "WANDongleInitializer.cpp" +#endif + +#include "dbg.h" + +#include <cstdint> +using std::uint16_t; + +#include "WANDongleInitializer.h" + +WANDongleInitializer::WANDongleInitializer(USBHost* pHost) : m_pHost(pHost) +{ + +} + +WANDongleInitializer** WANDongleInitializer::getInitializers(USBHost* pHost) +{ + static VodafoneK3770Initializer vodafoneK3770(pHost); + const static WANDongleInitializer* list[] = { &vodafoneK3770, NULL }; + return (WANDongleInitializer**)list; +} + +//Huawei K3770 (Vodafone) +static uint8_t vodafone_k3770_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 +}; + +VodafoneK3770Initializer::VodafoneK3770Initializer(USBHost* pHost) : WANDongleInitializer(pHost) +{ + +} + +uint16_t VodafoneK3770Initializer::getMSDVid() { return 0x12D1; } +uint16_t VodafoneK3770Initializer::getMSDPid() { return 0x14D1; } + +uint16_t VodafoneK3770Initializer::getSerialVid() { return 0x12D1; } +uint16_t VodafoneK3770Initializer::getSerialPid() { return 0x14C9; } + +bool VodafoneK3770Initializer::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_k3770_switch_packet, 31); + return true; + } + } + } + return false; +} + +Endpoint* VodafoneK3770Initializer::getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx) +{ + const int intf[3] = {0,4,2}; + return pDev->getEndpoint(intf[serialPortNumber], BULK_ENDPOINT, tx?OUT:IN, 0); +} + +int VodafoneK3770Initializer::getSerialPortCount() +{ + return 3; +} +