net: lwm2m: fix senml max name size

base name or name can contain up to two shorts.
(object id & object intstance or resource id & resource instance id)

Signed-off-by: Pascal Brogle <pascal.brogle@husqvarnagroup.com>
This commit is contained in:
Pascal Brogle 2023-01-10 18:19:08 +01:00 committed by Fabio Baltieri
commit cc40bc33ba

View file

@ -33,13 +33,15 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
#include "lwm2m_senml_cbor_types.h"
#include "lwm2m_util.h"
#define SENML_MAX_NAME_SIZE sizeof("/65535/65535/")
struct cbor_out_fmt_data {
/* Data */
struct lwm2m_senml input;
/* Storage for basenames and names ~ sizeof("/65535/999/") */
/* Storage for basenames and names ~ sizeof("/65535/65535/") */
struct {
char names[CONFIG_LWM2M_RW_SENML_CBOR_RECORDS][sizeof("/65535/999/")];
char names[CONFIG_LWM2M_RW_SENML_CBOR_RECORDS][SENML_MAX_NAME_SIZE];
size_t name_sz; /* Name buff size */
uint8_t name_cnt;
};
@ -93,7 +95,7 @@ static void setup_out_fmt_data(struct lwm2m_message *msg)
(void)memset(fd, 0, sizeof(*fd));
engine_set_out_user_data(&msg->out, fd);
fd->name_sz = sizeof("/65535/999/");
fd->name_sz = SENML_MAX_NAME_SIZE;
fd->basetime = 0;
fd->objlnk_sz = sizeof("65535:65535");
}
@ -160,7 +162,7 @@ static int put_basename(struct lwm2m_output_context *out, struct lwm2m_obj_path
record->_record_bn._record_bn.len = len;
record->_record_bn_present = 1;
if ((len < sizeof("0/0") - 1) || (len >= sizeof("65535/999"))) {
if ((len < sizeof("/0/0") - 1) || (len >= SENML_MAX_NAME_SIZE)) {
__ASSERT_NO_MSG(false);
return -EINVAL;
}
@ -307,7 +309,7 @@ static int put_begin_ri(struct lwm2m_output_context *out, struct lwm2m_obj_path
}
/* Forms name from resource id and resource instance id */
int len = snprintk(name, sizeof("65535/999"),
int len = snprintk(name, SENML_MAX_NAME_SIZE,
"%" PRIu16 "/%" PRIu16 "",
path->res_id, path->res_inst_id);
@ -709,7 +711,7 @@ static int do_write_op_item(struct lwm2m_message *msg, struct record *rec)
uint8_t created = 0U;
struct cbor_in_fmt_data *fd;
/* Composite op - name with basename */
char name[sizeof("65535/999")] = { 0 }; /* Null terminated name */
char name[SENML_MAX_NAME_SIZE] = { 0 }; /* Null terminated name */
int len = 0;
char fqn[MAX_RESOURCE_LEN + 1] = {0};