Commit 23a48093 authored by Johan Hedberg's avatar Johan Hedberg Committed by Marcel Holtmann

Bluetooth: Fix setting STOPPING state for discovery

If any of the HCI commands from the hci_stop_discovery function were
successfully sent we need to set the discovery state to STOPPING. The
Stop Discovery code was already handling this, but the code in
clean_up_hci_state was not. This patch updates the hci_stop_discovery to
return a bool to indicate whether it queued any commands and the
clean_up_hci_state() function respectively to look at the return value
and call hci_discovery_set_state() if necessary.
Signed-off-by: default avatarJohan Hedberg <johan.hedberg@intel.com>
Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
parent 34722277
...@@ -1251,7 +1251,7 @@ static void clean_up_hci_complete(struct hci_dev *hdev, u8 status) ...@@ -1251,7 +1251,7 @@ static void clean_up_hci_complete(struct hci_dev *hdev, u8 status)
} }
} }
static void hci_stop_discovery(struct hci_request *req) static bool hci_stop_discovery(struct hci_request *req)
{ {
struct hci_dev *hdev = req->hdev; struct hci_dev *hdev = req->hdev;
struct hci_cp_remote_name_req_cancel cp; struct hci_cp_remote_name_req_cancel cp;
...@@ -1266,32 +1266,39 @@ static void hci_stop_discovery(struct hci_request *req) ...@@ -1266,32 +1266,39 @@ static void hci_stop_discovery(struct hci_request *req)
hci_req_add_le_scan_disable(req); hci_req_add_le_scan_disable(req);
} }
break; return true;
case DISCOVERY_RESOLVING: case DISCOVERY_RESOLVING:
e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY,
NAME_PENDING); NAME_PENDING);
if (!e) if (!e)
return; break;
bacpy(&cp.bdaddr, &e->data.bdaddr); bacpy(&cp.bdaddr, &e->data.bdaddr);
hci_req_add(req, HCI_OP_REMOTE_NAME_REQ_CANCEL, sizeof(cp), hci_req_add(req, HCI_OP_REMOTE_NAME_REQ_CANCEL, sizeof(cp),
&cp); &cp);
break; return true;
default: default:
/* Passive scanning */ /* Passive scanning */
if (test_bit(HCI_LE_SCAN, &hdev->dev_flags)) if (test_bit(HCI_LE_SCAN, &hdev->dev_flags)) {
hci_req_add_le_scan_disable(req); hci_req_add_le_scan_disable(req);
return true;
}
break; break;
} }
return false;
} }
static int clean_up_hci_state(struct hci_dev *hdev) static int clean_up_hci_state(struct hci_dev *hdev)
{ {
struct hci_request req; struct hci_request req;
struct hci_conn *conn; struct hci_conn *conn;
bool discov_stopped;
int err;
hci_req_init(&req, hdev); hci_req_init(&req, hdev);
...@@ -1304,7 +1311,7 @@ static int clean_up_hci_state(struct hci_dev *hdev) ...@@ -1304,7 +1311,7 @@ static int clean_up_hci_state(struct hci_dev *hdev)
if (test_bit(HCI_LE_ADV, &hdev->dev_flags)) if (test_bit(HCI_LE_ADV, &hdev->dev_flags))
disable_advertising(&req); disable_advertising(&req);
hci_stop_discovery(&req); discov_stopped = hci_stop_discovery(&req);
list_for_each_entry(conn, &hdev->conn_hash.list, list) { list_for_each_entry(conn, &hdev->conn_hash.list, list) {
struct hci_cp_disconnect dc; struct hci_cp_disconnect dc;
...@@ -1338,7 +1345,11 @@ static int clean_up_hci_state(struct hci_dev *hdev) ...@@ -1338,7 +1345,11 @@ static int clean_up_hci_state(struct hci_dev *hdev)
} }
} }
return hci_req_run(&req, clean_up_hci_complete); err = hci_req_run(&req, clean_up_hci_complete);
if (!err && discov_stopped)
hci_discovery_set_state(hdev, DISCOVERY_STOPPING);
return err;
} }
static int set_powered(struct sock *sk, struct hci_dev *hdev, void *data, static int set_powered(struct sock *sk, struct hci_dev *hdev, void *data,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment