Lines Matching +full:wake +full:- +full:on +full:- +full:filer

1 // SPDX-License-Identifier: GPL-2.0
3 * BlueZ - Bluetooth protocol stack for Linux
28 if (hdev->req_status != HCI_REQ_PEND) in hci_cmd_sync_complete()
31 hdev->req_result = result; in hci_cmd_sync_complete()
32 hdev->req_status = HCI_REQ_DONE; in hci_cmd_sync_complete()
35 kfree_skb(hdev->req_skb); in hci_cmd_sync_complete()
36 hdev->req_skb = NULL; in hci_cmd_sync_complete()
45 hdev->req_rsp = skb_get(skb); in hci_cmd_sync_complete()
48 wake_up_interruptible(&hdev->req_wait_q); in hci_cmd_sync_complete()
63 hdr->opcode = cpu_to_le16(opcode); in hci_cmd_sync_alloc()
64 hdr->plen = plen; in hci_cmd_sync_alloc()
69 bt_dev_dbg(hdev, "skb len %d", skb->len); in hci_cmd_sync_alloc()
88 struct hci_dev *hdev = req->hdev; in hci_cmd_sync_add()
96 if (req->err) in hci_cmd_sync_add()
103 req->err = -ENOMEM; in hci_cmd_sync_add()
107 if (skb_queue_empty(&req->cmd_q)) in hci_cmd_sync_add()
108 bt_cb(skb)->hci.req_flags |= HCI_REQ_START; in hci_cmd_sync_add()
112 skb_queue_tail(&req->cmd_q, skb); in hci_cmd_sync_add()
117 struct hci_dev *hdev = req->hdev; in hci_req_sync_run()
121 bt_dev_dbg(hdev, "length %u", skb_queue_len(&req->cmd_q)); in hci_req_sync_run()
124 * commands queued on the HCI request queue. in hci_req_sync_run()
126 if (req->err) { in hci_req_sync_run()
127 skb_queue_purge(&req->cmd_q); in hci_req_sync_run()
128 return req->err; in hci_req_sync_run()
132 if (skb_queue_empty(&req->cmd_q)) in hci_req_sync_run()
133 return -ENODATA; in hci_req_sync_run()
135 skb = skb_peek_tail(&req->cmd_q); in hci_req_sync_run()
136 bt_cb(skb)->hci.req_complete_skb = hci_cmd_sync_complete; in hci_req_sync_run()
137 bt_cb(skb)->hci.req_flags |= HCI_REQ_SKB; in hci_req_sync_run()
139 spin_lock_irqsave(&hdev->cmd_q.lock, flags); in hci_req_sync_run()
140 skb_queue_splice_tail(&req->cmd_q, &hdev->cmd_q); in hci_req_sync_run()
141 spin_unlock_irqrestore(&hdev->cmd_q.lock, flags); in hci_req_sync_run()
143 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_req_sync_run()
150 skb_queue_head_init(&req->cmd_q); in hci_request_init()
151 req->hdev = hdev; in hci_request_init()
152 req->err = 0; in hci_request_init()
155 /* This function requires the caller holds hdev->req_lock. */
170 hdev->req_status = HCI_REQ_PEND; in __hci_cmd_sync_sk()
176 err = wait_event_interruptible_timeout(hdev->req_wait_q, in __hci_cmd_sync_sk()
177 hdev->req_status != HCI_REQ_PEND, in __hci_cmd_sync_sk()
180 if (err == -ERESTARTSYS) in __hci_cmd_sync_sk()
181 return ERR_PTR(-EINTR); in __hci_cmd_sync_sk()
183 switch (hdev->req_status) { in __hci_cmd_sync_sk()
185 err = -bt_to_errno(hdev->req_result); in __hci_cmd_sync_sk()
189 err = -hdev->req_result; in __hci_cmd_sync_sk()
193 err = -ETIMEDOUT; in __hci_cmd_sync_sk()
197 hdev->req_status = 0; in __hci_cmd_sync_sk()
198 hdev->req_result = 0; in __hci_cmd_sync_sk()
199 skb = hdev->req_rsp; in __hci_cmd_sync_sk()
200 hdev->req_rsp = NULL; in __hci_cmd_sync_sk()
213 return ERR_PTR(-ENODATA); in __hci_cmd_sync_sk()
219 /* This function requires the caller holds hdev->req_lock. */
233 if (!test_bit(HCI_UP, &hdev->flags)) in hci_cmd_sync()
234 return ERR_PTR(-ENETDOWN); in hci_cmd_sync()
246 /* This function requires the caller holds hdev->req_lock. */
255 /* This function requires the caller holds hdev->req_lock. */
265 /* If command return a status event, skb will be set to -ENODATA */ in __hci_cmd_sync_status_sk()
266 if (skb == ERR_PTR(-ENODATA)) in __hci_cmd_sync_status_sk()
276 status = skb->data[0]; in __hci_cmd_sync_status_sk()
315 mutex_lock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_work()
316 entry = list_first_entry_or_null(&hdev->cmd_sync_work_list, in hci_cmd_sync_work()
320 list_del(&entry->list); in hci_cmd_sync_work()
321 mutex_unlock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_work()
328 if (entry->func) { in hci_cmd_sync_work()
332 err = entry->func(hdev, entry->data); in hci_cmd_sync_work()
333 if (entry->destroy) in hci_cmd_sync_work()
334 entry->destroy(hdev, entry->data, err); in hci_cmd_sync_work()
346 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_cmd_sync_cancel_work()
347 cancel_delayed_work_sync(&hdev->ncmd_timer); in hci_cmd_sync_cancel_work()
348 atomic_set(&hdev->cmd_cnt, 1); in hci_cmd_sync_cancel_work()
350 wake_up_interruptible(&hdev->req_wait_q); in hci_cmd_sync_cancel_work()
390 if (hdev->discovery.type == DISCOV_TYPE_LE) in le_scan_disable()
393 if (hdev->discovery.type != DISCOV_TYPE_INTERLEAVED) in le_scan_disable()
397 if (!test_bit(HCI_INQUIRY, &hdev->flags) && in le_scan_disable()
398 hdev->discovery.state != DISCOVERY_RESOLVING) in le_scan_disable()
427 list_empty(&hdev->adv_instances)) in reenable_adv_sync()
430 if (hdev->cur_adv_instance) { in reenable_adv_sync()
432 hdev->cur_adv_instance, in reenable_adv_sync()
466 if (hdev->adv_instance_timeout) { in cancel_adv_timeout()
467 hdev->adv_instance_timeout = 0; in cancel_adv_timeout()
468 cancel_delayed_work(&hdev->adv_instance_expire); in cancel_adv_timeout()
473 * - force == true: The instance will be removed even when its remaining
475 * - force == false: the instance will be deactivated but kept stored unless
479 * - force == true: All instances will be removed regardless of their timeout
481 * - force == false: Only instances that have a timeout will be removed.
491 if (!instance || hdev->cur_adv_instance == instance) in hci_clear_adv_instance_sync()
498 if (instance && hdev->cur_adv_instance == instance) in hci_clear_adv_instance_sync()
502 list_for_each_entry_safe(adv_instance, n, &hdev->adv_instances, in hci_clear_adv_instance_sync()
504 if (!(force || adv_instance->timeout)) in hci_clear_adv_instance_sync()
507 rem_inst = adv_instance->instance; in hci_clear_adv_instance_sync()
515 if (force || (adv_instance && adv_instance->timeout && in hci_clear_adv_instance_sync()
516 !adv_instance->remaining_time)) { in hci_clear_adv_instance_sync()
519 next_instance->instance == instance) in hci_clear_adv_instance_sync()
533 next_instance->instance, in hci_clear_adv_instance_sync()
547 if (list_empty(&hdev->adv_instances)) in adv_timeout_expire_sync()
563 hdev->adv_instance_timeout = 0; in adv_timeout_expire()
565 if (hdev->cur_adv_instance == 0x00) in adv_timeout_expire()
572 *inst_ptr = hdev->cur_adv_instance; in adv_timeout_expire()
581 return hdev->interleave_scan_state != INTERLEAVE_SCAN_NONE; in is_interleave_scanning()
592 if (hdev->interleave_scan_state == INTERLEAVE_SCAN_ALLOWLIST) { in interleave_scan_work()
593 timeout = msecs_to_jiffies(hdev->advmon_allowlist_duration); in interleave_scan_work()
594 } else if (hdev->interleave_scan_state == INTERLEAVE_SCAN_NO_FILTER) { in interleave_scan_work()
595 timeout = msecs_to_jiffies(hdev->advmon_no_filter_duration); in interleave_scan_work()
605 switch (hdev->interleave_scan_state) { in interleave_scan_work()
608 hdev->interleave_scan_state = INTERLEAVE_SCAN_NO_FILTER; in interleave_scan_work()
612 hdev->interleave_scan_state = INTERLEAVE_SCAN_ALLOWLIST; in interleave_scan_work()
622 queue_delayed_work(hdev->req_workqueue, in interleave_scan_work()
623 &hdev->interleave_scan, timeout); in interleave_scan_work()
628 INIT_WORK(&hdev->cmd_sync_work, hci_cmd_sync_work); in hci_cmd_sync_init()
629 INIT_LIST_HEAD(&hdev->cmd_sync_work_list); in hci_cmd_sync_init()
630 mutex_init(&hdev->cmd_sync_work_lock); in hci_cmd_sync_init()
631 mutex_init(&hdev->unregister_lock); in hci_cmd_sync_init()
633 INIT_WORK(&hdev->cmd_sync_cancel_work, hci_cmd_sync_cancel_work); in hci_cmd_sync_init()
634 INIT_WORK(&hdev->reenable_adv_work, reenable_adv); in hci_cmd_sync_init()
635 INIT_DELAYED_WORK(&hdev->le_scan_disable, le_scan_disable); in hci_cmd_sync_init()
636 INIT_DELAYED_WORK(&hdev->adv_instance_expire, adv_timeout_expire); in hci_cmd_sync_init()
637 INIT_DELAYED_WORK(&hdev->interleave_scan, interleave_scan_work); in hci_cmd_sync_init()
644 if (entry->destroy) in _hci_cmd_sync_cancel_entry()
645 entry->destroy(hdev, entry->data, err); in _hci_cmd_sync_cancel_entry()
647 list_del(&entry->list); in _hci_cmd_sync_cancel_entry()
655 cancel_work_sync(&hdev->cmd_sync_work); in hci_cmd_sync_clear()
656 cancel_work_sync(&hdev->reenable_adv_work); in hci_cmd_sync_clear()
658 mutex_lock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_clear()
659 list_for_each_entry_safe(entry, tmp, &hdev->cmd_sync_work_list, list) in hci_cmd_sync_clear()
660 _hci_cmd_sync_cancel_entry(hdev, entry, -ECANCELED); in hci_cmd_sync_clear()
661 mutex_unlock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_clear()
668 if (hdev->req_status == HCI_REQ_PEND) { in hci_cmd_sync_cancel()
669 hdev->req_result = err; in hci_cmd_sync_cancel()
670 hdev->req_status = HCI_REQ_CANCELED; in hci_cmd_sync_cancel()
672 queue_work(hdev->workqueue, &hdev->cmd_sync_cancel_work); in hci_cmd_sync_cancel()
679 * - Set result and mark status to HCI_REQ_CANCELED
680 * - Wakeup command sync thread
686 if (hdev->req_status == HCI_REQ_PEND) { in hci_cmd_sync_cancel_sync()
690 hdev->req_result = err < 0 ? -err : err; in hci_cmd_sync_cancel_sync()
691 hdev->req_status = HCI_REQ_CANCELED; in hci_cmd_sync_cancel_sync()
693 wake_up_interruptible(&hdev->req_wait_q); in hci_cmd_sync_cancel_sync()
700 * - hdev must _not_ be unregistered
708 mutex_lock(&hdev->unregister_lock); in hci_cmd_sync_submit()
710 err = -ENODEV; in hci_cmd_sync_submit()
716 err = -ENOMEM; in hci_cmd_sync_submit()
719 entry->func = func; in hci_cmd_sync_submit()
720 entry->data = data; in hci_cmd_sync_submit()
721 entry->destroy = destroy; in hci_cmd_sync_submit()
723 mutex_lock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_submit()
724 list_add_tail(&entry->list, &hdev->cmd_sync_work_list); in hci_cmd_sync_submit()
725 mutex_unlock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_submit()
727 queue_work(hdev->req_workqueue, &hdev->cmd_sync_work); in hci_cmd_sync_submit()
730 mutex_unlock(&hdev->unregister_lock); in hci_cmd_sync_submit()
737 * - hdev must be running
743 * and is either on init phase or is already up. in hci_cmd_sync_queue()
745 if (!test_bit(HCI_RUNNING, &hdev->flags)) in hci_cmd_sync_queue()
746 return -ENETDOWN; in hci_cmd_sync_queue()
758 list_for_each_entry_safe(entry, tmp, &hdev->cmd_sync_work_list, list) { in _hci_cmd_sync_lookup_entry()
759 if (func && entry->func != func) in _hci_cmd_sync_lookup_entry()
762 if (data && entry->data != data) in _hci_cmd_sync_lookup_entry()
765 if (destroy && entry->destroy != destroy) in _hci_cmd_sync_lookup_entry()
776 * - Lookup if an entry already exist and only if it doesn't creates a new entry
791 * - hdev must be running
792 * - if on cmd_sync_work then run immediately otherwise queue
798 * and is either on init phase or is already up. in hci_cmd_sync_run()
800 if (!test_bit(HCI_RUNNING, &hdev->flags)) in hci_cmd_sync_run()
801 return -ENETDOWN; in hci_cmd_sync_run()
803 /* If on cmd_sync_work then run immediately otherwise queue */ in hci_cmd_sync_run()
804 if (current_work() == &hdev->cmd_sync_work) in hci_cmd_sync_run()
813 * - Lookup if an entry already exist and only if it doesn't creates a new entry
815 * - if on cmd_sync_work then run immediately otherwise queue
829 * - Return first entry that matches by function callback or data or
838 mutex_lock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_lookup_entry()
840 mutex_unlock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_lookup_entry()
850 mutex_lock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_cancel_entry()
851 _hci_cmd_sync_cancel_entry(hdev, entry, -ECANCELED); in hci_cmd_sync_cancel_entry()
852 mutex_unlock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_cancel_entry()
858 * - Lookup and cancel first entry that matches.
878 * - Lookup and cancel any entry that matches by function callback or data or
887 mutex_lock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_dequeue()
890 _hci_cmd_sync_cancel_entry(hdev, entry, -ECANCELED); in hci_cmd_sync_dequeue()
893 mutex_unlock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_dequeue()
921 if (memcmp(cp.data, hdev->eir, sizeof(cp.data)) == 0) in hci_update_eir_sync()
924 memcpy(hdev->eir, cp.data, sizeof(cp.data)); in hci_update_eir_sync()
935 list_for_each_entry(uuid, &hdev->uuids, list) in get_service_classes()
936 val |= uuid->svc_hint; in get_service_classes()
956 cod[0] = hdev->minor_class; in hci_update_class_sync()
957 cod[1] = hdev->major_class; in hci_update_class_sync()
963 if (memcmp(cod, hdev->dev_class, 3) == 0) in hci_update_class_sync()
977 if (hdev->conn_hash.le_num_peripheral > 0) { in is_advertising_allowed()
981 if (!connectable && !(hdev->le_states[2] & 0x10)) in is_advertising_allowed()
987 if (connectable && (!(hdev->le_states[4] & 0x40) || in is_advertising_allowed()
988 !(hdev->le_states[2] & 0x20))) in is_advertising_allowed()
993 if (hci_conn_num(hdev, LE_LINK) != hdev->conn_hash.le_num_peripheral) { in is_advertising_allowed()
995 if (!connectable && !(hdev->le_states[2] & 0x02)) in is_advertising_allowed()
1001 if (connectable && (!(hdev->le_states[4] & 0x08) || in is_advertising_allowed()
1002 !(hdev->le_states[2] & 0x08))) in is_advertising_allowed()
1044 if (bacmp(&hdev->random_addr, BDADDR_ANY) && in hci_set_random_addr_sync()
1078 err = smp_generate_rpa(hdev, hdev->irk, &hdev->rpa); in hci_update_random_address_sync()
1084 err = hci_set_random_addr_sync(hdev, &hdev->rpa); in hci_update_random_address_sync()
1092 * use an non-resolvable private address. This is useful for active in hci_update_random_address_sync()
1093 * scanning and non-connectable advertising. in hci_update_random_address_sync()
1099 /* The non-resolvable private address is generated in hci_update_random_address_sync()
1106 /* The non-resolvable private address shall not be in hci_update_random_address_sync()
1109 if (bacmp(&hdev->bdaddr, &nrpa)) in hci_update_random_address_sync()
1123 * In case BR/EDR has been disabled on a dual-mode controller in hci_update_random_address_sync()
1128 !bacmp(&hdev->bdaddr, BDADDR_ANY) || in hci_update_random_address_sync()
1130 bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_update_random_address_sync()
1132 if (bacmp(&hdev->static_addr, &hdev->random_addr)) in hci_update_random_address_sync()
1134 &hdev->static_addr); in hci_update_random_address_sync()
1158 return -EINVAL; in hci_disable_ext_adv_instance_sync()
1161 if (!adv->enabled) in hci_disable_ext_adv_instance_sync()
1168 set = (void *)cp->data; in hci_disable_ext_adv_instance_sync()
1171 cp->num_of_sets = !!instance; in hci_disable_ext_adv_instance_sync()
1172 cp->enable = 0x00; in hci_disable_ext_adv_instance_sync()
1174 set->handle = adv ? adv->handle : instance; in hci_disable_ext_adv_instance_sync()
1176 size = sizeof(*cp) + sizeof(*set) * cp->num_of_sets; in hci_disable_ext_adv_instance_sync()
1190 * hdev->random_addr to track its address so whenever it needs in hci_set_adv_set_random_addr_sync()
1192 * hdev->random_addr is shared with scan state machine. in hci_set_adv_set_random_addr_sync()
1218 /* If command return a status event, skb will be set to -ENODATA */ in hci_set_ext_adv_params_sync()
1219 if (skb == ERR_PTR(-ENODATA)) in hci_set_ext_adv_params_sync()
1228 if (skb->len != sizeof(*rp)) { in hci_set_ext_adv_params_sync()
1230 HCI_OP_LE_SET_EXT_ADV_PARAMS, skb->len); in hci_set_ext_adv_params_sync()
1232 return -EIO; in hci_set_ext_adv_params_sync()
1235 memcpy(rp, skb->data, sizeof(*rp)); in hci_set_ext_adv_params_sync()
1238 if (!rp->status) { in hci_set_ext_adv_params_sync()
1239 hdev->adv_addr_type = cp->own_addr_type; in hci_set_ext_adv_params_sync()
1240 if (!cp->handle) { in hci_set_ext_adv_params_sync()
1242 hdev->adv_tx_power = rp->tx_power; in hci_set_ext_adv_params_sync()
1244 adv->tx_power = rp->tx_power; in hci_set_ext_adv_params_sync()
1248 return rp->status; in hci_set_ext_adv_params_sync()
1261 if (!adv || !adv->adv_data_changed) in hci_set_ext_adv_data_sync()
1265 len = eir_create_adv_data(hdev, instance, pdu->data, in hci_set_ext_adv_data_sync()
1268 pdu->length = len; in hci_set_ext_adv_data_sync()
1269 pdu->handle = adv ? adv->handle : instance; in hci_set_ext_adv_data_sync()
1270 pdu->operation = LE_SET_ADV_DATA_OP_COMPLETE; in hci_set_ext_adv_data_sync()
1271 pdu->frag_pref = LE_SET_ADV_DATA_NO_FRAG; in hci_set_ext_adv_data_sync()
1281 adv->adv_data_changed = false; in hci_set_ext_adv_data_sync()
1283 memcpy(hdev->adv_data, pdu->data, len); in hci_set_ext_adv_data_sync()
1284 hdev->adv_data_len = len; in hci_set_ext_adv_data_sync()
1300 if (hdev->adv_data_len == len && in hci_set_adv_data_sync()
1301 memcmp(cp.data, hdev->adv_data, len) == 0) in hci_set_adv_data_sync()
1304 memcpy(hdev->adv_data, cp.data, sizeof(cp.data)); in hci_set_adv_data_sync()
1305 hdev->adv_data_len = len; in hci_set_adv_data_sync()
1339 return -EINVAL; in hci_setup_ext_adv_instance_sync()
1357 * ADV_IND and ADV_NONCONN_IND based on the global connectable setting. in hci_setup_ext_adv_instance_sync()
1363 return -EPERM; in hci_setup_ext_adv_instance_sync()
1365 /* Set require_privacy to true only when non-connectable in hci_setup_ext_adv_instance_sync()
1367 * In that case it is fine to use a non-resolvable private address. in hci_setup_ext_adv_instance_sync()
1369 require_privacy = !connectable && !(adv && adv->periodic); in hci_setup_ext_adv_instance_sync()
1380 hci_cpu_to_le24(adv->min_interval, cp.min_interval); in hci_setup_ext_adv_instance_sync()
1381 hci_cpu_to_le24(adv->max_interval, cp.max_interval); in hci_setup_ext_adv_instance_sync()
1382 cp.tx_power = adv->tx_power; in hci_setup_ext_adv_instance_sync()
1383 cp.sid = adv->sid; in hci_setup_ext_adv_instance_sync()
1385 hci_cpu_to_le24(hdev->le_adv_min_interval, cp.min_interval); in hci_setup_ext_adv_instance_sync()
1386 hci_cpu_to_le24(hdev->le_adv_max_interval, cp.max_interval); in hci_setup_ext_adv_instance_sync()
1423 cp.channel_map = hdev->le_adv_channel_map; in hci_setup_ext_adv_instance_sync()
1424 cp.handle = adv ? adv->handle : instance; in hci_setup_ext_adv_instance_sync()
1452 if (!bacmp(&random_addr, &adv->random_addr)) in hci_setup_ext_adv_instance_sync()
1455 if (!bacmp(&random_addr, &hdev->random_addr)) in hci_setup_ext_adv_instance_sync()
1476 if (!adv || !adv->scan_rsp_changed) in hci_set_ext_scan_rsp_data_sync()
1480 len = eir_create_scan_rsp(hdev, instance, pdu->data); in hci_set_ext_scan_rsp_data_sync()
1482 pdu->handle = adv ? adv->handle : instance; in hci_set_ext_scan_rsp_data_sync()
1483 pdu->length = len; in hci_set_ext_scan_rsp_data_sync()
1484 pdu->operation = LE_SET_ADV_DATA_OP_COMPLETE; in hci_set_ext_scan_rsp_data_sync()
1485 pdu->frag_pref = LE_SET_ADV_DATA_NO_FRAG; in hci_set_ext_scan_rsp_data_sync()
1494 adv->scan_rsp_changed = false; in hci_set_ext_scan_rsp_data_sync()
1496 memcpy(hdev->scan_rsp_data, pdu->data, len); in hci_set_ext_scan_rsp_data_sync()
1497 hdev->scan_rsp_data_len = len; in hci_set_ext_scan_rsp_data_sync()
1512 if (hdev->scan_rsp_data_len == len && in __hci_set_scan_rsp_data_sync()
1513 !memcmp(cp.data, hdev->scan_rsp_data, len)) in __hci_set_scan_rsp_data_sync()
1516 memcpy(hdev->scan_rsp_data, cp.data, sizeof(cp.data)); in __hci_set_scan_rsp_data_sync()
1517 hdev->scan_rsp_data_len = len; in __hci_set_scan_rsp_data_sync()
1546 return -EINVAL; in hci_enable_ext_advertising_sync()
1548 if (adv->enabled) in hci_enable_ext_advertising_sync()
1555 set = (void *)cp->data; in hci_enable_ext_advertising_sync()
1559 cp->enable = 0x01; in hci_enable_ext_advertising_sync()
1560 cp->num_of_sets = 0x01; in hci_enable_ext_advertising_sync()
1564 set->handle = adv ? adv->handle : instance; in hci_enable_ext_advertising_sync()
1569 if (adv && adv->timeout) { in hci_enable_ext_advertising_sync()
1570 u16 duration = adv->timeout * MSEC_PER_SEC; in hci_enable_ext_advertising_sync()
1573 set->duration = cpu_to_le16(duration / 10); in hci_enable_ext_advertising_sync()
1578 sizeof(*set) * cp->num_of_sets, in hci_enable_ext_advertising_sync()
1604 if (!adv || !adv->periodic || !adv->enabled) in hci_disable_per_advertising_sync()
1647 if (!adv || !adv->periodic) in hci_set_per_adv_data_sync()
1651 len = eir_create_per_adv_data(hdev, instance, pdu->data); in hci_set_per_adv_data_sync()
1653 pdu->length = len; in hci_set_per_adv_data_sync()
1654 pdu->handle = adv ? adv->handle : instance; in hci_set_per_adv_data_sync()
1655 pdu->operation = LE_SET_ADV_DATA_OP_COMPLETE; in hci_set_per_adv_data_sync()
1669 if (adv && adv->periodic && adv->enabled) in hci_enable_per_advertising_sync()
1700 if (!eir_get_service_data(adv->per_adv_data, adv->per_adv_data_len, in hci_adv_bcast_annoucement()
1708 if (eir_get_service_data(adv->adv_data, adv->adv_data_len, 0x1852, in hci_adv_bcast_annoucement()
1715 memcpy(ad + len, adv->adv_data, adv->adv_data_len); in hci_adv_bcast_annoucement()
1716 hci_set_adv_instance_data(hdev, adv->instance, len + adv->adv_data_len, in hci_adv_bcast_annoucement()
1719 return hci_update_adv_data_sync(hdev, adv->instance); in hci_adv_bcast_annoucement()
1735 if (sid != HCI_SID_INVALID && adv->sid != sid) { in hci_start_per_adv_sync()
1743 return -EINVAL; in hci_start_per_adv_sync()
1748 adv->periodic = true; in hci_start_per_adv_sync()
1749 adv->per_adv_data_len = data_len; in hci_start_per_adv_sync()
1751 memcpy(adv->per_adv_data, data, data_len); in hci_start_per_adv_sync()
1752 adv->flags = flags; in hci_start_per_adv_sync()
1761 adv->pending = false; in hci_start_per_adv_sync()
1827 hdev->cur_adv_instance); in hci_enable_advertising_sync()
1829 flags = hci_adv_instance_flags(hdev, hdev->cur_adv_instance); in hci_enable_advertising_sync()
1830 adv_instance = hci_find_adv_instance(hdev, hdev->cur_adv_instance); in hci_enable_advertising_sync()
1833 * ADV_IND and ADV_NONCONN_IND based on the global connectable setting. in hci_enable_advertising_sync()
1839 return -EINVAL; in hci_enable_advertising_sync()
1847 * and write a new random address. The flag will be set back on in hci_enable_advertising_sync()
1852 /* Set require_privacy to true only when non-connectable in hci_enable_advertising_sync()
1854 * non-resolvable private address. in hci_enable_advertising_sync()
1865 adv_min_interval = adv_instance->min_interval; in hci_enable_advertising_sync()
1866 adv_max_interval = adv_instance->max_interval; in hci_enable_advertising_sync()
1868 adv_min_interval = hdev->le_adv_min_interval; in hci_enable_advertising_sync()
1869 adv_max_interval = hdev->le_adv_max_interval; in hci_enable_advertising_sync()
1875 if (hci_adv_instance_is_scannable(hdev, hdev->cur_adv_instance)) in hci_enable_advertising_sync()
1890 cp.channel_map = hdev->le_adv_channel_map; in hci_enable_advertising_sync()
1909 list_empty(&hdev->adv_instances)) in hci_enable_advertising()
1929 return -EINVAL; in hci_remove_ext_adv_instance_sync()
1955 return -EPERM; in hci_schedule_adv_instance_sync()
1957 if (hdev->adv_instance_timeout) in hci_schedule_adv_instance_sync()
1958 return -EBUSY; in hci_schedule_adv_instance_sync()
1962 return -ENOENT; in hci_schedule_adv_instance_sync()
1966 * in case further instances are being added later on. in hci_schedule_adv_instance_sync()
1972 if (adv->timeout == 0 || adv->duration <= adv->remaining_time) in hci_schedule_adv_instance_sync()
1973 timeout = adv->duration; in hci_schedule_adv_instance_sync()
1975 timeout = adv->remaining_time; in hci_schedule_adv_instance_sync()
1980 if (adv->timeout) in hci_schedule_adv_instance_sync()
1981 adv->remaining_time = adv->remaining_time - timeout; in hci_schedule_adv_instance_sync()
1985 hdev->adv_instance_timeout = timeout; in hci_schedule_adv_instance_sync()
1986 queue_delayed_work(hdev->req_workqueue, in hci_schedule_adv_instance_sync()
1987 &hdev->adv_instance_expire, in hci_schedule_adv_instance_sync()
1991 /* If we're just re-scheduling the same instance again then do not in hci_schedule_adv_instance_sync()
1995 if (!force && hdev->cur_adv_instance == instance && in hci_schedule_adv_instance_sync()
1999 hdev->cur_adv_instance = instance; in hci_schedule_adv_instance_sync()
2033 /* Cleanup non-ext instances */ in hci_clear_adv_sync()
2034 list_for_each_entry_safe(adv, n, &hdev->adv_instances, list) { in hci_clear_adv_sync()
2035 u8 instance = adv->instance; in hci_clear_adv_sync()
2038 if (!(force || adv->timeout)) in hci_clear_adv_sync()
2075 * - force == true: The instance will be removed even when its remaining
2077 * - force == false: the instance will be deactivated but kept stored unless
2081 * - force == true: All instances will be removed regardless of their timeout
2083 * - force == false: Only instances that have a timeout will be removed.
2092 if (!instance || hdev->cur_adv_instance == instance) in hci_remove_advertising_sync()
2099 if (hdev->cur_adv_instance == instance) in hci_remove_advertising_sync()
2109 if (force || (adv && adv->timeout && !adv->remaining_time)) { in hci_remove_advertising_sync()
2111 if (next && next->instance == instance) in hci_remove_advertising_sync()
2124 hci_schedule_adv_instance_sync(hdev, next->instance, false); in hci_remove_advertising_sync()
2227 if (hdev->scanning_paused) { in hci_scan_disable_sync()
2248 hdev->interleave_scan_state = INTERLEAVE_SCAN_NO_FILTER; in hci_start_interleave_scan()
2249 queue_delayed_work(hdev->req_workqueue, in hci_start_interleave_scan()
2250 &hdev->interleave_scan, 0); in hci_start_interleave_scan()
2257 cancel_delayed_work_sync(&hdev->interleave_scan); in cancel_interleave_scan()
2259 hdev->interleave_scan_state = INTERLEAVE_SCAN_NONE; in cancel_interleave_scan()
2268 * - There is at least one ADV monitor in hci_update_interleaved_scan_sync()
2269 * - At least one pending LE connection or one device to be scanned for in hci_update_interleaved_scan_sync()
2270 * - Monitor offloading is not supported in hci_update_interleaved_scan_sync()
2275 !(list_empty(&hdev->pend_le_conns) && in hci_update_interleaved_scan_sync()
2276 list_empty(&hdev->pend_le_reports)) && in hci_update_interleaved_scan_sync()
2304 entry = hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, bdaddr, in hci_le_del_resolve_list_sync()
2322 /* Check if device is on accept list before removing it */ in hci_le_del_accept_list_sync()
2323 if (!hci_bdaddr_list_lookup(&hdev->le_accept_list, bdaddr, bdaddr_type)) in hci_le_del_accept_list_sync()
2355 * Setting params to NULL programs local hdev->irk
2376 memcpy(cp.peer_irk, hdev->irk, 16); in hci_le_add_resolve_list_sync()
2378 } else if (!(params->flags & HCI_CONN_FLAG_ADDRESS_RESOLUTION)) in hci_le_add_resolve_list_sync()
2381 irk = hci_find_irk_by_addr(hdev, &params->addr, params->addr_type); in hci_le_add_resolve_list_sync()
2386 entry = hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, in hci_le_add_resolve_list_sync()
2387 &params->addr, in hci_le_add_resolve_list_sync()
2388 params->addr_type); in hci_le_add_resolve_list_sync()
2392 cp.bdaddr_type = params->addr_type; in hci_le_add_resolve_list_sync()
2393 bacpy(&cp.bdaddr, &params->addr); in hci_le_add_resolve_list_sync()
2394 memcpy(cp.peer_irk, irk->val, 16); in hci_le_add_resolve_list_sync()
2397 params->privacy_mode = HCI_NETWORK_PRIVACY; in hci_le_add_resolve_list_sync()
2400 p = hci_pend_le_action_lookup(&hdev->pend_le_conns, in hci_le_add_resolve_list_sync()
2401 &params->addr, params->addr_type); in hci_le_add_resolve_list_sync()
2403 p = hci_pend_le_action_lookup(&hdev->pend_le_reports, in hci_le_add_resolve_list_sync()
2404 &params->addr, params->addr_type); in hci_le_add_resolve_list_sync()
2406 WRITE_ONCE(p->privacy_mode, HCI_NETWORK_PRIVACY); in hci_le_add_resolve_list_sync()
2411 memcpy(cp.local_irk, hdev->irk, 16); in hci_le_add_resolve_list_sync()
2427 !(params->flags & HCI_CONN_FLAG_ADDRESS_RESOLUTION)) in hci_le_set_privacy_mode_sync()
2431 if (params->privacy_mode == HCI_DEVICE_PRIVACY) in hci_le_set_privacy_mode_sync()
2438 if (!(params->flags & HCI_CONN_FLAG_DEVICE_PRIVACY)) in hci_le_set_privacy_mode_sync()
2441 irk = hci_find_irk_by_addr(hdev, &params->addr, params->addr_type); in hci_le_set_privacy_mode_sync()
2446 cp.bdaddr_type = irk->addr_type; in hci_le_set_privacy_mode_sync()
2447 bacpy(&cp.bdaddr, &irk->bdaddr); in hci_le_set_privacy_mode_sync()
2450 /* Note: params->privacy_mode is not updated since it is a copy */ in hci_le_set_privacy_mode_sync()
2468 if (hdev->suspended && in hci_le_add_accept_list_sync()
2469 !(params->flags & HCI_CONN_FLAG_REMOTE_WAKEUP)) { in hci_le_add_accept_list_sync()
2470 hci_le_del_accept_list_sync(hdev, &params->addr, in hci_le_add_accept_list_sync()
2471 params->addr_type); in hci_le_add_accept_list_sync()
2476 if (*num_entries >= hdev->le_accept_list_size) in hci_le_add_accept_list_sync()
2477 return -ENOSPC; in hci_le_add_accept_list_sync()
2497 if (hci_bdaddr_list_lookup(&hdev->le_accept_list, &params->addr, in hci_le_add_accept_list_sync()
2498 params->addr_type)) in hci_le_add_accept_list_sync()
2502 cp.bdaddr_type = params->addr_type; in hci_le_add_accept_list_sync()
2503 bacpy(&cp.bdaddr, &params->addr); in hci_le_add_accept_list_sync()
2531 if (hdev->advertising_paused) in hci_pause_advertising_sync()
2546 hdev->discov_timeout = 0; in hci_pause_advertising_sync()
2551 /* Call to disable any advertisements active on the controller. in hci_pause_advertising_sync()
2562 hdev->advertising_paused = true; in hci_pause_advertising_sync()
2563 hdev->advertising_old_state = old_state; in hci_pause_advertising_sync()
2575 if (!hdev->advertising_paused) in hci_resume_advertising_sync()
2579 hdev->advertising_paused = false; in hci_resume_advertising_sync()
2580 if (hdev->advertising_old_state) { in hci_resume_advertising_sync()
2582 hdev->advertising_old_state = 0; in hci_resume_advertising_sync()
2588 /* Call for each tracked instance to be re-enabled */ in hci_resume_advertising_sync()
2589 list_for_each_entry_safe(adv, tmp, &hdev->adv_instances, list) { in hci_resume_advertising_sync()
2591 adv->instance); in hci_resume_advertising_sync()
2596 hci_remove_ext_adv_instance_sync(hdev, adv->instance, in hci_resume_advertising_sync()
2601 * then we need to re-enable it. in hci_resume_advertising_sync()
2603 if (!hdev->cur_adv_instance) in hci_resume_advertising_sync()
2605 hdev->cur_adv_instance); in hci_resume_advertising_sync()
2611 hdev->cur_adv_instance, in hci_resume_advertising_sync()
2615 hdev->advertising_paused = false; in hci_resume_advertising_sync()
2636 return -EPERM; in hci_pause_addr_resolution()
2695 /* No hdev->lock, but: addr, addr_type are immutable. in conn_params_copy()
2701 bacpy(&p[i].addr, &params->addr); in conn_params_copy()
2702 p[i].addr_type = params->addr_type; in conn_params_copy()
2703 p[i].flags = READ_ONCE(params->flags); in conn_params_copy()
2704 p[i].privacy_mode = READ_ONCE(params->privacy_mode); in conn_params_copy()
2717 if (!(hdev->commands[26] & 0x80)) in hci_le_clear_accept_list_sync()
2728 * ll_privacy_capable((Disable Advertising) -> Disable Resolving List) ->
2729 * Remove Devices From Accept List ->
2730 * (has IRK && ll_privacy_capable(Remove Devices From Resolving List))->
2731 * Add Devices to Accept List ->
2732 * (has IRK && ll_privacy_capable(Remove Devices From Resolving List)) ->
2733 * ll_privacy_capable(Enable Resolving List -> (Enable Advertising)) ->
2782 bacpy(&pa.addr, &conn->dst); in hci_update_accept_list_sync()
2783 pa.addr_type = conn->dst_type; in hci_update_accept_list_sync()
2803 list_for_each_entry_safe(b, t, &hdev->le_accept_list, list) { in hci_update_accept_list_sync()
2804 if (hci_conn_hash_lookup_le(hdev, &b->bdaddr, b->bdaddr_type)) in hci_update_accept_list_sync()
2808 pend_conn = hci_pend_le_action_lookup(&hdev->pend_le_conns, in hci_update_accept_list_sync()
2809 &b->bdaddr, in hci_update_accept_list_sync()
2810 b->bdaddr_type); in hci_update_accept_list_sync()
2811 pend_report = hci_pend_le_action_lookup(&hdev->pend_le_reports, in hci_update_accept_list_sync()
2812 &b->bdaddr, in hci_update_accept_list_sync()
2813 b->bdaddr_type); in hci_update_accept_list_sync()
2819 hci_le_del_accept_list_sync(hdev, &b->bdaddr, in hci_update_accept_list_sync()
2820 b->bdaddr_type); in hci_update_accept_list_sync()
2834 * just abort and return filer policy value to not use the in hci_update_accept_list_sync()
2841 params = conn_params_copy(&hdev->pend_le_conns, &n); in hci_update_accept_list_sync()
2843 err = -ENOMEM; in hci_update_accept_list_sync()
2863 params = conn_params_copy(&hdev->pend_le_reports, &n); in hci_update_accept_list_sync()
2865 err = -ENOMEM; in hci_update_accept_list_sync()
2881 * - We are not currently suspending in hci_update_accept_list_sync()
2882 * - There are 1 or more ADV monitors registered and it's not offloaded in hci_update_accept_list_sync()
2883 * - Interleaved scanning is not currently using the allowlist in hci_update_accept_list_sync()
2885 if (!idr_is_empty(&hdev->adv_monitors_idr) && !hdev->suspended && in hci_update_accept_list_sync()
2887 hdev->interleave_scan_state != INTERLEAVE_SCAN_ALLOWLIST) in hci_update_accept_list_sync()
2888 err = -EINVAL; in hci_update_accept_list_sync()
2909 cp->type = type; in hci_le_scan_phy_params()
2910 cp->interval = cpu_to_le16(interval); in hci_le_scan_phy_params()
2911 cp->window = cpu_to_le16(window); in hci_le_scan_phy_params()
2924 phy = (void *)cp->data; in hci_le_set_ext_scan_param_sync()
2928 cp->own_addr_type = own_addr_type; in hci_le_set_ext_scan_param_sync()
2929 cp->filter_policy = filter_policy; in hci_le_set_ext_scan_param_sync()
2931 /* Check if PA Sync is in progress then select the PHY based on the in hci_le_set_ext_scan_param_sync()
2942 &sent->bdaddr); in hci_le_set_ext_scan_param_sync()
2944 struct bt_iso_qos *qos = &conn->iso_qos; in hci_le_set_ext_scan_param_sync()
2946 if (qos->bcast.in.phy & BT_ISO_PHY_1M || in hci_le_set_ext_scan_param_sync()
2947 qos->bcast.in.phy & BT_ISO_PHY_2M) { in hci_le_set_ext_scan_param_sync()
2948 cp->scanning_phys |= LE_SCAN_PHY_1M; in hci_le_set_ext_scan_param_sync()
2956 if (qos->bcast.in.phy & BT_ISO_PHY_CODED) { in hci_le_set_ext_scan_param_sync()
2957 cp->scanning_phys |= LE_SCAN_PHY_CODED; in hci_le_set_ext_scan_param_sync()
2972 cp->scanning_phys |= LE_SCAN_PHY_1M; in hci_le_set_ext_scan_param_sync()
2979 cp->scanning_phys |= LE_SCAN_PHY_CODED; in hci_le_set_ext_scan_param_sync()
2987 return -EINVAL; in hci_le_set_ext_scan_param_sync()
3022 if (hdev->scanning_paused) { in hci_start_scan_sync()
3043 if (hdev->scanning_paused) { in hci_passive_scan_sync()
3055 * during passive scanning. Not using an non-resolvable address in hci_passive_scan_sync()
3064 if (hdev->enable_advmon_interleave_scan && in hci_passive_scan_sync()
3068 bt_dev_dbg(hdev, "interleave state %d", hdev->interleave_scan_state); in hci_passive_scan_sync()
3080 if (hdev->suspended && !filter_policy) { in hci_passive_scan_sync()
3084 if (list_empty(&hdev->le_accept_list)) in hci_passive_scan_sync()
3088 * devices could not be programmed which in non-suspended case in hci_passive_scan_sync()
3107 (hdev->le_features[0] & HCI_LE_EXT_SCAN_POLICY)) in hci_passive_scan_sync()
3110 if (hdev->suspended) { in hci_passive_scan_sync()
3111 window = hdev->le_scan_window_suspend; in hci_passive_scan_sync()
3112 interval = hdev->le_scan_int_suspend; in hci_passive_scan_sync()
3114 window = hdev->le_scan_window_connect; in hci_passive_scan_sync()
3115 interval = hdev->le_scan_int_connect; in hci_passive_scan_sync()
3117 window = hdev->le_scan_window_adv_monitor; in hci_passive_scan_sync()
3118 interval = hdev->le_scan_int_adv_monitor; in hci_passive_scan_sync()
3134 window = hdev->le_scan_window; in hci_passive_scan_sync()
3135 interval = hdev->le_scan_interval; in hci_passive_scan_sync()
3150 /* This function controls the passive scanning based on hdev->pend_le_conns
3156 * Disable Scanning -> Update Accept List ->
3157 * ll_privacy_capable((Disable Advertising) -> Disable Resolving List ->
3158 * Update Resolving List -> Enable Resolving List -> (Enable Advertising)) ->
3169 if (!test_bit(HCI_UP, &hdev->flags) || in hci_update_passive_scan_sync()
3170 test_bit(HCI_INIT, &hdev->flags) || in hci_update_passive_scan_sync()
3182 if (hdev->discovery.state != DISCOVERY_STOPPED) in hci_update_passive_scan_sync()
3195 hci_is_adv_monitoring(hdev) ? "on" : "off"); in hci_update_passive_scan_sync()
3198 list_empty(&hdev->pend_le_conns) && in hci_update_passive_scan_sync()
3199 list_empty(&hdev->pend_le_reports) && in hci_update_passive_scan_sync()
3254 if (!test_bit(HCI_UP, &hdev->flags) || in hci_update_passive_scan()
3255 test_bit(HCI_INIT, &hdev->flags) || in hci_update_passive_scan()
3278 hdev->features[1][0] |= LMP_HOST_SC; in hci_write_sc_support_sync()
3281 hdev->features[1][0] &= ~LMP_HOST_SC; in hci_write_sc_support_sync()
3357 list_empty(&hdev->adv_instances)) { in hci_powered_update_adv_sync()
3373 list_for_each_entry_safe(adv, tmp, &hdev->adv_instances, list) in hci_powered_update_adv_sync()
3374 hci_schedule_adv_instance_sync(hdev, adv->instance, true); in hci_powered_update_adv_sync()
3384 if (link_sec == test_bit(HCI_AUTH, &hdev->flags)) in hci_write_auth_enable_sync()
3401 if (hdev->hci_ver < BLUETOOTH_VER_1_2) in hci_write_fast_connectable_sync()
3412 type = hdev->def_page_scan_type; in hci_write_fast_connectable_sync()
3413 cp.interval = cpu_to_le16(hdev->def_page_scan_int); in hci_write_fast_connectable_sync()
3416 cp.window = cpu_to_le16(hdev->def_page_scan_window); in hci_write_fast_connectable_sync()
3418 if (__cpu_to_le16(hdev->page_scan_interval) != cp.interval || in hci_write_fast_connectable_sync()
3419 __cpu_to_le16(hdev->page_scan_window) != cp.window) { in hci_write_fast_connectable_sync()
3427 if (hdev->page_scan_type != type) in hci_write_fast_connectable_sync()
3440 list_for_each_entry(b, &hdev->accept_list, list) { in disconnected_accept_list_entries()
3443 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &b->bdaddr); in disconnected_accept_list_entries()
3447 if (conn->state != BT_CONNECTED && conn->state != BT_CONFIG) in disconnected_accept_list_entries()
3474 if (hdev->scanning_paused) in hci_update_scan_sync()
3486 if (test_bit(HCI_PSCAN, &hdev->flags) == !!(scan & SCAN_PAGE) && in hci_update_scan_sync()
3487 test_bit(HCI_ISCAN, &hdev->flags) == !!(scan & SCAN_INQUIRY)) in hci_update_scan_sync()
3511 * HCI_LE_ENABLED(ll_privacy_capable(Add local IRK to Resolving List) ->
3514 * lmp_bredr_capable(Set Fast Connectable -> Set Scan Type -> Set Class ->
3515 * Set Name -> Set EIR)
3523 * successfully powering on the controller. This late in hci_powered_update_sync()
3552 hci_update_name_sync(hdev, hdev->dev_name); in hci_powered_update_sync()
3561 * In case BR/EDR has been disabled on a dual-mode controller in hci_powered_update_sync()
3566 (!bacmp(&hdev->bdaddr, BDADDR_ANY) && in hci_powered_update_sync()
3568 if (bacmp(&hdev->static_addr, BDADDR_ANY)) in hci_powered_update_sync()
3570 &hdev->static_addr); in hci_powered_update_sync()
3577 * hci_dev_get_bd_addr_from_property - Get the Bluetooth Device Address
3582 * Search the firmware node for 'local-bd-address'.
3584 * All-zero BD addresses are rejected, because those could be properties
3586 * example, the DTS could define 'local-bd-address', with zero BD addresses.
3590 struct fwnode_handle *fwnode = dev_fwnode(hdev->dev.parent); in hci_dev_get_bd_addr_from_property()
3594 ret = fwnode_property_read_u8_array(fwnode, "local-bd-address", in hci_dev_get_bd_addr_from_property()
3600 baswap(&hdev->public_addr, &ba); in hci_dev_get_bd_addr_from_property()
3602 bacpy(&hdev->public_addr, &ba); in hci_dev_get_bd_addr_from_property()
3657 set_bit(HCI_RESET, &hdev->flags); in hci_reset_sync()
3729 if (hdev->hci_ver > BLUETOOTH_VER_1_1 && in hci_read_local_cmds_sync()
3857 if (!lmp_sco_capable(hdev) || !(hdev->commands[10] & BIT(4)) || in hci_write_sync_flowctl_sync()
3908 hdev->max_page = 0x01; in hci_write_ssp_mode_1_sync()
3921 memset(hdev->eir, 0, sizeof(hdev->eir)); in hci_write_eir_sync()
3997 if (iso_capable(hdev) && hdev->commands[41] & 0x20) in hci_le_read_buffer_size_sync()
4053 /* LE-only controllers have LE implicitly enabled */ in hci_init2_sync()
4072 if (hdev->hci_ver < BLUETOOTH_VER_1_2) in hci_set_event_mask_sync()
4082 if (hdev->suspended) { in hci_set_event_mask_sync()
4087 /* Use a different default for LE-only devices */ in hci_set_event_mask_sync()
4097 if (hdev->commands[0] & 0x20) { in hci_set_event_mask_sync()
4102 if (!hdev->suspended) in hci_set_event_mask_sync()
4111 if (hdev->commands[2] & 0x80) in hci_set_event_mask_sync()
4116 if (hdev->le_features[0] & HCI_LE_ENCRYPTION) { in hci_set_event_mask_sync()
4164 events[7] |= 0x20; /* LE Meta-Event */ in hci_set_event_mask_sync()
4174 if (!(hdev->commands[6] & 0x20) || in hci_read_stored_link_key_sync()
4191 if (!(hdev->commands[5] & 0x10)) in hci_setup_link_policy_sync()
4213 if (!(hdev->commands[8] & 0x01)) in hci_read_page_scan_activity_sync()
4222 if (!(hdev->commands[18] & 0x04) || in hci_read_def_err_data_reporting_sync()
4223 !(hdev->features[0][6] & LMP_ERR_DATA_REPORTING) || in hci_read_def_err_data_reporting_sync()
4237 if (!(hdev->commands[13] & 0x01) || in hci_read_page_scan_type_sync()
4254 for (page = 2; page < HCI_MAX_PAGES && page <= hdev->max_page; in hci_read_local_ext_features_all_sync()
4292 if (hdev->le_features[0] & HCI_LE_ENCRYPTION) in hci_le_set_event_mask_sync()
4298 if (hdev->le_features[0] & HCI_LE_CONN_PARAM_REQ_PROC) in hci_le_set_event_mask_sync()
4305 if (hdev->le_features[0] & HCI_LE_DATA_LEN_EXT) in hci_le_set_event_mask_sync()
4316 hdev->conn_flags |= HCI_CONN_FLAG_DEVICE_PRIVACY; in hci_le_set_event_mask_sync()
4320 hdev->conn_flags |= HCI_CONN_FLAG_ADDRESS_RESOLUTION; in hci_le_set_event_mask_sync()
4325 if (hdev->le_features[0] & HCI_LE_EXT_SCAN_POLICY) in hci_le_set_event_mask_sync()
4331 if (hdev->le_features[1] & HCI_LE_CHAN_SEL_ALG2) in hci_le_set_event_mask_sync()
4337 if (hdev->commands[26] & 0x08) in hci_le_set_event_mask_sync()
4343 if (hdev->commands[26] & 0x10) in hci_le_set_event_mask_sync()
4349 if (hdev->commands[27] & 0x04) in hci_le_set_event_mask_sync()
4355 if (hdev->commands[27] & 0x20) in hci_le_set_event_mask_sync()
4359 /* If the controller supports the LE Read Local P-256 in hci_le_set_event_mask_sync()
4362 if (hdev->commands[34] & 0x02) in hci_le_set_event_mask_sync()
4363 /* LE Read Local P-256 Public Key Complete */ in hci_le_set_event_mask_sync()
4369 if (hdev->commands[34] & 0x04) in hci_le_set_event_mask_sync()
4375 if (hdev->commands[35] & (0x20 | 0x40)) in hci_le_set_event_mask_sync()
4414 if ((hdev->commands[25] & 0x40) && !ext_adv_capable(hdev)) { in hci_le_read_adv_tx_power_sync()
4432 if (!(hdev->commands[38] & 0x80) || in hci_le_read_tx_power_sync()
4443 if (!(hdev->commands[26] & 0x40)) in hci_le_read_accept_list_size_sync()
4453 if (!(hdev->commands[34] & 0x40)) in hci_le_read_resolv_list_size_sync()
4463 if (!(hdev->commands[34] & 0x20)) in hci_le_clear_resolv_list_sync()
4473 __le16 timeout = cpu_to_le16(hdev->rpa_timeout); in hci_le_set_rpa_timeout_sync()
4475 if (!(hdev->commands[35] & 0x04) || in hci_le_set_rpa_timeout_sync()
4487 if (!(hdev->le_features[0] & HCI_LE_DATA_LEN_EXT)) in hci_le_read_max_data_len_sync()
4497 if (!(hdev->le_features[0] & HCI_LE_DATA_LEN_EXT)) in hci_le_read_def_data_len_sync()
4520 /* LE-only devices do not support explicit enablement */ in hci_set_le_support_sync()
4620 if (!(hdev->commands[6] & 0x80) || in hci_delete_stored_link_key_sync()
4638 if (!(hdev->commands[22] & 0x04)) in hci_set_event_mask_page_2_sync()
4664 if (lmp_ping_capable(hdev) || hdev->le_features[0] & HCI_LE_PING) { in hci_set_event_mask_page_2_sync()
4685 if (hdev->commands[45] & 0x04) in hci_read_local_codecs_sync()
4687 else if (hdev->commands[29] & 0x20) in hci_read_local_codecs_sync()
4696 if (!(hdev->commands[41] & 0x08)) in hci_read_local_pairing_opts_sync()
4745 if (!(hdev->commands[18] & 0x08) || in hci_set_err_data_report_sync()
4746 !(hdev->features[0][6] & LMP_ERR_DATA_REPORTING) || in hci_set_err_data_report_sync()
4750 if (enabled == hdev->err_data_reporting) in hci_set_err_data_report_sync()
4786 if (!(hdev->le_features[0] & HCI_LE_DATA_LEN_EXT)) in hci_le_set_write_def_data_len_sync()
4790 cp.tx_len = cpu_to_le16(hdev->le_max_tx_len); in hci_le_set_write_def_data_len_sync()
4791 cp.tx_time = cpu_to_le16(hdev->le_max_tx_time); in hci_le_set_write_def_data_len_sync()
4804 if (!(hdev->commands[35] & 0x20)) { in hci_le_set_default_phy_sync()
4808 hdev->le_tx_def_phys = HCI_LE_SET_PHY_1M; in hci_le_set_default_phy_sync()
4809 hdev->le_rx_def_phys = HCI_LE_SET_PHY_1M; in hci_le_set_default_phy_sync()
4950 * Calls hdev->setup
4967 if (hdev->setup) in hci_dev_setup_sync()
4968 ret = hdev->setup(hdev); in hci_dev_setup_sync()
4983 !bacmp(&hdev->public_addr, BDADDR_ANY)) in hci_dev_setup_sync()
4986 if (invalid_bdaddr && bacmp(&hdev->public_addr, BDADDR_ANY) && in hci_dev_setup_sync()
4987 hdev->set_bdaddr) { in hci_dev_setup_sync()
4988 ret = hdev->set_bdaddr(hdev, &hdev->public_addr); in hci_dev_setup_sync()
5033 atomic_set(&hdev->cmd_cnt, 1); in hci_dev_init_sync()
5034 set_bit(HCI_INIT, &hdev->flags); in hci_dev_init_sync()
5042 * on procedure. in hci_dev_init_sync()
5044 if (bacmp(&hdev->public_addr, BDADDR_ANY) && in hci_dev_init_sync()
5045 hdev->set_bdaddr) in hci_dev_init_sync()
5046 ret = hdev->set_bdaddr(hdev, &hdev->public_addr); in hci_dev_init_sync()
5048 ret = -EADDRNOTAVAIL; in hci_dev_init_sync()
5055 if (!ret && hdev->post_init) in hci_dev_init_sync()
5056 ret = hdev->post_init(hdev); in hci_dev_init_sync()
5066 hci_dev_test_flag(hdev, HCI_VENDOR_DIAG) && hdev->set_diag) in hci_dev_init_sync()
5067 ret = hdev->set_diag(hdev, true); in hci_dev_init_sync()
5074 clear_bit(HCI_INIT, &hdev->flags); in hci_dev_init_sync()
5086 ret = -ENODEV; in hci_dev_open_sync()
5096 ret = -ERFKILL; in hci_dev_open_sync()
5110 !bacmp(&hdev->bdaddr, BDADDR_ANY) && in hci_dev_open_sync()
5111 !bacmp(&hdev->static_addr, BDADDR_ANY)) { in hci_dev_open_sync()
5112 ret = -EADDRNOTAVAIL; in hci_dev_open_sync()
5117 if (test_bit(HCI_UP, &hdev->flags)) { in hci_dev_open_sync()
5118 ret = -EALREADY; in hci_dev_open_sync()
5122 if (hdev->open(hdev)) { in hci_dev_open_sync()
5123 ret = -EIO; in hci_dev_open_sync()
5129 set_bit(HCI_RUNNING, &hdev->flags); in hci_dev_open_sync()
5137 set_bit(HCI_UP, &hdev->flags); in hci_dev_open_sync()
5150 flush_work(&hdev->tx_work); in hci_dev_open_sync()
5156 flush_work(&hdev->rx_work); in hci_dev_open_sync()
5157 flush_work(&hdev->cmd_work); in hci_dev_open_sync()
5159 skb_queue_purge(&hdev->cmd_q); in hci_dev_open_sync()
5160 skb_queue_purge(&hdev->rx_q); in hci_dev_open_sync()
5162 if (hdev->flush) in hci_dev_open_sync()
5163 hdev->flush(hdev); in hci_dev_open_sync()
5165 if (hdev->sent_cmd) { in hci_dev_open_sync()
5166 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_dev_open_sync()
5167 kfree_skb(hdev->sent_cmd); in hci_dev_open_sync()
5168 hdev->sent_cmd = NULL; in hci_dev_open_sync()
5171 if (hdev->req_skb) { in hci_dev_open_sync()
5172 kfree_skb(hdev->req_skb); in hci_dev_open_sync()
5173 hdev->req_skb = NULL; in hci_dev_open_sync()
5176 clear_bit(HCI_RUNNING, &hdev->flags); in hci_dev_open_sync()
5179 hdev->close(hdev); in hci_dev_open_sync()
5180 hdev->flags &= BIT(HCI_RAW); in hci_dev_open_sync()
5187 /* This function requires the caller holds hdev->lock */
5192 list_for_each_entry(p, &hdev->le_conn_params, list) { in hci_pend_le_actions_clear()
5194 if (p->conn) { in hci_pend_le_actions_clear()
5195 hci_conn_drop(p->conn); in hci_pend_le_actions_clear()
5196 hci_conn_put(p->conn); in hci_pend_le_actions_clear()
5197 p->conn = NULL; in hci_pend_le_actions_clear()
5217 test_bit(HCI_UP, &hdev->flags)) { in hci_dev_shutdown()
5219 if (hdev->shutdown) in hci_dev_shutdown()
5220 err = hdev->shutdown(hdev); in hci_dev_shutdown()
5237 disable_delayed_work(&hdev->power_off); in hci_dev_close_sync()
5238 disable_delayed_work(&hdev->ncmd_timer); in hci_dev_close_sync()
5239 disable_delayed_work(&hdev->le_scan_disable); in hci_dev_close_sync()
5241 cancel_delayed_work(&hdev->power_off); in hci_dev_close_sync()
5242 cancel_delayed_work(&hdev->ncmd_timer); in hci_dev_close_sync()
5243 cancel_delayed_work(&hdev->le_scan_disable); in hci_dev_close_sync()
5250 if (hdev->adv_instance_timeout) { in hci_dev_close_sync()
5251 cancel_delayed_work_sync(&hdev->adv_instance_expire); in hci_dev_close_sync()
5252 hdev->adv_instance_timeout = 0; in hci_dev_close_sync()
5257 if (!test_and_clear_bit(HCI_UP, &hdev->flags)) { in hci_dev_close_sync()
5258 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_dev_close_sync()
5265 flush_work(&hdev->tx_work); in hci_dev_close_sync()
5266 flush_work(&hdev->rx_work); in hci_dev_close_sync()
5268 if (hdev->discov_timeout > 0) { in hci_dev_close_sync()
5269 hdev->discov_timeout = 0; in hci_dev_close_sync()
5275 cancel_delayed_work(&hdev->service_cache); in hci_dev_close_sync()
5280 cancel_delayed_work_sync(&hdev->rpa_expired); in hci_dev_close_sync()
5282 list_for_each_entry(adv_instance, &hdev->adv_instances, list) in hci_dev_close_sync()
5283 cancel_delayed_work_sync(&adv_instance->rpa_expired_cb); in hci_dev_close_sync()
5289 drain_workqueue(hdev->workqueue); in hci_dev_close_sync()
5304 /* Prevent data races on hdev->smp_data or hdev->smp_bredr_data */ in hci_dev_close_sync()
5315 if (hdev->flush) in hci_dev_close_sync()
5316 hdev->flush(hdev); in hci_dev_close_sync()
5319 skb_queue_purge(&hdev->cmd_q); in hci_dev_close_sync()
5320 atomic_set(&hdev->cmd_cnt, 1); in hci_dev_close_sync()
5323 set_bit(HCI_INIT, &hdev->flags); in hci_dev_close_sync()
5325 clear_bit(HCI_INIT, &hdev->flags); in hci_dev_close_sync()
5329 flush_work(&hdev->cmd_work); in hci_dev_close_sync()
5332 skb_queue_purge(&hdev->rx_q); in hci_dev_close_sync()
5333 skb_queue_purge(&hdev->cmd_q); in hci_dev_close_sync()
5334 skb_queue_purge(&hdev->raw_q); in hci_dev_close_sync()
5337 if (hdev->sent_cmd) { in hci_dev_close_sync()
5338 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_dev_close_sync()
5339 kfree_skb(hdev->sent_cmd); in hci_dev_close_sync()
5340 hdev->sent_cmd = NULL; in hci_dev_close_sync()
5344 if (hdev->req_skb) { in hci_dev_close_sync()
5345 kfree_skb(hdev->req_skb); in hci_dev_close_sync()
5346 hdev->req_skb = NULL; in hci_dev_close_sync()
5349 clear_bit(HCI_RUNNING, &hdev->flags); in hci_dev_close_sync()
5353 hdev->close(hdev); in hci_dev_close_sync()
5356 hdev->flags &= BIT(HCI_RAW); in hci_dev_close_sync()
5359 memset(hdev->eir, 0, sizeof(hdev->eir)); in hci_dev_close_sync()
5360 memset(hdev->dev_class, 0, sizeof(hdev->dev_class)); in hci_dev_close_sync()
5361 bacpy(&hdev->random_addr, BDADDR_ANY); in hci_dev_close_sync()
5362 hci_codec_list_clear(&hdev->local_codecs); in hci_dev_close_sync()
5368 /* This function perform power on HCI command sequence as follows:
5378 if (test_bit(HCI_UP, &hdev->flags) && in hci_power_on_sync()
5381 cancel_delayed_work(&hdev->power_off); in hci_power_on_sync()
5395 (!bacmp(&hdev->bdaddr, BDADDR_ANY) && in hci_power_on_sync()
5396 !bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_power_on_sync()
5400 queue_delayed_work(hdev->req_workqueue, &hdev->power_off, in hci_power_on_sync()
5409 set_bit(HCI_RAW, &hdev->flags); in hci_power_on_sync()
5424 clear_bit(HCI_RAW, &hdev->flags); in hci_power_on_sync()
5426 /* Powering on the controller with HCI_CONFIG set only in hci_power_on_sync()
5449 struct discovery_state *d = &hdev->discovery; in hci_stop_discovery_sync()
5453 bt_dev_dbg(hdev, "state %u", hdev->discovery.state); in hci_stop_discovery_sync()
5455 if (d->state == DISCOVERY_FINDING || d->state == DISCOVERY_STOPPING) { in hci_stop_discovery_sync()
5456 if (test_bit(HCI_INQUIRY, &hdev->flags)) { in hci_stop_discovery_sync()
5464 cancel_delayed_work(&hdev->le_scan_disable); in hci_stop_discovery_sync()
5481 /* No further actions needed for LE-only discovery */ in hci_stop_discovery_sync()
5482 if (d->type == DISCOV_TYPE_LE) in hci_stop_discovery_sync()
5485 if (d->state == DISCOVERY_RESOLVING || d->state == DISCOVERY_STOPPING) { in hci_stop_discovery_sync()
5494 hci_remote_name_cancel_sync(hdev, &e->data.bdaddr); in hci_stop_discovery_sync()
5505 if (conn->type == BIS_LINK || conn->type == PA_LINK) { in hci_disconnect_sync()
5517 cp.handle = cpu_to_le16(conn->handle); in hci_disconnect_sync()
5541 if (test_bit(HCI_CONN_SCANNING, &conn->flags)) in hci_le_connect_cancel_sync()
5544 if (conn->role == HCI_ROLE_SLAVE || in hci_le_connect_cancel_sync()
5545 test_and_set_bit(HCI_CONN_CANCEL, &conn->flags)) in hci_le_connect_cancel_sync()
5555 if (conn->type == LE_LINK) in hci_connect_cancel_sync()
5558 if (conn->type == CIS_LINK) { in hci_connect_cancel_sync()
5562 * If this command is issued for a CIS on the Central and the in hci_connect_cancel_sync()
5567 if (test_bit(HCI_CONN_CREATE_CIS, &conn->flags)) in hci_connect_cancel_sync()
5574 if (conn->type == BIS_LINK || conn->type == PA_LINK) { in hci_connect_cancel_sync()
5576 * which is done later on connection cleanup. in hci_connect_cancel_sync()
5581 if (hdev->hci_ver < BLUETOOTH_VER_1_2) in hci_connect_cancel_sync()
5591 6, &conn->dst, in hci_connect_cancel_sync()
5596 6, &conn->dst, HCI_CMD_TIMEOUT); in hci_connect_cancel_sync()
5605 bacpy(&cp.bdaddr, &conn->dst); in hci_reject_sco_sync()
5609 * allowed error values (0x0D-0x0F). in hci_reject_sco_sync()
5624 cp.handle = cpu_to_le16(conn->handle); in hci_le_reject_cis_sync()
5636 if (conn->type == CIS_LINK) in hci_reject_conn_sync()
5639 if (conn->type == BIS_LINK || conn->type == PA_LINK) in hci_reject_conn_sync()
5640 return -EINVAL; in hci_reject_conn_sync()
5642 if (conn->type == SCO_LINK || conn->type == ESCO_LINK) in hci_reject_conn_sync()
5646 bacpy(&cp.bdaddr, &conn->dst); in hci_reject_conn_sync()
5656 u16 handle = conn->handle; in hci_abort_conn_sync()
5660 switch (conn->state) { in hci_abort_conn_sync()
5694 conn->state = BT_CLOSED; in hci_abort_conn_sync()
5708 struct list_head *head = &hdev->conn_hash.list; in hci_disconnect_all_sync()
5742 if (!test_bit(HCI_UP, &hdev->flags)) in hci_power_off_sync()
5747 if (test_bit(HCI_ISCAN, &hdev->flags) || in hci_power_off_sync()
5748 test_bit(HCI_PSCAN, &hdev->flags)) { in hci_power_off_sync()
5793 cp.num_iac = min_t(u8, hdev->num_iac, 2); in hci_write_iac_sync()
5880 * by-product of disabling connectable, we need to update the in hci_update_connectable_sync()
5884 err = hci_update_adv_data_sync(hdev, hdev->cur_adv_instance); in hci_update_connectable_sync()
5888 !list_empty(&hdev->adv_instances)) { in hci_update_connectable_sync()
5891 hdev->cur_adv_instance); in hci_update_connectable_sync()
5910 if (test_bit(HCI_INQUIRY, &hdev->flags)) in hci_inquiry_sync()
5919 if (hdev->discovery.limited) in hci_inquiry_sync()
5962 * address (when privacy feature has been enabled) or non-resolvable in hci_active_scan_sync()
5972 hdev->discovery.result_filtering)) { in hci_active_scan_sync()
5987 hdev->le_scan_window_discovery, in hci_active_scan_sync()
6008 err = hci_active_scan_sync(hdev, hdev->le_scan_int_discovery * 2); in hci_start_interleaved_discovery_sync()
6020 bt_dev_dbg(hdev, "type %u", hdev->discovery.type); in hci_start_discovery_sync()
6022 switch (hdev->discovery.type) { in hci_start_discovery_sync()
6044 timeout = msecs_to_jiffies(hdev->discov_interleaved_timeout); in hci_start_discovery_sync()
6045 err = hci_active_scan_sync(hdev, hdev->le_scan_int_discovery); in hci_start_discovery_sync()
6049 err = hci_active_scan_sync(hdev, hdev->le_scan_int_discovery); in hci_start_discovery_sync()
6052 return -EINVAL; in hci_start_discovery_sync()
6060 queue_delayed_work(hdev->req_workqueue, &hdev->le_scan_disable, in hci_start_discovery_sync()
6079 int old_state = hdev->discovery.state; in hci_pause_discovery_sync()
6084 hdev->discovery_paused) in hci_pause_discovery_sync()
6092 hdev->discovery_paused = true; in hci_pause_discovery_sync()
6102 bool scanning = test_bit(HCI_PSCAN, &hdev->flags); in hci_update_event_filter_sync()
6117 list_for_each_entry(b, &hdev->accept_list, list) { in hci_update_event_filter_sync()
6118 if (!(b->flags & HCI_CONN_FLAG_REMOTE_WAKEUP)) in hci_update_event_filter_sync()
6121 bt_dev_dbg(hdev, "Adding event filters for %pMR", &b->bdaddr); in hci_update_event_filter_sync()
6125 &b->bdaddr, in hci_update_event_filter_sync()
6129 &b->bdaddr); in hci_update_event_filter_sync()
6145 if (hdev->scanning_paused) in hci_pause_scan_sync()
6149 if (test_bit(HCI_PSCAN, &hdev->flags)) in hci_pause_scan_sync()
6154 hdev->scanning_paused = true; in hci_pause_scan_sync()
6167 * Update event mask (only set events that are allowed to wake up the host)
6177 if (hdev->suspended) in hci_suspend_sync()
6181 hdev->suspended = true; in hci_suspend_sync()
6192 /* Prevent disconnects from causing scanning to be re-enabled */ in hci_suspend_sync()
6200 hdev->suspend_state = BT_RUNNING; in hci_suspend_sync()
6211 /* Only configure accept list if disconnect succeeded and wake in hci_suspend_sync()
6214 if (!hdev->wakeup || !hdev->wakeup(hdev)) { in hci_suspend_sync()
6215 hdev->suspend_state = BT_SUSPEND_DISCONNECT; in hci_suspend_sync()
6220 hdev->scanning_paused = false; in hci_suspend_sync()
6229 hdev->scanning_paused = true; in hci_suspend_sync()
6231 hdev->suspend_state = BT_SUSPEND_CONFIGURE_WAKE; in hci_suspend_sync()
6242 if (!hdev->discovery_paused) in hci_resume_discovery_sync()
6245 hdev->discovery_paused = false; in hci_resume_discovery_sync()
6271 if (!hdev->scanning_paused) in hci_resume_scan_sync()
6274 hdev->scanning_paused = false; in hci_resume_scan_sync()
6295 if (!hdev->suspended) in hci_resume_sync()
6298 hdev->suspended = false; in hci_resume_sync()
6323 struct hci_dev *hdev = conn->hdev; in conn_use_rpa()
6353 cp.channel_map = hdev->le_adv_channel_map; in hci_le_ext_directed_advertising_sync()
6359 cp.peer_addr_type = conn->dst_type; in hci_le_ext_directed_advertising_sync()
6360 bacpy(&cp.peer_addr, &conn->dst); in hci_le_ext_directed_advertising_sync()
6386 bacmp(&random_addr, &hdev->random_addr)) { in hci_le_ext_directed_advertising_sync()
6409 * and write a new random address. The flag will be set back on in hci_le_directed_advertising_sync()
6433 cp.direct_addr_type = conn->dst_type; in hci_le_directed_advertising_sync()
6434 bacpy(&cp.direct_addr, &conn->dst); in hci_le_directed_advertising_sync()
6435 cp.channel_map = hdev->le_adv_channel_map; in hci_le_directed_advertising_sync()
6451 struct hci_dev *hdev = conn->hdev; in set_ext_conn_params()
6455 p->scan_interval = cpu_to_le16(hdev->le_scan_int_connect); in set_ext_conn_params()
6456 p->scan_window = cpu_to_le16(hdev->le_scan_window_connect); in set_ext_conn_params()
6457 p->conn_interval_min = cpu_to_le16(conn->le_conn_min_interval); in set_ext_conn_params()
6458 p->conn_interval_max = cpu_to_le16(conn->le_conn_max_interval); in set_ext_conn_params()
6459 p->conn_latency = cpu_to_le16(conn->le_conn_latency); in set_ext_conn_params()
6460 p->supervision_timeout = cpu_to_le16(conn->le_supv_timeout); in set_ext_conn_params()
6461 p->min_ce_len = cpu_to_le16(0x0000); in set_ext_conn_params()
6462 p->max_ce_len = cpu_to_le16(0x0000); in set_ext_conn_params()
6474 p = (void *)cp->data; in hci_le_ext_create_conn_sync()
6478 bacpy(&cp->peer_addr, &conn->dst); in hci_le_ext_create_conn_sync()
6479 cp->peer_addr_type = conn->dst_type; in hci_le_ext_create_conn_sync()
6480 cp->own_addr_type = own_addr_type; in hci_le_ext_create_conn_sync()
6484 if (scan_1m(hdev) && (conn->le_adv_phy == HCI_ADV_PHY_1M || in hci_le_ext_create_conn_sync()
6485 conn->le_adv_sec_phy == HCI_ADV_PHY_1M)) { in hci_le_ext_create_conn_sync()
6486 cp->phys |= LE_SCAN_PHY_1M; in hci_le_ext_create_conn_sync()
6493 if (scan_2m(hdev) && (conn->le_adv_phy == HCI_ADV_PHY_2M || in hci_le_ext_create_conn_sync()
6494 conn->le_adv_sec_phy == HCI_ADV_PHY_2M)) { in hci_le_ext_create_conn_sync()
6495 cp->phys |= LE_SCAN_PHY_2M; in hci_le_ext_create_conn_sync()
6502 if (scan_coded(hdev) && (conn->le_adv_phy == HCI_ADV_PHY_CODED || in hci_le_ext_create_conn_sync()
6503 conn->le_adv_sec_phy == HCI_ADV_PHY_CODED)) { in hci_le_ext_create_conn_sync()
6504 cp->phys |= LE_SCAN_PHY_CODED; in hci_le_ext_create_conn_sync()
6513 conn->conn_timeout, NULL); in hci_le_ext_create_conn_sync()
6525 return -ECANCELED; in hci_le_create_conn_sync()
6529 clear_bit(HCI_CONN_SCANNING, &conn->flags); in hci_le_create_conn_sync()
6530 conn->state = BT_CONNECT; in hci_le_create_conn_sync()
6533 if (conn->role == HCI_ROLE_SLAVE) { in hci_le_create_conn_sync()
6538 hdev->le_scan_type == LE_SCAN_ACTIVE && in hci_le_create_conn_sync()
6541 return -EBUSY; in hci_le_create_conn_sync()
6555 params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type); in hci_le_create_conn_sync()
6557 conn->le_conn_min_interval = params->conn_min_interval; in hci_le_create_conn_sync()
6558 conn->le_conn_max_interval = params->conn_max_interval; in hci_le_create_conn_sync()
6559 conn->le_conn_latency = params->conn_latency; in hci_le_create_conn_sync()
6560 conn->le_supv_timeout = params->supervision_timeout; in hci_le_create_conn_sync()
6562 conn->le_conn_min_interval = hdev->le_conn_min_interval; in hci_le_create_conn_sync()
6563 conn->le_conn_max_interval = hdev->le_conn_max_interval; in hci_le_create_conn_sync()
6564 conn->le_conn_latency = hdev->le_conn_latency; in hci_le_create_conn_sync()
6565 conn->le_supv_timeout = hdev->le_supv_timeout; in hci_le_create_conn_sync()
6580 * that we never connect with an non-resolvable address. in hci_le_create_conn_sync()
6594 cp.scan_interval = cpu_to_le16(hdev->le_scan_int_connect); in hci_le_create_conn_sync()
6595 cp.scan_window = cpu_to_le16(hdev->le_scan_window_connect); in hci_le_create_conn_sync()
6597 bacpy(&cp.peer_addr, &conn->dst); in hci_le_create_conn_sync()
6598 cp.peer_addr_type = conn->dst_type; in hci_le_create_conn_sync()
6600 cp.conn_interval_min = cpu_to_le16(conn->le_conn_min_interval); in hci_le_create_conn_sync()
6601 cp.conn_interval_max = cpu_to_le16(conn->le_conn_max_interval); in hci_le_create_conn_sync()
6602 cp.conn_latency = cpu_to_le16(conn->le_conn_latency); in hci_le_create_conn_sync()
6603 cp.supervision_timeout = cpu_to_le16(conn->le_supv_timeout); in hci_le_create_conn_sync()
6618 conn->conn_timeout, NULL); in hci_le_create_conn_sync()
6621 if (err == -ETIMEDOUT) in hci_le_create_conn_sync()
6624 /* Re-enable advertising after the connection attempt is finished. */ in hci_le_create_conn_sync()
6664 list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) { in hci_le_create_cis_sync()
6665 if (test_bit(HCI_CONN_CREATE_CIS, &conn->flags)) in hci_le_create_cis_sync()
6670 list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) { in hci_le_create_cis_sync()
6676 cig = conn->iso_qos.ucast.cig; in hci_le_create_cis_sync()
6678 list_for_each_entry_rcu(link, &hdev->conn_hash.list, list) { in hci_le_create_cis_sync()
6680 link->iso_qos.ucast.cig == cig && in hci_le_create_cis_sync()
6681 link->state != BT_CONNECTED) { in hci_le_create_cis_sync()
6694 list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) { in hci_le_create_cis_sync()
6695 struct hci_cis *cis = &cmd->cis[aux_num_cis]; in hci_le_create_cis_sync()
6698 conn->iso_qos.ucast.cig != cig) in hci_le_create_cis_sync()
6701 set_bit(HCI_CONN_CREATE_CIS, &conn->flags); in hci_le_create_cis_sync()
6702 cis->acl_handle = cpu_to_le16(conn->parent->handle); in hci_le_create_cis_sync()
6703 cis->cis_handle = cpu_to_le16(conn->handle); in hci_le_create_cis_sync()
6706 if (aux_num_cis >= cmd->num_cis) in hci_le_create_cis_sync()
6709 cmd->num_cis = aux_num_cis; in hci_le_create_cis_sync()
6721 struct_size(cmd, cis, cmd->num_cis), in hci_le_create_cis_sync()
6723 conn->conn_timeout, NULL); in hci_le_create_cis_sync()
6787 err = smp_generate_rpa(hdev, hdev->irk, &hdev->rpa); in hci_get_random_address()
6793 bacpy(rand_addr, &hdev->rpa); in hci_get_random_address()
6799 * use an non-resolvable private address. This is useful for in hci_get_random_address()
6800 * non-connectable advertising. in hci_get_random_address()
6806 /* The non-resolvable private address is generated in hci_get_random_address()
6813 /* The non-resolvable private address shall not be in hci_get_random_address()
6816 if (bacmp(&hdev->bdaddr, &nrpa)) in hci_get_random_address()
6853 return -ECANCELED; in hci_acl_create_conn_sync()
6863 if (test_bit(HCI_INQUIRY, &hdev->flags)) { in hci_acl_create_conn_sync()
6870 conn->state = BT_CONNECT; in hci_acl_create_conn_sync()
6871 conn->out = true; in hci_acl_create_conn_sync()
6872 conn->role = HCI_ROLE_MASTER; in hci_acl_create_conn_sync()
6874 conn->attempt++; in hci_acl_create_conn_sync()
6876 conn->link_policy = hdev->link_policy; in hci_acl_create_conn_sync()
6879 bacpy(&cp.bdaddr, &conn->dst); in hci_acl_create_conn_sync()
6882 ie = hci_inquiry_cache_lookup(hdev, &conn->dst); in hci_acl_create_conn_sync()
6885 cp.pscan_rep_mode = ie->data.pscan_rep_mode; in hci_acl_create_conn_sync()
6886 cp.pscan_mode = ie->data.pscan_mode; in hci_acl_create_conn_sync()
6887 cp.clock_offset = ie->data.clock_offset | in hci_acl_create_conn_sync()
6891 memcpy(conn->dev_class, ie->data.dev_class, 3); in hci_acl_create_conn_sync()
6894 cp.pkt_type = cpu_to_le16(conn->pkt_type); in hci_acl_create_conn_sync()
6895 if (lmp_rswitch_capable(hdev) && !(hdev->link_mode & HCI_LM_MASTER)) in hci_acl_create_conn_sync()
6903 conn->conn_timeout, NULL); in hci_acl_create_conn_sync()
6918 if (err == -ECANCELED) in create_le_conn_complete()
6936 flush_delayed_work(&conn->le_conn_timeout); in create_le_conn_complete()
6951 if (conn->state != BT_OPEN) in hci_cancel_connect_sync()
6952 return -EINVAL; in hci_cancel_connect_sync()
6954 switch (conn->type) { in hci_cancel_connect_sync()
6964 return -ENOENT; in hci_cancel_connect_sync()
6973 cp.handle = cpu_to_le16(conn->handle); in hci_le_conn_update_sync()
6974 cp.conn_interval_min = cpu_to_le16(params->conn_min_interval); in hci_le_conn_update_sync()
6975 cp.conn_interval_max = cpu_to_le16(params->conn_max_interval); in hci_le_conn_update_sync()
6976 cp.conn_latency = cpu_to_le16(params->conn_latency); in hci_le_conn_update_sync()
6977 cp.supervision_timeout = cpu_to_le16(params->supervision_timeout); in hci_le_conn_update_sync()
6992 if (err == -ECANCELED) in create_pa_complete()
6998 clear_bit(HCI_CONN_CREATE_PA_SYNC, &conn->flags); in create_pa_complete()
7010 set_bit(HCI_CONN_PA_SYNC_FAILED, &pa_sync->flags); in create_pa_complete()
7023 struct bt_iso_qos *qos = &conn->iso_qos; in hci_le_pa_create_sync()
7027 return -ECANCELED; in hci_le_pa_create_sync()
7029 if (conn->sync_handle != HCI_SYNC_HANDLE_INVALID) in hci_le_pa_create_sync()
7030 return -EINVAL; in hci_le_pa_create_sync()
7033 return -EBUSY; in hci_le_pa_create_sync()
7039 if (conn->sid == HCI_SID_INVALID && in hci_le_pa_create_sync()
7050 set_bit(HCI_CONN_CREATE_PA_SYNC, &conn->flags); in hci_le_pa_create_sync()
7057 if (conn->sid == HCI_SID_INVALID) { in hci_le_pa_create_sync()
7060 conn->conn_timeout, NULL); in hci_le_pa_create_sync()
7061 if (err == -ETIMEDOUT) in hci_le_pa_create_sync()
7066 cp.options = qos->bcast.options; in hci_le_pa_create_sync()
7067 cp.sid = conn->sid; in hci_le_pa_create_sync()
7068 cp.addr_type = conn->dst_type; in hci_le_pa_create_sync()
7069 bacpy(&cp.addr, &conn->dst); in hci_le_pa_create_sync()
7070 cp.skip = cpu_to_le16(qos->bcast.skip); in hci_le_pa_create_sync()
7071 cp.sync_timeout = cpu_to_le16(qos->bcast.sync_timeout); in hci_le_pa_create_sync()
7072 cp.sync_cte_type = qos->bcast.sync_cte_type; in hci_le_pa_create_sync()
7088 conn->conn_timeout, NULL); in hci_le_pa_create_sync()
7089 if (err == -ETIMEDOUT) in hci_le_pa_create_sync()
7114 if (err == -ECANCELED) in create_big_complete()
7118 clear_bit(HCI_CONN_CREATE_BIG_SYNC, &conn->flags); in create_big_complete()
7125 struct bt_iso_qos *qos = &conn->iso_qos; in hci_le_big_create_sync()
7129 return -ECANCELED; in hci_le_big_create_sync()
7131 set_bit(HCI_CONN_CREATE_BIG_SYNC, &conn->flags); in hci_le_big_create_sync()
7134 cp->handle = qos->bcast.big; in hci_le_big_create_sync()
7135 cp->sync_handle = cpu_to_le16(conn->sync_handle); in hci_le_big_create_sync()
7136 cp->encryption = qos->bcast.encryption; in hci_le_big_create_sync()
7137 memcpy(cp->bcode, qos->bcast.bcode, sizeof(cp->bcode)); in hci_le_big_create_sync()
7138 cp->mse = qos->bcast.mse; in hci_le_big_create_sync()
7139 cp->timeout = cpu_to_le16(qos->bcast.timeout); in hci_le_big_create_sync()
7140 cp->num_bis = conn->num_bis; in hci_le_big_create_sync()
7141 memcpy(cp->bis, conn->bis, conn->num_bis); in hci_le_big_create_sync()
7156 struct_size(cp, bis, cp->num_bis), cp, in hci_le_big_create_sync()
7158 conn->conn_timeout, NULL); in hci_le_big_create_sync()
7159 if (err == -ETIMEDOUT) in hci_le_big_create_sync()
7160 hci_le_big_terminate_sync(hdev, cp->handle); in hci_le_big_create_sync()