mirror of https://github.com/ARMmbed/mbed-os.git
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.pull/10138/head
parent
6b84b14ab6
commit
174d95709c
|
@ -408,6 +408,11 @@ void ATHandler::skip_param(uint32_t count)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!_is_fh_usable) {
|
||||||
|
_last_err = NSAPI_ERROR_BUSY;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (uint32_t i = 0; (i < count && !_stop_tag->found); i++) {
|
for (uint32_t i = 0; (i < count && !_stop_tag->found); i++) {
|
||||||
size_t match_pos = 0;
|
size_t match_pos = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -436,6 +441,10 @@ void ATHandler::skip_param(ssize_t len, uint32_t count)
|
||||||
if (_last_err || !_stop_tag || _stop_tag->found) {
|
if (_last_err || !_stop_tag || _stop_tag->found) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!_is_fh_usable) {
|
||||||
|
_last_err = NSAPI_ERROR_BUSY;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (uint32_t i = 0; i < count; i++) {
|
for (uint32_t i = 0; i < count; i++) {
|
||||||
ssize_t read_len = 0;
|
ssize_t read_len = 0;
|
||||||
|
@ -456,6 +465,10 @@ ssize_t ATHandler::read_bytes(uint8_t *buf, size_t len)
|
||||||
if (_last_err) {
|
if (_last_err) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (!_is_fh_usable) {
|
||||||
|
_last_err = NSAPI_ERROR_BUSY;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
bool debug_on = _debug_on;
|
bool debug_on = _debug_on;
|
||||||
size_t read_len = 0;
|
size_t read_len = 0;
|
||||||
|
@ -481,6 +494,10 @@ ssize_t ATHandler::read_string(char *buf, size_t size, bool read_even_stop_tag)
|
||||||
if (_last_err || !_stop_tag || (_stop_tag->found && read_even_stop_tag == false)) {
|
if (_last_err || !_stop_tag || (_stop_tag->found && read_even_stop_tag == false)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (!_is_fh_usable) {
|
||||||
|
_last_err = NSAPI_ERROR_BUSY;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int len = 0;
|
unsigned int len = 0;
|
||||||
size_t match_pos = 0;
|
size_t match_pos = 0;
|
||||||
|
@ -547,6 +564,10 @@ ssize_t ATHandler::read_hex_string(char *buf, size_t size)
|
||||||
if (_last_err || !_stop_tag || _stop_tag->found) {
|
if (_last_err || !_stop_tag || _stop_tag->found) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (!_is_fh_usable) {
|
||||||
|
_last_err = NSAPI_ERROR_BUSY;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
size_t match_pos = 0;
|
size_t match_pos = 0;
|
||||||
|
|
||||||
|
@ -620,6 +641,10 @@ int32_t ATHandler::read_int()
|
||||||
if (_last_err || !_stop_tag || _stop_tag->found) {
|
if (_last_err || !_stop_tag || _stop_tag->found) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (!_is_fh_usable) {
|
||||||
|
_last_err = NSAPI_ERROR_BUSY;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
char buff[BUFF_SIZE];
|
char buff[BUFF_SIZE];
|
||||||
if (read_string(buff, sizeof(buff)) == 0) {
|
if (read_string(buff, sizeof(buff)) == 0) {
|
||||||
|
@ -879,6 +904,10 @@ void ATHandler::resp_start(const char *prefix, bool stop)
|
||||||
if (_last_err) {
|
if (_last_err) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!_is_fh_usable) {
|
||||||
|
_last_err = NSAPI_ERROR_BUSY;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
set_scope(NotSet);
|
set_scope(NotSet);
|
||||||
// Try get as much data as possible
|
// Try get as much data as possible
|
||||||
|
@ -905,6 +934,10 @@ bool ATHandler::info_resp()
|
||||||
if (_last_err || _resp_stop.found) {
|
if (_last_err || _resp_stop.found) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (!_is_fh_usable) {
|
||||||
|
_last_err = NSAPI_ERROR_BUSY;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (_prefix_matched) {
|
if (_prefix_matched) {
|
||||||
_prefix_matched = false;
|
_prefix_matched = false;
|
||||||
|
@ -935,6 +968,10 @@ bool ATHandler::info_elem(char start_tag)
|
||||||
if (_last_err) {
|
if (_last_err) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (!_is_fh_usable) {
|
||||||
|
_last_err = NSAPI_ERROR_BUSY;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// If coming here after another info response element was started(looping), stop the previous one.
|
// If coming here after another info response element was started(looping), stop the previous one.
|
||||||
// Trying to handle stopping in this level instead of doing it in upper level.
|
// Trying to handle stopping in this level instead of doing it in upper level.
|
||||||
|
@ -1005,6 +1042,11 @@ bool ATHandler::consume_to_stop_tag()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!_is_fh_usable) {
|
||||||
|
_last_err = NSAPI_ERROR_BUSY;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (consume_to_tag((const char *)_stop_tag->tag, true)) {
|
if (consume_to_tag((const char *)_stop_tag->tag, true)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1081,15 +1123,18 @@ const char *ATHandler::mem_str(const char *dest, size_t dest_len, const char *sr
|
||||||
|
|
||||||
void ATHandler::cmd_start(const char *cmd)
|
void ATHandler::cmd_start(const char *cmd)
|
||||||
{
|
{
|
||||||
|
if (_last_err != NSAPI_ERROR_OK) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!_is_fh_usable) {
|
||||||
|
_last_err = NSAPI_ERROR_BUSY;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (_at_send_delay) {
|
if (_at_send_delay) {
|
||||||
rtos::ThisThread::sleep_until(_last_response_stop + _at_send_delay);
|
rtos::ThisThread::sleep_until(_last_response_stop + _at_send_delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_last_err != NSAPI_ERROR_OK) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
(void)write(cmd, strlen(cmd));
|
(void)write(cmd, strlen(cmd));
|
||||||
|
|
||||||
_cmd_start = true;
|
_cmd_start = true;
|
||||||
|
@ -1136,6 +1181,10 @@ void ATHandler::cmd_stop()
|
||||||
if (_last_err != NSAPI_ERROR_OK) {
|
if (_last_err != NSAPI_ERROR_OK) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!_is_fh_usable) {
|
||||||
|
_last_err = NSAPI_ERROR_BUSY;
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Finish with CR
|
// Finish with CR
|
||||||
(void)write(_output_delimiter, strlen(_output_delimiter));
|
(void)write(_output_delimiter, strlen(_output_delimiter));
|
||||||
}
|
}
|
||||||
|
@ -1152,6 +1201,10 @@ size_t ATHandler::write_bytes(const uint8_t *data, size_t len)
|
||||||
if (_last_err != NSAPI_ERROR_OK) {
|
if (_last_err != NSAPI_ERROR_OK) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
if (!_is_fh_usable) {
|
||||||
|
_last_err = NSAPI_ERROR_BUSY;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return write(data, len);
|
return write(data, len);
|
||||||
}
|
}
|
||||||
|
@ -1198,6 +1251,11 @@ bool ATHandler::check_cmd_send()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!_is_fh_usable) {
|
||||||
|
_last_err = NSAPI_ERROR_BUSY;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Don't write delimiter if flag was set so
|
// Don't write delimiter if flag was set so
|
||||||
if (!_use_delimiter) {
|
if (!_use_delimiter) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -1218,6 +1276,10 @@ bool ATHandler::check_cmd_send()
|
||||||
|
|
||||||
void ATHandler::flush()
|
void ATHandler::flush()
|
||||||
{
|
{
|
||||||
|
if (!_is_fh_usable) {
|
||||||
|
_last_err = NSAPI_ERROR_BUSY;
|
||||||
|
return;
|
||||||
|
}
|
||||||
tr_debug("AT flush");
|
tr_debug("AT flush");
|
||||||
reset_buffer();
|
reset_buffer();
|
||||||
while (fill_buffer(false)) {
|
while (fill_buffer(false)) {
|
||||||
|
@ -1255,6 +1317,10 @@ void ATHandler::debug_print(const char *p, int len)
|
||||||
|
|
||||||
bool ATHandler::sync(int timeout_ms)
|
bool ATHandler::sync(int timeout_ms)
|
||||||
{
|
{
|
||||||
|
if (!_is_fh_usable) {
|
||||||
|
_last_err = NSAPI_ERROR_BUSY;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
tr_debug("AT sync");
|
tr_debug("AT sync");
|
||||||
lock();
|
lock();
|
||||||
uint32_t timeout = _at_timeout;
|
uint32_t timeout = _at_timeout;
|
||||||
|
|
Loading…
Reference in New Issue