Lines Matching refs:hdev
65 struct hci_dev *hdev = file->private_data; in dut_mode_read() local
68 buf[0] = hci_dev_test_flag(hdev, HCI_DUT_MODE) ? 'Y' : 'N'; in dut_mode_read()
77 struct hci_dev *hdev = file->private_data; in dut_mode_write() local
82 if (!test_bit(HCI_UP, &hdev->flags)) in dut_mode_write()
89 if (enable == hci_dev_test_flag(hdev, HCI_DUT_MODE)) in dut_mode_write()
92 hci_req_sync_lock(hdev); in dut_mode_write()
94 skb = __hci_cmd_sync(hdev, HCI_OP_ENABLE_DUT_MODE, 0, NULL, in dut_mode_write()
97 skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, in dut_mode_write()
99 hci_req_sync_unlock(hdev); in dut_mode_write()
106 hci_dev_change_flag(hdev, HCI_DUT_MODE); in dut_mode_write()
121 struct hci_dev *hdev = file->private_data; in vendor_diag_read() local
124 buf[0] = hci_dev_test_flag(hdev, HCI_VENDOR_DIAG) ? 'Y' : 'N'; in vendor_diag_read()
133 struct hci_dev *hdev = file->private_data; in vendor_diag_write() local
146 if (test_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks) && in vendor_diag_write()
147 (!test_bit(HCI_RUNNING, &hdev->flags) || in vendor_diag_write()
148 hci_dev_test_flag(hdev, HCI_USER_CHANNEL))) in vendor_diag_write()
151 hci_req_sync_lock(hdev); in vendor_diag_write()
152 err = hdev->set_diag(hdev, enable); in vendor_diag_write()
153 hci_req_sync_unlock(hdev); in vendor_diag_write()
160 hci_dev_set_flag(hdev, HCI_VENDOR_DIAG); in vendor_diag_write()
162 hci_dev_clear_flag(hdev, HCI_VENDOR_DIAG); in vendor_diag_write()
174 static void hci_debugfs_create_basic(struct hci_dev *hdev) in hci_debugfs_create_basic() argument
176 debugfs_create_file("dut_mode", 0644, hdev->debugfs, hdev, in hci_debugfs_create_basic()
179 if (hdev->set_diag) in hci_debugfs_create_basic()
180 debugfs_create_file("vendor_diag", 0644, hdev->debugfs, hdev, in hci_debugfs_create_basic()
186 BT_DBG("%s %ld", req->hdev->name, opt); in hci_reset_req()
189 set_bit(HCI_RESET, &req->hdev->flags); in hci_reset_req()
196 req->hdev->flow_ctl_mode = HCI_FLOW_CTL_MODE_PACKET_BASED; in bredr_init()
210 req->hdev->flow_ctl_mode = HCI_FLOW_CTL_MODE_BLOCK_BASED; in amp_init1()
237 if (req->hdev->commands[14] & 0x20) in amp_init2()
245 struct hci_dev *hdev = req->hdev; in hci_init1_req() local
247 BT_DBG("%s %ld", hdev->name, opt); in hci_init1_req()
250 if (!test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks)) in hci_init1_req()
253 switch (hdev->dev_type) { in hci_init1_req()
261 bt_dev_err(hdev, "Unknown device type %d", hdev->dev_type); in hci_init1_req()
302 struct hci_dev *hdev = req->hdev; in le_setup() local
314 if (!lmp_bredr_capable(hdev)) in le_setup()
315 hci_dev_set_flag(hdev, HCI_LE_ENABLED); in le_setup()
320 struct hci_dev *hdev = req->hdev; in hci_setup_event_mask() local
331 if (hdev->hci_ver < BLUETOOTH_VER_1_2) in hci_setup_event_mask()
334 if (lmp_bredr_capable(hdev)) { in hci_setup_event_mask()
347 if (hdev->commands[0] & 0x20) { in hci_setup_event_mask()
356 if (hdev->commands[2] & 0x80) in hci_setup_event_mask()
361 if (hdev->le_features[0] & HCI_LE_ENCRYPTION) { in hci_setup_event_mask()
367 if (lmp_inq_rssi_capable(hdev) || in hci_setup_event_mask()
368 test_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks)) in hci_setup_event_mask()
371 if (lmp_ext_feat_capable(hdev)) in hci_setup_event_mask()
374 if (lmp_esco_capable(hdev)) { in hci_setup_event_mask()
379 if (lmp_sniffsubr_capable(hdev)) in hci_setup_event_mask()
382 if (lmp_pause_enc_capable(hdev)) in hci_setup_event_mask()
385 if (lmp_ext_inq_capable(hdev)) in hci_setup_event_mask()
388 if (lmp_no_flush_capable(hdev)) in hci_setup_event_mask()
391 if (lmp_lsto_capable(hdev)) in hci_setup_event_mask()
394 if (lmp_ssp_capable(hdev)) { in hci_setup_event_mask()
408 if (lmp_le_capable(hdev)) in hci_setup_event_mask()
416 struct hci_dev *hdev = req->hdev; in hci_init2_req() local
418 if (hdev->dev_type == HCI_AMP) in hci_init2_req()
421 if (lmp_bredr_capable(hdev)) in hci_init2_req()
424 hci_dev_clear_flag(hdev, HCI_BREDR_ENABLED); in hci_init2_req()
426 if (lmp_le_capable(hdev)) in hci_init2_req()
437 if (hdev->hci_ver > BLUETOOTH_VER_1_1 && in hci_init2_req()
438 !test_bit(HCI_QUIRK_BROKEN_LOCAL_COMMANDS, &hdev->quirks)) in hci_init2_req()
441 if (lmp_ssp_capable(hdev)) { in hci_init2_req()
448 hdev->max_page = 0x01; in hci_init2_req()
450 if (hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) { in hci_init2_req()
458 memset(hdev->eir, 0, sizeof(hdev->eir)); in hci_init2_req()
465 if (lmp_inq_rssi_capable(hdev) || in hci_init2_req()
466 test_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks)) { in hci_init2_req()
473 mode = lmp_ext_inq_capable(hdev) ? 0x02 : 0x01; in hci_init2_req()
478 if (lmp_inq_tx_pwr_capable(hdev)) in hci_init2_req()
481 if (lmp_ext_feat_capable(hdev)) { in hci_init2_req()
489 if (hci_dev_test_flag(hdev, HCI_LINK_SECURITY)) { in hci_init2_req()
500 struct hci_dev *hdev = req->hdev; in hci_setup_link_policy() local
504 if (lmp_rswitch_capable(hdev)) in hci_setup_link_policy()
506 if (lmp_hold_capable(hdev)) in hci_setup_link_policy()
508 if (lmp_sniff_capable(hdev)) in hci_setup_link_policy()
510 if (lmp_park_capable(hdev)) in hci_setup_link_policy()
519 struct hci_dev *hdev = req->hdev; in hci_set_le_support() local
523 if (!lmp_bredr_capable(hdev)) in hci_set_le_support()
528 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { in hci_set_le_support()
533 if (cp.le != lmp_host_le_capable(hdev)) in hci_set_le_support()
540 struct hci_dev *hdev = req->hdev; in hci_set_event_mask_page_2() local
547 if (lmp_csb_master_capable(hdev)) { in hci_set_event_mask_page_2()
558 if (lmp_csb_slave_capable(hdev)) { in hci_set_event_mask_page_2()
567 if (lmp_ping_capable(hdev) || hdev->le_features[0] & HCI_LE_PING) { in hci_set_event_mask_page_2()
585 struct hci_dev *hdev = req->hdev; in hci_init3_req() local
590 if (hdev->commands[6] & 0x20 && in hci_init3_req()
591 !test_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks)) { in hci_init3_req()
599 if (hdev->commands[5] & 0x10) in hci_init3_req()
602 if (hdev->commands[8] & 0x01) in hci_init3_req()
609 if (hdev->commands[13] & 0x01) in hci_init3_req()
612 if (lmp_le_capable(hdev)) { in hci_init3_req()
617 if (hdev->le_features[0] & HCI_LE_ENCRYPTION) in hci_init3_req()
623 if (hdev->le_features[0] & HCI_LE_CONN_PARAM_REQ_PROC) in hci_init3_req()
631 if (hdev->le_features[0] & HCI_LE_DATA_LEN_EXT) in hci_init3_req()
637 if (hdev->le_features[0] & HCI_LE_EXT_SCAN_POLICY) in hci_init3_req()
645 if (hdev->le_features[1] & HCI_LE_CHAN_SEL_ALG2) in hci_init3_req()
653 if (hdev->commands[26] & 0x08) in hci_init3_req()
659 if (hdev->commands[26] & 0x10) in hci_init3_req()
665 if (hdev->commands[27] & 0x04) in hci_init3_req()
673 if (hdev->commands[27] & 0x20) in hci_init3_req()
681 if (hdev->commands[34] & 0x02) in hci_init3_req()
689 if (hdev->commands[34] & 0x04) in hci_init3_req()
695 if (hdev->commands[35] & (0x20 | 0x40)) in hci_init3_req()
702 if (use_ext_scan(hdev)) in hci_init3_req()
710 if (use_ext_conn(hdev)) in hci_init3_req()
718 if (ext_adv_capable(hdev)) in hci_init3_req()
727 if ((hdev->commands[25] & 0x40) && !ext_adv_capable(hdev)) { in hci_init3_req()
737 if (hdev->commands[26] & 0x40) { in hci_init3_req()
743 if (hdev->commands[26] & 0x80) { in hci_init3_req()
748 if (hdev->commands[34] & 0x40) { in hci_init3_req()
754 if (hdev->commands[34] & 0x20) { in hci_init3_req()
759 if (hdev->le_features[0] & HCI_LE_DATA_LEN_EXT) { in hci_init3_req()
767 if (ext_adv_capable(hdev)) { in hci_init3_req()
777 for (p = 2; p < HCI_MAX_PAGES && p <= hdev->max_page; p++) { in hci_init3_req()
790 struct hci_dev *hdev = req->hdev; in hci_init4_req() local
805 if (hdev->commands[6] & 0x80 && in hci_init4_req()
806 !test_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks)) { in hci_init4_req()
816 if (hdev->commands[22] & 0x04) in hci_init4_req()
820 if (hdev->commands[29] & 0x20) in hci_init4_req()
824 if (hdev->commands[30] & 0x08) in hci_init4_req()
828 if (lmp_sync_train_capable(hdev)) in hci_init4_req()
832 if (hci_dev_test_flag(hdev, HCI_SSP_ENABLED) && in hci_init4_req()
833 bredr_sc_enabled(hdev)) { in hci_init4_req()
841 if (hdev->le_features[0] & HCI_LE_DATA_LEN_EXT) { in hci_init4_req()
844 cp.tx_len = hdev->le_max_tx_len; in hci_init4_req()
845 cp.tx_time = hdev->le_max_tx_time; in hci_init4_req()
850 if (hdev->commands[35] & 0x20) { in hci_init4_req()
854 cp.tx_phys = hdev->le_tx_def_phys; in hci_init4_req()
855 cp.rx_phys = hdev->le_rx_def_phys; in hci_init4_req()
863 static int __hci_init(struct hci_dev *hdev) in __hci_init() argument
867 err = __hci_req_sync(hdev, hci_init1_req, 0, HCI_INIT_TIMEOUT, NULL); in __hci_init()
871 if (hci_dev_test_flag(hdev, HCI_SETUP)) in __hci_init()
872 hci_debugfs_create_basic(hdev); in __hci_init()
874 err = __hci_req_sync(hdev, hci_init2_req, 0, HCI_INIT_TIMEOUT, NULL); in __hci_init()
882 if (hdev->dev_type != HCI_PRIMARY) in __hci_init()
885 err = __hci_req_sync(hdev, hci_init3_req, 0, HCI_INIT_TIMEOUT, NULL); in __hci_init()
889 err = __hci_req_sync(hdev, hci_init4_req, 0, HCI_INIT_TIMEOUT, NULL); in __hci_init()
905 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in __hci_init()
906 !hci_dev_test_flag(hdev, HCI_CONFIG)) in __hci_init()
909 hci_debugfs_create_common(hdev); in __hci_init()
911 if (lmp_bredr_capable(hdev)) in __hci_init()
912 hci_debugfs_create_bredr(hdev); in __hci_init()
914 if (lmp_le_capable(hdev)) in __hci_init()
915 hci_debugfs_create_le(hdev); in __hci_init()
922 struct hci_dev *hdev = req->hdev; in hci_init0_req() local
924 BT_DBG("%s %ld", hdev->name, opt); in hci_init0_req()
927 if (!test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks)) in hci_init0_req()
934 if (hdev->set_bdaddr) in hci_init0_req()
940 static int __hci_unconf_init(struct hci_dev *hdev) in __hci_unconf_init() argument
944 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in __hci_unconf_init()
947 err = __hci_req_sync(hdev, hci_init0_req, 0, HCI_INIT_TIMEOUT, NULL); in __hci_unconf_init()
951 if (hci_dev_test_flag(hdev, HCI_SETUP)) in __hci_unconf_init()
952 hci_debugfs_create_basic(hdev); in __hci_unconf_init()
961 BT_DBG("%s %x", req->hdev->name, scan); in hci_scan_req()
972 BT_DBG("%s %x", req->hdev->name, auth); in hci_auth_req()
983 BT_DBG("%s %x", req->hdev->name, encrypt); in hci_encrypt_req()
994 BT_DBG("%s %x", req->hdev->name, policy); in hci_linkpol_req()
1005 struct hci_dev *hdev = NULL, *d; in hci_dev_get() local
1015 hdev = hci_dev_hold(d); in hci_dev_get()
1020 return hdev; in hci_dev_get()
1025 bool hci_discovery_active(struct hci_dev *hdev) in hci_discovery_active() argument
1027 struct discovery_state *discov = &hdev->discovery; in hci_discovery_active()
1039 void hci_discovery_set_state(struct hci_dev *hdev, int state) in hci_discovery_set_state() argument
1041 int old_state = hdev->discovery.state; in hci_discovery_set_state()
1043 BT_DBG("%s state %u -> %u", hdev->name, hdev->discovery.state, state); in hci_discovery_set_state()
1048 hdev->discovery.state = state; in hci_discovery_set_state()
1052 hci_update_background_scan(hdev); in hci_discovery_set_state()
1055 mgmt_discovering(hdev, 0); in hci_discovery_set_state()
1060 mgmt_discovering(hdev, 1); in hci_discovery_set_state()
1069 void hci_inquiry_cache_flush(struct hci_dev *hdev) in hci_inquiry_cache_flush() argument
1071 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_flush()
1083 struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev, in hci_inquiry_cache_lookup() argument
1086 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_lookup()
1099 struct inquiry_entry *hci_inquiry_cache_lookup_unknown(struct hci_dev *hdev, in hci_inquiry_cache_lookup_unknown() argument
1102 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_lookup_unknown()
1115 struct inquiry_entry *hci_inquiry_cache_lookup_resolve(struct hci_dev *hdev, in hci_inquiry_cache_lookup_resolve() argument
1119 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_lookup_resolve()
1134 void hci_inquiry_cache_update_resolve(struct hci_dev *hdev, in hci_inquiry_cache_update_resolve() argument
1137 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_update_resolve()
1153 u32 hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data, in hci_inquiry_cache_update() argument
1156 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_update()
1162 hci_remove_remote_oob_data(hdev, &data->bdaddr, BDADDR_BREDR); in hci_inquiry_cache_update()
1167 ie = hci_inquiry_cache_lookup(hdev, &data->bdaddr); in hci_inquiry_cache_update()
1175 hci_inquiry_cache_update_resolve(hdev, ie); in hci_inquiry_cache_update()
1215 static int inquiry_cache_dump(struct hci_dev *hdev, int num, __u8 *buf) in inquiry_cache_dump() argument
1217 struct discovery_state *cache = &hdev->discovery; in inquiry_cache_dump()
1246 struct hci_dev *hdev = req->hdev; in hci_inq_req() local
1249 BT_DBG("%s", hdev->name); in hci_inq_req()
1251 if (test_bit(HCI_INQUIRY, &hdev->flags)) in hci_inq_req()
1267 struct hci_dev *hdev; in hci_inquiry() local
1275 hdev = hci_dev_get(ir.dev_id); in hci_inquiry()
1276 if (!hdev) in hci_inquiry()
1279 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_inquiry()
1284 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_inquiry()
1289 if (hdev->dev_type != HCI_PRIMARY) { in hci_inquiry()
1294 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in hci_inquiry()
1299 hci_dev_lock(hdev); in hci_inquiry()
1300 if (inquiry_cache_age(hdev) > INQUIRY_CACHE_AGE_MAX || in hci_inquiry()
1301 inquiry_cache_empty(hdev) || ir.flags & IREQ_CACHE_FLUSH) { in hci_inquiry()
1302 hci_inquiry_cache_flush(hdev); in hci_inquiry()
1305 hci_dev_unlock(hdev); in hci_inquiry()
1310 err = hci_req_sync(hdev, hci_inq_req, (unsigned long) &ir, in hci_inquiry()
1318 if (wait_on_bit(&hdev->flags, HCI_INQUIRY, in hci_inquiry()
1337 hci_dev_lock(hdev); in hci_inquiry()
1338 ir.num_rsp = inquiry_cache_dump(hdev, max_rsp, buf); in hci_inquiry()
1339 hci_dev_unlock(hdev); in hci_inquiry()
1354 hci_dev_put(hdev); in hci_inquiry()
1358 static int hci_dev_do_open(struct hci_dev *hdev) in hci_dev_do_open() argument
1362 BT_DBG("%s %p", hdev->name, hdev); in hci_dev_do_open()
1364 hci_req_sync_lock(hdev); in hci_dev_do_open()
1366 if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) { in hci_dev_do_open()
1371 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_dev_do_open()
1372 !hci_dev_test_flag(hdev, HCI_CONFIG)) { in hci_dev_do_open()
1376 if (hci_dev_test_flag(hdev, HCI_RFKILLED)) { in hci_dev_do_open()
1393 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_do_open()
1394 hdev->dev_type == HCI_PRIMARY && in hci_dev_do_open()
1395 !bacmp(&hdev->bdaddr, BDADDR_ANY) && in hci_dev_do_open()
1396 !bacmp(&hdev->static_addr, BDADDR_ANY)) { in hci_dev_do_open()
1402 if (test_bit(HCI_UP, &hdev->flags)) { in hci_dev_do_open()
1407 if (hdev->open(hdev)) { in hci_dev_do_open()
1412 set_bit(HCI_RUNNING, &hdev->flags); in hci_dev_do_open()
1413 hci_sock_dev_event(hdev, HCI_DEV_OPEN); in hci_dev_do_open()
1415 atomic_set(&hdev->cmd_cnt, 1); in hci_dev_do_open()
1416 set_bit(HCI_INIT, &hdev->flags); in hci_dev_do_open()
1418 if (hci_dev_test_flag(hdev, HCI_SETUP) || in hci_dev_do_open()
1419 test_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks)) { in hci_dev_do_open()
1420 hci_sock_dev_event(hdev, HCI_DEV_SETUP); in hci_dev_do_open()
1422 if (hdev->setup) in hci_dev_do_open()
1423 ret = hdev->setup(hdev); in hci_dev_do_open()
1431 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) || in hci_dev_do_open()
1432 test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks)) in hci_dev_do_open()
1433 hci_dev_set_flag(hdev, HCI_UNCONFIGURED); in hci_dev_do_open()
1443 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in hci_dev_do_open()
1444 ret = __hci_unconf_init(hdev); in hci_dev_do_open()
1447 if (hci_dev_test_flag(hdev, HCI_CONFIG)) { in hci_dev_do_open()
1453 if (bacmp(&hdev->public_addr, BDADDR_ANY) && in hci_dev_do_open()
1454 hdev->set_bdaddr) in hci_dev_do_open()
1455 ret = hdev->set_bdaddr(hdev, &hdev->public_addr); in hci_dev_do_open()
1461 if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED) && in hci_dev_do_open()
1462 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_do_open()
1463 ret = __hci_init(hdev); in hci_dev_do_open()
1464 if (!ret && hdev->post_init) in hci_dev_do_open()
1465 ret = hdev->post_init(hdev); in hci_dev_do_open()
1473 if (test_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks) && in hci_dev_do_open()
1474 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_do_open()
1475 hci_dev_test_flag(hdev, HCI_VENDOR_DIAG) && hdev->set_diag) in hci_dev_do_open()
1476 ret = hdev->set_diag(hdev, true); in hci_dev_do_open()
1478 clear_bit(HCI_INIT, &hdev->flags); in hci_dev_do_open()
1481 hci_dev_hold(hdev); in hci_dev_do_open()
1482 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in hci_dev_do_open()
1483 hci_adv_instances_set_rpa_expired(hdev, true); in hci_dev_do_open()
1484 set_bit(HCI_UP, &hdev->flags); in hci_dev_do_open()
1485 hci_sock_dev_event(hdev, HCI_DEV_UP); in hci_dev_do_open()
1486 hci_leds_update_powered(hdev, true); in hci_dev_do_open()
1487 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_dev_do_open()
1488 !hci_dev_test_flag(hdev, HCI_CONFIG) && in hci_dev_do_open()
1489 !hci_dev_test_flag(hdev, HCI_UNCONFIGURED) && in hci_dev_do_open()
1490 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_do_open()
1491 hci_dev_test_flag(hdev, HCI_MGMT) && in hci_dev_do_open()
1492 hdev->dev_type == HCI_PRIMARY) { in hci_dev_do_open()
1493 ret = __hci_req_hci_power_on(hdev); in hci_dev_do_open()
1494 mgmt_power_on(hdev, ret); in hci_dev_do_open()
1498 flush_work(&hdev->tx_work); in hci_dev_do_open()
1499 flush_work(&hdev->cmd_work); in hci_dev_do_open()
1500 flush_work(&hdev->rx_work); in hci_dev_do_open()
1502 skb_queue_purge(&hdev->cmd_q); in hci_dev_do_open()
1503 skb_queue_purge(&hdev->rx_q); in hci_dev_do_open()
1505 if (hdev->flush) in hci_dev_do_open()
1506 hdev->flush(hdev); in hci_dev_do_open()
1508 if (hdev->sent_cmd) { in hci_dev_do_open()
1509 kfree_skb(hdev->sent_cmd); in hci_dev_do_open()
1510 hdev->sent_cmd = NULL; in hci_dev_do_open()
1513 clear_bit(HCI_RUNNING, &hdev->flags); in hci_dev_do_open()
1514 hci_sock_dev_event(hdev, HCI_DEV_CLOSE); in hci_dev_do_open()
1516 hdev->close(hdev); in hci_dev_do_open()
1517 hdev->flags &= BIT(HCI_RAW); in hci_dev_do_open()
1521 hci_req_sync_unlock(hdev); in hci_dev_do_open()
1529 struct hci_dev *hdev; in hci_dev_open() local
1532 hdev = hci_dev_get(dev); in hci_dev_open()
1533 if (!hdev) in hci_dev_open()
1545 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED) && in hci_dev_open()
1546 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_open()
1556 if (hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF)) in hci_dev_open()
1557 cancel_delayed_work(&hdev->power_off); in hci_dev_open()
1563 flush_workqueue(hdev->req_workqueue); in hci_dev_open()
1571 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_open()
1572 !hci_dev_test_flag(hdev, HCI_MGMT)) in hci_dev_open()
1573 hci_dev_set_flag(hdev, HCI_BONDABLE); in hci_dev_open()
1575 err = hci_dev_do_open(hdev); in hci_dev_open()
1578 hci_dev_put(hdev); in hci_dev_open()
1583 static void hci_pend_le_actions_clear(struct hci_dev *hdev) in hci_pend_le_actions_clear() argument
1587 list_for_each_entry(p, &hdev->le_conn_params, list) { in hci_pend_le_actions_clear()
1599 int hci_dev_do_close(struct hci_dev *hdev) in hci_dev_do_close() argument
1603 BT_DBG("%s %p", hdev->name, hdev); in hci_dev_do_close()
1605 if (!hci_dev_test_flag(hdev, HCI_UNREGISTER) && in hci_dev_do_close()
1606 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_do_close()
1607 test_bit(HCI_UP, &hdev->flags)) { in hci_dev_do_close()
1609 if (hdev->shutdown) in hci_dev_do_close()
1610 hdev->shutdown(hdev); in hci_dev_do_close()
1613 cancel_delayed_work(&hdev->power_off); in hci_dev_do_close()
1615 hci_request_cancel_all(hdev); in hci_dev_do_close()
1616 hci_req_sync_lock(hdev); in hci_dev_do_close()
1618 if (!test_and_clear_bit(HCI_UP, &hdev->flags)) { in hci_dev_do_close()
1619 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_dev_do_close()
1620 hci_req_sync_unlock(hdev); in hci_dev_do_close()
1624 hci_leds_update_powered(hdev, false); in hci_dev_do_close()
1627 flush_work(&hdev->tx_work); in hci_dev_do_close()
1628 flush_work(&hdev->rx_work); in hci_dev_do_close()
1630 if (hdev->discov_timeout > 0) { in hci_dev_do_close()
1631 hdev->discov_timeout = 0; in hci_dev_do_close()
1632 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in hci_dev_do_close()
1633 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in hci_dev_do_close()
1636 if (hci_dev_test_and_clear_flag(hdev, HCI_SERVICE_CACHE)) in hci_dev_do_close()
1637 cancel_delayed_work(&hdev->service_cache); in hci_dev_do_close()
1639 if (hci_dev_test_flag(hdev, HCI_MGMT)) { in hci_dev_do_close()
1642 cancel_delayed_work_sync(&hdev->rpa_expired); in hci_dev_do_close()
1644 list_for_each_entry(adv_instance, &hdev->adv_instances, list) in hci_dev_do_close()
1651 drain_workqueue(hdev->workqueue); in hci_dev_do_close()
1653 hci_dev_lock(hdev); in hci_dev_do_close()
1655 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in hci_dev_do_close()
1657 auto_off = hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF); in hci_dev_do_close()
1659 if (!auto_off && hdev->dev_type == HCI_PRIMARY && in hci_dev_do_close()
1660 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_do_close()
1661 hci_dev_test_flag(hdev, HCI_MGMT)) in hci_dev_do_close()
1662 __mgmt_power_off(hdev); in hci_dev_do_close()
1664 hci_inquiry_cache_flush(hdev); in hci_dev_do_close()
1665 hci_pend_le_actions_clear(hdev); in hci_dev_do_close()
1666 hci_conn_hash_flush(hdev); in hci_dev_do_close()
1667 hci_dev_unlock(hdev); in hci_dev_do_close()
1669 smp_unregister(hdev); in hci_dev_do_close()
1671 hci_sock_dev_event(hdev, HCI_DEV_DOWN); in hci_dev_do_close()
1673 if (hdev->flush) in hci_dev_do_close()
1674 hdev->flush(hdev); in hci_dev_do_close()
1677 skb_queue_purge(&hdev->cmd_q); in hci_dev_do_close()
1678 atomic_set(&hdev->cmd_cnt, 1); in hci_dev_do_close()
1679 if (test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks) && in hci_dev_do_close()
1680 !auto_off && !hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_dev_do_close()
1681 set_bit(HCI_INIT, &hdev->flags); in hci_dev_do_close()
1682 __hci_req_sync(hdev, hci_reset_req, 0, HCI_CMD_TIMEOUT, NULL); in hci_dev_do_close()
1683 clear_bit(HCI_INIT, &hdev->flags); in hci_dev_do_close()
1687 flush_work(&hdev->cmd_work); in hci_dev_do_close()
1690 skb_queue_purge(&hdev->rx_q); in hci_dev_do_close()
1691 skb_queue_purge(&hdev->cmd_q); in hci_dev_do_close()
1692 skb_queue_purge(&hdev->raw_q); in hci_dev_do_close()
1695 if (hdev->sent_cmd) { in hci_dev_do_close()
1696 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_dev_do_close()
1697 kfree_skb(hdev->sent_cmd); in hci_dev_do_close()
1698 hdev->sent_cmd = NULL; in hci_dev_do_close()
1701 clear_bit(HCI_RUNNING, &hdev->flags); in hci_dev_do_close()
1702 hci_sock_dev_event(hdev, HCI_DEV_CLOSE); in hci_dev_do_close()
1706 hdev->close(hdev); in hci_dev_do_close()
1709 hdev->flags &= BIT(HCI_RAW); in hci_dev_do_close()
1710 hci_dev_clear_volatile_flags(hdev); in hci_dev_do_close()
1713 hdev->amp_status = AMP_STATUS_POWERED_DOWN; in hci_dev_do_close()
1715 memset(hdev->eir, 0, sizeof(hdev->eir)); in hci_dev_do_close()
1716 memset(hdev->dev_class, 0, sizeof(hdev->dev_class)); in hci_dev_do_close()
1717 bacpy(&hdev->random_addr, BDADDR_ANY); in hci_dev_do_close()
1719 hci_req_sync_unlock(hdev); in hci_dev_do_close()
1721 hci_dev_put(hdev); in hci_dev_do_close()
1727 struct hci_dev *hdev; in hci_dev_close() local
1730 hdev = hci_dev_get(dev); in hci_dev_close()
1731 if (!hdev) in hci_dev_close()
1734 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_close()
1739 if (hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF)) in hci_dev_close()
1740 cancel_delayed_work(&hdev->power_off); in hci_dev_close()
1742 err = hci_dev_do_close(hdev); in hci_dev_close()
1745 hci_dev_put(hdev); in hci_dev_close()
1749 static int hci_dev_do_reset(struct hci_dev *hdev) in hci_dev_do_reset() argument
1753 BT_DBG("%s %p", hdev->name, hdev); in hci_dev_do_reset()
1755 hci_req_sync_lock(hdev); in hci_dev_do_reset()
1758 skb_queue_purge(&hdev->rx_q); in hci_dev_do_reset()
1759 skb_queue_purge(&hdev->cmd_q); in hci_dev_do_reset()
1764 drain_workqueue(hdev->workqueue); in hci_dev_do_reset()
1766 hci_dev_lock(hdev); in hci_dev_do_reset()
1767 hci_inquiry_cache_flush(hdev); in hci_dev_do_reset()
1768 hci_conn_hash_flush(hdev); in hci_dev_do_reset()
1769 hci_dev_unlock(hdev); in hci_dev_do_reset()
1771 if (hdev->flush) in hci_dev_do_reset()
1772 hdev->flush(hdev); in hci_dev_do_reset()
1774 atomic_set(&hdev->cmd_cnt, 1); in hci_dev_do_reset()
1775 hdev->acl_cnt = 0; hdev->sco_cnt = 0; hdev->le_cnt = 0; in hci_dev_do_reset()
1777 ret = __hci_req_sync(hdev, hci_reset_req, 0, HCI_INIT_TIMEOUT, NULL); in hci_dev_do_reset()
1779 hci_req_sync_unlock(hdev); in hci_dev_do_reset()
1785 struct hci_dev *hdev; in hci_dev_reset() local
1788 hdev = hci_dev_get(dev); in hci_dev_reset()
1789 if (!hdev) in hci_dev_reset()
1792 if (!test_bit(HCI_UP, &hdev->flags)) { in hci_dev_reset()
1797 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_reset()
1802 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_dev_reset()
1807 err = hci_dev_do_reset(hdev); in hci_dev_reset()
1810 hci_dev_put(hdev); in hci_dev_reset()
1816 struct hci_dev *hdev; in hci_dev_reset_stat() local
1819 hdev = hci_dev_get(dev); in hci_dev_reset_stat()
1820 if (!hdev) in hci_dev_reset_stat()
1823 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_reset_stat()
1828 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_dev_reset_stat()
1833 memset(&hdev->stat, 0, sizeof(struct hci_dev_stats)); in hci_dev_reset_stat()
1836 hci_dev_put(hdev); in hci_dev_reset_stat()
1840 static void hci_update_scan_state(struct hci_dev *hdev, u8 scan) in hci_update_scan_state() argument
1844 BT_DBG("%s scan 0x%02x", hdev->name, scan); in hci_update_scan_state()
1847 conn_changed = !hci_dev_test_and_set_flag(hdev, in hci_update_scan_state()
1850 conn_changed = hci_dev_test_and_clear_flag(hdev, in hci_update_scan_state()
1854 discov_changed = !hci_dev_test_and_set_flag(hdev, in hci_update_scan_state()
1857 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in hci_update_scan_state()
1858 discov_changed = hci_dev_test_and_clear_flag(hdev, in hci_update_scan_state()
1862 if (!hci_dev_test_flag(hdev, HCI_MGMT)) in hci_update_scan_state()
1867 hci_dev_set_flag(hdev, HCI_BREDR_ENABLED); in hci_update_scan_state()
1869 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in hci_update_scan_state()
1870 hci_req_update_adv_data(hdev, hdev->cur_adv_instance); in hci_update_scan_state()
1872 mgmt_new_settings(hdev); in hci_update_scan_state()
1878 struct hci_dev *hdev; in hci_dev_cmd() local
1885 hdev = hci_dev_get(dr.dev_id); in hci_dev_cmd()
1886 if (!hdev) in hci_dev_cmd()
1889 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_cmd()
1894 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_dev_cmd()
1899 if (hdev->dev_type != HCI_PRIMARY) { in hci_dev_cmd()
1904 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in hci_dev_cmd()
1911 err = hci_req_sync(hdev, hci_auth_req, dr.dev_opt, in hci_dev_cmd()
1916 if (!lmp_encrypt_capable(hdev)) { in hci_dev_cmd()
1921 if (!test_bit(HCI_AUTH, &hdev->flags)) { in hci_dev_cmd()
1923 err = hci_req_sync(hdev, hci_auth_req, dr.dev_opt, in hci_dev_cmd()
1929 err = hci_req_sync(hdev, hci_encrypt_req, dr.dev_opt, in hci_dev_cmd()
1934 err = hci_req_sync(hdev, hci_scan_req, dr.dev_opt, in hci_dev_cmd()
1941 hci_update_scan_state(hdev, dr.dev_opt); in hci_dev_cmd()
1945 err = hci_req_sync(hdev, hci_linkpol_req, dr.dev_opt, in hci_dev_cmd()
1950 hdev->link_mode = ((__u16) dr.dev_opt) & in hci_dev_cmd()
1955 if (hdev->pkt_type == (__u16) dr.dev_opt) in hci_dev_cmd()
1958 hdev->pkt_type = (__u16) dr.dev_opt; in hci_dev_cmd()
1959 mgmt_phy_configuration_changed(hdev, NULL); in hci_dev_cmd()
1963 hdev->acl_mtu = *((__u16 *) &dr.dev_opt + 1); in hci_dev_cmd()
1964 hdev->acl_pkts = *((__u16 *) &dr.dev_opt + 0); in hci_dev_cmd()
1968 hdev->sco_mtu = *((__u16 *) &dr.dev_opt + 1); in hci_dev_cmd()
1969 hdev->sco_pkts = *((__u16 *) &dr.dev_opt + 0); in hci_dev_cmd()
1978 hci_dev_put(hdev); in hci_dev_cmd()
1984 struct hci_dev *hdev; in hci_get_dev_list() local
2005 list_for_each_entry(hdev, &hci_dev_list, list) { in hci_get_dev_list()
2006 unsigned long flags = hdev->flags; in hci_get_dev_list()
2012 if (hci_dev_test_flag(hdev, HCI_AUTO_OFF)) in hci_get_dev_list()
2015 (dr + n)->dev_id = hdev->id; in hci_get_dev_list()
2034 struct hci_dev *hdev; in hci_get_dev_info() local
2042 hdev = hci_dev_get(di.dev_id); in hci_get_dev_info()
2043 if (!hdev) in hci_get_dev_info()
2050 if (hci_dev_test_flag(hdev, HCI_AUTO_OFF)) in hci_get_dev_info()
2051 flags = hdev->flags & ~BIT(HCI_UP); in hci_get_dev_info()
2053 flags = hdev->flags; in hci_get_dev_info()
2055 strcpy(di.name, hdev->name); in hci_get_dev_info()
2056 di.bdaddr = hdev->bdaddr; in hci_get_dev_info()
2057 di.type = (hdev->bus & 0x0f) | ((hdev->dev_type & 0x03) << 4); in hci_get_dev_info()
2059 di.pkt_type = hdev->pkt_type; in hci_get_dev_info()
2060 if (lmp_bredr_capable(hdev)) { in hci_get_dev_info()
2061 di.acl_mtu = hdev->acl_mtu; in hci_get_dev_info()
2062 di.acl_pkts = hdev->acl_pkts; in hci_get_dev_info()
2063 di.sco_mtu = hdev->sco_mtu; in hci_get_dev_info()
2064 di.sco_pkts = hdev->sco_pkts; in hci_get_dev_info()
2066 di.acl_mtu = hdev->le_mtu; in hci_get_dev_info()
2067 di.acl_pkts = hdev->le_pkts; in hci_get_dev_info()
2071 di.link_policy = hdev->link_policy; in hci_get_dev_info()
2072 di.link_mode = hdev->link_mode; in hci_get_dev_info()
2074 memcpy(&di.stat, &hdev->stat, sizeof(di.stat)); in hci_get_dev_info()
2075 memcpy(&di.features, &hdev->features, sizeof(di.features)); in hci_get_dev_info()
2080 hci_dev_put(hdev); in hci_get_dev_info()
2089 struct hci_dev *hdev = data; in hci_rfkill_set_block() local
2091 BT_DBG("%p name %s blocked %d", hdev, hdev->name, blocked); in hci_rfkill_set_block()
2093 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) in hci_rfkill_set_block()
2097 hci_dev_set_flag(hdev, HCI_RFKILLED); in hci_rfkill_set_block()
2098 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_rfkill_set_block()
2099 !hci_dev_test_flag(hdev, HCI_CONFIG)) in hci_rfkill_set_block()
2100 hci_dev_do_close(hdev); in hci_rfkill_set_block()
2102 hci_dev_clear_flag(hdev, HCI_RFKILLED); in hci_rfkill_set_block()
2114 struct hci_dev *hdev = container_of(work, struct hci_dev, power_on); in hci_power_on() local
2117 BT_DBG("%s", hdev->name); in hci_power_on()
2119 if (test_bit(HCI_UP, &hdev->flags) && in hci_power_on()
2120 hci_dev_test_flag(hdev, HCI_MGMT) && in hci_power_on()
2121 hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF)) { in hci_power_on()
2122 cancel_delayed_work(&hdev->power_off); in hci_power_on()
2123 hci_req_sync_lock(hdev); in hci_power_on()
2124 err = __hci_req_hci_power_on(hdev); in hci_power_on()
2125 hci_req_sync_unlock(hdev); in hci_power_on()
2126 mgmt_power_on(hdev, err); in hci_power_on()
2130 err = hci_dev_do_open(hdev); in hci_power_on()
2132 hci_dev_lock(hdev); in hci_power_on()
2133 mgmt_set_powered_failed(hdev, err); in hci_power_on()
2134 hci_dev_unlock(hdev); in hci_power_on()
2142 if (hci_dev_test_flag(hdev, HCI_RFKILLED) || in hci_power_on()
2143 hci_dev_test_flag(hdev, HCI_UNCONFIGURED) || in hci_power_on()
2144 (hdev->dev_type == HCI_PRIMARY && in hci_power_on()
2145 !bacmp(&hdev->bdaddr, BDADDR_ANY) && in hci_power_on()
2146 !bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_power_on()
2147 hci_dev_clear_flag(hdev, HCI_AUTO_OFF); in hci_power_on()
2148 hci_dev_do_close(hdev); in hci_power_on()
2149 } else if (hci_dev_test_flag(hdev, HCI_AUTO_OFF)) { in hci_power_on()
2150 queue_delayed_work(hdev->req_workqueue, &hdev->power_off, in hci_power_on()
2154 if (hci_dev_test_and_clear_flag(hdev, HCI_SETUP)) { in hci_power_on()
2158 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in hci_power_on()
2159 set_bit(HCI_RAW, &hdev->flags); in hci_power_on()
2168 mgmt_index_added(hdev); in hci_power_on()
2169 } else if (hci_dev_test_and_clear_flag(hdev, HCI_CONFIG)) { in hci_power_on()
2173 if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in hci_power_on()
2174 clear_bit(HCI_RAW, &hdev->flags); in hci_power_on()
2180 mgmt_index_added(hdev); in hci_power_on()
2186 struct hci_dev *hdev = container_of(work, struct hci_dev, in hci_power_off() local
2189 BT_DBG("%s", hdev->name); in hci_power_off()
2191 hci_dev_do_close(hdev); in hci_power_off()
2196 struct hci_dev *hdev = container_of(work, struct hci_dev, error_reset); in hci_error_reset() local
2198 BT_DBG("%s", hdev->name); in hci_error_reset()
2200 if (hdev->hw_error) in hci_error_reset()
2201 hdev->hw_error(hdev, hdev->hw_error_code); in hci_error_reset()
2203 bt_dev_err(hdev, "hardware error 0x%2.2x", hdev->hw_error_code); in hci_error_reset()
2205 if (hci_dev_do_close(hdev)) in hci_error_reset()
2208 hci_dev_do_open(hdev); in hci_error_reset()
2211 void hci_uuids_clear(struct hci_dev *hdev) in hci_uuids_clear() argument
2215 list_for_each_entry_safe(uuid, tmp, &hdev->uuids, list) { in hci_uuids_clear()
2221 void hci_link_keys_clear(struct hci_dev *hdev) in hci_link_keys_clear() argument
2225 list_for_each_entry_rcu(key, &hdev->link_keys, list) { in hci_link_keys_clear()
2231 void hci_smp_ltks_clear(struct hci_dev *hdev) in hci_smp_ltks_clear() argument
2235 list_for_each_entry_rcu(k, &hdev->long_term_keys, list) { in hci_smp_ltks_clear()
2241 void hci_smp_irks_clear(struct hci_dev *hdev) in hci_smp_irks_clear() argument
2245 list_for_each_entry_rcu(k, &hdev->identity_resolving_keys, list) { in hci_smp_irks_clear()
2251 struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr) in hci_find_link_key() argument
2256 list_for_each_entry_rcu(k, &hdev->link_keys, list) { in hci_find_link_key()
2267 static bool hci_persistent_key(struct hci_dev *hdev, struct hci_conn *conn, in hci_persistent_key() argument
2315 struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_find_ltk() argument
2321 list_for_each_entry_rcu(k, &hdev->long_term_keys, list) { in hci_find_ltk()
2335 struct smp_irk *hci_find_irk_by_rpa(struct hci_dev *hdev, bdaddr_t *rpa) in hci_find_irk_by_rpa() argument
2340 list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) { in hci_find_irk_by_rpa()
2347 list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) { in hci_find_irk_by_rpa()
2348 if (smp_irk_matches(hdev, irk->val, rpa)) { in hci_find_irk_by_rpa()
2359 struct smp_irk *hci_find_irk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_find_irk_by_addr() argument
2369 list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) { in hci_find_irk_by_addr()
2381 struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, in hci_add_link_key() argument
2388 old_key = hci_find_link_key(hdev, bdaddr); in hci_add_link_key()
2397 list_add_rcu(&key->list, &hdev->link_keys); in hci_add_link_key()
2400 BT_DBG("%s key for %pMR type %u", hdev->name, bdaddr, type); in hci_add_link_key()
2422 *persistent = hci_persistent_key(hdev, conn, type, in hci_add_link_key()
2428 struct smp_ltk *hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_add_ltk() argument
2435 old_key = hci_find_ltk(hdev, bdaddr, addr_type, role); in hci_add_ltk()
2442 list_add_rcu(&key->list, &hdev->long_term_keys); in hci_add_ltk()
2457 struct smp_irk *hci_add_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_add_irk() argument
2462 irk = hci_find_irk_by_addr(hdev, bdaddr, addr_type); in hci_add_irk()
2471 list_add_rcu(&irk->list, &hdev->identity_resolving_keys); in hci_add_irk()
2480 int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr) in hci_remove_link_key() argument
2484 key = hci_find_link_key(hdev, bdaddr); in hci_remove_link_key()
2488 BT_DBG("%s removing %pMR", hdev->name, bdaddr); in hci_remove_link_key()
2496 int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 bdaddr_type) in hci_remove_ltk() argument
2501 list_for_each_entry_rcu(k, &hdev->long_term_keys, list) { in hci_remove_ltk()
2505 BT_DBG("%s removing %pMR", hdev->name, bdaddr); in hci_remove_ltk()
2515 void hci_remove_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type) in hci_remove_irk() argument
2519 list_for_each_entry_rcu(k, &hdev->identity_resolving_keys, list) { in hci_remove_irk()
2523 BT_DBG("%s removing %pMR", hdev->name, bdaddr); in hci_remove_irk()
2530 bool hci_bdaddr_is_paired(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type) in hci_bdaddr_is_paired() argument
2537 if (hci_find_link_key(hdev, bdaddr)) in hci_bdaddr_is_paired()
2548 irk = hci_get_irk(hdev, bdaddr, addr_type); in hci_bdaddr_is_paired()
2555 list_for_each_entry_rcu(k, &hdev->long_term_keys, list) { in hci_bdaddr_is_paired()
2569 struct hci_dev *hdev = container_of(work, struct hci_dev, in hci_cmd_timeout() local
2572 if (hdev->sent_cmd) { in hci_cmd_timeout()
2573 struct hci_command_hdr *sent = (void *) hdev->sent_cmd->data; in hci_cmd_timeout()
2576 bt_dev_err(hdev, "command 0x%4.4x tx timeout", opcode); in hci_cmd_timeout()
2578 bt_dev_err(hdev, "command tx timeout"); in hci_cmd_timeout()
2581 atomic_set(&hdev->cmd_cnt, 1); in hci_cmd_timeout()
2582 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_cmd_timeout()
2585 struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev, in hci_find_remote_oob_data() argument
2590 list_for_each_entry(data, &hdev->remote_oob_data, list) { in hci_find_remote_oob_data()
2601 int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_remove_remote_oob_data() argument
2606 data = hci_find_remote_oob_data(hdev, bdaddr, bdaddr_type); in hci_remove_remote_oob_data()
2610 BT_DBG("%s removing %pMR (%u)", hdev->name, bdaddr, bdaddr_type); in hci_remove_remote_oob_data()
2618 void hci_remote_oob_data_clear(struct hci_dev *hdev) in hci_remote_oob_data_clear() argument
2622 list_for_each_entry_safe(data, n, &hdev->remote_oob_data, list) { in hci_remote_oob_data_clear()
2628 int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_add_remote_oob_data() argument
2634 data = hci_find_remote_oob_data(hdev, bdaddr, bdaddr_type); in hci_add_remote_oob_data()
2642 list_add(&data->list, &hdev->remote_oob_data); in hci_add_remote_oob_data()
2669 BT_DBG("%s for %pMR", hdev->name, bdaddr); in hci_add_remote_oob_data()
2675 struct adv_info *hci_find_adv_instance(struct hci_dev *hdev, u8 instance) in hci_find_adv_instance() argument
2679 list_for_each_entry(adv_instance, &hdev->adv_instances, list) { in hci_find_adv_instance()
2688 struct adv_info *hci_get_next_instance(struct hci_dev *hdev, u8 instance) in hci_get_next_instance() argument
2692 cur_instance = hci_find_adv_instance(hdev, instance); in hci_get_next_instance()
2696 if (cur_instance == list_last_entry(&hdev->adv_instances, in hci_get_next_instance()
2698 return list_first_entry(&hdev->adv_instances, in hci_get_next_instance()
2705 int hci_remove_adv_instance(struct hci_dev *hdev, u8 instance) in hci_remove_adv_instance() argument
2709 adv_instance = hci_find_adv_instance(hdev, instance); in hci_remove_adv_instance()
2713 BT_DBG("%s removing %dMR", hdev->name, instance); in hci_remove_adv_instance()
2715 if (hdev->cur_adv_instance == instance) { in hci_remove_adv_instance()
2716 if (hdev->adv_instance_timeout) { in hci_remove_adv_instance()
2717 cancel_delayed_work(&hdev->adv_instance_expire); in hci_remove_adv_instance()
2718 hdev->adv_instance_timeout = 0; in hci_remove_adv_instance()
2720 hdev->cur_adv_instance = 0x00; in hci_remove_adv_instance()
2728 hdev->adv_instance_cnt--; in hci_remove_adv_instance()
2733 void hci_adv_instances_set_rpa_expired(struct hci_dev *hdev, bool rpa_expired) in hci_adv_instances_set_rpa_expired() argument
2737 list_for_each_entry_safe(adv_instance, n, &hdev->adv_instances, list) in hci_adv_instances_set_rpa_expired()
2742 void hci_adv_instances_clear(struct hci_dev *hdev) in hci_adv_instances_clear() argument
2746 if (hdev->adv_instance_timeout) { in hci_adv_instances_clear()
2747 cancel_delayed_work(&hdev->adv_instance_expire); in hci_adv_instances_clear()
2748 hdev->adv_instance_timeout = 0; in hci_adv_instances_clear()
2751 list_for_each_entry_safe(adv_instance, n, &hdev->adv_instances, list) { in hci_adv_instances_clear()
2757 hdev->adv_instance_cnt = 0; in hci_adv_instances_clear()
2758 hdev->cur_adv_instance = 0x00; in hci_adv_instances_clear()
2772 int hci_add_adv_instance(struct hci_dev *hdev, u8 instance, u32 flags, in hci_add_adv_instance() argument
2779 adv_instance = hci_find_adv_instance(hdev, instance); in hci_add_adv_instance()
2786 if (hdev->adv_instance_cnt >= HCI_MAX_ADV_INSTANCES || in hci_add_adv_instance()
2796 list_add(&adv_instance->list, &hdev->adv_instances); in hci_add_adv_instance()
2797 hdev->adv_instance_cnt++; in hci_add_adv_instance()
2824 BT_DBG("%s for %dMR", hdev->name, instance); in hci_add_adv_instance()
2894 struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev, in hci_conn_params_lookup() argument
2899 list_for_each_entry(params, &hdev->le_conn_params, list) { in hci_conn_params_lookup()
2925 struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev, in hci_conn_params_add() argument
2930 params = hci_conn_params_lookup(hdev, addr, addr_type); in hci_conn_params_add()
2936 bt_dev_err(hdev, "out of memory"); in hci_conn_params_add()
2943 list_add(¶ms->list, &hdev->le_conn_params); in hci_conn_params_add()
2946 params->conn_min_interval = hdev->le_conn_min_interval; in hci_conn_params_add()
2947 params->conn_max_interval = hdev->le_conn_max_interval; in hci_conn_params_add()
2948 params->conn_latency = hdev->le_conn_latency; in hci_conn_params_add()
2949 params->supervision_timeout = hdev->le_supv_timeout; in hci_conn_params_add()
2970 void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type) in hci_conn_params_del() argument
2974 params = hci_conn_params_lookup(hdev, addr, addr_type); in hci_conn_params_del()
2980 hci_update_background_scan(hdev); in hci_conn_params_del()
2986 void hci_conn_params_clear_disabled(struct hci_dev *hdev) in hci_conn_params_clear_disabled() argument
2990 list_for_each_entry_safe(params, tmp, &hdev->le_conn_params, list) { in hci_conn_params_clear_disabled()
3010 static void hci_conn_params_clear_all(struct hci_dev *hdev) in hci_conn_params_clear_all() argument
3014 list_for_each_entry_safe(params, tmp, &hdev->le_conn_params, list) in hci_conn_params_clear_all()
3033 void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_copy_identity_address() argument
3036 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in hci_copy_identity_address()
3037 !bacmp(&hdev->bdaddr, BDADDR_ANY) || in hci_copy_identity_address()
3038 (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in hci_copy_identity_address()
3039 bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_copy_identity_address()
3040 bacpy(bdaddr, &hdev->static_addr); in hci_copy_identity_address()
3043 bacpy(bdaddr, &hdev->bdaddr); in hci_copy_identity_address()
3051 struct hci_dev *hdev; in hci_alloc_dev() local
3053 hdev = kzalloc(sizeof(*hdev), GFP_KERNEL); in hci_alloc_dev()
3054 if (!hdev) in hci_alloc_dev()
3057 hdev->pkt_type = (HCI_DM1 | HCI_DH1 | HCI_HV1); in hci_alloc_dev()
3058 hdev->esco_type = (ESCO_HV1); in hci_alloc_dev()
3059 hdev->link_mode = (HCI_LM_ACCEPT); in hci_alloc_dev()
3060 hdev->num_iac = 0x01; /* One IAC support is mandatory */ in hci_alloc_dev()
3061 hdev->io_capability = 0x03; /* No Input No Output */ in hci_alloc_dev()
3062 hdev->manufacturer = 0xffff; /* Default to internal use */ in hci_alloc_dev()
3063 hdev->inq_tx_power = HCI_TX_POWER_INVALID; in hci_alloc_dev()
3064 hdev->adv_tx_power = HCI_TX_POWER_INVALID; in hci_alloc_dev()
3065 hdev->adv_instance_cnt = 0; in hci_alloc_dev()
3066 hdev->cur_adv_instance = 0x00; in hci_alloc_dev()
3067 hdev->adv_instance_timeout = 0; in hci_alloc_dev()
3069 hdev->sniff_max_interval = 800; in hci_alloc_dev()
3070 hdev->sniff_min_interval = 80; in hci_alloc_dev()
3072 hdev->le_adv_channel_map = 0x07; in hci_alloc_dev()
3073 hdev->le_adv_min_interval = 0x0800; in hci_alloc_dev()
3074 hdev->le_adv_max_interval = 0x0800; in hci_alloc_dev()
3075 hdev->le_scan_interval = 0x0060; in hci_alloc_dev()
3076 hdev->le_scan_window = 0x0030; in hci_alloc_dev()
3077 hdev->le_conn_min_interval = 0x0018; in hci_alloc_dev()
3078 hdev->le_conn_max_interval = 0x0028; in hci_alloc_dev()
3079 hdev->le_conn_latency = 0x0000; in hci_alloc_dev()
3080 hdev->le_supv_timeout = 0x002a; in hci_alloc_dev()
3081 hdev->le_def_tx_len = 0x001b; in hci_alloc_dev()
3082 hdev->le_def_tx_time = 0x0148; in hci_alloc_dev()
3083 hdev->le_max_tx_len = 0x001b; in hci_alloc_dev()
3084 hdev->le_max_tx_time = 0x0148; in hci_alloc_dev()
3085 hdev->le_max_rx_len = 0x001b; in hci_alloc_dev()
3086 hdev->le_max_rx_time = 0x0148; in hci_alloc_dev()
3087 hdev->le_tx_def_phys = HCI_LE_SET_PHY_1M; in hci_alloc_dev()
3088 hdev->le_rx_def_phys = HCI_LE_SET_PHY_1M; in hci_alloc_dev()
3090 hdev->rpa_timeout = HCI_DEFAULT_RPA_TIMEOUT; in hci_alloc_dev()
3091 hdev->discov_interleaved_timeout = DISCOV_INTERLEAVED_TIMEOUT; in hci_alloc_dev()
3092 hdev->conn_info_min_age = DEFAULT_CONN_INFO_MIN_AGE; in hci_alloc_dev()
3093 hdev->conn_info_max_age = DEFAULT_CONN_INFO_MAX_AGE; in hci_alloc_dev()
3095 mutex_init(&hdev->lock); in hci_alloc_dev()
3096 mutex_init(&hdev->req_lock); in hci_alloc_dev()
3098 INIT_LIST_HEAD(&hdev->mgmt_pending); in hci_alloc_dev()
3099 INIT_LIST_HEAD(&hdev->blacklist); in hci_alloc_dev()
3100 INIT_LIST_HEAD(&hdev->whitelist); in hci_alloc_dev()
3101 INIT_LIST_HEAD(&hdev->uuids); in hci_alloc_dev()
3102 INIT_LIST_HEAD(&hdev->link_keys); in hci_alloc_dev()
3103 INIT_LIST_HEAD(&hdev->long_term_keys); in hci_alloc_dev()
3104 INIT_LIST_HEAD(&hdev->identity_resolving_keys); in hci_alloc_dev()
3105 INIT_LIST_HEAD(&hdev->remote_oob_data); in hci_alloc_dev()
3106 INIT_LIST_HEAD(&hdev->le_white_list); in hci_alloc_dev()
3107 INIT_LIST_HEAD(&hdev->le_resolv_list); in hci_alloc_dev()
3108 INIT_LIST_HEAD(&hdev->le_conn_params); in hci_alloc_dev()
3109 INIT_LIST_HEAD(&hdev->pend_le_conns); in hci_alloc_dev()
3110 INIT_LIST_HEAD(&hdev->pend_le_reports); in hci_alloc_dev()
3111 INIT_LIST_HEAD(&hdev->conn_hash.list); in hci_alloc_dev()
3112 INIT_LIST_HEAD(&hdev->adv_instances); in hci_alloc_dev()
3114 INIT_WORK(&hdev->rx_work, hci_rx_work); in hci_alloc_dev()
3115 INIT_WORK(&hdev->cmd_work, hci_cmd_work); in hci_alloc_dev()
3116 INIT_WORK(&hdev->tx_work, hci_tx_work); in hci_alloc_dev()
3117 INIT_WORK(&hdev->power_on, hci_power_on); in hci_alloc_dev()
3118 INIT_WORK(&hdev->error_reset, hci_error_reset); in hci_alloc_dev()
3120 INIT_DELAYED_WORK(&hdev->power_off, hci_power_off); in hci_alloc_dev()
3122 skb_queue_head_init(&hdev->rx_q); in hci_alloc_dev()
3123 skb_queue_head_init(&hdev->cmd_q); in hci_alloc_dev()
3124 skb_queue_head_init(&hdev->raw_q); in hci_alloc_dev()
3126 init_waitqueue_head(&hdev->req_wait_q); in hci_alloc_dev()
3128 INIT_DELAYED_WORK(&hdev->cmd_timer, hci_cmd_timeout); in hci_alloc_dev()
3130 hci_request_setup(hdev); in hci_alloc_dev()
3132 hci_init_sysfs(hdev); in hci_alloc_dev()
3133 discovery_init(hdev); in hci_alloc_dev()
3135 return hdev; in hci_alloc_dev()
3140 void hci_free_dev(struct hci_dev *hdev) in hci_free_dev() argument
3143 put_device(&hdev->dev); in hci_free_dev()
3148 int hci_register_dev(struct hci_dev *hdev) in hci_register_dev() argument
3152 if (!hdev->open || !hdev->close || !hdev->send) in hci_register_dev()
3158 switch (hdev->dev_type) { in hci_register_dev()
3172 sprintf(hdev->name, "hci%d", id); in hci_register_dev()
3173 hdev->id = id; in hci_register_dev()
3175 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus); in hci_register_dev()
3177 hdev->workqueue = alloc_ordered_workqueue("%s", WQ_HIGHPRI, hdev->name); in hci_register_dev()
3178 if (!hdev->workqueue) { in hci_register_dev()
3183 hdev->req_workqueue = alloc_ordered_workqueue("%s", WQ_HIGHPRI, in hci_register_dev()
3184 hdev->name); in hci_register_dev()
3185 if (!hdev->req_workqueue) { in hci_register_dev()
3186 destroy_workqueue(hdev->workqueue); in hci_register_dev()
3192 hdev->debugfs = debugfs_create_dir(hdev->name, bt_debugfs); in hci_register_dev()
3194 dev_set_name(&hdev->dev, "%s", hdev->name); in hci_register_dev()
3196 error = device_add(&hdev->dev); in hci_register_dev()
3200 hci_leds_init(hdev); in hci_register_dev()
3202 hdev->rfkill = rfkill_alloc(hdev->name, &hdev->dev, in hci_register_dev()
3204 hdev); in hci_register_dev()
3205 if (hdev->rfkill) { in hci_register_dev()
3206 if (rfkill_register(hdev->rfkill) < 0) { in hci_register_dev()
3207 rfkill_destroy(hdev->rfkill); in hci_register_dev()
3208 hdev->rfkill = NULL; in hci_register_dev()
3212 if (hdev->rfkill && rfkill_blocked(hdev->rfkill)) in hci_register_dev()
3213 hci_dev_set_flag(hdev, HCI_RFKILLED); in hci_register_dev()
3215 hci_dev_set_flag(hdev, HCI_SETUP); in hci_register_dev()
3216 hci_dev_set_flag(hdev, HCI_AUTO_OFF); in hci_register_dev()
3218 if (hdev->dev_type == HCI_PRIMARY) { in hci_register_dev()
3222 hci_dev_set_flag(hdev, HCI_BREDR_ENABLED); in hci_register_dev()
3226 list_add(&hdev->list, &hci_dev_list); in hci_register_dev()
3232 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in hci_register_dev()
3233 hci_dev_set_flag(hdev, HCI_UNCONFIGURED); in hci_register_dev()
3235 hci_sock_dev_event(hdev, HCI_DEV_REG); in hci_register_dev()
3236 hci_dev_hold(hdev); in hci_register_dev()
3238 queue_work(hdev->req_workqueue, &hdev->power_on); in hci_register_dev()
3243 destroy_workqueue(hdev->workqueue); in hci_register_dev()
3244 destroy_workqueue(hdev->req_workqueue); in hci_register_dev()
3246 ida_simple_remove(&hci_index_ida, hdev->id); in hci_register_dev()
3253 void hci_unregister_dev(struct hci_dev *hdev) in hci_unregister_dev() argument
3257 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus); in hci_unregister_dev()
3259 hci_dev_set_flag(hdev, HCI_UNREGISTER); in hci_unregister_dev()
3261 id = hdev->id; in hci_unregister_dev()
3264 list_del(&hdev->list); in hci_unregister_dev()
3267 cancel_work_sync(&hdev->power_on); in hci_unregister_dev()
3269 hci_dev_do_close(hdev); in hci_unregister_dev()
3271 if (!test_bit(HCI_INIT, &hdev->flags) && in hci_unregister_dev()
3272 !hci_dev_test_flag(hdev, HCI_SETUP) && in hci_unregister_dev()
3273 !hci_dev_test_flag(hdev, HCI_CONFIG)) { in hci_unregister_dev()
3274 hci_dev_lock(hdev); in hci_unregister_dev()
3275 mgmt_index_removed(hdev); in hci_unregister_dev()
3276 hci_dev_unlock(hdev); in hci_unregister_dev()
3281 BUG_ON(!list_empty(&hdev->mgmt_pending)); in hci_unregister_dev()
3283 hci_sock_dev_event(hdev, HCI_DEV_UNREG); in hci_unregister_dev()
3285 if (hdev->rfkill) { in hci_unregister_dev()
3286 rfkill_unregister(hdev->rfkill); in hci_unregister_dev()
3287 rfkill_destroy(hdev->rfkill); in hci_unregister_dev()
3290 device_del(&hdev->dev); in hci_unregister_dev()
3292 debugfs_remove_recursive(hdev->debugfs); in hci_unregister_dev()
3293 kfree_const(hdev->hw_info); in hci_unregister_dev()
3294 kfree_const(hdev->fw_info); in hci_unregister_dev()
3296 destroy_workqueue(hdev->workqueue); in hci_unregister_dev()
3297 destroy_workqueue(hdev->req_workqueue); in hci_unregister_dev()
3299 hci_dev_lock(hdev); in hci_unregister_dev()
3300 hci_bdaddr_list_clear(&hdev->blacklist); in hci_unregister_dev()
3301 hci_bdaddr_list_clear(&hdev->whitelist); in hci_unregister_dev()
3302 hci_uuids_clear(hdev); in hci_unregister_dev()
3303 hci_link_keys_clear(hdev); in hci_unregister_dev()
3304 hci_smp_ltks_clear(hdev); in hci_unregister_dev()
3305 hci_smp_irks_clear(hdev); in hci_unregister_dev()
3306 hci_remote_oob_data_clear(hdev); in hci_unregister_dev()
3307 hci_adv_instances_clear(hdev); in hci_unregister_dev()
3308 hci_bdaddr_list_clear(&hdev->le_white_list); in hci_unregister_dev()
3309 hci_bdaddr_list_clear(&hdev->le_resolv_list); in hci_unregister_dev()
3310 hci_conn_params_clear_all(hdev); in hci_unregister_dev()
3311 hci_discovery_filter_clear(hdev); in hci_unregister_dev()
3312 hci_dev_unlock(hdev); in hci_unregister_dev()
3314 hci_dev_put(hdev); in hci_unregister_dev()
3321 int hci_suspend_dev(struct hci_dev *hdev) in hci_suspend_dev() argument
3323 hci_sock_dev_event(hdev, HCI_DEV_SUSPEND); in hci_suspend_dev()
3329 int hci_resume_dev(struct hci_dev *hdev) in hci_resume_dev() argument
3331 hci_sock_dev_event(hdev, HCI_DEV_RESUME); in hci_resume_dev()
3337 int hci_reset_dev(struct hci_dev *hdev) in hci_reset_dev() argument
3350 return hci_recv_frame(hdev, skb); in hci_reset_dev()
3355 int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb) in hci_recv_frame() argument
3357 if (!hdev || (!test_bit(HCI_UP, &hdev->flags) in hci_recv_frame()
3358 && !test_bit(HCI_INIT, &hdev->flags))) { in hci_recv_frame()
3376 skb_queue_tail(&hdev->rx_q, skb); in hci_recv_frame()
3377 queue_work(hdev->workqueue, &hdev->rx_work); in hci_recv_frame()
3384 int hci_recv_diag(struct hci_dev *hdev, struct sk_buff *skb) in hci_recv_diag() argument
3392 skb_queue_tail(&hdev->rx_q, skb); in hci_recv_diag()
3393 queue_work(hdev->workqueue, &hdev->rx_work); in hci_recv_diag()
3399 void hci_set_hw_info(struct hci_dev *hdev, const char *fmt, ...) in hci_set_hw_info() argument
3404 kfree_const(hdev->hw_info); in hci_set_hw_info()
3405 hdev->hw_info = kvasprintf_const(GFP_KERNEL, fmt, vargs); in hci_set_hw_info()
3410 void hci_set_fw_info(struct hci_dev *hdev, const char *fmt, ...) in hci_set_fw_info() argument
3415 kfree_const(hdev->fw_info); in hci_set_fw_info()
3416 hdev->fw_info = kvasprintf_const(GFP_KERNEL, fmt, vargs); in hci_set_fw_info()
3447 static void hci_send_frame(struct hci_dev *hdev, struct sk_buff *skb) in hci_send_frame() argument
3451 BT_DBG("%s type %d len %d", hdev->name, hci_skb_pkt_type(skb), in hci_send_frame()
3458 hci_send_to_monitor(hdev, skb); in hci_send_frame()
3460 if (atomic_read(&hdev->promisc)) { in hci_send_frame()
3462 hci_send_to_sock(hdev, skb); in hci_send_frame()
3468 if (!test_bit(HCI_RUNNING, &hdev->flags)) { in hci_send_frame()
3473 err = hdev->send(hdev, skb); in hci_send_frame()
3475 bt_dev_err(hdev, "sending frame failed (%d)", err); in hci_send_frame()
3481 int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, in hci_send_cmd() argument
3486 BT_DBG("%s opcode 0x%4.4x plen %d", hdev->name, opcode, plen); in hci_send_cmd()
3488 skb = hci_prepare_cmd(hdev, opcode, plen, param); in hci_send_cmd()
3490 bt_dev_err(hdev, "no memory for command"); in hci_send_cmd()
3499 skb_queue_tail(&hdev->cmd_q, skb); in hci_send_cmd()
3500 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_send_cmd()
3505 int __hci_cmd_send(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_send() argument
3519 bt_dev_err(hdev, "unresponded command not supported"); in __hci_cmd_send()
3523 skb = hci_prepare_cmd(hdev, opcode, plen, param); in __hci_cmd_send()
3525 bt_dev_err(hdev, "no memory for command (opcode 0x%4.4x)", in __hci_cmd_send()
3530 hci_send_frame(hdev, skb); in __hci_cmd_send()
3537 void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode) in hci_sent_cmd_data() argument
3541 if (!hdev->sent_cmd) in hci_sent_cmd_data()
3544 hdr = (void *) hdev->sent_cmd->data; in hci_sent_cmd_data()
3549 BT_DBG("%s opcode 0x%4.4x", hdev->name, opcode); in hci_sent_cmd_data()
3551 return hdev->sent_cmd->data + HCI_COMMAND_HDR_SIZE; in hci_sent_cmd_data()
3555 struct sk_buff *hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen, in hci_cmd_sync() argument
3560 if (!test_bit(HCI_UP, &hdev->flags)) in hci_cmd_sync()
3563 bt_dev_dbg(hdev, "opcode 0x%4.4x plen %d", opcode, plen); in hci_cmd_sync()
3565 hci_req_sync_lock(hdev); in hci_cmd_sync()
3566 skb = __hci_cmd_sync(hdev, opcode, plen, param, timeout); in hci_cmd_sync()
3567 hci_req_sync_unlock(hdev); in hci_cmd_sync()
3590 struct hci_dev *hdev = conn->hdev; in hci_queue_acl() local
3598 switch (hdev->dev_type) { in hci_queue_acl()
3606 bt_dev_err(hdev, "unknown dev_type %d", hdev->dev_type); in hci_queue_acl()
3613 BT_DBG("%s nonfrag skb %p len %d", hdev->name, skb, skb->len); in hci_queue_acl()
3618 BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len); in hci_queue_acl()
3639 BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len); in hci_queue_acl()
3650 struct hci_dev *hdev = chan->conn->hdev; in hci_send_acl() local
3652 BT_DBG("%s chan %p flags 0x%4.4x", hdev->name, chan, flags); in hci_send_acl()
3656 queue_work(hdev->workqueue, &hdev->tx_work); in hci_send_acl()
3662 struct hci_dev *hdev = conn->hdev; in hci_send_sco() local
3665 BT_DBG("%s len %d", hdev->name, skb->len); in hci_send_sco()
3677 queue_work(hdev->workqueue, &hdev->tx_work); in hci_send_sco()
3683 static struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type, in hci_low_sent() argument
3686 struct hci_conn_hash *h = &hdev->conn_hash; in hci_low_sent()
3709 if (hci_conn_num(hdev, type) == num) in hci_low_sent()
3720 cnt = hdev->acl_cnt; in hci_low_sent()
3724 cnt = hdev->sco_cnt; in hci_low_sent()
3727 cnt = hdev->le_mtu ? hdev->le_cnt : hdev->acl_cnt; in hci_low_sent()
3731 bt_dev_err(hdev, "unknown link type %d", conn->type); in hci_low_sent()
3743 static void hci_link_tx_to(struct hci_dev *hdev, __u8 type) in hci_link_tx_to() argument
3745 struct hci_conn_hash *h = &hdev->conn_hash; in hci_link_tx_to()
3748 bt_dev_err(hdev, "link tx timeout"); in hci_link_tx_to()
3755 bt_dev_err(hdev, "killing stalled connection %pMR", in hci_link_tx_to()
3764 static struct hci_chan *hci_chan_sent(struct hci_dev *hdev, __u8 type, in hci_chan_sent() argument
3767 struct hci_conn_hash *h = &hdev->conn_hash; in hci_chan_sent()
3773 BT_DBG("%s", hdev->name); in hci_chan_sent()
3812 if (hci_conn_num(hdev, type) == conn_num) in hci_chan_sent()
3823 cnt = hdev->acl_cnt; in hci_chan_sent()
3826 cnt = hdev->block_cnt; in hci_chan_sent()
3830 cnt = hdev->sco_cnt; in hci_chan_sent()
3833 cnt = hdev->le_mtu ? hdev->le_cnt : hdev->acl_cnt; in hci_chan_sent()
3837 bt_dev_err(hdev, "unknown link type %d", chan->conn->type); in hci_chan_sent()
3846 static void hci_prio_recalculate(struct hci_dev *hdev, __u8 type) in hci_prio_recalculate() argument
3848 struct hci_conn_hash *h = &hdev->conn_hash; in hci_prio_recalculate()
3852 BT_DBG("%s", hdev->name); in hci_prio_recalculate()
3888 if (hci_conn_num(hdev, type) == num) in hci_prio_recalculate()
3896 static inline int __get_blocks(struct hci_dev *hdev, struct sk_buff *skb) in __get_blocks() argument
3899 return DIV_ROUND_UP(skb->len - HCI_ACL_HDR_SIZE, hdev->block_len); in __get_blocks()
3902 static void __check_timeout(struct hci_dev *hdev, unsigned int cnt) in __check_timeout() argument
3904 if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in __check_timeout()
3907 if (!cnt && time_after(jiffies, hdev->acl_last_tx + in __check_timeout()
3909 hci_link_tx_to(hdev, ACL_LINK); in __check_timeout()
3913 static void hci_sched_acl_pkt(struct hci_dev *hdev) in hci_sched_acl_pkt() argument
3915 unsigned int cnt = hdev->acl_cnt; in hci_sched_acl_pkt()
3920 __check_timeout(hdev, cnt); in hci_sched_acl_pkt()
3922 while (hdev->acl_cnt && in hci_sched_acl_pkt()
3923 (chan = hci_chan_sent(hdev, ACL_LINK, "e))) { in hci_sched_acl_pkt()
3938 hci_send_frame(hdev, skb); in hci_sched_acl_pkt()
3939 hdev->acl_last_tx = jiffies; in hci_sched_acl_pkt()
3941 hdev->acl_cnt--; in hci_sched_acl_pkt()
3947 if (cnt != hdev->acl_cnt) in hci_sched_acl_pkt()
3948 hci_prio_recalculate(hdev, ACL_LINK); in hci_sched_acl_pkt()
3951 static void hci_sched_acl_blk(struct hci_dev *hdev) in hci_sched_acl_blk() argument
3953 unsigned int cnt = hdev->block_cnt; in hci_sched_acl_blk()
3959 __check_timeout(hdev, cnt); in hci_sched_acl_blk()
3961 BT_DBG("%s", hdev->name); in hci_sched_acl_blk()
3963 if (hdev->dev_type == HCI_AMP) in hci_sched_acl_blk()
3968 while (hdev->block_cnt > 0 && in hci_sched_acl_blk()
3969 (chan = hci_chan_sent(hdev, type, "e))) { in hci_sched_acl_blk()
3983 blocks = __get_blocks(hdev, skb); in hci_sched_acl_blk()
3984 if (blocks > hdev->block_cnt) in hci_sched_acl_blk()
3990 hci_send_frame(hdev, skb); in hci_sched_acl_blk()
3991 hdev->acl_last_tx = jiffies; in hci_sched_acl_blk()
3993 hdev->block_cnt -= blocks; in hci_sched_acl_blk()
4001 if (cnt != hdev->block_cnt) in hci_sched_acl_blk()
4002 hci_prio_recalculate(hdev, type); in hci_sched_acl_blk()
4005 static void hci_sched_acl(struct hci_dev *hdev) in hci_sched_acl() argument
4007 BT_DBG("%s", hdev->name); in hci_sched_acl()
4010 if (!hci_conn_num(hdev, ACL_LINK) && hdev->dev_type == HCI_PRIMARY) in hci_sched_acl()
4014 if (!hci_conn_num(hdev, AMP_LINK) && hdev->dev_type == HCI_AMP) in hci_sched_acl()
4017 switch (hdev->flow_ctl_mode) { in hci_sched_acl()
4019 hci_sched_acl_pkt(hdev); in hci_sched_acl()
4023 hci_sched_acl_blk(hdev); in hci_sched_acl()
4029 static void hci_sched_sco(struct hci_dev *hdev) in hci_sched_sco() argument
4035 BT_DBG("%s", hdev->name); in hci_sched_sco()
4037 if (!hci_conn_num(hdev, SCO_LINK)) in hci_sched_sco()
4040 while (hdev->sco_cnt && (conn = hci_low_sent(hdev, SCO_LINK, "e))) { in hci_sched_sco()
4043 hci_send_frame(hdev, skb); in hci_sched_sco()
4052 static void hci_sched_esco(struct hci_dev *hdev) in hci_sched_esco() argument
4058 BT_DBG("%s", hdev->name); in hci_sched_esco()
4060 if (!hci_conn_num(hdev, ESCO_LINK)) in hci_sched_esco()
4063 while (hdev->sco_cnt && (conn = hci_low_sent(hdev, ESCO_LINK, in hci_sched_esco()
4067 hci_send_frame(hdev, skb); in hci_sched_esco()
4076 static void hci_sched_le(struct hci_dev *hdev) in hci_sched_le() argument
4082 BT_DBG("%s", hdev->name); in hci_sched_le()
4084 if (!hci_conn_num(hdev, LE_LINK)) in hci_sched_le()
4087 if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_sched_le()
4090 if (!hdev->le_cnt && hdev->le_pkts && in hci_sched_le()
4091 time_after(jiffies, hdev->le_last_tx + HZ * 45)) in hci_sched_le()
4092 hci_link_tx_to(hdev, LE_LINK); in hci_sched_le()
4095 cnt = hdev->le_pkts ? hdev->le_cnt : hdev->acl_cnt; in hci_sched_le()
4097 while (cnt && (chan = hci_chan_sent(hdev, LE_LINK, "e))) { in hci_sched_le()
4109 hci_send_frame(hdev, skb); in hci_sched_le()
4110 hdev->le_last_tx = jiffies; in hci_sched_le()
4118 if (hdev->le_pkts) in hci_sched_le()
4119 hdev->le_cnt = cnt; in hci_sched_le()
4121 hdev->acl_cnt = cnt; in hci_sched_le()
4124 hci_prio_recalculate(hdev, LE_LINK); in hci_sched_le()
4129 struct hci_dev *hdev = container_of(work, struct hci_dev, tx_work); in hci_tx_work() local
4132 BT_DBG("%s acl %d sco %d le %d", hdev->name, hdev->acl_cnt, in hci_tx_work()
4133 hdev->sco_cnt, hdev->le_cnt); in hci_tx_work()
4135 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_tx_work()
4137 hci_sched_acl(hdev); in hci_tx_work()
4138 hci_sched_sco(hdev); in hci_tx_work()
4139 hci_sched_esco(hdev); in hci_tx_work()
4140 hci_sched_le(hdev); in hci_tx_work()
4144 while ((skb = skb_dequeue(&hdev->raw_q))) in hci_tx_work()
4145 hci_send_frame(hdev, skb); in hci_tx_work()
4151 static void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb) in hci_acldata_packet() argument
4163 BT_DBG("%s len %d handle 0x%4.4x flags 0x%4.4x", hdev->name, skb->len, in hci_acldata_packet()
4166 hdev->stat.acl_rx++; in hci_acldata_packet()
4168 hci_dev_lock(hdev); in hci_acldata_packet()
4169 conn = hci_conn_hash_lookup_handle(hdev, handle); in hci_acldata_packet()
4170 hci_dev_unlock(hdev); in hci_acldata_packet()
4179 bt_dev_err(hdev, "ACL packet for unknown connection handle %d", in hci_acldata_packet()
4187 static void hci_scodata_packet(struct hci_dev *hdev, struct sk_buff *skb) in hci_scodata_packet() argument
4197 BT_DBG("%s len %d handle 0x%4.4x", hdev->name, skb->len, handle); in hci_scodata_packet()
4199 hdev->stat.sco_rx++; in hci_scodata_packet()
4201 hci_dev_lock(hdev); in hci_scodata_packet()
4202 conn = hci_conn_hash_lookup_handle(hdev, handle); in hci_scodata_packet()
4203 hci_dev_unlock(hdev); in hci_scodata_packet()
4210 bt_dev_err(hdev, "SCO packet for unknown connection handle %d", in hci_scodata_packet()
4217 static bool hci_req_is_complete(struct hci_dev *hdev) in hci_req_is_complete() argument
4221 skb = skb_peek(&hdev->cmd_q); in hci_req_is_complete()
4228 static void hci_resend_last(struct hci_dev *hdev) in hci_resend_last() argument
4234 if (!hdev->sent_cmd) in hci_resend_last()
4237 sent = (void *) hdev->sent_cmd->data; in hci_resend_last()
4242 skb = skb_clone(hdev->sent_cmd, GFP_KERNEL); in hci_resend_last()
4246 skb_queue_head(&hdev->cmd_q, skb); in hci_resend_last()
4247 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_resend_last()
4250 void hci_req_cmd_complete(struct hci_dev *hdev, u16 opcode, u8 status, in hci_req_cmd_complete() argument
4262 if (!hci_sent_cmd_data(hdev, opcode)) { in hci_req_cmd_complete()
4269 if (test_bit(HCI_INIT, &hdev->flags) && opcode == HCI_OP_RESET) in hci_req_cmd_complete()
4270 hci_resend_last(hdev); in hci_req_cmd_complete()
4278 if (!status && !hci_req_is_complete(hdev)) in hci_req_cmd_complete()
4285 if (bt_cb(hdev->sent_cmd)->hci.req_flags & HCI_REQ_SKB) { in hci_req_cmd_complete()
4286 *req_complete_skb = bt_cb(hdev->sent_cmd)->hci.req_complete_skb; in hci_req_cmd_complete()
4290 if (bt_cb(hdev->sent_cmd)->hci.req_complete) { in hci_req_cmd_complete()
4291 *req_complete = bt_cb(hdev->sent_cmd)->hci.req_complete; in hci_req_cmd_complete()
4296 spin_lock_irqsave(&hdev->cmd_q.lock, flags); in hci_req_cmd_complete()
4297 while ((skb = __skb_dequeue(&hdev->cmd_q))) { in hci_req_cmd_complete()
4299 __skb_queue_head(&hdev->cmd_q, skb); in hci_req_cmd_complete()
4309 spin_unlock_irqrestore(&hdev->cmd_q.lock, flags); in hci_req_cmd_complete()
4314 struct hci_dev *hdev = container_of(work, struct hci_dev, rx_work); in hci_rx_work() local
4317 BT_DBG("%s", hdev->name); in hci_rx_work()
4319 while ((skb = skb_dequeue(&hdev->rx_q))) { in hci_rx_work()
4321 hci_send_to_monitor(hdev, skb); in hci_rx_work()
4323 if (atomic_read(&hdev->promisc)) { in hci_rx_work()
4325 hci_send_to_sock(hdev, skb); in hci_rx_work()
4328 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_rx_work()
4333 if (test_bit(HCI_INIT, &hdev->flags)) { in hci_rx_work()
4346 BT_DBG("%s Event packet", hdev->name); in hci_rx_work()
4347 hci_event_packet(hdev, skb); in hci_rx_work()
4351 BT_DBG("%s ACL data packet", hdev->name); in hci_rx_work()
4352 hci_acldata_packet(hdev, skb); in hci_rx_work()
4356 BT_DBG("%s SCO data packet", hdev->name); in hci_rx_work()
4357 hci_scodata_packet(hdev, skb); in hci_rx_work()
4369 struct hci_dev *hdev = container_of(work, struct hci_dev, cmd_work); in hci_cmd_work() local
4372 BT_DBG("%s cmd_cnt %d cmd queued %d", hdev->name, in hci_cmd_work()
4373 atomic_read(&hdev->cmd_cnt), skb_queue_len(&hdev->cmd_q)); in hci_cmd_work()
4376 if (atomic_read(&hdev->cmd_cnt)) { in hci_cmd_work()
4377 skb = skb_dequeue(&hdev->cmd_q); in hci_cmd_work()
4381 kfree_skb(hdev->sent_cmd); in hci_cmd_work()
4383 hdev->sent_cmd = skb_clone(skb, GFP_KERNEL); in hci_cmd_work()
4384 if (hdev->sent_cmd) { in hci_cmd_work()
4385 atomic_dec(&hdev->cmd_cnt); in hci_cmd_work()
4386 hci_send_frame(hdev, skb); in hci_cmd_work()
4387 if (test_bit(HCI_RESET, &hdev->flags)) in hci_cmd_work()
4388 cancel_delayed_work(&hdev->cmd_timer); in hci_cmd_work()
4390 schedule_delayed_work(&hdev->cmd_timer, in hci_cmd_work()
4393 skb_queue_head(&hdev->cmd_q, skb); in hci_cmd_work()
4394 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_cmd_work()