2
* Scan and output information about Zaptel spans and ports.
4
* Written by Brandon Kruse <bkruse@digium.com>
5
* and Kevin P. Fleming <kpfleming@digium.com>
6
* Copyright (C) 2007 Digium, Inc.
8
* Based on zttool written by Mark Spencer <markster@digium.com>
10
* All rights reserved.
12
* This program is free software; you can redistribute it and/or modify
13
* it under thet erms of the GNU General Public License as published by
14
* the Free Software Foundation; either version 2 of the License, or
15
* (at your option) any later version.
17
* This program is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
* GNU General Public License for more details.
22
* You should have received a copy of the GNU General Public License
23
* along with this program; if not, write to the Free Software
24
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33
#include <sys/ioctl.h>
37
#ifdef STANDALONE_ZAPATA
38
#include "kernel/zaptel.h"
40
#include <zaptel/zaptel.h>
43
int main(int argc, char *argv[])
47
struct zt_params params;
48
unsigned int basechan = 1;
53
if ((ctl = open("/dev/zap/ctl", O_RDWR)) < 0) {
54
fprintf(stderr, "Unable to open /dev/zap/ctl: %s\n", strerror(errno));
58
for (x = 1; x < ZT_MAX_SPANS; x++) {
59
memset(&s, 0, sizeof(s));
61
if (ioctl(ctl, ZT_SPANSTAT, &s))
66
if (s.alarms & ZT_ALARM_BLUE)
67
strcat(alarms,"BLU/");
68
if (s.alarms & ZT_ALARM_YELLOW)
69
strcat(alarms, "YEL/");
70
if (s.alarms & ZT_ALARM_RED)
71
strcat(alarms, "RED/");
72
if (s.alarms & ZT_ALARM_LOOPBACK)
74
if (s.alarms & ZT_ALARM_RECOVER)
75
strcat(alarms,"REC/");
76
if (s.alarms & ZT_ALARM_NOTOPEN)
77
strcat(alarms, "NOP/");
79
strcat(alarms, "UUU/");
81
/* Strip trailing / */
82
alarms[strlen(alarms)-1]='\0';
88
strcpy(alarms, "UNCONFIGURED");
91
fprintf(stdout, "[%d]\n", x);
92
fprintf(stdout, "active=yes\n");
93
fprintf(stdout, "alarms=%s\n", alarms);
94
fprintf(stdout, "description=%s\n", s.desc);
95
fprintf(stdout, "name=%s\n", s.name);
96
fprintf(stdout, "manufacturer=%s\n", s.manufacturer);
97
fprintf(stdout, "devicetype=%s\n", s.devicetype);
98
fprintf(stdout, "location=%s\n", s.location);
99
fprintf(stdout, "basechan=%d\n", basechan);
100
fprintf(stdout, "totchans=%d\n", s.totalchans);
101
fprintf(stdout, "irq=%d\n", s.irq);
103
memset(¶ms, 0, sizeof(params));
105
if (ioctl(ctl, ZT_GET_PARAMS, ¶ms)) {
106
basechan += s.totalchans;
110
if (params.sigcap & (__ZT_SIG_DACS | ZT_SIG_CAS)) {
111
/* this is a digital span */
112
fprintf(stdout, "type=digital-%s\n", s.spantype);
113
fprintf(stdout, "syncsrc=%d\n", s.syncsrc);
114
fprintf(stdout, "lbo=%s\n", s.lboname);
115
fprintf(stdout, "coding_opts=");
117
if (s.linecompat & ZT_CONFIG_B8ZS) strcat(buf, "B8ZS,");
118
if (s.linecompat & ZT_CONFIG_AMI) strcat(buf, "AMI,");
119
if (s.linecompat & ZT_CONFIG_HDB3) strcat(buf, "HDB3,");
120
buf[strlen(buf) - 1] = '\0';
121
fprintf(stdout, "%s\n", buf);
122
fprintf(stdout, "framing_opts=");
124
if (s.linecompat & ZT_CONFIG_ESF) strcat(buf, "ESF,");
125
if (s.linecompat & ZT_CONFIG_D4) strcat(buf, "D4,");
126
if (s.linecompat & ZT_CONFIG_CCS) strcat(buf, "CCS,");
127
if (s.linecompat & ZT_CONFIG_CRC4) strcat(buf, "CRC4,");
128
buf[strlen(buf) - 1] = '\0';
129
fprintf(stdout, "%s\n", buf);
130
fprintf(stdout, "coding=");
131
if (s.lineconfig & ZT_CONFIG_B8ZS) fprintf(stdout, "B8ZS");
132
else if (s.lineconfig & ZT_CONFIG_AMI) fprintf(stdout, "AMI");
133
else if (s.lineconfig & ZT_CONFIG_HDB3) fprintf(stdout, "HDB3");
134
fprintf(stdout, "\n");
135
fprintf(stdout, "framing=");
136
if (s.lineconfig & ZT_CONFIG_ESF) fprintf(stdout, "ESF");
137
else if (s.lineconfig & ZT_CONFIG_D4) fprintf(stdout, "D4");
138
else if (s.lineconfig & ZT_CONFIG_CCS) fprintf(stdout, "CCS");
139
else if (s.lineconfig & ZT_CONFIG_CRC4) fprintf(stdout, "/CRC4");
140
fprintf(stdout, "\n");
142
/* this is an analog span */
143
fprintf(stdout, "type=analog\n");
144
for (y = basechan; y < (basechan + s.totalchans); y++) {
145
memset(¶ms, 0, sizeof(params));
147
if (ioctl(ctl, ZT_GET_PARAMS, ¶ms)) {
148
fprintf(stdout, "port=%d,unknown\n", y);
151
fprintf(stdout, "port=%d,", y);
152
switch (params.sigcap & (__ZT_SIG_FXO | __ZT_SIG_FXS)) {
154
fprintf(stdout, "FXS");
157
fprintf(stdout, "FXO");
160
fprintf(stdout, "none");
162
if (params.sigcap & ZT_SIG_BROKEN)
163
fprintf(stdout, " FAILED");
164
fprintf(stdout, "\n");
168
basechan += s.totalchans;