Пример #1
0
static uint8_t prf_client_pool_envs_alloc(prf_env_struct ***p_envs)
{
    // Allocation status
    uint8_t status = PRF_ERR_OK;

    // Check if provided pointer is NULL
    if (*p_envs == NULL)
    {
        // Allocates buffer size for  jump_table_struct[nb_links_user] pointers
        *p_envs = (prf_env_struct **)ke_malloc( jump_table_struct[nb_links_user]*sizeof(prf_env_struct *), KE_MEM_ATT_DB);

        // Check if a non-NULL pointer has been returned
        if(*p_envs == NULL)
        {
            // Not enough memory to allocate the data structure.
            status = PRF_ERR_REQ_DISALLOWED;
        }
        else
        {
            // Initialize all pointers for the pool to NULL
            memset(*p_envs, 0,  jump_table_struct[nb_links_user]*sizeof(prf_env_struct *));
        }
    }
    else
    {
        // envs should be a NULL pointer
        status = PRF_ERR_REQ_DISALLOWED;
    }

    return status;
}
Пример #2
0
static uint8_t prf_client_env_alloc(prf_env_struct ***p_envs, uint8_t conidx, uint16_t env_size)
{
    // Status
    uint8_t status = PRF_ERR_OK;
    // Pointer to the environment
    prf_env_struct *env;

    /*
     * Check if the pool of environment already exists. This pool exists only if it contains
     * the address of at least one environment.
     */
    if (*p_envs == NULL)
    {
        // Allocate the pool which contains the address of each profile client role environment.
        status = prf_client_pool_envs_alloc(p_envs);
    }

    // If the pool exists, allocate a new environment
    if (status == PRF_ERR_OK)
    {
        // Check index
        if (conidx <  jump_table_struct[nb_links_user])
        {
            // Get the current address of the environment
            env = *(*p_envs + conidx);

            // Check if the environment matching this index already exists.
            if (env == NULL)
            {
                // Allocate a new environment.
                env = (prf_env_struct *)ke_malloc((uint32_t)env_size, KE_MEM_ATT_DB);

                // Check if the memory for the environment has been successfully allocated.
                if (env == NULL)
                {
                    // Not enough memory to allocate a new environment.
                    status = PRF_ERR_REQ_DISALLOWED;
                }
                else
                {
                    // Initialize values in the profile environment
                    memset(env, 0, env_size);

                    // Save the address of the environment in the pool.
                    *(*p_envs + conidx) = env;
                }
            }
            else
            {
                // The profile client role is already enable for this index.
                status = PRF_ERR_REQ_DISALLOWED;
            }
        }
        else
        {
            // The provided connection doesn't exist.
            status = PRF_ERR_INVALID_PARAM;
        }
    }

    return status;
}
Пример #3
0
static int qpps_create_db_req_handler(ke_msg_id_t const msgid,
                                      struct qpps_create_db_req const *param,
                                      ke_task_id_t const dest_id,
                                      ke_task_id_t const src_id)
{
    //Service Configuration Flag
    uint64_t cfg_flag = QPPS_MANDATORY_MASK;
    //Database Creation Status
    uint8_t status;
    uint8_t idx_nb = 4;
    uint8_t tx_char_num = param->tx_char_num;
    struct atts_desc_ext *qpps_db = NULL;
    struct atts_char128_desc *char_desc_def = NULL;

    if (tx_char_num > 7)
        tx_char_num = 7;

    //Save Application ID
    qpps_env.appid = src_id;
    qpps_env.ntf_char_num = tx_char_num;
    /*---------------------------------------------------*
     * Quintic private Service Creation
     *---------------------------------------------------*/

    if (tx_char_num > 1)
    {
        qpps_db = (struct atts_desc_ext *)ke_malloc(sizeof(qpps_att_db) + 3 * (tx_char_num) * sizeof(struct atts_desc_ext));
        char_desc_def = (struct atts_char128_desc *)ke_malloc((tx_char_num) * sizeof(struct atts_char128_desc));
        for (uint8_t i = 0; i < tx_char_num; i++)
        {
            struct atts_char128_desc value_char = ATTS_CHAR128(ATT_CHAR_PROP_NTF,
                                                                0,
                                                            QPPS_FIRST_TX_CHAR_UUID);
            
            value_char.attr_type[0] += i;
            char_desc_def[i] = value_char;
        }

        memcpy(qpps_db, qpps_att_db, sizeof(qpps_att_db));

        for (uint8_t i = 0; i < tx_char_num; i++)
        {
            qpps_db[QPPS_IDX_VAL_CHAR + i * 3] = qpps_db[QPPS_IDX_VAL_CHAR];
            qpps_db[QPPS_IDX_VAL_CHAR + i * 3].value = (uint8_t*)&char_desc_def[i];
            qpps_db[QPPS_IDX_VAL_CHAR + i * 3 + 1] = qpps_db[QPPS_IDX_VAL];
            qpps_db[QPPS_IDX_VAL_CHAR + i * 3 + 1].type.uuid = qpp_uuid_list[i];
            qpps_db[QPPS_IDX_VAL_CHAR + i * 3 + 2] = qpps_db[QPPS_IDX_VAL + 1];
        }
    }

    while (tx_char_num--)
    {
        cfg_flag = (cfg_flag << 3) | 0x07;
        idx_nb += 3;
    }
    //Add Service Into Database
    status = atts_svc_create_db_ext(&qpps_env.shdl, (uint8_t *)&cfg_flag, idx_nb, NULL,
                               dest_id, (param->tx_char_num <= 1 ? &qpps_att_db[0] : &qpps_db[0]));

    if (qpps_db != NULL)
        ke_free(qpps_db);
    if (char_desc_def != NULL)
        ke_free(char_desc_def);
    
    //Disable QPPS
    attsdb_svc_set_permission(qpps_env.shdl, PERM(SVC, DISABLE));

    //Go to Idle State
    if (status == ATT_ERR_NO_ERROR)
    {
        //If we are here, database has been fulfilled with success, go to idle test
        ke_state_set(TASK_QPPS, QPPS_IDLE);
    }

    //Send response to application
    struct qpps_create_db_cfm * cfm = KE_MSG_ALLOC(QPPS_CREATE_DB_CFM, qpps_env.appid,
                                                   TASK_QPPS, qpps_create_db_cfm);
    cfm->status = status;
    ke_msg_send(cfm);

    return (KE_MSG_CONSUMED);
}