Skip to content

Commit 2aefab6

Browse files
[nrf fromlist] mgmt: Adapt to API changes in zcbor 0.8.0
zcbor_new_state and zcbor_tstr_put_term Signed-off-by: Øyvind Rønningstad <[email protected]>
1 parent c728f77 commit 2aefab6

File tree

9 files changed

+25
-15
lines changed

9 files changed

+25
-15
lines changed

include/zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt_client.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ void os_mgmt_client_init(struct os_mgmt_client *client, struct smp_client_object
4545
*
4646
* @param client OS mgmt client object
4747
* @param echo_string Echo string
48+
* @param max_len Max length of @p echo_string
4849
*
4950
* @return 0 on success.
5051
* @return @ref mcumgr_err_t code on failure.
5152
*/
52-
int os_mgmt_client_echo(struct os_mgmt_client *client, const char *echo_string);
53+
int os_mgmt_client_echo(struct os_mgmt_client *client, const char *echo_string, size_t max_len);
5354

5455
/**
5556
* @brief Send SMP Reset command.

subsys/mgmt/mcumgr/grp/fs_mgmt/src/fs_mgmt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ static int fs_mgmt_file_hash_checksum(struct smp_streamer *ctxt)
783783
}
784784

785785
ok &= zcbor_tstr_put_lit(zse, "type") &&
786-
zcbor_tstr_put_term(zse, type_arr);
786+
zcbor_tstr_put_term(zse, type_arr, sizeof(type_arr));
787787

788788
if (off != 0) {
789789
ok &= zcbor_tstr_put_lit(zse, "off") &&

subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,11 @@ static bool img_mgmt_state_encode_slot(zcbor_state_t *zse, uint32_t slot, int st
443443
ok = zcbor_tstr_put_lit(zse, "<\?\?\?>");
444444
} else {
445445
vers_str[sizeof(vers_str) - 1] = '\0';
446-
ok = zcbor_tstr_put_term(zse, vers_str);
446+
ok = zcbor_tstr_put_term(zse, vers_str, sizeof(vers_str));
447447
}
448448
}
449449

450-
ok = ok && zcbor_tstr_put_term(zse, "hash") &&
450+
ok = ok && zcbor_tstr_put_lit(zse, "hash") &&
451451
zcbor_bstr_encode(zse, &zhash) &&
452452
ZCBOR_ENCODE_FLAG(zse, "bootable", !(flags & IMAGE_F_NON_BOOTABLE)) &&
453453
ZCBOR_ENCODE_FLAG(zse, "pending", state_flags & REPORT_SLOT_PENDING) &&

subsys/mgmt/mcumgr/grp/img_mgmt_client/src/img_mgmt_client.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static int image_state_res_fn(struct net_buf *nb, void *user_data)
7474
goto out;
7575
}
7676

77-
zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data, nb->len, 1);
77+
zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data, nb->len, 1, NULL, 0);
7878

7979
ok = zcbor_map_start_decode(zsd);
8080
if (!ok) {
@@ -201,7 +201,7 @@ static int image_upload_res_fn(struct net_buf *nb, void *user_data)
201201
goto end;
202202
}
203203

204-
zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data, nb->len, 1);
204+
zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data, nb->len, 1, NULL, 0);
205205

206206
rc = zcbor_map_decode_bulk(zsd, upload_res_decode, ARRAY_SIZE(upload_res_decode), &decoded);
207207
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)
233233
goto end;
234234
}
235235

236-
zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data, nb->len, 1);
236+
zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data, nb->len, 1, NULL, 0);
237237

238238
rc = zcbor_map_decode_bulk(zsd, upload_res_decode, ARRAY_SIZE(upload_res_decode), &decoded);
239239
if (rc) {

subsys/mgmt/mcumgr/grp/os_mgmt/src/os_mgmt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ os_mgmt_taskstat_encode_thread_name(zcbor_state_t *zse, int idx,
207207
snprintf(thread_name, sizeof(thread_name) - 1, "%d", idx);
208208
thread_name[sizeof(thread_name) - 1] = 0;
209209

210-
return zcbor_tstr_put_term(zse, thread_name);
210+
return zcbor_tstr_put_term(zse, thread_name, sizeof(thread_name));
211211
}
212212

213213
#endif

subsys/mgmt/mcumgr/grp/os_mgmt_client/src/os_mgmt_client.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static int echo_res_fn(struct net_buf *nb, void *user_data)
104104
}
105105

106106
/* Init ZCOR decoder state */
107-
zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data, nb->len, 1);
107+
zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data, nb->len, 1, NULL, 0);
108108

109109
ok = zcbor_map_decode_bulk(zsd, echo_response, ARRAY_SIZE(echo_response), &decoded) == 0;
110110

@@ -119,7 +119,7 @@ static int echo_res_fn(struct net_buf *nb, void *user_data)
119119
return rc;
120120
}
121121

122-
int os_mgmt_client_echo(struct os_mgmt_client *client, const char *echo_string)
122+
int os_mgmt_client_echo(struct os_mgmt_client *client, const char *echo_string, size_t max_len)
123123
{
124124
struct net_buf *nb;
125125
int rc;
@@ -138,7 +138,8 @@ int os_mgmt_client_echo(struct os_mgmt_client *client, const char *echo_string)
138138
zcbor_new_encode_state(zse, ARRAY_SIZE(zse), nb->data + nb->len, net_buf_tailroom(nb), 0);
139139

140140
ok = zcbor_map_start_encode(zse, 2) &&
141-
zcbor_tstr_put_lit(zse, "d") && zcbor_tstr_put_term(zse, echo_string) &&
141+
zcbor_tstr_put_lit(zse, "d") &&
142+
zcbor_tstr_put_term(zse, echo_string, max_len) &&
142143
zcbor_map_end_encode(zse, 2);
143144

144145
if (!ok) {

subsys/mgmt/mcumgr/grp/stat_mgmt/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ config MCUMGR_GRP_STAT_MAX_NAME_LEN
3232
stat read commands. If a stat group's name exceeds this limit, it will
3333
be impossible to retrieve its values with a stat show command.
3434

35+
config MCUMGR_STAT_MAX_NAME_LEN
36+
int "Maximum stat name length"
37+
default MCUMGR_GRP_STAT_MAX_NAME_LEN
38+
depends on MCUMGR_GRP_STAT
39+
help
40+
Limits the maximum length of stat names in MCUmgr requests, in bytes.
41+
This applies to both s_name and snm_name.
42+
3543
module = MCUMGR_GRP_STAT
3644
module-str = mcumgr_grp_stat
3745
source "subsys/logging/Kconfig.template.log_config"

subsys/mgmt/mcumgr/grp/stat_mgmt/src/stat_mgmt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ stat_mgmt_foreach_entry(zcbor_state_t *zse, const char *group_name, stat_mgmt_fo
110110
static int
111111
stat_mgmt_cb_encode(zcbor_state_t *zse, struct stat_mgmt_entry *entry)
112112
{
113-
bool ok = zcbor_tstr_put_term(zse, entry->name) &&
113+
bool ok = zcbor_tstr_put_term(zse, entry->name, CONFIG_MCUMGR_STAT_MAX_NAME_LEN) &&
114114
zcbor_uint32_put(zse, entry->value);
115115

116116
return ok ? MGMT_ERR_EOK : MGMT_ERR_EMSGSIZE;
@@ -215,7 +215,7 @@ stat_mgmt_list(struct smp_streamer *ctxt)
215215
do {
216216
cur = stats_group_get_next(cur);
217217
if (cur != NULL) {
218-
ok = zcbor_tstr_put_term(zse, cur->s_name);
218+
ok = zcbor_tstr_put_term(zse, cur->s_name, CONFIG_MCUMGR_STAT_MAX_NAME_LEN);
219219
}
220220
} while (ok && cur != NULL);
221221

subsys/mgmt/mcumgr/smp/src/smp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static void cbor_nb_reader_init(struct cbor_nb_reader *cnr, struct net_buf *nb)
5353
{
5454
cnr->nb = nb;
5555
zcbor_new_decode_state(cnr->zs, ARRAY_SIZE(cnr->zs), nb->data,
56-
nb->len, 1);
56+
nb->len, 1, NULL, 0);
5757
}
5858

5959
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
125125
#ifdef CONFIG_MCUMGR_SMP_VERBOSE_ERR_RESPONSE
126126
if (ok && rc_rsn != NULL) {
127127
ok = zcbor_tstr_put_lit(zsp, "rsn") &&
128-
zcbor_tstr_put_term(zsp, rc_rsn);
128+
zcbor_tstr_put_term(zsp, rc_rsn, CONFIG_ZCBOR_MAX_STR_LEN);
129129
}
130130
#else
131131
ARG_UNUSED(rc_rsn);

0 commit comments

Comments
 (0)