Vodafone K3770/K3772-Z modems driver & networking library

Dependencies:   Socket USBHostWANDongle lwip-sys lwip

Dependents:   VodafoneUSBModemHTTPClientTest VodafoneUSBModemNTPClientTest VodafoneUSBModemSMSTest VodafoneUSBModemUSSDTest ... more

Fork of VodafoneUSBModem_bleedingedge by Donatien Garnier

This is the driver for the Vodafone K3700 & K3772-Z Dongles:

K3770

More details and instructions can be found here.

Files at this revision

API Documentation at this revision

Comitter:
donatien
Date:
Wed Jul 11 12:44:33 2012 +0000
Parent:
8:04b6a042595f
Child:
11:565b2ec40dea
Commit message:
Send AT Connect command in PPPIPInterface, tweaks in VodafoneK3770 for dual serial port support

Changed in this revision

VodafoneK3770.cpp Show annotated file Show diff for this revision Revisions of this file
ip/PPPIPInterface.cpp Show annotated file Show diff for this revision Revisions of this file
ip/PPPIPInterface.h Show annotated file Show diff for this revision Revisions of this file
--- a/VodafoneK3770.cpp	Tue Jun 26 13:44:59 2012 +0000
+++ b/VodafoneK3770.cpp	Wed Jul 11 12:44:33 2012 +0000
@@ -176,12 +176,14 @@
     return ret;
   }
 
+  #if USE_ONE_PORT
   m_smsInit = false; //SMS status reset
   m_ussdInit = false; //USSD status reset
+  #endif
 
   ATCommandsInterface::ATResult result;
 
-#if 0
+  #if 0
   //Get network info & select corresponding APN
   COPSProcessor copsProcessor;
   DBG("Get network info & select APN from DB");
@@ -219,21 +221,27 @@
 
   //Connect
   DBG("Connecting");
+  #if 0
   ret = m_at.executeSimple("ATDT *99#", &result);
   DBG("Result of command: Err code=%d", ret);
   DBG("ATResult: AT return=%d (code %d)", result.result, result.code);
+  #endif
+  #if USE_ONE_PORT
   m_at.close(); // Closing AT parser
   m_atOpen = false; //Will need to be reinitialized afterwards
+  #endif
 
+  #if 0
   DBG("AT Parser closed");
   if( (ret!=NET_MOREINFO) || (result.result != ATCommandsInterface::ATResult::AT_CONNECT))
   {
     ERR("Could not connect");
     return ret; //Could not connect
   }
+  #endif
   DBG("Connecting PPP");
 
-  ret = m_ppp.connect();
+  ret = m_ppp.connect("*99#");
   DBG("Result of connect: Err code=%d", ret);
   return ret;
 }
@@ -251,6 +259,7 @@
   //Ugly but leave dongle time to recover
   Thread::wait(500);
 
+  #if USE_ONE_PORT
   ATCommandsInterface::ATResult result;
   DBG("Starting AT thread");
   ret = m_at.open();
@@ -258,10 +267,11 @@
   {
     return ret;
   }
+  #endif
 
   DBG("Trying to hangup");
 
-#if 0 //Does not appear to work
+  #if 0 //Does not appear to work
   int tries = 10;
   do
   {
@@ -275,8 +285,9 @@
     DBG("Result of command: Err code=%d\n", ret);
     DBG("ATResult: AT return=%d (code %d)\n", result.result, result.code);
   }
-#endif
+  #endif
 
+  #if USE_ONE_PORT
   //Reinit AT parser
   ret = m_at.init();
   DBG("Result of command: Err code=%d\n", ret);
@@ -287,8 +298,11 @@
     return NET_TIMEOUT;
   }
 
+  #if 0
   m_at.close(); // Closing AT parser
   DBG("AT Parser closed");
+  #endif
+  #endif
   return OK;
 }
 
@@ -436,6 +450,7 @@
     return ret;
   }
 
+  #if USE_ONE_PORT
   DBG("Configuring unsolicited result codes support properly");
   //Configuring port
   ret = m_at.executeSimple("AT^CURC=0;^PORTSEL=1", NULL); //Huawei-specific, not 3GPP-compliant
@@ -443,6 +458,7 @@
   {
     return NET_PROTOCOL;
   }
+  #endif
 
   ATCommandsInterface::ATResult result;
 
--- a/ip/PPPIPInterface.cpp	Tue Jun 26 13:44:59 2012 +0000
+++ b/ip/PPPIPInterface.cpp	Wed Jul 11 12:44:33 2012 +0000
@@ -67,9 +67,45 @@
   return OK;
 }
 
-/*virtual*/ int PPPIPInterface::connect()
+/*virtual*/ int PPPIPInterface::connect(const char* msisdn)
 {
+  int ret;
+  char buf[32];
+  size_t len;
   DBG("Trying to connect with PPP");
+  
+  do //Clear buf
+  {
+    ret = m_pStream->read(buf, &len, 32, 0) > 0
+  } while( (ret == OK) && (len > 0) );
+  
+  sprintf(buf, "ATD %16s\x0D");
+  
+  ret = m_pStream->write(buf, strlen(buf), osWaitForever);
+  if( ret != OK )
+  {
+    return NET_UNKNOWN;
+  }
+  
+  const char expected = "\x0D\0x0ACONNECT\x0D\0x0A";
+  
+  ret = m_pStream->read(buf, strlen(expected), &len, 3000);
+  if( ret != OK )
+  {
+    return NET_UNKNOWN;
+  }
+  
+  if( (len < strlen(expected)) || (memcmp(expected, buf) != 0) )
+  {
+    //Discard buffer
+    do //Clear buf
+    {
+      ret = m_pStream->read(buf, &len, 32, 0) > 0
+    } while( (ret == OK) && (len > 0) );
+    return NET_CONN;
+  }
+      
+  DBG("Transport link open");
   m_linkStatusSphre.wait(0);
   if((m_pppd != -1) && (m_pppErrCode == 0)) //Already connected
   {
--- a/ip/PPPIPInterface.h	Tue Jun 26 13:44:59 2012 +0000
+++ b/ip/PPPIPInterface.h	Wed Jul 11 12:44:33 2012 +0000
@@ -46,7 +46,7 @@
 
     int init(); //Init PPP-specific stuff, create the right bindings, etc
     int setup(const char* user, const char* pw); //Setup authentication
-    virtual int connect();
+    virtual int connect(const char* msisdn);
     virtual int disconnect();
 
 private: