4 * Asterisk -- An open source telephony toolkit.
6 * Copyright (C) 1999 - 2009, Digium, Inc.
8 * Mark Spencer <markster@digium.com>
10 * See http://www.asterisk.org for more information about
11 * the Asterisk project. Please do not directly contact
12 * any of the maintainers of this project for assistance;
13 * the project provides a web site, mailing lists and IRC
14 * channels for your use.
16 * This program is free software, distributed under the terms of
17 * the GNU General Public License Version 2. See the LICENSE file
18 * at the top of the source tree.
23 * \brief Interface header for PRI signaling module
25 * \author Matthew Fredrickson <creslin@digium.com>
28 #include "asterisk/channel.h"
29 #include "asterisk/frame.h"
31 #include <dahdi/user.h>
34 SIG_PRI_TONE_RINGTONE = 0,
36 SIG_PRI_TONE_CONGESTION,
37 SIG_PRI_TONE_DIALTONE,
38 SIG_PRI_TONE_DIALRECALL,
51 struct sig_pri_callback {
52 /* Unlock the private in the signalling private structure. This is used for three way calling madness. */
53 void (* const unlock_private)(void *pvt);
54 /* Lock the private in the signalling private structure. ... */
55 void (* const lock_private)(void *pvt);
56 /* Function which is called back to handle any other DTMF up events that are received. Called by analog_handle_event. Why is this
57 * important to use, instead of just directly using events received before they are passed into the library? Because sometimes,
58 * (CWCID) the library absorbs DTMF events received. */
59 //void (* const handle_dtmfup)(void *pvt, struct ast_channel *ast, enum analog_sub analog_index, struct ast_frame **dest);
61 //int (* const dial_digits)(void *pvt, enum analog_sub sub, struct analog_dialoperation *dop);
62 int (* const play_tone)(void *pvt, enum sig_pri_tone tone);
64 int (* const set_echocanceller)(void *pvt, int enable);
65 int (* const train_echocanceller)(void *pvt);
66 int (* const dsp_reset_and_flush_digits)(void *pvt);
68 struct ast_channel * (* const new_ast_channel)(void *pvt, int state, int startpbx, enum sig_pri_law law, int transfercapability, char *exten, const struct ast_channel *chan);
70 void (* const fixup_chans)(void *old_chan, void *new_chan);
72 /* Note: Called with PRI lock held */
73 void (* const handle_dchan_exception)(struct sig_pri_pri *pri, int index);
74 void (* const set_dialing)(void *pvt, int flag);
75 void (* const set_callerid)(void *pvt, const struct ast_party_caller *caller);
76 void (* const set_dnid)(void *pvt, const char *dnid);
77 void (* const set_rdnis)(void *pvt, const char *rdnis);
80 #define NUM_DCHANS 4 /*!< No more than 4 d-channels */
81 #define MAX_CHANNELS 672 /*!< No more than a DS3 per trunk group */
83 #define SIG_PRI DAHDI_SIG_CLEAR
84 #define SIG_BRI (0x2000000 | DAHDI_SIG_CLEAR)
85 #define SIG_BRI_PTMP (0X4000000 | DAHDI_SIG_CLEAR)
87 /* QSIG channel mapping option types */
88 #define DAHDI_CHAN_MAPPING_PHYSICAL 0
89 #define DAHDI_CHAN_MAPPING_LOGICAL 1
91 /* Overlap dialing option types */
92 #define DAHDI_OVERLAPDIAL_NONE 0
93 #define DAHDI_OVERLAPDIAL_OUTGOING 1
94 #define DAHDI_OVERLAPDIAL_INCOMING 2
95 #define DAHDI_OVERLAPDIAL_BOTH (DAHDI_OVERLAPDIAL_INCOMING|DAHDI_OVERLAPDIAL_OUTGOING)
97 #ifdef HAVE_PRI_SERVICE_MESSAGES
98 /*! \brief Persistent Service State */
99 #define SRVST_DBKEY "service-state"
100 /*! \brief The out-of-service SERVICE state */
101 #define SRVST_TYPE_OOS "O"
102 /*! \brief SRVST_INITIALIZED is used to indicate a channel being out-of-service
103 * The SRVST_INITIALIZED is mostly used maintain backwards compatibility but also may
104 * mean that the channel has not yet received a RESTART message. If a channel is
105 * out-of-service with this reason a RESTART message will result in the channel
106 * being put into service. */
107 #define SRVST_INITIALIZED 0
108 /*! \brief SRVST_NEAREND is used to indicate that the near end was put out-of-service */
109 #define SRVST_NEAREND (1 << 0)
110 /*! \brief SRVST_FAREND is used to indicate that the far end was taken out-of-service */
111 #define SRVST_FAREND (1 << 1)
112 /*! \brief SRVST_BOTH is used to indicate that both sides of the channel are out-of-service */
113 #define SRVST_BOTH (SRVST_NEAREND | SRVST_FAREND)
115 /*! \brief The AstDB family */
116 static const char dahdi_db[] = "dahdi/registry";
119 struct sig_pri_chan {
120 /* Options to be set by user */
121 unsigned int hidecallerid:1;
122 unsigned int hidecalleridname:1; /*!< Hide just the name not the number for legacy PBX use */
123 unsigned int immediate:1; /*!< Answer before getting digits? */
124 unsigned int inalarm:1;
125 unsigned int priexclusive:1; /*!< Whether or not to override and use exculsive mode for channel selection */
126 unsigned int priindication_oob:1;
127 unsigned int use_callerid:1; /*!< Whether or not to use caller id on this channel */
128 unsigned int use_callingpres:1; /*!< Whether to use the callingpres the calling switch sends */
129 char context[AST_MAX_CONTEXT];
130 int channel; /*!< Channel Number or CRV */
131 char mohinterpret[MAX_MUSICCLASS];
134 /* Options to be checked by user */
135 int cid_ani2; /*!< Automatic Number Identification number (Alternate PRI caller ID number) */
136 int cid_ton; /*!< Type Of Number (TON) */
137 int callingpres; /*!< The value of calling presentation that we're going to use when placing a PRI call */
138 char cid_num[AST_MAX_EXTENSION];
139 char cid_name[AST_MAX_EXTENSION];
140 char cid_ani[AST_MAX_EXTENSION];
141 char exten[AST_MAX_EXTENSION];
143 /* Internal variables -- Don't touch */
144 /* Probably will need DS0 number, DS1 number, and a few other things */
145 char dialdest[256]; /* Queued up digits for overlap dialing. They will be sent out as information messages when setup ACK is received */
147 unsigned int alerting:1; /*!< TRUE if channel is alerting/ringing */
148 unsigned int alreadyhungup:1; /*!< TRUE if the call has already gone/hungup */
149 unsigned int isidlecall:1; /*!< TRUE if this is an idle call */
150 unsigned int proceeding:1; /*!< TRUE if call is in a proceeding state */
151 unsigned int progress:1; /*!< TRUE if the call has seen progress through the network */
152 unsigned int resetting:1; /*!< TRUE if this channel is being reset/restarted */
153 unsigned int setup_ack:1; /*!< TRUE if this channel has received a SETUP_ACKNOWLEDGE */
155 unsigned int outgoing:1;
156 unsigned int digital:1;
158 struct ast_channel *owner;
160 struct sig_pri_pri *pri;
161 q931_call *call; /*!< opaque libpri call control structure */
163 int prioffset; /*!< channel number in span */
164 int logicalspan; /*!< logical span number within trunk group */
165 int mastertrunkgroup; /*!< what trunk group is our master */
167 struct sig_pri_callback *calls;
168 void *chan_pvt; /*!< Private structure of the user of this module. */
169 ast_mutex_t service_lock; /*!< Mutex for service messages */
170 #if defined(HAVE_PRI_REVERSE_CHARGE)
171 int reverse_charging_indication;
176 /* Should be set by user */
177 int pritimers[PRI_MAX_TIMERS];
178 int overlapdial; /*!< In overlap dialing mode */
179 int qsigchannelmapping; /*!< QSIG channel mapping type */
180 int discardremoteholdretrieval; /*!< shall remote hold or remote retrieval notifications be discarded? */
181 int facilityenable; /*!< Enable facility IEs */
182 int dchan_logical_span[NUM_DCHANS]; /*!< Logical offset the DCHAN sits in */
183 int fds[NUM_DCHANS]; /*!< FD's for d-channels */
184 #ifdef HAVE_PRI_SERVICE_MESSAGES
185 unsigned int enable_service_message_support:1; /*!< enable SERVICE message support */
187 #ifdef HAVE_PRI_INBANDDISCONNECT
188 unsigned int inbanddisconnect:1; /*!< Should we support inband audio after receiving DISCONNECT? */
190 int dialplan; /*!< Dialing plan */
191 int localdialplan; /*!< Local dialing plan */
192 char internationalprefix[10]; /*!< country access code ('00' for european dialplans) */
193 char nationalprefix[10]; /*!< area access code ('0' for european dialplans) */
194 char localprefix[20]; /*!< area access code + area code ('0'+area code for european dialplans) */
195 char privateprefix[20]; /*!< for private dialplans */
196 char unknownprefix[20]; /*!< for unknown dialplans */
197 long resetinterval; /*!< Interval (in seconds) for resetting unused channels */
198 char msn_list[AST_MAX_EXTENSION]; /*!< Comma separated list of MSNs to handle. Empty if disabled. */
199 char idleext[AST_MAX_EXTENSION]; /*!< Where to idle extra calls */
200 char idlecontext[AST_MAX_CONTEXT]; /*!< What context to use for idle */
201 char idledial[AST_MAX_EXTENSION]; /*!< What to dial before dumping */
202 int minunused; /*!< Min # of channels to keep empty */
203 int minidle; /*!< Min # of "idling" calls to keep active */
204 int nodetype; /*!< Node type */
205 int switchtype; /*!< Type of switch to emulate */
206 int nsf; /*!< Network-Specific Facilities */
207 int trunkgroup; /*!< What our trunkgroup is */
209 int dchanavail[NUM_DCHANS]; /*!< Whether each channel is available */
210 int debug; /*!< set to true if to dump PRI event info (tested but never set) */
211 int span; /*!< span number put into user output messages */
212 int resetting; /*!< true if span is being reset/restarted */
213 int resetpos; /*!< current position during a reset (-1 if not started) */
214 int sig; /*!< ISDN signalling type (SIG_PRI, SIG_BRI, SIG_BRI_PTMP, etc...) */
216 /* Everything after here is internally set */
217 struct pri *dchans[NUM_DCHANS]; /*!< Actual d-channels */
218 struct pri *pri; /*!< Currently active D-channel */
219 int numchans; /*!< Num of channels we represent */
220 struct sig_pri_chan *pvts[MAX_CHANNELS]; /*!< Member channel pvt structs */
221 pthread_t master; /*!< Thread of master */
222 ast_mutex_t lock; /*!< libpri access Mutex */
223 time_t lastreset; /*!< time when unused channels were last reset */
224 struct sig_pri_callback *calls;
227 int sig_pri_call(struct sig_pri_chan *p, struct ast_channel *ast, char *rdest, int timeout, int layer1);
229 int sig_pri_hangup(struct sig_pri_chan *p, struct ast_channel *ast);
231 int sig_pri_indicate(struct sig_pri_chan *p, struct ast_channel *chan, int condition, const void *data, size_t datalen);
233 int sig_pri_answer(struct sig_pri_chan *p, struct ast_channel *ast);
235 int sig_pri_available(struct sig_pri_chan *p, int channelmatch, ast_group_t groupmatch, int *busy, int *channelmatched, int *groupmatched);
237 void sig_pri_init_pri(struct sig_pri_pri *pri);
239 /* If return 0, it means this function was able to handle it (pre setup digits). If non zero, the user of this
240 * functions should handle it normally (generate inband DTMF) */
241 int sig_pri_digit_begin(struct sig_pri_chan *pvt, struct ast_channel *ast, char digit);
243 int sig_pri_start_pri(struct sig_pri_pri *pri);
245 void sig_pri_chan_alarm_notify(struct sig_pri_chan *p, int noalarm);
247 void pri_event_alarm(struct sig_pri_pri *pri, int index, int before_start_pri);
249 void pri_event_noalarm(struct sig_pri_pri *pri, int index, int before_start_pri);
251 struct ast_channel *sig_pri_request(struct sig_pri_chan *p, enum sig_pri_law law, const struct ast_channel *requestor);
253 struct sig_pri_chan *sig_pri_chan_new(void *pvt_data, struct sig_pri_callback *callback, struct sig_pri_pri *pri, int logicalspan, int channo, int trunkgroup);
255 int pri_is_up(struct sig_pri_pri *pri);
257 void sig_pri_cli_show_spans(int fd, int span, struct sig_pri_pri *pri);
259 void sig_pri_cli_show_span(int fd, int *dchannels, struct sig_pri_pri *pri);
261 int pri_send_keypad_facility_exec(struct sig_pri_chan *p, const char *digits);
262 int pri_send_callrerouting_facility_exec(struct sig_pri_chan *p, enum ast_channel_state chanstate, const char *destination, const char *original, const char *reason);
264 #ifdef HAVE_PRI_SERVICE_MESSAGES
265 int pri_maintenance_bservice(struct pri *pri, struct sig_pri_chan *p, int changestatus);
268 #endif /* _SIG_PRI_H */