]> git.openfabrics.org - ~emulex/infiniband.git/commitdiff
Bluetooth: Clearly distinguish mgmt LTK type from authenticated property
authorJohan Hedberg <johan.hedberg@intel.com>
Fri, 23 May 2014 10:19:53 +0000 (13:19 +0300)
committerMarcel Holtmann <marcel@holtmann.org>
Fri, 23 May 2014 18:24:04 +0000 (11:24 -0700)
On the mgmt level we have a key type parameter which currently accepts
two possible values: 0x00 for unauthenticated and 0x01 for
authenticated. However, in the internal struct smp_ltk representation we
have an explicit "authenticated" boolean value.

To make this distinction clear, add defines for the possible mgmt values
and do conversion to and from the internal authenticated value.

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

index 226ae03cafe710986469c3beb8f20b0d6f03bf13..bcffc9ae0c89bec0bd3237d708e76d0911abfa36 100644 (file)
@@ -181,6 +181,9 @@ struct mgmt_cp_load_link_keys {
 } __packed;
 #define MGMT_LOAD_LINK_KEYS_SIZE       3
 
+#define MGMT_LTK_UNAUTHENTICATED       0x00
+#define MGMT_LTK_AUTHENTICATED         0x01
+
 struct mgmt_ltk_info {
        struct mgmt_addr_info addr;
        __u8    type;
index f8ca69dd1984ec6de30e7c7357cf26e6907af1e8..5e9c21a5525f445ae7c513a9a175e6337aed3a41 100644 (file)
@@ -4534,7 +4534,7 @@ static int load_long_term_keys(struct sock *sk, struct hci_dev *hdev,
 
        for (i = 0; i < key_count; i++) {
                struct mgmt_ltk_info *key = &cp->keys[i];
-               u8 type, addr_type;
+               u8 type, addr_type, authenticated;
 
                if (key->addr.type == BDADDR_LE_PUBLIC)
                        addr_type = ADDR_LE_DEV_PUBLIC;
@@ -4546,8 +4546,13 @@ static int load_long_term_keys(struct sock *sk, struct hci_dev *hdev,
                else
                        type = HCI_SMP_LTK_SLAVE;
 
+               if (key->type == MGMT_LTK_UNAUTHENTICATED)
+                       authenticated = 0x00;
+               else
+                       authenticated = 0x01;
+
                hci_add_ltk(hdev, &key->addr.bdaddr, addr_type, type,
-                           key->type, key->val, key->enc_size, key->ediv,
+                           authenticated, key->val, key->enc_size, key->ediv,
                            key->rand);
        }
 
@@ -5222,6 +5227,14 @@ void mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key,
        mgmt_event(MGMT_EV_NEW_LINK_KEY, hdev, &ev, sizeof(ev), NULL);
 }
 
+static u8 mgmt_ltk_type(struct smp_ltk *ltk)
+{
+       if (ltk->authenticated)
+               return MGMT_LTK_AUTHENTICATED;
+
+       return MGMT_LTK_UNAUTHENTICATED;
+}
+
 void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, bool persistent)
 {
        struct mgmt_ev_new_long_term_key ev;
@@ -5247,7 +5260,7 @@ void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, bool persistent)
 
        bacpy(&ev.key.addr.bdaddr, &key->bdaddr);
        ev.key.addr.type = link_to_bdaddr(LE_LINK, key->bdaddr_type);
-       ev.key.type = key->authenticated;
+       ev.key.type = mgmt_ltk_type(key);
        ev.key.enc_size = key->enc_size;
        ev.key.ediv = key->ediv;
        ev.key.rand = key->rand;