From b0d34d83c53d1348f50044dc416b9ee9e5e8c84c Mon Sep 17 00:00:00 2001 From: Sathish Narasimman Date: Fri, 4 Nov 2016 12:05:10 +0530 Subject: [PATCH] Bluetooth: AT handling error condition In function at_get_number check for the value if gets computed. If not return error. Also change the end state handling. Change-Id: I193b04fa2880dfb44e7727b30b67c1ec2e051cc7 Signed-off-by: Sathish Narasimman --- subsys/bluetooth/host/at.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/subsys/bluetooth/host/at.c b/subsys/bluetooth/host/at.c index dd225c16e99..2c2eb8d76e4 100644 --- a/subsys/bluetooth/host/at.c +++ b/subsys/bluetooth/host/at.c @@ -50,12 +50,18 @@ const char *skip_whitespace(const char *buf) int at_get_number(const char *buf, uint32_t *val) { - *val = 0; + uint32_t i; - for (buf = skip_whitespace(buf); isdigit(*buf); buf++) { + buf = skip_whitespace(buf); + + for (i = 0, *val = 0; isdigit(*buf); buf++, i++) { *val = *val * 10 + *buf - '0'; } + if (i == 0) { + return -ENODATA; + } + return 0; } @@ -279,7 +285,12 @@ static int cmd_get_value(struct at_client *at, struct net_buf *buf, static int cmd_process_value(struct at_client *at, struct net_buf *buf, const char *prefix, parse_val_t func) { - return func(at); + int ret; + + ret = func(at); + at->cmd_state = CMD_STATE_END_LF; + + return ret; } static int cmd_state_end_lf(struct at_client *at, struct net_buf *buf,