Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d623b2412e | ||
|
|
63699af574 | ||
|
|
2323c14331 | ||
|
|
9ed9f37ada | ||
|
|
ecca15537d | ||
|
|
0aa2e6fe6c | ||
|
|
c84465ba47 |
5
ChangeLog
Executable file → Normal file
5
ChangeLog
Executable file → Normal file
@@ -1,3 +1,8 @@
|
||||
-- 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.
|
||||
|
||||
16
libpri.h
Executable file → Normal file
16
libpri.h
Executable file → Normal file
@@ -58,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
|
||||
@@ -135,6 +136,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 +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;
|
||||
|
||||
@@ -264,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
25
pri.c
Executable file → Normal 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
3
pri_internal.h
Executable file → Normal 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);
|
||||
|
||||
|
||||
1
pri_q921.h
Executable file → Normal file
1
pri_q921.h
Executable file → Normal 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
|
||||
|
||||
|
||||
5
pri_q931.h
Executable file → Normal file
5
pri_q931.h
Executable file → Normal file
@@ -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);
|
||||
|
||||
#endif
|
||||
|
||||
13
prisched.c
Executable file → Normal file
13
prisched.c
Executable file → Normal 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)
|
||||
|
||||
97
q921.c
Executable file → Normal file
97
q921.c
Executable file → Normal 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)
|
||||
@@ -474,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;
|
||||
|
||||
@@ -534,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:
|
||||
|
||||
80
q931.c
Executable file → Normal file
80
q931.c
Executable file → Normal file
@@ -131,16 +131,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
|
||||
@@ -184,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) */
|
||||
@@ -242,6 +233,7 @@ 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;
|
||||
@@ -477,15 +469,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]));
|
||||
}
|
||||
@@ -530,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_ITU_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 {
|
||||
@@ -555,7 +547,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 +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_ITU_RATE_ADAPT) {
|
||||
if (call->userl1 == PRI_LAYER_1_ITU_RATE_ADAPT) {
|
||||
ie->data[3] = call->rateadaption | 0x80;
|
||||
return 6;
|
||||
}
|
||||
@@ -649,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);
|
||||
@@ -789,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) {
|
||||
@@ -801,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" },
|
||||
@@ -851,6 +860,7 @@ struct ie ies[] = {
|
||||
{ Q931_IE_ORIGINAL_CALLED_NUMBER, "Original Called Number" },
|
||||
{ Q931_IE_USER_USER_FACILITY, "User-User Facility" },
|
||||
{ Q931_IE_UPDATE, "Update" },
|
||||
{ Q931_SENDING_COMPLETE, "Sending Complete", NULL, receive_sending_complete, transmit_sending_complete },
|
||||
};
|
||||
|
||||
static char *ie2str(int ie)
|
||||
@@ -987,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);
|
||||
@@ -1190,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;
|
||||
|
||||
@@ -1209,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;
|
||||
@@ -1220,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)) {
|
||||
@@ -1235,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;
|
||||
@@ -1405,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;
|
||||
@@ -1463,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 */
|
||||
|
||||
Reference in New Issue
Block a user