Changes to support Vodafone K4606

Dependents:   VodafoneUSBModem

Fork of USBHostWANDongle by mbed official

Revision:
28:34cdecfff9f4
Parent:
27:980fe31c14f7
--- a/USB3GModule/WANDongleInitializer.cpp	Fri Sep 20 10:40:15 2013 +0000
+++ b/USB3GModule/WANDongleInitializer.cpp	Wed Jan 28 11:38:44 2015 +0000
@@ -28,9 +28,9 @@
 
 #include "WANDongleInitializer.h"
 
+
 WANDongleInitializer::WANDongleInitializer(USBHost* pHost) : m_pHost(pHost)
 {
-
 }
 
 WANDongleInitializer** WANDongleInitializer::getInitializers(USBHost* pHost)
@@ -41,6 +41,8 @@
   static VodafoneK3773Initializer vodafoneK3773(pHost);
   static HuaweiMU509Initializer huaweiMU509(pHost);
   static UbloxLISAU200Initializer ubloxLISAU200(pHost);
+  static VodafoneK4606Initializer vodafoneK4606(pHost);  
+
   const static WANDongleInitializer* list[] = {
      &vodafoneK3770,
      &vodafoneK3772Z,
@@ -48,6 +50,7 @@
      &vodafoneK3773,
      &huaweiMU509,
      &ubloxLISAU200,
+     &vodafoneK4606,     
      NULL
   };
   return (WANDongleInitializer**)list;
@@ -681,4 +684,118 @@
 /*virtual*/ WAN_DONGLE_TYPE UbloxLISAU200Initializer::getType()
 {
   return WAN_DONGLE_TYPE_UBLOX_LISAU200;
-}
\ No newline at end of file
+}
+
+
+//-----------------------------------------------------------------------
+// Huawei K4606 (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_k4606_switch_packet[] = {
+    0x55, 0x53, 0x42, 0x43, 0x12, 0x34, 0x56, 0x78, 0, 0, 0, 0, 0, 0, 0, 0x11, 0x06, 0x00, 0, 0, 0x00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+VodafoneK4606Initializer::VodafoneK4606Initializer(USBHost* pHost) : WANDongleInitializer(pHost)
+{
+}
+
+uint16_t VodafoneK4606Initializer::getMSDVid()      { return 0x12D1; }
+uint16_t VodafoneK4606Initializer::getMSDPid()      { return 0x1F19; }
+
+uint16_t VodafoneK4606Initializer::getSerialVid()   { return 0x12D1; }
+uint16_t VodafoneK4606Initializer::getSerialPid()   { return 0x1001;}
+
+bool VodafoneK4606Initializer::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("Vodafone K4606 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_k4606_switch_packet, 31);
+        return true;
+      }
+    }  
+  }
+  return false;
+}
+
+USBEndpoint* VodafoneK4606Initializer::getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx)
+{
+  return pDev->getEndpoint(serialPortNumber, BULK_ENDPOINT, tx?OUT:IN, 0);
+}
+
+int VodafoneK4606Initializer::getSerialPortCount()
+{
+  return 2;
+}
+
+void VodafoneK4606Initializer::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;
+    }
+}
+
+bool VodafoneK4606Initializer::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("*K4606 parsing intf %d, intf_class %d, m_currentSerialIntf %d", intf_nb, intf_class, m_currentSerialIntf);    
+    
+    if( intf_class == 0x2 )
+    {
+      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;
+}
+
+bool VodafoneK4606Initializer::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;
+}
+
+ WAN_DONGLE_TYPE VodafoneK4606Initializer::getType()
+{
+  return WAN_DONGLE_TYPE_VODAFONE_K4606;
+}