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