net: lwm2m: Accept OMA TLV in LwM2M 1.1

Support write OMA TLV resource instance in LwM2M 1.1.
Accept OMA TLV as default content format.

Signed-off-by: Stig Bjørlykke <stig.bjorlykke@nordicsemi.no>
This commit is contained in:
Stig Bjørlykke 2024-08-21 12:30:07 +02:00 committed by Fabio Baltieri
commit 633269a913
2 changed files with 35 additions and 1 deletions

View file

@ -2257,8 +2257,11 @@ static int lwm2m_engine_default_content_format(uint16_t *accept_format)
} else if (IS_ENABLED(CONFIG_LWM2M_RW_CBOR_SUPPORT)) {
LOG_DBG("No accept option given. Assume CBOR.");
*accept_format = LWM2M_FORMAT_APP_CBOR;
} else if (IS_ENABLED(CONFIG_LWM2M_RW_OMA_TLV_SUPPORT)) {
LOG_DBG("No accept option given. Assume OMA TLV.");
*accept_format = LWM2M_FORMAT_OMA_TLV;
} else {
LOG_ERR("CBOR, SenML CBOR or SenML JSON is not supported");
LOG_ERR("CBOR, SenML CBOR, SenML JSON or OMA TLV is not supported");
return -ENOTSUP;
}
} else if (IS_ENABLED(CONFIG_LWM2M_RW_OMA_TLV_SUPPORT)) {

View file

@ -907,6 +907,27 @@ static int write_tlv_resource(struct lwm2m_message *msg, struct oma_tlv *tlv)
return 0;
}
#if defined(CONFIG_LWM2M_VERSION_1_1)
static int write_tlv_resource_instance(struct lwm2m_message *msg, struct oma_tlv *tlv)
{
int ret;
if (msg->in.block_ctx) {
msg->in.block_ctx->path.res_inst_id = tlv->id;
}
msg->path.res_inst_id = tlv->id;
msg->path.level = LWM2M_PATH_LEVEL_RESOURCE_INST;
ret = do_write_op_tlv_item(msg);
if (ret < 0) {
return ret;
}
return 0;
}
#endif
static int lwm2m_multi_resource_tlv_parse(struct lwm2m_message *msg,
struct oma_tlv *multi_resource_tlv)
{
@ -1044,6 +1065,16 @@ int do_write_op_tlv(struct lwm2m_message *msg)
if (ret) {
return ret;
}
#if defined(CONFIG_LWM2M_VERSION_1_1)
} else if (tlv.type == OMA_TLV_TYPE_RESOURCE_INSTANCE) {
if (msg->path.level < LWM2M_PATH_LEVEL_OBJECT_INST) {
return -ENOTSUP;
}
ret = write_tlv_resource_instance(msg, &tlv);
if (ret) {
return ret;
}
#endif
} else {
return -ENOTSUP;
}