From 12e8e481b5789c73b60202e193967274a067f9e7 Mon Sep 17 00:00:00 2001 From: Kapil Date: Tue, 24 Jul 2012 13:34:02 -0400 Subject: [PATCH] adding API to send "In-Activity" timer expiry NOTIFY to MGC for IT/ITO package --- .../mod_media_gateway/media_gateway_cli.c | 19 ++++++ .../media_gateway_cmd_handler.c | 62 +++++++++++++++---- .../mod_media_gateway/media_gateway_stack.h | 1 + .../mod_media_gateway/media_gateway_utils.c | 36 ++++++----- .../mod_media_gateway/mod_media_gateway.c | 4 +- 5 files changed, 93 insertions(+), 29 deletions(-) diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_cli.c b/src/mod/endpoints/mod_media_gateway/media_gateway_cli.c index f249d012f4..9b575c5384 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_cli.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_cli.c @@ -142,6 +142,25 @@ switch_status_t mg_process_cli_cmd(const char *cmd, switch_stream_handle_t *stre megaco_profile_release(profile); mg_send_dtmf_notify(profile, argv[4], (char*)argv[5], (int)strlen(argv[5])); + break; + } + case 5: + { + /* mg profile send ito notify */ + if(zstr(argv[3])){ + goto usage; + } + + if(strcasecmp(argv[3],"ito")){ + stream->write_function(stream, "-ERR wrong input \n"); + goto usage; + } + + printf("Sending In-Activity NOTIFY \n"); + + megaco_profile_release(profile); + mg_send_ito_notify(profile); + break; } default: 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 12174639ae..290b21efe8 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 @@ -2134,6 +2134,36 @@ err: mgUtlDelMgMgcoSvcChgPar(&srvPar); return ret; } + +/*****************************************************************************************************************************/ +/* API to send In-Activity Timeout NOTIFY to MGC */ +switch_status_t mg_send_ito_notify(megaco_profile_t* mg_profile ) +{ + MgMgcoObsEvt *oevt; + + switch_assert(mg_profile); + + mg_stack_alloc_mem((Ptr*)&oevt, sizeof(MgMgcoObsEvt)); + + oevt->pres.pres = PRSNT_NODEF; + + mg_get_time_stamp(&oevt->time); + + MG_INIT_TOKEN_VALUE(&(oevt->pkg.pkgType), MGT_PKG_KNOWN); + + MG_INIT_TOKEN_VALUE(&(oevt->pkg.valType), MGT_PKG_KNOWN); + + MG_INIT_TOKEN_VALUE(&(oevt->pkg.u.val), MGT_PKG_INACTTIMER); + + MG_INIT_TOKEN_VALUE(&(oevt->name.type),MGT_GEN_TYPE_KNOWN); + + MG_INIT_TOKEN_VALUE(&(oevt->name.u.val),(U8)MGT_PKG_ENUM_REQEVT_INACTTIMER_INACT_TIMOUT); + + oevt->pl.num.pres = PRSNT_NODEF; + oevt->pl.num.val = 0x00; + + return mg_send_notify(mg_profile, "ROOT", oevt); +} /*****************************************************************************************************************************/ /* API to send DTMF Digits Notification */ @@ -2255,23 +2285,29 @@ switch_status_t mg_send_notify(megaco_profile_t* mg_profile, const char* term_n MG_ZERO(&request, sizeof(request)); MG_ZERO(&reqId, sizeof(reqId)); - term = megaco_find_termination(mg_profile, (char*)term_name); + if(strcmp(term_name, "ROOT")){ + /* Not ROOT term then --- */ + term = megaco_find_termination(mg_profile, (char*)term_name); - if(!term){ - switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "No termination configured for given name[%s] !\n", term_name); - return SWITCH_STATUS_FALSE; - } + if(!term){ + switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "No termination configured for given name[%s] !\n", term_name); + return SWITCH_STATUS_FALSE; + } - if(NULL == term->active_events){ - switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "No Active events observed on given termination[%s] !\n", term_name); - /* return SWITCH_STATUS_FALSE; */ - /*TODO - ideally we should return ... - * as of now not returning .. if we dont have active signals then - * setting default request id and sending notification to MGC */ - MG_SET_DEF_REQID(&reqId); + if(NULL == term->active_events){ + switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO, "No Active events observed on given termination[%s] !\n", term_name); + /* return SWITCH_STATUS_FALSE; */ + /*TODO - ideally we should return ... + * as of now not returning .. if we dont have active signals then + * setting default request id and sending notification to MGC */ + MG_SET_DEF_REQID(&reqId); + }else{ + MG_MEM_COPY(&reqId, &term->active_events->reqId, sizeof(MgMgcoRequestId)); + } }else{ - MG_MEM_COPY(&reqId, &term->active_events->reqId, sizeof(MgMgcoRequestId)); + MG_SET_DEF_REQID(&reqId); } + if(SWITCH_STATUS_FALSE == (ret = mg_create_mgco_command(&request, CH_CMD_TYPE_REQ, MGT_NTFY))){ 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 f308496b1e..d5b82a5b54 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_stack.h +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_stack.h @@ -183,6 +183,7 @@ switch_status_t mg_send_oos_service_change(megaco_profile_t* mg_profile, const c switch_status_t mg_send_ins_service_change(megaco_profile_t* mg_profile, const char* term_name, int wild); switch_status_t mg_send_notify(megaco_profile_t* mg_profile, const char* term_name, MgMgcoObsEvt* oevt); switch_status_t mg_send_dtmf_notify(megaco_profile_t* mg_profile, const char* term_name, char* digits, int num_of_collected_digits); +switch_status_t mg_send_ito_notify(megaco_profile_t* mg_profile); switch_status_t mg_util_build_obs_evt_desc (MgMgcoObsEvt *obs_event, MgMgcoRequestId *request_id, MgMgcoObsEvtDesc **ptr_obs_desc); 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 b6751c6eea..d521823005 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_utils.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_utils.c @@ -96,27 +96,33 @@ S16 mg_fill_mgco_termid ( MgMgcoTermId *termId, char* term_str, int term_len, C S16 ret = ROK; termId->type.pres = PRSNT_NODEF; - termId->type.val = MGT_TERMID_OTHER; - termId->name.dom.pres = NOTPRSNT; - termId->name.dom.len = 0x00; + if(!strcmp(term_str,"ROOT")){ + /* ROOT Termination */ + termId->type.val = MGT_TERMID_ROOT; + } else { + termId->type.val = MGT_TERMID_OTHER; - termId->name.pres.pres = PRSNT_NODEF; - termId->name.lcl.pres = PRSNT_NODEF; - termId->name.lcl.len = term_len; - /*MG_GETMEM(termId->name.lcl.val, termId->name.lcl.len , memCp, ret);*/ - ret = mg_stack_alloc_mem((Ptr*)&termId->name.lcl.val,term_len); + termId->name.dom.pres = NOTPRSNT; + termId->name.dom.len = 0x00; - printf("termId->name.lcl.val[%p]\n",termId->name.lcl.val); + termId->name.pres.pres = PRSNT_NODEF; + termId->name.lcl.pres = PRSNT_NODEF; + termId->name.lcl.len = term_len; + /*MG_GETMEM(termId->name.lcl.val, termId->name.lcl.len , memCp, ret);*/ + ret = mg_stack_alloc_mem((Ptr*)&termId->name.lcl.val,term_len); - if( ret != ROK) - RETVALUE(ret); + printf("termId->name.lcl.val[%p]\n",termId->name.lcl.val); - /*cmMemcpy((U8*)(termId->name.lcl.val), (CONSTANT U8*)term_str,termId->name.lcl.len);*/ - strncpy((char*)(termId->name.lcl.val), term_str, termId->name.lcl.len); - termId->name.lcl.val[termId->name.lcl.len] = '\0'; + if( ret != ROK) + RETVALUE(ret); - printf("mg_fill_mgco_termid: name.lcl.val[%s], len[%d], term_str[%s], term_len[%d]\n",termId->name.lcl.val, termId->name.lcl.len, term_str,term_len); + /*cmMemcpy((U8*)(termId->name.lcl.val), (CONSTANT U8*)term_str,termId->name.lcl.len);*/ + strncpy((char*)(termId->name.lcl.val), term_str, termId->name.lcl.len); + termId->name.lcl.val[termId->name.lcl.len] = '\0'; + + printf("mg_fill_mgco_termid: name.lcl.val[%s], len[%d], term_str[%s], term_len[%d]\n",termId->name.lcl.val, termId->name.lcl.len, term_str,term_len); + } #ifdef GCP_ASN 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 03a61104ec..4394a86184 100644 --- a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.c +++ b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.c @@ -613,6 +613,7 @@ void handle_mgco_cmd_ind(Pst *pst, SuId suId, MgMgcoCommand* cmd) } case CH_CMD_TYPE_CFM: { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Received Command txn[%d] Response/Confirmation \n",txn_id); break; } default: @@ -623,7 +624,8 @@ void handle_mgco_cmd_ind(Pst *pst, SuId suId, MgMgcoCommand* cmd) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "cmd->cmdStatus.val[%d]\n",cmd->cmdStatus.val); /* 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)*/{ + if(CH_CMD_TYPE_IND == cmd->cmdType.val){ + /*if(CH_CMD_STATUS_END_OF_TXN == cmd->cmdStatus.val)*/ mg_send_end_of_axn(suId, &cmd->transId, &out_ctxt, &cmd->peerId); }