diff --git a/UNITTESTS/features/cellular/framework/common/util/utiltest.cpp b/UNITTESTS/features/cellular/framework/common/util/utiltest.cpp index 23ff20f8265..d2ed76036d4 100644 --- a/UNITTESTS/features/cellular/framework/common/util/utiltest.cpp +++ b/UNITTESTS/features/cellular/framework/common/util/utiltest.cpp @@ -18,7 +18,6 @@ #include #include "CellularUtil.h" -using namespace mbed; using namespace mbed_cellular_util; // AStyle ignored as the definition is not clear due to preprocessor usage @@ -250,22 +249,3 @@ TEST_F(Testutil, int_to_hex_str) EXPECT_TRUE(buf[0] == '6'); EXPECT_TRUE(buf[1] == '4'); } - -TEST_F(Testutil, string_to_pdp_type) -{ - pdp_type_t type = string_to_pdp_type("IPV4V6"); - ASSERT_EQ(type, IPV4V6_PDP_TYPE); - - type = string_to_pdp_type("IPV6"); - ASSERT_EQ(type, IPV6_PDP_TYPE); - - type = string_to_pdp_type("IP"); - ASSERT_EQ(type, IPV4_PDP_TYPE); - - type = string_to_pdp_type("Non-IP"); - ASSERT_EQ(type, NON_IP_PDP_TYPE); - - type = string_to_pdp_type("diipadaapa"); - ASSERT_EQ(type, DEFAULT_PDP_TYPE); -} - diff --git a/UNITTESTS/features/cellular/framework/device/cellularcontext/cellularcontexttest.cpp b/UNITTESTS/features/cellular/framework/device/cellularcontext/cellularcontexttest.cpp index 617f33ef8a3..3e6b889ed52 100644 --- a/UNITTESTS/features/cellular/framework/device/cellularcontext/cellularcontexttest.cpp +++ b/UNITTESTS/features/cellular/framework/device/cellularcontext/cellularcontexttest.cpp @@ -47,12 +47,15 @@ class testContext : public CellularContext { _device = dev; _cp_netif = new ControlPlane_netif_stub(); + + nonip_pdp_string = NULL; } ~testContext() { delete _cp_netif; } + int get_retry_count() { return _retry_count; @@ -180,6 +183,11 @@ class testContext : public CellularContext } + const char *get_nonip_context_type_str() + { + return nonip_pdp_string; + } + void cp_data_received() { CellularContext::cp_data_received(); @@ -198,6 +206,58 @@ class testContext : public CellularContext { CellularContext::do_connect_with_retry(); } + + void test_string_to_pdp_type() + { + pdp_type_t type = string_to_pdp_type("IPV4V6"); + ASSERT_EQ(type, IPV4V6_PDP_TYPE); + + type = string_to_pdp_type("IPV6"); + ASSERT_EQ(type, IPV6_PDP_TYPE); + + type = string_to_pdp_type("IP"); + ASSERT_EQ(type, IPV4_PDP_TYPE); + + type = string_to_pdp_type("Non-IP"); + ASSERT_EQ(type, NON_IP_PDP_TYPE); + + nonip_pdp_string = NULL; + type = string_to_pdp_type("diipadaapa"); + ASSERT_EQ(type, DEFAULT_PDP_TYPE); + } + + void test_nonip_context_type_str() + { + nonip_pdp_string = "NONIP"; + + pdp_type_t type = string_to_pdp_type("diipadaapa"); + ASSERT_EQ(type, DEFAULT_PDP_TYPE); + + type = string_to_pdp_type("NONIP"); + ASSERT_EQ(type, NON_IP_PDP_TYPE); + + type = string_to_pdp_type("nonip"); + ASSERT_EQ(type, DEFAULT_PDP_TYPE); + + type = string_to_pdp_type("IPV6"); + ASSERT_EQ(type, IPV6_PDP_TYPE); + + nonip_pdp_string = "testnonip"; + + type = string_to_pdp_type("diipadaapa"); + ASSERT_EQ(type, DEFAULT_PDP_TYPE); + + type = string_to_pdp_type("testnonip"); + ASSERT_EQ(type, NON_IP_PDP_TYPE); + + type = string_to_pdp_type("nonip"); + ASSERT_EQ(type, DEFAULT_PDP_TYPE); + + type = string_to_pdp_type("IPV6"); + ASSERT_EQ(type, IPV6_PDP_TYPE); + } + + const char *nonip_pdp_string; }; static int network_cb_count = 0; @@ -314,6 +374,20 @@ TEST_F(TestCellularContext, do_connect_with_retry_async) delete dev; } +TEST_F(TestCellularContext, string_to_pdp_type) +{ + testContext *ctx = new testContext(); + EXPECT_TRUE(ctx != NULL); + ctx->test_string_to_pdp_type(); + delete ctx; +} +TEST_F(TestCellularContext, nonip_context_type_str) +{ + testContext *ctx = new testContext(); + EXPECT_TRUE(ctx != NULL); + ctx->test_nonip_context_type_str(); + delete ctx; +} diff --git a/UNITTESTS/stubs/CellularContext_stub.cpp b/UNITTESTS/stubs/CellularContext_stub.cpp index f976643848d..aa51554ee01 100644 --- a/UNITTESTS/stubs/CellularContext_stub.cpp +++ b/UNITTESTS/stubs/CellularContext_stub.cpp @@ -68,4 +68,9 @@ void CellularContext::call_network_cb(nsapi_connection_status_t status) } } +CellularContext::pdp_type_t CellularContext::string_to_pdp_type(const char *pdp_type) +{ + return IPV4V6_PDP_TYPE; +} + } diff --git a/UNITTESTS/stubs/CellularUtil_stub.cpp b/UNITTESTS/stubs/CellularUtil_stub.cpp index d54469a6590..d33474dbacc 100644 --- a/UNITTESTS/stubs/CellularUtil_stub.cpp +++ b/UNITTESTS/stubs/CellularUtil_stub.cpp @@ -28,7 +28,6 @@ int CellularUtil_stub::char_pos = 0; char *CellularUtil_stub::char_table[50] = {}; int CellularUtil_stub::table_idx = 0; -using namespace mbed; namespace mbed_cellular_util { #define MAX_STRING_LEN 200 @@ -134,9 +133,4 @@ uint16_t get_dynamic_ip_port() return CellularUtil_stub::uint16_value; } -pdp_type_t string_to_pdp_type(const char *pdp_type) -{ - return IPV4V6_PDP_TYPE; -} - } // namespace mbed_cellular_util diff --git a/features/cellular/framework/API/CellularContext.h b/features/cellular/framework/API/CellularContext.h index 170cd63f907..6aed7f937c5 100644 --- a/features/cellular/framework/API/CellularContext.h +++ b/features/cellular/framework/API/CellularContext.h @@ -305,6 +305,14 @@ class CellularContext : public CellularInterface { OP_MAX = 5 }; + enum pdp_type_t { + DEFAULT_PDP_TYPE = DEFAULT_STACK, + IPV4_PDP_TYPE = IPV4_STACK, + IPV6_PDP_TYPE = IPV6_STACK, + IPV4V6_PDP_TYPE = IPV4V6_STACK, + NON_IP_PDP_TYPE + }; + /** The CellularDevice calls the status callback function on status changes on the network or CellularDevice. * * @param ev event type @@ -321,6 +329,16 @@ class CellularContext : public CellularInterface { */ virtual void enable_hup(bool enable) = 0; + /** Return PDP type string for Non-IP if modem uses other than standard "Non-IP" + * + * Some modems uses a non-standard PDP type string for non-ip (e.g. "NONIP"). + * In those cases modem driver must implement this method to return the PDP type string + * used by the modem. + * + * @return PDP type string used by the modem or NULL if standard ("Non-IP") + */ + virtual const char *get_nonip_context_type_str() = 0; + /** Triggers control plane's operations needed when control plane data is received, * like socket event, for example. */ @@ -347,6 +365,14 @@ class CellularContext : public CellularInterface { */ void validate_ip_address(); + /** Converts the given pdp type in char format to enum pdp_type_t + * + * @param pdp_type pdp type in string format + * @return converted pdp_type_t enum + */ + CellularContext::pdp_type_t string_to_pdp_type(const char *pdp_type); + +protected: // member variables needed in target override methods NetworkStack *_stack; // must be pointer because of PPP pdp_type_t _pdp_type; diff --git a/features/cellular/framework/common/CellularUtil.cpp b/features/cellular/framework/common/CellularUtil.cpp index 07f33c71f58..ffb7d90d1d7 100644 --- a/features/cellular/framework/common/CellularUtil.cpp +++ b/features/cellular/framework/common/CellularUtil.cpp @@ -25,7 +25,6 @@ #define RANDOM_PORT_NUMBER_COUNT (RANDOM_PORT_NUMBER_END - RANDOM_PORT_NUMBER_START + 1) #define RANDOM_PORT_NUMBER_MAX_STEP 100 -using namespace mbed; namespace mbed_cellular_util { nsapi_version_t convert_ipv6(char *ip) @@ -365,23 +364,4 @@ uint16_t get_dynamic_ip_port() return (RANDOM_PORT_NUMBER_START + port_counter); } -pdp_type_t string_to_pdp_type(const char *pdp_type_str) -{ - pdp_type_t pdp_type = DEFAULT_PDP_TYPE; - int len = strlen(pdp_type_str); - - if (len == 6 && memcmp(pdp_type_str, "IPV4V6", len) == 0) { - pdp_type = IPV4V6_PDP_TYPE; - } else if (len == 4 && memcmp(pdp_type_str, "IPV6", len) == 0) { - pdp_type = IPV6_PDP_TYPE; - } else if (len == 2 && memcmp(pdp_type_str, "IP", len) == 0) { - pdp_type = IPV4_PDP_TYPE; - } else if (len == 6 && memcmp(pdp_type_str, "Non-IP", len) == 0) { - pdp_type = NON_IP_PDP_TYPE; - } else if (len == 5 && memcmp(pdp_type_str, "NONIP", len) == 0) { - pdp_type = NON_IP_PDP_TYPE; - } - return pdp_type; -} - } // namespace mbed_cellular_util diff --git a/features/cellular/framework/common/CellularUtil.h b/features/cellular/framework/common/CellularUtil.h index cfe0c86cbaf..ede626be2fb 100644 --- a/features/cellular/framework/common/CellularUtil.h +++ b/features/cellular/framework/common/CellularUtil.h @@ -22,16 +22,6 @@ #include #include "nsapi_types.h" -namespace mbed { - -typedef enum pdp_type { - DEFAULT_PDP_TYPE = DEFAULT_STACK, - IPV4_PDP_TYPE = IPV4_STACK, - IPV6_PDP_TYPE = IPV6_STACK, - IPV4V6_PDP_TYPE = IPV4V6_STACK, - NON_IP_PDP_TYPE -} pdp_type_t; -} namespace mbed_cellular_util { // some helper macros @@ -139,13 +129,6 @@ uint32_t binary_str_to_uint(const char *binary_string, int binary_string_length) */ uint16_t get_dynamic_ip_port(); -/** Converts the given pdp type in char format to enum pdp_type_t - * - * @param pdp_type pdp type in string format - * @return converted pdp_type_t enum - */ -mbed::pdp_type_t string_to_pdp_type(const char *pdp_type); - } // namespace mbed_cellular_util #endif diff --git a/features/cellular/framework/device/CellularContext.cpp b/features/cellular/framework/device/CellularContext.cpp index 9b6ab190756..35c174b0b10 100644 --- a/features/cellular/framework/device/CellularContext.cpp +++ b/features/cellular/framework/device/CellularContext.cpp @@ -113,6 +113,27 @@ void CellularContext::validate_ip_address() } } +CellularContext::pdp_type_t CellularContext::string_to_pdp_type(const char *pdp_type_str) +{ + pdp_type_t pdp_type = DEFAULT_PDP_TYPE; + int len = strlen(pdp_type_str); + + if (len == 6 && memcmp(pdp_type_str, "IPV4V6", len) == 0) { + pdp_type = IPV4V6_PDP_TYPE; + } else if (len == 4 && memcmp(pdp_type_str, "IPV6", len) == 0) { + pdp_type = IPV6_PDP_TYPE; + } else if (len == 2 && memcmp(pdp_type_str, "IP", len) == 0) { + pdp_type = IPV4_PDP_TYPE; + } else if (len == 6 && memcmp(pdp_type_str, "Non-IP", len) == 0) { + pdp_type = NON_IP_PDP_TYPE; + } else if (get_nonip_context_type_str() && + len == strlen(get_nonip_context_type_str()) && + memcmp(pdp_type_str, get_nonip_context_type_str(), len) == 0) { + pdp_type = NON_IP_PDP_TYPE; + } + return pdp_type; +} + void CellularContext::do_connect_with_retry() { if (_cb_data.final_try) {