GATT-Server: Modify the "bt_gatt_server_send_response" API parameters. 93/70993/4
authorh.sandeep <h.sandeep@samsung.com>
Mon, 23 May 2016 13:53:30 +0000 (19:23 +0530)
committerSandeep Hattiholi <h.sandeep@samsung.com>
Tue, 24 May 2016 10:07:54 +0000 (03:07 -0700)
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 <h.sandeep@samsung.com>
include/bluetooth_private.h
include/mobile/bluetooth_internal.h
include/mobile/bluetooth_type_internal.h
include/tv/bluetooth_internal.h
include/tv/bluetooth_type_internal.h
include/wearable/bluetooth_internal.h
include/wearable/bluetooth_type_internal.h
src/bluetooth-common.c
src/bluetooth-gatt.c
test/bt_unit_test.c

index e064c2456e9933b872fb97ce6b6bd6553b75e390..2ac8b06579758673ad8a3add6176d09f27a27f50 100644 (file)
@@ -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;
index 9d926a999825693252e72447b202839be27845aa..afd6e235043bf511f59ce976568e4e1376871f9a 100644 (file)
@@ -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
index 1a99beae2156b1637091823bb04f810189b86f85..17c180518da9741dd2bce576148ee806dda6345e 100644 (file)
@@ -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
index c03dc136576a087cb10d552416fc09b7e097746c..1dcdbbf776e70b6f5ff95ab5fcbc06e1f21b2feb 100644 (file)
@@ -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
index 1a99beae2156b1637091823bb04f810189b86f85..17c180518da9741dd2bce576148ee806dda6345e 100644 (file)
@@ -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
index 87ff8c0b159457b848f67e0c06fed478697bfb14..9d115b7fa04fb90cedaa3e0da8e7de209429a9f5 100644 (file)
@@ -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
index f40f0ed0da996d7636684d3e61fab58776b2682b..c4b19500278fcc4405a289b1baa1fe8afd2370e0 100644 (file)
@@ -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
index 43aa1e37f327d87ead9dd615a5d614873494560f..968e0429bc301e4cdefbcda86ab2020d7badddb6 100644 (file)
@@ -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);
                                        }
                                }
                        }
index e175aefe63a04e8b88bc6f5247b0b7fa91b17f8f..e510ab3b1a744a0148e31cadbfedef1c1db56d70 100644 (file)
@@ -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;
index a4ebc72f430d5508651b695faa6ab1d6d854c4cb..891fcfb2ba0f0dc627b9eba15fa4208bfc449636 100644 (file)
@@ -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);