Compare commits

...

18 Commits
0.1.0 ... 0.3.0

Author SHA1 Message Date
Kevin P. Fleming
2a08465d55 remove extraneous svn:executable properties
git-svn-id: https://origsvn.digium.com/svn/libpri/tags/0.3.0@266 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2005-11-29 18:39:18 +00:00
Kevin P. Fleming
ebe2cae963 automatic tag renames
git-svn-id: https://origsvn.digium.com/svn/libpri/tags/0.3.0@263 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2005-11-27 04:17:23 +00:00
Admin Commit
ea6c293782 This commit was manufactured by cvs2svn to create tag 'v0-3-0'.
git-svn-id: https://origsvn.digium.com/svn/libpri/tags/v0-3-0@24 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2002-03-22 17:17:47 +00:00
Mark Spencer
05f41a4926 Version 0.3.0 from FTP
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@23 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2002-03-22 17:17:47 +00:00
Mark Spencer
a6bebcaafc Version 0.3.0 from FTP
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@22 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2002-03-18 14:04:47 +00:00
Mark Spencer
a68a6bd01d Version 0.3.0 from FTP
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@21 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2002-03-18 13:59:09 +00:00
Mark Spencer
455227676a Version 0.3.0 from FTP
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@20 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2002-03-18 13:41:15 +00:00
Mark Spencer
834b8d85d7 Version 0.3.0 from FTP
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@19 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2002-03-16 04:17:53 +00:00
Mark Spencer
f81ba655b2 Version 0.3.0 from FTP
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@18 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2002-03-15 22:52:37 +00:00
Mark Spencer
8cf62085ee Version 0.3.0 from FTP
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@17 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2002-02-18 14:06:31 +00:00
Mark Spencer
9ed9f37ada Version 0.2.0 from FTP
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@15 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2001-12-07 19:45:45 +00:00
Mark Spencer
ecca15537d Version 0.2.0 from FTP
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@14 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2001-11-29 18:09:09 +00:00
Mark Spencer
0aa2e6fe6c Version 0.2.0 from FTP
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@13 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2001-11-26 02:54:32 +00:00
Mark Spencer
c84465ba47 Version 0.2.0 from FTP
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@12 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2001-10-18 16:21:39 +00:00
Mark Spencer
5d2d870837 Version 0.1.1 from FTP
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@10 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2001-07-20 20:52:43 +00:00
Mark Spencer
46baaa36df Version 0.1.1 from FTP
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@9 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2001-07-17 12:12:42 +00:00
Mark Spencer
ecb32ede6a Version 0.1.1 from FTP
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@8 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2001-05-21 13:39:30 +00:00
Mark Spencer
c752834a02 Version 0.1.1 from FTP
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@7 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2001-05-15 15:32:24 +00:00
14 changed files with 1398 additions and 378 deletions

14
ChangeLog Executable file → Normal file
View 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

7
Makefile Executable file → Normal file
View File

@@ -38,6 +38,12 @@ install: $(STATIC_LIBRARY) $(DYNAMIC_LIBRARY)
install -m 644 $(STATIC_LIBRARY) /usr/lib
/sbin/ldconfig
pritest: pritest.o
$(CC) -o pritest pritest.o -L. -lpri -lzap
pridump: pridump.o
$(CC) -o pridump pridump.o -L. -lpri -lzap
%.lo : %.c
$(CC) -fPIC $(CFLAGS) -o $@ -c $<
@@ -53,3 +59,4 @@ $(DYNAMIC_LIBRARY): $(DYNAMIC_OBJS)
clean:
rm -f *.o *.so *.lo
rm -f testpri $(STATIC_LIBRARY) $(DYNAMIC_LIBRARY)
rm -f pritest pridump

0
README Executable file → Normal file
View File

0
TODO Executable file → Normal file
View File

97
libpri.h Executable file → Normal file
View 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,61 @@
#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) */
/* 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 */
/* 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 +120,58 @@
#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
typedef struct q931_call q931_call;
@@ -159,6 +215,7 @@ typedef struct pri_event_ring {
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 */
q931_call *call; /* Opaque call pointer */
} pri_event_ring;
@@ -246,9 +303,9 @@ extern q931_call *pri_new_call(struct pri *pri);
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);
char *called,int calledplan, int ulayer1);
#endif

25
pri.c Executable file → Normal file
View File

@@ -105,13 +105,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 +134,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 +153,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);
@@ -222,9 +235,9 @@ void pri_dump_event(struct pri *pri, pri_event *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)
int calledplan,int ulayer1)
{
if (!pri || !c)
return -1;
return q931_setup(pri, c, transmode, channel, exclusive, nonisdn, caller, callerplan, callerpres, called, calledplan);
return q931_setup(pri, c, transmode, channel, exclusive, nonisdn, caller, callerplan, callerpres, called, calledplan, ulayer1);
}

3
pri_internal.h Executable file → Normal file
View File

@@ -70,6 +70,7 @@ struct pri {
/* Used by scheduler */
struct timeval tv;
int schedev;
pri_event ev; /* Static event thingy */
/* Q.921 Re-transmission queue */
@@ -81,7 +82,7 @@ struct pri {
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);

8
pri_q921.h Executable file → Normal file
View File

@@ -34,6 +34,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 +42,13 @@
#define Q921_FRAMETYPE_I 0x0
#define Q921_FRAMETYPE_S 0x1
#define Q921_TEI_GROUP 127
#define Q921_SAPI_CALL_CTRL 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

54
pri_q931.h Executable file → Normal file
View File

@@ -123,6 +123,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 +135,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 */
@@ -169,6 +190,33 @@ typedef struct q931_ie {
#define Q931_LOW_LAYER_COMPAT 0x7c
#define Q931_HIGH_LAYER_COMPAT 0x7d
#define Q931_IE_SEGMENTED_MSG 0x00
#define Q931_IE_CHANGE_STATUS 0x01
#define Q931_IE_CONNECTED_NUM 0x0C
#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_DISPLAY 0x28
#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
/* EuroISDN */
#define Q931_SENDING_COMPLETE 0x21
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);
@@ -185,6 +233,6 @@ 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);
int calledplan, int ulay1);
extern void q931_dump(q931_h *h, int len, int txrx);
#endif

130
pridump.c Normal file
View File

@@ -0,0 +1,130 @@
/*
* 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 <linux/zaptel.h>
#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;
}

13
prisched.c Executable file → Normal file
View File

@@ -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;
@@ -68,11 +70,10 @@ struct timeval *pri_schedule_next(struct pri *pri)
return closest;
}
int pri_schedule_run(struct pri *pri)
pri_event *pri_schedule_run(struct pri *pri)
{
struct timeval tv;
int x;
int p = 0;
void (*callback)(void *);
void *data;
gettimeofday(&tv, NULL);
@@ -81,15 +82,17 @@ int pri_schedule_run(struct pri *pri)
((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->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;
}
void pri_schedule_del(struct pri *pri,int id)

346
pritest.c Normal file
View File

@@ -0,0 +1,346 @@
/*
* 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 <linux/zaptel.h>
#include <zap.h>
#include "libpri.h"
#define PRI_DEF_NODETYPE PRI_CPE
#define PRI_DEF_SWITCHTYPE PRI_SWITCH_NI2
#define MAX_CHAN 32
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;
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 void start_channel(struct pri *pri, pri_event *e)
{
int channo = e->ring.channel;
/* 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 */
pri_answer(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;
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;
}
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;
}

231
q921.c Executable file → Normal file
View File

@@ -32,6 +32,15 @@
#include "pri_q921.h"
#include "pri_q931.h"
/*
* Define RANDOM_DROPS To randomly drop packets in order to simulate loss for testing
* retransmission functionality
*/
/*
#define RANDOM_DROPS
*/
#define Q921_INIT(hf) do { \
(hf).h.sapi = 0; \
(hf).h.ea1 = 0; \
@@ -54,6 +63,13 @@ static void q921_discard_retransmissions(struct pri *pri)
static int q921_transmit(struct pri *pri, q921_h *h, int len) {
int res;
#ifdef RANDOM_DROPS
if (!(random() % 3)) {
printf(" === Dropping Packet ===\n");
return 0;
}
#endif
/* Just send it raw */
if (pri->debug & PRI_DEBUG_Q921_DUMP)
q921_dump(h, len, pri->debug & PRI_DEBUG_Q921_RAW, 1);
@@ -66,7 +82,6 @@ static int q921_transmit(struct pri *pri, q921_h *h, int len) {
return 0;
}
static void q921_send_ua(struct pri *pri, int pfbit)
{
q921_h h;
@@ -99,8 +114,8 @@ static void q921_send_sabme(void *vpri)
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 */
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) {
@@ -118,7 +133,6 @@ static void q921_send_sabme(void *vpri)
printf("Sending Set Asynchronous Balanced Mode Extended\n");
q921_transmit(pri, &h, 3);
pri->q921_state = Q921_AWAITING_ESTABLISH;
}
static int q921_ack_packet(struct pri *pri, int num)
@@ -159,9 +173,9 @@ static void q921_ack_rx(struct pri *pri, int ack)
/* Cancel each packet as necessary */
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");
printf("-- 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;
@@ -186,6 +200,31 @@ static void q921_ack_rx(struct pri *pri, int ack)
}
}
static void q921_reject(struct pri *pri)
{
q921_h h;
Q921_INIT(h);
h.s.x0 = 0; /* Always 0 */
h.s.ss = 2; /* Reject */
h.s.ft = 1; /* Frametype (01) */
h.s.n_r = pri->v_r; /* Where to start retransmission */
h.s.p_f = 1; /* XXX Should it always be set to 1? XXX */
switch(pri->localtype) {
case PRI_NETWORK:
h.h.c_r = 0;
break;
case PRI_CPE:
h.h.c_r = 1;
break;
default:
fprintf(stderr, "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 Reject (%d)\n", pri->v_r);
q921_transmit(pri, &h, 4);
}
static void q921_rr(struct pri *pri, int pbit) {
q921_h h;
Q921_INIT(h);
@@ -211,13 +250,15 @@ static void q921_rr(struct pri *pri, int pbit) {
q921_transmit(pri, &h, 4);
}
static pri_event *q921_dchannel_down(struct pri *pri);
static void t200_expire(void *vpri)
{
struct pri *pri = vpri;
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);
printf("-- T200 counter expired, What to do...\n");
/* Force Poll bit */
pri->txqueue->h.p_f = 1;
/* Update nr */
@@ -225,11 +266,28 @@ 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)
printf("-- Retransmitting %d bytes\n", pri->txqueue->len);
q921_transmit(pri, (q921_h *)&pri->txqueue->h, pri->txqueue->len);
if (pri->debug & PRI_DEBUG_Q921_STATE)
printf("-- 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)
printf("-- Timeout occured, restarting PRI\n");
pri->state = Q921_LINK_CONNECTION_RELEASED;
pri->t200_timer = 0;
q921_dchannel_down(pri);
q921_start(pri);
pri->schedev = 1;
}
} else {
fprintf(stderr, "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)
@@ -294,7 +352,7 @@ 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");
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);
@@ -330,7 +388,7 @@ static pri_event *q921_handle_iframe(struct pri *pri, q921_i *i, int len)
/* 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);
q921_reject(pri);
#if 0
q931_reject(pri);
#endif
@@ -341,36 +399,41 @@ 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 ? '>' : '<'));
printf("\n%c [", direction_tag);
for (x=0;x<len;x++)
printf("%02x ",h->raw[x]);
printf("]\n");
printf("]");
}
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");
printf("\n%c Informational frame:\n", direction_tag);
break;
case 1:
printf("\n Supervisory frame:\n");
printf("\n%c Supervisory frame:\n", direction_tag);
break;
case 3:
printf("\n Unnumbered frame:\n");
printf("\n%c Unnumbered frame:\n", direction_tag);
break;
}
printf(
"%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 */
@@ -378,42 +441,85 @@ void q921_dump(q921_h *h, int len, int showraw, int txrx)
"%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 */
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;
}
printf(
"%c Zeros: %d S: %d 01: %d\n"
"%c N(R): %03d P/F: %d\n"
"%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 */
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;
}
}
printf(
"%c M3: %d P/F: %d M2: %d 11: %d\n"
"%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;
};
@@ -473,6 +579,7 @@ void q921_reset(struct pri *pri)
pri_event *q921_receive(struct pri *pri, q921_h *h, int len)
{
q921_frame *f;
/* Discard FCS */
len -= 2;
@@ -482,7 +589,15 @@ pri_event *q921_receive(struct pri *pri, q921_h *h, int len)
/* Check some reject conditions -- Start by rejecting improper ea's */
if (h->h.ea1 || !(h->h.ea2))
return NULL;
/* Check for broadcasts - not yet handled */
if (h->h.tei == Q921_TEI_GROUP)
return NULL;
/* Check for SAPIs we don't yet handle */
if (h->h.sapi != Q921_SAPI_CALL_CTRL)
return NULL;
switch(h->h.data[0] & Q921_FRAMETYPE_MASK) {
case 0:
case 2:
@@ -525,8 +640,57 @@ pri_event *q921_receive(struct pri *pri, q921_h *h, int len)
pri->solicitfbit = 0;
}
break;
#if 0
case 1:
/* Receiver not ready */
if (pri->debug & PRI_DEBUG_Q921_STATE)
printf("-- Got receiver not ready\n");
pri->busy = 1;
break;
#endif
case 2:
/* Just retransmit */
if (pri->debug & PRI_DEBUG_Q921_STATE)
printf("-- 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);
}
/* Resend the proper I-frame */
for(f=pri->txqueue;f;f=f->next) {
if (f->h.n_s == h->s.n_r) {
/* Matches the request */
break;
}
}
if (f) {
/* Retransmit the requested frame */
q921_transmit(pri, (q921_h *)(&f->h), f->len);
} else {
if (pri->txqueue) {
/* This should never happen */
if (!h->s.p_f || h->s.n_r) {
fprintf(stderr, "!! 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->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");
fprintf(stderr, "!! 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:
@@ -620,4 +784,3 @@ void q921_start(struct pri *pri)
/* Do the SABME XXX Maybe we should implement T_WAIT? XXX */
q921_send_sabme(pri);
}

848
q931.c Executable file → Normal file

File diff suppressed because it is too large Load Diff