]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blobdiff - net/bluetooth/mgmt.c
Bluetooth: Interleaved discovery support
[mirror_ubuntu-artful-kernel.git] / net / bluetooth / mgmt.c
index a9cd38dc2cab2f11962c2e598f058f13c53a002c..89754bbcd02bf45f8c1a8883341fdc60e9aab3cf 100644 (file)
@@ -108,8 +108,10 @@ static const u16 mgmt_events[] = {
 #define LE_SCAN_WIN                    0x12
 #define LE_SCAN_INT                    0x12
 #define LE_SCAN_TIMEOUT_LE_ONLY                10240   /* TGAP(gen_disc_scan_min) */
+#define LE_SCAN_TIMEOUT_BREDR_LE       5120    /* TGAP(100)/2 */
 
 #define INQUIRY_LEN_BREDR              0x08    /* TGAP(100) */
+#define INQUIRY_LEN_BREDR_LE           0x04    /* TGAP(100)/2 */
 
 #define SERVICE_CACHE_TIMEOUT (5 * 1000)
 
@@ -2153,6 +2155,46 @@ static int remove_remote_oob_data(struct sock *sk, u16 index,
        return err;
 }
 
+static int discovery(struct hci_dev *hdev)
+{
+       int err;
+
+       if (lmp_host_le_capable(hdev)) {
+               if (lmp_bredr_capable(hdev)) {
+                       err = hci_le_scan(hdev, LE_SCAN_TYPE,
+                                               LE_SCAN_INT, LE_SCAN_WIN,
+                                               LE_SCAN_TIMEOUT_BREDR_LE);
+               } else {
+                       hdev->discovery.type = DISCOV_TYPE_LE;
+                       err = hci_le_scan(hdev, LE_SCAN_TYPE,
+                                               LE_SCAN_INT, LE_SCAN_WIN,
+                                               LE_SCAN_TIMEOUT_LE_ONLY);
+               }
+       } else {
+               hdev->discovery.type = DISCOV_TYPE_BREDR;
+               err = hci_do_inquiry(hdev, INQUIRY_LEN_BREDR);
+       }
+
+       return err;
+}
+
+int mgmt_interleaved_discovery(struct hci_dev *hdev)
+{
+       int err;
+
+       BT_DBG("%s", hdev->name);
+
+       hci_dev_lock(hdev);
+
+       err = hci_do_inquiry(hdev, INQUIRY_LEN_BREDR_LE);
+       if (err < 0)
+               hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
+
+       hci_dev_unlock(hdev);
+
+       return err;
+}
+
 static int start_discovery(struct sock *sk, u16 index,
                                                void *data, u16 len)
 {
@@ -2196,7 +2238,6 @@ static int start_discovery(struct sock *sk, u16 index,
 
        switch (hdev->discovery.type) {
        case DISCOV_TYPE_BREDR:
-       case DISCOV_TYPE_INTERLEAVED:
                err = hci_do_inquiry(hdev, INQUIRY_LEN_BREDR);
                break;
 
@@ -2205,6 +2246,10 @@ static int start_discovery(struct sock *sk, u16 index,
                                        LE_SCAN_WIN, LE_SCAN_TIMEOUT_LE_ONLY);
                break;
 
+       case DISCOV_TYPE_INTERLEAVED:
+               err = discovery(hdev);
+               break;
+
        default:
                err = -EINVAL;
        }