Commit 8556876847effb03ca33334464c2854bdd3f0ed8

Authored by Johan Hedberg
Committed by Greg Kroah-Hartman
1 parent 28084dbaaf

Bluetooth: Clearly distinguish mgmt LTK type from authenticated property

commit d7b2545023ecfde94d3ea9c03c5480ac18da96c9 upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Showing 2 changed files with 19 additions and 3 deletions Side-by-side Diff

include/net/bluetooth/mgmt.h
... ... @@ -181,6 +181,9 @@
181 181 } __packed;
182 182 #define MGMT_LOAD_LINK_KEYS_SIZE 3
183 183  
  184 +#define MGMT_LTK_UNAUTHENTICATED 0x00
  185 +#define MGMT_LTK_AUTHENTICATED 0x01
  186 +
184 187 struct mgmt_ltk_info {
185 188 struct mgmt_addr_info addr;
186 189 __u8 type;
net/bluetooth/mgmt.c
... ... @@ -4530,7 +4530,7 @@
4530 4530  
4531 4531 for (i = 0; i < key_count; i++) {
4532 4532 struct mgmt_ltk_info *key = &cp->keys[i];
4533   - u8 type, addr_type;
  4533 + u8 type, addr_type, authenticated;
4534 4534  
4535 4535 if (key->addr.type == BDADDR_LE_PUBLIC)
4536 4536 addr_type = ADDR_LE_DEV_PUBLIC;
4537 4537  
... ... @@ -4542,8 +4542,13 @@
4542 4542 else
4543 4543 type = HCI_SMP_LTK_SLAVE;
4544 4544  
  4545 + if (key->type == MGMT_LTK_UNAUTHENTICATED)
  4546 + authenticated = 0x00;
  4547 + else
  4548 + authenticated = 0x01;
  4549 +
4545 4550 hci_add_ltk(hdev, &key->addr.bdaddr, addr_type, type,
4546   - key->type, key->val, key->enc_size, key->ediv,
  4551 + authenticated, key->val, key->enc_size, key->ediv,
4547 4552 key->rand);
4548 4553 }
4549 4554  
... ... @@ -5005,6 +5010,14 @@
5005 5010 mgmt_event(MGMT_EV_NEW_LINK_KEY, hdev, &ev, sizeof(ev), NULL);
5006 5011 }
5007 5012  
  5013 +static u8 mgmt_ltk_type(struct smp_ltk *ltk)
  5014 +{
  5015 + if (ltk->authenticated)
  5016 + return MGMT_LTK_AUTHENTICATED;
  5017 +
  5018 + return MGMT_LTK_UNAUTHENTICATED;
  5019 +}
  5020 +
5008 5021 void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, bool persistent)
5009 5022 {
5010 5023 struct mgmt_ev_new_long_term_key ev;
... ... @@ -5030,7 +5043,7 @@
5030 5043  
5031 5044 bacpy(&ev.key.addr.bdaddr, &key->bdaddr);
5032 5045 ev.key.addr.type = link_to_bdaddr(LE_LINK, key->bdaddr_type);
5033   - ev.key.type = key->authenticated;
  5046 + ev.key.type = mgmt_ltk_type(key);
5034 5047 ev.key.enc_size = key->enc_size;
5035 5048 ev.key.ediv = key->ediv;
5036 5049 ev.key.rand = key->rand;