@@ -51,7 +51,7 @@ void UBLOX_AT_CellularContext::do_connect()
51
51
_cb_data.error = NSAPI_ERROR_NO_CONNECTION;
52
52
53
53
// Attempt to establish a connection
54
- #ifdef TARGET_UBLOX_C030_R41XM
54
+ #ifdef TARGET_UBLOX_C030_R410M
55
55
_cb_data.error = NSAPI_ERROR_OK;
56
56
#else
57
57
_cb_data.error = open_data_channel ();
@@ -72,6 +72,78 @@ void UBLOX_AT_CellularContext::do_connect()
72
72
}
73
73
}
74
74
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
75
147
nsapi_error_t UBLOX_AT_CellularContext::open_data_channel ()
76
148
{
77
149
bool success = false ;
@@ -121,7 +193,60 @@ nsapi_error_t UBLOX_AT_CellularContext::open_data_channel()
121
193
122
194
return err;
123
195
}
196
+ #endif
124
197
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
125
250
bool UBLOX_AT_CellularContext::activate_profile (const char *apn,
126
251
const char *username,
127
252
const char *password)
@@ -222,6 +347,7 @@ bool UBLOX_AT_CellularContext::activate_profile(const char *apn,
222
347
223
348
return activated;
224
349
}
350
+ #endif
225
351
226
352
// Convert nsapi_security_t to the modem security numbers
227
353
int UBLOX_AT_CellularContext::nsapi_security_to_modem_security (nsapi_security_t nsapi_security)
@@ -238,12 +364,18 @@ int UBLOX_AT_CellularContext::nsapi_security_to_modem_security(nsapi_security_t
238
364
case NSAPI_SECURITY_CHAP:
239
365
modem_security = 2 ;
240
366
break ;
367
+ #ifndef TARGET_UBLOX_C030_R41XM
241
368
case NSAPI_SECURITY_UNKNOWN:
242
369
modem_security = 3 ;
243
370
break ;
244
371
default :
245
372
modem_security = 3 ;
246
373
break ;
374
+ #else
375
+ default :
376
+ modem_security = 0 ;
377
+ break ;
378
+ #endif
247
379
}
248
380
249
381
return modem_security;
0 commit comments