diff options
author | John W. Linville <linville@tuxdriver.com> | 2013-12-09 15:31:57 -0500 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2013-12-09 15:31:57 -0500 |
commit | 596c62b1ffd3bb8cdb5053382679ff9b5d5bf81a (patch) | |
tree | b0ad85db84cf3074ad5db995b7aa4d775a7b9ca8 /net | |
parent | 145babc68eebc4d72cd1a92d92e91739b905b7df (diff) | |
parent | 201a5929c8c788f9ef53b010065c9ce70c9c06f0 (diff) |
Merge branch 'for-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next
Diffstat (limited to 'net')
-rw-r--r-- | net/bluetooth/hci_core.c | 20 | ||||
-rw-r--r-- | net/bluetooth/hci_event.c | 72 | ||||
-rw-r--r-- | net/bluetooth/mgmt.c | 17 | ||||
-rw-r--r-- | net/bluetooth/smp.c | 40 |
4 files changed, 70 insertions, 79 deletions
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 6ccc4eb9e55e..03e83558a411 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c | |||
@@ -1275,15 +1275,17 @@ static void hci_init3_req(struct hci_request *req, unsigned long opt) | |||
1275 | hci_setup_link_policy(req); | 1275 | hci_setup_link_policy(req); |
1276 | 1276 | ||
1277 | if (lmp_le_capable(hdev)) { | 1277 | if (lmp_le_capable(hdev)) { |
1278 | /* If the controller has a public BD_ADDR, then by | 1278 | if (test_bit(HCI_SETUP, &hdev->dev_flags)) { |
1279 | * default use that one. If this is a LE only | 1279 | /* If the controller has a public BD_ADDR, then |
1280 | * controller without one, default to the random | 1280 | * by default use that one. If this is a LE only |
1281 | * address. | 1281 | * controller without a public address, default |
1282 | */ | 1282 | * to the random address. |
1283 | if (bacmp(&hdev->bdaddr, BDADDR_ANY)) | 1283 | */ |
1284 | hdev->own_addr_type = ADDR_LE_DEV_PUBLIC; | 1284 | if (bacmp(&hdev->bdaddr, BDADDR_ANY)) |
1285 | else | 1285 | hdev->own_addr_type = ADDR_LE_DEV_PUBLIC; |
1286 | hdev->own_addr_type = ADDR_LE_DEV_RANDOM; | 1286 | else |
1287 | hdev->own_addr_type = ADDR_LE_DEV_RANDOM; | ||
1288 | } | ||
1287 | 1289 | ||
1288 | hci_set_le_support(req); | 1290 | hci_set_le_support(req); |
1289 | } | 1291 | } |
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 5935f748c0f9..5fb3df66c2cd 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c | |||
@@ -486,7 +486,10 @@ static void hci_cc_read_local_commands(struct hci_dev *hdev, | |||
486 | 486 | ||
487 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); | 487 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
488 | 488 | ||
489 | if (!rp->status) | 489 | if (rp->status) |
490 | return; | ||
491 | |||
492 | if (test_bit(HCI_SETUP, &hdev->dev_flags)) | ||
490 | memcpy(hdev->commands, rp->commands, sizeof(hdev->commands)); | 493 | memcpy(hdev->commands, rp->commands, sizeof(hdev->commands)); |
491 | } | 494 | } |
492 | 495 | ||
@@ -538,12 +541,6 @@ static void hci_cc_read_local_features(struct hci_dev *hdev, | |||
538 | 541 | ||
539 | if (hdev->features[0][5] & LMP_EDR_3S_ESCO) | 542 | if (hdev->features[0][5] & LMP_EDR_3S_ESCO) |
540 | hdev->esco_type |= (ESCO_2EV5 | ESCO_3EV5); | 543 | hdev->esco_type |= (ESCO_2EV5 | ESCO_3EV5); |
541 | |||
542 | BT_DBG("%s features 0x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x", hdev->name, | ||
543 | hdev->features[0][0], hdev->features[0][1], | ||
544 | hdev->features[0][2], hdev->features[0][3], | ||
545 | hdev->features[0][4], hdev->features[0][5], | ||
546 | hdev->features[0][6], hdev->features[0][7]); | ||
547 | } | 544 | } |
548 | 545 | ||
549 | static void hci_cc_read_local_ext_features(struct hci_dev *hdev, | 546 | static void hci_cc_read_local_ext_features(struct hci_dev *hdev, |
@@ -1782,7 +1779,9 @@ static u8 hci_to_mgmt_reason(u8 err) | |||
1782 | static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) | 1779 | static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
1783 | { | 1780 | { |
1784 | struct hci_ev_disconn_complete *ev = (void *) skb->data; | 1781 | struct hci_ev_disconn_complete *ev = (void *) skb->data; |
1782 | u8 reason = hci_to_mgmt_reason(ev->reason); | ||
1785 | struct hci_conn *conn; | 1783 | struct hci_conn *conn; |
1784 | u8 type; | ||
1786 | 1785 | ||
1787 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); | 1786 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
1788 | 1787 | ||
@@ -1792,43 +1791,38 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) | |||
1792 | if (!conn) | 1791 | if (!conn) |
1793 | goto unlock; | 1792 | goto unlock; |
1794 | 1793 | ||
1795 | if (ev->status == 0) | 1794 | if (ev->status) { |
1796 | conn->state = BT_CLOSED; | 1795 | mgmt_disconnect_failed(hdev, &conn->dst, conn->type, |
1796 | conn->dst_type, ev->status); | ||
1797 | goto unlock; | ||
1798 | } | ||
1797 | 1799 | ||
1798 | if (test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags) && | 1800 | conn->state = BT_CLOSED; |
1799 | (conn->type == ACL_LINK || conn->type == LE_LINK)) { | ||
1800 | if (ev->status) { | ||
1801 | mgmt_disconnect_failed(hdev, &conn->dst, conn->type, | ||
1802 | conn->dst_type, ev->status); | ||
1803 | } else { | ||
1804 | u8 reason = hci_to_mgmt_reason(ev->reason); | ||
1805 | 1801 | ||
1806 | mgmt_device_disconnected(hdev, &conn->dst, conn->type, | 1802 | if (test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) |
1807 | conn->dst_type, reason); | 1803 | mgmt_device_disconnected(hdev, &conn->dst, conn->type, |
1808 | } | 1804 | conn->dst_type, reason); |
1809 | } | ||
1810 | 1805 | ||
1811 | if (ev->status == 0) { | 1806 | if (conn->type == ACL_LINK && conn->flush_key) |
1812 | u8 type = conn->type; | 1807 | hci_remove_link_key(hdev, &conn->dst); |
1813 | 1808 | ||
1814 | if (type == ACL_LINK && conn->flush_key) | 1809 | type = conn->type; |
1815 | hci_remove_link_key(hdev, &conn->dst); | ||
1816 | hci_proto_disconn_cfm(conn, ev->reason); | ||
1817 | hci_conn_del(conn); | ||
1818 | 1810 | ||
1819 | /* Re-enable advertising if necessary, since it might | 1811 | hci_proto_disconn_cfm(conn, ev->reason); |
1820 | * have been disabled by the connection. From the | 1812 | hci_conn_del(conn); |
1821 | * HCI_LE_Set_Advertise_Enable command description in | 1813 | |
1822 | * the core specification (v4.0): | 1814 | /* Re-enable advertising if necessary, since it might |
1823 | * "The Controller shall continue advertising until the Host | 1815 | * have been disabled by the connection. From the |
1824 | * issues an LE_Set_Advertise_Enable command with | 1816 | * HCI_LE_Set_Advertise_Enable command description in |
1825 | * Advertising_Enable set to 0x00 (Advertising is disabled) | 1817 | * the core specification (v4.0): |
1826 | * or until a connection is created or until the Advertising | 1818 | * "The Controller shall continue advertising until the Host |
1827 | * is timed out due to Directed Advertising." | 1819 | * issues an LE_Set_Advertise_Enable command with |
1828 | */ | 1820 | * Advertising_Enable set to 0x00 (Advertising is disabled) |
1829 | if (type == LE_LINK) | 1821 | * or until a connection is created or until the Advertising |
1830 | mgmt_reenable_advertising(hdev); | 1822 | * is timed out due to Directed Advertising." |
1831 | } | 1823 | */ |
1824 | if (type == LE_LINK) | ||
1825 | mgmt_reenable_advertising(hdev); | ||
1832 | 1826 | ||
1833 | unlock: | 1827 | unlock: |
1834 | hci_dev_unlock(hdev); | 1828 | hci_dev_unlock(hdev); |
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 074d83690a41..a03ca3ca91bf 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c | |||
@@ -1264,7 +1264,7 @@ static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data, | |||
1264 | 1264 | ||
1265 | if (cp->val == 0x02) { | 1265 | if (cp->val == 0x02) { |
1266 | /* Limited discoverable mode */ | 1266 | /* Limited discoverable mode */ |
1267 | hci_cp.num_iac = 2; | 1267 | hci_cp.num_iac = min_t(u8, hdev->num_iac, 2); |
1268 | hci_cp.iac_lap[0] = 0x00; /* LIAC */ | 1268 | hci_cp.iac_lap[0] = 0x00; /* LIAC */ |
1269 | hci_cp.iac_lap[1] = 0x8b; | 1269 | hci_cp.iac_lap[1] = 0x8b; |
1270 | hci_cp.iac_lap[2] = 0x9e; | 1270 | hci_cp.iac_lap[2] = 0x9e; |
@@ -4595,6 +4595,9 @@ void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, | |||
4595 | struct mgmt_ev_device_disconnected ev; | 4595 | struct mgmt_ev_device_disconnected ev; |
4596 | struct sock *sk = NULL; | 4596 | struct sock *sk = NULL; |
4597 | 4597 | ||
4598 | if (link_type != ACL_LINK && link_type != LE_LINK) | ||
4599 | return; | ||
4600 | |||
4598 | mgmt_pending_foreach(MGMT_OP_DISCONNECT, hdev, disconnect_rsp, &sk); | 4601 | mgmt_pending_foreach(MGMT_OP_DISCONNECT, hdev, disconnect_rsp, &sk); |
4599 | 4602 | ||
4600 | bacpy(&ev.addr.bdaddr, bdaddr); | 4603 | bacpy(&ev.addr.bdaddr, bdaddr); |
@@ -4613,6 +4616,8 @@ void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, | |||
4613 | void mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, | 4616 | void mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, |
4614 | u8 link_type, u8 addr_type, u8 status) | 4617 | u8 link_type, u8 addr_type, u8 status) |
4615 | { | 4618 | { |
4619 | u8 bdaddr_type = link_to_bdaddr(link_type, addr_type); | ||
4620 | struct mgmt_cp_disconnect *cp; | ||
4616 | struct mgmt_rp_disconnect rp; | 4621 | struct mgmt_rp_disconnect rp; |
4617 | struct pending_cmd *cmd; | 4622 | struct pending_cmd *cmd; |
4618 | 4623 | ||
@@ -4623,8 +4628,16 @@ void mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, | |||
4623 | if (!cmd) | 4628 | if (!cmd) |
4624 | return; | 4629 | return; |
4625 | 4630 | ||
4631 | cp = cmd->param; | ||
4632 | |||
4633 | if (bacmp(bdaddr, &cp->addr.bdaddr)) | ||
4634 | return; | ||
4635 | |||
4636 | if (cp->addr.type != bdaddr_type) | ||
4637 | return; | ||
4638 | |||
4626 | bacpy(&rp.addr.bdaddr, bdaddr); | 4639 | bacpy(&rp.addr.bdaddr, bdaddr); |
4627 | rp.addr.type = link_to_bdaddr(link_type, addr_type); | 4640 | rp.addr.type = bdaddr_type; |
4628 | 4641 | ||
4629 | cmd_complete(cmd->sk, cmd->index, MGMT_OP_DISCONNECT, | 4642 | cmd_complete(cmd->sk, cmd->index, MGMT_OP_DISCONNECT, |
4630 | mgmt_status(status), &rp, sizeof(rp)); | 4643 | mgmt_status(status), &rp, sizeof(rp)); |
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c index 4b07acb8293c..e61e74a1aabb 100644 --- a/net/bluetooth/smp.c +++ b/net/bluetooth/smp.c | |||
@@ -53,8 +53,7 @@ static int smp_e(struct crypto_blkcipher *tfm, const u8 *k, u8 *r) | |||
53 | { | 53 | { |
54 | struct blkcipher_desc desc; | 54 | struct blkcipher_desc desc; |
55 | struct scatterlist sg; | 55 | struct scatterlist sg; |
56 | int err, iv_len; | 56 | int err; |
57 | unsigned char iv[128]; | ||
58 | 57 | ||
59 | if (tfm == NULL) { | 58 | if (tfm == NULL) { |
60 | BT_ERR("tfm %p", tfm); | 59 | BT_ERR("tfm %p", tfm); |
@@ -72,12 +71,6 @@ static int smp_e(struct crypto_blkcipher *tfm, const u8 *k, u8 *r) | |||
72 | 71 | ||
73 | sg_init_one(&sg, r, 16); | 72 | sg_init_one(&sg, r, 16); |
74 | 73 | ||
75 | iv_len = crypto_blkcipher_ivsize(tfm); | ||
76 | if (iv_len) { | ||
77 | memset(&iv, 0xff, iv_len); | ||
78 | crypto_blkcipher_set_iv(tfm, iv, iv_len); | ||
79 | } | ||
80 | |||
81 | err = crypto_blkcipher_encrypt(&desc, &sg, &sg, 16); | 74 | err = crypto_blkcipher_encrypt(&desc, &sg, &sg, 16); |
82 | if (err) | 75 | if (err) |
83 | BT_ERR("Encrypt data error %d", err); | 76 | BT_ERR("Encrypt data error %d", err); |
@@ -143,13 +136,6 @@ static int smp_s1(struct crypto_blkcipher *tfm, u8 k[16], u8 r1[16], | |||
143 | return err; | 136 | return err; |
144 | } | 137 | } |
145 | 138 | ||
146 | static int smp_rand(u8 *buf) | ||
147 | { | ||
148 | get_random_bytes(buf, 16); | ||
149 | |||
150 | return 0; | ||
151 | } | ||
152 | |||
153 | static struct sk_buff *smp_build_cmd(struct l2cap_conn *conn, u8 code, | 139 | static struct sk_buff *smp_build_cmd(struct l2cap_conn *conn, u8 code, |
154 | u16 dlen, void *data) | 140 | u16 dlen, void *data) |
155 | { | 141 | { |
@@ -257,11 +243,11 @@ static u8 check_enc_key_size(struct l2cap_conn *conn, __u8 max_key_size) | |||
257 | return 0; | 243 | return 0; |
258 | } | 244 | } |
259 | 245 | ||
260 | static void smp_failure(struct l2cap_conn *conn, u8 reason, u8 send) | 246 | static void smp_failure(struct l2cap_conn *conn, u8 reason) |
261 | { | 247 | { |
262 | struct hci_conn *hcon = conn->hcon; | 248 | struct hci_conn *hcon = conn->hcon; |
263 | 249 | ||
264 | if (send) | 250 | if (reason) |
265 | smp_send_cmd(conn, SMP_CMD_PAIRING_FAIL, sizeof(reason), | 251 | smp_send_cmd(conn, SMP_CMD_PAIRING_FAIL, sizeof(reason), |
266 | &reason); | 252 | &reason); |
267 | 253 | ||
@@ -406,7 +392,7 @@ static void confirm_work(struct work_struct *work) | |||
406 | return; | 392 | return; |
407 | 393 | ||
408 | error: | 394 | error: |
409 | smp_failure(conn, reason, 1); | 395 | smp_failure(conn, reason); |
410 | } | 396 | } |
411 | 397 | ||
412 | static void random_work(struct work_struct *work) | 398 | static void random_work(struct work_struct *work) |
@@ -490,7 +476,7 @@ static void random_work(struct work_struct *work) | |||
490 | return; | 476 | return; |
491 | 477 | ||
492 | error: | 478 | error: |
493 | smp_failure(conn, reason, 1); | 479 | smp_failure(conn, reason); |
494 | } | 480 | } |
495 | 481 | ||
496 | static struct smp_chan *smp_chan_create(struct l2cap_conn *conn) | 482 | static struct smp_chan *smp_chan_create(struct l2cap_conn *conn) |
@@ -555,10 +541,10 @@ int smp_user_confirm_reply(struct hci_conn *hcon, u16 mgmt_op, __le32 passkey) | |||
555 | break; | 541 | break; |
556 | case MGMT_OP_USER_PASSKEY_NEG_REPLY: | 542 | case MGMT_OP_USER_PASSKEY_NEG_REPLY: |
557 | case MGMT_OP_USER_CONFIRM_NEG_REPLY: | 543 | case MGMT_OP_USER_CONFIRM_NEG_REPLY: |
558 | smp_failure(conn, SMP_PASSKEY_ENTRY_FAILED, 1); | 544 | smp_failure(conn, SMP_PASSKEY_ENTRY_FAILED); |
559 | return 0; | 545 | return 0; |
560 | default: | 546 | default: |
561 | smp_failure(conn, SMP_PASSKEY_ENTRY_FAILED, 1); | 547 | smp_failure(conn, SMP_PASSKEY_ENTRY_FAILED); |
562 | return -EOPNOTSUPP; | 548 | return -EOPNOTSUPP; |
563 | } | 549 | } |
564 | 550 | ||
@@ -606,9 +592,7 @@ static u8 smp_cmd_pairing_req(struct l2cap_conn *conn, struct sk_buff *skb) | |||
606 | if (check_enc_key_size(conn, key_size)) | 592 | if (check_enc_key_size(conn, key_size)) |
607 | return SMP_ENC_KEY_SIZE; | 593 | return SMP_ENC_KEY_SIZE; |
608 | 594 | ||
609 | ret = smp_rand(smp->prnd); | 595 | get_random_bytes(smp->prnd, sizeof(smp->prnd)); |
610 | if (ret) | ||
611 | return SMP_UNSPECIFIED; | ||
612 | 596 | ||
613 | smp->prsp[0] = SMP_CMD_PAIRING_RSP; | 597 | smp->prsp[0] = SMP_CMD_PAIRING_RSP; |
614 | memcpy(&smp->prsp[1], &rsp, sizeof(rsp)); | 598 | memcpy(&smp->prsp[1], &rsp, sizeof(rsp)); |
@@ -644,9 +628,7 @@ static u8 smp_cmd_pairing_rsp(struct l2cap_conn *conn, struct sk_buff *skb) | |||
644 | if (check_enc_key_size(conn, key_size)) | 628 | if (check_enc_key_size(conn, key_size)) |
645 | return SMP_ENC_KEY_SIZE; | 629 | return SMP_ENC_KEY_SIZE; |
646 | 630 | ||
647 | ret = smp_rand(smp->prnd); | 631 | get_random_bytes(smp->prnd, sizeof(smp->prnd)); |
648 | if (ret) | ||
649 | return SMP_UNSPECIFIED; | ||
650 | 632 | ||
651 | smp->prsp[0] = SMP_CMD_PAIRING_RSP; | 633 | smp->prsp[0] = SMP_CMD_PAIRING_RSP; |
652 | memcpy(&smp->prsp[1], rsp, sizeof(*rsp)); | 634 | memcpy(&smp->prsp[1], rsp, sizeof(*rsp)); |
@@ -895,7 +877,7 @@ int smp_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb) | |||
895 | break; | 877 | break; |
896 | 878 | ||
897 | case SMP_CMD_PAIRING_FAIL: | 879 | case SMP_CMD_PAIRING_FAIL: |
898 | smp_failure(conn, skb->data[0], 0); | 880 | smp_failure(conn, 0); |
899 | reason = 0; | 881 | reason = 0; |
900 | err = -EPERM; | 882 | err = -EPERM; |
901 | break; | 883 | break; |
@@ -941,7 +923,7 @@ int smp_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb) | |||
941 | 923 | ||
942 | done: | 924 | done: |
943 | if (reason) | 925 | if (reason) |
944 | smp_failure(conn, reason, 1); | 926 | smp_failure(conn, reason); |
945 | 927 | ||
946 | kfree_skb(skb); | 928 | kfree_skb(skb); |
947 | return err; | 929 | return err; |