diff --git a/pkg/wakaama/contrib/lwm2m_client.c b/pkg/wakaama/contrib/lwm2m_client.c index 6d8fd0448c..e2f8d8deea 100644 --- a/pkg/wakaama/contrib/lwm2m_client.c +++ b/pkg/wakaama/contrib/lwm2m_client.c @@ -119,8 +119,6 @@ static credman_tag_t _get_credential(const sock_udp_ep_t *ep, uint8_t security_m /* prepare query */ lwm2m_uri_t query_uri = { .objectId = LWM2M_SECURITY_OBJECT_ID, - // .resourceId = LWM2M_SECURITY_URI_ID, - .flag = LWM2M_URI_FLAG_OBJECT_ID | LWM2M_URI_FLAG_INSTANCE_ID | LWM2M_URI_FLAG_RESOURCE_ID }; lwm2m_list_t *instance = sec->instanceList; @@ -413,7 +411,6 @@ void lwm2m_client_refresh_dtls_credentials(void) /* prepare query */ lwm2m_uri_t query_uri = { .objectId = LWM2M_SECURITY_OBJECT_ID, - .flag = LWM2M_URI_FLAG_OBJECT_ID | LWM2M_URI_FLAG_INSTANCE_ID | LWM2M_URI_FLAG_RESOURCE_ID }; lwm2m_list_t *instance = sec->instanceList; diff --git a/pkg/wakaama/contrib/lwm2m_client_connection.c b/pkg/wakaama/contrib/lwm2m_client_connection.c index ac3349bda7..2d3a8f02a0 100644 --- a/pkg/wakaama/contrib/lwm2m_client_connection.c +++ b/pkg/wakaama/contrib/lwm2m_client_connection.c @@ -284,7 +284,6 @@ static lwm2m_client_connection_t *_connection_create(uint16_t sec_obj_inst_id, .objectId = LWM2M_SECURITY_URI_ID, .instanceId = sec_obj_inst_id, .resourceId = LWM2M_SECURITY_URI_ID, - .flag = LWM2M_URI_FLAG_OBJECT_ID | LWM2M_URI_FLAG_INSTANCE_ID | LWM2M_URI_FLAG_RESOURCE_ID }; int res = lwm2m_get_string(client_data, &resource_uri, uri, &uri_len); diff --git a/pkg/wakaama/contrib/objects/common.c b/pkg/wakaama/contrib/objects/common.c index 88ec3511e3..a32c5f8eb8 100644 --- a/pkg/wakaama/contrib/objects/common.c +++ b/pkg/wakaama/contrib/objects/common.c @@ -76,7 +76,7 @@ static int _get_resource_data(lwm2m_client_data_t *client_data, const lwm2m_uri_ data->id = uri->resourceId; /* read the resource from the specified instance */ - uint8_t res = object->readFunc(uri->instanceId, &data_num, &data, object); + uint8_t res = object->readFunc(client_data->lwm2m_ctx, uri->instanceId, &data_num, &data, object); if (res != COAP_205_CONTENT || data->type != expected_type) { result = -EINVAL; goto out; @@ -245,7 +245,7 @@ static int _set_resource_data(lwm2m_client_data_t *client_data, const lwm2m_uri_ } /* write the resource of the specified instance */ - uint8_t res = object->writeFunc(uri->instanceId, 1, data, object); + uint8_t res = object->writeFunc(client_data->lwm2m_ctx, uri->instanceId, 1, data, object, LWM2M_WRITE_PARTIAL_UPDATE); lwm2m_resource_value_changed(client_data->lwm2m_ctx, uri); if (res != COAP_204_CHANGED) { diff --git a/pkg/wakaama/contrib/objects/device.c b/pkg/wakaama/contrib/objects/device.c index aebc1713cb..065c01f331 100644 --- a/pkg/wakaama/contrib/objects/device.c +++ b/pkg/wakaama/contrib/objects/device.c @@ -36,6 +36,7 @@ static bool reboot; /** * @brief 'Execute' callback for the Device object. * + * @param[in] context LWM2M Context * @param[in] instance_id Instance ID. Should be 0 as a single instance exists. * @param[in] resource_id ID of the resource to execute. * @param[in] buffer Information needed for the execution. @@ -47,12 +48,13 @@ static bool reboot; * @return COAP_400_BAD_REQUEST when wrong information has been sent * @return COAP_405_METHOD_NOT_ALLOWED when trying to execute a resource that is not supported */ -static uint8_t _execute_cb(uint16_t instance_id, uint16_t resource_id, uint8_t *buffer, int length, - lwm2m_object_t *object); +static uint8_t _execute_cb(lwm2m_context_t * context, uint16_t instance_id, uint16_t resource_id, + uint8_t * buffer, int length, lwm2m_object_t * object); /** * @brief 'Read' callback for the Device object. * + * @param[in] context LWM2M Context * @param[in] instance_id Instance ID. Should be 0 as a single instance exists. * @param[in, out] num_data Number of resources requested. 0 means all. * @param[in, out] data_array Initialized data array to output the values, @@ -63,12 +65,13 @@ static uint8_t _execute_cb(uint16_t instance_id, uint16_t resource_id, uint8_t * * @return COAP_404_NOT_FOUND when resource can't be found * @return COAP_500_INTERNAL_SERVER_ERROR otherwise */ -static uint8_t _read_cb(uint16_t instance_id, int *num_data, lwm2m_data_t **data_array, - lwm2m_object_t *object); +static uint8_t _read_cb(lwm2m_context_t * context, uint16_t instance_id, int * num_data, + lwm2m_data_t ** data_array, lwm2m_object_t * object); /** * @brief 'Discover' callback for the Device object. * + * @param[in] context LWM2M Context * @param[in] instance_id Instance ID. Should be 0 as a single instance exists. * @param[in, out] num_data Number of resources requested. 0 means all. * @param[in, out] data_array Initialized data array to determine if the resource exists, @@ -79,8 +82,8 @@ static uint8_t _read_cb(uint16_t instance_id, int *num_data, lwm2m_data_t **data * @return COAP_404_NOT_FOUND when a resource is not supported * @return COAP_500_INTERNAL_SERVER_ERROR otherwise */ -static uint8_t _discover_cb(uint16_t instance_id, int *num_data, lwm2m_data_t **data_array, - lwm2m_object_t *object); +static uint8_t _discover_cb(lwm2m_context_t * context, uint16_t instance_id, int * num_data, + lwm2m_data_t ** data_array, lwm2m_object_t * object); typedef struct { lwm2m_list_t list; /**< Linked list handle */ @@ -95,7 +98,7 @@ static lwm2m_object_t _device_object = { .next = NULL, .objID = LWM2M_DEVICE_OBJECT_ID, .instanceList = (lwm2m_list_t *)&_instance, - .readFunc = _read_cb, + .readFunc = _read_cb, .executeFunc = _execute_cb, .discoverFunc = _discover_cb, .writeFunc = NULL, @@ -104,12 +107,13 @@ static lwm2m_object_t _device_object = { .userData = NULL }; -static uint8_t _discover_cb(uint16_t instance_id, int *num_data, lwm2m_data_t **data_array, - lwm2m_object_t *object) +static uint8_t _discover_cb(lwm2m_context_t * context, uint16_t instance_id, int * num_data, + lwm2m_data_t ** data_array, lwm2m_object_t * object) { uint8_t result; int i; + (void)context; (void)object; if (instance_id != 0) { @@ -166,9 +170,10 @@ static uint8_t _discover_cb(uint16_t instance_id, int *num_data, lwm2m_data_t ** return result; } -static uint8_t _read_cb(uint16_t instance_id, int *num_data, lwm2m_data_t **data_array, - lwm2m_object_t *object) +static uint8_t _read_cb(lwm2m_context_t * context, uint16_t instance_id, int * num_data, + lwm2m_data_t ** data_array, lwm2m_object_t * object) { + (void)context; (void)object; int i; DEBUG("[lwm2m:device:read]\n"); @@ -264,9 +269,10 @@ static uint8_t _read_cb(uint16_t instance_id, int *num_data, lwm2m_data_t **data return COAP_205_CONTENT; } -static uint8_t _execute_cb(uint16_t instance_id, uint16_t resource_id, uint8_t *buffer, int length, - lwm2m_object_t *object) +static uint8_t _execute_cb(lwm2m_context_t * context, uint16_t instance_id, uint16_t resource_id, + uint8_t * buffer, int length, lwm2m_object_t * object) { + (void)context; (void)buffer; (void)object; diff --git a/pkg/wakaama/contrib/objects/ipso_sensor_base.c b/pkg/wakaama/contrib/objects/ipso_sensor_base.c index a2e498c913..0caf58189c 100644 --- a/pkg/wakaama/contrib/objects/ipso_sensor_base.c +++ b/pkg/wakaama/contrib/objects/ipso_sensor_base.c @@ -28,7 +28,8 @@ /** * @brief 'Read' callback for the LwM2M Illuminance Sensor object implementation. - * + * + * @param[in] context LWM2M Context * @param[in] instance_id ID of the instance to read resource from. * @param[in] num_data Number of elements in @p data_array. * @param[in, out] data_array IDs of resources to read. Array of data structures to place values. @@ -38,12 +39,13 @@ * @return COAP_404_NOT_FOUND if the instance was not found * @return COAP_500_INTERNAL_SERVER_ERROR otherwise */ -static uint8_t _read_cb(uint16_t instance_id, int *num_data, lwm2m_data_t **data_array, - lwm2m_object_t *object); +static uint8_t _read_cb(lwm2m_context_t * context, uint16_t instance_id, int * num_data, + lwm2m_data_t ** data_array, lwm2m_object_t * object); /** * @brief 'Execute' callback for the LwM2M Illuminance Sensor object implementation. * + * @param[in] context LWM2M Context * @param[in] instance_id ID of the instance to execute resource from. * @param[in] resource_id ID of the resource to execute. * @param[in] buffer Pointer to the buffer containing the payload. @@ -54,8 +56,8 @@ static uint8_t _read_cb(uint16_t instance_id, int *num_data, lwm2m_data_t **data * @return COAP_404_NOT_FOUND if the instance was not found * @return COAP_405_METHOD_NOT_ALLOWED if the resource is not executable */ -static uint8_t _exec_cb(uint16_t instance_id, uint16_t resource_id, uint8_t *buffer, int length, - lwm2m_object_t *object); +static uint8_t _exec_cb(lwm2m_context_t * context, uint16_t instance_id, uint16_t resource_id, + uint8_t * buffer, int length, lwm2m_object_t * object); /** * @brief Gets the current value of a given @p instance. @@ -193,9 +195,11 @@ static uint8_t _get_value(lwm2m_data_t *data, lwm2m_obj_ipso_sensor_base_inst_t return COAP_205_CONTENT; } -static uint8_t _read_cb(uint16_t instance_id, int *num_data, lwm2m_data_t **data_array, - lwm2m_object_t *object) +static uint8_t _read_cb(lwm2m_context_t * context, uint16_t instance_id, int * num_data, + lwm2m_data_t ** data_array, lwm2m_object_t * object) { + (void)context; + lwm2m_obj_ipso_sensor_base_inst_t *instance; uint8_t result; int i = 0; @@ -252,9 +256,10 @@ out: return result; } -static uint8_t _exec_cb(uint16_t instance_id, uint16_t resource_id, uint8_t *buffer, int length, - lwm2m_object_t *object) +static uint8_t _exec_cb(lwm2m_context_t * context, uint16_t instance_id, uint16_t resource_id, + uint8_t * buffer, int length, lwm2m_object_t * object); { + (void)context; (void)buffer; (void)length; diff --git a/pkg/wakaama/contrib/objects/light_control.c b/pkg/wakaama/contrib/objects/light_control.c index 4f61c6fc9c..fd0ea09361 100644 --- a/pkg/wakaama/contrib/objects/light_control.c +++ b/pkg/wakaama/contrib/objects/light_control.c @@ -46,7 +46,8 @@ typedef struct lwm2m_obj_light_control_inst { /** * @brief 'Read' callback for the LwM2M Light Control object implementation. - * + * + * @param[in] context LWM2M Context * @param[in] instance_id ID of the instance to read resource from. * @param[in] num_data Number of elements in @p data_array. * @param[in, out] data_array IDs of resources to read. Array of data structures to place values. @@ -56,12 +57,13 @@ typedef struct lwm2m_obj_light_control_inst { * @return COAP_404_NOT_FOUND if the instance was not found * @return COAP_500_INTERNAL_SERVER_ERROR otherwise */ -static uint8_t _read_cb(uint16_t instance_id, int *num_data, lwm2m_data_t **data_array, - lwm2m_object_t *object); +static uint8_t _read_cb(lwm2m_context_t * context, uint16_t instance_id, int * num_data, + lwm2m_data_t ** data_array, lwm2m_object_t * object); /** * @brief 'Write' callback for the LwM2M Light Control object implementation. * + * @param[in] context LWM2M Context * @param[in] instance_id ID of the instance to write resource to. * @param[in] num_data Number of elements in @p data_array. * @param[in] data_array IDs of resources to write and values. @@ -72,8 +74,8 @@ static uint8_t _read_cb(uint16_t instance_id, int *num_data, lwm2m_data_t **data * @return COAP_400_BAD_REQUEST if a value is not encoded correctly * @return COAP_500_INTERNAL_SERVER_ERROR otherwise */ -static uint8_t _write_cb(uint16_t instance_id, int num_data, lwm2m_data_t * data_array, - lwm2m_object_t * object); +static uint8_t _write_cb(lwm2m_context_t * context, uint16_t instance_id, int num_data, + lwm2m_data_t * data_array, lwm2m_object_t * object, lwm2m_write_type_t write_type); /** * @brief Gets the current value of a given @p instance. @@ -154,9 +156,11 @@ static uint8_t _get_value(lwm2m_data_t *data, lwm2m_obj_light_control_inst_t *in return COAP_205_CONTENT; } -static uint8_t _read_cb(uint16_t instance_id, int *num_data, lwm2m_data_t **data_array, - lwm2m_object_t *object) +static uint8_t _read_cb(lwm2m_context_t * context, uint16_t instance_id, int * num_data, + lwm2m_data_t ** data_array, lwm2m_object_t * object) { + (void)context; + lwm2m_obj_light_control_inst_t *instance; uint8_t result = COAP_404_NOT_FOUND; int i = 0; @@ -214,9 +218,12 @@ free_out: return result; } -static uint8_t _write_cb(uint16_t instance_id, int num_data, lwm2m_data_t * data_array, - lwm2m_object_t * object) +static uint8_t _write_cb(lwm2m_context_t * context, uint16_t instance_id, int num_data, + lwm2m_data_t * data_array, lwm2m_object_t * object, lwm2m_write_type_t write_type) { + (void)context; + (void)write_type; + lwm2m_obj_light_control_inst_t *instance; uint8_t result = COAP_204_CHANGED; bool call_cb = false; @@ -336,7 +343,6 @@ free_out: static void _mark_resource_changed(uint16_t instance_id, uint16_t resource_id) { lwm2m_uri_t uri; - uri.flag = LWM2M_URI_FLAG_OBJECT_ID | LWM2M_URI_FLAG_INSTANCE_ID | LWM2M_URI_FLAG_RESOURCE_ID; uri.objectId = LWM2M_LIGHT_CONTROL_OBJECT_ID; uri.instanceId = instance_id; uri.resourceId = resource_id; diff --git a/pkg/wakaama/contrib/objects/security.c b/pkg/wakaama/contrib/objects/security.c index 3bc2897460..3cddee7a01 100644 --- a/pkg/wakaama/contrib/objects/security.c +++ b/pkg/wakaama/contrib/objects/security.c @@ -119,6 +119,7 @@ typedef struct lwm2m_obj_security_inst { /** * @brief 'Read' callback for the security object. * + * @param[in] context LWM2M Context * @param[in] instance_id ID of the instance to read * @param[in, out] num_data Number of resources requested. 0 means all. * @param[in, out] data_array Initialized data array to output the values, @@ -129,12 +130,13 @@ typedef struct lwm2m_obj_security_inst { * @retval COAP_404_NOT_FOUND when resource can't be found * @retval COAP_500_INTERNAL_SERVER_ERROR otherwise */ -static uint8_t _read_cb(uint16_t instance_id, int *num_data, lwm2m_data_t *data_array[], - lwm2m_object_t *object); +static uint8_t _read_cb(lwm2m_context_t * context, uint16_t instance_id, int * num_data, + lwm2m_data_t ** data_array, lwm2m_object_t * object); /** * @brief 'Write' callback for the security object. - * + + * @param[in] context LWM2M Context * @param[in] instance_id ID of the instance to write to * @param[in] num_data Number of resources to write * @param[in] data_array Array of data to write @@ -143,23 +145,27 @@ static uint8_t _read_cb(uint16_t instance_id, int *num_data, lwm2m_data_t *data_ * @retval COAP_204_CHANGED on success * @retval COAP_400_BAD_REQUEST otherwise */ -static uint8_t _write_cb(uint16_t instance_id, int num_data, lwm2m_data_t *data_array, - lwm2m_object_t *object); +static uint8_t _write_cb(lwm2m_context_t * context, uint16_t instance_id, int num_data, + lwm2m_data_t * data_array, lwm2m_object_t * object, + lwm2m_write_type_t write_type); /** * @brief 'Delete' callback for the security object. * + * @param[in] context LWM2M Context * @param[in] instance_id ID of the instance to delete * @param[in] object Security object pointer * * @retval COAP_202_DELETED on success * @retval COAP_404_NOT_FOUND when the instance can't be found */ -static uint8_t _delete_cb(uint16_t instance_id, lwm2m_object_t *object); +static uint8_t _delete_cb(lwm2m_context_t * context, uint16_t instance_id, + lwm2m_object_t * object); /** * @brief 'Create' callback for the security object. * + * @param[in] context LWM2M Context * @param[in] instance_id ID of the instance to create * @param[in] num_data Number of resources to write * @param[in] data_array Array of data to write @@ -168,8 +174,8 @@ static uint8_t _delete_cb(uint16_t instance_id, lwm2m_object_t *object); * @retval COAP_201_CREATED on success * @retval COAP_500_INTERNAL_SERVER_ERROR otherwise */ -static uint8_t _create_cb(uint16_t instance_id, int num_data, lwm2m_data_t *data_array, - lwm2m_object_t *object); +static uint8_t _create_cb(lwm2m_context_t * context, uint16_t instance_id, int num_data, + lwm2m_data_t * data_array, lwm2m_object_t * object); /** * @brief Get a value from a security object instance. @@ -392,9 +398,11 @@ static int _get_value(lwm2m_data_t *data, lwm2m_obj_security_inst_t *instance) return COAP_205_CONTENT; } -static uint8_t _read_cb(uint16_t instance_id, int *num_data, lwm2m_data_t *data_array[], - lwm2m_object_t *object) +static uint8_t _read_cb(lwm2m_context_t * context, uint16_t instance_id, int * num_data, + lwm2m_data_t ** data_array, lwm2m_object_t * object) { + (void)context; + lwm2m_obj_security_inst_t *instance; uint8_t result; int i = 0; @@ -458,9 +466,12 @@ out: return result; } -static uint8_t _write_cb(uint16_t instance_id, int num_data, lwm2m_data_t *data_array, - lwm2m_object_t *object) +static uint8_t _write_cb(lwm2m_context_t * context, uint16_t instance_id, int num_data, + lwm2m_data_t * data_array, lwm2m_object_t * object, + lwm2m_write_type_t write_type) { + (void)context; + (void)write_type; lwm2m_obj_security_inst_t *instance; int64_t value; uint8_t result = COAP_404_NOT_FOUND; @@ -641,8 +652,10 @@ out: return result; } -static uint8_t _delete_cb(uint16_t instance_id, lwm2m_object_t *object) +static uint8_t _delete_cb(lwm2m_context_t * context, uint16_t instance_id, + lwm2m_object_t * object) { + (void)context; uint8_t result = COAP_404_NOT_FOUND; lwm2m_obj_security_inst_t *instance; @@ -679,9 +692,11 @@ free_out: return result; } -static uint8_t _create_cb(uint16_t instance_id, int num_data, lwm2m_data_t *data_array, - lwm2m_object_t *object) +static uint8_t _create_cb(lwm2m_context_t * context, uint16_t instance_id, int num_data, + lwm2m_data_t * data_array, lwm2m_object_t * object) { + (void)context; + lwm2m_obj_security_inst_t *instance; uint8_t result; @@ -718,10 +733,10 @@ static uint8_t _create_cb(uint16_t instance_id, int num_data, lwm2m_data_t *data object->instanceList = LWM2M_LIST_ADD(object->instanceList, instance); /* write incoming data to the instance */ - result = _write_cb(instance_id, num_data, data_array, object); + result = _write_cb(context, instance_id, num_data, data_array, object, LWM2M_WRITE_PARTIAL_UPDATE); if (result != COAP_204_CHANGED) { - _delete_cb(instance_id, object); + _delete_cb(context,instance_id, object); } else { result = COAP_201_CREATED; diff --git a/pkg/wakaama/doc.txt b/pkg/wakaama/doc.txt index 6641083515..0901c9cfa5 100644 --- a/pkg/wakaama/doc.txt +++ b/pkg/wakaama/doc.txt @@ -67,7 +67,7 @@ * obj_list[1] = lwm2m_client_get_server_object(&client_data, CONFIG_LWM2M_SERVER_SHORT_ID); * * // device object has a single instance. All the information for now is defined at compile-time - * obj_list[2] = lwm2m_object_device_get(); + * obj_list[2] = lwm2m_object_device_init(&client_data); * * // run the LwM2M client * lwm2m_client_run(&client_data, obj_list, ARRAY_SIZE(obj_list);