vvvv

Files at this revision

API Documentation at this revision

Comitter:
mazgch
Date:
Fri Aug 21 09:11:54 2015 +0000
Parent:
128:c1c27d0f53c5
Child:
130:7b747676de86
Commit message:
added the alternative way of activating the profile by cid

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 21 07:37:49 2015 +0000
+++ b/MDM.cpp	Fri Aug 21 09:11:54 2015 +0000
@@ -711,6 +711,63 @@
 // ----------------------------------------------------------------
 // internet connection 
 
+bool MDMParser::_activateProfile(const char* apn, const char* username, const char* password, Auth auth)
+{
+    // Set up the APN
+    if (*apn) {
+        sendFormated("AT+UPSD=" PROFILE ",1,\"%s\"\r\n", apn);
+        if (RESP_OK != waitFinalResp())
+            return false;
+    }
+    if (*username) {
+        sendFormated("AT+UPSD=" PROFILE ",2,\"%s\"\r\n", username);
+        if (RESP_OK != waitFinalResp())
+            return false;
+    }
+    if (*password) {
+        sendFormated("AT+UPSD=" PROFILE ",3,\"%s\"\r\n", password);
+        if (RESP_OK != waitFinalResp())
+            return false;
+    }
+    // Set up the dynamic IP address assignment.
+    sendFormated("AT+UPSD=" PROFILE ",7,\"0.0.0.0\"\r\n");
+    if (RESP_OK != waitFinalResp())
+        return false;
+    // try different Authentication Protocols
+    // 0 = none 
+    // 1 = PAP (Password Authentication Protocol)
+    // 2 = CHAP (Challenge Handshake Authentication Protocol)
+    for (int i = AUTH_NONE; i <= AUTH_CHAP; i ++) {
+        if ((auth == AUTH_DETECT) || (auth == i)) {
+            // Set up the Authentication Protocol
+            sendFormated("AT+UPSD=" PROFILE ",6,%d\r\n",i);
+            if (RESP_OK != waitFinalResp())
+                return false;
+            // Activate the profile and make connection
+            sendFormated("AT+UPSDA=" PROFILE ",3\r\n");
+            if (RESP_OK == waitFinalResp(NULL,NULL,150*1000))
+                return true;
+        }
+    }
+    return false;
+}
+
+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);
+    if (RESP_OK != waitFinalResp())
+        return false;
+    sendFormated("AT+UAUTHREQ=%d,%d,\"%s\",\"%s\"\r\n", cid, auth, username, password);
+    if (RESP_OK != waitFinalResp())
+        return false;
+    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));
+}
+ 
 MDMParser::IP MDMParser::join(const char* apn /*= NULL*/, const char* username /*= NULL*/, 
                               const char* password /*= NULL*/, Auth auth /*= AUTH_DETECT*/)
 {
@@ -753,12 +810,6 @@
             const char* config = NULL;
             if (!apn && !username && !password)
                 config = apnconfig(_dev.imsi);
-/**** NOT SUPPORTED YET ****/ if ((_dev.dev != DEV_TOBY_L2) && (_dev.dev != DEV_MPCI_L2)) {
-            // Set up the dynamic IP address assignment.
-            sendFormated("AT+UPSD=" PROFILE ",7,\"0.0.0.0\"\r\n");
-            if (RESP_OK != waitFinalResp())
-                goto failure;
-/**** NOT SUPPORTED YET ****/ }
             do {
                 if (config) {
                     apn      = _APN_GET(config);
@@ -771,40 +822,10 @@
                 password = password ? password : "";
                 auth = (*username && *password) ? auth : AUTH_NONE;
                 TRACE("Testing APN Settings(\"%s\",\"%s\",\"%s\",%d)\r\n", apn, username, password, auth);
-                // Set up the APN
-                if (*apn) {
-                    sendFormated("AT+UPSD=" PROFILE ",1,\"%s\"\r\n", apn);
-                    if (RESP_OK != waitFinalResp())
-                        goto failure;
-                }
-                if (*username) {
-                    sendFormated("AT+UPSD=" PROFILE ",2,\"%s\"\r\n", username);
-                    if (RESP_OK != waitFinalResp())
-                        goto failure;
-                }
-                if (*password) {
-                    sendFormated("AT+UPSD=" PROFILE ",3,\"%s\"\r\n", password);
-                    if (RESP_OK != waitFinalResp())
-                        goto failure;
-                }
-                // try different Authentication Protocols
-                // 0 = none 
-                // 1 = PAP (Password Authentication Protocol)
-                // 2 = CHAP (Challenge Handshake Authentication Protocol)
-                for (int i = AUTH_NONE; i <= AUTH_CHAP && !ok; i ++) {
-                    if ((auth == AUTH_DETECT) || (auth == i)) {
-/**** NOT SUPPORTED YET ****/ if ((_dev.dev != DEV_TOBY_L2) && (_dev.dev != DEV_MPCI_L2)) {
-                        // Set up the Authentication Protocol
-                        sendFormated("AT+UPSD=" PROFILE ",6,%d\r\n",i);
-                        if (RESP_OK != waitFinalResp())
-                            goto failure;
-/**** NOT SUPPORTED YET ****/ }
-                        // Activate the profile and make connection
-                        sendFormated("AT+UPSDA=" PROFILE ",3\r\n");
-                        if (RESP_OK == waitFinalResp(NULL,NULL,150*1000))
-                            ok = true;
-                    }
-                }
+                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);
             } 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 21 07:37:49 2015 +0000
+++ b/MDM.h	Fri Aug 21 09:11:54 2015 +0000
@@ -6,7 +6,7 @@
 #include "Pipe.h"
 #include "SerialPipe.h"
 
-#ifdef TARGET_UBLOX_C027
+#if 0 //def TARGET_UBLOX_C027
  #define MDM_IF(onboard,shield) onboard
 #else
  #define MDM_IF(onboard,shield) shield
@@ -520,6 +520,8 @@
     //! override the unlock in a rtos system
     virtual void unlock(void)      { } 
 protected:
+    bool _activateProfile(const char* apn, const char* username, const char* password, Auth auth);
+    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);
     static int _cbInt(int type, const char* buf, int len, int* val);