Merge branch 'for-3.20' of git://linux-nfs.org/~bfields/linux
[firefly-linux-kernel-4.4.55.git] / net / bluetooth / smp.c
index 3e4de935f667ae3228f1d54a686498bd5623ac4c..c09a821f381d0b648b45ca5c722d89161775f638 100644 (file)
@@ -620,7 +620,7 @@ static void build_pairing_cmd(struct l2cap_conn *conn,
 
                oob_data = hci_find_remote_oob_data(hdev, &hcon->dst,
                                                    bdaddr_type);
-               if (oob_data) {
+               if (oob_data && oob_data->present) {
                        set_bit(SMP_FLAG_OOB, &smp->flags);
                        oob_flag = SMP_OOB_PRESENT;
                        memcpy(smp->rr, oob_data->rand256, 16);
@@ -3066,6 +3066,18 @@ int smp_register(struct hci_dev *hdev)
 
        BT_DBG("%s", hdev->name);
 
+       /* If the controller does not support Low Energy operation, then
+        * there is also no need to register any SMP channel.
+        */
+       if (!lmp_le_capable(hdev))
+               return 0;
+
+       if (WARN_ON(hdev->smp_data)) {
+               chan = hdev->smp_data;
+               hdev->smp_data = NULL;
+               smp_del_chan(chan);
+       }
+
        chan = smp_add_cid(hdev, L2CAP_CID_SMP);
        if (IS_ERR(chan))
                return PTR_ERR(chan);
@@ -3085,6 +3097,12 @@ int smp_register(struct hci_dev *hdev)
                return 0;
        }
 
+       if (WARN_ON(hdev->smp_bredr_data)) {
+               chan = hdev->smp_bredr_data;
+               hdev->smp_bredr_data = NULL;
+               smp_del_chan(chan);
+       }
+
        chan = smp_add_cid(hdev, L2CAP_CID_SMP_BREDR);
        if (IS_ERR(chan)) {
                int err = PTR_ERR(chan);