GATT: Fix bug in GATT Send indication 65/252065/1
authorAnupam Roy <anupam.r@samsung.com>
Fri, 22 Jan 2021 07:14:33 +0000 (12:44 +0530)
committerAnupam Roy <anupam.r@samsung.com>
Fri, 22 Jan 2021 07:21:51 +0000 (12:51 +0530)
Issue: When remote device address is NULL,
fd is searched in fd list and returned error if not found.
But, it is possible that, fd is not found because,
GATT characteristic attribute is not acquired by stack.
In such case, currently, GATT FRWK is wrongly missing to send
GATT indication to remote device.

Fix: Handle GATT send indication in following way
- If device address is valid unicast, send DBUS indication
- If device addres is NULL or "00:00:00:00:00:00"
    a/ First, try to find fd for multicast over socket
    b/ if fd not found, fallback to multicast over DBUS

Change-Id: Ib0e4b9d49ca3a6f3b75d8a691a1a01750152893b
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
bt-api/bt-gatt-service.c

index 60c58ff..3ba4217 100644 (file)
@@ -346,13 +346,14 @@ static int __bt_gatt_unregister_service(struct gatt_service_info *svc_info);
 static int bluetooth_get_characteristic_fd(int att_handle , char *address)
 {
        GSList *l;
+       int ret = -1;
 
        BT_DBG("Find FD for address [%s] att_handle [ %d]", address, att_handle);
 
        /* Check for NULL address */
        if (g_strcmp0(address, "00:00:00:00:00:00") != 0) {
                BT_INFO("Unicast address: Use DBUS send indication");
-               return -1;
+               return ret;
        }
 
        for (l = gatt_characteristic_server_notify_list; l != NULL; l = l->next) {
@@ -363,7 +364,7 @@ static int bluetooth_get_characteristic_fd(int att_handle , char *address)
                        return info->write_fd;
                }
        }
-       return -2;
+       return ret;
 }
 
 static bluetooth_gatt_acquire_notify_info_t * bluetooth_get_characteristic_info_from_path(int att_handle)
@@ -2924,14 +2925,11 @@ BT_EXPORT_API int bluetooth_gatt_server_send_indication(bluetooth_device_address
        fd =  bluetooth_get_characteristic_fd(param->atrribute_handle, addr);
 
        if (fd > -1) {
-               BT_INFO("Send Multicast");
+               BT_INFO("Acquire Notify FD found: Send Multicast Indication over Socket");
                result  = bluetooth_gatt_write_characteristics_value_to_fd_(fd, att_value->data, att_value->length, NULL);
                param->fd = fd;
-       } else if (fd == -2) {
-               BT_ERR("Acquire Notify FD not found for charatcristic handle");
-               BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
-               return BLUETOOTH_ERROR_INVALID_PARAM;
-       } else if (fd == -1) {
+       } else {
+               BT_ERR("Acquire Notify FD not found for charatcristic handle: Send DBUS indication");
                result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GATT_SERVER_SEND_INDICATION,
                                in_param1, in_param2, in_param3, in_param4, &out_param);
        }