Exemple #1
0
static int apply_fiftysix(void)
{
	int x;
	int rate;
	int chanfd;

	for (x = 1; x < DAHDI_MAX_CHANNELS; x++) {
		if (skip_channel(x))
			continue;
		chanfd = open("/dev/dahdi/channel", O_RDWR);
		if (chanfd == -1) {
			fprintf(stderr, 
			    "Couldn't open /dev/dahdi/channel: %s\n", 
			    strerror(errno));
			return -1;	
		}

		if (ioctl(chanfd, DAHDI_SPECIFY, &x)) {
			close(chanfd);
			continue;
		}

		if (fiftysixkhdlc[x]) {
			printf("Setting channel %d to 56K mode (only valid on HDLC channels)\n", x);
			rate = 56;
		} else {
			rate = 64;
		}

		if (ioctl(chanfd, DAHDI_HDLC_RATE, &rate)) {
			fprintf(stderr, "Error setting HDLC rate\n");
			exit(-1);
		}
		close(chanfd);
	}
	return 0;
}
Exemple #2
0
int main(int argc, char *argv[])
{
	int c;
	char *buf;
	char *key, *value;
	int x,found;

	while((c = getopt(argc, argv, "fthc:vsd::C:S:")) != -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 'f':
			force++;
			break;
		case 't':
			fo_real = 0;
			break;
		case 's':
			stopmode = 1;
			break;
		case 'C':
			if (!chan_restrict(optarg))
				usage(argv[0], 1);
			break;
		case 'S':
			if (!span_restrict(optarg))
				usage(argv[0], 1);
			break;
		case 'd':
			if (optarg)
				debug = atoi(optarg);
			else
				debug = 1;	
			break;
		}
	}
	
	if (verbose) {
		fprintf(stderr, "%s\n", dahdi_tools_version);
	}

	if (fd == -1) fd = open(MASTER_DEVICE, O_RDWR);
	if (fd < 0) {
		error("Unable to open master device '%s'\n", MASTER_DEVICE);
		goto finish;
	}
	cf = fopen(filename, "r");
	if (cf) {
		while((buf = readline())) {
			if (*buf == 10) /* skip new line */
				continue;

			if (debug & DEBUG_READER) 
				fprintf(stderr, "Line %d: %s\n", lineno, buf);

			if ((value = strchr(buf, '='))) {
				*value++ = '\0';
				value = trim(value);
				key = trim(buf);
			}

			if (!value || !*value || !*key) {
				error("Syntax error. Should be <keyword>=<value>\n");
				continue;
			}

			if (debug & DEBUG_PARSER)
				fprintf(stderr, "Keyword: [%s], Value: [%s]\n", key, value);

			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); // causes seg fault (double free) */
	} else {
		error("Unable to open configuration file '%s'\n", filename);
	}

finish:
	if (errcnt) {
		fprintf(stderr, "\n%d error(s) detected\n\n", errcnt);
		exit(1);
	}
	if (verbose) {
		printconfig(fd);
	}
	if (!fo_real) 
		exit(0);

	
	if (debug & DEBUG_APPLY) {
		printf("About to open Master device\n");
		fflush(stdout);
	}
	for (x=0;x<numdynamic;x++) {
		/* destroy them all */
		ioctl(fd, DAHDI_DYNAMIC_DESTROY, &zds[x]);
	}
	if (stopmode) {
		for (x=0;x<spans;x++) {
			if (only_span && lc[x].span != only_span)
				continue;
			if (ioctl(fd, DAHDI_SHUTDOWN, &lc[x].span)) {
				fprintf(stderr, "DAHDI shutdown failed: %s\n", strerror(errno));
				close(fd);
				exit(1);
			}
		}
		exit(1);
	}
	for (x=0;x<spans;x++) {
		if (only_span && lc[x].span != only_span)
			continue;
		if (ioctl(fd, DAHDI_SPANCONFIG, lc + x)) {
			fprintf(stderr, "DAHDI_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, DAHDI_DYNAMIC_CREATE, &zds[x])) {
			fprintf(stderr, "DAHDI dynamic span creation failed: %s\n", strerror(errno));
			close(fd);
			exit(1);
		}
	}
	for (x=1;x<DAHDI_MAX_CHANNELS;x++) {
		struct dahdi_params current_state;
		int master;
		int needupdate = force;

		if (skip_channel(x)) {
			if (debug & DEBUG_APPLY) {
				printf("Skip device %d\n", x);
				fflush(stdout);
			}
			continue;
		}
		if (debug & DEBUG_APPLY) {
			printf("Configuring device %d\n", x);
			fflush(stdout);
		}
		if (!cc[x].sigtype)
			continue;
		
		if (!needupdate) {
			memset(&current_state, 0, sizeof(current_state));
			current_state.channo = cc[x].chan | DAHDI_GET_PARAMS_RETURN_MASTER;
			if (ioctl(fd, DAHDI_GET_PARAMS, &current_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].deflaw != DAHDI_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, DAHDI_CHANCONFIG, &cc[x])) {
			fprintf(stderr, "DAHDI_CHANCONFIG failed on channel %d: %s (%d)\n", x, strerror(errno), errno);
			if (errno == EINVAL) {
				/* give helpful suggestions on signaling errors */
				fprintf(stderr, "Selected signaling not "
						"supported\n");
				fprintf(stderr, "Possible causes:\n");
				switch(cc[x].sigtype) {
				case DAHDI_SIG_FXOKS:
				case DAHDI_SIG_FXOLS:
				case DAHDI_SIG_FXOGS:
					fprintf(stderr, "\tFXO signaling is "
						"being used on a FXO interface"
						" (use a FXS signaling variant"
						")\n");
					fprintf(stderr, "\tRBS signaling is "
						"being used on a E1 CCS span"
						"\n");
					break;
				case DAHDI_SIG_FXSKS:
				case DAHDI_SIG_FXSLS:
				case DAHDI_SIG_FXSGS:
					fprintf(stderr, "\tFXS signaling is "
						"being used on a FXS interface"
						" (use a FXO signaling variant"
						")\n");
					fprintf(stderr, "\tRBS signaling is "
						"being used on a E1 CCS span"
						"\n");
					break;
				case DAHDI_SIG_EM:
					fprintf(stderr, "\te&m signaling is "
						"being used on a E1 line (use"
						" e&me1)\n");
					break;
				case DAHDI_SIG_EM_E1:
					fprintf(stderr, "\te&me1 signaling is "
						"being used on a T1 line (use "
						"e&m)\n");
					fprintf(stderr, "\tRBS signaling is "
						"being used on a E1 CCS span"
						"\n");
					break;
				case DAHDI_SIG_HARDHDLC:
					fprintf(stderr, "\thardhdlc is being "
						"used on a TE12x (use dchan)\n"
						);
					break;
				case DAHDI_SIG_HDLCFCS:
					fprintf(stderr, "\tdchan is being used"
						" on a BRI span (use hardhdlc)"
						"\n");
					break;
				default:
					break;
				}
				fprintf(stderr, "\tSignaling is being assigned"
					" to channel 16 of an E1 CAS span\n");
			}
			close(fd);
			exit(1);
		}

		ae[x].chan = x;
		if (verbose) {
			printf("Setting echocan for channel %d to %s\n", ae[x].chan, ae[x].echocan[0] ? ae[x].echocan : "none");
		}

		if (ioctl(fd, DAHDI_ATTACH_ECHOCAN, &ae[x])) {
			fprintf(stderr, "DAHDI_ATTACH_ECHOCAN failed on channel %d: %s (%d)\n", x, strerror(errno), errno);
			close(fd);
			exit(1);
		}
	}
Exemple #3
0
static void printconfig(int fd)
{
	int x,y;
	int ps;
	int configs=0;
	struct dahdi_versioninfo vi;

	strcpy(vi.version, "Unknown");
	strcpy(vi.echo_canceller, "Unknown");

	if (ioctl(fd, DAHDI_GETVERSION, &vi))
		error("Unable to read DAHDI version information.\n");

	printf("\nDAHDI Version: %s\n"
	       "Echo Canceller(s): %s\n"
	       "Configuration\n"
	       "======================\n\n", vi.version, vi.echo_canceller);
	for (x = 0; x < spans; x++) {
		if (only_span && only_span != lc[x].span)
			continue;
		printf("SPAN %d: %3s/%4s Build-out: %s\n",
		       lc[x].span,
		       (lc[x].lineconfig & DAHDI_CONFIG_D4 ? "D4" :
			lc[x].lineconfig & DAHDI_CONFIG_ESF ? "ESF" :
			lc[x].lineconfig & DAHDI_CONFIG_CCS ? "CCS" : "CAS"),
		       (lc[x].lineconfig & DAHDI_CONFIG_AMI ? "AMI" :
			lc[x].lineconfig & DAHDI_CONFIG_B8ZS ? "B8ZS" :
			lc[x].lineconfig & DAHDI_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<DAHDI_MAX_CHANNELS;x++) {
			if (skip_channel(x))
				continue;
			if ((cc[x].sigtype != DAHDI_SIG_SLAVE) && (cc[x].sigtype)) {
				configs++;
				ps = 0;
				if ((cc[x].sigtype & __DAHDI_SIG_DACS) == __DAHDI_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]);
					printf(" (Echo Canceler: %s)", ae[x].echocan[0] ? ae[x].echocan : "none");
					for (y=1;y<DAHDI_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<DAHDI_MAX_CHANNELS;x++) {
			if (skip_channel(x))
				continue;
			if (cc[x].sigtype)
				configs++;
		}
	}
	printf("\n%d channels to configure.\n\n", configs);
}