From 937fd0e66fdb25c78f23e1d856a36484e5a8a96f Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Wed, 7 Jun 2006 21:20:29 +0000 Subject: Timeout for PIN request --- hcid/dbus-adapter.c | 37 +++++++++++++++++++++++++++++++++++++ hcid/dbus.c | 2 +- hcid/dbus.h | 2 ++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/hcid/dbus-adapter.c b/hcid/dbus-adapter.c index 62280f24..3b56ced4 100644 --- a/hcid/dbus-adapter.c +++ b/hcid/dbus-adapter.c @@ -1552,6 +1552,37 @@ static DBusHandlerResult handle_dev_disconnect_remote_device_req(DBusConnection } +static int bonding_timeout_handler(void *data) +{ + struct hci_dbus_data *dbus_data = data; + struct active_conn_info *con; + struct slist *l; + int dd = -1; + + if (!dbus_data->bonding || !dbus_data->bonding->disconnect) + return -1; + + l = slist_find(dbus_data->active_conn, &dbus_data->bonding->bdaddr, active_conn_find_by_bdaddr); + if (!l) + return -1; + + con = l->data; + + dd = hci_open_dev(dbus_data->dev_id); + if (dd < 0) { + error("HCI device open failed: hci%d", dbus_data->dev_id); + return -1; + } + + if (hci_disconnect(dd, htobs(con->handle), HCI_AUTHENTICATION_FAILURE, 1000) < 0) + error("Disconnect failed"); + + if (dd >= 0) + close(dd); + + return -1; +} + static DBusHandlerResult handle_dev_create_bonding_req(DBusConnection *conn, DBusMessage *msg, void *data) { char filename[PATH_MAX + 1]; @@ -1669,6 +1700,12 @@ static DBusHandlerResult handle_dev_create_bonding_req(DBusConnection *conn, DBu hci_close_dev(dd); + /* + * Create a timeout to disconnect automatically if no passkey is provided + * Broadcom chips doesn't handle timeout for PIN code request command + */ + g_timeout_add(BONDING_TIMEOUT, bonding_timeout_handler, dbus_data); + return DBUS_HANDLER_RESULT_HANDLED; } diff --git a/hcid/dbus.c b/hcid/dbus.c index 93bf23fa..274dd8d8 100644 --- a/hcid/dbus.c +++ b/hcid/dbus.c @@ -646,7 +646,7 @@ void hcid_dbus_bonding_process_complete(bdaddr_t *local, bdaddr_t *peer, const u memset(&cp, 0, sizeof(cp)); cp.handle = con->handle; - cp.reason = HCI_OE_USER_ENDED_CONNECTION; + cp.reason = (status ? HCI_AUTHENTICATION_FAILURE : HCI_OE_USER_ENDED_CONNECTION); data = hci_req_data_new(pdata->dev_id, peer, OGF_LINK_CTL, OCF_DISCONNECT, EVT_DISCONN_COMPLETE, diff --git a/hcid/dbus.h b/hcid/dbus.h index 69952bfc..d032f16b 100644 --- a/hcid/dbus.h +++ b/hcid/dbus.h @@ -50,6 +50,8 @@ #define MAX_PATH_LENGTH 64 +#define BONDING_TIMEOUT 45000 /* 45 sec */ + typedef DBusHandlerResult (*service_handler_func_t) (DBusConnection *conn, DBusMessage *msg, void *user_data); -- cgit