fix conflict

This commit is contained in:
Mathieu Rene 2012-07-03 12:28:13 -04:00
commit 1d5f9f9f88
8 changed files with 1407 additions and 47 deletions

View File

@ -7,7 +7,9 @@ applications/mod_hash
applications/mod_spandsp
dialplans/mod_dialplan_xml
endpoints/mod_sofia
#endpoints/mod_media_gateway
../../libs/freetdm/mod_freetdm
xml_int/mod_xml_cdr
event_handlers/mod_event_socket
codecs/mod_sangoma_codec
event_handlers/mod_radius_cdr

View File

@ -7,6 +7,6 @@ ifeq ($(ARCH),x86_64)
endif
BASE=../../../..
LOCAL_OBJS=media_gateway.o media_gateway_stack.o media_gateway_xml.o media_gateway_cli.o media_gateway_stack_alarms.o
LOCAL_OBJS=media_gateway.o media_gateway_stack.o media_gateway_xml.o media_gateway_cli.o media_gateway_stack_alarms.o media_gateway_cmd_handler.o media_gateway_utils.o media_gateway_packages.o
LOCAL_LDFLAGS=-lsng_mg
include $(BASE)/build/modmake.rules

View File

@ -0,0 +1,708 @@
/*
* Copyright (c) 2012, Sangoma Technologies
* Mathieu Rene <mrene@avgs.ca>
* All rights reserved.
*
* <Insert license here>
*/
#include "mod_media_gateway.h"
#include "media_gateway_stack.h"
/*****************************************************************************************************************************/
/*
*
* Fun: handle_mg_add_cmd
*
* Desc: this api will handle the ADD request received from MG stack
*
*
*/
switch_status_t handle_mg_add_cmd(MgMgcoAmmReq *addReq)
{
int descId;
for (descId = 0; descId < addReq->dl.num.val; descId++) {
switch (addReq->dl.descs[descId]->type.val) {
case MGT_MEDIADESC:
{
int mediaId;
for (mediaId = 0; mediaId < addReq->dl.descs[descId]->u.media.num.val; mediaId++) {
MgMgcoMediaPar *mediaPar = addReq->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");
break;
}
case MGT_MEDIAPAR_REMOTE:
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "MGT_MEDIAPAR_REMOTE");
break;
}
case MGT_MEDIAPAR_LOCCTL:
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "MGT_MEDIAPAR_LOCCTL");
break;
}
case MGT_MEDIAPAR_TERMST:
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "MGT_MEDIAPAR_TERMST");
break;
}
case MGT_MEDIAPAR_STRPAR:
{
MgMgcoStreamDesc *mgStream = &mediaPar->u.stream;
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);
}
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;
}
}
return SWITCH_STATUS_SUCCESS;
}
/*****************************************************************************************************************************/
/*
*
* Fun: mg_send_add_rsp
*
* Desc: this api will send the ADD response based on ADD request received from MG stack
*
* TODO - Dummy response , needs to have proper ADD response code
*/
switch_status_t mg_send_add_rsp(SuId suId, MgMgcoCommand *req)
{
MgMgcoCommand cmd;
int ret = 0x00;
MgMgcoTermId *termId;
memset(&cmd,0, sizeof(cmd));
/*copy transaction-id*/
memcpy(&cmd.transId, &req->transId,sizeof(MgMgcoTransId));
/*copy context-id*/ /*TODO - in case of $ context should be generated by app, we should not simply copy incoming structure */
memcpy(&cmd.contextId, &req->contextId,sizeof(MgMgcoContextId));
/*copy peer identifier */
memcpy(&cmd.peerId, &req->peerId,sizeof(TknU32));
/*fill response structue */
if(SWITCH_STATUS_FALSE == (ret = mg_stack_alloc_mem((Ptr*)&cmd.u.mgCmdRsp[0],sizeof(MgMgcoCmdReply)))){
return ret;
}
cmd.u.mgCmdRsp[0]->pres.pres = PRSNT_NODEF;
cmd.u.mgCmdRsp[0]->type.pres = PRSNT_NODEF;
cmd.u.mgCmdRsp[0]->type.val = MGT_ADD;
cmd.u.mgCmdRsp[0]->u.add.pres.pres = PRSNT_NODEF;
cmd.u.mgCmdRsp[0]->u.add.termIdLst.num.pres = PRSNT_NODEF;
cmd.u.mgCmdRsp[0]->u.add.termIdLst.num.val = 1;
mgUtlAllocMgMgcoTermIdLst(&cmd.u.mgCmdRsp[0]->u.add.termIdLst, &req->u.mgCmdReq[0]->cmd.u.add.termIdLst);
#ifdef GCP_VER_2_1
termId = cmd.u.mgCmdRsp[0]->u.add.termIdLst.terms[0];
#else
termId = &(cmd.u.mgCmdRsp[0]->u.add.termId);
#endif
mg_fill_mgco_termid(termId, (CONSTANT U8*)"term1",&req->u.mgCmdRsp[0]->memCp);
/* We will always send one command at a time..*/
cmd.cmdStatus.pres = PRSNT_NODEF;
cmd.cmdStatus.val = CH_CMD_STATUS_END_OF_CMD;
cmd.cmdType.pres = PRSNT_NODEF;
cmd.cmdType.val = CH_CMD_TYPE_RSP;
ret = sng_mgco_send_cmd(suId, &cmd);
return ret;
}
/*****************************************************************************************************************************/
/*
*
* Fun: mg_send_end_of_axn
*
* Desc: this api will send the END_OF_AXN event to MG stack to indicate that application is done with processing
*
*
*/
switch_status_t mg_send_end_of_axn(SuId suId, MgMgcoTransId* transId, MgMgcoContextId* ctxtId, TknU32* peerId)
{
int ret = 0x00;
MgMgcoCtxt ctxt;
memset(&ctxt,0, sizeof(ctxt));
memcpy(&ctxt.transId,transId,sizeof(MgMgcoTransId));
memcpy(&ctxt.cntxtId, ctxtId,sizeof(MgMgcoContextId));
memcpy(&ctxt.peerId, peerId,sizeof(TknU32));
ctxt.cmdStatus.pres = PRSNT_NODEF;
ctxt.cmdStatus.val = CH_CMD_STATUS_END_OF_AXN;
#ifdef BIT_64
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,
"mg_send_end_of_axn: Sending END_OF_AXN for transId[%d], peerId[%d], context[type = %s, value = %d]\n",
transId->val, peerId->val, PRNT_MG_CTXT_TYPE(ctxtId->type.val), ctxtId->val.val);
#else
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,
"mg_send_end_of_axn: Sending END_OF_AXN for transId[%lu], peerId[%lu], context[type = %s, value = %lu]\n",
transId->val, peerId->val, PRNT_MG_CTXT_TYPE(ctxtId->type.val), ctxtId->val.val);
#endif
ret = sng_mgco_send_axn_req(suId, &ctxt);
return SWITCH_STATUS_SUCCESS;
}
/*****************************************************************************************************************************/
/*
*
* Fun: mg_build_mgco_err_request
*
* Desc: this api will send the Error event to MG stack to indicate failure in application
*
*
*/
switch_status_t mg_build_mgco_err_request(MgMgcoInd **errcmd,U32 trans_id, MgMgcoContextId *ctxt_id, U32 err, MgStr *errTxt)
{
MgMgcoInd *mgErr;
S16 ret;
mgErr = NULLP;
ret = ROK;
/* Allocate for AG error */
mg_stack_alloc_mem((Ptr*)&mgErr, sizeof(MgMgcoInd));
if (NULL == mgErr) {
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, " mg_build_mgco_err_request Failed : memory alloc \n");
return SWITCH_STATUS_FALSE;
}
/* Set transaction Id in the error request */
MG_SET_VAL_PRES(mgErr->transId, trans_id);
/* Copy the context Id */
MG_MEM_COPY(&mgErr->cntxtId,
ctxt_id,
sizeof(MgMgcoContextId));
/* Set the peerId */
mgErr->peerId.pres = NOTPRSNT;
/* Set the error code */
MG_SET_PRES(mgErr->err.pres.pres);
MG_SET_PRES(mgErr->err.code.pres);
MG_SET_VAL_PRES(mgErr->err.code, err);
if(errTxt->len)
{
MG_GETMEM(mgErr->err.text.val, (errTxt->len)*sizeof(U8), &mgErr->memCp, &ret);
if (ROK != ret) {
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, " mg_build_mgco_err_request Failed : memory alloc \n");
return SWITCH_STATUS_FALSE;
}
mgErr->err.text.pres = PRSNT_NODEF;
mgErr->err.text.len = errTxt->len;
MG_MEM_COPY(mgErr->err.text.val, errTxt->val, errTxt->len);
}
/* Set the output value */
*errcmd = mgErr;
return SWITCH_STATUS_SUCCESS;
}
/*****************************************************************************************************************************/
switch_status_t handle_mg_audit_cmd( SuId suId, MgMgcoCommand *auditReq)
{
MgMgcoContextId *ctxtId;
MgMgcoTermIdLst *term_list;
MgStr errTxt;
MgMgcoInd *mgErr;
MgMgcoTermId *termId;
MgMgcoSubAudReq *audit;
MgMgcoAuditDesc *audit_desc;
MgMgcoAuditItem *audit_item;
int i;
int err_code;
audit = &auditReq->u.mgCmdReq[0]->cmd.u.aval;
if(NOTPRSNT == audit->pres.pres){
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,"Audit structure not present..rejecting \n");
return SWITCH_STATUS_FALSE;
}
audit_desc = &audit->audit;
if((NOTPRSNT == audit_desc->pres.pres) || ( NOTPRSNT == audit_desc->num.pres)){
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,"Audit Descriptor not present..rejecting \n");
return SWITCH_STATUS_FALSE;
}
/* dump AUDIT message information */
/*mgAccEvntPrntMgMgcoSubAudReq(auditReq,stdout);*/
/*-- Get context id --*/
ctxtId = &auditReq->contextId;
/*-- Get termination list --*/
term_list = mg_get_term_id_list(auditReq);
termId = term_list->terms[0];
/*-- Start with Context level checks --*/
/*-- CHOOSE Context not allowed --*/
if ((NOTPRSNT != ctxtId->type.pres) &&
(MGT_CXTID_CHOOSE == ctxtId->type.val)) {
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,
"failed, Ctxt: CHOOSE not allowed in Audit Value\n");
/* set correct error code */
mg_util_set_ctxt_string(&errTxt,ctxtId);
err_code = MGT_MGCO_RSP_CODE_INVLD_IDENTIFIER;
goto error;
}
/*-- CHOOSE Termination not allowed --*/
else if ((NOTPRSNT != termId->type.pres) &&
(MGT_TERMID_CHOOSE == termId->type.val)) {
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,
"failed, Term: CHOOSE not allowed in Audit Value\n");
mg_util_set_term_string(&errTxt,termId);
err_code = MGT_MGCO_RSP_CODE_INVLD_IDENTIFIER;
goto error;
}
/*-- For Audit Values, ROOT Termination is allowed with Context = ALL but not allowed with Other --*/
/*-- Check whether the termination is present in the given context --*/
if (((NOTPRSNT != termId->type.pres) &&
(MGT_TERMID_ROOT == termId->type.val)) &&
((NOTPRSNT != ctxtId->type.pres) &&
(MGT_CXTID_OTHER == ctxtId->type.val))) {
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,
"failed, Term: Invalid combination, ROOT Term with OTHER CONTEXT\n");
mg_util_set_ctxt_string(&errTxt,ctxtId);
err_code = MGT_MGCO_RSP_CODE_INVLD_IDENTIFIER;
goto error;
}
/* validation done , now processing command */
for (i = 0; i < audit_desc->num.val; i++) {
audit_item = audit_desc->al[i];
if (!audit_item) {
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,
"Audit Descriptor is NULL.. rejecting \n");
return SWITCH_STATUS_FALSE;
}
/*TODO - If we are not supporint AUDIT type then can send "MGT_MGCO_RSP_CODE_UNSUPPORTED_DESC" error to MG stack */
if (NOTPRSNT != audit_item->auditItem.pres) {
switch(audit_item->auditItem.val)
{
case MGT_MEDIADESC:
{
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,"Auditing MEDIA \n");
break;
}
case MGT_MODEMDESC:
{
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,"Auditing MODEM \n");
break;
}
case MGT_MUXDESC:
{
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,"Auditing MULTIPLEX \n");
break;
}
case MGT_REQEVTDESC:
{
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,"Auditing Events \n");
break;
}
case MGT_SIGNALSDESC:
{
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,"Auditing Signals \n");
break;
}
case MGT_DIGMAPDESC:
{
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,"Auditing Digit Maps \n");
break;
}
case MGT_OBSEVTDESC:
{
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,"Auditing Buffer Events \n");
break;
}
case MGT_EVBUFDESC:
{
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,"Auditing Events Buffer \n");
break;
}
case MGT_STATSDESC:
{
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,"Auditing Statistics \n");
break;
}
case MGT_PKGSDESC:
{
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,"Auditing Packages \n");
handle_pkg_audit(suId, auditReq);
break;
}
case MGT_INDAUD_TERMAUDDESC:
{
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO,"Individual Term Audit \n");
break;
}
default:
{
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,"Invalid Audit Descriptor[%d] request\n",audit_item->auditItem.val);
err_code = MGT_MGCO_RSP_CODE_UNSUPPORTED_DESC;
goto error;
}
}/*switch(audit_item->auditItem.val)*/
}/*if (NOTPRSNT != audit_item->auditItem.pres)*/
}/*for loop - audit_desc->num.val */
return SWITCH_STATUS_SUCCESS;
error:
if (SWITCH_STATUS_SUCCESS == mg_build_mgco_err_request(&mgErr, auditReq->transId.val, ctxtId, err_code, &errTxt)) {
sng_mgco_send_err(suId, mgErr);
}
/* deallocate the msg */
mg_free_cmd(auditReq);
return SWITCH_STATUS_FALSE;
}
/*****************************************************************************************************************************/
switch_status_t handle_pkg_audit( SuId suId, MgMgcoCommand *auditReq)
{
switch_status_t ret;
MgMgcoCommand reply;
MgMgcoTermIdLst *term_list;
MgMgcoTermId *termId;
MgMgcoSubAudReq *audit;
MgMgcoAuditDesc *audit_desc;
MgMgcoAuditReply *adtRep = NULLP;
U16 numOfParms;
MgMgcoCtxt ctxt;
memset(&reply, 0, sizeof(reply));
audit = &auditReq->u.mgCmdReq[0]->cmd.u.aval;
if(NOTPRSNT == audit->pres.pres){
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,"Audit structure not present..rejecting \n");
return SWITCH_STATUS_FALSE;
}
audit_desc = &audit->audit;
if((NOTPRSNT == audit_desc->pres.pres) || ( NOTPRSNT == audit_desc->num.pres)){
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,"Audit Descriptor not present..rejecting \n");
return SWITCH_STATUS_FALSE;
}
/* dump AUDIT message information */
/*mgAccEvntPrntMgMgcoSubAudReq(auditReq,stdout);*/
/*-- Get termination list --*/
term_list = mg_get_term_id_list(auditReq);
termId = term_list->terms[0];
/*copy transaction-id*/
memcpy(&reply.transId, &auditReq->transId,sizeof(MgMgcoTransId));
/*copy context-id*/
memcpy(&reply.contextId, &auditReq->contextId,sizeof(MgMgcoContextId));
/*copy peer identifier */
memcpy(&reply.peerId, &auditReq->peerId,sizeof(TknU32));
/*fill response structue */
if(SWITCH_STATUS_FALSE == (ret = mg_stack_alloc_mem((Ptr*)&reply.u.mgCmdRsp[0],sizeof(MgMgcoCmdReply)))){
return ret;
}
reply.u.mgCmdRsp[0]->pres.pres = PRSNT_NODEF;
reply.u.mgCmdRsp[0]->type.pres = PRSNT_NODEF;
reply.u.mgCmdRsp[0]->type.val = MGT_AUDITVAL;
adtRep = &(reply.u.mgCmdRsp[0]->u.aval);
adtRep->type.pres = PRSNT_NODEF;
adtRep->type.val = MGT_TERMAUDIT;
adtRep->u.other.pres.pres = PRSNT_NODEF;
mgUtlAllocMgMgcoTermIdLst(&adtRep->u.other.termIdLst, term_list);
/* Grow the list of reply parameters */
if (mgUtlGrowList((void ***)&adtRep->u.other.audit.parms, sizeof(MgMgcoAudRetParm),
&adtRep->u.other.audit.num, &reply.u.mgCmdRsp[0]->memCp) != ROK)
{
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,"Grow List failed\n");
return SWITCH_STATUS_FALSE;
}
numOfParms = adtRep->u.other.audit.num.val;
adtRep->u.other.audit.parms[numOfParms - 1]->type.pres = PRSNT_NODEF;
adtRep->u.other.audit.parms[numOfParms - 1]->type.val = MGT_PKGSDESC;
if(SWITCH_STATUS_FALSE == mg_build_pkg_desc(&adtRep->u.other.audit.parms[numOfParms - 1]->u.pkgs)){
return SWITCH_STATUS_FALSE;
}
/* We will always send one command at a time..*/
reply.cmdStatus.pres = PRSNT_NODEF;
reply.cmdStatus.val = CH_CMD_STATUS_END_OF_CMD;
reply.cmdType.pres = PRSNT_NODEF;
reply.cmdType.val = CH_CMD_TYPE_RSP;
ret = sng_mgco_send_cmd(suId, &reply);
memcpy(&ctxt.transId,&auditReq->transId,sizeof(MgMgcoTransId));
memcpy(&ctxt.cntxtId, &auditReq->contextId,sizeof(MgMgcoContextId));
memcpy(&ctxt.peerId, &auditReq->peerId,sizeof(TknU32));
ctxt.cmdStatus.pres = PRSNT_NODEF;
ctxt.cmdStatus.val = CH_CMD_STATUS_END_OF_AXN;
ret = sng_mgco_send_axn_req(suId, &ctxt);
return ret;
}
/*****************************************************************************************************************************/
switch_status_t mg_send_audit_rsp(SuId suId, MgMgcoCommand *req)
{
MgMgcoCommand cmd;
int ret = 0x00;
MgMgcoTermId *termId;
MgMgcoCtxt ctxt;
MgMgcoAuditReply *adtRep = NULLP;
memset(&cmd,0, sizeof(cmd));
/*copy transaction-id*/
memcpy(&cmd.transId, &req->transId,sizeof(MgMgcoTransId));
/*copy context-id*/ /*TODO - in case of $ context should be generated by app, we should not simply copy incoming structure */
memcpy(&cmd.contextId, &req->contextId,sizeof(MgMgcoContextId));
/*copy peer identifier */
memcpy(&cmd.peerId, &req->peerId,sizeof(TknU32));
/*fill response structue */
if(SWITCH_STATUS_FALSE == (ret = mg_stack_alloc_mem((Ptr*)&cmd.u.mgCmdRsp[0],sizeof(MgMgcoCmdReply)))){
return ret;
}
cmd.u.mgCmdRsp[0]->pres.pres = PRSNT_NODEF;
cmd.u.mgCmdRsp[0]->type.pres = PRSNT_NODEF;
cmd.u.mgCmdRsp[0]->wild.pres = NOTPRSNT;
cmd.u.mgCmdRsp[0]->type.val = MGT_AUDITVAL;
adtRep = &(cmd.u.mgCmdRsp[0]->u.aval);
/* Set type as Cxt Audit */
MG_INIT_TOKEN_VALUE(&(adtRep->type), MGT_CXTAUDIT);
/* Set no of Terminations to 1 */
MG_INIT_TOKEN_VALUE(&(adtRep->u.cxt.num), 1);
cmd.u.mgCmdRsp[0]->u.aval.u.cxt.num.pres = PRSNT_NODEF;
cmd.u.mgCmdRsp[0]->u.aval.u.cxt.num.val = 1;
mgUtlAllocMgMgcoTermIdLst(&cmd.u.mgCmdRsp[0]->u.aval.u.cxt, &req->u.mgCmdReq[0]->cmd.u.aval.termIdLst);
#ifdef GCP_VER_2_1
termId = cmd.u.mgCmdRsp[0]->u.add.termIdLst.terms[0];
#else
termId = &(cmd.u.mgCmdRsp[0]->u.add.termId);
#endif
mg_fill_mgco_termid(termId, (CONSTANT U8*)"term1",&req->u.mgCmdRsp[0]->memCp);
/* We will always send one command at a time..*/
cmd.cmdStatus.pres = PRSNT_NODEF;
cmd.cmdStatus.val = CH_CMD_STATUS_END_OF_CMD;
cmd.cmdType.pres = PRSNT_NODEF;
cmd.cmdType.val = CH_CMD_TYPE_RSP;
ret = sng_mgco_send_cmd(suId, &cmd);
memcpy(&ctxt.transId,&req->transId,sizeof(MgMgcoTransId));
memcpy(&ctxt.cntxtId, &req->contextId,sizeof(MgMgcoContextId));
memcpy(&ctxt.peerId, &req->peerId,sizeof(TknU32));
ctxt.cmdStatus.pres = PRSNT_NODEF;
ctxt.cmdStatus.val = CH_CMD_STATUS_END_OF_AXN;
ret = sng_mgco_send_axn_req(suId, &ctxt);
return ret;
}
/*****************************************************************************************************************************/
switch_status_t mg_send_modify_rsp(SuId suId, MgMgcoCommand *req)
{
MgMgcoCommand cmd;
int ret = 0x00;
MgMgcoTermId *termId;
MgMgcoCtxt ctxt;
memset(&cmd,0, sizeof(cmd));
/*copy transaction-id*/
memcpy(&cmd.transId, &req->transId,sizeof(MgMgcoTransId));
/*copy context-id*/ /*TODO - in case of $ context should be generated by app, we should not simply copy incoming structure */
memcpy(&cmd.contextId, &req->contextId,sizeof(MgMgcoContextId));
/*copy peer identifier */
memcpy(&cmd.peerId, &req->peerId,sizeof(TknU32));
/*fill response structue */
if(SWITCH_STATUS_FALSE == (ret = mg_stack_alloc_mem((Ptr*)&cmd.u.mgCmdRsp[0],sizeof(MgMgcoCmdReply)))){
return ret;
}
cmd.u.mgCmdRsp[0]->pres.pres = PRSNT_NODEF;
cmd.u.mgCmdRsp[0]->type.pres = PRSNT_NODEF;
cmd.u.mgCmdRsp[0]->type.val = MGT_MODIFY;
cmd.u.mgCmdRsp[0]->u.mod.pres.pres = PRSNT_NODEF;
cmd.u.mgCmdRsp[0]->u.mod.termIdLst.num.pres = PRSNT_NODEF;
cmd.u.mgCmdRsp[0]->u.mod.termIdLst.num.val = 1;
mgUtlAllocMgMgcoTermIdLst(&cmd.u.mgCmdRsp[0]->u.mod.termIdLst, &req->u.mgCmdReq[0]->cmd.u.mod.termIdLst);
#ifdef GCP_VER_2_1
termId = cmd.u.mgCmdRsp[0]->u.mod.termIdLst.terms[0];
#else
termId = &(cmd.u.mgCmdRsp[0]->u.mod.termId);
#endif
mg_fill_mgco_termid(termId, (CONSTANT U8*)"term1",&req->u.mgCmdRsp[0]->memCp);
/* We will always send one command at a time..*/
cmd.cmdStatus.pres = PRSNT_NODEF;
cmd.cmdStatus.val = CH_CMD_STATUS_END_OF_CMD;
cmd.cmdType.pres = PRSNT_NODEF;
cmd.cmdType.val = CH_CMD_TYPE_RSP;
ret = sng_mgco_send_cmd(suId, &cmd);
memcpy(&ctxt.transId,&req->transId,sizeof(MgMgcoTransId));
memcpy(&ctxt.cntxtId, &req->contextId,sizeof(MgMgcoContextId));
memcpy(&ctxt.peerId, &req->peerId,sizeof(TknU32));
ctxt.cmdStatus.pres = PRSNT_NODEF;
ctxt.cmdStatus.val = CH_CMD_STATUS_END_OF_AXN;
ret = sng_mgco_send_axn_req(suId, &ctxt);
return ret;
}
/*****************************************************************************************************************************/
/*****************************************************************************************************************************/
switch_status_t mg_send_subtract_rsp(SuId suId, MgMgcoCommand *req)
{
MgMgcoCommand cmd;
int ret = 0x00;
MgMgcoTermId *termId;
MgMgcoCtxt ctxt;
memset(&cmd,0, sizeof(cmd));
/*copy transaction-id*/
memcpy(&cmd.transId, &req->transId,sizeof(MgMgcoTransId));
/*copy context-id*/ /*TODO - in case of $ context should be generated by app, we should not simply copy incoming structure */
memcpy(&cmd.contextId, &req->contextId,sizeof(MgMgcoContextId));
/*copy peer identifier */
memcpy(&cmd.peerId, &req->peerId,sizeof(TknU32));
/*fill response structue */
if(SWITCH_STATUS_FALSE == (ret = mg_stack_alloc_mem((Ptr*)&cmd.u.mgCmdRsp[0],sizeof(MgMgcoCmdReply)))){
return ret;
}
cmd.u.mgCmdRsp[0]->pres.pres = PRSNT_NODEF;
cmd.u.mgCmdRsp[0]->type.pres = PRSNT_NODEF;
cmd.u.mgCmdRsp[0]->type.val = MGT_SUB;
cmd.u.mgCmdRsp[0]->u.sub.pres.pres = PRSNT_NODEF;
cmd.u.mgCmdRsp[0]->u.sub.termIdLst.num.pres = PRSNT_NODEF;
cmd.u.mgCmdRsp[0]->u.sub.termIdLst.num.val = 1;
mgUtlAllocMgMgcoTermIdLst(&cmd.u.mgCmdRsp[0]->u.sub.termIdLst, &req->u.mgCmdReq[0]->cmd.u.sub.termIdLst);
#ifdef GCP_VER_2_1
termId = cmd.u.mgCmdRsp[0]->u.sub.termIdLst.terms[0];
#else
termId = &(cmd.u.mgCmdRsp[0]->u.sub.termId);
#endif
mg_fill_mgco_termid(termId, (CONSTANT U8*)"term1",&req->u.mgCmdRsp[0]->memCp);
/* We will always send one command at a time..*/
cmd.cmdStatus.pres = PRSNT_NODEF;
cmd.cmdStatus.val = CH_CMD_STATUS_END_OF_CMD;
cmd.cmdType.pres = PRSNT_NODEF;
cmd.cmdType.val = CH_CMD_TYPE_RSP;
ret = sng_mgco_send_cmd(suId, &cmd);
memcpy(&ctxt.transId,&req->transId,sizeof(MgMgcoTransId));
memcpy(&ctxt.cntxtId, &req->contextId,sizeof(MgMgcoContextId));
memcpy(&ctxt.peerId, &req->peerId,sizeof(TknU32));
ctxt.cmdStatus.pres = PRSNT_NODEF;
ctxt.cmdStatus.val = CH_CMD_STATUS_END_OF_AXN;
ret = sng_mgco_send_axn_req(suId, &ctxt);
return ret;
}

View File

@ -0,0 +1,135 @@
/*
* Copyright (c) 2012, Sangoma Technologies
* Mathieu Rene <mrene@avgs.ca>
* All rights reserved.
*
* <Insert license here>
*/
#include "mod_media_gateway.h"
#include "media_gateway_stack.h"
MgPackage_t mg_pkg_list [] =
{
{ /* INDEX : 0 */
MGT_PKG_GENERIC, /* Package Id 1 : Generic package */
1, /* Version 1 */
"g", /* Package name */
},
{ /* INDEX : 1 */
MGT_PKG_ROOT,
2, /* Version 1 */
"root", /* Package name */
},
{ /* INDEX : 2 */
MGT_PKG_TONEDET, /*4*/
1, /* Version 1 */
"tonedet", /* Package name */
},
{ /* INDEX : 3 */
MGT_PKG_DTMFDET, /*6*/
1, /* Version 1 */
"dd", /* Package name */
},
{ /* INDEX : 4 */
MGT_PKG_NETWORK, /*11*/
1, /* Version 1 */
"nt", /* Package name */
},
{ /* INDEX : 5 */
MGT_PKG_RTP, /*12*/
1, /* Version 1 */
"rtp", /* Package name */
},
{ /* INDEX : 6 */
MGT_PKG_TDM_CKT, /*13*/
1, /* Version 1 */
"tdmc", /* Package name */
},
{ /* INDEX : 7 */
MGT_PKG_QTY_ALT, /*55*/
1, /* Version 1 */
"qac", /* Package name */
},
{ /* INDEX : 8 */
MGT_PKG_EN_ALERT, /*59*/
2, /* Version 2 */
"alert", /* Package name */
},
{ /* INDEX : 9 */
MGT_PKG_AN_DISP, /*60*/
2, /* Version 1 */
"andisp", /* Package name */
},
{ /* INDEX : 10 */
MGT_PKG_INACTTIMER, /*69*/
1, /* Version 1 */
"it", /* Package name */
},
{ /* INDEX : 11 */
MGT_PKG_STIMAL, /* 147 */
1, /* Version 1 */
"stimal ", /* Package name */
},
{ /* INDEX : 12 */
MGT_PKG_CALLPROGGEN, /* 7 */
1, /* Version 1 */
"cg", /* Package name */
},
{ /* INDEX : 13 */
MGT_PKG_GENERIC_ANNC, /* 29 */
1, /* Version 1 */
"an", /* Package name */
},
{ /* INDEX : 14 */
MGT_PKG_XD_CALPG_TNGN, /* 36 */
1, /* Version 1 */
"xcg", /* Package name */
},
{ /* INDEX : 15 */
MGT_PKG_BSC_SRV_TN, /* 37 */
1, /* Version 1 */
"srvtn", /* Package name */
},
{ /* INDEX : 16 */
MGT_PKG_ETSI_NR,
1, /* Version 1 */
"etsi_nr", /* Package name */
},
/* Add more packages */
};
/***************************************************************************************/
switch_status_t mg_build_pkg_desc(MgMgcoPkgsDesc* pkg)
{
uint16_t i = 0x00;
uint16_t num_of_pkgs = sizeof(mg_pkg_list)/sizeof(MgPackage_t);
printf("mg_build_pkg_desc: num_of_pkgs[%d]\n",num_of_pkgs);
for (i = 0; i < num_of_pkgs; i++) {
if (mgUtlGrowList((void ***)&pkg->items,
sizeof(MgMgcoPkgsItem), &pkg->num, NULLP) != ROK) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,"Package descriptor Grow List failed\n");
return SWITCH_STATUS_FALSE;
}
pkg->items[pkg->num.val - 1 ]->pres.pres = PRSNT_NODEF;
pkg->items[pkg->num.val - 1 ]->name.type.pres = PRSNT_NODEF;
pkg->items[pkg->num.val - 1 ]->name.type.val = MGT_GEN_TYPE_KNOWN;
pkg->items[pkg->num.val - 1 ]->name.u.val.pres = PRSNT_NODEF;
pkg->items[pkg->num.val - 1 ]->name.u.val.val = mg_pkg_list[i].package_id;
pkg->items[pkg->num.val - 1 ]->ver.pres = PRSNT_NODEF;
pkg->items[pkg->num.val - 1 ]->ver.val = mg_pkg_list[i].version;
printf("mg_build_pkg_desc: Inserted pkg_id[%d] with version[%d] into pkg list index[%d]\n",mg_pkg_list[i].package_id,mg_pkg_list[i].version,i);
}
return SWITCH_STATUS_SUCCESS;
}
/***************************************************************************************/

View File

@ -49,29 +49,55 @@ typedef struct _mgStr
U8 val[128];
} MgStr;
#define MAX_PACKAGE_NAME 128
typedef struct _mgPackage
{
uint8_t package_id;
uint16_t version;
uint8_t name[MAX_PACKAGE_NAME+1];
}MgPackage_t;
extern MgPackage_t mg_pkg_list[];
#define MG_TXN_INVALID 0
#define mg_zero(_buf, _size) {cmMemset((U8 *)(_buf), 0, _size);}
#define MG_ZERO(_buf, _size) {cmMemset((U8 *)(_buf), 0, _size);}
/* Set pres field */
#define mg_util_set_pres(_pres) \
#define MG_SET_PRES(_pres) \
(_pres) = PRSNT_NODEF;
/* Set token value */
#define mg_util_set_val_pres(tkn,_val) \
mg_util_set_pres((tkn).pres); \
#define MG_SET_VAL_PRES(tkn,_val) \
MG_SET_PRES((tkn).pres); \
(tkn).val = _val;
#define mg_mem_copy(_dst, _src, _len) \
#define MG_MEM_COPY(_dst, _src, _len) \
cmMemcpy((U8*) (_dst), (const U8*) (_src), _len)
#define mg_get_mem(_memPtr, _size, _allocPtr, ret) \
#define MG_INIT_TOKEN_VALUE(_tkn, _val) \
{ \
(*ret) = cmGetMem((Ptr *)(_memPtr),(_size) ,(Ptr *)&(_allocPtr)); \
(_tkn)->pres = PRSNT_NODEF; \
(_tkn)->val = (_val); \
}
#define MG_GETMEM(_ptr,_len,_memCp,_ret) \
{ \
ret = cmGetMem((_memCp), (_len), (Ptr *)&(_ptr)); \
if( ret == ROK) \
cmMemset((U8 *)(_ptr), (U8)0, (PTR)(_len)); \
}
#define MG_INIT_TKNSTR(_tkn, _val, _len) \
{ \
(_tkn)->pres = PRSNT_NODEF; \
(_tkn)->len = (U8)(_len); \
cmMemcpy((U8 *)(_tkn)->val, (CONSTANT U8 *)(_val), (_len)); \
}
void handle_sng_log(uint8_t level, char *fmt, ...);
void handle_mgco_sta_ind(Pst *pst, SuId suId, MgMgtSta* msg);
@ -91,6 +117,29 @@ switch_status_t sng_mgco_init(sng_mg_event_interface_t* event);
switch_status_t sng_mgco_stack_shutdown(void);
int sng_mgco_mg_get_status(int elemId, MgMngmt* cfm, megaco_profile_t* mg_cfg, mg_peer_profile_t* mg_peer);
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(MgMgcoAmmReq *addReq);
switch_status_t mg_stack_free_mem(MgMgcoMsg* msg);
switch_status_t mg_stack_free_mem(MgMgcoMsg* msg);
switch_status_t mg_stack_alloc_mem( Ptr* _memPtr, Size _memSize );
switch_status_t mg_send_add_rsp(SuId suId, MgMgcoCommand *req);
S16 mg_fill_mgco_termid ( MgMgcoTermId *termId, CONSTANT U8 *str, CmMemListCp *memCp);
void mg_util_set_txn_string(MgStr *errTxt, U32 *txnId);
switch_status_t mg_build_mgco_err_request(MgMgcoInd **errcmd,U32 trans_id, MgMgcoContextId *ctxt_id, U32 err, MgStr *errTxt);
switch_status_t mg_send_audit_rsp(SuId suId, MgMgcoCommand *req);
switch_status_t handle_mg_audit_cmd(SuId suId, MgMgcoCommand *auditReq);
switch_status_t mg_send_modify_rsp(SuId suId, MgMgcoCommand *req);
switch_status_t mg_send_subtract_rsp(SuId suId, MgMgcoCommand *req);
void mg_util_set_term_string ( MgStr *errTxt, MgMgcoTermId *termId);
MgMgcoTermIdLst *mg_get_term_id_list(MgMgcoCommand *cmd);
switch_status_t handle_pkg_audit( SuId suId, MgMgcoCommand *auditReq);
switch_status_t mg_build_pkg_desc(MgMgcoPkgsDesc* pkg);
/****************************************************************************************************************/
/* MG Stack defines */

View File

@ -0,0 +1,434 @@
/*
* Copyright (c) 2012, Sangoma Technologies
* Mathieu Rene <mrene@avgs.ca>
* All rights reserved.
*
* <Insert license here>
*/
#include "mod_media_gateway.h"
#include "media_gateway_stack.h"
/*****************************************************************************************************************************/
switch_status_t mg_stack_alloc_mem( Ptr* _memPtr, Size _memSize )
{
Mem sMem;
sMem.region = 0;
sMem.pool = 0;
if ( _memSize <= 0 )
{
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, " Failed mg_stack_alloc_mem: invalid size\n");
return SWITCH_STATUS_FALSE;
}
if ( ROK != cmAllocEvnt( _memSize, MG_MAXBLKSIZE, &sMem, _memPtr ) )
{
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, " Failed mg_stack_alloc_mem: cmAllocEvnt return failure for _memSize=%d\n",(int)_memSize);
return SWITCH_STATUS_FALSE;
}
// Note: memset done inside stack api
return SWITCH_STATUS_SUCCESS;
}
/*****************************************************************************************************************************/
switch_status_t mg_stack_get_mem(MgMgcoMsg* msg, Ptr* _memPtr, Size _memSize )
{
if ( _memSize <= 0 )
{
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, " Failed mg_stack_get_mem: invalid size\n");
return SWITCH_STATUS_FALSE;
}
if ( !msg )
{
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, " Failed mg_stack_get_mem: invalid message\n");
return SWITCH_STATUS_FALSE;
}
if ( cmGetMem( (Ptr)msg, _memSize, (Ptr*)_memPtr ) != ROK )
{
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, " Failed alloc_mg_stack_mem: get memory failed _memSize=%d\n", (int)_memSize );
return SWITCH_STATUS_FALSE;
}
// Note: memset done inside stack api
return SWITCH_STATUS_SUCCESS;
}
/*****************************************************************************************************************************/
switch_status_t mg_stack_free_mem(MgMgcoMsg* msg)
{
if ( !msg )
{
switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR, " Failed mg_stack_get_mem: invalid message\n");
return SWITCH_STATUS_FALSE;
}
cmFreeMem( (Ptr)msg );
return SWITCH_STATUS_SUCCESS;
}
/*****************************************************************************************************************************/
S16 mg_fill_mgco_termid ( MgMgcoTermId *termId, CONSTANT U8 *str, CmMemListCp *memCp)
{
#ifdef GCP_ASN
Size size;
#endif
S16 ret = ROK;
termId->name.pres.pres = PRSNT_NODEF;
/* mg011.105: Bug fixes */
termId->name.lcl.pres = PRSNT_NODEF;
termId->name.lcl.len = cmStrlen((CONSTANT U8*)str);
MG_GETMEM(termId->name.lcl.val, termId->name.lcl.len, memCp, ret);
if( ret != ROK)
RETVALUE(ret);
cmMemcpy((U8*)(termId->name.lcl.val), (CONSTANT U8*)str,termId->name.lcl.len);
#ifdef GCP_ASN
/* Remove comment to fill other term ID
termId->wildcard.num.pres = NOTPRSNT; */
/* Remove comment to fill wilcard term ID */
termId->wildcard.num.pres = PRSNT_NODEF;
termId->wildcard.num.val = 1;
size = ((sizeof(MgMgcoWildcardField*)));
MG_GETMEM((termId->wildcard.wildcard),size,memCp, ret);
if( ret != ROK)
RETVALUE(ret);
MG_GETMEM( ((termId->wildcard.wildcard)[0]),sizeof(MgMgcoWildcardField),
memCp, ret);
if( ret != ROK)
RETVALUE(ret);
termId->wildcard.wildcard[0]->pres = PRSNT_NODEF;
termId->wildcard.wildcard[0]->len = 1;
termId->wildcard.wildcard[0]->val[0] = 0x55;
#endif /* GCP_ASN */
RETVALUE(ROK);
}
/*****************************************************************************************************************************/
/*
*
* Fun: mg_get_term_id_list
*
* Desc: Utility function to get MgMgcoTermIdLst structure
* from MgMgcoCommand structure.
* GCP_VER_2_1 - we will have term id list instead of single term id
*
* Ret: If success, return pointer to MgMgcoTermIdLst.
* If failure, return Null.
*
* Notes: None
*
*/
MgMgcoTermIdLst *mg_get_term_id_list(MgMgcoCommand *cmd)
{
uint8_t cmd_type = MGT_NONE;
uint8_t api_type = CM_CMD_TYPE_NONE;
MgMgcoTermIdLst * term_id = NULL;
/*-- mgCmdInd type represents the data structure for both
* incoming and outgoing requests, hence we can get the
* command type from there itself --*/
cmd_type = cmd->u.mgCmdInd[0]->cmd.type.val;
/*-- Find apiType --*/
api_type = cmd->cmdType.val;
switch (api_type)
{
case CH_CMD_TYPE_REQ:
case CH_CMD_TYPE_IND:
/* Based on Command Type, get to the TermId structure */
switch (cmd_type)
{
case MGT_ADD:
if (cmd->u.mgCmdInd[0]->cmd.u.add.pres.pres)
term_id = &cmd->u.mgCmdInd[0]->cmd.u.add.termIdLst;
break;
case MGT_MOVE:
if (cmd->u.mgCmdInd[0]->cmd.u.move.pres.pres)
term_id = &cmd->u.mgCmdInd[0]->cmd.u.move.termIdLst;
break;
case MGT_MODIFY:
if (cmd->u.mgCmdInd[0]->cmd.u.mod.pres.pres)
term_id = &cmd->u.mgCmdInd[0]->cmd.u.mod.termIdLst;
break;
case MGT_SUB:
if (cmd->u.mgCmdInd[0]->cmd.u.sub.pres.pres)
term_id = &cmd->u.mgCmdInd[0]->cmd.u.sub.termIdLst;
break;
case MGT_AUDITCAP:
if (cmd->u.mgCmdInd[0]->cmd.u.acap.pres.pres)
term_id = &cmd->u.mgCmdInd[0]->cmd.u.acap.termIdLst;
break;
case MGT_AUDITVAL:
if (cmd->u.mgCmdInd[0]->cmd.u.aval.pres.pres)
term_id = &cmd->u.mgCmdInd[0]->cmd.u.aval.termIdLst;
break;
case MGT_NTFY:
if (cmd->u.mgCmdInd[0]->cmd.u.ntfy.pres.pres)
term_id = &cmd->u.mgCmdInd[0]->cmd.u.ntfy.termIdLst;
break;
case MGT_SVCCHG:
if (cmd->u.mgCmdInd[0]->cmd.u.svc.pres.pres)
term_id = &cmd->u.mgCmdInd[0]->cmd.u.svc.termIdLst;
break;
default:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%s: failed, Unsupported Command[%s]\n", __PRETTY_FUNCTION__, PRNT_MG_CMD(cmd_type));
break;
}
break;
case CH_CMD_TYPE_RSP:
case CH_CMD_TYPE_CFM:
cmd_type = cmd->u.mgCmdRsp[0]->type.val;
switch (cmd_type)
{
case MGT_ADD:
if (cmd->u.mgCmdRsp[0]->u.add.pres.pres)
term_id = &cmd->u.mgCmdRsp[0]->u.add.termIdLst;
break;
case MGT_MOVE:
if (cmd->u.mgCmdRsp[0]->u.move.pres.pres)
term_id = &cmd->u.mgCmdRsp[0]->u.move.termIdLst;
break;
case MGT_MODIFY:
if (cmd->u.mgCmdRsp[0]->u.mod.pres.pres)
term_id = &cmd->u.mgCmdRsp[0]->u.mod.termIdLst;
break;
case MGT_SUB:
if (cmd->u.mgCmdRsp[0]->u.sub.pres.pres)
term_id = &cmd->u.mgCmdRsp[0]->u.sub.termIdLst;
break;
case MGT_SVCCHG:
if (cmd->u.mgCmdRsp[0]->u.svc.pres.pres)
term_id = &cmd->u.mgCmdRsp[0]->u.svc.termIdLst;
break;
case MGT_AUDITVAL:
if (cmd->u.mgCmdRsp[0]->u.aval.u.other.pres.pres)
term_id = &cmd->u.mgCmdRsp[0]->u.aval.u.other.termIdLst;
break;
case MGT_AUDITCAP:
if (cmd->u.mgCmdRsp[0]->u.acap.u.other.pres.pres)
term_id = &cmd->u.mgCmdRsp[0]->u.acap.u.other.termIdLst;
break;
case MGT_NTFY:
if (cmd->u.mgCmdRsp[0]->u.ntfy.pres.pres)
term_id = &cmd->u.mgCmdRsp[0]->u.ntfy.termIdLst;
break;
default:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%s: failed, Unsupported Command[%s]\n", __PRETTY_FUNCTION__, PRNT_MG_CMD(cmd_type));
} /* switch command type for reply */
break;
default:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%s: failed, Unsupported api_type[%s]!\n", __PRETTY_FUNCTION__, PRNT_MG_CMD_TYPE(api_type));
break;
} /* switch -api_type */
return (term_id);
}
/*****************************************************************************************************************************/
void mg_util_set_txn_string(MgStr *errTxt, U32 *txnId)
{
MG_ZERO(errTxt->val, sizeof(errTxt->val));
errTxt->len = 0;
errTxt->val[errTxt->len] = '\"';
errTxt->len += 1;
if (MG_TXN_INVALID == txnId )
{
MG_MEM_COPY((&errTxt->val[errTxt->len]), "TransactionId=0", 15);
errTxt->len += 15;
}
errTxt->val[errTxt->len] = '\"';
errTxt->len += 1;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%s:"
"info, error-text is: %s\n", __PRETTY_FUNCTION__,errTxt->val);
}
/*****************************************************************************************************************************/
void mg_util_set_ctxt_string ( MgStr *errTxt, MgMgcoContextId *ctxtId)
{
MG_ZERO((errTxt->val), sizeof(errTxt->val));
errTxt->len = 0;
if(ctxtId->type.pres != NOTPRSNT)
{
errTxt->val[errTxt->len] = '\"';
errTxt->len += 1;
if(ctxtId->type.val == MGT_CXTID_NULL)
{
errTxt->val[errTxt->len] = '-';
errTxt->len += 1;
}
else if(ctxtId->type.val == MGT_CXTID_ALL)
{
errTxt->val[errTxt->len] = '*';
errTxt->len += 1;
}
else if(ctxtId->type.val == MGT_CXTID_CHOOSE)
{
errTxt->val[errTxt->len] = '$';
errTxt->len += 1;
}
else if((ctxtId->type.val == MGT_CXTID_OTHER) && (ctxtId->val.pres != NOTPRSNT))
{
#ifdef BIT_64
sprintf((char*)&errTxt->val[errTxt->len], "%d", ctxtId->val.val);
#else
sprintf((char*)&errTxt->val[errTxt->len], "%lu", ctxtId->val.val);
#endif
errTxt->len += cmStrlen((U8*)(&errTxt->val[errTxt->len]));
}
errTxt->val[errTxt->len] = '\"';
errTxt->len += 1;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%s:"
"info, error-text is: %s\n", __PRETTY_FUNCTION__,errTxt->val);
}
/*****************************************************************************************************************************/
void mgco_print_sdp(CmSdpInfoSet *sdp)
{
int i;
if (sdp->numComp.pres == NOTPRSNT) {
return;
}
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) {
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];*/
}
}
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;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Port: %d\n", port);
}
}
}
}
}
}
/*****************************************************************************************************************************/
void mg_util_set_term_string ( MgStr *errTxt, MgMgcoTermId *termId)
{
MG_ZERO((errTxt->val), sizeof(errTxt->val));
errTxt->len = 0;
if(termId->type.pres != NOTPRSNT)
{
errTxt->val[errTxt->len] = '\"';
errTxt->len += 1;
if(termId->type.val == MGT_TERMID_ROOT)
{
MG_MEM_COPY((&errTxt->val[errTxt->len]), "ROOT", 4);
errTxt->len += 4;
}
else if(termId->type.val == MGT_TERMID_ALL)
{
errTxt->val[errTxt->len] = '*';
errTxt->len += 1;
}
else if(termId->type.val == MGT_TERMID_CHOOSE)
{
errTxt->val[errTxt->len] = '$';
errTxt->len += 1;
}
else if((termId->type.val == MGT_TERMID_OTHER) && (termId->name.pres.pres != NOTPRSNT))
{
if(termId->name.lcl.pres != NOTPRSNT)
{
MG_MEM_COPY(&(errTxt->val[errTxt->len]), termId->name.lcl.val, sizeof(U8) * termId->name.lcl.len);
errTxt->len += termId->name.lcl.len;
}
if(termId->name.dom.pres != NOTPRSNT)
{
MG_MEM_COPY(&(errTxt->val[errTxt->len]),
termId->name.dom.val, sizeof(U8) * termId->name.dom.len);
errTxt->len += termId->name.dom.len;
}
}
errTxt->val[errTxt->len] = '\"';
errTxt->len += 1;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%s:"
"info, error-text is: %s\n", __PRETTY_FUNCTION__,errTxt->val);
}
/*****************************************************************************************************************************/

View File

@ -12,7 +12,7 @@
static switch_xml_config_item_t *get_instructions(megaco_profile_t *profile) ;
static switch_xml_config_item_t *get_peer_instructions(mg_peer_profile_t *profile) ;
static int mg_sap_id;
static switch_status_t modify_mid(char* mid);
static switch_status_t modify_mid(char** pmid);
/****************************************************************************************************************************/
switch_status_t config_profile(megaco_profile_t *profile, switch_bool_t reload)
@ -59,10 +59,11 @@ switch_status_t config_profile(megaco_profile_t *profile, switch_bool_t reload)
profile->total_peers++;
}
if(SWITCH_STATUS_FALSE == (status = modify_mid(profile->mid))){
if(SWITCH_STATUS_FALSE == (status = modify_mid(&profile->mid))){
goto done;
}
profile->idx = ++mg_sap_id;
/* we should break from here , profile name should be unique */
@ -100,7 +101,7 @@ switch_status_t config_profile(megaco_profile_t *profile, switch_bool_t reload)
goto done;
}
if(SWITCH_STATUS_FALSE == (status = modify_mid(peer_profile->mid))){
if(SWITCH_STATUS_FALSE == (status = modify_mid(&peer_profile->mid))){
goto done;
}
@ -215,55 +216,57 @@ static switch_xml_config_item_t *get_instructions(megaco_profile_t *profile) {
/****************************************************************************************************************************/
static switch_status_t modify_mid(char* mid)
static switch_status_t modify_mid(char** pmid)
{
char* dup = NULL;
char* mid = *pmid;
char* dup;
char* val[10];
int count;
switch_status_t status = SWITCH_STATUS_FALSE;
switch_assert(mid);
dup = strdup(mid);
/* If MID type is IP then add mid into [] brackets ,
* If MID type is domain then add mid into <> brackets *
*/
dup = strdup(mid);
count = switch_split(dup, '.', val);
if(!count) {
/* Input string is not separated by '.', check if its separated by '-' as format could be xxx-xx-xxx/xxx-xx-xx-xxx */
free(dup);
dup = strdup(mid);
if(0 == (count = switch_split(dup, '-', val))){
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid input MID string[%s]\n",mid);
return SWITCH_STATUS_FALSE;
goto done;
}
}
if(('<' == val[0][0]) || ('[' == val[0][0])){
free(dup);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "MID[%s] is already prefixed with proper brackets \n",mid);
return SWITCH_STATUS_SUCCESS;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "MID = %s is already prefixed with proper brackets \n",mid);
status = SWITCH_STATUS_SUCCESS;
goto done;
}
/*first check could be if count is 3 means domain name as generally we have xxx-xx-xxx/xxx.xx.xxx domain */
if(3 == count){
/* domain-type, add value into <> */
free(dup);
dup = strdup(mid);
sprintf(mid,"<%s>",dup);
*pmid = switch_mprintf("<%s>", mid);
free(mid);
mid = *pmid;
}else if(4 == count){
/* IP address in xxx.xxx.xxx.xxx format */
free(dup);
dup = strdup(mid);
sprintf(mid,"[%s]",dup);
*pmid = switch_mprintf("[%s]", mid);
free(mid);
mid = *pmid;
}else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid input MID string[%s]\n",mid);
free(dup);
return SWITCH_STATUS_FALSE;
goto done;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Added proper brackets to MID = %s \n",mid);
free(dup);
return SWITCH_STATUS_SUCCESS;
status = SWITCH_STATUS_SUCCESS;
done:
return status;
}

View File

@ -18,6 +18,7 @@ static sng_mg_event_interface_t sng_event;
SWITCH_MODULE_LOAD_FUNCTION(mod_media_gateway_load);
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_media_gateway_shutdown);
SWITCH_MODULE_DEFINITION(mod_media_gateway, mod_media_gateway_load, mod_media_gateway_shutdown, NULL);
switch_status_t handle_mg_add_cmd(SuId suId, MgMgcoCommand *req, MgMgcoAmmReq *addReq);
switch_status_t mg_stack_free_mem(MgMgcoMsg* msg);
switch_status_t mg_stack_free_mem(MgMgcoMsg* msg);
@ -287,8 +288,6 @@ static switch_status_t mgco_parse_local_sdp(mg_termination_t *term, CmSdpInfoSet
}
}
/*****************************************************************************************************************************/
void handle_mgco_txn_ind(Pst *pst, SuId suId, MgMgcoMsg* msg)
{
size_t txnIter;
@ -307,7 +306,7 @@ void handle_mgco_txn_ind(Pst *pst, SuId suId, MgMgcoMsg* msg)
case MGT_TXNREQ:
{
MgMgcoTxnReq* txnReq;
MgMgcoTransId transId; /* XXX */
/*MgMgcoTransId transId; *//* XXX */
int axnIter;
txnReq = &(msg->body.u.tl.txns[txnIter]->u.req);
@ -332,14 +331,13 @@ void handle_mgco_txn_ind(Pst *pst, SuId suId, MgMgcoMsg* msg)
MgMgcoCommand mgCmd;
memset(&mgCmd, 0, sizeof(mgCmd));
mgCmd.peerId = msg->lcl.id;
mgCmd.transId = transId;
mgCmd.u.mgCmdInd[0] = cmdReq;
/* XXX Handle choose context before this */
mgCmd.contextId = ctxId;
mgCmd.transId = transId;
/*mgCmd.transId = transId;*/
mgCmd.cmdStatus.pres = PRSNT_NODEF;
@ -478,31 +476,30 @@ void handle_mgco_txn_ind(Pst *pst, SuId suId, MgMgcoMsg* msg)
/*****************************************************************************************************************************/
void handle_mgco_cmd_ind(Pst *pst, SuId suId, MgMgcoCommand* cmd)
{
uint32_t txn_id = 0x00;
U32 txn_id = 0x00;
MgMgcoInd *mgErr;
MgStr errTxt;
MgMgcoContextId ctxtId;
MgMgcoTermIdLst* termLst;
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 */
if (NOTPRSNT != cmd->transId.pres)
if (NOTPRSNT != cmd->transId.pres){
txn_id = cmd->transId.val;
else
{
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "%s: Transaction Id not present, rejecting\n", __PRETTY_FUNCTION__);
/*-- Send Error to MG Stack --*/
mg_zero(&ctxtId, sizeof(MgMgcoContextId));
MG_ZERO(&ctxtId, sizeof(MgMgcoContextId));
ctxtId.type.pres = NOTPRSNT;
ctxtId.val.pres = NOTPRSNT;
mg_util_set_txn_string(&errTxt, &txn_id);
if (SWITCH_STATUS_FALSE == mg_build_mgco_err_request(&mgErr, txn_id, &ctxtId,
MGT_MGCO_RSP_CODE_INVLD_IDENTIFIER, &errTxt))
{
if (SWITCH_STATUS_SUCCESS == mg_build_mgco_err_request(&mgErr, txn_id, &ctxtId,
MGT_MGCO_RSP_CODE_INVLD_IDENTIFIER, &errTxt)) {
sng_mgco_send_err(suId, mgErr);
}
@ -511,7 +508,16 @@ void handle_mgco_cmd_ind(Pst *pst, SuId suId, MgMgcoCommand* cmd)
return ;
}
mgAccEvntPrntMgMgcoCommand(cmd, stdout);
/* Get the termination Id list from the command(Note: GCP_2_1 has termination list , else it will be termination Id) */
termLst = mg_get_term_id_list(cmd);
if ((NULL == termLst) || (NOTPRSNT == termLst->num.pres)) {
/* termination-id not present , error */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Termination-Id Not received..rejecting command \n");
mg_free_cmd(cmd);
return ;
}
/*mgAccEvntPrntMgMgcoCommand(cmd, stdout);*/
switch(cmd->cmdType.val)
{
@ -531,6 +537,7 @@ void handle_mgco_cmd_ind(Pst *pst, SuId suId, MgMgcoCommand* cmd)
case MGT_MODIFY:
{
/*MgMgcoAmmReq *addReq = &cmdReq->cmd.u.mod;*/
mg_send_modify_rsp(suId, cmd);
break;
}
case MGT_MOVE:
@ -542,11 +549,33 @@ 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);
break;
}
case MGT_SVCCHG:
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Service-Change Method Not Yet Supported\n");
break;
}
case MGT_NTFY:
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "NOTIFY Method Not Yet Supported\n");
break;
}
case MGT_AUDITCAP:
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Audit-Capability Method Not Yet Supported\n");
break;
}
case MGT_AUDITVAL:
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received Audit-Value Method \n");
handle_mg_audit_cmd(suId, cmd);
/*need to call this for other types of audit..
* ideally from the request apis we should send response..keeping now here just to send dummy responses*/
mg_send_audit_rsp(suId, cmd);
break;
}
break;
}
@ -605,6 +634,7 @@ void handle_mgco_audit_cfm(Pst *pst, SuId suId, MgMgtAudit* audit, Reason reason
/*****************************************************************************************************************************/
/*
*
* Fun: mg_get_term_id_list
@ -1069,7 +1099,6 @@ void mg_util_set_txn_string(MgStr *errTxt, U32 *txnId)
/*****************************************************************************************************************************/
/* For Emacs:
* Local Variables:
* mode:c