Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2a08465d55 | ||
|
|
ebe2cae963 | ||
|
|
ea6c293782 | ||
|
|
05f41a4926 | ||
|
|
a6bebcaafc | ||
|
|
a68a6bd01d | ||
|
|
455227676a | ||
|
|
834b8d85d7 | ||
|
|
f81ba655b2 | ||
|
|
8cf62085ee | ||
|
|
9ed9f37ada | ||
|
|
ecca15537d | ||
|
|
0aa2e6fe6c | ||
|
|
c84465ba47 |
@@ -1,3 +1,12 @@
|
||||
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.
|
||||
|
||||
7
Makefile
7
Makefile
@@ -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
|
||||
|
||||
67
libpri.h
67
libpri.h
@@ -22,8 +22,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _PRI_H
|
||||
#define _PRI_H
|
||||
#ifndef _LIBPRI_H
|
||||
#define _LIBPRI_H
|
||||
|
||||
/* Node types */
|
||||
#define PRI_NETWORK 1
|
||||
@@ -50,19 +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_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
|
||||
@@ -118,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
|
||||
|
||||
@@ -135,6 +163,16 @@
|
||||
#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;
|
||||
|
||||
typedef struct pri_event_generic {
|
||||
@@ -177,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;
|
||||
|
||||
@@ -264,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
25
pri.c
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -214,6 +214,9 @@ typedef struct q931_ie {
|
||||
#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);
|
||||
@@ -230,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
130
pridump.c
Normal 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
13
prisched.c
@@ -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
346
pritest.c
Normal 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;
|
||||
}
|
||||
221
q921.c
221
q921.c
@@ -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,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 */
|
||||
@@ -379,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;
|
||||
};
|
||||
@@ -474,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;
|
||||
|
||||
@@ -534,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:
|
||||
|
||||
381
q931.c
381
q931.c
@@ -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" },
|
||||
};
|
||||
@@ -131,16 +145,6 @@ struct msgtype causes[] = {
|
||||
#define TRANS_MODE_MULTIRATE 0x18
|
||||
#define TRANS_MODE_PACKET 0X40
|
||||
|
||||
#define LAYER_1_ITU_RATE_ADAPT 0x21
|
||||
#define LAYER_1_ULAW 0x22
|
||||
#define LAYER_1_ALAW 0x23
|
||||
#define LAYER_1_G721 0x24
|
||||
#define LAYER_1_G722_G725 0x25
|
||||
#define LAYER_1_G7XX_384K 0x26
|
||||
#define LAYER_1_NON_ITU_ADAPT 0x27
|
||||
#define LAYER_1_V120_RATE_ADAPT 0x28
|
||||
#define LAYER_1_X31_RATE_ADAPT 0x29
|
||||
|
||||
#define RATE_ADAPT_56K 0x0f
|
||||
|
||||
#define LAYER_2_LAPB 0x46
|
||||
@@ -151,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
|
||||
@@ -173,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;
|
||||
@@ -184,6 +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 proc; /* Whether we've sent a call proceeding / alerting */
|
||||
|
||||
int ri; /* Restart Indicator (Restart Indicator IE) */
|
||||
@@ -242,6 +252,8 @@ 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;
|
||||
@@ -329,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)) {
|
||||
@@ -366,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,
|
||||
@@ -375,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 {
|
||||
@@ -383,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++;
|
||||
@@ -446,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[] = {
|
||||
@@ -477,15 +501,15 @@ static char *mode2str(int mode)
|
||||
static char *l12str(int proto)
|
||||
{
|
||||
static struct msgtype protos[] = {
|
||||
{ LAYER_1_ITU_RATE_ADAPT, "ITU Rate Adaption" },
|
||||
{ LAYER_1_ULAW, "u-Law" },
|
||||
{ LAYER_1_ALAW, "A-Law" },
|
||||
{ LAYER_1_G721, "G.721 ADPCM" },
|
||||
{ LAYER_1_G722_G725, "G.722/G.725 7kHz Audio" },
|
||||
{ LAYER_1_G7XX_384K, "G.7xx 384k Video" },
|
||||
{ LAYER_1_NON_ITU_ADAPT, "Non-ITU Rate Adaption" },
|
||||
{ LAYER_1_V120_RATE_ADAPT, "V.120 Rate Adaption" },
|
||||
{ LAYER_1_X31_RATE_ADAPT, "X.31 Rate Adaption" },
|
||||
{ PRI_LAYER_1_ITU_RATE_ADAPT, "ITU Rate Adaption" },
|
||||
{ PRI_LAYER_1_ULAW, "u-Law" },
|
||||
{ PRI_LAYER_1_ALAW, "A-Law" },
|
||||
{ PRI_LAYER_1_G721, "G.721 ADPCM" },
|
||||
{ PRI_LAYER_1_G722_G725, "G.722/G.725 7kHz Audio" },
|
||||
{ PRI_LAYER_1_G7XX_384K, "G.7xx 384k Video" },
|
||||
{ PRI_LAYER_1_NON_ITU_ADAPT, "Non-ITU Rate Adaption" },
|
||||
{ PRI_LAYER_1_V120_RATE_ADAPT, "V.120 Rate Adaption" },
|
||||
{ PRI_LAYER_1_X31_RATE_ADAPT, "X.31 Rate Adaption" },
|
||||
};
|
||||
return code2str(proto, protos, sizeof(protos) / sizeof(protos[0]));
|
||||
}
|
||||
@@ -517,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 */
|
||||
@@ -529,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));
|
||||
if ((ie->data[pos] & 0x7f) == 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 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: %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++;
|
||||
}
|
||||
}
|
||||
@@ -555,7 +579,7 @@ static int receive_bearer_capability(struct pri* pri, q931_call *call, int msgty
|
||||
call->transmoderate = PRI_TRANS_CAP_3_1K_AUDIO;
|
||||
if (call->transmoderate != TRANS_MODE_PACKET) {
|
||||
call->userl1 = ie->data[pos] & 0x7f;
|
||||
if (call->userl1 == LAYER_1_ITU_RATE_ADAPT) {
|
||||
if (call->userl1 == PRI_LAYER_1_ITU_RATE_ADAPT) {
|
||||
call->rateadaption = ie->data[++pos] & 0x7f;
|
||||
}
|
||||
pos++;
|
||||
@@ -583,7 +607,7 @@ static int transmit_bearer_capability(struct pri *pri, q931_call *call, int msgt
|
||||
if (pri->switchtype == PRI_SWITCH_ATT4ESS)
|
||||
return 4;
|
||||
ie->data[2] = call->userl1 | 0x80; /* XXX Ext bit? XXX */
|
||||
if (call->userl1 == LAYER_1_ITU_RATE_ADAPT) {
|
||||
if (call->userl1 == PRI_LAYER_1_ITU_RATE_ADAPT) {
|
||||
ie->data[3] = call->rateadaption | 0x80;
|
||||
return 6;
|
||||
}
|
||||
@@ -607,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[] = {
|
||||
@@ -635,18 +696,57 @@ 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)
|
||||
@@ -684,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]));
|
||||
}
|
||||
@@ -721,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;
|
||||
}
|
||||
@@ -748,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]));
|
||||
@@ -771,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++)
|
||||
@@ -784,7 +957,7 @@ 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;
|
||||
}
|
||||
@@ -801,12 +974,33 @@ 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)) {
|
||||
/* Include this single-byte IE */
|
||||
ie->f = 1;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct ie ies[] = {
|
||||
{ NATIONAL_CHANGE_STATUS, "Change Status" },
|
||||
{ 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" },
|
||||
@@ -818,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" },
|
||||
@@ -835,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" },
|
||||
@@ -851,6 +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", dump_sending_complete, receive_sending_complete, transmit_sending_complete },
|
||||
};
|
||||
|
||||
static char *ie2str(int ie)
|
||||
@@ -987,7 +1182,8 @@ static int add_ie(struct pri *pri, q931_call *call, int msgtype, int ie, q931_ie
|
||||
res = ies[x].transmit(pri, call, msgtype, iet, maxlen);
|
||||
if (res < 0)
|
||||
return res;
|
||||
iet->len = res - 2;
|
||||
if (!iet->f)
|
||||
iet->len = res - 2;
|
||||
return res;
|
||||
} else {
|
||||
fprintf(stderr, "!! Don't know how to add an IE %s (%d)\n", ie2str(ie), ie);
|
||||
@@ -1010,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);
|
||||
@@ -1063,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 {
|
||||
@@ -1080,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;
|
||||
}
|
||||
|
||||
@@ -1142,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)
|
||||
@@ -1161,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);
|
||||
@@ -1190,17 +1386,18 @@ int q931_disconnect(struct pri *pri, q931_call *c, int cause)
|
||||
c->cause = cause;
|
||||
c->causecode = CODE_CCITT;
|
||||
c->causeloc = LOC_PRIV_NET_LOCAL_USER;
|
||||
c->sendhangupack = 1;
|
||||
return send_message(pri, c, Q931_DISCONNECT, disconnect_ies);
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int setup_ies[] = { Q931_BEARER_CAPABILITY, Q931_CHANNEL_IDENT, Q931_PROGRESS_INDICATOR,
|
||||
Q931_CALLING_PARTY_NUMBER, Q931_CALLED_PARTY_NUMBER, -1 };
|
||||
Q931_CALLING_PARTY_NUMBER, Q931_CALLED_PARTY_NUMBER, Q931_SENDING_COMPLETE, -1 };
|
||||
|
||||
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 userl1)
|
||||
{
|
||||
int res;
|
||||
|
||||
@@ -1209,7 +1406,9 @@ int q931_setup(struct pri *pri, q931_call *c, int transmode, int channel, int ex
|
||||
return -1;
|
||||
c->transcapability = transmode;
|
||||
c->transmoderate = TRANS_MODE_64_CIRCUIT;
|
||||
c->userl1 = LAYER_1_ULAW;
|
||||
if (!userl1)
|
||||
userl1 = PRI_LAYER_1_ULAW;
|
||||
c->userl1 = userl1;
|
||||
c->channelno = channel;
|
||||
c->slotmap = -1;
|
||||
c->ds1no = -1;
|
||||
@@ -1220,7 +1419,7 @@ int q931_setup(struct pri *pri, q931_call *c, int transmode, int channel, int ex
|
||||
else
|
||||
c->chanflags = FLAG_PREFERRED;
|
||||
if (caller) {
|
||||
strncpy(c->callernum, caller, sizeof(c->callernum));
|
||||
strncpy(c->callernum, caller, sizeof(c->callernum) - 1);
|
||||
c->callerplan = callerplan;
|
||||
if ((pri->switchtype == PRI_SWITCH_DMS100) ||
|
||||
(pri->switchtype == PRI_SWITCH_ATT4ESS)) {
|
||||
@@ -1235,13 +1434,13 @@ int q931_setup(struct pri *pri, q931_call *c, int transmode, int channel, int ex
|
||||
c->callerpres = PRES_NUMBER_NOT_AVAILABLE;
|
||||
}
|
||||
if (called) {
|
||||
strncpy(c->callednum, called, sizeof(c->callednum));
|
||||
strncpy(c->callednum, called, sizeof(c->callednum) - 1);
|
||||
c->calledplan = calledplan;
|
||||
} else
|
||||
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;
|
||||
|
||||
@@ -1405,12 +1604,13 @@ int q931_receive(struct pri *pri, q931_h *h, int len)
|
||||
pri->ev.ring.channel = c->channelno;
|
||||
pri->ev.ring.callingpres = c->callerpres;
|
||||
pri->ev.ring.callingplan = c->callerplan;
|
||||
strncpy(pri->ev.ring.callingnum, c->callernum, sizeof(pri->ev.ring.callingnum));
|
||||
strncpy(pri->ev.ring.callingnum, c->callernum, sizeof(pri->ev.ring.callingnum) - 1);
|
||||
pri->ev.ring.calledplan = c->calledplan;
|
||||
strncpy(pri->ev.ring.callednum, c->callednum, sizeof(pri->ev.ring.callednum));
|
||||
strncpy(pri->ev.ring.callednum, c->callednum, sizeof(pri->ev.ring.callednum) - 1);
|
||||
pri->ev.ring.flexible = ! (c->chanflags & FLAG_EXCLUSIVE);
|
||||
pri->ev.ring.cref = c->cr;
|
||||
pri->ev.ring.call = c;
|
||||
pri->ev.ring.layer1 = c->userl1;
|
||||
if (c->transmoderate != TRANS_MODE_64_CIRCUIT) {
|
||||
q931_release(pri, c, PRI_CAUSE_BEARERCAPABILITY_NOTIMPL);
|
||||
break;
|
||||
@@ -1463,7 +1663,10 @@ int q931_receive(struct pri *pri, q931_h *h, int len)
|
||||
pri->ev.hangup.call = c;
|
||||
if (c->alive)
|
||||
res = Q931_RES_HAVEEVENT;
|
||||
else
|
||||
else if (c->sendhangupack) {
|
||||
res = Q931_RES_HAVEEVENT;
|
||||
pri->ev.e = PRI_EVENT_HANGUP_ACK;
|
||||
} else
|
||||
res = 0;
|
||||
q931_release_complete(pri, c);
|
||||
/* Free resources */
|
||||
|
||||
Reference in New Issue
Block a user