summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2006-09-20 12:33:01 +0000
committerJohan Hedberg <johan.hedberg@nokia.com>2006-09-20 12:33:01 +0000
commitd75af5636343673c811abfd5ae3fb09e5fab47fd (patch)
tree372a15ee83bba64918fa6127608fe145e495c21f
parenta249cdf97cf304d6c29eabc7a32d7e25eb4c5098 (diff)
Fix sending the right HCI command when a discovery is canceled
-rw-r--r--hcid/dbus-adapter.c12
-rw-r--r--hcid/dbus.c64
-rw-r--r--hcid/dbus.h4
3 files changed, 39 insertions, 41 deletions
diff --git a/hcid/dbus-adapter.c b/hcid/dbus-adapter.c
index 1c6213c4..9edaec79 100644
--- a/hcid/dbus-adapter.c
+++ b/hcid/dbus-adapter.c
@@ -1463,7 +1463,7 @@ static DBusHandlerResult handle_dev_get_remote_name_req(DBusConnection *conn, DB
* if there is a discover process running, just queue the request.
* Otherwise, send the HCI cmd to get the remote name
*/
- if (!(dbus_data->inq_active || dbus_data->pinq_active))
+ if (!(dbus_data->disc_active || dbus_data->pdisc_active))
disc_device_req_name(dbus_data);
return error_request_deferred(conn, msg);
@@ -1933,7 +1933,7 @@ static DBusHandlerResult handle_dev_create_bonding_req(DBusConnection *conn, DBu
str2ba(peer_addr, &peer_bdaddr);
/* check if there is a pending discover: requested by D-Bus/non clients */
- if (dbus_data->inq_active || !dbus_data->pinq_idle)
+ if (dbus_data->disc_active || !dbus_data->pinq_idle)
return error_discover_in_progress(conn, msg);
cancel_remote_name(dbus_data);
@@ -2305,7 +2305,7 @@ static DBusHandlerResult handle_dev_start_periodic_req(DBusConnection *conn, DBu
if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING))
return error_invalid_arguments(conn, msg);
- if (dbus_data->inq_active || dbus_data->pinq_active)
+ if (dbus_data->disc_active || dbus_data->pdisc_active)
return error_discover_in_progress(conn, msg);
cancel_remote_name(dbus_data);
@@ -2370,7 +2370,7 @@ static DBusHandlerResult handle_dev_stop_periodic_req(DBusConnection *conn, DBus
if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING))
return error_invalid_arguments(conn, msg);
- if (!dbus_data->pinq_active)
+ if (!dbus_data->pdisc_active)
return error_not_authorized(conn, msg);
/* only the requestor can stop the periodic inquiry */
@@ -2411,7 +2411,7 @@ static DBusHandlerResult handle_dev_discover_devices_req(DBusConnection *conn, D
if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING))
return error_invalid_arguments(conn, msg);
- if (dbus_data->inq_active || dbus_data->pinq_active)
+ if (dbus_data->disc_active || dbus_data->pdisc_active)
return error_discover_in_progress(conn, msg);
cancel_remote_name(dbus_data);
@@ -2486,7 +2486,7 @@ static DBusHandlerResult handle_dev_cancel_discovery_req(DBusConnection *conn, D
return error_invalid_arguments(conn, msg);
/* is there discover pending? or discovery cancel was requested previously */
- if (!dbus_data->inq_active || dbus_data->discovery_cancel)
+ if (!dbus_data->disc_active || dbus_data->discovery_cancel)
return error_not_authorized(conn, msg);
/* only the discover requestor can cancel the inquiry process */
diff --git a/hcid/dbus.c b/hcid/dbus.c
index 59230c12..2541ef47 100644
--- a/hcid/dbus.c
+++ b/hcid/dbus.c
@@ -599,9 +599,9 @@ int hcid_dbus_start_device(uint16_t id)
}
if (hci_test_bit(HCI_INQUIRY, &di.flags))
- pdata->inq_active = 1;
+ pdata->disc_active = 1;
else
- pdata->inq_active = 0;
+ pdata->disc_active = 0;
pdata->mode = rp.enable; /* Keep the current scan status */
pdata->up = 1;
@@ -719,8 +719,8 @@ int hcid_dbus_stop_device(uint16_t id)
pdata->up = 0;
pdata->mode = SCAN_DISABLED;
- pdata->inq_active = 0;
- pdata->pinq_active = 0;
+ pdata->disc_active = 0;
+ pdata->pdisc_active = 0;
pdata->pinq_idle = 0;
pdata->discover_type = DISCOVER_TYPE_NONE;
@@ -862,7 +862,7 @@ 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))
- pdata->inq_active = 1;
+ pdata->disc_active = 1;
message = dbus_message_new_signal(path, ADAPTER_INTERFACE,
"DiscoveryStarted");
@@ -1013,7 +1013,7 @@ void hcid_dbus_inquiry_complete(bdaddr_t *local)
pdata->disc_devices = NULL;
/* Don't send signal if it is a periodic inquiry */
- if (pdata->pinq_active)
+ if (pdata->pdisc_active)
goto done;
if (pdata->discovery_requestor) {
@@ -1030,7 +1030,7 @@ void hcid_dbus_inquiry_complete(bdaddr_t *local)
pdata->discovery_cancel = NULL;
}
- if (pdata->inq_active) {
+ if (pdata->disc_active) {
/* Send discovery completed signal if there isn't name to resolve */
message = dbus_message_new_signal(path, ADAPTER_INTERFACE,
"DiscoveryCompleted");
@@ -1042,7 +1042,7 @@ void hcid_dbus_inquiry_complete(bdaddr_t *local)
}
/* tracks D-Bus and NON D-Bus */
- pdata->inq_active = 0;
+ pdata->disc_active = 0;
done:
bt_free(local_addr);
}
@@ -1071,7 +1071,7 @@ 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))
- pdata->pinq_active = 1;
+ pdata->pdisc_active = 1;
message = dbus_message_new_signal(path, ADAPTER_INTERFACE,
"PeriodicDiscoveryStarted");
@@ -1109,7 +1109,7 @@ void hcid_dbus_periodic_inquiry_exit(bdaddr_t *local, uint8_t status)
}
/* reset the discover type to be able to handle D-Bus and non D-Bus requests */
- pdata->pinq_active = 0;
+ pdata->pdisc_active = 0;
pdata->discover_type &= ~(PERIODIC_INQUIRY | RESOLVE_NAME);
/* free discovered devices list */
@@ -1170,13 +1170,13 @@ 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->inq_active && !pdata->pinq_active) {
+ if (!pdata->disc_active && !pdata->pdisc_active) {
pdata->discover_type |= (PERIODIC_INQUIRY | RESOLVE_NAME);
- pdata->pinq_active = 1;
+ pdata->pdisc_active = 1;
}
/* reset the idle flag when the inquiry complete event arrives */
- if (pdata->pinq_active)
+ if (pdata->pdisc_active)
pdata->pinq_idle = 0;
/* the inquiry result can be triggered by NON D-Bus client */
@@ -1337,7 +1337,7 @@ void hcid_dbus_remote_name(bdaddr_t *local, bdaddr_t *peer, uint8_t status, char
send_reply_and_unref(connection, message);
}
}
- pdata->inq_active = 0;
+ pdata->disc_active = 0;
done:
bt_free(local_addr);
bt_free(peer_addr);
@@ -2122,6 +2122,9 @@ int cancel_discovery(struct hci_dbus_data *pdata)
int dd, err = 0;
uint8_t status;
+ if (!pdata->disc_active)
+ goto cleanup;
+
dd = hci_open_dev(pdata->dev_id);
if (dd < 0) {
err = -ENODEV;
@@ -2131,24 +2134,19 @@ int cancel_discovery(struct hci_dbus_data *pdata)
memset(&rq, 0, sizeof(rq));
memset(&cp, 0, sizeof(cp));
- rq.ogf = OGF_LINK_CTL;
-
+ rq.ogf = OGF_LINK_CTL;
rq.rparam = &status;
- rq.rlen = sizeof(status);
+ rq.rlen = sizeof(status);
rq.event = EVT_CMD_COMPLETE;
- if (pdata->inq_active) {
- rq.ocf = OCF_INQUIRY_CANCEL;
- } else {
- /* find the pending remote name request */
- memset(&match, 0, sizeof(struct discovered_dev_info));
- bacpy(&match.bdaddr, BDADDR_ANY);
- match.name_status = NAME_REQUESTED;
+ /* find the pending remote name request */
+ memset(&match, 0, sizeof(struct discovered_dev_info));
+ bacpy(&match.bdaddr, BDADDR_ANY);
+ match.name_status = NAME_REQUESTED;
- l = slist_find(pdata->disc_devices, &match, (cmp_func_t) disc_device_find);
- if (!l)
- goto cleanup; /* no request pending */
+ l = slist_find(pdata->disc_devices, &match, (cmp_func_t) disc_device_find);
+ if (l) {
dev = l->data;
bacpy(&cp.bdaddr, &dev->bdaddr);
@@ -2156,20 +2154,23 @@ int cancel_discovery(struct hci_dbus_data *pdata)
rq.ocf = OCF_REMOTE_NAME_REQ_CANCEL;
rq.cparam = &cp;
rq.clen = REMOTE_NAME_REQ_CANCEL_CP_SIZE;
- }
+ } else
+ rq.ocf = OCF_INQUIRY_CANCEL;
if (hci_send_req(dd, &rq, 100) < 0) {
error("Sending command failed: %s (%d)", strerror(errno), errno);
err = -errno;
+ hci_close_dev(dd);
goto cleanup;
}
if (status) {
error("Cancel failed with status 0x%02x", status);
err = -bt_error(status);
- goto cleanup;
}
+ hci_close_dev(dd);
+
cleanup:
/*
* Reset discovery_requestor and discover_state in the remote name
@@ -2179,9 +2180,6 @@ cleanup:
slist_free(pdata->disc_devices);
pdata->disc_devices = NULL;
- if (dd >= 0)
- hci_close_dev(dd);
-
return err;
}
@@ -2200,7 +2198,7 @@ void periodic_discover_req_exit(const char *name, struct hci_dbus_data *pdata)
pdata->pdiscovery_requestor = NULL;
}
- pdata->pinq_active = 0;
+ pdata->pdisc_active = 0;
}
int cancel_periodic_discovery(struct hci_dbus_data *pdata)
diff --git a/hcid/dbus.h b/hcid/dbus.h
index 3dc5bd59..d0eadb73 100644
--- a/hcid/dbus.h
+++ b/hcid/dbus.h
@@ -108,8 +108,8 @@ struct hci_dbus_data {
uint32_t timeout_id; /* discoverable timeout id */
uint32_t discoverable_timeout; /* discoverable time(msec) */
uint8_t mode; /* scan mode */
- int inq_active; /* standard inquiry active: includes name resolution step */
- int pinq_active; /* periodic inquiry active */
+ int disc_active; /* standard discovery active: includes name resolution step */
+ int pdisc_active; /* periodic discovery active */
int pinq_idle; /* tracks the idle time for periodic inquiry */
int discover_type; /* type requested */
struct slist *disc_devices;