示例#1
0
void pasps_disable(struct pasps_idx_env_tag *idx_env)
{
    // Disable PAS service
    attsdb_svc_set_permission(pasps_env.pass_shdl, PERM(SVC, DISABLE));

    struct pasps_disable_ind *ind = KE_MSG_ALLOC(PASPS_DISABLE_IND,
                                                 idx_env->con_info.appid, idx_env->con_info.prf_id,
                                                 pasps_disable_ind);

    memset(ind, 0x00, sizeof(struct pasps_disable_ind));

    ind->conhdl = idx_env->con_info.conhdl;

    if (PASPS_IS_NTF_ENABLED(idx_env, PASPS_FLAG_ALERT_STATUS_CFG))
    {
        ind->alert_status_ntf_cfg = PRF_CLI_START_NTF;
    }

    if (PASPS_IS_NTF_ENABLED(idx_env, PASPS_FLAG_RINGER_SETTING_CFG))
    {
        ind->ringer_setting_ntf_cfg = PRF_CLI_START_NTF;
    }

    ke_msg_send(ind);

    // Go to idle state
    ke_state_set(idx_env->con_info.prf_id, PASPS_IDLE);

    // Free the environment allocated for this connection
    prf_client_disable((prf_env_struct ***)&pasps_idx_envs, KE_IDX_GET(idx_env->con_info.prf_id));
}
示例#2
0
void cscps_disable(void)
{
	// Disable CSCS in database
    attsdb_svc_set_permission(cscps_env.shdl, PERM_RIGHT_DISABLE);

    //Send current configuration to APP
    struct cscps_disable_ind* ind = KE_MSG_ALLOC(CSCPS_DISABLE_IND,
                                                 cscps_env.con_info.appid, cscps_env.con_info.prf_id,
                                                 cscps_disable_ind);

    ind->conhdl = cscps_env.con_info.conhdl;

    // CSC Measurement Char. - Client Characteristic Configuration Descriptor
    ind->csc_meas_ntf_cfg = CSCPS_IS_NTFIND_ENABLED(CSCP_PRF_CFG_FLAG_CSC_MEAS_NTF)
                            ? PRF_CLI_START_NTF : PRF_CLI_STOP_NTFIND;

    // SC Control Point Char. - Client Characteristic Configuration Descriptor
    if (cscps_env.hdl_offset[CSCP_CSCS_SC_CTNL_PT_CHAR] != 0)
    {
        ind->sc_ctnl_pt_ntf_cfg = CSCPS_IS_NTFIND_ENABLED(CSCP_PRF_CFG_FLAG_SC_CTNL_PT_IND)
                                  ? PRF_CLI_START_IND : PRF_CLI_STOP_NTFIND;
    }

    // Total wheel revolutions
    ind->wheel_revol = cscps_env.wheel_revol;

    ke_msg_send(ind);

    // Reset the notification/indication status
    cscps_env.prf_cfg &= CSCP_FEAT_ALL_SUPP;

    // Go to idle state
    ke_state_set(TASK_CSCPS, CSCPS_IDLE);
}
示例#3
0
void hogpd_disable(void)
{
    // HIDS instance counter
    uint8_t hids_nb;
    // Report Char. instance counter
    uint8_t report_nb;

    struct hogpd_disable_ind *ind = KE_MSG_ALLOC(HOGPD_DISABLE_IND,
                                                 hogpd_env.con_info.appid, TASK_HOGPD,
                                                 hogpd_disable_ind);

    ind->conhdl = hogpd_env.con_info.conhdl;

    for (hids_nb = 0; hids_nb < hogpd_env.hids_nb; hids_nb++)
    {
        // Disable HIDS in database
        attsdb_svc_set_permission(hogpd_env.shdl[hids_nb], PERM_RIGHT_DISABLE);

        // Save Boot Keyboard Input Report Char. Ntf Cfg
        if (hogpd_env.att_tbl[hids_nb][HOGPD_BOOT_KB_IN_REPORT_CHAR] != 0x00)
        {
            if ((hogpd_env.features[hids_nb].svc_features & HOGPD_BOOT_KB_IN_NTF_CFG_MASK)
                                                         == HOGPD_BOOT_KB_IN_NTF_CFG_MASK)
            {
                ind->ntf_cfg[hids_nb].boot_kb_in_report_ntf_en = PRF_CLI_START_NTF;
            }
        }

        // Save Boot Mouse Input Report Char. Ntf Cfg
        if (hogpd_env.att_tbl[hids_nb][HOGPD_BOOT_MOUSE_IN_REPORT_CHAR] != 0x00)
        {
            if ((hogpd_env.features[hids_nb].svc_features & HOGPD_BOOT_MOUSE_IN_NTF_CFG_MASK)
                                                         == HOGPD_BOOT_MOUSE_IN_NTF_CFG_MASK)
            {
                ind->ntf_cfg[hids_nb].boot_mouse_in_report_ntf_en = PRF_CLI_START_NTF;
            }
        }

        //Reset notifications bit field
        hogpd_env.features[hids_nb].svc_features &= ~(HOGPD_BOOT_KB_IN_NTF_CFG_MASK | HOGPD_BOOT_MOUSE_IN_NTF_CFG_MASK);

        // Save Report Char. Ntf Cfg
        for (report_nb = 0; report_nb < hogpd_env.features[hids_nb].report_nb; report_nb++)
        {
            if ((hogpd_env.features[hids_nb].report_char_cfg[report_nb] & HOGPD_REPORT_NTF_CFG_MASK)
                                                                       == HOGPD_REPORT_NTF_CFG_MASK)
            {
                ind->ntf_cfg[hids_nb].report_ntf_en[report_nb] = PRF_CLI_START_NTF;
            }

            //Reset notifications bit field
            hogpd_env.features[hids_nb].report_char_cfg[report_nb] &= ~HOGPD_REPORT_NTF_CFG_MASK;
        }
    }

    ke_msg_send(ind);

    //Go to idle state
    ke_state_set(TASK_HOGPD, HOGPD_IDLE);
}
示例#4
0
void scpps_disable(void)
{
    //Disable SCPS in database
    attsdb_svc_set_permission(scpps_env.shdl, PERM_RIGHT_DISABLE);

    //Send current configuration to the application
    struct scpps_disable_ind *ind = KE_MSG_ALLOC(SCPPS_DISABLE_IND,
                                                 scpps_env.con_info.appid, TASK_SCPPS,
                                                 scpps_disable_ind);

    ind->conhdl = scpps_env.con_info.conhdl;

    if (scpps_env.scan_refresh_ntf_cfg == PRF_CLI_START_NTF)
    {
        ind->scan_refresh_ntf_en = PRF_CLI_START_NTF;
    }

    ke_msg_send(ind);

    // Reset saved NTF cfg value
    scpps_env.scan_refresh_ntf_cfg = 0;

    // Go to Idle state
    ke_state_set(TASK_SCPPS, SCPPS_IDLE);
}
示例#5
0
/**
 ****************************************************************************************
 * @brief Handles reception of the @ref GLPS_CREATE_DB_REQ message.
 * The handler adds GLS into the database using the database
 * configuration value given in param.
 * @param[in] msgid Id of the message received (probably unused).
 * @param[in] param Pointer to the parameters of the message.
 * @param[in] dest_id ID of the receiving task instance (probably unused).
 * @param[in] src_id ID of the sending task instance.
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
static int glps_create_db_req_handler(ke_msg_id_t const msgid,
                                      struct glps_create_db_req const *param,
                                      ke_task_id_t const dest_id,
                                      ke_task_id_t const src_id)
{
    //Service Configuration Flag
    uint16_t cfg_flag = GLPS_MANDATORY_MASK;
    //Database Creation Status
    uint8_t status;

    //Save Profile ID
    glps_env.con_info.prf_id = TASK_GLPS;

    //Save Database Configuration
    if(param->meas_ctx_supported)
    {
        GLPS_SET(MEAS_CTX_SUPPORTED);
    }

    // set start handle or automatically set it when creating database (start_hdl = 0)
    glps_env.shdl=param->start_hdl;

    /*---------------------------------------------------*
     * Glucose Service Creation
     *---------------------------------------------------*/
    //Set Configuration Flag Value
    if (GLPS_IS(MEAS_CTX_SUPPORTED))
    {
        cfg_flag |= GLPS_MEAS_CTX_PRES_MASK;
    }

    //Add Service Into Database
    status = atts_svc_create_db(&glps_env.shdl, (uint8_t *)&cfg_flag, GLS_IDX_NB, NULL,
                               dest_id, &glps_att_db[0]);
    //Disable GLS
    attsdb_svc_set_permission(glps_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_GLPS, GLPS_IDLE);
    }

    //Send response to application
    struct glps_create_db_cfm * cfm = KE_MSG_ALLOC(GLPS_CREATE_DB_CFM, src_id,
                                                   TASK_GLPS, glps_create_db_cfm);
    cfm->status = status;
    ke_msg_send(cfm);

    return (KE_MSG_CONSUMED);
}
示例#6
0
/**
 ****************************************************************************************
 * @brief Handles reception of the @ref QPPS_ENABLE_REQ message.
 * The handler enables the Quintic private Profile.
 * @param[in] msgid Id of the message received (probably unused).
 * @param[in] param Pointer to the parameters of the message.
 * @param[in] dest_id ID of the receiving task instance (probably unused).
 * @param[in] src_id ID of the sending task instance.
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
static int qpps_enable_req_handler(ke_msg_id_t const msgid,
                                   struct qpps_enable_req const *param,
                                   ke_task_id_t const dest_id,
                                   ke_task_id_t const src_id)
{
    uint16_t value = 0;

    // Save the application task id
    qpps_env.appid = src_id;
    // Save the connection handle associated to the profile
    qpps_env.conhdl = param->conhdl;

    // If this connection is a not configuration one, apply config saved by app
    if(param->con_type == PRF_CON_NORMAL)
    {
		qpps_env.features = param->ntf_en;
		for (uint8_t i = 0; i < qpps_env.ntf_char_num; i++)
		{
			//Set Val NTF Configuration in DB
  			if (QPPS_IS_SUPPORTED(i, QPPS_VALUE_NTF_CFG))
			{
		        value = QPPS_VALUE_NTF_CFG;
				attsdb_att_set_value(qpps_env.shdl + QPPS_IDX_VAL_NTF_CFG + i*3, sizeof(uint16_t),
									(uint8_t *)&value);
		    }
            else
            {
                value = 0;
				attsdb_att_set_value(qpps_env.shdl + QPPS_IDX_VAL_NTF_CFG + i*3, sizeof(uint16_t),
									(uint8_t *)&value);
            }
		}
    }
	else
	{
		for (uint8_t i = 0; i < qpps_env.ntf_char_num; i++)
		{
			//Set Val NTF Configuration in DB
			attsdb_att_set_value(qpps_env.shdl + QPPS_IDX_VAL_NTF_CFG + i*3, sizeof(uint16_t),
								 (uint8_t *)&value);
		}
	}

    // Enable Service + Set Security Level
    attsdb_svc_set_permission(qpps_env.shdl, param->sec_lvl);

    // Go to connected state
    ke_state_set(TASK_QPPS, QPPS_CONNECTED);

    return (KE_MSG_CONSUMED);
}
示例#7
0
/**
 ****************************************************************************************
 * @brief Handles reception of the @ref BLPS_CREATE_DB_REQ message.
 * The handler adds BPS into the database using the database
 * configuration value given in param.
 * @param[in] msgid Id of the message received (probably unused).
 * @param[in] param Pointer to the parameters of the message.
 * @param[in] dest_id ID of the receiving task instance (probably unused).
 * @param[in] src_id ID of the sending task instance.
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
static int blps_create_db_req_handler(ke_msg_id_t const msgid,
                                      struct blps_create_db_req const *param,
                                      ke_task_id_t const dest_id,
                                      ke_task_id_t const src_id)
{
    //Service Configuration Flag
    uint16_t cfg_flag = BLPS_MANDATORY_MASK;
    //Database Creation Status
    uint8_t status;

    //Save Application ID
    blps_env.con_info.prf_id = TASK_BLPS;
    //Save Database Configuration
    blps_env.features = param->features;

    // automatically set start handle when creating database
//    blps_env.shdl=0;
    /*---------------------------------------------------*
     * Blood Pressure Service Creation
     *---------------------------------------------------*/
    //Set Configuration Flag Value
    if (BLPS_IS_SUPPORTED(BLPS_INTM_CUFF_PRESS_SUP))
    {
        cfg_flag |= BLPS_INTM_CUFF_PRESS_MASK;
    }

    //Add Service Into Database
    status = atts_svc_create_db(&blps_env.shdl, (uint8_t *)&cfg_flag, BPS_IDX_NB, NULL,
                               dest_id, &blps_att_db[0]);
    //Disable BPS
    attsdb_svc_set_permission(blps_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_BLPS, BLPS_IDLE);
    }

    //Send response to application
    struct blps_create_db_cfm * cfm = KE_MSG_ALLOC(BLPS_CREATE_DB_CFM, src_id,
                                                   TASK_BLPS, blps_create_db_cfm);
    cfm->status = status;
    ke_msg_send(cfm);

    return (KE_MSG_CONSUMED);
}
示例#8
0
void findt_disable(void)
{
    // Inform the application about the disconnection
    struct findt_disable_ind *ind = KE_MSG_ALLOC(FINDT_DISABLE_IND,
                                                 findt_env.con_info.appid, TASK_FINDT,
                                                 findt_disable_ind);

    ind->conhdl = findt_env.con_info.conhdl;

    ke_msg_send(ind);

    //Disable IAS in database
    attsdb_svc_set_permission(findt_env.shdl, PERM_RIGHT_DISABLE);

    //Go to idle state
    ke_state_set(TASK_FINDT, FINDT_IDLE);
}
示例#9
0
void qpps_disable(void)
{
    //Disable QPPS in database
    attsdb_svc_set_permission(qpps_env.shdl, PERM_RIGHT_DISABLE);

    //Send current configuration to APP
    struct qpps_disable_ind * cfg = KE_MSG_ALLOC(QPPS_DISABLE_IND,
                                                 qpps_env.appid, TASK_QPPS,
                                                 qpps_disable_ind);

    memcpy(&cfg->conhdl, &qpps_env.conhdl, sizeof(uint16_t));

    //Notifications Configuration
    cfg->ntf_en = qpps_env.features;

    ke_msg_send(cfg);

    //Go to idle state
    ke_state_set(TASK_QPPS, QPPS_IDLE);
}
示例#10
0
文件: beacon_task.c 项目: haby77/tqb6
/**
 ****************************************************************************************
 * @brief Handles reception of the @ref BEACON_CREATE_DB_REQ message.
 * The handler adds BAS into the database using value of the features param.
 * @param[in] msgid Id of the message received (probably unused).
 * @param[in] param Pointer to the parameters of the message.
 * @param[in] dest_id ID of the receiving task instance (probably unused).
 * @param[in] src_id ID of the sending task instance.
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
static int beacon_create_db_req_handler(ke_msg_id_t const msgid,
                                      struct beacon_create_db_req const *param,
                                      ke_task_id_t const dest_id,
                                      ke_task_id_t const src_id)
{
    // Service content flag
    uint8_t cfg_flag = BEACON_CFG_FLAG_MANDATORY_MASK;
    // Status
    uint8_t status = PRF_ERR_OK;
//     // Counter
//     uint8_t i;
//     // Battery Level characteristic value permissions
//     uint16_t perm;
//     // Battery Level characteristic value properties
//     uint8_t prop;

    // Save profile id
    beacon_env.con_info.prf_id = TASK_BEACON;
    //beacon_env.features        = param->features;
    status = atts_svc_create_db(&beacon_env.shdl, (uint8_t *)&cfg_flag, BEACON_IDX_NB, NULL,dest_id, &beacon_att_db[0]);

    //Disable service
    status = attsdb_svc_set_permission(beacon_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_BEACON, BEACON_IDLE);
    }
    
    //Send response to application
    struct beacon_create_db_cfm * cfm = KE_MSG_ALLOC(BEACON_CREATE_DB_CFM, beacon_env.con_info.appid,
                                                   TASK_BEACON, beacon_create_db_cfm);
    cfm->status = status;
    ke_msg_send(cfm);
    
//     // Check number of BAS instances
//     if (param->bas_nb <= BASS_NB_BAS_INSTANCES_MAX)
//     {
//         // Save number of BAS
//         bass_env.bas_nb = param->bas_nb;

//         for (i = 0; ((i < param->bas_nb) && (status == PRF_ERR_OK)); i++)
//         {
//             // Save database configuration
//             bass_env.features[i] = param->features[i];

//             // Check if notifications are supported
//             if (bass_env.features[i] == BAS_BATT_LVL_NTF_SUP)
//             {
//                 cfg_flag |= BAS_CFG_FLAG_NTF_SUP_MASK;
//             }

//             // Check if multiple instances
//             if (bass_env.bas_nb > 1)
//             {
//                 cfg_flag |= BAS_CFG_FLAG_MTP_BAS_MASK;
//             }

//             //Create BAS in the DB
//             status = atts_svc_create_db(&bass_env.shdl[i], (uint8_t *)&cfg_flag, BAS_IDX_NB, NULL,
//                                         dest_id, &bas_att_db[0]);

//             //Disable the service and set optional features
//             if (status == PRF_ERR_OK)
//             {
//                 //Disable service
//                 status = attsdb_svc_set_permission(bass_env.shdl[i], PERM(SVC, DISABLE));

//                 //Set optional properties and permissions
//                 if (bass_env.features[i] == BAS_BATT_LVL_NTF_SUP)
//                 {
//                     prop = ATT_CHAR_PROP_RD | ATT_CHAR_PROP_NTF;
//                     perm = PERM(RD, ENABLE) | PERM(NTF, ENABLE);

//                     attsdb_att_partial_value_update(bass_env.shdl[i] + BAS_IDX_BATT_LVL_CHAR, 0, 1, &prop);
//                     attsdb_att_set_permission(bass_env.shdl[i] + BAS_IDX_BATT_LVL_VAL, perm);
//                 }
//             }

//             // Reset configuration flag
//             cfg_flag = BAS_CFG_FLAG_MANDATORY_MASK;
//         }

//         if (status == PRF_ERR_OK)
//         {
//             //If we are here, database has been fulfilled with success, go to idle state
//             ke_state_set(TASK_BASS, BASS_IDLE);
//         }
//     }
//     else
//     {
//         status = PRF_ERR_INVALID_PARAM;
//     }

//     // Send confirmation to application
//     struct bass_create_db_cfm * cfm = KE_MSG_ALLOC(BASS_CREATE_DB_CFM, src_id, TASK_BASS,
//                                                    bass_create_db_cfm);
//     cfm->status = status;
//     ke_msg_send(cfm);

     return (KE_MSG_CONSUMED);
}
示例#11
0
文件: beacon_task.c 项目: haby77/tqb6
/**
 ****************************************************************************************
 * @brief Handles reception of the @ref BAPS_ENABLE_REQ message.
 * The handler enables the Battery 'Profile' Server Role.
 * @param[in] msgid Id of the message received (probably unused).
 * @param[in] param Pointer to the parameters of the message.
 * @param[in] dest_id ID of the receiving task instance (probably unused).
 * @param[in] src_id ID of the sending task instance.
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
static int beacon_enable_req_handler(ke_msg_id_t const msgid,
                                   struct beacon_enable_req const *param,
                                   ke_task_id_t const dest_id,
                                   ke_task_id_t const src_id)
{
    // Save the application task id
    beacon_env.con_info.appid = src_id;
    // Save the connection handle associated to the profile
    beacon_env.conhdl = param->conhdl;
    
    // Check if the provided connection exist
    if (gap_get_rec_idx(param->conhdl) == GAP_INVALID_CONIDX)
    {
        // ??????????????????
        // The connection doesn't exist, request disallowed
        prf_server_error_ind_send((prf_env_struct *)&beacon_env, PRF_ERR_REQ_DISALLOWED,
                                  BEACON_ERROR_IND, BEACON_ENABLE_REQ);
    }
    else
    {
        attsdb_att_set_value(beacon_env.shdl + BEACON_IDX_LVL_VAL, sizeof(uint8_t),
                                  (uint8_t *)&param->measured_power_val);
        attsdb_svc_set_permission(beacon_env.shdl, param->sec_lvl);
    
        // Go to connected state
        ke_state_set(TASK_BEACON, BEACON_CONNECTED);
    }
    
    
    
//     // Attribute offset - Used to retrieve Char. Pres. Format Descriptor handle
//     uint8_t offset;
//     // Packed Char. Presentation Format value
//     uint8_t packed_char_pres[PRF_CHAR_PRES_FMT_SIZE];
//     // Counter
//     uint8_t i;
//     // Notification Configuration
//     uint16_t ntf_cfg = 0;

//     // Save the application task id
//     bass_env.con_info.appid = src_id;
//     // Save the connection handle associated to the profile
//     bass_env.con_info.conhdl = param->conhdl;

//     // Check if the provided connection exist
//     if (gap_get_rec_idx(param->conhdl) == GAP_INVALID_CONIDX)
//     {
//         // The connection doesn't exist, request disallowed
//         prf_server_error_ind_send((prf_env_struct *)&bass_env, PRF_ERR_REQ_DISALLOWED,
//                                   BASS_ERROR_IND, BASS_ENABLE_REQ);
//     }
//     else
//     {
//         // For each BAS instance
//         for (i = 0; i < bass_env.bas_nb; i++)
//         {
//             // Reset Offset value
//             offset = BAS_IDX_BATT_LVL_NTF_CFG;

//             // Update Battery Level value in DB
//             attsdb_att_set_value(bass_env.shdl[i] + BAS_IDX_BATT_LVL_VAL, sizeof(uint8_t),
//                                  (uint8_t *)&param->current_batt_lvl[i]);

//             // Check if BAS supports notifications
//             if (bass_env.features[i] == BAS_BATT_LVL_NTF_SUP)
//             {
//                 // Increment offset (Client Char. Cfg is placed before Char. Pres Fmt. in DB)
//                 offset++;

//                 // If client is a bonded client
//                 if (param->con_type == PRF_CON_NORMAL)
//                 {
//                     ntf_cfg = param->batt_level_ntf_cfg[i];

//                     /*
//                      * The server shall send a notification if value of the Battery Level characteristic
//                      * has changed while the service has been disconnected from a bonded client.
//                      */
//                     if (param->batt_level_ntf_cfg[i] == PRF_CLI_START_NTF)
//                     {
//                         // Conserve information in environment
//                         bass_env.features[i] |= BASS_FLAG_NTF_CFG_BIT;

//                         // Check if old and previous battery level values are different
//                         if (param->old_batt_lvl[i] != param->current_batt_lvl[i])
//                         {
//                             //Notify current battery level value
//                             struct gatt_notify_req *ntf = KE_MSG_ALLOC(GATT_NOTIFY_REQ, TASK_GATT,
//                                                                        TASK_BASS, gatt_notify_req);

//                             ntf->conhdl  = bass_env.con_info.conhdl;
//                             ntf->charhdl = bass_env.shdl[i] + BAS_IDX_BATT_LVL_VAL;

//                             ke_msg_send(ntf);
//                         }
//                     }
//                 }

//                 // Set NTF Cfg value in the DB
//                 attsdb_att_set_value(bass_env.shdl[i] + BAS_IDX_BATT_LVL_NTF_CFG, sizeof(uint16_t),
//                                      (uint8_t *)&ntf_cfg);
//             }

//             // Check if Characteristic Presentation Format descriptor has been added
//             if (bass_env.bas_nb > 1)
//             {
//                 prf_pack_char_pres_fmt(&packed_char_pres[0], &param->batt_level_pres_format[i]);

//                 /*
//                  * Set Characteristic Presentation Format descriptor value
//                  * Not supposed to change during connection
//                  */
//                 attsdb_att_set_value(bass_env.shdl[i] + offset,
//                                      PRF_CHAR_PRES_FMT_SIZE,
//                                      &packed_char_pres[0]);
//             }

//             // Enable Service + Set Security Level
//             attsdb_svc_set_permission(bass_env.shdl[i], param->sec_lvl);
//         }

//         // Go to connected state
//         ke_state_set(TASK_BASS, BASS_CONNECTED);
//     }

    return (KE_MSG_CONSUMED);
}
示例#12
0
/**
 ****************************************************************************************
 * @brief Handles reception of the @ref GLPS_ENABLE_REQ message.
 * The handler enables the Glucose Sensor Profile and initialize readable values.
 * @param[in] msgid Id of the message received (probably unused).off
 * @param[in] param Pointer to the parameters of the message.
 * @param[in] dest_id ID of the receiving task instance (probably unused).
 * @param[in] src_id ID of the sending task instance.
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
static int glps_enable_req_handler(ke_msg_id_t const msgid,
                                   struct glps_enable_req const *param,
                                   ke_task_id_t const dest_id,
                                   ke_task_id_t const src_id)
{
    uint8_t status = PRF_ERR_REQ_DISALLOWED;

    if(!GLPS_IS(ENABLE))
    {
        // Check if the provided connection exist
        if (gap_get_rec_idx(param->conhdl) != GAP_INVALID_CONIDX)
        {
            status = PRF_ERR_OK;

            GLPS_SET(ENABLE);

            //Value used to initialize all readable value in DB
            uint16_t indntf_cfg = PRF_CLI_STOP_NTFIND;

            // Save the application task id
            glps_env.con_info.appid = src_id;
            // Save the connection handle associated to the profile
            glps_env.con_info.conhdl = param->conhdl;

            // No RACP at service start.
            GLPS_CLEAR(RACP_ON_GOING);
            GLPS_CLEAR(SENDING_MEAS);

            // Configure Glucose Measuremment IND Cfg in DB
            if(param->con_type == PRF_CON_NORMAL)
            {
                glps_env.evt_cfg = param->evt_cfg;
            }
            else
            {
                glps_env.evt_cfg = 0;
            }

            if((glps_env.evt_cfg & GLPS_MEAS_NTF_CFG) != 0)
            {
                indntf_cfg = PRF_CLI_START_NTF;
            }

            //Set Glucose measurement notification configuration
            attsdb_att_set_value(GLPS_HANDLE(GLS_IDX_MEAS_NTF_CFG), sizeof(uint16_t),
                                 (uint8_t *)&indntf_cfg);

            // Configure Intermediate Cuff Pressure NTF Cfg in DB

            //Configure Glucose measurement context notification
            if (GLPS_IS(MEAS_CTX_SUPPORTED))
            {
                indntf_cfg = PRF_CLI_STOP_NTFIND;

                if((glps_env.evt_cfg & GLPS_MEAS_CTX_NTF_CFG) != 0)
                {
                    indntf_cfg = PRF_CLI_START_NTF;
                }

                //Set Glucose measurement context notification configuration
                attsdb_att_set_value(GLPS_HANDLE(GLS_IDX_MEAS_CTX_NTF_CFG), sizeof(uint16_t),
                                     (uint8_t *)&indntf_cfg);
            }

            indntf_cfg = PRF_CLI_STOP_NTFIND;

            if((glps_env.evt_cfg & GLPS_RACP_IND_CFG) != 0)
            {
                indntf_cfg = PRF_CLI_START_IND;
            }

            //Set record access control point indication configuration
            attsdb_att_set_value(GLPS_HANDLE(GLS_IDX_REC_ACCESS_CTRL_IND_CFG), sizeof(uint16_t),
                                 (uint8_t *)&indntf_cfg);


            //Set Glucose sensor features
            attsdb_att_set_value(GLPS_HANDLE(GLS_IDX_FEATURE_VAL), sizeof(uint16_t),
                                 (uint8_t *)&param->features);

            // Enable Service + Set Security Level
            attsdb_svc_set_permission(glps_env.shdl, param->sec_lvl);

            // Go to connected state
            ke_state_set(TASK_GLPS, GLPS_CONNECTED);
        }
    }

    // send completed information to APP task that contains error status
    struct glps_enable_cfm * cmp_evt = KE_MSG_ALLOC(GLPS_ENABLE_CFM, src_id,
                                                    TASK_GLPS, glps_enable_cfm);

    cmp_evt->conhdl     = param->conhdl;
    cmp_evt->status     = status;

    ke_msg_send(cmp_evt);

    return (KE_MSG_CONSUMED);
}
示例#13
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);
}
示例#14
0
/**
 ****************************************************************************************
 * @brief Handles reception of the @ref BLPS_ENABLE_REQ message.
 * The handler enables the Blood Pressure Sensor Profile and initialize readable values.
 * @param[in] msgid Id of the message received (probably unused).off
 * @param[in] param Pointer to the parameters of the message.
 * @param[in] dest_id ID of the receiving task instance (probably unused).
 * @param[in] src_id ID of the sending task instance.
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
static int blps_enable_req_handler(ke_msg_id_t const msgid,
                                   struct blps_enable_req const *param,
                                   ke_task_id_t const dest_id,
                                   ke_task_id_t const src_id)
{
    //Value used to initialize all readable value in DB
    uint16_t indntf_cfg = 0;

    // Save the application task id
    blps_env.con_info.appid = src_id;
    // Save the connection handle associated to the profile
    blps_env.con_info.conhdl = param->conhdl;

    // Check if the provided connection exist
    if (gap_get_rec_idx(param->conhdl) == GAP_INVALID_CONIDX)
    {
        // The connection doesn't exist, request disallowed
        prf_server_error_ind_send((prf_env_struct *)&blps_env, PRF_ERR_REQ_DISALLOWED,
                                  BLPS_ERROR_IND, BLPS_ENABLE_REQ);
    }
    else
    {
        // Set Blood Pressure Feature Value in database - Not supposed to change during connection
        attsdb_att_set_value(blps_env.shdl + BPS_IDX_BP_FEATURE_VAL, sizeof(uint16_t),
                             (uint8_t *)&param->bp_feature);

        // Configure Blood Pressure Measuremment IND Cfg in DB
        if(param->con_type == PRF_CON_NORMAL)
        {
            memcpy(&indntf_cfg, &param->bp_meas_ind_en, sizeof(uint16_t));

            if (param->bp_meas_ind_en == PRF_CLI_START_IND)
            {
                blps_env.evt_cfg |= BLPS_BP_MEAS_IND_CFG;
            }
        }

        //Set BP Meas. Char. IND Configuration in DB - 0 if not normal connection
        attsdb_att_set_value(blps_env.shdl + BPS_IDX_BP_MEAS_IND_CFG, sizeof(uint16_t),
                             (uint8_t *)&indntf_cfg);

        // Configure Intermediate Cuff Pressure NTF Cfg in DB
        if (BLPS_IS_SUPPORTED(BLPS_INTM_CUFF_PRESS_SUP))
        {
            if(param->con_type == PRF_CON_NORMAL)
            {
                memcpy(&indntf_cfg, &param->interm_cp_ntf_en, sizeof(uint16_t));

                if (param->interm_cp_ntf_en == PRF_CLI_START_NTF)
                {
                    blps_env.evt_cfg |= BLPS_INTM_CUFF_PRESS_NTF_CFG;
                }
            }

            //Set Intm. Cuff Pressure NTF Configuration in DB - 0 if not normal connection
            attsdb_att_set_value(blps_env.shdl + BPS_IDX_INTM_CUFF_PRESS_NTF_CFG, sizeof(uint16_t),
                                 (uint8_t *)&indntf_cfg);
        }

        // Enable Service + Set Security Level
        attsdb_svc_set_permission(blps_env.shdl, param->sec_lvl);

        // Go to connected state
        ke_state_set(TASK_BLPS, BLPS_CONNECTED);
    }

    return (KE_MSG_CONSUMED);
}