Compare commits

...

10 Commits
0.2.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
14 changed files with 881 additions and 112 deletions

4
ChangeLog Executable file → Normal file
View File

@@ -1,3 +1,7 @@
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

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

59
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
@@ -50,20 +50,47 @@
#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_HANGUP_ACK 9 /* Call hangup has been acknowledged */
#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
@@ -119,12 +146,12 @@
#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_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_MANDATORY_IE_LENGTH_ERROR 103
#define PRI_CAUSE_PROTOCOL_ERROR 111
#define PRI_CAUSE_INTERWORKING 127
@@ -137,9 +164,9 @@
#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_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

0
pri.c Executable file → Normal file
View File

0
pri_internal.h Executable file → Normal file
View File

0
pri_q921.h Executable file → Normal file
View File

2
pri_q931.h Executable file → Normal file
View File

@@ -234,5 +234,5 @@ 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 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;
}

0
prisched.c Executable file → Normal file
View File

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;
}

128
q921.c Executable file → Normal file
View File

@@ -82,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;
@@ -115,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) {
@@ -134,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)
@@ -177,7 +175,7 @@ static void q921_ack_rx(struct pri *pri, int ack)
cnt += q921_ack_packet(pri, x);
if (!pri->txqueue) {
if (pri->debug & PRI_DEBUG_Q921_STATE)
printf("-- Since there wis nothing left, 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;
@@ -202,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);
@@ -329,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);
@@ -365,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
@@ -376,37 +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 */
@@ -414,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;
};
@@ -509,7 +579,7 @@ void q921_reset(struct pri *pri)
pri_event *q921_receive(struct pri *pri, q921_h *h, int len)
{
q921_frame *f;
q921_frame *f;
/* Discard FCS */
len -= 2;

317
q931.c Executable file → Normal file
View File

@@ -45,6 +45,7 @@ struct msgtype msgs[] = {
{ Q931_CONNECT_ACKNOWLEDGE, "CONNECT ACKNOWLEDGE" },
{ Q931_PROGRESS, "PROGRESS" },
{ Q931_SETUP, "SETUP" },
{ Q931_SETUP_ACKNOWLEDGE, "SETUP ACKNOWLEDGE" },
/* Call disestablishment messages */
{ Q931_DISCONNECT, "DISCONNECT" },
@@ -93,25 +94,38 @@ struct msgtype causes[] = {
{ PRI_CAUSE_NO_USER_RESPONSE, "No user responding" },
{ PRI_CAUSE_NO_ANSWER, "User alerting, no answer" },
{ PRI_CAUSE_CALL_REJECTED, "Call Rejected" },
{ PRI_CAUSE_NUMBER_CHANGED, "Number changed" },
{ PRI_CAUSE_DESTINATION_OUT_OF_ORDER, "Destination out of order" },
{ PRI_CAUSE_INVALID_NUMBER_FORMAT, "Invalid number format" },
{ PRI_CAUSE_FACILITY_REJECTED, "Facility rejected" },
{ PRI_CAUSE_RESPONSE_TO_STATUS_ENQUIRY, "Response to STATus ENQuiry" },
{ PRI_CAUSE_NORMAL_UNSPECIFIED, "Normal, unspecified" },
{ PRI_CAUSE_NORMAL_CIRCUIT_CONGESTION, "Circuit/channel congestion" },
{ PRI_CAUSE_NETWORK_OUT_OF_ORDER, "Network out of order" },
{ PRI_CAUSE_NORMAL_TEMPORARY_FAILURE, "Temporary failure" },
{ PRI_CAUSE_SWITCH_CONGESTION, "Switching equipment congestion" },
{ PRI_CAUSE_ACCESS_INFO_DISCARDED, "Access information discarded" },
{ PRI_CAUSE_REQUESTED_CHAN_UNAVAIL, "Requested channel not available" },
{ PRI_CAUSE_PRE_EMPTED, "Pre-empted" },
{ PRI_CAUSE_FACILITY_NOT_SUBSCRIBED, "Facility not subscribed" },
{ PRI_CAUSE_OUTGOING_CALL_BARRED, "Outgoing call barred" },
{ PRI_CAUSE_INCOMING_CALL_BARRED, "Incoming call barred" },
{ PRI_CAUSE_BEARERCAPABILITY_NOTAUTH, "Bearer capability not authorized" },
{ PRI_CAUSE_BEARERCAPABILITY_NOTAVAIL, "Bearer capability not available" },
{ PRI_CAUSE_BEARERCAPABILITY_NOTIMPL, "Bearer capability not implemented" },
{ PRI_CAUSE_CHAN_NOT_IMPLEMENTED, "Channel not implemented" },
{ PRI_CAUSE_FACILITY_NOT_IMPLEMENTED, "Facility not implemented" },
{ PRI_CAUSE_INVALID_CALL_REFERENCE, "Invalid call reference value" },
{ PRI_CAUSE_INCOMPATIBLE_DESTINATION, "Incompatible destination" },
{ PRI_CAUSE_INVALID_MSG_UNSPECIFIED, "Invalid message unspecified" },
{ PRI_CAUSE_MANDATORY_IE_MISSING, "Mandatory information element is missing" },
{ PRI_CAUSE_MESSAGE_TYPE_NONEXIST, "Message type nonexist." },
{ PRI_CAUSE_WRONG_MESSAGE, "Wrong message" },
{ PRI_CAUSE_IE_NONEXIST, "Info. element nonexist or not implemented" },
{ PRI_CAUSE_INVALID_IE_CONTENTS, "Invalid information element contents" },
{ PRI_CAUSE_WRONG_CALL_STATE, "Message not compatible with call state" },
{ PRI_CAUSE_RECOVERY_ON_TIMER_EXPIRE, "Recover on timer expiry" },
{ PRI_CAUSE_MANDATORY_IE_LENGTH_ERROR, "Mandatory IE length error" },
{ PRI_CAUSE_PROTOCOL_ERROR, "Protocol error, unspecified" },
{ PRI_CAUSE_INTERWORKING, "Interworking, unspecified" },
};
@@ -141,11 +155,15 @@ struct msgtype causes[] = {
#define PRI_TRANS_CAP_AUDIO_4ESS 0x08
#define Q931_CALL_NOT_E2E_ISDN 0x1
#define Q931_CALLED_NOT_ISDN 0x2
#define Q931_CALLER_NOT_ISDN 0x3
#define Q931_INBAND_AVAILABLE 0x8
#define Q931_DELAY_AT_INTERF 0xa
#define Q931_PROG_CALL_NOT_E2E_ISDN 0x011
#define Q931_PROG_CALLED_NOT_ISDN 0x02
#define Q931_PROG_CALLER_NOT_ISDN 0x03
#define Q931_PROG_INBAND_AVAILABLE 0x08
#define Q931_PROG_DELAY_AT_INTERF 0x0a
#define Q931_PROG_INTERWORKING_WITH_PUBLIC 0x10
#define Q931_PROG_INTERWORKING_NO_RELEASE 0x11
#define Q931_PROG_INTERWORKING_NO_RELEASE_PRE_ANSWER 0x12
#define Q931_PROG_INTERWORKING_NO_RELEASE_POST_ANSWER 0x13
#define CODE_CCITT 0x0
#define CODE_INTERNATIONAL 0x1
@@ -163,6 +181,7 @@ struct msgtype causes[] = {
struct q931_call {
int cr; /* Call Reference */
int forceinvert; /* Force inversion of call number even if 0 */
q931_call *next;
/* Slotmap specified (bitmap of channels 31/24-1) (Channel Identifier IE) (-1 means not specified) */
int slotmap;
@@ -174,7 +193,7 @@ struct q931_call {
int chanflags;
int alive; /* Whether or not the call is alive */
int sendhangupack; /* Whether or not to send a hangup ack */
int sendhangupack; /* Whether or not to send a hangup ack */
int proc; /* Whether we've sent a call proceeding / alerting */
int ri; /* Restart Indicator (Restart Indicator IE) */
@@ -234,6 +253,7 @@ static void call_init(struct q931_call *c)
memset(c, 0, sizeof(*c));
c->alive = 0;
c->sendhangupack = 0;
c->forceinvert = -1;
c->cr = -1;
c->slotmap = -1;
c->channelno = -1;
@@ -321,11 +341,9 @@ static int transmit_channel_id(struct pri *pri, q931_call *call, int msgtype, q9
if (call->ds1no > -1) {
/* Note that we are specifying the identifier */
ie->data[pos] |= 0x40;
pos++;
ie->data[pos++] |= 0x40;
/* We need to use the Channel Identifier Present thingy. Just specify it and we're done */
ie->data[pos] = 0x80 | call->ds1no;
pos++;
ie->data[pos++] = 0x80 | call->ds1no;
} else
pos++;
if ((call->channelno > -1) || (call->slotmap != -1)) {
@@ -358,7 +376,7 @@ static void dump_channel_id(q931_ie *ie, int len, char prefix)
int pos=0;
int x;
int res = 0;
printf("%c Channel ID len = %d [ Ext: %d IntID: %s, %s Spare: %d, %s Dchan: %d, ChanSel: %d \n",
printf("%c Channel ID (len=%2d) [ Ext: %d IntID: %s, %s Spare: %d, %s Dchan: %d, ChanSel: %d \n",
prefix, len, (ie->data[0] & 0x80) ? 1 : 0, (ie->data[0] & 0x40) ? "Explicit" : "Implicit",
(ie->data[0] & 0x20) ? "PRI" : "Other", (ie->data[0] & 0x10) ? 1 : 0,
(ie->data[0] & 0x08) ? "Exclusive" : "Preferred", (ie->data[0] & 0x04) ? 1 : 0,
@@ -367,7 +385,7 @@ static void dump_channel_id(q931_ie *ie, int len, char prefix)
len--;
if (ie->data[0] & 0x40) {
/* Explicitly defined DS1 */
printf("%c Ext: %d DS1 Identifier: %d \n", prefix, (ie->data[pos] & 0x80) >> 7, ie->data[pos] & 0x7f);
printf("%c Ext: %d DS1 Identifier: %d \n", prefix, (ie->data[pos] & 0x80) >> 7, ie->data[pos] & 0x7f);
pos++;
len--;
} else {
@@ -375,13 +393,13 @@ static void dump_channel_id(q931_ie *ie, int len, char prefix)
}
if (pos < len) {
/* Still more information here */
printf("%c Ext: %d Coding: %d %s Specified Channel Type: %d\n",
printf("%c Ext: %d Coding: %d %s Specified Channel Type: %d\n",
prefix, (ie->data[pos] & 0x80) >> 7, (ie->data[pos] & 60) >> 5,
(ie->data[pos] & 0x10) ? "Slot Map" : "Number", ie->data[pos] & 0x0f);
if (!(ie->data[pos] & 0x10)) {
/* Number specified */
pos++;
printf("%c Ext: %d Channel: %d ]\n", prefix, (ie->data[pos] & 0x80) >> 7,
printf("%c Ext: %d Channel: %d ]\n", prefix, (ie->data[pos] & 0x80) >> 7,
(ie->data[pos]) & 0x7f);
} else {
pos++;
@@ -438,6 +456,20 @@ static int transmit_restart_indicator(struct pri *pri, q931_call *call, int msgt
return 3;
}
static char *redirection_reason2str(int mode)
{
static struct msgtype modes[] = {
{ PRI_REDIR_UNKNOWN, "Unknown" },
{ PRI_REDIR_FORWARD_ON_BUSY, "Forwarded on busy" },
{ PRI_REDIR_FORWARD_ON_NO_REPLY, "Forwarded on no reply" },
{ PRI_REDIR_DEFLECTION, "Call deflected" },
{ PRI_REDIR_DTE_OUT_OF_ORDER, "Called DTE out of order" },
{ PRI_REDIR_FORWARDED_BY_DTE, "Forwarded by called DTE" },
{ PRI_REDIR_UNCONDITIONAL, "Forwarded unconditionally" },
};
return code2str(mode, modes, sizeof(modes) / sizeof(modes[0]));
}
static char *cap2str(int mode)
{
static struct msgtype modes[] = {
@@ -509,11 +541,11 @@ static char *l32str(int proto)
static void dump_bearer_capability(q931_ie *ie, int len, char prefix)
{
int pos=2;
printf("%c Bearer Capability: [ Ext: %d Q.931 Std: %d Info transfer capability: %d (%s)\n",
prefix, (ie->data[0] & 0x80 ) >> 7, (ie->data[0] & 0x60) >> 5, (ie->data[0] & 0x1f), cap2str(ie->data[0] & 0x1f));
printf("%c Ext: %d Trans Mode/Rate: %d (%s)\n", prefix, (ie->data[1] & 0x80) >> 7, ie->data[1] & 0x7f, mode2str(ie->data[1] & 0x7f));
printf("%c Bearer Capability (len=%2d) [ Ext: %d Q.931 Std: %d Info transfer capability: %s (%d)\n",
prefix, ie->len, (ie->data[0] & 0x80 ) >> 7, (ie->data[0] & 0x60) >> 5, cap2str(ie->data[0] & 0x1f), (ie->data[0] & 0x1f));
printf("%c Ext: %d Trans mode/rate: %s (%d)\n", prefix, (ie->data[1] & 0x80) >> 7, mode2str(ie->data[1] & 0x7f), ie->data[1] & 0x7f);
if ((ie->data[1] & 0x7f) == 0x18) {
printf("%c Ext: %d Transfer Rate Multiplier: %d x 64\n", prefix, (ie->data[2] & 0x80) >> 7, ie->data[2] & 0x7f);
printf("%c Ext: %d Transfer rate multiplier: %d x 64\n", prefix, (ie->data[2] & 0x80) >> 7, ie->data[2] & 0x7f);
pos++;
}
/* Stop here if no more */
@@ -521,15 +553,15 @@ static void dump_bearer_capability(q931_ie *ie, int len, char prefix)
return;
if ((ie->data[1] & 0x7f) != TRANS_MODE_PACKET) {
/* Look for octets 5 and 5.a if present */
printf("%c Ext: %d User Information Layer 1: %d (%s)\n", prefix, (ie->data[pos] >> 7), ie->data[pos] & 0x7f,l12str(ie->data[pos] & 0x7f));
printf("%c Ext: %d User information layer 1: %s (%d)\n", prefix, (ie->data[pos] >> 7), l12str(ie->data[pos] & 0x7f), ie->data[pos] & 0x7f);
if ((ie->data[pos] & 0x7f) == PRI_LAYER_1_ITU_RATE_ADAPT)
printf("%c Ext: %d Rate Adaptatation: %d (%s)\n", prefix, ie->data[pos] >> 7, ie->data[pos] & 0x7f, ra2str(ie->data[pos] & 0x7f));
printf("%c Ext: %d Rate adaptatation: %s (%d)\n", prefix, ie->data[pos] >> 7, ra2str(ie->data[pos] & 0x7f), ie->data[pos] & 0x7f);
pos++;
} else {
/* Look for octets 6 and 7 but not 5 and 5.a */
printf("%c Ext: %d User Information Layer 2: %d (%s)\n", prefix, ie->data[pos] >> 7, ie->data[pos] & 0x7f, l22str(ie->data[pos] & 0x7f));
printf("%c Ext: %d User information layer 2: %s (%d)\n", prefix, ie->data[pos] >> 7, l22str(ie->data[pos] & 0x7f), ie->data[pos] & 0x7f);
pos++;
printf("%c Ext: %d User Information Layer 3: %d (%s)\n", prefix, ie->data[pos] >> 7, ie->data[pos] & 0x7f, l32str(ie->data[pos] & 0x7f));
printf("%c Ext: %d User information layer 3: %s (%d)\n", prefix, ie->data[pos] >> 7, l32str(ie->data[pos] & 0x7f), ie->data[pos] & 0x7f);
pos++;
}
}
@@ -599,6 +631,43 @@ char *pri_plan2str(int plan)
return code2str(plan, plans, sizeof(plans) / sizeof(plans[0]));
}
static char *npi2str(int plan)
{
static struct msgtype plans[] = {
{ PRI_NPI_UNKNOWN, "Unknown Number Plan" },
{ PRI_NPI_E163_E164, "ISDN/Telephony Numbering Plan (E.164/E.163)" },
{ PRI_NPI_X121, "Data Numbering Plan (X.121)" },
{ PRI_NPI_F69, "Telex Numbering Plan (F.69)" },
{ PRI_NPI_NATIONAL, "National Standard Numbering Plan" },
{ PRI_NPI_PRIVATE, "Private Numbering Plan" },
{ PRI_NPI_RESERVED, "Reserved Number Plan" },
};
return code2str(plan, plans, sizeof(plans) / sizeof(plans[0]));
}
static char *ton2str(int plan)
{
static struct msgtype plans[] = {
{ PRI_TON_UNKNOWN, "Unknown Number Type" },
{ PRI_TON_INTERNATIONAL, "International Number" },
{ PRI_TON_NATIONAL, "National Number" },
{ PRI_TON_NET_SPECIFIC, "Network Specific Number" },
{ PRI_TON_SUBSCRIBER, "Subscriber Number" },
{ PRI_TON_ABBREVIATED, "Abbreviated number" },
{ PRI_TON_RESERVED, "Reserved Number" },
};
return code2str(plan, plans, sizeof(plans) / sizeof(plans[0]));
}
static char *subaddrtype2str(int plan)
{
static struct msgtype plans[] = {
{ 0, "NSAP (X.213/ISO 8348 AD2)" },
{ 2, "User Specified" },
};
return code2str(plan, plans, sizeof(plans) / sizeof(plans[0]));
}
char *pri_pres2str(int pres)
{
static struct msgtype press[] = {
@@ -627,20 +696,58 @@ static void q931_get_number(unsigned char *num, int maxlen, unsigned char *src,
static void dump_called_party_number(q931_ie *ie, int len, char prefix)
{
char cnum[256];
q931_get_number(cnum, sizeof(cnum), ie->data + 1, len - 3);
printf("%c Called Number len = %d: [ Ext: %d Type: %s (%d) '%s' ]\n", prefix, len, ie->data[0] >> 7, pri_plan2str(ie->data[0] & 0x7f), ie->data[0] & 0x7f, cnum);
printf("%c Called Number (len=%2d) [ Ext: %d TON: %s (%d) NPI: %s (%d) '%s' ]\n",
prefix, len, ie->data[0] >> 7, ton2str((ie->data[0] >> 4) & 0x07), (ie->data[0] >> 4) & 0x07, npi2str(ie->data[0] & 0x0f), ie->data[0] & 0x0f, cnum);
}
static void dump_called_party_subaddr(q931_ie *ie, int len, char prefix)
{
char cnum[256];
q931_get_number(cnum, sizeof(cnum), ie->data + 1, len - 3);
printf("%c Called Sub-Address (len=%2d) [ Ext: %d Type: %s (%d) O: %d '%s' ]\n",
prefix, len, ie->data[0] >> 7,
subaddrtype2str((ie->data[0] & 0x70) >> 4), (ie->data[0] & 0x70) >> 4,
(ie->data[0] & 0x08) >> 3, cnum);
}
static void dump_calling_party_number(q931_ie *ie, int len, char prefix)
{
char cnum[256];
q931_get_number(cnum, sizeof(cnum), ie->data + 2, len - 4);
printf("%c Calling Number len = %d: [ Ext: %d Type: %s (%d) ", prefix, len, ie->data[0] >> 7, pri_plan2str(ie->data[0] & 0x7f), ie->data[0] & 0x7f);
printf("%c Presentation: %s (%d) '%s' ]\n", prefix, pri_pres2str(ie->data[1]), ie->data[1] & 0x7f, cnum);
printf("%c Calling Number (len=%2d) [ Ext: %d TON: %s (%d) NPI: %s (%d)\n", prefix, len, ie->data[0] >> 7, ton2str((ie->data[0] >> 4) & 0x07), (ie->data[0] >> 4) & 0x07, npi2str(ie->data[0] & 0x0f), ie->data[0] & 0x0f);
printf("%c Presentation: %s (%d) '%s' ]\n", prefix, pri_pres2str(ie->data[1]), ie->data[1] & 0x7f, cnum);
}
static void dump_calling_party_subaddr(q931_ie *ie, int len, char prefix)
{
char cnum[256];
q931_get_number(cnum, sizeof(cnum), ie->data + 2, len - 4);
printf("%c Calling Sub-Address (len=%2d) [ Ext: %d Type: %s (%d) O: %d '%s' ]\n",
prefix, len, ie->data[0] >> 7,
subaddrtype2str((ie->data[0] & 0x70) >> 4), (ie->data[0] & 0x70) >> 4,
(ie->data[0] & 0x08) >> 3, cnum);
}
static void dump_redirecting_number(q931_ie *ie, int len, char prefix)
{
char cnum[256];
q931_get_number(cnum, sizeof(cnum), ie->data + 3, len - 5);
printf("%c Redirecting Number (len=%2d) [ Ext: %d TON: %s (%d) NPI: %s (%d)\n", prefix, len, ie->data[0] >> 7, ton2str((ie->data[0] >> 4) & 0x07), (ie->data[0] >> 4) & 0x07, npi2str(ie->data[0] & 0x0f), ie->data[0] & 0x0f);
printf("%c Presentation: %s (%d) Reason: %s (%d) '%s' ]\n", prefix, pri_pres2str(ie->data[1]), ie->data[1] & 0x7f, redirection_reason2str(ie->data[2]), ie->data[2], cnum);
}
static void dump_redirecting_subaddr(q931_ie *ie, int len, char prefix)
{
char cnum[256];
q931_get_number(cnum, sizeof(cnum), ie->data + 2, len - 4);
printf("%c Redirecting Sub-Address (len=%2d) [ Ext: %d Type: %s (%d) O: %d '%s' ]\n",
prefix, len, ie->data[0] >> 7,
subaddrtype2str((ie->data[0] & 0x70) >> 4), (ie->data[0] & 0x70) >> 4,
(ie->data[0] & 0x08) >> 3, cnum);
}
static int receive_called_party_number(struct pri *pri, q931_call *call, int msgtype, q931_ie *ie, int len)
{
@@ -677,11 +784,15 @@ static int transmit_calling_party_number(struct pri *pri, q931_call *call, int m
static char *prog2str(int prog)
{
static struct msgtype progs[] = {
{ Q931_CALL_NOT_E2E_ISDN, "Call is not end-to-end ISDN; further call progress information may be available inband." },
{ Q931_CALLED_NOT_ISDN, "Called equipment is non-ISDN." },
{ Q931_CALLER_NOT_ISDN, "Calling equipment is non-ISDN." },
{ Q931_INBAND_AVAILABLE, "Inband information or appropriate pattern now available." },
{ Q931_DELAY_AT_INTERF, "Delay in response at called Interface." },
{ Q931_PROG_CALL_NOT_E2E_ISDN, "Call is not end-to-end ISDN; further call progress information may be available inband." },
{ Q931_PROG_CALLED_NOT_ISDN, "Called equipment is non-ISDN." },
{ Q931_PROG_CALLER_NOT_ISDN, "Calling equipment is non-ISDN." },
{ Q931_PROG_INBAND_AVAILABLE, "Inband information or appropriate pattern now available." },
{ Q931_PROG_DELAY_AT_INTERF, "Delay in response at called Interface." },
{ Q931_PROG_INTERWORKING_WITH_PUBLIC, "Interworking with a public network." },
{ Q931_PROG_INTERWORKING_NO_RELEASE, "Interworking with a network unable to supply a release signal." },
{ Q931_PROG_INTERWORKING_NO_RELEASE_PRE_ANSWER, "Interworking with a network unable to supply a release signal before answer." },
{ Q931_PROG_INTERWORKING_NO_RELEASE_POST_ANSWER, "Interworking with a network unable to supply a release signal after answer." },
};
return code2str(prog, progs, sizeof(progs) / sizeof(progs[0]));
}
@@ -714,17 +825,17 @@ static char *loc2str(int loc)
static void dump_progress_indicator(q931_ie *ie, int len, char prefix)
{
printf("%c Progress Indicator len = %d [ Ext: %d Coding standard: %s (%d) 0: %d Location: %s (%d)\n",
prefix, ie->len, ie->data[0] >> 7, coding2str((ie->data[0] & 0x6) >> 5), (ie->data[0] & 0x6) >> 5,
printf("%c Progress Indicator (len=%2d) [ Ext: %d Coding: %s (%d) 0: %d Location: %s (%d)\n",
prefix, ie->len, ie->data[0] >> 7, coding2str((ie->data[0] & 0x60) >> 5), (ie->data[0] & 0x60) >> 5,
(ie->data[0] & 0x10) >> 4, loc2str(ie->data[0] & 0xf), ie->data[0] & 0xf);
printf("%c Ext: %d Progress Description: %s (%d) ]\n",
printf("%c Ext: %d Progress Description: %s (%d) ]\n",
prefix, ie->data[1] >> 7, prog2str(ie->data[1] & 0x7f), ie->data[1] & 0x7f);
}
static int receive_progress_indicator(struct pri *pri, q931_call *call, int msgtype, q931_ie *ie, int len)
{
call->progloc = ie->data[0] & 0xf;
call->progcode = (ie->data[0] & 0x6) >> 5;
call->progcode = (ie->data[0] & 0x60) >> 5;
call->progress = (ie->data[1] & 0x7f);
return 0;
}
@@ -741,6 +852,75 @@ static int transmit_progress_indicator(struct pri *pri, q931_call *call, int msg
}
}
static char *callstate2str(int callstate)
{
static struct msgtype callstates[] = {
{ 0, "Null" },
{ 1, "Call Initiated" },
{ 2, "Overlap sending" },
{ 3, "Outgoing call Proceeding" },
{ 4, "Call Delivered" },
{ 6, "Call Present" },
{ 7, "Call Received" },
{ 8, "Connect Request" },
{ 9, "Incoming Call Proceeding" },
{ 10, "Active" },
{ 11, "Disconnect Request" },
{ 12, "Disconnect Indication" },
{ 15, "Suspend Request" },
{ 17, "Resume Request" },
{ 19, "Release Request" },
{ 22, "Call Abort" },
{ 25, "Overlap Receiving" },
{ 61, "Restart Request" },
{ 62, "Restart" },
};
return code2str(callstate, callstates, sizeof(callstates) / sizeof(callstates[0]));
}
static void dump_call_state(q931_ie *ie, int len, char prefix)
{
printf("%c Call State (len=%2d) [ Ext: %d Coding: %s (%d) Call state: %s (%d)\n",
prefix, ie->len, ie->data[0] >> 7, coding2str((ie->data[0] & 0xC0) >> 6), (ie->data[0] & 0xC0) >> 6,
callstate2str(ie->data[0] & 0x3f), ie->data[0] & 0x3f);
}
static void dump_call_identity(q931_ie *ie, int len, char prefix)
{
int x;
printf("%c Call Identity (len=%2d) [ ", prefix, ie->len);
for (x=0;x<ie->len;x++)
printf("0x%02X ", ie->data[x]);
printf(" ]\n");
}
static void dump_time_date(q931_ie *ie, int len, char prefix)
{
printf("%c Time Date (len=%2d) [ ", prefix, ie->len);
if (ie->len > 0)
printf("%02d", ie->data[0]);
if (ie->len > 1)
printf("-%02d", ie->data[1]);
if (ie->len > 2)
printf("-%02d", ie->data[2]);
if (ie->len > 3)
printf(" %02d", ie->data[3]);
if (ie->len > 4)
printf(":%02d", ie->data[4]);
if (ie->len > 5)
printf(":%02d", ie->data[5]);
printf(" ]\n");
}
static void dump_display(q931_ie *ie, int len, char prefix)
{
int x;
printf("%c Call Identity (len=%2d) [ ", prefix, ie->len);
for (x=0;x<ie->len;x++)
printf("%c", ie->data[x] & 0x7f);
printf(" ]\n");
}
char *pri_cause2str(int cause)
{
return code2str(cause, causes, sizeof(causes) / sizeof(causes[0]));
@@ -764,10 +944,10 @@ static char *pri_causeclass2str(int cause)
static void dump_cause(q931_ie *ie, int len, char prefix)
{
int x;
printf("%c Cause len = %d [ Ext: %d Coding standard: %s (%d) 0: %d Location: %s (%d)\n",
prefix, ie->len, ie->data[0] >> 7, coding2str((ie->data[0] & 0x6) >> 5), (ie->data[0] & 0x6) >> 5,
printf("%c Cause (len=%2d) [ Ext: %d Coding: %s (%d) 0: %d Location: %s (%d)\n",
prefix, ie->len, ie->data[0] >> 7, coding2str((ie->data[0] & 0x60) >> 5), (ie->data[0] & 0x60) >> 5,
(ie->data[0] & 0x10) >> 4, loc2str(ie->data[0] & 0xf), ie->data[0] & 0xf);
printf("%c Ext: %d Cause: %s (%d), class = %s (%d) ]\n",
printf("%c Ext: %d Cause: %s (%d), class = %s (%d) ]\n",
prefix, (ie->data[1] >> 7), pri_cause2str(ie->data[1] & 0x7f), ie->data[1] & 0x7f,
pri_causeclass2str((ie->data[1] & 0x7f) >> 4), (ie->data[1] & 0x7f) >> 4);
for (x=4;x<len;x++)
@@ -777,17 +957,11 @@ static void dump_cause(q931_ie *ie, int len, char prefix)
static int receive_cause(struct pri *pri, q931_call *call, int msgtype, q931_ie *ie, int len)
{
call->causeloc = ie->data[0] & 0xf;
call->causecode = (ie->data[0] & 0x6) >> 5;
call->causecode = (ie->data[0] & 0x60) >> 5;
call->cause = (ie->data[1] & 0x7f);
return 0;
}
static int receive_sending_complete(struct pri *pri, q931_call *call, int msgtype, q931_ie *ie, int len)
{
/* Do nothing */
return 0;
}
static int transmit_cause(struct pri *pri, q931_call *call, int msgtype, q931_ie *ie, int len)
{
if (call->cause > 0) {
@@ -800,6 +974,17 @@ static int transmit_cause(struct pri *pri, q931_call *call, int msgtype, q931_ie
}
}
static void dump_sending_complete(q931_ie *ie, int len, char prefix)
{
printf("%c Sending Complete (len=%2d)\n", prefix, ie->len);
}
static int receive_sending_complete(struct pri *pri, q931_call *call, int msgtype, q931_ie *ie, int len)
{
/* Do nothing */
return 0;
}
static int transmit_sending_complete(struct pri *pri, q931_call *call, int msgtype, q931_ie *ie, int len)
{
if ((pri->switchtype == PRI_SWITCH_EUROISDN_E1) || (pri->switchtype == PRI_SWITCH_EUROISDN_T1)) {
@@ -815,7 +1000,7 @@ struct ie ies[] = {
{ Q931_LOCKING_SHIFT, "Locking Shift" },
{ Q931_BEARER_CAPABILITY, "Bearer Capability", dump_bearer_capability, receive_bearer_capability, transmit_bearer_capability },
{ Q931_CAUSE, "Cause", dump_cause, receive_cause, transmit_cause },
{ Q931_CALL_STATE, "Call State" },
{ Q931_CALL_STATE, "Call State", dump_call_state },
{ Q931_CHANNEL_IDENT, "Channel Identification", dump_channel_id, receive_channel_id, transmit_channel_id },
{ Q931_PROGRESS_INDICATOR, "Progress Indicator", dump_progress_indicator, receive_progress_indicator, transmit_progress_indicator },
{ Q931_NETWORK_SPEC_FAC, "Network-Specific Facilities" },
@@ -827,11 +1012,11 @@ struct ie ies[] = {
{ Q931_CLOSED_USER_GROUP, "Closed User Group" },
{ Q931_REVERSE_CHARGE_INDIC, "Reverse Charging Indication" },
{ Q931_CALLING_PARTY_NUMBER, "Calling Party Number", dump_calling_party_number, receive_calling_party_number, transmit_calling_party_number },
{ Q931_CALLING_PARTY_SUBADDR, "Calling Party Subaddress" },
{ Q931_CALLING_PARTY_SUBADDR, "Calling Party Subaddress", dump_calling_party_subaddr },
{ Q931_CALLED_PARTY_NUMBER, "Called Party Number", dump_called_party_number, receive_called_party_number, transmit_called_party_number },
{ Q931_CALLED_PARTY_SUBADDR, "Called Party Subaddress" },
{ Q931_REDIRECTING_NUMBER, "Redirecting Number" },
{ Q931_REDIRECTING_SUBADDR, "Redirecting Subaddress" },
{ Q931_CALLED_PARTY_SUBADDR, "Called Party Subaddress", dump_called_party_subaddr },
{ Q931_REDIRECTING_NUMBER, "Redirecting Number", dump_redirecting_number },
{ Q931_REDIRECTING_SUBADDR, "Redirecting Subaddress", dump_redirecting_subaddr },
{ Q931_TRANSIT_NET_SELECT, "Transit Network Selection" },
{ Q931_RESTART_INDICATOR, "Restart Indicator", dump_restart_indicator, receive_restart_indicator, transmit_restart_indicator },
{ Q931_LOW_LAYER_COMPAT, "Low-layer Compatibility" },
@@ -844,11 +1029,11 @@ struct ie ies[] = {
{ Q931_IE_INFO_REQUEST, "Feature Request" },
{ Q931_IE_FEATURE_IND, "Feature Indication" },
{ Q931_IE_SEGMENTED_MSG, "Segmented Message" },
{ Q931_IE_CALL_IDENTITY, "Call Identity" },
{ Q931_IE_CALL_IDENTITY, "Call Identity", dump_call_identity },
{ Q931_IE_ENDPOINT_ID, "Endpoint Identification" },
{ Q931_IE_NOTIFY_IND, "Notification Indicator" },
{ Q931_IE_DISPLAY, "Display" },
{ Q931_IE_TIME_DATE, "Date/Time" },
{ Q931_IE_DISPLAY, "Display", dump_display },
{ Q931_IE_TIME_DATE, "Date/Time", dump_time_date },
{ Q931_IE_KEYPAD_FACILITY, "Keypad Facility" },
{ Q931_IE_SIGNAL, "Signal" },
{ Q931_IE_SWITCHHOOK, "Switch-hook" },
@@ -860,7 +1045,7 @@ struct ie ies[] = {
{ Q931_IE_ORIGINAL_CALLED_NUMBER, "Original Called Number" },
{ Q931_IE_USER_USER_FACILITY, "User-User Facility" },
{ Q931_IE_UPDATE, "Update" },
{ Q931_SENDING_COMPLETE, "Sending Complete", NULL, receive_sending_complete, transmit_sending_complete },
{ Q931_SENDING_COMPLETE, "Sending Complete", dump_sending_complete, receive_sending_complete, transmit_sending_complete },
};
static char *ie2str(int ie)
@@ -1021,17 +1206,14 @@ static char *disc2str(int disc)
return code2str(disc, discs, sizeof(discs) / sizeof(discs[0]));
}
static void q931_dump(q931_h *h, int len, int txrx)
void q931_dump(q931_h *h, int len, int txrx)
{
q931_mh *mh;
char c;
int x=0, r;
if (txrx)
c = '>';
else
c = '<';
printf("%c Protocol Discriminator: %d (%s)\n", c, h->pd, disc2str(h->pd));
printf("%c Call Ref Len: %d (reference %d) (%s)\n", c, h->crlen, q931_cr(h), (h->crv[0] & 0x80) ? "Terminator" : "Originator");
c = txrx ? '>' : '<';
printf("%c Protocol Discriminator: %s (%d) len=%d\n", c, disc2str(h->pd), h->pd, len);
printf("%c Call Ref: len=%2d (reference %d/0x%X) (%s)\n", c, h->crlen, q931_cr(h), q931_cr(h), (h->crv[0] & 0x80) ? "Terminator" : "Originator");
/* Message header begins at the end of the call reference number */
mh = (q931_mh *)(h->contents + h->crlen);
printf("%c Message type: %s (%d)\n", c, msg2str(mh->msg), mh->msg);
@@ -1074,7 +1256,7 @@ static void init_header(q931_call *call, char *buf, q931_h **hb, q931_mh **mhb,
h->pd = Q931_PROTOCOL_DISCRIMINATOR;
h->x0 = 0; /* Reserved 0 */
h->crlen = 2; /* Two bytes of Call Reference. Invert the top bit to make it from our sense */
if (call->cr) {
if (call->cr || call->forceinvert) {
h->crv[0] = ((call->cr ^ 0x8000) & 0xff00) >> 8;
h->crv[1] = (call->cr & 0xff);
} else {
@@ -1091,9 +1273,12 @@ static void init_header(q931_call *call, char *buf, q931_h **hb, q931_mh **mhb,
static int q931_xmit(struct pri *pri, q931_h *h, int len, int cr)
{
q921_transmit_iframe(pri, h, len, cr);
/* The transmit operation might dump the q921 header, so logging the q931
message body after the transmit puts the sections of the message in the
right order in the log */
if (pri->debug & PRI_DEBUG_Q931_DUMP)
q931_dump(h, len, 1);
q921_transmit_iframe(pri, h, len, cr);
return 0;
}
@@ -1153,7 +1338,7 @@ int q931_alerting(struct pri *pri, q931_call *c, int channel, int info)
if (info) {
c->progloc = LOC_PRIV_NET_LOCAL_USER;
c->progcode = CODE_CCITT;
c->progress = Q931_INBAND_AVAILABLE;
c->progress = Q931_PROG_INBAND_AVAILABLE;
} else
c->progress = -1;
if (!c->proc)
@@ -1172,7 +1357,7 @@ int q931_connect(struct pri *pri, q931_call *c, int channel, int nonisdn)
if (nonisdn && (pri->switchtype != PRI_SWITCH_DMS100)) {
c->progloc = LOC_PRIV_NET_LOCAL_USER;
c->progcode = CODE_CCITT;
c->progress = Q931_CALLED_NOT_ISDN;
c->progress = Q931_PROG_CALLED_NOT_ISDN;
} else
c->progress = -1;
return send_message(pri, c, Q931_CONNECT, connect_ies);
@@ -1255,7 +1440,7 @@ int q931_setup(struct pri *pri, q931_call *c, int transmode, int channel, int ex
return -1;
if (nonisdn && (pri->switchtype == PRI_SWITCH_NI2))
c->progress = Q931_CALLER_NOT_ISDN;
c->progress = Q931_PROG_CALLER_NOT_ISDN;
else
c->progress = -1;