From c1500fe9a4653c69e28b3872b0d649b9bb72d773 Mon Sep 17 00:00:00 2001 From: Robert Chou Date: Mon, 14 Aug 2017 17:06:03 +0800 Subject: [PATCH] net: lwm2m: report resource type / content type at registration Per LwM2M specification 5.3.1 Register, report "ct=11543" when JSON is supported. Also, report the resource type as rt="oma.lwm2m" when "ct=" presents. Signed-off-by: Robert Chou --- subsys/net/lib/lwm2m/lwm2m_engine.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/subsys/net/lib/lwm2m/lwm2m_engine.c b/subsys/net/lib/lwm2m/lwm2m_engine.c index fb1b717fc0c..56f0f90825e 100644 --- a/subsys/net/lib/lwm2m/lwm2m_engine.c +++ b/subsys/net/lib/lwm2m/lwm2m_engine.c @@ -56,6 +56,26 @@ #define DISCOVER_PREFACE ";ct=40" +/* + * TODO: to implement a way for clients to specify alternate path + * via Kconfig (LwM2M specification 8.2.2 Alternate Path) + * + * For now, in order to inform server we support JSON format, we have to + * report 'ct=11543' to the server. '' is required in order to append + * content attribute. And resource type attribute is appended because of + * Eclipse wakaama will reject the registration when 'rt="oma.lwm2m"' is + * missing. + */ + +#define RESOURCE_TYPE ";rt=\"oma.lwm2m\"" + +#if defined(CONFIG_LWM2M_RW_JSON_SUPPORT) +#define REG_PREFACE "" RESOURCE_TYPE \ + ";ct=" STRINGIFY(LWM2M_FORMAT_OMA_JSON) +#else +#define REG_PREFACE "" +#endif + #define BUF_ALLOC_TIMEOUT K_SECONDS(1) struct observe_node { @@ -585,6 +605,10 @@ u16_t lwm2m_get_rd_data(u8_t *client_data, u16_t size) u16_t pos = 0; int len; + /* Add resource-type/content-type to the registration message */ + memcpy(client_data, REG_PREFACE, sizeof(REG_PREFACE) - 1); + pos += sizeof(REG_PREFACE) - 1; + SYS_SLIST_FOR_EACH_CONTAINER(&engine_obj_list, obj, node) { /* Security obj MUST NOT be part of registration message */ if (obj->obj_id == LWM2M_OBJECT_SECURITY_ID) {