Skip to content

Commit 633269a

Browse files
stig-bjorlykkefabiobaltieri
authored andcommitted
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 <[email protected]>
1 parent 3bd4000 commit 633269a

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

subsys/net/lib/lwm2m/lwm2m_message_handling.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2257,8 +2257,11 @@ static int lwm2m_engine_default_content_format(uint16_t *accept_format)
22572257
} else if (IS_ENABLED(CONFIG_LWM2M_RW_CBOR_SUPPORT)) {
22582258
LOG_DBG("No accept option given. Assume CBOR.");
22592259
*accept_format = LWM2M_FORMAT_APP_CBOR;
2260+
} else if (IS_ENABLED(CONFIG_LWM2M_RW_OMA_TLV_SUPPORT)) {
2261+
LOG_DBG("No accept option given. Assume OMA TLV.");
2262+
*accept_format = LWM2M_FORMAT_OMA_TLV;
22602263
} else {
2261-
LOG_ERR("CBOR, SenML CBOR or SenML JSON is not supported");
2264+
LOG_ERR("CBOR, SenML CBOR, SenML JSON or OMA TLV is not supported");
22622265
return -ENOTSUP;
22632266
}
22642267
} else if (IS_ENABLED(CONFIG_LWM2M_RW_OMA_TLV_SUPPORT)) {

subsys/net/lib/lwm2m/lwm2m_rw_oma_tlv.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,27 @@ static int write_tlv_resource(struct lwm2m_message *msg, struct oma_tlv *tlv)
907907
return 0;
908908
}
909909

910+
#if defined(CONFIG_LWM2M_VERSION_1_1)
911+
static int write_tlv_resource_instance(struct lwm2m_message *msg, struct oma_tlv *tlv)
912+
{
913+
int ret;
914+
915+
if (msg->in.block_ctx) {
916+
msg->in.block_ctx->path.res_inst_id = tlv->id;
917+
}
918+
919+
msg->path.res_inst_id = tlv->id;
920+
msg->path.level = LWM2M_PATH_LEVEL_RESOURCE_INST;
921+
ret = do_write_op_tlv_item(msg);
922+
923+
if (ret < 0) {
924+
return ret;
925+
}
926+
927+
return 0;
928+
}
929+
#endif
930+
910931
static int lwm2m_multi_resource_tlv_parse(struct lwm2m_message *msg,
911932
struct oma_tlv *multi_resource_tlv)
912933
{
@@ -1044,6 +1065,16 @@ int do_write_op_tlv(struct lwm2m_message *msg)
10441065
if (ret) {
10451066
return ret;
10461067
}
1068+
#if defined(CONFIG_LWM2M_VERSION_1_1)
1069+
} else if (tlv.type == OMA_TLV_TYPE_RESOURCE_INSTANCE) {
1070+
if (msg->path.level < LWM2M_PATH_LEVEL_OBJECT_INST) {
1071+
return -ENOTSUP;
1072+
}
1073+
ret = write_tlv_resource_instance(msg, &tlv);
1074+
if (ret) {
1075+
return ret;
1076+
}
1077+
#endif
10471078
} else {
10481079
return -ENOTSUP;
10491080
}

0 commit comments

Comments
 (0)