aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2014-12-04 05:36:35 -0500
committerJohan Hedberg <johan.hedberg@intel.com>2014-12-04 05:50:34 -0500
commit11e6e25d052478235a0c3f94d2f2faddeb58eb96 (patch)
tree2b0b7a206638756656c0870f244fc1d69d294be6 /net/bluetooth
parentf5a969f23bc32945b0ec4bdb8084f514a5311142 (diff)
Bluetooth: Use {start,stop}_discovery_complete handler for cmd_complete
Sending the required cmd_complete for the management commands should be done in one place and not in multiple places. Especially for Start and Stop Discovery commands this is split into to sending it in case of failure from the complete handler, but in case of success from the event state update function triggering mgmt_discovering. This is way too convoluted and since hci_request serializes the HCI command processing, send the cmd_complete response from the complete handler for all cases. Signed-off-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Diffstat (limited to 'net/bluetooth')
-rw-r--r--net/bluetooth/mgmt.c97
1 files changed, 31 insertions, 66 deletions
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index f3296371a310..311984fcac55 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -3686,64 +3686,53 @@ done:
3686 return err; 3686 return err;
3687} 3687}
3688 3688
3689static int mgmt_start_discovery_failed(struct hci_dev *hdev, u8 status) 3689static void start_discovery_complete(struct hci_dev *hdev, u8 status)
3690{ 3690{
3691 struct pending_cmd *cmd; 3691 struct pending_cmd *cmd;
3692 u8 type; 3692 unsigned long timeout;
3693 int err;
3694
3695 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
3696
3697 cmd = mgmt_pending_find(MGMT_OP_START_DISCOVERY, hdev);
3698 if (!cmd)
3699 return -ENOENT;
3700
3701 type = hdev->discovery.type;
3702 3693
3703 err = cmd_complete(cmd->sk, hdev->id, cmd->opcode, mgmt_status(status), 3694 BT_DBG("status %d", status);
3704 &type, sizeof(type));
3705 mgmt_pending_remove(cmd);
3706 3695
3707 return err; 3696 hci_dev_lock(hdev);
3708}
3709 3697
3710static void start_discovery_complete(struct hci_dev *hdev, u8 status) 3698 cmd = mgmt_pending_find(MGMT_OP_START_DISCOVERY, hdev);
3711{ 3699 if (cmd) {
3712 unsigned long timeout = 0; 3700 u8 type = hdev->discovery.type;
3713 3701
3714 BT_DBG("status %d", status); 3702 cmd_complete(cmd->sk, hdev->id, cmd->opcode,
3703 mgmt_status(status), &type, sizeof(type));
3704 mgmt_pending_remove(cmd);
3705 }
3715 3706
3716 if (status) { 3707 if (status) {
3717 hci_dev_lock(hdev); 3708 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
3718 mgmt_start_discovery_failed(hdev, status); 3709 goto unlock;
3719 hci_dev_unlock(hdev);
3720 return;
3721 } 3710 }
3722 3711
3723 hci_dev_lock(hdev);
3724 hci_discovery_set_state(hdev, DISCOVERY_FINDING); 3712 hci_discovery_set_state(hdev, DISCOVERY_FINDING);
3725 hci_dev_unlock(hdev);
3726 3713
3727 switch (hdev->discovery.type) { 3714 switch (hdev->discovery.type) {
3728 case DISCOV_TYPE_LE: 3715 case DISCOV_TYPE_LE:
3729 timeout = msecs_to_jiffies(DISCOV_LE_TIMEOUT); 3716 timeout = msecs_to_jiffies(DISCOV_LE_TIMEOUT);
3730 break; 3717 break;
3731
3732 case DISCOV_TYPE_INTERLEAVED: 3718 case DISCOV_TYPE_INTERLEAVED:
3733 timeout = msecs_to_jiffies(hdev->discov_interleaved_timeout); 3719 timeout = msecs_to_jiffies(hdev->discov_interleaved_timeout);
3734 break; 3720 break;
3735
3736 case DISCOV_TYPE_BREDR: 3721 case DISCOV_TYPE_BREDR:
3722 timeout = 0;
3737 break; 3723 break;
3738
3739 default: 3724 default:
3740 BT_ERR("Invalid discovery type %d", hdev->discovery.type); 3725 BT_ERR("Invalid discovery type %d", hdev->discovery.type);
3726 timeout = 0;
3727 break;
3741 } 3728 }
3742 3729
3743 if (!timeout) 3730 if (timeout)
3744 return; 3731 queue_delayed_work(hdev->workqueue,
3732 &hdev->le_scan_disable, timeout);
3745 3733
3746 queue_delayed_work(hdev->workqueue, &hdev->le_scan_disable, timeout); 3734unlock:
3735 hci_dev_unlock(hdev);
3747} 3736}
3748 3737
3749static int start_discovery(struct sock *sk, struct hci_dev *hdev, 3738static int start_discovery(struct sock *sk, struct hci_dev *hdev,
@@ -3915,36 +3904,26 @@ failed:
3915 return err; 3904 return err;
3916} 3905}
3917 3906
3918static int mgmt_stop_discovery_failed(struct hci_dev *hdev, u8 status) 3907static void stop_discovery_complete(struct hci_dev *hdev, u8 status)
3919{ 3908{
3920 struct pending_cmd *cmd; 3909 struct pending_cmd *cmd;
3921 int err;
3922 3910
3923 cmd = mgmt_pending_find(MGMT_OP_STOP_DISCOVERY, hdev);
3924 if (!cmd)
3925 return -ENOENT;
3926
3927 err = cmd_complete(cmd->sk, hdev->id, cmd->opcode, mgmt_status(status),
3928 &hdev->discovery.type, sizeof(hdev->discovery.type));
3929 mgmt_pending_remove(cmd);
3930
3931 return err;
3932}
3933
3934static void stop_discovery_complete(struct hci_dev *hdev, u8 status)
3935{
3936 BT_DBG("status %d", status); 3911 BT_DBG("status %d", status);
3937 3912
3938 hci_dev_lock(hdev); 3913 hci_dev_lock(hdev);
3939 3914
3940 if (status) { 3915 cmd = mgmt_pending_find(MGMT_OP_STOP_DISCOVERY, hdev);
3941 mgmt_stop_discovery_failed(hdev, status); 3916 if (cmd) {
3942 goto unlock; 3917 u8 type = hdev->discovery.type;
3918
3919 cmd_complete(cmd->sk, hdev->id, cmd->opcode,
3920 mgmt_status(status), &type, sizeof(type));
3921 mgmt_pending_remove(cmd);
3943 } 3922 }
3944 3923
3945 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); 3924 if (!status)
3925 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
3946 3926
3947unlock:
3948 hci_dev_unlock(hdev); 3927 hci_dev_unlock(hdev);
3949} 3928}
3950 3929
@@ -6909,23 +6888,9 @@ void mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
6909void mgmt_discovering(struct hci_dev *hdev, u8 discovering) 6888void mgmt_discovering(struct hci_dev *hdev, u8 discovering)
6910{ 6889{
6911 struct mgmt_ev_discovering ev; 6890 struct mgmt_ev_discovering ev;
6912 struct pending_cmd *cmd;
6913 6891
6914 BT_DBG("%s discovering %u", hdev->name, discovering); 6892 BT_DBG("%s discovering %u", hdev->name, discovering);
6915 6893
6916 if (discovering)
6917 cmd = mgmt_pending_find(MGMT_OP_START_DISCOVERY, hdev);
6918 else
6919 cmd = mgmt_pending_find(MGMT_OP_STOP_DISCOVERY, hdev);
6920
6921 if (cmd != NULL) {
6922 u8 type = hdev->discovery.type;
6923
6924 cmd_complete(cmd->sk, hdev->id, cmd->opcode, 0, &type,
6925 sizeof(type));
6926 mgmt_pending_remove(cmd);
6927 }
6928
6929 memset(&ev, 0, sizeof(ev)); 6894 memset(&ev, 0, sizeof(ev));
6930 ev.type = hdev->discovery.type; 6895 ev.type = hdev->discovery.type;
6931 ev.discovering = discovering; 6896 ev.discovering = discovering;