• Home
  • Raw
  • Download

Lines Matching refs:hdev

37 void hci_req_init(struct hci_request *req, struct hci_dev *hdev)  in hci_req_init()  argument
40 req->hdev = hdev; in hci_req_init()
49 bool hci_req_status_pend(struct hci_dev *hdev) in hci_req_status_pend() argument
51 return hdev->req_status == HCI_REQ_PEND; in hci_req_status_pend()
57 struct hci_dev *hdev = req->hdev; in req_run() local
83 spin_lock_irqsave(&hdev->cmd_q.lock, flags); in req_run()
84 skb_queue_splice_tail(&req->cmd_q, &hdev->cmd_q); in req_run()
85 spin_unlock_irqrestore(&hdev->cmd_q.lock, flags); in req_run()
87 queue_work(hdev->workqueue, &hdev->cmd_work); in req_run()
102 static void hci_req_sync_complete(struct hci_dev *hdev, u8 result, u16 opcode, in hci_req_sync_complete() argument
105 BT_DBG("%s result 0x%2.2x", hdev->name, result); in hci_req_sync_complete()
107 if (hdev->req_status == HCI_REQ_PEND) { in hci_req_sync_complete()
108 hdev->req_result = result; in hci_req_sync_complete()
109 hdev->req_status = HCI_REQ_DONE; in hci_req_sync_complete()
111 hdev->req_skb = skb_get(skb); in hci_req_sync_complete()
112 wake_up_interruptible(&hdev->req_wait_q); in hci_req_sync_complete()
116 void hci_req_sync_cancel(struct hci_dev *hdev, int err) in hci_req_sync_cancel() argument
118 BT_DBG("%s err 0x%2.2x", hdev->name, err); in hci_req_sync_cancel()
120 if (hdev->req_status == HCI_REQ_PEND) { in hci_req_sync_cancel()
121 hdev->req_result = err; in hci_req_sync_cancel()
122 hdev->req_status = HCI_REQ_CANCELED; in hci_req_sync_cancel()
123 wake_up_interruptible(&hdev->req_wait_q); in hci_req_sync_cancel()
127 struct sk_buff *__hci_cmd_sync_ev(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_sync_ev() argument
134 BT_DBG("%s", hdev->name); in __hci_cmd_sync_ev()
136 hci_req_init(&req, hdev); in __hci_cmd_sync_ev()
140 hdev->req_status = HCI_REQ_PEND; in __hci_cmd_sync_ev()
146 err = wait_event_interruptible_timeout(hdev->req_wait_q, in __hci_cmd_sync_ev()
147 hdev->req_status != HCI_REQ_PEND, timeout); in __hci_cmd_sync_ev()
152 switch (hdev->req_status) { in __hci_cmd_sync_ev()
154 err = -bt_to_errno(hdev->req_result); in __hci_cmd_sync_ev()
158 err = -hdev->req_result; in __hci_cmd_sync_ev()
166 hdev->req_status = hdev->req_result = 0; in __hci_cmd_sync_ev()
167 skb = hdev->req_skb; in __hci_cmd_sync_ev()
168 hdev->req_skb = NULL; in __hci_cmd_sync_ev()
170 BT_DBG("%s end: err %d", hdev->name, err); in __hci_cmd_sync_ev()
184 struct sk_buff *__hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_sync() argument
187 return __hci_cmd_sync_ev(hdev, opcode, plen, param, 0, timeout); in __hci_cmd_sync()
192 int __hci_req_sync(struct hci_dev *hdev, int (*func)(struct hci_request *req, in __hci_req_sync() argument
199 BT_DBG("%s start", hdev->name); in __hci_req_sync()
201 hci_req_init(&req, hdev); in __hci_req_sync()
203 hdev->req_status = HCI_REQ_PEND; in __hci_req_sync()
214 hdev->req_status = 0; in __hci_req_sync()
233 err = wait_event_interruptible_timeout(hdev->req_wait_q, in __hci_req_sync()
234 hdev->req_status != HCI_REQ_PEND, timeout); in __hci_req_sync()
239 switch (hdev->req_status) { in __hci_req_sync()
241 err = -bt_to_errno(hdev->req_result); in __hci_req_sync()
243 *hci_status = hdev->req_result; in __hci_req_sync()
247 err = -hdev->req_result; in __hci_req_sync()
259 kfree_skb(hdev->req_skb); in __hci_req_sync()
260 hdev->req_skb = NULL; in __hci_req_sync()
261 hdev->req_status = hdev->req_result = 0; in __hci_req_sync()
263 BT_DBG("%s end: err %d", hdev->name, err); in __hci_req_sync()
268 int hci_req_sync(struct hci_dev *hdev, int (*req)(struct hci_request *req, in hci_req_sync() argument
275 hci_req_sync_lock(hdev); in hci_req_sync()
280 if (test_bit(HCI_UP, &hdev->flags)) in hci_req_sync()
281 ret = __hci_req_sync(hdev, req, opt, timeout, hci_status); in hci_req_sync()
284 hci_req_sync_unlock(hdev); in hci_req_sync()
289 struct sk_buff *hci_prepare_cmd(struct hci_dev *hdev, u16 opcode, u32 plen, in hci_prepare_cmd() argument
319 struct hci_dev *hdev = req->hdev; in hci_req_add_ev() local
322 BT_DBG("%s opcode 0x%4.4x plen %d", hdev->name, opcode, plen); in hci_req_add_ev()
330 skb = hci_prepare_cmd(hdev, opcode, plen, param); in hci_req_add_ev()
332 bt_dev_err(hdev, "no memory for command (opcode 0x%4.4x)", in hci_req_add_ev()
354 struct hci_dev *hdev = req->hdev; in __hci_req_write_fast_connectable() local
358 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in __hci_req_write_fast_connectable()
361 if (hdev->hci_ver < BLUETOOTH_VER_1_2) in __hci_req_write_fast_connectable()
370 type = hdev->def_page_scan_type; in __hci_req_write_fast_connectable()
371 acp.interval = cpu_to_le16(hdev->def_page_scan_int); in __hci_req_write_fast_connectable()
374 acp.window = cpu_to_le16(hdev->def_page_scan_window); in __hci_req_write_fast_connectable()
376 if (__cpu_to_le16(hdev->page_scan_interval) != acp.interval || in __hci_req_write_fast_connectable()
377 __cpu_to_le16(hdev->page_scan_window) != acp.window) in __hci_req_write_fast_connectable()
381 if (hdev->page_scan_type != type) in __hci_req_write_fast_connectable()
385 static void start_interleave_scan(struct hci_dev *hdev) in start_interleave_scan() argument
387 hdev->interleave_scan_state = INTERLEAVE_SCAN_NO_FILTER; in start_interleave_scan()
388 queue_delayed_work(hdev->req_workqueue, in start_interleave_scan()
389 &hdev->interleave_scan, 0); in start_interleave_scan()
392 static bool is_interleave_scanning(struct hci_dev *hdev) in is_interleave_scanning() argument
394 return hdev->interleave_scan_state != INTERLEAVE_SCAN_NONE; in is_interleave_scanning()
397 static void cancel_interleave_scan(struct hci_dev *hdev) in cancel_interleave_scan() argument
399 bt_dev_dbg(hdev, "cancelling interleave scan"); in cancel_interleave_scan()
401 cancel_delayed_work_sync(&hdev->interleave_scan); in cancel_interleave_scan()
403 hdev->interleave_scan_state = INTERLEAVE_SCAN_NONE; in cancel_interleave_scan()
409 static bool __hci_update_interleaved_scan(struct hci_dev *hdev) in __hci_update_interleaved_scan() argument
415 bool use_interleaving = hci_is_adv_monitoring(hdev) && in __hci_update_interleaved_scan()
416 !(list_empty(&hdev->pend_le_conns) && in __hci_update_interleaved_scan()
417 list_empty(&hdev->pend_le_reports)); in __hci_update_interleaved_scan()
418 bool is_interleaving = is_interleave_scanning(hdev); in __hci_update_interleaved_scan()
421 start_interleave_scan(hdev); in __hci_update_interleaved_scan()
422 bt_dev_dbg(hdev, "starting interleave scan"); in __hci_update_interleaved_scan()
427 cancel_interleave_scan(hdev); in __hci_update_interleaved_scan()
440 struct hci_dev *hdev = req->hdev; in __hci_update_background_scan() local
442 if (!test_bit(HCI_UP, &hdev->flags) || in __hci_update_background_scan()
443 test_bit(HCI_INIT, &hdev->flags) || in __hci_update_background_scan()
444 hci_dev_test_flag(hdev, HCI_SETUP) || in __hci_update_background_scan()
445 hci_dev_test_flag(hdev, HCI_CONFIG) || in __hci_update_background_scan()
446 hci_dev_test_flag(hdev, HCI_AUTO_OFF) || in __hci_update_background_scan()
447 hci_dev_test_flag(hdev, HCI_UNREGISTER)) in __hci_update_background_scan()
451 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in __hci_update_background_scan()
455 if (hdev->discovery.state != DISCOVERY_STOPPED) in __hci_update_background_scan()
465 hci_discovery_filter_clear(hdev); in __hci_update_background_scan()
467 BT_DBG("%s ADV monitoring is %s", hdev->name, in __hci_update_background_scan()
468 hci_is_adv_monitoring(hdev) ? "on" : "off"); in __hci_update_background_scan()
470 if (list_empty(&hdev->pend_le_conns) && in __hci_update_background_scan()
471 list_empty(&hdev->pend_le_reports) && in __hci_update_background_scan()
472 !hci_is_adv_monitoring(hdev)) { in __hci_update_background_scan()
479 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN)) in __hci_update_background_scan()
484 BT_DBG("%s stopping background scanning", hdev->name); in __hci_update_background_scan()
494 if (hci_lookup_le_connect(hdev)) in __hci_update_background_scan()
500 if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) in __hci_update_background_scan()
504 bt_dev_dbg(hdev, "starting background scanning"); in __hci_update_background_scan()
510 struct hci_dev *hdev = req->hdev; in __hci_req_update_name() local
513 memcpy(cp.name, hdev->dev_name, sizeof(cp.name)); in __hci_req_update_name()
520 static u8 *create_uuid16_list(struct hci_dev *hdev, u8 *data, ptrdiff_t len) in create_uuid16_list() argument
528 list_for_each_entry(uuid, &hdev->uuids, list) { in create_uuid16_list()
562 static u8 *create_uuid32_list(struct hci_dev *hdev, u8 *data, ptrdiff_t len) in create_uuid32_list() argument
570 list_for_each_entry(uuid, &hdev->uuids, list) { in create_uuid32_list()
595 static u8 *create_uuid128_list(struct hci_dev *hdev, u8 *data, ptrdiff_t len) in create_uuid128_list() argument
603 list_for_each_entry(uuid, &hdev->uuids, list) { in create_uuid128_list()
628 static void create_eir(struct hci_dev *hdev, u8 *data) in create_eir() argument
633 name_len = strlen(hdev->dev_name); in create_eir()
646 memcpy(ptr + 2, hdev->dev_name, name_len); in create_eir()
651 if (hdev->inq_tx_power != HCI_TX_POWER_INVALID) { in create_eir()
654 ptr[2] = (u8) hdev->inq_tx_power; in create_eir()
659 if (hdev->devid_source > 0) { in create_eir()
663 put_unaligned_le16(hdev->devid_source, ptr + 2); in create_eir()
664 put_unaligned_le16(hdev->devid_vendor, ptr + 4); in create_eir()
665 put_unaligned_le16(hdev->devid_product, ptr + 6); in create_eir()
666 put_unaligned_le16(hdev->devid_version, ptr + 8); in create_eir()
671 ptr = create_uuid16_list(hdev, ptr, HCI_MAX_EIR_LENGTH - (ptr - data)); in create_eir()
672 ptr = create_uuid32_list(hdev, ptr, HCI_MAX_EIR_LENGTH - (ptr - data)); in create_eir()
673 ptr = create_uuid128_list(hdev, ptr, HCI_MAX_EIR_LENGTH - (ptr - data)); in create_eir()
678 struct hci_dev *hdev = req->hdev; in __hci_req_update_eir() local
681 if (!hdev_is_powered(hdev)) in __hci_req_update_eir()
684 if (!lmp_ext_inq_capable(hdev)) in __hci_req_update_eir()
687 if (!hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in __hci_req_update_eir()
690 if (hci_dev_test_flag(hdev, HCI_SERVICE_CACHE)) in __hci_req_update_eir()
695 create_eir(hdev, cp.data); in __hci_req_update_eir()
697 if (memcmp(cp.data, hdev->eir, sizeof(cp.data)) == 0) in __hci_req_update_eir()
700 memcpy(hdev->eir, cp.data, sizeof(cp.data)); in __hci_req_update_eir()
707 struct hci_dev *hdev = req->hdev; in hci_req_add_le_scan_disable() local
709 if (hdev->scanning_paused) { in hci_req_add_le_scan_disable()
710 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in hci_req_add_le_scan_disable()
714 if (use_ext_scan(hdev)) { in hci_req_add_le_scan_disable()
730 if (use_ll_privacy(hdev) && in hci_req_add_le_scan_disable()
731 hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY) && in hci_req_add_le_scan_disable()
732 hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION) && !rpa_le_conn) { in hci_req_add_le_scan_disable()
747 bt_dev_dbg(req->hdev, "Remove %pMR (0x%x) from accept list", &cp.bdaddr, in del_from_accept_list()
751 if (use_ll_privacy(req->hdev) && in del_from_accept_list()
752 hci_dev_test_flag(req->hdev, HCI_ENABLE_LL_PRIVACY)) { in del_from_accept_list()
755 irk = hci_find_irk_by_addr(req->hdev, bdaddr, bdaddr_type); in del_from_accept_list()
774 struct hci_dev *hdev = req->hdev; in add_to_accept_list() local
777 if (hci_bdaddr_list_lookup(&hdev->le_accept_list, &params->addr, in add_to_accept_list()
782 if (*num_entries >= hdev->le_accept_list_size) in add_to_accept_list()
787 !hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY) && in add_to_accept_list()
788 hci_find_irk_by_addr(hdev, &params->addr, params->addr_type)) { in add_to_accept_list()
793 if (hdev->suspended && !hci_conn_test_flag(HCI_CONN_FLAG_REMOTE_WAKEUP, in add_to_accept_list()
801 bt_dev_dbg(hdev, "Add %pMR (0x%x) to accept list", &cp.bdaddr, in add_to_accept_list()
805 if (use_ll_privacy(hdev) && in add_to_accept_list()
806 hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY)) { in add_to_accept_list()
809 irk = hci_find_irk_by_addr(hdev, &params->addr, in add_to_accept_list()
818 if (hci_dev_test_flag(hdev, HCI_PRIVACY)) in add_to_accept_list()
819 memcpy(cp.local_irk, hdev->irk, 16); in add_to_accept_list()
833 struct hci_dev *hdev = req->hdev; in update_accept_list() local
843 bool allow_rpa = hdev->suspended; in update_accept_list()
845 if (use_ll_privacy(hdev) && in update_accept_list()
846 hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY)) in update_accept_list()
855 list_for_each_entry(b, &hdev->le_accept_list, list) { in update_accept_list()
856 pend_conn = hci_pend_le_action_lookup(&hdev->pend_le_conns, in update_accept_list()
859 pend_report = hci_pend_le_action_lookup(&hdev->pend_le_reports, in update_accept_list()
873 !hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY) && in update_accept_list()
874 hci_find_irk_by_addr(hdev, &b->bdaddr, b->bdaddr_type)) { in update_accept_list()
891 list_for_each_entry(params, &hdev->pend_le_conns, action) { in update_accept_list()
900 list_for_each_entry(params, &hdev->pend_le_reports, action) { in update_accept_list()
914 if (!idr_is_empty(&hdev->adv_monitors_idr) && !hdev->suspended && in update_accept_list()
915 hdev->interleave_scan_state != INTERLEAVE_SCAN_ALLOWLIST) in update_accept_list()
922 static bool scan_use_rpa(struct hci_dev *hdev) in scan_use_rpa() argument
924 return hci_dev_test_flag(hdev, HCI_PRIVACY); in scan_use_rpa()
931 struct hci_dev *hdev = req->hdev; in hci_req_start_scan() local
933 if (hdev->scanning_paused) { in hci_req_start_scan()
934 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in hci_req_start_scan()
938 if (use_ll_privacy(hdev) && in hci_req_start_scan()
939 hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY) && in hci_req_start_scan()
949 if (use_ext_scan(hdev)) { in hci_req_start_scan()
965 if (scan_1m(hdev) || scan_2m(hdev)) { in hci_req_start_scan()
977 if (scan_coded(hdev)) { in hci_req_start_scan()
1020 static inline bool hci_is_le_conn_scanning(struct hci_dev *hdev) in hci_is_le_conn_scanning() argument
1022 struct hci_conn_hash *h = &hdev->conn_hash; in hci_is_le_conn_scanning()
1046 struct hci_dev *hdev = req->hdev; in hci_req_add_le_passive_scan() local
1053 if (hdev->scanning_paused) { in hci_req_add_le_passive_scan()
1054 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in hci_req_add_le_passive_scan()
1064 if (hci_update_random_address(req, false, scan_use_rpa(hdev), in hci_req_add_le_passive_scan()
1068 if (__hci_update_interleaved_scan(hdev)) in hci_req_add_le_passive_scan()
1071 bt_dev_dbg(hdev, "interleave state %d", hdev->interleave_scan_state); in hci_req_add_le_passive_scan()
1087 if (hci_dev_test_flag(hdev, HCI_PRIVACY) && in hci_req_add_le_passive_scan()
1088 (hdev->le_features[0] & HCI_LE_EXT_SCAN_POLICY)) in hci_req_add_le_passive_scan()
1091 if (hdev->suspended) { in hci_req_add_le_passive_scan()
1092 window = hdev->le_scan_window_suspend; in hci_req_add_le_passive_scan()
1093 interval = hdev->le_scan_int_suspend; in hci_req_add_le_passive_scan()
1094 } else if (hci_is_le_conn_scanning(hdev)) { in hci_req_add_le_passive_scan()
1095 window = hdev->le_scan_window_connect; in hci_req_add_le_passive_scan()
1096 interval = hdev->le_scan_int_connect; in hci_req_add_le_passive_scan()
1097 } else if (hci_is_adv_monitoring(hdev)) { in hci_req_add_le_passive_scan()
1098 window = hdev->le_scan_window_adv_monitor; in hci_req_add_le_passive_scan()
1099 interval = hdev->le_scan_int_adv_monitor; in hci_req_add_le_passive_scan()
1101 window = hdev->le_scan_window; in hci_req_add_le_passive_scan()
1102 interval = hdev->le_scan_interval; in hci_req_add_le_passive_scan()
1105 bt_dev_dbg(hdev, "LE passive scan with accept list = %d", in hci_req_add_le_passive_scan()
1111 static u8 get_adv_instance_scan_rsp_len(struct hci_dev *hdev, u8 instance) in get_adv_instance_scan_rsp_len() argument
1119 adv_instance = hci_find_adv_instance(hdev, instance); in get_adv_instance_scan_rsp_len()
1148 struct hci_dev *hdev = req->hdev; in hci_req_set_event_filter() local
1154 list_for_each_entry(b, &hdev->accept_list, list) { in hci_req_set_event_filter()
1165 bt_dev_dbg(hdev, "Adding event filters for %pMR", &b->bdaddr); in hci_req_set_event_filter()
1176 if (hci_dev_test_flag(req->hdev, HCI_LE_SCAN)) in hci_req_config_le_suspend_scan()
1183 set_bit(SUSPEND_SCAN_ENABLE, req->hdev->suspend_tasks); in hci_req_config_le_suspend_scan()
1186 static void cancel_adv_timeout(struct hci_dev *hdev) in cancel_adv_timeout() argument
1188 if (hdev->adv_instance_timeout) { in cancel_adv_timeout()
1189 hdev->adv_instance_timeout = 0; in cancel_adv_timeout()
1190 cancel_delayed_work(&hdev->adv_instance_expire); in cancel_adv_timeout()
1197 bt_dev_dbg(req->hdev, "Suspending advertising instances"); in hci_suspend_adv_instances()
1205 if (!ext_adv_capable(req->hdev)) in hci_suspend_adv_instances()
1206 cancel_adv_timeout(req->hdev); in hci_suspend_adv_instances()
1214 bt_dev_dbg(req->hdev, "Resuming advertising instances"); in hci_resume_adv_instances()
1216 if (ext_adv_capable(req->hdev)) { in hci_resume_adv_instances()
1218 list_for_each_entry(adv, &req->hdev->adv_instances, list) { in hci_resume_adv_instances()
1228 req->hdev->cur_adv_instance, in hci_resume_adv_instances()
1233 static void suspend_req_complete(struct hci_dev *hdev, u8 status, u16 opcode) in suspend_req_complete() argument
1235 bt_dev_dbg(hdev, "Request complete opcode=0x%x, status=0x%x", opcode, in suspend_req_complete()
1237 if (test_and_clear_bit(SUSPEND_SCAN_ENABLE, hdev->suspend_tasks) || in suspend_req_complete()
1238 test_and_clear_bit(SUSPEND_SCAN_DISABLE, hdev->suspend_tasks)) { in suspend_req_complete()
1239 wake_up(&hdev->suspend_wait_q); in suspend_req_complete()
1244 void hci_req_prepare_suspend(struct hci_dev *hdev, enum suspended_state next) in hci_req_prepare_suspend() argument
1252 if (next == hdev->suspend_state) { in hci_req_prepare_suspend()
1253 bt_dev_dbg(hdev, "Same state before and after: %d", next); in hci_req_prepare_suspend()
1257 hdev->suspend_state = next; in hci_req_prepare_suspend()
1258 hci_req_init(&req, hdev); in hci_req_prepare_suspend()
1262 hdev->suspended = true; in hci_req_prepare_suspend()
1265 old_state = hdev->discovery.state; in hci_req_prepare_suspend()
1267 set_bit(SUSPEND_PAUSE_DISCOVERY, hdev->suspend_tasks); in hci_req_prepare_suspend()
1268 hci_discovery_set_state(hdev, DISCOVERY_STOPPING); in hci_req_prepare_suspend()
1269 queue_work(hdev->req_workqueue, &hdev->discov_update); in hci_req_prepare_suspend()
1272 hdev->discovery_paused = true; in hci_req_prepare_suspend()
1273 hdev->discovery_old_state = old_state; in hci_req_prepare_suspend()
1276 old_state = hci_dev_test_flag(hdev, HCI_ADVERTISING); in hci_req_prepare_suspend()
1278 set_bit(SUSPEND_PAUSE_ADVERTISING, hdev->suspend_tasks); in hci_req_prepare_suspend()
1279 cancel_delayed_work(&hdev->discov_off); in hci_req_prepare_suspend()
1280 queue_delayed_work(hdev->req_workqueue, in hci_req_prepare_suspend()
1281 &hdev->discov_off, 0); in hci_req_prepare_suspend()
1285 if (hdev->adv_instance_cnt) in hci_req_prepare_suspend()
1288 hdev->advertising_paused = true; in hci_req_prepare_suspend()
1289 hdev->advertising_old_state = old_state; in hci_req_prepare_suspend()
1295 if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) in hci_req_prepare_suspend()
1299 set_bit(SUSPEND_SCAN_DISABLE, hdev->suspend_tasks); in hci_req_prepare_suspend()
1302 hdev->scanning_paused = true; in hci_req_prepare_suspend()
1309 list_for_each_entry(conn, &hdev->conn_hash.list, list) { in hci_req_prepare_suspend()
1315 bt_dev_dbg(hdev, in hci_req_prepare_suspend()
1318 set_bit(SUSPEND_DISCONNECTING, hdev->suspend_tasks); in hci_req_prepare_suspend()
1322 hdev->scanning_paused = false; in hci_req_prepare_suspend()
1328 hdev->scanning_paused = true; in hci_req_prepare_suspend()
1331 hdev->suspended = false; in hci_req_prepare_suspend()
1332 hdev->scanning_paused = false; in hci_req_prepare_suspend()
1339 hdev->advertising_paused = false; in hci_req_prepare_suspend()
1340 if (hdev->advertising_old_state) { in hci_req_prepare_suspend()
1342 hdev->suspend_tasks); in hci_req_prepare_suspend()
1343 hci_dev_set_flag(hdev, HCI_ADVERTISING); in hci_req_prepare_suspend()
1344 queue_work(hdev->req_workqueue, in hci_req_prepare_suspend()
1345 &hdev->discoverable_update); in hci_req_prepare_suspend()
1346 hdev->advertising_old_state = 0; in hci_req_prepare_suspend()
1350 if (hdev->adv_instance_cnt) in hci_req_prepare_suspend()
1354 hdev->discovery_paused = false; in hci_req_prepare_suspend()
1355 if (hdev->discovery_old_state != DISCOVERY_STOPPED && in hci_req_prepare_suspend()
1356 hdev->discovery_old_state != DISCOVERY_STOPPING) { in hci_req_prepare_suspend()
1357 set_bit(SUSPEND_UNPAUSE_DISCOVERY, hdev->suspend_tasks); in hci_req_prepare_suspend()
1358 hci_discovery_set_state(hdev, DISCOVERY_STARTING); in hci_req_prepare_suspend()
1359 queue_work(hdev->req_workqueue, &hdev->discov_update); in hci_req_prepare_suspend()
1365 hdev->suspend_state = next; in hci_req_prepare_suspend()
1368 clear_bit(SUSPEND_PREPARE_NOTIFIER, hdev->suspend_tasks); in hci_req_prepare_suspend()
1369 wake_up(&hdev->suspend_wait_q); in hci_req_prepare_suspend()
1372 static u8 get_cur_adv_instance_scan_rsp_len(struct hci_dev *hdev) in get_cur_adv_instance_scan_rsp_len() argument
1374 u8 instance = hdev->cur_adv_instance; in get_cur_adv_instance_scan_rsp_len()
1381 adv_instance = hci_find_adv_instance(hdev, instance); in get_cur_adv_instance_scan_rsp_len()
1393 if (ext_adv_capable(req->hdev)) { in __hci_req_disable_advertising()
1403 static u32 get_adv_instance_flags(struct hci_dev *hdev, u8 instance) in get_adv_instance_flags() argument
1417 if (hci_dev_test_flag(hdev, HCI_ADVERTISING_CONNECTABLE)) in get_adv_instance_flags()
1420 if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) in get_adv_instance_flags()
1422 else if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in get_adv_instance_flags()
1428 adv_instance = hci_find_adv_instance(hdev, instance); in get_adv_instance_flags()
1437 static bool adv_use_rpa(struct hci_dev *hdev, uint32_t flags) in adv_use_rpa() argument
1440 if (!hci_dev_test_flag(hdev, HCI_PRIVACY)) in adv_use_rpa()
1444 if (!hci_dev_test_flag(hdev, HCI_LIMITED_PRIVACY)) in adv_use_rpa()
1451 hci_dev_test_flag(hdev, HCI_BONDABLE)) in adv_use_rpa()
1460 static bool is_advertising_allowed(struct hci_dev *hdev, bool connectable) in is_advertising_allowed() argument
1463 if (hci_conn_num(hdev, LE_LINK) == 0) in is_advertising_allowed()
1467 if (hdev->conn_hash.le_num_slave > 0) { in is_advertising_allowed()
1469 if (!connectable && !(hdev->le_states[2] & 0x10)) in is_advertising_allowed()
1475 if (connectable && (!(hdev->le_states[4] & 0x40) || in is_advertising_allowed()
1476 !(hdev->le_states[2] & 0x20))) in is_advertising_allowed()
1481 if (hci_conn_num(hdev, LE_LINK) != hdev->conn_hash.le_num_slave) { in is_advertising_allowed()
1483 if (!connectable && !(hdev->le_states[2] & 0x02)) in is_advertising_allowed()
1489 if (connectable && (!(hdev->le_states[4] & 0x08) || in is_advertising_allowed()
1490 !(hdev->le_states[2] & 0x08))) in is_advertising_allowed()
1499 struct hci_dev *hdev = req->hdev; in __hci_req_enable_advertising() local
1506 flags = get_adv_instance_flags(hdev, hdev->cur_adv_instance); in __hci_req_enable_advertising()
1512 mgmt_get_connectable(hdev); in __hci_req_enable_advertising()
1514 if (!is_advertising_allowed(hdev, connectable)) in __hci_req_enable_advertising()
1517 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in __hci_req_enable_advertising()
1525 hci_dev_clear_flag(hdev, HCI_LE_ADV); in __hci_req_enable_advertising()
1532 adv_use_rpa(hdev, flags), in __hci_req_enable_advertising()
1541 adv_min_interval = hdev->le_adv_min_interval; in __hci_req_enable_advertising()
1542 adv_max_interval = hdev->le_adv_max_interval; in __hci_req_enable_advertising()
1544 if (get_cur_adv_instance_scan_rsp_len(hdev)) in __hci_req_enable_advertising()
1549 if (!hci_dev_test_flag(hdev, HCI_DISCOVERABLE) || in __hci_req_enable_advertising()
1550 hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) { in __hci_req_enable_advertising()
1554 adv_min_interval = hdev->le_adv_min_interval; in __hci_req_enable_advertising()
1555 adv_max_interval = hdev->le_adv_max_interval; in __hci_req_enable_advertising()
1562 cp.channel_map = hdev->le_adv_channel_map; in __hci_req_enable_advertising()
1569 u8 append_local_name(struct hci_dev *hdev, u8 *ptr, u8 ad_len) in append_local_name() argument
1579 complete_len = strlen(hdev->dev_name); in append_local_name()
1582 hdev->dev_name, complete_len + 1); in append_local_name()
1585 short_len = strlen(hdev->short_name); in append_local_name()
1588 hdev->short_name, short_len + 1); in append_local_name()
1596 memcpy(name, hdev->dev_name, HCI_MAX_SHORT_NAME_LENGTH); in append_local_name()
1606 static u8 append_appearance(struct hci_dev *hdev, u8 *ptr, u8 ad_len) in append_appearance() argument
1608 return eir_append_le16(ptr, ad_len, EIR_APPEARANCE, hdev->appearance); in append_appearance()
1611 static u8 create_default_scan_rsp_data(struct hci_dev *hdev, u8 *ptr) in create_default_scan_rsp_data() argument
1615 if (hdev->appearance) { in create_default_scan_rsp_data()
1616 scan_rsp_len = append_appearance(hdev, ptr, scan_rsp_len); in create_default_scan_rsp_data()
1619 return append_local_name(hdev, ptr, scan_rsp_len); in create_default_scan_rsp_data()
1622 static u8 create_instance_scan_rsp_data(struct hci_dev *hdev, u8 instance, in create_instance_scan_rsp_data() argument
1629 adv_instance = hci_find_adv_instance(hdev, instance); in create_instance_scan_rsp_data()
1635 if ((instance_flags & MGMT_ADV_FLAG_APPEARANCE) && hdev->appearance) { in create_instance_scan_rsp_data()
1636 scan_rsp_len = append_appearance(hdev, ptr, scan_rsp_len); in create_instance_scan_rsp_data()
1645 scan_rsp_len = append_local_name(hdev, ptr, scan_rsp_len); in create_instance_scan_rsp_data()
1652 struct hci_dev *hdev = req->hdev; in __hci_req_update_scan_rsp_data() local
1655 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in __hci_req_update_scan_rsp_data()
1658 if (ext_adv_capable(hdev)) { in __hci_req_update_scan_rsp_data()
1667 len = create_instance_scan_rsp_data(hdev, instance, in __hci_req_update_scan_rsp_data()
1670 len = create_default_scan_rsp_data(hdev, pdu.data); in __hci_req_update_scan_rsp_data()
1672 if (hdev->scan_rsp_data_len == len && in __hci_req_update_scan_rsp_data()
1673 !memcmp(pdu.data, hdev->scan_rsp_data, len)) in __hci_req_update_scan_rsp_data()
1676 memcpy(hdev->scan_rsp_data, pdu.data, len); in __hci_req_update_scan_rsp_data()
1677 hdev->scan_rsp_data_len = len; in __hci_req_update_scan_rsp_data()
1692 len = create_instance_scan_rsp_data(hdev, instance, in __hci_req_update_scan_rsp_data()
1695 len = create_default_scan_rsp_data(hdev, cp.data); in __hci_req_update_scan_rsp_data()
1697 if (hdev->scan_rsp_data_len == len && in __hci_req_update_scan_rsp_data()
1698 !memcmp(cp.data, hdev->scan_rsp_data, len)) in __hci_req_update_scan_rsp_data()
1701 memcpy(hdev->scan_rsp_data, cp.data, sizeof(cp.data)); in __hci_req_update_scan_rsp_data()
1702 hdev->scan_rsp_data_len = len; in __hci_req_update_scan_rsp_data()
1710 static u8 create_instance_adv_data(struct hci_dev *hdev, u8 instance, u8 *ptr) in create_instance_adv_data() argument
1718 adv_instance = hci_find_adv_instance(hdev, instance); in create_instance_adv_data()
1723 instance_flags = get_adv_instance_flags(hdev, instance); in create_instance_adv_data()
1742 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in create_instance_adv_data()
1750 flags |= mgmt_get_adv_discov_flags(hdev); in create_instance_adv_data()
1776 if (ext_adv_capable(hdev)) { in create_instance_adv_data()
1780 adv_tx_power = hdev->adv_tx_power; in create_instance_adv_data()
1782 adv_tx_power = hdev->adv_tx_power; in create_instance_adv_data()
1801 struct hci_dev *hdev = req->hdev; in __hci_req_update_adv_data() local
1804 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in __hci_req_update_adv_data()
1807 if (ext_adv_capable(hdev)) { in __hci_req_update_adv_data()
1815 len = create_instance_adv_data(hdev, instance, pdu.data); in __hci_req_update_adv_data()
1818 if (hdev->adv_data_len == len && in __hci_req_update_adv_data()
1819 memcmp(pdu.data, hdev->adv_data, len) == 0) in __hci_req_update_adv_data()
1822 memcpy(hdev->adv_data, pdu.data, len); in __hci_req_update_adv_data()
1823 hdev->adv_data_len = len; in __hci_req_update_adv_data()
1837 len = create_instance_adv_data(hdev, instance, cp.data); in __hci_req_update_adv_data()
1840 if (hdev->adv_data_len == len && in __hci_req_update_adv_data()
1841 memcmp(cp.data, hdev->adv_data, len) == 0) in __hci_req_update_adv_data()
1844 memcpy(hdev->adv_data, cp.data, sizeof(cp.data)); in __hci_req_update_adv_data()
1845 hdev->adv_data_len = len; in __hci_req_update_adv_data()
1853 int hci_req_update_adv_data(struct hci_dev *hdev, u8 instance) in hci_req_update_adv_data() argument
1857 hci_req_init(&req, hdev); in hci_req_update_adv_data()
1863 static void enable_addr_resolution_complete(struct hci_dev *hdev, u8 status, in enable_addr_resolution_complete() argument
1866 BT_DBG("%s status %u", hdev->name, status); in enable_addr_resolution_complete()
1869 void hci_req_disable_address_resolution(struct hci_dev *hdev) in hci_req_disable_address_resolution() argument
1874 if (!use_ll_privacy(hdev) && in hci_req_disable_address_resolution()
1875 !hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION)) in hci_req_disable_address_resolution()
1878 hci_req_init(&req, hdev); in hci_req_disable_address_resolution()
1885 static void adv_enable_complete(struct hci_dev *hdev, u8 status, u16 opcode) in adv_enable_complete() argument
1887 BT_DBG("%s status %u", hdev->name, status); in adv_enable_complete()
1890 void hci_req_reenable_advertising(struct hci_dev *hdev) in hci_req_reenable_advertising() argument
1894 if (!hci_dev_test_flag(hdev, HCI_ADVERTISING) && in hci_req_reenable_advertising()
1895 list_empty(&hdev->adv_instances)) in hci_req_reenable_advertising()
1898 hci_req_init(&req, hdev); in hci_req_reenable_advertising()
1900 if (hdev->cur_adv_instance) { in hci_req_reenable_advertising()
1901 __hci_req_schedule_adv_instance(&req, hdev->cur_adv_instance, in hci_req_reenable_advertising()
1904 if (ext_adv_capable(hdev)) { in hci_req_reenable_advertising()
1918 struct hci_dev *hdev = container_of(work, struct hci_dev, in adv_timeout_expire() local
1924 BT_DBG("%s", hdev->name); in adv_timeout_expire()
1926 hci_dev_lock(hdev); in adv_timeout_expire()
1928 hdev->adv_instance_timeout = 0; in adv_timeout_expire()
1930 instance = hdev->cur_adv_instance; in adv_timeout_expire()
1934 hci_req_init(&req, hdev); in adv_timeout_expire()
1936 hci_req_clear_adv_instance(hdev, NULL, &req, instance, false); in adv_timeout_expire()
1938 if (list_empty(&hdev->adv_instances)) in adv_timeout_expire()
1944 hci_dev_unlock(hdev); in adv_timeout_expire()
1950 struct hci_dev *hdev = req->hdev; in hci_req_add_le_interleaved_scan() local
1953 hci_dev_lock(hdev); in hci_req_add_le_interleaved_scan()
1955 if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) in hci_req_add_le_interleaved_scan()
1959 switch (hdev->interleave_scan_state) { in hci_req_add_le_interleaved_scan()
1961 bt_dev_dbg(hdev, "next state: allowlist"); in hci_req_add_le_interleaved_scan()
1962 hdev->interleave_scan_state = INTERLEAVE_SCAN_NO_FILTER; in hci_req_add_le_interleaved_scan()
1965 bt_dev_dbg(hdev, "next state: no filter"); in hci_req_add_le_interleaved_scan()
1966 hdev->interleave_scan_state = INTERLEAVE_SCAN_ALLOWLIST; in hci_req_add_le_interleaved_scan()
1973 hci_dev_unlock(hdev); in hci_req_add_le_interleaved_scan()
1980 struct hci_dev *hdev = container_of(work, struct hci_dev, in interleave_scan_work() local
1985 if (hdev->interleave_scan_state == INTERLEAVE_SCAN_ALLOWLIST) { in interleave_scan_work()
1986 timeout = msecs_to_jiffies(hdev->advmon_allowlist_duration); in interleave_scan_work()
1987 } else if (hdev->interleave_scan_state == INTERLEAVE_SCAN_NO_FILTER) { in interleave_scan_work()
1988 timeout = msecs_to_jiffies(hdev->advmon_no_filter_duration); in interleave_scan_work()
1990 bt_dev_err(hdev, "unexpected error"); in interleave_scan_work()
1994 hci_req_sync(hdev, hci_req_add_le_interleaved_scan, 0, in interleave_scan_work()
1998 if (is_interleave_scanning(hdev)) in interleave_scan_work()
1999 queue_delayed_work(hdev->req_workqueue, in interleave_scan_work()
2000 &hdev->interleave_scan, timeout); in interleave_scan_work()
2003 int hci_get_random_address(struct hci_dev *hdev, bool require_privacy, in hci_get_random_address() argument
2020 if (use_ll_privacy(hdev)) in hci_get_random_address()
2027 !bacmp(&adv_instance->random_addr, &hdev->rpa)) in hci_get_random_address()
2032 if (!hci_dev_test_and_clear_flag(hdev, HCI_RPA_EXPIRED) && in hci_get_random_address()
2033 !bacmp(&hdev->random_addr, &hdev->rpa)) in hci_get_random_address()
2037 err = smp_generate_rpa(hdev, hdev->irk, &hdev->rpa); in hci_get_random_address()
2039 bt_dev_err(hdev, "failed to generate new RPA"); in hci_get_random_address()
2043 bacpy(rand_addr, &hdev->rpa); in hci_get_random_address()
2045 to = msecs_to_jiffies(hdev->rpa_timeout * 1000); in hci_get_random_address()
2047 queue_delayed_work(hdev->workqueue, in hci_get_random_address()
2050 queue_delayed_work(hdev->workqueue, in hci_get_random_address()
2051 &hdev->rpa_expired, to); in hci_get_random_address()
2074 if (bacmp(&hdev->bdaddr, &nrpa)) in hci_get_random_address()
2098 struct hci_dev *hdev = req->hdev; in __hci_req_setup_ext_adv_instance() local
2108 adv_instance = hci_find_adv_instance(hdev, instance); in __hci_req_setup_ext_adv_instance()
2115 flags = get_adv_instance_flags(hdev, instance); in __hci_req_setup_ext_adv_instance()
2121 mgmt_get_connectable(hdev); in __hci_req_setup_ext_adv_instance()
2123 if (!is_advertising_allowed(hdev, connectable)) in __hci_req_setup_ext_adv_instance()
2130 err = hci_get_random_address(hdev, !connectable, in __hci_req_setup_ext_adv_instance()
2131 adv_use_rpa(hdev, flags), adv_instance, in __hci_req_setup_ext_adv_instance()
2139 hci_cpu_to_le24(hdev->le_adv_min_interval, cp.min_interval); in __hci_req_setup_ext_adv_instance()
2140 hci_cpu_to_le24(hdev->le_adv_max_interval, cp.max_interval); in __hci_req_setup_ext_adv_instance()
2149 } else if (get_adv_instance_scan_rsp_len(hdev, instance)) { in __hci_req_setup_ext_adv_instance()
2162 cp.channel_map = hdev->le_adv_channel_map; in __hci_req_setup_ext_adv_instance()
2189 if (!bacmp(&random_addr, &hdev->random_addr)) in __hci_req_setup_ext_adv_instance()
2208 struct hci_dev *hdev = req->hdev; in __hci_req_enable_ext_advertising() local
2215 adv_instance = hci_find_adv_instance(hdev, instance); in __hci_req_enable_ext_advertising()
2253 struct hci_dev *hdev = req->hdev; in __hci_req_disable_ext_adv_instance() local
2260 if (instance > 0 && !hci_find_adv_instance(hdev, instance)) in __hci_req_disable_ext_adv_instance()
2282 struct hci_dev *hdev = req->hdev; in __hci_req_remove_ext_adv_instance() local
2285 if (instance > 0 && !hci_find_adv_instance(hdev, instance)) in __hci_req_remove_ext_adv_instance()
2295 struct hci_dev *hdev = req->hdev; in __hci_req_start_ext_adv() local
2296 struct adv_info *adv_instance = hci_find_adv_instance(hdev, instance); in __hci_req_start_ext_adv()
2318 struct hci_dev *hdev = req->hdev; in __hci_req_schedule_adv_instance() local
2322 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || in __hci_req_schedule_adv_instance()
2323 list_empty(&hdev->adv_instances)) in __hci_req_schedule_adv_instance()
2326 if (hdev->adv_instance_timeout) in __hci_req_schedule_adv_instance()
2329 adv_instance = hci_find_adv_instance(hdev, instance); in __hci_req_schedule_adv_instance()
2355 if (!ext_adv_capable(hdev)) { in __hci_req_schedule_adv_instance()
2356 hdev->adv_instance_timeout = timeout; in __hci_req_schedule_adv_instance()
2357 queue_delayed_work(hdev->req_workqueue, in __hci_req_schedule_adv_instance()
2358 &hdev->adv_instance_expire, in __hci_req_schedule_adv_instance()
2366 if (!force && hdev->cur_adv_instance == instance && in __hci_req_schedule_adv_instance()
2367 hci_dev_test_flag(hdev, HCI_LE_ADV)) in __hci_req_schedule_adv_instance()
2370 hdev->cur_adv_instance = instance; in __hci_req_schedule_adv_instance()
2371 if (ext_adv_capable(hdev)) { in __hci_req_schedule_adv_instance()
2393 void hci_req_clear_adv_instance(struct hci_dev *hdev, struct sock *sk, in hci_req_clear_adv_instance() argument
2402 if (!instance || hdev->cur_adv_instance == instance) in hci_req_clear_adv_instance()
2403 cancel_adv_timeout(hdev); in hci_req_clear_adv_instance()
2409 if (instance && hdev->cur_adv_instance == instance) in hci_req_clear_adv_instance()
2410 next_instance = hci_get_next_instance(hdev, instance); in hci_req_clear_adv_instance()
2413 list_for_each_entry_safe(adv_instance, n, &hdev->adv_instances, in hci_req_clear_adv_instance()
2419 err = hci_remove_adv_instance(hdev, rem_inst); in hci_req_clear_adv_instance()
2421 mgmt_advertising_removed(sk, hdev, rem_inst); in hci_req_clear_adv_instance()
2424 adv_instance = hci_find_adv_instance(hdev, instance); in hci_req_clear_adv_instance()
2433 err = hci_remove_adv_instance(hdev, instance); in hci_req_clear_adv_instance()
2435 mgmt_advertising_removed(sk, hdev, instance); in hci_req_clear_adv_instance()
2439 if (!req || !hdev_is_powered(hdev) || in hci_req_clear_adv_instance()
2440 hci_dev_test_flag(hdev, HCI_ADVERTISING)) in hci_req_clear_adv_instance()
2443 if (next_instance && !ext_adv_capable(hdev)) in hci_req_clear_adv_instance()
2450 struct hci_dev *hdev = req->hdev; in set_random_addr() local
2462 if (hci_dev_test_flag(hdev, HCI_LE_ADV) || in set_random_addr()
2463 hci_lookup_le_connect(hdev)) { in set_random_addr()
2465 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in set_random_addr()
2475 struct hci_dev *hdev = req->hdev; in hci_update_random_address() local
2488 if (use_ll_privacy(hdev)) in hci_update_random_address()
2493 if (!hci_dev_test_and_clear_flag(hdev, HCI_RPA_EXPIRED) && in hci_update_random_address()
2494 !bacmp(&hdev->random_addr, &hdev->rpa)) in hci_update_random_address()
2497 err = smp_generate_rpa(hdev, hdev->irk, &hdev->rpa); in hci_update_random_address()
2499 bt_dev_err(hdev, "failed to generate new RPA"); in hci_update_random_address()
2503 set_random_addr(req, &hdev->rpa); in hci_update_random_address()
2505 to = msecs_to_jiffies(hdev->rpa_timeout * 1000); in hci_update_random_address()
2506 queue_delayed_work(hdev->workqueue, &hdev->rpa_expired, to); in hci_update_random_address()
2529 if (bacmp(&hdev->bdaddr, &nrpa)) in hci_update_random_address()
2547 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in hci_update_random_address()
2548 !bacmp(&hdev->bdaddr, BDADDR_ANY) || in hci_update_random_address()
2549 (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in hci_update_random_address()
2550 bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_update_random_address()
2552 if (bacmp(&hdev->static_addr, &hdev->random_addr)) in hci_update_random_address()
2554 &hdev->static_addr); in hci_update_random_address()
2566 static bool disconnected_accept_list_entries(struct hci_dev *hdev) in disconnected_accept_list_entries() argument
2570 list_for_each_entry(b, &hdev->accept_list, list) { in disconnected_accept_list_entries()
2573 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &b->bdaddr); in disconnected_accept_list_entries()
2586 struct hci_dev *hdev = req->hdev; in __hci_req_update_scan() local
2589 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in __hci_req_update_scan()
2592 if (!hdev_is_powered(hdev)) in __hci_req_update_scan()
2595 if (mgmt_powering_down(hdev)) in __hci_req_update_scan()
2598 if (hdev->scanning_paused) in __hci_req_update_scan()
2601 if (hci_dev_test_flag(hdev, HCI_CONNECTABLE) || in __hci_req_update_scan()
2602 disconnected_accept_list_entries(hdev)) in __hci_req_update_scan()
2607 if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in __hci_req_update_scan()
2610 if (test_bit(HCI_PSCAN, &hdev->flags) == !!(scan & SCAN_PAGE) && in __hci_req_update_scan()
2611 test_bit(HCI_ISCAN, &hdev->flags) == !!(scan & SCAN_INQUIRY)) in __hci_req_update_scan()
2619 hci_dev_lock(req->hdev); in update_scan()
2621 hci_dev_unlock(req->hdev); in update_scan()
2627 struct hci_dev *hdev = container_of(work, struct hci_dev, scan_update); in scan_update_work() local
2629 hci_req_sync(hdev, update_scan, 0, HCI_CMD_TIMEOUT, NULL); in scan_update_work()
2634 struct hci_dev *hdev = req->hdev; in connectable_update() local
2636 hci_dev_lock(hdev); in connectable_update()
2644 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in connectable_update()
2645 __hci_req_update_adv_data(req, hdev->cur_adv_instance); in connectable_update()
2648 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || in connectable_update()
2649 !list_empty(&hdev->adv_instances)) { in connectable_update()
2650 if (ext_adv_capable(hdev)) in connectable_update()
2651 __hci_req_start_ext_adv(req, hdev->cur_adv_instance); in connectable_update()
2658 hci_dev_unlock(hdev); in connectable_update()
2665 struct hci_dev *hdev = container_of(work, struct hci_dev, in connectable_update_work() local
2669 hci_req_sync(hdev, connectable_update, 0, HCI_CMD_TIMEOUT, &status); in connectable_update_work()
2670 mgmt_set_connectable_complete(hdev, status); in connectable_update_work()
2673 static u8 get_service_classes(struct hci_dev *hdev) in get_service_classes() argument
2678 list_for_each_entry(uuid, &hdev->uuids, list) in get_service_classes()
2686 struct hci_dev *hdev = req->hdev; in __hci_req_update_class() local
2689 BT_DBG("%s", hdev->name); in __hci_req_update_class()
2691 if (!hdev_is_powered(hdev)) in __hci_req_update_class()
2694 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in __hci_req_update_class()
2697 if (hci_dev_test_flag(hdev, HCI_SERVICE_CACHE)) in __hci_req_update_class()
2700 cod[0] = hdev->minor_class; in __hci_req_update_class()
2701 cod[1] = hdev->major_class; in __hci_req_update_class()
2702 cod[2] = get_service_classes(hdev); in __hci_req_update_class()
2704 if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) in __hci_req_update_class()
2707 if (memcmp(cod, hdev->dev_class, 3) == 0) in __hci_req_update_class()
2715 struct hci_dev *hdev = req->hdev; in write_iac() local
2718 if (!hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in write_iac()
2721 if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) { in write_iac()
2723 cp.num_iac = min_t(u8, hdev->num_iac, 2); in write_iac()
2744 struct hci_dev *hdev = req->hdev; in discoverable_update() local
2746 hci_dev_lock(hdev); in discoverable_update()
2748 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in discoverable_update()
2757 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) { in discoverable_update()
2763 if (hci_dev_test_flag(hdev, HCI_LIMITED_PRIVACY)) { in discoverable_update()
2764 if (ext_adv_capable(hdev)) in discoverable_update()
2771 hci_dev_unlock(hdev); in discoverable_update()
2778 struct hci_dev *hdev = container_of(work, struct hci_dev, in discoverable_update_work() local
2782 hci_req_sync(hdev, discoverable_update, 0, HCI_CMD_TIMEOUT, &status); in discoverable_update_work()
2783 mgmt_set_discoverable_complete(hdev, status); in discoverable_update_work()
2817 if (req->hdev->hci_ver < BLUETOOTH_VER_1_2) in __hci_abort_conn()
2855 static void abort_conn_complete(struct hci_dev *hdev, u8 status, u16 opcode) in abort_conn_complete() argument
2866 hci_req_init(&req, conn->hdev); in hci_abort_conn()
2872 bt_dev_err(conn->hdev, "failed to run HCI request: err %d", err); in hci_abort_conn()
2881 hci_dev_lock(req->hdev); in update_bg_scan()
2883 hci_dev_unlock(req->hdev); in update_bg_scan()
2889 struct hci_dev *hdev = container_of(work, struct hci_dev, in bg_scan_update() local
2895 err = hci_req_sync(hdev, update_bg_scan, 0, HCI_CMD_TIMEOUT, &status); in bg_scan_update()
2899 hci_dev_lock(hdev); in bg_scan_update()
2901 conn = hci_conn_hash_lookup_state(hdev, LE_LINK, BT_CONNECT); in bg_scan_update()
2905 hci_dev_unlock(hdev); in bg_scan_update()
2921 BT_DBG("%s", req->hdev->name); in bredr_inquiry()
2923 hci_dev_lock(req->hdev); in bredr_inquiry()
2924 hci_inquiry_cache_flush(req->hdev); in bredr_inquiry()
2925 hci_dev_unlock(req->hdev); in bredr_inquiry()
2929 if (req->hdev->discovery.limited) in bredr_inquiry()
2943 struct hci_dev *hdev = container_of(work, struct hci_dev, in le_scan_disable_work() local
2947 BT_DBG("%s", hdev->name); in le_scan_disable_work()
2949 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN)) in le_scan_disable_work()
2952 cancel_delayed_work(&hdev->le_scan_restart); in le_scan_disable_work()
2954 hci_req_sync(hdev, le_scan_disable, 0, HCI_CMD_TIMEOUT, &status); in le_scan_disable_work()
2956 bt_dev_err(hdev, "failed to disable LE scan: status 0x%02x", in le_scan_disable_work()
2961 hdev->discovery.scan_start = 0; in le_scan_disable_work()
2971 if (hdev->discovery.type == DISCOV_TYPE_LE) in le_scan_disable_work()
2974 if (hdev->discovery.type != DISCOV_TYPE_INTERLEAVED) in le_scan_disable_work()
2977 if (test_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks)) { in le_scan_disable_work()
2978 if (!test_bit(HCI_INQUIRY, &hdev->flags) && in le_scan_disable_work()
2979 hdev->discovery.state != DISCOVERY_RESOLVING) in le_scan_disable_work()
2985 hci_req_sync(hdev, bredr_inquiry, DISCOV_INTERLEAVED_INQUIRY_LEN, in le_scan_disable_work()
2988 bt_dev_err(hdev, "inquiry failed: status 0x%02x", status); in le_scan_disable_work()
2995 hci_dev_lock(hdev); in le_scan_disable_work()
2996 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in le_scan_disable_work()
2997 hci_dev_unlock(hdev); in le_scan_disable_work()
3002 struct hci_dev *hdev = req->hdev; in le_scan_restart() local
3005 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN)) in le_scan_restart()
3008 if (hdev->scanning_paused) { in le_scan_restart()
3009 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in le_scan_restart()
3015 if (use_ext_scan(hdev)) { in le_scan_restart()
3038 struct hci_dev *hdev = container_of(work, struct hci_dev, in le_scan_restart_work() local
3043 BT_DBG("%s", hdev->name); in le_scan_restart_work()
3045 hci_req_sync(hdev, le_scan_restart, 0, HCI_CMD_TIMEOUT, &status); in le_scan_restart_work()
3047 bt_dev_err(hdev, "failed to restart LE scan: status %d", in le_scan_restart_work()
3052 hci_dev_lock(hdev); in le_scan_restart_work()
3054 if (!test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks) || in le_scan_restart_work()
3055 !hdev->discovery.scan_start) in le_scan_restart_work()
3063 duration = hdev->discovery.scan_duration; in le_scan_restart_work()
3064 scan_start = hdev->discovery.scan_start; in le_scan_restart_work()
3079 queue_delayed_work(hdev->req_workqueue, in le_scan_restart_work()
3080 &hdev->le_scan_disable, timeout); in le_scan_restart_work()
3083 hci_dev_unlock(hdev); in le_scan_restart_work()
3089 struct hci_dev *hdev = req->hdev; in active_scan() local
3097 BT_DBG("%s", hdev->name); in active_scan()
3103 if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) in active_scan()
3110 err = hci_update_random_address(req, true, scan_use_rpa(hdev), in active_scan()
3116 hdev->le_scan_window_discovery, own_addr_type, in active_scan()
3125 BT_DBG("%s", req->hdev->name); in interleaved_discov()
3134 static void start_discovery(struct hci_dev *hdev, u8 *status) in start_discovery() argument
3138 BT_DBG("%s type %u", hdev->name, hdev->discovery.type); in start_discovery()
3140 switch (hdev->discovery.type) { in start_discovery()
3142 if (!hci_dev_test_flag(hdev, HCI_INQUIRY)) in start_discovery()
3143 hci_req_sync(hdev, bredr_inquiry, in start_discovery()
3157 &hdev->quirks)) { in start_discovery()
3163 hci_req_sync(hdev, interleaved_discov, in start_discovery()
3164 hdev->le_scan_int_discovery * 2, HCI_CMD_TIMEOUT, in start_discovery()
3169 timeout = msecs_to_jiffies(hdev->discov_interleaved_timeout); in start_discovery()
3170 hci_req_sync(hdev, active_scan, hdev->le_scan_int_discovery, in start_discovery()
3175 hci_req_sync(hdev, active_scan, hdev->le_scan_int_discovery, in start_discovery()
3186 BT_DBG("%s timeout %u ms", hdev->name, jiffies_to_msecs(timeout)); in start_discovery()
3193 if (test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks) && in start_discovery()
3194 hdev->discovery.result_filtering) { in start_discovery()
3195 hdev->discovery.scan_start = jiffies; in start_discovery()
3196 hdev->discovery.scan_duration = timeout; in start_discovery()
3199 queue_delayed_work(hdev->req_workqueue, &hdev->le_scan_disable, in start_discovery()
3205 struct hci_dev *hdev = req->hdev; in hci_req_stop_discovery() local
3206 struct discovery_state *d = &hdev->discovery; in hci_req_stop_discovery()
3211 BT_DBG("%s state %u", hdev->name, hdev->discovery.state); in hci_req_stop_discovery()
3214 if (test_bit(HCI_INQUIRY, &hdev->flags)) in hci_req_stop_discovery()
3217 if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) { in hci_req_stop_discovery()
3218 cancel_delayed_work(&hdev->le_scan_disable); in hci_req_stop_discovery()
3225 if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) { in hci_req_stop_discovery()
3236 e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, in hci_req_stop_discovery()
3252 hci_dev_lock(req->hdev); in stop_discovery()
3254 hci_dev_unlock(req->hdev); in stop_discovery()
3261 struct hci_dev *hdev = container_of(work, struct hci_dev, in discov_update() local
3265 switch (hdev->discovery.state) { in discov_update()
3267 start_discovery(hdev, &status); in discov_update()
3268 mgmt_start_discovery_complete(hdev, status); in discov_update()
3270 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in discov_update()
3272 hci_discovery_set_state(hdev, DISCOVERY_FINDING); in discov_update()
3275 hci_req_sync(hdev, stop_discovery, 0, HCI_CMD_TIMEOUT, &status); in discov_update()
3276 mgmt_stop_discovery_complete(hdev, status); in discov_update()
3278 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in discov_update()
3288 struct hci_dev *hdev = container_of(work, struct hci_dev, in discov_off() local
3291 BT_DBG("%s", hdev->name); in discov_off()
3293 hci_dev_lock(hdev); in discov_off()
3300 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in discov_off()
3301 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in discov_off()
3302 hdev->discov_timeout = 0; in discov_off()
3304 hci_dev_unlock(hdev); in discov_off()
3306 hci_req_sync(hdev, discoverable_update, 0, HCI_CMD_TIMEOUT, NULL); in discov_off()
3307 mgmt_new_settings(hdev); in discov_off()
3312 struct hci_dev *hdev = req->hdev; in powered_update_hci() local
3315 hci_dev_lock(hdev); in powered_update_hci()
3317 if (hci_dev_test_flag(hdev, HCI_SSP_ENABLED) && in powered_update_hci()
3318 !lmp_host_ssp_capable(hdev)) { in powered_update_hci()
3323 if (bredr_sc_enabled(hdev) && !lmp_host_sc_capable(hdev)) { in powered_update_hci()
3331 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED) && in powered_update_hci()
3332 lmp_bredr_capable(hdev)) { in powered_update_hci()
3341 if (cp.le != lmp_host_le_capable(hdev) || in powered_update_hci()
3342 cp.simul != lmp_host_le_br_capable(hdev)) in powered_update_hci()
3347 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { in powered_update_hci()
3352 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || in powered_update_hci()
3353 list_empty(&hdev->adv_instances)) { in powered_update_hci()
3356 if (ext_adv_capable(hdev)) { in powered_update_hci()
3368 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) { in powered_update_hci()
3369 if (!ext_adv_capable(hdev)) in powered_update_hci()
3375 } else if (!list_empty(&hdev->adv_instances)) { in powered_update_hci()
3378 adv_instance = list_first_entry(&hdev->adv_instances, in powered_update_hci()
3386 link_sec = hci_dev_test_flag(hdev, HCI_LINK_SECURITY); in powered_update_hci()
3387 if (link_sec != test_bit(HCI_AUTH, &hdev->flags)) in powered_update_hci()
3391 if (lmp_bredr_capable(hdev)) { in powered_update_hci()
3392 if (hci_dev_test_flag(hdev, HCI_FAST_CONNECTABLE)) in powered_update_hci()
3402 hci_dev_unlock(hdev); in powered_update_hci()
3406 int __hci_req_hci_power_on(struct hci_dev *hdev) in __hci_req_hci_power_on() argument
3413 smp_register(hdev); in __hci_req_hci_power_on()
3415 return __hci_req_sync(hdev, powered_update_hci, 0, HCI_CMD_TIMEOUT, in __hci_req_hci_power_on()
3419 void hci_request_setup(struct hci_dev *hdev) in hci_request_setup() argument
3421 INIT_WORK(&hdev->discov_update, discov_update); in hci_request_setup()
3422 INIT_WORK(&hdev->bg_scan_update, bg_scan_update); in hci_request_setup()
3423 INIT_WORK(&hdev->scan_update, scan_update_work); in hci_request_setup()
3424 INIT_WORK(&hdev->connectable_update, connectable_update_work); in hci_request_setup()
3425 INIT_WORK(&hdev->discoverable_update, discoverable_update_work); in hci_request_setup()
3426 INIT_DELAYED_WORK(&hdev->discov_off, discov_off); in hci_request_setup()
3427 INIT_DELAYED_WORK(&hdev->le_scan_disable, le_scan_disable_work); in hci_request_setup()
3428 INIT_DELAYED_WORK(&hdev->le_scan_restart, le_scan_restart_work); in hci_request_setup()
3429 INIT_DELAYED_WORK(&hdev->adv_instance_expire, adv_timeout_expire); in hci_request_setup()
3430 INIT_DELAYED_WORK(&hdev->interleave_scan, interleave_scan_work); in hci_request_setup()
3433 void hci_request_cancel_all(struct hci_dev *hdev) in hci_request_cancel_all() argument
3435 hci_req_sync_cancel(hdev, ENODEV); in hci_request_cancel_all()
3437 cancel_work_sync(&hdev->discov_update); in hci_request_cancel_all()
3438 cancel_work_sync(&hdev->bg_scan_update); in hci_request_cancel_all()
3439 cancel_work_sync(&hdev->scan_update); in hci_request_cancel_all()
3440 cancel_work_sync(&hdev->connectable_update); in hci_request_cancel_all()
3441 cancel_work_sync(&hdev->discoverable_update); in hci_request_cancel_all()
3442 cancel_delayed_work_sync(&hdev->discov_off); in hci_request_cancel_all()
3443 cancel_delayed_work_sync(&hdev->le_scan_disable); in hci_request_cancel_all()
3444 cancel_delayed_work_sync(&hdev->le_scan_restart); in hci_request_cancel_all()
3446 if (hdev->adv_instance_timeout) { in hci_request_cancel_all()
3447 cancel_delayed_work_sync(&hdev->adv_instance_expire); in hci_request_cancel_all()
3448 hdev->adv_instance_timeout = 0; in hci_request_cancel_all()
3451 cancel_interleave_scan(hdev); in hci_request_cancel_all()