00001 #ifndef _SIG_PRI_H
00002 #define _SIG_PRI_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "asterisk/channel.h"
00029 #include "asterisk/frame.h"
00030 #include "asterisk/event.h"
00031 #include "asterisk/ccss.h"
00032 #include <libpri.h>
00033 #include <dahdi/user.h>
00034
00035 #if defined(HAVE_PRI_CCSS)
00036
00037 #define SIG_PRI_DEBUG_NORMAL \
00038 (PRI_DEBUG_APDU | PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q931_STATE | PRI_DEBUG_Q921_STATE \
00039 | PRI_DEBUG_CC)
00040
00041
00042 #define SIG_PRI_DEBUG_INTENSE \
00043 (PRI_DEBUG_APDU | PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q931_STATE | PRI_DEBUG_Q921_STATE \
00044 | PRI_DEBUG_CC | PRI_DEBUG_Q921_RAW | PRI_DEBUG_Q921_DUMP)
00045
00046 #else
00047
00048
00049 #define SIG_PRI_DEBUG_NORMAL \
00050 (PRI_DEBUG_APDU | PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q931_STATE | PRI_DEBUG_Q921_STATE)
00051
00052
00053 #define SIG_PRI_DEBUG_INTENSE \
00054 (PRI_DEBUG_APDU | PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q931_STATE | PRI_DEBUG_Q921_STATE \
00055 | PRI_DEBUG_Q921_RAW | PRI_DEBUG_Q921_DUMP)
00056 #endif
00057
00058 #if 0
00059
00060 #define SIG_PRI_DEBUG_DEFAULT SIG_PRI_DEBUG_NORMAL
00061 #else
00062
00063 #define SIG_PRI_DEBUG_DEFAULT 0
00064 #endif
00065
00066 #define SIG_PRI_AOC_GRANT_S (1 << 0)
00067 #define SIG_PRI_AOC_GRANT_D (1 << 1)
00068 #define SIG_PRI_AOC_GRANT_E (1 << 2)
00069
00070 enum sig_pri_tone {
00071 SIG_PRI_TONE_RINGTONE = 0,
00072 SIG_PRI_TONE_STUTTER,
00073 SIG_PRI_TONE_CONGESTION,
00074 SIG_PRI_TONE_DIALTONE,
00075 SIG_PRI_TONE_DIALRECALL,
00076 SIG_PRI_TONE_INFO,
00077 SIG_PRI_TONE_BUSY,
00078 };
00079
00080 enum sig_pri_law {
00081 SIG_PRI_DEFLAW = 0,
00082 SIG_PRI_ULAW,
00083 SIG_PRI_ALAW
00084 };
00085
00086 struct sig_pri_span;
00087
00088 struct sig_pri_callback {
00089
00090 void (* const unlock_private)(void *pvt);
00091
00092 void (* const lock_private)(void *pvt);
00093
00094
00095
00096
00097
00098
00099 int (* const play_tone)(void *pvt, enum sig_pri_tone tone);
00100
00101 int (* const set_echocanceller)(void *pvt, int enable);
00102 int (* const train_echocanceller)(void *pvt);
00103 int (* const dsp_reset_and_flush_digits)(void *pvt);
00104
00105 struct ast_channel * (* const new_ast_channel)(void *pvt, int state, enum sig_pri_law law, char *exten, const struct ast_channel *chan);
00106
00107 void (* const fixup_chans)(void *old_chan, void *new_chan);
00108
00109
00110 void (* const handle_dchan_exception)(struct sig_pri_span *pri, int index);
00111 void (* const set_alarm)(void *pvt, int in_alarm);
00112 void (* const set_dialing)(void *pvt, int is_dialing);
00113 void (* const set_digital)(void *pvt, int is_digital);
00114 void (* const set_callerid)(void *pvt, const struct ast_party_caller *caller);
00115 void (* const set_dnid)(void *pvt, const char *dnid);
00116 void (* const set_rdnis)(void *pvt, const char *rdnis);
00117 void (* const queue_control)(void *pvt, int subclass);
00118 int (* const new_nobch_intf)(struct sig_pri_span *pri);
00119 void (* const init_config)(void *pvt, struct sig_pri_span *pri);
00120 const char *(* const get_orig_dialstring)(void *pvt);
00121 void (* const make_cc_dialstring)(void *pvt, char *buf, size_t buf_size);
00122 void (* const update_span_devstate)(struct sig_pri_span *pri);
00123
00124 void (* const open_media)(void *pvt);
00125
00126
00127 void (*module_ref)(void);
00128
00129 void (*module_unref)(void);
00130 };
00131
00132 #define SIG_PRI_NUM_DCHANS 4
00133 #define SIG_PRI_MAX_CHANNELS 672
00134
00135 #define SIG_PRI DAHDI_SIG_CLEAR
00136 #define SIG_BRI (0x2000000 | DAHDI_SIG_CLEAR)
00137 #define SIG_BRI_PTMP (0X4000000 | DAHDI_SIG_CLEAR)
00138
00139
00140 #define DAHDI_CHAN_MAPPING_PHYSICAL 0
00141 #define DAHDI_CHAN_MAPPING_LOGICAL 1
00142
00143
00144 #define DAHDI_OVERLAPDIAL_NONE 0
00145 #define DAHDI_OVERLAPDIAL_OUTGOING 1
00146 #define DAHDI_OVERLAPDIAL_INCOMING 2
00147 #define DAHDI_OVERLAPDIAL_BOTH (DAHDI_OVERLAPDIAL_INCOMING|DAHDI_OVERLAPDIAL_OUTGOING)
00148
00149 #if defined(HAVE_PRI_SERVICE_MESSAGES)
00150
00151 #define SRVST_DBKEY "service-state"
00152
00153 #define SRVST_TYPE_OOS "O"
00154
00155
00156
00157
00158
00159 #define SRVST_INITIALIZED 0
00160
00161 #define SRVST_NEAREND (1 << 0)
00162
00163 #define SRVST_FAREND (1 << 1)
00164
00165 #define SRVST_BOTH (SRVST_NEAREND | SRVST_FAREND)
00166
00167
00168 static const char dahdi_db[] = "dahdi/registry";
00169 #endif
00170
00171 struct sig_pri_chan {
00172
00173 unsigned int hidecallerid:1;
00174 unsigned int hidecalleridname:1;
00175 unsigned int immediate:1;
00176 unsigned int priexclusive:1;
00177 unsigned int priindication_oob:1;
00178 unsigned int use_callerid:1;
00179 unsigned int use_callingpres:1;
00180 char context[AST_MAX_CONTEXT];
00181 char mohinterpret[MAX_MUSICCLASS];
00182 int stripmsd;
00183 int channel;
00184
00185
00186 int cid_ani2;
00187 int cid_ton;
00188 int callingpres;
00189 char cid_num[AST_MAX_EXTENSION];
00190 char cid_subaddr[AST_MAX_EXTENSION];
00191 char cid_name[AST_MAX_EXTENSION];
00192 char cid_ani[AST_MAX_EXTENSION];
00193
00194 char user_tag[AST_MAX_EXTENSION];
00195 char exten[AST_MAX_EXTENSION];
00196
00197
00198
00199 char dialdest[256];
00200 #if defined(HAVE_PRI_SETUP_KEYPAD)
00201
00202 char keypad_digits[AST_MAX_EXTENSION];
00203 #endif
00204
00205 #if defined(HAVE_PRI_AOC_EVENTS)
00206 struct pri_subcmd_aoc_e aoc_e;
00207 int aoc_s_request_invoke_id;
00208 unsigned int aoc_s_request_invoke_id_valid:1;
00209 unsigned int waiting_for_aoce:1;
00210 unsigned int holding_aoce:1;
00211 #endif
00212 unsigned int inalarm:1;
00213 unsigned int alerting:1;
00214 unsigned int alreadyhungup:1;
00215 unsigned int isidlecall:1;
00216 unsigned int proceeding:1;
00217 unsigned int progress:1;
00218 unsigned int resetting:1;
00219 unsigned int setup_ack:1;
00220
00221 unsigned int outgoing:1;
00222 unsigned int digital:1;
00223
00224 unsigned int no_b_channel:1;
00225 #if defined(HAVE_PRI_CALL_WAITING)
00226
00227 unsigned int is_call_waiting:1;
00228 #endif
00229
00230 struct ast_channel *owner;
00231
00232 struct sig_pri_span *pri;
00233 q931_call *call;
00234
00235 int prioffset;
00236 int logicalspan;
00237 int mastertrunkgroup;
00238 #if defined(HAVE_PRI_SERVICE_MESSAGES)
00239
00240 unsigned service_status;
00241 #endif
00242
00243 struct sig_pri_callback *calls;
00244 void *chan_pvt;
00245 #if defined(HAVE_PRI_REVERSE_CHARGE)
00246
00247
00248
00249
00250
00251
00252
00253 int reverse_charging_indication;
00254 #endif
00255 };
00256
00257 #if defined(HAVE_PRI_MWI)
00258
00259 #define SIG_PRI_MAX_MWI_MAILBOXES 8
00260
00261 #define SIG_PRI_MAX_MWI_MBOX_NUMBER_LEN 10
00262
00263 #define SIG_PRI_MAX_MWI_CONTEXT_LEN 10
00264
00265
00266
00267
00268
00269
00270 #define SIG_PRI_MAX_MWI_MAILBOX_STR (SIG_PRI_MAX_MWI_MAILBOXES \
00271 * (SIG_PRI_MAX_MWI_MBOX_NUMBER_LEN + 1 + SIG_PRI_MAX_MWI_CONTEXT_LEN + 1))
00272
00273 struct sig_pri_mbox {
00274
00275
00276
00277
00278 struct ast_event_sub *sub;
00279
00280 const char *number;
00281
00282 const char *context;
00283 };
00284 #endif
00285
00286 struct sig_pri_span {
00287
00288 struct ast_cc_config_params *cc_params;
00289 int pritimers[PRI_MAX_TIMERS];
00290 int overlapdial;
00291 int qsigchannelmapping;
00292 int discardremoteholdretrieval;
00293 int facilityenable;
00294 int dchan_logical_span[SIG_PRI_NUM_DCHANS];
00295 int fds[SIG_PRI_NUM_DCHANS];
00296
00297 #if defined(HAVE_PRI_AOC_EVENTS)
00298 int aoc_passthrough_flag;
00299 unsigned int aoce_delayhangup:1;
00300 #endif
00301
00302 #if defined(HAVE_PRI_SERVICE_MESSAGES)
00303 unsigned int enable_service_message_support:1;
00304 #endif
00305 #ifdef HAVE_PRI_INBANDDISCONNECT
00306 unsigned int inbanddisconnect:1;
00307 #endif
00308 #if defined(HAVE_PRI_CALL_HOLD)
00309
00310 unsigned int hold_disconnect_transfer:1;
00311 #endif
00312
00313
00314
00315
00316 unsigned int transfer:1;
00317 #if defined(HAVE_PRI_CALL_WAITING)
00318
00319 unsigned int allow_call_waiting_calls:1;
00320 #endif
00321
00322
00323
00324
00325 unsigned int append_msn_to_user_tag:1;
00326 int dialplan;
00327 int localdialplan;
00328 char internationalprefix[10];
00329 char nationalprefix[10];
00330 char localprefix[20];
00331 char privateprefix[20];
00332 char unknownprefix[20];
00333 long resetinterval;
00334 #if defined(HAVE_PRI_MWI)
00335
00336 struct sig_pri_mbox mbox[SIG_PRI_MAX_MWI_MAILBOXES];
00337
00338
00339
00340
00341
00342
00343 char mwi_mailboxes[SIG_PRI_MAX_MWI_MAILBOX_STR];
00344 #endif
00345
00346
00347
00348
00349 char initial_user_tag[AST_MAX_EXTENSION];
00350 char msn_list[AST_MAX_EXTENSION];
00351 char idleext[AST_MAX_EXTENSION];
00352 char idlecontext[AST_MAX_CONTEXT];
00353 char idledial[AST_MAX_EXTENSION];
00354 int minunused;
00355 int minidle;
00356 int nodetype;
00357 int switchtype;
00358 int nsf;
00359 int trunkgroup;
00360 #if defined(HAVE_PRI_CCSS)
00361 int cc_ptmp_recall_mode;
00362 int cc_qsig_signaling_link_req;
00363 int cc_qsig_signaling_link_rsp;
00364 #endif
00365 #if defined(HAVE_PRI_CALL_WAITING)
00366
00367
00368
00369
00370 int max_call_waiting_calls;
00371 struct {
00372 int stripmsd;
00373 unsigned int hidecallerid:1;
00374 unsigned int hidecalleridname:1;
00375 unsigned int immediate:1;
00376 unsigned int priexclusive:1;
00377 unsigned int priindication_oob:1;
00378 unsigned int use_callerid:1;
00379 unsigned int use_callingpres:1;
00380 char context[AST_MAX_CONTEXT];
00381 char mohinterpret[MAX_MUSICCLASS];
00382 } ch_cfg;
00383
00384
00385
00386
00387
00388
00389 int num_call_waiting_calls;
00390 #endif
00391 int dchanavail[SIG_PRI_NUM_DCHANS];
00392 int debug;
00393 int span;
00394 int resetting;
00395 int resetpos;
00396 int sig;
00397 int new_chan_seq;
00398
00399 unsigned int no_d_channels:1;
00400
00401
00402 struct pri *dchans[SIG_PRI_NUM_DCHANS];
00403 struct pri *pri;
00404
00405
00406
00407
00408 void *no_b_chan_iflist;
00409
00410
00411
00412
00413 void *no_b_chan_end;
00414 int numchans;
00415 struct sig_pri_chan *pvts[SIG_PRI_MAX_CHANNELS];
00416 pthread_t master;
00417 ast_mutex_t lock;
00418 time_t lastreset;
00419 struct sig_pri_callback *calls;
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429 int congestion_devstate;
00430 #if defined(THRESHOLD_DEVSTATE_PLACEHOLDER)
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444 int threshold_devstate;
00445
00446
00447
00448
00449 int user_busy_threshold;
00450 #endif
00451 };
00452
00453 void sig_pri_extract_called_num_subaddr(struct sig_pri_chan *p, const char *rdest, char *called, size_t called_buff_size);
00454 int sig_pri_call(struct sig_pri_chan *p, struct ast_channel *ast, char *rdest, int timeout, int layer1);
00455
00456 int sig_pri_hangup(struct sig_pri_chan *p, struct ast_channel *ast);
00457
00458 int sig_pri_indicate(struct sig_pri_chan *p, struct ast_channel *chan, int condition, const void *data, size_t datalen);
00459
00460 int sig_pri_answer(struct sig_pri_chan *p, struct ast_channel *ast);
00461
00462 int sig_pri_available(struct sig_pri_chan **pvt, int is_specific_channel);
00463
00464 void sig_pri_init_pri(struct sig_pri_span *pri);
00465
00466
00467
00468 int sig_pri_digit_begin(struct sig_pri_chan *pvt, struct ast_channel *ast, char digit);
00469
00470 void sig_pri_stop_pri(struct sig_pri_span *pri);
00471 int sig_pri_start_pri(struct sig_pri_span *pri);
00472
00473 void sig_pri_chan_alarm_notify(struct sig_pri_chan *p, int noalarm);
00474
00475 void pri_event_alarm(struct sig_pri_span *pri, int index, int before_start_pri);
00476
00477 void pri_event_noalarm(struct sig_pri_span *pri, int index, int before_start_pri);
00478
00479 struct ast_channel *sig_pri_request(struct sig_pri_chan *p, enum sig_pri_law law, const struct ast_channel *requestor, int transfercapability);
00480
00481 struct sig_pri_chan *sig_pri_chan_new(void *pvt_data, struct sig_pri_callback *callback, struct sig_pri_span *pri, int logicalspan, int channo, int trunkgroup);
00482 void sig_pri_chan_delete(struct sig_pri_chan *doomed);
00483
00484 int pri_is_up(struct sig_pri_span *pri);
00485
00486 void sig_pri_cli_show_spans(int fd, int span, struct sig_pri_span *pri);
00487
00488 void sig_pri_cli_show_span(int fd, int *dchannels, struct sig_pri_span *pri);
00489
00490 int pri_send_keypad_facility_exec(struct sig_pri_chan *p, const char *digits);
00491 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);
00492
00493 #if defined(HAVE_PRI_SERVICE_MESSAGES)
00494 int pri_maintenance_bservice(struct pri *pri, struct sig_pri_chan *p, int changestatus);
00495 #endif
00496
00497 void sig_pri_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, struct sig_pri_chan *pchan);
00498
00499 int sig_pri_cc_agent_init(struct ast_cc_agent *agent, struct sig_pri_chan *pvt_chan);
00500 int sig_pri_cc_agent_start_offer_timer(struct ast_cc_agent *agent);
00501 int sig_pri_cc_agent_stop_offer_timer(struct ast_cc_agent *agent);
00502 void sig_pri_cc_agent_req_ack(struct ast_cc_agent *agent);
00503 int sig_pri_cc_agent_status_req(struct ast_cc_agent *agent);
00504 int sig_pri_cc_agent_stop_ringing(struct ast_cc_agent *agent);
00505 int sig_pri_cc_agent_party_b_free(struct ast_cc_agent *agent);
00506 int sig_pri_cc_agent_start_monitoring(struct ast_cc_agent *agent);
00507 int sig_pri_cc_agent_callee_available(struct ast_cc_agent *agent);
00508 void sig_pri_cc_agent_destructor(struct ast_cc_agent *agent);
00509
00510 int sig_pri_cc_monitor_req_cc(struct ast_cc_monitor *monitor, int *available_timer_id);
00511 int sig_pri_cc_monitor_suspend(struct ast_cc_monitor *monitor);
00512 int sig_pri_cc_monitor_unsuspend(struct ast_cc_monitor *monitor);
00513 int sig_pri_cc_monitor_status_rsp(struct ast_cc_monitor *monitor, enum ast_device_state devstate);
00514 int sig_pri_cc_monitor_cancel_available_timer(struct ast_cc_monitor *monitor, int *sched_id);
00515 void sig_pri_cc_monitor_destructor(void *monitor_pvt);
00516
00517 int sig_pri_load(const char *cc_type_name);
00518 void sig_pri_unload(void);
00519
00520 #endif