2 * Copyright (c) 1996 Gary Jennejohn. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. Neither the name of the author nor the names of any co-contributors
13 * may be used to endorse or promote products derived from this software
14 * without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 *---------------------------------------------------------------------------*
30 * q.921.c - print Q.921 traces
31 * ----------------------------
33 * $Id: q921.c,v 1.2 2003/10/06 09:43:28 itojun Exp $
37 * last edit-date: [Mon Dec 13 21:56:46 1999]
39 *---------------------------------------------------------------------------*/
43 /*---------------------------------------------------------------------------*
44 * decode LAPD (Q.921) protocol
45 *---------------------------------------------------------------------------*/
47 decode_lapd(char *pbuf
, int n
, unsigned char *buf
, int dir
, int raw
, int printit
)
49 int sap
, tei
, cmd
, p_f
;
53 char *lbufp
= &locbuf
[0];
58 sap
= (buf
[0] >> 2) & 0x3f;
71 /* SAPI control procedures */
75 sprintf((lbufp
+strlen(lbufp
)), "Q921: SAP=%d (Call Control), %c, TEI=%d, ", sap
, cmd
?'C':'R', tei
);
77 if ((buf
[2] & 0x01) == 0)
80 sprintf((lbufp
+strlen(lbufp
)), "I-Frame: ");
85 sprintf((lbufp
+strlen(lbufp
)), "N(S) %d N(R) %d P %d ", buf
[2] >> 1, buf
[3] >> 1, p_f
);
89 else if ((buf
[2] & 0x03) == 0x01)
92 sprintf((lbufp
+strlen(lbufp
)), "S-Frame: ");
100 sprintf((lbufp
+strlen(lbufp
)), "RR N(R) %d PF %d ", buf
[3] >> 1, p_f
);
102 sprintf((lbufp
+strlen(lbufp
)), "RNR N(R) %d PF %d ", buf
[3] >> 1, p_f
);
104 sprintf((lbufp
+strlen(lbufp
)), "REJ N(R) %d PF %d ", buf
[3] >> 1, p_f
);
108 else if ((buf
[2] & 0x03) == 0x03)
111 sprintf((lbufp
+strlen(lbufp
)), "U-Frame: ");
113 p_f
= (buf
[2] & 0x10) >> 4;
114 cmd
= buf
[2] & 0xec;
119 sprintf((lbufp
+strlen(lbufp
)), "SABME PF %d ", p_f
);
121 sprintf((lbufp
+strlen(lbufp
)), "DM PF %d ", p_f
);
123 sprintf((lbufp
+strlen(lbufp
)), "UI PF %d ", p_f
);
125 sprintf((lbufp
+strlen(lbufp
)), "DISC PF %d ", p_f
);
127 sprintf((lbufp
+strlen(lbufp
)), "UA PF %d ", p_f
);
129 sprintf((lbufp
+strlen(lbufp
)), "FRMR PF %d ", p_f
);
131 sprintf((lbufp
+strlen(lbufp
)), "XID PF %d ", p_f
);
132 /* information field ??? */
143 sprintf((lbufp
+strlen(lbufp
)), "Q921: SAP=%d (X.25), %c, TEI=%d, ", sap
, cmd
?'C':'R', tei
);
151 sprintf((lbufp
+strlen(lbufp
)), "Q921: SAP=%d (Loopbacktest), %c, TEI=%d, ", sap
, cmd
?'C':'R', tei
);
155 /* SAPI layer 2 management functions */
160 sprintf((lbufp
+strlen(lbufp
)), "Q921: SAP=%d (TEI-Management), %c, TEI=%d, ", sap
, cmd
?'C':'R', tei
);
165 sprintf((lbufp
+strlen(lbufp
)), "ILLEGAL TEI\n");
170 if (buf
[2] != 3 && buf
[3] != 0xf)
173 sprintf((lbufp
+strlen(lbufp
)), "invalid format!\n");
177 cnt
+= 2; /* UI + MEI */
180 sprintf((lbufp
+strlen(lbufp
)), "Ri=0x%04hx, ", *(short *)&buf
[4]);
187 sprintf((lbufp
+strlen(lbufp
)), "IdRequest, Ai=%d", (buf
[7] >> 1));
192 sprintf((lbufp
+strlen(lbufp
)), "IdAssign, Ai=%d", (buf
[7] >> 1));
197 sprintf((lbufp
+strlen(lbufp
)), "IdDenied, Ai=%d", (buf
[7] >> 1));
202 sprintf((lbufp
+strlen(lbufp
)), "IdCheckReq, Ai=%d", (buf
[7] >> 1));
207 sprintf((lbufp
+strlen(lbufp
)), "IdCheckResp, Ai=%d", (buf
[7] >> 1));
212 sprintf((lbufp
+strlen(lbufp
)), "IdRemove, Ai=%d", (buf
[7] >> 1));
217 sprintf((lbufp
+strlen(lbufp
)), "IdVerify, Ai=%d", (buf
[7] >> 1));
222 sprintf((lbufp
+strlen(lbufp
)), "Unknown Msg Type\n");
233 sprintf((lbufp
+strlen(lbufp
)), "Q921: ERROR, SAP=%d (Illegal SAPI), %c, TEI=%d\n", sap
, cmd
?'C':'R', tei
);
240 sprintf((lbufp
+strlen(lbufp
)), "\n");
245 for (i
= 0; i
< cnt
; i
+= 16)
247 sprintf((pbuf
+strlen(pbuf
)),"Dump:%.3d ", i
);
248 for (j
= 0; j
< 16; j
++)
250 sprintf((pbuf
+strlen(pbuf
)),"%02x ", buf
[i
+ j
]);
252 sprintf((pbuf
+strlen(pbuf
))," ");
253 sprintf((pbuf
+strlen(pbuf
))," ");
254 for (j
= 0; j
< 16 && i
+ j
< cnt
; j
++)
255 if (isprint(buf
[i
+ j
]))
256 sprintf((pbuf
+strlen(pbuf
)),"%c", buf
[i
+ j
]);
258 sprintf((pbuf
+strlen(pbuf
)),".");
259 sprintf((pbuf
+strlen(pbuf
)),"\n");
263 sprintf((pbuf
+strlen(pbuf
)),"%s", &locbuf
[0]);