USB Host WAN Dongle library

Fork of USBHostWANDongle_bleedingedge by Donatien Garnier

Files at this revision

API Documentation at this revision

Comitter:
ashleymills
Date:
Fri Mar 08 11:04:45 2013 +0000
Parent:
24:f4b676f61906
Parent:
19:6526d83aab9f
Child:
26:b241a57c465b
Commit message:
Merged MU509 and K3773 changes.

Changed in this revision

USB3GModule/WANDongle.cpp Show annotated file Show diff for this revision Revisions of this file
USB3GModule/WANDongleInitializer.cpp Show annotated file Show diff for this revision Revisions of this file
USB3GModule/WANDongleInitializer.h Show annotated file Show diff for this revision Revisions of this file
--- a/USB3GModule/WANDongle.cpp	Wed Jan 09 16:13:34 2013 +0000
+++ b/USB3GModule/WANDongle.cpp	Fri Mar 08 11:04:45 2013 +0000
@@ -32,6 +32,7 @@
 {
     host = USBHost::getHostInst();
     init();
+    DBG("WANDongle object instantiated. getHostInst method called on USBHost.");
 }
 
 
@@ -128,6 +129,13 @@
             }
           } //if()
       } //if()
+      /*else
+      {
+        // Looks like the getDevice method failed and returned a null pointer. Maybe there has been a power cut, modem pulled or something to stop the modem.
+        // Lets run the initilise routine again. Next time round the loop we might have a handle to an end point!
+        DBG("Trying to initialise the USB stack since the getDevice method has returned a null pointer");
+        init();
+      }*/
   } //for()
   host->unlock();
   return false;
--- a/USB3GModule/WANDongle.h	Wed Jan 09 16:13:34 2013 +0000
+++ b/USB3GModule/WANDongle.h	Fri Mar 08 11:04:45 2013 +0000
@@ -79,6 +79,8 @@
     
     virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used
     
+    //void init();
+    
 protected:
     USBHost * host;
     USBDeviceConnected * dev;
--- a/USB3GModule/WANDongleInitializer.cpp	Wed Jan 09 16:13:34 2013 +0000
+++ b/USB3GModule/WANDongleInitializer.cpp	Fri Mar 08 11:04:45 2013 +0000
@@ -37,11 +37,13 @@
 {
   static VodafoneK3770Initializer vodafoneK3770(pHost);
   static VodafoneK3772ZInitializer vodafoneK3772Z(pHost);
+  static VodafoneK3773Initializer vodafoneK3772(pHost);
   static VodafoneK3773Initializer vodafoneK3773(pHost);
   static VodafoneMU509Initializer vodafoneMU509(pHost);
   const static WANDongleInitializer* list[] = {
      &vodafoneK3770,
      &vodafoneK3772Z,
+     &vodafoneK3772,
      &vodafoneK3773,
      &vodafoneMU509,
      NULL
@@ -456,3 +458,114 @@
 {
   return WAN_DONGLE_TYPE_VODAFONEK3772Z;
 }
+
+//Huawei K3772 (Vodafone)
+// Switching from mass storage device string is: "55 53 42 43 12 34 56 78 00 02 00 00 80 00 0a 11 06 20 00 00 00 00 00 01 00 00 00 00 00 00 00"
+static uint8_t vodafone_k3772_switch_packet[] = {
+    0x55, 0x53, 0x42, 0x43, 0x12, 0x34, 0x56, 0x78, 0, 0x02, 0, 0, 0x80, 0, 0x0a, 0x11, 0x06, 0x20, 0, 0, 0, 0, 0, 0x01, 0, 0, 0, 0, 0, 0, 0
+};
+
+
+VodafoneK3772Initializer::VodafoneK3772Initializer(USBHost* pHost) : WANDongleInitializer(pHost)
+{
+  
+}
+
+uint16_t VodafoneK3772Initializer::getMSDVid()      { return 0x12D1; }
+uint16_t VodafoneK3772Initializer::getMSDPid()      { return 0x1526; }
+
+uint16_t VodafoneK3772Initializer::getSerialVid()   { return 0x12D1; }
+uint16_t VodafoneK3772Initializer::getSerialPid()   { return 0x14CF; }
+
+bool VodafoneK3772Initializer::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_k3772_switch_packet, 31);
+        return true;
+      }
+    }  
+  }
+  return false;
+}
+
+USBEndpoint* VodafoneK3772Initializer::getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx)
+{
+  return pDev->getEndpoint(serialPortNumber, BULK_ENDPOINT, tx?OUT:IN, 0);
+}
+
+int VodafoneK3772Initializer::getSerialPortCount()
+{
+  return 2;
+}
+
+/*virtual*/ void VodafoneK3772Initializer::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 VodafoneK3772Initializer::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 == 2) )
+      {
+        m_currentSerialIntf++;
+        return true;
+      }
+      m_currentSerialIntf++;
+    }
+  }
+  else
+  {
+    if( (intf_nb == 0) && (intf_class == MSD_CLASS) )
+    {
+      return true;
+    }
+  }
+  return false;
+}
+
+/*virtual*/ bool VodafoneK3772Initializer::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 VodafoneK3772Initializer::getType()
+{
+  return WAN_DONGLE_TYPE_VODAFONEK3772;
+}
\ No newline at end of file
--- a/USB3GModule/WANDongleInitializer.h	Wed Jan 09 16:13:34 2013 +0000
+++ b/USB3GModule/WANDongleInitializer.h	Fri Mar 08 11:04:45 2013 +0000
@@ -28,11 +28,12 @@
 
 enum WAN_DONGLE_TYPE
 {
-  WAN_DONGLE_TYPE_UNKNOWN = -1,
-  WAN_DONGLE_TYPE_VODAFONEK3770 = 0,
-  WAN_DONGLE_TYPE_VODAFONEK3772Z = 1,
-  WAN_DONGLE_TYPE_VODAFONEK3773 = 2,
-  WAN_DONGLE_TYPE_VODAFONEMU509 = 3,
+  WAN_DONGLE_TYPE_UNKNOWN        = -1,
+  WAN_DONGLE_TYPE_VODAFONEK3770  =  0,
+  WAN_DONGLE_TYPE_VODAFONEK3772Z =  1,
+  WAN_DONGLE_TYPE_VODAFONEK3772  =  2,
+  WAN_DONGLE_TYPE_VODAFONEK3773  =  3,
+  WAN_DONGLE_TYPE_VODAFONEMU509  =  4,
 };
 
 class WANDongleInitializer : public IUSBEnumerator
@@ -192,4 +193,37 @@
   int m_endpointsToFetch;
 };
 
+class VodafoneK3772Initializer : public WANDongleInitializer
+{
+public:
+    VodafoneK3772Initializer(USBHost* pHost);
+    
+    virtual uint16_t getMSDVid();
+    virtual uint16_t getMSDPid();
+    
+    virtual uint16_t getSerialVid();
+    virtual uint16_t getSerialPid();
+    
+    virtual bool switchMode(USBDeviceConnected* pDev);
+    
+    virtual USBEndpoint* getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx);
+    
+    virtual int getSerialPortCount();
+    
+    virtual void setVidPid(uint16_t vid, uint16_t pid);
+    
+    virtual bool 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
+    
+    virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used
+    
+    virtual WAN_DONGLE_TYPE getType();
+    
+private:
+
+  bool m_hasSwitched;
+  int m_currentSerialIntf;
+  int m_endpointsToFetch;
+};
+
 #endif
+
--- a/USBHost/USBHost.cpp	Wed Jan 09 16:13:34 2013 +0000
+++ b/USBHost/USBHost.cpp	Fri Mar 08 11:04:45 2013 +0000
@@ -285,6 +285,7 @@
 
 USBDeviceConnected * USBHost::getDevice(uint8_t index)  {
   if ((index >= MAX_DEVICE_NB) || (!deviceInUse[index])) {
+    DBG("getDevice failed. Index is: %d, and deviceInUse[%d] is %s", index, index, deviceInUse[index]);
     return NULL;
   }
   return (USBDeviceConnected*)&devices[index];