mirror of https://github.com/MelwareDE/ITunD
Initial checkin of version 0.3 -- started at sourceforge.
parent
cc34b2666e
commit
8eba0b3653
|
@ -0,0 +1,340 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Library General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) 19yy <name of author>
|
||||
|
||||
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 of the License, 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
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) 19yy name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Library General
|
||||
Public License instead of this License.
|
|
@ -0,0 +1,46 @@
|
|||
#
|
||||
# Makefile for ISDN Tunnel Daemon
|
||||
#
|
||||
|
||||
VERSION=0.3
|
||||
|
||||
PROG=itund
|
||||
|
||||
LIBS=-lcapi20 -lz
|
||||
|
||||
FILES=isdntun.o tun.o capiconn.o debug.o options.o \
|
||||
capi.o signals.o data.o
|
||||
|
||||
CFLAGS=-Wall -O2 -I. -DVERSION=\"$(VERSION)\"
|
||||
|
||||
DESTDIR=/
|
||||
BINDIR=sbin
|
||||
|
||||
all: $(PROG)
|
||||
@echo "Done!"
|
||||
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .c .o
|
||||
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) -c -o $*.o $*.c
|
||||
|
||||
$(PROG): $(FILES)
|
||||
$(CC) -o $(PROG) $(FILES) $(LDFLAGS) $(LIBS)
|
||||
|
||||
clean:
|
||||
@rm -f *.o $(PROG) *.tgz
|
||||
|
||||
install: $(PROG)
|
||||
mkdir -p $(DESTDIR)/$(BINDIR)
|
||||
install -m 0755 $(PROG) $(DESTDIR)/$(BINDIR)/$(PROG)
|
||||
|
||||
release:
|
||||
@rm -rf $(PROG)-$(VERSION)
|
||||
@mkdir -p $(PROG)-$(VERSION)
|
||||
@cp *.h *.c $(PROG)-$(VERSION)
|
||||
@cp README Makefile COPYING CHANGES $(PROG)-$(VERSION)
|
||||
@tar czf $(PROG)-$(VERSION).tgz $(PROG)-$(VERSION)
|
||||
@rm -rf $(PROG)-$(VERSION)
|
||||
@echo Archive created.
|
|
@ -0,0 +1,62 @@
|
|||
|
||||
ISDN-Tunnel-Daemon "itund"
|
||||
License GNU GPL
|
||||
|
||||
Copyright 2004-2005 SYSGO Real-Time Solutions AG
|
||||
Klein-Winternheim, Germany
|
||||
http://www.sysgo.com
|
||||
http://www.elinos.com
|
||||
|
||||
Copyright 2004-2005 Cytronics & Melware
|
||||
|
||||
ItunD is a user-space daemon to provide a network tunnel over ISDN lines. It works
|
||||
similiar (and most important together with) the ISDN4Linux net-devices.
|
||||
The ISDN link is provided as just another "network-card" to the kernel and can
|
||||
be configured easily.
|
||||
To provide the needed network interface, the generic TUN/TAP driver of kernels
|
||||
2.4 and 2.6 is used. This driver is also used by vtun.sourceforge.net.
|
||||
|
||||
|
||||
Impotant Notes
|
||||
--------------
|
||||
|
||||
1. User-Space daemon only, no kernel patches necessary.
|
||||
2. Options similar to PPPD CAPI options (pppdcapiplugin).
|
||||
3. Works with ISDN4Linux (isdn_net) network (e.g. rawip).
|
||||
|
||||
|
||||
Requirements
|
||||
------------
|
||||
|
||||
1. ISDN card providing CAPI2.0 interface (Eicon Networks, AVM, ...)
|
||||
The legacy isdn subsystem (isdn.o) is NOT necessary.
|
||||
2. Enabled (and loaded) Generic TUN/TAP network driver.
|
||||
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
When using itund on both sides, you may want to use encap "zipip"
|
||||
which is basically rawip, but compressed if possible.
|
||||
|
||||
|
||||
Examples
|
||||
========
|
||||
|
||||
Callback Server (reject and call back)
|
||||
itund --encap=rawip --controller=1 --protocol=hdlc \
|
||||
--number=5678 --msn=1234 --demand --idle=60 \
|
||||
--inmsn=1234 --coso=local --cbdelay=3
|
||||
|
||||
Client (expecting callback)
|
||||
itund --encap=rawip --controller=1 --protocol=hdlc \
|
||||
--number=1234 --msn=5678 --demand --idle=60 \
|
||||
--inmsn=5678 --coso=remote --dialtimeout=1
|
||||
|
||||
|
||||
|
||||
|
||||
armin.schindler@sysgo.com
|
||||
armin@melware.de
|
||||
|
||||
$Id$
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,435 @@
|
|||
/*
|
||||
* CAPI connection handling
|
||||
*
|
||||
* heavily based on capiconn.* of pppdcapiplugin by
|
||||
* Carsten Paeth (calle@calle.in-berlin.de)
|
||||
*
|
||||
* Copyright 2004 SYSGO Real-Time Solutions AG
|
||||
* Klein-Winternheim, Germany
|
||||
* All rights reserved.
|
||||
*
|
||||
* Author: Armin Schindler <armin.schindler@sysgo.com>
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* 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 of the License, or (at your
|
||||
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __CAPICONN_H__
|
||||
#define __CAPICONN_H__
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <capi20.h>
|
||||
|
||||
/*
|
||||
* CAPI_MESSAGES:
|
||||
* capiconn_inject():
|
||||
* inject capi message into state machine
|
||||
*
|
||||
* capiconn_context:
|
||||
* capiconn_getcontext():
|
||||
* get a context and supply callback functions
|
||||
* capiconn_freecontext():
|
||||
* free a context allocated with "capiconn_getcontext"
|
||||
* capiconn_addcontr():
|
||||
* add a controller to the context
|
||||
* capi_connection:
|
||||
* capiconn_connect():
|
||||
* connection setup, return a capi_connection.
|
||||
* capiconn_accept():
|
||||
* accept an incoming connection
|
||||
* capiconn_ignore():
|
||||
* ignore an incoming connection
|
||||
* capiconn_reject():
|
||||
* reject an incoming connection
|
||||
* capiconn_send():
|
||||
* send data to the connection
|
||||
* capiconn_disconnect():
|
||||
* disconnect a connection
|
||||
* capiconn_getinfo()
|
||||
* get infos about the connection
|
||||
* capiconn_listen():
|
||||
* setup listen
|
||||
*/
|
||||
|
||||
/* -------- returncodes -------------------------------------------------- */
|
||||
|
||||
#define CAPICONN_OK 0
|
||||
#define CAPICONN_NO_CONTROLLER -1
|
||||
#define CAPICONN_NO_MEMORY -2
|
||||
#define CAPICONN_WRONG_STATE 1
|
||||
#define CAPICONN_NOT_SENT 2
|
||||
#define CAPICONN_ALREADY_DISCONNECTING 3
|
||||
|
||||
/* -------- states for CAPI2.0 machine ----------------------------------- */
|
||||
|
||||
/*
|
||||
* LISTEN state machine
|
||||
*/
|
||||
#define ST_LISTEN_NONE 0 /* L-0 */
|
||||
#define ST_LISTEN_WAIT_CONF 1 /* L-0.1 */
|
||||
#define ST_LISTEN_ACTIVE 2 /* L-1 */
|
||||
#define ST_LISTEN_ACTIVE_WAIT_CONF 3 /* L-1.1 */
|
||||
|
||||
|
||||
#define EV_LISTEN_REQ 1 /* L-0 -> L-0.1
|
||||
L-1 -> L-1.1 */
|
||||
#define EV_LISTEN_CONF_ERROR 2 /* L-0.1 -> L-0
|
||||
L-1.1 -> L-1 */
|
||||
#define EV_LISTEN_CONF_EMPTY 3 /* L-0.1 -> L-0
|
||||
L-1.1 -> L-0 */
|
||||
#define EV_LISTEN_CONF_OK 4 /* L-0.1 -> L-1
|
||||
L-1.1 -> L.1 */
|
||||
|
||||
/*
|
||||
* per plci state machine
|
||||
*/
|
||||
#define ST_PLCI_NONE 0 /* P-0 */
|
||||
#define ST_PLCI_OUTGOING 1 /* P-0.1 */
|
||||
#define ST_PLCI_ALLOCATED 2 /* P-1 */
|
||||
#define ST_PLCI_ACTIVE 3 /* P-ACT */
|
||||
#define ST_PLCI_INCOMING 4 /* P-2 */
|
||||
#define ST_PLCI_FACILITY_IND 5 /* P-3 */
|
||||
#define ST_PLCI_ACCEPTING 6 /* P-4 */
|
||||
#define ST_PLCI_DISCONNECTING 7 /* P-5 */
|
||||
#define ST_PLCI_DISCONNECTED 8 /* P-6 */
|
||||
#define ST_PLCI_RESUMEING 9 /* P-0.Res */
|
||||
#define ST_PLCI_RESUME 10 /* P-Res */
|
||||
#define ST_PLCI_HELD 11 /* P-HELD */
|
||||
|
||||
#define EV_PLCI_CONNECT_REQ 1 /* P-0 -> P-0.1
|
||||
*/
|
||||
#define EV_PLCI_CONNECT_CONF_ERROR 2 /* P-0.1 -> P-0
|
||||
*/
|
||||
#define EV_PLCI_CONNECT_CONF_OK 3 /* P-0.1 -> P-1
|
||||
*/
|
||||
#define EV_PLCI_FACILITY_IND_UP 4 /* P-0 -> P-1
|
||||
*/
|
||||
#define EV_PLCI_CONNECT_IND 5 /* P-0 -> P-2
|
||||
*/
|
||||
#define EV_PLCI_CONNECT_ACTIVE_IND 6 /* P-1 -> P-ACT
|
||||
*/
|
||||
#define EV_PLCI_CONNECT_REJECT 7 /* P-2 -> P-5
|
||||
P-3 -> P-5
|
||||
*/
|
||||
#define EV_PLCI_DISCONNECT_REQ 8 /* P-1 -> P-5
|
||||
P-2 -> P-5
|
||||
P-3 -> P-5
|
||||
P-4 -> P-5
|
||||
P-ACT -> P-5
|
||||
P-Res -> P-5 (*)
|
||||
P-HELD -> P-5 (*)
|
||||
*/
|
||||
#define EV_PLCI_DISCONNECT_IND 9 /* P-1 -> P-6
|
||||
P-2 -> P-6
|
||||
P-3 -> P-6
|
||||
P-4 -> P-6
|
||||
P-5 -> P-6
|
||||
P-ACT -> P-6
|
||||
P-Res -> P-6 (*)
|
||||
P-HELD -> P-6 (*)
|
||||
*/
|
||||
#define EV_PLCI_FACILITY_IND_DOWN 10 /* P-0.1 -> P-5
|
||||
P-1 -> P-5
|
||||
P-ACT -> P-5
|
||||
P-2 -> P-5
|
||||
P-3 -> P-5
|
||||
P-4 -> P-5
|
||||
*/
|
||||
#define EV_PLCI_DISCONNECT_RESP 11 /* P-6 -> P-0
|
||||
*/
|
||||
#define EV_PLCI_CONNECT_RESP 12 /* P-6 -> P-0
|
||||
*/
|
||||
|
||||
#define EV_PLCI_RESUME_REQ 13 /* P-0 -> P-0.Res
|
||||
*/
|
||||
#define EV_PLCI_RESUME_CONF_OK 14 /* P-0.Res -> P-Res
|
||||
*/
|
||||
#define EV_PLCI_RESUME_CONF_ERROR 15 /* P-0.Res -> P-0
|
||||
*/
|
||||
#define EV_PLCI_RESUME_IND 16 /* P-Res -> P-ACT
|
||||
*/
|
||||
#define EV_PLCI_HOLD_IND 17 /* P-ACT -> P-HELD
|
||||
*/
|
||||
#define EV_PLCI_RETRIEVE_IND 18 /* P-HELD -> P-ACT
|
||||
*/
|
||||
#define EV_PLCI_SUSPEND_IND 19 /* P-ACT -> P-5
|
||||
*/
|
||||
#define EV_PLCI_CD_IND 20 /* P-2 -> P-5
|
||||
*/
|
||||
|
||||
/*
|
||||
* per ncci state machine
|
||||
*/
|
||||
#define ST_NCCI_PREVIOUS -1
|
||||
#define ST_NCCI_NONE 0 /* N-0 */
|
||||
#define ST_NCCI_OUTGOING 1 /* N-0.1 */
|
||||
#define ST_NCCI_INCOMING 2 /* N-1 */
|
||||
#define ST_NCCI_ALLOCATED 3 /* N-2 */
|
||||
#define ST_NCCI_ACTIVE 4 /* N-ACT */
|
||||
#define ST_NCCI_RESETING 5 /* N-3 */
|
||||
#define ST_NCCI_DISCONNECTING 6 /* N-4 */
|
||||
#define ST_NCCI_DISCONNECTED 7 /* N-5 */
|
||||
|
||||
#define EV_NCCI_CONNECT_B3_REQ 1 /* N-0 -> N-0.1 */
|
||||
#define EV_NCCI_CONNECT_B3_IND 2 /* N-0 -> N.1 */
|
||||
#define EV_NCCI_CONNECT_B3_CONF_OK 3 /* N-0.1 -> N.2 */
|
||||
#define EV_NCCI_CONNECT_B3_CONF_ERROR 4 /* N-0.1 -> N.0 */
|
||||
#define EV_NCCI_CONNECT_B3_REJECT 5 /* N-1 -> N-4 */
|
||||
#define EV_NCCI_CONNECT_B3_RESP 6 /* N-1 -> N-2 */
|
||||
#define EV_NCCI_CONNECT_B3_ACTIVE_IND 7 /* N-2 -> N-ACT */
|
||||
#define EV_NCCI_RESET_B3_REQ 8 /* N-ACT -> N-3 */
|
||||
#define EV_NCCI_RESET_B3_IND 9 /* N-3 -> N-ACT */
|
||||
#define EV_NCCI_DISCONNECT_B3_IND 10 /* N-4 -> N.5 */
|
||||
#define EV_NCCI_DISCONNECT_B3_CONF_ERROR 11 /* N-4 -> previous */
|
||||
#define EV_NCCI_DISCONNECT_B3_REQ 12 /* N-1 -> N-4
|
||||
N-2 -> N-4
|
||||
N-3 -> N-4
|
||||
N-ACT -> N-4 */
|
||||
#define EV_NCCI_DISCONNECT_B3_RESP 13 /* N-5 -> N-0 */
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
char *capiconn_version(void);
|
||||
|
||||
/* -------- context ------------------------------------------------------ */
|
||||
|
||||
struct capi_connection; typedef struct capi_connection capi_connection;
|
||||
struct capiconn_context; typedef struct capiconn_context capiconn_context;
|
||||
|
||||
struct capiconn_callbacks
|
||||
{
|
||||
/* ---------- memory functions ----------------- */
|
||||
|
||||
void *(*malloc)(size_t size);
|
||||
void (*free)(void *buf);
|
||||
|
||||
/* ---------- connection callbacks ------------- */
|
||||
|
||||
/*
|
||||
* the capi_connection will be destoried after
|
||||
* calling this function
|
||||
*/
|
||||
void (*disconnected)(capi_connection *,
|
||||
int localdisconnect,
|
||||
unsigned reason,
|
||||
unsigned reason_b3);
|
||||
/*
|
||||
* The application should call capiconn_accept()
|
||||
* capiconn_ignore() or capiconn_reject() inside
|
||||
* of the function. If not called an ALERT_REQ will
|
||||
* be sent, to let the application time to decide ...
|
||||
*/
|
||||
void (*incoming)(capi_connection *,
|
||||
unsigned contr,
|
||||
unsigned chipvalue,
|
||||
char *callednumber,
|
||||
char *callingnumber);
|
||||
|
||||
/*
|
||||
* Channel is ready to send and receive data
|
||||
*/
|
||||
void (*connected)(capi_connection *, _cstruct);
|
||||
|
||||
/*
|
||||
* Data received on channel, the data pointer
|
||||
* can not be used, after this function is called.
|
||||
*/
|
||||
void (*received)(capi_connection *,
|
||||
unsigned char *data,
|
||||
unsigned datalen);
|
||||
|
||||
/*
|
||||
* called for every call to capiconn_send().
|
||||
*/
|
||||
void (*datasent)(capi_connection *, unsigned char *);
|
||||
|
||||
/*
|
||||
* charge info received
|
||||
*/
|
||||
void (*chargeinfo)(capi_connection *,
|
||||
unsigned long charge,
|
||||
int inunits);
|
||||
/*
|
||||
* capi functions
|
||||
*/
|
||||
void (*capi_put_message) (unsigned appid, unsigned char *msg);
|
||||
|
||||
/*
|
||||
* message functions
|
||||
*/
|
||||
void (*debugmsg)(const char *fmt, ...);
|
||||
void (*infomsg)(const char *fmt, ...);
|
||||
void (*errmsg)(const char *fmt, ...);
|
||||
};
|
||||
typedef struct capiconn_callbacks capiconn_callbacks;
|
||||
|
||||
/* -------- context functions -------------------------------------------- */
|
||||
|
||||
capiconn_context *capiconn_getcontext(unsigned appid, capiconn_callbacks *env);
|
||||
|
||||
int capiconn_freecontext(capiconn_context *ctx);
|
||||
|
||||
/* -------- inject capi message into state machine ----------------------- */
|
||||
|
||||
void capiconn_inject(unsigned appid, unsigned char *msg);
|
||||
|
||||
/* -------- add controller to context ------------------------------------ */
|
||||
|
||||
struct capi_contrinfo {
|
||||
int bchannels;
|
||||
char *ddi;
|
||||
int ndigits; /* Durchwahllaenge */
|
||||
};
|
||||
typedef struct capi_contrinfo capi_contrinfo;
|
||||
|
||||
/*
|
||||
* returncodes:
|
||||
* CAPICONN_OK - controller added to the context
|
||||
* CAPICONN_NO_MEMORY - callback "malloc" returns no memory.
|
||||
*/
|
||||
int capiconn_addcontr(capiconn_context *ctx,
|
||||
unsigned contr, capi_contrinfo *cinfo);
|
||||
|
||||
/* -------- initiate a connection & disconnect a connection -------------- */
|
||||
|
||||
/*
|
||||
* returncodes:
|
||||
* a capi connection or 0 if
|
||||
* - controller not found
|
||||
* - memory problems
|
||||
*/
|
||||
|
||||
capi_connection *
|
||||
capiconn_connect(
|
||||
capiconn_context *ctx,
|
||||
unsigned contr,
|
||||
_cword cipvalue,
|
||||
char *callednumber, /* remote number */
|
||||
char *callingnumber, /* own number */
|
||||
_cword b1proto,
|
||||
_cword b2proto,
|
||||
_cword b3proto,
|
||||
_cstruct b1config,
|
||||
_cstruct b2config,
|
||||
_cstruct b3config,
|
||||
_cstruct bchaninfo,
|
||||
_cstruct ncpi);
|
||||
|
||||
/*
|
||||
* returncodes:
|
||||
* CAPICONN_OK - disconnect initiated
|
||||
* CAPICONN_ALREADY_DISCONNECTING - disconnect already initiated
|
||||
* CAPICONN_WRONG_STATE - should not happen
|
||||
*/
|
||||
int capiconn_disconnect(capi_connection *connection, _cstruct ncpi);
|
||||
|
||||
/* -------- reaction on incoming calls ----------------------------------- */
|
||||
|
||||
/*
|
||||
* returncodes:
|
||||
* CAPICONN_OK - Accept initiated
|
||||
* CAPICONN_WRONG_STATE - "conn" ist not in state "incoming"
|
||||
* CAPICONN_NO_MEMORY - callback "malloc" returns no memory.
|
||||
*/
|
||||
int capiconn_accept(
|
||||
capi_connection *conn,
|
||||
_cword b1proto,
|
||||
_cword b2proto,
|
||||
_cword b3proto,
|
||||
_cstruct b1config,
|
||||
_cstruct b2config,
|
||||
_cstruct b3config,
|
||||
_cstruct ncpi);
|
||||
|
||||
/*
|
||||
* returncodes:
|
||||
* CAPICONN_OK - call will be ignored
|
||||
* CAPICONN_WRONG_STATE - "conn" ist not in state "incoming"
|
||||
*/
|
||||
int capiconn_ignore(capi_connection *conn);
|
||||
|
||||
/*
|
||||
* returncodes:
|
||||
* CAPICONN_OK - call will be rejected
|
||||
* CAPICONN_WRONG_STATE - "conn" ist not in state "incoming"
|
||||
*/
|
||||
int capiconn_reject(capi_connection *conn);
|
||||
|
||||
/*
|
||||
* returncode:
|
||||
* CAPICONN_OK - Data sent to CAPI
|
||||
* CAPICONN_NOT_SENT - Data not sent (8 messages not acked)
|
||||
* CAPICONN_WRONG_STATE - Connection is not connected
|
||||
*/
|
||||
int capiconn_send(capi_connection *plcip,
|
||||
unsigned char *data,
|
||||
unsigned len);
|
||||
|
||||
/*
|
||||
* get info about connection
|
||||
*/
|
||||
|
||||
struct capi_conninfo {
|
||||
unsigned appid;
|
||||
|
||||
unsigned plci;
|
||||
int plci_state;
|
||||
unsigned ncci;
|
||||
int ncci_state;
|
||||
unsigned isincoming:1,
|
||||
disconnect_was_local;
|
||||
unsigned disconnectreason;
|
||||
unsigned disconnectreason_b3;
|
||||
|
||||
/* user supplied */
|
||||
_cword cipvalue;
|
||||
_cstruct callednumber;
|
||||
_cstruct callingnumber;
|
||||
_cword b1proto;
|
||||
_cword b2proto;
|
||||
_cword b3proto;
|
||||
_cstruct b1config;
|
||||
_cstruct b2config;
|
||||
_cstruct b3config;
|
||||
_cstruct bchaninfo;
|
||||
_cstruct ncpi;
|
||||
};
|
||||
typedef struct capi_conninfo capi_conninfo;
|
||||
|
||||
/*
|
||||
* returncode:
|
||||
* always a pointer to the conninfo.
|
||||
* the conninfo will not be update automaticly,
|
||||
* you always have to call this function to get
|
||||
* the actual informations.
|
||||
*/
|
||||
capi_conninfo *capiconn_getinfo(capi_connection *p);
|
||||
|
||||
/*
|
||||
* returncodes:
|
||||
* CAPICONN_OK - Listen request sent
|
||||
* CAPICONN_NO_CONTROLLER - Controller "contr" not added with
|
||||
* capiconn_addcontr()
|
||||
*/
|
||||
int capiconn_listen(capiconn_context *ctx,
|
||||
unsigned contr, unsigned cipmask, unsigned cipmask2);
|
||||
|
||||
/*
|
||||
* returncodes:
|
||||
* CAPICONN_OK - got ack for listen request
|
||||
* CAPICONN_NO_CONTROLLER - Controller "contr" not added with
|
||||
* capiconn_addcontr()
|
||||
* CAPICONN_WRONG_STATE - got no ack for listen request
|
||||
*/
|
||||
int capiconn_listenstate(capiconn_context *ctx, unsigned contr);
|
||||
|
||||
#endif /* __CAPICONN_H__ */
|
|
@ -0,0 +1,236 @@
|
|||
/*
|
||||
* Data handling functions
|
||||
*
|
||||
* Copyright 2004 SYSGO Real-Time Solutions AG
|
||||
* Klein-Winternheim, Germany
|
||||
* All rights reserved.
|
||||
*
|
||||
* Author: Armin Schindler <armin.schindler@sysgo.com>
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* 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 of the License, or (at your
|
||||
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <zlib.h>
|
||||
|
||||
#include "isdntun.h"
|
||||
#include "options.h"
|
||||
#include "tun.h"
|
||||
#include "capiconn.h"
|
||||
|
||||
int data_sent = 0;
|
||||
time_t idle_last_use = 0;
|
||||
|
||||
static capi_connection *conn = NULL;
|
||||
|
||||
#undef DEBUG_DATA
|
||||
|
||||
/*
|
||||
* flush the data in the interface
|
||||
*/
|
||||
void empty_interface(void)
|
||||
{
|
||||
fd_set rfds;
|
||||
struct timeval tv;
|
||||
int ret;
|
||||
unsigned char buffer[2048];
|
||||
|
||||
info("empty interface %s queue", dev_name);
|
||||
|
||||
while (1) {
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 0;
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(if_fd, &rfds);
|
||||
|
||||
ret = select(if_fd + 1, &rfds, NULL, NULL, &tv);
|
||||
if (ret < 1)
|
||||
break;
|
||||
read(if_fd, buffer, sizeof(buffer));
|
||||
dbglog("flushed one buffer");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* compress data
|
||||
*/
|
||||
static void compress_data(unsigned char *buf, int *len)
|
||||
{
|
||||
unsigned long l1, l2;
|
||||
unsigned char b[2048];
|
||||
|
||||
if (*len < 16)
|
||||
return;
|
||||
|
||||
l1 = (unsigned long)*len;
|
||||
memcpy(b, buf, *len);
|
||||
|
||||
l2 = sizeof(b);
|
||||
|
||||
buf[0] = 0;
|
||||
if ((compress(buf + 1, &l2, b, l1) != Z_OK) ||
|
||||
((l2 + 1) > *len)) {
|
||||
memcpy(buf + 1, b, *len);
|
||||
*len += 1;
|
||||
dbglog("if data not compressed len=%d", *len);
|
||||
return;
|
||||
}
|
||||
*len = (int)(l2 + 1);
|
||||
buf[0] = 1;
|
||||
dbglog("if data compressed %ld->%d", l1, *len);
|
||||
}
|
||||
|
||||
/*
|
||||
* compress data
|
||||
*/
|
||||
static void uncompress_data(unsigned char *buf, unsigned int *len)
|
||||
{
|
||||
unsigned long l1, l2;
|
||||
unsigned char b[2048];
|
||||
|
||||
memcpy(b, buf, *len);
|
||||
*len -= 1;
|
||||
|
||||
if (*b == 0) { /* not compressed */
|
||||
memcpy(buf, b + 1, *len);
|
||||
return;
|
||||
}
|
||||
|
||||
l1 = (unsigned long)*len;
|
||||
l2 = sizeof(b);
|
||||
|
||||
if (uncompress(buf, &l2, b + 1, l1) != Z_OK) {
|
||||
*len = 0;
|
||||
error("uncompress error");
|
||||
return;
|
||||
}
|
||||
*len = (unsigned int)l2;
|
||||
dbglog("if data uncompressed %ld->%d", l1, *len);
|
||||
}
|
||||
|
||||
/*
|
||||
* handle data coming from device
|
||||
*/
|
||||
void handle_if_data(void)
|
||||
{
|
||||
int len;
|
||||
unsigned char buffer[2048];
|
||||
if ((len = read(if_fd, buffer, sizeof(buffer))) < 1) {
|
||||
error("error %d reading %s", len, dev_name);
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_DATA
|
||||
{
|
||||
int i;
|
||||
FILE *f;
|
||||
if ((f = fopen("/tmp/itun.txt", "a")) != NULL) {
|
||||
fprintf(f, "inet %03d: ", len);
|
||||
for (i = 0; i < len; i++)
|
||||
fprintf(f, "%02x ", buffer[i]);
|
||||
fprintf(f, "\n");
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (encap == ENCAP_ZIPIP)
|
||||
compress_data(buffer, &len);
|
||||
|
||||
data_sent = 0;
|
||||
|
||||
if (capiconn_send(conn, buffer, len) != CAPICONN_OK) {
|
||||
error("data not sent");
|
||||
}
|
||||
|
||||
idle_last_use = time(NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* handle data coming from capi (isdn)
|
||||
*/
|
||||
void handle_capi_data(capi_connection *con, unsigned char* data, unsigned int len)
|
||||
{
|
||||
int dlen;
|
||||
|
||||
dlen = len;
|
||||
dbglog("capi data to if of len %d", dlen);
|
||||
|
||||
if (encap == ENCAP_ZIPIP)
|
||||
uncompress_data(data, &dlen);
|
||||
|
||||
if (write(if_fd, data, dlen) != dlen)
|
||||
error("Error writing isdn data to %s", dev_name);
|
||||
|
||||
idle_last_use = time(NULL);
|
||||
|
||||
#ifdef DEBUG_DATA
|
||||
{
|
||||
int i;
|
||||
FILE *f;
|
||||
if ((f = fopen("/tmp/itun.txt", "a")) != NULL) {
|
||||
fprintf(f, "isdn %03d: ", dlen);
|
||||
for (i = 0; i < dlen; i++)
|
||||
fprintf(f, "%02x ", data[i]);
|
||||
fprintf(f, "\n");
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* isdn data have been sent
|
||||
*/
|
||||
void handle_capi_sent(capi_connection *con, unsigned char* data)
|
||||
{
|
||||
dbglog("data sent confirmed");
|
||||
data_sent = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* get status of connection
|
||||
*/
|
||||
int is_connected(void)
|
||||
{
|
||||
if (conn)
|
||||
return(1);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* if connection is established, store connection pointer
|
||||
*/
|
||||
void capi_is_connected(capi_connection *con)
|
||||
{
|
||||
conn = con;
|
||||
data_sent = 1; /* ready for data */
|
||||
idle_last_use = time(NULL);
|
||||
new_phase(PHASE_RUNNING);
|
||||
}
|
||||
|
||||
/*
|
||||
* if connection is released, clear connection pointer
|
||||
*/
|
||||
void capi_is_disconnected(capi_connection *con)
|
||||
{
|
||||
conn = NULL;
|
||||
new_phase(PHASE_DISCONNECT);
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Data handling functions
|
||||
*
|
||||
* Copyright 2004 SYSGO Real-Time Solutions AG
|
||||
* Klein-Winternheim, Germany
|
||||
* All rights reserved.
|
||||
*
|
||||
* Author: Armin Schindler <armin.schindler@sysgo.com>
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* 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 of the License, or (at your
|
||||
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __ITUN_DATA_H__
|
||||
#define __ITUN_DATA_H__
|
||||
|
||||
#include "capiconn.h"
|
||||
|
||||
extern int data_sent;
|
||||
extern time_t idle_last_use;
|
||||
|
||||
extern void handle_if_data(void);
|
||||
extern void empty_interface(void);
|
||||
extern void handle_capi_data(capi_connection *con, unsigned char* data, unsigned int len);
|
||||
extern void handle_capi_sent(capi_connection *con, unsigned char* data);
|
||||
extern void capi_is_connected(capi_connection *con);
|
||||
extern void capi_is_disconnected(capi_connection *con);
|
||||
extern int is_connected(void);
|
||||
|
||||
#endif /* __ITUN_DATA_H__ */
|
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* Debug handling
|
||||
*
|
||||
* Copyright 2004 SYSGO Real-Time Solutions AG
|
||||
* Klein-Winternheim, Germany
|
||||
* All rights reserved.
|
||||
*
|
||||
* Author: Armin Schindler <armin.schindler@sysgo.com>
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* 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 of the License, or (at your
|
||||
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include "isdntun.h"
|
||||
#include "options.h"
|
||||
|
||||
int debug_level = 2;
|
||||
|
||||
/*
|
||||
* syslog
|
||||
*/
|
||||
static void do_syslog(int prio, char *format, va_list ap)
|
||||
{
|
||||
unsigned char buf[2048];
|
||||
int len;
|
||||
|
||||
len = sprintf(buf, "%s: ", opt_name);
|
||||
vsnprintf(buf + len, sizeof(buf), format, ap);
|
||||
syslog(prio, buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* debug
|
||||
*/
|
||||
static void debug_output(int level, char *format, va_list ap)
|
||||
{
|
||||
switch (level) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
do_syslog(LOG_ERR, format, ap);
|
||||
break;
|
||||
case 3:
|
||||
do_syslog(LOG_INFO, format, ap);
|
||||
break;
|
||||
}
|
||||
|
||||
if (level > debug_level)
|
||||
return;
|
||||
|
||||
fprintf(stderr, "Itun %d: ", level);
|
||||
vfprintf(stderr, format, ap);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
void option_error(char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
debug_output(0, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void fatal(char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
debug_output(1, format, ap);
|
||||
va_end(ap);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
void error(char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
debug_output(2, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void info(char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
debug_output(3, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void dbglog(char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, format);
|
||||
debug_output(4, format, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Debug handling
|
||||
*
|
||||
* Copyright 2004 SYSGO Real-Time Solutions AG
|
||||
* Klein-Winternheim, Germany
|
||||
* All rights reserved.
|
||||
*
|
||||
* Author: Armin Schindler <armin.schindler@sysgo.com>
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* 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 of the License, or (at your
|
||||
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __ITUN_DEBUG_H__
|
||||
#define __ITUN_DEBUG_H__
|
||||
|
||||
/*
|
||||
* debug
|
||||
*/
|
||||
|
||||
extern int debug_level;
|
||||
extern void fatal(char *format, ...);
|
||||
extern void error(char *format, ...);
|
||||
extern void info(char *format, ...);
|
||||
extern void dbglog(char *format, ...);
|
||||
extern void option_error(char *format, ...);
|
||||
|
||||
|
||||
#endif /* __ITUN_DEBUG_H__ */
|
||||
|
|
@ -0,0 +1,427 @@
|
|||
/*
|
||||
* ISDN tunnel Daemon "ItunD"
|
||||
*
|
||||
* Copyright 2004-2005 SYSGO Real-Time Solutions AG
|
||||
* Klein-Winternheim, Germany
|
||||
* All rights reserved.
|
||||
*
|
||||
* Author: Armin Schindler <armin.schindler@sysgo.com>
|
||||
*
|
||||
* Copyright 2004-2005 Cytronics & Melware
|
||||
*
|
||||
* Armin Schindler <armin@melware.de>
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* 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 of the License, or (at your
|
||||
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <getopt.h>
|
||||
#include <syslog.h>
|
||||
#include <sys/select.h>
|
||||
|
||||
#include "isdntun.h"
|
||||
#include "options.h"
|
||||
#include "signals.h"
|
||||
#include "tun.h"
|
||||
|
||||
static char pid_file[128];
|
||||
|
||||
int if_fd;
|
||||
int capi_fd;
|
||||
|
||||
int status = EXIT_OK;
|
||||
int iphase = PHASE_DEAD;
|
||||
|
||||
void new_phase(int phase)
|
||||
{
|
||||
iphase = phase;
|
||||
capi_new_phase(phase);
|
||||
}
|
||||
|
||||
/*
|
||||
* exit
|
||||
*/
|
||||
void die(int val)
|
||||
{
|
||||
error("die with %d", val);
|
||||
itun_close(if_fd);
|
||||
itun_exit();
|
||||
unlink(pid_file);
|
||||
exit(val);
|
||||
}
|
||||
|
||||
/*
|
||||
* usage
|
||||
*/
|
||||
static void usage(char *prg)
|
||||
{
|
||||
fprintf(stderr, "ISDN-Tunnel Daemon Version %s (c) 2004-2005 Cytronics & Melware, SYSGO AG\n", VERSION);
|
||||
fprintf(stderr, "usage: %s <option> <option> ...\n", prg);
|
||||
fprintf(stderr, "options:\n");
|
||||
fprintf(stderr, " -D Don't daemonize into background\n");
|
||||
fprintf(stderr, " -d <level> Set debug level (%d)\n", debug_level);
|
||||
fprintf(stderr, " --encap=<arg> Encapsulation (ether, rawip, zipip)\n");
|
||||
fprintf(stderr, " --controller=<arg> CAPI controller specification\n");
|
||||
fprintf(stderr, " --ddi=<arg,len> DDI-number,DDI-length\n");
|
||||
fprintf(stderr, " --protcol=<arg> Protocol (x75, hdlc)\n");
|
||||
fprintf(stderr, " --number=<arg> Number to call\n");
|
||||
fprintf(stderr, " (may be comma separated list)\n");
|
||||
fprintf(stderr, " --numberprefix=<arg> Prefix for number\n");
|
||||
fprintf(stderr, " --msn=<arg> Number to call from\n");
|
||||
fprintf(stderr, " --inmsn=<arg> Called number for incoming calls\n");
|
||||
fprintf(stderr, " --cli=<arg> Calling number for incoming calls\n");
|
||||
fprintf(stderr, " (may be comma separated list)\n");
|
||||
fprintf(stderr, " --clicb Call number and wait for callback\n");
|
||||
fprintf(stderr, " --cbwait=<arg> Number of seconds to wait for callback\n");
|
||||
fprintf(stderr, " --dialtimeout=<arg> Number of seconds to wait for connection\n");
|
||||
fprintf(stderr, " or reject\n");
|
||||
fprintf(stderr, " --dialmax=<arg> Number of dial retries\n");
|
||||
fprintf(stderr, " --redialdelay=<arg> Number of seconds to wait between dial retries\n");
|
||||
fprintf(stderr, " --channels=<arg> Channel to use for leased line\n");
|
||||
fprintf(stderr, " (may be comma separated list)\n");
|
||||
fprintf(stderr, " --cbdelay=<arg> Number of seconds to wait before calling back\n");
|
||||
fprintf(stderr, " --cbnumber=<arg> Number to call (may be comma separated list)\n");
|
||||
fprintf(stderr, " --connectdelay=<arg> Number of seconds to wait after connection is established\n");
|
||||
fprintf(stderr, " --acceptdelay Wait 1 second before accept incoming call\n");
|
||||
fprintf(stderr, " --coso=<arg> COSO: caller,local or remote\n");
|
||||
fprintf(stderr, " --voicecallwakeup Call number and wait for callback\n");
|
||||
fprintf(stderr, " --demand Establish connection on demand only\n");
|
||||
fprintf(stderr, " --nopersist Exit after connection\n");
|
||||
fprintf(stderr, " --idle=<arg> Number of idle seconds before hangup (%d)\n", opt_idle);
|
||||
fprintf(stderr, " --name=<arg> Personal name for this connection\n");
|
||||
fprintf(stderr, " --ifup=<arg> Script to be called when interface is up\n");
|
||||
fprintf(stderr, " called with arguments <if-name> <given-name>\n");
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* long options list
|
||||
*/
|
||||
static struct option itun_options[] = {
|
||||
{ "help", no_argument, NULL, 0x100 },
|
||||
{ "encap", required_argument, NULL, 0x101 },
|
||||
{ "controller", required_argument, NULL, 0x102 },
|
||||
{ "number", required_argument, NULL, 0x103 },
|
||||
{ "numberprefix", required_argument, NULL, 0x104 },
|
||||
{ "msn", required_argument, NULL, 0x105 },
|
||||
{ "protocol", required_argument, NULL, 0x106 },
|
||||
{ "inmsn", required_argument, NULL, 0x107 },
|
||||
{ "cli", required_argument, NULL, 0x108 },
|
||||
{ "clicb", no_argument, NULL, 0x109 },
|
||||
{ "cbwait", required_argument, NULL, 0x10A },
|
||||
{ "dialtimeout", required_argument, NULL, 0x10B },
|
||||
{ "dialmax", required_argument, NULL, 0x10C },
|
||||
{ "redialdelay", required_argument, NULL, 0x10D },
|
||||
{ "channels", required_argument, NULL, 0x10E },
|
||||
{ "cbdelay", required_argument, NULL, 0x10F },
|
||||
{ "cbnumber", required_argument, NULL, 0x110 },
|
||||
{ "connectdelay", required_argument, NULL, 0x111 },
|
||||
{ "acceptdelay", no_argument, NULL, 0x112 },
|
||||
{ "coso", required_argument, NULL, 0x113 },
|
||||
{ "voicecallwakup", no_argument, NULL, 0x114 },
|
||||
{ "demand", no_argument, NULL, 0x115 },
|
||||
{ "idle", required_argument, NULL, 0x116 },
|
||||
{ "nopersist", no_argument, NULL, 0x117 },
|
||||
{ "name", required_argument, NULL, 0x118 },
|
||||
{ "ddi", required_argument, NULL, 0x119 },
|
||||
{ "ifup", required_argument, NULL, 0x11A },
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
/*
|
||||
* capi wants wake up
|
||||
*/
|
||||
void capi_wake_up(void)
|
||||
{
|
||||
Dialsignal = 1;
|
||||
dbglog("capi_wake_up");
|
||||
}
|
||||
|
||||
/*
|
||||
* main loop of connection handling
|
||||
*/
|
||||
static void connection_handling(void)
|
||||
{
|
||||
fd_set rfds;
|
||||
struct timeval tv;
|
||||
int ret;
|
||||
int maxfd;
|
||||
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(capi_fd, &rfds);
|
||||
maxfd = capi_fd;
|
||||
|
||||
if (((iphase == PHASE_RUNNING) && (data_sent)) ||
|
||||
(iphase == PHASE_DORMANT)) {
|
||||
FD_SET(if_fd, &rfds);
|
||||
if (if_fd > capi_fd)
|
||||
maxfd = if_fd;
|
||||
}
|
||||
|
||||
tv.tv_sec = 1;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
ret = select(maxfd + 1, &rfds, NULL, NULL, &tv);
|
||||
|
||||
if (ret > 0) {
|
||||
if (FD_ISSET(capi_fd, &rfds)) {
|
||||
dbglog("capi_fd in select");
|
||||
handle_capi_message();
|
||||
}
|
||||
|
||||
if (FD_ISSET(if_fd, &rfds)) {
|
||||
dbglog("if_fd in select");
|
||||
if (is_connected())
|
||||
handle_if_data();
|
||||
else
|
||||
Dialsignal = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* MAIN
|
||||
*/
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int c;
|
||||
FILE *f;
|
||||
|
||||
while ((c = getopt_long(argc, argv, "?hDd:", itun_options, (int *)0)) != EOF) {
|
||||
switch(c) {
|
||||
case 'D': /* don't daemonize */
|
||||
daemonize = 0;
|
||||
break;
|
||||
case 'd': /* debug level */
|
||||
debug_level = strtol(optarg, NULL, 0);
|
||||
break;
|
||||
case 0x101: /* encap */
|
||||
opt_encap = strdup(optarg);
|
||||
break;
|
||||
case 0x102: /* controller */
|
||||
opt_controller = strdup(optarg);
|
||||
break;
|
||||
case 0x103: /* number */
|
||||
opt_number = strdup(optarg);
|
||||
break;
|
||||
case 0x104: /* numberprefix */
|
||||
opt_numberprefix = strdup(optarg);
|
||||
break;
|
||||
case 0x105: /* msn */
|
||||
opt_msn = strdup(optarg);
|
||||
break;
|
||||
case 0x106: /* protocol */
|
||||
opt_proto = strdup(optarg);
|
||||
break;
|
||||
case 0x107: /* inmsn */
|
||||
opt_inmsn = strdup(optarg);
|
||||
break;
|
||||
case 0x108: /* cli */
|
||||
opt_cli = strdup(optarg);
|
||||
break;
|
||||
case 0x109: /* clicb */
|
||||
opt_cbflag = 1;
|
||||
break;
|
||||
case 0x10A: /* cbwait */
|
||||
opt_cbwait = strtol(optarg, NULL, 0);
|
||||
break;
|
||||
case 0x10B: /* dialtimeout */
|
||||
opt_dialtimeout = strtol(optarg, NULL, 0);
|
||||
break;
|
||||
case 0x10C: /* dialmax */
|
||||
opt_dialmax = strtol(optarg, NULL, 0);
|
||||
break;
|
||||
case 0x10D: /* redialdelay */
|
||||
opt_redialdelay = strtol(optarg, NULL, 0);
|
||||
break;
|
||||
case 0x10E: /* channels */
|
||||
opt_channels = strdup(optarg);
|
||||
break;
|
||||
case 0x10F: /* cbdelay */
|
||||
opt_cbdelay = strtol(optarg, NULL, 0);
|
||||
break;
|
||||
case 0x110: /* cbnumber */
|
||||
opt_callbacknumber = strdup(optarg);
|
||||
break;
|
||||
case 0x111: /* connectdelay */
|
||||
opt_connectdelay = strtol(optarg, NULL, 0);
|
||||
break;
|
||||
case 0x112: /* acceptdelay */
|
||||
opt_acceptdelayflag = 1;
|
||||
break;
|
||||
case 0x113: /* coso */
|
||||
opt_coso = strdup(optarg);
|
||||
break;
|
||||
case 0x114: /* voicecallwakeup */
|
||||
opt_voicecallwakeup = 1;
|
||||
break;
|
||||
case 0x115: /* demand */
|
||||