diff options
author | Vinicius Costa Gomes <vinicius.gomes@openbossa.org> | 2011-08-25 19:02:28 -0400 |
---|---|---|
committer | Gustavo F. Padovan <padovan@profusion.mobi> | 2011-09-21 11:59:15 -0400 |
commit | 988c5997d32052a58bd0127710bc8e2c8c5665b1 (patch) | |
tree | d00b021239f09cfbeb5135e7e065cf90baadfdbd /net/bluetooth | |
parent | 0fb4eb6f630a22bf4c2f358ef2db91f28a3d18d4 (diff) |
Bluetooth: Use the LTK after receiving a LE Security Request
When receiving a security request from the remote device we should find
if there is already a LTK associated with the remote device, if found
we should use it to encrypt the link.
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/smp.c | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c index 7e558465133f..8a7eaaedd67a 100644 --- a/net/bluetooth/smp.c +++ b/net/bluetooth/smp.c | |||
@@ -499,6 +499,29 @@ static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb) | |||
499 | return 0; | 499 | return 0; |
500 | } | 500 | } |
501 | 501 | ||
502 | static u8 smp_ltk_encrypt(struct l2cap_conn *conn) | ||
503 | { | ||
504 | struct link_key *key; | ||
505 | struct key_master_id *master; | ||
506 | struct hci_conn *hcon = conn->hcon; | ||
507 | |||
508 | key = hci_find_link_key_type(hcon->hdev, conn->dst, | ||
509 | HCI_LK_SMP_LTK); | ||
510 | if (!key) | ||
511 | return 0; | ||
512 | |||
513 | if (test_and_set_bit(HCI_CONN_ENCRYPT_PEND, | ||
514 | &hcon->pend)) | ||
515 | return 1; | ||
516 | |||
517 | master = (void *) key->data; | ||
518 | hci_le_start_enc(hcon, master->ediv, master->rand, | ||
519 | key->val); | ||
520 | hcon->enc_key_size = key->pin_len; | ||
521 | |||
522 | return 1; | ||
523 | |||
524 | } | ||
502 | static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb) | 525 | static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb) |
503 | { | 526 | { |
504 | struct smp_cmd_security_req *rp = (void *) skb->data; | 527 | struct smp_cmd_security_req *rp = (void *) skb->data; |
@@ -508,6 +531,9 @@ static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb) | |||
508 | 531 | ||
509 | BT_DBG("conn %p", conn); | 532 | BT_DBG("conn %p", conn); |
510 | 533 | ||
534 | if (smp_ltk_encrypt(conn)) | ||
535 | return 0; | ||
536 | |||
511 | if (test_and_set_bit(HCI_CONN_LE_SMP_PEND, &hcon->pend)) | 537 | if (test_and_set_bit(HCI_CONN_LE_SMP_PEND, &hcon->pend)) |
512 | return 0; | 538 | return 0; |
513 | 539 | ||
@@ -542,25 +568,9 @@ int smp_conn_security(struct l2cap_conn *conn, __u8 sec_level) | |||
542 | if (hcon->sec_level >= sec_level) | 568 | if (hcon->sec_level >= sec_level) |
543 | return 1; | 569 | return 1; |
544 | 570 | ||
545 | if (hcon->link_mode & HCI_LM_MASTER) { | 571 | if (hcon->link_mode & HCI_LM_MASTER) |
546 | struct link_key *key; | 572 | if (smp_ltk_encrypt(conn)) |
547 | |||
548 | key = hci_find_link_key_type(hcon->hdev, conn->dst, | ||
549 | HCI_LK_SMP_LTK); | ||
550 | if (key) { | ||
551 | struct key_master_id *master = (void *) key->data; | ||
552 | |||
553 | if (test_and_set_bit(HCI_CONN_ENCRYPT_PEND, | ||
554 | &hcon->pend)) | ||
555 | goto done; | ||
556 | |||
557 | hci_le_start_enc(hcon, master->ediv, master->rand, | ||
558 | key->val); | ||
559 | hcon->enc_key_size = key->pin_len; | ||
560 | |||
561 | goto done; | 573 | goto done; |
562 | } | ||
563 | } | ||
564 | 574 | ||
565 | if (test_and_set_bit(HCI_CONN_LE_SMP_PEND, &hcon->pend)) | 575 | if (test_and_set_bit(HCI_CONN_LE_SMP_PEND, &hcon->pend)) |
566 | return 0; | 576 | return 0; |