From a425177bbf7805c06b8137361eefdde13d43a01e Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Thu, 6 Sep 2012 11:28:30 -0400 Subject: [PATCH 1/6] adding new "fax-detect-evevt-type" field in config --- .../mod_media_gateway/media_gateway.c | 32 ++++++++++++++++--- .../mod_media_gateway/media_gateway_xml.c | 9 ++++++ .../mod_media_gateway/mod_media_gateway.h | 26 +++++++++++++++ 3 files changed, 63 insertions(+), 4 deletions(-) diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway.c b/src/mod/endpoints/mod_media_gateway/media_gateway.c index a82a28743f..8b5d96930d 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway.c @@ -191,10 +191,34 @@ switch_status_t megaco_activate_termination(mg_termination_t *term) switch_core_event_hook_add_recv_dtmf(session, mg_on_dtmf); - if (term->type == MG_TERM_TDM) { - switch_core_session_execute_application_async(session, "spandsp_start_fax_detect", "mg_notify cng 120 cng"); - switch_core_session_execute_application_async(session, "spandsp_start_fax_detect", "mg_notify ced 120 ced"); - } + if ((term->type == MG_TERM_TDM) && (term->profile)){ + switch(term->profile->fax_detect_evt_type){ + case MG_FAX_DETECT_EVENT_TYPE_CED: + { + switch_core_session_execute_application_async(session, "spandsp_start_fax_detect", "mg_notify ced 120 ced"); + break; + } + case MG_FAX_DETECT_EVENT_TYPE_CNG: + { + switch_core_session_execute_application_async(session, "spandsp_start_fax_detect", "mg_notify cng 120 cng"); + break; + } + case MG_FAX_DETECT_EVENT_TYPE_CNG_CED: + { + switch_core_session_execute_application_async(session, "spandsp_start_fax_detect", "mg_notify cng 120 cng"); + switch_core_session_execute_application_async(session, "spandsp_start_fax_detect", "mg_notify ced 120 ced"); + break; + } + case MG_FAX_DETECT_EVENT_TYPE_DISABLE: + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "FAX detection Disable\n"); + break; + } + default: + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid FAX detection Event[%d]\n",term->profile->fax_detect_evt_type); + break; + } + } } switch_set_flag(term, MGT_ACTIVE); diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_xml.c b/src/mod/endpoints/mod_media_gateway/media_gateway_xml.c index 8b278279fe..4568030371 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_xml.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_xml.c @@ -71,6 +71,7 @@ switch_status_t config_profile(megaco_profile_t *profile, switch_bool_t reload) } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"rtp_ipaddr[%s], local ip[%s]\n", profile->rtp_ipaddr, profile->my_ipaddr); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"fax_detect_evt_type[%s]\n", mg_fax_detect_evt_type2str(profile->fax_detect_evt_type)); if(SWITCH_STATUS_FALSE == (status = modify_mg_profile_mid(profile, &profile->mid))){ goto done; @@ -337,6 +338,13 @@ static switch_xml_config_item_t *get_instructions(megaco_profile_t *profile) { { "ILBC", MEGACO_CODEC_ILBC }, }; #endif + static switch_xml_config_enum_item_t opt_fax_detect_type_enum[] = { + { "CED", MG_FAX_DETECT_EVENT_TYPE_CED}, + { "CNG", MG_FAX_DETECT_EVENT_TYPE_CNG}, + { "CED_CNG", MG_FAX_DETECT_EVENT_TYPE_CNG_CED}, + { "DISABLE", MG_FAX_DETECT_EVENT_TYPE_DISABLE}, + }; + switch_xml_config_item_t instructions[] = { /* parameter name type reloadable pointer default value options structure */ @@ -355,6 +363,7 @@ static switch_xml_config_item_t *get_instructions(megaco_profile_t *profile) { SWITCH_CONFIG_ITEM("codec-prefs", SWITCH_CONFIG_STRING, 0, &profile->codec_prefs, "", &switch_config_string_strdup, "", "codec preferences, coma-separated"), SWITCH_CONFIG_ITEM("license", SWITCH_CONFIG_STRING, 0, &profile->license, "/usr/local/nsg/conf/license.txt", &switch_config_string_strdup, "", "License file"), SWITCH_CONFIG_ITEM("rtp-ip", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &profile->rtp_ipaddr, "" , &switch_config_string_strdup, "", "rtp ip"), + SWITCH_CONFIG_ITEM("fax-detect-event-type", SWITCH_CONFIG_ENUM, CONFIG_RELOADABLE, &profile->fax_detect_evt_type, MG_FAX_DETECT_EVENT_TYPE_CNG_CED , &opt_fax_detect_type_enum, "", "fax-detect-event-type"), SWITCH_CONFIG_ITEM_END() }; diff --git a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h index b39a6ca51c..dfd1edb58e 100644 --- a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h +++ b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h @@ -150,6 +150,31 @@ static inline mg_media_type_t mg_media_type_parse(const char *str) { return MGM_INVALID; } +typedef enum { + MG_FAX_DETECT_EVENT_TYPE_NONE = 0, + MG_FAX_DETECT_EVENT_TYPE_CED, + MG_FAX_DETECT_EVENT_TYPE_CNG, + MG_FAX_DETECT_EVENT_TYPE_CNG_CED, + MG_FAX_DETECT_EVENT_TYPE_DISABLE, + MG_FAX_DETECT_EVENT_TYPE_INVALID, +} mg_fax_detect_event_type_t; + +static inline const char *mg_fax_detect_evt_type2str(mg_fax_detect_event_type_t type) { + switch (type) { + case MG_FAX_DETECT_EVENT_TYPE_CED: + return "CED"; + case MG_FAX_DETECT_EVENT_TYPE_CNG: + return "CNG"; + case MG_FAX_DETECT_EVENT_TYPE_CNG_CED: + return "CED AND CNG"; + case MG_FAX_DETECT_EVENT_TYPE_DISABLE: + return "DISABLE"; + default: + return "Invalid"; + } + return NULL; +} + struct mg_context_s { uint32_t context_id; mg_termination_t *terminations[MG_CONTEXT_MAX_TERMS]; @@ -232,6 +257,7 @@ struct megaco_profile_s { int inact_tmr; /* inactivity timer value */ int peer_active; /* inactivity timer value */ uint32_t inact_tmr_task_id; /* FS timer scheduler task-id */ + mg_fax_detect_event_type_t fax_detect_evt_type; switch_thread_rwlock_t *contexts_rwlock; uint32_t next_context_id; From 5f73d7457f2a92edf73750553b6ab983b5e0d43d Mon Sep 17 00:00:00 2001 From: Kapil Date: Thu, 6 Sep 2012 11:33:08 -0400 Subject: [PATCH 2/6] Revert "refs #5684 - make sure we retry all contexts ids if we start at the end of the list" This reverts commit 3e39945d73bc55c9bae492161e968bed239a4f4f. --- .../mod_media_gateway/media_gateway.c | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway.c b/src/mod/endpoints/mod_media_gateway/media_gateway.c index 8b5d96930d..eaf33cdcc2 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway.c @@ -569,7 +569,6 @@ mg_context_t *megaco_get_context(megaco_profile_t *profile, uint32_t context_id) mg_context_t *megaco_choose_context(megaco_profile_t *profile) { mg_context_t *ctx=NULL; - uint32_t start_id = profile->next_context_id; switch_thread_rwlock_wrlock(profile->contexts_rwlock); /* Try the next one */ @@ -577,7 +576,6 @@ mg_context_t *megaco_choose_context(megaco_profile_t *profile) profile->next_context_id = 1; } -again: /* Look for an available context */ for (; profile->next_context_id < MG_MAX_CONTEXTS; profile->next_context_id++) { if ((profile->contexts_bitmap[profile->next_context_id / 8] & (1 << (profile->next_context_id % 8))) == 0) { @@ -602,12 +600,6 @@ again: break; } } - - if (!ctx && start_id > 1) { - start_id = 1; - profile->next_context_id = 1; - goto again; - } switch_thread_rwlock_unlock(profile->contexts_rwlock); @@ -644,27 +636,19 @@ void megaco_release_context(mg_context_t *ctx) uint32_t mg_rtp_request_id(megaco_profile_t *profile) { uint32_t rtp_id = 0x00; - uint32_t start_id = profile->rtpid_next; if (profile->rtpid_next >= MG_MAX_RTPID || profile->rtpid_next == 0) { profile->rtpid_next = 1; } -again: for (; profile->rtpid_next < MG_MAX_RTPID; profile->rtpid_next++) { if ((profile->rtpid_bitmap[profile->rtpid_next / 8] & (1 << (profile->rtpid_next % 8))) == 0) { profile->rtpid_bitmap[profile->rtpid_next / 8] |= 1 << (profile->rtpid_next % 8); rtp_id = profile->rtpid_next; - profile->rtpid_next++; + profile->rtpid_next++; return rtp_id; } } - - if (start_id > 1) { - start_id = 1; - profile->rtpid_next = 1; - goto again; - } return 0; } From b285155449e6c294d63d15a5f1cf05671d70a9f4 Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Thu, 6 Sep 2012 11:52:23 -0400 Subject: [PATCH 3/6] temp fix - calling mg_choose_context api again if failure in first attempt --- .../media_gateway_cmd_handler.c | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) 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 9ed09d8b7b..1268660d82 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 @@ -631,13 +631,19 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i mg_ctxt = megaco_choose_context(mg_profile); - if(NULL == mg_ctxt){ - mg_profile->mg_stats->total_num_of_choose_ctxt_failed_error++; - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR," megaco_choose_context failed \n"); - mg_util_set_err_string(&errTxt, " Resource Failure "); - err_code = MGT_MGCO_RSP_CODE_RSRC_ERROR; - goto error; - } + if(NULL == mg_ctxt){ + /* temp fix - Calling again, just in case if this time we get context */ + mg_ctxt = megaco_choose_context(mg_profile); + if(NULL == mg_ctxt){ + mg_profile->mg_stats->total_num_of_choose_ctxt_failed_error++; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR," megaco_choose_context failed \n"); + mg_util_set_err_string(&errTxt, " Resource Failure "); + err_code = MGT_MGCO_RSP_CODE_RSRC_ERROR; + goto error; + }else{ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR," megaco_choose_context - Success in 2nd Attempt \n"); + } + } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO," Allocated Context[%p] with context_id[%d]\n", (void*)mg_ctxt, mg_ctxt->context_id); From 6381d06c23d8a50550beae2497236b98bef9bfa3 Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Thu, 6 Sep 2012 12:56:57 -0400 Subject: [PATCH 4/6] adding TUCL enable/disable logging --- .../mod_media_gateway/media_gateway_stack.c | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_stack.c b/src/mod/endpoints/mod_media_gateway/media_gateway_stack.c index 8a300ff97e..4030104c23 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_stack.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_stack.c @@ -33,6 +33,7 @@ int sng_mgco_mg_shutdown(); int sng_mgco_mg_ssap_stop(int sapId); int sng_mgco_mg_tpt_server_stop(megaco_profile_t* profile); int sng_mgco_mg_app_ssap_stop(int idx); +int mg_tucl_debug(int action); switch_status_t sng_mgco_stack_gen_cfg(); @@ -581,13 +582,15 @@ int mg_enable_logging() memset(&mgMngmt, 0, sizeof(mgMngmt)); cntrl = &mgMngmt.t.cntrl; + mg_tucl_debug(AENA); + /* initalize the post structure */ smPstInit(&pst); /* insert the destination Entity */ pst.dstEnt = ENTMG; mgMngmt.hdr.msgType = TCFG; - mgMngmt.hdr.entId.ent = ENTHI; + mgMngmt.hdr.entId.ent = ENTMG; mgMngmt.hdr.entId.inst = S_INST; mgMngmt.hdr.elmId.elmnt = STGEN; @@ -608,13 +611,15 @@ int mg_disable_logging() memset(&mgMngmt, 0, sizeof(mgMngmt)); cntrl = &mgMngmt.t.cntrl; + mg_tucl_debug(ADISIMM); + /* initalize the post structure */ smPstInit(&pst); /* insert the destination Entity */ pst.dstEnt = ENTMG; mgMngmt.hdr.msgType = TCFG; - mgMngmt.hdr.entId.ent = ENTHI; + mgMngmt.hdr.entId.ent = ENTMG; mgMngmt.hdr.entId.inst = S_INST; mgMngmt.hdr.elmId.elmnt = STGEN; @@ -625,6 +630,38 @@ int mg_disable_logging() return(sng_cntrl_mg(&pst, &mgMngmt)); } +/******************************************************************************/ +int mg_tucl_debug(int action) +{ + Pst pst; + HiMngmt cntrl; + + memset((U8 *)&pst, 0, sizeof(Pst)); + memset((U8 *)&cntrl, 0, sizeof(HiMngmt)); + + smPstInit(&pst); + + pst.dstEnt = ENTHI; + + /* prepare header */ + cntrl.hdr.msgType = TCNTRL; /* message type */ + cntrl.hdr.entId.ent = ENTHI; /* entity */ + cntrl.hdr.entId.inst = 0; /* instance */ + cntrl.hdr.elmId.elmnt = STGEN; /* General */ + + cntrl.hdr.response.selector = 0; + cntrl.hdr.response.prior = PRIOR0; + cntrl.hdr.response.route = RTESPEC; + cntrl.hdr.response.mem.region = S_REG; + cntrl.hdr.response.mem.pool = S_POOL; + + cntrl.t.cntrl.action = action; + cntrl.t.cntrl.subAction = SADBG; + cntrl.t.cntrl.ctlType.hiDbg.dbgMask = 0xFFFF; + + return (sng_cntrl_tucl (&pst, &cntrl)); +} + /******************************************************************************/ int mgco_tucl_gen_config(void) { From 2097799bf94829cd360a82cd4086ba7921847fa5 Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Thu, 6 Sep 2012 14:31:28 -0400 Subject: [PATCH 5/6] changing logtype from error to info for couple of logging prints --- .../endpoints/mod_media_gateway/media_gateway_cmd_handler.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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 1268660d82..f2673ac0c2 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 @@ -63,8 +63,6 @@ switch_status_t mg_is_ito_pkg_req(megaco_profile_t* mg_profile, MgMgcoCommand *c int descId = 0x00; MgMgcoAmmReq* desc = NULL; - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,"cmd->cmdType.val[%d]\n",cmd->cmdType.val); - if(CH_CMD_TYPE_IND != cmd->cmdType.val) return SWITCH_STATUS_FALSE; @@ -103,7 +101,7 @@ switch_status_t mg_is_ito_pkg_req(megaco_profile_t* mg_profile, MgMgcoCommand *c /* As of now only handling ito package */ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR," Requested Event descriptor\n"); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO," Requested Event descriptor\n"); if (evts->el.num.pres) numEvts = evts->el.num.val; @@ -1043,7 +1041,7 @@ switch_status_t handle_mg_modify_cmd(megaco_profile_t* mg_profile, MgMgcoCommand } if(MG_TERM_RTP == term->type){ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,"MODIFY REQUEST - Updated RTP attributes:" + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,"MODIFY REQUEST - Updated RTP attributes:" " Media_Type(%s),local_addr[%s] local_port[%d] remote_addr[%s], remote_port[%d], ptime[%d] pt[%d], " " rfc2833_pt[%d] rate[%d], codec[%s], term_id[%d]\n", mg_media_type2str(term->u.rtp.media_type), From e3de0a5c70df8af9fbd254266c969ec4c386b6e9 Mon Sep 17 00:00:00 2001 From: Kapil Gupta Date: Thu, 6 Sep 2012 14:37:36 -0400 Subject: [PATCH 6/6] logging change from ERROR to Warning [rtp.c:542 - Receive unknown command] --- src/mod/endpoints/mod_sofia/rtp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/endpoints/mod_sofia/rtp.c b/src/mod/endpoints/mod_sofia/rtp.c index a773a07590..50288a43df 100644 --- a/src/mod/endpoints/mod_sofia/rtp.c +++ b/src/mod/endpoints/mod_sofia/rtp.c @@ -539,7 +539,7 @@ static switch_status_t channel_receive_event(switch_core_session_t *session, swi } } else { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Received unknown command [%s] in event.\n", !command ? "null" : command); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Received unknown command [%s] in event.\n", !command ? "null" : command); } return SWITCH_STATUS_SUCCESS;