device: Fix issue with LE bonding-io closing before gatt client is ready 29/320629/1
authorWootak Jung <wootak.jung@samsung.com>
Wed, 12 Feb 2025 01:11:48 +0000 (10:11 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Wed, 5 Mar 2025 05:23:31 +0000 (14:23 +0900)
Change-Id: Ia2961de4bd9de3a7e947607173488e0617003a95
Signed-off-by: Sohyeon Choi <shss.choi@samsung.com>
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
src/adapter.c
src/device.c
src/device.h
src/gatt-client.c

index cf9fe3500fa57c4aafe76f0d2d46fecbf90b26c8..25a55214457e6cd61ac50ea0b7ee3c6d9db6ff73 100644 (file)
@@ -14662,8 +14662,13 @@ static void new_long_term_key_callback(uint16_t index, uint16_t length,
 
        ba2str(&addr->bdaddr, dst);
 
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+       DBG("hci%u new LTK for %s type %u enc_size %u central %d",
+               adapter->dev_id, dst, ev->key.type, ev->key.enc_size, ev->key.central);
+#else
        DBG("hci%u new LTK for %s type %u enc_size %u",
                adapter->dev_id, dst, ev->key.type, ev->key.enc_size);
+#endif
 
        device = btd_adapter_get_device(adapter, &addr->bdaddr, addr->type);
        if (!device) {
index 599146defd83a23e6f2c13c9aee1d62458f9c845..f8d3e5bdc15fe4510334a389cb39943df3ba5809 100644 (file)
@@ -109,9 +109,6 @@ struct bonding_req {
        guint retry_timer;
        struct timespec attempt_start_time;
        long last_attempt_duration_ms;
-#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
-       GIOChannel *io;
-#endif
 };
 
 typedef enum {
@@ -374,6 +371,7 @@ struct btd_device {
        bool pending_conn_update;
        bool le_connectable;
        struct l2cap_le_conn_info *conn_info;
+       GIOChannel *bonding_io;
 #endif
 };
 
@@ -1926,8 +1924,28 @@ void device_set_accept_io(const struct btd_device *device, GIOChannel *io)
 void device_set_le_bonding_io(struct btd_device *device, GIOChannel *io)
 {
        if (device->bonding) {
-               device->bonding->io = io;
+               device->bonding_io = io;
+       }
+}
+
+void device_close_le_bonding_io(struct btd_device *device)
+{
+       if (!device->bonding_io)
+               return;
+
+       if (device->bonding) {
+               DBG("LE bonding process is still ongoing");
+               return;
        }
+
+       if (!device->gatt_connected) {
+               DBG("GATT connection process is still ongoing");
+               return;
+       }
+
+       DBG("shutdown LE bonding-io after LE bonding completed");
+       g_io_channel_shutdown(device->bonding_io, FALSE, NULL);
+       device->bonding_io = NULL;
 }
 #endif
 
@@ -3766,13 +3784,6 @@ static void bonding_request_free(struct bonding_req *bonding)
        if (!bonding)
                return;
 
-#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
-       if (bonding->io) {
-               DBG("shutdown LE bonding-io after LE bonding completed");
-               g_io_channel_shutdown(bonding->io, FALSE, NULL);
-       }
-#endif
-
        if (bonding->listener_id)
                g_dbus_remove_watch(dbus_conn, bonding->listener_id);
 
@@ -3791,8 +3802,12 @@ static void bonding_request_free(struct bonding_req *bonding)
        if (bonding->retry_timer)
                g_source_remove(bonding->retry_timer);
 
-       if (bonding->device)
+       if (bonding->device) {
                bonding->device->bonding = NULL;
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+               device_close_le_bonding_io(bonding->device);
+#endif
+       }
 
        g_free(bonding);
 }
index e1575a585155b63e8439e74a6776b1afd26b05f7..067c6feb1752bacc1c6281e8b357aba303869780 100644 (file)
@@ -267,6 +267,7 @@ void btd_device_set_svc_changed_indication(struct btd_device *dev, bool value);
 bool btd_device_get_svc_changed_indication(struct btd_device *dev);
 void device_set_accept_io(const struct btd_device *device, GIOChannel *io);
 void device_set_le_bonding_io(struct btd_device *device, GIOChannel *io);
+void device_close_le_bonding_io(struct btd_device *device);
 #ifdef TIZEN_FEATURE_BLUEZ_BATTERY_WATCH
 void device_change_pkt_type(gpointer data, gpointer user_data);
 #endif /* TIZEN_FEATURE_BLUEZ_BATTERY_WATCH */
index b14578a8ddfddebbe64ececd3abe26822410bada..d577e4010fe8314baf56e8c559f2e9a5792e8ade 100644 (file)
@@ -2725,6 +2725,8 @@ static gboolean check_all_chrcs_ready(gpointer user_data)
 
        count = 0;
 
+       device_close_le_bonding_io(client->device);
+
        return FALSE;
 }
 #endif