From: h.sandeep Date: Mon, 23 May 2016 13:53:30 +0000 (+0530) Subject: GATT-Server: Modify the "bt_gatt_server_send_response" API parameters. X-Git-Tag: submit/tizen/20160530.005331~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b093d596a15911a4dbb8718129854bc7bd2b2ca7;p=platform%2Fcore%2Fapi%2Fbluetooth.git GATT-Server: Modify the "bt_gatt_server_send_response" API parameters. Add Prameter resp_status and request_type to the API "bt_gatt_server_send_response". This Patch allows the Application to send reponse status after processing the Read/Write request from client. Change-Id: Ic5f25dd6adffcf32c19fb8e28a82c14fa364f3cc Signed-off-by: h.sandeep --- diff --git a/include/bluetooth_private.h b/include/bluetooth_private.h index e064c24..2ac8b06 100644 --- a/include/bluetooth_private.h +++ b/include/bluetooth_private.h @@ -291,8 +291,8 @@ typedef struct { bt_gatt_client_characteristic_value_changed_cb value_changed_cb; void *value_changed_user_data; - bt_gatt_server_value_changed_cb server_value_changed_cb; - void *server_value_changed_user_data; + bt_gatt_server_write_value_requested_cb write_value_requested_cb; + void *write_value_requested_user_data; bt_gatt_server_read_value_requested_cb read_requested_cb; void *read_requested_user_data; @@ -316,8 +316,8 @@ typedef struct { int permissions; - bt_gatt_server_value_changed_cb server_value_changed_cb; - void *server_value_changed_user_data; + bt_gatt_server_write_value_requested_cb write_value_requested_cb; + void *write_value_requested_user_data; bt_gatt_server_read_value_requested_cb read_requested_cb; void *read_requested_user_data; diff --git a/include/mobile/bluetooth_internal.h b/include/mobile/bluetooth_internal.h index 9d926a9..afd6e23 100644 --- a/include/mobile/bluetooth_internal.h +++ b/include/mobile/bluetooth_internal.h @@ -2135,10 +2135,10 @@ int bt_gatt_server_set_notification_state_change_cb(bt_gatt_h gatt_handle, * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @see bt_gatt_server_value_changed_cb() + * @see bt_gatt_server_write_value_requested_cb() */ -int bt_gatt_server_set_value_changed_cb(bt_gatt_h gatt_handle, - bt_gatt_server_value_changed_cb callback, +int bt_gatt_server_set_write_value_requested_cb(bt_gatt_h gatt_handle, + bt_gatt_server_write_value_requested_cb callback, void *user_data); /** @@ -2222,8 +2222,10 @@ int bt_gatt_server_start(void); * * @remarks Until this function is called, a read request is not finished. * - * @param[in] request_id The identification of a read request + * @param[in] request_id The identification of a read/write request + * @param[in] request_type The request type for read/write. * @param[in] offset The offset from where a value is read + * @param[in] resp_status The applciation error if any occured or BT_ERROR_NONE for successful. * @param[in] value The value to be sent. It will be sent from @a offset. If it is NULL, a requested GATT handle's value will be sent from @a offset. * @param[in] value_length Value Length * @return 0 on success, otherwise a negative error value @@ -2233,8 +2235,8 @@ int bt_gatt_server_start(void); * * @see bt_gatt_server_read_value_requested_cb() */ -int bt_gatt_server_send_response(int request_id, - int offset, char *value, int value_length); +int bt_gatt_server_send_response(int request_id, int request_type, + int offset, int resp_status, char *value, int value_length); /** * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE diff --git a/include/mobile/bluetooth_type_internal.h b/include/mobile/bluetooth_type_internal.h index 1a99bea..17c1805 100644 --- a/include/mobile/bluetooth_type_internal.h +++ b/include/mobile/bluetooth_type_internal.h @@ -242,17 +242,18 @@ typedef void *bt_gatt_server_h; * @param[in] remote_address The address of the remote device which requests a change * @param[in] server The GATT server handle * @param[in] gatt_handle The characteristic or descriptor's GATT handle which has an old value + * @param[in] request_id The identification of this request. It will be used to send a reponse. * @param[in] offset The requested offset from where the @a gatt_handle value will be updated * @param[in] value The new value * @param[in] len The length of @a value * @param[in] user_data The user data passed from the registration function * - * @see bt_gatt_server_set_value_changed_cb() + * @see bt_gatt_server_set_write_value_requested_cb() */ -typedef void (*bt_gatt_server_value_changed_cb) (char *remote_address, - bt_gatt_server_h server, bt_gatt_h gatt_handle, - int offset, char *value, int len, - void *user_data); +typedef void (*bt_gatt_server_write_value_requested_cb) (char *remote_address, + int request_id, bt_gatt_server_h server, + bt_gatt_h gatt_handle, int offset, + char *value, int len, void *user_data); /** * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE diff --git a/include/tv/bluetooth_internal.h b/include/tv/bluetooth_internal.h index c03dc13..1dcdbbf 100644 --- a/include/tv/bluetooth_internal.h +++ b/include/tv/bluetooth_internal.h @@ -2135,10 +2135,10 @@ int bt_gatt_server_set_notification_state_change_cb(bt_gatt_h gatt_handle, * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @see bt_gatt_server_value_changed_cb() + * @see bt_gatt_server_write_value_requested_cb() */ -int bt_gatt_server_set_value_changed_cb(bt_gatt_h gatt_handle, - bt_gatt_server_value_changed_cb callback, +int bt_gatt_server_set_write_value_requested_cb(bt_gatt_h gatt_handle, + bt_gatt_server_write_value_requested_cb callback, void *user_data); /** @@ -2222,8 +2222,10 @@ int bt_gatt_server_start(void); * * @remarks Until this function is called, a read request is not finished. * - * @param[in] request_id The identification of a read request + * @param[in] request_id The identification of a read/write request + * @param[in] request_type The request type for read/write. * @param[in] offset The offset from where a value is read + * @param[in] resp_status The applciation error if any occured or BT_ERROR_NONE for successful. * @param[in] value The value to be sent. It will be sent from @a offset. If it is NULL, a requested GATT handle's value will be sent from @a offset. * @param[in] value_length Value Length * @return 0 on success, otherwise a negative error value @@ -2233,8 +2235,8 @@ int bt_gatt_server_start(void); * * @see bt_gatt_server_read_value_requested_cb() */ -int bt_gatt_server_send_response(int request_id, - int offset, char *value, int value_length); +int bt_gatt_server_send_response(int request_id, int request_type, + int offset, int resp_status, char *value, int value_length); /** * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE diff --git a/include/tv/bluetooth_type_internal.h b/include/tv/bluetooth_type_internal.h index 1a99bea..17c1805 100644 --- a/include/tv/bluetooth_type_internal.h +++ b/include/tv/bluetooth_type_internal.h @@ -242,17 +242,18 @@ typedef void *bt_gatt_server_h; * @param[in] remote_address The address of the remote device which requests a change * @param[in] server The GATT server handle * @param[in] gatt_handle The characteristic or descriptor's GATT handle which has an old value + * @param[in] request_id The identification of this request. It will be used to send a reponse. * @param[in] offset The requested offset from where the @a gatt_handle value will be updated * @param[in] value The new value * @param[in] len The length of @a value * @param[in] user_data The user data passed from the registration function * - * @see bt_gatt_server_set_value_changed_cb() + * @see bt_gatt_server_set_write_value_requested_cb() */ -typedef void (*bt_gatt_server_value_changed_cb) (char *remote_address, - bt_gatt_server_h server, bt_gatt_h gatt_handle, - int offset, char *value, int len, - void *user_data); +typedef void (*bt_gatt_server_write_value_requested_cb) (char *remote_address, + int request_id, bt_gatt_server_h server, + bt_gatt_h gatt_handle, int offset, + char *value, int len, void *user_data); /** * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE diff --git a/include/wearable/bluetooth_internal.h b/include/wearable/bluetooth_internal.h index 87ff8c0..9d115b7 100644 --- a/include/wearable/bluetooth_internal.h +++ b/include/wearable/bluetooth_internal.h @@ -2781,10 +2781,10 @@ int bt_gatt_server_set_notification_state_change_cb(bt_gatt_h gatt_handle, * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter * @retval #BT_ERROR_NOT_SUPPORTED Not supported * - * @see bt_gatt_server_value_changed_cb() + * @see bt_gatt_server_write_value_requested_cb() */ -int bt_gatt_server_set_value_changed_cb(bt_gatt_h gatt_handle, - bt_gatt_server_value_changed_cb callback, +int bt_gatt_server_set_write_value_requested_cb(bt_gatt_h gatt_handle, + bt_gatt_server_write_value_requested_cb callback, void *user_data); /** @@ -2868,8 +2868,10 @@ int bt_gatt_server_start(void); * * @remarks Until this function is called, a read request is not finished. * - * @param[in] request_id The identification of a read request + * @param[in] request_id The identification of a read/write request + * @param[in] request_type The request type for read/write. * @param[in] offset The offset from where a value is read + * @param[in] resp_status The applciation error if any occured or BT_ERROR_NONE for successful. * @param[in] value The value to be sent. It will be sent from @a offset. If it is NULL, a requested GATT handle's value will be sent from @a offset. * @param[in] value_length Value Length * @return 0 on success, otherwise a negative error value @@ -2879,8 +2881,8 @@ int bt_gatt_server_start(void); * * @see bt_gatt_server_read_value_requested_cb() */ -int bt_gatt_server_send_response(int request_id, - int offset, char *value, int value_length); +int bt_gatt_server_send_response(int request_id, int request_type, + int offset, int resp_status, char *value, int value_length); /** * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE diff --git a/include/wearable/bluetooth_type_internal.h b/include/wearable/bluetooth_type_internal.h index f40f0ed..c4b1950 100644 --- a/include/wearable/bluetooth_type_internal.h +++ b/include/wearable/bluetooth_type_internal.h @@ -649,17 +649,18 @@ typedef void *bt_gatt_server_h; * @param[in] remote_address The address of the remote device which requests a change * @param[in] server The GATT server handle * @param[in] gatt_handle The characteristic or descriptor's GATT handle which has an old value + * @param[in] request_id The identification of this request. It will be used to send a reponse. * @param[in] offset The requested offset from where the @a gatt_handle value will be updated * @param[in] value The new value * @param[in] len The length of @a value * @param[in] user_data The user data passed from the registration function * - * @see bt_gatt_server_set_value_changed_cb() + * @see bt_gatt_server_set_write_value_requested_cb() */ -typedef void (*bt_gatt_server_value_changed_cb) (char *remote_address, - bt_gatt_server_h server, bt_gatt_h gatt_handle, - int offset, char *value, int len, - void *user_data); +typedef void (*bt_gatt_server_write_value_requested_cb) (char *remote_address, + int request_id, bt_gatt_server_h server, + bt_gatt_h gatt_handle, int offset, + char *value, int len, void *user_data); /** * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE diff --git a/src/bluetooth-common.c b/src/bluetooth-common.c index 43aa1e3..968e042 100644 --- a/src/bluetooth-common.c +++ b/src/bluetooth-common.c @@ -536,7 +536,7 @@ static bt_gatt_server_read_value_requested_cb __bt_gatt_attribute_get_read_cb( return NULL; } -static bt_gatt_server_value_changed_cb __bt_gatt_attribute_get_value_change_cb( +static bt_gatt_server_write_value_requested_cb __bt_gatt_attribute_get_value_change_cb( bt_gatt_h service, bt_gatt_h attribute, void **user_data) { gchar *svc_path = (gchar *)service; @@ -561,9 +561,9 @@ static bt_gatt_server_value_changed_cb __bt_gatt_attribute_get_value_change_cb( if (chr) { if (g_strcmp0(chr->path, att_path) == 0) { - if (chr->server_value_changed_cb) { - *user_data = chr->server_value_changed_user_data; - return chr->server_value_changed_cb; + if (chr->write_value_requested_cb) { + *user_data = chr->write_value_requested_user_data; + return chr->write_value_requested_cb; } else return NULL; } else { @@ -571,9 +571,9 @@ static bt_gatt_server_value_changed_cb __bt_gatt_attribute_get_value_change_cb( bt_gatt_descriptor_s *desc = l4->data; if (desc && g_strcmp0(desc->path, att_path) == 0) { - if (desc->read_requested_cb) { - *user_data = desc->server_value_changed_user_data; - return desc->server_value_changed_cb; + if (desc->write_value_requested_cb) { + *user_data = desc->write_value_requested_user_data; + return desc->write_value_requested_cb; } else return NULL; } @@ -1676,7 +1676,7 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us } case BLUETOOTH_EVENT_GATT_SERVER_VALUE_CHANGED: { bt_gatt_value_change_t *value_change = param->param_data; - bt_gatt_server_value_changed_cb cb; + bt_gatt_server_write_value_requested_cb cb; void *user_data = NULL; cb = __bt_gatt_attribute_get_value_change_cb(value_change->service_handle, value_change->att_handle, &user_data); @@ -1689,11 +1689,7 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us return; } - bluetooth_gatt_send_response(value_change->req_id, - BLUETOOTH_GATT_ATT_REQUEST_TYPE_WRITE, - BLUETOOTH_ERROR_NONE, 0, NULL, 0); - - cb(value_change->address, value_change->service_handle, + cb(value_change->address, value_change->req_id, value_change->service_handle, value_change->att_handle, value_change->offset, (char *)value_change->att_value, value_change->val_len, user_data); break; @@ -1773,10 +1769,10 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us chr->value = g_memdup(char_val->char_value, char_val->val_len); chr->value_length = char_val->val_len; /* TODO : Fix build error temporary */ - if (chr->server_value_changed_cb) - chr->server_value_changed_cb(NULL, (bt_gatt_server_h)serv, (bt_gatt_h)chr, - 0, (char *)char_val->char_value, char_val->val_len, - chr->server_value_changed_user_data); + if (chr->write_value_requested_cb) + chr->write_value_requested_cb(NULL, 0, (bt_gatt_server_h)serv, (bt_gatt_h)chr, + 0, (char*)char_val->char_value, char_val->val_len, + chr->write_value_requested_user_data); } } } diff --git a/src/bluetooth-gatt.c b/src/bluetooth-gatt.c index e175aef..e510ab3 100644 --- a/src/bluetooth-gatt.c +++ b/src/bluetooth-gatt.c @@ -2306,22 +2306,17 @@ int bt_gatt_server_start(void) return ret; } -int bt_gatt_server_send_response(int request_id, - int offset, char *value, int value_length) +int bt_gatt_server_send_response(int request_id, int request_type, + int offset, int resp_status, char *value, int value_length) { int ret = BT_ERROR_NONE; BT_CHECK_INIT_STATUS(); - BT_CHECK_INPUT_PARAMETER(value); - if (value_length <= 0) + if (value_length < 0) return BT_ERROR_INVALID_PARAMETER; - /* By Default the response is sent for read requests, - * once the new parameters available to CAPI API, the below - * code be made generic for both read and write */ ret = _bt_get_error_code(bluetooth_gatt_send_response(request_id, - BLUETOOTH_GATT_ATT_REQUEST_TYPE_READ, - BT_ERROR_NONE, + request_type, resp_status, offset, value, value_length)); if (ret != BT_ERROR_NONE) @@ -2373,8 +2368,8 @@ int bt_gatt_server_notify(bt_gatt_h characteristic, bool need_confirm, return ret; } -int bt_gatt_server_set_value_changed_cb(bt_gatt_h gatt_handle, - bt_gatt_server_value_changed_cb callback, +int bt_gatt_server_set_write_value_requested_cb(bt_gatt_h gatt_handle, + bt_gatt_server_write_value_requested_cb callback, void *user_data) { bt_gatt_common_s *handle = (bt_gatt_common_s *)gatt_handle; @@ -2387,11 +2382,11 @@ int bt_gatt_server_set_value_changed_cb(bt_gatt_h gatt_handle, BT_CHECK_INPUT_PARAMETER(callback); if (handle->type == BT_GATT_TYPE_CHARACTERISTIC) { - chr->server_value_changed_cb = callback; - chr->server_value_changed_user_data = user_data; + chr->write_value_requested_cb = callback; + chr->write_value_requested_user_data = user_data; } else if (handle->type == BT_GATT_TYPE_DESCRIPTOR) { - desc->server_value_changed_cb = callback; - desc->server_value_changed_user_data = user_data; + desc->write_value_requested_cb = callback; + desc->write_value_requested_user_data = user_data; } else { BT_ERR("Type is invalid(type:%d)", handle->type); return BT_ERROR_INVALID_PARAMETER; diff --git a/test/bt_unit_test.c b/test/bt_unit_test.c index a4ebc72..891fcfb 100644 --- a/test/bt_unit_test.c +++ b/test/bt_unit_test.c @@ -1495,6 +1495,7 @@ void __bt_gatt_server_read_value_requested_cb( int offset, void *user_data) { char char_value_1[3] = {0, 1, 2}; + int resp_status = BT_ERROR_NONE; TC_PRT("__bt_gatt_server_read_value_requested_cb"); TC_PRT("remote_address %s", remote_address); @@ -1503,8 +1504,9 @@ void __bt_gatt_server_read_value_requested_cb( TC_PRT("gatt_handle %s", (char *)gatt_handle); TC_PRT("Offset %d", offset); /* Get the attribute new values here */ - bt_gatt_server_send_response(request_id, offset, - char_value_1, 3 - offset); + bt_gatt_server_send_response(request_id, + BLUETOOTH_GATT_ATT_REQUEST_TYPE_READ, offset, + resp_status, char_value_1, 3 - offset); } void __bt_gatt_server_notification_state_change_cb(bool notify, @@ -2341,17 +2343,22 @@ void __bt_gatt_server_notification_sent_cb(int result, TC_PRT("characteristic : %p", characteristic); } -void __bt_gatt_server_value_changed_cb(char *remote_address, - bt_gatt_server_h server, bt_gatt_h gatt_handle, - int offset, char *value, int len, void *user_data) +void __bt_gatt_server_write_value_requested_cb(char *remote_address, + int request_id, bt_gatt_server_h server, + bt_gatt_h gatt_handle, int offset, + char *value, int len, void *user_data) { - int i; + int i, resp_status = BT_ERROR_NONE; TC_PRT("remote_address : %s", remote_address); TC_PRT("offset : %d", offset); TC_PRT("len [%d] : ", len); for (i = 0; i < len; i++) printf("%d ", value[i]); + bt_gatt_server_send_response(request_id, + BLUETOOTH_GATT_ATT_REQUEST_TYPE_WRITE, offset, + resp_status, NULL, 0); + printf("\n"); } @@ -6141,10 +6148,10 @@ int test_input_callback(void *data) value_length, &characteristic); TC_PRT("bt_gatt_characteristic_create : %s\n", __bt_get_error_message(ret)); - ret = bt_gatt_server_set_value_changed_cb(characteristic, - __bt_gatt_server_value_changed_cb, + ret = bt_gatt_server_set_write_value_requested_cb(characteristic, + __bt_gatt_server_write_value_requested_cb, NULL); - TC_PRT("bt_gatt_server_set_value_changed_cb : %s\n", __bt_get_error_message(ret)); + TC_PRT("bt_gatt_server_set_write_value_requested_cb : %s\n", __bt_get_error_message(ret)); bt_gatt_server_set_read_value_requested_cb(characteristic, __bt_gatt_server_read_value_requested_cb, NULL); @@ -6200,8 +6207,8 @@ int test_input_callback(void *data) bt_gatt_server_set_read_value_requested_cb(descriptor, __bt_gatt_server_read_value_requested_cb, NULL); - ret = bt_gatt_server_set_value_changed_cb(descriptor, - __bt_gatt_server_value_changed_cb, + ret = bt_gatt_server_set_write_value_requested_cb(descriptor, + __bt_gatt_server_write_value_requested_cb, NULL); ret = bt_gatt_characteristic_add_descriptor(characteristic, descriptor);