Lines Matching refs:hdev
67 BT_DBG("%s %ld", req->hdev->name, opt); in hci_reset_req()
70 set_bit(HCI_RESET, &req->hdev->flags); in hci_reset_req()
77 req->hdev->flow_ctl_mode = HCI_FLOW_CTL_MODE_PACKET_BASED; in bredr_init()
91 req->hdev->flow_ctl_mode = HCI_FLOW_CTL_MODE_BLOCK_BASED; in amp_init1()
118 if (req->hdev->commands[14] & 0x20) in amp_init2()
126 struct hci_dev *hdev = req->hdev; in hci_init1_req() local
128 BT_DBG("%s %ld", hdev->name, opt); in hci_init1_req()
131 if (!test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks)) in hci_init1_req()
134 switch (hdev->dev_type) { in hci_init1_req()
142 bt_dev_err(hdev, "Unknown device type %d", hdev->dev_type); in hci_init1_req()
183 struct hci_dev *hdev = req->hdev; in le_setup() local
195 if (!lmp_bredr_capable(hdev)) in le_setup()
196 hci_dev_set_flag(hdev, HCI_LE_ENABLED); in le_setup()
201 struct hci_dev *hdev = req->hdev; in hci_setup_event_mask() local
212 if (hdev->hci_ver < BLUETOOTH_VER_1_2) in hci_setup_event_mask()
215 if (lmp_bredr_capable(hdev)) { in hci_setup_event_mask()
228 if (hdev->commands[0] & 0x20) { in hci_setup_event_mask()
237 if (hdev->commands[2] & 0x80) in hci_setup_event_mask()
242 if (hdev->le_features[0] & HCI_LE_ENCRYPTION) { in hci_setup_event_mask()
248 if (lmp_inq_rssi_capable(hdev) || in hci_setup_event_mask()
249 test_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks)) in hci_setup_event_mask()
252 if (lmp_ext_feat_capable(hdev)) in hci_setup_event_mask()
255 if (lmp_esco_capable(hdev)) { in hci_setup_event_mask()
260 if (lmp_sniffsubr_capable(hdev)) in hci_setup_event_mask()
263 if (lmp_pause_enc_capable(hdev)) in hci_setup_event_mask()
266 if (lmp_ext_inq_capable(hdev)) in hci_setup_event_mask()
269 if (lmp_no_flush_capable(hdev)) in hci_setup_event_mask()
272 if (lmp_lsto_capable(hdev)) in hci_setup_event_mask()
275 if (lmp_ssp_capable(hdev)) { in hci_setup_event_mask()
289 if (lmp_le_capable(hdev)) in hci_setup_event_mask()
297 struct hci_dev *hdev = req->hdev; in hci_init2_req() local
299 if (hdev->dev_type == HCI_AMP) in hci_init2_req()
302 if (lmp_bredr_capable(hdev)) in hci_init2_req()
305 hci_dev_clear_flag(hdev, HCI_BREDR_ENABLED); in hci_init2_req()
307 if (lmp_le_capable(hdev)) in hci_init2_req()
318 if (hdev->hci_ver > BLUETOOTH_VER_1_1 && in hci_init2_req()
319 !test_bit(HCI_QUIRK_BROKEN_LOCAL_COMMANDS, &hdev->quirks)) in hci_init2_req()
322 if (lmp_ssp_capable(hdev)) { in hci_init2_req()
329 hdev->max_page = 0x01; in hci_init2_req()
331 if (hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) { in hci_init2_req()
339 memset(hdev->eir, 0, sizeof(hdev->eir)); in hci_init2_req()
346 if (lmp_inq_rssi_capable(hdev) || in hci_init2_req()
347 test_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks)) { in hci_init2_req()
354 mode = lmp_ext_inq_capable(hdev) ? 0x02 : 0x01; in hci_init2_req()
359 if (lmp_inq_tx_pwr_capable(hdev)) in hci_init2_req()
362 if (lmp_ext_feat_capable(hdev)) { in hci_init2_req()
370 if (hci_dev_test_flag(hdev, HCI_LINK_SECURITY)) { in hci_init2_req()
381 struct hci_dev *hdev = req->hdev; in hci_setup_link_policy() local
385 if (lmp_rswitch_capable(hdev)) in hci_setup_link_policy()
387 if (lmp_hold_capable(hdev)) in hci_setup_link_policy()
389 if (lmp_sniff_capable(hdev)) in hci_setup_link_policy()
391 if (lmp_park_capable(hdev)) in hci_setup_link_policy()
400 struct hci_dev *hdev = req->hdev; in hci_set_le_support() local
404 if (!lmp_bredr_capable(hdev)) in hci_set_le_support()
409 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { in hci_set_le_support()
414 if (cp.le != lmp_host_le_capable(hdev)) in hci_set_le_support()
421 struct hci_dev *hdev = req->hdev; in hci_set_event_mask_page_2() local
428 if (lmp_cpb_central_capable(hdev)) { in hci_set_event_mask_page_2()
439 if (lmp_cpb_peripheral_capable(hdev)) { in hci_set_event_mask_page_2()
448 if (lmp_ping_capable(hdev) || hdev->le_features[0] & HCI_LE_PING) { in hci_set_event_mask_page_2()
466 struct hci_dev *hdev = req->hdev; in hci_init3_req() local
471 if (hdev->commands[6] & 0x20 && in hci_init3_req()
472 !test_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks)) { in hci_init3_req()
480 if (hdev->commands[5] & 0x10) in hci_init3_req()
483 if (hdev->commands[8] & 0x01) in hci_init3_req()
486 if (hdev->commands[18] & 0x04 && in hci_init3_req()
487 !test_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks)) in hci_init3_req()
494 if (hdev->commands[13] & 0x01) in hci_init3_req()
497 if (lmp_le_capable(hdev)) { in hci_init3_req()
502 if (hdev->le_features[0] & HCI_LE_ENCRYPTION) in hci_init3_req()
508 if (hdev->le_features[0] & HCI_LE_CONN_PARAM_REQ_PROC) in hci_init3_req()
516 if (hdev->le_features[0] & HCI_LE_DATA_LEN_EXT) in hci_init3_req()
522 if (hdev->le_features[0] & HCI_LE_LL_PRIVACY) in hci_init3_req()
530 if (hdev->le_features[0] & HCI_LE_EXT_SCAN_POLICY) in hci_init3_req()
538 if (hdev->le_features[1] & HCI_LE_CHAN_SEL_ALG2) in hci_init3_req()
546 if (hdev->commands[26] & 0x08) in hci_init3_req()
552 if (hdev->commands[26] & 0x10) in hci_init3_req()
558 if (hdev->commands[27] & 0x04) in hci_init3_req()
566 if (hdev->commands[27] & 0x20) in hci_init3_req()
574 if (hdev->commands[34] & 0x02) in hci_init3_req()
582 if (hdev->commands[34] & 0x04) in hci_init3_req()
588 if (hdev->commands[35] & (0x20 | 0x40)) in hci_init3_req()
595 if (use_ext_scan(hdev)) in hci_init3_req()
603 if (ext_adv_capable(hdev)) in hci_init3_req()
612 if ((hdev->commands[25] & 0x40) && !ext_adv_capable(hdev)) { in hci_init3_req()
622 if (hdev->commands[38] & 0x80) { in hci_init3_req()
628 if (hdev->commands[26] & 0x40) { in hci_init3_req()
634 if (hdev->commands[26] & 0x80) { in hci_init3_req()
639 if (hdev->commands[34] & 0x40) { in hci_init3_req()
645 if (hdev->commands[34] & 0x20) { in hci_init3_req()
650 if (hdev->commands[35] & 0x04) { in hci_init3_req()
651 __le16 rpa_timeout = cpu_to_le16(hdev->rpa_timeout); in hci_init3_req()
658 if (hdev->le_features[0] & HCI_LE_DATA_LEN_EXT) { in hci_init3_req()
666 if (ext_adv_capable(hdev)) { in hci_init3_req()
676 for (p = 2; p < HCI_MAX_PAGES && p <= hdev->max_page; p++) { in hci_init3_req()
689 struct hci_dev *hdev = req->hdev; in hci_init4_req() local
704 if (hdev->commands[6] & 0x80 && in hci_init4_req()
705 !test_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks)) { in hci_init4_req()
715 if (hdev->commands[22] & 0x04) in hci_init4_req()
719 if (hdev->commands[41] & 0x08) in hci_init4_req()
723 if (hdev->commands[30] & 0x08) in hci_init4_req()
727 if (lmp_sync_train_capable(hdev)) in hci_init4_req()
731 if (hci_dev_test_flag(hdev, HCI_SSP_ENABLED) && in hci_init4_req()
732 bredr_sc_enabled(hdev)) { in hci_init4_req()
742 if (hdev->commands[18] & 0x08 && in hci_init4_req()
743 !test_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks)) { in hci_init4_req()
744 bool enabled = hci_dev_test_flag(hdev, in hci_init4_req()
748 (hdev->err_data_reporting == ERR_DATA_REPORTING_ENABLED)) { in hci_init4_req()
761 if (hdev->le_features[0] & HCI_LE_DATA_LEN_EXT) { in hci_init4_req()
764 cp.tx_len = cpu_to_le16(hdev->le_max_tx_len); in hci_init4_req()
765 cp.tx_time = cpu_to_le16(hdev->le_max_tx_time); in hci_init4_req()
770 if (hdev->commands[35] & 0x20) { in hci_init4_req()
774 cp.tx_phys = hdev->le_tx_def_phys; in hci_init4_req()
775 cp.rx_phys = hdev->le_rx_def_phys; in hci_init4_req()
783 static int __hci_init(struct hci_dev *hdev) in __hci_init() argument
787 err = __hci_req_sync(hdev, hci_init1_req, 0, HCI_INIT_TIMEOUT, NULL); in __hci_init()
791 if (hci_dev_test_flag(hdev, HCI_SETUP)) in __hci_init()
792 hci_debugfs_create_basic(hdev); in __hci_init()
794 err = __hci_req_sync(hdev, hci_init2_req, 0, HCI_INIT_TIMEOUT, NULL); in __hci_init()
802 if (hdev->dev_type != HCI_PRIMARY) in __hci_init()
805 err = __hci_req_sync(hdev, hci_init3_req, 0, HCI_INIT_TIMEOUT, NULL); in __hci_init()
809 err = __hci_req_sync(hdev, hci_init4_req, 0, HCI_INIT_TIMEOUT, NULL); in __hci_init()
814 if (hdev->commands[45] & 0x04) in __hci_init()
815 hci_read_supported_codecs_v2(hdev); in __hci_init()
816 else if (hdev->commands[29] & 0x20) in __hci_init()
817 hci_read_supported_codecs(hdev); in __hci_init()
831 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in __hci_init()
832 !hci_dev_test_flag(hdev, HCI_CONFIG)) in __hci_init()
835 hci_debugfs_create_common(hdev); in __hci_init()
837 if (lmp_bredr_capable(hdev)) in __hci_init()
838 hci_debugfs_create_bredr(hdev); in __hci_init()
840 if (lmp_le_capable(hdev)) in __hci_init()
841 hci_debugfs_create_le(hdev); in __hci_init()
848 struct hci_dev *hdev = req->hdev; in hci_init0_req() local
850 BT_DBG("%s %ld", hdev->name, opt); in hci_init0_req()
853 if (!test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks)) in hci_init0_req()
860 if (hdev->set_bdaddr) in hci_init0_req()
866 static int __hci_unconf_init(struct hci_dev *hdev) in __hci_unconf_init() argument
870 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in __hci_unconf_init()
873 err = __hci_req_sync(hdev, hci_init0_req, 0, HCI_INIT_TIMEOUT, NULL); in __hci_unconf_init()
877 if (hci_dev_test_flag(hdev, HCI_SETUP)) in __hci_unconf_init()
878 hci_debugfs_create_basic(hdev); in __hci_unconf_init()
887 BT_DBG("%s %x", req->hdev->name, scan); in hci_scan_req()
898 BT_DBG("%s %x", req->hdev->name, auth); in hci_auth_req()
909 BT_DBG("%s %x", req->hdev->name, encrypt); in hci_encrypt_req()
920 BT_DBG("%s %x", req->hdev->name, policy); in hci_linkpol_req()
931 struct hci_dev *hdev = NULL, *d; in hci_dev_get() local
941 hdev = hci_dev_hold(d); in hci_dev_get()
946 return hdev; in hci_dev_get()
951 bool hci_discovery_active(struct hci_dev *hdev) in hci_discovery_active() argument
953 struct discovery_state *discov = &hdev->discovery; in hci_discovery_active()
965 void hci_discovery_set_state(struct hci_dev *hdev, int state) in hci_discovery_set_state() argument
967 int old_state = hdev->discovery.state; in hci_discovery_set_state()
969 BT_DBG("%s state %u -> %u", hdev->name, hdev->discovery.state, state); in hci_discovery_set_state()
974 hdev->discovery.state = state; in hci_discovery_set_state()
978 hci_update_background_scan(hdev); in hci_discovery_set_state()
981 mgmt_discovering(hdev, 0); in hci_discovery_set_state()
986 mgmt_discovering(hdev, 1); in hci_discovery_set_state()
995 void hci_inquiry_cache_flush(struct hci_dev *hdev) in hci_inquiry_cache_flush() argument
997 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_flush()
1009 struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev, in hci_inquiry_cache_lookup() argument
1012 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_lookup()
1025 struct inquiry_entry *hci_inquiry_cache_lookup_unknown(struct hci_dev *hdev, in hci_inquiry_cache_lookup_unknown() argument
1028 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_lookup_unknown()
1041 struct inquiry_entry *hci_inquiry_cache_lookup_resolve(struct hci_dev *hdev, in hci_inquiry_cache_lookup_resolve() argument
1045 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_lookup_resolve()
1060 void hci_inquiry_cache_update_resolve(struct hci_dev *hdev, in hci_inquiry_cache_update_resolve() argument
1063 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_update_resolve()
1079 u32 hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data, in hci_inquiry_cache_update() argument
1082 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_update()
1088 hci_remove_remote_oob_data(hdev, &data->bdaddr, BDADDR_BREDR); in hci_inquiry_cache_update()
1093 ie = hci_inquiry_cache_lookup(hdev, &data->bdaddr); in hci_inquiry_cache_update()
1101 hci_inquiry_cache_update_resolve(hdev, ie); in hci_inquiry_cache_update()
1141 static int inquiry_cache_dump(struct hci_dev *hdev, int num, __u8 *buf) in inquiry_cache_dump() argument
1143 struct discovery_state *cache = &hdev->discovery; in inquiry_cache_dump()
1172 struct hci_dev *hdev = req->hdev; in hci_inq_req() local
1175 BT_DBG("%s", hdev->name); in hci_inq_req()
1177 if (test_bit(HCI_INQUIRY, &hdev->flags)) in hci_inq_req()
1193 struct hci_dev *hdev; in hci_inquiry() local
1201 hdev = hci_dev_get(ir.dev_id); in hci_inquiry()
1202 if (!hdev) in hci_inquiry()
1205 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_inquiry()
1210 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_inquiry()
1215 if (hdev->dev_type != HCI_PRIMARY) { in hci_inquiry()
1220 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in hci_inquiry()
1231 hci_dev_lock(hdev); in hci_inquiry()
1232 if (inquiry_cache_age(hdev) > INQUIRY_CACHE_AGE_MAX || in hci_inquiry()
1233 inquiry_cache_empty(hdev) || ir.flags & IREQ_CACHE_FLUSH) { in hci_inquiry()
1234 hci_inquiry_cache_flush(hdev); in hci_inquiry()
1237 hci_dev_unlock(hdev); in hci_inquiry()
1242 err = hci_req_sync(hdev, hci_inq_req, (unsigned long) &ir, in hci_inquiry()
1250 if (wait_on_bit(&hdev->flags, HCI_INQUIRY, in hci_inquiry()
1271 hci_dev_lock(hdev); in hci_inquiry()
1272 ir.num_rsp = inquiry_cache_dump(hdev, max_rsp, buf); in hci_inquiry()
1273 hci_dev_unlock(hdev); in hci_inquiry()
1288 hci_dev_put(hdev); in hci_inquiry()
1304 static void hci_dev_get_bd_addr_from_property(struct hci_dev *hdev) in hci_dev_get_bd_addr_from_property() argument
1306 struct fwnode_handle *fwnode = dev_fwnode(hdev->dev.parent); in hci_dev_get_bd_addr_from_property()
1315 bacpy(&hdev->public_addr, &ba); in hci_dev_get_bd_addr_from_property()
1318 static int hci_dev_do_open(struct hci_dev *hdev) in hci_dev_do_open() argument
1322 BT_DBG("%s %p", hdev->name, hdev); in hci_dev_do_open()
1324 hci_req_sync_lock(hdev); in hci_dev_do_open()
1326 if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) { in hci_dev_do_open()
1331 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_dev_do_open()
1332 !hci_dev_test_flag(hdev, HCI_CONFIG)) { in hci_dev_do_open()
1336 if (hci_dev_test_flag(hdev, HCI_RFKILLED)) { in hci_dev_do_open()
1353 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_do_open()
1354 hdev->dev_type == HCI_PRIMARY && in hci_dev_do_open()
1355 !bacmp(&hdev->bdaddr, BDADDR_ANY) && in hci_dev_do_open()
1356 !bacmp(&hdev->static_addr, BDADDR_ANY)) { in hci_dev_do_open()
1362 if (test_bit(HCI_UP, &hdev->flags)) { in hci_dev_do_open()
1367 if (hdev->open(hdev)) { in hci_dev_do_open()
1372 set_bit(HCI_RUNNING, &hdev->flags); in hci_dev_do_open()
1373 hci_sock_dev_event(hdev, HCI_DEV_OPEN); in hci_dev_do_open()
1375 atomic_set(&hdev->cmd_cnt, 1); in hci_dev_do_open()
1376 set_bit(HCI_INIT, &hdev->flags); in hci_dev_do_open()
1378 if (hci_dev_test_flag(hdev, HCI_SETUP) || in hci_dev_do_open()
1379 test_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks)) { in hci_dev_do_open()
1382 hci_sock_dev_event(hdev, HCI_DEV_SETUP); in hci_dev_do_open()
1384 if (hdev->setup) in hci_dev_do_open()
1385 ret = hdev->setup(hdev); in hci_dev_do_open()
1392 &hdev->quirks); in hci_dev_do_open()
1397 if (test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) { in hci_dev_do_open()
1398 if (!bacmp(&hdev->public_addr, BDADDR_ANY)) in hci_dev_do_open()
1399 hci_dev_get_bd_addr_from_property(hdev); in hci_dev_do_open()
1401 if (bacmp(&hdev->public_addr, BDADDR_ANY) && in hci_dev_do_open()
1402 hdev->set_bdaddr) { in hci_dev_do_open()
1403 ret = hdev->set_bdaddr(hdev, in hci_dev_do_open()
1404 &hdev->public_addr); in hci_dev_do_open()
1427 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) || in hci_dev_do_open()
1429 hci_dev_set_flag(hdev, HCI_UNCONFIGURED); in hci_dev_do_open()
1439 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in hci_dev_do_open()
1440 ret = __hci_unconf_init(hdev); in hci_dev_do_open()
1443 if (hci_dev_test_flag(hdev, HCI_CONFIG)) { in hci_dev_do_open()
1449 if (bacmp(&hdev->public_addr, BDADDR_ANY) && in hci_dev_do_open()
1450 hdev->set_bdaddr) in hci_dev_do_open()
1451 ret = hdev->set_bdaddr(hdev, &hdev->public_addr); in hci_dev_do_open()
1457 if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED) && in hci_dev_do_open()
1458 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_do_open()
1459 ret = __hci_init(hdev); in hci_dev_do_open()
1460 if (!ret && hdev->post_init) in hci_dev_do_open()
1461 ret = hdev->post_init(hdev); in hci_dev_do_open()
1469 if (test_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks) && in hci_dev_do_open()
1470 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_do_open()
1471 hci_dev_test_flag(hdev, HCI_VENDOR_DIAG) && hdev->set_diag) in hci_dev_do_open()
1472 ret = hdev->set_diag(hdev, true); in hci_dev_do_open()
1474 msft_do_open(hdev); in hci_dev_do_open()
1475 aosp_do_open(hdev); in hci_dev_do_open()
1477 clear_bit(HCI_INIT, &hdev->flags); in hci_dev_do_open()
1480 hci_dev_hold(hdev); in hci_dev_do_open()
1481 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in hci_dev_do_open()
1482 hci_adv_instances_set_rpa_expired(hdev, true); in hci_dev_do_open()
1483 set_bit(HCI_UP, &hdev->flags); in hci_dev_do_open()
1484 hci_sock_dev_event(hdev, HCI_DEV_UP); in hci_dev_do_open()
1485 hci_leds_update_powered(hdev, true); in hci_dev_do_open()
1486 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_dev_do_open()
1487 !hci_dev_test_flag(hdev, HCI_CONFIG) && in hci_dev_do_open()
1488 !hci_dev_test_flag(hdev, HCI_UNCONFIGURED) && in hci_dev_do_open()
1489 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_do_open()
1490 hci_dev_test_flag(hdev, HCI_MGMT) && in hci_dev_do_open()
1491 hdev->dev_type == HCI_PRIMARY) { in hci_dev_do_open()
1492 ret = __hci_req_hci_power_on(hdev); in hci_dev_do_open()
1493 mgmt_power_on(hdev, ret); in hci_dev_do_open()
1497 flush_work(&hdev->tx_work); in hci_dev_do_open()
1503 flush_work(&hdev->rx_work); in hci_dev_do_open()
1504 flush_work(&hdev->cmd_work); in hci_dev_do_open()
1506 skb_queue_purge(&hdev->cmd_q); in hci_dev_do_open()
1507 skb_queue_purge(&hdev->rx_q); in hci_dev_do_open()
1509 if (hdev->flush) in hci_dev_do_open()
1510 hdev->flush(hdev); in hci_dev_do_open()
1512 if (hdev->sent_cmd) { in hci_dev_do_open()
1513 kfree_skb(hdev->sent_cmd); in hci_dev_do_open()
1514 hdev->sent_cmd = NULL; in hci_dev_do_open()
1517 clear_bit(HCI_RUNNING, &hdev->flags); in hci_dev_do_open()
1518 hci_sock_dev_event(hdev, HCI_DEV_CLOSE); in hci_dev_do_open()
1520 hdev->close(hdev); in hci_dev_do_open()
1521 hdev->flags &= BIT(HCI_RAW); in hci_dev_do_open()
1525 hci_req_sync_unlock(hdev); in hci_dev_do_open()
1533 struct hci_dev *hdev; in hci_dev_open() local
1536 hdev = hci_dev_get(dev); in hci_dev_open()
1537 if (!hdev) in hci_dev_open()
1549 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED) && in hci_dev_open()
1550 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_open()
1560 if (hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF)) in hci_dev_open()
1561 cancel_delayed_work(&hdev->power_off); in hci_dev_open()
1567 flush_workqueue(hdev->req_workqueue); in hci_dev_open()
1575 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_open()
1576 !hci_dev_test_flag(hdev, HCI_MGMT)) in hci_dev_open()
1577 hci_dev_set_flag(hdev, HCI_BONDABLE); in hci_dev_open()
1579 err = hci_dev_do_open(hdev); in hci_dev_open()
1582 hci_dev_put(hdev); in hci_dev_open()
1587 static void hci_pend_le_actions_clear(struct hci_dev *hdev) in hci_pend_le_actions_clear() argument
1591 list_for_each_entry(p, &hdev->le_conn_params, list) { in hci_pend_le_actions_clear()
1603 int hci_dev_do_close(struct hci_dev *hdev) in hci_dev_do_close() argument
1608 BT_DBG("%s %p", hdev->name, hdev); in hci_dev_do_close()
1610 cancel_delayed_work(&hdev->power_off); in hci_dev_do_close()
1611 cancel_delayed_work(&hdev->ncmd_timer); in hci_dev_do_close()
1613 hci_request_cancel_all(hdev); in hci_dev_do_close()
1614 hci_req_sync_lock(hdev); in hci_dev_do_close()
1616 if (!hci_dev_test_flag(hdev, HCI_UNREGISTER) && in hci_dev_do_close()
1617 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_do_close()
1618 test_bit(HCI_UP, &hdev->flags)) { in hci_dev_do_close()
1620 if (hdev->shutdown) in hci_dev_do_close()
1621 err = hdev->shutdown(hdev); in hci_dev_do_close()
1624 if (!test_and_clear_bit(HCI_UP, &hdev->flags)) { in hci_dev_do_close()
1625 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_dev_do_close()
1626 hci_req_sync_unlock(hdev); in hci_dev_do_close()
1630 hci_leds_update_powered(hdev, false); in hci_dev_do_close()
1633 flush_work(&hdev->tx_work); in hci_dev_do_close()
1634 flush_work(&hdev->rx_work); in hci_dev_do_close()
1636 if (hdev->discov_timeout > 0) { in hci_dev_do_close()
1637 hdev->discov_timeout = 0; in hci_dev_do_close()
1638 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in hci_dev_do_close()
1639 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in hci_dev_do_close()
1642 if (hci_dev_test_and_clear_flag(hdev, HCI_SERVICE_CACHE)) in hci_dev_do_close()
1643 cancel_delayed_work(&hdev->service_cache); in hci_dev_do_close()
1645 if (hci_dev_test_flag(hdev, HCI_MGMT)) { in hci_dev_do_close()
1648 cancel_delayed_work_sync(&hdev->rpa_expired); in hci_dev_do_close()
1650 list_for_each_entry(adv_instance, &hdev->adv_instances, list) in hci_dev_do_close()
1657 drain_workqueue(hdev->workqueue); in hci_dev_do_close()
1659 hci_dev_lock(hdev); in hci_dev_do_close()
1661 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in hci_dev_do_close()
1663 auto_off = hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF); in hci_dev_do_close()
1665 if (!auto_off && hdev->dev_type == HCI_PRIMARY && in hci_dev_do_close()
1666 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_do_close()
1667 hci_dev_test_flag(hdev, HCI_MGMT)) in hci_dev_do_close()
1668 __mgmt_power_off(hdev); in hci_dev_do_close()
1670 hci_inquiry_cache_flush(hdev); in hci_dev_do_close()
1671 hci_pend_le_actions_clear(hdev); in hci_dev_do_close()
1672 hci_conn_hash_flush(hdev); in hci_dev_do_close()
1673 hci_dev_unlock(hdev); in hci_dev_do_close()
1675 smp_unregister(hdev); in hci_dev_do_close()
1677 hci_sock_dev_event(hdev, HCI_DEV_DOWN); in hci_dev_do_close()
1679 aosp_do_close(hdev); in hci_dev_do_close()
1680 msft_do_close(hdev); in hci_dev_do_close()
1682 if (hdev->flush) in hci_dev_do_close()
1683 hdev->flush(hdev); in hci_dev_do_close()
1686 skb_queue_purge(&hdev->cmd_q); in hci_dev_do_close()
1687 atomic_set(&hdev->cmd_cnt, 1); in hci_dev_do_close()
1688 if (test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks) && in hci_dev_do_close()
1689 !auto_off && !hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_dev_do_close()
1690 set_bit(HCI_INIT, &hdev->flags); in hci_dev_do_close()
1691 __hci_req_sync(hdev, hci_reset_req, 0, HCI_CMD_TIMEOUT, NULL); in hci_dev_do_close()
1692 clear_bit(HCI_INIT, &hdev->flags); in hci_dev_do_close()
1696 flush_work(&hdev->cmd_work); in hci_dev_do_close()
1699 skb_queue_purge(&hdev->rx_q); in hci_dev_do_close()
1700 skb_queue_purge(&hdev->cmd_q); in hci_dev_do_close()
1701 skb_queue_purge(&hdev->raw_q); in hci_dev_do_close()
1704 if (hdev->sent_cmd) { in hci_dev_do_close()
1705 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_dev_do_close()
1706 kfree_skb(hdev->sent_cmd); in hci_dev_do_close()
1707 hdev->sent_cmd = NULL; in hci_dev_do_close()
1710 clear_bit(HCI_RUNNING, &hdev->flags); in hci_dev_do_close()
1711 hci_sock_dev_event(hdev, HCI_DEV_CLOSE); in hci_dev_do_close()
1713 if (test_and_clear_bit(SUSPEND_POWERING_DOWN, hdev->suspend_tasks)) in hci_dev_do_close()
1714 wake_up(&hdev->suspend_wait_q); in hci_dev_do_close()
1718 hdev->close(hdev); in hci_dev_do_close()
1721 hdev->flags &= BIT(HCI_RAW); in hci_dev_do_close()
1722 hci_dev_clear_volatile_flags(hdev); in hci_dev_do_close()
1725 hdev->amp_status = AMP_STATUS_POWERED_DOWN; in hci_dev_do_close()
1727 memset(hdev->eir, 0, sizeof(hdev->eir)); in hci_dev_do_close()
1728 memset(hdev->dev_class, 0, sizeof(hdev->dev_class)); in hci_dev_do_close()
1729 bacpy(&hdev->random_addr, BDADDR_ANY); in hci_dev_do_close()
1730 hci_codec_list_clear(&hdev->local_codecs); in hci_dev_do_close()
1732 hci_req_sync_unlock(hdev); in hci_dev_do_close()
1734 hci_dev_put(hdev); in hci_dev_do_close()
1740 struct hci_dev *hdev; in hci_dev_close() local
1743 hdev = hci_dev_get(dev); in hci_dev_close()
1744 if (!hdev) in hci_dev_close()
1747 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_close()
1752 if (hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF)) in hci_dev_close()
1753 cancel_delayed_work(&hdev->power_off); in hci_dev_close()
1755 err = hci_dev_do_close(hdev); in hci_dev_close()
1758 hci_dev_put(hdev); in hci_dev_close()
1762 static int hci_dev_do_reset(struct hci_dev *hdev) in hci_dev_do_reset() argument
1766 BT_DBG("%s %p", hdev->name, hdev); in hci_dev_do_reset()
1768 hci_req_sync_lock(hdev); in hci_dev_do_reset()
1771 skb_queue_purge(&hdev->rx_q); in hci_dev_do_reset()
1772 skb_queue_purge(&hdev->cmd_q); in hci_dev_do_reset()
1777 drain_workqueue(hdev->workqueue); in hci_dev_do_reset()
1779 hci_dev_lock(hdev); in hci_dev_do_reset()
1780 hci_inquiry_cache_flush(hdev); in hci_dev_do_reset()
1781 hci_conn_hash_flush(hdev); in hci_dev_do_reset()
1782 hci_dev_unlock(hdev); in hci_dev_do_reset()
1784 if (hdev->flush) in hci_dev_do_reset()
1785 hdev->flush(hdev); in hci_dev_do_reset()
1787 atomic_set(&hdev->cmd_cnt, 1); in hci_dev_do_reset()
1788 hdev->acl_cnt = 0; hdev->sco_cnt = 0; hdev->le_cnt = 0; in hci_dev_do_reset()
1790 ret = __hci_req_sync(hdev, hci_reset_req, 0, HCI_INIT_TIMEOUT, NULL); in hci_dev_do_reset()
1792 hci_req_sync_unlock(hdev); in hci_dev_do_reset()
1798 struct hci_dev *hdev; in hci_dev_reset() local
1801 hdev = hci_dev_get(dev); in hci_dev_reset()
1802 if (!hdev) in hci_dev_reset()
1805 if (!test_bit(HCI_UP, &hdev->flags)) { in hci_dev_reset()
1810 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_reset()
1815 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_dev_reset()
1820 err = hci_dev_do_reset(hdev); in hci_dev_reset()
1823 hci_dev_put(hdev); in hci_dev_reset()
1829 struct hci_dev *hdev; in hci_dev_reset_stat() local
1832 hdev = hci_dev_get(dev); in hci_dev_reset_stat()
1833 if (!hdev) in hci_dev_reset_stat()
1836 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_reset_stat()
1841 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_dev_reset_stat()
1846 memset(&hdev->stat, 0, sizeof(struct hci_dev_stats)); in hci_dev_reset_stat()
1849 hci_dev_put(hdev); in hci_dev_reset_stat()
1853 static void hci_update_scan_state(struct hci_dev *hdev, u8 scan) in hci_update_scan_state() argument
1857 BT_DBG("%s scan 0x%02x", hdev->name, scan); in hci_update_scan_state()
1860 conn_changed = !hci_dev_test_and_set_flag(hdev, in hci_update_scan_state()
1863 conn_changed = hci_dev_test_and_clear_flag(hdev, in hci_update_scan_state()
1867 discov_changed = !hci_dev_test_and_set_flag(hdev, in hci_update_scan_state()
1870 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in hci_update_scan_state()
1871 discov_changed = hci_dev_test_and_clear_flag(hdev, in hci_update_scan_state()
1875 if (!hci_dev_test_flag(hdev, HCI_MGMT)) in hci_update_scan_state()
1880 hci_dev_set_flag(hdev, HCI_BREDR_ENABLED); in hci_update_scan_state()
1882 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in hci_update_scan_state()
1883 hci_req_update_adv_data(hdev, hdev->cur_adv_instance); in hci_update_scan_state()
1885 mgmt_new_settings(hdev); in hci_update_scan_state()
1891 struct hci_dev *hdev; in hci_dev_cmd() local
1898 hdev = hci_dev_get(dr.dev_id); in hci_dev_cmd()
1899 if (!hdev) in hci_dev_cmd()
1902 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_cmd()
1907 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_dev_cmd()
1912 if (hdev->dev_type != HCI_PRIMARY) { in hci_dev_cmd()
1917 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in hci_dev_cmd()
1924 err = hci_req_sync(hdev, hci_auth_req, dr.dev_opt, in hci_dev_cmd()
1929 if (!lmp_encrypt_capable(hdev)) { in hci_dev_cmd()
1934 if (!test_bit(HCI_AUTH, &hdev->flags)) { in hci_dev_cmd()
1936 err = hci_req_sync(hdev, hci_auth_req, dr.dev_opt, in hci_dev_cmd()
1942 err = hci_req_sync(hdev, hci_encrypt_req, dr.dev_opt, in hci_dev_cmd()
1947 err = hci_req_sync(hdev, hci_scan_req, dr.dev_opt, in hci_dev_cmd()
1954 hci_update_scan_state(hdev, dr.dev_opt); in hci_dev_cmd()
1958 err = hci_req_sync(hdev, hci_linkpol_req, dr.dev_opt, in hci_dev_cmd()
1963 hdev->link_mode = ((__u16) dr.dev_opt) & in hci_dev_cmd()
1968 if (hdev->pkt_type == (__u16) dr.dev_opt) in hci_dev_cmd()
1971 hdev->pkt_type = (__u16) dr.dev_opt; in hci_dev_cmd()
1972 mgmt_phy_configuration_changed(hdev, NULL); in hci_dev_cmd()
1976 hdev->acl_mtu = *((__u16 *) &dr.dev_opt + 1); in hci_dev_cmd()
1977 hdev->acl_pkts = *((__u16 *) &dr.dev_opt + 0); in hci_dev_cmd()
1981 hdev->sco_mtu = *((__u16 *) &dr.dev_opt + 1); in hci_dev_cmd()
1982 hdev->sco_pkts = *((__u16 *) &dr.dev_opt + 0); in hci_dev_cmd()
1991 hci_dev_put(hdev); in hci_dev_cmd()
1997 struct hci_dev *hdev; in hci_get_dev_list() local
2018 list_for_each_entry(hdev, &hci_dev_list, list) { in hci_get_dev_list()
2019 unsigned long flags = hdev->flags; in hci_get_dev_list()
2025 if (hci_dev_test_flag(hdev, HCI_AUTO_OFF)) in hci_get_dev_list()
2028 (dr + n)->dev_id = hdev->id; in hci_get_dev_list()
2047 struct hci_dev *hdev; in hci_get_dev_info() local
2055 hdev = hci_dev_get(di.dev_id); in hci_get_dev_info()
2056 if (!hdev) in hci_get_dev_info()
2063 if (hci_dev_test_flag(hdev, HCI_AUTO_OFF)) in hci_get_dev_info()
2064 flags = hdev->flags & ~BIT(HCI_UP); in hci_get_dev_info()
2066 flags = hdev->flags; in hci_get_dev_info()
2068 strcpy(di.name, hdev->name); in hci_get_dev_info()
2069 di.bdaddr = hdev->bdaddr; in hci_get_dev_info()
2070 di.type = (hdev->bus & 0x0f) | ((hdev->dev_type & 0x03) << 4); in hci_get_dev_info()
2072 di.pkt_type = hdev->pkt_type; in hci_get_dev_info()
2073 if (lmp_bredr_capable(hdev)) { in hci_get_dev_info()
2074 di.acl_mtu = hdev->acl_mtu; in hci_get_dev_info()
2075 di.acl_pkts = hdev->acl_pkts; in hci_get_dev_info()
2076 di.sco_mtu = hdev->sco_mtu; in hci_get_dev_info()
2077 di.sco_pkts = hdev->sco_pkts; in hci_get_dev_info()
2079 di.acl_mtu = hdev->le_mtu; in hci_get_dev_info()
2080 di.acl_pkts = hdev->le_pkts; in hci_get_dev_info()
2084 di.link_policy = hdev->link_policy; in hci_get_dev_info()
2085 di.link_mode = hdev->link_mode; in hci_get_dev_info()
2087 memcpy(&di.stat, &hdev->stat, sizeof(di.stat)); in hci_get_dev_info()
2088 memcpy(&di.features, &hdev->features, sizeof(di.features)); in hci_get_dev_info()
2093 hci_dev_put(hdev); in hci_get_dev_info()
2102 struct hci_dev *hdev = data; in hci_rfkill_set_block() local
2104 BT_DBG("%p name %s blocked %d", hdev, hdev->name, blocked); in hci_rfkill_set_block()
2106 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) in hci_rfkill_set_block()
2110 hci_dev_set_flag(hdev, HCI_RFKILLED); in hci_rfkill_set_block()
2111 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_rfkill_set_block()
2112 !hci_dev_test_flag(hdev, HCI_CONFIG)) in hci_rfkill_set_block()
2113 hci_dev_do_close(hdev); in hci_rfkill_set_block()
2115 hci_dev_clear_flag(hdev, HCI_RFKILLED); in hci_rfkill_set_block()
2127 struct hci_dev *hdev = container_of(work, struct hci_dev, power_on); in hci_power_on() local
2130 BT_DBG("%s", hdev->name); in hci_power_on()
2132 if (test_bit(HCI_UP, &hdev->flags) && in hci_power_on()
2133 hci_dev_test_flag(hdev, HCI_MGMT) && in hci_power_on()
2134 hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF)) { in hci_power_on()
2135 cancel_delayed_work(&hdev->power_off); in hci_power_on()
2136 hci_req_sync_lock(hdev); in hci_power_on()
2137 err = __hci_req_hci_power_on(hdev); in hci_power_on()
2138 hci_req_sync_unlock(hdev); in hci_power_on()
2139 mgmt_power_on(hdev, err); in hci_power_on()
2143 err = hci_dev_do_open(hdev); in hci_power_on()
2145 hci_dev_lock(hdev); in hci_power_on()
2146 mgmt_set_powered_failed(hdev, err); in hci_power_on()
2147 hci_dev_unlock(hdev); in hci_power_on()
2155 if (hci_dev_test_flag(hdev, HCI_RFKILLED) || in hci_power_on()
2156 hci_dev_test_flag(hdev, HCI_UNCONFIGURED) || in hci_power_on()
2157 (hdev->dev_type == HCI_PRIMARY && in hci_power_on()
2158 !bacmp(&hdev->bdaddr, BDADDR_ANY) && in hci_power_on()
2159 !bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_power_on()
2160 hci_dev_clear_flag(hdev, HCI_AUTO_OFF); in hci_power_on()
2161 hci_dev_do_close(hdev); in hci_power_on()
2162 } else if (hci_dev_test_flag(hdev, HCI_AUTO_OFF)) { in hci_power_on()
2163 queue_delayed_work(hdev->req_workqueue, &hdev->power_off, in hci_power_on()
2167 if (hci_dev_test_and_clear_flag(hdev, HCI_SETUP)) { in hci_power_on()
2171 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in hci_power_on()
2172 set_bit(HCI_RAW, &hdev->flags); in hci_power_on()
2181 mgmt_index_added(hdev); in hci_power_on()
2182 } else if (hci_dev_test_and_clear_flag(hdev, HCI_CONFIG)) { in hci_power_on()
2186 if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in hci_power_on()
2187 clear_bit(HCI_RAW, &hdev->flags); in hci_power_on()
2193 mgmt_index_added(hdev); in hci_power_on()
2199 struct hci_dev *hdev = container_of(work, struct hci_dev, in hci_power_off() local
2202 BT_DBG("%s", hdev->name); in hci_power_off()
2204 hci_dev_do_close(hdev); in hci_power_off()
2209 struct hci_dev *hdev = container_of(work, struct hci_dev, error_reset); in hci_error_reset() local
2211 BT_DBG("%s", hdev->name); in hci_error_reset()
2213 if (hdev->hw_error) in hci_error_reset()
2214 hdev->hw_error(hdev, hdev->hw_error_code); in hci_error_reset()
2216 bt_dev_err(hdev, "hardware error 0x%2.2x", hdev->hw_error_code); in hci_error_reset()
2218 if (hci_dev_do_close(hdev)) in hci_error_reset()
2221 hci_dev_do_open(hdev); in hci_error_reset()
2224 void hci_uuids_clear(struct hci_dev *hdev) in hci_uuids_clear() argument
2228 list_for_each_entry_safe(uuid, tmp, &hdev->uuids, list) { in hci_uuids_clear()
2234 void hci_link_keys_clear(struct hci_dev *hdev) in hci_link_keys_clear() argument
2238 list_for_each_entry(key, &hdev->link_keys, list) { in hci_link_keys_clear()
2244 void hci_smp_ltks_clear(struct hci_dev *hdev) in hci_smp_ltks_clear() argument
2248 list_for_each_entry(k, &hdev->long_term_keys, list) { in hci_smp_ltks_clear()
2254 void hci_smp_irks_clear(struct hci_dev *hdev) in hci_smp_irks_clear() argument
2258 list_for_each_entry(k, &hdev->identity_resolving_keys, list) { in hci_smp_irks_clear()
2264 void hci_blocked_keys_clear(struct hci_dev *hdev) in hci_blocked_keys_clear() argument
2268 list_for_each_entry(b, &hdev->blocked_keys, list) { in hci_blocked_keys_clear()
2274 bool hci_is_blocked_key(struct hci_dev *hdev, u8 type, u8 val[16]) in hci_is_blocked_key() argument
2280 list_for_each_entry_rcu(b, &hdev->blocked_keys, list) { in hci_is_blocked_key()
2291 struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr) in hci_find_link_key() argument
2296 list_for_each_entry_rcu(k, &hdev->link_keys, list) { in hci_find_link_key()
2300 if (hci_is_blocked_key(hdev, in hci_find_link_key()
2303 bt_dev_warn_ratelimited(hdev, in hci_find_link_key()
2317 static bool hci_persistent_key(struct hci_dev *hdev, struct hci_conn *conn, in hci_persistent_key() argument
2365 struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_find_ltk() argument
2371 list_for_each_entry_rcu(k, &hdev->long_term_keys, list) { in hci_find_ltk()
2378 if (hci_is_blocked_key(hdev, HCI_BLOCKED_KEY_TYPE_LTK, in hci_find_ltk()
2380 bt_dev_warn_ratelimited(hdev, in hci_find_ltk()
2394 struct smp_irk *hci_find_irk_by_rpa(struct hci_dev *hdev, bdaddr_t *rpa) in hci_find_irk_by_rpa() argument
2400 list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) { in hci_find_irk_by_rpa()
2407 list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) { in hci_find_irk_by_rpa()
2408 if (smp_irk_matches(hdev, irk->val, rpa)) { in hci_find_irk_by_rpa()
2416 if (irk_to_return && hci_is_blocked_key(hdev, HCI_BLOCKED_KEY_TYPE_IRK, in hci_find_irk_by_rpa()
2418 bt_dev_warn_ratelimited(hdev, "Identity key blocked for %pMR", in hci_find_irk_by_rpa()
2428 struct smp_irk *hci_find_irk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_find_irk_by_addr() argument
2439 list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) { in hci_find_irk_by_addr()
2449 if (irk_to_return && hci_is_blocked_key(hdev, HCI_BLOCKED_KEY_TYPE_IRK, in hci_find_irk_by_addr()
2451 bt_dev_warn_ratelimited(hdev, "Identity key blocked for %pMR", in hci_find_irk_by_addr()
2461 struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, in hci_add_link_key() argument
2468 old_key = hci_find_link_key(hdev, bdaddr); in hci_add_link_key()
2477 list_add_rcu(&key->list, &hdev->link_keys); in hci_add_link_key()
2480 BT_DBG("%s key for %pMR type %u", hdev->name, bdaddr, type); in hci_add_link_key()
2502 *persistent = hci_persistent_key(hdev, conn, type, in hci_add_link_key()
2508 struct smp_ltk *hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_add_ltk() argument
2515 old_key = hci_find_ltk(hdev, bdaddr, addr_type, role); in hci_add_ltk()
2522 list_add_rcu(&key->list, &hdev->long_term_keys); in hci_add_ltk()
2537 struct smp_irk *hci_add_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_add_irk() argument
2542 irk = hci_find_irk_by_addr(hdev, bdaddr, addr_type); in hci_add_irk()
2551 list_add_rcu(&irk->list, &hdev->identity_resolving_keys); in hci_add_irk()
2560 int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr) in hci_remove_link_key() argument
2564 key = hci_find_link_key(hdev, bdaddr); in hci_remove_link_key()
2568 BT_DBG("%s removing %pMR", hdev->name, bdaddr); in hci_remove_link_key()
2576 int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 bdaddr_type) in hci_remove_ltk() argument
2581 list_for_each_entry_rcu(k, &hdev->long_term_keys, list) { in hci_remove_ltk()
2585 BT_DBG("%s removing %pMR", hdev->name, bdaddr); in hci_remove_ltk()
2595 void hci_remove_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type) in hci_remove_irk() argument
2599 list_for_each_entry_rcu(k, &hdev->identity_resolving_keys, list) { in hci_remove_irk()
2603 BT_DBG("%s removing %pMR", hdev->name, bdaddr); in hci_remove_irk()
2610 bool hci_bdaddr_is_paired(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type) in hci_bdaddr_is_paired() argument
2617 if (hci_find_link_key(hdev, bdaddr)) in hci_bdaddr_is_paired()
2628 irk = hci_get_irk(hdev, bdaddr, addr_type); in hci_bdaddr_is_paired()
2635 list_for_each_entry_rcu(k, &hdev->long_term_keys, list) { in hci_bdaddr_is_paired()
2649 struct hci_dev *hdev = container_of(work, struct hci_dev, in hci_cmd_timeout() local
2652 if (hdev->sent_cmd) { in hci_cmd_timeout()
2653 struct hci_command_hdr *sent = (void *) hdev->sent_cmd->data; in hci_cmd_timeout()
2656 bt_dev_err(hdev, "command 0x%4.4x tx timeout", opcode); in hci_cmd_timeout()
2658 bt_dev_err(hdev, "command tx timeout"); in hci_cmd_timeout()
2661 if (hdev->cmd_timeout) in hci_cmd_timeout()
2662 hdev->cmd_timeout(hdev); in hci_cmd_timeout()
2664 atomic_set(&hdev->cmd_cnt, 1); in hci_cmd_timeout()
2665 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_cmd_timeout()
2671 struct hci_dev *hdev = container_of(work, struct hci_dev, in hci_ncmd_timeout() local
2674 bt_dev_err(hdev, "Controller not accepting commands anymore: ncmd = 0"); in hci_ncmd_timeout()
2679 if (test_bit(HCI_INIT, &hdev->flags)) in hci_ncmd_timeout()
2683 hci_reset_dev(hdev); in hci_ncmd_timeout()
2686 struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev, in hci_find_remote_oob_data() argument
2691 list_for_each_entry(data, &hdev->remote_oob_data, list) { in hci_find_remote_oob_data()
2702 int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_remove_remote_oob_data() argument
2707 data = hci_find_remote_oob_data(hdev, bdaddr, bdaddr_type); in hci_remove_remote_oob_data()
2711 BT_DBG("%s removing %pMR (%u)", hdev->name, bdaddr, bdaddr_type); in hci_remove_remote_oob_data()
2719 void hci_remote_oob_data_clear(struct hci_dev *hdev) in hci_remote_oob_data_clear() argument
2723 list_for_each_entry_safe(data, n, &hdev->remote_oob_data, list) { in hci_remote_oob_data_clear()
2729 int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_add_remote_oob_data() argument
2735 data = hci_find_remote_oob_data(hdev, bdaddr, bdaddr_type); in hci_add_remote_oob_data()
2743 list_add(&data->list, &hdev->remote_oob_data); in hci_add_remote_oob_data()
2770 BT_DBG("%s for %pMR", hdev->name, bdaddr); in hci_add_remote_oob_data()
2776 struct adv_info *hci_find_adv_instance(struct hci_dev *hdev, u8 instance) in hci_find_adv_instance() argument
2780 list_for_each_entry(adv_instance, &hdev->adv_instances, list) { in hci_find_adv_instance()
2789 struct adv_info *hci_get_next_instance(struct hci_dev *hdev, u8 instance) in hci_get_next_instance() argument
2793 cur_instance = hci_find_adv_instance(hdev, instance); in hci_get_next_instance()
2797 if (cur_instance == list_last_entry(&hdev->adv_instances, in hci_get_next_instance()
2799 return list_first_entry(&hdev->adv_instances, in hci_get_next_instance()
2806 int hci_remove_adv_instance(struct hci_dev *hdev, u8 instance) in hci_remove_adv_instance() argument
2810 adv_instance = hci_find_adv_instance(hdev, instance); in hci_remove_adv_instance()
2814 BT_DBG("%s removing %dMR", hdev->name, instance); in hci_remove_adv_instance()
2816 if (hdev->cur_adv_instance == instance) { in hci_remove_adv_instance()
2817 if (hdev->adv_instance_timeout) { in hci_remove_adv_instance()
2818 cancel_delayed_work(&hdev->adv_instance_expire); in hci_remove_adv_instance()
2819 hdev->adv_instance_timeout = 0; in hci_remove_adv_instance()
2821 hdev->cur_adv_instance = 0x00; in hci_remove_adv_instance()
2829 hdev->adv_instance_cnt--; in hci_remove_adv_instance()
2834 void hci_adv_instances_set_rpa_expired(struct hci_dev *hdev, bool rpa_expired) in hci_adv_instances_set_rpa_expired() argument
2838 list_for_each_entry_safe(adv_instance, n, &hdev->adv_instances, list) in hci_adv_instances_set_rpa_expired()
2843 void hci_adv_instances_clear(struct hci_dev *hdev) in hci_adv_instances_clear() argument
2847 if (hdev->adv_instance_timeout) { in hci_adv_instances_clear()
2848 cancel_delayed_work(&hdev->adv_instance_expire); in hci_adv_instances_clear()
2849 hdev->adv_instance_timeout = 0; in hci_adv_instances_clear()
2852 list_for_each_entry_safe(adv_instance, n, &hdev->adv_instances, list) { in hci_adv_instances_clear()
2858 hdev->adv_instance_cnt = 0; in hci_adv_instances_clear()
2859 hdev->cur_adv_instance = 0x00; in hci_adv_instances_clear()
2873 int hci_add_adv_instance(struct hci_dev *hdev, u8 instance, u32 flags, in hci_add_adv_instance() argument
2881 adv_instance = hci_find_adv_instance(hdev, instance); in hci_add_adv_instance()
2888 if (hdev->adv_instance_cnt >= hdev->le_num_of_adv_sets || in hci_add_adv_instance()
2889 instance < 1 || instance > hdev->le_num_of_adv_sets) in hci_add_adv_instance()
2898 list_add(&adv_instance->list, &hdev->adv_instances); in hci_add_adv_instance()
2899 hdev->adv_instance_cnt++; in hci_add_adv_instance()
2920 adv_instance->duration = hdev->def_multi_adv_rotation_duration; in hci_add_adv_instance()
2927 BT_DBG("%s for %dMR", hdev->name, instance); in hci_add_adv_instance()
2933 int hci_set_adv_instance_data(struct hci_dev *hdev, u8 instance, in hci_set_adv_instance_data() argument
2939 adv_instance = hci_find_adv_instance(hdev, instance); in hci_set_adv_instance_data()
2964 u32 hci_adv_instance_flags(struct hci_dev *hdev, u8 instance) in hci_adv_instance_flags() argument
2978 if (hci_dev_test_flag(hdev, HCI_ADVERTISING_CONNECTABLE)) in hci_adv_instance_flags()
2981 if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) in hci_adv_instance_flags()
2983 else if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in hci_adv_instance_flags()
2989 adv = hci_find_adv_instance(hdev, instance); in hci_adv_instance_flags()
2998 bool hci_adv_instance_is_scannable(struct hci_dev *hdev, u8 instance) in hci_adv_instance_is_scannable() argument
3006 adv = hci_find_adv_instance(hdev, instance); in hci_adv_instance_is_scannable()
3018 void hci_adv_monitors_clear(struct hci_dev *hdev) in hci_adv_monitors_clear() argument
3023 idr_for_each_entry(&hdev->adv_monitors_idr, monitor, handle) in hci_adv_monitors_clear()
3024 hci_free_adv_monitor(hdev, monitor); in hci_adv_monitors_clear()
3026 idr_destroy(&hdev->adv_monitors_idr); in hci_adv_monitors_clear()
3032 void hci_free_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor) in hci_free_adv_monitor() argument
3046 idr_remove(&hdev->adv_monitors_idr, monitor->handle); in hci_free_adv_monitor()
3049 hdev->adv_monitors_cnt--; in hci_free_adv_monitor()
3050 mgmt_adv_monitor_removed(hdev, monitor->handle); in hci_free_adv_monitor()
3056 int hci_add_adv_patterns_monitor_complete(struct hci_dev *hdev, u8 status) in hci_add_adv_patterns_monitor_complete() argument
3058 return mgmt_add_adv_patterns_monitor_complete(hdev, status); in hci_add_adv_patterns_monitor_complete()
3061 int hci_remove_adv_monitor_complete(struct hci_dev *hdev, u8 status) in hci_remove_adv_monitor_complete() argument
3063 return mgmt_remove_adv_monitor_complete(hdev, status); in hci_remove_adv_monitor_complete()
3071 bool hci_add_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor, in hci_add_adv_monitor() argument
3085 handle = idr_alloc(&hdev->adv_monitors_idr, monitor, min, max, in hci_add_adv_monitor()
3094 if (!hdev_is_powered(hdev)) in hci_add_adv_monitor()
3097 switch (hci_get_adv_monitor_offload_ext(hdev)) { in hci_add_adv_monitor()
3099 hci_update_background_scan(hdev); in hci_add_adv_monitor()
3100 bt_dev_dbg(hdev, "%s add monitor status %d", hdev->name, *err); in hci_add_adv_monitor()
3104 *err = msft_add_monitor_pattern(hdev, monitor); in hci_add_adv_monitor()
3105 bt_dev_dbg(hdev, "%s add monitor msft status %d", hdev->name, in hci_add_adv_monitor()
3118 static bool hci_remove_adv_monitor(struct hci_dev *hdev, in hci_remove_adv_monitor() argument
3124 switch (hci_get_adv_monitor_offload_ext(hdev)) { in hci_remove_adv_monitor()
3128 *err = msft_remove_monitor(hdev, monitor, handle); in hci_remove_adv_monitor()
3140 bt_dev_warn(hdev, "Removing monitor with no matching handle %d", in hci_remove_adv_monitor()
3142 hci_free_adv_monitor(hdev, monitor); in hci_remove_adv_monitor()
3151 bool hci_remove_single_adv_monitor(struct hci_dev *hdev, u16 handle, int *err) in hci_remove_single_adv_monitor() argument
3153 struct adv_monitor *monitor = idr_find(&hdev->adv_monitors_idr, handle); in hci_remove_single_adv_monitor()
3161 pending = hci_remove_adv_monitor(hdev, monitor, handle, err); in hci_remove_single_adv_monitor()
3163 hci_update_background_scan(hdev); in hci_remove_single_adv_monitor()
3165 bt_dev_dbg(hdev, "%s remove monitor handle %d, status %d, %spending", in hci_remove_single_adv_monitor()
3166 hdev->name, handle, *err, pending ? "" : "not "); in hci_remove_single_adv_monitor()
3174 bool hci_remove_all_adv_monitor(struct hci_dev *hdev, int *err) in hci_remove_all_adv_monitor() argument
3184 monitor = idr_get_next(&hdev->adv_monitors_idr, &idr_next_id); in hci_remove_all_adv_monitor()
3188 pending = hci_remove_adv_monitor(hdev, monitor, 0, err); in hci_remove_all_adv_monitor()
3195 hci_update_background_scan(hdev); in hci_remove_all_adv_monitor()
3197 bt_dev_dbg(hdev, "%s remove all monitors status %d, %spending", in hci_remove_all_adv_monitor()
3198 hdev->name, *err, pending ? "" : "not "); in hci_remove_all_adv_monitor()
3204 bool hci_is_adv_monitoring(struct hci_dev *hdev) in hci_is_adv_monitoring() argument
3206 return !idr_is_empty(&hdev->adv_monitors_idr); in hci_is_adv_monitoring()
3209 int hci_get_adv_monitor_offload_ext(struct hci_dev *hdev) in hci_get_adv_monitor_offload_ext() argument
3211 if (msft_monitor_supported(hdev)) in hci_get_adv_monitor_offload_ext()
3403 struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev, in hci_conn_params_lookup() argument
3408 list_for_each_entry(params, &hdev->le_conn_params, list) { in hci_conn_params_lookup()
3434 struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev, in hci_conn_params_add() argument
3439 params = hci_conn_params_lookup(hdev, addr, addr_type); in hci_conn_params_add()
3445 bt_dev_err(hdev, "out of memory"); in hci_conn_params_add()
3452 list_add(¶ms->list, &hdev->le_conn_params); in hci_conn_params_add()
3455 params->conn_min_interval = hdev->le_conn_min_interval; in hci_conn_params_add()
3456 params->conn_max_interval = hdev->le_conn_max_interval; in hci_conn_params_add()
3457 params->conn_latency = hdev->le_conn_latency; in hci_conn_params_add()
3458 params->supervision_timeout = hdev->le_supv_timeout; in hci_conn_params_add()
3479 void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type) in hci_conn_params_del() argument
3483 params = hci_conn_params_lookup(hdev, addr, addr_type); in hci_conn_params_del()
3489 hci_update_background_scan(hdev); in hci_conn_params_del()
3495 void hci_conn_params_clear_disabled(struct hci_dev *hdev) in hci_conn_params_clear_disabled() argument
3499 list_for_each_entry_safe(params, tmp, &hdev->le_conn_params, list) { in hci_conn_params_clear_disabled()
3519 static void hci_conn_params_clear_all(struct hci_dev *hdev) in hci_conn_params_clear_all() argument
3523 list_for_each_entry_safe(params, tmp, &hdev->le_conn_params, list) in hci_conn_params_clear_all()
3542 void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_copy_identity_address() argument
3545 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in hci_copy_identity_address()
3546 !bacmp(&hdev->bdaddr, BDADDR_ANY) || in hci_copy_identity_address()
3547 (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in hci_copy_identity_address()
3548 bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_copy_identity_address()
3549 bacpy(bdaddr, &hdev->static_addr); in hci_copy_identity_address()
3552 bacpy(bdaddr, &hdev->bdaddr); in hci_copy_identity_address()
3557 static void hci_suspend_clear_tasks(struct hci_dev *hdev) in hci_suspend_clear_tasks() argument
3562 clear_bit(i, hdev->suspend_tasks); in hci_suspend_clear_tasks()
3564 wake_up(&hdev->suspend_wait_q); in hci_suspend_clear_tasks()
3567 static int hci_suspend_wait_event(struct hci_dev *hdev) in hci_suspend_wait_event() argument
3570 (find_first_bit(hdev->suspend_tasks, __SUSPEND_NUM_TASKS) == \ in hci_suspend_wait_event()
3574 int ret = wait_event_timeout(hdev->suspend_wait_q, in hci_suspend_wait_event()
3578 bt_dev_err(hdev, "Timed out waiting for suspend events"); in hci_suspend_wait_event()
3580 if (test_bit(i, hdev->suspend_tasks)) in hci_suspend_wait_event()
3581 bt_dev_err(hdev, "Suspend timeout bit: %d", i); in hci_suspend_wait_event()
3582 clear_bit(i, hdev->suspend_tasks); in hci_suspend_wait_event()
3595 struct hci_dev *hdev = in hci_prepare_suspend() local
3598 hci_dev_lock(hdev); in hci_prepare_suspend()
3599 hci_req_prepare_suspend(hdev, hdev->suspend_state_next); in hci_prepare_suspend()
3600 hci_dev_unlock(hdev); in hci_prepare_suspend()
3603 static int hci_change_suspend_state(struct hci_dev *hdev, in hci_change_suspend_state() argument
3606 hdev->suspend_state_next = next; in hci_change_suspend_state()
3607 set_bit(SUSPEND_PREPARE_NOTIFIER, hdev->suspend_tasks); in hci_change_suspend_state()
3608 queue_work(hdev->req_workqueue, &hdev->suspend_prepare); in hci_change_suspend_state()
3609 return hci_suspend_wait_event(hdev); in hci_change_suspend_state()
3612 static void hci_clear_wake_reason(struct hci_dev *hdev) in hci_clear_wake_reason() argument
3614 hci_dev_lock(hdev); in hci_clear_wake_reason()
3616 hdev->wake_reason = 0; in hci_clear_wake_reason()
3617 bacpy(&hdev->wake_addr, BDADDR_ANY); in hci_clear_wake_reason()
3618 hdev->wake_addr_type = 0; in hci_clear_wake_reason()
3620 hci_dev_unlock(hdev); in hci_clear_wake_reason()
3626 struct hci_dev *hdev = in hci_suspend_notifier() local
3631 ret = hci_suspend_dev(hdev); in hci_suspend_notifier()
3633 ret = hci_resume_dev(hdev); in hci_suspend_notifier()
3636 bt_dev_err(hdev, "Suspend notifier action (%lu) failed: %d", in hci_suspend_notifier()
3645 struct hci_dev *hdev; in hci_alloc_dev_priv() local
3648 alloc_size = sizeof(*hdev); in hci_alloc_dev_priv()
3654 hdev = kzalloc(alloc_size, GFP_KERNEL); in hci_alloc_dev_priv()
3655 if (!hdev) in hci_alloc_dev_priv()
3658 hdev->pkt_type = (HCI_DM1 | HCI_DH1 | HCI_HV1); in hci_alloc_dev_priv()
3659 hdev->esco_type = (ESCO_HV1); in hci_alloc_dev_priv()
3660 hdev->link_mode = (HCI_LM_ACCEPT); in hci_alloc_dev_priv()
3661 hdev->num_iac = 0x01; /* One IAC support is mandatory */ in hci_alloc_dev_priv()
3662 hdev->io_capability = 0x03; /* No Input No Output */ in hci_alloc_dev_priv()
3663 hdev->manufacturer = 0xffff; /* Default to internal use */ in hci_alloc_dev_priv()
3664 hdev->inq_tx_power = HCI_TX_POWER_INVALID; in hci_alloc_dev_priv()
3665 hdev->adv_tx_power = HCI_TX_POWER_INVALID; in hci_alloc_dev_priv()
3666 hdev->adv_instance_cnt = 0; in hci_alloc_dev_priv()
3667 hdev->cur_adv_instance = 0x00; in hci_alloc_dev_priv()
3668 hdev->adv_instance_timeout = 0; in hci_alloc_dev_priv()
3670 hdev->advmon_allowlist_duration = 300; in hci_alloc_dev_priv()
3671 hdev->advmon_no_filter_duration = 500; in hci_alloc_dev_priv()
3672 hdev->enable_advmon_interleave_scan = 0x00; /* Default to disable */ in hci_alloc_dev_priv()
3674 hdev->sniff_max_interval = 800; in hci_alloc_dev_priv()
3675 hdev->sniff_min_interval = 80; in hci_alloc_dev_priv()
3677 hdev->le_adv_channel_map = 0x07; in hci_alloc_dev_priv()
3678 hdev->le_adv_min_interval = 0x0800; in hci_alloc_dev_priv()
3679 hdev->le_adv_max_interval = 0x0800; in hci_alloc_dev_priv()
3680 hdev->le_scan_interval = 0x0060; in hci_alloc_dev_priv()
3681 hdev->le_scan_window = 0x0030; in hci_alloc_dev_priv()
3682 hdev->le_scan_int_suspend = 0x0400; in hci_alloc_dev_priv()
3683 hdev->le_scan_window_suspend = 0x0012; in hci_alloc_dev_priv()
3684 hdev->le_scan_int_discovery = DISCOV_LE_SCAN_INT; in hci_alloc_dev_priv()
3685 hdev->le_scan_window_discovery = DISCOV_LE_SCAN_WIN; in hci_alloc_dev_priv()
3686 hdev->le_scan_int_adv_monitor = 0x0060; in hci_alloc_dev_priv()
3687 hdev->le_scan_window_adv_monitor = 0x0030; in hci_alloc_dev_priv()
3688 hdev->le_scan_int_connect = 0x0060; in hci_alloc_dev_priv()
3689 hdev->le_scan_window_connect = 0x0060; in hci_alloc_dev_priv()
3690 hdev->le_conn_min_interval = 0x0018; in hci_alloc_dev_priv()
3691 hdev->le_conn_max_interval = 0x0028; in hci_alloc_dev_priv()
3692 hdev->le_conn_latency = 0x0000; in hci_alloc_dev_priv()
3693 hdev->le_supv_timeout = 0x002a; in hci_alloc_dev_priv()
3694 hdev->le_def_tx_len = 0x001b; in hci_alloc_dev_priv()
3695 hdev->le_def_tx_time = 0x0148; in hci_alloc_dev_priv()
3696 hdev->le_max_tx_len = 0x001b; in hci_alloc_dev_priv()
3697 hdev->le_max_tx_time = 0x0148; in hci_alloc_dev_priv()
3698 hdev->le_max_rx_len = 0x001b; in hci_alloc_dev_priv()
3699 hdev->le_max_rx_time = 0x0148; in hci_alloc_dev_priv()
3700 hdev->le_max_key_size = SMP_MAX_ENC_KEY_SIZE; in hci_alloc_dev_priv()
3701 hdev->le_min_key_size = SMP_MIN_ENC_KEY_SIZE; in hci_alloc_dev_priv()
3702 hdev->le_tx_def_phys = HCI_LE_SET_PHY_1M; in hci_alloc_dev_priv()
3703 hdev->le_rx_def_phys = HCI_LE_SET_PHY_1M; in hci_alloc_dev_priv()
3704 hdev->le_num_of_adv_sets = HCI_MAX_ADV_INSTANCES; in hci_alloc_dev_priv()
3705 hdev->def_multi_adv_rotation_duration = HCI_DEFAULT_ADV_DURATION; in hci_alloc_dev_priv()
3706 hdev->def_le_autoconnect_timeout = HCI_LE_AUTOCONN_TIMEOUT; in hci_alloc_dev_priv()
3707 hdev->min_le_tx_power = HCI_TX_POWER_INVALID; in hci_alloc_dev_priv()
3708 hdev->max_le_tx_power = HCI_TX_POWER_INVALID; in hci_alloc_dev_priv()
3710 hdev->rpa_timeout = HCI_DEFAULT_RPA_TIMEOUT; in hci_alloc_dev_priv()
3711 hdev->discov_interleaved_timeout = DISCOV_INTERLEAVED_TIMEOUT; in hci_alloc_dev_priv()
3712 hdev->conn_info_min_age = DEFAULT_CONN_INFO_MIN_AGE; in hci_alloc_dev_priv()
3713 hdev->conn_info_max_age = DEFAULT_CONN_INFO_MAX_AGE; in hci_alloc_dev_priv()
3714 hdev->auth_payload_timeout = DEFAULT_AUTH_PAYLOAD_TIMEOUT; in hci_alloc_dev_priv()
3715 hdev->min_enc_key_size = HCI_MIN_ENC_KEY_SIZE; in hci_alloc_dev_priv()
3718 hdev->def_page_scan_type = PAGE_SCAN_TYPE_STANDARD; in hci_alloc_dev_priv()
3719 hdev->def_page_scan_int = 0x0800; in hci_alloc_dev_priv()
3720 hdev->def_page_scan_window = 0x0012; in hci_alloc_dev_priv()
3722 mutex_init(&hdev->lock); in hci_alloc_dev_priv()
3723 mutex_init(&hdev->req_lock); in hci_alloc_dev_priv()
3725 INIT_LIST_HEAD(&hdev->mgmt_pending); in hci_alloc_dev_priv()
3726 INIT_LIST_HEAD(&hdev->reject_list); in hci_alloc_dev_priv()
3727 INIT_LIST_HEAD(&hdev->accept_list); in hci_alloc_dev_priv()
3728 INIT_LIST_HEAD(&hdev->uuids); in hci_alloc_dev_priv()
3729 INIT_LIST_HEAD(&hdev->link_keys); in hci_alloc_dev_priv()
3730 INIT_LIST_HEAD(&hdev->long_term_keys); in hci_alloc_dev_priv()
3731 INIT_LIST_HEAD(&hdev->identity_resolving_keys); in hci_alloc_dev_priv()
3732 INIT_LIST_HEAD(&hdev->remote_oob_data); in hci_alloc_dev_priv()
3733 INIT_LIST_HEAD(&hdev->le_accept_list); in hci_alloc_dev_priv()
3734 INIT_LIST_HEAD(&hdev->le_resolv_list); in hci_alloc_dev_priv()
3735 INIT_LIST_HEAD(&hdev->le_conn_params); in hci_alloc_dev_priv()
3736 INIT_LIST_HEAD(&hdev->pend_le_conns); in hci_alloc_dev_priv()
3737 INIT_LIST_HEAD(&hdev->pend_le_reports); in hci_alloc_dev_priv()
3738 INIT_LIST_HEAD(&hdev->conn_hash.list); in hci_alloc_dev_priv()
3739 INIT_LIST_HEAD(&hdev->adv_instances); in hci_alloc_dev_priv()
3740 INIT_LIST_HEAD(&hdev->blocked_keys); in hci_alloc_dev_priv()
3742 INIT_LIST_HEAD(&hdev->local_codecs); in hci_alloc_dev_priv()
3743 INIT_WORK(&hdev->rx_work, hci_rx_work); in hci_alloc_dev_priv()
3744 INIT_WORK(&hdev->cmd_work, hci_cmd_work); in hci_alloc_dev_priv()
3745 INIT_WORK(&hdev->tx_work, hci_tx_work); in hci_alloc_dev_priv()
3746 INIT_WORK(&hdev->power_on, hci_power_on); in hci_alloc_dev_priv()
3747 INIT_WORK(&hdev->error_reset, hci_error_reset); in hci_alloc_dev_priv()
3748 INIT_WORK(&hdev->suspend_prepare, hci_prepare_suspend); in hci_alloc_dev_priv()
3750 INIT_DELAYED_WORK(&hdev->power_off, hci_power_off); in hci_alloc_dev_priv()
3752 skb_queue_head_init(&hdev->rx_q); in hci_alloc_dev_priv()
3753 skb_queue_head_init(&hdev->cmd_q); in hci_alloc_dev_priv()
3754 skb_queue_head_init(&hdev->raw_q); in hci_alloc_dev_priv()
3756 init_waitqueue_head(&hdev->req_wait_q); in hci_alloc_dev_priv()
3757 init_waitqueue_head(&hdev->suspend_wait_q); in hci_alloc_dev_priv()
3759 INIT_DELAYED_WORK(&hdev->cmd_timer, hci_cmd_timeout); in hci_alloc_dev_priv()
3760 INIT_DELAYED_WORK(&hdev->ncmd_timer, hci_ncmd_timeout); in hci_alloc_dev_priv()
3762 hci_request_setup(hdev); in hci_alloc_dev_priv()
3764 hci_init_sysfs(hdev); in hci_alloc_dev_priv()
3765 discovery_init(hdev); in hci_alloc_dev_priv()
3767 return hdev; in hci_alloc_dev_priv()
3772 void hci_free_dev(struct hci_dev *hdev) in hci_free_dev() argument
3775 put_device(&hdev->dev); in hci_free_dev()
3780 int hci_register_dev(struct hci_dev *hdev) in hci_register_dev() argument
3784 if (!hdev->open || !hdev->close || !hdev->send) in hci_register_dev()
3790 switch (hdev->dev_type) { in hci_register_dev()
3804 sprintf(hdev->name, "hci%d", id); in hci_register_dev()
3805 hdev->id = id; in hci_register_dev()
3807 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus); in hci_register_dev()
3809 hdev->workqueue = alloc_ordered_workqueue("%s", WQ_HIGHPRI, hdev->name); in hci_register_dev()
3810 if (!hdev->workqueue) { in hci_register_dev()
3815 hdev->req_workqueue = alloc_ordered_workqueue("%s", WQ_HIGHPRI, in hci_register_dev()
3816 hdev->name); in hci_register_dev()
3817 if (!hdev->req_workqueue) { in hci_register_dev()
3818 destroy_workqueue(hdev->workqueue); in hci_register_dev()
3824 hdev->debugfs = debugfs_create_dir(hdev->name, bt_debugfs); in hci_register_dev()
3826 dev_set_name(&hdev->dev, "%s", hdev->name); in hci_register_dev()
3828 error = device_add(&hdev->dev); in hci_register_dev()
3832 hci_leds_init(hdev); in hci_register_dev()
3834 hdev->rfkill = rfkill_alloc(hdev->name, &hdev->dev, in hci_register_dev()
3836 hdev); in hci_register_dev()
3837 if (hdev->rfkill) { in hci_register_dev()
3838 if (rfkill_register(hdev->rfkill) < 0) { in hci_register_dev()
3839 rfkill_destroy(hdev->rfkill); in hci_register_dev()
3840 hdev->rfkill = NULL; in hci_register_dev()
3844 if (hdev->rfkill && rfkill_blocked(hdev->rfkill)) in hci_register_dev()
3845 hci_dev_set_flag(hdev, HCI_RFKILLED); in hci_register_dev()
3847 hci_dev_set_flag(hdev, HCI_SETUP); in hci_register_dev()
3848 hci_dev_set_flag(hdev, HCI_AUTO_OFF); in hci_register_dev()
3850 if (hdev->dev_type == HCI_PRIMARY) { in hci_register_dev()
3854 hci_dev_set_flag(hdev, HCI_BREDR_ENABLED); in hci_register_dev()
3858 list_add(&hdev->list, &hci_dev_list); in hci_register_dev()
3864 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in hci_register_dev()
3865 hci_dev_set_flag(hdev, HCI_UNCONFIGURED); in hci_register_dev()
3867 hci_sock_dev_event(hdev, HCI_DEV_REG); in hci_register_dev()
3868 hci_dev_hold(hdev); in hci_register_dev()
3870 if (!test_bit(HCI_QUIRK_NO_SUSPEND_NOTIFIER, &hdev->quirks)) { in hci_register_dev()
3871 hdev->suspend_notifier.notifier_call = hci_suspend_notifier; in hci_register_dev()
3872 error = register_pm_notifier(&hdev->suspend_notifier); in hci_register_dev()
3877 queue_work(hdev->req_workqueue, &hdev->power_on); in hci_register_dev()
3879 idr_init(&hdev->adv_monitors_idr); in hci_register_dev()
3880 msft_register(hdev); in hci_register_dev()
3885 destroy_workqueue(hdev->workqueue); in hci_register_dev()
3886 destroy_workqueue(hdev->req_workqueue); in hci_register_dev()
3888 ida_simple_remove(&hci_index_ida, hdev->id); in hci_register_dev()
3895 void hci_unregister_dev(struct hci_dev *hdev) in hci_unregister_dev() argument
3897 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus); in hci_unregister_dev()
3899 hci_dev_set_flag(hdev, HCI_UNREGISTER); in hci_unregister_dev()
3902 list_del(&hdev->list); in hci_unregister_dev()
3905 cancel_work_sync(&hdev->power_on); in hci_unregister_dev()
3907 if (!test_bit(HCI_QUIRK_NO_SUSPEND_NOTIFIER, &hdev->quirks)) { in hci_unregister_dev()
3908 hci_suspend_clear_tasks(hdev); in hci_unregister_dev()
3909 unregister_pm_notifier(&hdev->suspend_notifier); in hci_unregister_dev()
3910 cancel_work_sync(&hdev->suspend_prepare); in hci_unregister_dev()
3913 msft_unregister(hdev); in hci_unregister_dev()
3915 hci_dev_do_close(hdev); in hci_unregister_dev()
3917 if (!test_bit(HCI_INIT, &hdev->flags) && in hci_unregister_dev()
3918 !hci_dev_test_flag(hdev, HCI_SETUP) && in hci_unregister_dev()
3919 !hci_dev_test_flag(hdev, HCI_CONFIG)) { in hci_unregister_dev()
3920 hci_dev_lock(hdev); in hci_unregister_dev()
3921 mgmt_index_removed(hdev); in hci_unregister_dev()
3922 hci_dev_unlock(hdev); in hci_unregister_dev()
3927 BUG_ON(!list_empty(&hdev->mgmt_pending)); in hci_unregister_dev()
3929 hci_sock_dev_event(hdev, HCI_DEV_UNREG); in hci_unregister_dev()
3931 if (hdev->rfkill) { in hci_unregister_dev()
3932 rfkill_unregister(hdev->rfkill); in hci_unregister_dev()
3933 rfkill_destroy(hdev->rfkill); in hci_unregister_dev()
3936 device_del(&hdev->dev); in hci_unregister_dev()
3938 hci_dev_put(hdev); in hci_unregister_dev()
3943 void hci_release_dev(struct hci_dev *hdev) in hci_release_dev() argument
3945 debugfs_remove_recursive(hdev->debugfs); in hci_release_dev()
3946 kfree_const(hdev->hw_info); in hci_release_dev()
3947 kfree_const(hdev->fw_info); in hci_release_dev()
3949 destroy_workqueue(hdev->workqueue); in hci_release_dev()
3950 destroy_workqueue(hdev->req_workqueue); in hci_release_dev()
3952 hci_dev_lock(hdev); in hci_release_dev()
3953 hci_bdaddr_list_clear(&hdev->reject_list); in hci_release_dev()
3954 hci_bdaddr_list_clear(&hdev->accept_list); in hci_release_dev()
3955 hci_uuids_clear(hdev); in hci_release_dev()
3956 hci_link_keys_clear(hdev); in hci_release_dev()
3957 hci_smp_ltks_clear(hdev); in hci_release_dev()
3958 hci_smp_irks_clear(hdev); in hci_release_dev()
3959 hci_remote_oob_data_clear(hdev); in hci_release_dev()
3960 hci_adv_instances_clear(hdev); in hci_release_dev()
3961 hci_adv_monitors_clear(hdev); in hci_release_dev()
3962 hci_bdaddr_list_clear(&hdev->le_accept_list); in hci_release_dev()
3963 hci_bdaddr_list_clear(&hdev->le_resolv_list); in hci_release_dev()
3964 hci_conn_params_clear_all(hdev); in hci_release_dev()
3965 hci_discovery_filter_clear(hdev); in hci_release_dev()
3966 hci_blocked_keys_clear(hdev); in hci_release_dev()
3967 hci_dev_unlock(hdev); in hci_release_dev()
3969 ida_simple_remove(&hci_index_ida, hdev->id); in hci_release_dev()
3970 kfree(hdev); in hci_release_dev()
3975 int hci_suspend_dev(struct hci_dev *hdev) in hci_suspend_dev() argument
3980 bt_dev_dbg(hdev, ""); in hci_suspend_dev()
3983 if (!hdev_is_powered(hdev) || in hci_suspend_dev()
3984 hci_dev_test_flag(hdev, HCI_UNREGISTER)) in hci_suspend_dev()
3988 if (mgmt_powering_down(hdev)) { in hci_suspend_dev()
3989 set_bit(SUSPEND_POWERING_DOWN, hdev->suspend_tasks); in hci_suspend_dev()
3990 ret = hci_suspend_wait_event(hdev); in hci_suspend_dev()
4000 ret = hci_change_suspend_state(hdev, BT_SUSPEND_DISCONNECT); in hci_suspend_dev()
4007 if (hdev->wakeup && hdev->wakeup(hdev)) { in hci_suspend_dev()
4008 ret = hci_change_suspend_state(hdev, BT_SUSPEND_CONFIGURE_WAKE); in hci_suspend_dev()
4014 hci_clear_wake_reason(hdev); in hci_suspend_dev()
4015 mgmt_suspending(hdev, state); in hci_suspend_dev()
4021 hci_sock_dev_event(hdev, HCI_DEV_SUSPEND); in hci_suspend_dev()
4027 int hci_resume_dev(struct hci_dev *hdev) in hci_resume_dev() argument
4031 bt_dev_dbg(hdev, ""); in hci_resume_dev()
4034 if (!hdev_is_powered(hdev) || in hci_resume_dev()
4035 hci_dev_test_flag(hdev, HCI_UNREGISTER)) in hci_resume_dev()
4039 if (mgmt_powering_down(hdev)) in hci_resume_dev()
4042 ret = hci_change_suspend_state(hdev, BT_RUNNING); in hci_resume_dev()
4044 mgmt_resuming(hdev, hdev->wake_reason, &hdev->wake_addr, in hci_resume_dev()
4045 hdev->wake_addr_type); in hci_resume_dev()
4047 hci_sock_dev_event(hdev, HCI_DEV_RESUME); in hci_resume_dev()
4053 int hci_reset_dev(struct hci_dev *hdev) in hci_reset_dev() argument
4065 bt_dev_err(hdev, "Injecting HCI hardware error event"); in hci_reset_dev()
4068 return hci_recv_frame(hdev, skb); in hci_reset_dev()
4073 int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb) in hci_recv_frame() argument
4075 if (!hdev || (!test_bit(HCI_UP, &hdev->flags) in hci_recv_frame()
4076 && !test_bit(HCI_INIT, &hdev->flags))) { in hci_recv_frame()
4095 skb_queue_tail(&hdev->rx_q, skb); in hci_recv_frame()
4096 queue_work(hdev->workqueue, &hdev->rx_work); in hci_recv_frame()
4103 int hci_recv_diag(struct hci_dev *hdev, struct sk_buff *skb) in hci_recv_diag() argument
4111 skb_queue_tail(&hdev->rx_q, skb); in hci_recv_diag()
4112 queue_work(hdev->workqueue, &hdev->rx_work); in hci_recv_diag()
4118 void hci_set_hw_info(struct hci_dev *hdev, const char *fmt, ...) in hci_set_hw_info() argument
4123 kfree_const(hdev->hw_info); in hci_set_hw_info()
4124 hdev->hw_info = kvasprintf_const(GFP_KERNEL, fmt, vargs); in hci_set_hw_info()
4129 void hci_set_fw_info(struct hci_dev *hdev, const char *fmt, ...) in hci_set_fw_info() argument
4134 kfree_const(hdev->fw_info); in hci_set_fw_info()
4135 hdev->fw_info = kvasprintf_const(GFP_KERNEL, fmt, vargs); in hci_set_fw_info()
4166 static void hci_send_frame(struct hci_dev *hdev, struct sk_buff *skb) in hci_send_frame() argument
4170 BT_DBG("%s type %d len %d", hdev->name, hci_skb_pkt_type(skb), in hci_send_frame()
4177 hci_send_to_monitor(hdev, skb); in hci_send_frame()
4179 if (atomic_read(&hdev->promisc)) { in hci_send_frame()
4181 hci_send_to_sock(hdev, skb); in hci_send_frame()
4187 if (!test_bit(HCI_RUNNING, &hdev->flags)) { in hci_send_frame()
4192 err = hdev->send(hdev, skb); in hci_send_frame()
4194 bt_dev_err(hdev, "sending frame failed (%d)", err); in hci_send_frame()
4200 int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, in hci_send_cmd() argument
4205 BT_DBG("%s opcode 0x%4.4x plen %d", hdev->name, opcode, plen); in hci_send_cmd()
4207 skb = hci_prepare_cmd(hdev, opcode, plen, param); in hci_send_cmd()
4209 bt_dev_err(hdev, "no memory for command"); in hci_send_cmd()
4218 skb_queue_tail(&hdev->cmd_q, skb); in hci_send_cmd()
4219 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_send_cmd()
4224 int __hci_cmd_send(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_send() argument
4238 bt_dev_err(hdev, "unresponded command not supported"); in __hci_cmd_send()
4242 skb = hci_prepare_cmd(hdev, opcode, plen, param); in __hci_cmd_send()
4244 bt_dev_err(hdev, "no memory for command (opcode 0x%4.4x)", in __hci_cmd_send()
4249 hci_send_frame(hdev, skb); in __hci_cmd_send()
4256 void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode) in hci_sent_cmd_data() argument
4260 if (!hdev->sent_cmd) in hci_sent_cmd_data()
4263 hdr = (void *) hdev->sent_cmd->data; in hci_sent_cmd_data()
4268 BT_DBG("%s opcode 0x%4.4x", hdev->name, opcode); in hci_sent_cmd_data()
4270 return hdev->sent_cmd->data + HCI_COMMAND_HDR_SIZE; in hci_sent_cmd_data()
4274 struct sk_buff *hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen, in hci_cmd_sync() argument
4279 if (!test_bit(HCI_UP, &hdev->flags)) in hci_cmd_sync()
4282 bt_dev_dbg(hdev, "opcode 0x%4.4x plen %d", opcode, plen); in hci_cmd_sync()
4284 hci_req_sync_lock(hdev); in hci_cmd_sync()
4285 skb = __hci_cmd_sync(hdev, opcode, plen, param, timeout); in hci_cmd_sync()
4286 hci_req_sync_unlock(hdev); in hci_cmd_sync()
4309 struct hci_dev *hdev = conn->hdev; in hci_queue_acl() local
4317 switch (hdev->dev_type) { in hci_queue_acl()
4325 bt_dev_err(hdev, "unknown dev_type %d", hdev->dev_type); in hci_queue_acl()
4332 BT_DBG("%s nonfrag skb %p len %d", hdev->name, skb, skb->len); in hci_queue_acl()
4337 BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len); in hci_queue_acl()
4358 BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len); in hci_queue_acl()
4369 struct hci_dev *hdev = chan->conn->hdev; in hci_send_acl() local
4371 BT_DBG("%s chan %p flags 0x%4.4x", hdev->name, chan, flags); in hci_send_acl()
4375 queue_work(hdev->workqueue, &hdev->tx_work); in hci_send_acl()
4381 struct hci_dev *hdev = conn->hdev; in hci_send_sco() local
4384 BT_DBG("%s len %d", hdev->name, skb->len); in hci_send_sco()
4396 queue_work(hdev->workqueue, &hdev->tx_work); in hci_send_sco()
4402 static struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type, in hci_low_sent() argument
4405 struct hci_conn_hash *h = &hdev->conn_hash; in hci_low_sent()
4428 if (hci_conn_num(hdev, type) == num) in hci_low_sent()
4439 cnt = hdev->acl_cnt; in hci_low_sent()
4443 cnt = hdev->sco_cnt; in hci_low_sent()
4446 cnt = hdev->le_mtu ? hdev->le_cnt : hdev->acl_cnt; in hci_low_sent()
4450 bt_dev_err(hdev, "unknown link type %d", conn->type); in hci_low_sent()
4462 static void hci_link_tx_to(struct hci_dev *hdev, __u8 type) in hci_link_tx_to() argument
4464 struct hci_conn_hash *h = &hdev->conn_hash; in hci_link_tx_to()
4467 bt_dev_err(hdev, "link tx timeout"); in hci_link_tx_to()
4474 bt_dev_err(hdev, "killing stalled connection %pMR", in hci_link_tx_to()
4483 static struct hci_chan *hci_chan_sent(struct hci_dev *hdev, __u8 type, in hci_chan_sent() argument
4486 struct hci_conn_hash *h = &hdev->conn_hash; in hci_chan_sent()
4492 BT_DBG("%s", hdev->name); in hci_chan_sent()
4531 if (hci_conn_num(hdev, type) == conn_num) in hci_chan_sent()
4542 cnt = hdev->acl_cnt; in hci_chan_sent()
4545 cnt = hdev->block_cnt; in hci_chan_sent()
4549 cnt = hdev->sco_cnt; in hci_chan_sent()
4552 cnt = hdev->le_mtu ? hdev->le_cnt : hdev->acl_cnt; in hci_chan_sent()
4556 bt_dev_err(hdev, "unknown link type %d", chan->conn->type); in hci_chan_sent()
4565 static void hci_prio_recalculate(struct hci_dev *hdev, __u8 type) in hci_prio_recalculate() argument
4567 struct hci_conn_hash *h = &hdev->conn_hash; in hci_prio_recalculate()
4571 BT_DBG("%s", hdev->name); in hci_prio_recalculate()
4607 if (hci_conn_num(hdev, type) == num) in hci_prio_recalculate()
4615 static inline int __get_blocks(struct hci_dev *hdev, struct sk_buff *skb) in __get_blocks() argument
4618 return DIV_ROUND_UP(skb->len - HCI_ACL_HDR_SIZE, hdev->block_len); in __get_blocks()
4621 static void __check_timeout(struct hci_dev *hdev, unsigned int cnt) in __check_timeout() argument
4623 if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in __check_timeout()
4626 if (!cnt && time_after(jiffies, hdev->acl_last_tx + in __check_timeout()
4628 hci_link_tx_to(hdev, ACL_LINK); in __check_timeout()
4633 static void hci_sched_sco(struct hci_dev *hdev) in hci_sched_sco() argument
4639 BT_DBG("%s", hdev->name); in hci_sched_sco()
4641 if (!hci_conn_num(hdev, SCO_LINK)) in hci_sched_sco()
4644 while (hdev->sco_cnt && (conn = hci_low_sent(hdev, SCO_LINK, "e))) { in hci_sched_sco()
4647 hci_send_frame(hdev, skb); in hci_sched_sco()
4656 static void hci_sched_esco(struct hci_dev *hdev) in hci_sched_esco() argument
4662 BT_DBG("%s", hdev->name); in hci_sched_esco()
4664 if (!hci_conn_num(hdev, ESCO_LINK)) in hci_sched_esco()
4667 while (hdev->sco_cnt && (conn = hci_low_sent(hdev, ESCO_LINK, in hci_sched_esco()
4671 hci_send_frame(hdev, skb); in hci_sched_esco()
4680 static void hci_sched_acl_pkt(struct hci_dev *hdev) in hci_sched_acl_pkt() argument
4682 unsigned int cnt = hdev->acl_cnt; in hci_sched_acl_pkt()
4687 __check_timeout(hdev, cnt); in hci_sched_acl_pkt()
4689 while (hdev->acl_cnt && in hci_sched_acl_pkt()
4690 (chan = hci_chan_sent(hdev, ACL_LINK, "e))) { in hci_sched_acl_pkt()
4705 hci_send_frame(hdev, skb); in hci_sched_acl_pkt()
4706 hdev->acl_last_tx = jiffies; in hci_sched_acl_pkt()
4708 hdev->acl_cnt--; in hci_sched_acl_pkt()
4713 hci_sched_sco(hdev); in hci_sched_acl_pkt()
4714 hci_sched_esco(hdev); in hci_sched_acl_pkt()
4718 if (cnt != hdev->acl_cnt) in hci_sched_acl_pkt()
4719 hci_prio_recalculate(hdev, ACL_LINK); in hci_sched_acl_pkt()
4722 static void hci_sched_acl_blk(struct hci_dev *hdev) in hci_sched_acl_blk() argument
4724 unsigned int cnt = hdev->block_cnt; in hci_sched_acl_blk()
4730 __check_timeout(hdev, cnt); in hci_sched_acl_blk()
4732 BT_DBG("%s", hdev->name); in hci_sched_acl_blk()
4734 if (hdev->dev_type == HCI_AMP) in hci_sched_acl_blk()
4739 while (hdev->block_cnt > 0 && in hci_sched_acl_blk()
4740 (chan = hci_chan_sent(hdev, type, "e))) { in hci_sched_acl_blk()
4754 blocks = __get_blocks(hdev, skb); in hci_sched_acl_blk()
4755 if (blocks > hdev->block_cnt) in hci_sched_acl_blk()
4761 hci_send_frame(hdev, skb); in hci_sched_acl_blk()
4762 hdev->acl_last_tx = jiffies; in hci_sched_acl_blk()
4764 hdev->block_cnt -= blocks; in hci_sched_acl_blk()
4772 if (cnt != hdev->block_cnt) in hci_sched_acl_blk()
4773 hci_prio_recalculate(hdev, type); in hci_sched_acl_blk()
4776 static void hci_sched_acl(struct hci_dev *hdev) in hci_sched_acl() argument
4778 BT_DBG("%s", hdev->name); in hci_sched_acl()
4781 if (!hci_conn_num(hdev, ACL_LINK) && hdev->dev_type == HCI_PRIMARY) in hci_sched_acl()
4785 if (!hci_conn_num(hdev, AMP_LINK) && hdev->dev_type == HCI_AMP) in hci_sched_acl()
4788 switch (hdev->flow_ctl_mode) { in hci_sched_acl()
4790 hci_sched_acl_pkt(hdev); in hci_sched_acl()
4794 hci_sched_acl_blk(hdev); in hci_sched_acl()
4799 static void hci_sched_le(struct hci_dev *hdev) in hci_sched_le() argument
4805 BT_DBG("%s", hdev->name); in hci_sched_le()
4807 if (!hci_conn_num(hdev, LE_LINK)) in hci_sched_le()
4810 cnt = hdev->le_pkts ? hdev->le_cnt : hdev->acl_cnt; in hci_sched_le()
4812 __check_timeout(hdev, cnt); in hci_sched_le()
4815 while (cnt && (chan = hci_chan_sent(hdev, LE_LINK, "e))) { in hci_sched_le()
4827 hci_send_frame(hdev, skb); in hci_sched_le()
4828 hdev->le_last_tx = jiffies; in hci_sched_le()
4835 hci_sched_sco(hdev); in hci_sched_le()
4836 hci_sched_esco(hdev); in hci_sched_le()
4840 if (hdev->le_pkts) in hci_sched_le()
4841 hdev->le_cnt = cnt; in hci_sched_le()
4843 hdev->acl_cnt = cnt; in hci_sched_le()
4846 hci_prio_recalculate(hdev, LE_LINK); in hci_sched_le()
4851 struct hci_dev *hdev = container_of(work, struct hci_dev, tx_work); in hci_tx_work() local
4854 BT_DBG("%s acl %d sco %d le %d", hdev->name, hdev->acl_cnt, in hci_tx_work()
4855 hdev->sco_cnt, hdev->le_cnt); in hci_tx_work()
4857 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_tx_work()
4859 hci_sched_sco(hdev); in hci_tx_work()
4860 hci_sched_esco(hdev); in hci_tx_work()
4861 hci_sched_acl(hdev); in hci_tx_work()
4862 hci_sched_le(hdev); in hci_tx_work()
4866 while ((skb = skb_dequeue(&hdev->raw_q))) in hci_tx_work()
4867 hci_send_frame(hdev, skb); in hci_tx_work()
4873 static void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb) in hci_acldata_packet() argument
4885 BT_DBG("%s len %d handle 0x%4.4x flags 0x%4.4x", hdev->name, skb->len, in hci_acldata_packet()
4888 hdev->stat.acl_rx++; in hci_acldata_packet()
4890 hci_dev_lock(hdev); in hci_acldata_packet()
4891 conn = hci_conn_hash_lookup_handle(hdev, handle); in hci_acldata_packet()
4892 hci_dev_unlock(hdev); in hci_acldata_packet()
4901 bt_dev_err(hdev, "ACL packet for unknown connection handle %d", in hci_acldata_packet()
4909 static void hci_scodata_packet(struct hci_dev *hdev, struct sk_buff *skb) in hci_scodata_packet() argument
4921 BT_DBG("%s len %d handle 0x%4.4x flags 0x%4.4x", hdev->name, skb->len, in hci_scodata_packet()
4924 hdev->stat.sco_rx++; in hci_scodata_packet()
4926 hci_dev_lock(hdev); in hci_scodata_packet()
4927 conn = hci_conn_hash_lookup_handle(hdev, handle); in hci_scodata_packet()
4928 hci_dev_unlock(hdev); in hci_scodata_packet()
4936 bt_dev_err(hdev, "SCO packet for unknown connection handle %d", in hci_scodata_packet()
4943 static bool hci_req_is_complete(struct hci_dev *hdev) in hci_req_is_complete() argument
4947 skb = skb_peek(&hdev->cmd_q); in hci_req_is_complete()
4954 static void hci_resend_last(struct hci_dev *hdev) in hci_resend_last() argument
4960 if (!hdev->sent_cmd) in hci_resend_last()
4963 sent = (void *) hdev->sent_cmd->data; in hci_resend_last()
4968 skb = skb_clone(hdev->sent_cmd, GFP_KERNEL); in hci_resend_last()
4972 skb_queue_head(&hdev->cmd_q, skb); in hci_resend_last()
4973 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_resend_last()
4976 void hci_req_cmd_complete(struct hci_dev *hdev, u16 opcode, u8 status, in hci_req_cmd_complete() argument
4988 if (!hci_sent_cmd_data(hdev, opcode)) { in hci_req_cmd_complete()
4995 if (test_bit(HCI_INIT, &hdev->flags) && opcode == HCI_OP_RESET) in hci_req_cmd_complete()
4996 hci_resend_last(hdev); in hci_req_cmd_complete()
5002 hci_dev_clear_flag(hdev, HCI_CMD_PENDING); in hci_req_cmd_complete()
5007 if (!status && !hci_req_is_complete(hdev)) in hci_req_cmd_complete()
5014 if (bt_cb(hdev->sent_cmd)->hci.req_flags & HCI_REQ_SKB) { in hci_req_cmd_complete()
5015 *req_complete_skb = bt_cb(hdev->sent_cmd)->hci.req_complete_skb; in hci_req_cmd_complete()
5019 if (bt_cb(hdev->sent_cmd)->hci.req_complete) { in hci_req_cmd_complete()
5020 *req_complete = bt_cb(hdev->sent_cmd)->hci.req_complete; in hci_req_cmd_complete()
5025 spin_lock_irqsave(&hdev->cmd_q.lock, flags); in hci_req_cmd_complete()
5026 while ((skb = __skb_dequeue(&hdev->cmd_q))) { in hci_req_cmd_complete()
5028 __skb_queue_head(&hdev->cmd_q, skb); in hci_req_cmd_complete()
5038 spin_unlock_irqrestore(&hdev->cmd_q.lock, flags); in hci_req_cmd_complete()
5043 struct hci_dev *hdev = container_of(work, struct hci_dev, rx_work); in hci_rx_work() local
5046 BT_DBG("%s", hdev->name); in hci_rx_work()
5048 while ((skb = skb_dequeue(&hdev->rx_q))) { in hci_rx_work()
5050 hci_send_to_monitor(hdev, skb); in hci_rx_work()
5052 if (atomic_read(&hdev->promisc)) { in hci_rx_work()
5054 hci_send_to_sock(hdev, skb); in hci_rx_work()
5063 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_rx_work()
5064 !test_bit(HCI_INIT, &hdev->flags)) { in hci_rx_work()
5069 if (test_bit(HCI_INIT, &hdev->flags)) { in hci_rx_work()
5083 BT_DBG("%s Event packet", hdev->name); in hci_rx_work()
5084 hci_event_packet(hdev, skb); in hci_rx_work()
5088 BT_DBG("%s ACL data packet", hdev->name); in hci_rx_work()
5089 hci_acldata_packet(hdev, skb); in hci_rx_work()
5093 BT_DBG("%s SCO data packet", hdev->name); in hci_rx_work()
5094 hci_scodata_packet(hdev, skb); in hci_rx_work()
5106 struct hci_dev *hdev = container_of(work, struct hci_dev, cmd_work); in hci_cmd_work() local
5109 BT_DBG("%s cmd_cnt %d cmd queued %d", hdev->name, in hci_cmd_work()
5110 atomic_read(&hdev->cmd_cnt), skb_queue_len(&hdev->cmd_q)); in hci_cmd_work()
5113 if (atomic_read(&hdev->cmd_cnt)) { in hci_cmd_work()
5114 skb = skb_dequeue(&hdev->cmd_q); in hci_cmd_work()
5118 kfree_skb(hdev->sent_cmd); in hci_cmd_work()
5120 hdev->sent_cmd = skb_clone(skb, GFP_KERNEL); in hci_cmd_work()
5121 if (hdev->sent_cmd) { in hci_cmd_work()
5122 if (hci_req_status_pend(hdev)) in hci_cmd_work()
5123 hci_dev_set_flag(hdev, HCI_CMD_PENDING); in hci_cmd_work()
5124 atomic_dec(&hdev->cmd_cnt); in hci_cmd_work()
5125 hci_send_frame(hdev, skb); in hci_cmd_work()
5126 if (test_bit(HCI_RESET, &hdev->flags)) in hci_cmd_work()
5127 cancel_delayed_work(&hdev->cmd_timer); in hci_cmd_work()
5129 schedule_delayed_work(&hdev->cmd_timer, in hci_cmd_work()
5132 skb_queue_head(&hdev->cmd_q, skb); in hci_cmd_work()
5133 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_cmd_work()