From d12de2a199be385332061eb6ddf880247b63b4af Mon Sep 17 00:00:00 2001 From: Mirela Chirica Date: Wed, 13 Mar 2019 14:18:33 +0200 Subject: [PATCH] Cellular: AT information response to return false on empty prefix --- .../cellular/framework/AT/athandler/athandlertest.cpp | 2 +- features/cellular/framework/AT/ATHandler.cpp | 6 +++--- features/cellular/framework/AT/ATHandler.h | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp b/UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp index 4f85540ddd..e9cc01154e 100644 --- a/UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp @@ -1085,7 +1085,7 @@ TEST_F(TestATHandler, test_ATHandler_info_resp) filehandle_stub_table = NULL; ATHandler at(&fh1, que, 0, ","); - EXPECT_TRUE(at.info_resp()); + EXPECT_TRUE(!at.info_resp()); at.resp_start(); EXPECT_TRUE(!at.info_resp()); diff --git a/features/cellular/framework/AT/ATHandler.cpp b/features/cellular/framework/AT/ATHandler.cpp index 7282eb19d3..1910ac9449 100644 --- a/features/cellular/framework/AT/ATHandler.cpp +++ b/features/cellular/framework/AT/ATHandler.cpp @@ -839,7 +839,7 @@ void ATHandler::resp(const char *prefix, bool check_urc) return; } - if (prefix && match(prefix, strlen(prefix))) { + if (prefix && strlen(prefix) && match(prefix, strlen(prefix))) { _prefix_matched = true; return; } @@ -853,14 +853,14 @@ void ATHandler::resp(const char *prefix, bool check_urc) // If no match found, look for CRLF and consume everything up to and including CRLF if (mem_str(_recv_buff, _recv_len, CRLF, CRLF_LENGTH)) { // If no prefix, return on CRLF - means data to read - if (!prefix) { + if (!prefix || (prefix && !strlen(prefix))) { return; } consume_to_tag(CRLF, true); } else { // If no prefix, no CRLF and no more chance to match for OK, ERROR or URC(since max resp length is already in buffer) // return so data could be read - if (!prefix && ((_recv_len - _recv_pos) >= _max_resp_length)) { + if ((!prefix || (prefix && !strlen(prefix))) && ((_recv_len - _recv_pos) >= _max_resp_length)) { return; } if (!fill_buffer()) { diff --git a/features/cellular/framework/AT/ATHandler.h b/features/cellular/framework/AT/ATHandler.h index bdf9734285..c284c41c1c 100644 --- a/features/cellular/framework/AT/ATHandler.h +++ b/features/cellular/framework/AT/ATHandler.h @@ -391,7 +391,8 @@ public: * If needed, it ends the scope of a previous information response. * Sets the information response scope if new prefix is found and response scope if prefix is not found. * - * @return true if new information response is found, false otherwise + * @return true if prefix defined for information response is not empty string and is found, + * false otherwise. */ bool info_resp();