Lines Matching +full:local +full:- +full:bd +full:- +full:address +full:- +full:broken
2 BlueZ - Bluetooth protocol stack for Linux
3 Copyright (c) 2000-2001, 2010, Code Aurora Forum. All rights reserved.
4 Copyright 2023-2024 NXP
69 /* This function requires the caller holds hdev->lock */
73 struct hci_dev *hdev = conn->hdev; in hci_connect_le_scan_cleanup()
78 bdaddr = &conn->dst; in hci_connect_le_scan_cleanup()
79 bdaddr_type = conn->dst_type; in hci_connect_le_scan_cleanup()
81 /* Check if we need to convert to identity address */ in hci_connect_le_scan_cleanup()
84 bdaddr = &irk->bdaddr; in hci_connect_le_scan_cleanup()
85 bdaddr_type = irk->addr_type; in hci_connect_le_scan_cleanup()
88 params = hci_pend_le_action_lookup(&hdev->pend_le_conns, bdaddr, in hci_connect_le_scan_cleanup()
93 if (params->conn) { in hci_connect_le_scan_cleanup()
94 hci_conn_drop(params->conn); in hci_connect_le_scan_cleanup()
95 hci_conn_put(params->conn); in hci_connect_le_scan_cleanup()
96 params->conn = NULL; in hci_connect_le_scan_cleanup()
99 if (!params->explicit_connect) in hci_connect_le_scan_cleanup()
116 params->explicit_connect = false; in hci_connect_le_scan_cleanup()
120 switch (params->auto_connect) { in hci_connect_le_scan_cleanup()
127 hci_pend_le_list_add(params, &hdev->pend_le_conns); in hci_connect_le_scan_cleanup()
130 hci_pend_le_list_add(params, &hdev->pend_le_reports); in hci_connect_le_scan_cleanup()
141 struct hci_dev *hdev = conn->hdev; in hci_conn_cleanup()
143 if (test_bit(HCI_CONN_PARAM_REMOVAL_PEND, &conn->flags)) in hci_conn_cleanup()
144 hci_conn_params_del(conn->hdev, &conn->dst, conn->dst_type); in hci_conn_cleanup()
146 if (test_and_clear_bit(HCI_CONN_FLUSH_KEY, &conn->flags)) in hci_conn_cleanup()
147 hci_remove_link_key(hdev, &conn->dst); in hci_conn_cleanup()
153 if (HCI_CONN_HANDLE_UNSET(conn->handle)) in hci_conn_cleanup()
154 ida_free(&hdev->unset_handle_ida, conn->handle); in hci_conn_cleanup()
156 if (conn->cleanup) in hci_conn_cleanup()
157 conn->cleanup(conn); in hci_conn_cleanup()
159 if (conn->type == SCO_LINK || conn->type == ESCO_LINK) { in hci_conn_cleanup()
160 switch (conn->setting & SCO_AIRMODE_MASK) { in hci_conn_cleanup()
163 if (hdev->notify) in hci_conn_cleanup()
164 hdev->notify(hdev, HCI_NOTIFY_DISABLE_SCO); in hci_conn_cleanup()
168 if (hdev->notify) in hci_conn_cleanup()
169 hdev->notify(hdev, HCI_NOTIFY_CONN_DEL); in hci_conn_cleanup()
172 debugfs_remove_recursive(conn->debugfs); in hci_conn_cleanup()
188 if (conn->type == ACL_LINK && conn->role == HCI_ROLE_MASTER && in hci_disconnect()
189 (conn->state == BT_CONNECTED || conn->state == BT_CONFIG)) { in hci_disconnect()
190 struct hci_dev *hdev = conn->hdev; in hci_disconnect()
193 clkoff_cp.handle = cpu_to_le16(conn->handle); in hci_disconnect()
203 struct hci_dev *hdev = conn->hdev; in hci_add_sco()
208 conn->state = BT_CONNECT; in hci_add_sco()
209 conn->out = true; in hci_add_sco()
211 conn->attempt++; in hci_add_sco()
214 cp.pkt_type = cpu_to_le16(conn->pkt_type); in hci_add_sco()
222 if (!conn->parent) in find_next_esco_param()
225 for (; conn->attempt <= size; conn->attempt++) { in find_next_esco_param()
226 if (lmp_esco_2m_capable(conn->parent) || in find_next_esco_param()
227 (esco_param[conn->attempt - 1].pkt_type & ESCO_2EV3)) in find_next_esco_param()
230 conn, conn->attempt); in find_next_esco_param()
233 return conn->attempt <= size; in find_next_esco_param()
246 if (!codec->data_path || !hdev->get_codec_config_data) in configure_datapath_sync()
249 err = hdev->get_codec_config_data(hdev, ESCO_LINK, codec, &vnd_len, in configure_datapath_sync()
256 err = -ENOMEM; in configure_datapath_sync()
260 err = hdev->get_data_path_id(hdev, &cmd->data_path_id); in configure_datapath_sync()
264 cmd->vnd_len = vnd_len; in configure_datapath_sync()
265 memcpy(cmd->vnd_data, vnd_data, vnd_len); in configure_datapath_sync()
267 cmd->direction = 0x00; in configure_datapath_sync()
271 cmd->direction = 0x01; in configure_datapath_sync()
285 struct hci_conn *conn = conn_handle->conn; in hci_enhanced_setup_sync()
286 __u16 handle = conn_handle->handle; in hci_enhanced_setup_sync()
293 return -ECANCELED; in hci_enhanced_setup_sync()
297 configure_datapath_sync(hdev, &conn->codec); in hci_enhanced_setup_sync()
299 conn->state = BT_CONNECT; in hci_enhanced_setup_sync()
300 conn->out = true; in hci_enhanced_setup_sync()
302 conn->attempt++; in hci_enhanced_setup_sync()
311 switch (conn->codec.id) { in hci_enhanced_setup_sync()
315 return -EINVAL; in hci_enhanced_setup_sync()
317 param = &esco_param_msbc[conn->attempt - 1]; in hci_enhanced_setup_sync()
332 cp.in_data_path = conn->codec.data_path; in hci_enhanced_setup_sync()
333 cp.out_data_path = conn->codec.data_path; in hci_enhanced_setup_sync()
342 param = &esco_param_msbc[conn->attempt - 1]; in hci_enhanced_setup_sync()
357 cp.in_data_path = conn->codec.data_path; in hci_enhanced_setup_sync()
358 cp.out_data_path = conn->codec.data_path; in hci_enhanced_setup_sync()
364 if (conn->parent && lmp_esco_capable(conn->parent)) { in hci_enhanced_setup_sync()
367 return -EINVAL; in hci_enhanced_setup_sync()
368 param = &esco_param_cvsd[conn->attempt - 1]; in hci_enhanced_setup_sync()
370 if (conn->attempt > ARRAY_SIZE(sco_param_cvsd)) in hci_enhanced_setup_sync()
371 return -EINVAL; in hci_enhanced_setup_sync()
372 param = &sco_param_cvsd[conn->attempt - 1]; in hci_enhanced_setup_sync()
388 cp.in_data_path = conn->codec.data_path; in hci_enhanced_setup_sync()
389 cp.out_data_path = conn->codec.data_path; in hci_enhanced_setup_sync()
394 return -EINVAL; in hci_enhanced_setup_sync()
397 cp.retrans_effort = param->retrans_effort; in hci_enhanced_setup_sync()
398 cp.pkt_type = __cpu_to_le16(param->pkt_type); in hci_enhanced_setup_sync()
399 cp.max_latency = __cpu_to_le16(param->max_latency); in hci_enhanced_setup_sync()
402 return -EIO; in hci_enhanced_setup_sync()
409 struct hci_dev *hdev = conn->hdev; in hci_setup_sync_conn()
415 conn->state = BT_CONNECT; in hci_setup_sync_conn()
416 conn->out = true; in hci_setup_sync_conn()
418 conn->attempt++; in hci_setup_sync_conn()
424 cp.voice_setting = cpu_to_le16(conn->setting); in hci_setup_sync_conn()
426 switch (conn->setting & SCO_AIRMODE_MASK) { in hci_setup_sync_conn()
431 param = &esco_param_msbc[conn->attempt - 1]; in hci_setup_sync_conn()
434 if (conn->parent && lmp_esco_capable(conn->parent)) { in hci_setup_sync_conn()
438 param = &esco_param_cvsd[conn->attempt - 1]; in hci_setup_sync_conn()
440 if (conn->attempt > ARRAY_SIZE(sco_param_cvsd)) in hci_setup_sync_conn()
442 param = &sco_param_cvsd[conn->attempt - 1]; in hci_setup_sync_conn()
449 cp.retrans_effort = param->retrans_effort; in hci_setup_sync_conn()
450 cp.pkt_type = __cpu_to_le16(param->pkt_type); in hci_setup_sync_conn()
451 cp.max_latency = __cpu_to_le16(param->max_latency); in hci_setup_sync_conn()
464 if (enhanced_sync_conn_capable(conn->hdev)) { in hci_setup_sync()
470 conn_handle->conn = conn; in hci_setup_sync()
471 conn_handle->handle = handle; in hci_setup_sync()
472 result = hci_cmd_sync_queue(conn->hdev, hci_enhanced_setup_sync, in hci_setup_sync()
486 struct hci_dev *hdev = conn->hdev; in hci_le_conn_update()
492 params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type); in hci_le_conn_update()
494 params->conn_min_interval = min; in hci_le_conn_update()
495 params->conn_max_interval = max; in hci_le_conn_update()
496 params->conn_latency = latency; in hci_le_conn_update()
497 params->supervision_timeout = to_multiplier; in hci_le_conn_update()
503 cp.handle = cpu_to_le16(conn->handle); in hci_le_conn_update()
522 struct hci_dev *hdev = conn->hdev; in hci_le_start_enc()
529 cp.handle = cpu_to_le16(conn->handle); in hci_le_start_enc()
542 link = list_first_entry_or_null(&conn->link_list, struct hci_link, list); in hci_sco_setup()
543 if (!link || !link->conn) in hci_sco_setup()
549 if (lmp_esco_capable(conn->hdev)) in hci_sco_setup()
550 hci_setup_sync(link->conn, conn->handle); in hci_sco_setup()
552 hci_add_sco(link->conn, conn->handle); in hci_sco_setup()
554 hci_connect_cfm(link->conn, status); in hci_sco_setup()
555 hci_conn_del(link->conn); in hci_sco_setup()
563 int refcnt = atomic_read(&conn->refcnt); in hci_conn_timeout()
565 BT_DBG("hcon %p state %s", conn, state_to_string(conn->state)); in hci_conn_timeout()
587 struct hci_dev *hdev = conn->hdev; in hci_conn_idle()
589 BT_DBG("hcon %p mode %d", conn, conn->mode); in hci_conn_idle()
594 if (conn->mode != HCI_CM_ACTIVE || !(conn->link_policy & HCI_LP_SNIFF)) in hci_conn_idle()
599 cp.handle = cpu_to_le16(conn->handle); in hci_conn_idle()
606 if (!test_and_set_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags)) { in hci_conn_idle()
608 cp.handle = cpu_to_le16(conn->handle); in hci_conn_idle()
609 cp.max_interval = cpu_to_le16(hdev->sniff_max_interval); in hci_conn_idle()
610 cp.min_interval = cpu_to_le16(hdev->sniff_min_interval); in hci_conn_idle()
622 hci_send_cmd(conn->hdev, HCI_OP_USER_CONFIRM_REPLY, sizeof(conn->dst), in hci_conn_auto_accept()
623 &conn->dst); in hci_conn_auto_accept()
647 struct hci_dev *hdev = conn->hdev; in le_conn_timeout()
653 * happen with broken hardware or if low duty cycle was used in le_conn_timeout()
656 if (conn->role == HCI_ROLE_SLAVE) { in le_conn_timeout()
688 /* Skip if not broadcast/ANY address */ in bis_list()
689 if (bacmp(&conn->dst, BDADDR_ANY)) in bis_list()
692 if (d->big != conn->iso_qos.bcast.big || d->bis == BT_ISO_QOS_BIS_UNSET || in bis_list()
693 d->bis != conn->iso_qos.bcast.bis) in bis_list()
696 d->count++; in bis_list()
703 bt_dev_dbg(hdev, "big 0x%2.2x bis 0x%2.2x", d->big, d->bis); in terminate_big_sync()
705 hci_disable_per_advertising_sync(hdev, d->bis); in terminate_big_sync()
706 hci_remove_ext_adv_instance_sync(hdev, d->bis, NULL); in terminate_big_sync()
709 if (!d->big_term) in terminate_big_sync()
712 return hci_le_terminate_big_sync(hdev, d->big, in terminate_big_sync()
726 bt_dev_dbg(hdev, "big 0x%2.2x bis 0x%2.2x", conn->iso_qos.bcast.big, in hci_le_terminate_big()
727 conn->iso_qos.bcast.bis); in hci_le_terminate_big()
731 return -ENOMEM; in hci_le_terminate_big()
733 d->big = conn->iso_qos.bcast.big; in hci_le_terminate_big()
734 d->bis = conn->iso_qos.bcast.bis; in hci_le_terminate_big()
735 d->big_term = test_and_clear_bit(HCI_CONN_BIG_CREATED, &conn->flags); in hci_le_terminate_big()
749 bt_dev_dbg(hdev, "big 0x%2.2x sync_handle 0x%4.4x", d->big, in big_terminate_sync()
750 d->sync_handle); in big_terminate_sync()
752 if (d->big_sync_term) in big_terminate_sync()
753 hci_le_big_terminate_sync(hdev, d->big); in big_terminate_sync()
755 if (d->pa_sync_term) in big_terminate_sync()
756 return hci_le_pa_terminate_sync(hdev, d->sync_handle); in big_terminate_sync()
766 if (d->big != conn->iso_qos.bcast.big) in find_bis()
769 d->count++; in find_bis()
777 bt_dev_dbg(hdev, "big 0x%2.2x sync_handle 0x%4.4x", big, conn->sync_handle); in hci_le_big_terminate()
781 return -ENOMEM; in hci_le_big_terminate()
783 d->big = big; in hci_le_big_terminate()
784 d->sync_handle = conn->sync_handle; in hci_le_big_terminate()
786 if (test_and_clear_bit(HCI_CONN_PA_SYNC, &conn->flags)) { in hci_le_big_terminate()
790 if (!d->count) in hci_le_big_terminate()
791 d->pa_sync_term = true; in hci_le_big_terminate()
793 d->count = 0; in hci_le_big_terminate()
796 if (test_and_clear_bit(HCI_CONN_BIG_SYNC, &conn->flags)) { in hci_le_big_terminate()
800 if (!d->count) in hci_le_big_terminate()
801 d->big_sync_term = true; in hci_le_big_terminate()
820 struct hci_dev *hdev = conn->hdev; in bis_cleanup()
825 if (conn->role == HCI_ROLE_MASTER) { in bis_cleanup()
826 if (!test_and_clear_bit(HCI_CONN_PER_ADV, &conn->flags)) in bis_cleanup()
832 bis = hci_conn_hash_lookup_big(hdev, conn->iso_qos.bcast.big); in bis_cleanup()
838 hci_le_big_terminate(hdev, conn->iso_qos.bcast.big, in bis_cleanup()
863 if (!bacmp(&conn->dst, BDADDR_ANY) || d->cig != conn->iso_qos.ucast.cig) in find_cis()
866 d->count++; in find_cis()
875 struct hci_dev *hdev = conn->hdev; in cis_cleanup()
878 if (conn->iso_qos.ucast.cig == BT_ISO_QOS_CIG_UNSET) in cis_cleanup()
882 d.cig = conn->iso_qos.ucast.cig; in cis_cleanup()
893 hci_le_remove_cig(hdev, conn->iso_qos.ucast.cig); in cis_cleanup()
898 return ida_alloc_range(&hdev->unset_handle_ida, HCI_CONN_HANDLE_MAX + 1, in hci_conn_hash_alloc_unset()
909 if (!hdev->acl_mtu) in __hci_conn_add()
910 return ERR_PTR(-ECONNREFUSED); in __hci_conn_add()
913 if (hdev->iso_mtu) in __hci_conn_add()
918 if (hdev->le_mtu && hdev->le_mtu < HCI_MIN_LE_MTU) in __hci_conn_add()
919 return ERR_PTR(-ECONNREFUSED); in __hci_conn_add()
920 if (!hdev->le_mtu && hdev->acl_mtu < HCI_MIN_LE_MTU) in __hci_conn_add()
921 return ERR_PTR(-ECONNREFUSED); in __hci_conn_add()
925 if (!hdev->sco_pkts) in __hci_conn_add()
927 return ERR_PTR(-ECONNREFUSED); in __hci_conn_add()
930 return ERR_PTR(-ECONNREFUSED); in __hci_conn_add()
937 return ERR_PTR(-ENOMEM); in __hci_conn_add()
939 bacpy(&conn->dst, dst); in __hci_conn_add()
940 bacpy(&conn->src, &hdev->bdaddr); in __hci_conn_add()
941 conn->handle = handle; in __hci_conn_add()
942 conn->hdev = hdev; in __hci_conn_add()
943 conn->type = type; in __hci_conn_add()
944 conn->role = role; in __hci_conn_add()
945 conn->mode = HCI_CM_ACTIVE; in __hci_conn_add()
946 conn->state = BT_OPEN; in __hci_conn_add()
947 conn->auth_type = HCI_AT_GENERAL_BONDING; in __hci_conn_add()
948 conn->io_capability = hdev->io_capability; in __hci_conn_add()
949 conn->remote_auth = 0xff; in __hci_conn_add()
950 conn->key_type = 0xff; in __hci_conn_add()
951 conn->rssi = HCI_RSSI_INVALID; in __hci_conn_add()
952 conn->tx_power = HCI_TX_POWER_INVALID; in __hci_conn_add()
953 conn->max_tx_power = HCI_TX_POWER_INVALID; in __hci_conn_add()
954 conn->sync_handle = HCI_SYNC_HANDLE_INVALID; in __hci_conn_add()
955 conn->sid = HCI_SID_INVALID; in __hci_conn_add()
957 set_bit(HCI_CONN_POWER_SAVE, &conn->flags); in __hci_conn_add()
958 conn->disc_timeout = HCI_DISCONN_TIMEOUT; in __hci_conn_add()
961 conn->auth_payload_timeout = DEFAULT_AUTH_PAYLOAD_TIMEOUT; in __hci_conn_add()
963 if (conn->role == HCI_ROLE_MASTER) in __hci_conn_add()
964 conn->out = true; in __hci_conn_add()
968 conn->pkt_type = hdev->pkt_type & ACL_PTYPE_MASK; in __hci_conn_add()
969 conn->mtu = hdev->acl_mtu; in __hci_conn_add()
972 /* conn->src should reflect the local identity address */ in __hci_conn_add()
973 hci_copy_identity_address(hdev, &conn->src, &conn->src_type); in __hci_conn_add()
974 conn->mtu = hdev->le_mtu ? hdev->le_mtu : hdev->acl_mtu; in __hci_conn_add()
977 /* conn->src should reflect the local identity address */ in __hci_conn_add()
978 hci_copy_identity_address(hdev, &conn->src, &conn->src_type); in __hci_conn_add()
982 conn->cleanup = bis_cleanup; in __hci_conn_add()
983 else if (conn->role == HCI_ROLE_MASTER) in __hci_conn_add()
984 conn->cleanup = cis_cleanup; in __hci_conn_add()
986 conn->mtu = hdev->iso_mtu ? hdev->iso_mtu : in __hci_conn_add()
987 hdev->le_mtu ? hdev->le_mtu : hdev->acl_mtu; in __hci_conn_add()
991 conn->pkt_type = (hdev->esco_type & SCO_ESCO_MASK) | in __hci_conn_add()
992 (hdev->esco_type & EDR_ESCO_MASK); in __hci_conn_add()
994 conn->pkt_type = hdev->pkt_type & SCO_PTYPE_MASK; in __hci_conn_add()
996 conn->mtu = hdev->sco_mtu; in __hci_conn_add()
999 conn->pkt_type = hdev->esco_type & ~EDR_ESCO_MASK; in __hci_conn_add()
1000 conn->mtu = hdev->sco_mtu; in __hci_conn_add()
1004 skb_queue_head_init(&conn->data_q); in __hci_conn_add()
1006 INIT_LIST_HEAD(&conn->chan_list); in __hci_conn_add()
1007 INIT_LIST_HEAD(&conn->link_list); in __hci_conn_add()
1009 INIT_DELAYED_WORK(&conn->disc_work, hci_conn_timeout); in __hci_conn_add()
1010 INIT_DELAYED_WORK(&conn->auto_accept_work, hci_conn_auto_accept); in __hci_conn_add()
1011 INIT_DELAYED_WORK(&conn->idle_work, hci_conn_idle); in __hci_conn_add()
1012 INIT_DELAYED_WORK(&conn->le_conn_timeout, le_conn_timeout); in __hci_conn_add()
1014 atomic_set(&conn->refcnt, 0); in __hci_conn_add()
1024 if (conn->type != SCO_LINK && conn->type != ESCO_LINK) { in __hci_conn_add()
1025 if (hdev->notify) in __hci_conn_add()
1026 hdev->notify(hdev, HCI_NOTIFY_CONN_ADD); in __hci_conn_add()
1043 return ERR_PTR(-ECONNREFUSED); in hci_conn_add_unset()
1052 return ERR_PTR(-EINVAL); in hci_conn_add()
1066 switch (conn->type) { in hci_conn_cleanup_child()
1069 if (HCI_CONN_HANDLE_UNSET(conn->handle)) in hci_conn_cleanup_child()
1073 if ((conn->state != BT_CONNECTED && in hci_conn_cleanup_child()
1074 !test_bit(HCI_CONN_CREATE_CIS, &conn->flags)) || in hci_conn_cleanup_child()
1075 test_bit(HCI_CONN_BIG_CREATED, &conn->flags)) in hci_conn_cleanup_child()
1083 struct hci_dev *hdev = conn->hdev; in hci_conn_unlink()
1087 if (!conn->parent) { in hci_conn_unlink()
1090 list_for_each_entry_safe(link, t, &conn->link_list, list) { in hci_conn_unlink()
1091 struct hci_conn *child = link->conn; in hci_conn_unlink()
1100 if (!test_bit(HCI_UP, &hdev->flags)) in hci_conn_unlink()
1103 hci_conn_cleanup_child(child, conn->abort_reason); in hci_conn_unlink()
1109 if (!conn->link) in hci_conn_unlink()
1112 list_del_rcu(&conn->link->list); in hci_conn_unlink()
1115 hci_conn_drop(conn->parent); in hci_conn_unlink()
1116 hci_conn_put(conn->parent); in hci_conn_unlink()
1117 conn->parent = NULL; in hci_conn_unlink()
1119 kfree(conn->link); in hci_conn_unlink()
1120 conn->link = NULL; in hci_conn_unlink()
1125 struct hci_dev *hdev = conn->hdev; in hci_conn_del()
1127 BT_DBG("%s hcon %p handle %d", hdev->name, conn, conn->handle); in hci_conn_del()
1131 disable_delayed_work_sync(&conn->disc_work); in hci_conn_del()
1132 disable_delayed_work_sync(&conn->auto_accept_work); in hci_conn_del()
1133 disable_delayed_work_sync(&conn->idle_work); in hci_conn_del()
1135 if (conn->type == ACL_LINK) { in hci_conn_del()
1137 hdev->acl_cnt += conn->sent; in hci_conn_del()
1138 } else if (conn->type == LE_LINK) { in hci_conn_del()
1139 cancel_delayed_work(&conn->le_conn_timeout); in hci_conn_del()
1141 if (hdev->le_pkts) in hci_conn_del()
1142 hdev->le_cnt += conn->sent; in hci_conn_del()
1144 hdev->acl_cnt += conn->sent; in hci_conn_del()
1147 if (conn->type == ISO_LINK) { in hci_conn_del()
1148 if (hdev->iso_pkts) in hci_conn_del()
1149 hdev->iso_cnt += conn->sent; in hci_conn_del()
1150 else if (hdev->le_pkts) in hci_conn_del()
1151 hdev->le_cnt += conn->sent; in hci_conn_del()
1153 hdev->acl_cnt += conn->sent; in hci_conn_del()
1157 skb_queue_purge(&conn->data_q); in hci_conn_del()
1175 BT_DBG("%pMR -> %pMR", src, dst); in hci_get_route()
1180 if (!test_bit(HCI_UP, &d->flags) || in hci_get_route()
1185 * No source address - find interface with bdaddr != dst in hci_get_route()
1186 * Source address - find interface with bdaddr == src in hci_get_route()
1196 bacpy(&id_addr, &d->bdaddr); in hci_get_route()
1205 /* Convert from HCI to three-value type */ in hci_get_route()
1216 if (bacmp(&d->bdaddr, dst)) { in hci_get_route()
1230 /* This function requires the caller holds hdev->lock */
1233 struct hci_dev *hdev = conn->hdev; in hci_le_conn_failed()
1243 /* This function requires the caller holds hdev->lock */
1246 struct hci_dev *hdev = conn->hdev; in hci_conn_failed()
1250 switch (conn->type) { in hci_conn_failed()
1262 test_and_clear_bit(HCI_CONN_BIG_SYNC_FAILED, &conn->flags); in hci_conn_failed()
1263 test_and_clear_bit(HCI_CONN_PA_SYNC_FAILED, &conn->flags); in hci_conn_failed()
1265 conn->state = BT_CLOSED; in hci_conn_failed()
1270 /* This function requires the caller holds hdev->lock */
1273 struct hci_dev *hdev = conn->hdev; in hci_conn_set_handle()
1277 if (conn->handle == handle) in hci_conn_set_handle()
1289 if (conn->abort_reason) in hci_conn_set_handle()
1290 return conn->abort_reason; in hci_conn_set_handle()
1292 if (HCI_CONN_HANDLE_UNSET(conn->handle)) in hci_conn_set_handle()
1293 ida_free(&hdev->unset_handle_ida, conn->handle); in hci_conn_set_handle()
1295 conn->handle = handle; in hci_conn_set_handle()
1311 return ERR_PTR(-ECONNREFUSED); in hci_connect_le()
1313 return ERR_PTR(-EOPNOTSUPP); in hci_connect_le()
1317 * time, we return -EBUSY if there is any connection attempt running. in hci_connect_le()
1320 return ERR_PTR(-EBUSY); in hci_connect_le()
1328 if (conn && !test_bit(HCI_CONN_SCANNING, &conn->flags)) { in hci_connect_le()
1329 return ERR_PTR(-EBUSY); in hci_connect_le()
1332 /* Check if the destination address has been resolved by the controller in hci_connect_le()
1333 * since if it did then the identity address shall be used. in hci_connect_le()
1336 /* When given an identity address with existing identity in hci_connect_le()
1338 * to a resolvable random address. in hci_connect_le()
1340 * Storing the resolvable random address is required here in hci_connect_le()
1341 * to handle connection failures. The address will later in hci_connect_le()
1342 * be resolved back into the original identity address in hci_connect_le()
1346 if (irk && bacmp(&irk->rpa, BDADDR_ANY)) { in hci_connect_le()
1347 dst = &irk->rpa; in hci_connect_le()
1353 bacpy(&conn->dst, dst); in hci_connect_le()
1359 conn->pending_sec_level = sec_level; in hci_connect_le()
1362 conn->dst_type = dst_type; in hci_connect_le()
1363 conn->sec_level = BT_SECURITY_LOW; in hci_connect_le()
1364 conn->conn_timeout = conn_timeout; in hci_connect_le()
1365 conn->le_adv_phy = phy; in hci_connect_le()
1366 conn->le_adv_sec_phy = sec_phy; in hci_connect_le()
1385 if (conn->state != BT_CONNECTED) in is_connected()
1391 /* This function requires the caller holds hdev->lock */
1398 return -EISCONN; in hci_explicit_conn_params_set()
1404 return -ENOMEM; in hci_explicit_conn_params_set()
1410 params->auto_connect = HCI_AUTO_CONN_EXPLICIT; in hci_explicit_conn_params_set()
1414 if (params->auto_connect == HCI_AUTO_CONN_DISABLED || in hci_explicit_conn_params_set()
1415 params->auto_connect == HCI_AUTO_CONN_REPORT || in hci_explicit_conn_params_set()
1416 params->auto_connect == HCI_AUTO_CONN_EXPLICIT) { in hci_explicit_conn_params_set()
1418 hci_pend_le_list_add(params, &hdev->pend_le_conns); in hci_explicit_conn_params_set()
1421 params->explicit_connect = true; in hci_explicit_conn_params_set()
1424 params->auto_connect); in hci_explicit_conn_params_set()
1435 if (qos->bcast.big == BT_ISO_QOS_BIG_UNSET) { in qos_set_big()
1444 return -EADDRNOTAVAIL; in qos_set_big()
1447 qos->bcast.big = big; in qos_set_big()
1459 if (qos->bcast.bis == BT_ISO_QOS_BIS_UNSET) { in qos_set_bis()
1460 if (qos->bcast.big != BT_ISO_QOS_BIG_UNSET) { in qos_set_bis()
1461 conn = hci_conn_hash_lookup_big(hdev, qos->bcast.big); in qos_set_bis()
1467 qos->bcast.bis = conn->iso_qos.bcast.bis; in qos_set_bis()
1475 for (bis = 0x01; bis < hdev->le_num_of_adv_sets; in qos_set_bis()
1483 if (bis == hdev->le_num_of_adv_sets) in qos_set_bis()
1484 return -EADDRNOTAVAIL; in qos_set_bis()
1487 qos->bcast.bis = bis; in qos_set_bis()
1493 /* This function requires the caller holds hdev->lock */
1504 return ERR_PTR(-ECONNREFUSED); in hci_add_bis()
1505 return ERR_PTR(-EOPNOTSUPP); in hci_add_bis()
1517 conn = hci_conn_hash_lookup_per_adv_bis(hdev, dst, qos->bcast.big, in hci_add_bis()
1518 qos->bcast.big); in hci_add_bis()
1520 return ERR_PTR(-EADDRINUSE); in hci_add_bis()
1525 conn = hci_conn_hash_lookup_big(hdev, qos->bcast.big); in hci_add_bis()
1527 if (conn && (memcmp(qos, &conn->iso_qos, sizeof(*qos)) || in hci_add_bis()
1528 base_len != conn->le_per_adv_data_len || in hci_add_bis()
1529 memcmp(conn->le_per_adv_data, base, base_len))) in hci_add_bis()
1530 return ERR_PTR(-EADDRINUSE); in hci_add_bis()
1536 conn->state = BT_CONNECT; in hci_add_bis()
1542 /* This function requires the caller holds hdev->lock */
1553 return ERR_PTR(-ECONNREFUSED); in hci_connect_le_scan()
1555 return ERR_PTR(-EOPNOTSUPP); in hci_connect_le_scan()
1559 * established. To be able to handle these ATT messages, the user- in hci_connect_le_scan()
1569 if (conn->pending_sec_level < sec_level) in hci_connect_le_scan()
1570 conn->pending_sec_level = sec_level; in hci_connect_le_scan()
1582 return ERR_PTR(-EBUSY); in hci_connect_le_scan()
1585 conn->state = BT_CONNECT; in hci_connect_le_scan()
1586 set_bit(HCI_CONN_SCANNING, &conn->flags); in hci_connect_le_scan()
1587 conn->dst_type = dst_type; in hci_connect_le_scan()
1588 conn->sec_level = BT_SECURITY_LOW; in hci_connect_le_scan()
1589 conn->pending_sec_level = sec_level; in hci_connect_le_scan()
1590 conn->conn_timeout = conn_timeout; in hci_connect_le_scan()
1591 conn->conn_reason = conn_reason; in hci_connect_le_scan()
1608 return ERR_PTR(-ECONNREFUSED); in hci_connect_acl()
1610 return ERR_PTR(-EOPNOTSUPP); in hci_connect_acl()
1613 /* Reject outgoing connection to device with same BD ADDR against in hci_connect_acl()
1614 * CVE-2020-26555 in hci_connect_acl()
1616 if (!bacmp(&hdev->bdaddr, dst)) { in hci_connect_acl()
1619 return ERR_PTR(-ECONNREFUSED); in hci_connect_acl()
1631 acl->conn_reason = conn_reason; in hci_connect_acl()
1632 if (acl->state == BT_OPEN || acl->state == BT_CLOSED) { in hci_connect_acl()
1635 acl->sec_level = BT_SECURITY_LOW; in hci_connect_acl()
1636 acl->pending_sec_level = sec_level; in hci_connect_acl()
1637 acl->auth_type = auth_type; in hci_connect_acl()
1638 acl->conn_timeout = timeout; in hci_connect_acl()
1653 struct hci_dev *hdev = parent->hdev; in hci_conn_link()
1658 if (conn->link) in hci_conn_link()
1659 return conn->link; in hci_conn_link()
1661 if (conn->parent) in hci_conn_link()
1668 link->conn = hci_conn_hold(conn); in hci_conn_link()
1669 conn->link = link; in hci_conn_link()
1670 conn->parent = hci_conn_get(parent); in hci_conn_link()
1673 list_add_tail_rcu(&link->list, &parent->link_list); in hci_conn_link()
1704 return ERR_PTR(-ENOLINK); in hci_connect_sco()
1707 sco->setting = setting; in hci_connect_sco()
1708 sco->codec = *codec; in hci_connect_sco()
1710 if (acl->state == BT_CONNECTED && in hci_connect_sco()
1711 (sco->state == BT_OPEN || sco->state == BT_CLOSED)) { in hci_connect_sco()
1712 set_bit(HCI_CONN_POWER_SAVE, &acl->flags); in hci_connect_sco()
1715 if (test_bit(HCI_CONN_MODE_CHANGE_PEND, &acl->flags)) { in hci_connect_sco()
1717 set_bit(HCI_CONN_SCO_SETUP_PEND, &acl->flags); in hci_connect_sco()
1729 struct hci_dev *hdev = conn->hdev; in hci_le_create_big()
1735 data.big = qos->bcast.big; in hci_le_create_big()
1736 data.bis = qos->bcast.bis; in hci_le_create_big()
1743 cp.handle = qos->bcast.big; in hci_le_create_big()
1744 cp.adv_handle = qos->bcast.bis; in hci_le_create_big()
1746 hci_cpu_to_le24(qos->bcast.out.interval, cp.bis.sdu_interval); in hci_le_create_big()
1747 cp.bis.sdu = cpu_to_le16(qos->bcast.out.sdu); in hci_le_create_big()
1748 cp.bis.latency = cpu_to_le16(qos->bcast.out.latency); in hci_le_create_big()
1749 cp.bis.rtn = qos->bcast.out.rtn; in hci_le_create_big()
1750 cp.bis.phy = qos->bcast.out.phy; in hci_le_create_big()
1751 cp.bis.packing = qos->bcast.packing; in hci_le_create_big()
1752 cp.bis.framing = qos->bcast.framing; in hci_le_create_big()
1753 cp.bis.encryption = qos->bcast.encryption; in hci_le_create_big()
1754 memcpy(cp.bis.bcode, qos->bcast.bcode, sizeof(cp.bis.bcode)); in hci_le_create_big()
1772 qos = &conn->iso_qos; in set_cig_params_sync()
1773 pdu->cig_id = cig_id; in set_cig_params_sync()
1774 hci_cpu_to_le24(qos->ucast.out.interval, pdu->c_interval); in set_cig_params_sync()
1775 hci_cpu_to_le24(qos->ucast.in.interval, pdu->p_interval); in set_cig_params_sync()
1776 pdu->sca = qos->ucast.sca; in set_cig_params_sync()
1777 pdu->packing = qos->ucast.packing; in set_cig_params_sync()
1778 pdu->framing = qos->ucast.framing; in set_cig_params_sync()
1779 pdu->c_latency = cpu_to_le16(qos->ucast.out.latency); in set_cig_params_sync()
1780 pdu->p_latency = cpu_to_le16(qos->ucast.in.latency); in set_cig_params_sync()
1787 aux_num_cis < pdu->num_cis; cis_id++) { in set_cig_params_sync()
1794 qos = &conn->iso_qos; in set_cig_params_sync()
1796 cis = &pdu->cis[aux_num_cis++]; in set_cig_params_sync()
1797 cis->cis_id = cis_id; in set_cig_params_sync()
1798 cis->c_sdu = cpu_to_le16(conn->iso_qos.ucast.out.sdu); in set_cig_params_sync()
1799 cis->p_sdu = cpu_to_le16(conn->iso_qos.ucast.in.sdu); in set_cig_params_sync()
1800 cis->c_phy = qos->ucast.out.phy ? qos->ucast.out.phy : in set_cig_params_sync()
1801 qos->ucast.in.phy; in set_cig_params_sync()
1802 cis->p_phy = qos->ucast.in.phy ? qos->ucast.in.phy : in set_cig_params_sync()
1803 qos->ucast.out.phy; in set_cig_params_sync()
1804 cis->c_rtn = qos->ucast.out.rtn; in set_cig_params_sync()
1805 cis->p_rtn = qos->ucast.in.rtn; in set_cig_params_sync()
1807 pdu->num_cis = aux_num_cis; in set_cig_params_sync()
1809 if (!pdu->num_cis) in set_cig_params_sync()
1813 struct_size(pdu, cis, pdu->num_cis), in set_cig_params_sync()
1819 struct hci_dev *hdev = conn->hdev; in hci_le_set_cig_params()
1825 if (qos->ucast.cig == BT_ISO_QOS_CIG_UNSET) { in hci_le_set_cig_params()
1844 qos->ucast.cig = data.cig; in hci_le_set_cig_params()
1847 if (qos->ucast.cis != BT_ISO_QOS_CIS_UNSET) { in hci_le_set_cig_params()
1848 if (hci_conn_hash_lookup_cis(hdev, NULL, 0, qos->ucast.cig, in hci_le_set_cig_params()
1849 qos->ucast.cis)) in hci_le_set_cig_params()
1855 for (data.cig = qos->ucast.cig, data.cis = 0x00; data.cis < 0xf0; in hci_le_set_cig_params()
1860 qos->ucast.cis = data.cis; in hci_le_set_cig_params()
1865 if (qos->ucast.cis == BT_ISO_QOS_CIS_UNSET) in hci_le_set_cig_params()
1870 UINT_PTR(qos->ucast.cig), NULL) < 0) in hci_le_set_cig_params()
1881 cis = hci_conn_hash_lookup_cis(hdev, dst, dst_type, qos->ucast.cig, in hci_bind_cis()
1882 qos->ucast.cis); in hci_bind_cis()
1887 cis->cleanup = cis_cleanup; in hci_bind_cis()
1888 cis->dst_type = dst_type; in hci_bind_cis()
1889 cis->iso_qos.ucast.cig = BT_ISO_QOS_CIG_UNSET; in hci_bind_cis()
1890 cis->iso_qos.ucast.cis = BT_ISO_QOS_CIS_UNSET; in hci_bind_cis()
1893 if (cis->state == BT_CONNECTED) in hci_bind_cis()
1897 if (cis->state == BT_BOUND && in hci_bind_cis()
1898 !memcmp(&cis->iso_qos, qos, sizeof(*qos))) in hci_bind_cis()
1902 cis->le_tx_phy = qos->ucast.out.phy; in hci_bind_cis()
1903 cis->le_rx_phy = qos->ucast.in.phy; in hci_bind_cis()
1908 if (!qos->ucast.out.interval) in hci_bind_cis()
1909 qos->ucast.out.interval = qos->ucast.in.interval; in hci_bind_cis()
1914 if (!qos->ucast.in.interval) in hci_bind_cis()
1915 qos->ucast.in.interval = qos->ucast.out.interval; in hci_bind_cis()
1920 if (!qos->ucast.out.latency) in hci_bind_cis()
1921 qos->ucast.out.latency = qos->ucast.in.latency; in hci_bind_cis()
1926 if (!qos->ucast.in.latency) in hci_bind_cis()
1927 qos->ucast.in.latency = qos->ucast.out.latency; in hci_bind_cis()
1931 return ERR_PTR(-EINVAL); in hci_bind_cis()
1936 cis->iso_qos = *qos; in hci_bind_cis()
1937 cis->state = BT_BOUND; in hci_bind_cis()
1944 struct hci_dev *hdev = conn->hdev; in hci_iso_setup_path()
1949 if (conn->iso_qos.ucast.out.sdu) { in hci_iso_setup_path()
1950 cmd.handle = cpu_to_le16(conn->handle); in hci_iso_setup_path()
1960 if (conn->iso_qos.ucast.in.sdu) { in hci_iso_setup_path()
1961 cmd.handle = cpu_to_le16(conn->handle); in hci_iso_setup_path()
1976 if (conn->type != ISO_LINK || !bacmp(&conn->dst, BDADDR_ANY)) in hci_conn_check_create_cis()
1977 return -EINVAL; in hci_conn_check_create_cis()
1979 if (!conn->parent || conn->parent->state != BT_CONNECTED || in hci_conn_check_create_cis()
1980 conn->state != BT_CONNECT || HCI_CONN_HANDLE_UNSET(conn->handle)) in hci_conn_check_create_cis()
1998 list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) { in hci_le_create_cis_pending()
1999 if (test_bit(HCI_CONN_CREATE_CIS, &conn->flags)) { in hci_le_create_cis_pending()
2001 return -EBUSY; in hci_le_create_cis_pending()
2021 if (!qos->sdu && qos->phy) in hci_iso_qos_setup()
2022 qos->sdu = conn->mtu; in hci_iso_qos_setup()
2025 if (qos->phy == BT_ISO_PHY_ANY) in hci_iso_qos_setup()
2026 qos->phy = phy; in hci_iso_qos_setup()
2029 if (!qos->interval) in hci_iso_qos_setup()
2031 qos->interval = conn->le_conn_interval * 1250; in hci_iso_qos_setup()
2034 if (!qos->latency) in hci_iso_qos_setup()
2035 qos->latency = conn->le_conn_latency; in hci_iso_qos_setup()
2041 struct bt_iso_qos *qos = &conn->iso_qos; in create_big_sync()
2046 if (qos->bcast.out.phy == 0x02) in create_big_sync()
2050 interval = (qos->bcast.out.interval / 1250) * qos->bcast.sync_factor; in create_big_sync()
2052 if (qos->bcast.bis) in create_big_sync()
2055 err = hci_start_per_adv_sync(hdev, qos->bcast.bis, conn->le_per_adv_data_len, in create_big_sync()
2056 conn->le_per_adv_data, flags, interval, in create_big_sync()
2061 return hci_le_create_big(conn, &conn->iso_qos); in create_big_sync()
2074 if (conn->type != ISO_LINK || conn->sid == HCI_SID_INVALID) in hci_conn_check_create_pa_sync()
2102 list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) { in create_pa_sync()
2103 if (test_bit(HCI_CONN_CREATE_PA_SYNC, &conn->flags)) in create_pa_sync()
2107 list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) { in create_pa_sync()
2109 struct bt_iso_qos *qos = &conn->iso_qos; in create_pa_sync()
2111 cp.options = qos->bcast.options; in create_pa_sync()
2112 cp.sid = conn->sid; in create_pa_sync()
2113 cp.addr_type = conn->dst_type; in create_pa_sync()
2114 bacpy(&cp.addr, &conn->dst); in create_pa_sync()
2115 cp.skip = cpu_to_le16(qos->bcast.skip); in create_pa_sync()
2116 cp.sync_timeout = cpu_to_le16(qos->bcast.sync_timeout); in create_pa_sync()
2117 cp.sync_cte_type = qos->bcast.sync_cte_type; in create_pa_sync()
2130 set_bit(HCI_CONN_CREATE_PA_SYNC, &conn->flags); in create_pa_sync()
2139 clear_bit(HCI_CONN_CREATE_PA_SYNC, &conn->flags); in create_pa_sync()
2163 conn->iso_qos = *qos; in hci_pa_create_sync()
2164 conn->dst_type = dst_type; in hci_pa_create_sync()
2165 conn->sid = sid; in hci_pa_create_sync()
2166 conn->state = BT_LISTEN; in hci_pa_create_sync()
2177 if (!conn->num_bis) in hci_conn_check_create_big_sync()
2198 pdu->num_bis = 0; in big_create_sync()
2213 list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) { in big_create_sync()
2214 if (test_bit(HCI_CONN_CREATE_BIG_SYNC, &conn->flags)) in big_create_sync()
2218 list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) { in big_create_sync()
2220 struct bt_iso_qos *qos = &conn->iso_qos; in big_create_sync()
2222 set_bit(HCI_CONN_CREATE_BIG_SYNC, &conn->flags); in big_create_sync()
2224 pdu->handle = qos->bcast.big; in big_create_sync()
2225 pdu->sync_handle = cpu_to_le16(conn->sync_handle); in big_create_sync()
2226 pdu->encryption = qos->bcast.encryption; in big_create_sync()
2227 memcpy(pdu->bcode, qos->bcast.bcode, in big_create_sync()
2228 sizeof(pdu->bcode)); in big_create_sync()
2229 pdu->mse = qos->bcast.mse; in big_create_sync()
2230 pdu->timeout = cpu_to_le16(qos->bcast.timeout); in big_create_sync()
2231 pdu->num_bis = conn->num_bis; in big_create_sync()
2232 memcpy(pdu->bis, conn->bis, conn->num_bis); in big_create_sync()
2241 if (!pdu->num_bis) in big_create_sync()
2245 struct_size(pdu, bis, pdu->num_bis), pdu); in big_create_sync()
2262 return -EINVAL; in hci_le_big_create_sync()
2270 hcon->iso_qos = *qos; in hci_le_big_create_sync()
2272 hcon->num_bis = num_bis; in hci_le_big_create_sync()
2273 memcpy(hcon->bis, bis, num_bis); in hci_le_big_create_sync()
2302 conn = hci_conn_hash_lookup_big_state(hdev, qos->bcast.big, BT_OPEN); in hci_bind_bis()
2304 memcpy(qos, &conn->iso_qos, sizeof(*qos)); in hci_bind_bis()
2305 conn->state = BT_CONNECTED; in hci_bind_bis()
2319 conn->le_tx_phy = qos->bcast.out.phy; in hci_bind_bis()
2320 conn->le_tx_phy = qos->bcast.out.phy; in hci_bind_bis()
2324 memcpy(conn->le_per_adv_data, eir, sizeof(eir)); in hci_bind_bis()
2325 conn->le_per_adv_data_len = base_len; in hci_bind_bis()
2328 hci_iso_qos_setup(hdev, conn, &qos->bcast.out, in hci_bind_bis()
2329 conn->le_tx_phy ? conn->le_tx_phy : in hci_bind_bis()
2330 hdev->le_tx_def_phys); in hci_bind_bis()
2332 conn->iso_qos = *qos; in hci_bind_bis()
2333 conn->state = BT_BOUND; in hci_bind_bis()
2337 conn->iso_qos.bcast.big); in hci_bind_bis()
2342 return ERR_PTR(-ENOLINK); in hci_bind_bis()
2352 /* Skip if not broadcast/ANY address */ in bis_mark_per_adv()
2353 if (bacmp(&conn->dst, BDADDR_ANY)) in bis_mark_per_adv()
2356 if (d->big != conn->iso_qos.bcast.big || in bis_mark_per_adv()
2357 d->bis == BT_ISO_QOS_BIS_UNSET || in bis_mark_per_adv()
2358 d->bis != conn->iso_qos.bcast.bis) in bis_mark_per_adv()
2361 set_bit(HCI_CONN_PER_ADV, &conn->flags); in bis_mark_per_adv()
2376 if (conn->state == BT_CONNECTED) in hci_connect_bis()
2379 data.big = qos->bcast.big; in hci_connect_bis()
2380 data.bis = qos->bcast.bis; in hci_connect_bis()
2420 hci_iso_qos_setup(hdev, le, &qos->ucast.out, in hci_connect_cis()
2421 le->le_tx_phy ? le->le_tx_phy : hdev->le_tx_def_phys); in hci_connect_cis()
2422 hci_iso_qos_setup(hdev, le, &qos->ucast.in, in hci_connect_cis()
2423 le->le_rx_phy ? le->le_rx_phy : hdev->le_rx_def_phys); in hci_connect_cis()
2435 return ERR_PTR(-ENOLINK); in hci_connect_cis()
2438 cis->state = BT_CONNECT; in hci_connect_cis()
2451 * Connections is used and the link is encrypted with AES-CCM in hci_conn_check_link_mode()
2452 * using a P-256 authenticated combination key. in hci_conn_check_link_mode()
2454 if (hci_dev_test_flag(conn->hdev, HCI_SC_ONLY)) { in hci_conn_check_link_mode()
2456 !test_bit(HCI_CONN_AES_CCM, &conn->flags) || in hci_conn_check_link_mode()
2457 conn->key_type != HCI_LK_AUTH_COMBINATION_P256) in hci_conn_check_link_mode()
2466 * 128-bit equivalent strength for link and encryption keys in hci_conn_check_link_mode()
2468 * SAFER+ not allowed, and P-192 not allowed; encryption key in hci_conn_check_link_mode()
2471 if (conn->sec_level == BT_SECURITY_FIPS && in hci_conn_check_link_mode()
2472 !test_bit(HCI_CONN_AES_CCM, &conn->flags)) { in hci_conn_check_link_mode()
2473 bt_dev_err(conn->hdev, in hci_conn_check_link_mode()
2474 "Invalid security: Missing AES-CCM usage"); in hci_conn_check_link_mode()
2479 !test_bit(HCI_CONN_ENCRYPT, &conn->flags)) in hci_conn_check_link_mode()
2490 if (conn->pending_sec_level > sec_level) in hci_conn_auth()
2491 sec_level = conn->pending_sec_level; in hci_conn_auth()
2493 if (sec_level > conn->sec_level) in hci_conn_auth()
2494 conn->pending_sec_level = sec_level; in hci_conn_auth()
2495 else if (test_bit(HCI_CONN_AUTH, &conn->flags)) in hci_conn_auth()
2499 auth_type |= (conn->auth_type & 0x01); in hci_conn_auth()
2501 conn->auth_type = auth_type; in hci_conn_auth()
2503 if (!test_and_set_bit(HCI_CONN_AUTH_PEND, &conn->flags)) { in hci_conn_auth()
2506 cp.handle = cpu_to_le16(conn->handle); in hci_conn_auth()
2507 hci_send_cmd(conn->hdev, HCI_OP_AUTH_REQUESTED, in hci_conn_auth()
2513 if (!test_bit(HCI_CONN_ENCRYPT, &conn->flags)) in hci_conn_auth()
2514 set_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags); in hci_conn_auth()
2525 if (!test_and_set_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) { in hci_conn_encrypt()
2527 cp.handle = cpu_to_le16(conn->handle); in hci_conn_encrypt()
2529 hci_send_cmd(conn->hdev, HCI_OP_SET_CONN_ENCRYPT, sizeof(cp), in hci_conn_encrypt()
2540 if (conn->type == LE_LINK) in hci_conn_security()
2553 if (!test_bit(HCI_CONN_AUTH, &conn->flags)) in hci_conn_security()
2556 switch (conn->key_type) { in hci_conn_security()
2585 if (sec_level <= BT_SECURITY_MEDIUM || conn->pin_length == 16) in hci_conn_security()
2593 if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) in hci_conn_security()
2597 set_bit(HCI_CONN_AUTH_INITIATOR, &conn->flags); in hci_conn_security()
2603 if (test_bit(HCI_CONN_ENCRYPT, &conn->flags)) { in hci_conn_security()
2607 if (!conn->enc_key_size) in hci_conn_security()
2624 /* Accept if non-secure or higher security level is required */ in hci_conn_check_secure()
2629 if (conn->sec_level == BT_SECURITY_HIGH || in hci_conn_check_secure()
2630 conn->sec_level == BT_SECURITY_FIPS) in hci_conn_check_secure()
2643 if (role == conn->role) in hci_conn_switch_role()
2646 if (!test_and_set_bit(HCI_CONN_RSWITCH_PEND, &conn->flags)) { in hci_conn_switch_role()
2648 bacpy(&cp.bdaddr, &conn->dst); in hci_conn_switch_role()
2650 hci_send_cmd(conn->hdev, HCI_OP_SWITCH_ROLE, sizeof(cp), &cp); in hci_conn_switch_role()
2660 struct hci_dev *hdev = conn->hdev; in hci_conn_enter_active_mode()
2662 BT_DBG("hcon %p mode %d", conn, conn->mode); in hci_conn_enter_active_mode()
2664 if (conn->mode != HCI_CM_SNIFF) in hci_conn_enter_active_mode()
2667 if (!test_bit(HCI_CONN_POWER_SAVE, &conn->flags) && !force_active) in hci_conn_enter_active_mode()
2670 if (!test_and_set_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags)) { in hci_conn_enter_active_mode()
2672 cp.handle = cpu_to_le16(conn->handle); in hci_conn_enter_active_mode()
2677 if (hdev->idle_timeout > 0) in hci_conn_enter_active_mode()
2678 queue_delayed_work(hdev->workqueue, &conn->idle_work, in hci_conn_enter_active_mode()
2679 msecs_to_jiffies(hdev->idle_timeout)); in hci_conn_enter_active_mode()
2685 struct list_head *head = &hdev->conn_hash.list; in hci_conn_hash_flush()
2688 BT_DBG("hdev %s", hdev->name); in hci_conn_hash_flush()
2697 conn->state = BT_CLOSED; in hci_conn_hash_flush()
2707 if (conn->role == HCI_ROLE_MASTER) in get_link_mode()
2710 if (test_bit(HCI_CONN_ENCRYPT, &conn->flags)) in get_link_mode()
2713 if (test_bit(HCI_CONN_AUTH, &conn->flags)) in get_link_mode()
2716 if (test_bit(HCI_CONN_SECURE, &conn->flags)) in get_link_mode()
2719 if (test_bit(HCI_CONN_FIPS, &conn->flags)) in get_link_mode()
2734 return -EFAULT; in hci_get_conn_list()
2737 return -EINVAL; in hci_get_conn_list()
2743 return -ENOMEM; in hci_get_conn_list()
2748 return -ENODEV; in hci_get_conn_list()
2751 ci = cl->conn_info; in hci_get_conn_list()
2754 list_for_each_entry(c, &hdev->conn_hash.list, list) { in hci_get_conn_list()
2755 bacpy(&(ci + n)->bdaddr, &c->dst); in hci_get_conn_list()
2756 (ci + n)->handle = c->handle; in hci_get_conn_list()
2757 (ci + n)->type = c->type; in hci_get_conn_list()
2758 (ci + n)->out = c->out; in hci_get_conn_list()
2759 (ci + n)->state = c->state; in hci_get_conn_list()
2760 (ci + n)->link_mode = get_link_mode(c); in hci_get_conn_list()
2766 cl->dev_id = hdev->id; in hci_get_conn_list()
2767 cl->conn_num = n; in hci_get_conn_list()
2775 return err ? -EFAULT : 0; in hci_get_conn_list()
2786 return -EFAULT; in hci_get_conn_info()
2791 bacpy(&ci.bdaddr, &conn->dst); in hci_get_conn_info()
2792 ci.handle = conn->handle; in hci_get_conn_info()
2793 ci.type = conn->type; in hci_get_conn_info()
2794 ci.out = conn->out; in hci_get_conn_info()
2795 ci.state = conn->state; in hci_get_conn_info()
2801 return -ENOENT; in hci_get_conn_info()
2803 return copy_to_user(ptr, &ci, sizeof(ci)) ? -EFAULT : 0; in hci_get_conn_info()
2812 return -EFAULT; in hci_get_auth_info()
2817 req.type = conn->auth_type; in hci_get_auth_info()
2821 return -ENOENT; in hci_get_auth_info()
2823 return copy_to_user(arg, &req, sizeof(req)) ? -EFAULT : 0; in hci_get_auth_info()
2828 struct hci_dev *hdev = conn->hdev; in hci_chan_create()
2831 BT_DBG("%s hcon %p", hdev->name, conn); in hci_chan_create()
2833 if (test_bit(HCI_CONN_DROP, &conn->flags)) { in hci_chan_create()
2842 chan->conn = hci_conn_get(conn); in hci_chan_create()
2843 skb_queue_head_init(&chan->data_q); in hci_chan_create()
2844 chan->state = BT_CONNECTED; in hci_chan_create()
2846 list_add_rcu(&chan->list, &conn->chan_list); in hci_chan_create()
2853 struct hci_conn *conn = chan->conn; in hci_chan_del()
2854 struct hci_dev *hdev = conn->hdev; in hci_chan_del()
2856 BT_DBG("%s hcon %p chan %p", hdev->name, conn, chan); in hci_chan_del()
2858 list_del_rcu(&chan->list); in hci_chan_del()
2863 set_bit(HCI_CONN_DROP, &conn->flags); in hci_chan_del()
2867 skb_queue_purge(&chan->data_q); in hci_chan_del()
2877 list_for_each_entry_safe(chan, n, &conn->chan_list, list) in hci_chan_list_flush()
2886 list_for_each_entry(hchan, &hcon->chan_list, list) { in __hci_chan_lookup_handle()
2887 if (hchan->handle == handle) in __hci_chan_lookup_handle()
2896 struct hci_conn_hash *h = &hdev->conn_hash; in hci_chan_lookup_handle()
2902 list_for_each_entry_rcu(hcon, &h->list, list) { in hci_chan_lookup_handle()
2921 switch (conn->type) { in hci_conn_get_phy()
2936 if (conn->pkt_type & (HCI_DM3 | HCI_DH3)) in hci_conn_get_phy()
2939 if (conn->pkt_type & (HCI_DM5 | HCI_DH5)) in hci_conn_get_phy()
2943 * 2-DH1, 2-DH3 and 2-DH5. in hci_conn_get_phy()
2945 if (!(conn->pkt_type & HCI_2DH1)) in hci_conn_get_phy()
2948 if (!(conn->pkt_type & HCI_2DH3)) in hci_conn_get_phy()
2951 if (!(conn->pkt_type & HCI_2DH5)) in hci_conn_get_phy()
2955 * 3-DH1, 3-DH3 and 3-DH5. in hci_conn_get_phy()
2957 if (!(conn->pkt_type & HCI_3DH1)) in hci_conn_get_phy()
2960 if (!(conn->pkt_type & HCI_3DH3)) in hci_conn_get_phy()
2963 if (!(conn->pkt_type & HCI_3DH5)) in hci_conn_get_phy()
2972 if (!(conn->pkt_type & (ESCO_EV4 | ESCO_EV5))) in hci_conn_get_phy()
2975 /* eSCO logical transport (2 Mb/s): 2-EV3, 2-EV5 */ in hci_conn_get_phy()
2976 if (!(conn->pkt_type & ESCO_2EV3)) in hci_conn_get_phy()
2979 if (!(conn->pkt_type & ESCO_2EV5)) in hci_conn_get_phy()
2982 /* eSCO logical transport (3 Mb/s): 3-EV3, 3-EV5 */ in hci_conn_get_phy()
2983 if (!(conn->pkt_type & ESCO_3EV3)) in hci_conn_get_phy()
2986 if (!(conn->pkt_type & ESCO_3EV5)) in hci_conn_get_phy()
2992 if (conn->le_tx_phy & HCI_LE_SET_PHY_1M) in hci_conn_get_phy()
2995 if (conn->le_rx_phy & HCI_LE_SET_PHY_1M) in hci_conn_get_phy()
2998 if (conn->le_tx_phy & HCI_LE_SET_PHY_2M) in hci_conn_get_phy()
3001 if (conn->le_rx_phy & HCI_LE_SET_PHY_2M) in hci_conn_get_phy()
3004 if (conn->le_tx_phy & HCI_LE_SET_PHY_CODED) in hci_conn_get_phy()
3007 if (conn->le_rx_phy & HCI_LE_SET_PHY_CODED) in hci_conn_get_phy()
3021 return -ECANCELED; in abort_conn_sync()
3023 return hci_abort_conn_sync(hdev, conn, conn->abort_reason); in abort_conn_sync()
3028 struct hci_dev *hdev = conn->hdev; in hci_abort_conn()
3033 if (conn->abort_reason) in hci_abort_conn()
3036 bt_dev_dbg(hdev, "handle 0x%2.2x reason 0x%2.2x", conn->handle, reason); in hci_abort_conn()
3038 conn->abort_reason = reason; in hci_abort_conn()
3047 if (conn->state == BT_CONNECT && hdev->req_status == HCI_REQ_PEND) { in hci_abort_conn()
3048 switch (hci_skb_event(hdev->sent_cmd)) { in hci_abort_conn()