Skip to content

Commit 6ba362b

Browse files
rluboscarlescufi
authored andcommitted
net: lwm2m: Remove .well-known/core handling
`.well-known/core` resource is described by the CoAP RFC as an optional method of resource discovery. The LwM2M specification though makes no mentionon about this mechanism and provides an alternative method of resource discovery instead (Device Management Discover, sec 5.4.2, and Bootstrap Discovery, sec 5.2.7.3). Since LwM2M does not require to implement `.well-known/core` resource and it complicates the existing Discovery mechanism (and likely cause a security concern) remove its handling from the LwM2M implementation. Signed-off-by: Robert Lubos <[email protected]>
1 parent d53fb57 commit 6ba362b

File tree

1 file changed

+11
-52
lines changed

1 file changed

+11
-52
lines changed

subsys/net/lib/lwm2m/lwm2m_engine.c

Lines changed: 11 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
5959
#define ENGINE_UPDATE_INTERVAL_MS 500
6060
#define OBSERVE_COUNTER_START 0U
6161

62-
#define WELL_KNOWN_CORE_PATH "</.well-known/core>"
63-
6462
/*
6563
* TODO: to implement a way for clients to specify alternate path
6664
* via Kconfig (LwM2M specification 8.2.2 Alternate Path)
@@ -3316,20 +3314,18 @@ static int print_resource_dimension(struct lwm2m_output_context *out,
33163314
return 0;
33173315
}
33183316

3319-
static int do_discover_op(struct lwm2m_message *msg, bool well_known)
3317+
static int do_discover_op(struct lwm2m_message *msg)
33203318
{
33213319
static char disc_buf[24];
33223320
struct lwm2m_engine_obj *obj;
33233321
struct lwm2m_engine_obj_inst *obj_inst;
33243322
int ret;
33253323
bool reported = false;
33263324

3327-
/* object ID is required unless it's a ".well-known/core" discovery
3328-
* ref: lwm2m spec 20170208-A table 11
3325+
/* object ID is required in Device Management Discovery (5.4.2).
33293326
*/
3330-
if (!well_known &&
3331-
(msg->path.level == 0U ||
3332-
msg->path.obj_id == LWM2M_OBJECT_SECURITY_ID)) {
3327+
if (msg->path.level == 0U ||
3328+
msg->path.obj_id == LWM2M_OBJECT_SECURITY_ID) {
33333329
return -EPERM;
33343330
}
33353331

@@ -3347,30 +3343,6 @@ static int do_discover_op(struct lwm2m_message *msg, bool well_known)
33473343
return ret;
33483344
}
33493345

3350-
/* Handle CoAP .well-known/core discover */
3351-
if (well_known) {
3352-
/* </.well-known/core> */
3353-
ret = buf_append(CPKT_BUF_WRITE(msg->out.out_cpkt),
3354-
WELL_KNOWN_CORE_PATH,
3355-
strlen(WELL_KNOWN_CORE_PATH));
3356-
if (ret < 0) {
3357-
return ret;
3358-
}
3359-
3360-
SYS_SLIST_FOR_EACH_CONTAINER(&engine_obj_list, obj, node) {
3361-
snprintk(disc_buf, sizeof(disc_buf), ",</%u>",
3362-
obj->obj_id);
3363-
3364-
ret = buf_append(CPKT_BUF_WRITE(msg->out.out_cpkt),
3365-
disc_buf, strlen(disc_buf));
3366-
if (ret < 0) {
3367-
return ret;
3368-
}
3369-
}
3370-
3371-
return 0;
3372-
}
3373-
33743346
/* Report object attributes only when Object ID (alone) was
33753347
* provided (and do it only once in case of multiple instances).
33763348
*/
@@ -3812,7 +3784,6 @@ static int handle_request(struct coap_packet *request,
38123784
uint8_t tkl = 0U;
38133785
uint16_t format = LWM2M_FORMAT_NONE, accept;
38143786
int observe = -1; /* default to -1, 0 = ENABLE, 1 = DISABLE */
3815-
bool well_known = false;
38163787
int block_opt, block_num;
38173788
struct lwm2m_block_context *block_ctx = NULL;
38183789
enum coap_block_size block_size;
@@ -3872,22 +3843,10 @@ static int handle_request(struct coap_packet *request,
38723843
}
38733844
}
38743845

3875-
/* check for .well-known/core URI query (DISCOVER) */
3876-
if (r == 2 &&
3877-
(options[0].len == 11U &&
3878-
strncmp(options[0].value, ".well-known", 11) == 0) &&
3879-
(options[1].len == 4U &&
3880-
strncmp(options[1].value, "core", 4) == 0)) {
3881-
if ((code & COAP_REQUEST_MASK) != COAP_METHOD_GET) {
3882-
r = -EPERM;
3883-
goto error;
3884-
}
3885-
3886-
well_known = true;
38873846
#if defined(CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP)
38883847
/* check for bootstrap-finish */
3889-
} else if ((code & COAP_REQUEST_MASK) == COAP_METHOD_POST && r == 1 && \
3890-
strncmp(options[0].value, "bs", options[0].len) == 0) {
3848+
if ((code & COAP_REQUEST_MASK) == COAP_METHOD_POST && r == 1 &&
3849+
strncmp(options[0].value, "bs", options[0].len) == 0) {
38913850
engine_bootstrap_finish();
38923851

38933852
msg->code = COAP_RESPONSE_CODE_CHANGED;
@@ -3898,8 +3857,9 @@ static int handle_request(struct coap_packet *request,
38983857
}
38993858

39003859
return 0;
3860+
} else
39013861
#endif
3902-
} else {
3862+
{
39033863
r = coap_options_to_path(options, r, &msg->path);
39043864
if (r < 0) {
39053865
r = -ENOENT;
@@ -3932,8 +3892,7 @@ static int handle_request(struct coap_packet *request,
39323892
goto error;
39333893
}
39343894

3935-
if (!well_known && !(msg->ctx->bootstrap_mode &&
3936-
msg->path.level == 0)) {
3895+
if (!(msg->ctx->bootstrap_mode && msg->path.level == 0)) {
39373896
/* find registered obj */
39383897
obj = get_engine_obj(msg->path.obj_id);
39393898
if (!obj) {
@@ -3951,7 +3910,7 @@ static int handle_request(struct coap_packet *request,
39513910
* LwM2M V1_0_1-20170704-A, table 25,
39523911
* Discover: CoAP GET + accept=LWM2M_FORMAT_APP_LINK_FORMAT
39533912
*/
3954-
if (well_known || accept == LWM2M_FORMAT_APP_LINK_FORMAT) {
3913+
if (accept == LWM2M_FORMAT_APP_LINK_FORMAT) {
39553914
msg->operation = LWM2M_OP_DISCOVER;
39563915
accept = LWM2M_FORMAT_APP_LINK_FORMAT;
39573916
} else {
@@ -4121,7 +4080,7 @@ static int handle_request(struct coap_packet *request,
41214080
break;
41224081
}
41234082
#endif
4124-
r = do_discover_op(msg, well_known);
4083+
r = do_discover_op(msg);
41254084
break;
41264085

41274086
case LWM2M_OP_WRITE:

0 commit comments

Comments
 (0)