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