@@ -524,20 +524,25 @@ nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_sendto_impl(Cellul
524
524
return (_at.get_last_error () == NSAPI_ERROR_OK) ? accept_len : NSAPI_ERROR_DEVICE_ERROR;
525
525
}
526
526
527
+ #define DISABLE_URCs _at.at_cmd_discard(" ^SCFG" , " =" , " %s%s" ," Tcp/WithURCs" ," off" )
528
+ #define RESTORE_URCs_AND_RETURN (ret ) do { _at.at_cmd_discard (" ^SCFG" , " =" , " %s%s" ," Tcp/WithURCs" ," on" ); return ret; } while (0 )
529
+
527
530
nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_recvfrom_impl (CellularSocket *socket, SocketAddress *address,
528
531
void *buffer, nsapi_size_t size)
529
532
{
530
533
// AT_CellularStack::recvfrom(...) will make sure that we do have a socket
531
534
// open on the modem, assert here to catch a programming error
532
535
MBED_ASSERT (socket->id != -1 );
533
536
537
+ DISABLE_URCs;
538
+
534
539
// we must use this flag, otherwise ^SISR URC can come while we are reading response and there is
535
540
// no way to detect if that is really an URC or response
536
541
if (!socket->pending_bytes ) {
537
542
_at.process_oob (); // check for ^SISR URC
538
543
if (!socket->pending_bytes ) {
539
544
tr_debug (" Socket %d recv would block" , socket->id );
540
- return NSAPI_ERROR_WOULD_BLOCK;
545
+ RESTORE_URCs_AND_RETURN ( NSAPI_ERROR_WOULD_BLOCK) ;
541
546
}
542
547
}
543
548
@@ -552,7 +557,7 @@ nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_recvfrom_impl(Cell
552
557
_at.resp_start (" ^SISR:" );
553
558
if (!_at.info_resp ()) {
554
559
tr_error (" Socket %d not responding" , socket->id );
555
- return NSAPI_ERROR_DEVICE_ERROR;
560
+ RESTORE_URCs_AND_RETURN ( NSAPI_ERROR_DEVICE_ERROR) ;
556
561
}
557
562
558
563
int socket_id = _at.read_int ();
@@ -564,24 +569,24 @@ nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_recvfrom_impl(Cell
564
569
goto sisr_retry;
565
570
}
566
571
tr_error (" Socket recvfrom id %d != %d" , socket_id, socket->id );
567
- return NSAPI_ERROR_DEVICE_ERROR;
572
+ RESTORE_URCs_AND_RETURN ( NSAPI_ERROR_DEVICE_ERROR) ;
568
573
}
569
574
570
575
nsapi_size_or_error_t len = _at.read_int ();
571
576
if (len == 0 ) {
572
577
tr_warn (" Socket %d no data" , socket->id );
573
578
_at.resp_stop ();
574
- return NSAPI_ERROR_WOULD_BLOCK;
579
+ RESTORE_URCs_AND_RETURN ( NSAPI_ERROR_WOULD_BLOCK) ;
575
580
}
576
581
if (len == -1 ) {
577
582
if (GEMALTO_CINTERION::get_module () == GEMALTO_CINTERION::ModuleTX62 && _at.get_last_read_error () == -2 ) {
578
583
_at.process_oob ();
579
584
tr_error (" Socket %d recvfrom finished!" , socket->id );
580
585
socket->pending_bytes = 0 ;
581
- return NSAPI_ERROR_OK;
586
+ RESTORE_URCs_AND_RETURN ( NSAPI_ERROR_OK) ;
582
587
}
583
588
tr_error (" Socket %d recvfrom failed!" , socket->id );
584
- return NSAPI_ERROR_DEVICE_ERROR;
589
+ RESTORE_URCs_AND_RETURN ( NSAPI_ERROR_DEVICE_ERROR) ;
585
590
}
586
591
if (len >= (nsapi_size_or_error_t )size) {
587
592
len = (nsapi_size_or_error_t )size;
@@ -606,7 +611,7 @@ nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_recvfrom_impl(Cell
606
611
int len = _at.read_bytes (at_buf + ip_len, 1 );
607
612
if (len <= 0 ) {
608
613
tr_error (" Socket %d recvfrom addr (len %d)" , socket->id , ip_len);
609
- return NSAPI_ERROR_DEVICE_ERROR;
614
+ RESTORE_URCs_AND_RETURN ( NSAPI_ERROR_DEVICE_ERROR) ;
610
615
}
611
616
ip_len += len;
612
617
} while (ip_len < ip_address_len && at_buf[ip_len - 2 ] != ' \r ' && at_buf[ip_len - 1 ] != ' \n ' );
@@ -629,7 +634,7 @@ nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_recvfrom_impl(Cell
629
634
int ip_len = _at.read_string (ip_address, sizeof (ip_address));
630
635
if (ip_len <= 0 ) {
631
636
tr_error (" Socket %d recvfrom addr (len %d)" , socket->id , ip_len);
632
- return NSAPI_ERROR_DEVICE_ERROR;
637
+ RESTORE_URCs_AND_RETURN ( NSAPI_ERROR_DEVICE_ERROR) ;
633
638
}
634
639
}
635
640
@@ -671,7 +676,7 @@ nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_recvfrom_impl(Cell
671
676
672
677
_at.resp_stop ();
673
678
674
- return ( _at.get_last_error () == NSAPI_ERROR_OK) ? (recv_len ? recv_len : NSAPI_ERROR_WOULD_BLOCK) : NSAPI_ERROR_DEVICE_ERROR;
679
+ RESTORE_URCs_AND_RETURN (( _at.get_last_error () == NSAPI_ERROR_OK) ? (recv_len ? recv_len : NSAPI_ERROR_WOULD_BLOCK) : NSAPI_ERROR_DEVICE_ERROR) ;
675
680
}
676
681
677
682
// setup internet connection profile for sockets
0 commit comments