diff --git a/pri_q921.h b/pri_q921.h index c4217f9..554cdb5 100755 --- a/pri_q921.h +++ b/pri_q921.h @@ -148,7 +148,7 @@ typedef enum q921_state { } q921_state; /* Dumps a *known good* Q.921 packet */ -extern void q921_dump(q921_h *h, int len, int showraw, int txrx); +extern void q921_dump(struct pri *pri, q921_h *h, int len, int showraw, int txrx); /* Bring up the D-channel */ extern void q921_start(struct pri *pri, int now); diff --git a/q921.c b/q921.c index f857373..416cacc 100755 --- a/q921.c +++ b/q921.c @@ -78,7 +78,7 @@ static int q921_transmit(struct pri *pri, q921_h *h, int len) #endif /* Just send it raw */ if (pri->debug & PRI_DEBUG_Q921_DUMP) - q921_dump(h, len, pri->debug & PRI_DEBUG_Q921_RAW, 1); + q921_dump(pri, h, len, pri->debug & PRI_DEBUG_Q921_RAW, 1); /* Write an extra two bytes for the FCS */ res = write(pri->fd, h, len + 2); if (res != (len + 2)) { @@ -486,13 +486,27 @@ static pri_event *q921_handle_iframe(struct pri *pri, q921_i *i, int len) return NULL; } -void q921_dump(q921_h *h, int len, int showraw, int txrx) +void q921_dump(struct pri *pri, q921_h *h, int len, int showraw, int txrx) { int x; char *type; char direction_tag; + char *cmd_rsp; direction_tag = txrx ? '>' : '<'; + /* If we are PRI_CPE: Use "Command" if we are transmitting and C/R bit is 0. + * Use "Response" if we are transmitting and C/R bit is 1. + * Use "Command" if we are receiving and C/R bit is 1. + * Use "Response" if we are receiving and C/R bit is 0. + * + * If we are PRI_NETWORK: Use "Command" if we are transmitting and C/R bit is 1. + * Use "Response" if we are transmitting and C/R bit is 0. + * Use "Command" if we are receiving and C/R bit is 0. + * Use "Response" if we are receiving and C/R bit is 1. + */ + cmd_rsp = (((pri->localtype == PRI_CPE)?0:1) ^ txrx ^ h->h.c_r) ? "Command" : "Response"; + + if (showraw) { char *buf = malloc(len * 3 + 1); int buflen = 0; @@ -518,12 +532,13 @@ void q921_dump(q921_h *h, int len, int showraw, int txrx) } pri_message( -"%c SAPI: %02d C/R: %d EA: %d\n" +"%c SAPI: %02d C/R: %d EA: %d [%s]\n" "%c TEI: %03d EA: %d\n", direction_tag, h->h.sapi, h->h.c_r, h->h.ea1, + cmd_rsp, direction_tag, h->h.tei, h->h.ea2); @@ -686,7 +701,7 @@ static pri_event *__q921_receive(struct pri *pri, q921_h *h, int len) len -= 2; if (pri->debug & PRI_DEBUG_Q921_DUMP) - q921_dump(h, len, pri->debug & PRI_DEBUG_Q921_RAW, 0); + q921_dump(pri, h, len, pri->debug & PRI_DEBUG_Q921_RAW, 0); /* Check some reject conditions -- Start by rejecting improper ea's */ if (h->h.ea1 || !(h->h.ea2)) diff --git a/q931.c b/q931.c index e1c6d9b..6f8a1c3 100755 --- a/q931.c +++ b/q931.c @@ -1149,7 +1149,7 @@ 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) { - pri_message("%c Sending Complete (len=%2d)\n", prefix, ie->len); + pri_message("%c Sending Complete.\n", prefix); } static int receive_sending_complete(struct pri *pri, q931_call *call, int msgtype, q931_ie *ie, int len) @@ -1410,7 +1410,8 @@ void q931_dump(q931_h *h, int len, int txrx) int x=0, r; c = txrx ? '>' : '<'; pri_message("%c Protocol Discriminator: %s (%d) len=%d\n", c, disc2str(h->pd), h->pd, len); - pri_message("%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"); + pri_message("%c Call Ref: len=%2d (reference %d/0x%X) (%s)\n", + c, h->crlen, q931_cr(h) & 0x7fff, q931_cr(h) & 0x7fff, (q931_cr(h) & 0x8000) ? "Terminator" : "Originator"); /* Message header begins at the end of the call reference number */ mh = (q931_mh *)(h->contents + h->crlen); pri_message("%c Message type: %s (%d)\n", c, msg2str(mh->msg), mh->msg);