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