/* Function for possibly cleaning up after a failed pairing or encryption procedure.  */
static void link_secure_failure(uint16_t conn_handle, pm_sec_error_code_t error, uint8_t error_src)
/* Function for possibly cleaning up after a failed pairing or encryption procedure.  */
static void link_secure_failure(uint16_t conn_handle, pm_sec_error_code_t error, uint8_t error_src)
{
    if (ble_conn_state_user_flag_get(conn_handle, m_smd.flag_id_sec_proc))
    {
        pm_peer_id_t  peer_id = im_peer_id_get_by_conn_handle(conn_handle);
        if (peer_id != PM_PEER_ID_INVALID)
        {
            if (ble_conn_state_user_flag_get(conn_handle, m_smd.flag_id_sec_proc_pairing))
            {
                pairing_failure(conn_handle, peer_id, error, error_src);
            }
            else
            {
                encryption_failure(conn_handle, error, error_src);
            }
        }
    }
}