00001
00002
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
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #include "asterisk.h"
00049
00050 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 152286 $")
00051
00052 #include <stdio.h>
00053 #include <string.h>
00054 #ifdef __NetBSD__
00055 #include <pthread.h>
00056 #include <signal.h>
00057 #else
00058 #include <sys/signal.h>
00059 #endif
00060 #include <errno.h>
00061 #include <stdlib.h>
00062 #if !defined(SOLARIS) && !defined(__FreeBSD__)
00063 #include <stdint.h>
00064 #endif
00065 #include <unistd.h>
00066 #include <sys/ioctl.h>
00067 #include <math.h>
00068 #include <ctype.h>
00069
00070 #ifdef HAVE_PRI
00071 #include <libpri.h>
00072 #endif
00073
00074 #include "asterisk/lock.h"
00075 #include "asterisk/channel.h"
00076 #include "asterisk/config.h"
00077 #include "asterisk/logger.h"
00078 #include "asterisk/module.h"
00079 #include "asterisk/pbx.h"
00080 #include "asterisk/options.h"
00081 #include "asterisk/file.h"
00082 #include "asterisk/ulaw.h"
00083 #include "asterisk/alaw.h"
00084 #include "asterisk/callerid.h"
00085 #include "asterisk/adsi.h"
00086 #include "asterisk/cli.h"
00087 #include "asterisk/cdr.h"
00088 #include "asterisk/features.h"
00089 #include "asterisk/musiconhold.h"
00090 #include "asterisk/say.h"
00091 #include "asterisk/tdd.h"
00092 #include "asterisk/app.h"
00093 #include "asterisk/dsp.h"
00094 #include "asterisk/astdb.h"
00095 #include "asterisk/manager.h"
00096 #include "asterisk/causes.h"
00097 #include "asterisk/term.h"
00098 #include "asterisk/utils.h"
00099 #include "asterisk/transcap.h"
00100 #include "asterisk/stringfields.h"
00101 #include "asterisk/abstract_jb.h"
00102 #include "asterisk/smdi.h"
00103 #include "asterisk/astobj.h"
00104 #define SMDI_MD_WAIT_TIMEOUT 1500
00105
00106 #include "asterisk/dahdi_compat.h"
00107 #include "asterisk/tonezone_compat.h"
00108
00109
00110 static struct ast_jb_conf default_jbconf =
00111 {
00112 .flags = 0,
00113 .max_size = -1,
00114 .resync_threshold = -1,
00115 .impl = ""
00116 };
00117 static struct ast_jb_conf global_jbconf;
00118
00119 #ifndef DAHDI_TONEDETECT
00120
00121 #define DAHDI_EVENT_DTMFDOWN 0
00122 #define DAHDI_EVENT_DTMFUP 0
00123 #endif
00124
00125
00126 #undef SUPPORT_USERUSER
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147 #define DEFAULT_CIDRINGS 1
00148
00149 #define CHANNEL_PSEUDO -12
00150
00151 #define AST_LAW(p) (((p)->law == DAHDI_LAW_ALAW) ? AST_FORMAT_ALAW : AST_FORMAT_ULAW)
00152
00153
00154 #define NEED_MFDETECT(p) (((p)->sig == SIG_FEATDMF) || ((p)->sig == SIG_FEATDMF_TA) || ((p)->sig == SIG_E911) || ((p)->sig == SIG_FGC_CAMA) || ((p)->sig == SIG_FGC_CAMAMF) || ((p)->sig == SIG_FEATB))
00155
00156 static const char tdesc[] = "DAHDI Telephony Driver"
00157 #ifdef HAVE_PRI
00158 " w/PRI"
00159 #endif
00160 ;
00161
00162 #define SIG_EM DAHDI_SIG_EM
00163 #define SIG_EMWINK (0x0100000 | DAHDI_SIG_EM)
00164 #define SIG_FEATD (0x0200000 | DAHDI_SIG_EM)
00165 #define SIG_FEATDMF (0x0400000 | DAHDI_SIG_EM)
00166 #define SIG_FEATB (0x0800000 | DAHDI_SIG_EM)
00167 #define SIG_E911 (0x1000000 | DAHDI_SIG_EM)
00168 #define SIG_FEATDMF_TA (0x2000000 | DAHDI_SIG_EM)
00169 #define SIG_FGC_CAMA (0x4000000 | DAHDI_SIG_EM)
00170 #define SIG_FGC_CAMAMF (0x8000000 | DAHDI_SIG_EM)
00171 #define SIG_FXSLS DAHDI_SIG_FXSLS
00172 #define SIG_FXSGS DAHDI_SIG_FXSGS
00173 #define SIG_FXSKS DAHDI_SIG_FXSKS
00174 #define SIG_FXOLS DAHDI_SIG_FXOLS
00175 #define SIG_FXOGS DAHDI_SIG_FXOGS
00176 #define SIG_FXOKS DAHDI_SIG_FXOKS
00177 #define SIG_PRI DAHDI_SIG_CLEAR
00178 #define SIG_SF DAHDI_SIG_SF
00179 #define SIG_SFWINK (0x0100000 | DAHDI_SIG_SF)
00180 #define SIG_SF_FEATD (0x0200000 | DAHDI_SIG_SF)
00181 #define SIG_SF_FEATDMF (0x0400000 | DAHDI_SIG_SF)
00182 #define SIG_SF_FEATB (0x0800000 | DAHDI_SIG_SF)
00183 #define SIG_EM_E1 DAHDI_SIG_EM_E1
00184 #define SIG_GR303FXOKS (0x0100000 | DAHDI_SIG_FXOKS)
00185 #define SIG_GR303FXSKS (0x0100000 | DAHDI_SIG_FXSKS)
00186
00187 #define NUM_SPANS 32
00188 #define NUM_DCHANS 4
00189 #define MAX_CHANNELS 672
00190
00191 #define CHAN_PSEUDO -2
00192
00193 #define DCHAN_PROVISIONED (1 << 0)
00194 #define DCHAN_NOTINALARM (1 << 1)
00195 #define DCHAN_UP (1 << 2)
00196
00197 #define DCHAN_AVAILABLE (DCHAN_PROVISIONED | DCHAN_NOTINALARM | DCHAN_UP)
00198
00199 static char defaultcic[64] = "";
00200 static char defaultozz[64] = "";
00201
00202 static char progzone[10] = "";
00203
00204 static int distinctiveringaftercid = 0;
00205
00206 static int numbufs = 4;
00207
00208 #ifdef HAVE_PRI
00209 static struct ast_channel inuse;
00210 #ifdef PRI_GETSET_TIMERS
00211 static int pritimers[PRI_MAX_TIMERS];
00212 #endif
00213 static int pridebugfd = -1;
00214 static char pridebugfilename[1024] = "";
00215 #endif
00216
00217
00218 static int firstdigittimeout = 16000;
00219
00220
00221 static int gendigittimeout = 8000;
00222
00223
00224 static int matchdigittimeout = 3000;
00225
00226
00227 AST_MUTEX_DEFINE_STATIC(iflock);
00228
00229
00230 static int ifcount = 0;
00231
00232 #ifdef HAVE_PRI
00233 AST_MUTEX_DEFINE_STATIC(pridebugfdlock);
00234 #endif
00235
00236
00237
00238 AST_MUTEX_DEFINE_STATIC(monlock);
00239
00240
00241
00242 static pthread_t monitor_thread = AST_PTHREADT_NULL;
00243 static ast_cond_t ss_thread_complete;
00244 AST_MUTEX_DEFINE_STATIC(ss_thread_lock);
00245 AST_MUTEX_DEFINE_STATIC(restart_lock);
00246 static int ss_thread_count = 0;
00247 static int num_restart_pending = 0;
00248
00249 static int restart_monitor(void);
00250
00251 static enum ast_bridge_result dahdi_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc, int timeoutms);
00252
00253 static int dahdi_sendtext(struct ast_channel *c, const char *text);
00254
00255
00256 static inline int dahdi_get_event(int fd)
00257 {
00258 int j;
00259 if (ioctl(fd, DAHDI_GETEVENT, &j) == -1)
00260 return -1;
00261 return j;
00262 }
00263
00264
00265 static inline int dahdi_wait_event(int fd)
00266 {
00267 int i, j = 0;
00268 i = DAHDI_IOMUX_SIGEVENT;
00269 if (ioctl(fd, DAHDI_IOMUX, &i) == -1)
00270 return -1;
00271 if (ioctl(fd, DAHDI_GETEVENT, &j) == -1)
00272 return -1;
00273 return j;
00274 }
00275
00276
00277 #define READ_SIZE 160
00278
00279 #define MASK_AVAIL (1 << 0)
00280 #define MASK_INUSE (1 << 1)
00281
00282 #define CALLWAITING_SILENT_SAMPLES ( (300 * 8) / READ_SIZE)
00283 #define CALLWAITING_REPEAT_SAMPLES ( (10000 * 8) / READ_SIZE)
00284 #define CIDCW_EXPIRE_SAMPLES ( (500 * 8) / READ_SIZE)
00285 #define MIN_MS_SINCE_FLASH ( (2000) )
00286 #define DEFAULT_RINGT ( (8000 * 8) / READ_SIZE)
00287
00288 struct dahdi_pvt;
00289
00290 static int ringt_base = DEFAULT_RINGT;
00291
00292 #ifdef HAVE_PRI
00293
00294 #define PVT_TO_CHANNEL(p) (((p)->prioffset) | ((p)->logicalspan << 8) | (p->pri->mastertrunkgroup ? 0x10000 : 0))
00295 #define PRI_CHANNEL(p) ((p) & 0xff)
00296 #define PRI_SPAN(p) (((p) >> 8) & 0xff)
00297 #define PRI_EXPLICIT(p) (((p) >> 16) & 0x01)
00298
00299 struct dahdi_pri {
00300 pthread_t master;
00301 ast_mutex_t lock;
00302 char idleext[AST_MAX_EXTENSION];
00303 char idlecontext[AST_MAX_CONTEXT];
00304 char idledial[AST_MAX_EXTENSION];
00305 int minunused;
00306 int minidle;
00307 int nodetype;
00308 int switchtype;
00309 int nsf;
00310 int dialplan;
00311 int localdialplan;
00312 char internationalprefix[10];
00313 char nationalprefix[10];
00314 char localprefix[20];
00315 char privateprefix[20];
00316 char unknownprefix[20];
00317 int dchannels[NUM_DCHANS];
00318 int trunkgroup;
00319 int mastertrunkgroup;
00320 int prilogicalspan;
00321 int numchans;
00322 int overlapdial;
00323 int facilityenable;
00324 struct pri *dchans[NUM_DCHANS];
00325 int dchanavail[NUM_DCHANS];
00326 struct pri *pri;
00327 int debug;
00328 int fds[NUM_DCHANS];
00329 int offset;
00330 int span;
00331 int resetting;
00332 int resetpos;
00333 #ifdef HAVE_PRI_INBANDDISCONNECT
00334 unsigned int inbanddisconnect:1;
00335 #endif
00336 time_t lastreset;
00337 long resetinterval;
00338 struct dahdi_pvt *pvts[MAX_CHANNELS];
00339 struct dahdi_pvt *crvs;
00340 struct dahdi_pvt *crvend;
00341 };
00342
00343
00344 static struct dahdi_pri pris[NUM_SPANS];
00345
00346 #if 0
00347 #define DEFAULT_PRI_DEBUG (PRI_DEBUG_Q931_DUMP | PRI_DEBUG_Q921_DUMP | PRI_DEBUG_Q921_RAW | PRI_DEBUG_Q921_STATE)
00348 #else
00349 #define DEFAULT_PRI_DEBUG 0
00350 #endif
00351
00352 static inline void pri_rel(struct dahdi_pri *pri)
00353 {
00354 ast_mutex_unlock(&pri->lock);
00355 }
00356
00357 #else
00358
00359 struct dahdi_pri;
00360 #endif
00361
00362 #define SUB_REAL 0
00363 #define SUB_CALLWAIT 1
00364 #define SUB_THREEWAY 2
00365
00366
00367 #define POLARITY_IDLE 0
00368 #define POLARITY_REV 1
00369
00370
00371 static struct dahdi_distRings drings;
00372
00373 struct distRingData {
00374 int ring[3];
00375 };
00376 struct ringContextData {
00377 char contextData[AST_MAX_CONTEXT];
00378 };
00379 struct dahdi_distRings {
00380 struct distRingData ringnum[3];
00381 struct ringContextData ringContext[3];
00382 };
00383
00384 static char *subnames[] = {
00385 "Real",
00386 "Callwait",
00387 "Threeway"
00388 };
00389
00390 struct dahdi_subchannel {
00391 int dfd;
00392 struct ast_channel *owner;
00393 int chan;
00394 short buffer[AST_FRIENDLY_OFFSET/2 + READ_SIZE];
00395 struct ast_frame f;
00396 unsigned int needringing:1;
00397 unsigned int needbusy:1;
00398 unsigned int needcongestion:1;
00399 unsigned int needcallerid:1;
00400 unsigned int needanswer:1;
00401 unsigned int needflash:1;
00402 unsigned int needhold:1;
00403 unsigned int needunhold:1;
00404 unsigned int linear:1;
00405 unsigned int inthreeway:1;
00406 struct dahdi_confinfo curconf;
00407 };
00408
00409 #define CONF_USER_REAL (1 << 0)
00410 #define CONF_USER_THIRDCALL (1 << 1)
00411
00412 #define MAX_SLAVES 4
00413
00414 static struct dahdi_pvt {
00415 ast_mutex_t lock;
00416 struct ast_channel *owner;
00417
00418
00419 struct dahdi_subchannel sub_unused;
00420 struct dahdi_subchannel subs[3];
00421 struct dahdi_confinfo saveconf;
00422
00423 struct dahdi_pvt *slaves[MAX_SLAVES];
00424 struct dahdi_pvt *master;
00425 int inconference;
00426
00427 int buf_no;
00428 int buf_policy;
00429 int sig;
00430 int radio;
00431 int outsigmod;
00432 int oprmode;
00433 struct dahdi_pvt *oprpeer;
00434 float rxgain;
00435 float txgain;
00436 int tonezone;
00437 struct dahdi_pvt *next;
00438 struct dahdi_pvt *prev;
00439
00440
00441 unsigned int adsi:1;
00442 unsigned int answeronpolarityswitch:1;
00443 unsigned int busydetect:1;
00444 unsigned int callreturn:1;
00445 unsigned int callwaiting:1;
00446 unsigned int callwaitingcallerid:1;
00447 unsigned int cancallforward:1;
00448 unsigned int canpark:1;
00449 unsigned int confirmanswer:1;
00450 unsigned int destroy:1;
00451 unsigned int didtdd:1;
00452 unsigned int dialednone:1;
00453 unsigned int dialing:1;
00454 unsigned int digital:1;
00455 unsigned int dnd:1;
00456 unsigned int echobreak:1;
00457 unsigned int echocanbridged:1;
00458 unsigned int echocanon:1;
00459 unsigned int faxhandled:1;
00460 unsigned int firstradio:1;
00461 unsigned int hanguponpolarityswitch:1;
00462 unsigned int hardwaredtmf:1;
00463 unsigned int hidecallerid:1;
00464 unsigned int hidecalleridname:1;
00465 unsigned int ignoredtmf:1;
00466 unsigned int immediate:1;
00467 unsigned int inalarm:1;
00468 unsigned int unknown_alarm:1;
00469 unsigned int mate:1;
00470 unsigned int outgoing:1;
00471 unsigned int overlapdial:1;
00472 unsigned int permcallwaiting:1;
00473 unsigned int permhidecallerid:1;
00474 unsigned int priindication_oob:1;
00475 unsigned int priexclusive:1;
00476 unsigned int pulse:1;
00477 unsigned int pulsedial:1;
00478 unsigned int restartpending:1;
00479 unsigned int restrictcid:1;
00480 unsigned int threewaycalling:1;
00481 unsigned int transfer:1;
00482 unsigned int use_callerid:1;
00483 unsigned int use_callingpres:1;
00484 unsigned int usedistinctiveringdetection:1;
00485 unsigned int dahditrcallerid:1;
00486 unsigned int transfertobusy:1;
00487 #if defined(HAVE_PRI)
00488 unsigned int alerting:1;
00489 unsigned int alreadyhungup:1;
00490 unsigned int isidlecall:1;
00491 unsigned int proceeding:1;
00492 unsigned int progress:1;
00493 unsigned int resetting:1;
00494 unsigned int setup_ack:1;
00495 #endif
00496 unsigned int use_smdi:1;
00497 struct ast_smdi_interface *smdi_iface;
00498
00499 struct dahdi_distRings drings;
00500
00501 char context[AST_MAX_CONTEXT];
00502 char defcontext[AST_MAX_CONTEXT];
00503 char exten[AST_MAX_EXTENSION];
00504 char language[MAX_LANGUAGE];
00505 char mohinterpret[MAX_MUSICCLASS];
00506 char mohsuggest[MAX_MUSICCLASS];
00507 #ifdef PRI_ANI
00508 char cid_ani[AST_MAX_EXTENSION];
00509 #endif
00510 char cid_num[AST_MAX_EXTENSION];
00511 int cid_ton;
00512 char cid_name[AST_MAX_EXTENSION];
00513 char lastcid_num[AST_MAX_EXTENSION];
00514 char lastcid_name[AST_MAX_EXTENSION];
00515 char *origcid_num;
00516 char *origcid_name;
00517 char callwait_num[AST_MAX_EXTENSION];
00518 char callwait_name[AST_MAX_EXTENSION];
00519 char rdnis[AST_MAX_EXTENSION];
00520 char dnid[AST_MAX_EXTENSION];
00521 ast_group_t group;
00522 int law;
00523 int confno;
00524 int confusers;
00525 int propconfno;
00526 ast_group_t callgroup;
00527 ast_group_t pickupgroup;
00528 int channel;
00529 int span;
00530 time_t guardtime;
00531 int cid_signalling;
00532 int cid_start;
00533 int callingpres;
00534 int callwaitingrepeat;
00535 int cidcwexpire;
00536 unsigned char *cidspill;
00537 int cidpos;
00538 int cidlen;
00539 int ringt;
00540 int ringt_base;
00541 int stripmsd;
00542 int callwaitcas;
00543 int callwaitrings;
00544 int echocancel;
00545 int echotraining;
00546 char echorest[20];
00547 int busycount;
00548 int busy_tonelength;
00549 int busy_quietlength;
00550 int callprogress;
00551 struct timeval flashtime;
00552 struct ast_dsp *dsp;
00553 int cref;
00554 struct dahdi_dialoperation dop;
00555 int whichwink;
00556 char finaldial[64];
00557 char accountcode[AST_MAX_ACCOUNT_CODE];
00558 int amaflags;
00559 struct tdd_state *tdd;
00560 char call_forward[AST_MAX_EXTENSION];
00561 char mailbox[AST_MAX_EXTENSION];
00562 char dialdest[256];
00563 int onhooktime;
00564 int msgstate;
00565 int distinctivering;
00566 int cidrings;
00567 int dtmfrelax;
00568 int fake_event;
00569 int polarityonanswerdelay;
00570 struct timeval polaritydelaytv;
00571 int sendcalleridafter;
00572 #ifdef HAVE_PRI
00573 struct dahdi_pri *pri;
00574 struct dahdi_pvt *bearer;
00575 struct dahdi_pvt *realcall;
00576 q931_call *call;
00577 int prioffset;
00578 int logicalspan;
00579 #endif
00580 int polarity;
00581 int dsp_features;
00582 char begindigit;
00583 } *iflist = NULL, *ifend = NULL;
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595 struct dahdi_chan_conf {
00596 struct dahdi_pvt chan;
00597 #ifdef HAVE_PRI
00598 struct dahdi_pri pri;
00599 #endif
00600 struct dahdi_params timing;
00601
00602 char smdi_port[SMDI_MAX_FILENAME_LEN];
00603 };
00604
00605
00606 static struct dahdi_chan_conf dahdi_chan_conf_default(void) {
00607
00608
00609
00610 struct dahdi_chan_conf conf = {
00611 #ifdef HAVE_PRI
00612 .pri = {
00613 .nsf = PRI_NSF_NONE,
00614 .switchtype = PRI_SWITCH_NI2,
00615 .dialplan = PRI_NATIONAL_ISDN + 1,
00616 .localdialplan = PRI_NATIONAL_ISDN + 1,
00617 .nodetype = PRI_CPE,
00618
00619 .minunused = 2,
00620 .idleext = "",
00621 .idledial = "",
00622 .internationalprefix = "",
00623 .nationalprefix = "",
00624 .localprefix = "",
00625 .privateprefix = "",
00626 .unknownprefix = "",
00627
00628 .resetinterval = 3600
00629 },
00630 #endif
00631 .chan = {
00632 .context = "default",
00633 .cid_num = "",
00634 .cid_name = "",
00635 .mohinterpret = "default",
00636 .mohsuggest = "",
00637 .transfertobusy = 1,
00638
00639 .cid_signalling = CID_SIG_BELL,
00640 .cid_start = CID_START_RING,
00641 .dahditrcallerid = 0,
00642 .use_callerid = 1,
00643 .sig = -1,
00644 .outsigmod = -1,
00645
00646 .tonezone = -1,
00647
00648 .echocancel = 1,
00649
00650 .busycount = 3,
00651
00652 .accountcode = "",
00653
00654 .mailbox = "",
00655
00656
00657 .polarityonanswerdelay = 600,
00658
00659 .sendcalleridafter = DEFAULT_CIDRINGS,
00660
00661 .buf_policy = DAHDI_POLICY_IMMEDIATE,
00662 .buf_no = numbufs
00663 },
00664 .timing = {
00665 .prewinktime = -1,
00666 .preflashtime = -1,
00667 .winktime = -1,
00668 .flashtime = -1,
00669 .starttime = -1,
00670 .rxwinktime = -1,
00671 .rxflashtime = -1,
00672 .debouncetime = -1
00673 },
00674 .smdi_port = "/dev/ttyS0",
00675 };
00676
00677 return conf;
00678 }
00679
00680
00681 static struct ast_channel *dahdi_request(const char *type, int format, void *data, int *cause);
00682 static int dahdi_digit_begin(struct ast_channel *ast, char digit);
00683 static int dahdi_digit_end(struct ast_channel *ast, char digit, unsigned int duration);
00684 static int dahdi_sendtext(struct ast_channel *c, const char *text);
00685 static int dahdi_call(struct ast_channel *ast, char *rdest, int timeout);
00686 static int dahdi_hangup(struct ast_channel *ast);
00687 static int dahdi_answer(struct ast_channel *ast);
00688 static struct ast_frame *dahdi_read(struct ast_channel *ast);
00689 static int dahdi_write(struct ast_channel *ast, struct ast_frame *frame);
00690 static struct ast_frame *dahdi_exception(struct ast_channel *ast);
00691 static int dahdi_indicate(struct ast_channel *chan, int condition, const void *data, size_t datalen);
00692 static int dahdi_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
00693 static int dahdi_setoption(struct ast_channel *chan, int option, void *data, int datalen);
00694 static int dahdi_func_read(struct ast_channel *chan, char *function, char *data, char *buf, size_t len);
00695
00696 static const struct ast_channel_tech dahdi_tech = {
00697 .type = "DAHDI",
00698 .description = tdesc,
00699 .capabilities = AST_FORMAT_SLINEAR | AST_FORMAT_ULAW | AST_FORMAT_ALAW,
00700 .requester = dahdi_request,
00701 .send_digit_begin = dahdi_digit_begin,
00702 .send_digit_end = dahdi_digit_end,
00703 .send_text = dahdi_sendtext,
00704 .call = dahdi_call,
00705 .hangup = dahdi_hangup,
00706 .answer = dahdi_answer,
00707 .read = dahdi_read,
00708 .write = dahdi_write,
00709 .bridge = dahdi_bridge,
00710 .exception = dahdi_exception,
00711 .indicate = dahdi_indicate,
00712 .fixup = dahdi_fixup,
00713 .setoption = dahdi_setoption,
00714 .func_channel_read = dahdi_func_read,
00715 };
00716
00717 static const struct ast_channel_tech zap_tech = {
00718 .type = "Zap",
00719 .description = tdesc,
00720 .capabilities = AST_FORMAT_SLINEAR | AST_FORMAT_ULAW | AST_FORMAT_ALAW,
00721 .requester = dahdi_request,
00722 .send_digit_begin = dahdi_digit_begin,
00723 .send_digit_end = dahdi_digit_end,
00724 .send_text = dahdi_sendtext,
00725 .call = dahdi_call,
00726 .hangup = dahdi_hangup,
00727 .answer = dahdi_answer,
00728 .read = dahdi_read,
00729 .write = dahdi_write,
00730 .bridge = dahdi_bridge,
00731 .exception = dahdi_exception,
00732 .indicate = dahdi_indicate,
00733 .fixup = dahdi_fixup,
00734 .setoption = dahdi_setoption,
00735 .func_channel_read = dahdi_func_read,
00736 };
00737
00738 static const struct ast_channel_tech *chan_tech;
00739
00740 #ifdef HAVE_PRI
00741 #define GET_CHANNEL(p) ((p)->bearer ? (p)->bearer->channel : p->channel)
00742 #else
00743 #define GET_CHANNEL(p) ((p)->channel)
00744 #endif
00745
00746 struct dahdi_pvt *round_robin[32];
00747
00748 #ifdef HAVE_PRI
00749 static inline int pri_grab(struct dahdi_pvt *pvt, struct dahdi_pri *pri)
00750 {
00751 int res;
00752
00753 do {
00754 res = ast_mutex_trylock(&pri->lock);
00755 if (res) {
00756 DEADLOCK_AVOIDANCE(&pvt->lock);
00757 }
00758 } while (res);
00759
00760 if (pri->master != AST_PTHREADT_NULL)
00761 pthread_kill(pri->master, SIGURG);
00762 return 0;
00763 }
00764 #endif
00765
00766 #define NUM_CADENCE_MAX 25
00767 static int num_cadence = 4;
00768 static int user_has_defined_cadences = 0;
00769
00770 static struct dahdi_ring_cadence cadences[NUM_CADENCE_MAX] = {
00771 { { 125, 125, 2000, 4000 } },
00772 { { 250, 250, 500, 1000, 250, 250, 500, 4000 } },
00773 { { 125, 125, 125, 125, 125, 4000 } },
00774 { { 1000, 500, 2500, 5000 } },
00775 };
00776
00777