Fix: multiple gatt server apps send response for read/write request 14/237714/1
authorinjun.yang <injun.yang@samsung.com>
Thu, 18 Jun 2020 05:00:05 +0000 (14:00 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Fri, 3 Jul 2020 01:49:28 +0000 (10:49 +0900)
[Model] All
[BinType] AP
[Customer] OPEN

[Issue#] N/A
[Request] Internal
[Occurrence Version] N/A

[Problem] gatt client receive ATT error for read/write request.
[Cause & Measure] If several gatt server apps is running, all apps send respone.
 One of them, send ATT error.
[Checking Method] Multiple gatt server app > read/write request on client

[Team] Convergence BT
[Developer] Injun Yang
[Solution company] Samsung
[Change Type] Specification change

Change-Id: I2a48d70ef988e8a507df407d9100f7b1ccf32251
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
src/bluetooth-common.c

index 9326803..34aa11c 100644 (file)
@@ -871,7 +871,7 @@ static int __bt_get_bt_device_connection_info_s(bt_device_connection_info_s **de
 #ifdef TIZEN_FEATURE_GATT_RELAY
 /* Search for handle */
 static bt_gatt_server_read_value_requested_cb __bt_gatt_attribute_get_read_cb(int att_handle, bt_gatt_server_h *server,
-                                               bt_gatt_h *gatt_handle, void **user_data)
+                                               bt_gatt_h *gatt_handle, bool *is_own_handle, void **user_data)
 {
        const GSList *gatt_server_list = NULL;
        const GSList *l1, *l2, *l3, *l4;
@@ -886,16 +886,18 @@ static bt_gatt_server_read_value_requested_cb __bt_gatt_attribute_get_read_cb(in
 
                for (l2 = serv->services; l2 != NULL; l2 = l2->next) {
                        bt_gatt_service_s *svc = l2->data;
+
                        for (l3 = svc->characteristics; l3 != NULL; l3 = l3->next) {
                                bt_gatt_characteristic_s *chr = l3->data;
 
                                if (chr) {
                                        if (chr->handle == att_handle) {
                                                if (chr->read_requested_cb) {
-                                                       BT_INFO("GATT Server: Handle search match found! Its a characteristic: UUID [%s]", chr->uuid);
+                                                       BT_DBG("GATT Server: char handle found [%s]", chr->uuid);
                                                        *user_data = chr->read_requested_user_data;
                                                        *gatt_handle = chr;
                                                        *server = serv;
+                                                       *is_own_handle = true;
                                                        return chr->read_requested_cb;
                                                } else
                                                        return NULL;
@@ -908,7 +910,8 @@ static bt_gatt_server_read_value_requested_cb __bt_gatt_attribute_get_read_cb(in
                                                                        *user_data = desc->read_requested_user_data;
                                                                        *gatt_handle = desc;
                                                                        *server = serv;
-                                                                       BT_INFO("GATT Server: Handle search match found! Its a Desc UUID [%s]", desc->uuid);
+                                                                       *is_own_handle = true;
+                                                                       BT_DBG("GATT Server: desc handle found [%s]", desc->uuid);
                                                                        return desc->read_requested_cb;
                                                                } else
                                                                        return NULL;
@@ -923,7 +926,7 @@ static bt_gatt_server_read_value_requested_cb __bt_gatt_attribute_get_read_cb(in
 }
 
 static bt_gatt_server_write_value_requested_cb __bt_gatt_attribute_get_value_change_cb(int att_handle, bt_gatt_h *server,
-                               bt_gatt_h *gatt_handle, void **user_data)
+                               bt_gatt_h *gatt_handle, bool *is_own_handle, void **user_data)
 {
        const GSList *gatt_server_list = NULL;
        const GSList *l1, *l2, *l3, *l4;
@@ -938,16 +941,18 @@ static bt_gatt_server_write_value_requested_cb __bt_gatt_attribute_get_value_cha
 
                for (l2 = serv->services; l2 != NULL; l2 = l2->next) {
                        bt_gatt_service_s *svc = l2->data;
+
                        for (l3 = svc->characteristics; l3 != NULL; l3 = l3->next) {
                                bt_gatt_characteristic_s *chr = l3->data;
 
                                if (chr) {
                                        if (chr->handle == att_handle) {
                                                if (chr->write_value_requested_cb) {
-                                                       BT_INFO("GATT Server: Handle search match found! Its a characteristic: UUID [%s]", chr->uuid);
+                                                       BT_DBG("GATT Server: char handle found [%s]", chr->uuid);
                                                        *user_data = chr->write_value_requested_user_data;
                                                        *gatt_handle = chr;
                                                        *server = svc;
+                                                       *is_own_handle = true;
                                                        return chr->write_value_requested_cb;
                                                } else
                                                        return NULL;
@@ -960,7 +965,8 @@ static bt_gatt_server_write_value_requested_cb __bt_gatt_attribute_get_value_cha
                                                                        *user_data = desc->write_value_requested_user_data;
                                                                        *gatt_handle = desc;
                                                                        *server = svc;
-                                                                       BT_INFO("GATT Server: Handle search match found! Its a Desc UUID [%s]", desc->uuid);
+                                                                       *is_own_handle = true;
+                                                                       BT_DBG("GATT Server: desc handle found [%s]", desc->uuid);
                                                                        return desc->write_value_requested_cb;
                                                                } else
                                                                        return NULL;
@@ -2597,28 +2603,28 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                void *user_data_read = NULL;
                bt_gatt_h gatt_handle = NULL;
                bt_gatt_server_h serv = NULL;
+               bool is_own_handle = false;
 
                cb_read = __bt_gatt_attribute_get_read_cb(read_req->attribute_handle,
-                                                       &serv, &gatt_handle, &user_data_read);
+                                                       &serv, &gatt_handle, &is_own_handle, &user_data_read);
 
                /* Copy data */
                _bt_convert_address_to_string(&device_addr, &read_req->device_address);
 
-               BT_INFO("GATT Server Read Req: Addr      [%s]", device_addr);
-               BT_INFO("GATT Server Read Req: Att handle[%d]", read_req->attribute_handle);
-               BT_INFO("GATT Server Read Req: Conn ID   [%d]", read_req->connection_id);
-               BT_INFO("GATT Server Read Req: Trans ID  [%d]", read_req->request_id);
-               BT_INFO("GATT Server Read Req: Offset    [%d]", read_req->offset);
-               BT_INFO("GATT Server Read Req: Is Long   [%d]", read_req->is_long);
+               BT_DBG("conn_id %d, trans id %d, attr handle %d, offset %d, is_long %d, addr %s",
+                                       read_req->connection_id, read_req->request_id,
+                                       read_req->attribute_handle, read_req->offset,
+                                       read_req->is_long, device_addr);
 
                if (cb_read == NULL) {
-                       BT_INFO("GATT Server: App has not set the Read requested callback..for the current handle");
-
-                       bt_gatt_server_send_response(read_req->request_id,
+                       BT_DBG("GATT Server: App has not set the Read requested callback..for the current handle");
+                       if (is_own_handle) {
+                               BT_DBG("GATT Server: Internal response sent for Read Request");
+                               bt_gatt_server_send_response(read_req->request_id,
                                                        BT_GATT_REQUEST_TYPE_READ, 0,
                                                        BLUETOOTH_ERROR_INTERNAL, NULL, 0);
+                       }
 
-                       BT_INFO("GATT Server: Internal response sent for Read Request");
                        if (device_addr != NULL)
                                free(device_addr);
                        return;
@@ -2658,6 +2664,7 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                void *user_data_write = NULL;
                bt_gatt_h gatt_handle = NULL;
                bt_gatt_h server = NULL;
+               bool is_own_handle = false;
                bluetooth_gatt_server_write_requested_info_t *write_req =
                                        (bluetooth_gatt_server_write_requested_info_t *)(param->param_data);
 
@@ -2669,30 +2676,25 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
 
                memcpy(val, write_req->data.data, write_req->length);
                cb_wr = __bt_gatt_attribute_get_value_change_cb(write_req->attribute_handle,
-                                                               &server, &gatt_handle, &user_data_write);
+                                                               &server, &gatt_handle, &is_own_handle, &user_data_write);
 
                /* Copy data */
                _bt_convert_address_to_string(&device_addr, &write_req->device_address);
 
-               BT_INFO("GATT Server Write Req: Address    [%s]", device_addr);
-               BT_INFO("GATT Server Write Req: Att handle [%d]", write_req->attribute_handle);
-               BT_INFO("GATT Server Write Req: Conn ID    [%d]", write_req->connection_id);
-               BT_INFO("GATT Server Write Req: Trans ID   [%d]", write_req->request_id);
-               BT_INFO("GATT Server Write Req: Offset     [%d]", write_req->offset);
-               BT_INFO("GATT Server Write Req: Length     [%d]", write_req->length);
-               BT_INFO("GATT Server Write Req: Need Resp  [%d]", write_req->need_resp);
+               BT_DBG("GATT Server Write Requested [%s] att handle %d, conn id %d, trans id %d, offset %d, length %d, need resp %d",
+                       device_addr, write_req->attribute_handle, write_req->connection_id, write_req->request_id,
+                       write_req->offset, write_req->length, write_req->need_resp);
+
 
                if (cb_wr == NULL) {
-                       BT_INFO("GATT Server: App has not set the Write requested callback..for the current handle");
+                       BT_DBG("GATT Server: App has not set the Write requested callback..for the current handle");
 
-                       if (write_req->need_resp) {
-                               BT_INFO("GATT Server: Send Response to Remote GATT client");
+                       if (write_req->need_resp && is_own_handle) {
+                               BT_DBG("GATT Server: Internal response sent for Write Request");
 
                                bt_gatt_server_send_response(write_req->request_id,
                                                                BT_GATT_REQUEST_TYPE_WRITE, 0,
                                                                BLUETOOTH_ERROR_INTERNAL, NULL, 0);
-
-                               BT_INFO("GATT Server: Internal response sent for Write Request");
                        }
 
                        /* Free Data */