hci_event.c (a3ec4a603faf4244e275bf11b467aad092dfbd8a) | hci_event.c (fcd89c09a59a054fb986861e0862aa2fff7d7c40) |
---|---|
1/* 2 BlueZ - Bluetooth protocol stack for Linux 3 Copyright (c) 2000-2001, 2010, Code Aurora Forum. All rights reserved. 4 5 Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com> 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License version 2 as --- 260 unchanged lines hidden (view full) --- 269 BT_DBG("%s status 0x%x", hdev->name, status); 270 271 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SCAN_ENABLE); 272 if (!sent) 273 return; 274 275 if (!status) { 276 __u8 param = *((__u8 *) sent); | 1/* 2 BlueZ - Bluetooth protocol stack for Linux 3 Copyright (c) 2000-2001, 2010, Code Aurora Forum. All rights reserved. 4 5 Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com> 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License version 2 as --- 260 unchanged lines hidden (view full) --- 269 BT_DBG("%s status 0x%x", hdev->name, status); 270 271 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SCAN_ENABLE); 272 if (!sent) 273 return; 274 275 if (!status) { 276 __u8 param = *((__u8 *) sent); |
277 int old_pscan, old_iscan; |
|
277 | 278 |
278 clear_bit(HCI_PSCAN, &hdev->flags); 279 clear_bit(HCI_ISCAN, &hdev->flags); | 279 old_pscan = test_and_clear_bit(HCI_PSCAN, &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 } 287 288 hci_req_complete(hdev, HCI_OP_WRITE_SCAN_ENABLE, status); 289} 290 291static void hci_cc_read_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb) 292{ 293 struct hci_rp_read_class_of_dev *rp = (void *) skb->data; --- 116 unchanged lines hidden (view full) --- 410 411 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SSP_MODE); 412 if (!sent) 413 return; 414 415 hdev->ssp_mode = *((__u8 *) sent); 416} 417 | 295 } 296 297 hci_req_complete(hdev, HCI_OP_WRITE_SCAN_ENABLE, status); 298} 299 300static void hci_cc_read_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb) 301{ 302 struct hci_rp_read_class_of_dev *rp = (void *) skb->data; --- 116 unchanged lines hidden (view full) --- 419 420 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SSP_MODE); 421 if (!sent) 422 return; 423 424 hdev->ssp_mode = *((__u8 *) sent); 425} 426 |
427static 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 455static 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 464static 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 517static 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 |
|
418static void hci_cc_read_local_version(struct hci_dev *hdev, struct sk_buff *skb) 419{ 420 struct hci_rp_read_local_version *rp = (void *) skb->data; 421 422 BT_DBG("%s status 0x%x", hdev->name, rp->status); 423 424 if (rp->status) 425 return; 426 427 hdev->hci_ver = rp->hci_ver; 428 hdev->hci_rev = __le16_to_cpu(rp->hci_rev); | 536static void hci_cc_read_local_version(struct hci_dev *hdev, struct sk_buff *skb) 537{ 538 struct hci_rp_read_local_version *rp = (void *) skb->data; 539 540 BT_DBG("%s status 0x%x", hdev->name, rp->status); 541 542 if (rp->status) 543 return; 544 545 hdev->hci_ver = rp->hci_ver; 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 431 BT_DBG("%s manufacturer %d hci ver %d:%d", hdev->name, 432 hdev->manufacturer, 433 hdev->hci_ver, hdev->hci_rev); | 550 551 BT_DBG("%s manufacturer %d hci ver %d:%d", hdev->name, 552 hdev->manufacturer, 553 hdev->hci_ver, hdev->hci_rev); |
554 555 if (test_bit(HCI_INIT, &hdev->flags)) 556 hci_setup(hdev); |
|
434} 435 | 557} 558 |
559static 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); 575} 576 |
|
436static void hci_cc_read_local_commands(struct hci_dev *hdev, struct sk_buff *skb) 437{ 438 struct hci_rp_read_local_commands *rp = (void *) skb->data; 439 440 BT_DBG("%s status 0x%x", hdev->name, rp->status); 441 442 if (rp->status) | 577static void hci_cc_read_local_commands(struct hci_dev *hdev, struct sk_buff *skb) 578{ 579 struct hci_rp_read_local_commands *rp = (void *) skb->data; 580 581 BT_DBG("%s status 0x%x", hdev->name, rp->status); 582 583 if (rp->status) |
443 return; | 584 goto done; |
444 445 memcpy(hdev->commands, rp->commands, sizeof(hdev->commands)); | 585 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 591done: 592 hci_req_complete(hdev, HCI_OP_READ_LOCAL_COMMANDS, rp->status); |
|
446} 447 448static void hci_cc_read_local_features(struct hci_dev *hdev, struct sk_buff *skb) 449{ 450 struct hci_rp_read_local_features *rp = (void *) skb->data; 451 452 BT_DBG("%s status 0x%x", hdev->name, rp->status); 453 --- 89 unchanged lines hidden (view full) --- 543{ 544 __u8 status = *((__u8 *) skb->data); 545 546 BT_DBG("%s status 0x%x", hdev->name, status); 547 548 hci_req_complete(hdev, HCI_OP_WRITE_CA_TIMEOUT, status); 549} 550 | 593} 594 595static void hci_cc_read_local_features(struct hci_dev *hdev, struct sk_buff *skb) 596{ 597 struct hci_rp_read_local_features *rp = (void *) skb->data; 598 599 BT_DBG("%s status 0x%x", hdev->name, rp->status); 600 --- 89 unchanged lines hidden (view full) --- 690{ 691 __u8 status = *((__u8 *) skb->data); 692 693 BT_DBG("%s status 0x%x", hdev->name, status); 694 695 hci_req_complete(hdev, HCI_OP_WRITE_CA_TIMEOUT, status); 696} 697 |
698static 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 708static 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 717static 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 727static 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 737static 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 746static 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 769static 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 |
|
551static inline void hci_cs_inquiry(struct hci_dev *hdev, __u8 status) 552{ 553 BT_DBG("%s status 0x%x", hdev->name, status); 554 555 if (status) { 556 hci_req_complete(hdev, HCI_OP_INQUIRY, status); 557 558 hci_conn_check_pending(hdev); --- 58 unchanged lines hidden (view full) --- 617 618 handle = __le16_to_cpu(cp->handle); 619 620 BT_DBG("%s handle %d", hdev->name, handle); 621 622 hci_dev_lock(hdev); 623 624 acl = hci_conn_hash_lookup_handle(hdev, handle); | 780static inline void hci_cs_inquiry(struct hci_dev *hdev, __u8 status) 781{ 782 BT_DBG("%s status 0x%x", hdev->name, status); 783 784 if (status) { 785 hci_req_complete(hdev, HCI_OP_INQUIRY, status); 786 787 hci_conn_check_pending(hdev); --- 58 unchanged lines hidden (view full) --- 846 847 handle = __le16_to_cpu(cp->handle); 848 849 BT_DBG("%s handle %d", hdev->name, handle); 850 851 hci_dev_lock(hdev); 852 853 acl = hci_conn_hash_lookup_handle(hdev, handle); |
625 if (acl && (sco = acl->link)) { 626 sco->state = BT_CLOSED; | 854 if (acl) { 855 sco = acl->link; 856 if (sco) { 857 sco->state = BT_CLOSED; |
627 | 858 |
628 hci_proto_connect_cfm(sco, status); 629 hci_conn_del(sco); | 859 hci_proto_connect_cfm(sco, status); 860 hci_conn_del(sco); 861 } |
630 } 631 632 hci_dev_unlock(hdev); 633} 634 635static void hci_cs_auth_requested(struct hci_dev *hdev, __u8 status) 636{ 637 struct hci_cp_auth_requested *cp; --- 165 unchanged lines hidden (view full) --- 803 804 handle = __le16_to_cpu(cp->handle); 805 806 BT_DBG("%s handle %d", hdev->name, handle); 807 808 hci_dev_lock(hdev); 809 810 acl = hci_conn_hash_lookup_handle(hdev, handle); | 862 } 863 864 hci_dev_unlock(hdev); 865} 866 867static void hci_cs_auth_requested(struct hci_dev *hdev, __u8 status) 868{ 869 struct hci_cp_auth_requested *cp; --- 165 unchanged lines hidden (view full) --- 1035 1036 handle = __le16_to_cpu(cp->handle); 1037 1038 BT_DBG("%s handle %d", hdev->name, handle); 1039 1040 hci_dev_lock(hdev); 1041 1042 acl = hci_conn_hash_lookup_handle(hdev, handle); |
811 if (acl && (sco = acl->link)) { 812 sco->state = BT_CLOSED; | 1043 if (acl) { 1044 sco = acl->link; 1045 if (sco) { 1046 sco->state = BT_CLOSED; |
813 | 1047 |
814 hci_proto_connect_cfm(sco, status); 815 hci_conn_del(sco); | 1048 hci_proto_connect_cfm(sco, status); 1049 hci_conn_del(sco); 1050 } |
816 } 817 818 hci_dev_unlock(hdev); 819} 820 821static void hci_cs_sniff_mode(struct hci_dev *hdev, __u8 status) 822{ 823 struct hci_cp_sniff_mode *cp; --- 43 unchanged lines hidden (view full) --- 867 868 if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->pend)) 869 hci_sco_setup(conn, status); 870 } 871 872 hci_dev_unlock(hdev); 873} 874 | 1051 } 1052 1053 hci_dev_unlock(hdev); 1054} 1055 1056static void hci_cs_sniff_mode(struct hci_dev *hdev, __u8 status) 1057{ 1058 struct hci_cp_sniff_mode *cp; --- 43 unchanged lines hidden (view full) --- 1102 1103 if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->pend)) 1104 hci_sco_setup(conn, status); 1105 } 1106 1107 hci_dev_unlock(hdev); 1108} 1109 |
1110static void hci_cs_le_create_conn(struct hci_dev *hdev, __u8 status) 1111{ 1112 struct hci_cp_le_create_conn *cp; 1113 struct hci_conn *conn; 1114 1115 BT_DBG("%s status 0x%x", hdev->name, status); 1116 1117 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_CREATE_CONN); 1118 if (!cp) 1119 return; 1120 1121 hci_dev_lock(hdev); 1122 1123 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->peer_addr); 1124 1125 BT_DBG("%s bdaddr %s conn %p", hdev->name, batostr(&cp->peer_addr), 1126 conn); 1127 1128 if (status) { 1129 if (conn && conn->state == BT_CONNECT) { 1130 conn->state = BT_CLOSED; 1131 hci_proto_connect_cfm(conn, status); 1132 hci_conn_del(conn); 1133 } 1134 } else { 1135 if (!conn) { 1136 conn = hci_conn_add(hdev, LE_LINK, &cp->peer_addr); 1137 if (conn) 1138 conn->out = 1; 1139 else 1140 BT_ERR("No memory for new connection"); 1141 } 1142 } 1143 1144 hci_dev_unlock(hdev); 1145} 1146 |
|
875static inline void hci_inquiry_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) 876{ 877 __u8 status = *((__u8 *) skb->data); 878 879 BT_DBG("%s status %d", hdev->name, status); 880 881 clear_bit(HCI_INQUIRY, &hdev->flags); 882 --- 54 unchanged lines hidden (view full) --- 937 938 if (!ev->status) { 939 conn->handle = __le16_to_cpu(ev->handle); 940 941 if (conn->type == ACL_LINK) { 942 conn->state = BT_CONFIG; 943 hci_conn_hold(conn); 944 conn->disc_timeout = HCI_DISCONN_TIMEOUT; | 1147static inline void hci_inquiry_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) 1148{ 1149 __u8 status = *((__u8 *) skb->data); 1150 1151 BT_DBG("%s status %d", hdev->name, status); 1152 1153 clear_bit(HCI_INQUIRY, &hdev->flags); 1154 --- 54 unchanged lines hidden (view full) --- 1209 1210 if (!ev->status) { 1211 conn->handle = __le16_to_cpu(ev->handle); 1212 1213 if (conn->type == ACL_LINK) { 1214 conn->state = BT_CONFIG; 1215 hci_conn_hold(conn); 1216 conn->disc_timeout = HCI_DISCONN_TIMEOUT; |
1217 mgmt_connected(hdev->id, &ev->bdaddr); |
|
945 } else 946 conn->state = BT_CONNECTED; 947 948 hci_conn_hold_device(conn); 949 hci_conn_add_sysfs(conn); 950 951 if (test_bit(HCI_AUTH, &hdev->flags)) 952 conn->link_mode |= HCI_LM_AUTH; --- 12 unchanged lines hidden (view full) --- 965 /* Set packet type for incoming connection */ 966 if (!conn->out && hdev->hci_ver < 3) { 967 struct hci_cp_change_conn_ptype cp; 968 cp.handle = ev->handle; 969 cp.pkt_type = cpu_to_le16(conn->pkt_type); 970 hci_send_cmd(hdev, HCI_OP_CHANGE_CONN_PTYPE, 971 sizeof(cp), &cp); 972 } | 1218 } else 1219 conn->state = BT_CONNECTED; 1220 1221 hci_conn_hold_device(conn); 1222 hci_conn_add_sysfs(conn); 1223 1224 if (test_bit(HCI_AUTH, &hdev->flags)) 1225 conn->link_mode |= HCI_LM_AUTH; --- 12 unchanged lines hidden (view full) --- 1238 /* Set packet type for incoming connection */ 1239 if (!conn->out && hdev->hci_ver < 3) { 1240 struct hci_cp_change_conn_ptype cp; 1241 cp.handle = ev->handle; 1242 cp.pkt_type = cpu_to_le16(conn->pkt_type); 1243 hci_send_cmd(hdev, HCI_OP_CHANGE_CONN_PTYPE, 1244 sizeof(cp), &cp); 1245 } |
973 } else | 1246 } else { |
974 conn->state = BT_CLOSED; | 1247 conn->state = BT_CLOSED; |
1248 if (conn->type == ACL_LINK) 1249 mgmt_connect_failed(hdev->id, &ev->bdaddr, ev->status); 1250 } |
|
975 976 if (conn->type == ACL_LINK) 977 hci_sco_setup(conn, ev->status); 978 979 if (ev->status) { 980 hci_proto_connect_cfm(conn, ev->status); 981 hci_conn_del(conn); 982 } else if (ev->link_type != ACL_LINK) --- 80 unchanged lines hidden (view full) --- 1063 1064static inline void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) 1065{ 1066 struct hci_ev_disconn_complete *ev = (void *) skb->data; 1067 struct hci_conn *conn; 1068 1069 BT_DBG("%s status %d", hdev->name, ev->status); 1070 | 1251 1252 if (conn->type == ACL_LINK) 1253 hci_sco_setup(conn, ev->status); 1254 1255 if (ev->status) { 1256 hci_proto_connect_cfm(conn, ev->status); 1257 hci_conn_del(conn); 1258 } else if (ev->link_type != ACL_LINK) --- 80 unchanged lines hidden (view full) --- 1339 1340static inline void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) 1341{ 1342 struct hci_ev_disconn_complete *ev = (void *) skb->data; 1343 struct hci_conn *conn; 1344 1345 BT_DBG("%s status %d", hdev->name, ev->status); 1346 |
1071 if (ev->status) | 1347 if (ev->status) { 1348 mgmt_disconnect_failed(hdev->id); |
1072 return; | 1349 return; |
1350 } |
|
1073 1074 hci_dev_lock(hdev); 1075 1076 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); | 1351 1352 hci_dev_lock(hdev); 1353 1354 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
1077 if (conn) { 1078 conn->state = BT_CLOSED; | 1355 if (!conn) 1356 goto unlock; |
1079 | 1357 |
1080 hci_proto_disconn_cfm(conn, ev->reason); 1081 hci_conn_del(conn); 1082 } | 1358 conn->state = BT_CLOSED; |
1083 | 1359 |
1360 if (conn->type == ACL_LINK) 1361 mgmt_disconnected(hdev->id, &conn->dst); 1362 1363 hci_proto_disconn_cfm(conn, ev->reason); 1364 hci_conn_del(conn); 1365 1366unlock: |
|
1084 hci_dev_unlock(hdev); 1085} 1086 1087static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) 1088{ 1089 struct hci_ev_auth_complete *ev = (void *) skb->data; 1090 struct hci_conn *conn; 1091 --- 296 unchanged lines hidden (view full) --- 1388 case HCI_OP_READ_BD_ADDR: 1389 hci_cc_read_bd_addr(hdev, skb); 1390 break; 1391 1392 case HCI_OP_WRITE_CA_TIMEOUT: 1393 hci_cc_write_ca_timeout(hdev, skb); 1394 break; 1395 | 1367 hci_dev_unlock(hdev); 1368} 1369 1370static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) 1371{ 1372 struct hci_ev_auth_complete *ev = (void *) skb->data; 1373 struct hci_conn *conn; 1374 --- 296 unchanged lines hidden (view full) --- 1671 case HCI_OP_READ_BD_ADDR: 1672 hci_cc_read_bd_addr(hdev, skb); 1673 break; 1674 1675 case HCI_OP_WRITE_CA_TIMEOUT: 1676 hci_cc_write_ca_timeout(hdev, skb); 1677 break; 1678 |
1679 case HCI_OP_DELETE_STORED_LINK_KEY: 1680 hci_cc_delete_stored_link_key(hdev, skb); 1681 break; 1682 1683 case HCI_OP_SET_EVENT_MASK: 1684 hci_cc_set_event_mask(hdev, skb); 1685 break; 1686 1687 case HCI_OP_WRITE_INQUIRY_MODE: 1688 hci_cc_write_inquiry_mode(hdev, skb); 1689 break; 1690 1691 case HCI_OP_READ_INQ_RSP_TX_POWER: 1692 hci_cc_read_inq_rsp_tx_power(hdev, skb); 1693 break; 1694 1695 case HCI_OP_SET_EVENT_FLT: 1696 hci_cc_set_event_flt(hdev, skb); 1697 break; 1698 1699 case HCI_OP_PIN_CODE_REPLY: 1700 hci_cc_pin_code_reply(hdev, skb); 1701 break; 1702 1703 case HCI_OP_PIN_CODE_NEG_REPLY: 1704 hci_cc_pin_code_neg_reply(hdev, skb); 1705 break; 1706 |
|
1396 default: 1397 BT_DBG("%s opcode 0x%x", hdev->name, opcode); 1398 break; 1399 } 1400 1401 if (ev->ncmd) { 1402 atomic_set(&hdev->cmd_cnt, 1); 1403 if (!skb_queue_empty(&hdev->cmd_q)) --- 50 unchanged lines hidden (view full) --- 1454 case HCI_OP_SNIFF_MODE: 1455 hci_cs_sniff_mode(hdev, ev->status); 1456 break; 1457 1458 case HCI_OP_EXIT_SNIFF_MODE: 1459 hci_cs_exit_sniff_mode(hdev, ev->status); 1460 break; 1461 | 1707 default: 1708 BT_DBG("%s opcode 0x%x", hdev->name, opcode); 1709 break; 1710 } 1711 1712 if (ev->ncmd) { 1713 atomic_set(&hdev->cmd_cnt, 1); 1714 if (!skb_queue_empty(&hdev->cmd_q)) --- 50 unchanged lines hidden (view full) --- 1765 case HCI_OP_SNIFF_MODE: 1766 hci_cs_sniff_mode(hdev, ev->status); 1767 break; 1768 1769 case HCI_OP_EXIT_SNIFF_MODE: 1770 hci_cs_exit_sniff_mode(hdev, ev->status); 1771 break; 1772 |
1773 case HCI_OP_DISCONNECT: 1774 if (ev->status != 0) 1775 mgmt_disconnect_failed(hdev->id); 1776 break; 1777 1778 case HCI_OP_LE_CREATE_CONN: 1779 hci_cs_le_create_conn(hdev, ev->status); 1780 break; 1781 |
|
1462 default: 1463 BT_DBG("%s opcode 0x%x", hdev->name, opcode); 1464 break; 1465 } 1466 1467 if (ev->ncmd) { 1468 atomic_set(&hdev->cmd_cnt, 1); 1469 if (!skb_queue_empty(&hdev->cmd_q)) --- 111 unchanged lines hidden (view full) --- 1581 1582 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); 1583 if (conn && conn->state == BT_CONNECTED) { 1584 hci_conn_hold(conn); 1585 conn->disc_timeout = HCI_PAIRING_TIMEOUT; 1586 hci_conn_put(conn); 1587 } 1588 | 1782 default: 1783 BT_DBG("%s opcode 0x%x", hdev->name, opcode); 1784 break; 1785 } 1786 1787 if (ev->ncmd) { 1788 atomic_set(&hdev->cmd_cnt, 1); 1789 if (!skb_queue_empty(&hdev->cmd_q)) --- 111 unchanged lines hidden (view full) --- 1901 1902 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); 1903 if (conn && conn->state == BT_CONNECTED) { 1904 hci_conn_hold(conn); 1905 conn->disc_timeout = HCI_PAIRING_TIMEOUT; 1906 hci_conn_put(conn); 1907 } 1908 |
1909 if (!test_bit(HCI_PAIRABLE, &hdev->flags)) 1910 hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY, 1911 sizeof(ev->bdaddr), &ev->bdaddr); 1912 1913 if (test_bit(HCI_MGMT, &hdev->flags)) 1914 mgmt_pin_code_request(hdev->id, &ev->bdaddr); 1915 |
|
1589 hci_dev_unlock(hdev); 1590} 1591 1592static inline void hci_link_key_request_evt(struct hci_dev *hdev, struct sk_buff *skb) 1593{ | 1916 hci_dev_unlock(hdev); 1917} 1918 1919static inline void hci_link_key_request_evt(struct hci_dev *hdev, struct sk_buff *skb) 1920{ |
1921 struct hci_ev_link_key_req *ev = (void *) skb->data; 1922 struct hci_cp_link_key_reply cp; 1923 struct hci_conn *conn; 1924 struct link_key *key; 1925 |
|
1594 BT_DBG("%s", hdev->name); | 1926 BT_DBG("%s", hdev->name); |
1927 1928 if (!test_bit(HCI_LINK_KEYS, &hdev->flags)) 1929 return; 1930 1931 hci_dev_lock(hdev); 1932 1933 key = hci_find_link_key(hdev, &ev->bdaddr); 1934 if (!key) { 1935 BT_DBG("%s link key not found for %s", hdev->name, 1936 batostr(&ev->bdaddr)); 1937 goto not_found; 1938 } 1939 1940 BT_DBG("%s found key type %u for %s", hdev->name, key->type, 1941 batostr(&ev->bdaddr)); 1942 1943 if (!test_bit(HCI_DEBUG_KEYS, &hdev->flags) && key->type == 0x03) { 1944 BT_DBG("%s ignoring debug key", hdev->name); 1945 goto not_found; 1946 } 1947 1948 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); 1949 1950 if (key->type == 0x04 && conn && conn->auth_type != 0xff && 1951 (conn->auth_type & 0x01)) { 1952 BT_DBG("%s ignoring unauthenticated key", hdev->name); 1953 goto not_found; 1954 } 1955 1956 bacpy(&cp.bdaddr, &ev->bdaddr); 1957 memcpy(cp.link_key, key->val, 16); 1958 1959 hci_send_cmd(hdev, HCI_OP_LINK_KEY_REPLY, sizeof(cp), &cp); 1960 1961 hci_dev_unlock(hdev); 1962 1963 return; 1964 1965not_found: 1966 hci_send_cmd(hdev, HCI_OP_LINK_KEY_NEG_REPLY, 6, &ev->bdaddr); 1967 hci_dev_unlock(hdev); |
|
1595} 1596 1597static inline void hci_link_key_notify_evt(struct hci_dev *hdev, struct sk_buff *skb) 1598{ 1599 struct hci_ev_link_key_notify *ev = (void *) skb->data; 1600 struct hci_conn *conn; | 1968} 1969 1970static inline void hci_link_key_notify_evt(struct hci_dev *hdev, struct sk_buff *skb) 1971{ 1972 struct hci_ev_link_key_notify *ev = (void *) skb->data; 1973 struct hci_conn *conn; |
1974 u8 pin_len = 0; |
|
1601 1602 BT_DBG("%s", hdev->name); 1603 1604 hci_dev_lock(hdev); 1605 1606 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); 1607 if (conn) { 1608 hci_conn_hold(conn); 1609 conn->disc_timeout = HCI_DISCONN_TIMEOUT; | 1975 1976 BT_DBG("%s", hdev->name); 1977 1978 hci_dev_lock(hdev); 1979 1980 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); 1981 if (conn) { 1982 hci_conn_hold(conn); 1983 conn->disc_timeout = HCI_DISCONN_TIMEOUT; |
1984 pin_len = conn->pin_length; |
|
1610 hci_conn_put(conn); 1611 } 1612 | 1985 hci_conn_put(conn); 1986 } 1987 |
1988 if (test_bit(HCI_LINK_KEYS, &hdev->flags)) 1989 hci_add_link_key(hdev, 1, &ev->bdaddr, ev->link_key, 1990 ev->key_type, pin_len); 1991 |
|
1613 hci_dev_unlock(hdev); 1614} 1615 1616static inline void hci_clock_offset_evt(struct hci_dev *hdev, struct sk_buff *skb) 1617{ 1618 struct hci_ev_clock_offset *ev = (void *) skb->data; 1619 struct hci_conn *conn; 1620 --- 240 unchanged lines hidden (view full) --- 1861 data.ssp_mode = 0x01; 1862 info++; 1863 hci_inquiry_cache_update(hdev, &data); 1864 } 1865 1866 hci_dev_unlock(hdev); 1867} 1868 | 1992 hci_dev_unlock(hdev); 1993} 1994 1995static inline void hci_clock_offset_evt(struct hci_dev *hdev, struct sk_buff *skb) 1996{ 1997 struct hci_ev_clock_offset *ev = (void *) skb->data; 1998 struct hci_conn *conn; 1999 --- 240 unchanged lines hidden (view full) --- 2240 data.ssp_mode = 0x01; 2241 info++; 2242 hci_inquiry_cache_update(hdev, &data); 2243 } 2244 2245 hci_dev_unlock(hdev); 2246} 2247 |
2248static inline u8 hci_get_auth_req(struct hci_conn *conn) 2249{ 2250 /* If remote requests dedicated bonding follow that lead */ 2251 if (conn->remote_auth == 0x02 || conn->remote_auth == 0x03) { 2252 /* If both remote and local IO capabilities allow MITM 2253 * protection then require it, otherwise don't */ 2254 if (conn->remote_cap == 0x03 || conn->io_capability == 0x03) 2255 return 0x02; 2256 else 2257 return 0x03; 2258 } 2259 2260 /* If remote requests no-bonding follow that lead */ 2261 if (conn->remote_auth == 0x00 || conn->remote_auth == 0x01) 2262 return 0x00; 2263 2264 return conn->auth_type; 2265} 2266 |
|
1869static inline void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff *skb) 1870{ 1871 struct hci_ev_io_capa_request *ev = (void *) skb->data; 1872 struct hci_conn *conn; 1873 1874 BT_DBG("%s", hdev->name); 1875 1876 hci_dev_lock(hdev); 1877 1878 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); | 2267static inline void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff *skb) 2268{ 2269 struct hci_ev_io_capa_request *ev = (void *) skb->data; 2270 struct hci_conn *conn; 2271 2272 BT_DBG("%s", hdev->name); 2273 2274 hci_dev_lock(hdev); 2275 2276 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
1879 if (conn) 1880 hci_conn_hold(conn); | 2277 if (!conn) 2278 goto unlock; |
1881 | 2279 |
2280 hci_conn_hold(conn); 2281 2282 if (!test_bit(HCI_MGMT, &hdev->flags)) 2283 goto unlock; 2284 2285 if (test_bit(HCI_PAIRABLE, &hdev->flags) || 2286 (conn->remote_auth & ~0x01) == HCI_AT_NO_BONDING) { 2287 struct hci_cp_io_capability_reply cp; 2288 2289 bacpy(&cp.bdaddr, &ev->bdaddr); 2290 cp.capability = conn->io_capability; 2291 cp.oob_data = 0; 2292 cp.authentication = hci_get_auth_req(conn); 2293 2294 hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_REPLY, 2295 sizeof(cp), &cp); 2296 } else { 2297 struct hci_cp_io_capability_neg_reply cp; 2298 2299 bacpy(&cp.bdaddr, &ev->bdaddr); 2300 cp.reason = 0x16; /* Pairing not allowed */ 2301 2302 hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_NEG_REPLY, 2303 sizeof(cp), &cp); 2304 } 2305 2306unlock: |
|
1882 hci_dev_unlock(hdev); 1883} 1884 | 2307 hci_dev_unlock(hdev); 2308} 2309 |
2310static inline void hci_io_capa_reply_evt(struct hci_dev *hdev, struct sk_buff *skb) 2311{ 2312 struct hci_ev_io_capa_reply *ev = (void *) skb->data; 2313 struct hci_conn *conn; 2314 2315 BT_DBG("%s", hdev->name); 2316 2317 hci_dev_lock(hdev); 2318 2319 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); 2320 if (!conn) 2321 goto unlock; 2322 2323 hci_conn_hold(conn); 2324 2325 conn->remote_cap = ev->capability; 2326 conn->remote_oob = ev->oob_data; 2327 conn->remote_auth = ev->authentication; 2328 2329unlock: 2330 hci_dev_unlock(hdev); 2331} 2332 |
|
1885static inline void hci_simple_pair_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) 1886{ 1887 struct hci_ev_simple_pair_complete *ev = (void *) skb->data; 1888 struct hci_conn *conn; 1889 1890 BT_DBG("%s", hdev->name); 1891 1892 hci_dev_lock(hdev); --- 16 unchanged lines hidden (view full) --- 1909 1910 ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr); 1911 if (ie) 1912 ie->data.ssp_mode = (ev->features[0] & 0x01); 1913 1914 hci_dev_unlock(hdev); 1915} 1916 | 2333static inline void hci_simple_pair_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) 2334{ 2335 struct hci_ev_simple_pair_complete *ev = (void *) skb->data; 2336 struct hci_conn *conn; 2337 2338 BT_DBG("%s", hdev->name); 2339 2340 hci_dev_lock(hdev); --- 16 unchanged lines hidden (view full) --- 2357 2358 ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr); 2359 if (ie) 2360 ie->data.ssp_mode = (ev->features[0] & 0x01); 2361 2362 hci_dev_unlock(hdev); 2363} 2364 |
2365static inline void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) 2366{ 2367 struct hci_ev_le_conn_complete *ev = (void *) skb->data; 2368 struct hci_conn *conn; 2369 2370 BT_DBG("%s status %d", hdev->name, ev->status); 2371 2372 hci_dev_lock(hdev); 2373 2374 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &ev->bdaddr); 2375 if (!conn) 2376 goto unlock; 2377 2378 if (ev->status) { 2379 hci_proto_connect_cfm(conn, ev->status); 2380 conn->state = BT_CLOSED; 2381 hci_conn_del(conn); 2382 goto unlock; 2383 } 2384 2385 conn->handle = __le16_to_cpu(ev->handle); 2386 conn->state = BT_CONNECTED; 2387 2388 hci_conn_hold_device(conn); 2389 hci_conn_add_sysfs(conn); 2390 2391 hci_proto_connect_cfm(conn, ev->status); 2392 2393unlock: 2394 hci_dev_unlock(hdev); 2395} 2396 2397static inline void hci_le_meta_evt(struct hci_dev *hdev, struct sk_buff *skb) 2398{ 2399 struct hci_ev_le_meta *le_ev = (void *) skb->data; 2400 2401 skb_pull(skb, sizeof(*le_ev)); 2402 2403 switch (le_ev->subevent) { 2404 case HCI_EV_LE_CONN_COMPLETE: 2405 hci_le_conn_complete_evt(hdev, skb); 2406 break; 2407 2408 default: 2409 break; 2410 } 2411} 2412 |
|
1917void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb) 1918{ 1919 struct hci_event_hdr *hdr = (void *) skb->data; 1920 __u8 event = hdr->evt; 1921 1922 skb_pull(skb, HCI_EVENT_HDR_SIZE); 1923 1924 switch (event) { --- 112 unchanged lines hidden (view full) --- 2037 case HCI_EV_EXTENDED_INQUIRY_RESULT: 2038 hci_extended_inquiry_result_evt(hdev, skb); 2039 break; 2040 2041 case HCI_EV_IO_CAPA_REQUEST: 2042 hci_io_capa_request_evt(hdev, skb); 2043 break; 2044 | 2413void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb) 2414{ 2415 struct hci_event_hdr *hdr = (void *) skb->data; 2416 __u8 event = hdr->evt; 2417 2418 skb_pull(skb, HCI_EVENT_HDR_SIZE); 2419 2420 switch (event) { --- 112 unchanged lines hidden (view full) --- 2533 case HCI_EV_EXTENDED_INQUIRY_RESULT: 2534 hci_extended_inquiry_result_evt(hdev, skb); 2535 break; 2536 2537 case HCI_EV_IO_CAPA_REQUEST: 2538 hci_io_capa_request_evt(hdev, skb); 2539 break; 2540 |
2541 case HCI_EV_IO_CAPA_REPLY: 2542 hci_io_capa_reply_evt(hdev, skb); 2543 break; 2544 |
|
2045 case HCI_EV_SIMPLE_PAIR_COMPLETE: 2046 hci_simple_pair_complete_evt(hdev, skb); 2047 break; 2048 2049 case HCI_EV_REMOTE_HOST_FEATURES: 2050 hci_remote_host_features_evt(hdev, skb); 2051 break; 2052 | 2545 case HCI_EV_SIMPLE_PAIR_COMPLETE: 2546 hci_simple_pair_complete_evt(hdev, skb); 2547 break; 2548 2549 case HCI_EV_REMOTE_HOST_FEATURES: 2550 hci_remote_host_features_evt(hdev, skb); 2551 break; 2552 |
2553 case HCI_EV_LE_META: 2554 hci_le_meta_evt(hdev, skb); 2555 break; 2556 |
|
2053 default: 2054 BT_DBG("%s event 0x%x", hdev->name, event); 2055 break; 2056 } 2057 2058 kfree_skb(skb); 2059 hdev->stat.evt_rx++; 2060} --- 17 unchanged lines hidden (view full) --- 2078 ev->type = type; 2079 memcpy(ev->data, data, dlen); 2080 2081 bt_cb(skb)->incoming = 1; 2082 __net_timestamp(skb); 2083 2084 bt_cb(skb)->pkt_type = HCI_EVENT_PKT; 2085 skb->dev = (void *) hdev; | 2557 default: 2558 BT_DBG("%s event 0x%x", hdev->name, event); 2559 break; 2560 } 2561 2562 kfree_skb(skb); 2563 hdev->stat.evt_rx++; 2564} --- 17 unchanged lines hidden (view full) --- 2582 ev->type = type; 2583 memcpy(ev->data, data, dlen); 2584 2585 bt_cb(skb)->incoming = 1; 2586 __net_timestamp(skb); 2587 2588 bt_cb(skb)->pkt_type = HCI_EVENT_PKT; 2589 skb->dev = (void *) hdev; |
2086 hci_send_to_sock(hdev, skb); | 2590 hci_send_to_sock(hdev, skb, NULL); |
2087 kfree_skb(skb); 2088} | 2591 kfree_skb(skb); 2592} |