gatt: Emit PropertiesChanged("MTU") when MTU is exchanged
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Tue, 28 Sep 2021 23:42:58 +0000 (16:42 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:37 +0000 (19:08 +0530)
This notifies client when the ATT MTU changes.

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

index 64227e2..229b82f 100644 (file)
@@ -111,6 +111,7 @@ struct characteristic {
        char *path;
 
        unsigned int ready_id;
+       unsigned int exchange_id;
        struct sock_io *write_io;
        struct sock_io *notify_io;
 
@@ -1948,6 +1949,8 @@ static const GDBusSignalTable characteristic_signals[] = {
 static void characteristic_free(void *data)
 {
        struct characteristic *chrc = data;
+       struct bt_gatt_client *gatt = chrc->service->client->gatt;
+       struct bt_att *att;
 
        /* List should be empty here */
        queue_destroy(chrc->descs, NULL);
@@ -1964,15 +1967,29 @@ static void characteristic_free(void *data)
 
        queue_destroy(chrc->notify_clients, remove_client);
 
+       att = bt_gatt_client_get_att(gatt);
+       if (att)
+               bt_att_unregister_exchange(att, chrc->exchange_id);
+
        g_free(chrc->path);
        free(chrc);
 }
 
+static void att_exchange(uint16_t mtu, void *user_data)
+{
+       struct characteristic *chrc = user_data;
+
+       g_dbus_emit_property_changed(btd_get_dbus_connection(), chrc->path,
+                                       GATT_CHARACTERISTIC_IFACE, "MTU");
+}
+
 static struct characteristic *characteristic_create(
                                                struct gatt_db_attribute *attr,
                                                struct service *service)
 {
        struct characteristic *chrc;
+       struct bt_gatt_client *gatt = service->client->gatt;
+       struct bt_att *att;
        bt_uuid_t uuid;
 
        chrc = new0(struct characteristic, 1);
@@ -2028,6 +2045,11 @@ static struct characteristic *characteristic_create(
                return NULL;
        }
 
+       att = bt_gatt_client_get_att(gatt);
+       if (att)
+               chrc->exchange_id = bt_att_register_exchange(att, att_exchange,
+                                                               chrc, NULL);
+
        DBG("Exported GATT characteristic: %s", chrc->path);
 
        return chrc;