diff --git a/Makefile b/Makefile index aa99059..b51e9f5 100644 --- a/Makefile +++ b/Makefile @@ -178,7 +178,7 @@ uninstall: rm -f $(INSTALL_PREFIX)$(INSTALL_BASE)/include/libpri.h pritest: pritest.o - $(CC) -o pritest pritest.o -L. -lpri -lzap $(CFLAGS) + $(CC) -o pritest pritest.o -L. -lpri $(CFLAGS) testprilib.o: testprilib.c $(CC) $(CFLAGS) -D_REENTRANT -D_GNU_SOURCE -o $@ -c $< diff --git a/pritest.c b/pritest.c index 0baa363..ae6626c 100644 --- a/pritest.c +++ b/pritest.c @@ -28,7 +28,7 @@ */ /* - * This program tests libpri call reception using a zaptel interface. + * This program tests libpri call reception using a dahdi interface. * Its state machines are setup for RECEIVING CALLS ONLY, so if you * are trying to both place and receive calls you have to a bit more. */ @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -45,8 +46,8 @@ #include #include #include -#include -#include +#include +#include #include "libpri.h" #define PRI_DEF_NODETYPE PRI_CPE @@ -55,13 +56,20 @@ #define MAX_CHAN 32 #define DCHANNEL_TIMESLOT 16 +#define READ_SIZE 160 static int offset = 0; -static void do_channel(ZAP *z) +static void do_channel(int fd) { /* This is the part that runs on a given channel */ - zap_playf(z, "raw.ulaw", 0); + char buf[READ_SIZE]; + int res; + int i=0; + + while ((res = read(fd, buf, READ_SIZE)) > 0 && (i++ < 1000)) { + write(fd, buf, res); + } } struct pri_chan { @@ -141,10 +149,57 @@ static void hangup_channel(int channo) chans[channo].needhangup = 0; } +static int dahdi_open(char *fn) +{ + int fd; + int isnum; + int chan = 0; + int bs; + int x; + + fprintf(stderr, "dahdi open %s\n", fn); + + isnum = 1; + for (x = 0; x < strlen(fn); x++) { + if (!isdigit(fn[x])) { + isnum = 0; + break; + } + } + if (isnum) { + chan = atoi(fn); + if (chan < 1) { + printf("Invalid channel number '%s'\n", fn); + exit(1); + } + fn = "/dev/dahdi/channel"; + } + fd = open(fn, O_RDWR /* | O_NONBLOCK */); + if (fd < 0) { + printf("Unable to open '%s': %s\n", fn, strerror(errno)); + exit(1); + } + if (chan) { + if (ioctl(fd, DAHDI_SPECIFY, &chan)) { + x = errno; + close(fd); + errno = x; + printf("Unable to specify channel %d: %s\n", chan, strerror(errno)); + exit(1); + } + } + bs = READ_SIZE; + if (ioctl(fd, DAHDI_SET_BLOCKSIZE, &bs) == -1) { + printf("Unable to set blocksize '%d': %s\n", bs, strerror(errno)); + exit(1); + } + return fd; +} + static void launch_channel(int channo) { pid_t pid; - ZAP *z; + int z; char ch[80]; /* Make sure hangup state is reset */ @@ -161,7 +216,7 @@ static void launch_channel(int channo) chans[channo].pid = pid; } else { sprintf(ch, "%d", channo + offset); - z = zap_open(ch, 0); + z = dahdi_open(ch); if (z) { do_channel(z); exit(0); @@ -299,7 +354,7 @@ static int run_pri(int dfd, int swtype, int node) fd_set rfds, efds; int res,x; - pri = pri_new_bri(dfd, 1, node, swtype); + pri = pri_new(dfd, node, swtype); if (!pri) { fprintf(stderr, "Unable to create PRI\n"); return -1; @@ -334,8 +389,8 @@ static int run_pri(int dfd, int swtype, int node) } else if (res > 0) { e = pri_check_event(pri); } else if (errno == ELAST) { - res = ioctl(dfd, ZT_GETEVENT, &x); - printf("Got Zaptel event: %d\n", x); + res = ioctl(dfd, DAHDI_GETEVENT, &x); + printf("Got DAHDI event: %d\n", x); } else if (errno != EINTR) fprintf(stderr, "Error (%d) on select: %s\n", ELAST, strerror(errno)); @@ -343,7 +398,7 @@ static int run_pri(int dfd, int swtype, int node) handle_pri_event(pri, e); } - res = ioctl(dfd, ZT_GETEVENT, &x); + res = ioctl(dfd, DAHDI_GETEVENT, &x); if (!res && x) { fprintf(stderr, "Got event on PRI interface: %d\n", x); @@ -365,7 +420,7 @@ int main(int argc, char *argv[]) int dfd; int swtype = PRI_DEF_SWITCHTYPE; int node = PRI_DEF_NODETYPE; - struct zt_params p; + struct dahdi_params p; if (argc < 2) { fprintf(stderr, "Usage: pritest [swtypetype] [nodetype]\n"); exit(1); @@ -375,11 +430,11 @@ int main(int argc, char *argv[]) fprintf(stderr, "Failed to open dchannel '%s': %s\n", argv[1], strerror(errno)); exit(1); } - if (ioctl(dfd, ZT_GET_PARAMS, &p)) { + if (ioctl(dfd, DAHDI_GET_PARAMS, &p)) { fprintf(stderr, "Unable to get parameters on '%s': %s\n", argv[1], strerror(errno)); exit(1); } - if ((p.sigtype != ZT_SIG_HDLCRAW) && (p.sigtype != ZT_SIG_HDLCFCS)) { + if ((p.sigtype != DAHDI_SIG_HDLCRAW) && (p.sigtype != DAHDI_SIG_HDLCFCS)) { fprintf(stderr, "%s is in %d signalling, not FCS HDLC or RAW HDLC mode\n", argv[1], p.sigtype); exit(1); }