summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--hcid/dbus-adapter.c13
-rw-r--r--hcid/dbus.c33
-rw-r--r--hcid/dbus.h1
3 files changed, 36 insertions, 11 deletions
diff --git a/hcid/dbus-adapter.c b/hcid/dbus-adapter.c
index dab3255f..a7f1ee7c 100644
--- a/hcid/dbus-adapter.c
+++ b/hcid/dbus-adapter.c
@@ -2246,7 +2246,6 @@ static DBusHandlerResult handle_dev_discover_devices_req(DBusConnection *conn, D
static DBusHandlerResult handle_dev_cancel_discovery_req(DBusConnection *conn, DBusMessage *msg, void *data)
{
- DBusMessage *reply = NULL;
const char *requestor_name;
struct hci_dbus_data *dbus_data = data;
int err;
@@ -2259,9 +2258,10 @@ static DBusHandlerResult handle_dev_cancel_discovery_req(DBusConnection *conn, D
requestor_name = dbus_message_get_sender(msg);
- /* is there discover pending? */
- if (dbus_data->discover_state != STATE_DISCOVER &&
- dbus_data->discover_state != STATE_RESOLVING_NAMES)
+ /* is there discover pending? or discovery cancel was requested previously */
+ if ((dbus_data->discover_state != STATE_DISCOVER &&
+ dbus_data->discover_state != STATE_RESOLVING_NAMES) ||
+ dbus_data->discovery_cancel)
return error_not_authorized(conn, msg); /* FIXME: find a better error name */
/* only the discover requestor can cancel the inquiry process */
@@ -2281,8 +2281,9 @@ static DBusHandlerResult handle_dev_cancel_discovery_req(DBusConnection *conn, D
}
- reply = dbus_message_new_method_return(msg);
- return send_reply_and_unref(conn, reply);
+ /* Reply before send DiscoveryCompleted */
+ dbus_data->discovery_cancel = dbus_message_ref(msg);
+ return DBUS_HANDLER_RESULT_HANDLED;
}
const char *major_class_str(uint32_t class)
diff --git a/hcid/dbus.c b/hcid/dbus.c
index f3333e6d..0cdb5ccf 100644
--- a/hcid/dbus.c
+++ b/hcid/dbus.c
@@ -381,7 +381,14 @@ static void reply_pending_requests(const char *path, struct hci_dbus_data *pdata
pdata->bonding = NULL;
}
else if (pdata->discover_state != STATE_IDLE) {
- /* pending inquiry */
+
+ /* If there is a pending reply for discovery cancel */
+ if (pdata->discovery_cancel) {
+ message = dbus_message_new_method_return(pdata->discovery_cancel);
+ send_reply_and_unref(connection, message);
+ dbus_message_unref(pdata->discovery_cancel);
+ pdata->discovery_cancel = NULL;
+ }
/* Send discovery completed signal if there isn't name to resolve */
message = dbus_message_new_signal(path, ADAPTER_INTERFACE,
@@ -1009,6 +1016,14 @@ void hcid_dbus_inquiry_complete(bdaddr_t *local)
pdata->discovery_requestor = NULL;
}
+ /* If there is a pending reply for discovery cancel */
+ if (pdata->discovery_cancel) {
+ message = dbus_message_new_method_return(pdata->discovery_cancel);
+ send_reply_and_unref(connection, message);
+ dbus_message_unref(pdata->discovery_cancel);
+ pdata->discovery_cancel = NULL;
+ }
+
/* Send discovery completed signal if there isn't name to resolve */
message = dbus_message_new_signal(path, ADAPTER_INTERFACE,
"DiscoveryCompleted");
@@ -1189,10 +1204,6 @@ void hcid_dbus_remote_name(bdaddr_t *local, bdaddr_t *peer, uint8_t status, char
* devices request WITH name resolving
*/
if (pdata->discover_state == STATE_RESOLVING_NAMES) {
- message = dbus_message_new_signal(path, ADAPTER_INTERFACE,
- "DiscoveryCompleted");
-
- send_reply_and_unref(connection, message);
if (pdata->discovery_requestor) {
name_listener_remove(connection, pdata->discovery_requestor,
@@ -1200,6 +1211,18 @@ void hcid_dbus_remote_name(bdaddr_t *local, bdaddr_t *peer, uint8_t status, char
free(pdata->discovery_requestor);
pdata->discovery_requestor = NULL;
}
+
+ /* If there is a pending reply for discovery cancel */
+ if (pdata->discovery_cancel) {
+ message = dbus_message_new_method_return(pdata->discovery_cancel);
+ send_reply_and_unref(connection, message);
+ dbus_message_unref(pdata->discovery_cancel);
+ pdata->discovery_cancel = NULL;
+ }
+
+ message = dbus_message_new_signal(path, ADAPTER_INTERFACE,
+ "DiscoveryCompleted");
+ send_reply_and_unref(connection, message);
}
pdata->discover_state = STATE_IDLE;
diff --git a/hcid/dbus.h b/hcid/dbus.h
index 3a3bd62e..34e6fe0c 100644
--- a/hcid/dbus.h
+++ b/hcid/dbus.h
@@ -113,6 +113,7 @@ struct hci_dbus_data {
int discover_type; /* with/without name resolving */
struct slist *disc_devices;
char *discovery_requestor; /* discovery requestor unique name */
+ DBusMessage *discovery_cancel; /* discovery cancel message request */
struct slist *passkey_agents;
struct bonding_request_info *bonding;
struct slist *active_conn;