aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth/hci_conn.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/bluetooth/hci_conn.c')
-rw-r--r--net/bluetooth/hci_conn.c73
1 files changed, 33 insertions, 40 deletions
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 07bc69ed9498..947172bf1621 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -35,7 +35,6 @@
35#include <linux/init.h> 35#include <linux/init.h>
36#include <linux/skbuff.h> 36#include <linux/skbuff.h>
37#include <linux/interrupt.h> 37#include <linux/interrupt.h>
38#include <linux/notifier.h>
39#include <net/sock.h> 38#include <net/sock.h>
40 39
41#include <asm/system.h> 40#include <asm/system.h>
@@ -51,7 +50,7 @@ static void hci_le_connect(struct hci_conn *conn)
51 struct hci_cp_le_create_conn cp; 50 struct hci_cp_le_create_conn cp;
52 51
53 conn->state = BT_CONNECT; 52 conn->state = BT_CONNECT;
54 conn->out = 1; 53 conn->out = true;
55 conn->link_mode |= HCI_LM_MASTER; 54 conn->link_mode |= HCI_LM_MASTER;
56 conn->sec_level = BT_SECURITY_LOW; 55 conn->sec_level = BT_SECURITY_LOW;
57 56
@@ -80,10 +79,10 @@ void hci_acl_connect(struct hci_conn *conn)
80 struct inquiry_entry *ie; 79 struct inquiry_entry *ie;
81 struct hci_cp_create_conn cp; 80 struct hci_cp_create_conn cp;
82 81
83 BT_DBG("%p", conn); 82 BT_DBG("hcon %p", conn);
84 83
85 conn->state = BT_CONNECT; 84 conn->state = BT_CONNECT;
86 conn->out = 1; 85 conn->out = true;
87 86
88 conn->link_mode = HCI_LM_MASTER; 87 conn->link_mode = HCI_LM_MASTER;
89 88
@@ -105,7 +104,8 @@ void hci_acl_connect(struct hci_conn *conn)
105 } 104 }
106 105
107 memcpy(conn->dev_class, ie->data.dev_class, 3); 106 memcpy(conn->dev_class, ie->data.dev_class, 3);
108 conn->ssp_mode = ie->data.ssp_mode; 107 if (ie->data.ssp_mode > 0)
108 set_bit(HCI_CONN_SSP_ENABLED, &conn->flags);
109 } 109 }
110 110
111 cp.pkt_type = cpu_to_le16(conn->pkt_type); 111 cp.pkt_type = cpu_to_le16(conn->pkt_type);
@@ -151,7 +151,7 @@ void hci_add_sco(struct hci_conn *conn, __u16 handle)
151 BT_DBG("%p", conn); 151 BT_DBG("%p", conn);
152 152
153 conn->state = BT_CONNECT; 153 conn->state = BT_CONNECT;
154 conn->out = 1; 154 conn->out = true;
155 155
156 conn->attempt++; 156 conn->attempt++;
157 157
@@ -169,7 +169,7 @@ void hci_setup_sync(struct hci_conn *conn, __u16 handle)
169 BT_DBG("%p", conn); 169 BT_DBG("%p", conn);
170 170
171 conn->state = BT_CONNECT; 171 conn->state = BT_CONNECT;
172 conn->out = 1; 172 conn->out = true;
173 173
174 conn->attempt++; 174 conn->attempt++;
175 175
@@ -279,16 +279,13 @@ static void hci_conn_timeout(struct work_struct *work)
279{ 279{
280 struct hci_conn *conn = container_of(work, struct hci_conn, 280 struct hci_conn *conn = container_of(work, struct hci_conn,
281 disc_work.work); 281 disc_work.work);
282 struct hci_dev *hdev = conn->hdev;
283 __u8 reason; 282 __u8 reason;
284 283
285 BT_DBG("conn %p state %d", conn, conn->state); 284 BT_DBG("conn %p state %s", conn, state_to_string(conn->state));
286 285
287 if (atomic_read(&conn->refcnt)) 286 if (atomic_read(&conn->refcnt))
288 return; 287 return;
289 288
290 hci_dev_lock(hdev);
291
292 switch (conn->state) { 289 switch (conn->state) {
293 case BT_CONNECT: 290 case BT_CONNECT:
294 case BT_CONNECT2: 291 case BT_CONNECT2:
@@ -308,8 +305,6 @@ static void hci_conn_timeout(struct work_struct *work)
308 conn->state = BT_CLOSED; 305 conn->state = BT_CLOSED;
309 break; 306 break;
310 } 307 }
311
312 hci_dev_unlock(hdev);
313} 308}
314 309
315/* Enter sniff mode */ 310/* Enter sniff mode */
@@ -337,7 +332,7 @@ static void hci_conn_enter_sniff_mode(struct hci_conn *conn)
337 hci_send_cmd(hdev, HCI_OP_SNIFF_SUBRATE, sizeof(cp), &cp); 332 hci_send_cmd(hdev, HCI_OP_SNIFF_SUBRATE, sizeof(cp), &cp);
338 } 333 }
339 334
340 if (!test_and_set_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->pend)) { 335 if (!test_and_set_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags)) {
341 struct hci_cp_sniff_mode cp; 336 struct hci_cp_sniff_mode cp;
342 cp.handle = cpu_to_le16(conn->handle); 337 cp.handle = cpu_to_le16(conn->handle);
343 cp.max_interval = cpu_to_le16(hdev->sniff_max_interval); 338 cp.max_interval = cpu_to_le16(hdev->sniff_max_interval);
@@ -372,7 +367,7 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst)
372 367
373 BT_DBG("%s dst %s", hdev->name, batostr(dst)); 368 BT_DBG("%s dst %s", hdev->name, batostr(dst));
374 369
375 conn = kzalloc(sizeof(struct hci_conn), GFP_ATOMIC); 370 conn = kzalloc(sizeof(struct hci_conn), GFP_KERNEL);
376 if (!conn) 371 if (!conn)
377 return NULL; 372 return NULL;
378 373
@@ -386,7 +381,7 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst)
386 conn->remote_auth = 0xff; 381 conn->remote_auth = 0xff;
387 conn->key_type = 0xff; 382 conn->key_type = 0xff;
388 383
389 conn->power_save = 1; 384 set_bit(HCI_CONN_POWER_SAVE, &conn->flags);
390 conn->disc_timeout = HCI_DISCONN_TIMEOUT; 385 conn->disc_timeout = HCI_DISCONN_TIMEOUT;
391 386
392 switch (type) { 387 switch (type) {
@@ -407,7 +402,7 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst)
407 402
408 skb_queue_head_init(&conn->data_q); 403 skb_queue_head_init(&conn->data_q);
409 404
410 INIT_LIST_HEAD(&conn->chan_list);; 405 INIT_LIST_HEAD(&conn->chan_list);
411 406
412 INIT_DELAYED_WORK(&conn->disc_work, hci_conn_timeout); 407 INIT_DELAYED_WORK(&conn->disc_work, hci_conn_timeout);
413 setup_timer(&conn->idle_timer, hci_conn_idle, (unsigned long)conn); 408 setup_timer(&conn->idle_timer, hci_conn_idle, (unsigned long)conn);
@@ -555,7 +550,7 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8
555 if (!acl) { 550 if (!acl) {
556 acl = hci_conn_add(hdev, ACL_LINK, dst); 551 acl = hci_conn_add(hdev, ACL_LINK, dst);
557 if (!acl) 552 if (!acl)
558 return NULL; 553 return ERR_PTR(-ENOMEM);
559 } 554 }
560 555
561 hci_conn_hold(acl); 556 hci_conn_hold(acl);
@@ -575,7 +570,7 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8
575 sco = hci_conn_add(hdev, type, dst); 570 sco = hci_conn_add(hdev, type, dst);
576 if (!sco) { 571 if (!sco) {
577 hci_conn_put(acl); 572 hci_conn_put(acl);
578 return NULL; 573 return ERR_PTR(-ENOMEM);
579 } 574 }
580 } 575 }
581 576
@@ -586,12 +581,12 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8
586 581
587 if (acl->state == BT_CONNECTED && 582 if (acl->state == BT_CONNECTED &&
588 (sco->state == BT_OPEN || sco->state == BT_CLOSED)) { 583 (sco->state == BT_OPEN || sco->state == BT_CLOSED)) {
589 acl->power_save = 1; 584 set_bit(HCI_CONN_POWER_SAVE, &acl->flags);
590 hci_conn_enter_active_mode(acl, BT_POWER_FORCE_ACTIVE_ON); 585 hci_conn_enter_active_mode(acl, BT_POWER_FORCE_ACTIVE_ON);
591 586
592 if (test_bit(HCI_CONN_MODE_CHANGE_PEND, &acl->pend)) { 587 if (test_bit(HCI_CONN_MODE_CHANGE_PEND, &acl->flags)) {
593 /* defer SCO setup until mode change completed */ 588 /* defer SCO setup until mode change completed */
594 set_bit(HCI_CONN_SCO_SETUP_PEND, &acl->pend); 589 set_bit(HCI_CONN_SCO_SETUP_PEND, &acl->flags);
595 return sco; 590 return sco;
596 } 591 }
597 592
@@ -607,8 +602,7 @@ int hci_conn_check_link_mode(struct hci_conn *conn)
607{ 602{
608 BT_DBG("conn %p", conn); 603 BT_DBG("conn %p", conn);
609 604
610 if (conn->ssp_mode > 0 && conn->hdev->ssp_mode > 0 && 605 if (hci_conn_ssp_enabled(conn) && !(conn->link_mode & HCI_LM_ENCRYPT))
611 !(conn->link_mode & HCI_LM_ENCRYPT))
612 return 0; 606 return 0;
613 607
614 return 1; 608 return 1;
@@ -633,17 +627,17 @@ static int hci_conn_auth(struct hci_conn *conn, __u8 sec_level, __u8 auth_type)
633 627
634 conn->auth_type = auth_type; 628 conn->auth_type = auth_type;
635 629
636 if (!test_and_set_bit(HCI_CONN_AUTH_PEND, &conn->pend)) { 630 if (!test_and_set_bit(HCI_CONN_AUTH_PEND, &conn->flags)) {
637 struct hci_cp_auth_requested cp; 631 struct hci_cp_auth_requested cp;
638 632
639 /* encrypt must be pending if auth is also pending */ 633 /* encrypt must be pending if auth is also pending */
640 set_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend); 634 set_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags);
641 635
642 cp.handle = cpu_to_le16(conn->handle); 636 cp.handle = cpu_to_le16(conn->handle);
643 hci_send_cmd(conn->hdev, HCI_OP_AUTH_REQUESTED, 637 hci_send_cmd(conn->hdev, HCI_OP_AUTH_REQUESTED,
644 sizeof(cp), &cp); 638 sizeof(cp), &cp);
645 if (conn->key_type != 0xff) 639 if (conn->key_type != 0xff)
646 set_bit(HCI_CONN_REAUTH_PEND, &conn->pend); 640 set_bit(HCI_CONN_REAUTH_PEND, &conn->flags);
647 } 641 }
648 642
649 return 0; 643 return 0;
@@ -654,7 +648,7 @@ static void hci_conn_encrypt(struct hci_conn *conn)
654{ 648{
655 BT_DBG("conn %p", conn); 649 BT_DBG("conn %p", conn);
656 650
657 if (!test_and_set_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend)) { 651 if (!test_and_set_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) {
658 struct hci_cp_set_conn_encrypt cp; 652 struct hci_cp_set_conn_encrypt cp;
659 cp.handle = cpu_to_le16(conn->handle); 653 cp.handle = cpu_to_le16(conn->handle);
660 cp.encrypt = 0x01; 654 cp.encrypt = 0x01;
@@ -674,8 +668,7 @@ int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type)
674 668
675 /* For non 2.1 devices and low security level we don't need the link 669 /* For non 2.1 devices and low security level we don't need the link
676 key. */ 670 key. */
677 if (sec_level == BT_SECURITY_LOW && 671 if (sec_level == BT_SECURITY_LOW && !hci_conn_ssp_enabled(conn))
678 (!conn->ssp_mode || !conn->hdev->ssp_mode))
679 return 1; 672 return 1;
680 673
681 /* For other security levels we need the link key. */ 674 /* For other security levels we need the link key. */
@@ -704,7 +697,7 @@ int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type)
704 goto encrypt; 697 goto encrypt;
705 698
706auth: 699auth:
707 if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend)) 700 if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags))
708 return 0; 701 return 0;
709 702
710 if (!hci_conn_auth(conn, sec_level, auth_type)) 703 if (!hci_conn_auth(conn, sec_level, auth_type))
@@ -739,7 +732,7 @@ int hci_conn_change_link_key(struct hci_conn *conn)
739{ 732{
740 BT_DBG("conn %p", conn); 733 BT_DBG("conn %p", conn);
741 734
742 if (!test_and_set_bit(HCI_CONN_AUTH_PEND, &conn->pend)) { 735 if (!test_and_set_bit(HCI_CONN_AUTH_PEND, &conn->flags)) {
743 struct hci_cp_change_conn_link_key cp; 736 struct hci_cp_change_conn_link_key cp;
744 cp.handle = cpu_to_le16(conn->handle); 737 cp.handle = cpu_to_le16(conn->handle);
745 hci_send_cmd(conn->hdev, HCI_OP_CHANGE_CONN_LINK_KEY, 738 hci_send_cmd(conn->hdev, HCI_OP_CHANGE_CONN_LINK_KEY,
@@ -758,7 +751,7 @@ int hci_conn_switch_role(struct hci_conn *conn, __u8 role)
758 if (!role && conn->link_mode & HCI_LM_MASTER) 751 if (!role && conn->link_mode & HCI_LM_MASTER)
759 return 1; 752 return 1;
760 753
761 if (!test_and_set_bit(HCI_CONN_RSWITCH_PEND, &conn->pend)) { 754 if (!test_and_set_bit(HCI_CONN_RSWITCH_PEND, &conn->flags)) {
762 struct hci_cp_switch_role cp; 755 struct hci_cp_switch_role cp;
763 bacpy(&cp.bdaddr, &conn->dst); 756 bacpy(&cp.bdaddr, &conn->dst);
764 cp.role = role; 757 cp.role = role;
@@ -782,10 +775,10 @@ void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active)
782 if (conn->mode != HCI_CM_SNIFF) 775 if (conn->mode != HCI_CM_SNIFF)
783 goto timer; 776 goto timer;
784 777
785 if (!conn->power_save && !force_active) 778 if (!test_bit(HCI_CONN_POWER_SAVE, &conn->flags) && !force_active)
786 goto timer; 779 goto timer;
787 780
788 if (!test_and_set_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->pend)) { 781 if (!test_and_set_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags)) {
789 struct hci_cp_exit_sniff_mode cp; 782 struct hci_cp_exit_sniff_mode cp;
790 cp.handle = cpu_to_le16(conn->handle); 783 cp.handle = cpu_to_le16(conn->handle);
791 hci_send_cmd(hdev, HCI_OP_EXIT_SNIFF_MODE, sizeof(cp), &cp); 784 hci_send_cmd(hdev, HCI_OP_EXIT_SNIFF_MODE, sizeof(cp), &cp);
@@ -801,11 +794,11 @@ timer:
801void hci_conn_hash_flush(struct hci_dev *hdev) 794void hci_conn_hash_flush(struct hci_dev *hdev)
802{ 795{
803 struct hci_conn_hash *h = &hdev->conn_hash; 796 struct hci_conn_hash *h = &hdev->conn_hash;
804 struct hci_conn *c; 797 struct hci_conn *c, *n;
805 798
806 BT_DBG("hdev %s", hdev->name); 799 BT_DBG("hdev %s", hdev->name);
807 800
808 list_for_each_entry_rcu(c, &h->list, list) { 801 list_for_each_entry_safe(c, n, &h->list, list) {
809 c->state = BT_CLOSED; 802 c->state = BT_CLOSED;
810 803
811 hci_proto_disconn_cfm(c, HCI_ERROR_LOCAL_HOST_TERM); 804 hci_proto_disconn_cfm(c, HCI_ERROR_LOCAL_HOST_TERM);
@@ -950,7 +943,7 @@ struct hci_chan *hci_chan_create(struct hci_conn *conn)
950 943
951 BT_DBG("%s conn %p", hdev->name, conn); 944 BT_DBG("%s conn %p", hdev->name, conn);
952 945
953 chan = kzalloc(sizeof(struct hci_chan), GFP_ATOMIC); 946 chan = kzalloc(sizeof(struct hci_chan), GFP_KERNEL);
954 if (!chan) 947 if (!chan)
955 return NULL; 948 return NULL;
956 949
@@ -981,10 +974,10 @@ int hci_chan_del(struct hci_chan *chan)
981 974
982void hci_chan_list_flush(struct hci_conn *conn) 975void hci_chan_list_flush(struct hci_conn *conn)
983{ 976{
984 struct hci_chan *chan; 977 struct hci_chan *chan, *n;
985 978
986 BT_DBG("conn %p", conn); 979 BT_DBG("conn %p", conn);
987 980
988 list_for_each_entry_rcu(chan, &conn->chan_list, list) 981 list_for_each_entry_safe(chan, n, &conn->chan_list, list)
989 hci_chan_del(chan); 982 hci_chan_del(chan);
990} 983}