diff options
Diffstat (limited to 'ztcfg.c')
-rw-r--r-- | ztcfg.c | 222 |
1 files changed, 112 insertions, 110 deletions
@@ -1019,13 +1019,20 @@ static int rad_chanconfig(char *keyword, char *args) /* End Radio functions */ -static void printconfig() +static void printconfig(int fd) { int x,y; int ps; int configs=0; - printf("\nZaptel Configuration\n" - "======================\n\n"); + struct zt_versioninfo vi; + + if (ioctl(fd, ZT_GETVERSION, &vi)) + error("Unable to read Zaptel version information.\n"); + + printf("\nZaptel Version: %s\n" + "Echo Canceller: %s\n" + "Configuration\n" + "======================\n\n", vi.version, vi.echo_canceller); for (x=0;x<spans;x++) printf("SPAN %d: %3s/%4s Build-out: %s\n", x+1, ( lc[x].lineconfig & ZT_CONFIG_D4 ? "D4" : @@ -1226,134 +1233,129 @@ int main(int argc, char *argv[]) if (!errcnt) { if (verbose) { - printconfig(); + printconfig(fd); } if (fo_real) { if (debug & DEBUG_APPLY) { printf("About to open Master device\n"); fflush(stdout); } - if (fd == -1) fd = open(MASTER_DEVICE, O_RDWR); - if (fd < 0) - error("Unable to open master device '%s'\n", MASTER_DEVICE); - else { - for (x=0;x<numdynamic;x++) { - /* destroy them all */ - ioctl(fd, ZT_DYNAMIC_DESTROY, &zds[x]); + for (x=0;x<numdynamic;x++) { + /* destroy them all */ + ioctl(fd, ZT_DYNAMIC_DESTROY, &zds[x]); + } + if (stopmode) { + for (x=0;x<spans;x++) { + if (ioctl(fd, ZT_SHUTDOWN, &lc[x].span)) { + fprintf(stderr, "Zaptel shutdown failed: %s\n", strerror(errno)); + close(fd); + exit(1); + } } - if (stopmode) { - for (x=0;x<spans;x++) { - if (ioctl(fd, ZT_SHUTDOWN, &lc[x].span)) { - fprintf(stderr, "Zaptel shutdown failed: %s\n", strerror(errno)); - close(fd); - exit(1); - } + } else { + for (x=0;x<spans;x++) { + if (ioctl(fd, ZT_SPANCONFIG, lc + x)) { + fprintf(stderr, "ZT_SPANCONFIG failed on span %d: %s (%d)\n", lc[x].span, strerror(errno), errno); + close(fd); + exit(1); } - } else { - for (x=0;x<spans;x++) { - if (ioctl(fd, ZT_SPANCONFIG, lc + x)) { - fprintf(stderr, "ZT_SPANCONFIG failed on span %d: %s (%d)\n", lc[x].span, strerror(errno), errno); - close(fd); - exit(1); - } + } + for (x=0;x<numdynamic;x++) { + if (ioctl(fd, ZT_DYNAMIC_CREATE, &zds[x])) { + fprintf(stderr, "Zaptel dynamic span creation failed: %s\n", strerror(errno)); + close(fd); + exit(1); } - for (x=0;x<numdynamic;x++) { - if (ioctl(fd, ZT_DYNAMIC_CREATE, &zds[x])) { - fprintf(stderr, "Zaptel dynamic span creation failed: %s\n", strerror(errno)); - close(fd); - exit(1); - } + } + for (x=1;x<ZT_MAX_CHANNELS;x++) { + struct zt_params current_state; + int master; + int needupdate = force; + + if (debug & DEBUG_APPLY) { + printf("Configuring device %d\n", x); + fflush(stdout); } - for (x=1;x<ZT_MAX_CHANNELS;x++) { - struct zt_params current_state; - int master; - int needupdate = force; - - if (debug & DEBUG_APPLY) { - printf("Configuring device %d\n", x); - fflush(stdout); + if (!cc[x].sigtype) + continue; + + if (!needupdate) { + memset(¤t_state, 0, sizeof(current_state)); + current_state.channo = cc[x].chan | ZT_GET_PARAMS_RETURN_MASTER; + if (ioctl(fd, ZT_GET_PARAMS, ¤t_state)) + needupdate = 1; + } + + if (!needupdate) { + master = current_state.channo >> 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].sigtype) - continue; - - if (!needupdate) { - memset(¤t_state, 0, sizeof(current_state)); - current_state.channo = cc[x].chan | ZT_GET_PARAMS_RETURN_MASTER; - if (ioctl(fd, ZT_GET_PARAMS, ¤t_state)) - needupdate = 1; + + 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 (!needupdate) { - master = current_state.channo >> 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 (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 (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" - "and that FXO interfaces use FXS signalling?\n"); - } - close(fd); - exit(1); + + 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); } } - for (x=0;x<numzones;x++) { - if (debug & DEBUG_APPLY) { - printf("Loading tone zone for %s\n", zonestoload[x]); - fflush(stdout); + + 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" + "and that FXO interfaces use FXS signalling?\n"); } - if (tone_zone_register(fd, zonestoload[x])) - error("Unable to register tone zone '%s'\n", zonestoload[x]); + close(fd); + exit(1); } + } + for (x=0;x<numzones;x++) { if (debug & DEBUG_APPLY) { - printf("Doing startup\n"); + printf("Loading tone zone for %s\n", zonestoload[x]); fflush(stdout); } - if (deftonezone > -1) { - if (ioctl(fd, ZT_DEFAULTZONE, &deftonezone)) { - fprintf(stderr, "ZT_DEFAULTZONE failed: %s (%d)\n", strerror(errno), errno); - close(fd); - exit(1); - } + if (tone_zone_register(fd, zonestoload[x])) + error("Unable to register tone zone '%s'\n", zonestoload[x]); + } + if (debug & DEBUG_APPLY) { + printf("Doing startup\n"); + fflush(stdout); + } + if (deftonezone > -1) { + if (ioctl(fd, ZT_DEFAULTZONE, &deftonezone)) { + fprintf(stderr, "ZT_DEFAULTZONE failed: %s (%d)\n", strerror(errno), errno); + close(fd); + exit(1); } - for (x=0;x<spans;x++) { - if (ioctl(fd, ZT_STARTUP, &lc[x].span)) { - fprintf(stderr, "Zaptel startup failed: %s\n", strerror(errno)); - close(fd); - exit(1); - } + } + for (x=0;x<spans;x++) { + if (ioctl(fd, ZT_STARTUP, &lc[x].span)) { + fprintf(stderr, "Zaptel startup failed: %s\n", strerror(errno)); + close(fd); + exit(1); } } } |