1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
.Dd November 19, 2026
.Dt HCI-BIND 1
.Os
.Sh NAME
.Nm hci-bind
.Nd hand a Bluetooth adapter to an unprivileged program
.Sh SYNOPSIS
.Nm
.Ar index uid gid program
.Op Ar argument ...
.Sh DESCRIPTION
.Nm
binds the HCI user channel of
.Li hci Ns Ar index ,
which takes the adapter away from the kernel's Bluetooth stack, then drops
to
.Ar uid
and
.Ar gid
with no capabilities and
.Li no_new_privs ,
and with no supplementary groups but those in
.Ev HCI_BIND_GROUPS ,
and executes
.Ar program
with the bound socket open and its number in
.Ev FLOSS_HCI_FD .
.Pp
It is the only part of the stack that runs as root, and it is gone before
the stack starts: btadapterd, patched to take its socket from
.Ev FLOSS_HCI_FD
.Pq Pa patches/0001-hal-inherit-hci-fd.patch ,
then drives the adapter with no privileges at all, which the kernel allows
because it checks them in
.Fn bind
only; see
.Xr hci-probe 1 .
.Pp
While the adapter is held up by someone else
.Pq Er EBUSY ,
for instance by a bluetoothd that is still stopping,
.Nm
retries for five seconds.
.Sh ENVIRONMENT
.Bl -tag -width HCI_BIND_GROUPS
.It Ev HCI_BIND_GROUPS
a comma-separated list of numeric group ids
.Ar program
keeps as supplementary groups, at most 16, none of them 0.
For Floss these are the groups that own
.Pa /dev/uhid
and
.Pa /dev/uinput .
A service manager's
.Cm SupplementaryGroups=
cannot do this: they would apply to
.Nm
too, and are replaced when it drops to
.Ar uid .
Removed from the environment before
.Ar program
runs.
.It Ev FLOSS_HCI_FD
set for
.Ar program
to the number of the bound socket.
.El
.Sh EXIT STATUS
Does not return if
.Ar program
was executed; otherwise 1 on failure and 2 on wrong arguments, including a
.Ar uid
or
.Ar gid
of 0.
.Sh SEE ALSO
.Xr hci-probe 1 ,
.Xr chromium-floss 7
|