forked from nrfconnect/sdk-zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconn.h
More file actions
3320 lines (3042 loc) · 116 KB
/
conn.h
File metadata and controls
3320 lines (3042 loc) · 116 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/** @file
* @brief Bluetooth connection handling
*/
/*
* Copyright (c) 2015-2016 Intel Corporation
* Copyright (c) 2025 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_BLUETOOTH_CONN_H_
#define ZEPHYR_INCLUDE_BLUETOOTH_CONN_H_
/**
* @brief Connection management
* @defgroup bt_conn Connection management
* @ingroup bluetooth
* @{
*/
#include <stdbool.h>
#include <stdint.h>
#include <zephyr/bluetooth/addr.h>
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/direction.h>
#include <zephyr/bluetooth/gap.h>
#include <zephyr/bluetooth/hci_types.h>
#include <zephyr/net_buf.h>
#include <zephyr/sys/iterable_sections.h>
#include <zephyr/sys/slist.h>
#include <zephyr/sys/util_macro.h>
#include <zephyr/toolchain.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @struct bt_conn
* @brief Opaque type representing a connection to a remote device
*/
struct bt_conn;
/** Connection parameters for LE connections */
struct bt_le_conn_param {
uint16_t interval_min;
uint16_t interval_max;
uint16_t latency;
uint16_t timeout;
};
/** @brief Initialize connection parameters
*
* @param int_min Minimum Connection Interval (N * 1.25 ms)
* @param int_max Maximum Connection Interval (N * 1.25 ms)
* @param lat Connection Latency
* @param to Supervision Timeout (N * 10 ms)
*/
#define BT_LE_CONN_PARAM_INIT(int_min, int_max, lat, to) \
{ \
.interval_min = (int_min), \
.interval_max = (int_max), \
.latency = (lat), \
.timeout = (to), \
}
/** Helper to declare connection parameters inline
*
* @param int_min Minimum Connection Interval (N * 1.25 ms)
* @param int_max Maximum Connection Interval (N * 1.25 ms)
* @param lat Connection Latency
* @param to Supervision Timeout (N * 10 ms)
*/
#define BT_LE_CONN_PARAM(int_min, int_max, lat, to) \
((struct bt_le_conn_param[]) { \
BT_LE_CONN_PARAM_INIT(int_min, int_max, lat, to) \
})
/** Default LE connection parameters:
* Connection Interval: 30-50 ms
* Latency: 0
* Timeout: 4 s
*/
#define BT_LE_CONN_PARAM_DEFAULT \
BT_LE_CONN_PARAM(BT_GAP_INIT_CONN_INT_MIN, BT_GAP_INIT_CONN_INT_MAX, 0, \
BT_GAP_MS_TO_CONN_TIMEOUT(4000))
/** Connection PHY information for LE connections */
struct bt_conn_le_phy_info {
uint8_t tx_phy; /** Connection transmit PHY */
uint8_t rx_phy; /** Connection receive PHY */
};
/** Connection PHY options */
enum {
/** Convenience value when no options are specified. */
BT_CONN_LE_PHY_OPT_NONE = 0,
/** LE Coded using S=2 coding preferred when transmitting. */
BT_CONN_LE_PHY_OPT_CODED_S2 = BIT(0),
/** LE Coded using S=8 coding preferred when transmitting. */
BT_CONN_LE_PHY_OPT_CODED_S8 = BIT(1),
};
/** Preferred PHY parameters for LE connections */
struct bt_conn_le_phy_param {
uint16_t options; /**< Connection PHY options. */
uint8_t pref_tx_phy; /**< Bitmask of preferred transmit PHYs */
uint8_t pref_rx_phy; /**< Bitmask of preferred receive PHYs */
};
/** Initialize PHY parameters
*
* @param _pref_tx_phy Bitmask of preferred transmit PHYs.
* @param _pref_rx_phy Bitmask of preferred receive PHYs.
*/
#define BT_CONN_LE_PHY_PARAM_INIT(_pref_tx_phy, _pref_rx_phy) \
{ \
.options = BT_CONN_LE_PHY_OPT_NONE, \
.pref_tx_phy = (_pref_tx_phy), \
.pref_rx_phy = (_pref_rx_phy), \
}
/** Helper to declare PHY parameters inline
*
* @param _pref_tx_phy Bitmask of preferred transmit PHYs.
* @param _pref_rx_phy Bitmask of preferred receive PHYs.
*/
#define BT_CONN_LE_PHY_PARAM(_pref_tx_phy, _pref_rx_phy) \
((struct bt_conn_le_phy_param []) { \
BT_CONN_LE_PHY_PARAM_INIT(_pref_tx_phy, _pref_rx_phy) \
})
/** Only LE 1M PHY */
#define BT_CONN_LE_PHY_PARAM_1M BT_CONN_LE_PHY_PARAM(BT_GAP_LE_PHY_1M, \
BT_GAP_LE_PHY_1M)
/** Only LE 2M PHY */
#define BT_CONN_LE_PHY_PARAM_2M BT_CONN_LE_PHY_PARAM(BT_GAP_LE_PHY_2M, \
BT_GAP_LE_PHY_2M)
/** Only LE Coded PHY. */
#define BT_CONN_LE_PHY_PARAM_CODED BT_CONN_LE_PHY_PARAM(BT_GAP_LE_PHY_CODED, \
BT_GAP_LE_PHY_CODED)
/** All LE PHYs. */
#define BT_CONN_LE_PHY_PARAM_ALL BT_CONN_LE_PHY_PARAM(BT_GAP_LE_PHY_1M | \
BT_GAP_LE_PHY_2M | \
BT_GAP_LE_PHY_CODED, \
BT_GAP_LE_PHY_1M | \
BT_GAP_LE_PHY_2M | \
BT_GAP_LE_PHY_CODED)
/** Connection data length information for LE connections */
struct bt_conn_le_data_len_info {
/** Maximum Link Layer transmission payload size in bytes. */
uint16_t tx_max_len;
/** Maximum Link Layer transmission payload time in us. */
uint16_t tx_max_time;
/** Maximum Link Layer reception payload size in bytes. */
uint16_t rx_max_len;
/** Maximum Link Layer reception payload time in us. */
uint16_t rx_max_time;
};
/** Connection data length parameters for LE connections */
struct bt_conn_le_data_len_param {
/** Maximum Link Layer transmission payload size in bytes. */
uint16_t tx_max_len;
/** Maximum Link Layer transmission payload time in us. */
uint16_t tx_max_time;
};
/** Initialize transmit data length parameters
*
* @param _tx_max_len Maximum Link Layer transmission payload size in bytes.
* @param _tx_max_time Maximum Link Layer transmission payload time in us.
*/
#define BT_CONN_LE_DATA_LEN_PARAM_INIT(_tx_max_len, _tx_max_time) \
{ \
.tx_max_len = (_tx_max_len), \
.tx_max_time = (_tx_max_time), \
}
/** Helper to declare transmit data length parameters inline
*
* @param _tx_max_len Maximum Link Layer transmission payload size in bytes.
* @param _tx_max_time Maximum Link Layer transmission payload time in us.
*/
#define BT_CONN_LE_DATA_LEN_PARAM(_tx_max_len, _tx_max_time) \
((struct bt_conn_le_data_len_param[]) { \
BT_CONN_LE_DATA_LEN_PARAM_INIT(_tx_max_len, _tx_max_time) \
})
/** Default LE data length parameters. */
#define BT_LE_DATA_LEN_PARAM_DEFAULT \
BT_CONN_LE_DATA_LEN_PARAM(BT_GAP_DATA_LEN_DEFAULT, \
BT_GAP_DATA_TIME_DEFAULT)
/** Maximum LE data length parameters. */
#define BT_LE_DATA_LEN_PARAM_MAX \
BT_CONN_LE_DATA_LEN_PARAM(BT_GAP_DATA_LEN_MAX, \
BT_GAP_DATA_TIME_MAX)
/** Connection subrating parameters for LE connections */
struct bt_conn_le_subrate_param {
/** Minimum subrate factor. */
uint16_t subrate_min;
/** Maximum subrate factor. */
uint16_t subrate_max;
/** Maximum Peripheral latency in units of subrated connection intervals. */
uint16_t max_latency;
/** Minimum number of underlying connection events to remain active
* after a packet containing a Link Layer PDU with a non-zero Length
* field is sent or received.
*/
uint16_t continuation_number;
/** Connection Supervision timeout (N * 10 ms).
* If using @ref bt_conn_le_subrate_set_defaults, this is the
* maximum supervision timeout allowed in requests by a peripheral.
*/
uint16_t supervision_timeout;
};
/** Subrating information for LE connections */
struct bt_conn_le_subrating_info {
/** Connection subrate factor. */
uint16_t factor;
/** Number of underlying connection events to remain active after
* a packet containing a Link Layer PDU with a non-zero Length
* field is sent or received.
*/
uint16_t continuation_number;
};
/** Updated subrating connection parameters for LE connections */
struct bt_conn_le_subrate_changed {
/** HCI Status from LE Subrate Changed event.
* The remaining parameters will be unchanged if status is not
* BT_HCI_ERR_SUCCESS.
*/
uint8_t status;
/** Connection subrate factor. */
uint16_t factor;
/** Number of underlying connection events to remain active after
* a packet containing a Link Layer PDU with a non-zero Length
* field is sent or received.
*/
uint16_t continuation_number;
/** Peripheral latency in units of subrated connection intervals. */
uint16_t peripheral_latency;
/** Connection Supervision timeout (N * 10 ms). */
uint16_t supervision_timeout;
};
/** @brief Maximum Connection Interval Groups possible
*
* The practical maximum is 41 groups based on HCI event size constraints:
* (HCI event max size - cmd_complete overhead - response fields) / sizeof(group)
* (255 - 4 - 3) / 6 = 41 groups max
*/
#define BT_CONN_LE_MAX_CONN_INTERVAL_GROUPS 41
/** @brief Minimum supported connection interval group
*
* Each group represents an arithmetic sequence of supported connection intervals:
* min, min + stride, min + 2 * stride, ..., min + n * stride (where min + n * stride <= max)
*
* Example: min = 10 (1250 us), max = 60 (7500 us), stride = 5 (625 us)
* -> Supported: 1250 us, 1875 us, 2500 us, ..., 6875 us, 7500 us
*/
struct bt_conn_le_min_conn_interval_group {
/** @brief Lower bound of group interval range
*
* Unit: 125 microseconds
*
* Range: @ref BT_HCI_LE_SCI_INTERVAL_MIN_125US - @ref BT_HCI_LE_SCI_INTERVAL_MAX_125US
*/
uint16_t min_125us;
/** @brief Upper bound of group interval range
*
* Unit: 125 microseconds
*
* Range: @ref BT_HCI_LE_SCI_INTERVAL_MIN_125US - @ref BT_HCI_LE_SCI_INTERVAL_MAX_125US
*/
uint16_t max_125us;
/** @brief Increment between consecutive supported intervals
*
* Unit: 125 microseconds
*
* Range: @ref BT_HCI_LE_SCI_STRIDE_MIN_125US - @ref BT_HCI_LE_SCI_INTERVAL_MAX_125US
*/
uint16_t stride_125us;
};
/** Minimum supported connection interval information */
struct bt_conn_le_min_conn_interval_info {
/** @brief Minimum supported connection interval
*
* Unit: microseconds
*
* Range: @ref BT_HCI_LE_MIN_SUPP_CONN_INT_MIN_US - @ref BT_HCI_LE_MIN_SUPP_CONN_INT_MAX_US
*/
uint16_t min_supported_conn_interval_us;
/** @brief Number of interval groups.
*
* Range: 0 - @ref BT_CONN_LE_MAX_CONN_INTERVAL_GROUPS
*
* If zero, the controller only supports Rounded ConnInterval Values (RCV).
*/
uint8_t num_groups;
/** @brief Array of supported connection interval groups.
*
* Multiple groups allow representing non-contiguous or differently-strided ranges.
*/
struct bt_conn_le_min_conn_interval_group groups[BT_CONN_LE_MAX_CONN_INTERVAL_GROUPS];
};
/** Connection rate parameters for LE connections */
struct bt_conn_le_conn_rate_param {
/** @brief Minimum connection interval
*
* Unit: 125 microseconds
*
* Range: @ref BT_HCI_LE_SCI_INTERVAL_MIN_125US - @ref BT_HCI_LE_SCI_INTERVAL_MAX_125US
*/
uint16_t interval_min_125us;
/** @brief Maximum connection interval
*
* Unit: 125 microseconds
*
* Range: @ref BT_HCI_LE_SCI_INTERVAL_MIN_125US - @ref BT_HCI_LE_SCI_INTERVAL_MAX_125US
*/
uint16_t interval_max_125us;
/** @brief Minimum subrate factor
*
* Range: @ref BT_HCI_LE_SUBRATE_FACTOR_MIN - @ref BT_HCI_LE_SUBRATE_FACTOR_MAX
*/
uint16_t subrate_min;
/** @brief Maximum subrate factor
*
* Range: @ref BT_HCI_LE_SUBRATE_FACTOR_MIN - @ref BT_HCI_LE_SUBRATE_FACTOR_MAX
*/
uint16_t subrate_max;
/** @brief Maximum Peripheral latency
*
* Unit: subrated connection intervals @ref bt_conn_le_conn_rate_changed.subrate_factor
*
* Range: @ref BT_HCI_LE_PERIPHERAL_LATENCY_MIN - @ref BT_HCI_LE_PERIPHERAL_LATENCY_MAX
*/
uint16_t max_latency;
/** @brief Minimum number of underlying connection events to remain active
* after a packet containing a Link Layer PDU with a non-zero Length
* field is sent or received.
*
* Range: @ref BT_HCI_LE_CONTINUATION_NUM_MIN - @ref BT_HCI_LE_CONTINUATION_NUM_MAX
*/
uint16_t continuation_number;
/** @brief Connection Supervision timeout
*
* Unit: 10 milliseconds
*
* Range: @ref BT_HCI_LE_SUPERVISION_TIMEOUT_MIN - @ref BT_HCI_LE_SUPERVISION_TIMEOUT_MAX
*/
uint16_t supervision_timeout_10ms;
/** @brief Minimum length of connection event
*
* Unit: 125 microseconds
*
* Range: @ref BT_HCI_LE_SCI_CE_LEN_MIN_125US - @ref BT_HCI_LE_SCI_CE_LEN_MAX_125US
*/
uint16_t min_ce_len_125us;
/** @brief Maximum length of connection event
*
* Unit: 125 microseconds
*
* Range: @ref BT_HCI_LE_SCI_CE_LEN_MIN_125US - @ref BT_HCI_LE_SCI_CE_LEN_MAX_125US
*/
uint16_t max_ce_len_125us;
};
/** Updated connection rate parameters */
struct bt_conn_le_conn_rate_changed {
/** Connection interval
*
* Unit: microseconds
*
* Range: @ref BT_HCI_LE_SCI_INTERVAL_MIN_US - @ref BT_HCI_LE_SCI_INTERVAL_MAX_US
*/
uint32_t interval_us;
/** Connection subrate factor
*
* Range: @ref BT_HCI_LE_SUBRATE_FACTOR_MIN - @ref BT_HCI_LE_SUBRATE_FACTOR_MAX
*/
uint16_t subrate_factor;
/** Peripheral latency
*
* Unit: subrated connection intervals @ref bt_conn_le_conn_rate_changed.subrate_factor
*
* Range: @ref BT_HCI_LE_PERIPHERAL_LATENCY_MIN - @ref BT_HCI_LE_PERIPHERAL_LATENCY_MAX
*/
uint16_t peripheral_latency;
/** Number of underlying connection events to remain active after
* a packet containing a Link Layer PDU with a non-zero Length
* field is sent or received.
*
* Range: @ref BT_HCI_LE_CONTINUATION_NUM_MIN - @ref BT_HCI_LE_CONTINUATION_NUM_MAX
*/
uint16_t continuation_number;
/** Connection Supervision timeout
*
* Unit: 10 milliseconds
*
* Range: @ref BT_HCI_LE_SUPERVISION_TIMEOUT_MIN - @ref BT_HCI_LE_SUPERVISION_TIMEOUT_MAX
*/
uint16_t supervision_timeout_10ms;
};
/** Read all remote features complete callback params */
struct bt_conn_le_read_all_remote_feat_complete {
/** @brief HCI Status from LE Read All Remote Features Complete event.
*
* The remaining parameters will be unchanged if status is not @ref BT_HCI_ERR_SUCCESS.
*/
uint8_t status;
/** Number of pages supported by remote device. */
uint8_t max_remote_page;
/** Number of pages fetched from remote device. */
uint8_t max_valid_page;
/** @brief Pointer to array of size 248, with feature bits of remote supported features.
*
* Page 0 being 8 bytes, with the following 10 pages of 24 bytes.
* Refer to BT_LE_FEAT_BIT_* for values.
* Refer to the BT_FEAT_LE_* macros for value comparison.
* See Bluetooth Core Specification, Vol 6, Part B, Section 4.6.
*/
const uint8_t *features;
};
#define BT_CONN_LE_FRAME_SPACE_TYPES_MASK_ACL_IFS \
(BT_HCI_LE_FRAME_SPACE_UPDATE_SPACING_TYPE_IFS_ACL_CP_MASK | \
BT_HCI_LE_FRAME_SPACE_UPDATE_SPACING_TYPE_IFS_ACL_PC_MASK)
#define BT_CONN_LE_FRAME_SPACE_TYPES_MASK_ACL \
(BT_HCI_LE_FRAME_SPACE_UPDATE_SPACING_TYPE_IFS_ACL_CP_MASK | \
BT_HCI_LE_FRAME_SPACE_UPDATE_SPACING_TYPE_IFS_ACL_PC_MASK | \
BT_HCI_LE_FRAME_SPACE_UPDATE_SPACING_TYPE_MCES_MASK)
#define BT_CONN_LE_FRAME_SPACE_TYPES_MASK_CIS \
(BT_HCI_LE_FRAME_SPACE_UPDATE_SPACING_TYPE_IFS_CIS_MASK | \
BT_HCI_LE_FRAME_SPACE_UPDATE_SPACING_TYPE_MSS_CIS_MASK)
/** Maximum frame space in microseconds.
* As defined in Bluetooth Core Specification, Vol 4, Part E, Section 7.8.151.
*/
#define BT_CONN_LE_FRAME_SPACE_MAX (10000U)
/** Frame space update initiator. */
enum bt_conn_le_frame_space_update_initiator {
/** Initiated by local host */
BT_CONN_LE_FRAME_SPACE_UPDATE_INITIATOR_LOCAL_HOST =
BT_HCI_LE_FRAME_SPACE_UPDATE_INITIATOR_LOCAL_HOST,
/** Initiated by local controller */
BT_CONN_LE_FRAME_SPACE_UPDATE_INITIATOR_LOCAL_CONTROLLER =
BT_HCI_LE_FRAME_SPACE_UPDATE_INITIATOR_LOCAL_CONTROLLER,
/** Initiated by peer */
BT_CONN_LE_FRAME_SPACE_UPDATE_INITIATOR_PEER =
BT_HCI_LE_FRAME_SPACE_UPDATE_INITIATOR_PEER
};
/** Frame space update params */
struct bt_conn_le_frame_space_update_param {
/** Phy mask of the PHYs to be updated.
* Refer to BT_HCI_LE_FRAME_SPACE_UPDATE_PHY_* for values.
*/
uint8_t phys;
/** Spacing types mask of the spacing types to be updated.
* Refer to BT_HCI_LE_FRAME_SPACE_UPDATE_SPACING_TYPE_* and
* BT_CONN_LE_FRAME_SPACE_TYPES_MASK_* for values.
*/
uint16_t spacing_types;
/** Minimum frame space in microseconds.
* Bluetooth Core Specification, Vol 4, Part E, Section 7.8.151
* allows for a range of frame space from 0 to 10000 microseconds.
* The actual supported frame space values will be dependent on
* the controller's capabilities.
*/
uint16_t frame_space_min;
/** Maximum frame space in microseconds.
* Bluetooth Core Specification, Vol 4, Part E, Section 7.8.151
* allows for a range of frame space from 0 to 10000 microseconds.
* The actual supported frame space values will be dependent on
* the controller's capabilities.
*/
uint16_t frame_space_max;
};
/** Frame space updated callback params */
struct bt_conn_le_frame_space_updated {
/** HCI Status from LE Frame Space Update Complete event.
* The remaining parameters will be invalid if status is not
* @ref BT_HCI_ERR_SUCCESS.
*/
uint8_t status;
/** Initiator of the frame space update. */
enum bt_conn_le_frame_space_update_initiator initiator;
/** Updated frame space in microseconds. */
uint16_t frame_space;
/** Phy mask of the PHYs updated.
* Refer to BT_HCI_LE_FRAME_SPACE_UPDATE_PHY_* for values.
*/
uint8_t phys;
/** Spacing types mask of the spacing types updated.
* Refer to BT_HCI_LE_FRAME_SPACE_UPDATE_SPACING_TYPE_* and
* BT_CONN_LE_FRAME_SPACE_TYPES_MASK_* for values.
*/
uint16_t spacing_types;
};
/** Connection Type */
enum __packed bt_conn_type {
/** LE Connection Type */
BT_CONN_TYPE_LE = BIT(0),
/** BR/EDR Connection Type */
BT_CONN_TYPE_BR = BIT(1),
/** SCO Connection Type */
BT_CONN_TYPE_SCO = BIT(2),
/** ISO Connection Type */
BT_CONN_TYPE_ISO = BIT(3),
/** All Connection Type */
BT_CONN_TYPE_ALL = BT_CONN_TYPE_LE | BT_CONN_TYPE_BR |
BT_CONN_TYPE_SCO | BT_CONN_TYPE_ISO,
};
/** Supported AA-Only RTT precision. */
enum bt_conn_le_cs_capability_rtt_aa_only {
/** AA-Only RTT variant is not supported. */
BT_CONN_LE_CS_RTT_AA_ONLY_NOT_SUPP = 0,
/** 10ns time-of-flight accuracy. */
BT_CONN_LE_CS_RTT_AA_ONLY_10NS,
/** 150ns time-of-flight accuracy. */
BT_CONN_LE_CS_RTT_AA_ONLY_150NS,
};
/** Supported Sounding Sequence RTT precision. */
enum bt_conn_le_cs_capability_rtt_sounding {
/** Sounding Sequence RTT variant is not supported. */
BT_CONN_LE_CS_RTT_SOUNDING_NOT_SUPP = 0,
/** 10ns time-of-flight accuracy. */
BT_CONN_LE_CS_RTT_SOUNDING_10NS,
/** 150ns time-of-flight accuracy. */
BT_CONN_LE_CS_RTT_SOUNDING_150NS,
};
/** Supported Random Payload RTT precision. */
enum bt_conn_le_cs_capability_rtt_random_payload {
/** Random Payload RTT variant is not supported. */
BT_CONN_LE_CS_RTT_RANDOM_PAYLOAD_NOT_SUPP = 0,
/** 10ns time-of-flight accuracy. */
BT_CONN_LE_CS_RTT_RANDOM_PAYLOAD_10NS,
/** 150ns time-of-flight accuracy. */
BT_CONN_LE_CS_RTT_RANDOM_PAYLOAD_150NS,
};
/** Remote channel sounding capabilities for LE connections supporting CS */
struct bt_conn_le_cs_capabilities {
/** Number of CS configurations */
uint8_t num_config_supported;
/** Maximum number of consecutive CS procedures.
*
* When set to zero, indicates support for both fixed and indefinite
* numbers of CS procedures before termination.
*/
uint16_t max_consecutive_procedures_supported;
/** Number of antennas. */
uint8_t num_antennas_supported;
/** Maximum number of antenna paths. */
uint8_t max_antenna_paths_supported;
/** Initiator role. */
bool initiator_supported;
/** Reflector role. */
bool reflector_supported;
/** Mode-3 */
bool mode_3_supported;
/** RTT AA-Only */
enum bt_conn_le_cs_capability_rtt_aa_only rtt_aa_only_precision;
/** RTT Sounding */
enum bt_conn_le_cs_capability_rtt_sounding rtt_sounding_precision;
/** RTT Random Payload */
enum bt_conn_le_cs_capability_rtt_random_payload rtt_random_payload_precision;
/** Number of CS steps needed to achieve the
* accuracy requirements for RTT AA Only.
*
* Set to 0 if RTT AA Only isn't supported.
*/
uint8_t rtt_aa_only_n;
/** Number of CS steps needed to achieve the
* accuracy requirements for RTT Sounding.
*
* Set to 0 if RTT Sounding isn't supported
*/
uint8_t rtt_sounding_n;
/** Number of CS steps needed to achieve the
* accuracy requirements for RTT Random Payload.
*
* Set to 0 if RTT Random Payload isn't supported.
*/
uint8_t rtt_random_payload_n;
/** Phase-based normalized attack detector metric
* when a CS_SYNC with sounding sequence is received.
*/
bool phase_based_nadm_sounding_supported;
/** Phase-based normalized attack detector metric
* when a CS_SYNC with random sequence is received.
*/
bool phase_based_nadm_random_supported;
/** CS_SYNC LE 2M PHY. */
bool cs_sync_2m_phy_supported;
/** CS_SYNC LE 2M 2BT PHY. */
bool cs_sync_2m_2bt_phy_supported;
/** Subfeature: CS with no Frequency Actuation Error. */
bool cs_without_fae_supported;
/** Subfeature: Channel Selection Algorithm #3c */
bool chsel_alg_3c_supported;
/** Subfeature: Phase-based Ranging from RTT sounding sequence. */
bool pbr_from_rtt_sounding_seq_supported;
/** Subfeature: IPT in the CS reflector */
bool cs_ipt_reflector;
/** Optional T_IP1 time durations during CS steps.
*
* - Bit 0: 10 us
* - Bit 1: 20 us
* - Bit 2: 30 us
* - Bit 3: 40 us
* - Bit 4: 50 us
* - Bit 5: 60 us
* - Bit 6: 80 us
*/
uint16_t t_ip1_times_supported;
/** Optional T_IP2 time durations during CS steps.
*
* - Bit 0: 10 us
* - Bit 1: 20 us
* - Bit 2: 30 us
* - Bit 3: 40 us
* - Bit 4: 50 us
* - Bit 5: 60 us
* - Bit 6: 80 us
*/
uint16_t t_ip2_times_supported;
/** Optional T_FCS time durations during CS steps.
*
* - Bit 0: 15 us
* - Bit 1: 20 us
* - Bit 2: 30 us
* - Bit 3: 40 us
* - Bit 4: 50 us
* - Bit 5: 60 us
* - Bit 6: 80 us
* - Bit 7: 100 us
* - Bit 8: 120 us
*/
uint16_t t_fcs_times_supported;
/** Optional T_PM time durations during CS steps.
*
* - Bit 0: 10 us
* - Bit 1: 20 us
*/
uint16_t t_pm_times_supported;
/** Time in microseconds for the antenna switch period of the CS tones. */
uint8_t t_sw_time;
/** Supported SNR levels used in RTT packets.
*
* - Bit 0: 18dB
* - Bit 1: 21dB
* - Bit 2: 24dB
* - Bit 3: 27dB
* - Bit 4: 30dB
*/
uint8_t tx_snr_capability;
/** Supported T_IP2_IPT time durations during CS steps.
*
* - Bit 0: 10 us
* - Bit 1: 20 us
* - Bit 2: 30 us
* - Bit 3: 40 us
* - Bit 4: 50 us
* - Bit 5: 60 us
* - Bit 6: 80 us
*/
uint16_t t_ip2_ipt_times_supported;
/** Supported time in microseconds for the antenna switch period of the
* CS tones during IPT.
*
* 0x00, 0x01, 0x02, 0x04, or 0x0A - Time in microseconds for the
* antenna switch period of the CS tones
*/
uint8_t t_sw_ipt_time_supported;
};
/** Remote FAE Table for LE connections supporting CS */
struct bt_conn_le_cs_fae_table {
int8_t *remote_fae_table;
};
/** @brief Extract main mode part from @ref bt_conn_le_cs_mode
*
* @private
*
* @param x @ref bt_conn_le_cs_mode value
* @retval 1 Matches @ref BT_HCI_OP_LE_CS_MAIN_MODE_1 (0x01)
* @retval 2 Matches @ref BT_HCI_OP_LE_CS_MAIN_MODE_2 (0x02)
* @retval 3 Matches @ref BT_HCI_OP_LE_CS_MAIN_MODE_3 (0x03)
*
* @note Returned values match the HCI main mode values.
*/
#define BT_CONN_LE_CS_MODE_MAIN_MODE_PART(x) ((x) & 0x3)
/** @brief Extract sub-mode part from @ref bt_conn_le_cs_mode
*
* @private
*
* @param x @ref bt_conn_le_cs_mode value
* @retval 0 Internal encoding for @ref BT_HCI_OP_LE_CS_SUB_MODE_UNUSED (0xFF)
* @retval 1 Matches @ref BT_HCI_OP_LE_CS_SUB_MODE_1 (0x01)
* @retval 2 Matches @ref BT_HCI_OP_LE_CS_SUB_MODE_2 (0x02)
* @retval 3 Matches @ref BT_HCI_OP_LE_CS_SUB_MODE_3 (0x03)
*
* @note The value 0 encodes HCI 0xFF. This allows @ref bt_conn_le_cs_mode to
* fit in one byte. To obtain the HCI sub-mode value, use `(sub_mode == 0 ? 0xFF
* : sub_mode)`, where `sub_mode` is the value returned by this macro.
*/
#define BT_CONN_LE_CS_MODE_SUB_MODE_PART(x) (((x) >> 4) & 0x3)
/** @brief Channel sounding mode (main and sub-mode)
*
* Represents the combination of Channel Sounding (CS) main mode and sub-mode.
*
* @note The underlying numeric values are an internal encoding and are
* not stable API. Do not assume a direct concatenation of HCI values
* when inspecting the raw enum value.
*
* @sa BT_CONN_LE_CS_MODE_MAIN_MODE_PART
* @sa BT_CONN_LE_CS_MODE_SUB_MODE_PART
*/
enum bt_conn_le_cs_mode {
/** Main mode 1 (RTT), sub-mode: unused */
BT_CONN_LE_CS_MAIN_MODE_1_NO_SUB_MODE = BT_HCI_OP_LE_CS_MAIN_MODE_1,
/** Main mode 2 (PBR), sub-mode: unused */
BT_CONN_LE_CS_MAIN_MODE_2_NO_SUB_MODE = BT_HCI_OP_LE_CS_MAIN_MODE_2,
/** Main mode 3 (RTT and PBR), sub-mode: unused */
BT_CONN_LE_CS_MAIN_MODE_3_NO_SUB_MODE = BT_HCI_OP_LE_CS_MAIN_MODE_3,
/** Main mode 2 (PBR), sub-mode 1 (RTT) */
BT_CONN_LE_CS_MAIN_MODE_2_SUB_MODE_1 = BT_HCI_OP_LE_CS_MAIN_MODE_2 |
(BT_HCI_OP_LE_CS_SUB_MODE_1 << 4),
/** Main mode 2 (PBR), sub-mode 3 (RTT and PBR) */
BT_CONN_LE_CS_MAIN_MODE_2_SUB_MODE_3 = BT_HCI_OP_LE_CS_MAIN_MODE_2 |
(BT_HCI_OP_LE_CS_SUB_MODE_3 << 4),
/** Main mode 3 (RTT and PBR), sub-mode 2 (PBR) */
BT_CONN_LE_CS_MAIN_MODE_3_SUB_MODE_2 = BT_HCI_OP_LE_CS_MAIN_MODE_3 |
(BT_HCI_OP_LE_CS_SUB_MODE_2 << 4),
};
/** Channel sounding role */
enum bt_conn_le_cs_role {
/** CS initiator role */
BT_CONN_LE_CS_ROLE_INITIATOR,
/** CS reflector role */
BT_CONN_LE_CS_ROLE_REFLECTOR,
};
/** Channel sounding RTT type */
enum bt_conn_le_cs_rtt_type {
/** RTT AA only */
BT_CONN_LE_CS_RTT_TYPE_AA_ONLY = BT_HCI_OP_LE_CS_RTT_TYPE_AA_ONLY,
/** RTT with 32-bit sounding sequence */
BT_CONN_LE_CS_RTT_TYPE_32_BIT_SOUNDING = BT_HCI_OP_LE_CS_RTT_TYPE_32BIT_SOUND,
/** RTT with 96-bit sounding sequence */
BT_CONN_LE_CS_RTT_TYPE_96_BIT_SOUNDING = BT_HCI_OP_LE_CS_RTT_TYPE_96BIT_SOUND,
/** RTT with 32-bit random sequence */
BT_CONN_LE_CS_RTT_TYPE_32_BIT_RANDOM = BT_HCI_OP_LE_CS_RTT_TYPE_32BIT_RAND,
/** RTT with 64-bit random sequence */
BT_CONN_LE_CS_RTT_TYPE_64_BIT_RANDOM = BT_HCI_OP_LE_CS_RTT_TYPE_64BIT_RAND,
/** RTT with 96-bit random sequence */
BT_CONN_LE_CS_RTT_TYPE_96_BIT_RANDOM = BT_HCI_OP_LE_CS_RTT_TYPE_96BIT_RAND,
/** RTT with 128-bit random sequence */
BT_CONN_LE_CS_RTT_TYPE_128_BIT_RANDOM = BT_HCI_OP_LE_CS_RTT_TYPE_128BIT_RAND,
};
/** Channel sounding PHY used for CS sync */
enum bt_conn_le_cs_sync_phy {
/** LE 1M PHY */
BT_CONN_LE_CS_SYNC_1M_PHY = BT_HCI_OP_LE_CS_CS_SYNC_1M,
/** LE 2M PHY */
BT_CONN_LE_CS_SYNC_2M_PHY = BT_HCI_OP_LE_CS_CS_SYNC_2M,
/** LE 2M 2BT PHY */
BT_CONN_LE_CS_SYNC_2M_2BT_PHY = BT_HCI_OP_LE_CS_CS_SYNC_2M_2BT,
};
/** Channel sounding channel selection type */
enum bt_conn_le_cs_chsel_type {
/** Use Channel Selection Algorithm #3b for non-mode-0 CS steps */
BT_CONN_LE_CS_CHSEL_TYPE_3B = BT_HCI_OP_LE_CS_TEST_CHSEL_TYPE_3B,
/** Use Channel Selection Algorithm #3c for non-mode-0 CS steps */
BT_CONN_LE_CS_CHSEL_TYPE_3C = BT_HCI_OP_LE_CS_TEST_CHSEL_TYPE_3C,
};
/** Channel sounding channel sequence shape */
enum bt_conn_le_cs_ch3c_shape {
/** Use Hat shape for user-specified channel sequence */
BT_CONN_LE_CS_CH3C_SHAPE_HAT = BT_HCI_OP_LE_CS_TEST_CH3C_SHAPE_HAT,
/** Use X shape for user-specified channel sequence */
BT_CONN_LE_CS_CH3C_SHAPE_X = BT_HCI_OP_LE_CS_TEST_CH3C_SHAPE_X,
};
/** Channel sounding configuration */
struct bt_conn_le_cs_config {
/** CS configuration ID */
uint8_t id;
/** CS main and sub mode */
enum bt_conn_le_cs_mode mode;
/** Minimum number of CS main mode steps to be executed before a submode step is executed */
uint8_t min_main_mode_steps;
/** Maximum number of CS main mode steps to be executed before a submode step is executed */
uint8_t max_main_mode_steps;
/** Number of main mode steps taken from the end of the last CS subevent to be repeated
* at the beginning of the current CS subevent directly after the last mode-0 step of that
* event
*/
uint8_t main_mode_repetition;
/** Number of CS mode-0 steps to be included at the beginning of each CS subevent */
uint8_t mode_0_steps;
/** CS role */
enum bt_conn_le_cs_role role;
/** RTT type */
enum bt_conn_le_cs_rtt_type rtt_type;
/** CS Sync PHY */
enum bt_conn_le_cs_sync_phy cs_sync_phy;
/** The number of times the Channel_Map field will be cycled through for non-mode-0 steps
* within a CS procedure
*/
uint8_t channel_map_repetition;
/** Channel selection type */
enum bt_conn_le_cs_chsel_type channel_selection_type;
/** User-specified channel sequence shape */
enum bt_conn_le_cs_ch3c_shape ch3c_shape;
/** Number of channels skipped in each rising and falling sequence */
uint8_t ch3c_jump;
/** CS enhancements 1
* Bit 0 - IPT is enabled in the CS reflector.
* All other bits are reserved and shall be set to 0.
*/
uint8_t cs_enhancements_1;
/** Interlude time in microseconds between the RTT packets */
uint8_t t_ip1_time_us;
/** Interlude time in microseconds between the CS tones */
uint8_t t_ip2_time_us;
/** Time in microseconds for frequency changes */
uint8_t t_fcs_time_us;
/** Time in microseconds for the phase measurement period of the CS tones */
uint8_t t_pm_time_us;
/** Channel map used for CS procedure
* Channels n = 0, 1, 23, 24, 25, 77, and 78 are not allowed and shall be set to zero.
* Channel 79 is reserved for future use and shall be set to zero.
* At least 15 channels shall be enabled.
*/
uint8_t channel_map[10];
};
/** Procedure done status */
enum bt_conn_le_cs_procedure_done_status {
BT_CONN_LE_CS_PROCEDURE_COMPLETE = BT_HCI_LE_CS_PROCEDURE_DONE_STATUS_COMPLETE,
BT_CONN_LE_CS_PROCEDURE_INCOMPLETE = BT_HCI_LE_CS_PROCEDURE_DONE_STATUS_PARTIAL,
BT_CONN_LE_CS_PROCEDURE_ABORTED = BT_HCI_LE_CS_PROCEDURE_DONE_STATUS_ABORTED,
};
/** Subevent done status */
enum bt_conn_le_cs_subevent_done_status {
BT_CONN_LE_CS_SUBEVENT_COMPLETE = BT_HCI_LE_CS_SUBEVENT_DONE_STATUS_COMPLETE,
BT_CONN_LE_CS_SUBEVENT_ABORTED = BT_HCI_LE_CS_SUBEVENT_DONE_STATUS_ABORTED,
};
/** Procedure abort reason */
enum bt_conn_le_cs_procedure_abort_reason {
BT_CONN_LE_CS_PROCEDURE_NOT_ABORTED = BT_HCI_LE_CS_PROCEDURE_ABORT_REASON_NO_ABORT,
BT_CONN_LE_CS_PROCEDURE_ABORT_REQUESTED =
BT_HCI_LE_CS_PROCEDURE_ABORT_REASON_LOCAL_HOST_OR_REMOTE_REQUEST,
BT_CONN_LE_CS_PROCEDURE_ABORT_TOO_FEW_CHANNELS =
BT_HCI_LE_CS_PROCEDURE_ABORT_REASON_TOO_FEW_CHANNELS,
BT_CONN_LE_CS_PROCEDURE_ABORT_CHMAP_INSTANT_PASSED =
BT_HCI_LE_CS_PROCEDURE_ABORT_REASON_CHMAP_INSTANT_PASSED,
BT_CONN_LE_CS_PROCEDURE_ABORT_UNSPECIFIED = BT_HCI_LE_CS_PROCEDURE_ABORT_REASON_UNSPECIFIED,
};
/** Subevent abort reason */
enum bt_conn_le_cs_subevent_abort_reason {
BT_CONN_LE_CS_SUBEVENT_NOT_ABORTED = BT_HCI_LE_CS_SUBEVENT_ABORT_REASON_NO_ABORT,
BT_CONN_LE_CS_SUBEVENT_ABORT_REQUESTED =
BT_HCI_LE_CS_SUBEVENT_ABORT_REASON_LOCAL_HOST_OR_REMOTE_REQUEST,
BT_CONN_LE_CS_SUBEVENT_ABORT_NO_CS_SYNC =
BT_HCI_LE_CS_SUBEVENT_ABORT_REASON_NO_CS_SYNC_RECEIVED,
BT_CONN_LE_CS_SUBEVENT_ABORT_SCHED_CONFLICT =
BT_HCI_LE_CS_SUBEVENT_ABORT_REASON_SCHED_CONFLICT,
BT_CONN_LE_CS_SUBEVENT_ABORT_UNSPECIFIED = BT_HCI_LE_CS_SUBEVENT_ABORT_REASON_UNSPECIFIED,
};
/** Subevent data for LE connections supporting CS */
struct bt_conn_le_cs_subevent_result {
struct {
/** CS configuration identifier.
*
* Range: 0 to 3
*
* If these results were generated by a CS Test,
* this value will be set to 0 and has no meaning.
*/
uint8_t config_id;
/** Starting ACL connection event counter.
*
* If these results were generated by a CS Test,
* this value will be set to 0 and has no meaning.
*/
uint16_t start_acl_conn_event;
/** CS procedure count associated with these results.
*
* This is the CS procedure count since the completion of
* the Channel Sounding Security Start procedure.
*/
uint16_t procedure_counter;
/** Frequency compensation value in units of 0.01 ppm.
*
* This is a 15-bit signed integer in the range [-100, 100] ppm.
*
* A value of @ref BT_HCI_LE_CS_SUBEVENT_RESULT_FREQ_COMPENSATION_NOT_AVAILABLE
* indicates that the role is not the initiator, or that the
* frequency compensation value is unavailable.
*/
uint16_t frequency_compensation;
/** Reference power level in dBm.
*
* Range: -127 to 20
*
* A value of @ref BT_HCI_LE_CS_REF_POWER_LEVEL_UNAVAILABLE indicates
* that the reference power level was not available during a subevent.
*/
int8_t reference_power_level;
/** Procedure status. */
enum bt_conn_le_cs_procedure_done_status procedure_done_status;
/** Subevent status
*
* For aborted subevents, this will be set to @ref BT_CONN_LE_CS_SUBEVENT_ABORTED
* and abort_step will contain the step number on which the subevent was aborted.
* Consider the following example:
*
* subevent_done_status = @ref BT_CONN_LE_CS_SUBEVENT_ABORTED
* num_steps_reported = 160
* abort_step = 100
*
* this would mean that steps from 0 to 99 are complete and steps from 100 to 159
* are aborted.
*/
enum bt_conn_le_cs_subevent_done_status subevent_done_status;
/** Abort reason.
*
* If the procedure status is
* @ref BT_CONN_LE_CS_PROCEDURE_ABORTED, this field will
* specify the reason for the abortion.
*/
enum bt_conn_le_cs_procedure_abort_reason procedure_abort_reason;
/** Abort reason.
*
* If the subevent status is
* @ref BT_CONN_LE_CS_SUBEVENT_ABORTED, this field will
* specify the reason for the abortion.
*/
enum bt_conn_le_cs_subevent_abort_reason subevent_abort_reason;
/** Number of antenna paths used during the phase measurement stage.
*/
uint8_t num_antenna_paths;
/** Number of CS steps in the subevent.
*/
uint8_t num_steps_reported;
/** Step number, on which the subevent was aborted
* if subevent_done_status is @ref BT_CONN_LE_CS_SUBEVENT_COMPLETE
* then abort_step will be unused and set to 255
*/
uint8_t abort_step;
} header;
/** Pointer to buffer containing step data.
* NULL if num_steps_reported is 0.
*/
struct net_buf_simple *step_data_buf;
};
/** @brief Increment a connection's reference count.
*
* Increment the reference count of a connection object.
*