device: Fix issue with LE bonding-io closing before gatt client is ready 94/319494/2 accepted/tizen/7.0/unified/20250218.165110
authorWootak Jung <wootak.jung@samsung.com>
Wed, 12 Feb 2025 01:11:48 +0000 (10:11 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Wed, 12 Feb 2025 05:38:56 +0000 (05:38 +0000)
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 d4a6e053a555a56bd95d11cf591fc56345d385ee..b28385f2f07ae7b2c37b4ae404cf258b4e204133 100644 (file)
@@ -14418,8 +14418,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 ed7e5fe0e6a4dbfb8bfeced82ffd95062f1deb35..a42999cef4f27df2c2e16dba30e8e0b03624cf38 100644 (file)
@@ -111,9 +111,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 {
@@ -349,6 +346,7 @@ struct btd_device {
        bool pending_conn_update;
        bool le_connectable;
        struct l2cap_le_conn_info *conn_info;
+       GIOChannel *bonding_io;
 #endif
 };
 
@@ -1855,8 +1853,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
 
@@ -3657,13 +3675,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);
 
@@ -3682,8 +3693,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 596ed62faa1204f7487d8f3e8cd48911c2c0c9b1..f85b14b8394f2aff53498252ddebe6e9cf4eb452 100644 (file)
@@ -246,6 +246,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 0ab1fa95ebf595d4f6bfd62f7a0e3dfbf4fb8c0f..4676a9b262761d3c1d6a311969066531f2923ee9 100644 (file)
@@ -2736,6 +2736,8 @@ static gboolean check_all_chrcs_ready(gpointer user_data)
 
        count = 0;
 
+       device_close_le_bonding_io(client->device);
+
        return FALSE;
 }
 #endif