Skip to content

Commit 0a73eda

Browse files
authored
Merge pull request ARMmbed#11200 from jarvte/move_string_to_pdp_type
Cellular: moved string_to_pdp_type from AT_CellularContext to Cellula…
2 parents a64ab31 + 3c1bf0a commit 0a73eda

File tree

9 files changed

+65
-34
lines changed

9 files changed

+65
-34
lines changed

UNITTESTS/features/cellular/framework/common/util/utiltest.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <string.h>
1919
#include "CellularUtil.h"
2020

21+
using namespace mbed;
2122
using namespace mbed_cellular_util;
2223

2324
// AStyle ignored as the definition is not clear due to preprocessor usage
@@ -215,3 +216,21 @@ TEST_F(Testutil, int_to_hex_str)
215216
EXPECT_TRUE(buf[1] == '4');
216217
}
217218

219+
TEST_F(Testutil, string_to_pdp_type)
220+
{
221+
pdp_type_t type = string_to_pdp_type("IPV4V6");
222+
ASSERT_EQ(type, IPV4V6_PDP_TYPE);
223+
224+
type = string_to_pdp_type("IPV6");
225+
ASSERT_EQ(type, IPV6_PDP_TYPE);
226+
227+
type = string_to_pdp_type("IP");
228+
ASSERT_EQ(type, IPV4_PDP_TYPE);
229+
230+
type = string_to_pdp_type("Non-IP");
231+
ASSERT_EQ(type, NON_IP_PDP_TYPE);
232+
233+
type = string_to_pdp_type("diipadaapa");
234+
ASSERT_EQ(type, DEFAULT_PDP_TYPE);
235+
}
236+

UNITTESTS/stubs/AT_CellularContext_stub.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,6 @@ AT_CellularBase::CellularProperty AT_CellularContext::pdp_type_t_to_cellular_pro
166166
return prop;
167167
}
168168

169-
pdp_type_t AT_CellularContext::string_to_pdp_type(const char *pdp_type)
170-
{
171-
return IPV4V6_PDP_TYPE;
172-
}
173-
174169
// PDP Context handling
175170
nsapi_error_t AT_CellularContext::delete_current_context()
176171
{

UNITTESTS/stubs/CellularUtil_stub.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ int CellularUtil_stub::char_pos = 0;
2828
char *CellularUtil_stub::char_table[50] = {};
2929
int CellularUtil_stub::table_idx = 0;
3030

31+
using namespace mbed;
3132
namespace mbed_cellular_util {
3233

3334
#define MAX_STRING_LEN 200
@@ -124,4 +125,9 @@ uint16_t get_dynamic_ip_port()
124125
return CellularUtil_stub::uint16_value;
125126
}
126127

128+
pdp_type_t string_to_pdp_type(const char *pdp_type)
129+
{
130+
return IPV4V6_PDP_TYPE;
131+
}
132+
127133
} // namespace mbed_cellular_util

features/cellular/framework/API/CellularContext.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "CellularInterface.h"
2121
#include "CellularDevice.h"
22+
#include "CellularUtil.h"
2223
#include "ControlPlane_netif.h"
2324
#include "PinNames.h"
2425

@@ -29,14 +30,6 @@
2930

3031
namespace mbed {
3132

32-
typedef enum pdp_type {
33-
DEFAULT_PDP_TYPE = DEFAULT_STACK,
34-
IPV4_PDP_TYPE = IPV4_STACK,
35-
IPV6_PDP_TYPE = IPV6_STACK,
36-
IPV4V6_PDP_TYPE = IPV4V6_STACK,
37-
NON_IP_PDP_TYPE
38-
} pdp_type_t;
39-
4033
/**
4134
* @addtogroup cellular
4235
* @{

features/cellular/framework/AT/AT_CellularContext.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "AT_CellularStack.h"
2121
#include "AT_CellularDevice.h"
2222
#include "CellularLog.h"
23-
#include "CellularUtil.h"
2423
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
2524
#include "UARTSerial.h"
2625
#endif // #if DEVICE_SERIAL
@@ -291,23 +290,6 @@ void AT_CellularContext::set_credentials(const char *apn, const char *uname, con
291290
_pwd = pwd;
292291
}
293292

294-
pdp_type_t AT_CellularContext::string_to_pdp_type(const char *pdp_type_str)
295-
{
296-
pdp_type_t pdp_type = DEFAULT_PDP_TYPE;
297-
int len = strlen(pdp_type_str);
298-
299-
if (len == 6 && memcmp(pdp_type_str, "IPV4V6", len) == 0) {
300-
pdp_type = IPV4V6_PDP_TYPE;
301-
} else if (len == 4 && memcmp(pdp_type_str, "IPV6", len) == 0) {
302-
pdp_type = IPV6_PDP_TYPE;
303-
} else if (len == 2 && memcmp(pdp_type_str, "IP", len) == 0) {
304-
pdp_type = IPV4_PDP_TYPE;
305-
} else if (len == 6 && memcmp(pdp_type_str, "Non-IP", len) == 0) {
306-
pdp_type = NON_IP_PDP_TYPE;
307-
}
308-
return pdp_type;
309-
}
310-
311293
// PDP Context handling
312294
nsapi_error_t AT_CellularContext::delete_current_context()
313295
{

features/cellular/framework/AT/AT_CellularContext.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ class AT_CellularContext : public CellularContext, public AT_CellularBase {
101101
virtual void set_disconnect();
102102
virtual void deactivate_context();
103103
virtual bool get_context();
104-
pdp_type_t string_to_pdp_type(const char *pdp_type);
105104
AT_CellularBase::CellularProperty pdp_type_t_to_cellular_property(pdp_type_t pdp_type);
106105
bool set_new_context(int cid);
107106
private:

features/cellular/framework/common/CellularUtil.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#define RANDOM_PORT_NUMBER_COUNT (RANDOM_PORT_NUMBER_END - RANDOM_PORT_NUMBER_START + 1)
2626
#define RANDOM_PORT_NUMBER_MAX_STEP 100
2727

28-
28+
using namespace mbed;
2929
namespace mbed_cellular_util {
3030

3131
void convert_ipv6(char *ip)
@@ -355,4 +355,21 @@ uint16_t get_dynamic_ip_port()
355355
return (RANDOM_PORT_NUMBER_START + port_counter);
356356
}
357357

358+
pdp_type_t string_to_pdp_type(const char *pdp_type_str)
359+
{
360+
pdp_type_t pdp_type = DEFAULT_PDP_TYPE;
361+
int len = strlen(pdp_type_str);
362+
363+
if (len == 6 && memcmp(pdp_type_str, "IPV4V6", len) == 0) {
364+
pdp_type = IPV4V6_PDP_TYPE;
365+
} else if (len == 4 && memcmp(pdp_type_str, "IPV6", len) == 0) {
366+
pdp_type = IPV6_PDP_TYPE;
367+
} else if (len == 2 && memcmp(pdp_type_str, "IP", len) == 0) {
368+
pdp_type = IPV4_PDP_TYPE;
369+
} else if (len == 6 && memcmp(pdp_type_str, "Non-IP", len) == 0) {
370+
pdp_type = NON_IP_PDP_TYPE;
371+
}
372+
return pdp_type;
373+
}
374+
358375
} // namespace mbed_cellular_util

features/cellular/framework/common/CellularUtil.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,18 @@
2020

2121
#include <stddef.h>
2222
#include <inttypes.h>
23-
23+
#include "nsapi_types.h"
24+
25+
namespace mbed {
26+
27+
typedef enum pdp_type {
28+
DEFAULT_PDP_TYPE = DEFAULT_STACK,
29+
IPV4_PDP_TYPE = IPV4_STACK,
30+
IPV6_PDP_TYPE = IPV6_STACK,
31+
IPV4V6_PDP_TYPE = IPV4V6_STACK,
32+
NON_IP_PDP_TYPE
33+
} pdp_type_t;
34+
}
2435
namespace mbed_cellular_util {
2536

2637
// some helper macros
@@ -120,6 +131,13 @@ uint32_t binary_str_to_uint(const char *binary_string, int binary_string_length)
120131
*/
121132
uint16_t get_dynamic_ip_port();
122133

134+
/** Converts the given pdp type in char format to enum pdp_type_t
135+
*
136+
* @param pdp_type pdp type in string format
137+
* @return converted pdp_type_t enum
138+
*/
139+
mbed::pdp_type_t string_to_pdp_type(const char *pdp_type);
140+
123141
} // namespace mbed_cellular_util
124142

125143
#endif

features/cellular/framework/targets/TELIT/ME910/TELIT_ME910_CellularContext.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include "Semaphore.h"
2121

22+
using namespace mbed_cellular_util;
23+
2224
namespace mbed {
2325

2426
TELIT_ME910_CellularContext::TELIT_ME910_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) :

0 commit comments

Comments
 (0)