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@digium.com>
Signed-off-by: Russ Meyerriecks <rmeyerriecks@digium.com>
This commit is contained in:
Shaun Ruffell 2013-05-09 10:34:20 -05:00 committed by Russ Meyerriecks
parent 2889d6afee
commit 8b493f5ee2

View File

@ -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);