From 5a118826a8e9d41cb334349a2685348954fbe78b Mon Sep 17 00:00:00 2001 From: Jamie Smith Date: Fri, 19 Jul 2024 01:36:19 -0700 Subject: [PATCH] Fix CellularInterface functions never being defined (#307) * Fix several link errors with mbed-cellular * Fix unittest failure * Try again to fix unit tests? * OK try and fix these a little better * Fix style --- .../framework/device/CellularContext.cpp | 22 +++++++++++++ .../doubles/CellularContext_stub.cpp | 5 +++ .../coap-service/unittest/stub/mbedtls_stub.c | 10 +++--- connectivity/netsocket/CMakeLists.txt | 5 +++ .../source/NetworkInterfaceDefaults.cpp | 31 ------------------- .../doubles/NetworkInterfaceDefaults_stub.cpp | 4 --- .../build/_internal/config/config.py | 10 ++++++ 7 files changed, 47 insertions(+), 40 deletions(-) diff --git a/connectivity/cellular/source/framework/device/CellularContext.cpp b/connectivity/cellular/source/framework/device/CellularContext.cpp index d72b6b52631..c7805156712 100644 --- a/connectivity/cellular/source/framework/device/CellularContext.cpp +++ b/connectivity/cellular/source/framework/device/CellularContext.cpp @@ -25,6 +25,28 @@ MBED_WEAK CellularInterface *CellularInterface::get_target_default_instance() return mbed::CellularContext::get_default_instance(); } +void CellularInterface::set_default_parameters() +{ + /* CellularInterface 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 +} + namespace mbed { MBED_WEAK CellularContext *CellularContext::get_default_instance() diff --git a/connectivity/cellular/tests/UNITTESTS/doubles/CellularContext_stub.cpp b/connectivity/cellular/tests/UNITTESTS/doubles/CellularContext_stub.cpp index 1ef00faf063..489dac48eff 100644 --- a/connectivity/cellular/tests/UNITTESTS/doubles/CellularContext_stub.cpp +++ b/connectivity/cellular/tests/UNITTESTS/doubles/CellularContext_stub.cpp @@ -16,6 +16,11 @@ */ #include "CellularContext.h" +#include "netsocket/CellularInterface.h" + +void CellularInterface::set_default_parameters() +{ +} namespace mbed { diff --git a/connectivity/nanostack/coap-service/test/coap-service/unittest/stub/mbedtls_stub.c b/connectivity/nanostack/coap-service/test/coap-service/unittest/stub/mbedtls_stub.c index 32026c4fe6e..4a17fbfffe5 100644 --- a/connectivity/nanostack/coap-service/test/coap-service/unittest/stub/mbedtls_stub.c +++ b/connectivity/nanostack/coap-service/test/coap-service/unittest/stub/mbedtls_stub.c @@ -403,12 +403,12 @@ void mbedtls_ssl_conf_dtls_cookies(mbedtls_ssl_config *conf, void *p_cookie) { if (mbedtls_stub.cookie_obj && f_cookie_check && mbedtls_stub.cookie_len > 0) { - f_cookie_check(mbedtls_stub.cookie_obj, &mbedtls_stub.cookie_value, mbedtls_stub.cookie_len, NULL, 0); + f_cookie_check(mbedtls_stub.cookie_obj, mbedtls_stub.cookie_value, mbedtls_stub.cookie_len, NULL, 0); } if (mbedtls_stub.cookie_obj && f_cookie_write && mbedtls_stub.cookie_len > 0) { unsigned char out[16]; - unsigned char *ptr = &out; - f_cookie_write(mbedtls_stub.cookie_obj, &ptr, ptr + mbedtls_stub.cookie_len, NULL, 0); + unsigned char *ptr = out; + f_cookie_write(mbedtls_stub.cookie_obj, &ptr, out + mbedtls_stub.cookie_len, NULL, 0); } } @@ -420,9 +420,9 @@ void mbedtls_ssl_conf_export_keys_cb(mbedtls_ssl_config *conf, if (f_export_keys && p_export_keys) { unsigned char value[40]; memset(&value, 1, 40); - f_export_keys(p_export_keys, &value, "", 0, 0, 0); //failure case + f_export_keys(p_export_keys, value, "", 0, 0, 0); //failure case - f_export_keys(p_export_keys, &value, "", 0, 20, 0); //success case + f_export_keys(p_export_keys, value, "", 0, 20, 0); //success case } } #endif diff --git a/connectivity/netsocket/CMakeLists.txt b/connectivity/netsocket/CMakeLists.txt index ce0b315b677..b0623b4fec5 100644 --- a/connectivity/netsocket/CMakeLists.txt +++ b/connectivity/netsocket/CMakeLists.txt @@ -64,6 +64,11 @@ elseif("MBED_CONF_NSAPI_DEFAULT_STACK=NANOSTACK" IN_LIST MBED_CONFIG_DEFINITIONS target_link_libraries(mbed-netsocket-api PUBLIC mbed-nanostack) endif() +# Pull in cellular if cellular is the default network interface (used by NetworkInterfaceDefaults.cpp) +if("MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE=CELLULAR" IN_LIST MBED_CONFIG_DEFINITIONS) + target_link_libraries(mbed-netsocket-api PUBLIC mbed-cellular) +endif() + if("DEVICE_EMAC=1" IN_LIST MBED_TARGET_DEFINITIONS) target_link_libraries(mbed-netsocket-api INTERFACE diff --git a/connectivity/netsocket/source/NetworkInterfaceDefaults.cpp b/connectivity/netsocket/source/NetworkInterfaceDefaults.cpp index 1a814fff8bc..9529df92d21 100644 --- a/connectivity/netsocket/source/NetworkInterfaceDefaults.cpp +++ b/connectivity/netsocket/source/NetworkInterfaceDefaults.cpp @@ -43,13 +43,6 @@ MBED_WEAK MeshInterface *MeshInterface::get_default_instance() return get_target_default_instance(); } -#if MBED_CONF_CELLULAR_PRESENT -MBED_WEAK CellularInterface *CellularInterface::get_default_instance() -{ - return get_target_default_instance(); -} -#endif // MBED_CONF_CELLULAR_PRESENT - /* For other types, we can provide a reasonable get_target_default_instance * in some cases. This is done in EthernetInterface.cpp, mbed-mesh-api and * OnboardCellularInterface.cpp. We have no implementation for WiFi, so a @@ -92,30 +85,6 @@ void WiFiInterface::set_default_parameters() #endif } -#if MBED_CONF_CELLULAR_PRESENT -void CellularInterface::set_default_parameters() -{ - /* CellularInterface 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 -} -#endif // MBED_CONF_CELLULAR_PRESENT - /* 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). diff --git a/connectivity/netsocket/tests/UNITTESTS/doubles/NetworkInterfaceDefaults_stub.cpp b/connectivity/netsocket/tests/UNITTESTS/doubles/NetworkInterfaceDefaults_stub.cpp index dd3a562b2b0..8128f10b34b 100644 --- a/connectivity/netsocket/tests/UNITTESTS/doubles/NetworkInterfaceDefaults_stub.cpp +++ b/connectivity/netsocket/tests/UNITTESTS/doubles/NetworkInterfaceDefaults_stub.cpp @@ -52,10 +52,6 @@ void WiFiInterface::set_default_parameters() { } -void CellularInterface::set_default_parameters() -{ -} - MBED_WEAK NetworkInterface *NetworkInterface::get_target_default_instance() { return NULL; diff --git a/tools/python/mbed_tools/build/_internal/config/config.py b/tools/python/mbed_tools/build/_internal/config/config.py index 61ce6772a62..7444c9324aa 100644 --- a/tools/python/mbed_tools/build/_internal/config/config.py +++ b/tools/python/mbed_tools/build/_internal/config/config.py @@ -56,6 +56,16 @@ def _handle_overrides(self, overrides: Iterable[Override]) -> None: "Please check your target_overrides are correct.\n" f"The parameter `{override.namespace}.{override.name}` will not be added to the configuration." ) + + valid_params_in_namespace = list(filter( + lambda x: x.namespace == override.namespace, + self.data.get(CONFIG_SECTION, []), + )) + valid_param_names = [f'"{param.namespace}.{param.name}"' for param in valid_params_in_namespace] + + if len(valid_param_names) > 0: + logger.warning(f'Valid config parameters in this namespace are: {", ".join(valid_param_names)}. ' + f'Maybe you meant one of those?') else: setting.value = override.value