Skip to content

Commit 174d957

Browse files
author
Teppo Järvelin
committed
Cellular: don't allow ATHandler read/write if filehandle not usable
For example after going to ppp mode we must block at write and read as filehandle is not usable.
1 parent 6b84b14 commit 174d957

File tree

1 file changed

+70
-4
lines changed

1 file changed

+70
-4
lines changed

features/cellular/framework/AT/ATHandler.cpp

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,11 @@ void ATHandler::skip_param(uint32_t count)
408408
return;
409409
}
410410

411+
if (!_is_fh_usable) {
412+
_last_err = NSAPI_ERROR_BUSY;
413+
return;
414+
}
415+
411416
for (uint32_t i = 0; (i < count && !_stop_tag->found); i++) {
412417
size_t match_pos = 0;
413418
while (true) {
@@ -436,6 +441,10 @@ void ATHandler::skip_param(ssize_t len, uint32_t count)
436441
if (_last_err || !_stop_tag || _stop_tag->found) {
437442
return;
438443
}
444+
if (!_is_fh_usable) {
445+
_last_err = NSAPI_ERROR_BUSY;
446+
return;
447+
}
439448

440449
for (uint32_t i = 0; i < count; i++) {
441450
ssize_t read_len = 0;
@@ -456,6 +465,10 @@ ssize_t ATHandler::read_bytes(uint8_t *buf, size_t len)
456465
if (_last_err) {
457466
return -1;
458467
}
468+
if (!_is_fh_usable) {
469+
_last_err = NSAPI_ERROR_BUSY;
470+
return -1;
471+
}
459472

460473
bool debug_on = _debug_on;
461474
size_t read_len = 0;
@@ -481,6 +494,10 @@ ssize_t ATHandler::read_string(char *buf, size_t size, bool read_even_stop_tag)
481494
if (_last_err || !_stop_tag || (_stop_tag->found && read_even_stop_tag == false)) {
482495
return -1;
483496
}
497+
if (!_is_fh_usable) {
498+
_last_err = NSAPI_ERROR_BUSY;
499+
return -1;
500+
}
484501

485502
unsigned int len = 0;
486503
size_t match_pos = 0;
@@ -547,6 +564,10 @@ ssize_t ATHandler::read_hex_string(char *buf, size_t size)
547564
if (_last_err || !_stop_tag || _stop_tag->found) {
548565
return -1;
549566
}
567+
if (!_is_fh_usable) {
568+
_last_err = NSAPI_ERROR_BUSY;
569+
return -1;
570+
}
550571

551572
size_t match_pos = 0;
552573

@@ -620,6 +641,10 @@ int32_t ATHandler::read_int()
620641
if (_last_err || !_stop_tag || _stop_tag->found) {
621642
return -1;
622643
}
644+
if (!_is_fh_usable) {
645+
_last_err = NSAPI_ERROR_BUSY;
646+
return -1;
647+
}
623648

624649
char buff[BUFF_SIZE];
625650
if (read_string(buff, sizeof(buff)) == 0) {
@@ -879,6 +904,10 @@ void ATHandler::resp_start(const char *prefix, bool stop)
879904
if (_last_err) {
880905
return;
881906
}
907+
if (!_is_fh_usable) {
908+
_last_err = NSAPI_ERROR_BUSY;
909+
return;
910+
}
882911

883912
set_scope(NotSet);
884913
// Try get as much data as possible
@@ -905,6 +934,10 @@ bool ATHandler::info_resp()
905934
if (_last_err || _resp_stop.found) {
906935
return false;
907936
}
937+
if (!_is_fh_usable) {
938+
_last_err = NSAPI_ERROR_BUSY;
939+
return false;
940+
}
908941

909942
if (_prefix_matched) {
910943
_prefix_matched = false;
@@ -935,6 +968,10 @@ bool ATHandler::info_elem(char start_tag)
935968
if (_last_err) {
936969
return false;
937970
}
971+
if (!_is_fh_usable) {
972+
_last_err = NSAPI_ERROR_BUSY;
973+
return false;
974+
}
938975

939976
// If coming here after another info response element was started(looping), stop the previous one.
940977
// Trying to handle stopping in this level instead of doing it in upper level.
@@ -1005,6 +1042,11 @@ bool ATHandler::consume_to_stop_tag()
10051042
return true;
10061043
}
10071044

1045+
if (!_is_fh_usable) {
1046+
_last_err = NSAPI_ERROR_BUSY;
1047+
return true;
1048+
}
1049+
10081050
if (consume_to_tag((const char *)_stop_tag->tag, true)) {
10091051
return true;
10101052
}
@@ -1081,15 +1123,18 @@ const char *ATHandler::mem_str(const char *dest, size_t dest_len, const char *sr
10811123

10821124
void ATHandler::cmd_start(const char *cmd)
10831125
{
1126+
if (_last_err != NSAPI_ERROR_OK) {
1127+
return;
1128+
}
1129+
if (!_is_fh_usable) {
1130+
_last_err = NSAPI_ERROR_BUSY;
1131+
return;
1132+
}
10841133

10851134
if (_at_send_delay) {
10861135
rtos::ThisThread::sleep_until(_last_response_stop + _at_send_delay);
10871136
}
10881137

1089-
if (_last_err != NSAPI_ERROR_OK) {
1090-
return;
1091-
}
1092-
10931138
(void)write(cmd, strlen(cmd));
10941139

10951140
_cmd_start = true;
@@ -1136,6 +1181,10 @@ void ATHandler::cmd_stop()
11361181
if (_last_err != NSAPI_ERROR_OK) {
11371182
return;
11381183
}
1184+
if (!_is_fh_usable) {
1185+
_last_err = NSAPI_ERROR_BUSY;
1186+
return;
1187+
}
11391188
// Finish with CR
11401189
(void)write(_output_delimiter, strlen(_output_delimiter));
11411190
}
@@ -1152,6 +1201,10 @@ size_t ATHandler::write_bytes(const uint8_t *data, size_t len)
11521201
if (_last_err != NSAPI_ERROR_OK) {
11531202
return 0;
11541203
}
1204+
if (!_is_fh_usable) {
1205+
_last_err = NSAPI_ERROR_BUSY;
1206+
return 0;
1207+
}
11551208

11561209
return write(data, len);
11571210
}
@@ -1198,6 +1251,11 @@ bool ATHandler::check_cmd_send()
11981251
return false;
11991252
}
12001253

1254+
if (!_is_fh_usable) {
1255+
_last_err = NSAPI_ERROR_BUSY;
1256+
return false;
1257+
}
1258+
12011259
// Don't write delimiter if flag was set so
12021260
if (!_use_delimiter) {
12031261
return true;
@@ -1218,6 +1276,10 @@ bool ATHandler::check_cmd_send()
12181276

12191277
void ATHandler::flush()
12201278
{
1279+
if (!_is_fh_usable) {
1280+
_last_err = NSAPI_ERROR_BUSY;
1281+
return;
1282+
}
12211283
tr_debug("AT flush");
12221284
reset_buffer();
12231285
while (fill_buffer(false)) {
@@ -1255,6 +1317,10 @@ void ATHandler::debug_print(const char *p, int len)
12551317

12561318
bool ATHandler::sync(int timeout_ms)
12571319
{
1320+
if (!_is_fh_usable) {
1321+
_last_err = NSAPI_ERROR_BUSY;
1322+
return false;
1323+
}
12581324
tr_debug("AT sync");
12591325
lock();
12601326
uint32_t timeout = _at_timeout;

0 commit comments

Comments
 (0)