Compare commits
31 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
790e386bdd | ||
|
|
ac91b55cee | ||
|
|
42b8d8eb04 | ||
|
|
d85f96808b | ||
|
|
f2eb8afb7f | ||
|
|
8da0a1e5a7 | ||
|
|
4743ebd26f | ||
|
|
949afd2385 | ||
|
|
480160c5cf | ||
|
|
2f5952fa86 | ||
|
|
be3a8c206b | ||
|
|
ee394a7916 | ||
|
|
91b4a60c1f | ||
|
|
d00abddee3 | ||
|
|
09645488d6 | ||
|
|
24fba7f9b7 | ||
|
|
c3544cb866 | ||
|
|
ccafdd739b | ||
|
|
acf0e055ab | ||
|
|
e1394704ad | ||
|
|
0961ecb4b0 | ||
|
|
a36186ce49 | ||
|
|
5f6e12c3e5 | ||
|
|
d80324dbdd | ||
|
|
e172ca2a03 | ||
|
|
e4f9ea7583 | ||
|
|
b5fa5986b2 | ||
|
|
f63cc76a94 | ||
|
|
cb01262a54 | ||
|
|
79e10c30a1 | ||
|
|
06d9c2aeb3 |
37
Makefile
Executable file → Normal file
37
Makefile
Executable file → Normal file
@@ -24,15 +24,23 @@
|
||||
# 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 $(ALERTING)
|
||||
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
|
||||
@@ -43,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 $<
|
||||
|
||||
@@ -62,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`
|
||||
|
||||
7
libpri.h
Executable file → Normal file
7
libpri.h
Executable file → Normal file
@@ -386,4 +386,11 @@ 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
113
mkdep
Executable 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
|
||||
52
pri.c
Executable file → Normal file
52
pri.c
Executable file → Normal file
@@ -51,6 +51,8 @@ char *pri_switch2str(int sw)
|
||||
return "AT&T 4ESS";
|
||||
case PRI_SWITCH_NI1:
|
||||
return "National ISDN 1";
|
||||
case PRI_SWITCH_EUROISDN_E1:
|
||||
return "EuroISDN";
|
||||
default:
|
||||
return "Unknown switchtype";
|
||||
}
|
||||
@@ -66,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;
|
||||
}
|
||||
@@ -285,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);
|
||||
@@ -332,3 +340,41 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
10
pri_internal.h
Executable file → Normal file
10
pri_internal.h
Executable file → Normal 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 */
|
||||
|
||||
@@ -81,6 +83,14 @@ struct pri {
|
||||
|
||||
/* 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
1
pri_q921.h
Executable file → Normal 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;
|
||||
|
||||
|
||||
0
pri_q931.h
Executable file → Normal file
0
pri_q931.h
Executable file → Normal file
0
prisched.c
Executable file → Normal file
0
prisched.c
Executable file → Normal file
197
q921.c
Executable file → Normal file
197
q921.c
Executable file → Normal 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) {
|
||||
|
||||
392
q931.c
Executable file → Normal file
392
q931.c
Executable file → Normal file
@@ -32,9 +32,12 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define MAX_MAND_IES 10
|
||||
|
||||
struct msgtype {
|
||||
int msgnum;
|
||||
unsigned char *name;
|
||||
int mandies[MAX_MAND_IES];
|
||||
};
|
||||
|
||||
struct msgtype msgs[] = {
|
||||
@@ -43,26 +46,26 @@ struct msgtype msgs[] = {
|
||||
{ Q931_CALL_PROCEEDING, "CALL PROCEEDING" },
|
||||
{ Q931_CONNECT, "CONNECT" },
|
||||
{ Q931_CONNECT_ACKNOWLEDGE, "CONNECT ACKNOWLEDGE" },
|
||||
{ Q931_PROGRESS, "PROGRESS" },
|
||||
{ Q931_SETUP, "SETUP" },
|
||||
{ Q931_PROGRESS, "PROGRESS", { Q931_PROGRESS_INDICATOR } },
|
||||
{ Q931_SETUP, "SETUP", { Q931_BEARER_CAPABILITY, Q931_CHANNEL_IDENT } },
|
||||
{ Q931_SETUP_ACKNOWLEDGE, "SETUP ACKNOWLEDGE" },
|
||||
|
||||
/* Call disestablishment messages */
|
||||
{ Q931_DISCONNECT, "DISCONNECT" },
|
||||
{ Q931_DISCONNECT, "DISCONNECT", { Q931_CAUSE } },
|
||||
{ Q931_RELEASE, "RELEASE" },
|
||||
{ Q931_RELEASE_COMPLETE, "RELEASE COMPLETE" },
|
||||
{ Q931_RESTART, "RESTART" },
|
||||
{ Q931_RESTART_ACKNOWLEDGE, "RESTART ACKNOWLEDGE" },
|
||||
{ Q931_RESTART, "RESTART", { Q931_RESTART_INDICATOR } },
|
||||
{ Q931_RESTART_ACKNOWLEDGE, "RESTART ACKNOWLEDGE", { Q931_RESTART_INDICATOR } },
|
||||
|
||||
/* Miscellaneous */
|
||||
{ Q931_STATUS, "STATUS" },
|
||||
{ Q931_STATUS, "STATUS", { Q931_CAUSE, Q931_CALL_STATE } },
|
||||
{ Q931_STATUS_ENQUIRY, "STATUS ENQUIRY" },
|
||||
{ Q931_USER_INFORMATION, "USER_INFORMATION" },
|
||||
{ Q931_SEGMENT, "SEGMENT" },
|
||||
{ Q931_CONGESTION_CONTROL, "CONGESTION CONTROL" },
|
||||
{ Q931_INFORMATION, "INFORMATION" },
|
||||
{ Q931_FACILITY, "FACILITY" },
|
||||
{ Q931_NOTIFY, "NOTIFY" },
|
||||
{ Q931_NOTIFY, "NOTIFY", { Q931_IE_NOTIFY_IND } },
|
||||
|
||||
/* Call Management */
|
||||
{ Q931_HOLD, "HOLD" },
|
||||
@@ -72,8 +75,8 @@ struct msgtype msgs[] = {
|
||||
{ Q931_RETRIEVE_ACKNOWLEDGE, "RETRIEVE ACKNOWLEDGE" },
|
||||
{ Q931_RETRIEVE_REJECT, "RETRIEVE REJECT" },
|
||||
{ Q931_RESUME, "RESUME" },
|
||||
{ Q931_RESUME_ACKNOWLEDGE, "RESUME ACKNOWLEDGE" },
|
||||
{ Q931_RESUME_REJECT, "RESUME REJECT" },
|
||||
{ Q931_RESUME_ACKNOWLEDGE, "RESUME ACKNOWLEDGE", { Q931_CHANNEL_IDENT } },
|
||||
{ Q931_RESUME_REJECT, "RESUME REJECT", { Q931_CAUSE } },
|
||||
{ Q931_SUSPEND, "SUSPEND" },
|
||||
{ Q931_SUSPEND_ACKNOWLEDGE, "SUSPEND ACKNOWLEDGE" },
|
||||
{ Q931_SUSPEND_REJECT, "SUSPEND REJECT" },
|
||||
@@ -179,7 +182,12 @@ struct msgtype causes[] = {
|
||||
#define LOC_INTERNATIONAL_NETWORK 0x7
|
||||
#define LOC_NETWORK_BEYOND_INTERWORKING 0xa
|
||||
|
||||
#define T_308 4000
|
||||
#define T_305 30000
|
||||
#define T_313 4000
|
||||
|
||||
struct q931_call {
|
||||
struct pri *pri; /* PRI */
|
||||
int cr; /* Call Reference */
|
||||
int forceinvert; /* Force inversion of call number even if 0 */
|
||||
q931_call *next;
|
||||
@@ -220,6 +228,7 @@ struct q931_call {
|
||||
|
||||
int peercallstate; /* Call state of peer as reported */
|
||||
int ourcallstate; /* Our call state */
|
||||
int sugcallstate; /* Status call state */
|
||||
|
||||
int callerplan;
|
||||
int callerpres; /* Caller presentation */
|
||||
@@ -230,7 +239,10 @@ struct q931_call {
|
||||
int nonisdn;
|
||||
char callednum[256]; /* Called Number */
|
||||
int complete; /* no more digits coming */
|
||||
int newcall; /* if the received message has a new call reference value */
|
||||
|
||||
int retranstimer; /* Timer for retransmitting DISC */
|
||||
int t308_timedout; /* Whether t308 timed out once */
|
||||
int redirectingplan;
|
||||
int redirectingpres;
|
||||
int redirectingreason;
|
||||
@@ -273,6 +285,7 @@ static void call_init(struct q931_call *c)
|
||||
c->chanflags = 0;
|
||||
c->next = NULL;
|
||||
c->sentchannel = 0;
|
||||
c->newcall = 1;
|
||||
c->ourcallstate = Q931_CALL_STATE_NULL;
|
||||
c->peercallstate = Q931_CALL_STATE_NULL;
|
||||
}
|
||||
@@ -628,14 +641,15 @@ static int transmit_bearer_capability(struct pri *pri, q931_call *call, int msgt
|
||||
ie->data[1] = call->transmoderate | 0x80;
|
||||
if (call->transmoderate != TRANS_MODE_PACKET) {
|
||||
/* If you have an AT&T 4ESS, you don't send any more info */
|
||||
if (pri->switchtype == PRI_SWITCH_ATT4ESS)
|
||||
if ((pri->switchtype != PRI_SWITCH_ATT4ESS) && (call->userl1 > -1)) {
|
||||
ie->data[2] = call->userl1 | 0x80; /* XXX Ext bit? XXX */
|
||||
if (call->userl1 == PRI_LAYER_1_ITU_RATE_ADAPT) {
|
||||
ie->data[3] = call->rateadaption | 0x80;
|
||||
return 6;
|
||||
}
|
||||
return 5;
|
||||
} else
|
||||
return 4;
|
||||
ie->data[2] = call->userl1 | 0x80; /* XXX Ext bit? XXX */
|
||||
if (call->userl1 == PRI_LAYER_1_ITU_RATE_ADAPT) {
|
||||
ie->data[3] = call->rateadaption | 0x80;
|
||||
return 6;
|
||||
}
|
||||
return 5;
|
||||
} else {
|
||||
ie->data[2] = 0x80 | call->userl2;
|
||||
ie->data[3] = 0x80 | call->userl3;
|
||||
@@ -830,7 +844,11 @@ static int transmit_calling_party_number(struct pri *pri, q931_call *call, int m
|
||||
|
||||
static void dump_user_user(q931_ie *ie, int len, char prefix)
|
||||
{
|
||||
|
||||
int x;
|
||||
pri_message("%c User-User Information (len=%2d) [ ", prefix, ie->len);
|
||||
for (x=0;x<ie->len;x++)
|
||||
pri_message("%c", ie->data[x] & 0x7f);
|
||||
pri_message(" ]\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -908,7 +926,7 @@ static int receive_display(struct pri *pri, q931_call *call, int msgtype, q931_i
|
||||
|
||||
static int transmit_display(struct pri *pri, q931_call *call, int msgtype, q931_ie *ie, int len)
|
||||
{
|
||||
if (pri->switchtype != PRI_SWITCH_NI1) {
|
||||
if ((pri->switchtype != PRI_SWITCH_NI1) && strlen(call->callername)) {
|
||||
ie->data[0] = 0xb1;
|
||||
memcpy(ie->data + 1, call->callername, strlen(call->callername));
|
||||
return 3 + strlen(call->callername);
|
||||
@@ -958,7 +976,7 @@ static int transmit_call_state(struct pri *pri, q931_call *call, int msgtype, q9
|
||||
|
||||
static int receive_call_state(struct pri *pri, q931_call *call, int msgtype, q931_ie *ie, int len)
|
||||
{
|
||||
call->ourcallstate = ie->data[0] & 0x3f;
|
||||
call->sugcallstate = ie->data[0] & 0x3f;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1238,9 +1256,22 @@ static inline int q931_cr(q931_h *h)
|
||||
pri_error("Call Reference Length Too long: %d\n", h->crlen);
|
||||
return -1;
|
||||
}
|
||||
for (x=0;x<h->crlen;x++) {
|
||||
cr <<= 8;
|
||||
cr |= h->crv[x];
|
||||
switch (h->crlen) {
|
||||
case 2:
|
||||
for (x=0;x<h->crlen;x++) {
|
||||
cr <<= 8;
|
||||
cr |= h->crv[x];
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
cr = h->crv[0];
|
||||
if (cr & 0x80) {
|
||||
cr &= ~0x80;
|
||||
cr |= 0x8000;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
pri_error("Call Reference Length not supported: %d\n", h->crlen);
|
||||
}
|
||||
return cr;
|
||||
}
|
||||
@@ -1279,6 +1310,7 @@ static q931_call *q931_getcall(struct pri *pri, int cr)
|
||||
call_init(cur);
|
||||
/* Call reference */
|
||||
cur->cr = cr;
|
||||
cur->pri = pri;
|
||||
/* Append to end of list */
|
||||
if (prev)
|
||||
prev->next = cur;
|
||||
@@ -1318,6 +1350,8 @@ static void q931_destroycall(struct pri *pri, int cr)
|
||||
pri->calls = cur->next;
|
||||
if (pri->debug & PRI_DEBUG_Q931_STATE)
|
||||
pri_message("NEW_HANGUP DEBUG: Destroying the call, ourstate %s, peerstate %s\n",callstate2str(cur->ourcallstate),callstate2str(cur->peercallstate));
|
||||
if (cur->retranstimer)
|
||||
pri_schedule_del(pri, cur->retranstimer);
|
||||
free(cur);
|
||||
return;
|
||||
}
|
||||
@@ -1442,6 +1476,9 @@ static int q931_xmit(struct pri *pri, q931_h *h, int len, int cr)
|
||||
right order in the log */
|
||||
if (pri->debug & PRI_DEBUG_Q931_DUMP)
|
||||
q931_dump(h, len, 1);
|
||||
#ifdef LIBPRI_COUNTERS
|
||||
pri->q931_txcount++;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1478,21 +1515,24 @@ static int send_message(struct pri *pri, q931_call *c, int msgtype, int ies[])
|
||||
|
||||
static int status_ies[] = { Q931_CAUSE, Q931_CALL_STATE, -1 };
|
||||
|
||||
static int q931_status(struct pri *pri, q931_call *c)
|
||||
static int q931_status(struct pri *pri, q931_call *c, int cause)
|
||||
{
|
||||
q931_call *cur = NULL;
|
||||
if (!cause)
|
||||
cause = PRI_CAUSE_RESPONSE_TO_STATUS_ENQUIRY;
|
||||
if (c->cr > -1)
|
||||
cur = pri->calls;
|
||||
while(cur) {
|
||||
if (cur->cr == c->cr) {
|
||||
cur->cause=PRI_CAUSE_RESPONSE_TO_STATUS_ENQUIRY;
|
||||
cur->cause=cause;
|
||||
cur->causecode = CODE_CCITT;
|
||||
cur->causeloc = LOC_PRIV_NET_LOCAL_USER;
|
||||
cur->causeloc = LOC_USER;
|
||||
break;
|
||||
}
|
||||
cur = cur->next;
|
||||
}
|
||||
if (!cur) {
|
||||
pri_message("YYY Here we get reset YYY\n");
|
||||
/* something went wrong, respond with "no such call" */
|
||||
c->ourcallstate = Q931_CALL_STATE_NULL;
|
||||
c->peercallstate = Q931_CALL_STATE_NULL;
|
||||
@@ -1575,6 +1615,56 @@ int q931_setup_ack(struct pri *pri, q931_call *c, int channel, int nonisdn)
|
||||
return send_message(pri, c, Q931_SETUP_ACKNOWLEDGE, connect_ies);
|
||||
}
|
||||
|
||||
static void pri_connect_timeout(void *data)
|
||||
{
|
||||
struct q931_call *c = data;
|
||||
struct pri *pri = c->pri;
|
||||
if (pri->debug & PRI_DEBUG_Q931_STATE)
|
||||
pri_message("Timed out looking for connect acknowledge\n");
|
||||
q931_disconnect(pri, c, PRI_CAUSE_NORMAL_CLEARING);
|
||||
|
||||
}
|
||||
|
||||
static void pri_release_timeout(void *data)
|
||||
{
|
||||
struct q931_call *c = data;
|
||||
struct pri *pri = c->pri;
|
||||
if (pri->debug & PRI_DEBUG_Q931_STATE)
|
||||
pri_message("Timed out looking for release complete\n");
|
||||
c->t308_timedout++;
|
||||
c->alive = 1;
|
||||
q931_release(pri, c, PRI_CAUSE_NORMAL_CLEARING);
|
||||
}
|
||||
|
||||
static void pri_release_finaltimeout(void *data)
|
||||
{
|
||||
struct q931_call *c = data;
|
||||
struct pri *pri = c->pri;
|
||||
c->alive = 1;
|
||||
if (pri->debug & PRI_DEBUG_Q931_STATE)
|
||||
pri_message("Final time-out looking for release complete\n");
|
||||
c->t308_timedout++;
|
||||
c->ourcallstate = Q931_CALL_STATE_NULL;
|
||||
c->peercallstate = Q931_CALL_STATE_NULL;
|
||||
pri->schedev = 1;
|
||||
pri->ev.e = PRI_EVENT_HANGUP_ACK;
|
||||
pri->ev.hangup.channel = c->channelno;
|
||||
pri->ev.hangup.cref = c->cr;
|
||||
pri->ev.hangup.cause = c->cause;
|
||||
pri->ev.hangup.call = c;
|
||||
q931_hangup(pri, c, c->cause);
|
||||
}
|
||||
|
||||
static void pri_disconnect_timeout(void *data)
|
||||
{
|
||||
struct q931_call *c = data;
|
||||
struct pri *pri = c->pri;
|
||||
if (pri->debug & PRI_DEBUG_Q931_STATE)
|
||||
pri_message("Timed out looking for release\n");
|
||||
c->alive = 1;
|
||||
q931_release(pri, c, PRI_CAUSE_NORMAL_CLEARING);
|
||||
}
|
||||
|
||||
int q931_connect(struct pri *pri, q931_call *c, int channel, int nonisdn)
|
||||
{
|
||||
if (channel)
|
||||
@@ -1590,6 +1680,11 @@ int q931_connect(struct pri *pri, q931_call *c, int channel, int nonisdn)
|
||||
c->ourcallstate = Q931_CALL_STATE_CONNECT_REQUEST;
|
||||
c->peercallstate = Q931_CALL_STATE_ACTIVE;
|
||||
c->alive = 1;
|
||||
/* Setup timer */
|
||||
if (c->retranstimer)
|
||||
pri_schedule_del(pri, c->retranstimer);
|
||||
if (pri->localtype == PRI_CPE)
|
||||
c->retranstimer = pri_schedule_event(pri, T_313, pri_connect_timeout, c);
|
||||
return send_message(pri, c, Q931_CONNECT, connect_ies);
|
||||
}
|
||||
|
||||
@@ -1604,9 +1699,16 @@ int q931_release(struct pri *pri, q931_call *c, int cause)
|
||||
c->cause = cause;
|
||||
c->causecode = CODE_CCITT;
|
||||
c->causeloc = LOC_PRIV_NET_LOCAL_USER;
|
||||
if (c->acked)
|
||||
if (c->acked) {
|
||||
if (c->retranstimer)
|
||||
pri_schedule_del(pri, c->retranstimer);
|
||||
if (!c->t308_timedout) {
|
||||
c->retranstimer = pri_schedule_event(pri, T_308, pri_release_timeout, c);
|
||||
} else {
|
||||
c->retranstimer = pri_schedule_event(pri, T_308, pri_release_finaltimeout, c);
|
||||
}
|
||||
return send_message(pri, c, Q931_RELEASE, release_ies);
|
||||
else
|
||||
} else
|
||||
return send_message(pri, c, Q931_RELEASE_COMPLETE, release_ies); /* Yes, release_ies, not release_complete_ies */
|
||||
} else
|
||||
return 0;
|
||||
@@ -1643,6 +1745,9 @@ int q931_disconnect(struct pri *pri, q931_call *c, int cause)
|
||||
c->causecode = CODE_CCITT;
|
||||
c->causeloc = LOC_PRIV_NET_LOCAL_USER;
|
||||
c->sendhangupack = 1;
|
||||
if (c->retranstimer)
|
||||
pri_schedule_del(pri, c->retranstimer);
|
||||
c->retranstimer = pri_schedule_event(pri, T_305, pri_disconnect_timeout, c);
|
||||
return send_message(pri, c, Q931_DISCONNECT, disconnect_ies);
|
||||
} else
|
||||
return 0;
|
||||
@@ -1669,7 +1774,7 @@ int q931_setup(struct pri *pri, q931_call *c, int transmode, int channel, int ex
|
||||
c->slotmap = -1;
|
||||
c->ds1no = -1;
|
||||
c->nonisdn = nonisdn;
|
||||
|
||||
c->newcall = 0;
|
||||
if (exclusive)
|
||||
c->chanflags = FLAG_EXCLUSIVE;
|
||||
else
|
||||
@@ -1803,11 +1908,15 @@ int q931_hangup(struct pri *pri, q931_call *c, int cause)
|
||||
break;
|
||||
case Q931_CALL_STATE_DISCONNECT_REQUEST:
|
||||
/* sent DISCONNECT */
|
||||
q931_release(pri,c,cause);
|
||||
break;
|
||||
case Q931_CALL_STATE_DISCONNECT_INDICATION:
|
||||
/* received DISCONNECT */
|
||||
if (c->peercallstate == Q931_CALL_STATE_DISCONNECT_REQUEST)
|
||||
if (c->peercallstate == Q931_CALL_STATE_DISCONNECT_REQUEST) {
|
||||
c->alive = 1;
|
||||
q931_release(pri,c,cause);
|
||||
}
|
||||
break;
|
||||
case Q931_CALL_STATE_RELEASE_REQUEST:
|
||||
/* sent RELEASE */
|
||||
/* don't do anything, waiting for RELEASE_COMPLETE */
|
||||
@@ -1830,19 +1939,28 @@ int q931_receive(struct pri *pri, q931_h *h, int len)
|
||||
q931_mh *mh;
|
||||
q931_call *c;
|
||||
q931_ie *ie;
|
||||
int x;
|
||||
unsigned int x;
|
||||
int y;
|
||||
int res;
|
||||
int r;
|
||||
int mandies[MAX_MAND_IES];
|
||||
int missingmand;
|
||||
if (pri->debug & PRI_DEBUG_Q931_DUMP)
|
||||
q931_dump(h, len, 0);
|
||||
#ifdef LIBPRI_COUNTERS
|
||||
pri->q931_rxcount++;
|
||||
#endif
|
||||
mh = (q931_mh *)(h->contents + h->crlen);
|
||||
if (h->pd == 0x3) {
|
||||
/* This is the weird maintenance stuff. We majorly
|
||||
KLUDGE this by changing byte 4 from a 0xf (SERVICE)
|
||||
to a 0x7 (SERVICE ACKNOWLEDGE) */
|
||||
h->raw[3] -= 0x8;
|
||||
h->raw[h->crlen + 2] -= 0x8;
|
||||
q931_xmit(pri, h, len, 1);
|
||||
return 0;
|
||||
} else if (h->pd != Q931_PROTOCOL_DISCRIMINATOR) {
|
||||
pri_error("Warning: unknown protocol discriminator received\n");
|
||||
return 0;
|
||||
}
|
||||
c = q931_getcall(pri, q931_cr(h));
|
||||
if (!c) {
|
||||
@@ -1898,8 +2016,12 @@ int q931_receive(struct pri *pri, q931_h *h, int len)
|
||||
case Q931_PROGRESS:
|
||||
c->progress = -1;
|
||||
break;
|
||||
case Q931_CALL_PROCEEDING:
|
||||
case Q931_CONNECT_ACKNOWLEDGE:
|
||||
if (c->retranstimer)
|
||||
pri_schedule_del(pri, c->retranstimer);
|
||||
c->retranstimer = 0;
|
||||
/* Fall through */
|
||||
case Q931_CALL_PROCEEDING:
|
||||
/* Do nothing */
|
||||
break;
|
||||
case Q931_RELEASE:
|
||||
@@ -1907,12 +2029,19 @@ int q931_receive(struct pri *pri, q931_h *h, int len)
|
||||
c->cause = -1;
|
||||
c->causecode = -1;
|
||||
c->causeloc = -1;
|
||||
if (c->retranstimer)
|
||||
pri_schedule_del(pri, c->retranstimer);
|
||||
c->retranstimer = 0;
|
||||
break;
|
||||
case Q931_RELEASE_COMPLETE:
|
||||
if (c->retranstimer)
|
||||
pri_schedule_del(pri, c->retranstimer);
|
||||
c->retranstimer = 0;
|
||||
case Q931_STATUS:
|
||||
c->cause = -1;
|
||||
c->causecode = -1;
|
||||
c->causeloc = -1;
|
||||
c->sugcallstate = -1;
|
||||
break;
|
||||
case Q931_RESTART_ACKNOWLEDGE:
|
||||
c->channelno = -1;
|
||||
@@ -1923,10 +2052,11 @@ int q931_receive(struct pri *pri, q931_h *h, int len)
|
||||
break;
|
||||
case Q931_SETUP_ACKNOWLEDGE:
|
||||
break;
|
||||
case Q931_NOTIFY:
|
||||
break;
|
||||
case Q931_USER_INFORMATION:
|
||||
case Q931_SEGMENT:
|
||||
case Q931_CONGESTION_CONTROL:
|
||||
case Q931_NOTIFY:
|
||||
case Q931_HOLD:
|
||||
case Q931_HOLD_ACKNOWLEDGE:
|
||||
case Q931_HOLD_REJECT:
|
||||
@@ -1940,29 +2070,66 @@ int q931_receive(struct pri *pri, q931_h *h, int len)
|
||||
case Q931_SUSPEND_ACKNOWLEDGE:
|
||||
case Q931_SUSPEND_REJECT:
|
||||
pri_error("!! Not yet handling pre-handle message type %s (%d)\n", msg2str(mh->msg), mh->msg);
|
||||
return -1;
|
||||
|
||||
/* Fall through */
|
||||
default:
|
||||
pri_error("!! Don't know how to pre-handle message type %s (%d)\n", msg2str(mh->msg), mh->msg);
|
||||
pri_error("!! Don't know how to post-handle message type %s (%d)\n", msg2str(mh->msg), mh->msg);
|
||||
q931_status(pri,c, PRI_CAUSE_MESSAGE_TYPE_NONEXIST);
|
||||
if (c->newcall)
|
||||
q931_destroycall(pri,c->cr);
|
||||
return -1;
|
||||
}
|
||||
memset(mandies, 0, sizeof(mandies));
|
||||
missingmand = 0;
|
||||
for (x=0;x<sizeof(msgs) / sizeof(msgs[0]); x++) {
|
||||
if (msgs[x].msgnum == mh->msg) {
|
||||
memcpy(mandies, msgs[x].mandies, sizeof(mandies));
|
||||
}
|
||||
}
|
||||
x = 0;
|
||||
/* Do real IE processing */
|
||||
len -= (h->crlen + 3);
|
||||
while(len) {
|
||||
ie = (q931_ie *)(mh->data + x);
|
||||
for (y=0;y<MAX_MAND_IES;y++) {
|
||||
if (mandies[y] == ie->ie)
|
||||
mandies[y] = 0;
|
||||
}
|
||||
r = ielen(ie);
|
||||
if (r > len) {
|
||||
pri_error("XXX Message longer than it should be?? XXX\n");
|
||||
return -1;
|
||||
}
|
||||
q931_handle_ie(pri, c, mh->msg, ie);
|
||||
y = q931_handle_ie(pri, c, mh->msg, ie);
|
||||
if (!(ie->ie & 0xf0) && (y < 0))
|
||||
mandies[MAX_MAND_IES - 1] = ie->ie;
|
||||
x += r;
|
||||
len -= r;
|
||||
}
|
||||
missingmand = 0;
|
||||
for (x=0;x<MAX_MAND_IES;x++) {
|
||||
if (mandies[x]) {
|
||||
pri_error("XXX Missing mandatory IE %d/%s XXX\n", mandies[x], ie2str(mandies[x]));
|
||||
missingmand++;
|
||||
}
|
||||
}
|
||||
/* check if there is no channel identyfication when we're configured as network -> that's not an error */
|
||||
if (missingmand && pri->localtype == PRI_NETWORK && mh->msg == Q931_SETUP) {
|
||||
for (x=0;x<MAX_MAND_IES;x++) {
|
||||
if (mandies[x] == Q931_CHANNEL_IDENT) {
|
||||
missingmand--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Post handling */
|
||||
switch(mh->msg) {
|
||||
case Q931_RESTART:
|
||||
if (missingmand) {
|
||||
q931_status(pri, c, PRI_CAUSE_MANDATORY_IE_MISSING);
|
||||
q931_destroycall(pri, c->cr);
|
||||
break;
|
||||
}
|
||||
c->ourcallstate = Q931_CALL_STATE_RESTART;
|
||||
c->peercallstate = Q931_CALL_STATE_RESTART_REQUEST;
|
||||
/* Send back the Restart Acknowledge */
|
||||
@@ -1972,6 +2139,15 @@ int q931_receive(struct pri *pri, q931_h *h, int len)
|
||||
pri->ev.restart.channel = c->channelno;
|
||||
return Q931_RES_HAVEEVENT;
|
||||
case Q931_SETUP:
|
||||
if (missingmand) {
|
||||
q931_release_complete(pri, c, PRI_CAUSE_MANDATORY_IE_MISSING);
|
||||
break;
|
||||
}
|
||||
/* Must be new call */
|
||||
if (!c->newcall) {
|
||||
break;
|
||||
}
|
||||
c->newcall = 0;
|
||||
c->ourcallstate = Q931_CALL_STATE_CALL_PRESENT;
|
||||
c->peercallstate = Q931_CALL_STATE_CALL_INITIATED;
|
||||
/* it's not yet a call since higher level can respond with RELEASE or RELEASE_COMPLETE */
|
||||
@@ -1991,12 +2167,17 @@ int q931_receive(struct pri *pri, q931_h *h, int len)
|
||||
pri->ev.ring.call = c;
|
||||
pri->ev.ring.layer1 = c->userl1;
|
||||
pri->ev.ring.complete = c->complete;
|
||||
pri->ev.ring.ctype = c->transcapability;
|
||||
if (c->transmoderate != TRANS_MODE_64_CIRCUIT) {
|
||||
q931_release(pri, c, PRI_CAUSE_BEARERCAPABILITY_NOTIMPL);
|
||||
q931_release_complete(pri, c, PRI_CAUSE_BEARERCAPABILITY_NOTIMPL);
|
||||
break;
|
||||
}
|
||||
return Q931_RES_HAVEEVENT;
|
||||
case Q931_ALERTING:
|
||||
if (c->newcall) {
|
||||
q931_release_complete(pri,c,PRI_CAUSE_INVALID_CALL_REFERENCE);
|
||||
break;
|
||||
}
|
||||
c->ourcallstate = Q931_CALL_STATE_CALL_DELIVERED;
|
||||
c->peercallstate = Q931_CALL_STATE_CALL_RECEIVED;
|
||||
pri->ev.e = PRI_EVENT_RINGING;
|
||||
@@ -2005,6 +2186,14 @@ int q931_receive(struct pri *pri, q931_h *h, int len)
|
||||
pri->ev.ringing.call = c;
|
||||
return Q931_RES_HAVEEVENT;
|
||||
case Q931_CONNECT:
|
||||
if (c->newcall) {
|
||||
q931_release_complete(pri,c,PRI_CAUSE_INVALID_CALL_REFERENCE);
|
||||
break;
|
||||
}
|
||||
if (c->ourcallstate == Q931_CALL_STATE_ACTIVE) {
|
||||
q931_status(pri, c, PRI_CAUSE_WRONG_MESSAGE);
|
||||
break;
|
||||
}
|
||||
c->ourcallstate = Q931_CALL_STATE_ACTIVE;
|
||||
c->peercallstate = Q931_CALL_STATE_CONNECT_REQUEST;
|
||||
pri->ev.e = PRI_EVENT_ANSWER;
|
||||
@@ -2014,6 +2203,10 @@ int q931_receive(struct pri *pri, q931_h *h, int len)
|
||||
q931_connect_acknowledge(pri, c);
|
||||
return Q931_RES_HAVEEVENT;
|
||||
case Q931_FACILITY:
|
||||
if (c->newcall) {
|
||||
q931_release_complete(pri,c,PRI_CAUSE_INVALID_CALL_REFERENCE);
|
||||
break;
|
||||
}
|
||||
pri->ev.e = PRI_EVENT_FACNAME;
|
||||
strncpy(pri->ev.facname.callingname, c->callername, sizeof(pri->ev.facname.callingname) - 1);
|
||||
strncpy(pri->ev.facname.callingnum, c->callernum, sizeof(pri->ev.facname.callingname) - 1);
|
||||
@@ -2025,22 +2218,82 @@ int q931_receive(struct pri *pri, q931_h *h, int len)
|
||||
#endif
|
||||
return Q931_RES_HAVEEVENT;
|
||||
case Q931_PROGRESS:
|
||||
if (missingmand) {
|
||||
q931_status(pri, c, PRI_CAUSE_MANDATORY_IE_MISSING);
|
||||
q931_destroycall(pri, c->cr);
|
||||
break;
|
||||
}
|
||||
/* Fall through */
|
||||
case Q931_CALL_PROCEEDING:
|
||||
if (c->newcall) {
|
||||
q931_release_complete(pri,c,PRI_CAUSE_INVALID_CALL_REFERENCE);
|
||||
break;
|
||||
}
|
||||
if ((c->ourcallstate != Q931_CALL_STATE_CALL_INITIATED) &&
|
||||
(c->ourcallstate != Q931_CALL_STATE_OVERLAP_SENDING) &&
|
||||
(c->ourcallstate != Q931_CALL_STATE_CALL_DELIVERED) &&
|
||||
(c->ourcallstate != Q931_CALL_STATE_OUTGOING_CALL_PROCEEDING)) {
|
||||
q931_status(pri,c,PRI_CAUSE_WRONG_MESSAGE);
|
||||
break;
|
||||
}
|
||||
pri->ev.e = PRI_EVENT_PROCEEDING;
|
||||
pri->ev.proceeding.channel = c->channelno;
|
||||
c->ourcallstate = Q931_CALL_STATE_OUTGOING_CALL_PROCEEDING;
|
||||
c->peercallstate = Q931_CALL_STATE_INCOMING_CALL_PROCEEDING;
|
||||
if (mh->msg == Q931_CALL_PROCEEDING) {
|
||||
c->ourcallstate = Q931_CALL_STATE_OUTGOING_CALL_PROCEEDING;
|
||||
c->peercallstate = Q931_CALL_STATE_INCOMING_CALL_PROCEEDING;
|
||||
}
|
||||
return Q931_RES_HAVEEVENT;
|
||||
case Q931_CONNECT_ACKNOWLEDGE:
|
||||
if (c->newcall) {
|
||||
q931_release_complete(pri,c,PRI_CAUSE_INVALID_CALL_REFERENCE);
|
||||
break;
|
||||
}
|
||||
if (c->ourcallstate != Q931_CALL_STATE_CONNECT_REQUEST) {
|
||||
q931_status(pri,c,PRI_CAUSE_WRONG_MESSAGE);
|
||||
break;
|
||||
}
|
||||
c->ourcallstate = Q931_CALL_STATE_ACTIVE;
|
||||
c->peercallstate = Q931_CALL_STATE_ACTIVE;
|
||||
break;
|
||||
case Q931_STATUS:
|
||||
if (missingmand) {
|
||||
q931_status(pri, c, PRI_CAUSE_MANDATORY_IE_MISSING);
|
||||
q931_destroycall(pri, c->cr);
|
||||
break;
|
||||
}
|
||||
if (c->newcall) {
|
||||
if (c->cr & 0x7fff)
|
||||
q931_release_complete(pri,c,PRI_CAUSE_WRONG_CALL_STATE);
|
||||
break;
|
||||
}
|
||||
/* Do nothing */
|
||||
/* FIXME if the callstate != ourcallstate send RELEASE */
|
||||
/* Also when the STATUS asks for the call of an unexisting reference send RELEASE_COMPL */
|
||||
if ((pri->debug & PRI_DEBUG_Q931_ANOMALY) &&
|
||||
(c->cause != PRI_CAUSE_INTERWORKING))
|
||||
(c->cause != PRI_CAUSE_INTERWORKING))
|
||||
pri_error("Received unsolicited status: %s\n", pri_cause2str(c->cause));
|
||||
if (!c->sugcallstate) {
|
||||
pri->ev.hangup.channel = c->channelno;
|
||||
pri->ev.hangup.cref = c->cr;
|
||||
pri->ev.hangup.cause = c->cause;
|
||||
pri->ev.hangup.call = c;
|
||||
/* Free resources */
|
||||
c->ourcallstate = Q931_CALL_STATE_NULL;
|
||||
c->peercallstate = Q931_CALL_STATE_NULL;
|
||||
if (c->alive) {
|
||||
pri->ev.e = PRI_EVENT_HANGUP;
|
||||
res = Q931_RES_HAVEEVENT;
|
||||
c->alive = 0;
|
||||
} else if (c->sendhangupack) {
|
||||
res = Q931_RES_HAVEEVENT;
|
||||
pri->ev.e = PRI_EVENT_HANGUP_ACK;
|
||||
q931_hangup(pri, c, c->cause);
|
||||
} else {
|
||||
q931_hangup(pri, c, c->cause);
|
||||
res = 0;
|
||||
}
|
||||
if (res)
|
||||
return res;
|
||||
}
|
||||
break;
|
||||
case Q931_RELEASE_COMPLETE:
|
||||
c->ourcallstate = Q931_CALL_STATE_NULL;
|
||||
@@ -2066,15 +2319,37 @@ int q931_receive(struct pri *pri, q931_h *h, int len)
|
||||
q931_hangup(pri,c,c->cause);
|
||||
break;
|
||||
case Q931_RELEASE:
|
||||
if (missingmand) {
|
||||
q931_release_complete(pri, c, PRI_CAUSE_MANDATORY_IE_MISSING);
|
||||
break;
|
||||
}
|
||||
if (c->ourcallstate == Q931_CALL_STATE_RELEASE_REQUEST)
|
||||
c->peercallstate = Q931_CALL_STATE_NULL;
|
||||
else {
|
||||
c->peercallstate = Q931_CALL_STATE_RELEASE_REQUEST;
|
||||
}
|
||||
c->ourcallstate = Q931_CALL_STATE_NULL;
|
||||
c->peercallstate = Q931_CALL_STATE_RELEASE_REQUEST;
|
||||
pri->ev.e = PRI_EVENT_HANGUP;
|
||||
pri->ev.hangup.channel = c->channelno;
|
||||
pri->ev.hangup.cref = c->cr;
|
||||
pri->ev.hangup.cause = c->cause;
|
||||
pri->ev.hangup.call = c;
|
||||
return Q931_RES_HAVEEVENT;
|
||||
/* Don't send release complete if they send us release
|
||||
while we sent it, assume a NULL state */
|
||||
if (c->newcall)
|
||||
q931_release_complete(pri,c,PRI_CAUSE_INVALID_CALL_REFERENCE);
|
||||
else
|
||||
return Q931_RES_HAVEEVENT;
|
||||
break;
|
||||
case Q931_DISCONNECT:
|
||||
if (missingmand) {
|
||||
q931_release(pri, c, PRI_CAUSE_MANDATORY_IE_MISSING);
|
||||
break;
|
||||
}
|
||||
if (c->newcall) {
|
||||
q931_release_complete(pri,c,PRI_CAUSE_INVALID_CALL_REFERENCE);
|
||||
break;
|
||||
}
|
||||
c->ourcallstate = Q931_CALL_STATE_DISCONNECT_INDICATION;
|
||||
c->peercallstate = Q931_CALL_STATE_DISCONNECT_REQUEST;
|
||||
c->sendhangupack = 1;
|
||||
@@ -2084,10 +2359,6 @@ int q931_receive(struct pri *pri, q931_h *h, int len)
|
||||
pri->ev.hangup.cref = c->cr;
|
||||
pri->ev.hangup.cause = c->cause;
|
||||
pri->ev.hangup.call = c;
|
||||
#if 0 /* Require the user app to call release */
|
||||
/* Send a release with no cause */
|
||||
q931_release(pri, c, -1);
|
||||
#endif
|
||||
if (c->alive)
|
||||
return Q931_RES_HAVEEVENT;
|
||||
else
|
||||
@@ -2104,6 +2375,10 @@ int q931_receive(struct pri *pri, q931_h *h, int len)
|
||||
overlap dialing received digit
|
||||
+ the "Complete" msg which is basically an EOF on further digits
|
||||
XXX */
|
||||
if (c->newcall) {
|
||||
q931_release_complete(pri,c,PRI_CAUSE_INVALID_CALL_REFERENCE);
|
||||
break;
|
||||
}
|
||||
if (c->ourcallstate!=Q931_CALL_STATE_OVERLAP_RECEIVING)
|
||||
break;
|
||||
pri->ev.e = PRI_EVENT_INFO_RECEIVED;
|
||||
@@ -2112,19 +2387,29 @@ int q931_receive(struct pri *pri, q931_h *h, int len)
|
||||
strncpy(pri->ev.ring.callednum, c->callednum, sizeof(pri->ev.ring.callednum) - 1);
|
||||
pri->ev.ring.complete = c->complete; /* this covers IE 33 (Sending Complete) */
|
||||
return Q931_RES_HAVEEVENT;
|
||||
break;
|
||||
case Q931_STATUS_ENQUIRY:
|
||||
q931_status(pri,c);
|
||||
if (c->newcall) {
|
||||
q931_release_complete(pri, c, PRI_CAUSE_INVALID_CALL_REFERENCE);
|
||||
} else
|
||||
q931_status(pri,c, 0);
|
||||
break;
|
||||
case Q931_SETUP_ACKNOWLEDGE:
|
||||
if (c->newcall) {
|
||||
q931_release_complete(pri,c,PRI_CAUSE_INVALID_CALL_REFERENCE);
|
||||
break;
|
||||
}
|
||||
c->ourcallstate = Q931_CALL_STATE_OVERLAP_SENDING;
|
||||
c->peercallstate = Q931_CALL_STATE_OVERLAP_RECEIVING;
|
||||
pri->ev.e = PRI_EVENT_SETUP_ACK;
|
||||
pri->ev.setup_ack.channel = c->channelno;
|
||||
return Q931_RES_HAVEEVENT;
|
||||
case Q931_NOTIFY:
|
||||
/* Do nothing */
|
||||
break;
|
||||
case Q931_USER_INFORMATION:
|
||||
case Q931_SEGMENT:
|
||||
case Q931_CONGESTION_CONTROL:
|
||||
case Q931_NOTIFY:
|
||||
case Q931_HOLD:
|
||||
case Q931_HOLD_ACKNOWLEDGE:
|
||||
case Q931_HOLD_REJECT:
|
||||
@@ -2138,10 +2423,13 @@ int q931_receive(struct pri *pri, q931_h *h, int len)
|
||||
case Q931_SUSPEND_ACKNOWLEDGE:
|
||||
case Q931_SUSPEND_REJECT:
|
||||
pri_error("!! Not yet handling post-handle message type %s (%d)\n", msg2str(mh->msg), mh->msg);
|
||||
return -1;
|
||||
|
||||
/* Fall through */
|
||||
default:
|
||||
|
||||
pri_error("!! Don't know how to post-handle message type %s (%d)\n", msg2str(mh->msg), mh->msg);
|
||||
q931_status(pri,c, PRI_CAUSE_MESSAGE_TYPE_NONEXIST);
|
||||
if (c->newcall)
|
||||
q931_destroycall(pri,c->cr);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
234
testprilib.c
Normal file
234
testprilib.c
Normal 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user