From 4b25044ac6043b4a411a62d0d28ceb4b50cc95b2 Mon Sep 17 00:00:00 2001 From: Nenad Corbic Date: Thu, 3 Nov 2011 20:04:26 -0400 Subject: [PATCH] freetdm: Made CPG optional on configuration file Fixes in hw alarm - no need to set hw unblock if hw block did not execute yet. Minor bug fixes --- .../ftmod_sangoma_ss7/ftmod_sangoma_ss7_cfg.c | 2 +- .../ftmod_sangoma_ss7_main.c | 47 ++++++++++++++++--- .../ftmod_sangoma_ss7_main.h | 12 ++++- .../ftmod_sangoma_ss7/ftmod_sangoma_ss7_xml.c | 12 +++++ 4 files changed, 64 insertions(+), 9 deletions(-) diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_cfg.c b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_cfg.c index a9b4136665..e51428acaa 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_cfg.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_cfg.c @@ -94,7 +94,7 @@ int ft_to_sngss7_cfg_all(void) /* set the desired procID value */ sng_set_procId((uint16_t)g_ftdm_sngss7_data.cfg.procId); } - + /* start up the stack manager */ if (sng_isup_init_sm()) { SS7_CRITICAL("Failed to start Stack Manager\n"); 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 c4854f860c..cd7f3ad58e 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 @@ -308,10 +308,14 @@ static void handle_hw_alarm(ftdm_event_t *e) } } else if (e->enum_id == FTDM_OOB_ALARM_CLEAR) { SS7_DEBUG("handle_hw_alarm: Clear\n"); - sngss7_set_ckt_blk_flag(ss7_info, FLAG_GRP_HW_UNBLK_TX); - SS7_DEBUG("handle_hw_alarm: Setting FLAG_GRP_HW_UNBLK_TX\n"); - if (ftdmchan->state != FTDM_CHANNEL_STATE_SUSPENDED) { - ftdm_set_state(ftdmchan, FTDM_CHANNEL_STATE_SUSPENDED); + sngss7_clear_ckt_blk_flag(ss7_info, FLAG_GRP_HW_BLOCK_TX); + sngss7_clear_ckt_blk_flag(ss7_info, FLAG_GRP_HW_UNBLK_TX); + if (sngss7_test_ckt_blk_flag(ss7_info, FLAG_GRP_HW_BLOCK_TX_DN)) { + sngss7_set_ckt_blk_flag(ss7_info, FLAG_GRP_HW_UNBLK_TX); + SS7_DEBUG("handle_hw_alarm: Setting FLAG_GRP_HW_UNBLK_TX\n"); + if (ftdmchan->state != FTDM_CHANNEL_STATE_SUSPENDED) { + ftdm_set_state(ftdmchan, FTDM_CHANNEL_STATE_SUSPENDED); + } } } } @@ -737,6 +741,12 @@ ftdm_status_t ftdm_sangoma_ss7_process_state_change (ftdm_channel_t * ftdmchan) sngss7_set_ckt_flag(sngss7_info, FLAG_SENT_ACM); ft_to_sngss7_acm(ftdmchan); } + if (g_ftdm_sngss7_data.cfg.isupCkt[sngss7_info->circuit->id].cpg_on_progress == FTDM_TRUE) { + if (!sngss7_test_ckt_flag(sngss7_info, FLAG_SENT_CPG)) { + sngss7_set_ckt_flag(sngss7_info, FLAG_SENT_CPG); + ft_to_sngss7_cpg(ftdmchan); + } + } } break; @@ -756,7 +766,12 @@ ftdm_status_t ftdm_sangoma_ss7_process_state_change (ftdm_channel_t * ftdmchan) sngss7_set_ckt_flag(sngss7_info, FLAG_SENT_ACM); ft_to_sngss7_acm(ftdmchan); } - ft_to_sngss7_cpg(ftdmchan); + if (g_ftdm_sngss7_data.cfg.isupCkt[sngss7_info->circuit->id].cpg_on_progress_media == FTDM_TRUE) { + if (!sngss7_test_ckt_flag(sngss7_info, FLAG_SENT_CPG)) { + sngss7_set_ckt_flag(sngss7_info, FLAG_SENT_CPG); + ft_to_sngss7_cpg(ftdmchan); + } + } } break; @@ -973,7 +988,10 @@ ftdm_status_t ftdm_sangoma_ss7_process_state_change (ftdm_channel_t * ftdmchan) /* all flags are down so we can bring up the sig status */ sngss7_set_sig_status(sngss7_info, FTDM_SIG_STATE_UP); } /* if (!ftdm_test_flag (ftdmchan, FTDM_CHANNEL_SIG_UP)) */ - } /* if !blocked */ + } else { + state_flag = 0; + ftdm_set_state(ftdmchan, FTDM_CHANNEL_STATE_SUSPENDED); + } /* if !blocked */ } else { SS7_DEBUG_CHAN(ftdmchan,"Reset flags present (0x%X)\n", sngss7_info->ckt_flags); @@ -998,6 +1016,7 @@ ftdm_status_t ftdm_sangoma_ss7_process_state_change (ftdm_channel_t * ftdmchan) sngss7_clear_ckt_flag (sngss7_info, FLAG_REMOTE_REL); sngss7_clear_ckt_flag (sngss7_info, FLAG_LOCAL_REL); sngss7_clear_ckt_flag (sngss7_info, FLAG_SENT_ACM); + sngss7_clear_ckt_flag (sngss7_info, FLAG_SENT_CPG); if (ftdm_test_flag (ftdmchan, FTDM_CHANNEL_OPEN)) { @@ -1162,6 +1181,22 @@ ftdm_status_t ftdm_sangoma_ss7_process_state_change (ftdm_channel_t * ftdmchan) /* clear the PAUSE flag */ sngss7_clear_ckt_flag(sngss7_info, FLAG_INFID_PAUSED); + /* We have transmitted Reset/GRS but have not gotten a + * Response. In mean time we got a RESUME. We cannot be sure + * that our reset has been trasmitted, thus restart reset procedure. */ + if (sngss7_tx_reset_status_pending(sngss7_info)) { + SS7_DEBUG_CHAN(ftdmchan, "Channel transmitted RSC/GRS before RESUME, restart Reset procedure%s\n", ""); + clear_rx_grs_flags(sngss7_info); + clear_rx_grs_data(sngss7_info); + clear_tx_grs_flags(sngss7_info); + clear_tx_grs_data(sngss7_info); + clear_rx_rsc_flags(sngss7_info); + clear_tx_rsc_flags(sngss7_info); + + clear_tx_rsc_flags(sngss7_info); + sngss7_set_ckt_flag(sngss7_info, FLAG_RESET_TX); + } + /* if there are any resets present */ if (!sngss7_channel_status_clear(sngss7_info)) { /* don't bring up the sig status but also move to reset */ 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 4a0f6026c7..4a0a331594 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 @@ -342,6 +342,8 @@ typedef struct sng_isup_ckt { uint32_t min_digits; uint8_t itx_auto_reply; uint8_t transparent_iam; + uint8_t cpg_on_progress_media; + uint8_t cpg_on_progress; void *obj; uint16_t t3; uint32_t t10; @@ -534,6 +536,7 @@ typedef enum { FLAG_INFID_RESUME = (1 << 14), FLAG_INFID_PAUSED = (1 << 15), FLAG_SENT_ACM = (1 << 16), + FLAG_SENT_CPG = (1 << 17), FLAG_RELAY_DOWN = (1 << 30), FLAG_CKT_RECONFIG = (1 << 31) } sng_ckt_flag_t; @@ -542,14 +545,14 @@ typedef enum { "RX_RSC", \ "TX_RSC", \ "TX_RSC_REQ_SENT", \ - "TX_RSC_RSP_RECIEVED", \ + "TX_RSC_RSP_RECEIVED", \ "RX_GRS", \ "RX_GRS_DONE", \ "RX_GRS_CMPLT", \ "GRS_BASE", \ "TX_GRS", \ "TX_GRS_REQ_SENT", \ - "TX_GRS_RSP_RECIEVED", \ + "TX_GRS_RSP_RECEIVED", \ "REMOTE_REL", \ "LOCAL_REL", \ "GLARE", \ @@ -1058,6 +1061,11 @@ if (ftdmchan->state == new_state) { \ FLAG_GRP_RESET_TX | \ FLAG_GRP_RESET_RX ))) +#define sngss7_tx_reset_status_pending(obj) ((sngss7_test_ckt_flag(obj, (FLAG_RESET_TX)) && \ + sngss7_test_ckt_flag(obj, (FLAG_RESET_SENT))) || \ + (sngss7_test_ckt_flag(obj, (FLAG_GRP_RESET_TX)) && \ + sngss7_test_ckt_flag(obj, (FLAG_GRP_RESET_SENT)))) + #define sngss7_channel_status_clear(obj) ((sngss7_block_status_clear(obj)) && (sngss7_reset_status_clear(obj))) 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 8f29c55efe..045c1835ef 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 @@ -128,6 +128,8 @@ typedef struct sng_ccSpan uint32_t min_digits; uint8_t itx_auto_reply; uint8_t transparent_iam; + uint8_t cpg_on_progress_media; + uint8_t cpg_on_progress; uint32_t t3; uint32_t t10; uint32_t t12; @@ -1906,6 +1908,14 @@ static int ftmod_ss7_parse_cc_span(ftdm_conf_node_t *cc_span) sng_ccSpan.transparent_iam = ftdm_true(parm->val); SS7_DEBUG("Found transparent_iam %d\n", sng_ccSpan.transparent_iam); #endif + } else if (!strcasecmp(parm->var, "cpg_on_progress_media")) { + sng_ccSpan.cpg_on_progress_media = ftdm_true(parm->val); + SS7_DEBUG("Found cpg_on_progress_media %d\n", sng_ccSpan.cpg_on_progress_media); + + } else if (!strcasecmp(parm->var, "cpg_on_progress")) { + sng_ccSpan.cpg_on_progress = ftdm_true(parm->val); + SS7_DEBUG("Found cpg_on_progress_media %d\n", sng_ccSpan.cpg_on_progress); + } else if (!strcasecmp(parm->var, "cicbase")) { /**********************************************************************/ sng_ccSpan.cicbase = atoi(parm->val); @@ -2941,6 +2951,8 @@ static int ftmod_ss7_fill_in_ccSpan(sng_ccSpan_t *ccSpan) g_ftdm_sngss7_data.cfg.isupCkt[x].min_digits = ccSpan->min_digits; g_ftdm_sngss7_data.cfg.isupCkt[x].itx_auto_reply = ccSpan->itx_auto_reply; g_ftdm_sngss7_data.cfg.isupCkt[x].transparent_iam = ccSpan->transparent_iam; + g_ftdm_sngss7_data.cfg.isupCkt[x].cpg_on_progress_media = ccSpan->cpg_on_progress_media; + g_ftdm_sngss7_data.cfg.isupCkt[x].cpg_on_progress = ccSpan->cpg_on_progress; if (ccSpan->t3 == 0) { g_ftdm_sngss7_data.cfg.isupCkt[x].t3 = 1200;