Skip to content

Commit 9e72fa2

Browse files
Hasnain VirkAri Parkkila
authored andcommitted
Updating Ublox to accomodate socket id assignment
Changes to accomodate socket id assigment upon actual creation of the socket at the modem.
1 parent 2e53a71 commit 9e72fa2

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularStack.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ bool UBLOX_AT_CellularStack::is_protocol_supported(nsapi_protocol_t protocol)
118118

119119
nsapi_error_t UBLOX_AT_CellularStack::create_socket_impl(CellularSocket *socket)
120120
{
121-
int sock_id = 0;
121+
int sock_id = SOCKET_UNUSED;
122122

123123
_at.lock();
124124
if (socket->proto == NSAPI_UDP) {
@@ -146,13 +146,12 @@ nsapi_error_t UBLOX_AT_CellularStack::create_socket_impl(CellularSocket *socket)
146146
// Check for duplicate socket id delivered by modem
147147
for (int i = 0; i < UBLOX_MAX_SOCKET; i++) {
148148
CellularSocket *sock = _socket[i];
149-
if (sock && sock->created && sock->id == sock_id) {
149+
if (sock && sock != socket && sock->id == sock_id) {
150150
return NSAPI_ERROR_NO_SOCKET;
151151
}
152152
}
153153

154154
socket->id = sock_id;
155-
socket->created = true;
156155

157156
return NSAPI_ERROR_OK;
158157
}
@@ -162,7 +161,7 @@ nsapi_error_t UBLOX_AT_CellularStack::socket_connect(nsapi_socket_t handle, cons
162161
CellularSocket *socket = (CellularSocket *)handle;
163162

164163
if (socket) {
165-
if (!socket->created) {
164+
if (socket->id != SOCKET_UNUSED) {
166165
nsapi_error_t err = create_socket_impl(socket);
167166
if (err != NSAPI_ERROR_OK) {
168167
return err;
@@ -192,6 +191,8 @@ nsapi_error_t UBLOX_AT_CellularStack::socket_connect(nsapi_socket_t handle, cons
192191
nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_sendto_impl(CellularSocket *socket, const SocketAddress &address,
193192
const void *data, nsapi_size_t size)
194193
{
194+
MBED_ASSERT(socket->id != -1);
195+
195196
int sent_len = 0;
196197
pollfh fhs;
197198
fhs.fh = _at.get_file_handle();
@@ -261,6 +262,8 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_sendto_impl(CellularSocket
261262
nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address,
262263
void *buffer, nsapi_size_t size)
263264
{
265+
MBED_ASSERT(socket->id != -1);
266+
264267
nsapi_size_or_error_t nsapi_error_size = NSAPI_ERROR_DEVICE_ERROR;
265268
bool success = true;
266269
nsapi_size_t read_blk;
@@ -430,7 +433,6 @@ void UBLOX_AT_CellularStack::clear_socket(CellularSocket *socket)
430433
socket->pending_bytes = 0;
431434
socket->_cb = NULL;
432435
socket->_data = NULL;
433-
socket->created = false;
434436
}
435437
}
436438

features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularStack.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ bool UBLOX_N2XX_CellularStack::is_protocol_supported(nsapi_protocol_t protocol)
7575

7676
nsapi_error_t UBLOX_N2XX_CellularStack::create_socket_impl(CellularSocket *socket)
7777
{
78-
int sock_id = 0;
78+
int sock_id = -1;
7979
int localport = socket->localAddress.get_port();
8080

8181
if (localport == 5683 || localport < 0 || localport > 65535) {
@@ -101,20 +101,21 @@ nsapi_error_t UBLOX_N2XX_CellularStack::create_socket_impl(CellularSocket *socke
101101
// Check for duplicate socket id delivered by modem
102102
for (int i = 0; i < N2XX_MAX_SOCKET; i++) {
103103
CellularSocket *sock = _socket[i];
104-
if (sock && sock->created && sock->id == sock_id) {
104+
if (sock && sock != socket && sock->id == sock_id) {
105105
return NSAPI_ERROR_NO_SOCKET;
106106
}
107107
}
108108

109109
socket->id = sock_id;
110-
socket->created = true;
111110

112111
return NSAPI_ERROR_OK;
113112
}
114113

115114
nsapi_size_or_error_t UBLOX_N2XX_CellularStack::socket_sendto_impl(CellularSocket *socket, const SocketAddress &address,
116115
const void *data, nsapi_size_t size)
117116
{
117+
MBED_ASSERT(socket->id != -1);
118+
118119
if (size > N2XX_MAX_PACKET_SIZE) {
119120
return NSAPI_ERROR_PARAMETER;
120121
}
@@ -150,6 +151,8 @@ nsapi_size_or_error_t UBLOX_N2XX_CellularStack::socket_sendto_impl(CellularSocke
150151
nsapi_size_or_error_t UBLOX_N2XX_CellularStack::socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address,
151152
void *buffer, nsapi_size_t size)
152153
{
154+
MBED_ASSERT(socket->id != -1);
155+
153156
nsapi_size_or_error_t nsapi_error_size = NSAPI_ERROR_DEVICE_ERROR;
154157
nsapi_size_t read_blk, usorf_sz, count = 0, length = size;
155158
bool success = true;

0 commit comments

Comments
 (0)