stm32wb_hci/event/
command.rs

1//! Return parameters for HCI commands.
2//!
3//! This module defines the return parameters that can be returned in a
4//! [Command Complete](super::Event::CommandComplete) event for every HCI command.
5//!
6//! For the Command Complete event, see the Bluetooth specification, v4.1 or later, Vol 2, Part E,
7//! Section 7.7.14.
8//!
9//! For the return parameters of the commands, see the description of each command in sections 7.1 -
10//! 7.6 of the same part of the spec.
11
12use crate::vendor::opcode::VENDOR_OGF;
13use crate::{ConnectionHandle, Status};
14use byteorder::{ByteOrder, LittleEndian};
15use core::convert::{TryFrom, TryInto};
16use core::fmt::{Debug, Formatter, Result as FmtResult};
17use core::mem;
18
19/// The [Command Complete](super::Event::CommandComplete) event is used by the Controller for most
20/// commands to transmit return status of a command and the other event parameters that are
21/// specified for the issued HCI command.
22///
23/// Must be specialized on the return parameters that may be returned by vendor-specific commands.
24///
25/// Defined in the Bluetooth spec, Vol 2, Part E, Section 7.7.14.
26#[derive(Clone, Debug)]
27#[cfg_attr(feature = "defmt", derive(defmt::Format))]
28pub struct CommandComplete {
29    /// Indicates the number of HCI command packets the Host can send to the Controller. If the
30    /// Controller requires the Host to stop sending commands, `num_hci_command_packets` will be set
31    /// to zero.  To indicate to the Host that the Controller is ready to receive HCI command
32    /// packets, the Controller generates a Command Complete event with `return_params` set to
33    /// [`Spontaneous`](ReturnParameters::Spontaneous) and `num_hci_command_packets` parameter set
34    /// to 1 or more.  [`Spontaneous`](ReturnParameters::Spontaneous) return parameters indicates
35    /// that this event is not associated with a command sent by the Host. The Controller can send a
36    /// Spontaneous Command Complete event at any time to change the number of outstanding HCI
37    /// command packets that the Host can send before waiting.
38    pub num_hci_command_packets: u8,
39
40    /// The type of command that has completed, and any parameters that it returns.
41    pub return_params: ReturnParameters,
42}
43
44impl CommandComplete {
45    /// Deserializes a buffer into a CommandComplete event.
46    ///
47    /// # Errors
48    ///
49    /// - [`BadLength`](crate::event::Error::BadLength) if the buffer is not large enough to contain
50    ///   a parameter length (1 byte) and opcode (2 bytes)
51    /// - Returns errors that may be generated when deserializing specific events. This may be
52    ///   [`BadLength`](crate::event::Error::BadLength), which indicates the buffer was not large
53    ///   enough to contain all of the required data for the event. Some commands define other
54    ///   errors that indicate parameter values are invalid. The error type must be specialized on
55    ///   potential vendor-specific errors, though vendor-specific errors are never returned by this
56    ///   function.
57    pub fn new(bytes: &[u8]) -> Result<CommandComplete, crate::event::Error> {
58        require_len_at_least!(bytes, 3);
59
60        let params = match crate::opcode::Opcode(LittleEndian::read_u16(&bytes[1..])) {
61            crate::opcode::Opcode(0x0000) => ReturnParameters::Spontaneous,
62            crate::opcode::SET_EVENT_MASK => {
63                ReturnParameters::SetEventMask(to_status(&bytes[3..])?)
64            }
65            crate::opcode::RESET => ReturnParameters::Reset(to_status(&bytes[3..])?),
66            crate::opcode::READ_TX_POWER_LEVEL => {
67                ReturnParameters::ReadTxPowerLevel(to_tx_power_level(&bytes[3..])?)
68            }
69            crate::opcode::READ_LOCAL_VERSION_INFO => {
70                ReturnParameters::ReadLocalVersionInformation(to_local_version_info(&bytes[3..])?)
71            }
72            crate::opcode::READ_LOCAL_SUPPORTED_COMMANDS => {
73                ReturnParameters::ReadLocalSupportedCommands(to_supported_commands(&bytes[3..])?)
74            }
75            crate::opcode::READ_LOCAL_SUPPORTED_FEATURES => {
76                ReturnParameters::ReadLocalSupportedFeatures(to_supported_features(&bytes[3..])?)
77            }
78            crate::opcode::READ_BD_ADDR => ReturnParameters::ReadBdAddr(to_bd_addr(&bytes[3..])?),
79            crate::opcode::READ_RSSI => ReturnParameters::ReadRssi(to_read_rssi(&bytes[3..])?),
80            crate::opcode::LE_SET_EVENT_MASK => {
81                ReturnParameters::LeSetEventMask(to_status(&bytes[3..])?)
82            }
83            crate::opcode::LE_READ_BUFFER_SIZE => {
84                ReturnParameters::LeReadBufferSize(to_le_read_buffer_status(&bytes[3..])?)
85            }
86            crate::opcode::LE_READ_LOCAL_SUPPORTED_FEATURES => {
87                ReturnParameters::LeReadLocalSupportedFeatures(to_le_local_supported_features(
88                    &bytes[3..],
89                )?)
90            }
91            crate::opcode::LE_SET_RANDOM_ADDRESS => {
92                ReturnParameters::LeSetRandomAddress(to_status(&bytes[3..])?)
93            }
94            crate::opcode::LE_SET_ADVERTISING_PARAMETERS => {
95                ReturnParameters::LeSetAdvertisingParameters(to_status(&bytes[3..])?)
96            }
97            crate::opcode::LE_READ_ADVERTISING_CHANNEL_TX_POWER => {
98                ReturnParameters::LeReadAdvertisingChannelTxPower(
99                    to_le_advertising_channel_tx_power(&bytes[3..])?,
100                )
101            }
102            crate::opcode::LE_SET_ADVERTISING_DATA => {
103                ReturnParameters::LeSetAdvertisingData(to_status(&bytes[3..])?)
104            }
105            crate::opcode::LE_SET_SCAN_RESPONSE_DATA => {
106                ReturnParameters::LeSetScanResponseData(to_status(&bytes[3..])?)
107            }
108            crate::opcode::LE_SET_ADVERTISE_ENABLE => {
109                to_le_set_advertise_enable(to_status(&bytes[3..])?)
110            }
111            crate::opcode::LE_SET_SCAN_PARAMETERS => {
112                ReturnParameters::LeSetScanParameters(to_status(&bytes[3..])?)
113            }
114            crate::opcode::LE_SET_SCAN_ENABLE => {
115                ReturnParameters::LeSetScanEnable(to_status(&bytes[3..])?)
116            }
117            crate::opcode::LE_CREATE_CONNECTION_CANCEL => {
118                ReturnParameters::LeCreateConnectionCancel(to_status(&bytes[3..])?)
119            }
120            crate::opcode::LE_READ_WHITE_LIST_SIZE => {
121                ReturnParameters::LeReadWhiteListSize(to_status(&bytes[3..])?, bytes[4] as usize)
122            }
123            crate::opcode::LE_CLEAR_WHITE_LIST => {
124                ReturnParameters::LeClearWhiteList(to_status(&bytes[3..])?)
125            }
126            crate::opcode::LE_ADD_DEVICE_TO_WHITE_LIST => {
127                ReturnParameters::LeAddDeviceToWhiteList(to_status(&bytes[3..])?)
128            }
129            crate::opcode::LE_REMOVE_DEVICE_FROM_WHITE_LIST => {
130                ReturnParameters::LeRemoveDeviceFromWhiteList(to_status(&bytes[3..])?)
131            }
132            crate::opcode::LE_SET_HOST_CHANNEL_CLASSIFICATION => {
133                ReturnParameters::LeSetHostChannelClassification(to_status(&bytes[3..])?)
134            }
135            crate::opcode::LE_READ_CHANNEL_MAP => {
136                ReturnParameters::LeReadChannelMap(to_le_channel_map_parameters(&bytes[3..])?)
137            }
138            crate::opcode::LE_ENCRYPT => {
139                ReturnParameters::LeEncrypt(to_le_encrypted_data(&bytes[3..])?)
140            }
141            crate::opcode::LE_RAND => ReturnParameters::LeRand(to_random_number(&bytes[3..])?),
142            crate::opcode::LE_LTK_REQUEST_REPLY => {
143                ReturnParameters::LeLongTermKeyRequestReply(to_le_ltk_request_reply(&bytes[3..])?)
144            }
145            crate::opcode::LE_LTK_REQUEST_NEGATIVE_REPLY => {
146                ReturnParameters::LeLongTermKeyRequestNegativeReply(to_le_ltk_request_reply(
147                    &bytes[3..],
148                )?)
149            }
150            crate::opcode::LE_READ_STATES => {
151                ReturnParameters::LeReadSupportedStates(to_le_read_states(&bytes[3..])?)
152            }
153            crate::opcode::LE_RECEIVER_TEST => {
154                ReturnParameters::LeReceiverTest(to_status(&bytes[3..])?)
155            }
156            crate::opcode::LE_TRANSMITTER_TEST => {
157                ReturnParameters::LeTransmitterTest(to_status(&bytes[3..])?)
158            }
159            crate::opcode::LE_TEST_END => ReturnParameters::LeTestEnd(to_le_test_end(&bytes[3..])?),
160            other => {
161                if other.ogf() != VENDOR_OGF {
162                    return Err(crate::event::Error::UnknownOpcode(other));
163                }
164
165                ReturnParameters::Vendor(
166                    crate::vendor::event::command::VendorReturnParameters::new(bytes)?,
167                )
168            }
169        };
170        Ok(CommandComplete {
171            num_hci_command_packets: bytes[0],
172            return_params: params,
173        })
174    }
175}
176
177/// Commands that may generate the [Command Complete](crate::event::Event::CommandComplete) event.
178/// If the commands have defined return parameters, they are included in this enum.
179#[derive(Clone, Debug)]
180#[cfg_attr(feature = "defmt", derive(defmt::Format))]
181#[allow(clippy::large_enum_variant)]
182pub enum ReturnParameters {
183    /// The controller sent an unsolicited command complete event in order to change the number of
184    /// HCI command packets the Host is allowed to send.
185    Spontaneous,
186
187    /// Status returned by the [Set Event Mask](crate::host::HostHci::set_event_mask) command.
188    SetEventMask(Status),
189
190    /// Status returned by the [Reset](crate::host::HostHci::reset) command.
191    Reset(Status),
192
193    /// [Read Transmit Power Level](crate::host::HostHci::read_tx_power_level) return parameters.
194    ReadTxPowerLevel(TxPowerLevel),
195
196    /// Local version info returned by the
197    /// [Read Local Version Information](crate::host::HostHci::read_local_version_information) command.
198    ReadLocalVersionInformation(LocalVersionInfo),
199
200    /// Supported commands returned by the
201    /// [Read Local Supported Commands](crate::host::HostHci::read_local_supported_commands) command.
202    ReadLocalSupportedCommands(LocalSupportedCommands),
203
204    /// Supported features returned by the
205    /// [Read Local Supported Features](crate::host::HostHci::read_local_supported_features) command.
206    ReadLocalSupportedFeatures(LocalSupportedFeatures),
207
208    /// BD ADDR returned by the [Read BD ADDR](crate::host::HostHci::read_bd_addr) command.
209    ReadBdAddr(ReadBdAddr),
210
211    /// RSSI returned by the [Read RSSI](crate::host::HostHci::read_rssi) command.
212    ReadRssi(ReadRssi),
213
214    /// Status returned by the [LE Set Event Mask](crate::host::HostHci::le_set_event_mask) command.
215    LeSetEventMask(Status),
216
217    /// Parameters returned by the [LE Read Buffer Size](crate::host::HostHci::le_read_buffer_size)
218    /// command.
219    LeReadBufferSize(LeReadBufferSize),
220
221    /// Parameters returned by the
222    /// [LE Read Local Supported Features](crate::host::HostHci::le_read_local_supported_features) command.
223    LeReadLocalSupportedFeatures(LeSupportedFeatures),
224
225    /// Status returned by the [LE Set Random Address](crate::host::HostHci::le_set_random_address)
226    /// command.
227    LeSetRandomAddress(Status),
228
229    /// Status returned by the
230    /// [LE Set Advertising Parameters](crate::host::HostHci::le_set_advertising_parameters) command.
231    LeSetAdvertisingParameters(Status),
232
233    /// Parameters returned by the
234    /// [LE Read Advertising Channel TX Power](crate::host::HostHci::le_read_advertising_channel_tx_power) command.
235    LeReadAdvertisingChannelTxPower(LeAdvertisingChannelTxPower),
236
237    /// Status returned by the [LE Set Advertising Data](crate::host::HostHci::le_set_advertising_data)
238    /// command.
239    LeSetAdvertisingData(Status),
240
241    /// Status returned by the
242    /// [LE Set Scan Response Data](crate::host::HostHci::le_set_scan_response_data) command.
243    LeSetScanResponseData(Status),
244
245    /// Status returned by the
246    /// [LE Set Advertising Enable](crate::host::HostHci::le_set_advertising_enable) command.
247    LeSetAdvertisingEnable(Status),
248
249    /// Status returned by the [LE Set Scan Parameters](crate::host::HostHci::le_set_scan_parameters)
250    /// command.
251    LeSetScanParameters(Status),
252
253    /// Status returned by the [LE Set Scan Enable](crate::host::HostHci::le_set_scan_enable) command.
254    LeSetScanEnable(Status),
255
256    /// Status returned by the
257    /// [LE Create Connection Cancel](crate::host::HostHci::le_create_connection_cancel) command.
258    LeCreateConnectionCancel(Status),
259
260    /// Status and white list size returned by the
261    /// [LE Read White List Size](crate::host::HostHci::le_read_white_list_size) command.
262    LeReadWhiteListSize(Status, usize),
263
264    /// Status returned by the [LE Clear White List](crate::host::HostHci::le_clear_white_list) command.
265    LeClearWhiteList(Status),
266
267    /// Status returned by the
268    /// [LE Add Device to White List](crate::host::HostHci::le_add_device_to_white_list) command.
269    LeAddDeviceToWhiteList(Status),
270
271    /// Status returned by the
272    /// [LE Remove Device from White List](crate::host::HostHci::le_remove_device_from_white_list) command.
273    LeRemoveDeviceFromWhiteList(Status),
274
275    /// Status returned by the
276    /// [LE Set Host Channel Classification](crate::host::HostHci::le_set_host_channel_classification) command.
277    LeSetHostChannelClassification(Status),
278
279    /// Parameters returned by the [LE Read Channel Map](crate::host::HostHci::le_read_channel_map)
280    /// command.
281    LeReadChannelMap(ChannelMapParameters),
282
283    /// Parameters returned by the [LE Encrypt](crate::host::HostHci::le_encrypt) command.
284    LeEncrypt(EncryptedReturnParameters),
285
286    /// Parameters returned by the [LE Rand](crate::host::HostHci::le_rand) command.
287    LeRand(LeRandom),
288
289    /// Parameters returned by the
290    /// [LE Long Term Key Request Reply](crate::host::HostHci::le_long_term_key_request_reply) command.
291    LeLongTermKeyRequestReply(LeLongTermRequestReply),
292
293    /// Parameters returned by the
294    /// [LE Long Term Key Request Negative Reply](crate::host::HostHci::le_long_term_key_request_negative_reply) command.
295    LeLongTermKeyRequestNegativeReply(LeLongTermRequestReply),
296
297    /// Parameters returned by the [LE Read States](crate::host::HostHci::le_read_supported_states))
298    /// command.
299    LeReadSupportedStates(LeReadSupportedStates),
300
301    /// Status returned by the [LE Receiver Test](crate::host::HostHci::le_receiver_test) command.
302    LeReceiverTest(Status),
303
304    /// Status returned by the [LE Transmitter Test](crate::host::HostHci::le_transmitter_test) command.
305    LeTransmitterTest(Status),
306
307    /// Parameters returned by the [LE Test End](crate::host::HostHci::le_test_end) command.
308    LeTestEnd(LeTestEnd),
309
310    /// Parameters returned by vendor-specific commands.
311    Vendor(crate::vendor::event::command::VendorReturnParameters),
312}
313
314fn to_status(bytes: &[u8]) -> Result<Status, crate::event::Error> {
315    bytes[0].try_into().map_err(super::rewrap_bad_status)
316}
317
318/// Values returned by the [Read Transmit Power Level](crate::host::HostHci::read_tx_power_level)
319/// command.
320#[derive(Copy, Clone, Debug)]
321#[cfg_attr(feature = "defmt", derive(defmt::Format))]
322pub struct TxPowerLevel {
323    /// Did the command fail, and if so, how?
324    pub status: Status,
325
326    /// Specifies which connection handle's transmit power level setting is returned
327    pub conn_handle: ConnectionHandle,
328
329    /// Power level for the connection handle, in dBm.
330    ///
331    /// Valid range is -30 dBm to +20 dBm, but that is not enforced by this implementation.
332    pub tx_power_level_dbm: i8,
333}
334
335fn to_tx_power_level(bytes: &[u8]) -> Result<TxPowerLevel, crate::event::Error> {
336    require_len!(bytes, 4);
337    Ok(TxPowerLevel {
338        status: to_status(bytes)?,
339        conn_handle: ConnectionHandle(LittleEndian::read_u16(&bytes[1..])),
340        tx_power_level_dbm: unsafe { mem::transmute::<u8, i8>(bytes[3]) },
341    })
342}
343
344/// Values returned by
345/// [Read Local Version Information](crate::host::HostHci::read_local_version_information) command.
346#[derive(Copy, Clone, Debug)]
347#[cfg_attr(feature = "defmt", derive(defmt::Format))]
348pub struct LocalVersionInfo {
349    /// Did the command fail, and if so, how?
350    pub status: Status,
351
352    /// The version information of the HCI layer.
353    ///
354    /// See the Bluetooth
355    /// [Assigned Numbers](https://www.bluetooth.com/specifications/assigned-numbers/host-controller-interface).
356    pub hci_version: u8,
357
358    /// Revision of the Current HCI in the BR/EDR Controller.  This value is implementation
359    /// dependent.
360    pub hci_revision: u16,
361
362    /// Version of the Current [LMP] or [PAL] in the Controller.
363    ///
364    /// [LMP]: https://www.bluetooth.com/specifications/assigned-numbers/link-manager
365    /// [PAL]: https://www.bluetooth.com/specifications/assigned-numbers/protocol-adaptation-layer
366    pub lmp_version: u8,
367
368    /// Manufacturer Name of the BR/EDR Controller.  See Bluetooth
369    /// [Assigned Numbers](https://www.bluetooth.com/specifications/assigned-numbers/company-identifiers)
370    pub manufacturer_name: u16,
371
372    /// Subversion of the Current [LMP] or [PAL] in the Controller. This value is implementation
373    /// dependent.
374    ///
375    /// [LMP]: https://www.bluetooth.com/specifications/assigned-numbers/link-manager
376    /// [PAL]: https://www.bluetooth.com/specifications/assigned-numbers/protocol-adaptation-layer
377    pub lmp_subversion: u16,
378}
379
380fn to_local_version_info(bytes: &[u8]) -> Result<LocalVersionInfo, crate::event::Error> {
381    require_len!(bytes, 9);
382
383    Ok(LocalVersionInfo {
384        status: bytes[0].try_into().map_err(super::rewrap_bad_status)?,
385        hci_version: bytes[1],
386        hci_revision: LittleEndian::read_u16(&bytes[2..]),
387        lmp_version: bytes[4],
388        manufacturer_name: LittleEndian::read_u16(&bytes[5..]),
389        lmp_subversion: LittleEndian::read_u16(&bytes[7..]),
390    })
391}
392
393/// Values returned by the
394/// [Read Local Supported Commands](crate::host::HostHci::read_local_supported_commands) command.
395#[derive(Copy, Clone, Debug)]
396#[cfg_attr(feature = "defmt", derive(defmt::Format))]
397pub struct LocalSupportedCommands {
398    /// Did the command fail, and if so, how?
399    pub status: Status,
400
401    /// Flags for supported commands.
402    pub supported_commands: CommandFlags,
403}
404
405const COMMAND_FLAGS_SIZE: usize = 64;
406
407bitflag_array! {
408    /// Extended bit field for the command flags of the [`LocalSupportedCommands`] return
409    /// parameters.
410    #[derive(Copy, Clone)]
411    #[cfg_attr(feature = "defmt", derive(defmt::Format))]
412    pub struct CommandFlags : COMMAND_FLAGS_SIZE;
413    pub struct CommandFlag;
414
415    /// Inquiry
416    const INQUIRY = 0, 1 << 0;
417    /// Cancel Inquiry
418    const INQUIRY_CANCEL = 0, 1 << 1;
419    /// Periodic Inquiry Mode
420    const PERIODIC_INQUIRY_MODE = 0, 1 << 2;
421    /// Exit Periodic Inquiry Mode
422    const EXIT_PERIODIC_INQUIRY_MODE = 0, 1 << 3;
423    /// Create Connection
424    const CREATE_CONNECTION = 0, 1 << 4;
425    /// Disconnect
426    const DISCONNECT = 0, 1 << 5;
427    /// Add SCO Connection (deprecated by the spec)
428    #[deprecated]
429    const ADD_SCO_CONNECTION = 0, 1 << 6;
430    /// Create Connection Cancel
431    const CREATE_CONNECTION_CANCEL = 0, 1 << 7;
432    /// Accept Connection Request
433    const ACCEPT_CONNECTION_REQUEST = 1, 1 << 0;
434    /// Reject Connection Request
435    const REJECT_CONNECTION_REQUEST = 1, 1 << 1;
436    /// Link Key Request Reply
437    const LINK_KEY_REQUEST_REPLY = 1, 1 << 2;
438    /// Link Key Request Negative Reply
439    const LINK_KEY_REQUEST_NEGATIVE_REPLY = 1, 1 << 3;
440    /// PIN Code Request Reply
441    const PIN_CODE_REQUEST_REPLY = 1, 1 << 4;
442    /// PIN Code Request Negative Reply
443    const PIN_CODE_REQUEST_NEGATIVE_REPLY = 1, 1 << 5;
444    /// Change Connection Packet Type
445    const CHANGE_CONNECTION_PACKET_TYPE = 1, 1 << 6;
446    /// Authentication Requested
447    const AUTHENTICATION_REQUESTED = 1, 1 << 7;
448    /// Set Connection Encryption
449    const SET_CONNECTION_ENCRYPTION = 2, 1 << 0;
450    /// Change Connection Link Key
451    const CHANGE_CONNECTION_LINK_KEY = 2, 1 << 1;
452    /// Master Link Key
453    const MASTER_LINK_KEY = 2, 1 << 2;
454    /// Remote Name Request
455    const REMOTE_NAME_REQUEST = 2, 1 << 3;
456    /// Remote Name Request Cancel
457    const REMOTE_NAME_REQUEST_CANCEL = 2, 1 << 4;
458    /// Read Remote Supported Features
459    const READ_REMOTE_SUPPORTED_FEATURES = 2, 1 << 5;
460    /// Read Remote Extended Features
461    const READ_REMOTE_EXTENDED_FEATURES = 2, 1 << 6;
462    /// Read Remote Version Information
463    const READ_REMOTE_VERSION_INFORMATION = 2, 1 << 7;
464    /// Read Clock Offset
465    const READ_CLOCK_OFFSET = 3, 1 << 0;
466    /// Read LMP Handle
467    const READ_LMP_HANDLE = 3, 1 << 1;
468    /// Hold Mode
469    const HOLD_MODE = 4, 1 << 1;
470    /// Sniff Mode
471    const SNIFF_MODE = 4, 1 << 2;
472    /// Exit Sniff Mode
473    const EXIT_SNIFF_MODE = 4, 1 << 3;
474    /// Park State
475    const PARK_STATE = 4, 1 << 4;
476    /// Exit Park State
477    const EXIT_PARK_STATE = 4, 1 << 5;
478    /// QoS Setup
479    const QOS_SETUP = 4, 1 << 6;
480    /// Role Discovery
481    const ROLE_DISCOVERY = 4, 1 << 7;
482    /// Switch Role
483    const SWITCH_ROLE = 5, 1 << 0;
484    /// Read Link Policy Settings
485    const READ_LINK_POLICY_SETTINGS = 5, 1 << 1;
486    /// Write Link Policy Settings
487    const WRITE_LINK_POLICY_SETTINGS = 5, 1 << 2;
488    /// Read Default Link Policy Settings
489    const READ_DEFAULT_LINK_POLICY_SETTINGS = 5, 1 << 3;
490    /// Write Default Link Policy Settings
491    const WRITE_DEFAULT_LINK_POLICY_SETTINGS = 5, 1 << 4;
492    /// Flow Specification
493    const FLOW_SPECIFICATION = 5, 1 << 5;
494    /// Set Event Mask
495    const SET_EVENT_MASK = 5, 1 << 6;
496    /// Reset
497    const RESET = 5, 1 << 7;
498    /// Set Event Filter
499    const SET_EVENT_FILTER = 6, 1 << 0;
500    /// Flush
501    const FLUSH = 6, 1 << 1;
502    /// Read PIN Type
503    const READ_PIN_TYPE = 6, 1 << 2;
504    /// Write PIN Type
505    const WRITE_PIN_TYPE = 6, 1 << 3;
506    /// Create New Unit Key
507    const CREATE_NEW_UNIT_KEY = 6, 1 << 4;
508    /// Read Stored Link Key
509    const READ_STORED_LINK_KEY = 6, 1 << 5;
510    /// Write Stored Link Key
511    const WRITE_STORED_LINK_KEY = 6, 1 << 6;
512    /// Delete Stored Link Key
513    const DELETE_STORED_LINK_KEY = 6, 1 << 7;
514    /// Write Local Name
515    const WRITE_LOCAL_NAME = 7, 1 << 0;
516    /// Read Local Name
517    const READ_LOCAL_NAME = 7, 1 << 1;
518    /// Read Connection Accept Timeout
519    const READ_CONNECTION_ACCEPT_TIMEOUT = 7, 1 << 2;
520    /// Write Connection Accept Timeout
521    const WRITE_CONNECTION_ACCEPT_TIMEOUT = 7, 1 << 3;
522    /// Read Page Timeout
523    const READ_PAGE_TIMEOUT = 7, 1 << 4;
524    /// Write Page Timeout
525    const WRITE_PAGE_TIMEOUT = 7, 1 << 5;
526    /// Read Scan Enable
527    const READ_SCAN_ENABLE = 7, 1 << 6;
528    /// Write Scan Enable
529    const WRITE_SCAN_ENABLE = 7, 1 << 7;
530    /// Read Page Scan Activity
531    const READ_PAGE_SCAN_ACTIVITY = 8, 1 << 0;
532    /// Write Page Scan Activity
533    const WRITE_PAGE_SCAN_ACTIVITY = 8, 1 << 1;
534    /// Read Inquiry Scan Activity
535    const READ_INQUIRY_SCAN_ACTIVITY = 8, 1 << 2;
536    /// Write Inquiry Scan Activity
537    const WRITE_INQUIRY_SCAN_ACTIVITY = 8, 1 << 3;
538    /// Read Authentication Enable
539    const READ_AUTHENTICATION_ENABLE = 8, 1 << 4;
540    /// Write Authentication Enable
541    const WRITE_AUTHENTICATION_ENABLE = 8, 1 << 5;
542    /// Read Encryption Mode (deprecated by the spec)
543    #[deprecated]
544    const READ_ENCRYPTION_MODE = 8, 1 << 6;
545    /// Write Encryption Mode (deprecated by the spec)
546    #[deprecated]
547    const WRITE_ENCRYPTION_MODE = 8, 1 << 7;
548    /// Read Class Of Device
549    const READ_CLASS_OF_DEVICE = 9, 1 << 0;
550    /// Write Class Of Device
551    const WRITE_CLASS_OF_DEVICE = 9, 1 << 1;
552    /// Read Voice Setting
553    const READ_VOICE_SETTING = 9, 1 << 2;
554    /// Write Voice Setting
555    const WRITE_VOICE_SETTING = 9, 1 << 3;
556    /// Read Automatic Flush Timeout
557    const READ_AUTOMATIC_FLUSH_TIMEOUT = 9, 1 << 4;
558    /// Write Automatic Flush Timeout
559    const WRITE_AUTOMATIC_FLUSH_TIMEOUT = 9, 1 << 5;
560    /// Read Num Broadcast Retransmissions
561    const READ_NUM_BROADCAST_RETRANSMISSIONS = 9, 1 << 6;
562    /// Write Num Broadcast Retransmissions
563    const WRITE_NUM_BROADCAST_RETRANSMISSIONS = 9, 1 << 7;
564    /// Read Hold Mode Activity
565    const READ_HOLD_MODE_ACTIVITY = 10, 1 << 0;
566    /// Write Hold Mode Activity
567    const WRITE_HOLD_MODE_ACTIVITY = 10, 1 << 1;
568    /// Read Transmit Power Level
569    const READ_TRANSMIT_POWER_LEVEL = 10, 1 << 2;
570    /// Read Synchronous Flow Control Enable
571    const READ_SYNCHRONOUS_FLOW_CONTROL_ENABLE = 10, 1 << 3;
572    /// Write Synchronous Flow Control Enable
573    const WRITE_SYNCHRONOUS_FLOW_CONTROL_ENABLE = 10, 1 << 4;
574    /// Set Controller To Host Flow Control
575    const SET_CONTROLLER_TO_HOST_FLOW_CONTROL = 10, 1 << 5;
576    /// Host Buffer Size
577    const HOST_BUFFER_SIZE = 10, 1 << 6;
578    /// Host Number Of Completed Packets
579    const HOST_NUMBER_OF_COMPLETED_PACKETS = 10, 1 << 7;
580    /// Read Link Supervision Timeout
581    const READ_LINK_SUPERVISION_TIMEOUT = 11, 1 << 0;
582    /// Write Link Supervision Timeout
583    const WRITE_LINK_SUPERVISION_TIMEOUT = 11, 1 << 1;
584    /// Read Number of Supported IAC
585    const READ_NUMBER_OF_SUPPORTED_IAC = 11, 1 << 2;
586    /// Read Current IAC LAP
587    const READ_CURRENT_IAC_LAP = 11, 1 << 3;
588    /// Write Current IAC LAP
589    const WRITE_CURRENT_IAC_LAP = 11, 1 << 4;
590    /// Read Page Scan Mode Period (deprecated by the spec)
591    #[deprecated]
592    const READ_PAGE_SCAN_MODE_PERIOD = 11, 1 << 5;
593    /// Write Page Scan Mode Period (deprecated by the spec)
594    #[deprecated]
595    const WRITE_PAGE_SCAN_MODE_PERIOD = 11, 1 << 6;
596    /// Read Page Scan Mode (deprecated by the spec)
597    #[deprecated]
598    const READ_PAGE_SCAN_MODE = 11, 1 << 7;
599    /// Write Page Scan Mode (deprecated by the spec)
600    #[deprecated]
601    const WRITE_PAGE_SCAN_MODE = 12, 1 << 0;
602    /// Set AFH Host Channel Classification
603    const SET_AFH_HOST_CHANNEL_CLASSIFICATION = 12, 1 << 1;
604    /// Read Inquiry Scan Type
605    const READ_INQUIRY_SCAN_TYPE = 12, 1 << 4;
606    /// Write Inquiry Scan Type
607    const WRITE_INQUIRY_SCAN_TYPE = 12, 1 << 5;
608    /// Read Inquiry Mode
609    const READ_INQUIRY_MODE = 12, 1 << 6;
610    /// Write Inquiry Mode
611    const WRITE_INQUIRY_MODE = 12, 1 << 7;
612    /// Read Page Scan Type
613    const READ_PAGE_SCAN_TYPE = 13, 1 << 0;
614    /// Write Page Scan Type
615    const WRITE_PAGE_SCAN_TYPE = 13, 1 << 1;
616    /// Read AFH Channel Assessment Mode
617    const READ_AFH_CHANNEL_ASSESSMENT_MODE = 13, 1 << 2;
618    /// Write AFH Channel Assessment Mode
619    const WRITE_AFH_CHANNEL_ASSESSMENT_MODE = 13, 1 << 3;
620    /// Read Local Version Information
621    const READ_LOCAL_VERSION_INFORMATION = 14, 1 << 3;
622    /// Read Local Supported Features
623    const READ_LOCAL_SUPPORTED_FEATURES = 14, 1 << 5;
624    /// Read Local Extended Features
625    const READ_LOCAL_EXTENDED_FEATURES = 14, 1 << 6;
626    /// Read Buffer Size
627    const READ_BUFFER_SIZE = 14, 1 << 7;
628    /// Read Country Code [Deprecated by the spec]
629    #[deprecated]
630    const READ_COUNTRY_CODE = 15, 1 << 0;
631    /// Read BD ADDR
632    const READ_BD_ADDR = 15, 1 << 1;
633    /// Read Failed Contact Counter
634    const READ_FAILED_CONTACT_COUNTER = 15, 1 << 2;
635    /// Reset Failed Contact Counter
636    const RESET_FAILED_CONTACT_COUNTER = 15, 1 << 3;
637    /// Read Link Quality
638    const READ_LINK_QUALITY = 15, 1 << 4;
639    /// Read RSSI
640    const READ_RSSI = 15, 1 << 5;
641    /// Read AFH Channel Map
642    const READ_AFH_CHANNEL_MAP = 15, 1 << 6;
643    /// Read Clock
644    const READ_CLOCK = 15, 1 << 7;
645    /// Read Loopback Mode
646    const READ_LOOPBACK_MODE = 16, 1 << 0;
647    /// Write Loopback Mode
648    const WRITE_LOOPBACK_MODE = 16, 1 << 1;
649    /// Enable Device Under Test Mode
650    const ENABLE_DEVICE_UNDER_TEST_MODE = 16, 1 << 2;
651    /// Setup Synchronous Connection Request
652    const SETUP_SYNCHRONOUS_CONNECTION_REQUEST = 16, 1 << 3;
653    /// Accept Synchronous Connection Request
654    const ACCEPT_SYNCHRONOUS_CONNECTION_REQUEST = 16, 1 << 4;
655    /// Reject Synchronous Connection Request
656    const REJECT_SYNCHRONOUS_CONNECTION_REQUEST = 16, 1 << 5;
657    /// Read Extended Inquiry Response
658    const READ_EXTENDED_INQUIRY_RESPONSE = 17, 1 << 0;
659    /// Write Extended Inquiry Response
660    const WRITE_EXTENDED_INQUIRY_RESPONSE = 17, 1 << 1;
661    /// Refresh Encryption Key
662    const REFRESH_ENCRYPTION_KEY = 17, 1 << 2;
663    /// Sniff Subrating
664    const SNIFF_SUBRATING = 17, 1 << 4;
665    /// Read Simple Pairing Mode
666    const READ_SIMPLE_PAIRING_MODE = 17, 1 << 5;
667    /// Write Simple Pairing Mode
668    const WRITE_SIMPLE_PAIRING_MODE = 17, 1 << 6;
669    /// Read Local OOB Data
670    const READ_LOCAL_OOB_DATA = 17, 1 << 7;
671    /// Read Inquiry Response Transmit Power Level
672    const READ_INQUIRY_RESPONSE_TRANSMIT_POWER_LEVEL = 18, 1 << 0;
673    /// Write Inquiry Transmit Power Level
674    const WRITE_INQUIRY_TRANSMIT_POWER_LEVEL = 18, 1 << 1;
675    /// Read Default Erroneous Data Reporting
676    const READ_DEFAULT_ERRONEOUS_DATA_REPORTING = 18, 1 << 2;
677    /// Write Default Erroneous Data Reporting
678    const WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING = 18, 1 << 3;
679    /// IO Capability Request Reply
680    const IO_CAPABILITY_REQUEST_REPLY = 18, 1 << 7;
681    /// User Confirmation Request Reply
682    const USER_CONFIRMATION_REQUEST_REPLY = 19, 1 << 0;
683    /// User Confirmation Request Negative Reply
684    const USER_CONFIRMATION_REQUEST_NEGATIVE_REPLY = 19, 1 << 1;
685    /// User Passkey Request Reply
686    const USER_PASSKEY_REQUEST_REPLY = 19, 1 << 2;
687    /// User Passkey Request Negative Reply
688    const USER_PASSKEY_REQUEST_NEGATIVE_REPLY = 19, 1 << 3;
689    /// Remote OOB Data Request Reply
690    const REMOTE_OOB_DATA_REQUEST_REPLY = 19, 1 << 4;
691    /// Write Simple Pairing Debug Mode
692    const WRITE_SIMPLE_PAIRING_DEBUG_MODE = 19, 1 << 5;
693    /// Enhanced Flush
694    const ENHANCED_FLUSH = 19, 1 << 6;
695    /// Remote OOB Data Request Negative Reply
696    const REMOTE_OOB_DATA_REQUEST_NEGATIVE_REPLY = 19, 1 << 7;
697    /// Send Keypress Notification
698    const SEND_KEYPRESS_NOTIFICATION = 20, 1 << 2;
699    /// IO Capability Request Negative Reply
700    const IO_CAPABILITY_REQUEST_NEGATIVE_REPLY = 20, 1 << 3;
701    /// Read Encryption Key Size
702    const READ_ENCRYPTION_KEY_SIZE = 20, 1 << 4;
703    /// Create Physical Link
704    const CREATE_PHYSICAL_LINK = 21, 1 << 0;
705    /// Accept Physical Link
706    const ACCEPT_PHYSICAL_LINK = 21, 1 << 1;
707    /// Disconnect Physical Link
708    const DISCONNECT_PHYSICAL_LINK = 21, 1 << 2;
709    /// Create Logical Link
710    const CREATE_LOGICAL_LINK = 21, 1 << 3;
711    /// Accept Logical Link
712    const ACCEPT_LOGICAL_LINK = 21, 1 << 4;
713    /// Disconnect Logical Link
714    const DISCONNECT_LOGICAL_LINK = 21, 1 << 5;
715    /// Logical Link Cancel
716    const LOGICAL_LINK_CANCEL = 21, 1 << 6;
717    /// Flow Spec Modify
718    const FLOW_SPEC_MODIFY = 21, 1 << 7;
719    /// Read Logical Link Accept Timeout
720    const READ_LOGICAL_LINK_ACCEPT_TIMEOUT = 22, 1 << 0;
721    /// Write Logical Link Accept Timeout
722    const WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT = 22, 1 << 1;
723    /// Set Event Mask Page 2
724    const SET_EVENT_MASK_PAGE_2 = 22, 1 << 2;
725    /// Read Location Data
726    const READ_LOCATION_DATA = 22, 1 << 3;
727    /// Write Location Data
728    const WRITE_LOCATION_DATA = 22, 1 << 4;
729    /// Read Local AMP Info
730    const READ_LOCAL_AMP_INFO = 22, 1 << 5;
731    /// Read Local AMP_ASSOC
732    const READ_LOCAL_AMP_ASSOC = 22, 1 << 6;
733    /// Write Remote AMP_ASSOC
734    const WRITE_REMOTE_AMP_ASSOC = 22, 1 << 7;
735    /// Read Flow Control Mode
736    const READ_FLOW_CONTROL_MODE = 23, 1 << 0;
737    /// Write Flow Control Mode
738    const WRITE_FLOW_CONTROL_MODE = 23, 1 << 1;
739    /// Read Data Block Size
740    const READ_DATA_BLOCK_SIZE = 23, 1 << 2;
741    /// Enable AMP Receiver Reports
742    const ENABLE_AMP_RECEIVER_REPORTS = 23, 1 << 5;
743    /// AMP Test End
744    const AMP_TEST_END = 23, 1 << 6;
745    /// AMP Test
746    const AMP_TEST = 23, 1 << 7;
747    /// Read Enhanced Transmit Power Level
748    const READ_ENHANCED_TRANSMIT_POWER_LEVEL = 24, 1 << 0;
749    /// Read Best Effort Flush Timeout
750    const READ_BEST_EFFORT_FLUSH_TIMEOUT = 24, 1 << 2;
751    /// Write Best Effort Flush Timeout
752    const WRITE_BEST_EFFORT_FLUSH_TIMEOUT = 24, 1 << 3;
753    /// Short Range Mode
754    const SHORT_RANGE_MODE = 24, 1 << 4;
755    /// Read LE Host Support
756    const READ_LE_HOST_SUPPORT = 24, 1 << 5;
757    /// Write LE Host Support
758    const WRITE_LE_HOST_SUPPORT = 24, 1 << 6;
759    /// LE Set Event Mask
760    const LE_SET_EVENT_MASK = 25, 1 << 0;
761    /// LE Read Buffer Size
762    const LE_READ_BUFFER_SIZE = 25, 1 << 1;
763    /// LE Read Local Supported Features
764    const LE_READ_LOCAL_SUPPORTED_FEATURES = 25, 1 << 2;
765    /// LE Set Random Address
766    const LE_SET_RANDOM_ADDRESS = 25, 1 << 4;
767    /// LE Set Advertising Parameters
768    const LE_SET_ADVERTISING_PARAMETERS = 25, 1 << 5;
769    /// LE Read Advertising Channel TX Power
770    const LE_READ_ADVERTISING_CHANNEL_TX_POWER = 25, 1 << 6;
771    /// LE Set Advertising Data
772    const LE_SET_ADVERTISING_DATA = 25, 1 << 7;
773    /// LE Set Scan Response Data
774    const LE_SET_SCAN_RESPONSE_DATA = 26, 1 << 0;
775    /// LE Set Advertise Enable
776    const LE_SET_ADVERTISE_ENABLE = 26, 1 << 1;
777    /// LE Set Scan Parameters
778    const LE_SET_SCAN_PARAMETERS = 26, 1 << 2;
779    /// LE Set Scan Enable
780    const LE_SET_SCAN_ENABLE = 26, 1 << 3;
781    /// LE Create Connection
782    const LE_CREATE_CONNECTION = 26, 1 << 4;
783    /// LE Create Connection Cancel
784    const LE_CREATE_CONNECTION_CANCEL = 26, 1 << 5;
785    /// LE Read White List Size
786    const LE_READ_WHITE_LIST_SIZE = 26, 1 << 6;
787    /// LE Clear White List
788    const LE_CLEAR_WHITE_LIST = 26, 1 << 7;
789    /// LE Add Device To White List
790    const LE_ADD_DEVICE_TO_WHITE_LIST = 27, 1 << 0;
791    /// LE Remove Device From White List
792    const LE_REMOVE_DEVICE_FROM_WHITE_LIST = 27, 1 << 1;
793    /// LE Connection Update
794    const LE_CONNECTION_UPDATE = 27, 1 << 2;
795    /// LE Set Host Channel Classification
796    const LE_SET_HOST_CHANNEL_CLASSIFICATION = 27, 1 << 3;
797    /// LE Read Channel Map
798    const LE_READ_CHANNEL_MAP = 27, 1 << 4;
799    /// LE Read Remote Used Features
800    const LE_READ_REMOTE_USED_FEATURES = 27, 1 << 5;
801    /// LE Encrypt
802    const LE_ENCRYPT = 27, 1 << 6;
803    /// LE Rand
804    const LE_RAND = 27, 1 << 7;
805    /// LE Start Encryption
806    const LE_START_ENCRYPTION = 28, 1 << 0;
807    /// LE Long Term Key Request Reply
808    const LE_LONG_TERM_KEY_REQUEST_REPLY = 28, 1 << 1;
809    /// LE Long Term Key Request Negative Reply
810    const LE_LONG_TERM_KEY_REQUEST_NEGATIVE_REPLY = 28, 1 << 2;
811    /// LE Read Supported States
812    const LE_READ_SUPPORTED_STATES = 28, 1 << 3;
813    /// LE Receiver Test
814    const LE_RECEIVER_TEST = 28, 1 << 4;
815    /// LE Transmitter Test
816    const LE_TRANSMITTER_TEST = 28, 1 << 5;
817    /// LE Test End
818    const LE_TEST_END = 28, 1 << 6;
819    /// Enhanced Setup Synchronous Connection
820    const ENHANCED_SETUP_SYNCHRONOUS_CONNECTION = 29, 1 << 3;
821    /// Enhanced Accept Synchronous Connection
822    const ENHANCED_ACCEPT_SYNCHRONOUS_CONNECTION = 29, 1 << 4;
823    /// Read Local Supported Codecs
824    const READ_LOCAL_SUPPORTED_CODECS = 29, 1 << 5;
825    /// Set MWS Channel Parameters Command
826    const SET_MWS_CHANNEL_PARAMETERS_COMMAND = 29, 1 << 6;
827    /// Set External Frame Configuration Command
828    const SET_EXTERNAL_FRAME_CONFIGURATION_COMMAND = 29, 1 << 7;
829    /// Set MWS Signaling Command
830    const SET_MWS_SIGNALING_COMMAND = 30, 1 << 0;
831    /// Set Transport Layer Command
832    const SET_TRANSPORT_LAYER_COMMAND = 30, 1 << 1;
833    /// Set MWS Scan Frequency Table Command
834    const SET_MWS_SCAN_FREQUENCY_TABLE_COMMAND = 30, 1 << 2;
835    /// Get Transport Layer Configuration Command
836    const GET_TRANSPORT_LAYER_CONFIGURATION_COMMAND = 30, 1 << 3;
837    /// Set MWS PATTERN Configuration Command
838    const SET_MWS_PATTERN_CONFIGURATION_COMMAND = 30, 1 << 4;
839    /// Set Triggered Clock Capture
840    const SET_TRIGGERED_CLOCK_CAPTURE = 30, 1 << 5;
841    /// Truncated Page
842    const TRUNCATED_PAGE = 30, 1 << 6;
843    /// Truncated Page Cancel
844    const TRUNCATED_PAGE_CANCEL = 30, 1 << 7;
845    /// Set Connectionless Peripheral Broadcast
846    const SET_CONNECTIONLESS_PERIPHERAL_BROADCAST = 31, 1 << 0;
847    /// Set Connectionless Peripheral Broadcast Receive
848    const SET_CONNECTIONLESS_PERIPHERAL_BROADCAST_RECEIVE = 31, 1 << 1;
849    /// Start Synchronization Train
850    const START_SYNCHRONIZATION_TRAIN = 31, 1 << 2;
851    /// Receive Synchronization Train
852    const RECEIVE_SYNCHRONIZATION_TRAIN = 31, 1 << 3;
853    /// Set Connectionless Peripheral Broadcast Data
854    const SET_CONNECTIONLESS_PERIPHERAL_BROADCAST_DATA = 31, 1 << 6;
855    /// Read Synchronization Train Parameters
856    const READ_SYNCHRONIZATION_TRAIN_PARAMETERS = 31, 1 << 7;
857    /// Write Synchronization Train Parameters
858    const WRITE_SYNCHRONIZATION_TRAIN_PARAMETERS = 32, 1 << 0;
859    /// Remote OOB Extended Data Request Reply
860    const REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY = 32, 1 << 1;
861    /// Read Secure Connections Host Support
862    const READ_SECURE_CONNECTIONS_HOST_SUPPORT = 32, 1 << 2;
863    /// Write Secure Connections Host Support
864    const WRITE_SECURE_CONNECTIONS_HOST_SUPPORT = 32, 1 << 3;
865    /// Read Authenticated Payload Timeout
866    const READ_AUTHENTICATED_PAYLOAD_TIMEOUT = 32, 1 << 4;
867    /// Write Authenticated Payload Timeout
868    const WRITE_AUTHENTICATED_PAYLOAD_TIMEOUT = 32, 1 << 5;
869    /// Read Local OOB Extended Data
870    const READ_LOCAL_OOB_EXTENDED_DATA = 32, 1 << 6;
871    /// Write Secure Connections Test Mode
872    const WRITE_SECURE_CONNECTIONS_TEST_MODE = 32, 1 << 7;
873    /// Read Extended Page Timeout
874    const READ_EXTENDED_PAGE_TIMEOUT = 33, 1 << 0;
875    /// Write Extended Page Timeout
876    const WRITE_EXTENDED_PAGE_TIMEOUT = 33, 1 << 1;
877    /// Read Extended Inquiry Length
878    const READ_EXTENDED_INQUIRY_LENGTH = 33, 1 << 2;
879    /// Write Extended Inquiry Length
880    const WRITE_EXTENDED_INQUIRY_LENGTH = 33, 1 << 3;
881    /// LE Remote Connection Parameter Request Reply Command
882    const LE_REMOTE_CONNECTION_PARAMETER_REQUEST_REPLY_COMMAND = 33, 1 << 4;
883    /// LE Remote Connection Parameter Request Negative Reply Command
884    const LE_REMOTE_CONNECTION_PARAMETER_REQUEST_NEGATIVE_REPLY_COMMAND = 33, 1 << 5;
885    /// LE Set Data Length
886    const LE_SET_DATA_LENGTH = 33, 1 << 6;
887    /// LE Read Suggested Default Data Length
888    const LE_READ_SUGGESTED_DEFAULT_DATA_LENGTH = 33, 1 << 7;
889    /// LE Write Suggested Default Data Length
890    const LE_WRITE_SUGGESTED_DEFAULT_DATA_LENGTH = 34, 1 << 0;
891    /// LE Read Local P-256 Public Key
892    const LE_READ_LOCAL_P256_PUBLIC_KEY = 34, 1 << 1;
893    /// LE Generate DH Key
894    const LE_GENERATE_DH_KEY = 34, 1 << 2;
895    /// LE Add Device To Resolving List
896    const LE_ADD_DEVICE_TO_RESOLVING_LIST = 34, 1 << 3;
897    /// LE Remove Device From Resolving List
898    const LE_REMOVE_DEVICE_FROM_RESOLVING_LIST = 34, 1 << 4;
899    /// LE Clear Resolving List
900    const LE_CLEAR_RESOLVING_LIST = 34, 1 << 5;
901    /// LE Read Resolving List Size
902    const LE_READ_RESOLVING_LIST_SIZE = 34, 1 << 6;
903    /// LE Read Peer Resolvable Address
904    const LE_READ_PEER_RESOLVABLE_ADDRESS = 34, 1 << 7;
905    /// LE Read Local Resolvable Address
906    const LE_READ_LOCAL_RESOLVABLE_ADDRESS = 35, 1 << 0;
907    /// LE Set Address Resolution Enable
908    const LE_SET_ADDRESS_RESOLUTION_ENABLE = 35, 1 << 1;
909    /// LE Set Resolvable Private Address Timeout
910    const LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT = 35, 1 << 2;
911    /// LE Read Maximum Data Length
912    const LE_READ_MAXIMUM_DATA_LENGTH = 35, 1 << 3;
913    /// LE Read PHY Command
914    const LE_READ_PHY_COMMAND = 35, 1 << 4;
915    /// LE Set Default PHY Command
916    const LE_SET_DEFAULT_PHY_COMMAND = 35, 1 << 5;
917    /// LE Set PHY Command
918    const LE_SET_PHY_COMMAND = 35, 1 << 6;
919    /// LE Enhanced Receiver Test Command
920    const LE_ENHANCED_RECEIVER_TEST_COMMAND = 35, 1 << 7;
921    /// LE Enhanced Transmitter Test Command
922    const LE_ENHANCED_TRANSMITTER_TEST_COMMAND = 36, 1 << 0;
923    /// LE Set Advertising Set Random Address Command
924    const LE_SET_ADVERTISING_SET_RANDOM_ADDRESS_COMMAND = 36, 1 << 1;
925    /// LE Set Extended Advertising Parameters Command
926    const LE_SET_EXTENDED_ADVERTISING_PARAMETERS_COMMAND = 36, 1 << 2;
927    /// LE Set Extended Advertising Data Command
928    const LE_SET_EXTENDED_ADVERTISING_DATA_COMMAND = 36, 1 << 3;
929    /// LE Set Extended Scan Response Data Command
930    const LE_SET_EXTENDED_SCAN_RESPONSE_DATA_COMMAND = 36, 1 << 4;
931    /// LE Set Extended Advertising Enable Command
932    const LE_SET_EXTENDED_ADVERTISING_ENABLE_COMMAND = 36, 1 << 5;
933    /// LE Read Maximum Advertising Data Length Command
934    const LE_READ_MAXIMUM_ADVERTISING_DATA_LENGTH_COMMAND = 36, 1 << 6;
935    /// LE Read Number of Supported Advertising Sets Command
936    const LE_READ_NUMBER_OF_SUPPORTED_ADVERTISING_SETS_COMMAND = 36, 1 << 7;
937    /// LE Remove Advertising Set Command
938    const LE_REMOVE_ADVERTISING_SET_COMMAND = 37, 1 << 0;
939    /// LE Clear Advertising Sets Command
940    const LE_CLEAR_ADVERTISING_SETS_COMMAND = 37, 1 << 1;
941    /// LE Set Periodic Advertising Parameters Command
942    const LE_SET_PERIODIC_ADVERTISING_PARAMETERS_COMMAND = 37, 1 << 2;
943    /// LE Set Periodic Advertising Data Command
944    const LE_SET_PERIODIC_ADVERTISING_DATA_COMMAND = 37, 1 << 3;
945    /// LE Set Periodic Advertising Enable Command
946    const LE_SET_PERIODIC_ADVERTISING_ENABLE_COMMAND = 37, 1 << 4;
947    /// LE Set Extended Scan Parameters Command
948    const LE_SET_EXTENDED_SCAN_PARAMETERS_COMMAND = 37, 1 << 5;
949    /// LE Set Extended Scan Enable Command
950    const LE_SET_EXTENDED_SCAN_ENABLE_COMMAND = 37, 1 << 6;
951    /// LE Extended Create Connection Command
952    const LE_EXTENDED_CREATE_CONNECTION_COMMAND = 37, 1 << 7;
953    /// LE Periodic Advertising Create Sync Command
954    const LE_PERIODIC_ADVERTISING_CREATE_SYNC_COMMAND = 38, 1 << 0;
955    /// LE Periodic Advertising Create Sync Cancel Command
956    const LE_PERIODIC_ADVERTISING_CREATE_SYNC_CANCEL_COMMAND = 38, 1 << 1;
957    /// LE Periodic Advertising Terminate Sync Command
958    const LE_PERIODIC_ADVERTISING_TERMINATE_SYNC_COMMAND = 38, 1 << 2;
959    /// LE Add Device To Periodic Advertiser List Command
960    const LE_ADD_DEVICE_TO_PERIODIC_ADVERTISER_LIST_COMMAND = 38, 1 << 3;
961    /// LE Remove Device From Periodic Advertiser List Command
962    const LE_REMOVE_DEVICE_FROM_PERIODIC_ADVERTISER_LIST_COMMAND = 38, 1 << 4;
963    /// LE Clear Periodic Advertiser List Command
964    const LE_CLEAR_PERIODIC_ADVERTISER_LIST_COMMAND = 38, 1 << 5;
965    /// LE Read Periodic Advertiser List Size Command
966    const LE_READ_PERIODIC_ADVERTISER_LIST_SIZE_COMMAND = 38, 1 << 6;
967    /// LE Read Transmit Power Command
968    const LE_READ_TRANSMIT_POWER_COMMAND = 38, 1 << 7;
969    /// LE Read RF Path Compensation Command
970    const LE_READ_RF_PATH_COMPENSATION_COMMAND = 39, 1 << 0;
971    /// LE Write RF Path Compensation Command
972    const LE_WRITE_RF_PATH_COMPENSATION_COMMAND = 39, 1 << 1;
973    /// LE Set Privacy Mode
974    const LE_SET_PRIVACY_MODE = 39, 1 << 2;
975}
976
977impl Debug for CommandFlags {
978    fn fmt(&self, f: &mut Formatter) -> FmtResult {
979        writeln!(f, "{:?}", &self.0[..16])?;
980        writeln!(f, "{:?}", &self.0[16..32])?;
981        writeln!(f, "{:?}", &self.0[32..39])
982    }
983}
984
985impl<'a> TryFrom<&'a [u8]> for CommandFlags {
986    type Error = crate::event::Error;
987    fn try_from(value: &[u8]) -> Result<CommandFlags, Self::Error> {
988        require_len!(value, COMMAND_FLAGS_SIZE);
989
990        CommandFlags::from_bits(value).ok_or(crate::event::Error::BadCommandFlag)
991    }
992}
993
994fn to_supported_commands(bytes: &[u8]) -> Result<LocalSupportedCommands, crate::event::Error> {
995    require_len!(bytes, 1 + COMMAND_FLAGS_SIZE);
996    Ok(LocalSupportedCommands {
997        status: bytes[0].try_into().map_err(super::rewrap_bad_status)?,
998        supported_commands: bytes[1..=COMMAND_FLAGS_SIZE]
999            .try_into()
1000            .map_err(|e| match e {
1001                crate::event::Error::BadLength(actual, expected) => {
1002                    crate::event::Error::BadLength(actual, expected)
1003                }
1004                crate::event::Error::BadCommandFlag => crate::event::Error::BadCommandFlag,
1005                _ => unreachable!(),
1006            })?,
1007    })
1008}
1009
1010/// Values returned by the
1011/// [Read Local Supported Features](crate::host::HostHci::read_local_supported_features) command.
1012#[derive(Copy, Clone, Debug)]
1013#[cfg_attr(feature = "defmt", derive(defmt::Format))]
1014pub struct LocalSupportedFeatures {
1015    /// Did the command fail, and if so, how?
1016    pub status: Status,
1017
1018    /// Flags for supported features.
1019    pub supported_features: LmpFeatures,
1020}
1021
1022#[cfg(not(feature = "defmt"))]
1023bitflags::bitflags! {
1024    /// See the Bluetooth Specification, v4.1 or later, Vol 2, Part C, Section 3.3 (Table 3.2).
1025    #[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
1026    pub struct LmpFeatures : u64 {
1027        /// 3-slot packets
1028        const THREE_SLOT_PACKETS = 1 << 0;
1029        /// 5-slot packets
1030        const FIVE_SLOT_PACKETS = 1 << 1;
1031        /// Encryption
1032        const ENCRYPTION = 1 << 2;
1033        /// Slot offset
1034        const SLOT_OFFSET = 1 << 3;
1035        /// Timing accuracy
1036        const TIMING_ACCURACY = 1 << 4;
1037        /// Role switch
1038        const ROLE_SWITCH = 1 << 5;
1039        /// Hold mode
1040        const HOLD_MODE = 1 << 6;
1041        /// Sniff mode
1042        const SNIFF_MODE = 1 << 7;
1043        /// Power control requests
1044        const POWER_CONTROL_REQUESTS = 1 << 9;
1045        /// Channel quality driven data rate (CQDDR)
1046        const CHANNEL_QUALITY_DRIVEN_DATA_RATE_CQDDR = 1 << 10;
1047        /// SCO link
1048        const SCO_LINK = 1 << 11;
1049        /// HV2 packets
1050        const HV2_PACKETS = 1 << 12;
1051        /// HV3 packets
1052        const HV3_PACKETS = 1 << 13;
1053        /// μ-law log synchronous data
1054        const MU_LAW_LOG_SYNCHRONOUS_DATA = 1 << 14;
1055        /// A-law log synchronous data
1056        const A_LAW_LOG_SYNCHRONOUS_DATA = 1 << 15;
1057        /// CVSD synchronous data
1058        const CVSD_SYNCHRONOUS_DATA = 1 << 16;
1059        /// Paging parameter negotiation
1060        const PAGING_PARAMETER_NEGOTIATION = 1 << 17;
1061        /// Power control
1062        const POWER_CONTROL = 1 << 18;
1063        /// Transparent synchronous data
1064        const TRANSPARENT_SYNCHRONOUS_DATA = 1 << 19;
1065        /// Flow control lag (least significant bit)
1066        const FLOW_CONTROL_LAG_LSB = 1 << 20;
1067        /// Flow control lag (middle bit)
1068        const FLOW_CONTROL_LAG_MID = 1 << 21;
1069        /// Flow control lag (most significant bit)
1070        const FLOW_CONTROL_LAG_MSB = 1 << 22;
1071        /// Broadcast Encryption
1072        const BROADCAST_ENCRYPTION = 1 << 23;
1073        /// Enhanced Data Rate ACL 2 Mb/s mode
1074        const ENHANCED_DATA_RATE_ACL_2_MB_PER_S_MODE = 1 << 25;
1075        /// Enhanced Data Rate ACL 3 Mb/s mode
1076        const ENHANCED_DATA_RATE_ACL_3_MB_PER_S_MODE = 1 << 26;
1077        /// Enhanced inquiry scan
1078        const ENHANCED_INQUIRY_SCAN = 1 << 27;
1079        /// Interlaced inquiry scan
1080        const INTERLACED_INQUIRY_SCAN = 1 << 28;
1081        /// Interlaced page scan
1082        const INTERLACED_PAGE_SCAN = 1 << 29;
1083        /// RSSI with inquiry results
1084        const RSSI_WITH_INQUIRY_RESULTS = 1 << 30;
1085        /// Extended SCO link (EV3 packets)
1086        const EXTENDED_SCO_LINK_EV3_PACKETS = 1 << 31;
1087        /// EV4 packets
1088        const EV4_PACKETS = 1 << 32;
1089        /// EV5 packets
1090        const EV5_PACKETS = 1 << 33;
1091        /// AFH capable peripheral
1092        const AFH_CAPABLE_PERIPHERAL = 1 << 35;
1093        /// AFH classification peripheral
1094        const AFH_CLASSIFICATION_PERIPHERAL = 1 << 36;
1095        /// BR/EDR Not Supported
1096        const BR_EDR_NOT_SUPPORTED = 1 << 37;
1097        /// LE Supported (Controller)
1098        const LE_SUPPORTED_BY_CONTROLLER = 1 << 38;
1099        /// 3-slot Enhanced Data Rate ACL packets
1100        const THREE_SLOT_ENHANCED_DATA_RATE_ACL_PACKETS = 1 << 39;
1101        /// 5-slot Enhanced Data Rate ACL packets
1102        const FIVE_SLOT_ENHANCED_DATA_RATE_ACL_PACKETS = 1 << 40;
1103        /// Sniff subrating
1104        const SNIFF_SUBRATING = 1 << 41;
1105        /// Pause encryption
1106        const PAUSE_ENCRYPTION = 1 << 42;
1107        /// AFH capable central device
1108        const AFH_CAPABLE_CENTRAL_DEVICE = 1 << 43;
1109        /// AFH classification central device
1110        const AFH_CLASSIFICATION_CENTRAL_DEVICE = 1 << 44;
1111        /// Enhanced Data Rate eSCO 2 Mb/s mode
1112        const ENHANCED_DATA_RATE_ESCO_2_MB_PER_S_MODE = 1 << 45;
1113        /// Enhanced Data Rate eSCO 3 Mb/s mode
1114        const ENHANCED_DATA_RATE_ESCO_3_MB_PER_S_MODE = 1 << 46;
1115        /// 3-slot Enhanced Data Rate eSCO packets
1116        const THREE_SLOT_ENHANCED_DATA_RATE_ESCO_PACKETS = 1 << 47;
1117        /// Extended Inquiry Response
1118        const EXTENDED_INQUIRY_RESPONSE = 1 << 48;
1119        /// Simultaneous LE and BR/EDR to Same Device Capable (Controller)
1120        const SIMULTANEOUS_LE_AND_BR_EDR_TO_SAME_DEVICE_CAPABLE = 1 << 49;
1121        /// Secure Simple Pairing
1122        const SECURE_SIMPLE_PAIRING = 1 << 51;
1123        /// Encapsulated PDU
1124        const ENCAPSULATED_PDU = 1 << 52;
1125        /// Erroneous Data Reporting
1126        const ERRONEOUS_DATA_REPORTING = 1 << 53;
1127        /// Non-flushable Packet Boundary Flag
1128        const NON_FLUSHABLE_PACKET_BOUNDARY_FLAG = 1 << 54;
1129        /// Link Supervision Timeout Changed Event
1130        const LINK_SUPERVISION_TIMEOUT_CHANGED_EVENT = 1 << 56;
1131        /// Inquiry TX Power Level
1132        const INQUIRY_TX_POWER_LEVEL = 1 << 57;
1133        /// Enhanced Power Control
1134        const ENHANCED_POWER_CONTROL = 1 << 58;
1135        /// Extended features
1136        const EXTENDED_FEATURES = 1 << 63;
1137    }
1138}
1139
1140#[cfg(feature = "defmt")]
1141defmt::bitflags! {
1142    /// See the Bluetooth Specification, v4.1 or later, Vol 2, Part C, Section 3.3 (Table 3.2).
1143    #[derive(Default)]
1144    pub struct LmpFeatures : u64 {
1145        /// 3-slot packets
1146        const THREE_SLOT_PACKETS = 1 << 0;
1147        /// 5-slot packets
1148        const FIVE_SLOT_PACKETS = 1 << 1;
1149        /// Encryption
1150        const ENCRYPTION = 1 << 2;
1151        /// Slot offset
1152        const SLOT_OFFSET = 1 << 3;
1153        /// Timing accuracy
1154        const TIMING_ACCURACY = 1 << 4;
1155        /// Role switch
1156        const ROLE_SWITCH = 1 << 5;
1157        /// Hold mode
1158        const HOLD_MODE = 1 << 6;
1159        /// Sniff mode
1160        const SNIFF_MODE = 1 << 7;
1161        /// Power control requests
1162        const POWER_CONTROL_REQUESTS = 1 << 9;
1163        /// Channel quality driven data rate (CQDDR)
1164        const CHANNEL_QUALITY_DRIVEN_DATA_RATE_CQDDR = 1 << 10;
1165        /// SCO link
1166        const SCO_LINK = 1 << 11;
1167        /// HV2 packets
1168        const HV2_PACKETS = 1 << 12;
1169        /// HV3 packets
1170        const HV3_PACKETS = 1 << 13;
1171        /// μ-law log synchronous data
1172        const MU_LAW_LOG_SYNCHRONOUS_DATA = 1 << 14;
1173        /// A-law log synchronous data
1174        const A_LAW_LOG_SYNCHRONOUS_DATA = 1 << 15;
1175        /// CVSD synchronous data
1176        const CVSD_SYNCHRONOUS_DATA = 1 << 16;
1177        /// Paging parameter negotiation
1178        const PAGING_PARAMETER_NEGOTIATION = 1 << 17;
1179        /// Power control
1180        const POWER_CONTROL = 1 << 18;
1181        /// Transparent synchronous data
1182        const TRANSPARENT_SYNCHRONOUS_DATA = 1 << 19;
1183        /// Flow control lag (least significant bit)
1184        const FLOW_CONTROL_LAG_LSB = 1 << 20;
1185        /// Flow control lag (middle bit)
1186        const FLOW_CONTROL_LAG_MID = 1 << 21;
1187        /// Flow control lag (most significant bit)
1188        const FLOW_CONTROL_LAG_MSB = 1 << 22;
1189        /// Broadcast Encryption
1190        const BROADCAST_ENCRYPTION = 1 << 23;
1191        /// Enhanced Data Rate ACL 2 Mb/s mode
1192        const ENHANCED_DATA_RATE_ACL_2_MB_PER_S_MODE = 1 << 25;
1193        /// Enhanced Data Rate ACL 3 Mb/s mode
1194        const ENHANCED_DATA_RATE_ACL_3_MB_PER_S_MODE = 1 << 26;
1195        /// Enhanced inquiry scan
1196        const ENHANCED_INQUIRY_SCAN = 1 << 27;
1197        /// Interlaced inquiry scan
1198        const INTERLACED_INQUIRY_SCAN = 1 << 28;
1199        /// Interlaced page scan
1200        const INTERLACED_PAGE_SCAN = 1 << 29;
1201        /// RSSI with inquiry results
1202        const RSSI_WITH_INQUIRY_RESULTS = 1 << 30;
1203        /// Extended SCO link (EV3 packets)
1204        const EXTENDED_SCO_LINK_EV3_PACKETS = 1 << 31;
1205        /// EV4 packets
1206        const EV4_PACKETS = 1 << 32;
1207        /// EV5 packets
1208        const EV5_PACKETS = 1 << 33;
1209        /// AFH capable peripheral
1210        const AFH_CAPABLE_PERIPHERAL = 1 << 35;
1211        /// AFH classification peripheral
1212        const AFH_CLASSIFICATION_PERIPHERAL = 1 << 36;
1213        /// BR/EDR Not Supported
1214        const BR_EDR_NOT_SUPPORTED = 1 << 37;
1215        /// LE Supported (Controller)
1216        const LE_SUPPORTED_BY_CONTROLLER = 1 << 38;
1217        /// 3-slot Enhanced Data Rate ACL packets
1218        const THREE_SLOT_ENHANCED_DATA_RATE_ACL_PACKETS = 1 << 39;
1219        /// 5-slot Enhanced Data Rate ACL packets
1220        const FIVE_SLOT_ENHANCED_DATA_RATE_ACL_PACKETS = 1 << 40;
1221        /// Sniff subrating
1222        const SNIFF_SUBRATING = 1 << 41;
1223        /// Pause encryption
1224        const PAUSE_ENCRYPTION = 1 << 42;
1225        /// AFH capable central device
1226        const AFH_CAPABLE_CENTRAL_DEVICE = 1 << 43;
1227        /// AFH classification central device
1228        const AFH_CLASSIFICATION_CENTRAL_DEVICE = 1 << 44;
1229        /// Enhanced Data Rate eSCO 2 Mb/s mode
1230        const ENHANCED_DATA_RATE_ESCO_2_MB_PER_S_MODE = 1 << 45;
1231        /// Enhanced Data Rate eSCO 3 Mb/s mode
1232        const ENHANCED_DATA_RATE_ESCO_3_MB_PER_S_MODE = 1 << 46;
1233        /// 3-slot Enhanced Data Rate eSCO packets
1234        const THREE_SLOT_ENHANCED_DATA_RATE_ESCO_PACKETS = 1 << 47;
1235        /// Extended Inquiry Response
1236        const EXTENDED_INQUIRY_RESPONSE = 1 << 48;
1237        /// Simultaneous LE and BR/EDR to Same Device Capable (Controller)
1238        const SIMULTANEOUS_LE_AND_BR_EDR_TO_SAME_DEVICE_CAPABLE = 1 << 49;
1239        /// Secure Simple Pairing
1240        const SECURE_SIMPLE_PAIRING = 1 << 51;
1241        /// Encapsulated PDU
1242        const ENCAPSULATED_PDU = 1 << 52;
1243        /// Erroneous Data Reporting
1244        const ERRONEOUS_DATA_REPORTING = 1 << 53;
1245        /// Non-flushable Packet Boundary Flag
1246        const NON_FLUSHABLE_PACKET_BOUNDARY_FLAG = 1 << 54;
1247        /// Link Supervision Timeout Changed Event
1248        const LINK_SUPERVISION_TIMEOUT_CHANGED_EVENT = 1 << 56;
1249        /// Inquiry TX Power Level
1250        const INQUIRY_TX_POWER_LEVEL = 1 << 57;
1251        /// Enhanced Power Control
1252        const ENHANCED_POWER_CONTROL = 1 << 58;
1253        /// Extended features
1254        const EXTENDED_FEATURES = 1 << 63;
1255    }
1256}
1257
1258fn to_supported_features(bytes: &[u8]) -> Result<LocalSupportedFeatures, crate::event::Error> {
1259    require_len!(bytes, 9);
1260    Ok(LocalSupportedFeatures {
1261        status: to_status(bytes)?,
1262        supported_features: LmpFeatures::from_bits_truncate(LittleEndian::read_u64(&bytes[1..])),
1263    })
1264}
1265
1266/// Values returned by the [Read BD ADDR](crate::host::HostHci::read_bd_addr) command.
1267#[derive(Copy, Clone, Debug)]
1268#[cfg_attr(feature = "defmt", derive(defmt::Format))]
1269pub struct ReadBdAddr {
1270    /// Did the command fail, and if so, how?
1271    pub status: Status,
1272
1273    /// Address of the device.
1274    pub bd_addr: crate::BdAddr,
1275}
1276
1277fn to_bd_addr(bytes: &[u8]) -> Result<ReadBdAddr, crate::event::Error> {
1278    require_len!(bytes, 7);
1279    let mut bd_addr = crate::BdAddr([0; 6]);
1280    bd_addr.0.copy_from_slice(&bytes[1..]);
1281    Ok(ReadBdAddr {
1282        status: to_status(bytes)?,
1283        bd_addr,
1284    })
1285}
1286
1287/// Values returned by the [Read RSSI](crate::host::HostHci::read_rssi) command.
1288#[derive(Copy, Clone, Debug)]
1289#[cfg_attr(feature = "defmt", derive(defmt::Format))]
1290pub struct ReadRssi {
1291    /// Did the command fail, and if so, how?
1292    pub status: Status,
1293
1294    /// The Handle for the connection for which the RSSI has been read.
1295    ///
1296    /// The Handle is a connection handle for a BR/EDR Controller and a physical link handle for an
1297    /// AMP Controller.
1298    pub conn_handle: ConnectionHandle,
1299
1300    /// - BR/EDR
1301    ///   - No range restriction
1302    ///   - Units: dB
1303    /// - AMP:
1304    ///   - Range: AMP type specific
1305    ///   - Units: dBm
1306    /// - LE:
1307    ///   - Range: -127 to 20, range not checked by this implementation. 127 indicates RSSI not
1308    ///     available.
1309    ///   - Units: dBm
1310    pub rssi: i8,
1311}
1312
1313fn to_read_rssi(bytes: &[u8]) -> Result<ReadRssi, crate::event::Error> {
1314    require_len!(bytes, 4);
1315    Ok(ReadRssi {
1316        status: to_status(bytes)?,
1317        conn_handle: ConnectionHandle(LittleEndian::read_u16(&bytes[1..])),
1318        rssi: unsafe { mem::transmute::<u8, i8>(bytes[3]) },
1319    })
1320}
1321
1322/// Values returned by the [LE Read Buffer Size](crate::host::HostHci::le_read_buffer_size) command.
1323#[derive(Copy, Clone, Debug)]
1324#[cfg_attr(feature = "defmt", derive(defmt::Format))]
1325pub struct LeReadBufferSize {
1326    /// Did the command fail, and if so, how?
1327    pub status: Status,
1328
1329    /// The size of the L2CAP PDU segments contained in ACL Data Packets, which are transferred from
1330    /// the Host to the Controller to be broken up into packets by the Link Layer. Both the Host and
1331    /// the Controller shall support command and event packets, where the data portion (excluding
1332    /// header) contained in the packets is 255 octets in size.
1333    ///
1334    /// Note: Does not include the length of the HCI Data Packet header.
1335    ///
1336    /// If `data_packet_count` is 0, then the controller has no dedicated LE read buffer, so the
1337    /// caller should use the `read_buffer_size` command.
1338    pub data_packet_length: u16,
1339
1340    /// Contains the total number of HCI ACL Data Packets that can be stored in the data buffers of
1341    /// the Controller. The Host determines how the buffers are to be divided between different
1342    /// Connection Handles.
1343    ///
1344    /// If `data_packet_count` is 0, then the controller has no dedicated LE read buffer, so the
1345    /// caller should use the `read_buffer_size` command.
1346    pub data_packet_count: u8,
1347}
1348
1349fn to_le_read_buffer_status(bytes: &[u8]) -> Result<LeReadBufferSize, crate::event::Error> {
1350    require_len!(bytes, 4);
1351    Ok(LeReadBufferSize {
1352        status: to_status(bytes)?,
1353        data_packet_length: LittleEndian::read_u16(&bytes[1..]),
1354        data_packet_count: bytes[3],
1355    })
1356}
1357
1358/// Values returned by the
1359/// [LE Read Local Supported Features](crate::host::HostHci::le_read_local_supported_features) command.
1360#[derive(Copy, Clone, Debug)]
1361#[cfg_attr(feature = "defmt", derive(defmt::Format))]
1362pub struct LeSupportedFeatures {
1363    /// Did the command fail, and if so, how?
1364    pub status: Status,
1365
1366    /// Supported LE features.
1367    pub supported_features: LeFeatures,
1368}
1369
1370#[cfg(not(feature = "defmt"))]
1371bitflags::bitflags! {
1372    /// Possible LE features for the
1373    /// [LE Read Local Supported Features](crate::host::HostHci::le_read_local_supported_features) command.
1374    /// See the Bluetooth specification, Vol 6, Part B, Section 4.6.  See Table 4.3 (v4.1 of the spec),
1375    /// Table 4.4 (v4.2 and v5.0).
1376    #[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
1377    pub struct LeFeatures : u64 {
1378        /// LE Encryption.  Valid from controller to controller.
1379        const ENCRYPTION = 1 << 0;
1380        /// Connection Parameters Request Procedure.  Valid from controller to controller.
1381        const CONNECTION_PARAMETERS_REQUEST_PROCEDURE = 1 << 1;
1382        /// Extended Reject Indication.  Valid from controller to controller.
1383        const EXTENDED_REJECT_INDICATION = 1 << 2;
1384        /// Peripheral-initiated Features Exchange.  Valid from controller to controller.
1385        const PERIPHERALINITIATED_FEATURES_EXCHANGE = 1 << 3;
1386        /// LE Ping.  Not valid from controller to controller.
1387        const PING = 1 << 4;
1388        /// LE Data Packet Length Extension.  Valid from controller to controller.
1389        const DATA_PACKET_LENGTH_EXTENSION = 1 << 5;
1390        /// LL Privacy.  Not valid from controller to controller.
1391        const LL_PRIVACY = 1 << 6;
1392        /// Extended Scanner Filter Policies.  Not valid from controller to controller.
1393        const EXTENDED_SCANNER_FILTER_POLICIES = 1 << 7;
1394        /// LE 2M PHY.  Valid from controller to controller.
1395        const PHY_2M = 1 << 8;
1396        /// Stable Modulation Index - Transmitter.  Valid from controller to controller.
1397        const STABLE_MODULATION_INDEX_TX = 1 << 9;
1398        /// Stable Modulation Index - Receiver.  Valid from controller to controller.
1399        const STABLE_MODULATION_INDEX_RX = 1 << 10;
1400        /// LE Coded PHY.  Valid from controller to controller.
1401        const CODED_PHY = 1 << 11;
1402        /// LE Extended Advertising.  Not valid from controller to controller.
1403        const EXTENDED_ADVERTISING = 1 << 12;
1404        /// LE Periodic Advertising.  Not valid from controller to controller.
1405        const PERIODIC_ADVERTISING = 1 << 13;
1406        /// Channel Selection Algorithm #2.  Valid from controller to controller.
1407        const CHANNEL_SELECTION_ALGORITHM_2 = 1 << 14;
1408        /// LE Power Class 1.  Valid from controller to controller.
1409        const POWER_CLASS_1 = 1 << 15;
1410        /// Minimum Number of Used Channels Procedure
1411        const MINIMUM_NUMBER_OF_USED_CHANNELS_PROCEDURE = 1 << 16;
1412    }
1413}
1414
1415#[cfg(feature = "defmt")]
1416defmt::bitflags! {
1417    /// Possible LE features for the
1418    /// [LE Read Local Supported Features](::host::Hci::le_read_local_supported_features) command.
1419    /// See the Bluetooth specification, Vol 6, Part B, Section 4.6.  See Table 4.3 (v4.1 of the spec),
1420    /// Table 4.4 (v4.2 and v5.0).
1421    #[derive(Default)]
1422    pub struct LeFeatures : u64 {
1423        /// LE Encryption.  Valid from controller to controller.
1424        const ENCRYPTION = 1 << 0;
1425        /// Connection Parameters Request Procedure.  Valid from controller to controller.
1426        const CONNECTION_PARAMETERS_REQUEST_PROCEDURE = 1 << 1;
1427        /// Extended Reject Indication.  Valid from controller to controller.
1428        const EXTENDED_REJECT_INDICATION = 1 << 2;
1429        /// Peripheral-initiated Features Exchange.  Valid from controller to controller.
1430        const PERIPHERALINITIATED_FEATURES_EXCHANGE = 1 << 3;
1431        /// LE Ping.  Not valid from controller to controller.
1432        const PING = 1 << 4;
1433        /// LE Data Packet Length Extension.  Valid from controller to controller.
1434        const DATA_PACKET_LENGTH_EXTENSION = 1 << 5;
1435        /// LL Privacy.  Not valid from controller to controller.
1436        const LL_PRIVACY = 1 << 6;
1437        /// Extended Scanner Filter Policies.  Not valid from controller to controller.
1438        const EXTENDED_SCANNER_FILTER_POLICIES = 1 << 7;
1439        /// LE 2M PHY.  Valid from controller to controller.
1440        const PHY_2M = 1 << 8;
1441        /// Stable Modulation Index - Transmitter.  Valid from controller to controller.
1442        const STABLE_MODULATION_INDEX_TX = 1 << 9;
1443        /// Stable Modulation Index - Receiver.  Valid from controller to controller.
1444        const STABLE_MODULATION_INDEX_RX = 1 << 10;
1445        /// LE Coded PHY.  Valid from controller to controller.
1446        const CODED_PHY = 1 << 11;
1447        /// LE Extended Advertising.  Not valid from controller to controller.
1448        const EXTENDED_ADVERTISING = 1 << 12;
1449        /// LE Periodic Advertising.  Not valid from controller to controller.
1450        const PERIODIC_ADVERTISING = 1 << 13;
1451        /// Channel Selection Algorithm #2.  Valid from controller to controller.
1452        const CHANNEL_SELECTION_ALGORITHM_2 = 1 << 14;
1453        /// LE Power Class 1.  Valid from controller to controller.
1454        const POWER_CLASS_1 = 1 << 15;
1455        /// Minimum Number of Used Channels Procedure
1456        const MINIMUM_NUMBER_OF_USED_CHANNELS_PROCEDURE = 1 << 16;
1457    }
1458}
1459
1460fn to_le_local_supported_features(
1461    bytes: &[u8],
1462) -> Result<LeSupportedFeatures, crate::event::Error> {
1463    require_len!(bytes, 9);
1464    Ok(LeSupportedFeatures {
1465        status: to_status(bytes)?,
1466        supported_features: LeFeatures::from_bits_truncate(LittleEndian::read_u64(&bytes[1..])),
1467    })
1468}
1469
1470/// Values returned by the
1471/// [LE Read Advertising Channel TX Power](crate::host::HostHci::le_read_advertising_channel_tx_power)
1472/// command.
1473#[derive(Copy, Clone, Debug)]
1474#[cfg_attr(feature = "defmt", derive(defmt::Format))]
1475pub struct LeAdvertisingChannelTxPower {
1476    /// Did the command fail, and if so, how?
1477    pub status: Status,
1478    /// The transmit power of the advertising channel.
1479    ///   - Range: -20 ≤ N ≤ 10 (this is not enforced in this implementation)
1480    ///   - Units: dBm
1481    ///   - Accuracy: ±4 dB
1482    pub power: i8,
1483}
1484
1485fn to_le_advertising_channel_tx_power(
1486    bytes: &[u8],
1487) -> Result<LeAdvertisingChannelTxPower, crate::event::Error> {
1488    require_len!(bytes, 2);
1489    Ok(LeAdvertisingChannelTxPower {
1490        status: to_status(bytes)?,
1491        power: unsafe { mem::transmute::<u8, i8>(bytes[1]) },
1492    })
1493}
1494
1495fn to_le_set_advertise_enable(status: Status) -> ReturnParameters {
1496    ReturnParameters::LeSetAdvertisingEnable(status)
1497}
1498
1499/// Parameters returned by the [LE Read Channel Map](crate::host::HostHci::le_read_channel_map) command.
1500#[derive(Copy, Clone, Debug)]
1501#[cfg_attr(feature = "defmt", derive(defmt::Format))]
1502pub struct ChannelMapParameters {
1503    /// Did the command fail, and if so, how?
1504    pub status: Status,
1505
1506    /// Connection handle whose channel map is returned.
1507    pub conn_handle: ConnectionHandle,
1508
1509    /// Channels that may be used for this connection.
1510    pub channel_map: crate::ChannelClassification,
1511}
1512
1513fn to_le_channel_map_parameters(bytes: &[u8]) -> Result<ChannelMapParameters, crate::event::Error> {
1514    require_len!(bytes, 8);
1515
1516    let mut channel_bits = [0; 5];
1517    channel_bits.copy_from_slice(&bytes[3..8]);
1518    let channel_bits = channel_bits;
1519    Ok(ChannelMapParameters {
1520        status: to_status(&bytes[0..])?,
1521        conn_handle: ConnectionHandle(LittleEndian::read_u16(&bytes[1..])),
1522        channel_map: crate::ChannelClassification::from_bits(&bytes[3..])
1523            .ok_or(crate::event::Error::InvalidChannelMap(channel_bits))?,
1524    })
1525}
1526
1527/// Parameters returned by the [LE Encrypt](crate::host::HostHci::le_encrypt) command.
1528#[derive(Copy, Clone, Debug)]
1529#[cfg_attr(feature = "defmt", derive(defmt::Format))]
1530pub struct EncryptedReturnParameters {
1531    /// Did the command fail, and if so, how?
1532    pub status: Status,
1533
1534    /// Encrypted data block.
1535    ///
1536    /// The most significant octet (last) of the block corresponds to `out[0]` using the notation
1537    /// specified in FIPS 197.
1538    pub encrypted_data: EncryptedBlock,
1539}
1540
1541/// Newtype for a 128-bit encrypted block of data.
1542///
1543/// See [`EncryptedReturnParameters`].
1544#[derive(Copy, Clone)]
1545#[cfg_attr(feature = "defmt", derive(defmt::Format))]
1546pub struct EncryptedBlock(pub [u8; 16]);
1547
1548impl Debug for EncryptedBlock {
1549    fn fmt(&self, f: &mut Formatter) -> FmtResult {
1550        writeln!(f, "AES-128 Encrypted Data ({:X?})", &self.0)
1551    }
1552}
1553
1554fn to_le_encrypted_data(bytes: &[u8]) -> Result<EncryptedReturnParameters, crate::event::Error> {
1555    require_len!(bytes, 17);
1556
1557    let mut block = [0; 16];
1558    block.copy_from_slice(&bytes[1..]);
1559    Ok(EncryptedReturnParameters {
1560        status: to_status(bytes)?,
1561        encrypted_data: EncryptedBlock(block),
1562    })
1563}
1564
1565/// Return parameters for the [LE Rand](crate::host::HostHci::le_rand) command.
1566#[derive(Copy, Clone, Debug)]
1567#[cfg_attr(feature = "defmt", derive(defmt::Format))]
1568pub struct LeRandom {
1569    /// Did the command fail, and if so, how?
1570    pub status: Status,
1571
1572    /// Controller-generated random number.
1573    pub random_number: u64,
1574}
1575
1576fn to_random_number(bytes: &[u8]) -> Result<LeRandom, crate::event::Error> {
1577    require_len!(bytes, 9);
1578
1579    Ok(LeRandom {
1580        status: to_status(bytes)?,
1581        random_number: LittleEndian::read_u64(&bytes[1..]),
1582    })
1583}
1584
1585/// Parameters returned by the
1586/// [LE LTK Request Reply](crate::host::HostHci::le_long_term_key_request_reply) command.
1587#[derive(Copy, Clone, Debug)]
1588#[cfg_attr(feature = "defmt", derive(defmt::Format))]
1589pub struct LeLongTermRequestReply {
1590    /// Did the command fail, and if so, how?
1591    pub status: Status,
1592
1593    /// Connection handle that the request came from
1594    pub conn_handle: ConnectionHandle,
1595}
1596
1597fn to_le_ltk_request_reply(bytes: &[u8]) -> Result<LeLongTermRequestReply, crate::event::Error> {
1598    require_len!(bytes, 3);
1599
1600    Ok(LeLongTermRequestReply {
1601        status: to_status(bytes)?,
1602        conn_handle: ConnectionHandle(LittleEndian::read_u16(&bytes[1..])),
1603    })
1604}
1605
1606/// Parameters returned by the
1607/// [LE Read Supported States](crate::host::HostHci::le_read_supported_states) command.
1608#[derive(Copy, Clone, Debug)]
1609#[cfg_attr(feature = "defmt", derive(defmt::Format))]
1610pub struct LeReadSupportedStates {
1611    /// Did the command fail, and if so, how?
1612    pub status: Status,
1613
1614    /// States or state combinations supported by the Controller. Multiple state and state
1615    /// combinations may be supported.
1616    pub supported_states: LeStates,
1617}
1618
1619#[cfg(not(feature = "defmt"))]
1620bitflags::bitflags! {
1621    /// Possible LE states or state combinations for the
1622    /// [LE Read Supported States](crate::host::HostHci::le_read_supported_states) command.
1623    #[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
1624    pub struct LeStates : u64 {
1625        /// Non-connectable advertising state alone.
1626        const NON_CONNECTABLE_ADVERTISING = 1 << 0;
1627        /// Scannable advertising state alone
1628        const SCANNABLE_ADVERTISING = 1 << 1;
1629        /// Connectable advertising state alone
1630        const CONNECTABLE_ADVERTISING = 1 << 2;
1631        /// Directed advertising (high duty cycle) state alone
1632        const DIRECTED_ADVERTISING_HIGH_DUTY_CYCLE = 1 << 3;
1633        /// Passive scanning state alone
1634        const PASSIVE_SCANNING = 1 << 4;
1635        /// Active scanning state alone
1636        const ACTIVE_SCANNING = 1 << 5;
1637        /// Initianing state alone
1638        const INITIATING = 1 << 6;
1639        /// Peripheral (slave) connection state alone
1640        const PERIPHERAL_CONNECTION = 1 << 7;
1641        /// Non-connectable advertising and passive scan states.
1642        const NONCONN_AD_AND_PASS_SCAN = 1 << 8;
1643        /// Scannable advertising and passive scan states
1644        const SCAN_AD_AND_PASS_SCAN = 1 << 9;
1645        /// Connectable advertising and passive scan states
1646        const CONN_AD_AND_PASS_SCAN = 1 << 10;
1647        /// Directed advertising (high duty cycle) and passive scan states
1648        const DIR_AD_HDC_AND_PASS_SCAN = 1 << 11;
1649        /// Non-connectable advertising and active scan states.
1650        const NONCONN_AD_AND_ACT_SCAN = 1 << 12;
1651        /// Scannable advertising and active scan states
1652        const SCAN_AD_AND_ACT_SCAN = 1 << 13;
1653        /// Connectable advertising and active scan states
1654        const CONN_AD_AND_ACT_SCAN = 1 << 14;
1655        /// Directed advertising (high duty cycle) and active scan states
1656        const DIR_AD_HDC_AND_ACT_SCAN = 1 << 15;
1657        /// Non-connectable advertising and initiating states.
1658        const NONCONN_AD_AND_INITIATING = 1 << 16;
1659        /// Scannable advertising and initiating states
1660        const SCAN_AD_AND_INITIATING = 1 << 17;
1661        /// Non-connectable advertising and central (master) connection states.
1662        const NONCONN_AD_AND_CENTRAL_CONN = 1 << 18;
1663        /// Scannable advertising and central (master) connection states
1664        const SCAN_AD_AND_CENTRAL_CONN = 1 << 19;
1665        /// Non-connectable advertising and peripheral (slave) connection states.
1666        const NONCONN_AD_AND_PERIPH_CONN = 1 << 20;
1667        /// Scannable advertising and peripheral (slave) connection states
1668        const SCAN_AD_AND_PERIPH_CONN = 1 << 21;
1669        /// Passive scan and initiating states
1670        const PASS_SCAN_AND_INITIATING = 1 << 22;
1671        /// Active scan and initiating states
1672        const ACT_SCAN_AND_INITIATING = 1 << 23;
1673        /// Passive scan and central (master) connection states
1674        const PASS_SCAN_AND_CENTRAL_CONN = 1 << 24;
1675        /// Active scan and central (master) connection states
1676        const ACT_SCAN_AND_CENTRAL_CONN = 1 << 25;
1677        /// Passive scan and peripheral (slave) connection states
1678        const PASS_SCAN_AND_PERIPH_CONN = 1 << 26;
1679        /// Active scan and peripheral (slave) connection states
1680        const ACT_SCAN_AND_PERIPH_CONN = 1 << 27;
1681        /// Initiating and central (master) connection states
1682        const INITIATING_AND_CENTRAL_CONN = 1 << 28;
1683        /// Directed advertising (low duty cycle) state alone
1684        const DIRECTED_ADVERTISING_LOW_DUTY_CYCLE = 1 << 29;
1685        /// Directed advertising (low duty cycle) and passive scan states
1686        const DIR_AD_LDC_AND_PASS_SCAN = 1 << 30;
1687        /// Directed advertising (low duty cycle) and active scan states
1688        const DIR_AD_LDC_AND_ACT_SCAN = 1 << 31;
1689        /// Connectable advertising and initiating states
1690        const CONN_AD_AND_INITIATING = 1 << 32;
1691        /// Directed advertising (high duty cycle) and initiating states
1692        const DIR_AD_HDC_AND_INITIATING = 1 << 33;
1693        /// Directed advertising (low duty cycle) and initiating states
1694        const DIR_AD_LDC_AND_INITIATING = 1 << 34;
1695        /// Connectable advertising and central (master) connection states
1696        const CONN_AD_AND_CENTRAL_CONN = 1 << 35;
1697        /// Directed advertising (high duty cycle) and central (master) states
1698        const DIR_AD_HDC_AND_CENTRAL_CONN = 1 << 36;
1699        /// Directed advertising (low duty cycle) and central (master) states
1700        const DIR_AD_LDC_AND_CENTRAL_CONN = 1 << 37;
1701        /// Connectable advertising and peripheral (slave) connection states
1702        const CONN_AD_AND_PERIPH_CONN = 1 << 38;
1703        /// Directed advertising (high duty cycle) and peripheral (slave) states
1704        const DIR_AD_HDC_AND_PERIPH_CONN = 1 << 39;
1705        /// Directed advertising (low duty cycle) and peripheral (slave) states
1706        const DIR_AD_LDC_AND_PERIPH_CONN = 1 << 40;
1707        /// Initiating and peripheral (slave) connection states
1708        const INITIATING_AND_PERIPH_CONN = 1 << 41;
1709    }
1710}
1711
1712#[cfg(feature = "defmt")]
1713defmt::bitflags! {
1714    /// Possible LE states or state combinations for the
1715    /// [LE Read Supported States](crate::host::HostHci::le_read_supported_states) command.
1716    #[derive(Default)]
1717    pub struct LeStates : u64 {
1718        /// Non-connectable advertising state alone.
1719        const NON_CONNECTABLE_ADVERTISING = 1 << 0;
1720        /// Scannable advertising state alone
1721        const SCANNABLE_ADVERTISING = 1 << 1;
1722        /// Connectable advertising state alone
1723        const CONNECTABLE_ADVERTISING = 1 << 2;
1724        /// Directed advertising (high duty cycle) state alone
1725        const DIRECTED_ADVERTISING_HIGH_DUTY_CYCLE = 1 << 3;
1726        /// Passive scanning state alone
1727        const PASSIVE_SCANNING = 1 << 4;
1728        /// Active scanning state alone
1729        const ACTIVE_SCANNING = 1 << 5;
1730        /// Initianing state alone
1731        const INITIATING = 1 << 6;
1732        /// Peripheral (slave) connection state alone
1733        const PERIPHERAL_CONNECTION = 1 << 7;
1734        /// Non-connectable advertising and passive scan states.
1735        const NONCONN_AD_AND_PASS_SCAN = 1 << 8;
1736        /// Scannable advertising and passive scan states
1737        const SCAN_AD_AND_PASS_SCAN = 1 << 9;
1738        /// Connectable advertising and passive scan states
1739        const CONN_AD_AND_PASS_SCAN = 1 << 10;
1740        /// Directed advertising (high duty cycle) and passive scan states
1741        const DIR_AD_HDC_AND_PASS_SCAN = 1 << 11;
1742        /// Non-connectable advertising and active scan states.
1743        const NONCONN_AD_AND_ACT_SCAN = 1 << 12;
1744        /// Scannable advertising and active scan states
1745        const SCAN_AD_AND_ACT_SCAN = 1 << 13;
1746        /// Connectable advertising and active scan states
1747        const CONN_AD_AND_ACT_SCAN = 1 << 14;
1748        /// Directed advertising (high duty cycle) and active scan states
1749        const DIR_AD_HDC_AND_ACT_SCAN = 1 << 15;
1750        /// Non-connectable advertising and initiating states.
1751        const NONCONN_AD_AND_INITIATING = 1 << 16;
1752        /// Scannable advertising and initiating states
1753        const SCAN_AD_AND_INITIATING = 1 << 17;
1754        /// Non-connectable advertising and central (master) connection states.
1755        const NONCONN_AD_AND_CENTRAL_CONN = 1 << 18;
1756        /// Scannable advertising and central (master) connection states
1757        const SCAN_AD_AND_CENTRAL_CONN = 1 << 19;
1758        /// Non-connectable advertising and peripheral (slave) connection states.
1759        const NONCONN_AD_AND_PERIPH_CONN = 1 << 20;
1760        /// Scannable advertising and peripheral (slave) connection states
1761        const SCAN_AD_AND_PERIPH_CONN = 1 << 21;
1762        /// Passive scan and initiating states
1763        const PASS_SCAN_AND_INITIATING = 1 << 22;
1764        /// Active scan and initiating states
1765        const ACT_SCAN_AND_INITIATING = 1 << 23;
1766        /// Passive scan and central (master) connection states
1767        const PASS_SCAN_AND_CENTRAL_CONN = 1 << 24;
1768        /// Active scan and central (master) connection states
1769        const ACT_SCAN_AND_CENTRAL_CONN = 1 << 25;
1770        /// Passive scan and peripheral (slave) connection states
1771        const PASS_SCAN_AND_PERIPH_CONN = 1 << 26;
1772        /// Active scan and peripheral (slave) connection states
1773        const ACT_SCAN_AND_PERIPH_CONN = 1 << 27;
1774        /// Initiating and central (master) connection states
1775        const INITIATING_AND_CENTRAL_CONN = 1 << 28;
1776        /// Directed advertising (low duty cycle) state alone
1777        const DIRECTED_ADVERTISING_LOW_DUTY_CYCLE = 1 << 29;
1778        /// Directed advertising (low duty cycle) and passive scan states
1779        const DIR_AD_LDC_AND_PASS_SCAN = 1 << 30;
1780        /// Directed advertising (low duty cycle) and active scan states
1781        const DIR_AD_LDC_AND_ACT_SCAN = 1 << 31;
1782        /// Connectable advertising and initiating states
1783        const CONN_AD_AND_INITIATING = 1 << 32;
1784        /// Directed advertising (high duty cycle) and initiating states
1785        const DIR_AD_HDC_AND_INITIATING = 1 << 33;
1786        /// Directed advertising (low duty cycle) and initiating states
1787        const DIR_AD_LDC_AND_INITIATING = 1 << 34;
1788        /// Connectable advertising and central (master) connection states
1789        const CONN_AD_AND_CENTRAL_CONN = 1 << 35;
1790        /// Directed advertising (high duty cycle) and central (master) states
1791        const DIR_AD_HDC_AND_CENTRAL_CONN = 1 << 36;
1792        /// Directed advertising (low duty cycle) and central (master) states
1793        const DIR_AD_LDC_AND_CENTRAL_CONN = 1 << 37;
1794        /// Connectable advertising and peripheral (slave) connection states
1795        const CONN_AD_AND_PERIPH_CONN = 1 << 38;
1796        /// Directed advertising (high duty cycle) and peripheral (slave) states
1797        const DIR_AD_HDC_AND_PERIPH_CONN = 1 << 39;
1798        /// Directed advertising (low duty cycle) and peripheral (slave) states
1799        const DIR_AD_LDC_AND_PERIPH_CONN = 1 << 40;
1800        /// Initiating and peripheral (slave) connection states
1801        const INITIATING_AND_PERIPH_CONN = 1 << 41;
1802    }
1803}
1804
1805fn to_le_read_states(bytes: &[u8]) -> Result<LeReadSupportedStates, crate::event::Error> {
1806    require_len!(bytes, 9);
1807
1808    let bitfield = LittleEndian::read_u64(&bytes[1..]);
1809    Ok(LeReadSupportedStates {
1810        status: to_status(bytes)?,
1811        supported_states: LeStates::from_bits(bitfield)
1812            .ok_or(crate::event::Error::InvalidLeStates(bitfield))?,
1813    })
1814}
1815
1816/// Parameters returned by the [LE Test End](crate::host::HostHci::le_test_end) command.
1817#[derive(Copy, Clone, Debug)]
1818#[cfg_attr(feature = "defmt", derive(defmt::Format))]
1819pub struct LeTestEnd {
1820    /// Did the command fail, and if so, how?
1821    pub status: Status,
1822
1823    /// The number of packets received during the test.  For transmitter tests, this value shall be
1824    /// 0.
1825    pub number_of_packets: usize,
1826}
1827
1828fn to_le_test_end(bytes: &[u8]) -> Result<LeTestEnd, crate::event::Error> {
1829    require_len!(bytes, 3);
1830
1831    Ok(LeTestEnd {
1832        status: to_status(bytes)?,
1833        number_of_packets: LittleEndian::read_u16(&bytes[1..]) as usize,
1834    })
1835}