btmgmt_packet/event.rs
1//! mgmt API events.
2use getset::Getters;
3
4use btmgmt_packet_helper::events;
5
6use super::*;
7pub use imp::*;
8
9/// Management API Events
10#[events(name = Event, codes = EventCode)]
11mod imp {
12 use super::*;
13
14 /// Command Complete Event
15 ///
16 /// see [bluez
17 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
18 #[derive(Debug, Clone, Unpack, Getters)]
19 #[event(0x0001)]
20 #[getset(get = "pub")]
21 pub struct CommandComplete {
22 opcode: crate::command::CommandCode,
23 status: ErrorCode,
24 data: Box<[u8]>,
25 }
26
27 /// Command Status Event
28 ///
29 /// see [bluez
30 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
31 #[derive(Debug, Clone, Unpack, Getters)]
32 #[event(0x0002)]
33 #[getset(get = "pub")]
34 pub struct CommandStatus {
35 pub opcode: crate::command::CommandCode,
36 pub status: ErrorCode,
37 }
38
39 /// Controller Error Event
40 ///
41 /// see [bluez
42 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
43 #[derive(Debug, Clone, Unpack, Newtype)]
44 #[event(0x0003)]
45 pub struct ControllerError(ErrorCode);
46
47 /// Index Added Event
48 ///
49 /// see [bluez
50 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
51 #[derive(Debug, Clone, Unpack)]
52 #[event(0x0004)]
53 pub struct IndexAdded;
54
55 /// Index Removed Event
56 ///
57 /// see [bluez
58 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
59 #[derive(Debug, Clone, Unpack)]
60 #[event(0x0005)]
61 pub struct IndexRemoved;
62
63 /// New Settings Event
64 ///
65 /// see [bluez
66 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
67 #[derive(Debug, Clone, Unpack, Newtype)]
68 #[event(0x0006)]
69 pub struct NewSettings(super::Settings);
70
71 /// Class Of Device Changed Event
72 ///
73 /// see [bluez
74 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
75 #[derive(Debug, Clone, Unpack, Newtype)]
76 #[event(0x0007)]
77 pub struct ClassOfDeviceChanged(super::ClassOfDevice);
78
79 /// Local Name Changed Event
80 ///
81 /// see [bluez
82 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
83 #[derive(Debug, Clone, Unpack, Getters)]
84 #[event(0x0008)]
85 #[getset(get = "pub")]
86 pub struct LocalNameChanged {
87 name: super::Name,
88 short_name: super::ShortName,
89 }
90
91 /// New Link Key Event
92 ///
93 /// see [bluez
94 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
95 #[derive(Debug, Clone, Unpack, Getters)]
96 #[event(0x0009)]
97 #[getset(get = "pub")]
98 pub struct NewLinkKey {
99 store_hint: bool,
100 key: super::LinkKey,
101 }
102
103 /// New Long Term Key Event
104 ///
105 /// see [bluez
106 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
107 #[derive(Debug, Clone, Unpack, Getters)]
108 #[event(0x000A)]
109 #[getset(get = "pub")]
110 pub struct NewLongTermKey {
111 store_hint: bool,
112 key: super::LongTermKey,
113 }
114
115 /// Device Connected Event
116 ///
117 /// see [bluez
118 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
119 #[derive(Debug, Clone, Unpack, Getters)]
120 #[event(0x000B)]
121 #[getset(get = "pub")]
122 pub struct DeviceConnected {
123 address: super::Address,
124 address_type: super::AddressType,
125 flags: super::DeviceConnectFlags,
126 eir_data: super::VariableLengthBytes,
127 }
128
129 /// Device Disconnected Event
130 ///
131 /// see [bluez
132 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
133 #[derive(Debug, Clone, Unpack, Getters)]
134 #[event(0x000C)]
135 #[getset(get = "pub")]
136 pub struct DeviceDisconnect {
137 address: super::Address,
138 address_type: super::AddressType,
139 reason: super::DeviceDisconnectReason,
140 }
141
142 /// Connect Failed Event
143 ///
144 /// see [bluez
145 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
146 #[derive(Debug, Clone, Unpack, Getters)]
147 #[event(0x000D)]
148 #[getset(get = "pub")]
149 pub struct ConnectFailed {
150 address: super::Address,
151 address_type: super::AddressType,
152 status: super::ErrorCode,
153 }
154
155 /// PIN Code Request Event
156 ///
157 /// see [bluez
158 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
159 #[derive(Debug, Clone, Unpack, Getters)]
160 #[event(0x000E)]
161 #[getset(get = "pub")]
162 pub struct PinCodeRequest {
163 address: super::Address,
164 address_type: super::AddressType,
165 secure: bool,
166 }
167
168 /// User Confirmation Request Event
169 ///
170 /// see [bluez
171 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
172 #[derive(Debug, Clone, Unpack, Getters)]
173 #[event(0x000F)]
174 #[getset(get = "pub")]
175 pub struct UserConfirmationRequest {
176 address: super::Address,
177 address_type: super::AddressType,
178 confirm_hint: super::ConfirmHint,
179 value: [u8; 4],
180 }
181
182 /// User Passkey Request Event
183 ///
184 /// see [bluez
185 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
186 #[derive(Debug, Clone, Unpack, Getters)]
187 #[event(0x0010)]
188 #[getset(get = "pub")]
189 pub struct UserPasskeyRequest {
190 address: super::Address,
191 address_type: super::AddressType,
192 }
193
194 /// Authentication Failed Event
195 ///
196 /// see [bluez
197 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
198 #[derive(Debug, Clone, Unpack, Getters)]
199 #[event(0x0011)]
200 #[getset(get = "pub")]
201 pub struct AuthenticationFailed {
202 address: super::Address,
203 address_type: super::AddressType,
204 status: super::ErrorCode,
205 }
206
207 /// Device Found Event
208 ///
209 /// see [bluez
210 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
211 #[derive(Debug, Clone, Unpack, Getters)]
212 #[event(0x0012)]
213 #[getset(get = "pub")]
214 pub struct DeviceFound {
215 address: super::Address,
216 address_type: super::AddressType,
217 rssi: u8,
218 flags: super::DeviceConnectFlags,
219 eir_data: super::VariableLengthBytes,
220 }
221
222 /// Discovering Event
223 ///
224 /// see [bluez
225 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
226 #[derive(Debug, Clone, Unpack, Getters)]
227 #[event(0x0013)]
228 #[getset(get = "pub")]
229 pub struct Discovering {
230 address_type: super::AddressTypes,
231 discovering: bool,
232 }
233
234 /// Device Blocked Event
235 ///
236 /// see [bluez
237 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
238 #[derive(Debug, Clone, Unpack, Getters)]
239 #[event(0x0014)]
240 #[getset(get = "pub")]
241 pub struct DeviceBlocked {
242 address: super::Address,
243 address_type: super::AddressType,
244 }
245
246 /// Device Unblocked Event
247 ///
248 /// see [bluez
249 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
250 #[derive(Debug, Clone, Unpack, Getters)]
251 #[event(0x0015)]
252 #[getset(get = "pub")]
253 pub struct DeviceUnblocked {
254 address: super::Address,
255 address_type: super::AddressType,
256 }
257
258 /// Device Unpaired Event
259 ///
260 /// see [bluez
261 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
262 #[derive(Debug, Clone, Unpack, Getters)]
263 #[event(0x0016)]
264 #[getset(get = "pub")]
265 pub struct DeviceUnpaired {
266 address: super::Address,
267 address_type: super::AddressType,
268 }
269
270 /// Passkey Notify Event
271 ///
272 /// see [bluez
273 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
274 #[derive(Debug, Clone, Unpack, Getters)]
275 #[event(0x0017)]
276 #[getset(get = "pub")]
277 pub struct PasskeyNotify {
278 address: super::Address,
279 address_type: super::AddressType,
280 passkey: u32,
281 entered: u8,
282 }
283
284 /// New Identity Resolving Key Event
285 ///
286 /// see [bluez
287 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
288 #[derive(Debug, Clone, Unpack, Getters)]
289 #[event(0x0018)]
290 #[getset(get = "pub")]
291 pub struct NewIdentityResolvingKey {
292 store_hint: bool,
293 random_address: super::Address,
294 key: super::IdentityResolvingKey,
295 }
296
297 /// New Signature Resolving Key Event
298 ///
299 /// see [bluez
300 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
301 #[derive(Debug, Clone, Unpack, Getters)]
302 #[event(0x0019)]
303 #[getset(get = "pub")]
304 pub struct NewSignatureResolvingKey {
305 store_hint: bool,
306 key: super::SignatureResolvingKey,
307 }
308
309 /// Device Added Event
310 ///
311 /// see [bluez
312 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
313 #[derive(Debug, Clone, Unpack, Getters)]
314 #[event(0x001A)]
315 #[getset(get = "pub")]
316 pub struct DeviceAdded {
317 address: super::Address,
318 address_type: super::AddressType,
319 action: super::Action,
320 }
321
322 /// Device Removed Event
323 ///
324 /// see [bluez
325 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
326 #[derive(Debug, Clone, Unpack, Getters)]
327 #[event(0x001B)]
328 #[getset(get = "pub")]
329 pub struct DeviceRemoved {
330 address: super::Address,
331 address_type: super::AddressType,
332 }
333
334 /// New Connection Parameter Event
335 ///
336 /// see [bluez
337 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
338 #[derive(Debug, Clone, Unpack, Getters)]
339 #[event(0x001C)]
340 #[getset(get = "pub")]
341 pub struct NewConnectionParameter {
342 address: super::Address,
343 address_type: super::AddressType,
344 min_connection_interval: u16,
345 max_connection_interval: u16,
346 connection_latency: u16,
347 supervision_timeout: u16,
348 }
349
350 /// Unconfigured Index Added Event
351 ///
352 /// see [bluez
353 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
354 #[derive(Debug, Clone, Unpack)]
355 #[event(0x001D)]
356 pub struct UnconfiguredIndexAdded;
357
358 /// Unconfigured Index Removed Event
359 ///
360 /// see [bluez
361 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
362 #[derive(Debug, Clone, Unpack)]
363 #[event(0x001E)]
364 pub struct UnconfiguredIndexRemoved;
365
366 /// New Configuration Options Event
367 ///
368 /// see [bluez
369 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
370 #[derive(Debug, Clone, Unpack, Newtype)]
371 #[event(0x001F)]
372 pub struct NewConfigurationOptions(super::ControllerConfigurationOption);
373
374 /// Extended Index Added Event
375 ///
376 /// see [bluez
377 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
378 #[derive(Debug, Clone, Unpack, Getters)]
379 #[event(0x0020)]
380 #[getset(get = "pub")]
381 pub struct ExtendedIndexAdded {
382 controller_type: super::ControllerType,
383 controller_bus: super::ControllerBus,
384 }
385
386 /// Extended Index Removed Event
387 ///
388 /// see [bluez
389 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
390 #[derive(Debug, Clone, Unpack, Getters)]
391 #[event(0x0021)]
392 #[getset(get = "pub")]
393 pub struct ExtendedIndexRemoved {
394 controller_type: super::ControllerType,
395 controller_bus: super::ControllerBus,
396 }
397
398 /// Local Out Of Band Extended Data Updated Event
399 ///
400 /// see [bluez
401 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
402 #[derive(Debug, Clone, Unpack, Getters)]
403 #[event(0x0022)]
404 #[getset(get = "pub")]
405 pub struct LocalOutOfBandExtendedDataUpdate {
406 address_type: super::AddressTypes,
407 eir_data: super::VariableLengthBytes,
408 }
409
410 /// Advertising Added Event
411 ///
412 /// see [bluez
413 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
414 #[derive(Debug, Clone, Unpack, Newtype)]
415 #[event(0x0023)]
416 pub struct AdvertisingAdded(super::AdvertiseInstance);
417
418 /// Advertising Removed Event
419 ///
420 /// see [bluez
421 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
422 #[derive(Debug, Clone, Unpack, Newtype)]
423 #[event(0x0024)]
424 pub struct AdvertisingRemoved(super::AdvertiseInstance);
425
426 /// Extended Controller Information Changed Event
427 ///
428 /// see [bluez
429 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
430 #[derive(Debug, Clone, Unpack, Newtype)]
431 #[event(0x0025)]
432 pub struct ExtendedControllerInformationChanged(super::VariableLengthBytes);
433
434 /// PHY Configuration Changed Event
435 ///
436 /// see [bluez
437 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
438 #[derive(Debug, Clone, Unpack, Newtype)]
439 #[event(0x0026)]
440 pub struct PhyConfigurationChanged(super::Phys);
441
442 /// Experimental Feature Changed Event
443 ///
444 /// see [bluez
445 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
446 #[derive(Debug, Clone, Unpack, Getters)]
447 #[event(0x0027)]
448 #[getset(get = "pub")]
449 pub struct ExperimentalFeatureChanged {
450 uuid: super::Uuid,
451 flags: super::FeatureFlags,
452 }
453
454 /// Default System Configuration Changed Event
455 ///
456 /// see [bluez
457 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
458 #[derive(Debug, Clone, Unpack, IterNewtype)]
459 #[event(0x0028)]
460 pub struct DefaultSystemConfigurationChanged(
461 super::Remaining<super::SystemConfigurationParameter>,
462 );
463
464 /// Default Runtime Configuration Changed Event
465 ///
466 /// see [bluez
467 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
468 #[derive(Debug, Clone, Unpack, IterNewtype)]
469 #[event(0x0029)]
470 pub struct DefaultRuntimeConfigurationChanged(
471 super::Remaining<super::RuntimeConfigurationParameter>,
472 );
473
474 /// Device Flags Changed Event
475 ///
476 /// see [bluez
477 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
478 #[derive(Debug, Clone, Unpack, Getters)]
479 #[event(0x002A)]
480 #[getset(get = "pub")]
481 pub struct DeviceFlagsChanged {
482 address: super::Address,
483 address_type: super::AddressType,
484 supported_flags: super::DeviceFlags,
485 current_flags: super::DeviceFlags,
486 }
487
488 /// Advertisement Monitor Added Event
489 ///
490 /// see [bluez
491 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
492 #[derive(Debug, Clone, Unpack, Newtype)]
493 #[event(0x002B)]
494 pub struct AdvertisementMonitorAdded(super::AdvertisementMonitorHandle);
495
496 /// Advertisement Monitor Removed Event
497 ///
498 /// see [bluez
499 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
500 #[derive(Debug, Clone, Unpack, Newtype)]
501 #[event(0x002C)]
502 pub struct AdvertisementMonitorRemoved(super::AdvertisementMonitorHandle);
503
504 /// Controller Suspend Event
505 ///
506 /// see [bluez
507 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
508 #[derive(Debug, Clone, Unpack, Newtype)]
509 #[event(0x002D)]
510 pub struct ControllerSuspend(super::SuspendState);
511
512 /// Controller Resume Event
513 ///
514 /// see [bluez
515 /// docs/mgmt-api.txt](https://git.kernel.org/pub/scm/bluetooth/bluez.git/plain/doc/mgmt-api.txt)
516 #[derive(Debug, Clone, Unpack, Getters)]
517 #[event(0x002E)]
518 #[getset(get = "pub")]
519 pub struct ControllerResume {
520 wake_reason: super::WakeReason,
521 address: super::Address,
522 address_type: super::AddressType,
523 }
524}
525
526#[doc(hidden)]
527pub fn unpack_events<R>(read: &mut R) -> pack::Result<(ControllerIndex, Event)>
528where
529 R: io::Read,
530{
531 let code = EventCode::unpack(read)?;
532 let index = ControllerIndex::unpack(read)?;
533
534 let data = <Vec<u8>>::unpack(read)?;
535 let events = Event::unpack_inner(code, &mut &data[..])?;
536
537 Ok((index, events))
538}