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
This commit is contained in:
Kinsey Moore 2012-02-03 23:12:57 +00:00
parent 2c159d4685
commit 17649b363b
3 changed files with 123 additions and 119 deletions

View File

@ -273,7 +273,7 @@ static inline int Q921_ADD(int a, int b)
} }
/* Dumps a *known good* Q.921 packet */ /* 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 */ /* Bring up the D-channel */
void q921_start(struct q921_link *link); void q921_start(struct q921_link *link);

View File

@ -71,7 +71,7 @@ static int pri_open(char *dev)
static void dump_packet(struct pri *pri, char *buf, int len, int txrx) static void dump_packet(struct pri *pri, char *buf, int len, int txrx)
{ {
q921_h *h = (q921_h *)buf; 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)) { 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); q931_dump(pri, h->h.tei, (q931_h *)(h->i.data), len - 4 - 2 /* FCS */, txrx);
} }

234
q921.c
View File

@ -186,7 +186,7 @@ static int q921_transmit(struct pri *ctrl, q921_h *h, int len)
ctrl->q921_txcount++; ctrl->q921_txcount++;
/* Just send it raw */ /* Just send it raw */
if (ctrl->debug & (PRI_DEBUG_Q921_DUMP | PRI_DEBUG_Q921_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 */ /* Write an extra two bytes for the FCS */
res = ctrl->write_func ? ctrl->write_func(ctrl, h, len + 2) : 0; res = ctrl->write_func ? ctrl->write_func(ctrl, h, len + 2) : 0;
if (res != (len + 2)) { 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); 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; int x;
const char *type; 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 ? '>' : '<'; direction_tag = txrx ? '>' : '<';
pri_message(ctrl, "\n"); 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); char *buf = malloc(len * 3 + 1);
int buflen = 0; int buflen = 0;
if (buf) { 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) { if (debugflags & PRI_DEBUG_Q921_DUMP) {
case 0: switch (h->h.data[0] & Q921_FRAMETYPE_MASK) {
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) {
case 0: case 0:
type = "RR (receive ready)"; case 2:
pri_message(ctrl, "%c Informational frame:\n", direction_tag);
break; break;
case 1: case 1:
type = "RNR (receive not ready)"; pri_message(ctrl, "%c Supervisory frame:\n", direction_tag);
break; break;
case 2: case 3:
type = "REJ (reject)"; pri_message(ctrl, "%c Unnumbered frame:\n", direction_tag);
break; break;
} }
pri_message(ctrl, "%c Zero: %d S: %d 01: %d [ %s ]\n",
pri_message(ctrl, "%c SAPI: %02d C/R: %d EA: %d\n",
direction_tag, direction_tag,
h->s.x0, h->h.sapi,
h->s.ss, h->h.c_r,
h->s.ft, h->h.ea1);
type); pri_message(ctrl, "%c TEI: %03d EA: %d\n",
pri_message(ctrl, "%c N(R): %03d P/F: %d\n",
direction_tag, direction_tag,
h->s.n_r, h->h.tei,
h->s.p_f); h->h.ea2);
pri_message(ctrl, "%c %d bytes of data\n",
direction_tag, switch (h->h.data[0] & Q921_FRAMETYPE_MASK) {
len - 4); case 0:
break; case 2:
case 3: /* Informational frame */
/* Unnumbered frame */ pri_message(ctrl, "%c N(S): %03d 0: %d\n",
type = "???"; direction_tag,
if (h->u.ft == 3) { h->i.n_s,
switch (h->u.m3) { 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: case 0:
if (h->u.m2 == 3) type = "RR (receive ready)";
type = "DM (disconnect mode)"; break;
else if (h->u.m2 == 0) case 1:
type = "UI (unnumbered information)"; type = "RNR (receive not ready)";
break; break;
case 2: case 2:
if (h->u.m2 == 0) type = "REJ (reject)";
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; 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)) { if ((h->u.ft == 3) && (h->u.m3 == 0) && (h->u.m2 == 0) && (h->u.data[0] == 0x0f)) {
int ri; int ri;
u_int8_t *action; u_int8_t *action;
/* TEI management related */ /* TEI management related */
type = q921_tei_mgmt2str(h->u.data[3]); type = q921_tei_mgmt2str(h->u.data[3]);
pri_message(ctrl, "%c MDL Message: %d(%s)\n", direction_tag, h->u.data[3], type); 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]; ri = (h->u.data[1] << 8) | h->u.data[2];
pri_message(ctrl, "%c Ri: %d\n", direction_tag, ri); pri_message(ctrl, "%c Ri: %d\n", direction_tag, ri);
action = &h->u.data[4]; action = &h->u.data[4];
for (x = len - (action - (u_int8_t *) h); 0 < x; --x, ++action) { for (x = len - (action - (u_int8_t *) h); 0 < x; --x, ++action) {
pri_message(ctrl, "%c Ai: %d E:%d\n", pri_message(ctrl, "%c Ai: %d E:%d\n",
direction_tag, (*action >> 1) & 0x7f, *action & 0x01); 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; len -= 2;
if (ctrl->debug & (PRI_DEBUG_Q921_DUMP | PRI_DEBUG_Q921_RAW)) { 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 */ /* Check some reject conditions -- Start by rejecting improper ea's */