From 1baf330aa9a4f92ba48a5d070d9a48160a92f4b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20R=C3=B8nningstad?= Date: Wed, 10 Jan 2024 09:09:41 +0100 Subject: [PATCH 1/7] [nrf fromlist] west.yml: Update zcbor to 0.8.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add support for unordered maps - Performance improvements - Naming improvements for generated code - Bugfixes Signed-off-by: Øyvind Rønningstad --- west.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/west.yml b/west.yml index a141e94edd6..ddda63add28 100644 --- a/west.yml +++ b/west.yml @@ -335,7 +335,7 @@ manifest: revision: 5fe2cb613bd7e4590bd1b00c2adf181ac0229379 path: modules/lib/uoscore-uedhoc - name: zcbor - revision: 67fd8bb88d3136738661fa8bb5f9989103f4599e + revision: 0.8.0 path: modules/lib/zcbor self: From f97e82322da3744e5618b29f43d6365b346c9766 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20R=C3=B8nningstad?= Date: Wed, 10 Jan 2024 12:49:09 +0100 Subject: [PATCH 2/7] [nrf fromlist] west.yml: Update MCUboot to bring in zcbor 0.8.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes in boot_serial.c Signed-off-by: Øyvind Rønningstad --- west.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/west.yml b/west.yml index ddda63add28..0507c89f1da 100644 --- a/west.yml +++ b/west.yml @@ -282,7 +282,8 @@ manifest: groups: - crypto - name: mcuboot - revision: 0c0470e294dcfb52aab92299356a5f3caa0aa52b + revision: pull/1886/head + url: https://github.com/mcu-tools/mcuboot path: bootloader/mcuboot - name: mipi-sys-t path: modules/debug/mipi-sys-t From a5373d828a0c44870c11db153aa23b0530037857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20R=C3=B8nningstad?= Date: Wed, 10 Jan 2024 14:40:49 +0100 Subject: [PATCH 3/7] [nrf fromlist] west.yml: Update uoscore-uedhoc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit to bring in changes related to zcbor 0.8.0 Signed-off-by: Øyvind Rønningstad --- west.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/west.yml b/west.yml index 0507c89f1da..fbc3b2083b3 100644 --- a/west.yml +++ b/west.yml @@ -333,7 +333,8 @@ manifest: groups: - tee - name: uoscore-uedhoc - revision: 5fe2cb613bd7e4590bd1b00c2adf181ac0229379 + revision: pull/61/head + url: https://github.com/eriptic/uoscore-uedhoc path: modules/lib/uoscore-uedhoc - name: zcbor revision: 0.8.0 From 2c40b34b8358ac9c241b69e33e3218917d2e54b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20R=C3=B8nningstad?= Date: Thu, 11 Jan 2024 14:18:21 +0100 Subject: [PATCH 4/7] [nrf fromlist] modules: zcbor: Add config CONFIG_ZCBOR_MAX_STR_LEN MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For use with zcbor_tstr_put_term() which needs a maximum string length. Signed-off-by: Øyvind Rønningstad --- modules/zcbor/Kconfig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/zcbor/Kconfig b/modules/zcbor/Kconfig index 1b3fd15d5e3..655fb2ed2a8 100644 --- a/modules/zcbor/Kconfig +++ b/modules/zcbor/Kconfig @@ -33,4 +33,11 @@ config ZCBOR_ASSERT config ZCBOR_BIG_ENDIAN def_bool BIG_ENDIAN +config ZCBOR_MAX_STR_LEN + int "Default max length when calling zcbor_tstr_put_term()" + default 256 + help + This can be manually used if no other value is readily available, but + using this is discouraged. + endif # ZCBOR From c728f7790182854483e172641581d4f592e62fa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20R=C3=B8nningstad?= Date: Wed, 10 Jan 2024 10:00:53 +0100 Subject: [PATCH 5/7] [nrf fromlist] lwm2m: Adapt to zcbor 0.8.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Regenerate from CDDL, update patch, fix references in code. Signed-off-by: Øyvind Rønningstad --- subsys/net/lib/lwm2m/lwm2m_rw_cbor.c | 22 +- subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c | 144 +++++----- subsys/net/lib/lwm2m/lwm2m_senml_cbor.patch | 218 +++++---------- .../net/lib/lwm2m/lwm2m_senml_cbor_decode.c | 220 ++++++++------- .../net/lib/lwm2m/lwm2m_senml_cbor_decode.h | 2 +- .../net/lib/lwm2m/lwm2m_senml_cbor_encode.c | 254 ++++++++++-------- .../net/lib/lwm2m/lwm2m_senml_cbor_encode.h | 2 +- subsys/net/lib/lwm2m/lwm2m_senml_cbor_types.h | 116 ++++---- 8 files changed, 465 insertions(+), 513 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_rw_cbor.c b/subsys/net/lib/lwm2m/lwm2m_rw_cbor.c index daa37d3b4ba..3b35d579569 100644 --- a/subsys/net/lib/lwm2m/lwm2m_rw_cbor.c +++ b/subsys/net/lib/lwm2m/lwm2m_rw_cbor.c @@ -66,7 +66,7 @@ static int put_time(struct lwm2m_output_context *out, struct lwm2m_obj_path *pat ZCBOR_STATE_E(states, 0, CPKT_BUF_W_PTR(out->out_cpkt), CPKT_BUF_W_SIZE(out->out_cpkt), 1); /* Are tags required? V1.1 leaves this unspecified but some servers require tags */ - ret = zcbor_tag_encode(states, ZCBOR_TAG_TIME_TSTR); + ret = zcbor_tag_put(states, ZCBOR_TAG_TIME_TSTR); if (!ret) { LOG_ERR("unable to encode date/time string tag"); @@ -77,7 +77,7 @@ static int put_time(struct lwm2m_output_context *out, struct lwm2m_obj_path *pat out->out_cpkt->offset += tag_sz; - ret = zcbor_tstr_put_term(states, time_str); + ret = zcbor_tstr_put_term(states, time_str, sizeof(time_str)); if (!ret) { LOG_ERR("unable to encode date/time string"); return -ENOMEM; @@ -232,7 +232,7 @@ static int put_objlnk(struct lwm2m_output_context *out, struct lwm2m_obj_path *p static int get_s64(struct lwm2m_input_context *in, int64_t *value) { - ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1); + ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1, 0); if (!zcbor_int64_decode(states, value)) { LOG_WRN("unable to decode a 64-bit integer value"); @@ -248,7 +248,7 @@ static int get_s64(struct lwm2m_input_context *in, int64_t *value) static int get_s32(struct lwm2m_input_context *in, int32_t *value) { - ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1); + ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1, 0); if (!zcbor_int32_decode(states, value)) { LOG_WRN("unable to decode a 32-bit integer value, err: %d", @@ -265,7 +265,7 @@ static int get_s32(struct lwm2m_input_context *in, int32_t *value) static int get_float(struct lwm2m_input_context *in, double *value) { - ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1); + ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1, 0); if (!zcbor_float_decode(states, value)) { LOG_ERR("unable to decode a floating-point value"); @@ -284,7 +284,7 @@ static int get_string(struct lwm2m_input_context *in, uint8_t *value, size_t buf struct zcbor_string hndl; int len; - ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1); + ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1, 0); if (!zcbor_tstr_decode(states, &hndl)) { LOG_WRN("unable to decode a string"); @@ -313,7 +313,7 @@ static int get_time_string(struct lwm2m_input_context *in, int64_t *value) char time_str[sizeof("4294967295")] = { 0 }; struct zcbor_string hndl = { .value = time_str, .len = sizeof(time_str) - 1 }; - ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1); + ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1, 0); if (!zcbor_tstr_decode(states, &hndl)) { return -EBADMSG; @@ -331,7 +331,7 @@ static int get_time_string(struct lwm2m_input_context *in, int64_t *value) */ static int get_time_numerical(struct lwm2m_input_context *in, int64_t *value) { - ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1); + ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1, 0); if (!zcbor_int64_decode(states, value)) { LOG_WRN("unable to decode seconds since Epoch"); @@ -350,7 +350,7 @@ static int get_time(struct lwm2m_input_context *in, time_t *value) bool success; int64_t temp64; - ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1); + ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1, 0); success = zcbor_tag_decode(states, &tag); @@ -400,7 +400,7 @@ static int get_time(struct lwm2m_input_context *in, time_t *value) static int get_bool(struct lwm2m_input_context *in, bool *value) { - ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1); + ZCBOR_STATE_D(states, 0, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1, 0); if (!zcbor_bool_decode(states, value)) { LOG_WRN("unable to decode a boolean value"); @@ -420,7 +420,7 @@ static int get_opaque(struct lwm2m_input_context *in, uint8_t *value, size_t buf struct zcbor_string_fragment hndl = { 0 }; int ret; - ZCBOR_STATE_D(states, 1, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1); + ZCBOR_STATE_D(states, 1, ICTX_BUF_R_PTR(in), ICTX_BUF_R_LEFT_SZ(in), 1, 0); /* Get the CBOR header only on first read. */ if (opaque->remaining == 0) { diff --git a/subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c b/subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c index dd963aa0583..6c20024bbde 100644 --- a/subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c +++ b/subsys/net/lib/lwm2m/lwm2m_rw_senml_cbor.c @@ -81,12 +81,12 @@ K_MUTEX_DEFINE(fd_mtx); #define GET_CBOR_FD_NAME(fd) ((fd)->names[(fd)->name_cnt]) /* Get the current record */ #define GET_CBOR_FD_REC(fd) \ - &((fd)->input._lwm2m_senml__record[(fd)->input._lwm2m_senml__record_count]) + &((fd)->input.lwm2m_senml_record_m[(fd)->input.lwm2m_senml_record_m_count]) /* Get a record */ -#define GET_IN_FD_REC_I(fd, i) &((fd)->dcd._lwm2m_senml__record[i]) +#define GET_IN_FD_REC_I(fd, i) &((fd)->dcd.lwm2m_senml_record_m[i]) /* Consume the current record */ #define CONSUME_CBOR_FD_REC(fd) \ - &((fd)->input._lwm2m_senml__record[(fd)->input._lwm2m_senml__record_count++]) + &((fd)->input.lwm2m_senml_record_m[(fd)->input.lwm2m_senml_record_m_count++]) /* Get CBOR output formatter data */ #define LWM2M_OFD_CBOR(octx) ((struct cbor_out_fmt_data *)engine_get_out_user_data(octx)) @@ -131,7 +131,7 @@ static int fmt_range_check(struct cbor_out_fmt_data *fd) { if (fd->name_cnt >= CONFIG_LWM2M_RW_SENML_CBOR_RECORDS || fd->objlnk_cnt >= CONFIG_LWM2M_RW_SENML_CBOR_RECORDS || - fd->input._lwm2m_senml__record_count >= CONFIG_LWM2M_RW_SENML_CBOR_RECORDS) { + fd->input.lwm2m_senml_record_m_count >= CONFIG_LWM2M_RW_SENML_CBOR_RECORDS) { LOG_ERR("CONFIG_LWM2M_RW_SENML_CBOR_RECORDS too small"); return -ENOMEM; } @@ -161,9 +161,9 @@ static int put_basename(struct lwm2m_output_context *out, struct lwm2m_obj_path /* Tell CBOR encoder where to find the name */ struct record *record = GET_CBOR_FD_REC(fd); - record->_record_bn._record_bn.value = basename; - record->_record_bn._record_bn.len = len; - record->_record_bn_present = 1; + record->record_bn.record_bn.value = basename; + record->record_bn.record_bn.len = len; + record->record_bn_present = 1; if ((len < sizeof("/0/0") - 1) || (len >= SENML_MAX_NAME_SIZE)) { __ASSERT_NO_MSG(false); @@ -190,7 +190,7 @@ static int put_end(struct lwm2m_output_context *out, struct lwm2m_obj_path *path size_t len; struct lwm2m_senml *input = &(LWM2M_OFD_CBOR(out)->input); - if (!input->_lwm2m_senml__record_count) { + if (!input->lwm2m_senml_record_m_count) { len = put_empty_array(out); return len; @@ -258,9 +258,9 @@ static int put_begin_r(struct lwm2m_output_context *out, struct lwm2m_obj_path * /* Tell CBOR encoder where to find the name */ struct record *record = GET_CBOR_FD_REC(fd); - record->_record_n._record_n.value = name; - record->_record_n._record_n.len = len; - record->_record_n_present = 1; + record->record_n.record_n.value = name; + record->record_n.record_n.len = len; + record->record_n_present = 1; /* Makes possible to use same slot for storing r/ri name combination. * No need to increase the name count if an existing name has been used @@ -287,12 +287,12 @@ static int put_data_timestamp(struct lwm2m_output_context *out, time_t value) out_record = GET_CBOR_FD_REC(fd); if (fd->basetime) { - out_record->_record_t._record_t = value - fd->basetime; - out_record->_record_t_present = 1; + out_record->record_t.record_t = value - fd->basetime; + out_record->record_t_present = 1; } else { fd->basetime = value; - out_record->_record_bt._record_bt = value; - out_record->_record_bt_present = 1; + out_record->record_bt.record_bt = value; + out_record->record_bt_present = 1; } return 0; @@ -332,9 +332,9 @@ static int put_begin_ri(struct lwm2m_output_context *out, struct lwm2m_obj_path } /* Tell CBOR encoder where to find the name */ - record->_record_n._record_n.value = name; - record->_record_n._record_n.len = len; - record->_record_n_present = 1; + record->record_n.record_n.value = name; + record->record_n.record_n.len = len; + record->record_n_present = 1; /* No need to increase the name count if an existing name has been used */ if (name == GET_CBOR_FD_NAME(fd)) { @@ -353,7 +353,7 @@ static int put_name_nth_ri(struct lwm2m_output_context *out, struct lwm2m_obj_pa /* With the first ri the resource name (and ri name) are already in place*/ if (path->res_inst_id > 0) { ret = put_begin_ri(out, path); - } else if (record && record->_record_t_present) { + } else if (record && record->record_t_present) { /* Name need to be add for each time serialized record */ ret = put_begin_r(out, path); } @@ -372,9 +372,9 @@ static int put_value(struct lwm2m_output_context *out, struct lwm2m_obj_path *pa struct record *record = CONSUME_CBOR_FD_REC(LWM2M_OFD_CBOR(out)); /* Write the value */ - record->_record_union._record_union_choice = _union_vi; - record->_record_union._union_vi = value; - record->_record_union_present = 1; + record->record_union.record_union_choice = union_vi_c; + record->record_union.union_vi = value; + record->record_union_present = 1; return 0; } @@ -410,9 +410,9 @@ static int put_time(struct lwm2m_output_context *out, struct lwm2m_obj_path *pat struct record *record = CONSUME_CBOR_FD_REC(LWM2M_OFD_CBOR(out)); /* Write the value */ - record->_record_union._record_union_choice = _union_vi; - record->_record_union._union_vi = (int64_t)value; - record->_record_union_present = 1; + record->record_union.record_union_choice = union_vi_c; + record->record_union.union_vi = (int64_t)value; + record->record_union_present = 1; return 0; } @@ -428,9 +428,9 @@ static int put_float(struct lwm2m_output_context *out, struct lwm2m_obj_path *pa struct record *record = CONSUME_CBOR_FD_REC(LWM2M_OFD_CBOR(out)); /* Write the value */ - record->_record_union._record_union_choice = _union_vf; - record->_record_union._union_vf = *value; - record->_record_union_present = 1; + record->record_union.record_union_choice = union_vf_c; + record->record_union.union_vf = *value; + record->record_union_present = 1; return 0; } @@ -447,10 +447,10 @@ static int put_string(struct lwm2m_output_context *out, struct lwm2m_obj_path *p struct record *record = CONSUME_CBOR_FD_REC(LWM2M_OFD_CBOR(out)); /* Write the value */ - record->_record_union._record_union_choice = _union_vs; - record->_record_union._union_vs.value = buf; - record->_record_union._union_vs.len = buflen; - record->_record_union_present = 1; + record->record_union.record_union_choice = union_vs_c; + record->record_union.union_vs.value = buf; + record->record_union.union_vs.len = buflen; + record->record_union_present = 1; return 0; } @@ -466,9 +466,9 @@ static int put_bool(struct lwm2m_output_context *out, struct lwm2m_obj_path *pat struct record *record = CONSUME_CBOR_FD_REC(LWM2M_OFD_CBOR(out)); /* Write the value */ - record->_record_union._record_union_choice = _union_vb; - record->_record_union._union_vb = value; - record->_record_union_present = 1; + record->record_union.record_union_choice = union_vb_c; + record->record_union.union_vb = value; + record->record_union_present = 1; return 0; } @@ -485,10 +485,10 @@ static int put_opaque(struct lwm2m_output_context *out, struct lwm2m_obj_path *p struct record *record = CONSUME_CBOR_FD_REC(LWM2M_OFD_CBOR(out)); /* Write the value */ - record->_record_union._record_union_choice = _union_vd; - record->_record_union._union_vd.value = buf; - record->_record_union._union_vd.len = buflen; - record->_record_union_present = 1; + record->record_union.record_union_choice = union_vd_c; + record->record_union.union_vd.value = buf; + record->record_union.union_vd.len = buflen; + record->record_union_present = 1; return 0; } @@ -522,10 +522,10 @@ static int put_objlnk(struct lwm2m_output_context *out, struct lwm2m_obj_path *p struct record *record = CONSUME_CBOR_FD_REC(LWM2M_OFD_CBOR(out)); /* Write the value */ - record->_record_union._record_union_choice = _union_vlo; - record->_record_union._union_vlo.value = objlink_buf; - record->_record_union._union_vlo.len = objlnk_len; - record->_record_union_present = 1; + record->record_union.record_union_choice = union_vlo_c; + record->record_union.union_vlo.value = objlink_buf; + record->record_union.union_vlo.len = objlnk_len; + record->record_union_present = 1; fd->objlnk_cnt++; @@ -548,14 +548,14 @@ static int get_opaque(struct lwm2m_input_context *in, return -EINVAL; } - opaque->len = fd->current->_record_union._union_vd.len; + opaque->len = fd->current->record_union.union_vd.len; if (buflen < opaque->len) { LOG_DBG("Write opaque failed, no buffer space"); return -ENOMEM; } - dest = memcpy(value, fd->current->_record_union._union_vd.value, opaque->len); + dest = memcpy(value, fd->current->record_union.union_vd.value, opaque->len); *last_block = true; } else { LOG_DBG("Blockwise transfer not supported with SenML CBOR"); @@ -574,7 +574,7 @@ static int get_s32(struct lwm2m_input_context *in, int32_t *value) return -EINVAL; } - *value = fd->current->_record_union._union_vi; + *value = fd->current->record_union.union_vi; fd->current = NULL; return 0; @@ -589,7 +589,7 @@ static int get_s64(struct lwm2m_input_context *in, int64_t *value) return -EINVAL; } - *value = fd->current->_record_union._union_vi; + *value = fd->current->record_union.union_vi; fd->current = NULL; return 0; @@ -615,7 +615,7 @@ static int get_float(struct lwm2m_input_context *in, double *value) return -EINVAL; } - *value = fd->current->_record_union._union_vf; + *value = fd->current->record_union.union_vf; fd->current = NULL; return 0; @@ -631,9 +631,9 @@ static int get_string(struct lwm2m_input_context *in, uint8_t *buf, size_t bufle return -EINVAL; } - len = MIN(buflen-1, fd->current->_record_union._union_vs.len); + len = MIN(buflen-1, fd->current->record_union.union_vs.len); - memcpy(buf, fd->current->_record_union._union_vs.value, len); + memcpy(buf, fd->current->record_union.union_vs.value, len); buf[len] = '\0'; fd->current = NULL; @@ -698,7 +698,7 @@ static int get_bool(struct lwm2m_input_context *in, bool *value) return -EINVAL; } - *value = fd->current->_record_union._union_vb; + *value = fd->current->record_union.union_vb; fd->current = NULL; return 0; @@ -727,9 +727,9 @@ static int do_write_op_item(struct lwm2m_message *msg, struct record *rec) } /* If there's no name then the basename forms the path */ - if (rec->_record_n_present) { - len = MIN(sizeof(name) - 1, rec->_record_n._record_n.len); - snprintk(name, len + 1, "%s", rec->_record_n._record_n.value); + if (rec->record_n_present) { + len = MIN(sizeof(name) - 1, rec->record_n.record_n.len); + snprintk(name, len + 1, "%s", rec->record_n.record_n.value); } /* Form fully qualified path name */ @@ -853,29 +853,29 @@ static uint8_t parse_composite_read_paths(struct lwm2m_message *msg, msg->in.offset += isize; - for (int idx = 0; idx < fd->dcd._lwm2m_senml__record_count; idx++) { + for (int idx = 0; idx < fd->dcd.lwm2m_senml_record_m_count; idx++) { /* Where to find the basenames and names */ struct record *record = GET_IN_FD_REC_I(fd, idx); /* Set null terminated effective basename */ - if (record->_record_bn_present) { - len = MIN(sizeof(basename)-1, record->_record_bn._record_bn.len); - snprintk(basename, len + 1, "%s", record->_record_bn._record_bn.value); + if (record->record_bn_present) { + len = MIN(sizeof(basename)-1, record->record_bn.record_bn.len); + snprintk(basename, len + 1, "%s", record->record_bn.record_bn.value); basename[len] = '\0'; } /* Best effort with read, skip if no proper name is available */ - if (!record->_record_n_present) { + if (!record->record_n_present) { if (strcmp(basename, "") == 0) { continue; } } /* Set null terminated name */ - if (record->_record_n_present) { - len = MIN(sizeof(name)-1, record->_record_n._record_n.len); - snprintk(name, len + 1, "%s", record->_record_n._record_n.value); + if (record->record_n_present) { + len = MIN(sizeof(name)-1, record->record_n.record_n.len); + snprintk(name, len + 1, "%s", record->record_n.record_n.value); name[len] = '\0'; } @@ -979,30 +979,30 @@ int do_write_op_senml_cbor(struct lwm2m_message *msg) msg->in.offset += decoded_sz; - for (int idx = 0; idx < fd->dcd._lwm2m_senml__record_count; idx++) { + for (int idx = 0; idx < fd->dcd.lwm2m_senml_record_m_count; idx++) { - struct record *rec = &fd->dcd._lwm2m_senml__record[idx]; + struct record *rec = &fd->dcd.lwm2m_senml_record_m[idx]; /* Basename applies for current and succeeding records */ - if (rec->_record_bn_present) { + if (rec->record_bn_present) { int len = MIN(sizeof(fd->basename) - 1, - rec->_record_bn._record_bn.len); + rec->record_bn.record_bn.len); - snprintk(fd->basename, len + 1, "%s", rec->_record_bn._record_bn.value); + snprintk(fd->basename, len + 1, "%s", rec->record_bn.record_bn.value); goto write; } /* Keys' lexicographic order differ from the default */ - for (int jdx = 0; jdx < rec->_record__key_value_pair_count; jdx++) { + for (int jdx = 0; jdx < rec->record_key_value_pair_m_count; jdx++) { struct key_value_pair *kvp = - &(rec->_record__key_value_pair[jdx]._record__key_value_pair); + &(rec->record_key_value_pair_m[jdx].record_key_value_pair_m); - if (kvp->_key_value_pair_key == lwm2m_senml_cbor_key_bn) { + if (kvp->key_value_pair_key == lwm2m_senml_cbor_key_bn) { int len = MIN(sizeof(fd->basename) - 1, - kvp->_key_value_pair._value_tstr.len); + kvp->key_value_pair.value_tstr.len); snprintk(fd->basename, len + 1, "%s", - kvp->_key_value_pair._value_tstr.value); + kvp->key_value_pair.value_tstr.value); break; } } diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor.patch b/subsys/net/lib/lwm2m/lwm2m_senml_cbor.patch index 48b984aafac..81ec06bab8b 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor.patch +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor.patch @@ -1,94 +1,59 @@ diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.c b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.c -index f97f0ebb2d..1c1233d616 100644 +index c12f477cce..f41b81275d 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.c +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 * - * Generated using zcbor version 0.7.0 + * Generated using zcbor version 0.8.0 - * https://github.com/NordicSemiconductor/zcbor + * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 */ -@@ -15,9 +15,6 @@ - #include "zcbor_decode.h" +@@ -16,10 +16,6 @@ #include "lwm2m_senml_cbor_decode.h" + #include "zcbor_print.h" -#if DEFAULT_MAX_QTY != 99 -#error "The type file was generated with a different default_max_qty than this file" -#endif - +- static bool decode_repeated_record_bn(zcbor_state_t *state, struct record_bn *result); static bool decode_repeated_record_bt(zcbor_state_t *state, struct record_bt *result); -@@ -52,7 +49,7 @@ static bool decode_repeated_record_bt( - - bool tmp_result = ((((zcbor_int32_expect(state, (-3)))) - && (zcbor_int64_decode(state, (&(*result)._record_bt))) -- && ((((*result)._record_bt >= -9223372036854775807LL) -+ && ((((*result)._record_bt >= INT64_MIN) - && ((*result)._record_bt <= INT64_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)))); - - if (!tmp_result) -@@ -82,7 +79,7 @@ static bool decode_repeated_record_t( - - bool tmp_result = ((((zcbor_uint32_expect(state, (6)))) - && (zcbor_int64_decode(state, (&(*result)._record_t))) -- && ((((*result)._record_t >= -9223372036854775807LL) -+ && ((((*result)._record_t >= INT64_MIN) - && ((*result)._record_t <= INT64_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)))); - - if (!tmp_result) -@@ -100,7 +97,7 @@ static bool decode_repeated_record_union( - - bool tmp_result = (((zcbor_union_start_code(state) && (int_res = (((((zcbor_uint32_expect_union(state, (2)))) - && (zcbor_int64_decode(state, (&(*result)._union_vi))) -- && ((((*result)._union_vi >= -9223372036854775807LL) -+ && ((((*result)._union_vi >= INT64_MIN) - && ((*result)._union_vi <= INT64_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) && (((*result)._record_union_choice = _union_vi), true)) - || ((((zcbor_uint32_expect_union(state, (2)))) - && (zcbor_float_decode(state, (&(*result)._union_vf)))) && (((*result)._record_union_choice = _union_vf), true)) -@@ -128,7 +125,7 @@ static bool decode_value( - bool tmp_result = (((zcbor_union_start_code(state) && (int_res = ((((zcbor_tstr_decode(state, (&(*result)._value_tstr)))) && (((*result)._value_choice = _value_tstr), true)) - || (((zcbor_bstr_decode(state, (&(*result)._value_bstr)))) && (((*result)._value_choice = _value_bstr), true)) - || (((zcbor_int64_decode(state, (&(*result)._value_int))) -- && ((((*result)._value_int >= -9223372036854775807LL) -+ && ((((*result)._value_int >= INT64_MIN) - && ((*result)._value_int <= INT64_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) && (((*result)._value_choice = _value_int), true)) - || (((zcbor_float_decode(state, (&(*result)._value_float)))) && (((*result)._value_choice = _value_float), true)) - || (((zcbor_bool_decode(state, (&(*result)._value_bool)))) && (((*result)._value_choice = _value_bool), true))), zcbor_union_end_code(state), int_res)))); -@@ -176,7 +173,7 @@ static bool decode_record( - && zcbor_present_decode(&((*result)._record_n_present), (zcbor_decoder_t *)decode_repeated_record_n, state, (&(*result)._record_n)) - && zcbor_present_decode(&((*result)._record_t_present), (zcbor_decoder_t *)decode_repeated_record_t, state, (&(*result)._record_t)) - && zcbor_present_decode(&((*result)._record_union_present), (zcbor_decoder_t *)decode_repeated_record_union, state, (&(*result)._record_union)) -- && zcbor_multi_decode(0, 5, &(*result)._record__key_value_pair_count, (zcbor_decoder_t *)decode_repeated_record__key_value_pair, state, (&(*result)._record__key_value_pair), sizeof(struct record__key_value_pair))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_map_end_decode(state)))); -+ && zcbor_multi_decode(0, ZCBOR_ARRAY_SIZE(result->_record__key_value_pair), &(*result)._record__key_value_pair_count, (zcbor_decoder_t *)decode_repeated_record__key_value_pair, state, (&(*result)._record__key_value_pair), sizeof(struct record__key_value_pair))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_map_end_decode(state)))); - - if (!tmp_result) - zcbor_trace(); -@@ -189,7 +186,7 @@ static bool decode_lwm2m_senml( + static bool decode_repeated_record_n(zcbor_state_t *state, struct record_n *result); +@@ -209,7 +205,7 @@ static bool decode_record( + && zcbor_present_decode(&((*result).record_n_present), (zcbor_decoder_t *)decode_repeated_record_n, state, (&(*result).record_n)) + && zcbor_present_decode(&((*result).record_t_present), (zcbor_decoder_t *)decode_repeated_record_t, state, (&(*result).record_t)) + && zcbor_present_decode(&((*result).record_union_present), (zcbor_decoder_t *)decode_repeated_record_union, state, (&(*result).record_union)) +- && zcbor_multi_decode(0, 5, &(*result).record_key_value_pair_m_count, (zcbor_decoder_t *)decode_repeated_record_key_value_pair_m, state, (&(*result).record_key_value_pair_m), sizeof(struct record_key_value_pair_m))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_map_end_decode(state)))); ++ && zcbor_multi_decode(0, ZCBOR_ARRAY_SIZE(result->record_key_value_pair_m), &(*result).record_key_value_pair_m_count, (zcbor_decoder_t *)decode_repeated_record_key_value_pair_m, state, (&(*result).record_key_value_pair_m), sizeof(struct record_key_value_pair_m))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_map_end_decode(state)))); + + if (!tmp_result) { + zcbor_trace_file(state); +@@ -226,7 +222,7 @@ static bool decode_lwm2m_senml( { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); -- bool tmp_result = (((zcbor_list_start_decode(state) && ((zcbor_multi_decode(1, 99, &(*result)._lwm2m_senml__record_count, (zcbor_decoder_t *)decode_record, state, (&(*result)._lwm2m_senml__record), sizeof(struct record))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_list_end_decode(state)))); -+ bool tmp_result = (((zcbor_list_start_decode(state) && ((zcbor_multi_decode(1, ZCBOR_ARRAY_SIZE(result->_lwm2m_senml__record), &(*result)._lwm2m_senml__record_count, (zcbor_decoder_t *)decode_record, state, (&(*result)._lwm2m_senml__record), sizeof(struct record))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_list_end_decode(state)))); +- bool tmp_result = (((zcbor_list_start_decode(state) && ((zcbor_multi_decode(1, 99, &(*result).lwm2m_senml_record_m_count, (zcbor_decoder_t *)decode_record, state, (&(*result).lwm2m_senml_record_m), sizeof(struct record))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_list_end_decode(state)))); ++ bool tmp_result = (((zcbor_list_start_decode(state) && ((zcbor_multi_decode(1, ZCBOR_ARRAY_SIZE(result->lwm2m_senml_record_m), &(*result).lwm2m_senml_record_m_count, (zcbor_decoder_t *)decode_record, state, (&(*result).lwm2m_senml_record_m), sizeof(struct record))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_list_end_decode(state)))); - if (!tmp_result) - zcbor_trace(); + if (!tmp_result) { + zcbor_trace_file(state); diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.h b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.h -index cb5d5c9695..7db7ed0591 100644 +index a36f8782c6..b913fb78e9 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.h +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.h @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 * - * Generated using zcbor version 0.7.0 + * Generated using zcbor version 0.8.0 - * https://github.com/NordicSemiconductor/zcbor + * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 */ -@@ -21,10 +21,6 @@ +@@ -21,11 +21,6 @@ extern "C" { #endif @@ -96,25 +61,26 @@ index cb5d5c9695..7db7ed0591 100644 -#error "The type file was generated with a different default_max_qty than this file" -#endif - - +- int cbor_decode_lwm2m_senml( - const uint8_t *payload, size_t payload_len, + const uint8_t *payload, size_t payload_len, + struct lwm2m_senml *result, diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.c b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.c -index 982cfca6c3..afdc6a32f7 100644 +index 94926c531f..5521917853 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.c +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 * - * Generated using zcbor version 0.7.0 + * Generated using zcbor version 0.8.0 - * https://github.com/NordicSemiconductor/zcbor + * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 */ -@@ -15,10 +15,6 @@ - #include "zcbor_encode.h" +@@ -16,10 +16,6 @@ #include "lwm2m_senml_cbor_encode.h" + #include "zcbor_print.h" -#if DEFAULT_MAX_QTY != 99 -#error "The type file was generated with a different default_max_qty than this file" @@ -123,80 +89,44 @@ index 982cfca6c3..afdc6a32f7 100644 static bool encode_repeated_record_bn(zcbor_state_t *state, const struct record_bn *input); static bool encode_repeated_record_bt(zcbor_state_t *state, const struct record_bt *input); static bool encode_repeated_record_n(zcbor_state_t *state, const struct record_n *input); -@@ -51,7 +47,7 @@ static bool encode_repeated_record_bt( - zcbor_print("%s\r\n", __func__); - - bool tmp_result = ((((zcbor_int32_put(state, (-3)))) -- && ((((*input)._record_bt >= -9223372036854775807LL) -+ && ((((*input)._record_bt >= INT64_MIN) - && ((*input)._record_bt <= INT64_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) - && (zcbor_int64_encode(state, (&(*input)._record_bt))))); - -@@ -81,7 +77,7 @@ static bool encode_repeated_record_t( - zcbor_print("%s\r\n", __func__); - - bool tmp_result = ((((zcbor_uint32_put(state, (6)))) -- && ((((*input)._record_t >= -9223372036854775807LL) -+ && ((((*input)._record_t >= INT64_MIN) - && ((*input)._record_t <= INT64_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) - && (zcbor_int64_encode(state, (&(*input)._record_t))))); - -@@ -98,7 +94,7 @@ static bool encode_repeated_record_union( - struct zcbor_string tmp_str; - - bool tmp_result = (((((*input)._record_union_choice == _union_vi) ? (((zcbor_uint32_put(state, (2)))) -- && ((((*input)._union_vi >= -9223372036854775807LL) -+ && ((((*input)._union_vi >= INT64_MIN) - && ((*input)._union_vi <= INT64_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) - && (zcbor_int64_encode(state, (&(*input)._union_vi)))) - : (((*input)._record_union_choice == _union_vf) ? (((zcbor_uint32_put(state, (2)))) -@@ -126,7 +122,7 @@ static bool encode_value( - - bool tmp_result = (((((*input)._value_choice == _value_tstr) ? ((zcbor_tstr_encode(state, (&(*input)._value_tstr)))) - : (((*input)._value_choice == _value_bstr) ? ((zcbor_bstr_encode(state, (&(*input)._value_bstr)))) -- : (((*input)._value_choice == _value_int) ? (((((*input)._value_int >= -9223372036854775807LL) -+ : (((*input)._value_choice == _value_int) ? (((((*input)._value_int >= INT64_MIN) - && ((*input)._value_int <= INT64_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) - && (zcbor_int64_encode(state, (&(*input)._value_int)))) - : (((*input)._value_choice == _value_float) ? ((zcbor_float64_encode(state, (&(*input)._value_float)))) -@@ -171,12 +167,12 @@ static bool encode_record( +@@ -204,12 +200,12 @@ static bool encode_record( { - zcbor_print("%s\r\n", __func__); - -- bool tmp_result = (((zcbor_map_start_encode(state, 10) && ((zcbor_present_encode(&((*input)._record_bn_present), (zcbor_encoder_t *)encode_repeated_record_bn, state, (&(*input)._record_bn)) -+ bool tmp_result = (((zcbor_map_start_encode(state, ZCBOR_ARRAY_SIZE(input->_record__key_value_pair)) && ((zcbor_present_encode(&((*input)._record_bn_present), (zcbor_encoder_t *)encode_repeated_record_bn, state, (&(*input)._record_bn)) - && zcbor_present_encode(&((*input)._record_bt_present), (zcbor_encoder_t *)encode_repeated_record_bt, state, (&(*input)._record_bt)) - && zcbor_present_encode(&((*input)._record_n_present), (zcbor_encoder_t *)encode_repeated_record_n, state, (&(*input)._record_n)) - && zcbor_present_encode(&((*input)._record_t_present), (zcbor_encoder_t *)encode_repeated_record_t, state, (&(*input)._record_t)) - && zcbor_present_encode(&((*input)._record_union_present), (zcbor_encoder_t *)encode_repeated_record_union, state, (&(*input)._record_union)) -- && zcbor_multi_encode_minmax(0, 5, &(*input)._record__key_value_pair_count, (zcbor_encoder_t *)encode_repeated_record__key_value_pair, state, (&(*input)._record__key_value_pair), sizeof(struct record__key_value_pair))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_map_end_encode(state, 10)))); -+ && zcbor_multi_encode_minmax(0, ZCBOR_ARRAY_SIZE(input->_record__key_value_pair), &(*input)._record__key_value_pair_count, (zcbor_encoder_t *)encode_repeated_record__key_value_pair, state, (&(*input)._record__key_value_pair), sizeof(struct record__key_value_pair))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_map_end_encode(state, ZCBOR_ARRAY_SIZE(input->_record__key_value_pair))))); - - if (!tmp_result) - zcbor_trace(); -@@ -189,7 +185,7 @@ static bool encode_lwm2m_senml( + zcbor_log("%s\r\n", __func__); + +- bool tmp_result = (((zcbor_map_start_encode(state, 10) && (((!(*input).record_bn_present || encode_repeated_record_bn(state, (&(*input).record_bn))) ++ bool tmp_result = (((zcbor_map_start_encode(state, ZCBOR_ARRAY_SIZE(input->record_key_value_pair_m)) && (((!(*input).record_bn_present || encode_repeated_record_bn(state, (&(*input).record_bn))) + && (!(*input).record_bt_present || encode_repeated_record_bt(state, (&(*input).record_bt))) + && (!(*input).record_n_present || encode_repeated_record_n(state, (&(*input).record_n))) + && (!(*input).record_t_present || encode_repeated_record_t(state, (&(*input).record_t))) + && (!(*input).record_union_present || encode_repeated_record_union(state, (&(*input).record_union))) +- && zcbor_multi_encode_minmax(0, 5, &(*input).record_key_value_pair_m_count, (zcbor_encoder_t *)encode_repeated_record_key_value_pair_m, state, (&(*input).record_key_value_pair_m), sizeof(struct record_key_value_pair_m))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_map_end_encode(state, 10)))); ++ && zcbor_multi_encode_minmax(0, ZCBOR_ARRAY_SIZE(input->record_key_value_pair_m), &(*input).record_key_value_pair_m_count, (zcbor_encoder_t *)encode_repeated_record_key_value_pair_m, state, (&(*input).record_key_value_pair_m), sizeof(struct record_key_value_pair_m))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_map_end_encode(state, ZCBOR_ARRAY_SIZE(input->record_key_value_pair_m))))); + + if (!tmp_result) { + zcbor_trace_file(state); +@@ -226,7 +222,7 @@ static bool encode_lwm2m_senml( { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); -- bool tmp_result = (((zcbor_list_start_encode(state, 99) && ((zcbor_multi_encode_minmax(1, 99, &(*input)._lwm2m_senml__record_count, (zcbor_encoder_t *)encode_record, state, (&(*input)._lwm2m_senml__record), sizeof(struct record))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_list_end_encode(state, 99)))); -+ bool tmp_result = (((zcbor_list_start_encode(state, ZCBOR_ARRAY_SIZE(input->_lwm2m_senml__record)) && ((zcbor_multi_encode_minmax(1, ZCBOR_ARRAY_SIZE(input->_lwm2m_senml__record), &(*input)._lwm2m_senml__record_count, (zcbor_encoder_t *)encode_record, state, (&(*input)._lwm2m_senml__record), sizeof(struct record))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_list_end_encode(state, ZCBOR_ARRAY_SIZE(input->_lwm2m_senml__record))))); +- bool tmp_result = (((zcbor_list_start_encode(state, 99) && ((zcbor_multi_encode_minmax(1, 99, &(*input).lwm2m_senml_record_m_count, (zcbor_encoder_t *)encode_record, state, (&(*input).lwm2m_senml_record_m), sizeof(struct record))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_list_end_encode(state, 99)))); ++ bool tmp_result = (((zcbor_list_start_encode(state, ZCBOR_ARRAY_SIZE(input->lwm2m_senml_record_m)) && ((zcbor_multi_encode_minmax(1, ZCBOR_ARRAY_SIZE(input->lwm2m_senml_record_m), &(*input).lwm2m_senml_record_m_count, (zcbor_encoder_t *)encode_record, state, (&(*input).lwm2m_senml_record_m), sizeof(struct record))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_list_end_encode(state, ZCBOR_ARRAY_SIZE(input->lwm2m_senml_record_m))))); - if (!tmp_result) - zcbor_trace(); + if (!tmp_result) { + zcbor_trace_file(state); diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.h b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.h -index b6c54afde5..cbc32e540c 100644 +index df2f0ac6a1..8fa1eedb2b 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.h +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.h @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 * - * Generated using zcbor version 0.7.0 + * Generated using zcbor version 0.8.0 - * https://github.com/NordicSemiconductor/zcbor + * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 */ -@@ -21,10 +21,6 @@ +@@ -21,11 +21,6 @@ extern "C" { #endif @@ -204,26 +134,36 @@ index b6c54afde5..cbc32e540c 100644 -#error "The type file was generated with a different default_max_qty than this file" -#endif - - +- int cbor_encode_lwm2m_senml( - uint8_t *payload, size_t payload_len, + uint8_t *payload, size_t payload_len, + const struct lwm2m_senml *input, diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_types.h b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_types.h -index e12f33636e..f709086a5c 100644 +index 77649036ef..f0a2958072 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_types.h +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_types.h @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 * - * Generated using zcbor version 0.7.0 + * Generated using zcbor version 0.8.0 - * https://github.com/NordicSemiconductor/zcbor + * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 */ -@@ -20,6 +20,18 @@ +@@ -20,14 +20,18 @@ extern "C" { #endif +-/** Which value for --default-max-qty this file was created with. +- * +- * The define is used in the other generated file to do a build-time +- * compatibility check. +- * +- * See `zcbor --help` for more information about --default-max-qty +- */ +-#define DEFAULT_MAX_QTY 99 ++ +enum lwm2m_senml_cbor_key { + lwm2m_senml_cbor_key_bn = -2, + lwm2m_senml_cbor_key_bt = -3, @@ -235,25 +175,15 @@ index e12f33636e..f709086a5c 100644 + lwm2m_senml_cbor_key_vb = 4, + lwm2m_senml_cbor_key_vd = 8, +}; -+ - /** Which value for --default-max-qty this file was created with. - * - * The define is used in the other generated file to do a build-time -@@ -27,7 +39,7 @@ extern "C" { - * - * See `zcbor --help` for more information about --default-max-qty - */ --#define DEFAULT_MAX_QTY 99 -+#define DEFAULT_MAX_QTY CONFIG_LWM2M_RW_SENML_CBOR_RECORDS struct record_bn { - struct zcbor_string _record_bn; -@@ -118,7 +130,7 @@ struct record { + struct zcbor_string record_bn; +@@ -118,7 +122,7 @@ struct record { }; struct lwm2m_senml { -- struct record _lwm2m_senml__record[99]; -+ struct record _lwm2m_senml__record[DEFAULT_MAX_QTY]; - size_t _lwm2m_senml__record_count; +- struct record lwm2m_senml_record_m[99]; ++ struct record lwm2m_senml_record_m[CONFIG_LWM2M_RW_SENML_CBOR_RECORDS]; + size_t lwm2m_senml_record_m_count; }; diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.c b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.c index a75aee02120..3906d476cac 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.c +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: Apache-2.0 * - * Generated using zcbor version 0.7.0 + * Generated using zcbor version 0.8.0 * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 */ @@ -14,28 +14,32 @@ #include #include "zcbor_decode.h" #include "lwm2m_senml_cbor_decode.h" +#include "zcbor_print.h" static bool decode_repeated_record_bn(zcbor_state_t *state, struct record_bn *result); static bool decode_repeated_record_bt(zcbor_state_t *state, struct record_bt *result); static bool decode_repeated_record_n(zcbor_state_t *state, struct record_n *result); static bool decode_repeated_record_t(zcbor_state_t *state, struct record_t *result); -static bool decode_repeated_record_union(zcbor_state_t *state, struct record_union_ *result); -static bool decode_value(zcbor_state_t *state, struct value_ *result); +static bool decode_repeated_record_union(zcbor_state_t *state, struct record_union_r *result); +static bool decode_value(zcbor_state_t *state, struct value_r *result); static bool decode_key_value_pair(zcbor_state_t *state, struct key_value_pair *result); -static bool decode_repeated_record__key_value_pair(zcbor_state_t *state, - struct record__key_value_pair *result); +static bool decode_repeated_record_key_value_pair_m(zcbor_state_t *state, + struct record_key_value_pair_m *result); static bool decode_record(zcbor_state_t *state, struct record *result); static bool decode_lwm2m_senml(zcbor_state_t *state, struct lwm2m_senml *result); static bool decode_repeated_record_bn(zcbor_state_t *state, struct record_bn *result) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); bool tmp_result = ((((zcbor_int32_expect(state, (-2)))) && - (zcbor_tstr_decode(state, (&(*result)._record_bn))))); + (zcbor_tstr_decode(state, (&(*result).record_bn))))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; @@ -43,16 +47,19 @@ static bool decode_repeated_record_bn(zcbor_state_t *state, struct record_bn *re static bool decode_repeated_record_bt(zcbor_state_t *state, struct record_bt *result) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); bool tmp_result = ((((zcbor_int32_expect(state, (-3)))) && - (zcbor_int64_decode(state, (&(*result)._record_bt))) && - ((((*result)._record_bt >= INT64_MIN) && ((*result)._record_bt <= INT64_MAX)) || + (zcbor_int64_decode(state, (&(*result).record_bt))) && + ((((*result).record_bt >= INT64_MIN) && ((*result).record_bt <= INT64_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; @@ -60,13 +67,16 @@ static bool decode_repeated_record_bt(zcbor_state_t *state, struct record_bt *re static bool decode_repeated_record_n(zcbor_state_t *state, struct record_n *result) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); bool tmp_result = ((((zcbor_uint32_expect(state, (0)))) && - (zcbor_tstr_decode(state, (&(*result)._record_n))))); + (zcbor_tstr_decode(state, (&(*result).record_n))))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; @@ -74,86 +84,94 @@ static bool decode_repeated_record_n(zcbor_state_t *state, struct record_n *resu static bool decode_repeated_record_t(zcbor_state_t *state, struct record_t *result) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); bool tmp_result = ((((zcbor_uint32_expect(state, (6)))) && - (zcbor_int64_decode(state, (&(*result)._record_t))) && - ((((*result)._record_t >= INT64_MIN) && ((*result)._record_t <= INT64_MAX)) || + (zcbor_int64_decode(state, (&(*result).record_t))) && + ((((*result).record_t >= INT64_MIN) && ((*result).record_t <= INT64_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; } -static bool decode_repeated_record_union(zcbor_state_t *state, struct record_union_ *result) +static bool decode_repeated_record_union(zcbor_state_t *state, struct record_union_r *result) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); struct zcbor_string tmp_str; bool int_res; bool tmp_result = (((zcbor_union_start_code(state) && (int_res = (((((zcbor_uint32_expect_union(state, (2)))) && - (zcbor_int64_decode(state, (&(*result)._union_vi))) && - ((((*result)._union_vi >= INT64_MIN) && - ((*result)._union_vi <= INT64_MAX)) || + (zcbor_int64_decode(state, (&(*result).union_vi))) && + ((((*result).union_vi >= INT64_MIN) && + ((*result).union_vi <= INT64_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) && - (((*result)._record_union_choice = _union_vi), true)) || + (((*result).record_union_choice = union_vi_c), true)) || ((((zcbor_uint32_expect_union(state, (2)))) && - (zcbor_float_decode(state, (&(*result)._union_vf)))) && - (((*result)._record_union_choice = _union_vf), true)) || + (zcbor_float_decode(state, (&(*result).union_vf)))) && + (((*result).record_union_choice = union_vf_c), true)) || ((((zcbor_uint32_expect_union(state, (3)))) && - (zcbor_tstr_decode(state, (&(*result)._union_vs)))) && - (((*result)._record_union_choice = _union_vs), true)) || + (zcbor_tstr_decode(state, (&(*result).union_vs)))) && + (((*result).record_union_choice = union_vs_c), true)) || ((((zcbor_uint32_expect_union(state, (4)))) && - (zcbor_bool_decode(state, (&(*result)._union_vb)))) && - (((*result)._record_union_choice = _union_vb), true)) || + (zcbor_bool_decode(state, (&(*result).union_vb)))) && + (((*result).record_union_choice = union_vb_c), true)) || ((((zcbor_uint32_expect_union(state, (8)))) && - (zcbor_bstr_decode(state, (&(*result)._union_vd)))) && - (((*result)._record_union_choice = _union_vd), true)) || + (zcbor_bstr_decode(state, (&(*result).union_vd)))) && + (((*result).record_union_choice = union_vd_c), true)) || (zcbor_union_elem_code(state) && ((((zcbor_tstr_expect( state, ((tmp_str.value = (uint8_t *)"vlo", tmp_str.len = sizeof("vlo") - 1, &tmp_str))))) && - (zcbor_tstr_decode(state, (&(*result)._union_vlo)))) && - (((*result)._record_union_choice = _union_vlo), true)))), + (zcbor_tstr_decode(state, (&(*result).union_vlo)))) && + (((*result).record_union_choice = union_vlo_c), true)))), zcbor_union_end_code(state), int_res)))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; } -static bool decode_value(zcbor_state_t *state, struct value_ *result) +static bool decode_value(zcbor_state_t *state, struct value_r *result) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); bool int_res; - bool tmp_result = - (((zcbor_union_start_code(state) && - (int_res = ((((zcbor_tstr_decode(state, (&(*result)._value_tstr)))) && - (((*result)._value_choice = _value_tstr), true)) || - (((zcbor_bstr_decode(state, (&(*result)._value_bstr)))) && - (((*result)._value_choice = _value_bstr), true)) || - (((zcbor_int64_decode(state, (&(*result)._value_int))) && - ((((*result)._value_int >= INT64_MIN) && - ((*result)._value_int <= INT64_MAX)) || - (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) && - (((*result)._value_choice = _value_int), true)) || - (((zcbor_float_decode(state, (&(*result)._value_float)))) && - (((*result)._value_choice = _value_float), true)) || - (((zcbor_bool_decode(state, (&(*result)._value_bool)))) && - (((*result)._value_choice = _value_bool), true))), - zcbor_union_end_code(state), int_res)))); + bool tmp_result = (((zcbor_union_start_code(state) && + (int_res = ((((zcbor_tstr_decode(state, (&(*result).value_tstr)))) && + (((*result).value_choice = value_tstr_c), true)) || + (((zcbor_bstr_decode(state, (&(*result).value_bstr)))) && + (((*result).value_choice = value_bstr_c), true)) || + (((zcbor_int64_decode(state, (&(*result).value_int))) && + ((((*result).value_int >= INT64_MIN) && + ((*result).value_int <= INT64_MAX)) || + (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false))) && + (((*result).value_choice = value_int_c), true)) || + (((zcbor_float_decode(state, (&(*result).value_float)))) && + (((*result).value_choice = value_float_c), true)) || + (((zcbor_bool_decode(state, (&(*result).value_bool)))) && + (((*result).value_choice = value_bool_c), true))), + zcbor_union_end_code(state), int_res)))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; @@ -161,27 +179,33 @@ static bool decode_value(zcbor_state_t *state, struct value_ *result) static bool decode_key_value_pair(zcbor_state_t *state, struct key_value_pair *result) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); - bool tmp_result = ((((zcbor_int32_decode(state, (&(*result)._key_value_pair_key)))) && - (decode_value(state, (&(*result)._key_value_pair))))); + bool tmp_result = ((((zcbor_int32_decode(state, (&(*result).key_value_pair_key)))) && + (decode_value(state, (&(*result).key_value_pair))))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; } -static bool decode_repeated_record__key_value_pair(zcbor_state_t *state, - struct record__key_value_pair *result) +static bool decode_repeated_record_key_value_pair_m(zcbor_state_t *state, + struct record_key_value_pair_m *result) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); - bool tmp_result = (((decode_key_value_pair(state, (&(*result)._record__key_value_pair))))); + bool tmp_result = (((decode_key_value_pair(state, (&(*result).record_key_value_pair_m))))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; @@ -189,35 +213,38 @@ static bool decode_repeated_record__key_value_pair(zcbor_state_t *state, static bool decode_record(zcbor_state_t *state, struct record *result) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); bool tmp_result = (((zcbor_map_start_decode(state) && - ((zcbor_present_decode(&((*result)._record_bn_present), + ((zcbor_present_decode(&((*result).record_bn_present), (zcbor_decoder_t *)decode_repeated_record_bn, state, - (&(*result)._record_bn)) && - zcbor_present_decode(&((*result)._record_bt_present), + (&(*result).record_bn)) && + zcbor_present_decode(&((*result).record_bt_present), (zcbor_decoder_t *)decode_repeated_record_bt, state, - (&(*result)._record_bt)) && - zcbor_present_decode(&((*result)._record_n_present), + (&(*result).record_bt)) && + zcbor_present_decode(&((*result).record_n_present), (zcbor_decoder_t *)decode_repeated_record_n, state, - (&(*result)._record_n)) && - zcbor_present_decode(&((*result)._record_t_present), + (&(*result).record_n)) && + zcbor_present_decode(&((*result).record_t_present), (zcbor_decoder_t *)decode_repeated_record_t, state, - (&(*result)._record_t)) && - zcbor_present_decode(&((*result)._record_union_present), + (&(*result).record_t)) && + zcbor_present_decode(&((*result).record_union_present), (zcbor_decoder_t *)decode_repeated_record_union, state, - (&(*result)._record_union)) && - zcbor_multi_decode(0, ZCBOR_ARRAY_SIZE(result->_record__key_value_pair), - &(*result)._record__key_value_pair_count, - (zcbor_decoder_t *)decode_repeated_record__key_value_pair, - state, (&(*result)._record__key_value_pair), - sizeof(struct record__key_value_pair))) || + (&(*result).record_union)) && + zcbor_multi_decode(0, ZCBOR_ARRAY_SIZE(result->record_key_value_pair_m), + &(*result).record_key_value_pair_m_count, + (zcbor_decoder_t *)decode_repeated_record_key_value_pair_m, + state, (&(*result).record_key_value_pair_m), + sizeof(struct record_key_value_pair_m))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_map_end_decode(state)))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; @@ -225,19 +252,22 @@ static bool decode_record(zcbor_state_t *state, struct record *result) static bool decode_lwm2m_senml(zcbor_state_t *state, struct lwm2m_senml *result) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); bool tmp_result = (((zcbor_list_start_decode(state) && ((zcbor_multi_decode( - 1, ZCBOR_ARRAY_SIZE(result->_lwm2m_senml__record), - &(*result)._lwm2m_senml__record_count, (zcbor_decoder_t *)decode_record, - state, (&(*result)._lwm2m_senml__record), sizeof(struct record))) || + 1, ZCBOR_ARRAY_SIZE(result->lwm2m_senml_record_m), + &(*result).lwm2m_senml_record_m_count, (zcbor_decoder_t *)decode_record, + state, (&(*result).lwm2m_senml_record_m), sizeof(struct record))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_list_end_decode(state)))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; @@ -248,19 +278,7 @@ int cbor_decode_lwm2m_senml(const uint8_t *payload, size_t payload_len, struct l { zcbor_state_t states[5]; - zcbor_new_state(states, sizeof(states) / sizeof(zcbor_state_t), payload, payload_len, 1); - - bool ret = decode_lwm2m_senml(states, result); - - if (ret && (payload_len_out != NULL)) { - *payload_len_out = MIN(payload_len, (size_t)states[0].payload - (size_t)payload); - } - - if (!ret) { - int err = zcbor_pop_error(states); - - zcbor_print("Return error: %d\r\n", err); - return (err == ZCBOR_SUCCESS) ? ZCBOR_ERR_UNKNOWN : err; - } - return ZCBOR_SUCCESS; + return zcbor_entry_function(payload, payload_len, (void *)result, payload_len_out, states, + (zcbor_decoder_t *)decode_lwm2m_senml, + sizeof(states) / sizeof(zcbor_state_t), 1); } diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.h b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.h index a8ae779b6a1..b47b79de615 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.h +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_decode.h @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: Apache-2.0 * - * Generated using zcbor version 0.7.0 + * Generated using zcbor version 0.8.0 * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 */ diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.c b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.c index 74c9310941b..9cf4f3457c6 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.c +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.c @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: Apache-2.0 * - * Generated using zcbor version 0.7.0 + * Generated using zcbor version 0.8.0 * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 */ @@ -14,28 +14,32 @@ #include #include "zcbor_encode.h" #include "lwm2m_senml_cbor_encode.h" +#include "zcbor_print.h" static bool encode_repeated_record_bn(zcbor_state_t *state, const struct record_bn *input); static bool encode_repeated_record_bt(zcbor_state_t *state, const struct record_bt *input); static bool encode_repeated_record_n(zcbor_state_t *state, const struct record_n *input); static bool encode_repeated_record_t(zcbor_state_t *state, const struct record_t *input); -static bool encode_repeated_record_union(zcbor_state_t *state, const struct record_union_ *input); -static bool encode_value(zcbor_state_t *state, const struct value_ *input); +static bool encode_repeated_record_union(zcbor_state_t *state, const struct record_union_r *input); +static bool encode_value(zcbor_state_t *state, const struct value_r *input); static bool encode_key_value_pair(zcbor_state_t *state, const struct key_value_pair *input); -static bool encode_repeated_record__key_value_pair(zcbor_state_t *state, - const struct record__key_value_pair *input); +static bool encode_repeated_record_key_value_pair_m(zcbor_state_t *state, + const struct record_key_value_pair_m *input); static bool encode_record(zcbor_state_t *state, const struct record *input); static bool encode_lwm2m_senml(zcbor_state_t *state, const struct lwm2m_senml *input); static bool encode_repeated_record_bn(zcbor_state_t *state, const struct record_bn *input) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); bool tmp_result = ((((zcbor_int32_put(state, (-2)))) && - (zcbor_tstr_encode(state, (&(*input)._record_bn))))); + (zcbor_tstr_encode(state, (&(*input).record_bn))))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; @@ -43,16 +47,19 @@ static bool encode_repeated_record_bn(zcbor_state_t *state, const struct record_ static bool encode_repeated_record_bt(zcbor_state_t *state, const struct record_bt *input) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); bool tmp_result = ((((zcbor_int32_put(state, (-3)))) && - ((((*input)._record_bt >= INT64_MIN) && ((*input)._record_bt <= INT64_MAX)) || + ((((*input).record_bt >= INT64_MIN) && ((*input).record_bt <= INT64_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) && - (zcbor_int64_encode(state, (&(*input)._record_bt))))); + (zcbor_int64_encode(state, (&(*input).record_bt))))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; @@ -60,13 +67,16 @@ static bool encode_repeated_record_bt(zcbor_state_t *state, const struct record_ static bool encode_repeated_record_n(zcbor_state_t *state, const struct record_n *input) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); bool tmp_result = ((((zcbor_uint32_put(state, (0)))) && - (zcbor_tstr_encode(state, (&(*input)._record_n))))); + (zcbor_tstr_encode(state, (&(*input).record_n))))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; @@ -74,81 +84,98 @@ static bool encode_repeated_record_n(zcbor_state_t *state, const struct record_n static bool encode_repeated_record_t(zcbor_state_t *state, const struct record_t *input) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); bool tmp_result = ((((zcbor_uint32_put(state, (6)))) && - ((((*input)._record_t >= INT64_MIN) && ((*input)._record_t <= INT64_MAX)) || + ((((*input).record_t >= INT64_MIN) && ((*input).record_t <= INT64_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) && - (zcbor_int64_encode(state, (&(*input)._record_t))))); + (zcbor_int64_encode(state, (&(*input).record_t))))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; } -static bool encode_repeated_record_union(zcbor_state_t *state, const struct record_union_ *input) +static bool encode_repeated_record_union(zcbor_state_t *state, const struct record_union_r *input) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); struct zcbor_string tmp_str; bool tmp_result = ((( - ((*input)._record_union_choice == _union_vi) + ((*input).record_union_choice == union_vi_c) ? (((zcbor_uint32_put(state, (2)))) && - ((((*input)._union_vi >= INT64_MIN) && - ((*input)._union_vi <= INT64_MAX)) || + ((((*input).union_vi >= INT64_MIN) && + ((*input).union_vi <= INT64_MAX)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) && - (zcbor_int64_encode(state, (&(*input)._union_vi)))) - : (((*input)._record_union_choice == _union_vf) - ? (((zcbor_uint32_put(state, (2)))) && - (zcbor_float64_encode(state, (&(*input)._union_vf)))) - : (((*input)._record_union_choice == _union_vs) - ? (((zcbor_uint32_put(state, (3)))) && - (zcbor_tstr_encode(state, (&(*input)._union_vs)))) - : (((*input)._record_union_choice == _union_vb) - ? (((zcbor_uint32_put(state, (4)))) && - (zcbor_bool_encode(state, (&(*input)._union_vb)))) - : (((*input)._record_union_choice == _union_vd) - ? (((zcbor_uint32_put(state, (8)))) && - (zcbor_bstr_encode(state, (&(*input)._union_vd)))) - : (((*input)._record_union_choice == _union_vlo) - ? (((zcbor_tstr_encode(state, ((tmp_str.value = (uint8_t *)"vlo", - tmp_str.len = sizeof("vlo") - 1, - &tmp_str))))) && - (zcbor_tstr_encode(state, (&(*input)._union_vlo)))) - : false)))))))); + (zcbor_int64_encode(state, (&(*input).union_vi)))) + : (((*input).record_union_choice == union_vf_c) + ? (((zcbor_uint32_put(state, (2)))) && + (zcbor_float64_encode(state, (&(*input).union_vf)))) + : (((*input).record_union_choice == union_vs_c) + ? (((zcbor_uint32_put(state, (3)))) && + (zcbor_tstr_encode(state, (&(*input).union_vs)))) + : (((*input).record_union_choice == union_vb_c) + ? (((zcbor_uint32_put(state, (4)))) && + (zcbor_bool_encode(state, (&(*input).union_vb)))) + : (((*input).record_union_choice == union_vd_c) + ? (((zcbor_uint32_put(state, (8)))) && + (zcbor_bstr_encode(state, (&(*input).union_vd)))) + : (((*input).record_union_choice == union_vlo_c) + ? (((zcbor_tstr_encode( + state, + ((tmp_str.value = (uint8_t *)"vlo", + tmp_str.len = sizeof("vlo") - 1, + &tmp_str))))) && + (zcbor_tstr_encode( + state, + (&(*input).union_vlo)))) + : false)))))))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; } -static bool encode_value(zcbor_state_t *state, const struct value_ *input) +static bool encode_value(zcbor_state_t *state, const struct value_r *input) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); bool tmp_result = ((( - ((*input)._value_choice == _value_tstr) - ? ((zcbor_tstr_encode(state, (&(*input)._value_tstr)))) - : (((*input)._value_choice == _value_bstr) - ? ((zcbor_bstr_encode(state, (&(*input)._value_bstr)))) - : (((*input)._value_choice == _value_int) - ? (((((*input)._value_int >= INT64_MIN) && - ((*input)._value_int <= INT64_MAX)) || - (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)) && - (zcbor_int64_encode(state, (&(*input)._value_int)))) - : (((*input)._value_choice == _value_float) - ? ((zcbor_float64_encode(state, (&(*input)._value_float)))) - : (((*input)._value_choice == _value_bool) - ? ((zcbor_bool_encode(state, (&(*input)._value_bool)))) - : false))))))); + ((*input).value_choice == value_tstr_c) + ? ((zcbor_tstr_encode(state, (&(*input).value_tstr)))) + : (((*input).value_choice == value_bstr_c) + ? ((zcbor_bstr_encode(state, (&(*input).value_bstr)))) + : (((*input).value_choice == value_int_c) + ? (((((*input).value_int >= INT64_MIN) && + ((*input).value_int <= INT64_MAX)) || + (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), + false)) && + (zcbor_int64_encode(state, (&(*input).value_int)))) + : (((*input).value_choice == value_float_c) + ? ((zcbor_float64_encode( + state, (&(*input).value_float)))) + : (((*input).value_choice == value_bool_c) + ? ((zcbor_bool_encode( + state, + (&(*input).value_bool)))) + : false))))))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; @@ -156,27 +183,33 @@ static bool encode_value(zcbor_state_t *state, const struct value_ *input) static bool encode_key_value_pair(zcbor_state_t *state, const struct key_value_pair *input) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); - bool tmp_result = ((((zcbor_int32_encode(state, (&(*input)._key_value_pair_key)))) && - (encode_value(state, (&(*input)._key_value_pair))))); + bool tmp_result = ((((zcbor_int32_encode(state, (&(*input).key_value_pair_key)))) && + (encode_value(state, (&(*input).key_value_pair))))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; } -static bool encode_repeated_record__key_value_pair(zcbor_state_t *state, - const struct record__key_value_pair *input) +static bool encode_repeated_record_key_value_pair_m(zcbor_state_t *state, + const struct record_key_value_pair_m *input) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); - bool tmp_result = (((encode_key_value_pair(state, (&(*input)._record__key_value_pair))))); + bool tmp_result = (((encode_key_value_pair(state, (&(*input).record_key_value_pair_m))))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; @@ -184,36 +217,34 @@ static bool encode_repeated_record__key_value_pair(zcbor_state_t *state, static bool encode_record(zcbor_state_t *state, const struct record *input) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); bool tmp_result = (( - (zcbor_map_start_encode(state, ZCBOR_ARRAY_SIZE(input->_record__key_value_pair)) && - ((zcbor_present_encode(&((*input)._record_bn_present), - (zcbor_encoder_t *)encode_repeated_record_bn, state, - (&(*input)._record_bn)) && - zcbor_present_encode(&((*input)._record_bt_present), - (zcbor_encoder_t *)encode_repeated_record_bt, state, - (&(*input)._record_bt)) && - zcbor_present_encode(&((*input)._record_n_present), - (zcbor_encoder_t *)encode_repeated_record_n, state, - (&(*input)._record_n)) && - zcbor_present_encode(&((*input)._record_t_present), - (zcbor_encoder_t *)encode_repeated_record_t, state, - (&(*input)._record_t)) && - zcbor_present_encode(&((*input)._record_union_present), - (zcbor_encoder_t *)encode_repeated_record_union, state, - (&(*input)._record_union)) && + (zcbor_map_start_encode(state, ZCBOR_ARRAY_SIZE(input->record_key_value_pair_m)) && + (((!(*input).record_bn_present || + encode_repeated_record_bn(state, (&(*input).record_bn))) && + (!(*input).record_bt_present || + encode_repeated_record_bt(state, (&(*input).record_bt))) && + (!(*input).record_n_present || + encode_repeated_record_n(state, (&(*input).record_n))) && + (!(*input).record_t_present || + encode_repeated_record_t(state, (&(*input).record_t))) && + (!(*input).record_union_present || + encode_repeated_record_union(state, (&(*input).record_union))) && zcbor_multi_encode_minmax( - 0, ZCBOR_ARRAY_SIZE(input->_record__key_value_pair), - &(*input)._record__key_value_pair_count, - (zcbor_encoder_t *)encode_repeated_record__key_value_pair, state, - (&(*input)._record__key_value_pair), - sizeof(struct record__key_value_pair))) || + 0, ZCBOR_ARRAY_SIZE(input->record_key_value_pair_m), + &(*input).record_key_value_pair_m_count, + (zcbor_encoder_t *)encode_repeated_record_key_value_pair_m, state, + (&(*input).record_key_value_pair_m), + sizeof(struct record_key_value_pair_m))) || (zcbor_list_map_end_force_encode(state), false)) && - zcbor_map_end_encode(state, ZCBOR_ARRAY_SIZE(input->_record__key_value_pair))))); + zcbor_map_end_encode(state, ZCBOR_ARRAY_SIZE(input->record_key_value_pair_m))))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; @@ -221,19 +252,22 @@ static bool encode_record(zcbor_state_t *state, const struct record *input) static bool encode_lwm2m_senml(zcbor_state_t *state, const struct lwm2m_senml *input) { - zcbor_print("%s\r\n", __func__); + zcbor_log("%s\r\n", __func__); bool tmp_result = - (((zcbor_list_start_encode(state, ZCBOR_ARRAY_SIZE(input->_lwm2m_senml__record)) && + (((zcbor_list_start_encode(state, ZCBOR_ARRAY_SIZE(input->lwm2m_senml_record_m)) && ((zcbor_multi_encode_minmax( - 1, ZCBOR_ARRAY_SIZE(input->_lwm2m_senml__record), - &(*input)._lwm2m_senml__record_count, (zcbor_encoder_t *)encode_record, - state, (&(*input)._lwm2m_senml__record), sizeof(struct record))) || + 1, ZCBOR_ARRAY_SIZE(input->lwm2m_senml_record_m), + &(*input).lwm2m_senml_record_m_count, (zcbor_encoder_t *)encode_record, + state, (&(*input).lwm2m_senml_record_m), sizeof(struct record))) || (zcbor_list_map_end_force_encode(state), false)) && - zcbor_list_end_encode(state, ZCBOR_ARRAY_SIZE(input->_lwm2m_senml__record))))); + zcbor_list_end_encode(state, ZCBOR_ARRAY_SIZE(input->lwm2m_senml_record_m))))); if (!tmp_result) { - zcbor_trace(); + zcbor_trace_file(state); + zcbor_log("%s error: %s\r\n", __func__, zcbor_error_str(zcbor_peek_error(state))); + } else { + zcbor_log("%s success\r\n", __func__); } return tmp_result; @@ -244,19 +278,7 @@ int cbor_encode_lwm2m_senml(uint8_t *payload, size_t payload_len, const struct l { zcbor_state_t states[5]; - zcbor_new_state(states, sizeof(states) / sizeof(zcbor_state_t), payload, payload_len, 1); - - bool ret = encode_lwm2m_senml(states, input); - - if (ret && (payload_len_out != NULL)) { - *payload_len_out = MIN(payload_len, (size_t)states[0].payload - (size_t)payload); - } - - if (!ret) { - int err = zcbor_pop_error(states); - - zcbor_print("Return error: %d\r\n", err); - return (err == ZCBOR_SUCCESS) ? ZCBOR_ERR_UNKNOWN : err; - } - return ZCBOR_SUCCESS; + return zcbor_entry_function(payload, payload_len, (void *)input, payload_len_out, states, + (zcbor_decoder_t *)encode_lwm2m_senml, + sizeof(states) / sizeof(zcbor_state_t), 1); } diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.h b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.h index 05d2664c2a0..49ce5c55159 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.h +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_encode.h @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: Apache-2.0 * - * Generated using zcbor version 0.7.0 + * Generated using zcbor version 0.8.0 * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 */ diff --git a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_types.h b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_types.h index f1b86bb60b0..4c41385ba4b 100644 --- a/subsys/net/lib/lwm2m/lwm2m_senml_cbor_types.h +++ b/subsys/net/lib/lwm2m/lwm2m_senml_cbor_types.h @@ -3,7 +3,7 @@ * * SPDX-License-Identifier: Apache-2.0 * - * Generated using zcbor version 0.7.0 + * Generated using zcbor version 0.8.0 * https://github.com/zephyrproject-rtos/zcbor * Generated with a --default-max-qty of 99 */ @@ -32,115 +32,97 @@ enum lwm2m_senml_cbor_key { lwm2m_senml_cbor_key_vd = 8, }; -/** Which value for --default-max-qty this file was created with. - * - * The define is used in the other generated file to do a build-time - * compatibility check. - * - * See `zcbor --help` for more information about --default-max-qty - */ -#define DEFAULT_MAX_QTY CONFIG_LWM2M_RW_SENML_CBOR_RECORDS - struct record_bn { - struct zcbor_string _record_bn; + struct zcbor_string record_bn; }; struct record_bt { - int64_t _record_bt; + int64_t record_bt; }; struct record_n { - struct zcbor_string _record_n; + struct zcbor_string record_n; }; struct record_t { - int64_t _record_t; + int64_t record_t; }; -/* The union members and enum members have the same names. - * This is intentional so we need to ignore -Wshadow to avoid - * compiler complaining about them. - */ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wshadow" - -struct record_union_ { +struct record_union_r { union { struct { - int64_t _union_vi; + int64_t union_vi; }; struct { - double _union_vf; + double union_vf; }; struct { - struct zcbor_string _union_vs; + struct zcbor_string union_vs; }; struct { - bool _union_vb; + bool union_vb; }; struct { - struct zcbor_string _union_vd; + struct zcbor_string union_vd; }; struct { - struct zcbor_string _union_vlo; + struct zcbor_string union_vlo; }; }; enum { - _union_vi, - _union_vf, - _union_vs, - _union_vb, - _union_vd, - _union_vlo, - } _record_union_choice; + union_vi_c, + union_vf_c, + union_vs_c, + union_vb_c, + union_vd_c, + union_vlo_c, + } record_union_choice; }; -struct value_ { +struct value_r { union { - struct zcbor_string _value_tstr; - struct zcbor_string _value_bstr; - int64_t _value_int; - double _value_float; - bool _value_bool; + struct zcbor_string value_tstr; + struct zcbor_string value_bstr; + int64_t value_int; + double value_float; + bool value_bool; }; enum { - _value_tstr, - _value_bstr, - _value_int, - _value_float, - _value_bool, - } _value_choice; + value_tstr_c, + value_bstr_c, + value_int_c, + value_float_c, + value_bool_c, + } value_choice; }; -#pragma GCC diagnostic pop - struct key_value_pair { - int32_t _key_value_pair_key; - struct value_ _key_value_pair; + int32_t key_value_pair_key; + struct value_r key_value_pair; }; -struct record__key_value_pair { - struct key_value_pair _record__key_value_pair; +struct record_key_value_pair_m { + struct key_value_pair record_key_value_pair_m; }; struct record { - struct record_bn _record_bn; - bool _record_bn_present; - struct record_bt _record_bt; - bool _record_bt_present; - struct record_n _record_n; - bool _record_n_present; - struct record_t _record_t; - bool _record_t_present; - struct record_union_ _record_union; - bool _record_union_present; - struct record__key_value_pair _record__key_value_pair[5]; - size_t _record__key_value_pair_count; + struct record_bn record_bn; + bool record_bn_present; + struct record_bt record_bt; + bool record_bt_present; + struct record_n record_n; + bool record_n_present; + struct record_t record_t; + bool record_t_present; + struct record_union_r record_union; + bool record_union_present; + struct record_key_value_pair_m record_key_value_pair_m[5]; + size_t record_key_value_pair_m_count; }; struct lwm2m_senml { - struct record _lwm2m_senml__record[DEFAULT_MAX_QTY]; - size_t _lwm2m_senml__record_count; + struct record lwm2m_senml_record_m[CONFIG_LWM2M_RW_SENML_CBOR_RECORDS]; + size_t lwm2m_senml_record_m_count; }; #ifdef __cplusplus From 2aefab6fd8e9b4f1fd02bfff6dba595d2a2ad68d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20R=C3=B8nningstad?= Date: Wed, 10 Jan 2024 14:39:42 +0100 Subject: [PATCH 6/7] [nrf fromlist] mgmt: Adapt to API changes in zcbor 0.8.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit zcbor_new_state and zcbor_tstr_put_term Signed-off-by: Øyvind Rønningstad --- include/zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt_client.h | 3 ++- subsys/mgmt/mcumgr/grp/fs_mgmt/src/fs_mgmt.c | 2 +- subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c | 4 ++-- .../mgmt/mcumgr/grp/img_mgmt_client/src/img_mgmt_client.c | 6 +++--- subsys/mgmt/mcumgr/grp/os_mgmt/src/os_mgmt.c | 2 +- .../mgmt/mcumgr/grp/os_mgmt_client/src/os_mgmt_client.c | 7 ++++--- subsys/mgmt/mcumgr/grp/stat_mgmt/Kconfig | 8 ++++++++ subsys/mgmt/mcumgr/grp/stat_mgmt/src/stat_mgmt.c | 4 ++-- subsys/mgmt/mcumgr/smp/src/smp.c | 4 ++-- 9 files changed, 25 insertions(+), 15 deletions(-) diff --git a/include/zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt_client.h b/include/zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt_client.h index 0b12ccdb684..ba63c136f50 100644 --- a/include/zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt_client.h +++ b/include/zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt_client.h @@ -45,11 +45,12 @@ void os_mgmt_client_init(struct os_mgmt_client *client, struct smp_client_object * * @param client OS mgmt client object * @param echo_string Echo string + * @param max_len Max length of @p echo_string * * @return 0 on success. * @return @ref mcumgr_err_t code on failure. */ -int os_mgmt_client_echo(struct os_mgmt_client *client, const char *echo_string); +int os_mgmt_client_echo(struct os_mgmt_client *client, const char *echo_string, size_t max_len); /** * @brief Send SMP Reset command. diff --git a/subsys/mgmt/mcumgr/grp/fs_mgmt/src/fs_mgmt.c b/subsys/mgmt/mcumgr/grp/fs_mgmt/src/fs_mgmt.c index 3458c3d6f8b..ae75aea9140 100644 --- a/subsys/mgmt/mcumgr/grp/fs_mgmt/src/fs_mgmt.c +++ b/subsys/mgmt/mcumgr/grp/fs_mgmt/src/fs_mgmt.c @@ -783,7 +783,7 @@ static int fs_mgmt_file_hash_checksum(struct smp_streamer *ctxt) } ok &= zcbor_tstr_put_lit(zse, "type") && - zcbor_tstr_put_term(zse, type_arr); + zcbor_tstr_put_term(zse, type_arr, sizeof(type_arr)); if (off != 0) { ok &= zcbor_tstr_put_lit(zse, "off") && diff --git a/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c b/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c index 61515c14655..edfe26e452f 100644 --- a/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c +++ b/subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c @@ -443,11 +443,11 @@ static bool img_mgmt_state_encode_slot(zcbor_state_t *zse, uint32_t slot, int st ok = zcbor_tstr_put_lit(zse, "<\?\?\?>"); } else { vers_str[sizeof(vers_str) - 1] = '\0'; - ok = zcbor_tstr_put_term(zse, vers_str); + ok = zcbor_tstr_put_term(zse, vers_str, sizeof(vers_str)); } } - ok = ok && zcbor_tstr_put_term(zse, "hash") && + ok = ok && zcbor_tstr_put_lit(zse, "hash") && zcbor_bstr_encode(zse, &zhash) && ZCBOR_ENCODE_FLAG(zse, "bootable", !(flags & IMAGE_F_NON_BOOTABLE)) && ZCBOR_ENCODE_FLAG(zse, "pending", state_flags & REPORT_SLOT_PENDING) && diff --git a/subsys/mgmt/mcumgr/grp/img_mgmt_client/src/img_mgmt_client.c b/subsys/mgmt/mcumgr/grp/img_mgmt_client/src/img_mgmt_client.c index 9ab8ee02dcd..b8cbc38b275 100644 --- a/subsys/mgmt/mcumgr/grp/img_mgmt_client/src/img_mgmt_client.c +++ b/subsys/mgmt/mcumgr/grp/img_mgmt_client/src/img_mgmt_client.c @@ -74,7 +74,7 @@ static int image_state_res_fn(struct net_buf *nb, void *user_data) goto out; } - zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_start_decode(zsd); if (!ok) { @@ -201,7 +201,7 @@ static int image_upload_res_fn(struct net_buf *nb, void *user_data) goto end; } - zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data, nb->len, 1, NULL, 0); rc = zcbor_map_decode_bulk(zsd, upload_res_decode, ARRAY_SIZE(upload_res_decode), &decoded); if (rc || image_upload_buf->image_upload_offset == SIZE_MAX) { @@ -233,7 +233,7 @@ static int erase_res_fn(struct net_buf *nb, void *user_data) goto end; } - zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data, nb->len, 1, NULL, 0); rc = zcbor_map_decode_bulk(zsd, upload_res_decode, ARRAY_SIZE(upload_res_decode), &decoded); if (rc) { diff --git a/subsys/mgmt/mcumgr/grp/os_mgmt/src/os_mgmt.c b/subsys/mgmt/mcumgr/grp/os_mgmt/src/os_mgmt.c index 13de45f02a9..d5244cb07d8 100644 --- a/subsys/mgmt/mcumgr/grp/os_mgmt/src/os_mgmt.c +++ b/subsys/mgmt/mcumgr/grp/os_mgmt/src/os_mgmt.c @@ -207,7 +207,7 @@ os_mgmt_taskstat_encode_thread_name(zcbor_state_t *zse, int idx, snprintf(thread_name, sizeof(thread_name) - 1, "%d", idx); thread_name[sizeof(thread_name) - 1] = 0; - return zcbor_tstr_put_term(zse, thread_name); + return zcbor_tstr_put_term(zse, thread_name, sizeof(thread_name)); } #endif diff --git a/subsys/mgmt/mcumgr/grp/os_mgmt_client/src/os_mgmt_client.c b/subsys/mgmt/mcumgr/grp/os_mgmt_client/src/os_mgmt_client.c index 2bd804494c4..0bd174d1c97 100644 --- a/subsys/mgmt/mcumgr/grp/os_mgmt_client/src/os_mgmt_client.c +++ b/subsys/mgmt/mcumgr/grp/os_mgmt_client/src/os_mgmt_client.c @@ -104,7 +104,7 @@ static int echo_res_fn(struct net_buf *nb, void *user_data) } /* Init ZCOR decoder state */ - zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, echo_response, ARRAY_SIZE(echo_response), &decoded) == 0; @@ -119,7 +119,7 @@ static int echo_res_fn(struct net_buf *nb, void *user_data) return rc; } -int os_mgmt_client_echo(struct os_mgmt_client *client, const char *echo_string) +int os_mgmt_client_echo(struct os_mgmt_client *client, const char *echo_string, size_t max_len) { struct net_buf *nb; int rc; @@ -138,7 +138,8 @@ int os_mgmt_client_echo(struct os_mgmt_client *client, const char *echo_string) zcbor_new_encode_state(zse, ARRAY_SIZE(zse), nb->data + nb->len, net_buf_tailroom(nb), 0); ok = zcbor_map_start_encode(zse, 2) && - zcbor_tstr_put_lit(zse, "d") && zcbor_tstr_put_term(zse, echo_string) && + zcbor_tstr_put_lit(zse, "d") && + zcbor_tstr_put_term(zse, echo_string, max_len) && zcbor_map_end_encode(zse, 2); if (!ok) { diff --git a/subsys/mgmt/mcumgr/grp/stat_mgmt/Kconfig b/subsys/mgmt/mcumgr/grp/stat_mgmt/Kconfig index 757d290d10d..20b6549c61a 100644 --- a/subsys/mgmt/mcumgr/grp/stat_mgmt/Kconfig +++ b/subsys/mgmt/mcumgr/grp/stat_mgmt/Kconfig @@ -32,6 +32,14 @@ config MCUMGR_GRP_STAT_MAX_NAME_LEN stat read commands. If a stat group's name exceeds this limit, it will be impossible to retrieve its values with a stat show command. +config MCUMGR_STAT_MAX_NAME_LEN + int "Maximum stat name length" + default MCUMGR_GRP_STAT_MAX_NAME_LEN + depends on MCUMGR_GRP_STAT + help + Limits the maximum length of stat names in MCUmgr requests, in bytes. + This applies to both s_name and snm_name. + module = MCUMGR_GRP_STAT module-str = mcumgr_grp_stat source "subsys/logging/Kconfig.template.log_config" diff --git a/subsys/mgmt/mcumgr/grp/stat_mgmt/src/stat_mgmt.c b/subsys/mgmt/mcumgr/grp/stat_mgmt/src/stat_mgmt.c index 4740073cf01..53ae4e81be0 100644 --- a/subsys/mgmt/mcumgr/grp/stat_mgmt/src/stat_mgmt.c +++ b/subsys/mgmt/mcumgr/grp/stat_mgmt/src/stat_mgmt.c @@ -110,7 +110,7 @@ stat_mgmt_foreach_entry(zcbor_state_t *zse, const char *group_name, stat_mgmt_fo static int stat_mgmt_cb_encode(zcbor_state_t *zse, struct stat_mgmt_entry *entry) { - bool ok = zcbor_tstr_put_term(zse, entry->name) && + bool ok = zcbor_tstr_put_term(zse, entry->name, CONFIG_MCUMGR_STAT_MAX_NAME_LEN) && zcbor_uint32_put(zse, entry->value); return ok ? MGMT_ERR_EOK : MGMT_ERR_EMSGSIZE; @@ -215,7 +215,7 @@ stat_mgmt_list(struct smp_streamer *ctxt) do { cur = stats_group_get_next(cur); if (cur != NULL) { - ok = zcbor_tstr_put_term(zse, cur->s_name); + ok = zcbor_tstr_put_term(zse, cur->s_name, CONFIG_MCUMGR_STAT_MAX_NAME_LEN); } } while (ok && cur != NULL); diff --git a/subsys/mgmt/mcumgr/smp/src/smp.c b/subsys/mgmt/mcumgr/smp/src/smp.c index a97beebddaa..902979d9faf 100644 --- a/subsys/mgmt/mcumgr/smp/src/smp.c +++ b/subsys/mgmt/mcumgr/smp/src/smp.c @@ -53,7 +53,7 @@ static void cbor_nb_reader_init(struct cbor_nb_reader *cnr, struct net_buf *nb) { cnr->nb = nb; zcbor_new_decode_state(cnr->zs, ARRAY_SIZE(cnr->zs), nb->data, - nb->len, 1); + nb->len, 1, NULL, 0); } static void cbor_nb_writer_init(struct cbor_nb_writer *cnw, struct net_buf *nb) @@ -125,7 +125,7 @@ static int smp_build_err_rsp(struct smp_streamer *streamer, const struct smp_hdr #ifdef CONFIG_MCUMGR_SMP_VERBOSE_ERR_RESPONSE if (ok && rc_rsn != NULL) { ok = zcbor_tstr_put_lit(zsp, "rsn") && - zcbor_tstr_put_term(zsp, rc_rsn); + zcbor_tstr_put_term(zsp, rc_rsn, CONFIG_ZCBOR_MAX_STR_LEN); } #else ARG_UNUSED(rc_rsn); From c970356c22fef1b5fb81ccc25a3ceeb2cf8ceb27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20R=C3=B8nningstad?= Date: Wed, 10 Jan 2024 14:39:42 +0100 Subject: [PATCH 7/7] [nrf fromlist] tests: mgmt: Adapt to API changes in zcbor 0.8.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit zcbor_new_state and zcbor_tstr_put_term Signed-off-by: Øyvind Rønningstad --- .../cb_notifications/src/smp_test_util.c | 2 +- .../mcumgr/fs_mgmt_hash_supported/src/main.c | 2 +- .../mcumgr/mcumgr_client/src/img_gr_stub.c | 11 +++-- .../mgmt/mcumgr/mcumgr_client/src/main.c | 4 +- .../mcumgr/mcumgr_client/src/os_gr_stub.c | 3 +- .../mgmt/mcumgr/os_mgmt_datetime/src/main.c | 44 +++++++++---------- .../os_mgmt_datetime/src/smp_test_util.c | 6 +-- .../mgmt/mcumgr/os_mgmt_info/src/build_date.c | 4 +- .../mgmt/mcumgr/os_mgmt_info/src/limited.c | 6 +-- .../mgmt/mcumgr/os_mgmt_info/src/main.c | 44 +++++++++---------- .../mcumgr/os_mgmt_info/src/smp_test_util.c | 2 +- .../mgmt/mcumgr/settings_mgmt/src/main.c | 14 +++--- .../mcumgr/settings_mgmt/src/smp_test_util.c | 18 ++++---- .../subsys/mgmt/mcumgr/smp_version/src/main.c | 6 +-- .../mcumgr/smp_version/src/smp_test_util.c | 2 +- .../subsys/mgmt/mcumgr/zcbor_bulk/src/main.c | 22 +++++----- 16 files changed, 97 insertions(+), 93 deletions(-) diff --git a/tests/subsys/mgmt/mcumgr/cb_notifications/src/smp_test_util.c b/tests/subsys/mgmt/mcumgr/cb_notifications/src/smp_test_util.c index a20f948f30b..270f232af77 100644 --- a/tests/subsys/mgmt/mcumgr/cb_notifications/src/smp_test_util.c +++ b/tests/subsys/mgmt/mcumgr/cb_notifications/src/smp_test_util.c @@ -29,7 +29,7 @@ bool create_mcumgr_format_packet(zcbor_state_t *zse, uint8_t *buffer, uint8_t *o ok = zcbor_map_start_encode(zse, 2) && zcbor_tstr_put_lit(zse, "d") && - zcbor_tstr_put_term(zse, "some test data") && + zcbor_tstr_put_lit(zse, "some test data") && zcbor_map_end_encode(zse, 2); *buffer_size = (zse->payload_mut - buffer); diff --git a/tests/subsys/mgmt/mcumgr/fs_mgmt_hash_supported/src/main.c b/tests/subsys/mgmt/mcumgr/fs_mgmt_hash_supported/src/main.c index a5cafef589d..30575172a84 100644 --- a/tests/subsys/mgmt/mcumgr/fs_mgmt_hash_supported/src/main.c +++ b/tests/subsys/mgmt/mcumgr/fs_mgmt_hash_supported/src/main.c @@ -97,7 +97,7 @@ ZTEST(fs_mgmt_hash_supported, test_supported) /* Search expected type array for this type and update details */ zcbor_new_decode_state(state, 10, &nb->data[sizeof(struct smp_hdr)], - (nb->len - sizeof(struct smp_hdr)), 1); + (nb->len - sizeof(struct smp_hdr)), 1, NULL, 0); ok = zcbor_map_start_decode(state); diff --git a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/img_gr_stub.c b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/img_gr_stub.c index aea03935fe6..9b12fd7b2b0 100644 --- a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/img_gr_stub.c +++ b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/img_gr_stub.c @@ -120,9 +120,10 @@ void img_read_response(int count) zcbor_tstr_put_lit(zse, "slot") && zcbor_uint32_put(zse, image_dummy_info[i].slot_num) && zcbor_tstr_put_lit(zse, "version") && - zcbor_tstr_put_term(zse, image_dummy_info[i].version) && + zcbor_tstr_put_term(zse, image_dummy_info[i].version, + sizeof(image_dummy_info[i].version)) && - zcbor_tstr_put_term(zse, "hash") && + zcbor_tstr_put_lit(zse, "hash") && zcbor_bstr_encode_ptr(zse, image_dummy_info[i].hash, IMG_MGMT_DATA_SHA_LEN) && ZCBOR_ENCODE_FLAG(zse, "bootable", image_dummy_info[i].flags.bootable) && ZCBOR_ENCODE_FLAG(zse, "pending", image_dummy_info[i].flags.pending) && @@ -180,7 +181,8 @@ void img_state_write_verify(struct net_buf *nb) ZCBOR_MAP_DECODE_KEY_DECODER("hash", zcbor_bstr_decode, &hash) }; - zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data + sizeof(struct smp_hdr), nb->len, 1); + zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data + sizeof(struct smp_hdr), nb->len, 1, + NULL, 0); decoded = 0; /* Init buffer values */ @@ -231,7 +233,8 @@ void img_upload_init_verify(struct net_buf *nb) ZCBOR_MAP_DECODE_KEY_DECODER("sha", zcbor_bstr_decode, &sha) }; - zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data + sizeof(struct smp_hdr), nb->len, 1); + zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data + sizeof(struct smp_hdr), nb->len, 1, + NULL, 0); decoded = 0; /* Init buffer values */ diff --git a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/main.c b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/main.c index bf70f178fe7..c724c72c2cc 100644 --- a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/main.c +++ b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/main.c @@ -225,12 +225,12 @@ ZTEST(mcumgr_client, test_os_echo) smp_stub_set_rx_data_verify(NULL); smp_client_send_status_stub(MGMT_ERR_EOK); /* Test timeout */ - rc = os_mgmt_client_echo(&os_client, os_echo_test); + rc = os_mgmt_client_echo(&os_client, os_echo_test, sizeof(os_echo_test)); zassert_equal(MGMT_ERR_ETIMEOUT, rc, "Expected to receive %d response %d", MGMT_ERR_ETIMEOUT, rc); /* Test successfully operation */ smp_stub_set_rx_data_verify(os_echo_verify); - rc = os_mgmt_client_echo(&os_client, os_echo_test); + rc = os_mgmt_client_echo(&os_client, os_echo_test, sizeof(os_echo_test)); zassert_equal(MGMT_ERR_EOK, rc, "Expected to receive %d response %d", MGMT_ERR_EOK, rc); } diff --git a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/os_gr_stub.c b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/os_gr_stub.c index 888f00dba38..c7196874556 100644 --- a/tests/subsys/mgmt/mcumgr/mcumgr_client/src/os_gr_stub.c +++ b/tests/subsys/mgmt/mcumgr/mcumgr_client/src/os_gr_stub.c @@ -81,7 +81,8 @@ void os_echo_verify(struct net_buf *nb) ZCBOR_MAP_DECODE_KEY_DECODER("d", zcbor_tstr_decode, &echo_data) }; - zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data + sizeof(struct smp_hdr), nb->len, 1); + zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data + sizeof(struct smp_hdr), nb->len, 1, + NULL, 0); echo_data.len = 0; rc = zcbor_map_decode_bulk(zsd, list_res_decode, ARRAY_SIZE(list_res_decode), &decoded); diff --git a/tests/subsys/mgmt/mcumgr/os_mgmt_datetime/src/main.c b/tests/subsys/mgmt/mcumgr/os_mgmt_datetime/src/main.c index c387c3b4812..05adb1d6de4 100644 --- a/tests/subsys/mgmt/mcumgr/os_mgmt_datetime/src/main.c +++ b/tests/subsys/mgmt/mcumgr/os_mgmt_datetime/src/main.c @@ -191,7 +191,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_get_not_set_v1) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -253,7 +253,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_get_not_set_v2) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -318,7 +318,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v1_1) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -365,7 +365,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v1_1) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -428,7 +428,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v1_2) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -475,7 +475,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v1_2) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -538,7 +538,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v1_3) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -585,7 +585,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v1_3) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -648,7 +648,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v2_1) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -695,7 +695,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v2_1) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -760,7 +760,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v2_2) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -807,7 +807,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v2_2) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -872,7 +872,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v2_3) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -919,7 +919,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v2_3) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -984,7 +984,7 @@ ZTEST(os_mgmt_datetime_set, test_datetime_set_v1) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -1030,7 +1030,7 @@ ZTEST(os_mgmt_datetime_set, test_datetime_set_v1) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -1098,7 +1098,7 @@ ZTEST(os_mgmt_datetime_set, test_datetime_set_v2) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -1144,7 +1144,7 @@ ZTEST(os_mgmt_datetime_set, test_datetime_set_v2) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -1225,7 +1225,7 @@ ZTEST(os_mgmt_datetime_hook, test_datetime_set_valid_hook_v1) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -1287,7 +1287,7 @@ ZTEST(os_mgmt_datetime_hook, test_datetime_set_valid_hook_v1) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -1357,7 +1357,7 @@ ZTEST(os_mgmt_datetime_hook, test_datetime_set_valid_hook_v2) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -1418,7 +1418,7 @@ ZTEST(os_mgmt_datetime_hook, test_datetime_set_valid_hook_v2) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); diff --git a/tests/subsys/mgmt/mcumgr/os_mgmt_datetime/src/smp_test_util.c b/tests/subsys/mgmt/mcumgr/os_mgmt_datetime/src/smp_test_util.c index 927089c3ee3..d2b969999cd 100644 --- a/tests/subsys/mgmt/mcumgr/os_mgmt_datetime/src/smp_test_util.c +++ b/tests/subsys/mgmt/mcumgr/os_mgmt_datetime/src/smp_test_util.c @@ -49,9 +49,9 @@ bool create_mcumgr_datetime_set_packet_str(zcbor_state_t *zse, bool version2, co uint8_t *buffer, uint8_t *output_buffer, uint16_t *buffer_size) { - bool ok = zcbor_map_start_encode(zse, 2) && - zcbor_tstr_put_lit(zse, "datetime") && - zcbor_tstr_put_term(zse, data) && + bool ok = zcbor_map_start_encode(zse, 2) && + zcbor_tstr_put_lit(zse, "datetime") && + zcbor_tstr_put_term(zse, data, CONFIG_ZCBOR_MAX_STR_LEN) && zcbor_map_end_encode(zse, 2); *buffer_size = (zse->payload_mut - buffer); diff --git a/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/build_date.c b/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/build_date.c index 4af977895c3..5674e338dfa 100644 --- a/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/build_date.c +++ b/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/build_date.c @@ -121,7 +121,7 @@ ZTEST(os_mgmt_info_build_date, test_info_build_date_1_build_date) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -197,7 +197,7 @@ ZTEST(os_mgmt_info_build_date, test_info_build_date_2_all) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; diff --git a/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/limited.c b/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/limited.c index f8899734351..613402e1624 100644 --- a/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/limited.c +++ b/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/limited.c @@ -81,7 +81,7 @@ ZTEST(os_mgmt_info_limited, test_info_1_kernel_name) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -147,7 +147,7 @@ ZTEST(os_mgmt_info_limited, test_info_2_all) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); /* Ensure only an error is received */ ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -155,7 +155,7 @@ ZTEST(os_mgmt_info_limited, test_info_2_all) zassert_true(ok, "Expected decode to be successful\n"); zassert_equal(decoded, 0, "Expected to receive 0 decoded zcbor element\n"); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, error_decode, ARRAY_SIZE(error_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful\n"); diff --git a/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/main.c b/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/main.c index 8ffc2a354b8..6e8cc61098d 100644 --- a/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/main.c +++ b/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/main.c @@ -338,7 +338,7 @@ ZTEST(os_mgmt_info, test_info_2_kernel_name) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -399,7 +399,7 @@ ZTEST(os_mgmt_info, test_info_3_node_name) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -461,7 +461,7 @@ ZTEST(os_mgmt_info, test_info_4_kernel_release) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -523,7 +523,7 @@ ZTEST(os_mgmt_info, test_info_5_kernel_version) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -584,7 +584,7 @@ ZTEST(os_mgmt_info, test_info_6_machine) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -645,7 +645,7 @@ ZTEST(os_mgmt_info, test_info_7_processor) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -706,7 +706,7 @@ ZTEST(os_mgmt_info, test_info_8_platform) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -778,7 +778,7 @@ ZTEST(os_mgmt_info, test_info_9_os) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -839,7 +839,7 @@ ZTEST(os_mgmt_info, test_info_10_all) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -914,7 +914,7 @@ ZTEST(os_mgmt_info, test_info_11_multi_1) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -979,7 +979,7 @@ ZTEST(os_mgmt_info, test_info_12_multi_2) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -1051,7 +1051,7 @@ ZTEST(os_mgmt_info, test_info_13_invalid_1) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); /* Ensure only an error is received */ ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -1059,7 +1059,7 @@ ZTEST(os_mgmt_info, test_info_13_invalid_1) zassert_true(ok, "Expected decode to be successful\n"); zassert_equal(decoded, 0, "Expected to receive 0 decoded zcbor element\n"); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, error_decode, ARRAY_SIZE(error_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful\n"); @@ -1122,7 +1122,7 @@ ZTEST(os_mgmt_info, test_info_14_invalid_2) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); /* Ensure only an error is received */ ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -1130,7 +1130,7 @@ ZTEST(os_mgmt_info, test_info_14_invalid_2) zassert_true(ok, "Expected decode to be successful\n"); zassert_equal(decoded, 0, "Expected to receive 0 decoded zcbor element\n"); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, error_decode, ARRAY_SIZE(error_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful\n"); @@ -1199,7 +1199,7 @@ ZTEST(os_mgmt_info_custom_os, test_info_os_custom) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -1260,7 +1260,7 @@ ZTEST(os_mgmt_info_custom_os_disabled, test_info_os_custom_disabled) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -1333,7 +1333,7 @@ ZTEST(os_mgmt_info_custom_cmd, test_info_cmd_custom) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; @@ -1399,14 +1399,14 @@ ZTEST(os_mgmt_info_custom_cmd_disabled, test_info_cmd_custom_disabled) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful\n"); zassert_equal(decoded, 0, "Expected to receive 0 decoded zcbor element\n"); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, error_decode, ARRAY_SIZE(error_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful\n"); @@ -1468,14 +1468,14 @@ ZTEST(os_mgmt_info_custom_cmd_disabled_verify, test_info_cmd_custom_disabled) /* Process received data by removing header */ (void)net_buf_pull(nb, sizeof(struct smp_hdr)); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful\n"); zassert_equal(decoded, 0, "Expected to receive 0 decoded zcbor element\n"); - zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, error_decode, ARRAY_SIZE(error_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful\n"); diff --git a/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/smp_test_util.c b/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/smp_test_util.c index c1dcded0ff6..b76ac1ad623 100644 --- a/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/smp_test_util.c +++ b/tests/subsys/mgmt/mcumgr/os_mgmt_info/src/smp_test_util.c @@ -31,7 +31,7 @@ bool create_mcumgr_format_packet(zcbor_state_t *zse, const uint8_t *format, uint ok = zcbor_map_start_encode(zse, 2) && zcbor_tstr_put_lit(zse, "format") && - zcbor_tstr_put_term(zse, format) && + zcbor_tstr_put_term(zse, format, CONFIG_ZCBOR_MAX_STR_LEN) && zcbor_map_end_encode(zse, 2); *buffer_size = (zse->payload_mut - buffer); diff --git a/tests/subsys/mgmt/mcumgr/settings_mgmt/src/main.c b/tests/subsys/mgmt/mcumgr/settings_mgmt/src/main.c index 745fa333790..869a4f750d9 100644 --- a/tests/subsys/mgmt/mcumgr/settings_mgmt/src/main.c +++ b/tests/subsys/mgmt/mcumgr/settings_mgmt/src/main.c @@ -487,7 +487,7 @@ ZTEST(settings_mgmt, test_set_read) zassert_equal(smp_header->nh_version, 1, "SMP header version mismatch"); /* Get the response value to compare */ - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -590,7 +590,7 @@ ZTEST(settings_mgmt, test_read_max_size) zassert_equal(smp_header->nh_version, 1, "SMP header version mismatch"); /* Get the response value to compare */ - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); zassert_equal(decoded, 2, "Expected to receive 2 decoded zcbor elements"); @@ -745,7 +745,7 @@ ZTEST(settings_mgmt, test_set_disallowed) zassert_equal(smp_header->nh_version, 1, "SMP header version mismatch"); /* Get the response value to compare */ - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element"); @@ -875,7 +875,7 @@ ZTEST(settings_mgmt, test_set_disallowed) zassert_equal(smp_header->nh_version, 1, "SMP header version mismatch"); /* Get the response value to compare */ - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element"); @@ -1147,7 +1147,7 @@ ZTEST(settings_mgmt, test_delete) zassert_equal(smp_header->nh_version, 1, "SMP header version mismatch"); /* Get the response value to compare */ - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element"); @@ -1274,7 +1274,7 @@ ZTEST(settings_mgmt, test_delete) zassert_equal(smp_header->nh_version, 1, "SMP header version mismatch"); /* Get the response value to compare */ - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element"); @@ -1519,7 +1519,7 @@ ZTEST(settings_mgmt, test_delete) zassert_equal(smp_header->nh_version, 1, "SMP header version mismatch"); /* Get the response value to compare */ - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); zassert_equal(decoded, 1, "Expected to receive 1 decoded zcbor element"); diff --git a/tests/subsys/mgmt/mcumgr/settings_mgmt/src/smp_test_util.c b/tests/subsys/mgmt/mcumgr/settings_mgmt/src/smp_test_util.c index 63b91151797..dcabd0d08c3 100644 --- a/tests/subsys/mgmt/mcumgr/settings_mgmt/src/smp_test_util.c +++ b/tests/subsys/mgmt/mcumgr/settings_mgmt/src/smp_test_util.c @@ -31,7 +31,7 @@ bool create_settings_mgmt_read_packet(zcbor_state_t *zse, uint8_t *buffer, uint8 ok = zcbor_map_start_encode(zse, 2) && zcbor_tstr_put_lit(zse, "name") && - zcbor_tstr_put_term(zse, name) && + zcbor_tstr_put_term(zse, name, CONFIG_ZCBOR_MAX_STR_LEN) && (max_size == 0 || (zcbor_tstr_put_lit(zse, "max_size") && zcbor_uint32_put(zse, max_size))) && zcbor_map_end_encode(zse, 2); @@ -51,11 +51,11 @@ bool create_settings_mgmt_write_packet(zcbor_state_t *zse, uint8_t *buffer, uint { bool ok; - ok = zcbor_map_start_encode(zse, 2) && - zcbor_tstr_put_lit(zse, "name") && - zcbor_tstr_put_term(zse, name) && - zcbor_tstr_put_lit(zse, "val") && - zcbor_bstr_encode_ptr(zse, val, val_size) && + ok = zcbor_map_start_encode(zse, 2) && + zcbor_tstr_put_lit(zse, "name") && + zcbor_tstr_put_term(zse, name, CONFIG_ZCBOR_MAX_STR_LEN) && + zcbor_tstr_put_lit(zse, "val") && + zcbor_bstr_encode_ptr(zse, val, val_size) && zcbor_map_end_encode(zse, 2); *buffer_size = (zse->payload_mut - buffer); @@ -72,9 +72,9 @@ bool create_settings_mgmt_delete_packet(zcbor_state_t *zse, uint8_t *buffer, { bool ok; - ok = zcbor_map_start_encode(zse, 2) && - zcbor_tstr_put_lit(zse, "name") && - zcbor_tstr_put_term(zse, name) && + ok = zcbor_map_start_encode(zse, 2) && + zcbor_tstr_put_lit(zse, "name") && + zcbor_tstr_put_term(zse, name, CONFIG_ZCBOR_MAX_STR_LEN) && zcbor_map_end_encode(zse, 2); *buffer_size = (zse->payload_mut - buffer); diff --git a/tests/subsys/mgmt/mcumgr/smp_version/src/main.c b/tests/subsys/mgmt/mcumgr/smp_version/src/main.c index 8676678336e..ed596ae964e 100644 --- a/tests/subsys/mgmt/mcumgr/smp_version/src/main.c +++ b/tests/subsys/mgmt/mcumgr/smp_version/src/main.c @@ -155,7 +155,7 @@ ZTEST(smp_version, test_legacy_command) zassert_equal(smp_header->nh_version, LEGACY_VERSION, "Expected response header version mismatch"); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -242,7 +242,7 @@ ZTEST(smp_version, test_current_command) zassert_equal(smp_header->nh_version, CURRENT_VERSION, "Expected response header version mismatch"); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); @@ -328,7 +328,7 @@ ZTEST(smp_version, test_new_command) zassert_equal(smp_header->nh_version, CURRENT_VERSION, "Expected response header version mismatch"); - zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1); + zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0); ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0; zassert_true(ok, "Expected decode to be successful"); diff --git a/tests/subsys/mgmt/mcumgr/smp_version/src/smp_test_util.c b/tests/subsys/mgmt/mcumgr/smp_version/src/smp_test_util.c index e93ad69ff2a..96d97a6b6fa 100644 --- a/tests/subsys/mgmt/mcumgr/smp_version/src/smp_test_util.c +++ b/tests/subsys/mgmt/mcumgr/smp_version/src/smp_test_util.c @@ -32,7 +32,7 @@ bool create_mcumgr_format_packet(zcbor_state_t *zse, const uint8_t *format, uint ok = zcbor_map_start_encode(zse, 2) && zcbor_tstr_put_lit(zse, "format") && - zcbor_tstr_put_term(zse, format) && + zcbor_tstr_put_term(zse, format, CONFIG_ZCBOR_MAX_STR_LEN) && zcbor_map_end_encode(zse, 2); *buffer_size = (zse->payload_mut - buffer); diff --git a/tests/subsys/mgmt/mcumgr/zcbor_bulk/src/main.c b/tests/subsys/mgmt/mcumgr/zcbor_bulk/src/main.c index e50dc8fe51f..b1d3d79b30a 100644 --- a/tests/subsys/mgmt/mcumgr/zcbor_bulk/src/main.c +++ b/tests/subsys/mgmt/mcumgr/zcbor_bulk/src/main.c @@ -60,7 +60,7 @@ ZTEST(zcbor_bulk, test_correct) zassert_true(ok, "Expected to be successful in encoding test pattern"); - zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1); + zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1, NULL, 0); int rc = zcbor_map_decode_bulk(zsd, dm, ARRAY_SIZE(dm), &decoded); @@ -101,7 +101,7 @@ ZTEST(zcbor_bulk, test_correct_out_of_order) zassert_true(ok, "Expected to be successful in encoding test pattern"); - zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1); + zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1, NULL, 0); int rc = zcbor_map_decode_bulk(zsd, dm, ARRAY_SIZE(dm), &decoded); @@ -140,7 +140,7 @@ ZTEST(zcbor_bulk, test_not_map) zassert_true(ok, "Expected to be successful in encoding test pattern"); - zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1); + zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1, NULL, 0); int rc = zcbor_map_decode_bulk(zsd, dm, ARRAY_SIZE(dm), &decoded); @@ -175,7 +175,7 @@ ZTEST(zcbor_bulk, test_bad_type) zassert_true(ok, "Expected to be successful in encoding test pattern"); - zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1); + zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1, NULL, 0); int rc = zcbor_map_decode_bulk(zsd, dm, ARRAY_SIZE(dm), &decoded); @@ -211,7 +211,7 @@ ZTEST(zcbor_bulk, test_bad_type_2) zcbor_tstr_put_lit(zsd, "bool val") && zcbor_true_put(zsd) && zcbor_map_end_encode(zsd, 10); - zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1); + zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1, NULL, 0); int rc = zcbor_map_decode_bulk(zsd, dm, ARRAY_SIZE(dm), &decoded); @@ -252,7 +252,7 @@ ZTEST(zcbor_bulk, test_bad_type_encoded) zassert_true(ok, "Expected to be successful in encoding test pattern"); - zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1); + zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1, NULL, 0); int rc = zcbor_map_decode_bulk(zsd, dm, ARRAY_SIZE(dm), &decoded); @@ -287,7 +287,7 @@ ZTEST(zcbor_bulk, test_duplicate) zcbor_tstr_put_lit(zsd, "hello") && zcbor_tstr_put_lit(zsd, "world") && zcbor_map_end_encode(zsd, 10); - zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1); + zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1, NULL, 0); int rc = zcbor_map_decode_bulk(zsd, dm, ARRAY_SIZE(dm), &decoded); @@ -366,7 +366,7 @@ ZTEST(zcbor_bulk, test_map_in_map_correct) zassert_true(ok, "Expected to be successful in encoding test pattern"); - zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1); + zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1, NULL, 0); int rc = zcbor_map_decode_bulk(zsd, dm, ARRAY_SIZE(dm), &decoded); @@ -445,7 +445,7 @@ ZTEST(zcbor_bulk, test_map_in_map_bad) zassert_true(ok, "Expected to be successful in encoding test pattern"); - zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1); + zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1, NULL, 0); int rc = zcbor_map_decode_bulk(zsd, dm, ARRAY_SIZE(dm), &decoded); @@ -486,7 +486,7 @@ ZTEST(zcbor_bulk, test_key_found) zassert_true(ok, "Expected to be successful in encoding test pattern"); - zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1); + zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1, NULL, 0); int rc = zcbor_map_decode_bulk(zsd, dm, ARRAY_SIZE(dm), &decoded); @@ -528,7 +528,7 @@ ZTEST(zcbor_bulk, test_reset) zassert_true(ok, "Expected to be successful in encoding test pattern"); - zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1); + zcbor_new_decode_state(zsd, 4, buffer, ARRAY_SIZE(buffer), 1, NULL, 0); int rc = zcbor_map_decode_bulk(zsd, dm, ARRAY_SIZE(dm), &decoded);