From f3658d422b593a568743b7e9ff3a84f82413c7aa Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Thu, 21 Sep 2006 12:59:55 +0000 Subject: DiscoveryCompleted:send this signal properly when inq is called inside the periodic inq idle interval --- hcid/dbus-adapter.c | 8 +++---- hcid/dbus.c | 61 +++++++++++++++++++++++++++++++++++++---------------- hcid/dbus.h | 1 + 3 files changed, 48 insertions(+), 22 deletions(-) diff --git a/hcid/dbus-adapter.c b/hcid/dbus-adapter.c index fb9da371..0a0fae55 100644 --- a/hcid/dbus-adapter.c +++ b/hcid/dbus-adapter.c @@ -203,7 +203,7 @@ static int check_address(const char *addr) return 0; } -static int cancel_remote_name(struct hci_dbus_data *pdata) +int pending_remote_name_cancel(struct hci_dbus_data *pdata) { struct discovered_dev_info *dev, match; struct slist *l; @@ -1916,7 +1916,7 @@ static DBusHandlerResult handle_dev_create_bonding_req(DBusConnection *conn, DBu if (dbus_data->disc_active || !dbus_data->pinq_idle) return error_discover_in_progress(conn, msg); - cancel_remote_name(dbus_data); + pending_remote_name_cancel(dbus_data); if (dbus_data->bonding) return error_bonding_in_progress(conn, msg); @@ -2288,7 +2288,7 @@ static DBusHandlerResult handle_dev_start_periodic_req(DBusConnection *conn, DBu if (dbus_data->disc_active || dbus_data->pdisc_active) return error_discover_in_progress(conn, msg); - cancel_remote_name(dbus_data); + pending_remote_name_cancel(dbus_data); dd = hci_open_dev(dbus_data->dev_id); if (dd < 0) @@ -2389,7 +2389,7 @@ static DBusHandlerResult handle_dev_discover_devices_req(DBusConnection *conn, D if (dbus_data->disc_active || dbus_data->pdisc_active) return error_discover_in_progress(conn, msg); - cancel_remote_name(dbus_data); + pending_remote_name_cancel(dbus_data); if (dbus_data->bonding) return error_bonding_in_progress(conn, msg); diff --git a/hcid/dbus.c b/hcid/dbus.c index 21545dbf..ca419ca3 100644 --- a/hcid/dbus.c +++ b/hcid/dbus.c @@ -870,8 +870,19 @@ void hcid_dbus_inquiry_start(bdaddr_t *local) snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); - if (dbus_connection_get_object_path_data(connection, path, (void *) &pdata)) + if (dbus_connection_get_object_path_data(connection, path, (void *) &pdata)) { pdata->disc_active = 1; + /* + * Cancel pending remote name request and clean the device list + * when inquiry is supported in periodic inquiry idle state. + */ + if (pdata->pdisc_active) + pending_remote_name_cancel(pdata); + + /* disable name resolution for NON D-Bus requests */ + if (!pdata->discovery_requestor) + pdata->discover_type &= ~RESOLVE_NAME; + } message = dbus_message_new_signal(path, ADAPTER_INTERFACE, "DiscoveryStarted"); @@ -1012,19 +1023,39 @@ void hcid_dbus_inquiry_complete(bdaddr_t *local) } pdata->pinq_idle = 1; + /* + * Enable resolution again: standard inquiry can be + * received in the periodic inquiry idle state. + */ + if (pdata->pdiscovery_requestor) + pdata->discover_type |= RESOLVE_NAME; + + /* + * The following scenarios can happen: + * 1. standard inquiry: always send discovery completed signal + * 2. standard inquiry + name resolving: send discovery completed after name resolving + * 3. periodic inquiry: skip discovery completed signal + * 4. periodic inquiry + standard inquiry: always send discovery completed signal + * + * Keep in mind that non D-Bus requests can arrive. + */ if (!disc_device_req_name(pdata)) goto done; /* skip - there is name to resolve */ + if (pdata->disc_active) { + message = dbus_message_new_signal(path, ADAPTER_INTERFACE, + "DiscoveryCompleted"); + send_reply_and_unref(connection, message); + + pdata->disc_active = 0; + } + /* free discovered devices list */ slist_foreach(pdata->disc_devices, (slist_func_t) free, NULL); slist_free(pdata->disc_devices); pdata->disc_devices = NULL; - /* Don't send signal if it is a periodic inquiry */ - if (pdata->pdisc_active) - goto done; - if (pdata->discovery_requestor) { name_listener_remove(connection, pdata->discovery_requestor, (name_cb_t) discover_devices_req_exit, pdata); @@ -1043,15 +1074,6 @@ void hcid_dbus_inquiry_complete(bdaddr_t *local) pdata->discover_type &= ~STD_INQUIRY; } - if (pdata->disc_active) { - /* Send discovery completed signal if there isn't name to resolve */ - message = dbus_message_new_signal(path, ADAPTER_INTERFACE, - "DiscoveryCompleted"); - send_reply_and_unref(connection, message); - } - - /* tracks D-Bus and NON D-Bus */ - pdata->disc_active = 0; done: bt_free(local_addr); } @@ -1079,9 +1101,14 @@ void hcid_dbus_periodic_inquiry_start(bdaddr_t *local, uint8_t status) snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); - if (dbus_connection_get_object_path_data(connection, path, (void *) &pdata)) + if (dbus_connection_get_object_path_data(connection, path, (void *) &pdata)) { pdata->pdisc_active = 1; + /* disable name resolution for NON D-Bus requests */ + if (!pdata->pdiscovery_requestor) + pdata->discover_type &= ~RESOLVE_NAME; + } + message = dbus_message_new_signal(path, ADAPTER_INTERFACE, "PeriodicDiscoveryStarted"); send_reply_and_unref(connection, message); @@ -1200,10 +1227,8 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class, i * workaround to identify situation when the daemon started and * a standard inquiry or periodic inquiry was already running */ - if (!pdata->disc_active && !pdata->pdisc_active) { - pdata->discover_type |= (PERIODIC_INQUIRY | RESOLVE_NAME); + if (!pdata->disc_active && !pdata->pdisc_active) pdata->pdisc_active = 1; - } /* reset the idle flag when the inquiry complete event arrives */ if (pdata->pdisc_active) diff --git a/hcid/dbus.h b/hcid/dbus.h index d0eadb73..b4f597e7 100644 --- a/hcid/dbus.h +++ b/hcid/dbus.h @@ -212,6 +212,7 @@ void discover_devices_req_exit(const char *name, struct hci_dbus_data *pdata); int cancel_discovery(struct hci_dbus_data *pdata); void periodic_discover_req_exit(const char *name, struct hci_dbus_data *pdata); int cancel_periodic_discovery(struct hci_dbus_data *pdata); +int pending_remote_name_cancel(struct hci_dbus_data *pdata); int handle_passkey_request(DBusConnection *conn, int dev, const char *path, bdaddr_t *sba, bdaddr_t *dba); void release_default_agent(void); -- cgit