Skip to content

Cellular: moved string_to_pdp_type from AT_CellularContext to Cellula… #11200

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
Aug 14, 2019
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
19 changes: 19 additions & 0 deletions UNITTESTS/features/cellular/framework/common/util/utiltest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#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 @@ -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);
}

5 changes: 0 additions & 5 deletions UNITTESTS/stubs/AT_CellularContext_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
6 changes: 6 additions & 0 deletions UNITTESTS/stubs/CellularUtil_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
9 changes: 1 addition & 8 deletions features/cellular/framework/API/CellularContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "CellularInterface.h"
#include "CellularDevice.h"
#include "CellularUtil.h"
#include "ControlPlane_netif.h"
#include "PinNames.h"

Expand All @@ -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
* @{
Expand Down
18 changes: 0 additions & 18 deletions features/cellular/framework/AT/AT_CellularContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
{
Expand Down
1 change: 0 additions & 1 deletion features/cellular/framework/AT/AT_CellularContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 18 additions & 1 deletion features/cellular/framework/common/CellularUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
20 changes: 19 additions & 1 deletion features/cellular/framework/common/CellularUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,18 @@

#include <stddef.h>
#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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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) :
Expand Down