summaryrefslogtreecommitdiff
path: root/patgen.c
diff options
context:
space:
mode:
authorKevin P. Fleming <kpfleming@digium.com>2008-05-23 14:21:58 +0000
committerKevin P. Fleming <kpfleming@digium.com>2008-05-23 14:21:58 +0000
commit3403af6f5eba79740c98abb2678f9a66ef5a8190 (patch)
tree93415a9598e5363284832757de0596988a421aa6 /patgen.c
parentdb9cffbffeedcde4ee52027160b96a2548262c5d (diff)
initial copy
git-svn-id: http://svn.asterisk.org/svn/dahdi/tools/trunk@4335 a0bf4364-ded3-4de4-8d8a-66a801d63aff
Diffstat (limited to 'patgen.c')
-rw-r--r--patgen.c98
1 files changed, 98 insertions, 0 deletions
diff --git a/patgen.c b/patgen.c
new file mode 100644
index 0000000..34f455a
--- /dev/null
+++ b/patgen.c
@@ -0,0 +1,98 @@
+#include <stdio.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+#include <linux/types.h>
+#include <linux/ppp_defs.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include "bittest.h"
+
+#ifdef STANDALONE_ZAPATA
+#include "kernel/zaptel.h"
+#else
+#include <zaptel/zaptel.h>
+#endif
+
+/* #define BLOCK_SIZE 2048 */
+#define BLOCK_SIZE 2041
+
+void print_packet(unsigned char *buf, int len)
+{
+ int x;
+ printf("{ ");
+ for (x=0;x<len;x++)
+ printf("%02x ",buf[x]);
+ printf("}\n");
+}
+
+int main(int argc, char *argv[])
+{
+ int fd;
+ int res, res1, x;
+ ZT_PARAMS tp;
+ int bs = BLOCK_SIZE;
+ unsigned char c=0;
+ unsigned char outbuf[BLOCK_SIZE];
+ if (argc < 2) {
+ fprintf(stderr, "Usage: %s <tor device>\n", argv[0]);
+ exit(1);
+ }
+ fd = open(argv[1], O_RDWR, 0600);
+ if (fd < 0) {
+ fprintf(stderr, "Unable to open %s: %s\n", argv[1], strerror(errno));
+ exit(1);
+ }
+ if (ioctl(fd, ZT_SET_BLOCKSIZE, &bs)) {
+ fprintf(stderr, "Unable to set block size to %d: %s\n", bs, strerror(errno));
+ exit(1);
+ }
+ if (ioctl(fd, ZT_GET_PARAMS, &tp)) {
+ fprintf(stderr, "Unable to get channel parameters\n");
+ exit(1);
+ }
+ ioctl(fd, ZT_GETEVENT);
+#if 0
+ print_packet(outbuf, res);
+ printf("FCS is %x, PPP_GOODFCS is %x\n",
+ fcs,PPP_GOODFCS);
+#endif
+ for(;;) {
+ res = bs;
+ for (x=0;x<bs;x++) {
+ outbuf[x] = c;
+ c = bit_next(c);
+ }
+ res1 = write(fd, outbuf, res);
+ if (res1 < res) {
+ int e;
+ ZT_SPANINFO zi;
+ res = ioctl(fd,ZT_GETEVENT,&e);
+ if (res == -1)
+ {
+ perror("ZT_GETEVENT");
+ exit(1);
+ }
+ if (e == ZT_EVENT_NOALARM)
+ printf("ALARMS CLEARED\n");
+ if (e == ZT_EVENT_ALARM)
+ {
+ zi.spanno = 0;
+ res = ioctl(fd,ZT_SPANSTAT,&zi);
+ if (res == -1)
+ {
+ perror("ZT_SPANSTAT");
+ exit(1);
+ }
+ printf("Alarm mask %x hex\n",zi.alarms);
+ }
+ continue;
+ }
+#if 0
+ printf("(%d) Wrote %d bytes\n", packets++, res);
+#endif
+ }
+
+}