diff --git a/subsys/net/lib/lwm2m/lwm2m_engine.c b/subsys/net/lib/lwm2m/lwm2m_engine.c index 7b636e28fbf..920c7c265c2 100644 --- a/subsys/net/lib/lwm2m/lwm2m_engine.c +++ b/subsys/net/lib/lwm2m/lwm2m_engine.c @@ -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) {