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 <robert.ch.chou@acer.com>
This commit is contained in:
parent
40c15566eb
commit
228bf05af6
1 changed files with 12 additions and 12 deletions
|
@ -1133,7 +1133,7 @@ u16_t lwm2m_get_rd_data(u8_t *client_data, u16_t size)
|
|||
|
||||
/* input / output selection */
|
||||
|
||||
static u16_t select_writer(struct lwm2m_output_context *out, u16_t accept)
|
||||
static int select_writer(struct lwm2m_output_context *out, u16_t accept)
|
||||
{
|
||||
switch (accept) {
|
||||
|
||||
|
@ -1159,15 +1159,12 @@ static u16_t select_writer(struct lwm2m_output_context *out, u16_t accept)
|
|||
#endif
|
||||
|
||||
default:
|
||||
SYS_LOG_ERR("Unknown Accept type %u, using LWM2M plain text",
|
||||
accept);
|
||||
out->writer = &plain_text_writer;
|
||||
accept = LWM2M_FORMAT_PLAIN_TEXT;
|
||||
break;
|
||||
SYS_LOG_WRN("Unknown content type %u", accept);
|
||||
return -ENOMSG;
|
||||
|
||||
}
|
||||
|
||||
return accept;
|
||||
return 0;
|
||||
}
|
||||
|
||||
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)
|
|||
return -ENOMSG;
|
||||
}
|
||||
|
||||
return format;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* user data setter functions */
|
||||
|
@ -3045,7 +3042,7 @@ static int handle_request(struct coap_packet *request,
|
|||
}
|
||||
}
|
||||
|
||||
/* read Content Format */
|
||||
/* read Content Format / setup in.reader */
|
||||
r = coap_find_options(in.in_cpkt, COAP_OPTION_CONTENT_FORMAT,
|
||||
options, 1);
|
||||
if (r > 0) {
|
||||
|
@ -3056,7 +3053,7 @@ static int handle_request(struct coap_packet *request,
|
|||
}
|
||||
}
|
||||
|
||||
/* read Accept */
|
||||
/* read Accept / setup out.writer */
|
||||
r = coap_find_options(in.in_cpkt, COAP_OPTION_ACCEPT, options, 1);
|
||||
if (r > 0) {
|
||||
accept = coap_option_value_to_int(&options[0]);
|
||||
|
@ -3065,6 +3062,11 @@ static int handle_request(struct coap_packet *request,
|
|||
accept = LWM2M_FORMAT_OMA_TLV;
|
||||
}
|
||||
|
||||
r = select_writer(&out, accept);
|
||||
if (r < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!well_known) {
|
||||
/* find registered obj */
|
||||
obj = get_engine_obj(path.obj_id);
|
||||
|
@ -3075,8 +3077,6 @@ static int handle_request(struct coap_packet *request,
|
|||
}
|
||||
}
|
||||
|
||||
accept = select_writer(&out, accept);
|
||||
|
||||
/* set the operation */
|
||||
switch (code & COAP_REQUEST_MASK) {
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue