gatt-database: Fix notifying on indicatable attr
authorCurtis <curtis@maves.io>
Fri, 19 Feb 2021 17:49:46 +0000 (12:49 -0500)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:34 +0000 (19:08 +0530)
When a local GATT characteristic has both the indicate and notify
properties, notifications will not be send to clients requesting them.
This change fixes this, allowing for notifications to be sent.

Also simplifies logic about when notifications/indications should
be sent.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
src/gatt-database.c

index 9bc6915..c38ab85 100644 (file)
@@ -1746,10 +1746,7 @@ static void send_notification_to_device(void *data, void *user_data)
        }
 
        ccc = find_ccc_state(device_state, notify->ccc_handle);
-       if (!ccc)
-               return;
-
-       if (!ccc->value || (notify->conf && !(ccc->value & 0x0002)))
+       if (!ccc || !(ccc->value & 0x0003))
                return;
 
        device = btd_adapter_find_device(notify->database->adapter,
@@ -1776,7 +1773,7 @@ static void send_notification_to_device(void *data, void *user_data)
         * TODO: If the device is not connected but bonded, send the
         * notification/indication when it becomes connected.
         */
-       if (!notify->conf) {
+       if (!(ccc->value & 0x0002)) {
                DBG("GATT server sending notification");
                bt_gatt_server_send_notification(server,
                                        notify->handle, notify->value,
@@ -2902,8 +2899,8 @@ static bool sock_io_read(struct io *io, void *user_data)
                                gatt_db_attribute_get_handle(chrc->attrib),
                                buf, bytes_read,
                                gatt_db_attribute_get_handle(chrc->ccc),
-                               chrc->props & BT_GATT_CHRC_PROP_INDICATE ?
-                               conf_cb : NULL, chrc->proxy);
+                               conf_cb,
+                               chrc->proxy);
 
        return true;
 }
@@ -3362,8 +3359,8 @@ static void property_changed_cb(GDBusProxy *proxy, const char *name,
                                gatt_db_attribute_get_handle(chrc->attrib),
                                value, len,
                                gatt_db_attribute_get_handle(chrc->ccc),
-                               chrc->props & BT_GATT_CHRC_PROP_INDICATE ?
-                               conf_cb : NULL, proxy);
+                               conf_cb,
+                               proxy);
 #endif
 }