From 17649b363b27cadfb28541d645fe3f9c692b3a39 Mon Sep 17 00:00:00 2001 From: Kinsey Moore Date: Fri, 3 Feb 2012 23:12:57 +0000 Subject: [PATCH] Make PRI_DEBUG_Q921_RAW work independantly of PRI_DEBUG_Q921_DUMP Ensure that the DUMP and RAW flags work independently in q921_dump(). (closes issue PRI-119) Patch-by: wimpy git-svn-id: https://origsvn.digium.com/svn/libpri/branches/1.4@2282 2fbb986a-6c06-0410-b554-c9c1f0a7f128 --- pri_q921.h | 2 +- pridump.c | 2 +- q921.c | 238 +++++++++++++++++++++++++++-------------------------- 3 files changed, 123 insertions(+), 119 deletions(-) diff --git a/pri_q921.h b/pri_q921.h index 2452d19..22bb9fe 100644 --- a/pri_q921.h +++ b/pri_q921.h @@ -273,7 +273,7 @@ static inline int Q921_ADD(int a, int b) } /* Dumps a *known good* Q.921 packet */ -extern void q921_dump(struct pri *pri, q921_h *h, int len, int showraw, int txrx); +extern void q921_dump(struct pri *pri, q921_h *h, int len, int debugflags, int txrx); /* Bring up the D-channel */ void q921_start(struct q921_link *link); diff --git a/pridump.c b/pridump.c index a43e473..45978d1 100644 --- a/pridump.c +++ b/pridump.c @@ -71,7 +71,7 @@ static int pri_open(char *dev) static void dump_packet(struct pri *pri, char *buf, int len, int txrx) { q921_h *h = (q921_h *)buf; - q921_dump(pri, h, len, 1, txrx); + q921_dump(pri, h, len, PRI_DEBUG_ALL, txrx); if (!((h->h.data[0] & Q921_FRAMETYPE_MASK) & 0x3)) { q931_dump(pri, h->h.tei, (q931_h *)(h->i.data), len - 4 - 2 /* FCS */, txrx); } diff --git a/q921.c b/q921.c index 5b5cfed..093c9fa 100644 --- a/q921.c +++ b/q921.c @@ -186,7 +186,7 @@ static int q921_transmit(struct pri *ctrl, q921_h *h, int len) ctrl->q921_txcount++; /* Just send it raw */ if (ctrl->debug & (PRI_DEBUG_Q921_DUMP | PRI_DEBUG_Q921_RAW)) - q921_dump(ctrl, h, len, ctrl->debug & PRI_DEBUG_Q921_RAW, 1); + q921_dump(ctrl, h, len, ctrl->debug, 1); /* Write an extra two bytes for the FCS */ res = ctrl->write_func ? ctrl->write_func(ctrl, h, len + 2) : 0; if (res != (len + 2)) { @@ -1187,7 +1187,7 @@ static void q921_dump_iqueue_info(struct q921_link *link) static void q921_dump_pri_by_h(struct pri *ctrl, char direction_tag, q921_h *h); -void q921_dump(struct pri *ctrl, q921_h *h, int len, int showraw, int txrx) +void q921_dump(struct pri *ctrl, q921_h *h, int len, int debugflags, int txrx) { int x; const char *type; @@ -1196,9 +1196,11 @@ void q921_dump(struct pri *ctrl, q921_h *h, int len, int showraw, int txrx) direction_tag = txrx ? '>' : '<'; pri_message(ctrl, "\n"); - q921_dump_pri_by_h(ctrl, direction_tag, h); + if (debugflags & PRI_DEBUG_Q921_DUMP) { + q921_dump_pri_by_h(ctrl, direction_tag, h); + } - if (showraw) { + if (debugflags & PRI_DEBUG_Q921_RAW) { char *buf = malloc(len * 3 + 1); int buflen = 0; if (buf) { @@ -1209,132 +1211,134 @@ void q921_dump(struct pri *ctrl, q921_h *h, int len, int showraw, int txrx) } } - switch (h->h.data[0] & Q921_FRAMETYPE_MASK) { - case 0: - case 2: - pri_message(ctrl, "%c Informational frame:\n", direction_tag); - break; - case 1: - pri_message(ctrl, "%c Supervisory frame:\n", direction_tag); - break; - case 3: - pri_message(ctrl, "%c Unnumbered frame:\n", direction_tag); - break; - } - - pri_message(ctrl, "%c SAPI: %02d C/R: %d EA: %d\n", - direction_tag, - h->h.sapi, - h->h.c_r, - h->h.ea1); - pri_message(ctrl, "%c TEI: %03d EA: %d\n", - direction_tag, - h->h.tei, - h->h.ea2); - - switch (h->h.data[0] & Q921_FRAMETYPE_MASK) { - case 0: - case 2: - /* Informational frame */ - pri_message(ctrl, "%c N(S): %03d 0: %d\n", - direction_tag, - h->i.n_s, - h->i.ft); - pri_message(ctrl, "%c N(R): %03d P: %d\n", - direction_tag, - h->i.n_r, - h->i.p_f); - pri_message(ctrl, "%c %d bytes of data\n", - direction_tag, - len - 4); - break; - case 1: - /* Supervisory frame */ - type = "???"; - switch (h->s.ss) { + if (debugflags & PRI_DEBUG_Q921_DUMP) { + switch (h->h.data[0] & Q921_FRAMETYPE_MASK) { case 0: - type = "RR (receive ready)"; + case 2: + pri_message(ctrl, "%c Informational frame:\n", direction_tag); break; case 1: - type = "RNR (receive not ready)"; + pri_message(ctrl, "%c Supervisory frame:\n", direction_tag); break; - case 2: - type = "REJ (reject)"; + case 3: + pri_message(ctrl, "%c Unnumbered frame:\n", direction_tag); break; } - pri_message(ctrl, "%c Zero: %d S: %d 01: %d [ %s ]\n", - direction_tag, - h->s.x0, - h->s.ss, - h->s.ft, - type); - pri_message(ctrl, "%c N(R): %03d P/F: %d\n", + + pri_message(ctrl, "%c SAPI: %02d C/R: %d EA: %d\n", direction_tag, - h->s.n_r, - h->s.p_f); - pri_message(ctrl, "%c %d bytes of data\n", + h->h.sapi, + h->h.c_r, + h->h.ea1); + pri_message(ctrl, "%c TEI: %03d EA: %d\n", direction_tag, - len - 4); - break; - case 3: - /* Unnumbered frame */ - type = "???"; - if (h->u.ft == 3) { - switch (h->u.m3) { + h->h.tei, + h->h.ea2); + + switch (h->h.data[0] & Q921_FRAMETYPE_MASK) { + case 0: + case 2: + /* Informational frame */ + pri_message(ctrl, "%c N(S): %03d 0: %d\n", + direction_tag, + h->i.n_s, + h->i.ft); + pri_message(ctrl, "%c N(R): %03d P: %d\n", + direction_tag, + h->i.n_r, + h->i.p_f); + pri_message(ctrl, "%c %d bytes of data\n", + direction_tag, + len - 4); + break; + case 1: + /* Supervisory frame */ + type = "???"; + switch (h->s.ss) { 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)"; + type = "RR (receive ready)"; 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)"; + case 1: + type = "RNR (receive not ready)"; 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; - default: + case 2: + type = "REJ (reject)"; break; } + pri_message(ctrl, "%c Zero: %d S: %d 01: %d [ %s ]\n", + direction_tag, + h->s.x0, + h->s.ss, + h->s.ft, + type); + pri_message(ctrl, "%c N(R): %03d P/F: %d\n", + direction_tag, + h->s.n_r, + h->s.p_f); + pri_message(ctrl, "%c %d bytes of data\n", + direction_tag, + len - 4); + break; + 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; + default: + break; + } + } + pri_message(ctrl, "%c M3: %d P/F: %d M2: %d 11: %d [ %s ]\n", + direction_tag, + h->u.m3, + h->u.p_f, + h->u.m2, + h->u.ft, + type); + pri_message(ctrl, "%c %d bytes of data\n", + direction_tag, + len - 3); + break; } - pri_message(ctrl, "%c M3: %d P/F: %d M2: %d 11: %d [ %s ]\n", - direction_tag, - h->u.m3, - h->u.p_f, - h->u.m2, - h->u.ft, - type); - pri_message(ctrl, "%c %d bytes of data\n", - direction_tag, - len - 3); - break; - } - - if ((h->u.ft == 3) && (h->u.m3 == 0) && (h->u.m2 == 0) && (h->u.data[0] == 0x0f)) { - int ri; - u_int8_t *action; - - /* TEI management related */ - type = q921_tei_mgmt2str(h->u.data[3]); - pri_message(ctrl, "%c MDL Message: %d(%s)\n", direction_tag, h->u.data[3], type); - ri = (h->u.data[1] << 8) | h->u.data[2]; - pri_message(ctrl, "%c Ri: %d\n", direction_tag, ri); - action = &h->u.data[4]; - for (x = len - (action - (u_int8_t *) h); 0 < x; --x, ++action) { - pri_message(ctrl, "%c Ai: %d E:%d\n", - direction_tag, (*action >> 1) & 0x7f, *action & 0x01); + + if ((h->u.ft == 3) && (h->u.m3 == 0) && (h->u.m2 == 0) && (h->u.data[0] == 0x0f)) { + int ri; + u_int8_t *action; + + /* TEI management related */ + type = q921_tei_mgmt2str(h->u.data[3]); + pri_message(ctrl, "%c MDL Message: %d(%s)\n", direction_tag, h->u.data[3], type); + ri = (h->u.data[1] << 8) | h->u.data[2]; + pri_message(ctrl, "%c Ri: %d\n", direction_tag, ri); + action = &h->u.data[4]; + for (x = len - (action - (u_int8_t *) h); 0 < x; --x, ++action) { + pri_message(ctrl, "%c Ai: %d E:%d\n", + direction_tag, (*action >> 1) & 0x7f, *action & 0x01); + } } } } @@ -3006,7 +3010,7 @@ static pri_event *__q921_receive(struct pri *ctrl, q921_h *h, int len) len -= 2; if (ctrl->debug & (PRI_DEBUG_Q921_DUMP | PRI_DEBUG_Q921_RAW)) { - q921_dump(ctrl, h, len, ctrl->debug & PRI_DEBUG_Q921_RAW, 0); + q921_dump(ctrl, h, len, ctrl->debug, 0); } /* Check some reject conditions -- Start by rejecting improper ea's */