Add a bunch of APNs

Fork of C027_Support by Xinlei Cao

Revision:
26:07be5faf8925
Parent:
25:4045d02e44f1
Child:
27:e35f2118368f
--- a/MDM.cpp	Tue Apr 08 11:59:28 2014 +0000
+++ b/MDM.cpp	Tue Apr 08 13:52:07 2014 +0000
@@ -3,7 +3,7 @@
 #include "MDM.h"
 
 #define TRACE           (0)?:printf
-//#define DEBUG           
+#define DEBUG           
 #define PROFILE         "0"   // this is the psd profile used
 #define MAX_SIZE        256  // max expected messages
 // some helper 
@@ -27,14 +27,21 @@
 
 MDMParser::MDMParser(void)
 {
+    
+    // device info
     _model   = MODEL_UNKNOWN;
     _sim     = SIM_UNKNOWN;
+    *_ccid  = '\0';
+    *_imsi  = '\0';
+    *_imei  = '\0';
+    // network info
     _net     = NET_UNKNOWN;
     _act     = ACT_UNKNOWN;
-    _ip      = 0;
     _rssi    = 0;
     *_num    = '\0';
     *_opr    = '\0';
+    // data network info
+    _ip      = 0;
     for (int socket = 0; socket < sizeof(_sockets)/sizeof(*_sockets); socket++) {
         _sockets[socket].state = SOCK_FREE;
         _sockets[socket].pending = 0;
@@ -60,7 +67,10 @@
     return send(buf, len);
 }
 
-int MDMParser::waitFinalResp(_CB cb /*= NULL*/, void* param /*= NULL*/, int timeout_ms /*= 5000*/) {
+int MDMParser::waitFinalResp(_CALLBACKPTR cb /* = NULL*/, 
+                             void* param /* = NULL*/, 
+                             int timeout_ms /*= 5000*/)
+{
     char buf[MAX_SIZE];
     Timer timer;
     timer.start();
@@ -187,10 +197,13 @@
     if ((type == TYPE_UNKNOWN) && model) {
         if (strstr(buf, "SARA-G350")) {
             *model = MODEL_SARA_G350;
+            TRACE("Identified Model: SARA-G350 2G\n");
         } else if (strstr(buf, "LISA-U200")) {
             *model = MODEL_LISA_U200;
+            TRACE("Identified Model: LISA-U200 2G/3G\n");
         } else if (strstr(buf, "LISA-C200")) {
             *model= MODEL_LISA_C200;
+            TRACE("Identified Model: LISA-C200 CDMA\n");
         }
     }
     return WAIT;
@@ -217,23 +230,27 @@
     if (OK != waitFinalResp())
         return false;
     wait_ms(40);
-    // disable flow control
-    sendFormated("AT&K0\r\n");
-    if (OK != waitFinalResp())
-        return false;
     // identify the module 
     sendFormated("ATI\r\n");
-    if (OK != waitFinalResp((_CB)_cbATI, &_model))
+    if (OK != waitFinalResp(_cbATI, &_model))
         return false;
     if (_model == MODEL_UNKNOWN)
         return false;
     // model specific init
     if (_model == MODEL_LISA_C200) {
+        // disable flow control
+        sendFormated("AT+IFC=0,0\r\n");
+        if (OK != waitFinalResp())
+            return false;
         // Return the pseudo ESN or MEID
         sendFormated("AT+GSN\r\n");
+        if (OK != waitFinalResp(_cbGSN, _imei))
+            return false;
+    } else {
+        // disable flow control
+        sendFormated("AT&K0\r\n");
         if (OK != waitFinalResp())
             return false;
-    } else {
         // enable power saving
         sendFormated("AT+UPSV=1\r\n");
         if (OK != waitFinalResp())
@@ -269,11 +286,11 @@
         // Returns the ICCID (Integrated Circuit Card ID) of the SIM-card. 
         // ICCID is a serial number identifying the SIM.
         sendFormated("AT+CCID\r\n");
-        if (OK != waitFinalResp())
+        if (OK != waitFinalResp(_cbCCID, _ccid))
             return false;
         // Returns the product serial number, IMEI (International Mobile Equipment Identity)
         sendFormated("AT+CGSN\r\n");
-        if (OK != waitFinalResp())
+        if (OK != waitFinalResp(_cbCGSN, _imei))
             return false;
         // Setup SMS in text mode 
         sendFormated("AT+CMGF=1\r\n");
@@ -287,11 +304,47 @@
     } 
     // Request IMSI (International Mobile Subscriber Identification)
     sendFormated("AT+CIMI\r\n");
-    if (OK != waitFinalResp())
+    if (OK != waitFinalResp(_cbCIMI, _imsi))
         return false;
     return true; 
 }
 
+int MDMParser::_cbCCID(int type, const char* buf, int len, char* ccid)
+{
+    if ((type == TYPE_PLUS) && ccid){
+        if (sscanf(buf, "\r\n+CCID: %[^\r]\r\n", ccid) == 1)
+            TRACE("Got CCID: %s\n", ccid);
+    }
+    return WAIT;
+}
+
+int MDMParser::_cbGSN(int type, const char* buf, int len, char* imei)
+{
+    if ((type == TYPE_UNKNOWN) && imei){
+        if (sscanf(buf, "\r\n%[^\r]\r\n%*[^\r]\r\n", imei) == 1)
+            TRACE("Got IMEI: %s\n", imei);
+    }
+    return WAIT;
+}
+
+int MDMParser::_cbCGSN(int type, const char* buf, int len, char* imei)
+{
+    if ((type == TYPE_UNKNOWN) && imei){
+        if (sscanf(buf, "\r\n%[^\r]\r\n", imei) == 1)
+            TRACE("Got IMEI: %s\n", imei);
+    }
+    return WAIT;
+}
+
+int MDMParser::_cbCIMI(int type, const char* buf, int len, char* imsi)
+{
+    if ((type == TYPE_UNKNOWN) && imsi) {
+        if (sscanf(buf, "\r\n%[^\r]\r\n", imsi) == 1)
+            TRACE("Got IMSI: %s\n", imsi);
+    }
+    return WAIT;
+}
+
 bool MDMParser::checkNetStatus(Status* info /*= NULL*/)
 {
     // check registration
@@ -450,7 +503,7 @@
         return true;
     }
     sendFormated("AT+UDNSRN=0,\"%s\"\r\n", host);
-    if (OK != waitFinalResp((_CB)_cbUDNSRN, ip))
+    if (OK != waitFinalResp(_cbUDNSRN, ip))
         return false;
     return *ip != 0;
 }
@@ -480,7 +533,7 @@
     }
     sendFormated(cmd);
     int socket = -1;
-    if (OK != waitFinalResp((_CB)_cbUSOCR, &socket))
+    if (OK != waitFinalResp(_cbUSOCR, &socket))
         return SOCKET_ERROR;
     if (!ISSOCKET(socket) || (_sockets[socket].state != SOCK_FREE))
         return SOCKET_ERROR;
@@ -590,7 +643,7 @@
         if (len < blk) blk = len;
         if (blk) {
              sendFormated("AT+USORD=%d,%d\r\n",socket, blk);
-            if (OK != waitFinalResp((_CB)_cbUSORD, buf)) {
+            if (OK != waitFinalResp(_cbUSORD, buf)) {
                 return cnt ? cnt : SOCKET_ERROR;
             }
             len -= blk;
@@ -637,7 +690,7 @@
             sendFormated("AT+USORF=%d,%d\r\n",socket, blk);
             USORFparam param;
             param.buf = buf;
-            if (OK != waitFinalResp((_CB)_cbUSORF, &param)) {
+            if (OK != waitFinalResp(_cbUSORF, &param)) {
                 return cnt ? cnt : SOCKET_ERROR;
             }
             *ip = param.ip;
@@ -665,7 +718,7 @@
 {
     int num = 0;
     sendFormated("AT+CMGL=ALL\r\n");
-    if (OK != waitFinalResp((_CB)_cbCMGL,&num)) {
+    if (OK != waitFinalResp(_cbCMGL,&num)) {
         return false;
     }
     return true;
@@ -716,7 +769,7 @@
     param.num = num;
     param.buf = buf;
     sendFormated("AT+CMGR=%d\r\n",ix);
-    if (OK != waitFinalResp((_CB)_cbCMGR, &param)) {
+    if (OK != waitFinalResp(_cbCMGR, &param)) {
         return false;
     }
     return true;
@@ -738,13 +791,12 @@
 {
     *buf = '\0';
     sendFormated("AT+CUSD=1,\"%s\"\r\n",cmd);
-    if (OK != waitFinalResp((_CB)_cbCUSD, buf)) {
+    if (OK != waitFinalResp(_cbCUSD, buf)) {
         return -1;
     }
     return strlen(buf);
 }
-    
-   
+       
 // ----------------------------------------------------------------
 int MDMParser::_parseMatch(Pipe<char>* pipe, int len, const char* sta, const char* end)
 {