Merge pull request from jarvte/athandler_filehandle_not_usable

Cellular: don't allow ATHandler read/write if filehandle not usable
pull/10178/head
Martin Kojtal 2019-03-20 15:39:12 +01:00 committed by GitHub
commit 839e977bee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 70 additions and 4 deletions
features/cellular/framework/AT

View File

@ -408,6 +408,11 @@ void ATHandler::skip_param(uint32_t count)
return;
}
if (!_is_fh_usable) {
_last_err = NSAPI_ERROR_BUSY;
return;
}
for (uint32_t i = 0; (i < count && !_stop_tag->found); i++) {
size_t match_pos = 0;
while (true) {
@ -436,6 +441,10 @@ void ATHandler::skip_param(ssize_t len, uint32_t count)
if (_last_err || !_stop_tag || _stop_tag->found) {
return;
}
if (!_is_fh_usable) {
_last_err = NSAPI_ERROR_BUSY;
return;
}
for (uint32_t i = 0; i < count; i++) {
ssize_t read_len = 0;
@ -456,6 +465,10 @@ ssize_t ATHandler::read_bytes(uint8_t *buf, size_t len)
if (_last_err) {
return -1;
}
if (!_is_fh_usable) {
_last_err = NSAPI_ERROR_BUSY;
return -1;
}
bool debug_on = _debug_on;
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)) {
return -1;
}
if (!_is_fh_usable) {
_last_err = NSAPI_ERROR_BUSY;
return -1;
}
unsigned int len = 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) {
return -1;
}
if (!_is_fh_usable) {
_last_err = NSAPI_ERROR_BUSY;
return -1;
}
size_t match_pos = 0;
@ -620,6 +641,10 @@ int32_t ATHandler::read_int()
if (_last_err || !_stop_tag || _stop_tag->found) {
return -1;
}
if (!_is_fh_usable) {
_last_err = NSAPI_ERROR_BUSY;
return -1;
}
char buff[BUFF_SIZE];
if (read_string(buff, sizeof(buff)) == 0) {
@ -879,6 +904,10 @@ void ATHandler::resp_start(const char *prefix, bool stop)
if (_last_err) {
return;
}
if (!_is_fh_usable) {
_last_err = NSAPI_ERROR_BUSY;
return;
}
set_scope(NotSet);
// Try get as much data as possible
@ -905,6 +934,10 @@ bool ATHandler::info_resp()
if (_last_err || _resp_stop.found) {
return false;
}
if (!_is_fh_usable) {
_last_err = NSAPI_ERROR_BUSY;
return false;
}
if (_prefix_matched) {
_prefix_matched = false;
@ -935,6 +968,10 @@ bool ATHandler::info_elem(char start_tag)
if (_last_err) {
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.
// 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;
}
if (!_is_fh_usable) {
_last_err = NSAPI_ERROR_BUSY;
return true;
}
if (consume_to_tag((const char *)_stop_tag->tag, 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)
{
if (_last_err != NSAPI_ERROR_OK) {
return;
}
if (!_is_fh_usable) {
_last_err = NSAPI_ERROR_BUSY;
return;
}
if (_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));
_cmd_start = true;
@ -1136,6 +1181,10 @@ void ATHandler::cmd_stop()
if (_last_err != NSAPI_ERROR_OK) {
return;
}
if (!_is_fh_usable) {
_last_err = NSAPI_ERROR_BUSY;
return;
}
// Finish with CR
(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) {
return 0;
}
if (!_is_fh_usable) {
_last_err = NSAPI_ERROR_BUSY;
return 0;
}
return write(data, len);
}
@ -1198,6 +1251,11 @@ bool ATHandler::check_cmd_send()
return false;
}
if (!_is_fh_usable) {
_last_err = NSAPI_ERROR_BUSY;
return false;
}
// Don't write delimiter if flag was set so
if (!_use_delimiter) {
return true;
@ -1218,6 +1276,10 @@ bool ATHandler::check_cmd_send()
void ATHandler::flush()
{
if (!_is_fh_usable) {
_last_err = NSAPI_ERROR_BUSY;
return;
}
tr_debug("AT flush");
reset_buffer();
while (fill_buffer(false)) {
@ -1255,6 +1317,10 @@ void ATHandler::debug_print(const char *p, int len)
bool ATHandler::sync(int timeout_ms)
{
if (!_is_fh_usable) {
_last_err = NSAPI_ERROR_BUSY;
return false;
}
tr_debug("AT sync");
lock();
uint32_t timeout = _at_timeout;