2 BlueZ - Bluetooth protocol stack for Linux
3 Copyright (c) 2000-2001, 2010, Code Aurora Forum. All rights reserved.
5 Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
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
9 published by the Free Software Foundation;
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
12 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
14 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
15 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
16 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
21 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
22 SOFTWARE IS DISCLAIMED.
25 /* Bluetooth HCI event handling. */
27 #include <asm/unaligned.h>
29 #include <net/bluetooth/bluetooth.h>
30 #include <net/bluetooth/hci_core.h>
31 #include <net/bluetooth/mgmt.h>
32 #include <net/bluetooth/a2mp.h>
33 #include <net/bluetooth/amp.h>
35 /* Handle HCI Event packets */
37 static void hci_cc_inquiry_cancel(struct hci_dev *hdev, struct sk_buff *skb)
39 __u8 status = *((__u8 *) skb->data);
41 BT_DBG("%s status 0x%2.2x", hdev->name, status);
45 mgmt_stop_discovery_failed(hdev, status);
50 clear_bit(HCI_INQUIRY, &hdev->flags);
53 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
56 hci_req_complete(hdev, HCI_OP_INQUIRY_CANCEL, status);
58 hci_conn_check_pending(hdev);
61 static void hci_cc_periodic_inq(struct hci_dev *hdev, struct sk_buff *skb)
63 __u8 status = *((__u8 *) skb->data);
65 BT_DBG("%s status 0x%2.2x", hdev->name, status);
70 set_bit(HCI_PERIODIC_INQ, &hdev->dev_flags);
73 static void hci_cc_exit_periodic_inq(struct hci_dev *hdev, struct sk_buff *skb)
75 __u8 status = *((__u8 *) skb->data);
77 BT_DBG("%s status 0x%2.2x", hdev->name, status);
82 clear_bit(HCI_PERIODIC_INQ, &hdev->dev_flags);
84 hci_conn_check_pending(hdev);
87 static void hci_cc_remote_name_req_cancel(struct hci_dev *hdev,
90 BT_DBG("%s", hdev->name);
93 static void hci_cc_role_discovery(struct hci_dev *hdev, struct sk_buff *skb)
95 struct hci_rp_role_discovery *rp = (void *) skb->data;
96 struct hci_conn *conn;
98 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
105 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
108 conn->link_mode &= ~HCI_LM_MASTER;
110 conn->link_mode |= HCI_LM_MASTER;
113 hci_dev_unlock(hdev);
116 static void hci_cc_read_link_policy(struct hci_dev *hdev, struct sk_buff *skb)
118 struct hci_rp_read_link_policy *rp = (void *) skb->data;
119 struct hci_conn *conn;
121 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
128 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
130 conn->link_policy = __le16_to_cpu(rp->policy);
132 hci_dev_unlock(hdev);
135 static void hci_cc_write_link_policy(struct hci_dev *hdev, struct sk_buff *skb)
137 struct hci_rp_write_link_policy *rp = (void *) skb->data;
138 struct hci_conn *conn;
141 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
146 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LINK_POLICY);
152 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
154 conn->link_policy = get_unaligned_le16(sent + 2);
156 hci_dev_unlock(hdev);
159 static void hci_cc_read_def_link_policy(struct hci_dev *hdev,
162 struct hci_rp_read_def_link_policy *rp = (void *) skb->data;
164 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
169 hdev->link_policy = __le16_to_cpu(rp->policy);
172 static void hci_cc_write_def_link_policy(struct hci_dev *hdev,
175 __u8 status = *((__u8 *) skb->data);
178 BT_DBG("%s status 0x%2.2x", hdev->name, status);
180 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_DEF_LINK_POLICY);
185 hdev->link_policy = get_unaligned_le16(sent);
187 hci_req_complete(hdev, HCI_OP_WRITE_DEF_LINK_POLICY, status);
190 static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb)
192 __u8 status = *((__u8 *) skb->data);
194 BT_DBG("%s status 0x%2.2x", hdev->name, status);
196 clear_bit(HCI_RESET, &hdev->flags);
198 hci_req_complete(hdev, HCI_OP_RESET, status);
200 /* Reset all non-persistent flags */
201 hdev->dev_flags &= ~(BIT(HCI_LE_SCAN) | BIT(HCI_PENDING_CLASS) |
202 BIT(HCI_PERIODIC_INQ));
204 hdev->discovery.state = DISCOVERY_STOPPED;
205 hdev->inq_tx_power = HCI_TX_POWER_INVALID;
206 hdev->adv_tx_power = HCI_TX_POWER_INVALID;
208 memset(hdev->adv_data, 0, sizeof(hdev->adv_data));
209 hdev->adv_data_len = 0;
212 static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb)
214 __u8 status = *((__u8 *) skb->data);
217 BT_DBG("%s status 0x%2.2x", hdev->name, status);
219 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LOCAL_NAME);
225 if (test_bit(HCI_MGMT, &hdev->dev_flags))
226 mgmt_set_local_name_complete(hdev, sent, status);
228 memcpy(hdev->dev_name, sent, HCI_MAX_NAME_LENGTH);
230 hci_dev_unlock(hdev);
232 if (!status && !test_bit(HCI_INIT, &hdev->flags))
235 hci_req_complete(hdev, HCI_OP_WRITE_LOCAL_NAME, status);
238 static void hci_cc_read_local_name(struct hci_dev *hdev, struct sk_buff *skb)
240 struct hci_rp_read_local_name *rp = (void *) skb->data;
242 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
247 if (test_bit(HCI_SETUP, &hdev->dev_flags))
248 memcpy(hdev->dev_name, rp->name, HCI_MAX_NAME_LENGTH);
251 static void hci_cc_write_auth_enable(struct hci_dev *hdev, struct sk_buff *skb)
253 __u8 status = *((__u8 *) skb->data);
256 BT_DBG("%s status 0x%2.2x", hdev->name, status);
258 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_AUTH_ENABLE);
263 __u8 param = *((__u8 *) sent);
265 if (param == AUTH_ENABLED)
266 set_bit(HCI_AUTH, &hdev->flags);
268 clear_bit(HCI_AUTH, &hdev->flags);
271 if (test_bit(HCI_MGMT, &hdev->dev_flags))
272 mgmt_auth_enable_complete(hdev, status);
274 hci_req_complete(hdev, HCI_OP_WRITE_AUTH_ENABLE, status);
277 static void hci_cc_write_encrypt_mode(struct hci_dev *hdev, struct sk_buff *skb)
279 __u8 status = *((__u8 *) skb->data);
282 BT_DBG("%s status 0x%2.2x", hdev->name, status);
284 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_ENCRYPT_MODE);
289 __u8 param = *((__u8 *) sent);
292 set_bit(HCI_ENCRYPT, &hdev->flags);
294 clear_bit(HCI_ENCRYPT, &hdev->flags);
297 hci_req_complete(hdev, HCI_OP_WRITE_ENCRYPT_MODE, status);
300 static void hci_cc_write_scan_enable(struct hci_dev *hdev, struct sk_buff *skb)
302 __u8 param, status = *((__u8 *) skb->data);
303 int old_pscan, old_iscan;
306 BT_DBG("%s status 0x%2.2x", hdev->name, status);
308 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SCAN_ENABLE);
312 param = *((__u8 *) sent);
317 mgmt_write_scan_failed(hdev, param, status);
318 hdev->discov_timeout = 0;
322 old_pscan = test_and_clear_bit(HCI_PSCAN, &hdev->flags);
323 old_iscan = test_and_clear_bit(HCI_ISCAN, &hdev->flags);
325 if (param & SCAN_INQUIRY) {
326 set_bit(HCI_ISCAN, &hdev->flags);
328 mgmt_discoverable(hdev, 1);
329 if (hdev->discov_timeout > 0) {
330 int to = msecs_to_jiffies(hdev->discov_timeout * 1000);
331 queue_delayed_work(hdev->workqueue, &hdev->discov_off,
334 } else if (old_iscan)
335 mgmt_discoverable(hdev, 0);
337 if (param & SCAN_PAGE) {
338 set_bit(HCI_PSCAN, &hdev->flags);
340 mgmt_connectable(hdev, 1);
341 } else if (old_pscan)
342 mgmt_connectable(hdev, 0);
345 hci_dev_unlock(hdev);
346 hci_req_complete(hdev, HCI_OP_WRITE_SCAN_ENABLE, status);
349 static void hci_cc_read_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb)
351 struct hci_rp_read_class_of_dev *rp = (void *) skb->data;
353 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
358 memcpy(hdev->dev_class, rp->dev_class, 3);
360 BT_DBG("%s class 0x%.2x%.2x%.2x", hdev->name,
361 hdev->dev_class[2], hdev->dev_class[1], hdev->dev_class[0]);
364 static void hci_cc_write_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb)
366 __u8 status = *((__u8 *) skb->data);
369 BT_DBG("%s status 0x%2.2x", hdev->name, status);
371 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_CLASS_OF_DEV);
378 memcpy(hdev->dev_class, sent, 3);
380 if (test_bit(HCI_MGMT, &hdev->dev_flags))
381 mgmt_set_class_of_dev_complete(hdev, sent, status);
383 hci_dev_unlock(hdev);
386 static void hci_cc_read_voice_setting(struct hci_dev *hdev, struct sk_buff *skb)
388 struct hci_rp_read_voice_setting *rp = (void *) skb->data;
391 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
396 setting = __le16_to_cpu(rp->voice_setting);
398 if (hdev->voice_setting == setting)
401 hdev->voice_setting = setting;
403 BT_DBG("%s voice setting 0x%4.4x", hdev->name, setting);
406 hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING);
409 static void hci_cc_write_voice_setting(struct hci_dev *hdev,
412 __u8 status = *((__u8 *) skb->data);
416 BT_DBG("%s status 0x%2.2x", hdev->name, status);
421 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_VOICE_SETTING);
425 setting = get_unaligned_le16(sent);
427 if (hdev->voice_setting == setting)
430 hdev->voice_setting = setting;
432 BT_DBG("%s voice setting 0x%4.4x", hdev->name, setting);
435 hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING);
438 static void hci_cc_host_buffer_size(struct hci_dev *hdev, struct sk_buff *skb)
440 __u8 status = *((__u8 *) skb->data);
442 BT_DBG("%s status 0x%2.2x", hdev->name, status);
444 hci_req_complete(hdev, HCI_OP_HOST_BUFFER_SIZE, status);
447 static void hci_cc_write_ssp_mode(struct hci_dev *hdev, struct sk_buff *skb)
449 __u8 status = *((__u8 *) skb->data);
450 struct hci_cp_write_ssp_mode *sent;
452 BT_DBG("%s status 0x%2.2x", hdev->name, status);
454 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SSP_MODE);
460 hdev->host_features[0] |= LMP_HOST_SSP;
462 hdev->host_features[0] &= ~LMP_HOST_SSP;
465 if (test_bit(HCI_MGMT, &hdev->dev_flags))
466 mgmt_ssp_enable_complete(hdev, sent->mode, status);
469 set_bit(HCI_SSP_ENABLED, &hdev->dev_flags);
471 clear_bit(HCI_SSP_ENABLED, &hdev->dev_flags);
475 static void hci_cc_read_local_version(struct hci_dev *hdev, struct sk_buff *skb)
477 struct hci_rp_read_local_version *rp = (void *) skb->data;
479 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
484 hdev->hci_ver = rp->hci_ver;
485 hdev->hci_rev = __le16_to_cpu(rp->hci_rev);
486 hdev->lmp_ver = rp->lmp_ver;
487 hdev->manufacturer = __le16_to_cpu(rp->manufacturer);
488 hdev->lmp_subver = __le16_to_cpu(rp->lmp_subver);
490 BT_DBG("%s manufacturer 0x%4.4x hci ver %d:%d", hdev->name,
491 hdev->manufacturer, hdev->hci_ver, hdev->hci_rev);
494 hci_req_complete(hdev, HCI_OP_READ_LOCAL_VERSION, rp->status);
497 static void hci_cc_read_local_commands(struct hci_dev *hdev,
500 struct hci_rp_read_local_commands *rp = (void *) skb->data;
502 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
505 memcpy(hdev->commands, rp->commands, sizeof(hdev->commands));
507 hci_req_complete(hdev, HCI_OP_READ_LOCAL_COMMANDS, rp->status);
510 static void hci_cc_read_local_features(struct hci_dev *hdev,
513 struct hci_rp_read_local_features *rp = (void *) skb->data;
515 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
520 memcpy(hdev->features, rp->features, 8);
522 /* Adjust default settings according to features
523 * supported by device. */
525 if (hdev->features[0] & LMP_3SLOT)
526 hdev->pkt_type |= (HCI_DM3 | HCI_DH3);
528 if (hdev->features[0] & LMP_5SLOT)
529 hdev->pkt_type |= (HCI_DM5 | HCI_DH5);
531 if (hdev->features[1] & LMP_HV2) {
532 hdev->pkt_type |= (HCI_HV2);
533 hdev->esco_type |= (ESCO_HV2);
536 if (hdev->features[1] & LMP_HV3) {
537 hdev->pkt_type |= (HCI_HV3);
538 hdev->esco_type |= (ESCO_HV3);
541 if (lmp_esco_capable(hdev))
542 hdev->esco_type |= (ESCO_EV3);
544 if (hdev->features[4] & LMP_EV4)
545 hdev->esco_type |= (ESCO_EV4);
547 if (hdev->features[4] & LMP_EV5)
548 hdev->esco_type |= (ESCO_EV5);
550 if (hdev->features[5] & LMP_EDR_ESCO_2M)
551 hdev->esco_type |= (ESCO_2EV3);
553 if (hdev->features[5] & LMP_EDR_ESCO_3M)
554 hdev->esco_type |= (ESCO_3EV3);
556 if (hdev->features[5] & LMP_EDR_3S_ESCO)
557 hdev->esco_type |= (ESCO_2EV5 | ESCO_3EV5);
559 BT_DBG("%s features 0x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x", hdev->name,
560 hdev->features[0], hdev->features[1],
561 hdev->features[2], hdev->features[3],
562 hdev->features[4], hdev->features[5],
563 hdev->features[6], hdev->features[7]);
566 static void hci_cc_read_local_ext_features(struct hci_dev *hdev,
569 struct hci_rp_read_local_ext_features *rp = (void *) skb->data;
571 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
578 memcpy(hdev->features, rp->features, 8);
581 memcpy(hdev->host_features, rp->features, 8);
586 hci_req_complete(hdev, HCI_OP_READ_LOCAL_EXT_FEATURES, rp->status);
589 static void hci_cc_read_flow_control_mode(struct hci_dev *hdev,
592 struct hci_rp_read_flow_control_mode *rp = (void *) skb->data;
594 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
599 hdev->flow_ctl_mode = rp->mode;
601 hci_req_complete(hdev, HCI_OP_READ_FLOW_CONTROL_MODE, rp->status);
604 static void hci_cc_read_buffer_size(struct hci_dev *hdev, struct sk_buff *skb)
606 struct hci_rp_read_buffer_size *rp = (void *) skb->data;
608 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
613 hdev->acl_mtu = __le16_to_cpu(rp->acl_mtu);
614 hdev->sco_mtu = rp->sco_mtu;
615 hdev->acl_pkts = __le16_to_cpu(rp->acl_max_pkt);
616 hdev->sco_pkts = __le16_to_cpu(rp->sco_max_pkt);
618 if (test_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks)) {
623 hdev->acl_cnt = hdev->acl_pkts;
624 hdev->sco_cnt = hdev->sco_pkts;
626 BT_DBG("%s acl mtu %d:%d sco mtu %d:%d", hdev->name, hdev->acl_mtu,
627 hdev->acl_pkts, hdev->sco_mtu, hdev->sco_pkts);
630 static void hci_cc_read_bd_addr(struct hci_dev *hdev, struct sk_buff *skb)
632 struct hci_rp_read_bd_addr *rp = (void *) skb->data;
634 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
637 bacpy(&hdev->bdaddr, &rp->bdaddr);
639 hci_req_complete(hdev, HCI_OP_READ_BD_ADDR, rp->status);
642 static void hci_cc_read_data_block_size(struct hci_dev *hdev,
645 struct hci_rp_read_data_block_size *rp = (void *) skb->data;
647 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
652 hdev->block_mtu = __le16_to_cpu(rp->max_acl_len);
653 hdev->block_len = __le16_to_cpu(rp->block_len);
654 hdev->num_blocks = __le16_to_cpu(rp->num_blocks);
656 hdev->block_cnt = hdev->num_blocks;
658 BT_DBG("%s blk mtu %d cnt %d len %d", hdev->name, hdev->block_mtu,
659 hdev->block_cnt, hdev->block_len);
661 hci_req_complete(hdev, HCI_OP_READ_DATA_BLOCK_SIZE, rp->status);
664 static void hci_cc_write_ca_timeout(struct hci_dev *hdev, struct sk_buff *skb)
666 __u8 status = *((__u8 *) skb->data);
668 BT_DBG("%s status 0x%2.2x", hdev->name, status);
670 hci_req_complete(hdev, HCI_OP_WRITE_CA_TIMEOUT, status);
673 static void hci_cc_read_local_amp_info(struct hci_dev *hdev,
676 struct hci_rp_read_local_amp_info *rp = (void *) skb->data;
678 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
683 hdev->amp_status = rp->amp_status;
684 hdev->amp_total_bw = __le32_to_cpu(rp->total_bw);
685 hdev->amp_max_bw = __le32_to_cpu(rp->max_bw);
686 hdev->amp_min_latency = __le32_to_cpu(rp->min_latency);
687 hdev->amp_max_pdu = __le32_to_cpu(rp->max_pdu);
688 hdev->amp_type = rp->amp_type;
689 hdev->amp_pal_cap = __le16_to_cpu(rp->pal_cap);
690 hdev->amp_assoc_size = __le16_to_cpu(rp->max_assoc_size);
691 hdev->amp_be_flush_to = __le32_to_cpu(rp->be_flush_to);
692 hdev->amp_max_flush_to = __le32_to_cpu(rp->max_flush_to);
694 hci_req_complete(hdev, HCI_OP_READ_LOCAL_AMP_INFO, rp->status);
697 a2mp_send_getinfo_rsp(hdev);
700 static void hci_cc_read_local_amp_assoc(struct hci_dev *hdev,
703 struct hci_rp_read_local_amp_assoc *rp = (void *) skb->data;
704 struct amp_assoc *assoc = &hdev->loc_assoc;
705 size_t rem_len, frag_len;
707 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
712 frag_len = skb->len - sizeof(*rp);
713 rem_len = __le16_to_cpu(rp->rem_len);
715 if (rem_len > frag_len) {
716 BT_DBG("frag_len %zu rem_len %zu", frag_len, rem_len);
718 memcpy(assoc->data + assoc->offset, rp->frag, frag_len);
719 assoc->offset += frag_len;
721 /* Read other fragments */
722 amp_read_loc_assoc_frag(hdev, rp->phy_handle);
727 memcpy(assoc->data + assoc->offset, rp->frag, rem_len);
728 assoc->len = assoc->offset + rem_len;
732 /* Send A2MP Rsp when all fragments are received */
733 a2mp_send_getampassoc_rsp(hdev, rp->status);
734 a2mp_send_create_phy_link_req(hdev, rp->status);
737 static void hci_cc_delete_stored_link_key(struct hci_dev *hdev,
740 __u8 status = *((__u8 *) skb->data);
742 BT_DBG("%s status 0x%2.2x", hdev->name, status);
744 hci_req_complete(hdev, HCI_OP_DELETE_STORED_LINK_KEY, status);
747 static void hci_cc_set_event_mask(struct hci_dev *hdev, struct sk_buff *skb)
749 __u8 status = *((__u8 *) skb->data);
751 BT_DBG("%s status 0x%2.2x", hdev->name, status);
753 hci_req_complete(hdev, HCI_OP_SET_EVENT_MASK, status);
756 static void hci_cc_write_inquiry_mode(struct hci_dev *hdev,
759 __u8 status = *((__u8 *) skb->data);
761 BT_DBG("%s status 0x%2.2x", hdev->name, status);
763 hci_req_complete(hdev, HCI_OP_WRITE_INQUIRY_MODE, status);
766 static void hci_cc_read_inq_rsp_tx_power(struct hci_dev *hdev,
769 struct hci_rp_read_inq_rsp_tx_power *rp = (void *) skb->data;
771 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
774 hdev->inq_tx_power = rp->tx_power;
776 hci_req_complete(hdev, HCI_OP_READ_INQ_RSP_TX_POWER, rp->status);
779 static void hci_cc_set_event_flt(struct hci_dev *hdev, struct sk_buff *skb)
781 __u8 status = *((__u8 *) skb->data);
783 BT_DBG("%s status 0x%2.2x", hdev->name, status);
785 hci_req_complete(hdev, HCI_OP_SET_EVENT_FLT, status);
788 static void hci_cc_pin_code_reply(struct hci_dev *hdev, struct sk_buff *skb)
790 struct hci_rp_pin_code_reply *rp = (void *) skb->data;
791 struct hci_cp_pin_code_reply *cp;
792 struct hci_conn *conn;
794 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
798 if (test_bit(HCI_MGMT, &hdev->dev_flags))
799 mgmt_pin_code_reply_complete(hdev, &rp->bdaddr, rp->status);
804 cp = hci_sent_cmd_data(hdev, HCI_OP_PIN_CODE_REPLY);
808 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
810 conn->pin_length = cp->pin_len;
813 hci_dev_unlock(hdev);
816 static void hci_cc_pin_code_neg_reply(struct hci_dev *hdev, struct sk_buff *skb)
818 struct hci_rp_pin_code_neg_reply *rp = (void *) skb->data;
820 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
824 if (test_bit(HCI_MGMT, &hdev->dev_flags))
825 mgmt_pin_code_neg_reply_complete(hdev, &rp->bdaddr,
828 hci_dev_unlock(hdev);
831 static void hci_cc_le_read_buffer_size(struct hci_dev *hdev,
834 struct hci_rp_le_read_buffer_size *rp = (void *) skb->data;
836 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
841 hdev->le_mtu = __le16_to_cpu(rp->le_mtu);
842 hdev->le_pkts = rp->le_max_pkt;
844 hdev->le_cnt = hdev->le_pkts;
846 BT_DBG("%s le mtu %d:%d", hdev->name, hdev->le_mtu, hdev->le_pkts);
848 hci_req_complete(hdev, HCI_OP_LE_READ_BUFFER_SIZE, rp->status);
851 static void hci_cc_le_read_local_features(struct hci_dev *hdev,
854 struct hci_rp_le_read_local_features *rp = (void *) skb->data;
856 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
859 memcpy(hdev->le_features, rp->features, 8);
861 hci_req_complete(hdev, HCI_OP_LE_READ_LOCAL_FEATURES, rp->status);
864 static void hci_cc_le_read_adv_tx_power(struct hci_dev *hdev,
867 struct hci_rp_le_read_adv_tx_power *rp = (void *) skb->data;
869 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
872 hdev->adv_tx_power = rp->tx_power;
873 if (!test_bit(HCI_INIT, &hdev->flags))
877 hci_req_complete(hdev, HCI_OP_LE_READ_ADV_TX_POWER, rp->status);
880 static void hci_cc_le_set_event_mask(struct hci_dev *hdev, struct sk_buff *skb)
882 __u8 status = *((__u8 *) skb->data);
884 BT_DBG("%s status 0x%2.2x", hdev->name, status);
886 hci_req_complete(hdev, HCI_OP_LE_SET_EVENT_MASK, status);
889 static void hci_cc_user_confirm_reply(struct hci_dev *hdev, struct sk_buff *skb)
891 struct hci_rp_user_confirm_reply *rp = (void *) skb->data;
893 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
897 if (test_bit(HCI_MGMT, &hdev->dev_flags))
898 mgmt_user_confirm_reply_complete(hdev, &rp->bdaddr, ACL_LINK, 0,
901 hci_dev_unlock(hdev);
904 static void hci_cc_user_confirm_neg_reply(struct hci_dev *hdev,
907 struct hci_rp_user_confirm_reply *rp = (void *) skb->data;
909 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
913 if (test_bit(HCI_MGMT, &hdev->dev_flags))
914 mgmt_user_confirm_neg_reply_complete(hdev, &rp->bdaddr,
915 ACL_LINK, 0, rp->status);
917 hci_dev_unlock(hdev);
920 static void hci_cc_user_passkey_reply(struct hci_dev *hdev, struct sk_buff *skb)
922 struct hci_rp_user_confirm_reply *rp = (void *) skb->data;
924 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
928 if (test_bit(HCI_MGMT, &hdev->dev_flags))
929 mgmt_user_passkey_reply_complete(hdev, &rp->bdaddr, ACL_LINK,
932 hci_dev_unlock(hdev);
935 static void hci_cc_user_passkey_neg_reply(struct hci_dev *hdev,
938 struct hci_rp_user_confirm_reply *rp = (void *) skb->data;
940 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
944 if (test_bit(HCI_MGMT, &hdev->dev_flags))
945 mgmt_user_passkey_neg_reply_complete(hdev, &rp->bdaddr,
946 ACL_LINK, 0, rp->status);
948 hci_dev_unlock(hdev);
951 static void hci_cc_read_local_oob_data_reply(struct hci_dev *hdev,
954 struct hci_rp_read_local_oob_data *rp = (void *) skb->data;
956 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
959 mgmt_read_local_oob_data_reply_complete(hdev, rp->hash,
960 rp->randomizer, rp->status);
961 hci_dev_unlock(hdev);
964 static void hci_cc_le_set_adv_enable(struct hci_dev *hdev, struct sk_buff *skb)
966 __u8 *sent, status = *((__u8 *) skb->data);
968 BT_DBG("%s status 0x%2.2x", hdev->name, status);
970 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADV_ENABLE);
978 set_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags);
980 clear_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags);
983 hci_dev_unlock(hdev);
985 if (!test_bit(HCI_INIT, &hdev->flags))
988 hci_req_complete(hdev, HCI_OP_LE_SET_ADV_ENABLE, status);
991 static void hci_cc_le_set_scan_param(struct hci_dev *hdev, struct sk_buff *skb)
993 __u8 status = *((__u8 *) skb->data);
995 BT_DBG("%s status 0x%2.2x", hdev->name, status);
997 hci_req_complete(hdev, HCI_OP_LE_SET_SCAN_PARAM, status);
1001 mgmt_start_discovery_failed(hdev, status);
1002 hci_dev_unlock(hdev);
1007 static void hci_cc_le_set_scan_enable(struct hci_dev *hdev,
1008 struct sk_buff *skb)
1010 struct hci_cp_le_set_scan_enable *cp;
1011 __u8 status = *((__u8 *) skb->data);
1013 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1015 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_SCAN_ENABLE);
1019 switch (cp->enable) {
1020 case LE_SCANNING_ENABLED:
1021 hci_req_complete(hdev, HCI_OP_LE_SET_SCAN_ENABLE, status);
1025 mgmt_start_discovery_failed(hdev, status);
1026 hci_dev_unlock(hdev);
1030 set_bit(HCI_LE_SCAN, &hdev->dev_flags);
1033 hci_discovery_set_state(hdev, DISCOVERY_FINDING);
1034 hci_dev_unlock(hdev);
1037 case LE_SCANNING_DISABLED:
1040 mgmt_stop_discovery_failed(hdev, status);
1041 hci_dev_unlock(hdev);
1045 clear_bit(HCI_LE_SCAN, &hdev->dev_flags);
1047 if (hdev->discovery.type == DISCOV_TYPE_INTERLEAVED &&
1048 hdev->discovery.state == DISCOVERY_FINDING) {
1049 mgmt_interleaved_discovery(hdev);
1052 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
1053 hci_dev_unlock(hdev);
1059 BT_ERR("Used reserved LE_Scan_Enable param %d", cp->enable);
1064 static void hci_cc_le_read_white_list_size(struct hci_dev *hdev,
1065 struct sk_buff *skb)
1067 struct hci_rp_le_read_white_list_size *rp = (void *) skb->data;
1069 BT_DBG("%s status 0x%2.2x size %u", hdev->name, rp->status, rp->size);
1072 hdev->le_white_list_size = rp->size;
1074 hci_req_complete(hdev, HCI_OP_LE_READ_WHITE_LIST_SIZE, rp->status);
1077 static void hci_cc_le_ltk_reply(struct hci_dev *hdev, struct sk_buff *skb)
1079 struct hci_rp_le_ltk_reply *rp = (void *) skb->data;
1081 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
1086 hci_req_complete(hdev, HCI_OP_LE_LTK_REPLY, rp->status);
1089 static void hci_cc_le_ltk_neg_reply(struct hci_dev *hdev, struct sk_buff *skb)
1091 struct hci_rp_le_ltk_neg_reply *rp = (void *) skb->data;
1093 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
1098 hci_req_complete(hdev, HCI_OP_LE_LTK_NEG_REPLY, rp->status);
1101 static void hci_cc_le_read_supported_states(struct hci_dev *hdev,
1102 struct sk_buff *skb)
1104 struct hci_rp_le_read_supported_states *rp = (void *) skb->data;
1106 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
1109 memcpy(hdev->le_states, rp->le_states, 8);
1111 hci_req_complete(hdev, HCI_OP_LE_READ_SUPPORTED_STATES, rp->status);
1114 static void hci_cc_write_le_host_supported(struct hci_dev *hdev,
1115 struct sk_buff *skb)
1117 struct hci_cp_write_le_host_supported *sent;
1118 __u8 status = *((__u8 *) skb->data);
1120 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1122 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED);
1128 hdev->host_features[0] |= LMP_HOST_LE;
1130 hdev->host_features[0] &= ~LMP_HOST_LE;
1133 hdev->host_features[0] |= LMP_HOST_LE_BREDR;
1135 hdev->host_features[0] &= ~LMP_HOST_LE_BREDR;
1138 if (test_bit(HCI_MGMT, &hdev->dev_flags) &&
1139 !test_bit(HCI_INIT, &hdev->flags))
1140 mgmt_le_enable_complete(hdev, sent->le, status);
1142 hci_req_complete(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED, status);
1145 static void hci_cc_write_remote_amp_assoc(struct hci_dev *hdev,
1146 struct sk_buff *skb)
1148 struct hci_rp_write_remote_amp_assoc *rp = (void *) skb->data;
1150 BT_DBG("%s status 0x%2.2x phy_handle 0x%2.2x",
1151 hdev->name, rp->status, rp->phy_handle);
1156 amp_write_rem_assoc_continue(hdev, rp->phy_handle);
1159 static void hci_cs_inquiry(struct hci_dev *hdev, __u8 status)
1161 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1164 hci_req_complete(hdev, HCI_OP_INQUIRY, status);
1165 hci_conn_check_pending(hdev);
1167 if (test_bit(HCI_MGMT, &hdev->dev_flags))
1168 mgmt_start_discovery_failed(hdev, status);
1169 hci_dev_unlock(hdev);
1173 set_bit(HCI_INQUIRY, &hdev->flags);
1176 hci_discovery_set_state(hdev, DISCOVERY_FINDING);
1177 hci_dev_unlock(hdev);
1180 static void hci_cs_create_conn(struct hci_dev *hdev, __u8 status)
1182 struct hci_cp_create_conn *cp;
1183 struct hci_conn *conn;
1185 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1187 cp = hci_sent_cmd_data(hdev, HCI_OP_CREATE_CONN);
1193 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
1195 BT_DBG("%s bdaddr %pMR hcon %p", hdev->name, &cp->bdaddr, conn);
1198 if (conn && conn->state == BT_CONNECT) {
1199 if (status != 0x0c || conn->attempt > 2) {
1200 conn->state = BT_CLOSED;
1201 hci_proto_connect_cfm(conn, status);
1204 conn->state = BT_CONNECT2;
1208 conn = hci_conn_add(hdev, ACL_LINK, &cp->bdaddr);
1211 conn->link_mode |= HCI_LM_MASTER;
1213 BT_ERR("No memory for new connection");
1217 hci_dev_unlock(hdev);
1220 static void hci_cs_add_sco(struct hci_dev *hdev, __u8 status)
1222 struct hci_cp_add_sco *cp;
1223 struct hci_conn *acl, *sco;
1226 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1231 cp = hci_sent_cmd_data(hdev, HCI_OP_ADD_SCO);
1235 handle = __le16_to_cpu(cp->handle);
1237 BT_DBG("%s handle 0x%4.4x", hdev->name, handle);
1241 acl = hci_conn_hash_lookup_handle(hdev, handle);
1245 sco->state = BT_CLOSED;
1247 hci_proto_connect_cfm(sco, status);
1252 hci_dev_unlock(hdev);
1255 static void hci_cs_auth_requested(struct hci_dev *hdev, __u8 status)
1257 struct hci_cp_auth_requested *cp;
1258 struct hci_conn *conn;
1260 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1265 cp = hci_sent_cmd_data(hdev, HCI_OP_AUTH_REQUESTED);
1271 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
1273 if (conn->state == BT_CONFIG) {
1274 hci_proto_connect_cfm(conn, status);
1279 hci_dev_unlock(hdev);
1282 static void hci_cs_set_conn_encrypt(struct hci_dev *hdev, __u8 status)
1284 struct hci_cp_set_conn_encrypt *cp;
1285 struct hci_conn *conn;
1287 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1292 cp = hci_sent_cmd_data(hdev, HCI_OP_SET_CONN_ENCRYPT);
1298 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
1300 if (conn->state == BT_CONFIG) {
1301 hci_proto_connect_cfm(conn, status);
1306 hci_dev_unlock(hdev);
1309 static int hci_outgoing_auth_needed(struct hci_dev *hdev,
1310 struct hci_conn *conn)
1312 if (conn->state != BT_CONFIG || !conn->out)
1315 if (conn->pending_sec_level == BT_SECURITY_SDP)
1318 /* Only request authentication for SSP connections or non-SSP
1319 * devices with sec_level HIGH or if MITM protection is requested */
1320 if (!hci_conn_ssp_enabled(conn) && !(conn->auth_type & 0x01) &&
1321 conn->pending_sec_level != BT_SECURITY_HIGH)
1327 static int hci_resolve_name(struct hci_dev *hdev,
1328 struct inquiry_entry *e)
1330 struct hci_cp_remote_name_req cp;
1332 memset(&cp, 0, sizeof(cp));
1334 bacpy(&cp.bdaddr, &e->data.bdaddr);
1335 cp.pscan_rep_mode = e->data.pscan_rep_mode;
1336 cp.pscan_mode = e->data.pscan_mode;
1337 cp.clock_offset = e->data.clock_offset;
1339 return hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp);
1342 static bool hci_resolve_next_name(struct hci_dev *hdev)
1344 struct discovery_state *discov = &hdev->discovery;
1345 struct inquiry_entry *e;
1347 if (list_empty(&discov->resolve))
1350 e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, NAME_NEEDED);
1354 if (hci_resolve_name(hdev, e) == 0) {
1355 e->name_state = NAME_PENDING;
1362 static void hci_check_pending_name(struct hci_dev *hdev, struct hci_conn *conn,
1363 bdaddr_t *bdaddr, u8 *name, u8 name_len)
1365 struct discovery_state *discov = &hdev->discovery;
1366 struct inquiry_entry *e;
1368 if (conn && !test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
1369 mgmt_device_connected(hdev, bdaddr, ACL_LINK, 0x00, 0, name,
1370 name_len, conn->dev_class);
1372 if (discov->state == DISCOVERY_STOPPED)
1375 if (discov->state == DISCOVERY_STOPPING)
1376 goto discov_complete;
1378 if (discov->state != DISCOVERY_RESOLVING)
1381 e = hci_inquiry_cache_lookup_resolve(hdev, bdaddr, NAME_PENDING);
1382 /* If the device was not found in a list of found devices names of which
1383 * are pending. there is no need to continue resolving a next name as it
1384 * will be done upon receiving another Remote Name Request Complete
1391 e->name_state = NAME_KNOWN;
1392 mgmt_remote_name(hdev, bdaddr, ACL_LINK, 0x00,
1393 e->data.rssi, name, name_len);
1395 e->name_state = NAME_NOT_KNOWN;
1398 if (hci_resolve_next_name(hdev))
1402 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
1405 static void hci_cs_remote_name_req(struct hci_dev *hdev, __u8 status)
1407 struct hci_cp_remote_name_req *cp;
1408 struct hci_conn *conn;
1410 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1412 /* If successful wait for the name req complete event before
1413 * checking for the need to do authentication */
1417 cp = hci_sent_cmd_data(hdev, HCI_OP_REMOTE_NAME_REQ);
1423 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
1425 if (test_bit(HCI_MGMT, &hdev->dev_flags))
1426 hci_check_pending_name(hdev, conn, &cp->bdaddr, NULL, 0);
1431 if (!hci_outgoing_auth_needed(hdev, conn))
1434 if (!test_and_set_bit(HCI_CONN_AUTH_PEND, &conn->flags)) {
1435 struct hci_cp_auth_requested cp;
1436 cp.handle = __cpu_to_le16(conn->handle);
1437 hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED, sizeof(cp), &cp);
1441 hci_dev_unlock(hdev);
1444 static void hci_cs_read_remote_features(struct hci_dev *hdev, __u8 status)
1446 struct hci_cp_read_remote_features *cp;
1447 struct hci_conn *conn;
1449 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1454 cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_FEATURES);
1460 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
1462 if (conn->state == BT_CONFIG) {
1463 hci_proto_connect_cfm(conn, status);
1468 hci_dev_unlock(hdev);
1471 static void hci_cs_read_remote_ext_features(struct hci_dev *hdev, __u8 status)
1473 struct hci_cp_read_remote_ext_features *cp;
1474 struct hci_conn *conn;
1476 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1481 cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES);
1487 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
1489 if (conn->state == BT_CONFIG) {
1490 hci_proto_connect_cfm(conn, status);
1495 hci_dev_unlock(hdev);
1498 static void hci_cs_setup_sync_conn(struct hci_dev *hdev, __u8 status)
1500 struct hci_cp_setup_sync_conn *cp;
1501 struct hci_conn *acl, *sco;
1504 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1509 cp = hci_sent_cmd_data(hdev, HCI_OP_SETUP_SYNC_CONN);
1513 handle = __le16_to_cpu(cp->handle);
1515 BT_DBG("%s handle 0x%4.4x", hdev->name, handle);
1519 acl = hci_conn_hash_lookup_handle(hdev, handle);
1523 sco->state = BT_CLOSED;
1525 hci_proto_connect_cfm(sco, status);
1530 hci_dev_unlock(hdev);
1533 static void hci_cs_sniff_mode(struct hci_dev *hdev, __u8 status)
1535 struct hci_cp_sniff_mode *cp;
1536 struct hci_conn *conn;
1538 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1543 cp = hci_sent_cmd_data(hdev, HCI_OP_SNIFF_MODE);
1549 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
1551 clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags);
1553 if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->flags))
1554 hci_sco_setup(conn, status);
1557 hci_dev_unlock(hdev);
1560 static void hci_cs_exit_sniff_mode(struct hci_dev *hdev, __u8 status)
1562 struct hci_cp_exit_sniff_mode *cp;
1563 struct hci_conn *conn;
1565 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1570 cp = hci_sent_cmd_data(hdev, HCI_OP_EXIT_SNIFF_MODE);
1576 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
1578 clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags);
1580 if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->flags))
1581 hci_sco_setup(conn, status);
1584 hci_dev_unlock(hdev);
1587 static void hci_cs_disconnect(struct hci_dev *hdev, u8 status)
1589 struct hci_cp_disconnect *cp;
1590 struct hci_conn *conn;
1595 cp = hci_sent_cmd_data(hdev, HCI_OP_DISCONNECT);
1601 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
1603 mgmt_disconnect_failed(hdev, &conn->dst, conn->type,
1604 conn->dst_type, status);
1606 hci_dev_unlock(hdev);
1609 static void hci_cs_le_create_conn(struct hci_dev *hdev, __u8 status)
1611 struct hci_conn *conn;
1613 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1618 conn = hci_conn_hash_lookup_state(hdev, LE_LINK, BT_CONNECT);
1620 hci_dev_unlock(hdev);
1624 BT_DBG("%s bdaddr %pMR conn %p", hdev->name, &conn->dst, conn);
1626 conn->state = BT_CLOSED;
1627 mgmt_connect_failed(hdev, &conn->dst, conn->type,
1628 conn->dst_type, status);
1629 hci_proto_connect_cfm(conn, status);
1632 hci_dev_unlock(hdev);
1636 static void hci_cs_le_start_enc(struct hci_dev *hdev, u8 status)
1638 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1641 static void hci_cs_create_phylink(struct hci_dev *hdev, u8 status)
1643 struct hci_cp_create_phy_link *cp;
1645 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1647 cp = hci_sent_cmd_data(hdev, HCI_OP_CREATE_PHY_LINK);
1654 struct hci_conn *hcon;
1656 hcon = hci_conn_hash_lookup_handle(hdev, cp->phy_handle);
1660 amp_write_remote_assoc(hdev, cp->phy_handle);
1663 hci_dev_unlock(hdev);
1666 static void hci_cs_accept_phylink(struct hci_dev *hdev, u8 status)
1668 struct hci_cp_accept_phy_link *cp;
1670 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1675 cp = hci_sent_cmd_data(hdev, HCI_OP_ACCEPT_PHY_LINK);
1679 amp_write_remote_assoc(hdev, cp->phy_handle);
1682 static void hci_cs_create_logical_link(struct hci_dev *hdev, u8 status)
1684 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1687 static void hci_inquiry_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1689 __u8 status = *((__u8 *) skb->data);
1690 struct discovery_state *discov = &hdev->discovery;
1691 struct inquiry_entry *e;
1693 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1695 hci_req_complete(hdev, HCI_OP_INQUIRY, status);
1697 hci_conn_check_pending(hdev);
1699 if (!test_and_clear_bit(HCI_INQUIRY, &hdev->flags))
1702 if (!test_bit(HCI_MGMT, &hdev->dev_flags))
1707 if (discov->state != DISCOVERY_FINDING)
1710 if (list_empty(&discov->resolve)) {
1711 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
1715 e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, NAME_NEEDED);
1716 if (e && hci_resolve_name(hdev, e) == 0) {
1717 e->name_state = NAME_PENDING;
1718 hci_discovery_set_state(hdev, DISCOVERY_RESOLVING);
1720 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
1724 hci_dev_unlock(hdev);
1727 static void hci_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *skb)
1729 struct inquiry_data data;
1730 struct inquiry_info *info = (void *) (skb->data + 1);
1731 int num_rsp = *((__u8 *) skb->data);
1733 BT_DBG("%s num_rsp %d", hdev->name, num_rsp);
1738 if (test_bit(HCI_PERIODIC_INQ, &hdev->dev_flags))
1743 for (; num_rsp; num_rsp--, info++) {
1744 bool name_known, ssp;
1746 bacpy(&data.bdaddr, &info->bdaddr);
1747 data.pscan_rep_mode = info->pscan_rep_mode;
1748 data.pscan_period_mode = info->pscan_period_mode;
1749 data.pscan_mode = info->pscan_mode;
1750 memcpy(data.dev_class, info->dev_class, 3);
1751 data.clock_offset = info->clock_offset;
1753 data.ssp_mode = 0x00;
1755 name_known = hci_inquiry_cache_update(hdev, &data, false, &ssp);
1756 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00,
1757 info->dev_class, 0, !name_known, ssp, NULL,
1761 hci_dev_unlock(hdev);
1764 static void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1766 struct hci_ev_conn_complete *ev = (void *) skb->data;
1767 struct hci_conn *conn;
1769 BT_DBG("%s", hdev->name);
1773 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr);
1775 if (ev->link_type != SCO_LINK)
1778 conn = hci_conn_hash_lookup_ba(hdev, ESCO_LINK, &ev->bdaddr);
1782 conn->type = SCO_LINK;
1786 conn->handle = __le16_to_cpu(ev->handle);
1788 if (conn->type == ACL_LINK) {
1789 conn->state = BT_CONFIG;
1790 hci_conn_hold(conn);
1792 if (!conn->out && !hci_conn_ssp_enabled(conn) &&
1793 !hci_find_link_key(hdev, &ev->bdaddr))
1794 conn->disc_timeout = HCI_PAIRING_TIMEOUT;
1796 conn->disc_timeout = HCI_DISCONN_TIMEOUT;
1798 conn->state = BT_CONNECTED;
1800 hci_conn_hold_device(conn);
1801 hci_conn_add_sysfs(conn);
1803 if (test_bit(HCI_AUTH, &hdev->flags))
1804 conn->link_mode |= HCI_LM_AUTH;
1806 if (test_bit(HCI_ENCRYPT, &hdev->flags))
1807 conn->link_mode |= HCI_LM_ENCRYPT;
1809 /* Get remote features */
1810 if (conn->type == ACL_LINK) {
1811 struct hci_cp_read_remote_features cp;
1812 cp.handle = ev->handle;
1813 hci_send_cmd(hdev, HCI_OP_READ_REMOTE_FEATURES,
1817 /* Set packet type for incoming connection */
1818 if (!conn->out && hdev->hci_ver < BLUETOOTH_VER_2_0) {
1819 struct hci_cp_change_conn_ptype cp;
1820 cp.handle = ev->handle;
1821 cp.pkt_type = cpu_to_le16(conn->pkt_type);
1822 hci_send_cmd(hdev, HCI_OP_CHANGE_CONN_PTYPE, sizeof(cp),
1826 conn->state = BT_CLOSED;
1827 if (conn->type == ACL_LINK)
1828 mgmt_connect_failed(hdev, &ev->bdaddr, conn->type,
1829 conn->dst_type, ev->status);
1832 if (conn->type == ACL_LINK)
1833 hci_sco_setup(conn, ev->status);
1836 hci_proto_connect_cfm(conn, ev->status);
1838 } else if (ev->link_type != ACL_LINK)
1839 hci_proto_connect_cfm(conn, ev->status);
1842 hci_dev_unlock(hdev);
1844 hci_conn_check_pending(hdev);
1847 void hci_conn_accept(struct hci_conn *conn, int mask)
1849 struct hci_dev *hdev = conn->hdev;
1851 BT_DBG("conn %p", conn);
1853 conn->state = BT_CONFIG;
1855 if (!lmp_esco_capable(hdev)) {
1856 struct hci_cp_accept_conn_req cp;
1858 bacpy(&cp.bdaddr, &conn->dst);
1860 if (lmp_rswitch_capable(hdev) && (mask & HCI_LM_MASTER))
1861 cp.role = 0x00; /* Become master */
1863 cp.role = 0x01; /* Remain slave */
1865 hci_send_cmd(hdev, HCI_OP_ACCEPT_CONN_REQ, sizeof(cp), &cp);
1866 } else /* lmp_esco_capable(hdev)) */ {
1867 struct hci_cp_accept_sync_conn_req cp;
1869 bacpy(&cp.bdaddr, &conn->dst);
1870 cp.pkt_type = cpu_to_le16(conn->pkt_type);
1872 cp.tx_bandwidth = __constant_cpu_to_le32(0x00001f40);
1873 cp.rx_bandwidth = __constant_cpu_to_le32(0x00001f40);
1874 cp.max_latency = __constant_cpu_to_le16(0xffff);
1875 cp.content_format = cpu_to_le16(hdev->voice_setting);
1876 cp.retrans_effort = 0xff;
1878 hci_send_cmd(hdev, HCI_OP_ACCEPT_SYNC_CONN_REQ,
1883 static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
1885 struct hci_ev_conn_request *ev = (void *) skb->data;
1886 int mask = hdev->link_mode;
1889 BT_DBG("%s bdaddr %pMR type 0x%x", hdev->name, &ev->bdaddr,
1892 mask |= hci_proto_connect_ind(hdev, &ev->bdaddr, ev->link_type,
1895 if ((mask & HCI_LM_ACCEPT) &&
1896 !hci_blacklist_lookup(hdev, &ev->bdaddr)) {
1897 /* Connection accepted */
1898 struct inquiry_entry *ie;
1899 struct hci_conn *conn;
1903 ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr);
1905 memcpy(ie->data.dev_class, ev->dev_class, 3);
1907 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type,
1910 conn = hci_conn_add(hdev, ev->link_type, &ev->bdaddr);
1912 BT_ERR("No memory for new connection");
1913 hci_dev_unlock(hdev);
1918 memcpy(conn->dev_class, ev->dev_class, 3);
1920 hci_dev_unlock(hdev);
1922 if (ev->link_type == ACL_LINK ||
1923 (!(flags & HCI_PROTO_DEFER) && !lmp_esco_capable(hdev))) {
1924 struct hci_cp_accept_conn_req cp;
1925 conn->state = BT_CONNECT;
1927 bacpy(&cp.bdaddr, &ev->bdaddr);
1929 if (lmp_rswitch_capable(hdev) && (mask & HCI_LM_MASTER))
1930 cp.role = 0x00; /* Become master */
1932 cp.role = 0x01; /* Remain slave */
1934 hci_send_cmd(hdev, HCI_OP_ACCEPT_CONN_REQ, sizeof(cp),
1936 } else if (!(flags & HCI_PROTO_DEFER)) {
1937 struct hci_cp_accept_sync_conn_req cp;
1938 conn->state = BT_CONNECT;
1940 bacpy(&cp.bdaddr, &ev->bdaddr);
1941 cp.pkt_type = cpu_to_le16(conn->pkt_type);
1943 cp.tx_bandwidth = __constant_cpu_to_le32(0x00001f40);
1944 cp.rx_bandwidth = __constant_cpu_to_le32(0x00001f40);
1945 cp.max_latency = __constant_cpu_to_le16(0xffff);
1946 cp.content_format = cpu_to_le16(hdev->voice_setting);
1947 cp.retrans_effort = 0xff;
1949 hci_send_cmd(hdev, HCI_OP_ACCEPT_SYNC_CONN_REQ,
1952 conn->state = BT_CONNECT2;
1953 hci_proto_connect_cfm(conn, 0);
1957 /* Connection rejected */
1958 struct hci_cp_reject_conn_req cp;
1960 bacpy(&cp.bdaddr, &ev->bdaddr);
1961 cp.reason = HCI_ERROR_REJ_BAD_ADDR;
1962 hci_send_cmd(hdev, HCI_OP_REJECT_CONN_REQ, sizeof(cp), &cp);
1966 static u8 hci_to_mgmt_reason(u8 err)
1969 case HCI_ERROR_CONNECTION_TIMEOUT:
1970 return MGMT_DEV_DISCONN_TIMEOUT;
1971 case HCI_ERROR_REMOTE_USER_TERM:
1972 case HCI_ERROR_REMOTE_LOW_RESOURCES:
1973 case HCI_ERROR_REMOTE_POWER_OFF:
1974 return MGMT_DEV_DISCONN_REMOTE;
1975 case HCI_ERROR_LOCAL_HOST_TERM:
1976 return MGMT_DEV_DISCONN_LOCAL_HOST;
1978 return MGMT_DEV_DISCONN_UNKNOWN;
1982 static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1984 struct hci_ev_disconn_complete *ev = (void *) skb->data;
1985 struct hci_conn *conn;
1987 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
1991 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
1995 if (ev->status == 0)
1996 conn->state = BT_CLOSED;
1998 if (test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags) &&
1999 (conn->type == ACL_LINK || conn->type == LE_LINK)) {
2001 mgmt_disconnect_failed(hdev, &conn->dst, conn->type,
2002 conn->dst_type, ev->status);
2004 u8 reason = hci_to_mgmt_reason(ev->reason);
2006 mgmt_device_disconnected(hdev, &conn->dst, conn->type,
2007 conn->dst_type, reason);
2011 if (ev->status == 0) {
2012 if (conn->type == ACL_LINK && conn->flush_key)
2013 hci_remove_link_key(hdev, &conn->dst);
2014 hci_proto_disconn_cfm(conn, ev->reason);
2019 hci_dev_unlock(hdev);
2022 static void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
2024 struct hci_ev_auth_complete *ev = (void *) skb->data;
2025 struct hci_conn *conn;
2027 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
2031 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
2036 if (!hci_conn_ssp_enabled(conn) &&
2037 test_bit(HCI_CONN_REAUTH_PEND, &conn->flags)) {
2038 BT_INFO("re-auth of legacy device is not possible.");
2040 conn->link_mode |= HCI_LM_AUTH;
2041 conn->sec_level = conn->pending_sec_level;
2044 mgmt_auth_failed(hdev, &conn->dst, conn->type, conn->dst_type,
2048 clear_bit(HCI_CONN_AUTH_PEND, &conn->flags);
2049 clear_bit(HCI_CONN_REAUTH_PEND, &conn->flags);
2051 if (conn->state == BT_CONFIG) {
2052 if (!ev->status && hci_conn_ssp_enabled(conn)) {
2053 struct hci_cp_set_conn_encrypt cp;
2054 cp.handle = ev->handle;
2056 hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT, sizeof(cp),
2059 conn->state = BT_CONNECTED;
2060 hci_proto_connect_cfm(conn, ev->status);
2064 hci_auth_cfm(conn, ev->status);
2066 hci_conn_hold(conn);
2067 conn->disc_timeout = HCI_DISCONN_TIMEOUT;
2071 if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) {
2073 struct hci_cp_set_conn_encrypt cp;
2074 cp.handle = ev->handle;
2076 hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT, sizeof(cp),
2079 clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags);
2080 hci_encrypt_cfm(conn, ev->status, 0x00);
2085 hci_dev_unlock(hdev);
2088 static void hci_remote_name_evt(struct hci_dev *hdev, struct sk_buff *skb)
2090 struct hci_ev_remote_name *ev = (void *) skb->data;
2091 struct hci_conn *conn;
2093 BT_DBG("%s", hdev->name);
2095 hci_conn_check_pending(hdev);
2099 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
2101 if (!test_bit(HCI_MGMT, &hdev->dev_flags))
2104 if (ev->status == 0)
2105 hci_check_pending_name(hdev, conn, &ev->bdaddr, ev->name,
2106 strnlen(ev->name, HCI_MAX_NAME_LENGTH));
2108 hci_check_pending_name(hdev, conn, &ev->bdaddr, NULL, 0);
2114 if (!hci_outgoing_auth_needed(hdev, conn))
2117 if (!test_and_set_bit(HCI_CONN_AUTH_PEND, &conn->flags)) {
2118 struct hci_cp_auth_requested cp;
2119 cp.handle = __cpu_to_le16(conn->handle);
2120 hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED, sizeof(cp), &cp);
2124 hci_dev_unlock(hdev);
2127 static void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
2129 struct hci_ev_encrypt_change *ev = (void *) skb->data;
2130 struct hci_conn *conn;
2132 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
2136 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
2140 /* Encryption implies authentication */
2141 conn->link_mode |= HCI_LM_AUTH;
2142 conn->link_mode |= HCI_LM_ENCRYPT;
2143 conn->sec_level = conn->pending_sec_level;
2145 conn->link_mode &= ~HCI_LM_ENCRYPT;
2148 clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags);
2150 if (ev->status && conn->state == BT_CONNECTED) {
2151 hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE);
2156 if (conn->state == BT_CONFIG) {
2158 conn->state = BT_CONNECTED;
2160 hci_proto_connect_cfm(conn, ev->status);
2163 hci_encrypt_cfm(conn, ev->status, ev->encrypt);
2167 hci_dev_unlock(hdev);
2170 static void hci_change_link_key_complete_evt(struct hci_dev *hdev,
2171 struct sk_buff *skb)
2173 struct hci_ev_change_link_key_complete *ev = (void *) skb->data;
2174 struct hci_conn *conn;
2176 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
2180 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
2183 conn->link_mode |= HCI_LM_SECURE;
2185 clear_bit(HCI_CONN_AUTH_PEND, &conn->flags);
2187 hci_key_change_cfm(conn, ev->status);
2190 hci_dev_unlock(hdev);
2193 static void hci_remote_features_evt(struct hci_dev *hdev,
2194 struct sk_buff *skb)
2196 struct hci_ev_remote_features *ev = (void *) skb->data;
2197 struct hci_conn *conn;
2199 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
2203 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
2208 memcpy(conn->features, ev->features, 8);
2210 if (conn->state != BT_CONFIG)
2213 if (!ev->status && lmp_ssp_capable(hdev) && lmp_ssp_capable(conn)) {
2214 struct hci_cp_read_remote_ext_features cp;
2215 cp.handle = ev->handle;
2217 hci_send_cmd(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES,
2222 if (!ev->status && !test_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) {
2223 struct hci_cp_remote_name_req cp;
2224 memset(&cp, 0, sizeof(cp));
2225 bacpy(&cp.bdaddr, &conn->dst);
2226 cp.pscan_rep_mode = 0x02;
2227 hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp);
2228 } else if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
2229 mgmt_device_connected(hdev, &conn->dst, conn->type,
2230 conn->dst_type, 0, NULL, 0,
2233 if (!hci_outgoing_auth_needed(hdev, conn)) {
2234 conn->state = BT_CONNECTED;
2235 hci_proto_connect_cfm(conn, ev->status);
2240 hci_dev_unlock(hdev);
2243 static void hci_remote_version_evt(struct hci_dev *hdev, struct sk_buff *skb)
2245 BT_DBG("%s", hdev->name);
2248 static void hci_qos_setup_complete_evt(struct hci_dev *hdev,
2249 struct sk_buff *skb)
2251 BT_DBG("%s", hdev->name);
2254 static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
2256 struct hci_ev_cmd_complete *ev = (void *) skb->data;
2259 skb_pull(skb, sizeof(*ev));
2261 opcode = __le16_to_cpu(ev->opcode);
2264 case HCI_OP_INQUIRY_CANCEL:
2265 hci_cc_inquiry_cancel(hdev, skb);
2268 case HCI_OP_PERIODIC_INQ:
2269 hci_cc_periodic_inq(hdev, skb);
2272 case HCI_OP_EXIT_PERIODIC_INQ:
2273 hci_cc_exit_periodic_inq(hdev, skb);
2276 case HCI_OP_REMOTE_NAME_REQ_CANCEL:
2277 hci_cc_remote_name_req_cancel(hdev, skb);
2280 case HCI_OP_ROLE_DISCOVERY:
2281 hci_cc_role_discovery(hdev, skb);
2284 case HCI_OP_READ_LINK_POLICY:
2285 hci_cc_read_link_policy(hdev, skb);
2288 case HCI_OP_WRITE_LINK_POLICY:
2289 hci_cc_write_link_policy(hdev, skb);
2292 case HCI_OP_READ_DEF_LINK_POLICY:
2293 hci_cc_read_def_link_policy(hdev, skb);
2296 case HCI_OP_WRITE_DEF_LINK_POLICY:
2297 hci_cc_write_def_link_policy(hdev, skb);
2301 hci_cc_reset(hdev, skb);
2304 case HCI_OP_WRITE_LOCAL_NAME:
2305 hci_cc_write_local_name(hdev, skb);
2308 case HCI_OP_READ_LOCAL_NAME:
2309 hci_cc_read_local_name(hdev, skb);
2312 case HCI_OP_WRITE_AUTH_ENABLE:
2313 hci_cc_write_auth_enable(hdev, skb);
2316 case HCI_OP_WRITE_ENCRYPT_MODE:
2317 hci_cc_write_encrypt_mode(hdev, skb);
2320 case HCI_OP_WRITE_SCAN_ENABLE:
2321 hci_cc_write_scan_enable(hdev, skb);
2324 case HCI_OP_READ_CLASS_OF_DEV:
2325 hci_cc_read_class_of_dev(hdev, skb);
2328 case HCI_OP_WRITE_CLASS_OF_DEV:
2329 hci_cc_write_class_of_dev(hdev, skb);
2332 case HCI_OP_READ_VOICE_SETTING:
2333 hci_cc_read_voice_setting(hdev, skb);
2336 case HCI_OP_WRITE_VOICE_SETTING:
2337 hci_cc_write_voice_setting(hdev, skb);
2340 case HCI_OP_HOST_BUFFER_SIZE:
2341 hci_cc_host_buffer_size(hdev, skb);
2344 case HCI_OP_WRITE_SSP_MODE:
2345 hci_cc_write_ssp_mode(hdev, skb);
2348 case HCI_OP_READ_LOCAL_VERSION:
2349 hci_cc_read_local_version(hdev, skb);
2352 case HCI_OP_READ_LOCAL_COMMANDS:
2353 hci_cc_read_local_commands(hdev, skb);
2356 case HCI_OP_READ_LOCAL_FEATURES:
2357 hci_cc_read_local_features(hdev, skb);
2360 case HCI_OP_READ_LOCAL_EXT_FEATURES:
2361 hci_cc_read_local_ext_features(hdev, skb);
2364 case HCI_OP_READ_BUFFER_SIZE:
2365 hci_cc_read_buffer_size(hdev, skb);
2368 case HCI_OP_READ_BD_ADDR:
2369 hci_cc_read_bd_addr(hdev, skb);
2372 case HCI_OP_READ_DATA_BLOCK_SIZE:
2373 hci_cc_read_data_block_size(hdev, skb);
2376 case HCI_OP_WRITE_CA_TIMEOUT:
2377 hci_cc_write_ca_timeout(hdev, skb);
2380 case HCI_OP_READ_FLOW_CONTROL_MODE:
2381 hci_cc_read_flow_control_mode(hdev, skb);
2384 case HCI_OP_READ_LOCAL_AMP_INFO:
2385 hci_cc_read_local_amp_info(hdev, skb);
2388 case HCI_OP_READ_LOCAL_AMP_ASSOC:
2389 hci_cc_read_local_amp_assoc(hdev, skb);
2392 case HCI_OP_DELETE_STORED_LINK_KEY:
2393 hci_cc_delete_stored_link_key(hdev, skb);
2396 case HCI_OP_SET_EVENT_MASK:
2397 hci_cc_set_event_mask(hdev, skb);
2400 case HCI_OP_WRITE_INQUIRY_MODE:
2401 hci_cc_write_inquiry_mode(hdev, skb);
2404 case HCI_OP_READ_INQ_RSP_TX_POWER:
2405 hci_cc_read_inq_rsp_tx_power(hdev, skb);
2408 case HCI_OP_SET_EVENT_FLT:
2409 hci_cc_set_event_flt(hdev, skb);
2412 case HCI_OP_PIN_CODE_REPLY:
2413 hci_cc_pin_code_reply(hdev, skb);
2416 case HCI_OP_PIN_CODE_NEG_REPLY:
2417 hci_cc_pin_code_neg_reply(hdev, skb);
2420 case HCI_OP_READ_LOCAL_OOB_DATA:
2421 hci_cc_read_local_oob_data_reply(hdev, skb);
2424 case HCI_OP_LE_READ_BUFFER_SIZE:
2425 hci_cc_le_read_buffer_size(hdev, skb);
2428 case HCI_OP_LE_READ_LOCAL_FEATURES:
2429 hci_cc_le_read_local_features(hdev, skb);
2432 case HCI_OP_LE_READ_ADV_TX_POWER:
2433 hci_cc_le_read_adv_tx_power(hdev, skb);
2436 case HCI_OP_LE_SET_EVENT_MASK:
2437 hci_cc_le_set_event_mask(hdev, skb);
2440 case HCI_OP_USER_CONFIRM_REPLY:
2441 hci_cc_user_confirm_reply(hdev, skb);
2444 case HCI_OP_USER_CONFIRM_NEG_REPLY:
2445 hci_cc_user_confirm_neg_reply(hdev, skb);
2448 case HCI_OP_USER_PASSKEY_REPLY:
2449 hci_cc_user_passkey_reply(hdev, skb);
2452 case HCI_OP_USER_PASSKEY_NEG_REPLY:
2453 hci_cc_user_passkey_neg_reply(hdev, skb);
2456 case HCI_OP_LE_SET_SCAN_PARAM:
2457 hci_cc_le_set_scan_param(hdev, skb);
2460 case HCI_OP_LE_SET_ADV_ENABLE:
2461 hci_cc_le_set_adv_enable(hdev, skb);
2464 case HCI_OP_LE_SET_SCAN_ENABLE:
2465 hci_cc_le_set_scan_enable(hdev, skb);
2468 case HCI_OP_LE_READ_WHITE_LIST_SIZE:
2469 hci_cc_le_read_white_list_size(hdev, skb);
2472 case HCI_OP_LE_LTK_REPLY:
2473 hci_cc_le_ltk_reply(hdev, skb);
2476 case HCI_OP_LE_LTK_NEG_REPLY:
2477 hci_cc_le_ltk_neg_reply(hdev, skb);
2480 case HCI_OP_LE_READ_SUPPORTED_STATES:
2481 hci_cc_le_read_supported_states(hdev, skb);
2484 case HCI_OP_WRITE_LE_HOST_SUPPORTED:
2485 hci_cc_write_le_host_supported(hdev, skb);
2488 case HCI_OP_WRITE_REMOTE_AMP_ASSOC:
2489 hci_cc_write_remote_amp_assoc(hdev, skb);
2493 BT_DBG("%s opcode 0x%4.4x", hdev->name, opcode);
2497 if (ev->opcode != HCI_OP_NOP)
2498 del_timer(&hdev->cmd_timer);
2500 if (ev->ncmd && !test_bit(HCI_RESET, &hdev->flags)) {
2501 atomic_set(&hdev->cmd_cnt, 1);
2502 if (!skb_queue_empty(&hdev->cmd_q))
2503 queue_work(hdev->workqueue, &hdev->cmd_work);
2507 static void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb)
2509 struct hci_ev_cmd_status *ev = (void *) skb->data;
2512 skb_pull(skb, sizeof(*ev));
2514 opcode = __le16_to_cpu(ev->opcode);
2517 case HCI_OP_INQUIRY:
2518 hci_cs_inquiry(hdev, ev->status);
2521 case HCI_OP_CREATE_CONN:
2522 hci_cs_create_conn(hdev, ev->status);
2525 case HCI_OP_ADD_SCO:
2526 hci_cs_add_sco(hdev, ev->status);
2529 case HCI_OP_AUTH_REQUESTED:
2530 hci_cs_auth_requested(hdev, ev->status);
2533 case HCI_OP_SET_CONN_ENCRYPT:
2534 hci_cs_set_conn_encrypt(hdev, ev->status);
2537 case HCI_OP_REMOTE_NAME_REQ:
2538 hci_cs_remote_name_req(hdev, ev->status);
2541 case HCI_OP_READ_REMOTE_FEATURES:
2542 hci_cs_read_remote_features(hdev, ev->status);
2545 case HCI_OP_READ_REMOTE_EXT_FEATURES:
2546 hci_cs_read_remote_ext_features(hdev, ev->status);
2549 case HCI_OP_SETUP_SYNC_CONN:
2550 hci_cs_setup_sync_conn(hdev, ev->status);
2553 case HCI_OP_SNIFF_MODE:
2554 hci_cs_sniff_mode(hdev, ev->status);
2557 case HCI_OP_EXIT_SNIFF_MODE:
2558 hci_cs_exit_sniff_mode(hdev, ev->status);
2561 case HCI_OP_DISCONNECT:
2562 hci_cs_disconnect(hdev, ev->status);
2565 case HCI_OP_LE_CREATE_CONN:
2566 hci_cs_le_create_conn(hdev, ev->status);
2569 case HCI_OP_LE_START_ENC:
2570 hci_cs_le_start_enc(hdev, ev->status);
2573 case HCI_OP_CREATE_PHY_LINK:
2574 hci_cs_create_phylink(hdev, ev->status);
2577 case HCI_OP_ACCEPT_PHY_LINK:
2578 hci_cs_accept_phylink(hdev, ev->status);
2581 case HCI_OP_CREATE_LOGICAL_LINK:
2582 hci_cs_create_logical_link(hdev, ev->status);
2586 BT_DBG("%s opcode 0x%4.4x", hdev->name, opcode);
2590 if (ev->opcode != HCI_OP_NOP)
2591 del_timer(&hdev->cmd_timer);
2593 if (ev->ncmd && !test_bit(HCI_RESET, &hdev->flags)) {
2594 atomic_set(&hdev->cmd_cnt, 1);
2595 if (!skb_queue_empty(&hdev->cmd_q))
2596 queue_work(hdev->workqueue, &hdev->cmd_work);
2600 static void hci_role_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
2602 struct hci_ev_role_change *ev = (void *) skb->data;
2603 struct hci_conn *conn;
2605 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
2609 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
2613 conn->link_mode &= ~HCI_LM_MASTER;
2615 conn->link_mode |= HCI_LM_MASTER;
2618 clear_bit(HCI_CONN_RSWITCH_PEND, &conn->flags);
2620 hci_role_switch_cfm(conn, ev->status, ev->role);
2623 hci_dev_unlock(hdev);
2626 static void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *skb)
2628 struct hci_ev_num_comp_pkts *ev = (void *) skb->data;
2631 if (hdev->flow_ctl_mode != HCI_FLOW_CTL_MODE_PACKET_BASED) {
2632 BT_ERR("Wrong event for mode %d", hdev->flow_ctl_mode);
2636 if (skb->len < sizeof(*ev) || skb->len < sizeof(*ev) +
2637 ev->num_hndl * sizeof(struct hci_comp_pkts_info)) {
2638 BT_DBG("%s bad parameters", hdev->name);
2642 BT_DBG("%s num_hndl %d", hdev->name, ev->num_hndl);
2644 for (i = 0; i < ev->num_hndl; i++) {
2645 struct hci_comp_pkts_info *info = &ev->handles[i];
2646 struct hci_conn *conn;
2647 __u16 handle, count;
2649 handle = __le16_to_cpu(info->handle);
2650 count = __le16_to_cpu(info->count);
2652 conn = hci_conn_hash_lookup_handle(hdev, handle);
2656 conn->sent -= count;
2658 switch (conn->type) {
2660 hdev->acl_cnt += count;
2661 if (hdev->acl_cnt > hdev->acl_pkts)
2662 hdev->acl_cnt = hdev->acl_pkts;
2666 if (hdev->le_pkts) {
2667 hdev->le_cnt += count;
2668 if (hdev->le_cnt > hdev->le_pkts)
2669 hdev->le_cnt = hdev->le_pkts;
2671 hdev->acl_cnt += count;
2672 if (hdev->acl_cnt > hdev->acl_pkts)
2673 hdev->acl_cnt = hdev->acl_pkts;
2678 hdev->sco_cnt += count;
2679 if (hdev->sco_cnt > hdev->sco_pkts)
2680 hdev->sco_cnt = hdev->sco_pkts;
2684 BT_ERR("Unknown type %d conn %p", conn->type, conn);
2689 queue_work(hdev->workqueue, &hdev->tx_work);
2692 static struct hci_conn *__hci_conn_lookup_handle(struct hci_dev *hdev,
2695 struct hci_chan *chan;
2697 switch (hdev->dev_type) {
2699 return hci_conn_hash_lookup_handle(hdev, handle);
2701 chan = hci_chan_lookup_handle(hdev, handle);
2706 BT_ERR("%s unknown dev_type %d", hdev->name, hdev->dev_type);
2713 static void hci_num_comp_blocks_evt(struct hci_dev *hdev, struct sk_buff *skb)
2715 struct hci_ev_num_comp_blocks *ev = (void *) skb->data;
2718 if (hdev->flow_ctl_mode != HCI_FLOW_CTL_MODE_BLOCK_BASED) {
2719 BT_ERR("Wrong event for mode %d", hdev->flow_ctl_mode);
2723 if (skb->len < sizeof(*ev) || skb->len < sizeof(*ev) +
2724 ev->num_hndl * sizeof(struct hci_comp_blocks_info)) {
2725 BT_DBG("%s bad parameters", hdev->name);
2729 BT_DBG("%s num_blocks %d num_hndl %d", hdev->name, ev->num_blocks,
2732 for (i = 0; i < ev->num_hndl; i++) {
2733 struct hci_comp_blocks_info *info = &ev->handles[i];
2734 struct hci_conn *conn = NULL;
2735 __u16 handle, block_count;
2737 handle = __le16_to_cpu(info->handle);
2738 block_count = __le16_to_cpu(info->blocks);
2740 conn = __hci_conn_lookup_handle(hdev, handle);
2744 conn->sent -= block_count;
2746 switch (conn->type) {
2749 hdev->block_cnt += block_count;
2750 if (hdev->block_cnt > hdev->num_blocks)
2751 hdev->block_cnt = hdev->num_blocks;
2755 BT_ERR("Unknown type %d conn %p", conn->type, conn);
2760 queue_work(hdev->workqueue, &hdev->tx_work);
2763 static void hci_mode_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
2765 struct hci_ev_mode_change *ev = (void *) skb->data;
2766 struct hci_conn *conn;
2768 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
2772 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
2774 conn->mode = ev->mode;
2775 conn->interval = __le16_to_cpu(ev->interval);
2777 if (!test_and_clear_bit(HCI_CONN_MODE_CHANGE_PEND,
2779 if (conn->mode == HCI_CM_ACTIVE)
2780 set_bit(HCI_CONN_POWER_SAVE, &conn->flags);
2782 clear_bit(HCI_CONN_POWER_SAVE, &conn->flags);
2785 if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->flags))
2786 hci_sco_setup(conn, ev->status);
2789 hci_dev_unlock(hdev);
2792 static void hci_pin_code_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
2794 struct hci_ev_pin_code_req *ev = (void *) skb->data;
2795 struct hci_conn *conn;
2797 BT_DBG("%s", hdev->name);
2801 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
2805 if (conn->state == BT_CONNECTED) {
2806 hci_conn_hold(conn);
2807 conn->disc_timeout = HCI_PAIRING_TIMEOUT;
2811 if (!test_bit(HCI_PAIRABLE, &hdev->dev_flags))
2812 hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY,
2813 sizeof(ev->bdaddr), &ev->bdaddr);
2814 else if (test_bit(HCI_MGMT, &hdev->dev_flags)) {
2817 if (conn->pending_sec_level == BT_SECURITY_HIGH)
2822 mgmt_pin_code_request(hdev, &ev->bdaddr, secure);
2826 hci_dev_unlock(hdev);
2829 static void hci_link_key_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
2831 struct hci_ev_link_key_req *ev = (void *) skb->data;
2832 struct hci_cp_link_key_reply cp;
2833 struct hci_conn *conn;
2834 struct link_key *key;
2836 BT_DBG("%s", hdev->name);
2838 if (!test_bit(HCI_LINK_KEYS, &hdev->dev_flags))
2843 key = hci_find_link_key(hdev, &ev->bdaddr);
2845 BT_DBG("%s link key not found for %pMR", hdev->name,
2850 BT_DBG("%s found key type %u for %pMR", hdev->name, key->type,
2853 if (!test_bit(HCI_DEBUG_KEYS, &hdev->dev_flags) &&
2854 key->type == HCI_LK_DEBUG_COMBINATION) {
2855 BT_DBG("%s ignoring debug key", hdev->name);
2859 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
2861 if (key->type == HCI_LK_UNAUTH_COMBINATION &&
2862 conn->auth_type != 0xff && (conn->auth_type & 0x01)) {
2863 BT_DBG("%s ignoring unauthenticated key", hdev->name);
2867 if (key->type == HCI_LK_COMBINATION && key->pin_len < 16 &&
2868 conn->pending_sec_level == BT_SECURITY_HIGH) {
2869 BT_DBG("%s ignoring key unauthenticated for high security",
2874 conn->key_type = key->type;
2875 conn->pin_length = key->pin_len;
2878 bacpy(&cp.bdaddr, &ev->bdaddr);
2879 memcpy(cp.link_key, key->val, HCI_LINK_KEY_SIZE);
2881 hci_send_cmd(hdev, HCI_OP_LINK_KEY_REPLY, sizeof(cp), &cp);
2883 hci_dev_unlock(hdev);
2888 hci_send_cmd(hdev, HCI_OP_LINK_KEY_NEG_REPLY, 6, &ev->bdaddr);
2889 hci_dev_unlock(hdev);
2892 static void hci_link_key_notify_evt(struct hci_dev *hdev, struct sk_buff *skb)
2894 struct hci_ev_link_key_notify *ev = (void *) skb->data;
2895 struct hci_conn *conn;
2898 BT_DBG("%s", hdev->name);
2902 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
2904 hci_conn_hold(conn);
2905 conn->disc_timeout = HCI_DISCONN_TIMEOUT;
2906 pin_len = conn->pin_length;
2908 if (ev->key_type != HCI_LK_CHANGED_COMBINATION)
2909 conn->key_type = ev->key_type;
2914 if (test_bit(HCI_LINK_KEYS, &hdev->dev_flags))
2915 hci_add_link_key(hdev, conn, 1, &ev->bdaddr, ev->link_key,
2916 ev->key_type, pin_len);
2918 hci_dev_unlock(hdev);
2921 static void hci_clock_offset_evt(struct hci_dev *hdev, struct sk_buff *skb)
2923 struct hci_ev_clock_offset *ev = (void *) skb->data;
2924 struct hci_conn *conn;
2926 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
2930 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
2931 if (conn && !ev->status) {
2932 struct inquiry_entry *ie;
2934 ie = hci_inquiry_cache_lookup(hdev, &conn->dst);
2936 ie->data.clock_offset = ev->clock_offset;
2937 ie->timestamp = jiffies;
2941 hci_dev_unlock(hdev);
2944 static void hci_pkt_type_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
2946 struct hci_ev_pkt_type_change *ev = (void *) skb->data;
2947 struct hci_conn *conn;
2949 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
2953 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
2954 if (conn && !ev->status)
2955 conn->pkt_type = __le16_to_cpu(ev->pkt_type);
2957 hci_dev_unlock(hdev);
2960 static void hci_pscan_rep_mode_evt(struct hci_dev *hdev, struct sk_buff *skb)
2962 struct hci_ev_pscan_rep_mode *ev = (void *) skb->data;
2963 struct inquiry_entry *ie;
2965 BT_DBG("%s", hdev->name);
2969 ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr);
2971 ie->data.pscan_rep_mode = ev->pscan_rep_mode;
2972 ie->timestamp = jiffies;
2975 hci_dev_unlock(hdev);
2978 static void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev,
2979 struct sk_buff *skb)
2981 struct inquiry_data data;
2982 int num_rsp = *((__u8 *) skb->data);
2983 bool name_known, ssp;
2985 BT_DBG("%s num_rsp %d", hdev->name, num_rsp);
2990 if (test_bit(HCI_PERIODIC_INQ, &hdev->dev_flags))
2995 if ((skb->len - 1) / num_rsp != sizeof(struct inquiry_info_with_rssi)) {
2996 struct inquiry_info_with_rssi_and_pscan_mode *info;
2997 info = (void *) (skb->data + 1);
2999 for (; num_rsp; num_rsp--, info++) {
3000 bacpy(&data.bdaddr, &info->bdaddr);
3001 data.pscan_rep_mode = info->pscan_rep_mode;
3002 data.pscan_period_mode = info->pscan_period_mode;
3003 data.pscan_mode = info->pscan_mode;
3004 memcpy(data.dev_class, info->dev_class, 3);
3005 data.clock_offset = info->clock_offset;
3006 data.rssi = info->rssi;
3007 data.ssp_mode = 0x00;
3009 name_known = hci_inquiry_cache_update(hdev, &data,
3011 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00,
3012 info->dev_class, info->rssi,
3013 !name_known, ssp, NULL, 0);
3016 struct inquiry_info_with_rssi *info = (void *) (skb->data + 1);
3018 for (; num_rsp; num_rsp--, info++) {
3019 bacpy(&data.bdaddr, &info->bdaddr);
3020 data.pscan_rep_mode = info->pscan_rep_mode;
3021 data.pscan_period_mode = info->pscan_period_mode;
3022 data.pscan_mode = 0x00;
3023 memcpy(data.dev_class, info->dev_class, 3);
3024 data.clock_offset = info->clock_offset;
3025 data.rssi = info->rssi;
3026 data.ssp_mode = 0x00;
3027 name_known = hci_inquiry_cache_update(hdev, &data,
3029 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00,
3030 info->dev_class, info->rssi,
3031 !name_known, ssp, NULL, 0);
3035 hci_dev_unlock(hdev);
3038 static void hci_remote_ext_features_evt(struct hci_dev *hdev,
3039 struct sk_buff *skb)
3041 struct hci_ev_remote_ext_features *ev = (void *) skb->data;
3042 struct hci_conn *conn;
3044 BT_DBG("%s", hdev->name);
3048 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
3052 if (!ev->status && ev->page == 0x01) {
3053 struct inquiry_entry *ie;
3055 ie = hci_inquiry_cache_lookup(hdev, &conn->dst);
3057 ie->data.ssp_mode = (ev->features[0] & LMP_HOST_SSP);
3059 if (ev->features[0] & LMP_HOST_SSP)
3060 set_bit(HCI_CONN_SSP_ENABLED, &conn->flags);
3063 if (conn->state != BT_CONFIG)
3066 if (!ev->status && !test_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) {
3067 struct hci_cp_remote_name_req cp;
3068 memset(&cp, 0, sizeof(cp));
3069 bacpy(&cp.bdaddr, &conn->dst);
3070 cp.pscan_rep_mode = 0x02;
3071 hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp);
3072 } else if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
3073 mgmt_device_connected(hdev, &conn->dst, conn->type,
3074 conn->dst_type, 0, NULL, 0,
3077 if (!hci_outgoing_auth_needed(hdev, conn)) {
3078 conn->state = BT_CONNECTED;
3079 hci_proto_connect_cfm(conn, ev->status);
3084 hci_dev_unlock(hdev);
3087 static void hci_sync_conn_complete_evt(struct hci_dev *hdev,
3088 struct sk_buff *skb)
3090 struct hci_ev_sync_conn_complete *ev = (void *) skb->data;
3091 struct hci_conn *conn;
3093 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
3097 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr);
3099 if (ev->link_type == ESCO_LINK)
3102 conn = hci_conn_hash_lookup_ba(hdev, ESCO_LINK, &ev->bdaddr);
3106 conn->type = SCO_LINK;
3109 switch (ev->status) {
3111 conn->handle = __le16_to_cpu(ev->handle);
3112 conn->state = BT_CONNECTED;
3114 hci_conn_hold_device(conn);
3115 hci_conn_add_sysfs(conn);
3118 case 0x11: /* Unsupported Feature or Parameter Value */
3119 case 0x1c: /* SCO interval rejected */
3120 case 0x1a: /* Unsupported Remote Feature */
3121 case 0x1f: /* Unspecified error */
3122 if (conn->out && conn->attempt < 2) {
3123 conn->pkt_type = (hdev->esco_type & SCO_ESCO_MASK) |
3124 (hdev->esco_type & EDR_ESCO_MASK);
3125 hci_setup_sync(conn, conn->link->handle);
3131 conn->state = BT_CLOSED;
3135 hci_proto_connect_cfm(conn, ev->status);
3140 hci_dev_unlock(hdev);
3143 static void hci_sync_conn_changed_evt(struct hci_dev *hdev, struct sk_buff *skb)
3145 BT_DBG("%s", hdev->name);
3148 static void hci_sniff_subrate_evt(struct hci_dev *hdev, struct sk_buff *skb)
3150 struct hci_ev_sniff_subrate *ev = (void *) skb->data;
3152 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
3155 static void hci_extended_inquiry_result_evt(struct hci_dev *hdev,
3156 struct sk_buff *skb)
3158 struct inquiry_data data;
3159 struct extended_inquiry_info *info = (void *) (skb->data + 1);
3160 int num_rsp = *((__u8 *) skb->data);
3163 BT_DBG("%s num_rsp %d", hdev->name, num_rsp);
3168 if (test_bit(HCI_PERIODIC_INQ, &hdev->dev_flags))
3173 for (; num_rsp; num_rsp--, info++) {
3174 bool name_known, ssp;
3176 bacpy(&data.bdaddr, &info->bdaddr);
3177 data.pscan_rep_mode = info->pscan_rep_mode;
3178 data.pscan_period_mode = info->pscan_period_mode;
3179 data.pscan_mode = 0x00;
3180 memcpy(data.dev_class, info->dev_class, 3);
3181 data.clock_offset = info->clock_offset;
3182 data.rssi = info->rssi;
3183 data.ssp_mode = 0x01;
3185 if (test_bit(HCI_MGMT, &hdev->dev_flags))
3186 name_known = eir_has_data_type(info->data,
3192 name_known = hci_inquiry_cache_update(hdev, &data, name_known,
3194 eir_len = eir_get_length(info->data, sizeof(info->data));
3195 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00,
3196 info->dev_class, info->rssi, !name_known,
3197 ssp, info->data, eir_len);
3200 hci_dev_unlock(hdev);
3203 static void hci_key_refresh_complete_evt(struct hci_dev *hdev,
3204 struct sk_buff *skb)
3206 struct hci_ev_key_refresh_complete *ev = (void *) skb->data;
3207 struct hci_conn *conn;
3209 BT_DBG("%s status 0x%2.2x handle 0x%4.4x", hdev->name, ev->status,
3210 __le16_to_cpu(ev->handle));
3214 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
3219 conn->sec_level = conn->pending_sec_level;
3221 clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags);
3223 if (ev->status && conn->state == BT_CONNECTED) {
3224 hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE);
3229 if (conn->state == BT_CONFIG) {
3231 conn->state = BT_CONNECTED;
3233 hci_proto_connect_cfm(conn, ev->status);
3236 hci_auth_cfm(conn, ev->status);
3238 hci_conn_hold(conn);
3239 conn->disc_timeout = HCI_DISCONN_TIMEOUT;
3244 hci_dev_unlock(hdev);
3247 static u8 hci_get_auth_req(struct hci_conn *conn)
3249 /* If remote requests dedicated bonding follow that lead */
3250 if (conn->remote_auth == 0x02 || conn->remote_auth == 0x03) {
3251 /* If both remote and local IO capabilities allow MITM
3252 * protection then require it, otherwise don't */
3253 if (conn->remote_cap == 0x03 || conn->io_capability == 0x03)
3259 /* If remote requests no-bonding follow that lead */
3260 if (conn->remote_auth == 0x00 || conn->remote_auth == 0x01)
3261 return conn->remote_auth | (conn->auth_type & 0x01);
3263 return conn->auth_type;
3266 static void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
3268 struct hci_ev_io_capa_request *ev = (void *) skb->data;
3269 struct hci_conn *conn;
3271 BT_DBG("%s", hdev->name);
3275 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
3279 hci_conn_hold(conn);
3281 if (!test_bit(HCI_MGMT, &hdev->dev_flags))
3284 if (test_bit(HCI_PAIRABLE, &hdev->dev_flags) ||
3285 (conn->remote_auth & ~0x01) == HCI_AT_NO_BONDING) {
3286 struct hci_cp_io_capability_reply cp;
3288 bacpy(&cp.bdaddr, &ev->bdaddr);
3289 /* Change the IO capability from KeyboardDisplay
3290 * to DisplayYesNo as it is not supported by BT spec. */
3291 cp.capability = (conn->io_capability == 0x04) ?
3292 0x01 : conn->io_capability;
3293 conn->auth_type = hci_get_auth_req(conn);
3294 cp.authentication = conn->auth_type;
3296 if (hci_find_remote_oob_data(hdev, &conn->dst) &&
3297 (conn->out || test_bit(HCI_CONN_REMOTE_OOB, &conn->flags)))
3302 hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_REPLY,
3305 struct hci_cp_io_capability_neg_reply cp;
3307 bacpy(&cp.bdaddr, &ev->bdaddr);
3308 cp.reason = HCI_ERROR_PAIRING_NOT_ALLOWED;
3310 hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_NEG_REPLY,
3315 hci_dev_unlock(hdev);
3318 static void hci_io_capa_reply_evt(struct hci_dev *hdev, struct sk_buff *skb)
3320 struct hci_ev_io_capa_reply *ev = (void *) skb->data;
3321 struct hci_conn *conn;
3323 BT_DBG("%s", hdev->name);
3327 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
3331 conn->remote_cap = ev->capability;
3332 conn->remote_auth = ev->authentication;
3334 set_bit(HCI_CONN_REMOTE_OOB, &conn->flags);
3337 hci_dev_unlock(hdev);
3340 static void hci_user_confirm_request_evt(struct hci_dev *hdev,
3341 struct sk_buff *skb)
3343 struct hci_ev_user_confirm_req *ev = (void *) skb->data;
3344 int loc_mitm, rem_mitm, confirm_hint = 0;
3345 struct hci_conn *conn;
3347 BT_DBG("%s", hdev->name);
3351 if (!test_bit(HCI_MGMT, &hdev->dev_flags))
3354 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
3358 loc_mitm = (conn->auth_type & 0x01);
3359 rem_mitm = (conn->remote_auth & 0x01);
3361 /* If we require MITM but the remote device can't provide that
3362 * (it has NoInputNoOutput) then reject the confirmation
3363 * request. The only exception is when we're dedicated bonding
3364 * initiators (connect_cfm_cb set) since then we always have the MITM
3366 if (!conn->connect_cfm_cb && loc_mitm && conn->remote_cap == 0x03) {
3367 BT_DBG("Rejecting request: remote device can't provide MITM");
3368 hci_send_cmd(hdev, HCI_OP_USER_CONFIRM_NEG_REPLY,
3369 sizeof(ev->bdaddr), &ev->bdaddr);
3373 /* If no side requires MITM protection; auto-accept */
3374 if ((!loc_mitm || conn->remote_cap == 0x03) &&
3375 (!rem_mitm || conn->io_capability == 0x03)) {
3377 /* If we're not the initiators request authorization to
3378 * proceed from user space (mgmt_user_confirm with
3379 * confirm_hint set to 1). */
3380 if (!test_bit(HCI_CONN_AUTH_PEND, &conn->flags)) {
3381 BT_DBG("Confirming auto-accept as acceptor");
3386 BT_DBG("Auto-accept of user confirmation with %ums delay",
3387 hdev->auto_accept_delay);
3389 if (hdev->auto_accept_delay > 0) {
3390 int delay = msecs_to_jiffies(hdev->auto_accept_delay);
3391 mod_timer(&conn->auto_accept_timer, jiffies + delay);
3395 hci_send_cmd(hdev, HCI_OP_USER_CONFIRM_REPLY,
3396 sizeof(ev->bdaddr), &ev->bdaddr);
3401 mgmt_user_confirm_request(hdev, &ev->bdaddr, ACL_LINK, 0, ev->passkey,
3405 hci_dev_unlock(hdev);
3408 static void hci_user_passkey_request_evt(struct hci_dev *hdev,
3409 struct sk_buff *skb)
3411 struct hci_ev_user_passkey_req *ev = (void *) skb->data;
3413 BT_DBG("%s", hdev->name);
3415 if (test_bit(HCI_MGMT, &hdev->dev_flags))
3416 mgmt_user_passkey_request(hdev, &ev->bdaddr, ACL_LINK, 0);
3419 static void hci_user_passkey_notify_evt(struct hci_dev *hdev,
3420 struct sk_buff *skb)
3422 struct hci_ev_user_passkey_notify *ev = (void *) skb->data;
3423 struct hci_conn *conn;
3425 BT_DBG("%s", hdev->name);
3427 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
3431 conn->passkey_notify = __le32_to_cpu(ev->passkey);
3432 conn->passkey_entered = 0;
3434 if (test_bit(HCI_MGMT, &hdev->dev_flags))
3435 mgmt_user_passkey_notify(hdev, &conn->dst, conn->type,
3436 conn->dst_type, conn->passkey_notify,
3437 conn->passkey_entered);
3440 static void hci_keypress_notify_evt(struct hci_dev *hdev, struct sk_buff *skb)
3442 struct hci_ev_keypress_notify *ev = (void *) skb->data;
3443 struct hci_conn *conn;
3445 BT_DBG("%s", hdev->name);
3447 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
3452 case HCI_KEYPRESS_STARTED:
3453 conn->passkey_entered = 0;
3456 case HCI_KEYPRESS_ENTERED:
3457 conn->passkey_entered++;
3460 case HCI_KEYPRESS_ERASED:
3461 conn->passkey_entered--;
3464 case HCI_KEYPRESS_CLEARED:
3465 conn->passkey_entered = 0;
3468 case HCI_KEYPRESS_COMPLETED:
3472 if (test_bit(HCI_MGMT, &hdev->dev_flags))
3473 mgmt_user_passkey_notify(hdev, &conn->dst, conn->type,
3474 conn->dst_type, conn->passkey_notify,
3475 conn->passkey_entered);
3478 static void hci_simple_pair_complete_evt(struct hci_dev *hdev,
3479 struct sk_buff *skb)
3481 struct hci_ev_simple_pair_complete *ev = (void *) skb->data;
3482 struct hci_conn *conn;
3484 BT_DBG("%s", hdev->name);
3488 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
3492 /* To avoid duplicate auth_failed events to user space we check
3493 * the HCI_CONN_AUTH_PEND flag which will be set if we
3494 * initiated the authentication. A traditional auth_complete
3495 * event gets always produced as initiator and is also mapped to
3496 * the mgmt_auth_failed event */
3497 if (!test_bit(HCI_CONN_AUTH_PEND, &conn->flags) && ev->status)
3498 mgmt_auth_failed(hdev, &conn->dst, conn->type, conn->dst_type,
3504 hci_dev_unlock(hdev);
3507 static void hci_remote_host_features_evt(struct hci_dev *hdev,
3508 struct sk_buff *skb)
3510 struct hci_ev_remote_host_features *ev = (void *) skb->data;
3511 struct inquiry_entry *ie;
3513 BT_DBG("%s", hdev->name);
3517 ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr);
3519 ie->data.ssp_mode = (ev->features[0] & LMP_HOST_SSP);
3521 hci_dev_unlock(hdev);
3524 static void hci_remote_oob_data_request_evt(struct hci_dev *hdev,
3525 struct sk_buff *skb)
3527 struct hci_ev_remote_oob_data_request *ev = (void *) skb->data;
3528 struct oob_data *data;
3530 BT_DBG("%s", hdev->name);
3534 if (!test_bit(HCI_MGMT, &hdev->dev_flags))
3537 data = hci_find_remote_oob_data(hdev, &ev->bdaddr);
3539 struct hci_cp_remote_oob_data_reply cp;
3541 bacpy(&cp.bdaddr, &ev->bdaddr);
3542 memcpy(cp.hash, data->hash, sizeof(cp.hash));
3543 memcpy(cp.randomizer, data->randomizer, sizeof(cp.randomizer));
3545 hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_DATA_REPLY, sizeof(cp),
3548 struct hci_cp_remote_oob_data_neg_reply cp;
3550 bacpy(&cp.bdaddr, &ev->bdaddr);
3551 hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_DATA_NEG_REPLY, sizeof(cp),
3556 hci_dev_unlock(hdev);
3559 static void hci_phy_link_complete_evt(struct hci_dev *hdev,
3560 struct sk_buff *skb)
3562 struct hci_ev_phy_link_complete *ev = (void *) skb->data;
3563 struct hci_conn *hcon, *bredr_hcon;
3565 BT_DBG("%s handle 0x%2.2x status 0x%2.2x", hdev->name, ev->phy_handle,
3570 hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle);
3572 hci_dev_unlock(hdev);
3578 hci_dev_unlock(hdev);
3582 bredr_hcon = hcon->amp_mgr->l2cap_conn->hcon;
3584 hcon->state = BT_CONNECTED;
3585 bacpy(&hcon->dst, &bredr_hcon->dst);
3587 hci_conn_hold(hcon);
3588 hcon->disc_timeout = HCI_DISCONN_TIMEOUT;
3591 hci_conn_hold_device(hcon);
3592 hci_conn_add_sysfs(hcon);
3594 amp_physical_cfm(bredr_hcon, hcon);
3596 hci_dev_unlock(hdev);
3599 static void hci_loglink_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
3601 struct hci_ev_logical_link_complete *ev = (void *) skb->data;
3602 struct hci_conn *hcon;
3603 struct hci_chan *hchan;
3604 struct amp_mgr *mgr;
3606 BT_DBG("%s log_handle 0x%4.4x phy_handle 0x%2.2x status 0x%2.2x",
3607 hdev->name, le16_to_cpu(ev->handle), ev->phy_handle,
3610 hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle);
3614 /* Create AMP hchan */
3615 hchan = hci_chan_create(hcon);
3619 hchan->handle = le16_to_cpu(ev->handle);
3621 BT_DBG("hcon %p mgr %p hchan %p", hcon, hcon->amp_mgr, hchan);
3623 mgr = hcon->amp_mgr;
3624 if (mgr && mgr->bredr_chan) {
3625 struct l2cap_chan *bredr_chan = mgr->bredr_chan;
3627 l2cap_chan_lock(bredr_chan);
3629 bredr_chan->conn->mtu = hdev->block_mtu;
3630 l2cap_logical_cfm(bredr_chan, hchan, 0);
3631 hci_conn_hold(hcon);
3633 l2cap_chan_unlock(bredr_chan);
3637 static void hci_disconn_loglink_complete_evt(struct hci_dev *hdev,
3638 struct sk_buff *skb)
3640 struct hci_ev_disconn_logical_link_complete *ev = (void *) skb->data;
3641 struct hci_chan *hchan;
3643 BT_DBG("%s log handle 0x%4.4x status 0x%2.2x", hdev->name,
3644 le16_to_cpu(ev->handle), ev->status);
3651 hchan = hci_chan_lookup_handle(hdev, le16_to_cpu(ev->handle));
3655 amp_destroy_logical_link(hchan, ev->reason);
3658 hci_dev_unlock(hdev);
3661 static void hci_disconn_phylink_complete_evt(struct hci_dev *hdev,
3662 struct sk_buff *skb)
3664 struct hci_ev_disconn_phy_link_complete *ev = (void *) skb->data;
3665 struct hci_conn *hcon;
3667 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
3674 hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle);
3676 hcon->state = BT_CLOSED;
3680 hci_dev_unlock(hdev);
3683 static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
3685 struct hci_ev_le_conn_complete *ev = (void *) skb->data;
3686 struct hci_conn *conn;
3688 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
3692 conn = hci_conn_hash_lookup_state(hdev, LE_LINK, BT_CONNECT);
3694 conn = hci_conn_add(hdev, LE_LINK, &ev->bdaddr);
3696 BT_ERR("No memory for new connection");
3700 conn->dst_type = ev->bdaddr_type;
3702 if (ev->role == LE_CONN_ROLE_MASTER) {
3704 conn->link_mode |= HCI_LM_MASTER;
3709 mgmt_connect_failed(hdev, &conn->dst, conn->type,
3710 conn->dst_type, ev->status);
3711 hci_proto_connect_cfm(conn, ev->status);
3712 conn->state = BT_CLOSED;
3717 if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
3718 mgmt_device_connected(hdev, &ev->bdaddr, conn->type,
3719 conn->dst_type, 0, NULL, 0, NULL);
3721 conn->sec_level = BT_SECURITY_LOW;
3722 conn->handle = __le16_to_cpu(ev->handle);
3723 conn->state = BT_CONNECTED;
3725 hci_conn_hold_device(conn);
3726 hci_conn_add_sysfs(conn);
3728 hci_proto_connect_cfm(conn, ev->status);
3731 hci_dev_unlock(hdev);
3734 static void hci_le_adv_report_evt(struct hci_dev *hdev, struct sk_buff *skb)
3736 u8 num_reports = skb->data[0];
3737 void *ptr = &skb->data[1];
3740 while (num_reports--) {
3741 struct hci_ev_le_advertising_info *ev = ptr;
3743 rssi = ev->data[ev->length];
3744 mgmt_device_found(hdev, &ev->bdaddr, LE_LINK, ev->bdaddr_type,
3745 NULL, rssi, 0, 1, ev->data, ev->length);
3747 ptr += sizeof(*ev) + ev->length + 1;
3751 static void hci_le_ltk_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
3753 struct hci_ev_le_ltk_req *ev = (void *) skb->data;
3754 struct hci_cp_le_ltk_reply cp;
3755 struct hci_cp_le_ltk_neg_reply neg;
3756 struct hci_conn *conn;
3757 struct smp_ltk *ltk;
3759 BT_DBG("%s handle 0x%4.4x", hdev->name, __le16_to_cpu(ev->handle));
3763 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
3767 ltk = hci_find_ltk(hdev, ev->ediv, ev->random);
3771 memcpy(cp.ltk, ltk->val, sizeof(ltk->val));
3772 cp.handle = cpu_to_le16(conn->handle);
3774 if (ltk->authenticated)
3775 conn->sec_level = BT_SECURITY_HIGH;
3777 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
3779 if (ltk->type & HCI_SMP_STK) {
3780 list_del(<k->list);
3784 hci_dev_unlock(hdev);
3789 neg.handle = ev->handle;
3790 hci_send_cmd(hdev, HCI_OP_LE_LTK_NEG_REPLY, sizeof(neg), &neg);
3791 hci_dev_unlock(hdev);
3794 static void hci_le_meta_evt(struct hci_dev *hdev, struct sk_buff *skb)
3796 struct hci_ev_le_meta *le_ev = (void *) skb->data;
3798 skb_pull(skb, sizeof(*le_ev));
3800 switch (le_ev->subevent) {
3801 case HCI_EV_LE_CONN_COMPLETE:
3802 hci_le_conn_complete_evt(hdev, skb);
3805 case HCI_EV_LE_ADVERTISING_REPORT:
3806 hci_le_adv_report_evt(hdev, skb);
3809 case HCI_EV_LE_LTK_REQ:
3810 hci_le_ltk_request_evt(hdev, skb);
3818 static void hci_chan_selected_evt(struct hci_dev *hdev, struct sk_buff *skb)
3820 struct hci_ev_channel_selected *ev = (void *) skb->data;
3821 struct hci_conn *hcon;
3823 BT_DBG("%s handle 0x%2.2x", hdev->name, ev->phy_handle);
3825 skb_pull(skb, sizeof(*ev));
3827 hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle);
3831 amp_read_loc_assoc_final_data(hdev, hcon);
3834 void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
3836 struct hci_event_hdr *hdr = (void *) skb->data;
3837 __u8 event = hdr->evt;
3839 skb_pull(skb, HCI_EVENT_HDR_SIZE);
3842 case HCI_EV_INQUIRY_COMPLETE:
3843 hci_inquiry_complete_evt(hdev, skb);
3846 case HCI_EV_INQUIRY_RESULT:
3847 hci_inquiry_result_evt(hdev, skb);
3850 case HCI_EV_CONN_COMPLETE:
3851 hci_conn_complete_evt(hdev, skb);
3854 case HCI_EV_CONN_REQUEST:
3855 hci_conn_request_evt(hdev, skb);
3858 case HCI_EV_DISCONN_COMPLETE:
3859 hci_disconn_complete_evt(hdev, skb);
3862 case HCI_EV_AUTH_COMPLETE:
3863 hci_auth_complete_evt(hdev, skb);
3866 case HCI_EV_REMOTE_NAME:
3867 hci_remote_name_evt(hdev, skb);
3870 case HCI_EV_ENCRYPT_CHANGE:
3871 hci_encrypt_change_evt(hdev, skb);
3874 case HCI_EV_CHANGE_LINK_KEY_COMPLETE:
3875 hci_change_link_key_complete_evt(hdev, skb);
3878 case HCI_EV_REMOTE_FEATURES:
3879 hci_remote_features_evt(hdev, skb);
3882 case HCI_EV_REMOTE_VERSION:
3883 hci_remote_version_evt(hdev, skb);
3886 case HCI_EV_QOS_SETUP_COMPLETE:
3887 hci_qos_setup_complete_evt(hdev, skb);
3890 case HCI_EV_CMD_COMPLETE:
3891 hci_cmd_complete_evt(hdev, skb);
3894 case HCI_EV_CMD_STATUS:
3895 hci_cmd_status_evt(hdev, skb);
3898 case HCI_EV_ROLE_CHANGE:
3899 hci_role_change_evt(hdev, skb);
3902 case HCI_EV_NUM_COMP_PKTS:
3903 hci_num_comp_pkts_evt(hdev, skb);
3906 case HCI_EV_MODE_CHANGE:
3907 hci_mode_change_evt(hdev, skb);
3910 case HCI_EV_PIN_CODE_REQ:
3911 hci_pin_code_request_evt(hdev, skb);
3914 case HCI_EV_LINK_KEY_REQ:
3915 hci_link_key_request_evt(hdev, skb);
3918 case HCI_EV_LINK_KEY_NOTIFY:
3919 hci_link_key_notify_evt(hdev, skb);
3922 case HCI_EV_CLOCK_OFFSET:
3923 hci_clock_offset_evt(hdev, skb);
3926 case HCI_EV_PKT_TYPE_CHANGE:
3927 hci_pkt_type_change_evt(hdev, skb);
3930 case HCI_EV_PSCAN_REP_MODE:
3931 hci_pscan_rep_mode_evt(hdev, skb);
3934 case HCI_EV_INQUIRY_RESULT_WITH_RSSI:
3935 hci_inquiry_result_with_rssi_evt(hdev, skb);
3938 case HCI_EV_REMOTE_EXT_FEATURES:
3939 hci_remote_ext_features_evt(hdev, skb);
3942 case HCI_EV_SYNC_CONN_COMPLETE:
3943 hci_sync_conn_complete_evt(hdev, skb);
3946 case HCI_EV_SYNC_CONN_CHANGED:
3947 hci_sync_conn_changed_evt(hdev, skb);
3950 case HCI_EV_SNIFF_SUBRATE:
3951 hci_sniff_subrate_evt(hdev, skb);
3954 case HCI_EV_EXTENDED_INQUIRY_RESULT:
3955 hci_extended_inquiry_result_evt(hdev, skb);
3958 case HCI_EV_KEY_REFRESH_COMPLETE:
3959 hci_key_refresh_complete_evt(hdev, skb);
3962 case HCI_EV_IO_CAPA_REQUEST:
3963 hci_io_capa_request_evt(hdev, skb);
3966 case HCI_EV_IO_CAPA_REPLY:
3967 hci_io_capa_reply_evt(hdev, skb);
3970 case HCI_EV_USER_CONFIRM_REQUEST:
3971 hci_user_confirm_request_evt(hdev, skb);
3974 case HCI_EV_USER_PASSKEY_REQUEST:
3975 hci_user_passkey_request_evt(hdev, skb);
3978 case HCI_EV_USER_PASSKEY_NOTIFY:
3979 hci_user_passkey_notify_evt(hdev, skb);
3982 case HCI_EV_KEYPRESS_NOTIFY:
3983 hci_keypress_notify_evt(hdev, skb);
3986 case HCI_EV_SIMPLE_PAIR_COMPLETE:
3987 hci_simple_pair_complete_evt(hdev, skb);
3990 case HCI_EV_REMOTE_HOST_FEATURES:
3991 hci_remote_host_features_evt(hdev, skb);
3994 case HCI_EV_LE_META:
3995 hci_le_meta_evt(hdev, skb);
3998 case HCI_EV_CHANNEL_SELECTED:
3999 hci_chan_selected_evt(hdev, skb);
4002 case HCI_EV_REMOTE_OOB_DATA_REQUEST:
4003 hci_remote_oob_data_request_evt(hdev, skb);
4006 case HCI_EV_PHY_LINK_COMPLETE:
4007 hci_phy_link_complete_evt(hdev, skb);
4010 case HCI_EV_LOGICAL_LINK_COMPLETE:
4011 hci_loglink_complete_evt(hdev, skb);
4014 case HCI_EV_DISCONN_LOGICAL_LINK_COMPLETE:
4015 hci_disconn_loglink_complete_evt(hdev, skb);
4018 case HCI_EV_DISCONN_PHY_LINK_COMPLETE:
4019 hci_disconn_phylink_complete_evt(hdev, skb);
4022 case HCI_EV_NUM_COMP_BLOCKS:
4023 hci_num_comp_blocks_evt(hdev, skb);
4027 BT_DBG("%s event 0x%2.2x", hdev->name, event);
4032 hdev->stat.evt_rx++;