Skip to content

Commit b37532a

Browse files
author
Ari Parkkila
committed
Cellular: Fix to prefer IPv6 single stack with fallback to IPv4
1 parent 6634e46 commit b37532a

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

features/cellular/framework/AT/AT_CellularNetwork.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ bool AT_CellularNetwork::set_new_context(int cid)
459459
strncpy(pdp_type, "IPV6", sizeof(pdp_type));
460460
break;
461461
case IPV4V6_STACK:
462-
strncpy(pdp_type, "IPV4V6", sizeof(pdp_type));
462+
strncpy(pdp_type, "IPV6", sizeof(pdp_type)); // try first IPV6 and then fall-back to IPv4
463463
break;
464464
default:
465465
break;

features/cellular/framework/AT/AT_CellularStack.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ const char * AT_CellularStack::get_ip_address()
8181
return _ip;
8282
}
8383

84+
nsapi_error_t AT_CellularStack::socket_stack_init()
85+
{
86+
return NSAPI_ERROR_OK;
87+
}
88+
8489
nsapi_error_t AT_CellularStack::socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto)
8590
{
8691
if (!is_protocol_supported(proto) || !handle) {
@@ -90,6 +95,10 @@ nsapi_error_t AT_CellularStack::socket_open(nsapi_socket_t *handle, nsapi_protoc
9095
int max_socket_count = get_max_socket_count();
9196

9297
if (!_socket) {
98+
if (socket_stack_init() != NSAPI_ERROR_OK) {
99+
return NSAPI_ERROR_NO_SOCKET;
100+
}
101+
93102
_socket = new CellularSocket*[max_socket_count];
94103
if (!_socket) {
95104
tr_error("No memory to open socket!");

features/cellular/framework/AT/AT_CellularStack.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ class AT_CellularStack : public NetworkStack, public AT_CellularBase
4646
virtual const char *get_ip_address();
4747
protected: // NetworkStack
4848

49+
/**
50+
* Modem specific socket stack initialization
51+
*
52+
* @return 0 on success
53+
*/
54+
virtual nsapi_error_t socket_stack_init();
55+
4956
virtual nsapi_error_t socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto);
5057

5158
virtual nsapi_error_t socket_close(nsapi_socket_t handle);
@@ -87,8 +94,10 @@ class AT_CellularStack : public NetworkStack, public AT_CellularBase
8794
SocketAddress localAddress;
8895
void (*_cb)(void *);
8996
void *_data;
90-
bool created;
91-
bool rx_avail; // used to synchronize reading from modem
97+
bool created; // socket has been created on modem stack
98+
bool started; // socket has been opened on modem stack
99+
bool tx_ready; // socket is ready for sending on modem stack
100+
bool rx_avail; // socket has data for reading on modem stack
92101
};
93102

94103
/**

0 commit comments

Comments
 (0)