From a46c03ef6588f9a476838d4f17429a456364ed5b Mon Sep 17 00:00:00 2001 From: James Zhang Date: Fri, 10 Feb 2012 17:29:28 -0500 Subject: [PATCH] freetdm: fixing glare - adding configuration of glare handling rule - fixed cic status remains COLLECTING --- .../ftmod_sangoma_ss7_handle.c | 4 +- .../ftmod_sangoma_ss7_main.c | 48 ++++++++++++++----- .../ftmod_sangoma_ss7_main.h | 22 +++++++++ .../ftmod_sangoma_ss7/ftmod_sangoma_ss7_xml.c | 48 ++++++++++++++----- 4 files changed, 98 insertions(+), 24 deletions(-) diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_handle.c b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_handle.c index 84da8b95e9..2eed15e391 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_handle.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_handle.c @@ -33,6 +33,7 @@ * Contributors: * * Ricardo BarroetaveƱa + * James Zhang * */ @@ -96,7 +97,7 @@ ftdm_status_t handle_con_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circ sngss7_chan_data_t *sngss7_info = NULL; ftdm_channel_t *ftdmchan = NULL; char var[FTDM_DIGITS_LIMIT]; - + memset(var, '\0', sizeof(var)); ftdm_running_return(FTDM_FAIL); @@ -199,7 +200,6 @@ ftdm_status_t handle_con_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circ } else { SS7_INFO_CHAN(ftdmchan,"No Called party (DNIS) information in IAM!%s\n", " "); } - copy_redirgNum_from_sngss7(ftdmchan, &siConEvnt->redirgNum); copy_redirgInfo_from_sngss7(ftdmchan, &siConEvnt->redirInfo); copy_genNmb_from_sngss7(ftdmchan, &siConEvnt->genNmb); diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.c b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.c index fa36c7280a..2463d59115 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.c @@ -35,6 +35,7 @@ * * Moises Silva * David Yat Sin + * James Zhang * */ @@ -1086,14 +1087,12 @@ ftdm_status_t ftdm_sangoma_ss7_process_state_change (ftdm_channel_t *ftdmchan) /*now go to the RING state */ state_flag = 0; ftdm_set_state(ftdmchan, FTDM_CHANNEL_STATE_RING); - } else if (i >= sngss7_info->circuit->min_digits) { SS7_DEBUG_CHAN(ftdmchan, "Received %d digits (min digits = %d)\n", i, sngss7_info->circuit->min_digits); /*now go to the RING state */ state_flag = 0; ftdm_set_state(ftdmchan, FTDM_CHANNEL_STATE_RING); - } else { /* if we are coming from idle state then we have already been here once before */ if (ftdmchan->last_state != FTDM_CHANNEL_STATE_IDLE) { @@ -1101,7 +1100,7 @@ ftdm_status_t ftdm_sangoma_ss7_process_state_change (ftdm_channel_t *ftdmchan) i, sngss7_info->circuit->min_digits, ftdmchan->caller_data.dnis.digits); - + /* start ISUP t35 */ if (ftdm_sched_timer (sngss7_info->t35.sched, "t35", @@ -1530,20 +1529,47 @@ ftdm_status_t ftdm_sangoma_ss7_process_state_change (ftdm_channel_t *ftdmchan) /* check if there is a glared call that needs to be processed */ if (sngss7_test_ckt_flag(sngss7_info, FLAG_GLARE)) { - - /* clear the glare flag */ sngss7_clear_ckt_flag (sngss7_info, FLAG_GLARE); - /* check if we have an IAM stored...if we don't have one just exit */ if (sngss7_info->glare.circuit != 0) { - /* send the saved call back in to us */ - handle_con_ind (0, - sngss7_info->glare.spInstId, - sngss7_info->glare.circuit, - &sngss7_info->glare.iam); + int bHandle=0; + switch (g_ftdm_sngss7_data.cfg.glareResolution) { + case SNGSS7_GLARE_DOWN: + SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Giving control to the other side, handling copied IAM from glare. \n", sngss7_info->circuit->cic); + bHandle = 1; + break; + case SNGSS7_GLARE_PC: + SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Trying to handle IAM copied from glare. \n", sngss7_info->circuit->cic); + SS7_INFO_CHAN(ftdmchan,"[CIC:%d]My PC = %d, incoming PC = %d. \n", sngss7_info->circuit->cic, + g_ftdm_sngss7_data.cfg.isupIntf[sngss7_info->circuit->infId].spc, + g_ftdm_sngss7_data.cfg.isupIntf[sngss7_info->circuit->infId].dpc ); + + if( g_ftdm_sngss7_data.cfg.isupIntf[sngss7_info->circuit->infId].spc > g_ftdm_sngss7_data.cfg.isupIntf[sngss7_info->circuit->infId].dpc ) + { + if ((sngss7_info->circuit->cic % 2) == 1 ) { + bHandle = 1; + } + } else { + if( (sngss7_info->circuit->cic % 2) == 0 ) { + bHandle = 1; + } + } + + break; + default: /* if configured as SNGSS7_GLARE_CONTROL, always abandon incoming glared IAM. */ + bHandle = 0; + break; + } + + if (!bHandle) { + SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Handling glare IAM. \n", sngss7_info->circuit->cic); + handle_con_ind (0, sngss7_info->glare.spInstId, sngss7_info->glare.circuit, &sngss7_info->glare.iam); + } + /* clear the glare info */ memset(&sngss7_info->glare, 0x0, sizeof(sngss7_glare_data_t)); + state_flag = 0; } } diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.h b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.h index fb60183bf8..f288a78e5f 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.h +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.h @@ -29,6 +29,12 @@ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * Contributors: + * + * James Zhang + * */ /******************************************************************************/ #ifndef __FTMOD_SNG_SS7_H__ @@ -195,6 +201,21 @@ typedef struct sng_mtp2_link { uint32_t t7; } sng_mtp2_link_t; +/* defining glare handling methods: + SNGSS7_GLARE_PC: + higher PointCode controls even number CIC + lower PointCode controls odd number CIC + SNGSS7_GLARE_DOWN: + always give control to the other side + SNGSS7_GLARE_CONTROL: + always trying to control +*/ +typedef enum { + SNGSS7_GLARE_PC = 0, + SNGSS7_GLARE_DOWN, + SNGSS7_GLARE_CONTROL +} sng_glare_resolution; + typedef struct sng_mtp3_link { char name[MAX_NAME_LEN]; uint32_t flags; @@ -444,6 +465,7 @@ typedef struct sng_ss7_cfg { sng_isup_ckt_t isupCkt[10000]; /* KONRAD - only need 2000 ( and 0-1000 aren't used) since other servers are registerd else where */ sng_nsap_t nsap[MAX_NSAPS+1]; sng_isap_t isap[MAX_ISAPS+1]; + sng_glare_resolution glareResolution; } sng_ss7_cfg_t; typedef struct ftdm_sngss7_data { diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_xml.c b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_xml.c index 430b9895fe..6ea7400b37 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_xml.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_xml.c @@ -29,6 +29,12 @@ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * Contributors: + * + * James Zhang + * */ /* INCLUDE ********************************************************************/ @@ -191,6 +197,7 @@ static int ftmod_ss7_fill_in_self_route(int spc, int linkType, int switchType, i static int ftmod_ss7_fill_in_circuits(sng_span_t *sngSpan); static int ftmod_ss7_next_timeslot(char *ch_map, sng_timeslot_t *timeslot); +static void ftmod_ss7_set_glare_resolution (const char *method); /******************************************************************************/ @@ -451,6 +458,26 @@ static int ftmod_ss7_parse_sng_isup(ftdm_conf_node_t *sng_isup) return FTDM_SUCCESS; } +static void ftmod_ss7_set_glare_resolution (const char *method) +{ + sng_glare_resolution iMethod=SNGSS7_GLARE_PC; + if (!method || (strlen (method) <=0) ) { + SS7_ERROR( "Wrong glare resolution parameter, using default. \n" ); + } else { + if (!strcasecmp( method, "PointCode")) { + iMethod = SNGSS7_GLARE_PC; + } else if (!strcasecmp( method, "Down")) { + iMethod = SNGSS7_GLARE_DOWN; + } else if (!strcasecmp( method, "Control")) { + iMethod = SNGSS7_GLARE_CONTROL; + } else { + SS7_ERROR( "Wrong glare resolution parameter, using default. \n" ); + iMethod = SNGSS7_GLARE_PC; + } + } + g_ftdm_sngss7_data.cfg.glareResolution = iMethod; +} + /******************************************************************************/ static int ftmod_ss7_parse_sng_gen(ftdm_conf_node_t *sng_gen) { @@ -463,28 +490,27 @@ static int ftmod_ss7_parse_sng_gen(ftdm_conf_node_t *sng_gen) /* extract all the information from the parameters */ for (i = 0; i < num_parms; i++) { - /**************************************************************************/ - if (!strcasecmp(parm->var, "procId")) { - /**********************************************************************/ g_ftdm_sngss7_data.cfg.procId = atoi(parm->val); SS7_DEBUG("Found a procId = %d\n", g_ftdm_sngss7_data.cfg.procId); - /**********************************************************************/ - } else if (!strcasecmp(parm->var, "license")) { - /**********************************************************************/ + } + else if (!strcasecmp(parm->var, "license")) { ftdm_set_string(g_ftdm_sngss7_data.cfg.license, parm->val); snprintf(g_ftdm_sngss7_data.cfg.signature, sizeof(g_ftdm_sngss7_data.cfg.signature), "%s.sig", parm->val); SS7_DEBUG("Found license file = %s\n", g_ftdm_sngss7_data.cfg.license); SS7_DEBUG("Found signature file = %s\n", g_ftdm_sngss7_data.cfg.signature); - /**********************************************************************/ - } else if (!strcasecmp(parm->var, "transparent_iam_max_size")) { + } + else if (!strcasecmp(parm->var, "transparent_iam_max_size")) { g_ftdm_sngss7_data.cfg.transparent_iam_max_size = atoi(parm->val); SS7_DEBUG("Found a transparent_iam max size = %d\n", g_ftdm_sngss7_data.cfg.transparent_iam_max_size); - } else { - /**********************************************************************/ + } + else if (!strcasecmp(parm->var, "glare-reso")) { + ftmod_ss7_set_glare_resolution (parm->val); + SS7_DEBUG("Found glare resolution configuration = %d %s\n", g_ftdm_sngss7_data.cfg.glareResolution, parm->val ); + } + else { SS7_ERROR("Found an invalid parameter \"%s\"!\n", parm->val); return FTDM_FAIL; - /**********************************************************************/ } /* move to the next parmeter */