Bluetooth: If link is encrypted, do not send encrpt link request
When BT2.1 link is in encrypted state, if HOST posts
SET_CONNECTION_ENCRYPTION with enable as on, in some cases
SoC fails to generate ENCRYPT_CHANGE event. Since the link is
already in encrypted state with current link key, HOST can avoid
repeated request for encrypting the link while doing service level
authentication. This patch avoids the repeated request for encrypting
the link after service level authentication from HOST, if the link
is already encrypted by current link key.
Change-Id: I9402d64310f0e4e6240ca6ed610e0108de061a12
Signed-off-by: Prabhakaran Mc <prabhakaranmc@codeaurora.org>
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
old mode 100755
new mode 100644
index f4f833b..598c310
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1852,11 +1852,29 @@
if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend)) {
if (!ev->status) {
- struct hci_cp_set_conn_encrypt cp;
- cp.handle = ev->handle;
- cp.encrypt = 0x01;
- hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT,
- sizeof(cp), &cp);
+ if (conn->link_mode & HCI_LM_ENCRYPT) {
+ /* Encryption implies authentication */
+ conn->link_mode |= HCI_LM_AUTH;
+ conn->link_mode |= HCI_LM_ENCRYPT;
+ conn->sec_level =
+ conn->pending_sec_level;
+ clear_bit(HCI_CONN_ENCRYPT_PEND,
+ &conn->pend);
+ hci_encrypt_cfm(conn, ev->status, 1);
+
+ if (test_bit(HCI_MGMT, &hdev->flags))
+ mgmt_encrypt_change(hdev->id,
+ &conn->dst,
+ ev->status);
+
+ } else {
+ struct hci_cp_set_conn_encrypt cp;
+ cp.handle = ev->handle;
+ cp.encrypt = 0x01;
+ hci_send_cmd(hdev,
+ HCI_OP_SET_CONN_ENCRYPT,
+ sizeof(cp), &cp);
+ }
} else {
clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend);
hci_encrypt_cfm(conn, ev->status, 0x00);
@@ -2653,6 +2671,7 @@
conn->key_type = ev->key_type;
hci_disconnect_amp(conn, 0x06);
+ conn->link_mode &= ~HCI_LM_ENCRYPT;
pin_len = conn->pin_length;
hci_conn_put(conn);
hci_conn_enter_active_mode(conn, 0);