Skip to content

Commit 55b54f7

Browse files
Mirela ChiricaAri Parkkila
authored andcommitted
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)

0 commit comments

Comments
 (0)