1998-12-27 21:47:14 +00:00
|
|
|
/*
|
1999-03-07 16:12:47 +00:00
|
|
|
* Copyright (c) 1997, 1999 Hellmuth Michaelis. All rights reserved.
|
1998-12-27 21:47:14 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*---------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* isdntelctl - i4b set telephone interface options
|
|
|
|
* ------------------------------------------------
|
|
|
|
*
|
1999-12-14 21:14:28 +00:00
|
|
|
* $Id: main.c,v 1.12 1999/12/13 21:25:26 hm Exp $
|
|
|
|
*
|
1999-08-28 01:35:59 +00:00
|
|
|
* $FreeBSD$
|
1998-12-27 21:47:14 +00:00
|
|
|
*
|
1999-12-14 21:14:28 +00:00
|
|
|
* last edit-date: [Mon Dec 13 21:54:50 1999]
|
1998-12-27 21:47:14 +00:00
|
|
|
*
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
1999-05-20 10:14:57 +00:00
|
|
|
#include <machine/i4b_ioctl.h>
|
1998-12-27 21:47:14 +00:00
|
|
|
#include <machine/i4b_tel_ioctl.h>
|
|
|
|
|
|
|
|
static void usage ( void );
|
|
|
|
|
|
|
|
#define I4BTELDEVICE "/dev/i4btel"
|
|
|
|
|
|
|
|
int opt_get = 0;
|
|
|
|
int opt_unit = 0;
|
|
|
|
int opt_U = 0;
|
|
|
|
int opt_A = 0;
|
|
|
|
int opt_C = 0;
|
1999-05-20 10:14:57 +00:00
|
|
|
int opt_N = 0;
|
1998-12-27 21:47:14 +00:00
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* program entry
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
int ret;
|
|
|
|
int telfd;
|
|
|
|
char namebuffer[128];
|
|
|
|
|
1999-06-24 06:43:21 +00:00
|
|
|
while ((c = getopt(argc, argv, "cgu:AUN")) != -1)
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
|
|
|
switch(c)
|
|
|
|
{
|
|
|
|
case 'c':
|
|
|
|
opt_C = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'g':
|
|
|
|
opt_get = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'u':
|
|
|
|
opt_unit = atoi(optarg);
|
|
|
|
if(opt_unit < 0 || opt_unit > 9)
|
|
|
|
usage();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'A':
|
|
|
|
opt_A = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'U':
|
|
|
|
opt_U = 1;
|
|
|
|
break;
|
|
|
|
|
1999-05-20 10:14:57 +00:00
|
|
|
case 'N':
|
|
|
|
opt_N = 1;
|
1999-03-07 16:12:47 +00:00
|
|
|
break;
|
|
|
|
|
1998-12-27 21:47:14 +00:00
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-05-20 10:14:57 +00:00
|
|
|
if(opt_get == 0 && opt_N == 0 && opt_U == 0 && opt_A == 0 && opt_C == 0)
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
|
|
|
opt_get = 1;
|
|
|
|
}
|
|
|
|
|
1999-05-20 10:14:57 +00:00
|
|
|
if((opt_get + opt_N + opt_U + opt_A + opt_C) > 1)
|
1998-12-27 21:47:14 +00:00
|
|
|
{
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf(namebuffer,"%s%d", I4BTELDEVICE, opt_unit);
|
|
|
|
|
|
|
|
if((telfd = open(namebuffer, O_RDWR)) < 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "isdntelctl: cannot open %s: %s\n", namebuffer, strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(opt_get)
|
|
|
|
{
|
|
|
|
int format;
|
|
|
|
|
|
|
|
if((ret = ioctl(telfd, I4B_TEL_GETAUDIOFMT, &format)) < 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ioctl I4B_TEL_GETAUDIOFMT failed: %s", strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(format == CVT_NONE)
|
|
|
|
{
|
1999-05-20 10:14:57 +00:00
|
|
|
printf("device %s does not do A-law/u-law format conversion\n", namebuffer);
|
1998-12-27 21:47:14 +00:00
|
|
|
}
|
|
|
|
else if(format == CVT_ALAW2ULAW)
|
|
|
|
{
|
1999-05-20 10:14:57 +00:00
|
|
|
printf("device %s does ISDN: A-law -> user: u-law format conversion\n", namebuffer);
|
1998-12-27 21:47:14 +00:00
|
|
|
}
|
1999-05-20 10:14:57 +00:00
|
|
|
else if(format == CVT_ULAW2ALAW)
|
1999-03-07 16:12:47 +00:00
|
|
|
{
|
1999-05-20 10:14:57 +00:00
|
|
|
printf("device %s does ISDN: u-law -> user: A-law format conversion\n", namebuffer);
|
1999-03-07 16:12:47 +00:00
|
|
|
}
|
1998-12-27 21:47:14 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("ERROR, device %s uses unknown format %d!\n", namebuffer, format);
|
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(opt_A)
|
|
|
|
{
|
1999-05-20 10:14:57 +00:00
|
|
|
int format = CVT_ALAW2ULAW;
|
1998-12-27 21:47:14 +00:00
|
|
|
|
|
|
|
if((ret = ioctl(telfd, I4B_TEL_SETAUDIOFMT, &format)) < 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ioctl I4B_TEL_SETAUDIOFMT failed: %s", strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(opt_U)
|
|
|
|
{
|
1999-05-20 10:14:57 +00:00
|
|
|
int format = CVT_ULAW2ALAW;
|
1998-12-27 21:47:14 +00:00
|
|
|
|
|
|
|
if((ret = ioctl(telfd, I4B_TEL_SETAUDIOFMT, &format)) < 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ioctl I4B_TEL_SETAUDIOFMT failed: %s", strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
1999-05-20 10:14:57 +00:00
|
|
|
if(opt_N)
|
1999-03-07 16:12:47 +00:00
|
|
|
{
|
1999-05-20 10:14:57 +00:00
|
|
|
int format = CVT_NONE;
|
1999-03-07 16:12:47 +00:00
|
|
|
|
|
|
|
if((ret = ioctl(telfd, I4B_TEL_SETAUDIOFMT, &format)) < 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ioctl I4B_TEL_SETAUDIOFMT failed: %s", strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
1998-12-27 21:47:14 +00:00
|
|
|
if(opt_C)
|
|
|
|
{
|
|
|
|
int dummy;
|
|
|
|
if((ret = ioctl(telfd, I4B_TEL_EMPTYINPUTQUEUE, &dummy)) < 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ioctl I4B_TEL_EMPTYINPUTQUEUE failed: %s", strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
|
|
* usage display and exit
|
|
|
|
*---------------------------------------------------------------------------*/
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "\n");
|
1999-05-20 10:14:57 +00:00
|
|
|
fprintf(stderr, "isdntelctl - /dev/i4btel control, version %d.%d.%d (%s %s)\n",VERSION, REL, STEP, __DATE__, __TIME__);
|
|
|
|
fprintf(stderr, "usage: isdntelctl -c -g -u <unit> -A -N -U\n");
|
|
|
|
fprintf(stderr, " -c clear input queue\n");
|
1998-12-27 21:47:14 +00:00
|
|
|
fprintf(stderr, " -g get current settings\n");
|
|
|
|
fprintf(stderr, " -u unit specify unit number\n");
|
1999-05-20 10:14:57 +00:00
|
|
|
fprintf(stderr, " -A set conversion ISDN: A-law -> user: u-law\n");
|
|
|
|
fprintf(stderr, " -U set conversion ISDN: u-law -> user: A-law\n");
|
|
|
|
fprintf(stderr, " -N set conversion to no A-law/u-law conversion\n");
|
1998-12-27 21:47:14 +00:00
|
|
|
fprintf(stderr, "\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|