Exemplo n.º 1
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);
}
Exemplo n.º 2
0
/**
 ****************************************************************************************
 * @brief Handles reception of the @ref QPPS_DATA_SEND_REQ message.
 * @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_data_send_req_handler(ke_msg_id_t const msgid,
                                      struct qpps_data_send_req const *param,
                                      ke_task_id_t const dest_id,
                                      ke_task_id_t const src_id)
{
	 if((param->conhdl == qpps_env.conhdl) &&
			(param->length <= QPP_DATA_MAX_LEN) &&
			(param->index <= qpps_env.ntf_char_num))
    {
        // Check if notifications are enabled
        if(QPPS_IS_SUPPORTED(param->index, QPPS_VALUE_NTF_CFG))
        {
            //Update value in DB
            attsdb_att_set_value(qpps_env.shdl + QPPS_IDX_VAL + param->index * 3,
                                 param->length, (void *)param->data);

            //send notification through GATT
            struct gatt_notify_req * ntf = KE_MSG_ALLOC(GATT_NOTIFY_REQ, TASK_GATT,
                                                        TASK_QPPS, gatt_notify_req);
            ntf->conhdl  = qpps_env.conhdl;
            ntf->charhdl = qpps_env.shdl + QPPS_IDX_VAL + param->index * 3;

            ke_msg_send(ntf);
        }
        //notification not enabled, simply don't send anything
        else
        {
            // Send CFM to APP that value was not sent not
            struct qpps_data_send_cfm * cfm = KE_MSG_ALLOC(QPPS_DATA_SEND_CFM, qpps_env.appid,
                    TASK_QPPS, qpps_data_send_cfm);

            cfm->conhdl = qpps_env.conhdl;
            cfm->status = PRF_ERR_NTF_DISABLED;;

            ke_msg_send(cfm);
        }
    }
    else
    {
        // Derek, Send Confirm here, not Error
        // Wrong Connection Handle
        qpps_error_ind_send(PRF_ERR_INVALID_PARAM);
    }
    return (KE_MSG_CONSUMED);
}