Bluetooth: Fix link security setting when powering on
authorJohan Hedberg <johan.hedberg@intel.com>
Sun, 27 Jan 2013 14:32:00 +0000 (08:32 -0600)
committerGustavo Padovan <gustavo.padovan@collabora.co.uk>
Fri, 1 Feb 2013 17:50:18 +0000 (15:50 -0200)
If a controller is powered on while the HCI_AUTO_OFF flag is set the
link security setting (HCI_LINK_SECURITY) might not be in sync with the
actual state of the controller (HCI_AUTH). This patch fixes the issue by
checking for inequality between the intended and actual settings and
sends a HCI_Write_Auth_Enable command if necessary.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
net/bluetooth/mgmt.c

index fbc8edf7dc1f66df9da4a018eb3c8b357b704eb7..ae7585de9c081229d40c86d05165da62501081d3 100644 (file)
@@ -3073,6 +3073,8 @@ int mgmt_powered(struct hci_dev *hdev, u8 powered)
        mgmt_pending_foreach(MGMT_OP_SET_POWERED, hdev, settings_rsp, &match);
 
        if (powered) {
+               u8 link_sec;
+
                if (test_bit(HCI_SSP_ENABLED, &hdev->dev_flags) &&
                    !lmp_host_ssp_capable(hdev)) {
                        u8 ssp = 1;
@@ -3096,6 +3098,11 @@ int mgmt_powered(struct hci_dev *hdev, u8 powered)
                                             sizeof(cp), &cp);
                }
 
+               link_sec = test_bit(HCI_LINK_SECURITY, &hdev->dev_flags);
+               if (link_sec != test_bit(HCI_AUTH, &hdev->flags))
+                       hci_send_cmd(hdev, HCI_OP_WRITE_AUTH_ENABLE,
+                                    sizeof(link_sec), &link_sec);
+
                if (lmp_bredr_capable(hdev)) {
                        set_bredr_scan(hdev);
                        update_class(hdev);