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