From 96fd063ae3cb9e264fdc2bd6d669078f88567ea3 Mon Sep 17 00:00:00 2001 From: Kapil Date: Fri, 20 Jul 2012 09:58:43 -0400 Subject: [PATCH 1/2] adding add/mod/sub api and alloc context during add and release context while processing subtract code --- .../mod_media_gateway/media_gateway.c | 12 +- .../media_gateway_cmd_handler.c | 786 +++++++++++++----- .../media_gateway_packages.c | 34 +- .../mod_media_gateway/media_gateway_stack.h | 3 +- .../mod_media_gateway/mod_media_gateway.c | 18 +- 5 files changed, 615 insertions(+), 238 deletions(-) diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway.c b/src/mod/endpoints/mod_media_gateway/media_gateway.c index b596cdb819..8ed5590e54 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway.c @@ -140,6 +140,8 @@ done: switch_core_session_rwunlock(session); } switch_event_destroy(&var_event); + + return SWITCH_STATUS_SUCCESS; } mg_termination_t *megaco_choose_termination(megaco_profile_t *profile, const char *prefix) @@ -154,7 +156,7 @@ mg_termination_t *megaco_choose_termination(megaco_profile_t *profile, const cha return NULL; } - + return SWITCH_STATUS_SUCCESS; } mg_termination_t *megaco_find_termination(megaco_profile_t *profile, const char *name) @@ -210,6 +212,8 @@ switch_status_t megaco_context_add_termination(mg_context_t *ctx, mg_termination switch_ivr_uuid_bridge(ctx->terminations[0]->uuid, ctx->terminations[1]->uuid); } + + return SWITCH_STATUS_SUCCESS; } @@ -226,17 +230,19 @@ switch_status_t megaco_context_sub_termination(mg_context_t *ctx, mg_termination } megaco_termination_destroy(term); + + return SWITCH_STATUS_SUCCESS; } switch_status_t megaco_context_move_termination(mg_context_t *dst, mg_termination_t *term) { - + + return SWITCH_STATUS_SUCCESS; } mg_context_t *megaco_find_context_by_suid(SuId suId, uint32_t context_id) { - mg_context_t *result = NULL; megaco_profile_t* profile = NULL; if(NULL == (profile = megaco_get_profile_by_suId(suId))){ diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c b/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c index 7da367155a..8cc0e41268 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c @@ -29,254 +29,441 @@ const char *mg_service_change_reason[] = { * * */ -switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *inc_cmd) +switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *inc_cmd, MgMgcoContextId* new_ctxtId) { - MgMgcoContextId *ctxtId; - int descId; - MgStr errTxt; - MgMgcoInd *mgErr; - MgMgcoTermId *termId; - MgMgcoTermIdLst* termLst; - int err_code; - int i; - int j; - int fmtCnt; - MgMgcoAmmReq *cmd = &inc_cmd->u.mgCmdInd[0]->cmd.u.add; - U32 txn_id = inc_cmd->transId.val; - MgMgcoLocalDesc *local; - MgMgcoRemoteDesc *remote; - MgMgcoLclCtlDesc *locCtl; - CmSdpInfo *sdp; - MgMgcoLocalParm *lclParm; - MgMgcoTermStateDesc *tstate; - CmSdpMedFmtRtpList *fmt_list; - MgMgcoTermStateParm *tsp; - TknU8 *fmt; - CmSdpMedProtoFmts *format; + MgMgcoContextId *ctxtId; + int descId; + MgStr errTxt; + MgMgcoInd *mgErr; + MgMgcoTermId *termId; + MgMgcoTermIdLst* termLst; + int err_code; + int i; + int j; + int is_rtp = 0x00; + char rtp_term_name[32]; + int fmtCnt; + MgMgcoAmmReq *cmd = &inc_cmd->u.mgCmdInd[0]->cmd.u.add; + U32 txn_id = inc_cmd->transId.val; + MgMgcoLocalDesc *local; + MgMgcoRemoteDesc *remote; + MgMgcoLclCtlDesc *locCtl; + CmSdpInfo *sdp; + MgMgcoLocalParm *lclParm; + MgMgcoTermStateDesc *tstate; + CmSdpMedFmtRtpList *fmt_list; + MgMgcoTermStateParm *tsp; + TknU8 *fmt; + CmSdpMedProtoFmts *format; + MgMgcoMediaDesc* inc_med_desc; + MgMgcoAudRetParm *desc; + mg_context_t* mg_ctxt; - /********************************************************************/ - ctxtId = &inc_cmd->contextId; - termLst = mg_get_term_id_list(inc_cmd); - termId = termLst->terms[0]; - /* For Matt - termId->name.lcl.val - to get the termination id name */ + memset(&rtp_term_name[0], 0, 32); - /********************************************************************/ - /* Validating ADD request *******************************************/ - /*-- NULL Context & ALL Context not applicable for ADD request --*/ - if ((NOTPRSNT != ctxtId->type.pres) && - ((MGT_CXTID_ALL == ctxtId->type.val) || - (MGT_CXTID_NULL == ctxtId->type.val))) { + /********************************************************************/ + ctxtId = &inc_cmd->contextId; + termLst = mg_get_term_id_list(inc_cmd); + termId = termLst->terms[0]; + /* For Matt - termId->name.lcl.val - to get the termination id name */ - switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR," ADD Request processing failed, Context ALL/NULL not allowed\n"); + /********************************************************************/ + /* Validating ADD request *******************************************/ - mg_util_set_ctxt_string(&errTxt, ctxtId); - err_code = MGT_MGCO_RSP_CODE_PROT_ERROR; - goto error; - } + /*-- NULL Context & ALL Context not applicable for ADD request --*/ + if ((NOTPRSNT != ctxtId->type.pres) && + ((MGT_CXTID_ALL == ctxtId->type.val) || + (MGT_CXTID_NULL == ctxtId->type.val))) { - /********************************************************************/ - /* Allocate context - if context type is CHOOSE */ - if ((NOTPRSNT != ctxtId->type.pres) && - (MGT_CXTID_CHOOSE == ctxtId->type.val)){ + switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR," ADD Request processing failed, Context ALL/NULL not allowed\n"); - /* TODO - Matt */ - } + mg_util_set_ctxt_string(&errTxt, ctxtId); + err_code = MGT_MGCO_RSP_CODE_PROT_ERROR; + goto error; + } - /********************************************************************/ - /* Allocate new RTP termination - If term type is CHOOSE */ - if ((NOTPRSNT != termId->type.pres) && - (MGT_TERMID_CHOOSE == termId->type.val)){ + /********************************************************************/ + /* Allocate context - if context type is CHOOSE */ + if ((NOTPRSNT != ctxtId->type.pres) && + (MGT_CXTID_CHOOSE == ctxtId->type.val)){ - /* TODO - Matt */ - /* allocate rtp term and associated the same to context */ - /********************************************************************/ - }else{ /* Physical termination */ - /* TODO - Matt - associate physical termination to context */ - } - /********************************************************************/ + mg_ctxt = megaco_choose_context(mg_profile); - for (descId = 0; descId < cmd->dl.num.val; descId++) { - switch (cmd->dl.descs[descId]->type.val) { - case MGT_MEDIADESC: - { - int mediaId; - for (mediaId = 0; mediaId < cmd->dl.descs[descId]->u.media.num.val; mediaId++) { - MgMgcoMediaPar *mediaPar = cmd->dl.descs[descId]->u.media.parms[mediaId]; - switch (mediaPar->type.val) { - case MGT_MEDIAPAR_LOCAL: - { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "MGT_MEDIAPAR_LOCAL"); - /* Matt - check local descriptor processing */ - local = &mediaPar->u.local; - sdp = local->sdp.info[0]; - for (i = 0; i < sdp->mediaDescSet.numComp.val; i++) { - /* sdp formats */ - for (j = 0; j < - sdp->mediaDescSet.mediaDesc[i]->field.par.numProtFmts.val; j++) - { - format = sdp->mediaDescSet.mediaDesc[i]->field.par.pflst[j]; - /* Matt - format has field for T38 also */ - if ((format->protType.pres != NOTPRSNT) && - (format->protType.val == CM_SDP_MEDIA_PROTO_RTP)) { + switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO," Allocated Context[%p] with context_id[%d]\n", (void*)mg_ctxt, mg_ctxt->context_id); - /* protocol type RTP */ - fmt_list = &format->u.rtp; + /* fill Trillium Context structure with allocated context */ + MG_SET_VAL_PRES(new_ctxtId->type, MGT_CXTID_OTHER); + MG_SET_VAL_PRES(new_ctxtId->val, mg_ctxt->context_id); + } + else { + /* context already present */ + memcpy(new_ctxtId, &inc_cmd->contextId,sizeof(MgMgcoContextId)); + } - /* print format */ - for(fmtCnt = 0; fmtCnt < fmt_list->num.val; fmtCnt++){ - fmt = &fmt_list->fmts[i]->val; - if(fmt->pres == NOTPRSNT) continue; - printf("Format [%d]\n", fmt->val); - } - } - } - } + /********************************************************************/ + /* Allocate new RTP termination - If term type is CHOOSE */ + if ((NOTPRSNT != termId->type.pres) && + (MGT_TERMID_CHOOSE == termId->type.val)){ - break; - } + is_rtp = 0x01; + strcpy(rtp_term_name,"rtp/1"); - case MGT_MEDIAPAR_REMOTE: - { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "MGT_MEDIAPAR_REMOTE"); - /* Matt - check remote descriptor processing */ - remote = &mediaPar->u.remote; - sdp = remote->sdp.info[0]; - /* for Matt - same like local descriptor */ - break; - } + /* TODO - Matt */ + /* allocate rtp term and associated the same to context */ + /********************************************************************/ + }else{ /* Physical termination */ + /* TODO - Matt - associate physical termination to context */ + } + /********************************************************************/ - case MGT_MEDIAPAR_LOCCTL: - { - /* Matt - check Local Control descriptor processing */ - locCtl = &mediaPar->u.locCtl; - for (i = 0; i < locCtl->num.val; i++){ - lclParm = locCtl->parms[i]; - if (PRSNT_NODEF == lclParm->type.pres){ - switch(lclParm->type.val) - { - case MGT_LCLCTL_MODE: - { - /* Mode Property */ - printf("MGT_LCLCTL_MODE - Mode value [%d]\n", lclParm->u.mode.val); - break; - } - case MGT_LCLCTL_RESVAL: - { - /* Reserve Value */ - printf("MGT_LCLCTL_RESVAL: Reserve Value[%d] \n", lclParm->u.resVal.val); - break; - } - case MGT_LCLCTL_RESGRP: - { - /* Reserve group */ - printf("MGT_LCLCTL_RESGRP: Reserve Group[%d]\n", lclParm->u.resGrp.val); - break; - } - case MGT_LCLCTL_PROPPARM: - { - /* Properties (of a termination) */ - /* Matt - See how we can apply this to a termination */ - printf("MGT_LCLCTL_PROPPARM: \n"); - break; - } - default: - printf("Invalid local control descriptor type[%d]\n",lclParm->type.val); - break; - } - } - } + for (descId = 0; descId < cmd->dl.num.val; descId++) { + switch (cmd->dl.descs[descId]->type.val) { + case MGT_MEDIADESC: + { + int mediaId; + inc_med_desc = &cmd->dl.descs[descId]->u.media; + for (mediaId = 0; mediaId < cmd->dl.descs[descId]->u.media.num.val; mediaId++) { + MgMgcoMediaPar *mediaPar = cmd->dl.descs[descId]->u.media.parms[mediaId]; + switch (mediaPar->type.val) { + case MGT_MEDIAPAR_LOCAL: + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "MGT_MEDIAPAR_LOCAL"); + /* Matt - check local descriptor processing */ + local = &mediaPar->u.local; + sdp = local->sdp.info[0]; + for (i = 0; i < sdp->mediaDescSet.numComp.val; i++) { + /* sdp formats */ + for (j = 0; j < + sdp->mediaDescSet.mediaDesc[i]->field.par.numProtFmts.val; j++) + { + format = sdp->mediaDescSet.mediaDesc[i]->field.par.pflst[j]; + /* Matt - format has field for T38 also */ + if ((format->protType.pres != NOTPRSNT) && + (format->protType.val == CM_SDP_MEDIA_PROTO_RTP)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "MGT_MEDIAPAR_LOCCTL"); - break; - } - case MGT_MEDIAPAR_TERMST: - { - /* Matt - apply termination state descriptor */ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "MGT_MEDIAPAR_TERMST"); - tstate = &mediaPar->u.tstate; - for (i = 0; i < tstate->numComp.val; i++) - { - /* Matt to see how to apply below descriptors to a termination */ - tsp = tstate->trmStPar[i]; - if (PRSNT_NODEF == tsp->type.pres) { - switch(tsp->type.val) - { - case MGT_TERMST_PROPLST: - { - /* Matt to see how to apply properties to a termination */ - /* Properties of a termination */ - printf("MGT_TERMST_PROPLST:\n"); - break; - } - case MGT_TERMST_EVTBUFCTL: - { - /* Event /buffer Control Properties */ - printf(" MGT_TERMST_EVTBUFCTL: value[%d]\n", tsp->u.evtBufCtl.val); - break; - } - case MGT_TERMST_SVCST: - { - /* Service State Properties */ - printf(" MGT_TERMST_SVCST: value[%d]\n", tsp->u.svcState.val); - break; - } - default: - printf("Invalid termination state descriptor type[%d]\n",tsp->type.val); - break; - } - } - } - break; - } - case MGT_MEDIAPAR_STRPAR: - { - MgMgcoStreamDesc *mgStream = &mediaPar->u.stream; + /* protocol type RTP */ + fmt_list = &format->u.rtp; - if (mgStream->sl.remote.pres.pres) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Got remote stream media description:\n"); - mgco_print_sdp(&mgStream->sl.remote.sdp); - } + /* print format */ + for(fmtCnt = 0; fmtCnt < fmt_list->num.val; fmtCnt++){ + fmt = &fmt_list->fmts[i]->val; + if(fmt->pres == NOTPRSNT) continue; + printf("Format [%d]\n", fmt->val); + } + } + } + } - if (mgStream->sl.local.pres.pres) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Got local stream media description:\n"); - mgco_print_sdp(&mgStream->sl.local.sdp); - } + break; + } - break; - } - } - } - } - case MGT_MODEMDESC: - case MGT_MUXDESC: - case MGT_REQEVTDESC: - case MGT_EVBUFDESC: - case MGT_SIGNALSDESC: - case MGT_DIGMAPDESC: - case MGT_AUDITDESC: - case MGT_STATSDESC: - break; - } - } + case MGT_MEDIAPAR_REMOTE: + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "MGT_MEDIAPAR_REMOTE"); + /* Matt - check remote descriptor processing */ + remote = &mediaPar->u.remote; + sdp = remote->sdp.info[0]; + /* for Matt - same like local descriptor */ + break; + } - /* Matt - to provide the response SDP structure which needs to fill in ADD command response */ + case MGT_MEDIAPAR_LOCCTL: + { + /* Matt - check Local Control descriptor processing */ + locCtl = &mediaPar->u.locCtl; + for (i = 0; i < locCtl->num.val; i++){ + lclParm = locCtl->parms[i]; + if (PRSNT_NODEF == lclParm->type.pres){ + switch(lclParm->type.val) + { + case MGT_LCLCTL_MODE: + { + /* Mode Property */ + printf("MGT_LCLCTL_MODE - Mode value [%d]\n", lclParm->u.mode.val); + break; + } + case MGT_LCLCTL_RESVAL: + { + /* Reserve Value */ + printf("MGT_LCLCTL_RESVAL: Reserve Value[%d] \n", lclParm->u.resVal.val); + break; + } + case MGT_LCLCTL_RESGRP: + { + /* Reserve group */ + printf("MGT_LCLCTL_RESGRP: Reserve Group[%d]\n", lclParm->u.resGrp.val); + break; + } + case MGT_LCLCTL_PROPPARM: + { + /* Properties (of a termination) */ + /* Matt - See how we can apply this to a termination */ + printf("MGT_LCLCTL_PROPPARM: \n"); + break; + } + default: + printf("Invalid local control descriptor type[%d]\n",lclParm->type.val); + break; + } + } + } - /* Matt - to indicate if there is any failure while processing add message */ - - /* Kapil - to return error if there is any failure based on Matt's indication */ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "MGT_MEDIAPAR_LOCCTL"); + break; + } + case MGT_MEDIAPAR_TERMST: + { + /* Matt - apply termination state descriptor */ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "MGT_MEDIAPAR_TERMST"); + tstate = &mediaPar->u.tstate; + for (i = 0; i < tstate->numComp.val; i++) + { + /* Matt to see how to apply below descriptors to a termination */ + tsp = tstate->trmStPar[i]; + if (PRSNT_NODEF == tsp->type.pres) { + switch(tsp->type.val) + { + case MGT_TERMST_PROPLST: + { + /* Matt to see how to apply properties to a termination */ + /* Properties of a termination */ + printf("MGT_TERMST_PROPLST:\n"); + break; + } + case MGT_TERMST_EVTBUFCTL: + { + /* Event /buffer Control Properties */ + printf(" MGT_TERMST_EVTBUFCTL: value[%d]\n", tsp->u.evtBufCtl.val); + break; + } + case MGT_TERMST_SVCST: + { + /* Service State Properties */ + printf(" MGT_TERMST_SVCST: value[%d]\n", tsp->u.svcState.val); + break; + } + default: + printf("Invalid termination state descriptor type[%d]\n",tsp->type.val); + break; + } + } + } + break; + } + case MGT_MEDIAPAR_STRPAR: + { + MgMgcoStreamDesc *mgStream = &mediaPar->u.stream; - /* Kapil - to fill the response structure and call the response API to send ADD response */ - + if (mgStream->sl.remote.pres.pres) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Got remote stream media description:\n"); + mgco_print_sdp(&mgStream->sl.remote.sdp); + } - return SWITCH_STATUS_SUCCESS; + if (mgStream->sl.local.pres.pres) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Got local stream media description:\n"); + mgco_print_sdp(&mgStream->sl.local.sdp); + } + + break; + } + } + } + } + case MGT_MODEMDESC: + case MGT_MUXDESC: + case MGT_REQEVTDESC: + case MGT_EVBUFDESC: + case MGT_SIGNALSDESC: + case MGT_DIGMAPDESC: + case MGT_AUDITDESC: + case MGT_STATSDESC: + break; + } + } + + /* Matt - to provide the response SDP structure which needs to fill in ADD command response */ + + /* Matt - to indicate if there is any failure while processing add message */ + + /* Kapil - to return error if there is any failure based on Matt's indication */ + + /* Kapil - to fill the response structure and call the response API to send ADD response */ + + /*************************************************************************************************************************/ + /* sample resp code -- begin */ + { + MgMgcoCommand rsp; + int ret = 0x00; + MgMgcoTermId *out_termId; + + memset(&rsp,0, sizeof(rsp)); + + /*copy transaction-id*/ + memcpy(&rsp.transId, &inc_cmd->transId,sizeof(MgMgcoTransId)); + + /*copy context-id*/ + memcpy(&rsp.contextId, new_ctxtId,sizeof(MgMgcoContextId)); + + /*copy peer identifier */ + memcpy(&rsp.peerId, &inc_cmd->peerId,sizeof(TknU32)); + + /*fill response structue */ + if(SWITCH_STATUS_FALSE == (ret = mg_stack_alloc_mem((Ptr*)&rsp.u.mgCmdRsp[0],sizeof(MgMgcoCmdReply)))){ + return ret; + } + + rsp.u.mgCmdRsp[0]->pres.pres = PRSNT_NODEF; + rsp.u.mgCmdRsp[0]->type.pres = PRSNT_NODEF; + rsp.u.mgCmdRsp[0]->type.val = MGT_ADD; + rsp.u.mgCmdRsp[0]->u.add.pres.pres = PRSNT_NODEF; + + if(!is_rtp){ + /* IF ADD request is for Physical term then we can simply copy incoming + * termination */ + mgUtlAllocMgMgcoTermIdLst(&rsp.u.mgCmdRsp[0]->u.add.termIdLst, &inc_cmd->u.mgCmdReq[0]->cmd.u.add.termIdLst); + +#ifdef GCP_VER_2_1 + out_termId = rsp.u.mgCmdRsp[0]->u.add.termIdLst.terms[0]; +#else + out_termId = &(rsp.u.mgCmdRsp[0]->u.add.termId); +#endif + }else{ + /* ADD request is for RTP term we need to create termination */ + + /* Grow the list of reply parameters */ + if (mgUtlGrowList((void ***)&rsp.u.mgCmdRsp[0]->u.add.termIdLst.terms, sizeof(MgMgcoTermId), + &rsp.u.mgCmdRsp[0]->u.add.termIdLst.num, &rsp.u.mgCmdRsp[0]->memCp) != ROK) + { + switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,"Grow List failed\n"); + return SWITCH_STATUS_FALSE; + } + + out_termId = rsp.u.mgCmdRsp[0]->u.add.termIdLst.terms[rsp.u.mgCmdRsp[0]->u.add.termIdLst.num.val-1]; + mg_fill_mgco_termid(out_termId, (char*)rtp_term_name, strlen((char*)rtp_term_name), &rsp.u.mgCmdRsp[0]->memCp); + } + + /* Whatever Media descriptor we have received, we can copy that and then + * whatever we want we can modify the fields */ + /* Kapil - TODO - will see if there is any problem of coping the + * descriptor */ + + if (mgUtlGrowList((void ***)&rsp.u.mgCmdRsp[0]->u.add.audit.parms, sizeof(MgMgcoAudRetParm), + &rsp.u.mgCmdRsp[0]->u.add.audit.num, &rsp.u.mgCmdRsp[0]->memCp) != ROK) + { + switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,"Grow List failed\n"); + return SWITCH_STATUS_FALSE; + } + + /* copy media descriptor */ + + desc = rsp.u.mgCmdRsp[0]->u.add.audit.parms[rsp.u.mgCmdRsp[0]->u.add.audit.num.val-1]; + desc->type.pres = PRSNT_NODEF; + desc->type.val = MGT_MEDIADESC; + mgUtlCpyMgMgcoMediaDesc(&desc->u.media, inc_med_desc, &rsp.u.mgCmdRsp[0]->memCp); + +#if 0 + + /* Most probably we need to add local descriptor */ + { + MgMgcoStreamDesc *stream; + MgMgcoLocalDesc *local; + MgMgcoRemoteDesc* remote; + CmSdpInfoSet *psdp; + CmSdpInfoSet *prsdp; + char* ipAddress = "192.168.1.1"; + + /* TODO - considering only one descriptor*/ + stream = &desc->u.media.parms[0]->u.stream; + local = &stream->sl.local; + remote = &stream->sl.remote; + + if(!local->pres.pres) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, " Local stream media not present adding it \n"); + local->pres.pres = PRSNT_NODEF; + psdp = &(local->sdp); + prsdp = &(remote->sdp); + + if (mgUtlGrowList((void ***)&psdp->info, sizeof(CmSdpInfo), + &psdp->numComp, &rsp.u.mgCmdRsp[0]->memCp) != ROK) + { + switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,"Grow List failed\n"); + return SWITCH_STATUS_FALSE; + } + + psdp->info[0]->pres.pres = PRSNT_NODEF; + + /* fill version */ + memcpy(&psdp->info[0]->ver, &prsdp->info[0]->ver, sizeof(TknU16)); + + /* fill orig */ + MG_SET_VAL_PRES( (psdp->info[0]->orig.orig.sdpAddr.u.ip4.u.ip.b[0]), ipAddress[0]); + MG_SET_VAL_PRES( (psdp->info[0]->orig.orig.sdpAddr.u.ip4.u.ip.b[1]), ipAddress[1]); + MG_SET_VAL_PRES( (psdp->info[0]->orig.orig.sdpAddr.u.ip4.u.ip.b[2]), ipAddress[2]); + MG_SET_VAL_PRES( (psdp->info[0]->orig.orig.sdpAddr.u.ip4.u.ip.b[3]), ipAddress[3]); + + /* fill session name */ + memcpy(&psdp->info[0]->sessName, &prsdp->info[0]->sessName, sizeof(TknStrOSXL)); + + /* fill info */ + MG_SET_VAL_PRES( (psdp->info[0]->conn.u.ip4.u.uniIp.b[0]), ipAddress[0]); + MG_SET_VAL_PRES( (psdp->info[0]->conn.u.ip4.u.uniIp.b[1]), ipAddress[1]); + MG_SET_VAL_PRES( (psdp->info[0]->conn.u.ip4.u.uniIp.b[2]), ipAddress[2]); + MG_SET_VAL_PRES( (psdp->info[0]->conn.u.ip4.u.uniIp.b[3]), ipAddress[3]); + + /* Fill the SDP Connection Info */ + /* "c=" line - ipaddress */ + memcpy(&psdp->info[0]->conn, &prsdp->info[0]->conn, sizeof(CmSdpConn)); + + /* fill media descriptors */ + { + CmSdpMediaDescSet* med = &psdp->mediaDescSet; + CmSdpMediaDesc* m; + + if (mgUtlGrowList((void ***)&med->mediaDesc, sizeof(CmSdpMediaDesc), + &med->numComp, &rsp.u.mgCmdRsp[0]->memCp) != ROK) + { + switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,"Grow List failed\n"); + return SWITCH_STATUS_FALSE; + } + } + + m = med->mediaDesc[0]; + + m->pres.pres = PRSNT_NODEF; + } + else { + printf("!local->pres.pres false \n"); + } + } +#endif + + + + /* We will always send one command at a time..*/ + rsp.cmdStatus.pres = PRSNT_NODEF; + rsp.cmdStatus.val = CH_CMD_STATUS_END_OF_CMD; + + rsp.cmdType.pres = PRSNT_NODEF; + rsp.cmdType.val = CH_CMD_TYPE_RSP; + + ret = sng_mgco_send_cmd( mg_profile->idx, &rsp); + + return ret; + + } + /* sample resp code -- end */ + /*************************************************************************************************************************/ + + + return SWITCH_STATUS_SUCCESS; error: - if (SWITCH_STATUS_SUCCESS == - mg_build_mgco_err_request(&mgErr, txn_id, ctxtId, err_code, &errTxt)) { - sng_mgco_send_err(mg_profile->idx, mgErr); - } - mg_free_cmd(cmd); - return SWITCH_STATUS_FALSE; + if (SWITCH_STATUS_SUCCESS == + mg_build_mgco_err_request(&mgErr, txn_id, ctxtId, err_code, &errTxt)) { + sng_mgco_send_err(mg_profile->idx, mgErr); + } + mg_free_cmd(cmd); + return SWITCH_STATUS_FALSE; } /*****************************************************************************************************************************/ @@ -341,7 +528,7 @@ switch_status_t handle_mg_modify_cmd(megaco_profile_t* mg_profile, MgMgcoCommand { switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, "Modify request processing failure, CHOOSE Termination should not present in Modify\n"); - + err_code = MGT_MGCO_RSP_CODE_INVLD_IDENTIFIER; mg_util_set_term_string(&errTxt,termId); goto error; @@ -359,7 +546,11 @@ switch_status_t handle_mg_modify_cmd(megaco_profile_t* mg_profile, MgMgcoCommand /* Kapil - If there is an error - send response back to MG stack with MGT_MGCO_RSP_CODE_NO_TERM_CTXT error code*/ /********************************************************************/ - + + + /* Media Descriptor processing same as ADD command */ + + /* TODO - Will see If we can have common media_descriptor processing API which we can use for both ADD/MODIFY */ for (descId = 0; descId < cmd->dl.num.val; descId++) { switch (cmd->dl.descs[descId]->type.val) { @@ -528,11 +719,11 @@ switch_status_t handle_mg_modify_cmd(megaco_profile_t* mg_profile, MgMgcoCommand /* Matt - to provide the response SDP structure which needs to fill in Modify command response */ /* Matt - to indicate if there is any failure while processing add message */ - + /* Kapil - to return error if there is any failure based on Matt's indication */ /* Kapil - to fill the response structure and call the response API to send Modify response */ - + return SWITCH_STATUS_SUCCESS; error: @@ -544,6 +735,147 @@ error: return SWITCH_STATUS_FALSE; } +/*****************************************************************************************************************************/ + +/* +* +* Fun: handle_mg_subtract_cmd +* +* Desc: this api will handle the Subtract request received from MG stack +* +* +*/ +switch_status_t handle_mg_subtract_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *inc_cmd) +{ + MgMgcoContextId *ctxtId; + MgStr errTxt; + MgMgcoInd *mgErr; + MgMgcoTermId *termId; + MgMgcoTermIdLst* termLst; + int err_code; + MgMgcoAmmReq *cmd = &inc_cmd->u.mgCmdInd[0]->cmd.u.add; + U32 txn_id = inc_cmd->transId.val; + mg_context_t* mg_ctxt; + uint8_t wild = 0x00; + + wild = inc_cmd->u.mgCmdReq[0]->wild.pres; + + + /********************************************************************/ + ctxtId = &inc_cmd->contextId; + termLst = mg_get_term_id_list(inc_cmd); + termId = termLst->terms[0]; + + /********************************************************************/ + /* Validating Subtract request *******************************************/ + + /*-- NULL Context & CHOOSE Context not applicable for SUB request --*/ + if ((NOTPRSNT != ctxtId->type.pres) && + ((MGT_CXTID_CHOOSE == ctxtId->type.val) || + (MGT_CXTID_NULL == ctxtId->type.val))) { + + switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR," SUB Request processing failed, Context CHOOSE/NULL not allowed\n"); + + mg_util_set_ctxt_string(&errTxt, ctxtId); + err_code = MGT_MGCO_RSP_CODE_PROT_ERROR; + goto error; + } + /* ROOT Termination & CHOOSE Termination not allowed */ + else if ((NOTPRSNT != termId->type.pres) && + ((MGT_TERMID_ROOT == termId->type.val) || + (MGT_TERMID_CHOOSE == termId->type.val))) { + + switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR," SUB Request processing failed, Termination ROOT/CHOOSE not allowed\n"); + + mg_util_set_term_string(&errTxt,termId); + err_code = MGT_MGCO_RSP_CODE_INVLD_IDENTIFIER; + goto error; + } + + + /********************************************************************/ + /* Matt - TODO - check if we have terminations in the context */ + + /* Matt to indicate ERROR - If there is no terminations in requested context */ + + switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO," Received context_id[%d]\n", ctxtId->val.val); + + /*find context based on received context-id */ + mg_ctxt = megaco_get_context(mg_profile, ctxtId->val.val); + + switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO," Found Context[%p] for context_id[%d]\n", (void*)mg_ctxt, mg_ctxt->context_id); + + /* TODO - remove terminations from context....as if now there is no termination associated with Context */ + + /* release context*/ + megaco_release_context(mg_ctxt); + + /*************************************************************************************************************************/ + /* resp code -- begin */ + { + MgMgcoCommand rsp; + int ret = 0x00; + MgMgcoTermId *out_termId; + + memset(&rsp,0, sizeof(rsp)); + + /*copy transaction-id*/ + memcpy(&rsp.transId, &inc_cmd->transId, sizeof(MgMgcoTransId)); + + /*copy context-id*/ + memcpy(&rsp.contextId, &inc_cmd->contextId, sizeof(MgMgcoContextId)); + + /*copy peer identifier */ + memcpy(&rsp.peerId, &inc_cmd->peerId,sizeof(TknU32)); + + /*fill response structue */ + if(SWITCH_STATUS_FALSE == (ret = mg_stack_alloc_mem((Ptr*)&rsp.u.mgCmdRsp[0],sizeof(MgMgcoCmdReply)))){ + return ret; + } + + rsp.u.mgCmdRsp[0]->pres.pres = PRSNT_NODEF; + rsp.u.mgCmdRsp[0]->type.pres = PRSNT_NODEF; + rsp.u.mgCmdRsp[0]->type.val = MGT_SUB; + rsp.u.mgCmdRsp[0]->u.sub.pres.pres = PRSNT_NODEF; + + if(wild){ + rsp.u.mgCmdRsp[0]->wild.pres = PRSNT_NODEF; + } + + mgUtlAllocMgMgcoTermIdLst(&rsp.u.mgCmdRsp[0]->u.add.termIdLst, &inc_cmd->u.mgCmdReq[0]->cmd.u.add.termIdLst); + +#ifdef GCP_VER_2_1 + out_termId = rsp.u.mgCmdRsp[0]->u.add.termIdLst.terms[0]; +#else + out_termId = &(rsp.u.mgCmdRsp[0]->u.add.termId); +#endif + + /* We will always send one command at a time..*/ + rsp.cmdStatus.pres = PRSNT_NODEF; + rsp.cmdStatus.val = CH_CMD_STATUS_END_OF_CMD; + + rsp.cmdType.pres = PRSNT_NODEF; + rsp.cmdType.val = CH_CMD_TYPE_RSP; + + ret = sng_mgco_send_cmd( mg_profile->idx, &rsp); + + return ret; + + } + /* sample resp code -- end */ + /*************************************************************************************************************************/ + + + return SWITCH_STATUS_SUCCESS; +error: + if (SWITCH_STATUS_SUCCESS == + mg_build_mgco_err_request(&mgErr, txn_id, ctxtId, err_code, &errTxt)) { + sng_mgco_send_err(mg_profile->idx, mgErr); + } + mg_free_cmd(cmd); + return SWITCH_STATUS_FALSE; +} + /*****************************************************************************************************************************/ /* * diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_packages.c b/src/mod/endpoints/mod_media_gateway/media_gateway_packages.c index 19c1b1dae7..0c6f17b0df 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_packages.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_packages.c @@ -47,10 +47,11 @@ MgPackage_t mg_pkg_list [] = 1, /* Version 1 */ "tdmc", /* Package name */ }, + /* TODO - not sure IF we need this */ { /* INDEX : 7 */ - MGT_PKG_QTY_ALT, /*55*/ + MGT_PKG_SEGMENTATION, 1, /* Version 1 */ - "qac", /* Package name */ + "seg", /* Package name */ }, { /* INDEX : 8 */ MGT_PKG_EN_ALERT, /*59*/ @@ -58,9 +59,9 @@ MgPackage_t mg_pkg_list [] = "alert", /* Package name */ }, { /* INDEX : 9 */ - MGT_PKG_AN_DISP, /*60*/ + MGT_PKG_CONTINUITY, /*60*/ 2, /* Version 1 */ - "andisp", /* Package name */ + "ct", /* Package name */ }, { /* INDEX : 10 */ MGT_PKG_INACTTIMER, /*69*/ @@ -97,6 +98,31 @@ MgPackage_t mg_pkg_list [] = 1, /* Version 1 */ "etsi_nr", /* Package name */ }, + { /* INDEX : 17 */ + MGT_PKG_TONEGEN, + 1, /* Version 1 */ + "tonegen", /* Package name */ + }, + { /* INDEX : 18 */ + MGT_PKG_DTMFGEN, + 1, /* Version 1 */ + "tonegen", /* Package name */ + }, + { /* INDEX : 19 */ + MGT_PKG_CALLPROGGEN, + 1, /* Version 1 */ + "tonegen", /* Package name */ + }, + { /* INDEX : 20 */ + MGT_PKG_CALLPROGDET, + 1, /* Version 1 */ + "tonedet", /* Package name */ + }, + { /* INDEX : 21 */ + MGT_PKG_ANALOG, + 1, /* Version 1 */ + "analog", /* Package name */ + }, /* Add more packages */ }; diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_stack.h b/src/mod/endpoints/mod_media_gateway/media_gateway_stack.h index d06fd727a1..b207f2e75a 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_stack.h +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_stack.h @@ -133,7 +133,8 @@ int sng_mgco_mg_get_status(int elemId, MgMngmt* cfm, megaco_profile_t* mg_cfg, m switch_status_t mg_send_end_of_axn(SuId suId, MgMgcoTransId* transId, MgMgcoContextId* ctxtId, TknU32* peerId); void mgco_print_sdp(CmSdpInfoSet *sdp); void mg_util_set_ctxt_string ( MgStr *errTxt, MgMgcoContextId *ctxtId); -switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *cmd); +switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *inc_cmd, MgMgcoContextId* new_ctxtId); +switch_status_t handle_mg_subtract_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *inc_cmd); switch_status_t handle_mg_modify_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *cmd); switch_status_t mg_stack_free_mem(void* msg); switch_status_t mg_stack_alloc_mem( Ptr* _memPtr, Size _memSize ); diff --git a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.c b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.c index 4336b90982..cbdf144a6a 100644 --- a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.c +++ b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.c @@ -424,6 +424,7 @@ void handle_mgco_txn_ind(Pst *pst, SuId suId, MgMgcoMsg* msg) /*****************************************************************************************************************************/ void handle_mgco_cmd_ind(Pst *pst, SuId suId, MgMgcoCommand* cmd) { + MgMgcoContextId out_ctxt; U32 txn_id = 0x00; MgMgcoInd *mgErr; MgStr errTxt; @@ -435,6 +436,8 @@ void handle_mgco_cmd_ind(Pst *pst, SuId suId, MgMgcoCommand* cmd) int err_code; megaco_profile_t* mg_profile; + memset(&out_ctxt,0,sizeof(out_ctxt)); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%s: Received Command Type[%s] \n", __PRETTY_FUNCTION__, PRNT_MG_CMD_TYPE(cmd->cmdType.val)); /* validate Transaction Id */ @@ -532,6 +535,8 @@ void handle_mgco_cmd_ind(Pst *pst, SuId suId, MgMgcoCommand* cmd) goto error1; } + memcpy(&out_ctxt, inc_context,sizeof(MgMgcoContextId)); + switch(cmd->cmdType.val) { case CH_CMD_TYPE_IND: @@ -543,8 +548,8 @@ void handle_mgco_cmd_ind(Pst *pst, SuId suId, MgMgcoCommand* cmd) { case MGT_ADD: { - handle_mg_add_cmd(mg_profile, cmd); - mg_send_add_rsp(suId, cmd); + handle_mg_add_cmd(mg_profile, cmd, &out_ctxt); + /*mg_send_add_rsp(suId, cmd);*/ break; } @@ -565,7 +570,8 @@ void handle_mgco_cmd_ind(Pst *pst, SuId suId, MgMgcoCommand* cmd) case MGT_SUB: { /*MgMgcoSubAudReq *addReq = &cmdReq->cmd.u.sub;*/ - mg_send_subtract_rsp(suId, cmd); + handle_mg_subtract_cmd(mg_profile, cmd); + /*mg_send_subtract_rsp(suId, cmd);*/ break; } case MGT_SVCCHG: @@ -613,6 +619,12 @@ void handle_mgco_cmd_ind(Pst *pst, SuId suId, MgMgcoCommand* cmd) return; } + /* END OF TXN received - means last command in txn to process. + * Send response to peer */ + if(CH_CMD_STATUS_END_OF_TXN == cmd->cmdStatus.val){ + mg_send_end_of_axn(suId, &cmd->transId, &out_ctxt, &cmd->peerId); + } + return; ctxt_error: From fffc9d4eec85964a6fa1c439b5322bc99ef0ec15 Mon Sep 17 00:00:00 2001 From: Kapil Date: Fri, 20 Jul 2012 13:25:16 -0400 Subject: [PATCH 2/2] Adding code to print SDP structure --- .../mod_media_gateway/media_gateway_utils.c | 673 +++++++++++++++++- 1 file changed, 637 insertions(+), 36 deletions(-) diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_utils.c b/src/mod/endpoints/mod_media_gateway/media_gateway_utils.c index e536fd83bf..b4728a2bc0 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_utils.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_utils.c @@ -410,55 +410,656 @@ void mg_util_set_cmd_name_string (MgStr *errTxt, MgMgcoCommand *cmd) } /*****************************************************************************************************************************/ +void mgco_print_sdp_attr_set(CmSdpAttrSet *s) +{ + int i=0x00; + if (s->numComp.pres) { + for (i = 0; i < s->numComp.val; i++) { + CmSdpAttr *a = s->attr[i]; + + if(NOTPRSNT == a->type.pres) continue; + + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Attribute Type[%d]\n",a->type.val); + + switch(a->type.val) + { + case CM_SDP_ATTR_GENERIC: + { + break; + } + case CM_SDP_ATTR_CAT: + { + break; + } + + case CM_SDP_ATTR_KEYWDS: + { + break; + } + case CM_SDP_ATTR_TOOL: + { + break; + } + case CM_SDP_ATTR_PTIME: + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t PTIME = %d \n", + (NOTPRSNT != a->u.ptime.pres)?a->u.ptime.val:-1); + break; + } + case CM_SDP_ATTR_RECVONLY: + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t CM_SDP_ATTR_RECVONLY: \n"); + break; + } + case CM_SDP_ATTR_SENDRECV: + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t CM_SDP_ATTR_SENDRECV: \n"); + break; + } + case CM_SDP_ATTR_SENDONLY: + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t CM_SDP_ATTR_SENDONLY: \n"); + break; + } + case CM_SDP_ATTR_ORIENT: + { + break; + } + case CM_SDP_ATTR_TYPE: + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t CM_SDP_ATTR_TYPE: \n"); + break; + } + case CM_SDP_ATTR_CHARSET: + { + break; + } + + case CM_SDP_ATTR_SDPLANG: + { + break; + } + + case CM_SDP_ATTR_LANG: + { + break; + } + case CM_SDP_ATTR_FRAMERATE: + { + break; + } + case CM_SDP_ATTR_QUALITY: + { + break; + } + case CM_SDP_ATTR_FMTP: + { + CmSdpAttrFmtp* f = &a->u.fmtp; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t CM_SDP_ATTR_FMTP: \n"); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Format Type = %d \n",(NOTPRSNT == f->type.pres)?f->type.val:-1); + + break; + } + case CM_SDP_ATTR_RTPMAP: + { + CmSdpAttrRtpMap* r = &a->u.rtpmap; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t CM_SDP_ATTR_RTPMAP: \n"); + + if(NOTPRSNT != r->pres.pres){ + + /* payload type */ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Payload Type = %d \n", + (NOTPRSNT != r->pay.type.pres)?r->pay.type.val:-1); + + /* payload value */ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Payload Value = %d \n", + (NOTPRSNT != r->pay.val.pres)?r->pay.val.val:-1); + + /* encoding name */ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Encoding Name value = %d \n", + (NOTPRSNT != r->enc.val.pres)?r->enc.val.val:-1); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Encoding Name name = %s \n", + (NOTPRSNT != r->enc.name.pres)?(char*)r->enc.name.val:"Not Present"); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Clock Rate = %d \n", + (NOTPRSNT != r->clk.pres)?r->clk.val:-1); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Encoding Parameters = %s \n", + (NOTPRSNT != r->parms.pres)?(char*)r->parms.val:"Not Present"); + } + break; + } + case CM_SDP_ATTR_INACTIVE: + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t CM_SDP_ATTR_INACTIVE: \n"); + break; + } + case CM_SDP_ATTR_CONTROL: + { + break; + } + case CM_SDP_ATTR_RANGE: + { + break; + } + case CM_SDP_ATTR_ETAG: + { + break; + } + case CM_SDP_ATTR_ATMMAP: + { + break; + } + case CM_SDP_ATTR_EECID: + { + break; + } + case CM_SDP_ATTR_AALTYPE: + { + break; + } + case CM_SDP_ATTR_SILENCESUPP: + { + break; + } + case CM_SDP_ATTR_ECAN: + { + break; + } + case CM_SDP_ATTR_GC: + { + break; + } + case CM_SDP_ATTR_PROFILEDESC: + { + break; + } + case CM_SDP_ATTR_VSEL: + { + break; + } + case CM_SDP_ATTR_DSEL: + { + break; + } + case CM_SDP_ATTR_FSEL: + { + break; + } + case CM_SDP_ATTR_CAPABILITY: + { + break; + } + case CM_SDP_ATTR_QOSCLASS: + { + break; + } + case CM_SDP_ATTR_BCOB: + { + break; + } + case CM_SDP_ATTR_STC: + { + break; + } + case CM_SDP_ATTR_UPCC: + { + break; + } + case CM_SDP_ATTR_ATMQOSPARMS: + { + break; + } + case CM_SDP_ATTR_AAL2QOSFPARMS: + { + break; + } + case CM_SDP_ATTR_AAL2QOSBPARMS: + { + break; + } + case CM_SDP_ATTR_ATMTRFCDESC: + { + break; + } + case CM_SDP_ATTR_AAL2FTRFCDESC: + { + break; + } + case CM_SDP_ATTR_AAL2BTRFCDESC: + { + break; + } + case CM_SDP_ATTR_ABRPARMS: + { + break; + } + case CM_SDP_ATTR_CLKREC: + { + break; + } + case CM_SDP_ATTR_FEC: + { + break; + } + case CM_SDP_ATTR_PRTFL: + { + break; + } + case CM_SDP_ATTR_BEARERTYPE: + { + break; + } + case CM_SDP_ATTR_STRUCTURE: + { + break; + } + case CM_SDP_ATTR_SBC: + { + break; + } + case CM_SDP_ATTR_CPSSDUSIZE: + { + break; + } + case CM_SDP_ATTR_AAL2CPS: + { + break; + } + case CM_SDP_ATTR_ANYCAST: + { + break; + } + case CM_SDP_ATTR_WTP: + { + break; + } + case CM_SDP_ATTR_CACHE: + { + break; + } + case CM_SDP_ATTR_CHAIN: + { + break; + } + case CM_SDP_ATTR_PHONECONTEXT: + { + break; + } + case CM_SDP_ATTR_CLIR: + { + break; + } + case CM_SDP_ATTR_DIRECTION: + { + break; + } + case CM_SDP_ATTR_MAXPTIME: + { + break; + } + case CM_SDP_ATTR_T38_FAX: + { + break; + } + default: + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Not supported Type[%d]\n",a->type.val); + break; + } + } + }else{ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "a-line not present \n"); + } + + +} + +void mgco_print_sdp_c_line(CmSdpConn *s) +{ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "********** SDP connection line ****** \n"); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Net Type = %d \n", + (NOTPRSNT != s->netType.type.pres)?s->netType.type.val:-1); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Address Type = %d \n", + (NOTPRSNT != s->addrType.pres)?s->addrType.val:-1); + + if (s->addrType.pres && s->addrType.val == CM_SDP_ADDR_TYPE_IPV4 && + s->netType.type.val == CM_SDP_NET_TYPE_IN && + s->u.ip4.addrType.val == CM_SDP_IPV4_IP_UNI) { + + if (s->u.ip4.addrType.pres) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Address: %d.%d.%d.%d\n", + s->u.ip4.u.uniIp.b[0].val, + s->u.ip4.u.uniIp.b[1].val, + s->u.ip4.u.uniIp.b[2].val, + s->u.ip4.u.uniIp.b[3].val); + } + } + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "**************** \n"); +} + +void mgco_print_CmSdpU8OrNil(CmSdpU8OrNil* p) +{ + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE,"CmSdpU8OrNil: Type = %d \n", (NOTPRSNT != p->type.pres)?p->type.val:-1); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE,"CmSdpU8OrNil: Value = %d \n", (NOTPRSNT != p->val.pres)?p->val.val:-1); +} + +void mgco_print_sdp_media_param(CmSdpMedPar *s) +{ + int i=0x00; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "***** Media Parameter *********** \n"); + if (s->numProtFmts.pres) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Media Formats = %d \n", s->numProtFmts.val); + for (i = 0; i < s->numProtFmts.val; i++) { + CmSdpMedProtoFmts *a = s->pflst[i]; + + /*Prot*/ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, " Proto Type = %d \n", (NOTPRSNT != a->prot.type.pres)?a->prot.type.val:-1); + switch(a->prot.type.val) + { + case CM_SDP_MEDIA_PROTO_UNKNOWN: + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, " Proto Type Unknown , name = %s \n", + (NOTPRSNT != a->prot.u.name.pres)?(char*)a->prot.u.name.val:"Not Present "); + break; + } + case CM_SDP_MEDIA_PROTO_RTP: + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, " Proto Type RTP , subtype = %d \n", + (NOTPRSNT != a->prot.u.subtype.type.pres)?a->prot.u.subtype.type.val: -1); + break; + } + } + + /*repeated from "prot" field */ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, " Proto Type = %d \n", + (NOTPRSNT != a->protType.pres)?a->protType.val: -1); + + switch(a->protType.val) + { + case CM_SDP_MEDIA_PROTO_RTP: + { + CmSdpMedFmtRtpList* r = &a->u.rtp; + int i = 0x00; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, " CM_SDP_MEDIA_PROTO_RTP: \n"); + if(NOTPRSNT != r->num.pres){ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, " Number of Formats[%d] \n", r->num.val); + + for(i=0;inum.val;i++){ + mgco_print_CmSdpU8OrNil(r->fmts[i]); + } + } + break; + } + + case CM_SDP_UDPTL_FMT_T38: + { + /*CmSdpMedFmtUdptlList* t = &a->u.t38;*/ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, " CM_SDP_UDPTL_FMT_T38: \n"); + break; + } + default: + break; + } + } + } + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "**************** \n"); +} + void mgco_print_sdp(CmSdpInfoSet *sdp) { - int i; + int i; - if (sdp->numComp.pres == NOTPRSNT) { - return; - } + if (sdp->numComp.pres == NOTPRSNT) { + return; + } - for (i = 0; i < sdp->numComp.val; i++) { - CmSdpInfo *s = sdp->info[i]; - int mediaId; + for (i = 0; i < sdp->numComp.val; i++) { + CmSdpInfo *s = sdp->info[i]; + int mediaId; - if (s->conn.addrType.pres && s->conn.addrType.val == CM_SDP_ADDR_TYPE_IPV4 && - s->conn.netType.type.val == CM_SDP_NET_TYPE_IN && - s->conn.u.ip4.addrType.val == CM_SDP_IPV4_IP_UNI) { + /************************************************************************************************************************/ + /* info presence check */ + if(NOTPRSNT == s->pres.pres) continue; - if (s->conn.u.ip4.addrType.pres) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Address: %d.%d.%d.%d\n", - s->conn.u.ip4.u.uniIp.b[0].val, - s->conn.u.ip4.u.uniIp.b[1].val, - s->conn.u.ip4.u.uniIp.b[2].val, - s->conn.u.ip4.u.uniIp.b[3].val); - } - if (s->attrSet.numComp.pres) { - for (mediaId = 0; mediaId < s->attrSet.numComp.val; mediaId++) { - /*CmSdpAttr *a = s->attrSet.attr[mediaId];*/ + /************************************************************************************************************************/ + /* Version */ + if(NOTPRSNT != s->ver.pres) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, " SDP Version = %d \n", s->ver.val); + } + + /************************************************************************************************************************/ + /* Orig */ + if(NOTPRSNT != s->orig.pres.pres) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "********** SDP orig line ****** \n \t Type = %d \n", s->orig.type.val); + + if(NOTPRSNT != s->orig.orig.pres.pres) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t User Name = %s \n", + (NOTPRSNT != s->orig.orig.usrName.pres)?(char*)s->orig.orig.usrName.val:"Not Present"); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Session Id = %s \n", + (NOTPRSNT != s->orig.orig.sessId.pres)?(char*)s->orig.orig.sessId.val:"Not Present"); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Session Version = %s \n", + (NOTPRSNT != s->orig.orig.sessVer.pres)?(char*)s->orig.orig.sessVer.val:"Not Present"); + + /* sdpAddr */ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Net Type = %d \n", + (NOTPRSNT != s->orig.orig.sdpAddr.netType.type.pres)?s->orig.orig.sdpAddr.netType.type.val:-1); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Address Type = %d \n", + (NOTPRSNT != s->orig.orig.sdpAddr.addrType.pres)?s->orig.orig.sdpAddr.addrType.val:-1); + + /* print IPV4 address */ + if (s->orig.orig.sdpAddr.addrType.pres && s->orig.orig.sdpAddr.addrType.val == CM_SDP_ADDR_TYPE_IPV4 && + s->orig.orig.sdpAddr.netType.type.val == CM_SDP_NET_TYPE_IN && + s->orig.orig.sdpAddr.u.ip4.addrType.val == CM_SDP_IPV4_IP_UNI) { + + if (s->orig.orig.sdpAddr.u.ip4.addrType.pres) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Address: %d.%d.%d.%d\n", + s->orig.orig.sdpAddr.u.ip4.u.ip.b[0].val, + s->orig.orig.sdpAddr.u.ip4.u.ip.b[1].val, + s->orig.orig.sdpAddr.u.ip4.u.ip.b[2].val, + s->orig.orig.sdpAddr.u.ip4.u.ip.b[3].val); + } + + }else{ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t O-line not present \n"); + } + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "********** ****** \n"); + } + } else{ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t O-line not present \n"); + } + /************************************************************************************************************************/ + /* Session Name (s = line) */ + + if(NOTPRSNT != s->sessName.pres) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Session Name = %s \n", s->sessName.val); + } else{ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t s-line not present \n"); + } + + /************************************************************************************************************************/ + /* Session Info(i= line) */ + + if(NOTPRSNT != s->info.pres) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Session Info = %s \n", s->info.val); + } else{ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t i-line not present \n"); + } + + /************************************************************************************************************************/ + /* Session Uri */ + + if(NOTPRSNT != s->uri.pres) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Session Uri = %s \n", s->uri.val); + } else{ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t uri not present \n"); + } + + /************************************************************************************************************************/ + /* E-Mail */ + /* TODO */ - } - } + /************************************************************************************************************************/ + /* Phone */ + /* TODO */ - if (s->mediaDescSet.numComp.pres) { - for (mediaId = 0; mediaId < s->mediaDescSet.numComp.val; mediaId++) { - CmSdpMediaDesc *desc = s->mediaDescSet.mediaDesc[mediaId]; - if (desc->field.mediaType.val == CM_SDP_MEDIA_AUDIO && - desc->field.id.type.val == CM_SDP_VCID_PORT && - desc->field.id.u.port.type.val == CM_SDP_PORT_INT && - desc->field.id.u.port.u.portInt.port.type.val == CM_SDP_SPEC) { - int port = desc->field.id.u.port.u.portInt.port.val.val; + /************************************************************************************************************************/ + /* connection line */ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Port: %d\n", port); + mgco_print_sdp_c_line(&s->conn); + /************************************************************************************************************************/ + /* Bandwidth */ + /* TODO */ - } - } - } - } - } + /************************************************************************************************************************/ + /* SDP Time (t= line)*/ + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "*** t-line **************** \n"); + if(NOTPRSNT != s->sdpTime.pres.pres) { + if(NOTPRSNT != s->sdpTime.sdpOpTimeSet.numComp.pres) { + int i = 0x00; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "SDP op time present with total component[%d]\n", s->sdpTime.sdpOpTimeSet.numComp.val); + for (i = 0;isdpTime.sdpOpTimeSet.numComp.val;i++){ + CmSdpOpTime* t = s->sdpTime.sdpOpTimeSet.sdpOpTime[i]; + if(NOTPRSNT == t->pres.pres) continue; + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Start Time = %s \n", + (NOTPRSNT != t->startTime.pres)?(char*)t->startTime.val:"Not Present"); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Stop Time = %s \n", + (NOTPRSNT != t->stopTime.pres)?(char*)t->stopTime.val:"Not Present"); + + /*repeat time repFieldSet */ + + if(NOTPRSNT != t->repFieldSet.numComp.pres) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "SDP repeat time present with total component[%d]\n", + t->repFieldSet.numComp.val); + + /*TODO - print repeat fields */ + }else{ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "SDP repeat time not present \n"); + } + } /* sdpOpTimeSet.numComp for loop -- end */ + }else{/*sdpOpTimeSet.numComp.pres if -- end */ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "SDP op time not present \n"); + } + + /*TODO - zoneAdjSet */ + }else{ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "t-line not present \n"); + } + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "**************** \n"); + + + /************************************************************************************************************************/ + /* key type (k= line)*/ + + if(NOTPRSNT != s->keyType.pres.pres) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Key Type = %d \n", + (NOTPRSNT != s->keyType.keyType.pres)?s->keyType.keyType.val:-1); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Key Data = %s \n", + (NOTPRSNT != s->keyType.key_data.pres)?(char*)s->keyType.key_data.val:"Not Present"); + }else{ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "k-line not present \n"); + } + + /************************************************************************************************************************/ + /* Attribute Set */ + + mgco_print_sdp_attr_set(&s->attrSet); + + /************************************************************************************************************************/ + /* Media Descriptor Set */ + + if (s->mediaDescSet.numComp.pres) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "****** Media Descriptor Set present with numComp[%d]\n", s->mediaDescSet.numComp.val); + for (mediaId = 0; mediaId < s->mediaDescSet.numComp.val; mediaId++) { + CmSdpMediaDesc *desc = s->mediaDescSet.mediaDesc[mediaId]; + + if(NOTPRSNT == desc->pres.pres) continue; + + /* Media Field */ + { + CmSdpMediaField* f = &desc->field; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Media Type = %d \n",(NOTPRSNT == f->mediaType.pres)?f->mediaType.val:-1); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Media = %s \n",(NOTPRSNT == f->media.pres)?(char*)f->media.val:"Not Present"); + /* Channel ID */ + if(NOTPRSNT != f->id.type.pres){ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t VcId Type = %d \n", f->id.type.val); + switch(f->id.type.val){ + case CM_SDP_VCID_PORT: + { + CmSdpPort *p = &f->id.u.port; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "CM_SDP_VCID_PORT:\n"); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t SDP port type = %d \n", (NOTPRSNT == p->type.pres)?p->type.val:-1); + switch(p->type.val) + { + case CM_SDP_PORT_INT: + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t CM_SDP_PORT_INT: SDP port = %d type = %d \n", p->u.portInt.port.val.val, p->u.portInt.port.type.val); + break; + } + case CM_SDP_PORT_VPCID: + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t CM_SDP_PORT_VPCID: \n"); + break; + } + default: + break; + } + break; + } + default: + break; + } + } + mgco_print_sdp_media_param(&f->par); + } + + /*info */ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Info = %s \n",(NOTPRSNT == desc->info.pres)?(char*)desc->info.val:"Not Present"); + + /*connection set */ + { + int cnt=0x00; + if(NOTPRSNT != desc->connSet.numComp.pres){ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Number of Connection component[%d]\n",desc->connSet.numComp.val); + for(cnt=0;cntconnSet.numComp.val;cnt++){ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "************************\n"); + mgco_print_sdp_c_line(desc->connSet.connSet[cnt]); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "************************\n"); + } + } + } + + /* attribute set */ + mgco_print_sdp_attr_set(&desc->attrSet); + + + if (desc->field.mediaType.val == CM_SDP_MEDIA_AUDIO && + desc->field.id.type.val == CM_SDP_VCID_PORT && + desc->field.id.u.port.type.val == CM_SDP_PORT_INT && + desc->field.id.u.port.u.portInt.port.type.val == CM_SDP_SPEC) { + int port = desc->field.id.u.port.u.portInt.port.val.val; + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Port: %d\n", port); + + } + } + } + } } /*****************************************************************************************************************************/