/* Function for allocating instance. 
The instance identifier is provided in the 'p_instance' parameter if the routine succeeds. */
static __INLINE uint32_t connection_instance_allocate(uint32_t *p_instance)
/* Function for allocating instance. 
The instance identifier is provided in the 'p_instance' parameter if the routine succeeds. */
static __INLINE uint32_t connection_instance_allocate(uint32_t *p_instance)
{
    uint32_t err_code;
    DM_TRC("[DM]: Request to allocation connection instance\r\n");
    err_code = connection_instance_find(BLE_CONN_HANDLE_INVALID, STATE_IDLE, p_instance);
    if (err_code == NRF_SUCCESS)
    {
        DM_LOG("[DM]:[%02X]: Connection Instance Allocated.\r\n", (*p_instance));        
        m_connection_table[*p_instance].state = STATE_CONNECTED;
    }
    else
    {
        DM_LOG("[DM]: No free connection instances available\r\n");        
        err_code = NRF_ERROR_NO_MEM;
    }
    return err_code;
}