xref: /btstack/src/gap.h (revision e8b7768f4320b89e088aeff6b8ffd5c9b51f3338)
1 /*
2  * Copyright (C) 2014 BlueKitchen GmbH
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the copyright holders nor the names of
14  *    contributors may be used to endorse or promote products derived
15  *    from this software without specific prior written permission.
16  * 4. Any redistribution, use, or modification is done solely for
17  *    personal benefit and not for any commercial purpose or for
18  *    monetary gain.
19  *
20  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
24  * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * Please inquire about commercial licensing options at
34  * [email protected]
35  *
36  */
37 
38 /**
39  * @title Genral Access Profile (GAP)
40  *
41  */
42 
43 #ifndef GAP_H
44 #define GAP_H
45 
46 #if defined __cplusplus
47 extern "C" {
48 #endif
49 
50 #include "btstack_defines.h"
51 #include "btstack_util.h"
52 
53 #ifdef ENABLE_CLASSIC
54 #include "classic/btstack_link_key_db.h"
55 #endif
56 
57 // BIG has up to 2 BIS (stereo)
58 #ifndef MAX_NR_BIS
59 #define MAX_NR_BIS 2
60 #endif
61 
62 // CIG usually has up to 2 CIS (stereo)
63 #ifndef MAX_NR_CIS
64 #define MAX_NR_CIS 2
65 #endif
66 
67 typedef enum {
68 
69 	// MITM protection not required
70 	// No encryption required
71 	// No user interaction required
72 	LEVEL_0 = 0,
73 
74 	// MITM protection not required
75 	// No encryption required
76 	// Minimal user interaction desired
77 	LEVEL_1,
78 
79 	// MITM protection not required
80 	// Encryption required
81 	LEVEL_2,
82 
83 	// MITM protection required
84 	// Encryption required
85 	// User interaction acceptable
86 	LEVEL_3,
87 
88 	// MITM protection required
89 	// Encryption required
90 	// 128-bit equivalent strength for link and encryption keys required (P-192 is not enough)
91 	// User interaction acceptable
92 	LEVEL_4,
93 } gap_security_level_t;
94 
95 
96 typedef enum {
97     // non-secure
98     GAP_SECURITY_MODE_1 = 1,
99 
100     // service level enforced security
101     GAP_SECURITY_MODE_2,
102 
103     // link level enforced security
104     GAP_SECURITY_MODE_3,
105 
106     // service level enforced security
107     GAP_SECURITY_MODE_4
108 } gap_security_mode_t;
109 
110 typedef enum {
111 	GAP_SECURITY_NONE,
112 	GAP_SECURITY_ENCRYPTED,		// SSP: JUST WORKS
113 	GAP_SECURITY_AUTHENTICATED, // SSP: numeric comparison, passkey, OOB
114 	// GAP_SECURITY_AUTHORIZED
115 } gap_security_state;
116 
117 typedef enum {
118 	GAP_CONNECTION_INVALID,
119 	GAP_CONNECTION_ACL,
120 	GAP_CONNECTION_SCO,
121 	GAP_CONNECTION_LE
122 } gap_connection_type_t;
123 
124 typedef struct le_connection_parameter_range{
125     uint16_t le_conn_interval_min;
126     uint16_t le_conn_interval_max;
127     uint16_t le_conn_latency_min;
128     uint16_t le_conn_latency_max;
129     uint16_t le_supervision_timeout_min;
130     uint16_t le_supervision_timeout_max;
131 } le_connection_parameter_range_t;
132 
133 typedef enum {
134     GAP_RANDOM_ADDRESS_TYPE_OFF = 0,
135     GAP_RANDOM_ADDRESS_TYPE_STATIC,
136     GAP_RANDOM_ADDRESS_NON_RESOLVABLE,
137     GAP_RANDOM_ADDRESS_RESOLVABLE,
138 } gap_random_address_type_t;
139 
140 // Authorization state
141 typedef enum {
142     AUTHORIZATION_UNKNOWN,
143     AUTHORIZATION_PENDING,
144     AUTHORIZATION_DECLINED,
145     AUTHORIZATION_GRANTED
146 } authorization_state_t;
147 
148 // Extended Advertising Parameters
149 typedef struct {
150     uint16_t        advertising_event_properties;
151     uint16_t        primary_advertising_interval_min;
152     uint16_t        primary_advertising_interval_max;
153     uint8_t         primary_advertising_channel_map;
154     bd_addr_type_t  own_address_type;
155     bd_addr_type_t  peer_address_type;
156     bd_addr_t       peer_address;
157     uint8_t         advertising_filter_policy;
158     int8_t          advertising_tx_power;
159     uint8_t         primary_advertising_phy;
160     uint8_t         secondary_advertising_max_skip;
161     uint8_t         secondary_advertising_phy;
162     uint8_t         advertising_sid;
163     uint8_t         scan_request_notification_enable;
164 } le_extended_advertising_parameters_t;
165 
166 typedef struct {
167     uint16_t  periodic_advertising_interval_min;
168     uint16_t  periodic_advertising_interval_max;
169     uint16_t  periodic_advertising_properties;
170 } le_periodic_advertising_parameters_t;
171 
172 // Extended Advertising Set State
173 typedef struct {
174     btstack_linked_item_t item;
175     le_extended_advertising_parameters_t extended_params;
176     le_periodic_advertising_parameters_t periodic_params;
177     bd_addr_t random_address;
178     const uint8_t * adv_data;
179     const uint8_t * scan_data;
180     const uint8_t * periodic_data;
181     uint16_t  adv_data_len;
182     uint16_t  scan_data_len;
183     uint16_t  periodic_data_len;
184     uint16_t  adv_data_pos;
185     uint16_t  scan_data_pos;
186     uint16_t  periodic_data_pos;
187     uint16_t  enable_timeout;
188     uint8_t   advertising_handle;
189     uint8_t   enable_max_scan_events;
190     bool      periodic_include_adi;
191     uint8_t   state;
192     uint8_t   tasks;
193 } le_advertising_set_t;
194 
195 // Isochronous Streams
196 
197 // -- Broadcast Isochronous Group BIG
198 
199 typedef struct {
200     uint8_t  big_handle;
201     uint8_t  advertising_handle;
202     uint8_t  num_bis;
203     uint32_t sdu_interval_us;
204     uint16_t max_sdu;
205     uint16_t max_transport_latency_ms;
206     uint8_t  rtn;
207     uint8_t  phy;
208     uint8_t  packing;
209     uint8_t  framing;
210     uint8_t  encryption;
211     uint8_t  broadcast_code[16];
212 } le_audio_big_params_t;
213 
214 typedef struct {
215     uint8_t  big_handle;
216     uint8_t  sync_handle;
217     uint8_t  encryption;
218     uint8_t  broadcast_code[16];
219     uint8_t  mse;
220     uint16_t big_sync_timeout_10ms;
221     uint8_t  num_bis;
222     uint8_t bis_indices[MAX_NR_BIS];
223 } le_audio_big_sync_params_t;
224 
225 typedef enum {
226     LE_AUDIO_BIG_STATE_CREATE,
227     LE_AUDIO_BIG_STATE_W4_ESTABLISHED,
228     LE_AUDIO_BIG_STATE_SETUP_ISO_PATH,
229     LE_AUDIO_BIG_STATE_W4_SETUP_ISO_PATH,
230     LE_AUDIO_BIG_STATE_W4_SETUP_ISO_PATH_THEN_TERMINATE,
231     LE_AUDIO_BIG_STATE_SETUP_ISO_PATHS_FAILED,
232     LE_AUDIO_BIG_STATE_ACTIVE,
233     LE_AUDIO_BIG_STATE_TERMINATE,
234     LE_AUDIO_BIG_STATE_W4_TERMINATED_AFTER_SETUP_FAILED,
235     LE_AUDIO_BIG_STATE_W4_TERMINATED,
236 } le_audio_big_state_t;
237 
238 typedef struct {
239 	btstack_linked_item_t item;
240     uint8_t big_handle;
241     le_audio_big_state_t state;
242     union {
243         uint8_t next_bis;
244         uint8_t status;
245     } state_vars;
246     uint8_t num_bis;
247     hci_con_handle_t bis_con_handles[MAX_NR_BIS];
248     const le_audio_big_params_t * params;
249     // request to send
250     bool can_send_now_requested;
251     // previous and current timestamp of number completed event to track ISO intervals
252     bool     num_completed_timestamp_previous_valid;
253     bool     num_completed_timestamp_current_valid;
254     uint32_t num_completed_timestamp_previous_ms;
255     uint32_t num_completed_timestamp_current_ms;
256 
257 } le_audio_big_t;
258 
259 typedef struct {
260     btstack_linked_item_t  item;
261     uint8_t big_handle;
262     le_audio_big_state_t   state;
263     union {
264         uint8_t next_bis;
265         uint8_t status;
266     } state_vars;
267     uint8_t num_bis;
268     hci_con_handle_t bis_con_handles[MAX_NR_BIS];
269     const le_audio_big_sync_params_t * params;
270 } le_audio_big_sync_t;
271 
272 // -- Connected Isochronuous Group CIG
273 
274 typedef enum {
275     LE_AUDIO_CIG_STATE_CREATE,
276     LE_AUDIO_CIG_STATE_W4_ESTABLISHED,
277     LE_AUDIO_CIG_STATE_W4_CIS_REQUEST,
278     LE_AUDIO_CIG_STATE_CREATE_CIS,
279     LE_AUDIO_CIG_STATE_W4_CREATE_CIS,
280     LE_AUDIO_CIG_STATE_SETUP_ISO_PATH,
281     LE_AUDIO_CIG_STATE_W4_SETUP_ISO_PATH,
282     LE_AUDIO_CIG_STATE_ACTIVE,
283     LE_AUDIO_CIG_STATE_REMOVE,
284 } le_audio_cig_state_t;
285 
286 typedef struct {
287     uint8_t  cis_id;
288     uint16_t max_sdu_c_to_p;
289     uint16_t max_sdu_p_to_c;
290     uint8_t phy_c_to_p;
291     uint8_t phy_p_to_c;
292     uint8_t rtn_c_to_p;
293     uint8_t rtn_p_to_c;
294 } le_audio_cis_params_t;
295 
296 typedef struct {
297     uint8_t  cig_id;
298     uint32_t sdu_interval_c_to_p;
299     uint32_t sdu_interval_p_to_c;
300     uint8_t worst_case_sca;
301     uint8_t packing;
302     uint8_t framing;
303     uint16_t max_transport_latency_c_to_p;
304     uint16_t max_transport_latency_p_to_c;
305     uint8_t num_cis;
306     le_audio_cis_params_t cis_params[MAX_NR_CIS];
307 } le_audio_cig_params_t;
308 
309 typedef struct {
310     btstack_linked_item_t item;
311     uint8_t cig_id;
312     le_audio_cig_params_t * params;
313     le_audio_cig_state_t state;
314     union {
315         uint8_t next_cis;
316         uint8_t status;
317     } state_vars;
318     uint8_t num_cis;
319     hci_con_handle_t cis_con_handles[MAX_NR_CIS];
320     hci_con_handle_t acl_con_handles[MAX_NR_CIS];
321     bool cis_setup_active[MAX_NR_CIS];
322     bool cis_established[MAX_NR_CIS];
323     // request to send
324     bool can_send_now_requested;
325 } le_audio_cig_t;
326 
327 /* API_START */
328 
329 // Classic + LE
330 
331 /**
332  * @brief Read RSSI
333  * @param con_handle
334  * @events: GAP_EVENT_RSSI_MEASUREMENT
335  */
336 int gap_read_rssi(hci_con_handle_t con_handle);
337 
338 
339 /**
340  * @brief Gets local address.
341  */
342 void gap_local_bd_addr(bd_addr_t address_buffer);
343 
344 /**
345  * @brief Disconnect connection with handle
346  * @param handle
347  */
348 uint8_t gap_disconnect(hci_con_handle_t handle);
349 
350 /**
351  * @brief Get connection type
352  * @param con_handle
353  * @result connection_type
354  */
355 gap_connection_type_t gap_get_connection_type(hci_con_handle_t connection_handle);
356 
357 /**
358  * @brief Get HCI connection role
359  * @param con_handle
360  * @result hci_role_t HCI_ROLE_MASTER / HCI_ROLE_SLAVE / HCI_ROLE_INVALID (if connection does not exist)
361  */
362 hci_role_t gap_get_role(hci_con_handle_t connection_handle);
363 
364 // Classic
365 
366 /**
367  * @brief Request role switch
368  * @note this only requests the role switch. A HCI_EVENT_ROLE_CHANGE is emitted and its status field will indicate if the switch was succesful
369  * @param addr
370  * @param hci_role_t HCI_ROLE_MASTER / HCI_ROLE_SLAVE
371  * @result status
372  */
373 uint8_t gap_request_role(const bd_addr_t addr, hci_role_t role);
374 
375 /**
376  * @brief Sets local name.
377  * @note Default name is 'BTstack 00:00:00:00:00:00'
378  * @note '00:00:00:00:00:00' in local_name will be replaced with actual bd addr
379  * @param name is not copied, make sure memory stays valid
380  */
381 void gap_set_local_name(const char * local_name);
382 
383 /**
384  * @brief Set Extended Inquiry Response data
385  * @note If not set, local name will be used for EIR data (see gap_set_local_name)
386  * @note '00:00:00:00:00:00' in local_name will be replaced with actual bd addr
387  * @param eir_data size HCI_EXTENDED_INQUIRY_RESPONSE_DATA_LEN (240) bytes, is not copied make sure memory stays valid
388  */
389 void gap_set_extended_inquiry_response(const uint8_t * data);
390 
391 /**
392  * @brief Set class of device
393  */
394 void gap_set_class_of_device(uint32_t class_of_device);
395 
396 /**
397  * @brief Set default link policy settings for all classic ACL links
398  * @param default_link_policy_settings - see LM_LINK_POLICY_* in bluetooth.h
399  * @note common value: LM_LINK_POLICY_ENABLE_ROLE_SWITCH | LM_LINK_POLICY_ENABLE_SNIFF_MODE to enable role switch and sniff mode
400  */
401 void gap_set_default_link_policy_settings(uint16_t default_link_policy_settings);
402 
403 /**
404  * @brief Set Allow Role Switch param for outgoing classic ACL links
405  * @param allow_role_switch - true: allow remote device to request role switch, false: stay master
406  */
407 void gap_set_allow_role_switch(bool allow_role_switch);
408 
409 /**
410  * @brief Set  link supervision timeout for outgoing classic ACL links
411  * @param default_link_supervision_timeout * 0.625 ms, default 0x7d00 = 20 seconds, 0 = no link supervision timeout
412  */
413 void gap_set_link_supervision_timeout(uint16_t link_supervision_timeout);
414 
415 /**
416  * @brief Enable link watchdog. If no ACL packet is sent within timeout_ms, the link will get disconnected
417  * note: current implementation uses the automatic flush timeout controller feature with a max timeout of 1.28s
418  * @param timeout_ms
419  */
420 void gap_enable_link_watchdog(uint16_t timeout_ms);
421 
422 /**
423  * @brief Enable/disable bonding. Default is enabled.
424  * @param enabled
425  */
426 void gap_set_bondable_mode(int enabled);
427 
428 /**
429  * @brief Get bondable mode.
430  * @return 1 if bondable
431  */
432 int gap_get_bondable_mode(void);
433 
434 /**
435  * @brief Set security mode for all outgoing and incoming connections. Default: GAP_SECURITY_MODE_4
436  * @param security_mode is GAP_SECURITY_MODE_2 or GAP_SECURITY_MODE_4
437  * @return status ERROR_CODE_SUCCESS or ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE
438  */
439 uint8_t gap_set_security_mode(gap_security_mode_t security_mode);
440 
441 /**
442  * @brief Get security mode
443  * @return security_mode
444  */
445 gap_security_mode_t gap_get_security_mode(void);
446 
447 /**
448  * @brief Set security level for all outgoing and incoming connections. Default: LEVEL_2
449  * @param security_level
450  * @note has to be called before services or profiles are initialized
451  */
452 void gap_set_security_level(gap_security_level_t security_level);
453 
454 /**
455  * @brief Get security level
456  * @return security_level
457  */
458 gap_security_level_t gap_get_security_level(void);
459 
460 /**
461  * @brief Set Secure Connections Only Mode for BR/EDR (Classic) Default: false
462  * @param enable
463  */
464 void gap_set_secure_connections_only_mode(bool enable);
465 
466 /**
467  * @breif Get Secure Connections Only Mode
468  * @param enabled
469  */
470 bool gap_get_secure_connections_only_mode(void);
471 
472 /**
473  * @brief Set minimal security level for registered services
474  * @param security_level
475  * @note Called by L2CAP based on registered services
476  */
477 void gap_set_minimal_service_security_level(gap_security_level_t security_level);
478 
479 /**
480  * @brief Register filter for rejecting classic connections. Callback will return 1 accept connection, 0 on reject.
481  */
482 void gap_register_classic_connection_filter(int (*accept_callback)(bd_addr_t addr, hci_link_type_t link_type));
483 
484 /* Configure Secure Simple Pairing */
485 
486 /**
487  * @brief Enable will enable SSP during init. Default: true
488  */
489 void gap_ssp_set_enable(int enable);
490 
491 /**
492  * @brief Set IO Capability. BTstack will return capability to SSP requests
493  */
494 void gap_ssp_set_io_capability(int ssp_io_capability);
495 
496 /**
497  * @brief Set Authentication Requirements using during SSP
498  */
499 void gap_ssp_set_authentication_requirement(int authentication_requirement);
500 
501 /**
502  * @brief Enable/disable Secure Connections. Default: true if supported by Controller
503  */
504 void gap_secure_connections_enable(bool enable);
505 
506 /**
507  * @brief Query if Secure Connections can be used for Classic connections.
508  * @note Requires gap_secure_connections_enable == true and Controller to support it
509  */
510 bool gap_secure_connections_active(void);
511 
512 /**
513  * @brief If set, BTstack will confirm a numeric comparison and enter '000000' if requested.
514  */
515 void gap_ssp_set_auto_accept(int auto_accept);
516 
517 /**
518  * @brief Set required encryption key size for GAP Levels 1-3 on ccassic connections. Default: 16 bytes
519  * @param encryption_key_size in bytes. Valid 7..16
520  */
521 void gap_set_required_encryption_key_size(uint8_t encryption_key_size);
522 
523 /**
524  * @brief Start dedicated bonding with device. Disconnect after bonding.
525  * @param device
526  * @param request MITM protection
527  * @return error, if max num acl connections active
528  * @result GAP_DEDICATED_BONDING_COMPLETE
529  */
530 int gap_dedicated_bonding(bd_addr_t device, int mitm_protection_required);
531 
532 gap_security_level_t gap_security_level_for_link_key_type(link_key_type_t link_key_type);
533 
534 /**
535  * @brief map link keys to secure connection yes/no
536  */
537 bool gap_secure_connection_for_link_key_type(link_key_type_t link_key_type);
538 
539 /**
540  * @brief map link keys to authenticated
541  */
542 bool gap_authenticated_for_link_key_type(link_key_type_t link_key_type);
543 
544 gap_security_level_t gap_security_level(hci_con_handle_t con_handle);
545 
546 void gap_request_security_level(hci_con_handle_t con_handle, gap_security_level_t level);
547 
548 bool gap_mitm_protection_required_for_security_level(gap_security_level_t level);
549 
550 /**
551  * @brief Set Page Scan Type
552  * @param page_scan_interval * 0.625 ms, range: 0x0012..0x1000, default: 0x0800
553  * @param page_scan_windows  * 0.625 ms, range: 0x0011..page_scan_interval, default: 0x0012
554  */
555 void gap_set_page_scan_activity(uint16_t page_scan_interval, uint16_t page_scan_window);
556 
557 /**
558  * @brief Set Page Scan Type
559  * @param page_scan_mode
560  */
561 void gap_set_page_scan_type(page_scan_type_t page_scan_type);
562 
563 /**
564  * @brief Set Page Timeout
565  * @param page_timeout * 0.625 ms, range: 0x0001..0xffff, default: 0x6000 (ca 15 seconds)
566  */
567 void gap_set_page_timeout(uint16_t page_timeout);
568 
569 // LE
570 
571 /**
572  * @brief Set parameters for LE Scan
573  * @param scan_type 0 = passive, 1 = active
574  * @param scan_interval range 0x0004..0x4000, unit 0.625 ms
575  * @param scan_window range 0x0004..0x4000, unit 0.625 ms
576  * @param scanning_filter_policy 0 = all devices, 1 = all from whitelist
577  */
578 void gap_set_scan_params(uint8_t scan_type, uint16_t scan_interval, uint16_t scan_window, uint8_t scanning_filter_policy);
579 
580 /**
581  * @brief Set parameters for LE Scan
582  * @deprecated Use gap_set_scan_params instead
583  */
584 void gap_set_scan_parameters(uint8_t scan_type, uint16_t scan_interval, uint16_t scan_window);
585 
586 /**
587  * @brief Set duplicate filter for LE Scan
588  * @param enabled if enabled, only one advertisements per BD_ADDR is reported, default: false
589  */
590 void gap_set_scan_duplicate_filter(bool enabled);
591 
592 /**
593  * @brief Set PHYs for LE Scan
594  * @param phy bitmask: 1 = LE 1M PHY, 4 = LE Coded PHY
595  */
596 void gap_set_scan_phys(uint8_t phys);
597 
598 /**
599  * @brief Start LE Scan
600  */
601 void gap_start_scan(void);
602 
603 /**
604  * @brief Stop LE Scan
605  */
606 void gap_stop_scan(void);
607 
608 /**
609  * @brief Enable privacy by using random addresses
610  * @param random_address_type to use (incl. OFF)
611  */
612 void gap_random_address_set_mode(gap_random_address_type_t random_address_type);
613 
614 /**
615  * @brief Get privacy mode
616  */
617 gap_random_address_type_t gap_random_address_get_mode(void);
618 
619 /**
620  * @brief Sets update period for random address
621  * @param period_ms in ms
622  */
623  void gap_random_address_set_update_period(int period_ms);
624 
625 /**
626  * @brief Sets a fixed random address for advertising
627  * @param addr
628  * @note Sets random address mode to type static
629  */
630 void gap_random_address_set(const bd_addr_t addr);
631 
632 /**
633  * @brief Set Advertisement Data
634  * @param advertising_data_length
635  * @param advertising_data (max 31 octets)
636  * @note data is not copied, pointer has to stay valid
637  * @note '00:00:00:00:00:00' in advertising_data will be replaced with actual bd addr
638  */
639 void gap_advertisements_set_data(uint8_t advertising_data_length, uint8_t * advertising_data);
640 
641 /**
642  * @brief Set Advertisement Parameters
643  * @param adv_int_min
644  * @param adv_int_max
645  * @param adv_type
646  * @param direct_address_type
647  * @param direct_address
648  * @param channel_map
649  * @param filter_policy
650  * @note own_address_type is used from gap_random_address_set_mode
651  */
652 void gap_advertisements_set_params(uint16_t adv_int_min, uint16_t adv_int_max, uint8_t adv_type,
653 	uint8_t direct_address_typ, bd_addr_t direct_address, uint8_t channel_map, uint8_t filter_policy);
654 
655 /**
656  * @brief Enable/Disable Advertisements. OFF by default.
657  * @param enabled
658  */
659 void gap_advertisements_enable(int enabled);
660 
661 /**
662  * @brief Set Scan Response Data
663  *
664  * @note For scan response data, scannable undirected advertising (ADV_SCAN_IND) need to be used
665  *
666  * @param advertising_data_length
667  * @param advertising_data (max 31 octets)
668  * @note data is not copied, pointer has to stay valid
669  * @note '00:00:00:00:00:00' in scan_response_data will be replaced with actual bd addr
670  */
671 void gap_scan_response_set_data(uint8_t scan_response_data_length, uint8_t * scan_response_data);
672 
673 
674 /**
675  * @brief Set update interval for resolvable private addresses generated by the Controller
676  * @param update_s timeout for updates in seconds
677  * @return status
678  */
679 uint8_t gap_extended_advertising_set_resolvable_private_address_update(uint16_t update_s);
680 
681 /**
682  * @brief Provide storage for new advertising set and setup on Controller
683  * @param storage to use by stack, needs to stay valid until adv set is removed with gap_extended_advertising_remove
684  * @param advertising_parameters
685  * @param out_advertising_handle to use with other adv config commands
686  * @return status
687  * @events: GAP_SUBEVENT_ADVERTISING_SET_INSTALLED
688  */
689 uint8_t gap_extended_advertising_setup(le_advertising_set_t * storage, const le_extended_advertising_parameters_t * advertising_parameters, uint8_t * out_advertising_handle);
690 
691 /**
692  * @param Set advertising params for advertising set
693  * @param advertising_handle
694  * @param advertising_parameters
695  * @return status
696  */
697 uint8_t gap_extended_advertising_set_params(uint8_t advertising_handle, const le_extended_advertising_parameters_t * advertising_parameters);
698 
699 /**
700  * @param Get advertising params for advertising set, e.g. to update params
701  * @param advertising_handle
702  * @param advertising_parameters
703  * @return status
704  */
705 uint8_t gap_extended_advertising_get_params(uint8_t advertising_handle, le_extended_advertising_parameters_t * advertising_parameters);
706 
707 /**
708  * @param Set periodic advertising params for advertising set
709  * @param advertising_handle
710  * @param advertising_parameters
711  * @return status
712  */
713 uint8_t gap_periodic_advertising_set_params(uint8_t advertising_handle, const le_periodic_advertising_parameters_t * advertising_parameters);
714 
715 /**
716  * @param Get params for periodic advertising set, e.g. to update params
717  * @param advertising_handle
718  * @param advertising_parameters
719  * @return status
720  */
721 uint8_t gap_periodic_advertising_get_params(uint8_t advertising_handle, le_periodic_advertising_parameters_t * advertising_parameters);
722 
723 /**
724  * @param Set random addrress for advertising set
725  * @param advertising_handle
726  * @param random_address
727  * @return status
728  */
729 uint8_t gap_extended_advertising_set_random_address(uint8_t advertising_handle, bd_addr_t random_address);
730 
731 /**
732  * @brief Set Advertising Data for a advertisement set
733  * @param advertising_handle
734  * @param advertising_data_length
735  * @param advertising_data
736  * @return status
737  */
738 uint8_t gap_extended_advertising_set_adv_data(uint8_t advertising_handle, uint16_t advertising_data_length, const uint8_t * advertising_data);
739 
740 /**
741  * @brief Set Scan Response Data for a advertisement set
742  * @param advertising_handle
743  * @param scan_response_data_length
744  * @param scan_response_data
745  * @return status
746  */
747 uint8_t gap_extended_advertising_set_scan_response_data(uint8_t advertising_handle, uint16_t scan_response_data_length, const uint8_t * scan_response_data);
748 
749 /**
750  * @brief Set data for periodic advertisement set
751  * @param advertising_handle
752  * @param periodic_data_length
753  * @param periodic_data
754  * @return status
755  */
756 uint8_t gap_periodic_advertising_set_data(uint8_t advertising_handle, uint16_t periodic_data_length, const uint8_t * periodic_data);
757 
758 /**
759  * @brief Start advertising advertising set
760  * @param advertising_handle
761  * @param timeout in 10ms, or 0 == no timeout
762  * @param num_extended_advertising_events Controller shall send, or 0 == no max number
763  * @return status
764  */
765 uint8_t gap_extended_advertising_start(uint8_t advertising_handle, uint16_t timeout, uint8_t num_extended_advertising_events);
766 
767 /**
768  * @brief Stop advertising
769  * @param advertising_handle
770  * @return status
771  */
772 uint8_t gap_extended_advertising_stop(uint8_t advertising_handle);
773 
774 /**
775  * @brief Start periodic advertising for given advertising set
776  * @param advertising_handle
777  * @param include_adi
778  * @return status
779  */
780 uint8_t gap_periodic_advertising_start(uint8_t advertising_handle, bool include_adi);
781 
782 /**
783  * @brief Stop periodic advertising for given advertising set
784  * @param advertising_handle
785  * @return status
786  */
787 uint8_t gap_periodic_advertising_stop(uint8_t advertising_handle);
788 
789 /**
790  * @brief Set Default Periodic Advertising Sync Transfer Parameters
791  * @note The parameters are used for all subsequent connections over the LE transport.
792  *       If mode != 0, an HCI_LE_Periodic_Advertising_Sync_Transfer_Received event will be emitted by the Controller
793  * @param mode 0 = ignore (default), 1 = periodic advertising events disabled
794  *             2 = periodic advertising events enabled with duplicate filtering
795  *             3 = periodic advertising events enabled with duplicate filtering
796  * @return status
797  * @param skip The number of periodic advertising packets that can be skipped after a successful receive
798  * @param sync_timeout Range: 0x000A to 0x4000, Time = N*10 ms, Time Range: 100 ms to 163.84 s
799  * @param cte_type  bit 0 = Do not sync to packets with an AoA Constant Tone Extension
800  *                  bit 1 = Do not sync to packets with an AoD Constant Tone Extension with 1 μs slots
801  *                  bit 2 = Do not sync to packets with an AoD Constant Tone Extension with 2 μs slots
802  *                  bit 3 = Do not sync to packets without a Constant Tone Extension
803  */
804 uint8_t gap_periodic_advertising_sync_transfer_set_default_parameters(uint8_t mode, uint16_t skip, uint16_t sync_timeout, uint8_t cte_type);
805 
806 /**
807  * @brief Send Periodic Advertising Sync Transfer to connected device
808  * @param con_handle of connected device
809  * @param service_data 16-bit data to transfer to remote host
810  * @param sync_handle of synchronized periodic advertising train to transfer
811  * @return
812  */
813 uint8_t gap_periodic_advertising_sync_transfer_send(hci_con_handle_t con_handle, uint16_t service_data, hci_con_handle_t sync_handle);
814 
815 /**
816  * @brief Send Periodic Advertising Set Info Transfer to connected device
817  * @param con_handle of connected device
818  * @param service_data 16-bit data to transfer to remote host
819  * @param advertising_handle of local periodic advertising train to transfer
820  * @return
821  */
822 uint8_t gap_periodic_advertising_set_info_transfer_send(hci_con_handle_t con_handle, uint16_t service_data, uint8_t advertising_handle);
823 
824 /**
825  * @brief Remove advertising set from Controller
826  * @param advertising_handle
827  * @return status
828  * @events GAP_SUBEVENT_ADVERTISING_SET_REMOVED
829  */
830 uint8_t gap_extended_advertising_remove(uint8_t advertising_handle);
831 
832 /**
833  * @brief Create Broadcast Isochronous Group (BIG)
834  * @param storage to use by stack, needs to stay valid until adv set is removed with gap_big_terminate
835  * @param big_params
836  * @return status
837  * @events GAP_SUBEVENT_BIG_CREATED unless interrupted by call to gap_big_terminate
838  */
839 uint8_t gap_big_create(le_audio_big_t * storage, le_audio_big_params_t * big_params);
840 
841 /**
842  * @brief Terminate Broadcast Isochronous Group (BIG)
843  * @param big_handle
844  * @return status
845  * @events: GAP_SUBEVENT_BIG_TERMINATED
846  */
847 uint8_t gap_big_terminate(uint8_t big_handle);
848 
849 /**
850  * @brief Synchronize to Broadcast Isochronous Group (BIG)
851  * @param storage to use by stack, needs to stay valid until adv set is removed with gap_big_terminate
852  * @param big_sync_params
853  * @return status
854  * @events GAP_SUBEVENT_BIG_SYNC_CREATED unless interrupted by call to gap_big_sync_terminate
855  */
856 uint8_t gap_big_sync_create(le_audio_big_sync_t * storage, le_audio_big_sync_params_t * big_sync_params);
857 
858 /**
859  * @brief Stop synchronizing to Broadcast Isochronous Group (BIG). Triggers GAP_SUBEVENT_BIG_SYNC_STOPPED
860  * @note Also used to stop synchronizing before BIG Sync was established
861  * @param big_handle
862  * @return status
863  * @events GAP_SUBEVENT_BIG_SYNC_STOPPED
864  */
865 uint8_t gap_big_sync_terminate(uint8_t big_handle);
866 
867 /**
868  * @brief Create Connected Isochronous Group (CIG)
869  * @param storage to use by stack, needs to stay valid until CIG removed with gap_cig_remove
870  * @param cig_params
871  * @return status
872  * @events GAP_SUBEVENT_CIG_CREATED unless interrupted by call to gap_cig_remove
873  */
874 uint8_t gap_cig_create(le_audio_cig_t * storage, le_audio_cig_params_t * cig_params);
875 
876 /**
877  * @brief Remove Connected Isochronous Group (CIG)
878  * @param cig_handle
879  * @return status
880  * @events GAP_SUBEVENT_CIG_TERMINATED
881  */
882 uint8_t gap_cig_remove(uint8_t cig_handle);
883 
884 /**
885  * @brief Create Connected Isochronous Streams (CIS)
886  * @note number of CIS from cig_params in gap_cig_create is used
887  * @param cig_handle
888  * @param cis_con_handles array of CIS Connection Handles
889  * @param acl_con_handles array of ACL Connection Handles
890  * @return status
891  * @events GAP_SUBEVENT_CIS_CREATED unless interrupted by call to gap_cig_remove
892  */
893 uint8_t gap_cis_create(uint8_t cig_handle, hci_con_handle_t cis_con_handles [], hci_con_handle_t acl_con_handles []);
894 
895 /**
896  * @brief Accept Connected Isochronous Stream (CIS)
897  * @param cis_con_handle
898  * @return status
899  * @events GAP_SUBEVENT_CIS_CREATED
900  */
901 uint8_t gap_cis_accept(hci_con_handle_t cis_con_handle);
902 
903 /**
904  * @brief Reject Connected Isochronous Stream (CIS)
905  * @param cis_con_handle
906  * @return status
907  * @events GAP_SUBEVENT_CIS_CREATED
908  */
909 uint8_t gap_cis_reject(hci_con_handle_t cis_con_handle);
910 
911 /**
912  * @brief Set connection parameters for outgoing connections and connection parameter updates
913  * @param conn_scan_interval (unit: 0.625 msec), default: 60 ms
914  * @param conn_scan_window (unit: 0.625 msec), default: 30 ms
915  * @param conn_interval_min (unit: 1.25ms), default: 10 ms
916  * @param conn_interval_max (unit: 1.25ms), default: 30 ms
917  * @param conn_latency, default: 4
918  * @param supervision_timeout (unit: 10ms), default: 720 ms
919  * @param min_ce_length (unit: 0.625ms), default: 10 ms
920  * @param max_ce_length (unit: 0.625ms), default: 30 ms
921  */
922 void gap_set_connection_parameters(uint16_t conn_scan_interval, uint16_t conn_scan_window,
923     uint16_t conn_interval_min, uint16_t conn_interval_max, uint16_t conn_latency,
924     uint16_t supervision_timeout, uint16_t min_ce_length, uint16_t max_ce_length);
925 
926 /**
927  * @brief Set initiating PHYs for outgoing connections
928  * @param phy bitmask: 1 = LE 1M PHY, 2 = LE 2M PHY, 4 = LE Coded PHY
929  */
930 void gap_set_connection_phys(uint8_t phys);
931 
932 /**
933  * @brief Request an update of the connection parameter for a given LE connection
934  * @param handle
935  * @param conn_interval_min (unit: 1.25ms)
936  * @param conn_interval_max (unit: 1.25ms)
937  * @param conn_latency
938  * @param supervision_timeout (unit: 10ms)
939  * @return 0 if ok
940  */
941 int gap_request_connection_parameter_update(hci_con_handle_t con_handle, uint16_t conn_interval_min,
942 	uint16_t conn_interval_max, uint16_t conn_latency, uint16_t supervision_timeout);
943 
944 /**
945  * @brief Updates the connection parameters for a given LE connection
946  * @param handle
947  * @param conn_interval_min (unit: 1.25ms)
948  * @param conn_interval_max (unit: 1.25ms)
949  * @param conn_latency
950  * @param supervision_timeout (unit: 10ms)
951  * @return 0 if ok
952  */
953 int gap_update_connection_parameters(hci_con_handle_t con_handle, uint16_t conn_interval_min,
954 	uint16_t conn_interval_max, uint16_t conn_latency, uint16_t supervision_timeout);
955 
956 /**
957  * @brief Set accepted connection parameter range
958  * @param range
959  */
960 void gap_get_connection_parameter_range(le_connection_parameter_range_t * range);
961 
962 /**
963  * @brief Get accepted connection parameter range
964  * @param range
965  */
966 void gap_set_connection_parameter_range(le_connection_parameter_range_t * range);
967 
968 /**
969  * @brief Test if connection parameters are inside in existing rage
970  * @param conn_interval_min (unit: 1.25ms)
971  * @param conn_interval_max (unit: 1.25ms)
972  * @param conn_latency
973  * @param supervision_timeout (unit: 10ms)
974  * @return 1 if included
975  */
976 int gap_connection_parameter_range_included(le_connection_parameter_range_t * existing_range, uint16_t le_conn_interval_min, uint16_t le_conn_interval_max, uint16_t le_conn_latency, uint16_t le_supervision_timeout);
977 
978 /**
979  * @brief Set max number of connections in LE Peripheral role (if Bluetooth Controller supports it)
980  * @note: default: 1
981  * @param max_peripheral_connections
982  */
983 void gap_set_max_number_peripheral_connections(int max_peripheral_connections);
984 
985 /**
986  * @brief Add Device to Whitelist
987  * @param address_typ
988  * @param address
989  * @return 0 if ok
990  */
991 uint8_t gap_whitelist_add(bd_addr_type_t address_type, const bd_addr_t address);
992 
993 /**
994  * @brief Remove Device from Whitelist
995  * @param address_typ
996  * @param address
997  * @return 0 if ok
998  */
999 uint8_t gap_whitelist_remove(bd_addr_type_t address_type, const bd_addr_t address);
1000 
1001 /**
1002  * @brief Clear Whitelist
1003  * @return 0 if ok
1004  */
1005 uint8_t gap_whitelist_clear(void);
1006 
1007 /**
1008  * @brief Connect to remote LE device
1009  */
1010 uint8_t gap_connect(const bd_addr_t addr, bd_addr_type_t addr_type);
1011 
1012 /**
1013  *  @brief Connect with Whitelist
1014  *  @note Explicit whitelist management and this connect with whitelist replace deprecated gap_auto_connection_* functions
1015  *  @return - if ok
1016  */
1017 uint8_t gap_connect_with_whitelist(void);
1018 
1019 /**
1020  * @brief Cancel connection process initiated by gap_connect
1021  */
1022 uint8_t gap_connect_cancel(void);
1023 
1024 /**
1025  * @brief Auto Connection Establishment - Start Connecting to device
1026  * @deprecated Please setup Whitelist with gap_whitelist_* and start connecting with gap_connect_with_whitelist
1027  * @param address_type
1028  * @param address
1029  * @return 0 if ok
1030  */
1031 uint8_t gap_auto_connection_start(bd_addr_type_t address_type, const bd_addr_t address);
1032 
1033 /**
1034  * @brief Auto Connection Establishment - Stop Connecting to device
1035  * @deprecated Please setup Whitelist with gap_whitelist_* and start connecting with gap_connect_with_whitelist
1036  * @param address_type
1037  * @param address
1038  * @return 0 if ok
1039  */
1040 uint8_t gap_auto_connection_stop(bd_addr_type_t address_type, const bd_addr_t address);
1041 
1042 /**
1043  * @brief Auto Connection Establishment - Stop everything
1044  * @deprecated Please setup Whitelist with gap_whitelist_* and start connecting with gap_connect_with_whitelist
1045  * @note  Convenience function to stop all active auto connection attempts
1046  */
1047 uint8_t gap_auto_connection_stop_all(void);
1048 
1049 /**
1050  * @brief Set LE PHY
1051  * @param con_handle
1052  * @param all_phys 0 = set rx/tx, 1 = set only rx, 2 = set only tx
1053  * @param tx_phys 1 = 1M, 2 = 2M, 4 = Coded
1054  * @param rx_phys 1 = 1M, 2 = 2M, 4 = Coded
1055  * @param phy_options 0 = no preferred coding for Coded, 1 = S=2 coding (500 kbit), 2 = S=8 coding (125 kbit)
1056  * @return 0 if ok
1057  */
1058 uint8_t gap_le_set_phy(hci_con_handle_t con_handle, uint8_t all_phys, uint8_t tx_phys, uint8_t rx_phys, uint16_t phy_options);
1059 
1060 /**
1061  * @brief Get connection interval
1062  * @param con_handle
1063  * @return connection interval, otherwise 0 if error
1064  */
1065 uint16_t gap_le_connection_interval(hci_con_handle_t con_handle);
1066 
1067 /**
1068  *
1069  * @brief Get encryption key size.
1070  * @param con_handle
1071  * @return 0 if not encrypted, 7-16 otherwise
1072  */
1073 uint8_t gap_encryption_key_size(hci_con_handle_t con_handle);
1074 
1075 /**
1076  * @brief Get authentication property.
1077  * @param con_handle
1078  * @return 1 if bonded with OOB/Passkey (AND MITM protection)
1079  */
1080 bool gap_authenticated(hci_con_handle_t con_handle);
1081 
1082 /**
1083  * @brief Get secure connection property
1084  * @param con_handle
1085  * @return 1 if bonded usiung LE Secure Connections
1086  */
1087 bool gap_secure_connection(hci_con_handle_t con_handle);
1088 
1089 /**
1090  * @brief Queries authorization state.
1091  * @param con_handle
1092  * @return authorization_state for the current session
1093  */
1094 authorization_state_t gap_authorization_state(hci_con_handle_t con_handle);
1095 
1096 /**
1097  * @brief Get bonded property (BR/EDR/LE)
1098  * @note LE: has to be called after identity resolving is complete
1099  * @param con_handle
1100  * @return true if bonded
1101  */
1102 bool gap_bonded(hci_con_handle_t con_handle);
1103 
1104 // Classic
1105 #ifdef ENABLE_CLASSIC
1106 
1107 /**
1108  * @brief Override page scan mode. Page scan mode enabled by l2cap when services are registered
1109  * @note Might be used to reduce power consumption while Bluetooth module stays powered but no (new)
1110  *       connections are expected
1111  */
1112 void gap_connectable_control(uint8_t enable);
1113 
1114 /**
1115  * @brief Allows to control if device is discoverable. OFF by default.
1116  */
1117 void gap_discoverable_control(uint8_t enable);
1118 
1119 /**
1120  * @brief Deletes link key for remote device with baseband address.
1121  * @param addr
1122  * @note On most desktop ports, the Link Key DB uses a TLV and there is one TLV storage per
1123  *       Controller resp. its Bluetooth Address. As the Bluetooth Address is retrieved during
1124  *       power up, this function only works, when the stack is in working state for these ports.
1125  */
1126 void gap_drop_link_key_for_bd_addr(bd_addr_t addr);
1127 
1128 /**
1129  * @brief Delete all stored link keys
1130  * @note On most desktop ports, the Link Key DB uses a TLV and there is one TLV storage per
1131  *       Controller resp. its Bluetooth Address. As the Bluetooth Address is retrieved during
1132  *       power up, this function only works, when the stack is in working state for these ports.
1133  */
1134 void gap_delete_all_link_keys(void);
1135 
1136 /**
1137  * @brief Store link key for remote device with baseband address
1138  * @param addr
1139  * @param link_key
1140  * @param link_key_type
1141  * @note On most desktop ports, the Link Key DB uses a TLV and there is one TLV storage per
1142  *       Controller resp. its Bluetooth Address. As the Bluetooth Address is retrieved during
1143  *       power up, this function only works, when the stack is in working state for these ports.
1144  */
1145 void gap_store_link_key_for_bd_addr(bd_addr_t addr, link_key_t link_key, link_key_type_t type);
1146 
1147 /**
1148  * @brief Get link for remote device with basband address
1149  * @param addr
1150  * @param link_key (out) is stored here
1151  * @param link_key_type (out) is stored here
1152  * @note On most desktop ports, the Link Key DB uses a TLV and there is one TLV storage per
1153  *       Controller resp. its Bluetooth Address. As the Bluetooth Address is retrieved during
1154  *       power up, this function only works, when the stack is in working state for these ports.
1155  */
1156 bool gap_get_link_key_for_bd_addr(bd_addr_t addr, link_key_t link_key, link_key_type_t * type);
1157 
1158 /**
1159  * @brief Setup Link Key iterator
1160  * @param it
1161  * @return 1 on success
1162  * @note On most desktop ports, the Link Key DB uses a TLV and there is one TLV storage per
1163  *       Controller resp. its Bluetooth Address. As the Bluetooth Address is retrieved during
1164  *       power up, this function only works, when the stack is in working state for these ports.
1165  */
1166 int gap_link_key_iterator_init(btstack_link_key_iterator_t * it);
1167 
1168 /**
1169  * @brief Get next Link Key
1170  * @param it
1171  * @brief addr
1172  * @brief link_key
1173  * @brief type of link key
1174  * @return 1, if valid link key found
1175  * @see note on gap_link_key_iterator_init
1176  */
1177 int gap_link_key_iterator_get_next(btstack_link_key_iterator_t * it, bd_addr_t bd_addr, link_key_t link_key, link_key_type_t * type);
1178 
1179 /**
1180  * @brief Frees resources allocated by iterator_init
1181  * @note Must be called after iteration to free resources
1182  * @param it
1183  * @see note on gap_link_key_iterator_init
1184  */
1185 void gap_link_key_iterator_done(btstack_link_key_iterator_t * it);
1186 
1187 /**
1188  * @brief Start GAP Classic Inquiry
1189  * @param duration in 1.28s units
1190  * @return 0 if ok
1191  * @events: GAP_EVENT_INQUIRY_RESULT, GAP_EVENT_INQUIRY_COMPLETE
1192  */
1193 int gap_inquiry_start(uint8_t duration_in_1280ms_units);
1194 
1195 /**
1196  * @brief Start GAP Classic Periodic Inquiry
1197  * @param duration in 1.28s units
1198  * @param max_period_length between consecutive inquiries in 1.28s units
1199  * @param min_period_length between consecutive inquiries in 1.28s units
1200  * @return 0 if ok
1201  * @events: GAP_EVENT_INQUIRY_RESULT, GAP_EVENT_INQUIRY_COMPLETE
1202  */
1203 uint8_t gap_inquiry_periodic_start(uint8_t duration, uint16_t max_period_length, uint16_t min_period_length);
1204 
1205 /**
1206  * @brief Stop GAP Classic Inquiry (regular or periodic)
1207  * @return 0 if ok
1208  * @events: GAP_EVENT_INQUIRY_COMPLETE
1209  */
1210 int gap_inquiry_stop(void);
1211 
1212 /**
1213  * @brief Set LAP for GAP Classic Inquiry
1214  * @param lap GAP_IAC_GENERAL_INQUIRY (default), GAP_IAC_LIMITED_INQUIRY
1215  */
1216 void gap_inquiry_set_lap(uint32_t lap);
1217 
1218 /**
1219  * @brief Set Inquiry Scan Activity
1220  * @param inquiry_scan_interval range: 0x0012 to 0x1000; only even values are valid, Time = N * 0.625 ms
1221  * @param inquiry_scan_window range: 0x0011 to 0x1000; Time = N * 0.625 ms
1222  */
1223 void gap_inquiry_set_scan_activity(uint16_t inquiry_scan_interval, uint16_t inquiry_scan_window);
1224 
1225 /**
1226  * @brief Set Inquiry Transmit Power Level
1227  * @param tx_power range: -70 to 20 dBm
1228  */
1229 void gap_inquiry_set_transmit_power_level(int8_t tx_power);
1230 
1231 /**
1232  * @brief Remote Name Request
1233  * @param addr
1234  * @param page_scan_repetition_mode
1235  * @param clock_offset only used when bit 15 is set - pass 0 if not known
1236  * @events: HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE
1237  */
1238 int gap_remote_name_request(const bd_addr_t addr, uint8_t page_scan_repetition_mode, uint16_t clock_offset);
1239 
1240 /**
1241  * @brief Legacy Pairing Pin Code Response
1242  * @note data is not copied, pointer has to stay valid
1243  * @param addr
1244  * @param pin
1245  * @return 0 if ok
1246  */
1247 int gap_pin_code_response(const bd_addr_t addr, const char * pin);
1248 
1249 /**
1250  * @brief Legacy Pairing Pin Code Response for binary data / non-strings
1251  * @note data is not copied, pointer has to stay valid
1252  * @param addr
1253  * @param pin_data
1254  * @param pin_len
1255  * @return 0 if ok
1256  */
1257 int gap_pin_code_response_binary(const bd_addr_t addr, const uint8_t * pin_data, uint8_t pin_len);
1258 
1259 /**
1260  * @brief Abort Legacy Pairing
1261  * @param addr
1262  * @param pin
1263  * @return 0 if ok
1264  */
1265 int gap_pin_code_negative(bd_addr_t addr);
1266 
1267 /**
1268  * @brief SSP Passkey Response
1269  * @param addr
1270  * @param passkey [0..999999]
1271  * @return 0 if ok
1272  */
1273 int gap_ssp_passkey_response(const bd_addr_t addr, uint32_t passkey);
1274 
1275 /**
1276  * @brief Abort SSP Passkey Entry/Pairing
1277  * @param addr
1278  * @param pin
1279  * @return 0 if ok
1280  */
1281 int gap_ssp_passkey_negative(const bd_addr_t addr);
1282 
1283 /**
1284  * @brief Accept SSP Numeric Comparison
1285  * @param addr
1286  * @param passkey
1287  * @return 0 if ok
1288  */
1289 int gap_ssp_confirmation_response(const bd_addr_t addr);
1290 
1291 /**
1292  * @brief Abort SSP Numeric Comparison/Pairing
1293  * @param addr
1294  * @param pin
1295  * @return 0 if ok
1296  */
1297 int gap_ssp_confirmation_negative(const bd_addr_t addr);
1298 
1299 /**
1300  * @brief Generate new OOB data
1301  * @note OOB data will be provided in GAP_EVENT_LOCAL_OOB_DATA and be used in future pairing procedures
1302  */
1303 void gap_ssp_generate_oob_data(void);
1304 
1305 /**
1306  * @brief Report Remote OOB Data
1307  * @note Pairing Hash and Randomizer are expected in big-endian byte format
1308  * @param bd_addr
1309  * @param c_192 Simple Pairing Hash C derived from P-192 public key
1310  * @param r_192 Simple Pairing Randomizer derived from P-192 public key
1311  * @param c_256 Simple Pairing Hash C derived from P-256 public key
1312  * @param r_256 Simple Pairing Randomizer derived from P-256 public key
1313  */
1314 uint8_t gap_ssp_remote_oob_data(const bd_addr_t addr, const uint8_t * c_192, const uint8_t * r_192, const uint8_t * c_256, const uint8_t * r_256);
1315 
1316 /**
1317  * Send SSP IO Capabilities Reply
1318  * @note IO Capabilities (Negative) Reply is sent automatically unless ENABLE_EXPLICIT_IO_CAPABILITIES_REPLY
1319  * @param addr
1320  * @return 0 if ok
1321  */
1322 uint8_t gap_ssp_io_capabilities_response(const bd_addr_t addr);
1323 
1324 /**
1325  * Send SSP IO Capabilities Negative Reply
1326  * @note IO Capabilities (Negative) Reply is sent automatically unless ENABLE_EXPLICIT_IO_CAPABILITIES_REPLY
1327  * @param addr
1328  * @return 0 if ok
1329  */
1330 uint8_t gap_ssp_io_capabilities_negative(const bd_addr_t addr);
1331 
1332 /**
1333  * Send Link Key Reponse
1334  * @note Link Key (Negative) Reply is sent automatically unless ENABLE_EXPLICIT_LINK_KEY_RESPONSE
1335  * @param addr
1336  * @param link_key
1337  * @param type or INVALID_LINK_KEY if link key not available
1338  * @return 0 if ok
1339  */
1340  uint8_t gap_send_link_key_response(const bd_addr_t addr, link_key_t link_key, link_key_type_t type);
1341 
1342 /**
1343  * @brief Enter Sniff mode
1344  * @param con_handle
1345  * @param sniff_min_interval range: 0x0002 to 0xFFFE; only even values are valid, Time = N * 0.625 ms
1346  * @param sniff_max_interval range: 0x0002 to 0xFFFE; only even values are valid, Time = N * 0.625 ms
1347  * @param sniff_attempt Number of Baseband receive slots for sniff attempt.
1348  * @param sniff_timeout Number of Baseband receive slots for sniff timeout.
1349  @ @return 0 if ok
1350  */
1351 uint8_t gap_sniff_mode_enter(hci_con_handle_t con_handle, uint16_t sniff_min_interval, uint16_t sniff_max_interval, uint16_t sniff_attempt, uint16_t sniff_timeout);
1352 
1353 /**
1354  * @brief Exit Sniff mode
1355  * @param con_handle
1356  @ @return 0 if ok
1357  */
1358 uint8_t gap_sniff_mode_exit(hci_con_handle_t con_handle);
1359 
1360 /**
1361  * @brief Configure Sniff Subrating
1362  * @param con_handle
1363  * @param max_latency range: 0x0002 to 0xFFFE; Time = N * 0.625 ms
1364  * @param min_remote_timeout range:  0x0002 to 0xFFFE; Time = N * 0.625 ms
1365  * @param min_local_timeout range:  0x0002 to 0xFFFE; Time = N * 0.625 ms
1366  @ @return 0 if ok
1367  */
1368 uint8_t gap_sniff_subrating_configure(hci_con_handle_t con_handle, uint16_t max_latency, uint16_t min_remote_timeout, uint16_t min_local_timeout);
1369 
1370 /**
1371  * @Brief Set QoS
1372  * @param con_handle
1373  * @param service_type
1374  * @param token_rate
1375  * @param peak_bandwidth
1376  * @param latency
1377  * @param delay_variation
1378  @ @return 0 if ok
1379  */
1380 uint8_t gap_qos_set(hci_con_handle_t con_handle, hci_service_type_t service_type, uint32_t token_rate, uint32_t peak_bandwidth, uint32_t latency, uint32_t delay_variation);
1381 
1382 #endif
1383 
1384 // LE
1385 
1386 /**
1387  * @brief Get own addr type and address used for LE for next scan/advertisement/connect operation
1388  */
1389 void gap_le_get_own_address(uint8_t * addr_type, bd_addr_t addr);
1390 
1391 /**
1392  * @brief Get own addr type and address used for LE advertisements (Peripheral)
1393  */
1394 void gap_le_get_own_advertisements_address(uint8_t * addr_type, bd_addr_t addr);
1395 
1396 /**
1397  * @brief Get own addr type and address used for LE connections (Central)
1398  */
1399 void gap_le_get_own_connection_address(uint8_t * addr_type, bd_addr_t addr);
1400 
1401 /**
1402  * @brief Get state of connection re-encryption for bonded devices when in central role
1403  * @note used by gatt_client and att_server to wait for re-encryption
1404  * @param con_handle
1405  * @return 1 if security setup is active
1406  */
1407 int gap_reconnect_security_setup_active(hci_con_handle_t con_handle);
1408 
1409 /**
1410  * @brief Delete bonding information for remote device
1411  * @note On most desktop ports, the LE Device DB uses a TLV and there is one TLV storage per
1412  *       Controller resp. its Bluetooth Address. As the Bluetooth Address is retrieved during
1413  *       power up, this function only works, when the stack is in working state for these ports.
1414  * @param address_type
1415  * @param address
1416  */
1417 void gap_delete_bonding(bd_addr_type_t address_type, bd_addr_t address);
1418 
1419 /**
1420  * LE Privacy 1.2 - requires support by Controller and ENABLE_LE_RESOLVING_LIST to be defined
1421  */
1422 
1423 /**
1424  * Set Privacy Mode for use in Resolving List. Default: LE_PRIVACY_MODE_DEVICE
1425  * @note Only applies for new devices added to resolving list, please call before startup
1426  * @param privacy_mode
1427  */
1428 void gap_set_peer_privacy_mode(le_privacy_mode_t privacy_mode );
1429 
1430 /**
1431  * @brief Load LE Device DB entries into Controller Resolving List to allow filtering on
1432  *        bonded devies with resolvable private addresses
1433  * @return EROOR_CODE_SUCCESS if supported by Controller
1434  */
1435 uint8_t gap_load_resolving_list_from_le_device_db(void);
1436 
1437 /**
1438  * @brief Get local persistent IRK
1439  */
1440 const uint8_t * gap_get_persistent_irk(void);
1441 
1442 /* API_END*/
1443 
1444 #if defined __cplusplus
1445 }
1446 #endif
1447 
1448 #endif // GAP_H
1449