[libpri-commits] rmudgett: branch 1.4 r1833 - in /branches/1.4: Makefile pritest.c

SVN commits to the libpri project libpri-commits at lists.digium.com
Fri Jul 16 17:55:19 CDT 2010


Author: rmudgett
Date: Fri Jul 16 17:55:15 2010
New Revision: 1833

URL: http://svnview.digium.com/svn/libpri?view=rev&rev=1833
Log:
pritest hadn't been ported to DAHDI

pritest hadn't been ported to DAHDI, made the trivial changes to make it
work.  (I haven't found the equivalent to zap_playf, so changed the
behaviour to an echo box)

(closes issue #17274)
Reported by: horape
Patches:
      pritest.diff uploaded by horape (license 1035) (with minor cosmetic changes)

Modified:
    branches/1.4/Makefile
    branches/1.4/pritest.c

Modified: branches/1.4/Makefile
URL: http://svnview.digium.com/svn/libpri/branches/1.4/Makefile?view=diff&rev=1833&r1=1832&r2=1833
==============================================================================
--- branches/1.4/Makefile (original)
+++ branches/1.4/Makefile Fri Jul 16 17:55:15 2010
@@ -178,7 +178,7 @@
 	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 $<

Modified: branches/1.4/pritest.c
URL: http://svnview.digium.com/svn/libpri/branches/1.4/pritest.c?view=diff&rev=1833&r1=1832&r2=1833
==============================================================================
--- branches/1.4/pritest.c (original)
+++ branches/1.4/pritest.c Fri Jul 16 17:55:15 2010
@@ -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 <stdio.h>
 #include <string.h>
 #include <errno.h>
+#include <ctype.h>
 #include <sys/ioctl.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -45,8 +46,8 @@
 #include <sys/wait.h>
 #include <sys/resource.h>
 #include <sys/time.h>
-#include <zaptel/zaptel.h>
-#include <zap.h>
+#include <dahdi/user.h>
+#include <dahdi/tonezone.h>
 #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 @@
 		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 @@
 		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 @@
 	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 @@
 		} 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 @@
 			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 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 <dchannel> [swtypetype] [nodetype]\n");
 		exit(1);
@@ -375,11 +430,11 @@
 		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);
 	}




More information about the libpri-commits mailing list