vvvv

Dependents:   02_DPPU_JUANDA_120 02_DPPU_JUANDA_120_Latest_copy 02_DPPU_JUANDA_120_Latest

Files at this revision

API Documentation at this revision

Comitter:
mazgch
Date:
Tue Sep 01 15:50:06 2015 +0000
Parent:
131:3189949981ec
Child:
133:de505da3aadf
Commit message:
re-use context in LTE

Changed in this revision

MDM.cpp Show annotated file Show diff for this revision Revisions of this file
MDM.h Show annotated file Show diff for this revision Revisions of this file
--- a/MDM.cpp	Fri Aug 28 12:40:05 2015 +0000
+++ b/MDM.cpp	Tue Sep 01 15:50:06 2015 +0000
@@ -752,6 +752,23 @@
     return false;
 }
 
+bool MDMParser::_activateProfileReuseExternal(void)
+{
+    int cid = -1;
+    sendFormated("AT+CGDCONT?\r\n");
+    if (RESP_OK != waitFinalResp(_cbCGDCONT, &cid))
+        return false;
+    if (cid == -1)
+        return false;
+    // we found a context that provides us a valid IP so lets reuse it for the internal IP stack
+    sendFormated("AT+UPSD=" PROFILE ",100,%d\r\n", cid);
+    if (RESP_OK != waitFinalResp())
+        return false;
+    // Activate the profile and make connection
+    sendFormated("AT+UPSDA=" PROFILE ",3\r\n");
+    return (RESP_OK == waitFinalResp(NULL,NULL,150*1000));
+}
+
 bool MDMParser::_activateProfileByCid(int cid, const char* apn, const char* username, const char* password, Auth auth)
 {
     sendFormated("AT+CGDCONT=%d,\"IP\",\"%s\"\r\n", cid, apn);
@@ -768,6 +785,22 @@
     return (RESP_OK == waitFinalResp(NULL,NULL,150*1000));
 }
  
+int MDMParser::_cbCGDCONT(int type, const char* buf, int len, int* cid)
+{
+    // accept with and without leading \r\n in +CGDCONT:
+    if ((type == TYPE_PLUS) && (buf[0] == '\r') && (buf[1] == '\n') && (len >= 2))
+        buf += 2, len -= 2, type = TYPE_UNKNOWN;
+    if (type == TYPE_UNKNOWN) {
+        int a,b,c,d,t;
+        //+CGDCONT: <cid>,"IP","<apn name>","<ip adr>",0,0,0,0,0,0
+        if (sscanf(buf, "+CGDCONT: %d,\"IP\",\"%*[^\"]\",\"" IPSTR "\",%*d,%*d,%*d,%*d,%*d,%*d", &t, &a,&b,&c,&d) == 5) {
+            if (IPADR(a,b,c,d) != NOIP) 
+                *cid = t;
+        }
+    }
+    return WAIT;
+}
+
 MDMParser::IP MDMParser::join(const char* apn /*= NULL*/, const char* username /*= NULL*/, 
                               const char* password /*= NULL*/, Auth auth /*= AUTH_DETECT*/)
 {
@@ -824,8 +857,13 @@
                 TRACE("Testing APN Settings(\"%s\",\"%s\",\"%s\",%d)\r\n", apn, username, password, auth);
                 if ((_dev.dev != DEV_TOBY_L2) && (_dev.dev != DEV_MPCI_L2))
                     ok = _activateProfile(apn, username, password, auth);
-                else
-                    ok = _activateProfileByCid(1, apn, username, password, auth);
+                else {
+                    ok = _activateProfileReuseExternal();
+                    if (ok) 
+                        TRACE("Reusing External Context\r\n");
+                    else
+                        ok = _activateProfileByCid(1, apn, username, password, auth);
+                }
             } while (!ok && config && *config); // maybe use next setting ? 
             if (!ok) {
                 ERROR("Your modem APN/password/username may be wrong\r\n");
--- a/MDM.h	Fri Aug 28 12:40:05 2015 +0000
+++ b/MDM.h	Tue Sep 01 15:50:06 2015 +0000
@@ -522,6 +522,7 @@
     virtual void unlock(void)      { } 
 protected:
     bool _activateProfile(const char* apn, const char* username, const char* password, Auth auth);
+    bool _activateProfileReuseExternal(void);
     bool _activateProfileByCid(int cid, const char* apn, const char* username, const char* password, Auth auth);
     // parsing callbacks for different AT commands and their parameter arguments
     static int _cbString(int type, const char* buf, int len, char* str);
@@ -535,6 +536,7 @@
     static int _cbCOPS(int type, const char* buf, int len, NetStatus* status);
     static int _cbCNUM(int type, const char* buf, int len, char* num);
     static int _cbUACTIND(int type, const char* buf, int len, int* i);
+    static int _cbCGDCONT(int type, const char* buf, int len, int* cid);
     static int _cbUDOPN(int type, const char* buf, int len, char* mccmnc);
     // sockets
     static int _cbCMIP(int type, const char* buf, int len, IP* ip);