diff options
author | Anuj Jain <anuj01.jain@samsung.com> | 2024-03-27 15:57:52 +0530 |
---|---|---|
committer | Anuj Jain <anuj01.jain@samsung.com> | 2024-03-27 15:57:52 +0530 |
commit | 295363fb6acdcb404b0e5c250b45e10a6af8b20b (patch) | |
tree | 344e74f0ba9f5142a0b1b0c42dd8e1aaa6d0d1eb | |
parent | ad9f69b3130aa8e6cf5c29a49d6252c32e19ea25 (diff) | |
download | bluez-295363fb6acdcb404b0e5c250b45e10a6af8b20b.tar.gz bluez-295363fb6acdcb404b0e5c250b45e10a6af8b20b.tar.bz2 bluez-295363fb6acdcb404b0e5c250b45e10a6af8b20b.zip |
Add timeout logic for le coc connection request
This patch adds 10 sec timeout upon receiving l2cap_le
connection request.
Change-Id: Id4cf266603e64eab8685325f218b1180c9c5b125
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
-rw-r--r-- | src/device.c | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/src/device.c b/src/device.c index d203b206..391b4094 100644 --- a/src/device.c +++ b/src/device.c @@ -419,6 +419,7 @@ struct l2cap_le_conn_info { int psm; guint auth_id; char *auth_uuid; + guint conn_timer; }; struct l2cap_le_profile_info { @@ -3504,7 +3505,7 @@ static void device_svc_resolved(struct btd_device *dev, uint8_t browse_type, } #ifdef TIZEN_FEATURE_BLUEZ_MODIFY - if (!req) + if (!req) return; /* If bdaddr_type is LE but req is for SDP, don't complete browse req. */ @@ -4537,6 +4538,20 @@ static gboolean l2cap_le_disconnected_cb(GIOChannel *chan, return FALSE; } +static gboolean handle_conn_fail(gpointer data) +{ + DBG("+"); + struct l2cap_le_conn_info *conn = data; + + conn->conn_timer = 0; + g_dbus_emit_signal(dbus_conn, conn->dev_path, + DEVICE_INTERFACE, "ConnectionFail", + DBUS_TYPE_STRING, &(conn->profile_info->path), + DBUS_TYPE_INVALID); + DBG("-"); + return FALSE; +} + static void l2cap_le_connect_cb(GIOChannel *chan, GError *gerr, gpointer user_data) { @@ -4548,6 +4563,16 @@ static void l2cap_le_connect_cb(GIOChannel *chan, GError *gerr, int fd; GError *io_err = NULL; char addr[18]; + int is_request_by_app = 0; + + dev_path = conn->dev_path; + + if (conn->conn_timer) { + DBG("Removing timer %d", conn->conn_timer); + is_request_by_app = 1; + g_source_remove(conn->conn_timer); + conn->conn_timer = 0; + } if (!bt_io_get(chan, &io_err, BT_IO_OPT_DEST, addr, @@ -4588,8 +4613,6 @@ static void l2cap_le_connect_cb(GIOChannel *chan, GError *gerr, goto drop; } - dev_path = conn->dev_path; - dbus_message_iter_init_append(msg, &iter); dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH, &dev_path); @@ -4610,6 +4633,11 @@ drop: if (io_err) g_error_free(io_err); + if(is_request_by_app) { + error("Call Connection Failed Event"); + handle_conn_fail((gpointer)conn); + } + info->conn = g_slist_remove(info->conn, conn); l2cap_le_io_destroy(conn); } @@ -4804,6 +4832,13 @@ static int _connect_l2cap_le(struct btd_device *device, conn = g_malloc0(sizeof(struct l2cap_le_conn_info)); info->conn = g_slist_append(info->conn, conn); + info->role = BT_L2CAP_LE_CLIENT_ROLE; + conn->dev_path = dev_path; + conn->profile_info = info; + + DBG("Add timer for 10 sec"); + conn->conn_timer = g_timeout_add(10000, handle_conn_fail, conn); + conn->io = bt_io_connect(l2cap_le_connect_cb, conn, NULL, &gerr, BT_IO_OPT_SOURCE_BDADDR, src, @@ -4818,12 +4853,11 @@ static int _connect_l2cap_le(struct btd_device *device, error("L2CAP_LE Connect failed : %s", gerr->message); g_error_free(gerr); _remove_l2cap_le_socket(info); + g_source_remove(conn->conn_timer); + conn->conn_timer = 0; return -EIO; } - info->role = BT_L2CAP_LE_CLIENT_ROLE; - conn->dev_path = dev_path; - conn->profile_info = info; conn->connected = false; g_io_channel_set_close_on_unref(conn->io, FALSE); @@ -5537,6 +5571,7 @@ static const GDBusSignalTable device_signals[] = { GDBUS_ARGS({ "bdaddr_type", "y" }, { "reason", "y" }, { "name", "s" })) }, { GDBUS_SIGNAL("DeviceConnected", GDBUS_ARGS({ "bdaddr_type", "y"})) }, + { GDBUS_SIGNAL("ConnectionFail", GDBUS_ARGS({ "path", "s" }))}, { GDBUS_SIGNAL("ProfileStateChanged", GDBUS_ARGS({ "profile", "s"}, {"state", "i"})) }, { GDBUS_SIGNAL("AdvReport", @@ -8573,7 +8608,6 @@ static void gatt_server_init(struct btd_device *device, error("Failed to initialize bt_gatt_server"); return; } - bt_att_set_enc_key_size(device->att, device->ltk_enc_size); bt_gatt_server_set_debug(device->server, gatt_debug, NULL, NULL); |