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 MATTHIAS 24 * RINGWALD 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 #ifndef GAP_H 39 #define GAP_H 40 41 #if defined __cplusplus 42 extern "C" { 43 #endif 44 45 #include "btstack_defines.h" 46 #include "btstack_util.h" 47 48 #ifdef ENABLE_CLASSIC 49 #include "classic/btstack_link_key_db.h" 50 #endif 51 52 typedef enum { 53 54 // MITM protection not required 55 // No encryption required 56 // No user interaction required 57 LEVEL_0 = 0, 58 59 // MITM protection not required 60 // No encryption required 61 // Minimal user interaction desired 62 LEVEL_1, 63 64 // MITM protection not required 65 // Encryption required 66 LEVEL_2, 67 68 // MITM protection required 69 // Encryption required 70 // User interaction acceptable 71 LEVEL_3, 72 73 // MITM protection required 74 // Encryption required 75 // 128-bit equivalent strength for link and encryption keys required (P-192 is not enough) 76 // User interaction acceptable 77 LEVEL_4, 78 } gap_security_level_t; 79 80 typedef enum { 81 GAP_SECURITY_NONE, 82 GAP_SECUIRTY_ENCRYPTED, // SSP: JUST WORKS 83 GAP_SECURITY_AUTHENTICATED, // SSP: numeric comparison, passkey, OOB 84 // GAP_SECURITY_AUTHORIZED 85 } gap_security_state; 86 87 typedef enum { 88 GAP_CONNECTION_INVALID, 89 GAP_CONNECTION_ACL, 90 GAP_CONNECTION_SCO, 91 GAP_CONNECTION_LE 92 } gap_connection_type_t; 93 94 typedef struct le_connection_parameter_range{ 95 uint16_t le_conn_interval_min; 96 uint16_t le_conn_interval_max; 97 uint16_t le_conn_latency_min; 98 uint16_t le_conn_latency_max; 99 uint16_t le_supervision_timeout_min; 100 uint16_t le_supervision_timeout_max; 101 } le_connection_parameter_range_t; 102 103 typedef enum { 104 GAP_RANDOM_ADDRESS_TYPE_OFF = 0, 105 GAP_RANDOM_ADDRESS_TYPE_STATIC, 106 GAP_RANDOM_ADDRESS_NON_RESOLVABLE, 107 GAP_RANDOM_ADDRESS_RESOLVABLE, 108 } gap_random_address_type_t; 109 110 // Authorization state 111 typedef enum { 112 AUTHORIZATION_UNKNOWN, 113 AUTHORIZATION_PENDING, 114 AUTHORIZATION_DECLINED, 115 AUTHORIZATION_GRANTED 116 } authorization_state_t; 117 118 119 /* API_START */ 120 121 // Classic + LE 122 123 /** 124 * @brief Read RSSI 125 * @param con_handle 126 * @events: GAP_EVENT_RSSI_MEASUREMENT 127 */ 128 int gap_read_rssi(hci_con_handle_t con_handle); 129 130 131 /** 132 * @brief Gets local address. 133 */ 134 void gap_local_bd_addr(bd_addr_t address_buffer); 135 136 /** 137 * @brief Disconnect connection with handle 138 * @param handle 139 */ 140 uint8_t gap_disconnect(hci_con_handle_t handle); 141 142 /** 143 * @brief Get connection type 144 * @param con_handle 145 * @result connection_type 146 */ 147 gap_connection_type_t gap_get_connection_type(hci_con_handle_t connection_handle); 148 149 /** 150 * @brief Get HCI connection role 151 * @param con_handle 152 * @result hci_role_t HCI_ROLE_MASTER / HCI_ROLE_SLAVE / HCI_ROLE_INVALID (if connection does not exist) 153 */ 154 hci_role_t gap_get_role(hci_con_handle_t connection_handle); 155 156 // Classic 157 158 /** 159 * @brief Request role switch 160 * @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 161 * @param addr 162 * @param hci_role_t HCI_ROLE_MASTER / HCI_ROLE_SLAVE 163 * @result status 164 */ 165 uint8_t gap_request_role(const bd_addr_t addr, hci_role_t role); 166 167 /** 168 * @brief Sets local name. 169 * @note has to be done before stack starts up 170 * @note Default name is 'BTstack 00:00:00:00:00:00' 171 * @note '00:00:00:00:00:00' in local_name will be replaced with actual bd addr 172 * @param name is not copied, make sure memory is accessible during stack startup 173 */ 174 void gap_set_local_name(const char * local_name); 175 176 /** 177 * @brief Set Extended Inquiry Response data 178 * @note has to be done before stack starts up 179 * @note If not set, local name will be used for EIR data (see gap_set_local_name) 180 * @note '00:00:00:00:00:00' in local_name will be replaced with actual bd addr 181 * @param eir_data size HCI_EXTENDED_INQUIRY_RESPONSE_DATA_LEN (240) bytes, is not copied make sure memory is accessible during stack startup 182 */ 183 void gap_set_extended_inquiry_response(const uint8_t * data); 184 185 /** 186 * @brief Set class of device that will be set during Bluetooth init. 187 * @note has to be done before stack starts up 188 */ 189 void gap_set_class_of_device(uint32_t class_of_device); 190 191 /** 192 * @brief Set default link policy settings for all classic ACL links 193 * @param default_link_policy_settings - see LM_LINK_POLICY_* in bluetooth.h 194 * @note common value: LM_LINK_POLICY_ENABLE_ROLE_SWITCH | LM_LINK_POLICY_ENABLE_SNIFF_MODE to enable role switch and sniff mode 195 * @note has to be done before stack starts up 196 */ 197 void gap_set_default_link_policy_settings(uint16_t default_link_policy_settings); 198 199 /** 200 * @brief Set Allow Role Switch param for outgoing classic ACL links 201 * @param allow_role_switch - true: allow remote device to request role switch, false: stay master 202 */ 203 void gap_set_allow_role_switch(bool allow_role_switch); 204 205 /** 206 * @brief Set link supervision timeout for outgoing classic ACL links 207 * @param default_link_supervision_timeout * 0.625 ms, default 0x7d00 = 20 seconds, 0 = no link supervision timeout 208 */ 209 void gap_set_link_supervision_timeout(uint16_t link_supervision_timeout); 210 211 /** 212 * @brief Enable/disable bonding. Default is enabled. 213 * @param enabled 214 */ 215 void gap_set_bondable_mode(int enabled); 216 217 /** 218 * @brief Get bondable mode. 219 * @return 1 if bondable 220 */ 221 int gap_get_bondable_mode(void); 222 223 /** 224 * @brief Set security level for all outgoing and incoming connections. Default: LEVEL_2 225 * @param security_level 226 * @note has to be called before services or profiles are initialized 227 */ 228 void gap_set_security_level(gap_security_level_t security_level); 229 230 /** 231 * @brief Get security level 232 * @return security_level 233 */ 234 gap_security_level_t gap_get_security_level(void); 235 236 /** 237 * @brief Register filter for rejecting classic connections. Callback will return 1 accept connection, 0 on reject. 238 */ 239 void gap_register_classic_connection_filter(int (*accept_callback)(bd_addr_t addr, hci_link_type_t link_type)); 240 241 /* Configure Secure Simple Pairing */ 242 243 /** 244 * @brief Enable will enable SSP during init. Default: true 245 */ 246 void gap_ssp_set_enable(int enable); 247 248 /** 249 * @brief Set IO Capability. BTstack will return capability to SSP requests 250 */ 251 void gap_ssp_set_io_capability(int ssp_io_capability); 252 253 /** 254 * @brief Set Authentication Requirements using during SSP 255 */ 256 void gap_ssp_set_authentication_requirement(int authentication_requirement); 257 258 /** 259 * @brief Enable/disable Secure Connections. Default: true if supported by Controller 260 */ 261 void gap_secure_connections_enable(bool enable); 262 263 /** 264 * @brief If set, BTstack will confirm a numeric comparison and enter '000000' if requested. 265 */ 266 void gap_ssp_set_auto_accept(int auto_accept); 267 268 /** 269 * @brief Set required encryption key size for GAP Levels 1-3 on ccassic connections. Default: 16 bytes 270 * @param encryption_key_size in bytes. Valid 7..16 271 */ 272 void gap_set_required_encryption_key_size(uint8_t encryption_key_size); 273 274 /** 275 * @brief Start dedicated bonding with device. Disconnect after bonding. 276 * @param device 277 * @param request MITM protection 278 * @return error, if max num acl connections active 279 * @result GAP_DEDICATED_BONDING_COMPLETE 280 */ 281 int gap_dedicated_bonding(bd_addr_t device, int mitm_protection_required); 282 283 gap_security_level_t gap_security_level_for_link_key_type(link_key_type_t link_key_type); 284 285 /** 286 * @brief map link keys to secure connection yes/no 287 */ 288 int gap_secure_connection_for_link_key_type(link_key_type_t link_key_type); 289 290 /** 291 * @brief map link keys to authenticated 292 */ 293 int gap_authenticated_for_link_key_type(link_key_type_t link_key_type); 294 295 gap_security_level_t gap_security_level(hci_con_handle_t con_handle); 296 297 void gap_request_security_level(hci_con_handle_t con_handle, gap_security_level_t level); 298 299 int gap_mitm_protection_required_for_security_level(gap_security_level_t level); 300 301 /** 302 * @brief Set Page Scan Type 303 * @param page_scan_interval * 0.625 ms, range: 0x0012..0x1000, default: 0x0800 304 * @param page_scan_windows * 0.625 ms, range: 0x0011..page_scan_interval, default: 0x0012 305 */ 306 void gap_set_page_scan_activity(uint16_t page_scan_interval, uint16_t page_scan_window); 307 308 /** 309 * @brief Set Page Scan Type 310 * @param page_scan_mode 311 */ 312 void gap_set_page_scan_type(page_scan_type_t page_scan_type); 313 314 // LE 315 316 /** 317 * @brief Set parameters for LE Scan 318 * @param scan_type 0 = passive, 1 = active 319 * @param scan_interval range 0x0004..0x4000, unit 0.625 ms 320 * @param scan_window range 0x0004..0x4000, unit 0.625 ms 321 * @param scanning_filter_policy 0 = all devices, 1 = all from whitelist 322 */ 323 void gap_set_scan_params(uint8_t scan_type, uint16_t scan_interval, uint16_t scan_window, uint8_t scanning_filter_policy); 324 325 /** 326 * @brief Set parameters for LE Scan 327 * @deprecated Use gap_set_scan_params instead 328 */ 329 void gap_set_scan_parameters(uint8_t scan_type, uint16_t scan_interval, uint16_t scan_window); 330 331 /** 332 * @brief Start LE Scan 333 */ 334 void gap_start_scan(void); 335 336 /** 337 * @brief Stop LE Scan 338 */ 339 void gap_stop_scan(void); 340 341 /** 342 * @brief Enable privacy by using random addresses 343 * @param random_address_type to use (incl. OFF) 344 */ 345 void gap_random_address_set_mode(gap_random_address_type_t random_address_type); 346 347 /** 348 * @brief Get privacy mode 349 */ 350 gap_random_address_type_t gap_random_address_get_mode(void); 351 352 /** 353 * @brief Sets update period for random address 354 * @param period_ms in ms 355 */ 356 void gap_random_address_set_update_period(int period_ms); 357 358 /** 359 * @brief Sets a fixed random address for advertising 360 * @param addr 361 * @note Sets random address mode to type off 362 */ 363 void gap_random_address_set(const bd_addr_t addr); 364 365 /** 366 * @brief Set Advertisement Data 367 * @param advertising_data_length 368 * @param advertising_data (max 31 octets) 369 * @note data is not copied, pointer has to stay valid 370 * @note '00:00:00:00:00:00' in advertising_data will be replaced with actual bd addr 371 */ 372 void gap_advertisements_set_data(uint8_t advertising_data_length, uint8_t * advertising_data); 373 374 /** 375 * @brief Set Advertisement Paramters 376 * @param adv_int_min 377 * @param adv_int_max 378 * @param adv_type 379 * @param direct_address_type 380 * @param direct_address 381 * @param channel_map 382 * @param filter_policy 383 * @note own_address_type is used from gap_random_address_set_mode 384 */ 385 void gap_advertisements_set_params(uint16_t adv_int_min, uint16_t adv_int_max, uint8_t adv_type, 386 uint8_t direct_address_typ, bd_addr_t direct_address, uint8_t channel_map, uint8_t filter_policy); 387 388 /** 389 * @brief Enable/Disable Advertisements. OFF by default. 390 * @param enabled 391 */ 392 void gap_advertisements_enable(int enabled); 393 394 /** 395 * @brief Set Scan Response Data 396 * 397 * @note For scan response data, scannable undirected advertising (ADV_SCAN_IND) need to be used 398 * 399 * @param advertising_data_length 400 * @param advertising_data (max 31 octets) 401 * @note data is not copied, pointer has to stay valid 402 * @note '00:00:00:00:00:00' in scan_response_data will be replaced with actual bd addr 403 */ 404 void gap_scan_response_set_data(uint8_t scan_response_data_length, uint8_t * scan_response_data); 405 406 /** 407 * @brief Set connection parameters for outgoing connections 408 * @param conn_scan_interval (unit: 0.625 msec), default: 60 ms 409 * @param conn_scan_window (unit: 0.625 msec), default: 30 ms 410 * @param conn_interval_min (unit: 1.25ms), default: 10 ms 411 * @param conn_interval_max (unit: 1.25ms), default: 30 ms 412 * @param conn_latency, default: 4 413 * @param supervision_timeout (unit: 10ms), default: 720 ms 414 * @param min_ce_length (unit: 0.625ms), default: 10 ms 415 * @param max_ce_length (unit: 0.625ms), default: 30 ms 416 */ 417 void gap_set_connection_parameters(uint16_t conn_scan_interval, uint16_t conn_scan_window, 418 uint16_t conn_interval_min, uint16_t conn_interval_max, uint16_t conn_latency, 419 uint16_t supervision_timeout, uint16_t min_ce_length, uint16_t max_ce_length); 420 421 /** 422 * @brief Request an update of the connection parameter for a given LE connection 423 * @param handle 424 * @param conn_interval_min (unit: 1.25ms) 425 * @param conn_interval_max (unit: 1.25ms) 426 * @param conn_latency 427 * @param supervision_timeout (unit: 10ms) 428 * @returns 0 if ok 429 */ 430 int gap_request_connection_parameter_update(hci_con_handle_t con_handle, uint16_t conn_interval_min, 431 uint16_t conn_interval_max, uint16_t conn_latency, uint16_t supervision_timeout); 432 433 /** 434 * @brief Updates the connection parameters for a given LE connection 435 * @param handle 436 * @param conn_interval_min (unit: 1.25ms) 437 * @param conn_interval_max (unit: 1.25ms) 438 * @param conn_latency 439 * @param supervision_timeout (unit: 10ms) 440 * @returns 0 if ok 441 */ 442 int gap_update_connection_parameters(hci_con_handle_t con_handle, uint16_t conn_interval_min, 443 uint16_t conn_interval_max, uint16_t conn_latency, uint16_t supervision_timeout); 444 445 /** 446 * @brief Set accepted connection parameter range 447 * @param range 448 */ 449 void gap_get_connection_parameter_range(le_connection_parameter_range_t * range); 450 451 /** 452 * @brief Get accepted connection parameter range 453 * @param range 454 */ 455 void gap_set_connection_parameter_range(le_connection_parameter_range_t * range); 456 457 /** 458 * @brief Test if connection parameters are inside in existing rage 459 * @param conn_interval_min (unit: 1.25ms) 460 * @param conn_interval_max (unit: 1.25ms) 461 * @param conn_latency 462 * @param supervision_timeout (unit: 10ms) 463 * @returns 1 if included 464 */ 465 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); 466 467 /** 468 * @brief Set max number of connections in LE Peripheral role (if Bluetooth Controller supports it) 469 * @note: default: 1 470 * @param max_peripheral_connections 471 */ 472 void gap_set_max_number_peripheral_connections(int max_peripheral_connections); 473 474 /** 475 * @brief Add Device to Whitelist 476 * @param address_typ 477 * @param address 478 * @returns 0 if ok 479 */ 480 uint8_t gap_whitelist_add(bd_addr_type_t address_type, const bd_addr_t address); 481 482 /** 483 * @brief Remove Device from Whitelist 484 * @param address_typ 485 * @param address 486 * @returns 0 if ok 487 */ 488 uint8_t gap_whitelist_remove(bd_addr_type_t address_type, const bd_addr_t address); 489 490 /** 491 * @brief Clear Whitelist 492 * @returns 0 if ok 493 */ 494 uint8_t gap_whitelist_clear(void); 495 496 /** 497 * @brief Connect to remote LE device 498 */ 499 uint8_t gap_connect(const bd_addr_t addr, bd_addr_type_t addr_type); 500 501 /** 502 * @brief Connect with Whitelist 503 * @note Explicit whitelist management and this connect with whitelist replace deprecated gap_auto_connection_* functions 504 * @returns - if ok 505 */ 506 uint8_t gap_connect_with_whitelist(void); 507 508 /** 509 * @brief Cancel connection process initiated by gap_connect 510 */ 511 uint8_t gap_connect_cancel(void); 512 513 /** 514 * @brief Auto Connection Establishment - Start Connecting to device 515 * @deprecated Please setup Whitelist with gap_whitelist_* and start connecting with gap_connect_with_whitelist 516 * @param address_typ 517 * @param address 518 * @returns 0 if ok 519 */ 520 uint8_t gap_auto_connection_start(bd_addr_type_t address_typ, const bd_addr_t address); 521 522 /** 523 * @brief Auto Connection Establishment - Stop Connecting to device 524 * @deprecated Please setup Whitelist with gap_whitelist_* and start connecting with gap_connect_with_whitelist 525 * @param address_typ 526 * @param address 527 * @returns 0 if ok 528 */ 529 uint8_t gap_auto_connection_stop(bd_addr_type_t address_typ, const bd_addr_t address); 530 531 /** 532 * @brief Auto Connection Establishment - Stop everything 533 * @deprecated Please setup Whitelist with gap_whitelist_* and start connecting with gap_connect_with_whitelist 534 * @note Convenience function to stop all active auto connection attempts 535 */ 536 uint8_t gap_auto_connection_stop_all(void); 537 538 /** 539 * @brief Set LE PHY 540 * @param con_handle 541 * @param all_phys 0 = set rx/tx, 1 = set only rx, 2 = set only tx 542 * @param tx_phys 1 = 1M, 2 = 2M, 4 = Coded 543 * @param rx_phys 1 = 1M, 2 = 2M, 4 = Coded 544 * @param phy_options 0 = no preferred coding for Coded, 1 = S=2 coding (500 kbit), 2 = S=8 coding (125 kbit) 545 * @returns 0 if ok 546 */ 547 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); 548 549 /** 550 * @brief Get connection interval 551 * @return connection interval, otherwise 0 if error 552 */ 553 uint16_t gap_le_connection_interval(hci_con_handle_t connection_handle); 554 555 /** 556 * 557 * @brief Get encryption key size. 558 * @param con_handle 559 * @return 0 if not encrypted, 7-16 otherwise 560 */ 561 int gap_encryption_key_size(hci_con_handle_t con_handle); 562 563 /** 564 * @brief Get authentication property. 565 * @param con_handle 566 * @return 1 if bonded with OOB/Passkey (AND MITM protection) 567 */ 568 int gap_authenticated(hci_con_handle_t con_handle); 569 570 /** 571 * @brief Get secure connection property 572 * @param con_handle 573 * @return 1 if bonded usiung LE Secure Connections 574 */ 575 int gap_secure_connection(hci_con_handle_t con_handle); 576 577 /** 578 * @brief Queries authorization state. 579 * @param con_handle 580 * @return authorization_state for the current session 581 */ 582 authorization_state_t gap_authorization_state(hci_con_handle_t con_handle); 583 584 /** 585 * @brief Get bonded property (BR/EDR/LE) 586 * @note LE: has to be called after identity resolving is complete 587 * @param con_handle 588 * @return true if bonded 589 */ 590 bool gap_bonded(hci_con_handle_t con_handle); 591 592 // Classic 593 #ifdef ENABLE_CLASSIC 594 595 /** 596 * @brief Override page scan mode. Page scan mode enabled by l2cap when services are registered 597 * @note Might be used to reduce power consumption while Bluetooth module stays powered but no (new) 598 * connections are expected 599 */ 600 void gap_connectable_control(uint8_t enable); 601 602 /** 603 * @brief Allows to control if device is discoverable. OFF by default. 604 */ 605 void gap_discoverable_control(uint8_t enable); 606 607 /** 608 * @brief Deletes link key for remote device with baseband address. 609 * @param addr 610 * @note On most desktop ports, the Link Key DB uses a TLV and there is one TLV storage per 611 * Controller resp. its Bluetooth Address. As the Bluetooth Address is retrieved during 612 * power up, this function only works, when the stack is in working state for these ports. 613 */ 614 void gap_drop_link_key_for_bd_addr(bd_addr_t addr); 615 616 /** 617 * @brief Delete all stored link keys 618 * @note On most desktop ports, the Link Key DB uses a TLV and there is one TLV storage per 619 * Controller resp. its Bluetooth Address. As the Bluetooth Address is retrieved during 620 * power up, this function only works, when the stack is in working state for these ports. 621 */ 622 void gap_delete_all_link_keys(void); 623 624 /** 625 * @brief Store link key for remote device with baseband address 626 * @param addr 627 * @param link_key 628 * @param link_key_type 629 * @note On most desktop ports, the Link Key DB uses a TLV and there is one TLV storage per 630 * Controller resp. its Bluetooth Address. As the Bluetooth Address is retrieved during 631 * power up, this function only works, when the stack is in working state for these ports. 632 */ 633 void gap_store_link_key_for_bd_addr(bd_addr_t addr, link_key_t link_key, link_key_type_t type); 634 635 /** 636 * @brief Get link for remote device with basband address 637 * @param addr 638 * @param link_key (out) is stored here 639 * @param link_key_type (out) is stored here 640 * @note On most desktop ports, the Link Key DB uses a TLV and there is one TLV storage per 641 * Controller resp. its Bluetooth Address. As the Bluetooth Address is retrieved during 642 * power up, this function only works, when the stack is in working state for these ports. 643 */ 644 bool gap_get_link_key_for_bd_addr(bd_addr_t addr, link_key_t link_key, link_key_type_t * type); 645 646 /** 647 * @brief Setup Link Key iterator 648 * @param it 649 * @returns 1 on success 650 * @note On most desktop ports, the Link Key DB uses a TLV and there is one TLV storage per 651 * Controller resp. its Bluetooth Address. As the Bluetooth Address is retrieved during 652 * power up, this function only works, when the stack is in working state for these ports. 653 */ 654 int gap_link_key_iterator_init(btstack_link_key_iterator_t * it); 655 656 /** 657 * @brief Get next Link Key 658 * @param it 659 * @brief addr 660 * @brief link_key 661 * @brief type of link key 662 * @returns 1, if valid link key found 663 * @see note on gap_link_key_iterator_init 664 */ 665 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); 666 667 /** 668 * @brief Frees resources allocated by iterator_init 669 * @note Must be called after iteration to free resources 670 * @param it 671 * @see note on gap_link_key_iterator_init 672 */ 673 void gap_link_key_iterator_done(btstack_link_key_iterator_t * it); 674 675 /** 676 * @brief Start GAP Classic Inquiry 677 * @param duration in 1.28s units 678 * @return 0 if ok 679 * @events: GAP_EVENT_INQUIRY_RESULT, GAP_EVENT_INQUIRY_COMPLETE 680 */ 681 int gap_inquiry_start(uint8_t duration_in_1280ms_units); 682 683 /** 684 * @brief Stop GAP Classic Inquiry 685 * @brief Stop GAP Classic Inquiry 686 * @returns 0 if ok 687 * @events: GAP_EVENT_INQUIRY_COMPLETE 688 */ 689 int gap_inquiry_stop(void); 690 691 /** 692 * @brief Remote Name Request 693 * @param addr 694 * @param page_scan_repetition_mode 695 * @param clock_offset only used when bit 15 is set - pass 0 if not known 696 * @events: HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE 697 */ 698 int gap_remote_name_request(const bd_addr_t addr, uint8_t page_scan_repetition_mode, uint16_t clock_offset); 699 700 /** 701 * @brief Legacy Pairing Pin Code Response 702 * @note data is not copied, pointer has to stay valid 703 * @param addr 704 * @param pin 705 * @return 0 if ok 706 */ 707 int gap_pin_code_response(const bd_addr_t addr, const char * pin); 708 709 /** 710 * @brief Legacy Pairing Pin Code Response for binary data / non-strings 711 * @note data is not copied, pointer has to stay valid 712 * @param addr 713 * @param pin_data 714 * @param pin_len 715 * @return 0 if ok 716 */ 717 int gap_pin_code_response_binary(const bd_addr_t addr, const uint8_t * pin_data, uint8_t pin_len); 718 719 /** 720 * @brief Abort Legacy Pairing 721 * @param addr 722 * @param pin 723 * @return 0 if ok 724 */ 725 int gap_pin_code_negative(bd_addr_t addr); 726 727 /** 728 * @brief SSP Passkey Response 729 * @param addr 730 * @param passkey [0..999999] 731 * @return 0 if ok 732 */ 733 int gap_ssp_passkey_response(const bd_addr_t addr, uint32_t passkey); 734 735 /** 736 * @brief Abort SSP Passkey Entry/Pairing 737 * @param addr 738 * @param pin 739 * @return 0 if ok 740 */ 741 int gap_ssp_passkey_negative(const bd_addr_t addr); 742 743 /** 744 * @brief Accept SSP Numeric Comparison 745 * @param addr 746 * @param passkey 747 * @return 0 if ok 748 */ 749 int gap_ssp_confirmation_response(const bd_addr_t addr); 750 751 /** 752 * @brief Abort SSP Numeric Comparison/Pairing 753 * @param addr 754 * @param pin 755 * @return 0 if ok 756 */ 757 int gap_ssp_confirmation_negative(const bd_addr_t addr); 758 759 /** 760 * @brief Generate new OOB data 761 * @note OOB data will be provided in GAP_EVENT_LOCAL_OOB_DATA and be used in future pairing procedures 762 */ 763 void gap_ssp_generate_oob_data(void); 764 765 /** 766 * @brief Report Remote OOB Data 767 * @param bd_addr 768 * @param c_192 Simple Pairing Hash C derived from P-192 public key 769 * @param r_192 Simple Pairing Randomizer derived from P-192 public key 770 * @param c_256 Simple Pairing Hash C derived from P-256 public key 771 * @param r_256 Simple Pairing Randomizer derived from P-256 public key 772 */ 773 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); 774 775 /** 776 * Send SSP IO Capabilities Reply 777 * @note IO Capabilities (Negative) Reply is sent automatically unless ENABLE_EXPLICIT_IO_CAPABILITIES_REPLY 778 * @param addr 779 * @return 0 if ok 780 */ 781 uint8_t gap_ssp_io_capabilities_response(const bd_addr_t addr); 782 783 /** 784 * Send SSP IO Capabilities Negative Reply 785 * @note IO Capabilities (Negative) Reply is sent automatically unless ENABLE_EXPLICIT_IO_CAPABILITIES_REPLY 786 * @param addr 787 * @return 0 if ok 788 */ 789 uint8_t gap_ssp_io_capabilities_negative(const bd_addr_t addr); 790 791 /** 792 * @brief Enter Sniff mode 793 * @param con_handle 794 * @param sniff_min_interval range: 0x0002 to 0xFFFE; only even values are valid, Time = N * 0.625 ms 795 * @param sniff_max_interval range: 0x0002 to 0xFFFE; only even values are valid, Time = N * 0.625 ms 796 * @param sniff_attempt Number of Baseband receive slots for sniff attempt. 797 * @param sniff_timeout Number of Baseband receive slots for sniff timeout. 798 @ @return 0 if ok 799 */ 800 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); 801 802 /** 803 * @brief Exit Sniff mode 804 * @param con_handle 805 @ @return 0 if ok 806 */ 807 uint8_t gap_sniff_mode_exit(hci_con_handle_t con_handle); 808 809 /** 810 * @brief Configure Sniff Subrating 811 * @param con_handle 812 * @param max_latency range: 0x0002 to 0xFFFE; Time = N * 0.625 ms 813 * @param min_remote_timeout range: 0x0002 to 0xFFFE; Time = N * 0.625 ms 814 * @param min_local_timeout range: 0x0002 to 0xFFFE; Time = N * 0.625 ms 815 @ @return 0 if ok 816 */ 817 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); 818 819 /** 820 * @Brief Set QoS 821 * @param con_handle 822 * @param service_type 823 * @param token_rate 824 * @param peak_bandwidth 825 * @param latency 826 * @param delay_variation 827 @ @return 0 if ok 828 */ 829 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); 830 831 #endif 832 833 // LE 834 835 /** 836 * @brief Get own addr type and address used for LE 837 */ 838 void gap_le_get_own_address(uint8_t * addr_type, bd_addr_t addr); 839 840 841 /** 842 * @brief Get state of connection re-encryption for bonded devices when in central role 843 * @note used by gatt_client and att_server to wait for re-encryption 844 * @param con_handle 845 * @return 1 if security setup is active 846 */ 847 int gap_reconnect_security_setup_active(hci_con_handle_t con_handle); 848 849 /** 850 * @brief Delete bonding information for remote device 851 * @note On most desktop ports, the LE Device DB uses a TLV and there is one TLV storage per 852 * Controller resp. its Bluetooth Address. As the Bluetooth Address is retrieved during 853 * power up, this function only works, when the stack is in working state for these ports. 854 * @param address_type 855 * @param address 856 */ 857 void gap_delete_bonding(bd_addr_type_t address_type, bd_addr_t address); 858 859 /** 860 * LE Privacy 1.2 - requires support by Controller and ENABLE_LE_RESOLVING_LIST to be defined 861 */ 862 863 /** 864 * @brief Load LE Device DB entries into Controller Resolving List to allow filtering on 865 * bonded devies with resolvable private addresses 866 * @return EROOR_CODE_SUCCESS if supported by Controller 867 */ 868 uint8_t gap_load_resolving_list_from_le_device_db(void); 869 870 /** 871 * @brief Get local persistent IRK 872 */ 873 const uint8_t * gap_get_persistent_irk(void); 874 875 /* API_END*/ 876 877 #if defined __cplusplus 878 } 879 #endif 880 881 #endif // GAP_H 882