Skip to content

Commit 0308cb8

Browse files
Hasnain VirkAri Parkkila
authored andcommitted
Updating Gemalto Cinterion to accomodate socked id assignment
Changes introduced to accomodate the socket id assignment upon actual creation of the socket at the modem.
1 parent 04242c7 commit 0308cb8

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ nsapi_error_t GEMALTO_CINTERION_CellularStack::socket_open_defer(CellularSocket
167167
int retry_open = 1;
168168
retry_open:
169169
// setup internet session profile
170-
int internet_service_id = socket->id;
170+
int internet_service_id = find_socket_index(socket);
171171
bool foundSrvType = false;
172172
bool foundConIdType = false;
173173
_at.cmd_start("AT^SISS?");
@@ -244,26 +244,26 @@ nsapi_error_t GEMALTO_CINTERION_CellularStack::socket_open_defer(CellularSocket
244244
}
245245

246246
_at.cmd_start("AT^SISS=");
247-
_at.write_int(socket->id);
247+
_at.write_int(internet_service_id);
248248
_at.write_string("address", false);
249249
_at.write_string(sock_addr);
250250
_at.cmd_stop_read_resp();
251251

252252
_at.cmd_start("AT^SISO=");
253-
_at.write_int(socket->id);
253+
_at.write_int(internet_service_id);
254254
_at.cmd_stop_read_resp();
255255

256256
if (_at.get_last_error()) {
257257
tr_error("Socket %d open failed!", socket->id);
258258
_at.clear_error();
259-
socket_close_impl(socket->id); // socket may already be open on modem if app and modem are not in sync, as a recovery, try to close the socket so open succeeds the next time
259+
socket_close_impl(internet_service_id); // socket may already be open on modem if app and modem are not in sync, as a recovery, try to close the socket so open succeeds the next time
260260
if (retry_open--) {
261261
goto retry_open;
262262
}
263263
return NSAPI_ERROR_NO_SOCKET;
264264
}
265265

266-
socket->created = true;
266+
socket->id = internet_service_id;
267267
tr_debug("Cinterion open %d (err %d)", socket->id, _at.get_last_error());
268268

269269
return _at.get_last_error();
@@ -316,11 +316,11 @@ nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_sendto_impl(Cellul
316316
socket->remoteAddress = address;
317317
_at.resp_start("^SISW:");
318318
int sock_id = _at.read_int();
319+
MBED_ASSERT(sock_id == socket->id);
319320
int urc_code = _at.read_int();
320321
tr_debug("TX ready: socket=%d, urc=%d (err=%d)", sock_id, urc_code, _at.get_last_error());
321322
(void)sock_id;
322323
(void)urc_code;
323-
socket->created = true;
324324
socket->started = true;
325325
socket->tx_ready = true;
326326
}
@@ -399,6 +399,10 @@ nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_sendto_impl(Cellul
399399
nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address,
400400
void *buffer, nsapi_size_t size)
401401
{
402+
// AT_CellularStack::recvfrom(...) will make sure that we do have a socket
403+
// open on the modem, assert here to catch a programming error
404+
MBED_ASSERT(socket->id != -1);
405+
402406
// we must use this flag, otherwise ^SISR URC can come while we are reading response and there is
403407
// no way to detect if that is really an URC or response
404408
if (!socket->rx_avail) {

0 commit comments

Comments
 (0)