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
00087 enum sig_pri_call_level {
00088
00089 SIG_PRI_CALL_LEVEL_IDLE,
00090
00091 SIG_PRI_CALL_LEVEL_SETUP,
00092
00093 SIG_PRI_CALL_LEVEL_OVERLAP,
00094
00095 SIG_PRI_CALL_LEVEL_PROCEEDING,
00096
00097 SIG_PRI_CALL_LEVEL_ALERTING,
00098
00099 SIG_PRI_CALL_LEVEL_DEFER_DIAL,
00100
00101 SIG_PRI_CALL_LEVEL_CONNECT,
00102 };
00103
00104 enum sig_pri_reset_state {
00105
00106 SIG_PRI_RESET_IDLE,
00107
00108
00109
00110
00111 SIG_PRI_RESET_ACTIVE,
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 SIG_PRI_RESET_NO_ACK,
00123 };
00124
00125 struct sig_pri_span;
00126
00127 struct sig_pri_callback {
00128
00129 void (* const unlock_private)(void *pvt);
00130
00131 void (* const lock_private)(void *pvt);
00132
00133
00134
00135
00136
00137
00138 int (* const play_tone)(void *pvt, enum sig_pri_tone tone);
00139
00140 int (* const set_echocanceller)(void *pvt, int enable);
00141 int (* const train_echocanceller)(void *pvt);
00142 int (* const dsp_reset_and_flush_digits)(void *pvt);
00143
00144 struct ast_channel * (* const new_ast_channel)(void *pvt, int state, enum sig_pri_law law, char *exten, const struct ast_channel *chan);
00145
00146 void (* const fixup_chans)(void *old_chan, void *new_chan);
00147
00148
00149 void (* const handle_dchan_exception)(struct sig_pri_span *pri, int index);
00150 void (* const set_alarm)(void *pvt, int in_alarm);
00151 void (* const set_dialing)(void *pvt, int is_dialing);
00152 void (* const set_digital)(void *pvt, int is_digital);
00153 void (* const set_outgoing)(void *pvt, int is_outgoing);
00154 void (* const set_callerid)(void *pvt, const struct ast_party_caller *caller);
00155 void (* const set_dnid)(void *pvt, const char *dnid);
00156 void (* const set_rdnis)(void *pvt, const char *rdnis);
00157 void (* const queue_control)(void *pvt, int subclass);
00158 int (* const new_nobch_intf)(struct sig_pri_span *pri);
00159 void (* const init_config)(void *pvt, struct sig_pri_span *pri);
00160 const char *(* const get_orig_dialstring)(void *pvt);
00161 void (* const make_cc_dialstring)(void *pvt, char *buf, size_t buf_size);
00162 void (* const update_span_devstate)(struct sig_pri_span *pri);
00163 void (* const dial_digits)(void *pvt, const char *dial_string);
00164
00165 void (* const open_media)(void *pvt);
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175 void (* const ami_channel_event)(void *pvt, struct ast_channel *chan);
00176
00177
00178 void (*module_ref)(void);
00179
00180 void (*module_unref)(void);
00181 };
00182
00183 #define SIG_PRI_NUM_DCHANS 4
00184 #define SIG_PRI_MAX_CHANNELS 672
00185
00186 #define SIG_PRI DAHDI_SIG_CLEAR
00187 #define SIG_BRI (0x2000000 | DAHDI_SIG_CLEAR)
00188 #define SIG_BRI_PTMP (0X4000000 | DAHDI_SIG_CLEAR)
00189
00190
00191 #define DAHDI_CHAN_MAPPING_PHYSICAL 0
00192 #define DAHDI_CHAN_MAPPING_LOGICAL 1
00193
00194
00195 #define DAHDI_OVERLAPDIAL_NONE 0
00196 #define DAHDI_OVERLAPDIAL_OUTGOING 1
00197 #define DAHDI_OVERLAPDIAL_INCOMING 2
00198 #define DAHDI_OVERLAPDIAL_BOTH (DAHDI_OVERLAPDIAL_INCOMING|DAHDI_OVERLAPDIAL_OUTGOING)
00199
00200 #if defined(HAVE_PRI_SERVICE_MESSAGES)
00201
00202 #define SRVST_DBKEY "service-state"
00203
00204 #define SRVST_TYPE_OOS "O"
00205
00206
00207
00208
00209
00210 #define SRVST_INITIALIZED 0
00211
00212 #define SRVST_NEAREND (1 << 0)
00213
00214 #define SRVST_FAREND (1 << 1)
00215
00216 #define SRVST_BOTH (SRVST_NEAREND | SRVST_FAREND)
00217
00218
00219 static const char dahdi_db[] = "dahdi/registry";
00220 #endif
00221
00222 struct sig_pri_chan {
00223
00224 unsigned int hidecallerid:1;
00225 unsigned int hidecalleridname:1;
00226 unsigned int immediate:1;
00227 unsigned int priexclusive:1;
00228 unsigned int priindication_oob:1;
00229 unsigned int use_callerid:1;
00230 unsigned int use_callingpres:1;
00231 char context[AST_MAX_CONTEXT];
00232 char mohinterpret[MAX_MUSICCLASS];
00233 int stripmsd;
00234 int channel;
00235
00236
00237 int cid_ani2;
00238 int cid_ton;
00239 int callingpres;
00240 char cid_num[AST_MAX_EXTENSION];
00241 char cid_subaddr[AST_MAX_EXTENSION];
00242 char cid_name[AST_MAX_EXTENSION];
00243 char cid_ani[AST_MAX_EXTENSION];
00244
00245 char user_tag[AST_MAX_EXTENSION];
00246 char exten[AST_MAX_EXTENSION];
00247
00248
00249
00250 char dialdest[256];
00251 #if defined(HAVE_PRI_SETUP_KEYPAD)
00252
00253 char keypad_digits[AST_MAX_EXTENSION];
00254 #endif
00255
00256 char deferred_digits[AST_MAX_EXTENSION];
00257
00258 #if defined(HAVE_PRI_AOC_EVENTS)
00259 struct pri_subcmd_aoc_e aoc_e;
00260 int aoc_s_request_invoke_id;
00261 unsigned int aoc_s_request_invoke_id_valid:1;
00262 unsigned int waiting_for_aoce:1;
00263 unsigned int holding_aoce:1;
00264 #endif
00265 unsigned int inalarm:1;
00266 unsigned int alreadyhungup:1;
00267 unsigned int isidlecall:1;
00268 unsigned int progress:1;
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280 unsigned int allocated:1;
00281 unsigned int outgoing:1;
00282 unsigned int digital:1;
00283
00284 unsigned int no_b_channel:1;
00285 #if defined(HAVE_PRI_CALL_WAITING)
00286
00287 unsigned int is_call_waiting:1;
00288 #endif
00289
00290 struct ast_channel *owner;
00291
00292 struct sig_pri_span *pri;
00293 q931_call *call;
00294
00295
00296 enum sig_pri_call_level call_level;
00297
00298 enum sig_pri_reset_state resetting;
00299 int prioffset;
00300 int logicalspan;
00301 int mastertrunkgroup;
00302 #if defined(HAVE_PRI_SERVICE_MESSAGES)
00303
00304 unsigned service_status;
00305 #endif
00306
00307 struct sig_pri_callback *calls;
00308 void *chan_pvt;
00309 #if defined(HAVE_PRI_REVERSE_CHARGE)
00310
00311
00312
00313
00314
00315
00316
00317 int reverse_charging_indication;
00318 #endif
00319 };
00320
00321 #if defined(HAVE_PRI_MWI)
00322
00323 #define SIG_PRI_MAX_MWI_MAILBOXES 8
00324
00325 #define SIG_PRI_MAX_MWI_MBOX_NUMBER_LEN 10
00326
00327 #define SIG_PRI_MAX_MWI_CONTEXT_LEN 10
00328
00329
00330
00331
00332
00333
00334 #define SIG_PRI_MAX_MWI_MAILBOX_STR (SIG_PRI_MAX_MWI_MAILBOXES \
00335 * (SIG_PRI_MAX_MWI_MBOX_NUMBER_LEN + 1 + SIG_PRI_MAX_MWI_CONTEXT_LEN + 1))
00336
00337 struct sig_pri_mbox {
00338
00339
00340
00341
00342 struct ast_event_sub *sub;
00343
00344 const char *number;
00345
00346 const char *context;
00347 };
00348 #endif
00349
00350 struct sig_pri_span {
00351
00352 struct ast_cc_config_params *cc_params;
00353 int pritimers[PRI_MAX_TIMERS];
00354 int overlapdial;
00355 int qsigchannelmapping;
00356 int discardremoteholdretrieval;
00357 int facilityenable;
00358 #if defined(HAVE_PRI_L2_PERSISTENCE)
00359
00360 int l2_persistence;
00361 #endif
00362 int dchan_logical_span[SIG_PRI_NUM_DCHANS];
00363 int fds[SIG_PRI_NUM_DCHANS];
00364
00365 #if defined(HAVE_PRI_AOC_EVENTS)
00366 int aoc_passthrough_flag;
00367 unsigned int aoce_delayhangup:1;
00368 #endif
00369
00370 #if defined(HAVE_PRI_SERVICE_MESSAGES)
00371 unsigned int enable_service_message_support:1;
00372 #endif
00373 #ifdef HAVE_PRI_INBANDDISCONNECT
00374 unsigned int inbanddisconnect:1;
00375 #endif
00376 #if defined(HAVE_PRI_CALL_HOLD)
00377
00378 unsigned int hold_disconnect_transfer:1;
00379 #endif
00380
00381
00382
00383
00384 unsigned int transfer:1;
00385 #if defined(HAVE_PRI_CALL_WAITING)
00386
00387 unsigned int allow_call_waiting_calls:1;
00388 #endif
00389
00390 unsigned int layer1_ignored:1;
00391
00392
00393
00394
00395 unsigned int append_msn_to_user_tag:1;
00396 int dialplan;
00397 int localdialplan;
00398 char internationalprefix[10];
00399 char nationalprefix[10];
00400 char localprefix[20];
00401 char privateprefix[20];
00402 char unknownprefix[20];
00403 long resetinterval;
00404 #if defined(HAVE_PRI_MWI)
00405
00406 struct sig_pri_mbox mbox[SIG_PRI_MAX_MWI_MAILBOXES];
00407
00408
00409
00410
00411
00412
00413 char mwi_mailboxes[SIG_PRI_MAX_MWI_MAILBOX_STR];
00414 #endif
00415
00416
00417
00418
00419 char initial_user_tag[AST_MAX_EXTENSION];
00420 char msn_list[AST_MAX_EXTENSION];
00421 char idleext[AST_MAX_EXTENSION];
00422 char idlecontext[AST_MAX_CONTEXT];
00423 char idledial[AST_MAX_EXTENSION];
00424 int minunused;
00425 int minidle;
00426 int nodetype;
00427 int switchtype;
00428 int nsf;
00429 int trunkgroup;
00430 #if defined(HAVE_PRI_CCSS)
00431 int cc_ptmp_recall_mode;
00432 int cc_qsig_signaling_link_req;
00433 int cc_qsig_signaling_link_rsp;
00434 #endif
00435 #if defined(HAVE_PRI_CALL_WAITING)
00436
00437
00438
00439
00440 int max_call_waiting_calls;
00441 struct {
00442 int stripmsd;
00443 unsigned int hidecallerid:1;
00444 unsigned int hidecalleridname:1;
00445 unsigned int immediate:1;
00446 unsigned int priexclusive:1;
00447 unsigned int priindication_oob:1;
00448 unsigned int use_callerid:1;
00449 unsigned int use_callingpres:1;
00450 char context[AST_MAX_CONTEXT];
00451 char mohinterpret[MAX_MUSICCLASS];
00452 } ch_cfg;
00453
00454
00455
00456
00457
00458
00459 int num_call_waiting_calls;
00460 #endif
00461 int dchanavail[SIG_PRI_NUM_DCHANS];
00462 int debug;
00463 int span;
00464 int resetting;
00465 int resetpos;
00466 int sig;
00467 int new_chan_seq;
00468
00469 unsigned int no_d_channels:1;
00470
00471
00472 struct pri *dchans[SIG_PRI_NUM_DCHANS];
00473 struct pri *pri;
00474
00475
00476
00477
00478 void *no_b_chan_iflist;
00479
00480
00481
00482
00483 void *no_b_chan_end;
00484 int numchans;
00485 struct sig_pri_chan *pvts[SIG_PRI_MAX_CHANNELS];
00486 pthread_t master;
00487 ast_mutex_t lock;
00488 time_t lastreset;
00489 struct sig_pri_callback *calls;
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499 int congestion_devstate;
00500 #if defined(THRESHOLD_DEVSTATE_PLACEHOLDER)
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514 int threshold_devstate;
00515
00516
00517
00518
00519 int user_busy_threshold;
00520 #endif
00521 };
00522
00523 void sig_pri_extract_called_num_subaddr(struct sig_pri_chan *p, const char *rdest, char *called, size_t called_buff_size);
00524 int sig_pri_call(struct sig_pri_chan *p, struct ast_channel *ast, char *rdest, int timeout, int layer1);
00525
00526 int sig_pri_hangup(struct sig_pri_chan *p, struct ast_channel *ast);
00527
00528 int sig_pri_indicate(struct sig_pri_chan *p, struct ast_channel *chan, int condition, const void *data, size_t datalen);
00529
00530 int sig_pri_answer(struct sig_pri_chan *p, struct ast_channel *ast);
00531
00532 int sig_pri_is_chan_available(struct sig_pri_chan *pvt);
00533 int sig_pri_available(struct sig_pri_chan **pvt, int is_specific_channel);
00534
00535 void sig_pri_init_pri(struct sig_pri_span *pri);
00536
00537
00538
00539 int sig_pri_digit_begin(struct sig_pri_chan *pvt, struct ast_channel *ast, char digit);
00540 void sig_pri_dial_complete(struct sig_pri_chan *pvt, struct ast_channel *ast);
00541
00542 void sig_pri_stop_pri(struct sig_pri_span *pri);
00543 int sig_pri_start_pri(struct sig_pri_span *pri);
00544
00545 void sig_pri_set_alarm(struct sig_pri_chan *p, int in_alarm);
00546 void sig_pri_chan_alarm_notify(struct sig_pri_chan *p, int noalarm);
00547
00548 int sig_pri_is_alarm_ignored(struct sig_pri_span *pri);
00549 void pri_event_alarm(struct sig_pri_span *pri, int index, int before_start_pri);
00550 void pri_event_noalarm(struct sig_pri_span *pri, int index, int before_start_pri);
00551
00552 struct ast_channel *sig_pri_request(struct sig_pri_chan *p, enum sig_pri_law law, const struct ast_channel *requestor, int transfercapability);
00553
00554 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);
00555 void sig_pri_chan_delete(struct sig_pri_chan *doomed);
00556
00557 int pri_is_up(struct sig_pri_span *pri);
00558
00559 void sig_pri_cli_show_channels_header(int fd);
00560 void sig_pri_cli_show_channels(int fd, struct sig_pri_span *pri);
00561 void sig_pri_cli_show_spans(int fd, int span, struct sig_pri_span *pri);
00562
00563 void sig_pri_cli_show_span(int fd, int *dchannels, struct sig_pri_span *pri);
00564
00565 int pri_send_keypad_facility_exec(struct sig_pri_chan *p, const char *digits);
00566 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);
00567
00568 #if defined(HAVE_PRI_SERVICE_MESSAGES)
00569 int pri_maintenance_bservice(struct pri *pri, struct sig_pri_chan *p, int changestatus);
00570 #endif
00571
00572 void sig_pri_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, struct sig_pri_chan *pchan);
00573
00574 int sig_pri_cc_agent_init(struct ast_cc_agent *agent, struct sig_pri_chan *pvt_chan);
00575 int sig_pri_cc_agent_start_offer_timer(struct ast_cc_agent *agent);
00576 int sig_pri_cc_agent_stop_offer_timer(struct ast_cc_agent *agent);
00577 void sig_pri_cc_agent_req_rsp(struct ast_cc_agent *agent, enum ast_cc_agent_response_reason reason);
00578 int sig_pri_cc_agent_status_req(struct ast_cc_agent *agent);
00579 int sig_pri_cc_agent_stop_ringing(struct ast_cc_agent *agent);
00580 int sig_pri_cc_agent_party_b_free(struct ast_cc_agent *agent);
00581 int sig_pri_cc_agent_start_monitoring(struct ast_cc_agent *agent);
00582 int sig_pri_cc_agent_callee_available(struct ast_cc_agent *agent);
00583 void sig_pri_cc_agent_destructor(struct ast_cc_agent *agent);
00584
00585 int sig_pri_cc_monitor_req_cc(struct ast_cc_monitor *monitor, int *available_timer_id);
00586 int sig_pri_cc_monitor_suspend(struct ast_cc_monitor *monitor);
00587 int sig_pri_cc_monitor_unsuspend(struct ast_cc_monitor *monitor);
00588 int sig_pri_cc_monitor_status_rsp(struct ast_cc_monitor *monitor, enum ast_device_state devstate);
00589 int sig_pri_cc_monitor_cancel_available_timer(struct ast_cc_monitor *monitor, int *sched_id);
00590 void sig_pri_cc_monitor_destructor(void *monitor_pvt);
00591
00592 int sig_pri_load(const char *cc_type_name);
00593 void sig_pri_unload(void);
00594
00595 #endif