summaryrefslogtreecommitdiff
path: root/ztscan.c
diff options
context:
space:
mode:
authorkpfleming <kpfleming@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2007-12-04 13:55:19 +0000
committerkpfleming <kpfleming@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2007-12-04 13:55:19 +0000
commit62315ace88956c4456598eaf6b6d278d13c86a17 (patch)
treeeea5aa85c604d11f62cc6ae376ff88f3edb7efb9 /ztscan.c
parentfd130696615d48e186afb5def7e4b3a3b796bd7d (diff)
add a new Zaptel scanning tool, primarily for use by the Asterisk GUI, called 'ztscan'. this tool outputs an Asterisk-style
configuration file containing one context for each Zaptel span with all the details that can be learned about that span. to enable this tool, the ZT_SPANSTAT ioctl gained a number of new elements to report information about the spans: - linecompat (available signaling modes for digital spans) - spantype (T1, E1 or J1 for digital spans) - location (PCI/PCI-Express location) - manufacturer - devicetype Along the way I also found that the digital span drivers always set T1-style signaling bits in 'linecompat' even for E1 spans, and that the ZT_SPANCONFIG ioctl did not properly check these bits when configuring E1 spans. The result of this is that it was possible to configure T1-only coding/framing (AMI/B8Zs, D4/ESF) on E1 spans (but not the reverse); this has been corrected and any attempt to use T1-only coding/framing on E1 spans will now result in an error from ztcfg. Also did some minor simplification of the Makefile rules that build the userspace tools. (the basics of ztscan were written by Brandon Kruse then reworked and fleshed out by me) git-svn-id: http://svn.digium.com/svn/zaptel/branches/1.4@3278 5390a7c7-147a-4af0-8ec9-7488f05a26cb
Diffstat (limited to 'ztscan.c')
-rw-r--r--ztscan.c181
1 files changed, 181 insertions, 0 deletions
diff --git a/ztscan.c b/ztscan.c
new file mode 100644
index 0000000..48316b1
--- /dev/null
+++ b/ztscan.c
@@ -0,0 +1,181 @@
+/*
+ * Scan and output information about Zaptel spans and ports.
+ *
+ * Written by Brandon Kruse <bkruse@digium.com>
+ * and Kevin P. Fleming <kpfleming@digium.com>
+ * Copyright (C) 2007 Digium, Inc.
+ *
+ * Based on zttool written by Mark Spencer <markster@digium.com>
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under thet erms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#ifdef STANDALONE_ZAPATA
+#include "zaptel.h"
+#else
+#include <zaptel/zaptel.h>
+#endif
+
+int main(int argc, char *argv[])
+{
+ int ctl;
+ int span = 0;
+ int x, y;
+ int hasgeneral = 0;
+ struct zt_params params;
+ unsigned int basechan = 1;
+ struct zt_spaninfo s;
+ char buf[100];
+ int totalspans = ZT_MAX_SPANS;
+ char alarms[50];
+
+ if ((ctl = open("/dev/zap/ctl", O_RDWR)) < 0) {
+ fprintf(stderr, "Unable to open /dev/zap/ctl: %s\n", strerror(errno));
+ exit(1);
+ }
+
+ for (x = 1; x < totalspans; x++) {
+ memset(&s, 0, sizeof(s));
+ s.spanno = x;
+ if (ioctl(ctl, ZT_SPANSTAT, s))
+ continue;
+
+ alarms[0] = '\0';
+ if (s.alarms) {
+ if (s.alarms & ZT_ALARM_BLUE)
+ strcat(alarms,"BLU/");
+ if (s.alarms & ZT_ALARM_YELLOW)
+ strcat(alarms, "YEL/");
+ if (s.alarms & ZT_ALARM_RED)
+ strcat(alarms, "RED/");
+ if (s.alarms & ZT_ALARM_LOOPBACK)
+ strcat(alarms,"LB/");
+ if (s.alarms & ZT_ALARM_RECOVER)
+ strcat(alarms,"REC/");
+ if (s.alarms & ZT_ALARM_NOTOPEN)
+ strcat(alarms, "NOP/");
+ if (!strlen(alarms))
+ strcat(alarms, "UUU/");
+ if (strlen(alarms)) {
+ /* Strip trailing / */
+ alarms[strlen(alarms)-1]='\0';
+ }
+ } else {
+ if (s.numchans)
+ strcpy(alarms, "OK");
+ else
+ strcpy(alarms, "UNCONFIGURED");
+ }
+
+ if (!hasgeneral) {
+ fprintf(stdout, "[general]\ntotalspans=%d\n", s.totalspans);
+ hasgeneral++;
+ totalspans = s.totalspans;
+ }
+
+ fprintf(stdout, "[%d]\n", x);
+ fprintf(stdout, "active=yes\n");
+ fprintf(stdout, "alarms=%s\n", alarms);
+ fprintf(stdout, "description=%s\n", s.desc);
+ fprintf(stdout, "name=%s\n", s.name);
+ fprintf(stdout, "manufacturer=%s\n", s.manufacturer);
+ fprintf(stdout, "devicetype=%s\n", s.devicetype);
+ fprintf(stdout, "location=%s\n", s.location);
+ fprintf(stdout, "basechan=%d\n", basechan);
+ fprintf(stdout, "totchans=%d\n", s.totalchans);
+ fprintf(stdout, "irq=%d\n", s.irq);
+ y = basechan;
+ memset(&params, 0, sizeof(params));
+ params.channo = y;
+ if (ioctl(ctl, ZT_GET_PARAMS, &params))
+ goto skip;
+ if (params.sigcap & __ZT_SIG_DACS) {
+ /* this is a digital span */
+ fprintf(stdout, "type=digital-%s\n", s.spantype);
+ fprintf(stdout, "syncsrc=%d\n", s.syncsrc);
+ fprintf(stdout, "lbo=%s\n", s.lboname);
+ fprintf(stdout, "coding_opts=");
+ buf[0] = '\0';
+ if (s.linecompat & ZT_CONFIG_B8ZS) strcat(buf, "B8ZS,");
+ if (s.linecompat & ZT_CONFIG_AMI) strcat(buf, "AMI,");
+ if (s.linecompat & ZT_CONFIG_HDB3) strcat(buf, "HDB3,");
+ buf[strlen(buf) - 1] = '\0';
+ fprintf(stdout, "%s\n", buf);
+ fprintf(stdout, "framing_opts=");
+ buf[0] = '\0';
+ if (s.linecompat & ZT_CONFIG_ESF) strcat(buf, "ESF,");
+ if (s.linecompat & ZT_CONFIG_D4) strcat(buf, "D4,");
+ if (s.linecompat & ZT_CONFIG_CCS) strcat(buf, "CCS,");
+ if (s.linecompat & ZT_CONFIG_CRC4) strcat(buf, "CRC4,");
+ buf[strlen(buf) - 1] = '\0';
+ fprintf(stdout, "%s\n", buf);
+ fprintf(stdout, "coding=");
+ if (s.lineconfig & ZT_CONFIG_B8ZS) fprintf(stdout, "B8ZS");
+ else if (s.lineconfig & ZT_CONFIG_AMI) fprintf(stdout, "AMI");
+ else if (s.lineconfig & ZT_CONFIG_HDB3) fprintf(stdout, "HDB3");
+ fprintf(stdout, "\n");
+ fprintf(stdout, "framing=");
+ if (s.lineconfig & ZT_CONFIG_ESF) fprintf(stdout, "ESF");
+ else if (s.lineconfig & ZT_CONFIG_D4) fprintf(stdout, "D4");
+ else if (s.lineconfig & ZT_CONFIG_CCS) fprintf(stdout, "CCS");
+ else if (s.lineconfig & ZT_CONFIG_CRC4) fprintf(stdout, "/CRC4");
+ fprintf(stdout, "\n");
+ } else {
+ /* this is an analog span */
+ fprintf(stdout, "type=analog\n");
+ for (y = basechan; y < (basechan + s.totalchans); y++) {
+ memset(&params, 0, sizeof(params));
+ params.channo = y;
+ if (ioctl(ctl, ZT_GET_PARAMS, &params)) {
+ fprintf(stdout, "port=%d,unknown\n", y);
+ continue;
+ };
+ fprintf(stdout, "port=%d,", y);
+ switch (params.sigcap & (__ZT_SIG_FXO | __ZT_SIG_FXS)) {
+ case __ZT_SIG_FXO:
+ fprintf(stdout, "FXO");
+ break;
+ case __ZT_SIG_FXS:
+ fprintf(stdout, "FXS");
+ break;
+ default:
+ fprintf(stdout, "none");
+ }
+ fprintf(stdout, "\n");
+ }
+ }
+
+ skip:
+ basechan += s.totalchans;
+ span++;
+ }
+
+ if (!hasgeneral)
+ fprintf(stdout, "[general]\ntotalspans=0\nerror=No Spans Found\n");
+
+ exit(0);
+}