Compare commits

...

53 Commits
0.3.2 ... 0.6.0

Author SHA1 Message Date
Kevin P. Fleming
790e386bdd remove CVS ignore lists
git-svn-id: https://origsvn.digium.com/svn/libpri/tags/0.6.0@267 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2005-11-29 18:40:06 +00:00
Kevin P. Fleming
ac91b55cee remove extraneous svn:executable properties
git-svn-id: https://origsvn.digium.com/svn/libpri/tags/0.6.0@266 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2005-11-29 18:39:18 +00:00
Kevin P. Fleming
42b8d8eb04 manual tag renames
git-svn-id: https://origsvn.digium.com/svn/libpri/tags/0.6.0@262 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2005-11-27 04:16:28 +00:00
Admin Commit
d85f96808b This commit was manufactured by cvs2svn to create tag 'v0_6_0'.
git-svn-id: https://origsvn.digium.com/svn/libpri/tags/v0_6_0@88 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2004-04-11 01:55:54 +00:00
Mark Spencer
f2eb8afb7f Revert jcdutton's changes which are not subject to be disclaimed
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@87 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2004-04-11 01:55:54 +00:00
Mark Spencer
8da0a1e5a7 Debug improvements (bug #1329)
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@86 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2004-04-11 01:27:11 +00:00
Mark Spencer
4743ebd26f Generate release complete message back to Asterisk when T308 expires twice.
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@85 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2004-04-06 14:50:19 +00:00
James Golovich
949afd2385 Format q921 log string before printing. Fixes those annoying half patch
packet decodes when logging data with something like script or tee


git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@84 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2004-04-05 08:22:14 +00:00
James Golovich
480160c5cf Add .cvsignore to libpri
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@83 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2004-04-04 21:44:38 +00:00
James Golovich
2f5952fa86 Make pri_switch2str know about EuroISDN (bug 1348)
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@82 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2004-04-04 21:41:43 +00:00
James Golovich
be3a8c206b Add mkdep and 'make depend' to libpri Makefile
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@81 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2004-03-30 20:18:12 +00:00
James Golovich
ee394a7916 Make pri_dump_info print newly added pri->windowlen
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@80 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2004-03-29 09:18:38 +00:00
Mark Spencer
91b4a60c1f Add test program for windowing, implement proper windowing
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@79 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2004-03-29 08:09:01 +00:00
James Golovich
d00abddee3 Add pri_dump_info and q921/q931 counters to libpri
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@78 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2004-03-15 05:53:25 +00:00
Mark Spencer
09645488d6 Don't send release complete on the global call identifier
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@77 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2004-02-25 20:02:04 +00:00
Mark Spencer
24fba7f9b7 If userl1 is -1, don't include it
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@76 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2004-02-08 00:20:18 +00:00
Mark Spencer
c3544cb866 Add uninstall target
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@75 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2004-02-02 05:55:03 +00:00
Martin Pycko
ccafdd739b Add displaying User to User messages (the 2nd part of Bug #289)
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@74 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2004-01-28 21:02:23 +00:00
Mark Spencer
acf0e055ab Makefile fixes (bug #923)
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@73 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2004-01-27 00:39:59 +00:00
Mark Spencer
e1394704ad Fix SERVICE_ACKNOWLEDGE even with different address sizes
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@71 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2004-01-17 15:14:11 +00:00
Martin Pycko
0961ecb4b0 Don't expect CONNECT_ACK after we send CONNECT if we're the network and they're the user.
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@70 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-12-09 15:55:48 +00:00
Martin Pycko
a36186ce49 Don't reject SETUP without missing channel information IE if we're network.
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@69 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-12-05 23:10:33 +00:00
Mark Spencer
5f6e12c3e5 Populate ctype field
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@68 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-11-24 14:36:46 +00:00
Mark Spencer
d80324dbdd Ignore invalid/non Q.931 protocol discriminator
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@67 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-11-19 20:11:11 +00:00
Mark Spencer
e172ca2a03 Accept "PROGRESS" after "ALERTING"
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@66 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-10-15 13:56:10 +00:00
Mark Spencer
e4f9ea7583 Accept "PROGRESS" after "ALERTING"
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@65 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-10-15 13:56:09 +00:00
Martin Pycko
b5fa5986b2 Forgot to put break in the last patch
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@64 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-10-13 22:36:07 +00:00
Martin Pycko
f63cc76a94 Allow the reception of 1 byte Call Reference value
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@63 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-10-13 22:34:05 +00:00
Mark Spencer
cb01262a54 Progress OK when "CALL PROCEEDING"
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@62 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-10-10 07:04:19 +00:00
Mark Spencer
79e10c30a1 Fix for new GCC's
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@61 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-10-06 05:15:16 +00:00
Mark Spencer
06d9c2aeb3 Bring into full TBR4 compliance
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@60 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-09-25 06:13:14 +00:00
Martin Pycko
4e6c9e0410 Fix q931_hangup for (call received, call delivered)
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@58 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-09-09 23:49:10 +00:00
Martin Pycko
88656d9497 Don't reset peercallstate when we receive the STATUS message
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@57 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-09-09 23:40:16 +00:00
Martin Pycko
fe0eba8175 Fix the displaying of the information about the ANI/callerid
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@56 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-08-13 03:08:22 +00:00
Martin Pycko
24b85a379b Add pri_destroycall
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@55 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-08-12 20:16:55 +00:00
Martin Pycko
ec99ad86dd Regarding the new pri hangup: rewrite a little bit and introduce the PRI_EVENT_HANGUP_REQ
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@54 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-08-07 00:45:04 +00:00
Martin Pycko
ee9ef9ef3c One last thing fixed so that libpri would compile on 'other' systems
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@53 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-08-06 16:53:40 +00:00
Martin Pycko
f6966bc35b Fix the compilation errors on some systems due to -Werror flag
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@52 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-08-06 15:20:49 +00:00
Martin Pycko
45efb97ebd Update q931_hangup routine
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@51 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-08-05 20:37:32 +00:00
Martin Pycko
110062aef6 Allow to send the CAUSE IE along with RELEASE_COMPLETE message
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@50 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-08-05 19:26:07 +00:00
Martin Pycko
de24dd76a6 Send RELEASE COMPLETE if the cause is UNALLOCATED NUMBER (1) instead of sending DISCONNECT (although that should be ok too)
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@49 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-08-05 18:42:55 +00:00
Martin Pycko
e09654f0ed Allow the use of pri_release and pri_disconnect to have backwards compatibility for those who don't use asterisk with libpri
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@48 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-08-05 01:20:25 +00:00
Martin Pycko
86fe59eacc Make dependencies between asterisk and libpri using the flag PRI_HANGUP
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@47 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-08-05 01:08:06 +00:00
Martin Pycko
2809056303 Fix and improve (based on callstates) the hangup routines
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@46 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-08-05 01:00:45 +00:00
Mark Spencer
f8d3569b56 Handle sendingcomplete properly
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@45 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-07-26 15:14:44 +00:00
Martin Pycko
5f1aba027a Add posibility of choosing a diffrent form of ALERTING messages that has to be changed to work e.g. with Mitel switches.
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@44 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-07-07 23:37:18 +00:00
Mark Spencer
a85d2c508b Handle sending complete
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@43 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-07-01 20:25:34 +00:00
Martin Pycko
34f700b584 Change the way we store the callednum from INFORMATION messages
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@42 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-06-05 21:15:56 +00:00
Mark Spencer
5137d733f9 Add National ISDN 1 switchtype
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@41 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-05-28 22:34:59 +00:00
Martin Pycko
5478d68b2a Pass the info about SETUP_ACKNOWLEDGE outside libpri
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@40 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-05-15 22:15:38 +00:00
Martin Pycko
6e8e051464 Don't send IE field 'Sending Complete' when we want to do overlap dialing (sending)
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@39 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-05-15 19:35:05 +00:00
Mark Spencer
80355d96c5 Don't automatically send release
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@38 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-05-12 16:59:12 +00:00
Martin Pycko
e4d3ca388b Add PRI_EVENT_PROCEEDING when we get CALL_PROCEEDING or PROGRESS
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@37 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2003-04-18 15:56:38 +00:00
16 changed files with 1210 additions and 166 deletions

0
ChangeLog Executable file → Normal file
View File

41
Makefile Executable file → Normal file
View File

@@ -20,15 +20,27 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#
# Uncomment if you want libpri not send PROGRESS_INDICATOR w/ALERTING
#ALERTING=-DALERTING_NO_PROGRESS
# Uncomment if you want libpri to count number of Q921/Q931 sent/received
#LIBPRI_COUNTERS=-DLIBPRI_COUNTERS
TOBJS=testpri.o
T2OBJS=testprilib.o
STATIC_LIBRARY=libpri.a
DYNAMIC_LIBRARY=libpri.so.1.0
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
CFLAGS=-Wall -Werror -Wstrict-prototypes -Wmissing-prototypes -g $(ALERTING) $(LIBPRI_COUNTERS)
INSTALL_PREFIX=
all: $(STATIC_LIBRARY) $(DYNAMIC_LIBRARY)
all: depend $(STATIC_LIBRARY) $(DYNAMIC_LIBRARY)
update:
@echo "Updating from CVS"
@cvs update -d
install: $(STATIC_LIBRARY) $(DYNAMIC_LIBRARY)
mkdir -p $(INSTALL_PREFIX)/usr/lib
@@ -39,12 +51,27 @@ install: $(STATIC_LIBRARY) $(DYNAMIC_LIBRARY)
install -m 644 $(STATIC_LIBRARY) $(INSTALL_PREFIX)/usr/lib
/sbin/ldconfig
uninstall:
@echo "Removing Libpri"
rm -f $(INSTALL_PREFIX)/usr/lib/libpri.so.1.0
rm -f $(INSTALL_PREFIX)/usr/lib/libpri.so
rm -f $(INSTALL_PREFIX)/usr/lib/libpri.a
rm -f $(INSTALL_PREFIX)/usr/include/libpri.h
pritest: pritest.o
$(CC) -o pritest pritest.o -L. -lpri -lzap
testprilib.o: testprilib.c
$(CC) $(CFLAGS) -D_REENTRANT -D_GNU_SOURCE -o $@ -c $<
testprilib: testprilib.o
$(CC) -o testprilib testprilib.o -L. -lpri -lpthread
pridump: pridump.o
$(CC) -o pridump pridump.o -L. -lpri -lzap
include .depend
%.lo : %.c
$(CC) -fPIC $(CFLAGS) -o $@ -c $<
@@ -58,6 +85,12 @@ $(DYNAMIC_LIBRARY): $(DYNAMIC_OBJS)
ln -sf libpri.so.1 libpri.so
clean:
rm -f *.o *.so *.lo
rm -f testpri $(STATIC_LIBRARY) $(DYNAMIC_LIBRARY)
rm -f *.o *.so *.lo *.so.1 *.so.1.0
rm -f testpri testprilib $(STATIC_LIBRARY) $(DYNAMIC_LIBRARY)
rm -f pritest pridump
rm -f .depend
depend: .depend
.depend:
./mkdep ${CFLAGS} `ls *.c`

0
README Executable file → Normal file
View File

0
TODO Executable file → Normal file
View File

50
libpri.h Executable file → Normal file
View File

@@ -48,6 +48,7 @@
#define PRI_SWITCH_ATT4ESS 4 /* AT&T 4ESS */
#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 */
/* PRI D-Channel Events */
#define PRI_EVENT_DCHAN_UP 1 /* D-channel is up */
@@ -62,6 +63,9 @@
#define PRI_EVENT_RESTART_ACK 10 /* Restart complete on a given channel */
#define PRI_EVENT_FACNAME 11 /* Caller*ID Name received on Facility */
#define PRI_EVENT_INFO_RECEIVED 12 /* Additional info (keypad) received */
#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 */
/* Simple states */
#define PRI_STATE_DOWN 0
@@ -176,6 +180,8 @@
#define PRI_LAYER_1_V120_RATE_ADAPT 0x28
#define PRI_LAYER_1_X31_RATE_ADAPT 0x29
#define PRI_COPY_DIGITS_CALLED_NUMBER
typedef struct q931_call q931_call;
typedef struct pri_event_generic {
@@ -231,6 +237,7 @@ typedef struct pri_event_ring {
int cref; /* Call Reference Number */
int ctype; /* Call type (see PRI_TRANS_CAP_* */
int layer1; /* User layer 1 */
int complete; /* Have we seen "Complete" i.e. no more number? */
q931_call *call; /* Opaque call pointer */
} pri_event_ring;
@@ -247,6 +254,16 @@ typedef struct pri_event_restart_ack {
int channel;
} pri_event_restart_ack;
typedef struct pri_event_proceeding {
int e;
int channel;
} pri_event_proceeding;
typedef struct pri_event_setup_ack {
int e;
int channel;
} pri_event_setup_ack;
typedef union {
int e;
pri_event_generic gen; /* Generic view */
@@ -258,6 +275,8 @@ typedef union {
pri_event_ringing ringing; /* Ringing */
pri_event_ringing answer; /* Answer */
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;
struct pri;
@@ -319,11 +338,31 @@ 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);
/* Hangup / Disconnect a call */
extern int pri_disconnect(struct pri *pri, q931_call *call, int cause);
#endif
#undef pri_release
#undef pri_disconnect
/* backwards compatibility for those who don't use asterisk with libpri */
#define pri_release(a,b,c) \
pri_hangup(a,b,c)
#define pri_disconnect(a,b,c) \
pri_hangup(a,b,c)
/* Hangup a call */
#define PRI_HANGUP
extern int pri_hangup(struct pri *pri, q931_call *call, int cause);
#define PRI_DESTROYCALL
extern void pri_destroycall(struct pri *pri, q931_call *call);
extern int pri_reset(struct pri *pri, int channel);
@@ -343,4 +382,15 @@ extern int pri_call(struct pri *pri, q931_call *c, int transmode, int channel,
/* Override message and error stuff */
extern void pri_set_message(void (*__pri_error)(char *));
extern void pri_set_error(void (*__pri_error)(char *));
/* Set overlap mode */
#define PRI_SET_OVERLAPDIAL
extern void pri_set_overlapdial(struct pri *pri,int state);
#define PRI_DUMP_INFO
extern void pri_dump_info(struct pri *pri);
/* Get file descriptor */
extern int pri_fd(struct pri *pri);
#endif

113
mkdep Executable file
View File

@@ -0,0 +1,113 @@
#!/bin/sh -
#
# $OpenBSD: mkdep.gcc.sh,v 1.8 1998/09/02 06:40:07 deraadt Exp $
# $NetBSD: mkdep.gcc.sh,v 1.9 1994/12/23 07:34:59 jtc Exp $
#
# Copyright (c) 1991, 1993
# The Regents of the University of California. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
# must display the following acknowledgement:
# This product includes software developed by the University of
# California, Berkeley and its contributors.
# 4. Neither the name of the University nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# @(#)mkdep.gcc.sh 8.1 (Berkeley) 6/6/93
#
D=.depend # default dependency file is .depend
append=0
pflag=
while :
do case "$1" in
# -a appends to the depend file
-a)
append=1
shift ;;
# -f allows you to select a makefile name
-f)
D=$2
shift; shift ;;
# the -p flag produces "program: program.c" style dependencies
# so .o's don't get produced
-p)
pflag=p
shift ;;
*)
break ;;
esac
done
if [ $# = 0 ] ; then
echo 'usage: mkdep [-p] [-f depend_file] [cc_flags] file ...'
exit 1
fi
DTMP=/tmp/mkdep$$
TMP=$DTMP/mkdep
um=`umask`
umask 022
if ! mkdir $DTMP ; then
echo failed to create tmp dir $DTMP
exit 1
fi
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
else
${CC:-cc} -M "$@" | sed -e 's;\.o :; :;' -e 's; \./; ;g' > $TMP
fi
if [ $? != 0 ]; then
echo 'mkdep: compile failed.'
rm -rf $DTMP
exit 1
fi
if [ $append = 1 ]; then
cat $TMP >> $D
if [ $? != 0 ]; then
echo 'mkdep: append failed.'
rm -rf $DTMP
exit 1
fi
else
mv $TMP $D
if [ $? != 0 ]; then
echo 'mkdep: rename failed.'
rm -rf $DTMP
exit 1
fi
fi
rm -rf $DTMP
exit 0

80
pri.c Executable file → Normal file
View File

@@ -49,6 +49,10 @@ char *pri_switch2str(int sw)
return "Lucent 5E";
case PRI_SWITCH_ATT4ESS:
return "AT&T 4ESS";
case PRI_SWITCH_NI1:
return "National ISDN 1";
case PRI_SWITCH_EUROISDN_E1:
return "EuroISDN";
default:
return "Unknown switchtype";
}
@@ -64,8 +68,14 @@ struct pri *pri_new(int fd, int node, int switchtype)
p->localtype = node;
p->switchtype = switchtype;
p->cref = 1;
/* Start Q.921 layer */
q921_start(p, 1);
#ifdef LIBPRI_COUNTERS
p->q921_rxcount = 0;
p->q921_txcount = 0;
p->q931_rxcount = 0;
p->q931_txcount = 0;
#endif
/* Start Q.921 layer, Wait if we're the network */
q921_start(p, p->localtype == PRI_CPE);
}
return p;
}
@@ -188,6 +198,13 @@ int pri_information(struct pri *pri, q931_call *call, char digit)
return q931_information(pri, call, digit);
}
void pri_destroycall(struct pri *pri, q931_call *call)
{
if (pri && call)
__q931_destroycall(pri, call);
return;
}
int pri_need_more_info(struct pri *pri, q931_call *call, int channel, int nonisdn)
{
if (!pri || !call)
@@ -202,6 +219,8 @@ int pri_answer(struct pri *pri, q931_call *call, int channel, int nonisdn)
return q931_connect(pri, call, channel, nonisdn);
}
#if 0
/* deprecated routines, use pri_hangup */
int pri_release(struct pri *pri, q931_call *call, int cause)
{
if (!pri || !call)
@@ -215,6 +234,17 @@ int pri_disconnect(struct pri *pri, q931_call *call, int cause)
return -1;
return q931_disconnect(pri, call, cause);
}
#endif
int pri_hangup(struct pri *pri, q931_call *call, int cause)
{
if (!pri || !call)
return -1;
if (cause == -1)
/* normal clear cause */
cause = 16;
return q931_hangup(pri, call, cause);
}
int pri_reset(struct pri *pri, int channel)
{
@@ -263,7 +293,7 @@ int pri_call(struct pri *pri, q931_call *c, int transmode, int channel, int excl
{
if (!pri || !c)
return -1;
return q931_setup(pri, c, transmode, channel, exclusive, nonisdn, caller, callerplan, callername, callerpres, called, calledplan, ulayer1);
return q931_setup(pri, c, transmode, channel, exclusive, nonisdn, caller, callerplan, callername, callerpres, called, calledplan, ulayer1);
}
static void (*__pri_error)(char *stuff);
@@ -304,3 +334,47 @@ void pri_error(char *fmt, ...)
else
fprintf(stderr, tmp);
}
/* Set overlap mode */
void pri_set_overlapdial(struct pri *pri,int state)
{
pri->overlapdial = state;
}
int pri_fd(struct pri *pri)
{
return pri->fd;
}
void pri_dump_info(struct pri *pri)
{
#ifdef LIBPRI_COUNTERS
struct q921_frame *f;
int q921outstanding = 0;
#endif
if (!pri)
return;
/* Might be nice to format these a little better */
pri_message("Switchtype: %s\n", pri_switch2str(pri->switchtype));
pri_message("Type: %s\n", pri_node2str(pri->localtype));
#ifdef LIBPRI_COUNTERS
/* Remember that Q921 Counters include Q931 packets (and any retransmissions) */
pri_message("Q931 RX: %d\n", pri->q931_rxcount);
pri_message("Q931 TX: %d\n", pri->q931_txcount);
pri_message("Q921 RX: %d\n", pri->q921_rxcount);
pri_message("Q921 TX: %d\n", pri->q921_txcount);
f = pri->txqueue;
while (f) {
q921outstanding++;
f = f->next;
}
pri_message("Q921 Outstanding: %d\n", q921outstanding);
#endif
pri_message("Window Length: %d/%d\n", pri->windowlen, pri->window);
pri_message("Sentrej: %d\n", pri->sentrej);
pri_message("SolicitFbit: %d\n", pri->solicitfbit);
pri_message("Retrans: %d\n", pri->retrans);
pri_message("Busy: %d\n", pri->busy);
pri_message("Overlap Dial: %d\n", pri->overlapdial);
}

13
pri_internal.h Executable file → Normal file
View File

@@ -52,12 +52,14 @@ struct pri {
/* Q.921 State */
int q921_state;
int window; /* Max window size */
int windowlen; /* Fullness of window */
int v_s; /* Next N(S) for transmission */
int v_a; /* Last acknowledged frame */
int v_r; /* Next frame expected to be received */
int v_na; /* What we've told our peer we've acknowledged */
int solicitfbit; /* Have we sent an I or S frame with the F-bit set? */
int retrans; /* Retransmissions */
int sentrej; /* Are we in reject state */
int cref; /* Next call reference value */
@@ -78,6 +80,17 @@ struct pri {
/* Q.931 calls */
q931_call *calls;
/* do we do overlap dialing */
int overlapdial;
#ifdef LIBPRI_COUNTERS
/* q921/q931 packet counters */
unsigned int q921_txcount;
unsigned int q921_rxcount;
unsigned int q931_txcount;
unsigned int q931_rxcount;
#endif
};
extern int pri_schedule_event(struct pri *pri, int ms, void (*function)(void *data), void *data);

1
pri_q921.h Executable file → Normal file
View File

@@ -134,6 +134,7 @@ typedef union {
typedef struct q921_frame {
struct q921_frame *next; /* Next in list */
int len; /* Length of header + body */
int transmitted; /* Have we been transmitted */
q921_i h;
} q921_frame;

5
pri_q931.h Executable file → Normal file
View File

@@ -255,6 +255,8 @@ extern int q931_release(struct pri *pri, q931_call *call, int cause);
extern int q931_disconnect(struct pri *pri, q931_call *call, int cause);
extern int q931_hangup(struct pri *pri, q931_call *call, int cause);
extern int q931_restart(struct pri *pri, int channel);
extern q931_call *q931_new_call(struct pri *pri);
@@ -263,4 +265,7 @@ extern int q931_setup(struct pri *pri, q931_call *c, int transmode, int channel,
int nonisdn, char *caller, int callerplan, char *callername, int callerpres, char *called,
int calledplan, int ulay1);
extern void q931_dump(q931_h *h, int len, int txrx);
extern void __q931_destroycall(struct pri *pri, q931_call *c);
#endif

0
pridump.c Executable file → Normal file
View File

0
prisched.c Executable file → Normal file
View File

0
pritest.c Executable file → Normal file
View File

197
q921.c Executable file → Normal file
View File

@@ -49,6 +49,8 @@
(hf).h.tei = 0; \
} while(0)
static void reschedule_t203(struct pri *pri);
static void q921_discard_retransmissions(struct pri *pri)
{
struct q921_frame *f, *p;
@@ -62,7 +64,8 @@ static void q921_discard_retransmissions(struct pri *pri)
pri->txqueue = NULL;
}
static int q921_transmit(struct pri *pri, q921_h *h, int len) {
static int q921_transmit(struct pri *pri, q921_h *h, int len)
{
int res;
#ifdef RANDOM_DROPS
if (!(random() % 3)) {
@@ -70,7 +73,9 @@ static int q921_transmit(struct pri *pri, q921_h *h, int len) {
return 0;
}
#endif
#ifdef LIBPRI_COUNTERS
pri->q921_txcount++;
#endif
/* Just send it raw */
if (pri->debug & PRI_DEBUG_Q921_DUMP)
q921_dump(h, len, pri->debug & PRI_DEBUG_Q921_RAW, 1);
@@ -80,6 +85,7 @@ static int q921_transmit(struct pri *pri, q921_h *h, int len) {
pri_error("Short write: %d/%d (%s)\n", res, len + 2, strerror(errno));
return -1;
}
reschedule_t203(pri);
return 0;
}
@@ -164,6 +170,22 @@ static int q921_ack_packet(struct pri *pri, int num)
free(f);
/* Reset retransmission counter if we actually acked something */
pri->retrans = 0;
/* Decrement window size */
pri->windowlen--;
/* Search for something to send */
f = pri->txqueue;
while(f) {
if (!f->transmitted) {
/* Send it now... */
if (pri->debug & PRI_DEBUG_Q921_STATE)
pri_message("-- Finally transmitting %d, since window opened up\n", f->h.n_s);
f->transmitted++;
pri->windowlen++;
q921_transmit(pri, (q921_h *)(&f->h), f->len);
break;
}
f = f->next;
}
return 1;
}
prev = f;
@@ -174,17 +196,33 @@ static int q921_ack_packet(struct pri *pri, int num)
static void t203_expire(void *);
static void t200_expire(void *);
static pri_event *q921_dchannel_down(struct pri *pri);
static void q921_ack_rx(struct pri *pri, int ack)
static void reschedule_t203(struct pri *pri)
{
if (pri->t203_timer) {
pri_schedule_del(pri, pri->t203_timer);
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);
}
}
static pri_event *q921_ack_rx(struct pri *pri, int ack)
{
int x;
int cnt=0;
pri_event *ev;
/* Make sure the ACK was within our window */
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, ignoring\n");
return;
pri_error("ACK received outside of window, restarting\n");
ev = q921_dchannel_down(pri);
q921_start(pri, 1);
pri->schedev = 1;
return ev;
}
/* Cancel each packet as necessary */
if (pri->debug & PRI_DEBUG_Q921_STATE)
@@ -216,9 +254,10 @@ static void q921_ack_rx(struct pri *pri, int ack)
/* Nothing to transmit, start the T203 counter instead */
pri->t203_timer = pri_schedule_event(pri, T_203, t203_expire, pri);
}
return NULL;
}
static void q921_reject(struct pri *pri)
static void q921_reject(struct pri *pri, int pf)
{
q921_h h;
Q921_INIT(h);
@@ -226,7 +265,7 @@ static void q921_reject(struct pri *pri)
h.s.ss = 2; /* Reject */
h.s.ft = 1; /* Frametype (01) */
h.s.n_r = pri->v_r; /* Where to start retransmission */
h.s.p_f = 1; /* XXX Should it always be set to 1? XXX */
h.s.p_f = pf;
switch(pri->localtype) {
case PRI_NETWORK:
h.h.c_r = 0;
@@ -240,10 +279,11 @@ static void q921_reject(struct pri *pri)
}
if (pri->debug & PRI_DEBUG_Q921_STATE)
pri_message("Sending Reject (%d)\n", pri->v_r);
pri->sentrej = 1;
q921_transmit(pri, &h, 4);
}
static void q921_rr(struct pri *pri, int pbit) {
static void q921_rr(struct pri *pri, int pbit, int cmd) {
q921_h h;
Q921_INIT(h);
h.s.x0 = 0; /* Always 0 */
@@ -253,10 +293,16 @@ static void q921_rr(struct pri *pri, int pbit) {
h.s.p_f = pbit; /* Poll/Final set appropriately */
switch(pri->localtype) {
case PRI_NETWORK:
h.h.c_r = 0;
if (cmd)
h.h.c_r = 1;
else
h.h.c_r = 0;
break;
case PRI_CPE:
h.h.c_r = 1;
if (cmd)
h.h.c_r = 0;
else
h.h.c_r = 1;
break;
default:
pri_error("Don't know how to U/A on a type %d node\n", pri->localtype);
@@ -268,8 +314,6 @@ static void q921_rr(struct pri *pri, int pbit) {
q921_transmit(pri, &h, 4);
}
static pri_event *q921_dchannel_down(struct pri *pri);
static void t200_expire(void *vpri)
{
struct pri *pri = vpri;
@@ -289,14 +333,20 @@ static void t200_expire(void *vpri)
/* Reschedule t200_timer */
if (pri->debug & PRI_DEBUG_Q921_STATE)
pri_message("-- Retransmitting %d bytes\n", pri->txqueue->len);
q921_transmit(pri, (q921_h *)&pri->txqueue->h, pri->txqueue->len);
if (pri->busy)
q921_rr(pri, 1, 0);
else {
if (!pri->txqueue->transmitted)
pri_error("!! Not good - head of queue has not been transmitted yet\n");
q921_transmit(pri, (q921_h *)&pri->txqueue->h, pri->txqueue->len);
}
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);
} else {
if (pri->debug & PRI_DEBUG_Q921_STATE)
pri_message("-- Timeout occured, restarting PRI\n");
pri->state = Q921_LINK_CONNECTION_RELEASED;
pri->q921_state = Q921_LINK_CONNECTION_RELEASED;
pri->t200_timer = 0;
q921_dchannel_down(pri);
q921_start(pri, 1);
@@ -331,6 +381,7 @@ int q921_transmit_iframe(struct pri *pri, void *buf, int len, int cr)
break;
}
f->next = NULL;
f->transmitted = 0;
f->len = len + 4;
memcpy(f->h.data, buf, len);
f->h.n_s = pri->v_s;
@@ -343,9 +394,19 @@ int q921_transmit_iframe(struct pri *pri, void *buf, int len, int cr)
prev->next = f;
else
pri->txqueue = f;
/* Immediately transmit unless we're in a recovery state */
if (!pri->retrans)
q921_transmit(pri, (q921_h *)(&f->h), f->len);
/* Immediately transmit unless we're in a recovery state, or the window
size is too big */
if (!pri->retrans && !pri->busy) {
if (pri->windowlen < pri->window) {
pri->windowlen++;
q921_transmit(pri, (q921_h *)(&f->h), f->len);
f->transmitted++;
} else {
if (pri->debug & PRI_DEBUG_Q921_STATE)
pri_message("Delaying transmission of %d, window is %d/%d long\n",
f->h.n_s, pri->windowlen, pri->window);
}
}
if (pri->t203_timer) {
if (pri->debug & PRI_DEBUG_Q921_STATE)
pri_message("Stopping T_203 timer\n");
@@ -370,47 +431,57 @@ int q921_transmit_iframe(struct pri *pri, void *buf, int len, int cr)
static void t203_expire(void *vpri)
{
struct pri *pri = vpri;
if (pri->debug & PRI_DEBUG_Q921_STATE)
pri_message("T203 counter expired, sending RR and scheduling T203 again\n");
/* Solicit an F-bit in the other's RR */
pri->solicitfbit = 1;
q921_rr(pri, 1);
/* Restart ourselves */
pri->t203_timer = pri_schedule_event(pri, T_203, t203_expire, pri);
if (pri->q921_state == Q921_LINK_CONNECTION_ESTABLISHED) {
if (pri->debug & PRI_DEBUG_Q921_STATE)
pri_message("T203 counter expired, sending RR and scheduling T203 again\n");
/* Solicit an F-bit in the other's RR */
pri->solicitfbit = 1;
q921_rr(pri, 1, 1);
/* Restart ourselves */
pri->t203_timer = pri_schedule_event(pri, T_203, t203_expire, pri);
} else {
if (pri->debug & PRI_DEBUG_Q921_STATE)
pri_message("T203 counter expired in weird statd %d\n", pri->q921_state);
pri->t203_timer = 0;
}
}
static pri_event *q921_handle_iframe(struct pri *pri, q921_i *i, int len)
{
int res;
pri_event *ev;
/* Make sure this is a valid packet */
if (i->n_s == pri->v_r) {
/* Increment next expected I-frame */
Q921_INC(pri->v_r);
/* Handle their ACK */
q921_ack_rx(pri, i->n_r);
pri->sentrej = 0;
ev = q921_ack_rx(pri, i->n_r);
if (ev)
return ev;
if (i->p_f) {
/* If the Poll/Final bit is set, immediate send the RR */
q921_rr(pri, 1);
q921_rr(pri, 1, 0);
} else if (pri->busy) {
q921_rr(pri, 0, 0);
}
/* Receive Q.931 data */
res = q931_receive(pri, (q931_h *)i->data, len - 4);
/* Send an RR if one wasn't sent already */
if (pri->v_na != pri->v_r)
q921_rr(pri, 0);
q921_rr(pri, 0, 0);
if (res == -1) {
return NULL;
}
if (res & Q931_RES_HAVEEVENT)
return &pri->ev;
} else {
if (((pri->v_r - i->n_s) & 127) < pri->window) {
/* It's within our window -- send back an RR */
q921_rr(pri, 0);
} else
q921_reject(pri);
#if 0
q931_reject(pri);
#endif
/* If we haven't already sent a reject, send it now, otherwise
we are obliged to RR */
if (!pri->sentrej)
q921_reject(pri, i->p_f);
else if (i->p_f)
q921_rr(pri, 1, 0);
}
return NULL;
}
@@ -423,10 +494,14 @@ void q921_dump(q921_h *h, int len, int showraw, int txrx)
direction_tag = txrx ? '>' : '<';
if (showraw) {
pri_message("\n%c [", direction_tag);
for (x=0;x<len;x++)
pri_message("%02x ",h->raw[x]);
pri_message("]");
char *buf = malloc(len * 3 + 1);
int buflen = 0;
if (buf) {
for (x=0;x<len;x++)
buflen += sprintf(buf + buflen, "%02x ", h->raw[x]);
pri_message("\n%c [ %s]\n", direction_tag, buf);
free(buf);
}
}
switch (h->h.data[0] & Q921_FRAMETYPE_MASK) {
@@ -553,6 +628,9 @@ static pri_event *q921_dchannel_up(struct pri *pri)
pri_schedule_del(pri, pri->sabme_timer);
pri->sabme_timer = 0;
/* Reset any rejects */
pri->sentrej = 0;
/* Go into connection established state */
pri->q921_state = Q921_LINK_CONNECTION_ESTABLISHED;
@@ -582,6 +660,7 @@ void q921_reset(struct pri *pri)
pri->v_r = 0;
pri->v_na = 0;
pri->window = 7;
pri->windowlen = 0;
pri_schedule_del(pri, pri->sabme_timer);
pri_schedule_del(pri, pri->t203_timer);
pri_schedule_del(pri, pri->t200_timer);
@@ -592,13 +671,16 @@ void q921_reset(struct pri *pri)
pri->solicitfbit = 0;
pri->q921_state = Q921_LINK_CONNECTION_RELEASED;
pri->retrans = 0;
pri->sentrej = 0;
/* Discard anything waiting to go out */
q921_discard_retransmissions(pri);
}
pri_event *q921_receive(struct pri *pri, q921_h *h, int len)
static pri_event *__q921_receive(struct pri *pri, q921_h *h, int len)
{
q921_frame *f;
pri_event *ev;
int sendnow;
/* Discard FCS */
len -= 2;
@@ -646,7 +728,9 @@ pri_event *q921_receive(struct pri *pri, q921_h *h, int len)
/* Receiver Ready */
pri->busy = 0;
/* Acknowledge frames as necessary */
q921_ack_rx(pri, h->s.n_r);
ev = q921_ack_rx(pri, h->s.n_r);
if (ev)
return ev;
if (h->s.p_f) {
/* If it's a p/f one then send back a RR in return with the p/f bit set */
if (pri->solicitfbit) {
@@ -655,32 +739,35 @@ pri_event *q921_receive(struct pri *pri, q921_h *h, int len)
} else {
if (pri->debug & PRI_DEBUG_Q921_STATE)
pri_message("-- Unsolicited RR with P/F bit, responding\n");
q921_rr(pri, 1);
q921_rr(pri, 1, 0);
}
pri->solicitfbit = 0;
}
break;
#if 0
case 1:
/* Receiver not ready */
if (pri->debug & PRI_DEBUG_Q921_STATE)
pri_message("-- Got receiver not ready\n");
if(h->s.p_f) {
/* Send RR if poll bit set */
q921_rr(pri, h->s.p_f, 0);
}
pri->busy = 1;
break;
#endif
case 2:
/* Just retransmit */
if (pri->debug & PRI_DEBUG_Q921_STATE)
pri_message("-- Got reject requesting packet %d... Retransmitting.\n", h->s.n_r);
if (h->s.p_f) {
/* If it has the poll bit set, send an appropriate supervisory response */
q921_rr(pri, 1);
q921_rr(pri, 1, 0);
}
sendnow = 0;
/* Resend the proper I-frame */
for(f=pri->txqueue;f;f=f->next) {
if (sendnow || (f->h.n_s == h->s.n_r)) {
/* Matches the request, or follows in our window */
if ((sendnow || (f->h.n_s == h->s.n_r)) && f->transmitted) {
/* Matches the request, or follows in our window, and has
already been transmitted. */
sendnow = 1;
pri_error("!! Got reject for frame %d, retransmitting frame %d now, updating n_r!\n", h->s.n_r, f->h.n_s);
f->h.n_r = pri->v_r;
@@ -726,7 +813,6 @@ pri_event *q921_receive(struct pri *pri, q921_h *h, int len)
if (h->u.p_f) {
/* Section 5.7.1 says we should restart on receiving a DM response with the f-bit set to
one, but we wait T200 first */
pri_event *ev = NULL;
if (pri->debug & PRI_DEBUG_Q921_STATE)
pri_message("-- Got DM Mode from peer.\n");
/* Disconnected mode, try again after T200 */
@@ -752,7 +838,9 @@ pri_event *q921_receive(struct pri *pri, q921_h *h, int len)
pri_message("-- Got Disconnect from peer.\n");
/* Acknowledge */
q921_send_ua(pri, h->u.p_f);
return q921_dchannel_down(pri);
ev = q921_dchannel_down(pri);
q921_start(pri, 0);
return ev;
case 3:
if (h->u.m2 == 3) {
/* SABME */
@@ -802,6 +890,17 @@ pri_event *q921_receive(struct pri *pri, q921_h *h, int len)
return NULL;
}
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
return e;
}
void q921_start(struct pri *pri, int now)
{
if (pri->q921_state != Q921_LINK_CONNECTION_RELEASED) {

642
q931.c Executable file → Normal file

File diff suppressed because it is too large Load Diff

234
testprilib.c Normal file
View File

@@ -0,0 +1,234 @@
/*
* 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.
*
*/
/*
* This program tests libpri call reception using a zaptel interface.
* Its state machines are setup for RECEIVING CALLS ONLY, so if you
* are trying to both place and receive calls you have to a bit more.
*/
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/signal.h>
#include <sys/select.h>
#include <sys/wait.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <linux/zaptel.h>
#include <zap.h>
#include <pthread.h>
#include <sys/select.h>
#include "libpri.h"
#define DEBUG_LEVEL PRI_DEBUG_ALL
#define PRI_DEF_NODETYPE PRI_CPE
#define PRI_DEF_SWITCHTYPE PRI_SWITCH_NI2
static struct pri *first, *cur;
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
#define TEST_CALLS 32
static void event1(struct pri *pri, pri_event *e)
{
/* Network */
int x;
static q931_call *calls[TEST_CALLS];
char name[256], num[256], dest[256];
switch(e->gen.e) {
case PRI_EVENT_DCHAN_UP:
printf("Network is up. Sending blast of calls!\n");
for (x=0;x<TEST_CALLS;x++) {
sprintf(name, "Caller %d", x + 1);
sprintf(num, "25642860%02d", x+1);
sprintf(dest, "60%02d", x + 1);
if (!(calls[x] = pri_new_call(pri))) {
perror("pri_new_call");
} else if (pri_call(pri, calls[x], PRI_TRANS_CAP_DIGITAL, x + 1, 1, 1, num,
PRI_NATIONAL_ISDN, name, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN,
dest, PRI_NATIONAL_ISDN, PRI_LAYER_1_ULAW)) {
perror("pri_call");
}
}
printf("Setup %d calls!\n", TEST_CALLS);
break;
default:
printf("PRI 1: %s (%d)\n", pri_event2str(e->gen.e), e->gen.e);
}
}
static void event2(struct pri *pri, pri_event *e)
{
/* CPE */
switch(e->gen.e) {
case PRI_EVENT_DCHAN_UP:
default:
printf("PRI 2: %s (%d)\n", pri_event2str(e->gen.e), e->gen.e);
}
}
static void testmsg(char *s)
{
char *c;
static int keeplast = 0;
do {
c = strchr(s, '\n');
if (c) {
*c = '\0';
c++;
}
if (keeplast)
printf("%s", s);
else if (cur == first)
printf("-1 %s", s);
else
printf("-2 %s", s);
if (c)
printf("\n");
s = c;
} while(c && *c);
if (!c)
keeplast = 1;
else
keeplast = 0;
}
static void testerr(char *s)
{
char *c;
static int keeplast = 0;
do {
c = strchr(s, '\n');
if (c) {
*c = '\0';
c++;
}
if (keeplast)
printf("%s", s);
else if (cur == first)
printf("=1 %s", s);
else
printf("=2 %s", s);
if (c)
printf("\n");
s = c;
} while(c && *c);
if (!c)
keeplast = 1;
else
keeplast = 0;
}
static void *dchan(void *data)
{
/* Joint D-channel */
struct pri *pri = data;
struct timeval *next, tv;
pri_event *e;
fd_set fds;
int res;
for(;;) {
if (next == pri_schedule_next(pri)) {
gettimeofday(&tv, NULL);
tv.tv_sec = next->tv_sec - tv.tv_sec;
tv.tv_usec = next->tv_usec - tv.tv_usec;
if (tv.tv_usec < 0) {
tv.tv_usec += 1000000;
tv.tv_sec -= 1;
}
if (tv.tv_sec < 0) {
tv.tv_sec = 0;
tv.tv_usec = 0;
}
}
FD_ZERO(&fds);
FD_SET(pri_fd(pri), &fds);
res = select(pri_fd(pri) + 1, &fds, NULL, NULL, next ? &tv : NULL);
pthread_mutex_lock(&lock);
cur = pri;
if (res < 0) {
perror("select");
} else if (!res) {
e = pri_schedule_run(pri);
} else {
e = pri_check_event(pri);
}
if (e) {
if (first == pri) {
event1(pri, e);
} else {
event2(pri, e);
}
}
pthread_mutex_unlock(&lock);
}
return NULL;
}
int main(int argc, char *argv[])
{
int pair[2];
pthread_t tmp;
struct pri *pri;
pri_set_message(testmsg);
pri_set_error(testerr);
if (socketpair(AF_LOCAL, SOCK_DGRAM, 0, pair)) {
perror("socketpair");
exit(1);
}
if (!(pri = pri_new(pair[0], PRI_NETWORK, PRI_DEF_SWITCHTYPE))) {
perror("pri(0)");
exit(1);
}
first = pri;
pri_set_debug(pri, DEBUG_LEVEL);
if (pthread_create(&tmp, NULL, dchan, pri)) {
perror("thread(0)");
exit(1);
}
if (!(pri = pri_new(pair[1], PRI_CPE, PRI_DEF_SWITCHTYPE))) {
perror("pri(1)");
exit(1);
}
pri_set_debug(pri, DEBUG_LEVEL);
if (pthread_create(&tmp, NULL, dchan, pri)) {
perror("thread(1)");
exit(1);
}
/* Wait for things to run */
sleep(5);
exit(0);
}