mirror of https://github.com/ARMmbed/mbed-os.git
Cellular: Added API for setting default parameters to a network interface
parent
ba3727b4e8
commit
55b54f7c97
|
|
@ -35,6 +35,7 @@ set(unittest-test-sources
|
|||
stubs/FileHandle_stub.cpp
|
||||
stubs/mbed_assert_stub.c
|
||||
stubs/NetworkInterface_stub.cpp
|
||||
stubs/NetworkInterfaceDefaults_stub.cpp
|
||||
stubs/NetworkStack_stub.cpp
|
||||
stubs/randLIB_stub.cpp
|
||||
stubs/Semaphore_stub.cpp
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ set(unittest-test-sources
|
|||
stubs/CellularUtil_stub.cpp
|
||||
stubs/AT_CellularBase_stub.cpp
|
||||
stubs/NetworkInterface_stub.cpp
|
||||
stubs/NetworkInterfaceDefaults_stub.cpp
|
||||
stubs/EventQueue_stub.cpp
|
||||
stubs/FileHandle_stub.cpp
|
||||
stubs/mbed_assert_stub.c
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ set(unittest-test-sources
|
|||
stubs/AT_CellularContext_stub.cpp
|
||||
stubs/Semaphore_stub.cpp
|
||||
stubs/NetworkInterface_stub.cpp
|
||||
stubs/NetworkInterfaceDefaults_stub.cpp
|
||||
)
|
||||
|
||||
# defines
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ set(unittest-test-sources
|
|||
stubs/AT_CellularDevice_stub.cpp
|
||||
stubs/Semaphore_stub.cpp
|
||||
stubs/NetworkInterface_stub.cpp
|
||||
stubs/NetworkInterfaceDefaults_stub.cpp
|
||||
stubs/Thread_stub.cpp
|
||||
stubs/Mutex_stub.cpp
|
||||
stubs/EventQueue_stub.cpp
|
||||
|
|
|
|||
|
|
@ -33,5 +33,6 @@ set(unittest-test-sources
|
|||
stubs/stoip4_stub.c
|
||||
stubs/ip4tos_stub.c
|
||||
stubs/NetworkStack_stub.cpp
|
||||
stubs/NetworkInterfaceDefaults_stub.cpp
|
||||
stubs/SocketStats_Stub.cpp
|
||||
)
|
||||
|
|
|
|||
|
|
@ -25,5 +25,6 @@ set(unittest-test-sources
|
|||
stubs/nsapi_dns_stub.cpp
|
||||
stubs/EventFlags_stub.cpp
|
||||
features/netsocket/NetworkInterface/test_NetworkInterface.cpp
|
||||
stubs/NetworkInterfaceDefaults_stub.cpp
|
||||
stubs/SocketStats_Stub.cpp
|
||||
)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ set(unittest-sources
|
|||
set(unittest-test-sources
|
||||
features/netsocket/cellular/CellularNonIPSocket/test_CellularNonIPSocket.cpp
|
||||
stubs/NetworkInterface_stub.cpp
|
||||
stubs/NetworkInterfaceDefaults_stub.cpp
|
||||
stubs/NetworkStack_stub.cpp
|
||||
stubs/EventFlags_stub.cpp
|
||||
stubs/Mutex_stub.cpp
|
||||
|
|
|
|||
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright (c) 2017, Arm Limited and affiliates.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "netsocket/NetworkInterface.h"
|
||||
#include "WiFiInterface.h"
|
||||
#include "CellularBase.h"
|
||||
#include "MeshInterface.h"
|
||||
|
||||
MBED_WEAK WiFiInterface *WiFiInterface::get_default_instance()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
MBED_WEAK MeshInterface *MeshInterface::get_default_instance()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
MBED_WEAK CellularBase *CellularBase::get_default_instance()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
MBED_WEAK WiFiInterface *WiFiInterface::get_target_default_instance()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
MBED_WEAK NetworkInterface *NetworkInterface::get_default_instance()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void NetworkInterface::set_default_parameters()
|
||||
{
|
||||
}
|
||||
|
||||
void WiFiInterface::set_default_parameters()
|
||||
{
|
||||
}
|
||||
|
||||
void CellularBase::set_default_parameters()
|
||||
{
|
||||
}
|
||||
|
||||
MBED_WEAK NetworkInterface *NetworkInterface::get_target_default_instance()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -144,9 +144,27 @@ public: // from NetworkInterface
|
|||
virtual const char *get_netmask() = 0;
|
||||
virtual const char *get_gateway() = 0;
|
||||
virtual bool is_connected() = 0;
|
||||
|
||||
/** Same as NetworkInterface::get_default_instance()
|
||||
*
|
||||
* @note not to be used if get_default_nonip_instance() was already used
|
||||
*
|
||||
*/
|
||||
static CellularContext *get_default_instance();
|
||||
|
||||
|
||||
/** Instantiates a default Non-IP cellular interface
|
||||
*
|
||||
* This function creates a new Non-IP PDP context.
|
||||
*
|
||||
* @note not to be used if get_default_instance() was already used
|
||||
*
|
||||
* @return A Non-IP cellular PDP context
|
||||
*
|
||||
*/
|
||||
static CellularContext *get_default_nonip_instance();
|
||||
|
||||
|
||||
// Operations, can be sync/async. Also Connect() is this kind of operation, inherited from NetworkInterface above.
|
||||
|
||||
/** Start the interface
|
||||
|
|
|
|||
|
|
@ -21,11 +21,27 @@ namespace mbed {
|
|||
MBED_WEAK CellularContext *CellularContext::get_default_instance()
|
||||
{
|
||||
// Uses default APN, uname, password from mbed_app.json
|
||||
static CellularDevice *dev = CellularDevice::get_default_instance();
|
||||
CellularDevice *dev = CellularDevice::get_default_instance();
|
||||
if (!dev) {
|
||||
return NULL;
|
||||
}
|
||||
static CellularContext *context = dev->create_context();
|
||||
|
||||
static CellularContext *context = dev->create_context(NULL, NULL, MBED_CONF_CELLULAR_CONTROL_PLANE_OPT);
|
||||
#if defined(MDMDCD) && defined(MDM_PIN_POLARITY)
|
||||
context->set_file_handle(static_cast<UARTSerial *>(&dev->get_file_handle()), MDMDCD, MDM_PIN_POLARITY);
|
||||
#endif // #if defined(MDMDCD) && defined(MDM_PIN_POLARITY)
|
||||
return context;
|
||||
}
|
||||
|
||||
MBED_WEAK CellularContext *CellularContext::get_default_nonip_instance()
|
||||
{
|
||||
// Uses default APN, uname, password from mbed_app.json
|
||||
CellularDevice *dev = CellularDevice::get_default_instance();
|
||||
if (!dev) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static CellularContext *context = dev->create_context(NULL, NULL, MBED_CONF_CELLULAR_CONTROL_PLANE_OPT, true);
|
||||
#if defined(MDMDCD) && defined(MDM_PIN_POLARITY)
|
||||
context->set_file_handle(static_cast<UARTSerial *>(&dev->get_file_handle()), MDMDCD, MDM_PIN_POLARITY);
|
||||
#endif // #if defined(MDMDCD) && defined(MDM_PIN_POLARITY)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,10 @@
|
|||
"radio-access-technology": {
|
||||
"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",
|
||||
"value": null
|
||||
},
|
||||
"control-plane-opt": {
|
||||
"help": "Enables control plane CIoT EPS optimisation",
|
||||
"value": false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,6 +39,17 @@ public:
|
|||
*/
|
||||
static CellularBase *get_default_instance();
|
||||
|
||||
/** Set default parameters on a cellular interface.
|
||||
*
|
||||
* A cellular interface instantiated directly or using
|
||||
* CellularBase::get_default_instance() is initially unconfigured.
|
||||
* This call can be used to set the default parameters that would
|
||||
* have been set if the interface had been requested using
|
||||
* NetworkInterface::get_default_instance() (see nsapi JSON
|
||||
* configuration).
|
||||
*/
|
||||
virtual void set_default_parameters();
|
||||
|
||||
/** Set the cellular network credentials.
|
||||
*
|
||||
* Please check documentation of connect() for default behavior of APN settings.
|
||||
|
|
|
|||
|
|
@ -84,6 +84,17 @@ public:
|
|||
*/
|
||||
static NetworkInterface *get_default_instance();
|
||||
|
||||
/** Set default parameters on an interface.
|
||||
*
|
||||
* A network interface instantiated directly or using calls such as
|
||||
* WiFiInterface::get_default_instance() is initially unconfigured.
|
||||
* This call can be used to set the default parameters that would
|
||||
* have been set if the interface had been requested using
|
||||
* NetworkInterface::get_default_instance() (see nsapi JSON
|
||||
* configuration).
|
||||
*/
|
||||
virtual void set_default_parameters();
|
||||
|
||||
/** Get the local MAC address.
|
||||
*
|
||||
* Provided MAC address is intended for info or debug purposes and
|
||||
|
|
|
|||
|
|
@ -62,6 +62,53 @@ MBED_WEAK NetworkInterface *NetworkInterface::get_default_instance()
|
|||
return get_target_default_instance();
|
||||
}
|
||||
|
||||
|
||||
/* Helpers to set default parameters - used by NetworkInterface::get_default_instance,
|
||||
* but exposed for apps which want to get these defaults after requesting a specific type.
|
||||
*/
|
||||
void NetworkInterface::set_default_parameters()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void WiFiInterface::set_default_parameters()
|
||||
{
|
||||
#ifdef MBED_CONF_NSAPI_DEFAULT_WIFI_SSID
|
||||
#ifndef MBED_CONF_NSAPI_DEFAULT_WIFI_PASSWORD
|
||||
#define MBED_CONF_NSAPI_DEFAULT_WIFI_PASSWORD NULL
|
||||
#endif
|
||||
#ifndef MBED_CONF_NSAPI_DEFAULT_WIFI_SECURITY
|
||||
#define MBED_CONF_NSAPI_DEFAULT_WIFI_SECURITY NONE
|
||||
#endif
|
||||
#define concat_(x,y) x##y
|
||||
#define concat(x,y) concat_(x,y)
|
||||
#define SECURITY concat(NSAPI_SECURITY_,MBED_CONF_NSAPI_DEFAULT_WIFI_SECURITY)
|
||||
set_credentials(MBED_CONF_NSAPI_DEFAULT_WIFI_SSID, MBED_CONF_NSAPI_DEFAULT_WIFI_PASSWORD, SECURITY);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CellularBase::set_default_parameters()
|
||||
{
|
||||
/* CellularBase is expected to attempt to work without any parameters - we
|
||||
* will try, at least.
|
||||
*/
|
||||
#ifdef MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN
|
||||
#ifndef MBED_CONF_NSAPI_DEFAULT_CELLULAR_USERNAME
|
||||
#define MBED_CONF_NSAPI_DEFAULT_CELLULAR_USERNAME NULL
|
||||
#endif
|
||||
#ifndef MBED_CONF_NSAPI_DEFAULT_CELLULAR_PASSWORD
|
||||
#define MBED_CONF_NSAPI_DEFAULT_CELLULAR_PASSWORD NULL
|
||||
#endif
|
||||
set_credentials(MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN, MBED_CONF_NSAPI_DEFAULT_CELLULAR_USERNAME, MBED_CONF_NSAPI_DEFAULT_CELLULAR_PASSWORD);
|
||||
#endif
|
||||
#ifdef MBED_CONF_NSAPI_DEFAULT_CELLULAR_SIM_PIN
|
||||
set_sim_pin(MBED_CONF_NSAPI_DEFAULT_CELLULAR_SIM_PIN);
|
||||
#endif
|
||||
#ifdef MBED_CONF_NSAPI_DEFAULT_CELLULAR_PLMN
|
||||
set_plmn(MBED_CONF_NSAPI_DEFAULT_CELLULAR_PLMN);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Finally the dispatch from the JSON default interface type to the specific
|
||||
* subclasses. It's our job to configure - the default NetworkInterface is
|
||||
* preconfigured - the specific subtypes' defaults are not (necessarily).
|
||||
|
|
@ -87,16 +134,7 @@ MBED_WEAK NetworkInterface *NetworkInterface::get_target_default_instance()
|
|||
if (!wifi) {
|
||||
return NULL;
|
||||
}
|
||||
#ifndef MBED_CONF_NSAPI_DEFAULT_WIFI_PASSWORD
|
||||
#define MBED_CONF_NSAPI_DEFAULT_WIFI_PASSWORD NULL
|
||||
#endif
|
||||
#ifndef MBED_CONF_NSAPI_DEFAULT_WIFI_SECURITY
|
||||
#define MBED_CONF_NSAPI_DEFAULT_WIFI_SECURITY NONE
|
||||
#endif
|
||||
#define concat_(x,y) x##y
|
||||
#define concat(x,y) concat_(x,y)
|
||||
#define SECURITY concat(NSAPI_SECURITY_,MBED_CONF_NSAPI_DEFAULT_WIFI_SECURITY)
|
||||
wifi->set_credentials(MBED_CONF_NSAPI_DEFAULT_WIFI_SSID, MBED_CONF_NSAPI_DEFAULT_WIFI_PASSWORD, SECURITY);
|
||||
wifi->set_default_parameters();
|
||||
return wifi;
|
||||
#else
|
||||
return NULL;
|
||||
|
|
@ -114,24 +152,7 @@ MBED_WEAK NetworkInterface *NetworkInterface::get_target_default_instance()
|
|||
if (!cellular) {
|
||||
return NULL;
|
||||
}
|
||||
/* CellularBase is expected to attempt to work without any parameters - we
|
||||
* will try, at least.
|
||||
*/
|
||||
#ifdef MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN
|
||||
#ifndef MBED_CONF_NSAPI_DEFAULT_CELLULAR_USERNAME
|
||||
#define MBED_CONF_NSAPI_DEFAULT_CELLULAR_USERNAME NULL
|
||||
#endif
|
||||
#ifndef MBED_CONF_NSAPI_DEFAULT_CELLULAR_PASSWORD
|
||||
#define MBED_CONF_NSAPI_DEFAULT_CELLULAR_PASSWORD NULL
|
||||
#endif
|
||||
cellular->set_credentials(MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN, MBED_CONF_NSAPI_DEFAULT_CELLULAR_USERNAME, MBED_CONF_NSAPI_DEFAULT_CELLULAR_PASSWORD);
|
||||
#endif
|
||||
#ifdef MBED_CONF_NSAPI_DEFAULT_CELLULAR_SIM_PIN
|
||||
cellular->set_sim_pin(MBED_CONF_NSAPI_DEFAULT_CELLULAR_SIM_PIN);
|
||||
#endif
|
||||
#ifdef MBED_CONF_NSAPI_DEFAULT_CELLULAR_PLMN
|
||||
cellular->set_plmn(MBED_CONF_NSAPI_DEFAULT_CELLULAR_PLMN);
|
||||
#endif
|
||||
cellular->set_default_parameters();
|
||||
return cellular;
|
||||
}
|
||||
#elif defined(MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE)
|
||||
|
|
|
|||
|
|
@ -40,6 +40,17 @@ public:
|
|||
*/
|
||||
static WiFiInterface *get_default_instance();
|
||||
|
||||
/** Set default parameters on a Wi-Fi interface.
|
||||
*
|
||||
* A Wi-Fi interface instantiated directly or using
|
||||
* WiFiInterface::get_default_instance() is initially unconfigured.
|
||||
* This call can be used to set the default parameters that would
|
||||
* have been set if the interface had been requested using
|
||||
* NetworkInterface::get_default_instance() (see nsapi JSON
|
||||
* configuration).
|
||||
*/
|
||||
virtual void set_default_parameters();
|
||||
|
||||
/** Set the Wi-Fi network credentials.
|
||||
*
|
||||
* @param ssid Name of the network to connect to.
|
||||
|
|
|
|||
Loading…
Reference in New Issue