diff --git a/CHANGELOG.md b/CHANGELOG.md index 522134bc5..0ba495921 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - GAP: add `gap_get_link_key_for_bd_addr` +- GAP: add `gap_bonded` to check if bonding information is available for active connection - SM: support h7 for CTKD ### Changed diff --git a/src/gap.h b/src/gap.h index 3e39b1bea..9e4c26244 100644 --- a/src/gap.h +++ b/src/gap.h @@ -552,6 +552,14 @@ int gap_secure_connection(hci_con_handle_t con_handle); */ authorization_state_t gap_authorization_state(hci_con_handle_t con_handle); +/** + * @brief Get bonded property (BR/EDR/LE) + * @note LE: has to be called after identity resolving is complete + * @param con_handle + * @return true if bonded + */ +bool gap_bonded(hci_con_handle_t con_handle); + // Classic /** diff --git a/src/hci.c b/src/hci.c index 7fc272527..9ea40af7d 100644 --- a/src/hci.c +++ b/src/hci.c @@ -5953,6 +5953,27 @@ int gap_secure_connection(hci_con_handle_t con_handle){ } } +bool gap_bonded(hci_con_handle_t con_handle){ + hci_connection_t * hci_connection = hci_connection_for_handle(con_handle); + if (hci_connection == NULL) return 0; + + link_key_t link_key; + link_key_type_t link_key_type; + switch (hci_connection->address_type){ + case BD_ADDR_TYPE_LE_PUBLIC: + case BD_ADDR_TYPE_LE_RANDOM: + return hci_connection->sm_connection.sm_le_db_index >= 0; +#ifdef ENABLE_CLASSIC + case BD_ADDR_TYPE_SCO: + case BD_ADDR_TYPE_ACL: + return hci_stack->link_key_db && hci_stack->link_key_db->get_link_key(hci_connection->address, link_key, &link_key_type); +#endif + default: + return false; + } +} + + authorization_state_t gap_authorization_state(hci_con_handle_t con_handle){ sm_connection_t * sm_conn = sm_get_connection_for_handle(con_handle); if (!sm_conn) return AUTHORIZATION_UNKNOWN; // wrong connection