Skip to content

Commit 5a1dc18

Browse files
MirkoCovizzinordicjm
authored andcommitted
lib: at_parser: return -ENODATA on empty subparameter
Return `-ENODATA` instead of `-EOPNOTSUPP` when parsing empty subparameters. Signed-off-by: Mirko Covizzi <[email protected]>
1 parent 7b09faf commit 5a1dc18

File tree

4 files changed

+90
-19
lines changed

4 files changed

+90
-19
lines changed

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,19 @@ Modem libraries
495495

496496
* Added support for parsing DECT NR+ modem firmware names.
497497

498+
* Updated the following macros and functions to return ``-ENODATA`` when the target subparameter to parse is empty:
499+
500+
* :c:macro:`at_parser_num_get` macro
501+
* Functions:
502+
503+
* :c:func:`at_parser_int16_get`
504+
* :c:func:`at_parser_uint16_get`
505+
* :c:func:`at_parser_int32_get`
506+
* :c:func:`at_parser_uint32_get`
507+
* :c:func:`at_parser_int64_get`
508+
* :c:func:`at_parser_uint64_get`
509+
* :c:func:`at_parser_string_get`
510+
498511
* :ref:`lte_lc_readme` library:
499512

500513
* Added the :kconfig:option:`CONFIG_LTE_LC_DNS_FALLBACK_MODULE` and :kconfig:option:`CONFIG_LTE_LC_DNS_FALLBACK_ADDRESS` Kconfig options to enable setting a fallback DNS address.

include/modem/at_parser.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ struct at_parser {
6767
* @retval -EINVAL One or more of the supplied parameters are invalid.
6868
* @retval -EPERM @p parser has not been initialized.
6969
* @retval -EOPNOTSUPP Operation not supported for the type of value at the given index.
70+
* @retval -ENODATA The value at the given index is empty.
7071
* @retval -ERANGE Parsed integer value is out of range for the expected type.
7172
* @retval -EBADMSG The AT command string is malformed.
7273
* @retval -EAGAIN Parsing of the current AT command line is terminated and a subsequent line is
@@ -157,6 +158,7 @@ int at_parser_cmd_count_get(struct at_parser *parser, size_t *count);
157158
* @retval -EINVAL One or more of the supplied parameters are invalid.
158159
* @retval -EPERM @p parser has not been initialized.
159160
* @retval -EOPNOTSUPP Operation not supported for the type of value at the given index.
161+
* @retval -ENODATA The value at the given index is empty.
160162
* @retval -ERANGE Parsed integer value is out of range for the expected type.
161163
* @retval -EBADMSG The AT command string is malformed.
162164
* @retval -EAGAIN Parsing of the current AT command line is terminated and a subsequent line is
@@ -180,6 +182,7 @@ int at_parser_int16_get(struct at_parser *parser, size_t index, int16_t *value);
180182
* @retval -EINVAL One or more of the supplied parameters are invalid.
181183
* @retval -EPERM @p parser has not been initialized.
182184
* @retval -EOPNOTSUPP Operation not supported for the type of value at the given index.
185+
* @retval -ENODATA The value at the given index is empty.
183186
* @retval -ERANGE Parsed integer value is out of range for the expected type.
184187
* @retval -EBADMSG The AT command string is malformed.
185188
* @retval -EAGAIN Parsing of the current AT command line is terminated and a subsequent line is
@@ -203,6 +206,7 @@ int at_parser_uint16_get(struct at_parser *parser, size_t index, uint16_t *value
203206
* @retval -EINVAL One or more of the supplied parameters are invalid.
204207
* @retval -EPERM @p parser has not been initialized.
205208
* @retval -EOPNOTSUPP Operation not supported for the type of value at the given index.
209+
* @retval -ENODATA The value at the given index is empty.
206210
* @retval -ERANGE Parsed integer value is out of range for the expected type.
207211
* @retval -EBADMSG The AT command string is malformed.
208212
* @retval -EAGAIN Parsing of the current AT command line is terminated and a subsequent line is
@@ -226,6 +230,7 @@ int at_parser_int32_get(struct at_parser *parser, size_t index, int32_t *value);
226230
* @retval -EINVAL One or more of the supplied parameters are invalid.
227231
* @retval -EPERM @p parser has not been initialized.
228232
* @retval -EOPNOTSUPP Operation not supported for the type of value at the given index.
233+
* @retval -ENODATA The value at the given index is empty.
229234
* @retval -ERANGE Parsed integer value is out of range for the expected type.
230235
* @retval -EBADMSG The AT command string is malformed.
231236
* @retval -EAGAIN Parsing of the current AT command line is terminated and a subsequent line is
@@ -249,6 +254,7 @@ int at_parser_uint32_get(struct at_parser *parser, size_t index, uint32_t *value
249254
* @retval -EINVAL One or more of the supplied parameters are invalid.
250255
* @retval -EPERM @p parser has not been initialized.
251256
* @retval -EOPNOTSUPP Operation not supported for the type of value at the given index.
257+
* @retval -ENODATA The value at the given index is empty.
252258
* @retval -ERANGE Parsed integer value is out of range for the expected type.
253259
* @retval -EBADMSG The AT command string is malformed.
254260
* @retval -EAGAIN Parsing of the current AT command line is terminated and a subsequent line is
@@ -272,6 +278,7 @@ int at_parser_int64_get(struct at_parser *parser, size_t index, int64_t *value);
272278
* @retval -EINVAL One or more of the supplied parameters are invalid.
273279
* @retval -EPERM @p parser has not been initialized.
274280
* @retval -EOPNOTSUPP Operation not supported for the type of value at the given index.
281+
* @retval -ENODATA The value at the given index is empty.
275282
* @retval -ERANGE Parsed integer value is out of range for the expected type.
276283
* @retval -EBADMSG The AT command string is malformed.
277284
* @retval -EAGAIN Parsing of the current AT command line is terminated and a subsequent line is
@@ -301,6 +308,7 @@ int at_parser_uint64_get(struct at_parser *parser, size_t index, uint64_t *value
301308
* @retval -EINVAL One or more of the supplied parameters are invalid.
302309
* @retval -EPERM @p parser has not been initialized.
303310
* @retval -EOPNOTSUPP Operation not supported for the type of value at the given index.
311+
* @retval -ENODATA The value at the given index is empty.
304312
* @retval -ENOMEM @p str is smaller than the null-terminated string to be copied.
305313
* @retval -EBADMSG The AT command string is malformed.
306314
* @retval -EAGAIN Parsing of the current AT command line is terminated and a subsequent line is

lib/at_parser/at_parser.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,13 @@ static int at_parser_num_get_impl(struct at_parser *parser, size_t index, void *
370370
return err;
371371
}
372372

373-
if (token.type != AT_TOKEN_TYPE_INT) {
373+
switch (token.type) {
374+
/* Acceptable types. */
375+
case AT_TOKEN_TYPE_INT:
376+
break;
377+
case AT_TOKEN_TYPE_EMPTY:
378+
return -ENODATA;
379+
default:
374380
return -EOPNOTSUPP;
375381
}
376382

@@ -493,6 +499,8 @@ static int at_parser_string_common_get_impl(struct at_parser *parser, size_t ind
493499
case AT_TOKEN_TYPE_STRING:
494500
case AT_TOKEN_TYPE_ARRAY:
495501
break;
502+
case AT_TOKEN_TYPE_EMPTY:
503+
return -ENODATA;
496504
default:
497505
return -EOPNOTSUPP;
498506
}

tests/lib/at_parser/src/main.c

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -810,15 +810,22 @@ ZTEST(at_parser, test_at_parser_uint16_get_eopnotsupp)
810810
/* Trying to parse notification string as integer. */
811811
ret = at_parser_uint16_get(&parser, 0, &val);
812812
zassert_equal(ret, -EOPNOTSUPP);
813+
}
813814

814-
const char *str2 = "+NOTIF: 1,,3";
815+
ZTEST(at_parser, test_at_parser_uint16_get_enodata)
816+
{
817+
int ret;
818+
uint16_t val;
819+
struct at_parser parser;
815820

816-
ret = at_parser_init(&parser, str2);
821+
const char *str1 = "+NOTIF: 1,,3";
822+
823+
ret = at_parser_init(&parser, str1);
817824
zassert_ok(ret);
818825

819826
/* Trying to parse an empty subparameter as integer. */
820827
ret = at_parser_uint16_get(&parser, 2, &val);
821-
zassert_equal(ret, -EOPNOTSUPP);
828+
zassert_equal(ret, -ENODATA);
822829
}
823830

824831
ZTEST(at_parser, test_at_parser_uint16_get_ebadmsg)
@@ -951,15 +958,22 @@ ZTEST(at_parser, test_at_parser_int16_get_eopnotsupp)
951958
/* Trying to parse notification string as integer. */
952959
ret = at_parser_int16_get(&parser, 0, &val);
953960
zassert_equal(ret, -EOPNOTSUPP);
961+
}
954962

955-
const char *str2 = "+NOTIF: 1,,3";
963+
ZTEST(at_parser, test_at_parser_int16_get_enodata)
964+
{
965+
int ret;
966+
int16_t val;
967+
struct at_parser parser;
956968

957-
ret = at_parser_init(&parser, str2);
969+
const char *str1 = "+NOTIF: 1,,3";
970+
971+
ret = at_parser_init(&parser, str1);
958972
zassert_ok(ret);
959973

960974
/* Trying to parse an empty subparameter as integer. */
961975
ret = at_parser_int16_get(&parser, 2, &val);
962-
zassert_equal(ret, -EOPNOTSUPP);
976+
zassert_equal(ret, -ENODATA);
963977
}
964978

965979
ZTEST(at_parser, test_at_parser_int16_get_ebadmsg)
@@ -1099,15 +1113,22 @@ ZTEST(at_parser, test_at_parser_uint32_get_eopnotsupp)
10991113
/* Trying to parse notification string as integer. */
11001114
ret = at_parser_uint32_get(&parser, 0, &val);
11011115
zassert_equal(ret, -EOPNOTSUPP);
1116+
}
11021117

1103-
const char *str2 = "+NOTIF: 1,,3";
1118+
ZTEST(at_parser, test_at_parser_uint32_get_enodata)
1119+
{
1120+
int ret;
1121+
uint32_t val;
1122+
struct at_parser parser;
11041123

1105-
ret = at_parser_init(&parser, str2);
1124+
const char *str1 = "+NOTIF: 1,,3";
1125+
1126+
ret = at_parser_init(&parser, str1);
11061127
zassert_ok(ret);
11071128

11081129
/* Trying to parse an empty subparameter as integer. */
11091130
ret = at_parser_uint32_get(&parser, 2, &val);
1110-
zassert_equal(ret, -EOPNOTSUPP);
1131+
zassert_equal(ret, -ENODATA);
11111132
}
11121133

11131134
ZTEST(at_parser, test_at_parser_uint32_get_ebadmsg)
@@ -1242,15 +1263,22 @@ ZTEST(at_parser, test_at_parser_int32_get_eopnotsupp)
12421263
/* Trying to parse notification string as integer. */
12431264
ret = at_parser_int32_get(&parser, 0, &val);
12441265
zassert_equal(ret, -EOPNOTSUPP);
1266+
}
12451267

1246-
const char *str2 = "+NOTIF: 1,,3";
1268+
ZTEST(at_parser, test_at_parser_int32_get_enodata)
1269+
{
1270+
int ret;
1271+
int32_t val;
1272+
struct at_parser parser;
12471273

1248-
ret = at_parser_init(&parser, str2);
1274+
const char *str1 = "+NOTIF: 1,,3";
1275+
1276+
ret = at_parser_init(&parser, str1);
12491277
zassert_ok(ret);
12501278

12511279
/* Trying to parse an empty subparameter as integer. */
12521280
ret = at_parser_int32_get(&parser, 2, &val);
1253-
zassert_equal(ret, -EOPNOTSUPP);
1281+
zassert_equal(ret, -ENODATA);
12541282
}
12551283

12561284
ZTEST(at_parser, test_at_parser_int32_get_ebadmsg)
@@ -1389,15 +1417,22 @@ ZTEST(at_parser, test_at_parser_uint64_get_eopnotsupp)
13891417
/* Trying to parse notification string as integer. */
13901418
ret = at_parser_uint64_get(&parser, 0, &val);
13911419
zassert_equal(ret, -EOPNOTSUPP);
1420+
}
13921421

1393-
const char *str2 = "+NOTIF: 1,,3";
1422+
ZTEST(at_parser, test_at_parser_uint64_get_enodata)
1423+
{
1424+
int ret;
1425+
uint64_t val;
1426+
struct at_parser parser;
13941427

1395-
ret = at_parser_init(&parser, str2);
1428+
const char *str1 = "+NOTIF: 1,,3";
1429+
1430+
ret = at_parser_init(&parser, str1);
13961431
zassert_ok(ret);
13971432

13981433
/* Trying to parse an empty subparameter as integer. */
13991434
ret = at_parser_uint64_get(&parser, 2, &val);
1400-
zassert_equal(ret, -EOPNOTSUPP);
1435+
zassert_equal(ret, -ENODATA);
14011436
}
14021437

14031438
ZTEST(at_parser, test_at_parser_uint64_get_ebadmsg)
@@ -1540,15 +1575,22 @@ ZTEST(at_parser, test_at_parser_int64_get_eopnotsupp)
15401575
/* Trying to parse notification string as integer. */
15411576
ret = at_parser_int64_get(&parser, 0, &val);
15421577
zassert_equal(ret, -EOPNOTSUPP);
1578+
}
15431579

1544-
const char *str2 = "+NOTIF: 1,,3";
1580+
ZTEST(at_parser, test_at_parser_int64_get_enodata)
1581+
{
1582+
int ret;
1583+
int64_t val;
1584+
struct at_parser parser;
15451585

1546-
ret = at_parser_init(&parser, str2);
1586+
const char *str1 = "+NOTIF: 1,,3";
1587+
1588+
ret = at_parser_init(&parser, str1);
15471589
zassert_ok(ret);
15481590

15491591
/* Trying to parse an empty subparameter as integer. */
15501592
ret = at_parser_int64_get(&parser, 2, &val);
1551-
zassert_equal(ret, -EOPNOTSUPP);
1593+
zassert_equal(ret, -ENODATA);
15521594
}
15531595

15541596
ZTEST(at_parser, test_at_parser_int64_get_ebadmsg)

0 commit comments

Comments
 (0)