xref: /btstack/src/gap.h (revision 07e010b651aa0c21250aae7989f803919cab78d2)
1458bf4e8S[email protected] /*
2a0c35809S[email protected]  * Copyright (C) 2014 BlueKitchen GmbH
3458bf4e8S[email protected]  *
4458bf4e8S[email protected]  * Redistribution and use in source and binary forms, with or without
5458bf4e8S[email protected]  * modification, are permitted provided that the following conditions
6458bf4e8S[email protected]  * are met:
7458bf4e8S[email protected]  *
8458bf4e8S[email protected]  * 1. Redistributions of source code must retain the above copyright
9458bf4e8S[email protected]  *    notice, this list of conditions and the following disclaimer.
10458bf4e8S[email protected]  * 2. Redistributions in binary form must reproduce the above copyright
11458bf4e8S[email protected]  *    notice, this list of conditions and the following disclaimer in the
12458bf4e8S[email protected]  *    documentation and/or other materials provided with the distribution.
13458bf4e8S[email protected]  * 3. Neither the name of the copyright holders nor the names of
14458bf4e8S[email protected]  *    contributors may be used to endorse or promote products derived
15458bf4e8S[email protected]  *    from this software without specific prior written permission.
16458bf4e8S[email protected]  * 4. Any redistribution, use, or modification is done solely for
17458bf4e8S[email protected]  *    personal benefit and not for any commercial purpose or for
18458bf4e8S[email protected]  *    monetary gain.
19458bf4e8S[email protected]  *
20a0c35809S[email protected]  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21458bf4e8S[email protected]  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22458bf4e8S[email protected]  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23458bf4e8S[email protected]  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
24458bf4e8S[email protected]  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25458bf4e8S[email protected]  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26458bf4e8S[email protected]  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27458bf4e8S[email protected]  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28458bf4e8S[email protected]  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29458bf4e8S[email protected]  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30458bf4e8S[email protected]  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31458bf4e8S[email protected]  * SUCH DAMAGE.
32458bf4e8S[email protected]  *
33a0c35809S[email protected]  * Please inquire about commercial licensing options at
34a0c35809S[email protected]  * [email protected]
35458bf4e8S[email protected]  *
36458bf4e8S[email protected]  */
37458bf4e8S[email protected] 
3880e33422SMatthias Ringwald #ifndef GAP_H
3980e33422SMatthias Ringwald #define GAP_H
40458bf4e8S[email protected] 
41458bf4e8S[email protected] #if defined __cplusplus
42458bf4e8S[email protected] extern "C" {
43458bf4e8S[email protected] #endif
44458bf4e8S[email protected] 
45f7a05cdaSMatthias Ringwald #include "btstack_defines.h"
46eb886013SMatthias Ringwald #include "btstack_util.h"
471b6fb31bSMatthias Ringwald #include "classic/btstack_link_key_db.h"
48f7a05cdaSMatthias Ringwald 
49cb230b9dS[email protected] typedef enum {
50cb230b9dS[email protected] 
51cb230b9dS[email protected] 	// MITM protection not required
52cb230b9dS[email protected] 	// No encryption required
53cb230b9dS[email protected] 	// No user interaction required
54cb230b9dS[email protected] 	LEVEL_0 = 0,
55cb230b9dS[email protected] 
56cb230b9dS[email protected] 	// MITM protection not required
57cb230b9dS[email protected] 	// No encryption required
58cb230b9dS[email protected] 	// Minimal user interaction desired
59cb230b9dS[email protected] 	LEVEL_1,
60cb230b9dS[email protected] 
61cb230b9dS[email protected] 	// MITM protection not required
62cb230b9dS[email protected] 	// Encryption required
63cb230b9dS[email protected] 	LEVEL_2,
64cb230b9dS[email protected] 
65cb230b9dS[email protected] 	// MITM protection required
66cb230b9dS[email protected] 	// Encryption required
67cb230b9dS[email protected] 	// User interaction acceptable
68cb230b9dS[email protected] 	LEVEL_3,
69cb230b9dS[email protected] 
70cb230b9dS[email protected] 	// MITM protection required
71cb230b9dS[email protected] 	// Encryption required
723c68dfa9S[email protected] 	// 128-bit equivalent strength for link and encryption keys required (P-192 is not enough)
73cb230b9dS[email protected] 	// User interaction acceptable
74cb230b9dS[email protected] 	LEVEL_4,
75cb230b9dS[email protected] } gap_security_level_t;
76cb230b9dS[email protected] 
7734f9eab8S[email protected] typedef enum {
7834f9eab8S[email protected] 	GAP_SECURITY_NONE,
7934f9eab8S[email protected] 	GAP_SECUIRTY_ENCRYPTED,		// SSP: JUST WORKS
8034f9eab8S[email protected] 	GAP_SECURITY_AUTHENTICATED, // SSP: numeric comparison, passkey, OOB
8134f9eab8S[email protected] 	// GAP_SECURITY_AUTHORIZED
823c68dfa9S[email protected] } gap_security_state;
8334f9eab8S[email protected] 
84a1bf5ae7SMatthias Ringwald typedef enum {
85a1bf5ae7SMatthias Ringwald 	GAP_CONNECTION_INVALID,
86a1bf5ae7SMatthias Ringwald 	GAP_CONNECTION_ACL,
87a1bf5ae7SMatthias Ringwald 	GAP_CONNECTION_SCO,
88a1bf5ae7SMatthias Ringwald 	GAP_CONNECTION_LE
89a1bf5ae7SMatthias Ringwald } gap_connection_type_t;
90a1bf5ae7SMatthias Ringwald 
916e364deaSMatthias Ringwald typedef struct le_connection_parameter_range{
926e364deaSMatthias Ringwald     uint16_t le_conn_interval_min;
936e364deaSMatthias Ringwald     uint16_t le_conn_interval_max;
946e364deaSMatthias Ringwald     uint16_t le_conn_latency_min;
956e364deaSMatthias Ringwald     uint16_t le_conn_latency_max;
966e364deaSMatthias Ringwald     uint16_t le_supervision_timeout_min;
976e364deaSMatthias Ringwald     uint16_t le_supervision_timeout_max;
986e364deaSMatthias Ringwald } le_connection_parameter_range_t;
996e364deaSMatthias Ringwald 
1006e364deaSMatthias Ringwald typedef enum {
1016e364deaSMatthias Ringwald     GAP_RANDOM_ADDRESS_TYPE_OFF = 0,
1028f57b085SMatthias Ringwald     GAP_RANDOM_ADDRESS_TYPE_STATIC,
1036e364deaSMatthias Ringwald     GAP_RANDOM_ADDRESS_NON_RESOLVABLE,
1046e364deaSMatthias Ringwald     GAP_RANDOM_ADDRESS_RESOLVABLE,
1056e364deaSMatthias Ringwald } gap_random_address_type_t;
1066e364deaSMatthias Ringwald 
1079c6e867eSMatthias Ringwald // Authorization state
1089c6e867eSMatthias Ringwald typedef enum {
1099c6e867eSMatthias Ringwald     AUTHORIZATION_UNKNOWN,
1109c6e867eSMatthias Ringwald     AUTHORIZATION_PENDING,
1119c6e867eSMatthias Ringwald     AUTHORIZATION_DECLINED,
1129c6e867eSMatthias Ringwald     AUTHORIZATION_GRANTED
1139c6e867eSMatthias Ringwald } authorization_state_t;
1149c6e867eSMatthias Ringwald 
1159c6e867eSMatthias Ringwald 
1163de95307SMilanka Ringwald /* API_START */
1173de95307SMilanka Ringwald 
118d8e8f12aSMatthias Ringwald // Classic + LE
119d8e8f12aSMatthias Ringwald 
120d8e8f12aSMatthias Ringwald /**
121d8e8f12aSMatthias Ringwald  * @brief Disconnect connection with handle
122d8e8f12aSMatthias Ringwald  * @param handle
123d8e8f12aSMatthias Ringwald  */
124d8e8f12aSMatthias Ringwald uint8_t gap_disconnect(hci_con_handle_t handle);
125d8e8f12aSMatthias Ringwald 
126d8e8f12aSMatthias Ringwald /**
127d8e8f12aSMatthias Ringwald  * @brief Get connection type
128d8e8f12aSMatthias Ringwald  * @param con_handle
129d8e8f12aSMatthias Ringwald  * @result connection_type
130d8e8f12aSMatthias Ringwald  */
131d8e8f12aSMatthias Ringwald gap_connection_type_t gap_get_connection_type(hci_con_handle_t connection_handle);
132d8e8f12aSMatthias Ringwald 
133d8e8f12aSMatthias Ringwald // Classic
134d8e8f12aSMatthias Ringwald 
135d8e8f12aSMatthias Ringwald /**
136d8e8f12aSMatthias Ringwald  * @brief Sets local name.
137d8e8f12aSMatthias Ringwald  * @note has to be done before stack starts up
138ad0d1108SMatthias Ringwald  * @note Default name is 'BTstack 00:00:00:00:00:00'
139f868b059SMatthias Ringwald  * @note '00:00:00:00:00:00' in local_name will be replaced with actual bd addr
140ad0d1108SMatthias Ringwald  * @param name is not copied, make sure memory is accessible during stack startup
141d8e8f12aSMatthias Ringwald  */
142d8e8f12aSMatthias Ringwald void gap_set_local_name(const char * local_name);
143d8e8f12aSMatthias Ringwald 
144458bf4e8S[email protected] /**
145ff00ed1cSMatthias Ringwald  * @brief Set Extended Inquiry Response data
146ff00ed1cSMatthias Ringwald  * @note has to be done before stack starts up
147ad0d1108SMatthias Ringwald  * @note If not set, local name will be used for EIR data (see gap_set_local_name)
148f868b059SMatthias Ringwald  * @note '00:00:00:00:00:00' in local_name will be replaced with actual bd addr
149ad0d1108SMatthias Ringwald  * @param eir_data size 240 bytes, is not copied make sure memory is accessible during stack startup
150ff00ed1cSMatthias Ringwald  */
151ff00ed1cSMatthias Ringwald void gap_set_extended_inquiry_response(const uint8_t * data);
152ff00ed1cSMatthias Ringwald 
153ff00ed1cSMatthias Ringwald /**
15460b9e82fSMatthias Ringwald  * @brief Set class of device that will be set during Bluetooth init.
15560b9e82fSMatthias Ringwald  * @note has to be done before stack starts up
15660b9e82fSMatthias Ringwald  */
15760b9e82fSMatthias Ringwald void gap_set_class_of_device(uint32_t class_of_device);
15860b9e82fSMatthias Ringwald 
15960b9e82fSMatthias Ringwald /**
160c33e56d3SMatthias Ringwald  * @brief Set default link policy settings for all classic ACL links
161c33e56d3SMatthias Ringwald  * @param default_link_policy_settings - see LM_LINK_POLICY_* in bluetooth.h
162c33e56d3SMatthias Ringwald  * @note common value: LM_LINK_POLICY_ENABLE_ROLE_SWITCH | LM_LINK_POLICY_ENABLE_SNIFF_MODE to enable role switch and sniff mode
163c33e56d3SMatthias Ringwald  * @note has to be done before stack starts up
164c33e56d3SMatthias Ringwald  */
165c33e56d3SMatthias Ringwald void gap_set_default_link_policy_settings(uint16_t default_link_policy_settings);
166c33e56d3SMatthias Ringwald 
167c33e56d3SMatthias Ringwald /**
1683de95307SMilanka Ringwald  * @brief Enable/disable bonding. Default is enabled.
1693de95307SMilanka Ringwald  * @param enabled
170458bf4e8S[email protected]  */
171458bf4e8S[email protected] void gap_set_bondable_mode(int enabled);
17234d2123cS[email protected] 
173ad83dc6aS[email protected] /**
174671d15e6SMatthias Ringwald  * @brief Get bondable mode.
175671d15e6SMatthias Ringwald  * @return 1 if bondable
176671d15e6SMatthias Ringwald  */
177671d15e6SMatthias Ringwald int gap_get_bondable_mode(void);
178671d15e6SMatthias Ringwald 
179*07e010b6SMilanka Ringwald /**
180*07e010b6SMilanka Ringwald  * @brief Register filter for rejecting classic connections. Callback will return 1 accept connection, 0 on reject.
181*07e010b6SMilanka Ringwald  */
182*07e010b6SMilanka Ringwald 
183*07e010b6SMilanka Ringwald void gap_register_classic_connection_filter(int (*accept_callback)(bd_addr_t addr));
184*07e010b6SMilanka Ringwald 
185*07e010b6SMilanka Ringwald 
18615a95bd5SMatthias Ringwald /* Configure Secure Simple Pairing */
18715a95bd5SMatthias Ringwald 
18815a95bd5SMatthias Ringwald /**
18915a95bd5SMatthias Ringwald  * @brief Enable will enable SSP during init.
19015a95bd5SMatthias Ringwald  */
19115a95bd5SMatthias Ringwald void gap_ssp_set_enable(int enable);
19215a95bd5SMatthias Ringwald 
19315a95bd5SMatthias Ringwald /**
19415a95bd5SMatthias Ringwald  * @brief Set IO Capability. BTstack will return capability to SSP requests
19515a95bd5SMatthias Ringwald  */
19615a95bd5SMatthias Ringwald void gap_ssp_set_io_capability(int ssp_io_capability);
19715a95bd5SMatthias Ringwald 
19815a95bd5SMatthias Ringwald /**
19915a95bd5SMatthias Ringwald  * @brief Set Authentication Requirements using during SSP
20015a95bd5SMatthias Ringwald  */
20115a95bd5SMatthias Ringwald void gap_ssp_set_authentication_requirement(int authentication_requirement);
20215a95bd5SMatthias Ringwald 
20315a95bd5SMatthias Ringwald /**
20415a95bd5SMatthias Ringwald  * @brief If set, BTstack will confirm a numeric comparison and enter '000000' if requested.
20515a95bd5SMatthias Ringwald  */
20615a95bd5SMatthias Ringwald void gap_ssp_set_auto_accept(int auto_accept);
20715a95bd5SMatthias Ringwald 
208671d15e6SMatthias Ringwald /**
209170fafaeSMatthias Ringwald  * @brief Set required encryption key size for GAP Levels 1-3 on ccassic connections. Default: 16 bytes
210170fafaeSMatthias Ringwald  * @param encryption_key_size in bytes. Valid 7..16
211170fafaeSMatthias Ringwald  */
212170fafaeSMatthias Ringwald void gap_set_required_encryption_key_size(uint8_t encryption_key_size);
213170fafaeSMatthias Ringwald 
214170fafaeSMatthias Ringwald /**
2153de95307SMilanka Ringwald  * @brief Start dedicated bonding with device. Disconnect after bonding.
216ad83dc6aS[email protected]  * @param device
217ad83dc6aS[email protected]  * @param request MITM protection
2183de95307SMilanka Ringwald  * @return error, if max num acl connections active
219ad83dc6aS[email protected]  * @result GAP_DEDICATED_BONDING_COMPLETE
220ad83dc6aS[email protected]  */
221ad83dc6aS[email protected] int gap_dedicated_bonding(bd_addr_t device, int mitm_protection_required);
222ad83dc6aS[email protected] 
22334d2123cS[email protected] gap_security_level_t gap_security_level_for_link_key_type(link_key_type_t link_key_type);
2248b35e16aSMatthias Ringwald 
2258b35e16aSMatthias Ringwald /**
2268b35e16aSMatthias Ringwald  * @brief map link keys to secure connection yes/no
2278b35e16aSMatthias Ringwald  */
2288b35e16aSMatthias Ringwald int gap_secure_connection_for_link_key_type(link_key_type_t link_key_type);
2298b35e16aSMatthias Ringwald 
2308b35e16aSMatthias Ringwald /**
2318b35e16aSMatthias Ringwald  * @brief map link keys to authenticated
2328b35e16aSMatthias Ringwald  */
2338b35e16aSMatthias Ringwald int gap_authenticated_for_link_key_type(link_key_type_t link_key_type);
2348b35e16aSMatthias Ringwald 
235ad671560S[email protected] gap_security_level_t gap_security_level(hci_con_handle_t con_handle);
23634d2123cS[email protected] 
237ad671560S[email protected] void gap_request_security_level(hci_con_handle_t con_handle, gap_security_level_t level);
238d8e8f12aSMatthias Ringwald 
239106d6d11S[email protected] int  gap_mitm_protection_required_for_security_level(gap_security_level_t level);
240458bf4e8S[email protected] 
241d8e8f12aSMatthias Ringwald // LE
2428e618f72S[email protected] 
243a1bf5ae7SMatthias Ringwald /**
244d8e8f12aSMatthias Ringwald  * @brief Set parameters for LE Scan
245a1bf5ae7SMatthias Ringwald  */
246d8e8f12aSMatthias Ringwald void gap_set_scan_parameters(uint8_t scan_type, uint16_t scan_interval, uint16_t scan_window);
247d8e8f12aSMatthias Ringwald 
248d8e8f12aSMatthias Ringwald /**
249d8e8f12aSMatthias Ringwald  * @brief Start LE Scan
250d8e8f12aSMatthias Ringwald  */
251d8e8f12aSMatthias Ringwald void gap_start_scan(void);
252d8e8f12aSMatthias Ringwald 
253d8e8f12aSMatthias Ringwald /**
254d8e8f12aSMatthias Ringwald  * @brief Stop LE Scan
255d8e8f12aSMatthias Ringwald  */
256d8e8f12aSMatthias Ringwald void gap_stop_scan(void);
257a1bf5ae7SMatthias Ringwald 
258f7a05cdaSMatthias Ringwald /**
259f7a05cdaSMatthias Ringwald  * @brief Enable privacy by using random addresses
260f7a05cdaSMatthias Ringwald  * @param random_address_type to use (incl. OFF)
261f7a05cdaSMatthias Ringwald  */
262f7a05cdaSMatthias Ringwald void gap_random_address_set_mode(gap_random_address_type_t random_address_type);
263f7a05cdaSMatthias Ringwald 
264f7a05cdaSMatthias Ringwald /**
265f7a05cdaSMatthias Ringwald  * @brief Get privacy mode
266f7a05cdaSMatthias Ringwald  */
267f7a05cdaSMatthias Ringwald gap_random_address_type_t gap_random_address_get_mode(void);
268f7a05cdaSMatthias Ringwald 
269f7a05cdaSMatthias Ringwald /**
270f7a05cdaSMatthias Ringwald  * @brief Sets update period for random address
271f7a05cdaSMatthias Ringwald  * @param period_ms in ms
272f7a05cdaSMatthias Ringwald  */
273f7a05cdaSMatthias Ringwald  void gap_random_address_set_update_period(int period_ms);
274f7a05cdaSMatthias Ringwald 
275f7a05cdaSMatthias Ringwald /**
2767e252622SMatthias Ringwald  * @brief Sets a fixed random address for advertising
2777e252622SMatthias Ringwald  * @param addr
2787e252622SMatthias Ringwald  * @note Sets random address mode to type off
2797e252622SMatthias Ringwald  */
2807e252622SMatthias Ringwald void gap_random_address_set(bd_addr_t addr);
2817e252622SMatthias Ringwald 
2827e252622SMatthias Ringwald /**
283f7a05cdaSMatthias Ringwald  * @brief Set Advertisement Data
284f7a05cdaSMatthias Ringwald  * @param advertising_data_length
285f7a05cdaSMatthias Ringwald  * @param advertising_data (max 31 octets)
286f7a05cdaSMatthias Ringwald  * @note data is not copied, pointer has to stay valid
287f868b059SMatthias Ringwald  * @note '00:00:00:00:00:00' in advertising_data will be replaced with actual bd addr
288f7a05cdaSMatthias Ringwald  */
289f7a05cdaSMatthias Ringwald void gap_advertisements_set_data(uint8_t advertising_data_length, uint8_t * advertising_data);
290f7a05cdaSMatthias Ringwald 
291f7a05cdaSMatthias Ringwald /**
292f7a05cdaSMatthias Ringwald  * @brief Set Advertisement Paramters
293f7a05cdaSMatthias Ringwald  * @param adv_int_min
294f7a05cdaSMatthias Ringwald  * @param adv_int_max
295f7a05cdaSMatthias Ringwald  * @param adv_type
296f7a05cdaSMatthias Ringwald  * @param direct_address_type
297f7a05cdaSMatthias Ringwald  * @param direct_address
298f7a05cdaSMatthias Ringwald  * @param channel_map
299f7a05cdaSMatthias Ringwald  * @param filter_policy
300f7a05cdaSMatthias Ringwald  * @note own_address_type is used from gap_random_address_set_mode
301f7a05cdaSMatthias Ringwald  */
302f7a05cdaSMatthias Ringwald void gap_advertisements_set_params(uint16_t adv_int_min, uint16_t adv_int_max, uint8_t adv_type,
303f7a05cdaSMatthias Ringwald 	uint8_t direct_address_typ, bd_addr_t direct_address, uint8_t channel_map, uint8_t filter_policy);
304f7a05cdaSMatthias Ringwald 
305f7a05cdaSMatthias Ringwald /**
306cb264910SMatthias Ringwald  * @brief Enable/Disable Advertisements. OFF by default.
307f7a05cdaSMatthias Ringwald  * @param enabled
308f7a05cdaSMatthias Ringwald  */
309f7a05cdaSMatthias Ringwald void gap_advertisements_enable(int enabled);
310501f56b3SMatthias Ringwald 
311501f56b3SMatthias Ringwald /**
312501f56b3SMatthias Ringwald  * @brief Set Scan Response Data
313501f56b3SMatthias Ringwald  *
314501f56b3SMatthias Ringwald  * @note For scan response data, scannable undirected advertising (ADV_SCAN_IND) need to be used
315501f56b3SMatthias Ringwald  *
316501f56b3SMatthias Ringwald  * @param advertising_data_length
317501f56b3SMatthias Ringwald  * @param advertising_data (max 31 octets)
318501f56b3SMatthias Ringwald  * @note data is not copied, pointer has to stay valid
319f868b059SMatthias Ringwald  * @note '00:00:00:00:00:00' in scan_response_data will be replaced with actual bd addr
320501f56b3SMatthias Ringwald  */
321501f56b3SMatthias Ringwald void gap_scan_response_set_data(uint8_t scan_response_data_length, uint8_t * scan_response_data);
322501f56b3SMatthias Ringwald 
323d8e8f12aSMatthias Ringwald /**
3246012052bSMatthias Ringwald  * @brief Set connection parameters for outgoing connections
325cbe54ab2SJakob Krantz  * @param conn_scan_interval (unit: 0.625 msec), default: 60 ms
326cbe54ab2SJakob Krantz  * @param conn_scan_window (unit: 0.625 msec), default: 30 ms
3276012052bSMatthias Ringwald  * @param conn_interval_min (unit: 1.25ms), default: 10 ms
3286012052bSMatthias Ringwald  * @param conn_interval_max (unit: 1.25ms), default: 30 ms
3296012052bSMatthias Ringwald  * @param conn_latency, default: 4
3306012052bSMatthias Ringwald  * @param supervision_timeout (unit: 10ms), default: 720 ms
3316012052bSMatthias Ringwald  * @param min_ce_length (unit: 0.625ms), default: 10 ms
3326012052bSMatthias Ringwald  * @param max_ce_length (unit: 0.625ms), default: 30 ms
3336012052bSMatthias Ringwald  */
334cbe54ab2SJakob Krantz void gap_set_connection_parameters(uint16_t conn_scan_interval, uint16_t conn_scan_window,
335cbe54ab2SJakob Krantz     uint16_t conn_interval_min, uint16_t conn_interval_max, uint16_t conn_latency,
336cbe54ab2SJakob Krantz     uint16_t supervision_timeout, uint16_t min_ce_length, uint16_t max_ce_length);
3376012052bSMatthias Ringwald 
3386012052bSMatthias Ringwald /**
339d8e8f12aSMatthias Ringwald  * @brief Request an update of the connection parameter for a given LE connection
340d8e8f12aSMatthias Ringwald  * @param handle
341d8e8f12aSMatthias Ringwald  * @param conn_interval_min (unit: 1.25ms)
342d8e8f12aSMatthias Ringwald  * @param conn_interval_max (unit: 1.25ms)
343d8e8f12aSMatthias Ringwald  * @param conn_latency
344d8e8f12aSMatthias Ringwald  * @param supervision_timeout (unit: 10ms)
345d8e8f12aSMatthias Ringwald  * @returns 0 if ok
346d8e8f12aSMatthias Ringwald  */
347d8e8f12aSMatthias Ringwald int gap_request_connection_parameter_update(hci_con_handle_t con_handle, uint16_t conn_interval_min,
348d8e8f12aSMatthias Ringwald 	uint16_t conn_interval_max, uint16_t conn_latency, uint16_t supervision_timeout);
349d8e8f12aSMatthias Ringwald 
350d8e8f12aSMatthias Ringwald /**
351d8e8f12aSMatthias Ringwald  * @brief Updates the connection parameters for a given LE connection
352d8e8f12aSMatthias Ringwald  * @param handle
353d8e8f12aSMatthias Ringwald  * @param conn_interval_min (unit: 1.25ms)
354d8e8f12aSMatthias Ringwald  * @param conn_interval_max (unit: 1.25ms)
355d8e8f12aSMatthias Ringwald  * @param conn_latency
356d8e8f12aSMatthias Ringwald  * @param supervision_timeout (unit: 10ms)
357d8e8f12aSMatthias Ringwald  * @returns 0 if ok
358d8e8f12aSMatthias Ringwald  */
359d8e8f12aSMatthias Ringwald int gap_update_connection_parameters(hci_con_handle_t con_handle, uint16_t conn_interval_min,
360d8e8f12aSMatthias Ringwald 	uint16_t conn_interval_max, uint16_t conn_latency, uint16_t supervision_timeout);
361d8e8f12aSMatthias Ringwald 
362d8e8f12aSMatthias Ringwald /**
363d8e8f12aSMatthias Ringwald  * @brief Set accepted connection parameter range
364d8e8f12aSMatthias Ringwald  * @param range
365d8e8f12aSMatthias Ringwald  */
3664ced4e8cSMatthias Ringwald void gap_get_connection_parameter_range(le_connection_parameter_range_t * range);
367d8e8f12aSMatthias Ringwald 
368d8e8f12aSMatthias Ringwald /**
369d8e8f12aSMatthias Ringwald  * @brief Get accepted connection parameter range
370d8e8f12aSMatthias Ringwald  * @param range
371d8e8f12aSMatthias Ringwald  */
3724ced4e8cSMatthias Ringwald void gap_set_connection_parameter_range(le_connection_parameter_range_t * range);
373d8e8f12aSMatthias Ringwald 
374d8e8f12aSMatthias Ringwald /**
37573cd8a2aSMatthias Ringwald  * @brief Test if connection parameters are inside in existing rage
37673cd8a2aSMatthias Ringwald  * @param conn_interval_min (unit: 1.25ms)
37773cd8a2aSMatthias Ringwald  * @param conn_interval_max (unit: 1.25ms)
37873cd8a2aSMatthias Ringwald  * @param conn_latency
37973cd8a2aSMatthias Ringwald  * @param supervision_timeout (unit: 10ms)
38073cd8a2aSMatthias Ringwald  * @returns 1 if included
38173cd8a2aSMatthias Ringwald  */
38273cd8a2aSMatthias Ringwald 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);
38373cd8a2aSMatthias Ringwald 
38473cd8a2aSMatthias Ringwald /**
3852b6ab3e6SMatthias Ringwald  * @brief Set max number of connections in LE Peripheral role (if Bluetooth Controller supports it)
3862b6ab3e6SMatthias Ringwald  * @note: default: 1
3872b6ab3e6SMatthias Ringwald  * @param max_peripheral_connections
3882b6ab3e6SMatthias Ringwald  */
3892b6ab3e6SMatthias Ringwald void gap_set_max_number_peripheral_connections(int max_peripheral_connections);
3902b6ab3e6SMatthias Ringwald 
3912b6ab3e6SMatthias Ringwald /**
392d8e8f12aSMatthias Ringwald  * @brief Connect to remote LE device
393d8e8f12aSMatthias Ringwald  */
394d8e8f12aSMatthias Ringwald uint8_t gap_connect(bd_addr_t addr, bd_addr_type_t addr_type);
395d8e8f12aSMatthias Ringwald 
396d8e8f12aSMatthias Ringwald /**
397d8e8f12aSMatthias Ringwald  * @brief Cancel connection process initiated by gap_connect
398d8e8f12aSMatthias Ringwald  */
399d8e8f12aSMatthias Ringwald uint8_t gap_connect_cancel(void);
400f7a05cdaSMatthias Ringwald 
401f7a05cdaSMatthias Ringwald /**
402f7a05cdaSMatthias Ringwald  * @brief Auto Connection Establishment - Start Connecting to device
403f7a05cdaSMatthias Ringwald  * @param address_typ
404f7a05cdaSMatthias Ringwald  * @param address
405f7a05cdaSMatthias Ringwald  * @returns 0 if ok
406f7a05cdaSMatthias Ringwald  */
407f7a05cdaSMatthias Ringwald int gap_auto_connection_start(bd_addr_type_t address_typ, bd_addr_t address);
408f7a05cdaSMatthias Ringwald 
409f7a05cdaSMatthias Ringwald /**
410f7a05cdaSMatthias Ringwald  * @brief Auto Connection Establishment - Stop Connecting to device
411f7a05cdaSMatthias Ringwald  * @param address_typ
412f7a05cdaSMatthias Ringwald  * @param address
413f7a05cdaSMatthias Ringwald  * @returns 0 if ok
414f7a05cdaSMatthias Ringwald  */
415f7a05cdaSMatthias Ringwald int gap_auto_connection_stop(bd_addr_type_t address_typ, bd_addr_t address);
416f7a05cdaSMatthias Ringwald 
417f7a05cdaSMatthias Ringwald /**
418f7a05cdaSMatthias Ringwald  * @brief Auto Connection Establishment - Stop everything
419f7a05cdaSMatthias Ringwald  * @note  Convenience function to stop all active auto connection attempts
420f7a05cdaSMatthias Ringwald  */
421f7a05cdaSMatthias Ringwald void gap_auto_connection_stop_all(void);
422f7a05cdaSMatthias Ringwald 
4239c6e867eSMatthias Ringwald /**
424b90f6e0aSMatthias Ringwald  * @brief Set LE PHY
425b90f6e0aSMatthias Ringwald  * @param con_handle
426b90f6e0aSMatthias Ringwald  * @param all_phys 0 = set rx/tx, 1 = set only rx, 2 = set only tx
427b90f6e0aSMatthias Ringwald  * @param tx_phys 1 = 1M, 2 = 2M, 4 = Coded
428b90f6e0aSMatthias Ringwald  * @param rx_phys 1 = 1M, 2 = 2M, 4 = Coded
429b90f6e0aSMatthias Ringwald  * @param phy_options 0 = no preferred coding for Coded, 1 = S=2 coding (500 kbit), 2 = S=8 coding (125 kbit)
430b90f6e0aSMatthias Ringwald  * @returns 0 if ok
431b90f6e0aSMatthias Ringwald  */
432b90f6e0aSMatthias Ringwald uint8_t gap_le_set_phy(hci_con_handle_t con_handle, uint8_t all_phys, uint8_t tx_phys, uint8_t rx_phys, uint8_t phy_options);
433b90f6e0aSMatthias Ringwald 
434b90f6e0aSMatthias Ringwald /**
435c9db5c21SMilanka Ringwald  * @brief Get connection interval
436c9db5c21SMilanka Ringwald  * @return connection interval, otherwise 0 if error
437c9db5c21SMilanka Ringwald  */
438c9db5c21SMilanka Ringwald uint16_t gap_le_connection_interval(hci_con_handle_t connection_handle);
439c9db5c21SMilanka Ringwald 
440c9db5c21SMilanka Ringwald /**
4419c6e867eSMatthias Ringwald  *
4429c6e867eSMatthias Ringwald  * @brief Get encryption key size.
4439c6e867eSMatthias Ringwald  * @param con_handle
4449c6e867eSMatthias Ringwald  * @return 0 if not encrypted, 7-16 otherwise
4459c6e867eSMatthias Ringwald  */
4469c6e867eSMatthias Ringwald int gap_encryption_key_size(hci_con_handle_t con_handle);
4479c6e867eSMatthias Ringwald 
4489c6e867eSMatthias Ringwald /**
4499c6e867eSMatthias Ringwald  * @brief Get authentication property.
4509c6e867eSMatthias Ringwald  * @param con_handle
4519c6e867eSMatthias Ringwald  * @return 1 if bonded with OOB/Passkey (AND MITM protection)
4529c6e867eSMatthias Ringwald  */
4539c6e867eSMatthias Ringwald int gap_authenticated(hci_con_handle_t con_handle);
4549c6e867eSMatthias Ringwald 
4559c6e867eSMatthias Ringwald /**
456f1dfbe18SMatthias Ringwald  * @brief Get secure connection property
457f1dfbe18SMatthias Ringwald  * @param con_handle
458f1dfbe18SMatthias Ringwald  * @return 1 if bonded usiung LE Secure Connections
459f1dfbe18SMatthias Ringwald  */
460f1dfbe18SMatthias Ringwald int gap_secure_connection(hci_con_handle_t con_handle);
461f1dfbe18SMatthias Ringwald 
462f1dfbe18SMatthias Ringwald /**
4639c6e867eSMatthias Ringwald  * @brief Queries authorization state.
4649c6e867eSMatthias Ringwald  * @param con_handle
4659c6e867eSMatthias Ringwald  * @return authorization_state for the current session
4669c6e867eSMatthias Ringwald  */
4679c6e867eSMatthias Ringwald authorization_state_t gap_authorization_state(hci_con_handle_t con_handle);
4689c6e867eSMatthias Ringwald 
46915a95bd5SMatthias Ringwald // Classic
47015a95bd5SMatthias Ringwald 
47115a95bd5SMatthias Ringwald /**
47215a95bd5SMatthias Ringwald  * @brief Override page scan mode. Page scan mode enabled by l2cap when services are registered
47315a95bd5SMatthias Ringwald  * @note Might be used to reduce power consumption while Bluetooth module stays powered but no (new)
47415a95bd5SMatthias Ringwald  *       connections are expected
47515a95bd5SMatthias Ringwald  */
47615a95bd5SMatthias Ringwald void gap_connectable_control(uint8_t enable);
47715a95bd5SMatthias Ringwald 
47815a95bd5SMatthias Ringwald /**
47915a95bd5SMatthias Ringwald  * @brief Allows to control if device is discoverable. OFF by default.
48015a95bd5SMatthias Ringwald  */
48115a95bd5SMatthias Ringwald void gap_discoverable_control(uint8_t enable);
48215a95bd5SMatthias Ringwald 
48315a95bd5SMatthias Ringwald /**
48415a95bd5SMatthias Ringwald  * @brief Gets local address.
48515a95bd5SMatthias Ringwald  */
48615a95bd5SMatthias Ringwald void gap_local_bd_addr(bd_addr_t address_buffer);
48715a95bd5SMatthias Ringwald 
48815a95bd5SMatthias Ringwald /**
48915a95bd5SMatthias Ringwald  * @brief Deletes link key for remote device with baseband address.
49055597469SMatthias Ringwald  * @param addr
49115a95bd5SMatthias Ringwald  */
49215a95bd5SMatthias Ringwald void gap_drop_link_key_for_bd_addr(bd_addr_t addr);
49315a95bd5SMatthias Ringwald 
49455597469SMatthias Ringwald /**
495ceecb9d9SMatthias Ringwald  * @brief Delete all stored link keys
496ceecb9d9SMatthias Ringwald  */
497ceecb9d9SMatthias Ringwald void gap_delete_all_link_keys(void);
498ceecb9d9SMatthias Ringwald 
499ceecb9d9SMatthias Ringwald /**
50055597469SMatthias Ringwald  * @brief Store link key for remote device with baseband address
50155597469SMatthias Ringwald  * @param addr
50255597469SMatthias Ringwald  * @param link_key
50355597469SMatthias Ringwald  * @param link_key_type
50455597469SMatthias Ringwald  */
50555597469SMatthias Ringwald void gap_store_link_key_for_bd_addr(bd_addr_t addr, link_key_t link_key, link_key_type_t type);
50655597469SMatthias Ringwald 
507f5875de5SMatthias Ringwald /**
5081b6fb31bSMatthias Ringwald  * @brief Setup Link Key iterator
5091b6fb31bSMatthias Ringwald  * @param it
5101b6fb31bSMatthias Ringwald  * @returns 1 on success
5111b6fb31bSMatthias Ringwald  */
5121b6fb31bSMatthias Ringwald int gap_link_key_iterator_init(btstack_link_key_iterator_t * it);
5131b6fb31bSMatthias Ringwald 
5141b6fb31bSMatthias Ringwald /**
5151b6fb31bSMatthias Ringwald  * @brief Get next Link Key
5161b6fb31bSMatthias Ringwald  * @param it
5171b6fb31bSMatthias Ringwald  * @brief addr
5181b6fb31bSMatthias Ringwald  * @brief link_key
5191b6fb31bSMatthias Ringwald  * @brief type of link key
5201b6fb31bSMatthias Ringwald  * @returns 1, if valid link key found
5211b6fb31bSMatthias Ringwald  */
5221b6fb31bSMatthias Ringwald 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);
5231b6fb31bSMatthias Ringwald 
5241b6fb31bSMatthias Ringwald /**
5251b6fb31bSMatthias Ringwald  * @brief Frees resources allocated by iterator_init
5261b6fb31bSMatthias Ringwald  * @note Must be called after iteration to free resources
5271b6fb31bSMatthias Ringwald  * @param it
5281b6fb31bSMatthias Ringwald  */
5291b6fb31bSMatthias Ringwald void gap_link_key_iterator_done(btstack_link_key_iterator_t * it);
5301b6fb31bSMatthias Ringwald 
5311b6fb31bSMatthias Ringwald /**
532f5875de5SMatthias Ringwald  * @brief Start GAP Classic Inquiry
533f5875de5SMatthias Ringwald  * @param duration in 1.28s units
534f5875de5SMatthias Ringwald  * @return 0 if ok
535f5875de5SMatthias Ringwald  * @events: GAP_EVENT_INQUIRY_RESULT, GAP_EVENT_INQUIRY_COMPLETE
536f5875de5SMatthias Ringwald  */
537f5875de5SMatthias Ringwald int gap_inquiry_start(uint8_t duration_in_1280ms_units);
538f5875de5SMatthias Ringwald 
539f5875de5SMatthias Ringwald /**
540f5875de5SMatthias Ringwald  * @brief Stop GAP Classic Inquiry
541f5875de5SMatthias Ringwald  * @brief Stop GAP Classic Inquiry
542f5875de5SMatthias Ringwald  * @returns 0 if ok
543f5875de5SMatthias Ringwald  * @events: GAP_EVENT_INQUIRY_COMPLETE
544f5875de5SMatthias Ringwald  */
545f5875de5SMatthias Ringwald int gap_inquiry_stop(void);
546f5875de5SMatthias Ringwald 
547b7f1ee76SMatthias Ringwald /**
548b7f1ee76SMatthias Ringwald  * @brief Remote Name Request
549b7f1ee76SMatthias Ringwald  * @param addr
550b7f1ee76SMatthias Ringwald  * @param page_scan_repetition_mode
551b7f1ee76SMatthias Ringwald  * @param clock_offset only used when bit 15 is set - pass 0 if not known
552b7f1ee76SMatthias Ringwald  * @events: HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE
553b7f1ee76SMatthias Ringwald  */
554b7f1ee76SMatthias Ringwald int gap_remote_name_request(bd_addr_t addr, uint8_t page_scan_repetition_mode, uint16_t clock_offset);
555b7f1ee76SMatthias Ringwald 
5560a51f88bSMatthias Ringwald /**
5570a51f88bSMatthias Ringwald  * @brief Legacy Pairing Pin Code Response
5580a51f88bSMatthias Ringwald  * @param addr
5590a51f88bSMatthias Ringwald  * @param pin
5600a51f88bSMatthias Ringwald  * @return 0 if ok
5610a51f88bSMatthias Ringwald  */
5620a51f88bSMatthias Ringwald int gap_pin_code_response(bd_addr_t addr, const char * pin);
5630a51f88bSMatthias Ringwald 
5640a51f88bSMatthias Ringwald /**
5650a51f88bSMatthias Ringwald  * @brief Abort Legacy Pairing
5660a51f88bSMatthias Ringwald  * @param addr
5670a51f88bSMatthias Ringwald  * @param pin
5680a51f88bSMatthias Ringwald  * @return 0 if ok
5690a51f88bSMatthias Ringwald  */
5700a51f88bSMatthias Ringwald int gap_pin_code_negative(bd_addr_t addr);
5710a51f88bSMatthias Ringwald 
5720a51f88bSMatthias Ringwald /**
5730a51f88bSMatthias Ringwald  * @brief SSP Passkey Response
5740a51f88bSMatthias Ringwald  * @param addr
5750a51f88bSMatthias Ringwald  * @param passkey [0..999999]
5760a51f88bSMatthias Ringwald  * @return 0 if ok
5770a51f88bSMatthias Ringwald  */
5780a51f88bSMatthias Ringwald int gap_ssp_passkey_response(bd_addr_t addr, uint32_t passkey);
5790a51f88bSMatthias Ringwald 
5800a51f88bSMatthias Ringwald /**
5810a51f88bSMatthias Ringwald  * @brief Abort SSP Passkey Entry/Pairing
5820a51f88bSMatthias Ringwald  * @param addr
5830a51f88bSMatthias Ringwald  * @param pin
5840a51f88bSMatthias Ringwald  * @return 0 if ok
5850a51f88bSMatthias Ringwald  */
5860a51f88bSMatthias Ringwald int gap_ssp_passkey_negative(bd_addr_t addr);
5870a51f88bSMatthias Ringwald 
5880a51f88bSMatthias Ringwald /**
5890a51f88bSMatthias Ringwald  * @brief Accept SSP Numeric Comparison
5900a51f88bSMatthias Ringwald  * @param addr
5910a51f88bSMatthias Ringwald  * @param passkey
5920a51f88bSMatthias Ringwald  * @return 0 if ok
5930a51f88bSMatthias Ringwald  */
5940a51f88bSMatthias Ringwald int gap_ssp_confirmation_response(bd_addr_t addr);
5950a51f88bSMatthias Ringwald 
5960a51f88bSMatthias Ringwald /**
5970a51f88bSMatthias Ringwald  * @brief Abort SSP Numeric Comparison/Pairing
5980a51f88bSMatthias Ringwald  * @param addr
5990a51f88bSMatthias Ringwald  * @param pin
6000a51f88bSMatthias Ringwald  * @return 0 if ok
6010a51f88bSMatthias Ringwald  */
6020a51f88bSMatthias Ringwald int gap_ssp_confirmation_negative(bd_addr_t addr);
6030a51f88bSMatthias Ringwald 
604f8ee3071SMatthias Ringwald /**
605f8ee3071SMatthias Ringwald  * @brief Enter Sniff mode
606f8ee3071SMatthias Ringwald  * @param con_handle
607f8ee3071SMatthias Ringwald  * @param sniff_min_interval range: 0x0002 to 0xFFFE; only even values are valid, Time = N * 0.625 ms
608f8ee3071SMatthias Ringwald  * @param sniff_max_interval range: 0x0002 to 0xFFFE; only even values are valid, Time = N * 0.625 ms
609f8ee3071SMatthias Ringwald  * @param sniff_attempt Number of Baseband receive slots for sniff attempt.
610f8ee3071SMatthias Ringwald  * @param sniff_timeout Number of Baseband receive slots for sniff timeout.
611f8ee3071SMatthias Ringwald  @ @return 0 if ok
612f8ee3071SMatthias Ringwald  */
613f8ee3071SMatthias Ringwald 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);
6140a51f88bSMatthias Ringwald 
615f8ee3071SMatthias Ringwald /**
616f8ee3071SMatthias Ringwald  * @brief Exit Sniff mode
617f8ee3071SMatthias Ringwald  * @param con_handle
618f8ee3071SMatthias Ringwald  @ @return 0 if ok
619f8ee3071SMatthias Ringwald  */
620f8ee3071SMatthias Ringwald uint8_t gap_sniff_mode_exit(hci_con_handle_t con_handle);
6210a51f88bSMatthias Ringwald 
62215a95bd5SMatthias Ringwald // LE
62315a95bd5SMatthias Ringwald 
62415a95bd5SMatthias Ringwald /**
625b95a5a35SMatthias Ringwald  * @brief Get own addr type and address used for LE
62615a95bd5SMatthias Ringwald  */
627b95a5a35SMatthias Ringwald void gap_le_get_own_address(uint8_t * addr_type, bd_addr_t addr);
62815a95bd5SMatthias Ringwald 
6296e364deaSMatthias Ringwald 
630dcd6c9b5SMatthias Ringwald /**
631dcd6c9b5SMatthias Ringwald  * @brief Get state of connection re-encryptiong for bonded devices when in central role
632dcd6c9b5SMatthias Ringwald  * @note used by gatt_client and att_server to wait for re-encryption
633dcd6c9b5SMatthias Ringwald  * @param con_handle
634dcd6c9b5SMatthias Ringwald  * @return 1 if security setup is active
635dcd6c9b5SMatthias Ringwald  */
636dcd6c9b5SMatthias Ringwald int gap_reconnect_security_setup_active(hci_con_handle_t con_handle);
637dcd6c9b5SMatthias Ringwald 
638dcd6c9b5SMatthias Ringwald 
639d8e8f12aSMatthias Ringwald /* API_END*/
6406e364deaSMatthias Ringwald 
641458bf4e8S[email protected] #if defined __cplusplus
642458bf4e8S[email protected] }
643458bf4e8S[email protected] #endif
644458bf4e8S[email protected] 
64580e33422SMatthias Ringwald #endif // GAP_H
646