31
31
#error [NOT_SUPPORTED] SIM pin code is needed. Skipping this build.
32
32
#endif
33
33
34
+ #if defined(TARGET_ADV_WISE_1570) || defined(TARGET_MTB_ADV_WISE_1570)
35
+ #error [NOT_SUPPORTED] target MTB_ADV_WISE_1570 is too unstable for network tests, IoT network is unstable
36
+ #endif
37
+
34
38
#include " greentea-client/test_env.h"
35
39
#include " unity.h"
36
40
#include " utest.h"
37
41
38
42
#include " mbed.h"
39
43
40
44
#include " AT_CellularNetwork.h"
41
- #include " CellularConnectionFSM .h"
45
+ #include " CellularContext .h"
42
46
#include " CellularDevice.h"
43
47
#include " ../../cellular_tests_common.h"
44
48
#include CELLULAR_STRINGIFY(CELLULAR_DEVICE.h)
45
49
46
50
#define NETWORK_TIMEOUT (180 *1000 )
47
51
48
- static UARTSerial cellular_serial (MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
49
- static EventQueue queue (8 * EVENTS_EVENT_SIZE);
50
- static rtos::Semaphore network_semaphore (0 );
51
- static CellularConnectionFSM cellular;
52
- static CellularConnectionFSM::CellularState cellular_target_state;
53
- static CELLULAR_DEVICE *device;
52
+ static CellularContext *ctx;
53
+ static CellularDevice *device;
54
54
static CellularNetwork *nw;
55
55
56
-
57
- static bool fsm_callback (int state, int next_state)
58
- {
59
- if (next_state == cellular_target_state) {
60
- TEST_ASSERT (network_semaphore.release () == osOK);
61
- return false ;
62
- }
63
- return true ;
64
- }
65
-
66
- // test methods that are already run in state machine (CellularConnectionFSM) but as it might change
67
- // we wan't to run these 'manually' also
68
- static void test_network_interface_fsm ()
69
- {
70
- #if defined (MDMRTS) && defined (MDMCTS)
71
- cellular_serial.set_flow_control (SerialBase::RTSCTS, MDMRTS, MDMCTS);
72
- #endif
73
- device = new CELLULAR_DEVICE (queue);
74
- TEST_ASSERT (device != NULL );
75
-
76
- CellularNetwork *nw = device->open_network (&cellular_serial);
77
- TEST_ASSERT (nw != NULL );
78
- TEST_ASSERT (nw->init () == NSAPI_ERROR_OK);
79
-
80
- delete device;
81
- device = NULL ;
82
- }
83
-
84
56
static void init_network_interface ()
85
57
{
86
- cellular.set_serial (&cellular_serial);
87
- TEST_ASSERT (cellular.init () == NSAPI_ERROR_OK);
88
- cellular.set_callback (&fsm_callback);
89
- TEST_ASSERT (cellular.start_dispatch () == NSAPI_ERROR_OK);
90
- cellular.set_sim_pin (MBED_CONF_APP_CELLULAR_SIM_PIN);
58
+ ctx = CellularContext::get_default_instance ();
59
+ TEST_ASSERT (ctx != NULL );
60
+ ctx->set_sim_pin (MBED_CONF_APP_CELLULAR_SIM_PIN);
91
61
#ifdef MBED_CONF_APP_APN
92
- CellularNetwork *network = cellular.get_network ();
93
- TEST_ASSERT (network->set_credentials (MBED_CONF_APP_APN) == NSAPI_ERROR_OK);
62
+ ctx->set_credentials (MBED_CONF_APP_APN);
94
63
#endif
95
- cellular_target_state = CellularConnectionFSM::STATE_REGISTERING_NETWORK;
96
- TEST_ASSERT (cellular.continue_to_state (cellular_target_state) == NSAPI_ERROR_OK);
97
- TEST_ASSERT (network_semaphore.wait (NETWORK_TIMEOUT) == 1 );
98
- }
64
+ TEST_ASSERT (ctx->register_to_network () == NSAPI_ERROR_OK);
99
65
66
+ device = CellularDevice::get_default_instance ();
67
+ TEST_ASSERT (device != NULL );
68
+ }
100
69
101
70
static bool get_network_registration (CellularNetwork::RegistrationType type,
102
71
CellularNetwork::RegistrationStatus &status, bool &is_registered)
@@ -149,8 +118,8 @@ static void nw_callback(nsapi_event_t ev, intptr_t intptr)
149
118
150
119
static void test_network_registration ()
151
120
{
152
- cellular. get_device () ->set_timeout (10 * 1000 );
153
- nw = cellular. get_network ();
121
+ device ->set_timeout (10 * 1000 );
122
+ nw = device-> open_network ();
154
123
TEST_ASSERT (nw != NULL );
155
124
156
125
nw->attach (&nw_callback);
@@ -194,97 +163,22 @@ static void test_attach()
194
163
TEST_ASSERT (status == CellularNetwork::Attached);
195
164
}
196
165
197
- static void test_activate_context ()
198
- {
199
- TEST_ASSERT (nw->activate_context () == NSAPI_ERROR_OK);
200
- }
201
-
202
- static void test_connect ()
203
- {
204
- TEST_ASSERT (nw->connect () == NSAPI_ERROR_OK);
205
- char count = 0 ;
206
- while ((nw->get_connection_status () != NSAPI_STATUS_GLOBAL_UP) && (count++ < 60 )) {
207
- wait (1 );
208
- }
209
- nsapi_connection_status_t st = nw->get_connection_status ();
210
- TEST_ASSERT (st == NSAPI_STATUS_GLOBAL_UP);
211
- }
212
-
213
- static void test_credentials ()
214
- {
215
- nsapi_error_t err = nw->set_credentials (NULL , " username" , " pass" );
216
- TEST_ASSERT (err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
217
- err = nw->set_credentials (" internet" , " user" , NULL );
218
- TEST_ASSERT (err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
219
- err = nw->set_credentials (" internet" , CellularNetwork::NOAUTH, " user" , " pass" );
220
- TEST_ASSERT (err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
221
- TEST_ASSERT (nw->set_credentials (" internet" , NULL , " pass" ) == NSAPI_ERROR_OK);
222
- }
223
-
224
166
static void test_other ()
225
167
{
226
168
const char *devi = CELLULAR_STRINGIFY (CELLULAR_DEVICE);
227
169
TEST_ASSERT (nw->get_3gpp_error () == 0 );
228
170
229
- CellularNetwork::RateControlExceptionReports reports;
230
- CellularNetwork::RateControlUplinkTimeUnit timeUnit;
231
- int uplinkRate;
232
- // can't test values as they are optional
233
- nsapi_error_t err = nw->get_rate_control (reports, timeUnit, uplinkRate);
234
- TEST_ASSERT (err == NSAPI_ERROR_OK || err == NSAPI_ERROR_DEVICE_ERROR);
235
- if (strcmp (devi, " QUECTEL_BG96" ) != 0 && strcmp (devi, " TELIT_HE910" ) != 0 && strcmp (devi, " SARA4_PPP" ) != 0 ) { // QUECTEL_BG96 does not give any specific reason for device error
236
- if (err == NSAPI_ERROR_DEVICE_ERROR) {
237
- TEST_ASSERT (((AT_CellularNetwork *)nw)->get_device_error ().errCode == 100 && // 100 == unknown command for modem
238
- ((AT_CellularNetwork *)nw)->get_device_error ().errType == 3 ); // 3 == CME error from the modem
239
- }
240
- }
241
-
242
- uplinkRate = -1 ;
243
- err = nw->get_apn_backoff_timer (uplinkRate);
244
- TEST_ASSERT (err == NSAPI_ERROR_OK || err == NSAPI_ERROR_DEVICE_ERROR || err == NSAPI_ERROR_PARAMETER);
245
- if (err == NSAPI_ERROR_DEVICE_ERROR) {
246
- if (strcmp (devi, " QUECTEL_BG96" ) != 0 && strcmp (devi, " TELIT_HE910" ) != 0 && strcmp (devi, " SARA4_PPP" ) != 0 ) { // QUECTEL_BG96 does not give any specific reason for device error
247
- TEST_ASSERT (((AT_CellularNetwork *)nw)->get_device_error ().errCode == 100 && // 100 == unknown command for modem
248
- ((AT_CellularNetwork *)nw)->get_device_error ().errType == 3 ); // 3 == CME error from the modem
249
- }
250
- } else if (err == NSAPI_ERROR_PARAMETER) {
251
- TEST_ASSERT (uplinkRate == -1 );
252
- } else {
253
- TEST_ASSERT (uplinkRate >= 0 );
254
- }
255
-
256
- err = nw->set_access_technology (CellularNetwork::RAT_GSM);
171
+ nsapi_error_t err = nw->set_access_technology (CellularNetwork::RAT_GSM);
257
172
TEST_ASSERT (err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED);
258
173
259
174
// scanning of operators requires some delay before operation is allowed(seen with WISE_1570)
260
175
wait (5 );
261
176
// scanning of operators might take a long time
262
- cellular. get_device () ->set_timeout (240 * 1000 );
177
+ device ->set_timeout (240 * 1000 );
263
178
CellularNetwork::operList_t operators;
179
+ int uplinkRate = -1 ;
264
180
TEST_ASSERT (nw->scan_plmn (operators, uplinkRate) == NSAPI_ERROR_OK);
265
- cellular.get_device ()->set_timeout (10 * 1000 );
266
-
267
-
268
- // all current targets support IPV4
269
- nsapi_ip_stack_t stack_type = IPV4_STACK;
270
- TEST_ASSERT (nw->set_stack_type (stack_type) == NSAPI_ERROR_OK);
271
- TEST_ASSERT (nw->get_stack_type () == stack_type);
272
-
273
- CellularNetwork::pdpContextList_t params_list;
274
- err = nw->get_pdpcontext_params (params_list);
275
-
276
- TEST_ASSERT (err == NSAPI_ERROR_OK || err == NSAPI_ERROR_DEVICE_ERROR);
277
- if (err == NSAPI_ERROR_DEVICE_ERROR) {
278
- if (strcmp (devi, " TELIT_HE910" ) != 0 ) { // TELIT_HE910 just gives an error and no specific error number so we can't know is this real error or that modem/network does not support the command
279
- TEST_ASSERT ((((AT_CellularNetwork *)nw)->get_device_error ().errType == 3 ) && // 3 == CME error from the modem
280
- ((((AT_CellularNetwork *)nw)->get_device_error ().errCode == 100 ) || // 100 == unknown command for modem
281
- (((AT_CellularNetwork *)nw)->get_device_error ().errCode == 50 ))); // 50 == incorrect parameters // seen in wise_1570 for not supported commands
282
- }
283
- } else {
284
- // should have some values, only not optional are apn and bearer id
285
- CellularNetwork::pdpcontext_params_t *params = params_list.get_head ();
286
- TEST_ASSERT (params->bearer_id >= 0 )
287
- }
181
+ device->set_timeout (10 * 1000 );
288
182
289
183
int rxlev = -1 , ber = -1 , rscp = -1 , ecno = -1 , rsrq = -1 , rsrp = -1 ;
290
184
err = nw->get_extended_signal_quality (rxlev, ber, rscp, ecno, rsrq, rsrp);
@@ -328,8 +222,6 @@ static void test_other()
328
222
nsapi_connection_status_t st = nw->get_connection_status ();
329
223
TEST_ASSERT (st == NSAPI_STATUS_DISCONNECTED);
330
224
331
- TEST_ASSERT (nw->set_blocking (true ) == NSAPI_ERROR_OK);
332
-
333
225
#ifndef TARGET_UBLOX_C027 // AT command is supported, but excluded as it runs out of memory easily (there can be very many operator names)
334
226
if (strcmp (devi, " QUECTEL_BG96" ) != 0 && strcmp (devi, " SARA4_PPP" ) != 0 ) {
335
227
// QUECTEL_BG96 timeouts with this one, tested with 3 minute timeout
@@ -378,15 +270,6 @@ static void test_other()
378
270
}
379
271
}
380
272
381
- static void test_disconnect ()
382
- {
383
- nsapi_connection_status_t st = nw->get_connection_status ();
384
- TEST_ASSERT (st == NSAPI_STATUS_GLOBAL_UP);
385
- TEST_ASSERT (nw->disconnect () == NSAPI_ERROR_OK);
386
- // wait to process URC's, received after disconnect
387
- rtos::ThisThread::sleep_for (500 );
388
- }
389
-
390
273
static void test_detach ()
391
274
{
392
275
// in PPP mode there is NO CARRIER waiting so flush it out
@@ -412,17 +295,11 @@ static utest::v1::status_t greentea_failure_handler(const Case *const source, co
412
295
}
413
296
414
297
static Case cases[] = {
415
- Case (" CellularNetwork state machine methods" , test_network_interface_fsm, greentea_failure_handler),
416
298
Case (" CellularNetwork init" , init_network_interface, greentea_failure_handler),
417
299
Case (" CellularNetwork test registering" , test_network_registration, greentea_failure_handler),
418
300
Case (" CellularNetwork test attach" , test_attach, greentea_failure_handler),
419
- Case (" CellularNetwork test activate pdp context" , test_activate_context, greentea_failure_handler),
420
301
Case (" CellularNetwork test other functions" , test_other, greentea_failure_handler),
421
- Case (" CellularNetwork test connect" , test_connect, greentea_failure_handler),
422
- Case (" CellularNetwork test credentials" , test_credentials, greentea_failure_handler),
423
- Case (" CellularNetwork test disconnect" , test_disconnect, greentea_failure_handler),
424
302
Case (" CellularNetwork test detach" , test_detach, greentea_failure_handler)
425
-
426
303
};
427
304
428
305
static utest::v1::status_t test_setup (const size_t number_of_cases)
0 commit comments