2001-01-06 18:25:05 +00:00
|
|
|
/* $Id: iprofd.c,v 1.9 2001/01/06 18:25:05 kai Exp $
|
1997-02-21 13:18:27 +00:00
|
|
|
|
1997-02-17 00:08:36 +00:00
|
|
|
* Daemon for saving ttyIx-profiles to a file.
|
|
|
|
*
|
1999-09-06 08:03:23 +00:00
|
|
|
* Copyright 1994,95 by Fritz Elfert (fritz@isdn4linux.de)
|
1997-02-17 00:08:36 +00:00
|
|
|
* Copyright 1995 Thinking Objects Software GmbH Wuerzburg
|
|
|
|
*
|
|
|
|
* This file is part of Isdn4Linux.
|
1997-02-21 13:18:27 +00:00
|
|
|
*
|
1997-02-17 00:08:36 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
1997-02-21 13:18:27 +00:00
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
1997-02-17 00:08:36 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define SIGNATURE "iprofd%02x"
|
|
|
|
#define SIGLEN 9
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <signal.h>
|
2001-01-06 18:25:05 +00:00
|
|
|
#include <string.h>
|
|
|
|
//#include <linux/isdn.h>
|
1997-02-17 00:08:36 +00:00
|
|
|
|
|
|
|
typedef unsigned char uchar;
|
|
|
|
|
1997-02-21 13:18:27 +00:00
|
|
|
int isdnctrl_fd;
|
1997-02-17 00:08:36 +00:00
|
|
|
char *modemsettings;
|
|
|
|
|
2001-01-06 18:25:05 +00:00
|
|
|
#define IIOCSIGPRF _IO('I',14)
|
|
|
|
#define IIOCGETPRF _IO('I',15)
|
|
|
|
#define IIOCSETPRF _IO('I',16)
|
|
|
|
#define IIOCGETDVR _IO('I',22)
|
|
|
|
|
|
|
|
#define ISDN_MAX_CHANNELS 64
|
1998-07-22 19:07:13 +00:00
|
|
|
|
2001-01-06 18:25:05 +00:00
|
|
|
#define ISDN_LMSNLEN_4 0
|
|
|
|
#define ISDN_LMSNLEN_5 255
|
|
|
|
#define ISDN_LMSNLEN_6 255
|
2000-03-03 12:45:53 +00:00
|
|
|
|
2001-01-06 18:25:05 +00:00
|
|
|
#define ISDN_MSNLEN_4 20
|
|
|
|
#define ISDN_MSNLEN_5 20
|
|
|
|
#define ISDN_MSNLEN_6 32
|
|
|
|
|
|
|
|
#define ISDN_MODEM_NUMREG_4 23
|
|
|
|
#define ISDN_MODEM_NUMREG_5 24
|
|
|
|
#define ISDN_MODEM_NUMREG_6 24
|
|
|
|
|
|
|
|
#define BUFSZ_4 ((ISDN_MODEM_NUMREG_4+ISDN_MSNLEN_4+ISDN_LMSNLEN_4)*ISDN_MAX_CHANNELS)
|
|
|
|
#define BUFSZ_5 ((ISDN_MODEM_NUMREG_5+ISDN_MSNLEN_5+ISDN_LMSNLEN_5)*ISDN_MAX_CHANNELS)
|
|
|
|
#define BUFSZ_6 ((ISDN_MODEM_NUMREG_6+ISDN_MSNLEN_6+ISDN_LMSNLEN_6)*ISDN_MAX_CHANNELS)
|
|
|
|
|
|
|
|
int bufsz;
|
|
|
|
int tty_dv;
|
1997-02-17 00:08:36 +00:00
|
|
|
|
|
|
|
void
|
1997-02-21 13:18:27 +00:00
|
|
|
dumpModem(int dummy)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
int len;
|
2001-01-06 18:25:05 +00:00
|
|
|
char buffer[bufsz];
|
1997-02-21 13:18:27 +00:00
|
|
|
char signature[SIGLEN];
|
1997-02-17 00:08:36 +00:00
|
|
|
|
1997-02-21 13:18:27 +00:00
|
|
|
if ((len = ioctl(isdnctrl_fd, IIOCGETPRF, &buffer)) < 0) {
|
|
|
|
perror("ioctl IIOCGETPRF");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
fd = open(modemsettings, O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
|
|
|
if (fd < 0) {
|
|
|
|
perror(modemsettings);
|
|
|
|
exit(-1);
|
|
|
|
}
|
2001-01-06 18:25:05 +00:00
|
|
|
sprintf(signature, SIGNATURE, tty_dv);
|
1997-02-21 13:18:27 +00:00
|
|
|
write(fd, signature, sizeof(signature));
|
|
|
|
write(fd, buffer, len);
|
|
|
|
close(fd);
|
|
|
|
signal(SIGIO, dumpModem);
|
1997-02-17 00:08:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1997-02-21 13:18:27 +00:00
|
|
|
readModem(void)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
int fd;
|
2001-01-06 18:25:05 +00:00
|
|
|
char buffer[bufsz];
|
1997-02-21 13:18:27 +00:00
|
|
|
char signature[SIGLEN];
|
1997-02-17 00:08:36 +00:00
|
|
|
|
2001-01-06 18:25:05 +00:00
|
|
|
sprintf(signature, SIGNATURE, tty_dv);
|
1997-02-21 13:18:27 +00:00
|
|
|
fd = open(modemsettings, O_RDONLY);
|
|
|
|
if (fd < 0)
|
|
|
|
return;
|
|
|
|
len = read(fd, buffer, sizeof(signature));
|
|
|
|
if (len < 0) {
|
|
|
|
perror(modemsettings);
|
|
|
|
exit(-1);
|
|
|
|
}
|
2001-01-06 18:25:05 +00:00
|
|
|
if (len == 0) { /* empty file, ignore it */
|
|
|
|
close(fd);
|
|
|
|
return;
|
|
|
|
}
|
1997-02-21 13:18:27 +00:00
|
|
|
if (strcmp(buffer, signature)) {
|
2001-01-06 18:25:05 +00:00
|
|
|
fprintf(stderr, "Currently running kernel does NOT match\n");
|
1997-02-21 13:18:27 +00:00
|
|
|
fprintf(stderr, "signature of saved data!\n");
|
|
|
|
fprintf(stderr, "Profiles NOT restored, use AT&W0 to update data.\n");
|
|
|
|
close(fd);
|
|
|
|
return;
|
|
|
|
}
|
2001-01-06 18:25:05 +00:00
|
|
|
len = read(fd, buffer, bufsz);
|
1997-02-21 13:18:27 +00:00
|
|
|
if (len < 0) {
|
|
|
|
perror(modemsettings);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
if (ioctl(isdnctrl_fd, IIOCSETPRF, &buffer) < 0) {
|
|
|
|
perror("ioctl IIOCSETPRF");
|
|
|
|
exit(-1);
|
|
|
|
}
|
1997-02-17 00:08:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1997-02-21 13:18:27 +00:00
|
|
|
usage(void)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "usage: iprofd <IsdnModemProfile>\n");
|
|
|
|
exit(-1);
|
1997-02-17 00:08:36 +00:00
|
|
|
}
|
|
|
|
|
1998-04-28 08:33:52 +00:00
|
|
|
int
|
1997-02-21 13:18:27 +00:00
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
1997-02-17 00:08:36 +00:00
|
|
|
|
1997-02-21 13:18:27 +00:00
|
|
|
int data_version;
|
1997-02-17 00:08:36 +00:00
|
|
|
|
1997-02-21 13:18:27 +00:00
|
|
|
if (argc != 2)
|
|
|
|
usage();
|
|
|
|
modemsettings = argv[1];
|
|
|
|
isdnctrl_fd = open("/dev/isdninfo", O_RDWR);
|
|
|
|
if (isdnctrl_fd < 0) {
|
|
|
|
perror("/dev/isdninfo");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
data_version = ioctl(isdnctrl_fd, IIOCGETDVR, 0);
|
|
|
|
if (data_version < 0) {
|
|
|
|
fprintf(stderr, "Could not get version of kernel modem-profile!\n");
|
|
|
|
fprintf(stderr, "Make sure, you are using the correct version.\n");
|
|
|
|
fprintf(stderr, "(Try recompiling iprofd).\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
close(isdnctrl_fd);
|
2001-01-06 18:25:05 +00:00
|
|
|
tty_dv = data_version & 0xff;
|
|
|
|
switch (tty_dv) {
|
|
|
|
case 4:
|
|
|
|
bufsz = BUFSZ_4;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
bufsz = BUFSZ_5;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
bufsz = BUFSZ_6;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "Version of kernel modem-profile (%d) is NOT handled\n",
|
|
|
|
tty_dv);
|
|
|
|
fprintf(stderr, "by this version of iprofd!\n");
|
|
|
|
fprintf(stderr, "(Try to get the latest version).\n");
|
1997-02-21 13:18:27 +00:00
|
|
|
exit(-1);
|
|
|
|
}
|
2001-01-06 18:25:05 +00:00
|
|
|
|
1997-02-21 13:18:27 +00:00
|
|
|
isdnctrl_fd = open("/dev/isdnctrl", O_RDONLY);
|
|
|
|
if (isdnctrl_fd < 0) {
|
|
|
|
perror("/dev/isdninfo");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
readModem();
|
|
|
|
switch (fork()) {
|
|
|
|
case -1:
|
|
|
|
perror("fork");
|
|
|
|
exit(-1);
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
dumpModem(0);
|
|
|
|
if (ioctl(isdnctrl_fd, IIOCSIGPRF, 0)) {
|
|
|
|
perror("ioctl IIOCSIGPRF");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
while (1)
|
|
|
|
sleep(1000);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1998-04-28 08:33:52 +00:00
|
|
|
return 0;
|
1997-02-17 00:08:36 +00:00
|
|
|
}
|