Compare commits

...

11 Commits
0.1.0 ... 0.2.0

Author SHA1 Message Date
Kevin P. Fleming
d623b2412e remove extraneous svn:executable properties
git-svn-id: https://origsvn.digium.com/svn/libpri/tags/0.2.0@266 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2005-11-29 18:39:18 +00:00
Kevin P. Fleming
63699af574 automatic tag renames
git-svn-id: https://origsvn.digium.com/svn/libpri/tags/0.2.0@263 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2005-11-27 04:17:23 +00:00
Admin Commit
2323c14331 This commit was manufactured by cvs2svn to create tag 'v0-2-0'.
git-svn-id: https://origsvn.digium.com/svn/libpri/tags/v0-2-0@16 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2001-12-07 19:45:45 +00:00
Mark Spencer
9ed9f37ada Version 0.2.0 from FTP
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@15 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2001-12-07 19:45:45 +00:00
Mark Spencer
ecca15537d Version 0.2.0 from FTP
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@14 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2001-11-29 18:09:09 +00:00
Mark Spencer
0aa2e6fe6c Version 0.2.0 from FTP
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@13 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2001-11-26 02:54:32 +00:00
Mark Spencer
c84465ba47 Version 0.2.0 from FTP
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@12 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2001-10-18 16:21:39 +00:00
Mark Spencer
5d2d870837 Version 0.1.1 from FTP
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@10 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2001-07-20 20:52:43 +00:00
Mark Spencer
46baaa36df Version 0.1.1 from FTP
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@9 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2001-07-17 12:12:42 +00:00
Mark Spencer
ecb32ede6a Version 0.1.1 from FTP
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@8 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2001-05-21 13:39:30 +00:00
Mark Spencer
c752834a02 Version 0.1.1 from FTP
git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@7 2fbb986a-6c06-0410-b554-c9c1f0a7f128
2001-05-15 15:32:24 +00:00
12 changed files with 546 additions and 295 deletions

10
ChangeLog Executable file → Normal file
View File

@@ -1,2 +1,12 @@
-- Fix strncpy stuff
libpri 0.1.2
-- Added PRI_EVENT_HANGUP_ACK so you can know when the disconnect was
acknowledged
libpri 0.1.1
-- Added PRI_DEBUG_Q931_ANOMALY flag so that certain non-error-related
messages would not be output unless specifically desired.
libpri 0.1.0
-- Initial release

0
Makefile Executable file → Normal file
View File

0
README Executable file → Normal file
View File

0
TODO Executable file → Normal file
View File

50
libpri.h Executable file → Normal file
View File

@@ -36,15 +36,18 @@
#define PRI_DEBUG_CONFIG (1 << 3) /* Display error events on stdout */
#define PRI_DEBUG_Q931_DUMP (1 << 5) /* Show interpreted Q.931 frames */
#define PRI_DEBUG_Q931_STATE (1 << 6) /* Debug Q.931 state machine changes */
#define PRI_DEBUG_Q931_ANOMALY (1 << 7) /* Show unexpected events */
#define PRI_DEBUG_ALL (0xffff) /* Everything */
/* Switch types */
#define PRI_SWITCH_UNKNOWN 0
#define PRI_SWITCH_NI2 1 /* National ISDN 2 */
#define PRI_SWITCH_DMS100 2 /* DMS 100 */
#define PRI_SWITCH_LUCENT5E 3 /* Lucent 5E */
#define PRI_SWITCH_ATT4ESS 4 /* AT&T 4ESS */
#define PRI_SWITCH_UNKNOWN 0
#define PRI_SWITCH_NI2 1 /* National ISDN 2 */
#define PRI_SWITCH_DMS100 2 /* DMS 100 */
#define PRI_SWITCH_LUCENT5E 3 /* Lucent 5E */
#define PRI_SWITCH_ATT4ESS 4 /* AT&T 4ESS */
#define PRI_SWITCH_EUROISDN_E1 5 /* Standard EuroISDN (CTR4, ETSI 300-102) */
#define PRI_SWITCH_EUROISDN_T1 6 /* T1 EuroISDN variant (ETSI 300-102) */
/* PRI D-Channel Events */
#define PRI_EVENT_DCHAN_UP 1 /* D-channel is up */
@@ -55,6 +58,7 @@
#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
@@ -89,33 +93,58 @@
#define PRI_CAUSE_NO_USER_RESPONSE 18
#define PRI_CAUSE_NO_ANSWER 19
#define PRI_CAUSE_CALL_REJECTED 21
#define PRI_CAUSE_NUMBER_CHANGED 22
#define PRI_CAUSE_DESTINATION_OUT_OF_ORDER 27
#define PRI_CAUSE_INVALID_NUMBER_FORMAT 28
#define PRI_CAUSE_FACILITY_REJECTED 29
#define PRI_CAUSE_RESPONSE_TO_STATUS_ENQUIRY 30
#define PRI_CAUSE_NORMAL_UNSPECIFIED 31
#define PRI_CAUSE_NORMAL_CIRCUIT_CONGESTION 34
#define PRI_CAUSE_NETWORK_OUT_OF_ORDER 38
#define PRI_CAUSE_NORMAL_TEMPORARY_FAILURE 41
#define PRI_CAUSE_SWITCH_CONGESTION 42
#define PRI_CAUSE_ACCESS_INFO_DISCARDED 43
#define PRI_CAUSE_REQUESTED_CHAN_UNAVAIL 44
#define PRI_CAUSE_PRE_EMPTED 45
#define PRI_CAUSE_FACILITY_NOT_SUBSCRIBED 50
#define PRI_CAUSE_OUTGOING_CALL_BARRED 52
#define PRI_CAUSE_INCOMING_CALL_BARRED 54
#define PRI_CAUSE_BEARERCAPABILITY_NOTAUTH 57
#define PRI_CAUSE_BEARERCAPABILITY_NOTAVAIL 58
#define PRI_CAUSE_BEARERCAPABILITY_NOTIMPL 65
#define PRI_CAUSE_CHAN_NOT_IMPLEMENTED 66
#define PRI_CAUSE_FACILITY_NOT_IMPLEMENTED 69
#define PRI_CAUSE_INVALID_CALL_REFERENCE 81
#define PRI_CAUSE_INCOMPATIBLE_DESTINATION 88
#define PRI_CAUSE_INVALID_MSG_UNSPECIFIED 95
#define PRI_CAUSE_MANDATORY_IE_MISSING 96
#define PRI_CAUSE_MESSAGE_TYPE_NONEXIST 97
#define PRI_CAUSE_WRONG_MESSAGE 98
#define PRI_CAUSE_IE_NONEXIST 99
#define PRI_CAUSE_INVALID_IE_CONTENTS 100
#define PRI_CAUSE_WRONG_CALL_STATE 101
#define PRI_CAUSE_RECOVERY_ON_TIMER_EXPIRE 102
#define PRI_CAUSE_MANDATORY_IE_LENGTH_ERROR 103
#define PRI_CAUSE_PROTOCOL_ERROR 111
#define PRI_CAUSE_INTERWORKING 127
/* Transmit capabilities */
#define PRI_TRANS_CAP_SPEECH 0x0
#define PRI_TRANS_CAP_DIGITAL 0x80
#define PRI_TRANS_CAP_AUDIO 0x10
#define PRI_TRANS_CAP_SPEECH 0x0
#define PRI_TRANS_CAP_DIGITAL 0x08
#define PRI_TRANS_CAP_RESTRICTED_DIGITAL 0x09
#define PRI_TRANS_CAP_3_1K_AUDIO 0x10
#define PRI_TRANS_CAP_7K_AUDIO 0x11
#define PRI_TRANS_CAP_VIDEO 0x18
#define PRI_LAYER_1_ITU_RATE_ADAPT 0x21
#define PRI_LAYER_1_ULAW 0x22
#define PRI_LAYER_1_ALAW 0x23
#define PRI_LAYER_1_G721 0x24
#define PRI_LAYER_1_G722_G725 0x25
#define PRI_LAYER_1_G7XX_384K 0x26
#define PRI_LAYER_1_NON_ITU_ADAPT 0x27
#define PRI_LAYER_1_V120_RATE_ADAPT 0x28
#define PRI_LAYER_1_X31_RATE_ADAPT 0x29
typedef struct q931_call q931_call;
@@ -159,6 +188,7 @@ typedef struct pri_event_ring {
int flexible; /* Are we flexible with our channel selection? */
int cref; /* Call Reference Number */
int ctype; /* Call type (see PRI_TRANS_CAP_* */
int layer1; /* User layer 1 */
q931_call *call; /* Opaque call pointer */
} pri_event_ring;
@@ -246,9 +276,9 @@ extern q931_call *pri_new_call(struct pri *pri);
extern struct timeval *pri_schedule_next(struct pri *pri);
/* Run any pending schedule events */
extern int pri_schedule_run(struct pri *pri);
extern pri_event *pri_schedule_run(struct pri *pri);
extern int pri_call(struct pri *pri, q931_call *c, int transmode, int channel,
int exclusive, int nonisdn, char *caller, int callerplan, int callerpres,
char *called,int calledplan);
char *called,int calledplan, int ulayer1);
#endif

25
pri.c Executable file → Normal file
View File

@@ -105,13 +105,26 @@ pri_event *pri_check_event(struct pri *pri)
static int wait_pri(struct pri *pri)
{
struct timeval *tv;
struct timeval *tv, real;
fd_set fds;
int res;
FD_ZERO(&fds);
FD_SET(pri->fd, &fds);
tv = pri_schedule_next(pri);
res = select(pri->fd + 1, &fds, NULL, NULL, tv);
if (tv) {
gettimeofday(&real, NULL);
real.tv_sec = tv->tv_sec - real.tv_sec;
real.tv_usec = tv->tv_usec - real.tv_usec;
if (real.tv_usec < 0) {
real.tv_usec += 1000000;
real.tv_sec -= 1;
}
if (real.tv_sec < 0) {
real.tv_sec = 0;
real.tv_usec = 0;
}
}
res = select(pri->fd + 1, &fds, NULL, NULL, tv ? &real : tv);
if (res < 0)
return -1;
return res;
@@ -121,7 +134,7 @@ pri_event *pri_mkerror(struct pri *pri, char *errstr)
{
/* Return a configuration error */
pri->ev.err.e = PRI_EVENT_CONFIG_ERR;
strncpy(pri->ev.err.err, errstr, sizeof(pri->ev.err.err));
strncpy(pri->ev.err.err, errstr, sizeof(pri->ev.err.err) - 1);
return &pri->ev;
}
@@ -140,7 +153,7 @@ pri_event *pri_dchannel_run(struct pri *pri, int block)
if (res < 0)
return NULL;
if (!res)
pri_schedule_run(pri);
e = pri_schedule_run(pri);
else
e = pri_check_event(pri);
} while(!e);
@@ -222,9 +235,9 @@ void pri_dump_event(struct pri *pri, pri_event *e)
int pri_call(struct pri *pri, q931_call *c, int transmode, int channel, int exclusive,
int nonisdn, char *caller, int callerplan, int callerpres, char *called,
int calledplan)
int calledplan,int ulayer1)
{
if (!pri || !c)
return -1;
return q931_setup(pri, c, transmode, channel, exclusive, nonisdn, caller, callerplan, callerpres, called, calledplan);
return q931_setup(pri, c, transmode, channel, exclusive, nonisdn, caller, callerplan, callerpres, called, calledplan, ulayer1);
}

3
pri_internal.h Executable file → Normal file
View File

@@ -70,6 +70,7 @@ struct pri {
/* Used by scheduler */
struct timeval tv;
int schedev;
pri_event ev; /* Static event thingy */
/* Q.921 Re-transmission queue */
@@ -81,7 +82,7 @@ struct pri {
extern int pri_schedule_event(struct pri *pri, int ms, void (*function)(void *data), void *data);
extern int pri_schedule_run(struct pri *pri);
extern pri_event *pri_schedule_run(struct pri *pri);
extern void pri_schedule_del(struct pri *pri, int ev);

8
pri_q921.h Executable file → Normal file
View File

@@ -34,6 +34,7 @@
#define T_WAIT_MAX 10000
#define T_200 1000 /* 1 second between SABME's */
#define T_203 10000 /* 10 seconds with no packets max */
#define N_200 3 /* 3 retries */
#define Q921_FRAMETYPE_MASK 0x3
@@ -41,6 +42,13 @@
#define Q921_FRAMETYPE_I 0x0
#define Q921_FRAMETYPE_S 0x1
#define Q921_TEI_GROUP 127
#define Q921_SAPI_CALL_CTRL 0
#define Q921_SAPI_PACKET_MODE 1
#define Q921_SAPI_X25_LAYER3 16
#define Q921_SAPI_LAYER2_MANAGEMENT 63
typedef struct q921_header {
#if __BYTE_ORDER == __BIG_ENDIAN

52
pri_q931.h Executable file → Normal file
View File

@@ -123,6 +123,7 @@ typedef struct q931_ie {
#define Q931_CONNECT_ACKNOWLEDGE 0x0f
#define Q931_PROGRESS 0x03
#define Q931_SETUP 0x05
#define Q931_SETUP_ACKNOWLEDGE 0x0d
/* Call Disestablishment Messages */
#define Q931_DISCONNECT 0x45
@@ -134,9 +135,29 @@ typedef struct q931_ie {
/* Miscellaneous Messages */
#define Q931_STATUS 0x7d
#define Q931_STATUS_ENQUIRY 0x75
#define Q931_USER_INFORMATION 0x20
#define Q931_SEGMENT 0x60
#define Q931_CONGESTION_CONTROL 0x79
#define Q931_INFORMATION 0x7b
#define Q931_FACILITY 0x62
#define Q931_NOTIFY 0x6e
/* Call Management Messages */
#define Q931_HOLD 0x24
#define Q931_HOLD_ACKNOWLEDGE 0x28
#define Q931_HOLD_REJECT 0x30
#define Q931_RETRIEVE 0x31
#define Q931_RETRIEVE_ACKNOWLEDGE 0x33
#define Q931_RETRIEVE_REJECT 0x37
#define Q931_RESUME 0x26
#define Q931_RESUME_ACKNOWLEDGE 0x2e
#define Q931_RESUME_REJECT 0x22
#define Q931_SUSPEND 0x25
#define Q931_SUSPEND_ACKNOWLEDGE 0x2d
#define Q931_SUSPEND_REJECT 0x21
/* Maintenance messages (codeset 0 only) */
#define NATIONAL_SERVICE 0x0f
#define NATIONAL_SERVICE 0x0f
#define NATIONAL_SERVICE_ACKNOWLEDGE 0x07
/* Special codeset 0 IE */
@@ -169,6 +190,33 @@ typedef struct q931_ie {
#define Q931_LOW_LAYER_COMPAT 0x7c
#define Q931_HIGH_LAYER_COMPAT 0x7d
#define Q931_IE_SEGMENTED_MSG 0x00
#define Q931_IE_CHANGE_STATUS 0x01
#define Q931_IE_CONNECTED_NUM 0x0C
#define Q931_IE_CALL_IDENTITY 0x10
#define Q931_IE_FACILITY 0x1c
#define Q931_IE_ENDPOINT_ID 0x26
#define Q931_IE_NOTIFY_IND 0x27
#define Q931_IE_DISPLAY 0x28
#define Q931_IE_TIME_DATE 0x29
#define Q931_IE_KEYPAD_FACILITY 0x2c
#define Q931_IE_CALL_STATUS 0x2d
#define Q931_IE_UPDATE 0x31
#define Q931_IE_INFO_REQUEST 0x32
#define Q931_IE_SIGNAL 0x34
#define Q931_IE_SWITCHHOOK 0x36
#define Q931_IE_FEATURE_ACTIVATE 0x38
#define Q931_IE_FEATURE_IND 0x39
#define Q931_IE_ORIGINAL_CALLED_NUMBER 0x73
#define Q931_IE_REDIRECTION_NUMBER 0x76
#define Q931_IE_REDIRECTION_SUBADDR 0x77
#define Q931_IE_USER_USER_FACILITY 0x7A
#define Q931_IE_USER_USER 0x7E
#define Q931_IE_ESCAPE_FOR_EXT 0x7F
/* EuroISDN */
#define Q931_SENDING_COMPLETE 0x21
extern int q931_receive(struct pri *pri, q931_h *h, int len);
extern int q931_alerting(struct pri *pri, q931_call *call, int channel, int info);
@@ -185,6 +233,6 @@ extern q931_call *q931_new_call(struct pri *pri);
extern int q931_setup(struct pri *pri, q931_call *c, int transmode, int channel, int exclusive,
int nonisdn, char *caller, int callerplan, int callerpres, char *called,
int calledplan);
int calledplan, int ulay1);
#endif

13
prisched.c Executable file → Normal file
View File

@@ -46,8 +46,10 @@ int pri_schedule_event(struct pri *pri, int ms, void (*function)(void *data), vo
gettimeofday(&tv, NULL);
tv.tv_sec += ms / 1000;
tv.tv_usec += (ms % 1000) * 1000;
if (tv.tv_usec > 1000000)
if (tv.tv_usec > 1000000) {
tv.tv_usec -= 1000000;
tv.tv_sec += 1;
}
pri->pri_sched[x].when = tv;
pri->pri_sched[x].callback = function;
pri->pri_sched[x].data = data;
@@ -68,11 +70,10 @@ struct timeval *pri_schedule_next(struct pri *pri)
return closest;
}
int pri_schedule_run(struct pri *pri)
pri_event *pri_schedule_run(struct pri *pri)
{
struct timeval tv;
int x;
int p = 0;
void (*callback)(void *);
void *data;
gettimeofday(&tv, NULL);
@@ -81,15 +82,17 @@ int pri_schedule_run(struct pri *pri)
((pri->pri_sched[x].when.tv_sec < tv.tv_sec) ||
((pri->pri_sched[x].when.tv_sec == tv.tv_sec) &&
(pri->pri_sched[x].when.tv_usec <= tv.tv_usec)))) {
p++;
pri->schedev = 0;
callback = pri->pri_sched[x].callback;
data = pri->pri_sched[x].data;
pri->pri_sched[x].callback = NULL;
pri->pri_sched[x].data = NULL;
callback(data);
if (pri->schedev)
return &pri->ev;
}
}
return p;
return NULL;
}
void pri_schedule_del(struct pri *pri,int id)

107
q921.c Executable file → Normal file
View File

@@ -32,6 +32,15 @@
#include "pri_q921.h"
#include "pri_q931.h"
/*
* Define RANDOM_DROPS To randomly drop packets in order to simulate loss for testing
* retransmission functionality
*/
/*
#define RANDOM_DROPS
*/
#define Q921_INIT(hf) do { \
(hf).h.sapi = 0; \
(hf).h.ea1 = 0; \
@@ -54,6 +63,13 @@ static void q921_discard_retransmissions(struct pri *pri)
static int q921_transmit(struct pri *pri, q921_h *h, int len) {
int res;
#ifdef RANDOM_DROPS
if (!(random() % 3)) {
printf(" === Dropping Packet ===\n");
return 0;
}
#endif
/* Just send it raw */
if (pri->debug & PRI_DEBUG_Q921_DUMP)
q921_dump(h, len, pri->debug & PRI_DEBUG_Q921_RAW, 1);
@@ -159,9 +175,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 wis nothing left, stopping T200 counter\n");
/* Something was ACK'd. Stop T200 counter */
pri_schedule_del(pri, pri->t200_timer);
pri->t200_timer = 0;
@@ -211,13 +227,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 +243,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)
@@ -347,6 +382,7 @@ void q921_dump(q921_h *h, int len, int showraw, int txrx)
printf("%02x ",h->raw[x]);
printf("]\n");
}
switch(h->h.data[0] & Q921_FRAMETYPE_MASK) {
case 0:
case 2:
@@ -473,6 +509,7 @@ void q921_reset(struct pri *pri)
pri_event *q921_receive(struct pri *pri, q921_h *h, int len)
{
q921_frame *f;
/* Discard FCS */
len -= 2;
@@ -482,7 +519,15 @@ pri_event *q921_receive(struct pri *pri, q921_h *h, int len)
/* Check some reject conditions -- Start by rejecting improper ea's */
if (h->h.ea1 || !(h->h.ea2))
return NULL;
/* Check for broadcasts - not yet handled */
if (h->h.tei == Q921_TEI_GROUP)
return NULL;
/* Check for SAPIs we don't yet handle */
if (h->h.sapi != Q921_SAPI_CALL_CTRL)
return NULL;
switch(h->h.data[0] & Q921_FRAMETYPE_MASK) {
case 0:
case 2:
@@ -525,8 +570,57 @@ pri_event *q921_receive(struct pri *pri, q921_h *h, int len)
pri->solicitfbit = 0;
}
break;
#if 0
case 1:
/* Receiver not ready */
if (pri->debug & PRI_DEBUG_Q921_STATE)
printf("-- Got receiver not ready\n");
pri->busy = 1;
break;
#endif
case 2:
/* Just retransmit */
if (pri->debug & PRI_DEBUG_Q921_STATE)
printf("-- Got reject requesting packet %d... Retransmitting.\n", h->s.n_r);
if (h->s.p_f) {
/* If it has the poll bit set, send an appropriate supervisory response */
q921_rr(pri, 1);
}
/* Resend the proper I-frame */
for(f=pri->txqueue;f;f=f->next) {
if (f->h.n_s == h->s.n_r) {
/* Matches the request */
break;
}
}
if (f) {
/* Retransmit the requested frame */
q921_transmit(pri, (q921_h *)(&f->h), f->len);
} else {
if (pri->txqueue) {
/* This should never happen */
if (!h->s.p_f || h->s.n_r) {
fprintf(stderr, "!! Got reject for frame %d, but we only have others!\n", h->s.n_r);
}
} else {
/* Hrm, we have nothing to send, but have been REJ'd. Reset v_a, v_s, etc */
pri->v_a = h->s.n_r;
pri->v_s = h->s.n_r;
/* Reset t200 timer if it was somehow going */
if (pri->t200_timer) {
pri_schedule_del(pri, pri->t200_timer);
pri->t200_timer = 0;
}
/* Reset and restart t203 timer */
if (pri->t203_timer)
pri_schedule_del(pri, pri->t203_timer);
pri->t203_timer = pri_schedule_event(pri, T_203, t203_expire, pri);
}
}
break;
default:
fprintf(stderr, "!! XXX Unknown Supervisory frame XXX\n");
fprintf(stderr, "!! XXX Unknown Supervisory frame ss=0x%02x,pf=%02xnr=%02x vs=%02x, va=%02x XXX\n", h->s.ss, h->s.p_f, h->s.n_r,
pri->v_s, pri->v_a);
}
break;
case 3:
@@ -620,4 +714,3 @@ void q921_start(struct pri *pri)
/* Do the SABME XXX Maybe we should implement T_WAIT? XXX */
q921_send_sabme(pri);
}

573
q931.c Executable file → Normal file
View File

@@ -35,7 +35,9 @@
struct msgtype {
int msgnum;
unsigned char *name;
} msgs[] = {
};
struct msgtype msgs[] = {
/* Call establishment messages */
{ Q931_ALERTING, "ALERTING" },
{ Q931_CALL_PROCEEDING, "CALL PROCEEDING" },
@@ -54,12 +56,66 @@ struct msgtype {
/* Miscellaneous */
{ Q931_STATUS, "STATUS" },
{ Q931_STATUS_ENQUIRY, "STATUS ENQUIRY" },
{ Q931_USER_INFORMATION, "USER_INFORMATION" },
{ Q931_SEGMENT, "SEGMENT" },
{ Q931_CONGESTION_CONTROL, "CONGESTION CONTROL" },
{ Q931_INFORMATION, "INFORMATION" },
{ Q931_FACILITY, "FACLITY" },
{ Q931_NOTIFY, "NOTIFY" },
/* Call Management */
{ Q931_HOLD, "HOLD" },
{ Q931_HOLD_ACKNOWLEDGE, "HOLD ACKNOWLEDGE" },
{ Q931_HOLD_REJECT, "HOLD REJECT" },
{ Q931_RETRIEVE, "RETRIEVE" },
{ Q931_RETRIEVE_ACKNOWLEDGE, "RETRIEVE ACKNOWLEDGE" },
{ Q931_RETRIEVE_REJECT, "RETRIEVE REJECT" },
{ Q931_RESUME, "RESUME" },
{ Q931_RESUME_ACKNOWLEDGE, "RESUME ACKNOWLEDGE" },
{ Q931_RESUME_REJECT, "RESUME REJECT" },
{ Q931_SUSPEND, "SUSPEND" },
{ Q931_SUSPEND_ACKNOWLEDGE, "SUSPEND ACKNOWLEDGE" },
{ Q931_SUSPEND_REJECT, "SUSPEND REJECT" },
/* Maintenance */
{ NATIONAL_SERVICE, "SERVICE" },
{ NATIONAL_SERVICE_ACKNOWLEDGE, "SERVICE ACKNOWLEDGE" },
};
struct msgtype causes[] = {
{ PRI_CAUSE_UNALLOCATED, "Unallocated (unassigned) number" },
{ PRI_CAUSE_NO_ROUTE_TRANSIT_NET, "No route to specified transmit network" },
{ PRI_CAUSE_NO_ROUTE_DESTINATION, "No route to destination" },
{ PRI_CAUSE_CHANNEL_UNACCEPTABLE, "Channel unacceptable" },
{ PRI_CAUSE_CALL_AWARDED_DELIVERED, "Call awarded and being delivered in an established channel" },
{ PRI_CAUSE_NORMAL_CLEARING, "Normal Clearing" },
{ PRI_CAUSE_USER_BUSY, "User busy" },
{ PRI_CAUSE_NO_USER_RESPONSE, "No user responding" },
{ PRI_CAUSE_NO_ANSWER, "User alerting, no answer" },
{ PRI_CAUSE_CALL_REJECTED, "Call Rejected" },
{ PRI_CAUSE_DESTINATION_OUT_OF_ORDER, "Destination out of order" },
{ PRI_CAUSE_INVALID_NUMBER_FORMAT, "Invalid number format" },
{ 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_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_BEARERCAPABILITY_NOTAUTH, "Bearer capability not authorized" },
{ PRI_CAUSE_BEARERCAPABILITY_NOTIMPL, "Bearer capability not implemented" },
{ PRI_CAUSE_INVALID_CALL_REFERENCE, "Invalid call reference value" },
{ PRI_CAUSE_INCOMPATIBLE_DESTINATION, "Incompatible destination" },
{ PRI_CAUSE_MANDATORY_IE_MISSING, "Mandatory information element is missing" },
{ PRI_CAUSE_MESSAGE_TYPE_NONEXIST, "Message type nonexist." },
{ 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_PROTOCOL_ERROR, "Protocol error, unspecified" },
{ PRI_CAUSE_INTERWORKING, "Interworking, unspecified" },
};
#define FLAG_PREFERRED 2
#define FLAG_EXCLUSIVE 4
@@ -68,14 +124,13 @@ struct msgtype {
#define RESET_INDICATOR_PRI 7
#define TRANS_MODE_64_CIRCUIT 0x10
#define TRANS_MODE_2x64_CIRCUIT 0x11
#define TRANS_MODE_384_CIRCUIT 0x13
#define TRANS_MODE_1536_CIRCUIT 0x15
#define TRANS_MODE_1920_CIRCUIT 0x17
#define TRANS_MODE_MULTIRATE 0x18
#define TRANS_MODE_PACKET 0X40
#define LAYER_1_RATE_ADAPT 0x21
#define LAYER_1_ULAW 0x22
#define RATE_ADAPT_56K 0x0f
#define LAYER_2_LAPB 0x46
@@ -86,15 +141,16 @@ struct msgtype {
#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_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 CODE_CCITT 0x0
#define CODE_NATIONAL 0x2
#define CODE_NETWORK_SPECIFIC 0x3
#define CODE_CCITT 0x0
#define CODE_INTERNATIONAL 0x1
#define CODE_NATIONAL 0x2
#define CODE_NETWORK_SPECIFIC 0x3
#define LOC_USER 0x0
#define LOC_PRIV_NET_LOCAL_USER 0x1
@@ -108,7 +164,7 @@ struct msgtype {
struct q931_call {
int cr; /* Call Reference */
q931_call *next;
/* Slotmap specified (bitmap of channels 24-1) (Channel Identifier IE) (-1 means not specified) */
/* Slotmap specified (bitmap of channels 31/24-1) (Channel Identifier IE) (-1 means not specified) */
int slotmap;
/* An explicit channel (Channel Identifier IE) (-1 means not specified) */
int channelno;
@@ -118,6 +174,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) */
@@ -163,10 +220,20 @@ struct ie {
int (*transmit)(struct pri *pri, q931_call *call, int msgtype, q931_ie *ie, int maxlen);
};
static char *code2str(int code, struct msgtype *codes, int max)
{
int x;
for (x=0;x<max; x++)
if (codes[x].msgnum == code)
return codes[x].name;
return "Unknown";
}
static void call_init(struct q931_call *c)
{
memset(c, 0, sizeof(*c));
c->alive = 0;
c->sendhangupack = 0;
c->cr = -1;
c->slotmap = -1;
c->channelno = -1;
@@ -330,16 +397,12 @@ static void dump_channel_id(q931_ie *ie, int len, char prefix)
static char *ri2str(int ri)
{
switch(ri) {
case 0:
return "Indicated Channel";
case 6:
return "Single DS1 Facility";
case 7:
return "All DS1 Facilities";
default:
return "Unknown";
}
static struct msgtype ris[] = {
{ 0, "Indicated Channel" },
{ 6, "Single DS1 Facility" },
{ 7, "All DS1 Facilities" },
};
return code2str(ri, ris, sizeof(ris) / sizeof(ris[0]));
}
static void dump_restart_indicator(q931_ie *ie, int len, char prefix)
@@ -377,79 +440,70 @@ static int transmit_restart_indicator(struct pri *pri, q931_call *call, int msgt
static char *cap2str(int mode)
{
switch (mode) {
case PRI_TRANS_CAP_SPEECH:
return "Speech";
case PRI_TRANS_CAP_DIGITAL:
return "Unrestricted digital information";
case PRI_TRANS_CAP_AUDIO:
return "3.1-kHz audio";
case PRI_TRANS_CAP_AUDIO_4ESS:
return "3.1-khz audio (4ESS)";
default:
return "Unknown";
}
static struct msgtype modes[] = {
{ PRI_TRANS_CAP_SPEECH, "Speech" },
{ PRI_TRANS_CAP_DIGITAL, "Unrestricted digital information" },
{ PRI_TRANS_CAP_RESTRICTED_DIGITAL, "Restricted digital information" },
{ PRI_TRANS_CAP_3_1K_AUDIO, "3.1kHz audio" },
{ PRI_TRANS_CAP_7K_AUDIO, "7kHz audio" },
{ PRI_TRANS_CAP_VIDEO, "Video" },
{ PRI_TRANS_CAP_AUDIO_4ESS, "3.1khz audio (4ESS)" },
};
return code2str(mode, modes, sizeof(modes) / sizeof(modes[0]));
}
static char *mode2str(int mode)
{
switch(mode) {
case TRANS_MODE_64_CIRCUIT:
return "64-kbps, circuit-mode";
case TRANS_MODE_384_CIRCUIT:
return "384kbps, circuit-mode";
case TRANS_MODE_1536_CIRCUIT:
return "1536kbps, circuit-mode";
case TRANS_MODE_MULTIRATE:
return "Multirate (Nx64kbps)";
case TRANS_MODE_PACKET:
return "Packet Mode";
}
return "Unknown";
static struct msgtype modes[] = {
{ TRANS_MODE_64_CIRCUIT, "64kbps, circuit-mode" },
{ TRANS_MODE_2x64_CIRCUIT, "2x64kbps, circuit-mode" },
{ TRANS_MODE_384_CIRCUIT, "384kbps, circuit-mode" },
{ TRANS_MODE_1536_CIRCUIT, "1536kbps, circuit-mode" },
{ TRANS_MODE_1920_CIRCUIT, "1920kbps, circuit-mode" },
{ TRANS_MODE_MULTIRATE, "Multirate (Nx64kbps)" },
{ TRANS_MODE_PACKET, "Packet Mode" },
};
return code2str(mode, modes, sizeof(modes) / sizeof(modes[0]));
}
static char *l12str(int proto)
{
switch(proto) {
case LAYER_1_RATE_ADAPT:
return "Rate Adaption";
case LAYER_1_ULAW:
return "u-Law";
default:
return "Unknown";
}
static struct msgtype protos[] = {
{ 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]));
}
static char *ra2str(int proto)
{
switch(proto) {
case RATE_ADAPT_56K:
return "from 56kbps";
default:
return "Unknown";
}
static struct msgtype protos[] = {
{ RATE_ADAPT_56K, "from 56kbps" },
};
return code2str(proto, protos, sizeof(protos) / sizeof(protos[0]));
}
static char *l22str(int proto)
{
switch(proto) {
case LAYER_2_LAPB:
return "LAPB";
default:
return "Unknown";
}
static struct msgtype protos[] = {
{ LAYER_2_LAPB, "LAPB" },
};
return code2str(proto, protos, sizeof(protos) / sizeof(protos[0]));
}
static char *l32str(int proto)
{
switch(proto) {
case LAYER_3_X25:
return "X.25";
default:
return "Unknown";
}
static struct msgtype protos[] = {
{ LAYER_3_X25, "X.25" },
};
return code2str(proto, protos, sizeof(protos) / sizeof(protos[0]));
}
static void dump_bearer_capability(q931_ie *ie, int len, char prefix)
@@ -468,7 +522,7 @@ static void dump_bearer_capability(q931_ie *ie, int len, char prefix)
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_RATE_ADAPT)
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));
pos++;
} else {
@@ -490,10 +544,10 @@ static int receive_bearer_capability(struct pri* pri, q931_call *call, int msgty
call->transcapability = ie->data[0] & 0x1f;
call->transmoderate = ie->data[1] & 0x7f;
if (call->transmoderate == PRI_TRANS_CAP_AUDIO_4ESS)
call->transmoderate = PRI_TRANS_CAP_AUDIO;
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_RATE_ADAPT) {
if (call->userl1 == PRI_LAYER_1_ITU_RATE_ADAPT) {
call->rateadaption = ie->data[++pos] & 0x7f;
}
pos++;
@@ -511,7 +565,7 @@ static int transmit_bearer_capability(struct pri *pri, q931_call *call, int msgt
tc = call->transcapability;
if (pri->switchtype == PRI_SWITCH_ATT4ESS) {
/* 4ESS uses a different trans capability for 3.1khz audio */
if (tc == PRI_TRANS_CAP_AUDIO)
if (tc == PRI_TRANS_CAP_3_1K_AUDIO)
tc = PRI_TRANS_CAP_AUDIO_4ESS;
}
ie->data[0] = 0x80 | tc;
@@ -521,7 +575,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_RATE_ADAPT) {
if (call->userl1 == PRI_LAYER_1_ITU_RATE_ADAPT) {
ie->data[3] = call->rateadaption | 0x80;
return 6;
}
@@ -535,47 +589,31 @@ static int transmit_bearer_capability(struct pri *pri, q931_call *call, int msgt
char *pri_plan2str(int plan)
{
switch(plan) {
case PRI_INTERNATIONAL_ISDN:
return "International number in ISDN";
case PRI_NATIONAL_ISDN:
return "National number in ISDN";
case PRI_LOCAL_ISDN:
return "Local number in ISDN";
case PRI_PRIVATE:
return "Private numbering plan";
case PRI_UNKNOWN:
return "Unknown numbering plan";
default:
return "Unknown";
}
static struct msgtype plans[] = {
{ PRI_INTERNATIONAL_ISDN, "International number in ISDN" },
{ PRI_NATIONAL_ISDN, "National number in ISDN" },
{ PRI_LOCAL_ISDN, "Local number in ISDN" },
{ PRI_PRIVATE, "Private numbering plan" },
{ PRI_UNKNOWN, "Unknown numbering plan" },
};
return code2str(plan, plans, sizeof(plans) / sizeof(plans[0]));
}
char *pri_pres2str(int pres)
{
switch(pres) {
case PRES_ALLOWED_USER_NUMBER_NOT_SCREENED:
return "Presentation permitted, user number not screened";
case PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN:
return "Presentation permitted, user number passed network screening";
case PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN:
return "Presentation permitted, user number failed network screening";
case PRES_ALLOWED_NETWORK_NUMBER:
return "Presentation allowed of network provided number";
case PRES_PROHIB_USER_NUMBER_NOT_SCREENED:
return "Presentation prohibited, user number not screened";
case PRES_PROHIB_USER_NUMBER_PASSED_SCREEN:
return "Presentation prohibited, user number passed network screening";
case PRES_PROHIB_USER_NUMBER_FAILED_SCREEN:
return "Presentation prohibited, user number failed network screening";
case PRES_PROHIB_NETWORK_NUMBER:
return "Presentation prohibbited of network provided number";
default:
return "Unknown";
}
static struct msgtype press[] = {
{ PRES_ALLOWED_USER_NUMBER_NOT_SCREENED, "Presentation permitted, user number not screened" },
{ PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, "Presentation permitted, user number passed network screening" },
{ PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN, "Presentation permitted, user number failed network screening" },
{ PRES_ALLOWED_NETWORK_NUMBER, "Presentation allowed of network provided number" },
{ PRES_PROHIB_USER_NUMBER_NOT_SCREENED, "Presentation prohibited, user number not screened" },
{ PRES_PROHIB_USER_NUMBER_PASSED_SCREEN, "Presentation prohibited, user number passed network screening" },
{ PRES_PROHIB_USER_NUMBER_FAILED_SCREEN, "Presentation prohibited, user number failed network screening" },
{ PRES_PROHIB_NETWORK_NUMBER, "Presentation prohibbited of network provided number" },
};
return code2str(pres, press, sizeof(press) / sizeof(press[0]));
}
static void q931_get_number(unsigned char *num, int maxlen, unsigned char *src, int len)
{
if (len > maxlen - 1) {
@@ -603,6 +641,7 @@ static void dump_calling_party_number(q931_ie *ie, int len, char prefix)
printf("%c Presentation: %s (%d) '%s' ]\n", prefix, pri_pres2str(ie->data[1]), ie->data[1] & 0x7f, cnum);
}
static int receive_called_party_number(struct pri *pri, q931_call *call, int msgtype, q931_ie *ie, int len)
{
q931_get_number(call->callednum, sizeof(call->callednum), ie->data + 1, len - 3);
@@ -637,58 +676,40 @@ static int transmit_calling_party_number(struct pri *pri, q931_call *call, int m
static char *prog2str(int prog)
{
switch(prog) {
case Q931_CALL_NOT_E2E_ISDN:
return "Call is not end-to-end ISDN; further call progress information may be available inband.";
case Q931_CALLED_NOT_ISDN:
return "Called equipment is non-ISDN.";
case Q931_CALLER_NOT_ISDN:
return "Calling equipment is non-ISDN.";
case Q931_INBAND_AVAILABLE:
return "Inband information or appropriate pattern now available.";
case Q931_DELAY_AT_INTERF:
return "Delay in response at called Interface.";
default:
return "Unknown";
}
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." },
};
return code2str(prog, progs, sizeof(progs) / sizeof(progs[0]));
}
static char *coding2str(int cod)
{
switch(cod) {
case CODE_CCITT:
return "CCITT (ITU) standard";
case CODE_NATIONAL:
return "National standard";
case CODE_NETWORK_SPECIFIC:
return "Network specific standard";
default:
return "Unknown";
}
static struct msgtype cods[] = {
{ CODE_CCITT, "CCITT (ITU) standard" },
{ CODE_INTERNATIONAL, "Non-ITU international standard" },
{ CODE_NATIONAL, "National standard" },
{ CODE_NETWORK_SPECIFIC, "Network specific standard" },
};
return code2str(cod, cods, sizeof(cods) / sizeof(cods[0]));
}
static char *loc2str(int loc)
{
switch(loc) {
case LOC_USER:
return "User";
case LOC_PRIV_NET_LOCAL_USER:
return "Private network serving the local user";
case LOC_PUB_NET_LOCAL_USER:
return "Public network serving the local user";
case LOC_TRANSIT_NET:
return "Transit network";
case LOC_PUB_NET_REMOTE_USER:
return "Public network serving the remote user";
case LOC_PRIV_NET_REMOTE_USER:
return "Private network serving the remote user";
case LOC_INTERNATIONAL_NETWORK:
return "International network";
case LOC_NETWORK_BEYOND_INTERWORKING:
return "Network beyond the interworking point";
default:
return "Unknown";
}
static struct msgtype locs[] = {
{ LOC_USER, "User" },
{ LOC_PRIV_NET_LOCAL_USER, "Private network serving the local user" },
{ LOC_PUB_NET_LOCAL_USER, "Public network serving the local user" },
{ LOC_TRANSIT_NET, "Transit network" },
{ LOC_PUB_NET_REMOTE_USER, "Public network serving the remote user" },
{ LOC_PRIV_NET_REMOTE_USER, "Private network serving the remote user" },
{ LOC_INTERNATIONAL_NETWORK, "International network" },
{ LOC_NETWORK_BEYOND_INTERWORKING, "Network beyond the interworking point" },
};
return code2str(loc, locs, sizeof(locs) / sizeof(locs[0]));
}
static void dump_progress_indicator(q931_ie *ie, int len, char prefix)
@@ -722,95 +743,22 @@ static int transmit_progress_indicator(struct pri *pri, q931_call *call, int msg
char *pri_cause2str(int cause)
{
switch(cause) {
case PRI_CAUSE_UNALLOCATED:
return "Unallocated (unassigned) number";
case PRI_CAUSE_NO_ROUTE_TRANSIT_NET:
return "No route to specified transmit network";
case PRI_CAUSE_NO_ROUTE_DESTINATION:
return "No route to destination";
case PRI_CAUSE_CHANNEL_UNACCEPTABLE:
return "Channel unacceptable";
case PRI_CAUSE_CALL_AWARDED_DELIVERED:
return "Call awarded and being delivered in an established channel";
case PRI_CAUSE_NORMAL_CLEARING:
return "Normal Clearing";
case PRI_CAUSE_USER_BUSY:
return "User busy";
case PRI_CAUSE_NO_USER_RESPONSE:
return "No user responding";
case PRI_CAUSE_NO_ANSWER:
return "User alerting, no answer";
case PRI_CAUSE_CALL_REJECTED:
return "Call Rejected";
case PRI_CAUSE_DESTINATION_OUT_OF_ORDER:
return "Destination out of order";
case PRI_CAUSE_INVALID_NUMBER_FORMAT:
return "Invalid number format";
case PRI_CAUSE_RESPONSE_TO_STATUS_ENQUIRY:
return "Response to STATus ENQuiry";
case PRI_CAUSE_NORMAL_UNSPECIFIED:
return "Normal, unspecified";
case PRI_CAUSE_NORMAL_CIRCUIT_CONGESTION:
return "Circuit/channel congestion";
case PRI_CAUSE_NORMAL_TEMPORARY_FAILURE:
return "Temporary failure";
case PRI_CAUSE_SWITCH_CONGESTION:
return "Switching equipment congestion";
case PRI_CAUSE_ACCESS_INFO_DISCARDED:
return "Access information discarded";
case PRI_CAUSE_REQUESTED_CHAN_UNAVAIL:
return "Requested channel not available";
case PRI_CAUSE_BEARERCAPABILITY_NOTAUTH:
return "Bearer capability not authorized";
case PRI_CAUSE_BEARERCAPABILITY_NOTIMPL:
return "Bearer capability not implemented";
case PRI_CAUSE_INVALID_CALL_REFERENCE:
return "Invalid call reference value";
case PRI_CAUSE_INCOMPATIBLE_DESTINATION:
return "Incompatible destination";
case PRI_CAUSE_MANDATORY_IE_MISSING:
return "Mandatory information element is missing";
case PRI_CAUSE_MESSAGE_TYPE_NONEXIST:
return "Message type nonexist.";
case PRI_CAUSE_IE_NONEXIST:
return "Info. element nonexist or not implemented";
case PRI_CAUSE_INVALID_IE_CONTENTS:
return "Invalid information element contents";
case PRI_CAUSE_WRONG_CALL_STATE:
return "Message not compatible with call state";
case PRI_CAUSE_RECOVERY_ON_TIMER_EXPIRE:
return "Recover on timer expiry";
case PRI_CAUSE_PROTOCOL_ERROR:
return "Protocol error, unspecified";
case PRI_CAUSE_INTERWORKING:
return "Interworking, unspecified";
default:
return "Unknown";
}
return code2str(cause, causes, sizeof(causes) / sizeof(causes[0]));
}
static char *pri_causeclass2str(int cause)
{
switch(cause) {
case 0:
case 1:
return "Normal Event";
case 2:
return "Network Congestion";
case 3:
return "Service or Option not Available";
case 4:
return "Service or Option not Implemented";
case 5:
return "Invalid message";
case 6:
return "Protocol Error";
case 7:
return "Interworking";
default:
return "Unknown";
}
static struct msgtype causeclasses[] = {
{ 0, "Normal Event" },
{ 1, "Normal Event" },
{ 2, "Network Congestion" },
{ 3, "Service or Option not Available" },
{ 4, "Service or Option not Implemented" },
{ 5, "Invalid message" },
{ 6, "Protocol Error" },
{ 7, "Interworking" },
};
return code2str(cause, causeclasses, sizeof(causeclasses) / sizeof(causeclasses[0]));
}
static void dump_cause(q931_ie *ie, int len, char prefix)
@@ -834,6 +782,12 @@ static int receive_cause(struct pri *pri, q931_call *call, int msgtype, q931_ie
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) {
@@ -846,6 +800,16 @@ static int transmit_cause(struct pri *pri, q931_call *call, int msgtype, q931_ie
}
}
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" },
@@ -872,6 +836,31 @@ struct ie ies[] = {
{ Q931_RESTART_INDICATOR, "Restart Indicator", dump_restart_indicator, receive_restart_indicator, transmit_restart_indicator },
{ Q931_LOW_LAYER_COMPAT, "Low-layer Compatibility" },
{ Q931_HIGH_LAYER_COMPAT, "High-layer Compatibility" },
{ Q931_PACKET_SIZE, "Packet Size" },
{ Q931_IE_FACILITY, "Facility" },
{ Q931_IE_REDIRECTION_NUMBER, "Redirection Number" },
{ Q931_IE_REDIRECTION_SUBADDR, "Redirection Subaddress" },
{ Q931_IE_FEATURE_ACTIVATE, "Feature Activation" },
{ 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_ENDPOINT_ID, "Endpoint Identification" },
{ Q931_IE_NOTIFY_IND, "Notification Indicator" },
{ Q931_IE_DISPLAY, "Display" },
{ Q931_IE_TIME_DATE, "Date/Time" },
{ Q931_IE_KEYPAD_FACILITY, "Keypad Facility" },
{ Q931_IE_SIGNAL, "Signal" },
{ Q931_IE_SWITCHHOOK, "Switch-hook" },
{ Q931_IE_USER_USER, "User-User" },
{ Q931_IE_ESCAPE_FOR_EXT, "Escape for Extension" },
{ Q931_IE_CALL_STATUS, "Call Status" },
{ Q931_IE_CHANGE_STATUS, "Change Status" },
{ Q931_IE_CONNECTED_NUM, "Connected Number" },
{ 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 },
};
static char *ie2str(int ie)
@@ -1008,7 +997,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);
@@ -1024,14 +1014,11 @@ static int add_ie(struct pri *pri, q931_call *call, int msgtype, int ie, q931_ie
static char *disc2str(int disc)
{
switch(disc) {
case Q931_PROTOCOL_DISCRIMINATOR:
return "Q.931";
case 0x3:
return "AT&T Maintenance";
default:
return "Unknown";
}
static struct msgtype discs[] = {
{ Q931_PROTOCOL_DISCRIMINATOR, "Q.931" },
{ 0x3, "AT&T Maintenance" },
};
return code2str(disc, discs, sizeof(discs) / sizeof(discs[0]));
}
static void q931_dump(q931_h *h, int len, int txrx)
@@ -1069,7 +1056,8 @@ static int q931_handle_ie(struct pri *pri, q931_call *c, int msg, q931_ie *ie)
if (ies[x].receive)
return ies[x].receive(pri, c, msg, ie, ielen(ie));
else {
fprintf(stderr, "!! No handler for IE %d (%s)\n", ie->ie, ie2str(ie->ie));
if (pri->debug & PRI_DEBUG_Q931_ANOMALY)
fprintf(stderr, "!! No handler for IE %d (%s)\n", ie->ie, ie2str(ie->ie));
return -1;
}
}
@@ -1213,17 +1201,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;
@@ -1232,7 +1221,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;
@@ -1243,7 +1234,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)) {
@@ -1258,7 +1249,7 @@ 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;
@@ -1369,6 +1360,31 @@ int q931_receive(struct pri *pri, q931_h *h, int len)
c->causeloc = -1;
c->callstate = -1;
break;
case Q931_SETUP_ACKNOWLEDGE:
case Q931_RESTART_ACKNOWLEDGE:
case Q931_STATUS_ENQUIRY:
case Q931_USER_INFORMATION:
case Q931_SEGMENT:
case Q931_CONGESTION_CONTROL:
case Q931_INFORMATION:
case Q931_FACILITY:
case Q931_NOTIFY:
case Q931_HOLD:
case Q931_HOLD_ACKNOWLEDGE:
case Q931_HOLD_REJECT:
case Q931_RETRIEVE:
case Q931_RETRIEVE_ACKNOWLEDGE:
case Q931_RETRIEVE_REJECT:
case Q931_RESUME:
case Q931_RESUME_ACKNOWLEDGE:
case Q931_RESUME_REJECT:
case Q931_SUSPEND:
case Q931_SUSPEND_ACKNOWLEDGE:
case Q931_SUSPEND_REJECT:
fprintf(stderr, "!! Not yet handling post-handle message type %s (%d)\n", msg2str(mh->msg), mh->msg);
return -1;
default:
fprintf(stderr, "!! Don't know how to pre-handle message type %s (%d)\n", msg2str(mh->msg), mh->msg);
return -1;
@@ -1403,12 +1419,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;
@@ -1431,7 +1448,8 @@ int q931_receive(struct pri *pri, q931_h *h, int len)
case Q931_CONNECT_ACKNOWLEDGE:
case Q931_STATUS:
/* Do nothing */
if (c->cause != PRI_CAUSE_INTERWORKING)
if ((pri->debug & PRI_DEBUG_Q931_ANOMALY) &&
(c->cause != PRI_CAUSE_INTERWORKING))
fprintf(stderr, "Received unsolicited status: %s\n", pri_cause2str(c->cause));
break;
case Q931_CALL_PROCEEDING:
@@ -1460,7 +1478,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 */
@@ -1479,6 +1500,30 @@ int q931_receive(struct pri *pri, q931_h *h, int len)
pri->ev.hangup.call = c;
return Q931_RES_HAVEEVENT;
case Q931_SETUP_ACKNOWLEDGE:
case Q931_RESTART_ACKNOWLEDGE:
case Q931_STATUS_ENQUIRY:
case Q931_USER_INFORMATION:
case Q931_SEGMENT:
case Q931_CONGESTION_CONTROL:
case Q931_INFORMATION:
case Q931_FACILITY:
case Q931_NOTIFY:
case Q931_HOLD:
case Q931_HOLD_ACKNOWLEDGE:
case Q931_HOLD_REJECT:
case Q931_RETRIEVE:
case Q931_RETRIEVE_ACKNOWLEDGE:
case Q931_RETRIEVE_REJECT:
case Q931_RESUME:
case Q931_RESUME_ACKNOWLEDGE:
case Q931_RESUME_REJECT:
case Q931_SUSPEND:
case Q931_SUSPEND_ACKNOWLEDGE:
case Q931_SUSPEND_REJECT:
fprintf(stderr, "!! Not yet handling post-handle message type %s (%d)\n", msg2str(mh->msg), mh->msg);
return -1;
default:
fprintf(stderr, "!! Don't know how to post-handle message type %s (%d)\n", msg2str(mh->msg), mh->msg);
return -1;