Skip to content

Commit 55b54f7

Browse files
Mirela ChiricaAri Parkkila
Mirela Chirica
authored and
Ari Parkkila
committed
Cellular: Added API for setting default parameters to a network interface
1 parent ba3727b commit 55b54f7

File tree

15 files changed

+191
-30
lines changed

15 files changed

+191
-30
lines changed

UNITTESTS/features/cellular/framework/AT/at_cellularcontext/unittest.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ set(unittest-test-sources
3535
stubs/FileHandle_stub.cpp
3636
stubs/mbed_assert_stub.c
3737
stubs/NetworkInterface_stub.cpp
38+
stubs/NetworkInterfaceDefaults_stub.cpp
3839
stubs/NetworkStack_stub.cpp
3940
stubs/randLIB_stub.cpp
4041
stubs/Semaphore_stub.cpp

UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ set(unittest-test-sources
3333
stubs/CellularUtil_stub.cpp
3434
stubs/AT_CellularBase_stub.cpp
3535
stubs/NetworkInterface_stub.cpp
36+
stubs/NetworkInterfaceDefaults_stub.cpp
3637
stubs/EventQueue_stub.cpp
3738
stubs/FileHandle_stub.cpp
3839
stubs/mbed_assert_stub.c

UNITTESTS/features/cellular/framework/device/cellulardevice/unittest.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ set(unittest-test-sources
3131
stubs/AT_CellularContext_stub.cpp
3232
stubs/Semaphore_stub.cpp
3333
stubs/NetworkInterface_stub.cpp
34+
stubs/NetworkInterfaceDefaults_stub.cpp
3435
)
3536

3637
# defines

UNITTESTS/features/cellular/framework/device/cellularstatemachine/unittest.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ set(unittest-test-sources
3434
stubs/AT_CellularDevice_stub.cpp
3535
stubs/Semaphore_stub.cpp
3636
stubs/NetworkInterface_stub.cpp
37+
stubs/NetworkInterfaceDefaults_stub.cpp
3738
stubs/Thread_stub.cpp
3839
stubs/Mutex_stub.cpp
3940
stubs/EventQueue_stub.cpp

UNITTESTS/features/netsocket/EthernetInterface/unittest.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ set(unittest-test-sources
3333
stubs/stoip4_stub.c
3434
stubs/ip4tos_stub.c
3535
stubs/NetworkStack_stub.cpp
36+
stubs/NetworkInterfaceDefaults_stub.cpp
3637
stubs/SocketStats_Stub.cpp
3738
)

UNITTESTS/features/netsocket/NetworkInterface/unittest.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ set(unittest-test-sources
2525
stubs/nsapi_dns_stub.cpp
2626
stubs/EventFlags_stub.cpp
2727
features/netsocket/NetworkInterface/test_NetworkInterface.cpp
28+
stubs/NetworkInterfaceDefaults_stub.cpp
2829
stubs/SocketStats_Stub.cpp
2930
)

UNITTESTS/features/netsocket/cellular/CellularNonIPSocket/unittest.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ set(unittest-sources
1515
set(unittest-test-sources
1616
features/netsocket/cellular/CellularNonIPSocket/test_CellularNonIPSocket.cpp
1717
stubs/NetworkInterface_stub.cpp
18+
stubs/NetworkInterfaceDefaults_stub.cpp
1819
stubs/NetworkStack_stub.cpp
1920
stubs/EventFlags_stub.cpp
2021
stubs/Mutex_stub.cpp
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2017, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#include "netsocket/NetworkInterface.h"
18+
#include "WiFiInterface.h"
19+
#include "CellularBase.h"
20+
#include "MeshInterface.h"
21+
22+
MBED_WEAK WiFiInterface *WiFiInterface::get_default_instance()
23+
{
24+
return NULL;
25+
}
26+
27+
MBED_WEAK MeshInterface *MeshInterface::get_default_instance()
28+
{
29+
return NULL;
30+
}
31+
32+
MBED_WEAK CellularBase *CellularBase::get_default_instance()
33+
{
34+
return NULL;
35+
}
36+
37+
MBED_WEAK WiFiInterface *WiFiInterface::get_target_default_instance()
38+
{
39+
return NULL;
40+
}
41+
42+
MBED_WEAK NetworkInterface *NetworkInterface::get_default_instance()
43+
{
44+
return NULL;
45+
}
46+
47+
void NetworkInterface::set_default_parameters()
48+
{
49+
}
50+
51+
void WiFiInterface::set_default_parameters()
52+
{
53+
}
54+
55+
void CellularBase::set_default_parameters()
56+
{
57+
}
58+
59+
MBED_WEAK NetworkInterface *NetworkInterface::get_target_default_instance()
60+
{
61+
return NULL;
62+
}

features/cellular/framework/API/CellularContext.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,27 @@ class CellularContext : public CellularBase {
144144
virtual const char *get_netmask() = 0;
145145
virtual const char *get_gateway() = 0;
146146
virtual bool is_connected() = 0;
147+
148+
/** Same as NetworkInterface::get_default_instance()
149+
*
150+
* @note not to be used if get_default_nonip_instance() was already used
151+
*
152+
*/
147153
static CellularContext *get_default_instance();
148154

149155

156+
/** Instantiates a default Non-IP cellular interface
157+
*
158+
* This function creates a new Non-IP PDP context.
159+
*
160+
* @note not to be used if get_default_instance() was already used
161+
*
162+
* @return A Non-IP cellular PDP context
163+
*
164+
*/
165+
static CellularContext *get_default_nonip_instance();
166+
167+
150168
// Operations, can be sync/async. Also Connect() is this kind of operation, inherited from NetworkInterface above.
151169

152170
/** Start the interface

features/cellular/framework/device/CellularContext.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,27 @@ namespace mbed {
2121
MBED_WEAK CellularContext *CellularContext::get_default_instance()
2222
{
2323
// Uses default APN, uname, password from mbed_app.json
24-
static CellularDevice *dev = CellularDevice::get_default_instance();
24+
CellularDevice *dev = CellularDevice::get_default_instance();
2525
if (!dev) {
2626
return NULL;
2727
}
28-
static CellularContext *context = dev->create_context();
28+
29+
static CellularContext *context = dev->create_context(NULL, NULL, MBED_CONF_CELLULAR_CONTROL_PLANE_OPT);
30+
#if defined(MDMDCD) && defined(MDM_PIN_POLARITY)
31+
context->set_file_handle(static_cast<UARTSerial *>(&dev->get_file_handle()), MDMDCD, MDM_PIN_POLARITY);
32+
#endif // #if defined(MDMDCD) && defined(MDM_PIN_POLARITY)
33+
return context;
34+
}
35+
36+
MBED_WEAK CellularContext *CellularContext::get_default_nonip_instance()
37+
{
38+
// Uses default APN, uname, password from mbed_app.json
39+
CellularDevice *dev = CellularDevice::get_default_instance();
40+
if (!dev) {
41+
return NULL;
42+
}
43+
44+
static CellularContext *context = dev->create_context(NULL, NULL, MBED_CONF_CELLULAR_CONTROL_PLANE_OPT, true);
2945
#if defined(MDMDCD) && defined(MDM_PIN_POLARITY)
3046
context->set_file_handle(static_cast<UARTSerial *>(&dev->get_file_handle()), MDMDCD, MDM_PIN_POLARITY);
3147
#endif // #if defined(MDMDCD) && defined(MDM_PIN_POLARITY)

features/cellular/mbed_lib.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
"radio-access-technology": {
1717
"help": "Radio access technology to use. Value in integer: GSM=0, GSM_COMPACT=1, UTRAN=2, EGPRS=3, HSDPA=4, HSUPA=5, HSDPA_HSUPA=6, E_UTRAN=7, CATM1=8 ,NB1=9",
1818
"value": null
19+
},
20+
"control-plane-opt": {
21+
"help": "Enables control plane CIoT EPS optimisation",
22+
"value": false
1923
}
2024
}
2125
}

features/netsocket/CellularBase.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ class CellularBase: public NetworkInterface {
3939
*/
4040
static CellularBase *get_default_instance();
4141

42+
/** Set default parameters on a cellular interface.
43+
*
44+
* A cellular interface instantiated directly or using
45+
* CellularBase::get_default_instance() is initially unconfigured.
46+
* This call can be used to set the default parameters that would
47+
* have been set if the interface had been requested using
48+
* NetworkInterface::get_default_instance() (see nsapi JSON
49+
* configuration).
50+
*/
51+
virtual void set_default_parameters();
52+
4253
/** Set the cellular network credentials.
4354
*
4455
* Please check documentation of connect() for default behavior of APN settings.

features/netsocket/NetworkInterface.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ class NetworkInterface: public DNS {
8484
*/
8585
static NetworkInterface *get_default_instance();
8686

87+
/** Set default parameters on an interface.
88+
*
89+
* A network interface instantiated directly or using calls such as
90+
* WiFiInterface::get_default_instance() is initially unconfigured.
91+
* This call can be used to set the default parameters that would
92+
* have been set if the interface had been requested using
93+
* NetworkInterface::get_default_instance() (see nsapi JSON
94+
* configuration).
95+
*/
96+
virtual void set_default_parameters();
97+
8798
/** Get the local MAC address.
8899
*
89100
* Provided MAC address is intended for info or debug purposes and

features/netsocket/NetworkInterfaceDefaults.cpp

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,53 @@ MBED_WEAK NetworkInterface *NetworkInterface::get_default_instance()
6262
return get_target_default_instance();
6363
}
6464

65+
66+
/* Helpers to set default parameters - used by NetworkInterface::get_default_instance,
67+
* but exposed for apps which want to get these defaults after requesting a specific type.
68+
*/
69+
void NetworkInterface::set_default_parameters()
70+
{
71+
72+
}
73+
74+
void WiFiInterface::set_default_parameters()
75+
{
76+
#ifdef MBED_CONF_NSAPI_DEFAULT_WIFI_SSID
77+
#ifndef MBED_CONF_NSAPI_DEFAULT_WIFI_PASSWORD
78+
#define MBED_CONF_NSAPI_DEFAULT_WIFI_PASSWORD NULL
79+
#endif
80+
#ifndef MBED_CONF_NSAPI_DEFAULT_WIFI_SECURITY
81+
#define MBED_CONF_NSAPI_DEFAULT_WIFI_SECURITY NONE
82+
#endif
83+
#define concat_(x,y) x##y
84+
#define concat(x,y) concat_(x,y)
85+
#define SECURITY concat(NSAPI_SECURITY_,MBED_CONF_NSAPI_DEFAULT_WIFI_SECURITY)
86+
set_credentials(MBED_CONF_NSAPI_DEFAULT_WIFI_SSID, MBED_CONF_NSAPI_DEFAULT_WIFI_PASSWORD, SECURITY);
87+
#endif
88+
}
89+
90+
void CellularBase::set_default_parameters()
91+
{
92+
/* CellularBase is expected to attempt to work without any parameters - we
93+
* will try, at least.
94+
*/
95+
#ifdef MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN
96+
#ifndef MBED_CONF_NSAPI_DEFAULT_CELLULAR_USERNAME
97+
#define MBED_CONF_NSAPI_DEFAULT_CELLULAR_USERNAME NULL
98+
#endif
99+
#ifndef MBED_CONF_NSAPI_DEFAULT_CELLULAR_PASSWORD
100+
#define MBED_CONF_NSAPI_DEFAULT_CELLULAR_PASSWORD NULL
101+
#endif
102+
set_credentials(MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN, MBED_CONF_NSAPI_DEFAULT_CELLULAR_USERNAME, MBED_CONF_NSAPI_DEFAULT_CELLULAR_PASSWORD);
103+
#endif
104+
#ifdef MBED_CONF_NSAPI_DEFAULT_CELLULAR_SIM_PIN
105+
set_sim_pin(MBED_CONF_NSAPI_DEFAULT_CELLULAR_SIM_PIN);
106+
#endif
107+
#ifdef MBED_CONF_NSAPI_DEFAULT_CELLULAR_PLMN
108+
set_plmn(MBED_CONF_NSAPI_DEFAULT_CELLULAR_PLMN);
109+
#endif
110+
}
111+
65112
/* Finally the dispatch from the JSON default interface type to the specific
66113
* subclasses. It's our job to configure - the default NetworkInterface is
67114
* preconfigured - the specific subtypes' defaults are not (necessarily).
@@ -87,16 +134,7 @@ MBED_WEAK NetworkInterface *NetworkInterface::get_target_default_instance()
87134
if (!wifi) {
88135
return NULL;
89136
}
90-
#ifndef MBED_CONF_NSAPI_DEFAULT_WIFI_PASSWORD
91-
#define MBED_CONF_NSAPI_DEFAULT_WIFI_PASSWORD NULL
92-
#endif
93-
#ifndef MBED_CONF_NSAPI_DEFAULT_WIFI_SECURITY
94-
#define MBED_CONF_NSAPI_DEFAULT_WIFI_SECURITY NONE
95-
#endif
96-
#define concat_(x,y) x##y
97-
#define concat(x,y) concat_(x,y)
98-
#define SECURITY concat(NSAPI_SECURITY_,MBED_CONF_NSAPI_DEFAULT_WIFI_SECURITY)
99-
wifi->set_credentials(MBED_CONF_NSAPI_DEFAULT_WIFI_SSID, MBED_CONF_NSAPI_DEFAULT_WIFI_PASSWORD, SECURITY);
137+
wifi->set_default_parameters();
100138
return wifi;
101139
#else
102140
return NULL;
@@ -114,24 +152,7 @@ MBED_WEAK NetworkInterface *NetworkInterface::get_target_default_instance()
114152
if (!cellular) {
115153
return NULL;
116154
}
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
155+
cellular->set_default_parameters();
135156
return cellular;
136157
}
137158
#elif defined(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE)

features/netsocket/WiFiInterface.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ class WiFiInterface: public virtual NetworkInterface {
4040
*/
4141
static WiFiInterface *get_default_instance();
4242

43+
/** Set default parameters on a Wi-Fi interface.
44+
*
45+
* A Wi-Fi interface instantiated directly or using
46+
* WiFiInterface::get_default_instance() is initially unconfigured.
47+
* This call can be used to set the default parameters that would
48+
* have been set if the interface had been requested using
49+
* NetworkInterface::get_default_instance() (see nsapi JSON
50+
* configuration).
51+
*/
52+
virtual void set_default_parameters();
53+
4354
/** Set the Wi-Fi network credentials.
4455
*
4556
* @param ssid Name of the network to connect to.

0 commit comments

Comments
 (0)