diff options
author | Andre Guedes <andre.guedes@openbossa.org> | 2013-04-30 14:29:33 -0400 |
---|---|---|
committer | Gustavo Padovan <gustavo.padovan@collabora.co.uk> | 2013-06-22 19:23:51 -0400 |
commit | 0e05bba6f6f8c2dca7a13fe0566742277e92df07 (patch) | |
tree | 99e02b894717a221de7f703c72cbb3eb877c5681 /net | |
parent | 4c87eaab01df271c81f6a68e3c28dbd44d348004 (diff) |
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>
Diffstat (limited to 'net')
-rw-r--r-- | net/bluetooth/mgmt.c | 47 |
1 files changed, 40 insertions, 7 deletions
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 743100f3ab9c..c33bc4f4d006 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c | |||
@@ -2808,6 +2808,23 @@ failed: | |||
2808 | return err; | 2808 | return err; |
2809 | } | 2809 | } |
2810 | 2810 | ||
2811 | static void stop_discovery_complete(struct hci_dev *hdev, u8 status) | ||
2812 | { | ||
2813 | BT_DBG("status %d", status); | ||
2814 | |||
2815 | hci_dev_lock(hdev); | ||
2816 | |||
2817 | if (status) { | ||
2818 | mgmt_stop_discovery_failed(hdev, status); | ||
2819 | goto unlock; | ||
2820 | } | ||
2821 | |||
2822 | hci_discovery_set_state(hdev, DISCOVERY_STOPPED); | ||
2823 | |||
2824 | unlock: | ||
2825 | hci_dev_unlock(hdev); | ||
2826 | } | ||
2827 | |||
2811 | static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data, | 2828 | static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data, |
2812 | u16 len) | 2829 | u16 len) |
2813 | { | 2830 | { |
@@ -2815,6 +2832,8 @@ static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data, | |||
2815 | struct pending_cmd *cmd; | 2832 | struct pending_cmd *cmd; |
2816 | struct hci_cp_remote_name_req_cancel cp; | 2833 | struct hci_cp_remote_name_req_cancel cp; |
2817 | struct inquiry_entry *e; | 2834 | struct inquiry_entry *e; |
2835 | struct hci_request req; | ||
2836 | struct hci_cp_le_set_scan_enable enable_cp; | ||
2818 | int err; | 2837 | int err; |
2819 | 2838 | ||
2820 | BT_DBG("%s", hdev->name); | 2839 | BT_DBG("%s", hdev->name); |
@@ -2841,12 +2860,20 @@ static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data, | |||
2841 | goto unlock; | 2860 | goto unlock; |
2842 | } | 2861 | } |
2843 | 2862 | ||
2863 | hci_req_init(&req, hdev); | ||
2864 | |||
2844 | switch (hdev->discovery.state) { | 2865 | switch (hdev->discovery.state) { |
2845 | case DISCOVERY_FINDING: | 2866 | case DISCOVERY_FINDING: |
2846 | if (test_bit(HCI_INQUIRY, &hdev->flags)) | 2867 | if (test_bit(HCI_INQUIRY, &hdev->flags)) { |
2847 | err = hci_cancel_inquiry(hdev); | 2868 | hci_req_add(&req, HCI_OP_INQUIRY_CANCEL, 0, NULL); |
2848 | else | 2869 | } else { |
2849 | err = hci_cancel_le_scan(hdev); | 2870 | cancel_delayed_work(&hdev->le_scan_disable); |
2871 | |||
2872 | memset(&enable_cp, 0, sizeof(enable_cp)); | ||
2873 | enable_cp.enable = LE_SCAN_DISABLE; | ||
2874 | hci_req_add(&req, HCI_OP_LE_SET_SCAN_ENABLE, | ||
2875 | sizeof(enable_cp), &enable_cp); | ||
2876 | } | ||
2850 | 2877 | ||
2851 | break; | 2878 | break; |
2852 | 2879 | ||
@@ -2864,16 +2891,22 @@ static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data, | |||
2864 | } | 2891 | } |
2865 | 2892 | ||
2866 | bacpy(&cp.bdaddr, &e->data.bdaddr); | 2893 | bacpy(&cp.bdaddr, &e->data.bdaddr); |
2867 | err = hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ_CANCEL, | 2894 | hci_req_add(&req, HCI_OP_REMOTE_NAME_REQ_CANCEL, sizeof(cp), |
2868 | sizeof(cp), &cp); | 2895 | &cp); |
2869 | 2896 | ||
2870 | break; | 2897 | break; |
2871 | 2898 | ||
2872 | default: | 2899 | default: |
2873 | BT_DBG("unknown discovery state %u", hdev->discovery.state); | 2900 | BT_DBG("unknown discovery state %u", hdev->discovery.state); |
2874 | err = -EFAULT; | 2901 | |
2902 | mgmt_pending_remove(cmd); | ||
2903 | err = cmd_complete(sk, hdev->id, MGMT_OP_STOP_DISCOVERY, | ||
2904 | MGMT_STATUS_FAILED, &mgmt_cp->type, | ||
2905 | sizeof(mgmt_cp->type)); | ||
2906 | goto unlock; | ||
2875 | } | 2907 | } |
2876 | 2908 | ||
2909 | err = hci_req_run(&req, stop_discovery_complete); | ||
2877 | if (err < 0) | 2910 | if (err < 0) |
2878 | mgmt_pending_remove(cmd); | 2911 | mgmt_pending_remove(cmd); |
2879 | else | 2912 | else |