Skip to content

Commit ceea992

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

33 files changed

+64
-70
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
@@ -81,10 +81,6 @@ class my_stack : public AT_CellularStack {
8181
{
8282
return 200;
8383
}
84-
virtual bool is_protocol_supported(nsapi_protocol_t protocol)
85-
{
86-
return true;
87-
}
8884
virtual nsapi_error_t socket_close_impl(int sock_id)
8985
{
9086
return NSAPI_ERROR_OK;

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ class MyStack : public AT_CellularStack {
4444
create_error = NSAPI_ERROR_OK;
4545
}
4646

47-
virtual bool is_protocol_supported(nsapi_protocol_t protocol)
48-
{
49-
return bool_value;
50-
}
51-
5247
virtual nsapi_error_t socket_close_impl(int sock_id)
5348
{
5449
return NSAPI_ERROR_OK;
@@ -201,10 +196,10 @@ TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_open)
201196
ATHandler at(&fh1, que, 0, ",");
202197

203198
MyStack st(at, 0, IPV6_STACK, *_dev);
204-
st.bool_value = false;
199+
AT_CellularDevice_stub::supported_bool = 0;
205200
EXPECT_EQ(st.socket_open(NULL, NSAPI_TCP), NSAPI_ERROR_UNSUPPORTED);
206201

207-
st.bool_value = true;
202+
AT_CellularDevice_stub::supported_bool = 1;
208203
AT_CellularDevice_stub::max_sock_value = 0;
209204
nsapi_socket_t sock = &st.socket;
210205
EXPECT_EQ(st.socket_open(&sock, NSAPI_TCP), NSAPI_ERROR_NO_SOCKET);

features/cellular/framework/AT/AT_CellularDevice.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class AT_CellularDevice : public CellularDevice {
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= ?
6161
PROPERTY_SOCKET_COUNT, // The number of sockets of modem IP stack
62+
PROPERTY_IP_TCP, // 0 = not supported, 1 = supported. Modem IP stack has support for TCP
63+
PROPERTY_IP_UDP, // 0 = not supported, 1 = supported. Modem IP stack has support for TCP
6264
PROPERTY_MAX
6365
};
6466

features/cellular/framework/AT/AT_CellularStack.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,28 @@ nsapi_error_t AT_CellularStack::socket_stack_init()
157157

158158
nsapi_error_t AT_CellularStack::socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto)
159159
{
160-
if (!is_protocol_supported(proto) || !handle) {
160+
if (!handle) {
161+
return NSAPI_ERROR_UNSUPPORTED;
162+
}
163+
164+
if (proto == NSAPI_UDP) {
165+
if (!_device.get_property(AT_CellularDevice::PROPERTY_IP_UDP)) {
166+
return NSAPI_ERROR_UNSUPPORTED;
167+
}
168+
} else if (proto == NSAPI_TCP) {
169+
if (!_device.get_property(AT_CellularDevice::PROPERTY_IP_TCP)) {
170+
return NSAPI_ERROR_UNSUPPORTED;
171+
}
172+
} else {
161173
return NSAPI_ERROR_UNSUPPORTED;
162174
}
163175

164176
_socket_mutex.lock();
165177

166178
if (!_socket) {
179+
if (_device.get_property(AT_CellularDevice::PROPERTY_SOCKET_COUNT) == 0) {
180+
return NSAPI_ERROR_NO_SOCKET;
181+
}
167182
if (socket_stack_init() != NSAPI_ERROR_OK) {
168183
_socket_mutex.unlock();
169184
return NSAPI_ERROR_NO_SOCKET;

features/cellular/framework/AT/AT_CellularStack.h

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

138-
/**
139-
* Checks if modem supports the given protocol
140-
*
141-
* @param protocol Protocol type
142-
*/
143-
virtual bool is_protocol_supported(nsapi_protocol_t protocol) = 0;
144-
145138
/**
146139
* Implements modem specific AT command set for socket closing
147140
*

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ void GEMALTO_CINTERION::init_module_bgs2()
114114
1, // PROPERTY_AT_CGEREP
115115
1, // PROPERTY_AT_COPS_FALLBACK_AUTO
116116
10, // PROPERTY_SOCKET_COUNT
117+
1, // PROPERTY_IP_TCP
118+
1, // PROPERTY_IP_UDP
117119
};
118120
set_cellular_properties(cellular_properties);
119121
_module = ModuleBGS2;
@@ -140,6 +142,8 @@ void GEMALTO_CINTERION::init_module_els61()
140142
1, // PROPERTY_AT_CGEREP
141143
1, // PROPERTY_AT_COPS_FALLBACK_AUTO
142144
10, // PROPERTY_SOCKET_COUNT
145+
1, // PROPERTY_IP_TCP
146+
1, // PROPERTY_IP_UDP
143147
};
144148
set_cellular_properties(cellular_properties);
145149
_module = ModuleELS61;
@@ -166,6 +170,8 @@ void GEMALTO_CINTERION::init_module_ems31()
166170
1, // PROPERTY_AT_CGEREP
167171
1, // PROPERTY_AT_COPS_FALLBACK_AUTO
168172
10, // PROPERTY_SOCKET_COUNT
173+
1, // PROPERTY_IP_TCP
174+
1, // PROPERTY_IP_UDP
169175
};
170176
set_cellular_properties(cellular_properties);
171177
_module = ModuleEMS31;
@@ -192,6 +198,8 @@ void GEMALTO_CINTERION::init_module_ehs5e()
192198
1, // PROPERTY_AT_CGEREP
193199
1, // PROPERTY_AT_COPS_FALLBACK_AUTO
194200
10, // PROPERTY_SOCKET_COUNT
201+
1, // PROPERTY_IP_TCP
202+
1, // PROPERTY_IP_UDP
195203
};
196204
set_cellular_properties(cellular_properties);
197205
_module = ModuleEHS5E;

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,6 @@ nsapi_error_t GEMALTO_CINTERION_CellularStack::socket_stack_init()
132132
return err;
133133
}
134134

135-
bool GEMALTO_CINTERION_CellularStack::is_protocol_supported(nsapi_protocol_t protocol)
136-
{
137-
return (protocol == NSAPI_UDP || protocol == NSAPI_TCP);
138-
}
139-
140135
nsapi_error_t GEMALTO_CINTERION_CellularStack::socket_close_impl(int sock_id)
141136
{
142137
tr_debug("Cinterion close %d", sock_id);

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 bool is_protocol_supported(nsapi_protocol_t protocol);
36-
3735
virtual nsapi_error_t socket_close_impl(int sock_id);
3836

3937
virtual nsapi_error_t create_socket_impl(CellularSocket *socket);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
3939
1, // PROPERTY_AT_CGEREP
4040
1, // PROPERTY_AT_COPS_FALLBACK_AUTO
4141
0, // PROPERTY_SOCKET_COUNT
42+
0, // PROPERTY_IP_TCP
43+
0, // PROPERTY_IP_UDP
4244
};
4345

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

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
3939
1, // PROPERTY_AT_CGEREP
4040
1, // PROPERTY_AT_COPS_FALLBACK_AUTO
4141
0, // PROPERTY_SOCKET_COUNT
42+
0, // PROPERTY_IP_TCP
43+
0, // PROPERTY_IP_UDP
4244
};
4345

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

0 commit comments

Comments
 (0)