root/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_handle.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. handle_con_ind
  2. handle_con_sta
  3. handle_con_cfm
  4. handle_rel_ind
  5. handle_rel_cfm
  6. handle_dat_ind
  7. handle_fac_ind
  8. handle_fac_cfm
  9. handle_umsg_ind
  10. handle_sta_ind
  11. handle_reattempt
  12. handle_pause
  13. handle_resume
  14. handle_cot_start
  15. handle_cot_stop
  16. handle_cot
  17. handle_blo_req
  18. handle_blo_rsp
  19. handle_ubl_req
  20. handle_ubl_rsp
  21. handle_rsc_req
  22. handle_local_rsc_req
  23. handle_rsc_rsp
  24. handle_grs_req
  25. handle_grs_rsp
  26. handle_local_blk
  27. handle_local_ubl
  28. handle_ucic
  29. handle_cgb_req
  30. handle_cgu_req

   1 /*
   2  * Copyright (c) 2009 Konrad Hammel <konrad@sangoma.com>
   3  * All rights reserved.
   4  *
   5  * Redistribution and use in source and binary forms|with or without
   6  * modification|are permitted provided that the following conditions
   7  * are met:
   8  *
   9  * * Redistributions of source code must retain the above copyright
  10  * notice|this list of conditions and the following disclaimer.
  11  *
  12  * * Redistributions in binary form must reproduce the above copyright
  13  * notice|this list of conditions and the following disclaimer in the
  14  * documentation and/or other materials provided with the distribution.
  15  *
  16  * * Neither the name of the original author; nor the names of any contributors
  17  * may be used to endorse or promote products derived from this software
  18  * without specific prior written permission.
  19  *
  20  *
  21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES|INCLUDING|BUT NOT
  23  * LIMITED TO|THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER
  25  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT|INDIRECT|INCIDENTAL|SPECIAL,
  26  * EXEMPLARY|OR CONSEQUENTIAL DAMAGES (INCLUDING|BUT NOT LIMITED TO,
  27  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE|DATA|OR
  28  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29  * LIABILITY|WHETHER IN CONTRACT|STRICT LIABILITY|OR TORT (INCLUDING
  30  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31  * SOFTWARE|EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32  */
  33 
  34 /* INCLUDE ********************************************************************/
  35 #include "ftmod_sangoma_ss7_main.h"
  36 /******************************************************************************/
  37 
  38 /* DEFINES ********************************************************************/
  39 /******************************************************************************/
  40 
  41 /* GLOBALS ********************************************************************/
  42 /******************************************************************************/
  43 
  44 /* PROTOTYPES *****************************************************************/
  45 ftdm_status_t handle_con_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiConEvnt *siConEvnt);
  46 ftdm_status_t handle_con_sta(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiCnStEvnt *siCnStEvnt, uint8_t evntType);
  47 ftdm_status_t handle_con_cfm(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiConEvnt *siConEvnt);
  48 ftdm_status_t handle_rel_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiRelEvnt *siRelEvnt);
  49 ftdm_status_t handle_rel_cfm(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiRelEvnt *siRelEvnt);
  50 ftdm_status_t handle_dat_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiInfoEvnt *siInfoEvnt);
  51 ftdm_status_t handle_fac_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t evntType, SiFacEvnt *siFacEvnt);
  52 ftdm_status_t handle_fac_cfm(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t evntType, SiFacEvnt *siFacEvnt);
  53 ftdm_status_t handle_umsg_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit);
  54 ftdm_status_t handle_sta_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt);
  55 
  56 ftdm_status_t handle_reattempt(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt);
  57 ftdm_status_t handle_pause(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt);
  58 ftdm_status_t handle_resume(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt);
  59 ftdm_status_t handle_cot_start(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt);
  60 ftdm_status_t handle_cot_stop(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt);
  61 ftdm_status_t handle_cot(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt);
  62 ftdm_status_t handle_rsc_req(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt);
  63 ftdm_status_t handle_local_rsc_req(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt);
  64 ftdm_status_t handle_rsc_rsp(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt);
  65 ftdm_status_t handle_grs_req(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt);
  66 ftdm_status_t handle_grs_rsp(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt);
  67 ftdm_status_t handle_blo_req(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt);
  68 ftdm_status_t handle_blo_rsp(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt);
  69 ftdm_status_t handle_ubl_req(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt);
  70 ftdm_status_t handle_ubl_rsp(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt);
  71 ftdm_status_t handle_local_blk(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt);
  72 ftdm_status_t handle_local_ubl(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt);
  73 ftdm_status_t handle_ucic(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt);
  74 ftdm_status_t handle_cgb_req(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt);
  75 ftdm_status_t handle_cgu_req(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt);
  76 /******************************************************************************/
  77 
  78 /* FUNCTIONS ******************************************************************/
  79 ftdm_status_t handle_con_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiConEvnt *siConEvnt)
  80 {
  81         SS7_FUNC_TRACE_ENTER(__FUNCTION__);
  82 
  83         sngss7_chan_data_t  *sngss7_info = NULL;
  84         ftdm_channel_t          *ftdmchan = NULL;
  85         char                            nadi[2];
  86 
  87         memset(nadi, '\0', sizeof(nadi));
  88 
  89         /* get the ftdmchan and ss7_chan_data from the circuit */
  90         if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
  91                 SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
  92                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
  93                 return FTDM_FAIL;
  94         }
  95 
  96         /* lock the channel */
  97         ftdm_mutex_lock(ftdmchan->mutex);
  98 
  99         if (sngss7_test_flag(sngss7_info, FLAG_GLARE)) {
 100                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx IAM (glare)\n", sngss7_info->circuit->cic);
 101         } else {
 102                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx IAM\n", sngss7_info->circuit->cic);
 103         }
 104 
 105         /* check if the circuit has a remote block */
 106         if ((sngss7_test_flag(sngss7_info, FLAG_CKT_MN_BLOCK_RX)) ||
 107                 (sngss7_test_flag(sngss7_info, FLAG_GRP_HW_BLOCK_RX)) ||
 108                 (sngss7_test_flag(sngss7_info, FLAG_GRP_MN_BLOCK_RX))) {
 109 
 110                 /* as per Q.764, 2.8.2.3 xiv ... remove the block from this channel */
 111                 sngss7_clear_flag(sngss7_info, FLAG_CKT_MN_BLOCK_RX);
 112                 sngss7_clear_flag(sngss7_info, FLAG_GRP_HW_BLOCK_RX);
 113                 sngss7_clear_flag(sngss7_info, FLAG_GRP_MN_BLOCK_RX);
 114 
 115                 /* KONRAD FIX ME : check in case there is a ckt and grp block */
 116         }
 117 
 118         /* check whether the ftdm channel is in a state to accept a call */
 119         switch (ftdmchan->state) {
 120         /**************************************************************************/
 121         case (FTDM_CHANNEL_STATE_DOWN):  /* only state it is valid to get IAM (except if there is glare */
 122 
 123                 /* check if there is any reason why we can't use this channel */
 124                 if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_INUSE)) {
 125                         /* channel is already requested for use by the ftdm core */
 126                         goto handle_glare;
 127                 } else if(ftdm_channel_open_chan(ftdmchan) != FTDM_SUCCESS) {
 128                         /* channel is not inuse but we can't open it...fail the call */
 129                         SS7_ERROR("Failed to open span: %d, chan: %d\n",
 130                                                 ftdmchan->physical_span_id,
 131                                                 ftdmchan->physical_chan_id);
 132 
 133                          /* set the flag to indicate this hangup is started from the local side */
 134                         sngss7_set_flag(sngss7_info, FLAG_LOCAL_REL);
 135 
 136                         ftdmchan->caller_data.hangup_cause = 41;
 137 
 138                         /* move the state to CANCEL */
 139                         ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_CANCEL);
 140 
 141                 } else {
 142 
 143                         /* fill in the channels SS7 Stack information */
 144                         sngss7_info->suInstId = get_unique_id();
 145                         sngss7_info->spInstId = spInstId;
 146 
 147                         /* fill in calling party information */
 148                         if (siConEvnt->cgPtyNum.eh.pres) {
 149                                 if (siConEvnt->cgPtyNum.addrSig.pres) {
 150                                         /* fill in cid_num */
 151                                         copy_tknStr_from_sngss7(siConEvnt->cgPtyNum.addrSig,
 152                                                                                         ftdmchan->caller_data.cid_num.digits, 
 153                                                                                         siConEvnt->cgPtyNum.oddEven);
 154 
 155                                         /* fill in cid Name */
 156                                         ftdm_set_string(ftdmchan->caller_data.cid_name, ftdmchan->caller_data.cid_num.digits);
 157 
 158                                         /* fill in ANI */
 159                                         ftdm_set_string(ftdmchan->caller_data.ani.digits, ftdmchan->caller_data.cid_num.digits);
 160                                 }
 161 
 162                                 if (siConEvnt->cgPtyNum.scrnInd.pres) {
 163                                         /* fill in the screening indication value */
 164                                         ftdmchan->caller_data.screen = siConEvnt->cgPtyNum.scrnInd.val;
 165                                 }
 166 
 167                                 if (siConEvnt->cgPtyNum.presRest.pres) {
 168                                         /* fill in the presentation value */
 169                                         ftdmchan->caller_data.pres = siConEvnt->cgPtyNum.presRest.val;
 170                                 }       
 171                         } else {
 172                                 SS7_INFO_CHAN(ftdmchan,"No Calling party (ANI) information in IAM!%s\n", " ");
 173                         }
 174 
 175                         /* fill in called party infomation */
 176                         if (siConEvnt->cdPtyNum.eh.pres) {
 177                                 if (siConEvnt->cdPtyNum.addrSig.pres) {
 178                                         /* fill in the called number/dnis */
 179                                         copy_tknStr_from_sngss7(siConEvnt->cdPtyNum.addrSig, 
 180                                                                                         ftdmchan->caller_data.dnis.digits, 
 181                                                                                         siConEvnt->cdPtyNum.oddEven);
 182                                 }
 183                         } else {
 184                                 SS7_INFO_CHAN(ftdmchan,"No Called party (DNIS) information in IAM!%s\n", " ");
 185                         }
 186 
 187                         /* fill in rdnis information*/
 188                         if (siConEvnt->redirgNum.eh.pres) {
 189                                 if (siConEvnt->redirgNum.addrSig.pres) {
 190                                         /* fill in the rdnis digits */
 191                                         copy_tknStr_from_sngss7(siConEvnt->redirgNum.addrSig, 
 192                                                                                         ftdmchan->caller_data.rdnis.digits, 
 193                                                                                         siConEvnt->cgPtyNum.oddEven);
 194                                 }
 195                         }   else {
 196                                 SS7_DEBUG_CHAN(ftdmchan,"No RDNIS party information in IAM!%s\n", " ");
 197                         }
 198 
 199                         /* fill in the TMR/bearer capability */
 200                         if (siConEvnt->txMedReq.eh.pres) {
 201                                 if (siConEvnt->txMedReq.trMedReq.pres) {
 202                                         /* fill in the bearer type */
 203                                         ftdmchan->caller_data.bearer_capability = siConEvnt->txMedReq.trMedReq.val;
 204                                 }
 205                         } else {
 206                                 SS7_DEBUG_CHAN(ftdmchan,"No TMR/Bearer Cap information in IAM!%s\n", " ");
 207                         }
 208 
 209                         /* add any special variables for the dialplan */
 210                         sprintf(nadi, "%d", siConEvnt->cgPtyNum.natAddrInd.val);
 211                         ftdm_channel_add_var(ftdmchan, "ss7_nadi", nadi);
 212 
 213                         /* set the state of the channel to collecting...the rest is done by the chan monitor */
 214                         ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_COLLECT);
 215 
 216                 } /* if (channel is usable */
 217 
 218                 break;
 219         /**************************************************************************/
 220         case (FTDM_CHANNEL_STATE_DIALING):
 221         case (FTDM_CHANNEL_STATE_TERMINATING):
 222         case (FTDM_CHANNEL_STATE_HANGUP):
 223         case (FTDM_CHANNEL_STATE_HANGUP_COMPLETE):
 224 handle_glare:
 225                 /* the core already has plans for this channel...glare */
 226                 SS7_INFO_CHAN(ftdmchan, "Got IAM on channel that is already inuse (state=%s|inuse=%d)...glare!\n", 
 227                                                                 ftdm_channel_state2str (ftdmchan->state),
 228                                                                 ftdm_test_flag(ftdmchan, FTDM_CHANNEL_INUSE));
 229 
 230                 /* save the info so that we can use it later on */
 231                 sngss7_info->glare.spInstId = spInstId;
 232                 sngss7_info->glare.circuit = circuit;
 233                 memcpy(&sngss7_info->glare.iam, siConEvnt, sizeof(*siConEvnt));
 234 
 235                 if (!(sngss7_test_flag(sngss7_info, FLAG_GLARE))) {
 236                         /* glare, throw the flag */
 237                         sngss7_set_flag(sngss7_info, FLAG_GLARE);
 238                 
 239                         /* setup the hangup cause */
 240                         ftdmchan->caller_data.hangup_cause = 34;        /* Circuit Congrestion */
 241                 
 242                         /* this is a remote hangup request */
 243                         sngss7_set_flag(sngss7_info, FLAG_REMOTE_REL);
 244                 
 245                         /* move the state of the channel to Terminating to end the call */
 246                         ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_TERMINATING);
 247                 } /* if (!(sngss7_test_flag(sngss7_info, FLAG_GLARE))) */
 248                 break;
 249         /**************************************************************************/
 250         default:        /* should not have gotten an IAM while in this state */
 251                 SS7_ERROR_CHAN(ftdmchan, "Got IAM on channel in invalid state(%s)...reset!\n", ftdm_channel_state2str (ftdmchan->state));
 252 
 253                 /* move the state of the channel to RESTART to force a reset */
 254                 ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_RESTART);
 255 
 256                 break;
 257         /**************************************************************************/
 258         } /* switch (ftdmchan->state) */
 259 
 260         /* unlock the channel */
 261         ftdm_mutex_unlock(ftdmchan->mutex);
 262 
 263         SS7_FUNC_TRACE_EXIT(__FUNCTION__);
 264         return FTDM_SUCCESS;
 265 }
 266 
 267 /******************************************************************************/
 268 ftdm_status_t handle_con_sta(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiCnStEvnt *siCnStEvnt, uint8_t evntType)
 269 {
 270         SS7_FUNC_TRACE_ENTER(__FUNCTION__);
 271 
 272         sngss7_chan_data_t  *sngss7_info ;
 273         ftdm_channel_t    *ftdmchan;
 274 
 275         /* get the ftdmchan and ss7_chan_data from the circuit */
 276         if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
 277                 SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
 278                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
 279                 return FTDM_FAIL;
 280         }
 281 
 282         /* lock the channel */
 283         ftdm_mutex_lock(ftdmchan->mutex);
 284 
 285         switch (evntType) {
 286         /**************************************************************************/
 287         case (ADDRCMPLT):
 288                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx ACM\n", sngss7_info->circuit->cic);
 289                 switch (ftdmchan->state) {
 290                 /**********************************************************************/
 291                 case FTDM_CHANNEL_STATE_DIALING:
 292                         /* KONRAD: should we confirm the instance ids ? */
 293 
 294                         /* need to grab the sp instance id */ 
 295                         sngss7_info->spInstId = spInstId;
 296 
 297                         /* go to PROGRESS */
 298                         ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_PROGRESS);
 299                 break;
 300                 /**********************************************************************/
 301                 default:        /* incorrect state...reset the CIC */
 302                         /* go to RESTART */
 303                         ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_PROGRESS);
 304                 break;
 305                 /**********************************************************************/
 306                 } /* switch (ftdmchan->state) */
 307         /**************************************************************************/
 308         case (MODIFY):
 309                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx MODIFY\n", sngss7_info->circuit->cic);
 310                 break;
 311         /**************************************************************************/
 312         case (MODCMPLT):
 313                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx MODIFY-COMPLETE\n", sngss7_info->circuit->cic);
 314                 break;
 315         /**************************************************************************/
 316         case (MODREJ):
 317                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx MODIFY-REJECT\n", sngss7_info->circuit->cic);
 318                 break;
 319         /**************************************************************************/
 320         case (PROGRESS):
 321                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx CPG\n", sngss7_info->circuit->cic);
 322                 break;
 323         /**************************************************************************/
 324         case (FRWDTRSFR):
 325                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx FOT\n", sngss7_info->circuit->cic);
 326                 break;
 327         /**************************************************************************/
 328         case (INFORMATION):
 329                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx INF\n", sngss7_info->circuit->cic);
 330                 break;
 331         /**************************************************************************/
 332         case (INFORMATREQ):
 333                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx INR\n", sngss7_info->circuit->cic);
 334                 break;
 335         /**************************************************************************/
 336         case (SUBSADDR):
 337                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx SAM\n", sngss7_info->circuit->cic);
 338                 break;
 339         /**************************************************************************/
 340         case (EXIT):
 341                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx EXIT\n", sngss7_info->circuit->cic);
 342                 break;
 343         /**************************************************************************/
 344         case (NETRESMGT):
 345                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx NRM\n", sngss7_info->circuit->cic);
 346                 break;
 347         /**************************************************************************/
 348         case (IDENTREQ):
 349                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx IDR\n", sngss7_info->circuit->cic);
 350                 break;
 351         /**************************************************************************/
 352         case (IDENTRSP):
 353                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx IRS\n", sngss7_info->circuit->cic);
 354                 break;
 355         /**************************************************************************/
 356         case (MALCLLPRNT):
 357                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx MALICIOUS CALL\n", sngss7_info->circuit->cic);
 358                 break;
 359         /**************************************************************************/
 360         case (CHARGE):
 361                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx CRG\n", sngss7_info->circuit->cic);
 362                 break;
 363         /**************************************************************************/
 364         case (TRFFCHGE):
 365                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx CRG-TARIFF\n", sngss7_info->circuit->cic);
 366                 break;
 367         /**************************************************************************/
 368         case (CHARGEACK):
 369                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx CRG-ACK\n", sngss7_info->circuit->cic);
 370                 break;
 371         /**************************************************************************/
 372         case (CALLOFFMSG):
 373                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx CALL-OFFER\n", sngss7_info->circuit->cic);
 374                 break;
 375         /**************************************************************************/
 376         case (LOOPPRVNT):
 377                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx LOP\n", sngss7_info->circuit->cic);
 378                 break;
 379         /**************************************************************************/
 380         case (TECT_TIMEOUT):
 381                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx ECT-Timeout\n", sngss7_info->circuit->cic);
 382                 break;
 383         /**************************************************************************/
 384         case (RINGSEND):
 385                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx RINGING-SEND\n", sngss7_info->circuit->cic);
 386                 break;
 387         /**************************************************************************/
 388         case (CALLCLEAR):
 389                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx CALL-LINE Clear\n", sngss7_info->circuit->cic);
 390                 break;
 391         /**************************************************************************/
 392         case (PRERELEASE):
 393                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx PRI\n", sngss7_info->circuit->cic);
 394                 break;
 395         /**************************************************************************/
 396         case (APPTRANSPORT):
 397                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx APM\n", sngss7_info->circuit->cic);
 398                 break;
 399         /**************************************************************************/
 400         case (OPERATOR):
 401                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx OPERATOR\n", sngss7_info->circuit->cic);
 402                 break;
 403         /**************************************************************************/
 404         case (METPULSE):
 405                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx METERING-PULSE\n", sngss7_info->circuit->cic);
 406                 break;
 407         /**************************************************************************/
 408         case (CLGPTCLR):
 409                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx CALLING_PARTY_CLEAR\n", sngss7_info->circuit->cic);
 410                 break;
 411         /**************************************************************************/
 412         case (SUBDIRNUM):
 413                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx SUB-DIR\n", sngss7_info->circuit->cic);
 414                 break;
 415         /**************************************************************************/
 416         default:
 417                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx Unknown Msg\n", sngss7_info->circuit->cic);
 418                 break;
 419         /**************************************************************************/
 420         }
 421 
 422         /* unlock the channel */
 423         ftdm_mutex_unlock(ftdmchan->mutex);
 424 
 425         SS7_FUNC_TRACE_EXIT(__FUNCTION__);
 426         return FTDM_SUCCESS;
 427 }
 428 
 429 /******************************************************************************/
 430 ftdm_status_t handle_con_cfm(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiConEvnt *siConEvnt)
 431 {
 432         SS7_FUNC_TRACE_ENTER(__FUNCTION__);
 433 
 434         sngss7_chan_data_t  *sngss7_info ;
 435         ftdm_channel_t    *ftdmchan;
 436 
 437         /* get the ftdmchan and ss7_chan_data from the circuit */
 438         if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
 439                 SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
 440                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
 441                 return FTDM_FAIL;
 442         }
 443 
 444         /* lock the channel */
 445         ftdm_mutex_lock(ftdmchan->mutex);
 446 
 447         /* check whether the ftdm channel is in a state to accept a call */
 448         switch (ftdmchan->state) {
 449         /**************************************************************************/
 450         case FTDM_CHANNEL_STATE_PROGRESS:
 451         case FTDM_CHANNEL_STATE_PROGRESS_MEDIA:
 452 
 453                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx ANM\n", sngss7_info->circuit->cic);
 454 
 455                 /* go to UP */
 456                 ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_UP);
 457 
 458                 break;
 459         /**************************************************************************/
 460         case FTDM_CHANNEL_STATE_DIALING:
 461 
 462                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx CON\n", sngss7_info->circuit->cic);
 463 
 464                 /* go to UP */
 465                 ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_UP);
 466 
 467                 break;          
 468         /**************************************************************************/
 469         default:        /* incorrect state...reset the CIC */
 470 
 471                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx ANM/CON\n", sngss7_info->circuit->cic);
 472 
 473                 /* throw the TX reset flag */
 474                 sngss7_set_flag(sngss7_info, FLAG_GRP_RESET_TX);
 475 
 476                 /* go to RESTART */
 477                 ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_RESTART);
 478 
 479                 break;
 480         /**************************************************************************/
 481         }
 482 
 483         /* unlock the channel */
 484         ftdm_mutex_unlock(ftdmchan->mutex);
 485 
 486         SS7_FUNC_TRACE_EXIT(__FUNCTION__);
 487         return FTDM_SUCCESS;
 488 }
 489 
 490 /******************************************************************************/
 491 ftdm_status_t handle_rel_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiRelEvnt *siRelEvnt)
 492 {
 493         SS7_FUNC_TRACE_ENTER(__FUNCTION__);
 494 
 495         sngss7_chan_data_t  *sngss7_info ;
 496         ftdm_channel_t    *ftdmchan;
 497 
 498         /* get the ftdmchan and ss7_chan_data from the circuit */
 499         if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
 500                 SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
 501                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
 502                 return FTDM_FAIL;
 503         }
 504 
 505         /* lock the channel */
 506         ftdm_mutex_lock(ftdmchan->mutex);
 507 
 508         SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx REL cause=%d\n",
 509                                                         sngss7_info->circuit->cic, 
 510                                                         siRelEvnt->causeDgn.causeVal.val);
 511 
 512         /* check whether the ftdm channel is in a state to release a call */
 513         switch (ftdmchan->state) {
 514         /**************************************************************************/
 515         case FTDM_CHANNEL_STATE_DIALING:
 516 
 517                 /* pass the release code up to FTDM */
 518                 if (siRelEvnt->causeDgn.causeVal.pres) {
 519                         ftdmchan->caller_data.hangup_cause = siRelEvnt->causeDgn.causeVal.val;
 520                 } else {
 521                         SS7_ERROR("REL does not have a cause code!\n");
 522                         ftdmchan->caller_data.hangup_cause = 0;
 523                 }
 524 
 525                 /* this is a remote hangup request */
 526                 sngss7_set_flag(sngss7_info, FLAG_REMOTE_REL);
 527 
 528                 /* move the state of the channel to CANCEL to end the call */
 529                 ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_TERMINATING);
 530 
 531                 break;
 532         /**************************************************************************/
 533         case FTDM_CHANNEL_STATE_RING:
 534         case FTDM_CHANNEL_STATE_PROGRESS:
 535         case FTDM_CHANNEL_STATE_PROGRESS_MEDIA:
 536         case FTDM_CHANNEL_STATE_UP:
 537 
 538                 /* pass the release code up to FTDM */
 539                 if (siRelEvnt->causeDgn.causeVal.pres) {
 540                         ftdmchan->caller_data.hangup_cause = siRelEvnt->causeDgn.causeVal.val;
 541                 } else {
 542                         SS7_ERROR("REL does not have a cause code!\n");
 543                         ftdmchan->caller_data.hangup_cause = 0;
 544                 }
 545 
 546                 /* this is a remote hangup request */
 547                 sngss7_set_flag(sngss7_info, FLAG_REMOTE_REL);
 548 
 549                 /* move the state of the channel to TERMINATING to end the call */
 550                 ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_TERMINATING);
 551 
 552                 break;
 553         /**************************************************************************/
 554         default:
 555 
 556                 /* throw the reset flag */
 557                 sngss7_set_flag(sngss7_info, FLAG_RESET_RX);
 558 
 559                 /* set the state to RESTART */
 560                 ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_RESTART);
 561                 break;
 562         /**************************************************************************/
 563         } /* switch (ftdmchan->state) */
 564 
 565 
 566         /* unlock the channel */
 567         ftdm_mutex_unlock(ftdmchan->mutex);
 568 
 569         SS7_FUNC_TRACE_EXIT(__FUNCTION__);
 570         return FTDM_SUCCESS;
 571 }
 572 
 573 /******************************************************************************/
 574 ftdm_status_t handle_rel_cfm(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiRelEvnt *siRelEvnt)
 575 {
 576         SS7_FUNC_TRACE_ENTER(__FUNCTION__);
 577         
 578         sngss7_chan_data_t  *sngss7_info ;
 579         ftdm_channel_t    *ftdmchan;
 580 
 581         /* get the ftdmchan and ss7_chan_data from the circuit */
 582         if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
 583                 SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
 584                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
 585                 return FTDM_FAIL;
 586         }
 587 
 588         /* lock the channel */
 589         ftdm_mutex_lock(ftdmchan->mutex);
 590 
 591         SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx RLC\n", sngss7_info->circuit->cic);
 592 
 593         /* check whether the ftdm channel is in a state to accept a call */
 594         switch (ftdmchan->state) {
 595         /**************************************************************************/
 596         case FTDM_CHANNEL_STATE_HANGUP_COMPLETE:
 597 
 598                 /* go to DOWN */
 599                 ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN);
 600 
 601                 break;
 602         /**************************************************************************/
 603         case FTDM_CHANNEL_STATE_DOWN:
 604                 /* do nothing, just drop the message */
 605                 break;
 606         /**************************************************************************/
 607         default:        
 608                 /* KONRAD: should just stop the call...but a reset is easier for now (since it does hangup the call) */
 609 
 610                 /* go to RESTART */
 611                 ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_RESTART);
 612 
 613                 break;
 614         /**************************************************************************/
 615         }
 616 
 617         /* unlock the channel */
 618         ftdm_mutex_unlock(ftdmchan->mutex);
 619 
 620         SS7_FUNC_TRACE_EXIT(__FUNCTION__);
 621         return FTDM_SUCCESS;
 622 }
 623 
 624 /******************************************************************************/
 625 ftdm_status_t handle_dat_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiInfoEvnt *siInfoEvnt)
 626 {
 627         SS7_FUNC_TRACE_ENTER(__FUNCTION__);
 628         
 629         sngss7_chan_data_t  *sngss7_info ;
 630         ftdm_channel_t    *ftdmchan;
 631 
 632         /* get the ftdmchan and ss7_chan_data from the circuit */
 633         if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
 634                 SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
 635                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
 636                 return FTDM_FAIL;
 637         }
 638 
 639         /* lock the channel */
 640         ftdm_mutex_lock(ftdmchan->mutex);
 641 
 642         SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx DATA IND\n", sngss7_info->circuit->cic);
 643 
 644         /* unlock the channel */
 645         ftdm_mutex_unlock(ftdmchan->mutex);
 646 
 647         SS7_FUNC_TRACE_EXIT(__FUNCTION__);
 648         return FTDM_SUCCESS;
 649 }
 650 
 651 /******************************************************************************/
 652 ftdm_status_t handle_fac_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t evntType, SiFacEvnt *siFacEvnt)
 653 {
 654         SS7_FUNC_TRACE_ENTER(__FUNCTION__);
 655         
 656         sngss7_chan_data_t  *sngss7_info ;
 657         ftdm_channel_t    *ftdmchan;
 658 
 659         /* get the ftdmchan and ss7_chan_data from the circuit */
 660         if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
 661                 SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
 662                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
 663                 return FTDM_FAIL;
 664         }
 665 
 666         /* lock the channel */
 667         ftdm_mutex_lock(ftdmchan->mutex);
 668 
 669         SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx FAC\n", sngss7_info->circuit->cic);
 670 
 671         /* unlock the channel */
 672         ftdm_mutex_unlock(ftdmchan->mutex);
 673 
 674         SS7_FUNC_TRACE_EXIT(__FUNCTION__);
 675         return FTDM_SUCCESS;
 676 }
 677 
 678 /******************************************************************************/
 679 ftdm_status_t handle_fac_cfm(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t evntType, SiFacEvnt *siFacEvnt)
 680 {
 681         SS7_FUNC_TRACE_ENTER(__FUNCTION__);
 682         
 683         sngss7_chan_data_t  *sngss7_info ;
 684         ftdm_channel_t    *ftdmchan;
 685 
 686         /* get the ftdmchan and ss7_chan_data from the circuit */
 687         if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
 688                 SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
 689                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
 690                 return FTDM_FAIL;
 691         }
 692 
 693         /* lock the channel */
 694         ftdm_mutex_lock(ftdmchan->mutex);
 695 
 696         SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx FAC-CON\n", sngss7_info->circuit->cic);
 697 
 698         /* unlock the channel */
 699         ftdm_mutex_unlock(ftdmchan->mutex);
 700 
 701         SS7_FUNC_TRACE_EXIT(__FUNCTION__);
 702         return FTDM_SUCCESS;
 703 }
 704 
 705 /******************************************************************************/
 706 ftdm_status_t handle_umsg_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit)
 707 {
 708         SS7_FUNC_TRACE_ENTER(__FUNCTION__);
 709         
 710         sngss7_chan_data_t  *sngss7_info ;
 711         ftdm_channel_t    *ftdmchan;
 712 
 713         /* get the ftdmchan and ss7_chan_data from the circuit */
 714         if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
 715                 SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
 716                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
 717                 return FTDM_FAIL;
 718         }
 719 
 720         /* lock the channel */
 721         ftdm_mutex_lock(ftdmchan->mutex);
 722 
 723         SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx USER-USER msg\n", sngss7_info->circuit->cic);
 724 
 725         /* unlock the channel */
 726         ftdm_mutex_unlock(ftdmchan->mutex);
 727 
 728         SS7_FUNC_TRACE_EXIT(__FUNCTION__);
 729         return FTDM_SUCCESS;
 730 }
 731 
 732 /******************************************************************************/
 733 ftdm_status_t handle_sta_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt)
 734 {
 735         sngss7_chan_data_t  *sngss7_info ;
 736         ftdm_channel_t    *ftdmchan;
 737 
 738         /* get the ftdmchan and ss7_chan_data from the circuit */
 739         if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
 740                 SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
 741                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
 742                 return FTDM_FAIL;
 743         }
 744 
 745         SS7_FUNC_TRACE_ENTER(__FUNCTION__);
 746 
 747         switch (evntType) {
 748         /**************************************************************************/
 749         case SIT_STA_REATTEMPT:          /* reattempt indication */
 750                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx Reattempt indication\n", sngss7_info->circuit->cic);
 751                 handle_reattempt(suInstId, spInstId, circuit, globalFlg, evntType, siStaEvnt);
 752                 break;
 753         /**************************************************************************/
 754         case SIT_STA_ERRORIND:            /* error indication */
 755                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx Error indication\n", sngss7_info->circuit->cic);
 756                 SS7_WARN(" %s indication not currently supported\n", DECODE_LCC_EVENT(evntType));
 757                 break;
 758         /**************************************************************************/
 759         case SIT_STA_CONTCHK:              /* continuity check */
 760                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx COT start\n", sngss7_info->circuit->cic);
 761                 handle_cot_start(suInstId, spInstId, circuit, globalFlg, evntType, siStaEvnt);
 762                 break;
 763         /**************************************************************************/
 764         case SIT_STA_CONTREP:              /* continuity report */
 765                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx COT report\n", sngss7_info->circuit->cic);
 766                 handle_cot(suInstId, spInstId, circuit, globalFlg, evntType, siStaEvnt);
 767                 break;
 768         /**************************************************************************/
 769         case SIT_STA_STPCONTIN:          /* stop continuity */
 770                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx COT stop\n", sngss7_info->circuit->cic);
 771                 handle_cot_stop(suInstId, spInstId, circuit, globalFlg, evntType, siStaEvnt);
 772                 break;
 773         /**************************************************************************/
 774         case SIT_STA_CGQRYRSP:            /* circuit grp query response from far end forwarded to upper layer by ISUP */
 775                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx CQM\n", sngss7_info->circuit->cic);
 776                 SS7_WARN(" %s indication not currently supported\n", DECODE_LCC_EVENT(evntType));
 777                 break;
 778         /**************************************************************************/
 779         case SIT_STA_CONFUSION:          /* confusion */
 780                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx CFN\n", sngss7_info->circuit->cic);
 781                 SS7_WARN(" %s indication not currently supported\n", DECODE_LCC_EVENT(evntType));
 782                 break;
 783         /**************************************************************************/
 784         case SIT_STA_LOOPBACKACK:          /* loop-back acknowledge */
 785                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx LPA\n", sngss7_info->circuit->cic);
 786                 SS7_WARN(" %s indication not currently supported\n", DECODE_LCC_EVENT(evntType));
 787                 break;
 788         /**************************************************************************/
 789         case SIT_STA_CIRRSRVREQ:                /* circuit reservation request */
 790                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx Ckt Resveration req\n", sngss7_info->circuit->cic);
 791                 SS7_WARN(" %s indication not currently supported\n", DECODE_LCC_EVENT(evntType));
 792                 break;
 793         /**************************************************************************/
 794         case SIT_STA_CIRRSRVACK:                /* circuit reservation acknowledgement */
 795                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx Ckt Res ack\n", sngss7_info->circuit->cic);
 796                 SS7_WARN(" %s indication not currently supported\n", DECODE_LCC_EVENT(evntType));
 797                 break;
 798         /**************************************************************************/
 799         case SIT_STA_CIRBLOREQ:          /* circuit blocking request */
 800                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx BLO\n", sngss7_info->circuit->cic);
 801                 handle_blo_req(suInstId, spInstId, circuit, globalFlg, evntType, siStaEvnt);
 802                 break;
 803         /**************************************************************************/
 804         case SIT_STA_CIRBLORSP:          /* circuit blocking response   */
 805                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx BLA\n", sngss7_info->circuit->cic);
 806                 handle_blo_rsp(suInstId, spInstId, circuit, globalFlg, evntType, siStaEvnt);
 807                 break;
 808         /**************************************************************************/
 809         case SIT_STA_CIRUBLREQ:          /* circuit unblocking request */
 810                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx UBL\n", sngss7_info->circuit->cic);
 811                 handle_ubl_req(suInstId, spInstId, circuit, globalFlg, evntType, siStaEvnt);
 812                 break;
 813         /**************************************************************************/
 814         case SIT_STA_CIRUBLRSP:          /* circuit unblocking response */
 815                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx UBA\n", sngss7_info->circuit->cic);
 816                 handle_ubl_rsp(suInstId, spInstId, circuit, globalFlg, evntType, siStaEvnt);
 817                 break;
 818         /**************************************************************************/
 819         case SIT_STA_CIRRESREQ:          /* circuit reset request - RSC */
 820                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx RSC\n", sngss7_info->circuit->cic);
 821                 handle_rsc_req(suInstId, spInstId, circuit, globalFlg, evntType, siStaEvnt);
 822                 break;
 823         /**************************************************************************/
 824         case SIT_STA_CIRLOCRES:          /* reset initiated locally by the software */
 825                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx Local RSC\n", sngss7_info->circuit->cic);
 826                 handle_local_rsc_req(suInstId, spInstId, circuit, globalFlg, evntType, siStaEvnt);
 827                 break;
 828         /**************************************************************************/
 829         case SIT_STA_CIRRESRSP:          /* circuit reset response */
 830                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx RSC-RLC\n", sngss7_info->circuit->cic);
 831                 handle_rsc_rsp(suInstId, spInstId, circuit, globalFlg, evntType, siStaEvnt);
 832                 break;
 833         /**************************************************************************/
 834         case SIT_STA_CGBREQ:                    /* CGB request */
 835                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx CGB\n", sngss7_info->circuit->cic);
 836                 handle_cgb_req(suInstId, spInstId, circuit, globalFlg, evntType, siStaEvnt);
 837                 break;
 838         /**************************************************************************/
 839         case SIT_STA_CGUREQ:                    /* CGU request */
 840                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx CGU\n", sngss7_info->circuit->cic);
 841                 handle_cgu_req(suInstId, spInstId, circuit, globalFlg, evntType, siStaEvnt);
 842                 break;
 843         /**************************************************************************/
 844         case SIT_STA_CGQRYREQ:            /* circuit group query request */
 845                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx CQM\n", sngss7_info->circuit->cic);
 846                 SS7_WARN(" %s indication not currently supported\n", DECODE_LCC_EVENT(evntType));
 847                 break;
 848         /**************************************************************************/
 849         case SIT_STA_CGBRSP:                    /* mntc. oriented CGB response */
 850                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx mntc CGB\n", sngss7_info->circuit->cic);
 851                 /*handle_cgb_req(suInstId, spInstId, circuit, globalFlg, evntType, siStaEvnt);*/
 852                 break;
 853         /**************************************************************************/
 854         case SIT_STA_CGURSP:                    /* mntc. oriented CGU response */
 855                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx mntc CGU\n", sngss7_info->circuit->cic);
 856                 /*SS7_WARN(" %s indication not currently supported\n", DECODE_LCC_EVENT(evntType));*/
 857                 break;
 858         /**************************************************************************/
 859         case SIT_STA_GRSREQ:                    /* circuit group reset request */
 860                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx GRS\n", sngss7_info->circuit->cic);
 861                 handle_grs_req(suInstId, spInstId, circuit, globalFlg, evntType, siStaEvnt);
 862                 break;
 863         /**************************************************************************/
 864         case SIT_STA_CIRUNEQPD:          /* circuit unequipped indication */
 865                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx UCIC\n", sngss7_info->circuit->cic);
 866                 handle_ucic(suInstId, spInstId, circuit, globalFlg, evntType, siStaEvnt);
 867                 break;
 868         /**************************************************************************/
 869         case SIT_STA_GRSRSP:                    /* circuit group reset response */
 870                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx GRA\n", sngss7_info->circuit->cic);
 871                 handle_grs_rsp(suInstId, spInstId, circuit, globalFlg, evntType, siStaEvnt);
 872                 break;
 873         /**************************************************************************/
 874         case SIT_STA_PAUSEIND:            /* pause indication */
 875                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx SUS\n", sngss7_info->circuit->cic);
 876                 handle_pause(suInstId, spInstId, circuit, globalFlg, evntType, siStaEvnt);
 877                 break;
 878         /**************************************************************************/
 879         case SIT_STA_RESUMEIND:          /* resume indication */
 880                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx RES\n", sngss7_info->circuit->cic);
 881                 handle_resume(suInstId, spInstId, circuit, globalFlg, evntType, siStaEvnt);
 882                 break;
 883         /**************************************************************************/
 884         case SIT_STA_USRPARTA:            /* user part available */
 885                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx UPA\n", sngss7_info->circuit->cic);
 886                 SS7_WARN(" %s indication not currently supported\n", DECODE_LCC_EVENT(evntType));
 887                 break;
 888         /**************************************************************************/
 889         case SIT_STA_RMTUSRUNAV:                /* remote user not available */
 890                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx Remote User not Available\n", sngss7_info->circuit->cic);
 891                 SS7_WARN(" %s indication not currently supported\n", DECODE_LCC_EVENT(evntType));
 892                 break;
 893         /**************************************************************************/
 894         case SIT_STA_MTPCONG0:            /* congestion indication level 0 */
 895                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx Congestion L0\n", sngss7_info->circuit->cic);
 896                 SS7_WARN(" %s indication not currently supported\n", DECODE_LCC_EVENT(evntType));
 897                 break;
 898         /**************************************************************************/
 899         case SIT_STA_MTPCONG1:            /* congestion indication level 1 */
 900                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx Congestion L1\n", sngss7_info->circuit->cic);
 901                 SS7_WARN(" %s indication not currently supported\n", DECODE_LCC_EVENT(evntType));
 902                 break;
 903         /**************************************************************************/
 904         case SIT_STA_MTPCONG2:            /* congestion indication level 2 */
 905                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx Congestion L2\n", sngss7_info->circuit->cic);
 906                 SS7_WARN(" %s indication not currently supported\n", DECODE_LCC_EVENT(evntType));
 907                 break;
 908         /**************************************************************************/
 909         case SIT_STA_MTPCONG3:            /* congestion indication level 3 */
 910                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx Congestion L3\n", sngss7_info->circuit->cic);
 911                 SS7_WARN(" %s indication not currently supported\n", DECODE_LCC_EVENT(evntType));
 912                 break;
 913         /**************************************************************************/
 914         case SIT_STA_MTPSTPCONG:                /* stop congestion indication level 0 */
 915                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx Stop Congestion\n", sngss7_info->circuit->cic);
 916                 SS7_WARN(" %s indication not currently supported\n", DECODE_LCC_EVENT(evntType));
 917                 break; 
 918         /**************************************************************************/
 919         case SIT_STA_CIRLOCALBLOIND:    /* Mngmt local blocking */
 920                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx Local BLO\n", sngss7_info->circuit->cic);
 921                 handle_local_blk(suInstId, spInstId, circuit, globalFlg, evntType, siStaEvnt);
 922                 break;
 923         /**************************************************************************/
 924         case SIT_STA_CIRLOCALUBLIND:    /* Mngmt local unblocking */
 925                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx Local UBL\n", sngss7_info->circuit->cic);
 926                 handle_local_ubl(suInstId, spInstId, circuit, globalFlg, evntType, siStaEvnt);
 927                 break;
 928         /**************************************************************************/
 929         case SIT_STA_OVERLOAD:            /* Overload */
 930                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx Overload\n", sngss7_info->circuit->cic);
 931                 SS7_WARN(" %s indication not currently supported\n", DECODE_LCC_EVENT(evntType));
 932                 break;
 933         /**************************************************************************/
 934         case SIT_STA_LMCGBREQ:            /* when LM requests ckt grp blocking */
 935                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx LM CGB\n", sngss7_info->circuit->cic);
 936                 SS7_WARN(" %s indication not currently supported\n", DECODE_LCC_EVENT(evntType));
 937                 break;
 938         /**************************************************************************/
 939         case SIT_STA_LMCGUREQ:            /* when LM requests ckt grp unblocking */
 940                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx LM CGU\n", sngss7_info->circuit->cic);
 941                 SS7_WARN(" %s indication not currently supported\n", DECODE_LCC_EVENT(evntType));
 942                 break;
 943         /**************************************************************************/
 944         case SIT_STA_LMGRSREQ:            /* when LM requests ckt grp reset */
 945                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx LM RSC\n", sngss7_info->circuit->cic);
 946                 SS7_WARN(" %s indication not currently supported\n", DECODE_LCC_EVENT(evntType));
 947                 break;
 948         /**************************************************************************/
 949         case SIT_STA_CGBINFOIND:                /* circuit grp blking ind , no resp req */
 950                 /*SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx CGB no resp req\n", sngss7_info->circuit->cic);*/
 951 /*              handle_cgb_req(suInstId, spInstId, circuit, globalFlg, evntType, siStaEvnt);*/
 952                 break;
 953         /**************************************************************************/
 954         case SIT_STA_LMCQMINFOREQ:        /* when LM requests ckt grp query */
 955                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx LM CQM\n", sngss7_info->circuit->cic);
 956 //              SS7_WARN(" %s indication not currently supported\n", DECODE_LCC_EVENT(evntType));
 957                 break;
 958         /**************************************************************************/
 959         case SIT_STA_CIRLOCGRS:          /* group reset initiated locally by the software */
 960                 SS7_INFO_CHAN(ftdmchan,"[CIC:%d]Rx Local GRS\n", sngss7_info->circuit->cic);
 961                 SS7_WARN(" %s indication not currently supported\n", DECODE_LCC_EVENT(evntType));
 962                 break;
 963         /**************************************************************************/
 964         default:
 965                 SS7_INFO("[SNG-CC] Received Unknown indication %d\n", evntType);
 966                 break;
 967         } /* switch (evntType) */
 968 
 969         SS7_FUNC_TRACE_EXIT(__FUNCTION__);
 970         return FTDM_SUCCESS;
 971 
 972 }
 973 
 974 /******************************************************************************/
 975 ftdm_status_t handle_reattempt(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt)
 976 {
 977         SS7_FUNC_TRACE_ENTER(__FUNCTION__);
 978 
 979         sngss7_chan_data_t  *sngss7_info = NULL;
 980         ftdm_channel_t    *ftdmchan = NULL;
 981 
 982         /* get the ftdmchan and ss7_chan_data from the circuit */
 983         if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
 984                 SS7_ERROR("Failed to extract channel data for ISUP circuit = %d!\n", circuit);
 985                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
 986                 return FTDM_FAIL;
 987         }
 988 
 989         /* lock the channel */
 990         ftdm_mutex_lock(ftdmchan->mutex);
 991 
 992         if (sngss7_test_flag(sngss7_info, FLAG_GLARE)) {
 993                 /* the glare flag is already up so it was caught ... do nothing */
 994                 SS7_DEBUG_CHAN(ftdmchan, "Glare flag is already up...nothing to do!%s\n", " ");
 995         } else {
 996                 SS7_DEBUG_CHAN(ftdmchan, "Glare flag is not up yet...indicating glare from reattempt!%s\n", " ");
 997                 /* glare, throw the flag */
 998                 sngss7_set_flag(sngss7_info, FLAG_GLARE);
 999 
1000                 /* clear any existing glare data from the channel */
1001                 memset(&sngss7_info->glare, 0x0, sizeof(sngss7_glare_data_t));
1002 
1003                 /* setup the hangup cause */
1004                 ftdmchan->caller_data.hangup_cause = 34;        /* Circuit Congrestion */
1005 
1006                 /* this is a remote hangup request */
1007                 sngss7_set_flag(sngss7_info, FLAG_REMOTE_REL);
1008 
1009                 /* move the state of the channel to Terminating to end the call */
1010                 ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_TERMINATING);
1011         }
1012 
1013         /* unlock the channel again before we exit */
1014         ftdm_mutex_unlock(ftdmchan->mutex);
1015 
1016         SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1017         return FTDM_SUCCESS;
1018 }
1019 
1020 /******************************************************************************/
1021 ftdm_status_t handle_pause(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt)
1022 {
1023         SS7_FUNC_TRACE_ENTER(__FUNCTION__);
1024         
1025         sngss7_chan_data_t  *sngss7_info = NULL;
1026         ftdm_channel_t    *ftdmchan = NULL;
1027         int                              infId;
1028         int                              i;
1029         
1030         /* extract the affected infId from the circuit structure */
1031         infId = g_ftdm_sngss7_data.cfg.isupCkt[circuit].infId;
1032 
1033         /* set the interface to paused */
1034         sngss7_set_flag(&g_ftdm_sngss7_data.cfg.isupIntf[infId], SNGSS7_PAUSED);
1035         
1036         /* go through all the circuits now and find any other circuits on this infId */
1037         i = 1;
1038         while (g_ftdm_sngss7_data.cfg.isupCkt[i].id != 0) {
1039                 
1040                 /* check that the infId matches and that this is not a siglink */
1041                 if ((g_ftdm_sngss7_data.cfg.isupCkt[i].infId == infId) && 
1042                         (g_ftdm_sngss7_data.cfg.isupCkt[i].type == VOICE)) {
1043         
1044                         /* get the ftdmchan and ss7_chan_data from the circuit */
1045                         if (extract_chan_data(i, &sngss7_info, &ftdmchan)) {
1046                                 SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
1047                                 i++;
1048                                 continue;
1049                         }
1050         
1051                         /* lock the channel */
1052                         ftdm_mutex_lock(ftdmchan->mutex);
1053         
1054                         /* check if the circuit is fully started */
1055                         if (ftdm_test_flag(ftdmchan->span, FTDM_SPAN_IN_THREAD)) {
1056                                 SS7_DEBUG_CHAN(ftdmchan, "Rx PAUSE%s\n", "");
1057                                 /* set the pause flag on the channel */
1058                                 sngss7_set_flag(sngss7_info, FLAG_INFID_PAUSED);
1059                         }
1060         
1061                         /* unlock the channel again before we exit */
1062                         ftdm_mutex_unlock(ftdmchan->mutex);
1063         
1064                 } /* if (g_ftdm_sngss7_data.cfg.isupCkt[i].infId == infId) */
1065         
1066                 /* move to the next circuit */
1067                 i++;
1068         
1069         } /* while (g_ftdm_sngss7_data.cfg.isupCkt[i].id != 0) */
1070         
1071         SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1072         return FTDM_SUCCESS;
1073 }
1074 
1075 /******************************************************************************/
1076 ftdm_status_t handle_resume(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt)
1077 {
1078         SS7_FUNC_TRACE_ENTER(__FUNCTION__);
1079 
1080         sngss7_chan_data_t  *sngss7_info = NULL;
1081         ftdm_channel_t    *ftdmchan = NULL;
1082         int                              infId;
1083         int                              i;
1084 
1085         /* extract the affect infId from the circuit structure */
1086         infId = g_ftdm_sngss7_data.cfg.isupCkt[circuit].infId;
1087 
1088         /* set the interface to resumed */
1089         sngss7_clear_flag(&g_ftdm_sngss7_data.cfg.isupIntf[infId], SNGSS7_PAUSED);
1090 
1091         /* go through all the circuits now and find any other circuits on this infId */
1092         i = 1;
1093         while (g_ftdm_sngss7_data.cfg.isupCkt[i].id != 0) {
1094 
1095                 /* check that the infId matches and that this is not a siglink */
1096                 if ((g_ftdm_sngss7_data.cfg.isupCkt[i].infId == infId) && 
1097                         (g_ftdm_sngss7_data.cfg.isupCkt[i].type == VOICE)) {
1098 
1099                         /* get the ftdmchan and ss7_chan_data from the circuit */
1100                         if (extract_chan_data(i, &sngss7_info, &ftdmchan)) {
1101                                 SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
1102                                 i++;
1103                                 continue;
1104                         }
1105 
1106                         /* lock the channel */
1107                         ftdm_mutex_lock(ftdmchan->mutex);
1108 
1109                         /* only resume if we are paused */
1110                         if (sngss7_test_flag(sngss7_info, FLAG_INFID_PAUSED)) {
1111                                 SS7_DEBUG_CHAN(ftdmchan, "Rx RESUME%s\n", "");
1112 
1113                                 /* set the resume flag on the channel */
1114                                 sngss7_set_flag(sngss7_info, FLAG_INFID_RESUME);
1115 
1116                                 /* clear the paused flag */
1117                                 sngss7_clear_flag(sngss7_info, FLAG_INFID_PAUSED);
1118                         }
1119                         
1120                         /* unlock the channel again before we exit */
1121                         ftdm_mutex_unlock(ftdmchan->mutex);
1122 
1123                 } /* if (g_ftdm_sngss7_data.cfg.isupCkt[i].infId == infId) */
1124 
1125                 /* move to the next circuit */
1126                 i++;
1127 
1128         } /* while (g_ftdm_sngss7_data.cfg.isupCkt[i].id != 0) */
1129 
1130         SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1131         return FTDM_SUCCESS;
1132 }
1133 
1134 /******************************************************************************/
1135 ftdm_status_t handle_cot_start(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt)
1136 {
1137         SS7_FUNC_TRACE_ENTER(__FUNCTION__);
1138 
1139         sngss7_chan_data_t  *sngss7_info = NULL;
1140         ftdm_channel_t    *ftdmchan = NULL;
1141 
1142         /* get the ftdmchan and ss7_chan_data from the circuit */
1143         if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
1144                 SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
1145                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1146                 return FTDM_FAIL;
1147         }
1148 
1149         /* lock the channel */
1150         ftdm_mutex_lock(ftdmchan->mutex);
1151 
1152         /* open the channel if it is not open */
1153         if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OPEN)) {
1154                 if (ftdm_channel_open_chan(ftdmchan) != FTDM_SUCCESS) {
1155                         SS7_ERROR("Failed to open CIC %d for COT test!\n", sngss7_info->circuit->cic);
1156                         /* KONRAD FIX ME */
1157                         SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1158                         return FTDM_FAIL;
1159                 }
1160         }
1161 
1162         /* tell the core to loop the channel */
1163         ftdm_channel_command(ftdmchan, FTDM_COMMAND_ENABLE_LOOP, NULL);
1164 
1165         /* switch to the IN_LOOP state */
1166         ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_IN_LOOP);
1167 
1168         /* store the sngss7 ids */
1169         if (suInstId == 0) {
1170                 sngss7_info->suInstId = get_unique_id();
1171         } else {
1172                 sngss7_info->suInstId = suInstId;
1173         }
1174         sngss7_info->spInstId = spInstId;
1175         sngss7_info->globalFlg = globalFlg;
1176 
1177         /* unlock the channel again before we exit */
1178         ftdm_mutex_unlock(ftdmchan->mutex);
1179 
1180         SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1181         return FTDM_SUCCESS;
1182 }
1183 
1184 /******************************************************************************/
1185 ftdm_status_t handle_cot_stop(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt)
1186 {
1187         SS7_FUNC_TRACE_ENTER(__FUNCTION__);
1188 
1189         sngss7_chan_data_t  *sngss7_info = NULL;
1190         ftdm_channel_t    *ftdmchan = NULL;
1191 
1192         /* get the ftdmchan and ss7_chan_data from the circuit */
1193         if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
1194                 SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
1195                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1196                 return FTDM_FAIL;
1197         }
1198 
1199         /* lock the channel */
1200         ftdm_mutex_lock(ftdmchan->mutex);
1201 
1202         /* tell the core to stop looping the channel */
1203         ftdm_channel_command(ftdmchan, FTDM_COMMAND_DISABLE_LOOP, NULL);
1204 
1205         /* exit out of the LOOP state to the last state */
1206         ftdm_set_state_locked(ftdmchan, ftdmchan->last_state);
1207 
1208         /* unlock the channel again before we exit */
1209         ftdm_mutex_unlock(ftdmchan->mutex);
1210 
1211         SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1212         return FTDM_SUCCESS;
1213 }
1214 
1215 /******************************************************************************/
1216 ftdm_status_t handle_cot(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt)
1217 {
1218         SS7_FUNC_TRACE_ENTER(__FUNCTION__);
1219 
1220         if ( (siStaEvnt->contInd.eh.pres > 0) && (siStaEvnt->contInd.contInd.pres > 0)) {
1221                 SS7_INFO("Continuity Test result for CIC = %d (span %d, chan %d) is: \"%s\"\n",
1222                                         g_ftdm_sngss7_data.cfg.isupCkt[circuit].cic,
1223                                         g_ftdm_sngss7_data.cfg.isupCkt[circuit].span,
1224                                         g_ftdm_sngss7_data.cfg.isupCkt[circuit].chan,
1225                                         (siStaEvnt->contInd.contInd.val) ? "PASS" : "FAIL");
1226         } else {
1227                 SS7_ERROR("Recieved Continuity report containing no results!\n");
1228         }
1229 
1230         SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1231         return FTDM_SUCCESS;
1232 }
1233 
1234 /******************************************************************************/
1235 
1236 
1237 /******************************************************************************/
1238 ftdm_status_t handle_blo_req(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt)
1239 {
1240         SS7_FUNC_TRACE_ENTER(__FUNCTION__);
1241 
1242         sngss7_chan_data_t  *sngss7_info = NULL;
1243         ftdm_channel_t    *ftdmchan = NULL;
1244 
1245         /* get the ftdmchan and ss7_chan_data from the circuit */
1246         if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
1247                 SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
1248                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1249                 return FTDM_FAIL;
1250         }
1251 
1252         /* lock the channel */
1253         ftdm_mutex_lock(ftdmchan->mutex);
1254 
1255         /* check if the circuit is already blocked or not */
1256         if (sngss7_test_flag(sngss7_info, FLAG_CKT_MN_BLOCK_RX)) {
1257                 SS7_WARN("Received BLO on circuit that is already blocked!\n");
1258         }
1259 
1260         /* throw the ckt block flag */
1261         sngss7_set_flag(sngss7_info, FLAG_CKT_MN_BLOCK_RX);
1262 
1263         /* set the channel to suspended state */
1264         ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_SUSPENDED);
1265 
1266         /* unlock the channel again before we exit */
1267         ftdm_mutex_unlock(ftdmchan->mutex);
1268 
1269         SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1270         return FTDM_SUCCESS;
1271 }
1272 
1273 /******************************************************************************/
1274 ftdm_status_t handle_blo_rsp(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt)
1275 {
1276         SS7_FUNC_TRACE_ENTER(__FUNCTION__);
1277 
1278         sngss7_chan_data_t  *sngss7_info = NULL;
1279         ftdm_channel_t    *ftdmchan = NULL;
1280 
1281         /* get the ftdmchan and ss7_chan_data from the circuit */
1282         if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
1283                 SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
1284                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1285                 return FTDM_FAIL;
1286         }
1287 
1288         /* lock the channel */
1289         ftdm_mutex_lock(ftdmchan->mutex);
1290 
1291         /* KONRAD FIX ME */
1292 
1293         /* unlock the channel again before we exit */
1294         ftdm_mutex_unlock(ftdmchan->mutex);
1295 
1296         SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1297         return FTDM_SUCCESS;
1298 }
1299 
1300 /******************************************************************************/
1301 ftdm_status_t handle_ubl_req(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt)
1302 {
1303         SS7_FUNC_TRACE_ENTER(__FUNCTION__);
1304 
1305         sngss7_chan_data_t  *sngss7_info = NULL;
1306         ftdm_channel_t    *ftdmchan = NULL;
1307 
1308         /* get the ftdmchan and ss7_chan_data from the circuit */
1309         if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
1310                 SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
1311                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1312                 return FTDM_FAIL;
1313         }
1314 
1315         /* lock the channel */
1316         ftdm_mutex_lock(ftdmchan->mutex);
1317 
1318         /* check if the channel is blocked */
1319         if (!(sngss7_test_flag(sngss7_info, FLAG_CKT_MN_BLOCK_RX))) {
1320                 SS7_WARN("Received UBL on circuit that is not blocked!\n");
1321         }
1322 
1323         /* throw the unblock flag */
1324         sngss7_set_flag(sngss7_info, FLAG_CKT_MN_UNBLK_RX);
1325 
1326         /* clear the block flag */
1327         sngss7_clear_flag(sngss7_info, FLAG_CKT_MN_BLOCK_RX);
1328 
1329         /* set the channel to suspended state */
1330         ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_SUSPENDED);
1331 
1332         /* unlock the channel again before we exit */
1333         ftdm_mutex_unlock(ftdmchan->mutex);
1334 
1335         SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1336         return FTDM_SUCCESS;
1337 }
1338 
1339 /******************************************************************************/
1340 ftdm_status_t handle_ubl_rsp(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt)
1341 {
1342         SS7_FUNC_TRACE_ENTER(__FUNCTION__);
1343 
1344         sngss7_chan_data_t  *sngss7_info = NULL;
1345         ftdm_channel_t    *ftdmchan = NULL;
1346 
1347         /* get the ftdmchan and ss7_chan_data from the circuit */
1348         if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
1349                 SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
1350                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1351                 return FTDM_FAIL;
1352         }
1353 
1354         /* lock the channel */
1355         ftdm_mutex_lock(ftdmchan->mutex);
1356 
1357         /* KONRAD FIX ME */
1358 
1359         /* unlock the channel again before we exit */
1360         ftdm_mutex_unlock(ftdmchan->mutex);
1361 
1362         SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1363         return FTDM_SUCCESS;
1364 }
1365 
1366 /******************************************************************************/
1367 ftdm_status_t handle_rsc_req(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt)
1368 {
1369         SS7_FUNC_TRACE_ENTER(__FUNCTION__);
1370 
1371         sngss7_chan_data_t  *sngss7_info = NULL;
1372         ftdm_channel_t    *ftdmchan = NULL;
1373 
1374         /* get the ftdmchan and ss7_chan_data from the circuit */
1375         if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
1376                 SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
1377                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1378                 return FTDM_FAIL;
1379         }
1380 
1381         /* lock the channel */
1382         ftdm_mutex_lock(ftdmchan->mutex);
1383 
1384         /* throw the reset flag */
1385         sngss7_set_flag(sngss7_info, FLAG_RESET_RX);
1386 
1387         switch (ftdmchan->state) {
1388         /**************************************************************************/
1389         case FTDM_CHANNEL_STATE_RESTART:
1390 
1391                 /* go to idle so that we can redo the restart state*/
1392                 ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_IDLE);
1393 
1394                 break;
1395         /**************************************************************************/
1396         default:
1397 
1398                 /* set the state of the channel to restart...the rest is done by the chan monitor */
1399                 ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_RESTART);
1400                 break;
1401         /**************************************************************************/
1402         }
1403 
1404         /* unlock the channel again before we exit */
1405         ftdm_mutex_unlock(ftdmchan->mutex);
1406 
1407         SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1408         return FTDM_SUCCESS;
1409 }
1410 
1411 /******************************************************************************/
1412 ftdm_status_t handle_local_rsc_req(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt)
1413 {
1414         SS7_FUNC_TRACE_ENTER(__FUNCTION__);
1415 
1416         sngss7_chan_data_t  *sngss7_info = NULL;
1417         ftdm_channel_t    *ftdmchan = NULL;
1418 
1419         /* get the ftdmchan and ss7_chan_data from the circuit */
1420         if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
1421                 SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
1422                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1423                 return FTDM_FAIL;
1424         }
1425 
1426         /* lock the channel */
1427         ftdm_mutex_lock(ftdmchan->mutex);
1428 
1429         /* throw the reset flag */
1430         sngss7_set_flag(sngss7_info, FLAG_RESET_RX);
1431 
1432         switch (ftdmchan->state) {
1433         /**************************************************************************/
1434         case FTDM_CHANNEL_STATE_RESTART:
1435 
1436                 /* go to idle so that we can redo the restart state*/
1437                 ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_IDLE);
1438 
1439                 break;
1440         /**************************************************************************/
1441         default:
1442 
1443                 /* set the state of the channel to restart...the rest is done by the chan monitor */
1444                 ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_RESTART);
1445                 break;
1446         /**************************************************************************/
1447         }
1448 
1449         /* unlock the channel again before we exit */
1450         ftdm_mutex_unlock(ftdmchan->mutex);
1451 
1452         SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1453         return FTDM_SUCCESS;
1454 }
1455 
1456 /******************************************************************************/
1457 ftdm_status_t handle_rsc_rsp(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt)
1458 {
1459         SS7_FUNC_TRACE_ENTER(__FUNCTION__);
1460 
1461         sngss7_chan_data_t  *sngss7_info = NULL;
1462         ftdm_channel_t    *ftdmchan = NULL;
1463 
1464         /* get the ftdmchan and ss7_chan_data from the circuit */
1465         if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
1466                 SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
1467                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1468                 return FTDM_FAIL;
1469         }
1470 
1471         /* lock the channel */
1472         ftdm_mutex_lock(ftdmchan->mutex);
1473 
1474         switch (ftdmchan->state) {
1475         /**********************************************************************/
1476         case FTDM_CHANNEL_STATE_RESTART:
1477                 
1478                 if ( sngss7_test_flag(sngss7_info, FLAG_RESET_TX) ) {
1479                         /* throw the FLAG_RESET_TX_RSP to indicate we have acknowledgement from the remote side */
1480                         sngss7_set_flag(sngss7_info, FLAG_RESET_TX_RSP);
1481 
1482                         /* go to DOWN */
1483                         ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN);
1484                 } else {
1485                         SS7_ERROR("Received RSC-RLC but we're not waiting on a RSC-RLC on CIC #, dropping\n", sngss7_info->circuit->cic);
1486                 }
1487 
1488                 break;
1489         /**********************************************************************/
1490         case FTDM_CHANNEL_STATE_DOWN:
1491                 
1492                 /* do nothing, just drop the message */
1493                 SS7_DEBUG("Receveived RSC-RLC in down state, dropping\n");
1494                 
1495                 break;
1496         /**********************************************************************/
1497         case FTDM_CHANNEL_STATE_TERMINATING:
1498         case FTDM_CHANNEL_STATE_HANGUP:
1499         case FTDM_CHANNEL_STATE_HANGUP_COMPLETE:
1500                 
1501                 /* throw the FLAG_RESET_TX_RSP to indicate we have acknowledgement from the remote side */
1502                 sngss7_set_flag(sngss7_info, FLAG_RESET_TX_RSP);
1503 
1504                 /* go to DOWN */
1505                 ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN);
1506 
1507                 break;
1508         /**********************************************************************/
1509         default:
1510                 /* ITU Q764-2.9.5.1.c -> release the circuit */
1511                 if ((siStaEvnt != NULL) &&
1512                         (siStaEvnt->causeDgn.eh.pres ==PRSNT_NODEF) &&
1513                         (siStaEvnt->causeDgn.causeVal.pres == PRSNT_NODEF)) {
1514                         ftdmchan->caller_data.hangup_cause = siStaEvnt->causeDgn.causeVal.val;
1515                 } else {
1516                         ftdmchan->caller_data.hangup_cause = 98;        /* Message not compatiable with call state */
1517                 }
1518 
1519                 ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_TERMINATING);
1520                 break;
1521         /**********************************************************************/
1522         }
1523 
1524         /* unlock the channel again before we exit */
1525         ftdm_mutex_unlock(ftdmchan->mutex);
1526 
1527         SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1528         return FTDM_SUCCESS;
1529 }
1530 /******************************************************************************/
1531 ftdm_status_t handle_grs_req(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt)
1532 {
1533         SS7_FUNC_TRACE_ENTER(__FUNCTION__);
1534 
1535         sngss7_chan_data_t      *sngss7_info = NULL;
1536         ftdm_channel_t          *ftdmchan = NULL;
1537         sngss7_span_data_t      *sngss7_span = NULL; 
1538         int                                     range;
1539 
1540 
1541         if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
1542                 SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
1543                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1544                 return FTDM_FAIL;
1545         }
1546 
1547         /* extract the range value from the event structure */
1548         if ((siStaEvnt->rangStat.eh.pres == PRSNT_NODEF) && (siStaEvnt->rangStat.range.pres == PRSNT_NODEF)) {
1549                 range = siStaEvnt->rangStat.range.val;
1550         } else {
1551                 SS7_ERROR("Received GRS with no range value on CIC = %d\n", sngss7_info->circuit->cic);
1552                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1553                 return FTDM_FAIL;
1554         }
1555 
1556         /* fill in the span structure for this circuit */
1557         sngss7_span = ftdmchan->span->mod_data;
1558         sngss7_span->rx_grs.circuit = circuit; 
1559         sngss7_span->rx_grs.range = range;
1560 
1561         /* the reset will be started in the main thread by "check_if_rx_grs_started" */
1562 
1563         SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1564         return FTDM_SUCCESS;
1565 }
1566 
1567 /******************************************************************************/
1568 ftdm_status_t handle_grs_rsp(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt)
1569 {
1570         SS7_FUNC_TRACE_ENTER(__FUNCTION__);
1571 
1572         sngss7_chan_data_t      *sngss7_info = NULL;
1573         ftdm_channel_t          *ftdmchan = NULL;
1574         sngss7_span_data_t      *sngss7_span = NULL; 
1575         int                                     range;
1576 
1577         if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
1578                 SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
1579                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1580                 return FTDM_FAIL;
1581         }
1582 
1583         /* extract the range value from the event structure */
1584         if ((siStaEvnt->rangStat.eh.pres == PRSNT_NODEF) && (siStaEvnt->rangStat.range.pres == PRSNT_NODEF)) {
1585                 range = siStaEvnt->rangStat.range.val;
1586         } else {
1587                 SS7_ERROR("Received GRA with no range value on CIC = %d\n", sngss7_info->circuit->cic);
1588                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1589                 return FTDM_FAIL;
1590         }
1591 
1592         /* fill in the span structure for this circuit */
1593         sngss7_span = ftdmchan->span->mod_data;
1594         sngss7_span->rx_gra.circuit = circuit; 
1595         sngss7_span->rx_gra.range = range;
1596 
1597         /* check if there is a cause value in the GRA */
1598         if ((siStaEvnt != NULL) &&
1599                 (siStaEvnt->causeDgn.eh.pres == PRSNT_NODEF) &&
1600                 (siStaEvnt->causeDgn.causeVal.pres == PRSNT_NODEF)) {
1601 
1602                 sngss7_span->rx_gra.cause = siStaEvnt->causeDgn.causeVal.val;
1603         }
1604 
1605         /* the reset will be started in the main thread by "check_if_rx_gra_started" */
1606         
1607         SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1608         return FTDM_SUCCESS;
1609 }
1610 
1611 /******************************************************************************/
1612 ftdm_status_t handle_local_blk(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt)
1613 {
1614         SS7_FUNC_TRACE_ENTER(__FUNCTION__);
1615 
1616         sngss7_chan_data_t  *sngss7_info = NULL;
1617         ftdm_channel_t    *ftdmchan = NULL;
1618 
1619         /* get the ftdmchan and ss7_chan_data from the circuit */
1620         if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
1621                 SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
1622                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1623                 return FTDM_FAIL;
1624         }
1625 
1626         /* lock the channel */
1627         ftdm_mutex_lock(ftdmchan->mutex);
1628 
1629         /* check if the circuit is already blocked or not */
1630         if (sngss7_test_flag(sngss7_info, FLAG_CKT_LC_BLOCK_RX)) {
1631                 SS7_WARN("Received local BLO on circuit that is already blocked!\n");
1632         }
1633 
1634         /* throw the ckt block flag */
1635         sngss7_set_flag(sngss7_info, FLAG_CKT_LC_BLOCK_RX);
1636 
1637         /* set the channel to suspended state */
1638         ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_SUSPENDED);
1639 
1640         /* unlock the channel again before we exit */
1641         ftdm_mutex_unlock(ftdmchan->mutex);
1642 
1643         SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1644         return FTDM_SUCCESS;
1645 }
1646 
1647 /******************************************************************************/
1648 ftdm_status_t handle_local_ubl(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt)
1649 {
1650         SS7_FUNC_TRACE_ENTER(__FUNCTION__);
1651 
1652         sngss7_chan_data_t  *sngss7_info = NULL;
1653         ftdm_channel_t    *ftdmchan = NULL;
1654 
1655         /* get the ftdmchan and ss7_chan_data from the circuit */
1656         if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
1657                 SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
1658                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1659                 return FTDM_FAIL;
1660         }
1661 
1662         /* lock the channel */
1663         ftdm_mutex_lock(ftdmchan->mutex);
1664 
1665         /* check if the circuit is already blocked or not */
1666         if (sngss7_test_flag(sngss7_info, FLAG_CKT_LC_UNBLK_RX)) {
1667                 SS7_WARN("Received local UBL on circuit that is already unblocked!\n");
1668         }
1669 
1670         /* throw the ckt block flag */
1671         sngss7_set_flag(sngss7_info, FLAG_CKT_LC_UNBLK_RX);
1672 
1673         /* set the channel to suspended state */
1674         ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_SUSPENDED);
1675 
1676         /* unlock the channel again before we exit */
1677         ftdm_mutex_unlock(ftdmchan->mutex);
1678 
1679         SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1680         return FTDM_SUCCESS;
1681 }
1682 
1683 /******************************************************************************/
1684 ftdm_status_t handle_ucic(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt)
1685 {
1686         SS7_FUNC_TRACE_ENTER(__FUNCTION__);
1687 
1688         sngss7_chan_data_t  *sngss7_info = NULL;
1689         ftdm_channel_t    *ftdmchan = NULL;
1690 
1691         /* get the ftdmchan and ss7_chan_data from the circuit */
1692         if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
1693                 SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
1694                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1695                 return FTDM_FAIL;
1696         }
1697 
1698         /* lock the channel */
1699         ftdm_mutex_lock(ftdmchan->mutex);
1700 
1701         /* throw the ckt block flag */
1702         sngss7_set_flag(sngss7_info, FLAG_CKT_UCIC_BLOCK);
1703 
1704         /* set the channel to suspended state */
1705         ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_SUSPENDED);
1706 
1707         /* unlock the channel again before we exit */
1708         ftdm_mutex_unlock(ftdmchan->mutex);
1709 
1710         SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1711         return FTDM_SUCCESS;
1712 }
1713 
1714 /******************************************************************************/
1715 ftdm_status_t handle_cgb_req(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt)
1716 {
1717         SS7_FUNC_TRACE_ENTER(__FUNCTION__);
1718 
1719         sngss7_chan_data_t      *sngss7_info = NULL;
1720         sngss7_span_data_t      *sngss7_span = NULL;
1721         ftdm_channel_t          *ftdmchan = NULL;
1722         int                                     range;
1723         uint8_t                         status[255];
1724         int                                     blockType = 0;
1725         int                                     byte = 0;
1726         int                                     bit = 0;
1727         int                             x;
1728         ftdm_sigmsg_t           sigev;
1729 
1730         memset(&sigev, 0, sizeof (sigev));
1731         memset(&status[0], '\0', sizeof(status));
1732 
1733         /* get the ftdmchan and ss7_chan_data from the circuit */
1734         if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
1735                 SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
1736                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1737                 return FTDM_FAIL;
1738         }
1739 
1740         /* grab the span info */
1741         sngss7_span = ftdmchan->span->mod_data;
1742 
1743         /* figure out what type of block needs to be applied */
1744         if ((siStaEvnt->cgsmti.eh.pres == PRSNT_NODEF) && (siStaEvnt->cgsmti.typeInd.pres == PRSNT_NODEF)) {
1745                 blockType = siStaEvnt->cgsmti.typeInd.val;
1746         } else {
1747                 SS7_ERROR("Received CGB with no circuit group supervision value on CIC = %d\n", sngss7_info->circuit->cic);
1748                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1749                 return FTDM_FAIL;
1750         }       
1751 
1752         /* pull out the range value */
1753         if ((siStaEvnt->rangStat.eh.pres == PRSNT_NODEF) && (siStaEvnt->rangStat.range.pres == PRSNT_NODEF)) {
1754                 range = siStaEvnt->rangStat.range.val;
1755         } else {
1756                 SS7_ERROR("Received CGB with no range value on CIC = %d\n", sngss7_info->circuit->cic);
1757                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1758                 return FTDM_FAIL;
1759         }
1760 
1761         /* pull out the status field */
1762         if ((siStaEvnt->rangStat.eh.pres == PRSNT_NODEF) && (siStaEvnt->rangStat.status.pres == PRSNT_NODEF)) {
1763                 for (x = 0; x < siStaEvnt->rangStat.status.len; x++) {
1764                         status[x] = siStaEvnt->rangStat.status.val[x];
1765                 }
1766         } else {
1767                 SS7_ERROR("Received CGB with no status value on CIC = %d\n", sngss7_info->circuit->cic);
1768                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1769                 return FTDM_FAIL;
1770         }
1771 
1772         /* save the circuit, range and status */
1773         sngss7_span->rx_cgb.circuit = circuit;
1774         sngss7_span->rx_cgb.range = range;
1775         sngss7_span->rx_cgb.type = blockType;
1776         for (x = 0; x < siStaEvnt->rangStat.status.len; x++) {
1777                 sngss7_span->rx_cgb.status[x] = status[x];
1778         }
1779 
1780         /* loop over the cics starting from circuit until range+1 */
1781         for (x = circuit; x < (circuit + range + 1); x++) {
1782                 /* confirm this is a voice channel */
1783                 if (g_ftdm_sngss7_data.cfg.isupCkt[x].type != VOICE) continue;
1784 
1785                 /* grab the circuit in question */
1786                 if (extract_chan_data(x, &sngss7_info, &ftdmchan)) {
1787                         SS7_ERROR("Failed to extract channel data for circuit = %d!\n", x);
1788                         break;
1789                 }
1790         
1791                 /* lock the channel */
1792                 ftdm_mutex_lock(ftdmchan->mutex);
1793 
1794 #if 0
1795                 SS7_ERROR("KONRAD -> circuit=%d, byte=%d, bit=%d, status[byte]=%d, math=%d\n",
1796                                         x,
1797                                         byte,
1798                                         bit,
1799                                         status[byte],
1800                                         (status[byte] & (1 << bit)));
1801 #endif
1802                 if (status[byte] & (1 << bit)) {
1803                         switch (blockType) {
1804                         /**********************************************************************/
1805                         case 0: /* maintenance oriented */
1806                                 sngss7_set_flag(sngss7_info, FLAG_GRP_MN_BLOCK_RX);
1807                                 break;
1808                         /**********************************************************************/
1809                         case 1: /* hardware failure oriented */
1810                                 sngss7_set_flag(sngss7_info, FLAG_GRP_HW_BLOCK_RX);
1811                                 break;
1812                         /**********************************************************************/
1813                         case 2: /* reserved for national use */
1814                                 break;
1815                         /**********************************************************************/
1816                         default:
1817                                 break;
1818                         /**********************************************************************/
1819                         } /* switch (blockType) */
1820                 }
1821 
1822                 sigev.chan_id = ftdmchan->chan_id;
1823                 sigev.span_id = ftdmchan->span_id;
1824                 sigev.channel = ftdmchan;
1825 
1826                 /* bring the sig status down */
1827                 sigev.event_id = FTDM_SIGEVENT_SIGSTATUS_CHANGED;
1828                 sigev.sigstatus = FTDM_SIG_STATE_DOWN;
1829                 ftdm_span_send_signal(ftdmchan->span, &sigev);
1830 
1831                 /* unlock the channel again before we exit */
1832                 ftdm_mutex_unlock(ftdmchan->mutex);
1833 
1834                 /* update the bit and byte counter*/
1835                 bit ++;
1836                 if (bit == 8) {
1837                         byte++;
1838                         bit = 0;
1839                 }
1840 
1841         } /* for (x = circuit; x < (circuit + range + 1); x++) */
1842 
1843         /* get the ftdmchan and ss7_chan_data from the circuit */
1844         if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
1845                 SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
1846                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1847                 return FTDM_FAIL;
1848         }
1849 
1850         ft_to_sngss7_cgba(ftdmchan);
1851 
1852         return FTDM_SUCCESS;
1853 }
1854 
1855 /******************************************************************************/
1856 ftdm_status_t handle_cgu_req(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt)
1857 {
1858         SS7_FUNC_TRACE_ENTER(__FUNCTION__);
1859 
1860         sngss7_chan_data_t      *sngss7_info = NULL;
1861         sngss7_span_data_t      *sngss7_span = NULL;
1862         ftdm_channel_t          *ftdmchan = NULL;
1863         int                                     range;
1864         uint8_t                         status[255];
1865         int                                     blockType = 0;
1866         int                                     byte = 0;
1867         int                                     bit = 0;
1868         int                             x;
1869         ftdm_sigmsg_t           sigev;
1870 
1871         memset(&sigev, 0, sizeof (sigev));
1872         memset(&status[0], '\0', sizeof(status));
1873 
1874         /* get the ftdmchan and ss7_chan_data from the circuit */
1875         if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
1876                 SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
1877                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1878                 return FTDM_FAIL;
1879         }
1880 
1881         /* grab the span info */
1882         sngss7_span = ftdmchan->span->mod_data;
1883 
1884         /* figure out what type of block needs to be applied */
1885         if ((siStaEvnt->cgsmti.eh.pres == PRSNT_NODEF) && (siStaEvnt->cgsmti.typeInd.pres == PRSNT_NODEF)) {
1886                 blockType = siStaEvnt->cgsmti.typeInd.val;
1887         } else {
1888                 SS7_ERROR("Received CGU with no circuit group supervision value on CIC = %d\n", sngss7_info->circuit->cic);
1889                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1890                 return FTDM_FAIL;
1891         }       
1892 
1893         /* pull out the range value */
1894         if ((siStaEvnt->rangStat.eh.pres == PRSNT_NODEF) && (siStaEvnt->rangStat.range.pres == PRSNT_NODEF)) {
1895                 range = siStaEvnt->rangStat.range.val;
1896         } else {
1897                 SS7_ERROR("Received CGU with no range value on CIC = %d\n", sngss7_info->circuit->cic);
1898                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1899                 return FTDM_FAIL;
1900         }
1901 
1902         /* pull out the status field */
1903         if ((siStaEvnt->rangStat.eh.pres == PRSNT_NODEF) && (siStaEvnt->rangStat.status.pres == PRSNT_NODEF)) {
1904                 for (x = 0; x < siStaEvnt->rangStat.status.len; x++) {
1905                         status[x] = siStaEvnt->rangStat.status.val[x];
1906                 }
1907         } else {
1908                 SS7_ERROR("Received CGU with no status value on CIC = %d\n", sngss7_info->circuit->cic);
1909                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1910                 return FTDM_FAIL;
1911         }
1912 
1913         /* save the circuit, range and status */
1914         sngss7_span->rx_cgu.circuit = circuit;
1915         sngss7_span->rx_cgu.range = range;
1916         sngss7_span->rx_cgu.type = blockType;
1917         for (x = 0; x < siStaEvnt->rangStat.status.len; x++) {
1918                 sngss7_span->rx_cgu.status[x] = status[x];
1919         }
1920 
1921         /* loop over the cics starting from circuit until range+1 */
1922         for (x = circuit; x < (circuit + range + 1); x++) {
1923                 if (g_ftdm_sngss7_data.cfg.isupCkt[x].type != VOICE) continue;
1924                 /* grab the circuit in question */
1925                 if (extract_chan_data(x, &sngss7_info, &ftdmchan)) {
1926                         SS7_ERROR("Failed to extract channel data for circuit = %d!\n", x);
1927                         break;
1928                 }
1929         
1930                 /* lock the channel */
1931                 ftdm_mutex_lock(ftdmchan->mutex);
1932 
1933                 if (status[byte] & (1 << bit)) {
1934                         switch (blockType) {
1935                         /**********************************************************************/
1936                         case 0: /* maintenance oriented */
1937                                 sngss7_clear_flag(sngss7_info, FLAG_GRP_MN_BLOCK_RX);
1938                                 break;
1939                         /**********************************************************************/
1940                         case 1: /* hardware failure oriented */
1941                                 sngss7_clear_flag(sngss7_info, FLAG_GRP_HW_BLOCK_RX);
1942                                 break;
1943                         /**********************************************************************/
1944                         case 2: /* reserved for national use */
1945                                 break;
1946                         /**********************************************************************/
1947                         default:
1948                                 break;
1949                         /**********************************************************************/
1950                         } /* switch (blockType) */
1951                 } /* if (status[byte] & (1 << bit)) */
1952 
1953                 sigev.chan_id = ftdmchan->chan_id;
1954                 sigev.span_id = ftdmchan->span_id;
1955                 sigev.channel = ftdmchan;
1956 
1957                 /* bring the sig status down */
1958                 sigev.event_id = FTDM_SIGEVENT_SIGSTATUS_CHANGED;
1959                 sigev.sigstatus = FTDM_SIG_STATE_UP;
1960                 ftdm_span_send_signal(ftdmchan->span, &sigev);
1961         
1962                 /* unlock the channel again before we exit */
1963                 ftdm_mutex_unlock(ftdmchan->mutex);
1964 
1965                 /* update the bit and byte counter*/
1966                 bit ++;
1967                 if (bit == 8) {
1968                         byte++;
1969                         bit = 0;
1970                 }
1971 
1972         } /* for (x = circuit; x < (circuit + range + 1); x++) */
1973 
1974         /* get the ftdmchan and ss7_chan_data from the circuit */
1975         if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) {
1976                 SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit);
1977                 SS7_FUNC_TRACE_EXIT(__FUNCTION__);
1978                 return FTDM_FAIL;
1979         }
1980 
1981         ft_to_sngss7_cgua(ftdmchan);
1982 
1983         return FTDM_SUCCESS;
1984 }
1985 
1986 /******************************************************************************/
1987 /* For Emacs:
1988  * Local Variables:
1989  * mode:c
1990  * indent-tabs-mode:t
1991  * tab-width:4
1992  * c-basic-offset:4
1993  * End:
1994  * For VIM:
1995  * vim:set softtabstop=4 shiftwidth=4 tabstop=4:
1996  */
1997 /******************************************************************************/

/* [<][>][^][v][top][bottom][index][help] */