net: lwm2m: Add dimension discovery support

Multi-instance resources shall report its dimension (number of
resource instances) on discovery. Since it was not possible to tell
simply on the instance count whether the resource is multi-instance or
not (there could be a multi-instance resource with only one instance
avaialble) add a new parameter to the structure representing resource,
indicating whether it's multi-instance or not.

Add dimension information to the discovery result.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2020-11-26 16:51:49 +01:00 committed by Carles Cufí
commit 366a2147cc
14 changed files with 69 additions and 36 deletions

View file

@ -3089,6 +3089,31 @@ static int print_attr(struct lwm2m_output_context *out,
return 0;
}
static int print_resource_dimension(struct lwm2m_output_context *out,
uint8_t *buf, uint16_t buflen,
struct lwm2m_engine_res *res)
{
int ret, i, inst_count = 0;
if (res->multi_res_inst) {
for (i = 0; i < res->res_inst_count; i++) {
if (res->res_instances[i].res_inst_id !=
RES_INSTANCE_NOT_CREATED) {
inst_count++;
}
}
snprintk(buf, buflen, ";dim=%d", inst_count);
ret = buf_append(CPKT_BUF_WRITE(out->out_cpkt), buf,
strlen(buf));
if (ret < 0) {
return ret;
}
}
return 0;
}
static int do_discover_op(struct lwm2m_message *msg, bool well_known)
{
static char disc_buf[24];
@ -3233,6 +3258,13 @@ static int do_discover_op(struct lwm2m_message *msg, bool well_known)
/* report resource attrs when path > 1 (5.4.2) */
if (msg->path.level > 1) {
ret = print_resource_dimension(
&msg->out, disc_buf, sizeof(disc_buf),
&obj_inst->resources[i]);
if (ret < 0) {
return ret;
}
ret = print_attr(&msg->out,
disc_buf, sizeof(disc_buf),
&obj_inst->resources[i]);