Пример #1
0
static void prf_client_pool_envs_free(prf_env_struct ***p_envs)
{
    // Check if the pool of environments exists
    if (*p_envs != NULL)
    {
        // No environment exists, free the array of environment pointers
        ke_free(*p_envs);
        // Reset the address of the pool
        *p_envs = NULL;
    }
}
Пример #2
0
static uint8_t prf_client_env_free(prf_env_struct ***p_envs, uint8_t conidx, prf_cleanup_cb cleanup)
{
    // Status
    uint8_t status = PRF_ERR_OK;
    // Pointer to a profile environment
    prf_env_struct *p_prf_env = NULL;

    // Check that the provided pointer in non-NULL and that conidx is OK
    if ((p_envs != NULL) && (conidx <  jump_table_struct[nb_links_user]))
    {
        // Check if the pool of environments exists
        if (*p_envs != NULL)
        {
            // Get the address of the environment for the provided connection
            p_prf_env = *(*p_envs + conidx);
        }

        // Check if this environment exists
        if (p_prf_env != NULL)
        {
            // request profile to clean-up variable allocated dynamically for current connection
            if(cleanup != NULL)
            {
                cleanup(p_prf_env);
            }

            // Free the profile environment
            ke_free(p_prf_env);

            // Reset the address of the environment in the pool
            *(*p_envs + conidx) = NULL;
        }
        else
        {
            // The environment doesn't exist.
            status = PRF_ERR_INVALID_PARAM;
        }
    }
    else
    {
        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);
}