root/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn.h

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

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. sngisdn_test_flag
  2. sngisdn_clear_flag
  3. sngisdn_set_flag

   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 #ifndef __FTMOD_SNG_ISDN_H__
  36 #define __FTMOD_SNG_ISDN_H__
  37 
  38 #include <stdio.h>
  39 #include <string.h>
  40 #include <stdarg.h>
  41 #include <stdint.h>
  42 #include <unistd.h>
  43 #include <ctype.h>
  44 
  45 #include "private/ftdm_core.h"
  46 
  47 #include <sng_isdn.h>
  48 
  49 /* Theoretical limit for MAX_SPANS_PER_NFAS_LINK is 31,
  50    but set to 8 for now to save some memor */
  51 
  52 #define MAX_SPANS_PER_NFAS_LINK         8 
  53 #define NUM_E1_CHANNELS_PER_SPAN        32
  54 #define NUM_T1_CHANNELS_PER_SPAN        24
  55 #define NUM_BRI_CHANNELS_PER_SPAN       2
  56 #define SNGISDN_EVENT_QUEUE_SIZE        100
  57 #define SNGISDN_EVENT_POLL_RATE         100
  58 #define SNGISDN_NUM_LOCAL_NUMBERS       8
  59 
  60 /* TODO: rename all *_cc_* to *_an_*  */
  61 
  62 typedef enum {
  63         FLAG_RESET_RX           = (1 << 0),
  64         FLAG_RESET_TX           = (1 << 1),
  65         FLAG_REMOTE_REL         = (1 << 2),
  66         FLAG_LOCAL_REL          = (1 << 3),
  67         FLAG_REMOTE_ABORT       = (1 << 4),
  68         FLAG_LOCAL_ABORT        = (1 << 5),
  69         FLAG_GLARE              = (1 << 6),
  70         FLAG_DELAYED_REL        = (1 << 7),
  71         FLAG_SENT_PROCEED       = (1 << 8),
  72         FLAG_SEND_DISC                  = (1 << 9),
  73 } sngisdn_flag_t;
  74 
  75 
  76 typedef enum {
  77         SNGISDN_SWITCH_INVALID = 0,     /* invalid */
  78         SNGISDN_SWITCH_NI2 ,    /* national isdn-2 */
  79         SNGISDN_SWITCH_5ESS,    /* att 5ess */
  80         SNGISDN_SWITCH_4ESS,    /* att 4ess */
  81         SNGISDN_SWITCH_DMS100,  /* nt dms100 */
  82         SNGISDN_SWITCH_EUROISDN,/* etsi */
  83         SNGISDN_SWITCH_QSIG,    /* etsi qsig */
  84         SNGISDN_SWITCH_INSNET,  /* int - net */
  85 } sngisdn_switchtype_t;
  86 
  87 typedef enum {
  88         SNGISDN_SIGNALING_INVALID = 0,          /* invalid */
  89         SNGISDN_SIGNALING_CPE ,                         /* customer side emulation */
  90         SNGISDN_SIGNALING_NET,                          /* network side emulation */
  91 } sngisdn_signalingtype_t;
  92 
  93 typedef enum {
  94         SNGISDN_TRACE_DISABLE = 0,
  95         SNGISDN_TRACE_Q921 = 1,
  96         SNGISDN_TRACE_Q931 = 2,
  97 } sngisdn_tracetype_t;
  98 
  99 typedef enum {
 100         SNGISDN_OPT_DEFAULT = 0,
 101         SNGISDN_OPT_TRUE = 1,
 102         SNGISDN_OPT_FALSE = 2,
 103 } sngisdn_opt_t;
 104 
 105 
 106 typedef enum {
 107         SNGISDN_AVAIL_DOWN = 1,
 108         SNGISDN_AVAIL_PWR_SAVING = 5,
 109         SNGISDN_AVAIL_UP = 10,
 110 } sngisdn_avail_t;
 111 
 112 typedef enum {
 113         SNGISDN_EVENT_CON_IND = 1,
 114         SNGISDN_EVENT_CON_CFM,
 115         SNGISDN_EVENT_CNST_IND,
 116         SNGISDN_EVENT_DISC_IND,
 117         SNGISDN_EVENT_REL_IND,
 118         SNGISDN_EVENT_DAT_IND,
 119         SNGISDN_EVENT_SSHL_IND,
 120         SNGISDN_EVENT_SSHL_CFM,
 121         SNGISDN_EVENT_RMRT_IND,
 122         SNGISDN_EVENT_RMRT_CFM,
 123         SNGISDN_EVENT_FLC_IND,
 124         SNGISDN_EVENT_FAC_IND,
 125         SNGISDN_EVENT_STA_CFM,
 126         SNGISDN_EVENT_SRV_IND,
 127         SNGISDN_EVENT_SRV_CFM,
 128         SNGISDN_EVENT_RST_CFM,
 129         SNGISDN_EVENT_RST_IND,
 130 } ftdm_sngisdn_event_id_t;
 131 
 132 /* Only timers that can be cancelled are listed here */
 133 #define SNGISDN_NUM_TIMERS 1
 134 /* Increase NUM_TIMERS as number of ftdm_sngisdn_timer_t increases */
 135 typedef enum {
 136         SNGISDN_TIMER_FACILITY = 0,
 137 } ftdm_sngisdn_timer_t;
 138 
 139 typedef struct sngisdn_glare_data {
 140         int16_t         suId;
 141     uint32_t    suInstId;
 142     uint32_t    spInstId;
 143         int16_t         dChan;
 144     ConEvnt             setup;
 145         uint8_t         ces;
 146 }sngisdn_glare_data_t;
 147 
 148 
 149 /* Channel specific data */
 150 typedef struct sngisdn_chan_data {
 151     ftdm_channel_t                      *ftdmchan;
 152     uint32_t                            flags;
 153         uint8_t                                 ces;            /* used only for BRI, otherwise always 0 */
 154         uint8_t                                 dchan_id;
 155         uint32_t                                suInstId;       /* instance ID generated locally */
 156         uint32_t                                spInstId;       /* instance ID generated by stack */
 157 
 158         uint8_t                 globalFlg;
 159         sngisdn_glare_data_t    glare;
 160         ftdm_timer_id_t                 timers[SNGISDN_NUM_TIMERS];
 161 } sngisdn_chan_data_t;
 162 
 163 /* Span specific data */
 164 typedef struct sngisdn_span_data {
 165         ftdm_span_t             *ftdm_span;
 166         uint8_t                 link_id;
 167         uint8_t                 switchtype;
 168         uint8_t                 signalling;                     /* SNGISDN_SIGNALING_CPE or SNGISDN_SIGNALING_NET */
 169         uint8_t                 cc_id;
 170         uint8_t                 dchan_id;
 171         uint8_t                 span_id;
 172         uint8_t                 tei;
 173         uint8_t                 min_digits;
 174         uint8_t                 trace_flags;            /* TODO: change to flags, so we can use ftdm_test_flag etc.. */
 175         uint8_t                 overlap_dial;
 176         uint8_t                 setup_arb;
 177         uint8_t                 facility;
 178         int8_t                  facility_timeout;
 179         uint8_t                 num_local_numbers;
 180         char*                   local_numbers[SNGISDN_NUM_LOCAL_NUMBERS];
 181         ftdm_sched_t    *sched;
 182         ftdm_queue_t    *event_queue;
 183 } sngisdn_span_data_t;
 184 
 185 typedef struct sngisdn_event_data {
 186         
 187         int16_t         suId;
 188         int16_t         dChan;
 189         uint32_t        suInstId;
 190         uint32_t        spInstId;
 191         uint8_t         ces;
 192         uint8_t         action;
 193         uint8_t         evntType;
 194 
 195         sngisdn_chan_data_t *sngisdn_info;
 196         sngisdn_span_data_t *signal_data;       
 197         
 198         ftdm_sngisdn_event_id_t event_id;
 199         
 200         union
 201         {
 202                 ConEvnt         conEvnt;
 203                 CnStEvnt        cnStEvnt;
 204                 DiscEvnt        discEvnt;
 205                 RelEvnt         relEvnt;
 206                 InfoEvnt        infoEvnt;
 207                 SsHlEvnt        ssHlEvnt;
 208                 RmRtEvnt        rmRtEvnt;
 209                 StaEvnt         staEvnt;
 210                 FacEvnt         facEvnt;
 211                 Srv                     srvEvnt;
 212                 Rst                     rstEvnt;
 213         }event;
 214         
 215 } sngisdn_event_data_t;
 216 
 217 /* dchan_data can have more than 1 span when running NFAS */
 218 typedef struct sngisdn_dchan_data {
 219         uint8_t                         num_spans;
 220         sngisdn_span_data_t     *spans[MAX_L1_LINKS+1];
 221         uint16_t                        num_chans;
 222         /* worst case for number of channel is when using NFAS, and NFAS is only used on T1,
 223                 so we can use MAX_SPANS_PER_NFAS_LINK*NUM_T1_CHANNELS_PER_SPAN instead of
 224                 MAX_SPANS_PER_NFAS_LINK*NUM_E1_CHANNELS_PER_SPAN
 225         */
 226         /* Never seen NFAS on E1 yet, so use NUM_T1_CHANNELS_PER_SPAN */
 227         /* b-channels are arranged by physical id's not logical */
 228         sngisdn_chan_data_t *channels[MAX_SPANS_PER_NFAS_LINK*NUM_T1_CHANNELS_PER_SPAN];
 229 }sngisdn_dchan_data_t;
 230 
 231 typedef struct sngisdn_cc {
 232         /* TODO: use flags instead of config_done and activation_done */
 233         uint8_t                         config_done;
 234         uint8_t                         activation_done;
 235         uint8_t                         switchtype;
 236         ftdm_trunk_type_t       trunktype;
 237         uint32_t                        last_suInstId;  
 238         ftdm_mutex_t            *mutex;
 239         sngisdn_chan_data_t     *active_spInstIds[MAX_INSTID+1];
 240         sngisdn_chan_data_t     *active_suInstIds[MAX_INSTID+1];
 241 }sngisdn_cc_t;
 242 
 243 /* Global sngisdn data */
 244 typedef struct ftdm_sngisdn_data {
 245         uint8_t gen_config_done;
 246         uint8_t num_cc;                                         /* 1 ent per switchtype */
 247         struct sngisdn_cc ccs[MAX_VARIANTS+1];
 248         uint8_t num_dchan;
 249         sngisdn_dchan_data_t dchans[MAX_L1_LINKS+1];
 250         sngisdn_span_data_t *spans[MAX_L1_LINKS+1]; /* spans are indexed by link_id */
 251 }ftdm_sngisdn_data_t;
 252 
 253 
 254 /* TODO implement these 2 functions */
 255 #define ISDN_FUNC_TRACE_ENTER(a)
 256 #define ISDN_FUNC_TRACE_EXIT(a)
 257 
 258 /* Global Structs */
 259 extern ftdm_sngisdn_data_t      g_sngisdn_data;
 260 
 261 /* Configuration functions */
 262 ftdm_status_t ftmod_isdn_parse_cfg(ftdm_conf_parameter_t *ftdm_parameters, ftdm_span_t *span);
 263 
 264 /* Support functions */
 265 uint32_t get_unique_suInstId(uint8_t cc_id);
 266 void clear_call_data(sngisdn_chan_data_t *sngisdn_info);
 267 void clear_call_glare_data(sngisdn_chan_data_t *sngisdn_info);
 268 
 269 
 270 void stack_hdr_init(Header *hdr);
 271 void stack_pst_init(Pst *pst);
 272 ftdm_status_t get_ftdmchan_by_spInstId(uint8_t cc_id, uint32_t spInstId, sngisdn_chan_data_t **sngisdn_data);
 273 ftdm_status_t get_ftdmchan_by_suInstId(uint8_t cc_id, uint32_t suInstId, sngisdn_chan_data_t **sngisdn_data);
 274 ftdm_status_t sng_isdn_set_avail_rate(ftdm_span_t *ftdmspan, sngisdn_avail_t avail);
 275 
 276 /* Outbound Call Control functions */
 277 void sngisdn_snd_setup(ftdm_channel_t *ftdmchan);
 278 void sngisdn_snd_setup_ack(ftdm_channel_t *ftdmchan);
 279 void sngisdn_snd_proceed(ftdm_channel_t *ftdmchan);
 280 void sngisdn_snd_progress(ftdm_channel_t *ftdmchan);
 281 void sngisdn_snd_alert(ftdm_channel_t *ftdmchan);
 282 void sngisdn_snd_connect(ftdm_channel_t *ftdmchan);
 283 void sngisdn_snd_disconnect(ftdm_channel_t *ftdmchan);
 284 void sngisdn_snd_release(ftdm_channel_t *ftdmchan, uint8_t glare);
 285 void sngisdn_snd_reset(ftdm_channel_t *ftdmchan);
 286 void sngisdn_snd_con_complete(ftdm_channel_t *ftdmchan);
 287 void sngisdn_snd_info_req(ftdm_channel_t *ftdmchan);
 288 void sngisdn_snd_status_enq(ftdm_channel_t *ftdmchan);
 289 
 290 /* Inbound Call Control functions */
 291 void sngisdn_rcv_con_ind (int16_t suId, uint32_t suInstId, uint32_t spInstId, ConEvnt *conEvnt, int16_t dChan, uint8_t ces);
 292 void sngisdn_rcv_con_cfm (int16_t suId, uint32_t suInstId, uint32_t spInstId, CnStEvnt *cnStEvnt, int16_t dChan, uint8_t ces);
 293 void sngisdn_rcv_cnst_ind (int16_t suId, uint32_t suInstId, uint32_t spInstId, CnStEvnt *cnStEvnt, uint8_t evntType, int16_t dChan, uint8_t ces);
 294 void sngisdn_rcv_disc_ind (int16_t suId, uint32_t suInstId, uint32_t spInstId, DiscEvnt *discEvnt);
 295 void sngisdn_rcv_rel_ind (int16_t suId, uint32_t suInstId, uint32_t spInstId, RelEvnt *relEvnt);
 296 void sngisdn_rcv_dat_ind (int16_t suId, uint32_t suInstId, uint32_t spInstId, InfoEvnt *infoEvnt);
 297 void sngisdn_rcv_sshl_ind (int16_t suId, uint32_t suInstId, uint32_t spInstId, SsHlEvnt *ssHlEvnt, uint8_t action);
 298 void sngisdn_rcv_sshl_cfm (int16_t suId, uint32_t suInstId, uint32_t spInstId, SsHlEvnt *ssHlEvnt, uint8_t action);
 299 void sngisdn_rcv_rmrt_ind (int16_t suId, uint32_t suInstId, uint32_t spInstId, RmRtEvnt *rmRtEvnt, uint8_t action);
 300 void sngisdn_rcv_rmrt_cfm (int16_t suId, uint32_t suInstId, uint32_t spInstId, RmRtEvnt *rmRtEvnt, uint8_t action);
 301 void sngisdn_rcv_flc_ind (int16_t suId, uint32_t suInstId, uint32_t spInstId, StaEvnt *staEvnt);
 302 void sngisdn_rcv_fac_ind (int16_t suId, uint32_t suInstId, uint32_t spInstId, FacEvnt *facEvnt, uint8_t evntType, int16_t dChan, uint8_t ces);
 303 void sngisdn_rcv_sta_cfm ( int16_t suId, uint32_t suInstId, uint32_t spInstId, StaEvnt *staEvnt);
 304 void sngisdn_rcv_srv_ind ( int16_t suId, Srv *srvEvnt, int16_t dChan, uint8_t ces);
 305 void sngisdn_rcv_srv_cfm ( int16_t suId, Srv *srvEvnt, int16_t dChan, uint8_t ces);
 306 void sngisdn_rcv_rst_cfm ( int16_t suId, Rst *rstEvnt, int16_t dChan, uint8_t ces, uint8_t evntType);
 307 void sngisdn_rcv_rst_ind ( int16_t suId, Rst *rstEvnt, int16_t dChan, uint8_t ces, uint8_t evntType);
 308 
 309 void sngisdn_process_con_ind (sngisdn_event_data_t *sngisdn_event);
 310 void sngisdn_process_con_cfm (sngisdn_event_data_t *sngisdn_event);
 311 void sngisdn_process_cnst_ind (sngisdn_event_data_t *sngisdn_event);
 312 void sngisdn_process_disc_ind (sngisdn_event_data_t *sngisdn_event);
 313 void sngisdn_process_rel_ind (sngisdn_event_data_t *sngisdn_event);
 314 void sngisdn_process_dat_ind (sngisdn_event_data_t *sngisdn_event);
 315 void sngisdn_process_sshl_ind (sngisdn_event_data_t *sngisdn_event);
 316 void sngisdn_process_sshl_cfm (sngisdn_event_data_t *sngisdn_event);
 317 void sngisdn_process_rmrt_ind (sngisdn_event_data_t *sngisdn_event);
 318 void sngisdn_process_rmrt_cfm (sngisdn_event_data_t *sngisdn_event);
 319 void sngisdn_process_flc_ind (sngisdn_event_data_t *sngisdn_event);
 320 void sngisdn_process_fac_ind (sngisdn_event_data_t *sngisdn_event);
 321 void sngisdn_process_sta_cfm (sngisdn_event_data_t *sngisdn_event);
 322 
 323 void sngisdn_process_srv_ind (sngisdn_event_data_t *sngisdn_event);
 324 void sngisdn_process_srv_cfm (sngisdn_event_data_t *sngisdn_event);
 325 void sngisdn_process_rst_cfm (sngisdn_event_data_t *sngisdn_event);
 326 void sngisdn_process_rst_ind (sngisdn_event_data_t *sngisdn_event);
 327 
 328 void sngisdn_rcv_phy_ind(SuId suId, Reason reason);
 329 void sngisdn_rcv_q921_ind(BdMngmt *status);
 330 void sngisdn_rcv_q921_trace(BdMngmt *trc, Buffer *mBuf);
 331 void sngisdn_rcv_q931_ind(InMngmt *status);
 332 void sngisdn_rcv_q931_trace(InMngmt *trc, Buffer *mBuf);
 333 void sngisdn_rcv_cc_ind(CcMngmt *status);
 334 void sngisdn_rcv_sng_log(uint8_t level, char *fmt,...);
 335 void sngisdn_rcv_sng_assert(char *message);
 336 
 337 uint8_t sngisdn_get_infoTranCap_from_stack(ftdm_bearer_cap_t bearer_capability);
 338 uint8_t sngisdn_get_usrInfoLyr1Prot_from_stack(ftdm_user_layer1_prot_t layer1_prot);
 339 ftdm_bearer_cap_t sngisdn_get_infoTranCap_from_user(uint8_t bearer_capability);
 340 ftdm_user_layer1_prot_t sngisdn_get_usrInfoLyr1Prot_from_user(uint8_t layer1_prot);
 341 
 342 static __inline__ uint32_t sngisdn_test_flag(sngisdn_chan_data_t *sngisdn_info, sngisdn_flag_t flag)
 343 {
 344         return (uint32_t) sngisdn_info->flags & flag;
 345 }
 346 static __inline__ void sngisdn_clear_flag(sngisdn_chan_data_t *sngisdn_info, sngisdn_flag_t flag)
 347 {
 348         sngisdn_info->flags &= ~flag;
 349 }
 350 
 351 static __inline__ void sngisdn_set_flag(sngisdn_chan_data_t *sngisdn_info, sngisdn_flag_t flag)
 352 {
 353         sngisdn_info->flags |= flag;
 354 }
 355 
 356 #define sngisdn_set_trace_flag(obj, flag)   ((obj)->trace_flags |= (flag))
 357 #define sngisdn_clear_trace_flag(obj, flag) ((obj)->trace_flags &= ~(flag))
 358 #define sngisdn_test_trace_flag(obj, flag)  ((obj)->trace_flags & flag)
 359 
 360 
 361 void handle_sng_log(uint8_t level, char *fmt,...);
 362 void sngisdn_set_span_sig_status(ftdm_span_t *ftdmspan, ftdm_signaling_status_t status);
 363 void sngisdn_delayed_release(void* p_sngisdn_info);
 364 void sngisdn_delayed_connect(void* p_sngisdn_info);
 365 void sngisdn_delayed_disconnect(void* p_sngisdn_info);
 366 void sngisdn_facility_timeout(void* p_sngisdn_info);
 367 
 368 /* Stack management functions */
 369 ftdm_status_t sng_isdn_stack_cfg(ftdm_span_t *span);
 370 ftdm_status_t sng_isdn_stack_start(ftdm_span_t *span);
 371 ftdm_status_t sng_isdn_stack_stop(ftdm_span_t *span);
 372 
 373 void sngisdn_print_phy_stats(ftdm_stream_handle_t *stream, ftdm_span_t *span);
 374 void sngisdn_print_spans(ftdm_stream_handle_t *stream);
 375 void sngisdn_print_span(ftdm_stream_handle_t *stream, ftdm_span_t *span);
 376 
 377 #endif /* __FTMOD_SNG_ISDN_H__ */
 378 

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