Skip to content

Commit c1500fe

Browse files
rbtchcjukkar
authored andcommitted
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 <[email protected]>
1 parent a64dcbb commit c1500fe

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

subsys/net/lib/lwm2m/lwm2m_engine.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,26 @@
5656

5757
#define DISCOVER_PREFACE "</.well-known/core>;ct=40"
5858

59+
/*
60+
* TODO: to implement a way for clients to specify alternate path
61+
* via Kconfig (LwM2M specification 8.2.2 Alternate Path)
62+
*
63+
* For now, in order to inform server we support JSON format, we have to
64+
* report 'ct=11543' to the server. '</>' is required in order to append
65+
* content attribute. And resource type attribute is appended because of
66+
* Eclipse wakaama will reject the registration when 'rt="oma.lwm2m"' is
67+
* missing.
68+
*/
69+
70+
#define RESOURCE_TYPE ";rt=\"oma.lwm2m\""
71+
72+
#if defined(CONFIG_LWM2M_RW_JSON_SUPPORT)
73+
#define REG_PREFACE "</>" RESOURCE_TYPE \
74+
";ct=" STRINGIFY(LWM2M_FORMAT_OMA_JSON)
75+
#else
76+
#define REG_PREFACE ""
77+
#endif
78+
5979
#define BUF_ALLOC_TIMEOUT K_SECONDS(1)
6080

6181
struct observe_node {
@@ -585,6 +605,10 @@ u16_t lwm2m_get_rd_data(u8_t *client_data, u16_t size)
585605
u16_t pos = 0;
586606
int len;
587607

608+
/* Add resource-type/content-type to the registration message */
609+
memcpy(client_data, REG_PREFACE, sizeof(REG_PREFACE) - 1);
610+
pos += sizeof(REG_PREFACE) - 1;
611+
588612
SYS_SLIST_FOR_EACH_CONTAINER(&engine_obj_list, obj, node) {
589613
/* Security obj MUST NOT be part of registration message */
590614
if (obj->obj_id == LWM2M_OBJECT_SECURITY_ID) {

0 commit comments

Comments
 (0)