Added HTTP API to C027_Support library.

Fork of C027_Support by u-blox

Files at this revision

API Documentation at this revision

Comitter:
mazgch
Date:
Fri Jun 06 10:33:13 2014 +0000
Parent:
87:64f54572ea74
Child:
89:ea396f9f90a2
Commit message:
improve apn lookup

Changed in this revision

MDM.cpp Show annotated file Show diff for this revision Revisions of this file
MDMAPN.h Show annotated file Show diff for this revision Revisions of this file
--- a/MDM.cpp	Fri Jun 06 09:00:03 2014 +0000
+++ b/MDM.cpp	Fri Jun 06 10:33:13 2014 +0000
@@ -529,13 +529,11 @@
     _net.ci = 0xFFFFFFFF;
     // check registration
     sendFormated("AT+CREG?\r\n");
-    if (RESP_OK != waitFinalResp())
-        return false;
+    waitFinalResp();     // don't fail as service could be not subscribed 
     if (_dev.dev != DEV_LISA_C200) {
         // check PSD registration
         sendFormated("AT+CGREG?\r\n");
-        if (RESP_OK != waitFinalResp())
-            return false;
+        waitFinalResp(); // don't fail as service could be not subscribed 
     }
     if (REG_OK(_net.csd) || REG_OK(_net.psd))
     {
@@ -700,23 +698,8 @@
             bool ok = false;
             // try to lookup the apn settings from our local database by mccmnc
             const char* config = NULL;
-            if (!apn && !username && !password) {
-                char mccmnc[8] = "";
-                config = apndef;
-                sendFormated("AT+UDOPN=0\r\n");
-                if ((RESP_OK == waitFinalResp(_cbUDOPN, mccmnc)) && *mccmnc) {
-                    TRACE("Lookup APN Settings for network \"%s\" from operator \"%s\"\r\n", 
-                            mccmnc, _net.opr);
-                    // many carriers use internet without username and password, os use this as default
-                    // now try to lookup the setting for our table
-                    for (int i = 0; i < sizeof(apnlut)/sizeof(*apnlut); i ++) {
-                        if (strstr(apnlut[i].mccmnc, mccmnc)) {
-                            config = apnlut[i].cfg;
-                            break;
-                        }
-                    }
-                }
-            }
+            if (!apn && !username && !password)
+                config = apnconfig(_dev.imsi);
             
             // Set up the dynamic IP address assignment.
             sendFormated("AT+UPSD=" PROFILE ",7,\"0.0.0.0\"\r\n");
--- a/MDMAPN.h	Fri Jun 06 09:00:03 2014 +0000
+++ b/MDMAPN.h	Fri Jun 06 10:33:13 2014 +0000
@@ -34,22 +34,66 @@
 
 //! this is a list of special APNs for different network operators 
 static const APN_t apnlut[] = {
+// MCC Country
+//  { /* Operator */ "MCC-MNC[,MNC]" _APN(APN,USERNAME,PASSWORD) },
+// MCC must be 3 digits
+// MNC must be either 2 or 3 digits
 
-// Germany 
-    { /*T-Mobile*/ "26201",     _APN("internet.t-mobile","t-mobile","tm") },
+// 262 Germany 
+    { /* T-Mobile */ "262-01",  _APN("internet.t-mobile","t-mobile","tm") },
+
+// 222 Italy
+    { /* TIM */      "222-01",  _APN("ibox.tim.it",,) },
+    { /* Vodafone */ "222-10",  _APN("web.omnitel.it",,) },
 
-// Switzerland
-    { /*Swisscom*/ "22801",     _APN("gprs.swisscom.ch",,) },
-    { /*Orange*/   "22803",     _APN("internet",,) /* post-paid */ 
-                                _APN("click",,)    /* pre-paid */ },
-    
-// USA
-    { /*T-Mobile*/ "310026|310260|310490",
+// 228 Switzerland
+    { /* Swisscom */ "228-01",  _APN("gprs.swisscom.ch",,) },
+    { /* Orange */   "228-03",  _APN("internet",,) /* contract */ 
+                                _APN("click",,)    /* pre-pay */ },
+
+// 234 United Kingdom - GB
+    { /* O2 */       "234-02,10,11",
+                                _APN("mobile.o2.co.uk","faster","web") /* contract */
+                                _APN("mobile.o2.co.uk","bypass","web") /* pre-pay */ 
+                                _APN("payandgo.o2.co.uk","payandgo","payandgo") },
+    { /* Vodafone */ "234-15",  _APN("internet","web","web")          /* contract */
+                                _APN("pp.vodafone.co.uk","wap","wap")  /* pre-pay */ },
+
+// 310 USA
+    { /* T-Mobile */ "310-026,260,490",
                                 _APN("epc.tmobile.com",,) 
-                                _APN("fast.tmobile.com",,) /*LTE*/ },
-    { /*AT&T*/     "310030|310150|310170|310260|310410|310560|310680",
+                                _APN("fast.tmobile.com",,) /* LTE */ },
+    { /* AT&T */     "310-030,150,170,260,410,560,680",
                                 _APN("phone",,)
                                 _APN("wap.cingular","WAP@CINGULARGPRS.COM","CINGULAR1")
                                 _APN("isp.cingular","ISP@CINGULARGPRS.COM","CINGULAR1") },
-    // ...     
 };
+
+inline const char* apnconfig(const char* imsi)
+{
+    const char* config = NULL;
+    if (imsi && *imsi) {
+        // many carriers use internet without username and password, os use this as default
+        // now try to lookup the setting for our table
+        for (int i = 0; i < sizeof(apnlut)/sizeof(*apnlut) && !config; i ++) {
+            const char* p = apnlut[i].mccmnc;
+            // check the MCC
+            if ((0 == memcmp(imsi, p, 3))) {
+                p += 3;
+                // check all the MNC, MNC length can be 2 or 3 digits
+                while (((p[0] == '-') || (p[0] == ',')) && 
+                        (p[1] >= '0') && (p[1] <= '9') && 
+                        (p[2] >= '0') && (p[2] <= '9') && !config) {
+                    int l = ((p[3] >= '0') && (p[3] <= '9')) ? 3 : 2;
+                    if (0 == memcmp(imsi+3,p+1,l))
+                        config = apnlut[i].cfg;
+                    p += 1 + l;
+                } 
+            }
+        }
+    }
+    // use default if not found
+    if (!config)
+        config = apndef;
+    return config;
+}
\ No newline at end of file