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
83 if (!test_bit(HCI_UP, &hdev->flags)) in dut_mode_write()
93 if (enable == hci_dev_test_flag(hdev, HCI_DUT_MODE)) in dut_mode_write()
96 hci_req_sync_lock(hdev); in dut_mode_write()
98 skb = __hci_cmd_sync(hdev, HCI_OP_ENABLE_DUT_MODE, 0, NULL, in dut_mode_write()
101 skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, in dut_mode_write()
103 hci_req_sync_unlock(hdev); in dut_mode_write()
110 hci_dev_change_flag(hdev, HCI_DUT_MODE); in dut_mode_write()
125 struct hci_dev *hdev = file->private_data; in vendor_diag_read() local
128 buf[0] = hci_dev_test_flag(hdev, HCI_VENDOR_DIAG) ? 'Y' : 'N'; in vendor_diag_read()
137 struct hci_dev *hdev = file->private_data; in vendor_diag_write() local
156 if (test_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks) && in vendor_diag_write()
157 !test_bit(HCI_RUNNING, &hdev->flags)) in vendor_diag_write()
160 hci_req_sync_lock(hdev); in vendor_diag_write()
161 err = hdev->set_diag(hdev, enable); in vendor_diag_write()
162 hci_req_sync_unlock(hdev); in vendor_diag_write()
169 hci_dev_set_flag(hdev, HCI_VENDOR_DIAG); in vendor_diag_write()
171 hci_dev_clear_flag(hdev, HCI_VENDOR_DIAG); in vendor_diag_write()
183 static void hci_debugfs_create_basic(struct hci_dev *hdev) in hci_debugfs_create_basic() argument
185 debugfs_create_file("dut_mode", 0644, hdev->debugfs, hdev, in hci_debugfs_create_basic()
188 if (hdev->set_diag) in hci_debugfs_create_basic()
189 debugfs_create_file("vendor_diag", 0644, hdev->debugfs, hdev, in hci_debugfs_create_basic()
195 BT_DBG("%s %ld", req->hdev->name, opt); in hci_reset_req()
198 set_bit(HCI_RESET, &req->hdev->flags); in hci_reset_req()
205 req->hdev->flow_ctl_mode = HCI_FLOW_CTL_MODE_PACKET_BASED; in bredr_init()
219 req->hdev->flow_ctl_mode = HCI_FLOW_CTL_MODE_BLOCK_BASED; in amp_init1()
246 if (req->hdev->commands[14] & 0x20) in amp_init2()
254 struct hci_dev *hdev = req->hdev; in hci_init1_req() local
256 BT_DBG("%s %ld", hdev->name, opt); in hci_init1_req()
259 if (!test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks)) in hci_init1_req()
262 switch (hdev->dev_type) { in hci_init1_req()
270 BT_ERR("Unknown device type %d", hdev->dev_type); in hci_init1_req()
311 struct hci_dev *hdev = req->hdev; in le_setup() local
323 if (!lmp_bredr_capable(hdev)) in le_setup()
324 hci_dev_set_flag(hdev, HCI_LE_ENABLED); in le_setup()
329 struct hci_dev *hdev = req->hdev; in hci_setup_event_mask() local
340 if (hdev->hci_ver < BLUETOOTH_VER_1_2) in hci_setup_event_mask()
343 if (lmp_bredr_capable(hdev)) { in hci_setup_event_mask()
356 if (hdev->commands[0] & 0x20) { in hci_setup_event_mask()
365 if (hdev->commands[2] & 0x80) in hci_setup_event_mask()
370 if (hdev->le_features[0] & HCI_LE_ENCRYPTION) { in hci_setup_event_mask()
376 if (lmp_inq_rssi_capable(hdev) || in hci_setup_event_mask()
377 test_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks)) in hci_setup_event_mask()
380 if (lmp_ext_feat_capable(hdev)) in hci_setup_event_mask()
383 if (lmp_esco_capable(hdev)) { in hci_setup_event_mask()
388 if (lmp_sniffsubr_capable(hdev)) in hci_setup_event_mask()
391 if (lmp_pause_enc_capable(hdev)) in hci_setup_event_mask()
394 if (lmp_ext_inq_capable(hdev)) in hci_setup_event_mask()
397 if (lmp_no_flush_capable(hdev)) in hci_setup_event_mask()
400 if (lmp_lsto_capable(hdev)) in hci_setup_event_mask()
403 if (lmp_ssp_capable(hdev)) { in hci_setup_event_mask()
417 if (lmp_le_capable(hdev)) in hci_setup_event_mask()
425 struct hci_dev *hdev = req->hdev; in hci_init2_req() local
427 if (hdev->dev_type == HCI_AMP) in hci_init2_req()
430 if (lmp_bredr_capable(hdev)) in hci_init2_req()
433 hci_dev_clear_flag(hdev, HCI_BREDR_ENABLED); in hci_init2_req()
435 if (lmp_le_capable(hdev)) in hci_init2_req()
446 if (hdev->hci_ver > BLUETOOTH_VER_1_1 && in hci_init2_req()
447 !test_bit(HCI_QUIRK_BROKEN_LOCAL_COMMANDS, &hdev->quirks)) in hci_init2_req()
450 if (lmp_ssp_capable(hdev)) { in hci_init2_req()
457 hdev->max_page = 0x01; in hci_init2_req()
459 if (hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) { in hci_init2_req()
467 memset(hdev->eir, 0, sizeof(hdev->eir)); in hci_init2_req()
474 if (lmp_inq_rssi_capable(hdev) || in hci_init2_req()
475 test_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks)) { in hci_init2_req()
482 mode = lmp_ext_inq_capable(hdev) ? 0x02 : 0x01; in hci_init2_req()
487 if (lmp_inq_tx_pwr_capable(hdev)) in hci_init2_req()
490 if (lmp_ext_feat_capable(hdev)) { in hci_init2_req()
498 if (hci_dev_test_flag(hdev, HCI_LINK_SECURITY)) { in hci_init2_req()
509 struct hci_dev *hdev = req->hdev; in hci_setup_link_policy() local
513 if (lmp_rswitch_capable(hdev)) in hci_setup_link_policy()
515 if (lmp_hold_capable(hdev)) in hci_setup_link_policy()
517 if (lmp_sniff_capable(hdev)) in hci_setup_link_policy()
519 if (lmp_park_capable(hdev)) in hci_setup_link_policy()
528 struct hci_dev *hdev = req->hdev; in hci_set_le_support() local
532 if (!lmp_bredr_capable(hdev)) in hci_set_le_support()
537 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { in hci_set_le_support()
542 if (cp.le != lmp_host_le_capable(hdev)) in hci_set_le_support()
549 struct hci_dev *hdev = req->hdev; in hci_set_event_mask_page_2() local
556 if (lmp_csb_master_capable(hdev)) { in hci_set_event_mask_page_2()
567 if (lmp_csb_slave_capable(hdev)) { in hci_set_event_mask_page_2()
576 if (lmp_ping_capable(hdev) || hdev->le_features[0] & HCI_LE_PING) { in hci_set_event_mask_page_2()
594 struct hci_dev *hdev = req->hdev; in hci_init3_req() local
599 if (hdev->commands[6] & 0x20 && in hci_init3_req()
600 !test_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks)) { in hci_init3_req()
608 if (hdev->commands[5] & 0x10) in hci_init3_req()
611 if (hdev->commands[8] & 0x01) in hci_init3_req()
618 if (hdev->commands[13] & 0x01) in hci_init3_req()
621 if (lmp_le_capable(hdev)) { in hci_init3_req()
626 if (hdev->le_features[0] & HCI_LE_ENCRYPTION) in hci_init3_req()
632 if (hdev->le_features[0] & HCI_LE_CONN_PARAM_REQ_PROC) in hci_init3_req()
640 if (hdev->le_features[0] & HCI_LE_DATA_LEN_EXT) in hci_init3_req()
646 if (hdev->le_features[0] & HCI_LE_EXT_SCAN_POLICY) in hci_init3_req()
654 if (hdev->commands[26] & 0x08) in hci_init3_req()
660 if (hdev->commands[26] & 0x10) in hci_init3_req()
666 if (hdev->commands[27] & 0x04) in hci_init3_req()
674 if (hdev->commands[27] & 0x20) in hci_init3_req()
682 if (hdev->commands[34] & 0x02) in hci_init3_req()
690 if (hdev->commands[34] & 0x04) in hci_init3_req()
696 if (hdev->commands[25] & 0x40) { in hci_init3_req()
701 if (hdev->commands[26] & 0x40) { in hci_init3_req()
707 if (hdev->commands[26] & 0x80) { in hci_init3_req()
712 if (hdev->le_features[0] & HCI_LE_DATA_LEN_EXT) { in hci_init3_req()
724 for (p = 2; p < HCI_MAX_PAGES && p <= hdev->max_page; p++) { in hci_init3_req()
737 struct hci_dev *hdev = req->hdev; in hci_init4_req() local
752 if (hdev->commands[6] & 0x80 && in hci_init4_req()
753 !test_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks)) { in hci_init4_req()
763 if (hdev->commands[22] & 0x04) in hci_init4_req()
767 if (hdev->commands[29] & 0x20) in hci_init4_req()
771 if (hdev->commands[30] & 0x08) in hci_init4_req()
775 if (lmp_sync_train_capable(hdev)) in hci_init4_req()
779 if (hci_dev_test_flag(hdev, HCI_SSP_ENABLED) && in hci_init4_req()
780 bredr_sc_enabled(hdev)) { in hci_init4_req()
790 static int __hci_init(struct hci_dev *hdev) in __hci_init() argument
794 err = __hci_req_sync(hdev, hci_init1_req, 0, HCI_INIT_TIMEOUT, NULL); in __hci_init()
798 if (hci_dev_test_flag(hdev, HCI_SETUP)) in __hci_init()
799 hci_debugfs_create_basic(hdev); in __hci_init()
801 err = __hci_req_sync(hdev, hci_init2_req, 0, HCI_INIT_TIMEOUT, NULL); in __hci_init()
809 if (hdev->dev_type != HCI_PRIMARY) in __hci_init()
812 err = __hci_req_sync(hdev, hci_init3_req, 0, HCI_INIT_TIMEOUT, NULL); in __hci_init()
816 err = __hci_req_sync(hdev, hci_init4_req, 0, HCI_INIT_TIMEOUT, NULL); in __hci_init()
832 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in __hci_init()
833 !hci_dev_test_flag(hdev, HCI_CONFIG)) in __hci_init()
836 hci_debugfs_create_common(hdev); in __hci_init()
838 if (lmp_bredr_capable(hdev)) in __hci_init()
839 hci_debugfs_create_bredr(hdev); in __hci_init()
841 if (lmp_le_capable(hdev)) in __hci_init()
842 hci_debugfs_create_le(hdev); in __hci_init()
849 struct hci_dev *hdev = req->hdev; in hci_init0_req() local
851 BT_DBG("%s %ld", hdev->name, opt); in hci_init0_req()
854 if (!test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks)) in hci_init0_req()
861 if (hdev->set_bdaddr) in hci_init0_req()
867 static int __hci_unconf_init(struct hci_dev *hdev) in __hci_unconf_init() argument
871 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in __hci_unconf_init()
874 err = __hci_req_sync(hdev, hci_init0_req, 0, HCI_INIT_TIMEOUT, NULL); in __hci_unconf_init()
878 if (hci_dev_test_flag(hdev, HCI_SETUP)) in __hci_unconf_init()
879 hci_debugfs_create_basic(hdev); in __hci_unconf_init()
888 BT_DBG("%s %x", req->hdev->name, scan); in hci_scan_req()
899 BT_DBG("%s %x", req->hdev->name, auth); in hci_auth_req()
910 BT_DBG("%s %x", req->hdev->name, encrypt); in hci_encrypt_req()
921 BT_DBG("%s %x", req->hdev->name, policy); in hci_linkpol_req()
932 struct hci_dev *hdev = NULL, *d; in hci_dev_get() local
942 hdev = hci_dev_hold(d); in hci_dev_get()
947 return hdev; in hci_dev_get()
952 bool hci_discovery_active(struct hci_dev *hdev) in hci_discovery_active() argument
954 struct discovery_state *discov = &hdev->discovery; in hci_discovery_active()
966 void hci_discovery_set_state(struct hci_dev *hdev, int state) in hci_discovery_set_state() argument
968 int old_state = hdev->discovery.state; in hci_discovery_set_state()
970 BT_DBG("%s state %u -> %u", hdev->name, hdev->discovery.state, state); in hci_discovery_set_state()
975 hdev->discovery.state = state; in hci_discovery_set_state()
979 hci_update_background_scan(hdev); in hci_discovery_set_state()
982 mgmt_discovering(hdev, 0); in hci_discovery_set_state()
987 mgmt_discovering(hdev, 1); in hci_discovery_set_state()
996 void hci_inquiry_cache_flush(struct hci_dev *hdev) in hci_inquiry_cache_flush() argument
998 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_flush()
1010 struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev, in hci_inquiry_cache_lookup() argument
1013 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_lookup()
1026 struct inquiry_entry *hci_inquiry_cache_lookup_unknown(struct hci_dev *hdev, in hci_inquiry_cache_lookup_unknown() argument
1029 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_lookup_unknown()
1042 struct inquiry_entry *hci_inquiry_cache_lookup_resolve(struct hci_dev *hdev, in hci_inquiry_cache_lookup_resolve() argument
1046 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_lookup_resolve()
1061 void hci_inquiry_cache_update_resolve(struct hci_dev *hdev, in hci_inquiry_cache_update_resolve() argument
1064 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_update_resolve()
1080 u32 hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data, in hci_inquiry_cache_update() argument
1083 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_update()
1089 hci_remove_remote_oob_data(hdev, &data->bdaddr, BDADDR_BREDR); in hci_inquiry_cache_update()
1094 ie = hci_inquiry_cache_lookup(hdev, &data->bdaddr); in hci_inquiry_cache_update()
1102 hci_inquiry_cache_update_resolve(hdev, ie); in hci_inquiry_cache_update()
1142 static int inquiry_cache_dump(struct hci_dev *hdev, int num, __u8 *buf) in inquiry_cache_dump() argument
1144 struct discovery_state *cache = &hdev->discovery; in inquiry_cache_dump()
1173 struct hci_dev *hdev = req->hdev; in hci_inq_req() local
1176 BT_DBG("%s", hdev->name); in hci_inq_req()
1178 if (test_bit(HCI_INQUIRY, &hdev->flags)) in hci_inq_req()
1194 struct hci_dev *hdev; in hci_inquiry() local
1202 hdev = hci_dev_get(ir.dev_id); in hci_inquiry()
1203 if (!hdev) in hci_inquiry()
1206 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_inquiry()
1211 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_inquiry()
1216 if (hdev->dev_type != HCI_PRIMARY) { in hci_inquiry()
1221 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in hci_inquiry()
1226 hci_dev_lock(hdev); in hci_inquiry()
1227 if (inquiry_cache_age(hdev) > INQUIRY_CACHE_AGE_MAX || in hci_inquiry()
1228 inquiry_cache_empty(hdev) || ir.flags & IREQ_CACHE_FLUSH) { in hci_inquiry()
1229 hci_inquiry_cache_flush(hdev); in hci_inquiry()
1232 hci_dev_unlock(hdev); in hci_inquiry()
1237 err = hci_req_sync(hdev, hci_inq_req, (unsigned long) &ir, in hci_inquiry()
1245 if (wait_on_bit(&hdev->flags, HCI_INQUIRY, in hci_inquiry()
1264 hci_dev_lock(hdev); in hci_inquiry()
1265 ir.num_rsp = inquiry_cache_dump(hdev, max_rsp, buf); in hci_inquiry()
1266 hci_dev_unlock(hdev); in hci_inquiry()
1281 hci_dev_put(hdev); in hci_inquiry()
1285 static int hci_dev_do_open(struct hci_dev *hdev) in hci_dev_do_open() argument
1289 BT_DBG("%s %p", hdev->name, hdev); in hci_dev_do_open()
1291 hci_req_sync_lock(hdev); in hci_dev_do_open()
1293 if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) { in hci_dev_do_open()
1298 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_dev_do_open()
1299 !hci_dev_test_flag(hdev, HCI_CONFIG)) { in hci_dev_do_open()
1303 if (hci_dev_test_flag(hdev, HCI_RFKILLED)) { in hci_dev_do_open()
1320 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_do_open()
1321 hdev->dev_type == HCI_PRIMARY && in hci_dev_do_open()
1322 !bacmp(&hdev->bdaddr, BDADDR_ANY) && in hci_dev_do_open()
1323 !bacmp(&hdev->static_addr, BDADDR_ANY)) { in hci_dev_do_open()
1329 if (test_bit(HCI_UP, &hdev->flags)) { in hci_dev_do_open()
1334 if (hdev->open(hdev)) { in hci_dev_do_open()
1339 set_bit(HCI_RUNNING, &hdev->flags); in hci_dev_do_open()
1340 hci_sock_dev_event(hdev, HCI_DEV_OPEN); in hci_dev_do_open()
1342 atomic_set(&hdev->cmd_cnt, 1); in hci_dev_do_open()
1343 set_bit(HCI_INIT, &hdev->flags); in hci_dev_do_open()
1345 if (hci_dev_test_flag(hdev, HCI_SETUP)) { in hci_dev_do_open()
1346 hci_sock_dev_event(hdev, HCI_DEV_SETUP); in hci_dev_do_open()
1348 if (hdev->setup) in hci_dev_do_open()
1349 ret = hdev->setup(hdev); in hci_dev_do_open()
1357 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) || in hci_dev_do_open()
1358 test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks)) in hci_dev_do_open()
1359 hci_dev_set_flag(hdev, HCI_UNCONFIGURED); in hci_dev_do_open()
1369 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in hci_dev_do_open()
1370 ret = __hci_unconf_init(hdev); in hci_dev_do_open()
1373 if (hci_dev_test_flag(hdev, HCI_CONFIG)) { in hci_dev_do_open()
1379 if (bacmp(&hdev->public_addr, BDADDR_ANY) && in hci_dev_do_open()
1380 hdev->set_bdaddr) in hci_dev_do_open()
1381 ret = hdev->set_bdaddr(hdev, &hdev->public_addr); in hci_dev_do_open()
1387 if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED) && in hci_dev_do_open()
1388 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_do_open()
1389 ret = __hci_init(hdev); in hci_dev_do_open()
1390 if (!ret && hdev->post_init) in hci_dev_do_open()
1391 ret = hdev->post_init(hdev); in hci_dev_do_open()
1399 if (test_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks) && in hci_dev_do_open()
1400 hci_dev_test_flag(hdev, HCI_VENDOR_DIAG) && hdev->set_diag) in hci_dev_do_open()
1401 ret = hdev->set_diag(hdev, true); in hci_dev_do_open()
1403 clear_bit(HCI_INIT, &hdev->flags); in hci_dev_do_open()
1406 hci_dev_hold(hdev); in hci_dev_do_open()
1407 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in hci_dev_do_open()
1408 set_bit(HCI_UP, &hdev->flags); in hci_dev_do_open()
1409 hci_sock_dev_event(hdev, HCI_DEV_UP); in hci_dev_do_open()
1410 hci_leds_update_powered(hdev, true); in hci_dev_do_open()
1411 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_dev_do_open()
1412 !hci_dev_test_flag(hdev, HCI_CONFIG) && in hci_dev_do_open()
1413 !hci_dev_test_flag(hdev, HCI_UNCONFIGURED) && in hci_dev_do_open()
1414 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_do_open()
1415 hci_dev_test_flag(hdev, HCI_MGMT) && in hci_dev_do_open()
1416 hdev->dev_type == HCI_PRIMARY) { in hci_dev_do_open()
1417 ret = __hci_req_hci_power_on(hdev); in hci_dev_do_open()
1418 mgmt_power_on(hdev, ret); in hci_dev_do_open()
1422 flush_work(&hdev->tx_work); in hci_dev_do_open()
1423 flush_work(&hdev->cmd_work); in hci_dev_do_open()
1424 flush_work(&hdev->rx_work); in hci_dev_do_open()
1426 skb_queue_purge(&hdev->cmd_q); in hci_dev_do_open()
1427 skb_queue_purge(&hdev->rx_q); in hci_dev_do_open()
1429 if (hdev->flush) in hci_dev_do_open()
1430 hdev->flush(hdev); in hci_dev_do_open()
1432 if (hdev->sent_cmd) { in hci_dev_do_open()
1433 kfree_skb(hdev->sent_cmd); in hci_dev_do_open()
1434 hdev->sent_cmd = NULL; in hci_dev_do_open()
1437 clear_bit(HCI_RUNNING, &hdev->flags); in hci_dev_do_open()
1438 hci_sock_dev_event(hdev, HCI_DEV_CLOSE); in hci_dev_do_open()
1440 hdev->close(hdev); in hci_dev_do_open()
1441 hdev->flags &= BIT(HCI_RAW); in hci_dev_do_open()
1445 hci_req_sync_unlock(hdev); in hci_dev_do_open()
1453 struct hci_dev *hdev; in hci_dev_open() local
1456 hdev = hci_dev_get(dev); in hci_dev_open()
1457 if (!hdev) in hci_dev_open()
1469 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED) && in hci_dev_open()
1470 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_open()
1480 if (hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF)) in hci_dev_open()
1481 cancel_delayed_work(&hdev->power_off); in hci_dev_open()
1487 flush_workqueue(hdev->req_workqueue); in hci_dev_open()
1495 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_open()
1496 !hci_dev_test_flag(hdev, HCI_MGMT)) in hci_dev_open()
1497 hci_dev_set_flag(hdev, HCI_BONDABLE); in hci_dev_open()
1499 err = hci_dev_do_open(hdev); in hci_dev_open()
1502 hci_dev_put(hdev); in hci_dev_open()
1507 static void hci_pend_le_actions_clear(struct hci_dev *hdev) in hci_pend_le_actions_clear() argument
1511 list_for_each_entry(p, &hdev->le_conn_params, list) { in hci_pend_le_actions_clear()
1523 int hci_dev_do_close(struct hci_dev *hdev) in hci_dev_do_close() argument
1527 BT_DBG("%s %p", hdev->name, hdev); in hci_dev_do_close()
1529 if (!hci_dev_test_flag(hdev, HCI_UNREGISTER) && in hci_dev_do_close()
1530 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_do_close()
1531 test_bit(HCI_UP, &hdev->flags)) { in hci_dev_do_close()
1533 if (hdev->shutdown) in hci_dev_do_close()
1534 hdev->shutdown(hdev); in hci_dev_do_close()
1537 cancel_delayed_work(&hdev->power_off); in hci_dev_do_close()
1539 hci_request_cancel_all(hdev); in hci_dev_do_close()
1540 hci_req_sync_lock(hdev); in hci_dev_do_close()
1542 if (!test_and_clear_bit(HCI_UP, &hdev->flags)) { in hci_dev_do_close()
1543 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_dev_do_close()
1544 hci_req_sync_unlock(hdev); in hci_dev_do_close()
1548 hci_leds_update_powered(hdev, false); in hci_dev_do_close()
1551 flush_work(&hdev->tx_work); in hci_dev_do_close()
1552 flush_work(&hdev->rx_work); in hci_dev_do_close()
1554 if (hdev->discov_timeout > 0) { in hci_dev_do_close()
1555 hdev->discov_timeout = 0; in hci_dev_do_close()
1556 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in hci_dev_do_close()
1557 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in hci_dev_do_close()
1560 if (hci_dev_test_and_clear_flag(hdev, HCI_SERVICE_CACHE)) in hci_dev_do_close()
1561 cancel_delayed_work(&hdev->service_cache); in hci_dev_do_close()
1563 if (hci_dev_test_flag(hdev, HCI_MGMT)) in hci_dev_do_close()
1564 cancel_delayed_work_sync(&hdev->rpa_expired); in hci_dev_do_close()
1569 drain_workqueue(hdev->workqueue); in hci_dev_do_close()
1571 hci_dev_lock(hdev); in hci_dev_do_close()
1573 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in hci_dev_do_close()
1575 auto_off = hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF); in hci_dev_do_close()
1577 if (!auto_off && hdev->dev_type == HCI_PRIMARY && in hci_dev_do_close()
1578 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_do_close()
1579 hci_dev_test_flag(hdev, HCI_MGMT)) in hci_dev_do_close()
1580 __mgmt_power_off(hdev); in hci_dev_do_close()
1582 hci_inquiry_cache_flush(hdev); in hci_dev_do_close()
1583 hci_pend_le_actions_clear(hdev); in hci_dev_do_close()
1584 hci_conn_hash_flush(hdev); in hci_dev_do_close()
1585 hci_dev_unlock(hdev); in hci_dev_do_close()
1587 smp_unregister(hdev); in hci_dev_do_close()
1589 hci_sock_dev_event(hdev, HCI_DEV_DOWN); in hci_dev_do_close()
1591 if (hdev->flush) in hci_dev_do_close()
1592 hdev->flush(hdev); in hci_dev_do_close()
1595 skb_queue_purge(&hdev->cmd_q); in hci_dev_do_close()
1596 atomic_set(&hdev->cmd_cnt, 1); in hci_dev_do_close()
1597 if (test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks) && in hci_dev_do_close()
1598 !auto_off && !hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_dev_do_close()
1599 set_bit(HCI_INIT, &hdev->flags); in hci_dev_do_close()
1600 __hci_req_sync(hdev, hci_reset_req, 0, HCI_CMD_TIMEOUT, NULL); in hci_dev_do_close()
1601 clear_bit(HCI_INIT, &hdev->flags); in hci_dev_do_close()
1605 flush_work(&hdev->cmd_work); in hci_dev_do_close()
1608 skb_queue_purge(&hdev->rx_q); in hci_dev_do_close()
1609 skb_queue_purge(&hdev->cmd_q); in hci_dev_do_close()
1610 skb_queue_purge(&hdev->raw_q); in hci_dev_do_close()
1613 if (hdev->sent_cmd) { in hci_dev_do_close()
1614 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_dev_do_close()
1615 kfree_skb(hdev->sent_cmd); in hci_dev_do_close()
1616 hdev->sent_cmd = NULL; in hci_dev_do_close()
1619 clear_bit(HCI_RUNNING, &hdev->flags); in hci_dev_do_close()
1620 hci_sock_dev_event(hdev, HCI_DEV_CLOSE); in hci_dev_do_close()
1624 hdev->close(hdev); in hci_dev_do_close()
1627 hdev->flags &= BIT(HCI_RAW); in hci_dev_do_close()
1628 hci_dev_clear_volatile_flags(hdev); in hci_dev_do_close()
1631 hdev->amp_status = AMP_STATUS_POWERED_DOWN; in hci_dev_do_close()
1633 memset(hdev->eir, 0, sizeof(hdev->eir)); in hci_dev_do_close()
1634 memset(hdev->dev_class, 0, sizeof(hdev->dev_class)); in hci_dev_do_close()
1635 bacpy(&hdev->random_addr, BDADDR_ANY); in hci_dev_do_close()
1637 hci_req_sync_unlock(hdev); in hci_dev_do_close()
1639 hci_dev_put(hdev); in hci_dev_do_close()
1645 struct hci_dev *hdev; in hci_dev_close() local
1648 hdev = hci_dev_get(dev); in hci_dev_close()
1649 if (!hdev) in hci_dev_close()
1652 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_close()
1657 if (hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF)) in hci_dev_close()
1658 cancel_delayed_work(&hdev->power_off); in hci_dev_close()
1660 err = hci_dev_do_close(hdev); in hci_dev_close()
1663 hci_dev_put(hdev); in hci_dev_close()
1667 static int hci_dev_do_reset(struct hci_dev *hdev) in hci_dev_do_reset() argument
1671 BT_DBG("%s %p", hdev->name, hdev); in hci_dev_do_reset()
1673 hci_req_sync_lock(hdev); in hci_dev_do_reset()
1676 skb_queue_purge(&hdev->rx_q); in hci_dev_do_reset()
1677 skb_queue_purge(&hdev->cmd_q); in hci_dev_do_reset()
1682 drain_workqueue(hdev->workqueue); in hci_dev_do_reset()
1684 hci_dev_lock(hdev); in hci_dev_do_reset()
1685 hci_inquiry_cache_flush(hdev); in hci_dev_do_reset()
1686 hci_conn_hash_flush(hdev); in hci_dev_do_reset()
1687 hci_dev_unlock(hdev); in hci_dev_do_reset()
1689 if (hdev->flush) in hci_dev_do_reset()
1690 hdev->flush(hdev); in hci_dev_do_reset()
1692 atomic_set(&hdev->cmd_cnt, 1); in hci_dev_do_reset()
1693 hdev->acl_cnt = 0; hdev->sco_cnt = 0; hdev->le_cnt = 0; in hci_dev_do_reset()
1695 ret = __hci_req_sync(hdev, hci_reset_req, 0, HCI_INIT_TIMEOUT, NULL); in hci_dev_do_reset()
1697 hci_req_sync_unlock(hdev); in hci_dev_do_reset()
1703 struct hci_dev *hdev; in hci_dev_reset() local
1706 hdev = hci_dev_get(dev); in hci_dev_reset()
1707 if (!hdev) in hci_dev_reset()
1710 if (!test_bit(HCI_UP, &hdev->flags)) { in hci_dev_reset()
1715 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_reset()
1720 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_dev_reset()
1725 err = hci_dev_do_reset(hdev); in hci_dev_reset()
1728 hci_dev_put(hdev); in hci_dev_reset()
1734 struct hci_dev *hdev; in hci_dev_reset_stat() local
1737 hdev = hci_dev_get(dev); in hci_dev_reset_stat()
1738 if (!hdev) in hci_dev_reset_stat()
1741 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_reset_stat()
1746 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_dev_reset_stat()
1751 memset(&hdev->stat, 0, sizeof(struct hci_dev_stats)); in hci_dev_reset_stat()
1754 hci_dev_put(hdev); in hci_dev_reset_stat()
1758 static void hci_update_scan_state(struct hci_dev *hdev, u8 scan) in hci_update_scan_state() argument
1762 BT_DBG("%s scan 0x%02x", hdev->name, scan); in hci_update_scan_state()
1765 conn_changed = !hci_dev_test_and_set_flag(hdev, in hci_update_scan_state()
1768 conn_changed = hci_dev_test_and_clear_flag(hdev, in hci_update_scan_state()
1772 discov_changed = !hci_dev_test_and_set_flag(hdev, in hci_update_scan_state()
1775 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in hci_update_scan_state()
1776 discov_changed = hci_dev_test_and_clear_flag(hdev, in hci_update_scan_state()
1780 if (!hci_dev_test_flag(hdev, HCI_MGMT)) in hci_update_scan_state()
1785 hci_dev_set_flag(hdev, HCI_BREDR_ENABLED); in hci_update_scan_state()
1787 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in hci_update_scan_state()
1788 hci_req_update_adv_data(hdev, hdev->cur_adv_instance); in hci_update_scan_state()
1790 mgmt_new_settings(hdev); in hci_update_scan_state()
1796 struct hci_dev *hdev; in hci_dev_cmd() local
1803 hdev = hci_dev_get(dr.dev_id); in hci_dev_cmd()
1804 if (!hdev) in hci_dev_cmd()
1807 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_cmd()
1812 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_dev_cmd()
1817 if (hdev->dev_type != HCI_PRIMARY) { in hci_dev_cmd()
1822 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in hci_dev_cmd()
1829 err = hci_req_sync(hdev, hci_auth_req, dr.dev_opt, in hci_dev_cmd()
1834 if (!lmp_encrypt_capable(hdev)) { in hci_dev_cmd()
1839 if (!test_bit(HCI_AUTH, &hdev->flags)) { in hci_dev_cmd()
1841 err = hci_req_sync(hdev, hci_auth_req, dr.dev_opt, in hci_dev_cmd()
1847 err = hci_req_sync(hdev, hci_encrypt_req, dr.dev_opt, in hci_dev_cmd()
1852 err = hci_req_sync(hdev, hci_scan_req, dr.dev_opt, in hci_dev_cmd()
1859 hci_update_scan_state(hdev, dr.dev_opt); in hci_dev_cmd()
1863 err = hci_req_sync(hdev, hci_linkpol_req, dr.dev_opt, in hci_dev_cmd()
1868 hdev->link_mode = ((__u16) dr.dev_opt) & in hci_dev_cmd()
1873 hdev->pkt_type = (__u16) dr.dev_opt; in hci_dev_cmd()
1877 hdev->acl_mtu = *((__u16 *) &dr.dev_opt + 1); in hci_dev_cmd()
1878 hdev->acl_pkts = *((__u16 *) &dr.dev_opt + 0); in hci_dev_cmd()
1882 hdev->sco_mtu = *((__u16 *) &dr.dev_opt + 1); in hci_dev_cmd()
1883 hdev->sco_pkts = *((__u16 *) &dr.dev_opt + 0); in hci_dev_cmd()
1892 hci_dev_put(hdev); in hci_dev_cmd()
1898 struct hci_dev *hdev; in hci_get_dev_list() local
1919 list_for_each_entry(hdev, &hci_dev_list, list) { in hci_get_dev_list()
1920 unsigned long flags = hdev->flags; in hci_get_dev_list()
1926 if (hci_dev_test_flag(hdev, HCI_AUTO_OFF)) in hci_get_dev_list()
1929 (dr + n)->dev_id = hdev->id; in hci_get_dev_list()
1948 struct hci_dev *hdev; in hci_get_dev_info() local
1956 hdev = hci_dev_get(di.dev_id); in hci_get_dev_info()
1957 if (!hdev) in hci_get_dev_info()
1964 if (hci_dev_test_flag(hdev, HCI_AUTO_OFF)) in hci_get_dev_info()
1965 flags = hdev->flags & ~BIT(HCI_UP); in hci_get_dev_info()
1967 flags = hdev->flags; in hci_get_dev_info()
1969 strcpy(di.name, hdev->name); in hci_get_dev_info()
1970 di.bdaddr = hdev->bdaddr; in hci_get_dev_info()
1971 di.type = (hdev->bus & 0x0f) | ((hdev->dev_type & 0x03) << 4); in hci_get_dev_info()
1973 di.pkt_type = hdev->pkt_type; in hci_get_dev_info()
1974 if (lmp_bredr_capable(hdev)) { in hci_get_dev_info()
1975 di.acl_mtu = hdev->acl_mtu; in hci_get_dev_info()
1976 di.acl_pkts = hdev->acl_pkts; in hci_get_dev_info()
1977 di.sco_mtu = hdev->sco_mtu; in hci_get_dev_info()
1978 di.sco_pkts = hdev->sco_pkts; in hci_get_dev_info()
1980 di.acl_mtu = hdev->le_mtu; in hci_get_dev_info()
1981 di.acl_pkts = hdev->le_pkts; in hci_get_dev_info()
1985 di.link_policy = hdev->link_policy; in hci_get_dev_info()
1986 di.link_mode = hdev->link_mode; in hci_get_dev_info()
1988 memcpy(&di.stat, &hdev->stat, sizeof(di.stat)); in hci_get_dev_info()
1989 memcpy(&di.features, &hdev->features, sizeof(di.features)); in hci_get_dev_info()
1994 hci_dev_put(hdev); in hci_get_dev_info()
2003 struct hci_dev *hdev = data; in hci_rfkill_set_block() local
2005 BT_DBG("%p name %s blocked %d", hdev, hdev->name, blocked); in hci_rfkill_set_block()
2007 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) in hci_rfkill_set_block()
2011 hci_dev_set_flag(hdev, HCI_RFKILLED); in hci_rfkill_set_block()
2012 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_rfkill_set_block()
2013 !hci_dev_test_flag(hdev, HCI_CONFIG)) in hci_rfkill_set_block()
2014 hci_dev_do_close(hdev); in hci_rfkill_set_block()
2016 hci_dev_clear_flag(hdev, HCI_RFKILLED); in hci_rfkill_set_block()
2028 struct hci_dev *hdev = container_of(work, struct hci_dev, power_on); in hci_power_on() local
2031 BT_DBG("%s", hdev->name); in hci_power_on()
2033 if (test_bit(HCI_UP, &hdev->flags) && in hci_power_on()
2034 hci_dev_test_flag(hdev, HCI_MGMT) && in hci_power_on()
2035 hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF)) { in hci_power_on()
2036 cancel_delayed_work(&hdev->power_off); in hci_power_on()
2037 hci_req_sync_lock(hdev); in hci_power_on()
2038 err = __hci_req_hci_power_on(hdev); in hci_power_on()
2039 hci_req_sync_unlock(hdev); in hci_power_on()
2040 mgmt_power_on(hdev, err); in hci_power_on()
2044 err = hci_dev_do_open(hdev); in hci_power_on()
2046 hci_dev_lock(hdev); in hci_power_on()
2047 mgmt_set_powered_failed(hdev, err); in hci_power_on()
2048 hci_dev_unlock(hdev); in hci_power_on()
2056 if (hci_dev_test_flag(hdev, HCI_RFKILLED) || in hci_power_on()
2057 hci_dev_test_flag(hdev, HCI_UNCONFIGURED) || in hci_power_on()
2058 (hdev->dev_type == HCI_PRIMARY && in hci_power_on()
2059 !bacmp(&hdev->bdaddr, BDADDR_ANY) && in hci_power_on()
2060 !bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_power_on()
2061 hci_dev_clear_flag(hdev, HCI_AUTO_OFF); in hci_power_on()
2062 hci_dev_do_close(hdev); in hci_power_on()
2063 } else if (hci_dev_test_flag(hdev, HCI_AUTO_OFF)) { in hci_power_on()
2064 queue_delayed_work(hdev->req_workqueue, &hdev->power_off, in hci_power_on()
2068 if (hci_dev_test_and_clear_flag(hdev, HCI_SETUP)) { in hci_power_on()
2072 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in hci_power_on()
2073 set_bit(HCI_RAW, &hdev->flags); in hci_power_on()
2082 mgmt_index_added(hdev); in hci_power_on()
2083 } else if (hci_dev_test_and_clear_flag(hdev, HCI_CONFIG)) { in hci_power_on()
2087 if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in hci_power_on()
2088 clear_bit(HCI_RAW, &hdev->flags); in hci_power_on()
2094 mgmt_index_added(hdev); in hci_power_on()
2100 struct hci_dev *hdev = container_of(work, struct hci_dev, in hci_power_off() local
2103 BT_DBG("%s", hdev->name); in hci_power_off()
2105 hci_dev_do_close(hdev); in hci_power_off()
2110 struct hci_dev *hdev = container_of(work, struct hci_dev, error_reset); in hci_error_reset() local
2112 BT_DBG("%s", hdev->name); in hci_error_reset()
2114 if (hdev->hw_error) in hci_error_reset()
2115 hdev->hw_error(hdev, hdev->hw_error_code); in hci_error_reset()
2117 BT_ERR("%s hardware error 0x%2.2x", hdev->name, in hci_error_reset()
2118 hdev->hw_error_code); in hci_error_reset()
2120 if (hci_dev_do_close(hdev)) in hci_error_reset()
2123 hci_dev_do_open(hdev); in hci_error_reset()
2126 void hci_uuids_clear(struct hci_dev *hdev) in hci_uuids_clear() argument
2130 list_for_each_entry_safe(uuid, tmp, &hdev->uuids, list) { in hci_uuids_clear()
2136 void hci_link_keys_clear(struct hci_dev *hdev) in hci_link_keys_clear() argument
2140 list_for_each_entry_rcu(key, &hdev->link_keys, list) { in hci_link_keys_clear()
2146 void hci_smp_ltks_clear(struct hci_dev *hdev) in hci_smp_ltks_clear() argument
2150 list_for_each_entry_rcu(k, &hdev->long_term_keys, list) { in hci_smp_ltks_clear()
2156 void hci_smp_irks_clear(struct hci_dev *hdev) in hci_smp_irks_clear() argument
2160 list_for_each_entry_rcu(k, &hdev->identity_resolving_keys, list) { in hci_smp_irks_clear()
2166 struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr) in hci_find_link_key() argument
2171 list_for_each_entry_rcu(k, &hdev->link_keys, list) { in hci_find_link_key()
2182 static bool hci_persistent_key(struct hci_dev *hdev, struct hci_conn *conn, in hci_persistent_key() argument
2230 struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_find_ltk() argument
2236 list_for_each_entry_rcu(k, &hdev->long_term_keys, list) { in hci_find_ltk()
2250 struct smp_irk *hci_find_irk_by_rpa(struct hci_dev *hdev, bdaddr_t *rpa) in hci_find_irk_by_rpa() argument
2255 list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) { in hci_find_irk_by_rpa()
2262 list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) { in hci_find_irk_by_rpa()
2263 if (smp_irk_matches(hdev, irk->val, rpa)) { in hci_find_irk_by_rpa()
2274 struct smp_irk *hci_find_irk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_find_irk_by_addr() argument
2284 list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) { in hci_find_irk_by_addr()
2296 struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, in hci_add_link_key() argument
2303 old_key = hci_find_link_key(hdev, bdaddr); in hci_add_link_key()
2312 list_add_rcu(&key->list, &hdev->link_keys); in hci_add_link_key()
2315 BT_DBG("%s key for %pMR type %u", hdev->name, bdaddr, type); in hci_add_link_key()
2337 *persistent = hci_persistent_key(hdev, conn, type, in hci_add_link_key()
2343 struct smp_ltk *hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_add_ltk() argument
2350 old_key = hci_find_ltk(hdev, bdaddr, addr_type, role); in hci_add_ltk()
2357 list_add_rcu(&key->list, &hdev->long_term_keys); in hci_add_ltk()
2372 struct smp_irk *hci_add_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_add_irk() argument
2377 irk = hci_find_irk_by_addr(hdev, bdaddr, addr_type); in hci_add_irk()
2386 list_add_rcu(&irk->list, &hdev->identity_resolving_keys); in hci_add_irk()
2395 int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr) in hci_remove_link_key() argument
2399 key = hci_find_link_key(hdev, bdaddr); in hci_remove_link_key()
2403 BT_DBG("%s removing %pMR", hdev->name, bdaddr); in hci_remove_link_key()
2411 int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 bdaddr_type) in hci_remove_ltk() argument
2416 list_for_each_entry_rcu(k, &hdev->long_term_keys, list) { in hci_remove_ltk()
2420 BT_DBG("%s removing %pMR", hdev->name, bdaddr); in hci_remove_ltk()
2430 void hci_remove_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type) in hci_remove_irk() argument
2434 list_for_each_entry_rcu(k, &hdev->identity_resolving_keys, list) { in hci_remove_irk()
2438 BT_DBG("%s removing %pMR", hdev->name, bdaddr); in hci_remove_irk()
2445 bool hci_bdaddr_is_paired(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type) in hci_bdaddr_is_paired() argument
2452 if (hci_find_link_key(hdev, bdaddr)) in hci_bdaddr_is_paired()
2463 irk = hci_get_irk(hdev, bdaddr, addr_type); in hci_bdaddr_is_paired()
2470 list_for_each_entry_rcu(k, &hdev->long_term_keys, list) { in hci_bdaddr_is_paired()
2484 struct hci_dev *hdev = container_of(work, struct hci_dev, in hci_cmd_timeout() local
2487 if (hdev->sent_cmd) { in hci_cmd_timeout()
2488 struct hci_command_hdr *sent = (void *) hdev->sent_cmd->data; in hci_cmd_timeout()
2491 BT_ERR("%s command 0x%4.4x tx timeout", hdev->name, opcode); in hci_cmd_timeout()
2493 BT_ERR("%s command tx timeout", hdev->name); in hci_cmd_timeout()
2496 atomic_set(&hdev->cmd_cnt, 1); in hci_cmd_timeout()
2497 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_cmd_timeout()
2500 struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev, in hci_find_remote_oob_data() argument
2505 list_for_each_entry(data, &hdev->remote_oob_data, list) { in hci_find_remote_oob_data()
2516 int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_remove_remote_oob_data() argument
2521 data = hci_find_remote_oob_data(hdev, bdaddr, bdaddr_type); in hci_remove_remote_oob_data()
2525 BT_DBG("%s removing %pMR (%u)", hdev->name, bdaddr, bdaddr_type); in hci_remove_remote_oob_data()
2533 void hci_remote_oob_data_clear(struct hci_dev *hdev) in hci_remote_oob_data_clear() argument
2537 list_for_each_entry_safe(data, n, &hdev->remote_oob_data, list) { in hci_remote_oob_data_clear()
2543 int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_add_remote_oob_data() argument
2549 data = hci_find_remote_oob_data(hdev, bdaddr, bdaddr_type); in hci_add_remote_oob_data()
2557 list_add(&data->list, &hdev->remote_oob_data); in hci_add_remote_oob_data()
2584 BT_DBG("%s for %pMR", hdev->name, bdaddr); in hci_add_remote_oob_data()
2590 struct adv_info *hci_find_adv_instance(struct hci_dev *hdev, u8 instance) in hci_find_adv_instance() argument
2594 list_for_each_entry(adv_instance, &hdev->adv_instances, list) { in hci_find_adv_instance()
2603 struct adv_info *hci_get_next_instance(struct hci_dev *hdev, u8 instance) in hci_get_next_instance() argument
2607 cur_instance = hci_find_adv_instance(hdev, instance); in hci_get_next_instance()
2611 if (cur_instance == list_last_entry(&hdev->adv_instances, in hci_get_next_instance()
2613 return list_first_entry(&hdev->adv_instances, in hci_get_next_instance()
2620 int hci_remove_adv_instance(struct hci_dev *hdev, u8 instance) in hci_remove_adv_instance() argument
2624 adv_instance = hci_find_adv_instance(hdev, instance); in hci_remove_adv_instance()
2628 BT_DBG("%s removing %dMR", hdev->name, instance); in hci_remove_adv_instance()
2630 if (hdev->cur_adv_instance == instance) { in hci_remove_adv_instance()
2631 if (hdev->adv_instance_timeout) { in hci_remove_adv_instance()
2632 cancel_delayed_work(&hdev->adv_instance_expire); in hci_remove_adv_instance()
2633 hdev->adv_instance_timeout = 0; in hci_remove_adv_instance()
2635 hdev->cur_adv_instance = 0x00; in hci_remove_adv_instance()
2641 hdev->adv_instance_cnt--; in hci_remove_adv_instance()
2647 void hci_adv_instances_clear(struct hci_dev *hdev) in hci_adv_instances_clear() argument
2651 if (hdev->adv_instance_timeout) { in hci_adv_instances_clear()
2652 cancel_delayed_work(&hdev->adv_instance_expire); in hci_adv_instances_clear()
2653 hdev->adv_instance_timeout = 0; in hci_adv_instances_clear()
2656 list_for_each_entry_safe(adv_instance, n, &hdev->adv_instances, list) { in hci_adv_instances_clear()
2661 hdev->adv_instance_cnt = 0; in hci_adv_instances_clear()
2662 hdev->cur_adv_instance = 0x00; in hci_adv_instances_clear()
2666 int hci_add_adv_instance(struct hci_dev *hdev, u8 instance, u32 flags, in hci_add_adv_instance() argument
2673 adv_instance = hci_find_adv_instance(hdev, instance); in hci_add_adv_instance()
2680 if (hdev->adv_instance_cnt >= HCI_MAX_ADV_INSTANCES || in hci_add_adv_instance()
2690 list_add(&adv_instance->list, &hdev->adv_instances); in hci_add_adv_instance()
2691 hdev->adv_instance_cnt++; in hci_add_adv_instance()
2713 BT_DBG("%s for %dMR", hdev->name, instance); in hci_add_adv_instance()
2783 struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev, in hci_conn_params_lookup() argument
2788 list_for_each_entry(params, &hdev->le_conn_params, list) { in hci_conn_params_lookup()
2814 struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev, in hci_conn_params_add() argument
2819 params = hci_conn_params_lookup(hdev, addr, addr_type); in hci_conn_params_add()
2832 list_add(¶ms->list, &hdev->le_conn_params); in hci_conn_params_add()
2835 params->conn_min_interval = hdev->le_conn_min_interval; in hci_conn_params_add()
2836 params->conn_max_interval = hdev->le_conn_max_interval; in hci_conn_params_add()
2837 params->conn_latency = hdev->le_conn_latency; in hci_conn_params_add()
2838 params->supervision_timeout = hdev->le_supv_timeout; in hci_conn_params_add()
2859 void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type) in hci_conn_params_del() argument
2863 params = hci_conn_params_lookup(hdev, addr, addr_type); in hci_conn_params_del()
2869 hci_update_background_scan(hdev); in hci_conn_params_del()
2875 void hci_conn_params_clear_disabled(struct hci_dev *hdev) in hci_conn_params_clear_disabled() argument
2879 list_for_each_entry_safe(params, tmp, &hdev->le_conn_params, list) { in hci_conn_params_clear_disabled()
2899 static void hci_conn_params_clear_all(struct hci_dev *hdev) in hci_conn_params_clear_all() argument
2903 list_for_each_entry_safe(params, tmp, &hdev->le_conn_params, list) in hci_conn_params_clear_all()
2922 void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_copy_identity_address() argument
2925 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in hci_copy_identity_address()
2926 !bacmp(&hdev->bdaddr, BDADDR_ANY) || in hci_copy_identity_address()
2927 (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in hci_copy_identity_address()
2928 bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_copy_identity_address()
2929 bacpy(bdaddr, &hdev->static_addr); in hci_copy_identity_address()
2932 bacpy(bdaddr, &hdev->bdaddr); in hci_copy_identity_address()
2940 struct hci_dev *hdev; in hci_alloc_dev() local
2942 hdev = kzalloc(sizeof(*hdev), GFP_KERNEL); in hci_alloc_dev()
2943 if (!hdev) in hci_alloc_dev()
2946 hdev->pkt_type = (HCI_DM1 | HCI_DH1 | HCI_HV1); in hci_alloc_dev()
2947 hdev->esco_type = (ESCO_HV1); in hci_alloc_dev()
2948 hdev->link_mode = (HCI_LM_ACCEPT); in hci_alloc_dev()
2949 hdev->num_iac = 0x01; /* One IAC support is mandatory */ in hci_alloc_dev()
2950 hdev->io_capability = 0x03; /* No Input No Output */ in hci_alloc_dev()
2951 hdev->manufacturer = 0xffff; /* Default to internal use */ in hci_alloc_dev()
2952 hdev->inq_tx_power = HCI_TX_POWER_INVALID; in hci_alloc_dev()
2953 hdev->adv_tx_power = HCI_TX_POWER_INVALID; in hci_alloc_dev()
2954 hdev->adv_instance_cnt = 0; in hci_alloc_dev()
2955 hdev->cur_adv_instance = 0x00; in hci_alloc_dev()
2956 hdev->adv_instance_timeout = 0; in hci_alloc_dev()
2958 hdev->sniff_max_interval = 800; in hci_alloc_dev()
2959 hdev->sniff_min_interval = 80; in hci_alloc_dev()
2961 hdev->le_adv_channel_map = 0x07; in hci_alloc_dev()
2962 hdev->le_adv_min_interval = 0x0800; in hci_alloc_dev()
2963 hdev->le_adv_max_interval = 0x0800; in hci_alloc_dev()
2964 hdev->le_scan_interval = 0x0060; in hci_alloc_dev()
2965 hdev->le_scan_window = 0x0030; in hci_alloc_dev()
2966 hdev->le_conn_min_interval = 0x0028; in hci_alloc_dev()
2967 hdev->le_conn_max_interval = 0x0038; in hci_alloc_dev()
2968 hdev->le_conn_latency = 0x0000; in hci_alloc_dev()
2969 hdev->le_supv_timeout = 0x002a; in hci_alloc_dev()
2970 hdev->le_def_tx_len = 0x001b; in hci_alloc_dev()
2971 hdev->le_def_tx_time = 0x0148; in hci_alloc_dev()
2972 hdev->le_max_tx_len = 0x001b; in hci_alloc_dev()
2973 hdev->le_max_tx_time = 0x0148; in hci_alloc_dev()
2974 hdev->le_max_rx_len = 0x001b; in hci_alloc_dev()
2975 hdev->le_max_rx_time = 0x0148; in hci_alloc_dev()
2977 hdev->rpa_timeout = HCI_DEFAULT_RPA_TIMEOUT; in hci_alloc_dev()
2978 hdev->discov_interleaved_timeout = DISCOV_INTERLEAVED_TIMEOUT; in hci_alloc_dev()
2979 hdev->conn_info_min_age = DEFAULT_CONN_INFO_MIN_AGE; in hci_alloc_dev()
2980 hdev->conn_info_max_age = DEFAULT_CONN_INFO_MAX_AGE; in hci_alloc_dev()
2982 mutex_init(&hdev->lock); in hci_alloc_dev()
2983 mutex_init(&hdev->req_lock); in hci_alloc_dev()
2985 INIT_LIST_HEAD(&hdev->mgmt_pending); in hci_alloc_dev()
2986 INIT_LIST_HEAD(&hdev->blacklist); in hci_alloc_dev()
2987 INIT_LIST_HEAD(&hdev->whitelist); in hci_alloc_dev()
2988 INIT_LIST_HEAD(&hdev->uuids); in hci_alloc_dev()
2989 INIT_LIST_HEAD(&hdev->link_keys); in hci_alloc_dev()
2990 INIT_LIST_HEAD(&hdev->long_term_keys); in hci_alloc_dev()
2991 INIT_LIST_HEAD(&hdev->identity_resolving_keys); in hci_alloc_dev()
2992 INIT_LIST_HEAD(&hdev->remote_oob_data); in hci_alloc_dev()
2993 INIT_LIST_HEAD(&hdev->le_white_list); in hci_alloc_dev()
2994 INIT_LIST_HEAD(&hdev->le_conn_params); in hci_alloc_dev()
2995 INIT_LIST_HEAD(&hdev->pend_le_conns); in hci_alloc_dev()
2996 INIT_LIST_HEAD(&hdev->pend_le_reports); in hci_alloc_dev()
2997 INIT_LIST_HEAD(&hdev->conn_hash.list); in hci_alloc_dev()
2998 INIT_LIST_HEAD(&hdev->adv_instances); in hci_alloc_dev()
3000 INIT_WORK(&hdev->rx_work, hci_rx_work); in hci_alloc_dev()
3001 INIT_WORK(&hdev->cmd_work, hci_cmd_work); in hci_alloc_dev()
3002 INIT_WORK(&hdev->tx_work, hci_tx_work); in hci_alloc_dev()
3003 INIT_WORK(&hdev->power_on, hci_power_on); in hci_alloc_dev()
3004 INIT_WORK(&hdev->error_reset, hci_error_reset); in hci_alloc_dev()
3006 INIT_DELAYED_WORK(&hdev->power_off, hci_power_off); in hci_alloc_dev()
3008 skb_queue_head_init(&hdev->rx_q); in hci_alloc_dev()
3009 skb_queue_head_init(&hdev->cmd_q); in hci_alloc_dev()
3010 skb_queue_head_init(&hdev->raw_q); in hci_alloc_dev()
3012 init_waitqueue_head(&hdev->req_wait_q); in hci_alloc_dev()
3014 INIT_DELAYED_WORK(&hdev->cmd_timer, hci_cmd_timeout); in hci_alloc_dev()
3016 hci_request_setup(hdev); in hci_alloc_dev()
3018 hci_init_sysfs(hdev); in hci_alloc_dev()
3019 discovery_init(hdev); in hci_alloc_dev()
3021 return hdev; in hci_alloc_dev()
3026 void hci_free_dev(struct hci_dev *hdev) in hci_free_dev() argument
3029 put_device(&hdev->dev); in hci_free_dev()
3034 int hci_register_dev(struct hci_dev *hdev) in hci_register_dev() argument
3038 if (!hdev->open || !hdev->close || !hdev->send) in hci_register_dev()
3044 switch (hdev->dev_type) { in hci_register_dev()
3058 sprintf(hdev->name, "hci%d", id); in hci_register_dev()
3059 hdev->id = id; in hci_register_dev()
3061 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus); in hci_register_dev()
3063 hdev->workqueue = alloc_workqueue("%s", WQ_HIGHPRI | WQ_UNBOUND | in hci_register_dev()
3064 WQ_MEM_RECLAIM, 1, hdev->name); in hci_register_dev()
3065 if (!hdev->workqueue) { in hci_register_dev()
3070 hdev->req_workqueue = alloc_workqueue("%s", WQ_HIGHPRI | WQ_UNBOUND | in hci_register_dev()
3071 WQ_MEM_RECLAIM, 1, hdev->name); in hci_register_dev()
3072 if (!hdev->req_workqueue) { in hci_register_dev()
3073 destroy_workqueue(hdev->workqueue); in hci_register_dev()
3079 hdev->debugfs = debugfs_create_dir(hdev->name, bt_debugfs); in hci_register_dev()
3081 dev_set_name(&hdev->dev, "%s", hdev->name); in hci_register_dev()
3083 error = device_add(&hdev->dev); in hci_register_dev()
3087 hci_leds_init(hdev); in hci_register_dev()
3089 hdev->rfkill = rfkill_alloc(hdev->name, &hdev->dev, in hci_register_dev()
3091 hdev); in hci_register_dev()
3092 if (hdev->rfkill) { in hci_register_dev()
3093 if (rfkill_register(hdev->rfkill) < 0) { in hci_register_dev()
3094 rfkill_destroy(hdev->rfkill); in hci_register_dev()
3095 hdev->rfkill = NULL; in hci_register_dev()
3099 if (hdev->rfkill && rfkill_blocked(hdev->rfkill)) in hci_register_dev()
3100 hci_dev_set_flag(hdev, HCI_RFKILLED); in hci_register_dev()
3102 hci_dev_set_flag(hdev, HCI_SETUP); in hci_register_dev()
3103 hci_dev_set_flag(hdev, HCI_AUTO_OFF); in hci_register_dev()
3105 if (hdev->dev_type == HCI_PRIMARY) { in hci_register_dev()
3109 hci_dev_set_flag(hdev, HCI_BREDR_ENABLED); in hci_register_dev()
3113 list_add(&hdev->list, &hci_dev_list); in hci_register_dev()
3119 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in hci_register_dev()
3120 hci_dev_set_flag(hdev, HCI_UNCONFIGURED); in hci_register_dev()
3122 hci_sock_dev_event(hdev, HCI_DEV_REG); in hci_register_dev()
3123 hci_dev_hold(hdev); in hci_register_dev()
3125 queue_work(hdev->req_workqueue, &hdev->power_on); in hci_register_dev()
3130 destroy_workqueue(hdev->workqueue); in hci_register_dev()
3131 destroy_workqueue(hdev->req_workqueue); in hci_register_dev()
3133 ida_simple_remove(&hci_index_ida, hdev->id); in hci_register_dev()
3140 void hci_unregister_dev(struct hci_dev *hdev) in hci_unregister_dev() argument
3144 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus); in hci_unregister_dev()
3146 hci_dev_set_flag(hdev, HCI_UNREGISTER); in hci_unregister_dev()
3148 id = hdev->id; in hci_unregister_dev()
3151 list_del(&hdev->list); in hci_unregister_dev()
3154 cancel_work_sync(&hdev->power_on); in hci_unregister_dev()
3156 hci_dev_do_close(hdev); in hci_unregister_dev()
3158 if (!test_bit(HCI_INIT, &hdev->flags) && in hci_unregister_dev()
3159 !hci_dev_test_flag(hdev, HCI_SETUP) && in hci_unregister_dev()
3160 !hci_dev_test_flag(hdev, HCI_CONFIG)) { in hci_unregister_dev()
3161 hci_dev_lock(hdev); in hci_unregister_dev()
3162 mgmt_index_removed(hdev); in hci_unregister_dev()
3163 hci_dev_unlock(hdev); in hci_unregister_dev()
3168 BUG_ON(!list_empty(&hdev->mgmt_pending)); in hci_unregister_dev()
3170 hci_sock_dev_event(hdev, HCI_DEV_UNREG); in hci_unregister_dev()
3172 if (hdev->rfkill) { in hci_unregister_dev()
3173 rfkill_unregister(hdev->rfkill); in hci_unregister_dev()
3174 rfkill_destroy(hdev->rfkill); in hci_unregister_dev()
3177 device_del(&hdev->dev); in hci_unregister_dev()
3179 debugfs_remove_recursive(hdev->debugfs); in hci_unregister_dev()
3180 kfree_const(hdev->hw_info); in hci_unregister_dev()
3181 kfree_const(hdev->fw_info); in hci_unregister_dev()
3183 destroy_workqueue(hdev->workqueue); in hci_unregister_dev()
3184 destroy_workqueue(hdev->req_workqueue); in hci_unregister_dev()
3186 hci_dev_lock(hdev); in hci_unregister_dev()
3187 hci_bdaddr_list_clear(&hdev->blacklist); in hci_unregister_dev()
3188 hci_bdaddr_list_clear(&hdev->whitelist); in hci_unregister_dev()
3189 hci_uuids_clear(hdev); in hci_unregister_dev()
3190 hci_link_keys_clear(hdev); in hci_unregister_dev()
3191 hci_smp_ltks_clear(hdev); in hci_unregister_dev()
3192 hci_smp_irks_clear(hdev); in hci_unregister_dev()
3193 hci_remote_oob_data_clear(hdev); in hci_unregister_dev()
3194 hci_adv_instances_clear(hdev); in hci_unregister_dev()
3195 hci_bdaddr_list_clear(&hdev->le_white_list); in hci_unregister_dev()
3196 hci_conn_params_clear_all(hdev); in hci_unregister_dev()
3197 hci_discovery_filter_clear(hdev); in hci_unregister_dev()
3198 hci_dev_unlock(hdev); in hci_unregister_dev()
3200 hci_dev_put(hdev); in hci_unregister_dev()
3207 int hci_suspend_dev(struct hci_dev *hdev) in hci_suspend_dev() argument
3209 hci_sock_dev_event(hdev, HCI_DEV_SUSPEND); in hci_suspend_dev()
3215 int hci_resume_dev(struct hci_dev *hdev) in hci_resume_dev() argument
3217 hci_sock_dev_event(hdev, HCI_DEV_RESUME); in hci_resume_dev()
3223 int hci_reset_dev(struct hci_dev *hdev) in hci_reset_dev() argument
3236 return hci_recv_frame(hdev, skb); in hci_reset_dev()
3241 int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb) in hci_recv_frame() argument
3243 if (!hdev || (!test_bit(HCI_UP, &hdev->flags) in hci_recv_frame()
3244 && !test_bit(HCI_INIT, &hdev->flags))) { in hci_recv_frame()
3262 skb_queue_tail(&hdev->rx_q, skb); in hci_recv_frame()
3263 queue_work(hdev->workqueue, &hdev->rx_work); in hci_recv_frame()
3270 int hci_recv_diag(struct hci_dev *hdev, struct sk_buff *skb) in hci_recv_diag() argument
3278 skb_queue_tail(&hdev->rx_q, skb); in hci_recv_diag()
3279 queue_work(hdev->workqueue, &hdev->rx_work); in hci_recv_diag()
3285 void hci_set_hw_info(struct hci_dev *hdev, const char *fmt, ...) in hci_set_hw_info() argument
3290 kfree_const(hdev->hw_info); in hci_set_hw_info()
3291 hdev->hw_info = kvasprintf_const(GFP_KERNEL, fmt, vargs); in hci_set_hw_info()
3296 void hci_set_fw_info(struct hci_dev *hdev, const char *fmt, ...) in hci_set_fw_info() argument
3301 kfree_const(hdev->fw_info); in hci_set_fw_info()
3302 hdev->fw_info = kvasprintf_const(GFP_KERNEL, fmt, vargs); in hci_set_fw_info()
3333 static void hci_send_frame(struct hci_dev *hdev, struct sk_buff *skb) in hci_send_frame() argument
3337 BT_DBG("%s type %d len %d", hdev->name, hci_skb_pkt_type(skb), in hci_send_frame()
3344 hci_send_to_monitor(hdev, skb); in hci_send_frame()
3346 if (atomic_read(&hdev->promisc)) { in hci_send_frame()
3348 hci_send_to_sock(hdev, skb); in hci_send_frame()
3354 if (!test_bit(HCI_RUNNING, &hdev->flags)) { in hci_send_frame()
3359 err = hdev->send(hdev, skb); in hci_send_frame()
3361 BT_ERR("%s sending frame failed (%d)", hdev->name, err); in hci_send_frame()
3367 int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, in hci_send_cmd() argument
3372 BT_DBG("%s opcode 0x%4.4x plen %d", hdev->name, opcode, plen); in hci_send_cmd()
3374 skb = hci_prepare_cmd(hdev, opcode, plen, param); in hci_send_cmd()
3376 BT_ERR("%s no memory for command", hdev->name); in hci_send_cmd()
3385 skb_queue_tail(&hdev->cmd_q, skb); in hci_send_cmd()
3386 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_send_cmd()
3392 void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode) in hci_sent_cmd_data() argument
3396 if (!hdev->sent_cmd) in hci_sent_cmd_data()
3399 hdr = (void *) hdev->sent_cmd->data; in hci_sent_cmd_data()
3404 BT_DBG("%s opcode 0x%4.4x", hdev->name, opcode); in hci_sent_cmd_data()
3406 return hdev->sent_cmd->data + HCI_COMMAND_HDR_SIZE; in hci_sent_cmd_data()
3410 struct sk_buff *hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen, in hci_cmd_sync() argument
3415 if (!test_bit(HCI_UP, &hdev->flags)) in hci_cmd_sync()
3418 bt_dev_dbg(hdev, "opcode 0x%4.4x plen %d", opcode, plen); in hci_cmd_sync()
3420 hci_req_sync_lock(hdev); in hci_cmd_sync()
3421 skb = __hci_cmd_sync(hdev, opcode, plen, param, timeout); in hci_cmd_sync()
3422 hci_req_sync_unlock(hdev); in hci_cmd_sync()
3445 struct hci_dev *hdev = conn->hdev; in hci_queue_acl() local
3453 switch (hdev->dev_type) { in hci_queue_acl()
3461 BT_ERR("%s unknown dev_type %d", hdev->name, hdev->dev_type); in hci_queue_acl()
3468 BT_DBG("%s nonfrag skb %p len %d", hdev->name, skb, skb->len); in hci_queue_acl()
3473 BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len); in hci_queue_acl()
3494 BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len); in hci_queue_acl()
3505 struct hci_dev *hdev = chan->conn->hdev; in hci_send_acl() local
3507 BT_DBG("%s chan %p flags 0x%4.4x", hdev->name, chan, flags); in hci_send_acl()
3511 queue_work(hdev->workqueue, &hdev->tx_work); in hci_send_acl()
3517 struct hci_dev *hdev = conn->hdev; in hci_send_sco() local
3520 BT_DBG("%s len %d", hdev->name, skb->len); in hci_send_sco()
3532 queue_work(hdev->workqueue, &hdev->tx_work); in hci_send_sco()
3538 static struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type, in hci_low_sent() argument
3541 struct hci_conn_hash *h = &hdev->conn_hash; in hci_low_sent()
3564 if (hci_conn_num(hdev, type) == num) in hci_low_sent()
3575 cnt = hdev->acl_cnt; in hci_low_sent()
3579 cnt = hdev->sco_cnt; in hci_low_sent()
3582 cnt = hdev->le_mtu ? hdev->le_cnt : hdev->acl_cnt; in hci_low_sent()
3598 static void hci_link_tx_to(struct hci_dev *hdev, __u8 type) in hci_link_tx_to() argument
3600 struct hci_conn_hash *h = &hdev->conn_hash; in hci_link_tx_to()
3603 BT_ERR("%s link tx timeout", hdev->name); in hci_link_tx_to()
3611 hdev->name, &c->dst); in hci_link_tx_to()
3619 static struct hci_chan *hci_chan_sent(struct hci_dev *hdev, __u8 type, in hci_chan_sent() argument
3622 struct hci_conn_hash *h = &hdev->conn_hash; in hci_chan_sent()
3628 BT_DBG("%s", hdev->name); in hci_chan_sent()
3667 if (hci_conn_num(hdev, type) == conn_num) in hci_chan_sent()
3678 cnt = hdev->acl_cnt; in hci_chan_sent()
3681 cnt = hdev->block_cnt; in hci_chan_sent()
3685 cnt = hdev->sco_cnt; in hci_chan_sent()
3688 cnt = hdev->le_mtu ? hdev->le_cnt : hdev->acl_cnt; in hci_chan_sent()
3701 static void hci_prio_recalculate(struct hci_dev *hdev, __u8 type) in hci_prio_recalculate() argument
3703 struct hci_conn_hash *h = &hdev->conn_hash; in hci_prio_recalculate()
3707 BT_DBG("%s", hdev->name); in hci_prio_recalculate()
3743 if (hci_conn_num(hdev, type) == num) in hci_prio_recalculate()
3751 static inline int __get_blocks(struct hci_dev *hdev, struct sk_buff *skb) in __get_blocks() argument
3754 return DIV_ROUND_UP(skb->len - HCI_ACL_HDR_SIZE, hdev->block_len); in __get_blocks()
3757 static void __check_timeout(struct hci_dev *hdev, unsigned int cnt) in __check_timeout() argument
3759 if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in __check_timeout()
3762 if (!cnt && time_after(jiffies, hdev->acl_last_tx + in __check_timeout()
3764 hci_link_tx_to(hdev, ACL_LINK); in __check_timeout()
3768 static void hci_sched_acl_pkt(struct hci_dev *hdev) in hci_sched_acl_pkt() argument
3770 unsigned int cnt = hdev->acl_cnt; in hci_sched_acl_pkt()
3775 __check_timeout(hdev, cnt); in hci_sched_acl_pkt()
3777 while (hdev->acl_cnt && in hci_sched_acl_pkt()
3778 (chan = hci_chan_sent(hdev, ACL_LINK, "e))) { in hci_sched_acl_pkt()
3793 hci_send_frame(hdev, skb); in hci_sched_acl_pkt()
3794 hdev->acl_last_tx = jiffies; in hci_sched_acl_pkt()
3796 hdev->acl_cnt--; in hci_sched_acl_pkt()
3802 if (cnt != hdev->acl_cnt) in hci_sched_acl_pkt()
3803 hci_prio_recalculate(hdev, ACL_LINK); in hci_sched_acl_pkt()
3806 static void hci_sched_acl_blk(struct hci_dev *hdev) in hci_sched_acl_blk() argument
3808 unsigned int cnt = hdev->block_cnt; in hci_sched_acl_blk()
3814 __check_timeout(hdev, cnt); in hci_sched_acl_blk()
3816 BT_DBG("%s", hdev->name); in hci_sched_acl_blk()
3818 if (hdev->dev_type == HCI_AMP) in hci_sched_acl_blk()
3823 while (hdev->block_cnt > 0 && in hci_sched_acl_blk()
3824 (chan = hci_chan_sent(hdev, type, "e))) { in hci_sched_acl_blk()
3838 blocks = __get_blocks(hdev, skb); in hci_sched_acl_blk()
3839 if (blocks > hdev->block_cnt) in hci_sched_acl_blk()
3845 hci_send_frame(hdev, skb); in hci_sched_acl_blk()
3846 hdev->acl_last_tx = jiffies; in hci_sched_acl_blk()
3848 hdev->block_cnt -= blocks; in hci_sched_acl_blk()
3856 if (cnt != hdev->block_cnt) in hci_sched_acl_blk()
3857 hci_prio_recalculate(hdev, type); in hci_sched_acl_blk()
3860 static void hci_sched_acl(struct hci_dev *hdev) in hci_sched_acl() argument
3862 BT_DBG("%s", hdev->name); in hci_sched_acl()
3865 if (!hci_conn_num(hdev, ACL_LINK) && hdev->dev_type == HCI_PRIMARY) in hci_sched_acl()
3869 if (!hci_conn_num(hdev, AMP_LINK) && hdev->dev_type == HCI_AMP) in hci_sched_acl()
3872 switch (hdev->flow_ctl_mode) { in hci_sched_acl()
3874 hci_sched_acl_pkt(hdev); in hci_sched_acl()
3878 hci_sched_acl_blk(hdev); in hci_sched_acl()
3884 static void hci_sched_sco(struct hci_dev *hdev) in hci_sched_sco() argument
3890 BT_DBG("%s", hdev->name); in hci_sched_sco()
3892 if (!hci_conn_num(hdev, SCO_LINK)) in hci_sched_sco()
3895 while (hdev->sco_cnt && (conn = hci_low_sent(hdev, SCO_LINK, "e))) { in hci_sched_sco()
3898 hci_send_frame(hdev, skb); in hci_sched_sco()
3907 static void hci_sched_esco(struct hci_dev *hdev) in hci_sched_esco() argument
3913 BT_DBG("%s", hdev->name); in hci_sched_esco()
3915 if (!hci_conn_num(hdev, ESCO_LINK)) in hci_sched_esco()
3918 while (hdev->sco_cnt && (conn = hci_low_sent(hdev, ESCO_LINK, in hci_sched_esco()
3922 hci_send_frame(hdev, skb); in hci_sched_esco()
3931 static void hci_sched_le(struct hci_dev *hdev) in hci_sched_le() argument
3937 BT_DBG("%s", hdev->name); in hci_sched_le()
3939 if (!hci_conn_num(hdev, LE_LINK)) in hci_sched_le()
3942 if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_sched_le()
3945 if (!hdev->le_cnt && hdev->le_pkts && in hci_sched_le()
3946 time_after(jiffies, hdev->le_last_tx + HZ * 45)) in hci_sched_le()
3947 hci_link_tx_to(hdev, LE_LINK); in hci_sched_le()
3950 cnt = hdev->le_pkts ? hdev->le_cnt : hdev->acl_cnt; in hci_sched_le()
3952 while (cnt && (chan = hci_chan_sent(hdev, LE_LINK, "e))) { in hci_sched_le()
3964 hci_send_frame(hdev, skb); in hci_sched_le()
3965 hdev->le_last_tx = jiffies; in hci_sched_le()
3973 if (hdev->le_pkts) in hci_sched_le()
3974 hdev->le_cnt = cnt; in hci_sched_le()
3976 hdev->acl_cnt = cnt; in hci_sched_le()
3979 hci_prio_recalculate(hdev, LE_LINK); in hci_sched_le()
3984 struct hci_dev *hdev = container_of(work, struct hci_dev, tx_work); in hci_tx_work() local
3987 BT_DBG("%s acl %d sco %d le %d", hdev->name, hdev->acl_cnt, in hci_tx_work()
3988 hdev->sco_cnt, hdev->le_cnt); in hci_tx_work()
3990 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_tx_work()
3992 hci_sched_acl(hdev); in hci_tx_work()
3993 hci_sched_sco(hdev); in hci_tx_work()
3994 hci_sched_esco(hdev); in hci_tx_work()
3995 hci_sched_le(hdev); in hci_tx_work()
3999 while ((skb = skb_dequeue(&hdev->raw_q))) in hci_tx_work()
4000 hci_send_frame(hdev, skb); in hci_tx_work()
4006 static void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb) in hci_acldata_packet() argument
4018 BT_DBG("%s len %d handle 0x%4.4x flags 0x%4.4x", hdev->name, skb->len, in hci_acldata_packet()
4021 hdev->stat.acl_rx++; in hci_acldata_packet()
4023 hci_dev_lock(hdev); in hci_acldata_packet()
4024 conn = hci_conn_hash_lookup_handle(hdev, handle); in hci_acldata_packet()
4025 hci_dev_unlock(hdev); in hci_acldata_packet()
4035 hdev->name, handle); in hci_acldata_packet()
4042 static void hci_scodata_packet(struct hci_dev *hdev, struct sk_buff *skb) in hci_scodata_packet() argument
4052 BT_DBG("%s len %d handle 0x%4.4x", hdev->name, skb->len, handle); in hci_scodata_packet()
4054 hdev->stat.sco_rx++; in hci_scodata_packet()
4056 hci_dev_lock(hdev); in hci_scodata_packet()
4057 conn = hci_conn_hash_lookup_handle(hdev, handle); in hci_scodata_packet()
4058 hci_dev_unlock(hdev); in hci_scodata_packet()
4066 hdev->name, handle); in hci_scodata_packet()
4072 static bool hci_req_is_complete(struct hci_dev *hdev) in hci_req_is_complete() argument
4076 skb = skb_peek(&hdev->cmd_q); in hci_req_is_complete()
4083 static void hci_resend_last(struct hci_dev *hdev) in hci_resend_last() argument
4089 if (!hdev->sent_cmd) in hci_resend_last()
4092 sent = (void *) hdev->sent_cmd->data; in hci_resend_last()
4097 skb = skb_clone(hdev->sent_cmd, GFP_KERNEL); in hci_resend_last()
4101 skb_queue_head(&hdev->cmd_q, skb); in hci_resend_last()
4102 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_resend_last()
4105 void hci_req_cmd_complete(struct hci_dev *hdev, u16 opcode, u8 status, in hci_req_cmd_complete() argument
4117 if (!hci_sent_cmd_data(hdev, opcode)) { in hci_req_cmd_complete()
4124 if (test_bit(HCI_INIT, &hdev->flags) && opcode == HCI_OP_RESET) in hci_req_cmd_complete()
4125 hci_resend_last(hdev); in hci_req_cmd_complete()
4133 if (!status && !hci_req_is_complete(hdev)) in hci_req_cmd_complete()
4140 if (bt_cb(hdev->sent_cmd)->hci.req_flags & HCI_REQ_SKB) { in hci_req_cmd_complete()
4141 *req_complete_skb = bt_cb(hdev->sent_cmd)->hci.req_complete_skb; in hci_req_cmd_complete()
4145 if (bt_cb(hdev->sent_cmd)->hci.req_complete) { in hci_req_cmd_complete()
4146 *req_complete = bt_cb(hdev->sent_cmd)->hci.req_complete; in hci_req_cmd_complete()
4151 spin_lock_irqsave(&hdev->cmd_q.lock, flags); in hci_req_cmd_complete()
4152 while ((skb = __skb_dequeue(&hdev->cmd_q))) { in hci_req_cmd_complete()
4154 __skb_queue_head(&hdev->cmd_q, skb); in hci_req_cmd_complete()
4164 spin_unlock_irqrestore(&hdev->cmd_q.lock, flags); in hci_req_cmd_complete()
4169 struct hci_dev *hdev = container_of(work, struct hci_dev, rx_work); in hci_rx_work() local
4172 BT_DBG("%s", hdev->name); in hci_rx_work()
4174 while ((skb = skb_dequeue(&hdev->rx_q))) { in hci_rx_work()
4176 hci_send_to_monitor(hdev, skb); in hci_rx_work()
4178 if (atomic_read(&hdev->promisc)) { in hci_rx_work()
4180 hci_send_to_sock(hdev, skb); in hci_rx_work()
4183 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_rx_work()
4188 if (test_bit(HCI_INIT, &hdev->flags)) { in hci_rx_work()
4201 BT_DBG("%s Event packet", hdev->name); in hci_rx_work()
4202 hci_event_packet(hdev, skb); in hci_rx_work()
4206 BT_DBG("%s ACL data packet", hdev->name); in hci_rx_work()
4207 hci_acldata_packet(hdev, skb); in hci_rx_work()
4211 BT_DBG("%s SCO data packet", hdev->name); in hci_rx_work()
4212 hci_scodata_packet(hdev, skb); in hci_rx_work()
4224 struct hci_dev *hdev = container_of(work, struct hci_dev, cmd_work); in hci_cmd_work() local
4227 BT_DBG("%s cmd_cnt %d cmd queued %d", hdev->name, in hci_cmd_work()
4228 atomic_read(&hdev->cmd_cnt), skb_queue_len(&hdev->cmd_q)); in hci_cmd_work()
4231 if (atomic_read(&hdev->cmd_cnt)) { in hci_cmd_work()
4232 skb = skb_dequeue(&hdev->cmd_q); in hci_cmd_work()
4236 kfree_skb(hdev->sent_cmd); in hci_cmd_work()
4238 hdev->sent_cmd = skb_clone(skb, GFP_KERNEL); in hci_cmd_work()
4239 if (hdev->sent_cmd) { in hci_cmd_work()
4240 atomic_dec(&hdev->cmd_cnt); in hci_cmd_work()
4241 hci_send_frame(hdev, skb); in hci_cmd_work()
4242 if (test_bit(HCI_RESET, &hdev->flags)) in hci_cmd_work()
4243 cancel_delayed_work(&hdev->cmd_timer); in hci_cmd_work()
4245 schedule_delayed_work(&hdev->cmd_timer, in hci_cmd_work()
4248 skb_queue_head(&hdev->cmd_q, skb); in hci_cmd_work()
4249 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_cmd_work()