aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth/hci_event.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/bluetooth/hci_event.c')
-rw-r--r--net/bluetooth/hci_event.c512
1 files changed, 454 insertions, 58 deletions
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 6aef8f24e581..0e3db289f4be 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -110,6 +110,25 @@ static void hci_cc_role_discovery(struct hci_dev *hdev, struct sk_buff *skb)
110 hci_dev_unlock(hdev); 110 hci_dev_unlock(hdev);
111} 111}
112 112
113static void hci_cc_read_link_policy(struct hci_dev *hdev, struct sk_buff *skb)
114{
115 struct hci_rp_read_link_policy *rp = (void *) skb->data;
116 struct hci_conn *conn;
117
118 BT_DBG("%s status 0x%x", hdev->name, rp->status);
119
120 if (rp->status)
121 return;
122
123 hci_dev_lock(hdev);
124
125 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
126 if (conn)
127 conn->link_policy = __le16_to_cpu(rp->policy);
128
129 hci_dev_unlock(hdev);
130}
131
113static void hci_cc_write_link_policy(struct hci_dev *hdev, struct sk_buff *skb) 132static void hci_cc_write_link_policy(struct hci_dev *hdev, struct sk_buff *skb)
114{ 133{
115 struct hci_rp_write_link_policy *rp = (void *) skb->data; 134 struct hci_rp_write_link_policy *rp = (void *) skb->data;
@@ -128,13 +147,41 @@ static void hci_cc_write_link_policy(struct hci_dev *hdev, struct sk_buff *skb)
128 hci_dev_lock(hdev); 147 hci_dev_lock(hdev);
129 148
130 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); 149 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
131 if (conn) { 150 if (conn)
132 conn->link_policy = get_unaligned_le16(sent + 2); 151 conn->link_policy = get_unaligned_le16(sent + 2);
133 }
134 152
135 hci_dev_unlock(hdev); 153 hci_dev_unlock(hdev);
136} 154}
137 155
156static void hci_cc_read_def_link_policy(struct hci_dev *hdev, struct sk_buff *skb)
157{
158 struct hci_rp_read_def_link_policy *rp = (void *) skb->data;
159
160 BT_DBG("%s status 0x%x", hdev->name, rp->status);
161
162 if (rp->status)
163 return;
164
165 hdev->link_policy = __le16_to_cpu(rp->policy);
166}
167
168static void hci_cc_write_def_link_policy(struct hci_dev *hdev, struct sk_buff *skb)
169{
170 __u8 status = *((__u8 *) skb->data);
171 void *sent;
172
173 BT_DBG("%s status 0x%x", hdev->name, status);
174
175 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_DEF_LINK_POLICY);
176 if (!sent)
177 return;
178
179 if (!status)
180 hdev->link_policy = get_unaligned_le16(sent);
181
182 hci_req_complete(hdev, status);
183}
184
138static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb) 185static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb)
139{ 186{
140 __u8 status = *((__u8 *) skb->data); 187 __u8 status = *((__u8 *) skb->data);
@@ -151,12 +198,14 @@ static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb)
151 198
152 BT_DBG("%s status 0x%x", hdev->name, status); 199 BT_DBG("%s status 0x%x", hdev->name, status);
153 200
201 if (status)
202 return;
203
154 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LOCAL_NAME); 204 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LOCAL_NAME);
155 if (!sent) 205 if (!sent)
156 return; 206 return;
157 207
158 if (!status) 208 memcpy(hdev->dev_name, sent, 248);
159 memcpy(hdev->dev_name, sent, 248);
160} 209}
161 210
162static void hci_cc_read_local_name(struct hci_dev *hdev, struct sk_buff *skb) 211static void hci_cc_read_local_name(struct hci_dev *hdev, struct sk_buff *skb)
@@ -266,12 +315,14 @@ static void hci_cc_write_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb)
266 315
267 BT_DBG("%s status 0x%x", hdev->name, status); 316 BT_DBG("%s status 0x%x", hdev->name, status);
268 317
318 if (status)
319 return;
320
269 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_CLASS_OF_DEV); 321 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_CLASS_OF_DEV);
270 if (!sent) 322 if (!sent)
271 return; 323 return;
272 324
273 if (!status) 325 memcpy(hdev->dev_class, sent, 3);
274 memcpy(hdev->dev_class, sent, 3);
275} 326}
276 327
277static void hci_cc_read_voice_setting(struct hci_dev *hdev, struct sk_buff *skb) 328static void hci_cc_read_voice_setting(struct hci_dev *hdev, struct sk_buff *skb)
@@ -286,7 +337,7 @@ static void hci_cc_read_voice_setting(struct hci_dev *hdev, struct sk_buff *skb)
286 337
287 setting = __le16_to_cpu(rp->voice_setting); 338 setting = __le16_to_cpu(rp->voice_setting);
288 339
289 if (hdev->voice_setting == setting ) 340 if (hdev->voice_setting == setting)
290 return; 341 return;
291 342
292 hdev->voice_setting = setting; 343 hdev->voice_setting = setting;
@@ -303,28 +354,31 @@ static void hci_cc_read_voice_setting(struct hci_dev *hdev, struct sk_buff *skb)
303static void hci_cc_write_voice_setting(struct hci_dev *hdev, struct sk_buff *skb) 354static void hci_cc_write_voice_setting(struct hci_dev *hdev, struct sk_buff *skb)
304{ 355{
305 __u8 status = *((__u8 *) skb->data); 356 __u8 status = *((__u8 *) skb->data);
357 __u16 setting;
306 void *sent; 358 void *sent;
307 359
308 BT_DBG("%s status 0x%x", hdev->name, status); 360 BT_DBG("%s status 0x%x", hdev->name, status);
309 361
362 if (status)
363 return;
364
310 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_VOICE_SETTING); 365 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_VOICE_SETTING);
311 if (!sent) 366 if (!sent)
312 return; 367 return;
313 368
314 if (!status) { 369 setting = get_unaligned_le16(sent);
315 __u16 setting = get_unaligned_le16(sent);
316 370
317 if (hdev->voice_setting != setting) { 371 if (hdev->voice_setting == setting)
318 hdev->voice_setting = setting; 372 return;
319 373
320 BT_DBG("%s voice setting 0x%04x", hdev->name, setting); 374 hdev->voice_setting = setting;
321 375
322 if (hdev->notify) { 376 BT_DBG("%s voice setting 0x%04x", hdev->name, setting);
323 tasklet_disable(&hdev->tx_task); 377
324 hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING); 378 if (hdev->notify) {
325 tasklet_enable(&hdev->tx_task); 379 tasklet_disable(&hdev->tx_task);
326 } 380 hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING);
327 } 381 tasklet_enable(&hdev->tx_task);
328 } 382 }
329} 383}
330 384
@@ -337,6 +391,35 @@ static void hci_cc_host_buffer_size(struct hci_dev *hdev, struct sk_buff *skb)
337 hci_req_complete(hdev, status); 391 hci_req_complete(hdev, status);
338} 392}
339 393
394static void hci_cc_read_ssp_mode(struct hci_dev *hdev, struct sk_buff *skb)
395{
396 struct hci_rp_read_ssp_mode *rp = (void *) skb->data;
397
398 BT_DBG("%s status 0x%x", hdev->name, rp->status);
399
400 if (rp->status)
401 return;
402
403 hdev->ssp_mode = rp->mode;
404}
405
406static void hci_cc_write_ssp_mode(struct hci_dev *hdev, struct sk_buff *skb)
407{
408 __u8 status = *((__u8 *) skb->data);
409 void *sent;
410
411 BT_DBG("%s status 0x%x", hdev->name, status);
412
413 if (status)
414 return;
415
416 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SSP_MODE);
417 if (!sent)
418 return;
419
420 hdev->ssp_mode = *((__u8 *) sent);
421}
422
340static void hci_cc_read_local_version(struct hci_dev *hdev, struct sk_buff *skb) 423static void hci_cc_read_local_version(struct hci_dev *hdev, struct sk_buff *skb)
341{ 424{
342 struct hci_rp_read_local_version *rp = (void *) skb->data; 425 struct hci_rp_read_local_version *rp = (void *) skb->data;
@@ -347,8 +430,8 @@ static void hci_cc_read_local_version(struct hci_dev *hdev, struct sk_buff *skb)
347 return; 430 return;
348 431
349 hdev->hci_ver = rp->hci_ver; 432 hdev->hci_ver = rp->hci_ver;
350 hdev->hci_rev = btohs(rp->hci_rev); 433 hdev->hci_rev = __le16_to_cpu(rp->hci_rev);
351 hdev->manufacturer = btohs(rp->manufacturer); 434 hdev->manufacturer = __le16_to_cpu(rp->manufacturer);
352 435
353 BT_DBG("%s manufacturer %d hci ver %d:%d", hdev->name, 436 BT_DBG("%s manufacturer %d hci ver %d:%d", hdev->name,
354 hdev->manufacturer, 437 hdev->manufacturer,
@@ -536,11 +619,119 @@ static void hci_cs_add_sco(struct hci_dev *hdev, __u8 status)
536 hci_dev_unlock(hdev); 619 hci_dev_unlock(hdev);
537} 620}
538 621
622static void hci_cs_auth_requested(struct hci_dev *hdev, __u8 status)
623{
624 struct hci_cp_auth_requested *cp;
625 struct hci_conn *conn;
626
627 BT_DBG("%s status 0x%x", hdev->name, status);
628
629 if (!status)
630 return;
631
632 cp = hci_sent_cmd_data(hdev, HCI_OP_AUTH_REQUESTED);
633 if (!cp)
634 return;
635
636 hci_dev_lock(hdev);
637
638 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
639 if (conn) {
640 if (conn->state == BT_CONFIG) {
641 hci_proto_connect_cfm(conn, status);
642 hci_conn_put(conn);
643 }
644 }
645
646 hci_dev_unlock(hdev);
647}
648
649static void hci_cs_set_conn_encrypt(struct hci_dev *hdev, __u8 status)
650{
651 struct hci_cp_set_conn_encrypt *cp;
652 struct hci_conn *conn;
653
654 BT_DBG("%s status 0x%x", hdev->name, status);
655
656 if (!status)
657 return;
658
659 cp = hci_sent_cmd_data(hdev, HCI_OP_SET_CONN_ENCRYPT);
660 if (!cp)
661 return;
662
663 hci_dev_lock(hdev);
664
665 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
666 if (conn) {
667 if (conn->state == BT_CONFIG) {
668 hci_proto_connect_cfm(conn, status);
669 hci_conn_put(conn);
670 }
671 }
672
673 hci_dev_unlock(hdev);
674}
675
539static void hci_cs_remote_name_req(struct hci_dev *hdev, __u8 status) 676static void hci_cs_remote_name_req(struct hci_dev *hdev, __u8 status)
540{ 677{
541 BT_DBG("%s status 0x%x", hdev->name, status); 678 BT_DBG("%s status 0x%x", hdev->name, status);
542} 679}
543 680
681static void hci_cs_read_remote_features(struct hci_dev *hdev, __u8 status)
682{
683 struct hci_cp_read_remote_features *cp;
684 struct hci_conn *conn;
685
686 BT_DBG("%s status 0x%x", hdev->name, status);
687
688 if (!status)
689 return;
690
691 cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_FEATURES);
692 if (!cp)
693 return;
694
695 hci_dev_lock(hdev);
696
697 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
698 if (conn) {
699 if (conn->state == BT_CONFIG) {
700 hci_proto_connect_cfm(conn, status);
701 hci_conn_put(conn);
702 }
703 }
704
705 hci_dev_unlock(hdev);
706}
707
708static void hci_cs_read_remote_ext_features(struct hci_dev *hdev, __u8 status)
709{
710 struct hci_cp_read_remote_ext_features *cp;
711 struct hci_conn *conn;
712
713 BT_DBG("%s status 0x%x", hdev->name, status);
714
715 if (!status)
716 return;
717
718 cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES);
719 if (!cp)
720 return;
721
722 hci_dev_lock(hdev);
723
724 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
725 if (conn) {
726 if (conn->state == BT_CONFIG) {
727 hci_proto_connect_cfm(conn, status);
728 hci_conn_put(conn);
729 }
730 }
731
732 hci_dev_unlock(hdev);
733}
734
544static void hci_cs_setup_sync_conn(struct hci_dev *hdev, __u8 status) 735static void hci_cs_setup_sync_conn(struct hci_dev *hdev, __u8 status)
545{ 736{
546 struct hci_cp_setup_sync_conn *cp; 737 struct hci_cp_setup_sync_conn *cp;
@@ -653,6 +844,7 @@ static inline void hci_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *
653 memcpy(data.dev_class, info->dev_class, 3); 844 memcpy(data.dev_class, info->dev_class, 3);
654 data.clock_offset = info->clock_offset; 845 data.clock_offset = info->clock_offset;
655 data.rssi = 0x00; 846 data.rssi = 0x00;
847 data.ssp_mode = 0x00;
656 info++; 848 info++;
657 hci_inquiry_cache_update(hdev, &data); 849 hci_inquiry_cache_update(hdev, &data);
658 } 850 }
@@ -675,7 +867,14 @@ static inline void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *s
675 867
676 if (!ev->status) { 868 if (!ev->status) {
677 conn->handle = __le16_to_cpu(ev->handle); 869 conn->handle = __le16_to_cpu(ev->handle);
678 conn->state = BT_CONNECTED; 870
871 if (conn->type == ACL_LINK) {
872 conn->state = BT_CONFIG;
873 hci_conn_hold(conn);
874 } else
875 conn->state = BT_CONNECTED;
876
877 hci_conn_add_sysfs(conn);
679 878
680 if (test_bit(HCI_AUTH, &hdev->flags)) 879 if (test_bit(HCI_AUTH, &hdev->flags))
681 conn->link_mode |= HCI_LM_AUTH; 880 conn->link_mode |= HCI_LM_AUTH;
@@ -687,30 +886,17 @@ static inline void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *s
687 if (conn->type == ACL_LINK) { 886 if (conn->type == ACL_LINK) {
688 struct hci_cp_read_remote_features cp; 887 struct hci_cp_read_remote_features cp;
689 cp.handle = ev->handle; 888 cp.handle = ev->handle;
690 hci_send_cmd(hdev, HCI_OP_READ_REMOTE_FEATURES, sizeof(cp), &cp); 889 hci_send_cmd(hdev, HCI_OP_READ_REMOTE_FEATURES,
691 } 890 sizeof(cp), &cp);
692
693 /* Set link policy */
694 if (conn->type == ACL_LINK && hdev->link_policy) {
695 struct hci_cp_write_link_policy cp;
696 cp.handle = ev->handle;
697 cp.policy = cpu_to_le16(hdev->link_policy);
698 hci_send_cmd(hdev, HCI_OP_WRITE_LINK_POLICY, sizeof(cp), &cp);
699 } 891 }
700 892
701 /* Set packet type for incoming connection */ 893 /* Set packet type for incoming connection */
702 if (!conn->out) { 894 if (!conn->out && hdev->hci_ver < 3) {
703 struct hci_cp_change_conn_ptype cp; 895 struct hci_cp_change_conn_ptype cp;
704 cp.handle = ev->handle; 896 cp.handle = ev->handle;
705 cp.pkt_type = (conn->type == ACL_LINK) ? 897 cp.pkt_type = cpu_to_le16(conn->pkt_type);
706 cpu_to_le16(hdev->pkt_type & ACL_PTYPE_MASK): 898 hci_send_cmd(hdev, HCI_OP_CHANGE_CONN_PTYPE,
707 cpu_to_le16(hdev->pkt_type & SCO_PTYPE_MASK); 899 sizeof(cp), &cp);
708
709 hci_send_cmd(hdev, HCI_OP_CHANGE_CONN_PTYPE, sizeof(cp), &cp);
710 } else {
711 /* Update disconnect timer */
712 hci_conn_hold(conn);
713 hci_conn_put(conn);
714 } 900 }
715 } else 901 } else
716 conn->state = BT_CLOSED; 902 conn->state = BT_CLOSED;
@@ -730,9 +916,10 @@ static inline void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *s
730 } 916 }
731 } 917 }
732 918
733 hci_proto_connect_cfm(conn, ev->status); 919 if (ev->status) {
734 if (ev->status) 920 hci_proto_connect_cfm(conn, ev->status);
735 hci_conn_del(conn); 921 hci_conn_del(conn);
922 }
736 923
737unlock: 924unlock:
738 hci_dev_unlock(hdev); 925 hci_dev_unlock(hdev);
@@ -752,10 +939,14 @@ static inline void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *sk
752 939
753 if (mask & HCI_LM_ACCEPT) { 940 if (mask & HCI_LM_ACCEPT) {
754 /* Connection accepted */ 941 /* Connection accepted */
942 struct inquiry_entry *ie;
755 struct hci_conn *conn; 943 struct hci_conn *conn;
756 944
757 hci_dev_lock(hdev); 945 hci_dev_lock(hdev);
758 946
947 if ((ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr)))
948 memcpy(ie->data.dev_class, ev->dev_class, 3);
949
759 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr); 950 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr);
760 if (!conn) { 951 if (!conn) {
761 if (!(conn = hci_conn_add(hdev, ev->link_type, &ev->bdaddr))) { 952 if (!(conn = hci_conn_add(hdev, ev->link_type, &ev->bdaddr))) {
@@ -786,7 +977,7 @@ static inline void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *sk
786 struct hci_cp_accept_sync_conn_req cp; 977 struct hci_cp_accept_sync_conn_req cp;
787 978
788 bacpy(&cp.bdaddr, &ev->bdaddr); 979 bacpy(&cp.bdaddr, &ev->bdaddr);
789 cp.pkt_type = cpu_to_le16(hdev->esco_type); 980 cp.pkt_type = cpu_to_le16(conn->pkt_type);
790 981
791 cp.tx_bandwidth = cpu_to_le32(0x00001f40); 982 cp.tx_bandwidth = cpu_to_le32(0x00001f40);
792 cp.rx_bandwidth = cpu_to_le32(0x00001f40); 983 cp.rx_bandwidth = cpu_to_le32(0x00001f40);
@@ -822,6 +1013,9 @@ static inline void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff
822 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); 1013 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
823 if (conn) { 1014 if (conn) {
824 conn->state = BT_CLOSED; 1015 conn->state = BT_CLOSED;
1016
1017 hci_conn_del_sysfs(conn);
1018
825 hci_proto_disconn_ind(conn, ev->reason); 1019 hci_proto_disconn_ind(conn, ev->reason);
826 hci_conn_del(conn); 1020 hci_conn_del(conn);
827 } 1021 }
@@ -845,15 +1039,29 @@ static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *s
845 1039
846 clear_bit(HCI_CONN_AUTH_PEND, &conn->pend); 1040 clear_bit(HCI_CONN_AUTH_PEND, &conn->pend);
847 1041
848 hci_auth_cfm(conn, ev->status); 1042 if (conn->state == BT_CONFIG) {
1043 if (!ev->status && hdev->ssp_mode > 0 &&
1044 conn->ssp_mode > 0) {
1045 struct hci_cp_set_conn_encrypt cp;
1046 cp.handle = ev->handle;
1047 cp.encrypt = 0x01;
1048 hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT,
1049 sizeof(cp), &cp);
1050 } else {
1051 conn->state = BT_CONNECTED;
1052 hci_proto_connect_cfm(conn, ev->status);
1053 hci_conn_put(conn);
1054 }
1055 } else
1056 hci_auth_cfm(conn, ev->status);
849 1057
850 if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend)) { 1058 if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend)) {
851 if (!ev->status) { 1059 if (!ev->status) {
852 struct hci_cp_set_conn_encrypt cp; 1060 struct hci_cp_set_conn_encrypt cp;
853 cp.handle = cpu_to_le16(conn->handle); 1061 cp.handle = ev->handle;
854 cp.encrypt = 1; 1062 cp.encrypt = 0x01;
855 hci_send_cmd(conn->hdev, 1063 hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT,
856 HCI_OP_SET_CONN_ENCRYPT, sizeof(cp), &cp); 1064 sizeof(cp), &cp);
857 } else { 1065 } else {
858 clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend); 1066 clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend);
859 hci_encrypt_cfm(conn, ev->status, 0x00); 1067 hci_encrypt_cfm(conn, ev->status, 0x00);
@@ -883,15 +1091,24 @@ static inline void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *
883 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); 1091 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
884 if (conn) { 1092 if (conn) {
885 if (!ev->status) { 1093 if (!ev->status) {
886 if (ev->encrypt) 1094 if (ev->encrypt) {
1095 /* Encryption implies authentication */
1096 conn->link_mode |= HCI_LM_AUTH;
887 conn->link_mode |= HCI_LM_ENCRYPT; 1097 conn->link_mode |= HCI_LM_ENCRYPT;
888 else 1098 } else
889 conn->link_mode &= ~HCI_LM_ENCRYPT; 1099 conn->link_mode &= ~HCI_LM_ENCRYPT;
890 } 1100 }
891 1101
892 clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend); 1102 clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend);
893 1103
894 hci_encrypt_cfm(conn, ev->status, ev->encrypt); 1104 if (conn->state == BT_CONFIG) {
1105 if (!ev->status)
1106 conn->state = BT_CONNECTED;
1107
1108 hci_proto_connect_cfm(conn, ev->status);
1109 hci_conn_put(conn);
1110 } else
1111 hci_encrypt_cfm(conn, ev->status, ev->encrypt);
895 } 1112 }
896 1113
897 hci_dev_unlock(hdev); 1114 hci_dev_unlock(hdev);
@@ -926,14 +1143,29 @@ static inline void hci_remote_features_evt(struct hci_dev *hdev, struct sk_buff
926 1143
927 BT_DBG("%s status %d", hdev->name, ev->status); 1144 BT_DBG("%s status %d", hdev->name, ev->status);
928 1145
929 if (ev->status)
930 return;
931
932 hci_dev_lock(hdev); 1146 hci_dev_lock(hdev);
933 1147
934 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); 1148 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
935 if (conn) 1149 if (conn) {
936 memcpy(conn->features, ev->features, 8); 1150 if (!ev->status)
1151 memcpy(conn->features, ev->features, 8);
1152
1153 if (conn->state == BT_CONFIG) {
1154 if (!ev->status && lmp_ssp_capable(hdev) &&
1155 lmp_ssp_capable(conn)) {
1156 struct hci_cp_read_remote_ext_features cp;
1157 cp.handle = ev->handle;
1158 cp.page = 0x01;
1159 hci_send_cmd(hdev,
1160 HCI_OP_READ_REMOTE_EXT_FEATURES,
1161 sizeof(cp), &cp);
1162 } else {
1163 conn->state = BT_CONNECTED;
1164 hci_proto_connect_cfm(conn, ev->status);
1165 hci_conn_put(conn);
1166 }
1167 }
1168 }
937 1169
938 hci_dev_unlock(hdev); 1170 hci_dev_unlock(hdev);
939} 1171}
@@ -974,10 +1206,22 @@ static inline void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *sk
974 hci_cc_role_discovery(hdev, skb); 1206 hci_cc_role_discovery(hdev, skb);
975 break; 1207 break;
976 1208
1209 case HCI_OP_READ_LINK_POLICY:
1210 hci_cc_read_link_policy(hdev, skb);
1211 break;
1212
977 case HCI_OP_WRITE_LINK_POLICY: 1213 case HCI_OP_WRITE_LINK_POLICY:
978 hci_cc_write_link_policy(hdev, skb); 1214 hci_cc_write_link_policy(hdev, skb);
979 break; 1215 break;
980 1216
1217 case HCI_OP_READ_DEF_LINK_POLICY:
1218 hci_cc_read_def_link_policy(hdev, skb);
1219 break;
1220
1221 case HCI_OP_WRITE_DEF_LINK_POLICY:
1222 hci_cc_write_def_link_policy(hdev, skb);
1223 break;
1224
981 case HCI_OP_RESET: 1225 case HCI_OP_RESET:
982 hci_cc_reset(hdev, skb); 1226 hci_cc_reset(hdev, skb);
983 break; 1227 break;
@@ -1022,6 +1266,14 @@ static inline void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *sk
1022 hci_cc_host_buffer_size(hdev, skb); 1266 hci_cc_host_buffer_size(hdev, skb);
1023 break; 1267 break;
1024 1268
1269 case HCI_OP_READ_SSP_MODE:
1270 hci_cc_read_ssp_mode(hdev, skb);
1271 break;
1272
1273 case HCI_OP_WRITE_SSP_MODE:
1274 hci_cc_write_ssp_mode(hdev, skb);
1275 break;
1276
1025 case HCI_OP_READ_LOCAL_VERSION: 1277 case HCI_OP_READ_LOCAL_VERSION:
1026 hci_cc_read_local_version(hdev, skb); 1278 hci_cc_read_local_version(hdev, skb);
1027 break; 1279 break;
@@ -1076,10 +1328,26 @@ static inline void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb)
1076 hci_cs_add_sco(hdev, ev->status); 1328 hci_cs_add_sco(hdev, ev->status);
1077 break; 1329 break;
1078 1330
1331 case HCI_OP_AUTH_REQUESTED:
1332 hci_cs_auth_requested(hdev, ev->status);
1333 break;
1334
1335 case HCI_OP_SET_CONN_ENCRYPT:
1336 hci_cs_set_conn_encrypt(hdev, ev->status);
1337 break;
1338
1079 case HCI_OP_REMOTE_NAME_REQ: 1339 case HCI_OP_REMOTE_NAME_REQ:
1080 hci_cs_remote_name_req(hdev, ev->status); 1340 hci_cs_remote_name_req(hdev, ev->status);
1081 break; 1341 break;
1082 1342
1343 case HCI_OP_READ_REMOTE_FEATURES:
1344 hci_cs_read_remote_features(hdev, ev->status);
1345 break;
1346
1347 case HCI_OP_READ_REMOTE_EXT_FEATURES:
1348 hci_cs_read_remote_ext_features(hdev, ev->status);
1349 break;
1350
1083 case HCI_OP_SETUP_SYNC_CONN: 1351 case HCI_OP_SETUP_SYNC_CONN:
1084 hci_cs_setup_sync_conn(hdev, ev->status); 1352 hci_cs_setup_sync_conn(hdev, ev->status);
1085 break; 1353 break;
@@ -1235,6 +1503,22 @@ static inline void hci_clock_offset_evt(struct hci_dev *hdev, struct sk_buff *sk
1235 hci_dev_unlock(hdev); 1503 hci_dev_unlock(hdev);
1236} 1504}
1237 1505
1506static inline void hci_pkt_type_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
1507{
1508 struct hci_ev_pkt_type_change *ev = (void *) skb->data;
1509 struct hci_conn *conn;
1510
1511 BT_DBG("%s status %d", hdev->name, ev->status);
1512
1513 hci_dev_lock(hdev);
1514
1515 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
1516 if (conn && !ev->status)
1517 conn->pkt_type = __le16_to_cpu(ev->pkt_type);
1518
1519 hci_dev_unlock(hdev);
1520}
1521
1238static inline void hci_pscan_rep_mode_evt(struct hci_dev *hdev, struct sk_buff *skb) 1522static inline void hci_pscan_rep_mode_evt(struct hci_dev *hdev, struct sk_buff *skb)
1239{ 1523{
1240 struct hci_ev_pscan_rep_mode *ev = (void *) skb->data; 1524 struct hci_ev_pscan_rep_mode *ev = (void *) skb->data;
@@ -1275,6 +1559,7 @@ static inline void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, struct
1275 memcpy(data.dev_class, info->dev_class, 3); 1559 memcpy(data.dev_class, info->dev_class, 3);
1276 data.clock_offset = info->clock_offset; 1560 data.clock_offset = info->clock_offset;
1277 data.rssi = info->rssi; 1561 data.rssi = info->rssi;
1562 data.ssp_mode = 0x00;
1278 info++; 1563 info++;
1279 hci_inquiry_cache_update(hdev, &data); 1564 hci_inquiry_cache_update(hdev, &data);
1280 } 1565 }
@@ -1289,6 +1574,7 @@ static inline void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, struct
1289 memcpy(data.dev_class, info->dev_class, 3); 1574 memcpy(data.dev_class, info->dev_class, 3);
1290 data.clock_offset = info->clock_offset; 1575 data.clock_offset = info->clock_offset;
1291 data.rssi = info->rssi; 1576 data.rssi = info->rssi;
1577 data.ssp_mode = 0x00;
1292 info++; 1578 info++;
1293 hci_inquiry_cache_update(hdev, &data); 1579 hci_inquiry_cache_update(hdev, &data);
1294 } 1580 }
@@ -1299,7 +1585,43 @@ static inline void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, struct
1299 1585
1300static inline void hci_remote_ext_features_evt(struct hci_dev *hdev, struct sk_buff *skb) 1586static inline void hci_remote_ext_features_evt(struct hci_dev *hdev, struct sk_buff *skb)
1301{ 1587{
1588 struct hci_ev_remote_ext_features *ev = (void *) skb->data;
1589 struct hci_conn *conn;
1590
1302 BT_DBG("%s", hdev->name); 1591 BT_DBG("%s", hdev->name);
1592
1593 hci_dev_lock(hdev);
1594
1595 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
1596 if (conn) {
1597 if (!ev->status && ev->page == 0x01) {
1598 struct inquiry_entry *ie;
1599
1600 if ((ie = hci_inquiry_cache_lookup(hdev, &conn->dst)))
1601 ie->data.ssp_mode = (ev->features[0] & 0x01);
1602
1603 conn->ssp_mode = (ev->features[0] & 0x01);
1604 }
1605
1606 if (conn->state == BT_CONFIG) {
1607 if (!ev->status && hdev->ssp_mode > 0 &&
1608 conn->ssp_mode > 0) {
1609 if (conn->out) {
1610 struct hci_cp_auth_requested cp;
1611 cp.handle = ev->handle;
1612 hci_send_cmd(hdev,
1613 HCI_OP_AUTH_REQUESTED,
1614 sizeof(cp), &cp);
1615 }
1616 } else {
1617 conn->state = BT_CONNECTED;
1618 hci_proto_connect_cfm(conn, ev->status);
1619 hci_conn_put(conn);
1620 }
1621 }
1622 }
1623
1624 hci_dev_unlock(hdev);
1303} 1625}
1304 1626
1305static inline void hci_sync_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) 1627static inline void hci_sync_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
@@ -1312,12 +1634,22 @@ static inline void hci_sync_conn_complete_evt(struct hci_dev *hdev, struct sk_bu
1312 hci_dev_lock(hdev); 1634 hci_dev_lock(hdev);
1313 1635
1314 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr); 1636 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr);
1315 if (!conn) 1637 if (!conn) {
1316 goto unlock; 1638 if (ev->link_type == ESCO_LINK)
1639 goto unlock;
1640
1641 conn = hci_conn_hash_lookup_ba(hdev, ESCO_LINK, &ev->bdaddr);
1642 if (!conn)
1643 goto unlock;
1644
1645 conn->type = SCO_LINK;
1646 }
1317 1647
1318 if (!ev->status) { 1648 if (!ev->status) {
1319 conn->handle = __le16_to_cpu(ev->handle); 1649 conn->handle = __le16_to_cpu(ev->handle);
1320 conn->state = BT_CONNECTED; 1650 conn->state = BT_CONNECTED;
1651
1652 hci_conn_add_sysfs(conn);
1321 } else 1653 } else
1322 conn->state = BT_CLOSED; 1654 conn->state = BT_CLOSED;
1323 1655
@@ -1371,6 +1703,7 @@ static inline void hci_extended_inquiry_result_evt(struct hci_dev *hdev, struct
1371 memcpy(data.dev_class, info->dev_class, 3); 1703 memcpy(data.dev_class, info->dev_class, 3);
1372 data.clock_offset = info->clock_offset; 1704 data.clock_offset = info->clock_offset;
1373 data.rssi = info->rssi; 1705 data.rssi = info->rssi;
1706 data.ssp_mode = 0x01;
1374 info++; 1707 info++;
1375 hci_inquiry_cache_update(hdev, &data); 1708 hci_inquiry_cache_update(hdev, &data);
1376 } 1709 }
@@ -1378,6 +1711,53 @@ static inline void hci_extended_inquiry_result_evt(struct hci_dev *hdev, struct
1378 hci_dev_unlock(hdev); 1711 hci_dev_unlock(hdev);
1379} 1712}
1380 1713
1714static inline void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
1715{
1716 struct hci_ev_io_capa_request *ev = (void *) skb->data;
1717 struct hci_conn *conn;
1718
1719 BT_DBG("%s", hdev->name);
1720
1721 hci_dev_lock(hdev);
1722
1723 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
1724 if (conn)
1725 hci_conn_hold(conn);
1726
1727 hci_dev_unlock(hdev);
1728}
1729
1730static inline void hci_simple_pair_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1731{
1732 struct hci_ev_simple_pair_complete *ev = (void *) skb->data;
1733 struct hci_conn *conn;
1734
1735 BT_DBG("%s", hdev->name);
1736
1737 hci_dev_lock(hdev);
1738
1739 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
1740 if (conn)
1741 hci_conn_put(conn);
1742
1743 hci_dev_unlock(hdev);
1744}
1745
1746static inline void hci_remote_host_features_evt(struct hci_dev *hdev, struct sk_buff *skb)
1747{
1748 struct hci_ev_remote_host_features *ev = (void *) skb->data;
1749 struct inquiry_entry *ie;
1750
1751 BT_DBG("%s", hdev->name);
1752
1753 hci_dev_lock(hdev);
1754
1755 if ((ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr)))
1756 ie->data.ssp_mode = (ev->features[0] & 0x01);
1757
1758 hci_dev_unlock(hdev);
1759}
1760
1381void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb) 1761void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
1382{ 1762{
1383 struct hci_event_hdr *hdr = (void *) skb->data; 1763 struct hci_event_hdr *hdr = (void *) skb->data;
@@ -1470,6 +1850,10 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
1470 hci_clock_offset_evt(hdev, skb); 1850 hci_clock_offset_evt(hdev, skb);
1471 break; 1851 break;
1472 1852
1853 case HCI_EV_PKT_TYPE_CHANGE:
1854 hci_pkt_type_change_evt(hdev, skb);
1855 break;
1856
1473 case HCI_EV_PSCAN_REP_MODE: 1857 case HCI_EV_PSCAN_REP_MODE:
1474 hci_pscan_rep_mode_evt(hdev, skb); 1858 hci_pscan_rep_mode_evt(hdev, skb);
1475 break; 1859 break;
@@ -1498,6 +1882,18 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
1498 hci_extended_inquiry_result_evt(hdev, skb); 1882 hci_extended_inquiry_result_evt(hdev, skb);
1499 break; 1883 break;
1500 1884
1885 case HCI_EV_IO_CAPA_REQUEST:
1886 hci_io_capa_request_evt(hdev, skb);
1887 break;
1888
1889 case HCI_EV_SIMPLE_PAIR_COMPLETE:
1890 hci_simple_pair_complete_evt(hdev, skb);
1891 break;
1892
1893 case HCI_EV_REMOTE_HOST_FEATURES:
1894 hci_remote_host_features_evt(hdev, skb);
1895 break;
1896
1501 default: 1897 default:
1502 BT_DBG("%s event 0x%x", hdev->name, event); 1898 BT_DBG("%s event 0x%x", hdev->name, event);
1503 break; 1899 break;