Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of C027_Support by
Diff: MDM.cpp
- Revision:
- 128:0415646a9934
- Parent:
- 127:c1c27d0f53c5
- Child:
- 130:3189949981ec
--- 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");