Bluetooth: Temporarily stop background scanning on discovery
authorAndre Guedes <andre.guedes@openbossa.org>
Wed, 26 Feb 2014 23:21:50 +0000 (20:21 -0300)
committerMarcel Holtmann <marcel@holtmann.org>
Thu, 27 Feb 2014 03:41:35 +0000 (19:41 -0800)
If the user sends a mgmt start discovery command while the background
scanning is running, we should temporarily stop it. Once the discovery
finishes, we start the background scanning again.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
net/bluetooth/hci_core.c
net/bluetooth/mgmt.c

index 89ff09249eee5c4b3520f1618c4fa46ebd0248b9..507a137a584b2445fb23b5865988193336d9bcc6 100644 (file)
@@ -1786,6 +1786,8 @@ void hci_discovery_set_state(struct hci_dev *hdev, int state)
 
        switch (state) {
        case DISCOVERY_STOPPED:
+               hci_update_background_scan(hdev);
+
                if (hdev->discovery.state != DISCOVERY_STARTING)
                        mgmt_discovering(hdev, 0);
                break;
index bad23d5fdd3535b88af384ec1ae0ea9ed8603418..a62e22ca73a17d58daf066b103de2eca1b51bc63 100644 (file)
@@ -3439,12 +3439,12 @@ static int start_discovery(struct sock *sk, struct hci_dev *hdev,
                        goto failed;
                }
 
-               if (test_bit(HCI_LE_SCAN, &hdev->dev_flags)) {
-                       err = cmd_status(sk, hdev->id, MGMT_OP_START_DISCOVERY,
-                                        MGMT_STATUS_BUSY);
-                       mgmt_pending_remove(cmd);
-                       goto failed;
-               }
+               /* If controller is scanning, it means the background scanning
+                * is running. Thus, we should temporarily stop it in order to
+                * set the discovery scanning parameters.
+                */
+               if (test_bit(HCI_LE_SCAN, &hdev->dev_flags))
+                       hci_req_add_le_scan_disable(&req);
 
                memset(&param_cp, 0, sizeof(param_cp));