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. sngisdn_stack_start
  2. sngisdn_stack_stop
  3. sngisdn_activate_phy
  4. sngisdn_deactivate_phy
  5. sngisdn_wake_up_phy
  6. sngisdn_activate_cc
  7. sngisdn_activate_trace
  8. sngisdn_cntrl_q931
  9. sngisdn_cntrl_q921
  10. 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 sngisdn_activate_phy(ftdm_span_t *span);
  41 ftdm_status_t sngisdn_deactivate_phy(ftdm_span_t *span);
  42 
  43 ftdm_status_t sngisdn_activate_cc(ftdm_span_t *span);
  44 
  45 ftdm_status_t sngisdn_cntrl_q931(ftdm_span_t *span, uint8_t action, uint8_t subaction);
  46 ftdm_status_t sngisdn_cntrl_q921(ftdm_span_t *span, uint8_t action, uint8_t subaction);
  47 
  48 
  49 extern ftdm_sngisdn_data_t      g_sngisdn_data;
  50 
  51 ftdm_status_t sngisdn_stack_stop(ftdm_span_t *span);
  52 
  53 
  54 ftdm_status_t sngisdn_stack_start(ftdm_span_t *span)
  55 {
  56         sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*)span->signal_data;
  57 
  58         
  59         if (sngisdn_cntrl_q921(span, ABND_ENA, NOTUSED) != FTDM_SUCCESS) {
  60                 ftdm_log(FTDM_LOG_CRIT, "%s:Failed to activate stack q921\n", span->name);
  61                 return FTDM_FAIL;
  62         }
  63 
  64         /* Try to find an alternative for this */
  65         /* LAPD will call LdUiDatBndCfm before it received a LdLiMacBndCfm from L1,
  66         so we need to give some time before activating q931, as q931 will send a
  67         LdUiDatConReq when activated, and this requires the Mac SAP to be already
  68         bound first */
  69         ftdm_sleep(500); 
  70         
  71         ftdm_log(FTDM_LOG_DEBUG, "%s:Stack q921 activated\n", span->name);
  72         if (!g_sngisdn_data.ccs[signal_data->cc_id].activation_done) {
  73                 g_sngisdn_data.ccs[signal_data->cc_id].activation_done = 1;
  74                 if (sngisdn_activate_cc(span) != FTDM_SUCCESS) {
  75                         ftdm_log(FTDM_LOG_CRIT, "%s:Failed to activate stack CC\n", span->name);
  76                         return FTDM_FAIL;
  77                 }
  78                 ftdm_log(FTDM_LOG_DEBUG, "%s:Stack CC activated\n", span->name);
  79         }
  80 
  81         
  82         if (sngisdn_cntrl_q931(span, ABND_ENA, SAELMNT) != FTDM_SUCCESS) {
  83                 ftdm_log(FTDM_LOG_CRIT, "%s:Failed to activate stack q931\n", span->name);
  84                 return FTDM_FAIL;
  85         }
  86         ftdm_log(FTDM_LOG_DEBUG, "%s:Stack q931 activated\n", span->name);
  87 
  88         ftdm_log(FTDM_LOG_INFO, "%s:Stack activated\n",span->name);
  89         return FTDM_SUCCESS;
  90 }
  91 
  92 ftdm_status_t sngisdn_stack_stop(ftdm_span_t *span)
  93 {
  94         /* Stop L1 first, so we do not receive any more frames */
  95         if (sngisdn_deactivate_phy(span) != FTDM_SUCCESS) {
  96                 ftdm_log(FTDM_LOG_CRIT, "%s:Failed to deactivate stack phy\n", span->name);
  97                 return FTDM_FAIL;
  98         }
  99 
 100         if (sngisdn_cntrl_q931(span, AUBND_DIS, SAELMNT) != FTDM_SUCCESS) {
 101                 ftdm_log(FTDM_LOG_CRIT, "%s:Failed to deactivate stack q931\n", span->name);
 102                 return FTDM_FAIL;
 103         }
 104 
 105         if (sngisdn_cntrl_q921(span, AUBND_DIS, SAELMNT) != FTDM_SUCCESS) {
 106                 ftdm_log(FTDM_LOG_CRIT, "%s:Failed to deactivate stack q921\n", span->name);
 107                 return FTDM_FAIL;
 108         }
 109         
 110         ftdm_log(FTDM_LOG_INFO, "%s:Signalling stopped\n", span->name);
 111         return FTDM_SUCCESS;
 112 }
 113 
 114 
 115 ftdm_status_t sngisdn_activate_phy(ftdm_span_t *span)
 116 {
 117 
 118         /* There is no need to start phy, as it will Q921 will send a activate request to phy when it starts */
 119         
 120         return FTDM_SUCCESS;
 121 }
 122 
 123 ftdm_status_t sngisdn_deactivate_phy(ftdm_span_t *span)
 124 {
 125         L1Mngmt cntrl;
 126         Pst pst;
 127 
 128         sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*)span->signal_data;
 129 
 130         /* initalize the post structure */
 131         stack_pst_init(&pst);
 132 
 133         /* insert the destination Entity */
 134         pst.dstEnt = ENTL1;
 135 
 136         /* initalize the control structure */
 137         memset(&cntrl, 0, sizeof(cntrl));
 138 
 139         /* initalize the control header */
 140         stack_hdr_init(&cntrl.hdr);
 141 
 142         cntrl.hdr.msgType = TCNTRL;                     /* configuration */
 143         cntrl.hdr.entId.ent = ENTL1;            /* entity */
 144         cntrl.hdr.entId.inst = S_INST;          /* instance */
 145         cntrl.hdr.elmId.elmnt = STTSAP;         /* SAP Specific cntrl */
 146 
 147         cntrl.t.cntrl.action = AUBND_DIS;
 148         cntrl.t.cntrl.subAction = SAELMNT;
 149 
 150         cntrl.t.cntrl.sapId = signal_data->dchan_id;
 151         
 152         if (sng_isdn_phy_cntrl(&pst, &cntrl)) {
 153                 return FTDM_FAIL;
 154         }
 155         return FTDM_SUCCESS;
 156 }
 157 
 158 ftdm_status_t sngisdn_wake_up_phy(ftdm_span_t *span)
 159 {
 160         L1Mngmt cntrl;
 161         Pst pst;
 162 
 163         sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*)span->signal_data;
 164 
 165         /* initalize the post structure */
 166         stack_pst_init(&pst);
 167 
 168         /* insert the destination Entity */
 169         pst.dstEnt = ENTL1;
 170 
 171         /* initalize the control structure */
 172         memset(&cntrl, 0, sizeof(cntrl));
 173 
 174         /* initalize the control header */
 175         stack_hdr_init(&cntrl.hdr);
 176 
 177         cntrl.hdr.msgType = TCNTRL;                     /* configuration */
 178         cntrl.hdr.entId.ent = ENTL1;            /* entity */
 179         cntrl.hdr.entId.inst = S_INST;          /* instance */
 180         cntrl.hdr.elmId.elmnt = STTSAP;         /* SAP Specific cntrl */
 181 
 182         cntrl.t.cntrl.action = AENA;
 183         cntrl.t.cntrl.subAction = SAELMNT;
 184 
 185         cntrl.t.cntrl.sapId = signal_data->dchan_id;
 186         
 187         if (sng_isdn_phy_cntrl(&pst, &cntrl)) {
 188                 return FTDM_FAIL;
 189         }
 190         return FTDM_SUCCESS;
 191 }
 192 
 193 ftdm_status_t sngisdn_activate_cc(ftdm_span_t *span)
 194 {
 195         CcMngmt cntrl;
 196     Pst pst;
 197 
 198         sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*)span->signal_data;
 199 
 200     /* initalize the post structure */
 201    stack_pst_init(&pst);
 202 
 203     /* insert the destination Entity */
 204     pst.dstEnt = ENTCC;
 205 
 206     /* initalize the control structure */
 207         memset(&cntrl, 0, sizeof(cntrl));
 208 
 209     /* initalize the control header */
 210     stack_hdr_init(&cntrl.hdr);
 211 
 212         cntrl.hdr.msgType = TCNTRL;                     /* configuration */
 213         cntrl.hdr.entId.ent = ENTCC;            /* entity */
 214         cntrl.hdr.entId.inst = S_INST;          /* instance */
 215         cntrl.hdr.elmId.elmnt = STTSAP;         /* physical sap */
 216 
 217         cntrl.t.cntrl.action = ABND_ENA;
 218         cntrl.t.cntrl.subAction = SAELMNT;
 219 
 220         cntrl.t.cntrl.sapId = signal_data->cc_id;
 221         if (sng_isdn_cc_cntrl(&pst, &cntrl)) {
 222                 return FTDM_FAIL;
 223         }
 224         return FTDM_SUCCESS;
 225 }
 226 
 227 ftdm_status_t sngisdn_activate_trace(ftdm_span_t *span, sngisdn_tracetype_t trace_opt)
 228 {
 229         sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*)span->signal_data;
 230         switch (trace_opt) {
 231                 case SNGISDN_TRACE_DISABLE:
 232                         if (sngisdn_test_trace_flag(signal_data, SNGISDN_TRACE_Q921)) {
 233                                 ftdm_log(FTDM_LOG_INFO, "s%d Disabling q921 trace\n", signal_data->link_id);
 234                                 sngisdn_clear_trace_flag(signal_data, SNGISDN_TRACE_Q921);
 235                                 
 236                                 if (sngisdn_cntrl_q921(span, ADISIMM, SATRC) != FTDM_SUCCESS) {
 237                                         ftdm_log(FTDM_LOG_ERROR, "s%d Failed to disable q921 trace\n");
 238                                 }
 239                         }
 240                         if (sngisdn_test_trace_flag(signal_data, SNGISDN_TRACE_Q931)) {
 241                                 ftdm_log(FTDM_LOG_INFO, "s%d Disabling q931 trace\n", signal_data->link_id);
 242                                 sngisdn_clear_trace_flag(signal_data, SNGISDN_TRACE_Q931);
 243 
 244                                 if (sngisdn_cntrl_q931(span, ADISIMM, SATRC) != FTDM_SUCCESS) {
 245                                         ftdm_log(FTDM_LOG_ERROR, "s%d Failed to disable q931 trace\n");
 246                                 }
 247                         }
 248                         break;
 249                 case SNGISDN_TRACE_Q921:
 250                         if (!sngisdn_test_trace_flag(signal_data, SNGISDN_TRACE_Q921)) {
 251                                 ftdm_log(FTDM_LOG_INFO, "s%d Enabling q921 trace\n", signal_data->link_id);
 252                                 sngisdn_set_trace_flag(signal_data, SNGISDN_TRACE_Q921);
 253 
 254                                 if (sngisdn_cntrl_q921(span, AENA, SATRC) != FTDM_SUCCESS) {
 255                                         ftdm_log(FTDM_LOG_ERROR, "s%d Failed to enable q921 trace\n");
 256                                 }
 257                         }
 258                         break;
 259                 case SNGISDN_TRACE_Q931:
 260                         if (!sngisdn_test_trace_flag(signal_data, SNGISDN_TRACE_Q931)) {
 261                                 ftdm_log(FTDM_LOG_INFO, "s%d Enabling q931 trace\n", signal_data->link_id);
 262                                 sngisdn_set_trace_flag(signal_data, SNGISDN_TRACE_Q931);
 263                                 
 264                                 if (sngisdn_cntrl_q931(span, AENA, SATRC) != FTDM_SUCCESS) {
 265                                         ftdm_log(FTDM_LOG_ERROR, "s%d Failed to enable q931 trace\n");
 266                                 }
 267                         }
 268                         break;
 269         }
 270         return FTDM_SUCCESS;
 271 }
 272 
 273 
 274 ftdm_status_t sngisdn_cntrl_q931(ftdm_span_t *span, uint8_t action, uint8_t subaction)
 275 {
 276         InMngmt cntrl;
 277         Pst pst;
 278         sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*)span->signal_data;
 279 
 280         /* initalize the post structure */
 281         stack_pst_init(&pst);
 282 
 283         /* insert the destination Entity */
 284         pst.dstEnt = ENTIN;
 285 
 286         /* initalize the control structure */
 287         memset(&cntrl, 0, sizeof(cntrl));
 288 
 289         /* initalize the control header */
 290         stack_hdr_init(&cntrl.hdr);
 291 
 292         cntrl.hdr.msgType = TCNTRL;                     /* configuration */
 293         cntrl.hdr.entId.ent = ENTIN;            /* entity */
 294         cntrl.hdr.entId.inst = S_INST;          /* instance */
 295         cntrl.hdr.elmId.elmnt = STDLSAP;        /* physical sap */
 296 
 297         cntrl.t.cntrl.action = action;
 298         cntrl.t.cntrl.subAction = subaction;
 299 
 300         if (action == AENA && subaction == SATRC) {
 301                 cntrl.t.cntrl.trcLen = -1; /* Trace the entire message buffer */
 302         }
 303 
 304         cntrl.t.cntrl.sapId = signal_data->dchan_id;
 305         cntrl.t.cntrl.ces = 0;
 306 
 307         if(sng_isdn_q931_cntrl(&pst, &cntrl)) {
 308                 return FTDM_FAIL;
 309         }
 310         return FTDM_SUCCESS;    
 311 
 312 }
 313 
 314 ftdm_status_t sngisdn_cntrl_q921(ftdm_span_t *span, uint8_t action, uint8_t subaction)
 315 {
 316         BdMngmt cntrl;
 317         Pst pst;
 318         sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*)span->signal_data;
 319 
 320         /* initalize the post structure */
 321         stack_pst_init(&pst);
 322 
 323         /* insert the destination Entity */
 324         pst.dstEnt = ENTLD;
 325 
 326         /* initalize the control structure */
 327         memset(&cntrl, 0, sizeof(cntrl));
 328 
 329         /* initalize the control header */
 330         stack_hdr_init(&cntrl.hdr);
 331         /* build control request */
 332         cntrl.hdr.msgType          = TCNTRL;
 333         cntrl.hdr.entId.ent        = ENTLD;
 334         cntrl.hdr.entId.inst       = S_INST;
 335 
 336 #if (SMBD_LMINT3 || BD_LMINT3)
 337         stack_resp_hdr_init(&cntrl.hdr);
 338 #endif /* _LMINT3 */
 339 
 340         cntrl.hdr.elmId.elmnt      = STMSAP;
 341         cntrl.t.cntrl.action       = action;
 342         cntrl.t.cntrl.subAction    = subaction;
 343 
 344 #if (SMBD_LMINT3 || BD_LMINT3)
 345         cntrl.t.cntrl.lnkNmb       = signal_data->dchan_id;
 346         cntrl.t.cntrl.sapi         = NOTUSED;
 347         cntrl.t.cntrl.tei          = NOTUSED;
 348 #else /* _LMINT3 */
 349         cntrl.hdr.elmId.elmntInst1 = signal_data->dchan_id;
 350         cntrl.hdr.elmId.elmntInst2 = NOTUSED;
 351         cntrl.hdr.elmId.elmntInst3 = NOTUSED;
 352 #endif /* _LMINT3 */
 353 
 354         cntrl.t.cntrl.logInt       = NOTUSED;
 355         cntrl.t.cntrl.trcLen       = NOTUSED;
 356         if (action == AENA && subaction == SATRC) {
 357                 cntrl.t.cntrl.trcLen = -1; /* Trace the entire message buffer */
 358         }
 359 
 360         SGetDateTime(&(cntrl.t.cntrl.dt));
 361         if(sng_isdn_q921_cntrl(&pst, &cntrl)) {
 362                 return FTDM_FAIL;
 363         }
 364 
 365         return FTDM_SUCCESS;
 366 }
 367 
 368 
 369 void stack_resp_hdr_init(Header *hdr)
 370 { 
 371         hdr->response.selector   = 0;
 372         hdr->response.mem.region = RTESPEC;
 373         hdr->response.mem.pool   = S_POOL;
 374         hdr->response.prior      = PRIOR0;
 375         hdr->response.route      = RTESPEC;
 376 
 377         return;
 378 }
 379 
 380 
 381 
 382 /* For Emacs:
 383  * Local Variables:
 384  * mode:c
 385  * indent-tabs-mode:t
 386  * tab-width:4
 387  * c-basic-offset:4
 388  * End:
 389  * For VIM:
 390  * vim:set softtabstop=4 shiftwidth=4 tabstop=4:
 391  */
 392 
 393 /******************************************************************************/

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