Skip to content

Commit 1a047ef

Browse files
author
Teppo Järvelin
committed
Cellular: review fixes, added missing fixes from master.
1 parent 467ae09 commit 1a047ef

28 files changed

+118
-78
lines changed

UNITTESTS/stubs/AT_CellularContext_stub.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ nsapi_error_t AT_CellularContext::set_blocking(bool blocking)
105105
{
106106
return NSAPI_ERROR_OK;
107107
}
108+
109+
void AT_CellularContext::set_plmn(const char *plmn)
110+
{
111+
}
112+
108113
void AT_CellularContext::set_sim_pin(const char *sim_pin)
109114
{
110115
}

UNITTESTS/stubs/CellularDevice_stub.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ events::EventQueue *CellularDevice::get_queue()
4141
return NULL;
4242
}
4343

44+
void CellularDevice::set_plmn(char const*)
45+
{
46+
}
47+
4448
void CellularDevice::set_sim_pin(char const*)
4549
{
4650
}

features/cellular/framework/API/CellularContext.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,6 @@ class CellularContext : public CellularBase {
2828
// max simultaneous PDP contexts active
2929
static const int PDP_CONTEXT_COUNT = 4;
3030

31-
/** Get the default cellular interface.
32-
*
33-
* This is provided as a weak method so applications can override.
34-
* Default behaviour is to get the target's default interface, if
35-
* any.
36-
*
37-
* @return pointer to interface, if any.
38-
*/
39-
static CellularBase *get_default_instance();
40-
4131
/* authentication type when activating or modifying the pdp context */
4232
enum AuthenticationType {
4333
NOAUTH = 0,
@@ -119,15 +109,18 @@ class CellularContext : public CellularBase {
119109
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb) = 0;
120110
virtual nsapi_error_t connect() = 0;
121111
virtual nsapi_error_t disconnect() = 0;
122-
virtual bool is_connected() = 0;
123112

124113
// from CellularBase
114+
virtual void set_plmn(const char *plmn) = 0;
125115
virtual void set_sim_pin(const char *sim_pin) = 0;
126116
virtual nsapi_error_t connect(const char *sim_pin, const char *apn = 0, const char *uname = 0,
127117
const char *pwd = 0) = 0;
128118
virtual void set_credentials(const char *apn, const char *uname = 0, const char *pwd = 0) = 0;
129119
virtual const char *get_netmask() = 0;
130120
virtual const char *get_gateway() = 0;
121+
virtual bool is_connected() = 0;
122+
static CellularBase *get_default_instance();
123+
131124

132125
// Operations, can be sync/async. Also Connect() is this kind of operations, inherited from NetworkInterface above.
133126

features/cellular/framework/API/CellularDevice.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,11 @@ class CellularDevice {
242242
protected:
243243
friend class AT_CellularNetwork;
244244
friend class AT_CellularContext;
245-
/** Cellular callback which is called by Network class after this class attaches to it, CellularStateMachine
246-
* and CellularContext when in PPP mode. This method will broadcast to every interested classes:
245+
246+
/** Cellular callback to be attached to Network and CellularStateMachine classes.
247+
* CellularContext calls this when in PPP mode to provide network changes.
248+
* This method will broadcast to every interested classes:
247249
* CellularContext (might be many) and CellularStateMachine if available.
248-
*
249250
*/
250251
void cellular_callback(nsapi_event_t ev, intptr_t ptr);
251252

features/cellular/framework/AT/AT_CellularContext.cpp

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
#include "UARTSerial.h"
2525
#include "mbed_wait_api.h"
2626

27+
#define NETWORK_TIMEOUT 30 * 60 * 1000 // 30 minutes
28+
#define DEVICE_TIMEOUT 5 * 60 * 1000 // 5 minutes
29+
2730
#if NSAPI_PPP_AVAILABLE
2831
#include "nsapi_ppp.h"
2932
#endif
@@ -141,9 +144,9 @@ nsapi_error_t AT_CellularContext::check_operation(nsapi_error_t err, ContextOper
141144

142145
uint32_t AT_CellularContext::get_timeout_for_operation(ContextOperation op) const
143146
{
144-
uint32_t timeout = 10 * 60 * 1000; // default timeout is 10 minutes as registration and attach may take time
147+
uint32_t timeout = NETWORK_TIMEOUT; // default timeout is 30 minutes as registration and attach may take time
145148
if (op == OP_SIM_READY || op == OP_DEVICE_READY) {
146-
timeout = 3 * 60 * 1000; // use 3 minutes for device ready and sim
149+
timeout = DEVICE_TIMEOUT; // use 5 minutes for device ready and sim
147150
}
148151
return timeout;
149152
}
@@ -204,6 +207,11 @@ nsapi_error_t AT_CellularContext::set_blocking(bool blocking)
204207
return err;
205208
}
206209

210+
void AT_CellularContext::set_plmn(const char *plmn)
211+
{
212+
_device->set_plmn(plmn);
213+
}
214+
207215
void AT_CellularContext::set_sim_pin(const char *sim_pin)
208216
{
209217
_device->set_sim_pin(sim_pin);
@@ -260,9 +268,7 @@ nsapi_error_t AT_CellularContext::delete_current_context()
260268
_at.clear_error();
261269
_at.cmd_start("AT+CGDCONT=");
262270
_at.write_int(_cid);
263-
_at.cmd_stop();
264-
_at.resp_start();
265-
_at.resp_stop();
271+
_at.cmd_stop_read_resp();
266272

267273
if (_at.get_last_error() == NSAPI_ERROR_OK) {
268274
_cid = -1;
@@ -276,14 +282,15 @@ nsapi_error_t AT_CellularContext::do_user_authentication()
276282
{
277283
// if user has defined user name and password we need to call CGAUTH before activating or modifying context
278284
if (_pwd && _uname) {
285+
if (!is_supported(AT_CGAUTH)) {
286+
return NSAPI_ERROR_UNSUPPORTED;
287+
}
279288
_at.cmd_start("AT+CGAUTH=");
280289
_at.write_int(_cid);
281290
_at.write_int(_authentication_type);
282291
_at.write_string(_uname);
283292
_at.write_string(_pwd);
284-
_at.cmd_stop();
285-
_at.resp_start();
286-
_at.resp_stop();
293+
_at.cmd_stop_read_resp();
287294
if (_at.get_last_error() != NSAPI_ERROR_OK) {
288295
return NSAPI_ERROR_AUTH_FAILURE;
289296
}
@@ -424,9 +431,7 @@ bool AT_CellularContext::set_new_context(int cid)
424431
_at.write_int(cid);
425432
_at.write_string(pdp_type);
426433
_at.write_string(_apn);
427-
_at.cmd_stop();
428-
_at.resp_start();
429-
_at.resp_stop();
434+
_at.cmd_stop_read_resp();
430435
success = (_at.get_last_error() == NSAPI_ERROR_OK);
431436

432437
// Fall back to ipv4
@@ -437,9 +442,7 @@ bool AT_CellularContext::set_new_context(int cid)
437442
_at.write_int(cid);
438443
_at.write_string("IP");
439444
_at.write_string(_apn);
440-
_at.cmd_stop();
441-
_at.resp_start();
442-
_at.resp_stop();
445+
_at.cmd_stop_read_resp();
443446
success = (_at.get_last_error() == NSAPI_ERROR_OK);
444447
}
445448

@@ -502,9 +505,7 @@ nsapi_error_t AT_CellularContext::do_activate_context()
502505
tr_info("Activate PDP context %d", _cid);
503506
_at.cmd_start("AT+CGACT=1,");
504507
_at.write_int(_cid);
505-
_at.cmd_stop();
506-
_at.resp_start();
507-
_at.resp_stop();
508+
_at.cmd_stop_read_resp();
508509
if (_at.get_last_error() == NSAPI_ERROR_OK) {
509510
_is_context_activated = true;
510511
}
@@ -569,9 +570,11 @@ nsapi_error_t AT_CellularContext::open_data_channel()
569570
_at.write_int(_cid);
570571
} else {
571572
MBED_ASSERT(_cid >= 0 && _cid <= 99);
572-
char cmd_buf[sizeof("ATD*99***xx#")];
573-
std::sprintf(cmd_buf, "ATD*99***%d#", _cid);
574-
_at.cmd_start(cmd_buf);
573+
_at.cmd_start("ATD*99***");
574+
_at.use_delimiter(false);
575+
_at.write_int(_cid);
576+
_at.write_string("#", false);
577+
_at.use_delimiter(true);
575578
}
576579
_at.cmd_stop();
577580

@@ -591,6 +594,7 @@ nsapi_error_t AT_CellularContext::open_data_channel()
591594

592595
void AT_CellularContext::ppp_status_cb(nsapi_event_t ev, intptr_t ptr)
593596
{
597+
tr_debug("AT_CellularContext::ppp_status_cb, network_callback called with event: %d, ptr: %d", ev, ptr);
594598
if (ev == NSAPI_EVENT_CONNECTION_STATUS_CHANGE && ptr == NSAPI_STATUS_GLOBAL_UP) {
595599
_is_connected = true;
596600
} else {
@@ -607,7 +611,7 @@ void AT_CellularContext::ppp_status_cb(nsapi_event_t ev, intptr_t ptr)
607611

608612
nsapi_error_t AT_CellularContext::disconnect()
609613
{
610-
if (!_nw) {
614+
if (!_nw || !_is_connected) {
611615
return NSAPI_ERROR_NO_CONNECTION;
612616
}
613617
#if NSAPI_PPP_AVAILABLE
@@ -655,13 +659,12 @@ nsapi_error_t AT_CellularContext::disconnect()
655659
if (_is_context_active && (rat < CellularNetwork::RAT_E_UTRAN || active_contexts_count > 1)) {
656660
_at.cmd_start("AT+CGACT=0,");
657661
_at.write_int(_cid);
658-
_at.cmd_stop();
659-
_at.resp_start();
660-
_at.resp_stop();
662+
_at.cmd_stop_read_resp();
661663
}
662664
}
663665

664666
if (!_at.get_last_error()) {
667+
_is_connected = false;
665668
call_network_cb(NSAPI_STATUS_DISCONNECTED);
666669
}
667670

@@ -837,6 +840,11 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr)
837840
}
838841
}
839842
#endif // USE_APN_LOOKUP
843+
844+
if (!_nw && st == CellularDeviceReady && data->error == NSAPI_ERROR_OK) {
845+
_nw = _device->open_network(_fh);
846+
}
847+
840848
if (_is_blocking) {
841849
if (data->error != NSAPI_ERROR_OK) {
842850
// operation failed, release semaphore
@@ -853,7 +861,6 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr)
853861
_semaphore.release();
854862
} else if (st == CellularAttachNetwork && (_current_op == OP_ATTACH || _current_op == OP_CONNECT) &&
855863
data->status_data == CellularNetwork::Attached) {
856-
_nw = _device->open_network(_fh);
857864
// target reached, release semaphore
858865
_semaphore.release();
859866
}
@@ -871,6 +878,7 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr)
871878
}
872879
}
873880
} else {
881+
tr_debug("AT_CellularContext::cellular_callback, network_callback called with event: %d, ptr: %d", ev, ptr);
874882
#if NSAPI_PPP_AVAILABLE
875883
if (_is_blocking) {
876884
if (ev == NSAPI_EVENT_CONNECTION_STATUS_CHANGE && ptr == NSAPI_STATUS_GLOBAL_UP) {

features/cellular/framework/AT/AT_CellularContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class AT_CellularContext : public CellularContext, public AT_CellularBase {
3939
virtual nsapi_error_t disconnect();
4040
virtual bool is_connected();
4141
// from CellularBase
42+
virtual void set_plmn(const char *plmn);
4243
virtual void set_sim_pin(const char *sim_pin);
4344
virtual nsapi_error_t connect(const char *sim_pin, const char *apn = 0, const char *uname = 0,
4445
const char *pwd = 0);

features/cellular/framework/AT/AT_CellularNetwork.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,15 @@ AT_CellularNetwork::AT_CellularNetwork(ATHandler &atHandler) : AT_CellularBase(a
5656
_at.set_urc_handler("+CGEV:", callback(this, &AT_CellularNetwork::urc_cgev));
5757
_at.lock();
5858
_at.cmd_start("AT+CGEREP=1");// discard unsolicited result codes when MT TE link is reserved (e.g. in on line data mode); otherwise forward them directly to the TE
59-
_at.cmd_stop();
60-
_at.resp_start();
61-
_at.resp_stop();
59+
_at.cmd_stop_read_resp();
6260
_at.unlock();
6361
}
6462

6563
AT_CellularNetwork::~AT_CellularNetwork()
6664
{
6765
_at.lock();
6866
_at.cmd_start("AT+CGEREP=0");// buffer unsolicited result codes in the MT; if MT result code buffer is full, the oldest ones can be discarded. No codes are forwarded to the TE
69-
_at.cmd_stop();
70-
_at.resp_start();
71-
_at.resp_stop();
67+
_at.cmd_stop_read_resp();
7268
_at.unlock();
7369

7470
for (int type = 0; type < CellularNetwork::C_MAX; type++) {
@@ -254,7 +250,7 @@ nsapi_error_t AT_CellularNetwork::set_registration(const char *plmn)
254250
}
255251
} else {
256252
tr_debug("Manual network registration to %s", plmn);
257-
_at.cmd_start("AT+COPS=4,2,");
253+
_at.cmd_start("AT+COPS=1,2,");
258254
_at.write_string(plmn);
259255
_at.cmd_stop_read_resp();
260256
}

features/cellular/framework/device/CellularDevice.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ namespace mbed {
3434
MBED_WEAK CellularDevice *CellularDevice::get_default_instance()
3535
{
3636
static UARTSerial serial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
37+
#if DEVICE_SERIAL_FC
38+
if (MDMRTS != NC && MDMCTS != NC) {
39+
tr_info("_USING flow control, MDMRTS: %d MDMCTS: %d",MDMRTS, MDMCTS);
40+
serial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS);
41+
}
42+
#endif
3743
static CELLULAR_DEVICE device(&serial);
3844
return &device;
3945
}

features/cellular/framework/device/CellularStateMachine.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,24 +374,31 @@ void CellularStateMachine::state_power_on()
374374
}
375375
}
376376

377-
void CellularStateMachine::device_ready()
377+
bool CellularStateMachine::device_ready()
378378
{
379379
tr_info("Cellular device ready");
380+
if (_cellularDevice.init_module() != NSAPI_ERROR_OK) {
381+
return false;
382+
}
380383
if (_event_status_cb) {
381384
_event_status_cb((nsapi_event_t)CellularDeviceReady, (intptr_t )&_cb_data);
382385
}
383386
_power->remove_device_ready_urc_cb(mbed::callback(this, &CellularStateMachine::ready_urc_cb));
384387
_cellularDevice.close_power();
385388
_power = NULL;
389+
return true;
386390
}
387391

388392
void CellularStateMachine::state_device_ready()
389393
{
390394
_cellularDevice.set_timeout(TIMEOUT_POWER_ON);
391395
_cb_data.error = _power->set_at_mode();
392396
if (_cb_data.error == NSAPI_ERROR_OK) {
393-
device_ready();
394-
enter_to_state(STATE_SIM_PIN);
397+
if (device_ready()) {
398+
enter_to_state(STATE_SIM_PIN);
399+
} else {
400+
retry_state_or_fail();
401+
}
395402
} else {
396403
if (_retry_count == 0) {
397404
_power->set_device_ready_urc_cb(mbed::callback(this, &CellularStateMachine::ready_urc_cb));
@@ -605,7 +612,7 @@ void CellularStateMachine::event()
605612
}
606613

607614
if ((_target_state == _state && _cb_data.error == NSAPI_ERROR_OK && !_is_retry) || _event_id == STM_STOPPED) {
608-
tr_info("Target state reached: %s", get_state_string(_target_state));
615+
tr_info("Target state reached: %s, _cb_data.error: %d, _event_id: %d", get_state_string(_target_state), _cb_data.error, _event_id);
609616
_event_id = -1;
610617
return;
611618
}
@@ -683,8 +690,11 @@ void CellularStateMachine::ready_urc_cb()
683690
if (_state == STATE_DEVICE_READY && _power->set_at_mode() == NSAPI_ERROR_OK) {
684691
tr_debug("State was STATE_DEVICE_READY and at mode ready, cancel state and move to next");
685692
_queue.cancel(_event_id);
686-
device_ready();
687-
continue_from_state(STATE_SIM_PIN);
693+
if (device_ready()) {
694+
continue_from_state(STATE_SIM_PIN);
695+
} else {
696+
continue_from_state(STATE_DEVICE_READY);
697+
}
688698
}
689699
}
690700

features/cellular/framework/device/CellularStateMachine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class CellularStateMachine {
138138
bool open_sim();
139139
bool get_network_registration(CellularNetwork::RegistrationType type, CellularNetwork::RegistrationStatus &status, bool &is_registered);
140140
bool is_registered();
141-
void device_ready();
141+
bool device_ready();
142142

143143
// state functions to keep state machine simple
144144
void state_init();

features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ nsapi_error_t GEMALTO_CINTERION::init_module()
6262
return GEMALTO_CINTERION_Module::detect_model(model);
6363
}
6464

65-
uint16_t GEMALTO_CINTERION::get_send_delay()
65+
uint16_t GEMALTO_CINTERION::get_send_delay() const
6666
{
6767
return RESPONSE_TO_SEND_DELAY;
6868
}

features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class GEMALTO_CINTERION : public AT_CellularDevice {
3333
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn);
3434
public:
3535
virtual nsapi_error_t init_module();
36-
virtual uint16_t get_send_delay();
36+
virtual uint16_t get_send_delay() const;
3737
};
3838

3939
} // namespace mbed

features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,10 @@ NetworkStack *GEMALTO_CINTERION_CellularContext::get_stack()
4141

4242
bool GEMALTO_CINTERION_CellularContext::stack_type_supported(nsapi_ip_stack_t requested_stack)
4343
{
44-
#if NSAPI_PPP_AVAILABLE
45-
return (requested_stack == IPV4_STACK || requested_stack == IPV6_STACK);
46-
#else
4744
if (GEMALTO_CINTERION_Module::get_model() == GEMALTO_CINTERION_Module::ModelBGS2) {
4845
return (requested_stack == IPV4_STACK);
4946
}
5047
return (requested_stack == IPV4_STACK || requested_stack == IPV6_STACK);
51-
#endif
5248
}
5349

5450
} /* namespace mbed */

0 commit comments

Comments
 (0)