added IIOCNETGPN support for 2.0 kernels

s. isdnlog/kernel_2_0/README for more information (isdnlog 4.51)
This commit is contained in:
leo 2001-03-13 14:39:30 +00:00
parent 541536f7a6
commit 7df0c78dda
6 changed files with 284 additions and 4 deletions

View File

@ -1,4 +1,4 @@
## $Id: Makefile.in,v 1.192 2001/01/31 11:58:00 leo Exp $
## $Id: Makefile.in,v 1.193 2001/03/13 14:39:30 leo Exp $
##
## ISDN accounting for isdn4linux.
##
@ -19,6 +19,10 @@
## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
##
## $Log: Makefile.in,v $
## Revision 1.193 2001/03/13 14:39:30 leo
## added IIOCNETGPN support for 2.0 kernels
## s. isdnlog/kernel_2_0/README for more information (isdnlog 4.51)
##
## Revision 1.192 2001/01/31 11:58:00 leo
## Fixed length of Alias in ilp.c
##
@ -1442,7 +1446,7 @@ SERVICEFILE = /etc/services
# DON'T EDIT BELOW THIS LINE
######################################################################
VERSION = 4.50
VERSION = 4.51
MANPAGES = isdnlog/callerid.conf.5 isdnlog/isdn.conf.5 \
isdnlog/isdnformat.5 isdnlog/isdnlog.5 isdnlog/isdnlog.8 \
@ -1496,6 +1500,10 @@ ifdef ILP
DEFS += -DILP=1
endif
ifdef IIOCNETGPN
DEFS += -DIIOCNETGPN=-1
endif
PC = proc
PCFLAGS = mode=oracle ireclen=160 lines=yes
@ -1545,6 +1553,7 @@ ifdef ILP
ISDNLOG_OBJS += isdnlog/ilp/ilp.o
endif
ISDNREP_OBJS = isdnrep/rep_main.o tools/tools.o tools/isdnconf.o \
isdnlog/messages.o isdnrep/isdnrep.o \
tools/rate.o tools/zone.o tools/holiday.o tools/dest.o \
@ -1587,6 +1596,12 @@ endif
all: depend libs mybin progs $(MANPAGES)
ifdef IIOCNETGPN
ISDNLOG_OBJS += isdnlog/kernel_2_0/iiocnetgpn.o
isdnlog/kernel_2_0/iiocnetgpn.o: isdnlog/kernel_2_0/iiocnetgpn.c
cd isdnlog/kernel_2_0 && make
endif
Makefile: Makefile.in config.status
./config.status
@ -1608,6 +1623,9 @@ libs:
clean:
-rm -f $(MODS)
set -e; for i in `echo $(SUBDIRS)`; do $(MAKE) -C $$i clean; done
ifdef IIOCNETGPN
cd isdnlog/kernel_2_0 && make clean
endif
distclean: clean
-rm -f $(MANPAGES)

View File

@ -5,6 +5,10 @@ This file contains summaries for main changes and for new config options.
For details please always consult Makefile.in in this directory.
========================================================================
lt 2001.03.13
added IIOCNETGPN support for kernel 2.0
s. isdnlog/kernel_2_0/README
lt 2000.06.27

View File

@ -0,0 +1,8 @@
# Makefile for iiocnetgpn.c
# look at /usr/src/linux/Makefile for your kernel compiler
#
iiocnetgpn.o: iiocnetgpn.c
cc -c -V2.7.2.3 -O2 -Wall -g -I/usr/src/linux/include iiocnetgpn.c
clean:
rm *.o *~

View File

@ -0,0 +1,45 @@
This is the README for kernel_2_0/iiocnetgpn.c
As my isdnlog 4.50 running on kernel 2.0.36 (isdn ~2.0.38) doesn't
set the huptime always, I wrote this small addition, for usage with
2.0 kernels.
The code is ugly (kernel headers are included, with __KERNEL__ defined,
there are some warnings (which can be ignored), but it seems to work.
You can try the code standalone, look at the file for a short description.
So to use this feature, compile isdnlog with:
touch isdnlog/processor.c
make IIOCNETGPN=1
Before:
isdnlog: to Magnet-N with '' No HUP: HUP = 1 c = 8 *INTERFACE=
(so interface was not found)
After:
isdnlog: (ISDN subsystem with ISDN_MAX_CHANNELS > 16 detected, \
ioctl(IIOCNETGPN) is available)
isdnlog: isdn.conf:2 active channels, 8 MSN/SI entries
isdnlog: (watching "/dev/isdnctrl0" as HFC/echo mode)
isdnlog: (Data versions: iprofd=0x04 net_cfg=0x04 /dev/isdninfo=0x01)
isdnlog: Everything is fine, isdnlog-4.51 is running in full featured mode.
...
isdnlog: to Magnet-N with '' INTERFACE ippp0 calling 071891xxxx
...
isdnlog: to Magnet-N with '' NEXT CI AFTER 03:00 \
(Telekom Austria Min.tarif, Internet, Werktag (Dienstag), Geschäftszeit)
isdnlog: to Magnet-N with '' CHARGEINT ippp0 180 (was 160)
isdnlog: to Magnet-N with '' HUPTIMEOUT ippp0 8 (was 60)
Comments welcome
-lt
Leopold Toetsch <lt@toetsch.at>

View File

@ -0,0 +1,187 @@
/* this implements ioctl(IIOCNETGPN) for 2.0 Kernels in user space
*
* int iiocnetgpn(int isdnctrl_desc, isdn_net_ioctl_phone *phone);
*
*
* Copyright 2001 by Leopold Toetsch <lt@toetsch.at>
*
* 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
*
*
* for standalone testing compile with:
* cc iiocnetgpn -I/usr/src/linux/include -DSTANDALONE -V2.7.2.3 -o iiocnetgpn
* (the compilerversion may be different, look at your kernel Makefile)
*
* referenced files are all in /usr/src/linux/isdn/drivers/isdn
*/
// #include <errno.h>
// #include <unistd.h>
//
extern int errno; /* above generates a lot of errors due to mixing of headers */
#define __KERNEL__
#include <linux/isdn.h>
#undef __KERNEL__
#define SEEK_SET 0
typedef unsigned char uchar;
static int mem_fd;
static isdn_dev *dev;
/* based on debugvar.c */
#if USE_MM /* MM is not working on /dev/kmem */
#include <sys/mman.h>
static ulong msize(long size) {
ulong ps = getpagesize();
return (size / ps + 1) * ps;
}
static uchar * mapmem(ulong location, long size)
{
ulong mmseg;
ulong mmsize;
uchar* addr=0;
ulong offset;
mmseg = location & ~(ps-1);
mmsize = msize(size);
offset = location - mmseg;
addr = (uchar*) mmap(0, mmsize, PROT_READ, MAP_SHARED, mem_fd, mmseg);
if ((int) addr == -1) {
return 0;
}
return ((uchar *) (addr + offset));
}
#else
void *malloc(long);
void free(void*);
static uchar
* mapmem(ulong location, long size)
{
uchar *buffer = 0;
if ((buffer = malloc(size))) {
lseek(mem_fd, location, SEEK_SET);
read(mem_fd, buffer, size);
}
return buffer;
}
#endif
/* based on isdn_common.c */
static int
isdn_dc2minor(int di, int ch)
{
int i;
for (i = 0; i < ISDN_MAX_CHANNELS; i++)
if (dev->chanmap[i] == ch && dev->drvmap[i] == di)
return i;
return -1;
}
/* based on isdn_net.c */
static isdn_net_dev *
isdn_net_findif(char *name)
{
ulong addr = (ulong)dev->netdev;
while (addr) {
isdn_net_dev *p = (isdn_net_dev *) mapmem(addr, sizeof(isdn_net_dev));
if (!strcmp(p->local.name, name))
return p;
addr = (ulong) p->next;
#if USE_MM
munmap(p, msize(sizeof(isdn_net_dev)));
#else
free(p);
#endif
}
return (isdn_net_dev *) NULL;
}
static int getpeer(isdn_net_ioctl_phone *phone)
{
isdn_net_dev *p = isdn_net_findif(phone->name);
int ch, dv, idx;
int ret = 0;
if (!p) return -ENODEV;
ch = p->local.isdn_channel;
dv = p->local.isdn_device;
if(ch<0 && dv<0) return -ENOTCONN;
idx = isdn_dc2minor(dv, ch);
if (idx<0) {
ret = -ENODEV;
goto err;
}
/* for pre-bound channels, we need this extra check */
if ( strncmp(dev->num[idx],"???",3) == 0 ) {
ret= -ENOTCONN;
goto err;
}
strncpy(phone->phone,dev->num[idx],ISDN_MSNLEN);
phone->outgoing=USG_OUTGOING(dev->usage[idx]);
err:
#if USE_MM
munmap(p, msize(sizeof(isdn_net_dev)));
#else
free(p);
#endif
return ret;
}
/* based on debugvar.c */
int iiocnetgpn(int isdnctrl_desc, isdn_net_ioctl_phone *phone) {
ulong kaddr;
int ret;
errno=0;
if (ioctl(isdnctrl_desc, IIOCDBGVAR, &kaddr)) {
errno=EINVAL;
return(-1);
}
if ((mem_fd = open("/dev/kmem", O_RDONLY)) < 0) {
errno=EINVAL;
return(-1);
}
dev = (isdn_dev *) mapmem(kaddr, sizeof(isdn_dev));
ret = getpeer(phone);
#if USE_MM
munmap(dev, msize(sizeof(isdn_dev)));
#else
free(dev);
#endif
close(mem_fd);
return ret;
}
#ifdef STANDALONE
int main(int argc, char *argv[]) {
int isdnctrl_desc = open("/dev/isdnctrl",O_RDONLY);
isdn_net_ioctl_phone phone;
int ret;
strcpy(phone.name, argv[1] && *argv[1] ? argv[1] : "ippp0");
if (!(ret=iiocnetgpn(isdnctrl_desc, &phone)))
printf("Ok: '%s'\n", phone.phone);
else
printf("Err %d\n", ret);
close(isdnctrl_desc);
return ret;
}
#endif

View File

@ -1,4 +1,4 @@
/* $Id: processor.c,v 1.120 2000/12/21 09:56:47 leo Exp $
/* $Id: processor.c,v 1.121 2001/03/13 14:39:30 leo Exp $
*
* ISDN accounting for isdn4linux. (log-module)
*
@ -19,6 +19,10 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log: processor.c,v $
* Revision 1.121 2001/03/13 14:39:30 leo
* added IIOCNETGPN support for 2.0 kernels
* s. isdnlog/kernel_2_0/README for more information (isdnlog 4.51)
*
* Revision 1.120 2000/12/21 09:56:47 leo
* modilp, ilp - show duration, bugfix
* s. isdnlog/ilp/README for more information isdnlog 4.48
@ -3399,6 +3403,10 @@ static void huptime(int chan, int setup)
} /* else */
} /* if */
} /* if */
else if (hupctrl) {
sprintf(sx, "No HUP: HUP = %d c = %d *INTERFACE=%c", hupctrl, c, *INTERFACE);
info(chan, PRT_ERR, STATE_HUPTIMEOUT, sx);
}
} /* huptime */
@ -3431,6 +3439,9 @@ static void oops(int where)
} /* oops */
#if IIOCNETGPN == -1
extern int iiocnetgpn();
#endif
static int findinterface(void)
{
@ -3464,6 +3475,8 @@ static int findinterface(void)
*p = 0;
sscanf(s, "%9s", name);
if (*name != 'i') /* only ipppX is this ok? -lt */
continue;
memset(&phone, 0, sizeof(phone));
if (net_dv == 0x05 || net_dv == 0x06)
@ -3478,8 +3491,13 @@ static int findinterface(void)
return -1; /* can't happen? Versions should have been checked */
}
#endif
/* call emulation for 2.0 kernels */
#if IIOCNETGPN == -1
/* IIOCDBGVAR works on isdnctrl */
rc = iiocnetgpn(sockets[ISDNCTRL].descriptor, &phone);
#else
rc = ioctl(sockets[ISDNINFO].descriptor, IIOCNETGPN, &phone);
#endif
if (rc) {
if (errno == EINVAL) {
info(chan, PRT_SHOWNUMBERS, STATE_HUPTIMEOUT, "Sorry, IIOCNETGPN not available in your kernel (2.2.12 or higher is required)");