Skip to content

Cellular: Move string_to_pdp_type method to CellularContext #12214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions UNITTESTS/features/cellular/framework/common/util/utiltest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <string.h>
#include "CellularUtil.h"

using namespace mbed;
using namespace mbed_cellular_util;

// AStyle ignored as the definition is not clear due to preprocessor usage
Expand Down Expand Up @@ -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);
}

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
5 changes: 5 additions & 0 deletions UNITTESTS/stubs/CellularContext_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
6 changes: 0 additions & 6 deletions UNITTESTS/stubs/CellularUtil_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
26 changes: 26 additions & 0 deletions features/cellular/framework/API/CellularContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
*/
Expand All @@ -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;
Expand Down
20 changes: 0 additions & 20 deletions features/cellular/framework/common/CellularUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
17 changes: 0 additions & 17 deletions features/cellular/framework/common/CellularUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@
#include <inttypes.h>
#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
Expand Down Expand Up @@ -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
21 changes: 21 additions & 0 deletions features/cellular/framework/device/CellularContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down