📄 ztcfg.c
字号:
} else if (!strcasecmp(keyword, "fxols")) { sig[x] = "FXO Loopstart"; cc[x].sigtype = ZT_SIG_FXOLS; } else if (!strcasecmp(keyword, "fxogs")) { sig[x] = "FXO Groundstart"; cc[x].sigtype = ZT_SIG_FXOGS; } else if (!strcasecmp(keyword, "fxoks")) { sig[x] = "FXO Kewlstart"; cc[x].sigtype = ZT_SIG_FXOKS; } 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; } else if (!strcasecmp(keyword, "dacs")) { /* Setup channel for monitor */ cc[x].idlebits = dacschan; cc[x].sigtype = ZT_SIG_DACS; sig[x] = "DACS"; /* Setup inverse */ cc[dacschan].idlebits = x; cc[dacschan].sigtype = ZT_SIG_DACS; sig[dacschan] = "DACS"; 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"; /* Setup inverse */ cc[dacschan].idlebits = x; cc[dacschan].sigtype = ZT_SIG_DACS_RBS; sig[dacschan] = "DACS w/ RBS"; dacschan++; } else if (!strcasecmp(keyword, "unused")) { sig[x] = "Unused"; cc[x].sigtype = 0; } else if (!strcasecmp(keyword, "indclear") || !strcasecmp(keyword, "bchan")) { sig[x] = "Individual Clear channel"; cc[x].sigtype = ZT_SIG_CLEAR; } else if (!strcasecmp(keyword, "clear")) { sig[x] = "Clear channel"; if (master) { cc[x].sigtype = ZT_SIG_SLAVE; cc[x].master = master; } else { cc[x].sigtype = ZT_SIG_CLEAR; master = x; } } else if (!strcasecmp(keyword, "rawhdlc")) { sig[x] = "Raw HDLC"; if (master) { cc[x].sigtype = ZT_SIG_SLAVE; cc[x].master = master; } else { cc[x].sigtype = ZT_SIG_HDLCRAW; master = x; } } else if (!strcasecmp(keyword, "nethdlc")) { sig[x] = "Network HDLC"; if (master) { cc[x].sigtype = ZT_SIG_SLAVE; cc[x].master = master; } else { cc[x].sigtype = ZT_SIG_HDLCNET; master = x; } } else if (!strcasecmp(keyword, "fcshdlc")) { sig[x] = "HDLC with FCS check"; if (master) { cc[x].sigtype = ZT_SIG_SLAVE; cc[x].master = master; } else { cc[x].sigtype = ZT_SIG_HDLCFCS; master = x; } } else if (!strcasecmp(keyword, "dchan")) { sig[x] = "D-channel"; cc[x].sigtype = ZT_SIG_HDLCFCS; } else { fprintf(stderr, "Huh? (%s)\n", keyword); } } return 0;}static int setlaw(char *keyword, char *args){ int res; int law; int x; int chans[ZT_MAX_CHANNELS]; bzero(chans, sizeof(chans)); res = apply_channels(chans, args); if (res <= 0) return -1; if (!strcasecmp(keyword, "alaw")) { law = ZT_LAW_ALAW; } else if (!strcasecmp(keyword, "mulaw")) { law = ZT_LAW_MULAW; } else if (!strcasecmp(keyword, "deflaw")) { law = ZT_LAW_DEFAULT; } else { fprintf(stderr, "Huh??? Don't know about '%s' law\n", keyword); return -1; } for (x=0;x<ZT_MAX_CHANNELS;x++) { if (chans[x]) cc[x].deflaw = law; } return 0;}static int registerzone(char *keyword, char *args){ if (numzones >= ZT_TONE_ZONE_MAX) { error("Too many tone zones specified\n"); return 0; } strncpy(zonestoload[numzones++], args, sizeof(zonestoload[0])); return 0;}static int defaultzone(char *keyword, char *args){ struct tone_zone *z; if (!(z = tone_zone_find(args))) { error("No such tone zone known: %s\n", args); return 0; } deftonezone = z->zone; return 0;}#if 0static int unimplemented(char *keyword, char *args){ fprintf(stderr, "Warning: '%s' is not yet implemented\n", keyword); return 0;}#endifstatic void printconfig(){ int x,y; int ps; int configs=0; printf("\nZaptel Configuration\n" "======================\n\n"); for (x=0;x<spans;x++) printf("SPAN %d: %3s/%4s Build-out: %s\n", x+1, ( lc[x].lineconfig & ZT_CONFIG_D4 ? "D4" : lc[x].lineconfig & ZT_CONFIG_ESF ? "ESF" : lc[x].lineconfig & ZT_CONFIG_CCS ? "CCS" : "CAS" ), ( lc[x].lineconfig & ZT_CONFIG_AMI ? "AMI" : lc[x].lineconfig & ZT_CONFIG_B8ZS ? "B8ZS" : lc[x].lineconfig & ZT_CONFIG_HDB3 ? "HDB3" : "???" ), lbostr[lc[x].lbo]); for (x=0;x<numdynamic;x++) { printf("Dynamic span %d: driver %s, addr %s, channels %d, timing %d\n", x +1, zds[x].driver, zds[x].addr, zds[x].numchans, zds[x].timing); } if (verbose > 1) { printf("\nChannel map:\n\n"); for (x=1;x<ZT_MAX_CHANNELS;x++) { if ((cc[x].sigtype != ZT_SIG_SLAVE) && (cc[x].sigtype)) { configs++; ps = 0; if ((cc[x].sigtype & __ZT_SIG_DACS) == __ZT_SIG_DACS) printf("Channel %02d %s to %02d", x, sig[x], cc[x].idlebits); else { printf("Channel %02d: %s (%s)", x, sig[x], laws[cc[x].deflaw]); for (y=1;y<ZT_MAX_CHANNELS;y++) if (cc[y].master == x) { printf("%s%02d", ps++ ? " " : " (Slaves: ", y); } } if (ps) printf(")\n"); else printf("\n"); } else if (cc[x].sigtype) configs++; } } else for (x=1;x<ZT_MAX_CHANNELS;x++) if (cc[x].sigtype) configs++; printf("\n%d channels configured.\n\n", configs);}static struct handler { char *keyword; int (*func)(char *keyword, char *args);} handlers[] = { { "span", spanconfig }, { "dynamic", dspanconfig }, { "loadzone", registerzone }, { "defaultzone", defaultzone }, { "e&m", chanconfig }, { "e&me1", chanconfig }, { "fxsls", chanconfig }, { "fxsgs", chanconfig }, { "fxsks", chanconfig }, { "fxols", chanconfig }, { "fxogs", chanconfig }, { "fxoks", chanconfig }, { "rawhdlc", chanconfig }, { "nethdlc", chanconfig }, { "fcshdlc", chanconfig }, { "dchan", chanconfig }, { "bchan", chanconfig }, { "indclear", chanconfig }, { "clear", chanconfig }, { "unused", chanconfig }, { "cas", chanconfig }, { "dacs", chanconfig }, { "dacsrbs", chanconfig }, { "user", chanconfig }, { "alaw", setlaw }, { "mulaw", setlaw }, { "deflaw", setlaw },};static char *readline(){ static char buf[256]; char *c; do { if (!fgets(buf, sizeof(buf), cf)) return NULL; /* Strip comments */ c = strchr(buf, '#'); if (c) *c = '\0'; trim(buf); lineno++; } while (!strlen(buf)); return buf;}static void usage(char *argv0, int exitcode){ char *c; c = strrchr(argv0, '/'); if (!c) c = argv0; else c++; fprintf(stderr, "Usage: %s [options]\n" " Valid options are:\n" " -c <filename> -- Use <filename> instead of " CONFIG_FILENAME "\n" " -h -- Generate this help statement\n" " -v -- Verbose (more -v's means more verbose)\n" " -t -- Test mode only, do not apply\n" " -s -- Shutdown spans only\n" ,c); exit(exitcode);}int main(int argc, char *argv[]){ char c; char *buf; char *key, *value; int x,found; int fd; while((c = getopt(argc, argv, "thc:vs")) != -1) { switch(c) { case 'c': filename=optarg; break; case 'h': usage(argv[0], 0); break; case '?': usage(argv[0], 1); break; case 'v': verbose++; break; case 't': fo_real = 0; break; case 's': stopmode = 1; break; } } cf = fopen(filename, "r"); if (cf) { while((buf = readline())) { if (debug & DEBUG_READER) fprintf(stderr, "Line %d: %s\n", lineno, buf); key = value = buf; while(value && *value && (*value != '=')) value++; if (value) *value='\0'; if (value) value++; while(value && *value && (*value < 33)) value++; if (*value) { trim(key); if (debug & DEBUG_PARSER) fprintf(stderr, "Keyword: [%s], Value: [%s]\n", key, value); } else error("Syntax error. Should be <keyword>=<value>\n"); found=0; for (x=0;x<sizeof(handlers) / sizeof(handlers[0]);x++) { if (!strcasecmp(key, handlers[x].keyword)) { found++; handlers[x].func(key, value); break; } } if (!found) error("Unknown keyword '%s'\n", key); } if (debug & DEBUG_READER) fprintf(stderr, "<End of File>\n"); fclose(cf); } else { error("Unable to open configuration file '%s'\n", filename); } if (!errcnt) { if (verbose) { printconfig(); } if (fo_real) { if (debug & DEBUG_APPLY) { printf("About to open Master device\n"); fflush(stdout); } 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]); } 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); } } 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++) { if (debug & DEBUG_APPLY) { printf("Configuring device %d\n", x); fflush(stdout); } if (cc[x].sigtype && 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); } } for (x=0;x<numzones;x++) { if (debug & DEBUG_APPLY) { printf("Loading tone zone for %s\n", zonestoload[x]); fflush(stdout); } 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); } } } close(fd); } } } else { fprintf(stderr, "\n%d error(s) detected\n\n", errcnt); exit(1); } exit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -