From 8c8d649221b6d700d9738c619ceef0689aa0e134 Mon Sep 17 00:00:00 2001 From: James Zhang Date: Thu, 16 Feb 2012 15:14:06 -0500 Subject: [PATCH] freetdm: Add support to set/receive location and original call number SS7 elements through variables (including SIP X headers) --- libs/freetdm/mod_freetdm/mod_freetdm.c | 55 ++++++++++++- .../ftmod_sangoma_ss7_main.h | 3 + .../ftmod_sangoma_ss7/ftmod_sangoma_ss7_out.c | 21 ++++- .../ftmod_sangoma_ss7_support.c | 81 ++++++++++++++++--- 4 files changed, 148 insertions(+), 12 deletions(-) diff --git a/libs/freetdm/mod_freetdm/mod_freetdm.c b/libs/freetdm/mod_freetdm/mod_freetdm.c index b78cc078d4..01d7c282c3 100755 --- a/libs/freetdm/mod_freetdm/mod_freetdm.c +++ b/libs/freetdm/mod_freetdm/mod_freetdm.c @@ -1400,6 +1400,22 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi ftdm_set_string(caller_data.loc.digits, sipvar); } + sipvar = switch_channel_get_variable(channel, "sip_h_X-FreeTDM-LOC-Screen"); + if (sipvar) { + ftdm_usrmsg_add_var(&usrmsg, "ss7_loc_screen_ind", sipvar); + } + + sipvar = switch_channel_get_variable(channel, "sip_h_X-FreeTDM-LOC-Presentation"); + if (sipvar) { + ftdm_usrmsg_add_var(&usrmsg, "ss7_loc_pres_ind", sipvar); + } + + sipvar = switch_channel_get_variable(channel, "sip_h_X-FreeTDM-LOC-NADI"); + if (sipvar) { + ftdm_usrmsg_add_var(&usrmsg, "ss7_loc_nadi", sipvar); + } + + sipvar = switch_channel_get_variable(channel, "sip_h_X-FreeTDM-DNIS-TON"); if (sipvar) { caller_data.dnis.type = (uint8_t)atoi(sipvar); @@ -1514,6 +1530,24 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi if (sipvar) { ftdm_usrmsg_add_var(&usrmsg, "ss7_rdinfo_reason", sipvar); } + + + sipvar = switch_channel_get_variable(channel, "sip_h_X-FreeTDM-OCN"); + if (sipvar) { + ftdm_usrmsg_add_var(&usrmsg, "ss7_ocn", sipvar); + } + sipvar = switch_channel_get_variable(channel, "sip_h_X-FreeTDM-OCN-NADI"); + if (sipvar) { + ftdm_usrmsg_add_var(&usrmsg, "ss7_ocn_nadi", sipvar); + } + sipvar = switch_channel_get_variable(channel, "sip_h_X-FreeTDM-OCN-Plan"); + if (sipvar) { + ftdm_usrmsg_add_var(&usrmsg, "ss7_ocn_plan", sipvar); + } + sipvar = switch_channel_get_variable(channel, "sip_h_X-FreeTDM-OCN-Presentation"); + if (sipvar) { + ftdm_usrmsg_add_var(&usrmsg, "ss7_ocn_pres", sipvar); + } } if (switch_test_flag(outbound_profile, SWITCH_CPF_SCREEN)) { @@ -1944,10 +1978,29 @@ ftdm_status_t ftdm_channel_from_event(ftdm_sigmsg_t *sigmsg, switch_core_session } var_value = ftdm_sigmsg_get_var(sigmsg, "ss7_loc_nadi"); - printf ( "ss7_loc_nadi = %s \n " , var_value ); if (!ftdm_strlen_zero(var_value)) { switch_channel_set_variable_printf(channel, "sip_h_X-FreeTDM-LOC-NADI", "%s", var_value); } + + var_value = ftdm_sigmsg_get_var(sigmsg, "ss7_ocn"); + if (!ftdm_strlen_zero(var_value)) { + switch_channel_set_variable_printf(channel, "sip_h_X-FreeTDM-OCN", "%s", var_value); + } + + var_value = ftdm_sigmsg_get_var(sigmsg, "ss7_ocn_nadi"); + if (!ftdm_strlen_zero(var_value)) { + switch_channel_set_variable_printf(channel, "sip_h_X-FreeTDM-OCN-NADI", "%s", var_value); + } + + var_value = ftdm_sigmsg_get_var(sigmsg, "ss7_ocn_plan"); + if (!ftdm_strlen_zero(var_value)) { + switch_channel_set_variable_printf(channel, "sip_h_X-FreeTDM-OCN-Plan", "%s", var_value); + } + + var_value = ftdm_sigmsg_get_var(sigmsg, "ss7_ocn_pres"); + if (!ftdm_strlen_zero(var_value)) { + switch_channel_set_variable_printf(channel, "sip_h_X-FreeTDM-OCN-Presentation", "%s", var_value); + } } /* Add any call variable to the dial plan */ 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..86cdc73bc9 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 @@ -868,6 +868,9 @@ ftdm_status_t copy_redirgNum_to_sngss7(ftdm_channel_t *ftdmchan, SiRedirNum *red ftdm_status_t copy_redirgNum_from_sngss7(ftdm_channel_t *ftdmchan, SiRedirNum *redirgNum); ftdm_status_t copy_redirgInfo_from_sngss7(ftdm_channel_t *ftdmchan, SiRedirInfo *redirInfo); ftdm_status_t copy_redirgInfo_to_sngss7(ftdm_channel_t *ftdmchan, SiRedirInfo *redirInfo); +ftdm_status_t copy_ocn_to_sngss7(ftdm_channel_t *ftdmchan, SiOrigCdNum *origCdNum); +ftdm_status_t copy_ocn_from_sngss7(ftdm_channel_t *ftdmchan, SiOrigCdNum *origCdNum); + ftdm_status_t copy_locPtyNum_to_sngss7(ftdm_channel_t *ftdmchan, SiCgPtyNum *locPtyNum); ftdm_status_t copy_locPtyNum_from_sngss7(ftdm_channel_t *ftdmchan, SiCgPtyNum *locPtyNum); diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_out.c b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_out.c index 7ad510079f..930457c7c8 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_out.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_out.c @@ -135,6 +135,11 @@ void ft_to_sngss7_iam (ftdm_channel_t * ftdmchan) /* Redirecting Information */ copy_redirgInfo_to_sngss7(ftdmchan, &iam.redirInfo); } + + if (iam.origCdNum.eh.pres != PRSNT_NODEF) { + /* Original Called Number */ + copy_ocn_to_sngss7(ftdmchan, &iam.origCdNum); + } } /* since this is the first time we dequeue an event from the peer, make sure our main thread process any other events, this will trigger the interrupt in our span peer_chans queue which will wake up our main thread if it is sleeping */ @@ -157,6 +162,9 @@ void ft_to_sngss7_iam (ftdm_channel_t * ftdmchan) /* Forward Call Indicators */ copy_fwdCallInd_to_sngss7(ftdmchan, &iam.fwdCallInd); + + /* Original Called Number */ + copy_ocn_to_sngss7(ftdmchan, &iam.origCdNum); } else { /* Nature of Connection Indicators */ copy_natConInd_to_sngss7(ftdmchan, &iam.natConInd); @@ -193,6 +201,8 @@ void ft_to_sngss7_iam (ftdm_channel_t * ftdmchan) /* Redirecting Information */ copy_redirgInfo_to_sngss7(ftdmchan, &iam.redirInfo); + /* Original Called Number */ + copy_ocn_to_sngss7(ftdmchan, &iam.origCdNum); /* Access Transport */ copy_accTrnspt_to_sngss7(ftdmchan, &iam.accTrnspt); @@ -236,6 +246,7 @@ void ft_to_sngss7_acm (ftdm_channel_t * ftdmchan) sngss7_chan_data_t *sngss7_info = ftdmchan->call_data; SiCnStEvnt acm; + const char *backwardInd = NULL; memset (&acm, 0x0, sizeof (acm)); @@ -253,8 +264,16 @@ void ft_to_sngss7_acm (ftdm_channel_t * ftdmchan) acm.bckCallInd.intInd.val = INTIND_NOINTW; acm.bckCallInd.end2EndInfoInd.pres = PRSNT_NODEF; acm.bckCallInd.end2EndInfoInd.val = E2EINF_NOINFO; + acm.bckCallInd.isdnUsrPrtInd.pres = PRSNT_NODEF; - acm.bckCallInd.isdnUsrPrtInd.val = ISUP_USED; + acm.bckCallInd.isdnUsrPrtInd.val = ISUP_NOTUSED; + backwardInd = ftdm_usrmsg_get_var(ftdmchan->usrmsg, "acm_bi_iup"); + ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "Found user supplied backward indicator ISDN user part indicator ACM, value \"%s\"\n", backwardInd); + if (!ftdm_strlen_zero(backwardInd)) { + if (atoi(backwardInd) != 0 ) { + acm.bckCallInd.isdnUsrPrtInd.val = ISUP_USED; + } + } acm.bckCallInd.holdInd.pres = PRSNT_NODEF; acm.bckCallInd.holdInd.val = HOLD_NOTREQD; acm.bckCallInd.isdnAccInd.pres = PRSNT_NODEF; diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_support.c b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_support.c index 2088f240b6..4557c00a10 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_support.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_support.c @@ -259,20 +259,20 @@ ftdm_status_t copy_locPtyNum_to_sngss7(ftdm_channel_t *ftdmchan, SiCgPtyNum *loc locPtyNum->scrnInd.pres = pres_val; val = ftdm_usrmsg_get_var(ftdmchan->usrmsg, "ss7_loc_screen_ind"); if (!ftdm_strlen_zero(val)) { - locPtyNum->scrnInd.val = atoi(val); + locPtyNum->scrnInd.val = atoi(val); + ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "Found user supplied Location Screening Ind %d\n", locPtyNum->scrnInd.val); } else { - locPtyNum->scrnInd.val = caller_data->screen; + locPtyNum->scrnInd.val = caller_data->screen; } - ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "Location Reference Code Screening Ind %d\n", locPtyNum->scrnInd.val); locPtyNum->presRest.pres = pres_val; - val = ftdm_usrmsg_get_var(ftdmchan->usrmsg, "ss7_pres_ind"); + val = ftdm_usrmsg_get_var(ftdmchan->usrmsg, "ss7_loc_pres_ind"); if (!ftdm_strlen_zero(val)) { - locPtyNum->presRest.val = atoi(val); + locPtyNum->presRest.val = atoi(val); + ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "Found user supplied Location Presentation Ind %d\n", locPtyNum->presRest.val); } else { - locPtyNum->presRest.val = caller_data->pres; + locPtyNum->presRest.val = caller_data->pres; } - ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "Calling Party Number Presentation Ind %d\n", locPtyNum->presRest.val); locPtyNum->numPlan.pres = pres_val; locPtyNum->numPlan.val = 0x01; @@ -286,11 +286,10 @@ ftdm_status_t copy_locPtyNum_to_sngss7(ftdm_channel_t *ftdmchan, SiCgPtyNum *loc ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "Found user supplied Location Reference NADI value \"%s\"\n", loc_nadi); locPtyNum->natAddrInd.val = atoi(loc_nadi); } else { + ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "No user supplied NADI value found for LOC, using \"%d\"\n", locPtyNum->natAddrInd.val); locPtyNum->natAddrInd.val = g_ftdm_sngss7_data.cfg.isupCkt[sngss7_info->circuit->id].loc_nadi; locPtyNum->natAddrInd.val = 0x03; - ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "No user supplied NADI value found for LOC, using \"%d\"\n", locPtyNum->natAddrInd.val); } - ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "Location Reference Presentation Ind %d\n", locPtyNum->presRest.val); return copy_tknStr_to_sngss7(caller_data->loc.digits, &locPtyNum->addrSig, &locPtyNum->oddEven); } @@ -439,7 +438,7 @@ ftdm_status_t copy_redirgNum_to_sngss7(ftdm_channel_t *ftdmchan, SiRedirNum *red return FTDM_FAIL; } } else if (!ftdm_strlen_zero(caller_data->rdnis.digits)) { - ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "Found user supplied Redirection Number\"%s\"\n", val); + ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "Found user supplied Redirection Number\"%s\"\n", caller_data->rdnis.digits); if (copy_tknStr_to_sngss7(caller_data->rdnis.digits, &redirgNum->addrSig, &redirgNum->oddEven) != FTDM_SUCCESS) { return FTDM_FAIL; } @@ -639,6 +638,68 @@ ftdm_status_t copy_redirgInfo_to_sngss7(ftdm_channel_t *ftdmchan, SiRedirInfo *r return FTDM_SUCCESS; } +ftdm_status_t copy_ocn_from_sngss7(ftdm_channel_t *ftdmchan, SiOrigCdNum *origCdNum) +{ + return FTDM_FAIL; +} + +ftdm_status_t copy_ocn_to_sngss7(ftdm_channel_t *ftdmchan, SiOrigCdNum *origCdNum) +{ + + const char *val = NULL; + int bProceed = 0; + + val = ftdm_usrmsg_get_var(ftdmchan->usrmsg, "ss7_ocn"); + if (!ftdm_strlen_zero(val)) { + ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "Found user supplied Original Called Number \"%s\"\n", val); + if (copy_tknStr_to_sngss7((char*)val, &origCdNum->addrSig, &origCdNum->oddEven) != FTDM_SUCCESS) { + return FTDM_FAIL; + } + origCdNum->addrSig.pres = 1; + } else { + return FTDM_SUCCESS; + } + + val = ftdm_usrmsg_get_var(ftdmchan->usrmsg, "ss7_ocn_nadi"); + if (!ftdm_strlen_zero(val)) { + origCdNum->natAddr.val = atoi(val); + origCdNum->natAddr.pres = 1; + ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "Found user supplied Original Called Number NADI value \"%s\"\n", val); + bProceed = 1; + } else { + ftdm_log_chan_msg(ftdmchan, FTDM_LOG_DEBUG, "No user supplied Original Called Number NADI value\n"); + } + + val = ftdm_usrmsg_get_var(ftdmchan->usrmsg, "ss7_ocn_plan"); + if (!ftdm_strlen_zero(val)) { + origCdNum->numPlan.val = atoi(val); + origCdNum->numPlan.pres = 1; + ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "Found user supplied Original Called Number Plan value \"%s\"\n", val); + bProceed = 1; + } else { + ftdm_log_chan_msg(ftdmchan, FTDM_LOG_DEBUG, "No user supplied Original Called Number Plan value\n"); + } + + val = ftdm_usrmsg_get_var(ftdmchan->usrmsg, "ss7_ocn_pres"); + if (!ftdm_strlen_zero(val)) { + origCdNum->presRest.val = atoi(val); + origCdNum->presRest.pres = 1; + ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "Found user supplied Original Called Number Presentation value \"%s\"\n", val); + bProceed = 1; + } else { + ftdm_log_chan_msg(ftdmchan, FTDM_LOG_DEBUG, "No user supplied Original Called Number Presentation value\n"); + } + + if( bProceed == 1 ) { + origCdNum->eh.pres = PRSNT_NODEF; + } else { + origCdNum->eh.pres = NOTPRSNT; + } + + + return FTDM_SUCCESS; +} + ftdm_status_t copy_cgPtyCat_to_sngss7(ftdm_channel_t *ftdmchan, SiCgPtyCat *cgPtyCat) { ftdm_caller_data_t *caller_data = &ftdmchan->caller_data;