Compare commits
54 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc26ccb8b2 | ||
|
|
e19c054972 | ||
|
|
93fb70171b | ||
|
|
0118fc15a7 | ||
|
|
a3101da9fe | ||
|
|
8ac2db33d4 | ||
|
|
ba5a5ca907 | ||
|
|
2b7b7e2e68 | ||
|
|
9682be31fb | ||
|
|
ea146a8f6f | ||
|
|
12155fa6c3 | ||
|
|
96535a0c17 | ||
|
|
cac414333f | ||
|
|
748702c5c5 | ||
|
|
6dd859f5de | ||
|
|
5fd79b6b1b | ||
|
|
e88ac71b3d | ||
|
|
5166adfb1e | ||
|
|
f8b7c404a0 | ||
|
|
b93317f38b | ||
|
|
18958fa7e8 | ||
|
|
c9bb969586 | ||
|
|
7cdd6c7f2c | ||
|
|
3193d779ef | ||
|
|
97648bb1b4 | ||
|
|
20e146406b | ||
|
|
1e5fad5fe7 | ||
|
|
dd9ba5b8a5 | ||
|
|
d4eab6216e | ||
|
|
1cabafb5fb | ||
|
|
66781c3141 | ||
|
|
832475b271 | ||
|
|
6ccb8df101 | ||
|
|
fd0f41e4a5 | ||
|
|
0933575a5d | ||
|
|
818a8cb57a | ||
|
|
de0e6ba4cc | ||
|
|
30d983f45f | ||
|
|
d0c78dd62d | ||
|
|
551f0fafc8 | ||
|
|
2300f57294 | ||
|
|
f065327cc1 | ||
|
|
bce8bfb87f | ||
|
|
4ae8cc7bcf | ||
|
|
76955b74c3 | ||
|
|
baefdcb18d | ||
|
|
7aac157b7f | ||
|
|
2c26d98a89 | ||
|
|
c413151375 | ||
|
|
8098266c90 | ||
|
|
c8528b633a | ||
|
|
c591726079 | ||
|
|
9f724a22f3 | ||
|
|
c39fdd5cad |
@@ -1,5 +0,0 @@
|
||||
.depend
|
||||
*.lo
|
||||
libpri.so.1.0
|
||||
pritest
|
||||
|
||||
341
LICENSE
Normal file
341
LICENSE
Normal file
@@ -0,0 +1,341 @@
|
||||
|
||||
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.
|
||||
27
Makefile
Executable file → Normal file
27
Makefile
Executable file → Normal file
@@ -27,6 +27,9 @@
|
||||
# Uncomment if you want libpri to count number of Q921/Q931 sent/received
|
||||
#LIBPRI_COUNTERS=-DLIBPRI_COUNTERS
|
||||
|
||||
OSARCH=$(shell uname -s)
|
||||
PROC=$(shell uname -m)
|
||||
|
||||
TOBJS=testpri.o
|
||||
T2OBJS=testprilib.o
|
||||
STATIC_LIBRARY=libpri.a
|
||||
@@ -35,6 +38,22 @@ STATIC_OBJS=pri.o q921.o prisched.o q931.o
|
||||
DYNAMIC_OBJS=pri.lo q921.lo prisched.lo q931.lo
|
||||
CFLAGS=-Wall -Werror -Wstrict-prototypes -Wmissing-prototypes -g $(ALERTING) $(LIBPRI_COUNTERS)
|
||||
INSTALL_PREFIX=
|
||||
ifeq (${OSARCH},Linux)
|
||||
LDCONFIG_FLAGS=-n
|
||||
else
|
||||
ifeq (${OSARCH},FreeBSD)
|
||||
LDCONFIG_FLAGS=-m
|
||||
CFLAGS += -I../zaptel -I../zapata
|
||||
endif
|
||||
endif
|
||||
|
||||
#The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only.
|
||||
#This works for even old (2.96) versions of gcc and provides a small boost either way.
|
||||
#A ultrasparc cpu is really v9 but the stock debian stable 3.0 gcc doesnt support it.
|
||||
ifeq ($(PROC),sparc64)
|
||||
PROC=ultrasparc
|
||||
CFLAGS += -mtune=$(PROC) -O3 -pipe -fomit-frame-pointer -mcpu=v8
|
||||
endif
|
||||
|
||||
all: depend $(STATIC_LIBRARY) $(DYNAMIC_LIBRARY)
|
||||
|
||||
@@ -59,16 +78,16 @@ uninstall:
|
||||
rm -f $(INSTALL_PREFIX)/usr/include/libpri.h
|
||||
|
||||
pritest: pritest.o
|
||||
$(CC) -o pritest pritest.o -L. -lpri -lzap
|
||||
$(CC) -o pritest pritest.o -L. -lpri -lzap $(CFLAGS)
|
||||
|
||||
testprilib.o: testprilib.c
|
||||
$(CC) $(CFLAGS) -D_REENTRANT -D_GNU_SOURCE -o $@ -c $<
|
||||
|
||||
testprilib: testprilib.o
|
||||
$(CC) -o testprilib testprilib.o -L. -lpri -lpthread
|
||||
$(CC) -o testprilib testprilib.o -L. -lpri -lpthread $(CFLAGS)
|
||||
|
||||
pridump: pridump.o
|
||||
$(CC) -o pridump pridump.o -L. -lpri -lzap
|
||||
$(CC) -o pridump pridump.o -L. -lpri -lzap $(CFLAGS)
|
||||
|
||||
include .depend
|
||||
|
||||
@@ -81,7 +100,7 @@ $(STATIC_LIBRARY): $(STATIC_OBJS)
|
||||
|
||||
$(DYNAMIC_LIBRARY): $(DYNAMIC_OBJS)
|
||||
$(CC) -shared -Wl,-soname,libpri.so.1 -o $@ $(DYNAMIC_OBJS)
|
||||
/sbin/ldconfig -n .
|
||||
/sbin/ldconfig $(LDCONFIG_FLAGS) .
|
||||
ln -sf libpri.so.1 libpri.so
|
||||
|
||||
clean:
|
||||
|
||||
23
README
Executable file → Normal file
23
README
Executable file → Normal file
@@ -1,31 +1,40 @@
|
||||
libpri: An implementation of Primate Rate ISDN
|
||||
|
||||
Written by Mark Spencer <markster@linux-support.net>
|
||||
Written by Mark Spencer <markster@digium.com>
|
||||
|
||||
What is libpri?
|
||||
===============
|
||||
|
||||
libpri is a C implementation of the Primary Rate ISDN specification. It was
|
||||
based on the Bellcore specification SR-NWT-002343 for National ISDN. As of
|
||||
May 12, 2001, it has been tested work with NI-2, Nortel DMS-100, and Lucent 5E Custom protocols on switches from Nortel and Lucent.
|
||||
May 12, 2001, it has been tested work with NI-2, Nortel DMS-100, and
|
||||
Lucent 5E Custom protocols on switches from Nortel and Lucent.
|
||||
|
||||
What is the license for libpri?
|
||||
===============================
|
||||
libpri is distributed under the terms of the GNU General Public License, which permit its use and linking with other GPL'd software only.
|
||||
libpri is distributed under the terms of the GNU General Public License,
|
||||
which permit its use and linking with other GPL'd software only.
|
||||
The GNU GPL is included in the file LICENSE in this directory.
|
||||
|
||||
If you wish to use libpri in an application for which the GPL is not
|
||||
appropriate (e.g. a proprietary embedded system), licenses for libpri
|
||||
under more flexible terms can be readily obtained through Digium, Inc.
|
||||
at reasonable cost.
|
||||
|
||||
If you wish to use libpri in an application for which the GPL is not appropriate (e.g. a proprietary embedded system), licenses for libpri under more flexible terms can be readily obtained through Linux Support Services, Inc. at reasonable cost.
|
||||
|
||||
How do I report bugs or contribute?
|
||||
===================================
|
||||
For now, contact the author directly. In the future if there is sufficient interest, we will setup a mailing list.
|
||||
For now, contact the author directly. In the future if there is
|
||||
sufficient interest, we will setup a mailing list.
|
||||
|
||||
Does anything use this library so far?
|
||||
======================================
|
||||
Yes, the Asterisk Open Source PBX does. http://www.asteriskpbx.com
|
||||
Yes, the Asterisk Open Source PBX does. http://www.asterisk.org
|
||||
|
||||
Also, the Zapata library has hooks for it. http://www.zapatatelephony.org
|
||||
|
||||
Special thanks
|
||||
==============
|
||||
Special thanks to Jim Dixon <jim@lambdatel.com> for his help in testing and fixing the implementation.
|
||||
Special thanks to Jim Dixon <jim@lambdatel.com> for his help in
|
||||
testing and fixing the implementation.
|
||||
|
||||
|
||||
145
libpri.h
Executable file → Normal file
145
libpri.h
Executable file → Normal file
@@ -49,6 +49,10 @@
|
||||
#define PRI_SWITCH_EUROISDN_E1 5 /* Standard EuroISDN (CTR4, ETSI 300-102) */
|
||||
#define PRI_SWITCH_EUROISDN_T1 6 /* T1 EuroISDN variant (ETSI 300-102) */
|
||||
#define PRI_SWITCH_NI1 7 /* National ISDN 1 */
|
||||
#define PRI_SWITCH_GR303_EOC 8 /* GR-303 Embedded Operations Channel */
|
||||
#define PRI_SWITCH_GR303_TMC 9 /* GR-303 Timeslot Management Channel */
|
||||
/* Switchtypes 10 - 20 are reserved for internal use */
|
||||
|
||||
|
||||
/* PRI D-Channel Events */
|
||||
#define PRI_EVENT_DCHAN_UP 1 /* D-channel is up */
|
||||
@@ -66,6 +70,8 @@
|
||||
#define PRI_EVENT_PROCEEDING 13 /* When we get CALL_PROCEEDING or PROGRESS */
|
||||
#define PRI_EVENT_SETUP_ACK 14 /* When we get SETUP_ACKNOWLEDGE */
|
||||
#define PRI_EVENT_HANGUP_REQ 15 /* Requesting the higher layer to hangup */
|
||||
#define PRI_EVENT_NOTIFY 16 /* Notification received */
|
||||
#define PRI_EVENT_PROGRESS 17 /* When we get CALL_PROCEEDING or PROGRESS */
|
||||
|
||||
/* Simple states */
|
||||
#define PRI_STATE_DOWN 0
|
||||
@@ -180,8 +186,51 @@
|
||||
#define PRI_LAYER_1_V120_RATE_ADAPT 0x28
|
||||
#define PRI_LAYER_1_X31_RATE_ADAPT 0x29
|
||||
|
||||
/* Notifications */
|
||||
#define PRI_NOTIFY_USER_SUSPENDED 0x00 /* User suspended */
|
||||
#define PRI_NOTIFY_USER_RESUMED 0x01 /* User resumed */
|
||||
#define PRI_NOTIFY_BEARER_CHANGE 0x02 /* Bearer service change (DSS1) */
|
||||
#define PRI_NOTIFY_ASN1_COMPONENT 0x03 /* ASN.1 encoded component (DSS1) */
|
||||
#define PRI_NOTIFY_COMPLETION_DELAY 0x04 /* Call completion delay */
|
||||
#define PRI_NOTIFY_CONF_ESTABLISHED 0x42 /* Conference established */
|
||||
#define PRI_NOTIFY_CONF_DISCONNECTED 0x43 /* Conference disconnected */
|
||||
#define PRI_NOTIFY_CONF_PARTY_ADDED 0x44 /* Other party added */
|
||||
#define PRI_NOTIFY_CONF_ISOLATED 0x45 /* Isolated */
|
||||
#define PRI_NOTIFY_CONF_REATTACHED 0x46 /* Reattached */
|
||||
#define PRI_NOTIFY_CONF_OTHER_ISOLATED 0x47 /* Other party isolated */
|
||||
#define PRI_NOTIFY_CONF_OTHER_REATTACHED 0x48 /* Other party reattached */
|
||||
#define PRI_NOTIFY_CONF_OTHER_SPLIT 0x49 /* Other party split */
|
||||
#define PRI_NOTIFY_CONF_OTHER_DISCONNECTED 0x4a /* Other party disconnected */
|
||||
#define PRI_NOTIFY_CONF_FLOATING 0x4b /* Conference floating */
|
||||
#define PRI_NOTIFY_WAITING_CALL 0x60 /* Call is waiting call */
|
||||
#define PRI_NOTIFY_DIVERSION_ACTIVATED 0x68 /* Diversion activated (DSS1) */
|
||||
#define PRI_NOTIFY_TRANSFER_ALERTING 0x69 /* Call transfer, alerting */
|
||||
#define PRI_NOTIFY_TRANSFER_ACTIVE 0x6a /* Call transfer, active */
|
||||
#define PRI_NOTIFY_REMOTE_HOLD 0x79 /* Remote hold */
|
||||
#define PRI_NOTIFY_REMOTE_RETRIEVAL 0x7a /* Remote retrieval */
|
||||
#define PRI_NOTIFY_CALL_DIVERTING 0x7b /* Call is diverting */
|
||||
|
||||
#define PRI_COPY_DIGITS_CALLED_NUMBER
|
||||
|
||||
/* Network Specific Facilities (AT&T) */
|
||||
#define PRI_NSF_NONE -1
|
||||
#define PRI_NSF_SID_PREFERRED 0xB1
|
||||
#define PRI_NSF_ANI_PREFERRED 0xB2
|
||||
#define PRI_NSF_SID_ONLY 0xB3
|
||||
#define PRI_NSF_ANI_ONLY 0xB4
|
||||
#define PRI_NSF_CALL_ASSOC_TSC 0xB9
|
||||
#define PRI_NSF_NOTIF_CATSC_CLEARING 0xBA
|
||||
#define PRI_NSF_OPERATOR 0xB5
|
||||
#define PRI_NSF_PCCO 0xB6
|
||||
#define PRI_NSF_SDN 0xE1
|
||||
#define PRI_NSF_TOLL_FREE_MEGACOM 0xE2
|
||||
#define PRI_NSF_MEGACOM 0xE3
|
||||
#define PRI_NSF_ACCUNET 0xE6
|
||||
#define PRI_NSF_LONG_DISTANCE_SERVICE 0xE7
|
||||
#define PRI_NSF_INTERNATIONAL_TOLL_FREE 0xE8
|
||||
#define PRI_NSF_ATT_MULTIQUEST 0xF0
|
||||
#define PRI_NSF_CALL_REDIRECTION_SERVICE 0xF7
|
||||
|
||||
typedef struct q931_call q931_call;
|
||||
|
||||
typedef struct pri_event_generic {
|
||||
@@ -230,6 +279,7 @@ typedef struct pri_event_ring {
|
||||
char callingnum[256]; /* Calling number */
|
||||
char callingname[256]; /* Calling name (if provided) */
|
||||
int calledplan; /* Dialing plan of Called number */
|
||||
int ani2; /* ANI II */
|
||||
char callednum[256]; /* Called number */
|
||||
char redirectingnum[256]; /* Redirecting number */
|
||||
char useruserinfo[256]; /* User->User info */
|
||||
@@ -239,6 +289,7 @@ typedef struct pri_event_ring {
|
||||
int layer1; /* User layer 1 */
|
||||
int complete; /* Have we seen "Complete" i.e. no more number? */
|
||||
q931_call *call; /* Opaque call pointer */
|
||||
char callingsubaddr[256]; /* Calling parties subaddress */
|
||||
} pri_event_ring;
|
||||
|
||||
typedef struct pri_event_hangup {
|
||||
@@ -264,6 +315,12 @@ typedef struct pri_event_setup_ack {
|
||||
int channel;
|
||||
} pri_event_setup_ack;
|
||||
|
||||
typedef struct pri_event_notify {
|
||||
int e;
|
||||
int channel;
|
||||
int info;
|
||||
} pri_event_notify;
|
||||
|
||||
typedef union {
|
||||
int e;
|
||||
pri_event_generic gen; /* Generic view */
|
||||
@@ -277,9 +334,11 @@ typedef union {
|
||||
pri_event_restart_ack restartack; /* Restart Acknowledge */
|
||||
pri_event_proceeding proceeding; /* Call proceeding & Progress */
|
||||
pri_event_setup_ack setup_ack; /* SETUP_ACKNOWLEDGE structure */
|
||||
pri_event_notify notify; /* Notification */
|
||||
} pri_event;
|
||||
|
||||
struct pri;
|
||||
struct pri_sr;
|
||||
|
||||
|
||||
/* Create a D-channel on a given file descriptor. The file descriptor must be a
|
||||
@@ -288,6 +347,9 @@ struct pri;
|
||||
must be one of PRI_NETWORK or PRI_CPE. switchtype should be PRI_SWITCH_* */
|
||||
extern struct pri *pri_new(int fd, int nodetype, int switchtype);
|
||||
|
||||
/* Set Network Specific Facility for PRI */
|
||||
extern void pri_set_nsf(struct pri *pri, int nsf);
|
||||
|
||||
/* Set debug parameters on PRI -- see above debug definitions */
|
||||
extern void pri_set_debug(struct pri *pri, int debug);
|
||||
|
||||
@@ -338,14 +400,8 @@ extern int pri_need_more_info(struct pri *pri, q931_call *call, int channel, int
|
||||
Set non-isdn to non-zero if you are not connecting to ISDN equipment */
|
||||
extern int pri_answer(struct pri *pri, q931_call *call, int channel, int nonisdn);
|
||||
|
||||
#if 0
|
||||
/* deprecated routines, use pri_hangup */
|
||||
/* Release/Reject a call */
|
||||
extern int pri_release(struct pri *pri, q931_call *call, int cause);
|
||||
/* Set CRV reference for GR-303 calls */
|
||||
|
||||
/* Hangup / Disconnect a call */
|
||||
extern int pri_disconnect(struct pri *pri, q931_call *call, int cause);
|
||||
#endif
|
||||
|
||||
#undef pri_release
|
||||
#undef pri_disconnect
|
||||
@@ -369,6 +425,12 @@ extern int pri_reset(struct pri *pri, int channel);
|
||||
/* Create a new call */
|
||||
extern q931_call *pri_new_call(struct pri *pri);
|
||||
|
||||
/* Retrieve CRV reference for GR-303 calls. Returns >0 on success. */
|
||||
extern int pri_get_crv(struct pri *pri, q931_call *call, int *callmode);
|
||||
|
||||
/* Retrieve CRV reference for GR-303 calls. CRV must be >0, call mode should be 0 */
|
||||
extern int pri_set_crv(struct pri *pri, q931_call *call, int crv, int callmode);
|
||||
|
||||
/* How long until you need to poll for a new event */
|
||||
extern struct timeval *pri_schedule_next(struct pri *pri);
|
||||
|
||||
@@ -378,6 +440,16 @@ extern pri_event *pri_schedule_run(struct pri *pri);
|
||||
extern int pri_call(struct pri *pri, q931_call *c, int transmode, int channel,
|
||||
int exclusive, int nonisdn, char *caller, int callerplan, char *callername, int callerpres,
|
||||
char *called,int calledplan, int ulayer1);
|
||||
|
||||
extern struct pri_sr *pri_sr_new(void);
|
||||
extern void pri_sr_free(struct pri_sr *sr);
|
||||
|
||||
extern int pri_sr_set_channel(struct pri_sr *sr, int channel, int exclusive, int nonisdn);
|
||||
extern int pri_sr_set_bearer(struct pri_sr *sr, int transmode, int userl1);
|
||||
extern int pri_sr_set_called(struct pri_sr *sr, char *called, int calledplan, int complete);
|
||||
extern int pri_sr_set_caller(struct pri_sr *sr, char *caller, char *callername, int callerplan, int callerpres);
|
||||
|
||||
extern int pri_setup(struct pri *pri, q931_call *call, struct pri_sr *req);
|
||||
|
||||
/* Override message and error stuff */
|
||||
extern void pri_set_message(void (*__pri_error)(char *));
|
||||
@@ -393,4 +465,63 @@ extern void pri_dump_info(struct pri *pri);
|
||||
/* Get file descriptor */
|
||||
extern int pri_fd(struct pri *pri);
|
||||
|
||||
#define PRI_PROGRESS
|
||||
/* Send call proceeding */
|
||||
extern int pri_progress(struct pri *pri, q931_call *c, int channel, int info);
|
||||
|
||||
#define PRI_PROCEEDING_FULL
|
||||
/* Send call proceeding */
|
||||
extern int pri_proceeding(struct pri *pri, q931_call *c, int channel, int info);
|
||||
|
||||
/* Enslave a PRI to another, so they share the same call list
|
||||
(and maybe some timers) */
|
||||
extern void pri_enslave(struct pri *master, struct pri *slave);
|
||||
|
||||
#define PRI_GR303_SUPPORT
|
||||
#define PRI_ENSLAVE_SUPPORT
|
||||
#define PRI_SETUP_CALL
|
||||
#define PRI_RECEIVE_SUBADDR
|
||||
|
||||
/* Send notification */
|
||||
extern int pri_notify(struct pri *pri, q931_call *c, int channel, int info);
|
||||
|
||||
/* Get/Set PRI Timers */
|
||||
#define PRI_GETSET_TIMERS
|
||||
extern int pri_set_timer(struct pri *pri, int timer, int value);
|
||||
extern int pri_get_timer(struct pri *pri, int timer);
|
||||
extern int pri_timer2idx(char *timer);
|
||||
|
||||
#define PRI_MAX_TIMERS 32
|
||||
|
||||
#define PRI_TIMER_N200 0 /* Maximum numer of q921 retransmissions */
|
||||
#define PRI_TIMER_N201 1 /* Maximum numer of octets in an information field */
|
||||
#define PRI_TIMER_N202 2 /* Maximum numer of transmissions of the TEI identity request message */
|
||||
#define PRI_TIMER_K 3 /* Maximum number of outstanding I-frames */
|
||||
|
||||
#define PRI_TIMER_T200 4 /* time between SABME's */
|
||||
#define PRI_TIMER_T201 5 /* minimum time between retransmissions of the TEI Identity check messages */
|
||||
#define PRI_TIMER_T202 6 /* minimum time between transmission of TEI Identity request messages */
|
||||
#define PRI_TIMER_T203 7 /* maxiumum time without exchanging packets */
|
||||
|
||||
#define PRI_TIMER_T300 8
|
||||
#define PRI_TIMER_T301 9 /* maximum time to respond to an ALERT */
|
||||
#define PRI_TIMER_T302 10
|
||||
#define PRI_TIMER_T303 11 /* maximum time to wait after sending a SETUP without a response */
|
||||
#define PRI_TIMER_T304 12
|
||||
#define PRI_TIMER_T305 13
|
||||
#define PRI_TIMER_T306 14
|
||||
#define PRI_TIMER_T307 15
|
||||
#define PRI_TIMER_T308 16
|
||||
#define PRI_TIMER_T309 17
|
||||
#define PRI_TIMER_T310 18 /* maximum time between receiving a CALLPROCEEDING and receiving a ALERT/CONNECT/DISCONNECT/PROGRESS */
|
||||
#define PRI_TIMER_T313 19
|
||||
#define PRI_TIMER_T314 20
|
||||
#define PRI_TIMER_T316 21 /* maximum time between transmitting a RESTART and receiving a RESTART ACK */
|
||||
#define PRI_TIMER_T317 22
|
||||
#define PRI_TIMER_T318 23
|
||||
#define PRI_TIMER_T319 24
|
||||
#define PRI_TIMER_T320 25
|
||||
#define PRI_TIMER_T321 26
|
||||
#define PRI_TIMER_T322 27
|
||||
|
||||
#endif
|
||||
|
||||
4
mkdep
4
mkdep
@@ -82,9 +82,9 @@ umask $um
|
||||
trap 'rm -rf $DTMP ; trap 2 ; kill -2 $$' 1 2 3 13 15
|
||||
|
||||
if [ x$pflag = x ]; then
|
||||
${CC:-cc} -M "$@" | sed -e 's; \./; ;g' > $TMP
|
||||
${CC:-cc} -M "$@" 2>/dev/null | sed -e 's; \./; ;g' > $TMP
|
||||
else
|
||||
${CC:-cc} -M "$@" | sed -e 's;\.o :; :;' -e 's; \./; ;g' > $TMP
|
||||
${CC:-cc} -M "$@" 2>/dev/null | sed -e 's;\.o :; :;' -e 's; \./; ;g' > $TMP
|
||||
fi
|
||||
|
||||
if [ $? != 0 ]; then
|
||||
|
||||
260
pri.c
Executable file → Normal file
260
pri.c
Executable file → Normal file
@@ -23,6 +23,7 @@
|
||||
#include "pri_internal.h"
|
||||
#include "pri_q921.h"
|
||||
#include "pri_q931.h"
|
||||
#include "pri_timers.h"
|
||||
|
||||
char *pri_node2str(int node)
|
||||
{
|
||||
@@ -53,12 +54,102 @@ char *pri_switch2str(int sw)
|
||||
return "National ISDN 1";
|
||||
case PRI_SWITCH_EUROISDN_E1:
|
||||
return "EuroISDN";
|
||||
case PRI_SWITCH_GR303_EOC:
|
||||
return "GR303 EOC";
|
||||
case PRI_SWITCH_GR303_TMC:
|
||||
return "GR303 TMC";
|
||||
default:
|
||||
return "Unknown switchtype";
|
||||
}
|
||||
}
|
||||
|
||||
struct pri *pri_new(int fd, int node, int switchtype)
|
||||
static void pri_default_timers(struct pri *pri, int switchtype)
|
||||
{
|
||||
int defaulttimers[20][PRI_MAX_TIMERS] = PRI_TIMERS_ALL;
|
||||
int x;
|
||||
|
||||
for (x = 0; x<PRI_MAX_TIMERS; x++) {
|
||||
pri->timers[x] = defaulttimers[switchtype][x];
|
||||
}
|
||||
}
|
||||
|
||||
int pri_set_timer(struct pri *pri, int timer, int value)
|
||||
{
|
||||
if (timer < 0 || timer > PRI_MAX_TIMERS || value < 0)
|
||||
return -1;
|
||||
|
||||
pri->timers[timer] = value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pri_get_timer(struct pri *pri, int timer)
|
||||
{
|
||||
if (timer < 0 || timer > PRI_MAX_TIMERS)
|
||||
return -1;
|
||||
return pri->timers[timer];
|
||||
}
|
||||
|
||||
int pri_timer2idx(char *timer)
|
||||
{
|
||||
if (!strcasecmp(timer, "N200"))
|
||||
return PRI_TIMER_N200;
|
||||
else if (!strcasecmp(timer, "N201"))
|
||||
return PRI_TIMER_N201;
|
||||
else if (!strcasecmp(timer, "N202"))
|
||||
return PRI_TIMER_N202;
|
||||
else if (!strcasecmp(timer, "K"))
|
||||
return PRI_TIMER_K;
|
||||
else if (!strcasecmp(timer, "T200"))
|
||||
return PRI_TIMER_T200;
|
||||
else if (!strcasecmp(timer, "T202"))
|
||||
return PRI_TIMER_T202;
|
||||
else if (!strcasecmp(timer, "T203"))
|
||||
return PRI_TIMER_T203;
|
||||
else if (!strcasecmp(timer, "T300"))
|
||||
return PRI_TIMER_T300;
|
||||
else if (!strcasecmp(timer, "T301"))
|
||||
return PRI_TIMER_T301;
|
||||
else if (!strcasecmp(timer, "T302"))
|
||||
return PRI_TIMER_T302;
|
||||
else if (!strcasecmp(timer, "T303"))
|
||||
return PRI_TIMER_T303;
|
||||
else if (!strcasecmp(timer, "T304"))
|
||||
return PRI_TIMER_T304;
|
||||
else if (!strcasecmp(timer, "T305"))
|
||||
return PRI_TIMER_T305;
|
||||
else if (!strcasecmp(timer, "T306"))
|
||||
return PRI_TIMER_T306;
|
||||
else if (!strcasecmp(timer, "T307"))
|
||||
return PRI_TIMER_T307;
|
||||
else if (!strcasecmp(timer, "T308"))
|
||||
return PRI_TIMER_T308;
|
||||
else if (!strcasecmp(timer, "T309"))
|
||||
return PRI_TIMER_T309;
|
||||
else if (!strcasecmp(timer, "T310"))
|
||||
return PRI_TIMER_T310;
|
||||
else if (!strcasecmp(timer, "T313"))
|
||||
return PRI_TIMER_T313;
|
||||
else if (!strcasecmp(timer, "T314"))
|
||||
return PRI_TIMER_T314;
|
||||
else if (!strcasecmp(timer, "T316"))
|
||||
return PRI_TIMER_T316;
|
||||
else if (!strcasecmp(timer, "T317"))
|
||||
return PRI_TIMER_T317;
|
||||
else if (!strcasecmp(timer, "T318"))
|
||||
return PRI_TIMER_T318;
|
||||
else if (!strcasecmp(timer, "T319"))
|
||||
return PRI_TIMER_T319;
|
||||
else if (!strcasecmp(timer, "T320"))
|
||||
return PRI_TIMER_T320;
|
||||
else if (!strcasecmp(timer, "T321"))
|
||||
return PRI_TIMER_T321;
|
||||
else if (!strcasecmp(timer, "T322"))
|
||||
return PRI_TIMER_T322;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
static struct pri *__pri_new(int fd, int node, int switchtype, struct pri *master)
|
||||
{
|
||||
struct pri *p;
|
||||
p = malloc(sizeof(struct pri));
|
||||
@@ -68,18 +159,64 @@ struct pri *pri_new(int fd, int node, int switchtype)
|
||||
p->localtype = node;
|
||||
p->switchtype = switchtype;
|
||||
p->cref = 1;
|
||||
p->sapi = Q921_SAPI_CALL_CTRL;
|
||||
p->tei = 0;
|
||||
p->nsf = PRI_NSF_NONE;
|
||||
p->protodisc = Q931_PROTOCOL_DISCRIMINATOR;
|
||||
p->master = master;
|
||||
p->callpool = &p->localpool;
|
||||
pri_default_timers(p, switchtype);
|
||||
#ifdef LIBPRI_COUNTERS
|
||||
p->q921_rxcount = 0;
|
||||
p->q921_txcount = 0;
|
||||
p->q931_rxcount = 0;
|
||||
p->q931_txcount = 0;
|
||||
#endif
|
||||
if (switchtype == PRI_SWITCH_GR303_EOC) {
|
||||
p->protodisc = GR303_PROTOCOL_DISCRIMINATOR;
|
||||
p->sapi = Q921_SAPI_GR303_EOC;
|
||||
p->tei = Q921_TEI_GR303_EOC_OPS;
|
||||
p->subchannel = __pri_new(-1, node, PRI_SWITCH_GR303_EOC_PATH, p);
|
||||
if (!p->subchannel) {
|
||||
free(p);
|
||||
p = NULL;
|
||||
}
|
||||
} else if (switchtype == PRI_SWITCH_GR303_TMC) {
|
||||
p->protodisc = GR303_PROTOCOL_DISCRIMINATOR;
|
||||
p->sapi = Q921_SAPI_GR303_TMC_CALLPROC;
|
||||
p->tei = Q921_TEI_GR303_TMC_CALLPROC;
|
||||
p->subchannel = __pri_new(-1, node, PRI_SWITCH_GR303_TMC_SWITCHING, p);
|
||||
if (!p->subchannel) {
|
||||
free(p);
|
||||
p = NULL;
|
||||
}
|
||||
} else if (switchtype == PRI_SWITCH_GR303_TMC_SWITCHING) {
|
||||
p->protodisc = GR303_PROTOCOL_DISCRIMINATOR;
|
||||
p->sapi = Q921_SAPI_GR303_TMC_SWITCHING;
|
||||
p->tei = Q921_TEI_GR303_TMC_SWITCHING;
|
||||
} else if (switchtype == PRI_SWITCH_GR303_EOC_PATH) {
|
||||
p->protodisc = GR303_PROTOCOL_DISCRIMINATOR;
|
||||
p->sapi = Q921_SAPI_GR303_EOC;
|
||||
p->tei = Q921_TEI_GR303_EOC_PATH;
|
||||
}
|
||||
/* Start Q.921 layer, Wait if we're the network */
|
||||
q921_start(p, p->localtype == PRI_CPE);
|
||||
if (p)
|
||||
q921_start(p, p->localtype == PRI_CPE);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
struct pri *pri_new(int fd, int node, int switchtype)
|
||||
{
|
||||
return __pri_new(fd, node, switchtype, NULL);
|
||||
}
|
||||
|
||||
void pri_set_nsf(struct pri *pri, int nsf)
|
||||
{
|
||||
if (pri)
|
||||
pri->nsf = nsf;
|
||||
}
|
||||
|
||||
char *pri_event2str(int id)
|
||||
{
|
||||
switch(id) {
|
||||
@@ -182,6 +319,8 @@ void pri_set_debug(struct pri *pri, int debug)
|
||||
if (!pri)
|
||||
return;
|
||||
pri->debug = debug;
|
||||
if (pri->subchannel)
|
||||
pri_set_debug(pri->subchannel, debug);
|
||||
}
|
||||
|
||||
int pri_acknowledge(struct pri *pri, q931_call *call, int channel, int info)
|
||||
@@ -191,6 +330,20 @@ int pri_acknowledge(struct pri *pri, q931_call *call, int channel, int info)
|
||||
return q931_alerting(pri, call, channel, info);
|
||||
}
|
||||
|
||||
int pri_proceeding(struct pri *pri, q931_call *call, int channel, int info)
|
||||
{
|
||||
if (!pri || !call)
|
||||
return -1;
|
||||
return q931_call_proceeding(pri, call, channel, info);
|
||||
}
|
||||
|
||||
int pri_progress(struct pri *pri, q931_call *call, int channel, int info)
|
||||
{
|
||||
if (!pri || !call)
|
||||
return -1;
|
||||
return q931_call_progress(pri, call, channel, info);
|
||||
}
|
||||
|
||||
int pri_information(struct pri *pri, q931_call *call, char digit)
|
||||
{
|
||||
if (!pri || !call)
|
||||
@@ -198,6 +351,13 @@ int pri_information(struct pri *pri, q931_call *call, char digit)
|
||||
return q931_information(pri, call, digit);
|
||||
}
|
||||
|
||||
int pri_notify(struct pri *pri, q931_call *call, int channel, int info)
|
||||
{
|
||||
if (!pri || !call)
|
||||
return -1;
|
||||
return q931_notify(pri, call, channel, info);
|
||||
}
|
||||
|
||||
void pri_destroycall(struct pri *pri, q931_call *call)
|
||||
{
|
||||
if (pri && call)
|
||||
@@ -287,13 +447,39 @@ void pri_dump_event(struct pri *pri, pri_event *e)
|
||||
}
|
||||
}
|
||||
|
||||
static void pri_sr_init(struct pri_sr *req)
|
||||
{
|
||||
memset(req, 0, sizeof(struct pri_sr));
|
||||
|
||||
}
|
||||
|
||||
int pri_setup(struct pri *pri, q931_call *c, struct pri_sr *req)
|
||||
{
|
||||
if (!pri || !c)
|
||||
return -1;
|
||||
return q931_setup(pri, c, req);
|
||||
}
|
||||
|
||||
int pri_call(struct pri *pri, q931_call *c, int transmode, int channel, int exclusive,
|
||||
int nonisdn, char *caller, int callerplan, char *callername, int callerpres, char *called,
|
||||
int calledplan,int ulayer1)
|
||||
{
|
||||
struct pri_sr req;
|
||||
if (!pri || !c)
|
||||
return -1;
|
||||
return q931_setup(pri, c, transmode, channel, exclusive, nonisdn, caller, callerplan, callername, callerpres, called, calledplan, ulayer1);
|
||||
pri_sr_init(&req);
|
||||
req.transmode = transmode;
|
||||
req.channel = channel;
|
||||
req.exclusive = exclusive;
|
||||
req.nonisdn = nonisdn;
|
||||
req.caller = caller;
|
||||
req.callerplan = callerplan;
|
||||
req.callername = callername;
|
||||
req.callerpres = callerpres;
|
||||
req.called = called;
|
||||
req.calledplan = calledplan;
|
||||
req.userl1 = ulayer1;
|
||||
return q931_setup(pri, c, &req);
|
||||
}
|
||||
|
||||
static void (*__pri_error)(char *stuff);
|
||||
@@ -376,5 +562,73 @@ void pri_dump_info(struct pri *pri)
|
||||
pri_message("Retrans: %d\n", pri->retrans);
|
||||
pri_message("Busy: %d\n", pri->busy);
|
||||
pri_message("Overlap Dial: %d\n", pri->overlapdial);
|
||||
pri_message("T200 Timer: %d\n", pri->timers[PRI_TIMER_T200]);
|
||||
pri_message("T203 Timer: %d\n", pri->timers[PRI_TIMER_T203]);
|
||||
pri_message("T305 Timer: %d\n", pri->timers[PRI_TIMER_T305]);
|
||||
pri_message("T308 Timer: %d\n", pri->timers[PRI_TIMER_T308]);
|
||||
pri_message("T313 Timer: %d\n", pri->timers[PRI_TIMER_T313]);
|
||||
pri_message("N200 Counter: %d\n", pri->timers[PRI_TIMER_N200]);
|
||||
}
|
||||
|
||||
int pri_get_crv(struct pri *pri, q931_call *call, int *callmode)
|
||||
{
|
||||
return q931_call_getcrv(pri, call, callmode);
|
||||
}
|
||||
|
||||
int pri_set_crv(struct pri *pri, q931_call *call, int crv, int callmode)
|
||||
{
|
||||
return q931_call_setcrv(pri, call, crv, callmode);
|
||||
}
|
||||
|
||||
void pri_enslave(struct pri *master, struct pri *slave)
|
||||
{
|
||||
if (master && slave)
|
||||
slave->callpool = &master->localpool;
|
||||
}
|
||||
|
||||
struct pri_sr *pri_sr_new(void)
|
||||
{
|
||||
struct pri_sr *req;
|
||||
req = malloc(sizeof(struct pri_sr));
|
||||
if (req)
|
||||
pri_sr_init(req);
|
||||
return req;
|
||||
}
|
||||
|
||||
void pri_sr_free(struct pri_sr *sr)
|
||||
{
|
||||
free(sr);
|
||||
}
|
||||
|
||||
int pri_sr_set_channel(struct pri_sr *sr, int channel, int exclusive, int nonisdn)
|
||||
{
|
||||
sr->channel = channel;
|
||||
sr->exclusive = exclusive;
|
||||
sr->nonisdn = nonisdn;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pri_sr_set_bearer(struct pri_sr *sr, int transmode, int userl1)
|
||||
{
|
||||
sr->transmode = transmode;
|
||||
sr->userl1 = userl1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pri_sr_set_called(struct pri_sr *sr, char *called, int calledplan, int numcomplete)
|
||||
{
|
||||
sr->called = called;
|
||||
sr->calledplan = calledplan;
|
||||
sr->numcomplete = numcomplete;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pri_sr_set_caller(struct pri_sr *sr, char *caller, char *callername, int callerplan, int callerpres)
|
||||
{
|
||||
sr->caller = caller;
|
||||
sr->callername = callername;
|
||||
sr->callerplan = callerplan;
|
||||
sr->callerpres = callerpres;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
35
pri_internal.h
Executable file → Normal file
35
pri_internal.h
Executable file → Normal file
@@ -40,14 +40,23 @@ enum q931_mode;
|
||||
/* No more than 128 scheduled events */
|
||||
#define MAX_SCHED 128
|
||||
|
||||
#define MAX_TIMERS 32
|
||||
|
||||
struct pri {
|
||||
int fd; /* File descriptor for D-Channel */
|
||||
struct pri *subchannel; /* Sub-channel if appropriate */
|
||||
struct pri *master; /* Master channel if appropriate */
|
||||
struct pri_sched pri_sched[MAX_SCHED]; /* Scheduled events */
|
||||
int debug; /* Debug stuff */
|
||||
int state; /* State of D-channel */
|
||||
int switchtype; /* Switch type */
|
||||
int nsf; /* Network-Specific Facility (if any) */
|
||||
int localtype; /* Local network type (unknown, network, cpe) */
|
||||
int remotetype; /* Remote network type (unknown, network, cpe) */
|
||||
|
||||
int sapi;
|
||||
int tei;
|
||||
int protodisc;
|
||||
|
||||
/* Q.921 State */
|
||||
int q921_state;
|
||||
@@ -69,7 +78,9 @@ struct pri {
|
||||
int sabme_timer; /* SABME retransmit */
|
||||
int t203_timer; /* Max idle time */
|
||||
int t200_timer; /* T-200 retransmission timer */
|
||||
|
||||
/* All ISDN Timer values */
|
||||
int timers[MAX_TIMERS];
|
||||
|
||||
/* Used by scheduler */
|
||||
struct timeval tv;
|
||||
int schedev;
|
||||
@@ -79,7 +90,8 @@ struct pri {
|
||||
struct q921_frame *txqueue;
|
||||
|
||||
/* Q.931 calls */
|
||||
q931_call *calls;
|
||||
q931_call **callpool;
|
||||
q931_call *localpool;
|
||||
|
||||
/* do we do overlap dialing */
|
||||
int overlapdial;
|
||||
@@ -93,6 +105,25 @@ struct pri {
|
||||
#endif
|
||||
};
|
||||
|
||||
struct pri_sr {
|
||||
int transmode;
|
||||
int channel;
|
||||
int exclusive;
|
||||
int nonisdn;
|
||||
char *caller;
|
||||
int callerplan;
|
||||
char *callername;
|
||||
int callerpres;
|
||||
char *called;
|
||||
int calledplan;
|
||||
int userl1;
|
||||
int numcomplete;
|
||||
};
|
||||
|
||||
/* Internal switch types */
|
||||
#define PRI_SWITCH_GR303_EOC_PATH 10
|
||||
#define PRI_SWITCH_GR303_TMC_SWITCHING 11
|
||||
|
||||
extern int pri_schedule_event(struct pri *pri, int ms, void (*function)(void *data), void *data);
|
||||
|
||||
extern pri_event *pri_schedule_run(struct pri *pri);
|
||||
|
||||
18
pri_q921.h
Executable file → Normal file
18
pri_q921.h
Executable file → Normal file
@@ -26,15 +26,16 @@
|
||||
#define _PRI_Q921_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#if defined(__linux__)
|
||||
#include <endian.h>
|
||||
#elif defined(__FreeBSD__)
|
||||
#include <sys/endian.h>
|
||||
#endif
|
||||
|
||||
/* Timer values */
|
||||
|
||||
#define T_WAIT_MIN 2000
|
||||
#define T_WAIT_MAX 10000
|
||||
#define T_200 1000 /* 1 second between SABME's */
|
||||
#define T_203 10000 /* 10 seconds with no packets max */
|
||||
#define N_200 3 /* 3 retries */
|
||||
|
||||
#define Q921_FRAMETYPE_MASK 0x3
|
||||
|
||||
@@ -43,8 +44,17 @@
|
||||
#define Q921_FRAMETYPE_S 0x1
|
||||
|
||||
#define Q921_TEI_GROUP 127
|
||||
#define Q921_TEI_GR303_EOC_PATH 0
|
||||
#define Q921_TEI_GR303_EOC_OPS 4
|
||||
#define Q921_TEI_GR303_TMC_SWITCHING 0
|
||||
#define Q921_TEI_GR303_TMC_CALLPROC 0
|
||||
|
||||
#define Q921_SAPI_CALL_CTRL 0
|
||||
#define Q921_SAPI_GR303_EOC 1
|
||||
#define Q921_SAPI_GR303_TMC_SWITCHING 1
|
||||
#define Q921_SAPI_GR303_TMC_CALLPROC 0
|
||||
|
||||
|
||||
#define Q921_SAPI_CALL_CTRL 0
|
||||
#define Q921_SAPI_PACKET_MODE 1
|
||||
#define Q921_SAPI_X25_LAYER3 16
|
||||
#define Q921_SAPI_LAYER2_MANAGEMENT 63
|
||||
|
||||
35
pri_q931.h
Executable file → Normal file
35
pri_q931.h
Executable file → Normal file
@@ -98,13 +98,7 @@ typedef struct q931_mh {
|
||||
|
||||
/* Information element format */
|
||||
typedef struct q931_ie {
|
||||
#if __BYTE_ORDER == __BIG_ENDIAN
|
||||
u_int8_t f:1;
|
||||
u_int8_t ie:7;
|
||||
#else
|
||||
u_int8_t ie:7;
|
||||
u_int8_t f:1;
|
||||
#endif
|
||||
u_int8_t ie;
|
||||
u_int8_t len;
|
||||
u_int8_t data[0];
|
||||
} q931_ie;
|
||||
@@ -113,6 +107,7 @@ typedef struct q931_ie {
|
||||
#define Q931_RES_INERRROR (1 << 1)
|
||||
|
||||
#define Q931_PROTOCOL_DISCRIMINATOR 0x08
|
||||
#define GR303_PROTOCOL_DISCRIMINATOR 0x4f
|
||||
|
||||
/* Q.931 / National ISDN Message Types */
|
||||
|
||||
@@ -165,6 +160,7 @@ typedef struct q931_ie {
|
||||
|
||||
/* Q.931 / National ISDN Information Elements */
|
||||
#define Q931_LOCKING_SHIFT 0x90
|
||||
#define Q931_NON_LOCKING_SHIFT 0x98
|
||||
#define Q931_BEARER_CAPABILITY 0x04
|
||||
#define Q931_CAUSE 0x08
|
||||
#define Q931_CALL_STATE 0x14
|
||||
@@ -190,10 +186,17 @@ typedef struct q931_ie {
|
||||
#define Q931_LOW_LAYER_COMPAT 0x7c
|
||||
#define Q931_HIGH_LAYER_COMPAT 0x7d
|
||||
|
||||
#define Q931_CODESET(x) ((x) << 8)
|
||||
#define Q931_IE_CODESET(x) ((x) >> 8)
|
||||
#define Q931_IE_IE(x) ((x) & 0xff)
|
||||
#define Q931_FULL_IE(codeset, ie) (((codeset) << 8) | ((ie) & 0xff))
|
||||
|
||||
#define Q931_DISPLAY 0x28
|
||||
#define Q931_IE_SEGMENTED_MSG 0x00
|
||||
#define Q931_IE_CHANGE_STATUS 0x01
|
||||
#define Q931_IE_CONNECTED_NUM 0x0C
|
||||
#define Q931_IE_ORIGINATING_LINE_INFO (0x01 | Q931_CODESET(6))
|
||||
#define Q931_IE_CONNECTED_ADDR 0x0C
|
||||
#define Q931_IE_CONNECTED_NUM 0x4C
|
||||
#define Q931_IE_CALL_IDENTITY 0x10
|
||||
#define Q931_IE_FACILITY 0x1c
|
||||
#define Q931_IE_ENDPOINT_ID 0x26
|
||||
@@ -237,13 +240,17 @@ typedef struct q931_ie {
|
||||
|
||||
|
||||
/* EuroISDN */
|
||||
#define Q931_SENDING_COMPLETE 0x21
|
||||
#define Q931_SENDING_COMPLETE 0xa1
|
||||
|
||||
extern int q931_receive(struct pri *pri, q931_h *h, int len);
|
||||
|
||||
extern int q931_alerting(struct pri *pri, q931_call *call, int channel, int info);
|
||||
|
||||
extern int q931_call_proceeding(struct pri *pri, q931_call *call);
|
||||
extern int q931_call_progress(struct pri *pri, q931_call *call, int channel, int info);
|
||||
|
||||
extern int q931_notify(struct pri *pri, q931_call *call, int channel, int info);
|
||||
|
||||
extern int q931_call_proceeding(struct pri *pri, q931_call *call, int channel, int info);
|
||||
|
||||
extern int q931_setup_ack(struct pri *pri, q931_call *call, int channel, int nonisdn);
|
||||
|
||||
@@ -259,11 +266,13 @@ extern int q931_hangup(struct pri *pri, q931_call *call, int cause);
|
||||
|
||||
extern int q931_restart(struct pri *pri, int channel);
|
||||
|
||||
extern int q931_call_getcrv(struct pri *pri, q931_call *call, int *callmode);
|
||||
|
||||
extern int q931_call_setcrv(struct pri *pri, q931_call *call, int crv, int callmode);
|
||||
|
||||
extern q931_call *q931_new_call(struct pri *pri);
|
||||
|
||||
extern int q931_setup(struct pri *pri, q931_call *c, int transmode, int channel, int exclusive,
|
||||
int nonisdn, char *caller, int callerplan, char *callername, int callerpres, char *called,
|
||||
int calledplan, int ulay1);
|
||||
extern int q931_setup(struct pri *pri, q931_call *c, struct pri_sr *req);
|
||||
extern void q931_dump(q931_h *h, int len, int txrx);
|
||||
|
||||
extern void __q931_destroycall(struct pri *pri, q931_call *c);
|
||||
|
||||
83
pri_timers.h
Normal file
83
pri_timers.h
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* libpri: An implementation of Primary Rate ISDN
|
||||
*
|
||||
* Written by Mark Spencer <markster@linux-support.net>
|
||||
*
|
||||
* Copyright (C) 2001, Linux Support Services, Inc.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _PRI_TIMERS_H
|
||||
#define _PRI_TIMERS_H
|
||||
|
||||
/* -1 means we dont currently support the timer/counter */
|
||||
#define PRI_TIMERS_DEFAULT { 3, /* N200 */ \
|
||||
-1, /* N201 */ \
|
||||
-1, /* N202 */ \
|
||||
7, /* K */ \
|
||||
1000, /* T200 */ \
|
||||
-1, /* T201 */ \
|
||||
-1, /* T202 */ \
|
||||
10000, /* T203 */ \
|
||||
-1, /* T300 */ \
|
||||
-1, /* T301 */ \
|
||||
-1, /* T302 */ \
|
||||
-1, /* T303 */ \
|
||||
-1, /* T304 */ \
|
||||
30000, /* T305 */ \
|
||||
-1, /* T306 */ \
|
||||
-1, /* T307 */ \
|
||||
4000, /* T308 */ \
|
||||
-1, /* T309 */ \
|
||||
-1, /* T310 */ \
|
||||
4000, /* T313 */ \
|
||||
-1, /* T314 */ \
|
||||
-1, /* T316 */ \
|
||||
-1, /* T317 */ \
|
||||
-1, /* T318 */ \
|
||||
-1, /* T319 */ \
|
||||
-1, /* T320 */ \
|
||||
-1, /* T321 */ \
|
||||
-1 /* T322 */ \
|
||||
}
|
||||
|
||||
/* XXX Only our default timers are setup now XXX */
|
||||
#define PRI_TIMERS_UNKNOWN PRI_TIMERS_DEFAULT
|
||||
#define PRI_TIMERS_NI2 PRI_TIMERS_DEFAULT
|
||||
#define PRI_TIMERS_DMS100 PRI_TIMERS_DEFAULT
|
||||
#define PRI_TIMERS_LUCENT5E PRI_TIMERS_DEFAULT
|
||||
#define PRI_TIMERS_ATT4ESS PRI_TIMERS_DEFAULT
|
||||
#define PRI_TIMERS_EUROISDN_E1 PRI_TIMERS_DEFAULT
|
||||
#define PRI_TIMERS_EUROISDN_T1 PRI_TIMERS_DEFAULT
|
||||
#define PRI_TIMERS_NI1 PRI_TIMERS_DEFAULT
|
||||
#define PRI_TIMERS_GR303_EOC PRI_TIMERS_DEFAULT
|
||||
#define PRI_TIMERS_GR303_TMC PRI_TIMERS_DEFAULT
|
||||
|
||||
#define PRI_TIMERS_ALL { PRI_TIMERS_UNKNOWN, \
|
||||
PRI_TIMERS_NI2, \
|
||||
PRI_TIMERS_DMS100, \
|
||||
PRI_TIMERS_LUCENT5E, \
|
||||
PRI_TIMERS_ATT4ESS, \
|
||||
PRI_TIMERS_EUROISDN_E1, \
|
||||
PRI_TIMERS_EUROISDN_T1, \
|
||||
PRI_TIMERS_NI1, \
|
||||
PRI_TIMERS_GR303_EOC, \
|
||||
PRI_TIMERS_GR303_TMC \
|
||||
}
|
||||
|
||||
#endif
|
||||
5
pridump.c
Executable file → Normal file
5
pridump.c
Executable file → Normal file
@@ -36,7 +36,12 @@
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/types.h>
|
||||
#if defined(__linux__)
|
||||
#include <linux/zaptel.h>
|
||||
#elif defined(__FreeBSD__)
|
||||
#include <zaptel.h>
|
||||
#endif
|
||||
#include "libpri.h"
|
||||
#include "pri_q921.h"
|
||||
#include "pri_q931.h"
|
||||
|
||||
31
prisched.c
Executable file → Normal file
31
prisched.c
Executable file → Normal file
@@ -60,6 +60,9 @@ struct timeval *pri_schedule_next(struct pri *pri)
|
||||
{
|
||||
struct timeval *closest = NULL;
|
||||
int x;
|
||||
/* Check subchannels */
|
||||
if (pri->subchannel)
|
||||
closest = pri_schedule_next(pri->subchannel);
|
||||
for (x=1;x<MAX_SCHED;x++) {
|
||||
if (pri->pri_sched[x].callback &&
|
||||
(!closest || (closest->tv_sec > pri->pri_sched[x].when.tv_sec) ||
|
||||
@@ -70,19 +73,23 @@ struct timeval *pri_schedule_next(struct pri *pri)
|
||||
return closest;
|
||||
}
|
||||
|
||||
pri_event *pri_schedule_run(struct pri *pri)
|
||||
static pri_event *__pri_schedule_run(struct pri *pri, struct timeval *tv)
|
||||
{
|
||||
struct timeval tv;
|
||||
int x;
|
||||
void (*callback)(void *);
|
||||
void *data;
|
||||
gettimeofday(&tv, NULL);
|
||||
pri_event *e;
|
||||
if (pri->subchannel) {
|
||||
if ((e = __pri_schedule_run(pri->subchannel, tv))) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
for (x=1;x<MAX_SCHED;x++) {
|
||||
if (pri->pri_sched[x].callback &&
|
||||
((pri->pri_sched[x].when.tv_sec < tv.tv_sec) ||
|
||||
((pri->pri_sched[x].when.tv_sec == tv.tv_sec) &&
|
||||
(pri->pri_sched[x].when.tv_usec <= tv.tv_usec)))) {
|
||||
pri->schedev = 0;
|
||||
((pri->pri_sched[x].when.tv_sec < tv->tv_sec) ||
|
||||
((pri->pri_sched[x].when.tv_sec == tv->tv_sec) &&
|
||||
(pri->pri_sched[x].when.tv_usec <= tv->tv_usec)))) {
|
||||
pri->schedev = 0;
|
||||
callback = pri->pri_sched[x].callback;
|
||||
data = pri->pri_sched[x].data;
|
||||
pri->pri_sched[x].callback = NULL;
|
||||
@@ -90,11 +97,19 @@ pri_event *pri_schedule_run(struct pri *pri)
|
||||
callback(data);
|
||||
if (pri->schedev)
|
||||
return &pri->ev;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pri_event *pri_schedule_run(struct pri *pri)
|
||||
{
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
return __pri_schedule_run(pri, &tv);
|
||||
}
|
||||
|
||||
|
||||
void pri_schedule_del(struct pri *pri,int id)
|
||||
{
|
||||
if ((id >= MAX_SCHED) || (id < 0))
|
||||
|
||||
9
pritest.c
Executable file → Normal file
9
pritest.c
Executable file → Normal file
@@ -40,7 +40,11 @@
|
||||
#include <sys/wait.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/time.h>
|
||||
#if defined(__linux__)
|
||||
#include <linux/zaptel.h>
|
||||
#elif defined(__FreeBSD__)
|
||||
#include <zaptel.h>
|
||||
#endif
|
||||
#include <zap.h>
|
||||
#include "libpri.h"
|
||||
|
||||
@@ -116,6 +120,10 @@ static int str2switch(char *swtype)
|
||||
return PRI_SWITCH_ATT4ESS;
|
||||
if (!strcasecmp(swtype, "euroisdn"))
|
||||
return PRI_SWITCH_EUROISDN_E1;
|
||||
if (!strcasecmp(swtype, "gr303eoc"))
|
||||
return PRI_SWITCH_GR303_EOC;
|
||||
if (!strcasecmp(swtype, "gr303tmc"))
|
||||
return PRI_SWITCH_GR303_TMC;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -295,6 +303,7 @@ static int run_pri(int dfd, int swtype, int node)
|
||||
fprintf(stderr, "Unable to create PRI\n");
|
||||
return -1;
|
||||
}
|
||||
pri_set_debug(pri, -1);
|
||||
for (;;) {
|
||||
|
||||
/* Run the D-Channel */
|
||||
|
||||
122
q921.c
Executable file → Normal file
122
q921.c
Executable file → Normal file
@@ -41,12 +41,12 @@
|
||||
#define RANDOM_DROPS
|
||||
*/
|
||||
|
||||
#define Q921_INIT(hf) do { \
|
||||
#define Q921_INIT(pri, hf) do { \
|
||||
memset(&(hf),0,sizeof(hf)); \
|
||||
(hf).h.sapi = 0; \
|
||||
(hf).h.sapi = (pri)->sapi; \
|
||||
(hf).h.ea1 = 0; \
|
||||
(hf).h.ea2 = 1; \
|
||||
(hf).h.tei = 0; \
|
||||
(hf).h.tei = (pri)->tei; \
|
||||
} while(0)
|
||||
|
||||
static void reschedule_t203(struct pri *pri);
|
||||
@@ -67,6 +67,8 @@ static void q921_discard_retransmissions(struct pri *pri)
|
||||
static int q921_transmit(struct pri *pri, q921_h *h, int len)
|
||||
{
|
||||
int res;
|
||||
if (pri->master)
|
||||
return q921_transmit(pri->master, h, len);
|
||||
#ifdef RANDOM_DROPS
|
||||
if (!(random() % 3)) {
|
||||
pri_message(" === Dropping Packet ===\n");
|
||||
@@ -92,7 +94,7 @@ static int q921_transmit(struct pri *pri, q921_h *h, int len)
|
||||
static void q921_send_ua(struct pri *pri, int pfbit)
|
||||
{
|
||||
q921_h h;
|
||||
Q921_INIT(h);
|
||||
Q921_INIT(pri, h);
|
||||
h.u.m3 = 3; /* M3 = 3 */
|
||||
h.u.m2 = 0; /* M2 = 0 */
|
||||
h.u.p_f = pfbit; /* Final bit on */
|
||||
@@ -121,10 +123,10 @@ static void q921_send_sabme(void *vpri, int now)
|
||||
q921_h h;
|
||||
pri_schedule_del(pri, pri->sabme_timer);
|
||||
pri->sabme_timer = 0;
|
||||
pri->sabme_timer = pri_schedule_event(pri, T_200, q921_send_sabme_now, pri);
|
||||
pri->sabme_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T200], q921_send_sabme_now, pri);
|
||||
if (!now)
|
||||
return;
|
||||
Q921_INIT(h);
|
||||
Q921_INIT(pri, h);
|
||||
h.u.m3 = 3; /* M3 = 3 */
|
||||
h.u.m2 = 3; /* M2 = 3 */
|
||||
h.u.p_f = 1; /* Poll bit set */
|
||||
@@ -181,6 +183,7 @@ static int q921_ack_packet(struct pri *pri, int num)
|
||||
pri_message("-- Finally transmitting %d, since window opened up\n", f->h.n_s);
|
||||
f->transmitted++;
|
||||
pri->windowlen++;
|
||||
f->h.n_r = pri->v_r;
|
||||
q921_transmit(pri, (q921_h *)(&f->h), f->len);
|
||||
break;
|
||||
}
|
||||
@@ -205,7 +208,7 @@ static void reschedule_t203(struct pri *pri)
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
pri_message("-- Restarting T203 counter\n");
|
||||
/* Nothing to transmit, start the T203 counter instead */
|
||||
pri->t203_timer = pri_schedule_event(pri, T_203, t203_expire, pri);
|
||||
pri->t203_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T203], t203_expire, pri);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,7 +221,7 @@ static pri_event *q921_ack_rx(struct pri *pri, int ack)
|
||||
for (x=pri->v_a; (x != pri->v_s) && (x != ack); Q921_INC(x));
|
||||
if (x != ack) {
|
||||
/* ACK was outside of our window --- ignore */
|
||||
pri_error("ACK received outside of window, restarting\n");
|
||||
pri_error("ACK received for '%d' outside of window of '%d' to '%d', restarting\n", ack, pri->v_a, pri->v_s);
|
||||
ev = q921_dchannel_down(pri);
|
||||
q921_start(pri, 1);
|
||||
pri->schedev = 1;
|
||||
@@ -247,12 +250,12 @@ static pri_event *q921_ack_rx(struct pri *pri, int ack)
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
pri_message("-- Something left to transmit (%d), restarting T200 counter\n", pri->txqueue->h.n_s);
|
||||
if (!pri->t200_timer)
|
||||
pri->t200_timer = pri_schedule_event(pri, T_200, t200_expire, pri);
|
||||
pri->t200_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri);
|
||||
} else {
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
pri_message("-- Nothing left, starting T203 counter\n");
|
||||
/* Nothing to transmit, start the T203 counter instead */
|
||||
pri->t203_timer = pri_schedule_event(pri, T_203, t203_expire, pri);
|
||||
pri->t203_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T203], t203_expire, pri);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -260,7 +263,7 @@ static pri_event *q921_ack_rx(struct pri *pri, int ack)
|
||||
static void q921_reject(struct pri *pri, int pf)
|
||||
{
|
||||
q921_h h;
|
||||
Q921_INIT(h);
|
||||
Q921_INIT(pri, h);
|
||||
h.s.x0 = 0; /* Always 0 */
|
||||
h.s.ss = 2; /* Reject */
|
||||
h.s.ft = 1; /* Frametype (01) */
|
||||
@@ -285,7 +288,7 @@ static void q921_reject(struct pri *pri, int pf)
|
||||
|
||||
static void q921_rr(struct pri *pri, int pbit, int cmd) {
|
||||
q921_h h;
|
||||
Q921_INIT(h);
|
||||
Q921_INIT(pri, h);
|
||||
h.s.x0 = 0; /* Always 0 */
|
||||
h.s.ss = 0; /* Receive Ready */
|
||||
h.s.ft = 1; /* Frametype (01) */
|
||||
@@ -329,7 +332,7 @@ static void t200_expire(void *vpri)
|
||||
pri->solicitfbit = 1;
|
||||
pri->retrans++;
|
||||
/* Up to three retransmissions */
|
||||
if (pri->retrans < N_200) {
|
||||
if (pri->retrans < pri->timers[PRI_TIMER_N200]) {
|
||||
/* Reschedule t200_timer */
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
pri_message("-- Retransmitting %d bytes\n", pri->txqueue->len);
|
||||
@@ -342,7 +345,7 @@ static void t200_expire(void *vpri)
|
||||
}
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
pri_message("-- Rescheduling retransmission (%d)\n", pri->retrans);
|
||||
pri->t200_timer = pri_schedule_event(pri, T_200, t200_expire, pri);
|
||||
pri->t200_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri);
|
||||
} else {
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
pri_message("-- Timeout occured, restarting PRI\n");
|
||||
@@ -352,9 +355,26 @@ static void t200_expire(void *vpri)
|
||||
q921_start(pri, 1);
|
||||
pri->schedev = 1;
|
||||
}
|
||||
} else if (pri->solicitfbit) {
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
pri_message("-- Retrying poll with f-bit\n");
|
||||
pri->retrans++;
|
||||
if (pri->retrans < pri->timers[PRI_TIMER_N200]) {
|
||||
pri->solicitfbit = 1;
|
||||
q921_rr(pri, 1, 1);
|
||||
pri->t200_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri);
|
||||
} else {
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
pri_message("-- Timeout occured, restarting PRI\n");
|
||||
pri->q921_state = Q921_LINK_CONNECTION_RELEASED;
|
||||
pri->t200_timer = 0;
|
||||
q921_dchannel_down(pri);
|
||||
q921_start(pri, 1);
|
||||
pri->schedev = 1;
|
||||
}
|
||||
} else {
|
||||
pri_error("T200 counter expired, nothing to send...\n");
|
||||
pri->t200_timer = 0;
|
||||
pri->t200_timer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -363,9 +383,9 @@ int q921_transmit_iframe(struct pri *pri, void *buf, int len, int cr)
|
||||
q921_frame *f, *prev=NULL;
|
||||
for (f=pri->txqueue; f; f = f->next) prev = f;
|
||||
f = malloc(sizeof(q921_frame) + len + 2);
|
||||
memset(f,0,sizeof(q921_frame) + len + 2);
|
||||
if (f) {
|
||||
Q921_INIT(f->h);
|
||||
memset(f,0,sizeof(q921_frame) + len + 2);
|
||||
Q921_INIT(pri, f->h);
|
||||
switch(pri->localtype) {
|
||||
case PRI_NETWORK:
|
||||
if (cr)
|
||||
@@ -416,7 +436,7 @@ int q921_transmit_iframe(struct pri *pri, void *buf, int len, int cr)
|
||||
if (!pri->t200_timer) {
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
pri_message("Starting T_200 timer\n");
|
||||
pri->t200_timer = pri_schedule_event(pri, T_200, t200_expire, pri);
|
||||
pri->t200_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri);
|
||||
} else
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
pri_message("T_200 timer already going (%d)\n", pri->t200_timer);
|
||||
@@ -436,12 +456,13 @@ static void t203_expire(void *vpri)
|
||||
pri_message("T203 counter expired, sending RR and scheduling T203 again\n");
|
||||
/* Solicit an F-bit in the other's RR */
|
||||
pri->solicitfbit = 1;
|
||||
pri->retrans = 0;
|
||||
q921_rr(pri, 1, 1);
|
||||
/* Restart ourselves */
|
||||
pri->t203_timer = pri_schedule_event(pri, T_203, t203_expire, pri);
|
||||
/* Start timer T200 to resend our RR if we don't get it */
|
||||
pri->t203_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri);
|
||||
} else {
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
pri_message("T203 counter expired in weird statd %d\n", pri->q921_state);
|
||||
pri_message("T203 counter expired in weird state %d\n", pri->q921_state);
|
||||
pri->t203_timer = 0;
|
||||
}
|
||||
}
|
||||
@@ -635,7 +656,7 @@ static pri_event *q921_dchannel_up(struct pri *pri)
|
||||
pri->q921_state = Q921_LINK_CONNECTION_ESTABLISHED;
|
||||
|
||||
/* Start the T203 timer */
|
||||
pri->t203_timer = pri_schedule_event(pri, T_203, t203_expire, pri);
|
||||
pri->t203_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T203], t203_expire, pri);
|
||||
|
||||
/* Report event that D-Channel is now up */
|
||||
pri->ev.gen.e = PRI_EVENT_DCHAN_UP;
|
||||
@@ -659,7 +680,7 @@ void q921_reset(struct pri *pri)
|
||||
pri->v_a = 0;
|
||||
pri->v_r = 0;
|
||||
pri->v_na = 0;
|
||||
pri->window = 7;
|
||||
pri->window = pri->timers[PRI_TIMER_K];
|
||||
pri->windowlen = 0;
|
||||
pri_schedule_del(pri, pri->sabme_timer);
|
||||
pri_schedule_del(pri, pri->t203_timer);
|
||||
@@ -677,28 +698,11 @@ void q921_reset(struct pri *pri)
|
||||
q921_discard_retransmissions(pri);
|
||||
}
|
||||
|
||||
static pri_event *__q921_receive(struct pri *pri, q921_h *h, int len)
|
||||
static pri_event *__q921_receive_qualified(struct pri *pri, q921_h *h, int len)
|
||||
{
|
||||
q921_frame *f;
|
||||
pri_event *ev;
|
||||
int sendnow;
|
||||
/* Discard FCS */
|
||||
len -= 2;
|
||||
|
||||
if (pri->debug & PRI_DEBUG_Q921_DUMP)
|
||||
q921_dump(h, len, pri->debug & PRI_DEBUG_Q921_RAW, 0);
|
||||
|
||||
/* Check some reject conditions -- Start by rejecting improper ea's */
|
||||
if (h->h.ea1 || !(h->h.ea2))
|
||||
return NULL;
|
||||
|
||||
/* Check for broadcasts - not yet handled */
|
||||
if (h->h.tei == Q921_TEI_GROUP)
|
||||
return NULL;
|
||||
|
||||
/* Check for SAPIs we don't yet handle */
|
||||
if (h->h.sapi != Q921_SAPI_CALL_CTRL)
|
||||
return NULL;
|
||||
|
||||
switch(h->h.data[0] & Q921_FRAMETYPE_MASK) {
|
||||
case 0:
|
||||
@@ -793,7 +797,7 @@ static pri_event *__q921_receive(struct pri *pri, q921_h *h, int len)
|
||||
/* Reset and restart t203 timer */
|
||||
if (pri->t203_timer)
|
||||
pri_schedule_del(pri, pri->t203_timer);
|
||||
pri->t203_timer = pri_schedule_event(pri, T_203, t203_expire, pri);
|
||||
pri->t203_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T203], t203_expire, pri);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -890,11 +894,43 @@ static pri_event *__q921_receive(struct pri *pri, q921_h *h, int len)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static pri_event *__q921_receive(struct pri *pri, q921_h *h, int len)
|
||||
{
|
||||
pri_event *ev;
|
||||
/* Discard FCS */
|
||||
len -= 2;
|
||||
|
||||
if (!pri->master && pri->debug & PRI_DEBUG_Q921_DUMP)
|
||||
q921_dump(h, len, pri->debug & PRI_DEBUG_Q921_RAW, 0);
|
||||
|
||||
/* Check some reject conditions -- Start by rejecting improper ea's */
|
||||
if (h->h.ea1 || !(h->h.ea2))
|
||||
return NULL;
|
||||
|
||||
/* Check for broadcasts - not yet handled */
|
||||
if (h->h.tei == Q921_TEI_GROUP)
|
||||
return NULL;
|
||||
|
||||
/* Check for SAPIs we don't yet handle */
|
||||
if ((h->h.sapi != pri->sapi) || (h->h.tei != pri->tei)) {
|
||||
#ifdef PROCESS_SUBCHANNELS
|
||||
/* If it's not us, try any subchannels we have */
|
||||
if (pri->subchannel)
|
||||
return q921_receive(pri->subchannel, h, len + 2);
|
||||
else
|
||||
#endif
|
||||
return NULL;
|
||||
|
||||
}
|
||||
ev = __q921_receive_qualified(pri, h, len);
|
||||
reschedule_t203(pri);
|
||||
return ev;
|
||||
}
|
||||
|
||||
pri_event *q921_receive(struct pri *pri, q921_h *h, int len)
|
||||
{
|
||||
pri_event *e;
|
||||
e = __q921_receive(pri, h, len);
|
||||
reschedule_t203(pri);
|
||||
#ifdef LIBPRI_COUNTERS
|
||||
pri->q921_rxcount++;
|
||||
#endif
|
||||
|
||||
4
testprilib.c
Executable file → Normal file
4
testprilib.c
Executable file → Normal file
@@ -42,7 +42,11 @@
|
||||
#include <sys/time.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#if defined(__linux__)
|
||||
#include <linux/zaptel.h>
|
||||
#elif defined(__FreeBSD__)
|
||||
#include <zaptel.h>
|
||||
#endif
|
||||
#include <zap.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/select.h>
|
||||
|
||||
Reference in New Issue
Block a user