net: lib: lwm2m: Deprecate string based send

Deprecate send API using the string references as paths.
Replace it with one using path structs.

Signed-off-by: Jarno Lämsä <jarno.lamsa@nordicsemi.no>
This commit is contained in:
Jarno Lämsä 2023-01-05 15:40:38 +02:00 committed by Carles Cufí
commit 460dd6530f
5 changed files with 58 additions and 12 deletions

View file

@ -2937,8 +2937,8 @@ static bool init_next_pending_timeseries_data(struct lwm2m_cache_read_info *cach
}
#endif
int lwm2m_engine_send(struct lwm2m_ctx *ctx, char const *path_list[], uint8_t path_list_size,
bool confirmation_request)
int lwm2m_send(struct lwm2m_ctx *ctx, const struct lwm2m_obj_path path_list[],
uint8_t path_list_size, bool confirmation_request)
{
#if defined(CONFIG_LWM2M_SERVER_OBJECT_VERSION_1_1)
struct lwm2m_message *msg;
@ -2946,7 +2946,6 @@ int lwm2m_engine_send(struct lwm2m_ctx *ctx, char const *path_list[], uint8_t pa
uint16_t content_format;
/* Path list buffer */
struct lwm2m_obj_path temp;
struct lwm2m_obj_path_list lwm2m_path_list_buf[CONFIG_LWM2M_COMPOSITE_PATH_LIST_SIZE];
sys_slist_t lwm2m_path_list;
sys_slist_t lwm2m_path_free_list;
@ -2986,12 +2985,9 @@ int lwm2m_engine_send(struct lwm2m_ctx *ctx, char const *path_list[], uint8_t pa
/* Parse Path to internal used object path format */
for (int i = 0; i < path_list_size; i++) {
ret = lwm2m_string_to_path(path_list[i], &temp, '/');
if (ret < 0) {
return ret;
}
/* Add to linked list */
if (lwm2m_engine_add_path_to_list(&lwm2m_path_list, &lwm2m_path_free_list, &temp)) {
if (lwm2m_engine_add_path_to_list(&lwm2m_path_list, &lwm2m_path_free_list,
&path_list[i])) {
return -1;
}
}
@ -3087,3 +3083,24 @@ cleanup:
return -ENOTSUP;
#endif
}
int lwm2m_engine_send(struct lwm2m_ctx *ctx, char const *path_list[], uint8_t path_list_size,
bool confirmation_request)
{
int ret;
struct lwm2m_obj_path lwm2m_path_list[CONFIG_LWM2M_COMPOSITE_PATH_LIST_SIZE];
if (path_list_size > CONFIG_LWM2M_COMPOSITE_PATH_LIST_SIZE) {
return -E2BIG;
}
for (int i = 0; i < path_list_size; i++) {
/* translate path -> path_obj */
ret = lwm2m_string_to_path(path_list[i], &lwm2m_path_list[i], '/');
if (ret < 0) {
return ret;
}
}
return lwm2m_send(ctx, lwm2m_path_list, path_list_size, confirmation_request);
}

View file

@ -1501,7 +1501,7 @@ void lwm2m_engine_path_list_init(sys_slist_t *lwm2m_path_list, sys_slist_t *lwm2
}
int lwm2m_engine_add_path_to_list(sys_slist_t *lwm2m_path_list, sys_slist_t *lwm2m_free_list,
struct lwm2m_obj_path *path)
const struct lwm2m_obj_path *path)
{
struct lwm2m_obj_path_list *prev = NULL;
struct lwm2m_obj_path_list *entry;

View file

@ -70,7 +70,7 @@ void lwm2m_engine_path_list_init(sys_slist_t *lwm2m_path_list, sys_slist_t *lwm2
* @return 0 on success or a negative error code
*/
int lwm2m_engine_add_path_to_list(sys_slist_t *lwm2m_path_list, sys_slist_t *lwm2m_free_list,
struct lwm2m_obj_path *path);
const struct lwm2m_obj_path *path);
int lwm2m_get_path_reference_ptr(struct lwm2m_engine_obj *obj, const struct lwm2m_obj_path *path,
void **ref);

View file

@ -62,6 +62,7 @@ static int cmd_send(const struct shell *sh, size_t argc, char **argv)
int path_cnt = argc - 1;
bool confirmable = true;
int ignore_cnt = 1; /* Subcmd + arguments preceding the path list */
struct lwm2m_obj_path lwm2m_path_list[CONFIG_LWM2M_COMPOSITE_PATH_LIST_SIZE];
if (!ctx) {
shell_error(sh, "no lwm2m context yet\n");
@ -86,8 +87,20 @@ static int cmd_send(const struct shell *sh, size_t argc, char **argv)
return -EINVAL;
}
ret = lwm2m_engine_send(ctx, (const char **)&(argv[ignore_cnt]),
path_cnt, confirmable);
if (path_cnt > CONFIG_LWM2M_COMPOSITE_PATH_LIST_SIZE) {
return -E2BIG;
}
for (int i = ignore_cnt; i < path_cnt; i++) {
/* translate path -> path_obj */
ret = lwm2m_string_to_path(argv[i], &lwm2m_path_list[i], '/');
if (ret < 0) {
return ret;
}
}
ret = lwm2m_send(ctx, lwm2m_path_list, path_cnt, confirmable);
if (ret < 0) {
shell_error(sh, "can't do send operation, request failed\n");
return -ENOEXEC;