Skip to content

Commit 40db17e

Browse files
Teppo Järvelin0xc0170
authored andcommitted
Cellular: change stack_type_supported to get_property
Change usage of AT_CellularContext::stack_type_supported to AT_CellularBase::get_property. This way we can rid of targets overriding stack_type_supported and delete unnecessary classes and simplify new targets.
1 parent e30c20b commit 40db17e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+121
-455
lines changed

UNITTESTS/features/cellular/framework/AT/at_cellularbase/at_cellularbasetest.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class my_base : public AT_CellularBase {
4040
0, // AT_CGSN_WITH_TYPE
4141
1, // AT_CGDATA
4242
1, // AT_CGAUTH
43+
1, // PROPERTY_IPV4_STACK
44+
0, // PROPERTY_IPV6_STACK
45+
0, // PROPERTY_IPV4V6_STACK
4346
};
4447

4548
set_cellular_properties(cellular_properties);
@@ -116,7 +119,10 @@ TEST_F(TestAT_CellularBase, test_AT_CellularBase_set_cellular_properties)
116119
AT_CellularNetwork::RegistrationModeLAC, // C_REG
117120
0, // AT_CGSN_WITH_TYPE
118121
1, // AT_CGDATA
119-
1 // AT_CGAUTH
122+
1, // AT_CGAUTH
123+
1, // PROPERTY_IPV4_STACK
124+
0, // PROPERTY_IPV6_STACK
125+
0, // PROPERTY_IPV4V6_STACK
120126
};
121127
at.set_cellular_properties(cellular_properties);
122128
}

UNITTESTS/features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "Semaphore_stub.h"
2828
#include "CellularDevice_stub.h"
2929
#include "equeue_stub.h"
30+
#include "AT_CellularBase_stub.h"
3031

3132
using namespace mbed;
3233
using namespace events;
@@ -114,12 +115,12 @@ class my_stack : public AT_CellularStack {
114115
class my_AT_CTX : public AT_CellularContext {
115116
public:
116117
my_AT_CTX(ATHandler &at, CellularDevice *device, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN) :
117-
AT_CellularContext(at, device, apn), _st(at) {}
118-
virtual ~my_AT_CTX() {}
119-
virtual bool stack_type_supported(nsapi_ip_stack_t stack_type)
118+
AT_CellularContext(at, device, apn), _st(at)
120119
{
121-
return false;
120+
AT_CellularBase_stub::supported_bool = false;
122121
}
122+
virtual ~my_AT_CTX() {}
123+
123124
virtual NetworkStack *get_stack()
124125
{
125126
return &_st;

UNITTESTS/stubs/AT_CellularBase_stub.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ intptr_t AT_CellularBase::get_property(CellularProperty key)
4646
return AT_CellularNetwork::RegistrationModeDisable;
4747
} else if (key == PROPERTY_C_REG || key == PROPERTY_C_EREG) {
4848
return AT_CellularNetwork::RegistrationModeEnable;
49+
} else if (key == PROPERTY_AT_CGAUTH) {
50+
return true;
4951
}
5052

5153
return AT_CellularBase_stub::supported_bool;

UNITTESTS/stubs/AT_CellularContext_stub.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,15 @@ const char *AT_CellularContext::get_gateway()
135135
return NULL;
136136
}
137137

138-
bool AT_CellularContext::stack_type_supported(nsapi_ip_stack_t stack_type)
139-
{
140-
return true;
138+
AT_CellularBase::CellularProperty AT_CellularContext::nsapi_ip_stack_t_to_cellular_property(nsapi_ip_stack_t stack)
139+
{
140+
AT_CellularBase::CellularProperty prop = PROPERTY_IPV4_STACK;
141+
if (stack == IPV6_STACK) {
142+
prop = PROPERTY_IPV6_STACK;
143+
} else if (stack == IPV4V6_STACK) {
144+
prop = PROPERTY_IPV4V6_STACK;
145+
}
146+
return prop;
141147
}
142148

143149
nsapi_ip_stack_t AT_CellularContext::get_stack_type()

features/cellular/framework/AT/AT_CellularBase.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,15 @@ class AT_CellularBase {
4343
device_err_t get_device_error() const;
4444

4545
enum CellularProperty {
46-
PROPERTY_C_EREG, // AT_CellularNetwork::RegistrationMode. What support modem has for this registration type.
47-
PROPERTY_C_GREG, // AT_CellularNetwork::RegistrationMode. What support modem has for this registration type.
48-
PROPERTY_C_REG, // AT_CellularNetwork::RegistrationMode. What support modem has for this registration type.
49-
PROPERTY_AT_CGSN_WITH_TYPE, // 0 = not supported, 1 = supported. AT+CGSN without type is likely always supported similar to AT+GSN.
50-
PROPERTY_AT_CGDATA, // 0 = not supported, 1 = supported. Alternative is to support only ATD*99***<cid>#
51-
PROPERTY_AT_CGAUTH, // 0 = not supported, 1 = supported. APN authentication AT commands supported
46+
PROPERTY_C_EREG, // AT_CellularNetwork::RegistrationMode. What support modem has for this registration type.
47+
PROPERTY_C_GREG, // AT_CellularNetwork::RegistrationMode. What support modem has for this registration type.
48+
PROPERTY_C_REG, // AT_CellularNetwork::RegistrationMode. What support modem has for this registration type.
49+
PROPERTY_AT_CGSN_WITH_TYPE, // 0 = not supported, 1 = supported. AT+CGSN without type is likely always supported similar to AT+GSN.
50+
PROPERTY_AT_CGDATA, // 0 = not supported, 1 = supported. Alternative is to support only ATD*99***<cid>#
51+
PROPERTY_AT_CGAUTH, // 0 = not supported, 1 = supported. APN authentication AT commands supported
52+
PROPERTY_IPV4_STACK, // 0 = not supported, 1 = supported
53+
PROPERTY_IPV6_STACK, // 0 = not supported, 1 = supported
54+
PROPERTY_IPV4V6_STACK, // 0 = not supported, 1 = supported
5255
PROPERTY_MAX
5356
};
5457

features/cellular/framework/AT/AT_CellularContext.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,6 @@ void AT_CellularContext::set_credentials(const char *apn, const char *uname, con
239239
_pwd = pwd;
240240
}
241241

242-
bool AT_CellularContext::stack_type_supported(nsapi_ip_stack_t stack_type)
243-
{
244-
if (stack_type == _ip_stack_type) {
245-
return true;
246-
} else {
247-
return false;
248-
}
249-
}
250-
251242
nsapi_ip_stack_t AT_CellularContext::get_stack_type()
252243
{
253244
return _ip_stack_type;
@@ -306,6 +297,17 @@ nsapi_error_t AT_CellularContext::do_user_authentication()
306297
return NSAPI_ERROR_OK;
307298
}
308299

300+
AT_CellularBase::CellularProperty AT_CellularContext::nsapi_ip_stack_t_to_cellular_property(nsapi_ip_stack_t stack)
301+
{
302+
AT_CellularBase::CellularProperty prop = PROPERTY_IPV4_STACK;
303+
if (stack == IPV6_STACK) {
304+
prop = PROPERTY_IPV6_STACK;
305+
} else if (stack == IPV4V6_STACK) {
306+
prop = PROPERTY_IPV4V6_STACK;
307+
}
308+
return prop;
309+
}
310+
309311
bool AT_CellularContext::get_context()
310312
{
311313
_at.cmd_start("AT+CGDCONT?");
@@ -316,8 +318,8 @@ bool AT_CellularContext::get_context()
316318
char apn[MAX_ACCESSPOINT_NAME_LENGTH];
317319
int apn_len = 0;
318320

319-
bool modem_supports_ipv6 = stack_type_supported(IPV6_STACK);
320-
bool modem_supports_ipv4 = stack_type_supported(IPV4_STACK);
321+
bool modem_supports_ipv6 = get_property(PROPERTY_IPV6_STACK);
322+
bool modem_supports_ipv4 = get_property(PROPERTY_IPV4_STACK);
321323

322324
while (_at.info_resp()) {
323325
int cid = _at.read_int();
@@ -334,7 +336,8 @@ bool AT_CellularContext::get_context()
334336
}
335337
nsapi_ip_stack_t pdp_stack = string_to_stack_type(pdp_type_from_context);
336338
// Accept dual PDP context for IPv4/IPv6 only modems
337-
if (pdp_stack != DEFAULT_STACK && (stack_type_supported(pdp_stack) || pdp_stack == IPV4V6_STACK)) {
339+
if (pdp_stack != DEFAULT_STACK && (get_property(nsapi_ip_stack_t_to_cellular_property(pdp_stack))
340+
|| pdp_stack == IPV4V6_STACK)) {
338341
if (_ip_stack_type_requested == IPV4_STACK) {
339342
if (pdp_stack == IPV4_STACK || pdp_stack == IPV4V6_STACK) {
340343
_ip_stack_type = _ip_stack_type_requested;
@@ -399,8 +402,8 @@ bool AT_CellularContext::set_new_context(int cid)
399402
nsapi_ip_stack_t tmp_stack = _ip_stack_type_requested;
400403

401404
if (tmp_stack == DEFAULT_STACK) {
402-
bool modem_supports_ipv6 = stack_type_supported(IPV6_STACK);
403-
bool modem_supports_ipv4 = stack_type_supported(IPV4_STACK);
405+
bool modem_supports_ipv6 = get_property(PROPERTY_IPV6_STACK);
406+
bool modem_supports_ipv4 = get_property(PROPERTY_IPV4_STACK);
404407

405408
if (modem_supports_ipv6 && modem_supports_ipv4) {
406409
tmp_stack = IPV4V6_STACK;

features/cellular/framework/AT/AT_CellularContext.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,6 @@ class AT_CellularContext : public CellularContext, public AT_CellularBase {
7575
*/
7676
virtual void do_connect();
7777

78-
/** Check if modem supports the given stack type. Can be overridden by the modem.
79-
*
80-
* @return true if supported
81-
*/
82-
virtual bool stack_type_supported(nsapi_ip_stack_t stack_type);
83-
8478
/** Get the operation specific timeout. Used in synchronous mode when setting the maximum
8579
* waiting time. Modem specific implementation can override this to provide different timeouts.
8680
*
@@ -107,6 +101,7 @@ class AT_CellularContext : public CellularContext, public AT_CellularBase {
107101
nsapi_ip_stack_t string_to_stack_type(const char *pdp_type);
108102
nsapi_ip_stack_t get_stack_type();
109103
nsapi_error_t check_operation(nsapi_error_t err, ContextOperation op);
104+
AT_CellularBase::CellularProperty nsapi_ip_stack_t_to_cellular_property(nsapi_ip_stack_t stack);
110105

111106
private:
112107
nsapi_ip_stack_t _ip_stack_type_requested;

features/cellular/framework/AT/AT_CellularNetwork.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ static const char *const rat_str[AT_CellularNetwork::RAT_MAX] = {
7171

7272

7373
AT_CellularNetwork::AT_CellularNetwork(ATHandler &atHandler) : AT_CellularBase(atHandler),
74-
_connection_status_cb(NULL), _op_act(RAT_UNKNOWN), _connect_status(NSAPI_STATUS_DISCONNECTED),
75-
_ciotopt_network_support_cb(NULL), _supported_network_opt(CIOT_OPT_MAX)
74+
_connection_status_cb(NULL), _ciotopt_network_support_cb(NULL), _op_act(RAT_UNKNOWN),
75+
_connect_status(NSAPI_STATUS_DISCONNECTED), _supported_network_opt(CIOT_OPT_MAX)
7676
{
7777

7878
_urc_funcs[C_EREG] = callback(this, &AT_CellularNetwork::urc_cereg);

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,4 @@ NetworkStack *GEMALTO_CINTERION_CellularContext::get_stack()
3939
}
4040
#endif // NSAPI_PPP_AVAILABLE
4141

42-
bool GEMALTO_CINTERION_CellularContext::stack_type_supported(nsapi_ip_stack_t requested_stack)
43-
{
44-
if (GEMALTO_CINTERION_Module::get_model() == GEMALTO_CINTERION_Module::ModelBGS2) {
45-
return (requested_stack == IPV4_STACK);
46-
}
47-
return (requested_stack == IPV4_STACK || requested_stack == IPV6_STACK);
48-
}
49-
5042
} /* namespace mbed */

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class GEMALTO_CINTERION_CellularContext: public AT_CellularContext {
3030
#if !NSAPI_PPP_AVAILABLE
3131
virtual NetworkStack *get_stack();
3232
#endif // NSAPI_PPP_AVAILABLE
33-
virtual bool stack_type_supported(nsapi_ip_stack_t requested_stack);
3433
};
3534

3635
} /* namespace mbed */

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,37 @@ static const intptr_t cellular_properties_els61[AT_CellularBase::PROPERTY_MAX] =
2828
AT_CellularNetwork::RegistrationModeLAC, // C_EREG
2929
AT_CellularNetwork::RegistrationModeLAC, // C_GREG
3030
AT_CellularNetwork::RegistrationModeLAC, // C_REG
31-
0, // AT_CGSN_WITH_TYPE
32-
1, // AT_CGDATA
33-
1, // AT_CGAUTH
31+
0, // AT_CGSN_WITH_TYPE
32+
1, // AT_CGDATA
33+
1, // AT_CGAUTH
34+
1, // PROPERTY_IPV4_STACK
35+
1, // PROPERTY_IPV6_STACK
36+
0, // PROPERTY_IPV4V6_STACK
3437
};
3538

3639
static const intptr_t cellular_properties_bgs2[AT_CellularBase::PROPERTY_MAX] = {
3740
AT_CellularNetwork::RegistrationModeDisable, // C_EREG
3841
AT_CellularNetwork::RegistrationModeEnable, // C_GREG
3942
AT_CellularNetwork::RegistrationModeLAC, // C_REG
40-
0, // AT_CGSN_WITH_TYPE
41-
1, // AT_CGDATA
42-
1, // AT_CGAUTH
43+
0, // AT_CGSN_WITH_TYPE
44+
1, // AT_CGDATA
45+
1, // AT_CGAUTH
46+
1, // PROPERTY_IPV4_STACK
47+
0, // PROPERTY_IPV6_STACK
48+
0, // PROPERTY_IPV4V6_STACK
49+
4350
};
4451

4552
static const intptr_t cellular_properties_ems31[AT_CellularBase::PROPERTY_MAX] = {
4653
AT_CellularNetwork::RegistrationModeLAC, // C_EREG
4754
AT_CellularNetwork::RegistrationModeDisable, // C_GREG
4855
AT_CellularNetwork::RegistrationModeDisable, // C_REG
49-
1, // AT_CGSN_WITH_TYPE
50-
1, // AT_CGDATA
51-
1, // AT_CGAUTH
56+
1, // AT_CGSN_WITH_TYPE
57+
1, // AT_CGDATA
58+
1, // AT_CGAUTH
59+
1, // PROPERTY_IPV4_STACK
60+
1, // PROPERTY_IPV6_STACK
61+
0, // PROPERTY_IPV4V6_STACK
5262
};
5363

5464
GEMALTO_CINTERION_Module::Model GEMALTO_CINTERION_Module::_model;

features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "SARA4_PPP.h"
1919
#include "SARA4_PPP_CellularNetwork.h"
2020
#include "SARA4_PPP_CellularPower.h"
21-
#include "SARA4_PPP_CellularContext.h"
2221

2322
using namespace mbed;
2423
using namespace events;
@@ -30,6 +29,9 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
3029
0, // AT_CGSN_WITH_TYPE
3130
0, // AT_CGDATA
3231
1, // AT_CGAUTH
32+
1, // PROPERTY_IPV4_STACK
33+
0, // PROPERTY_IPV6_STACK
34+
0, // PROPERTY_IPV4V6_STACK
3335
};
3436

3537
SARA4_PPP::SARA4_PPP(FileHandle *fh) : AT_CellularDevice(fh)
@@ -51,7 +53,3 @@ AT_CellularPower *SARA4_PPP::open_power_impl(ATHandler &at)
5153
return new SARA4_PPP_CellularPower(at);
5254
}
5355

54-
AT_CellularContext *SARA4_PPP::create_context_impl(ATHandler &at, const char *apn)
55-
{
56-
return new SARA4_PPP_CellularContext(at, this, apn);
57-
}

features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class SARA4_PPP : public AT_CellularDevice {
3131
public: // CellularDevice
3232
virtual AT_CellularNetwork *open_network_impl(ATHandler &at);
3333
virtual AT_CellularPower *open_power_impl(ATHandler &at);
34-
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn);
3534
};
3635

3736
} // namespace mbed

features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP_CellularContext.cpp

Lines changed: 0 additions & 35 deletions
This file was deleted.

features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP_CellularContext.h

Lines changed: 0 additions & 35 deletions
This file was deleted.

features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717

1818
#include "QUECTEL_BC95_CellularNetwork.h"
19-
#include "QUECTEL_BC95_CellularPower.h"
2019
#include "QUECTEL_BC95_CellularContext.h"
2120
#include "QUECTEL_BC95_CellularInformation.h"
2221
#include "QUECTEL_BC95.h"
@@ -36,6 +35,9 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = {
3635
1, // AT_CGSN_WITH_TYPE
3736
1, // AT_CGDATA
3837
0, // AT_CGAUTH, BC95_AT_Commands_Manual_V1.9
38+
1, // PROPERTY_IPV4_STACK
39+
0, // PROPERTY_IPV6_STACK
40+
0, // PROPERTY_IPV4V6_STACK
3941
};
4042

4143
QUECTEL_BC95::QUECTEL_BC95(FileHandle *fh) : AT_CellularDevice(fh)
@@ -69,11 +71,6 @@ AT_CellularNetwork *QUECTEL_BC95::open_network_impl(ATHandler &at)
6971
return new QUECTEL_BC95_CellularNetwork(at);
7072
}
7173

72-
AT_CellularPower *QUECTEL_BC95::open_power_impl(ATHandler &at)
73-
{
74-
return new QUECTEL_BC95_CellularPower(at);
75-
}
76-
7774
AT_CellularContext *QUECTEL_BC95::create_context_impl(ATHandler &at, const char *apn)
7875
{
7976
return new QUECTEL_BC95_CellularContext(at, this, apn);

0 commit comments

Comments
 (0)