Lines Matching defs:hdev
50 static void *hci_ev_skb_pull(struct hci_dev *hdev, struct sk_buff *skb,
57 bt_dev_err(hdev, "Malformed Event: 0x%2.2x", ev);
62 static void *hci_cc_skb_pull(struct hci_dev *hdev, struct sk_buff *skb,
69 bt_dev_err(hdev, "Malformed Command Complete: 0x%4.4x", op);
74 static void *hci_le_ev_skb_pull(struct hci_dev *hdev, struct sk_buff *skb,
81 bt_dev_err(hdev, "Malformed LE Event: 0x%2.2x", ev);
86 static u8 hci_cc_inquiry_cancel(struct hci_dev *hdev, void *data,
91 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
100 if (rp->status == 0x0c && !test_bit(HCI_INQUIRY, &hdev->flags)) {
101 bt_dev_warn(hdev, "Ignoring error of Inquiry Cancel command");
108 clear_bit(HCI_INQUIRY, &hdev->flags);
110 wake_up_bit(&hdev->flags, HCI_INQUIRY);
112 hci_dev_lock(hdev);
116 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN) ||
117 hdev->le_scan_type != LE_SCAN_ACTIVE)
118 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
119 hci_dev_unlock(hdev);
121 hci_conn_check_pending(hdev);
126 static u8 hci_cc_periodic_inq(struct hci_dev *hdev, void *data,
131 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
136 hci_dev_set_flag(hdev, HCI_PERIODIC_INQ);
141 static u8 hci_cc_exit_periodic_inq(struct hci_dev *hdev, void *data,
146 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
151 hci_dev_clear_flag(hdev, HCI_PERIODIC_INQ);
153 hci_conn_check_pending(hdev);
158 static u8 hci_cc_remote_name_req_cancel(struct hci_dev *hdev, void *data,
163 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
168 static u8 hci_cc_role_discovery(struct hci_dev *hdev, void *data,
174 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
179 hci_dev_lock(hdev);
181 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
185 hci_dev_unlock(hdev);
190 static u8 hci_cc_read_link_policy(struct hci_dev *hdev, void *data,
196 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
201 hci_dev_lock(hdev);
203 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
207 hci_dev_unlock(hdev);
212 static u8 hci_cc_write_link_policy(struct hci_dev *hdev, void *data,
219 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
224 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LINK_POLICY);
228 hci_dev_lock(hdev);
230 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
234 hci_dev_unlock(hdev);
239 static u8 hci_cc_read_def_link_policy(struct hci_dev *hdev, void *data,
244 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
249 hdev->link_policy = __le16_to_cpu(rp->policy);
254 static u8 hci_cc_write_def_link_policy(struct hci_dev *hdev, void *data,
260 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
265 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_DEF_LINK_POLICY);
269 hdev->link_policy = get_unaligned_le16(sent);
274 static u8 hci_cc_reset(struct hci_dev *hdev, void *data, struct sk_buff *skb)
278 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
280 clear_bit(HCI_RESET, &hdev->flags);
286 hci_dev_clear_volatile_flags(hdev);
288 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
290 hdev->inq_tx_power = HCI_TX_POWER_INVALID;
291 hdev->adv_tx_power = HCI_TX_POWER_INVALID;
293 memset(hdev->adv_data, 0, sizeof(hdev->adv_data));
294 hdev->adv_data_len = 0;
296 memset(hdev->scan_rsp_data, 0, sizeof(hdev->scan_rsp_data));
297 hdev->scan_rsp_data_len = 0;
299 hdev->le_scan_type = LE_SCAN_PASSIVE;
301 hdev->ssp_debug_mode = 0;
303 hci_bdaddr_list_clear(&hdev->le_accept_list);
304 hci_bdaddr_list_clear(&hdev->le_resolv_list);
309 static u8 hci_cc_read_stored_link_key(struct hci_dev *hdev, void *data,
315 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
317 sent = hci_sent_cmd_data(hdev, HCI_OP_READ_STORED_LINK_KEY);
322 hdev->stored_max_keys = le16_to_cpu(rp->max_keys);
323 hdev->stored_num_keys = le16_to_cpu(rp->num_keys);
329 static u8 hci_cc_delete_stored_link_key(struct hci_dev *hdev, void *data,
335 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
342 if (num_keys <= hdev->stored_num_keys)
343 hdev->stored_num_keys -= num_keys;
345 hdev->stored_num_keys = 0;
350 static u8 hci_cc_write_local_name(struct hci_dev *hdev, void *data,
356 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
358 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LOCAL_NAME);
362 hci_dev_lock(hdev);
364 if (hci_dev_test_flag(hdev, HCI_MGMT))
365 mgmt_set_local_name_complete(hdev, sent, rp->status);
367 memcpy(hdev->dev_name, sent, HCI_MAX_NAME_LENGTH);
369 hci_dev_unlock(hdev);
374 static u8 hci_cc_read_local_name(struct hci_dev *hdev, void *data,
379 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
384 if (hci_dev_test_flag(hdev, HCI_SETUP) ||
385 hci_dev_test_flag(hdev, HCI_CONFIG))
386 memcpy(hdev->dev_name, rp->name, HCI_MAX_NAME_LENGTH);
391 static u8 hci_cc_write_auth_enable(struct hci_dev *hdev, void *data,
397 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
399 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_AUTH_ENABLE);
403 hci_dev_lock(hdev);
409 set_bit(HCI_AUTH, &hdev->flags);
411 clear_bit(HCI_AUTH, &hdev->flags);
414 if (hci_dev_test_flag(hdev, HCI_MGMT))
415 mgmt_auth_enable_complete(hdev, rp->status);
417 hci_dev_unlock(hdev);
422 static u8 hci_cc_write_encrypt_mode(struct hci_dev *hdev, void *data,
429 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
434 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_ENCRYPT_MODE);
441 set_bit(HCI_ENCRYPT, &hdev->flags);
443 clear_bit(HCI_ENCRYPT, &hdev->flags);
448 static u8 hci_cc_write_scan_enable(struct hci_dev *hdev, void *data,
455 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
457 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SCAN_ENABLE);
463 hci_dev_lock(hdev);
466 hdev->discov_timeout = 0;
471 set_bit(HCI_ISCAN, &hdev->flags);
473 clear_bit(HCI_ISCAN, &hdev->flags);
476 set_bit(HCI_PSCAN, &hdev->flags);
478 clear_bit(HCI_PSCAN, &hdev->flags);
481 hci_dev_unlock(hdev);
486 static u8 hci_cc_set_event_filter(struct hci_dev *hdev, void *data,
493 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
498 sent = hci_sent_cmd_data(hdev, HCI_OP_SET_EVENT_FLT);
505 hci_dev_clear_flag(hdev, HCI_EVENT_FILTER_CONFIGURED);
507 hci_dev_set_flag(hdev, HCI_EVENT_FILTER_CONFIGURED);
512 static u8 hci_cc_read_class_of_dev(struct hci_dev *hdev, void *data,
517 if (WARN_ON(!hdev))
520 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
525 memcpy(hdev->dev_class, rp->dev_class, 3);
527 bt_dev_dbg(hdev, "class 0x%.2x%.2x%.2x", hdev->dev_class[2],
528 hdev->dev_class[1], hdev->dev_class[0]);
533 static u8 hci_cc_write_class_of_dev(struct hci_dev *hdev, void *data,
539 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
541 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_CLASS_OF_DEV);
545 hci_dev_lock(hdev);
548 memcpy(hdev->dev_class, sent, 3);
550 if (hci_dev_test_flag(hdev, HCI_MGMT))
551 mgmt_set_class_of_dev_complete(hdev, sent, rp->status);
553 hci_dev_unlock(hdev);
558 static u8 hci_cc_read_voice_setting(struct hci_dev *hdev, void *data,
564 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
571 if (hdev->voice_setting == setting)
574 hdev->voice_setting = setting;
576 bt_dev_dbg(hdev, "voice setting 0x%4.4x", setting);
578 if (hdev->notify)
579 hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING);
584 static u8 hci_cc_write_voice_setting(struct hci_dev *hdev, void *data,
591 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
596 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_VOICE_SETTING);
602 if (hdev->voice_setting == setting)
605 hdev->voice_setting = setting;
607 bt_dev_dbg(hdev, "voice setting 0x%4.4x", setting);
609 if (hdev->notify)
610 hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING);
615 static u8 hci_cc_read_num_supported_iac(struct hci_dev *hdev, void *data,
620 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
625 hdev->num_iac = rp->num_iac;
627 bt_dev_dbg(hdev, "num iac %d", hdev->num_iac);
632 static u8 hci_cc_write_ssp_mode(struct hci_dev *hdev, void *data,
638 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
640 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SSP_MODE);
644 hci_dev_lock(hdev);
648 hdev->features[1][0] |= LMP_HOST_SSP;
650 hdev->features[1][0] &= ~LMP_HOST_SSP;
655 hci_dev_set_flag(hdev, HCI_SSP_ENABLED);
657 hci_dev_clear_flag(hdev, HCI_SSP_ENABLED);
660 hci_dev_unlock(hdev);
665 static u8 hci_cc_write_sc_support(struct hci_dev *hdev, void *data,
671 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
673 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SC_SUPPORT);
677 hci_dev_lock(hdev);
681 hdev->features[1][0] |= LMP_HOST_SC;
683 hdev->features[1][0] &= ~LMP_HOST_SC;
686 if (!hci_dev_test_flag(hdev, HCI_MGMT) && !rp->status) {
688 hci_dev_set_flag(hdev, HCI_SC_ENABLED);
690 hci_dev_clear_flag(hdev, HCI_SC_ENABLED);
693 hci_dev_unlock(hdev);
698 static u8 hci_cc_read_local_version(struct hci_dev *hdev, void *data,
703 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
708 if (hci_dev_test_flag(hdev, HCI_SETUP) ||
709 hci_dev_test_flag(hdev, HCI_CONFIG)) {
710 hdev->hci_ver = rp->hci_ver;
711 hdev->hci_rev = __le16_to_cpu(rp->hci_rev);
712 hdev->lmp_ver = rp->lmp_ver;
713 hdev->manufacturer = __le16_to_cpu(rp->manufacturer);
714 hdev->lmp_subver = __le16_to_cpu(rp->lmp_subver);
720 static u8 hci_cc_read_enc_key_size(struct hci_dev *hdev, void *data,
728 bt_dev_dbg(hdev, "status 0x%2.2x", status);
732 hci_dev_lock(hdev);
734 conn = hci_conn_hash_lookup_handle(hdev, handle);
745 bt_dev_err(hdev, "failed to read key size for handle %u",
752 if (conn->enc_key_size < hdev->min_enc_key_size) {
770 hci_dev_unlock(hdev);
775 static u8 hci_cc_read_local_commands(struct hci_dev *hdev, void *data,
780 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
785 if (hci_dev_test_flag(hdev, HCI_SETUP) ||
786 hci_dev_test_flag(hdev, HCI_CONFIG))
787 memcpy(hdev->commands, rp->commands, sizeof(hdev->commands));
792 static u8 hci_cc_read_auth_payload_timeout(struct hci_dev *hdev, void *data,
798 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
803 hci_dev_lock(hdev);
805 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
809 hci_dev_unlock(hdev);
814 static u8 hci_cc_write_auth_payload_timeout(struct hci_dev *hdev, void *data,
821 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
823 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_AUTH_PAYLOAD_TO);
827 hci_dev_lock(hdev);
829 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
839 hci_dev_unlock(hdev);
844 static u8 hci_cc_read_local_features(struct hci_dev *hdev, void *data,
849 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
854 memcpy(hdev->features, rp->features, 8);
859 if (hdev->features[0][0] & LMP_3SLOT)
860 hdev->pkt_type |= (HCI_DM3 | HCI_DH3);
862 if (hdev->features[0][0] & LMP_5SLOT)
863 hdev->pkt_type |= (HCI_DM5 | HCI_DH5);
865 if (hdev->features[0][1] & LMP_HV2) {
866 hdev->pkt_type |= (HCI_HV2);
867 hdev->esco_type |= (ESCO_HV2);
870 if (hdev->features[0][1] & LMP_HV3) {
871 hdev->pkt_type |= (HCI_HV3);
872 hdev->esco_type |= (ESCO_HV3);
875 if (lmp_esco_capable(hdev))
876 hdev->esco_type |= (ESCO_EV3);
878 if (hdev->features[0][4] & LMP_EV4)
879 hdev->esco_type |= (ESCO_EV4);
881 if (hdev->features[0][4] & LMP_EV5)
882 hdev->esco_type |= (ESCO_EV5);
884 if (hdev->features[0][5] & LMP_EDR_ESCO_2M)
885 hdev->esco_type |= (ESCO_2EV3);
887 if (hdev->features[0][5] & LMP_EDR_ESCO_3M)
888 hdev->esco_type |= (ESCO_3EV3);
890 if (hdev->features[0][5] & LMP_EDR_3S_ESCO)
891 hdev->esco_type |= (ESCO_2EV5 | ESCO_3EV5);
896 static u8 hci_cc_read_local_ext_features(struct hci_dev *hdev, void *data,
901 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
906 if (hdev->max_page < rp->max_page) {
908 &hdev->quirks))
909 bt_dev_warn(hdev, "broken local ext features page 2");
911 hdev->max_page = rp->max_page;
915 memcpy(hdev->features[rp->page], rp->features, 8);
920 static u8 hci_cc_read_flow_control_mode(struct hci_dev *hdev, void *data,
925 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
930 hdev->flow_ctl_mode = rp->mode;
935 static u8 hci_cc_read_buffer_size(struct hci_dev *hdev, void *data,
940 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
945 hdev->acl_mtu = __le16_to_cpu(rp->acl_mtu);
946 hdev->sco_mtu = rp->sco_mtu;
947 hdev->acl_pkts = __le16_to_cpu(rp->acl_max_pkt);
948 hdev->sco_pkts = __le16_to_cpu(rp->sco_max_pkt);
950 if (test_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks)) {
951 hdev->sco_mtu = 64;
952 hdev->sco_pkts = 8;
955 hdev->acl_cnt = hdev->acl_pkts;
956 hdev->sco_cnt = hdev->sco_pkts;
958 BT_DBG("%s acl mtu %d:%d sco mtu %d:%d", hdev->name, hdev->acl_mtu,
959 hdev->acl_pkts, hdev->sco_mtu, hdev->sco_pkts);
964 static u8 hci_cc_read_bd_addr(struct hci_dev *hdev, void *data,
969 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
974 if (test_bit(HCI_INIT, &hdev->flags))
975 bacpy(&hdev->bdaddr, &rp->bdaddr);
977 if (hci_dev_test_flag(hdev, HCI_SETUP))
978 bacpy(&hdev->setup_addr, &rp->bdaddr);
983 static u8 hci_cc_read_local_pairing_opts(struct hci_dev *hdev, void *data,
988 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
993 if (hci_dev_test_flag(hdev, HCI_SETUP) ||
994 hci_dev_test_flag(hdev, HCI_CONFIG)) {
995 hdev->pairing_opts = rp->pairing_opts;
996 hdev->max_enc_key_size = rp->max_key_size;
1002 static u8 hci_cc_read_page_scan_activity(struct hci_dev *hdev, void *data,
1007 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1012 if (test_bit(HCI_INIT, &hdev->flags)) {
1013 hdev->page_scan_interval = __le16_to_cpu(rp->interval);
1014 hdev->page_scan_window = __le16_to_cpu(rp->window);
1020 static u8 hci_cc_write_page_scan_activity(struct hci_dev *hdev, void *data,
1026 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1031 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_PAGE_SCAN_ACTIVITY);
1035 hdev->page_scan_interval = __le16_to_cpu(sent->interval);
1036 hdev->page_scan_window = __le16_to_cpu(sent->window);
1041 static u8 hci_cc_read_page_scan_type(struct hci_dev *hdev, void *data,
1046 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1051 if (test_bit(HCI_INIT, &hdev->flags))
1052 hdev->page_scan_type = rp->type;
1057 static u8 hci_cc_write_page_scan_type(struct hci_dev *hdev, void *data,
1063 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1068 type = hci_sent_cmd_data(hdev, HCI_OP_WRITE_PAGE_SCAN_TYPE);
1070 hdev->page_scan_type = *type;
1075 static u8 hci_cc_read_data_block_size(struct hci_dev *hdev, void *data,
1080 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1085 hdev->block_mtu = __le16_to_cpu(rp->max_acl_len);
1086 hdev->block_len = __le16_to_cpu(rp->block_len);
1087 hdev->num_blocks = __le16_to_cpu(rp->num_blocks);
1089 hdev->block_cnt = hdev->num_blocks;
1091 BT_DBG("%s blk mtu %d cnt %d len %d", hdev->name, hdev->block_mtu,
1092 hdev->block_cnt, hdev->block_len);
1097 static u8 hci_cc_read_clock(struct hci_dev *hdev, void *data,
1104 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1109 hci_dev_lock(hdev);
1111 cp = hci_sent_cmd_data(hdev, HCI_OP_READ_CLOCK);
1116 hdev->clock = le32_to_cpu(rp->clock);
1120 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
1127 hci_dev_unlock(hdev);
1131 static u8 hci_cc_read_local_amp_info(struct hci_dev *hdev, void *data,
1136 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1141 hdev->amp_status = rp->amp_status;
1142 hdev->amp_total_bw = __le32_to_cpu(rp->total_bw);
1143 hdev->amp_max_bw = __le32_to_cpu(rp->max_bw);
1144 hdev->amp_min_latency = __le32_to_cpu(rp->min_latency);
1145 hdev->amp_max_pdu = __le32_to_cpu(rp->max_pdu);
1146 hdev->amp_type = rp->amp_type;
1147 hdev->amp_pal_cap = __le16_to_cpu(rp->pal_cap);
1148 hdev->amp_assoc_size = __le16_to_cpu(rp->max_assoc_size);
1149 hdev->amp_be_flush_to = __le32_to_cpu(rp->be_flush_to);
1150 hdev->amp_max_flush_to = __le32_to_cpu(rp->max_flush_to);
1155 static u8 hci_cc_read_inq_rsp_tx_power(struct hci_dev *hdev, void *data,
1160 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1165 hdev->inq_tx_power = rp->tx_power;
1170 static u8 hci_cc_read_def_err_data_reporting(struct hci_dev *hdev, void *data,
1175 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1180 hdev->err_data_reporting = rp->err_data_reporting;
1185 static u8 hci_cc_write_def_err_data_reporting(struct hci_dev *hdev, void *data,
1191 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1196 cp = hci_sent_cmd_data(hdev, HCI_OP_WRITE_DEF_ERR_DATA_REPORTING);
1200 hdev->err_data_reporting = cp->err_data_reporting;
1205 static u8 hci_cc_pin_code_reply(struct hci_dev *hdev, void *data,
1212 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1214 hci_dev_lock(hdev);
1216 if (hci_dev_test_flag(hdev, HCI_MGMT))
1217 mgmt_pin_code_reply_complete(hdev, &rp->bdaddr, rp->status);
1222 cp = hci_sent_cmd_data(hdev, HCI_OP_PIN_CODE_REPLY);
1226 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
1231 hci_dev_unlock(hdev);
1235 static u8 hci_cc_pin_code_neg_reply(struct hci_dev *hdev, void *data,
1240 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1242 hci_dev_lock(hdev);
1244 if (hci_dev_test_flag(hdev, HCI_MGMT))
1245 mgmt_pin_code_neg_reply_complete(hdev, &rp->bdaddr,
1248 hci_dev_unlock(hdev);
1253 static u8 hci_cc_le_read_buffer_size(struct hci_dev *hdev, void *data,
1258 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1263 hdev->le_mtu = __le16_to_cpu(rp->le_mtu);
1264 hdev->le_pkts = rp->le_max_pkt;
1266 hdev->le_cnt = hdev->le_pkts;
1268 BT_DBG("%s le mtu %d:%d", hdev->name, hdev->le_mtu, hdev->le_pkts);
1273 static u8 hci_cc_le_read_local_features(struct hci_dev *hdev, void *data,
1278 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
1283 memcpy(hdev->le_features, rp->features, 8);
1288 static u8 hci_cc_le_read_adv_tx_power(struct hci_dev *hdev, void *data,
1293 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1298 hdev->adv_tx_power = rp->tx_power;
1303 static u8 hci_cc_user_confirm_reply(struct hci_dev *hdev, void *data,
1308 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1310 hci_dev_lock(hdev);
1312 if (hci_dev_test_flag(hdev, HCI_MGMT))
1313 mgmt_user_confirm_reply_complete(hdev, &rp->bdaddr, ACL_LINK, 0,
1316 hci_dev_unlock(hdev);
1321 static u8 hci_cc_user_confirm_neg_reply(struct hci_dev *hdev, void *data,
1326 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1328 hci_dev_lock(hdev);
1330 if (hci_dev_test_flag(hdev, HCI_MGMT))
1331 mgmt_user_confirm_neg_reply_complete(hdev, &rp->bdaddr,
1334 hci_dev_unlock(hdev);
1339 static u8 hci_cc_user_passkey_reply(struct hci_dev *hdev, void *data,
1344 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1346 hci_dev_lock(hdev);
1348 if (hci_dev_test_flag(hdev, HCI_MGMT))
1349 mgmt_user_passkey_reply_complete(hdev, &rp->bdaddr, ACL_LINK,
1352 hci_dev_unlock(hdev);
1357 static u8 hci_cc_user_passkey_neg_reply(struct hci_dev *hdev, void *data,
1362 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1364 hci_dev_lock(hdev);
1366 if (hci_dev_test_flag(hdev, HCI_MGMT))
1367 mgmt_user_passkey_neg_reply_complete(hdev, &rp->bdaddr,
1370 hci_dev_unlock(hdev);
1375 static u8 hci_cc_read_local_oob_data(struct hci_dev *hdev, void *data,
1380 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1385 static u8 hci_cc_read_local_oob_ext_data(struct hci_dev *hdev, void *data,
1390 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1395 static u8 hci_cc_le_set_random_addr(struct hci_dev *hdev, void *data,
1401 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1406 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_RANDOM_ADDR);
1410 hci_dev_lock(hdev);
1412 bacpy(&hdev->random_addr, sent);
1414 if (!bacmp(&hdev->rpa, sent)) {
1415 hci_dev_clear_flag(hdev, HCI_RPA_EXPIRED);
1416 queue_delayed_work(hdev->workqueue, &hdev->rpa_expired,
1417 secs_to_jiffies(hdev->rpa_timeout));
1420 hci_dev_unlock(hdev);
1425 static u8 hci_cc_le_set_default_phy(struct hci_dev *hdev, void *data,
1431 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1436 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_DEFAULT_PHY);
1440 hci_dev_lock(hdev);
1442 hdev->le_tx_def_phys = cp->tx_phys;
1443 hdev->le_rx_def_phys = cp->rx_phys;
1445 hci_dev_unlock(hdev);
1450 static u8 hci_cc_le_set_adv_set_random_addr(struct hci_dev *hdev, void *data,
1457 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1462 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADV_SET_RAND_ADDR);
1470 hci_dev_lock(hdev);
1472 adv = hci_find_adv_instance(hdev, cp->handle);
1475 if (!bacmp(&hdev->rpa, &cp->bdaddr)) {
1477 queue_delayed_work(hdev->workqueue,
1479 secs_to_jiffies(hdev->rpa_timeout));
1483 hci_dev_unlock(hdev);
1488 static u8 hci_cc_le_remove_adv_set(struct hci_dev *hdev, void *data,
1495 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1500 instance = hci_sent_cmd_data(hdev, HCI_OP_LE_REMOVE_ADV_SET);
1504 hci_dev_lock(hdev);
1506 err = hci_remove_adv_instance(hdev, *instance);
1508 mgmt_advertising_removed(hci_skb_sk(hdev->sent_cmd), hdev,
1511 hci_dev_unlock(hdev);
1516 static u8 hci_cc_le_clear_adv_sets(struct hci_dev *hdev, void *data,
1523 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1528 if (!hci_sent_cmd_data(hdev, HCI_OP_LE_CLEAR_ADV_SETS))
1531 hci_dev_lock(hdev);
1533 list_for_each_entry_safe(adv, n, &hdev->adv_instances, list) {
1536 err = hci_remove_adv_instance(hdev, instance);
1538 mgmt_advertising_removed(hci_skb_sk(hdev->sent_cmd),
1539 hdev, instance);
1542 hci_dev_unlock(hdev);
1547 static u8 hci_cc_le_read_transmit_power(struct hci_dev *hdev, void *data,
1552 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1557 hdev->min_le_tx_power = rp->min_le_tx_power;
1558 hdev->max_le_tx_power = rp->max_le_tx_power;
1563 static u8 hci_cc_le_set_privacy_mode(struct hci_dev *hdev, void *data,
1570 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1575 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_PRIVACY_MODE);
1579 hci_dev_lock(hdev);
1581 params = hci_conn_params_lookup(hdev, &cp->bdaddr, cp->bdaddr_type);
1585 hci_dev_unlock(hdev);
1590 static u8 hci_cc_le_set_adv_enable(struct hci_dev *hdev, void *data,
1596 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1601 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADV_ENABLE);
1605 hci_dev_lock(hdev);
1613 hci_dev_set_flag(hdev, HCI_LE_ADV);
1615 conn = hci_lookup_le_connect(hdev);
1617 queue_delayed_work(hdev->workqueue,
1621 hci_dev_clear_flag(hdev, HCI_LE_ADV);
1624 hci_dev_unlock(hdev);
1629 static u8 hci_cc_le_set_ext_adv_enable(struct hci_dev *hdev, void *data,
1637 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1642 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_ADV_ENABLE);
1648 hci_dev_lock(hdev);
1651 adv = hci_find_adv_instance(hdev, set->handle);
1656 hci_dev_set_flag(hdev, HCI_LE_ADV);
1661 conn = hci_lookup_le_connect(hdev);
1663 queue_delayed_work(hdev->workqueue,
1674 list_for_each_entry_safe(adv, n, &hdev->adv_instances,
1681 list_for_each_entry_safe(adv, n, &hdev->adv_instances,
1686 hci_dev_clear_flag(hdev, HCI_LE_ADV);
1690 hci_dev_unlock(hdev);
1694 static u8 hci_cc_le_set_scan_param(struct hci_dev *hdev, void *data,
1700 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1705 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_SCAN_PARAM);
1709 hci_dev_lock(hdev);
1711 hdev->le_scan_type = cp->type;
1713 hci_dev_unlock(hdev);
1718 static u8 hci_cc_le_set_ext_scan_param(struct hci_dev *hdev, void *data,
1725 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1730 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_SCAN_PARAMS);
1736 hci_dev_lock(hdev);
1738 hdev->le_scan_type = phy_param->type;
1740 hci_dev_unlock(hdev);
1745 static bool has_pending_adv_report(struct hci_dev *hdev)
1747 struct discovery_state *d = &hdev->discovery;
1752 static void clear_pending_adv_report(struct hci_dev *hdev)
1754 struct discovery_state *d = &hdev->discovery;
1760 static void store_pending_adv_report(struct hci_dev *hdev, bdaddr_t *bdaddr,
1764 struct discovery_state *d = &hdev->discovery;
1766 if (len > max_adv_len(hdev))
1777 static void le_set_scan_enable_complete(struct hci_dev *hdev, u8 enable)
1779 hci_dev_lock(hdev);
1783 hci_dev_set_flag(hdev, HCI_LE_SCAN);
1784 if (hdev->le_scan_type == LE_SCAN_ACTIVE)
1785 clear_pending_adv_report(hdev);
1786 if (hci_dev_test_flag(hdev, HCI_MESH))
1787 hci_discovery_set_state(hdev, DISCOVERY_FINDING);
1795 if (has_pending_adv_report(hdev)) {
1796 struct discovery_state *d = &hdev->discovery;
1798 mgmt_device_found(hdev, &d->last_adv_addr, LE_LINK,
1808 cancel_delayed_work(&hdev->le_scan_disable);
1810 hci_dev_clear_flag(hdev, HCI_LE_SCAN);
1816 if (hci_dev_test_and_clear_flag(hdev, HCI_LE_SCAN_INTERRUPTED))
1817 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
1818 else if (!hci_dev_test_flag(hdev, HCI_LE_ADV) &&
1819 hdev->discovery.state == DISCOVERY_FINDING)
1820 queue_work(hdev->workqueue, &hdev->reenable_adv_work);
1825 bt_dev_err(hdev, "use of reserved LE_Scan_Enable param %d",
1830 hci_dev_unlock(hdev);
1833 static u8 hci_cc_le_set_scan_enable(struct hci_dev *hdev, void *data,
1839 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1844 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_SCAN_ENABLE);
1848 le_set_scan_enable_complete(hdev, cp->enable);
1853 static u8 hci_cc_le_set_ext_scan_enable(struct hci_dev *hdev, void *data,
1859 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1864 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_SCAN_ENABLE);
1868 le_set_scan_enable_complete(hdev, cp->enable);
1873 static u8 hci_cc_le_read_num_adv_sets(struct hci_dev *hdev, void *data,
1878 bt_dev_dbg(hdev, "status 0x%2.2x No of Adv sets %u", rp->status,
1884 hdev->le_num_of_adv_sets = rp->num_of_sets;
1889 static u8 hci_cc_le_read_accept_list_size(struct hci_dev *hdev, void *data,
1894 bt_dev_dbg(hdev, "status 0x%2.2x size %u", rp->status, rp->size);
1899 hdev->le_accept_list_size = rp->size;
1904 static u8 hci_cc_le_clear_accept_list(struct hci_dev *hdev, void *data,
1909 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1914 hci_dev_lock(hdev);
1915 hci_bdaddr_list_clear(&hdev->le_accept_list);
1916 hci_dev_unlock(hdev);
1921 static u8 hci_cc_le_add_to_accept_list(struct hci_dev *hdev, void *data,
1927 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1932 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_ADD_TO_ACCEPT_LIST);
1936 hci_dev_lock(hdev);
1937 hci_bdaddr_list_add(&hdev->le_accept_list, &sent->bdaddr,
1939 hci_dev_unlock(hdev);
1944 static u8 hci_cc_le_del_from_accept_list(struct hci_dev *hdev, void *data,
1950 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1955 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_DEL_FROM_ACCEPT_LIST);
1959 hci_dev_lock(hdev);
1960 hci_bdaddr_list_del(&hdev->le_accept_list, &sent->bdaddr,
1962 hci_dev_unlock(hdev);
1967 static u8 hci_cc_le_read_supported_states(struct hci_dev *hdev, void *data,
1972 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1977 memcpy(hdev->le_states, rp->le_states, 8);
1982 static u8 hci_cc_le_read_def_data_len(struct hci_dev *hdev, void *data,
1987 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1992 hdev->le_def_tx_len = le16_to_cpu(rp->tx_len);
1993 hdev->le_def_tx_time = le16_to_cpu(rp->tx_time);
1998 static u8 hci_cc_le_write_def_data_len(struct hci_dev *hdev, void *data,
2004 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
2009 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_WRITE_DEF_DATA_LEN);
2013 hdev->le_def_tx_len = le16_to_cpu(sent->tx_len);
2014 hdev->le_def_tx_time = le16_to_cpu(sent->tx_time);
2019 static u8 hci_cc_le_add_to_resolv_list(struct hci_dev *hdev, void *data,
2025 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
2030 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_ADD_TO_RESOLV_LIST);
2034 hci_dev_lock(hdev);
2035 hci_bdaddr_list_add_with_irk(&hdev->le_resolv_list, &sent->bdaddr,
2038 hci_dev_unlock(hdev);
2043 static u8 hci_cc_le_del_from_resolv_list(struct hci_dev *hdev, void *data,
2049 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
2054 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_DEL_FROM_RESOLV_LIST);
2058 hci_dev_lock(hdev);
2059 hci_bdaddr_list_del_with_irk(&hdev->le_resolv_list, &sent->bdaddr,
2061 hci_dev_unlock(hdev);
2066 static u8 hci_cc_le_clear_resolv_list(struct hci_dev *hdev, void *data,
2071 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
2076 hci_dev_lock(hdev);
2077 hci_bdaddr_list_clear(&hdev->le_resolv_list);
2078 hci_dev_unlock(hdev);
2083 static u8 hci_cc_le_read_resolv_list_size(struct hci_dev *hdev, void *data,
2088 bt_dev_dbg(hdev, "status 0x%2.2x size %u", rp->status, rp->size);
2093 hdev->le_resolv_list_size = rp->size;
2098 static u8 hci_cc_le_set_addr_resolution_enable(struct hci_dev *hdev, void *data,
2104 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
2109 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE);
2113 hci_dev_lock(hdev);
2116 hci_dev_set_flag(hdev, HCI_LL_RPA_RESOLUTION);
2118 hci_dev_clear_flag(hdev, HCI_LL_RPA_RESOLUTION);
2120 hci_dev_unlock(hdev);
2125 static u8 hci_cc_le_read_max_data_len(struct hci_dev *hdev, void *data,
2130 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
2135 hdev->le_max_tx_len = le16_to_cpu(rp->tx_len);
2136 hdev->le_max_tx_time = le16_to_cpu(rp->tx_time);
2137 hdev->le_max_rx_len = le16_to_cpu(rp->rx_len);
2138 hdev->le_max_rx_time = le16_to_cpu(rp->rx_time);
2143 static u8 hci_cc_write_le_host_supported(struct hci_dev *hdev, void *data,
2149 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
2154 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED);
2158 hci_dev_lock(hdev);
2161 hdev->features[1][0] |= LMP_HOST_LE;
2162 hci_dev_set_flag(hdev, HCI_LE_ENABLED);
2164 hdev->features[1][0] &= ~LMP_HOST_LE;
2165 hci_dev_clear_flag(hdev, HCI_LE_ENABLED);
2166 hci_dev_clear_flag(hdev, HCI_ADVERTISING);
2170 hdev->features[1][0] |= LMP_HOST_LE_BREDR;
2172 hdev->features[1][0] &= ~LMP_HOST_LE_BREDR;
2174 hci_dev_unlock(hdev);
2179 static u8 hci_cc_set_adv_param(struct hci_dev *hdev, void *data,
2185 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
2190 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADV_PARAM);
2194 hci_dev_lock(hdev);
2195 hdev->adv_addr_type = cp->own_address_type;
2196 hci_dev_unlock(hdev);
2201 static u8 hci_cc_set_ext_adv_param(struct hci_dev *hdev, void *data,
2208 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
2213 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_ADV_PARAMS);
2217 hci_dev_lock(hdev);
2218 hdev->adv_addr_type = cp->own_addr_type;
2220 /* Store in hdev for instance 0 */
2221 hdev->adv_tx_power = rp->tx_power;
2223 adv_instance = hci_find_adv_instance(hdev, cp->handle);
2228 hci_update_adv_data(hdev, cp->handle);
2230 hci_dev_unlock(hdev);
2235 static u8 hci_cc_read_rssi(struct hci_dev *hdev, void *data,
2241 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
2246 hci_dev_lock(hdev);
2248 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
2252 hci_dev_unlock(hdev);
2257 static u8 hci_cc_read_tx_power(struct hci_dev *hdev, void *data,
2264 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
2269 sent = hci_sent_cmd_data(hdev, HCI_OP_READ_TX_POWER);
2273 hci_dev_lock(hdev);
2275 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
2289 hci_dev_unlock(hdev);
2293 static u8 hci_cc_write_ssp_debug_mode(struct hci_dev *hdev, void *data,
2299 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
2304 mode = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SSP_DEBUG_MODE);
2306 hdev->ssp_debug_mode = *mode;
2311 static void hci_cs_inquiry(struct hci_dev *hdev, __u8 status)
2313 bt_dev_dbg(hdev, "status 0x%2.2x", status);
2316 hci_conn_check_pending(hdev);
2320 if (hci_sent_cmd_data(hdev, HCI_OP_INQUIRY))
2321 set_bit(HCI_INQUIRY, &hdev->flags);
2324 static void hci_cs_create_conn(struct hci_dev *hdev, __u8 status)
2329 bt_dev_dbg(hdev, "status 0x%2.2x", status);
2331 cp = hci_sent_cmd_data(hdev, HCI_OP_CREATE_CONN);
2335 hci_dev_lock(hdev);
2337 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
2339 bt_dev_dbg(hdev, "bdaddr %pMR hcon %p", &cp->bdaddr, conn);
2352 conn = hci_conn_add_unset(hdev, ACL_LINK, &cp->bdaddr,
2355 bt_dev_err(hdev, "no memory for new connection");
2359 hci_dev_unlock(hdev);
2362 static void hci_cs_add_sco(struct hci_dev *hdev, __u8 status)
2369 bt_dev_dbg(hdev, "status 0x%2.2x", status);
2374 cp = hci_sent_cmd_data(hdev, HCI_OP_ADD_SCO);
2380 bt_dev_dbg(hdev, "handle 0x%4.4x", handle);
2382 hci_dev_lock(hdev);
2384 acl = hci_conn_hash_lookup_handle(hdev, handle);
2396 hci_dev_unlock(hdev);
2399 static void hci_cs_auth_requested(struct hci_dev *hdev, __u8 status)
2404 bt_dev_dbg(hdev, "status 0x%2.2x", status);
2409 cp = hci_sent_cmd_data(hdev, HCI_OP_AUTH_REQUESTED);
2413 hci_dev_lock(hdev);
2415 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
2423 hci_dev_unlock(hdev);
2426 static void hci_cs_set_conn_encrypt(struct hci_dev *hdev, __u8 status)
2431 bt_dev_dbg(hdev, "status 0x%2.2x", status);
2436 cp = hci_sent_cmd_data(hdev, HCI_OP_SET_CONN_ENCRYPT);
2440 hci_dev_lock(hdev);
2442 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
2450 hci_dev_unlock(hdev);
2453 static int hci_outgoing_auth_needed(struct hci_dev *hdev,
2475 static int hci_resolve_name(struct hci_dev *hdev,
2487 return hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp);
2490 static bool hci_resolve_next_name(struct hci_dev *hdev)
2492 struct discovery_state *discov = &hdev->discovery;
2500 bt_dev_warn_ratelimited(hdev, "Name resolve takes too long.");
2504 e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, NAME_NEEDED);
2508 if (hci_resolve_name(hdev, e) == 0) {
2516 static void hci_check_pending_name(struct hci_dev *hdev, struct hci_conn *conn,
2519 struct discovery_state *discov = &hdev->discovery;
2528 mgmt_device_connected(hdev, conn, name, name_len);
2539 e = hci_inquiry_cache_lookup_resolve(hdev, bdaddr, NAME_PENDING);
2550 mgmt_remote_name(hdev, bdaddr, ACL_LINK, 0x00, e->data.rssi,
2553 if (hci_resolve_next_name(hdev))
2557 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
2560 static void hci_cs_remote_name_req(struct hci_dev *hdev, __u8 status)
2565 bt_dev_dbg(hdev, "status 0x%2.2x", status);
2572 cp = hci_sent_cmd_data(hdev, HCI_OP_REMOTE_NAME_REQ);
2576 hci_dev_lock(hdev);
2578 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
2580 if (hci_dev_test_flag(hdev, HCI_MGMT))
2581 hci_check_pending_name(hdev, conn, &cp->bdaddr, NULL, 0);
2586 if (!hci_outgoing_auth_needed(hdev, conn))
2595 hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED,
2600 hci_dev_unlock(hdev);
2603 static void hci_cs_read_remote_features(struct hci_dev *hdev, __u8 status)
2608 bt_dev_dbg(hdev, "status 0x%2.2x", status);
2613 cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_FEATURES);
2617 hci_dev_lock(hdev);
2619 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
2627 hci_dev_unlock(hdev);
2630 static void hci_cs_read_remote_ext_features(struct hci_dev *hdev, __u8 status)
2635 bt_dev_dbg(hdev, "status 0x%2.2x", status);
2640 cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES);
2644 hci_dev_lock(hdev);
2646 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
2654 hci_dev_unlock(hdev);
2657 static void hci_setup_sync_conn_status(struct hci_dev *hdev, __u16 handle,
2663 bt_dev_dbg(hdev, "handle 0x%4.4x status 0x%2.2x", handle, status);
2665 hci_dev_lock(hdev);
2667 acl = hci_conn_hash_lookup_handle(hdev, handle);
2679 hci_dev_unlock(hdev);
2682 static void hci_cs_setup_sync_conn(struct hci_dev *hdev, __u8 status)
2686 bt_dev_dbg(hdev, "status 0x%2.2x", status);
2691 cp = hci_sent_cmd_data(hdev, HCI_OP_SETUP_SYNC_CONN);
2695 hci_setup_sync_conn_status(hdev, __le16_to_cpu(cp->handle), status);
2698 static void hci_cs_enhanced_setup_sync_conn(struct hci_dev *hdev, __u8 status)
2702 bt_dev_dbg(hdev, "status 0x%2.2x", status);
2707 cp = hci_sent_cmd_data(hdev, HCI_OP_ENHANCED_SETUP_SYNC_CONN);
2711 hci_setup_sync_conn_status(hdev, __le16_to_cpu(cp->handle), status);
2714 static void hci_cs_sniff_mode(struct hci_dev *hdev, __u8 status)
2719 bt_dev_dbg(hdev, "status 0x%2.2x", status);
2724 cp = hci_sent_cmd_data(hdev, HCI_OP_SNIFF_MODE);
2728 hci_dev_lock(hdev);
2730 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
2738 hci_dev_unlock(hdev);
2741 static void hci_cs_exit_sniff_mode(struct hci_dev *hdev, __u8 status)
2746 bt_dev_dbg(hdev, "status 0x%2.2x", status);
2751 cp = hci_sent_cmd_data(hdev, HCI_OP_EXIT_SNIFF_MODE);
2755 hci_dev_lock(hdev);
2757 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
2765 hci_dev_unlock(hdev);
2768 static void hci_cs_disconnect(struct hci_dev *hdev, u8 status)
2775 bt_dev_dbg(hdev, "status 0x%2.2x", status);
2780 if (!status && !hdev->suspended)
2783 cp = hci_sent_cmd_data(hdev, HCI_OP_DISCONNECT);
2787 hci_dev_lock(hdev);
2789 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
2794 mgmt_disconnect_failed(hdev, &conn->dst, conn->type,
2798 hdev->cur_adv_instance = conn->adv_instance;
2799 hci_enable_advertising(hdev);
2812 hci_remove_link_key(hdev, &conn->dst);
2815 params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type);
2826 hci_pend_le_list_add(params, &hdev->pend_le_conns);
2834 mgmt_device_disconnected(hdev, &conn->dst, conn->type, conn->dst_type,
2847 hci_dev_unlock(hdev);
2850 static u8 ev_bdaddr_type(struct hci_dev *hdev, u8 type, bool *resolved)
2872 static void cs_le_create_conn(struct hci_dev *hdev, bdaddr_t *peer_addr,
2878 conn = hci_conn_hash_lookup_le(hdev, peer_addr,
2883 own_address_type = ev_bdaddr_type(hdev, own_address_type, NULL);
2891 bacpy(&conn->init_addr, &hdev->random_addr);
2893 bacpy(&conn->init_addr, &hdev->bdaddr);
2899 static void hci_cs_le_create_conn(struct hci_dev *hdev, u8 status)
2903 bt_dev_dbg(hdev, "status 0x%2.2x", status);
2912 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_CREATE_CONN);
2916 hci_dev_lock(hdev);
2918 cs_le_create_conn(hdev, &cp->peer_addr, cp->peer_addr_type,
2921 hci_dev_unlock(hdev);
2924 static void hci_cs_le_ext_create_conn(struct hci_dev *hdev, u8 status)
2928 bt_dev_dbg(hdev, "status 0x%2.2x", status);
2937 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_EXT_CREATE_CONN);
2941 hci_dev_lock(hdev);
2943 cs_le_create_conn(hdev, &cp->peer_addr, cp->peer_addr_type,
2946 hci_dev_unlock(hdev);
2949 static void hci_cs_le_read_remote_features(struct hci_dev *hdev, u8 status)
2954 bt_dev_dbg(hdev, "status 0x%2.2x", status);
2959 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_READ_REMOTE_FEATURES);
2963 hci_dev_lock(hdev);
2965 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
2973 hci_dev_unlock(hdev);
2976 static void hci_cs_le_start_enc(struct hci_dev *hdev, u8 status)
2981 bt_dev_dbg(hdev, "status 0x%2.2x", status);
2986 hci_dev_lock(hdev);
2988 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_START_ENC);
2992 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
3003 hci_dev_unlock(hdev);
3006 static void hci_cs_switch_role(struct hci_dev *hdev, u8 status)
3011 BT_DBG("%s status 0x%2.2x", hdev->name, status);
3016 cp = hci_sent_cmd_data(hdev, HCI_OP_SWITCH_ROLE);
3020 hci_dev_lock(hdev);
3022 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
3026 hci_dev_unlock(hdev);
3029 static void hci_inquiry_complete_evt(struct hci_dev *hdev, void *data,
3033 struct discovery_state *discov = &hdev->discovery;
3036 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
3038 hci_conn_check_pending(hdev);
3040 if (!test_and_clear_bit(HCI_INQUIRY, &hdev->flags))
3044 wake_up_bit(&hdev->flags, HCI_INQUIRY);
3046 if (!hci_dev_test_flag(hdev, HCI_MGMT))
3049 hci_dev_lock(hdev);
3062 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN) ||
3063 !test_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks))
3064 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
3068 e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, NAME_NEEDED);
3069 if (e && hci_resolve_name(hdev, e) == 0) {
3071 hci_discovery_set_state(hdev, DISCOVERY_RESOLVING);
3081 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN) ||
3082 !test_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks))
3083 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
3087 hci_dev_unlock(hdev);
3090 static void hci_inquiry_result_evt(struct hci_dev *hdev, void *edata,
3097 if (!hci_ev_skb_pull(hdev, skb, HCI_EV_INQUIRY_RESULT,
3101 bt_dev_dbg(hdev, "num %d", ev->num);
3106 if (hci_dev_test_flag(hdev, HCI_PERIODIC_INQ))
3109 hci_dev_lock(hdev);
3124 flags = hci_inquiry_cache_update(hdev, &data, false);
3126 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00,
3131 hci_dev_unlock(hdev);
3134 static void hci_conn_complete_evt(struct hci_dev *hdev, void *data,
3141 bt_dev_dbg(hdev, "status 0x%2.2x", status);
3143 hci_dev_lock(hdev);
3145 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr);
3163 hci_bdaddr_list_lookup_with_flags(&hdev->accept_list,
3166 conn = hci_conn_add_unset(hdev, ev->link_type,
3169 bt_dev_err(hdev, "no memory for new conn");
3176 conn = hci_conn_hash_lookup_ba(hdev, ESCO_LINK,
3192 bt_dev_err(hdev, "Ignoring HCI_Connection_Complete for existing connection");
3206 !hci_find_link_key(hdev, &ev->bdaddr))
3216 if (test_bit(HCI_AUTH, &hdev->flags))
3219 if (test_bit(HCI_ENCRYPT, &hdev->flags))
3226 hci_send_cmd(hdev, HCI_OP_READ_REMOTE_FEATURES,
3229 hci_update_scan(hdev);
3233 if (!conn->out && hdev->hci_ver < BLUETOOTH_VER_2_0) {
3237 hci_send_cmd(hdev, HCI_OP_CHANGE_CONN_PTYPE, sizeof(cp),
3251 if (hdev->notify)
3252 hdev->notify(hdev, HCI_NOTIFY_ENABLE_SCO_CVSD);
3260 hci_dev_unlock(hdev);
3262 hci_conn_check_pending(hdev);
3265 static void hci_reject_conn(struct hci_dev *hdev, bdaddr_t *bdaddr)
3271 hci_send_cmd(hdev, HCI_OP_REJECT_CONN_REQ, sizeof(cp), &cp);
3274 static void hci_conn_request_evt(struct hci_dev *hdev, void *data,
3278 int mask = hdev->link_mode;
3283 bt_dev_dbg(hdev, "bdaddr %pMR type 0x%x", &ev->bdaddr, ev->link_type);
3288 if (hdev && !bacmp(&hdev->bdaddr, &ev->bdaddr)) {
3289 bt_dev_dbg(hdev, "Reject connection with same BD_ADDR %pMR\n",
3291 hci_reject_conn(hdev, &ev->bdaddr);
3295 mask |= hci_proto_connect_ind(hdev, &ev->bdaddr, ev->link_type,
3299 hci_reject_conn(hdev, &ev->bdaddr);
3303 hci_dev_lock(hdev);
3305 if (hci_bdaddr_list_lookup(&hdev->reject_list, &ev->bdaddr,
3307 hci_reject_conn(hdev, &ev->bdaddr);
3315 if (hci_dev_test_flag(hdev, HCI_MGMT) &&
3316 !hci_dev_test_flag(hdev, HCI_CONNECTABLE) &&
3317 !hci_bdaddr_list_lookup_with_flags(&hdev->accept_list, &ev->bdaddr,
3319 hci_reject_conn(hdev, &ev->bdaddr);
3325 ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr);
3329 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type,
3332 conn = hci_conn_add_unset(hdev, ev->link_type, &ev->bdaddr,
3335 bt_dev_err(hdev, "no memory for new connection");
3342 hci_dev_unlock(hdev);
3345 (!(flags & HCI_PROTO_DEFER) && !lmp_esco_capable(hdev))) {
3351 if (lmp_rswitch_capable(hdev) && (mask & HCI_LM_MASTER))
3356 hci_send_cmd(hdev, HCI_OP_ACCEPT_CONN_REQ, sizeof(cp), &cp);
3367 cp.content_format = cpu_to_le16(hdev->voice_setting);
3370 hci_send_cmd(hdev, HCI_OP_ACCEPT_SYNC_CONN_REQ, sizeof(cp),
3379 hci_dev_unlock(hdev);
3398 static void hci_disconn_complete_evt(struct hci_dev *hdev, void *data,
3407 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
3409 hci_dev_lock(hdev);
3411 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
3416 mgmt_disconnect_failed(hdev, &conn->dst, conn->type,
3430 mgmt_device_disconnected(hdev, &conn->dst, conn->type, conn->dst_type,
3435 hci_remove_link_key(hdev, &conn->dst);
3437 hci_update_scan(hdev);
3440 params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type);
3451 hci_pend_le_list_add(params, &hdev->pend_le_conns);
3452 hci_update_passive_scan(hdev);
3473 hdev->cur_adv_instance = conn->adv_instance;
3474 hci_enable_advertising(hdev);
3480 hci_dev_unlock(hdev);
3483 static void hci_auth_complete_evt(struct hci_dev *hdev, void *data,
3489 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
3491 hci_dev_lock(hdev);
3493 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
3515 hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT, sizeof(cp),
3535 hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT, sizeof(cp),
3544 hci_dev_unlock(hdev);
3547 static void hci_remote_name_evt(struct hci_dev *hdev, void *data,
3553 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
3555 hci_dev_lock(hdev);
3557 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
3559 if (!hci_dev_test_flag(hdev, HCI_MGMT))
3563 hci_check_pending_name(hdev, conn, &ev->bdaddr, ev->name,
3566 hci_check_pending_name(hdev, conn, &ev->bdaddr, NULL, 0);
3572 if (!hci_outgoing_auth_needed(hdev, conn))
3581 hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED, sizeof(cp), &cp);
3585 hci_dev_unlock(hdev);
3588 static void hci_encrypt_change_evt(struct hci_dev *hdev, void *data,
3594 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
3596 hci_dev_lock(hdev);
3598 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
3626 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED);
3627 hci_adv_instances_set_rpa_expired(hdev, true);
3657 if (!(hdev->commands[20] & 0x10)) {
3663 if (hci_send_cmd(hdev, HCI_OP_READ_ENC_KEY_SIZE,
3665 bt_dev_err(hdev, "sending read key size failed");
3682 ((conn->type == ACL_LINK && lmp_ping_capable(hdev)) ||
3683 (conn->type == LE_LINK && (hdev->le_features[0] & HCI_LE_PING)))) {
3687 cp.timeout = cpu_to_le16(hdev->auth_payload_timeout);
3688 if (hci_send_cmd(conn->hdev, HCI_OP_WRITE_AUTH_PAYLOAD_TO,
3690 bt_dev_err(hdev, "write auth payload timeout failed");
3697 hci_dev_unlock(hdev);
3700 static void hci_change_link_key_complete_evt(struct hci_dev *hdev, void *data,
3706 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
3708 hci_dev_lock(hdev);
3710 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
3720 hci_dev_unlock(hdev);
3723 static void hci_remote_features_evt(struct hci_dev *hdev, void *data,
3729 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
3731 hci_dev_lock(hdev);
3733 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
3743 if (!ev->status && lmp_ext_feat_capable(hdev) &&
3748 hci_send_cmd(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES,
3758 hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp);
3760 mgmt_device_connected(hdev, conn, NULL, 0);
3763 if (!hci_outgoing_auth_needed(hdev, conn)) {
3770 hci_dev_unlock(hdev);
3773 static inline void handle_cmd_cnt_and_timer(struct hci_dev *hdev, u8 ncmd)
3775 cancel_delayed_work(&hdev->cmd_timer);
3778 if (!test_bit(HCI_RESET, &hdev->flags)) {
3780 cancel_delayed_work(&hdev->ncmd_timer);
3781 atomic_set(&hdev->cmd_cnt, 1);
3783 if (!hci_dev_test_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE))
3784 queue_delayed_work(hdev->workqueue, &hdev->ncmd_timer,
3791 static u8 hci_cc_le_read_buffer_size_v2(struct hci_dev *hdev, void *data,
3796 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
3801 hdev->le_mtu = __le16_to_cpu(rp->acl_mtu);
3802 hdev->le_pkts = rp->acl_max_pkt;
3803 hdev->iso_mtu = __le16_to_cpu(rp->iso_mtu);
3804 hdev->iso_pkts = rp->iso_max_pkt;
3806 hdev->le_cnt = hdev->le_pkts;
3807 hdev->iso_cnt = hdev->iso_pkts;
3809 BT_DBG("%s acl mtu %d:%d iso mtu %d:%d", hdev->name, hdev->acl_mtu,
3810 hdev->acl_pkts, hdev->iso_mtu, hdev->iso_pkts);
3815 static void hci_unbound_cis_failed(struct hci_dev *hdev, u8 cig, u8 status)
3819 lockdep_assert_held(&hdev->lock);
3821 list_for_each_entry_safe(conn, tmp, &hdev->conn_hash.list, list) {
3831 static u8 hci_cc_le_set_cig_params(struct hci_dev *hdev, void *data,
3841 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
3843 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_CIG_PARAMS);
3846 bt_dev_err(hdev, "unexpected Set CIG Parameters response data");
3850 hci_dev_lock(hdev);
3860 hci_unbound_cis_failed(hdev, rp->cig_id, status);
3872 conn = hci_conn_hash_lookup_cis(hdev, NULL, 0, rp->cig_id,
3889 hci_le_create_cis_pending(hdev);
3891 hci_dev_unlock(hdev);
3896 static u8 hci_cc_le_setup_iso_path(struct hci_dev *hdev, void *data,
3903 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
3905 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SETUP_ISO_PATH);
3909 hci_dev_lock(hdev);
3911 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
3937 mgmt_device_connected(hdev, conn, NULL, 0);
3943 hci_dev_unlock(hdev);
3947 static void hci_cs_le_create_big(struct hci_dev *hdev, u8 status)
3949 bt_dev_dbg(hdev, "status 0x%2.2x", status);
3952 static u8 hci_cc_set_per_adv_param(struct hci_dev *hdev, void *data,
3958 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
3963 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_PER_ADV_PARAMS);
3971 static u8 hci_cc_le_set_per_adv_enable(struct hci_dev *hdev, void *data,
3979 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
3984 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_PER_ADV_ENABLE);
3988 hci_dev_lock(hdev);
3990 adv = hci_find_adv_instance(hdev, cp->handle);
3993 hci_dev_set_flag(hdev, HCI_LE_PER_ADV);
4003 list_for_each_entry_safe(adv, n, &hdev->adv_instances,
4012 hci_dev_clear_flag(hdev, HCI_LE_PER_ADV);
4016 hci_dev_unlock(hdev);
4037 u8 (*func)(struct hci_dev *hdev, void *data, struct sk_buff *skb);
4210 static u8 hci_cc_func(struct hci_dev *hdev, const struct hci_cc *cc,
4216 bt_dev_err(hdev, "unexpected cc 0x%4.4x length: %u < %u",
4226 bt_dev_warn(hdev, "unexpected cc 0x%4.4x length: %u > %u",
4229 data = hci_cc_skb_pull(hdev, skb, cc->op, cc->min_len);
4233 return cc->func(hdev, data, skb);
4236 static void hci_cmd_complete_evt(struct hci_dev *hdev, void *data,
4246 bt_dev_dbg(hdev, "opcode 0x%4.4x", *opcode);
4250 *status = hci_cc_func(hdev, &hci_cc_table[i], skb);
4266 handle_cmd_cnt_and_timer(hdev, ev->ncmd);
4268 hci_req_cmd_complete(hdev, *opcode, *status, req_complete,
4271 if (hci_dev_test_flag(hdev, HCI_CMD_PENDING)) {
4272 bt_dev_err(hdev,
4277 if (atomic_read(&hdev->cmd_cnt) && !skb_queue_empty(&hdev->cmd_q))
4278 queue_work(hdev->workqueue, &hdev->cmd_work);
4281 static void hci_cs_le_create_cis(struct hci_dev *hdev, u8 status)
4287 bt_dev_dbg(hdev, "status 0x%2.2x", status);
4292 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_CREATE_CIS);
4296 hci_dev_lock(hdev);
4305 conn = hci_conn_hash_lookup_handle(hdev, handle);
4317 hci_le_create_cis_pending(hdev);
4319 hci_dev_unlock(hdev);
4330 void (*func)(struct hci_dev *hdev, __u8 status);
4356 static void hci_cmd_status_evt(struct hci_dev *hdev, void *data,
4367 bt_dev_dbg(hdev, "opcode 0x%4.4x", *opcode);
4371 hci_cs_table[i].func(hdev, ev->status);
4376 handle_cmd_cnt_and_timer(hdev, ev->ncmd);
4384 if (ev->status || (hdev->req_skb && !hci_skb_event(hdev->req_skb))) {
4385 hci_req_cmd_complete(hdev, *opcode, ev->status, req_complete,
4387 if (hci_dev_test_flag(hdev, HCI_CMD_PENDING)) {
4388 bt_dev_err(hdev, "unexpected event for opcode 0x%4.4x",
4394 if (atomic_read(&hdev->cmd_cnt) && !skb_queue_empty(&hdev->cmd_q))
4395 queue_work(hdev->workqueue, &hdev->cmd_work);
4398 static void hci_hardware_error_evt(struct hci_dev *hdev, void *data,
4403 bt_dev_dbg(hdev, "code 0x%2.2x", ev->code);
4405 hdev->hw_error_code = ev->code;
4407 queue_work(hdev->req_workqueue, &hdev->error_reset);
4410 static void hci_role_change_evt(struct hci_dev *hdev, void *data,
4416 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
4418 hci_dev_lock(hdev);
4420 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
4430 hci_dev_unlock(hdev);
4433 static void hci_num_comp_pkts_evt(struct hci_dev *hdev, void *data,
4439 if (!hci_ev_skb_pull(hdev, skb, HCI_EV_NUM_COMP_PKTS,
4443 if (hdev->flow_ctl_mode != HCI_FLOW_CTL_MODE_PACKET_BASED) {
4444 bt_dev_err(hdev, "wrong event for mode %d", hdev->flow_ctl_mode);
4448 bt_dev_dbg(hdev, "num %d", ev->num);
4458 conn = hci_conn_hash_lookup_handle(hdev, handle);
4466 hdev->acl_cnt += count;
4467 if (hdev->acl_cnt > hdev->acl_pkts)
4468 hdev->acl_cnt = hdev->acl_pkts;
4472 if (hdev->le_pkts) {
4473 hdev->le_cnt += count;
4474 if (hdev->le_cnt > hdev->le_pkts)
4475 hdev->le_cnt = hdev->le_pkts;
4477 hdev->acl_cnt += count;
4478 if (hdev->acl_cnt > hdev->acl_pkts)
4479 hdev->acl_cnt = hdev->acl_pkts;
4484 hdev->sco_cnt += count;
4485 if (hdev->sco_cnt > hdev->sco_pkts)
4486 hdev->sco_cnt = hdev->sco_pkts;
4490 if (hdev->iso_pkts) {
4491 hdev->iso_cnt += count;
4492 if (hdev->iso_cnt > hdev->iso_pkts)
4493 hdev->iso_cnt = hdev->iso_pkts;
4494 } else if (hdev->le_pkts) {
4495 hdev->le_cnt += count;
4496 if (hdev->le_cnt > hdev->le_pkts)
4497 hdev->le_cnt = hdev->le_pkts;
4499 hdev->acl_cnt += count;
4500 if (hdev->acl_cnt > hdev->acl_pkts)
4501 hdev->acl_cnt = hdev->acl_pkts;
4506 bt_dev_err(hdev, "unknown type %d conn %p",
4512 queue_work(hdev->workqueue, &hdev->tx_work);
4515 static struct hci_conn *__hci_conn_lookup_handle(struct hci_dev *hdev,
4520 switch (hdev->dev_type) {
4522 return hci_conn_hash_lookup_handle(hdev, handle);
4524 chan = hci_chan_lookup_handle(hdev, handle);
4529 bt_dev_err(hdev, "unknown dev_type %d", hdev->dev_type);
4536 static void hci_num_comp_blocks_evt(struct hci_dev *hdev, void *data,
4542 if (!hci_ev_skb_pull(hdev, skb, HCI_EV_NUM_COMP_BLOCKS,
4546 if (hdev->flow_ctl_mode != HCI_FLOW_CTL_MODE_BLOCK_BASED) {
4547 bt_dev_err(hdev, "wrong event for mode %d",
4548 hdev->flow_ctl_mode);
4552 bt_dev_dbg(hdev, "num_blocks %d num_hndl %d", ev->num_blocks,
4563 conn = __hci_conn_lookup_handle(hdev, handle);
4572 hdev->block_cnt += block_count;
4573 if (hdev->block_cnt > hdev->num_blocks)
4574 hdev->block_cnt = hdev->num_blocks;
4578 bt_dev_err(hdev, "unknown type %d conn %p",
4584 queue_work(hdev->workqueue, &hdev->tx_work);
4587 static void hci_mode_change_evt(struct hci_dev *hdev, void *data,
4593 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
4595 hci_dev_lock(hdev);
4597 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
4613 hci_dev_unlock(hdev);
4616 static void hci_pin_code_request_evt(struct hci_dev *hdev, void *data,
4622 bt_dev_dbg(hdev, "");
4624 hci_dev_lock(hdev);
4626 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
4636 if (!hci_dev_test_flag(hdev, HCI_BONDABLE) &&
4638 hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY,
4640 } else if (hci_dev_test_flag(hdev, HCI_MGMT)) {
4648 mgmt_pin_code_request(hdev, &ev->bdaddr, secure);
4652 hci_dev_unlock(hdev);
4687 static void hci_link_key_request_evt(struct hci_dev *hdev, void *data,
4695 bt_dev_dbg(hdev, "");
4697 if (!hci_dev_test_flag(hdev, HCI_MGMT))
4700 hci_dev_lock(hdev);
4702 key = hci_find_link_key(hdev, &ev->bdaddr);
4704 bt_dev_dbg(hdev, "link key not found for %pMR", &ev->bdaddr);
4708 bt_dev_dbg(hdev, "found key type %u for %pMR", key->type, &ev->bdaddr);
4710 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
4717 bt_dev_dbg(hdev, "ignoring unauthenticated key");
4724 bt_dev_dbg(hdev, "ignoring key unauthenticated for high security");
4734 hci_send_cmd(hdev, HCI_OP_LINK_KEY_REPLY, sizeof(cp), &cp);
4736 hci_dev_unlock(hdev);
4741 hci_send_cmd(hdev, HCI_OP_LINK_KEY_NEG_REPLY, 6, &ev->bdaddr);
4742 hci_dev_unlock(hdev);
4745 static void hci_link_key_notify_evt(struct hci_dev *hdev, void *data,
4754 bt_dev_dbg(hdev, "");
4756 hci_dev_lock(hdev);
4758 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
4764 bt_dev_dbg(hdev, "Ignore NULL link key (ZERO KEY) for %pMR",
4778 if (!hci_dev_test_flag(hdev, HCI_MGMT))
4781 key = hci_add_link_key(hdev, conn, &ev->bdaddr, ev->link_key,
4792 mgmt_new_link_key(hdev, key, persistent);
4800 !hci_dev_test_flag(hdev, HCI_KEEP_DEBUG_KEYS)) {
4812 hci_dev_unlock(hdev);
4815 static void hci_clock_offset_evt(struct hci_dev *hdev, void *data,
4821 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
4823 hci_dev_lock(hdev);
4825 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
4829 ie = hci_inquiry_cache_lookup(hdev, &conn->dst);
4836 hci_dev_unlock(hdev);
4839 static void hci_pkt_type_change_evt(struct hci_dev *hdev, void *data,
4845 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
4847 hci_dev_lock(hdev);
4849 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
4853 hci_dev_unlock(hdev);
4856 static void hci_pscan_rep_mode_evt(struct hci_dev *hdev, void *data,
4862 bt_dev_dbg(hdev, "");
4864 hci_dev_lock(hdev);
4866 ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr);
4872 hci_dev_unlock(hdev);
4875 static void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, void *edata,
4882 bt_dev_dbg(hdev, "num_rsp %d", ev->num);
4887 if (hci_dev_test_flag(hdev, HCI_PERIODIC_INQ))
4890 hci_dev_lock(hdev);
4899 info = hci_ev_skb_pull(hdev, skb,
4903 bt_dev_err(hdev, "Malformed HCI Event: 0x%2.2x",
4917 flags = hci_inquiry_cache_update(hdev, &data, false);
4919 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00,
4930 info = hci_ev_skb_pull(hdev, skb,
4934 bt_dev_err(hdev, "Malformed HCI Event: 0x%2.2x",
4948 flags = hci_inquiry_cache_update(hdev, &data, false);
4950 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00,
4955 bt_dev_err(hdev, "Malformed HCI Event: 0x%2.2x",
4959 hci_dev_unlock(hdev);
4962 static void hci_remote_ext_features_evt(struct hci_dev *hdev, void *data,
4968 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
4970 hci_dev_lock(hdev);
4972 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
4982 ie = hci_inquiry_cache_lookup(hdev, &conn->dst);
5012 hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp);
5014 mgmt_device_connected(hdev, conn, NULL, 0);
5017 if (!hci_outgoing_auth_needed(hdev, conn)) {
5024 hci_dev_unlock(hdev);
5027 static void hci_sync_conn_complete_evt(struct hci_dev *hdev, void *data,
5043 bt_dev_err(hdev, "Ignoring connect complete event for invalid link type");
5047 bt_dev_dbg(hdev, "status 0x%2.2x", status);
5049 hci_dev_lock(hdev);
5051 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr);
5065 conn = hci_conn_hash_lookup_ba(hdev, ESCO_LINK, &ev->bdaddr);
5077 bt_dev_err(hdev, "Ignoring HCI_Sync_Conn_Complete event for existing connection");
5105 conn->pkt_type = (hdev->esco_type & SCO_ESCO_MASK) |
5106 (hdev->esco_type & EDR_ESCO_MASK);
5117 bt_dev_dbg(hdev, "SCO connected with air mode: %02x", ev->air_mode);
5121 if (conn->codec.data_path == 0 && hdev->notify) {
5124 hdev->notify(hdev, HCI_NOTIFY_ENABLE_SCO_CVSD);
5127 hdev->notify(hdev, HCI_NOTIFY_ENABLE_SCO_TRANSP);
5137 hci_dev_unlock(hdev);
5157 static void hci_extended_inquiry_result_evt(struct hci_dev *hdev, void *edata,
5165 if (!hci_ev_skb_pull(hdev, skb, HCI_EV_EXTENDED_INQUIRY_RESULT,
5169 bt_dev_dbg(hdev, "num %d", ev->num);
5174 if (hci_dev_test_flag(hdev, HCI_PERIODIC_INQ))
5177 hci_dev_lock(hdev);
5193 if (hci_dev_test_flag(hdev, HCI_MGMT))
5200 flags = hci_inquiry_cache_update(hdev, &data, name_known);
5204 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00,
5209 hci_dev_unlock(hdev);
5212 static void hci_key_refresh_complete_evt(struct hci_dev *hdev, void *data,
5218 bt_dev_dbg(hdev, "status 0x%2.2x handle 0x%4.4x", ev->status,
5221 hci_dev_lock(hdev);
5223 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
5259 hci_dev_unlock(hdev);
5282 struct hci_dev *hdev = conn->hdev;
5285 data = hci_find_remote_oob_data(hdev, &conn->dst, BDADDR_BREDR);
5289 if (bredr_sc_enabled(hdev)) {
5296 if (!hci_dev_test_flag(hdev, HCI_SC_ONLY))
5322 static void hci_io_capa_request_evt(struct hci_dev *hdev, void *data,
5328 bt_dev_dbg(hdev, "");
5330 hci_dev_lock(hdev);
5332 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
5333 if (!conn || !hci_dev_test_flag(hdev, HCI_SSP_ENABLED))
5341 if (!hci_dev_test_flag(hdev, HCI_MGMT))
5347 if (hci_dev_test_flag(hdev, HCI_BONDABLE) ||
5373 if (!hci_dev_test_flag(hdev, HCI_BONDABLE))
5379 hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_REPLY,
5387 hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_NEG_REPLY,
5392 hci_dev_unlock(hdev);
5395 static void hci_io_capa_reply_evt(struct hci_dev *hdev, void *data,
5401 bt_dev_dbg(hdev, "");
5403 hci_dev_lock(hdev);
5405 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
5413 hci_dev_unlock(hdev);
5416 static void hci_user_confirm_request_evt(struct hci_dev *hdev, void *data,
5423 bt_dev_dbg(hdev, "");
5425 hci_dev_lock(hdev);
5427 if (!hci_dev_test_flag(hdev, HCI_MGMT))
5430 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
5444 bt_dev_dbg(hdev, "Rejecting request: remote device can't provide MITM");
5445 hci_send_cmd(hdev, HCI_OP_USER_CONFIRM_NEG_REPLY,
5463 bt_dev_dbg(hdev, "Confirming auto-accept as acceptor");
5472 if (hci_find_link_key(hdev, &ev->bdaddr)) {
5473 bt_dev_dbg(hdev, "Local host already has link key");
5479 hdev->auto_accept_delay);
5481 if (hdev->auto_accept_delay > 0) {
5482 int delay = msecs_to_jiffies(hdev->auto_accept_delay);
5483 queue_delayed_work(conn->hdev->workqueue,
5488 hci_send_cmd(hdev, HCI_OP_USER_CONFIRM_REPLY,
5494 mgmt_user_confirm_request(hdev, &ev->bdaddr, ACL_LINK, 0,
5498 hci_dev_unlock(hdev);
5501 static void hci_user_passkey_request_evt(struct hci_dev *hdev, void *data,
5506 bt_dev_dbg(hdev, "");
5508 if (hci_dev_test_flag(hdev, HCI_MGMT))
5509 mgmt_user_passkey_request(hdev, &ev->bdaddr, ACL_LINK, 0);
5512 static void hci_user_passkey_notify_evt(struct hci_dev *hdev, void *data,
5518 bt_dev_dbg(hdev, "");
5520 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
5527 if (hci_dev_test_flag(hdev, HCI_MGMT))
5528 mgmt_user_passkey_notify(hdev, &conn->dst, conn->type,
5533 static void hci_keypress_notify_evt(struct hci_dev *hdev, void *data,
5539 bt_dev_dbg(hdev, "");
5541 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
5566 if (hci_dev_test_flag(hdev, HCI_MGMT))
5567 mgmt_user_passkey_notify(hdev, &conn->dst, conn->type,
5572 static void hci_simple_pair_complete_evt(struct hci_dev *hdev, void *data,
5578 bt_dev_dbg(hdev, "");
5580 hci_dev_lock(hdev);
5582 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
5600 hci_dev_unlock(hdev);
5603 static void hci_remote_host_features_evt(struct hci_dev *hdev, void *data,
5610 bt_dev_dbg(hdev, "");
5612 hci_dev_lock(hdev);
5614 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
5618 ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr);
5622 hci_dev_unlock(hdev);
5625 static void hci_remote_oob_data_request_evt(struct hci_dev *hdev, void *edata,
5631 bt_dev_dbg(hdev, "");
5633 hci_dev_lock(hdev);
5635 if (!hci_dev_test_flag(hdev, HCI_MGMT))
5638 data = hci_find_remote_oob_data(hdev, &ev->bdaddr, BDADDR_BREDR);
5643 hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_DATA_NEG_REPLY,
5648 if (bredr_sc_enabled(hdev)) {
5652 if (hci_dev_test_flag(hdev, HCI_SC_ONLY)) {
5662 hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_EXT_DATA_REPLY,
5671 hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_DATA_REPLY,
5676 hci_dev_unlock(hdev);
5680 static void hci_chan_selected_evt(struct hci_dev *hdev, void *data,
5686 bt_dev_dbg(hdev, "handle 0x%2.2x", ev->phy_handle);
5688 hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle);
5692 amp_read_loc_assoc_final_data(hdev, hcon);
5695 static void hci_phy_link_complete_evt(struct hci_dev *hdev, void *data,
5701 bt_dev_dbg(hdev, "handle 0x%2.2x status 0x%2.2x", ev->phy_handle,
5704 hci_dev_lock(hdev);
5706 hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle);
5733 hci_dev_unlock(hdev);
5736 static void hci_loglink_complete_evt(struct hci_dev *hdev, void *data,
5744 bt_dev_dbg(hdev, "log_handle 0x%4.4x phy_handle 0x%2.2x status 0x%2.2x",
5747 hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle);
5767 bredr_chan->conn->mtu = hdev->block_mtu;
5775 static void hci_disconn_loglink_complete_evt(struct hci_dev *hdev, void *data,
5781 bt_dev_dbg(hdev, "handle 0x%4.4x status 0x%2.2x",
5787 hci_dev_lock(hdev);
5789 hchan = hci_chan_lookup_handle(hdev, le16_to_cpu(ev->handle));
5796 hci_dev_unlock(hdev);
5799 static void hci_disconn_phylink_complete_evt(struct hci_dev *hdev, void *data,
5805 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
5810 hci_dev_lock(hdev);
5812 hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle);
5819 hci_dev_unlock(hdev);
5832 * used instead or hdev->rpa.
5837 } else if (hci_dev_test_flag(conn->hdev, HCI_PRIVACY)) {
5839 bacpy(&conn->init_addr, &conn->hdev->rpa);
5841 hci_copy_identity_address(conn->hdev, &conn->init_addr,
5845 conn->resp_addr_type = conn->hdev->adv_addr_type;
5847 * used instead or hdev->rpa.
5852 } else if (conn->hdev->adv_addr_type == ADDR_LE_DEV_RANDOM) {
5856 if (!ext_adv_capable(conn->hdev))
5858 &conn->hdev->random_addr);
5860 bacpy(&conn->resp_addr, &conn->hdev->bdaddr);
5871 conn->le_conn_min_interval = conn->hdev->le_conn_min_interval;
5872 conn->le_conn_max_interval = conn->hdev->le_conn_max_interval;
5876 static void le_conn_complete_evt(struct hci_dev *hdev, u8 status,
5887 hci_dev_lock(hdev);
5892 hci_dev_clear_flag(hdev, HCI_LE_ADV);
5894 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, bdaddr);
5902 conn = hci_conn_add_unset(hdev, LE_LINK, bdaddr, role);
5904 bt_dev_err(hdev, "no memory for new connection");
5921 if (hci_dev_test_flag(hdev, HCI_PRIVACY)) {
5923 bacpy(&conn->init_addr, &hdev->rpa);
5925 hci_copy_identity_address(hdev,
5941 bt_dev_err(hdev, "Ignoring HCI_Connection_Complete for existing connection");
5956 irk = hci_get_irk(hdev, &conn->dst, conn->dst_type);
5962 conn->dst_type = ev_bdaddr_type(hdev, conn->dst_type, NULL);
5983 if (hci_bdaddr_list_lookup(&hdev->reject_list, &conn->dst, addr_type)) {
5988 mgmt_device_connected(hdev, conn, NULL, 0);
5997 if (!ext_adv_capable(hdev))
5998 conn->adv_instance = hdev->cur_adv_instance;
6017 (hdev->le_features[0] & HCI_LE_PERIPHERAL_FEATURES)) {
6022 hci_send_cmd(hdev, HCI_OP_LE_READ_REMOTE_FEATURES,
6031 params = hci_pend_le_action_lookup(&hdev->pend_le_conns, &conn->dst,
6043 hci_update_passive_scan(hdev);
6044 hci_dev_unlock(hdev);
6047 static void hci_le_conn_complete_evt(struct hci_dev *hdev, void *data,
6052 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
6054 le_conn_complete_evt(hdev, ev->status, &ev->bdaddr, ev->bdaddr_type,
6061 static void hci_le_enh_conn_complete_evt(struct hci_dev *hdev, void *data,
6066 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
6068 le_conn_complete_evt(hdev, ev->status, &ev->bdaddr, ev->bdaddr_type,
6075 static void hci_le_ext_adv_term_evt(struct hci_dev *hdev, void *data,
6082 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
6092 bt_dev_warn_ratelimited(hdev, "Unexpected advertising set terminated event");
6096 hci_dev_lock(hdev);
6098 adv = hci_find_adv_instance(hdev, ev->handle);
6105 hci_remove_adv_instance(hdev, ev->handle);
6106 mgmt_advertising_removed(NULL, hdev, ev->handle);
6108 list_for_each_entry_safe(adv, n, &hdev->adv_instances, list) {
6114 hci_dev_clear_flag(hdev, HCI_LE_ADV);
6121 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->conn_handle));
6128 if (hdev->adv_addr_type != ADDR_LE_DEV_RANDOM ||
6133 bacpy(&conn->resp_addr, &hdev->random_addr);
6142 hci_dev_unlock(hdev);
6145 static void hci_le_conn_update_complete_evt(struct hci_dev *hdev, void *data,
6151 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
6156 hci_dev_lock(hdev);
6158 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
6165 hci_dev_unlock(hdev);
6168 /* This function requires the caller holds hdev->lock */
6169 static struct hci_conn *check_pending_le_conn(struct hci_dev *hdev,
6181 /* Ignore if the device is blocked or hdev is suspended */
6182 if (hci_bdaddr_list_lookup(&hdev->reject_list, addr, addr_type) ||
6183 hdev->suspended)
6189 if (hdev->conn_hash.le_num_peripheral > 0 &&
6190 (!test_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks) ||
6191 !(hdev->le_states[3] & 0x10)))
6197 params = hci_pend_le_action_lookup(&hdev->pend_le_conns, addr,
6225 conn = hci_connect_le(hdev, addr, addr_type, addr_resolved,
6226 BT_SECURITY_LOW, hdev->def_le_autoconnect_timeout,
6260 static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,
6265 struct discovery_state *d = &hdev->discovery;
6280 bt_dev_err_ratelimited(hdev, "unknown advertising packet "
6285 if (len > max_adv_len(hdev)) {
6286 bt_dev_err_ratelimited(hdev,
6312 if (!hci_dev_test_flag(hdev, HCI_MESH) && direct_addr) {
6313 direct_addr_type = ev_bdaddr_type(hdev, direct_addr_type,
6325 if (!hci_dev_test_flag(hdev, HCI_PRIVACY))
6332 if (!smp_irk_matches(hdev, hdev->irk, direct_addr))
6337 irk = hci_get_irk(hdev, bdaddr, bdaddr_type);
6343 bdaddr_type = ev_bdaddr_type(hdev, bdaddr_type, &bdaddr_resolved);
6350 conn = check_pending_le_conn(hdev, bdaddr, bdaddr_type, bdaddr_resolved,
6353 len <= max_adv_len(hdev)) {
6367 if (hci_dev_test_flag(hdev, HCI_MESH)) {
6368 mgmt_device_found(hdev, bdaddr, LE_LINK, bdaddr_type, NULL,
6377 if (hdev->le_scan_type == LE_SCAN_PASSIVE) {
6381 if (!hci_pend_le_action_lookup(&hdev->pend_le_reports,
6383 idr_is_empty(&hdev->adv_monitors_idr))
6386 mgmt_device_found(hdev, bdaddr, LE_LINK, bdaddr_type, NULL,
6408 if (!ext_adv && !has_pending_adv_report(hdev)) {
6413 store_pending_adv_report(hdev, bdaddr, bdaddr_type,
6418 mgmt_device_found(hdev, bdaddr, LE_LINK, bdaddr_type, NULL,
6434 mgmt_device_found(hdev, &d->last_adv_addr, LE_LINK,
6445 store_pending_adv_report(hdev, bdaddr, bdaddr_type,
6453 clear_pending_adv_report(hdev);
6454 mgmt_device_found(hdev, bdaddr, LE_LINK, bdaddr_type, NULL,
6463 mgmt_device_found(hdev, &d->last_adv_addr, LE_LINK,
6466 clear_pending_adv_report(hdev);
6469 static void hci_le_adv_report_evt(struct hci_dev *hdev, void *data,
6478 hci_dev_lock(hdev);
6484 info = hci_le_ev_skb_pull(hdev, skb,
6490 if (!hci_le_ev_skb_pull(hdev, skb, HCI_EV_LE_ADVERTISING_REPORT,
6494 if (info->length <= max_adv_len(hdev)) {
6496 process_adv_report(hdev, info->type, &info->bdaddr,
6501 bt_dev_err(hdev, "Dropping invalid advertising data");
6505 hci_dev_unlock(hdev);
6508 static u8 ext_evt_type_to_legacy(struct hci_dev *hdev, u16 evt_type)
6546 bt_dev_err_ratelimited(hdev, "Unknown advertising packet type: 0x%02x",
6552 static void hci_le_ext_adv_report_evt(struct hci_dev *hdev, void *data,
6561 hci_dev_lock(hdev);
6568 info = hci_le_ev_skb_pull(hdev, skb, HCI_EV_LE_EXT_ADV_REPORT,
6573 if (!hci_le_ev_skb_pull(hdev, skb, HCI_EV_LE_EXT_ADV_REPORT,
6578 legacy_evt_type = ext_evt_type_to_legacy(hdev, evt_type);
6580 process_adv_report(hdev, legacy_evt_type, &info->bdaddr,
6588 hci_dev_unlock(hdev);
6591 static int hci_le_pa_term_sync(struct hci_dev *hdev, __le16 handle)
6598 return hci_send_cmd(hdev, HCI_OP_LE_PA_TERM_SYNC, sizeof(cp), &cp);
6601 static void hci_le_pa_sync_estabilished_evt(struct hci_dev *hdev, void *data,
6605 int mask = hdev->link_mode;
6609 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
6611 hci_dev_lock(hdev);
6613 hci_dev_clear_flag(hdev, HCI_PA_SYNC);
6615 mask |= hci_proto_connect_ind(hdev, &ev->bdaddr, ISO_LINK, &flags);
6617 hci_le_pa_term_sync(hdev, ev->handle);
6626 pa_sync = hci_conn_add_unset(hdev, ISO_LINK, BDADDR_ANY,
6639 hci_dev_unlock(hdev);
6642 static void hci_le_per_adv_report_evt(struct hci_dev *hdev, void *data,
6646 int mask = hdev->link_mode;
6649 bt_dev_dbg(hdev, "sync_handle 0x%4.4x", le16_to_cpu(ev->sync_handle));
6651 hci_dev_lock(hdev);
6653 mask |= hci_proto_connect_ind(hdev, BDADDR_ANY, ISO_LINK, &flags);
6655 hci_le_pa_term_sync(hdev, ev->sync_handle);
6657 hci_dev_unlock(hdev);
6660 static void hci_le_remote_feat_complete_evt(struct hci_dev *hdev, void *data,
6666 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
6668 hci_dev_lock(hdev);
6670 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
6688 (hdev->le_features[0] & HCI_LE_PERIPHERAL_FEATURES))
6699 hci_dev_unlock(hdev);
6702 static void hci_le_ltk_request_evt(struct hci_dev *hdev, void *data,
6711 bt_dev_dbg(hdev, "handle 0x%4.4x", __le16_to_cpu(ev->handle));
6713 hci_dev_lock(hdev);
6715 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
6719 ltk = hci_find_ltk(hdev, &conn->dst, conn->dst_type, conn->role);
6741 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
6757 hci_dev_unlock(hdev);
6763 hci_send_cmd(hdev, HCI_OP_LE_LTK_NEG_REPLY, sizeof(neg), &neg);
6764 hci_dev_unlock(hdev);
6767 static void send_conn_param_neg_reply(struct hci_dev *hdev, u16 handle,
6775 hci_send_cmd(hdev, HCI_OP_LE_CONN_PARAM_REQ_NEG_REPLY, sizeof(cp),
6779 static void hci_le_remote_conn_param_req_evt(struct hci_dev *hdev, void *data,
6787 bt_dev_dbg(hdev, "handle 0x%4.4x", __le16_to_cpu(ev->handle));
6795 hcon = hci_conn_hash_lookup_handle(hdev, handle);
6797 return send_conn_param_neg_reply(hdev, handle,
6801 return send_conn_param_neg_reply(hdev, handle,
6805 return send_conn_param_neg_reply(hdev, handle,
6812 hci_dev_lock(hdev);
6814 params = hci_conn_params_lookup(hdev, &hcon->dst,
6826 hci_dev_unlock(hdev);
6828 mgmt_new_conn_param(hdev, &hcon->dst, hcon->dst_type,
6840 hci_send_cmd(hdev, HCI_OP_LE_CONN_PARAM_REQ_REPLY, sizeof(cp), &cp);
6843 static void hci_le_direct_adv_report_evt(struct hci_dev *hdev, void *data,
6850 if (!hci_le_ev_skb_pull(hdev, skb, HCI_EV_LE_DIRECT_ADV_REPORT,
6857 hci_dev_lock(hdev);
6862 process_adv_report(hdev, info->type, &info->bdaddr,
6868 hci_dev_unlock(hdev);
6871 static void hci_le_phy_update_evt(struct hci_dev *hdev, void *data,
6877 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
6882 hci_dev_lock(hdev);
6884 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
6892 hci_dev_unlock(hdev);
6895 static void hci_le_cis_estabilished_evt(struct hci_dev *hdev, void *data,
6904 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
6906 hci_dev_lock(hdev);
6908 conn = hci_conn_hash_lookup_handle(hdev, handle);
6910 bt_dev_err(hdev,
6917 bt_dev_err(hdev,
6974 hci_le_create_cis_pending(hdev);
6976 hci_dev_unlock(hdev);
6979 static void hci_le_reject_cis(struct hci_dev *hdev, __le16 handle)
6986 hci_send_cmd(hdev, HCI_OP_LE_REJECT_CIS, sizeof(cp), &cp);
6989 static void hci_le_accept_cis(struct hci_dev *hdev, __le16 handle)
6995 hci_send_cmd(hdev, HCI_OP_LE_ACCEPT_CIS, sizeof(cp), &cp);
6998 static void hci_le_cis_req_evt(struct hci_dev *hdev, void *data,
7010 bt_dev_dbg(hdev, "acl 0x%4.4x handle 0x%4.4x cig 0x%2.2x cis 0x%2.2x",
7013 hci_dev_lock(hdev);
7015 acl = hci_conn_hash_lookup_handle(hdev, acl_handle);
7019 mask = hci_proto_connect_ind(hdev, &acl->dst, ISO_LINK, &flags);
7021 hci_le_reject_cis(hdev, ev->cis_handle);
7025 cis = hci_conn_hash_lookup_handle(hdev, cis_handle);
7027 cis = hci_conn_add(hdev, ISO_LINK, &acl->dst, HCI_ROLE_SLAVE,
7030 hci_le_reject_cis(hdev, ev->cis_handle);
7039 hci_le_accept_cis(hdev, ev->cis_handle);
7046 hci_dev_unlock(hdev);
7049 static int hci_iso_term_big_sync(struct hci_dev *hdev, void *data)
7053 return hci_le_terminate_big_sync(hdev, handle,
7057 static void hci_le_create_big_complete_evt(struct hci_dev *hdev, void *data,
7064 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
7066 if (!hci_le_ev_skb_pull(hdev, skb, HCI_EVT_LE_CREATE_BIG_COMPLETE,
7070 hci_dev_lock(hdev);
7074 list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) {
7109 hci_cmd_sync_queue(hdev, hci_iso_term_big_sync,
7112 hci_dev_unlock(hdev);
7115 static void hci_le_big_sync_established_evt(struct hci_dev *hdev, void *data,
7123 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
7125 if (!hci_le_ev_skb_pull(hdev, skb, HCI_EVT_LE_BIG_SYNC_ESTABILISHED,
7129 hci_dev_lock(hdev);
7132 pa_sync = hci_conn_hash_lookup_pa_sync_big_handle(hdev, ev->handle);
7144 bis = hci_conn_hash_lookup_handle(hdev, handle);
7146 bis = hci_conn_add(hdev, ISO_LINK, BDADDR_ANY,
7177 bis = hci_conn_hash_lookup_handle(hdev, handle);
7183 hci_dev_unlock(hdev);
7186 static void hci_le_big_info_adv_report_evt(struct hci_dev *hdev, void *data,
7190 int mask = hdev->link_mode;
7194 bt_dev_dbg(hdev, "sync_handle 0x%4.4x", le16_to_cpu(ev->sync_handle));
7196 hci_dev_lock(hdev);
7198 mask |= hci_proto_connect_ind(hdev, BDADDR_ANY, ISO_LINK, &flags);
7200 hci_le_pa_term_sync(hdev, ev->sync_handle);
7208 (hdev,
7215 pa_sync = hci_conn_add_unset(hdev, ISO_LINK, BDADDR_ANY,
7228 mgmt_device_connected(hdev, pa_sync, NULL, 0);
7231 hci_dev_unlock(hdev);
7253 void (*func)(struct hci_dev *hdev, void *data, struct sk_buff *skb);
7329 static void hci_le_meta_evt(struct hci_dev *hdev, void *data,
7337 bt_dev_dbg(hdev, "subevent 0x%2.2x", ev->subevent);
7340 if (hdev->req_skb &&
7341 hci_opcode_ogf(hci_skb_opcode(hdev->req_skb)) == 0x08 &&
7342 hci_skb_event(hdev->req_skb) == ev->subevent) {
7343 *opcode = hci_skb_opcode(hdev->req_skb);
7344 hci_req_cmd_complete(hdev, *opcode, 0x00, req_complete,
7353 bt_dev_err(hdev, "unexpected subevent 0x%2.2x length: %u < %u",
7363 bt_dev_warn(hdev, "unexpected subevent 0x%2.2x length: %u > %u",
7365 data = hci_le_ev_skb_pull(hdev, skb, ev->subevent, subev->min_len);
7369 subev->func(hdev, data, skb);
7372 static bool hci_get_cmd_complete(struct hci_dev *hdev, u16 opcode,
7381 hdr = hci_ev_skb_pull(hdev, skb, event, sizeof(*hdr));
7398 bt_dev_err(hdev, "last event is not cmd complete (0x%2.2x)",
7403 ev = hci_cc_skb_pull(hdev, skb, opcode, sizeof(*ev));
7416 static void hci_store_wake_reason(struct hci_dev *hdev, u8 event,
7425 hci_dev_lock(hdev);
7430 if (!hdev->suspended || hdev->wake_reason)
7436 hdev->wake_reason = MGMT_WAKE_REASON_REMOTE_WAKE;
7443 bacpy(&hdev->wake_addr, &conn_request->bdaddr);
7444 hdev->wake_addr_type = BDADDR_BREDR;
7446 bacpy(&hdev->wake_addr, &conn_complete->bdaddr);
7447 hdev->wake_addr_type = BDADDR_BREDR;
7464 bacpy(&hdev->wake_addr, &adv->bdaddr);
7465 hdev->wake_addr_type = adv->bdaddr_type;
7468 bacpy(&hdev->wake_addr, &direct_adv->bdaddr);
7469 hdev->wake_addr_type = direct_adv->bdaddr_type;
7472 bacpy(&hdev->wake_addr, &ext_adv->bdaddr);
7473 hdev->wake_addr_type = ext_adv->bdaddr_type;
7478 hdev->wake_reason = MGMT_WAKE_REASON_UNEXPECTED;
7482 hci_dev_unlock(hdev);
7518 void (*func)(struct hci_dev *hdev, void *data,
7520 void (*func_req)(struct hci_dev *hdev, void *data,
7668 static void hci_event_func(struct hci_dev *hdev, u8 event, struct sk_buff *skb,
7680 bt_dev_err(hdev, "unexpected event 0x%2.2x length: %u < %u",
7690 bt_dev_warn_ratelimited(hdev,
7694 data = hci_ev_skb_pull(hdev, skb, event, ev->min_len);
7699 ev->func_req(hdev, data, skb, opcode, status, req_complete,
7702 ev->func(hdev, data, skb);
7705 void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
7715 bt_dev_err(hdev, "Malformed HCI Event");
7719 kfree_skb(hdev->recv_event);
7720 hdev->recv_event = skb_clone(skb, GFP_KERNEL);
7724 bt_dev_warn(hdev, "Received unexpected HCI Event 0x%2.2x",
7730 if (hdev->req_skb &&
7731 hci_opcode_ogf(hci_skb_opcode(hdev->req_skb)) != 0x08 &&
7732 hci_skb_event(hdev->req_skb) == event) {
7733 hci_req_cmd_complete(hdev, hci_skb_opcode(hdev->req_skb),
7750 hci_store_wake_reason(hdev, event, skb);
7752 bt_dev_dbg(hdev, "event 0x%2.2x", event);
7754 hci_event_func(hdev, event, skb, &opcode, &status, &req_complete,
7758 req_complete(hdev, status, opcode);
7760 if (!hci_get_cmd_complete(hdev, opcode, req_evt, orig_skb)) {
7764 req_complete_skb(hdev, status, opcode, orig_skb);
7770 hdev->stat.evt_rx++;