Skip to main content

bt_hci/param/
classic.rs

1use crate::param::macros::param;
2use crate::param::{BdAddr, ConnHandle};
3
4param! {
5    bitfield PacketType[2] {
6        // ACL Link_Type bits
7        (1, shall_not_be_used_2dh1, set_shall_not_be_used_2dh1);
8        (2, shall_not_be_used_3dh1, set_shall_not_be_used_3dh1);
9        // Bit 3: Ignored; DM1 may be used whether or not this bit is set
10        (4, dh1_may_be_used, set_dh1_may_be_used);
11        // SCO Link_Type bits
12        (5, hv1_may_be_used, set_hv1_may_be_used);
13        (6, hv2_may_be_used, set_hv2_may_be_used);
14        (7, hv3_may_be_used, set_hv3_may_be_used);
15        // ACL Link_Type bits (continued)
16        (8, shall_not_be_used_2dh3, set_shall_not_be_used_2dh3);
17        (9, shall_not_be_used_3dh3, set_shall_not_be_used_3dh3);
18        (10, dm3_may_be_used, set_dm3_may_be_used);
19        (11, dh3_may_be_used, set_dh3_may_be_used);
20        (12, shall_not_be_used_2dh5, set_shall_not_be_used_2dh5);
21        (13, shall_not_be_used_3dh5, set_shall_not_be_used_3dh5);
22        (14, dm5_may_be_used, set_dm5_may_be_used);
23        (15, dh5_may_be_used, set_dh5_may_be_used);
24    }
25}
26
27param! {
28    bitfield SyncPacketType[2]{
29        // Basic synchronous packet types
30        (0, hv1_may_be_used, set_hv1_may_be_used);
31        (1, hv2_may_be_used, set_hv2_may_be_used);
32        (2, hv3_may_be_used, set_hv3_may_be_used);
33        // Extended synchronous packet types
34        (3, ev3_may_be_used, set_ev3_may_be_used);
35        (4, ev4_may_be_used, set_ev4_may_be_used);
36        (5, ev5_may_be_used, set_ev5_may_be_used);
37        // EDR synchronous packet types that shall not be used
38        (6, shall_not_be_used_2ev3, set_shall_not_be_used_2ev3);
39        (7, shall_not_be_used_3ev3, set_shall_not_be_used_3ev3);
40        (8, shall_not_be_used_2ev5, set_shall_not_be_used_2ev5);
41        (9, shall_not_be_used_3ev5, set_shall_not_be_used_3ev5);
42        // All other bits reserved for future use
43    }
44}
45
46param! {
47    bitfield ClockOffset[2] {
48        // Bits 0-14: Bits 2 to 16 of CLKNPeripheral - CLK
49        (0, clock_offset_0, set_clock_offset_0);
50        (1, clock_offset_1, set_clock_offset_1);
51        (2, clock_offset_2, set_clock_offset_2);
52        (3, clock_offset_3, set_clock_offset_3);
53        (4, clock_offset_4, set_clock_offset_4);
54        (5, clock_offset_5, set_clock_offset_5);
55        (6, clock_offset_6, set_clock_offset_6);
56        (7, clock_offset_7, set_clock_offset_7);
57        (8, clock_offset_8, set_clock_offset_8);
58        (9, clock_offset_9, set_clock_offset_9);
59        (10, clock_offset_10, set_clock_offset_10);
60        (11, clock_offset_11, set_clock_offset_11);
61        (12, clock_offset_12, set_clock_offset_12);
62        (13, clock_offset_13, set_clock_offset_13);
63        (14, clock_offset_14, set_clock_offset_14);
64        // Bit 15: Clock_Offset_Valid_Flag (0 = Invalid, 1 = Valid)
65        (15, clock_offset_valid_flag, set_clock_offset_valid_flag);
66    }
67}
68
69param! {
70    bitfield VoiceSetting[2]{
71        // Bits 0-1: Air coding format
72        (0, air_coding_format_0, set_air_coding_format_0);
73        (1, air_coding_format_1, set_air_coding_format_1);
74        // Bits 2-4: Linear PCM bit position
75        (2, linear_pcm_bit_position_0, set_linear_pcm_bit_position_0);
76        (3, linear_pcm_bit_position_1, set_linear_pcm_bit_position_1);
77        (4, linear_pcm_bit_position_2, set_linear_pcm_bit_position_2);
78        // Bit 5: Input sample size (only for linear PCM)
79        (5, input_sample_size, set_input_sample_size);
80        // Bits 6-7: Input data format
81        (6, input_data_format_0, set_input_data_format_0);
82        (7, input_data_format_1, set_input_data_format_1);
83        // Bits 8-9: Input coding format
84        (8, input_coding_format_0, set_input_coding_format_0);
85        (9, input_coding_format_1, set_input_coding_format_1);
86        // Bits 10-15: Reserved for future use
87    }
88}
89
90param! {
91    enum PageScanRepetitionMode{
92        /// Page scan repetition mode 0
93        R0 = 0x00,
94        /// Page scan repetition mode 1
95        R1 = 0x01,
96        /// Page scan repetition mode 2
97        R2 = 0x02,
98        // Reserved for future use
99    }
100}
101
102param! {
103    enum AllowRoleSwitch{
104        /// The local device will be a Central, and will not accept a role switch requested by
105        /// the remote device at the connection setup.
106        NotAllowed = 0x00,
107        /// The local device may be a Central, or may become a Peripheral after accepting a role switch
108        /// requested by the remote device at the connection setup.
109        Allowed = 0x01,
110        // Reserved for future use
111    }
112}
113
114param! {
115    enum ConnectionLinkType {
116        /// SCO connection
117        Sco = 0x00,
118        /// ACL connection (Data Channels)
119        Acl = 0x01,
120        /// eSCO connection (Enhanced Data Channels)
121        EnhancedSco = 0x02,
122        // All other values reserved for future use
123    }
124}
125
126param! {
127    enum LinkKeyType {
128        /// Combination Key
129        CombinationKey = 0x00,
130        /// Debug Combination Key
131        DebugCombinationKey = 0x03,
132        /// Unauthenticated Combination Key generated from P-192
133        UnauthenticatedCombinationKeyP192 = 0x04,
134        /// Authenticated Combination Key generated from P-192
135        AuthenticatedCombinationKeyP192 = 0x05,
136        /// Changed Combination Key
137        ChangedCombinationKey = 0x06,
138        /// Unauthenticated Combination Key generated from P-256
139        UnauthenticatedCombinationKeyP256 = 0x07,
140        /// Authenticated Combination Key generated from P-256
141        AuthenticatedCombinationKeyP256 = 0x08,
142        // All other values reserved for future use
143    }
144}
145
146param! {
147    enum IoCapability{
148        /// Display Only
149        DisplayOnly = 0x00,
150        /// Display Yes/No
151        DisplayYesNo = 0x01,
152        /// Keyboard Only
153        KeyboardOnly = 0x02,
154        /// No Input No Output
155        NoInputNoOutput = 0x03,
156        // All other values reserved for future use
157    }
158}
159
160param! {
161    enum OobDataPresent {
162        /// OOB authentication data not present
163        NotPresent = 0x00,
164        /// P-192 OOB authentication data from remote device present
165        P192Present = 0x01,
166        /// P-256 OOB authentication data from remote device present
167        P256Present = 0x02,
168        /// P-192 and P-256 OOB authentication data from remote device present
169        P192AndP256Present = 0x03,
170        // All other values reserved for future use
171    }
172}
173
174param! {
175    enum AuthenticationRequirements {
176        /// MITM Protection Not Required – No Bonding. Numeric comparison with automatic accept allowed.
177        MitmNotRequiredNoBonding = 0x00,
178        /// MITM Protection Required – No Bonding. Use IO Capabilities to determine authentication procedure
179        MitmRequiredNoBonding = 0x01,
180        /// MITM Protection Not Required – Dedicated Bonding. Numeric comparison with automatic accept allowed.
181        MitmNotRequiredDedicatedBonding = 0x02,
182        /// MITM Protection Required – Dedicated Bonding. Use IO Capabilities to determine authentication procedure
183        MitmRequiredDedicatedBonding = 0x03,
184        /// MITM Protection Not Required – General Bonding. Numeric Comparison with automatic accept allowed.
185        MitmNotRequiredGeneralBonding = 0x04,
186        /// MITM Protection Required – General Bonding. Use IO capabilities to determine authentication procedure.
187        MitmRequiredGeneralBonding = 0x05,
188        // All other values reserved for future use
189    }
190}
191
192param! {
193    enum Role {
194        /// Become the Central for this connection. The LM will perform the role switch.
195        Central = 0x00,
196        /// Remain the Peripheral for this connection. The LM will NOT perform the role switch.
197        Peripheral = 0x01,
198    }
199}
200
201param! {
202    enum RejectReason {
203        /// Connection Rejected due to Limited Resources
204        LimitedResources = 0x0D,
205        /// Connection Rejected Due To Security Reasons
206        SecurityReasons = 0x0E,
207        /// Connection Rejected due to Unacceptable BD_ADDR
208        UnacceptableBdAddr = 0x0F,
209    }
210}
211
212param! {
213    enum KeyFlag{
214        /// Use semi-permanent Link Keys.
215        SemiPermanent = 0x00,
216        /// Use Temporary Link Key.
217        Temporary = 0x01,
218    }
219}
220
221param! {
222    enum RetransmissionEffort{
223        /// No retransmissions (SCO or eSCO connection allowed)
224        NoRetransmissions = 0x00,
225        /// At least one retransmission, optimize for power consumption (eSCO connection required)
226        OptimizePowerConsumption = 0x01,
227        /// At least one retransmission, optimize for link quality (eSCO connection required)
228        OptimizeLinkQuality = 0x02,
229        /// Don't care (SCO or eSCO connection allowed)
230        DontCare = 0xFF,
231        // All other values reserved for future use
232    }
233}
234
235param! {
236    enum ServiceType{
237        /// No Traffic Available.
238        NoTraffic = 0x00,
239        /// Best Effort Available.
240        BestEffort = 0x01,
241        /// Guaranteed Available.
242        Guaranteed = 0x02,
243        // All other values reserved for future use
244    }
245}
246
247param! {
248    enum Mode {
249        /// Active mode
250        Active = 0x00,
251        /// Hold mode
252        Hold = 0x01,
253        /// Sniff mode
254        Sniff = 0x02,
255        // All other values reserved for future use
256    }
257}
258
259param! {
260    enum MaxSlots {
261        /// 1 slot
262        OneSlot = 0x01,
263        /// 3 slots
264        ThreeSlots = 0x03,
265        /// 5 slots
266        FiveSlots = 0x05,
267        // All other values reserved for future use
268    }
269}
270
271param! {
272    enum FlowDirection {
273        /// Outgoing Flow i.e., traffic sent over the ACL connection.
274        Outgoing = 0x00,
275        /// Incoming Flow i.e., traffic received over the ACL connection.
276        Incoming = 0x01,
277        // All other values reserved for future use
278    }
279}
280
281param! {
282    enum KeypressNotificationType {
283        /// Passkey entry started
284        PasskeyEntryStarted = 0x00,
285        /// Passkey digit entered
286        PasskeyDigitEntered = 0x01,
287        /// Passkey digit erased
288        PasskeyDigitErased = 0x02,
289        /// Passkey cleared
290        PasskeyCleared = 0x03,
291        /// Passkey entry completed
292        PasskeyEntryCompleted = 0x04,
293        // All other values reserved for future use
294    }
295}
296
297param! {
298    enum ClockType {
299        /// Local clock
300        Local = 0x00,
301        /// Piconet Clock
302        Piconet = 0x01,
303        // All other values reserved for future use
304    }
305}
306
307param! {
308    enum EncryptionEnabledLevel {
309        /// Link Level Encryption is OFF
310        Off = 0x00,
311        /// Link Level Encryption is ON with E0 for BR/EDR or AES-CCM for LE
312        OnE0OrAesCcm = 0x01,
313        /// Link Level Encryption is ON with AES-CCM for BR/EDR
314        OnAesCcm = 0x02,
315        // All other values reserved for future use
316    }
317}
318
319param! {
320    /// Separate params for the Enhanced Setup Synchronous Connection command since they have too many fields
321    struct EnhancedSetupSynchronousConnectionParams {
322        handle: ConnHandle,
323        transmit_bandwidth: u32,
324        receive_bandwidth: u32,
325        transmit_coding_format: [u8; 5],
326        receive_coding_format: [u8; 5],
327        transmit_codec_frame_size: u16,
328        receive_codec_frame_size: u16,
329        input_bandwidth: u32,
330        output_bandwidth: u32,
331        input_coding_format: [u8; 5],
332        output_coding_format: [u8; 5],
333        input_coded_data_size: u16,
334        output_coded_data_size: u16,
335        input_pcm_data_format: u8,
336        output_pcm_data_format: u8,
337        input_pcm_sample_payload_msb_position: u8,
338        output_pcm_sample_payload_msb_position: u8,
339        input_data_path: u8,
340        output_data_path: u8,
341        input_transport_unit_size: u8,
342        output_transport_unit_size: u8,
343        max_latency: u16,
344        packet_type: SyncPacketType,
345        retransmission_effort: RetransmissionEffort,
346    }
347}
348
349param! {
350    /// Separate params for the Enhanced Accept Synchronous Connection Request command since they have too many fields
351    struct EnhancedAcceptSynchronousConnectionRequestParams {
352        bd_addr: BdAddr,
353        transmit_bandwidth: u32,
354        receive_bandwidth: u32,
355        transmit_coding_format: [u8; 5],
356        receive_coding_format: [u8; 5],
357        transmit_codec_frame_size: u16,
358        receive_codec_frame_size: u16,
359        input_bandwidth: u32,
360        output_bandwidth: u32,
361        input_coding_format: [u8; 5],
362        output_coding_format: [u8; 5],
363        input_coded_data_size: u16,
364        output_coded_data_size: u16,
365        input_pcm_data_format: u8,
366        output_pcm_data_format: u8,
367        input_pcm_sample_payload_msb_position: u8,
368        output_pcm_sample_payload_msb_position: u8,
369        input_data_path: u8,
370        output_data_path: u8,
371        input_transport_unit_size: u8,
372        output_transport_unit_size: u8,
373        max_latency: u16,
374        packet_type: SyncPacketType,
375        retransmission_effort: RetransmissionEffort,
376    }
377}