~ubuntu-branches/ubuntu/quantal/zaptel/quantal

« back to all changes in this revision

Viewing changes to ztscan.c

  • Committer: Bazaar Package Importer
  • Author(s): Tzafrir Cohen
  • Date: 2008-08-28 22:58:23 UTC
  • mfrom: (11.1.11 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080828225823-r8bdunirm8hmc76m
Tags: 1:1.4.11~dfsg-2
* Patch xpp_fxs_power: Fixed an issue with hook detection of the Astribank
  FXS module.
* Don't fail init.d script if fxotune fails. This may happen if running it
  when Asterisk is already running.
* Bump standards version to 3.8.0.0 .
* Ignore false lintian warning ("m-a a-i" has "a a").
* Patch xpp_fxo_cid_always: do always pass PCM if that's what the user
  asked.
* Patch vzaphfc_proc_root_dir: fix vzaphfc on 2.6.26.
* Patch wcte12xp_flags: Proper time for irq save flags.
* Patch headers_2627: Fix location of semaphore.h for 2.6.27 .
* Patch xpp_fxs_dtmf_leak: Don't play DTMFs to the wrong channel.
* Patch wctdm_fix_alarm: Fix sending channel alarms.
* Patch device_class_2626: Fix building 2.6.26 (Closes: #493397).
* Using dh_lintian for lintian overrides, hence requiring debhelper 6.0.7.
* Lintian: we know we have direct changes. Too bad we're half-upstream :-(
* Fix doc-base section names. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Scan and output information about Zaptel spans and ports.
 
3
 * 
 
4
 * Written by Brandon Kruse <bkruse@digium.com>
 
5
 * and Kevin P. Fleming <kpfleming@digium.com>
 
6
 * Copyright (C) 2007 Digium, Inc.
 
7
 *
 
8
 * Based on zttool written by Mark Spencer <markster@digium.com>
 
9
 *
 
10
 * All rights reserved.
 
11
 *
 
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.
 
16
 * 
 
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.
 
21
 * 
 
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. 
 
25
 *
 
26
 */
 
27
 
 
28
#include <stdio.h> 
 
29
#include <string.h>
 
30
#include <stdarg.h>
 
31
#include <stdlib.h>
 
32
#include <unistd.h>
 
33
#include <sys/ioctl.h>
 
34
#include <fcntl.h>
 
35
#include <errno.h>
 
36
 
 
37
#ifdef STANDALONE_ZAPATA
 
38
#include "kernel/zaptel.h"
 
39
#else
 
40
#include <zaptel/zaptel.h>
 
41
#endif
 
42
 
 
43
int main(int argc, char *argv[])
 
44
{
 
45
        int ctl;
 
46
        int x, y;
 
47
        struct zt_params params;
 
48
        unsigned int basechan = 1;
 
49
        struct zt_spaninfo s;
 
50
        char buf[100];
 
51
        char alarms[50];
 
52
 
 
53
        if ((ctl = open("/dev/zap/ctl", O_RDWR)) < 0) {
 
54
                fprintf(stderr, "Unable to open /dev/zap/ctl: %s\n", strerror(errno));
 
55
                exit(1);
 
56
        }
 
57
        
 
58
        for (x = 1; x < ZT_MAX_SPANS; x++) {
 
59
                memset(&s, 0, sizeof(s));
 
60
                s.spanno = x;
 
61
                if (ioctl(ctl, ZT_SPANSTAT, &s))
 
62
                        continue;
 
63
 
 
64
                alarms[0] = '\0';
 
65
                if (s.alarms) {
 
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)
 
73
                                strcat(alarms,"LB/");
 
74
                        if (s.alarms & ZT_ALARM_RECOVER)
 
75
                                strcat(alarms,"REC/");
 
76
                        if (s.alarms & ZT_ALARM_NOTOPEN)
 
77
                                strcat(alarms, "NOP/");
 
78
                        if (!strlen(alarms))
 
79
                                strcat(alarms, "UUU/");
 
80
                        if (strlen(alarms)) {
 
81
                                /* Strip trailing / */
 
82
                                alarms[strlen(alarms)-1]='\0';
 
83
                        }
 
84
                } else {
 
85
                        if (s.numchans)
 
86
                                strcpy(alarms, "OK");
 
87
                        else
 
88
                                strcpy(alarms, "UNCONFIGURED");
 
89
                }
 
90
 
 
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);
 
102
                y = basechan;
 
103
                memset(&params, 0, sizeof(params));
 
104
                params.channo = y;
 
105
                if (ioctl(ctl, ZT_GET_PARAMS, &params)) {
 
106
                        basechan += s.totalchans;
 
107
                        continue;
 
108
                }
 
109
 
 
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=");
 
116
                        buf[0] = '\0';
 
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=");
 
123
                        buf[0] = '\0';
 
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");
 
141
                } else {
 
142
                        /* this is an analog span */
 
143
                        fprintf(stdout, "type=analog\n");
 
144
                        for (y = basechan; y < (basechan + s.totalchans); y++) {
 
145
                                memset(&params, 0, sizeof(params));
 
146
                                params.channo = y;
 
147
                                if (ioctl(ctl, ZT_GET_PARAMS, &params)) {
 
148
                                        fprintf(stdout, "port=%d,unknown\n", y);
 
149
                                        continue;
 
150
                                };
 
151
                                fprintf(stdout, "port=%d,", y);
 
152
                                switch (params.sigcap & (__ZT_SIG_FXO | __ZT_SIG_FXS)) {
 
153
                                case __ZT_SIG_FXO:
 
154
                                        fprintf(stdout, "FXS");
 
155
                                        break;
 
156
                                case __ZT_SIG_FXS:
 
157
                                        fprintf(stdout, "FXO");
 
158
                                        break;
 
159
                                default:
 
160
                                        fprintf(stdout, "none");
 
161
                                }
 
162
                                if (params.sigcap & ZT_SIG_BROKEN)
 
163
                                        fprintf(stdout, " FAILED");
 
164
                                fprintf(stdout, "\n");
 
165
                        }
 
166
                }
 
167
          
 
168
                basechan += s.totalchans;
 
169
        }
 
170
 
 
171
        exit(0);
 
172
}