net: lwm2m: return BAD_REQUEST when object create fails

Per LwM2M spec (7.3.2.4 Operation on Object):
"If the payload (New Value) conveys an Object Instance ID in conflict
with one already present in the LwM2M Client, the complete request
MUST be rejected and a "Bad Request" error code MUST be sent back."

Let's do that.

Signed-off-by: Michael Scott <michael.scott@linaro.org>
This commit is contained in:
Michael Scott 2017-08-17 13:10:59 -07:00 committed by Anas Nashif
commit 8662b69685

View file

@ -390,7 +390,11 @@ int lwm2m_create_obj_inst(u16_t obj_id, u16_t obj_inst_id,
if (!*obj_inst) {
SYS_LOG_ERR("unable to create obj %u instance %u",
obj_id, obj_inst_id);
return -EINVAL;
/*
* Already checked for instance count total.
* This can only be an error if the object instance exists.
*/
return -EEXIST;
}
obj->instance_count++;
@ -2162,6 +2166,10 @@ static int handle_request(struct zoap_packet *request,
zoap_header_set_code(out.out_zpkt,
ZOAP_RESPONSE_CODE_NOT_ALLOWED);
r = 0;
} else if (r == -EEXIST) {
zoap_header_set_code(out.out_zpkt,
ZOAP_RESPONSE_CODE_BAD_REQUEST);
r = 0;
} else {
/* Failed to handle the request */
zoap_header_set_code(out.out_zpkt,