Lines Matching full:conn
48 struct hci_conn *conn; member
71 static void hci_connect_le_scan_cleanup(struct hci_conn *conn) in hci_connect_le_scan_cleanup() argument
74 struct hci_dev *hdev = conn->hdev; in hci_connect_le_scan_cleanup()
79 bdaddr = &conn->dst; in hci_connect_le_scan_cleanup()
80 bdaddr_type = conn->dst_type; in hci_connect_le_scan_cleanup()
122 static void hci_conn_cleanup(struct hci_conn *conn) in hci_conn_cleanup() argument
124 struct hci_dev *hdev = conn->hdev; in hci_conn_cleanup()
126 if (test_bit(HCI_CONN_PARAM_REMOVAL_PEND, &conn->flags)) in hci_conn_cleanup()
127 hci_conn_params_del(conn->hdev, &conn->dst, conn->dst_type); in hci_conn_cleanup()
129 if (test_and_clear_bit(HCI_CONN_FLUSH_KEY, &conn->flags)) in hci_conn_cleanup()
130 hci_remove_link_key(hdev, &conn->dst); in hci_conn_cleanup()
132 hci_chan_list_flush(conn); in hci_conn_cleanup()
134 hci_conn_hash_del(hdev, conn); in hci_conn_cleanup()
136 if (conn->cleanup) in hci_conn_cleanup()
137 conn->cleanup(conn); in hci_conn_cleanup()
139 if (conn->type == SCO_LINK || conn->type == ESCO_LINK) { in hci_conn_cleanup()
140 switch (conn->setting & SCO_AIRMODE_MASK) { in hci_conn_cleanup()
152 hci_conn_del_sysfs(conn); in hci_conn_cleanup()
154 debugfs_remove_recursive(conn->debugfs); in hci_conn_cleanup()
158 hci_conn_put(conn); in hci_conn_cleanup()
163 struct hci_conn *conn = container_of(work, struct hci_conn, in le_scan_cleanup() local
165 struct hci_dev *hdev = conn->hdev; in le_scan_cleanup()
168 BT_DBG("%s hcon %p", hdev->name, conn); in le_scan_cleanup()
175 if (c == conn) in le_scan_cleanup()
180 if (c == conn) { in le_scan_cleanup()
181 hci_connect_le_scan_cleanup(conn); in le_scan_cleanup()
182 hci_conn_cleanup(conn); in le_scan_cleanup()
187 hci_conn_put(conn); in le_scan_cleanup()
190 static void hci_connect_le_scan_remove(struct hci_conn *conn) in hci_connect_le_scan_remove() argument
192 BT_DBG("%s hcon %p", conn->hdev->name, conn); in hci_connect_le_scan_remove()
196 * hci_dev_lock and doing cancel_delayed_work_sync(&conn->disc_work). in hci_connect_le_scan_remove()
202 hci_dev_hold(conn->hdev); in hci_connect_le_scan_remove()
203 hci_conn_get(conn); in hci_connect_le_scan_remove()
209 schedule_work(&conn->le_scan_cleanup); in hci_connect_le_scan_remove()
212 static void hci_acl_create_connection(struct hci_conn *conn) in hci_acl_create_connection() argument
214 struct hci_dev *hdev = conn->hdev; in hci_acl_create_connection()
218 BT_DBG("hcon %p", conn); in hci_acl_create_connection()
232 conn->state = BT_CONNECT2; in hci_acl_create_connection()
237 conn->state = BT_CONNECT; in hci_acl_create_connection()
238 conn->out = true; in hci_acl_create_connection()
239 conn->role = HCI_ROLE_MASTER; in hci_acl_create_connection()
241 conn->attempt++; in hci_acl_create_connection()
243 conn->link_policy = hdev->link_policy; in hci_acl_create_connection()
246 bacpy(&cp.bdaddr, &conn->dst); in hci_acl_create_connection()
249 ie = hci_inquiry_cache_lookup(hdev, &conn->dst); in hci_acl_create_connection()
258 memcpy(conn->dev_class, ie->data.dev_class, 3); in hci_acl_create_connection()
261 cp.pkt_type = cpu_to_le16(conn->pkt_type); in hci_acl_create_connection()
270 int hci_disconnect(struct hci_conn *conn, __u8 reason) in hci_disconnect() argument
272 BT_DBG("hcon %p", conn); in hci_disconnect()
279 if (conn->type == ACL_LINK && conn->role == HCI_ROLE_MASTER && in hci_disconnect()
280 (conn->state == BT_CONNECTED || conn->state == BT_CONFIG)) { in hci_disconnect()
281 struct hci_dev *hdev = conn->hdev; in hci_disconnect()
284 clkoff_cp.handle = cpu_to_le16(conn->handle); in hci_disconnect()
289 return hci_abort_conn(conn, reason); in hci_disconnect()
292 static void hci_add_sco(struct hci_conn *conn, __u16 handle) in hci_add_sco() argument
294 struct hci_dev *hdev = conn->hdev; in hci_add_sco()
297 BT_DBG("hcon %p", conn); in hci_add_sco()
299 conn->state = BT_CONNECT; in hci_add_sco()
300 conn->out = true; in hci_add_sco()
302 conn->attempt++; in hci_add_sco()
305 cp.pkt_type = cpu_to_le16(conn->pkt_type); in hci_add_sco()
310 static bool find_next_esco_param(struct hci_conn *conn, in find_next_esco_param() argument
313 for (; conn->attempt <= size; conn->attempt++) { in find_next_esco_param()
314 if (lmp_esco_2m_capable(conn->link) || in find_next_esco_param()
315 (esco_param[conn->attempt - 1].pkt_type & ESCO_2EV3)) in find_next_esco_param()
318 conn, conn->attempt); in find_next_esco_param()
321 return conn->attempt <= size; in find_next_esco_param()
366 struct hci_conn *conn = conn_handle->conn; in hci_enhanced_setup_sync() local
373 bt_dev_dbg(hdev, "hcon %p", conn); in hci_enhanced_setup_sync()
376 if (conn->codec.data_path) in hci_enhanced_setup_sync()
377 configure_datapath_sync(hdev, &conn->codec); in hci_enhanced_setup_sync()
379 conn->state = BT_CONNECT; in hci_enhanced_setup_sync()
380 conn->out = true; in hci_enhanced_setup_sync()
382 conn->attempt++; in hci_enhanced_setup_sync()
391 switch (conn->codec.id) { in hci_enhanced_setup_sync()
393 if (!find_next_esco_param(conn, esco_param_msbc, in hci_enhanced_setup_sync()
397 param = &esco_param_msbc[conn->attempt - 1]; in hci_enhanced_setup_sync()
412 cp.in_data_path = conn->codec.data_path; in hci_enhanced_setup_sync()
413 cp.out_data_path = conn->codec.data_path; in hci_enhanced_setup_sync()
419 if (!find_next_esco_param(conn, esco_param_msbc, in hci_enhanced_setup_sync()
422 param = &esco_param_msbc[conn->attempt - 1]; in hci_enhanced_setup_sync()
437 cp.in_data_path = conn->codec.data_path; in hci_enhanced_setup_sync()
438 cp.out_data_path = conn->codec.data_path; in hci_enhanced_setup_sync()
444 if (lmp_esco_capable(conn->link)) { in hci_enhanced_setup_sync()
445 if (!find_next_esco_param(conn, esco_param_cvsd, in hci_enhanced_setup_sync()
448 param = &esco_param_cvsd[conn->attempt - 1]; in hci_enhanced_setup_sync()
450 if (conn->attempt > ARRAY_SIZE(sco_param_cvsd)) in hci_enhanced_setup_sync()
452 param = &sco_param_cvsd[conn->attempt - 1]; in hci_enhanced_setup_sync()
468 cp.in_data_path = conn->codec.data_path; in hci_enhanced_setup_sync()
469 cp.out_data_path = conn->codec.data_path; in hci_enhanced_setup_sync()
487 static bool hci_setup_sync_conn(struct hci_conn *conn, __u16 handle) in hci_setup_sync_conn() argument
489 struct hci_dev *hdev = conn->hdev; in hci_setup_sync_conn()
493 bt_dev_dbg(hdev, "hcon %p", conn); in hci_setup_sync_conn()
495 conn->state = BT_CONNECT; in hci_setup_sync_conn()
496 conn->out = true; in hci_setup_sync_conn()
498 conn->attempt++; in hci_setup_sync_conn()
504 cp.voice_setting = cpu_to_le16(conn->setting); in hci_setup_sync_conn()
506 switch (conn->setting & SCO_AIRMODE_MASK) { in hci_setup_sync_conn()
508 if (!find_next_esco_param(conn, esco_param_msbc, in hci_setup_sync_conn()
511 param = &esco_param_msbc[conn->attempt - 1]; in hci_setup_sync_conn()
514 if (lmp_esco_capable(conn->link)) { in hci_setup_sync_conn()
515 if (!find_next_esco_param(conn, esco_param_cvsd, in hci_setup_sync_conn()
518 param = &esco_param_cvsd[conn->attempt - 1]; in hci_setup_sync_conn()
520 if (conn->attempt > ARRAY_SIZE(sco_param_cvsd)) in hci_setup_sync_conn()
522 param = &sco_param_cvsd[conn->attempt - 1]; in hci_setup_sync_conn()
539 bool hci_setup_sync(struct hci_conn *conn, __u16 handle) in hci_setup_sync() argument
544 if (enhanced_sync_conn_capable(conn->hdev)) { in hci_setup_sync()
550 conn_handle->conn = conn; in hci_setup_sync()
552 result = hci_cmd_sync_queue(conn->hdev, hci_enhanced_setup_sync, in hci_setup_sync()
560 return hci_setup_sync_conn(conn, handle); in hci_setup_sync()
563 u8 hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max, u16 latency, in hci_le_conn_update() argument
566 struct hci_dev *hdev = conn->hdev; in hci_le_conn_update()
572 params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type); in hci_le_conn_update()
583 cp.handle = cpu_to_le16(conn->handle); in hci_le_conn_update()
599 void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __le64 rand, in hci_le_start_enc() argument
602 struct hci_dev *hdev = conn->hdev; in hci_le_start_enc()
605 BT_DBG("hcon %p", conn); in hci_le_start_enc()
609 cp.handle = cpu_to_le16(conn->handle); in hci_le_start_enc()
618 void hci_sco_setup(struct hci_conn *conn, __u8 status) in hci_sco_setup() argument
620 struct hci_conn *sco = conn->link; in hci_sco_setup()
625 BT_DBG("hcon %p", conn); in hci_sco_setup()
628 if (lmp_esco_capable(conn->hdev)) in hci_sco_setup()
629 hci_setup_sync(sco, conn->handle); in hci_sco_setup()
631 hci_add_sco(sco, conn->handle); in hci_sco_setup()
640 struct hci_conn *conn = container_of(work, struct hci_conn, in hci_conn_timeout() local
642 int refcnt = atomic_read(&conn->refcnt); in hci_conn_timeout()
644 BT_DBG("hcon %p state %s", conn, state_to_string(conn->state)); in hci_conn_timeout()
650 * l2cap_chan_del for each channel, and inside l2cap_chan_del conn is in hci_conn_timeout()
652 * conn. For now make sure that ACL is alive if refcnt is higher then 0, in hci_conn_timeout()
659 if (conn->state == BT_CONNECT && conn->type == LE_LINK && in hci_conn_timeout()
660 test_bit(HCI_CONN_SCANNING, &conn->flags)) { in hci_conn_timeout()
661 hci_connect_le_scan_remove(conn); in hci_conn_timeout()
665 hci_abort_conn(conn, hci_proto_disconn_ind(conn)); in hci_conn_timeout()
671 struct hci_conn *conn = container_of(work, struct hci_conn, in hci_conn_idle() local
673 struct hci_dev *hdev = conn->hdev; in hci_conn_idle()
675 BT_DBG("hcon %p mode %d", conn, conn->mode); in hci_conn_idle()
677 if (!lmp_sniff_capable(hdev) || !lmp_sniff_capable(conn)) in hci_conn_idle()
680 if (conn->mode != HCI_CM_ACTIVE || !(conn->link_policy & HCI_LP_SNIFF)) in hci_conn_idle()
683 if (lmp_sniffsubr_capable(hdev) && lmp_sniffsubr_capable(conn)) { in hci_conn_idle()
685 cp.handle = cpu_to_le16(conn->handle); in hci_conn_idle()
692 if (!test_and_set_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags)) { in hci_conn_idle()
694 cp.handle = cpu_to_le16(conn->handle); in hci_conn_idle()
705 struct hci_conn *conn = container_of(work, struct hci_conn, in hci_conn_auto_accept() local
708 hci_send_cmd(conn->hdev, HCI_OP_USER_CONFIRM_REPLY, sizeof(conn->dst), in hci_conn_auto_accept()
709 &conn->dst); in hci_conn_auto_accept()
731 struct hci_conn *conn = container_of(work, struct hci_conn, in le_conn_timeout() local
733 struct hci_dev *hdev = conn->hdev; in le_conn_timeout()
742 if (conn->role == HCI_ROLE_SLAVE) { in le_conn_timeout()
746 hci_conn_failed(conn, HCI_ERROR_ADVERTISING_TIMEOUT); in le_conn_timeout()
751 hci_abort_conn(conn, HCI_ERROR_REMOTE_USER_TERM); in le_conn_timeout()
771 static void bis_list(struct hci_conn *conn, void *data) in bis_list() argument
776 if (bacmp(&conn->dst, BDADDR_ANY)) in bis_list()
779 if (d->big != conn->iso_qos.big || d->bis == BT_ISO_QOS_BIS_UNSET || in bis_list()
780 d->bis != conn->iso_qos.bis) in bis_list()
786 static void find_bis(struct hci_conn *conn, void *data) in find_bis() argument
791 if (bacmp(&conn->dst, BDADDR_ANY)) in find_bis()
882 static void bis_cleanup(struct hci_conn *conn) in bis_cleanup() argument
884 struct hci_dev *hdev = conn->hdev; in bis_cleanup()
886 bt_dev_dbg(hdev, "conn %p", conn); in bis_cleanup()
888 if (conn->role == HCI_ROLE_MASTER) { in bis_cleanup()
889 if (!test_and_clear_bit(HCI_CONN_PER_ADV, &conn->flags)) in bis_cleanup()
892 hci_le_terminate_big(hdev, conn->iso_qos.big, in bis_cleanup()
893 conn->iso_qos.bis); in bis_cleanup()
895 hci_le_big_terminate(hdev, conn->iso_qos.big, in bis_cleanup()
896 conn->sync_handle); in bis_cleanup()
914 static void find_cis(struct hci_conn *conn, void *data) in find_cis() argument
919 if (!bacmp(&conn->dst, BDADDR_ANY)) in find_cis()
929 static void cis_cleanup(struct hci_conn *conn) in cis_cleanup() argument
931 struct hci_dev *hdev = conn->hdev; in cis_cleanup()
935 d.cig = conn->iso_qos.cig; in cis_cleanup()
944 hci_le_remove_cig(hdev, conn->iso_qos.cig); in cis_cleanup()
950 struct hci_conn *conn; in hci_conn_add() local
954 conn = kzalloc(sizeof(*conn), GFP_KERNEL); in hci_conn_add()
955 if (!conn) in hci_conn_add()
958 bacpy(&conn->dst, dst); in hci_conn_add()
959 bacpy(&conn->src, &hdev->bdaddr); in hci_conn_add()
960 conn->handle = HCI_CONN_HANDLE_UNSET; in hci_conn_add()
961 conn->hdev = hdev; in hci_conn_add()
962 conn->type = type; in hci_conn_add()
963 conn->role = role; in hci_conn_add()
964 conn->mode = HCI_CM_ACTIVE; in hci_conn_add()
965 conn->state = BT_OPEN; in hci_conn_add()
966 conn->auth_type = HCI_AT_GENERAL_BONDING; in hci_conn_add()
967 conn->io_capability = hdev->io_capability; in hci_conn_add()
968 conn->remote_auth = 0xff; in hci_conn_add()
969 conn->key_type = 0xff; in hci_conn_add()
970 conn->rssi = HCI_RSSI_INVALID; in hci_conn_add()
971 conn->tx_power = HCI_TX_POWER_INVALID; in hci_conn_add()
972 conn->max_tx_power = HCI_TX_POWER_INVALID; in hci_conn_add()
974 set_bit(HCI_CONN_POWER_SAVE, &conn->flags); in hci_conn_add()
975 conn->disc_timeout = HCI_DISCONN_TIMEOUT; in hci_conn_add()
978 conn->auth_payload_timeout = DEFAULT_AUTH_PAYLOAD_TIMEOUT; in hci_conn_add()
980 if (conn->role == HCI_ROLE_MASTER) in hci_conn_add()
981 conn->out = true; in hci_conn_add()
985 conn->pkt_type = hdev->pkt_type & ACL_PTYPE_MASK; in hci_conn_add()
988 /* conn->src should reflect the local identity address */ in hci_conn_add()
989 hci_copy_identity_address(hdev, &conn->src, &conn->src_type); in hci_conn_add()
992 /* conn->src should reflect the local identity address */ in hci_conn_add()
993 hci_copy_identity_address(hdev, &conn->src, &conn->src_type); in hci_conn_add()
997 conn->cleanup = bis_cleanup; in hci_conn_add()
998 else if (conn->role == HCI_ROLE_MASTER) in hci_conn_add()
999 conn->cleanup = cis_cleanup; in hci_conn_add()
1004 conn->pkt_type = (hdev->esco_type & SCO_ESCO_MASK) | in hci_conn_add()
1007 conn->pkt_type = hdev->pkt_type & SCO_PTYPE_MASK; in hci_conn_add()
1010 conn->pkt_type = hdev->esco_type & ~EDR_ESCO_MASK; in hci_conn_add()
1014 skb_queue_head_init(&conn->data_q); in hci_conn_add()
1016 INIT_LIST_HEAD(&conn->chan_list); in hci_conn_add()
1018 INIT_DELAYED_WORK(&conn->disc_work, hci_conn_timeout); in hci_conn_add()
1019 INIT_DELAYED_WORK(&conn->auto_accept_work, hci_conn_auto_accept); in hci_conn_add()
1020 INIT_DELAYED_WORK(&conn->idle_work, hci_conn_idle); in hci_conn_add()
1021 INIT_DELAYED_WORK(&conn->le_conn_timeout, le_conn_timeout); in hci_conn_add()
1022 INIT_WORK(&conn->le_scan_cleanup, le_scan_cleanup); in hci_conn_add()
1024 atomic_set(&conn->refcnt, 0); in hci_conn_add()
1028 hci_conn_hash_add(hdev, conn); in hci_conn_add()
1034 if (conn->type != SCO_LINK && conn->type != ESCO_LINK) { in hci_conn_add()
1039 hci_conn_init_sysfs(conn); in hci_conn_add()
1041 return conn; in hci_conn_add()
1044 int hci_conn_del(struct hci_conn *conn) in hci_conn_del() argument
1046 struct hci_dev *hdev = conn->hdev; in hci_conn_del()
1048 BT_DBG("%s hcon %p handle %d", hdev->name, conn, conn->handle); in hci_conn_del()
1050 cancel_delayed_work_sync(&conn->disc_work); in hci_conn_del()
1051 cancel_delayed_work_sync(&conn->auto_accept_work); in hci_conn_del()
1052 cancel_delayed_work_sync(&conn->idle_work); in hci_conn_del()
1054 if (conn->type == ACL_LINK) { in hci_conn_del()
1055 struct hci_conn *sco = conn->link; in hci_conn_del()
1060 hdev->acl_cnt += conn->sent; in hci_conn_del()
1061 } else if (conn->type == LE_LINK) { in hci_conn_del()
1062 cancel_delayed_work(&conn->le_conn_timeout); in hci_conn_del()
1065 hdev->le_cnt += conn->sent; in hci_conn_del()
1067 hdev->acl_cnt += conn->sent; in hci_conn_del()
1069 struct hci_conn *acl = conn->link; in hci_conn_del()
1077 if (conn->type == ISO_LINK) { in hci_conn_del()
1079 hdev->iso_cnt += conn->sent; in hci_conn_del()
1081 hdev->le_cnt += conn->sent; in hci_conn_del()
1083 hdev->acl_cnt += conn->sent; in hci_conn_del()
1087 if (conn->amp_mgr) in hci_conn_del()
1088 amp_mgr_put(conn->amp_mgr); in hci_conn_del()
1090 skb_queue_purge(&conn->data_q); in hci_conn_del()
1097 hci_conn_cleanup(conn); in hci_conn_del()
1164 static void hci_le_conn_failed(struct hci_conn *conn, u8 status) in hci_le_conn_failed() argument
1166 struct hci_dev *hdev = conn->hdev; in hci_le_conn_failed()
1169 params = hci_pend_le_action_lookup(&hdev->pend_le_conns, &conn->dst, in hci_le_conn_failed()
1170 conn->dst_type); in hci_le_conn_failed()
1171 if (params && params->conn) { in hci_le_conn_failed()
1172 hci_conn_drop(params->conn); in hci_le_conn_failed()
1173 hci_conn_put(params->conn); in hci_le_conn_failed()
1174 params->conn = NULL; in hci_le_conn_failed()
1185 mgmt_connect_failed(hdev, &conn->dst, conn->type, in hci_le_conn_failed()
1186 conn->dst_type, status); in hci_le_conn_failed()
1200 void hci_conn_failed(struct hci_conn *conn, u8 status) in hci_conn_failed() argument
1202 struct hci_dev *hdev = conn->hdev; in hci_conn_failed()
1206 switch (conn->type) { in hci_conn_failed()
1208 hci_le_conn_failed(conn, status); in hci_conn_failed()
1211 mgmt_connect_failed(hdev, &conn->dst, conn->type, in hci_conn_failed()
1212 conn->dst_type, status); in hci_conn_failed()
1216 conn->state = BT_CLOSED; in hci_conn_failed()
1217 hci_connect_cfm(conn, status); in hci_conn_failed()
1218 hci_conn_del(conn); in hci_conn_failed()
1223 struct hci_conn *conn = data; in create_le_conn_complete() local
1228 hci_connect_le_scan_cleanup(conn); in create_le_conn_complete()
1235 if (conn != hci_lookup_le_connect(hdev)) in create_le_conn_complete()
1238 hci_conn_failed(conn, bt_status(err)); in create_le_conn_complete()
1246 struct hci_conn *conn = data; in hci_connect_le_sync() local
1248 bt_dev_dbg(hdev, "conn %p", conn); in hci_connect_le_sync()
1250 return hci_le_create_conn_sync(hdev, conn); in hci_connect_le_sync()
1257 struct hci_conn *conn; in hci_connect_le() local
1280 conn = hci_conn_hash_lookup_le(hdev, dst, dst_type); in hci_connect_le()
1281 if (conn && !test_bit(HCI_CONN_SCANNING, &conn->flags)) { in hci_connect_le()
1305 if (conn) { in hci_connect_le()
1306 bacpy(&conn->dst, dst); in hci_connect_le()
1308 conn = hci_conn_add(hdev, LE_LINK, dst, role); in hci_connect_le()
1309 if (!conn) in hci_connect_le()
1311 hci_conn_hold(conn); in hci_connect_le()
1312 conn->pending_sec_level = sec_level; in hci_connect_le()
1315 conn->dst_type = dst_type; in hci_connect_le()
1316 conn->sec_level = BT_SECURITY_LOW; in hci_connect_le()
1317 conn->conn_timeout = conn_timeout; in hci_connect_le()
1319 conn->state = BT_CONNECT; in hci_connect_le()
1320 clear_bit(HCI_CONN_SCANNING, &conn->flags); in hci_connect_le()
1322 err = hci_cmd_sync_queue(hdev, hci_connect_le_sync, conn, in hci_connect_le()
1325 hci_conn_del(conn); in hci_connect_le()
1329 return conn; in hci_connect_le()
1334 struct hci_conn *conn; in is_connected() local
1336 conn = hci_conn_hash_lookup_le(hdev, addr, type); in is_connected()
1337 if (!conn) in is_connected()
1340 if (conn->state != BT_CONNECTED) in is_connected()
1443 struct hci_conn *conn; in hci_add_bis() local
1471 conn = hci_conn_hash_lookup_bis(hdev, dst, qos->big, qos->bis); in hci_add_bis()
1472 if (conn) in hci_add_bis()
1475 conn = hci_conn_add(hdev, ISO_LINK, dst, HCI_ROLE_MASTER); in hci_add_bis()
1476 if (!conn) in hci_add_bis()
1479 set_bit(HCI_CONN_PER_ADV, &conn->flags); in hci_add_bis()
1480 conn->state = BT_CONNECT; in hci_add_bis()
1482 hci_conn_hold(conn); in hci_add_bis()
1483 return conn; in hci_add_bis()
1492 struct hci_conn *conn; in hci_connect_le_scan() local
1511 conn = hci_conn_hash_lookup_le(hdev, dst, dst_type); in hci_connect_le_scan()
1512 if (conn) { in hci_connect_le_scan()
1513 if (conn->pending_sec_level < sec_level) in hci_connect_le_scan()
1514 conn->pending_sec_level = sec_level; in hci_connect_le_scan()
1520 conn = hci_conn_add(hdev, LE_LINK, dst, HCI_ROLE_MASTER); in hci_connect_le_scan()
1521 if (!conn) in hci_connect_le_scan()
1525 hci_conn_del(conn); in hci_connect_le_scan()
1529 conn->state = BT_CONNECT; in hci_connect_le_scan()
1530 set_bit(HCI_CONN_SCANNING, &conn->flags); in hci_connect_le_scan()
1531 conn->dst_type = dst_type; in hci_connect_le_scan()
1532 conn->sec_level = BT_SECURITY_LOW; in hci_connect_le_scan()
1533 conn->pending_sec_level = sec_level; in hci_connect_le_scan()
1534 conn->conn_timeout = conn_timeout; in hci_connect_le_scan()
1535 conn->conn_reason = conn_reason; in hci_connect_le_scan()
1540 hci_conn_hold(conn); in hci_connect_le_scan()
1541 return conn; in hci_connect_le_scan()
1637 static void cis_list(struct hci_conn *conn, void *data) in cis_list() argument
1642 if (!bacmp(&conn->dst, BDADDR_ANY)) in cis_list()
1645 if (d->cig != conn->iso_qos.cig || d->cis == BT_ISO_QOS_CIS_UNSET || in cis_list()
1646 d->cis != conn->iso_qos.cis) in cis_list()
1655 cis_add(d, &conn->iso_qos); in cis_list()
1658 static int hci_le_create_big(struct hci_conn *conn, struct bt_iso_qos *qos) in hci_le_create_big() argument
1660 struct hci_dev *hdev = conn->hdev; in hci_le_create_big()
1681 static bool hci_le_set_cig_params(struct hci_conn *conn, struct bt_iso_qos *qos) in hci_le_set_cig_params() argument
1683 struct hci_dev *hdev = conn->hdev; in hci_le_set_cig_params()
1825 bool hci_iso_setup_path(struct hci_conn *conn) in hci_iso_setup_path() argument
1827 struct hci_dev *hdev = conn->hdev; in hci_iso_setup_path()
1832 if (conn->iso_qos.out.sdu) { in hci_iso_setup_path()
1833 cmd.handle = cpu_to_le16(conn->handle); in hci_iso_setup_path()
1843 if (conn->iso_qos.in.sdu) { in hci_iso_setup_path()
1844 cmd.handle = cpu_to_le16(conn->handle); in hci_iso_setup_path()
1863 struct hci_conn *conn = data; in hci_create_cis_sync() local
1867 cmd.cis[0].acl_handle = cpu_to_le16(conn->link->handle); in hci_create_cis_sync()
1868 cmd.cis[0].cis_handle = cpu_to_le16(conn->handle); in hci_create_cis_sync()
1870 cig = conn->iso_qos.cig; in hci_create_cis_sync()
1876 list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) { in hci_create_cis_sync()
1879 if (conn == data || conn->type != ISO_LINK || in hci_create_cis_sync()
1880 conn->state == BT_CONNECTED || conn->iso_qos.cig != cig) in hci_create_cis_sync()
1884 if (conn->link->state != BT_CONNECTED || in hci_create_cis_sync()
1885 conn->state != BT_CONNECT) { in hci_create_cis_sync()
1901 cis->acl_handle = cpu_to_le16(conn->link->handle); in hci_create_cis_sync()
1902 cis->cis_handle = cpu_to_le16(conn->handle); in hci_create_cis_sync()
1917 int hci_le_create_cis(struct hci_conn *conn) in hci_le_create_cis() argument
1920 struct hci_dev *hdev = conn->hdev; in hci_le_create_cis()
1923 switch (conn->type) { in hci_le_create_cis()
1925 if (!conn->link || conn->state != BT_CONNECTED) in hci_le_create_cis()
1927 cis = conn->link; in hci_le_create_cis()
1930 cis = conn; in hci_le_create_cis()
1949 static void hci_iso_qos_setup(struct hci_dev *hdev, struct hci_conn *conn, in hci_iso_qos_setup() argument
1969 qos->interval = conn->le_conn_interval * 1250; in hci_iso_qos_setup()
1973 qos->latency = conn->le_conn_latency; in hci_iso_qos_setup()
1976 static struct hci_conn *hci_bind_bis(struct hci_conn *conn, in hci_bind_bis() argument
1980 conn->le_tx_phy = qos->out.phy; in hci_bind_bis()
1981 conn->le_tx_phy = qos->out.phy; in hci_bind_bis()
1982 conn->iso_qos = *qos; in hci_bind_bis()
1983 conn->state = BT_BOUND; in hci_bind_bis()
1985 return conn; in hci_bind_bis()
1990 struct hci_conn *conn = data; in create_big_sync() local
1991 struct bt_iso_qos *qos = &conn->iso_qos; in create_big_sync()
2005 err = hci_start_per_adv_sync(hdev, qos->bis, conn->le_per_adv_data_len, in create_big_sync()
2006 conn->le_per_adv_data, flags, interval, in create_big_sync()
2011 return hci_le_create_big(conn, &conn->iso_qos); in create_big_sync()
2098 struct hci_conn *conn = data; in create_big_complete() local
2100 bt_dev_dbg(hdev, "conn %p", conn); in create_big_complete()
2104 hci_connect_cfm(conn, err); in create_big_complete()
2105 hci_conn_del(conn); in create_big_complete()
2113 struct hci_conn *conn; in hci_connect_bis() local
2117 conn = hci_add_bis(hdev, dst, qos); in hci_connect_bis()
2118 if (IS_ERR(conn)) in hci_connect_bis()
2119 return conn; in hci_connect_bis()
2121 conn = hci_bind_bis(conn, qos); in hci_connect_bis()
2122 if (!conn) { in hci_connect_bis()
2123 hci_conn_drop(conn); in hci_connect_bis()
2129 base_len = eir_append_service_data(conn->le_per_adv_data, 0, in hci_connect_bis()
2131 conn->le_per_adv_data_len = base_len; in hci_connect_bis()
2135 err = hci_cmd_sync_queue(hdev, create_big_sync, conn, in hci_connect_bis()
2138 hci_conn_drop(conn); in hci_connect_bis()
2142 hci_iso_qos_setup(hdev, conn, &qos->out, in hci_connect_bis()
2143 conn->le_tx_phy ? conn->le_tx_phy : in hci_connect_bis()
2146 return conn; in hci_connect_bis()
2194 int hci_conn_check_link_mode(struct hci_conn *conn) in hci_conn_check_link_mode() argument
2196 BT_DBG("hcon %p", conn); in hci_conn_check_link_mode()
2202 if (hci_dev_test_flag(conn->hdev, HCI_SC_ONLY)) { in hci_conn_check_link_mode()
2203 if (!hci_conn_sc_enabled(conn) || in hci_conn_check_link_mode()
2204 !test_bit(HCI_CONN_AES_CCM, &conn->flags) || in hci_conn_check_link_mode()
2205 conn->key_type != HCI_LK_AUTH_COMBINATION_P256) in hci_conn_check_link_mode()
2219 if (conn->sec_level == BT_SECURITY_FIPS && in hci_conn_check_link_mode()
2220 !test_bit(HCI_CONN_AES_CCM, &conn->flags)) { in hci_conn_check_link_mode()
2221 bt_dev_err(conn->hdev, in hci_conn_check_link_mode()
2226 if (hci_conn_ssp_enabled(conn) && in hci_conn_check_link_mode()
2227 !test_bit(HCI_CONN_ENCRYPT, &conn->flags)) in hci_conn_check_link_mode()
2234 static int hci_conn_auth(struct hci_conn *conn, __u8 sec_level, __u8 auth_type) in hci_conn_auth() argument
2236 BT_DBG("hcon %p", conn); in hci_conn_auth()
2238 if (conn->pending_sec_level > sec_level) in hci_conn_auth()
2239 sec_level = conn->pending_sec_level; in hci_conn_auth()
2241 if (sec_level > conn->sec_level) in hci_conn_auth()
2242 conn->pending_sec_level = sec_level; in hci_conn_auth()
2243 else if (test_bit(HCI_CONN_AUTH, &conn->flags)) in hci_conn_auth()
2247 auth_type |= (conn->auth_type & 0x01); in hci_conn_auth()
2249 conn->auth_type = auth_type; in hci_conn_auth()
2251 if (!test_and_set_bit(HCI_CONN_AUTH_PEND, &conn->flags)) { in hci_conn_auth()
2254 cp.handle = cpu_to_le16(conn->handle); in hci_conn_auth()
2255 hci_send_cmd(conn->hdev, HCI_OP_AUTH_REQUESTED, in hci_conn_auth()
2261 if (test_bit(HCI_CONN_ENCRYPT, &conn->flags)) in hci_conn_auth()
2262 set_bit(HCI_CONN_REAUTH_PEND, &conn->flags); in hci_conn_auth()
2264 set_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags); in hci_conn_auth()
2271 static void hci_conn_encrypt(struct hci_conn *conn) in hci_conn_encrypt() argument
2273 BT_DBG("hcon %p", conn); in hci_conn_encrypt()
2275 if (!test_and_set_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) { in hci_conn_encrypt()
2277 cp.handle = cpu_to_le16(conn->handle); in hci_conn_encrypt()
2279 hci_send_cmd(conn->hdev, HCI_OP_SET_CONN_ENCRYPT, sizeof(cp), in hci_conn_encrypt()
2285 int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type, in hci_conn_security() argument
2288 BT_DBG("hcon %p", conn); in hci_conn_security()
2290 if (conn->type == LE_LINK) in hci_conn_security()
2291 return smp_conn_security(conn, sec_level); in hci_conn_security()
2299 if (sec_level == BT_SECURITY_LOW && !hci_conn_ssp_enabled(conn)) in hci_conn_security()
2303 if (!test_bit(HCI_CONN_AUTH, &conn->flags)) in hci_conn_security()
2308 if (conn->key_type == HCI_LK_AUTH_COMBINATION_P256 && in hci_conn_security()
2314 if ((conn->key_type == HCI_LK_AUTH_COMBINATION_P192 || in hci_conn_security()
2315 conn->key_type == HCI_LK_AUTH_COMBINATION_P256) && in hci_conn_security()
2321 if ((conn->key_type == HCI_LK_UNAUTH_COMBINATION_P192 || in hci_conn_security()
2322 conn->key_type == HCI_LK_UNAUTH_COMBINATION_P256) && in hci_conn_security()
2330 if (conn->key_type == HCI_LK_COMBINATION && in hci_conn_security()
2332 conn->pin_length == 16)) in hci_conn_security()
2336 if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) in hci_conn_security()
2340 set_bit(HCI_CONN_AUTH_INITIATOR, &conn->flags); in hci_conn_security()
2342 if (!hci_conn_auth(conn, sec_level, auth_type)) in hci_conn_security()
2346 if (test_bit(HCI_CONN_ENCRYPT, &conn->flags)) { in hci_conn_security()
2350 if (!conn->enc_key_size) in hci_conn_security()
2357 hci_conn_encrypt(conn); in hci_conn_security()
2363 int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level) in hci_conn_check_secure() argument
2365 BT_DBG("hcon %p", conn); in hci_conn_check_secure()
2372 if (conn->sec_level == BT_SECURITY_HIGH || in hci_conn_check_secure()
2373 conn->sec_level == BT_SECURITY_FIPS) in hci_conn_check_secure()
2382 int hci_conn_switch_role(struct hci_conn *conn, __u8 role) in hci_conn_switch_role() argument
2384 BT_DBG("hcon %p", conn); in hci_conn_switch_role()
2386 if (role == conn->role) in hci_conn_switch_role()
2389 if (!test_and_set_bit(HCI_CONN_RSWITCH_PEND, &conn->flags)) { in hci_conn_switch_role()
2391 bacpy(&cp.bdaddr, &conn->dst); in hci_conn_switch_role()
2393 hci_send_cmd(conn->hdev, HCI_OP_SWITCH_ROLE, sizeof(cp), &cp); in hci_conn_switch_role()
2401 void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active) in hci_conn_enter_active_mode() argument
2403 struct hci_dev *hdev = conn->hdev; in hci_conn_enter_active_mode()
2405 BT_DBG("hcon %p mode %d", conn, conn->mode); in hci_conn_enter_active_mode()
2407 if (conn->mode != HCI_CM_SNIFF) in hci_conn_enter_active_mode()
2410 if (!test_bit(HCI_CONN_POWER_SAVE, &conn->flags) && !force_active) in hci_conn_enter_active_mode()
2413 if (!test_and_set_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags)) { in hci_conn_enter_active_mode()
2415 cp.handle = cpu_to_le16(conn->handle); in hci_conn_enter_active_mode()
2421 queue_delayed_work(hdev->workqueue, &conn->idle_work, in hci_conn_enter_active_mode()
2444 struct hci_conn *conn; in hci_conn_check_pending() local
2450 conn = hci_conn_hash_lookup_state(hdev, ACL_LINK, BT_CONNECT2); in hci_conn_check_pending()
2451 if (conn) in hci_conn_check_pending()
2452 hci_acl_create_connection(conn); in hci_conn_check_pending()
2457 static u32 get_link_mode(struct hci_conn *conn) in get_link_mode() argument
2461 if (conn->role == HCI_ROLE_MASTER) in get_link_mode()
2464 if (test_bit(HCI_CONN_ENCRYPT, &conn->flags)) in get_link_mode()
2467 if (test_bit(HCI_CONN_AUTH, &conn->flags)) in get_link_mode()
2470 if (test_bit(HCI_CONN_SECURE, &conn->flags)) in get_link_mode()
2473 if (test_bit(HCI_CONN_FIPS, &conn->flags)) in get_link_mode()
2536 struct hci_conn *conn; in hci_get_conn_info() local
2543 conn = hci_conn_hash_lookup_ba(hdev, req.type, &req.bdaddr); in hci_get_conn_info()
2544 if (conn) { in hci_get_conn_info()
2545 bacpy(&ci.bdaddr, &conn->dst); in hci_get_conn_info()
2546 ci.handle = conn->handle; in hci_get_conn_info()
2547 ci.type = conn->type; in hci_get_conn_info()
2548 ci.out = conn->out; in hci_get_conn_info()
2549 ci.state = conn->state; in hci_get_conn_info()
2550 ci.link_mode = get_link_mode(conn); in hci_get_conn_info()
2554 if (!conn) in hci_get_conn_info()
2563 struct hci_conn *conn; in hci_get_auth_info() local
2569 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &req.bdaddr); in hci_get_auth_info()
2570 if (conn) in hci_get_auth_info()
2571 req.type = conn->auth_type; in hci_get_auth_info()
2574 if (!conn) in hci_get_auth_info()
2580 struct hci_chan *hci_chan_create(struct hci_conn *conn) in hci_chan_create() argument
2582 struct hci_dev *hdev = conn->hdev; in hci_chan_create()
2585 BT_DBG("%s hcon %p", hdev->name, conn); in hci_chan_create()
2587 if (test_bit(HCI_CONN_DROP, &conn->flags)) { in hci_chan_create()
2596 chan->conn = hci_conn_get(conn); in hci_chan_create()
2600 list_add_rcu(&chan->list, &conn->chan_list); in hci_chan_create()
2607 struct hci_conn *conn = chan->conn; in hci_chan_del() local
2608 struct hci_dev *hdev = conn->hdev; in hci_chan_del()
2610 BT_DBG("%s hcon %p chan %p", hdev->name, conn, chan); in hci_chan_del()
2617 set_bit(HCI_CONN_DROP, &conn->flags); in hci_chan_del()
2619 hci_conn_put(conn); in hci_chan_del()
2625 void hci_chan_list_flush(struct hci_conn *conn) in hci_chan_list_flush() argument
2629 BT_DBG("hcon %p", conn); in hci_chan_list_flush()
2631 list_for_each_entry_safe(chan, n, &conn->chan_list, list) in hci_chan_list_flush()
2667 u32 hci_conn_get_phy(struct hci_conn *conn) in hci_conn_get_phy() argument
2675 switch (conn->type) { in hci_conn_get_phy()
2690 if (conn->pkt_type & (HCI_DM3 | HCI_DH3)) in hci_conn_get_phy()
2693 if (conn->pkt_type & (HCI_DM5 | HCI_DH5)) in hci_conn_get_phy()
2699 if (!(conn->pkt_type & HCI_2DH1)) in hci_conn_get_phy()
2702 if (!(conn->pkt_type & HCI_2DH3)) in hci_conn_get_phy()
2705 if (!(conn->pkt_type & HCI_2DH5)) in hci_conn_get_phy()
2711 if (!(conn->pkt_type & HCI_3DH1)) in hci_conn_get_phy()
2714 if (!(conn->pkt_type & HCI_3DH3)) in hci_conn_get_phy()
2717 if (!(conn->pkt_type & HCI_3DH5)) in hci_conn_get_phy()
2726 if (!(conn->pkt_type & (ESCO_EV4 | ESCO_EV5))) in hci_conn_get_phy()
2730 if (!(conn->pkt_type & ESCO_2EV3)) in hci_conn_get_phy()
2733 if (!(conn->pkt_type & ESCO_2EV5)) in hci_conn_get_phy()
2737 if (!(conn->pkt_type & ESCO_3EV3)) in hci_conn_get_phy()
2740 if (!(conn->pkt_type & ESCO_3EV5)) in hci_conn_get_phy()
2746 if (conn->le_tx_phy & HCI_LE_SET_PHY_1M) in hci_conn_get_phy()
2749 if (conn->le_rx_phy & HCI_LE_SET_PHY_1M) in hci_conn_get_phy()
2752 if (conn->le_tx_phy & HCI_LE_SET_PHY_2M) in hci_conn_get_phy()
2755 if (conn->le_rx_phy & HCI_LE_SET_PHY_2M) in hci_conn_get_phy()
2758 if (conn->le_tx_phy & HCI_LE_SET_PHY_CODED) in hci_conn_get_phy()
2761 if (conn->le_rx_phy & HCI_LE_SET_PHY_CODED) in hci_conn_get_phy()
2770 int hci_abort_conn(struct hci_conn *conn, u8 reason) in hci_abort_conn() argument
2774 switch (conn->state) { in hci_abort_conn()
2777 if (conn->type == AMP_LINK) { in hci_abort_conn()
2780 cp.phy_handle = HCI_PHY_HANDLE(conn->handle); in hci_abort_conn()
2782 r = hci_send_cmd(conn->hdev, HCI_OP_DISCONN_PHY_LINK, in hci_abort_conn()
2787 dc.handle = cpu_to_le16(conn->handle); in hci_abort_conn()
2789 r = hci_send_cmd(conn->hdev, HCI_OP_DISCONNECT, in hci_abort_conn()
2793 conn->state = BT_DISCONN; in hci_abort_conn()
2797 if (conn->type == LE_LINK) { in hci_abort_conn()
2798 if (test_bit(HCI_CONN_SCANNING, &conn->flags)) in hci_abort_conn()
2800 r = hci_send_cmd(conn->hdev, in hci_abort_conn()
2802 } else if (conn->type == ACL_LINK) { in hci_abort_conn()
2803 if (conn->hdev->hci_ver < BLUETOOTH_VER_1_2) in hci_abort_conn()
2805 r = hci_send_cmd(conn->hdev, in hci_abort_conn()
2807 6, &conn->dst); in hci_abort_conn()
2811 if (conn->type == ACL_LINK) { in hci_abort_conn()
2814 bacpy(&rej.bdaddr, &conn->dst); in hci_abort_conn()
2817 r = hci_send_cmd(conn->hdev, in hci_abort_conn()
2820 } else if (conn->type == SCO_LINK || conn->type == ESCO_LINK) { in hci_abort_conn()
2823 bacpy(&rej.bdaddr, &conn->dst); in hci_abort_conn()
2833 r = hci_send_cmd(conn->hdev, in hci_abort_conn()
2839 conn->state = BT_CLOSED; in hci_abort_conn()