2 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 static const char rcsid
[] _U_
=
24 "@(#)$Header: /tcpdump/master/tcpdump/print-fr.c,v 1.17.2.4 2004-04-02 06:53:51 guy Exp $ (LBL)";
31 #include <tcpdump-stdinc.h>
37 #include "addrtoname.h"
38 #include "interface.h"
39 #include "ethertype.h"
42 static void lmi_print(const u_char
*, u_int
);
44 #define NLPID_LMI 0x08 /* ANSI T1.617 Annex D or ITU-T Q.933 Annex A */
45 #define NLPID_CISCO_LMI 0x09 /* The original, aka Cisco, aka Gang of Four */
46 #define NLPID_SNAP 0x80
47 #define NLPID_CLNP 0x81
48 #define NLPID_ESIS 0x82
49 #define NLPID_ISIS 0x83
50 #define NLPID_CONS 0x84
51 #define NLPID_IDRP 0x85
52 #define NLPID_X25_ESIS 0x8a
53 #define NLPID_IPV6 0x8e
56 #define FR_EA_BIT 0x01
59 /* Finds out Q.922 address length, DLCI and flags. Returns 0 on success */
60 static int parse_q922_addr(const u_char
*p
, u_int
*dlci
, u_int
*addr_len
,
63 static char flags
[32];
66 if ((p
[0] & FR_EA_BIT
))
71 *dlci
= ((p
[0] & 0xFC) << 2) | ((p
[1] & 0xF0) >> 4);
73 strcpy(flags
, (p
[0] & 0x02) ? "C!, " : "");
75 strcat(flags
, "FECN, ");
77 strcat(flags
, "BECN, ");
79 strcat(flags
, "DE, ");
83 flags
[len
- 2] = '\x0'; /* delete trailing comma and space */
86 return 0; /* 2-byte Q.922 address */
89 (*addr_len
)++; /* 3- or 4-byte Q.922 address */
90 if ((p
[0] & FR_EA_BIT
) == 0) {
91 *dlci
= (*dlci
<< 7) | (p
[0] >> 1);
92 (*addr_len
)++; /* 4-byte Q.922 address */
96 if ((p
[0] & FR_EA_BIT
) == 0)
97 return -1; /* more than 4 bytes of Q.922 address? */
101 snprintf(flags
+ len
, sizeof(flags
) - len
,
102 "%sdlcore %x", len
? ", " : "", p
[0] >> 2);
104 *dlci
= (*dlci
<< 6) | (p
[0] >> 2);
110 static const char *fr_nlpids
[256];
116 static int fr_nlpid_flag
= 0;
118 if (!fr_nlpid_flag
) {
119 for (i
=0; i
< 256; i
++)
121 fr_nlpids
[NLPID_LMI
] = "LMI";
122 fr_nlpids
[NLPID_CISCO_LMI
] = "Cisco LMI";
123 fr_nlpids
[NLPID_SNAP
] = "SNAP";
124 fr_nlpids
[NLPID_CLNP
] = "CLNP";
125 fr_nlpids
[NLPID_ESIS
] = "ESIS";
126 fr_nlpids
[NLPID_ISIS
] = "ISIS";
127 fr_nlpids
[NLPID_CONS
] = "CONS";
128 fr_nlpids
[NLPID_IDRP
] = "IDRP";
129 fr_nlpids
[NLPID_X25_ESIS
] = "X25_ESIS";
130 fr_nlpids
[NLPID_IP
] = "IP";
135 /* Frame Relay packet structure, with flags and CRC removed
137 +---------------------------+
141 +---------------------------+
142 | Control (UI = 0x03) |
143 +---------------------------+
144 | Optional Pad (0x00) |
145 +---------------------------+
147 +---------------------------+
154 +---------------------------+
156 * Q.922 addresses, as presently defined, are two octets and
157 contain a 10-bit DLCI. In some networks Q.922 addresses
158 may optionally be increased to three or four octets.
162 fr_hdrlen(const u_char
*p
, u_int addr_len
, u_int caplen
)
164 if ((caplen
> addr_len
+ 1 /* UI */ + 1 /* pad */) &&
165 !p
[addr_len
+ 1] /* pad exist */)
166 return addr_len
+ 1 /* UI */ + 1 /* pad */ + 1 /* NLPID */;
168 return addr_len
+ 1 /* UI */ + 1 /* NLPID */;
172 fr_protostring(u_int8_t proto
)
174 static char buf
[5+1+2+1];
178 if (nflag
|| fr_nlpids
[proto
] == NULL
) {
179 snprintf(buf
, sizeof(buf
), "proto %02x", proto
);
182 return fr_nlpids
[proto
];
186 fr_hdr_print(int length
, u_int dlci
, char *flags
, u_char nlpid
)
189 (void)printf("DLCI %u, %s%slength %d: ",
190 dlci
, flags
, *flags
? ", " : "", length
);
192 (void)printf("DLCI %u, %s%s%s, length %d: ",
193 dlci
, flags
, *flags
? ", " : "",
194 fr_protostring(nlpid
), length
);
198 fr_if_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
200 register u_int length
= h
->len
;
201 register u_int caplen
= h
->caplen
;
202 u_short extracted_ethertype
;
211 if (caplen
< 4) { /* minimum frame header length */
216 if (parse_q922_addr(p
, &dlci
, &addr_len
, &flags
)) {
217 printf("Invalid Q.922 address");
221 hdr_len
= fr_hdrlen(p
, addr_len
, caplen
);
223 if (caplen
< hdr_len
) {
228 if (p
[addr_len
] != 0x03)
229 printf("UI %02x! ", p
[addr_len
]);
231 if (!p
[addr_len
+ 1]) { /* pad byte should be used with 3-byte Q.922 */
234 } else if (addr_len
== 3)
237 nlpid
= p
[hdr_len
- 1];
244 fr_hdr_print(length
, dlci
, flags
, nlpid
);
253 ip6_print(p
, length
);
259 isoclns_print(p
, length
, caplen
);
263 orgcode
= EXTRACT_24BITS(p
);
264 et
= EXTRACT_16BITS(p
+ 3);
265 if (snap_print((const u_char
*)(p
+ 5), length
- 5,
266 caplen
- 5, &extracted_ethertype
, orgcode
, et
,
268 /* ether_type not known, print raw packet */
270 fr_hdr_print(length
+ hdr_len
,
272 if (extracted_ethertype
) {
274 etherproto_string(htons(extracted_ethertype
)));
276 if (!xflag
&& !qflag
)
277 default_print(p
- hdr_len
, caplen
+ hdr_len
);
282 lmi_print(p
, length
);
287 fr_hdr_print(length
+ hdr_len
,
290 default_print(p
, caplen
);
297 * Q.933 decoding portion for framerelay specific.
300 /* Q.933 packet format
301 Format of Other Protocols
303 +-------------------------------+
305 +---------------+---------------+
306 |Control 0x03 | NLPID 0x08 |
307 +---------------+---------------+
309 | octet 1 | octet 2 |
310 +-------------------------------+
312 | octet 2 | octet 2 |
313 +-------------------------------+
315 +-------------------------------+
317 +-------------------------------+
320 /* L2 (Octet 1)- Call Reference Usually is 0x0 */
323 * L2 (Octet 2)- Message Types definition 1 byte long.
326 #define MSG_TYPE_ESC_TO_NATIONAL 0x00
327 #define MSG_TYPE_ALERT 0x01
328 #define MSG_TYPE_CALL_PROCEEDING 0x02
329 #define MSG_TYPE_CONNECT 0x07
330 #define MSG_TYPE_CONNECT_ACK 0x0F
331 #define MSG_TYPE_PROGRESS 0x03
332 #define MSG_TYPE_SETUP 0x05
334 #define MSG_TYPE_DISCONNECT 0x45
335 #define MSG_TYPE_RELEASE 0x4D
336 #define MSG_TYPE_RELEASE_COMPLETE 0x5A
337 #define MSG_TYPE_RESTART 0x46
338 #define MSG_TYPE_RESTART_ACK 0x4E
340 #define MSG_TYPE_STATUS 0x7D
341 #define MSG_TYPE_STATUS_ENQ 0x75
343 #define MSG_ANSI_LOCKING_SHIFT 0x95
344 #define ONE_BYTE_IE_MASK 0xF0 /* details? */
346 #define ANSI_REPORT_TYPE_IE 0x01
347 #define ANSI_LINK_VERIFY_IE_91 0x19 /* details? */
348 #define ANSI_LINK_VERIFY_IE 0x03
349 #define ANSI_PVC_STATUS_IE 0x07
351 #define CCITT_REPORT_TYPE_IE 0x51
352 #define CCITT_LINK_VERIFY_IE 0x53
353 #define CCITT_PVC_STATUS_IE 0x57
355 struct common_ie_header
{
360 #define FULL_STATUS 0
361 #define LINK_VERIFY 1
365 /* Parses DLCI information element. */
366 static const char * parse_dlci_ie(const u_char
*p
, u_int ie_len
, char *buffer
,
373 ((ie_len
== 3) && !(p
[1] & 0x80)) ||
374 ((ie_len
== 4) && ((p
[1] & 0x80) || !(p
[2] & 0x80))) ||
375 ((ie_len
== 5) && ((p
[1] & 0x80) || (p
[2] & 0x80) ||
378 !(p
[ie_len
- 1] & 0x80))
379 return "Invalid DLCI IE";
381 dlci
= ((p
[0] & 0x3F) << 4) | ((p
[1] & 0x78) >> 3);
383 dlci
= (dlci
<< 6) | ((p
[2] & 0x7E) >> 1);
384 else if (ie_len
== 5)
385 dlci
= (dlci
<< 13) | (p
[2] & 0x7F) | ((p
[3] & 0x7E) >> 1);
387 snprintf(buffer
, buffer_len
, "DLCI %d: status %s%s", dlci
,
388 p
[ie_len
- 1] & 0x8 ? "New, " : "",
389 p
[ie_len
- 1] & 0x2 ? "Active" : "Inactive");
396 lmi_print(const u_char
*p
, u_int length
)
398 const u_char
*ptemp
= p
;
399 const char *decode_str
;
401 struct common_ie_header
*ie_p
;
404 if (length
< 9) { /* shortest: Q.933a LINK VERIFY */
409 if (p
[2] == MSG_ANSI_LOCKING_SHIFT
)
412 /* printing out header part */
413 printf(is_ansi
? "ANSI" : "CCITT");
415 printf(" Call Ref: %02x!", p
[0]);
419 case MSG_TYPE_STATUS
:
420 printf(" STATUS REPLY\n");
423 case MSG_TYPE_STATUS_ENQ
:
424 printf(" STATUS ENQUIRY\n");
428 printf(" UNKNOWN MSG Type %02x\n", p
[1]);
432 if (length
< (u_int
)(2 - is_ansi
)) {
436 length
-= 2 - is_ansi
;
437 ptemp
+= 2 + is_ansi
;
439 /* Loop through the rest of IE */
441 ie_p
= (struct common_ie_header
*)ptemp
;
442 if (length
< sizeof(struct common_ie_header
) ||
443 length
< sizeof(struct common_ie_header
) + ie_p
->ie_len
) {
448 if ((is_ansi
&& ie_p
->ie_id
== ANSI_REPORT_TYPE_IE
) ||
449 (!is_ansi
&& ie_p
->ie_id
== CCITT_REPORT_TYPE_IE
)) {
453 decode_str
= "FULL STATUS";
457 decode_str
= "LINK VERIFY";
461 decode_str
= "Async PVC Status";
465 decode_str
= "Reserved Value";
468 } else if ((is_ansi
&& (ie_p
->ie_id
== ANSI_LINK_VERIFY_IE_91
||
469 ie_p
->ie_id
== ANSI_LINK_VERIFY_IE
)) ||
470 (!is_ansi
&& ie_p
->ie_id
== CCITT_LINK_VERIFY_IE
)) {
471 snprintf(temp_str
, sizeof(temp_str
),
472 "TX Seq: %3d, RX Seq: %3d",
474 decode_str
= temp_str
;
475 } else if ((is_ansi
&& ie_p
->ie_id
== ANSI_PVC_STATUS_IE
) ||
476 (!is_ansi
&& ie_p
->ie_id
== CCITT_PVC_STATUS_IE
)) {
477 decode_str
= parse_dlci_ie(ptemp
+ 2, ie_p
->ie_len
,
478 temp_str
, sizeof(temp_str
));
480 decode_str
= "Non-decoded Value";
482 printf("\t\tIE: %02X Len: %d, %s\n",
483 ie_p
->ie_id
, ie_p
->ie_len
, decode_str
);
484 length
= length
- ie_p
->ie_len
- 2;
485 ptemp
= ptemp
+ ie_p
->ie_len
+ 2;