diff options
Diffstat (limited to 'net/bluetooth/hci_event.c')
-rw-r--r-- | net/bluetooth/hci_event.c | 691 |
1 files changed, 648 insertions, 43 deletions
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index a290854fdaa6..3fbfa50c2bff 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c | |||
@@ -274,15 +274,24 @@ static void hci_cc_write_scan_enable(struct hci_dev *hdev, struct sk_buff *skb) | |||
274 | 274 | ||
275 | if (!status) { | 275 | if (!status) { |
276 | __u8 param = *((__u8 *) sent); | 276 | __u8 param = *((__u8 *) sent); |
277 | int old_pscan, old_iscan; | ||
277 | 278 | ||
278 | clear_bit(HCI_PSCAN, &hdev->flags); | 279 | old_pscan = test_and_clear_bit(HCI_PSCAN, &hdev->flags); |
279 | clear_bit(HCI_ISCAN, &hdev->flags); | 280 | old_iscan = test_and_clear_bit(HCI_ISCAN, &hdev->flags); |
280 | 281 | ||
281 | if (param & SCAN_INQUIRY) | 282 | if (param & SCAN_INQUIRY) { |
282 | set_bit(HCI_ISCAN, &hdev->flags); | 283 | set_bit(HCI_ISCAN, &hdev->flags); |
284 | if (!old_iscan) | ||
285 | mgmt_discoverable(hdev->id, 1); | ||
286 | } else if (old_iscan) | ||
287 | mgmt_discoverable(hdev->id, 0); | ||
283 | 288 | ||
284 | if (param & SCAN_PAGE) | 289 | if (param & SCAN_PAGE) { |
285 | set_bit(HCI_PSCAN, &hdev->flags); | 290 | set_bit(HCI_PSCAN, &hdev->flags); |
291 | if (!old_pscan) | ||
292 | mgmt_connectable(hdev->id, 1); | ||
293 | } else if (old_pscan) | ||
294 | mgmt_connectable(hdev->id, 0); | ||
286 | } | 295 | } |
287 | 296 | ||
288 | hci_req_complete(hdev, HCI_OP_WRITE_SCAN_ENABLE, status); | 297 | hci_req_complete(hdev, HCI_OP_WRITE_SCAN_ENABLE, status); |
@@ -415,6 +424,115 @@ static void hci_cc_write_ssp_mode(struct hci_dev *hdev, struct sk_buff *skb) | |||
415 | hdev->ssp_mode = *((__u8 *) sent); | 424 | hdev->ssp_mode = *((__u8 *) sent); |
416 | } | 425 | } |
417 | 426 | ||
427 | static u8 hci_get_inquiry_mode(struct hci_dev *hdev) | ||
428 | { | ||
429 | if (hdev->features[6] & LMP_EXT_INQ) | ||
430 | return 2; | ||
431 | |||
432 | if (hdev->features[3] & LMP_RSSI_INQ) | ||
433 | return 1; | ||
434 | |||
435 | if (hdev->manufacturer == 11 && hdev->hci_rev == 0x00 && | ||
436 | hdev->lmp_subver == 0x0757) | ||
437 | return 1; | ||
438 | |||
439 | if (hdev->manufacturer == 15) { | ||
440 | if (hdev->hci_rev == 0x03 && hdev->lmp_subver == 0x6963) | ||
441 | return 1; | ||
442 | if (hdev->hci_rev == 0x09 && hdev->lmp_subver == 0x6963) | ||
443 | return 1; | ||
444 | if (hdev->hci_rev == 0x00 && hdev->lmp_subver == 0x6965) | ||
445 | return 1; | ||
446 | } | ||
447 | |||
448 | if (hdev->manufacturer == 31 && hdev->hci_rev == 0x2005 && | ||
449 | hdev->lmp_subver == 0x1805) | ||
450 | return 1; | ||
451 | |||
452 | return 0; | ||
453 | } | ||
454 | |||
455 | static void hci_setup_inquiry_mode(struct hci_dev *hdev) | ||
456 | { | ||
457 | u8 mode; | ||
458 | |||
459 | mode = hci_get_inquiry_mode(hdev); | ||
460 | |||
461 | hci_send_cmd(hdev, HCI_OP_WRITE_INQUIRY_MODE, 1, &mode); | ||
462 | } | ||
463 | |||
464 | static void hci_setup_event_mask(struct hci_dev *hdev) | ||
465 | { | ||
466 | /* The second byte is 0xff instead of 0x9f (two reserved bits | ||
467 | * disabled) since a Broadcom 1.2 dongle doesn't respond to the | ||
468 | * command otherwise */ | ||
469 | u8 events[8] = { 0xff, 0xff, 0xfb, 0xff, 0x00, 0x00, 0x00, 0x00 }; | ||
470 | |||
471 | /* Events for 1.2 and newer controllers */ | ||
472 | if (hdev->lmp_ver > 1) { | ||
473 | events[4] |= 0x01; /* Flow Specification Complete */ | ||
474 | events[4] |= 0x02; /* Inquiry Result with RSSI */ | ||
475 | events[4] |= 0x04; /* Read Remote Extended Features Complete */ | ||
476 | events[5] |= 0x08; /* Synchronous Connection Complete */ | ||
477 | events[5] |= 0x10; /* Synchronous Connection Changed */ | ||
478 | } | ||
479 | |||
480 | if (hdev->features[3] & LMP_RSSI_INQ) | ||
481 | events[4] |= 0x04; /* Inquiry Result with RSSI */ | ||
482 | |||
483 | if (hdev->features[5] & LMP_SNIFF_SUBR) | ||
484 | events[5] |= 0x20; /* Sniff Subrating */ | ||
485 | |||
486 | if (hdev->features[5] & LMP_PAUSE_ENC) | ||
487 | events[5] |= 0x80; /* Encryption Key Refresh Complete */ | ||
488 | |||
489 | if (hdev->features[6] & LMP_EXT_INQ) | ||
490 | events[5] |= 0x40; /* Extended Inquiry Result */ | ||
491 | |||
492 | if (hdev->features[6] & LMP_NO_FLUSH) | ||
493 | events[7] |= 0x01; /* Enhanced Flush Complete */ | ||
494 | |||
495 | if (hdev->features[7] & LMP_LSTO) | ||
496 | events[6] |= 0x80; /* Link Supervision Timeout Changed */ | ||
497 | |||
498 | if (hdev->features[6] & LMP_SIMPLE_PAIR) { | ||
499 | events[6] |= 0x01; /* IO Capability Request */ | ||
500 | events[6] |= 0x02; /* IO Capability Response */ | ||
501 | events[6] |= 0x04; /* User Confirmation Request */ | ||
502 | events[6] |= 0x08; /* User Passkey Request */ | ||
503 | events[6] |= 0x10; /* Remote OOB Data Request */ | ||
504 | events[6] |= 0x20; /* Simple Pairing Complete */ | ||
505 | events[7] |= 0x04; /* User Passkey Notification */ | ||
506 | events[7] |= 0x08; /* Keypress Notification */ | ||
507 | events[7] |= 0x10; /* Remote Host Supported | ||
508 | * Features Notification */ | ||
509 | } | ||
510 | |||
511 | if (hdev->features[4] & LMP_LE) | ||
512 | events[7] |= 0x20; /* LE Meta-Event */ | ||
513 | |||
514 | hci_send_cmd(hdev, HCI_OP_SET_EVENT_MASK, sizeof(events), events); | ||
515 | } | ||
516 | |||
517 | static void hci_setup(struct hci_dev *hdev) | ||
518 | { | ||
519 | hci_setup_event_mask(hdev); | ||
520 | |||
521 | if (hdev->lmp_ver > 1) | ||
522 | hci_send_cmd(hdev, HCI_OP_READ_LOCAL_COMMANDS, 0, NULL); | ||
523 | |||
524 | if (hdev->features[6] & LMP_SIMPLE_PAIR) { | ||
525 | u8 mode = 0x01; | ||
526 | hci_send_cmd(hdev, HCI_OP_WRITE_SSP_MODE, sizeof(mode), &mode); | ||
527 | } | ||
528 | |||
529 | if (hdev->features[3] & LMP_RSSI_INQ) | ||
530 | hci_setup_inquiry_mode(hdev); | ||
531 | |||
532 | if (hdev->features[7] & LMP_INQ_TX_PWR) | ||
533 | hci_send_cmd(hdev, HCI_OP_READ_INQ_RSP_TX_POWER, 0, NULL); | ||
534 | } | ||
535 | |||
418 | static void hci_cc_read_local_version(struct hci_dev *hdev, struct sk_buff *skb) | 536 | static void hci_cc_read_local_version(struct hci_dev *hdev, struct sk_buff *skb) |
419 | { | 537 | { |
420 | struct hci_rp_read_local_version *rp = (void *) skb->data; | 538 | struct hci_rp_read_local_version *rp = (void *) skb->data; |
@@ -426,11 +544,34 @@ static void hci_cc_read_local_version(struct hci_dev *hdev, struct sk_buff *skb) | |||
426 | 544 | ||
427 | hdev->hci_ver = rp->hci_ver; | 545 | hdev->hci_ver = rp->hci_ver; |
428 | hdev->hci_rev = __le16_to_cpu(rp->hci_rev); | 546 | hdev->hci_rev = __le16_to_cpu(rp->hci_rev); |
547 | hdev->lmp_ver = rp->lmp_ver; | ||
429 | hdev->manufacturer = __le16_to_cpu(rp->manufacturer); | 548 | hdev->manufacturer = __le16_to_cpu(rp->manufacturer); |
549 | hdev->lmp_subver = __le16_to_cpu(rp->lmp_subver); | ||
430 | 550 | ||
431 | BT_DBG("%s manufacturer %d hci ver %d:%d", hdev->name, | 551 | BT_DBG("%s manufacturer %d hci ver %d:%d", hdev->name, |
432 | hdev->manufacturer, | 552 | hdev->manufacturer, |
433 | hdev->hci_ver, hdev->hci_rev); | 553 | hdev->hci_ver, hdev->hci_rev); |
554 | |||
555 | if (test_bit(HCI_INIT, &hdev->flags)) | ||
556 | hci_setup(hdev); | ||
557 | } | ||
558 | |||
559 | static void hci_setup_link_policy(struct hci_dev *hdev) | ||
560 | { | ||
561 | u16 link_policy = 0; | ||
562 | |||
563 | if (hdev->features[0] & LMP_RSWITCH) | ||
564 | link_policy |= HCI_LP_RSWITCH; | ||
565 | if (hdev->features[0] & LMP_HOLD) | ||
566 | link_policy |= HCI_LP_HOLD; | ||
567 | if (hdev->features[0] & LMP_SNIFF) | ||
568 | link_policy |= HCI_LP_SNIFF; | ||
569 | if (hdev->features[1] & LMP_PARK) | ||
570 | link_policy |= HCI_LP_PARK; | ||
571 | |||
572 | link_policy = cpu_to_le16(link_policy); | ||
573 | hci_send_cmd(hdev, HCI_OP_WRITE_DEF_LINK_POLICY, | ||
574 | sizeof(link_policy), &link_policy); | ||
434 | } | 575 | } |
435 | 576 | ||
436 | static void hci_cc_read_local_commands(struct hci_dev *hdev, struct sk_buff *skb) | 577 | static void hci_cc_read_local_commands(struct hci_dev *hdev, struct sk_buff *skb) |
@@ -440,9 +581,15 @@ static void hci_cc_read_local_commands(struct hci_dev *hdev, struct sk_buff *skb | |||
440 | BT_DBG("%s status 0x%x", hdev->name, rp->status); | 581 | BT_DBG("%s status 0x%x", hdev->name, rp->status); |
441 | 582 | ||
442 | if (rp->status) | 583 | if (rp->status) |
443 | return; | 584 | goto done; |
444 | 585 | ||
445 | memcpy(hdev->commands, rp->commands, sizeof(hdev->commands)); | 586 | memcpy(hdev->commands, rp->commands, sizeof(hdev->commands)); |
587 | |||
588 | if (test_bit(HCI_INIT, &hdev->flags) && (hdev->commands[5] & 0x10)) | ||
589 | hci_setup_link_policy(hdev); | ||
590 | |||
591 | done: | ||
592 | hci_req_complete(hdev, HCI_OP_READ_LOCAL_COMMANDS, rp->status); | ||
446 | } | 593 | } |
447 | 594 | ||
448 | static void hci_cc_read_local_features(struct hci_dev *hdev, struct sk_buff *skb) | 595 | static void hci_cc_read_local_features(struct hci_dev *hdev, struct sk_buff *skb) |
@@ -548,6 +695,130 @@ static void hci_cc_write_ca_timeout(struct hci_dev *hdev, struct sk_buff *skb) | |||
548 | hci_req_complete(hdev, HCI_OP_WRITE_CA_TIMEOUT, status); | 695 | hci_req_complete(hdev, HCI_OP_WRITE_CA_TIMEOUT, status); |
549 | } | 696 | } |
550 | 697 | ||
698 | static void hci_cc_delete_stored_link_key(struct hci_dev *hdev, | ||
699 | struct sk_buff *skb) | ||
700 | { | ||
701 | __u8 status = *((__u8 *) skb->data); | ||
702 | |||
703 | BT_DBG("%s status 0x%x", hdev->name, status); | ||
704 | |||
705 | hci_req_complete(hdev, HCI_OP_DELETE_STORED_LINK_KEY, status); | ||
706 | } | ||
707 | |||
708 | static void hci_cc_set_event_mask(struct hci_dev *hdev, struct sk_buff *skb) | ||
709 | { | ||
710 | __u8 status = *((__u8 *) skb->data); | ||
711 | |||
712 | BT_DBG("%s status 0x%x", hdev->name, status); | ||
713 | |||
714 | hci_req_complete(hdev, HCI_OP_SET_EVENT_MASK, status); | ||
715 | } | ||
716 | |||
717 | static void hci_cc_write_inquiry_mode(struct hci_dev *hdev, | ||
718 | struct sk_buff *skb) | ||
719 | { | ||
720 | __u8 status = *((__u8 *) skb->data); | ||
721 | |||
722 | BT_DBG("%s status 0x%x", hdev->name, status); | ||
723 | |||
724 | hci_req_complete(hdev, HCI_OP_WRITE_INQUIRY_MODE, status); | ||
725 | } | ||
726 | |||
727 | static void hci_cc_read_inq_rsp_tx_power(struct hci_dev *hdev, | ||
728 | struct sk_buff *skb) | ||
729 | { | ||
730 | __u8 status = *((__u8 *) skb->data); | ||
731 | |||
732 | BT_DBG("%s status 0x%x", hdev->name, status); | ||
733 | |||
734 | hci_req_complete(hdev, HCI_OP_READ_INQ_RSP_TX_POWER, status); | ||
735 | } | ||
736 | |||
737 | static void hci_cc_set_event_flt(struct hci_dev *hdev, struct sk_buff *skb) | ||
738 | { | ||
739 | __u8 status = *((__u8 *) skb->data); | ||
740 | |||
741 | BT_DBG("%s status 0x%x", hdev->name, status); | ||
742 | |||
743 | hci_req_complete(hdev, HCI_OP_SET_EVENT_FLT, status); | ||
744 | } | ||
745 | |||
746 | static void hci_cc_pin_code_reply(struct hci_dev *hdev, struct sk_buff *skb) | ||
747 | { | ||
748 | struct hci_rp_pin_code_reply *rp = (void *) skb->data; | ||
749 | struct hci_cp_pin_code_reply *cp; | ||
750 | struct hci_conn *conn; | ||
751 | |||
752 | BT_DBG("%s status 0x%x", hdev->name, rp->status); | ||
753 | |||
754 | if (test_bit(HCI_MGMT, &hdev->flags)) | ||
755 | mgmt_pin_code_reply_complete(hdev->id, &rp->bdaddr, rp->status); | ||
756 | |||
757 | if (rp->status != 0) | ||
758 | return; | ||
759 | |||
760 | cp = hci_sent_cmd_data(hdev, HCI_OP_PIN_CODE_REPLY); | ||
761 | if (!cp) | ||
762 | return; | ||
763 | |||
764 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr); | ||
765 | if (conn) | ||
766 | conn->pin_length = cp->pin_len; | ||
767 | } | ||
768 | |||
769 | static void hci_cc_pin_code_neg_reply(struct hci_dev *hdev, struct sk_buff *skb) | ||
770 | { | ||
771 | struct hci_rp_pin_code_neg_reply *rp = (void *) skb->data; | ||
772 | |||
773 | BT_DBG("%s status 0x%x", hdev->name, rp->status); | ||
774 | |||
775 | if (test_bit(HCI_MGMT, &hdev->flags)) | ||
776 | mgmt_pin_code_neg_reply_complete(hdev->id, &rp->bdaddr, | ||
777 | rp->status); | ||
778 | } | ||
779 | static void hci_cc_le_read_buffer_size(struct hci_dev *hdev, | ||
780 | struct sk_buff *skb) | ||
781 | { | ||
782 | struct hci_rp_le_read_buffer_size *rp = (void *) skb->data; | ||
783 | |||
784 | BT_DBG("%s status 0x%x", hdev->name, rp->status); | ||
785 | |||
786 | if (rp->status) | ||
787 | return; | ||
788 | |||
789 | hdev->le_mtu = __le16_to_cpu(rp->le_mtu); | ||
790 | hdev->le_pkts = rp->le_max_pkt; | ||
791 | |||
792 | hdev->le_cnt = hdev->le_pkts; | ||
793 | |||
794 | BT_DBG("%s le mtu %d:%d", hdev->name, hdev->le_mtu, hdev->le_pkts); | ||
795 | |||
796 | hci_req_complete(hdev, HCI_OP_LE_READ_BUFFER_SIZE, rp->status); | ||
797 | } | ||
798 | |||
799 | static void hci_cc_user_confirm_reply(struct hci_dev *hdev, struct sk_buff *skb) | ||
800 | { | ||
801 | struct hci_rp_user_confirm_reply *rp = (void *) skb->data; | ||
802 | |||
803 | BT_DBG("%s status 0x%x", hdev->name, rp->status); | ||
804 | |||
805 | if (test_bit(HCI_MGMT, &hdev->flags)) | ||
806 | mgmt_user_confirm_reply_complete(hdev->id, &rp->bdaddr, | ||
807 | rp->status); | ||
808 | } | ||
809 | |||
810 | static void hci_cc_user_confirm_neg_reply(struct hci_dev *hdev, | ||
811 | struct sk_buff *skb) | ||
812 | { | ||
813 | struct hci_rp_user_confirm_reply *rp = (void *) skb->data; | ||
814 | |||
815 | BT_DBG("%s status 0x%x", hdev->name, rp->status); | ||
816 | |||
817 | if (test_bit(HCI_MGMT, &hdev->flags)) | ||
818 | mgmt_user_confirm_neg_reply_complete(hdev->id, &rp->bdaddr, | ||
819 | rp->status); | ||
820 | } | ||
821 | |||
551 | static inline void hci_cs_inquiry(struct hci_dev *hdev, __u8 status) | 822 | static inline void hci_cs_inquiry(struct hci_dev *hdev, __u8 status) |
552 | { | 823 | { |
553 | BT_DBG("%s status 0x%x", hdev->name, status); | 824 | BT_DBG("%s status 0x%x", hdev->name, status); |
@@ -622,11 +893,14 @@ static void hci_cs_add_sco(struct hci_dev *hdev, __u8 status) | |||
622 | hci_dev_lock(hdev); | 893 | hci_dev_lock(hdev); |
623 | 894 | ||
624 | acl = hci_conn_hash_lookup_handle(hdev, handle); | 895 | acl = hci_conn_hash_lookup_handle(hdev, handle); |
625 | if (acl && (sco = acl->link)) { | 896 | if (acl) { |
626 | sco->state = BT_CLOSED; | 897 | sco = acl->link; |
898 | if (sco) { | ||
899 | sco->state = BT_CLOSED; | ||
627 | 900 | ||
628 | hci_proto_connect_cfm(sco, status); | 901 | hci_proto_connect_cfm(sco, status); |
629 | hci_conn_del(sco); | 902 | hci_conn_del(sco); |
903 | } | ||
630 | } | 904 | } |
631 | 905 | ||
632 | hci_dev_unlock(hdev); | 906 | hci_dev_unlock(hdev); |
@@ -687,7 +961,7 @@ static void hci_cs_set_conn_encrypt(struct hci_dev *hdev, __u8 status) | |||
687 | } | 961 | } |
688 | 962 | ||
689 | static int hci_outgoing_auth_needed(struct hci_dev *hdev, | 963 | static int hci_outgoing_auth_needed(struct hci_dev *hdev, |
690 | struct hci_conn *conn) | 964 | struct hci_conn *conn) |
691 | { | 965 | { |
692 | if (conn->state != BT_CONFIG || !conn->out) | 966 | if (conn->state != BT_CONFIG || !conn->out) |
693 | return 0; | 967 | return 0; |
@@ -808,11 +1082,14 @@ static void hci_cs_setup_sync_conn(struct hci_dev *hdev, __u8 status) | |||
808 | hci_dev_lock(hdev); | 1082 | hci_dev_lock(hdev); |
809 | 1083 | ||
810 | acl = hci_conn_hash_lookup_handle(hdev, handle); | 1084 | acl = hci_conn_hash_lookup_handle(hdev, handle); |
811 | if (acl && (sco = acl->link)) { | 1085 | if (acl) { |
812 | sco->state = BT_CLOSED; | 1086 | sco = acl->link; |
1087 | if (sco) { | ||
1088 | sco->state = BT_CLOSED; | ||
813 | 1089 | ||
814 | hci_proto_connect_cfm(sco, status); | 1090 | hci_proto_connect_cfm(sco, status); |
815 | hci_conn_del(sco); | 1091 | hci_conn_del(sco); |
1092 | } | ||
816 | } | 1093 | } |
817 | 1094 | ||
818 | hci_dev_unlock(hdev); | 1095 | hci_dev_unlock(hdev); |
@@ -872,6 +1149,43 @@ static void hci_cs_exit_sniff_mode(struct hci_dev *hdev, __u8 status) | |||
872 | hci_dev_unlock(hdev); | 1149 | hci_dev_unlock(hdev); |
873 | } | 1150 | } |
874 | 1151 | ||
1152 | static void hci_cs_le_create_conn(struct hci_dev *hdev, __u8 status) | ||
1153 | { | ||
1154 | struct hci_cp_le_create_conn *cp; | ||
1155 | struct hci_conn *conn; | ||
1156 | |||
1157 | BT_DBG("%s status 0x%x", hdev->name, status); | ||
1158 | |||
1159 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_CREATE_CONN); | ||
1160 | if (!cp) | ||
1161 | return; | ||
1162 | |||
1163 | hci_dev_lock(hdev); | ||
1164 | |||
1165 | conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->peer_addr); | ||
1166 | |||
1167 | BT_DBG("%s bdaddr %s conn %p", hdev->name, batostr(&cp->peer_addr), | ||
1168 | conn); | ||
1169 | |||
1170 | if (status) { | ||
1171 | if (conn && conn->state == BT_CONNECT) { | ||
1172 | conn->state = BT_CLOSED; | ||
1173 | hci_proto_connect_cfm(conn, status); | ||
1174 | hci_conn_del(conn); | ||
1175 | } | ||
1176 | } else { | ||
1177 | if (!conn) { | ||
1178 | conn = hci_conn_add(hdev, LE_LINK, &cp->peer_addr); | ||
1179 | if (conn) | ||
1180 | conn->out = 1; | ||
1181 | else | ||
1182 | BT_ERR("No memory for new connection"); | ||
1183 | } | ||
1184 | } | ||
1185 | |||
1186 | hci_dev_unlock(hdev); | ||
1187 | } | ||
1188 | |||
875 | static inline void hci_inquiry_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) | 1189 | static inline void hci_inquiry_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
876 | { | 1190 | { |
877 | __u8 status = *((__u8 *) skb->data); | 1191 | __u8 status = *((__u8 *) skb->data); |
@@ -942,6 +1256,7 @@ static inline void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *s | |||
942 | conn->state = BT_CONFIG; | 1256 | conn->state = BT_CONFIG; |
943 | hci_conn_hold(conn); | 1257 | hci_conn_hold(conn); |
944 | conn->disc_timeout = HCI_DISCONN_TIMEOUT; | 1258 | conn->disc_timeout = HCI_DISCONN_TIMEOUT; |
1259 | mgmt_connected(hdev->id, &ev->bdaddr); | ||
945 | } else | 1260 | } else |
946 | conn->state = BT_CONNECTED; | 1261 | conn->state = BT_CONNECTED; |
947 | 1262 | ||
@@ -970,8 +1285,11 @@ static inline void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *s | |||
970 | hci_send_cmd(hdev, HCI_OP_CHANGE_CONN_PTYPE, | 1285 | hci_send_cmd(hdev, HCI_OP_CHANGE_CONN_PTYPE, |
971 | sizeof(cp), &cp); | 1286 | sizeof(cp), &cp); |
972 | } | 1287 | } |
973 | } else | 1288 | } else { |
974 | conn->state = BT_CLOSED; | 1289 | conn->state = BT_CLOSED; |
1290 | if (conn->type == ACL_LINK) | ||
1291 | mgmt_connect_failed(hdev->id, &ev->bdaddr, ev->status); | ||
1292 | } | ||
975 | 1293 | ||
976 | if (conn->type == ACL_LINK) | 1294 | if (conn->type == ACL_LINK) |
977 | hci_sco_setup(conn, ev->status); | 1295 | hci_sco_setup(conn, ev->status); |
@@ -998,7 +1316,8 @@ static inline void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *sk | |||
998 | 1316 | ||
999 | mask |= hci_proto_connect_ind(hdev, &ev->bdaddr, ev->link_type); | 1317 | mask |= hci_proto_connect_ind(hdev, &ev->bdaddr, ev->link_type); |
1000 | 1318 | ||
1001 | if ((mask & HCI_LM_ACCEPT) && !hci_blacklist_lookup(hdev, &ev->bdaddr)) { | 1319 | if ((mask & HCI_LM_ACCEPT) && |
1320 | !hci_blacklist_lookup(hdev, &ev->bdaddr)) { | ||
1002 | /* Connection accepted */ | 1321 | /* Connection accepted */ |
1003 | struct inquiry_entry *ie; | 1322 | struct inquiry_entry *ie; |
1004 | struct hci_conn *conn; | 1323 | struct hci_conn *conn; |
@@ -1068,19 +1387,26 @@ static inline void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff | |||
1068 | 1387 | ||
1069 | BT_DBG("%s status %d", hdev->name, ev->status); | 1388 | BT_DBG("%s status %d", hdev->name, ev->status); |
1070 | 1389 | ||
1071 | if (ev->status) | 1390 | if (ev->status) { |
1391 | mgmt_disconnect_failed(hdev->id); | ||
1072 | return; | 1392 | return; |
1393 | } | ||
1073 | 1394 | ||
1074 | hci_dev_lock(hdev); | 1395 | hci_dev_lock(hdev); |
1075 | 1396 | ||
1076 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); | 1397 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
1077 | if (conn) { | 1398 | if (!conn) |
1078 | conn->state = BT_CLOSED; | 1399 | goto unlock; |
1079 | 1400 | ||
1080 | hci_proto_disconn_cfm(conn, ev->reason); | 1401 | conn->state = BT_CLOSED; |
1081 | hci_conn_del(conn); | 1402 | |
1082 | } | 1403 | if (conn->type == ACL_LINK) |
1404 | mgmt_disconnected(hdev->id, &conn->dst); | ||
1083 | 1405 | ||
1406 | hci_proto_disconn_cfm(conn, ev->reason); | ||
1407 | hci_conn_del(conn); | ||
1408 | |||
1409 | unlock: | ||
1084 | hci_dev_unlock(hdev); | 1410 | hci_dev_unlock(hdev); |
1085 | } | 1411 | } |
1086 | 1412 | ||
@@ -1098,8 +1424,10 @@ static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *s | |||
1098 | if (!ev->status) { | 1424 | if (!ev->status) { |
1099 | conn->link_mode |= HCI_LM_AUTH; | 1425 | conn->link_mode |= HCI_LM_AUTH; |
1100 | conn->sec_level = conn->pending_sec_level; | 1426 | conn->sec_level = conn->pending_sec_level; |
1101 | } else | 1427 | } else { |
1428 | mgmt_auth_failed(hdev->id, &conn->dst, ev->status); | ||
1102 | conn->sec_level = BT_SECURITY_LOW; | 1429 | conn->sec_level = BT_SECURITY_LOW; |
1430 | } | ||
1103 | 1431 | ||
1104 | clear_bit(HCI_CONN_AUTH_PEND, &conn->pend); | 1432 | clear_bit(HCI_CONN_AUTH_PEND, &conn->pend); |
1105 | 1433 | ||
@@ -1393,11 +1721,54 @@ static inline void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *sk | |||
1393 | hci_cc_write_ca_timeout(hdev, skb); | 1721 | hci_cc_write_ca_timeout(hdev, skb); |
1394 | break; | 1722 | break; |
1395 | 1723 | ||
1724 | case HCI_OP_DELETE_STORED_LINK_KEY: | ||
1725 | hci_cc_delete_stored_link_key(hdev, skb); | ||
1726 | break; | ||
1727 | |||
1728 | case HCI_OP_SET_EVENT_MASK: | ||
1729 | hci_cc_set_event_mask(hdev, skb); | ||
1730 | break; | ||
1731 | |||
1732 | case HCI_OP_WRITE_INQUIRY_MODE: | ||
1733 | hci_cc_write_inquiry_mode(hdev, skb); | ||
1734 | break; | ||
1735 | |||
1736 | case HCI_OP_READ_INQ_RSP_TX_POWER: | ||
1737 | hci_cc_read_inq_rsp_tx_power(hdev, skb); | ||
1738 | break; | ||
1739 | |||
1740 | case HCI_OP_SET_EVENT_FLT: | ||
1741 | hci_cc_set_event_flt(hdev, skb); | ||
1742 | break; | ||
1743 | |||
1744 | case HCI_OP_PIN_CODE_REPLY: | ||
1745 | hci_cc_pin_code_reply(hdev, skb); | ||
1746 | break; | ||
1747 | |||
1748 | case HCI_OP_PIN_CODE_NEG_REPLY: | ||
1749 | hci_cc_pin_code_neg_reply(hdev, skb); | ||
1750 | break; | ||
1751 | |||
1752 | case HCI_OP_LE_READ_BUFFER_SIZE: | ||
1753 | hci_cc_le_read_buffer_size(hdev, skb); | ||
1754 | break; | ||
1755 | |||
1756 | case HCI_OP_USER_CONFIRM_REPLY: | ||
1757 | hci_cc_user_confirm_reply(hdev, skb); | ||
1758 | break; | ||
1759 | |||
1760 | case HCI_OP_USER_CONFIRM_NEG_REPLY: | ||
1761 | hci_cc_user_confirm_neg_reply(hdev, skb); | ||
1762 | break; | ||
1763 | |||
1396 | default: | 1764 | default: |
1397 | BT_DBG("%s opcode 0x%x", hdev->name, opcode); | 1765 | BT_DBG("%s opcode 0x%x", hdev->name, opcode); |
1398 | break; | 1766 | break; |
1399 | } | 1767 | } |
1400 | 1768 | ||
1769 | if (ev->opcode != HCI_OP_NOP) | ||
1770 | del_timer(&hdev->cmd_timer); | ||
1771 | |||
1401 | if (ev->ncmd) { | 1772 | if (ev->ncmd) { |
1402 | atomic_set(&hdev->cmd_cnt, 1); | 1773 | atomic_set(&hdev->cmd_cnt, 1); |
1403 | if (!skb_queue_empty(&hdev->cmd_q)) | 1774 | if (!skb_queue_empty(&hdev->cmd_q)) |
@@ -1459,11 +1830,23 @@ static inline void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb) | |||
1459 | hci_cs_exit_sniff_mode(hdev, ev->status); | 1830 | hci_cs_exit_sniff_mode(hdev, ev->status); |
1460 | break; | 1831 | break; |
1461 | 1832 | ||
1833 | case HCI_OP_DISCONNECT: | ||
1834 | if (ev->status != 0) | ||
1835 | mgmt_disconnect_failed(hdev->id); | ||
1836 | break; | ||
1837 | |||
1838 | case HCI_OP_LE_CREATE_CONN: | ||
1839 | hci_cs_le_create_conn(hdev, ev->status); | ||
1840 | break; | ||
1841 | |||
1462 | default: | 1842 | default: |
1463 | BT_DBG("%s opcode 0x%x", hdev->name, opcode); | 1843 | BT_DBG("%s opcode 0x%x", hdev->name, opcode); |
1464 | break; | 1844 | break; |
1465 | } | 1845 | } |
1466 | 1846 | ||
1847 | if (ev->opcode != HCI_OP_NOP) | ||
1848 | del_timer(&hdev->cmd_timer); | ||
1849 | |||
1467 | if (ev->ncmd) { | 1850 | if (ev->ncmd) { |
1468 | atomic_set(&hdev->cmd_cnt, 1); | 1851 | atomic_set(&hdev->cmd_cnt, 1); |
1469 | if (!skb_queue_empty(&hdev->cmd_q)) | 1852 | if (!skb_queue_empty(&hdev->cmd_q)) |
@@ -1529,6 +1912,16 @@ static inline void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *s | |||
1529 | hdev->acl_cnt += count; | 1912 | hdev->acl_cnt += count; |
1530 | if (hdev->acl_cnt > hdev->acl_pkts) | 1913 | if (hdev->acl_cnt > hdev->acl_pkts) |
1531 | hdev->acl_cnt = hdev->acl_pkts; | 1914 | hdev->acl_cnt = hdev->acl_pkts; |
1915 | } else if (conn->type == LE_LINK) { | ||
1916 | if (hdev->le_pkts) { | ||
1917 | hdev->le_cnt += count; | ||
1918 | if (hdev->le_cnt > hdev->le_pkts) | ||
1919 | hdev->le_cnt = hdev->le_pkts; | ||
1920 | } else { | ||
1921 | hdev->acl_cnt += count; | ||
1922 | if (hdev->acl_cnt > hdev->acl_pkts) | ||
1923 | hdev->acl_cnt = hdev->acl_pkts; | ||
1924 | } | ||
1532 | } else { | 1925 | } else { |
1533 | hdev->sco_cnt += count; | 1926 | hdev->sco_cnt += count; |
1534 | if (hdev->sco_cnt > hdev->sco_pkts) | 1927 | if (hdev->sco_cnt > hdev->sco_pkts) |
@@ -1586,18 +1979,72 @@ static inline void hci_pin_code_request_evt(struct hci_dev *hdev, struct sk_buff | |||
1586 | hci_conn_put(conn); | 1979 | hci_conn_put(conn); |
1587 | } | 1980 | } |
1588 | 1981 | ||
1982 | if (!test_bit(HCI_PAIRABLE, &hdev->flags)) | ||
1983 | hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY, | ||
1984 | sizeof(ev->bdaddr), &ev->bdaddr); | ||
1985 | |||
1986 | if (test_bit(HCI_MGMT, &hdev->flags)) | ||
1987 | mgmt_pin_code_request(hdev->id, &ev->bdaddr); | ||
1988 | |||
1589 | hci_dev_unlock(hdev); | 1989 | hci_dev_unlock(hdev); |
1590 | } | 1990 | } |
1591 | 1991 | ||
1592 | static inline void hci_link_key_request_evt(struct hci_dev *hdev, struct sk_buff *skb) | 1992 | static inline void hci_link_key_request_evt(struct hci_dev *hdev, struct sk_buff *skb) |
1593 | { | 1993 | { |
1994 | struct hci_ev_link_key_req *ev = (void *) skb->data; | ||
1995 | struct hci_cp_link_key_reply cp; | ||
1996 | struct hci_conn *conn; | ||
1997 | struct link_key *key; | ||
1998 | |||
1594 | BT_DBG("%s", hdev->name); | 1999 | BT_DBG("%s", hdev->name); |
2000 | |||
2001 | if (!test_bit(HCI_LINK_KEYS, &hdev->flags)) | ||
2002 | return; | ||
2003 | |||
2004 | hci_dev_lock(hdev); | ||
2005 | |||
2006 | key = hci_find_link_key(hdev, &ev->bdaddr); | ||
2007 | if (!key) { | ||
2008 | BT_DBG("%s link key not found for %s", hdev->name, | ||
2009 | batostr(&ev->bdaddr)); | ||
2010 | goto not_found; | ||
2011 | } | ||
2012 | |||
2013 | BT_DBG("%s found key type %u for %s", hdev->name, key->type, | ||
2014 | batostr(&ev->bdaddr)); | ||
2015 | |||
2016 | if (!test_bit(HCI_DEBUG_KEYS, &hdev->flags) && key->type == 0x03) { | ||
2017 | BT_DBG("%s ignoring debug key", hdev->name); | ||
2018 | goto not_found; | ||
2019 | } | ||
2020 | |||
2021 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); | ||
2022 | |||
2023 | if (key->type == 0x04 && conn && conn->auth_type != 0xff && | ||
2024 | (conn->auth_type & 0x01)) { | ||
2025 | BT_DBG("%s ignoring unauthenticated key", hdev->name); | ||
2026 | goto not_found; | ||
2027 | } | ||
2028 | |||
2029 | bacpy(&cp.bdaddr, &ev->bdaddr); | ||
2030 | memcpy(cp.link_key, key->val, 16); | ||
2031 | |||
2032 | hci_send_cmd(hdev, HCI_OP_LINK_KEY_REPLY, sizeof(cp), &cp); | ||
2033 | |||
2034 | hci_dev_unlock(hdev); | ||
2035 | |||
2036 | return; | ||
2037 | |||
2038 | not_found: | ||
2039 | hci_send_cmd(hdev, HCI_OP_LINK_KEY_NEG_REPLY, 6, &ev->bdaddr); | ||
2040 | hci_dev_unlock(hdev); | ||
1595 | } | 2041 | } |
1596 | 2042 | ||
1597 | static inline void hci_link_key_notify_evt(struct hci_dev *hdev, struct sk_buff *skb) | 2043 | static inline void hci_link_key_notify_evt(struct hci_dev *hdev, struct sk_buff *skb) |
1598 | { | 2044 | { |
1599 | struct hci_ev_link_key_notify *ev = (void *) skb->data; | 2045 | struct hci_ev_link_key_notify *ev = (void *) skb->data; |
1600 | struct hci_conn *conn; | 2046 | struct hci_conn *conn; |
2047 | u8 pin_len = 0; | ||
1601 | 2048 | ||
1602 | BT_DBG("%s", hdev->name); | 2049 | BT_DBG("%s", hdev->name); |
1603 | 2050 | ||
@@ -1607,9 +2054,14 @@ static inline void hci_link_key_notify_evt(struct hci_dev *hdev, struct sk_buff | |||
1607 | if (conn) { | 2054 | if (conn) { |
1608 | hci_conn_hold(conn); | 2055 | hci_conn_hold(conn); |
1609 | conn->disc_timeout = HCI_DISCONN_TIMEOUT; | 2056 | conn->disc_timeout = HCI_DISCONN_TIMEOUT; |
2057 | pin_len = conn->pin_length; | ||
1610 | hci_conn_put(conn); | 2058 | hci_conn_put(conn); |
1611 | } | 2059 | } |
1612 | 2060 | ||
2061 | if (test_bit(HCI_LINK_KEYS, &hdev->flags)) | ||
2062 | hci_add_link_key(hdev, 1, &ev->bdaddr, ev->link_key, | ||
2063 | ev->key_type, pin_len); | ||
2064 | |||
1613 | hci_dev_unlock(hdev); | 2065 | hci_dev_unlock(hdev); |
1614 | } | 2066 | } |
1615 | 2067 | ||
@@ -1683,7 +2135,8 @@ static inline void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, struct | |||
1683 | hci_dev_lock(hdev); | 2135 | hci_dev_lock(hdev); |
1684 | 2136 | ||
1685 | if ((skb->len - 1) / num_rsp != sizeof(struct inquiry_info_with_rssi)) { | 2137 | if ((skb->len - 1) / num_rsp != sizeof(struct inquiry_info_with_rssi)) { |
1686 | struct inquiry_info_with_rssi_and_pscan_mode *info = (void *) (skb->data + 1); | 2138 | struct inquiry_info_with_rssi_and_pscan_mode *info; |
2139 | info = (void *) (skb->data + 1); | ||
1687 | 2140 | ||
1688 | for (; num_rsp; num_rsp--) { | 2141 | for (; num_rsp; num_rsp--) { |
1689 | bacpy(&data.bdaddr, &info->bdaddr); | 2142 | bacpy(&data.bdaddr, &info->bdaddr); |
@@ -1824,17 +2277,8 @@ static inline void hci_sync_conn_changed_evt(struct hci_dev *hdev, struct sk_buf | |||
1824 | static inline void hci_sniff_subrate_evt(struct hci_dev *hdev, struct sk_buff *skb) | 2277 | static inline void hci_sniff_subrate_evt(struct hci_dev *hdev, struct sk_buff *skb) |
1825 | { | 2278 | { |
1826 | struct hci_ev_sniff_subrate *ev = (void *) skb->data; | 2279 | struct hci_ev_sniff_subrate *ev = (void *) skb->data; |
1827 | struct hci_conn *conn; | ||
1828 | 2280 | ||
1829 | BT_DBG("%s status %d", hdev->name, ev->status); | 2281 | BT_DBG("%s status %d", hdev->name, ev->status); |
1830 | |||
1831 | hci_dev_lock(hdev); | ||
1832 | |||
1833 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); | ||
1834 | if (conn) { | ||
1835 | } | ||
1836 | |||
1837 | hci_dev_unlock(hdev); | ||
1838 | } | 2282 | } |
1839 | 2283 | ||
1840 | static inline void hci_extended_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *skb) | 2284 | static inline void hci_extended_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *skb) |
@@ -1852,12 +2296,12 @@ static inline void hci_extended_inquiry_result_evt(struct hci_dev *hdev, struct | |||
1852 | 2296 | ||
1853 | for (; num_rsp; num_rsp--) { | 2297 | for (; num_rsp; num_rsp--) { |
1854 | bacpy(&data.bdaddr, &info->bdaddr); | 2298 | bacpy(&data.bdaddr, &info->bdaddr); |
1855 | data.pscan_rep_mode = info->pscan_rep_mode; | 2299 | data.pscan_rep_mode = info->pscan_rep_mode; |
1856 | data.pscan_period_mode = info->pscan_period_mode; | 2300 | data.pscan_period_mode = info->pscan_period_mode; |
1857 | data.pscan_mode = 0x00; | 2301 | data.pscan_mode = 0x00; |
1858 | memcpy(data.dev_class, info->dev_class, 3); | 2302 | memcpy(data.dev_class, info->dev_class, 3); |
1859 | data.clock_offset = info->clock_offset; | 2303 | data.clock_offset = info->clock_offset; |
1860 | data.rssi = info->rssi; | 2304 | data.rssi = info->rssi; |
1861 | data.ssp_mode = 0x01; | 2305 | data.ssp_mode = 0x01; |
1862 | info++; | 2306 | info++; |
1863 | hci_inquiry_cache_update(hdev, &data); | 2307 | hci_inquiry_cache_update(hdev, &data); |
@@ -1866,6 +2310,25 @@ static inline void hci_extended_inquiry_result_evt(struct hci_dev *hdev, struct | |||
1866 | hci_dev_unlock(hdev); | 2310 | hci_dev_unlock(hdev); |
1867 | } | 2311 | } |
1868 | 2312 | ||
2313 | static inline u8 hci_get_auth_req(struct hci_conn *conn) | ||
2314 | { | ||
2315 | /* If remote requests dedicated bonding follow that lead */ | ||
2316 | if (conn->remote_auth == 0x02 || conn->remote_auth == 0x03) { | ||
2317 | /* If both remote and local IO capabilities allow MITM | ||
2318 | * protection then require it, otherwise don't */ | ||
2319 | if (conn->remote_cap == 0x03 || conn->io_capability == 0x03) | ||
2320 | return 0x02; | ||
2321 | else | ||
2322 | return 0x03; | ||
2323 | } | ||
2324 | |||
2325 | /* If remote requests no-bonding follow that lead */ | ||
2326 | if (conn->remote_auth == 0x00 || conn->remote_auth == 0x01) | ||
2327 | return 0x00; | ||
2328 | |||
2329 | return conn->auth_type; | ||
2330 | } | ||
2331 | |||
1869 | static inline void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff *skb) | 2332 | static inline void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff *skb) |
1870 | { | 2333 | { |
1871 | struct hci_ev_io_capa_request *ev = (void *) skb->data; | 2334 | struct hci_ev_io_capa_request *ev = (void *) skb->data; |
@@ -1876,8 +2339,73 @@ static inline void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff | |||
1876 | hci_dev_lock(hdev); | 2339 | hci_dev_lock(hdev); |
1877 | 2340 | ||
1878 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); | 2341 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
1879 | if (conn) | 2342 | if (!conn) |
1880 | hci_conn_hold(conn); | 2343 | goto unlock; |
2344 | |||
2345 | hci_conn_hold(conn); | ||
2346 | |||
2347 | if (!test_bit(HCI_MGMT, &hdev->flags)) | ||
2348 | goto unlock; | ||
2349 | |||
2350 | if (test_bit(HCI_PAIRABLE, &hdev->flags) || | ||
2351 | (conn->remote_auth & ~0x01) == HCI_AT_NO_BONDING) { | ||
2352 | struct hci_cp_io_capability_reply cp; | ||
2353 | |||
2354 | bacpy(&cp.bdaddr, &ev->bdaddr); | ||
2355 | cp.capability = conn->io_capability; | ||
2356 | cp.oob_data = 0; | ||
2357 | cp.authentication = hci_get_auth_req(conn); | ||
2358 | |||
2359 | hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_REPLY, | ||
2360 | sizeof(cp), &cp); | ||
2361 | } else { | ||
2362 | struct hci_cp_io_capability_neg_reply cp; | ||
2363 | |||
2364 | bacpy(&cp.bdaddr, &ev->bdaddr); | ||
2365 | cp.reason = 0x16; /* Pairing not allowed */ | ||
2366 | |||
2367 | hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_NEG_REPLY, | ||
2368 | sizeof(cp), &cp); | ||
2369 | } | ||
2370 | |||
2371 | unlock: | ||
2372 | hci_dev_unlock(hdev); | ||
2373 | } | ||
2374 | |||
2375 | static inline void hci_io_capa_reply_evt(struct hci_dev *hdev, struct sk_buff *skb) | ||
2376 | { | ||
2377 | struct hci_ev_io_capa_reply *ev = (void *) skb->data; | ||
2378 | struct hci_conn *conn; | ||
2379 | |||
2380 | BT_DBG("%s", hdev->name); | ||
2381 | |||
2382 | hci_dev_lock(hdev); | ||
2383 | |||
2384 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); | ||
2385 | if (!conn) | ||
2386 | goto unlock; | ||
2387 | |||
2388 | hci_conn_hold(conn); | ||
2389 | |||
2390 | conn->remote_cap = ev->capability; | ||
2391 | conn->remote_oob = ev->oob_data; | ||
2392 | conn->remote_auth = ev->authentication; | ||
2393 | |||
2394 | unlock: | ||
2395 | hci_dev_unlock(hdev); | ||
2396 | } | ||
2397 | |||
2398 | static inline void hci_user_confirm_request_evt(struct hci_dev *hdev, | ||
2399 | struct sk_buff *skb) | ||
2400 | { | ||
2401 | struct hci_ev_user_confirm_req *ev = (void *) skb->data; | ||
2402 | |||
2403 | BT_DBG("%s", hdev->name); | ||
2404 | |||
2405 | hci_dev_lock(hdev); | ||
2406 | |||
2407 | if (test_bit(HCI_MGMT, &hdev->flags)) | ||
2408 | mgmt_user_confirm_request(hdev->id, &ev->bdaddr, ev->passkey); | ||
1881 | 2409 | ||
1882 | hci_dev_unlock(hdev); | 2410 | hci_dev_unlock(hdev); |
1883 | } | 2411 | } |
@@ -1892,9 +2420,20 @@ static inline void hci_simple_pair_complete_evt(struct hci_dev *hdev, struct sk_ | |||
1892 | hci_dev_lock(hdev); | 2420 | hci_dev_lock(hdev); |
1893 | 2421 | ||
1894 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); | 2422 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
1895 | if (conn) | 2423 | if (!conn) |
1896 | hci_conn_put(conn); | 2424 | goto unlock; |
2425 | |||
2426 | /* To avoid duplicate auth_failed events to user space we check | ||
2427 | * the HCI_CONN_AUTH_PEND flag which will be set if we | ||
2428 | * initiated the authentication. A traditional auth_complete | ||
2429 | * event gets always produced as initiator and is also mapped to | ||
2430 | * the mgmt_auth_failed event */ | ||
2431 | if (!test_bit(HCI_CONN_AUTH_PEND, &conn->pend) && ev->status != 0) | ||
2432 | mgmt_auth_failed(hdev->id, &conn->dst, ev->status); | ||
2433 | |||
2434 | hci_conn_put(conn); | ||
1897 | 2435 | ||
2436 | unlock: | ||
1898 | hci_dev_unlock(hdev); | 2437 | hci_dev_unlock(hdev); |
1899 | } | 2438 | } |
1900 | 2439 | ||
@@ -1914,6 +2453,60 @@ static inline void hci_remote_host_features_evt(struct hci_dev *hdev, struct sk_ | |||
1914 | hci_dev_unlock(hdev); | 2453 | hci_dev_unlock(hdev); |
1915 | } | 2454 | } |
1916 | 2455 | ||
2456 | static inline void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) | ||
2457 | { | ||
2458 | struct hci_ev_le_conn_complete *ev = (void *) skb->data; | ||
2459 | struct hci_conn *conn; | ||
2460 | |||
2461 | BT_DBG("%s status %d", hdev->name, ev->status); | ||
2462 | |||
2463 | hci_dev_lock(hdev); | ||
2464 | |||
2465 | conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &ev->bdaddr); | ||
2466 | if (!conn) { | ||
2467 | conn = hci_conn_add(hdev, LE_LINK, &ev->bdaddr); | ||
2468 | if (!conn) { | ||
2469 | BT_ERR("No memory for new connection"); | ||
2470 | hci_dev_unlock(hdev); | ||
2471 | return; | ||
2472 | } | ||
2473 | } | ||
2474 | |||
2475 | if (ev->status) { | ||
2476 | hci_proto_connect_cfm(conn, ev->status); | ||
2477 | conn->state = BT_CLOSED; | ||
2478 | hci_conn_del(conn); | ||
2479 | goto unlock; | ||
2480 | } | ||
2481 | |||
2482 | conn->handle = __le16_to_cpu(ev->handle); | ||
2483 | conn->state = BT_CONNECTED; | ||
2484 | |||
2485 | hci_conn_hold_device(conn); | ||
2486 | hci_conn_add_sysfs(conn); | ||
2487 | |||
2488 | hci_proto_connect_cfm(conn, ev->status); | ||
2489 | |||
2490 | unlock: | ||
2491 | hci_dev_unlock(hdev); | ||
2492 | } | ||
2493 | |||
2494 | static inline void hci_le_meta_evt(struct hci_dev *hdev, struct sk_buff *skb) | ||
2495 | { | ||
2496 | struct hci_ev_le_meta *le_ev = (void *) skb->data; | ||
2497 | |||
2498 | skb_pull(skb, sizeof(*le_ev)); | ||
2499 | |||
2500 | switch (le_ev->subevent) { | ||
2501 | case HCI_EV_LE_CONN_COMPLETE: | ||
2502 | hci_le_conn_complete_evt(hdev, skb); | ||
2503 | break; | ||
2504 | |||
2505 | default: | ||
2506 | break; | ||
2507 | } | ||
2508 | } | ||
2509 | |||
1917 | void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb) | 2510 | void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb) |
1918 | { | 2511 | { |
1919 | struct hci_event_hdr *hdr = (void *) skb->data; | 2512 | struct hci_event_hdr *hdr = (void *) skb->data; |
@@ -2042,6 +2635,14 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb) | |||
2042 | hci_io_capa_request_evt(hdev, skb); | 2635 | hci_io_capa_request_evt(hdev, skb); |
2043 | break; | 2636 | break; |
2044 | 2637 | ||
2638 | case HCI_EV_IO_CAPA_REPLY: | ||
2639 | hci_io_capa_reply_evt(hdev, skb); | ||
2640 | break; | ||
2641 | |||
2642 | case HCI_EV_USER_CONFIRM_REQUEST: | ||
2643 | hci_user_confirm_request_evt(hdev, skb); | ||
2644 | break; | ||
2645 | |||
2045 | case HCI_EV_SIMPLE_PAIR_COMPLETE: | 2646 | case HCI_EV_SIMPLE_PAIR_COMPLETE: |
2046 | hci_simple_pair_complete_evt(hdev, skb); | 2647 | hci_simple_pair_complete_evt(hdev, skb); |
2047 | break; | 2648 | break; |
@@ -2050,6 +2651,10 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb) | |||
2050 | hci_remote_host_features_evt(hdev, skb); | 2651 | hci_remote_host_features_evt(hdev, skb); |
2051 | break; | 2652 | break; |
2052 | 2653 | ||
2654 | case HCI_EV_LE_META: | ||
2655 | hci_le_meta_evt(hdev, skb); | ||
2656 | break; | ||
2657 | |||
2053 | default: | 2658 | default: |
2054 | BT_DBG("%s event 0x%x", hdev->name, event); | 2659 | BT_DBG("%s event 0x%x", hdev->name, event); |
2055 | break; | 2660 | break; |
@@ -2083,6 +2688,6 @@ void hci_si_event(struct hci_dev *hdev, int type, int dlen, void *data) | |||
2083 | 2688 | ||
2084 | bt_cb(skb)->pkt_type = HCI_EVENT_PKT; | 2689 | bt_cb(skb)->pkt_type = HCI_EVENT_PKT; |
2085 | skb->dev = (void *) hdev; | 2690 | skb->dev = (void *) hdev; |
2086 | hci_send_to_sock(hdev, skb); | 2691 | hci_send_to_sock(hdev, skb, NULL); |
2087 | kfree_skb(skb); | 2692 | kfree_skb(skb); |
2088 | } | 2693 | } |