diff options
-rw-r--r-- | zaptel.c | 8 | ||||
-rw-r--r-- | zaptel.h | 11 | ||||
-rw-r--r-- | ztcfg.c | 222 |
3 files changed, 131 insertions, 110 deletions
@@ -3108,6 +3108,7 @@ static int zt_ctl_ioctl(struct inode *inode, struct file *file, unsigned int cmd struct zt_dialparams tdp; struct zt_maintinfo maint; struct zt_indirect_data ind; + struct zt_versioninfo vi; unsigned long flags; int rv; switch(cmd) { @@ -3409,6 +3410,13 @@ static int zt_ctl_ioctl(struct inode *inode, struct file *file, unsigned int cmd if (copy_to_user((struct zt_dialparams *)data, &tdp, sizeof(tdp))) return -EFAULT; break; + case ZT_GETVERSION: + memset(&vi, 0, sizeof(vi)); + strncpy(vi.version, ZAPTEL_VERSION, sizeof(vi.version) - 1); + strncpy(vi.echo_canceller, ZAPTEL_ECHO_CANCELLER, sizeof(vi.echo_canceller) - 1); + if (copy_to_user((struct zt_versioninfo *) data, &vi, sizeof(vi))) + return -EFAULT; + break; case ZT_MAINT: /* do maintence stuff */ /* get struct from user */ if (copy_from_user(&maint,(struct zt_maintinfo *) data, sizeof(maint))) @@ -304,6 +304,11 @@ int op; void *data; } ZT_INDIRECT_DATA; +struct zt_versioninfo { + char version[80]; + char echo_canceller[80]; +}; + /* ioctl definitions */ #define ZT_CODE 'J' @@ -597,6 +602,12 @@ void *data; /* + * Get the version of Zaptel that is running, and a description + * of the compiled-in echo canceller (if any) + */ +#define ZT_GETVERSION _IOR(ZT_CODE, 57, struct zt_versioninfo) + +/* * 60-80 are reserved for private drivers * 80-85 are reserved for dynamic span stuff */ @@ -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); } } } |