[Pkg-voip-commits] [dahdi-tools] 107/285: fxotune: Use DAHDI_SPECIFY when opening by integer channel number.

tzafrir at debian.org tzafrir at debian.org
Thu Jul 7 19:18:39 UTC 2016


This is an automated email from the git hooks/post-receive script.

tzafrir pushed a commit to branch master
in repository dahdi-tools.

commit 8b493f5ee20e13055c4139dccff3ce127ddd51bd
Author: Shaun Ruffell <sruffell at digium.com>
Date:   Thu May 9 10:34:20 2013 -0500

    fxotune: Use DAHDI_SPECIFY when opening by integer channel number.
    
    In DAHDI-Linux 2.7 the layout of the /dev/dahdi files changes so that they are
    grouped by span. When opening channels by number all utilities need to use
    DAHDI_SPECIFY now.
    
    Signed-off-by: Shaun Ruffell <sruffell at digium.com>
    Signed-off-by: Russ Meyerriecks <rmeyerriecks at digium.com>
---
 fxotune.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 64 insertions(+), 15 deletions(-)

diff --git a/fxotune.c b/fxotune.c
index 08a9e9b..530ba21 100644
--- a/fxotune.c
+++ b/fxotune.c
@@ -47,7 +47,6 @@ static float sintable[SINE_SAMPLES];
 
 static const float amplitude = 16384.0;
 
-static char *dahdipath = "/dev/dahdi";
 static char *configfile = "/etc/fxotune.conf";
 
 static int audio_dump_fd = -1;
@@ -913,6 +912,66 @@ retry:
 	return 0;
 }
 
+static int channel_is_fxo(int channo)
+{
+	int res = 0;
+	int fd;
+	const char *CTL_DEV = "/dev/dahdi/ctl";
+	struct dahdi_params params;
+
+	fd = open(CTL_DEV, O_RDWR, 0600);
+	if (-1 == fd) {
+		fprintf(stderr, "Failed to open %s: %s\n",
+			CTL_DEV, strerror(errno));
+		return -1;
+	}
+	params.channo = channo;
+	if (ioctl(fd, DAHDI_GET_PARAMS, &params)) {
+		fprintf(stderr,
+			"%d is not a valid channel number.\n", channo);
+		res = -1;
+	} else if (0 == (__DAHDI_SIG_FXS & params.sigcap)) {
+		fprintf(stderr,
+			"Channel %d is not an FXO port.\n", channo);
+		res = -1;
+	} else if (0 == params.sigtype) {
+		fprintf(stderr,
+			"Cannot run on unconfigured channel %d. Please run dahdi_cfg to configure channels before running fxotune.\n",
+			channo);
+		res = -1;
+	}
+	close(fd);
+	return res;
+}
+
+static int channel_open(int channo)
+{
+	int	fd;
+	const char *DEVICE = "/dev/dahdi/channel";
+
+	if (channo > 0) {
+		if (channel_is_fxo(channo))
+			return -1;
+
+		fd = open(DEVICE, O_RDWR, 0600);
+		if (fd < 0) {
+			perror(DEVICE);
+			return -1;
+		}
+
+		if (ioctl(fd, DAHDI_SPECIFY, &channo) < 0) {
+			perror("DADHI_SPECIFY ioctl failed");
+			close(fd);
+			fd = -1;
+		}
+	} else {
+		fprintf(stderr,
+			"Specified channel is not a valid channel number");
+		fd = -1;
+	}
+	return fd;
+}
+
 /**
  * Reads echo register settings from the configuration file and pushes them into
  * the appropriate devices
@@ -969,11 +1028,8 @@ static int do_set(char *configfilename)
 		mycoefs.coef7 = mycoef7;
 		mycoefs.coef8 = mycoef8;
 	
-		snprintf(completedahdipath, sizeof(completedahdipath), "%s/%d", dahdipath, mydahdi);
-		fd = open(completedahdipath, O_RDWR);
-
+		fd = channel_open(mydahdi);
 		if (fd < 0) {
-			fprintf(stdout, "open error on %s: %s\n", completedahdipath, strerror(errno));
 			return -1;
 		}
 
@@ -1014,11 +1070,8 @@ static int do_dump(int startdev, char* dialstr, int delayuntilsilence, int silen
 	char dahdidev[80] = "";
 	
 	int dahdimodule = startdev;
-	snprintf(dahdidev, sizeof(dahdidev), "%s/%d", dahdipath, dahdimodule);
-
-	fd = open(dahdidev, O_RDWR);
+	fd = channel_open(dahdimodule);
 	if (fd < 0) {
-		fprintf(stdout, "%s absent: %s\n", dahdidev, strerror(errno));
 		return -1;
 	}
 
@@ -1060,7 +1113,6 @@ static int do_calibrate(int startdev, int enddev, int calibtype, char* configfil
 	int res = 0;
 	int configfd, fd;
 	int devno = 0;
-	char dahdidev[80] = "";
 	struct wctdm_echo_coefs coefs;
 	
 	configfd = open(configfile, O_CREAT|O_TRUNC|O_WRONLY, 0666);
@@ -1071,15 +1123,12 @@ static int do_calibrate(int startdev, int enddev, int calibtype, char* configfil
 	}
 
 	for (devno = startdev; devno <= enddev; devno++) {
-		snprintf(dahdidev, sizeof(dahdidev), "%s/%d", dahdipath, devno);
-
-		fd = open(dahdidev, O_RDWR);
+		fd = channel_open(devno);
 		if (fd < 0) {
-			fprintf(stdout, "%s absent: %s\n", dahdidev, strerror(errno));
 			continue;
 		}
 
-		fprintf(stdout, "Tuning module %s\n", dahdidev);
+		fprintf(stdout, "Tuning module %d\n", devno);
 		
 		if (1 == calibtype)
 			res = acim_tune(fd, dialstr, delayuntilsilence, silencegoodfor, &coefs);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-voip/dahdi-tools.git



More information about the Pkg-voip-commits mailing list