1/* 2 * Copyright (c) 1997, 1999 Hellmuth Michaelis. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 * SUCH DAMAGE. 24 * 25 *--------------------------------------------------------------------------- 26 * 27 * isdntelctl - i4b set telephone interface options 28 * ------------------------------------------------ 29 * 30 * $Id: main.c,v 1.7 2011/08/31 13:32:37 joerg Exp $ 31 * 32 * $FreeBSD$ 33 * 34 * last edit-date: [Sat Jan 6 13:05:22 2001] 35 * 36 *---------------------------------------------------------------------------*/ 37 38#include <stdio.h> 39#include <signal.h> 40#include <errno.h> 41#include <string.h> 42#include <stdlib.h> 43#include <unistd.h> 44#include <fcntl.h> 45#include <ctype.h> 46#include <sys/stat.h> 47#include <sys/wait.h> 48#include <sys/ioctl.h> 49#include <sys/types.h> 50#include <sys/time.h> 51 52#include <netisdn/i4b_ioctl.h> 53#include <netisdn/i4b_tel_ioctl.h> 54 55__dead static void usage ( void ); 56 57#define I4BTELDEVICE "/dev/isdntel" 58 59int opt_get = 0; 60int opt_unit = 0; 61int opt_U = 0; 62int opt_A = 0; 63int opt_C = 0; 64int opt_N = 0; 65 66/*---------------------------------------------------------------------------* 67 * program entry 68 *---------------------------------------------------------------------------*/ 69int 70main(int argc, char **argv) 71{ 72 int c; 73 int ret; 74 int telfd; 75 char namebuffer[128]; 76 77 while ((c = getopt(argc, argv, "cgu:AUN")) != -1) 78 { 79 switch (c) 80 { 81 case 'c': 82 opt_C = 1; 83 break; 84 85 case 'g': 86 opt_get = 1; 87 break; 88 89 case 'u': 90 opt_unit = atoi(optarg); 91 if (opt_unit < 0 || opt_unit > 9) 92 usage(); 93 break; 94 95 case 'A': 96 opt_A = 1; 97 break; 98 99 case 'U': 100 opt_U = 1; 101 break; 102 103 case 'N': 104 opt_N = 1; 105 break; 106 107 case '?': 108 default: 109 usage(); 110 break; 111 } 112 } 113 114 if (opt_get == 0 && opt_N == 0 && opt_U == 0 && opt_A == 0 && opt_C == 0) 115 { 116 opt_get = 1; 117 } 118 119 if ((opt_get + opt_N + opt_U + opt_A + opt_C) > 1) 120 { 121 usage(); 122 } 123 124 snprintf(namebuffer, sizeof(namebuffer), "%s%d", I4BTELDEVICE, opt_unit); 125 126 if ((telfd = open(namebuffer, O_RDWR)) < 0) 127 { 128 fprintf(stderr, "isdntelctl: cannot open %s: %s\n", namebuffer, strerror(errno)); 129 exit(1); 130 } 131 132 if (opt_get) 133 { 134 int format; 135 136 if ((ret = ioctl(telfd, I4B_TEL_GETAUDIOFMT, &format)) < 0) 137 { 138 fprintf(stderr, "ioctl I4B_TEL_GETAUDIOFMT failed: %s", strerror(errno)); 139 exit(1); 140 } 141 142 if (format == CVT_NONE) 143 { 144 printf("device %s does not do A-law/mu-law format conversion\n", namebuffer); 145 } 146 else if (format == CVT_ALAW2ULAW) 147 { 148 printf("device %s does ISDN: A-law -> user: mu-law format conversion\n", namebuffer); 149 } 150 else if (format == CVT_ULAW2ALAW) 151 { 152 printf("device %s does ISDN: mu-law -> user: A-law format conversion\n", namebuffer); 153 } 154 else 155 { 156 printf("ERROR, device %s uses unknown format %d!\n", namebuffer, format); 157 } 158 exit(0); 159 } 160 161 if (opt_A) 162 { 163 int format = CVT_ALAW2ULAW; 164 165 if ((ret = ioctl(telfd, I4B_TEL_SETAUDIOFMT, &format)) < 0) 166 { 167 fprintf(stderr, "ioctl I4B_TEL_SETAUDIOFMT failed: %s", strerror(errno)); 168 exit(1); 169 } 170 exit(0); 171 } 172 173 if (opt_U) 174 { 175 int format = CVT_ULAW2ALAW; 176 177 if ((ret = ioctl(telfd, I4B_TEL_SETAUDIOFMT, &format)) < 0) 178 { 179 fprintf(stderr, "ioctl I4B_TEL_SETAUDIOFMT failed: %s", strerror(errno)); 180 exit(1); 181 } 182 exit(0); 183 } 184 if (opt_N) 185 { 186 int format = CVT_NONE; 187 188 if ((ret = ioctl(telfd, I4B_TEL_SETAUDIOFMT, &format)) < 0) 189 { 190 fprintf(stderr, "ioctl I4B_TEL_SETAUDIOFMT failed: %s", strerror(errno)); 191 exit(1); 192 } 193 exit(0); 194 } 195 if (opt_C) 196 { 197 int dummy; 198 if ((ret = ioctl(telfd, I4B_TEL_EMPTYINPUTQUEUE, &dummy)) < 0) 199 { 200 fprintf(stderr, "ioctl I4B_TEL_EMPTYINPUTQUEUE failed: %s", strerror(errno)); 201 exit(1); 202 } 203 exit(0); 204 } 205 return(0); 206} 207 208/*---------------------------------------------------------------------------* 209 * usage display and exit 210 *---------------------------------------------------------------------------*/ 211static void 212usage(void) 213{ 214 fprintf(stderr, "\n"); 215 fprintf(stderr, "isdntelctl - /dev/isdntel control, version %d.%d.%d\n",VERSION, REL, STEP); 216 fprintf(stderr, "usage: isdntelctl -c -g -u <unit> -A -N -U\n"); 217 fprintf(stderr, " -c clear input queue\n"); 218 fprintf(stderr, " -g get current settings\n"); 219 fprintf(stderr, " -u unit specify unit number\n"); 220 fprintf(stderr, " -A set conversion ISDN: A-law -> user: mu-law\n"); 221 fprintf(stderr, " -U set conversion ISDN: mu-law -> user: A-law\n"); 222 fprintf(stderr, " -N set conversion to no A-law/mu-law conversion\n"); 223 fprintf(stderr, "\n"); 224 exit(1); 225} 226 227/* EOF */ 228