mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00
Bluetooth: Update stop_discovery to use HCI request
This patch modifies the stop_discovery function so it uses the HCI request framework. The HCI request is built according to the current discovery state (inquiry, LE scanning or name resolving) and a complete callback is register to handle the command complete event for the stop discovery command. This way, we move all stop_discovery mgmt handling code spread in hci_event.c to a single place in mgmt.c. Signed-off-by: Andre Guedes <andre.guedes@openbossa.org> Acked-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
This commit is contained in:
parent
4c87eaab01
commit
0e05bba6f6
1 changed files with 40 additions and 7 deletions
|
@ -2808,6 +2808,23 @@ failed:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void stop_discovery_complete(struct hci_dev *hdev, u8 status)
|
||||||
|
{
|
||||||
|
BT_DBG("status %d", status);
|
||||||
|
|
||||||
|
hci_dev_lock(hdev);
|
||||||
|
|
||||||
|
if (status) {
|
||||||
|
mgmt_stop_discovery_failed(hdev, status);
|
||||||
|
goto unlock;
|
||||||
|
}
|
||||||
|
|
||||||
|
hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
|
||||||
|
|
||||||
|
unlock:
|
||||||
|
hci_dev_unlock(hdev);
|
||||||
|
}
|
||||||
|
|
||||||
static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data,
|
static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data,
|
||||||
u16 len)
|
u16 len)
|
||||||
{
|
{
|
||||||
|
@ -2815,6 +2832,8 @@ static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data,
|
||||||
struct pending_cmd *cmd;
|
struct pending_cmd *cmd;
|
||||||
struct hci_cp_remote_name_req_cancel cp;
|
struct hci_cp_remote_name_req_cancel cp;
|
||||||
struct inquiry_entry *e;
|
struct inquiry_entry *e;
|
||||||
|
struct hci_request req;
|
||||||
|
struct hci_cp_le_set_scan_enable enable_cp;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
BT_DBG("%s", hdev->name);
|
BT_DBG("%s", hdev->name);
|
||||||
|
@ -2841,12 +2860,20 @@ static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data,
|
||||||
goto unlock;
|
goto unlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hci_req_init(&req, hdev);
|
||||||
|
|
||||||
switch (hdev->discovery.state) {
|
switch (hdev->discovery.state) {
|
||||||
case DISCOVERY_FINDING:
|
case DISCOVERY_FINDING:
|
||||||
if (test_bit(HCI_INQUIRY, &hdev->flags))
|
if (test_bit(HCI_INQUIRY, &hdev->flags)) {
|
||||||
err = hci_cancel_inquiry(hdev);
|
hci_req_add(&req, HCI_OP_INQUIRY_CANCEL, 0, NULL);
|
||||||
else
|
} else {
|
||||||
err = hci_cancel_le_scan(hdev);
|
cancel_delayed_work(&hdev->le_scan_disable);
|
||||||
|
|
||||||
|
memset(&enable_cp, 0, sizeof(enable_cp));
|
||||||
|
enable_cp.enable = LE_SCAN_DISABLE;
|
||||||
|
hci_req_add(&req, HCI_OP_LE_SET_SCAN_ENABLE,
|
||||||
|
sizeof(enable_cp), &enable_cp);
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -2864,16 +2891,22 @@ static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data,
|
||||||
}
|
}
|
||||||
|
|
||||||
bacpy(&cp.bdaddr, &e->data.bdaddr);
|
bacpy(&cp.bdaddr, &e->data.bdaddr);
|
||||||
err = hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ_CANCEL,
|
hci_req_add(&req, HCI_OP_REMOTE_NAME_REQ_CANCEL, sizeof(cp),
|
||||||
sizeof(cp), &cp);
|
&cp);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BT_DBG("unknown discovery state %u", hdev->discovery.state);
|
BT_DBG("unknown discovery state %u", hdev->discovery.state);
|
||||||
err = -EFAULT;
|
|
||||||
|
mgmt_pending_remove(cmd);
|
||||||
|
err = cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY,
|
||||||
|
MGMT_STATUS_FAILED, &mgmt_cp->type,
|
||||||
|
sizeof(mgmt_cp->type));
|
||||||
|
goto unlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = hci_req_run(&req, stop_discovery_complete);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
mgmt_pending_remove(cmd);
|
mgmt_pending_remove(cmd);
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Reference in a new issue