device: Fix issue where the connection was not completely released when coc disconnected 18/309818/1
authorWootak Jung <wootak.jung@samsung.com>
Thu, 28 Mar 2024 23:53:25 +0000 (08:53 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Wed, 17 Apr 2024 05:01:12 +0000 (14:01 +0900)
Change-Id: Ia2cbcea8a3a30a14426645b61631d9fea217c185
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
src/device.c
src/device.h
src/gatt-database.c

index edcde01..e2fc7b9 100644 (file)
@@ -367,6 +367,7 @@ struct btd_device {
        uint8_t         irk_val[16];
        bool pending_conn_update;
        bool le_connectable;
+       struct l2cap_le_conn_info *conn_info;
 #endif
 };
 
@@ -435,7 +436,9 @@ typedef enum {
 struct l2cap_le_conn_info {
        struct l2cap_le_profile_info *profile_info;
        GIOChannel *io;
+       GIOChannel *accept_io;
        guint io_id;
+       bool conn_req;
        bool connected;
        const char *dev_path;
        int psm;
@@ -1906,6 +1909,14 @@ gboolean device_get_gatt_connected(const struct btd_device *device)
 {
        return device->gatt_connected;
 }
+
+void device_set_accept_io(const struct btd_device *device, GIOChannel *io)
+{
+       struct l2cap_le_conn_info *conn_info = device->conn_info;
+       if (conn_info && conn_info->conn_req) {
+               conn_info->accept_io = io;
+       }
+}
 #endif
 
 static void append_manufacturer_data(void *data, void *user_data)
@@ -4567,6 +4578,9 @@ static void l2cap_le_io_destroy(gpointer p)
 {
        struct l2cap_le_conn_info *conn = p;
 
+       if (conn->accept_io)
+               g_io_channel_shutdown(conn->accept_io, FALSE, NULL);
+
        if (conn->io_id > 0)
                g_source_remove(conn->io_id);
 
@@ -4598,6 +4612,7 @@ static gboolean l2cap_le_disconnected_cb(GIOChannel *chan,
                        DBUS_TYPE_INVALID);
 
        conn->connected = false;
+       conn->conn_req = false;
 
        info->conn = g_slist_remove(info->conn, conn);
        l2cap_le_io_destroy(conn);
@@ -4691,11 +4706,15 @@ static void l2cap_le_connect_cb(GIOChannel *chan, GError *gerr,
                goto drop;
        }
 
+       conn->conn_req = false;
+
        DBG("L2CAP_LE Connected fd [%d] addr [%s], role [%s]",fd, addr,
                        info->role == BT_L2CAP_LE_SERVER_ROLE ? "server" : "client");
        return;
 
 drop:
+       conn->conn_req = false;
+
        if (io_err)
                g_error_free(io_err);
 
@@ -4905,6 +4924,9 @@ static int _connect_l2cap_le(struct btd_device *device,
        DBG("Add timer for 10 sec");
        conn->conn_timer = g_timeout_add(10000, handle_conn_fail, conn);
 
+       conn->conn_req = true;
+       device->conn_info = conn;
+
        conn->io = bt_io_connect(l2cap_le_connect_cb,
                                        conn, NULL, &gerr,
                                        BT_IO_OPT_SOURCE_BDADDR, src,
index 11a60d2..8346d6c 100644 (file)
@@ -256,6 +256,7 @@ void btd_device_disconnect(struct btd_device *dev);
 void btd_device_set_legacy_pairing(struct btd_device *dev, bool legacy_pairing);
 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);
 #ifdef TIZEN_FEATURE_BLUEZ_BATTERY_WATCH
 void device_change_pkt_type(gpointer data, gpointer user_data);
 #endif /* TIZEN_FEATURE_BLUEZ_BATTERY_WATCH */
index d260708..468655c 100644 (file)
@@ -746,6 +746,8 @@ static void connect_cb(GIOChannel *io, GError *gerr, gpointer user_data)
        device_attach_att(device, io);
 
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+       device_set_accept_io(device, io);
+
        if (btd_device_get_svc_changed_indication(device)) {
                send_service_changed_indication_on_reconnect(device,
                                        btd_device_get_gatt_server(device));