2007-02-09 14:24:33 +00:00
|
|
|
/*
|
2005-04-16 22:20:36 +00:00
|
|
|
BlueZ - Bluetooth protocol stack for Linux
|
2010-05-28 15:53:46 +00:00
|
|
|
Copyright (c) 2000-2001, 2010, Code Aurora Forum. All rights reserved.
|
2024-02-23 13:14:41 +00:00
|
|
|
Copyright 2023-2024 NXP
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License version 2 as
|
|
|
|
published by the Free Software Foundation;
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
|
|
|
|
IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
|
2007-02-09 14:24:33 +00:00
|
|
|
CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
|
|
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
2005-04-16 22:20:36 +00:00
|
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
2007-02-09 14:24:33 +00:00
|
|
|
ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
|
|
|
|
COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
|
2005-04-16 22:20:36 +00:00
|
|
|
SOFTWARE IS DISCLAIMED.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Bluetooth HCI connection handling. */
|
|
|
|
|
2012-05-23 07:04:22 +00:00
|
|
|
#include <linux/export.h>
|
2014-12-20 16:13:41 +00:00
|
|
|
#include <linux/debugfs.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#include <net/bluetooth/bluetooth.h>
|
|
|
|
#include <net/bluetooth/hci_core.h>
|
2014-05-20 06:45:47 +00:00
|
|
|
#include <net/bluetooth/l2cap.h>
|
2022-03-09 21:22:20 +00:00
|
|
|
#include <net/bluetooth/iso.h>
|
|
|
|
#include <net/bluetooth/mgmt.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2013-10-10 21:54:16 +00:00
|
|
|
#include "smp.h"
|
2022-03-09 21:22:20 +00:00
|
|
|
#include "eir.h"
|
2013-10-10 21:54:15 +00:00
|
|
|
|
2013-08-19 12:24:03 +00:00
|
|
|
struct sco_param {
|
|
|
|
u16 pkt_type;
|
|
|
|
u16 max_latency;
|
2014-09-24 19:41:46 +00:00
|
|
|
u8 retrans_effort;
|
2013-08-19 12:24:03 +00:00
|
|
|
};
|
|
|
|
|
2022-08-05 23:42:31 +00:00
|
|
|
struct conn_handle_t {
|
|
|
|
struct hci_conn *conn;
|
|
|
|
__u16 handle;
|
|
|
|
};
|
|
|
|
|
2014-09-23 09:01:07 +00:00
|
|
|
static const struct sco_param esco_param_cvsd[] = {
|
2014-09-24 19:41:46 +00:00
|
|
|
{ EDR_ESCO_MASK & ~ESCO_2EV3, 0x000a, 0x01 }, /* S3 */
|
|
|
|
{ EDR_ESCO_MASK & ~ESCO_2EV3, 0x0007, 0x01 }, /* S2 */
|
|
|
|
{ EDR_ESCO_MASK | ESCO_EV3, 0x0007, 0x01 }, /* S1 */
|
|
|
|
{ EDR_ESCO_MASK | ESCO_HV3, 0xffff, 0x01 }, /* D1 */
|
|
|
|
{ EDR_ESCO_MASK | ESCO_HV1, 0xffff, 0x01 }, /* D0 */
|
2013-08-19 12:24:03 +00:00
|
|
|
};
|
|
|
|
|
2014-09-23 09:01:07 +00:00
|
|
|
static const struct sco_param sco_param_cvsd[] = {
|
2014-09-24 19:41:46 +00:00
|
|
|
{ EDR_ESCO_MASK | ESCO_HV3, 0xffff, 0xff }, /* D1 */
|
|
|
|
{ EDR_ESCO_MASK | ESCO_HV1, 0xffff, 0xff }, /* D0 */
|
2014-09-23 09:01:07 +00:00
|
|
|
};
|
|
|
|
|
2014-09-25 06:48:01 +00:00
|
|
|
static const struct sco_param esco_param_msbc[] = {
|
2014-09-24 19:41:46 +00:00
|
|
|
{ EDR_ESCO_MASK & ~ESCO_2EV3, 0x000d, 0x02 }, /* T2 */
|
|
|
|
{ EDR_ESCO_MASK | ESCO_EV3, 0x0008, 0x02 }, /* T1 */
|
2013-08-19 12:24:03 +00:00
|
|
|
};
|
|
|
|
|
2015-08-07 18:22:53 +00:00
|
|
|
/* This function requires the caller holds hdev->lock */
|
2024-02-13 14:59:32 +00:00
|
|
|
void hci_connect_le_scan_cleanup(struct hci_conn *conn, u8 status)
|
2015-08-07 18:22:53 +00:00
|
|
|
{
|
|
|
|
struct hci_conn_params *params;
|
2015-10-21 15:03:09 +00:00
|
|
|
struct hci_dev *hdev = conn->hdev;
|
2015-08-07 18:22:53 +00:00
|
|
|
struct smp_irk *irk;
|
|
|
|
bdaddr_t *bdaddr;
|
|
|
|
u8 bdaddr_type;
|
|
|
|
|
|
|
|
bdaddr = &conn->dst;
|
|
|
|
bdaddr_type = conn->dst_type;
|
|
|
|
|
|
|
|
/* Check if we need to convert to identity address */
|
2015-10-21 15:03:09 +00:00
|
|
|
irk = hci_get_irk(hdev, bdaddr, bdaddr_type);
|
2015-08-07 18:22:53 +00:00
|
|
|
if (irk) {
|
|
|
|
bdaddr = &irk->bdaddr;
|
|
|
|
bdaddr_type = irk->addr_type;
|
|
|
|
}
|
|
|
|
|
2015-10-21 15:03:10 +00:00
|
|
|
params = hci_pend_le_action_lookup(&hdev->pend_le_conns, bdaddr,
|
|
|
|
bdaddr_type);
|
2023-03-24 17:57:55 +00:00
|
|
|
if (!params)
|
2015-08-07 18:22:53 +00:00
|
|
|
return;
|
|
|
|
|
2023-03-24 17:57:55 +00:00
|
|
|
if (params->conn) {
|
|
|
|
hci_conn_drop(params->conn);
|
|
|
|
hci_conn_put(params->conn);
|
|
|
|
params->conn = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!params->explicit_connect)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* If the status indicates successful cancellation of
|
|
|
|
* the attempt (i.e. Unknown Connection Id) there's no point of
|
|
|
|
* notifying failure since we'll go back to keep trying to
|
|
|
|
* connect. The only exception is explicit connect requests
|
|
|
|
* where a timeout + cancel does indicate an actual failure.
|
|
|
|
*/
|
|
|
|
if (status && status != HCI_ERROR_UNKNOWN_CONN_ID)
|
2024-08-30 21:29:27 +00:00
|
|
|
mgmt_connect_failed(hdev, conn, status);
|
2023-03-24 17:57:55 +00:00
|
|
|
|
2015-08-07 18:22:53 +00:00
|
|
|
/* The connection attempt was doing scan for new RPA, and is
|
|
|
|
* in scan phase. If params are not associated with any other
|
|
|
|
* autoconnect action, remove them completely. If they are, just unmark
|
|
|
|
* them as waiting for connection, by clearing explicit_connect field.
|
|
|
|
*/
|
2015-10-16 07:07:53 +00:00
|
|
|
params->explicit_connect = false;
|
|
|
|
|
Bluetooth: use RCU for hci_conn_params and iterate safely in hci_sync
hci_update_accept_list_sync iterates over hdev->pend_le_conns and
hdev->pend_le_reports, and waits for controller events in the loop body,
without holding hdev lock.
Meanwhile, these lists and the items may be modified e.g. by
le_scan_cleanup. This can invalidate the list cursor or any other item
in the list, resulting to invalid behavior (eg use-after-free).
Use RCU for the hci_conn_params action lists. Since the loop bodies in
hci_sync block and we cannot use RCU or hdev->lock for the whole loop,
copy list items first and then iterate on the copy. Only the flags field
is written from elsewhere, so READ_ONCE/WRITE_ONCE should guarantee we
read valid values.
Free params everywhere with hci_conn_params_free so the cleanup is
guaranteed to be done properly.
This fixes the following, which can be triggered e.g. by BlueZ new
mgmt-tester case "Add + Remove Device Nowait - Success", or by changing
hci_le_set_cig_params to always return false, and running iso-tester:
==================================================================
BUG: KASAN: slab-use-after-free in hci_update_passive_scan_sync (net/bluetooth/hci_sync.c:2536 net/bluetooth/hci_sync.c:2723 net/bluetooth/hci_sync.c:2841)
Read of size 8 at addr ffff888001265018 by task kworker/u3:0/32
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-1.fc38 04/01/2014
Workqueue: hci0 hci_cmd_sync_work
Call Trace:
<TASK>
dump_stack_lvl (./arch/x86/include/asm/irqflags.h:134 lib/dump_stack.c:107)
print_report (mm/kasan/report.c:320 mm/kasan/report.c:430)
? __virt_addr_valid (./include/linux/mmzone.h:1915 ./include/linux/mmzone.h:2011 arch/x86/mm/physaddr.c:65)
? hci_update_passive_scan_sync (net/bluetooth/hci_sync.c:2536 net/bluetooth/hci_sync.c:2723 net/bluetooth/hci_sync.c:2841)
kasan_report (mm/kasan/report.c:538)
? hci_update_passive_scan_sync (net/bluetooth/hci_sync.c:2536 net/bluetooth/hci_sync.c:2723 net/bluetooth/hci_sync.c:2841)
hci_update_passive_scan_sync (net/bluetooth/hci_sync.c:2536 net/bluetooth/hci_sync.c:2723 net/bluetooth/hci_sync.c:2841)
? __pfx_hci_update_passive_scan_sync (net/bluetooth/hci_sync.c:2780)
? mutex_lock (kernel/locking/mutex.c:282)
? __pfx_mutex_lock (kernel/locking/mutex.c:282)
? __pfx_mutex_unlock (kernel/locking/mutex.c:538)
? __pfx_update_passive_scan_sync (net/bluetooth/hci_sync.c:2861)
hci_cmd_sync_work (net/bluetooth/hci_sync.c:306)
process_one_work (./arch/x86/include/asm/preempt.h:27 kernel/workqueue.c:2399)
worker_thread (./include/linux/list.h:292 kernel/workqueue.c:2538)
? __pfx_worker_thread (kernel/workqueue.c:2480)
kthread (kernel/kthread.c:376)
? __pfx_kthread (kernel/kthread.c:331)
ret_from_fork (arch/x86/entry/entry_64.S:314)
</TASK>
Allocated by task 31:
kasan_save_stack (mm/kasan/common.c:46)
kasan_set_track (mm/kasan/common.c:52)
__kasan_kmalloc (mm/kasan/common.c:374 mm/kasan/common.c:383)
hci_conn_params_add (./include/linux/slab.h:580 ./include/linux/slab.h:720 net/bluetooth/hci_core.c:2277)
hci_connect_le_scan (net/bluetooth/hci_conn.c:1419 net/bluetooth/hci_conn.c:1589)
hci_connect_cis (net/bluetooth/hci_conn.c:2266)
iso_connect_cis (net/bluetooth/iso.c:390)
iso_sock_connect (net/bluetooth/iso.c:899)
__sys_connect (net/socket.c:2003 net/socket.c:2020)
__x64_sys_connect (net/socket.c:2027)
do_syscall_64 (arch/x86/entry/common.c:50 arch/x86/entry/common.c:80)
entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:120)
Freed by task 15:
kasan_save_stack (mm/kasan/common.c:46)
kasan_set_track (mm/kasan/common.c:52)
kasan_save_free_info (mm/kasan/generic.c:523)
__kasan_slab_free (mm/kasan/common.c:238 mm/kasan/common.c:200 mm/kasan/common.c:244)
__kmem_cache_free (mm/slub.c:1807 mm/slub.c:3787 mm/slub.c:3800)
hci_conn_params_del (net/bluetooth/hci_core.c:2323)
le_scan_cleanup (net/bluetooth/hci_conn.c:202)
process_one_work (./arch/x86/include/asm/preempt.h:27 kernel/workqueue.c:2399)
worker_thread (./include/linux/list.h:292 kernel/workqueue.c:2538)
kthread (kernel/kthread.c:376)
ret_from_fork (arch/x86/entry/entry_64.S:314)
==================================================================
Fixes: e8907f76544f ("Bluetooth: hci_sync: Make use of hci_cmd_sync_queue set 3")
Signed-off-by: Pauli Virtanen <pav@iki.fi>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2023-06-18 22:04:31 +00:00
|
|
|
hci_pend_le_list_del_init(params);
|
2015-10-16 07:07:53 +00:00
|
|
|
|
|
|
|
switch (params->auto_connect) {
|
|
|
|
case HCI_AUTO_CONN_EXPLICIT:
|
2015-10-21 15:03:09 +00:00
|
|
|
hci_conn_params_del(hdev, bdaddr, bdaddr_type);
|
2015-10-16 07:07:53 +00:00
|
|
|
/* return instead of break to avoid duplicate scan update */
|
|
|
|
return;
|
|
|
|
case HCI_AUTO_CONN_DIRECT:
|
|
|
|
case HCI_AUTO_CONN_ALWAYS:
|
Bluetooth: use RCU for hci_conn_params and iterate safely in hci_sync
hci_update_accept_list_sync iterates over hdev->pend_le_conns and
hdev->pend_le_reports, and waits for controller events in the loop body,
without holding hdev lock.
Meanwhile, these lists and the items may be modified e.g. by
le_scan_cleanup. This can invalidate the list cursor or any other item
in the list, resulting to invalid behavior (eg use-after-free).
Use RCU for the hci_conn_params action lists. Since the loop bodies in
hci_sync block and we cannot use RCU or hdev->lock for the whole loop,
copy list items first and then iterate on the copy. Only the flags field
is written from elsewhere, so READ_ONCE/WRITE_ONCE should guarantee we
read valid values.
Free params everywhere with hci_conn_params_free so the cleanup is
guaranteed to be done properly.
This fixes the following, which can be triggered e.g. by BlueZ new
mgmt-tester case "Add + Remove Device Nowait - Success", or by changing
hci_le_set_cig_params to always return false, and running iso-tester:
==================================================================
BUG: KASAN: slab-use-after-free in hci_update_passive_scan_sync (net/bluetooth/hci_sync.c:2536 net/bluetooth/hci_sync.c:2723 net/bluetooth/hci_sync.c:2841)
Read of size 8 at addr ffff888001265018 by task kworker/u3:0/32
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-1.fc38 04/01/2014
Workqueue: hci0 hci_cmd_sync_work
Call Trace:
<TASK>
dump_stack_lvl (./arch/x86/include/asm/irqflags.h:134 lib/dump_stack.c:107)
print_report (mm/kasan/report.c:320 mm/kasan/report.c:430)
? __virt_addr_valid (./include/linux/mmzone.h:1915 ./include/linux/mmzone.h:2011 arch/x86/mm/physaddr.c:65)
? hci_update_passive_scan_sync (net/bluetooth/hci_sync.c:2536 net/bluetooth/hci_sync.c:2723 net/bluetooth/hci_sync.c:2841)
kasan_report (mm/kasan/report.c:538)
? hci_update_passive_scan_sync (net/bluetooth/hci_sync.c:2536 net/bluetooth/hci_sync.c:2723 net/bluetooth/hci_sync.c:2841)
hci_update_passive_scan_sync (net/bluetooth/hci_sync.c:2536 net/bluetooth/hci_sync.c:2723 net/bluetooth/hci_sync.c:2841)
? __pfx_hci_update_passive_scan_sync (net/bluetooth/hci_sync.c:2780)
? mutex_lock (kernel/locking/mutex.c:282)
? __pfx_mutex_lock (kernel/locking/mutex.c:282)
? __pfx_mutex_unlock (kernel/locking/mutex.c:538)
? __pfx_update_passive_scan_sync (net/bluetooth/hci_sync.c:2861)
hci_cmd_sync_work (net/bluetooth/hci_sync.c:306)
process_one_work (./arch/x86/include/asm/preempt.h:27 kernel/workqueue.c:2399)
worker_thread (./include/linux/list.h:292 kernel/workqueue.c:2538)
? __pfx_worker_thread (kernel/workqueue.c:2480)
kthread (kernel/kthread.c:376)
? __pfx_kthread (kernel/kthread.c:331)
ret_from_fork (arch/x86/entry/entry_64.S:314)
</TASK>
Allocated by task 31:
kasan_save_stack (mm/kasan/common.c:46)
kasan_set_track (mm/kasan/common.c:52)
__kasan_kmalloc (mm/kasan/common.c:374 mm/kasan/common.c:383)
hci_conn_params_add (./include/linux/slab.h:580 ./include/linux/slab.h:720 net/bluetooth/hci_core.c:2277)
hci_connect_le_scan (net/bluetooth/hci_conn.c:1419 net/bluetooth/hci_conn.c:1589)
hci_connect_cis (net/bluetooth/hci_conn.c:2266)
iso_connect_cis (net/bluetooth/iso.c:390)
iso_sock_connect (net/bluetooth/iso.c:899)
__sys_connect (net/socket.c:2003 net/socket.c:2020)
__x64_sys_connect (net/socket.c:2027)
do_syscall_64 (arch/x86/entry/common.c:50 arch/x86/entry/common.c:80)
entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:120)
Freed by task 15:
kasan_save_stack (mm/kasan/common.c:46)
kasan_set_track (mm/kasan/common.c:52)
kasan_save_free_info (mm/kasan/generic.c:523)
__kasan_slab_free (mm/kasan/common.c:238 mm/kasan/common.c:200 mm/kasan/common.c:244)
__kmem_cache_free (mm/slub.c:1807 mm/slub.c:3787 mm/slub.c:3800)
hci_conn_params_del (net/bluetooth/hci_core.c:2323)
le_scan_cleanup (net/bluetooth/hci_conn.c:202)
process_one_work (./arch/x86/include/asm/preempt.h:27 kernel/workqueue.c:2399)
worker_thread (./include/linux/list.h:292 kernel/workqueue.c:2538)
kthread (kernel/kthread.c:376)
ret_from_fork (arch/x86/entry/entry_64.S:314)
==================================================================
Fixes: e8907f76544f ("Bluetooth: hci_sync: Make use of hci_cmd_sync_queue set 3")
Signed-off-by: Pauli Virtanen <pav@iki.fi>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2023-06-18 22:04:31 +00:00
|
|
|
hci_pend_le_list_add(params, &hdev->pend_le_conns);
|
2015-10-16 07:07:53 +00:00
|
|
|
break;
|
|
|
|
case HCI_AUTO_CONN_REPORT:
|
Bluetooth: use RCU for hci_conn_params and iterate safely in hci_sync
hci_update_accept_list_sync iterates over hdev->pend_le_conns and
hdev->pend_le_reports, and waits for controller events in the loop body,
without holding hdev lock.
Meanwhile, these lists and the items may be modified e.g. by
le_scan_cleanup. This can invalidate the list cursor or any other item
in the list, resulting to invalid behavior (eg use-after-free).
Use RCU for the hci_conn_params action lists. Since the loop bodies in
hci_sync block and we cannot use RCU or hdev->lock for the whole loop,
copy list items first and then iterate on the copy. Only the flags field
is written from elsewhere, so READ_ONCE/WRITE_ONCE should guarantee we
read valid values.
Free params everywhere with hci_conn_params_free so the cleanup is
guaranteed to be done properly.
This fixes the following, which can be triggered e.g. by BlueZ new
mgmt-tester case "Add + Remove Device Nowait - Success", or by changing
hci_le_set_cig_params to always return false, and running iso-tester:
==================================================================
BUG: KASAN: slab-use-after-free in hci_update_passive_scan_sync (net/bluetooth/hci_sync.c:2536 net/bluetooth/hci_sync.c:2723 net/bluetooth/hci_sync.c:2841)
Read of size 8 at addr ffff888001265018 by task kworker/u3:0/32
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-1.fc38 04/01/2014
Workqueue: hci0 hci_cmd_sync_work
Call Trace:
<TASK>
dump_stack_lvl (./arch/x86/include/asm/irqflags.h:134 lib/dump_stack.c:107)
print_report (mm/kasan/report.c:320 mm/kasan/report.c:430)
? __virt_addr_valid (./include/linux/mmzone.h:1915 ./include/linux/mmzone.h:2011 arch/x86/mm/physaddr.c:65)
? hci_update_passive_scan_sync (net/bluetooth/hci_sync.c:2536 net/bluetooth/hci_sync.c:2723 net/bluetooth/hci_sync.c:2841)
kasan_report (mm/kasan/report.c:538)
? hci_update_passive_scan_sync (net/bluetooth/hci_sync.c:2536 net/bluetooth/hci_sync.c:2723 net/bluetooth/hci_sync.c:2841)
hci_update_passive_scan_sync (net/bluetooth/hci_sync.c:2536 net/bluetooth/hci_sync.c:2723 net/bluetooth/hci_sync.c:2841)
? __pfx_hci_update_passive_scan_sync (net/bluetooth/hci_sync.c:2780)
? mutex_lock (kernel/locking/mutex.c:282)
? __pfx_mutex_lock (kernel/locking/mutex.c:282)
? __pfx_mutex_unlock (kernel/locking/mutex.c:538)
? __pfx_update_passive_scan_sync (net/bluetooth/hci_sync.c:2861)
hci_cmd_sync_work (net/bluetooth/hci_sync.c:306)
process_one_work (./arch/x86/include/asm/preempt.h:27 kernel/workqueue.c:2399)
worker_thread (./include/linux/list.h:292 kernel/workqueue.c:2538)
? __pfx_worker_thread (kernel/workqueue.c:2480)
kthread (kernel/kthread.c:376)
? __pfx_kthread (kernel/kthread.c:331)
ret_from_fork (arch/x86/entry/entry_64.S:314)
</TASK>
Allocated by task 31:
kasan_save_stack (mm/kasan/common.c:46)
kasan_set_track (mm/kasan/common.c:52)
__kasan_kmalloc (mm/kasan/common.c:374 mm/kasan/common.c:383)
hci_conn_params_add (./include/linux/slab.h:580 ./include/linux/slab.h:720 net/bluetooth/hci_core.c:2277)
hci_connect_le_scan (net/bluetooth/hci_conn.c:1419 net/bluetooth/hci_conn.c:1589)
hci_connect_cis (net/bluetooth/hci_conn.c:2266)
iso_connect_cis (net/bluetooth/iso.c:390)
iso_sock_connect (net/bluetooth/iso.c:899)
__sys_connect (net/socket.c:2003 net/socket.c:2020)
__x64_sys_connect (net/socket.c:2027)
do_syscall_64 (arch/x86/entry/common.c:50 arch/x86/entry/common.c:80)
entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:120)
Freed by task 15:
kasan_save_stack (mm/kasan/common.c:46)
kasan_set_track (mm/kasan/common.c:52)
kasan_save_free_info (mm/kasan/generic.c:523)
__kasan_slab_free (mm/kasan/common.c:238 mm/kasan/common.c:200 mm/kasan/common.c:244)
__kmem_cache_free (mm/slub.c:1807 mm/slub.c:3787 mm/slub.c:3800)
hci_conn_params_del (net/bluetooth/hci_core.c:2323)
le_scan_cleanup (net/bluetooth/hci_conn.c:202)
process_one_work (./arch/x86/include/asm/preempt.h:27 kernel/workqueue.c:2399)
worker_thread (./include/linux/list.h:292 kernel/workqueue.c:2538)
kthread (kernel/kthread.c:376)
ret_from_fork (arch/x86/entry/entry_64.S:314)
==================================================================
Fixes: e8907f76544f ("Bluetooth: hci_sync: Make use of hci_cmd_sync_queue set 3")
Signed-off-by: Pauli Virtanen <pav@iki.fi>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2023-06-18 22:04:31 +00:00
|
|
|
hci_pend_le_list_add(params, &hdev->pend_le_reports);
|
2015-10-16 07:07:53 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2015-10-16 07:07:49 +00:00
|
|
|
}
|
2015-10-16 07:07:53 +00:00
|
|
|
|
2021-10-27 23:58:43 +00:00
|
|
|
hci_update_passive_scan(hdev);
|
2015-08-07 18:22:53 +00:00
|
|
|
}
|
|
|
|
|
2015-10-16 07:07:50 +00:00
|
|
|
static void hci_conn_cleanup(struct hci_conn *conn)
|
|
|
|
{
|
|
|
|
struct hci_dev *hdev = conn->hdev;
|
|
|
|
|
|
|
|
if (test_bit(HCI_CONN_PARAM_REMOVAL_PEND, &conn->flags))
|
|
|
|
hci_conn_params_del(conn->hdev, &conn->dst, conn->dst_type);
|
|
|
|
|
2022-06-02 15:30:03 +00:00
|
|
|
if (test_and_clear_bit(HCI_CONN_FLUSH_KEY, &conn->flags))
|
|
|
|
hci_remove_link_key(hdev, &conn->dst);
|
|
|
|
|
2015-10-16 07:07:50 +00:00
|
|
|
hci_chan_list_flush(conn);
|
|
|
|
|
|
|
|
hci_conn_hash_del(hdev, conn);
|
|
|
|
|
2023-10-11 09:57:31 +00:00
|
|
|
if (HCI_CONN_HANDLE_UNSET(conn->handle))
|
|
|
|
ida_free(&hdev->unset_handle_ida, conn->handle);
|
|
|
|
|
2019-07-29 15:15:43 +00:00
|
|
|
if (conn->cleanup)
|
|
|
|
conn->cleanup(conn);
|
|
|
|
|
2020-04-03 19:43:58 +00:00
|
|
|
if (conn->type == SCO_LINK || conn->type == ESCO_LINK) {
|
|
|
|
switch (conn->setting & SCO_AIRMODE_MASK) {
|
|
|
|
case SCO_AIRMODE_CVSD:
|
|
|
|
case SCO_AIRMODE_TRANSP:
|
|
|
|
if (hdev->notify)
|
|
|
|
hdev->notify(hdev, HCI_NOTIFY_DISABLE_SCO);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (hdev->notify)
|
|
|
|
hdev->notify(hdev, HCI_NOTIFY_CONN_DEL);
|
|
|
|
}
|
2015-10-16 07:07:50 +00:00
|
|
|
|
|
|
|
debugfs_remove_recursive(conn->debugfs);
|
|
|
|
|
2023-10-18 10:30:55 +00:00
|
|
|
hci_conn_del_sysfs(conn);
|
2015-10-16 07:07:50 +00:00
|
|
|
|
2023-10-18 10:30:55 +00:00
|
|
|
hci_dev_put(hdev);
|
2015-10-16 07:07:50 +00:00
|
|
|
}
|
|
|
|
|
2014-08-18 17:33:32 +00:00
|
|
|
int hci_disconnect(struct hci_conn *conn, __u8 reason)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2012-06-15 08:50:28 +00:00
|
|
|
BT_DBG("hcon %p", conn);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-06-04 08:26:25 +00:00
|
|
|
/* When we are central of an established connection and it enters
|
2014-08-18 17:33:34 +00:00
|
|
|
* the disconnect timeout, then go ahead and try to read the
|
|
|
|
* current clock offset. Processing of the result is done
|
|
|
|
* within the event handling and hci_clock_offset_evt function.
|
|
|
|
*/
|
2015-10-22 07:49:39 +00:00
|
|
|
if (conn->type == ACL_LINK && conn->role == HCI_ROLE_MASTER &&
|
|
|
|
(conn->state == BT_CONNECTED || conn->state == BT_CONFIG)) {
|
2014-08-18 17:33:34 +00:00
|
|
|
struct hci_dev *hdev = conn->hdev;
|
2014-10-25 08:48:58 +00:00
|
|
|
struct hci_cp_read_clock_offset clkoff_cp;
|
2014-08-18 17:33:34 +00:00
|
|
|
|
2014-10-25 08:48:58 +00:00
|
|
|
clkoff_cp.handle = cpu_to_le16(conn->handle);
|
|
|
|
hci_send_cmd(hdev, HCI_OP_READ_CLOCK_OFFSET, sizeof(clkoff_cp),
|
|
|
|
&clkoff_cp);
|
2014-08-18 17:33:34 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 07:49:39 +00:00
|
|
|
return hci_abort_conn(conn, reason);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2012-07-27 22:32:54 +00:00
|
|
|
static void hci_add_sco(struct hci_conn *conn, __u16 handle)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct hci_dev *hdev = conn->hdev;
|
|
|
|
struct hci_cp_add_sco cp;
|
|
|
|
|
2012-06-15 08:50:28 +00:00
|
|
|
BT_DBG("hcon %p", conn);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
conn->state = BT_CONNECT;
|
2012-01-16 07:49:58 +00:00
|
|
|
conn->out = true;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-02-06 08:13:37 +00:00
|
|
|
conn->attempt++;
|
|
|
|
|
2007-03-26 03:12:50 +00:00
|
|
|
cp.handle = cpu_to_le16(handle);
|
2008-07-14 18:13:46 +00:00
|
|
|
cp.pkt_type = cpu_to_le16(conn->pkt_type);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-10-20 11:33:56 +00:00
|
|
|
hci_send_cmd(hdev, HCI_OP_ADD_SCO, sizeof(cp), &cp);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2021-01-29 21:53:48 +00:00
|
|
|
static bool find_next_esco_param(struct hci_conn *conn,
|
|
|
|
const struct sco_param *esco_param, int size)
|
|
|
|
{
|
2023-04-11 23:02:22 +00:00
|
|
|
if (!conn->parent)
|
|
|
|
return false;
|
|
|
|
|
2021-01-29 21:53:48 +00:00
|
|
|
for (; conn->attempt <= size; conn->attempt++) {
|
2023-04-11 23:02:22 +00:00
|
|
|
if (lmp_esco_2m_capable(conn->parent) ||
|
2021-01-29 21:53:48 +00:00
|
|
|
(esco_param[conn->attempt - 1].pkt_type & ESCO_2EV3))
|
|
|
|
break;
|
|
|
|
BT_DBG("hcon %p skipped attempt %d, eSCO 2M not supported",
|
|
|
|
conn, conn->attempt);
|
|
|
|
}
|
|
|
|
|
|
|
|
return conn->attempt <= size;
|
|
|
|
}
|
|
|
|
|
2022-08-05 23:42:31 +00:00
|
|
|
static int configure_datapath_sync(struct hci_dev *hdev, struct bt_codec *codec)
|
2021-09-07 10:12:43 +00:00
|
|
|
{
|
2022-08-05 23:42:31 +00:00
|
|
|
int err;
|
|
|
|
__u8 vnd_len, *vnd_data = NULL;
|
|
|
|
struct hci_op_configure_data_path *cmd = NULL;
|
|
|
|
|
2024-04-22 14:46:34 +00:00
|
|
|
/* Do not take below 2 checks as error since the 1st means user do not
|
|
|
|
* want to use HFP offload mode and the 2nd means the vendor controller
|
|
|
|
* do not need to send below HCI command for offload mode.
|
|
|
|
*/
|
2023-12-08 01:51:26 +00:00
|
|
|
if (!codec->data_path || !hdev->get_codec_config_data)
|
|
|
|
return 0;
|
|
|
|
|
2022-08-05 23:42:31 +00:00
|
|
|
err = hdev->get_codec_config_data(hdev, ESCO_LINK, codec, &vnd_len,
|
|
|
|
&vnd_data);
|
|
|
|
if (err < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
cmd = kzalloc(sizeof(*cmd) + vnd_len, GFP_KERNEL);
|
|
|
|
if (!cmd) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = hdev->get_data_path_id(hdev, &cmd->data_path_id);
|
|
|
|
if (err < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
cmd->vnd_len = vnd_len;
|
|
|
|
memcpy(cmd->vnd_data, vnd_data, vnd_len);
|
|
|
|
|
|
|
|
cmd->direction = 0x00;
|
|
|
|
__hci_cmd_sync_status(hdev, HCI_CONFIGURE_DATA_PATH,
|
|
|
|
sizeof(*cmd) + vnd_len, cmd, HCI_CMD_TIMEOUT);
|
|
|
|
|
|
|
|
cmd->direction = 0x01;
|
|
|
|
err = __hci_cmd_sync_status(hdev, HCI_CONFIGURE_DATA_PATH,
|
|
|
|
sizeof(*cmd) + vnd_len, cmd,
|
|
|
|
HCI_CMD_TIMEOUT);
|
|
|
|
error:
|
|
|
|
|
|
|
|
kfree(cmd);
|
|
|
|
kfree(vnd_data);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hci_enhanced_setup_sync(struct hci_dev *hdev, void *data)
|
|
|
|
{
|
|
|
|
struct conn_handle_t *conn_handle = data;
|
|
|
|
struct hci_conn *conn = conn_handle->conn;
|
|
|
|
__u16 handle = conn_handle->handle;
|
2021-09-07 10:12:43 +00:00
|
|
|
struct hci_cp_enhanced_setup_sync_conn cp;
|
|
|
|
const struct sco_param *param;
|
|
|
|
|
2022-08-05 23:42:31 +00:00
|
|
|
kfree(conn_handle);
|
|
|
|
|
2024-10-02 15:17:26 +00:00
|
|
|
if (!hci_conn_valid(hdev, conn))
|
|
|
|
return -ECANCELED;
|
|
|
|
|
2021-09-07 10:12:43 +00:00
|
|
|
bt_dev_dbg(hdev, "hcon %p", conn);
|
|
|
|
|
2023-12-08 01:51:26 +00:00
|
|
|
configure_datapath_sync(hdev, &conn->codec);
|
2021-09-07 10:12:44 +00:00
|
|
|
|
2021-09-07 10:12:43 +00:00
|
|
|
conn->state = BT_CONNECT;
|
|
|
|
conn->out = true;
|
|
|
|
|
|
|
|
conn->attempt++;
|
|
|
|
|
|
|
|
memset(&cp, 0x00, sizeof(cp));
|
|
|
|
|
|
|
|
cp.handle = cpu_to_le16(handle);
|
|
|
|
|
|
|
|
cp.tx_bandwidth = cpu_to_le32(0x00001f40);
|
|
|
|
cp.rx_bandwidth = cpu_to_le32(0x00001f40);
|
|
|
|
|
|
|
|
switch (conn->codec.id) {
|
2021-09-07 10:12:46 +00:00
|
|
|
case BT_CODEC_MSBC:
|
|
|
|
if (!find_next_esco_param(conn, esco_param_msbc,
|
|
|
|
ARRAY_SIZE(esco_param_msbc)))
|
2022-08-05 23:42:31 +00:00
|
|
|
return -EINVAL;
|
2021-09-07 10:12:46 +00:00
|
|
|
|
|
|
|
param = &esco_param_msbc[conn->attempt - 1];
|
|
|
|
cp.tx_coding_format.id = 0x05;
|
|
|
|
cp.rx_coding_format.id = 0x05;
|
|
|
|
cp.tx_codec_frame_size = __cpu_to_le16(60);
|
|
|
|
cp.rx_codec_frame_size = __cpu_to_le16(60);
|
|
|
|
cp.in_bandwidth = __cpu_to_le32(32000);
|
|
|
|
cp.out_bandwidth = __cpu_to_le32(32000);
|
|
|
|
cp.in_coding_format.id = 0x04;
|
|
|
|
cp.out_coding_format.id = 0x04;
|
|
|
|
cp.in_coded_data_size = __cpu_to_le16(16);
|
|
|
|
cp.out_coded_data_size = __cpu_to_le16(16);
|
|
|
|
cp.in_pcm_data_format = 2;
|
|
|
|
cp.out_pcm_data_format = 2;
|
|
|
|
cp.in_pcm_sample_payload_msb_pos = 0;
|
|
|
|
cp.out_pcm_sample_payload_msb_pos = 0;
|
|
|
|
cp.in_data_path = conn->codec.data_path;
|
|
|
|
cp.out_data_path = conn->codec.data_path;
|
|
|
|
cp.in_transport_unit_size = 1;
|
|
|
|
cp.out_transport_unit_size = 1;
|
|
|
|
break;
|
|
|
|
|
2021-09-07 10:12:43 +00:00
|
|
|
case BT_CODEC_TRANSPARENT:
|
|
|
|
if (!find_next_esco_param(conn, esco_param_msbc,
|
|
|
|
ARRAY_SIZE(esco_param_msbc)))
|
|
|
|
return false;
|
|
|
|
param = &esco_param_msbc[conn->attempt - 1];
|
|
|
|
cp.tx_coding_format.id = 0x03;
|
|
|
|
cp.rx_coding_format.id = 0x03;
|
|
|
|
cp.tx_codec_frame_size = __cpu_to_le16(60);
|
|
|
|
cp.rx_codec_frame_size = __cpu_to_le16(60);
|
|
|
|
cp.in_bandwidth = __cpu_to_le32(0x1f40);
|
|
|
|
cp.out_bandwidth = __cpu_to_le32(0x1f40);
|
|
|
|
cp.in_coding_format.id = 0x03;
|
|
|
|
cp.out_coding_format.id = 0x03;
|
|
|
|
cp.in_coded_data_size = __cpu_to_le16(16);
|
|
|
|
cp.out_coded_data_size = __cpu_to_le16(16);
|
|
|
|
cp.in_pcm_data_format = 2;
|
|
|
|
cp.out_pcm_data_format = 2;
|
|
|
|
cp.in_pcm_sample_payload_msb_pos = 0;
|
|
|
|
cp.out_pcm_sample_payload_msb_pos = 0;
|
|
|
|
cp.in_data_path = conn->codec.data_path;
|
|
|
|
cp.out_data_path = conn->codec.data_path;
|
|
|
|
cp.in_transport_unit_size = 1;
|
|
|
|
cp.out_transport_unit_size = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BT_CODEC_CVSD:
|
2023-04-11 23:02:22 +00:00
|
|
|
if (conn->parent && lmp_esco_capable(conn->parent)) {
|
2021-09-07 10:12:43 +00:00
|
|
|
if (!find_next_esco_param(conn, esco_param_cvsd,
|
|
|
|
ARRAY_SIZE(esco_param_cvsd)))
|
2022-08-05 23:42:31 +00:00
|
|
|
return -EINVAL;
|
2021-09-07 10:12:43 +00:00
|
|
|
param = &esco_param_cvsd[conn->attempt - 1];
|
|
|
|
} else {
|
|
|
|
if (conn->attempt > ARRAY_SIZE(sco_param_cvsd))
|
2022-08-05 23:42:31 +00:00
|
|
|
return -EINVAL;
|
2021-09-07 10:12:43 +00:00
|
|
|
param = &sco_param_cvsd[conn->attempt - 1];
|
|
|
|
}
|
|
|
|
cp.tx_coding_format.id = 2;
|
|
|
|
cp.rx_coding_format.id = 2;
|
|
|
|
cp.tx_codec_frame_size = __cpu_to_le16(60);
|
|
|
|
cp.rx_codec_frame_size = __cpu_to_le16(60);
|
|
|
|
cp.in_bandwidth = __cpu_to_le32(16000);
|
|
|
|
cp.out_bandwidth = __cpu_to_le32(16000);
|
|
|
|
cp.in_coding_format.id = 4;
|
|
|
|
cp.out_coding_format.id = 4;
|
|
|
|
cp.in_coded_data_size = __cpu_to_le16(16);
|
|
|
|
cp.out_coded_data_size = __cpu_to_le16(16);
|
|
|
|
cp.in_pcm_data_format = 2;
|
|
|
|
cp.out_pcm_data_format = 2;
|
|
|
|
cp.in_pcm_sample_payload_msb_pos = 0;
|
|
|
|
cp.out_pcm_sample_payload_msb_pos = 0;
|
|
|
|
cp.in_data_path = conn->codec.data_path;
|
|
|
|
cp.out_data_path = conn->codec.data_path;
|
|
|
|
cp.in_transport_unit_size = 16;
|
|
|
|
cp.out_transport_unit_size = 16;
|
|
|
|
break;
|
|
|
|
default:
|
2022-08-05 23:42:31 +00:00
|
|
|
return -EINVAL;
|
2021-09-07 10:12:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cp.retrans_effort = param->retrans_effort;
|
|
|
|
cp.pkt_type = __cpu_to_le16(param->pkt_type);
|
|
|
|
cp.max_latency = __cpu_to_le16(param->max_latency);
|
|
|
|
|
|
|
|
if (hci_send_cmd(hdev, HCI_OP_ENHANCED_SETUP_SYNC_CONN, sizeof(cp), &cp) < 0)
|
2022-08-05 23:42:31 +00:00
|
|
|
return -EIO;
|
2021-09-07 10:12:43 +00:00
|
|
|
|
2022-08-05 23:42:31 +00:00
|
|
|
return 0;
|
2021-09-07 10:12:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool hci_setup_sync_conn(struct hci_conn *conn, __u16 handle)
|
2007-10-20 12:55:10 +00:00
|
|
|
{
|
|
|
|
struct hci_dev *hdev = conn->hdev;
|
|
|
|
struct hci_cp_setup_sync_conn cp;
|
2013-08-19 12:24:03 +00:00
|
|
|
const struct sco_param *param;
|
2007-10-20 12:55:10 +00:00
|
|
|
|
2021-09-07 10:12:43 +00:00
|
|
|
bt_dev_dbg(hdev, "hcon %p", conn);
|
2007-10-20 12:55:10 +00:00
|
|
|
|
|
|
|
conn->state = BT_CONNECT;
|
2012-01-16 07:49:58 +00:00
|
|
|
conn->out = true;
|
2007-10-20 12:55:10 +00:00
|
|
|
|
2009-02-06 08:13:37 +00:00
|
|
|
conn->attempt++;
|
|
|
|
|
2007-10-20 12:55:10 +00:00
|
|
|
cp.handle = cpu_to_le16(handle);
|
|
|
|
|
2014-03-12 17:52:35 +00:00
|
|
|
cp.tx_bandwidth = cpu_to_le32(0x00001f40);
|
|
|
|
cp.rx_bandwidth = cpu_to_le32(0x00001f40);
|
2013-08-19 12:23:59 +00:00
|
|
|
cp.voice_setting = cpu_to_le16(conn->setting);
|
|
|
|
|
|
|
|
switch (conn->setting & SCO_AIRMODE_MASK) {
|
|
|
|
case SCO_AIRMODE_TRANSP:
|
2021-01-29 21:53:48 +00:00
|
|
|
if (!find_next_esco_param(conn, esco_param_msbc,
|
|
|
|
ARRAY_SIZE(esco_param_msbc)))
|
2013-08-19 12:24:03 +00:00
|
|
|
return false;
|
2014-09-25 06:48:01 +00:00
|
|
|
param = &esco_param_msbc[conn->attempt - 1];
|
2013-08-19 12:23:59 +00:00
|
|
|
break;
|
|
|
|
case SCO_AIRMODE_CVSD:
|
2023-04-11 23:02:22 +00:00
|
|
|
if (conn->parent && lmp_esco_capable(conn->parent)) {
|
2021-01-29 21:53:48 +00:00
|
|
|
if (!find_next_esco_param(conn, esco_param_cvsd,
|
|
|
|
ARRAY_SIZE(esco_param_cvsd)))
|
2014-09-23 09:01:07 +00:00
|
|
|
return false;
|
|
|
|
param = &esco_param_cvsd[conn->attempt - 1];
|
|
|
|
} else {
|
|
|
|
if (conn->attempt > ARRAY_SIZE(sco_param_cvsd))
|
|
|
|
return false;
|
|
|
|
param = &sco_param_cvsd[conn->attempt - 1];
|
|
|
|
}
|
2013-08-19 12:23:59 +00:00
|
|
|
break;
|
2013-08-19 12:24:03 +00:00
|
|
|
default:
|
|
|
|
return false;
|
2013-08-19 12:23:59 +00:00
|
|
|
}
|
2007-10-20 12:55:10 +00:00
|
|
|
|
2014-09-24 19:41:46 +00:00
|
|
|
cp.retrans_effort = param->retrans_effort;
|
2013-08-19 12:24:03 +00:00
|
|
|
cp.pkt_type = __cpu_to_le16(param->pkt_type);
|
|
|
|
cp.max_latency = __cpu_to_le16(param->max_latency);
|
|
|
|
|
|
|
|
if (hci_send_cmd(hdev, HCI_OP_SETUP_SYNC_CONN, sizeof(cp), &cp) < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2007-10-20 12:55:10 +00:00
|
|
|
}
|
|
|
|
|
2021-09-07 10:12:43 +00:00
|
|
|
bool hci_setup_sync(struct hci_conn *conn, __u16 handle)
|
|
|
|
{
|
2022-08-05 23:42:31 +00:00
|
|
|
int result;
|
|
|
|
struct conn_handle_t *conn_handle;
|
|
|
|
|
|
|
|
if (enhanced_sync_conn_capable(conn->hdev)) {
|
|
|
|
conn_handle = kzalloc(sizeof(*conn_handle), GFP_KERNEL);
|
|
|
|
|
|
|
|
if (!conn_handle)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
conn_handle->conn = conn;
|
|
|
|
conn_handle->handle = handle;
|
|
|
|
result = hci_cmd_sync_queue(conn->hdev, hci_enhanced_setup_sync,
|
|
|
|
conn_handle, NULL);
|
|
|
|
if (result < 0)
|
|
|
|
kfree(conn_handle);
|
|
|
|
|
|
|
|
return result == 0;
|
|
|
|
}
|
2021-09-07 10:12:43 +00:00
|
|
|
|
|
|
|
return hci_setup_sync_conn(conn, handle);
|
|
|
|
}
|
|
|
|
|
2014-07-02 14:37:31 +00:00
|
|
|
u8 hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max, u16 latency,
|
|
|
|
u16 to_multiplier)
|
2011-02-16 22:44:53 +00:00
|
|
|
{
|
|
|
|
struct hci_dev *hdev = conn->hdev;
|
2014-06-29 14:43:26 +00:00
|
|
|
struct hci_conn_params *params;
|
|
|
|
struct hci_cp_le_conn_update cp;
|
2011-02-16 22:44:53 +00:00
|
|
|
|
2014-06-29 14:43:26 +00:00
|
|
|
hci_dev_lock(hdev);
|
2011-02-16 22:44:53 +00:00
|
|
|
|
2014-06-29 14:43:26 +00:00
|
|
|
params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type);
|
|
|
|
if (params) {
|
|
|
|
params->conn_min_interval = min;
|
|
|
|
params->conn_max_interval = max;
|
|
|
|
params->conn_latency = latency;
|
|
|
|
params->supervision_timeout = to_multiplier;
|
|
|
|
}
|
|
|
|
|
|
|
|
hci_dev_unlock(hdev);
|
|
|
|
|
|
|
|
memset(&cp, 0, sizeof(cp));
|
2011-02-16 22:44:53 +00:00
|
|
|
cp.handle = cpu_to_le16(conn->handle);
|
|
|
|
cp.conn_interval_min = cpu_to_le16(min);
|
|
|
|
cp.conn_interval_max = cpu_to_le16(max);
|
|
|
|
cp.conn_latency = cpu_to_le16(latency);
|
|
|
|
cp.supervision_timeout = cpu_to_le16(to_multiplier);
|
2014-03-12 17:52:35 +00:00
|
|
|
cp.min_ce_len = cpu_to_le16(0x0000);
|
|
|
|
cp.max_ce_len = cpu_to_le16(0x0000);
|
2011-02-16 22:44:53 +00:00
|
|
|
|
|
|
|
hci_send_cmd(hdev, HCI_OP_LE_CONN_UPDATE, sizeof(cp), &cp);
|
2014-07-02 14:37:31 +00:00
|
|
|
|
|
|
|
if (params)
|
|
|
|
return 0x01;
|
|
|
|
|
|
|
|
return 0x00;
|
2011-02-16 22:44:53 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 00:00:28 +00:00
|
|
|
void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __le64 rand,
|
2015-06-08 15:14:39 +00:00
|
|
|
__u8 ltk[16], __u8 key_size)
|
2011-06-09 21:50:47 +00:00
|
|
|
{
|
|
|
|
struct hci_dev *hdev = conn->hdev;
|
|
|
|
struct hci_cp_le_start_enc cp;
|
|
|
|
|
2012-06-15 08:50:28 +00:00
|
|
|
BT_DBG("hcon %p", conn);
|
2011-06-09 21:50:47 +00:00
|
|
|
|
|
|
|
memset(&cp, 0, sizeof(cp));
|
|
|
|
|
|
|
|
cp.handle = cpu_to_le16(conn->handle);
|
2014-02-28 00:00:28 +00:00
|
|
|
cp.rand = rand;
|
2011-06-09 21:50:47 +00:00
|
|
|
cp.ediv = ediv;
|
2015-06-08 15:14:39 +00:00
|
|
|
memcpy(cp.ltk, ltk, key_size);
|
2011-06-09 21:50:47 +00:00
|
|
|
|
|
|
|
hci_send_cmd(hdev, HCI_OP_LE_START_ENC, sizeof(cp), &cp);
|
|
|
|
}
|
|
|
|
|
2010-07-26 14:06:00 +00:00
|
|
|
/* Device _must_ be locked */
|
|
|
|
void hci_sco_setup(struct hci_conn *conn, __u8 status)
|
|
|
|
{
|
2023-04-11 23:02:22 +00:00
|
|
|
struct hci_link *link;
|
2010-07-26 14:06:00 +00:00
|
|
|
|
2023-04-11 23:02:22 +00:00
|
|
|
link = list_first_entry_or_null(&conn->link_list, struct hci_link, list);
|
|
|
|
if (!link || !link->conn)
|
2010-07-26 14:06:00 +00:00
|
|
|
return;
|
|
|
|
|
2012-06-15 08:50:28 +00:00
|
|
|
BT_DBG("hcon %p", conn);
|
|
|
|
|
2010-07-26 14:06:00 +00:00
|
|
|
if (!status) {
|
|
|
|
if (lmp_esco_capable(conn->hdev))
|
2023-04-11 23:02:22 +00:00
|
|
|
hci_setup_sync(link->conn, conn->handle);
|
2010-07-26 14:06:00 +00:00
|
|
|
else
|
2023-04-11 23:02:22 +00:00
|
|
|
hci_add_sco(link->conn, conn->handle);
|
2010-07-26 14:06:00 +00:00
|
|
|
} else {
|
2023-04-11 23:02:22 +00:00
|
|
|
hci_connect_cfm(link->conn, status);
|
|
|
|
hci_conn_del(link->conn);
|
2010-07-26 14:06:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-17 16:03:21 +00:00
|
|
|
static void hci_conn_timeout(struct work_struct *work)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2011-06-17 16:03:21 +00:00
|
|
|
struct hci_conn *conn = container_of(work, struct hci_conn,
|
2012-05-17 03:36:25 +00:00
|
|
|
disc_work.work);
|
Bluetooth: Fix for ACL disconnect when pairing fails
When pairing fails hci_conn refcnt drops below zero. This cause that
ACL link is not disconnected when disconnect timeout fires.
Probably this is because l2cap_conn_del calls l2cap_chan_del for each
channel, and inside l2cap_chan_del conn is dropped. After that loop
hci_chan_del is called which also drops conn.
Anyway, as it is desrcibed in hci_core.h, it is known that refcnt
drops below 0 sometimes and it should be fine. If so, let disconnect
link when hci_conn_timeout fires and refcnt is 0 or below. This patch
does it.
This affects PTS test SM_TC_JW_BV_05_C
Logs from scenario:
[69713.706227] [6515] pair_device:
[69713.706230] [6515] hci_conn_add: hci0 dst 00:1b:dc:06:06:22
[69713.706233] [6515] hci_dev_hold: hci0 orig refcnt 8
[69713.706235] [6515] hci_conn_init_sysfs: conn ffff88021f65a000
[69713.706239] [6515] hci_req_add_ev: hci0 opcode 0x200d plen 25
[69713.706242] [6515] hci_prepare_cmd: skb len 28
[69713.706243] [6515] hci_req_run: length 1
[69713.706248] [6515] hci_conn_hold: hcon ffff88021f65a000 orig refcnt 0
[69713.706251] [6515] hci_dev_put: hci0 orig refcnt 9
[69713.706281] [8909] hci_cmd_work: hci0 cmd_cnt 1 cmd queued 1
[69713.706288] [8909] hci_send_frame: hci0 type 1 len 28
[69713.706290] [8909] hci_send_to_monitor: hdev ffff88021f0c7000 len 28
[69713.706316] [5949] hci_sock_recvmsg: sock ffff8800941a9680, sk ffff88012bf4d000
[69713.706382] [5949] hci_sock_recvmsg: sock ffff8800941a9680, sk ffff88012bf4d000
[69713.711664] [8909] hci_rx_work: hci0
[69713.711668] [8909] hci_send_to_monitor: hdev ffff88021f0c7000 len 6
[69713.711680] [8909] hci_rx_work: hci0 Event packet
[69713.711683] [8909] hci_cs_le_create_conn: hci0 status 0x00
[69713.711685] [8909] hci_sent_cmd_data: hci0 opcode 0x200d
[69713.711688] [8909] hci_req_cmd_complete: opcode 0x200d status 0x00
[69713.711690] [8909] hci_sent_cmd_data: hci0 opcode 0x200d
[69713.711695] [5949] hci_sock_recvmsg: sock ffff8800941a9680, sk ffff88012bf4d000
[69713.711744] [5949] hci_sock_recvmsg: sock ffff8800941a9680, sk ffff88012bf4d000
[69713.818875] [8909] hci_rx_work: hci0
[69713.818889] [8909] hci_send_to_monitor: hdev ffff88021f0c7000 len 21
[69713.818913] [8909] hci_rx_work: hci0 Event packet
[69713.818917] [8909] hci_le_conn_complete_evt: hci0 status 0x00
[69713.818922] [8909] hci_send_to_control: len 19
[69713.818927] [5949] hci_sock_recvmsg: sock ffff8800941a9680, sk ffff88012bf4d000
[69713.818938] [8909] hci_conn_add_sysfs: conn ffff88021f65a000
[69713.818975] [6450] bt_sock_poll: sock ffff88005e758500, sk ffff88010323b800
[69713.818981] [6515] hci_sock_recvmsg: sock ffff88005e75a080, sk ffff88010323ac00
...
[69713.819021] [8909] hci_dev_hold: hci0 orig refcnt 10
[69713.819025] [8909] l2cap_connect_cfm: hcon ffff88021f65a000 bdaddr 00:1b:dc:06:06:22 status 0
[69713.819028] [8909] hci_chan_create: hci0 hcon ffff88021f65a000
[69713.819031] [8909] l2cap_conn_add: hcon ffff88021f65a000 conn ffff880221005c00 hchan ffff88020d60b1c0
[69713.819034] [8909] l2cap_conn_ready: conn ffff880221005c00
[69713.819036] [5949] hci_sock_recvmsg: sock ffff8800941a9680, sk ffff88012bf4d000
[69713.819037] [8909] smp_conn_security: conn ffff880221005c00 hcon ffff88021f65a000 level 0x02
[69713.819039] [8909] smp_chan_create:
[69713.819041] [8909] hci_conn_hold: hcon ffff88021f65a000 orig refcnt 1
[69713.819043] [8909] smp_send_cmd: code 0x01
[69713.819045] [8909] hci_send_acl: hci0 chan ffff88020d60b1c0 flags 0x0000
[69713.819046] [5949] hci_sock_recvmsg: sock ffff8800941a9900, sk ffff88012bf4e800
[69713.819049] [8909] hci_queue_acl: hci0 nonfrag skb ffff88005157c100 len 15
[69713.819055] [5949] hci_sock_recvmsg: sock ffff8800941a9900, sk ffff88012bf4e800
[69713.819057] [8909] l2cap_le_conn_ready:
[69713.819064] [8909] l2cap_chan_create: chan ffff88005ede2c00
[69713.819066] [8909] l2cap_chan_hold: chan ffff88005ede2c00 orig refcnt 1
[69713.819069] [8909] l2cap_sock_init: sk ffff88005ede5800
[69713.819072] [8909] bt_accept_enqueue: parent ffff880160356000, sk ffff88005ede5800
[69713.819074] [8909] __l2cap_chan_add: conn ffff880221005c00, psm 0x00, dcid 0x0004
[69713.819076] [8909] l2cap_chan_hold: chan ffff88005ede2c00 orig refcnt 2
[69713.819078] [8909] hci_conn_hold: hcon ffff88021f65a000 orig refcnt 2
[69713.819080] [8909] smp_conn_security: conn ffff880221005c00 hcon ffff88021f65a000 level 0x01
[69713.819082] [8909] l2cap_sock_ready_cb: sk ffff88005ede5800, parent ffff880160356000
[69713.819086] [8909] le_pairing_complete_cb: status 0
[69713.819091] [8909] hci_tx_work: hci0 acl 10 sco 8 le 0
[69713.819093] [8909] hci_sched_acl: hci0
[69713.819094] [8909] hci_sched_sco: hci0
[69713.819096] [8909] hci_sched_esco: hci0
[69713.819098] [8909] hci_sched_le: hci0
[69713.819099] [8909] hci_chan_sent: hci0
[69713.819101] [8909] hci_chan_sent: chan ffff88020d60b1c0 quote 10
[69713.819104] [8909] hci_sched_le: chan ffff88020d60b1c0 skb ffff88005157c100 len 15 priority 7
[69713.819106] [8909] hci_send_frame: hci0 type 2 len 15
[69713.819108] [8909] hci_send_to_monitor: hdev ffff88021f0c7000 len 15
[69713.819119] [8909] hci_chan_sent: hci0
[69713.819121] [8909] hci_prio_recalculate: hci0
[69713.819123] [8909] process_pending_rx:
[69713.819226] [6450] hci_sock_recvmsg: sock ffff88005e758780, sk ffff88010323d400
...
[69713.822022] [6450] l2cap_sock_accept: sk ffff880160356000 timeo 0
[69713.822024] [6450] bt_accept_dequeue: parent ffff880160356000
[69713.822026] [6450] bt_accept_unlink: sk ffff88005ede5800 state 1
[69713.822028] [6450] l2cap_sock_accept: new socket ffff88005ede5800
[69713.822368] [6450] l2cap_sock_getname: sock ffff8800941ab700, sk ffff88005ede5800
[69713.822375] [6450] l2cap_sock_getsockopt: sk ffff88005ede5800
[69713.822383] [6450] l2cap_sock_getname: sock ffff8800941ab700, sk ffff88005ede5800
[69713.822414] [6450] bt_sock_poll: sock ffff8800941ab700, sk ffff88005ede5800
...
[69713.823255] [6450] l2cap_sock_getname: sock ffff8800941ab700, sk ffff88005ede5800
[69713.823259] [6450] l2cap_sock_getsockopt: sk ffff88005ede5800
[69713.824322] [6450] l2cap_sock_getname: sock ffff8800941ab700, sk ffff88005ede5800
[69713.824330] [6450] l2cap_sock_getsockopt: sk ffff88005ede5800
[69713.825029] [6450] bt_sock_poll: sock ffff88005e758500, sk ffff88010323b800
...
[69713.825187] [6450] l2cap_sock_sendmsg: sock ffff8800941ab700, sk ffff88005ede5800
[69713.825189] [6450] bt_sock_wait_ready: sk ffff88005ede5800
[69713.825192] [6450] l2cap_create_basic_pdu: chan ffff88005ede2c00 len 3
[69713.825196] [6450] l2cap_do_send: chan ffff88005ede2c00, skb ffff880160b0b500 len 7 priority 0
[69713.825199] [6450] hci_send_acl: hci0 chan ffff88020d60b1c0 flags 0x0000
[69713.825201] [6450] hci_queue_acl: hci0 nonfrag skb ffff880160b0b500 len 11
[69713.825210] [8909] hci_tx_work: hci0 acl 9 sco 8 le 0
[69713.825213] [8909] hci_sched_acl: hci0
[69713.825214] [8909] hci_sched_sco: hci0
[69713.825216] [8909] hci_sched_esco: hci0
[69713.825217] [8909] hci_sched_le: hci0
[69713.825219] [8909] hci_chan_sent: hci0
[69713.825221] [8909] hci_chan_sent: chan ffff88020d60b1c0 quote 9
[69713.825223] [8909] hci_sched_le: chan ffff88020d60b1c0 skb ffff880160b0b500 len 11 priority 0
[69713.825225] [8909] hci_send_frame: hci0 type 2 len 11
[69713.825227] [8909] hci_send_to_monitor: hdev ffff88021f0c7000 len 11
[69713.825242] [8909] hci_chan_sent: hci0
[69713.825253] [5949] hci_sock_recvmsg: sock ffff8800941a9680, sk ffff88012bf4d000
[69713.825253] [8909] hci_prio_recalculate: hci0
[69713.825292] [5949] hci_sock_recvmsg: sock ffff8800941a9680, sk ffff88012bf4d000
[69713.825768] [6450] bt_sock_poll: sock ffff88005e758500, sk ffff88010323b800
...
[69713.866902] [8909] hci_rx_work: hci0
[69713.866921] [8909] hci_send_to_monitor: hdev ffff88021f0c7000 len 7
[69713.866928] [8909] hci_rx_work: hci0 Event packet
[69713.866931] [8909] hci_num_comp_pkts_evt: hci0 num_hndl 1
[69713.866937] [8909] hci_tx_work: hci0 acl 9 sco 8 le 0
[69713.866939] [5949] hci_sock_recvmsg: sock ffff8800941a9680, sk ffff88012bf4d000
[69713.866940] [8909] hci_sched_acl: hci0
...
[69713.866944] [8909] hci_sched_le: hci0
[69713.866953] [8909] hci_chan_sent: hci0
[69713.866997] [5949] hci_sock_recvmsg: sock ffff8800941a9680, sk ffff88012bf4d000
[69713.867840] [28074] hci_rx_work: hci0
[69713.867844] [28074] hci_send_to_monitor: hdev ffff88021f0c7000 len 7
[69713.867850] [28074] hci_rx_work: hci0 Event packet
[69713.867853] [28074] hci_num_comp_pkts_evt: hci0 num_hndl 1
[69713.867857] [5949] hci_sock_recvmsg: sock ffff8800941a9680, sk ffff88012bf4d000
[69713.867858] [28074] hci_tx_work: hci0 acl 10 sco 8 le 0
[69713.867860] [28074] hci_sched_acl: hci0
[69713.867861] [28074] hci_sched_sco: hci0
[69713.867862] [28074] hci_sched_esco: hci0
[69713.867863] [28074] hci_sched_le: hci0
[69713.867865] [28074] hci_chan_sent: hci0
[69713.867888] [5949] hci_sock_recvmsg: sock ffff8800941a9680, sk ffff88012bf4d000
[69714.145661] [8909] hci_rx_work: hci0
[69714.145666] [8909] hci_send_to_monitor: hdev ffff88021f0c7000 len 10
[69714.145676] [8909] hci_rx_work: hci0 ACL data packet
[69714.145679] [8909] hci_acldata_packet: hci0 len 6 handle 0x002d flags 0x0002
[69714.145681] [8909] hci_conn_enter_active_mode: hcon ffff88021f65a000 mode 0
[69714.145683] [8909] l2cap_recv_acldata: conn ffff880221005c00 len 6 flags 0x2
[69714.145693] [8909] l2cap_recv_frame: len 2, cid 0x0006
[69714.145696] [8909] hci_send_to_control: len 14
[69714.145710] [8909] smp_chan_destroy:
[69714.145713] [8909] pairing_complete: status 3
[69714.145714] [8909] cmd_complete: sock ffff88010323ac00
[69714.145717] [8909] hci_conn_drop: hcon ffff88021f65a000 orig refcnt 3
[69714.145719] [5949] hci_sock_recvmsg: sock ffff8800941a9680, sk ffff88012bf4d000
[69714.145720] [6450] bt_sock_poll: sock ffff88005e758500, sk ffff88010323b800
[69714.145722] [6515] hci_sock_recvmsg: sock ffff88005e75a080, sk ffff88010323ac00
[69714.145724] [6450] bt_sock_poll: sock ffff8801db6b4f00, sk ffff880160351c00
...
[69714.145735] [6515] hci_sock_recvmsg: sock ffff88005e75a080, sk ffff88010323ac00
[69714.145737] [8909] hci_conn_drop: hcon ffff88021f65a000 orig refcnt 2
[69714.145739] [8909] l2cap_conn_del: hcon ffff88021f65a000 conn ffff880221005c00, err 13
[69714.145740] [6450] bt_sock_poll: sock ffff8801db6b5400, sk ffff88021e775000
[69714.145743] [6450] bt_sock_poll: sock ffff8801db6b5e00, sk ffff880160356000
[69714.145744] [8909] l2cap_chan_hold: chan ffff88005ede2c00 orig refcnt 3
[69714.145746] [6450] bt_sock_poll: sock ffff8800941ab700, sk ffff88005ede5800
[69714.145748] [8909] l2cap_chan_del: chan ffff88005ede2c00, conn ffff880221005c00, err 13
[69714.145749] [8909] l2cap_chan_put: chan ffff88005ede2c00 orig refcnt 4
[69714.145751] [8909] hci_conn_drop: hcon ffff88021f65a000 orig refcnt 1
[69714.145754] [6450] bt_sock_poll: sock ffff8800941ab700, sk ffff88005ede5800
[69714.145756] [8909] l2cap_chan_put: chan ffff88005ede2c00 orig refcnt 3
[69714.145759] [8909] hci_chan_del: hci0 hcon ffff88021f65a000 chan ffff88020d60b1c0
[69714.145766] [5949] hci_sock_recvmsg: sock ffff8800941a9680, sk ffff88012bf4d000
[69714.145787] [6515] hci_sock_release: sock ffff88005e75a080 sk ffff88010323ac00
[69714.146002] [6450] hci_sock_recvmsg: sock ffff88005e758780, sk ffff88010323d400
[69714.150795] [6450] l2cap_sock_release: sock ffff8800941ab700, sk ffff88005ede5800
[69714.150799] [6450] l2cap_sock_shutdown: sock ffff8800941ab700, sk ffff88005ede5800
[69714.150802] [6450] l2cap_chan_close: chan ffff88005ede2c00 state BT_CLOSED
[69714.150805] [6450] l2cap_sock_kill: sk ffff88005ede5800 state BT_CLOSED
[69714.150806] [6450] l2cap_chan_put: chan ffff88005ede2c00 orig refcnt 2
[69714.150808] [6450] l2cap_sock_destruct: sk ffff88005ede5800
[69714.150809] [6450] l2cap_chan_put: chan ffff88005ede2c00 orig refcnt 1
[69714.150811] [6450] l2cap_chan_destroy: chan ffff88005ede2c00
[69714.150970] [6450] bt_sock_poll: sock ffff88005e758500, sk ffff88010323b800
...
[69714.151991] [8909] hci_conn_drop: hcon ffff88021f65a000 orig refcnt 0
[69716.150339] [8909] hci_conn_timeout: hcon ffff88021f65a000 state BT_CONNECTED, refcnt -1
Signed-off-by: Lukasz Rymanowski <lukasz.rymanowski@tieto.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2014-06-17 11:04:20 +00:00
|
|
|
int refcnt = atomic_read(&conn->refcnt);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-06-15 08:50:28 +00:00
|
|
|
BT_DBG("hcon %p state %s", conn, state_to_string(conn->state));
|
2005-04-16 22:20:36 +00:00
|
|
|
|
Bluetooth: Fix for ACL disconnect when pairing fails
When pairing fails hci_conn refcnt drops below zero. This cause that
ACL link is not disconnected when disconnect timeout fires.
Probably this is because l2cap_conn_del calls l2cap_chan_del for each
channel, and inside l2cap_chan_del conn is dropped. After that loop
hci_chan_del is called which also drops conn.
Anyway, as it is desrcibed in hci_core.h, it is known that refcnt
drops below 0 sometimes and it should be fine. If so, let disconnect
link when hci_conn_timeout fires and refcnt is 0 or below. This patch
does it.
This affects PTS test SM_TC_JW_BV_05_C
Logs from scenario:
[69713.706227] [6515] pair_device:
[69713.706230] [6515] hci_conn_add: hci0 dst 00:1b:dc:06:06:22
[69713.706233] [6515] hci_dev_hold: hci0 orig refcnt 8
[69713.706235] [6515] hci_conn_init_sysfs: conn ffff88021f65a000
[69713.706239] [6515] hci_req_add_ev: hci0 opcode 0x200d plen 25
[69713.706242] [6515] hci_prepare_cmd: skb len 28
[69713.706243] [6515] hci_req_run: length 1
[69713.706248] [6515] hci_conn_hold: hcon ffff88021f65a000 orig refcnt 0
[69713.706251] [6515] hci_dev_put: hci0 orig refcnt 9
[69713.706281] [8909] hci_cmd_work: hci0 cmd_cnt 1 cmd queued 1
[69713.706288] [8909] hci_send_frame: hci0 type 1 len 28
[69713.706290] [8909] hci_send_to_monitor: hdev ffff88021f0c7000 len 28
[69713.706316] [5949] hci_sock_recvmsg: sock ffff8800941a9680, sk ffff88012bf4d000
[69713.706382] [5949] hci_sock_recvmsg: sock ffff8800941a9680, sk ffff88012bf4d000
[69713.711664] [8909] hci_rx_work: hci0
[69713.711668] [8909] hci_send_to_monitor: hdev ffff88021f0c7000 len 6
[69713.711680] [8909] hci_rx_work: hci0 Event packet
[69713.711683] [8909] hci_cs_le_create_conn: hci0 status 0x00
[69713.711685] [8909] hci_sent_cmd_data: hci0 opcode 0x200d
[69713.711688] [8909] hci_req_cmd_complete: opcode 0x200d status 0x00
[69713.711690] [8909] hci_sent_cmd_data: hci0 opcode 0x200d
[69713.711695] [5949] hci_sock_recvmsg: sock ffff8800941a9680, sk ffff88012bf4d000
[69713.711744] [5949] hci_sock_recvmsg: sock ffff8800941a9680, sk ffff88012bf4d000
[69713.818875] [8909] hci_rx_work: hci0
[69713.818889] [8909] hci_send_to_monitor: hdev ffff88021f0c7000 len 21
[69713.818913] [8909] hci_rx_work: hci0 Event packet
[69713.818917] [8909] hci_le_conn_complete_evt: hci0 status 0x00
[69713.818922] [8909] hci_send_to_control: len 19
[69713.818927] [5949] hci_sock_recvmsg: sock ffff8800941a9680, sk ffff88012bf4d000
[69713.818938] [8909] hci_conn_add_sysfs: conn ffff88021f65a000
[69713.818975] [6450] bt_sock_poll: sock ffff88005e758500, sk ffff88010323b800
[69713.818981] [6515] hci_sock_recvmsg: sock ffff88005e75a080, sk ffff88010323ac00
...
[69713.819021] [8909] hci_dev_hold: hci0 orig refcnt 10
[69713.819025] [8909] l2cap_connect_cfm: hcon ffff88021f65a000 bdaddr 00:1b:dc:06:06:22 status 0
[69713.819028] [8909] hci_chan_create: hci0 hcon ffff88021f65a000
[69713.819031] [8909] l2cap_conn_add: hcon ffff88021f65a000 conn ffff880221005c00 hchan ffff88020d60b1c0
[69713.819034] [8909] l2cap_conn_ready: conn ffff880221005c00
[69713.819036] [5949] hci_sock_recvmsg: sock ffff8800941a9680, sk ffff88012bf4d000
[69713.819037] [8909] smp_conn_security: conn ffff880221005c00 hcon ffff88021f65a000 level 0x02
[69713.819039] [8909] smp_chan_create:
[69713.819041] [8909] hci_conn_hold: hcon ffff88021f65a000 orig refcnt 1
[69713.819043] [8909] smp_send_cmd: code 0x01
[69713.819045] [8909] hci_send_acl: hci0 chan ffff88020d60b1c0 flags 0x0000
[69713.819046] [5949] hci_sock_recvmsg: sock ffff8800941a9900, sk ffff88012bf4e800
[69713.819049] [8909] hci_queue_acl: hci0 nonfrag skb ffff88005157c100 len 15
[69713.819055] [5949] hci_sock_recvmsg: sock ffff8800941a9900, sk ffff88012bf4e800
[69713.819057] [8909] l2cap_le_conn_ready:
[69713.819064] [8909] l2cap_chan_create: chan ffff88005ede2c00
[69713.819066] [8909] l2cap_chan_hold: chan ffff88005ede2c00 orig refcnt 1
[69713.819069] [8909] l2cap_sock_init: sk ffff88005ede5800
[69713.819072] [8909] bt_accept_enqueue: parent ffff880160356000, sk ffff88005ede5800
[69713.819074] [8909] __l2cap_chan_add: conn ffff880221005c00, psm 0x00, dcid 0x0004
[69713.819076] [8909] l2cap_chan_hold: chan ffff88005ede2c00 orig refcnt 2
[69713.819078] [8909] hci_conn_hold: hcon ffff88021f65a000 orig refcnt 2
[69713.819080] [8909] smp_conn_security: conn ffff880221005c00 hcon ffff88021f65a000 level 0x01
[69713.819082] [8909] l2cap_sock_ready_cb: sk ffff88005ede5800, parent ffff880160356000
[69713.819086] [8909] le_pairing_complete_cb: status 0
[69713.819091] [8909] hci_tx_work: hci0 acl 10 sco 8 le 0
[69713.819093] [8909] hci_sched_acl: hci0
[69713.819094] [8909] hci_sched_sco: hci0
[69713.819096] [8909] hci_sched_esco: hci0
[69713.819098] [8909] hci_sched_le: hci0
[69713.819099] [8909] hci_chan_sent: hci0
[69713.819101] [8909] hci_chan_sent: chan ffff88020d60b1c0 quote 10
[69713.819104] [8909] hci_sched_le: chan ffff88020d60b1c0 skb ffff88005157c100 len 15 priority 7
[69713.819106] [8909] hci_send_frame: hci0 type 2 len 15
[69713.819108] [8909] hci_send_to_monitor: hdev ffff88021f0c7000 len 15
[69713.819119] [8909] hci_chan_sent: hci0
[69713.819121] [8909] hci_prio_recalculate: hci0
[69713.819123] [8909] process_pending_rx:
[69713.819226] [6450] hci_sock_recvmsg: sock ffff88005e758780, sk ffff88010323d400
...
[69713.822022] [6450] l2cap_sock_accept: sk ffff880160356000 timeo 0
[69713.822024] [6450] bt_accept_dequeue: parent ffff880160356000
[69713.822026] [6450] bt_accept_unlink: sk ffff88005ede5800 state 1
[69713.822028] [6450] l2cap_sock_accept: new socket ffff88005ede5800
[69713.822368] [6450] l2cap_sock_getname: sock ffff8800941ab700, sk ffff88005ede5800
[69713.822375] [6450] l2cap_sock_getsockopt: sk ffff88005ede5800
[69713.822383] [6450] l2cap_sock_getname: sock ffff8800941ab700, sk ffff88005ede5800
[69713.822414] [6450] bt_sock_poll: sock ffff8800941ab700, sk ffff88005ede5800
...
[69713.823255] [6450] l2cap_sock_getname: sock ffff8800941ab700, sk ffff88005ede5800
[69713.823259] [6450] l2cap_sock_getsockopt: sk ffff88005ede5800
[69713.824322] [6450] l2cap_sock_getname: sock ffff8800941ab700, sk ffff88005ede5800
[69713.824330] [6450] l2cap_sock_getsockopt: sk ffff88005ede5800
[69713.825029] [6450] bt_sock_poll: sock ffff88005e758500, sk ffff88010323b800
...
[69713.825187] [6450] l2cap_sock_sendmsg: sock ffff8800941ab700, sk ffff88005ede5800
[69713.825189] [6450] bt_sock_wait_ready: sk ffff88005ede5800
[69713.825192] [6450] l2cap_create_basic_pdu: chan ffff88005ede2c00 len 3
[69713.825196] [6450] l2cap_do_send: chan ffff88005ede2c00, skb ffff880160b0b500 len 7 priority 0
[69713.825199] [6450] hci_send_acl: hci0 chan ffff88020d60b1c0 flags 0x0000
[69713.825201] [6450] hci_queue_acl: hci0 nonfrag skb ffff880160b0b500 len 11
[69713.825210] [8909] hci_tx_work: hci0 acl 9 sco 8 le 0
[69713.825213] [8909] hci_sched_acl: hci0
[69713.825214] [8909] hci_sched_sco: hci0
[69713.825216] [8909] hci_sched_esco: hci0
[69713.825217] [8909] hci_sched_le: hci0
[69713.825219] [8909] hci_chan_sent: hci0
[69713.825221] [8909] hci_chan_sent: chan ffff88020d60b1c0 quote 9
[69713.825223] [8909] hci_sched_le: chan ffff88020d60b1c0 skb ffff880160b0b500 len 11 priority 0
[69713.825225] [8909] hci_send_frame: hci0 type 2 len 11
[69713.825227] [8909] hci_send_to_monitor: hdev ffff88021f0c7000 len 11
[69713.825242] [8909] hci_chan_sent: hci0
[69713.825253] [5949] hci_sock_recvmsg: sock ffff8800941a9680, sk ffff88012bf4d000
[69713.825253] [8909] hci_prio_recalculate: hci0
[69713.825292] [5949] hci_sock_recvmsg: sock ffff8800941a9680, sk ffff88012bf4d000
[69713.825768] [6450] bt_sock_poll: sock ffff88005e758500, sk ffff88010323b800
...
[69713.866902] [8909] hci_rx_work: hci0
[69713.866921] [8909] hci_send_to_monitor: hdev ffff88021f0c7000 len 7
[69713.866928] [8909] hci_rx_work: hci0 Event packet
[69713.866931] [8909] hci_num_comp_pkts_evt: hci0 num_hndl 1
[69713.866937] [8909] hci_tx_work: hci0 acl 9 sco 8 le 0
[69713.866939] [5949] hci_sock_recvmsg: sock ffff8800941a9680, sk ffff88012bf4d000
[69713.866940] [8909] hci_sched_acl: hci0
...
[69713.866944] [8909] hci_sched_le: hci0
[69713.866953] [8909] hci_chan_sent: hci0
[69713.866997] [5949] hci_sock_recvmsg: sock ffff8800941a9680, sk ffff88012bf4d000
[69713.867840] [28074] hci_rx_work: hci0
[69713.867844] [28074] hci_send_to_monitor: hdev ffff88021f0c7000 len 7
[69713.867850] [28074] hci_rx_work: hci0 Event packet
[69713.867853] [28074] hci_num_comp_pkts_evt: hci0 num_hndl 1
[69713.867857] [5949] hci_sock_recvmsg: sock ffff8800941a9680, sk ffff88012bf4d000
[69713.867858] [28074] hci_tx_work: hci0 acl 10 sco 8 le 0
[69713.867860] [28074] hci_sched_acl: hci0
[69713.867861] [28074] hci_sched_sco: hci0
[69713.867862] [28074] hci_sched_esco: hci0
[69713.867863] [28074] hci_sched_le: hci0
[69713.867865] [28074] hci_chan_sent: hci0
[69713.867888] [5949] hci_sock_recvmsg: sock ffff8800941a9680, sk ffff88012bf4d000
[69714.145661] [8909] hci_rx_work: hci0
[69714.145666] [8909] hci_send_to_monitor: hdev ffff88021f0c7000 len 10
[69714.145676] [8909] hci_rx_work: hci0 ACL data packet
[69714.145679] [8909] hci_acldata_packet: hci0 len 6 handle 0x002d flags 0x0002
[69714.145681] [8909] hci_conn_enter_active_mode: hcon ffff88021f65a000 mode 0
[69714.145683] [8909] l2cap_recv_acldata: conn ffff880221005c00 len 6 flags 0x2
[69714.145693] [8909] l2cap_recv_frame: len 2, cid 0x0006
[69714.145696] [8909] hci_send_to_control: len 14
[69714.145710] [8909] smp_chan_destroy:
[69714.145713] [8909] pairing_complete: status 3
[69714.145714] [8909] cmd_complete: sock ffff88010323ac00
[69714.145717] [8909] hci_conn_drop: hcon ffff88021f65a000 orig refcnt 3
[69714.145719] [5949] hci_sock_recvmsg: sock ffff8800941a9680, sk ffff88012bf4d000
[69714.145720] [6450] bt_sock_poll: sock ffff88005e758500, sk ffff88010323b800
[69714.145722] [6515] hci_sock_recvmsg: sock ffff88005e75a080, sk ffff88010323ac00
[69714.145724] [6450] bt_sock_poll: sock ffff8801db6b4f00, sk ffff880160351c00
...
[69714.145735] [6515] hci_sock_recvmsg: sock ffff88005e75a080, sk ffff88010323ac00
[69714.145737] [8909] hci_conn_drop: hcon ffff88021f65a000 orig refcnt 2
[69714.145739] [8909] l2cap_conn_del: hcon ffff88021f65a000 conn ffff880221005c00, err 13
[69714.145740] [6450] bt_sock_poll: sock ffff8801db6b5400, sk ffff88021e775000
[69714.145743] [6450] bt_sock_poll: sock ffff8801db6b5e00, sk ffff880160356000
[69714.145744] [8909] l2cap_chan_hold: chan ffff88005ede2c00 orig refcnt 3
[69714.145746] [6450] bt_sock_poll: sock ffff8800941ab700, sk ffff88005ede5800
[69714.145748] [8909] l2cap_chan_del: chan ffff88005ede2c00, conn ffff880221005c00, err 13
[69714.145749] [8909] l2cap_chan_put: chan ffff88005ede2c00 orig refcnt 4
[69714.145751] [8909] hci_conn_drop: hcon ffff88021f65a000 orig refcnt 1
[69714.145754] [6450] bt_sock_poll: sock ffff8800941ab700, sk ffff88005ede5800
[69714.145756] [8909] l2cap_chan_put: chan ffff88005ede2c00 orig refcnt 3
[69714.145759] [8909] hci_chan_del: hci0 hcon ffff88021f65a000 chan ffff88020d60b1c0
[69714.145766] [5949] hci_sock_recvmsg: sock ffff8800941a9680, sk ffff88012bf4d000
[69714.145787] [6515] hci_sock_release: sock ffff88005e75a080 sk ffff88010323ac00
[69714.146002] [6450] hci_sock_recvmsg: sock ffff88005e758780, sk ffff88010323d400
[69714.150795] [6450] l2cap_sock_release: sock ffff8800941ab700, sk ffff88005ede5800
[69714.150799] [6450] l2cap_sock_shutdown: sock ffff8800941ab700, sk ffff88005ede5800
[69714.150802] [6450] l2cap_chan_close: chan ffff88005ede2c00 state BT_CLOSED
[69714.150805] [6450] l2cap_sock_kill: sk ffff88005ede5800 state BT_CLOSED
[69714.150806] [6450] l2cap_chan_put: chan ffff88005ede2c00 orig refcnt 2
[69714.150808] [6450] l2cap_sock_destruct: sk ffff88005ede5800
[69714.150809] [6450] l2cap_chan_put: chan ffff88005ede2c00 orig refcnt 1
[69714.150811] [6450] l2cap_chan_destroy: chan ffff88005ede2c00
[69714.150970] [6450] bt_sock_poll: sock ffff88005e758500, sk ffff88010323b800
...
[69714.151991] [8909] hci_conn_drop: hcon ffff88021f65a000 orig refcnt 0
[69716.150339] [8909] hci_conn_timeout: hcon ffff88021f65a000 state BT_CONNECTED, refcnt -1
Signed-off-by: Lukasz Rymanowski <lukasz.rymanowski@tieto.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2014-06-17 11:04:20 +00:00
|
|
|
WARN_ON(refcnt < 0);
|
|
|
|
|
|
|
|
/* FIXME: It was observed that in pairing failed scenario, refcnt
|
|
|
|
* drops below 0. Probably this is because l2cap_conn_del calls
|
|
|
|
* l2cap_chan_del for each channel, and inside l2cap_chan_del conn is
|
|
|
|
* dropped. After that loop hci_chan_del is called which also drops
|
|
|
|
* conn. For now make sure that ACL is alive if refcnt is higher then 0,
|
|
|
|
* otherwise drop it.
|
|
|
|
*/
|
|
|
|
if (refcnt > 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
|
2015-10-22 07:49:38 +00:00
|
|
|
hci_abort_conn(conn, hci_proto_disconn_ind(conn));
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2011-12-07 15:24:33 +00:00
|
|
|
/* Enter sniff mode */
|
2013-10-16 15:11:40 +00:00
|
|
|
static void hci_conn_idle(struct work_struct *work)
|
2011-12-07 15:24:33 +00:00
|
|
|
{
|
2013-10-16 15:11:40 +00:00
|
|
|
struct hci_conn *conn = container_of(work, struct hci_conn,
|
|
|
|
idle_work.work);
|
2011-12-07 15:24:33 +00:00
|
|
|
struct hci_dev *hdev = conn->hdev;
|
|
|
|
|
2012-06-15 08:50:28 +00:00
|
|
|
BT_DBG("hcon %p mode %d", conn, conn->mode);
|
2011-12-07 15:24:33 +00:00
|
|
|
|
|
|
|
if (!lmp_sniff_capable(hdev) || !lmp_sniff_capable(conn))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (conn->mode != HCI_CM_ACTIVE || !(conn->link_policy & HCI_LP_SNIFF))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (lmp_sniffsubr_capable(hdev) && lmp_sniffsubr_capable(conn)) {
|
|
|
|
struct hci_cp_sniff_subrate cp;
|
|
|
|
cp.handle = cpu_to_le16(conn->handle);
|
2014-03-12 17:52:35 +00:00
|
|
|
cp.max_latency = cpu_to_le16(0);
|
|
|
|
cp.min_remote_timeout = cpu_to_le16(0);
|
|
|
|
cp.min_local_timeout = cpu_to_le16(0);
|
2011-12-07 15:24:33 +00:00
|
|
|
hci_send_cmd(hdev, HCI_OP_SNIFF_SUBRATE, sizeof(cp), &cp);
|
|
|
|
}
|
|
|
|
|
2012-01-16 04:10:31 +00:00
|
|
|
if (!test_and_set_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags)) {
|
2011-12-07 15:24:33 +00:00
|
|
|
struct hci_cp_sniff_mode cp;
|
|
|
|
cp.handle = cpu_to_le16(conn->handle);
|
|
|
|
cp.max_interval = cpu_to_le16(hdev->sniff_max_interval);
|
|
|
|
cp.min_interval = cpu_to_le16(hdev->sniff_min_interval);
|
2014-03-12 17:52:35 +00:00
|
|
|
cp.attempt = cpu_to_le16(4);
|
|
|
|
cp.timeout = cpu_to_le16(1);
|
2011-12-07 15:24:33 +00:00
|
|
|
hci_send_cmd(hdev, HCI_OP_SNIFF_MODE, sizeof(cp), &cp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-16 15:11:39 +00:00
|
|
|
static void hci_conn_auto_accept(struct work_struct *work)
|
2011-04-28 18:28:54 +00:00
|
|
|
{
|
2013-10-16 15:11:39 +00:00
|
|
|
struct hci_conn *conn = container_of(work, struct hci_conn,
|
|
|
|
auto_accept_work.work);
|
2011-04-28 18:28:54 +00:00
|
|
|
|
2013-10-16 15:11:39 +00:00
|
|
|
hci_send_cmd(conn->hdev, HCI_OP_USER_CONFIRM_REPLY, sizeof(conn->dst),
|
2012-05-17 03:36:25 +00:00
|
|
|
&conn->dst);
|
2011-04-28 18:28:54 +00:00
|
|
|
}
|
|
|
|
|
2020-02-24 05:23:40 +00:00
|
|
|
static void le_disable_advertising(struct hci_dev *hdev)
|
|
|
|
{
|
|
|
|
if (ext_adv_capable(hdev)) {
|
|
|
|
struct hci_cp_le_set_ext_adv_enable cp;
|
|
|
|
|
|
|
|
cp.enable = 0x00;
|
|
|
|
cp.num_of_sets = 0x00;
|
|
|
|
|
|
|
|
hci_send_cmd(hdev, HCI_OP_LE_SET_EXT_ADV_ENABLE, sizeof(cp),
|
|
|
|
&cp);
|
|
|
|
} else {
|
|
|
|
u8 enable = 0x00;
|
|
|
|
hci_send_cmd(hdev, HCI_OP_LE_SET_ADV_ENABLE, sizeof(enable),
|
|
|
|
&enable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-28 15:45:46 +00:00
|
|
|
static void le_conn_timeout(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct hci_conn *conn = container_of(work, struct hci_conn,
|
|
|
|
le_conn_timeout.work);
|
2014-03-25 08:30:49 +00:00
|
|
|
struct hci_dev *hdev = conn->hdev;
|
2014-02-28 15:45:46 +00:00
|
|
|
|
|
|
|
BT_DBG("");
|
|
|
|
|
2014-03-25 08:30:49 +00:00
|
|
|
/* We could end up here due to having done directed advertising,
|
|
|
|
* so clean up the state if necessary. This should however only
|
|
|
|
* happen with broken hardware or if low duty cycle was used
|
|
|
|
* (which doesn't have a timeout of its own).
|
|
|
|
*/
|
2014-10-28 21:23:27 +00:00
|
|
|
if (conn->role == HCI_ROLE_SLAVE) {
|
2020-02-24 05:23:40 +00:00
|
|
|
/* Disable LE Advertising */
|
|
|
|
le_disable_advertising(hdev);
|
2022-03-16 15:33:50 +00:00
|
|
|
hci_dev_lock(hdev);
|
2022-04-22 19:58:18 +00:00
|
|
|
hci_conn_failed(conn, HCI_ERROR_ADVERTISING_TIMEOUT);
|
2022-03-16 15:33:50 +00:00
|
|
|
hci_dev_unlock(hdev);
|
2014-03-25 08:30:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-22 07:49:38 +00:00
|
|
|
hci_abort_conn(conn, HCI_ERROR_REMOTE_USER_TERM);
|
2014-02-28 15:45:46 +00:00
|
|
|
}
|
|
|
|
|
2022-03-09 21:22:20 +00:00
|
|
|
struct iso_list_data {
|
|
|
|
union {
|
|
|
|
u8 cig;
|
|
|
|
u8 big;
|
|
|
|
};
|
|
|
|
union {
|
|
|
|
u8 cis;
|
|
|
|
u8 bis;
|
|
|
|
u16 sync_handle;
|
|
|
|
};
|
|
|
|
int count;
|
Bluetooth: ISO: Add support for connecting multiple BISes
It is required for some configurations to have multiple BISes as part
of the same BIG.
Similar to the flow implemented for unicast, DEFER_SETUP will also be
used to bind multiple BISes for the same BIG, before starting Periodic
Advertising and creating the BIG.
The user will have to open a new socket for each BIS. By setting the
BT_DEFER_SETUP socket option and calling connect, a new connection
will be added for the BIG and advertising handle set by the socket
QoS parameters. Since all BISes will be bound for the same BIG and
advertising handle, the socket QoS options and base parameters should
match for all connections.
By calling connect on a socket that does not have the BT_DEFER_SETUP
option set, periodic advertising will be started and the BIG will
be created, with a BIS for each previously bound connection. Since
a BIG cannot be reconfigured with additional BISes after creation,
no more connections can be bound for the BIG after the start periodic
advertising and create BIG commands have been queued.
The bis_cleanup function has also been updated, so that the advertising
set and the BIG will not be terminated unless there are no more
bound or connected BISes.
The HCI_CONN_BIG_CREATED connection flag has been added to indicate
that the BIG has been successfully created. This flag is checked at
bis_cleanup, so that the BIG is only terminated if the
HCI_LE_Create_BIG_Complete has been received.
This implementation has been tested on hardware, using the "isotest"
tool with an additional command line option, to specify the number of
BISes to create as part of the desired BIG:
tools/isotest -i hci0 -s 00:00:00:00:00:00 -N 2 -G 1 -T 1
The btmon log shows that a BIG containing 2 BISes has been created:
< HCI Command: LE Create Broadcast Isochronous Group (0x08|0x0068) plen 31
Handle: 0x01
Advertising Handle: 0x01
Number of BIS: 2
SDU Interval: 10000 us (0x002710)
Maximum SDU size: 40
Maximum Latency: 10 ms (0x000a)
RTN: 0x02
PHY: LE 2M (0x02)
Packing: Sequential (0x00)
Framing: Unframed (0x00)
Encryption: 0x00
Broadcast Code: 00000000000000000000000000000000
> HCI Event: Command Status (0x0f) plen 4
LE Create Broadcast Isochronous Group (0x08|0x0068) ncmd 1
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 23
LE Broadcast Isochronous Group Complete (0x1b)
Status: Success (0x00)
Handle: 0x01
BIG Synchronization Delay: 1974 us (0x0007b6)
Transport Latency: 1974 us (0x0007b6)
PHY: LE 2M (0x02)
NSE: 3
BN: 1
PTO: 1
IRC: 3
Maximum PDU: 40
ISO Interval: 10.00 msec (0x0008)
Connection Handle #0: 10
Connection Handle #1: 11
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 10
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 10
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 11
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 11
< ISO Data TX: Handle 10 flags 0x02 dlen 44
< ISO Data TX: Handle 11 flags 0x02 dlen 44
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 10
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 11
Count: 1
Signed-off-by: Iulia Tanasescu <iulia.tanasescu@nxp.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2023-05-30 14:21:59 +00:00
|
|
|
bool big_term;
|
2023-08-17 06:44:27 +00:00
|
|
|
bool pa_sync_term;
|
2023-07-03 07:02:38 +00:00
|
|
|
bool big_sync_term;
|
2022-03-09 21:22:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void bis_list(struct hci_conn *conn, void *data)
|
|
|
|
{
|
|
|
|
struct iso_list_data *d = data;
|
|
|
|
|
|
|
|
/* Skip if not broadcast/ANY address */
|
|
|
|
if (bacmp(&conn->dst, BDADDR_ANY))
|
|
|
|
return;
|
|
|
|
|
2023-03-31 15:38:01 +00:00
|
|
|
if (d->big != conn->iso_qos.bcast.big || d->bis == BT_ISO_QOS_BIS_UNSET ||
|
|
|
|
d->bis != conn->iso_qos.bcast.bis)
|
2022-03-09 21:22:20 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
d->count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int terminate_big_sync(struct hci_dev *hdev, void *data)
|
|
|
|
{
|
|
|
|
struct iso_list_data *d = data;
|
|
|
|
|
|
|
|
bt_dev_dbg(hdev, "big 0x%2.2x bis 0x%2.2x", d->big, d->bis);
|
|
|
|
|
2023-09-06 13:59:54 +00:00
|
|
|
hci_disable_per_advertising_sync(hdev, d->bis);
|
2022-03-09 21:22:20 +00:00
|
|
|
hci_remove_ext_adv_instance_sync(hdev, d->bis, NULL);
|
|
|
|
|
Bluetooth: ISO: Add support for connecting multiple BISes
It is required for some configurations to have multiple BISes as part
of the same BIG.
Similar to the flow implemented for unicast, DEFER_SETUP will also be
used to bind multiple BISes for the same BIG, before starting Periodic
Advertising and creating the BIG.
The user will have to open a new socket for each BIS. By setting the
BT_DEFER_SETUP socket option and calling connect, a new connection
will be added for the BIG and advertising handle set by the socket
QoS parameters. Since all BISes will be bound for the same BIG and
advertising handle, the socket QoS options and base parameters should
match for all connections.
By calling connect on a socket that does not have the BT_DEFER_SETUP
option set, periodic advertising will be started and the BIG will
be created, with a BIS for each previously bound connection. Since
a BIG cannot be reconfigured with additional BISes after creation,
no more connections can be bound for the BIG after the start periodic
advertising and create BIG commands have been queued.
The bis_cleanup function has also been updated, so that the advertising
set and the BIG will not be terminated unless there are no more
bound or connected BISes.
The HCI_CONN_BIG_CREATED connection flag has been added to indicate
that the BIG has been successfully created. This flag is checked at
bis_cleanup, so that the BIG is only terminated if the
HCI_LE_Create_BIG_Complete has been received.
This implementation has been tested on hardware, using the "isotest"
tool with an additional command line option, to specify the number of
BISes to create as part of the desired BIG:
tools/isotest -i hci0 -s 00:00:00:00:00:00 -N 2 -G 1 -T 1
The btmon log shows that a BIG containing 2 BISes has been created:
< HCI Command: LE Create Broadcast Isochronous Group (0x08|0x0068) plen 31
Handle: 0x01
Advertising Handle: 0x01
Number of BIS: 2
SDU Interval: 10000 us (0x002710)
Maximum SDU size: 40
Maximum Latency: 10 ms (0x000a)
RTN: 0x02
PHY: LE 2M (0x02)
Packing: Sequential (0x00)
Framing: Unframed (0x00)
Encryption: 0x00
Broadcast Code: 00000000000000000000000000000000
> HCI Event: Command Status (0x0f) plen 4
LE Create Broadcast Isochronous Group (0x08|0x0068) ncmd 1
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 23
LE Broadcast Isochronous Group Complete (0x1b)
Status: Success (0x00)
Handle: 0x01
BIG Synchronization Delay: 1974 us (0x0007b6)
Transport Latency: 1974 us (0x0007b6)
PHY: LE 2M (0x02)
NSE: 3
BN: 1
PTO: 1
IRC: 3
Maximum PDU: 40
ISO Interval: 10.00 msec (0x0008)
Connection Handle #0: 10
Connection Handle #1: 11
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 10
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 10
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 11
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 11
< ISO Data TX: Handle 10 flags 0x02 dlen 44
< ISO Data TX: Handle 11 flags 0x02 dlen 44
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 10
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 11
Count: 1
Signed-off-by: Iulia Tanasescu <iulia.tanasescu@nxp.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2023-05-30 14:21:59 +00:00
|
|
|
/* Only terminate BIG if it has been created */
|
|
|
|
if (!d->big_term)
|
2022-03-09 21:22:20 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return hci_le_terminate_big_sync(hdev, d->big,
|
|
|
|
HCI_ERROR_LOCAL_HOST_TERM);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void terminate_big_destroy(struct hci_dev *hdev, void *data, int err)
|
|
|
|
{
|
|
|
|
kfree(data);
|
|
|
|
}
|
|
|
|
|
Bluetooth: ISO: Add support for connecting multiple BISes
It is required for some configurations to have multiple BISes as part
of the same BIG.
Similar to the flow implemented for unicast, DEFER_SETUP will also be
used to bind multiple BISes for the same BIG, before starting Periodic
Advertising and creating the BIG.
The user will have to open a new socket for each BIS. By setting the
BT_DEFER_SETUP socket option and calling connect, a new connection
will be added for the BIG and advertising handle set by the socket
QoS parameters. Since all BISes will be bound for the same BIG and
advertising handle, the socket QoS options and base parameters should
match for all connections.
By calling connect on a socket that does not have the BT_DEFER_SETUP
option set, periodic advertising will be started and the BIG will
be created, with a BIS for each previously bound connection. Since
a BIG cannot be reconfigured with additional BISes after creation,
no more connections can be bound for the BIG after the start periodic
advertising and create BIG commands have been queued.
The bis_cleanup function has also been updated, so that the advertising
set and the BIG will not be terminated unless there are no more
bound or connected BISes.
The HCI_CONN_BIG_CREATED connection flag has been added to indicate
that the BIG has been successfully created. This flag is checked at
bis_cleanup, so that the BIG is only terminated if the
HCI_LE_Create_BIG_Complete has been received.
This implementation has been tested on hardware, using the "isotest"
tool with an additional command line option, to specify the number of
BISes to create as part of the desired BIG:
tools/isotest -i hci0 -s 00:00:00:00:00:00 -N 2 -G 1 -T 1
The btmon log shows that a BIG containing 2 BISes has been created:
< HCI Command: LE Create Broadcast Isochronous Group (0x08|0x0068) plen 31
Handle: 0x01
Advertising Handle: 0x01
Number of BIS: 2
SDU Interval: 10000 us (0x002710)
Maximum SDU size: 40
Maximum Latency: 10 ms (0x000a)
RTN: 0x02
PHY: LE 2M (0x02)
Packing: Sequential (0x00)
Framing: Unframed (0x00)
Encryption: 0x00
Broadcast Code: 00000000000000000000000000000000
> HCI Event: Command Status (0x0f) plen 4
LE Create Broadcast Isochronous Group (0x08|0x0068) ncmd 1
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 23
LE Broadcast Isochronous Group Complete (0x1b)
Status: Success (0x00)
Handle: 0x01
BIG Synchronization Delay: 1974 us (0x0007b6)
Transport Latency: 1974 us (0x0007b6)
PHY: LE 2M (0x02)
NSE: 3
BN: 1
PTO: 1
IRC: 3
Maximum PDU: 40
ISO Interval: 10.00 msec (0x0008)
Connection Handle #0: 10
Connection Handle #1: 11
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 10
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 10
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 11
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 11
< ISO Data TX: Handle 10 flags 0x02 dlen 44
< ISO Data TX: Handle 11 flags 0x02 dlen 44
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 10
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 11
Count: 1
Signed-off-by: Iulia Tanasescu <iulia.tanasescu@nxp.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2023-05-30 14:21:59 +00:00
|
|
|
static int hci_le_terminate_big(struct hci_dev *hdev, struct hci_conn *conn)
|
2022-03-09 21:22:20 +00:00
|
|
|
{
|
|
|
|
struct iso_list_data *d;
|
2023-01-04 06:46:23 +00:00
|
|
|
int ret;
|
2022-03-09 21:22:20 +00:00
|
|
|
|
Bluetooth: ISO: Add support for connecting multiple BISes
It is required for some configurations to have multiple BISes as part
of the same BIG.
Similar to the flow implemented for unicast, DEFER_SETUP will also be
used to bind multiple BISes for the same BIG, before starting Periodic
Advertising and creating the BIG.
The user will have to open a new socket for each BIS. By setting the
BT_DEFER_SETUP socket option and calling connect, a new connection
will be added for the BIG and advertising handle set by the socket
QoS parameters. Since all BISes will be bound for the same BIG and
advertising handle, the socket QoS options and base parameters should
match for all connections.
By calling connect on a socket that does not have the BT_DEFER_SETUP
option set, periodic advertising will be started and the BIG will
be created, with a BIS for each previously bound connection. Since
a BIG cannot be reconfigured with additional BISes after creation,
no more connections can be bound for the BIG after the start periodic
advertising and create BIG commands have been queued.
The bis_cleanup function has also been updated, so that the advertising
set and the BIG will not be terminated unless there are no more
bound or connected BISes.
The HCI_CONN_BIG_CREATED connection flag has been added to indicate
that the BIG has been successfully created. This flag is checked at
bis_cleanup, so that the BIG is only terminated if the
HCI_LE_Create_BIG_Complete has been received.
This implementation has been tested on hardware, using the "isotest"
tool with an additional command line option, to specify the number of
BISes to create as part of the desired BIG:
tools/isotest -i hci0 -s 00:00:00:00:00:00 -N 2 -G 1 -T 1
The btmon log shows that a BIG containing 2 BISes has been created:
< HCI Command: LE Create Broadcast Isochronous Group (0x08|0x0068) plen 31
Handle: 0x01
Advertising Handle: 0x01
Number of BIS: 2
SDU Interval: 10000 us (0x002710)
Maximum SDU size: 40
Maximum Latency: 10 ms (0x000a)
RTN: 0x02
PHY: LE 2M (0x02)
Packing: Sequential (0x00)
Framing: Unframed (0x00)
Encryption: 0x00
Broadcast Code: 00000000000000000000000000000000
> HCI Event: Command Status (0x0f) plen 4
LE Create Broadcast Isochronous Group (0x08|0x0068) ncmd 1
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 23
LE Broadcast Isochronous Group Complete (0x1b)
Status: Success (0x00)
Handle: 0x01
BIG Synchronization Delay: 1974 us (0x0007b6)
Transport Latency: 1974 us (0x0007b6)
PHY: LE 2M (0x02)
NSE: 3
BN: 1
PTO: 1
IRC: 3
Maximum PDU: 40
ISO Interval: 10.00 msec (0x0008)
Connection Handle #0: 10
Connection Handle #1: 11
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 10
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 10
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 11
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 11
< ISO Data TX: Handle 10 flags 0x02 dlen 44
< ISO Data TX: Handle 11 flags 0x02 dlen 44
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 10
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 11
Count: 1
Signed-off-by: Iulia Tanasescu <iulia.tanasescu@nxp.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2023-05-30 14:21:59 +00:00
|
|
|
bt_dev_dbg(hdev, "big 0x%2.2x bis 0x%2.2x", conn->iso_qos.bcast.big,
|
|
|
|
conn->iso_qos.bcast.bis);
|
2022-03-09 21:22:20 +00:00
|
|
|
|
2022-10-30 18:17:22 +00:00
|
|
|
d = kzalloc(sizeof(*d), GFP_KERNEL);
|
2022-03-09 21:22:20 +00:00
|
|
|
if (!d)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
Bluetooth: ISO: Add support for connecting multiple BISes
It is required for some configurations to have multiple BISes as part
of the same BIG.
Similar to the flow implemented for unicast, DEFER_SETUP will also be
used to bind multiple BISes for the same BIG, before starting Periodic
Advertising and creating the BIG.
The user will have to open a new socket for each BIS. By setting the
BT_DEFER_SETUP socket option and calling connect, a new connection
will be added for the BIG and advertising handle set by the socket
QoS parameters. Since all BISes will be bound for the same BIG and
advertising handle, the socket QoS options and base parameters should
match for all connections.
By calling connect on a socket that does not have the BT_DEFER_SETUP
option set, periodic advertising will be started and the BIG will
be created, with a BIS for each previously bound connection. Since
a BIG cannot be reconfigured with additional BISes after creation,
no more connections can be bound for the BIG after the start periodic
advertising and create BIG commands have been queued.
The bis_cleanup function has also been updated, so that the advertising
set and the BIG will not be terminated unless there are no more
bound or connected BISes.
The HCI_CONN_BIG_CREATED connection flag has been added to indicate
that the BIG has been successfully created. This flag is checked at
bis_cleanup, so that the BIG is only terminated if the
HCI_LE_Create_BIG_Complete has been received.
This implementation has been tested on hardware, using the "isotest"
tool with an additional command line option, to specify the number of
BISes to create as part of the desired BIG:
tools/isotest -i hci0 -s 00:00:00:00:00:00 -N 2 -G 1 -T 1
The btmon log shows that a BIG containing 2 BISes has been created:
< HCI Command: LE Create Broadcast Isochronous Group (0x08|0x0068) plen 31
Handle: 0x01
Advertising Handle: 0x01
Number of BIS: 2
SDU Interval: 10000 us (0x002710)
Maximum SDU size: 40
Maximum Latency: 10 ms (0x000a)
RTN: 0x02
PHY: LE 2M (0x02)
Packing: Sequential (0x00)
Framing: Unframed (0x00)
Encryption: 0x00
Broadcast Code: 00000000000000000000000000000000
> HCI Event: Command Status (0x0f) plen 4
LE Create Broadcast Isochronous Group (0x08|0x0068) ncmd 1
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 23
LE Broadcast Isochronous Group Complete (0x1b)
Status: Success (0x00)
Handle: 0x01
BIG Synchronization Delay: 1974 us (0x0007b6)
Transport Latency: 1974 us (0x0007b6)
PHY: LE 2M (0x02)
NSE: 3
BN: 1
PTO: 1
IRC: 3
Maximum PDU: 40
ISO Interval: 10.00 msec (0x0008)
Connection Handle #0: 10
Connection Handle #1: 11
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 10
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 10
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 11
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 11
< ISO Data TX: Handle 10 flags 0x02 dlen 44
< ISO Data TX: Handle 11 flags 0x02 dlen 44
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 10
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 11
Count: 1
Signed-off-by: Iulia Tanasescu <iulia.tanasescu@nxp.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2023-05-30 14:21:59 +00:00
|
|
|
d->big = conn->iso_qos.bcast.big;
|
|
|
|
d->bis = conn->iso_qos.bcast.bis;
|
|
|
|
d->big_term = test_and_clear_bit(HCI_CONN_BIG_CREATED, &conn->flags);
|
2022-03-09 21:22:20 +00:00
|
|
|
|
2023-01-04 06:46:23 +00:00
|
|
|
ret = hci_cmd_sync_queue(hdev, terminate_big_sync, d,
|
|
|
|
terminate_big_destroy);
|
|
|
|
if (ret)
|
|
|
|
kfree(d);
|
|
|
|
|
|
|
|
return ret;
|
2022-03-09 21:22:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int big_terminate_sync(struct hci_dev *hdev, void *data)
|
|
|
|
{
|
|
|
|
struct iso_list_data *d = data;
|
|
|
|
|
|
|
|
bt_dev_dbg(hdev, "big 0x%2.2x sync_handle 0x%4.4x", d->big,
|
|
|
|
d->sync_handle);
|
|
|
|
|
2023-07-03 07:02:38 +00:00
|
|
|
if (d->big_sync_term)
|
|
|
|
hci_le_big_terminate_sync(hdev, d->big);
|
2022-03-09 21:22:20 +00:00
|
|
|
|
2023-08-17 06:44:27 +00:00
|
|
|
if (d->pa_sync_term)
|
|
|
|
return hci_le_pa_terminate_sync(hdev, d->sync_handle);
|
|
|
|
|
|
|
|
return 0;
|
2022-03-09 21:22:20 +00:00
|
|
|
}
|
|
|
|
|
2023-10-11 14:24:07 +00:00
|
|
|
static void find_bis(struct hci_conn *conn, void *data)
|
|
|
|
{
|
|
|
|
struct iso_list_data *d = data;
|
|
|
|
|
|
|
|
/* Ignore if BIG doesn't match */
|
|
|
|
if (d->big != conn->iso_qos.bcast.big)
|
|
|
|
return;
|
|
|
|
|
|
|
|
d->count++;
|
|
|
|
}
|
|
|
|
|
2023-07-03 07:02:38 +00:00
|
|
|
static int hci_le_big_terminate(struct hci_dev *hdev, u8 big, struct hci_conn *conn)
|
2022-03-09 21:22:20 +00:00
|
|
|
{
|
|
|
|
struct iso_list_data *d;
|
2023-01-04 06:46:23 +00:00
|
|
|
int ret;
|
2022-03-09 21:22:20 +00:00
|
|
|
|
2023-07-03 07:02:38 +00:00
|
|
|
bt_dev_dbg(hdev, "big 0x%2.2x sync_handle 0x%4.4x", big, conn->sync_handle);
|
2022-03-09 21:22:20 +00:00
|
|
|
|
2022-10-30 18:17:22 +00:00
|
|
|
d = kzalloc(sizeof(*d), GFP_KERNEL);
|
2022-03-09 21:22:20 +00:00
|
|
|
if (!d)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
d->big = big;
|
2023-07-03 07:02:38 +00:00
|
|
|
d->sync_handle = conn->sync_handle;
|
2023-10-11 14:24:07 +00:00
|
|
|
|
|
|
|
if (test_and_clear_bit(HCI_CONN_PA_SYNC, &conn->flags)) {
|
|
|
|
hci_conn_hash_list_flag(hdev, find_bis, ISO_LINK,
|
|
|
|
HCI_CONN_PA_SYNC, d);
|
|
|
|
|
|
|
|
if (!d->count)
|
|
|
|
d->pa_sync_term = true;
|
|
|
|
|
|
|
|
d->count = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (test_and_clear_bit(HCI_CONN_BIG_SYNC, &conn->flags)) {
|
|
|
|
hci_conn_hash_list_flag(hdev, find_bis, ISO_LINK,
|
|
|
|
HCI_CONN_BIG_SYNC, d);
|
|
|
|
|
|
|
|
if (!d->count)
|
|
|
|
d->big_sync_term = true;
|
|
|
|
}
|
2022-03-09 21:22:20 +00:00
|
|
|
|
2023-01-04 06:46:23 +00:00
|
|
|
ret = hci_cmd_sync_queue(hdev, big_terminate_sync, d,
|
|
|
|
terminate_big_destroy);
|
|
|
|
if (ret)
|
|
|
|
kfree(d);
|
|
|
|
|
|
|
|
return ret;
|
2022-03-09 21:22:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Cleanup BIS connection
|
|
|
|
*
|
|
|
|
* Detects if there any BIS left connected in a BIG
|
|
|
|
* broadcaster: Remove advertising instance and terminate BIG.
|
|
|
|
* broadcaster receiver: Teminate BIG sync and terminate PA sync.
|
|
|
|
*/
|
|
|
|
static void bis_cleanup(struct hci_conn *conn)
|
|
|
|
{
|
|
|
|
struct hci_dev *hdev = conn->hdev;
|
Bluetooth: ISO: Add support for connecting multiple BISes
It is required for some configurations to have multiple BISes as part
of the same BIG.
Similar to the flow implemented for unicast, DEFER_SETUP will also be
used to bind multiple BISes for the same BIG, before starting Periodic
Advertising and creating the BIG.
The user will have to open a new socket for each BIS. By setting the
BT_DEFER_SETUP socket option and calling connect, a new connection
will be added for the BIG and advertising handle set by the socket
QoS parameters. Since all BISes will be bound for the same BIG and
advertising handle, the socket QoS options and base parameters should
match for all connections.
By calling connect on a socket that does not have the BT_DEFER_SETUP
option set, periodic advertising will be started and the BIG will
be created, with a BIS for each previously bound connection. Since
a BIG cannot be reconfigured with additional BISes after creation,
no more connections can be bound for the BIG after the start periodic
advertising and create BIG commands have been queued.
The bis_cleanup function has also been updated, so that the advertising
set and the BIG will not be terminated unless there are no more
bound or connected BISes.
The HCI_CONN_BIG_CREATED connection flag has been added to indicate
that the BIG has been successfully created. This flag is checked at
bis_cleanup, so that the BIG is only terminated if the
HCI_LE_Create_BIG_Complete has been received.
This implementation has been tested on hardware, using the "isotest"
tool with an additional command line option, to specify the number of
BISes to create as part of the desired BIG:
tools/isotest -i hci0 -s 00:00:00:00:00:00 -N 2 -G 1 -T 1
The btmon log shows that a BIG containing 2 BISes has been created:
< HCI Command: LE Create Broadcast Isochronous Group (0x08|0x0068) plen 31
Handle: 0x01
Advertising Handle: 0x01
Number of BIS: 2
SDU Interval: 10000 us (0x002710)
Maximum SDU size: 40
Maximum Latency: 10 ms (0x000a)
RTN: 0x02
PHY: LE 2M (0x02)
Packing: Sequential (0x00)
Framing: Unframed (0x00)
Encryption: 0x00
Broadcast Code: 00000000000000000000000000000000
> HCI Event: Command Status (0x0f) plen 4
LE Create Broadcast Isochronous Group (0x08|0x0068) ncmd 1
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 23
LE Broadcast Isochronous Group Complete (0x1b)
Status: Success (0x00)
Handle: 0x01
BIG Synchronization Delay: 1974 us (0x0007b6)
Transport Latency: 1974 us (0x0007b6)
PHY: LE 2M (0x02)
NSE: 3
BN: 1
PTO: 1
IRC: 3
Maximum PDU: 40
ISO Interval: 10.00 msec (0x0008)
Connection Handle #0: 10
Connection Handle #1: 11
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 10
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 10
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 11
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 11
< ISO Data TX: Handle 10 flags 0x02 dlen 44
< ISO Data TX: Handle 11 flags 0x02 dlen 44
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 10
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 11
Count: 1
Signed-off-by: Iulia Tanasescu <iulia.tanasescu@nxp.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2023-05-30 14:21:59 +00:00
|
|
|
struct hci_conn *bis;
|
2022-03-09 21:22:20 +00:00
|
|
|
|
|
|
|
bt_dev_dbg(hdev, "conn %p", conn);
|
|
|
|
|
|
|
|
if (conn->role == HCI_ROLE_MASTER) {
|
|
|
|
if (!test_and_clear_bit(HCI_CONN_PER_ADV, &conn->flags))
|
|
|
|
return;
|
|
|
|
|
Bluetooth: ISO: Add support for connecting multiple BISes
It is required for some configurations to have multiple BISes as part
of the same BIG.
Similar to the flow implemented for unicast, DEFER_SETUP will also be
used to bind multiple BISes for the same BIG, before starting Periodic
Advertising and creating the BIG.
The user will have to open a new socket for each BIS. By setting the
BT_DEFER_SETUP socket option and calling connect, a new connection
will be added for the BIG and advertising handle set by the socket
QoS parameters. Since all BISes will be bound for the same BIG and
advertising handle, the socket QoS options and base parameters should
match for all connections.
By calling connect on a socket that does not have the BT_DEFER_SETUP
option set, periodic advertising will be started and the BIG will
be created, with a BIS for each previously bound connection. Since
a BIG cannot be reconfigured with additional BISes after creation,
no more connections can be bound for the BIG after the start periodic
advertising and create BIG commands have been queued.
The bis_cleanup function has also been updated, so that the advertising
set and the BIG will not be terminated unless there are no more
bound or connected BISes.
The HCI_CONN_BIG_CREATED connection flag has been added to indicate
that the BIG has been successfully created. This flag is checked at
bis_cleanup, so that the BIG is only terminated if the
HCI_LE_Create_BIG_Complete has been received.
This implementation has been tested on hardware, using the "isotest"
tool with an additional command line option, to specify the number of
BISes to create as part of the desired BIG:
tools/isotest -i hci0 -s 00:00:00:00:00:00 -N 2 -G 1 -T 1
The btmon log shows that a BIG containing 2 BISes has been created:
< HCI Command: LE Create Broadcast Isochronous Group (0x08|0x0068) plen 31
Handle: 0x01
Advertising Handle: 0x01
Number of BIS: 2
SDU Interval: 10000 us (0x002710)
Maximum SDU size: 40
Maximum Latency: 10 ms (0x000a)
RTN: 0x02
PHY: LE 2M (0x02)
Packing: Sequential (0x00)
Framing: Unframed (0x00)
Encryption: 0x00
Broadcast Code: 00000000000000000000000000000000
> HCI Event: Command Status (0x0f) plen 4
LE Create Broadcast Isochronous Group (0x08|0x0068) ncmd 1
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 23
LE Broadcast Isochronous Group Complete (0x1b)
Status: Success (0x00)
Handle: 0x01
BIG Synchronization Delay: 1974 us (0x0007b6)
Transport Latency: 1974 us (0x0007b6)
PHY: LE 2M (0x02)
NSE: 3
BN: 1
PTO: 1
IRC: 3
Maximum PDU: 40
ISO Interval: 10.00 msec (0x0008)
Connection Handle #0: 10
Connection Handle #1: 11
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 10
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 10
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 11
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 11
< ISO Data TX: Handle 10 flags 0x02 dlen 44
< ISO Data TX: Handle 11 flags 0x02 dlen 44
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 10
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 11
Count: 1
Signed-off-by: Iulia Tanasescu <iulia.tanasescu@nxp.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2023-05-30 14:21:59 +00:00
|
|
|
/* Check if ISO connection is a BIS and terminate advertising
|
|
|
|
* set and BIG if there are no other connections using it.
|
|
|
|
*/
|
2023-06-19 14:53:16 +00:00
|
|
|
bis = hci_conn_hash_lookup_big(hdev, conn->iso_qos.bcast.big);
|
Bluetooth: ISO: Add support for connecting multiple BISes
It is required for some configurations to have multiple BISes as part
of the same BIG.
Similar to the flow implemented for unicast, DEFER_SETUP will also be
used to bind multiple BISes for the same BIG, before starting Periodic
Advertising and creating the BIG.
The user will have to open a new socket for each BIS. By setting the
BT_DEFER_SETUP socket option and calling connect, a new connection
will be added for the BIG and advertising handle set by the socket
QoS parameters. Since all BISes will be bound for the same BIG and
advertising handle, the socket QoS options and base parameters should
match for all connections.
By calling connect on a socket that does not have the BT_DEFER_SETUP
option set, periodic advertising will be started and the BIG will
be created, with a BIS for each previously bound connection. Since
a BIG cannot be reconfigured with additional BISes after creation,
no more connections can be bound for the BIG after the start periodic
advertising and create BIG commands have been queued.
The bis_cleanup function has also been updated, so that the advertising
set and the BIG will not be terminated unless there are no more
bound or connected BISes.
The HCI_CONN_BIG_CREATED connection flag has been added to indicate
that the BIG has been successfully created. This flag is checked at
bis_cleanup, so that the BIG is only terminated if the
HCI_LE_Create_BIG_Complete has been received.
This implementation has been tested on hardware, using the "isotest"
tool with an additional command line option, to specify the number of
BISes to create as part of the desired BIG:
tools/isotest -i hci0 -s 00:00:00:00:00:00 -N 2 -G 1 -T 1
The btmon log shows that a BIG containing 2 BISes has been created:
< HCI Command: LE Create Broadcast Isochronous Group (0x08|0x0068) plen 31
Handle: 0x01
Advertising Handle: 0x01
Number of BIS: 2
SDU Interval: 10000 us (0x002710)
Maximum SDU size: 40
Maximum Latency: 10 ms (0x000a)
RTN: 0x02
PHY: LE 2M (0x02)
Packing: Sequential (0x00)
Framing: Unframed (0x00)
Encryption: 0x00
Broadcast Code: 00000000000000000000000000000000
> HCI Event: Command Status (0x0f) plen 4
LE Create Broadcast Isochronous Group (0x08|0x0068) ncmd 1
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 23
LE Broadcast Isochronous Group Complete (0x1b)
Status: Success (0x00)
Handle: 0x01
BIG Synchronization Delay: 1974 us (0x0007b6)
Transport Latency: 1974 us (0x0007b6)
PHY: LE 2M (0x02)
NSE: 3
BN: 1
PTO: 1
IRC: 3
Maximum PDU: 40
ISO Interval: 10.00 msec (0x0008)
Connection Handle #0: 10
Connection Handle #1: 11
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 10
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 10
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 11
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 11
< ISO Data TX: Handle 10 flags 0x02 dlen 44
< ISO Data TX: Handle 11 flags 0x02 dlen 44
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 10
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 11
Count: 1
Signed-off-by: Iulia Tanasescu <iulia.tanasescu@nxp.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2023-05-30 14:21:59 +00:00
|
|
|
if (bis)
|
|
|
|
return;
|
|
|
|
|
|
|
|
hci_le_terminate_big(hdev, conn);
|
2022-03-09 21:22:20 +00:00
|
|
|
} else {
|
2023-03-31 15:38:01 +00:00
|
|
|
hci_le_big_terminate(hdev, conn->iso_qos.bcast.big,
|
2023-07-03 07:02:38 +00:00
|
|
|
conn);
|
2022-03-09 21:22:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int remove_cig_sync(struct hci_dev *hdev, void *data)
|
|
|
|
{
|
2023-08-04 23:23:41 +00:00
|
|
|
u8 handle = PTR_UINT(data);
|
2022-03-09 21:22:20 +00:00
|
|
|
|
|
|
|
return hci_le_remove_cig_sync(hdev, handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hci_le_remove_cig(struct hci_dev *hdev, u8 handle)
|
|
|
|
{
|
|
|
|
bt_dev_dbg(hdev, "handle 0x%2.2x", handle);
|
|
|
|
|
2023-08-04 23:23:41 +00:00
|
|
|
return hci_cmd_sync_queue(hdev, remove_cig_sync, UINT_PTR(handle),
|
|
|
|
NULL);
|
2022-03-09 21:22:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void find_cis(struct hci_conn *conn, void *data)
|
|
|
|
{
|
|
|
|
struct iso_list_data *d = data;
|
|
|
|
|
2023-05-21 15:48:28 +00:00
|
|
|
/* Ignore broadcast or if CIG don't match */
|
|
|
|
if (!bacmp(&conn->dst, BDADDR_ANY) || d->cig != conn->iso_qos.ucast.cig)
|
2022-03-09 21:22:20 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
d->count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Cleanup CIS connection:
|
|
|
|
*
|
|
|
|
* Detects if there any CIS left connected in a CIG and remove it.
|
|
|
|
*/
|
|
|
|
static void cis_cleanup(struct hci_conn *conn)
|
|
|
|
{
|
|
|
|
struct hci_dev *hdev = conn->hdev;
|
|
|
|
struct iso_list_data d;
|
|
|
|
|
2023-05-21 15:48:28 +00:00
|
|
|
if (conn->iso_qos.ucast.cig == BT_ISO_QOS_CIG_UNSET)
|
|
|
|
return;
|
|
|
|
|
2022-03-09 21:22:20 +00:00
|
|
|
memset(&d, 0, sizeof(d));
|
2023-03-31 15:38:01 +00:00
|
|
|
d.cig = conn->iso_qos.ucast.cig;
|
2022-03-09 21:22:20 +00:00
|
|
|
|
|
|
|
/* Check if ISO connection is a CIS and remove CIG if there are
|
|
|
|
* no other connections using it.
|
|
|
|
*/
|
2023-06-01 06:34:44 +00:00
|
|
|
hci_conn_hash_list_state(hdev, find_cis, ISO_LINK, BT_BOUND, &d);
|
|
|
|
hci_conn_hash_list_state(hdev, find_cis, ISO_LINK, BT_CONNECT, &d);
|
2022-03-09 21:22:20 +00:00
|
|
|
hci_conn_hash_list_state(hdev, find_cis, ISO_LINK, BT_CONNECTED, &d);
|
|
|
|
if (d.count)
|
|
|
|
return;
|
|
|
|
|
2023-03-31 15:38:01 +00:00
|
|
|
hci_le_remove_cig(hdev, conn->iso_qos.ucast.cig);
|
2022-03-09 21:22:20 +00:00
|
|
|
}
|
|
|
|
|
2023-10-11 09:57:31 +00:00
|
|
|
static int hci_conn_hash_alloc_unset(struct hci_dev *hdev)
|
2023-06-28 19:15:53 +00:00
|
|
|
{
|
2023-10-11 09:57:31 +00:00
|
|
|
return ida_alloc_range(&hdev->unset_handle_ida, HCI_CONN_HANDLE_MAX + 1,
|
|
|
|
U16_MAX, GFP_ATOMIC);
|
2023-06-28 19:15:53 +00:00
|
|
|
}
|
|
|
|
|
2024-06-20 19:27:47 +00:00
|
|
|
static struct hci_conn *__hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
|
|
|
|
u8 role, u16 handle)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct hci_conn *conn;
|
|
|
|
|
2024-05-04 19:23:29 +00:00
|
|
|
switch (type) {
|
|
|
|
case ACL_LINK:
|
|
|
|
if (!hdev->acl_mtu)
|
|
|
|
return ERR_PTR(-ECONNREFUSED);
|
|
|
|
break;
|
|
|
|
case ISO_LINK:
|
|
|
|
if (hdev->iso_mtu)
|
|
|
|
/* Dedicated ISO Buffer exists */
|
|
|
|
break;
|
|
|
|
fallthrough;
|
|
|
|
case LE_LINK:
|
|
|
|
if (hdev->le_mtu && hdev->le_mtu < HCI_MIN_LE_MTU)
|
|
|
|
return ERR_PTR(-ECONNREFUSED);
|
|
|
|
if (!hdev->le_mtu && hdev->acl_mtu < HCI_MIN_LE_MTU)
|
|
|
|
return ERR_PTR(-ECONNREFUSED);
|
|
|
|
break;
|
|
|
|
case SCO_LINK:
|
|
|
|
case ESCO_LINK:
|
|
|
|
if (!hdev->sco_pkts)
|
|
|
|
/* Controller does not support SCO or eSCO over HCI */
|
|
|
|
return ERR_PTR(-ECONNREFUSED);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return ERR_PTR(-ECONNREFUSED);
|
|
|
|
}
|
|
|
|
|
2023-10-11 09:57:31 +00:00
|
|
|
bt_dev_dbg(hdev, "dst %pMR handle 0x%4.4x", dst, handle);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2014-07-21 07:50:06 +00:00
|
|
|
conn = kzalloc(sizeof(*conn), GFP_KERNEL);
|
2006-07-03 08:02:33 +00:00
|
|
|
if (!conn)
|
2024-05-04 19:23:29 +00:00
|
|
|
return ERR_PTR(-ENOMEM);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
bacpy(&conn->dst, dst);
|
2013-10-13 12:23:59 +00:00
|
|
|
bacpy(&conn->src, &hdev->bdaddr);
|
2023-10-11 09:57:31 +00:00
|
|
|
conn->handle = handle;
|
2008-07-14 18:13:46 +00:00
|
|
|
conn->hdev = hdev;
|
|
|
|
conn->type = type;
|
2014-07-16 08:56:07 +00:00
|
|
|
conn->role = role;
|
2008-07-14 18:13:46 +00:00
|
|
|
conn->mode = HCI_CM_ACTIVE;
|
|
|
|
conn->state = BT_OPEN;
|
2009-09-03 09:34:19 +00:00
|
|
|
conn->auth_type = HCI_AT_GENERAL_BONDING;
|
2011-01-25 11:28:33 +00:00
|
|
|
conn->io_capability = hdev->io_capability;
|
2011-02-19 15:06:01 +00:00
|
|
|
conn->remote_auth = 0xff;
|
2011-04-28 10:07:55 +00:00
|
|
|
conn->key_type = 0xff;
|
2014-12-05 11:36:08 +00:00
|
|
|
conn->rssi = HCI_RSSI_INVALID;
|
2014-05-09 19:35:28 +00:00
|
|
|
conn->tx_power = HCI_TX_POWER_INVALID;
|
2014-05-14 11:43:05 +00:00
|
|
|
conn->max_tx_power = HCI_TX_POWER_INVALID;
|
2023-09-06 14:01:03 +00:00
|
|
|
conn->sync_handle = HCI_SYNC_HANDLE_INVALID;
|
2024-11-01 08:23:36 +00:00
|
|
|
conn->sid = HCI_SID_INVALID;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-01-16 04:47:28 +00:00
|
|
|
set_bit(HCI_CONN_POWER_SAVE, &conn->flags);
|
2009-04-26 18:01:22 +00:00
|
|
|
conn->disc_timeout = HCI_DISCONN_TIMEOUT;
|
2006-07-03 08:02:33 +00:00
|
|
|
|
2019-06-21 09:21:56 +00:00
|
|
|
/* Set Default Authenticated payload timeout to 30s */
|
|
|
|
conn->auth_payload_timeout = DEFAULT_AUTH_PAYLOAD_TIMEOUT;
|
|
|
|
|
2014-07-16 08:56:07 +00:00
|
|
|
if (conn->role == HCI_ROLE_MASTER)
|
|
|
|
conn->out = true;
|
|
|
|
|
2008-07-14 18:13:46 +00:00
|
|
|
switch (type) {
|
|
|
|
case ACL_LINK:
|
|
|
|
conn->pkt_type = hdev->pkt_type & ACL_PTYPE_MASK;
|
2024-05-04 19:23:29 +00:00
|
|
|
conn->mtu = hdev->acl_mtu;
|
2008-07-14 18:13:46 +00:00
|
|
|
break;
|
2014-03-24 18:21:50 +00:00
|
|
|
case LE_LINK:
|
2022-03-09 21:22:20 +00:00
|
|
|
/* conn->src should reflect the local identity address */
|
|
|
|
hci_copy_identity_address(hdev, &conn->src, &conn->src_type);
|
2024-05-04 19:23:29 +00:00
|
|
|
conn->mtu = hdev->le_mtu ? hdev->le_mtu : hdev->acl_mtu;
|
2022-03-09 21:22:20 +00:00
|
|
|
break;
|
2019-07-29 15:15:43 +00:00
|
|
|
case ISO_LINK:
|
2014-03-24 18:21:50 +00:00
|
|
|
/* conn->src should reflect the local identity address */
|
|
|
|
hci_copy_identity_address(hdev, &conn->src, &conn->src_type);
|
2022-03-09 21:22:20 +00:00
|
|
|
|
|
|
|
/* set proper cleanup function */
|
|
|
|
if (!bacmp(dst, BDADDR_ANY))
|
|
|
|
conn->cleanup = bis_cleanup;
|
|
|
|
else if (conn->role == HCI_ROLE_MASTER)
|
|
|
|
conn->cleanup = cis_cleanup;
|
|
|
|
|
2024-05-04 19:23:29 +00:00
|
|
|
conn->mtu = hdev->iso_mtu ? hdev->iso_mtu :
|
|
|
|
hdev->le_mtu ? hdev->le_mtu : hdev->acl_mtu;
|
2014-03-24 18:21:50 +00:00
|
|
|
break;
|
2008-07-14 18:13:46 +00:00
|
|
|
case SCO_LINK:
|
|
|
|
if (lmp_esco_capable(hdev))
|
2009-02-06 08:13:37 +00:00
|
|
|
conn->pkt_type = (hdev->esco_type & SCO_ESCO_MASK) |
|
|
|
|
(hdev->esco_type & EDR_ESCO_MASK);
|
2008-07-14 18:13:46 +00:00
|
|
|
else
|
|
|
|
conn->pkt_type = hdev->pkt_type & SCO_PTYPE_MASK;
|
2024-05-04 19:23:29 +00:00
|
|
|
|
|
|
|
conn->mtu = hdev->sco_mtu;
|
2008-07-14 18:13:46 +00:00
|
|
|
break;
|
|
|
|
case ESCO_LINK:
|
2009-02-06 08:13:37 +00:00
|
|
|
conn->pkt_type = hdev->esco_type & ~EDR_ESCO_MASK;
|
2024-05-04 19:23:29 +00:00
|
|
|
conn->mtu = hdev->sco_mtu;
|
2008-07-14 18:13:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
skb_queue_head_init(&conn->data_q);
|
2006-07-03 08:02:33 +00:00
|
|
|
|
2012-02-22 11:06:43 +00:00
|
|
|
INIT_LIST_HEAD(&conn->chan_list);
|
2023-04-11 23:02:22 +00:00
|
|
|
INIT_LIST_HEAD(&conn->link_list);
|
2011-11-02 13:52:01 +00:00
|
|
|
|
2011-06-17 16:03:21 +00:00
|
|
|
INIT_DELAYED_WORK(&conn->disc_work, hci_conn_timeout);
|
2013-10-16 15:11:39 +00:00
|
|
|
INIT_DELAYED_WORK(&conn->auto_accept_work, hci_conn_auto_accept);
|
2013-10-16 15:11:40 +00:00
|
|
|
INIT_DELAYED_WORK(&conn->idle_work, hci_conn_idle);
|
2014-02-28 15:45:46 +00:00
|
|
|
INIT_DELAYED_WORK(&conn->le_conn_timeout, le_conn_timeout);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
atomic_set(&conn->refcnt, 0);
|
|
|
|
|
|
|
|
hci_dev_hold(hdev);
|
|
|
|
|
|
|
|
hci_conn_hash_add(hdev, conn);
|
2020-04-03 19:43:58 +00:00
|
|
|
|
|
|
|
/* The SCO and eSCO connections will only be notified when their
|
|
|
|
* setup has been completed. This is different to ACL links which
|
|
|
|
* can be notified right away.
|
|
|
|
*/
|
|
|
|
if (conn->type != SCO_LINK && conn->type != ESCO_LINK) {
|
|
|
|
if (hdev->notify)
|
|
|
|
hdev->notify(hdev, HCI_NOTIFY_CONN_ADD);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-05-03 01:24:06 +00:00
|
|
|
hci_conn_init_sysfs(conn);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return conn;
|
|
|
|
}
|
|
|
|
|
2023-10-11 09:57:31 +00:00
|
|
|
struct hci_conn *hci_conn_add_unset(struct hci_dev *hdev, int type,
|
|
|
|
bdaddr_t *dst, u8 role)
|
|
|
|
{
|
|
|
|
int handle;
|
|
|
|
|
|
|
|
bt_dev_dbg(hdev, "dst %pMR", dst);
|
|
|
|
|
|
|
|
handle = hci_conn_hash_alloc_unset(hdev);
|
|
|
|
if (unlikely(handle < 0))
|
2024-05-04 19:23:29 +00:00
|
|
|
return ERR_PTR(-ECONNREFUSED);
|
2023-10-11 09:57:31 +00:00
|
|
|
|
2024-06-20 19:27:47 +00:00
|
|
|
return __hci_conn_add(hdev, type, dst, role, handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
|
|
|
|
u8 role, u16 handle)
|
|
|
|
{
|
|
|
|
if (handle > HCI_CONN_HANDLE_MAX)
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
|
|
|
return __hci_conn_add(hdev, type, dst, role, handle);
|
2023-10-11 09:57:31 +00:00
|
|
|
}
|
|
|
|
|
2023-08-19 13:33:36 +00:00
|
|
|
static void hci_conn_cleanup_child(struct hci_conn *conn, u8 reason)
|
|
|
|
{
|
|
|
|
if (!reason)
|
|
|
|
reason = HCI_ERROR_REMOTE_USER_TERM;
|
|
|
|
|
|
|
|
/* Due to race, SCO/ISO conn might be not established yet at this point,
|
|
|
|
* and nothing else will clean it up. In other cases it is done via HCI
|
|
|
|
* events.
|
|
|
|
*/
|
|
|
|
switch (conn->type) {
|
|
|
|
case SCO_LINK:
|
|
|
|
case ESCO_LINK:
|
|
|
|
if (HCI_CONN_HANDLE_UNSET(conn->handle))
|
|
|
|
hci_conn_failed(conn, reason);
|
|
|
|
break;
|
|
|
|
case ISO_LINK:
|
2023-11-13 15:38:00 +00:00
|
|
|
if ((conn->state != BT_CONNECTED &&
|
|
|
|
!test_bit(HCI_CONN_CREATE_CIS, &conn->flags)) ||
|
|
|
|
test_bit(HCI_CONN_BIG_CREATED, &conn->flags))
|
2023-08-19 13:33:36 +00:00
|
|
|
hci_conn_failed(conn, reason);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-11 23:02:22 +00:00
|
|
|
static void hci_conn_unlink(struct hci_conn *conn)
|
2023-04-03 21:19:14 +00:00
|
|
|
{
|
2023-04-11 23:02:22 +00:00
|
|
|
struct hci_dev *hdev = conn->hdev;
|
|
|
|
|
|
|
|
bt_dev_dbg(hdev, "hcon %p", conn);
|
|
|
|
|
|
|
|
if (!conn->parent) {
|
|
|
|
struct hci_link *link, *t;
|
|
|
|
|
2023-05-03 13:39:34 +00:00
|
|
|
list_for_each_entry_safe(link, t, &conn->link_list, list) {
|
|
|
|
struct hci_conn *child = link->conn;
|
|
|
|
|
|
|
|
hci_conn_unlink(child);
|
|
|
|
|
2023-05-03 13:39:36 +00:00
|
|
|
/* If hdev is down it means
|
|
|
|
* hci_dev_close_sync/hci_conn_hash_flush is in progress
|
|
|
|
* and links don't need to be cleanup as all connections
|
|
|
|
* would be cleanup.
|
|
|
|
*/
|
|
|
|
if (!test_bit(HCI_UP, &hdev->flags))
|
|
|
|
continue;
|
|
|
|
|
2023-08-19 13:33:36 +00:00
|
|
|
hci_conn_cleanup_child(child, conn->abort_reason);
|
2023-05-03 13:39:34 +00:00
|
|
|
}
|
2023-04-11 23:02:22 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-04-03 21:19:14 +00:00
|
|
|
if (!conn->link)
|
2023-04-11 23:02:22 +00:00
|
|
|
return;
|
2023-04-03 21:19:14 +00:00
|
|
|
|
2023-04-11 23:02:22 +00:00
|
|
|
list_del_rcu(&conn->link->list);
|
|
|
|
synchronize_rcu();
|
|
|
|
|
Bluetooth: Unlink CISes when LE disconnects in hci_conn_del
Currently, hci_conn_del calls hci_conn_unlink for BR/EDR, (e)SCO, and
CIS connections, i.e., everything except LE connections. However, if
(e)SCO connections are unlinked when BR/EDR disconnects, CIS connections
should also be unlinked when LE disconnects.
In terms of disconnection behavior, CIS and (e)SCO connections are not
too different. One peculiarity of CIS is that when CIS connections are
disconnected, the CIS handle isn't deleted, as per [BLUETOOTH CORE
SPECIFICATION Version 5.4 | Vol 4, Part E] 7.1.6 Disconnect command:
All SCO, eSCO, and CIS connections on a physical link should be
disconnected before the ACL connection on the same physical
connection is disconnected. If it does not, they will be
implicitly disconnected as part of the ACL disconnection.
...
Note: As specified in Section 7.7.5, on the Central, the handle
for a CIS remains valid even after disconnection and, therefore,
the Host can recreate a disconnected CIS at a later point in
time using the same connection handle.
Since hci_conn_link invokes both hci_conn_get and hci_conn_hold,
hci_conn_unlink should perform both hci_conn_put and hci_conn_drop as
well. However, currently it performs only hci_conn_put.
This patch makes hci_conn_unlink call hci_conn_drop as well, which
simplifies the logic in hci_conn_del a bit and may benefit future users
of hci_conn_unlink. But it is noted that this change additionally
implies that hci_conn_unlink can queue disc_work on conn itself, with
the following call stack:
hci_conn_unlink(conn) [conn->parent == NULL]
-> hci_conn_unlink(child) [child->parent == conn]
-> hci_conn_drop(child->parent)
-> queue_delayed_work(&conn->disc_work)
Queued disc_work after hci_conn_del can be spurious, so during the
process of hci_conn_del, it is necessary to make the call to
cancel_delayed_work(&conn->disc_work) after invoking hci_conn_unlink.
Signed-off-by: Ruihan Li <lrh2000@pku.edu.cn>
Co-developed-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2023-05-03 13:39:37 +00:00
|
|
|
hci_conn_drop(conn->parent);
|
2023-05-03 13:39:35 +00:00
|
|
|
hci_conn_put(conn->parent);
|
|
|
|
conn->parent = NULL;
|
|
|
|
|
2023-04-11 23:02:22 +00:00
|
|
|
kfree(conn->link);
|
2023-04-03 21:19:14 +00:00
|
|
|
conn->link = NULL;
|
|
|
|
}
|
|
|
|
|
2023-05-03 13:39:36 +00:00
|
|
|
void hci_conn_del(struct hci_conn *conn)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct hci_dev *hdev = conn->hdev;
|
|
|
|
|
2012-06-15 08:50:28 +00:00
|
|
|
BT_DBG("%s hcon %p handle %d", hdev->name, conn, conn->handle);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
Bluetooth: Unlink CISes when LE disconnects in hci_conn_del
Currently, hci_conn_del calls hci_conn_unlink for BR/EDR, (e)SCO, and
CIS connections, i.e., everything except LE connections. However, if
(e)SCO connections are unlinked when BR/EDR disconnects, CIS connections
should also be unlinked when LE disconnects.
In terms of disconnection behavior, CIS and (e)SCO connections are not
too different. One peculiarity of CIS is that when CIS connections are
disconnected, the CIS handle isn't deleted, as per [BLUETOOTH CORE
SPECIFICATION Version 5.4 | Vol 4, Part E] 7.1.6 Disconnect command:
All SCO, eSCO, and CIS connections on a physical link should be
disconnected before the ACL connection on the same physical
connection is disconnected. If it does not, they will be
implicitly disconnected as part of the ACL disconnection.
...
Note: As specified in Section 7.7.5, on the Central, the handle
for a CIS remains valid even after disconnection and, therefore,
the Host can recreate a disconnected CIS at a later point in
time using the same connection handle.
Since hci_conn_link invokes both hci_conn_get and hci_conn_hold,
hci_conn_unlink should perform both hci_conn_put and hci_conn_drop as
well. However, currently it performs only hci_conn_put.
This patch makes hci_conn_unlink call hci_conn_drop as well, which
simplifies the logic in hci_conn_del a bit and may benefit future users
of hci_conn_unlink. But it is noted that this change additionally
implies that hci_conn_unlink can queue disc_work on conn itself, with
the following call stack:
hci_conn_unlink(conn) [conn->parent == NULL]
-> hci_conn_unlink(child) [child->parent == conn]
-> hci_conn_drop(child->parent)
-> queue_delayed_work(&conn->disc_work)
Queued disc_work after hci_conn_del can be spurious, so during the
process of hci_conn_del, it is necessary to make the call to
cancel_delayed_work(&conn->disc_work) after invoking hci_conn_unlink.
Signed-off-by: Ruihan Li <lrh2000@pku.edu.cn>
Co-developed-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2023-05-03 13:39:37 +00:00
|
|
|
hci_conn_unlink(conn);
|
|
|
|
|
2024-10-01 16:34:06 +00:00
|
|
|
disable_delayed_work_sync(&conn->disc_work);
|
|
|
|
disable_delayed_work_sync(&conn->auto_accept_work);
|
|
|
|
disable_delayed_work_sync(&conn->idle_work);
|
2011-04-28 18:28:54 +00:00
|
|
|
|
2007-07-11 07:51:55 +00:00
|
|
|
if (conn->type == ACL_LINK) {
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Unacked frames */
|
|
|
|
hdev->acl_cnt += conn->sent;
|
2011-02-11 01:38:48 +00:00
|
|
|
} else if (conn->type == LE_LINK) {
|
2014-10-28 21:23:26 +00:00
|
|
|
cancel_delayed_work(&conn->le_conn_timeout);
|
2014-02-28 15:45:46 +00:00
|
|
|
|
2011-02-11 01:38:48 +00:00
|
|
|
if (hdev->le_pkts)
|
|
|
|
hdev->le_cnt += conn->sent;
|
|
|
|
else
|
|
|
|
hdev->acl_cnt += conn->sent;
|
2007-07-11 07:51:55 +00:00
|
|
|
} else {
|
2022-10-17 22:36:23 +00:00
|
|
|
/* Unacked ISO frames */
|
|
|
|
if (conn->type == ISO_LINK) {
|
|
|
|
if (hdev->iso_pkts)
|
|
|
|
hdev->iso_cnt += conn->sent;
|
|
|
|
else if (hdev->le_pkts)
|
|
|
|
hdev->le_cnt += conn->sent;
|
|
|
|
else
|
|
|
|
hdev->acl_cnt += conn->sent;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
skb_queue_purge(&conn->data_q);
|
|
|
|
|
2015-10-16 07:07:50 +00:00
|
|
|
/* Remove the connection from the list and cleanup its remaining
|
|
|
|
* state. This is a separate function since for some cases like
|
|
|
|
* BT_CONNECT_SCAN we *only* want the cleanup part without the
|
|
|
|
* rest of hci_conn_del.
|
|
|
|
*/
|
|
|
|
hci_conn_cleanup(conn);
|
2024-02-13 14:59:32 +00:00
|
|
|
|
|
|
|
/* Dequeue callbacks using connection pointer as data */
|
|
|
|
hci_cmd_sync_dequeue(hdev, NULL, conn, NULL);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2016-11-12 15:03:07 +00:00
|
|
|
struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src, uint8_t src_type)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int use_src = bacmp(src, BDADDR_ANY);
|
2011-11-01 08:58:56 +00:00
|
|
|
struct hci_dev *hdev = NULL, *d;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-09-25 09:49:43 +00:00
|
|
|
BT_DBG("%pMR -> %pMR", src, dst);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-12-22 18:30:27 +00:00
|
|
|
read_lock(&hci_dev_list_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-11-01 08:58:56 +00:00
|
|
|
list_for_each_entry(d, &hci_dev_list, list) {
|
2012-05-23 07:04:21 +00:00
|
|
|
if (!test_bit(HCI_UP, &d->flags) ||
|
2024-05-06 22:33:52 +00:00
|
|
|
hci_dev_test_flag(d, HCI_USER_CHANNEL))
|
2005-04-16 22:20:36 +00:00
|
|
|
continue;
|
|
|
|
|
2007-02-09 14:24:33 +00:00
|
|
|
/* Simple routing:
|
2005-04-16 22:20:36 +00:00
|
|
|
* No source address - find interface with bdaddr != dst
|
|
|
|
* Source address - find interface with bdaddr == src
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (use_src) {
|
2016-11-12 15:03:07 +00:00
|
|
|
bdaddr_t id_addr;
|
|
|
|
u8 id_addr_type;
|
|
|
|
|
|
|
|
if (src_type == BDADDR_BREDR) {
|
|
|
|
if (!lmp_bredr_capable(d))
|
|
|
|
continue;
|
|
|
|
bacpy(&id_addr, &d->bdaddr);
|
|
|
|
id_addr_type = BDADDR_BREDR;
|
|
|
|
} else {
|
|
|
|
if (!lmp_le_capable(d))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
hci_copy_identity_address(d, &id_addr,
|
|
|
|
&id_addr_type);
|
|
|
|
|
|
|
|
/* Convert from HCI to three-value type */
|
|
|
|
if (id_addr_type == ADDR_LE_DEV_PUBLIC)
|
|
|
|
id_addr_type = BDADDR_LE_PUBLIC;
|
|
|
|
else
|
|
|
|
id_addr_type = BDADDR_LE_RANDOM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bacmp(&id_addr, src) && id_addr_type == src_type) {
|
2005-04-16 22:20:36 +00:00
|
|
|
hdev = d; break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (bacmp(&d->bdaddr, dst)) {
|
|
|
|
hdev = d; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hdev)
|
|
|
|
hdev = hci_dev_hold(hdev);
|
|
|
|
|
2011-12-22 18:30:27 +00:00
|
|
|
read_unlock(&hci_dev_list_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
return hdev;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(hci_get_route);
|
|
|
|
|
2014-01-30 21:22:08 +00:00
|
|
|
/* This function requires the caller holds hdev->lock */
|
2022-04-22 19:58:18 +00:00
|
|
|
static void hci_le_conn_failed(struct hci_conn *conn, u8 status)
|
2014-01-30 21:22:08 +00:00
|
|
|
{
|
|
|
|
struct hci_dev *hdev = conn->hdev;
|
2014-08-15 18:06:54 +00:00
|
|
|
|
2023-03-24 17:57:55 +00:00
|
|
|
hci_connect_le_scan_cleanup(conn, status);
|
2014-03-25 08:30:49 +00:00
|
|
|
|
Bluetooth: hci_sync: Convert MGMT_OP_START_DISCOVERY
This make use of hci_cmd_sync_queue for MGMT_OP_START_DISCOVERY,
MGMT_OP_START_SERVICE_DISCOVERY and MGMT_OP_STOP_DISCOVERY to use
hci_cmd_sync_queue so they no longer depend on hdev->discov_update work
to send any commands.
Tested with:
tools/mgmt-tester -s "Start Discovery"
Test Summary
------------
Start Discovery - Not powered 1 Passed
Start Discovery - Invalid parameters 1 Passed
Start Discovery - Not supported 1 Passed
Start Discovery - Success 1 Passed
Start Discovery - Success 2 Passed
Start Discovery - Power Off 1 Passed
Start Discovery BREDR LE - (Ext Scan Enable) Passed
Start Discovery LE - (Ext Scan Enable) Passed
Start Discovery LE - (Ext Scan Param) Passed
Start Discovery - (2m, Scan Param) Passed
Start Discovery - (coded, Scan Param) Passed
Start Discovery - (1m, 2m, coded, Scan Param) Passed
LL Privacy - Start Discovery 1 (Disable RL) Passed
LL Privacy - Start Discovery 2 (Disable RL) Passed
Total: 14, Passed: 14 (100.0%), Failed: 0, Not Run: 0
tools/mgmt-tester -s "Start Service"
Test Summary
------------
Start Service Discovery - Not powered 1 Passed
Start Service Discovery - Invalid parameters 1 Passed
Start Service Discovery - Not supported 1 Passed
Start Service Discovery - Success 1 Passed
Start Service Discovery - Success 2 Passed
Total: 5, Passed: 5 (100.0%), Failed: 0, Not Run: 0
tools/mgmt-tester -s "Stop Discovery"
Test Summary
------------
Stop Discovery - Success 1 Passed
Stop Discovery - BR/EDR (Inquiry) Success 1 Passed
Stop Discovery - Rejected 1 Passed
Stop Discovery - Invalid parameters 1 Passed
Stop Discovery - (Ext Scan Disable) Passed
Total: 5, Passed: 5 (100.0%), Failed: 0, Not Run: 0
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2021-10-27 23:58:45 +00:00
|
|
|
/* Enable advertising in case this was a failed connection
|
2014-03-25 08:30:49 +00:00
|
|
|
* attempt as a peripheral.
|
|
|
|
*/
|
Bluetooth: hci_sync: Convert MGMT_OP_START_DISCOVERY
This make use of hci_cmd_sync_queue for MGMT_OP_START_DISCOVERY,
MGMT_OP_START_SERVICE_DISCOVERY and MGMT_OP_STOP_DISCOVERY to use
hci_cmd_sync_queue so they no longer depend on hdev->discov_update work
to send any commands.
Tested with:
tools/mgmt-tester -s "Start Discovery"
Test Summary
------------
Start Discovery - Not powered 1 Passed
Start Discovery - Invalid parameters 1 Passed
Start Discovery - Not supported 1 Passed
Start Discovery - Success 1 Passed
Start Discovery - Success 2 Passed
Start Discovery - Power Off 1 Passed
Start Discovery BREDR LE - (Ext Scan Enable) Passed
Start Discovery LE - (Ext Scan Enable) Passed
Start Discovery LE - (Ext Scan Param) Passed
Start Discovery - (2m, Scan Param) Passed
Start Discovery - (coded, Scan Param) Passed
Start Discovery - (1m, 2m, coded, Scan Param) Passed
LL Privacy - Start Discovery 1 (Disable RL) Passed
LL Privacy - Start Discovery 2 (Disable RL) Passed
Total: 14, Passed: 14 (100.0%), Failed: 0, Not Run: 0
tools/mgmt-tester -s "Start Service"
Test Summary
------------
Start Service Discovery - Not powered 1 Passed
Start Service Discovery - Invalid parameters 1 Passed
Start Service Discovery - Not supported 1 Passed
Start Service Discovery - Success 1 Passed
Start Service Discovery - Success 2 Passed
Total: 5, Passed: 5 (100.0%), Failed: 0, Not Run: 0
tools/mgmt-tester -s "Stop Discovery"
Test Summary
------------
Stop Discovery - Success 1 Passed
Stop Discovery - BR/EDR (Inquiry) Success 1 Passed
Stop Discovery - Rejected 1 Passed
Stop Discovery - Invalid parameters 1 Passed
Stop Discovery - (Ext Scan Disable) Passed
Total: 5, Passed: 5 (100.0%), Failed: 0, Not Run: 0
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
2021-10-27 23:58:45 +00:00
|
|
|
hci_enable_advertising(hdev);
|
2014-01-30 21:22:08 +00:00
|
|
|
}
|
|
|
|
|
2022-04-22 19:58:18 +00:00
|
|
|
/* This function requires the caller holds hdev->lock */
|
|
|
|
void hci_conn_failed(struct hci_conn *conn, u8 status)
|
|
|
|
{
|
|
|
|
struct hci_dev *hdev = conn->hdev;
|
|
|
|
|
|
|
|
bt_dev_dbg(hdev, "status 0x%2.2x", status);
|
|
|
|
|
|
|
|
switch (conn->type) {
|
|
|
|
case LE_LINK:
|
|
|
|
hci_le_conn_failed(conn, status);
|
|
|
|
break;
|
|
|
|
case ACL_LINK:
|
2024-08-30 21:29:27 +00:00
|
|
|
mgmt_connect_failed(hdev, conn, status);
|
2022-04-22 19:58:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-09-06 13:59:54 +00:00
|
|
|
/* In case of BIG/PA sync failed, clear conn flags so that
|
|
|
|
* the conns will be correctly cleaned up by ISO layer
|
|
|
|
*/
|
|
|
|
test_and_clear_bit(HCI_CONN_BIG_SYNC_FAILED, &conn->flags);
|
|
|
|
test_and_clear_bit(HCI_CONN_PA_SYNC_FAILED, &conn->flags);
|
|
|
|
|
2022-04-22 19:58:18 +00:00
|
|
|
conn->state = BT_CLOSED;
|
|
|
|
hci_connect_cfm(conn, status);
|
|
|
|
hci_conn_del(conn);
|
|
|
|
}
|
|
|
|
|
2023-08-03 21:49:14 +00:00
|
|
|
/* This function requires the caller holds hdev->lock */
|
|
|
|
u8 hci_conn_set_handle(struct hci_conn *conn, u16 handle)
|
|
|
|
{
|
|
|
|
struct hci_dev *hdev = conn->hdev;
|
|
|
|
|
|
|
|
bt_dev_dbg(hdev, "hcon %p handle 0x%4.4x", conn, handle);
|
|
|
|
|
|
|
|
if (conn->handle == handle)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (handle > HCI_CONN_HANDLE_MAX) {
|
|
|
|
bt_dev_err(hdev, "Invalid handle: 0x%4.4x > 0x%4.4x",
|
|
|
|
handle, HCI_CONN_HANDLE_MAX);
|
|
|
|
return HCI_ERROR_INVALID_PARAMETERS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If abort_reason has been sent it means the connection is being
|
|
|
|
* aborted and the handle shall not be changed.
|
|
|
|
*/
|
|
|
|
if (conn->abort_reason)
|
|
|
|
return conn->abort_reason;
|
|
|
|
|
2023-10-11 09:57:31 +00:00
|
|
|
if (HCI_CONN_HANDLE_UNSET(conn->handle))
|
|
|
|
ida_free(&hdev->unset_handle_ida, conn->handle);
|
|
|
|
|
2023-08-03 21:49:14 +00:00
|
|
|
conn->handle = handle;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-02-26 23:21:44 +00:00
|
|
|
struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
|
2021-08-30 20:55:37 +00:00
|
|
|
u8 dst_type, bool dst_resolved, u8 sec_level,
|
2024-04-05 20:40:33 +00:00
|
|
|
u16 conn_timeout, u8 role, u8 phy, u8 sec_phy)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2015-11-11 12:44:59 +00:00
|
|
|
struct hci_conn *conn;
|
2014-02-18 19:41:36 +00:00
|
|
|
struct smp_irk *irk;
|
2013-10-08 11:21:17 +00:00
|
|
|
int err;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2015-02-11 11:31:40 +00:00
|
|
|
/* Let's make sure that le is enabled.*/
|
2015-03-13 09:11:00 +00:00
|
|
|
if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) {
|
2015-02-11 11:31:40 +00:00
|
|
|
if (lmp_le_capable(hdev))
|
|
|
|
return ERR_PTR(-ECONNREFUSED);
|
|
|
|
|
|
|
|
return ERR_PTR(-EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
2015-11-11 12:44:58 +00:00
|
|
|
/* Since the controller supports only one LE connection attempt at a
|
|
|
|
* time, we return -EBUSY if there is any connection attempt running.
|
|
|
|
*/
|
|
|
|
if (hci_lookup_le_connect(hdev))
|
|
|
|
return ERR_PTR(-EBUSY);
|
|
|
|
|
2015-11-11 12:44:59 +00:00
|
|
|
/* If there's already a connection object but it's not in
|
|
|
|
* scanning state it means it must already be established, in
|
|
|
|
* which case we can't do anything else except report a failure
|
|
|
|
* to connect.
|
2013-10-08 11:21:18 +00:00
|
|
|
*/
|
2015-10-21 15:03:01 +00:00
|
|
|
conn = hci_conn_hash_lookup_le(hdev, dst, dst_type);
|
2015-11-11 12:44:59 +00:00
|
|
|
if (conn && !test_bit(HCI_CONN_SCANNING, &conn->flags)) {
|
|
|
|
return ERR_PTR(-EBUSY);
|
2013-10-08 11:21:18 +00:00
|
|
|
}
|
2012-05-30 13:39:21 +00:00
|
|
|
|
2021-08-30 20:55:37 +00:00
|
|
|
/* Check if the destination address has been resolved by the controller
|
|
|
|
* since if it did then the identity address shall be used.
|
2014-02-18 23:13:43 +00:00
|
|
|
*/
|
2021-08-30 20:55:37 +00:00
|
|
|
if (!dst_resolved) {
|
|
|
|
/* When given an identity address with existing identity
|
|
|
|
* resolving key, the connection needs to be established
|
|
|
|
* to a resolvable random address.
|
|
|
|
*
|
|
|
|
* Storing the resolvable random address is required here
|
|
|
|
* to handle connection failures. The address will later
|
|
|
|
* be resolved back into the original identity address
|
|
|
|
* from the connect request.
|
|
|
|
*/
|
|
|
|
irk = hci_find_irk_by_addr(hdev, dst, dst_type);
|
|
|
|
if (irk && bacmp(&irk->rpa, BDADDR_ANY)) {
|
|
|
|
dst = &irk->rpa;
|
|
|
|
dst_type = ADDR_LE_DEV_RANDOM;
|
|
|
|
}
|
2014-02-18 19:41:36 +00:00
|
|
|
}
|
|
|
|
|
2015-11-11 12:44:59 +00:00
|
|
|
if (conn) {
|
2015-08-07 18:22:54 +00:00
|
|
|
bacpy(&conn->dst, dst);
|
|
|
|
} else {
|
2023-10-11 09:57:31 +00:00
|
|
|
conn = hci_conn_add_unset(hdev, LE_LINK, dst, role);
|
2024-05-04 19:23:29 +00:00
|
|
|
if (IS_ERR(conn))
|
|
|
|
return conn;
|
2015-11-11 12:44:59 +00:00
|
|
|
hci_conn_hold(conn);
|
|
|
|
conn->pending_sec_level = sec_level;
|
2015-08-07 18:22:54 +00:00
|
|
|
}
|
|
|
|
|
2014-02-18 19:41:36 +00:00
|
|
|
conn->dst_type = dst_type;
|
2013-10-08 11:21:18 +00:00
|
|
|
conn->sec_level = BT_SECURITY_LOW;
|
2014-07-06 10:41:15 +00:00
|
|
|
conn->conn_timeout = conn_timeout;
|
2024-04-05 20:40:33 +00:00
|
|
|
conn->le_adv_phy = phy;
|
|
|
|
conn->le_adv_sec_phy = sec_phy;
|
2014-02-03 16:56:19 +00:00
|
|
|
|
2024-02-13 14:59:32 +00:00
|
|
|
err = hci_connect_le_sync(hdev, conn);
|
2014-02-26 23:21:42 +00:00
|
|
|
if (err) {
|
|
|
|
hci_conn_del(conn);
|
2013-10-08 11:21:18 +00:00
|
|
|
return ERR_PTR(err);
|
2014-02-26 23:21:42 +00:00
|
|
|
}
|
2011-02-11 01:38:47 +00:00
|
|
|
|
2013-10-03 21:25:44 +00:00
|
|
|
return conn;
|
2012-07-27 22:32:56 +00:00
|
|
|
}
|
2011-02-11 01:38:47 +00:00
|
|
|
|
2015-08-07 18:22:53 +00:00
|
|
|
static bool is_connected(struct hci_dev *hdev, bdaddr_t *addr, u8 type)
|
|
|
|
{
|
|
|
|
struct hci_conn *conn;
|
|
|
|
|
2015-10-21 15:03:01 +00:00
|
|
|
conn = hci_conn_hash_lookup_le(hdev, addr, type);
|
2015-08-07 18:22:53 +00:00
|
|
|
if (!conn)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (conn->state != BT_CONNECTED)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This function requires the caller holds hdev->lock */
|
2015-11-11 06:11:20 +00:00
|
|
|
static int hci_explicit_conn_params_set(struct hci_dev *hdev,
|
2015-08-07 18:22:53 +00:00
|
|
|
bdaddr_t *addr, u8 addr_type)
|
|
|
|
{
|
|
|
|
struct hci_conn_params *params;
|
|
|
|
|
|
|
|
if (is_connected(hdev, addr, addr_type))
|
|
|
|
return -EISCONN;
|
|
|
|
|
2015-10-16 07:07:54 +00:00
|
|
|
params = hci_conn_params_lookup(hdev, addr, addr_type);
|
|
|
|
if (!params) {
|
|
|
|
params = hci_conn_params_add(hdev, addr, addr_type);
|
|
|
|
if (!params)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* If we created new params, mark them to be deleted in
|
|
|
|
* hci_connect_le_scan_cleanup. It's different case than
|
|
|
|
* existing disabled params, those will stay after cleanup.
|
|
|
|
*/
|
|
|
|
params->auto_connect = HCI_AUTO_CONN_EXPLICIT;
|
|
|
|
}
|
2015-08-07 18:22:53 +00:00
|
|
|
|
2015-10-16 07:07:54 +00:00
|
|
|
/* We're trying to connect, so make sure params are at pend_le_conns */
|
2015-10-16 07:07:51 +00:00
|
|
|
if (params->auto_connect == HCI_AUTO_CONN_DISABLED ||
|
2015-10-16 07:07:54 +00:00
|
|
|
params->auto_connect == HCI_AUTO_CONN_REPORT ||
|
|
|
|
params->auto_connect == HCI_AUTO_CONN_EXPLICIT) {
|
Bluetooth: use RCU for hci_conn_params and iterate safely in hci_sync
hci_update_accept_list_sync iterates over hdev->pend_le_conns and
hdev->pend_le_reports, and waits for controller events in the loop body,
without holding hdev lock.
Meanwhile, these lists and the items may be modified e.g. by
le_scan_cleanup. This can invalidate the list cursor or any other item
in the list, resulting to invalid behavior (eg use-after-free).
Use RCU for the hci_conn_params action lists. Since the loop bodies in
hci_sync block and we cannot use RCU or hdev->lock for the whole loop,
copy list items first and then iterate on the copy. Only the flags field
is written from elsewhere, so READ_ONCE/WRITE_ONCE should guarantee we
read valid values.
Free params everywhere with hci_conn_params_free so the cleanup is
guaranteed to be done properly.
This fixes the following, which can be triggered e.g. by BlueZ new
mgmt-tester case "Add + Remove Device Nowait - Success", or by changing
hci_le_set_cig_params to always return false, and running iso-tester:
==================================================================
BUG: KASAN: slab-use-after-free in hci_update_passive_scan_sync (net/bluetooth/hci_sync.c:2536 net/bluetooth/hci_sync.c:2723 net/bluetooth/hci_sync.c:2841)
Read of size 8 at addr ffff888001265018 by task kworker/u3:0/32
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-1.fc38 04/01/2014
Workqueue: hci0 hci_cmd_sync_work
Call Trace:
<TASK>
dump_stack_lvl (./arch/x86/include/asm/irqflags.h:134 lib/dump_stack.c:107)
print_report (mm/kasan/report.c:320 mm/kasan/report.c:430)
? __virt_addr_valid (./include/linux/mmzone.h:1915 ./include/linux/mmzone.h:2011 arch/x86/mm/physaddr.c:65)
? hci_update_passive_scan_sync (net/bluetooth/hci_sync.c:2536 net/bluetooth/hci_sync.c:2723 net/bluetooth/hci_sync.c:2841)
kasan_report (mm/kasan/report.c:538)
? hci_update_passive_scan_sync (net/bluetooth/hci_sync.c:2536 net/bluetooth/hci_sync.c:2723 net/bluetooth/hci_sync.c:2841)
hci_update_passive_scan_sync (net/bluetooth/hci_sync.c:2536 net/bluetooth/hci_sync.c:2723 net/bluetooth/hci_sync.c:2841)
? __pfx_hci_update_passive_scan_sync (net/bluetooth/hci_sync.c:2780)
? mutex_lock (kernel/locking/mutex.c:282)
? __pfx_mutex_lock (kernel/locking/mutex.c:282)
? __pfx_mutex_unlock (kernel/locking/mutex.c:538)
? __pfx_update_passive_scan_sync (net/bluetooth/hci_sync.c:2861)
hci_cmd_sync_work (net/bluetooth/hci_sync.c:306)
process_one_work (./arch/x86/include/asm/preempt.h:27 kernel/workqueue.c:2399)
worker_thread (./include/linux/list.h:292 kernel/workqueue.c:2538)
? __pfx_worker_thread (kernel/workqueue.c:2480)
kthread (kernel/kthread.c:376)
? __pfx_kthread (kernel/kthread.c:331)
ret_from_fork (arch/x86/entry/entry_64.S:314)
</TASK>
Allocated by task 31:
kasan_save_stack (mm/kasan/common.c:46)
kasan_set_track (mm/kasan/common.c:52)
__kasan_kmalloc (mm/kasan/common.c:374 mm/kasan/common.c:383)
hci_conn_params_add (./include/linux/slab.h:580 ./include/linux/slab.h:720 net/bluetooth/hci_core.c:2277)
hci_connect_le_scan (net/bluetooth/hci_conn.c:1419 net/bluetooth/hci_conn.c:1589)
hci_connect_cis (net/bluetooth/hci_conn.c:2266)
iso_connect_cis (net/bluetooth/iso.c:390)
iso_sock_connect (net/bluetooth/iso.c:899)
__sys_connect (net/socket.c:2003 net/socket.c:2020)
__x64_sys_connect (net/socket.c:2027)
do_syscall_64 (arch/x86/entry/common.c:50 arch/x86/entry/common.c:80)
entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:120)
Freed by task 15:
kasan_save_stack (mm/kasan/common.c:46)
kasan_set_track (mm/kasan/common.c:52)
kasan_save_free_info (mm/kasan/generic.c:523)
__kasan_slab_free (mm/kasan/common.c:238 mm/kasan/common.c:200 mm/kasan/common.c:244)
__kmem_cache_free (mm/slub.c:1807 mm/slub.c:3787 mm/slub.c:3800)
hci_conn_params_del (net/bluetooth/hci_core.c:2323)
le_scan_cleanup (net/bluetooth/hci_conn.c:202)
process_one_work (./arch/x86/include/asm/preempt.h:27 kernel/workqueue.c:2399)
worker_thread (./include/linux/list.h:292 kernel/workqueue.c:2538)
kthread (kernel/kthread.c:376)
ret_from_fork (arch/x86/entry/entry_64.S:314)
==================================================================
Fixes: e8907f76544f ("Bluetooth: hci_sync: Make use of hci_cmd_sync_queue set 3")
Signed-off-by: Pauli Virtanen <pav@iki.fi>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2023-06-18 22:04:31 +00:00
|
|
|
hci_pend_le_list_del_init(params);
|
|
|
|
hci_pend_le_list_add(params, &hdev->pend_le_conns);
|
2015-08-07 18:22:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
params->explicit_connect = true;
|
|
|
|
|
|
|
|
BT_DBG("addr %pMR (type %u) auto_connect %u", addr, addr_type,
|
|
|
|
params->auto_connect);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-03-09 21:22:20 +00:00
|
|
|
static int qos_set_big(struct hci_dev *hdev, struct bt_iso_qos *qos)
|
|
|
|
{
|
2023-06-19 14:53:16 +00:00
|
|
|
struct hci_conn *conn;
|
|
|
|
u8 big;
|
2022-03-09 21:22:20 +00:00
|
|
|
|
|
|
|
/* Allocate a BIG if not set */
|
2023-03-31 15:38:01 +00:00
|
|
|
if (qos->bcast.big == BT_ISO_QOS_BIG_UNSET) {
|
2023-06-19 14:53:16 +00:00
|
|
|
for (big = 0x00; big < 0xef; big++) {
|
2022-03-09 21:22:20 +00:00
|
|
|
|
2023-06-19 14:53:16 +00:00
|
|
|
conn = hci_conn_hash_lookup_big(hdev, big);
|
|
|
|
if (!conn)
|
2022-03-09 21:22:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-06-19 14:53:16 +00:00
|
|
|
if (big == 0xef)
|
2022-03-09 21:22:20 +00:00
|
|
|
return -EADDRNOTAVAIL;
|
|
|
|
|
|
|
|
/* Update BIG */
|
2023-06-19 14:53:16 +00:00
|
|
|
qos->bcast.big = big;
|
2022-03-09 21:22:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int qos_set_bis(struct hci_dev *hdev, struct bt_iso_qos *qos)
|
|
|
|
{
|
2023-06-19 14:53:16 +00:00
|
|
|
struct hci_conn *conn;
|
|
|
|
u8 bis;
|
2022-03-09 21:22:20 +00:00
|
|
|
|
|
|
|
/* Allocate BIS if not set */
|
2023-03-31 15:38:01 +00:00
|
|
|
if (qos->bcast.bis == BT_ISO_QOS_BIS_UNSET) {
|
2023-10-03 14:37:39 +00:00
|
|
|
if (qos->bcast.big != BT_ISO_QOS_BIG_UNSET) {
|
|
|
|
conn = hci_conn_hash_lookup_big(hdev, qos->bcast.big);
|
|
|
|
|
|
|
|
if (conn) {
|
|
|
|
/* If the BIG handle is already matched to an advertising
|
|
|
|
* handle, do not allocate a new one.
|
|
|
|
*/
|
|
|
|
qos->bcast.bis = conn->iso_qos.bcast.bis;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-09 21:22:20 +00:00
|
|
|
/* Find an unused adv set to advertise BIS, skip instance 0x00
|
|
|
|
* since it is reserved as general purpose set.
|
|
|
|
*/
|
2023-06-19 14:53:16 +00:00
|
|
|
for (bis = 0x01; bis < hdev->le_num_of_adv_sets;
|
|
|
|
bis++) {
|
2022-03-09 21:22:20 +00:00
|
|
|
|
2023-06-19 14:53:16 +00:00
|
|
|
conn = hci_conn_hash_lookup_bis(hdev, BDADDR_ANY, bis);
|
|
|
|
if (!conn)
|
2022-03-09 21:22:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-06-19 14:53:16 +00:00
|
|
|
if (bis == hdev->le_num_of_adv_sets)
|
2022-03-09 21:22:20 +00:00
|
|
|
return -EADDRNOTAVAIL;
|
|
|
|
|
|
|
|
/* Update BIS */
|
2023-06-19 14:53:16 +00:00
|
|
|
qos->bcast.bis = bis;
|
2022-03-09 21:22:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This function requires the caller holds hdev->lock */
|
|
|
|
static struct hci_conn *hci_add_bis(struct hci_dev *hdev, bdaddr_t *dst,
|
Bluetooth: ISO: Add support for connecting multiple BISes
It is required for some configurations to have multiple BISes as part
of the same BIG.
Similar to the flow implemented for unicast, DEFER_SETUP will also be
used to bind multiple BISes for the same BIG, before starting Periodic
Advertising and creating the BIG.
The user will have to open a new socket for each BIS. By setting the
BT_DEFER_SETUP socket option and calling connect, a new connection
will be added for the BIG and advertising handle set by the socket
QoS parameters. Since all BISes will be bound for the same BIG and
advertising handle, the socket QoS options and base parameters should
match for all connections.
By calling connect on a socket that does not have the BT_DEFER_SETUP
option set, periodic advertising will be started and the BIG will
be created, with a BIS for each previously bound connection. Since
a BIG cannot be reconfigured with additional BISes after creation,
no more connections can be bound for the BIG after the start periodic
advertising and create BIG commands have been queued.
The bis_cleanup function has also been updated, so that the advertising
set and the BIG will not be terminated unless there are no more
bound or connected BISes.
The HCI_CONN_BIG_CREATED connection flag has been added to indicate
that the BIG has been successfully created. This flag is checked at
bis_cleanup, so that the BIG is only terminated if the
HCI_LE_Create_BIG_Complete has been received.
This implementation has been tested on hardware, using the "isotest"
tool with an additional command line option, to specify the number of
BISes to create as part of the desired BIG:
tools/isotest -i hci0 -s 00:00:00:00:00:00 -N 2 -G 1 -T 1
The btmon log shows that a BIG containing 2 BISes has been created:
< HCI Command: LE Create Broadcast Isochronous Group (0x08|0x0068) plen 31
Handle: 0x01
Advertising Handle: 0x01
Number of BIS: 2
SDU Interval: 10000 us (0x002710)
Maximum SDU size: 40
Maximum Latency: 10 ms (0x000a)
RTN: 0x02
PHY: LE 2M (0x02)
Packing: Sequential (0x00)
Framing: Unframed (0x00)
Encryption: 0x00
Broadcast Code: 00000000000000000000000000000000
> HCI Event: Command Status (0x0f) plen 4
LE Create Broadcast Isochronous Group (0x08|0x0068) ncmd 1
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 23
LE Broadcast Isochronous Group Complete (0x1b)
Status: Success (0x00)
Handle: 0x01
BIG Synchronization Delay: 1974 us (0x0007b6)
Transport Latency: 1974 us (0x0007b6)
PHY: LE 2M (0x02)
NSE: 3
BN: 1
PTO: 1
IRC: 3
Maximum PDU: 40
ISO Interval: 10.00 msec (0x0008)
Connection Handle #0: 10
Connection Handle #1: 11
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 10
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 10
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 11
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 11
< ISO Data TX: Handle 10 flags 0x02 dlen 44
< ISO Data TX: Handle 11 flags 0x02 dlen 44
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 10
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 11
Count: 1
Signed-off-by: Iulia Tanasescu <iulia.tanasescu@nxp.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2023-05-30 14:21:59 +00:00
|
|
|
struct bt_iso_qos *qos, __u8 base_len,
|
|
|
|
__u8 *base)
|
2022-03-09 21:22:20 +00:00
|
|
|
{
|
|
|
|
struct hci_conn *conn;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/* Let's make sure that le is enabled.*/
|
|
|
|
if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) {
|
|
|
|
if (lmp_le_capable(hdev))
|
|
|
|
return ERR_PTR(-ECONNREFUSED);
|
|
|
|
return ERR_PTR(-EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
|
|
|
err = qos_set_big(hdev, qos);
|
|
|
|
if (err)
|
|
|
|
return ERR_PTR(err);
|
|
|
|
|
|
|
|
err = qos_set_bis(hdev, qos);
|
|
|
|
if (err)
|
|
|
|
return ERR_PTR(err);
|
|
|
|
|
Bluetooth: ISO: Add support for connecting multiple BISes
It is required for some configurations to have multiple BISes as part
of the same BIG.
Similar to the flow implemented for unicast, DEFER_SETUP will also be
used to bind multiple BISes for the same BIG, before starting Periodic
Advertising and creating the BIG.
The user will have to open a new socket for each BIS. By setting the
BT_DEFER_SETUP socket option and calling connect, a new connection
will be added for the BIG and advertising handle set by the socket
QoS parameters. Since all BISes will be bound for the same BIG and
advertising handle, the socket QoS options and base parameters should
match for all connections.
By calling connect on a socket that does not have the BT_DEFER_SETUP
option set, periodic advertising will be started and the BIG will
be created, with a BIS for each previously bound connection. Since
a BIG cannot be reconfigured with additional BISes after creation,
no more connections can be bound for the BIG after the start periodic
advertising and create BIG commands have been queued.
The bis_cleanup function has also been updated, so that the advertising
set and the BIG will not be terminated unless there are no more
bound or connected BISes.
The HCI_CONN_BIG_CREATED connection flag has been added to indicate
that the BIG has been successfully created. This flag is checked at
bis_cleanup, so that the BIG is only terminated if the
HCI_LE_Create_BIG_Complete has been received.
This implementation has been tested on hardware, using the "isotest"
tool with an additional command line option, to specify the number of
BISes to create as part of the desired BIG:
tools/isotest -i hci0 -s 00:00:00:00:00:00 -N 2 -G 1 -T 1
The btmon log shows that a BIG containing 2 BISes has been created:
< HCI Command: LE Create Broadcast Isochronous Group (0x08|0x0068) plen 31
Handle: 0x01
Advertising Handle: 0x01
Number of BIS: 2
SDU Interval: 10000 us (0x002710)
Maximum SDU size: 40
Maximum Latency: 10 ms (0x000a)
RTN: 0x02
PHY: LE 2M (0x02)
Packing: Sequential (0x00)
Framing: Unframed (0x00)
Encryption: 0x00
Broadcast Code: 00000000000000000000000000000000
> HCI Event: Command Status (0x0f) plen 4
LE Create Broadcast Isochronous Group (0x08|0x0068) ncmd 1
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 23
LE Broadcast Isochronous Group Complete (0x1b)
Status: Success (0x00)
Handle: 0x01
BIG Synchronization Delay: 1974 us (0x0007b6)
Transport Latency: 1974 us (0x0007b6)
PHY: LE 2M (0x02)
NSE: 3
BN: 1
PTO: 1
IRC: 3
Maximum PDU: 40
ISO Interval: 10.00 msec (0x0008)
Connection Handle #0: 10
Connection Handle #1: 11
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 10
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 10
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 11
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 11
< ISO Data TX: Handle 10 flags 0x02 dlen 44
< ISO Data TX: Handle 11 flags 0x02 dlen 44
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 10
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 11
Count: 1
Signed-off-by: Iulia Tanasescu <iulia.tanasescu@nxp.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2023-05-30 14:21:59 +00:00
|
|
|
/* Check if the LE Create BIG command has already been sent */
|
|
|
|
conn = hci_conn_hash_lookup_per_adv_bis(hdev, dst, qos->bcast.big,
|
|
|
|
qos->bcast.big);
|
|
|
|
if (conn)
|
2022-03-09 21:22:20 +00:00
|
|
|
return ERR_PTR(-EADDRINUSE);
|
|
|
|
|
Bluetooth: ISO: Add support for connecting multiple BISes
It is required for some configurations to have multiple BISes as part
of the same BIG.
Similar to the flow implemented for unicast, DEFER_SETUP will also be
used to bind multiple BISes for the same BIG, before starting Periodic
Advertising and creating the BIG.
The user will have to open a new socket for each BIS. By setting the
BT_DEFER_SETUP socket option and calling connect, a new connection
will be added for the BIG and advertising handle set by the socket
QoS parameters. Since all BISes will be bound for the same BIG and
advertising handle, the socket QoS options and base parameters should
match for all connections.
By calling connect on a socket that does not have the BT_DEFER_SETUP
option set, periodic advertising will be started and the BIG will
be created, with a BIS for each previously bound connection. Since
a BIG cannot be reconfigured with additional BISes after creation,
no more connections can be bound for the BIG after the start periodic
advertising and create BIG commands have been queued.
The bis_cleanup function has also been updated, so that the advertising
set and the BIG will not be terminated unless there are no more
bound or connected BISes.
The HCI_CONN_BIG_CREATED connection flag has been added to indicate
that the BIG has been successfully created. This flag is checked at
bis_cleanup, so that the BIG is only terminated if the
HCI_LE_Create_BIG_Complete has been received.
This implementation has been tested on hardware, using the "isotest"
tool with an additional command line option, to specify the number of
BISes to create as part of the desired BIG:
tools/isotest -i hci0 -s 00:00:00:00:00:00 -N 2 -G 1 -T 1
The btmon log shows that a BIG containing 2 BISes has been created:
< HCI Command: LE Create Broadcast Isochronous Group (0x08|0x0068) plen 31
Handle: 0x01
Advertising Handle: 0x01
Number of BIS: 2
SDU Interval: 10000 us (0x002710)
Maximum SDU size: 40
Maximum Latency: 10 ms (0x000a)
RTN: 0x02
PHY: LE 2M (0x02)
Packing: Sequential (0x00)
Framing: Unframed (0x00)
Encryption: 0x00
Broadcast Code: 00000000000000000000000000000000
> HCI Event: Command Status (0x0f) plen 4
LE Create Broadcast Isochronous Group (0x08|0x0068) ncmd 1
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 23
LE Broadcast Isochronous Group Complete (0x1b)
Status: Success (0x00)
Handle: 0x01
BIG Synchronization Delay: 1974 us (0x0007b6)
Transport Latency: 1974 us (0x0007b6)
PHY: LE 2M (0x02)
NSE: 3
BN: 1
PTO: 1
IRC: 3
Maximum PDU: 40
ISO Interval: 10.00 msec (0x0008)
Connection Handle #0: 10
Connection Handle #1: 11
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 10
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 10
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 11
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 11
< ISO Data TX: Handle 10 flags 0x02 dlen 44
< ISO Data TX: Handle 11 flags 0x02 dlen 44
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 10
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 11
Count: 1
Signed-off-by: Iulia Tanasescu <iulia.tanasescu@nxp.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2023-05-30 14:21:59 +00:00
|
|
|
/* Check BIS settings against other bound BISes, since all
|
|
|
|
* BISes in a BIG must have the same value for all parameters
|
|
|
|
*/
|
2023-06-19 14:53:16 +00:00
|
|
|
conn = hci_conn_hash_lookup_big(hdev, qos->bcast.big);
|
Bluetooth: ISO: Add support for connecting multiple BISes
It is required for some configurations to have multiple BISes as part
of the same BIG.
Similar to the flow implemented for unicast, DEFER_SETUP will also be
used to bind multiple BISes for the same BIG, before starting Periodic
Advertising and creating the BIG.
The user will have to open a new socket for each BIS. By setting the
BT_DEFER_SETUP socket option and calling connect, a new connection
will be added for the BIG and advertising handle set by the socket
QoS parameters. Since all BISes will be bound for the same BIG and
advertising handle, the socket QoS options and base parameters should
match for all connections.
By calling connect on a socket that does not have the BT_DEFER_SETUP
option set, periodic advertising will be started and the BIG will
be created, with a BIS for each previously bound connection. Since
a BIG cannot be reconfigured with additional BISes after creation,
no more connections can be bound for the BIG after the start periodic
advertising and create BIG commands have been queued.
The bis_cleanup function has also been updated, so that the advertising
set and the BIG will not be terminated unless there are no more
bound or connected BISes.
The HCI_CONN_BIG_CREATED connection flag has been added to indicate
that the BIG has been successfully created. This flag is checked at
bis_cleanup, so that the BIG is only terminated if the
HCI_LE_Create_BIG_Complete has been received.
This implementation has been tested on hardware, using the "isotest"
tool with an additional command line option, to specify the number of
BISes to create as part of the desired BIG:
tools/isotest -i hci0 -s 00:00:00:00:00:00 -N 2 -G 1 -T 1
The btmon log shows that a BIG containing 2 BISes has been created:
< HCI Command: LE Create Broadcast Isochronous Group (0x08|0x0068) plen 31
Handle: 0x01
Advertising Handle: 0x01
Number of BIS: 2
SDU Interval: 10000 us (0x002710)
Maximum SDU size: 40
Maximum Latency: 10 ms (0x000a)
RTN: 0x02
PHY: LE 2M (0x02)
Packing: Sequential (0x00)
Framing: Unframed (0x00)
Encryption: 0x00
Broadcast Code: 00000000000000000000000000000000
> HCI Event: Command Status (0x0f) plen 4
LE Create Broadcast Isochronous Group (0x08|0x0068) ncmd 1
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 23
LE Broadcast Isochronous Group Complete (0x1b)
Status: Success (0x00)
Handle: 0x01
BIG Synchronization Delay: 1974 us (0x0007b6)
Transport Latency: 1974 us (0x0007b6)
PHY: LE 2M (0x02)
NSE: 3
BN: 1
PTO: 1
IRC: 3
Maximum PDU: 40
ISO Interval: 10.00 msec (0x0008)
Connection Handle #0: 10
Connection Handle #1: 11
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 10
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 10
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 11
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 11
< ISO Data TX: Handle 10 flags 0x02 dlen 44
< ISO Data TX: Handle 11 flags 0x02 dlen 44
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 10
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 11
Count: 1
Signed-off-by: Iulia Tanasescu <iulia.tanasescu@nxp.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2023-05-30 14:21:59 +00:00
|
|
|
|
|
|
|
if (conn && (memcmp(qos, &conn->iso_qos, sizeof(*qos)) ||
|
|
|
|
base_len != conn->le_per_adv_data_len ||
|
|
|
|
memcmp(conn->le_per_adv_data, base, base_len)))
|
2022-03-09 21:22:20 +00:00
|
|
|
return ERR_PTR(-EADDRINUSE);
|
|
|
|
|
2023-10-11 09:57:31 +00:00
|
|
|
conn = hci_conn_add_unset(hdev, ISO_LINK, dst, HCI_ROLE_MASTER);
|
2024-05-04 19:23:29 +00:00
|
|
|
if (IS_ERR(conn))
|
|
|
|
return conn;
|
2022-03-09 21:22:20 +00:00
|
|
|
|
|
|
|
conn->state = BT_CONNECT;
|
|
|
|
|
|
|
|
hci_conn_hold(conn);
|
|
|
|
return conn;
|
|
|
|
}
|
|
|
|
|
2015-08-07 18:22:53 +00:00
|
|
|
/* This function requires the caller holds hdev->lock */
|
|
|
|
struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst,
|
|
|
|
u8 dst_type, u8 sec_level,
|
2020-06-17 14:39:19 +00:00
|
|
|
u16 conn_timeout,
|
|
|
|
enum conn_reasons conn_reason)
|
2015-08-07 18:22:53 +00:00
|
|
|
{
|
|
|
|
struct hci_conn *conn;
|
|
|
|
|
|
|
|
/* Let's make sure that le is enabled.*/
|
|
|
|
if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) {
|
|
|
|
if (lmp_le_capable(hdev))
|
|
|
|
return ERR_PTR(-ECONNREFUSED);
|
|
|
|
|
|
|
|
return ERR_PTR(-EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Some devices send ATT messages as soon as the physical link is
|
|
|
|
* established. To be able to handle these ATT messages, the user-
|
|
|
|
* space first establishes the connection and then starts the pairing
|
|
|
|
* process.
|
|
|
|
*
|
|
|
|
* So if a hci_conn object already exists for the following connection
|
|
|
|
* attempt, we simply update pending_sec_level and auth_type fields
|
|
|
|
* and return the object found.
|
|
|
|
*/
|
2015-10-21 15:03:01 +00:00
|
|
|
conn = hci_conn_hash_lookup_le(hdev, dst, dst_type);
|
2015-08-07 18:22:53 +00:00
|
|
|
if (conn) {
|
|
|
|
if (conn->pending_sec_level < sec_level)
|
|
|
|
conn->pending_sec_level = sec_level;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
BT_DBG("requesting refresh of dst_addr");
|
|
|
|
|
2023-10-11 09:57:31 +00:00
|
|
|
conn = hci_conn_add_unset(hdev, LE_LINK, dst, HCI_ROLE_MASTER);
|
2024-05-04 19:23:29 +00:00
|
|
|
if (IS_ERR(conn))
|
|
|
|
return conn;
|
2015-08-07 18:22:53 +00:00
|
|
|
|
2019-11-21 20:20:36 +00:00
|
|
|
if (hci_explicit_conn_params_set(hdev, dst, dst_type) < 0) {
|
|
|
|
hci_conn_del(conn);
|
2015-08-07 18:22:53 +00:00
|
|
|
return ERR_PTR(-EBUSY);
|
2019-11-21 20:20:36 +00:00
|
|
|
}
|
2015-08-07 18:22:53 +00:00
|
|
|
|
|
|
|
conn->state = BT_CONNECT;
|
|
|
|
set_bit(HCI_CONN_SCANNING, &conn->flags);
|
|
|
|
conn->dst_type = dst_type;
|
|
|
|
conn->sec_level = BT_SECURITY_LOW;
|
|
|
|
conn->pending_sec_level = sec_level;
|
|
|
|
conn->conn_timeout = conn_timeout;
|
2020-06-17 14:39:19 +00:00
|
|
|
conn->conn_reason = conn_reason;
|
2015-08-07 18:22:53 +00:00
|
|
|
|
2021-10-27 23:58:43 +00:00
|
|
|
hci_update_passive_scan(hdev);
|
2015-11-11 06:11:20 +00:00
|
|
|
|
2015-08-07 18:22:53 +00:00
|
|
|
done:
|
|
|
|
hci_conn_hold(conn);
|
|
|
|
return conn;
|
|
|
|
}
|
|
|
|
|
2014-02-26 23:21:44 +00:00
|
|
|
struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
|
2020-06-17 14:39:19 +00:00
|
|
|
u8 sec_level, u8 auth_type,
|
2024-02-07 20:26:20 +00:00
|
|
|
enum conn_reasons conn_reason, u16 timeout)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct hci_conn *acl;
|
2011-02-11 01:38:47 +00:00
|
|
|
|
2015-03-13 09:11:00 +00:00
|
|
|
if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) {
|
2015-02-11 11:31:41 +00:00
|
|
|
if (lmp_bredr_capable(hdev))
|
|
|
|
return ERR_PTR(-ECONNREFUSED);
|
|
|
|
|
2014-07-18 08:15:26 +00:00
|
|
|
return ERR_PTR(-EOPNOTSUPP);
|
2015-02-11 11:31:41 +00:00
|
|
|
}
|
2013-10-02 10:43:13 +00:00
|
|
|
|
2023-10-01 08:59:58 +00:00
|
|
|
/* Reject outgoing connection to device with same BD ADDR against
|
|
|
|
* CVE-2020-26555
|
|
|
|
*/
|
|
|
|
if (!bacmp(&hdev->bdaddr, dst)) {
|
|
|
|
bt_dev_dbg(hdev, "Reject connection with same BD_ADDR %pMR\n",
|
|
|
|
dst);
|
|
|
|
return ERR_PTR(-ECONNREFUSED);
|
|
|
|
}
|
|
|
|
|
2010-12-01 14:58:25 +00:00
|
|
|
acl = hci_conn_hash_lookup_ba(hdev, ACL_LINK, dst);
|
|
|
|
if (!acl) {
|
2023-10-11 09:57:31 +00:00
|
|
|
acl = hci_conn_add_unset(hdev, ACL_LINK, dst, HCI_ROLE_MASTER);
|
2024-05-04 19:23:29 +00:00
|
|
|
if (IS_ERR(acl))
|
|
|
|
return acl;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
hci_conn_hold(acl);
|
|
|
|
|
2020-06-17 14:39:19 +00:00
|
|
|
acl->conn_reason = conn_reason;
|
2008-09-09 05:19:20 +00:00
|
|
|
if (acl->state == BT_OPEN || acl->state == BT_CLOSED) {
|
2024-02-06 11:08:13 +00:00
|
|
|
int err;
|
|
|
|
|
2011-01-19 06:36:52 +00:00
|
|
|
acl->sec_level = BT_SECURITY_LOW;
|
|
|
|
acl->pending_sec_level = sec_level;
|
2008-09-09 05:19:20 +00:00
|
|
|
acl->auth_type = auth_type;
|
2024-02-07 20:26:20 +00:00
|
|
|
acl->conn_timeout = timeout;
|
2024-02-06 11:08:13 +00:00
|
|
|
|
2024-02-09 14:08:06 +00:00
|
|
|
err = hci_connect_acl_sync(hdev, acl);
|
2024-02-06 11:08:13 +00:00
|
|
|
if (err) {
|
|
|
|
hci_conn_del(acl);
|
|
|
|
return ERR_PTR(err);
|
|
|
|
}
|
2008-09-09 05:19:20 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-07-29 01:35:59 +00:00
|
|
|
return acl;
|
|
|
|
}
|
|
|
|
|
2023-04-11 23:02:22 +00:00
|
|
|
static struct hci_link *hci_conn_link(struct hci_conn *parent,
|
|
|
|
struct hci_conn *conn)
|
|
|
|
{
|
|
|
|
struct hci_dev *hdev = parent->hdev;
|
|
|
|
struct hci_link *link;
|
|
|
|
|
|
|
|
bt_dev_dbg(hdev, "parent %p hcon %p", parent, conn);
|
|
|
|
|
|
|
|
if (conn->link)
|
|
|
|
return conn->link;
|
|
|
|
|
|
|
|
if (conn->parent)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
link = kzalloc(sizeof(*link), GFP_KERNEL);
|
|
|
|
if (!link)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
link->conn = hci_conn_hold(conn);
|
|
|
|
conn->link = link;
|
|
|
|
conn->parent = hci_conn_get(parent);
|
|
|
|
|
|
|
|
/* Use list_add_tail_rcu append to the list */
|
|
|
|
list_add_tail_rcu(&link->list, &parent->link_list);
|
|
|
|
|
|
|
|
return link;
|
|
|
|
}
|
|
|
|
|
2013-08-19 12:23:59 +00:00
|
|
|
struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
|
2024-02-07 20:26:20 +00:00
|
|
|
__u16 setting, struct bt_codec *codec,
|
|
|
|
u16 timeout)
|
2012-07-29 01:35:59 +00:00
|
|
|
{
|
|
|
|
struct hci_conn *acl;
|
|
|
|
struct hci_conn *sco;
|
2023-04-11 23:02:22 +00:00
|
|
|
struct hci_link *link;
|
2012-07-29 01:35:59 +00:00
|
|
|
|
2020-06-17 14:39:19 +00:00
|
|
|
acl = hci_connect_acl(hdev, dst, BT_SECURITY_LOW, HCI_AT_NO_BONDING,
|
2024-02-07 20:26:20 +00:00
|
|
|
CONN_REASON_SCO_CONNECT, timeout);
|
2012-07-29 01:35:59 +00:00
|
|
|
if (IS_ERR(acl))
|
2007-07-11 07:51:55 +00:00
|
|
|
return acl;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2010-12-01 14:58:25 +00:00
|
|
|
sco = hci_conn_hash_lookup_ba(hdev, type, dst);
|
|
|
|
if (!sco) {
|
2023-10-11 09:57:31 +00:00
|
|
|
sco = hci_conn_add_unset(hdev, type, dst, HCI_ROLE_MASTER);
|
2024-05-04 19:23:29 +00:00
|
|
|
if (IS_ERR(sco)) {
|
2013-04-06 18:28:37 +00:00
|
|
|
hci_conn_drop(acl);
|
2024-05-04 19:23:29 +00:00
|
|
|
return sco;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2007-07-11 07:51:55 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2023-04-11 23:02:22 +00:00
|
|
|
link = hci_conn_link(acl, sco);
|
|
|
|
if (!link) {
|
|
|
|
hci_conn_drop(acl);
|
|
|
|
hci_conn_drop(sco);
|
2023-07-11 13:13:53 +00:00
|
|
|
return ERR_PTR(-ENOLINK);
|
2023-04-11 23:02:22 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2013-08-19 12:23:59 +00:00
|
|
|
sco->setting = setting;
|
2021-09-07 10:12:43 +00:00
|
|
|
sco->codec = *codec;
|
2013-08-19 12:23:59 +00:00
|
|
|
|
2007-07-11 07:51:55 +00:00
|
|
|
if (acl->state == BT_CONNECTED &&
|
2012-05-17 03:36:25 +00:00
|
|
|
(sco->state == BT_OPEN || sco->state == BT_CLOSED)) {
|
2012-01-16 04:47:28 +00:00
|
|
|
set_bit(HCI_CONN_POWER_SAVE, &acl->flags);
|
2011-05-24 01:06:04 +00:00
|
|
|
hci_conn_enter_active_mode(acl, BT_POWER_FORCE_ACTIVE_ON);
|
2009-11-13 22:16:32 +00:00
|
|
|
|
2012-01-16 04:10:31 +00:00
|
|
|
if (test_bit(HCI_CONN_MODE_CHANGE_PEND, &acl->flags)) {
|
2010-07-26 14:06:00 +00:00
|
|
|
/* defer SCO setup until mode change completed */
|
2012-01-16 04:10:31 +00:00
|
|
|
set_bit(HCI_CONN_SCO_SETUP_PEND, &acl->flags);
|
2010-07-26 14:06:00 +00:00
|
|
|
return sco;
|
|
|
|
}
|
|
|
|
|
|
|
|
hci_sco_setup(acl, 0x00);
|
2007-10-20 12:55:10 +00:00
|
|
|
}
|
2007-07-11 07:51:55 +00:00
|
|
|
|
|
|
|
return sco;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2022-03-09 21:22:20 +00:00
|
|
|
static int hci_le_create_big(struct hci_conn *conn, struct bt_iso_qos *qos)
|
|
|
|
{
|
|
|
|
struct hci_dev *hdev = conn->hdev;
|
|
|
|
struct hci_cp_le_create_big cp;
|
Bluetooth: ISO: Add support for connecting multiple BISes
It is required for some configurations to have multiple BISes as part
of the same BIG.
Similar to the flow implemented for unicast, DEFER_SETUP will also be
used to bind multiple BISes for the same BIG, before starting Periodic
Advertising and creating the BIG.
The user will have to open a new socket for each BIS. By setting the
BT_DEFER_SETUP socket option and calling connect, a new connection
will be added for the BIG and advertising handle set by the socket
QoS parameters. Since all BISes will be bound for the same BIG and
advertising handle, the socket QoS options and base parameters should
match for all connections.
By calling connect on a socket that does not have the BT_DEFER_SETUP
option set, periodic advertising will be started and the BIG will
be created, with a BIS for each previously bound connection. Since
a BIG cannot be reconfigured with additional BISes after creation,
no more connections can be bound for the BIG after the start periodic
advertising and create BIG commands have been queued.
The bis_cleanup function has also been updated, so that the advertising
set and the BIG will not be terminated unless there are no more
bound or connected BISes.
The HCI_CONN_BIG_CREATED connection flag has been added to indicate
that the BIG has been successfully created. This flag is checked at
bis_cleanup, so that the BIG is only terminated if the
HCI_LE_Create_BIG_Complete has been received.
This implementation has been tested on hardware, using the "isotest"
tool with an additional command line option, to specify the number of
BISes to create as part of the desired BIG:
tools/isotest -i hci0 -s 00:00:00:00:00:00 -N 2 -G 1 -T 1
The btmon log shows that a BIG containing 2 BISes has been created:
< HCI Command: LE Create Broadcast Isochronous Group (0x08|0x0068) plen 31
Handle: 0x01
Advertising Handle: 0x01
Number of BIS: 2
SDU Interval: 10000 us (0x002710)
Maximum SDU size: 40
Maximum Latency: 10 ms (0x000a)
RTN: 0x02
PHY: LE 2M (0x02)
Packing: Sequential (0x00)
Framing: Unframed (0x00)
Encryption: 0x00
Broadcast Code: 00000000000000000000000000000000
> HCI Event: Command Status (0x0f) plen 4
LE Create Broadcast Isochronous Group (0x08|0x0068) ncmd 1
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 23
LE Broadcast Isochronous Group Complete (0x1b)
Status: Success (0x00)
Handle: 0x01
BIG Synchronization Delay: 1974 us (0x0007b6)
Transport Latency: 1974 us (0x0007b6)
PHY: LE 2M (0x02)
NSE: 3
BN: 1
PTO: 1
IRC: 3
Maximum PDU: 40
ISO Interval: 10.00 msec (0x0008)
Connection Handle #0: 10
Connection Handle #1: 11
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 10
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 10
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 11
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 11
< ISO Data TX: Handle 10 flags 0x02 dlen 44
< ISO Data TX: Handle 11 flags 0x02 dlen 44
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 10
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 11
Count: 1
Signed-off-by: Iulia Tanasescu <iulia.tanasescu@nxp.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2023-05-30 14:21:59 +00:00
|
|
|
struct iso_list_data data;
|
2022-03-09 21:22:20 +00:00
|
|
|
|
|
|
|
memset(&cp, 0, sizeof(cp));
|
|
|
|
|
Bluetooth: ISO: Add support for connecting multiple BISes
It is required for some configurations to have multiple BISes as part
of the same BIG.
Similar to the flow implemented for unicast, DEFER_SETUP will also be
used to bind multiple BISes for the same BIG, before starting Periodic
Advertising and creating the BIG.
The user will have to open a new socket for each BIS. By setting the
BT_DEFER_SETUP socket option and calling connect, a new connection
will be added for the BIG and advertising handle set by the socket
QoS parameters. Since all BISes will be bound for the same BIG and
advertising handle, the socket QoS options and base parameters should
match for all connections.
By calling connect on a socket that does not have the BT_DEFER_SETUP
option set, periodic advertising will be started and the BIG will
be created, with a BIS for each previously bound connection. Since
a BIG cannot be reconfigured with additional BISes after creation,
no more connections can be bound for the BIG after the start periodic
advertising and create BIG commands have been queued.
The bis_cleanup function has also been updated, so that the advertising
set and the BIG will not be terminated unless there are no more
bound or connected BISes.
The HCI_CONN_BIG_CREATED connection flag has been added to indicate
that the BIG has been successfully created. This flag is checked at
bis_cleanup, so that the BIG is only terminated if the
HCI_LE_Create_BIG_Complete has been received.
This implementation has been tested on hardware, using the "isotest"
tool with an additional command line option, to specify the number of
BISes to create as part of the desired BIG:
tools/isotest -i hci0 -s 00:00:00:00:00:00 -N 2 -G 1 -T 1
The btmon log shows that a BIG containing 2 BISes has been created:
< HCI Command: LE Create Broadcast Isochronous Group (0x08|0x0068) plen 31
Handle: 0x01
Advertising Handle: 0x01
Number of BIS: 2
SDU Interval: 10000 us (0x002710)
Maximum SDU size: 40
Maximum Latency: 10 ms (0x000a)
RTN: 0x02
PHY: LE 2M (0x02)
Packing: Sequential (0x00)
Framing: Unframed (0x00)
Encryption: 0x00
Broadcast Code: 00000000000000000000000000000000
> HCI Event: Command Status (0x0f) plen 4
LE Create Broadcast Isochronous Group (0x08|0x0068) ncmd 1
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 23
LE Broadcast Isochronous Group Complete (0x1b)
Status: Success (0x00)
Handle: 0x01
BIG Synchronization Delay: 1974 us (0x0007b6)
Transport Latency: 1974 us (0x0007b6)
PHY: LE 2M (0x02)
NSE: 3
BN: 1
PTO: 1
IRC: 3
Maximum PDU: 40
ISO Interval: 10.00 msec (0x0008)
Connection Handle #0: 10
Connection Handle #1: 11
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 10
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 10
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 11
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 11
< ISO Data TX: Handle 10 flags 0x02 dlen 44
< ISO Data TX: Handle 11 flags 0x02 dlen 44
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 10
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 11
Count: 1
Signed-off-by: Iulia Tanasescu <iulia.tanasescu@nxp.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2023-05-30 14:21:59 +00:00
|
|
|
data.big = qos->bcast.big;
|
|
|
|
data.bis = qos->bcast.bis;
|
|
|
|
data.count = 0;
|
|
|
|
|
|
|
|
/* Create a BIS for each bound connection */
|
|
|
|
hci_conn_hash_list_state(hdev, bis_list, ISO_LINK,
|
|
|
|
BT_BOUND, &data);
|
|
|
|
|
2023-03-31 15:38:01 +00:00
|
|
|
cp.handle = qos->bcast.big;
|
|
|
|
cp.adv_handle = qos->bcast.bis;
|
Bluetooth: ISO: Add support for connecting multiple BISes
It is required for some configurations to have multiple BISes as part
of the same BIG.
Similar to the flow implemented for unicast, DEFER_SETUP will also be
used to bind multiple BISes for the same BIG, before starting Periodic
Advertising and creating the BIG.
The user will have to open a new socket for each BIS. By setting the
BT_DEFER_SETUP socket option and calling connect, a new connection
will be added for the BIG and advertising handle set by the socket
QoS parameters. Since all BISes will be bound for the same BIG and
advertising handle, the socket QoS options and base parameters should
match for all connections.
By calling connect on a socket that does not have the BT_DEFER_SETUP
option set, periodic advertising will be started and the BIG will
be created, with a BIS for each previously bound connection. Since
a BIG cannot be reconfigured with additional BISes after creation,
no more connections can be bound for the BIG after the start periodic
advertising and create BIG commands have been queued.
The bis_cleanup function has also been updated, so that the advertising
set and the BIG will not be terminated unless there are no more
bound or connected BISes.
The HCI_CONN_BIG_CREATED connection flag has been added to indicate
that the BIG has been successfully created. This flag is checked at
bis_cleanup, so that the BIG is only terminated if the
HCI_LE_Create_BIG_Complete has been received.
This implementation has been tested on hardware, using the "isotest"
tool with an additional command line option, to specify the number of
BISes to create as part of the desired BIG:
tools/isotest -i hci0 -s 00:00:00:00:00:00 -N 2 -G 1 -T 1
The btmon log shows that a BIG containing 2 BISes has been created:
< HCI Command: LE Create Broadcast Isochronous Group (0x08|0x0068) plen 31
Handle: 0x01
Advertising Handle: 0x01
Number of BIS: 2
SDU Interval: 10000 us (0x002710)
Maximum SDU size: 40
Maximum Latency: 10 ms (0x000a)
RTN: 0x02
PHY: LE 2M (0x02)
Packing: Sequential (0x00)
Framing: Unframed (0x00)
Encryption: 0x00
Broadcast Code: 00000000000000000000000000000000
> HCI Event: Command Status (0x0f) plen 4
LE Create Broadcast Isochronous Group (0x08|0x0068) ncmd 1
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 23
LE Broadcast Isochronous Group Complete (0x1b)
Status: Success (0x00)
Handle: 0x01
BIG Synchronization Delay: 1974 us (0x0007b6)
Transport Latency: 1974 us (0x0007b6)
PHY: LE 2M (0x02)
NSE: 3
BN: 1
PTO: 1
IRC: 3
Maximum PDU: 40
ISO Interval: 10.00 msec (0x0008)
Connection Handle #0: 10
Connection Handle #1: 11
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 10
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 10
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 11
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 11
< ISO Data TX: Handle 10 flags 0x02 dlen 44
< ISO Data TX: Handle 11 flags 0x02 dlen 44
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 10
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 11
Count: 1
Signed-off-by: Iulia Tanasescu <iulia.tanasescu@nxp.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2023-05-30 14:21:59 +00:00
|
|
|
cp.num_bis = data.count;
|
2023-03-31 15:38:01 +00:00
|
|
|
hci_cpu_to_le24(qos->bcast.out.interval, cp.bis.sdu_interval);
|
|
|
|
cp.bis.sdu = cpu_to_le16(qos->bcast.out.sdu);
|
|
|
|
cp.bis.latency = cpu_to_le16(qos->bcast.out.latency);
|
|
|
|
cp.bis.rtn = qos->bcast.out.rtn;
|
|
|
|
cp.bis.phy = qos->bcast.out.phy;
|
|
|
|
cp.bis.packing = qos->bcast.packing;
|
|
|
|
cp.bis.framing = qos->bcast.framing;
|
|
|
|
cp.bis.encryption = qos->bcast.encryption;
|
|
|
|
memcpy(cp.bis.bcode, qos->bcast.bcode, sizeof(cp.bis.bcode));
|
2022-03-09 21:22:20 +00:00
|
|
|
|
|
|
|
return hci_send_cmd(hdev, HCI_OP_LE_CREATE_BIG, sizeof(cp), &cp);
|
|
|
|
}
|
|
|
|
|
2023-08-04 21:54:09 +00:00
|
|
|
static int set_cig_params_sync(struct hci_dev *hdev, void *data)
|
2023-06-01 06:34:43 +00:00
|
|
|
{
|
2024-05-02 16:22:00 +00:00
|
|
|
DEFINE_FLEX(struct hci_cp_le_set_cig_params, pdu, cis, num_cis, 0x1f);
|
2023-08-04 23:23:41 +00:00
|
|
|
u8 cig_id = PTR_UINT(data);
|
2023-08-04 21:54:09 +00:00
|
|
|
struct hci_conn *conn;
|
|
|
|
struct bt_iso_qos *qos;
|
2024-05-02 16:22:00 +00:00
|
|
|
u8 aux_num_cis = 0;
|
2023-08-04 21:54:09 +00:00
|
|
|
u8 cis_id;
|
2023-06-01 06:34:43 +00:00
|
|
|
|
2023-08-04 21:54:09 +00:00
|
|
|
conn = hci_conn_hash_lookup_cig(hdev, cig_id);
|
|
|
|
if (!conn)
|
|
|
|
return 0;
|
2023-06-01 06:34:43 +00:00
|
|
|
|
2023-08-04 21:54:09 +00:00
|
|
|
qos = &conn->iso_qos;
|
2024-05-02 16:22:00 +00:00
|
|
|
pdu->cig_id = cig_id;
|
|
|
|
hci_cpu_to_le24(qos->ucast.out.interval, pdu->c_interval);
|
|
|
|
hci_cpu_to_le24(qos->ucast.in.interval, pdu->p_interval);
|
|
|
|
pdu->sca = qos->ucast.sca;
|
|
|
|
pdu->packing = qos->ucast.packing;
|
|
|
|
pdu->framing = qos->ucast.framing;
|
|
|
|
pdu->c_latency = cpu_to_le16(qos->ucast.out.latency);
|
|
|
|
pdu->p_latency = cpu_to_le16(qos->ucast.in.latency);
|
2023-06-01 06:34:43 +00:00
|
|
|
|
2023-08-04 21:54:09 +00:00
|
|
|
/* Reprogram all CIS(s) with the same CIG, valid range are:
|
|
|
|
* num_cis: 0x00 to 0x1F
|
|
|
|
* cis_id: 0x00 to 0xEF
|
|
|
|
*/
|
|
|
|
for (cis_id = 0x00; cis_id < 0xf0 &&
|
2024-05-02 16:22:00 +00:00
|
|
|
aux_num_cis < pdu->num_cis; cis_id++) {
|
2023-08-04 21:54:09 +00:00
|
|
|
struct hci_cis_params *cis;
|
|
|
|
|
|
|
|
conn = hci_conn_hash_lookup_cis(hdev, NULL, 0, cig_id, cis_id);
|
|
|
|
if (!conn)
|
|
|
|
continue;
|
2023-06-01 06:34:43 +00:00
|
|
|
|
2023-08-04 21:54:09 +00:00
|
|
|
qos = &conn->iso_qos;
|
|
|
|
|
2024-05-02 16:22:00 +00:00
|
|
|
cis = &pdu->cis[aux_num_cis++];
|
2023-08-04 21:54:09 +00:00
|
|
|
cis->cis_id = cis_id;
|
|
|
|
cis->c_sdu = cpu_to_le16(conn->iso_qos.ucast.out.sdu);
|
|
|
|
cis->p_sdu = cpu_to_le16(conn->iso_qos.ucast.in.sdu);
|
|
|
|
cis->c_phy = qos->ucast.out.phy ? qos->ucast.out.phy :
|
|
|
|
qos->ucast.in.phy;
|
|
|
|
cis->p_phy = qos->ucast.in.phy ? qos->ucast.in.phy :
|
|
|
|
qos->ucast.out.phy;
|
|
|
|
cis->c_rtn = qos->ucast.out.rtn;
|
|
|
|
cis->p_rtn = qos->ucast.in.rtn;
|
|
|
|
}
|
2024-05-02 16:22:00 +00:00
|
|
|
pdu->num_cis = aux_num_cis;
|
2023-08-04 21:54:09 +00:00
|
|
|
|
2024-05-02 16:22:00 +00:00
|
|
|
if (!pdu->num_cis)
|
2023-08-04 21:54:09 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_CIG_PARAMS,
|
2024-05-02 16:22:00 +00:00
|
|
|
struct_size(pdu, cis, pdu->num_cis),
|
|
|
|
pdu, HCI_CMD_TIMEOUT);
|
2023-06-01 06:34:43 +00:00
|
|
|
}
|
|
|
|
|
2019-07-29 15:15:43 +00:00
|
|
|
static bool hci_le_set_cig_params(struct hci_conn *conn, struct bt_iso_qos *qos)
|
|
|
|
{
|
|
|
|
struct hci_dev *hdev = conn->hdev;
|
|
|
|
struct iso_list_data data;
|
|
|
|
|
|
|
|
memset(&data, 0, sizeof(data));
|
|
|
|
|
2023-05-21 15:48:29 +00:00
|
|
|
/* Allocate first still reconfigurable CIG if not set */
|
2023-03-31 15:38:01 +00:00
|
|
|
if (qos->ucast.cig == BT_ISO_QOS_CIG_UNSET) {
|
2023-05-21 15:48:29 +00:00
|
|
|
for (data.cig = 0x00; data.cig < 0xf0; data.cig++) {
|
2019-07-29 15:15:43 +00:00
|
|
|
data.count = 0;
|
|
|
|
|
2023-05-21 15:48:29 +00:00
|
|
|
hci_conn_hash_list_state(hdev, find_cis, ISO_LINK,
|
|
|
|
BT_CONNECT, &data);
|
2019-07-29 15:15:43 +00:00
|
|
|
if (data.count)
|
|
|
|
continue;
|
|
|
|
|
2023-05-21 15:48:29 +00:00
|
|
|
hci_conn_hash_list_state(hdev, find_cis, ISO_LINK,
|
2019-07-29 15:15:43 +00:00
|
|
|
BT_CONNECTED, &data);
|
|
|
|
if (!data.count)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-05-21 15:48:29 +00:00
|
|
|
if (data.cig == 0xf0)
|
2019-07-29 15:15:43 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Update CIG */
|
2023-03-31 15:38:01 +00:00
|
|
|
qos->ucast.cig = data.cig;
|
2019-07-29 15:15:43 +00:00
|
|
|
}
|
|
|
|
|
2023-03-31 15:38:01 +00:00
|
|
|
if (qos->ucast.cis != BT_ISO_QOS_CIS_UNSET) {
|
2023-08-04 21:54:09 +00:00
|
|
|
if (hci_conn_hash_lookup_cis(hdev, NULL, 0, qos->ucast.cig,
|
|
|
|
qos->ucast.cis))
|
2019-07-29 15:15:43 +00:00
|
|
|
return false;
|
2023-08-04 21:54:09 +00:00
|
|
|
goto done;
|
2019-07-29 15:15:43 +00:00
|
|
|
}
|
|
|
|
|
2023-08-04 21:54:09 +00:00
|
|
|
/* Allocate first available CIS if not set */
|
|
|
|
for (data.cig = qos->ucast.cig, data.cis = 0x00; data.cis < 0xf0;
|
|
|
|
data.cis++) {
|
|
|
|
if (!hci_conn_hash_lookup_cis(hdev, NULL, 0, data.cig,
|
|
|
|
data.cis)) {
|
2019-07-29 15:15:43 +00:00
|
|
|
/* Update CIS */
|
2023-03-31 15:38:01 +00:00
|
|
|
qos->ucast.cis = data.cis;
|
2023-08-04 21:54:09 +00:00
|
|
|
break;
|
2019-07-29 15:15:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-04 21:54:09 +00:00
|
|
|
if (qos->ucast.cis == BT_ISO_QOS_CIS_UNSET)
|
2019-07-29 15:15:43 +00:00
|
|
|
return false;
|
|
|
|
|
2023-08-04 21:54:09 +00:00
|
|
|
done:
|
|
|
|
if (hci_cmd_sync_queue(hdev, set_cig_params_sync,
|
2023-08-04 23:23:41 +00:00
|
|
|
UINT_PTR(qos->ucast.cig), NULL) < 0)
|
2023-06-01 06:34:43 +00:00
|
|
|
return false;
|
|
|
|
|
2019-07-29 15:15:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct hci_conn *hci_bind_cis(struct hci_dev *hdev, bdaddr_t *dst,
|
|
|
|
__u8 dst_type, struct bt_iso_qos *qos)
|
|
|
|
{
|
|
|
|
struct hci_conn *cis;
|
|
|
|
|
2023-04-11 23:14:25 +00:00
|
|
|
cis = hci_conn_hash_lookup_cis(hdev, dst, dst_type, qos->ucast.cig,
|
|
|
|
qos->ucast.cis);
|
2019-07-29 15:15:43 +00:00
|
|
|
if (!cis) {
|
2023-10-11 09:57:31 +00:00
|
|
|
cis = hci_conn_add_unset(hdev, ISO_LINK, dst, HCI_ROLE_MASTER);
|
2024-05-04 19:23:29 +00:00
|
|
|
if (IS_ERR(cis))
|
|
|
|
return cis;
|
2019-07-29 15:15:43 +00:00
|
|
|
cis->cleanup = cis_cleanup;
|
2022-10-11 19:25:33 +00:00
|
|
|
cis->dst_type = dst_type;
|
2023-08-05 16:08:42 +00:00
|
|
|
cis->iso_qos.ucast.cig = BT_ISO_QOS_CIG_UNSET;
|
|
|
|
cis->iso_qos.ucast.cis = BT_ISO_QOS_CIS_UNSET;
|
2019-07-29 15:15:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cis->state == BT_CONNECTED)
|
|
|
|
return cis;
|
|
|
|
|
|
|
|
/* Check if CIS has been set and the settings matches */
|
|
|
|
if (cis->state == BT_BOUND &&
|
|
|
|
!memcmp(&cis->iso_qos, qos, sizeof(*qos)))
|
|
|
|
return cis;
|
|
|
|
|
|
|
|
/* Update LINK PHYs according to QoS preference */
|
2023-03-31 15:38:01 +00:00
|
|
|
cis->le_tx_phy = qos->ucast.out.phy;
|
|
|
|
cis->le_rx_phy = qos->ucast.in.phy;
|
2019-07-29 15:15:43 +00:00
|
|
|
|
|
|
|
/* If output interval is not set use the input interval as it cannot be
|
|
|
|
* 0x000000.
|
|
|
|
*/
|
2023-03-31 15:38:01 +00:00
|
|
|
if (!qos->ucast.out.interval)
|
|
|
|
qos->ucast.out.interval = qos->ucast.in.interval;
|
2019-07-29 15:15:43 +00:00
|
|
|
|
|
|
|
/* If input interval is not set use the output interval as it cannot be
|
|
|
|
* 0x000000.
|
|
|
|
*/
|
2023-03-31 15:38:01 +00:00
|
|
|
if (!qos->ucast.in.interval)
|
|
|
|
qos->ucast.in.interval = qos->ucast.out.interval;
|
2019-07-29 15:15:43 +00:00
|
|
|
|
|
|
|
/* If output latency is not set use the input latency as it cannot be
|
|
|
|
* 0x0000.
|
|
|
|
*/
|
2023-03-31 15:38:01 +00:00
|
|
|
if (!qos->ucast.out.latency)
|
|
|
|
qos->ucast.out.latency = qos->ucast.in.latency;
|
2019-07-29 15:15:43 +00:00
|
|
|
|
|
|
|
/* If input latency is not set use the output latency as it cannot be
|
|
|
|
* 0x0000.
|
|
|
|
*/
|
2023-03-31 15:38:01 +00:00
|
|
|
if (!qos->ucast.in.latency)
|
|
|
|
qos->ucast.in.latency = qos->ucast.out.latency;
|
2019-07-29 15:15:43 +00:00
|
|
|
|
|
|
|
if (!hci_le_set_cig_params(cis, qos)) {
|
|
|
|
hci_conn_drop(cis);
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
}
|
|
|
|
|
2023-07-26 21:25:26 +00:00
|
|
|
hci_conn_hold(cis);
|
|
|
|
|
2019-07-29 15:15:43 +00:00
|
|
|
cis->iso_qos = *qos;
|
|
|
|
cis->state = BT_BOUND;
|
|
|
|
|
|
|
|
return cis;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hci_iso_setup_path(struct hci_conn *conn)
|
|
|
|
{
|
|
|
|
struct hci_dev *hdev = conn->hdev;
|
|
|
|
struct hci_cp_le_setup_iso_path cmd;
|
|
|
|
|
|
|
|
memset(&cmd, 0, sizeof(cmd));
|
|
|
|
|
2023-03-31 15:38:01 +00:00
|
|
|
if (conn->iso_qos.ucast.out.sdu) {
|
2019-07-29 15:15:43 +00:00
|
|
|
cmd.handle = cpu_to_le16(conn->handle);
|
|
|
|
cmd.direction = 0x00; /* Input (Host to Controller) */
|
|
|
|
cmd.path = 0x00; /* HCI path if enabled */
|
|
|
|
cmd.codec = 0x03; /* Transparent Data */
|
|
|
|
|
|
|
|
if (hci_send_cmd(hdev, HCI_OP_LE_SETUP_ISO_PATH, sizeof(cmd),
|
|
|
|
&cmd) < 0)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-03-31 15:38:01 +00:00
|
|
|
if (conn->iso_qos.ucast.in.sdu) {
|
2019-07-29 15:15:43 +00:00
|
|
|
cmd.handle = cpu_to_le16(conn->handle);
|
|
|
|
cmd.direction = 0x01; /* Output (Controller to Host) */
|
|
|
|
cmd.path = 0x00; /* HCI path if enabled */
|
|
|
|
cmd.codec = 0x03; /* Transparent Data */
|
|
|
|
|
|
|
|
if (hci_send_cmd(hdev, HCI_OP_LE_SETUP_ISO_PATH, sizeof(cmd),
|
|
|
|
&cmd) < 0)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-06-01 06:34:46 +00:00
|
|
|
int hci_conn_check_create_cis(struct hci_conn *conn)
|
2019-07-29 15:15:43 +00:00
|
|
|
{
|
2023-06-01 06:34:46 +00:00
|
|
|
if (conn->type != ISO_LINK || !bacmp(&conn->dst, BDADDR_ANY))
|
|
|
|
return -EINVAL;
|
2019-07-29 15:15:43 +00:00
|
|
|
|
2023-06-01 06:34:46 +00:00
|
|
|
if (!conn->parent || conn->parent->state != BT_CONNECTED ||
|
2023-06-28 19:15:53 +00:00
|
|
|
conn->state != BT_CONNECT || HCI_CONN_HANDLE_UNSET(conn->handle))
|
2023-06-01 06:34:46 +00:00
|
|
|
return 1;
|
2019-07-29 15:15:43 +00:00
|
|
|
|
2023-06-01 06:34:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2023-04-11 23:02:22 +00:00
|
|
|
|
2023-06-01 06:34:46 +00:00
|
|
|
static int hci_create_cis_sync(struct hci_dev *hdev, void *data)
|
|
|
|
{
|
|
|
|
return hci_le_create_cis_sync(hdev);
|
|
|
|
}
|
2023-04-11 23:02:22 +00:00
|
|
|
|
2023-06-01 06:34:46 +00:00
|
|
|
int hci_le_create_cis_pending(struct hci_dev *hdev)
|
|
|
|
{
|
|
|
|
struct hci_conn *conn;
|
|
|
|
bool pending = false;
|
2023-04-11 23:02:22 +00:00
|
|
|
|
2023-06-01 06:34:46 +00:00
|
|
|
rcu_read_lock();
|
2023-04-11 23:02:22 +00:00
|
|
|
|
2023-06-01 06:34:46 +00:00
|
|
|
list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) {
|
|
|
|
if (test_bit(HCI_CONN_CREATE_CIS, &conn->flags)) {
|
|
|
|
rcu_read_unlock();
|
|
|
|
return -EBUSY;
|
2023-04-11 23:02:22 +00:00
|
|
|
}
|
|
|
|
|
2023-06-01 06:34:46 +00:00
|
|
|
if (!hci_conn_check_create_cis(conn))
|
|
|
|
pending = true;
|
2019-07-29 15:15:43 +00:00
|
|
|
}
|
|
|
|
|
2023-06-01 06:34:46 +00:00
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
if (!pending)
|
2019-07-29 15:15:43 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Queue Create CIS */
|
2023-06-01 06:34:46 +00:00
|
|
|
return hci_cmd_sync_queue(hdev, hci_create_cis_sync, NULL, NULL);
|
2019-07-29 15:15:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void hci_iso_qos_setup(struct hci_dev *hdev, struct hci_conn *conn,
|
|
|
|
struct bt_iso_io_qos *qos, __u8 phy)
|
|
|
|
{
|
|
|
|
/* Only set MTU if PHY is enabled */
|
2024-05-04 19:23:29 +00:00
|
|
|
if (!qos->sdu && qos->phy)
|
|
|
|
qos->sdu = conn->mtu;
|
2019-07-29 15:15:43 +00:00
|
|
|
|
|
|
|
/* Use the same PHY as ACL if set to any */
|
|
|
|
if (qos->phy == BT_ISO_PHY_ANY)
|
|
|
|
qos->phy = phy;
|
|
|
|
|
|
|
|
/* Use LE ACL connection interval if not set */
|
|
|
|
if (!qos->interval)
|
|
|
|
/* ACL interval unit in 1.25 ms to us */
|
|
|
|
qos->interval = conn->le_conn_interval * 1250;
|
|
|
|
|
|
|
|
/* Use LE ACL connection latency if not set */
|
|
|
|
if (!qos->latency)
|
|
|
|
qos->latency = conn->le_conn_latency;
|
|
|
|
}
|
|
|
|
|
2022-03-09 21:22:20 +00:00
|
|
|
static int create_big_sync(struct hci_dev *hdev, void *data)
|
|
|
|
{
|
|
|
|
struct hci_conn *conn = data;
|
|
|
|
struct bt_iso_qos *qos = &conn->iso_qos;
|
|
|
|
u16 interval, sync_interval = 0;
|
|
|
|
u32 flags = 0;
|
|
|
|
int err;
|
|
|
|
|
2023-03-31 15:38:01 +00:00
|
|
|
if (qos->bcast.out.phy == 0x02)
|
2022-03-09 21:22:20 +00:00
|
|
|
flags |= MGMT_ADV_FLAG_SEC_2M;
|
|
|
|
|
|
|
|
/* Align intervals */
|
2023-06-08 18:12:18 +00:00
|
|
|
interval = (qos->bcast.out.interval / 1250) * qos->bcast.sync_factor;
|
2022-03-09 21:22:20 +00:00
|
|
|
|
2023-03-31 15:38:01 +00:00
|
|
|
if (qos->bcast.bis)
|
2023-06-08 18:12:18 +00:00
|
|
|
sync_interval = interval * 4;
|
2022-03-09 21:22:20 +00:00
|
|
|
|
2023-03-31 15:38:01 +00:00
|
|
|
err = hci_start_per_adv_sync(hdev, qos->bcast.bis, conn->le_per_adv_data_len,
|
2022-03-09 21:22:20 +00:00
|
|
|
conn->le_per_adv_data, flags, interval,
|
|
|
|
interval, sync_interval);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
return hci_le_create_big(conn, &conn->iso_qos);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void create_pa_complete(struct hci_dev *hdev, void *data, int err)
|
|
|
|
{
|
|
|
|
bt_dev_dbg(hdev, "");
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
bt_dev_err(hdev, "Unable to create PA: %d", err);
|
2024-11-01 08:23:36 +00:00
|
|
|
}
|
2022-03-09 21:22:20 +00:00
|
|
|
|
2024-11-01 08:23:36 +00:00
|
|
|
static bool hci_conn_check_create_pa_sync(struct hci_conn *conn)
|
|
|
|
{
|
|
|
|
if (conn->type != ISO_LINK || conn->sid == HCI_SID_INVALID)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2022-03-09 21:22:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int create_pa_sync(struct hci_dev *hdev, void *data)
|
|
|
|
{
|
2024-11-11 11:47:07 +00:00
|
|
|
struct hci_cp_le_pa_create_sync cp = {0};
|
2024-11-01 08:23:36 +00:00
|
|
|
struct hci_conn *conn;
|
|
|
|
int err = 0;
|
2022-03-09 21:22:20 +00:00
|
|
|
|
2024-11-01 08:23:36 +00:00
|
|
|
hci_dev_lock(hdev);
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
|
|
|
|
/* The spec allows only one pending LE Periodic Advertising Create
|
|
|
|
* Sync command at a time. If the command is pending now, don't do
|
|
|
|
* anything. We check for pending connections after each PA Sync
|
|
|
|
* Established event.
|
|
|
|
*
|
|
|
|
* BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 4, Part E
|
|
|
|
* page 2493:
|
|
|
|
*
|
|
|
|
* If the Host issues this command when another HCI_LE_Periodic_
|
|
|
|
* Advertising_Create_Sync command is pending, the Controller shall
|
|
|
|
* return the error code Command Disallowed (0x0C).
|
|
|
|
*/
|
|
|
|
list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) {
|
|
|
|
if (test_bit(HCI_CONN_CREATE_PA_SYNC, &conn->flags))
|
|
|
|
goto unlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) {
|
|
|
|
if (hci_conn_check_create_pa_sync(conn)) {
|
|
|
|
struct bt_iso_qos *qos = &conn->iso_qos;
|
|
|
|
|
2024-11-11 11:47:07 +00:00
|
|
|
cp.options = qos->bcast.options;
|
|
|
|
cp.sid = conn->sid;
|
|
|
|
cp.addr_type = conn->dst_type;
|
|
|
|
bacpy(&cp.addr, &conn->dst);
|
|
|
|
cp.skip = cpu_to_le16(qos->bcast.skip);
|
|
|
|
cp.sync_timeout = cpu_to_le16(qos->bcast.sync_timeout);
|
|
|
|
cp.sync_cte_type = qos->bcast.sync_cte_type;
|
2024-11-01 08:23:36 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unlock:
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
hci_dev_unlock(hdev);
|
|
|
|
|
2024-11-11 11:47:07 +00:00
|
|
|
if (bacmp(&cp.addr, BDADDR_ANY)) {
|
2024-11-01 08:23:36 +00:00
|
|
|
hci_dev_set_flag(hdev, HCI_PA_SYNC);
|
|
|
|
set_bit(HCI_CONN_CREATE_PA_SYNC, &conn->flags);
|
|
|
|
|
|
|
|
err = __hci_cmd_sync_status(hdev, HCI_OP_LE_PA_CREATE_SYNC,
|
2024-11-11 11:47:07 +00:00
|
|
|
sizeof(cp), &cp, HCI_CMD_TIMEOUT);
|
2024-11-01 08:23:36 +00:00
|
|
|
if (!err)
|
|
|
|
err = hci_update_passive_scan_sync(hdev);
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
hci_dev_clear_flag(hdev, HCI_PA_SYNC);
|
|
|
|
clear_bit(HCI_CONN_CREATE_PA_SYNC, &conn->flags);
|
|
|
|
}
|
2022-03-09 21:22:20 +00:00
|
|
|
}
|
|
|
|
|
2024-11-01 08:23:36 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int hci_pa_create_sync_pending(struct hci_dev *hdev)
|
|
|
|
{
|
|
|
|
/* Queue start pa_create_sync and scan */
|
|
|
|
return hci_cmd_sync_queue(hdev, create_pa_sync,
|
|
|
|
NULL, create_pa_complete);
|
2022-03-09 21:22:20 +00:00
|
|
|
}
|
|
|
|
|
2024-02-23 13:14:41 +00:00
|
|
|
struct hci_conn *hci_pa_create_sync(struct hci_dev *hdev, bdaddr_t *dst,
|
|
|
|
__u8 dst_type, __u8 sid,
|
|
|
|
struct bt_iso_qos *qos)
|
2022-03-09 21:22:20 +00:00
|
|
|
{
|
2024-02-23 13:14:41 +00:00
|
|
|
struct hci_conn *conn;
|
|
|
|
|
|
|
|
conn = hci_conn_add_unset(hdev, ISO_LINK, dst, HCI_ROLE_SLAVE);
|
2024-05-04 19:23:29 +00:00
|
|
|
if (IS_ERR(conn))
|
|
|
|
return conn;
|
2024-02-23 13:14:41 +00:00
|
|
|
|
|
|
|
conn->iso_qos = *qos;
|
2024-11-01 08:23:36 +00:00
|
|
|
conn->dst_type = dst_type;
|
|
|
|
conn->sid = sid;
|
2024-02-23 13:14:41 +00:00
|
|
|
conn->state = BT_LISTEN;
|
|
|
|
|
|
|
|
hci_conn_hold(conn);
|
2022-03-09 21:22:20 +00:00
|
|
|
|
2024-11-01 08:23:36 +00:00
|
|
|
hci_pa_create_sync_pending(hdev);
|
2024-02-23 13:14:41 +00:00
|
|
|
|
|
|
|
return conn;
|
2022-03-09 21:22:20 +00:00
|
|
|
}
|
|
|
|
|
2024-11-01 08:23:38 +00:00
|
|
|
static bool hci_conn_check_create_big_sync(struct hci_conn *conn)
|
|
|
|
{
|
|
|
|
if (!conn->num_bis)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-11-11 11:47:08 +00:00
|
|
|
static void big_create_sync_complete(struct hci_dev *hdev, void *data, int err)
|
|
|
|
{
|
|
|
|
bt_dev_dbg(hdev, "");
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
bt_dev_err(hdev, "Unable to create BIG sync: %d", err);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int big_create_sync(struct hci_dev *hdev, void *data)
|
2024-11-01 08:23:38 +00:00
|
|
|
{
|
|
|
|
DEFINE_FLEX(struct hci_cp_le_big_create_sync, pdu, bis, num_bis, 0x11);
|
|
|
|
struct hci_conn *conn;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
|
|
|
|
pdu->num_bis = 0;
|
|
|
|
|
|
|
|
/* The spec allows only one pending LE BIG Create Sync command at
|
|
|
|
* a time. If the command is pending now, don't do anything. We
|
|
|
|
* check for pending connections after each BIG Sync Established
|
|
|
|
* event.
|
|
|
|
*
|
|
|
|
* BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 4, Part E
|
|
|
|
* page 2586:
|
|
|
|
*
|
|
|
|
* If the Host sends this command when the Controller is in the
|
|
|
|
* process of synchronizing to any BIG, i.e. the HCI_LE_BIG_Sync_
|
|
|
|
* Established event has not been generated, the Controller shall
|
|
|
|
* return the error code Command Disallowed (0x0C).
|
|
|
|
*/
|
|
|
|
list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) {
|
|
|
|
if (test_bit(HCI_CONN_CREATE_BIG_SYNC, &conn->flags))
|
|
|
|
goto unlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) {
|
|
|
|
if (hci_conn_check_create_big_sync(conn)) {
|
|
|
|
struct bt_iso_qos *qos = &conn->iso_qos;
|
|
|
|
|
|
|
|
set_bit(HCI_CONN_CREATE_BIG_SYNC, &conn->flags);
|
|
|
|
|
|
|
|
pdu->handle = qos->bcast.big;
|
|
|
|
pdu->sync_handle = cpu_to_le16(conn->sync_handle);
|
|
|
|
pdu->encryption = qos->bcast.encryption;
|
|
|
|
memcpy(pdu->bcode, qos->bcast.bcode,
|
|
|
|
sizeof(pdu->bcode));
|
|
|
|
pdu->mse = qos->bcast.mse;
|
|
|
|
pdu->timeout = cpu_to_le16(qos->bcast.timeout);
|
|
|
|
pdu->num_bis = conn->num_bis;
|
|
|
|
memcpy(pdu->bis, conn->bis, conn->num_bis);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unlock:
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
if (!pdu->num_bis)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return hci_send_cmd(hdev, HCI_OP_LE_BIG_CREATE_SYNC,
|
|
|
|
struct_size(pdu, bis, pdu->num_bis), pdu);
|
|
|
|
}
|
|
|
|
|
2024-11-11 11:47:08 +00:00
|
|
|
int hci_le_big_create_sync_pending(struct hci_dev *hdev)
|
|
|
|
{
|
|
|
|
/* Queue big_create_sync */
|
|
|
|
return hci_cmd_sync_queue_once(hdev, big_create_sync,
|
|
|
|
NULL, big_create_sync_complete);
|
|
|
|
}
|
|
|
|
|
2023-08-17 06:44:27 +00:00
|
|
|
int hci_le_big_create_sync(struct hci_dev *hdev, struct hci_conn *hcon,
|
|
|
|
struct bt_iso_qos *qos,
|
2022-03-09 21:22:20 +00:00
|
|
|
__u16 sync_handle, __u8 num_bis, __u8 bis[])
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2024-11-01 08:23:38 +00:00
|
|
|
if (num_bis < 0x01 || num_bis > ISO_MAX_NUM_BIS)
|
2022-03-09 21:22:20 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
err = qos_set_big(hdev, qos);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2024-11-01 08:23:38 +00:00
|
|
|
if (hcon) {
|
|
|
|
/* Update hcon QoS */
|
|
|
|
hcon->iso_qos = *qos;
|
2023-08-17 06:44:27 +00:00
|
|
|
|
2024-11-01 08:23:38 +00:00
|
|
|
hcon->num_bis = num_bis;
|
|
|
|
memcpy(hcon->bis, bis, num_bis);
|
|
|
|
}
|
2022-03-09 21:22:20 +00:00
|
|
|
|
2024-11-01 08:23:38 +00:00
|
|
|
return hci_le_big_create_sync_pending(hdev);
|
2022-03-09 21:22:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void create_big_complete(struct hci_dev *hdev, void *data, int err)
|
|
|
|
{
|
|
|
|
struct hci_conn *conn = data;
|
|
|
|
|
|
|
|
bt_dev_dbg(hdev, "conn %p", conn);
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
bt_dev_err(hdev, "Unable to create BIG: %d", err);
|
|
|
|
hci_connect_cfm(conn, err);
|
|
|
|
hci_conn_del(conn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Bluetooth: ISO: Add support for connecting multiple BISes
It is required for some configurations to have multiple BISes as part
of the same BIG.
Similar to the flow implemented for unicast, DEFER_SETUP will also be
used to bind multiple BISes for the same BIG, before starting Periodic
Advertising and creating the BIG.
The user will have to open a new socket for each BIS. By setting the
BT_DEFER_SETUP socket option and calling connect, a new connection
will be added for the BIG and advertising handle set by the socket
QoS parameters. Since all BISes will be bound for the same BIG and
advertising handle, the socket QoS options and base parameters should
match for all connections.
By calling connect on a socket that does not have the BT_DEFER_SETUP
option set, periodic advertising will be started and the BIG will
be created, with a BIS for each previously bound connection. Since
a BIG cannot be reconfigured with additional BISes after creation,
no more connections can be bound for the BIG after the start periodic
advertising and create BIG commands have been queued.
The bis_cleanup function has also been updated, so that the advertising
set and the BIG will not be terminated unless there are no more
bound or connected BISes.
The HCI_CONN_BIG_CREATED connection flag has been added to indicate
that the BIG has been successfully created. This flag is checked at
bis_cleanup, so that the BIG is only terminated if the
HCI_LE_Create_BIG_Complete has been received.
This implementation has been tested on hardware, using the "isotest"
tool with an additional command line option, to specify the number of
BISes to create as part of the desired BIG:
tools/isotest -i hci0 -s 00:00:00:00:00:00 -N 2 -G 1 -T 1
The btmon log shows that a BIG containing 2 BISes has been created:
< HCI Command: LE Create Broadcast Isochronous Group (0x08|0x0068) plen 31
Handle: 0x01
Advertising Handle: 0x01
Number of BIS: 2
SDU Interval: 10000 us (0x002710)
Maximum SDU size: 40
Maximum Latency: 10 ms (0x000a)
RTN: 0x02
PHY: LE 2M (0x02)
Packing: Sequential (0x00)
Framing: Unframed (0x00)
Encryption: 0x00
Broadcast Code: 00000000000000000000000000000000
> HCI Event: Command Status (0x0f) plen 4
LE Create Broadcast Isochronous Group (0x08|0x0068) ncmd 1
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 23
LE Broadcast Isochronous Group Complete (0x1b)
Status: Success (0x00)
Handle: 0x01
BIG Synchronization Delay: 1974 us (0x0007b6)
Transport Latency: 1974 us (0x0007b6)
PHY: LE 2M (0x02)
NSE: 3
BN: 1
PTO: 1
IRC: 3
Maximum PDU: 40
ISO Interval: 10.00 msec (0x0008)
Connection Handle #0: 10
Connection Handle #1: 11
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 10
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 10
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 11
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 11
< ISO Data TX: Handle 10 flags 0x02 dlen 44
< ISO Data TX: Handle 11 flags 0x02 dlen 44
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 10
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 11
Count: 1
Signed-off-by: Iulia Tanasescu <iulia.tanasescu@nxp.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2023-05-30 14:21:59 +00:00
|
|
|
struct hci_conn *hci_bind_bis(struct hci_dev *hdev, bdaddr_t *dst,
|
|
|
|
struct bt_iso_qos *qos,
|
|
|
|
__u8 base_len, __u8 *base)
|
2022-03-09 21:22:20 +00:00
|
|
|
{
|
|
|
|
struct hci_conn *conn;
|
2023-11-13 15:38:00 +00:00
|
|
|
struct hci_conn *parent;
|
Bluetooth: ISO: Add support for connecting multiple BISes
It is required for some configurations to have multiple BISes as part
of the same BIG.
Similar to the flow implemented for unicast, DEFER_SETUP will also be
used to bind multiple BISes for the same BIG, before starting Periodic
Advertising and creating the BIG.
The user will have to open a new socket for each BIS. By setting the
BT_DEFER_SETUP socket option and calling connect, a new connection
will be added for the BIG and advertising handle set by the socket
QoS parameters. Since all BISes will be bound for the same BIG and
advertising handle, the socket QoS options and base parameters should
match for all connections.
By calling connect on a socket that does not have the BT_DEFER_SETUP
option set, periodic advertising will be started and the BIG will
be created, with a BIS for each previously bound connection. Since
a BIG cannot be reconfigured with additional BISes after creation,
no more connections can be bound for the BIG after the start periodic
advertising and create BIG commands have been queued.
The bis_cleanup function has also been updated, so that the advertising
set and the BIG will not be terminated unless there are no more
bound or connected BISes.
The HCI_CONN_BIG_CREATED connection flag has been added to indicate
that the BIG has been successfully created. This flag is checked at
bis_cleanup, so that the BIG is only terminated if the
HCI_LE_Create_BIG_Complete has been received.
This implementation has been tested on hardware, using the "isotest"
tool with an additional command line option, to specify the number of
BISes to create as part of the desired BIG:
tools/isotest -i hci0 -s 00:00:00:00:00:00 -N 2 -G 1 -T 1
The btmon log shows that a BIG containing 2 BISes has been created:
< HCI Command: LE Create Broadcast Isochronous Group (0x08|0x0068) plen 31
Handle: 0x01
Advertising Handle: 0x01
Number of BIS: 2
SDU Interval: 10000 us (0x002710)
Maximum SDU size: 40
Maximum Latency: 10 ms (0x000a)
RTN: 0x02
PHY: LE 2M (0x02)
Packing: Sequential (0x00)
Framing: Unframed (0x00)
Encryption: 0x00
Broadcast Code: 00000000000000000000000000000000
> HCI Event: Command Status (0x0f) plen 4
LE Create Broadcast Isochronous Group (0x08|0x0068) ncmd 1
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 23
LE Broadcast Isochronous Group Complete (0x1b)
Status: Success (0x00)
Handle: 0x01
BIG Synchronization Delay: 1974 us (0x0007b6)
Transport Latency: 1974 us (0x0007b6)
PHY: LE 2M (0x02)
NSE: 3
BN: 1
PTO: 1
IRC: 3
Maximum PDU: 40
ISO Interval: 10.00 msec (0x0008)
Connection Handle #0: 10
Connection Handle #1: 11
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 10
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 10
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 11
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 11
< ISO Data TX: Handle 10 flags 0x02 dlen 44
< ISO Data TX: Handle 11 flags 0x02 dlen 44
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 10
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 11
Count: 1
Signed-off-by: Iulia Tanasescu <iulia.tanasescu@nxp.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2023-05-30 14:21:59 +00:00
|
|
|
__u8 eir[HCI_MAX_PER_AD_LENGTH];
|
2023-11-13 15:38:00 +00:00
|
|
|
struct hci_link *link;
|
|
|
|
|
|
|
|
/* Look for any BIS that is open for rebinding */
|
|
|
|
conn = hci_conn_hash_lookup_big_state(hdev, qos->bcast.big, BT_OPEN);
|
|
|
|
if (conn) {
|
|
|
|
memcpy(qos, &conn->iso_qos, sizeof(*qos));
|
|
|
|
conn->state = BT_CONNECTED;
|
|
|
|
return conn;
|
|
|
|
}
|
Bluetooth: ISO: Add support for connecting multiple BISes
It is required for some configurations to have multiple BISes as part
of the same BIG.
Similar to the flow implemented for unicast, DEFER_SETUP will also be
used to bind multiple BISes for the same BIG, before starting Periodic
Advertising and creating the BIG.
The user will have to open a new socket for each BIS. By setting the
BT_DEFER_SETUP socket option and calling connect, a new connection
will be added for the BIG and advertising handle set by the socket
QoS parameters. Since all BISes will be bound for the same BIG and
advertising handle, the socket QoS options and base parameters should
match for all connections.
By calling connect on a socket that does not have the BT_DEFER_SETUP
option set, periodic advertising will be started and the BIG will
be created, with a BIS for each previously bound connection. Since
a BIG cannot be reconfigured with additional BISes after creation,
no more connections can be bound for the BIG after the start periodic
advertising and create BIG commands have been queued.
The bis_cleanup function has also been updated, so that the advertising
set and the BIG will not be terminated unless there are no more
bound or connected BISes.
The HCI_CONN_BIG_CREATED connection flag has been added to indicate
that the BIG has been successfully created. This flag is checked at
bis_cleanup, so that the BIG is only terminated if the
HCI_LE_Create_BIG_Complete has been received.
This implementation has been tested on hardware, using the "isotest"
tool with an additional command line option, to specify the number of
BISes to create as part of the desired BIG:
tools/isotest -i hci0 -s 00:00:00:00:00:00 -N 2 -G 1 -T 1
The btmon log shows that a BIG containing 2 BISes has been created:
< HCI Command: LE Create Broadcast Isochronous Group (0x08|0x0068) plen 31
Handle: 0x01
Advertising Handle: 0x01
Number of BIS: 2
SDU Interval: 10000 us (0x002710)
Maximum SDU size: 40
Maximum Latency: 10 ms (0x000a)
RTN: 0x02
PHY: LE 2M (0x02)
Packing: Sequential (0x00)
Framing: Unframed (0x00)
Encryption: 0x00
Broadcast Code: 00000000000000000000000000000000
> HCI Event: Command Status (0x0f) plen 4
LE Create Broadcast Isochronous Group (0x08|0x0068) ncmd 1
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 23
LE Broadcast Isochronous Group Complete (0x1b)
Status: Success (0x00)
Handle: 0x01
BIG Synchronization Delay: 1974 us (0x0007b6)
Transport Latency: 1974 us (0x0007b6)
PHY: LE 2M (0x02)
NSE: 3
BN: 1
PTO: 1
IRC: 3
Maximum PDU: 40
ISO Interval: 10.00 msec (0x0008)
Connection Handle #0: 10
Connection Handle #1: 11
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 10
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 10
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 11
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 11
< ISO Data TX: Handle 10 flags 0x02 dlen 44
< ISO Data TX: Handle 11 flags 0x02 dlen 44
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 10
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 11
Count: 1
Signed-off-by: Iulia Tanasescu <iulia.tanasescu@nxp.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2023-05-30 14:21:59 +00:00
|
|
|
|
|
|
|
if (base_len && base)
|
|
|
|
base_len = eir_append_service_data(eir, 0, 0x1851,
|
|
|
|
base, base_len);
|
2022-03-09 21:22:20 +00:00
|
|
|
|
|
|
|
/* We need hci_conn object using the BDADDR_ANY as dst */
|
Bluetooth: ISO: Add support for connecting multiple BISes
It is required for some configurations to have multiple BISes as part
of the same BIG.
Similar to the flow implemented for unicast, DEFER_SETUP will also be
used to bind multiple BISes for the same BIG, before starting Periodic
Advertising and creating the BIG.
The user will have to open a new socket for each BIS. By setting the
BT_DEFER_SETUP socket option and calling connect, a new connection
will be added for the BIG and advertising handle set by the socket
QoS parameters. Since all BISes will be bound for the same BIG and
advertising handle, the socket QoS options and base parameters should
match for all connections.
By calling connect on a socket that does not have the BT_DEFER_SETUP
option set, periodic advertising will be started and the BIG will
be created, with a BIS for each previously bound connection. Since
a BIG cannot be reconfigured with additional BISes after creation,
no more connections can be bound for the BIG after the start periodic
advertising and create BIG commands have been queued.
The bis_cleanup function has also been updated, so that the advertising
set and the BIG will not be terminated unless there are no more
bound or connected BISes.
The HCI_CONN_BIG_CREATED connection flag has been added to indicate
that the BIG has been successfully created. This flag is checked at
bis_cleanup, so that the BIG is only terminated if the
HCI_LE_Create_BIG_Complete has been received.
This implementation has been tested on hardware, using the "isotest"
tool with an additional command line option, to specify the number of
BISes to create as part of the desired BIG:
tools/isotest -i hci0 -s 00:00:00:00:00:00 -N 2 -G 1 -T 1
The btmon log shows that a BIG containing 2 BISes has been created:
< HCI Command: LE Create Broadcast Isochronous Group (0x08|0x0068) plen 31
Handle: 0x01
Advertising Handle: 0x01
Number of BIS: 2
SDU Interval: 10000 us (0x002710)
Maximum SDU size: 40
Maximum Latency: 10 ms (0x000a)
RTN: 0x02
PHY: LE 2M (0x02)
Packing: Sequential (0x00)
Framing: Unframed (0x00)
Encryption: 0x00
Broadcast Code: 00000000000000000000000000000000
> HCI Event: Command Status (0x0f) plen 4
LE Create Broadcast Isochronous Group (0x08|0x0068) ncmd 1
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 23
LE Broadcast Isochronous Group Complete (0x1b)
Status: Success (0x00)
Handle: 0x01
BIG Synchronization Delay: 1974 us (0x0007b6)
Transport Latency: 1974 us (0x0007b6)
PHY: LE 2M (0x02)
NSE: 3
BN: 1
PTO: 1
IRC: 3
Maximum PDU: 40
ISO Interval: 10.00 msec (0x0008)
Connection Handle #0: 10
Connection Handle #1: 11
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 10
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 10
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 11
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 11
< ISO Data TX: Handle 10 flags 0x02 dlen 44
< ISO Data TX: Handle 11 flags 0x02 dlen 44
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 10
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 11
Count: 1
Signed-off-by: Iulia Tanasescu <iulia.tanasescu@nxp.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2023-05-30 14:21:59 +00:00
|
|
|
conn = hci_add_bis(hdev, dst, qos, base_len, eir);
|
2022-03-09 21:22:20 +00:00
|
|
|
if (IS_ERR(conn))
|
|
|
|
return conn;
|
|
|
|
|
Bluetooth: ISO: Add support for connecting multiple BISes
It is required for some configurations to have multiple BISes as part
of the same BIG.
Similar to the flow implemented for unicast, DEFER_SETUP will also be
used to bind multiple BISes for the same BIG, before starting Periodic
Advertising and creating the BIG.
The user will have to open a new socket for each BIS. By setting the
BT_DEFER_SETUP socket option and calling connect, a new connection
will be added for the BIG and advertising handle set by the socket
QoS parameters. Since all BISes will be bound for the same BIG and
advertising handle, the socket QoS options and base parameters should
match for all connections.
By calling connect on a socket that does not have the BT_DEFER_SETUP
option set, periodic advertising will be started and the BIG will
be created, with a BIS for each previously bound connection. Since
a BIG cannot be reconfigured with additional BISes after creation,
no more connections can be bound for the BIG after the start periodic
advertising and create BIG commands have been queued.
The bis_cleanup function has also been updated, so that the advertising
set and the BIG will not be terminated unless there are no more
bound or connected BISes.
The HCI_CONN_BIG_CREATED connection flag has been added to indicate
that the BIG has been successfully created. This flag is checked at
bis_cleanup, so that the BIG is only terminated if the
HCI_LE_Create_BIG_Complete has been received.
This implementation has been tested on hardware, using the "isotest"
tool with an additional command line option, to specify the number of
BISes to create as part of the desired BIG:
tools/isotest -i hci0 -s 00:00:00:00:00:00 -N 2 -G 1 -T 1
The btmon log shows that a BIG containing 2 BISes has been created:
< HCI Command: LE Create Broadcast Isochronous Group (0x08|0x0068) plen 31
Handle: 0x01
Advertising Handle: 0x01
Number of BIS: 2
SDU Interval: 10000 us (0x002710)
Maximum SDU size: 40
Maximum Latency: 10 ms (0x000a)
RTN: 0x02
PHY: LE 2M (0x02)
Packing: Sequential (0x00)
Framing: Unframed (0x00)
Encryption: 0x00
Broadcast Code: 00000000000000000000000000000000
> HCI Event: Command Status (0x0f) plen 4
LE Create Broadcast Isochronous Group (0x08|0x0068) ncmd 1
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 23
LE Broadcast Isochronous Group Complete (0x1b)
Status: Success (0x00)
Handle: 0x01
BIG Synchronization Delay: 1974 us (0x0007b6)
Transport Latency: 1974 us (0x0007b6)
PHY: LE 2M (0x02)
NSE: 3
BN: 1
PTO: 1
IRC: 3
Maximum PDU: 40
ISO Interval: 10.00 msec (0x0008)
Connection Handle #0: 10
Connection Handle #1: 11
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 10
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 10
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 11
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 11
< ISO Data TX: Handle 10 flags 0x02 dlen 44
< ISO Data TX: Handle 11 flags 0x02 dlen 44
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 10
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 11
Count: 1
Signed-off-by: Iulia Tanasescu <iulia.tanasescu@nxp.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2023-05-30 14:21:59 +00:00
|
|
|
/* Update LINK PHYs according to QoS preference */
|
|
|
|
conn->le_tx_phy = qos->bcast.out.phy;
|
|
|
|
conn->le_tx_phy = qos->bcast.out.phy;
|
2022-03-09 21:22:20 +00:00
|
|
|
|
|
|
|
/* Add Basic Announcement into Peridic Adv Data if BASE is set */
|
|
|
|
if (base_len && base) {
|
Bluetooth: ISO: Add support for connecting multiple BISes
It is required for some configurations to have multiple BISes as part
of the same BIG.
Similar to the flow implemented for unicast, DEFER_SETUP will also be
used to bind multiple BISes for the same BIG, before starting Periodic
Advertising and creating the BIG.
The user will have to open a new socket for each BIS. By setting the
BT_DEFER_SETUP socket option and calling connect, a new connection
will be added for the BIG and advertising handle set by the socket
QoS parameters. Since all BISes will be bound for the same BIG and
advertising handle, the socket QoS options and base parameters should
match for all connections.
By calling connect on a socket that does not have the BT_DEFER_SETUP
option set, periodic advertising will be started and the BIG will
be created, with a BIS for each previously bound connection. Since
a BIG cannot be reconfigured with additional BISes after creation,
no more connections can be bound for the BIG after the start periodic
advertising and create BIG commands have been queued.
The bis_cleanup function has also been updated, so that the advertising
set and the BIG will not be terminated unless there are no more
bound or connected BISes.
The HCI_CONN_BIG_CREATED connection flag has been added to indicate
that the BIG has been successfully created. This flag is checked at
bis_cleanup, so that the BIG is only terminated if the
HCI_LE_Create_BIG_Complete has been received.
This implementation has been tested on hardware, using the "isotest"
tool with an additional command line option, to specify the number of
BISes to create as part of the desired BIG:
tools/isotest -i hci0 -s 00:00:00:00:00:00 -N 2 -G 1 -T 1
The btmon log shows that a BIG containing 2 BISes has been created:
< HCI Command: LE Create Broadcast Isochronous Group (0x08|0x0068) plen 31
Handle: 0x01
Advertising Handle: 0x01
Number of BIS: 2
SDU Interval: 10000 us (0x002710)
Maximum SDU size: 40
Maximum Latency: 10 ms (0x000a)
RTN: 0x02
PHY: LE 2M (0x02)
Packing: Sequential (0x00)
Framing: Unframed (0x00)
Encryption: 0x00
Broadcast Code: 00000000000000000000000000000000
> HCI Event: Command Status (0x0f) plen 4
LE Create Broadcast Isochronous Group (0x08|0x0068) ncmd 1
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 23
LE Broadcast Isochronous Group Complete (0x1b)
Status: Success (0x00)
Handle: 0x01
BIG Synchronization Delay: 1974 us (0x0007b6)
Transport Latency: 1974 us (0x0007b6)
PHY: LE 2M (0x02)
NSE: 3
BN: 1
PTO: 1
IRC: 3
Maximum PDU: 40
ISO Interval: 10.00 msec (0x0008)
Connection Handle #0: 10
Connection Handle #1: 11
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 10
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 10
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 11
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 11
< ISO Data TX: Handle 10 flags 0x02 dlen 44
< ISO Data TX: Handle 11 flags 0x02 dlen 44
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 10
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 11
Count: 1
Signed-off-by: Iulia Tanasescu <iulia.tanasescu@nxp.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2023-05-30 14:21:59 +00:00
|
|
|
memcpy(conn->le_per_adv_data, eir, sizeof(eir));
|
2022-03-09 21:22:20 +00:00
|
|
|
conn->le_per_adv_data_len = base_len;
|
|
|
|
}
|
|
|
|
|
Bluetooth: ISO: Add support for connecting multiple BISes
It is required for some configurations to have multiple BISes as part
of the same BIG.
Similar to the flow implemented for unicast, DEFER_SETUP will also be
used to bind multiple BISes for the same BIG, before starting Periodic
Advertising and creating the BIG.
The user will have to open a new socket for each BIS. By setting the
BT_DEFER_SETUP socket option and calling connect, a new connection
will be added for the BIG and advertising handle set by the socket
QoS parameters. Since all BISes will be bound for the same BIG and
advertising handle, the socket QoS options and base parameters should
match for all connections.
By calling connect on a socket that does not have the BT_DEFER_SETUP
option set, periodic advertising will be started and the BIG will
be created, with a BIS for each previously bound connection. Since
a BIG cannot be reconfigured with additional BISes after creation,
no more connections can be bound for the BIG after the start periodic
advertising and create BIG commands have been queued.
The bis_cleanup function has also been updated, so that the advertising
set and the BIG will not be terminated unless there are no more
bound or connected BISes.
The HCI_CONN_BIG_CREATED connection flag has been added to indicate
that the BIG has been successfully created. This flag is checked at
bis_cleanup, so that the BIG is only terminated if the
HCI_LE_Create_BIG_Complete has been received.
This implementation has been tested on hardware, using the "isotest"
tool with an additional command line option, to specify the number of
BISes to create as part of the desired BIG:
tools/isotest -i hci0 -s 00:00:00:00:00:00 -N 2 -G 1 -T 1
The btmon log shows that a BIG containing 2 BISes has been created:
< HCI Command: LE Create Broadcast Isochronous Group (0x08|0x0068) plen 31
Handle: 0x01
Advertising Handle: 0x01
Number of BIS: 2
SDU Interval: 10000 us (0x002710)
Maximum SDU size: 40
Maximum Latency: 10 ms (0x000a)
RTN: 0x02
PHY: LE 2M (0x02)
Packing: Sequential (0x00)
Framing: Unframed (0x00)
Encryption: 0x00
Broadcast Code: 00000000000000000000000000000000
> HCI Event: Command Status (0x0f) plen 4
LE Create Broadcast Isochronous Group (0x08|0x0068) ncmd 1
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 23
LE Broadcast Isochronous Group Complete (0x1b)
Status: Success (0x00)
Handle: 0x01
BIG Synchronization Delay: 1974 us (0x0007b6)
Transport Latency: 1974 us (0x0007b6)
PHY: LE 2M (0x02)
NSE: 3
BN: 1
PTO: 1
IRC: 3
Maximum PDU: 40
ISO Interval: 10.00 msec (0x0008)
Connection Handle #0: 10
Connection Handle #1: 11
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 10
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 10
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 11
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 11
< ISO Data TX: Handle 10 flags 0x02 dlen 44
< ISO Data TX: Handle 11 flags 0x02 dlen 44
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 10
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 11
Count: 1
Signed-off-by: Iulia Tanasescu <iulia.tanasescu@nxp.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2023-05-30 14:21:59 +00:00
|
|
|
hci_iso_qos_setup(hdev, conn, &qos->bcast.out,
|
|
|
|
conn->le_tx_phy ? conn->le_tx_phy :
|
|
|
|
hdev->le_tx_def_phys);
|
|
|
|
|
|
|
|
conn->iso_qos = *qos;
|
|
|
|
conn->state = BT_BOUND;
|
|
|
|
|
2023-11-13 15:38:00 +00:00
|
|
|
/* Link BISes together */
|
|
|
|
parent = hci_conn_hash_lookup_big(hdev,
|
|
|
|
conn->iso_qos.bcast.big);
|
|
|
|
if (parent && parent != conn) {
|
|
|
|
link = hci_conn_link(parent, conn);
|
|
|
|
hci_conn_drop(conn);
|
2024-10-01 07:21:25 +00:00
|
|
|
if (!link)
|
|
|
|
return ERR_PTR(-ENOLINK);
|
2023-11-13 15:38:00 +00:00
|
|
|
}
|
|
|
|
|
Bluetooth: ISO: Add support for connecting multiple BISes
It is required for some configurations to have multiple BISes as part
of the same BIG.
Similar to the flow implemented for unicast, DEFER_SETUP will also be
used to bind multiple BISes for the same BIG, before starting Periodic
Advertising and creating the BIG.
The user will have to open a new socket for each BIS. By setting the
BT_DEFER_SETUP socket option and calling connect, a new connection
will be added for the BIG and advertising handle set by the socket
QoS parameters. Since all BISes will be bound for the same BIG and
advertising handle, the socket QoS options and base parameters should
match for all connections.
By calling connect on a socket that does not have the BT_DEFER_SETUP
option set, periodic advertising will be started and the BIG will
be created, with a BIS for each previously bound connection. Since
a BIG cannot be reconfigured with additional BISes after creation,
no more connections can be bound for the BIG after the start periodic
advertising and create BIG commands have been queued.
The bis_cleanup function has also been updated, so that the advertising
set and the BIG will not be terminated unless there are no more
bound or connected BISes.
The HCI_CONN_BIG_CREATED connection flag has been added to indicate
that the BIG has been successfully created. This flag is checked at
bis_cleanup, so that the BIG is only terminated if the
HCI_LE_Create_BIG_Complete has been received.
This implementation has been tested on hardware, using the "isotest"
tool with an additional command line option, to specify the number of
BISes to create as part of the desired BIG:
tools/isotest -i hci0 -s 00:00:00:00:00:00 -N 2 -G 1 -T 1
The btmon log shows that a BIG containing 2 BISes has been created:
< HCI Command: LE Create Broadcast Isochronous Group (0x08|0x0068) plen 31
Handle: 0x01
Advertising Handle: 0x01
Number of BIS: 2
SDU Interval: 10000 us (0x002710)
Maximum SDU size: 40
Maximum Latency: 10 ms (0x000a)
RTN: 0x02
PHY: LE 2M (0x02)
Packing: Sequential (0x00)
Framing: Unframed (0x00)
Encryption: 0x00
Broadcast Code: 00000000000000000000000000000000
> HCI Event: Command Status (0x0f) plen 4
LE Create Broadcast Isochronous Group (0x08|0x0068) ncmd 1
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 23
LE Broadcast Isochronous Group Complete (0x1b)
Status: Success (0x00)
Handle: 0x01
BIG Synchronization Delay: 1974 us (0x0007b6)
Transport Latency: 1974 us (0x0007b6)
PHY: LE 2M (0x02)
NSE: 3
BN: 1
PTO: 1
IRC: 3
Maximum PDU: 40
ISO Interval: 10.00 msec (0x0008)
Connection Handle #0: 10
Connection Handle #1: 11
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 10
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 10
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 11
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 11
< ISO Data TX: Handle 10 flags 0x02 dlen 44
< ISO Data TX: Handle 11 flags 0x02 dlen 44
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 10
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 11
Count: 1
Signed-off-by: Iulia Tanasescu <iulia.tanasescu@nxp.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2023-05-30 14:21:59 +00:00
|
|
|
return conn;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bis_mark_per_adv(struct hci_conn *conn, void *data)
|
|
|
|
{
|
|
|
|
struct iso_list_data *d = data;
|
|
|
|
|
|
|
|
/* Skip if not broadcast/ANY address */
|
|
|
|
if (bacmp(&conn->dst, BDADDR_ANY))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (d->big != conn->iso_qos.bcast.big ||
|
|
|
|
d->bis == BT_ISO_QOS_BIS_UNSET ||
|
|
|
|
d->bis != conn->iso_qos.bcast.bis)
|
|
|
|
return;
|
|
|
|
|
|
|
|
set_bit(HCI_CONN_PER_ADV, &conn->flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct hci_conn *hci_connect_bis(struct hci_dev *hdev, bdaddr_t *dst,
|
|
|
|
__u8 dst_type, struct bt_iso_qos *qos,
|
|
|
|
__u8 base_len, __u8 *base)
|
|
|
|
{
|
|
|
|
struct hci_conn *conn;
|
|
|
|
int err;
|
|
|
|
struct iso_list_data data;
|
|
|
|
|
|
|
|
conn = hci_bind_bis(hdev, dst, qos, base_len, base);
|
|
|
|
if (IS_ERR(conn))
|
|
|
|
return conn;
|
|
|
|
|
2023-11-13 15:38:00 +00:00
|
|
|
if (conn->state == BT_CONNECTED)
|
|
|
|
return conn;
|
|
|
|
|
Bluetooth: ISO: Add support for connecting multiple BISes
It is required for some configurations to have multiple BISes as part
of the same BIG.
Similar to the flow implemented for unicast, DEFER_SETUP will also be
used to bind multiple BISes for the same BIG, before starting Periodic
Advertising and creating the BIG.
The user will have to open a new socket for each BIS. By setting the
BT_DEFER_SETUP socket option and calling connect, a new connection
will be added for the BIG and advertising handle set by the socket
QoS parameters. Since all BISes will be bound for the same BIG and
advertising handle, the socket QoS options and base parameters should
match for all connections.
By calling connect on a socket that does not have the BT_DEFER_SETUP
option set, periodic advertising will be started and the BIG will
be created, with a BIS for each previously bound connection. Since
a BIG cannot be reconfigured with additional BISes after creation,
no more connections can be bound for the BIG after the start periodic
advertising and create BIG commands have been queued.
The bis_cleanup function has also been updated, so that the advertising
set and the BIG will not be terminated unless there are no more
bound or connected BISes.
The HCI_CONN_BIG_CREATED connection flag has been added to indicate
that the BIG has been successfully created. This flag is checked at
bis_cleanup, so that the BIG is only terminated if the
HCI_LE_Create_BIG_Complete has been received.
This implementation has been tested on hardware, using the "isotest"
tool with an additional command line option, to specify the number of
BISes to create as part of the desired BIG:
tools/isotest -i hci0 -s 00:00:00:00:00:00 -N 2 -G 1 -T 1
The btmon log shows that a BIG containing 2 BISes has been created:
< HCI Command: LE Create Broadcast Isochronous Group (0x08|0x0068) plen 31
Handle: 0x01
Advertising Handle: 0x01
Number of BIS: 2
SDU Interval: 10000 us (0x002710)
Maximum SDU size: 40
Maximum Latency: 10 ms (0x000a)
RTN: 0x02
PHY: LE 2M (0x02)
Packing: Sequential (0x00)
Framing: Unframed (0x00)
Encryption: 0x00
Broadcast Code: 00000000000000000000000000000000
> HCI Event: Command Status (0x0f) plen 4
LE Create Broadcast Isochronous Group (0x08|0x0068) ncmd 1
Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 23
LE Broadcast Isochronous Group Complete (0x1b)
Status: Success (0x00)
Handle: 0x01
BIG Synchronization Delay: 1974 us (0x0007b6)
Transport Latency: 1974 us (0x0007b6)
PHY: LE 2M (0x02)
NSE: 3
BN: 1
PTO: 1
IRC: 3
Maximum PDU: 40
ISO Interval: 10.00 msec (0x0008)
Connection Handle #0: 10
Connection Handle #1: 11
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 10
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 10
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 11
Data Path Direction: Input (Host to Controller) (0x00)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration:
> HCI Event: Command Complete (0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 11
< ISO Data TX: Handle 10 flags 0x02 dlen 44
< ISO Data TX: Handle 11 flags 0x02 dlen 44
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 10
Count: 1
> HCI Event: Number of Completed Packets (0x13) plen 5
Num handles: 1
Handle: 11
Count: 1
Signed-off-by: Iulia Tanasescu <iulia.tanasescu@nxp.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2023-05-30 14:21:59 +00:00
|
|
|
data.big = qos->bcast.big;
|
|
|
|
data.bis = qos->bcast.bis;
|
|
|
|
|
|
|
|
/* Set HCI_CONN_PER_ADV for all bound connections, to mark that
|
|
|
|
* the start periodic advertising and create BIG commands have
|
|
|
|
* been queued
|
|
|
|
*/
|
|
|
|
hci_conn_hash_list_state(hdev, bis_mark_per_adv, ISO_LINK,
|
|
|
|
BT_BOUND, &data);
|
|
|
|
|
2022-03-09 21:22:20 +00:00
|
|
|
/* Queue start periodic advertising and create BIG */
|
|
|
|
err = hci_cmd_sync_queue(hdev, create_big_sync, conn,
|
|
|
|
create_big_complete);
|
|
|
|
if (err < 0) {
|
|
|
|
hci_conn_drop(conn);
|
|
|
|
return ERR_PTR(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
return conn;
|
|
|
|
}
|
|
|
|
|
2019-07-29 15:15:43 +00:00
|
|
|
struct hci_conn *hci_connect_cis(struct hci_dev *hdev, bdaddr_t *dst,
|
|
|
|
__u8 dst_type, struct bt_iso_qos *qos)
|
|
|
|
{
|
|
|
|
struct hci_conn *le;
|
|
|
|
struct hci_conn *cis;
|
2023-04-11 23:02:22 +00:00
|
|
|
struct hci_link *link;
|
2019-07-29 15:15:43 +00:00
|
|
|
|
|
|
|
if (hci_dev_test_flag(hdev, HCI_ADVERTISING))
|
|
|
|
le = hci_connect_le(hdev, dst, dst_type, false,
|
|
|
|
BT_SECURITY_LOW,
|
|
|
|
HCI_LE_CONN_TIMEOUT,
|
2024-04-05 20:40:33 +00:00
|
|
|
HCI_ROLE_SLAVE, 0, 0);
|
2019-07-29 15:15:43 +00:00
|
|
|
else
|
|
|
|
le = hci_connect_le_scan(hdev, dst, dst_type,
|
|
|
|
BT_SECURITY_LOW,
|
|
|
|
HCI_LE_CONN_TIMEOUT,
|
|
|
|
CONN_REASON_ISO_CONNECT);
|
|
|
|
if (IS_ERR(le))
|
|
|
|
return le;
|
|
|
|
|
2023-03-31 15:38:01 +00:00
|
|
|
hci_iso_qos_setup(hdev, le, &qos->ucast.out,
|
2019-07-29 15:15:43 +00:00
|
|
|
le->le_tx_phy ? le->le_tx_phy : hdev->le_tx_def_phys);
|
2023-03-31 15:38:01 +00:00
|
|
|
hci_iso_qos_setup(hdev, le, &qos->ucast.in,
|
2019-07-29 15:15:43 +00:00
|
|
|
le->le_rx_phy ? le->le_rx_phy : hdev->le_rx_def_phys);
|
|
|
|
|
|
|
|
cis = hci_bind_cis(hdev, dst, dst_type, qos);
|
|
|
|
if (IS_ERR(cis)) {
|
|
|
|
hci_conn_drop(le);
|
|
|
|
return cis;
|
|
|
|
}
|
|
|
|
|
2023-04-11 23:02:22 +00:00
|
|
|
link = hci_conn_link(le, cis);
|
2024-10-01 07:21:25 +00:00
|
|
|
hci_conn_drop(cis);
|
2023-04-11 23:02:22 +00:00
|
|
|
if (!link) {
|
|
|
|
hci_conn_drop(le);
|
2023-07-11 13:13:53 +00:00
|
|
|
return ERR_PTR(-ENOLINK);
|
2023-04-11 23:02:22 +00:00
|
|
|
}
|
2019-07-29 15:15:43 +00:00
|
|
|
|
2023-06-01 06:34:46 +00:00
|
|
|
cis->state = BT_CONNECT;
|
|
|
|
|
|
|
|
hci_le_create_cis_pending(hdev);
|
2019-07-29 15:15:43 +00:00
|
|
|
|
|
|
|
return cis;
|
|
|
|
}
|
|
|
|
|
2008-09-09 05:19:20 +00:00
|
|
|
/* Check link security requirement */
|
|
|
|
int hci_conn_check_link_mode(struct hci_conn *conn)
|
|
|
|
{
|
2012-06-15 08:50:28 +00:00
|
|
|
BT_DBG("hcon %p", conn);
|
2008-09-09 05:19:20 +00:00
|
|
|
|
2014-03-19 21:10:25 +00:00
|
|
|
/* In Secure Connections Only mode, it is required that Secure
|
|
|
|
* Connections is used and the link is encrypted with AES-CCM
|
|
|
|
* using a P-256 authenticated combination key.
|
|
|
|
*/
|
2015-03-13 09:11:00 +00:00
|
|
|
if (hci_dev_test_flag(conn->hdev, HCI_SC_ONLY)) {
|
2014-03-19 21:10:25 +00:00
|
|
|
if (!hci_conn_sc_enabled(conn) ||
|
|
|
|
!test_bit(HCI_CONN_AES_CCM, &conn->flags) ||
|
|
|
|
conn->key_type != HCI_LK_AUTH_COMBINATION_P256)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-20 21:20:14 +00:00
|
|
|
/* AES encryption is required for Level 4:
|
|
|
|
*
|
|
|
|
* BLUETOOTH CORE SPECIFICATION Version 5.2 | Vol 3, Part C
|
|
|
|
* page 1319:
|
|
|
|
*
|
|
|
|
* 128-bit equivalent strength for link and encryption keys
|
|
|
|
* required using FIPS approved algorithms (E0 not allowed,
|
|
|
|
* SAFER+ not allowed, and P-192 not allowed; encryption key
|
|
|
|
* not shortened)
|
|
|
|
*/
|
|
|
|
if (conn->sec_level == BT_SECURITY_FIPS &&
|
|
|
|
!test_bit(HCI_CONN_AES_CCM, &conn->flags)) {
|
|
|
|
bt_dev_err(conn->hdev,
|
|
|
|
"Invalid security: Missing AES-CCM usage");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-24 14:03:50 +00:00
|
|
|
if (hci_conn_ssp_enabled(conn) &&
|
|
|
|
!test_bit(HCI_CONN_ENCRYPT, &conn->flags))
|
2008-09-09 05:19:20 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Authenticate remote device */
|
2009-02-09 01:48:38 +00:00
|
|
|
static int hci_conn_auth(struct hci_conn *conn, __u8 sec_level, __u8 auth_type)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2012-06-15 08:50:28 +00:00
|
|
|
BT_DBG("hcon %p", conn);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-01-19 06:36:52 +00:00
|
|
|
if (conn->pending_sec_level > sec_level)
|
|
|
|
sec_level = conn->pending_sec_level;
|
|
|
|
|
2009-02-12 15:23:03 +00:00
|
|
|
if (sec_level > conn->sec_level)
|
2011-01-19 06:36:52 +00:00
|
|
|
conn->pending_sec_level = sec_level;
|
2014-06-24 14:03:50 +00:00
|
|
|
else if (test_bit(HCI_CONN_AUTH, &conn->flags))
|
2005-04-16 22:20:36 +00:00
|
|
|
return 1;
|
|
|
|
|
2011-01-19 06:36:49 +00:00
|
|
|
/* Make sure we preserve an existing MITM requirement*/
|
|
|
|
auth_type |= (conn->auth_type & 0x01);
|
|
|
|
|
2009-02-12 15:23:03 +00:00
|
|
|
conn->auth_type = auth_type;
|
|
|
|
|
2012-01-16 04:10:31 +00:00
|
|
|
if (!test_and_set_bit(HCI_CONN_AUTH_PEND, &conn->flags)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
struct hci_cp_auth_requested cp;
|
2012-01-13 14:11:30 +00:00
|
|
|
|
2007-03-26 03:12:50 +00:00
|
|
|
cp.handle = cpu_to_le16(conn->handle);
|
2008-07-14 18:13:50 +00:00
|
|
|
hci_send_cmd(conn->hdev, HCI_OP_AUTH_REQUESTED,
|
2012-05-17 03:36:25 +00:00
|
|
|
sizeof(cp), &cp);
|
2014-04-11 19:02:32 +00:00
|
|
|
|
2023-11-30 13:58:03 +00:00
|
|
|
/* Set the ENCRYPT_PEND to trigger encryption after
|
|
|
|
* authentication.
|
2014-04-11 19:02:32 +00:00
|
|
|
*/
|
2023-11-30 13:58:03 +00:00
|
|
|
if (!test_bit(HCI_CONN_ENCRYPT, &conn->flags))
|
2014-04-11 19:02:32 +00:00
|
|
|
set_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2009-01-15 20:58:04 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-18 04:35:18 +00:00
|
|
|
/* Encrypt the link */
|
2011-04-28 10:07:55 +00:00
|
|
|
static void hci_conn_encrypt(struct hci_conn *conn)
|
|
|
|
{
|
2012-06-15 08:50:28 +00:00
|
|
|
BT_DBG("hcon %p", conn);
|
2011-04-28 10:07:55 +00:00
|
|
|
|
2012-01-16 04:10:31 +00:00
|
|
|
if (!test_and_set_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) {
|
2011-04-28 10:07:55 +00:00
|
|
|
struct hci_cp_set_conn_encrypt cp;
|
|
|
|
cp.handle = cpu_to_le16(conn->handle);
|
|
|
|
cp.encrypt = 0x01;
|
|
|
|
hci_send_cmd(conn->hdev, HCI_OP_SET_CONN_ENCRYPT, sizeof(cp),
|
2012-05-17 03:36:25 +00:00
|
|
|
&cp);
|
2011-04-28 10:07:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-15 20:58:04 +00:00
|
|
|
/* Enable security */
|
2014-07-17 12:35:38 +00:00
|
|
|
int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type,
|
|
|
|
bool initiator)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2012-06-15 08:50:28 +00:00
|
|
|
BT_DBG("hcon %p", conn);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-08-24 00:32:44 +00:00
|
|
|
if (conn->type == LE_LINK)
|
|
|
|
return smp_conn_security(conn, sec_level);
|
|
|
|
|
2011-04-28 10:07:55 +00:00
|
|
|
/* For sdp we don't need the link key. */
|
2009-01-15 20:58:04 +00:00
|
|
|
if (sec_level == BT_SECURITY_SDP)
|
|
|
|
return 1;
|
|
|
|
|
2011-04-28 10:07:55 +00:00
|
|
|
/* For non 2.1 devices and low security level we don't need the link
|
|
|
|
key. */
|
2012-01-18 19:33:12 +00:00
|
|
|
if (sec_level == BT_SECURITY_LOW && !hci_conn_ssp_enabled(conn))
|
2009-04-28 16:04:55 +00:00
|
|
|
return 1;
|
2009-01-15 20:58:04 +00:00
|
|
|
|
2011-04-28 10:07:55 +00:00
|
|
|
/* For other security levels we need the link key. */
|
2014-06-24 14:03:50 +00:00
|
|
|
if (!test_bit(HCI_CONN_AUTH, &conn->flags))
|
2011-04-28 10:07:55 +00:00
|
|
|
goto auth;
|
|
|
|
|
2023-09-07 04:39:34 +00:00
|
|
|
switch (conn->key_type) {
|
|
|
|
case HCI_LK_AUTH_COMBINATION_P256:
|
|
|
|
/* An authenticated FIPS approved combination key has
|
|
|
|
* sufficient security for security level 4 or lower.
|
|
|
|
*/
|
|
|
|
if (sec_level <= BT_SECURITY_FIPS)
|
|
|
|
goto encrypt;
|
|
|
|
break;
|
|
|
|
case HCI_LK_AUTH_COMBINATION_P192:
|
|
|
|
/* An authenticated combination key has sufficient security for
|
|
|
|
* security level 3 or lower.
|
|
|
|
*/
|
|
|
|
if (sec_level <= BT_SECURITY_HIGH)
|
|
|
|
goto encrypt;
|
|
|
|
break;
|
|
|
|
case HCI_LK_UNAUTH_COMBINATION_P192:
|
|
|
|
case HCI_LK_UNAUTH_COMBINATION_P256:
|
|
|
|
/* An unauthenticated combination key has sufficient security
|
|
|
|
* for security level 2 or lower.
|
|
|
|
*/
|
|
|
|
if (sec_level <= BT_SECURITY_MEDIUM)
|
|
|
|
goto encrypt;
|
|
|
|
break;
|
|
|
|
case HCI_LK_COMBINATION:
|
|
|
|
/* A combination key has always sufficient security for the
|
|
|
|
* security levels 2 or lower. High security level requires the
|
|
|
|
* combination key is generated using maximum PIN code length
|
|
|
|
* (16). For pre 2.1 units.
|
|
|
|
*/
|
|
|
|
if (sec_level <= BT_SECURITY_MEDIUM || conn->pin_length == 16)
|
|
|
|
goto encrypt;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-04-28 10:07:55 +00:00
|
|
|
|
|
|
|
auth:
|
2012-01-16 04:10:31 +00:00
|
|
|
if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags))
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
|
2014-07-17 12:35:39 +00:00
|
|
|
if (initiator)
|
|
|
|
set_bit(HCI_CONN_AUTH_INITIATOR, &conn->flags);
|
|
|
|
|
2011-06-13 12:37:35 +00:00
|
|
|
if (!hci_conn_auth(conn, sec_level, auth_type))
|
|
|
|
return 0;
|
2011-04-28 10:07:55 +00:00
|
|
|
|
|
|
|
encrypt:
|
2019-06-22 13:47:01 +00:00
|
|
|
if (test_bit(HCI_CONN_ENCRYPT, &conn->flags)) {
|
|
|
|
/* Ensure that the encryption key size has been read,
|
|
|
|
* otherwise stall the upper layer responses.
|
|
|
|
*/
|
|
|
|
if (!conn->enc_key_size)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Nothing else needed, all requirements are met */
|
2011-04-28 10:07:55 +00:00
|
|
|
return 1;
|
2019-06-22 13:47:01 +00:00
|
|
|
}
|
2009-01-15 20:58:04 +00:00
|
|
|
|
2011-04-28 10:07:55 +00:00
|
|
|
hci_conn_encrypt(conn);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-01-15 20:58:04 +00:00
|
|
|
EXPORT_SYMBOL(hci_conn_security);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-05-06 07:42:31 +00:00
|
|
|
/* Check secure link requirement */
|
|
|
|
int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level)
|
|
|
|
{
|
2012-06-15 08:50:28 +00:00
|
|
|
BT_DBG("hcon %p", conn);
|
2011-05-06 07:42:31 +00:00
|
|
|
|
2014-02-01 19:32:25 +00:00
|
|
|
/* Accept if non-secure or higher security level is required */
|
|
|
|
if (sec_level != BT_SECURITY_HIGH && sec_level != BT_SECURITY_FIPS)
|
|
|
|
return 1;
|
2011-05-06 07:42:31 +00:00
|
|
|
|
2014-02-01 19:32:25 +00:00
|
|
|
/* Accept if secure or higher security level is already present */
|
|
|
|
if (conn->sec_level == BT_SECURITY_HIGH ||
|
|
|
|
conn->sec_level == BT_SECURITY_FIPS)
|
2011-05-06 07:42:31 +00:00
|
|
|
return 1;
|
|
|
|
|
2014-02-01 19:32:25 +00:00
|
|
|
/* Reject not secure link */
|
|
|
|
return 0;
|
2011-05-06 07:42:31 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(hci_conn_check_secure);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Switch role */
|
2009-01-15 20:58:04 +00:00
|
|
|
int hci_conn_switch_role(struct hci_conn *conn, __u8 role)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2012-06-15 08:50:28 +00:00
|
|
|
BT_DBG("hcon %p", conn);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2014-07-16 08:42:27 +00:00
|
|
|
if (role == conn->role)
|
2005-04-16 22:20:36 +00:00
|
|
|
return 1;
|
|
|
|
|
2012-01-16 04:10:31 +00:00
|
|
|
if (!test_and_set_bit(HCI_CONN_RSWITCH_PEND, &conn->flags)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
struct hci_cp_switch_role cp;
|
|
|
|
bacpy(&cp.bdaddr, &conn->dst);
|
|
|
|
cp.role = role;
|
2007-10-20 11:33:56 +00:00
|
|
|
hci_send_cmd(conn->hdev, HCI_OP_SWITCH_ROLE, sizeof(cp), &cp);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2009-01-15 20:58:04 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(hci_conn_switch_role);
|
|
|
|
|
2006-07-03 08:02:33 +00:00
|
|
|
/* Enter active mode */
|
2011-05-24 01:06:04 +00:00
|
|
|
void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active)
|
2006-07-03 08:02:33 +00:00
|
|
|
{
|
|
|
|
struct hci_dev *hdev = conn->hdev;
|
|
|
|
|
2012-06-15 08:50:28 +00:00
|
|
|
BT_DBG("hcon %p mode %d", conn, conn->mode);
|
2006-07-03 08:02:33 +00:00
|
|
|
|
2011-05-24 01:06:04 +00:00
|
|
|
if (conn->mode != HCI_CM_SNIFF)
|
|
|
|
goto timer;
|
|
|
|
|
2012-01-16 04:47:28 +00:00
|
|
|
if (!test_bit(HCI_CONN_POWER_SAVE, &conn->flags) && !force_active)
|
2006-07-03 08:02:33 +00:00
|
|
|
goto timer;
|
|
|
|
|
2012-01-16 04:10:31 +00:00
|
|
|
if (!test_and_set_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags)) {
|
2006-07-03 08:02:33 +00:00
|
|
|
struct hci_cp_exit_sniff_mode cp;
|
2007-03-26 03:12:50 +00:00
|
|
|
cp.handle = cpu_to_le16(conn->handle);
|
2007-10-20 11:33:56 +00:00
|
|
|
hci_send_cmd(hdev, HCI_OP_EXIT_SNIFF_MODE, sizeof(cp), &cp);
|
2006-07-03 08:02:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
timer:
|
|
|
|
if (hdev->idle_timeout > 0)
|
2013-10-16 15:11:40 +00:00
|
|
|
queue_delayed_work(hdev->workqueue, &conn->idle_work,
|
|
|
|
msecs_to_jiffies(hdev->idle_timeout));
|
2006-07-03 08:02:33 +00:00
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Drop all connection on the device */
|
|
|
|
void hci_conn_hash_flush(struct hci_dev *hdev)
|
|
|
|
{
|
2023-05-03 13:39:36 +00:00
|
|
|
struct list_head *head = &hdev->conn_hash.list;
|
|
|
|
struct hci_conn *conn;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
BT_DBG("hdev %s", hdev->name);
|
|
|
|
|
2023-05-03 13:39:36 +00:00
|
|
|
/* We should not traverse the list here, because hci_conn_del
|
|
|
|
* can remove extra links, which may cause the list traversal
|
|
|
|
* to hit items that have already been released.
|
|
|
|
*/
|
|
|
|
while ((conn = list_first_entry_or_null(head,
|
|
|
|
struct hci_conn,
|
|
|
|
list)) != NULL) {
|
|
|
|
conn->state = BT_CLOSED;
|
|
|
|
hci_disconn_cfm(conn, HCI_ERROR_LOCAL_HOST_TERM);
|
|
|
|
hci_conn_del(conn);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-24 14:03:50 +00:00
|
|
|
static u32 get_link_mode(struct hci_conn *conn)
|
|
|
|
{
|
|
|
|
u32 link_mode = 0;
|
|
|
|
|
2014-07-16 08:42:27 +00:00
|
|
|
if (conn->role == HCI_ROLE_MASTER)
|
2014-06-24 14:03:50 +00:00
|
|
|
link_mode |= HCI_LM_MASTER;
|
|
|
|
|
|
|
|
if (test_bit(HCI_CONN_ENCRYPT, &conn->flags))
|
|
|
|
link_mode |= HCI_LM_ENCRYPT;
|
|
|
|
|
|
|
|
if (test_bit(HCI_CONN_AUTH, &conn->flags))
|
|
|
|
link_mode |= HCI_LM_AUTH;
|
|
|
|
|
|
|
|
if (test_bit(HCI_CONN_SECURE, &conn->flags))
|
|
|
|
link_mode |= HCI_LM_SECURE;
|
|
|
|
|
|
|
|
if (test_bit(HCI_CONN_FIPS, &conn->flags))
|
|
|
|
link_mode |= HCI_LM_FIPS;
|
|
|
|
|
|
|
|
return link_mode;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
int hci_get_conn_list(void __user *arg)
|
|
|
|
{
|
2012-05-23 07:04:19 +00:00
|
|
|
struct hci_conn *c;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct hci_conn_list_req req, *cl;
|
|
|
|
struct hci_conn_info *ci;
|
|
|
|
struct hci_dev *hdev;
|
|
|
|
int n = 0, size, err;
|
|
|
|
|
|
|
|
if (copy_from_user(&req, arg, sizeof(req)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
if (!req.conn_num || req.conn_num > (PAGE_SIZE * 2) / sizeof(*ci))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
size = sizeof(req) + req.conn_num * sizeof(*ci);
|
|
|
|
|
2010-12-01 14:58:25 +00:00
|
|
|
cl = kmalloc(size, GFP_KERNEL);
|
|
|
|
if (!cl)
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-12-01 14:58:25 +00:00
|
|
|
hdev = hci_dev_get(req.dev_id);
|
|
|
|
if (!hdev) {
|
2005-04-16 22:20:36 +00:00
|
|
|
kfree(cl);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
ci = cl->conn_info;
|
|
|
|
|
2011-06-17 16:03:21 +00:00
|
|
|
hci_dev_lock(hdev);
|
2011-11-01 08:58:56 +00:00
|
|
|
list_for_each_entry(c, &hdev->conn_hash.list, list) {
|
2005-04-16 22:20:36 +00:00
|
|
|
bacpy(&(ci + n)->bdaddr, &c->dst);
|
|
|
|
(ci + n)->handle = c->handle;
|
|
|
|
(ci + n)->type = c->type;
|
|
|
|
(ci + n)->out = c->out;
|
|
|
|
(ci + n)->state = c->state;
|
2014-06-24 14:03:50 +00:00
|
|
|
(ci + n)->link_mode = get_link_mode(c);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (++n >= req.conn_num)
|
|
|
|
break;
|
|
|
|
}
|
2011-06-17 16:03:21 +00:00
|
|
|
hci_dev_unlock(hdev);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
cl->dev_id = hdev->id;
|
|
|
|
cl->conn_num = n;
|
|
|
|
size = sizeof(req) + n * sizeof(*ci);
|
|
|
|
|
|
|
|
hci_dev_put(hdev);
|
|
|
|
|
|
|
|
err = copy_to_user(arg, cl, size);
|
|
|
|
kfree(cl);
|
|
|
|
|
|
|
|
return err ? -EFAULT : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int hci_get_conn_info(struct hci_dev *hdev, void __user *arg)
|
|
|
|
{
|
|
|
|
struct hci_conn_info_req req;
|
|
|
|
struct hci_conn_info ci;
|
|
|
|
struct hci_conn *conn;
|
|
|
|
char __user *ptr = arg + sizeof(req);
|
|
|
|
|
|
|
|
if (copy_from_user(&req, arg, sizeof(req)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2011-06-17 16:03:21 +00:00
|
|
|
hci_dev_lock(hdev);
|
2005-04-16 22:20:36 +00:00
|
|
|
conn = hci_conn_hash_lookup_ba(hdev, req.type, &req.bdaddr);
|
|
|
|
if (conn) {
|
|
|
|
bacpy(&ci.bdaddr, &conn->dst);
|
|
|
|
ci.handle = conn->handle;
|
|
|
|
ci.type = conn->type;
|
|
|
|
ci.out = conn->out;
|
|
|
|
ci.state = conn->state;
|
2014-06-24 14:03:50 +00:00
|
|
|
ci.link_mode = get_link_mode(conn);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2011-06-17 16:03:21 +00:00
|
|
|
hci_dev_unlock(hdev);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (!conn)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
return copy_to_user(ptr, &ci, sizeof(ci)) ? -EFAULT : 0;
|
|
|
|
}
|
2008-07-14 18:13:50 +00:00
|
|
|
|
|
|
|
int hci_get_auth_info(struct hci_dev *hdev, void __user *arg)
|
|
|
|
{
|
|
|
|
struct hci_auth_info_req req;
|
|
|
|
struct hci_conn *conn;
|
|
|
|
|
|
|
|
if (copy_from_user(&req, arg, sizeof(req)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2011-06-17 16:03:21 +00:00
|
|
|
hci_dev_lock(hdev);
|
2008-07-14 18:13:50 +00:00
|
|
|
conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &req.bdaddr);
|
|
|
|
if (conn)
|
|
|
|
req.type = conn->auth_type;
|
2011-06-17 16:03:21 +00:00
|
|
|
hci_dev_unlock(hdev);
|
2008-07-14 18:13:50 +00:00
|
|
|
|
|
|
|
if (!conn)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
return copy_to_user(arg, &req, sizeof(req)) ? -EFAULT : 0;
|
|
|
|
}
|
2011-11-02 13:52:01 +00:00
|
|
|
|
|
|
|
struct hci_chan *hci_chan_create(struct hci_conn *conn)
|
|
|
|
{
|
|
|
|
struct hci_dev *hdev = conn->hdev;
|
|
|
|
struct hci_chan *chan;
|
|
|
|
|
2012-06-15 08:50:28 +00:00
|
|
|
BT_DBG("%s hcon %p", hdev->name, conn);
|
2011-11-02 13:52:01 +00:00
|
|
|
|
2014-08-17 21:41:44 +00:00
|
|
|
if (test_bit(HCI_CONN_DROP, &conn->flags)) {
|
|
|
|
BT_DBG("Refusing to create new hci_chan");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-07-21 07:50:06 +00:00
|
|
|
chan = kzalloc(sizeof(*chan), GFP_KERNEL);
|
2011-11-02 13:52:01 +00:00
|
|
|
if (!chan)
|
|
|
|
return NULL;
|
|
|
|
|
2014-08-17 21:41:42 +00:00
|
|
|
chan->conn = hci_conn_get(conn);
|
2011-11-02 13:52:01 +00:00
|
|
|
skb_queue_head_init(&chan->data_q);
|
2012-10-23 22:24:13 +00:00
|
|
|
chan->state = BT_CONNECTED;
|
2011-11-02 13:52:01 +00:00
|
|
|
|
2011-12-14 17:08:48 +00:00
|
|
|
list_add_rcu(&chan->list, &conn->chan_list);
|
2011-11-02 13:52:01 +00:00
|
|
|
|
|
|
|
return chan;
|
|
|
|
}
|
|
|
|
|
2012-09-06 12:05:43 +00:00
|
|
|
void hci_chan_del(struct hci_chan *chan)
|
2011-11-02 13:52:01 +00:00
|
|
|
{
|
|
|
|
struct hci_conn *conn = chan->conn;
|
|
|
|
struct hci_dev *hdev = conn->hdev;
|
|
|
|
|
2012-06-15 08:50:28 +00:00
|
|
|
BT_DBG("%s hcon %p chan %p", hdev->name, conn, chan);
|
2011-11-02 13:52:01 +00:00
|
|
|
|
2011-12-14 17:08:48 +00:00
|
|
|
list_del_rcu(&chan->list);
|
|
|
|
|
|
|
|
synchronize_rcu();
|
2011-11-02 13:52:01 +00:00
|
|
|
|
2014-08-18 17:33:27 +00:00
|
|
|
/* Prevent new hci_chan's to be created for this hci_conn */
|
2014-08-17 21:41:44 +00:00
|
|
|
set_bit(HCI_CONN_DROP, &conn->flags);
|
2014-08-17 21:41:43 +00:00
|
|
|
|
2014-08-17 21:41:42 +00:00
|
|
|
hci_conn_put(conn);
|
2012-10-25 12:20:51 +00:00
|
|
|
|
2011-11-02 13:52:01 +00:00
|
|
|
skb_queue_purge(&chan->data_q);
|
|
|
|
kfree(chan);
|
|
|
|
}
|
|
|
|
|
2011-12-14 15:02:51 +00:00
|
|
|
void hci_chan_list_flush(struct hci_conn *conn)
|
2011-11-02 13:52:01 +00:00
|
|
|
{
|
2012-02-02 08:32:18 +00:00
|
|
|
struct hci_chan *chan, *n;
|
2011-11-02 13:52:01 +00:00
|
|
|
|
2012-06-15 08:50:28 +00:00
|
|
|
BT_DBG("hcon %p", conn);
|
2011-11-02 13:52:01 +00:00
|
|
|
|
2012-02-02 08:32:18 +00:00
|
|
|
list_for_each_entry_safe(chan, n, &conn->chan_list, list)
|
2011-11-02 13:52:01 +00:00
|
|
|
hci_chan_del(chan);
|
|
|
|
}
|
2012-10-10 14:38:28 +00:00
|
|
|
|
|
|
|
static struct hci_chan *__hci_chan_lookup_handle(struct hci_conn *hcon,
|
|
|
|
__u16 handle)
|
|
|
|
{
|
|
|
|
struct hci_chan *hchan;
|
|
|
|
|
|
|
|
list_for_each_entry(hchan, &hcon->chan_list, list) {
|
|
|
|
if (hchan->handle == handle)
|
|
|
|
return hchan;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle)
|
|
|
|
{
|
|
|
|
struct hci_conn_hash *h = &hdev->conn_hash;
|
|
|
|
struct hci_conn *hcon;
|
|
|
|
struct hci_chan *hchan = NULL;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
|
|
|
|
list_for_each_entry_rcu(hcon, &h->list, list) {
|
|
|
|
hchan = __hci_chan_lookup_handle(hcon, handle);
|
|
|
|
if (hchan)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
return hchan;
|
|
|
|
}
|
2020-02-14 18:08:57 +00:00
|
|
|
|
|
|
|
u32 hci_conn_get_phy(struct hci_conn *conn)
|
|
|
|
{
|
|
|
|
u32 phys = 0;
|
|
|
|
|
|
|
|
/* BLUETOOTH CORE SPECIFICATION Version 5.2 | Vol 2, Part B page 471:
|
|
|
|
* Table 6.2: Packets defined for synchronous, asynchronous, and
|
2021-05-31 08:37:22 +00:00
|
|
|
* CPB logical transport types.
|
2020-02-14 18:08:57 +00:00
|
|
|
*/
|
|
|
|
switch (conn->type) {
|
|
|
|
case SCO_LINK:
|
|
|
|
/* SCO logical transport (1 Mb/s):
|
|
|
|
* HV1, HV2, HV3 and DV.
|
|
|
|
*/
|
|
|
|
phys |= BT_PHY_BR_1M_1SLOT;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ACL_LINK:
|
|
|
|
/* ACL logical transport (1 Mb/s) ptt=0:
|
|
|
|
* DH1, DM3, DH3, DM5 and DH5.
|
|
|
|
*/
|
|
|
|
phys |= BT_PHY_BR_1M_1SLOT;
|
|
|
|
|
|
|
|
if (conn->pkt_type & (HCI_DM3 | HCI_DH3))
|
|
|
|
phys |= BT_PHY_BR_1M_3SLOT;
|
|
|
|
|
|
|
|
if (conn->pkt_type & (HCI_DM5 | HCI_DH5))
|
|
|
|
phys |= BT_PHY_BR_1M_5SLOT;
|
|
|
|
|
|
|
|
/* ACL logical transport (2 Mb/s) ptt=1:
|
|
|
|
* 2-DH1, 2-DH3 and 2-DH5.
|
|
|
|
*/
|
|
|
|
if (!(conn->pkt_type & HCI_2DH1))
|
|
|
|
phys |= BT_PHY_EDR_2M_1SLOT;
|
|
|
|
|
|
|
|
if (!(conn->pkt_type & HCI_2DH3))
|
|
|
|
phys |= BT_PHY_EDR_2M_3SLOT;
|
|
|
|
|
|
|
|
if (!(conn->pkt_type & HCI_2DH5))
|
|
|
|
phys |= BT_PHY_EDR_2M_5SLOT;
|
|
|
|
|
|
|
|
/* ACL logical transport (3 Mb/s) ptt=1:
|
|
|
|
* 3-DH1, 3-DH3 and 3-DH5.
|
|
|
|
*/
|
|
|
|
if (!(conn->pkt_type & HCI_3DH1))
|
|
|
|
phys |= BT_PHY_EDR_3M_1SLOT;
|
|
|
|
|
|
|
|
if (!(conn->pkt_type & HCI_3DH3))
|
|
|
|
phys |= BT_PHY_EDR_3M_3SLOT;
|
|
|
|
|
|
|
|
if (!(conn->pkt_type & HCI_3DH5))
|
|
|
|
phys |= BT_PHY_EDR_3M_5SLOT;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ESCO_LINK:
|
|
|
|
/* eSCO logical transport (1 Mb/s): EV3, EV4 and EV5 */
|
|
|
|
phys |= BT_PHY_BR_1M_1SLOT;
|
|
|
|
|
|
|
|
if (!(conn->pkt_type & (ESCO_EV4 | ESCO_EV5)))
|
|
|
|
phys |= BT_PHY_BR_1M_3SLOT;
|
|
|
|
|
|
|
|
/* eSCO logical transport (2 Mb/s): 2-EV3, 2-EV5 */
|
|
|
|
if (!(conn->pkt_type & ESCO_2EV3))
|
|
|
|
phys |= BT_PHY_EDR_2M_1SLOT;
|
|
|
|
|
|
|
|
if (!(conn->pkt_type & ESCO_2EV5))
|
|
|
|
phys |= BT_PHY_EDR_2M_3SLOT;
|
|
|
|
|
|
|
|
/* eSCO logical transport (3 Mb/s): 3-EV3, 3-EV5 */
|
|
|
|
if (!(conn->pkt_type & ESCO_3EV3))
|
|
|
|
phys |= BT_PHY_EDR_3M_1SLOT;
|
|
|
|
|
|
|
|
if (!(conn->pkt_type & ESCO_3EV5))
|
|
|
|
phys |= BT_PHY_EDR_3M_3SLOT;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LE_LINK:
|
|
|
|
if (conn->le_tx_phy & HCI_LE_SET_PHY_1M)
|
|
|
|
phys |= BT_PHY_LE_1M_TX;
|
|
|
|
|
|
|
|
if (conn->le_rx_phy & HCI_LE_SET_PHY_1M)
|
|
|
|
phys |= BT_PHY_LE_1M_RX;
|
|
|
|
|
|
|
|
if (conn->le_tx_phy & HCI_LE_SET_PHY_2M)
|
|
|
|
phys |= BT_PHY_LE_2M_TX;
|
|
|
|
|
|
|
|
if (conn->le_rx_phy & HCI_LE_SET_PHY_2M)
|
|
|
|
phys |= BT_PHY_LE_2M_RX;
|
|
|
|
|
|
|
|
if (conn->le_tx_phy & HCI_LE_SET_PHY_CODED)
|
|
|
|
phys |= BT_PHY_LE_CODED_TX;
|
|
|
|
|
|
|
|
if (conn->le_rx_phy & HCI_LE_SET_PHY_CODED)
|
|
|
|
phys |= BT_PHY_LE_CODED_RX;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return phys;
|
|
|
|
}
|
2022-08-16 16:41:20 +00:00
|
|
|
|
2023-06-27 00:25:06 +00:00
|
|
|
static int abort_conn_sync(struct hci_dev *hdev, void *data)
|
2022-08-16 16:41:20 +00:00
|
|
|
{
|
2024-02-13 14:59:32 +00:00
|
|
|
struct hci_conn *conn = data;
|
2022-08-16 16:41:20 +00:00
|
|
|
|
2024-02-13 14:59:32 +00:00
|
|
|
if (!hci_conn_valid(hdev, conn))
|
|
|
|
return -ECANCELED;
|
2023-03-24 20:18:20 +00:00
|
|
|
|
2023-06-27 00:25:06 +00:00
|
|
|
return hci_abort_conn_sync(hdev, conn, conn->abort_reason);
|
|
|
|
}
|
2022-08-16 16:41:20 +00:00
|
|
|
|
2023-06-27 00:25:06 +00:00
|
|
|
int hci_abort_conn(struct hci_conn *conn, u8 reason)
|
|
|
|
{
|
|
|
|
struct hci_dev *hdev = conn->hdev;
|
2022-08-16 16:41:20 +00:00
|
|
|
|
2023-06-27 00:25:06 +00:00
|
|
|
/* If abort_reason has already been set it means the connection is
|
|
|
|
* already being aborted so don't attempt to overwrite it.
|
|
|
|
*/
|
|
|
|
if (conn->abort_reason)
|
|
|
|
return 0;
|
2022-08-16 16:41:20 +00:00
|
|
|
|
2023-06-27 00:25:06 +00:00
|
|
|
bt_dev_dbg(hdev, "handle 0x%2.2x reason 0x%2.2x", conn->handle, reason);
|
2022-08-16 16:41:20 +00:00
|
|
|
|
2023-06-27 00:25:06 +00:00
|
|
|
conn->abort_reason = reason;
|
2022-08-16 16:41:20 +00:00
|
|
|
|
2023-06-27 00:25:06 +00:00
|
|
|
/* If the connection is pending check the command opcode since that
|
|
|
|
* might be blocking on hci_cmd_sync_work while waiting its respective
|
|
|
|
* event so we need to hci_cmd_sync_cancel to cancel it.
|
2023-06-27 22:55:47 +00:00
|
|
|
*
|
|
|
|
* hci_connect_le serializes the connection attempts so only one
|
|
|
|
* connection can be in BT_CONNECT at time.
|
2023-06-27 00:25:06 +00:00
|
|
|
*/
|
|
|
|
if (conn->state == BT_CONNECT && hdev->req_status == HCI_REQ_PEND) {
|
|
|
|
switch (hci_skb_event(hdev->sent_cmd)) {
|
2024-02-09 14:08:06 +00:00
|
|
|
case HCI_EV_CONN_COMPLETE:
|
2023-06-27 00:25:06 +00:00
|
|
|
case HCI_EV_LE_CONN_COMPLETE:
|
|
|
|
case HCI_EV_LE_ENHANCED_CONN_COMPLETE:
|
|
|
|
case HCI_EVT_LE_CIS_ESTABLISHED:
|
2024-02-16 21:20:11 +00:00
|
|
|
hci_cmd_sync_cancel(hdev, ECANCELED);
|
2023-06-27 00:25:06 +00:00
|
|
|
break;
|
2022-08-16 16:41:20 +00:00
|
|
|
}
|
2024-02-13 14:59:32 +00:00
|
|
|
/* Cancel connect attempt if still queued/pending */
|
|
|
|
} else if (!hci_cancel_connect_sync(hdev, conn)) {
|
|
|
|
return 0;
|
2022-08-16 16:41:20 +00:00
|
|
|
}
|
|
|
|
|
2024-08-26 20:14:04 +00:00
|
|
|
/* Run immediately if on cmd_sync_work since this may be called
|
|
|
|
* as a result to MGMT_OP_DISCONNECT/MGMT_OP_UNPAIR which does
|
|
|
|
* already queue its callback on cmd_sync_work.
|
|
|
|
*/
|
|
|
|
return hci_cmd_sync_run_once(hdev, abort_conn_sync, conn, NULL);
|
2022-08-16 16:41:20 +00:00
|
|
|
}
|