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] 38f471afd8S[email protected] #ifndef __GAP_H 39f471afd8S[email protected] #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" 47f7a05cdaSMatthias Ringwald 48cb230b9dS[email protected] typedef enum { 49cb230b9dS[email protected] 50cb230b9dS[email protected] // MITM protection not required 51cb230b9dS[email protected] // No encryption required 52cb230b9dS[email protected] // No user interaction required 53cb230b9dS[email protected] LEVEL_0 = 0, 54cb230b9dS[email protected] 55cb230b9dS[email protected] // MITM protection not required 56cb230b9dS[email protected] // No encryption required 57cb230b9dS[email protected] // Minimal user interaction desired 58cb230b9dS[email protected] LEVEL_1, 59cb230b9dS[email protected] 60cb230b9dS[email protected] // MITM protection not required 61cb230b9dS[email protected] // Encryption required 62cb230b9dS[email protected] LEVEL_2, 63cb230b9dS[email protected] 64cb230b9dS[email protected] // MITM protection required 65cb230b9dS[email protected] // Encryption required 66cb230b9dS[email protected] // User interaction acceptable 67cb230b9dS[email protected] LEVEL_3, 68cb230b9dS[email protected] 69cb230b9dS[email protected] // MITM protection required 70cb230b9dS[email protected] // Encryption required 713c68dfa9S[email protected] // 128-bit equivalent strength for link and encryption keys required (P-192 is not enough) 72cb230b9dS[email protected] // User interaction acceptable 73cb230b9dS[email protected] LEVEL_4, 74cb230b9dS[email protected] } gap_security_level_t; 75cb230b9dS[email protected] 7634f9eab8S[email protected] typedef enum { 7734f9eab8S[email protected] GAP_SECURITY_NONE, 7834f9eab8S[email protected] GAP_SECUIRTY_ENCRYPTED, // SSP: JUST WORKS 7934f9eab8S[email protected] GAP_SECURITY_AUTHENTICATED, // SSP: numeric comparison, passkey, OOB 8034f9eab8S[email protected] // GAP_SECURITY_AUTHORIZED 813c68dfa9S[email protected] } gap_security_state; 8234f9eab8S[email protected] 83a1bf5ae7SMatthias Ringwald typedef enum { 84a1bf5ae7SMatthias Ringwald GAP_CONNECTION_INVALID, 85a1bf5ae7SMatthias Ringwald GAP_CONNECTION_ACL, 86a1bf5ae7SMatthias Ringwald GAP_CONNECTION_SCO, 87a1bf5ae7SMatthias Ringwald GAP_CONNECTION_LE 88a1bf5ae7SMatthias Ringwald } gap_connection_type_t; 89a1bf5ae7SMatthias Ringwald 906e364deaSMatthias Ringwald typedef struct le_connection_parameter_range{ 916e364deaSMatthias Ringwald uint16_t le_conn_interval_min; 926e364deaSMatthias Ringwald uint16_t le_conn_interval_max; 936e364deaSMatthias Ringwald uint16_t le_conn_latency_min; 946e364deaSMatthias Ringwald uint16_t le_conn_latency_max; 956e364deaSMatthias Ringwald uint16_t le_supervision_timeout_min; 966e364deaSMatthias Ringwald uint16_t le_supervision_timeout_max; 976e364deaSMatthias Ringwald } le_connection_parameter_range_t; 986e364deaSMatthias Ringwald 996e364deaSMatthias Ringwald typedef enum { 1006e364deaSMatthias Ringwald GAP_RANDOM_ADDRESS_TYPE_OFF = 0, 1016e364deaSMatthias Ringwald GAP_RANDOM_ADDRESS_NON_RESOLVABLE, 1026e364deaSMatthias Ringwald GAP_RANDOM_ADDRESS_RESOLVABLE, 1036e364deaSMatthias Ringwald } gap_random_address_type_t; 1046e364deaSMatthias Ringwald 1053de95307SMilanka Ringwald /* API_START */ 1063de95307SMilanka Ringwald 107*d8e8f12aSMatthias Ringwald // Classic + LE 108*d8e8f12aSMatthias Ringwald 109*d8e8f12aSMatthias Ringwald /** 110*d8e8f12aSMatthias Ringwald * @brief Disconnect connection with handle 111*d8e8f12aSMatthias Ringwald * @param handle 112*d8e8f12aSMatthias Ringwald */ 113*d8e8f12aSMatthias Ringwald uint8_t gap_disconnect(hci_con_handle_t handle); 114*d8e8f12aSMatthias Ringwald 115*d8e8f12aSMatthias Ringwald /** 116*d8e8f12aSMatthias Ringwald * @brief Get connection type 117*d8e8f12aSMatthias Ringwald * @param con_handle 118*d8e8f12aSMatthias Ringwald * @result connection_type 119*d8e8f12aSMatthias Ringwald */ 120*d8e8f12aSMatthias Ringwald gap_connection_type_t gap_get_connection_type(hci_con_handle_t connection_handle); 121*d8e8f12aSMatthias Ringwald 122*d8e8f12aSMatthias Ringwald // Classic 123*d8e8f12aSMatthias Ringwald 124*d8e8f12aSMatthias Ringwald /** 125*d8e8f12aSMatthias Ringwald * @brief Sets local name. 126*d8e8f12aSMatthias Ringwald * @note has to be done before stack starts up 127*d8e8f12aSMatthias Ringwald * @param name is not copied, make sure memory is accessible during stack startup 128*d8e8f12aSMatthias Ringwald */ 129*d8e8f12aSMatthias Ringwald void gap_set_local_name(const char * local_name); 130*d8e8f12aSMatthias Ringwald 131458bf4e8S[email protected] /** 1323de95307SMilanka Ringwald * @brief Enable/disable bonding. Default is enabled. 1333de95307SMilanka Ringwald * @param enabled 134458bf4e8S[email protected] */ 135458bf4e8S[email protected] void gap_set_bondable_mode(int enabled); 13634d2123cS[email protected] 137ad83dc6aS[email protected] /** 138671d15e6SMatthias Ringwald * @brief Get bondable mode. 139671d15e6SMatthias Ringwald * @return 1 if bondable 140671d15e6SMatthias Ringwald */ 141671d15e6SMatthias Ringwald int gap_get_bondable_mode(void); 142671d15e6SMatthias Ringwald 143671d15e6SMatthias Ringwald /** 1443de95307SMilanka Ringwald * @brief Start dedicated bonding with device. Disconnect after bonding. 145ad83dc6aS[email protected] * @param device 146ad83dc6aS[email protected] * @param request MITM protection 1473de95307SMilanka Ringwald * @return error, if max num acl connections active 148ad83dc6aS[email protected] * @result GAP_DEDICATED_BONDING_COMPLETE 149ad83dc6aS[email protected] */ 150ad83dc6aS[email protected] int gap_dedicated_bonding(bd_addr_t device, int mitm_protection_required); 151ad83dc6aS[email protected] 15234d2123cS[email protected] gap_security_level_t gap_security_level_for_link_key_type(link_key_type_t link_key_type); 153ad671560S[email protected] gap_security_level_t gap_security_level(hci_con_handle_t con_handle); 15434d2123cS[email protected] 155ad671560S[email protected] void gap_request_security_level(hci_con_handle_t con_handle, gap_security_level_t level); 156*d8e8f12aSMatthias Ringwald 157106d6d11S[email protected] int gap_mitm_protection_required_for_security_level(gap_security_level_t level); 158458bf4e8S[email protected] 159*d8e8f12aSMatthias Ringwald // LE 1608e618f72S[email protected] 161a1bf5ae7SMatthias Ringwald /** 162*d8e8f12aSMatthias Ringwald * @brief Set parameters for LE Scan 163a1bf5ae7SMatthias Ringwald */ 164*d8e8f12aSMatthias Ringwald void gap_set_scan_parameters(uint8_t scan_type, uint16_t scan_interval, uint16_t scan_window); 165*d8e8f12aSMatthias Ringwald 166*d8e8f12aSMatthias Ringwald /** 167*d8e8f12aSMatthias Ringwald * @brief Start LE Scan 168*d8e8f12aSMatthias Ringwald */ 169*d8e8f12aSMatthias Ringwald void gap_start_scan(void); 170*d8e8f12aSMatthias Ringwald 171*d8e8f12aSMatthias Ringwald /** 172*d8e8f12aSMatthias Ringwald * @brief Stop LE Scan 173*d8e8f12aSMatthias Ringwald */ 174*d8e8f12aSMatthias Ringwald void gap_stop_scan(void); 175a1bf5ae7SMatthias Ringwald 176f7a05cdaSMatthias Ringwald /** 177f7a05cdaSMatthias Ringwald * @brief Enable privacy by using random addresses 178f7a05cdaSMatthias Ringwald * @param random_address_type to use (incl. OFF) 179f7a05cdaSMatthias Ringwald */ 180f7a05cdaSMatthias Ringwald void gap_random_address_set_mode(gap_random_address_type_t random_address_type); 181f7a05cdaSMatthias Ringwald 182f7a05cdaSMatthias Ringwald /** 183f7a05cdaSMatthias Ringwald * @brief Get privacy mode 184f7a05cdaSMatthias Ringwald */ 185f7a05cdaSMatthias Ringwald gap_random_address_type_t gap_random_address_get_mode(void); 186f7a05cdaSMatthias Ringwald 187f7a05cdaSMatthias Ringwald /** 188f7a05cdaSMatthias Ringwald * @brief Sets update period for random address 189f7a05cdaSMatthias Ringwald * @param period_ms in ms 190f7a05cdaSMatthias Ringwald */ 191f7a05cdaSMatthias Ringwald void gap_random_address_set_update_period(int period_ms); 192f7a05cdaSMatthias Ringwald 193f7a05cdaSMatthias Ringwald /** 1947e252622SMatthias Ringwald * @brief Sets a fixed random address for advertising 1957e252622SMatthias Ringwald * @param addr 1967e252622SMatthias Ringwald * @note Sets random address mode to type off 1977e252622SMatthias Ringwald */ 1987e252622SMatthias Ringwald void gap_random_address_set(bd_addr_t addr); 1997e252622SMatthias Ringwald 2007e252622SMatthias Ringwald /** 201f7a05cdaSMatthias Ringwald * @brief Set Advertisement Data 202f7a05cdaSMatthias Ringwald * @param advertising_data_length 203f7a05cdaSMatthias Ringwald * @param advertising_data (max 31 octets) 204f7a05cdaSMatthias Ringwald * @note data is not copied, pointer has to stay valid 205f7a05cdaSMatthias Ringwald */ 206f7a05cdaSMatthias Ringwald void gap_advertisements_set_data(uint8_t advertising_data_length, uint8_t * advertising_data); 207f7a05cdaSMatthias Ringwald 208f7a05cdaSMatthias Ringwald /** 209f7a05cdaSMatthias Ringwald * @brief Set Advertisement Paramters 210f7a05cdaSMatthias Ringwald * @param adv_int_min 211f7a05cdaSMatthias Ringwald * @param adv_int_max 212f7a05cdaSMatthias Ringwald * @param adv_type 213f7a05cdaSMatthias Ringwald * @param direct_address_type 214f7a05cdaSMatthias Ringwald * @param direct_address 215f7a05cdaSMatthias Ringwald * @param channel_map 216f7a05cdaSMatthias Ringwald * @param filter_policy 217f7a05cdaSMatthias Ringwald * @note own_address_type is used from gap_random_address_set_mode 218f7a05cdaSMatthias Ringwald */ 219f7a05cdaSMatthias Ringwald void gap_advertisements_set_params(uint16_t adv_int_min, uint16_t adv_int_max, uint8_t adv_type, 220f7a05cdaSMatthias Ringwald uint8_t direct_address_typ, bd_addr_t direct_address, uint8_t channel_map, uint8_t filter_policy); 221f7a05cdaSMatthias Ringwald 222f7a05cdaSMatthias Ringwald /** 223f7a05cdaSMatthias Ringwald * @brief Enable/Disable Advertisements 224f7a05cdaSMatthias Ringwald * @param enabled 225f7a05cdaSMatthias Ringwald */ 226f7a05cdaSMatthias Ringwald void gap_advertisements_enable(int enabled); 227*d8e8f12aSMatthias Ringwald /** 228*d8e8f12aSMatthias Ringwald * @brief Request an update of the connection parameter for a given LE connection 229*d8e8f12aSMatthias Ringwald * @param handle 230*d8e8f12aSMatthias Ringwald * @param conn_interval_min (unit: 1.25ms) 231*d8e8f12aSMatthias Ringwald * @param conn_interval_max (unit: 1.25ms) 232*d8e8f12aSMatthias Ringwald * @param conn_latency 233*d8e8f12aSMatthias Ringwald * @param supervision_timeout (unit: 10ms) 234*d8e8f12aSMatthias Ringwald * @returns 0 if ok 235*d8e8f12aSMatthias Ringwald */ 236*d8e8f12aSMatthias Ringwald int gap_request_connection_parameter_update(hci_con_handle_t con_handle, uint16_t conn_interval_min, 237*d8e8f12aSMatthias Ringwald uint16_t conn_interval_max, uint16_t conn_latency, uint16_t supervision_timeout); 238*d8e8f12aSMatthias Ringwald 239*d8e8f12aSMatthias Ringwald /** 240*d8e8f12aSMatthias Ringwald * @brief Updates the connection parameters for a given LE connection 241*d8e8f12aSMatthias Ringwald * @param handle 242*d8e8f12aSMatthias Ringwald * @param conn_interval_min (unit: 1.25ms) 243*d8e8f12aSMatthias Ringwald * @param conn_interval_max (unit: 1.25ms) 244*d8e8f12aSMatthias Ringwald * @param conn_latency 245*d8e8f12aSMatthias Ringwald * @param supervision_timeout (unit: 10ms) 246*d8e8f12aSMatthias Ringwald * @returns 0 if ok 247*d8e8f12aSMatthias Ringwald */ 248*d8e8f12aSMatthias Ringwald int gap_update_connection_parameters(hci_con_handle_t con_handle, uint16_t conn_interval_min, 249*d8e8f12aSMatthias Ringwald uint16_t conn_interval_max, uint16_t conn_latency, uint16_t supervision_timeout); 250*d8e8f12aSMatthias Ringwald 251*d8e8f12aSMatthias Ringwald /** 252*d8e8f12aSMatthias Ringwald * @brief Set accepted connection parameter range 253*d8e8f12aSMatthias Ringwald * @param range 254*d8e8f12aSMatthias Ringwald */ 255*d8e8f12aSMatthias Ringwald void gap_get_connection_parameter_range(le_connection_parameter_range_t range); 256*d8e8f12aSMatthias Ringwald 257*d8e8f12aSMatthias Ringwald /** 258*d8e8f12aSMatthias Ringwald * @brief Get accepted connection parameter range 259*d8e8f12aSMatthias Ringwald * @param range 260*d8e8f12aSMatthias Ringwald */ 261*d8e8f12aSMatthias Ringwald void gap_set_connection_parameter_range(le_connection_parameter_range_t range); 262*d8e8f12aSMatthias Ringwald 263*d8e8f12aSMatthias Ringwald /** 264*d8e8f12aSMatthias Ringwald * @brief Connect to remote LE device 265*d8e8f12aSMatthias Ringwald */ 266*d8e8f12aSMatthias Ringwald uint8_t gap_connect(bd_addr_t addr, bd_addr_type_t addr_type); 267*d8e8f12aSMatthias Ringwald 268*d8e8f12aSMatthias Ringwald /** 269*d8e8f12aSMatthias Ringwald * @brief Cancel connection process initiated by gap_connect 270*d8e8f12aSMatthias Ringwald */ 271*d8e8f12aSMatthias Ringwald uint8_t gap_connect_cancel(void); 272f7a05cdaSMatthias Ringwald 273f7a05cdaSMatthias Ringwald /** 274f7a05cdaSMatthias Ringwald * @brief Auto Connection Establishment - Start Connecting to device 275f7a05cdaSMatthias Ringwald * @param address_typ 276f7a05cdaSMatthias Ringwald * @param address 277f7a05cdaSMatthias Ringwald * @returns 0 if ok 278f7a05cdaSMatthias Ringwald */ 279f7a05cdaSMatthias Ringwald int gap_auto_connection_start(bd_addr_type_t address_typ, bd_addr_t address); 280f7a05cdaSMatthias Ringwald 281f7a05cdaSMatthias Ringwald /** 282f7a05cdaSMatthias Ringwald * @brief Auto Connection Establishment - Stop Connecting to device 283f7a05cdaSMatthias Ringwald * @param address_typ 284f7a05cdaSMatthias Ringwald * @param address 285f7a05cdaSMatthias Ringwald * @returns 0 if ok 286f7a05cdaSMatthias Ringwald */ 287f7a05cdaSMatthias Ringwald int gap_auto_connection_stop(bd_addr_type_t address_typ, bd_addr_t address); 288f7a05cdaSMatthias Ringwald 289f7a05cdaSMatthias Ringwald /** 290f7a05cdaSMatthias Ringwald * @brief Auto Connection Establishment - Stop everything 291f7a05cdaSMatthias Ringwald * @note Convenience function to stop all active auto connection attempts 292f7a05cdaSMatthias Ringwald */ 293f7a05cdaSMatthias Ringwald void gap_auto_connection_stop_all(void); 294f7a05cdaSMatthias Ringwald 2956e364deaSMatthias Ringwald 296*d8e8f12aSMatthias Ringwald /* API_END*/ 2976e364deaSMatthias Ringwald 298458bf4e8S[email protected] #if defined __cplusplus 299458bf4e8S[email protected] } 300458bf4e8S[email protected] #endif 301458bf4e8S[email protected] 302f471afd8S[email protected] #endif // __GAP_H 303