diff --git a/UNITTESTS/features/cellular/framework/common/util/utiltest.cpp b/UNITTESTS/features/cellular/framework/common/util/utiltest.cpp index a2b5b4dcc9f..a52a9dd4877 100644 --- a/UNITTESTS/features/cellular/framework/common/util/utiltest.cpp +++ b/UNITTESTS/features/cellular/framework/common/util/utiltest.cpp @@ -18,6 +18,7 @@ #include #include "CellularUtil.h" +using namespace mbed; using namespace mbed_cellular_util; // AStyle ignored as the definition is not clear due to preprocessor usage @@ -215,3 +216,21 @@ TEST_F(Testutil, int_to_hex_str) 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/stubs/AT_CellularContext_stub.cpp b/UNITTESTS/stubs/AT_CellularContext_stub.cpp index 4f89449efaa..306421dbaf6 100644 --- a/UNITTESTS/stubs/AT_CellularContext_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularContext_stub.cpp @@ -166,11 +166,6 @@ AT_CellularBase::CellularProperty AT_CellularContext::pdp_type_t_to_cellular_pro return prop; } -pdp_type_t AT_CellularContext::string_to_pdp_type(const char *pdp_type) -{ - return IPV4V6_PDP_TYPE; -} - // PDP Context handling nsapi_error_t AT_CellularContext::delete_current_context() { diff --git a/UNITTESTS/stubs/CellularUtil_stub.cpp b/UNITTESTS/stubs/CellularUtil_stub.cpp index 4ef142c3a53..76d3c143d23 100644 --- a/UNITTESTS/stubs/CellularUtil_stub.cpp +++ b/UNITTESTS/stubs/CellularUtil_stub.cpp @@ -28,6 +28,7 @@ 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 @@ -124,4 +125,9 @@ 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 7f5c1ceb40b..4383be3ed74 100644 --- a/features/cellular/framework/API/CellularContext.h +++ b/features/cellular/framework/API/CellularContext.h @@ -19,6 +19,7 @@ #include "CellularInterface.h" #include "CellularDevice.h" +#include "CellularUtil.h" #include "ControlPlane_netif.h" #include "PinNames.h" @@ -29,14 +30,6 @@ 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; - /** * @addtogroup cellular * @{ diff --git a/features/cellular/framework/AT/AT_CellularContext.cpp b/features/cellular/framework/AT/AT_CellularContext.cpp index 04dbe60cb56..1776cd045a4 100644 --- a/features/cellular/framework/AT/AT_CellularContext.cpp +++ b/features/cellular/framework/AT/AT_CellularContext.cpp @@ -20,7 +20,6 @@ #include "AT_CellularStack.h" #include "AT_CellularDevice.h" #include "CellularLog.h" -#include "CellularUtil.h" #if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY) #include "UARTSerial.h" #endif // #if DEVICE_SERIAL @@ -291,23 +290,6 @@ void AT_CellularContext::set_credentials(const char *apn, const char *uname, con _pwd = pwd; } -pdp_type_t AT_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; - } - return pdp_type; -} - // PDP Context handling nsapi_error_t AT_CellularContext::delete_current_context() { diff --git a/features/cellular/framework/AT/AT_CellularContext.h b/features/cellular/framework/AT/AT_CellularContext.h index 9831d9b9fab..c50e69440ab 100644 --- a/features/cellular/framework/AT/AT_CellularContext.h +++ b/features/cellular/framework/AT/AT_CellularContext.h @@ -101,7 +101,6 @@ class AT_CellularContext : public CellularContext, public AT_CellularBase { virtual void set_disconnect(); virtual void deactivate_context(); virtual bool get_context(); - pdp_type_t string_to_pdp_type(const char *pdp_type); AT_CellularBase::CellularProperty pdp_type_t_to_cellular_property(pdp_type_t pdp_type); bool set_new_context(int cid); private: diff --git a/features/cellular/framework/common/CellularUtil.cpp b/features/cellular/framework/common/CellularUtil.cpp index b1cdc2a0c87..22a88873443 100644 --- a/features/cellular/framework/common/CellularUtil.cpp +++ b/features/cellular/framework/common/CellularUtil.cpp @@ -25,7 +25,7 @@ #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 { void convert_ipv6(char *ip) @@ -355,4 +355,21 @@ 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; + } + return pdp_type; +} + } // namespace mbed_cellular_util diff --git a/features/cellular/framework/common/CellularUtil.h b/features/cellular/framework/common/CellularUtil.h index b9b0db95da4..43170de8887 100644 --- a/features/cellular/framework/common/CellularUtil.h +++ b/features/cellular/framework/common/CellularUtil.h @@ -20,7 +20,18 @@ #include #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 @@ -120,6 +131,13 @@ 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/targets/TELIT/ME910/TELIT_ME910_CellularContext.cpp b/features/cellular/framework/targets/TELIT/ME910/TELIT_ME910_CellularContext.cpp index ff286f2f16d..3de2c11bca6 100644 --- a/features/cellular/framework/targets/TELIT/ME910/TELIT_ME910_CellularContext.cpp +++ b/features/cellular/framework/targets/TELIT/ME910/TELIT_ME910_CellularContext.cpp @@ -19,6 +19,8 @@ #include "Semaphore.h" +using namespace mbed_cellular_util; + namespace mbed { TELIT_ME910_CellularContext::TELIT_ME910_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) :