/
bluetooth.h
2687 lines (2393 loc) · 85.3 KB
/
bluetooth.h
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 subsystem core APIs.
*/
/*
* Copyright (c) 2017 Nordic Semiconductor ASA
* Copyright (c) 2015-2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_BLUETOOTH_BLUETOOTH_H_
#define ZEPHYR_INCLUDE_BLUETOOTH_BLUETOOTH_H_
/**
* @brief Bluetooth APIs
* @defgroup bluetooth Bluetooth APIs
* @ingroup connectivity
* @{
*/
#include <stdbool.h>
#include <string.h>
#include <zephyr/sys/util.h>
#include <zephyr/net/buf.h>
#include <zephyr/bluetooth/gap.h>
#include <zephyr/bluetooth/addr.h>
#include <zephyr/bluetooth/crypto.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Generic Access Profile (GAP)
* @defgroup bt_gap Generic Access Profile (GAP)
* @since 1.0
* @version 1.0.0
* @ingroup bluetooth
* @{
*/
/**
* Convenience macro for specifying the default identity. This helps
* make the code more readable, especially when only one identity is
* supported.
*/
#define BT_ID_DEFAULT 0
/** Opaque type representing an advertiser. */
struct bt_le_ext_adv;
/** Opaque type representing an periodic advertising sync. */
struct bt_le_per_adv_sync;
/* Don't require everyone to include conn.h */
struct bt_conn;
/* Don't require everyone to include iso.h */
struct bt_iso_biginfo;
/* Don't require everyone to include direction.h */
struct bt_df_per_adv_sync_iq_samples_report;
struct bt_le_ext_adv_sent_info {
/** The number of advertising events completed. */
uint8_t num_sent;
};
struct bt_le_ext_adv_connected_info {
/** Connection object of the new connection */
struct bt_conn *conn;
};
struct bt_le_ext_adv_scanned_info {
/** Active scanner LE address and type */
bt_addr_le_t *addr;
};
struct bt_le_per_adv_data_request {
/** The first subevent data can be set for */
uint8_t start;
/** The number of subevents data can be set for */
uint8_t count;
};
struct bt_le_per_adv_response_info {
/** The subevent the response was received in */
uint8_t subevent;
/** @brief Status of the subevent indication.
*
* 0 if subevent indication was transmitted.
* 1 if subevent indication was not transmitted.
* All other values RFU.
*/
uint8_t tx_status;
/** The TX power of the response in dBm */
int8_t tx_power;
/** The RSSI of the response in dBm */
int8_t rssi;
/** The Constant Tone Extension (CTE) of the advertisement (@ref bt_df_cte_type) */
uint8_t cte_type;
/** The slot the response was received in */
uint8_t response_slot;
};
struct bt_le_ext_adv_cb {
/**
* @brief The advertising set has finished sending adv data.
*
* This callback notifies the application that the advertising set has
* finished sending advertising data.
* The advertising set can either have been stopped by a timeout or
* because the specified number of advertising events has been reached.
*
* @param adv The advertising set object.
* @param info Information about the sent event.
*/
void (*sent)(struct bt_le_ext_adv *adv,
struct bt_le_ext_adv_sent_info *info);
/**
* @brief The advertising set has accepted a new connection.
*
* This callback notifies the application that the advertising set has
* accepted a new connection.
*
* @param adv The advertising set object.
* @param info Information about the connected event.
*/
void (*connected)(struct bt_le_ext_adv *adv,
struct bt_le_ext_adv_connected_info *info);
/**
* @brief The advertising set has sent scan response data.
*
* This callback notifies the application that the advertising set has
* has received a Scan Request packet, and has sent a Scan Response
* packet.
*
* @param adv The advertising set object.
* @param addr Information about the scanned event.
*/
void (*scanned)(struct bt_le_ext_adv *adv,
struct bt_le_ext_adv_scanned_info *info);
#if defined(CONFIG_BT_PRIVACY)
/**
* @brief The RPA validity of the advertising set has expired.
*
* This callback notifies the application that the RPA validity of
* the advertising set has expired. The user can use this callback
* to synchronize the advertising payload update with the RPA rotation.
*
* If rpa sharing is enabled and rpa expired cb of any adv-sets belonging
* to same adv id returns false, then adv-sets will continue with old rpa
* through out the rpa rotations.
*
* @param adv The advertising set object.
*
* @return true to rotate the current RPA, or false to use it for the
* next rotation period.
*/
bool (*rpa_expired)(struct bt_le_ext_adv *adv);
#endif /* defined(CONFIG_BT_PRIVACY) */
#if defined(CONFIG_BT_PER_ADV_RSP)
/**
* @brief The Controller indicates it is ready to transmit one or more subevent.
*
* This callback notifies the application that the controller has requested
* data for upcoming subevents.
*
* @param adv The advertising set object.
* @param request Information about the upcoming subevents.
*/
void (*pawr_data_request)(struct bt_le_ext_adv *adv,
const struct bt_le_per_adv_data_request *request);
/**
* @brief The Controller indicates that one or more synced devices have
* responded to a periodic advertising subevent indication.
*
* @param adv The advertising set object.
* @param info Information about the responses received.
* @param buf The received data. NULL if the controller reported
* that it did not receive any response.
*/
void (*pawr_response)(struct bt_le_ext_adv *adv, struct bt_le_per_adv_response_info *info,
struct net_buf_simple *buf);
#endif /* defined(CONFIG_BT_PER_ADV_RSP) */
};
/**
* @typedef bt_ready_cb_t
* @brief Callback for notifying that Bluetooth has been enabled.
*
* @param err zero on success or (negative) error code otherwise.
*/
typedef void (*bt_ready_cb_t)(int err);
/**
* @brief Enable Bluetooth
*
* Enable Bluetooth. Must be the called before any calls that
* require communication with the local Bluetooth hardware.
*
* When @kconfig{CONFIG_BT_SETTINGS} is enabled, the application must load the
* Bluetooth settings after this API call successfully completes before
* Bluetooth APIs can be used. Loading the settings before calling this function
* is insufficient. Bluetooth settings can be loaded with settings_load() or
* settings_load_subtree() with argument "bt". The latter selectively loads only
* Bluetooth settings and is recommended if settings_load() has been called
* earlier.
*
* @param cb Callback to notify completion or NULL to perform the
* enabling synchronously.
*
* @return Zero on success or (negative) error code otherwise.
*/
int bt_enable(bt_ready_cb_t cb);
/**
* @brief Disable Bluetooth
*
* Disable Bluetooth. Can't be called before bt_enable has completed.
*
* Close and release HCI resources. Result is architecture dependent.
*
* @return Zero on success or (negative) error code otherwise.
*/
int bt_disable(void);
/**
* @brief Check if Bluetooth is ready
*
* @return true when Bluetooth is ready, false otherwise
*/
bool bt_is_ready(void);
/**
* @brief Set Bluetooth Device Name
*
* Set Bluetooth GAP Device Name.
*
* When advertising with device name in the advertising data the name should
* be updated by calling @ref bt_le_adv_update_data or
* @ref bt_le_ext_adv_set_data.
*
* @note Requires @kconfig{CONFIG_BT_DEVICE_NAME_DYNAMIC}.
*
* @sa @kconfig{CONFIG_BT_DEVICE_NAME_MAX}.
*
* @param name New name
*
* @return Zero on success or (negative) error code otherwise.
*/
int bt_set_name(const char *name);
/**
* @brief Get Bluetooth Device Name
*
* Get Bluetooth GAP Device Name.
*
* @return Bluetooth Device Name
*/
const char *bt_get_name(void);
/**
* @brief Get local Bluetooth appearance
*
* Bluetooth Appearance is a description of the external appearance of a device
* in terms of an Appearance Value.
*
* @see https://specificationrefs.bluetooth.com/assigned-values/Appearance%20Values.pdf
*
* @returns Appearance Value of local Bluetooth host.
*/
uint16_t bt_get_appearance(void);
/**
* @brief Set local Bluetooth appearance
*
* Automatically preserves the new appearance across reboots if
* @kconfig{CONFIG_BT_SETTINGS} is enabled.
*
* This symbol is linkable if @kconfig{CONFIG_BT_DEVICE_APPEARANCE_DYNAMIC} is
* enabled.
*
* @param new_appearance Appearance Value
*
* @retval 0 Success.
* @retval other Persistent storage failed. Appearance was not updated.
*/
int bt_set_appearance(uint16_t new_appearance);
/**
* @brief Get the currently configured identities.
*
* Returns an array of the currently configured identity addresses. To
* make sure all available identities can be retrieved, the number of
* elements in the @a addrs array should be CONFIG_BT_ID_MAX. The identity
* identifier that some APIs expect (such as advertising parameters) is
* simply the index of the identity in the @a addrs array.
*
* If @a addrs is passed as NULL, then returned @a count contains the
* count of all available identities that can be retrieved with a
* subsequent call to this function with non-NULL @a addrs parameter.
*
* @note Deleted identities may show up as @ref BT_ADDR_LE_ANY in the returned
* array.
*
* @param addrs Array where to store the configured identities.
* @param count Should be initialized to the array size. Once the function
* returns it will contain the number of returned identities.
*/
void bt_id_get(bt_addr_le_t *addrs, size_t *count);
/**
* @brief Create a new identity.
*
* Create a new identity using the given address and IRK. This function can be
* called before calling bt_enable(). However, the new identity will only be
* stored persistently in flash when this API is used after bt_enable(). The
* reason is that the persistent settings are loaded after bt_enable() and would
* therefore cause potential conflicts with the stack blindly overwriting what's
* stored in flash. The identity will also not be written to flash in case a
* pre-defined address is provided, since in such a situation the app clearly
* has some place it got the address from and will be able to repeat the
* procedure on every power cycle, i.e. it would be redundant to also store the
* information in flash.
*
* Generating random static address or random IRK is not supported when calling
* this function before bt_enable().
*
* If the application wants to have the stack randomly generate identities
* and store them in flash for later recovery, the way to do it would be
* to first initialize the stack (using bt_enable), then call settings_load(),
* and after that check with bt_id_get() how many identities were recovered.
* If an insufficient amount of identities were recovered the app may then
* call bt_id_create() to create new ones.
*
* If supported by the HCI driver (indicated by setting
* @kconfig{CONFIG_BT_HCI_SET_PUBLIC_ADDR}), the first call to this function can be
* used to set the controller's public identity address. This call must happen
* before calling bt_enable(). Subsequent calls always add/generate random
* static addresses.
*
* @param addr Address to use for the new identity. If NULL or initialized
* to BT_ADDR_LE_ANY the stack will generate a new random
* static address for the identity and copy it to the given
* parameter upon return from this function (in case the
* parameter was non-NULL).
* @param irk Identity Resolving Key (16 bytes) to be used with this
* identity. If set to all zeroes or NULL, the stack will
* generate a random IRK for the identity and copy it back
* to the parameter upon return from this function (in case
* the parameter was non-NULL). If privacy
* @kconfig{CONFIG_BT_PRIVACY} is not enabled this parameter must
* be NULL.
*
* @return Identity identifier (>= 0) in case of success, or a negative
* error code on failure.
*/
int bt_id_create(bt_addr_le_t *addr, uint8_t *irk);
/**
* @brief Reset/reclaim an identity for reuse.
*
* The semantics of the @a addr and @a irk parameters of this function
* are the same as with bt_id_create(). The difference is the first
* @a id parameter that needs to be an existing identity (if it doesn't
* exist this function will return an error). When given an existing
* identity this function will disconnect any connections created using it,
* remove any pairing keys or other data associated with it, and then create
* a new identity in the same slot, based on the @a addr and @a irk
* parameters.
*
* @note the default identity (BT_ID_DEFAULT) cannot be reset, i.e. this
* API will return an error if asked to do that.
*
* @param id Existing identity identifier.
* @param addr Address to use for the new identity. If NULL or initialized
* to BT_ADDR_LE_ANY the stack will generate a new static
* random address for the identity and copy it to the given
* parameter upon return from this function (in case the
* parameter was non-NULL).
* @param irk Identity Resolving Key (16 bytes) to be used with this
* identity. If set to all zeroes or NULL, the stack will
* generate a random IRK for the identity and copy it back
* to the parameter upon return from this function (in case
* the parameter was non-NULL). If privacy
* @kconfig{CONFIG_BT_PRIVACY} is not enabled this parameter must
* be NULL.
*
* @return Identity identifier (>= 0) in case of success, or a negative
* error code on failure.
*/
int bt_id_reset(uint8_t id, bt_addr_le_t *addr, uint8_t *irk);
/**
* @brief Delete an identity.
*
* When given a valid identity this function will disconnect any connections
* created using it, remove any pairing keys or other data associated with
* it, and then flag is as deleted, so that it can not be used for any
* operations. To take back into use the slot the identity was occupying the
* bt_id_reset() API needs to be used.
*
* @note the default identity (BT_ID_DEFAULT) cannot be deleted, i.e. this
* API will return an error if asked to do that.
*
* @param id Existing identity identifier.
*
* @return 0 in case of success, or a negative error code on failure.
*/
int bt_id_delete(uint8_t id);
/**
* @brief Bluetooth data serialized size.
*
* Get the size of a serialized @ref bt_data given its data length.
*
* Size of 'AD Structure'->'Length' field, equal to 1.
* Size of 'AD Structure'->'Data'->'AD Type' field, equal to 1.
* Size of 'AD Structure'->'Data'->'AD Data' field, equal to data_len.
*
* See Core Specification Version 5.4 Vol. 3 Part C, 11, Figure 11.1.
*/
#define BT_DATA_SERIALIZED_SIZE(data_len) ((data_len) + 2)
/**
* @brief Bluetooth data.
*
* Description of different data types that can be encoded into
* advertising data. Used to form arrays that are passed to the
* bt_le_adv_start() function.
*/
struct bt_data {
uint8_t type;
uint8_t data_len;
const uint8_t *data;
};
/**
* @brief Helper to declare elements of bt_data arrays
*
* This macro is mainly for creating an array of struct bt_data
* elements which is then passed to e.g. @ref bt_le_adv_start().
*
* @param _type Type of advertising data field
* @param _data Pointer to the data field payload
* @param _data_len Number of bytes behind the _data pointer
*/
#define BT_DATA(_type, _data, _data_len) \
{ \
.type = (_type), \
.data_len = (_data_len), \
.data = (const uint8_t *)(_data), \
}
/**
* @brief Helper to declare elements of bt_data arrays
*
* This macro is mainly for creating an array of struct bt_data
* elements which is then passed to e.g. @ref bt_le_adv_start().
*
* @param _type Type of advertising data field
* @param _bytes Variable number of single-byte parameters
*/
#define BT_DATA_BYTES(_type, _bytes...) \
BT_DATA(_type, ((uint8_t []) { _bytes }), \
sizeof((uint8_t []) { _bytes }))
/**
* @brief Get the total size (in bytes) of a given set of @ref bt_data
* structures.
*
* @param[in] data Array of @ref bt_data structures.
* @param[in] data_count Number of @ref bt_data structures in @p data.
*
* @return Size of the concatenated data, built from the @ref bt_data structure
* set.
*/
size_t bt_data_get_len(const struct bt_data data[], size_t data_count);
/**
* @brief Serialize a @ref bt_data struct into an advertising structure (a flat
* byte array).
*
* The data are formatted according to the Bluetooth Core Specification v. 5.4,
* vol. 3, part C, 11.
*
* @param[in] input Single @ref bt_data structure to read from.
* @param[out] output Buffer large enough to store the advertising structure in
* @p input. The size of it must be at least the size of the
* `input->data_len + 2` (for the type and the length).
*
* @return Number of bytes written in @p output.
*/
size_t bt_data_serialize(const struct bt_data *input, uint8_t *output);
/** Advertising options */
enum {
/** Convenience value when no options are specified. */
BT_LE_ADV_OPT_NONE = 0,
/**
* @brief Advertise as connectable.
*
* Advertise as connectable. If not connectable then the type of
* advertising is determined by providing scan response data.
* The advertiser address is determined by the type of advertising
* and/or enabling privacy @kconfig{CONFIG_BT_PRIVACY}.
*/
BT_LE_ADV_OPT_CONNECTABLE = BIT(0),
/**
* @brief Advertise one time.
*
* Don't try to resume connectable advertising after a connection.
* This option is only meaningful when used together with
* BT_LE_ADV_OPT_CONNECTABLE. If set the advertising will be stopped
* when bt_le_adv_stop() is called or when an incoming (peripheral)
* connection happens. If this option is not set the stack will
* take care of keeping advertising enabled even as connections
* occur.
* If Advertising directed or the advertiser was started with
* @ref bt_le_ext_adv_start then this behavior is the default behavior
* and this flag has no effect.
*/
BT_LE_ADV_OPT_ONE_TIME = BIT(1),
/**
* @brief Advertise using identity address.
*
* Advertise using the identity address as the advertiser address.
* @warning This will compromise the privacy of the device, so care
* must be taken when using this option.
* @note The address used for advertising will not be the same as
* returned by @ref bt_le_oob_get_local, instead @ref bt_id_get
* should be used to get the LE address.
*/
BT_LE_ADV_OPT_USE_IDENTITY = BIT(2),
/** Advertise using GAP device name.
*
* Include the GAP device name automatically when advertising.
* By default the GAP device name is put at the end of the scan
* response data.
* When advertising using @ref BT_LE_ADV_OPT_EXT_ADV and not
* @ref BT_LE_ADV_OPT_SCANNABLE then it will be put at the end of the
* advertising data.
* If the GAP device name does not fit into advertising data it will be
* converted to a shortened name if possible.
* @ref BT_LE_ADV_OPT_FORCE_NAME_IN_AD can be used to force the device
* name to appear in the advertising data of an advert with scan
* response data.
*
* The application can set the device name itself by including the
* following in the advertising data.
* @code
* BT_DATA(BT_DATA_NAME_COMPLETE, name, sizeof(name) - 1)
* @endcode
*/
BT_LE_ADV_OPT_USE_NAME = BIT(3),
/**
* @brief Low duty cycle directed advertising.
*
* Use low duty directed advertising mode, otherwise high duty mode
* will be used.
*/
BT_LE_ADV_OPT_DIR_MODE_LOW_DUTY = BIT(4),
/**
* @brief Directed advertising to privacy-enabled peer.
*
* Enable use of Resolvable Private Address (RPA) as the target address
* in directed advertisements.
* This is required if the remote device is privacy-enabled and
* supports address resolution of the target address in directed
* advertisement.
* It is the responsibility of the application to check that the remote
* device supports address resolution of directed advertisements by
* reading its Central Address Resolution characteristic.
*/
BT_LE_ADV_OPT_DIR_ADDR_RPA = BIT(5),
/** Use filter accept list to filter devices that can request scan
* response data.
*/
BT_LE_ADV_OPT_FILTER_SCAN_REQ = BIT(6),
/** Use filter accept list to filter devices that can connect. */
BT_LE_ADV_OPT_FILTER_CONN = BIT(7),
/** Notify the application when a scan response data has been sent to an
* active scanner.
*/
BT_LE_ADV_OPT_NOTIFY_SCAN_REQ = BIT(8),
/**
* @brief Support scan response data.
*
* When used together with @ref BT_LE_ADV_OPT_EXT_ADV then this option
* cannot be used together with the @ref BT_LE_ADV_OPT_CONNECTABLE
* option.
* When used together with @ref BT_LE_ADV_OPT_EXT_ADV then scan
* response data must be set.
*/
BT_LE_ADV_OPT_SCANNABLE = BIT(9),
/**
* @brief Advertise with extended advertising.
*
* This options enables extended advertising in the advertising set.
* In extended advertising the advertising set will send a small header
* packet on the three primary advertising channels. This small header
* points to the advertising data packet that will be sent on one of
* the 37 secondary advertising channels.
* The advertiser will send primary advertising on LE 1M PHY, and
* secondary advertising on LE 2M PHY.
* Connections will be established on LE 2M PHY.
*
* Without this option the advertiser will send advertising data on the
* three primary advertising channels.
*
* @note Enabling this option requires extended advertising support in
* the peer devices scanning for advertisement packets.
*
* @note This cannot be used with bt_le_adv_start().
*/
BT_LE_ADV_OPT_EXT_ADV = BIT(10),
/**
* @brief Disable use of LE 2M PHY on the secondary advertising
* channel.
*
* Disabling the use of LE 2M PHY could be necessary if scanners don't
* support the LE 2M PHY.
* The advertiser will send primary advertising on LE 1M PHY, and
* secondary advertising on LE 1M PHY.
* Connections will be established on LE 1M PHY.
*
* @note Cannot be set if BT_LE_ADV_OPT_CODED is set.
*
* @note Requires @ref BT_LE_ADV_OPT_EXT_ADV.
*/
BT_LE_ADV_OPT_NO_2M = BIT(11),
/**
* @brief Advertise on the LE Coded PHY (Long Range).
*
* The advertiser will send both primary and secondary advertising
* on the LE Coded PHY. This gives the advertiser increased range with
* the trade-off of lower data rate and higher power consumption.
* Connections will be established on LE Coded PHY.
*
* @note Requires @ref BT_LE_ADV_OPT_EXT_ADV
*/
BT_LE_ADV_OPT_CODED = BIT(12),
/**
* @brief Advertise without a device address (identity or RPA).
*
* @note Requires @ref BT_LE_ADV_OPT_EXT_ADV
*/
BT_LE_ADV_OPT_ANONYMOUS = BIT(13),
/**
* @brief Advertise with transmit power.
*
* @note Requires @ref BT_LE_ADV_OPT_EXT_ADV
*/
BT_LE_ADV_OPT_USE_TX_POWER = BIT(14),
/** Disable advertising on channel index 37. */
BT_LE_ADV_OPT_DISABLE_CHAN_37 = BIT(15),
/** Disable advertising on channel index 38. */
BT_LE_ADV_OPT_DISABLE_CHAN_38 = BIT(16),
/** Disable advertising on channel index 39. */
BT_LE_ADV_OPT_DISABLE_CHAN_39 = BIT(17),
/**
* @brief Put GAP device name into advert data
*
* Will place the GAP device name into the advertising data rather
* than the scan response data.
*
* @note Requires @ref BT_LE_ADV_OPT_USE_NAME
*/
BT_LE_ADV_OPT_FORCE_NAME_IN_AD = BIT(18),
/**
* @brief Advertise using a Non-Resolvable Private Address.
*
* A new NRPA is set when updating the advertising parameters.
*
* This is an advanced feature; most users will want to enable
* @kconfig{CONFIG_BT_EXT_ADV} instead.
*
* @note Not implemented when @kconfig{CONFIG_BT_PRIVACY}.
*
* @note Mutually exclusive with BT_LE_ADV_OPT_USE_IDENTITY.
*/
BT_LE_ADV_OPT_USE_NRPA = BIT(19),
};
/** LE Advertising Parameters. */
struct bt_le_adv_param {
/**
* @brief Local identity.
*
* @note When extended advertising @kconfig{CONFIG_BT_EXT_ADV} is not
* enabled or not supported by the controller it is not possible
* to scan and advertise simultaneously using two different
* random addresses.
*/
uint8_t id;
/**
* @brief Advertising Set Identifier, valid range 0x00 - 0x0f.
*
* @note Requires @ref BT_LE_ADV_OPT_EXT_ADV
**/
uint8_t sid;
/**
* @brief Secondary channel maximum skip count.
*
* Maximum advertising events the advertiser can skip before it must
* send advertising data on the secondary advertising channel.
*
* @note Requires @ref BT_LE_ADV_OPT_EXT_ADV
*/
uint8_t secondary_max_skip;
/** Bit-field of advertising options */
uint32_t options;
/** Minimum Advertising Interval (N * 0.625 milliseconds)
* Minimum Advertising Interval shall be less than or equal to the
* Maximum Advertising Interval. The Minimum Advertising Interval and
* Maximum Advertising Interval should not be the same value (as stated
* in Bluetooth Core Spec 5.2, section 7.8.5)
* Range: 0x0020 to 0x4000
*/
uint32_t interval_min;
/** Maximum Advertising Interval (N * 0.625 milliseconds)
* Minimum Advertising Interval shall be less than or equal to the
* Maximum Advertising Interval. The Minimum Advertising Interval and
* Maximum Advertising Interval should not be the same value (as stated
* in Bluetooth Core Spec 5.2, section 7.8.5)
* Range: 0x0020 to 0x4000
*/
uint32_t interval_max;
/**
* @brief Directed advertising to peer
*
* When this parameter is set the advertiser will send directed
* advertising to the remote device.
*
* The advertising type will either be high duty cycle, or low duty
* cycle if the BT_LE_ADV_OPT_DIR_MODE_LOW_DUTY option is enabled.
* When using @ref BT_LE_ADV_OPT_EXT_ADV then only low duty cycle is
* allowed.
*
* In case of connectable high duty cycle if the connection could not
* be established within the timeout the connected() callback will be
* called with the status set to @ref BT_HCI_ERR_ADV_TIMEOUT.
*/
const bt_addr_le_t *peer;
};
/** Periodic Advertising options */
enum {
/** Convenience value when no options are specified. */
BT_LE_PER_ADV_OPT_NONE = 0,
/**
* @brief Advertise with transmit power.
*
* @note Requires @ref BT_LE_ADV_OPT_EXT_ADV
*/
BT_LE_PER_ADV_OPT_USE_TX_POWER = BIT(1),
/**
* @brief Advertise with included AdvDataInfo (ADI).
*
* @note Requires @ref BT_LE_ADV_OPT_EXT_ADV
*/
BT_LE_PER_ADV_OPT_INCLUDE_ADI = BIT(2),
};
struct bt_le_per_adv_param {
/**
* @brief Minimum Periodic Advertising Interval (N * 1.25 ms)
*
* Shall be greater or equal to BT_GAP_PER_ADV_MIN_INTERVAL and
* less or equal to interval_max.
*/
uint16_t interval_min;
/**
* @brief Maximum Periodic Advertising Interval (N * 1.25 ms)
*
* Shall be less or equal to BT_GAP_PER_ADV_MAX_INTERVAL and
* greater or equal to interval_min.
*/
uint16_t interval_max;
/** Bit-field of periodic advertising options */
uint32_t options;
#if defined(CONFIG_BT_PER_ADV_RSP)
/**
* @brief Number of subevents
*
* If zero, the periodic advertiser will be a broadcaster, without responses.
*/
uint8_t num_subevents;
/**
* @brief Interval between subevents (N * 1.25 ms)
*
* Shall be between 7.5ms and 318.75 ms.
*/
uint8_t subevent_interval;
/**
* @brief Time between the advertising packet in a subevent and the
* first response slot (N * 1.25 ms)
*
*/
uint8_t response_slot_delay;
/**
* @brief Time between response slots (N * 0.125 ms)
*
* Shall be between 0.25 and 31.875 ms.
*/
uint8_t response_slot_spacing;
/**
* @brief Number of subevent response slots
*
* If zero, response_slot_delay and response_slot_spacing are ignored.
*/
uint8_t num_response_slots;
#endif /* CONFIG_BT_PER_ADV_RSP */
};
/**
* @brief Initialize advertising parameters
*
* @param _options Advertising Options
* @param _int_min Minimum advertising interval
* @param _int_max Maximum advertising interval
* @param _peer Peer address, set to NULL for undirected advertising or
* address of peer for directed advertising.
*/
#define BT_LE_ADV_PARAM_INIT(_options, _int_min, _int_max, _peer) \
{ \
.id = BT_ID_DEFAULT, \
.sid = 0, \
.secondary_max_skip = 0, \
.options = (_options), \
.interval_min = (_int_min), \
.interval_max = (_int_max), \
.peer = (_peer), \
}
/**
* @brief Helper to declare advertising parameters inline
*
* @param _options Advertising Options
* @param _int_min Minimum advertising interval
* @param _int_max Maximum advertising interval
* @param _peer Peer address, set to NULL for undirected advertising or
* address of peer for directed advertising.
*/
#define BT_LE_ADV_PARAM(_options, _int_min, _int_max, _peer) \
((struct bt_le_adv_param[]) { \
BT_LE_ADV_PARAM_INIT(_options, _int_min, _int_max, _peer) \
})
#define BT_LE_ADV_CONN_DIR(_peer) BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONNECTABLE | \
BT_LE_ADV_OPT_ONE_TIME, 0, 0,\
_peer)
#define BT_LE_ADV_CONN BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONNECTABLE, \
BT_GAP_ADV_FAST_INT_MIN_2, \
BT_GAP_ADV_FAST_INT_MAX_2, NULL)
#define BT_LE_ADV_CONN_NAME BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONNECTABLE | \
BT_LE_ADV_OPT_USE_NAME, \
BT_GAP_ADV_FAST_INT_MIN_2, \
BT_GAP_ADV_FAST_INT_MAX_2, NULL)
#define BT_LE_ADV_CONN_NAME_AD BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONNECTABLE | \
BT_LE_ADV_OPT_USE_NAME | \
BT_LE_ADV_OPT_FORCE_NAME_IN_AD, \
BT_GAP_ADV_FAST_INT_MIN_2, \
BT_GAP_ADV_FAST_INT_MAX_2, NULL)
#define BT_LE_ADV_CONN_DIR_LOW_DUTY(_peer) \
BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_ONE_TIME | \
BT_LE_ADV_OPT_DIR_MODE_LOW_DUTY, \
BT_GAP_ADV_FAST_INT_MIN_2, BT_GAP_ADV_FAST_INT_MAX_2, \
_peer)
/** Non-connectable advertising with private address */
#define BT_LE_ADV_NCONN BT_LE_ADV_PARAM(0, BT_GAP_ADV_FAST_INT_MIN_2, \
BT_GAP_ADV_FAST_INT_MAX_2, NULL)
/** Non-connectable advertising with @ref BT_LE_ADV_OPT_USE_NAME */
#define BT_LE_ADV_NCONN_NAME BT_LE_ADV_PARAM(BT_LE_ADV_OPT_USE_NAME, \
BT_GAP_ADV_FAST_INT_MIN_2, \
BT_GAP_ADV_FAST_INT_MAX_2, NULL)
/** Non-connectable advertising with @ref BT_LE_ADV_OPT_USE_IDENTITY */
#define BT_LE_ADV_NCONN_IDENTITY BT_LE_ADV_PARAM(BT_LE_ADV_OPT_USE_IDENTITY, \
BT_GAP_ADV_FAST_INT_MIN_2, \
BT_GAP_ADV_FAST_INT_MAX_2, \
NULL)
/** Connectable extended advertising with @ref BT_LE_ADV_OPT_USE_NAME */
#define BT_LE_EXT_ADV_CONN_NAME BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV | \
BT_LE_ADV_OPT_CONNECTABLE | \
BT_LE_ADV_OPT_USE_NAME, \
BT_GAP_ADV_FAST_INT_MIN_2, \
BT_GAP_ADV_FAST_INT_MAX_2, \
NULL)
/** Scannable extended advertising with @ref BT_LE_ADV_OPT_USE_NAME */
#define BT_LE_EXT_ADV_SCAN_NAME BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV | \
BT_LE_ADV_OPT_SCANNABLE | \
BT_LE_ADV_OPT_USE_NAME, \
BT_GAP_ADV_FAST_INT_MIN_2, \
BT_GAP_ADV_FAST_INT_MAX_2, \
NULL)
/** Non-connectable extended advertising with private address */
#define BT_LE_EXT_ADV_NCONN BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV, \
BT_GAP_ADV_FAST_INT_MIN_2, \
BT_GAP_ADV_FAST_INT_MAX_2, NULL)
/** Non-connectable extended advertising with @ref BT_LE_ADV_OPT_USE_NAME */
#define BT_LE_EXT_ADV_NCONN_NAME BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV | \
BT_LE_ADV_OPT_USE_NAME, \
BT_GAP_ADV_FAST_INT_MIN_2, \
BT_GAP_ADV_FAST_INT_MAX_2, \
NULL)
/** Non-connectable extended advertising with @ref BT_LE_ADV_OPT_USE_IDENTITY */
#define BT_LE_EXT_ADV_NCONN_IDENTITY \
BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV | \
BT_LE_ADV_OPT_USE_IDENTITY, \
BT_GAP_ADV_FAST_INT_MIN_2, \
BT_GAP_ADV_FAST_INT_MAX_2, NULL)
/** Non-connectable extended advertising on coded PHY with private address */
#define BT_LE_EXT_ADV_CODED_NCONN BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV | \
BT_LE_ADV_OPT_CODED, \
BT_GAP_ADV_FAST_INT_MIN_2, \
BT_GAP_ADV_FAST_INT_MAX_2, \
NULL)
/** Non-connectable extended advertising on coded PHY with
* @ref BT_LE_ADV_OPT_USE_NAME
*/
#define BT_LE_EXT_ADV_CODED_NCONN_NAME \
BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV | BT_LE_ADV_OPT_CODED | \
BT_LE_ADV_OPT_USE_NAME, \
BT_GAP_ADV_FAST_INT_MIN_2, \
BT_GAP_ADV_FAST_INT_MAX_2, NULL)
/** Non-connectable extended advertising on coded PHY with
* @ref BT_LE_ADV_OPT_USE_IDENTITY
*/
#define BT_LE_EXT_ADV_CODED_NCONN_IDENTITY \
BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV | BT_LE_ADV_OPT_CODED | \
BT_LE_ADV_OPT_USE_IDENTITY, \
BT_GAP_ADV_FAST_INT_MIN_2, \
BT_GAP_ADV_FAST_INT_MAX_2, NULL)
/**