Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zcbor 0.8.0 nrf #1448

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions modules/zcbor/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion subsys/mgmt/mcumgr/grp/fs_mgmt/src/fs_mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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") &&
Expand Down
4 changes: 2 additions & 2 deletions subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand Down
6 changes: 3 additions & 3 deletions subsys/mgmt/mcumgr/grp/img_mgmt_client/src/img_mgmt_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion subsys/mgmt/mcumgr/grp/os_mgmt/src/os_mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions subsys/mgmt/mcumgr/grp/os_mgmt_client/src/os_mgmt_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions subsys/mgmt/mcumgr/grp/stat_mgmt/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions subsys/mgmt/mcumgr/grp/stat_mgmt/src/stat_mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions subsys/mgmt/mcumgr/smp/src/smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
22 changes: 11 additions & 11 deletions subsys/net/lib/lwm2m/lwm2m_rw_cbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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",
Expand All @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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;
Expand All @@ -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");
Expand All @@ -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);

Expand Down Expand Up @@ -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");
Expand All @@ -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) {
Expand Down
Loading
Loading