Skip to content

Commit 228bf05

Browse files
rbtchcAnas Nashif
authored andcommitted
net: lwm2m: update internal API select_writer() and select_reader()
As per review of PR #5893, this is a follow up patch to update select_writer() API to match the behavior of select_reader() API. Quote from OMA-TS-LightweightM2M-V1_0_1-20170704-A. 8.2.5 "An Object Instance or Resource is Read by sending a CoAP GET to the corresponding path. The response includes the value in the corresponding Plain Text, Opaque, TLV or JSON format according to the specified Content-Format (see section 6.4).The request MAY specify an Accept option containing the preferred Content-Format to receive. When the specified Content-Format is not supported by the LwM2M Client, the request MUST be rejected." Therefore, we do not attempt to assign a content-format when the requested one is not supported. Instead, we return an error code. 0 is returned when reader or writer has been successfully selected by select_reader() or select_writer() Signed-off-by: Robert Chou <[email protected]>
1 parent 40c1556 commit 228bf05

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

subsys/net/lib/lwm2m/lwm2m_engine.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,7 @@ u16_t lwm2m_get_rd_data(u8_t *client_data, u16_t size)
11331133

11341134
/* input / output selection */
11351135

1136-
static u16_t select_writer(struct lwm2m_output_context *out, u16_t accept)
1136+
static int select_writer(struct lwm2m_output_context *out, u16_t accept)
11371137
{
11381138
switch (accept) {
11391139

@@ -1159,15 +1159,12 @@ static u16_t select_writer(struct lwm2m_output_context *out, u16_t accept)
11591159
#endif
11601160

11611161
default:
1162-
SYS_LOG_ERR("Unknown Accept type %u, using LWM2M plain text",
1163-
accept);
1164-
out->writer = &plain_text_writer;
1165-
accept = LWM2M_FORMAT_PLAIN_TEXT;
1166-
break;
1162+
SYS_LOG_WRN("Unknown content type %u", accept);
1163+
return -ENOMSG;
11671164

11681165
}
11691166

1170-
return accept;
1167+
return 0;
11711168
}
11721169

11731170
static int select_reader(struct lwm2m_input_context *in, u16_t format)
@@ -1190,7 +1187,7 @@ static int select_reader(struct lwm2m_input_context *in, u16_t format)
11901187
return -ENOMSG;
11911188
}
11921189

1193-
return format;
1190+
return 0;
11941191
}
11951192

11961193
/* user data setter functions */
@@ -3045,7 +3042,7 @@ static int handle_request(struct coap_packet *request,
30453042
}
30463043
}
30473044

3048-
/* read Content Format */
3045+
/* read Content Format / setup in.reader */
30493046
r = coap_find_options(in.in_cpkt, COAP_OPTION_CONTENT_FORMAT,
30503047
options, 1);
30513048
if (r > 0) {
@@ -3056,7 +3053,7 @@ static int handle_request(struct coap_packet *request,
30563053
}
30573054
}
30583055

3059-
/* read Accept */
3056+
/* read Accept / setup out.writer */
30603057
r = coap_find_options(in.in_cpkt, COAP_OPTION_ACCEPT, options, 1);
30613058
if (r > 0) {
30623059
accept = coap_option_value_to_int(&options[0]);
@@ -3065,6 +3062,11 @@ static int handle_request(struct coap_packet *request,
30653062
accept = LWM2M_FORMAT_OMA_TLV;
30663063
}
30673064

3065+
r = select_writer(&out, accept);
3066+
if (r < 0) {
3067+
goto error;
3068+
}
3069+
30683070
if (!well_known) {
30693071
/* find registered obj */
30703072
obj = get_engine_obj(path.obj_id);
@@ -3075,8 +3077,6 @@ static int handle_request(struct coap_packet *request,
30753077
}
30763078
}
30773079

3078-
accept = select_writer(&out, accept);
3079-
30803080
/* set the operation */
30813081
switch (code & COAP_REQUEST_MASK) {
30823082

0 commit comments

Comments
 (0)