Beispiel #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));
}
Beispiel #2
0
/**
 ****************************************************************************************
 * @brief Handles reception of the @ref PASPS_UPDATE_CHAR_VAL_REQ message.
 * @param[in] msgid Id of the message received.
 * @param[in] param Pointer to the parameters of the message.
 * @param[in] dest_id ID of the receiving task instance.
 * @param[in] src_id ID of the sending task instance.
 * @return If the message was consumed or not.
 ****************************************************************************************
 */
static int pasps_update_char_val_cmd_handler(ke_msg_id_t const msgid,
                                             struct pasps_update_char_val_cmd *param,
                                             ke_task_id_t const dest_id,
                                             ke_task_id_t const src_id)
{
    // Status
    uint8_t status = PRF_ERR_INVALID_PARAM;
    // Message status
    uint8_t msg_status = KE_MSG_CONSUMED;
    // Get the address of the environment
    struct pasps_idx_env_tag *pasps_idx_env = PRF_CLIENT_GET_ENV(dest_id, pasps_idx);


    if (pasps_idx_env != NULL)
    {
        // Check the provided connection handle value
        if (pasps_idx_env->con_info.conidx != gapc_get_conidx(param->conhdl))
        {
            status = PRF_ERR_INVALID_PARAM;
        }
        else if (ke_state_get(dest_id) == PASPS_BUSY)
        {
            // Keep the message for later
            msg_status = KE_MSG_NO_FREE;
        }
        else
        {
            // Handle
            uint16_t handle;
            // Notification status flag
            uint8_t flag;

            ASSERT_ERR(ke_state_get(dest_id) == PASPS_CONNECTED);

            switch (param->operation)
            {
                // Alert Status Characteristic
                case (PASPS_UPD_ALERT_STATUS_OP_CODE):
                {
                    // Check the provided value
                    if (param->value <= PASP_ALERT_STATUS_VAL_MAX)
                    {
                        // Set the handle value
                        handle = pasps_env.pass_shdl + PASS_IDX_ALERT_STATUS_VAL;
                        // Set the flag
                        flag   = PASPS_FLAG_ALERT_STATUS_CFG;

                        status = PRF_ERR_OK;
                    }
                    // else status is PRF_ERR_INVALID_PARAM
                } break;

                // Ringer Setting Characteristic
                case (PASPS_UPD_RINGER_SETTING_OP_CODE):
                {
                    // Check the provided value
                    if (param->value <= PASP_RINGER_NORMAL)
                    {
                        // Set the handle value
                        handle = pasps_env.pass_shdl + PASS_IDX_RINGER_SETTING_VAL;
                        // Set the flag
                        flag   = PASPS_FLAG_RINGER_SETTING_CFG;

                        status = PRF_ERR_OK;

                        // Update the ringer state value
                        pasps_env.ringer_state = param->value;
                    }
                    // else status is PRF_ERR_INVALID_PARAM
                } break;

                default:
                {
                    // Nothing more to do, status is PRF_ERR_INVALID_PARAM
                } break;
            }

            if (status == PRF_ERR_OK)
            {
                // Set the value of the characteristic
                attmdb_att_set_value(handle, sizeof(uint8_t), (uint8_t *)&param->value);

                // Check if sending of notifications is enabled for this connection
                if (PASPS_IS_NTF_ENABLED(pasps_idx_env, flag))
                {
                    // Configure the environment for the operation
                    pasps_idx_env->operation = param->operation;
                    // Go to the Busy state
                    ke_state_set(dest_id, PASPS_BUSY);

                    // The notification can be sent, send the notification
                    prf_server_send_event((prf_env_struct *)pasps_idx_env, false, handle);
                }
                else
                {
                    status = PRF_ERR_NTF_DISABLED;
                }
            }
        }

        // If the status is not OK, no notification has been sent
        if (status != PRF_ERR_OK)
        {
            // Send response to application
            pasps_send_cmp_evt(pasps_idx_env->con_info.prf_id, pasps_idx_env->con_info.appid,
                               param->conhdl,
                               param->operation, status);
        }
    }
    else
    {
        // Send response to application
        pasps_send_cmp_evt(dest_id, src_id, param->conhdl, param->operation, PRF_ERR_REQ_DISALLOWED);
    }

    return (int)msg_status;
}