components/bt/host/bluedroid/stack/btm/btm_sec.c
/*******************************************************************************
**
** Function         btm_sec_set_peer_sec_caps
**
** Description      This function is called to set sm4 and rmt_sec_caps fields
**                  based on the available peer device features.
**
** Returns          void
**
*******************************************************************************/
Function         btm_sec_set_peer_sec_caps
Description      This function is called to set sm4 and rmt_sec_caps fields
based on the available peer device features.

Returns          void
Function btm_sec_set_peer_sec_caps Description This function is called to set sm4 and rmt_sec_caps fields based on the available peer device features . Returns void
void btm_sec_set_peer_sec_caps(tACL_CONN *p_acl_cb, tBTM_SEC_DEV_REC *p_dev_rec)
{
    BD_ADDR     rem_bd_addr;
    UINT8       *p_rem_bd_addr;
    if ((btm_cb.security_mode == BTM_SEC_MODE_SP ||
            btm_cb.security_mode == BTM_SEC_MODE_SP_DEBUG ||
            btm_cb.security_mode == BTM_SEC_MODE_SC) &&
            HCI_SSP_HOST_SUPPORTED(p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_1])) {
        p_dev_rec->sm4 = BTM_SM4_TRUE;
        p_dev_rec->remote_supports_secure_connections =
            (HCI_SC_HOST_SUPPORTED(p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_1]));
    } else {
        p_dev_rec->sm4 = BTM_SM4_KNOWN;
        p_dev_rec->remote_supports_secure_connections = FALSE;
    }
    BTM_TRACE_API("%s: sm4: 0x%02x, rmt_support_for_secure_connections %d\n", __FUNCTION__,
                  p_dev_rec->sm4, p_dev_rec->remote_supports_secure_connections);
#if (CLASSIC_BT_INCLUDED == TRUE)
    if (p_dev_rec->remote_supports_secure_connections >= p_dev_rec->remote_secure_connection_previous_state) {
        p_dev_rec->remote_secure_connection_previous_state = p_dev_rec->remote_supports_secure_connections;
    } else {
        BTM_TRACE_ERROR("Remote Device downgraded security from SC, deleting Link Key");
        p_acl_cb->sc_downgrade = 1;
        p_dev_rec->remote_secure_connection_previous_state = 0;
        memset(p_dev_rec->link_key, 0, LINK_KEY_LEN);
        p_dev_rec->sec_flags &= ~(BTM_SEC_AUTHORIZED | BTM_SEC_AUTHENTICATED
                                | BTM_SEC_ENCRYPTED | BTM_SEC_NAME_KNOWN
                                | BTM_SEC_LINK_KEY_KNOWN | BTM_SEC_LINK_KEY_AUTHED
                                | BTM_SEC_ROLE_SWITCHED | BTM_SEC_16_DIGIT_PIN_AUTHED);
        return;
    }
#endif
    if (p_dev_rec->remote_features_needed) {
        BTM_TRACE_EVENT("%s: Now device in SC Only mode, waiting for peer remote features!\n",
                        __FUNCTION__);
        p_rem_bd_addr = (UINT8 *) rem_bd_addr;
        BDADDR_TO_STREAM(p_rem_bd_addr, p_dev_rec->bd_addr);
        p_rem_bd_addr = (UINT8 *) rem_bd_addr;
        btm_io_capabilities_req(p_rem_bd_addr);
        p_dev_rec->remote_features_needed = FALSE;
    }
}
void btm_sec_set_peer_sec_caps ( tACL_CONN * p_acl_cb , tBTM_SEC_DEV_REC * p_dev_rec ) { BD_ADDR rem_bd_addr ; UINT8 * p_rem_bd_addr ; if ( ( btm_cb . security_mode == BTM_SEC_MODE_SP || btm_cb . security_mode == BTM_SEC_MODE_SP_DEBUG || btm_cb . security_mode == BTM_SEC_MODE_SC ) && HCI_SSP_HOST_SUPPORTED ( p_acl_cb -> peer_lmp_features [ HCI_EXT_FEATURES_PAGE_1 ] ) ) { p_dev_rec -> sm4 = BTM_SM4_TRUE ; p_dev_rec -> remote_supports_secure_connections = ( HCI_SC_HOST_SUPPORTED ( p_acl_cb -> peer_lmp_features [ HCI_EXT_FEATURES_PAGE_1 ] ) ) ; } else { p_dev_rec -> sm4 = BTM_SM4_KNOWN ; p_dev_rec -> remote_supports_secure_connections = FALSE ; } BTM_TRACE_API ( " \n " , __FUNCTION__ , p_dev_rec -> sm4 , p_dev_rec -> remote_supports_secure_connections ) ; #if ( CLASSIC_BT_INCLUDED == TRUE ) if ( p_dev_rec -> remote_supports_secure_connections >= p_dev_rec -> remote_secure_connection_previous_state ) { p_dev_rec -> remote_secure_connection_previous_state = p_dev_rec -> remote_supports_secure_connections ; } else { BTM_TRACE_ERROR ( " " ) ; p_acl_cb -> sc_downgrade = 1 ; p_dev_rec -> remote_secure_connection_previous_state = 0 ; memset ( p_dev_rec -> link_key , 0 , LINK_KEY_LEN ) ; p_dev_rec -> sec_flags &= ~ ( BTM_SEC_AUTHORIZED | BTM_SEC_AUTHENTICATED | BTM_SEC_ENCRYPTED | BTM_SEC_NAME_KNOWN | BTM_SEC_LINK_KEY_KNOWN | BTM_SEC_LINK_KEY_AUTHED | BTM_SEC_ROLE_SWITCHED | BTM_SEC_16_DIGIT_PIN_AUTHED ) ; return ; } #endif if ( p_dev_rec -> remote_features_needed ) { BTM_TRACE_EVENT ( " \n " , __FUNCTION__ ) ; p_rem_bd_addr = ( UINT8 * ) rem_bd_addr ; BDADDR_TO_STREAM ( p_rem_bd_addr , p_dev_rec -> bd_addr ) ; p_rem_bd_addr = ( UINT8 * ) rem_bd_addr ; btm_io_capabilities_req ( p_rem_bd_addr ) ; p_dev_rec -> remote_features_needed = FALSE ; } }
Function         btm_sec_set_peer_sec_caps
Description      This function is called to set sm4 and rmt_sec_caps fields
based on the available peer device features.
Function btm_sec_set_peer_sec_caps Description This function is called to set sm4 and rmt_sec_caps fields based on the available peer device features .
/* Store previous state of remote device to check if peer device downgraded
     * it's secure connection state. */ /* Mark in ACL packet that secure connection is downgraded. */ /* As peer device downgraded it's security, peer device is a suspicious
         * device. Hence remove pairing information by removing link key
         * information. */