Base library for cellular modem implementations

Dependencies:   Socket lwip-sys lwip

Dependents:   CellularUSBModem CellularUSBModem

Deprecated

This is an mbed 2 networking library. For mbed 5, the networking libraries have been revised to better support additional network stacks and thread safety here.

Files at this revision

API Documentation at this revision

Comitter:
mbed_official
Date:
Mon Dec 16 09:00:24 2013 +0000
Parent:
3:317b007abdec
Child:
5:9a57892f206c
Commit message:
Synchronized with git revision 170ac6562b7b2b5bb43f8ecf82b2af18b37eeb9c

Full URL: https://github.com/mbedmicro/mbed/commit/170ac6562b7b2b5bb43f8ecf82b2af18b37eeb9c/

improve USB host library and cellular modem stack

Changed in this revision

at/ATCommandsInterface.cpp Show annotated file Show diff for this revision Revisions of this file
at/ATCommandsInterface.h 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/at/ATCommandsInterface.cpp	Thu Oct 17 16:50:41 2013 +0300
+++ b/at/ATCommandsInterface.cpp	Mon Dec 16 09:00:24 2013 +0000
@@ -63,30 +63,33 @@
 }
 
 //Initialize AT link & start events processing
-int ATCommandsInterface::init()
+int ATCommandsInterface::init(bool reset /* = true*/)
 {
-  DBG("Sending ATZ E1 V1");
   
   //Lock transaction mutex
   m_transactionMtx.lock();
   
-  //Should we flush m_pStream at this point ???
-  int err;
-  int tries = 5;
-  do
+  if (reset)
   {
-    err = executeInternal("ATZ E1 V1", this, NULL, 3000); //Enable echo and verbosity
-    if(err && tries)
+    DBG("Sending ATZ E1 V1");
+    //Should we flush m_pStream at this point ???
+    int err;
+    int tries = 5;
+    do
     {
-      WARN("No response, trying again");
-      Thread::wait(1000); //Give dongle time to recover
+      err = executeInternal("ATZ E1 V1", this, NULL, 3000); //Enable echo and verbosity
+      if(err && tries)
+      {
+        WARN("No response, trying again");
+        Thread::wait(1000); //Give dongle time to recover
+      }
+    } while(err && tries--);
+    if( err )
+    {
+      ERR("Sending ATZ E1 V1 returned with err code %d", err);
+      m_transactionMtx.unlock();
+      return err;
     }
-  } while(err && tries--);
-  if( err )
-  {
-    ERR("Sending ATZ E1 V1 returned with err code %d", err);
-    m_transactionMtx.unlock();
-    return err;
   }
   
   //Enable events handling and execute events enabling commands
--- a/at/ATCommandsInterface.h	Thu Oct 17 16:50:41 2013 +0300
+++ b/at/ATCommandsInterface.h	Mon Dec 16 09:00:24 2013 +0000
@@ -77,7 +77,7 @@
   int open();
 
   //Initialize AT link
-  int init();
+  int init(bool reset = true);
 
   //Close connection
   int close();
--- a/ip/PPPIPInterface.cpp	Thu Oct 17 16:50:41 2013 +0300
+++ b/ip/PPPIPInterface.cpp	Mon Dec 16 09:00:24 2013 +0000
@@ -50,22 +50,15 @@
 #include "netif/ppp/ppp.h"
 }
 
-PPPIPInterface::PPPIPInterface(IOStream* pStream, const char* msisdn) : LwIPInterface(), m_linkStatusSphre(1), m_pppErrCode(0), m_pStream(pStream), m_streamAvail(true), m_pppd(-1)
+PPPIPInterface::PPPIPInterface(IOStream* pStream) : LwIPInterface(), m_linkStatusSphre(1), m_pppErrCode(0), m_pStream(pStream), m_streamAvail(true), m_pppd(-1)
 {
-  m_connectCmd = new char[strlen(CONNECT_CMD_PREFIX) + strlen(msisdn) + strlen(CONNECT_CMD_SUFFIX) + 1];
-  sprintf(m_connectCmd, "%s%s%s", CONNECT_CMD_PREFIX, msisdn, CONNECT_CMD_SUFFIX);
-  m_expectedResp = new char[strlen(m_connectCmd) + strlen(EXPECTED_RESP_SUFFIX) + 1];
-  sprintf(m_expectedResp, "%s%s", m_connectCmd, EXPECTED_RESP_SUFFIX);
-  m_expectedRespDatarate = new char[strlen(m_connectCmd) + strlen(EXPECTED_RESP_DATARATE_SUFFIX) + 1];
-  sprintf(m_expectedRespDatarate, "%s%s", m_connectCmd, EXPECTED_RESP_DATARATE_SUFFIX);
   m_linkStatusSphre.wait();
 }
 
+
+
 /*virtual*/ PPPIPInterface::~PPPIPInterface()
 {
-  delete m_connectCmd;
-  delete m_expectedResp;
-  delete m_expectedRespDatarate;
 }
 
 /*virtual*/ int PPPIPInterface::init() //Init PPP-specific stuff, create the right bindings, etc
@@ -78,10 +71,11 @@
   return OK;
 }
 
-int PPPIPInterface::setup(const char* user, const char* pw)
+int PPPIPInterface::setup(const char* user, const char* pw, const char* msisdn)
 {
   DBG("Configuring PPP authentication method");
   pppSetAuth(PPPAUTHTYPE_ANY, user, pw);
+  m_msisdn = msisdn;
   DBG("Done");
   return OK;
 }
@@ -89,22 +83,22 @@
 /*virtual*/ int PPPIPInterface::connect()
 {
   int ret;
+  char cmd[32];
+  int cmdLen;
   char buf[32];
   size_t len;
   DBG("Trying to connect with PPP");
   
   cleanupLink();
   
-  DBG("Sending %s", m_connectCmd);
-  
-  ret = m_pStream->write((uint8_t*)m_connectCmd, strlen(m_connectCmd), osWaitForever);
+  cmdLen = sprintf(cmd, "%s%s%s", CONNECT_CMD_PREFIX, m_msisdn, CONNECT_CMD_SUFFIX);
+  DBG("Sending %s", cmd);
+  ret = m_pStream->write((uint8_t*)cmd, cmdLen, osWaitForever);
   if( ret != OK )
   {
     return NET_UNKNOWN;
   }
   
-  DBG("Expect %s", m_expectedResp);
-    
   len = 0;
   size_t readLen;
   ret = m_pStream->read((uint8_t*)buf + len, &readLen, EXPECTED_RESP_MIN_LEN, 10000);
@@ -128,16 +122,21 @@
   DBG("Got %s[len %d]", buf, len);
   
   int datarate = 0;
-  if( (sscanf(buf, m_expectedRespDatarate, &datarate ) != 1) && (strcmp(m_expectedResp, buf) != 0) )
+  strcpy(&cmd[cmdLen], EXPECTED_RESP_DATARATE_SUFFIX);
+  if( (sscanf(buf, cmd, &datarate ) != 1)) 
   {
-    //Discard buffer
-    do //Clear buf
+    strcpy(&cmd[cmdLen], EXPECTED_RESP_SUFFIX);
+    if (strcmp(cmd, buf) != 0)
     {
-      ret = m_pStream->read((uint8_t*)buf, &len, 32, 0);
-    } while( (ret == OK) && (len > 0) );
-    return NET_CONN;
-  }
-      
+      //Discard buffer
+      do //Clear buf
+      {
+        ret = m_pStream->read((uint8_t*)buf, &len, 32, 0);
+      } while( (ret == OK) && (len > 0) );
+      return NET_CONN;
+    }
+  }    
+  
   DBG("Transport link open");
   if(datarate != 0)
   {
--- a/ip/PPPIPInterface.h	Thu Oct 17 16:50:41 2013 +0300
+++ b/ip/PPPIPInterface.h	Mon Dec 16 09:00:24 2013 +0000
@@ -40,11 +40,11 @@
 class PPPIPInterface : public LwIPInterface
 {
 public:
-    PPPIPInterface(IOStream* pStream, const char* msisdn);
+    PPPIPInterface(IOStream* pStream);
     virtual ~PPPIPInterface();
 
     int init(); //Init PPP-specific stuff, create the right bindings, etc
-    int setup(const char* user, const char* pw); //Setup authentication
+    int setup(const char* user, const char* pw, const char* msisdn); //Setup authentication
     virtual int connect();
     virtual int disconnect();
 
@@ -57,16 +57,13 @@
 
     IOStream* m_pStream; //Serial stream
     bool m_streamAvail;
+    const char* m_msisdn;
 
     int m_pppd;
 
     friend u32_t sio_write(sio_fd_t fd, u8_t *data, u32_t len);
     friend u32_t sio_read(sio_fd_t fd, u8_t *data, u32_t len);
     friend void sio_read_abort(sio_fd_t fd);
-
-    char* m_connectCmd;
-    char* m_expectedResp;
-    char* m_expectedRespDatarate;
 };
 
 #endif /* PPPIPINTERFACE_H_ */