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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
//! The controllers themselves.
//!
//! Web Bluetooth has no concept of choosing a radio: a browser has one
//! Bluetooth, and `navigator.bluetooth` is it. That is the right model for a
//! web page and the wrong one for a machine with two dongles, a test rig
//! driving both ends of a link, or a Raspberry Pi whose built-in controller is
//! worse than the USB one next to it.
//!
//! So this sits alongside the standard rather than inside it. The default is
//! unchanged — `Bluetooth::new` takes whichever controller the
//! platform considers first — and nothing here has to be called to use the
//! rest of the crate.
//!
//! What a platform can say about its radios varies more than most things in
//! this crate, and the honest answer is sometimes "there is one and I cannot
//! describe it":
//!
//! | platform | enumerate | select | address |
//! |---|---|---|---|
//! | BlueZ | yes | yes | yes |
//! | `linux-hci` | yes | yes | yes |
//! | Windows | yes | yes | yes |
//! | CoreBluetooth | one | no | no |
//! | Android | one | no | redacted |
//!
//! CoreBluetooth exposes no controller identity at all — a `CBCentralManager`
//! is the radio, and there is no API to ask which one or to pick another.
//! Android has `getDefaultAdapter()` and no way to enumerate; since Android 6
//! `getAddress()` returns a fixed `02:00:00:00:00:00` to every caller that is
//! not the system, so reporting it would be reporting a placeholder.
//!
//! Rather than pretend, those platforms report exactly one adapter and
//! `Bluetooth::select_adapter` refuses anything else by name.
/// One Bluetooth controller.
///
/// Obtained from `Bluetooth::adapters`. The [`id`](Self::id) is what
/// `Bluetooth::select_adapter` takes, and is whatever the platform
/// uses to name a radio: `hci0` on Linux, a device interface path on Windows.
/// What a link actually negotiated.
///
/// The counterpart to `Bluetooth`'s connection *priority*: priority
/// asks for a profile, this reports what came back. Not part of Web
/// Bluetooth, which has neither.
///
/// The units are the Bluetooth ones rather than milliseconds, because that is
/// what the controller reports and converting would lose precision: the
/// interval is in 1.25 ms steps and the timeout in 10 ms steps.
/// What `BluetoothDevice::pair` did.
///
/// Three outcomes rather than a bare `Result<()>`, because "nothing happened"
/// is a real answer here and it is not a failure: Apple pairs when an
/// encrypted attribute is touched and offers no way to ask for it in advance.
/// Collapsing that into `Ok(())` would tell a caller a bond exists when it
/// does not, and into an error would send them looking for a problem that is
/// not there.
/// A physical layer an LE link can run at.
///
/// Not part of Web Bluetooth, which has no notion of one. It is here because
/// it is the largest single throughput lever available on a connection: 2M
/// doubles the symbol rate, which roughly doubles what fits in a connection
/// event. Coded trades the other way, buying range at a quarter or an eighth
/// of the rate.
/// What a link is actually running at, in each direction.
///
/// The two can differ: a sensor that sends a great deal and receives almost
/// nothing has no reason to run both ways at the same rate.
/// The single adapter a platform that cannot enumerate reports.
///
/// Named rather than empty so that `Bluetooth::adapters` has the same
/// shape everywhere: one entry, selectable by this id, and refusing any other.
pub const DEFAULT_ADAPTER: &str = "default";
/// Whether `address` is the placeholder Android hands out instead of the real
/// controller address.
///
/// Since Android 6 `BluetoothAdapter.getAddress()` returns a constant to any
/// app without `LOCAL_MAC_ADDRESS_PERMISSION`, which is a system permission.
/// Every device returns the same one, so passing it through would be worse
/// than saying nothing.
/// How aggressively to maintain a connection.
///
/// **Not part of Web Bluetooth**, and a hint rather than an instruction: the
/// peripheral has the final say on the connection interval, and only some
/// platforms can even ask. See
/// `BluetoothDevice::request_connection_priority`.