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

« back to all changes in this revision

Viewing changes to ztcfg.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
1
/*
2
2
 * Configuration program for Zapata Telephony Interface
3
3
 *
4
 
 * Written by Mark Spencer <markster@linux-support.net>
 
4
 * Written by Mark Spencer <markster@digium.com>
5
5
 * Based on previous works, designs, and architectures conceived and
6
6
 * written by Jim Dixon <jim@lambdatel.com>.
7
7
 *
24
24
 * along with this program; if not, write to the Free Software
25
25
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
26
26
 *
27
 
 * Primary Author: Mark Spencer <markster@linux-support.net>
 
27
 * Primary Author: Mark Spencer <markster@digium.com>
28
28
 * Radio Support by Jim Dixon <jim@lambdatel.com>
29
29
 */
30
30
 
37
37
#include <sys/ioctl.h>
38
38
#include <fcntl.h>
39
39
#include <errno.h>
 
40
#ifdef STANDALONE_ZAPATA
 
41
#include "kernel/zaptel.h"
 
42
#include "tonezone.h"
 
43
#else
 
44
#include <zaptel/zaptel.h>
 
45
#include <zaptel/tonezone.h>
 
46
#endif
40
47
#include "ztcfg.h"
41
 
#include "tonezone.h"
42
 
#include "zaptel.h"
43
48
 
44
49
#define NUM_SPANS ZT_MAX_SPANS
45
50
 
56
61
 
57
62
int rxtones[NUM_TONES + 1],rxtags[NUM_TONES + 1],txtones[NUM_TONES + 1];
58
63
int bursttime = 0, debouncetime = 0, invertcor = 0, exttone = 0, corthresh = 0;
 
64
int txgain = 0, rxgain = 0, deemp = 0, preemp = 0;
59
65
 
60
66
int corthreshes[] = {3125,6250,9375,12500,15625,18750,21875,25000,0} ;
61
67
 
152
158
                return "Network HDLC";
153
159
        case ZT_SIG_HDLCFCS:
154
160
                return "HDLC with FCS check";
 
161
        case ZT_SIG_HARDHDLC:
 
162
                return "Hardware assisted D-channel";
 
163
        case ZT_SIG_MTP2:
 
164
                return "MTP2";
155
165
        default:
156
166
                return "Unknown";
157
167
        }
177
187
        debouncetime = 0;
178
188
        invertcor = 0;
179
189
        exttone = 0;
 
190
        txgain = 0;
 
191
        rxgain = 0;
 
192
        deemp = 0;
 
193
        preemp = 0;
180
194
}
181
195
 
182
196
static int error(char *fmt, ...)
256
270
        }
257
271
 
258
272
 
259
 
        strncpy(zds[numdynamic].driver, realargs[0], sizeof(zds[numdynamic].driver));
260
 
        strncpy(zds[numdynamic].addr, realargs[1], sizeof(zds[numdynamic].addr));
 
273
        zap_copy_string(zds[numdynamic].driver, realargs[0], sizeof(zds[numdynamic].driver));
 
274
        zap_copy_string(zds[numdynamic].addr, realargs[1], sizeof(zds[numdynamic].addr));
261
275
        zds[numdynamic].numchans = chans;
262
276
        zds[numdynamic].timing = timing;
263
277
        
365
379
        for (x=0;x<res;x++) {
366
380
                if (strchr(args[x], '-')) {
367
381
                        /* It's a range */
368
 
                        strncpy(argcopy, args[x], sizeof(argcopy));
 
382
                        zap_copy_string(argcopy, args[x], sizeof(argcopy));
369
383
                        res2 = parseargs(argcopy, range, 2, '-');
370
384
                        if (res2 != 2) {
371
385
                                error("Syntax error in range '%s'.  Should be <val1>-<val2>.\n", args[x]);
552
566
                                }
553
567
                        } else if (!strcasecmp(keyword, "nethdlc")) {
554
568
                                sig[x] = sigtype_to_str(ZT_SIG_HDLCNET);
 
569
                                memset(cc[x].netdev_name, 0, sizeof(cc[x].netdev_name));
555
570
                                if (master) {
556
571
                                        cc[x].sigtype = ZT_SIG_SLAVE;
557
572
                                        cc[x].master = master;
558
573
                                } else {
559
574
                                        cc[x].sigtype = ZT_SIG_HDLCNET;
 
575
                                        if (idle) {
 
576
                                            zap_copy_string(cc[x].netdev_name, idle, sizeof(cc[x].netdev_name));
 
577
                                        }
560
578
                                        master = x;
561
579
                                }
562
580
                        } else if (!strcasecmp(keyword, "fcshdlc")) {
571
589
                        } else if (!strcasecmp(keyword, "dchan")) {
572
590
                                sig[x] = "D-channel";
573
591
                                cc[x].sigtype = ZT_SIG_HDLCFCS;
 
592
                        } else if (!strcasecmp(keyword, "hardhdlc")) {
 
593
                                sig[x] = "Hardware assisted D-channel";
 
594
                                cc[x].sigtype = ZT_SIG_HARDHDLC;
 
595
                        } else if (!strcasecmp(keyword, "mtp2")) {
 
596
                                sig[x] = "MTP2";
 
597
                                cc[x].sigtype = ZT_SIG_MTP2;
574
598
                        } else {
575
599
                                fprintf(stderr, "Huh? (%s)\n", keyword);
576
600
                        }
612
636
                error("Too many tone zones specified\n");
613
637
                return 0;
614
638
        }
615
 
        strncpy(zonestoload[numzones++], args, sizeof(zonestoload[0]));
 
639
        zap_copy_string(zonestoload[numzones++], args, sizeof(zonestoload[0]));
616
640
        return 0;
617
641
}
618
642
 
776
800
        return 0;
777
801
}
778
802
 
 
803
int tx_gain(char *keyword, char *args)
 
804
{
 
805
        static char *realargs[10];
 
806
        int argc;
 
807
        int res;
 
808
        int val;
 
809
        argc = res = parseargs(args, realargs, 1, ',');
 
810
        if (res != 1) {
 
811
                error("Incorrect number of arguments to 'txgain' (should be <value>)\n");
 
812
        }
 
813
        res = sscanf(realargs[0], "%d", &val);
 
814
        if (res != 1) {
 
815
                error("Invalid value '%s', should be a number > 0.\n", realargs[0]);
 
816
        }
 
817
 
 
818
        txgain = val;
 
819
        return 0;
 
820
}
 
821
 
 
822
int rx_gain(char *keyword, char *args)
 
823
{
 
824
        static char *realargs[10];
 
825
        int argc;
 
826
        int res;
 
827
        int val;
 
828
        argc = res = parseargs(args, realargs, 1, ',');
 
829
        if (res != 1) {
 
830
                error("Incorrect number of arguments to 'rxgain' (should be <value>)\n");
 
831
        }
 
832
        res = sscanf(realargs[0], "%d", &val);
 
833
        if (res != 1) {
 
834
                error("Invalid value '%s', should be a number > 0.\n", realargs[0]);
 
835
        }
 
836
 
 
837
        rxgain = val;
 
838
        return 0;
 
839
}
 
840
 
 
841
int de_emp(char *keyword, char *args)
 
842
{
 
843
        static char *realargs[10];
 
844
        int argc;
 
845
        int res;
 
846
        int val;
 
847
        argc = res = parseargs(args, realargs, 1, ',');
 
848
        if (res != 1) {
 
849
                error("Incorrect number of arguments to 'de-emp' (should be <value>)\n");
 
850
        }
 
851
        res = sscanf(realargs[0], "%d", &val);
 
852
        if ((res == 1) && (val < 1))
 
853
                res = -1;
 
854
        if (res != 1) {
 
855
                error("Invalid value '%s', should be a number > 0.\n", realargs[0]);
 
856
        }
 
857
 
 
858
        deemp = val;
 
859
        return 0;
 
860
}
 
861
 
 
862
int pre_emp(char *keyword, char *args)
 
863
{
 
864
        static char *realargs[10];
 
865
        int argc;
 
866
        int res;
 
867
        int val;
 
868
        argc = res = parseargs(args, realargs, 1, ',');
 
869
        if (res != 1) {
 
870
                error("Incorrect number of arguments to 'pre_emp' (should be <value>)\n");
 
871
        }
 
872
        res = sscanf(realargs[0], "%d", &val);
 
873
        if ((res == 1) && (val < 1))
 
874
                res = -1;
 
875
        if (res != 1) {
 
876
                error("Invalid value '%s', should be a number > 0.\n", realargs[0]);
 
877
        }
 
878
 
 
879
        preemp = val;
 
880
        return 0;
 
881
}
 
882
 
779
883
int invert_cor(char *keyword, char *args)
780
884
{
781
885
        static char *realargs[10];
868
972
        for (x=0;x<res;x++) {
869
973
                if (strchr(args[x], '-')) {
870
974
                        /* It's a range */
871
 
                        strncpy(argcopy, args[x], sizeof(argcopy));
 
975
                        zap_copy_string(argcopy, args[x], sizeof(argcopy));
872
976
                        res2 = parseargs(argcopy, range, 2, '-');
873
977
                        if (res2 != 2) {
874
978
                                error("Syntax error in range '%s'.  Should be <val1>-<val2>.\n", args[x]);
919
1023
        int x,i,n;
920
1024
        struct zt_radio_param p;
921
1025
 
 
1026
        toneindex = 1;
922
1027
        bzero(chans, sizeof(chans));
923
1028
        res = rad_apply_channels(chans, args);
924
1029
        if (res <= 0)
927
1032
                if (chans[x]) {
928
1033
                        p.radpar = ZT_RADPAR_NUMTONES;
929
1034
                        if (ind_ioctl(x,fd,ZT_RADIO_GETPARAM,&p) == -1)
930
 
                                error("Cannot get number of tones for channel %d\n",x);
931
 
                        n = p.data;
932
 
                        p.radpar = ZT_RADPAR_INITTONE;
933
 
                        if (ind_ioctl(x,fd,ZT_RADIO_SETPARAM,&p) == -1)
934
 
                                error("Cannot init tones for channel %d\n",x);
935
 
                        if (!rxtones[0]) for(i = 1; i <= n; i++)
 
1035
                                n = 0; else n = p.data;
 
1036
                        if (n)
936
1037
                        {
937
 
                                if (rxtones[i])
938
 
                                {
939
 
                                        p.radpar = ZT_RADPAR_RXTONE;
940
 
                                        p.index = i;
941
 
                                        p.data = rxtones[i];
942
 
                                        if (ind_ioctl(x,fd,ZT_RADIO_SETPARAM,&p) == -1)
943
 
                                                error("Cannot set rxtone on channel %d\n",x);
944
 
                                }
945
 
                                if (rxtags[i])
946
 
                                {
947
 
                                        p.radpar = ZT_RADPAR_RXTONECLASS;
948
 
                                        p.index = i;
949
 
                                        p.data = rxtags[i];
950
 
                                        if (ind_ioctl(x,fd,ZT_RADIO_SETPARAM,&p) == -1)
951
 
                                                error("Cannot set rxtag on channel %d\n",x);
952
 
                                }
953
 
                                if (txtones[i])
 
1038
                                p.radpar = ZT_RADPAR_INITTONE;
 
1039
                                if (ind_ioctl(x,fd,ZT_RADIO_SETPARAM,&p) == -1)
 
1040
                                        error("Cannot init tones for channel %d\n",x);
 
1041
                                if (!rxtones[0]) for(i = 1; i <= n; i++)
 
1042
                                {
 
1043
                                        if (rxtones[i])
 
1044
                                        {
 
1045
                                                p.radpar = ZT_RADPAR_RXTONE;
 
1046
                                                p.index = i;
 
1047
                                                p.data = rxtones[i];
 
1048
                                                if (ind_ioctl(x,fd,ZT_RADIO_SETPARAM,&p) == -1)
 
1049
                                                        error("Cannot set rxtone on channel %d\n",x);
 
1050
                                        }
 
1051
                                        if (rxtags[i])
 
1052
                                        {
 
1053
                                                p.radpar = ZT_RADPAR_RXTONECLASS;
 
1054
                                                p.index = i;
 
1055
                                                p.data = rxtags[i];
 
1056
                                                if (ind_ioctl(x,fd,ZT_RADIO_SETPARAM,&p) == -1)
 
1057
                                                        error("Cannot set rxtag on channel %d\n",x);
 
1058
                                        }
 
1059
                                        if (txtones[i])
 
1060
                                        {
 
1061
                                                p.radpar = ZT_RADPAR_TXTONE;
 
1062
                                                p.index = i;
 
1063
                                                p.data = txtones[i];
 
1064
                                                if (ind_ioctl(x,fd,ZT_RADIO_SETPARAM,&p) == -1)
 
1065
                                                        error("Cannot set txtone on channel %d\n",x);
 
1066
                                        }
 
1067
                                } else { /* if we may have DCS receive */
 
1068
                                        if (rxtones[0])
 
1069
                                        {
 
1070
                                                p.radpar = ZT_RADPAR_RXTONE;
 
1071
                                                p.index = 0;
 
1072
                                                p.data = rxtones[0];
 
1073
                                                if (ind_ioctl(x,fd,ZT_RADIO_SETPARAM,&p) == -1)
 
1074
                                                        error("Cannot set DCS rxtone on channel %d\n",x);
 
1075
                                        }
 
1076
                                }
 
1077
                                if (txtones[0])
954
1078
                                {
955
1079
                                        p.radpar = ZT_RADPAR_TXTONE;
956
 
                                        p.index = i;
957
 
                                        p.data = txtones[i];
958
 
                                        if (ind_ioctl(x,fd,ZT_RADIO_SETPARAM,&p) == -1)
959
 
                                                error("Cannot set txtone on channel %d\n",x);
960
 
                                }
961
 
                        } else { /* if we may have DCS receive */
962
 
                                if (rxtones[0])
963
 
                                {
964
 
                                        p.radpar = ZT_RADPAR_RXTONE;
965
1080
                                        p.index = 0;
966
 
                                        p.data = rxtones[0];
 
1081
                                        p.data = txtones[0];
967
1082
                                        if (ind_ioctl(x,fd,ZT_RADIO_SETPARAM,&p) == -1)
968
 
                                                error("Cannot set DCS rxtone on channel %d\n",x);
 
1083
                                                error("Cannot set default txtone on channel %d\n",x);
969
1084
                                }
970
1085
                        }
971
 
                        if (txtones[0])
972
 
                        {
973
 
                                p.radpar = ZT_RADPAR_TXTONE;
974
 
                                p.index = 0;
975
 
                                p.data = txtones[0];
976
 
                                if (ind_ioctl(x,fd,ZT_RADIO_SETPARAM,&p) == -1)
977
 
                                        error("Cannot set default txtone on channel %d\n",x);
978
 
                        }
979
1086
                        if (debouncetime)
980
1087
                        {
981
1088
                                p.radpar = ZT_RADPAR_DEBOUNCETIME;
990
1097
                                if (ind_ioctl(x,fd,ZT_RADIO_SETPARAM,&p) == -1)
991
1098
                                        error("Cannot set bursttime on channel %d\n",x);
992
1099
                        }
993
 
                        if (invertcor)
994
 
                        {
995
 
                                p.radpar = ZT_RADPAR_INVERTCOR;
996
 
                                p.data = invertcor;
997
 
                                if (ind_ioctl(x,fd,ZT_RADIO_SETPARAM,&p) == -1)
998
 
                                        error("Cannot set invertcor on channel %d\n",x);
999
 
                        }
1000
 
                        if (exttone)
1001
 
                        {
1002
 
                                p.radpar = ZT_RADPAR_EXTRXTONE;
1003
 
                                p.data = exttone;
1004
 
                                if (ind_ioctl(x,fd,ZT_RADIO_SETPARAM,&p) == -1)
1005
 
                                        error("Cannot set exttone on channel %d\n",x);
1006
 
                        }
 
1100
                        p.radpar = ZT_RADPAR_DEEMP;
 
1101
                        p.data = deemp;
 
1102
                        ind_ioctl(x,fd,ZT_RADIO_SETPARAM,&p);
 
1103
                        p.radpar = ZT_RADPAR_PREEMP;
 
1104
                        p.data = preemp;
 
1105
                        ind_ioctl(x,fd,ZT_RADIO_SETPARAM,&p);
 
1106
                        p.radpar = ZT_RADPAR_TXGAIN;
 
1107
                        p.data = txgain;
 
1108
                        ind_ioctl(x,fd,ZT_RADIO_SETPARAM,&p);
 
1109
                        p.radpar = ZT_RADPAR_RXGAIN;
 
1110
                        p.data = rxgain;
 
1111
                        ind_ioctl(x,fd,ZT_RADIO_SETPARAM,&p);
 
1112
                        p.radpar = ZT_RADPAR_INVERTCOR;
 
1113
                        p.data = invertcor;
 
1114
                        ind_ioctl(x,fd,ZT_RADIO_SETPARAM,&p);
 
1115
                        p.radpar = ZT_RADPAR_EXTRXTONE;
 
1116
                        p.data = exttone;
 
1117
                        ind_ioctl(x,fd,ZT_RADIO_SETPARAM,&p);
1007
1118
                        if (corthresh)
1008
1119
                        {
1009
1120
                                p.radpar = ZT_RADPAR_CORTHRESH;
1019
1130
 
1020
1131
/* End Radio functions */
1021
1132
 
1022
 
static void printconfig()
 
1133
static void printconfig(int fd)
1023
1134
{
1024
1135
        int x,y;
1025
1136
        int ps;
1026
1137
        int configs=0;
1027
 
        printf("\nZaptel Configuration\n"
1028
 
               "======================\n\n");
 
1138
        struct zt_versioninfo vi;
 
1139
 
 
1140
        strcpy(vi.version, "Unknown");
 
1141
        strcpy(vi.echo_canceller, "Unknown");
 
1142
 
 
1143
        if (ioctl(fd, ZT_GETVERSION, &vi))
 
1144
                error("Unable to read Zaptel version information.\n");
 
1145
 
 
1146
        printf("\nZaptel Version: %s\n"
 
1147
               "Echo Canceller: %s\n"
 
1148
               "Configuration\n"
 
1149
               "======================\n\n", vi.version, vi.echo_canceller);
1029
1150
        for (x=0;x<spans;x++) 
1030
1151
                printf("SPAN %d: %3s/%4s Build-out: %s\n",
1031
1152
                       x+1, ( lc[x].lineconfig & ZT_CONFIG_D4 ? "D4" :
1062
1183
                for (x=1;x<ZT_MAX_CHANNELS;x++) 
1063
1184
                        if (cc[x].sigtype)
1064
1185
                                configs++;
1065
 
        printf("\n%d channels configured.\n\n", configs);
 
1186
        printf("\n%d channels to configure.\n\n", configs);
1066
1187
}
1067
1188
 
1068
1189
static struct handler {
1084
1205
        { "rawhdlc", chanconfig },
1085
1206
        { "nethdlc", chanconfig },
1086
1207
        { "fcshdlc", chanconfig },
 
1208
        { "hardhdlc", chanconfig },
 
1209
        { "mtp2", chanconfig },
1087
1210
        { "dchan", chanconfig },
1088
1211
        { "bchan", chanconfig },
1089
1212
        { "indclear", chanconfig },
1105
1228
        { "exttone", ext_tone },
1106
1229
        { "invertcor", invert_cor },
1107
1230
        { "corthresh", cor_thresh },
 
1231
        { "rxgain", rx_gain },
 
1232
        { "txgain", tx_gain },
 
1233
        { "deemp", de_emp },
 
1234
        { "preemp", pre_emp },
1108
1235
        { "channel", rad_chanconfig },
1109
1236
        { "channels", rad_chanconfig },
1110
1237
};
1226
1353
 
1227
1354
        if (!errcnt) {
1228
1355
                if (verbose) {
1229
 
                        printconfig();
 
1356
                        printconfig(fd);
1230
1357
                }
1231
1358
                if (fo_real) {
1232
1359
                        if (debug & DEBUG_APPLY) {
1233
1360
                                printf("About to open Master device\n");
1234
1361
                                fflush(stdout);
1235
1362
                        }
1236
 
                        if (fd == -1) fd = open(MASTER_DEVICE, O_RDWR);
1237
 
                        if (fd < 0) 
1238
 
                                error("Unable to open master device '%s'\n", MASTER_DEVICE);
1239
 
                        else {
 
1363
                        for (x=0;x<numdynamic;x++) {
 
1364
                                /* destroy them all */
 
1365
                                ioctl(fd, ZT_DYNAMIC_DESTROY, &zds[x]);
 
1366
                        }
 
1367
                        if (stopmode) {
 
1368
                                for (x=0;x<spans;x++) {
 
1369
                                        if (ioctl(fd, ZT_SHUTDOWN, &lc[x].span)) {
 
1370
                                                fprintf(stderr, "Zaptel shutdown failed: %s\n", strerror(errno));
 
1371
                                                close(fd);
 
1372
                                                exit(1);
 
1373
                                        }
 
1374
                                }
 
1375
                        } else {
 
1376
                                for (x=0;x<spans;x++) {
 
1377
                                        if (ioctl(fd, ZT_SPANCONFIG, lc + x)) {
 
1378
                                                fprintf(stderr, "ZT_SPANCONFIG failed on span %d: %s (%d)\n", lc[x].span, strerror(errno), errno);
 
1379
                                                close(fd);
 
1380
                                                exit(1);
 
1381
                                        }
 
1382
                                }
1240
1383
                                for (x=0;x<numdynamic;x++) {
1241
 
                                        /* destroy them all */
1242
 
                                        ioctl(fd, ZT_DYNAMIC_DESTROY, &zds[x]);
1243
 
                                }
1244
 
                                if (stopmode) {
1245
 
                                        for (x=0;x<spans;x++) {
1246
 
                                                if (ioctl(fd, ZT_SHUTDOWN, &lc[x].span)) {
1247
 
                                                        fprintf(stderr, "Zaptel shutdown failed: %s\n", strerror(errno));
1248
 
                                                        close(fd);
1249
 
                                                        exit(1);
1250
 
                                                }
1251
 
                                        }
1252
 
                                } else {
1253
 
                                        for (x=0;x<spans;x++) {
1254
 
                                                if (ioctl(fd, ZT_SPANCONFIG, lc + x)) {
1255
 
                                                        fprintf(stderr, "ZT_SPANCONFIG failed on span %d: %s (%d)\n", lc[x].span, strerror(errno), errno);
1256
 
                                                        close(fd);
1257
 
                                                        exit(1);
1258
 
                                                }
1259
 
                                        }
1260
 
                                        for (x=0;x<numdynamic;x++) {
1261
 
                                                if (ioctl(fd, ZT_DYNAMIC_CREATE, &zds[x])) {
1262
 
                                                        fprintf(stderr, "Zaptel dynamic span creation failed: %s\n", strerror(errno));
1263
 
                                                        close(fd);
1264
 
                                                        exit(1);
1265
 
                                                }
1266
 
                                        }
1267
 
                                        for (x=1;x<ZT_MAX_CHANNELS;x++) {
1268
 
                                                struct zt_params current_state;
1269
 
                                                int master;
1270
 
                                                int needupdate = force;
1271
 
 
1272
 
                                                if (debug & DEBUG_APPLY) {
1273
 
                                                        printf("Configuring device %d\n", x);
1274
 
                                                        fflush(stdout);
1275
 
                                                }
1276
 
                                                if (!cc[x].sigtype)
1277
 
                                                        continue;
1278
 
 
1279
 
                                                if (!needupdate) {
1280
 
                                                        memset(&current_state, 0, sizeof(current_state));
1281
 
                                                        current_state.channo = cc[x].chan | ZT_GET_PARAMS_RETURN_MASTER;
1282
 
                                                        if (ioctl(fd, ZT_GET_PARAMS, &current_state))
1283
 
                                                                needupdate = 1;
1284
 
                                                }
1285
 
 
1286
 
                                                if (!needupdate) {
1287
 
                                                        master = current_state.channo >> 16;
1288
 
                                                        
1289
 
                                                        if (cc[x].sigtype != current_state.sigtype) {
1290
 
                                                                needupdate++;
1291
 
                                                                if (verbose > 1)
1292
 
                                                                        printf("Changing signalling on channel %d from %s to %s\n",
1293
 
                                                                               cc[x].chan, sigtype_to_str(current_state.sigtype),
1294
 
                                                                               sigtype_to_str(cc[x].sigtype));
1295
 
                                                        }
1296
 
                                                        
1297
 
                                                        if ((cc[x].deflaw != ZT_LAW_DEFAULT) && (cc[x].deflaw != current_state.curlaw)) {
1298
 
                                                                needupdate++;
1299
 
                                                                if (verbose > 1)
1300
 
                                                                        printf("Changing law on channel %d from %s to %s\n",
1301
 
                                                                               cc[x].chan, laws[current_state.curlaw],
1302
 
                                                                               laws[cc[x].deflaw]);
1303
 
                                                        }
1304
 
                                                        
1305
 
                                                        if (cc[x].master != master) {
1306
 
                                                                needupdate++;
1307
 
                                                                if (verbose > 1)
1308
 
                                                                        printf("Changing master of channel %d from %d to %d\n",
1309
 
                                                                               cc[x].chan, master,
1310
 
                                                                               cc[x].master);
1311
 
                                                        }
1312
 
                                                        
1313
 
                                                        if (cc[x].idlebits != current_state.idlebits) {
1314
 
                                                                needupdate++;
1315
 
                                                                if (verbose > 1)
1316
 
                                                                        printf("Changing idle bits of channel %d from %d to %d\n",
1317
 
                                                                               cc[x].chan, current_state.idlebits,
1318
 
                                                                               cc[x].idlebits);
1319
 
                                                        }
1320
 
                                                }
1321
 
 
1322
 
                                                if (needupdate && ioctl(fd, ZT_CHANCONFIG, &cc[x])) {
1323
 
                                                        fprintf(stderr, "ZT_CHANCONFIG failed on channel %d: %s (%d)\n", x, strerror(errno), errno);
1324
 
                                                        if (errno == EINVAL) {
1325
 
                                                                fprintf(stderr, "Did you forget that FXS interfaces are configured with FXO signalling\n"
1326
 
                                                                        "and that FXO interfaces use FXS signalling?\n");
1327
 
                                                        }
1328
 
                                                        close(fd);
1329
 
                                                        exit(1);
1330
 
                                                }
1331
 
                                        }
1332
 
                                        for (x=0;x<numzones;x++) {
1333
 
                                                if (debug & DEBUG_APPLY) {
1334
 
                                                        printf("Loading tone zone for %s\n", zonestoload[x]);
1335
 
                                                        fflush(stdout);
1336
 
                                                }
1337
 
                                                if (tone_zone_register(fd, zonestoload[x]))
 
1384
                                        if (ioctl(fd, ZT_DYNAMIC_CREATE, &zds[x])) {
 
1385
                                                fprintf(stderr, "Zaptel dynamic span creation failed: %s\n", strerror(errno));
 
1386
                                                close(fd);
 
1387
                                                exit(1);
 
1388
                                        }
 
1389
                                }
 
1390
                                for (x=1;x<ZT_MAX_CHANNELS;x++) {
 
1391
                                        struct zt_params current_state;
 
1392
                                        int master;
 
1393
                                        int needupdate = force;
 
1394
                                        
 
1395
                                        if (debug & DEBUG_APPLY) {
 
1396
                                                printf("Configuring device %d\n", x);
 
1397
                                                fflush(stdout);
 
1398
                                        }
 
1399
                                        if (!cc[x].sigtype)
 
1400
                                                continue;
 
1401
                                        
 
1402
                                        if (!needupdate) {
 
1403
                                                memset(&current_state, 0, sizeof(current_state));
 
1404
                                                current_state.channo = cc[x].chan | ZT_GET_PARAMS_RETURN_MASTER;
 
1405
                                                if (ioctl(fd, ZT_GET_PARAMS, &current_state))
 
1406
                                                        needupdate = 1;
 
1407
                                        }
 
1408
                                        
 
1409
                                        if (!needupdate) {
 
1410
                                                master = current_state.channo >> 16;
 
1411
                                                
 
1412
                                                if (cc[x].sigtype != current_state.sigtype) {
 
1413
                                                        needupdate++;
 
1414
                                                        if (verbose > 1)
 
1415
                                                                printf("Changing signalling on channel %d from %s to %s\n",
 
1416
                                                                       cc[x].chan, sigtype_to_str(current_state.sigtype),
 
1417
                                                                       sigtype_to_str(cc[x].sigtype));
 
1418
                                                }
 
1419
                                                
 
1420
                                                if ((cc[x].deflaw != ZT_LAW_DEFAULT) && (cc[x].deflaw != current_state.curlaw)) {
 
1421
                                                        needupdate++;
 
1422
                                                        if (verbose > 1)
 
1423
                                                                printf("Changing law on channel %d from %s to %s\n",
 
1424
                                                                       cc[x].chan, laws[current_state.curlaw],
 
1425
                                                                       laws[cc[x].deflaw]);
 
1426
                                                }
 
1427
                                                
 
1428
                                                if (cc[x].master != master) {
 
1429
                                                        needupdate++;
 
1430
                                                        if (verbose > 1)
 
1431
                                                                printf("Changing master of channel %d from %d to %d\n",
 
1432
                                                                       cc[x].chan, master,
 
1433
                                                                       cc[x].master);
 
1434
                                                }
 
1435
                                                
 
1436
                                                if (cc[x].idlebits != current_state.idlebits) {
 
1437
                                                        needupdate++;
 
1438
                                                        if (verbose > 1)
 
1439
                                                                printf("Changing idle bits of channel %d from %d to %d\n",
 
1440
                                                                       cc[x].chan, current_state.idlebits,
 
1441
                                                                       cc[x].idlebits);
 
1442
                                                }
 
1443
                                        }
 
1444
                                        
 
1445
                                        if (needupdate && ioctl(fd, ZT_CHANCONFIG, &cc[x])) {
 
1446
                                                fprintf(stderr, "ZT_CHANCONFIG failed on channel %d: %s (%d)\n", x, strerror(errno), errno);
 
1447
                                                if (errno == EINVAL) {
 
1448
                                                        fprintf(stderr, "Did you forget that FXS interfaces are configured with FXO signalling\n"
 
1449
                                                                "and that FXO interfaces use FXS signalling?\n");
 
1450
                                                }
 
1451
                                                close(fd);
 
1452
                                                exit(1);
 
1453
                                        }
 
1454
                                }
 
1455
                                for (x=0;x<numzones;x++) {
 
1456
                                        if (debug & DEBUG_APPLY) {
 
1457
                                                printf("Loading tone zone for %s\n", zonestoload[x]);
 
1458
                                                fflush(stdout);
 
1459
                                        }
 
1460
                                        if (tone_zone_register(fd, zonestoload[x]))
 
1461
                                                if (errno != EBUSY)
1338
1462
                                                        error("Unable to register tone zone '%s'\n", zonestoload[x]);
1339
 
                                        }
1340
 
                                        if (debug & DEBUG_APPLY) {
1341
 
                                                printf("Doing startup\n");
1342
 
                                                fflush(stdout);
1343
 
                                        }
1344
 
                                        if (deftonezone > -1) {
1345
 
                                                if (ioctl(fd, ZT_DEFAULTZONE, &deftonezone)) {
1346
 
                                                        fprintf(stderr, "ZT_DEFAULTZONE failed: %s (%d)\n", strerror(errno), errno);
1347
 
                                                        close(fd);
1348
 
                                                        exit(1);
1349
 
                                                }
1350
 
                                        }
1351
 
                                        for (x=0;x<spans;x++) {
1352
 
                                                if (ioctl(fd, ZT_STARTUP, &lc[x].span)) {
1353
 
                                                        fprintf(stderr, "Zaptel startup failed: %s\n", strerror(errno));
1354
 
                                                        close(fd);
1355
 
                                                        exit(1);
1356
 
                                                }
 
1463
                                }
 
1464
                                if (debug & DEBUG_APPLY) {
 
1465
                                        printf("Doing startup\n");
 
1466
                                        fflush(stdout);
 
1467
                                }
 
1468
                                if (deftonezone > -1) {
 
1469
                                        if (ioctl(fd, ZT_DEFAULTZONE, &deftonezone)) {
 
1470
                                                fprintf(stderr, "ZT_DEFAULTZONE failed: %s (%d)\n", strerror(errno), errno);
 
1471
                                                close(fd);
 
1472
                                                exit(1);
 
1473
                                        }
 
1474
                                }
 
1475
                                for (x=0;x<spans;x++) {
 
1476
                                        if (ioctl(fd, ZT_STARTUP, &lc[x].span)) {
 
1477
                                                fprintf(stderr, "Zaptel startup failed: %s\n", strerror(errno));
 
1478
                                                close(fd);
 
1479
                                                exit(1);
1357
1480
                                        }
1358
1481
                                }
1359
1482
                        }