Skip to content

Commit e2cb180

Browse files
author
Ari Parkkila
committed
Cellular: Refactor get_max_socket_count() into CellularProperty
1 parent b96d3ad commit e2cb180

35 files changed

+61
-124
lines changed

UNITTESTS/features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,6 @@ class TestAT_CellularContext : public testing::Test {
7777
class my_stack : public AT_CellularStack {
7878
public:
7979
my_stack(ATHandler &atHandler, AT_CellularDevice &device) : AT_CellularStack(atHandler, 1, IPV4_STACK, device) {}
80-
virtual int get_max_socket_count()
81-
{
82-
return 1;
83-
}
8480
virtual int get_max_packet_size()
8581
{
8682
return 200;

UNITTESTS/features/cellular/framework/AT/at_cellularstack/at_cellularstacktest.cpp

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "ATHandler_stub.h"
2727
#include "SocketAddress.h"
2828
#include "CellularDevice_stub.h"
29+
#include "AT_CellularDevice_stub.h"
2930
#include "myCellularDevice.h"
3031

3132
using namespace mbed;
@@ -34,22 +35,15 @@ using namespace events;
3435
class MyStack : public AT_CellularStack {
3536
public:
3637
bool bool_value;
37-
bool max_sock_value;
3838
nsapi_error_t create_error;
3939
CellularSocket socket;
4040

4141
MyStack(ATHandler &atr, int cid, nsapi_ip_stack_t typ, AT_CellularDevice &device) : AT_CellularStack(atr, cid, typ, device)
4242
{
4343
bool_value = false;
44-
max_sock_value = 0;
4544
create_error = NSAPI_ERROR_OK;
4645
}
4746

48-
virtual int get_max_socket_count()
49-
{
50-
return max_sock_value;
51-
}
52-
5347
virtual bool is_protocol_supported(nsapi_protocol_t protocol)
5448
{
5549
return bool_value;
@@ -211,15 +205,17 @@ TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_open)
211205
EXPECT_EQ(st.socket_open(NULL, NSAPI_TCP), NSAPI_ERROR_UNSUPPORTED);
212206

213207
st.bool_value = true;
214-
st.max_sock_value = 0;
208+
AT_CellularDevice_stub::max_sock_value = 0;
215209
nsapi_socket_t sock = &st.socket;
216210
EXPECT_EQ(st.socket_open(&sock, NSAPI_TCP), NSAPI_ERROR_NO_SOCKET);
217211

218212
MyStack st2(at, 0, IPV6_STACK, *_dev);
219213
st2.bool_value = true;
220-
st2.max_sock_value = 1;
214+
AT_CellularDevice_stub::max_sock_value = 1;
221215
sock = &st2.socket;
222216
EXPECT_EQ(st2.socket_open(&sock, NSAPI_TCP), NSAPI_ERROR_OK);
217+
218+
AT_CellularDevice_stub::max_sock_value = 0;
223219
}
224220

225221
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_close)
@@ -233,13 +229,13 @@ TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_close)
233229

234230
nsapi_socket_t sock = &st.socket;
235231
st.bool_value = true;
236-
st.max_sock_value = 1;
232+
AT_CellularDevice_stub::max_sock_value = 1;
237233
EXPECT_EQ(st.socket_open(&sock, NSAPI_TCP), NSAPI_ERROR_OK);
238-
st.max_sock_value = 0;
234+
AT_CellularDevice_stub::max_sock_value = 0;
239235
EXPECT_EQ(st.socket_close(sock), NSAPI_ERROR_DEVICE_ERROR);
240236

241237
MyStack st2(at, 0, IPV6_STACK, *_dev);
242-
st2.max_sock_value = 1;
238+
AT_CellularDevice_stub::max_sock_value = 1;
243239
st2.bool_value = true;
244240
sock = &st2.socket;
245241
EXPECT_EQ(st2.socket_open(&sock, NSAPI_TCP), NSAPI_ERROR_OK);
@@ -306,7 +302,7 @@ TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_send)
306302
EXPECT_EQ(st.socket_send(&st.socket, "addr", 4), NSAPI_ERROR_NO_CONNECTION);
307303

308304
SocketAddress addr("fc00::", 123);
309-
st.max_sock_value = 1;
305+
AT_CellularDevice_stub::max_sock_value = 1;
310306
st.bool_value = true;
311307
nsapi_socket_t sock = &st.socket;
312308
st.socket_open(&sock, NSAPI_TCP);
@@ -325,7 +321,7 @@ TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_sendto)
325321
SocketAddress addr("fc00::", 123);
326322
EXPECT_EQ(st.socket_sendto(NULL, addr, "addr", 4), NSAPI_ERROR_NO_SOCKET);
327323

328-
st.max_sock_value = 1;
324+
AT_CellularDevice_stub::max_sock_value = 1;
329325
st.bool_value = true;
330326
nsapi_socket_t sock = &st.socket;
331327
st.socket_open(&sock, NSAPI_TCP);
@@ -359,7 +355,7 @@ TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_recvfrom)
359355
EXPECT_EQ(st.socket_recvfrom(NULL, NULL, table, 4), NSAPI_ERROR_NO_SOCKET);
360356

361357
SocketAddress addr;
362-
st.max_sock_value = 1;
358+
AT_CellularDevice_stub::max_sock_value = 1;
363359
st.bool_value = true;
364360
nsapi_socket_t sock = &st.socket;
365361
st.socket_open(&sock, NSAPI_TCP);
@@ -380,7 +376,7 @@ TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_attach)
380376
MyStack st(at, 0, IPV6_STACK, *_dev);
381377

382378
st.socket_attach(NULL, NULL, NULL);
383-
st.max_sock_value = 1;
379+
AT_CellularDevice_stub::max_sock_value = 1;
384380
st.bool_value = true;
385381
nsapi_socket_t sock = &st.socket;
386382
st.socket_open(&sock, NSAPI_TCP);

UNITTESTS/stubs/AT_CellularDevice_stub.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ int AT_CellularDevice_stub::set_pin_failure_count = 0;
3131
int AT_CellularDevice_stub::get_sim_failure_count = 0;
3232
bool AT_CellularDevice_stub::pin_needed = false;
3333
bool AT_CellularDevice_stub::supported_bool = false;
34+
int AT_CellularDevice_stub::max_sock_value = 0;
3435

3536
AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh),
3637
#if MBED_CONF_CELLULAR_USE_SMS
@@ -293,6 +294,8 @@ intptr_t AT_CellularDevice::get_property(CellularProperty key)
293294
return true;
294295
} else if (key == PROPERTY_IPV4_PDP_TYPE) {
295296
return true;
297+
} else if (key == PROPERTY_SOCKET_COUNT) {
298+
return AT_CellularDevice_stub::max_sock_value;
296299
}
297300

298301
return AT_CellularDevice_stub::supported_bool;

UNITTESTS/stubs/AT_CellularDevice_stub.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ extern int set_pin_failure_count;
2828
extern int get_sim_failure_count;
2929
extern bool pin_needed;
3030
extern bool supported_bool;
31+
extern int max_sock_value;
3132
}
3233

3334

features/cellular/framework/AT/AT_CellularDevice.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class AT_CellularDevice : public CellularDevice {
5858
PROPERTY_NON_IP_PDP_TYPE, // 0 = not supported, 1 = supported. Does modem support Non-IP?
5959
PROPERTY_AT_CGEREP, // 0 = not supported, 1 = supported. Does modem support AT command AT+CGEREP.
6060
PROPERTY_AT_COPS_FALLBACK_AUTO, // 0 = not supported, 1 = supported. Does modem support mode 4 of AT+COPS= ?
61-
61+
PROPERTY_SOCKET_COUNT, // The number of sockets of modem IP stack
6262
PROPERTY_MAX
6363
};
6464

features/cellular/framework/AT/AT_CellularStack.cpp

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,29 @@ using namespace mbed_cellular_util;
2525
using namespace mbed;
2626

2727
AT_CellularStack::AT_CellularStack(ATHandler &at, int cid, nsapi_ip_stack_t stack_type, AT_CellularDevice &device) :
28-
_socket(NULL), _socket_count(0), _cid(cid),
28+
_socket(NULL), _cid(cid),
2929
_stack_type(stack_type), _ip_ver_sendto(NSAPI_UNSPEC), _at(at), _device(device)
3030
{
3131
memset(_ip, 0, PDP_IPV6_SIZE);
3232
}
3333

3434
AT_CellularStack::~AT_CellularStack()
3535
{
36-
for (int i = 0; i < _socket_count; i++) {
37-
if (_socket[i]) {
38-
delete _socket[i];
39-
_socket[i] = NULL;
36+
if (_socket) {
37+
for (int i = 0; i < _device.get_property(AT_CellularDevice::PROPERTY_SOCKET_COUNT); i++) {
38+
if (_socket[i]) {
39+
delete _socket[i];
40+
_socket[i] = NULL;
41+
}
4042
}
43+
delete [] _socket;
44+
_socket = NULL;
4145
}
42-
_socket_count = 0;
43-
44-
delete [] _socket;
45-
_socket = NULL;
4646
}
4747

4848
int AT_CellularStack::find_socket_index(nsapi_socket_t handle)
4949
{
50-
int max_socket_count = get_max_socket_count();
51-
for (int i = 0; i < max_socket_count; i++) {
50+
for (int i = 0; i < _device.get_property(AT_CellularDevice::PROPERTY_SOCKET_COUNT); i++) {
5251
if (_socket[i] == handle) {
5352
return i;
5453
}
@@ -162,8 +161,6 @@ nsapi_error_t AT_CellularStack::socket_open(nsapi_socket_t *handle, nsapi_protoc
162161
return NSAPI_ERROR_UNSUPPORTED;
163162
}
164163

165-
int max_socket_count = get_max_socket_count();
166-
167164
_socket_mutex.lock();
168165

169166
if (!_socket) {
@@ -172,9 +169,8 @@ nsapi_error_t AT_CellularStack::socket_open(nsapi_socket_t *handle, nsapi_protoc
172169
return NSAPI_ERROR_NO_SOCKET;
173170
}
174171

175-
_socket = new CellularSocket*[max_socket_count];
176-
_socket_count = max_socket_count;
177-
for (int i = 0; i < max_socket_count; i++) {
172+
_socket = new CellularSocket*[_device.get_property(AT_CellularDevice::PROPERTY_SOCKET_COUNT)];
173+
for (int i = 0; i < _device.get_property(AT_CellularDevice::PROPERTY_SOCKET_COUNT); i++) {
178174
_socket[i] = 0;
179175
}
180176
}
@@ -435,8 +431,7 @@ void AT_CellularStack::socket_attach(nsapi_socket_t handle, void (*callback)(voi
435431

436432
int AT_CellularStack::get_socket_index_by_port(uint16_t port)
437433
{
438-
int max_socket_count = get_max_socket_count();
439-
for (int i = 0; i < max_socket_count; i++) {
434+
for (int i = 0; i < _device.get_property(AT_CellularDevice::PROPERTY_SOCKET_COUNT); i++) {
440435
if (_socket[i]->localAddress.get_port() == port) {
441436
return i;
442437
}
@@ -447,7 +442,7 @@ int AT_CellularStack::get_socket_index_by_port(uint16_t port)
447442
AT_CellularStack::CellularSocket *AT_CellularStack::find_socket(int sock_id)
448443
{
449444
CellularSocket *sock = NULL;
450-
for (int i = 0; i < _socket_count; i++) {
445+
for (int i = 0; i < _device.get_property(AT_CellularDevice::PROPERTY_SOCKET_COUNT); i++) {
451446
if (_socket[i] && _socket[i]->id == sock_id) {
452447
sock = _socket[i];
453448
break;

features/cellular/framework/AT/AT_CellularStack.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,6 @@ class AT_CellularStack : public NetworkStack {
135135
bool txfull_event; // socket event after wouldblock
136136
};
137137

138-
/**
139-
* Gets maximum number of sockets modem supports
140-
*/
141-
virtual int get_max_socket_count() = 0;
142-
143138
/**
144139
* Checks if modem supports the given protocol
145140
*
@@ -218,9 +213,6 @@ class AT_CellularStack : public NetworkStack {
218213
// socket container
219214
CellularSocket **_socket;
220215

221-
// number of socket slots allocated in socket container
222-
int _socket_count;
223-
224216
// IP address
225217
char _ip[PDP_IPV6_SIZE];
226218

features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ void GEMALTO_CINTERION::init_module_bgs2()
113113
0, // PROPERTY_NON_IP_PDP_TYPE
114114
1, // PROPERTY_AT_CGEREP
115115
1, // PROPERTY_AT_COPS_FALLBACK_AUTO
116+
10, // PROPERTY_SOCKET_COUNT
116117
};
117118
set_cellular_properties(cellular_properties);
118119
_module = ModuleBGS2;
@@ -138,6 +139,7 @@ void GEMALTO_CINTERION::init_module_els61()
138139
0, // PROPERTY_NON_IP_PDP_TYPE
139140
1, // PROPERTY_AT_CGEREP
140141
1, // PROPERTY_AT_COPS_FALLBACK_AUTO
142+
10, // PROPERTY_SOCKET_COUNT
141143
};
142144
set_cellular_properties(cellular_properties);
143145
_module = ModuleELS61;
@@ -163,6 +165,7 @@ void GEMALTO_CINTERION::init_module_ems31()
163165
0, // PROPERTY_NON_IP_PDP_TYPE
164166
1, // PROPERTY_AT_CGEREP
165167
1, // PROPERTY_AT_COPS_FALLBACK_AUTO
168+
10, // PROPERTY_SOCKET_COUNT
166169
};
167170
set_cellular_properties(cellular_properties);
168171
_module = ModuleEMS31;
@@ -188,6 +191,7 @@ void GEMALTO_CINTERION::init_module_ehs5e()
188191
0, // PROPERTY_NON_IP_PDP_TYPE
189192
1, // PROPERTY_AT_CGEREP
190193
1, // PROPERTY_AT_COPS_FALLBACK_AUTO
194+
10, // PROPERTY_SOCKET_COUNT
191195
};
192196
set_cellular_properties(cellular_properties);
193197
_module = ModuleEHS5E;

features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularStack.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "CellularLog.h"
2222

2323
// defines as per ELS61-E2_ATC_V01.000 and BGS2-W_ATC_V00.100
24-
#define SOCKET_MAX 10
2524
#define UDP_PACKET_SIZE 1460
2625
#define FAILURE_TIMEOUT (30*1000) // failure timeout in milliseconds on modem side
2726

@@ -122,7 +121,7 @@ nsapi_error_t GEMALTO_CINTERION_CellularStack::socket_stack_init()
122121
_at.set_urc_handler("^SISR:", mbed::Callback<void()>(this, &GEMALTO_CINTERION_CellularStack::urc_sisr));
123122
} else { // recovery cleanup
124123
// close all Internet and connection profiles
125-
for (int i = 0; i < SOCKET_MAX; i++) {
124+
for (int i = 0; i < _device.get_property(AT_CellularDevice::PROPERTY_SOCKET_COUNT); i++) {
126125
_at.clear_error();
127126
socket_close_impl(i);
128127
}
@@ -133,11 +132,6 @@ nsapi_error_t GEMALTO_CINTERION_CellularStack::socket_stack_init()
133132
return err;
134133
}
135134

136-
int GEMALTO_CINTERION_CellularStack::get_max_socket_count()
137-
{
138-
return SOCKET_MAX;
139-
}
140-
141135
bool GEMALTO_CINTERION_CellularStack::is_protocol_supported(nsapi_protocol_t protocol)
142136
{
143137
return (protocol == NSAPI_UDP || protocol == NSAPI_TCP);

features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularStack.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ class GEMALTO_CINTERION_CellularStack : public AT_CellularStack {
3232

3333
virtual nsapi_error_t socket_stack_init();
3434

35-
virtual int get_max_socket_count();
36-
3735
virtual bool is_protocol_supported(nsapi_protocol_t protocol);
3836

3937
virtual nsapi_error_t socket_close_impl(int sock_id);

features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
3838
0, // PROPERTY_NON_IP_PDP_TYPE
3939
1, // PROPERTY_AT_CGEREP
4040
1, // PROPERTY_AT_COPS_FALLBACK_AUTO
41+
0, // PROPERTY_SOCKET_COUNT
4142
};
4243

4344
GENERIC_AT3GPP::GENERIC_AT3GPP(FileHandle *fh) : AT_CellularDevice(fh)

features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
3838
0, // PROPERTY_NON_IP_PDP_TYPE
3939
1, // PROPERTY_AT_CGEREP
4040
1, // PROPERTY_AT_COPS_FALLBACK_AUTO
41+
0, // PROPERTY_SOCKET_COUNT
4142
};
4243

4344
SARA4_PPP::SARA4_PPP(FileHandle *fh) : AT_CellularDevice(fh)

features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
4545
1, // PROPERTY_NON_IP_PDP_TYPE
4646
0, // PROPERTY_AT_CGEREP,
4747
0, // PROPERTY_AT_COPS_FALLBACK_AUTO
48+
7, // PROPERTY_SOCKET_COUNT
4849
};
4950

5051
QUECTEL_BC95::QUECTEL_BC95(FileHandle *fh) : AT_CellularDevice(fh)

features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularStack.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void QUECTEL_BC95_CellularStack::urc_nsonmi()
9595
{
9696
int sock_id = _at.read_int();
9797

98-
for (int i = 0; i < get_max_socket_count(); i++) {
98+
for (int i = 0; i < _device.get_property(AT_CellularDevice::PROPERTY_SOCKET_COUNT); i++) {
9999
CellularSocket *sock = _socket[i];
100100
if (sock && sock->id == sock_id) {
101101
if (sock->_cb) {
@@ -128,11 +128,6 @@ void QUECTEL_BC95_CellularStack::urc_nsocli()
128128
}
129129

130130

131-
int QUECTEL_BC95_CellularStack::get_max_socket_count()
132-
{
133-
return BC95_SOCKET_MAX;
134-
}
135-
136131
bool QUECTEL_BC95_CellularStack::is_protocol_supported(nsapi_protocol_t protocol)
137132
{
138133
return (protocol == NSAPI_UDP || protocol == NSAPI_TCP);
@@ -308,7 +303,7 @@ void QUECTEL_BC95_CellularStack::txfull_event_timeout()
308303
{
309304
_socket_mutex.lock();
310305
_txfull_event_id = 0;
311-
for (int i = 0; i < get_max_socket_count(); i++) {
306+
for (int i = 0; i < _device.get_property(AT_CellularDevice::PROPERTY_SOCKET_COUNT); i++) {
312307
CellularSocket *sock = _socket[i];
313308
if (sock && sock->_cb && sock->txfull_event) {
314309
sock->txfull_event = false;

features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularStack.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
#include "AT_CellularStack.h"
2222

23-
#define BC95_SOCKET_MAX 7
24-
2523
namespace mbed {
2624

2725
class QUECTEL_BC95_CellularStack : public AT_CellularStack {
@@ -40,8 +38,6 @@ class QUECTEL_BC95_CellularStack : public AT_CellularStack {
4038

4139
protected: // AT_CellularStack
4240

43-
virtual int get_max_socket_count();
44-
4541
virtual bool is_protocol_supported(nsapi_protocol_t protocol);
4642

4743
virtual nsapi_error_t socket_close_impl(int sock_id);

0 commit comments

Comments
 (0)