]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
Bluetooth: Add smp_ltk_sec_level() helper function
authorJohan Hedberg <johan.hedberg@intel.com>
Thu, 11 Sep 2014 00:37:45 +0000 (17:37 -0700)
committerMarcel Holtmann <marcel@holtmann.org>
Thu, 11 Sep 2014 00:45:24 +0000 (02:45 +0200)
There are several places that need to determine the security level that
an LTK can provide. This patch adds a convenience function for this to
help make the code more readable.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
net/bluetooth/hci_event.c
net/bluetooth/smp.c
net/bluetooth/smp.h

index 3a8381ab992f0c79691b52d022707895804a67a6..603a17cc52ac03279c4db06db3c55a32d566bbcd 100644 (file)
@@ -4506,10 +4506,7 @@ static void hci_le_ltk_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
        memcpy(cp.ltk, ltk->val, sizeof(ltk->val));
        cp.handle = cpu_to_le16(conn->handle);
 
-       if (ltk->authenticated)
-               conn->pending_sec_level = BT_SECURITY_HIGH;
-       else
-               conn->pending_sec_level = BT_SECURITY_MEDIUM;
+       conn->pending_sec_level = smp_ltk_sec_level(ltk);
 
        conn->enc_key_size = ltk->enc_size;
 
index a08b077cb725bd0419c1ed87030efae68eb0c9e0..3700dd8d9d0be206ac4b6db1e8c6a592c21338a5 100644 (file)
@@ -1114,7 +1114,7 @@ static bool smp_ltk_encrypt(struct l2cap_conn *conn, u8 sec_level)
        if (!key)
                return false;
 
-       if (sec_level > BT_SECURITY_MEDIUM && !key->authenticated)
+       if (smp_ltk_sec_level(key) < sec_level)
                return false;
 
        if (test_and_set_bit(HCI_CONN_ENCRYPT_PEND, &hcon->flags))
index 5240537efde3aeab83433c4d62553710ac2efac4..86a683a8b4917fe7ba0567254da8da210909f13c 100644 (file)
@@ -125,6 +125,14 @@ enum {
        SMP_LTK_SLAVE,
 };
 
+static inline u8 smp_ltk_sec_level(struct smp_ltk *key)
+{
+       if (key->authenticated)
+               return BT_SECURITY_HIGH;
+
+       return BT_SECURITY_MEDIUM;
+}
+
 /* SMP Commands */
 bool smp_sufficient_security(struct hci_conn *hcon, u8 sec_level);
 int smp_conn_security(struct hci_conn *hcon, __u8 sec_level);