USB Host WAN Dongle library
Fork of USBHostWANDongle_bleedingedge by
Revision 3:4394986752db, committed 2012-07-06
- Comitter:
- donatien
- Date:
- Fri Jul 06 08:53:17 2012 +0000
- Parent:
- 2:a8b2d0cd9bbd
- Child:
- 4:d229ebfb85c4
- Commit message:
- Increased limits for number of supported USB endpoints/interfaces
Changed in this revision
--- a/USB3GModule/WANDongle.cpp Tue Jun 26 13:43:54 2012 +0000 +++ b/USB3GModule/WANDongle.cpp Fri Jul 06 08:53:17 2012 +0000 @@ -28,7 +28,7 @@ #include "WANDongle.h" #include "WANDongleInitializer.h" -WANDongle::WANDongle() : cb_tx_en(false), cb_rx_en(false), listener(NULL), m_serialCount(0) +WANDongle::WANDongle() : m_serialCount(0) { host = USBHost::getHostInst(); init(); @@ -63,27 +63,45 @@ DBG("Enumerate"); host->enumerate(dev); - WANDongleInitializer* initializer = getInitializers(); + DBG("Device has VID:%04x PID%04x", dev->getVid(), dev->getPid()); - while(initializer++) + WANDongleInitializer** initializer = WANDongleInitializer::getInitializers(host); + + while((*initializer)) { - if ((dev->getVid() == initializer->getSerialVid()) && (dev->getPid() == initializer->getSerialPid())) + DBG("*initializer=%p", *initializer); + DBG("(*initializer)->getSerialVid()=%04x", (*initializer)->getSerialVid()); + DBG("(*initializer)->getSerialPid()=%04x", (*initializer)->getSerialPid()); + if ((dev->getVid() == (*initializer)->getSerialVid()) && (dev->getPid() == (*initializer)->getSerialPid())) { + DBG("The dongle is in virtual serial mode"); host->registerDriver(dev, 0, this, &WANDongle::init); - m_serialCount = initializer->getSerialPortCount(); + m_serialCount = (*initializer)->getSerialPortCount(); + if( m_serialCount > WANDONGLE_MAX_SERIAL_PORTS ) + { + m_serialCount = WANDONGLE_MAX_SERIAL_PORTS; + } for(int j = 0; j < m_serialCount; j++) { - m_serial[j].connect( initializer->getEp(dev, j, false), initializer->getEp(dev, j, true) ); + DBG("Connecting serial port #%d", j+1); + DBG("Ep %p", (*initializer)->getEp(dev, j, false)); + DBG("Ep %p", (*initializer)->getEp(dev, j, true)); + m_serial[j].connect( dev, (*initializer)->getEp(dev, j, false), (*initializer)->getEp(dev, j, true) ); } + + DBG("Device connected"); + dev_connected = true; host->unlock(); + + return true; } - else if ((dev->getVid() == initializer->getMSDVid()) && (dev->getPid() == initializer->getMSDPid())) + else if ((dev->getVid() == (*initializer)->getMSDVid()) && (dev->getPid() == (*initializer)->getMSDPid())) { DBG("Vodafone K3370 dongle detected in MSD mode"); //Try to switch - if( initializer->switchMode() ) + if( (*initializer)->switchMode(dev) ) { DBG("Switched OK"); host->unlock(); @@ -96,6 +114,7 @@ return false; } } + (*initializer)++; } //while() } //if() } //for() @@ -103,7 +122,7 @@ return false; } -IUSBHostSerial* WANDongle::getSerial(int index) +IUSBHostSerial& WANDongle::getSerial(int index) { return m_serial[index]; } @@ -117,5 +136,8 @@ void WANDongle::init() { dev_connected = false; + for(int i = 0; i < WANDONGLE_MAX_SERIAL_PORTS; i++) + { + m_serial[i].init(host); + } } -
--- a/USB3GModule/WANDongle.h Tue Jun 26 13:43:54 2012 +0000 +++ b/USB3GModule/WANDongle.h Fri Jul 06 08:53:17 2012 +0000 @@ -24,6 +24,7 @@ #include "rtos.h" +#include "WANDongleSerialPort.h" #define WANDONGLE_MAX_OUTEP_SIZE 64 #define WANDONGLE_MAX_INEP_SIZE 64 @@ -56,7 +57,7 @@ */ bool tryConnect(); - IUSBHostSerial* getSerial(int index); + IUSBHostSerial& getSerial(int index); int getSerialCount(); protected:
--- 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; +} +
--- a/USB3GModule/WANDongleInitializer.h Tue Jun 26 13:43:54 2012 +0000 +++ b/USB3GModule/WANDongleInitializer.h Fri Jul 06 08:53:17 2012 +0000 @@ -44,13 +44,13 @@ virtual int getSerialPortCount() = 0; - static WANDongleInitializer[] getInitializers(); + static WANDongleInitializer** getInitializers(USBHost* pHost); }; class VodafoneK3770Initializer : public WANDongleInitializer { public: - VodafoneK3770Initializer(); + VodafoneK3770Initializer(USBHost* pHost); virtual uint16_t getMSDVid(); virtual uint16_t getMSDPid(); @@ -62,7 +62,7 @@ virtual Endpoint* getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx); - virtual int getSerialPortCount() = 0; + virtual int getSerialPortCount(); }; #endif
--- a/USB3GModule/WANDongleSerialPort.cpp Tue Jun 26 13:43:54 2012 +0000 +++ b/USB3GModule/WANDongleSerialPort.cpp Fri Jul 06 08:53:17 2012 +0000 @@ -27,7 +27,7 @@ #include "WANDongleSerialPort.h" -WANDongleSerialPort::WANDongleSerialPort() : cb_tx_en(false), cb_rx_en(false) +WANDongleSerialPort::WANDongleSerialPort() : cb_tx_en(false), cb_rx_en(false), listener(NULL) { reset(); } @@ -238,8 +238,9 @@ } -void WANDongleSerialPort::connect( Endpoint* pInEp, Endpoint* pOutEp ) +void WANDongleSerialPort::connect( USBDeviceConnected* pDev, Endpoint* pInEp, Endpoint* pOutEp ) { + dev = pDev; bulk_in = pInEp; bulk_out = pOutEp; max_out_size = bulk_out->getSize();
--- a/USB3GModule/WANDongleSerialPort.h Tue Jun 26 13:43:54 2012 +0000 +++ b/USB3GModule/WANDongleSerialPort.h Fri Jul 06 08:53:17 2012 +0000 @@ -31,17 +31,17 @@ /** A class to use a WAN (3G/LTE) access dongle * */ -class WANDongle : public IUSBHostSerial { +class WANDongleSerialPort : public IUSBHostSerial { public: /* * Constructor * */ - WANDongleSerialPort( ); + WANDongleSerialPort(); - void init(USBHost* pHost); + void init( USBHost* pHost ); - void connect( Endpoint* pInEp, Endpoint* pOutEp ); + void connect( USBDeviceConnected* pDev, Endpoint* pInEp, Endpoint* pOutEp ); void disconnect( ); @@ -96,6 +96,7 @@ Endpoint * bulk_in; Endpoint * bulk_out; USBHost * host; + USBDeviceConnected * dev; uint8_t buf_out[WANDONGLE_MAX_OUTEP_SIZE]; volatile uint32_t buf_out_len;
--- a/USBHost/USBDeviceConnected.h Tue Jun 26 13:43:54 2012 +0000 +++ b/USBHost/USBDeviceConnected.h Fri Jul 06 08:53:17 2012 +0000 @@ -23,7 +23,7 @@ #include "Endpoint.h" #define MAX_ENDPOINT_PER_INTERFACE 4 -#define MAX_INTF 4 +#define MAX_INTF 5 typedef struct { bool in_use;
--- a/USBHost/USBHALHost.h Tue Jun 26 13:43:54 2012 +0000 +++ b/USBHost/USBHALHost.h Fri Jul 06 08:53:17 2012 +0000 @@ -23,7 +23,7 @@ #include "USBHostTypes.h" -#define MAX_ENDPOINT 6 +#define MAX_ENDPOINT 16 #define MAX_TD (MAX_ENDPOINT*2) #define USBHALHOST_SIG_INIT 0x01
--- a/USBHost/USBHost.cpp Tue Jun 26 13:43:54 2012 +0000 +++ b/USBHost/USBHost.cpp Fri Jul 06 08:53:17 2012 +0000 @@ -29,7 +29,7 @@ #include "rtos.h" -#define NB_MAX_INTF 3 +#define NB_MAX_INTF 5 USBHost * USBHost::instHost = NULL; @@ -662,7 +662,7 @@ case CONFIGURATION_DESCRIPTOR: break; case INTERFACE_DESCRIPTOR: - if (intf_nb++ < NB_MAX_INTF) { + if (intf_nb++ <= NB_MAX_INTF) { dev->addInterface(intf_nb - 1, conf_descr[index + 5], conf_descr[index + 6], conf_descr[index + 7]); nb_endpoints_used = 0; DBG("ADD INTF %d on device %p: class: %d, subclass: %d, proto: %d", intf_nb - 1, (void *)dev, conf_descr[index + 5],conf_descr[index + 6],conf_descr[index + 7]); @@ -671,7 +671,8 @@ } break; case ENDPOINT_DESCRIPTOR: - if (intf_nb < NB_MAX_INTF) { + DBG("Ep DESC"); + if (intf_nb <= NB_MAX_INTF) { if (nb_endpoints_used < MAX_ENDPOINT_PER_INTERFACE) { // if the endpoint is isochronous -> skip it (TODO: fix this) if ((conf_descr[index + 3] & 0x03) != ISOCHRONOUS_ENDPOINT) { @@ -683,7 +684,7 @@ if (ep != NULL && dev != NULL) { addEndpoint(dev, intf_nb - 1, ep); } else { - DBG("EP NULL\r\n"); + DBG("EP NULL"); } nb_endpoints_used++; } else { @@ -691,7 +692,7 @@ } } } - //DBG("ENDPOINT DESCR\r\n"); + //DBG("ENDPOINT DESCR"); break; case HID_DESCRIPTOR: lenReportDescr = conf_descr[index + 7] | (conf_descr[index + 8] << 8);