Compare commits
125 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1f98766ae2 | ||
|
|
b45e8995c7 | ||
|
|
316cf41fc7 | ||
|
|
c747aadbea | ||
|
|
2b7b7e2e68 | ||
|
|
9682be31fb | ||
|
|
ea146a8f6f | ||
|
|
12155fa6c3 | ||
|
|
96535a0c17 | ||
|
|
cac414333f | ||
|
|
748702c5c5 | ||
|
|
6dd859f5de | ||
|
|
5fd79b6b1b | ||
|
|
e88ac71b3d | ||
|
|
5166adfb1e | ||
|
|
f8b7c404a0 | ||
|
|
b93317f38b | ||
|
|
18958fa7e8 | ||
|
|
c9bb969586 | ||
|
|
7cdd6c7f2c | ||
|
|
3193d779ef | ||
|
|
97648bb1b4 | ||
|
|
20e146406b | ||
|
|
1e5fad5fe7 | ||
|
|
dd9ba5b8a5 | ||
|
|
d4eab6216e | ||
|
|
1cabafb5fb | ||
|
|
66781c3141 | ||
|
|
832475b271 | ||
|
|
6ccb8df101 | ||
|
|
fd0f41e4a5 | ||
|
|
0933575a5d | ||
|
|
818a8cb57a | ||
|
|
de0e6ba4cc | ||
|
|
30d983f45f | ||
|
|
d0c78dd62d | ||
|
|
551f0fafc8 | ||
|
|
2300f57294 | ||
|
|
f065327cc1 | ||
|
|
bce8bfb87f | ||
|
|
4ae8cc7bcf | ||
|
|
76955b74c3 | ||
|
|
baefdcb18d | ||
|
|
7aac157b7f | ||
|
|
2c26d98a89 | ||
|
|
c413151375 | ||
|
|
8098266c90 | ||
|
|
c8528b633a | ||
|
|
c591726079 | ||
|
|
9f724a22f3 | ||
|
|
c39fdd5cad | ||
|
|
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 | ||
|
|
4e6c9e0410 | ||
|
|
88656d9497 | ||
|
|
fe0eba8175 | ||
|
|
24b85a379b | ||
|
|
ec99ad86dd | ||
|
|
ee9ef9ef3c | ||
|
|
f6966bc35b | ||
|
|
45efb97ebd | ||
|
|
110062aef6 | ||
|
|
de24dd76a6 | ||
|
|
e09654f0ed | ||
|
|
86fe59eacc | ||
|
|
2809056303 | ||
|
|
f8d3569b56 | ||
|
|
5f1aba027a | ||
|
|
a85d2c508b | ||
|
|
34f700b584 | ||
|
|
5137d733f9 | ||
|
|
5478d68b2a | ||
|
|
6e8e051464 | ||
|
|
80355d96c5 | ||
|
|
e4d3ca388b | ||
|
|
426336f4e6 | ||
|
|
af1366fcde | ||
|
|
96695361e4 | ||
|
|
cc7adcd328 | ||
|
|
2a1c974412 | ||
|
|
b00db5738c | ||
|
|
c0ce1c85ed | ||
|
|
64f6535c65 | ||
|
|
a4d5210d18 | ||
|
|
7857739408 | ||
|
|
05f41a4926 | ||
|
|
a6bebcaafc | ||
|
|
a68a6bd01d | ||
|
|
455227676a | ||
|
|
834b8d85d7 | ||
|
|
f81ba655b2 | ||
|
|
8cf62085ee | ||
|
|
9ed9f37ada | ||
|
|
ecca15537d | ||
|
|
0aa2e6fe6c | ||
|
|
c84465ba47 | ||
|
|
5d2d870837 | ||
|
|
46baaa36df | ||
|
|
ecb32ede6a | ||
|
|
c752834a02 |
14
ChangeLog
Executable file → Normal file
14
ChangeLog
Executable file → Normal file
@@ -1,2 +1,16 @@
|
||||
libpri 0.3.0
|
||||
-- Fix talking to switch
|
||||
-- Add pri dump
|
||||
-- Add test application
|
||||
-- Fix strncpy stuff
|
||||
libpri 0.1.2
|
||||
-- Added PRI_EVENT_HANGUP_ACK so you can know when the disconnect was
|
||||
acknowledged
|
||||
|
||||
libpri 0.1.1
|
||||
-- Added PRI_DEBUG_Q931_ANOMALY flag so that certain non-error-related
|
||||
messages would not be output unless specifically desired.
|
||||
|
||||
libpri 0.1.0
|
||||
-- Initial release
|
||||
|
||||
|
||||
82
Makefile
Executable file → Normal file
82
Makefile
Executable file → Normal file
@@ -20,24 +20,77 @@
|
||||
# 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
|
||||
|
||||
OSARCH=$(shell uname -s)
|
||||
PROC=$(shell uname -m)
|
||||
|
||||
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=
|
||||
ifeq (${OSARCH},Linux)
|
||||
LDCONFIG_FLAGS=-n
|
||||
else
|
||||
ifeq (${OSARCH},FreeBSD)
|
||||
LDCONFIG_FLAGS=-m
|
||||
CFLAGS += -I../zaptel -I../zapata
|
||||
endif
|
||||
endif
|
||||
|
||||
all: $(STATIC_LIBRARY) $(DYNAMIC_LIBRARY)
|
||||
#The problem with sparc is the best stuff is in newer versions of gcc (post 3.0) only.
|
||||
#This works for even old (2.96) versions of gcc and provides a small boost either way.
|
||||
#A ultrasparc cpu is really v9 but the stock debian stable 3.0 gcc doesnt support it.
|
||||
ifeq ($(PROC),sparc64)
|
||||
PROC=ultrasparc
|
||||
CFLAGS += -mtune=$(PROC) -O3 -pipe -fomit-frame-pointer -mcpu=v8
|
||||
endif
|
||||
|
||||
all: depend $(STATIC_LIBRARY) $(DYNAMIC_LIBRARY)
|
||||
|
||||
update:
|
||||
@echo "Updating from CVS"
|
||||
@cvs update -d
|
||||
|
||||
install: $(STATIC_LIBRARY) $(DYNAMIC_LIBRARY)
|
||||
mkdir -p /usr/lib
|
||||
mkdir -p /usr/include
|
||||
install -m 644 libpri.h /usr/include
|
||||
install -m 755 $(DYNAMIC_LIBRARY) /usr/lib
|
||||
( cd /usr/lib ; ln -sf libpri.so.1 libpri.so )
|
||||
install -m 644 $(STATIC_LIBRARY) /usr/lib
|
||||
mkdir -p $(INSTALL_PREFIX)/usr/lib
|
||||
mkdir -p $(INSTALL_PREFIX)/usr/include
|
||||
install -m 644 libpri.h $(INSTALL_PREFIX)/usr/include
|
||||
install -m 755 $(DYNAMIC_LIBRARY) $(INSTALL_PREFIX)/usr/lib
|
||||
( cd $(INSTALL_PREFIX)/usr/lib ; ln -sf libpri.so.1 libpri.so )
|
||||
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 $(CFLAGS)
|
||||
|
||||
testprilib.o: testprilib.c
|
||||
$(CC) $(CFLAGS) -D_REENTRANT -D_GNU_SOURCE -o $@ -c $<
|
||||
|
||||
testprilib: testprilib.o
|
||||
$(CC) -o testprilib testprilib.o -L. -lpri -lpthread $(CFLAGS)
|
||||
|
||||
pridump: pridump.o
|
||||
$(CC) -o pridump pridump.o -L. -lpri -lzap $(CFLAGS)
|
||||
|
||||
include .depend
|
||||
|
||||
%.lo : %.c
|
||||
$(CC) -fPIC $(CFLAGS) -o $@ -c $<
|
||||
|
||||
@@ -47,9 +100,16 @@ $(STATIC_LIBRARY): $(STATIC_OBJS)
|
||||
|
||||
$(DYNAMIC_LIBRARY): $(DYNAMIC_OBJS)
|
||||
$(CC) -shared -Wl,-soname,libpri.so.1 -o $@ $(DYNAMIC_OBJS)
|
||||
/sbin/ldconfig -n .
|
||||
/sbin/ldconfig $(LDCONFIG_FLAGS) .
|
||||
ln -sf libpri.so.1 libpri.so
|
||||
|
||||
clean:
|
||||
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`
|
||||
|
||||
283
libpri.h
Executable file → Normal file
283
libpri.h
Executable file → Normal file
@@ -22,8 +22,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _PRI_H
|
||||
#define _PRI_H
|
||||
#ifndef _LIBPRI_H
|
||||
#define _LIBPRI_H
|
||||
|
||||
/* Node types */
|
||||
#define PRI_NETWORK 1
|
||||
@@ -36,30 +36,74 @@
|
||||
#define PRI_DEBUG_CONFIG (1 << 3) /* Display error events on stdout */
|
||||
#define PRI_DEBUG_Q931_DUMP (1 << 5) /* Show interpreted Q.931 frames */
|
||||
#define PRI_DEBUG_Q931_STATE (1 << 6) /* Debug Q.931 state machine changes */
|
||||
#define PRI_DEBUG_Q931_ANOMALY (1 << 7) /* Show unexpected events */
|
||||
|
||||
#define PRI_DEBUG_ALL (0xffff) /* Everything */
|
||||
|
||||
/* Switch types */
|
||||
#define PRI_SWITCH_UNKNOWN 0
|
||||
#define PRI_SWITCH_NI2 1 /* National ISDN 2 */
|
||||
#define PRI_SWITCH_DMS100 2 /* DMS 100 */
|
||||
#define PRI_SWITCH_LUCENT5E 3 /* Lucent 5E */
|
||||
#define PRI_SWITCH_ATT4ESS 4 /* AT&T 4ESS */
|
||||
#define PRI_SWITCH_UNKNOWN 0
|
||||
#define PRI_SWITCH_NI2 1 /* National ISDN 2 */
|
||||
#define PRI_SWITCH_DMS100 2 /* DMS 100 */
|
||||
#define PRI_SWITCH_LUCENT5E 3 /* Lucent 5E */
|
||||
#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 */
|
||||
#define PRI_SWITCH_GR303_EOC 8 /* GR-303 Embedded Operations Channel */
|
||||
#define PRI_SWITCH_GR303_TMC 9 /* GR-303 Timeslot Management Channel */
|
||||
/* Switchtypes 10 - 20 are reserved for internal use */
|
||||
|
||||
|
||||
/* PRI D-Channel Events */
|
||||
#define PRI_EVENT_DCHAN_UP 1 /* D-channel is up */
|
||||
#define PRI_EVENT_DCHAN_DOWN 2 /* D-channel is down */
|
||||
#define PRI_EVENT_RESTART 3 /* B-channel is restarted */
|
||||
#define PRI_EVENT_CONFIG_ERR 4 /* Configuration Error Detected */
|
||||
#define PRI_EVENT_RING 5 /* Incoming call */
|
||||
#define PRI_EVENT_HANGUP 6 /* Call got hung up */
|
||||
#define PRI_EVENT_RINGING 7 /* Call is ringing (alerting) */
|
||||
#define PRI_EVENT_ANSWER 8 /* Call has been answered */
|
||||
#define PRI_EVENT_DCHAN_UP 1 /* D-channel is up */
|
||||
#define PRI_EVENT_DCHAN_DOWN 2 /* D-channel is down */
|
||||
#define PRI_EVENT_RESTART 3 /* B-channel is restarted */
|
||||
#define PRI_EVENT_CONFIG_ERR 4 /* Configuration Error Detected */
|
||||
#define PRI_EVENT_RING 5 /* Incoming call */
|
||||
#define PRI_EVENT_HANGUP 6 /* Call got hung up */
|
||||
#define PRI_EVENT_RINGING 7 /* Call is ringing (alerting) */
|
||||
#define PRI_EVENT_ANSWER 8 /* Call has been answered */
|
||||
#define PRI_EVENT_HANGUP_ACK 9 /* Call hangup has been acknowledged */
|
||||
#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 */
|
||||
#define PRI_EVENT_NOTIFY 16 /* Notification received */
|
||||
#define PRI_EVENT_PROGRESS 17 /* When we get CALL_PROCEEDING or PROGRESS */
|
||||
|
||||
/* Simple states */
|
||||
#define PRI_STATE_DOWN 0
|
||||
#define PRI_STATE_UP 1
|
||||
|
||||
/* Numbering plan identifier */
|
||||
#define PRI_NPI_UNKNOWN 0x0
|
||||
#define PRI_NPI_E163_E164 0x1
|
||||
#define PRI_NPI_X121 0x3
|
||||
#define PRI_NPI_F69 0x4
|
||||
#define PRI_NPI_NATIONAL 0x8
|
||||
#define PRI_NPI_PRIVATE 0x9
|
||||
#define PRI_NPI_RESERVED 0xF
|
||||
|
||||
/* Type of number */
|
||||
#define PRI_TON_UNKNOWN 0x0
|
||||
#define PRI_TON_INTERNATIONAL 0x1
|
||||
#define PRI_TON_NATIONAL 0x2
|
||||
#define PRI_TON_NET_SPECIFIC 0x3
|
||||
#define PRI_TON_SUBSCRIBER 0x4
|
||||
#define PRI_TON_ABBREVIATED 0x6
|
||||
#define PRI_TON_RESERVED 0x7
|
||||
|
||||
/* Redirection reasons */
|
||||
#define PRI_REDIR_UNKNOWN 0x0
|
||||
#define PRI_REDIR_FORWARD_ON_BUSY 0x1
|
||||
#define PRI_REDIR_FORWARD_ON_NO_REPLY 0x2
|
||||
#define PRI_REDIR_DEFLECTION 0x3
|
||||
#define PRI_REDIR_DTE_OUT_OF_ORDER 0x9
|
||||
#define PRI_REDIR_FORWARDED_BY_DTE 0xA
|
||||
#define PRI_REDIR_UNCONDITIONAL 0xF
|
||||
|
||||
/* Dialing plan */
|
||||
#define PRI_INTERNATIONAL_ISDN 0x11
|
||||
#define PRI_NATIONAL_ISDN 0x21
|
||||
@@ -89,33 +133,103 @@
|
||||
#define PRI_CAUSE_NO_USER_RESPONSE 18
|
||||
#define PRI_CAUSE_NO_ANSWER 19
|
||||
#define PRI_CAUSE_CALL_REJECTED 21
|
||||
#define PRI_CAUSE_NUMBER_CHANGED 22
|
||||
#define PRI_CAUSE_DESTINATION_OUT_OF_ORDER 27
|
||||
#define PRI_CAUSE_INVALID_NUMBER_FORMAT 28
|
||||
#define PRI_CAUSE_FACILITY_REJECTED 29
|
||||
#define PRI_CAUSE_RESPONSE_TO_STATUS_ENQUIRY 30
|
||||
#define PRI_CAUSE_NORMAL_UNSPECIFIED 31
|
||||
#define PRI_CAUSE_NORMAL_CIRCUIT_CONGESTION 34
|
||||
#define PRI_CAUSE_NETWORK_OUT_OF_ORDER 38
|
||||
#define PRI_CAUSE_NORMAL_TEMPORARY_FAILURE 41
|
||||
#define PRI_CAUSE_SWITCH_CONGESTION 42
|
||||
#define PRI_CAUSE_ACCESS_INFO_DISCARDED 43
|
||||
#define PRI_CAUSE_REQUESTED_CHAN_UNAVAIL 44
|
||||
#define PRI_CAUSE_PRE_EMPTED 45
|
||||
#define PRI_CAUSE_FACILITY_NOT_SUBSCRIBED 50
|
||||
#define PRI_CAUSE_OUTGOING_CALL_BARRED 52
|
||||
#define PRI_CAUSE_INCOMING_CALL_BARRED 54
|
||||
#define PRI_CAUSE_BEARERCAPABILITY_NOTAUTH 57
|
||||
#define PRI_CAUSE_BEARERCAPABILITY_NOTAVAIL 58
|
||||
#define PRI_CAUSE_BEARERCAPABILITY_NOTIMPL 65
|
||||
#define PRI_CAUSE_CHAN_NOT_IMPLEMENTED 66
|
||||
#define PRI_CAUSE_FACILITY_NOT_IMPLEMENTED 69
|
||||
#define PRI_CAUSE_INVALID_CALL_REFERENCE 81
|
||||
#define PRI_CAUSE_INCOMPATIBLE_DESTINATION 88
|
||||
#define PRI_CAUSE_INVALID_MSG_UNSPECIFIED 95
|
||||
#define PRI_CAUSE_MANDATORY_IE_MISSING 96
|
||||
#define PRI_CAUSE_MESSAGE_TYPE_NONEXIST 97
|
||||
#define PRI_CAUSE_WRONG_MESSAGE 98
|
||||
#define PRI_CAUSE_IE_NONEXIST 99
|
||||
#define PRI_CAUSE_INVALID_IE_CONTENTS 100
|
||||
#define PRI_CAUSE_WRONG_CALL_STATE 101
|
||||
#define PRI_CAUSE_RECOVERY_ON_TIMER_EXPIRE 102
|
||||
#define PRI_CAUSE_MANDATORY_IE_LENGTH_ERROR 103
|
||||
#define PRI_CAUSE_PROTOCOL_ERROR 111
|
||||
#define PRI_CAUSE_INTERWORKING 127
|
||||
|
||||
/* Transmit capabilities */
|
||||
#define PRI_TRANS_CAP_SPEECH 0x0
|
||||
#define PRI_TRANS_CAP_DIGITAL 0x80
|
||||
#define PRI_TRANS_CAP_AUDIO 0x10
|
||||
#define PRI_TRANS_CAP_SPEECH 0x0
|
||||
#define PRI_TRANS_CAP_DIGITAL 0x08
|
||||
#define PRI_TRANS_CAP_RESTRICTED_DIGITAL 0x09
|
||||
#define PRI_TRANS_CAP_3_1K_AUDIO 0x10
|
||||
#define PRI_TRANS_CAP_7K_AUDIO 0x11
|
||||
#define PRI_TRANS_CAP_VIDEO 0x18
|
||||
|
||||
#define PRI_LAYER_1_ITU_RATE_ADAPT 0x21
|
||||
#define PRI_LAYER_1_ULAW 0x22
|
||||
#define PRI_LAYER_1_ALAW 0x23
|
||||
#define PRI_LAYER_1_G721 0x24
|
||||
#define PRI_LAYER_1_G722_G725 0x25
|
||||
#define PRI_LAYER_1_G7XX_384K 0x26
|
||||
#define PRI_LAYER_1_NON_ITU_ADAPT 0x27
|
||||
#define PRI_LAYER_1_V120_RATE_ADAPT 0x28
|
||||
#define PRI_LAYER_1_X31_RATE_ADAPT 0x29
|
||||
|
||||
/* Notifications */
|
||||
#define PRI_NOTIFY_USER_SUSPENDED 0x00 /* User suspended */
|
||||
#define PRI_NOTIFY_USER_RESUMED 0x01 /* User resumed */
|
||||
#define PRI_NOTIFY_BEARER_CHANGE 0x02 /* Bearer service change (DSS1) */
|
||||
#define PRI_NOTIFY_ASN1_COMPONENT 0x03 /* ASN.1 encoded component (DSS1) */
|
||||
#define PRI_NOTIFY_COMPLETION_DELAY 0x04 /* Call completion delay */
|
||||
#define PRI_NOTIFY_CONF_ESTABLISHED 0x42 /* Conference established */
|
||||
#define PRI_NOTIFY_CONF_DISCONNECTED 0x43 /* Conference disconnected */
|
||||
#define PRI_NOTIFY_CONF_PARTY_ADDED 0x44 /* Other party added */
|
||||
#define PRI_NOTIFY_CONF_ISOLATED 0x45 /* Isolated */
|
||||
#define PRI_NOTIFY_CONF_REATTACHED 0x46 /* Reattached */
|
||||
#define PRI_NOTIFY_CONF_OTHER_ISOLATED 0x47 /* Other party isolated */
|
||||
#define PRI_NOTIFY_CONF_OTHER_REATTACHED 0x48 /* Other party reattached */
|
||||
#define PRI_NOTIFY_CONF_OTHER_SPLIT 0x49 /* Other party split */
|
||||
#define PRI_NOTIFY_CONF_OTHER_DISCONNECTED 0x4a /* Other party disconnected */
|
||||
#define PRI_NOTIFY_CONF_FLOATING 0x4b /* Conference floating */
|
||||
#define PRI_NOTIFY_WAITING_CALL 0x60 /* Call is waiting call */
|
||||
#define PRI_NOTIFY_DIVERSION_ACTIVATED 0x68 /* Diversion activated (DSS1) */
|
||||
#define PRI_NOTIFY_TRANSFER_ALERTING 0x69 /* Call transfer, alerting */
|
||||
#define PRI_NOTIFY_TRANSFER_ACTIVE 0x6a /* Call transfer, active */
|
||||
#define PRI_NOTIFY_REMOTE_HOLD 0x79 /* Remote hold */
|
||||
#define PRI_NOTIFY_REMOTE_RETRIEVAL 0x7a /* Remote retrieval */
|
||||
#define PRI_NOTIFY_CALL_DIVERTING 0x7b /* Call is diverting */
|
||||
|
||||
#define PRI_COPY_DIGITS_CALLED_NUMBER
|
||||
|
||||
/* Network Specific Facilities (AT&T) */
|
||||
#define PRI_NSF_NONE -1
|
||||
#define PRI_NSF_SID_PREFERRED 0xB1
|
||||
#define PRI_NSF_ANI_PREFERRED 0xB2
|
||||
#define PRI_NSF_SID_ONLY 0xB3
|
||||
#define PRI_NSF_ANI_ONLY 0xB4
|
||||
#define PRI_NSF_CALL_ASSOC_TSC 0xB9
|
||||
#define PRI_NSF_NOTIF_CATSC_CLEARING 0xBA
|
||||
#define PRI_NSF_OPERATOR 0xB5
|
||||
#define PRI_NSF_PCCO 0xB6
|
||||
#define PRI_NSF_SDN 0xE1
|
||||
#define PRI_NSF_TOLL_FREE_MEGACOM 0xE2
|
||||
#define PRI_NSF_MEGACOM 0xE3
|
||||
#define PRI_NSF_ACCUNET 0xE6
|
||||
#define PRI_NSF_LONG_DISTANCE_SERVICE 0xE7
|
||||
#define PRI_NSF_INTERNATIONAL_TOLL_FREE 0xE8
|
||||
#define PRI_NSF_ATT_MULTIQUEST 0xF0
|
||||
#define PRI_NSF_CALL_REDIRECTION_SERVICE 0xF7
|
||||
|
||||
typedef struct q931_call q931_call;
|
||||
|
||||
@@ -148,18 +262,34 @@ typedef struct pri_event_answer {
|
||||
q931_call *call;
|
||||
} pri_event_answer;
|
||||
|
||||
typedef struct pri_event_facname {
|
||||
int e;
|
||||
char callingname[256];
|
||||
char callingnum[256];
|
||||
int channel;
|
||||
int cref;
|
||||
q931_call *call;
|
||||
} pri_event_facname;
|
||||
|
||||
typedef struct pri_event_ring {
|
||||
int e;
|
||||
int channel; /* Channel requested */
|
||||
int callingpres; /* Presentation of Calling CallerID */
|
||||
int callingplan; /* Dialing plan of Calling entity */
|
||||
char callingnum[256]; /* Calling number */
|
||||
char callingname[256]; /* Calling name (if provided) */
|
||||
int calledplan; /* Dialing plan of Called number */
|
||||
int ani2; /* ANI II */
|
||||
char callednum[256]; /* Called number */
|
||||
char redirectingnum[256]; /* Redirecting number */
|
||||
char useruserinfo[256]; /* User->User info */
|
||||
int flexible; /* Are we flexible with our channel selection? */
|
||||
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 */
|
||||
char callingsubaddr[256]; /* Calling parties subaddress */
|
||||
} pri_event_ring;
|
||||
|
||||
typedef struct pri_event_hangup {
|
||||
@@ -170,18 +300,45 @@ typedef struct pri_event_hangup {
|
||||
q931_call *call; /* Opaque call pointer */
|
||||
} pri_event_hangup;
|
||||
|
||||
typedef struct pri_event_restart_ack {
|
||||
int e;
|
||||
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 struct pri_event_notify {
|
||||
int e;
|
||||
int channel;
|
||||
int info;
|
||||
} pri_event_notify;
|
||||
|
||||
typedef union {
|
||||
int e;
|
||||
pri_event_generic gen; /* Generic view */
|
||||
pri_event_restart restart; /* Restart view */
|
||||
pri_event_error err; /* Error view */
|
||||
pri_event_facname facname; /* Caller*ID Name on Facility */
|
||||
pri_event_ring ring; /* Ring */
|
||||
pri_event_hangup hangup; /* Hang up */
|
||||
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_notify notify; /* Notification */
|
||||
} pri_event;
|
||||
|
||||
struct pri;
|
||||
struct pri_sr;
|
||||
|
||||
|
||||
/* Create a D-channel on a given file descriptor. The file descriptor must be a
|
||||
@@ -190,6 +347,9 @@ struct pri;
|
||||
must be one of PRI_NETWORK or PRI_CPE. switchtype should be PRI_SWITCH_* */
|
||||
extern struct pri *pri_new(int fd, int nodetype, int switchtype);
|
||||
|
||||
/* Set Network Specific Facility for PRI */
|
||||
extern void pri_set_nsf(struct pri *pri, int nsf);
|
||||
|
||||
/* Set debug parameters on PRI -- see above debug definitions */
|
||||
extern void pri_set_debug(struct pri *pri, int debug);
|
||||
|
||||
@@ -229,26 +389,99 @@ extern char *pri_cause2str(int cause);
|
||||
is in-band data available on the channel */
|
||||
extern int pri_acknowledge(struct pri *pri, q931_call *call, int channel, int info);
|
||||
|
||||
/* Send a digit in overlap mode */
|
||||
extern int pri_information(struct pri *pri, q931_call *call, char digit);
|
||||
|
||||
/* Answer the incomplete(call without called number) call on the given channel.
|
||||
Set non-isdn to non-zero if you are not connecting to ISDN equipment */
|
||||
extern int pri_need_more_info(struct pri *pri, q931_call *call, int channel, int nonisdn);
|
||||
|
||||
/* Answer the call on the given channel (ignored if you called acknowledge already).
|
||||
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);
|
||||
|
||||
/* Release/Reject a call */
|
||||
extern int pri_release(struct pri *pri, q931_call *call, int cause);
|
||||
/* Set CRV reference for GR-303 calls */
|
||||
|
||||
/* Hangup / Disconnect a call */
|
||||
extern int pri_disconnect(struct pri *pri, q931_call *call, int cause);
|
||||
|
||||
#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);
|
||||
|
||||
/* Create a new call */
|
||||
extern q931_call *pri_new_call(struct pri *pri);
|
||||
|
||||
/* Retrieve CRV reference for GR-303 calls. Returns >0 on success. */
|
||||
extern int pri_get_crv(struct pri *pri, q931_call *call, int *callmode);
|
||||
|
||||
/* Retrieve CRV reference for GR-303 calls. CRV must be >0, call mode should be 0 */
|
||||
extern int pri_set_crv(struct pri *pri, q931_call *call, int crv, int callmode);
|
||||
|
||||
/* How long until you need to poll for a new event */
|
||||
extern struct timeval *pri_schedule_next(struct pri *pri);
|
||||
|
||||
/* Run any pending schedule events */
|
||||
extern int pri_schedule_run(struct pri *pri);
|
||||
extern pri_event *pri_schedule_run(struct pri *pri);
|
||||
|
||||
extern int pri_call(struct pri *pri, q931_call *c, int transmode, int channel,
|
||||
int exclusive, int nonisdn, char *caller, int callerplan, int callerpres,
|
||||
char *called,int calledplan);
|
||||
int exclusive, int nonisdn, char *caller, int callerplan, char *callername, int callerpres,
|
||||
char *called,int calledplan, int ulayer1);
|
||||
|
||||
extern struct pri_sr *pri_sr_new(void);
|
||||
extern void pri_sr_free(struct pri_sr *sr);
|
||||
|
||||
extern int pri_sr_set_channel(struct pri_sr *sr, int channel, int exclusive, int nonisdn);
|
||||
extern int pri_sr_set_bearer(struct pri_sr *sr, int transmode, int userl1);
|
||||
extern int pri_sr_set_called(struct pri_sr *sr, char *called, int calledplan, int complete);
|
||||
extern int pri_sr_set_caller(struct pri_sr *sr, char *caller, char *callername, int callerplan, int callerpres);
|
||||
|
||||
extern int pri_setup(struct pri *pri, q931_call *call, struct pri_sr *req);
|
||||
|
||||
/* Override message and error stuff */
|
||||
extern void pri_set_message(void (*__pri_error)(char *));
|
||||
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);
|
||||
|
||||
#define PRI_PROGRESS
|
||||
/* Send call proceeding */
|
||||
extern int pri_progress(struct pri *pri, q931_call *c, int channel, int info);
|
||||
|
||||
#define PRI_PROCEEDING_FULL
|
||||
/* Send call proceeding */
|
||||
extern int pri_proceeding(struct pri *pri, q931_call *c, int channel, int info);
|
||||
|
||||
/* Enslave a PRI to another, so they share the same call list
|
||||
(and maybe some timers) */
|
||||
extern void pri_enslave(struct pri *master, struct pri *slave);
|
||||
|
||||
#define PRI_GR303_SUPPORT
|
||||
#define PRI_ENSLAVE_SUPPORT
|
||||
#define PRI_SETUP_CALL
|
||||
#define PRI_RECEIVE_SUBADDR
|
||||
#endif
|
||||
|
||||
/* Send notification */
|
||||
extern int pri_notify(struct pri *pri, q931_call *c, int channel, int info);
|
||||
|
||||
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 "$@" 2>/dev/null | sed -e 's; \./; ;g' > $TMP
|
||||
else
|
||||
${CC:-cc} -M "$@" 2>/dev/null | 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
|
||||
349
pri.c
Executable file → Normal file
349
pri.c
Executable file → Normal file
@@ -18,6 +18,7 @@
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/select.h>
|
||||
#include <stdarg.h>
|
||||
#include "libpri.h"
|
||||
#include "pri_internal.h"
|
||||
#include "pri_q921.h"
|
||||
@@ -48,12 +49,20 @@ 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";
|
||||
case PRI_SWITCH_GR303_EOC:
|
||||
return "GR303 EOC";
|
||||
case PRI_SWITCH_GR303_TMC:
|
||||
return "GR303 TMC";
|
||||
default:
|
||||
return "Unknown switchtype";
|
||||
}
|
||||
}
|
||||
|
||||
struct pri *pri_new(int fd, int node, int switchtype)
|
||||
static struct pri *__pri_new(int fd, int node, int switchtype, struct pri *master)
|
||||
{
|
||||
struct pri *p;
|
||||
p = malloc(sizeof(struct pri));
|
||||
@@ -63,12 +72,63 @@ 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);
|
||||
p->sapi = Q921_SAPI_CALL_CTRL;
|
||||
p->tei = 0;
|
||||
p->nsf = PRI_NSF_NONE;
|
||||
p->protodisc = Q931_PROTOCOL_DISCRIMINATOR;
|
||||
p->master = master;
|
||||
p->callpool = &p->localpool;
|
||||
#ifdef LIBPRI_COUNTERS
|
||||
p->q921_rxcount = 0;
|
||||
p->q921_txcount = 0;
|
||||
p->q931_rxcount = 0;
|
||||
p->q931_txcount = 0;
|
||||
#endif
|
||||
if (switchtype == PRI_SWITCH_GR303_EOC) {
|
||||
p->protodisc = GR303_PROTOCOL_DISCRIMINATOR;
|
||||
p->sapi = Q921_SAPI_GR303_EOC;
|
||||
p->tei = Q921_TEI_GR303_EOC_OPS;
|
||||
p->subchannel = __pri_new(-1, node, PRI_SWITCH_GR303_EOC_PATH, p);
|
||||
if (!p->subchannel) {
|
||||
free(p);
|
||||
p = NULL;
|
||||
}
|
||||
} else if (switchtype == PRI_SWITCH_GR303_TMC) {
|
||||
p->protodisc = GR303_PROTOCOL_DISCRIMINATOR;
|
||||
p->sapi = Q921_SAPI_GR303_TMC_CALLPROC;
|
||||
p->tei = Q921_TEI_GR303_TMC_CALLPROC;
|
||||
p->subchannel = __pri_new(-1, node, PRI_SWITCH_GR303_TMC_SWITCHING, p);
|
||||
if (!p->subchannel) {
|
||||
free(p);
|
||||
p = NULL;
|
||||
}
|
||||
} else if (switchtype == PRI_SWITCH_GR303_TMC_SWITCHING) {
|
||||
p->protodisc = GR303_PROTOCOL_DISCRIMINATOR;
|
||||
p->sapi = Q921_SAPI_GR303_TMC_SWITCHING;
|
||||
p->tei = Q921_TEI_GR303_TMC_SWITCHING;
|
||||
} else if (switchtype == PRI_SWITCH_GR303_EOC_PATH) {
|
||||
p->protodisc = GR303_PROTOCOL_DISCRIMINATOR;
|
||||
p->sapi = Q921_SAPI_GR303_EOC;
|
||||
p->tei = Q921_TEI_GR303_EOC_PATH;
|
||||
}
|
||||
/* Start Q.921 layer, Wait if we're the network */
|
||||
if (p)
|
||||
q921_start(p, p->localtype == PRI_CPE);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
struct pri *pri_new(int fd, int node, int switchtype)
|
||||
{
|
||||
return __pri_new(fd, node, switchtype, NULL);
|
||||
}
|
||||
|
||||
void pri_set_nsf(struct pri *pri, int nsf)
|
||||
{
|
||||
if (pri)
|
||||
pri->nsf = nsf;
|
||||
}
|
||||
|
||||
char *pri_event2str(int id)
|
||||
{
|
||||
switch(id) {
|
||||
@@ -95,9 +155,11 @@ pri_event *pri_check_event(struct pri *pri)
|
||||
res = read(pri->fd, buf, sizeof(buf));
|
||||
if (res < 0) {
|
||||
if (errno != EAGAIN)
|
||||
fprintf(stderr, "Read on %d failed: %s\n", pri->fd, strerror(errno));
|
||||
pri_error("Read on %d failed: %s\n", pri->fd, strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
if (!res)
|
||||
return NULL;
|
||||
/* Receive the q921 packet */
|
||||
e = q921_receive(pri, (q921_h *)buf, res);
|
||||
return e;
|
||||
@@ -105,13 +167,26 @@ pri_event *pri_check_event(struct pri *pri)
|
||||
|
||||
static int wait_pri(struct pri *pri)
|
||||
{
|
||||
struct timeval *tv;
|
||||
struct timeval *tv, real;
|
||||
fd_set fds;
|
||||
int res;
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(pri->fd, &fds);
|
||||
tv = pri_schedule_next(pri);
|
||||
res = select(pri->fd + 1, &fds, NULL, NULL, tv);
|
||||
if (tv) {
|
||||
gettimeofday(&real, NULL);
|
||||
real.tv_sec = tv->tv_sec - real.tv_sec;
|
||||
real.tv_usec = tv->tv_usec - real.tv_usec;
|
||||
if (real.tv_usec < 0) {
|
||||
real.tv_usec += 1000000;
|
||||
real.tv_sec -= 1;
|
||||
}
|
||||
if (real.tv_sec < 0) {
|
||||
real.tv_sec = 0;
|
||||
real.tv_usec = 0;
|
||||
}
|
||||
}
|
||||
res = select(pri->fd + 1, &fds, NULL, NULL, tv ? &real : tv);
|
||||
if (res < 0)
|
||||
return -1;
|
||||
return res;
|
||||
@@ -121,7 +196,7 @@ pri_event *pri_mkerror(struct pri *pri, char *errstr)
|
||||
{
|
||||
/* Return a configuration error */
|
||||
pri->ev.err.e = PRI_EVENT_CONFIG_ERR;
|
||||
strncpy(pri->ev.err.err, errstr, sizeof(pri->ev.err.err));
|
||||
strncpy(pri->ev.err.err, errstr, sizeof(pri->ev.err.err) - 1);
|
||||
return &pri->ev;
|
||||
}
|
||||
|
||||
@@ -140,7 +215,7 @@ pri_event *pri_dchannel_run(struct pri *pri, int block)
|
||||
if (res < 0)
|
||||
return NULL;
|
||||
if (!res)
|
||||
pri_schedule_run(pri);
|
||||
e = pri_schedule_run(pri);
|
||||
else
|
||||
e = pri_check_event(pri);
|
||||
} while(!e);
|
||||
@@ -156,6 +231,8 @@ void pri_set_debug(struct pri *pri, int debug)
|
||||
if (!pri)
|
||||
return;
|
||||
pri->debug = debug;
|
||||
if (pri->subchannel)
|
||||
pri_set_debug(pri->subchannel, debug);
|
||||
}
|
||||
|
||||
int pri_acknowledge(struct pri *pri, q931_call *call, int channel, int info)
|
||||
@@ -165,6 +242,48 @@ int pri_acknowledge(struct pri *pri, q931_call *call, int channel, int info)
|
||||
return q931_alerting(pri, call, channel, info);
|
||||
}
|
||||
|
||||
int pri_proceeding(struct pri *pri, q931_call *call, int channel, int info)
|
||||
{
|
||||
if (!pri || !call)
|
||||
return -1;
|
||||
return q931_call_proceeding(pri, call, channel, info);
|
||||
}
|
||||
|
||||
int pri_progress(struct pri *pri, q931_call *call, int channel, int info)
|
||||
{
|
||||
if (!pri || !call)
|
||||
return -1;
|
||||
return q931_call_progress(pri, call, channel, info);
|
||||
}
|
||||
|
||||
int pri_information(struct pri *pri, q931_call *call, char digit)
|
||||
{
|
||||
if (!pri || !call)
|
||||
return -1;
|
||||
return q931_information(pri, call, digit);
|
||||
}
|
||||
|
||||
int pri_notify(struct pri *pri, q931_call *call, int channel, int info)
|
||||
{
|
||||
if (!pri || !call)
|
||||
return -1;
|
||||
return q931_notify(pri, call, channel, info);
|
||||
}
|
||||
|
||||
void pri_destroycall(struct pri *pri, q931_call *call)
|
||||
{
|
||||
if (pri && call)
|
||||
__q931_destroycall(pri, call);
|
||||
return;
|
||||
}
|
||||
|
||||
int pri_need_more_info(struct pri *pri, q931_call *call, int channel, int nonisdn)
|
||||
{
|
||||
if (!pri || !call)
|
||||
return -1;
|
||||
return q931_setup_ack(pri, call, channel, nonisdn);
|
||||
}
|
||||
|
||||
int pri_answer(struct pri *pri, q931_call *call, int channel, int nonisdn)
|
||||
{
|
||||
if (!pri || !call)
|
||||
@@ -172,6 +291,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)
|
||||
@@ -185,6 +306,24 @@ 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)
|
||||
{
|
||||
if (!pri)
|
||||
return -1;
|
||||
return q931_restart(pri, channel);
|
||||
}
|
||||
|
||||
q931_call *pri_new_call(struct pri *pri)
|
||||
{
|
||||
@@ -197,34 +336,204 @@ void pri_dump_event(struct pri *pri, pri_event *e)
|
||||
{
|
||||
if (!pri || !e)
|
||||
return;
|
||||
printf("Event type: %s (%d)\n", pri_event2str(e->gen.e), e->gen.e);
|
||||
pri_message("Event type: %s (%d)\n", pri_event2str(e->gen.e), e->gen.e);
|
||||
switch(e->gen.e) {
|
||||
case PRI_EVENT_DCHAN_UP:
|
||||
case PRI_EVENT_DCHAN_DOWN:
|
||||
break;
|
||||
case PRI_EVENT_CONFIG_ERR:
|
||||
printf("Error: %s", e->err.err);
|
||||
pri_message("Error: %s", e->err.err);
|
||||
break;
|
||||
case PRI_EVENT_RESTART:
|
||||
printf("Restart on channel %d\n", e->restart.channel);
|
||||
pri_message("Restart on channel %d\n", e->restart.channel);
|
||||
case PRI_EVENT_RING:
|
||||
printf("Calling number: %s (%s, %s)\n", e->ring.callingnum, pri_plan2str(e->ring.callingplan), pri_pres2str(e->ring.callingpres));
|
||||
printf("Called number: %s (%s)\n", e->ring.callednum, pri_plan2str(e->ring.calledplan));
|
||||
printf("Channel: %d (%s) Reference number: %d\n", e->ring.channel, e->ring.flexible ? "Flexible" : "Not Flexible", e->ring.cref);
|
||||
pri_message("Calling number: %s (%s, %s)\n", e->ring.callingnum, pri_plan2str(e->ring.callingplan), pri_pres2str(e->ring.callingpres));
|
||||
pri_message("Called number: %s (%s)\n", e->ring.callednum, pri_plan2str(e->ring.calledplan));
|
||||
pri_message("Channel: %d (%s) Reference number: %d\n", e->ring.channel, e->ring.flexible ? "Flexible" : "Not Flexible", e->ring.cref);
|
||||
break;
|
||||
case PRI_EVENT_HANGUP:
|
||||
printf("Hangup, reference number: %d, reason: %s\n", e->hangup.cref, pri_cause2str(e->hangup.cause));
|
||||
pri_message("Hangup, reference number: %d, reason: %s\n", e->hangup.cref, pri_cause2str(e->hangup.cause));
|
||||
break;
|
||||
default:
|
||||
printf("Don't know how to dump events of type %d\n", e->gen.e);
|
||||
pri_message("Don't know how to dump events of type %d\n", e->gen.e);
|
||||
}
|
||||
}
|
||||
|
||||
int pri_call(struct pri *pri, q931_call *c, int transmode, int channel, int exclusive,
|
||||
int nonisdn, char *caller, int callerplan, int callerpres, char *called,
|
||||
int calledplan)
|
||||
static void pri_sr_init(struct pri_sr *req)
|
||||
{
|
||||
memset(req, 0, sizeof(struct pri_sr));
|
||||
|
||||
}
|
||||
|
||||
int pri_setup(struct pri *pri, q931_call *c, struct pri_sr *req)
|
||||
{
|
||||
if (!pri || !c)
|
||||
return -1;
|
||||
return q931_setup(pri, c, transmode, channel, exclusive, nonisdn, caller, callerplan, callerpres, called, calledplan);
|
||||
return q931_setup(pri, c, req);
|
||||
}
|
||||
|
||||
int pri_call(struct pri *pri, q931_call *c, int transmode, int channel, int exclusive,
|
||||
int nonisdn, char *caller, int callerplan, char *callername, int callerpres, char *called,
|
||||
int calledplan,int ulayer1)
|
||||
{
|
||||
struct pri_sr req;
|
||||
if (!pri || !c)
|
||||
return -1;
|
||||
pri_sr_init(&req);
|
||||
req.transmode = transmode;
|
||||
req.channel = channel;
|
||||
req.exclusive = exclusive;
|
||||
req.nonisdn = nonisdn;
|
||||
req.caller = caller;
|
||||
req.callerplan = callerplan;
|
||||
req.callername = callername;
|
||||
req.callerpres = callerpres;
|
||||
req.called = called;
|
||||
req.calledplan = calledplan;
|
||||
req.userl1 = ulayer1;
|
||||
return q931_setup(pri, c, &req);
|
||||
}
|
||||
|
||||
static void (*__pri_error)(char *stuff);
|
||||
static void (*__pri_message)(char *stuff);
|
||||
|
||||
void pri_set_message(void (*func)(char *stuff))
|
||||
{
|
||||
__pri_message = func;
|
||||
}
|
||||
|
||||
void pri_set_error(void (*func)(char *stuff))
|
||||
{
|
||||
__pri_error = func;
|
||||
}
|
||||
|
||||
void pri_message(char *fmt, ...)
|
||||
{
|
||||
char tmp[1024];
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(tmp, sizeof(tmp), fmt, ap);
|
||||
va_end(ap);
|
||||
if (__pri_message)
|
||||
__pri_message(tmp);
|
||||
else
|
||||
fprintf(stdout, tmp);
|
||||
}
|
||||
|
||||
void pri_error(char *fmt, ...)
|
||||
{
|
||||
char tmp[1024];
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(tmp, sizeof(tmp), fmt, ap);
|
||||
va_end(ap);
|
||||
if (__pri_error)
|
||||
__pri_error(tmp);
|
||||
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);
|
||||
}
|
||||
|
||||
int pri_get_crv(struct pri *pri, q931_call *call, int *callmode)
|
||||
{
|
||||
return q931_call_getcrv(pri, call, callmode);
|
||||
}
|
||||
|
||||
int pri_set_crv(struct pri *pri, q931_call *call, int crv, int callmode)
|
||||
{
|
||||
return q931_call_setcrv(pri, call, crv, callmode);
|
||||
}
|
||||
|
||||
void pri_enslave(struct pri *master, struct pri *slave)
|
||||
{
|
||||
if (master && slave)
|
||||
slave->callpool = &master->localpool;
|
||||
}
|
||||
|
||||
struct pri_sr *pri_sr_new(void)
|
||||
{
|
||||
struct pri_sr *req;
|
||||
req = malloc(sizeof(struct pri_sr));
|
||||
if (req)
|
||||
pri_sr_init(req);
|
||||
return req;
|
||||
}
|
||||
|
||||
void pri_sr_free(struct pri_sr *sr)
|
||||
{
|
||||
free(sr);
|
||||
}
|
||||
|
||||
int pri_sr_set_channel(struct pri_sr *sr, int channel, int exclusive, int nonisdn)
|
||||
{
|
||||
sr->channel = channel;
|
||||
sr->exclusive = exclusive;
|
||||
sr->nonisdn = nonisdn;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pri_sr_set_bearer(struct pri_sr *sr, int transmode, int userl1)
|
||||
{
|
||||
sr->transmode = transmode;
|
||||
sr->userl1 = userl1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pri_sr_set_called(struct pri_sr *sr, char *called, int calledplan, int numcomplete)
|
||||
{
|
||||
sr->called = called;
|
||||
sr->calledplan = calledplan;
|
||||
sr->numcomplete = numcomplete;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pri_sr_set_caller(struct pri_sr *sr, char *caller, char *callername, int callerplan, int callerpres)
|
||||
{
|
||||
sr->caller = caller;
|
||||
sr->callername = callername;
|
||||
sr->callerplan = callerplan;
|
||||
sr->callerpres = callerpres;
|
||||
return 0;
|
||||
}
|
||||
|
||||
49
pri_internal.h
Executable file → Normal file
49
pri_internal.h
Executable file → Normal file
@@ -42,22 +42,31 @@ enum q931_mode;
|
||||
|
||||
struct pri {
|
||||
int fd; /* File descriptor for D-Channel */
|
||||
struct pri *subchannel; /* Sub-channel if appropriate */
|
||||
struct pri *master; /* Master channel if appropriate */
|
||||
struct pri_sched pri_sched[MAX_SCHED]; /* Scheduled events */
|
||||
int debug; /* Debug stuff */
|
||||
int state; /* State of D-channel */
|
||||
int switchtype; /* Switch type */
|
||||
int nsf; /* Network-Specific Facility (if any) */
|
||||
int localtype; /* Local network type (unknown, network, cpe) */
|
||||
int remotetype; /* Remote network type (unknown, network, cpe) */
|
||||
|
||||
int sapi;
|
||||
int tei;
|
||||
int protodisc;
|
||||
|
||||
/* Q.921 State */
|
||||
int q921_state;
|
||||
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 */
|
||||
|
||||
@@ -70,21 +79,57 @@ struct pri {
|
||||
|
||||
/* Used by scheduler */
|
||||
struct timeval tv;
|
||||
int schedev;
|
||||
pri_event ev; /* Static event thingy */
|
||||
|
||||
/* Q.921 Re-transmission queue */
|
||||
struct q921_frame *txqueue;
|
||||
|
||||
/* Q.931 calls */
|
||||
q931_call *calls;
|
||||
q931_call **callpool;
|
||||
q931_call *localpool;
|
||||
|
||||
/* 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
|
||||
};
|
||||
|
||||
struct pri_sr {
|
||||
int transmode;
|
||||
int channel;
|
||||
int exclusive;
|
||||
int nonisdn;
|
||||
char *caller;
|
||||
int callerplan;
|
||||
char *callername;
|
||||
int callerpres;
|
||||
char *called;
|
||||
int calledplan;
|
||||
int userl1;
|
||||
int numcomplete;
|
||||
};
|
||||
|
||||
/* Internal switch types */
|
||||
#define PRI_SWITCH_GR303_EOC_PATH 10
|
||||
#define PRI_SWITCH_GR303_TMC_SWITCHING 11
|
||||
|
||||
extern int pri_schedule_event(struct pri *pri, int ms, void (*function)(void *data), void *data);
|
||||
|
||||
extern int pri_schedule_run(struct pri *pri);
|
||||
extern pri_event *pri_schedule_run(struct pri *pri);
|
||||
|
||||
extern void pri_schedule_del(struct pri *pri, int ev);
|
||||
|
||||
extern pri_event *pri_mkerror(struct pri *pri, char *errstr);
|
||||
|
||||
extern void pri_message(char *fmt, ...);
|
||||
|
||||
extern void pri_error(char *fmt, ...);
|
||||
|
||||
#endif
|
||||
|
||||
26
pri_q921.h
Executable file → Normal file
26
pri_q921.h
Executable file → Normal file
@@ -26,7 +26,11 @@
|
||||
#define _PRI_Q921_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#if defined(__linux__)
|
||||
#include <endian.h>
|
||||
#elif defined(__FreeBSD__)
|
||||
#include <sys/endian.h>
|
||||
#endif
|
||||
|
||||
/* Timer values */
|
||||
|
||||
@@ -34,6 +38,7 @@
|
||||
#define T_WAIT_MAX 10000
|
||||
#define T_200 1000 /* 1 second between SABME's */
|
||||
#define T_203 10000 /* 10 seconds with no packets max */
|
||||
#define N_200 3 /* 3 retries */
|
||||
|
||||
#define Q921_FRAMETYPE_MASK 0x3
|
||||
|
||||
@@ -41,6 +46,22 @@
|
||||
#define Q921_FRAMETYPE_I 0x0
|
||||
#define Q921_FRAMETYPE_S 0x1
|
||||
|
||||
#define Q921_TEI_GROUP 127
|
||||
#define Q921_TEI_GR303_EOC_PATH 0
|
||||
#define Q921_TEI_GR303_EOC_OPS 4
|
||||
#define Q921_TEI_GR303_TMC_SWITCHING 0
|
||||
#define Q921_TEI_GR303_TMC_CALLPROC 0
|
||||
|
||||
#define Q921_SAPI_CALL_CTRL 0
|
||||
#define Q921_SAPI_GR303_EOC 1
|
||||
#define Q921_SAPI_GR303_TMC_SWITCHING 1
|
||||
#define Q921_SAPI_GR303_TMC_CALLPROC 0
|
||||
|
||||
|
||||
#define Q921_SAPI_PACKET_MODE 1
|
||||
#define Q921_SAPI_X25_LAYER3 16
|
||||
#define Q921_SAPI_LAYER2_MANAGEMENT 63
|
||||
|
||||
|
||||
typedef struct q921_header {
|
||||
#if __BYTE_ORDER == __BIG_ENDIAN
|
||||
@@ -126,10 +147,11 @@ 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;
|
||||
|
||||
#define Q921_INC(j) (j) = ((j) + 1) % 128
|
||||
#define Q921_INC(j) (j) = (((j) + 1) % 128)
|
||||
|
||||
typedef enum q921_state {
|
||||
Q921_LINK_CONNECTION_RELEASED, /* Also known as TEI_ASSIGNED */
|
||||
@@ -142,7 +164,7 @@ typedef enum q921_state {
|
||||
extern void q921_dump(q921_h *h, int len, int showraw, int txrx);
|
||||
|
||||
/* Bring up the D-channel */
|
||||
extern void q921_start(struct pri *pri);
|
||||
extern void q921_start(struct pri *pri, int now);
|
||||
|
||||
extern void q921_reset(struct pri *pri);
|
||||
|
||||
|
||||
114
pri_q931.h
Executable file → Normal file
114
pri_q931.h
Executable file → Normal file
@@ -98,13 +98,7 @@ typedef struct q931_mh {
|
||||
|
||||
/* Information element format */
|
||||
typedef struct q931_ie {
|
||||
#if __BYTE_ORDER == __BIG_ENDIAN
|
||||
u_int8_t f:1;
|
||||
u_int8_t ie:7;
|
||||
#else
|
||||
u_int8_t ie:7;
|
||||
u_int8_t f:1;
|
||||
#endif
|
||||
u_int8_t ie;
|
||||
u_int8_t len;
|
||||
u_int8_t data[0];
|
||||
} q931_ie;
|
||||
@@ -113,6 +107,7 @@ typedef struct q931_ie {
|
||||
#define Q931_RES_INERRROR (1 << 1)
|
||||
|
||||
#define Q931_PROTOCOL_DISCRIMINATOR 0x08
|
||||
#define GR303_PROTOCOL_DISCRIMINATOR 0x4f
|
||||
|
||||
/* Q.931 / National ISDN Message Types */
|
||||
|
||||
@@ -123,6 +118,7 @@ typedef struct q931_ie {
|
||||
#define Q931_CONNECT_ACKNOWLEDGE 0x0f
|
||||
#define Q931_PROGRESS 0x03
|
||||
#define Q931_SETUP 0x05
|
||||
#define Q931_SETUP_ACKNOWLEDGE 0x0d
|
||||
|
||||
/* Call Disestablishment Messages */
|
||||
#define Q931_DISCONNECT 0x45
|
||||
@@ -134,9 +130,29 @@ typedef struct q931_ie {
|
||||
/* Miscellaneous Messages */
|
||||
#define Q931_STATUS 0x7d
|
||||
#define Q931_STATUS_ENQUIRY 0x75
|
||||
#define Q931_USER_INFORMATION 0x20
|
||||
#define Q931_SEGMENT 0x60
|
||||
#define Q931_CONGESTION_CONTROL 0x79
|
||||
#define Q931_INFORMATION 0x7b
|
||||
#define Q931_FACILITY 0x62
|
||||
#define Q931_NOTIFY 0x6e
|
||||
|
||||
/* Call Management Messages */
|
||||
#define Q931_HOLD 0x24
|
||||
#define Q931_HOLD_ACKNOWLEDGE 0x28
|
||||
#define Q931_HOLD_REJECT 0x30
|
||||
#define Q931_RETRIEVE 0x31
|
||||
#define Q931_RETRIEVE_ACKNOWLEDGE 0x33
|
||||
#define Q931_RETRIEVE_REJECT 0x37
|
||||
#define Q931_RESUME 0x26
|
||||
#define Q931_RESUME_ACKNOWLEDGE 0x2e
|
||||
#define Q931_RESUME_REJECT 0x22
|
||||
#define Q931_SUSPEND 0x25
|
||||
#define Q931_SUSPEND_ACKNOWLEDGE 0x2d
|
||||
#define Q931_SUSPEND_REJECT 0x21
|
||||
|
||||
/* Maintenance messages (codeset 0 only) */
|
||||
#define NATIONAL_SERVICE 0x0f
|
||||
#define NATIONAL_SERVICE 0x0f
|
||||
#define NATIONAL_SERVICE_ACKNOWLEDGE 0x07
|
||||
|
||||
/* Special codeset 0 IE */
|
||||
@@ -144,6 +160,7 @@ typedef struct q931_ie {
|
||||
|
||||
/* Q.931 / National ISDN Information Elements */
|
||||
#define Q931_LOCKING_SHIFT 0x90
|
||||
#define Q931_NON_LOCKING_SHIFT 0x98
|
||||
#define Q931_BEARER_CAPABILITY 0x04
|
||||
#define Q931_CAUSE 0x08
|
||||
#define Q931_CALL_STATE 0x14
|
||||
@@ -169,11 +186,75 @@ typedef struct q931_ie {
|
||||
#define Q931_LOW_LAYER_COMPAT 0x7c
|
||||
#define Q931_HIGH_LAYER_COMPAT 0x7d
|
||||
|
||||
#define Q931_CODESET(x) ((x) << 8)
|
||||
#define Q931_IE_CODESET(x) ((x) >> 8)
|
||||
#define Q931_IE_IE(x) ((x) & 0xff)
|
||||
#define Q931_FULL_IE(codeset, ie) (((codeset) << 8) | ((ie) & 0xff))
|
||||
|
||||
#define Q931_DISPLAY 0x28
|
||||
#define Q931_IE_SEGMENTED_MSG 0x00
|
||||
#define Q931_IE_CHANGE_STATUS 0x01
|
||||
#define Q931_IE_ORIGINATING_LINE_INFO (0x01 | Q931_CODESET(6))
|
||||
#define Q931_IE_CONNECTED_ADDR 0x0C
|
||||
#define Q931_IE_CONNECTED_NUM 0x4C
|
||||
#define Q931_IE_CALL_IDENTITY 0x10
|
||||
#define Q931_IE_FACILITY 0x1c
|
||||
#define Q931_IE_ENDPOINT_ID 0x26
|
||||
#define Q931_IE_NOTIFY_IND 0x27
|
||||
#define Q931_IE_TIME_DATE 0x29
|
||||
#define Q931_IE_KEYPAD_FACILITY 0x2c
|
||||
#define Q931_IE_CALL_STATUS 0x2d
|
||||
#define Q931_IE_UPDATE 0x31
|
||||
#define Q931_IE_INFO_REQUEST 0x32
|
||||
#define Q931_IE_SIGNAL 0x34
|
||||
#define Q931_IE_SWITCHHOOK 0x36
|
||||
#define Q931_IE_FEATURE_ACTIVATE 0x38
|
||||
#define Q931_IE_FEATURE_IND 0x39
|
||||
#define Q931_IE_ORIGINAL_CALLED_NUMBER 0x73
|
||||
#define Q931_IE_REDIRECTION_NUMBER 0x76
|
||||
#define Q931_IE_REDIRECTION_SUBADDR 0x77
|
||||
#define Q931_IE_USER_USER_FACILITY 0x7A
|
||||
#define Q931_IE_USER_USER 0x7E
|
||||
#define Q931_IE_ESCAPE_FOR_EXT 0x7F
|
||||
|
||||
|
||||
/* Call state stuff */
|
||||
#define Q931_CALL_STATE_NULL 0
|
||||
#define Q931_CALL_STATE_CALL_INITIATED 1
|
||||
#define Q931_CALL_STATE_OVERLAP_SENDING 2
|
||||
#define Q931_CALL_STATE_OUTGOING_CALL_PROCEEDING 3
|
||||
#define Q931_CALL_STATE_CALL_DELIVERED 4
|
||||
#define Q931_CALL_STATE_CALL_PRESENT 6
|
||||
#define Q931_CALL_STATE_CALL_RECEIVED 7
|
||||
#define Q931_CALL_STATE_CONNECT_REQUEST 8
|
||||
#define Q931_CALL_STATE_INCOMING_CALL_PROCEEDING 9
|
||||
#define Q931_CALL_STATE_ACTIVE 10
|
||||
#define Q931_CALL_STATE_DISCONNECT_REQUEST 11
|
||||
#define Q931_CALL_STATE_DISCONNECT_INDICATION 12
|
||||
#define Q931_CALL_STATE_SUSPEND_REQUEST 15
|
||||
#define Q931_CALL_STATE_RESUME_REQUEST 17
|
||||
#define Q931_CALL_STATE_RELEASE_REQUEST 19
|
||||
#define Q931_CALL_STATE_OVERLAP_RECEIVING 25
|
||||
#define Q931_CALL_STATE_RESTART_REQUEST 61
|
||||
#define Q931_CALL_STATE_RESTART 62
|
||||
|
||||
|
||||
/* EuroISDN */
|
||||
#define Q931_SENDING_COMPLETE 0xa1
|
||||
|
||||
extern int q931_receive(struct pri *pri, q931_h *h, int len);
|
||||
|
||||
extern int q931_alerting(struct pri *pri, q931_call *call, int channel, int info);
|
||||
|
||||
extern int q931_call_proceeding(struct pri *pri, q931_call *call);
|
||||
extern int q931_call_progress(struct pri *pri, q931_call *call, int channel, int info);
|
||||
|
||||
extern int q931_notify(struct pri *pri, q931_call *call, int channel, int info);
|
||||
|
||||
extern int q931_call_proceeding(struct pri *pri, q931_call *call, int channel, int info);
|
||||
|
||||
extern int q931_setup_ack(struct pri *pri, q931_call *call, int channel, int nonisdn);
|
||||
|
||||
extern int q931_information(struct pri *pri, q931_call *call, char digit);
|
||||
|
||||
extern int q931_connect(struct pri *pri, q931_call *call, int channel, int nonisdn);
|
||||
|
||||
@@ -181,10 +262,19 @@ 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 int q931_call_getcrv(struct pri *pri, q931_call *call, int *callmode);
|
||||
|
||||
extern int q931_call_setcrv(struct pri *pri, q931_call *call, int crv, int callmode);
|
||||
|
||||
extern q931_call *q931_new_call(struct pri *pri);
|
||||
|
||||
extern int q931_setup(struct pri *pri, q931_call *c, int transmode, int channel, int exclusive,
|
||||
int nonisdn, char *caller, int callerplan, int callerpres, char *called,
|
||||
int calledplan);
|
||||
extern int q931_setup(struct pri *pri, q931_call *c, struct pri_sr *req);
|
||||
extern void q931_dump(q931_h *h, int len, int txrx);
|
||||
|
||||
extern void __q931_destroycall(struct pri *pri, q931_call *c);
|
||||
|
||||
#endif
|
||||
|
||||
135
pridump.c
Normal file
135
pridump.c
Normal file
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* 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 <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/types.h>
|
||||
#if defined(__linux__)
|
||||
#include <linux/zaptel.h>
|
||||
#elif defined(__FreeBSD__)
|
||||
#include <zaptel.h>
|
||||
#endif
|
||||
#include "libpri.h"
|
||||
#include "pri_q921.h"
|
||||
#include "pri_q931.h"
|
||||
|
||||
static int pri_open(char *dev)
|
||||
{
|
||||
int dfd;
|
||||
struct zt_params p;
|
||||
|
||||
dfd = open(dev, O_RDWR);
|
||||
if (dfd < 0) {
|
||||
fprintf(stderr, "Failed to open dchannel '%s': %s\n", dev, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if (ioctl(dfd, ZT_GET_PARAMS, &p)) {
|
||||
fprintf(stderr, "Unable to get parameters on '%s': %s\n", dev, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if ((p.sigtype != ZT_SIG_HDLCRAW) && (p.sigtype != ZT_SIG_HDLCFCS)) {
|
||||
fprintf(stderr, "%s is in %d signalling, not FCS HDLC or RAW HDLC mode\n", dev, p.sigtype);
|
||||
return -1;
|
||||
}
|
||||
return dfd;
|
||||
}
|
||||
|
||||
static void dump_packet(char *buf, int len, int txrx)
|
||||
{
|
||||
q921_h *h = (q921_h *)buf;
|
||||
q921_dump(h, len, 1, txrx);
|
||||
if (!((h->h.data[0] & Q921_FRAMETYPE_MASK) & 0x3)) {
|
||||
q931_dump((q931_h *)(h->i.data), len - 4, txrx);
|
||||
}
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
|
||||
static int pri_bridge(int d1, int d2)
|
||||
{
|
||||
char buf[1024];
|
||||
fd_set fds;
|
||||
int max;
|
||||
int e;
|
||||
int res;
|
||||
for(;;) {
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(d1, &fds);
|
||||
FD_SET(d2, &fds);
|
||||
max = d1;
|
||||
if (max < d2)
|
||||
max = d2;
|
||||
ioctl(d1, ZT_GETEVENT, &e);
|
||||
ioctl(d2, ZT_GETEVENT, &e);
|
||||
res = select(max + 1, &fds, NULL, NULL, NULL);
|
||||
if (res < 0) {
|
||||
fprintf(stderr, "Select returned %d: %s\n", res, strerror(errno));
|
||||
continue;
|
||||
};
|
||||
if (FD_ISSET(d1, &fds)) {
|
||||
/* Copy from d1 to d2 */
|
||||
res = read(d1, buf, sizeof(buf));
|
||||
dump_packet(buf, res, 1);
|
||||
res = write(d2, buf, res);
|
||||
}
|
||||
if (FD_ISSET(d2, &fds)) {
|
||||
/* Copy from d2 to d1 */
|
||||
res = read(d2, buf, sizeof(buf));
|
||||
dump_packet(buf, res, 0);
|
||||
res = write(d1, buf, res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int d1, d2;
|
||||
|
||||
if (argc < 3) {
|
||||
fprintf(stderr, "Usage: pridump <dev1> <dev2>\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
d1 = pri_open(argv[1]);
|
||||
if (d1 < 0)
|
||||
exit(1);
|
||||
d2 = pri_open(argv[2]);
|
||||
if (d2 < 0)
|
||||
exit(1);
|
||||
pri_bridge(d1, d2);
|
||||
return 0;
|
||||
}
|
||||
44
prisched.c
Executable file → Normal file
44
prisched.c
Executable file → Normal file
@@ -38,7 +38,7 @@ int pri_schedule_event(struct pri *pri, int ms, void (*function)(void *data), vo
|
||||
if (!pri->pri_sched[x].callback)
|
||||
break;
|
||||
if (x == MAX_SCHED) {
|
||||
fprintf(stderr, "No more room in scheduler\n");
|
||||
pri_error("No more room in scheduler\n");
|
||||
return -1;
|
||||
}
|
||||
if (x > maxsched)
|
||||
@@ -46,8 +46,10 @@ int pri_schedule_event(struct pri *pri, int ms, void (*function)(void *data), vo
|
||||
gettimeofday(&tv, NULL);
|
||||
tv.tv_sec += ms / 1000;
|
||||
tv.tv_usec += (ms % 1000) * 1000;
|
||||
if (tv.tv_usec > 1000000)
|
||||
if (tv.tv_usec > 1000000) {
|
||||
tv.tv_usec -= 1000000;
|
||||
tv.tv_sec += 1;
|
||||
}
|
||||
pri->pri_sched[x].when = tv;
|
||||
pri->pri_sched[x].callback = function;
|
||||
pri->pri_sched[x].data = data;
|
||||
@@ -58,6 +60,9 @@ struct timeval *pri_schedule_next(struct pri *pri)
|
||||
{
|
||||
struct timeval *closest = NULL;
|
||||
int x;
|
||||
/* Check subchannels */
|
||||
if (pri->subchannel)
|
||||
closest = pri_schedule_next(pri->subchannel);
|
||||
for (x=1;x<MAX_SCHED;x++) {
|
||||
if (pri->pri_sched[x].callback &&
|
||||
(!closest || (closest->tv_sec > pri->pri_sched[x].when.tv_sec) ||
|
||||
@@ -68,33 +73,46 @@ struct timeval *pri_schedule_next(struct pri *pri)
|
||||
return closest;
|
||||
}
|
||||
|
||||
int pri_schedule_run(struct pri *pri)
|
||||
static pri_event *__pri_schedule_run(struct pri *pri, struct timeval *tv)
|
||||
{
|
||||
struct timeval tv;
|
||||
int x;
|
||||
int p = 0;
|
||||
void (*callback)(void *);
|
||||
void *data;
|
||||
gettimeofday(&tv, NULL);
|
||||
pri_event *e;
|
||||
if (pri->subchannel) {
|
||||
if ((e = __pri_schedule_run(pri->subchannel, tv))) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
for (x=1;x<MAX_SCHED;x++) {
|
||||
if (pri->pri_sched[x].callback &&
|
||||
((pri->pri_sched[x].when.tv_sec < tv.tv_sec) ||
|
||||
((pri->pri_sched[x].when.tv_sec == tv.tv_sec) &&
|
||||
(pri->pri_sched[x].when.tv_usec <= tv.tv_usec)))) {
|
||||
p++;
|
||||
((pri->pri_sched[x].when.tv_sec < tv->tv_sec) ||
|
||||
((pri->pri_sched[x].when.tv_sec == tv->tv_sec) &&
|
||||
(pri->pri_sched[x].when.tv_usec <= tv->tv_usec)))) {
|
||||
pri->schedev = 0;
|
||||
callback = pri->pri_sched[x].callback;
|
||||
data = pri->pri_sched[x].data;
|
||||
pri->pri_sched[x].callback = NULL;
|
||||
pri->pri_sched[x].data = NULL;
|
||||
callback(data);
|
||||
}
|
||||
if (pri->schedev)
|
||||
return &pri->ev;
|
||||
}
|
||||
}
|
||||
return p;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pri_event *pri_schedule_run(struct pri *pri)
|
||||
{
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
return __pri_schedule_run(pri, &tv);
|
||||
}
|
||||
|
||||
|
||||
void pri_schedule_del(struct pri *pri,int id)
|
||||
{
|
||||
if ((id >= MAX_SCHED) || (id < 0))
|
||||
fprintf(stderr, "Asked to delete sched id %d???\n", id);
|
||||
pri_error("Asked to delete sched id %d???\n", id);
|
||||
pri->pri_sched[id].callback = NULL;
|
||||
}
|
||||
|
||||
409
pritest.c
Normal file
409
pritest.c
Normal file
@@ -0,0 +1,409 @@
|
||||
/*
|
||||
* 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>
|
||||
#if defined(__linux__)
|
||||
#include <linux/zaptel.h>
|
||||
#elif defined(__FreeBSD__)
|
||||
#include <zaptel.h>
|
||||
#endif
|
||||
#include <zap.h>
|
||||
#include "libpri.h"
|
||||
|
||||
#define PRI_DEF_NODETYPE PRI_CPE
|
||||
#define PRI_DEF_SWITCHTYPE PRI_SWITCH_NI2
|
||||
|
||||
#define MAX_CHAN 32
|
||||
#define DCHANNEL_TIMESLOT 16
|
||||
|
||||
|
||||
static int offset = 0;
|
||||
|
||||
static void do_channel(ZAP *z)
|
||||
{
|
||||
/* This is the part that runs on a given channel */
|
||||
zap_playf(z, "raw.ulaw", 0);
|
||||
}
|
||||
|
||||
struct pri_chan {
|
||||
pid_t pid;
|
||||
int needhangup;
|
||||
int alreadyhungup;
|
||||
q931_call *call;
|
||||
} chans[MAX_CHAN];
|
||||
|
||||
static int str2node(char *node)
|
||||
{
|
||||
if (!strcasecmp(node, "cpe"))
|
||||
return PRI_CPE;
|
||||
if (!strcasecmp(node, "network"))
|
||||
return PRI_NETWORK;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void chan_ended(int sig)
|
||||
{
|
||||
int status;
|
||||
int x;
|
||||
struct rusage rusage;
|
||||
pid_t pid;
|
||||
pid = wait4(-1, &status, WNOHANG, &rusage);
|
||||
|
||||
for (x=0;x<MAX_CHAN;x++) {
|
||||
if (pid == chans[x].pid) {
|
||||
printf("-- PID %d ended, channel %d\n", pid, x);
|
||||
chans[x].pid = 0;
|
||||
if (!chans[x].alreadyhungup) {
|
||||
/* It died, we need to hangup now */
|
||||
chans[x].needhangup = 1;
|
||||
} else {
|
||||
/* We've already been hungup, just clear it */
|
||||
chans[x].alreadyhungup = 0;
|
||||
chans[x].call = NULL;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (pid > -1) {
|
||||
fprintf(stderr, "--!! Unknown PID %d exited\n", pid);
|
||||
return;
|
||||
}
|
||||
}
|
||||
static int str2switch(char *swtype)
|
||||
{
|
||||
if (!strcasecmp(swtype, "ni2"))
|
||||
return PRI_SWITCH_NI2;
|
||||
if (!strcasecmp(swtype, "dms100"))
|
||||
return PRI_SWITCH_DMS100;
|
||||
if (!strcasecmp(swtype, "lucent5e"))
|
||||
return PRI_SWITCH_LUCENT5E;
|
||||
if (!strcasecmp(swtype, "att4ess"))
|
||||
return PRI_SWITCH_ATT4ESS;
|
||||
if (!strcasecmp(swtype, "euroisdn"))
|
||||
return PRI_SWITCH_EUROISDN_E1;
|
||||
if (!strcasecmp(swtype, "gr303eoc"))
|
||||
return PRI_SWITCH_GR303_EOC;
|
||||
if (!strcasecmp(swtype, "gr303tmc"))
|
||||
return PRI_SWITCH_GR303_TMC;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void hangup_channel(int channo)
|
||||
{
|
||||
if (chans[channo].pid) {
|
||||
|
||||
#if 0
|
||||
printf("Killing channel %d (pid = %d)\n", channo, chans[channo].pid);
|
||||
#endif
|
||||
chans[channo].alreadyhungup = 1;
|
||||
kill(chans[channo].pid, SIGTERM);
|
||||
} else if (chans[channo].needhangup)
|
||||
chans[channo].needhangup = 0;
|
||||
}
|
||||
|
||||
static void launch_channel(int channo)
|
||||
{
|
||||
pid_t pid;
|
||||
ZAP *z;
|
||||
char ch[80];
|
||||
|
||||
/* Make sure hangup state is reset */
|
||||
chans[channo].needhangup = 0;
|
||||
chans[channo].alreadyhungup = 0;
|
||||
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
fprintf(stderr, "--!! Unable to fork\n");
|
||||
chans[channo].needhangup = 1;
|
||||
}
|
||||
if (pid) {
|
||||
printf("-- Launching process %d to handle channel %d\n", pid, channo);
|
||||
chans[channo].pid = pid;
|
||||
} else {
|
||||
sprintf(ch, "%d", channo + offset);
|
||||
z = zap_open(ch, 0);
|
||||
if (z) {
|
||||
do_channel(z);
|
||||
exit(0);
|
||||
} else {
|
||||
fprintf(stderr, "--!! Unable to open channel %d\n", channo);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static int get_free_channel(int channo)
|
||||
{
|
||||
channo--;
|
||||
if((channo>MAX_CHAN)||(channo<0)) {
|
||||
fprintf(stderr, "Invalid Bchannel RANGE <%d", channo);
|
||||
return 0;
|
||||
};
|
||||
|
||||
while(chans[channo].pid) {
|
||||
channo--;
|
||||
}
|
||||
|
||||
return channo;
|
||||
}
|
||||
|
||||
/* place here criteria for completion of destination number */
|
||||
static int number_incommplete(char *number)
|
||||
{
|
||||
return strlen(number) < 3;
|
||||
}
|
||||
|
||||
static void start_channel(struct pri *pri, pri_event *e)
|
||||
{
|
||||
int channo = e->ring.channel;
|
||||
int flag = 1;
|
||||
pri_event_ring *ring = &e->ring;
|
||||
|
||||
if(channo == -1) {
|
||||
channo = e->ring.channel = get_free_channel(MAX_CHAN);
|
||||
|
||||
if(channo == DCHANNEL_TIMESLOT)
|
||||
channo = e->ring.channel = get_free_channel(MAX_CHAN);
|
||||
|
||||
|
||||
fprintf(stdout, "Any channel selected: %d\n", channo);
|
||||
|
||||
if(!channo) {
|
||||
pri_release(pri, ring->call, PRI_CAUSE_REQUESTED_CHAN_UNAVAIL);
|
||||
fprintf(stdout, "Abort call due to no avl B channels\n");
|
||||
return;
|
||||
}
|
||||
|
||||
flag = 0;
|
||||
}
|
||||
/* Make sure it's a valid number */
|
||||
if ((channo >= MAX_CHAN) || (channo < 0)) {
|
||||
fprintf(stderr, "--!! Channel %d is out of range\n", channo);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Make sure nothing is there */
|
||||
if (chans[channo].pid) {
|
||||
fprintf(stderr, "--!! Channel %d still has a call on it, ending it...\n", channo);
|
||||
hangup_channel(channo);
|
||||
/* Wait for it to die */
|
||||
while(chans[channo].pid)
|
||||
usleep(100);
|
||||
}
|
||||
|
||||
/* Record call number */
|
||||
chans[channo].call = e->ring.call;
|
||||
|
||||
/* Answer the line */
|
||||
if(flag) {
|
||||
pri_answer(pri, chans[channo].call, channo, 1);
|
||||
} else {
|
||||
pri_need_more_info(pri, chans[channo].call, channo, 1);
|
||||
}
|
||||
|
||||
/* Launch a process to handle it */
|
||||
launch_channel(channo);
|
||||
|
||||
}
|
||||
|
||||
static void handle_pri_event(struct pri *pri, pri_event *e)
|
||||
{
|
||||
switch(e->e) {
|
||||
case PRI_EVENT_DCHAN_UP:
|
||||
printf("-- D-Channel is now up! :-)\n");
|
||||
break;
|
||||
case PRI_EVENT_DCHAN_DOWN:
|
||||
printf("-- D-Channel is now down! :-(\n");
|
||||
break;
|
||||
case PRI_EVENT_RESTART:
|
||||
printf("-- Restarting channel %d\n", e->restart.channel);
|
||||
hangup_channel(e->restart.channel);
|
||||
break;
|
||||
case PRI_EVENT_CONFIG_ERR:
|
||||
printf("-- Configuration error detected: %s\n", e->err.err);
|
||||
break;
|
||||
case PRI_EVENT_RING:
|
||||
printf("-- Ring on channel %d (from %s to %s), answering...\n", e->ring.channel, e->ring.callingnum, e->ring.callednum);
|
||||
start_channel(pri, e);
|
||||
break;
|
||||
case PRI_EVENT_HANGUP:
|
||||
printf("-- Hanging up channel %d\n", e->hangup.channel);
|
||||
hangup_channel(e->hangup.channel);
|
||||
break;
|
||||
case PRI_EVENT_RINGING:
|
||||
case PRI_EVENT_ANSWER:
|
||||
fprintf(stderr, "--!! What? We shouldn't be making any calls...\n");
|
||||
break;
|
||||
case PRI_EVENT_HANGUP_ACK:
|
||||
/* Ignore */
|
||||
break;
|
||||
case PRI_EVENT_INFO_RECEIVED:
|
||||
fprintf(stdout, "number is: %s\n", e->ring.callednum);
|
||||
if(!number_incommplete(e->ring.callednum)) {
|
||||
fprintf(stdout, "final number is: %s\n", e->ring.callednum);
|
||||
pri_answer(pri, e->ring.call, 0, 1);
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "--!! Unknown PRI event %d\n", e->e);
|
||||
}
|
||||
}
|
||||
|
||||
static int run_pri(int dfd, int swtype, int node)
|
||||
{
|
||||
struct pri *pri;
|
||||
pri_event *e;
|
||||
struct timeval tv = {0,0}, *next;
|
||||
fd_set rfds, efds;
|
||||
int res,x;
|
||||
|
||||
pri = pri_new(dfd, node, swtype);
|
||||
if (!pri) {
|
||||
fprintf(stderr, "Unable to create PRI\n");
|
||||
return -1;
|
||||
}
|
||||
pri_set_debug(pri, -1);
|
||||
for (;;) {
|
||||
|
||||
/* Run the D-Channel */
|
||||
FD_ZERO(&rfds);
|
||||
FD_ZERO(&efds);
|
||||
FD_SET(dfd, &rfds);
|
||||
FD_SET(dfd, &efds);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
res = select(dfd + 1, &rfds, NULL, &efds, next ? &tv : NULL);
|
||||
e = NULL;
|
||||
|
||||
if (!res) {
|
||||
e = pri_schedule_run(pri);
|
||||
} else if (res > 0) {
|
||||
e = pri_check_event(pri);
|
||||
} else if (errno == ELAST) {
|
||||
res = ioctl(dfd, ZT_GETEVENT, &x);
|
||||
printf("Got Zaptel event: %d\n", x);
|
||||
} else if (errno != EINTR)
|
||||
fprintf(stderr, "Error (%d) on select: %s\n", ELAST, strerror(errno));
|
||||
|
||||
if (e) {
|
||||
handle_pri_event(pri, e);
|
||||
}
|
||||
|
||||
res = ioctl(dfd, ZT_GETEVENT, &x);
|
||||
|
||||
if (!res && x) {
|
||||
fprintf(stderr, "Got event on PRI interface: %d\n", x);
|
||||
}
|
||||
|
||||
/* Check for lines that need hangups */
|
||||
for (x=0;x<MAX_CHAN;x++)
|
||||
if (chans[x].needhangup) {
|
||||
chans[x].needhangup = 0;
|
||||
pri_release(pri, chans[x].call, PRI_CAUSE_NORMAL_CLEARING);
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int dfd;
|
||||
int swtype = PRI_DEF_SWITCHTYPE;
|
||||
int node = PRI_DEF_NODETYPE;
|
||||
struct zt_params p;
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "Usage: pritest <dchannel> [swtypetype] [nodetype]\n");
|
||||
exit(1);
|
||||
}
|
||||
dfd = open(argv[1], O_RDWR);
|
||||
if (dfd < 0) {
|
||||
fprintf(stderr, "Failed to open dchannel '%s': %s\n", argv[1], strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
if (ioctl(dfd, ZT_GET_PARAMS, &p)) {
|
||||
fprintf(stderr, "Unable to get parameters on '%s': %s\n", argv[1], strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
if ((p.sigtype != ZT_SIG_HDLCRAW) && (p.sigtype != ZT_SIG_HDLCFCS)) {
|
||||
fprintf(stderr, "%s is in %d signalling, not FCS HDLC or RAW HDLC mode\n", argv[1], p.sigtype);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (argc > 2) {
|
||||
swtype = str2switch(argv[2]);
|
||||
if (swtype < 0) {
|
||||
fprintf(stderr, "Valid switchtypes are: ni2, dms100, lucent5e, att4ess, and euroisdn\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (argc > 3) {
|
||||
node = str2node(argv[3]);
|
||||
if (node < 0) {
|
||||
fprintf(stderr, "Valid node types are: network and cpe\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
signal(SIGCHLD, chan_ended);
|
||||
|
||||
if (run_pri(dfd, swtype, node))
|
||||
exit(1);
|
||||
exit(0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
585
q921.c
Executable file → Normal file
585
q921.c
Executable file → Normal file
@@ -32,13 +32,25 @@
|
||||
#include "pri_q921.h"
|
||||
#include "pri_q931.h"
|
||||
|
||||
#define Q921_INIT(hf) do { \
|
||||
(hf).h.sapi = 0; \
|
||||
/*
|
||||
* Define RANDOM_DROPS To randomly drop packets in order to simulate loss for testing
|
||||
* retransmission functionality
|
||||
*/
|
||||
|
||||
/*
|
||||
#define RANDOM_DROPS
|
||||
*/
|
||||
|
||||
#define Q921_INIT(pri, hf) do { \
|
||||
memset(&(hf),0,sizeof(hf)); \
|
||||
(hf).h.sapi = (pri)->sapi; \
|
||||
(hf).h.ea1 = 0; \
|
||||
(hf).h.ea2 = 1; \
|
||||
(hf).h.tei = 0; \
|
||||
(hf).h.tei = (pri)->tei; \
|
||||
} while(0)
|
||||
|
||||
static void reschedule_t203(struct pri *pri);
|
||||
|
||||
static void q921_discard_retransmissions(struct pri *pri)
|
||||
{
|
||||
struct q921_frame *f, *p;
|
||||
@@ -52,25 +64,37 @@ 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;
|
||||
if (pri->master)
|
||||
return q921_transmit(pri->master, h, len);
|
||||
#ifdef RANDOM_DROPS
|
||||
if (!(random() % 3)) {
|
||||
pri_message(" === Dropping Packet ===\n");
|
||||
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);
|
||||
/* Write an extra two bytes for the FCS */
|
||||
res = write(pri->fd, h, len + 2);
|
||||
if (res != (len + 2)) {
|
||||
fprintf(stderr, "Short write: %d/%d (%s)\n", res, len + 2, strerror(errno));
|
||||
pri_error("Short write: %d/%d (%s)\n", res, len + 2, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
reschedule_t203(pri);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void q921_send_ua(struct pri *pri, int pfbit)
|
||||
{
|
||||
q921_h h;
|
||||
Q921_INIT(h);
|
||||
Q921_INIT(pri, h);
|
||||
h.u.m3 = 3; /* M3 = 3 */
|
||||
h.u.m2 = 0; /* M2 = 0 */
|
||||
h.u.p_f = pfbit; /* Final bit on */
|
||||
@@ -83,24 +107,28 @@ static void q921_send_ua(struct pri *pri, int pfbit)
|
||||
h.h.c_r = 1;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Don't know how to U/A on a type %d node\n", pri->localtype);
|
||||
pri_error("Don't know how to U/A on a type %d node\n", pri->localtype);
|
||||
return;
|
||||
}
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
printf("Sending Unnumbered Acknowledgement\n");
|
||||
pri_message("Sending Unnumbered Acknowledgement\n");
|
||||
q921_transmit(pri, &h, 3);
|
||||
}
|
||||
|
||||
static void q921_send_sabme(void *vpri)
|
||||
static void q921_send_sabme_now(void *vpri);
|
||||
|
||||
static void q921_send_sabme(void *vpri, int now)
|
||||
{
|
||||
struct pri *pri = vpri;
|
||||
q921_h h;
|
||||
pri_schedule_del(pri, pri->sabme_timer);
|
||||
pri->sabme_timer = 0;
|
||||
pri->sabme_timer = pri_schedule_event(pri, T_200, q921_send_sabme, pri);
|
||||
Q921_INIT(h);
|
||||
h.u.m3 = 3; /* M3 = 3 */
|
||||
h.u.m2 = 3; /* M2 = 3 */
|
||||
pri->sabme_timer = pri_schedule_event(pri, T_200, q921_send_sabme_now, pri);
|
||||
if (!now)
|
||||
return;
|
||||
Q921_INIT(pri, h);
|
||||
h.u.m3 = 3; /* M3 = 3 */
|
||||
h.u.m2 = 3; /* M2 = 3 */
|
||||
h.u.p_f = 1; /* Poll bit set */
|
||||
h.u.ft = Q921_FRAMETYPE_U;
|
||||
switch(pri->localtype) {
|
||||
@@ -111,14 +139,18 @@ static void q921_send_sabme(void *vpri)
|
||||
h.h.c_r = 0;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Don't know how to U/A on a type %d node\n", pri->localtype);
|
||||
pri_error("Don't know how to U/A on a type %d node\n", pri->localtype);
|
||||
return;
|
||||
}
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
printf("Sending Set Asynchronous Balanced Mode Extended\n");
|
||||
pri_message("Sending Set Asynchronous Balanced Mode Extended\n");
|
||||
q921_transmit(pri, &h, 3);
|
||||
pri->q921_state = Q921_AWAITING_ESTABLISH;
|
||||
|
||||
}
|
||||
|
||||
static void q921_send_sabme_now(void *vpri)
|
||||
{
|
||||
q921_send_sabme(vpri, 1);
|
||||
}
|
||||
|
||||
static int q921_ack_packet(struct pri *pri, int num)
|
||||
@@ -127,16 +159,39 @@ static int q921_ack_packet(struct pri *pri, int num)
|
||||
f = pri->txqueue;
|
||||
while(f) {
|
||||
if (f->h.n_s == num) {
|
||||
/* Cancel each packet as necessary */
|
||||
/* That's our packet */
|
||||
if (prev)
|
||||
prev->next = f->next;
|
||||
else
|
||||
pri->txqueue = f->next;
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
pri_message("-- ACKing packet %d, new txqueue is %d (-1 means empty)\n", f->h.n_s, pri->txqueue ? pri->txqueue->h.n_s : -1);
|
||||
/* Update v_a */
|
||||
pri->v_a = 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++;
|
||||
f->h.n_r = pri->v_r;
|
||||
q921_transmit(pri, (q921_h *)(&f->h), f->len);
|
||||
break;
|
||||
}
|
||||
f = f->next;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
prev = f;
|
||||
f = f->next;
|
||||
}
|
||||
return 0;
|
||||
@@ -144,56 +199,76 @@ 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 */
|
||||
fprintf(stderr, "ACK received outside of window, ignoring\n");
|
||||
return;
|
||||
pri_error("ACK received for '%d' outside of window of '%d' to '%d', restarting\n", ack, pri->v_a, pri->v_s);
|
||||
ev = q921_dchannel_down(pri);
|
||||
q921_start(pri, 1);
|
||||
pri->schedev = 1;
|
||||
return ev;
|
||||
}
|
||||
/* Cancel each packet as necessary */
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
pri_message("-- ACKing all packets from %d to (but not including) %d\n", pri->v_a, ack);
|
||||
for (x=pri->v_a; x != ack; Q921_INC(x))
|
||||
cnt += q921_ack_packet(pri, x);
|
||||
if (cnt) {
|
||||
if (!pri->txqueue) {
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
printf("-- Since there was something acked, stopping T200 counter\n");
|
||||
pri_message("-- Since there was nothing left, stopping T200 counter\n");
|
||||
/* Something was ACK'd. Stop T200 counter */
|
||||
pri_schedule_del(pri, pri->t200_timer);
|
||||
pri->t200_timer = 0;
|
||||
}
|
||||
if (pri->t203_timer) {
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
printf("-- Stopping T203 counter since we got an ACK\n");
|
||||
pri_message("-- Stopping T203 counter since we got an ACK\n");
|
||||
pri_schedule_del(pri, pri->t203_timer);
|
||||
pri->t203_timer = 0;
|
||||
}
|
||||
if (pri->txqueue) {
|
||||
/* Something left to transmit, Start the T200 counter again if we stopped it */
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
printf("-- Something left to transmit, restarting T200 counter\n");
|
||||
pri_message("-- Something left to transmit (%d), restarting T200 counter\n", pri->txqueue->h.n_s);
|
||||
if (!pri->t200_timer)
|
||||
pri->t200_timer = pri_schedule_event(pri, T_200, t200_expire, pri);
|
||||
} else {
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
printf("-- Nothing left, starting T203 counter\n");
|
||||
pri_message("-- Nothing left, starting T203 counter\n");
|
||||
/* Nothing to transmit, start the T203 counter instead */
|
||||
pri->t203_timer = pri_schedule_event(pri, T_203, t203_expire, pri);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void q921_rr(struct pri *pri, int pbit) {
|
||||
static void q921_reject(struct pri *pri, int pf)
|
||||
{
|
||||
q921_h h;
|
||||
Q921_INIT(h);
|
||||
Q921_INIT(pri, h);
|
||||
h.s.x0 = 0; /* Always 0 */
|
||||
h.s.ss = 0; /* Receive Ready */
|
||||
h.s.ss = 2; /* Reject */
|
||||
h.s.ft = 1; /* Frametype (01) */
|
||||
h.s.n_r = pri->v_r; /* N/R */
|
||||
h.s.p_f = pbit; /* Poll/Final set appropriately */
|
||||
h.s.n_r = pri->v_r; /* Where to start retransmission */
|
||||
h.s.p_f = pf;
|
||||
switch(pri->localtype) {
|
||||
case PRI_NETWORK:
|
||||
h.h.c_r = 0;
|
||||
@@ -202,12 +277,43 @@ static void q921_rr(struct pri *pri, int pbit) {
|
||||
h.h.c_r = 1;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Don't know how to U/A on a type %d node\n", pri->localtype);
|
||||
pri_error("Don't know how to U/A on a type %d node\n", pri->localtype);
|
||||
return;
|
||||
}
|
||||
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, int cmd) {
|
||||
q921_h h;
|
||||
Q921_INIT(pri, h);
|
||||
h.s.x0 = 0; /* Always 0 */
|
||||
h.s.ss = 0; /* Receive Ready */
|
||||
h.s.ft = 1; /* Frametype (01) */
|
||||
h.s.n_r = pri->v_r; /* N/R */
|
||||
h.s.p_f = pbit; /* Poll/Final set appropriately */
|
||||
switch(pri->localtype) {
|
||||
case PRI_NETWORK:
|
||||
if (cmd)
|
||||
h.h.c_r = 1;
|
||||
else
|
||||
h.h.c_r = 0;
|
||||
break;
|
||||
case PRI_CPE:
|
||||
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);
|
||||
return;
|
||||
}
|
||||
pri->v_na = pri->v_r; /* Make a note that we've already acked this */
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
printf("Sending Receiver Ready (%d)\n", pri->v_r);
|
||||
pri_message("Sending Receiver Ready (%d)\n", pri->v_r);
|
||||
q921_transmit(pri, &h, 4);
|
||||
}
|
||||
|
||||
@@ -217,7 +323,7 @@ static void t200_expire(void *vpri)
|
||||
if (pri->txqueue) {
|
||||
/* Retransmit first packet in the queue, setting the poll bit */
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
printf("T200 counter expired, resending last frame and scheduling t200 again (retrans so far = %d)\n", pri->retrans);
|
||||
pri_message("-- T200 counter expired, What to do...\n");
|
||||
/* Force Poll bit */
|
||||
pri->txqueue->h.p_f = 1;
|
||||
/* Update nr */
|
||||
@@ -225,11 +331,51 @@ static void t200_expire(void *vpri)
|
||||
pri->v_na = pri->v_r;
|
||||
pri->solicitfbit = 1;
|
||||
pri->retrans++;
|
||||
q921_transmit(pri, (q921_h *)&pri->txqueue->h, pri->txqueue->len);
|
||||
/* Up to three retransmissions */
|
||||
if (pri->retrans < N_200) {
|
||||
/* Reschedule t200_timer */
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
pri_message("-- Retransmitting %d bytes\n", 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->q921_state = Q921_LINK_CONNECTION_RELEASED;
|
||||
pri->t200_timer = 0;
|
||||
q921_dchannel_down(pri);
|
||||
q921_start(pri, 1);
|
||||
pri->schedev = 1;
|
||||
}
|
||||
} else if (pri->solicitfbit) {
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
pri_message("-- Retrying poll with f-bit\n");
|
||||
pri->retrans++;
|
||||
if (pri->retrans < N_200) {
|
||||
pri->solicitfbit = 1;
|
||||
q921_rr(pri, 1, 1);
|
||||
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->q921_state = Q921_LINK_CONNECTION_RELEASED;
|
||||
pri->t200_timer = 0;
|
||||
q921_dchannel_down(pri);
|
||||
q921_start(pri, 1);
|
||||
pri->schedev = 1;
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "T200 counter expired, nothing to send...\n");
|
||||
pri_error("T200 counter expired, nothing to send...\n");
|
||||
pri->t200_timer = 0;
|
||||
}
|
||||
pri->t200_timer = 0;
|
||||
}
|
||||
|
||||
int q921_transmit_iframe(struct pri *pri, void *buf, int len, int cr)
|
||||
@@ -238,7 +384,8 @@ int q921_transmit_iframe(struct pri *pri, void *buf, int len, int cr)
|
||||
for (f=pri->txqueue; f; f = f->next) prev = f;
|
||||
f = malloc(sizeof(q921_frame) + len + 2);
|
||||
if (f) {
|
||||
Q921_INIT(f->h);
|
||||
memset(f,0,sizeof(q921_frame) + len + 2);
|
||||
Q921_INIT(pri, f->h);
|
||||
switch(pri->localtype) {
|
||||
case PRI_NETWORK:
|
||||
if (cr)
|
||||
@@ -254,6 +401,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;
|
||||
@@ -266,25 +414,35 @@ 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)
|
||||
printf("Stopping T_203 timer\n");
|
||||
pri_message("Stopping T_203 timer\n");
|
||||
pri_schedule_del(pri, pri->t203_timer);
|
||||
pri->t203_timer = 0;
|
||||
}
|
||||
if (!pri->t200_timer) {
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
printf("Starting T_200 timer\n");
|
||||
pri_message("Starting T_200 timer\n");
|
||||
pri->t200_timer = pri_schedule_event(pri, T_200, t200_expire, pri);
|
||||
} else
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
printf("T_200 timer already going (%d)\n", pri->t200_timer);
|
||||
pri_message("T_200 timer already going (%d)\n", pri->t200_timer);
|
||||
|
||||
} else {
|
||||
fprintf(stderr, "!! Out of memory for Q.921 transmit\n");
|
||||
pri_error("!! Out of memory for Q.921 transmit\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
@@ -293,47 +451,58 @@ 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)
|
||||
printf("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;
|
||||
pri->retrans = 0;
|
||||
q921_rr(pri, 1, 1);
|
||||
/* Start timer T200 to resend our RR if we don't get it */
|
||||
pri->t203_timer = pri_schedule_event(pri, T_200, t200_expire, pri);
|
||||
} else {
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
pri_message("T203 counter expired in weird state %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
|
||||
fprintf(stderr, "XXX I need to reject (expected %d, got %d) XXX\n", pri->v_r, i->n_s);
|
||||
#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;
|
||||
}
|
||||
@@ -341,79 +510,131 @@ static pri_event *q921_handle_iframe(struct pri *pri, q921_i *i, int len)
|
||||
void q921_dump(q921_h *h, int len, int showraw, int txrx)
|
||||
{
|
||||
int x;
|
||||
char *type;
|
||||
char direction_tag;
|
||||
|
||||
direction_tag = txrx ? '>' : '<';
|
||||
if (showraw) {
|
||||
printf("%c [", (txrx ? '>' : '<'));
|
||||
for (x=0;x<len;x++)
|
||||
printf("%02x ",h->raw[x]);
|
||||
printf("]\n");
|
||||
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) {
|
||||
|
||||
switch (h->h.data[0] & Q921_FRAMETYPE_MASK) {
|
||||
case 0:
|
||||
case 2:
|
||||
printf("\n Informational Frame:\n");
|
||||
pri_message("\n%c Informational frame:\n", direction_tag);
|
||||
break;
|
||||
case 1:
|
||||
printf("\n Supervisory frame:\n");
|
||||
pri_message("\n%c Supervisory frame:\n", direction_tag);
|
||||
break;
|
||||
case 3:
|
||||
printf("\n Unnumbered frame:\n");
|
||||
pri_message("\n%c Unnumbered frame:\n", direction_tag);
|
||||
break;
|
||||
}
|
||||
|
||||
printf(
|
||||
pri_message(
|
||||
"%c SAPI: %02d C/R: %d EA: %d\n"
|
||||
"%c TEI: %03d EA: %d\n",
|
||||
(txrx ? '>' : '<'),
|
||||
direction_tag,
|
||||
h->h.sapi,
|
||||
h->h.c_r,
|
||||
h->h.ea1,
|
||||
(txrx ? '>' : '<'),
|
||||
direction_tag,
|
||||
h->h.tei,
|
||||
h->h.ea2);
|
||||
switch(h->h.data[0] & Q921_FRAMETYPE_MASK) {
|
||||
switch (h->h.data[0] & Q921_FRAMETYPE_MASK) {
|
||||
case 0:
|
||||
case 2:
|
||||
/* Informational frame */
|
||||
printf(
|
||||
pri_message(
|
||||
"%c N(S): %03d 0: %d\n"
|
||||
"%c N(R): %03d P: %d\n"
|
||||
"%c %d bytes of data\n",
|
||||
(txrx ? '>' : '<'),
|
||||
direction_tag,
|
||||
h->i.n_s,
|
||||
h->i.ft,
|
||||
(txrx ? '>' : '<'),
|
||||
direction_tag,
|
||||
h->i.n_r,
|
||||
h->i.p_f,
|
||||
(txrx ? '>' : '<'),
|
||||
direction_tag,
|
||||
len - 4);
|
||||
break;
|
||||
case 1:
|
||||
/* Supervisory frame */
|
||||
printf(
|
||||
"%c Zeros: %d S: %d 01: %d\n"
|
||||
"%c N(R): %03d P/F: %d\n"
|
||||
type = "???";
|
||||
switch (h->s.ss) {
|
||||
case 0:
|
||||
type = "RR (receive ready)";
|
||||
break;
|
||||
case 1:
|
||||
type = "RNR (receive not ready)";
|
||||
break;
|
||||
case 2:
|
||||
type = "REJ (reject)";
|
||||
break;
|
||||
}
|
||||
pri_message(
|
||||
"%c Zero: %d S: %d 01: %d [ %s ]\n"
|
||||
"%c N(R): %03d P/F: %d\n"
|
||||
"%c %d bytes of data\n",
|
||||
(txrx ? '>' : '<'),
|
||||
direction_tag,
|
||||
h->s.x0,
|
||||
h->s.ss,
|
||||
h->s.ft,
|
||||
(txrx ? '>' : '<'),
|
||||
type,
|
||||
direction_tag,
|
||||
h->s.n_r,
|
||||
h->s.p_f,
|
||||
(txrx ? '>' : '<'),
|
||||
direction_tag,
|
||||
len - 4);
|
||||
break;
|
||||
case 3:
|
||||
case 3:
|
||||
/* Unnumbered frame */
|
||||
printf(
|
||||
"%c M3: %d P/F: %d M2: %d 11: %d\n"
|
||||
type = "???";
|
||||
if (h->u.ft == 3) {
|
||||
switch (h->u.m3) {
|
||||
case 0:
|
||||
if (h->u.m2 == 3)
|
||||
type = "DM (disconnect mode)";
|
||||
else if (h->u.m2 == 0)
|
||||
type = "UI (unnumbered information)";
|
||||
break;
|
||||
case 2:
|
||||
if (h->u.m2 == 0)
|
||||
type = "DISC (disconnect)";
|
||||
break;
|
||||
case 3:
|
||||
if (h->u.m2 == 3)
|
||||
type = "SABME (set asynchronous balanced mode extended)";
|
||||
else if (h->u.m2 == 0)
|
||||
type = "UA (unnumbered acknowledgement)";
|
||||
break;
|
||||
case 4:
|
||||
if (h->u.m2 == 1)
|
||||
type = "FRMR (frame reject)";
|
||||
break;
|
||||
case 5:
|
||||
if (h->u.m2 == 3)
|
||||
type = "XID (exchange identification note)";
|
||||
break;
|
||||
}
|
||||
}
|
||||
pri_message(
|
||||
"%c M3: %d P/F: %d M2: %d 11: %d [ %s ]\n"
|
||||
"%c %d bytes of data\n",
|
||||
(txrx ? '>' : '<'),
|
||||
direction_tag,
|
||||
h->u.m3,
|
||||
h->u.p_f,
|
||||
h->u.m2,
|
||||
h->u.ft,
|
||||
(txrx ? '>' : '<'),
|
||||
type,
|
||||
direction_tag,
|
||||
len - 3);
|
||||
break;
|
||||
};
|
||||
@@ -428,6 +649,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;
|
||||
|
||||
@@ -457,6 +681,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);
|
||||
@@ -467,43 +692,39 @@ 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_qualified(struct pri *pri, q921_h *h, int len)
|
||||
{
|
||||
/* Discard FCS */
|
||||
len -= 2;
|
||||
|
||||
if (pri->debug & PRI_DEBUG_Q921_DUMP)
|
||||
q921_dump(h, len, pri->debug & PRI_DEBUG_Q921_RAW, 0);
|
||||
q921_frame *f;
|
||||
pri_event *ev;
|
||||
int sendnow;
|
||||
|
||||
/* Check some reject conditions -- Start by rejecting improper ea's */
|
||||
if (h->h.ea1 || !(h->h.ea2))
|
||||
return NULL;
|
||||
|
||||
switch(h->h.data[0] & Q921_FRAMETYPE_MASK) {
|
||||
case 0:
|
||||
case 2:
|
||||
if (pri->q921_state != Q921_LINK_CONNECTION_ESTABLISHED) {
|
||||
fprintf(stderr, "!! Got I-frame while link state %d\n", pri->q921_state);
|
||||
pri_error("!! Got I-frame while link state %d\n", pri->q921_state);
|
||||
return NULL;
|
||||
}
|
||||
/* Informational frame */
|
||||
if (len < 4) {
|
||||
fprintf(stderr, "!! Received short I-frame\n");
|
||||
pri_error("!! Received short I-frame (expected 4, got %d)\n", len);
|
||||
break;
|
||||
}
|
||||
return q921_handle_iframe(pri, &h->i, len);
|
||||
break;
|
||||
case 1:
|
||||
if (pri->q921_state != Q921_LINK_CONNECTION_ESTABLISHED) {
|
||||
fprintf(stderr, "!! Got S-frame while link down\n");
|
||||
pri_error("!! Got S-frame while link down\n");
|
||||
return NULL;
|
||||
}
|
||||
if (len < 4) {
|
||||
fprintf(stderr, "!! Received short S-frame\n");
|
||||
pri_error("!! Received short S-frame (expected 4, got %d)\n", len);
|
||||
break;
|
||||
}
|
||||
switch(h->s.ss) {
|
||||
@@ -511,60 +732,124 @@ 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) {
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
printf("-- Got RR response to our frame\n");
|
||||
pri_message("-- Got RR response to our frame\n");
|
||||
} else {
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
printf("-- Unsolicited RR with P/F bit, responding\n");
|
||||
q921_rr(pri, 1);
|
||||
pri_message("-- Unsolicited RR with P/F bit, responding\n");
|
||||
q921_rr(pri, 1, 0);
|
||||
}
|
||||
pri->solicitfbit = 0;
|
||||
}
|
||||
break;
|
||||
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;
|
||||
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, 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)) && 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;
|
||||
q921_transmit(pri, (q921_h *)(&f->h), f->len);
|
||||
}
|
||||
}
|
||||
if (!sendnow) {
|
||||
if (pri->txqueue) {
|
||||
/* This should never happen */
|
||||
if (!h->s.p_f || h->s.n_r) {
|
||||
pri_error("!! Got reject for frame %d, but we only have others!\n", h->s.n_r);
|
||||
}
|
||||
} else {
|
||||
/* Hrm, we have nothing to send, but have been REJ'd. Reset v_a, v_s, etc */
|
||||
pri_error("!! Got reject for frame %d, but we have nothing -- resetting!\n", h->s.n_r);
|
||||
pri->v_a = h->s.n_r;
|
||||
pri->v_s = h->s.n_r;
|
||||
/* Reset t200 timer if it was somehow going */
|
||||
if (pri->t200_timer) {
|
||||
pri_schedule_del(pri, pri->t200_timer);
|
||||
pri->t200_timer = 0;
|
||||
}
|
||||
/* Reset and restart t203 timer */
|
||||
if (pri->t203_timer)
|
||||
pri_schedule_del(pri, pri->t203_timer);
|
||||
pri->t203_timer = pri_schedule_event(pri, T_203, t203_expire, pri);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "!! XXX Unknown Supervisory frame XXX\n");
|
||||
pri_error("!! XXX Unknown Supervisory frame ss=0x%02x,pf=%02xnr=%02x vs=%02x, va=%02x XXX\n", h->s.ss, h->s.p_f, h->s.n_r,
|
||||
pri->v_s, pri->v_a);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (len < 3) {
|
||||
fprintf(stderr, "!! Received short unnumbered frame\n");
|
||||
pri_error("!! Received short unnumbered frame\n");
|
||||
break;
|
||||
}
|
||||
switch(h->u.m3) {
|
||||
case 0:
|
||||
if (h->u.m2 == 3) {
|
||||
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 */
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
printf("-- Got Unconnected Mode from peer.\n");
|
||||
/* Disconnected mode */
|
||||
if (pri->q921_state != Q921_LINK_CONNECTION_RELEASED)
|
||||
return q921_dchannel_down(pri);
|
||||
pri_message("-- Got DM Mode from peer.\n");
|
||||
/* Disconnected mode, try again after T200 */
|
||||
ev = q921_dchannel_down(pri);
|
||||
q921_start(pri, 0);
|
||||
return ev;
|
||||
|
||||
} else {
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
printf("-- DM requesting SABME, starting.\n");
|
||||
pri_message("-- Ignoring unsolicited DM with p/f set to 0\n");
|
||||
#if 0
|
||||
/* Requesting that we start */
|
||||
q921_start(pri);
|
||||
q921_start(pri, 0);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
} else if (!h->u.m2) {
|
||||
printf("XXX Unnumbered Information not implemented XXX\n");
|
||||
pri_message("XXX Unnumbered Information not implemented XXX\n");
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE)
|
||||
printf("-- Got Disconnect from peer.\n");
|
||||
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 */
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE) {
|
||||
printf("-- Got SABME from %s peer.\n", h->h.c_r ? "network" : "cpe");
|
||||
pri_message("-- Got SABME from %s peer.\n", h->h.c_r ? "network" : "cpe");
|
||||
}
|
||||
if (h->h.c_r) {
|
||||
pri->remotetype = PRI_NETWORK;
|
||||
@@ -586,22 +871,22 @@ pri_event *q921_receive(struct pri *pri, q921_h *h, int len)
|
||||
/* It's a UA */
|
||||
if (pri->q921_state == Q921_AWAITING_ESTABLISH) {
|
||||
if (pri->debug & PRI_DEBUG_Q921_STATE) {
|
||||
printf("-- Got UA from %s peer Link up.\n", h->h.c_r ? "cpe" : "network");
|
||||
pri_message("-- Got UA from %s peer Link up.\n", h->h.c_r ? "cpe" : "network");
|
||||
}
|
||||
return q921_dchannel_up(pri);
|
||||
} else
|
||||
fprintf(stderr, "!! Got a UA, but i'm in state %d\n", pri->q921_state);
|
||||
pri_error("!! Got a UA, but i'm in state %d\n", pri->q921_state);
|
||||
} else
|
||||
fprintf(stderr, "!! Weird frame received (m3=3, m2 = %d)\n", h->u.m2);
|
||||
pri_error("!! Weird frame received (m3=3, m2 = %d)\n", h->u.m2);
|
||||
break;
|
||||
case 4:
|
||||
fprintf(stderr, "!! Frame got rejected!\n");
|
||||
pri_error("!! Frame got rejected!\n");
|
||||
break;
|
||||
case 5:
|
||||
fprintf(stderr, "!! XID frames not supported\n");
|
||||
pri_error("!! XID frames not supported\n");
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "!! Don't know what to do with M3=%d u-frames\n", h->u.m3);
|
||||
pri_error("!! Don't know what to do with M3=%d u-frames\n", h->u.m3);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -609,15 +894,57 @@ pri_event *q921_receive(struct pri *pri, q921_h *h, int len)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void q921_start(struct pri *pri)
|
||||
static pri_event *__q921_receive(struct pri *pri, q921_h *h, int len)
|
||||
{
|
||||
pri_event *ev;
|
||||
/* Discard FCS */
|
||||
len -= 2;
|
||||
|
||||
if (!pri->master && pri->debug & PRI_DEBUG_Q921_DUMP)
|
||||
q921_dump(h, len, pri->debug & PRI_DEBUG_Q921_RAW, 0);
|
||||
|
||||
/* Check some reject conditions -- Start by rejecting improper ea's */
|
||||
if (h->h.ea1 || !(h->h.ea2))
|
||||
return NULL;
|
||||
|
||||
/* Check for broadcasts - not yet handled */
|
||||
if (h->h.tei == Q921_TEI_GROUP)
|
||||
return NULL;
|
||||
|
||||
/* Check for SAPIs we don't yet handle */
|
||||
if ((h->h.sapi != pri->sapi) || (h->h.tei != pri->tei)) {
|
||||
#ifdef PROCESS_SUBCHANNELS
|
||||
/* If it's not us, try any subchannels we have */
|
||||
if (pri->subchannel)
|
||||
return q921_receive(pri->subchannel, h, len + 2);
|
||||
else
|
||||
#endif
|
||||
return NULL;
|
||||
|
||||
}
|
||||
ev = __q921_receive_qualified(pri, h, len);
|
||||
reschedule_t203(pri);
|
||||
return ev;
|
||||
}
|
||||
|
||||
pri_event *q921_receive(struct pri *pri, q921_h *h, int len)
|
||||
{
|
||||
pri_event *e;
|
||||
e = __q921_receive(pri, h, len);
|
||||
#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) {
|
||||
fprintf(stderr, "!! q921_start: Not in 'Link Connection Released' state\n");
|
||||
pri_error("!! q921_start: Not in 'Link Connection Released' state\n");
|
||||
return;
|
||||
}
|
||||
/* Reset our interface */
|
||||
q921_reset(pri);
|
||||
/* Do the SABME XXX Maybe we should implement T_WAIT? XXX */
|
||||
q921_send_sabme(pri);
|
||||
q921_send_sabme(pri, now);
|
||||
}
|
||||
|
||||
|
||||
238
testprilib.c
Normal file
238
testprilib.c
Normal file
@@ -0,0 +1,238 @@
|
||||
/*
|
||||
* 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>
|
||||
#if defined(__linux__)
|
||||
#include <linux/zaptel.h>
|
||||
#elif defined(__FreeBSD__)
|
||||
#include <zaptel.h>
|
||||
#endif
|
||||
#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