diff options
author | Vinicius Costa Gomes <vinicius.gomes@openbossa.org> | 2011-07-08 17:31:45 -0400 |
---|---|---|
committer | Gustavo F. Padovan <padovan@profusion.mobi> | 2011-07-08 17:39:19 -0400 |
commit | 726b4ffcaa450d9593b9b6ac8605967ce9f3e506 (patch) | |
tree | 5d274067ab8946d081f01c9b160bff495aca857c /net/bluetooth | |
parent | 5a0a8b49746771fba79866fb9185ffa051a6a183 (diff) |
Bluetooth: Add support for storing the key size
In some cases it will be useful having the key size used for
encrypting the link. For example, some profiles may restrict
some operations depending on the key length.
The key size is stored in the key that is passed to userspace
using the pin_length field in the key structure.
For now this field is only valid for LE controllers. 3.0+HS
controllers define the Read Encryption Key Size command, this
field is intended for storing the value returned by that
command.
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@openbossa.org>
Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
Diffstat (limited to 'net/bluetooth')
-rw-r--r-- | net/bluetooth/hci_core.c | 3 | ||||
-rw-r--r-- | net/bluetooth/hci_event.c | 1 | ||||
-rw-r--r-- | net/bluetooth/mgmt.c | 4 | ||||
-rw-r--r-- | net/bluetooth/smp.c | 14 |
4 files changed, 14 insertions, 8 deletions
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 4885914449f6..908fcd384ab4 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c | |||
@@ -1149,7 +1149,7 @@ int hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, int new_key, | |||
1149 | } | 1149 | } |
1150 | 1150 | ||
1151 | int hci_add_ltk(struct hci_dev *hdev, int new_key, bdaddr_t *bdaddr, | 1151 | int hci_add_ltk(struct hci_dev *hdev, int new_key, bdaddr_t *bdaddr, |
1152 | __le16 ediv, u8 rand[8], u8 ltk[16]) | 1152 | u8 key_size, __le16 ediv, u8 rand[8], u8 ltk[16]) |
1153 | { | 1153 | { |
1154 | struct link_key *key, *old_key; | 1154 | struct link_key *key, *old_key; |
1155 | struct key_master_id *id; | 1155 | struct key_master_id *id; |
@@ -1174,6 +1174,7 @@ int hci_add_ltk(struct hci_dev *hdev, int new_key, bdaddr_t *bdaddr, | |||
1174 | bacpy(&key->bdaddr, bdaddr); | 1174 | bacpy(&key->bdaddr, bdaddr); |
1175 | memcpy(key->val, ltk, sizeof(key->val)); | 1175 | memcpy(key->val, ltk, sizeof(key->val)); |
1176 | key->type = HCI_LK_SMP_LTK; | 1176 | key->type = HCI_LK_SMP_LTK; |
1177 | key->pin_len = key_size; | ||
1177 | 1178 | ||
1178 | id = (void *) &key->data; | 1179 | id = (void *) &key->data; |
1179 | id->ediv = ediv; | 1180 | id->ediv = ediv; |
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index ca5ff6eedf02..a40170e022e8 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c | |||
@@ -2876,6 +2876,7 @@ static inline void hci_le_ltk_request_evt(struct hci_dev *hdev, | |||
2876 | 2876 | ||
2877 | memcpy(cp.ltk, ltk->val, sizeof(ltk->val)); | 2877 | memcpy(cp.ltk, ltk->val, sizeof(ltk->val)); |
2878 | cp.handle = cpu_to_le16(conn->handle); | 2878 | cp.handle = cpu_to_le16(conn->handle); |
2879 | conn->pin_length = ltk->pin_len; | ||
2879 | 2880 | ||
2880 | hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp); | 2881 | hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp); |
2881 | 2882 | ||
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index f424d6ab4c1e..53e109eb043e 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c | |||
@@ -956,8 +956,8 @@ static int load_keys(struct sock *sk, u16 index, unsigned char *data, u16 len) | |||
956 | if (key->dlen != sizeof(struct key_master_id)) | 956 | if (key->dlen != sizeof(struct key_master_id)) |
957 | continue; | 957 | continue; |
958 | 958 | ||
959 | hci_add_ltk(hdev, 0, &key->bdaddr, id->ediv, | 959 | hci_add_ltk(hdev, 0, &key->bdaddr, key->pin_len, |
960 | id->rand, key->val); | 960 | id->ediv, id->rand, key->val); |
961 | 961 | ||
962 | continue; | 962 | continue; |
963 | } | 963 | } |
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c index a8b971b75a67..391888b88a92 100644 --- a/net/bluetooth/smp.c +++ b/net/bluetooth/smp.c | |||
@@ -401,6 +401,7 @@ static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb) | |||
401 | SMP_MAX_ENC_KEY_SIZE - conn->smp_key_size); | 401 | SMP_MAX_ENC_KEY_SIZE - conn->smp_key_size); |
402 | 402 | ||
403 | hci_le_start_enc(hcon, ediv, rand, stk); | 403 | hci_le_start_enc(hcon, ediv, rand, stk); |
404 | hcon->enc_key_size = conn->smp_key_size; | ||
404 | } else { | 405 | } else { |
405 | u8 stk[16], r[16], rand[8]; | 406 | u8 stk[16], r[16], rand[8]; |
406 | __le16 ediv; | 407 | __le16 ediv; |
@@ -417,7 +418,8 @@ static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb) | |||
417 | memset(stk + conn->smp_key_size, 0, | 418 | memset(stk + conn->smp_key_size, 0, |
418 | SMP_MAX_ENC_KEY_SIZE - conn->smp_key_size); | 419 | SMP_MAX_ENC_KEY_SIZE - conn->smp_key_size); |
419 | 420 | ||
420 | hci_add_ltk(conn->hcon->hdev, 0, conn->dst, ediv, rand, stk); | 421 | hci_add_ltk(conn->hcon->hdev, 0, conn->dst, conn->smp_key_size, |
422 | ediv, rand, stk); | ||
421 | } | 423 | } |
422 | 424 | ||
423 | return 0; | 425 | return 0; |
@@ -487,6 +489,8 @@ int smp_conn_security(struct l2cap_conn *conn, __u8 sec_level) | |||
487 | 489 | ||
488 | hci_le_start_enc(hcon, master->ediv, master->rand, | 490 | hci_le_start_enc(hcon, master->ediv, master->rand, |
489 | key->val); | 491 | key->val); |
492 | hcon->enc_key_size = key->pin_len; | ||
493 | |||
490 | goto done; | 494 | goto done; |
491 | } | 495 | } |
492 | 496 | ||
@@ -528,8 +532,8 @@ static int smp_cmd_master_ident(struct l2cap_conn *conn, struct sk_buff *skb) | |||
528 | 532 | ||
529 | skb_pull(skb, sizeof(*rp)); | 533 | skb_pull(skb, sizeof(*rp)); |
530 | 534 | ||
531 | hci_add_ltk(conn->hcon->hdev, 1, conn->src, rp->ediv, | 535 | hci_add_ltk(conn->hcon->hdev, 1, conn->src, conn->smp_key_size, |
532 | rp->rand, conn->tk); | 536 | rp->ediv, rp->rand, conn->tk); |
533 | 537 | ||
534 | smp_distribute_keys(conn, 1); | 538 | smp_distribute_keys(conn, 1); |
535 | 539 | ||
@@ -654,8 +658,8 @@ int smp_distribute_keys(struct l2cap_conn *conn, __u8 force) | |||
654 | 658 | ||
655 | smp_send_cmd(conn, SMP_CMD_ENCRYPT_INFO, sizeof(enc), &enc); | 659 | smp_send_cmd(conn, SMP_CMD_ENCRYPT_INFO, sizeof(enc), &enc); |
656 | 660 | ||
657 | hci_add_ltk(conn->hcon->hdev, 1, conn->dst, ediv, | 661 | hci_add_ltk(conn->hcon->hdev, 1, conn->dst, conn->smp_key_size, |
658 | ident.rand, enc.ltk); | 662 | ediv, ident.rand, enc.ltk); |
659 | 663 | ||
660 | ident.ediv = cpu_to_le16(ediv); | 664 | ident.ediv = cpu_to_le16(ediv); |
661 | 665 | ||