From bb9675a0268c73b0ad7c8af51b47967e99cda828 Mon Sep 17 00:00:00 2001 From: kpfleming Date: Thu, 29 Sep 2005 02:29:17 +0000 Subject: update ztcfg to only reconfigured changed channels unless 'force' parameter is supplied git-svn-id: http://svn.digium.com/svn/zaptel/trunk@781 5390a7c7-147a-4af0-8ec9-7488f05a26cb --- ztcfg.c | 152 ++++++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 125 insertions(+), 27 deletions(-) (limited to 'ztcfg.c') diff --git a/ztcfg.c b/ztcfg.c index 82cd2c0..044e451 100755 --- a/ztcfg.c +++ b/ztcfg.c @@ -76,7 +76,7 @@ static struct zt_chanconfig cc[ZT_MAX_CHANNELS]; static struct zt_dynamic_span zds[NUM_DYNAMIC]; -static char *sig[ZT_MAX_CHANNELS]; /* Signalling */ +static const char *sig[ZT_MAX_CHANNELS]; /* Signalling */ static int slineno[ZT_MAX_CHANNELS]; /* Line number where signalling specified */ @@ -86,6 +86,8 @@ static int fo_real = 1; static int verbose = 0; +static int force = 0; + static int stopmode = 0; static int numdynamic = 0; @@ -96,7 +98,7 @@ static int numzones = 0; static int fd = -1; -static char *lbostr[] = { +static const char *lbostr[] = { "0 db (CSU)/0-133 feet (DSX-1)", "133-266 feet (DSX-1)", "266-399 feet (DSX-1)", @@ -107,12 +109,54 @@ static char *lbostr[] = { "-22.5db (CSU)" }; -static char *laws[] = { +static const char *laws[] = { "Default", "Mu-law", "A-law" }; +static const char *sigtype_to_str(const int sig) +{ + switch (sig) { + case 0: + return "Unused"; + case ZT_SIG_EM: + return "E & M"; + case ZT_SIG_EM_E1: + return "E & M E1"; + case ZT_SIG_FXSLS: + return "FXS Loopstart"; + case ZT_SIG_FXSGS: + return "FXS Groundstart"; + case ZT_SIG_FXSKS: + return "FXS Kewlstart"; + case ZT_SIG_FXOLS: + return "FXO Loopstart"; + case ZT_SIG_FXOGS: + return "FXO Groundstart"; + case ZT_SIG_FXOKS: + return "FXO Kewlstart"; + case ZT_SIG_CAS: + return "CAS / User"; + case ZT_SIG_DACS: + return "DACS"; + case ZT_SIG_DACS_RBS: + return "DACS w/RBS"; + case ZT_SIG_CLEAR: + return "Clear channel"; + case ZT_SIG_SLAVE: + return "Slave channel"; + case ZT_SIG_HDLCRAW: + return "Raw HDLC"; + case ZT_SIG_HDLCNET: + return "Network HDLC"; + case ZT_SIG_HDLCFCS: + return "HDLC with FCS check"; + default: + return "Unknown"; + } +} + int ind_ioctl(int channo, int fd, int op, void *data) { ZT_INDIRECT_DATA ind; @@ -434,62 +478,62 @@ static int chanconfig(char *keyword, char *args) cc[x].master = x; slineno[x] = lineno; if (!strcasecmp(keyword, "e&m")) { - sig[x] = "E & M"; cc[x].sigtype = ZT_SIG_EM; + sig[x] = sigtype_to_str(cc[x].sigtype); } else if (!strcasecmp(keyword, "e&me1")) { - sig[x] = "E & M E1"; cc[x].sigtype = ZT_SIG_EM_E1; + sig[x] = sigtype_to_str(cc[x].sigtype); } else if (!strcasecmp(keyword, "fxsls")) { - sig[x] = "FXS Loopstart"; cc[x].sigtype = ZT_SIG_FXSLS; + sig[x] = sigtype_to_str(cc[x].sigtype); } else if (!strcasecmp(keyword, "fxsgs")) { - sig[x] = "FXS Groundstart"; cc[x].sigtype = ZT_SIG_FXSGS; + sig[x] = sigtype_to_str(cc[x].sigtype); } else if (!strcasecmp(keyword, "fxsks")) { - sig[x] = "FXS Kewlstart"; cc[x].sigtype = ZT_SIG_FXSKS; + sig[x] = sigtype_to_str(cc[x].sigtype); } else if (!strcasecmp(keyword, "fxols")) { - sig[x] = "FXO Loopstart"; cc[x].sigtype = ZT_SIG_FXOLS; + sig[x] = sigtype_to_str(cc[x].sigtype); } else if (!strcasecmp(keyword, "fxogs")) { - sig[x] = "FXO Groundstart"; cc[x].sigtype = ZT_SIG_FXOGS; + sig[x] = sigtype_to_str(cc[x].sigtype); } else if (!strcasecmp(keyword, "fxoks")) { - sig[x] = "FXO Kewlstart"; cc[x].sigtype = ZT_SIG_FXOKS; + sig[x] = sigtype_to_str(cc[x].sigtype); } else if (!strcasecmp(keyword, "cas") || !strcasecmp(keyword, "user")) { if (parse_idle(&cc[x].idlebits, idle)) return -1; - sig[x] = "CAS / User"; cc[x].sigtype = ZT_SIG_CAS; + sig[x] = sigtype_to_str(cc[x].sigtype); } else if (!strcasecmp(keyword, "dacs")) { /* Setup channel for monitor */ cc[x].idlebits = dacschan; cc[x].sigtype = ZT_SIG_DACS; - sig[x] = "DACS"; + sig[x] = sigtype_to_str(cc[x].sigtype); /* Setup inverse */ cc[dacschan].idlebits = x; cc[dacschan].sigtype = ZT_SIG_DACS; - sig[dacschan] = "DACS"; + sig[x] = sigtype_to_str(cc[dacschan].sigtype); dacschan++; } else if (!strcasecmp(keyword, "dacsrbs")) { /* Setup channel for monitor */ cc[x].idlebits = dacschan; cc[x].sigtype = ZT_SIG_DACS_RBS; - sig[x] = "DACS w/ RBS"; + sig[x] = sigtype_to_str(cc[x].sigtype); /* Setup inverse */ cc[dacschan].idlebits = x; cc[dacschan].sigtype = ZT_SIG_DACS_RBS; - sig[dacschan] = "DACS w/ RBS"; + sig[x] = sigtype_to_str(cc[dacschan].sigtype); dacschan++; } else if (!strcasecmp(keyword, "unused")) { - sig[x] = "Unused"; cc[x].sigtype = 0; + sig[x] = sigtype_to_str(cc[x].sigtype); } else if (!strcasecmp(keyword, "indclear") || !strcasecmp(keyword, "bchan")) { - sig[x] = "Individual Clear channel"; cc[x].sigtype = ZT_SIG_CLEAR; + sig[x] = sigtype_to_str(cc[x].sigtype); } else if (!strcasecmp(keyword, "clear")) { - sig[x] = "Clear channel"; + sig[x] = sigtype_to_str(ZT_SIG_CLEAR); if (master) { cc[x].sigtype = ZT_SIG_SLAVE; cc[x].master = master; @@ -498,7 +542,7 @@ static int chanconfig(char *keyword, char *args) master = x; } } else if (!strcasecmp(keyword, "rawhdlc")) { - sig[x] = "Raw HDLC"; + sig[x] = sigtype_to_str(ZT_SIG_HDLCRAW); if (master) { cc[x].sigtype = ZT_SIG_SLAVE; cc[x].master = master; @@ -507,7 +551,7 @@ static int chanconfig(char *keyword, char *args) master = x; } } else if (!strcasecmp(keyword, "nethdlc")) { - sig[x] = "Network HDLC"; + sig[x] = sigtype_to_str(ZT_SIG_HDLCNET); if (master) { cc[x].sigtype = ZT_SIG_SLAVE; cc[x].master = master; @@ -516,7 +560,7 @@ static int chanconfig(char *keyword, char *args) master = x; } } else if (!strcasecmp(keyword, "fcshdlc")) { - sig[x] = "HDLC with FCS check"; + sig[x] = sigtype_to_str(ZT_SIG_HDLCFCS); if (master) { cc[x].sigtype = ZT_SIG_SLAVE; cc[x].master = master; @@ -1094,11 +1138,12 @@ static void usage(char *argv0, int exitcode) "Usage: %s [options]\n" " Valid options are:\n" " -c -- Use instead of " CONFIG_FILENAME "\n" - " -h -- Generate this help statement\n" - " -v -- Verbose (more -v's means more verbose)\n" " -d [level] -- Generate debugging output. (Default level is 1.)\n" - " -t -- Test mode only, do not apply\n" + " -f -- Always reconfigure every channel\n" + " -h -- Generate this help statement\n" " -s -- Shutdown spans only\n" + " -t -- Test mode only, do not apply\n" + " -v -- Verbose (more -v's means more verbose)\n" ,c); exit(exitcode); } @@ -1109,7 +1154,7 @@ int main(int argc, char *argv[]) char *buf; char *key, *value; int x,found; - while((c = getopt(argc, argv, "thc:vsd::")) != -1) { + while((c = getopt(argc, argv, "fthc:vsd::")) != -1) { switch(c) { case 'c': filename=optarg; @@ -1123,6 +1168,9 @@ int main(int argc, char *argv[]) case 'v': verbose++; break; + case 'f': + force++; + break; case 't': fo_real = 0; break; @@ -1217,11 +1265,61 @@ int main(int argc, char *argv[]) } } for (x=1;x> 16; + + if (cc[x].sigtype != current_state.sigtype) { + needupdate++; + if (verbose > 1) + printf("Changing signalling on channel %d from %s to %s\n", + cc[x].chan, sigtype_to_str(current_state.sigtype), + sigtype_to_str(cc[x].sigtype)); + } + + if ((cc[x].deflaw != ZT_LAW_DEFAULT) && (cc[x].deflaw != current_state.curlaw)) { + needupdate++; + if (verbose > 1) + printf("Changing law on channel %d from %s to %s\n", + cc[x].chan, laws[current_state.curlaw], + laws[cc[x].deflaw]); + } + + if (cc[x].master != master) { + needupdate++; + if (verbose > 1) + printf("Changing master of channel %d from %d to %d\n", + cc[x].chan, master, + cc[x].master); + } + + if (cc[x].idlebits != current_state.idlebits) { + needupdate++; + if (verbose > 1) + printf("Changing idle bits of channel %d from %d to %d\n", + cc[x].chan, current_state.idlebits, + cc[x].idlebits); + } + } + + if (needupdate && ioctl(fd, ZT_CHANCONFIG, &cc[x])) { fprintf(stderr, "ZT_CHANCONFIG failed on channel %d: %s (%d)\n", x, strerror(errno), errno); if (errno == EINVAL) { fprintf(stderr, "Did you forget that FXS interfaces are configured with FXO signalling\n" -- cgit v1.2.3