static int crypto_activate(struct ast_sdp_crypto *p, int suite_val, unsigned char *remote_key, struct ast_rtp_instance *rtp) { struct ast_srtp_policy *local_policy = NULL; struct ast_srtp_policy *remote_policy = NULL; struct ast_rtp_instance_stats stats = {0,}; int res = -1; if (!ast_rtp_engine_srtp_is_registered()) { return -1; } if (!p) { return -1; } if (!(local_policy = res_srtp_policy->alloc())) { return -1; } if (!(remote_policy = res_srtp_policy->alloc())) { goto err; } if (ast_rtp_instance_get_stats(rtp, &stats, AST_RTP_INSTANCE_STAT_LOCAL_SSRC)) { goto err; } if (set_crypto_policy(local_policy, suite_val, p->local_key, stats.local_ssrc, 0) < 0) { goto err; } if (set_crypto_policy(remote_policy, suite_val, remote_key, 0, 1) < 0) { goto err; } /* Add the SRTP policies */ if (ast_rtp_instance_add_srtp_policy(rtp, remote_policy, local_policy)) { ast_log(LOG_WARNING, "Could not set SRTP policies\n"); goto err; } ast_debug(1 , "SRTP policy activated\n"); res = 0; err: if (local_policy) { res_srtp_policy->destroy(local_policy); } if (remote_policy) { res_srtp_policy->destroy(remote_policy); } return res; }
static int cli_channelstats_print_body(void *obj, void *arg, int flags) { struct ast_sip_cli_context *context = arg; const struct ast_channel_snapshot *snapshot = obj; struct ast_channel *channel = ast_channel_get_by_name(snapshot->name); struct ast_sip_channel_pvt *cpvt = channel ? ast_channel_tech_pvt(channel) : NULL; struct ast_sip_session *session; struct ast_sip_session_media *media; struct ast_rtp_instance *rtp; struct ast_rtp_instance_stats stats; char *print_name = NULL; char *print_time = alloca(32); char codec_in_use[7]; ast_assert(context->output_buffer != NULL); if (!channel) { ast_str_append(&context->output_buffer, 0, " %s not valid\n", snapshot->name); return -1; } ast_channel_lock(channel); session = cpvt->session; if (!session) { ast_str_append(&context->output_buffer, 0, " %s not valid\n", snapshot->name); ast_channel_unlock(channel); ao2_cleanup(channel); return -1; } media = session->active_media_state->default_session[AST_MEDIA_TYPE_AUDIO]; if (!media || !media->rtp) { ast_str_append(&context->output_buffer, 0, " %s not valid\n", snapshot->name); ast_channel_unlock(channel); ao2_cleanup(channel); return -1; } rtp = ao2_bump(media->rtp); codec_in_use[0] = '\0'; if (ast_channel_rawreadformat(channel)) { ast_copy_string(codec_in_use, ast_format_get_name(ast_channel_rawreadformat(channel)), sizeof(codec_in_use)); } ast_channel_unlock(channel); print_name = ast_strdupa(snapshot->name); /* Skip the PJSIP/. We know what channel type it is and we need the space. */ print_name += 6; ast_format_duration_hh_mm_ss(ast_tvnow().tv_sec - snapshot->creationtime.tv_sec, print_time, 32); if (ast_rtp_instance_get_stats(rtp, &stats, AST_RTP_INSTANCE_STAT_ALL)) { ast_str_append(&context->output_buffer, 0, "%s direct media\n", snapshot->name); } else { ast_str_append(&context->output_buffer, 0, " %8.8s %-18.18s %-8.8s %-6.6s %6u%s %6u%s %3u %7.3f %6u%s %6u%s %3u %7.3f %7.3f\n", snapshot->bridgeid, print_name, print_time, codec_in_use, stats.rxcount > 100000 ? stats.rxcount / 1000 : stats.rxcount, stats.rxcount > 100000 ? "K": " ", stats.rxploss > 100000 ? stats.rxploss / 1000 : stats.rxploss, stats.rxploss > 100000 ? "K": " ", stats.rxcount ? (stats.rxploss * 100) / stats.rxcount : 0, MIN(stats.rxjitter, 999.999), stats.txcount > 100000 ? stats.txcount / 1000 : stats.txcount, stats.txcount > 100000 ? "K": " ", stats.txploss > 100000 ? stats.txploss / 1000 : stats.txploss, stats.txploss > 100000 ? "K": " ", stats.txcount ? (stats.txploss * 100) / stats.txcount : 0, MIN(stats.txjitter, 999.999), MIN(stats.normdevrtt, 999.999) ); } ao2_cleanup(rtp); ao2_cleanup(channel); return 0; }