Skip to content

Commit 782617b

Browse files
ublox cellular context activation updated for C030_R412M
1 parent 9974899 commit 782617b

File tree

2 files changed

+137
-1
lines changed

2 files changed

+137
-1
lines changed

features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularContext.cpp

Lines changed: 133 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void UBLOX_AT_CellularContext::do_connect()
5151
_cb_data.error = NSAPI_ERROR_NO_CONNECTION;
5252

5353
// Attempt to establish a connection
54-
#ifdef TARGET_UBLOX_C030_R41XM
54+
#ifdef TARGET_UBLOX_C030_R410M
5555
_cb_data.error = NSAPI_ERROR_OK;
5656
#else
5757
_cb_data.error = open_data_channel();
@@ -72,6 +72,78 @@ void UBLOX_AT_CellularContext::do_connect()
7272
}
7373
}
7474

75+
#ifdef TARGET_UBLOX_C030_R412M
76+
nsapi_error_t UBLOX_AT_CellularContext::open_data_channel()
77+
{
78+
bool success = false;
79+
char *config = NULL;
80+
nsapi_error_t err = NSAPI_ERROR_NO_CONNECTION;
81+
char imsi[MAX_IMSI_LENGTH + 1];
82+
83+
// do check for stack to validate that we have support for stack
84+
_stack = get_stack();
85+
if (!_stack) {
86+
return err;
87+
}
88+
89+
_at.set_at_timeout(3*60*1000);
90+
_at.cmd_start("AT+CGATT=0");
91+
_at.cmd_stop();
92+
_at.resp_start();
93+
_at.resp_stop();
94+
_at.restore_at_timeout();
95+
96+
if (_at.get_last_error() == NSAPI_ERROR_OK) {
97+
_at.set_at_timeout(40*1000);
98+
_at.cmd_start("AT+CGACT=0");
99+
_at.cmd_stop();
100+
_at.resp_start();
101+
_at.resp_stop();
102+
_at.restore_at_timeout();
103+
104+
if (_at.get_last_error() == NSAPI_ERROR_OK) {
105+
if (_apn == NULL) {
106+
err = get_imsi(imsi);
107+
if (err == NSAPI_ERROR_OK) {
108+
config = (char *)apnconfig(imsi);
109+
}
110+
}
111+
112+
// Attempt to connect
113+
do {
114+
// Set up APN and IP protocol for PDP context
115+
get_next_credentials(&config);
116+
_auth = (*_uname && *_pwd) ? _auth : NSAPI_SECURITY_NONE;
117+
if (activate_profile(_apn, _uname, _pwd, _authentication_type)) {
118+
success = true;
119+
}
120+
} while (!success && config && *config);
121+
122+
if(success) {
123+
_at.set_at_timeout(3*60*1000);
124+
_at.cmd_start("AT+CGATT=1");
125+
_at.cmd_stop();
126+
_at.resp_start();
127+
_at.resp_stop();
128+
_at.restore_at_timeout();
129+
130+
if (_at.get_last_error() == NSAPI_ERROR_OK) {
131+
_at.set_at_timeout(150*1000);
132+
_at.cmd_start("AT+CGACT=1,1");
133+
_at.cmd_stop();
134+
_at.resp_start();
135+
_at.resp_stop();
136+
_at.restore_at_timeout();
137+
}
138+
}
139+
}
140+
}
141+
142+
err = (_at.get_last_error() == NSAPI_ERROR_OK) ? NSAPI_ERROR_OK : NSAPI_ERROR_NO_CONNECTION;
143+
144+
return err;
145+
}
146+
#else
75147
nsapi_error_t UBLOX_AT_CellularContext::open_data_channel()
76148
{
77149
bool success = false;
@@ -121,7 +193,60 @@ nsapi_error_t UBLOX_AT_CellularContext::open_data_channel()
121193

122194
return err;
123195
}
196+
#endif
124197

198+
#ifdef TARGET_UBLOX_C030_R412M
199+
bool UBLOX_AT_CellularContext::activate_profile(const char *apn,
200+
const char *username,
201+
const char *password,
202+
CellularContext::AuthenticationType auth)
203+
{
204+
bool success = false;
205+
int modem_security = nsapi_security_to_modem_security((nsapi_security_t)auth);
206+
207+
_at.cmd_start("AT+CGDCONT=1,");
208+
_at.write_string("IP");
209+
_at.write_string(apn);
210+
_at.cmd_stop();
211+
_at.resp_start();
212+
_at.resp_stop();
213+
214+
215+
if (_at.get_last_error() == NSAPI_ERROR_OK) {
216+
if (modem_security == NSAPI_SECURITY_CHAP) {
217+
_at.cmd_start("AT+UAUTHREQ=1,");
218+
_at.write_int(modem_security);
219+
_at.write_string(password);
220+
_at.write_string(username);
221+
_at.cmd_stop();
222+
_at.resp_start();
223+
_at.resp_stop();
224+
225+
} else if (modem_security == NSAPI_SECURITY_NONE) {
226+
_at.cmd_start("AT+UAUTHREQ=1,");
227+
_at.write_int(modem_security);
228+
_at.cmd_stop();
229+
_at.resp_start();
230+
_at.resp_stop();
231+
232+
} else {
233+
_at.cmd_start("AT+UAUTHREQ=1,");
234+
_at.write_int(modem_security);
235+
_at.write_string(username);
236+
_at.write_string(password);
237+
_at.cmd_stop();
238+
_at.resp_start();
239+
_at.resp_stop();
240+
}
241+
242+
if (_at.get_last_error() == NSAPI_ERROR_OK) {
243+
success = true;
244+
}
245+
}
246+
247+
return success;
248+
}
249+
#else
125250
bool UBLOX_AT_CellularContext::activate_profile(const char *apn,
126251
const char *username,
127252
const char *password)
@@ -222,6 +347,7 @@ bool UBLOX_AT_CellularContext::activate_profile(const char *apn,
222347

223348
return activated;
224349
}
350+
#endif
225351

226352
// Convert nsapi_security_t to the modem security numbers
227353
int UBLOX_AT_CellularContext::nsapi_security_to_modem_security(nsapi_security_t nsapi_security)
@@ -241,9 +367,15 @@ int UBLOX_AT_CellularContext::nsapi_security_to_modem_security(nsapi_security_t
241367
case NSAPI_SECURITY_UNKNOWN:
242368
modem_security = 3;
243369
break;
370+
#ifdef TARGET_UBLOX_C030_R412M
371+
default:
372+
modem_security = 0;
373+
break;
374+
#else
244375
default:
245376
modem_security = 3;
246377
break;
378+
#endif
247379
}
248380

249381
return modem_security;

features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularContext.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ class UBLOX_AT_CellularContext: public AT_CellularContext {
5858
* NSAPI_SECURITY_CHAP or NSAPI_SECURITY_UNKNOWN).
5959
* @return True if successful, otherwise false.
6060
*/
61+
#ifdef TARGET_UBLOX_C030_R412M
62+
bool activate_profile(const char *apn, const char *username, const char *password, CellularContext::AuthenticationType auth);
63+
#else
6164
bool activate_profile(const char *apn, const char *username, const char *password);
65+
#endif
6266

6367
/** Convert nsapi_security_t to the modem security numbers.
6468
*

0 commit comments

Comments
 (0)