Skip to content

Commit 3f6e088

Browse files
author
Teppo Järvelin
committed
Cellular: Fixed backward compatibility with OnBoardCellularInterface and set default values in NetworkInterfaceDefaults.cpp.
1 parent 1a047ef commit 3f6e088

File tree

11 files changed

+91
-30
lines changed

11 files changed

+91
-30
lines changed

features/cellular/framework/API/CellularContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class CellularContext : public CellularBase {
119119
virtual const char *get_netmask() = 0;
120120
virtual const char *get_gateway() = 0;
121121
virtual bool is_connected() = 0;
122-
static CellularBase *get_default_instance();
122+
static CellularContext *get_default_instance();
123123

124124

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

features/cellular/framework/API/CellularDevice.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ class FileHandle;
3434
const int MAX_PIN_SIZE = 8;
3535
const int MAX_PLMN_SIZE = 16;
3636

37-
#ifndef MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN
38-
#define MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN NULL
39-
#endif
40-
4137
/**
4238
* Class CellularDevice
4339
*
@@ -73,7 +69,7 @@ class CellularDevice {
7369
* @return new instance of class CellularContext or NULL in case of failure
7470
*
7571
*/
76-
virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN) = 0;
72+
virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = NULL) = 0;
7773

7874
/** Deletes the given CellularContext instance
7975
*

features/cellular/framework/AT/AT_CellularContext.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ AT_CellularContext::AT_CellularContext(ATHandler &at, CellularDevice *device, co
5252
_is_context_active = false;
5353
_is_context_activated = false;
5454
_apn = apn;
55-
_uname = MBED_CONF_NSAPI_DEFAULT_CELLULAR_USERNAME;
56-
_pwd = MBED_CONF_NSAPI_DEFAULT_CELLULAR_PASSWORD;
55+
_uname = NULL;
56+
_pwd = NULL;
5757
_status_cb = NULL;
5858
_cid = -1;
5959
_new_context_set = false;
@@ -465,6 +465,7 @@ nsapi_error_t AT_CellularContext::do_activate_context()
465465
// try to find or create context with suitable stack
466466
if (get_context()) {
467467
#if NSAPI_PPP_AVAILABLE
468+
_at.unlock();
468469
// in PPP we don't activate any context but leave it to PPP stack
469470
return err;
470471
#endif // NSAPI_PPP_AVAILABLE
@@ -483,6 +484,7 @@ nsapi_error_t AT_CellularContext::do_activate_context()
483484

484485
// do check for stack to validate that we have support for stack
485486
if (!get_stack()) {
487+
_at.unlock();
486488
tr_error("No cellular stack!");
487489
return NSAPI_ERROR_UNSUPPORTED;
488490
}

features/cellular/framework/AT/AT_CellularContext.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace mbed {
2727

2828
class AT_CellularContext : public CellularContext, public AT_CellularBase {
2929
public:
30-
AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN);
30+
AT_CellularContext(ATHandler &at, CellularDevice *device, const char *apn = 0);
3131
virtual ~AT_CellularContext();
3232

3333
// from CellularBase/NetworkInterface
@@ -47,7 +47,7 @@ class AT_CellularContext : public CellularContext, public AT_CellularBase {
4747
virtual const char *get_netmask();
4848
virtual const char *get_gateway();
4949

50-
private: // from CellularContext
50+
// from CellularContext
5151
virtual nsapi_error_t get_pdpcontext_params(pdpContextList_t &params_list);
5252
virtual nsapi_error_t get_rate_control(CellularContext::RateControlExceptionReports &reports,
5353
CellularContext::RateControlUplinkTimeUnit &time_unit, int &uplink_rate);

features/cellular/framework/AT/AT_CellularDevice.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class AT_CellularDevice : public CellularDevice {
4141
AT_CellularDevice(FileHandle *fh);
4242
virtual ~AT_CellularDevice();
4343

44-
virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN);
44+
virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = NULL);
4545
virtual void delete_context(CellularContext *context);
4646

4747
virtual CellularNetwork *open_network(FileHandle *fh = NULL);

features/cellular/framework/device/CellularContext.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@
1818

1919
namespace mbed {
2020
#ifdef CELLULAR_DEVICE
21-
MBED_WEAK CellularBase *CellularContext::get_default_instance()
21+
MBED_WEAK CellularContext *CellularContext::get_default_instance()
2222
{
2323
// Uses default APN, uname, password from mbed_app.json
2424
static CellularDevice *dev = CellularDevice::get_default_instance();
25-
return dev->create_context();
25+
if (!dev) {
26+
return NULL;
27+
}
28+
static CellularContext *context = dev->create_context();
29+
return context;
2630
}
2731
#else
28-
MBED_WEAK CellularBase *CellularContext::get_default_instance()
32+
MBED_WEAK CellularContext *CellularContext::get_default_instance()
2933
{
3034
return NULL;
3135
}

features/cellular/framework/device/CellularDevice.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ MBED_WEAK CellularDevice *CellularDevice::get_default_instance()
5353
CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0),_power_ref_count(0), _sim_ref_count(0),
5454
_info_ref_count(0), _fh(fh), _queue(5 * EVENTS_EVENT_SIZE), _state_machine(0), _nw(0)
5555
{
56-
set_sim_pin(MBED_CONF_NSAPI_DEFAULT_CELLULAR_SIM_PIN);
57-
set_plmn(MBED_CONF_NSAPI_DEFAULT_CELLULAR_PLMN);
56+
set_sim_pin(NULL);
57+
set_plmn(NULL);
5858
}
5959

6060
CellularDevice::~CellularDevice()
@@ -171,14 +171,14 @@ void CellularDevice::cellular_callback(nsapi_event_t ev, intptr_t ptr)
171171
_nw = open_network(_fh);
172172
// Attach to network so we can get update status from the network
173173
_nw->attach(callback(this, &CellularDevice::cellular_callback));
174+
if (strlen(_plmn)) {
175+
_state_machine->set_plmn(_plmn);
176+
}
174177
} else if (cell_ev == CellularSIMStatusChanged && ptr_data->error == NSAPI_ERROR_OK &&
175178
ptr_data->status_data == CellularSIM::SimStatePinNeeded) {
176179
if (strlen(_sim_pin)) {
177180
_state_machine->set_sim_pin(_sim_pin);
178181
}
179-
if (strlen(_plmn)) {
180-
_state_machine->set_plmn(_plmn);
181-
}
182182
}
183183
} else {
184184
tr_debug("Device: network_callback called with event: %d, ptr: %d", ev, ptr);

features/netsocket/NetworkInterfaceDefaults.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,29 @@ MBED_WEAK NetworkInterface *NetworkInterface::get_target_default_instance()
110110
#elif MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE == CELLULAR
111111
MBED_WEAK NetworkInterface *NetworkInterface::get_target_default_instance()
112112
{
113-
return CellularBase::get_default_instance();
114-
113+
CellularBase *cellular = CellularBase::get_default_instance();
114+
if (!cellular) {
115+
return NULL;
116+
}
117+
/* CellularBase is expected to attempt to work without any parameters - we
118+
* will try, at least.
119+
*/
120+
#ifdef MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN
121+
#ifndef MBED_CONF_NSAPI_DEFAULT_CELLULAR_USERNAME
122+
#define MBED_CONF_NSAPI_DEFAULT_CELLULAR_USERNAME NULL
123+
#endif
124+
#ifndef MBED_CONF_NSAPI_DEFAULT_CELLULAR_PASSWORD
125+
#define MBED_CONF_NSAPI_DEFAULT_CELLULAR_PASSWORD NULL
126+
#endif
127+
cellular->set_credentials(MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN, MBED_CONF_NSAPI_DEFAULT_CELLULAR_USERNAME, MBED_CONF_NSAPI_DEFAULT_CELLULAR_PASSWORD);
128+
#endif
129+
#ifdef MBED_CONF_NSAPI_DEFAULT_CELLULAR_SIM_PIN
130+
cellular->set_sim_pin(MBED_CONF_NSAPI_DEFAULT_CELLULAR_SIM_PIN);
131+
#endif
132+
#ifdef MBED_CONF_NSAPI_DEFAULT_CELLULAR_PLMN
133+
cellular->set_plmn(MBED_CONF_NSAPI_DEFAULT_CELLULAR_PLMN);
134+
#endif
135+
return cellular;
115136
}
116137
#elif defined(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE)
117138
/* If anyone invents a new JSON value, they must have their own default weak

features/netsocket/cellular/generic_modem_driver/OnboardCellularInterface.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,19 @@ void OnboardCellularInterface::modem_power_down()
6060
}
6161
#endif
6262

63-
6463
#endif // CELLULAR_DEVICE
6564

66-
#ifdef ONBOARD_CELLULAR_INTERFACE_AVAILABLE
65+
#ifdef CELLULAR_DEVICE
6766
MBED_WEAK CellularBase *CellularBase::get_target_default_instance()
6867
{
69-
return mbed::CellularContext::get_default_instance();
68+
return CellularContext::get_default_instance();
69+
}
70+
#elif defined ONBOARD_CELLULAR_INTERFACE_AVAILABLE
71+
MBED_WEAK CellularBase *CellularBase::get_target_default_instance()
72+
{
73+
static OnboardCellularInterface cellular;
74+
75+
return &cellular;
7076
}
7177
#else
7278
MBED_WEAK CellularBase *CellularBase::get_target_default_instance()

features/netsocket/cellular/generic_modem_driver/OnboardCellularInterface.h

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,39 @@
1818

1919
#include "CellularContext.h"
2020
#ifdef CELLULAR_DEVICE
21-
typedef mbed::CellularContext OnboardCellularInterface;
21+
using namespace mbed;
22+
MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, use CellularBase::get_default_instance() instead.")
23+
class OnboardCellularInterface : public CellularBase
24+
{
25+
public:
26+
OnboardCellularInterface() {
27+
context = CellularContext::get_default_instance();
28+
MBED_ASSERT(context != NULL);
29+
}
30+
public: // from NetworkInterface
31+
virtual nsapi_error_t set_blocking(bool blocking) {return context->set_blocking(blocking);}
32+
virtual NetworkStack *get_stack() {return context->get_stack();}
33+
virtual const char *get_ip_address() {return context->get_ip_address();}
34+
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb) {context->attach(status_cb);}
35+
virtual nsapi_error_t connect() {return context->connect();}
36+
virtual nsapi_error_t disconnect() {return context->disconnect();}
37+
38+
// from CellularBase
39+
virtual void set_plmn(const char *plmn) {context->set_plmn(plmn);}
40+
virtual void set_sim_pin(const char *sim_pin) {context->set_sim_pin(sim_pin);}
41+
virtual nsapi_error_t connect(const char *sim_pin, const char *apn = 0, const char *uname = 0,
42+
const char *pwd = 0)
43+
{return context->connect(sim_pin, apn, uname, pwd);}
44+
virtual void set_credentials(const char *apn, const char *uname = 0, const char *pwd = 0)
45+
{context->set_credentials(apn, uname, pwd);}
46+
virtual const char *get_netmask() {return context->get_netmask();}
47+
virtual const char *get_gateway() {return context->get_gateway();}
48+
virtual bool is_connected() {return context->is_connected();}
49+
50+
private:
51+
CellularContext *context;
52+
};
53+
2254
#define ONBOARD_CELLULAR_INTERFACE_AVAILABLE
2355
#elif MODEM_ON_BOARD && MODEM_ON_BOARD_UART && NSAPI_PPP_AVAILABLE
2456

features/netsocket/mbed_lib.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
"default-wifi-ssid": null,
77
"default-wifi-password": null,
88
"default-wifi-security": "NONE",
9-
"default-cellular-plmn": 0,
10-
"default-cellular-sim-pin": 0,
11-
"default-cellular-apn": 0,
12-
"default-cellular-username": 0,
13-
"default-cellular-password": 0,
9+
"default-cellular-plmn": null,
10+
"default-cellular-sim-pin": null,
11+
"default-cellular-apn": null,
12+
"default-cellular-username": null,
13+
"default-cellular-password": null,
1414
"default-mesh-type": {
1515
"help": "Configuration type for MeshInterface::get_default_instance(). [LOWPAN/THREAD]",
1616
"value": "THREAD"

0 commit comments

Comments
 (0)