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
274 if (!test_bit(HCI_UP, &hdev->flags)) in hci_req_sync()
278 hci_req_sync_lock(hdev); in hci_req_sync()
279 ret = __hci_req_sync(hdev, req, opt, timeout, hci_status); in hci_req_sync()
280 hci_req_sync_unlock(hdev); in hci_req_sync()
285 struct sk_buff *hci_prepare_cmd(struct hci_dev *hdev, u16 opcode, u32 plen, in hci_prepare_cmd() argument
315 struct hci_dev *hdev = req->hdev; in hci_req_add_ev() local
318 BT_DBG("%s opcode 0x%4.4x plen %d", hdev->name, opcode, plen); in hci_req_add_ev()
326 skb = hci_prepare_cmd(hdev, opcode, plen, param); in hci_req_add_ev()
328 bt_dev_err(hdev, "no memory for command (opcode 0x%4.4x)", in hci_req_add_ev()
350 struct hci_dev *hdev = req->hdev; in __hci_req_write_fast_connectable() local
354 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in __hci_req_write_fast_connectable()
357 if (hdev->hci_ver < BLUETOOTH_VER_1_2) in __hci_req_write_fast_connectable()
366 type = hdev->def_page_scan_type; in __hci_req_write_fast_connectable()
367 acp.interval = cpu_to_le16(hdev->def_page_scan_int); in __hci_req_write_fast_connectable()
370 acp.window = cpu_to_le16(hdev->def_page_scan_window); in __hci_req_write_fast_connectable()
372 if (__cpu_to_le16(hdev->page_scan_interval) != acp.interval || in __hci_req_write_fast_connectable()
373 __cpu_to_le16(hdev->page_scan_window) != acp.window) in __hci_req_write_fast_connectable()
377 if (hdev->page_scan_type != type) in __hci_req_write_fast_connectable()
389 struct hci_dev *hdev = req->hdev; in __hci_update_background_scan() local
391 if (!test_bit(HCI_UP, &hdev->flags) || in __hci_update_background_scan()
392 test_bit(HCI_INIT, &hdev->flags) || in __hci_update_background_scan()
393 hci_dev_test_flag(hdev, HCI_SETUP) || in __hci_update_background_scan()
394 hci_dev_test_flag(hdev, HCI_CONFIG) || in __hci_update_background_scan()
395 hci_dev_test_flag(hdev, HCI_AUTO_OFF) || in __hci_update_background_scan()
396 hci_dev_test_flag(hdev, HCI_UNREGISTER)) in __hci_update_background_scan()
400 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in __hci_update_background_scan()
404 if (hdev->discovery.state != DISCOVERY_STOPPED) in __hci_update_background_scan()
414 hci_discovery_filter_clear(hdev); in __hci_update_background_scan()
416 BT_DBG("%s ADV monitoring is %s", hdev->name, in __hci_update_background_scan()
417 hci_is_adv_monitoring(hdev) ? "on" : "off"); in __hci_update_background_scan()
419 if (list_empty(&hdev->pend_le_conns) && in __hci_update_background_scan()
420 list_empty(&hdev->pend_le_reports) && in __hci_update_background_scan()
421 !hci_is_adv_monitoring(hdev)) { in __hci_update_background_scan()
428 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN)) in __hci_update_background_scan()
433 BT_DBG("%s stopping background scanning", hdev->name); in __hci_update_background_scan()
443 if (hci_lookup_le_connect(hdev)) in __hci_update_background_scan()
449 if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) in __hci_update_background_scan()
454 BT_DBG("%s starting background scanning", hdev->name); in __hci_update_background_scan()
460 struct hci_dev *hdev = req->hdev; in __hci_req_update_name() local
463 memcpy(cp.name, hdev->dev_name, sizeof(cp.name)); in __hci_req_update_name()
470 static u8 *create_uuid16_list(struct hci_dev *hdev, u8 *data, ptrdiff_t len) in create_uuid16_list() argument
478 list_for_each_entry(uuid, &hdev->uuids, list) { in create_uuid16_list()
512 static u8 *create_uuid32_list(struct hci_dev *hdev, u8 *data, ptrdiff_t len) in create_uuid32_list() argument
520 list_for_each_entry(uuid, &hdev->uuids, list) { in create_uuid32_list()
545 static u8 *create_uuid128_list(struct hci_dev *hdev, u8 *data, ptrdiff_t len) in create_uuid128_list() argument
553 list_for_each_entry(uuid, &hdev->uuids, list) { in create_uuid128_list()
578 static void create_eir(struct hci_dev *hdev, u8 *data) in create_eir() argument
583 name_len = strlen(hdev->dev_name); in create_eir()
596 memcpy(ptr + 2, hdev->dev_name, name_len); in create_eir()
601 if (hdev->inq_tx_power != HCI_TX_POWER_INVALID) { in create_eir()
604 ptr[2] = (u8) hdev->inq_tx_power; in create_eir()
609 if (hdev->devid_source > 0) { in create_eir()
613 put_unaligned_le16(hdev->devid_source, ptr + 2); in create_eir()
614 put_unaligned_le16(hdev->devid_vendor, ptr + 4); in create_eir()
615 put_unaligned_le16(hdev->devid_product, ptr + 6); in create_eir()
616 put_unaligned_le16(hdev->devid_version, ptr + 8); in create_eir()
621 ptr = create_uuid16_list(hdev, ptr, HCI_MAX_EIR_LENGTH - (ptr - data)); in create_eir()
622 ptr = create_uuid32_list(hdev, ptr, HCI_MAX_EIR_LENGTH - (ptr - data)); in create_eir()
623 ptr = create_uuid128_list(hdev, ptr, HCI_MAX_EIR_LENGTH - (ptr - data)); in create_eir()
628 struct hci_dev *hdev = req->hdev; in __hci_req_update_eir() local
631 if (!hdev_is_powered(hdev)) in __hci_req_update_eir()
634 if (!lmp_ext_inq_capable(hdev)) in __hci_req_update_eir()
637 if (!hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in __hci_req_update_eir()
640 if (hci_dev_test_flag(hdev, HCI_SERVICE_CACHE)) in __hci_req_update_eir()
645 create_eir(hdev, cp.data); in __hci_req_update_eir()
647 if (memcmp(cp.data, hdev->eir, sizeof(cp.data)) == 0) in __hci_req_update_eir()
650 memcpy(hdev->eir, cp.data, sizeof(cp.data)); in __hci_req_update_eir()
657 struct hci_dev *hdev = req->hdev; in hci_req_add_le_scan_disable() local
659 if (hdev->scanning_paused) { in hci_req_add_le_scan_disable()
660 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in hci_req_add_le_scan_disable()
664 if (use_ext_scan(hdev)) { in hci_req_add_le_scan_disable()
680 if (use_ll_privacy(hdev) && in hci_req_add_le_scan_disable()
681 hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY) && in hci_req_add_le_scan_disable()
682 hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION) && !rpa_le_conn) { in hci_req_add_le_scan_disable()
697 bt_dev_dbg(req->hdev, "Remove %pMR (0x%x) from whitelist", &cp.bdaddr, in del_from_white_list()
701 if (use_ll_privacy(req->hdev)) { in del_from_white_list()
704 irk = hci_find_irk_by_addr(req->hdev, bdaddr, bdaddr_type); in del_from_white_list()
723 struct hci_dev *hdev = req->hdev; in add_to_white_list() local
726 if (hci_bdaddr_list_lookup(&hdev->le_white_list, &params->addr, in add_to_white_list()
731 if (*num_entries >= hdev->le_white_list_size) in add_to_white_list()
735 if (!allow_rpa && !use_ll_privacy(hdev) && in add_to_white_list()
736 hci_find_irk_by_addr(hdev, &params->addr, params->addr_type)) { in add_to_white_list()
741 if (hdev->suspended && !hci_conn_test_flag(HCI_CONN_FLAG_REMOTE_WAKEUP, in add_to_white_list()
749 bt_dev_dbg(hdev, "Add %pMR (0x%x) to whitelist", &cp.bdaddr, in add_to_white_list()
753 if (use_ll_privacy(hdev)) { in add_to_white_list()
756 irk = hci_find_irk_by_addr(hdev, &params->addr, in add_to_white_list()
765 if (hci_dev_test_flag(hdev, HCI_PRIVACY)) in add_to_white_list()
766 memcpy(cp.local_irk, hdev->irk, 16); in add_to_white_list()
780 struct hci_dev *hdev = req->hdev; in update_white_list() local
790 bool allow_rpa = hdev->suspended; in update_white_list()
798 list_for_each_entry(b, &hdev->le_white_list, list) { in update_white_list()
799 pend_conn = hci_pend_le_action_lookup(&hdev->pend_le_conns, in update_white_list()
802 pend_report = hci_pend_le_action_lookup(&hdev->pend_le_reports, in update_white_list()
815 if (!allow_rpa && !use_ll_privacy(hdev) && in update_white_list()
816 hci_find_irk_by_addr(hdev, &b->bdaddr, b->bdaddr_type)) { in update_white_list()
833 list_for_each_entry(params, &hdev->pend_le_conns, action) { in update_white_list()
842 list_for_each_entry(params, &hdev->pend_le_reports, action) { in update_white_list()
852 if (!idr_is_empty(&hdev->adv_monitors_idr) && !hdev->suspended) in update_white_list()
859 static bool scan_use_rpa(struct hci_dev *hdev) in scan_use_rpa() argument
861 return hci_dev_test_flag(hdev, HCI_PRIVACY); in scan_use_rpa()
868 struct hci_dev *hdev = req->hdev; in hci_req_start_scan() local
870 if (hdev->scanning_paused) { in hci_req_start_scan()
871 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in hci_req_start_scan()
875 if (use_ll_privacy(hdev) && in hci_req_start_scan()
876 hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY) && in hci_req_start_scan()
886 if (use_ext_scan(hdev)) { in hci_req_start_scan()
902 if (scan_1m(hdev) || scan_2m(hdev)) { in hci_req_start_scan()
914 if (scan_coded(hdev)) { in hci_req_start_scan()
957 static inline bool hci_is_le_conn_scanning(struct hci_dev *hdev) in hci_is_le_conn_scanning() argument
959 struct hci_conn_hash *h = &hdev->conn_hash; in hci_is_le_conn_scanning()
983 struct hci_dev *hdev = req->hdev; in hci_req_add_le_passive_scan() local
990 if (hdev->scanning_paused) { in hci_req_add_le_passive_scan()
991 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in hci_req_add_le_passive_scan()
1001 if (hci_update_random_address(req, false, scan_use_rpa(hdev), in hci_req_add_le_passive_scan()
1020 if (hci_dev_test_flag(hdev, HCI_PRIVACY) && in hci_req_add_le_passive_scan()
1021 (hdev->le_features[0] & HCI_LE_EXT_SCAN_POLICY)) in hci_req_add_le_passive_scan()
1024 if (hdev->suspended) { in hci_req_add_le_passive_scan()
1025 window = hdev->le_scan_window_suspend; in hci_req_add_le_passive_scan()
1026 interval = hdev->le_scan_int_suspend; in hci_req_add_le_passive_scan()
1027 } else if (hci_is_le_conn_scanning(hdev)) { in hci_req_add_le_passive_scan()
1028 window = hdev->le_scan_window_connect; in hci_req_add_le_passive_scan()
1029 interval = hdev->le_scan_int_connect; in hci_req_add_le_passive_scan()
1030 } else if (hci_is_adv_monitoring(hdev)) { in hci_req_add_le_passive_scan()
1031 window = hdev->le_scan_window_adv_monitor; in hci_req_add_le_passive_scan()
1032 interval = hdev->le_scan_int_adv_monitor; in hci_req_add_le_passive_scan()
1034 window = hdev->le_scan_window; in hci_req_add_le_passive_scan()
1035 interval = hdev->le_scan_interval; in hci_req_add_le_passive_scan()
1038 bt_dev_dbg(hdev, "LE passive scan with whitelist = %d", filter_policy); in hci_req_add_le_passive_scan()
1043 static u8 get_adv_instance_scan_rsp_len(struct hci_dev *hdev, u8 instance) in get_adv_instance_scan_rsp_len() argument
1051 adv_instance = hci_find_adv_instance(hdev, instance); in get_adv_instance_scan_rsp_len()
1079 struct hci_dev *hdev = req->hdev; in hci_req_set_event_filter() local
1085 list_for_each_entry(b, &hdev->whitelist, list) { in hci_req_set_event_filter()
1096 bt_dev_dbg(hdev, "Adding event filters for %pMR", &b->bdaddr); in hci_req_set_event_filter()
1107 if (hci_dev_test_flag(req->hdev, HCI_LE_SCAN)) in hci_req_config_le_suspend_scan()
1114 set_bit(SUSPEND_SCAN_ENABLE, req->hdev->suspend_tasks); in hci_req_config_le_suspend_scan()
1117 static void cancel_adv_timeout(struct hci_dev *hdev) in cancel_adv_timeout() argument
1119 if (hdev->adv_instance_timeout) { in cancel_adv_timeout()
1120 hdev->adv_instance_timeout = 0; in cancel_adv_timeout()
1121 cancel_delayed_work(&hdev->adv_instance_expire); in cancel_adv_timeout()
1128 bt_dev_dbg(req->hdev, "Suspending advertising instances"); in hci_suspend_adv_instances()
1136 if (!ext_adv_capable(req->hdev)) in hci_suspend_adv_instances()
1137 cancel_adv_timeout(req->hdev); in hci_suspend_adv_instances()
1145 bt_dev_dbg(req->hdev, "Resuming advertising instances"); in hci_resume_adv_instances()
1147 if (ext_adv_capable(req->hdev)) { in hci_resume_adv_instances()
1149 list_for_each_entry(adv, &req->hdev->adv_instances, list) { in hci_resume_adv_instances()
1159 req->hdev->cur_adv_instance, in hci_resume_adv_instances()
1164 static void suspend_req_complete(struct hci_dev *hdev, u8 status, u16 opcode) in suspend_req_complete() argument
1166 bt_dev_dbg(hdev, "Request complete opcode=0x%x, status=0x%x", opcode, in suspend_req_complete()
1168 if (test_and_clear_bit(SUSPEND_SCAN_ENABLE, hdev->suspend_tasks) || in suspend_req_complete()
1169 test_and_clear_bit(SUSPEND_SCAN_DISABLE, hdev->suspend_tasks)) { in suspend_req_complete()
1170 wake_up(&hdev->suspend_wait_q); in suspend_req_complete()
1175 void hci_req_prepare_suspend(struct hci_dev *hdev, enum suspended_state next) in hci_req_prepare_suspend() argument
1183 if (next == hdev->suspend_state) { in hci_req_prepare_suspend()
1184 bt_dev_dbg(hdev, "Same state before and after: %d", next); in hci_req_prepare_suspend()
1188 hdev->suspend_state = next; in hci_req_prepare_suspend()
1189 hci_req_init(&req, hdev); in hci_req_prepare_suspend()
1193 hdev->suspended = true; in hci_req_prepare_suspend()
1196 old_state = hdev->discovery.state; in hci_req_prepare_suspend()
1198 set_bit(SUSPEND_PAUSE_DISCOVERY, hdev->suspend_tasks); in hci_req_prepare_suspend()
1199 hci_discovery_set_state(hdev, DISCOVERY_STOPPING); in hci_req_prepare_suspend()
1200 queue_work(hdev->req_workqueue, &hdev->discov_update); in hci_req_prepare_suspend()
1203 hdev->discovery_paused = true; in hci_req_prepare_suspend()
1204 hdev->discovery_old_state = old_state; in hci_req_prepare_suspend()
1207 old_state = hci_dev_test_flag(hdev, HCI_ADVERTISING); in hci_req_prepare_suspend()
1209 set_bit(SUSPEND_PAUSE_ADVERTISING, hdev->suspend_tasks); in hci_req_prepare_suspend()
1210 cancel_delayed_work(&hdev->discov_off); in hci_req_prepare_suspend()
1211 queue_delayed_work(hdev->req_workqueue, in hci_req_prepare_suspend()
1212 &hdev->discov_off, 0); in hci_req_prepare_suspend()
1216 if (hdev->adv_instance_cnt) in hci_req_prepare_suspend()
1219 hdev->advertising_paused = true; in hci_req_prepare_suspend()
1220 hdev->advertising_old_state = old_state; in hci_req_prepare_suspend()
1226 if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) in hci_req_prepare_suspend()
1230 set_bit(SUSPEND_SCAN_DISABLE, hdev->suspend_tasks); in hci_req_prepare_suspend()
1233 hdev->scanning_paused = true; in hci_req_prepare_suspend()
1240 list_for_each_entry(conn, &hdev->conn_hash.list, list) { in hci_req_prepare_suspend()
1246 bt_dev_dbg(hdev, in hci_req_prepare_suspend()
1249 set_bit(SUSPEND_DISCONNECTING, hdev->suspend_tasks); in hci_req_prepare_suspend()
1253 hdev->scanning_paused = false; in hci_req_prepare_suspend()
1259 hdev->scanning_paused = true; in hci_req_prepare_suspend()
1262 hdev->suspended = false; in hci_req_prepare_suspend()
1263 hdev->scanning_paused = false; in hci_req_prepare_suspend()
1270 hdev->advertising_paused = false; in hci_req_prepare_suspend()
1271 if (hdev->advertising_old_state) { in hci_req_prepare_suspend()
1273 hdev->suspend_tasks); in hci_req_prepare_suspend()
1274 hci_dev_set_flag(hdev, HCI_ADVERTISING); in hci_req_prepare_suspend()
1275 queue_work(hdev->req_workqueue, in hci_req_prepare_suspend()
1276 &hdev->discoverable_update); in hci_req_prepare_suspend()
1277 hdev->advertising_old_state = 0; in hci_req_prepare_suspend()
1281 if (hdev->adv_instance_cnt) in hci_req_prepare_suspend()
1285 hdev->discovery_paused = false; in hci_req_prepare_suspend()
1286 if (hdev->discovery_old_state != DISCOVERY_STOPPED && in hci_req_prepare_suspend()
1287 hdev->discovery_old_state != DISCOVERY_STOPPING) { in hci_req_prepare_suspend()
1288 set_bit(SUSPEND_UNPAUSE_DISCOVERY, hdev->suspend_tasks); in hci_req_prepare_suspend()
1289 hci_discovery_set_state(hdev, DISCOVERY_STARTING); in hci_req_prepare_suspend()
1290 queue_work(hdev->req_workqueue, &hdev->discov_update); in hci_req_prepare_suspend()
1296 hdev->suspend_state = next; in hci_req_prepare_suspend()
1299 clear_bit(SUSPEND_PREPARE_NOTIFIER, hdev->suspend_tasks); in hci_req_prepare_suspend()
1300 wake_up(&hdev->suspend_wait_q); in hci_req_prepare_suspend()
1303 static u8 get_cur_adv_instance_scan_rsp_len(struct hci_dev *hdev) in get_cur_adv_instance_scan_rsp_len() argument
1305 u8 instance = hdev->cur_adv_instance; in get_cur_adv_instance_scan_rsp_len()
1312 adv_instance = hci_find_adv_instance(hdev, instance); in get_cur_adv_instance_scan_rsp_len()
1324 if (ext_adv_capable(req->hdev)) { in __hci_req_disable_advertising()
1334 static u32 get_adv_instance_flags(struct hci_dev *hdev, u8 instance) in get_adv_instance_flags() argument
1348 if (hci_dev_test_flag(hdev, HCI_ADVERTISING_CONNECTABLE)) in get_adv_instance_flags()
1351 if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) in get_adv_instance_flags()
1353 else if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in get_adv_instance_flags()
1359 adv_instance = hci_find_adv_instance(hdev, instance); in get_adv_instance_flags()
1368 static bool adv_use_rpa(struct hci_dev *hdev, uint32_t flags) in adv_use_rpa() argument
1371 if (!hci_dev_test_flag(hdev, HCI_PRIVACY)) in adv_use_rpa()
1375 if (!hci_dev_test_flag(hdev, HCI_LIMITED_PRIVACY)) in adv_use_rpa()
1382 hci_dev_test_flag(hdev, HCI_BONDABLE)) in adv_use_rpa()
1391 static bool is_advertising_allowed(struct hci_dev *hdev, bool connectable) in is_advertising_allowed() argument
1394 if (hci_conn_num(hdev, LE_LINK) == 0) in is_advertising_allowed()
1398 if (hdev->conn_hash.le_num_slave > 0) { in is_advertising_allowed()
1400 if (!connectable && !(hdev->le_states[2] & 0x10)) in is_advertising_allowed()
1406 if (connectable && (!(hdev->le_states[4] & 0x40) || in is_advertising_allowed()
1407 !(hdev->le_states[2] & 0x20))) in is_advertising_allowed()
1412 if (hci_conn_num(hdev, LE_LINK) != hdev->conn_hash.le_num_slave) { in is_advertising_allowed()
1414 if (!connectable && !(hdev->le_states[2] & 0x02)) in is_advertising_allowed()
1420 if (connectable && (!(hdev->le_states[4] & 0x08) || in is_advertising_allowed()
1421 !(hdev->le_states[2] & 0x08))) in is_advertising_allowed()
1430 struct hci_dev *hdev = req->hdev; in __hci_req_enable_advertising() local
1437 flags = get_adv_instance_flags(hdev, hdev->cur_adv_instance); in __hci_req_enable_advertising()
1443 mgmt_get_connectable(hdev); in __hci_req_enable_advertising()
1445 if (!is_advertising_allowed(hdev, connectable)) in __hci_req_enable_advertising()
1448 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in __hci_req_enable_advertising()
1456 hci_dev_clear_flag(hdev, HCI_LE_ADV); in __hci_req_enable_advertising()
1463 adv_use_rpa(hdev, flags), in __hci_req_enable_advertising()
1472 adv_min_interval = hdev->le_adv_min_interval; in __hci_req_enable_advertising()
1473 adv_max_interval = hdev->le_adv_max_interval; in __hci_req_enable_advertising()
1475 if (get_cur_adv_instance_scan_rsp_len(hdev)) in __hci_req_enable_advertising()
1480 if (!hci_dev_test_flag(hdev, HCI_DISCOVERABLE) || in __hci_req_enable_advertising()
1481 hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) { in __hci_req_enable_advertising()
1485 adv_min_interval = hdev->le_adv_min_interval; in __hci_req_enable_advertising()
1486 adv_max_interval = hdev->le_adv_max_interval; in __hci_req_enable_advertising()
1493 cp.channel_map = hdev->le_adv_channel_map; in __hci_req_enable_advertising()
1500 u8 append_local_name(struct hci_dev *hdev, u8 *ptr, u8 ad_len) in append_local_name() argument
1510 complete_len = strlen(hdev->dev_name); in append_local_name()
1513 hdev->dev_name, complete_len + 1); in append_local_name()
1516 short_len = strlen(hdev->short_name); in append_local_name()
1519 hdev->short_name, short_len + 1); in append_local_name()
1527 memcpy(name, hdev->dev_name, HCI_MAX_SHORT_NAME_LENGTH); in append_local_name()
1537 static u8 append_appearance(struct hci_dev *hdev, u8 *ptr, u8 ad_len) in append_appearance() argument
1539 return eir_append_le16(ptr, ad_len, EIR_APPEARANCE, hdev->appearance); in append_appearance()
1542 static u8 create_default_scan_rsp_data(struct hci_dev *hdev, u8 *ptr) in create_default_scan_rsp_data() argument
1546 if (hdev->appearance) { in create_default_scan_rsp_data()
1547 scan_rsp_len = append_appearance(hdev, ptr, scan_rsp_len); in create_default_scan_rsp_data()
1550 return append_local_name(hdev, ptr, scan_rsp_len); in create_default_scan_rsp_data()
1553 static u8 create_instance_scan_rsp_data(struct hci_dev *hdev, u8 instance, in create_instance_scan_rsp_data() argument
1560 adv_instance = hci_find_adv_instance(hdev, instance); in create_instance_scan_rsp_data()
1566 if ((instance_flags & MGMT_ADV_FLAG_APPEARANCE) && hdev->appearance) { in create_instance_scan_rsp_data()
1567 scan_rsp_len = append_appearance(hdev, ptr, scan_rsp_len); in create_instance_scan_rsp_data()
1576 scan_rsp_len = append_local_name(hdev, ptr, scan_rsp_len); in create_instance_scan_rsp_data()
1583 struct hci_dev *hdev = req->hdev; in __hci_req_update_scan_rsp_data() local
1586 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in __hci_req_update_scan_rsp_data()
1589 if (ext_adv_capable(hdev)) { in __hci_req_update_scan_rsp_data()
1597 if (get_adv_instance_scan_rsp_len(hdev, instance)) in __hci_req_update_scan_rsp_data()
1598 len = create_instance_scan_rsp_data(hdev, instance, in __hci_req_update_scan_rsp_data()
1603 if (hdev->scan_rsp_data_len == len && in __hci_req_update_scan_rsp_data()
1604 !memcmp(cp.data, hdev->scan_rsp_data, len)) in __hci_req_update_scan_rsp_data()
1607 memcpy(hdev->scan_rsp_data, cp.data, sizeof(cp.data)); in __hci_req_update_scan_rsp_data()
1608 hdev->scan_rsp_data_len = len; in __hci_req_update_scan_rsp_data()
1623 len = create_instance_scan_rsp_data(hdev, instance, in __hci_req_update_scan_rsp_data()
1626 len = create_default_scan_rsp_data(hdev, cp.data); in __hci_req_update_scan_rsp_data()
1628 if (hdev->scan_rsp_data_len == len && in __hci_req_update_scan_rsp_data()
1629 !memcmp(cp.data, hdev->scan_rsp_data, len)) in __hci_req_update_scan_rsp_data()
1632 memcpy(hdev->scan_rsp_data, cp.data, sizeof(cp.data)); in __hci_req_update_scan_rsp_data()
1633 hdev->scan_rsp_data_len = len; in __hci_req_update_scan_rsp_data()
1641 static u8 create_instance_adv_data(struct hci_dev *hdev, u8 instance, u8 *ptr) in create_instance_adv_data() argument
1649 adv_instance = hci_find_adv_instance(hdev, instance); in create_instance_adv_data()
1654 instance_flags = get_adv_instance_flags(hdev, instance); in create_instance_adv_data()
1673 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in create_instance_adv_data()
1681 flags |= mgmt_get_adv_discov_flags(hdev); in create_instance_adv_data()
1707 if (ext_adv_capable(hdev)) { in create_instance_adv_data()
1711 adv_tx_power = hdev->adv_tx_power; in create_instance_adv_data()
1713 adv_tx_power = hdev->adv_tx_power; in create_instance_adv_data()
1732 struct hci_dev *hdev = req->hdev; in __hci_req_update_adv_data() local
1735 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in __hci_req_update_adv_data()
1738 if (ext_adv_capable(hdev)) { in __hci_req_update_adv_data()
1743 len = create_instance_adv_data(hdev, instance, cp.data); in __hci_req_update_adv_data()
1746 if (hdev->adv_data_len == len && in __hci_req_update_adv_data()
1747 memcmp(cp.data, hdev->adv_data, len) == 0) in __hci_req_update_adv_data()
1750 memcpy(hdev->adv_data, cp.data, sizeof(cp.data)); in __hci_req_update_adv_data()
1751 hdev->adv_data_len = len; in __hci_req_update_adv_data()
1764 len = create_instance_adv_data(hdev, instance, cp.data); in __hci_req_update_adv_data()
1767 if (hdev->adv_data_len == len && in __hci_req_update_adv_data()
1768 memcmp(cp.data, hdev->adv_data, len) == 0) in __hci_req_update_adv_data()
1771 memcpy(hdev->adv_data, cp.data, sizeof(cp.data)); in __hci_req_update_adv_data()
1772 hdev->adv_data_len = len; in __hci_req_update_adv_data()
1780 int hci_req_update_adv_data(struct hci_dev *hdev, u8 instance) in hci_req_update_adv_data() argument
1784 hci_req_init(&req, hdev); in hci_req_update_adv_data()
1790 static void enable_addr_resolution_complete(struct hci_dev *hdev, u8 status, in enable_addr_resolution_complete() argument
1793 BT_DBG("%s status %u", hdev->name, status); in enable_addr_resolution_complete()
1796 void hci_req_disable_address_resolution(struct hci_dev *hdev) in hci_req_disable_address_resolution() argument
1801 if (!use_ll_privacy(hdev) && in hci_req_disable_address_resolution()
1802 !hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION)) in hci_req_disable_address_resolution()
1805 hci_req_init(&req, hdev); in hci_req_disable_address_resolution()
1812 static void adv_enable_complete(struct hci_dev *hdev, u8 status, u16 opcode) in adv_enable_complete() argument
1814 BT_DBG("%s status %u", hdev->name, status); in adv_enable_complete()
1817 void hci_req_reenable_advertising(struct hci_dev *hdev) in hci_req_reenable_advertising() argument
1821 if (!hci_dev_test_flag(hdev, HCI_ADVERTISING) && in hci_req_reenable_advertising()
1822 list_empty(&hdev->adv_instances)) in hci_req_reenable_advertising()
1825 hci_req_init(&req, hdev); in hci_req_reenable_advertising()
1827 if (hdev->cur_adv_instance) { in hci_req_reenable_advertising()
1828 __hci_req_schedule_adv_instance(&req, hdev->cur_adv_instance, in hci_req_reenable_advertising()
1831 if (ext_adv_capable(hdev)) { in hci_req_reenable_advertising()
1845 struct hci_dev *hdev = container_of(work, struct hci_dev, in adv_timeout_expire() local
1851 BT_DBG("%s", hdev->name); in adv_timeout_expire()
1853 hci_dev_lock(hdev); in adv_timeout_expire()
1855 hdev->adv_instance_timeout = 0; in adv_timeout_expire()
1857 instance = hdev->cur_adv_instance; in adv_timeout_expire()
1861 hci_req_init(&req, hdev); in adv_timeout_expire()
1863 hci_req_clear_adv_instance(hdev, NULL, &req, instance, false); in adv_timeout_expire()
1865 if (list_empty(&hdev->adv_instances)) in adv_timeout_expire()
1871 hci_dev_unlock(hdev); in adv_timeout_expire()
1874 int hci_get_random_address(struct hci_dev *hdev, bool require_privacy, in hci_get_random_address() argument
1891 if (use_ll_privacy(hdev)) in hci_get_random_address()
1898 !bacmp(&adv_instance->random_addr, &hdev->rpa)) in hci_get_random_address()
1903 if (!hci_dev_test_and_clear_flag(hdev, HCI_RPA_EXPIRED) && in hci_get_random_address()
1904 !bacmp(&hdev->random_addr, &hdev->rpa)) in hci_get_random_address()
1908 err = smp_generate_rpa(hdev, hdev->irk, &hdev->rpa); in hci_get_random_address()
1910 bt_dev_err(hdev, "failed to generate new RPA"); in hci_get_random_address()
1914 bacpy(rand_addr, &hdev->rpa); in hci_get_random_address()
1916 to = msecs_to_jiffies(hdev->rpa_timeout * 1000); in hci_get_random_address()
1918 queue_delayed_work(hdev->workqueue, in hci_get_random_address()
1921 queue_delayed_work(hdev->workqueue, in hci_get_random_address()
1922 &hdev->rpa_expired, to); in hci_get_random_address()
1945 if (bacmp(&hdev->bdaddr, &nrpa)) in hci_get_random_address()
1969 struct hci_dev *hdev = req->hdev; in __hci_req_setup_ext_adv_instance() local
1979 adv_instance = hci_find_adv_instance(hdev, instance); in __hci_req_setup_ext_adv_instance()
1986 flags = get_adv_instance_flags(hdev, instance); in __hci_req_setup_ext_adv_instance()
1992 mgmt_get_connectable(hdev); in __hci_req_setup_ext_adv_instance()
1994 if (!is_advertising_allowed(hdev, connectable)) in __hci_req_setup_ext_adv_instance()
2001 err = hci_get_random_address(hdev, !connectable, in __hci_req_setup_ext_adv_instance()
2002 adv_use_rpa(hdev, flags), adv_instance, in __hci_req_setup_ext_adv_instance()
2010 hci_cpu_to_le24(hdev->le_adv_min_interval, cp.min_interval); in __hci_req_setup_ext_adv_instance()
2011 hci_cpu_to_le24(hdev->le_adv_max_interval, cp.max_interval); in __hci_req_setup_ext_adv_instance()
2020 } else if (get_adv_instance_scan_rsp_len(hdev, instance)) { in __hci_req_setup_ext_adv_instance()
2033 cp.channel_map = hdev->le_adv_channel_map; in __hci_req_setup_ext_adv_instance()
2060 if (!bacmp(&random_addr, &hdev->random_addr)) in __hci_req_setup_ext_adv_instance()
2079 struct hci_dev *hdev = req->hdev; in __hci_req_enable_ext_advertising() local
2086 adv_instance = hci_find_adv_instance(hdev, instance); in __hci_req_enable_ext_advertising()
2124 struct hci_dev *hdev = req->hdev; in __hci_req_disable_ext_adv_instance() local
2131 if (instance > 0 && !hci_find_adv_instance(hdev, instance)) in __hci_req_disable_ext_adv_instance()
2153 struct hci_dev *hdev = req->hdev; in __hci_req_remove_ext_adv_instance() local
2156 if (instance > 0 && !hci_find_adv_instance(hdev, instance)) in __hci_req_remove_ext_adv_instance()
2166 struct hci_dev *hdev = req->hdev; in __hci_req_start_ext_adv() local
2167 struct adv_info *adv_instance = hci_find_adv_instance(hdev, instance); in __hci_req_start_ext_adv()
2189 struct hci_dev *hdev = req->hdev; in __hci_req_schedule_adv_instance() local
2193 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || in __hci_req_schedule_adv_instance()
2194 list_empty(&hdev->adv_instances)) in __hci_req_schedule_adv_instance()
2197 if (hdev->adv_instance_timeout) in __hci_req_schedule_adv_instance()
2200 adv_instance = hci_find_adv_instance(hdev, instance); in __hci_req_schedule_adv_instance()
2226 if (!ext_adv_capable(hdev)) { in __hci_req_schedule_adv_instance()
2227 hdev->adv_instance_timeout = timeout; in __hci_req_schedule_adv_instance()
2228 queue_delayed_work(hdev->req_workqueue, in __hci_req_schedule_adv_instance()
2229 &hdev->adv_instance_expire, in __hci_req_schedule_adv_instance()
2237 if (!force && hdev->cur_adv_instance == instance && in __hci_req_schedule_adv_instance()
2238 hci_dev_test_flag(hdev, HCI_LE_ADV)) in __hci_req_schedule_adv_instance()
2241 hdev->cur_adv_instance = instance; in __hci_req_schedule_adv_instance()
2242 if (ext_adv_capable(hdev)) { in __hci_req_schedule_adv_instance()
2264 void hci_req_clear_adv_instance(struct hci_dev *hdev, struct sock *sk, in hci_req_clear_adv_instance() argument
2273 if (!instance || hdev->cur_adv_instance == instance) in hci_req_clear_adv_instance()
2274 cancel_adv_timeout(hdev); in hci_req_clear_adv_instance()
2280 if (instance && hdev->cur_adv_instance == instance) in hci_req_clear_adv_instance()
2281 next_instance = hci_get_next_instance(hdev, instance); in hci_req_clear_adv_instance()
2284 list_for_each_entry_safe(adv_instance, n, &hdev->adv_instances, in hci_req_clear_adv_instance()
2290 err = hci_remove_adv_instance(hdev, rem_inst); in hci_req_clear_adv_instance()
2292 mgmt_advertising_removed(sk, hdev, rem_inst); in hci_req_clear_adv_instance()
2295 adv_instance = hci_find_adv_instance(hdev, instance); in hci_req_clear_adv_instance()
2304 err = hci_remove_adv_instance(hdev, instance); in hci_req_clear_adv_instance()
2306 mgmt_advertising_removed(sk, hdev, instance); in hci_req_clear_adv_instance()
2310 if (!req || !hdev_is_powered(hdev) || in hci_req_clear_adv_instance()
2311 hci_dev_test_flag(hdev, HCI_ADVERTISING)) in hci_req_clear_adv_instance()
2314 if (next_instance && !ext_adv_capable(hdev)) in hci_req_clear_adv_instance()
2321 struct hci_dev *hdev = req->hdev; in set_random_addr() local
2333 if (hci_dev_test_flag(hdev, HCI_LE_ADV) || in set_random_addr()
2334 hci_lookup_le_connect(hdev)) { in set_random_addr()
2336 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in set_random_addr()
2346 struct hci_dev *hdev = req->hdev; in hci_update_random_address() local
2359 if (use_ll_privacy(hdev)) in hci_update_random_address()
2364 if (!hci_dev_test_and_clear_flag(hdev, HCI_RPA_EXPIRED) && in hci_update_random_address()
2365 !bacmp(&hdev->random_addr, &hdev->rpa)) in hci_update_random_address()
2368 err = smp_generate_rpa(hdev, hdev->irk, &hdev->rpa); in hci_update_random_address()
2370 bt_dev_err(hdev, "failed to generate new RPA"); in hci_update_random_address()
2374 set_random_addr(req, &hdev->rpa); in hci_update_random_address()
2376 to = msecs_to_jiffies(hdev->rpa_timeout * 1000); in hci_update_random_address()
2377 queue_delayed_work(hdev->workqueue, &hdev->rpa_expired, to); in hci_update_random_address()
2400 if (bacmp(&hdev->bdaddr, &nrpa)) in hci_update_random_address()
2418 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in hci_update_random_address()
2419 !bacmp(&hdev->bdaddr, BDADDR_ANY) || in hci_update_random_address()
2420 (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in hci_update_random_address()
2421 bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_update_random_address()
2423 if (bacmp(&hdev->static_addr, &hdev->random_addr)) in hci_update_random_address()
2425 &hdev->static_addr); in hci_update_random_address()
2437 static bool disconnected_whitelist_entries(struct hci_dev *hdev) in disconnected_whitelist_entries() argument
2441 list_for_each_entry(b, &hdev->whitelist, list) { in disconnected_whitelist_entries()
2444 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &b->bdaddr); in disconnected_whitelist_entries()
2457 struct hci_dev *hdev = req->hdev; in __hci_req_update_scan() local
2460 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in __hci_req_update_scan()
2463 if (!hdev_is_powered(hdev)) in __hci_req_update_scan()
2466 if (mgmt_powering_down(hdev)) in __hci_req_update_scan()
2469 if (hdev->scanning_paused) in __hci_req_update_scan()
2472 if (hci_dev_test_flag(hdev, HCI_CONNECTABLE) || in __hci_req_update_scan()
2473 disconnected_whitelist_entries(hdev)) in __hci_req_update_scan()
2478 if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in __hci_req_update_scan()
2481 if (test_bit(HCI_PSCAN, &hdev->flags) == !!(scan & SCAN_PAGE) && in __hci_req_update_scan()
2482 test_bit(HCI_ISCAN, &hdev->flags) == !!(scan & SCAN_INQUIRY)) in __hci_req_update_scan()
2490 hci_dev_lock(req->hdev); in update_scan()
2492 hci_dev_unlock(req->hdev); in update_scan()
2498 struct hci_dev *hdev = container_of(work, struct hci_dev, scan_update); in scan_update_work() local
2500 hci_req_sync(hdev, update_scan, 0, HCI_CMD_TIMEOUT, NULL); in scan_update_work()
2505 struct hci_dev *hdev = req->hdev; in connectable_update() local
2507 hci_dev_lock(hdev); in connectable_update()
2515 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in connectable_update()
2516 __hci_req_update_adv_data(req, hdev->cur_adv_instance); in connectable_update()
2519 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || in connectable_update()
2520 !list_empty(&hdev->adv_instances)) { in connectable_update()
2521 if (ext_adv_capable(hdev)) in connectable_update()
2522 __hci_req_start_ext_adv(req, hdev->cur_adv_instance); in connectable_update()
2529 hci_dev_unlock(hdev); in connectable_update()
2536 struct hci_dev *hdev = container_of(work, struct hci_dev, in connectable_update_work() local
2540 hci_req_sync(hdev, connectable_update, 0, HCI_CMD_TIMEOUT, &status); in connectable_update_work()
2541 mgmt_set_connectable_complete(hdev, status); in connectable_update_work()
2544 static u8 get_service_classes(struct hci_dev *hdev) in get_service_classes() argument
2549 list_for_each_entry(uuid, &hdev->uuids, list) in get_service_classes()
2557 struct hci_dev *hdev = req->hdev; in __hci_req_update_class() local
2560 BT_DBG("%s", hdev->name); in __hci_req_update_class()
2562 if (!hdev_is_powered(hdev)) in __hci_req_update_class()
2565 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in __hci_req_update_class()
2568 if (hci_dev_test_flag(hdev, HCI_SERVICE_CACHE)) in __hci_req_update_class()
2571 cod[0] = hdev->minor_class; in __hci_req_update_class()
2572 cod[1] = hdev->major_class; in __hci_req_update_class()
2573 cod[2] = get_service_classes(hdev); in __hci_req_update_class()
2575 if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) in __hci_req_update_class()
2578 if (memcmp(cod, hdev->dev_class, 3) == 0) in __hci_req_update_class()
2586 struct hci_dev *hdev = req->hdev; in write_iac() local
2589 if (!hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in write_iac()
2592 if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) { in write_iac()
2594 cp.num_iac = min_t(u8, hdev->num_iac, 2); in write_iac()
2615 struct hci_dev *hdev = req->hdev; in discoverable_update() local
2617 hci_dev_lock(hdev); in discoverable_update()
2619 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in discoverable_update()
2628 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) { in discoverable_update()
2634 if (hci_dev_test_flag(hdev, HCI_LIMITED_PRIVACY)) { in discoverable_update()
2635 if (ext_adv_capable(hdev)) in discoverable_update()
2642 hci_dev_unlock(hdev); in discoverable_update()
2649 struct hci_dev *hdev = container_of(work, struct hci_dev, in discoverable_update_work() local
2653 hci_req_sync(hdev, discoverable_update, 0, HCI_CMD_TIMEOUT, &status); in discoverable_update_work()
2654 mgmt_set_discoverable_complete(hdev, status); in discoverable_update_work()
2688 if (req->hdev->hci_ver < BLUETOOTH_VER_1_2) in __hci_abort_conn()
2726 static void abort_conn_complete(struct hci_dev *hdev, u8 status, u16 opcode) in abort_conn_complete() argument
2737 hci_req_init(&req, conn->hdev); in hci_abort_conn()
2743 bt_dev_err(conn->hdev, "failed to run HCI request: err %d", err); in hci_abort_conn()
2752 hci_dev_lock(req->hdev); in update_bg_scan()
2754 hci_dev_unlock(req->hdev); in update_bg_scan()
2760 struct hci_dev *hdev = container_of(work, struct hci_dev, in bg_scan_update() local
2766 err = hci_req_sync(hdev, update_bg_scan, 0, HCI_CMD_TIMEOUT, &status); in bg_scan_update()
2770 hci_dev_lock(hdev); in bg_scan_update()
2772 conn = hci_conn_hash_lookup_state(hdev, LE_LINK, BT_CONNECT); in bg_scan_update()
2776 hci_dev_unlock(hdev); in bg_scan_update()
2792 BT_DBG("%s", req->hdev->name); in bredr_inquiry()
2794 hci_dev_lock(req->hdev); in bredr_inquiry()
2795 hci_inquiry_cache_flush(req->hdev); in bredr_inquiry()
2796 hci_dev_unlock(req->hdev); in bredr_inquiry()
2800 if (req->hdev->discovery.limited) in bredr_inquiry()
2814 struct hci_dev *hdev = container_of(work, struct hci_dev, in le_scan_disable_work() local
2818 BT_DBG("%s", hdev->name); in le_scan_disable_work()
2820 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN)) in le_scan_disable_work()
2823 cancel_delayed_work(&hdev->le_scan_restart); in le_scan_disable_work()
2825 hci_req_sync(hdev, le_scan_disable, 0, HCI_CMD_TIMEOUT, &status); in le_scan_disable_work()
2827 bt_dev_err(hdev, "failed to disable LE scan: status 0x%02x", in le_scan_disable_work()
2832 hdev->discovery.scan_start = 0; in le_scan_disable_work()
2842 if (hdev->discovery.type == DISCOV_TYPE_LE) in le_scan_disable_work()
2845 if (hdev->discovery.type != DISCOV_TYPE_INTERLEAVED) in le_scan_disable_work()
2848 if (test_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks)) { in le_scan_disable_work()
2849 if (!test_bit(HCI_INQUIRY, &hdev->flags) && in le_scan_disable_work()
2850 hdev->discovery.state != DISCOVERY_RESOLVING) in le_scan_disable_work()
2856 hci_req_sync(hdev, bredr_inquiry, DISCOV_INTERLEAVED_INQUIRY_LEN, in le_scan_disable_work()
2859 bt_dev_err(hdev, "inquiry failed: status 0x%02x", status); in le_scan_disable_work()
2866 hci_dev_lock(hdev); in le_scan_disable_work()
2867 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in le_scan_disable_work()
2868 hci_dev_unlock(hdev); in le_scan_disable_work()
2873 struct hci_dev *hdev = req->hdev; in le_scan_restart() local
2876 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN)) in le_scan_restart()
2879 if (hdev->scanning_paused) { in le_scan_restart()
2880 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in le_scan_restart()
2886 if (use_ext_scan(hdev)) { in le_scan_restart()
2909 struct hci_dev *hdev = container_of(work, struct hci_dev, in le_scan_restart_work() local
2914 BT_DBG("%s", hdev->name); in le_scan_restart_work()
2916 hci_req_sync(hdev, le_scan_restart, 0, HCI_CMD_TIMEOUT, &status); in le_scan_restart_work()
2918 bt_dev_err(hdev, "failed to restart LE scan: status %d", in le_scan_restart_work()
2923 hci_dev_lock(hdev); in le_scan_restart_work()
2925 if (!test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks) || in le_scan_restart_work()
2926 !hdev->discovery.scan_start) in le_scan_restart_work()
2934 duration = hdev->discovery.scan_duration; in le_scan_restart_work()
2935 scan_start = hdev->discovery.scan_start; in le_scan_restart_work()
2950 queue_delayed_work(hdev->req_workqueue, in le_scan_restart_work()
2951 &hdev->le_scan_disable, timeout); in le_scan_restart_work()
2954 hci_dev_unlock(hdev); in le_scan_restart_work()
2960 struct hci_dev *hdev = req->hdev; in active_scan() local
2968 BT_DBG("%s", hdev->name); in active_scan()
2974 if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) in active_scan()
2981 err = hci_update_random_address(req, true, scan_use_rpa(hdev), in active_scan()
2987 hdev->le_scan_window_discovery, own_addr_type, in active_scan()
2996 BT_DBG("%s", req->hdev->name); in interleaved_discov()
3005 static void start_discovery(struct hci_dev *hdev, u8 *status) in start_discovery() argument
3009 BT_DBG("%s type %u", hdev->name, hdev->discovery.type); in start_discovery()
3011 switch (hdev->discovery.type) { in start_discovery()
3013 if (!hci_dev_test_flag(hdev, HCI_INQUIRY)) in start_discovery()
3014 hci_req_sync(hdev, bredr_inquiry, in start_discovery()
3028 &hdev->quirks)) { in start_discovery()
3034 hci_req_sync(hdev, interleaved_discov, in start_discovery()
3035 hdev->le_scan_int_discovery * 2, HCI_CMD_TIMEOUT, in start_discovery()
3040 timeout = msecs_to_jiffies(hdev->discov_interleaved_timeout); in start_discovery()
3041 hci_req_sync(hdev, active_scan, hdev->le_scan_int_discovery, in start_discovery()
3046 hci_req_sync(hdev, active_scan, hdev->le_scan_int_discovery, in start_discovery()
3057 BT_DBG("%s timeout %u ms", hdev->name, jiffies_to_msecs(timeout)); in start_discovery()
3064 if (test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks) && in start_discovery()
3065 hdev->discovery.result_filtering) { in start_discovery()
3066 hdev->discovery.scan_start = jiffies; in start_discovery()
3067 hdev->discovery.scan_duration = timeout; in start_discovery()
3070 queue_delayed_work(hdev->req_workqueue, &hdev->le_scan_disable, in start_discovery()
3076 struct hci_dev *hdev = req->hdev; in hci_req_stop_discovery() local
3077 struct discovery_state *d = &hdev->discovery; in hci_req_stop_discovery()
3082 BT_DBG("%s state %u", hdev->name, hdev->discovery.state); in hci_req_stop_discovery()
3085 if (test_bit(HCI_INQUIRY, &hdev->flags)) in hci_req_stop_discovery()
3088 if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) { in hci_req_stop_discovery()
3089 cancel_delayed_work(&hdev->le_scan_disable); in hci_req_stop_discovery()
3096 if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) { in hci_req_stop_discovery()
3107 e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, in hci_req_stop_discovery()
3123 hci_dev_lock(req->hdev); in stop_discovery()
3125 hci_dev_unlock(req->hdev); in stop_discovery()
3132 struct hci_dev *hdev = container_of(work, struct hci_dev, in discov_update() local
3136 switch (hdev->discovery.state) { in discov_update()
3138 start_discovery(hdev, &status); in discov_update()
3139 mgmt_start_discovery_complete(hdev, status); in discov_update()
3141 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in discov_update()
3143 hci_discovery_set_state(hdev, DISCOVERY_FINDING); in discov_update()
3146 hci_req_sync(hdev, stop_discovery, 0, HCI_CMD_TIMEOUT, &status); in discov_update()
3147 mgmt_stop_discovery_complete(hdev, status); in discov_update()
3149 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in discov_update()
3159 struct hci_dev *hdev = container_of(work, struct hci_dev, in discov_off() local
3162 BT_DBG("%s", hdev->name); in discov_off()
3164 hci_dev_lock(hdev); in discov_off()
3171 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in discov_off()
3172 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in discov_off()
3173 hdev->discov_timeout = 0; in discov_off()
3175 hci_dev_unlock(hdev); in discov_off()
3177 hci_req_sync(hdev, discoverable_update, 0, HCI_CMD_TIMEOUT, NULL); in discov_off()
3178 mgmt_new_settings(hdev); in discov_off()
3183 struct hci_dev *hdev = req->hdev; in powered_update_hci() local
3186 hci_dev_lock(hdev); in powered_update_hci()
3188 if (hci_dev_test_flag(hdev, HCI_SSP_ENABLED) && in powered_update_hci()
3189 !lmp_host_ssp_capable(hdev)) { in powered_update_hci()
3194 if (bredr_sc_enabled(hdev) && !lmp_host_sc_capable(hdev)) { in powered_update_hci()
3202 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED) && in powered_update_hci()
3203 lmp_bredr_capable(hdev)) { in powered_update_hci()
3212 if (cp.le != lmp_host_le_capable(hdev) || in powered_update_hci()
3213 cp.simul != lmp_host_le_br_capable(hdev)) in powered_update_hci()
3218 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { in powered_update_hci()
3223 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || in powered_update_hci()
3224 list_empty(&hdev->adv_instances)) { in powered_update_hci()
3227 if (ext_adv_capable(hdev)) { in powered_update_hci()
3239 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) { in powered_update_hci()
3240 if (!ext_adv_capable(hdev)) in powered_update_hci()
3246 } else if (!list_empty(&hdev->adv_instances)) { in powered_update_hci()
3249 adv_instance = list_first_entry(&hdev->adv_instances, in powered_update_hci()
3257 link_sec = hci_dev_test_flag(hdev, HCI_LINK_SECURITY); in powered_update_hci()
3258 if (link_sec != test_bit(HCI_AUTH, &hdev->flags)) in powered_update_hci()
3262 if (lmp_bredr_capable(hdev)) { in powered_update_hci()
3263 if (hci_dev_test_flag(hdev, HCI_FAST_CONNECTABLE)) in powered_update_hci()
3273 hci_dev_unlock(hdev); in powered_update_hci()
3277 int __hci_req_hci_power_on(struct hci_dev *hdev) in __hci_req_hci_power_on() argument
3284 smp_register(hdev); in __hci_req_hci_power_on()
3286 return __hci_req_sync(hdev, powered_update_hci, 0, HCI_CMD_TIMEOUT, in __hci_req_hci_power_on()
3290 void hci_request_setup(struct hci_dev *hdev) in hci_request_setup() argument
3292 INIT_WORK(&hdev->discov_update, discov_update); in hci_request_setup()
3293 INIT_WORK(&hdev->bg_scan_update, bg_scan_update); in hci_request_setup()
3294 INIT_WORK(&hdev->scan_update, scan_update_work); in hci_request_setup()
3295 INIT_WORK(&hdev->connectable_update, connectable_update_work); in hci_request_setup()
3296 INIT_WORK(&hdev->discoverable_update, discoverable_update_work); in hci_request_setup()
3297 INIT_DELAYED_WORK(&hdev->discov_off, discov_off); in hci_request_setup()
3298 INIT_DELAYED_WORK(&hdev->le_scan_disable, le_scan_disable_work); in hci_request_setup()
3299 INIT_DELAYED_WORK(&hdev->le_scan_restart, le_scan_restart_work); in hci_request_setup()
3300 INIT_DELAYED_WORK(&hdev->adv_instance_expire, adv_timeout_expire); in hci_request_setup()
3303 void hci_request_cancel_all(struct hci_dev *hdev) in hci_request_cancel_all() argument
3305 hci_req_sync_cancel(hdev, ENODEV); in hci_request_cancel_all()
3307 cancel_work_sync(&hdev->discov_update); in hci_request_cancel_all()
3308 cancel_work_sync(&hdev->bg_scan_update); in hci_request_cancel_all()
3309 cancel_work_sync(&hdev->scan_update); in hci_request_cancel_all()
3310 cancel_work_sync(&hdev->connectable_update); in hci_request_cancel_all()
3311 cancel_work_sync(&hdev->discoverable_update); in hci_request_cancel_all()
3312 cancel_delayed_work_sync(&hdev->discov_off); in hci_request_cancel_all()
3313 cancel_delayed_work_sync(&hdev->le_scan_disable); in hci_request_cancel_all()
3314 cancel_delayed_work_sync(&hdev->le_scan_restart); in hci_request_cancel_all()
3316 if (hdev->adv_instance_timeout) { in hci_request_cancel_all()
3317 cancel_delayed_work_sync(&hdev->adv_instance_expire); in hci_request_cancel_all()
3318 hdev->adv_instance_timeout = 0; in hci_request_cancel_all()