tools: Allow pattern tools to access channels above the device file limit
pattest and patgen already had this capability, but there were cases in which they would act unexpectedly. Now, if the name specified is not a character device file, it will be treated as a channel number if possible. Acked-by: Shaun Ruffell <sruffell@digium.com> git-svn-id: http://svn.astersk.org/svn/dahdi/tools/trunk@9975 17933a7a-c749-41c5-a318-cba88f637d49
This commit is contained in:
parent
49a5fbfcd2
commit
178ae27825
49
patgen.c
49
patgen.c
@ -33,6 +33,7 @@
|
|||||||
#include <linux/types.h>
|
#include <linux/types.h>
|
||||||
#include <linux/ppp_defs.h>
|
#include <linux/ppp_defs.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "bittest.h"
|
#include "bittest.h"
|
||||||
@ -65,30 +66,40 @@ void print_packet(unsigned char *buf, int len)
|
|||||||
printf("}\n");
|
printf("}\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int channel_open(char *name, int *bs)
|
int channel_open(const char *name, int *bs)
|
||||||
{
|
{
|
||||||
int channo;
|
int channo, fd;
|
||||||
int fd;
|
struct dahdi_params tp;
|
||||||
struct dahdi_params tp;
|
struct stat filestat;
|
||||||
char *dev;
|
|
||||||
|
|
||||||
channo = atoi(name);
|
/* stat file, if character device, open it */
|
||||||
/* channo==0: The user passed a file name to be opened. */
|
channo = strtoul(name, NULL, 10);
|
||||||
dev = channo ? DEVICE : name;
|
fd = stat(name, &filestat);
|
||||||
|
if (!fd && S_ISCHR(filestat.st_mode)) {
|
||||||
fd = open(dev, O_RDWR, 0600);
|
fd = open(name, O_RDWR, 0600);
|
||||||
|
if (fd < 0) {
|
||||||
if (fd < 0) {
|
perror(name);
|
||||||
perror(DEVICE);
|
return -1;
|
||||||
|
}
|
||||||
|
/* try out the dahdi_specify interface */
|
||||||
|
} else if (channo > 0) {
|
||||||
|
fd = open(DEVICE, O_RDWR, 0600);
|
||||||
|
if (fd < 0) {
|
||||||
|
perror(DEVICE);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (ioctl(fd, DAHDI_SPECIFY, &channo) < 0) {
|
||||||
|
perror("DAHDI_SPECIFY ioctl failed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
/* die */
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Specified channel is not a valid character "
|
||||||
|
"device or channel number");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we got a channel number, get it from /dev/dahdi/channel: */
|
if (ioctl(fd, DAHDI_SET_BLOCKSIZE, bs) < 0) {
|
||||||
if(channo && ioctl(fd, DAHDI_SPECIFY, &channo) < 0) {
|
|
||||||
perror("SPECIFY");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if(ioctl(fd, DAHDI_SET_BLOCKSIZE, bs) < 0) {
|
|
||||||
perror("SET_BLOCKSIZE");
|
perror("SET_BLOCKSIZE");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
@ -47,6 +48,7 @@
|
|||||||
#include "dahdi_tools_version.h"
|
#include "dahdi_tools_version.h"
|
||||||
|
|
||||||
#define BLOCK_SIZE 2039
|
#define BLOCK_SIZE 2039
|
||||||
|
#define DEVICE "/dev/dahdi/channel"
|
||||||
|
|
||||||
#define CONTEXT_SIZE 7
|
#define CONTEXT_SIZE 7
|
||||||
/* Prints a set of bytes in hex format */
|
/* Prints a set of bytes in hex format */
|
||||||
@ -97,12 +99,57 @@ static void usage(const char * progname)
|
|||||||
printf("\n\t Also accepts old style usage:\n\t %s <device name> [<timeout in secs>]\n", progname);
|
printf("\n\t Also accepts old style usage:\n\t %s <device name> [<timeout in secs>]\n", progname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int channel_open(const char *name, int *bs)
|
||||||
|
{
|
||||||
|
int channo, fd;
|
||||||
|
struct dahdi_params tp;
|
||||||
|
struct stat filestat;
|
||||||
|
|
||||||
|
/* stat file, if character device, open it */
|
||||||
|
channo = strtoul(name, NULL, 10);
|
||||||
|
fd = stat(name, &filestat);
|
||||||
|
if (!fd && S_ISCHR(filestat.st_mode)) {
|
||||||
|
fd = open(name, O_RDWR, 0600);
|
||||||
|
if (fd < 0) {
|
||||||
|
perror(name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
/* try out the dahdi_specify interface */
|
||||||
|
} else if (channo > 0) {
|
||||||
|
fd = open(DEVICE, O_RDWR, 0600);
|
||||||
|
if (fd < 0) {
|
||||||
|
perror(DEVICE);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (ioctl(fd, DAHDI_SPECIFY, &channo) < 0) {
|
||||||
|
perror("DAHDI_SPECIFY ioctl failed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
/* die */
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Specified channel is not a valid character "
|
||||||
|
"device or channel number");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ioctl(fd, DAHDI_SET_BLOCKSIZE, bs) < 0) {
|
||||||
|
perror("SET_BLOCKSIZE");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ioctl(fd, DAHDI_GET_PARAMS, &tp)) {
|
||||||
|
fprintf(stderr, "Unable to get channel parameters\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
int res, x;
|
int res, x;
|
||||||
int i;
|
int i;
|
||||||
struct dahdi_params tp;
|
|
||||||
int bs = BLOCK_SIZE;
|
int bs = BLOCK_SIZE;
|
||||||
int skipcount = 10;
|
int skipcount = 10;
|
||||||
unsigned char c=0,c1=0;
|
unsigned char c=0,c1=0;
|
||||||
@ -173,19 +220,9 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
time_t start_time = 0;
|
time_t start_time = 0;
|
||||||
|
|
||||||
fd = open(device, O_RDWR, 0600);
|
fd = channel_open(device, &bs);
|
||||||
if (fd < 0) {
|
if (fd < 0)
|
||||||
fprintf(stderr, "Unable to open %s: %s\n", device, strerror(errno));
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
|
||||||
if (ioctl(fd, DAHDI_SET_BLOCKSIZE, &bs)) {
|
|
||||||
fprintf(stderr, "Unable to set block size to %d: %s\n", bs, strerror(errno));
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
if (ioctl(fd, DAHDI_GET_PARAMS, &tp)) {
|
|
||||||
fprintf(stderr, "Unable to get channel parameters\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
ioctl(fd, DAHDI_GETEVENT);
|
ioctl(fd, DAHDI_GETEVENT);
|
||||||
|
|
||||||
i = DAHDI_FLUSH_ALL;
|
i = DAHDI_FLUSH_ALL;
|
||||||
@ -299,3 +336,4 @@ read_again:
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
49
pattest.c
49
pattest.c
@ -33,6 +33,7 @@
|
|||||||
#include <linux/types.h>
|
#include <linux/types.h>
|
||||||
#include <linux/ppp_defs.h>
|
#include <linux/ppp_defs.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "bittest.h"
|
#include "bittest.h"
|
||||||
@ -64,30 +65,40 @@ void print_packet(unsigned char *buf, int len)
|
|||||||
printf("}\n");
|
printf("}\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int channel_open(char *name, int *bs)
|
int channel_open(const char *name, int *bs)
|
||||||
{
|
{
|
||||||
int channo;
|
int channo, fd;
|
||||||
int fd;
|
struct dahdi_params tp;
|
||||||
struct dahdi_params tp;
|
struct stat filestat;
|
||||||
char *dev;
|
|
||||||
|
|
||||||
channo = atoi(name);
|
/* stat file, if character device, open it */
|
||||||
/* channo==0: The user passed a file name to be opened. */
|
channo = strtoul(name, NULL, 10);
|
||||||
dev = channo ? DEVICE : name;
|
fd = stat(name, &filestat);
|
||||||
|
if (!fd && S_ISCHR(filestat.st_mode)) {
|
||||||
fd = open(dev, O_RDWR, 0600);
|
fd = open(name, O_RDWR, 0600);
|
||||||
|
if (fd < 0) {
|
||||||
if (fd < 0) {
|
perror(name);
|
||||||
perror(DEVICE);
|
return -1;
|
||||||
|
}
|
||||||
|
/* try out the dahdi_specify interface */
|
||||||
|
} else if (channo > 0) {
|
||||||
|
fd = open(DEVICE, O_RDWR, 0600);
|
||||||
|
if (fd < 0) {
|
||||||
|
perror(DEVICE);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (ioctl(fd, DAHDI_SPECIFY, &channo) < 0) {
|
||||||
|
perror("DAHDI_SPECIFY ioctl failed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
/* die */
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Specified channel is not a valid character "
|
||||||
|
"device or channel number");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we got a channel number, get it from /dev/dahdi/channel: */
|
if (ioctl(fd, DAHDI_SET_BLOCKSIZE, bs) < 0) {
|
||||||
if(channo && ioctl(fd, DAHDI_SPECIFY, &channo) < 0) {
|
|
||||||
perror("SPECIFY");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if(ioctl(fd, DAHDI_SET_BLOCKSIZE, bs) < 0) {
|
|
||||||
perror("SET_BLOCKSIZE");
|
perror("SET_BLOCKSIZE");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user