Version 0.3.0 from FTP

git-svn-id: https://origsvn.digium.com/svn/libpri/trunk@21 2fbb986a-6c06-0410-b554-c9c1f0a7f128
This commit is contained in:
Mark Spencer 2002-03-18 13:59:09 +00:00
parent 455227676a
commit a68a6bd01d

118
q921.c
View File

@ -82,7 +82,6 @@ static int q921_transmit(struct pri *pri, q921_h *h, int len) {
return 0; return 0;
} }
static void q921_send_ua(struct pri *pri, int pfbit) static void q921_send_ua(struct pri *pri, int pfbit)
{ {
q921_h h; q921_h h;
@ -134,7 +133,6 @@ static void q921_send_sabme(void *vpri)
printf("Sending Set Asynchronous Balanced Mode Extended\n"); printf("Sending Set Asynchronous Balanced Mode Extended\n");
q921_transmit(pri, &h, 3); q921_transmit(pri, &h, 3);
pri->q921_state = Q921_AWAITING_ESTABLISH; pri->q921_state = Q921_AWAITING_ESTABLISH;
} }
static int q921_ack_packet(struct pri *pri, int num) static int q921_ack_packet(struct pri *pri, int num)
@ -177,7 +175,7 @@ static void q921_ack_rx(struct pri *pri, int ack)
cnt += q921_ack_packet(pri, x); cnt += q921_ack_packet(pri, x);
if (!pri->txqueue) { if (!pri->txqueue) {
if (pri->debug & PRI_DEBUG_Q921_STATE) if (pri->debug & PRI_DEBUG_Q921_STATE)
printf("-- Since there wis nothing left, stopping T200 counter\n"); printf("-- Since there was nothing left, stopping T200 counter\n");
/* Something was ACK'd. Stop T200 counter */ /* Something was ACK'd. Stop T200 counter */
pri_schedule_del(pri, pri->t200_timer); pri_schedule_del(pri, pri->t200_timer);
pri->t200_timer = 0; pri->t200_timer = 0;
@ -202,6 +200,31 @@ static void q921_ack_rx(struct pri *pri, int ack)
} }
} }
static void q921_reject(struct pri *pri)
{
q921_h h;
Q921_INIT(h);
h.s.x0 = 0; /* Always 0 */
h.s.ss = 2; /* Reject */
h.s.ft = 1; /* Frametype (01) */
h.s.n_r = pri->v_r; /* Where to start retransmission */
h.s.p_f = 1; /* XXX Should it always be set to 1? XXX */
switch(pri->localtype) {
case PRI_NETWORK:
h.h.c_r = 0;
break;
case PRI_CPE:
h.h.c_r = 1;
break;
default:
fprintf(stderr, "Don't know how to U/A on a type %d node\n", pri->localtype);
return;
}
if (pri->debug & PRI_DEBUG_Q921_STATE)
printf("Sending Reject (%d)\n", pri->v_r);
q921_transmit(pri, &h, 4);
}
static void q921_rr(struct pri *pri, int pbit) { static void q921_rr(struct pri *pri, int pbit) {
q921_h h; q921_h h;
Q921_INIT(h); Q921_INIT(h);
@ -329,7 +352,7 @@ static void t203_expire(void *vpri)
{ {
struct pri *pri = vpri; struct pri *pri = vpri;
if (pri->debug & PRI_DEBUG_Q921_STATE) 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 */ /* Solicit an F-bit in the other's RR */
pri->solicitfbit = 1; pri->solicitfbit = 1;
q921_rr(pri, 1); q921_rr(pri, 1);
@ -365,7 +388,7 @@ static pri_event *q921_handle_iframe(struct pri *pri, q921_i *i, int len)
/* It's within our window -- send back an RR */ /* It's within our window -- send back an RR */
q921_rr(pri, 0); q921_rr(pri, 0);
} else } 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 #if 0
q931_reject(pri); q931_reject(pri);
#endif #endif
@ -376,37 +399,41 @@ static pri_event *q921_handle_iframe(struct pri *pri, q921_i *i, int len)
void q921_dump(q921_h *h, int len, int showraw, int txrx) void q921_dump(q921_h *h, int len, int showraw, int txrx)
{ {
int x; int x;
char *type;
char direction_tag;
direction_tag = txrx ? '>' : '<';
if (showraw) { if (showraw) {
printf("%c [", (txrx ? '>' : '<')); printf("\n%c [", direction_tag);
for (x=0;x<len;x++) for (x=0;x<len;x++)
printf("%02x ",h->raw[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 0:
case 2: case 2:
printf("\n Informational Frame:\n"); printf("\n%c Informational frame:\n", direction_tag);
break; break;
case 1: case 1:
printf("\n Supervisory frame:\n"); printf("\n%c Supervisory frame:\n", direction_tag);
break; break;
case 3: case 3:
printf("\n Unnumbered frame:\n"); printf("\n%c Unnumbered frame:\n", direction_tag);
break; break;
} }
printf( printf(
"%c SAPI: %02d C/R: %d EA: %d\n" "%c SAPI: %02d C/R: %d EA: %d\n"
"%c TEI: %03d EA: %d\n", "%c TEI: %03d EA: %d\n",
(txrx ? '>' : '<'), direction_tag,
h->h.sapi, h->h.sapi,
h->h.c_r, h->h.c_r,
h->h.ea1, h->h.ea1,
(txrx ? '>' : '<'), direction_tag,
h->h.tei, h->h.tei,
h->h.ea2); h->h.ea2);
switch(h->h.data[0] & Q921_FRAMETYPE_MASK) { switch (h->h.data[0] & Q921_FRAMETYPE_MASK) {
case 0: case 0:
case 2: case 2:
/* Informational frame */ /* Informational frame */
@ -414,42 +441,85 @@ void q921_dump(q921_h *h, int len, int showraw, int txrx)
"%c N(S): %03d 0: %d\n" "%c N(S): %03d 0: %d\n"
"%c N(R): %03d P: %d\n" "%c N(R): %03d P: %d\n"
"%c %d bytes of data\n", "%c %d bytes of data\n",
(txrx ? '>' : '<'), direction_tag,
h->i.n_s, h->i.n_s,
h->i.ft, h->i.ft,
(txrx ? '>' : '<'), direction_tag,
h->i.n_r, h->i.n_r,
h->i.p_f, h->i.p_f,
(txrx ? '>' : '<'), direction_tag,
len - 4); len - 4);
break; break;
case 1: case 1:
/* Supervisory frame */ /* 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( printf(
"%c Zeros: %d S: %d 01: %d\n" "%c Zero: %d S: %d 01: %d [ %s ]\n"
"%c N(R): %03d P/F: %d\n" "%c N(R): %03d P/F: %d\n"
"%c %d bytes of data\n", "%c %d bytes of data\n",
(txrx ? '>' : '<'), direction_tag,
h->s.x0, h->s.x0,
h->s.ss, h->s.ss,
h->s.ft, h->s.ft,
(txrx ? '>' : '<'), type,
direction_tag,
h->s.n_r, h->s.n_r,
h->s.p_f, h->s.p_f,
(txrx ? '>' : '<'), direction_tag,
len - 4); len - 4);
break; break;
case 3: case 3:
/* Unnumbered frame */ /* 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( 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", "%c %d bytes of data\n",
(txrx ? '>' : '<'), direction_tag,
h->u.m3, h->u.m3,
h->u.p_f, h->u.p_f,
h->u.m2, h->u.m2,
h->u.ft, h->u.ft,
(txrx ? '>' : '<'), type,
direction_tag,
len - 3); len - 3);
break; break;
}; };