Sat Apr 26 2014 22:01:42

Asterisk developer's documentation


sig_ss7.h
Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 2010 Digium, Inc.
00005  *
00006  * Richard Mudgett <rmudgett@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*!
00020  * \file
00021  * \brief Interface header for SS7 signaling module.
00022  *
00023  * \author Matthew Fredrickson <creslin@digium.com>
00024  * \author Richard Mudgett <rmudgett@digium.com>
00025  *
00026  * See Also:
00027  * \arg \ref AstCREDITS
00028  */
00029 
00030 #ifndef _ASTERISK_SIG_SS7_H
00031 #define _ASTERISK_SIG_SS7_H
00032 
00033 #include "asterisk/channel.h"
00034 #include <libss7.h>
00035 
00036 #ifdef __cplusplus
00037 extern "C" {
00038 #endif
00039 
00040 /* ------------------------------------------------------------------- */
00041 
00042 /*! SS7 debug message flags when SS7 debugging is turned on at the command line. */
00043 #define SIG_SS7_DEBUG   \
00044    (SS7_DEBUG_MTP2 | SS7_DEBUG_MTP3 | SS7_DEBUG_ISUP)
00045 
00046 #if 0
00047 /*! SS7 debug message flags set on initial startup. */
00048 #define SIG_SS7_DEBUG_DEFAULT SIG_SS7_DEBUG
00049 #else
00050 /*! SS7 debug message flags set on initial startup. */
00051 #define SIG_SS7_DEBUG_DEFAULT 0
00052 #endif
00053 
00054 /* ------------------------------------------------------------------- */
00055 
00056 #define SIG_SS7_NUM_DCHANS    4     /*!< No more than 4 d-channels */
00057 #define SIG_SS7_MAX_CHANNELS  672      /*!< No more than a DS3 per trunk group */
00058 
00059 #define SIG_SS7      (0x1000000 | DAHDI_SIG_CLEAR)
00060 
00061 #define LINKSTATE_INALARM  (1 << 0)
00062 #define LINKSTATE_STARTING (1 << 1)
00063 #define LINKSTATE_UP    (1 << 2)
00064 #define LINKSTATE_DOWN     (1 << 3)
00065 
00066 #define SS7_NAI_DYNAMIC    -1
00067 
00068 #define LINKSET_FLAG_EXPLICITACM (1 << 0)
00069 
00070 
00071 enum sig_ss7_tone {
00072    SIG_SS7_TONE_RINGTONE = 0,
00073    SIG_SS7_TONE_STUTTER,
00074    SIG_SS7_TONE_CONGESTION,
00075    SIG_SS7_TONE_DIALTONE,
00076    SIG_SS7_TONE_DIALRECALL,
00077    SIG_SS7_TONE_INFO,
00078    SIG_SS7_TONE_BUSY,
00079 };
00080 
00081 enum sig_ss7_law {
00082    SIG_SS7_DEFLAW = 0,
00083    SIG_SS7_ULAW,
00084    SIG_SS7_ALAW
00085 };
00086 
00087 /*! Call establishment life cycle level for simple comparisons. */
00088 enum sig_ss7_call_level {
00089    /*! Call does not exist. */
00090    SIG_SS7_CALL_LEVEL_IDLE,
00091    /*!
00092     * Call is allocated to the channel.
00093     * We have not sent or responded to IAM yet.
00094     */
00095    SIG_SS7_CALL_LEVEL_ALLOCATED,
00096    /*!
00097     * Call is performing continuity check after receiving IAM.
00098     * We are waiting for COT to proceed further.
00099     */
00100    SIG_SS7_CALL_LEVEL_CONTINUITY,
00101    /*!
00102     * Call is present.
00103     * We have not seen a response or sent further call progress to an IAM yet.
00104     */
00105    SIG_SS7_CALL_LEVEL_SETUP,
00106    /*!
00107     * Call routing is happening.
00108     * We have sent or received ACM.
00109     */
00110    SIG_SS7_CALL_LEVEL_PROCEEDING,
00111    /*!
00112     * Called party is being alerted of the call.
00113     * We have sent or received CPG(ALERTING)/ACM(ALERTING).
00114     */
00115    SIG_SS7_CALL_LEVEL_ALERTING,
00116    /*!
00117     * Call is connected/answered.
00118     * We have sent or received CON/ANM.
00119     */
00120    SIG_SS7_CALL_LEVEL_CONNECT,
00121    /*! Call has collided with incoming call. */
00122    SIG_SS7_CALL_LEVEL_GLARE,
00123 };
00124 
00125 struct sig_ss7_linkset;
00126 
00127 struct sig_ss7_callback {
00128    /* Unlock the private in the signaling private structure. */
00129    void (* const unlock_private)(void *pvt);
00130    /* Lock the private in the signaling private structure. */
00131    void (* const lock_private)(void *pvt);
00132    /* Do deadlock avoidance for the private signaling structure lock.  */
00133    void (* const deadlock_avoidance_private)(void *pvt);
00134 
00135    int (* const set_echocanceller)(void *pvt, int enable);
00136    void (* const set_loopback)(void *pvt, int enable);
00137 
00138    struct ast_channel * (* const new_ast_channel)(void *pvt, int state, enum sig_ss7_law law, char *exten, const struct ast_channel *requestor);
00139    int (* const play_tone)(void *pvt, enum sig_ss7_tone tone);
00140 
00141    void (* const handle_link_exception)(struct sig_ss7_linkset *linkset, int which);
00142    void (* const set_alarm)(void *pvt, int in_alarm);
00143    void (* const set_dialing)(void *pvt, int is_dialing);
00144    void (* const set_digital)(void *pvt, int is_digital);
00145    void (* const set_outgoing)(void *pvt, int is_outgoing);
00146    void (* const set_inservice)(void *pvt, int is_inservice);
00147    void (* const set_locallyblocked)(void *pvt, int is_blocked);
00148    void (* const set_remotelyblocked)(void *pvt, int is_blocked);
00149    void (* const set_callerid)(void *pvt, const struct ast_party_caller *caller);
00150    void (* const set_dnid)(void *pvt, const char *dnid);
00151 
00152    void (* const queue_control)(void *pvt, int subclass);
00153    void (* const open_media)(void *pvt);
00154 };
00155 
00156 /*! Global sig_ss7 callbacks to the upper layer. */
00157 extern struct sig_ss7_callback sig_ss7_callbacks;
00158 
00159 struct sig_ss7_chan {
00160    void *chan_pvt;               /*!< Private structure of the user of this module. */
00161    struct sig_ss7_linkset *ss7;
00162    struct ast_channel *owner;
00163 
00164    /*! \brief Opaque libss7 call control structure */
00165    struct isup_call *ss7call;
00166 
00167    /*! Call establishment life cycle level for simple comparisons. */
00168    enum sig_ss7_call_level call_level;
00169 
00170    int channel;               /*!< Channel Number */
00171    int cic;                /*!< CIC associated with channel */
00172    unsigned int dpc;          /*!< CIC's DPC */
00173 
00174    /* Options to be set by user */
00175    /*!
00176     * \brief Number of most significant digits/characters to strip from the dialed number.
00177     * \note Feature is deprecated.  Use dialplan logic.
00178     */
00179    int stripmsd;
00180    /*!
00181     * \brief TRUE if the outgoing caller ID is blocked/hidden.
00182     */
00183    unsigned int hidecallerid:1;
00184    /*! \brief TRUE if caller ID is used on this channel. */
00185    unsigned int use_callerid:1;
00186    /*!
00187     * \brief TRUE if we will use the calling presentation setting
00188     * from the Asterisk channel for outgoing calls.
00189     */
00190    unsigned int use_callingpres:1;
00191    unsigned int immediate:1;     /*!< Answer before getting digits? */
00192 
00193    /*! \brief TRUE if the channel is locally blocked.  Set by user and link. */
00194    unsigned int locallyblocked:1;
00195    /*! \brief TRUE if the channel is remotely blocked.  Set by user and link. */
00196    unsigned int remotelyblocked:1;
00197 
00198    char context[AST_MAX_CONTEXT];
00199    char mohinterpret[MAX_MUSICCLASS];
00200 
00201    /* Options to be checked by user */
00202    int cid_ani2;              /*!< Automatic Number Identification number (Alternate PRI caller ID number) */
00203    int cid_ton;               /*!< Type Of Number (TON) */
00204    int callingpres;           /*!< The value of calling presentation that we're going to use when placing a PRI call */
00205    char cid_num[AST_MAX_EXTENSION];
00206    char cid_subaddr[AST_MAX_EXTENSION];/*!< XXX SS7 may not support. */
00207    char cid_name[AST_MAX_EXTENSION];
00208    char cid_ani[AST_MAX_EXTENSION];
00209    char exten[AST_MAX_EXTENSION];
00210 
00211    /* Options to be checked by user that are stuffed into channel variables. */
00212    char charge_number[50];
00213    char gen_add_number[50];
00214    char gen_dig_number[50];
00215    char orig_called_num[50];
00216    char redirecting_num[50];
00217    char generic_name[50];
00218    unsigned char gen_add_num_plan;
00219    unsigned char gen_add_nai;
00220    unsigned char gen_add_pres_ind;
00221    unsigned char gen_add_type;
00222    unsigned char gen_dig_type;
00223    unsigned char gen_dig_scheme;
00224    char jip_number[50];
00225 #if 0
00226    unsigned char lspi_type;
00227    unsigned char lspi_scheme;
00228    unsigned char lspi_context;
00229 #endif
00230    char lspi_ident[50];
00231    unsigned int call_ref_ident;
00232    unsigned int call_ref_pc;
00233    unsigned char calling_party_cat;
00234 
00235    /*
00236     * Channel status bits.
00237     */
00238    /*! TRUE if channel is associated with a link that is down. */
00239    unsigned int inalarm:1;
00240    /*! TRUE if this channel is being used for an outgoing call. */
00241    unsigned int outgoing:1;
00242    /*! \brief TRUE if the call has seen inband-information progress through the network. */
00243    unsigned int progress:1;
00244    /*! \brief TRUE if the call has already gone/hungup */
00245    unsigned int alreadyhungup:1;
00246    /*! \brief XXX BOOLEAN Purpose??? */
00247    unsigned int rlt:1;
00248    /*! TRUE if this channel is in loopback. */
00249    unsigned int loopedback:1;
00250 };
00251 
00252 struct sig_ss7_linkset {
00253    pthread_t master;             /*!< Thread of master */
00254    ast_mutex_t lock;             /*!< libss7 access lock */
00255    struct ss7 *ss7;
00256    struct sig_ss7_chan *pvts[SIG_SS7_MAX_CHANNELS];/*!< Member channel pvt structs */
00257    int fds[SIG_SS7_NUM_DCHANS];
00258    int numsigchans;
00259    int linkstate[SIG_SS7_NUM_DCHANS];
00260    int numchans;
00261    int span;                     /*!< span number put into user output messages */
00262    int debug;                    /*!< set to true if to dump SS7 event info */
00263    enum {
00264       LINKSET_STATE_DOWN = 0,
00265       LINKSET_STATE_UP
00266    } state;
00267 
00268    /* Options to be set by user */
00269    int flags;                    /*!< Linkset flags (LINKSET_FLAG_EXPLICITACM) */
00270    int type;                     /*!< SS7 type ITU/ANSI. Used for companding selection. */
00271    char called_nai;              /*!< Called Nature of Address Indicator */
00272    char calling_nai;             /*!< Calling Nature of Address Indicator */
00273    char internationalprefix[10];    /*!< country access code ('00' for european dialplans) */
00274    char nationalprefix[10];         /*!< area access code ('0' for european dialplans) */
00275    char subscriberprefix[20];       /*!< area access code + area code ('0'+area code for european dialplans) */
00276    char unknownprefix[20];          /*!< for unknown dialplans */
00277 };
00278 
00279 void sig_ss7_set_alarm(struct sig_ss7_chan *p, int in_alarm);
00280 
00281 void *ss7_linkset(void *data);
00282 
00283 void sig_ss7_link_alarm(struct sig_ss7_linkset *linkset, int which);
00284 void sig_ss7_link_noalarm(struct sig_ss7_linkset *linkset, int which);
00285 int sig_ss7_add_sigchan(struct sig_ss7_linkset *linkset, int which, int ss7type, int transport, int inalarm, int networkindicator, int pointcode, int adjpointcode);
00286 
00287 int sig_ss7_available(struct sig_ss7_chan *p);
00288 int sig_ss7_call(struct sig_ss7_chan *p, struct ast_channel *ast, const char *rdest);
00289 int sig_ss7_hangup(struct sig_ss7_chan *p, struct ast_channel *ast);
00290 int sig_ss7_answer(struct sig_ss7_chan *p, struct ast_channel *ast);
00291 void sig_ss7_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, struct sig_ss7_chan *pchan);
00292 int sig_ss7_indicate(struct sig_ss7_chan *p, struct ast_channel *chan, int condition, const void *data, size_t datalen);
00293 struct ast_channel *sig_ss7_request(struct sig_ss7_chan *p, enum sig_ss7_law law, const struct ast_channel *requestor, int transfercapability);
00294 void sig_ss7_chan_delete(struct sig_ss7_chan *doomed);
00295 struct sig_ss7_chan *sig_ss7_chan_new(void *pvt_data, struct sig_ss7_linkset *ss7);
00296 void sig_ss7_init_linkset(struct sig_ss7_linkset *ss7);
00297 
00298 void sig_ss7_cli_show_channels_header(int fd);
00299 void sig_ss7_cli_show_channels(int fd, struct sig_ss7_linkset *linkset);
00300 
00301 
00302 /* ------------------------------------------------------------------- */
00303 
00304 #ifdef __cplusplus
00305 }
00306 #endif
00307 
00308 #endif   /* _ASTERISK_SIG_SS7_H */
00309 /* ------------------------------------------------------------------- */
00310 /* end sig_ss7.h */