Adds DAHDI support alongside Zaptel. DAHDI usage favored, but all Zap stuff should continue working. Release announcement to follow.

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@122314 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Jeff Peeler
2008-06-12 19:08:20 +00:00
parent 9f669a3a09
commit f9818af8dd
39 changed files with 2097 additions and 1510 deletions

View File

@@ -37,9 +37,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include <unistd.h>
#include <math.h>
#ifdef HAVE_ZAPTEL
#if defined(HAVE_ZAPTEL) || defined (HAVE_DAHDI)
#include <sys/ioctl.h>
#include <zaptel/zaptel.h>
#include "asterisk/dahdi_compat.h"
#endif
#include "asterisk/pbx.h"
@@ -742,13 +742,19 @@ struct ast_channel *ast_channel_alloc(int needqueue, int state, const char *cid_
for (x = 0; x < AST_MAX_FDS - 2; x++)
tmp->fds[x] = -1;
#ifdef HAVE_DAHDI
#ifdef HAVE_ZAPTEL
tmp->timingfd = open("/dev/zap/timer", O_RDWR);
#else
tmp->timingfd = open("/dev/dahdi/timer", O_RDWR);
#endif
if (tmp->timingfd > -1) {
/* Check if timing interface supports new
ping/pong scheme */
flags = 1;
if (!ioctl(tmp->timingfd, ZT_TIMERPONG, &flags))
if (!ioctl(tmp->timingfd, DAHDI_TIMERPONG, &flags))
needqueue = 0;
}
#else
@@ -759,7 +765,7 @@ struct ast_channel *ast_channel_alloc(int needqueue, int state, const char *cid_
if (pipe(tmp->alertpipe)) {
ast_log(LOG_WARNING, "Channel allocation failed: Can't create alert pipe!\n");
alertpipe_failed:
#ifdef HAVE_ZAPTEL
#ifdef HAVE_DAHDI
if (tmp->timingfd > -1)
close(tmp->timingfd);
#endif
@@ -937,9 +943,9 @@ int ast_queue_frame(struct ast_channel *chan, struct ast_frame *fin)
if (write(chan->alertpipe[1], &blah, sizeof(blah)) != sizeof(blah))
ast_log(LOG_WARNING, "Unable to write to alert pipe on %s, frametype/subclass %d/%d (qlen = %d): %s!\n",
chan->name, f->frametype, f->subclass, qlen, strerror(errno));
#ifdef HAVE_ZAPTEL
#ifdef HAVE_DAHDI
} else if (chan->timingfd > -1) {
ioctl(chan->timingfd, ZT_TIMERPING, &blah);
ioctl(chan->timingfd, DAHDI_TIMERPING, &blah);
#endif
} else if (ast_test_flag(chan, AST_FLAG_BLOCKING)) {
pthread_kill(chan->blocker, SIGURG);
@@ -1805,7 +1811,7 @@ int ast_waitfordigit(struct ast_channel *c, int ms)
int ast_settimeout(struct ast_channel *c, int samples, int (*func)(const void *data), void *data)
{
int res = -1;
#ifdef HAVE_ZAPTEL
#ifdef HAVE_DAHDI
if (c->timingfd > -1) {
if (!func) {
samples = 0;
@@ -1813,7 +1819,7 @@ int ast_settimeout(struct ast_channel *c, int samples, int (*func)(const void *d
}
if (option_debug)
ast_log(LOG_DEBUG, "Scheduling timer at %d sample intervals\n", samples);
res = ioctl(c->timingfd, ZT_TIMERCONFIG, &samples);
res = ioctl(c->timingfd, DAHDI_TIMERCONFIG, &samples);
c->timingfunc = func;
c->timingdata = data;
}
@@ -2020,26 +2026,26 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio)
read(chan->alertpipe[0], &blah, sizeof(blah));
}
#ifdef HAVE_ZAPTEL
#ifdef HAVE_DAHDI
if (chan->timingfd > -1 && chan->fdno == AST_TIMING_FD && ast_test_flag(chan, AST_FLAG_EXCEPTION)) {
int res;
ast_clear_flag(chan, AST_FLAG_EXCEPTION);
blah = -1;
/* IF we can't get event, assume it's an expired as-per the old interface */
res = ioctl(chan->timingfd, ZT_GETEVENT, &blah);
res = ioctl(chan->timingfd, DAHDI_GETEVENT, &blah);
if (res)
blah = ZT_EVENT_TIMER_EXPIRED;
blah = DAHDI_EVENT_TIMER_EXPIRED;
if (blah == ZT_EVENT_TIMER_PING) {
if (blah == DAHDI_EVENT_TIMER_PING) {
if (AST_LIST_EMPTY(&chan->readq) || !AST_LIST_NEXT(AST_LIST_FIRST(&chan->readq), frame_list)) {
/* Acknowledge PONG unless we need it again */
if (ioctl(chan->timingfd, ZT_TIMERPONG, &blah)) {
if (ioctl(chan->timingfd, DAHDI_TIMERPONG, &blah)) {
ast_log(LOG_WARNING, "Failed to pong timer on '%s': %s\n", chan->name, strerror(errno));
}
}
} else if (blah == ZT_EVENT_TIMER_EXPIRED) {
ioctl(chan->timingfd, ZT_TIMERACK, &blah);
} else if (blah == DAHDI_EVENT_TIMER_EXPIRED) {
ioctl(chan->timingfd, DAHDI_TIMERACK, &blah);
if (chan->timingfunc) {
/* save a copy of func/data before unlocking the channel */
int (*func)(const void *) = chan->timingfunc;
@@ -2048,7 +2054,7 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio)
func(data);
} else {
blah = 0;
ioctl(chan->timingfd, ZT_TIMERCONFIG, &blah);
ioctl(chan->timingfd, DAHDI_TIMERCONFIG, &blah);
chan->timingdata = NULL;
ast_channel_unlock(chan);
}
@@ -2405,7 +2411,7 @@ int ast_indicate_data(struct ast_channel *chan, int condition, const void *data,
if (condition < 0)
ast_playtones_stop(chan);
else {
const struct tone_zone_sound *ts = NULL;
const struct ind_tone_zone_sound *ts = NULL;
switch (condition) {
case AST_CONTROL_RINGING:
ts = ast_get_indication_tone(chan->zone, "ring");
@@ -3024,6 +3030,11 @@ struct ast_channel *ast_request(const char *type, int format, void *data, int *c
return NULL;
}
if (!strcasecmp(type, "Zap")) {
type = "DAHDI";
ast_log(LOG_NOTICE, "Zap interface translated to DAHDI.\n");
}
AST_LIST_TRAVERSE(&backends, chan, list) {
if (strcasecmp(type, chan->tech->type))
continue;