/* Function for searching connection instance matching the connection handle and the state requested. 
Connection handle and state information is used to get a connection instance, it is possible to ignore the connection handle by using BLE_CONN_HANDLE_INVALID. */
static ret_code_t connection_instance_find(uint16_t conn_handle, uint8_t state, uint32_t *p_instance)
/* Function for searching connection instance matching the connection handle and the state requested. 
Connection handle and state information is used to get a connection instance, it is possible to ignore the connection handle by using BLE_CONN_HANDLE_INVALID. */
static ret_code_t connection_instance_find(uint16_t conn_handle, uint8_t state, uint32_t *p_instance)
{
    ret_code_t err_code;
    uint32_t     index;
    err_code = NRF_ERROR_INVALID_STATE;
    for (index = 0; index < DEVICE_MANAGER_MAX_CONNECTIONS; index++)
    {
        if (state & m_connection_table[index].state)
        {
            if ((conn_handle == BLE_CONN_HANDLE_INVALID) ||
                (conn_handle == m_connection_table[index].conn_handle))
            {
                (*p_instance) = index;
                err_code      = NRF_SUCCESS;
                break;
            }
            else
            {
                err_code = NRF_ERROR_NOT_FOUND;
            }
        }
    }
    return err_code;
}