root/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_cntrl.c

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

DEFINITIONS

This source file includes following definitions.
  1. sng_isdn_stack_start
  2. sng_isdn_stack_stop
  3. sng_isdn_activate_phy
  4. sng_isdn_deactivate_phy
  5. sng_isdn_activate_cc
  6. sng_isdn_activate_trace
  7. sng_isdn_cntrl_q931
  8. sng_isdn_cntrl_q921
  9. stack_resp_hdr_init

   1 /*
   2  * Copyright (c) 2010, Sangoma Technologies 
   3  * David Yat Sin <davidy@sangoma.com>
   4  * Moises Silva <moy@sangoma.com>
   5  * All rights reserved.
   6  *
   7  * Redistribution and use in source and binary forms, with or without
   8  * modification, are permitted provided that the following conditions
   9  * are met:
  10  *
  11  * * Redistributions of source code must retain the above copyright
  12  * notice, this list of conditions and the following disclaimer.
  13  *
  14  * * Redistributions in binary form must reproduce the above copyright
  15  * notice, this list of conditions and the following disclaimer in the
  16  * documentation and/or other materials provided with the distribution.
  17  *
  18  * * Neither the name of the original author; nor the names of any contributors
  19  * may be used to endorse or promote products derived from this software
  20  * without specific prior written permission.
  21  *
  22  *
  23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  26  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER
  27  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  31  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  32  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34  */
  35 
  36 #include "ftmod_sangoma_isdn.h"
  37 
  38 void stack_resp_hdr_init(Header *hdr);
  39 
  40 ftdm_status_t sng_isdn_activate_phy(ftdm_span_t *span);
  41 ftdm_status_t sng_isdn_deactivate_phy(ftdm_span_t *span);
  42 
  43 ftdm_status_t sng_isdn_activate_cc(ftdm_span_t *span);
  44 ftdm_status_t sng_isdn_activate_trace(ftdm_span_t *span, sngisdn_tracetype_t trace_opt);
  45 
  46 ftdm_status_t sng_isdn_cntrl_q931(ftdm_span_t *span, uint8_t action, uint8_t subaction);
  47 ftdm_status_t sng_isdn_cntrl_q921(ftdm_span_t *span, uint8_t action, uint8_t subaction);
  48 
  49 
  50 extern ftdm_sngisdn_data_t      g_sngisdn_data;
  51 
  52 ftdm_status_t sng_isdn_stack_stop(ftdm_span_t *span);
  53 
  54 
  55 ftdm_status_t sng_isdn_stack_start(ftdm_span_t *span)
  56 {
  57         sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*)span->signal_data;
  58 
  59         
  60         if (sng_isdn_cntrl_q921(span, ABND_ENA, NOTUSED) != FTDM_SUCCESS) {
  61                 ftdm_log(FTDM_LOG_CRIT, "%s:Failed to activate stack q921\n", span->name);
  62                 return FTDM_FAIL;
  63         }
  64 
  65         /* Try to find an alternative for this */
  66         /* LAPD will call LdUiDatBndCfm before it received a LdLiMacBndCfm from L1,
  67         so we need to give some time before activating q931, as q931 will send a
  68         LdUiDatConReq when activated, and this requires the Mac SAP to be already
  69         bound first */
  70         ftdm_sleep(500); 
  71         
  72         ftdm_log(FTDM_LOG_DEBUG, "%s:Stack q921 activated\n", span->name);
  73         if (!g_sngisdn_data.ccs[signal_data->cc_id].activation_done) {
  74                 g_sngisdn_data.ccs[signal_data->cc_id].activation_done = 1;
  75                 if (sng_isdn_activate_cc(span) != FTDM_SUCCESS) {
  76                         ftdm_log(FTDM_LOG_CRIT, "%s:Failed to activate stack CC\n", span->name);
  77                         return FTDM_FAIL;
  78                 }
  79                 ftdm_log(FTDM_LOG_DEBUG, "%s:Stack CC activated\n", span->name);
  80         }
  81 
  82         
  83         if (sng_isdn_cntrl_q931(span, ABND_ENA, SAELMNT) != FTDM_SUCCESS) {
  84                 ftdm_log(FTDM_LOG_CRIT, "%s:Failed to activate stack q931\n", span->name);
  85                 return FTDM_FAIL;
  86         }
  87         ftdm_log(FTDM_LOG_DEBUG, "%s:Stack q931 activated\n", span->name);
  88 
  89         ftdm_log(FTDM_LOG_INFO, "%s:Stack activated\n",span->name);
  90         return FTDM_SUCCESS;
  91 }
  92 
  93 ftdm_status_t sng_isdn_stack_stop(ftdm_span_t *span)
  94 {
  95         /* Stop L1 first, so we do not receive any more frames */
  96         if (sng_isdn_deactivate_phy(span) != FTDM_SUCCESS) {
  97                 ftdm_log(FTDM_LOG_CRIT, "%s:Failed to deactivate stack phy\n", span->name);
  98                 return FTDM_FAIL;
  99         }
 100 
 101         if (sng_isdn_cntrl_q931(span, AUBND_DIS, SAELMNT) != FTDM_SUCCESS) {
 102                 ftdm_log(FTDM_LOG_CRIT, "%s:Failed to deactivate stack q931\n", span->name);
 103                 return FTDM_FAIL;
 104         }
 105 
 106         if (sng_isdn_cntrl_q921(span, AUBND_DIS, SAELMNT) != FTDM_SUCCESS) {
 107                 ftdm_log(FTDM_LOG_CRIT, "%s:Failed to deactivate stack q921\n", span->name);
 108                 return FTDM_FAIL;
 109         }
 110         
 111         ftdm_log(FTDM_LOG_INFO, "%s:Signalling stopped\n", span->name);
 112         return FTDM_SUCCESS;
 113 }
 114 
 115 
 116 ftdm_status_t sng_isdn_activate_phy(ftdm_span_t *span)
 117 {
 118 
 119         /* There is no need to start phy, as it will Q921 will send a activate request to phy when it starts */
 120         
 121         return FTDM_SUCCESS;
 122 }
 123 
 124 ftdm_status_t sng_isdn_deactivate_phy(ftdm_span_t *span)
 125 {
 126         L1Mngmt cntrl;
 127         Pst pst;
 128 
 129         sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*)span->signal_data;
 130 
 131         /* initalize the post structure */
 132         stack_pst_init(&pst);
 133 
 134         /* insert the destination Entity */
 135         pst.dstEnt = ENTL1;
 136 
 137         /* initalize the control structure */
 138         memset(&cntrl, 0, sizeof(cntrl));
 139 
 140         /* initalize the control header */
 141         stack_hdr_init(&cntrl.hdr);
 142 
 143         cntrl.hdr.msgType = TCNTRL;                     /* configuration */
 144         cntrl.hdr.entId.ent = ENTL1;            /* entity */
 145         cntrl.hdr.entId.inst = S_INST;          /* instance */
 146         cntrl.hdr.elmId.elmnt = STTSAP;         /* SAP Specific cntrl */
 147 
 148         cntrl.t.cntrl.action = AUBND_DIS;
 149         cntrl.t.cntrl.subAction = SAELMNT;
 150         cntrl.t.cntrl.sapId = signal_data->link_id;
 151         
 152         if (sng_isdn_phy_cntrl(&pst, &cntrl)) {
 153                 return FTDM_FAIL;
 154         }
 155         return FTDM_SUCCESS;
 156 }
 157 
 158 
 159 ftdm_status_t sng_isdn_activate_cc(ftdm_span_t *span)
 160 {
 161         CcMngmt cntrl;;
 162     Pst pst;
 163 
 164         sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*)span->signal_data;
 165 
 166     /* initalize the post structure */
 167    stack_pst_init(&pst);
 168 
 169     /* insert the destination Entity */
 170     pst.dstEnt = ENTCC;
 171 
 172     /* initalize the control structure */
 173         memset(&cntrl, 0, sizeof(cntrl));
 174 
 175     /* initalize the control header */
 176     stack_hdr_init(&cntrl.hdr);
 177 
 178         cntrl.hdr.msgType = TCNTRL;                     /* configuration */
 179         cntrl.hdr.entId.ent = ENTCC;            /* entity */
 180         cntrl.hdr.entId.inst = S_INST;          /* instance */
 181         cntrl.hdr.elmId.elmnt = STTSAP;         /* physical sap */
 182 
 183         cntrl.t.cntrl.action = ABND_ENA;
 184         cntrl.t.cntrl.subAction = SAELMNT;
 185 
 186         cntrl.t.cntrl.sapId = signal_data->cc_id;
 187         if (sng_isdn_cc_cntrl(&pst, &cntrl)) {
 188                 return FTDM_FAIL;
 189         }
 190         return FTDM_SUCCESS;
 191 }
 192 
 193 ftdm_status_t sng_isdn_activate_trace(ftdm_span_t *span, sngisdn_tracetype_t trace_opt)
 194 {
 195         sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*)span->signal_data;
 196         switch (trace_opt) {
 197                 case SNGISDN_TRACE_DISABLE:
 198                         if (sngisdn_test_trace_flag(signal_data, SNGISDN_TRACE_Q921)) {
 199                                 ftdm_log(FTDM_LOG_INFO, "s%d Disabling q921 trace\n", signal_data->link_id);
 200                                 sngisdn_clear_trace_flag(signal_data, SNGISDN_TRACE_Q921);
 201                                 
 202                                 if (sng_isdn_cntrl_q921(span, ADISIMM, SATRC) != FTDM_SUCCESS) {
 203                                         ftdm_log(FTDM_LOG_ERROR, "s%d Failed to disable q921 trace\n");
 204                                 }
 205                         }
 206                         if (sngisdn_test_trace_flag(signal_data, SNGISDN_TRACE_Q931)) {
 207                                 ftdm_log(FTDM_LOG_INFO, "s%d Disabling q931 trace\n", signal_data->link_id);
 208                                 sngisdn_clear_trace_flag(signal_data, SNGISDN_TRACE_Q931);
 209 
 210                                 if (sng_isdn_cntrl_q931(span, ADISIMM, SATRC) != FTDM_SUCCESS) {
 211                                         ftdm_log(FTDM_LOG_ERROR, "s%d Failed to disable q931 trace\n");
 212                                 }
 213                         }
 214                         break;
 215                 case SNGISDN_TRACE_Q921:
 216                         if (!sngisdn_test_trace_flag(signal_data, SNGISDN_TRACE_Q921)) {
 217                                 ftdm_log(FTDM_LOG_INFO, "s%d Enabling q921 trace\n", signal_data->link_id);
 218                                 sngisdn_set_trace_flag(signal_data, SNGISDN_TRACE_Q921);
 219 
 220                                 if (sng_isdn_cntrl_q921(span, AENA, SATRC) != FTDM_SUCCESS) {
 221                                         ftdm_log(FTDM_LOG_ERROR, "s%d Failed to enable q921 trace\n");
 222                                 }
 223                         }
 224                         break;
 225                 case SNGISDN_TRACE_Q931:
 226                         if (!sngisdn_test_trace_flag(signal_data, SNGISDN_TRACE_Q931)) {
 227                                 ftdm_log(FTDM_LOG_INFO, "s%d Enabling q931 trace\n", signal_data->link_id);
 228                                 sngisdn_set_trace_flag(signal_data, SNGISDN_TRACE_Q931);
 229                                 
 230                                 if (sng_isdn_cntrl_q931(span, AENA, SATRC) != FTDM_SUCCESS) {
 231                                         ftdm_log(FTDM_LOG_ERROR, "s%d Failed to enable q931 trace\n");
 232                                 }
 233                         }
 234                         break;
 235         }
 236         return FTDM_SUCCESS;
 237 }
 238 
 239 
 240 ftdm_status_t sng_isdn_cntrl_q931(ftdm_span_t *span, uint8_t action, uint8_t subaction)
 241 {
 242         InMngmt cntrl;;
 243         Pst pst;
 244         sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*)span->signal_data;
 245 
 246         /* initalize the post structure */
 247         stack_pst_init(&pst);
 248 
 249         /* insert the destination Entity */
 250         pst.dstEnt = ENTIN;
 251 
 252         /* initalize the control structure */
 253         memset(&cntrl, 0, sizeof(cntrl));
 254 
 255         /* initalize the control header */
 256         stack_hdr_init(&cntrl.hdr);
 257 
 258         cntrl.hdr.msgType = TCNTRL;                     /* configuration */
 259         cntrl.hdr.entId.ent = ENTIN;            /* entity */
 260         cntrl.hdr.entId.inst = S_INST;          /* instance */
 261         cntrl.hdr.elmId.elmnt = STDLSAP;        /* physical sap */
 262 
 263         cntrl.t.cntrl.action = action;
 264         cntrl.t.cntrl.subAction = subaction;
 265 
 266         if (action == AENA && subaction == SATRC) {
 267                 cntrl.t.cntrl.trcLen = -1; /* Trace the entire message buffer */
 268         }
 269         cntrl.t.cntrl.sapId = signal_data->link_id;
 270         cntrl.t.cntrl.ces = 0;
 271 
 272         if(sng_isdn_q931_cntrl(&pst, &cntrl)) {
 273                 return FTDM_FAIL;
 274         }
 275         return FTDM_SUCCESS;    
 276 
 277 }
 278 
 279 ftdm_status_t sng_isdn_cntrl_q921(ftdm_span_t *span, uint8_t action, uint8_t subaction)
 280 {
 281         BdMngmt cntrl;
 282         Pst pst;
 283         sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*)span->signal_data;
 284 
 285         /* initalize the post structure */
 286         stack_pst_init(&pst);
 287 
 288         /* insert the destination Entity */
 289         pst.dstEnt = ENTLD;
 290 
 291         /* initalize the control structure */
 292         memset(&cntrl, 0, sizeof(cntrl));
 293 
 294         /* initalize the control header */
 295         stack_hdr_init(&cntrl.hdr);
 296         /* build control request */
 297         cntrl.hdr.msgType          = TCNTRL;
 298         cntrl.hdr.entId.ent        = ENTLD;
 299         cntrl.hdr.entId.inst       = S_INST;
 300 
 301 #if (SMBD_LMINT3 || BD_LMINT3)
 302         stack_resp_hdr_init(&cntrl.hdr);
 303 #endif /* _LMINT3 */
 304 
 305         cntrl.hdr.elmId.elmnt      = STMSAP;
 306         cntrl.t.cntrl.action       = action;
 307         cntrl.t.cntrl.subAction    = subaction;
 308 
 309 #if (SMBD_LMINT3 || BD_LMINT3)
 310         cntrl.t.cntrl.lnkNmb       = signal_data->link_id;
 311         cntrl.t.cntrl.sapi         = NOTUSED;
 312         cntrl.t.cntrl.tei          = NOTUSED;
 313 #else /* _LMINT3 */
 314         cntrl.hdr.elmId.elmntInst1 = signal_data->link_id;
 315         cntrl.hdr.elmId.elmntInst2 = NOTUSED;
 316         cntrl.hdr.elmId.elmntInst3 = NOTUSED;
 317 #endif /* _LMINT3 */
 318 
 319         cntrl.t.cntrl.logInt       = NOTUSED;
 320         cntrl.t.cntrl.trcLen       = NOTUSED;
 321         if (action == AENA && subaction == SATRC) {
 322                 cntrl.t.cntrl.trcLen = -1; /* Trace the entire message buffer */
 323         }
 324 
 325         SGetDateTime(&(cntrl.t.cntrl.dt));
 326         if(sng_isdn_q921_cntrl(&pst, &cntrl)) {
 327                 return FTDM_FAIL;
 328         }
 329 
 330         return FTDM_SUCCESS;
 331 }
 332 
 333 
 334 void stack_resp_hdr_init(Header *hdr)
 335 { 
 336         hdr->response.selector   = 0;
 337         hdr->response.mem.region = RTESPEC;
 338         hdr->response.mem.pool   = S_POOL;
 339         hdr->response.prior      = PRIOR0;
 340         hdr->response.route      = RTESPEC;
 341 
 342         return;
 343 }
 344 
 345 
 346 
 347 /* For Emacs:
 348  * Local Variables:
 349  * mode:c
 350  * indent-tabs-mode:t
 351  * tab-width:4
 352  * c-basic-offset:4
 353  * End:
 354  * For VIM:
 355  * vim:set softtabstop=4 shiftwidth=4 tabstop=4:
 356  */
 357 
 358 /******************************************************************************/

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