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.23 2004-10-07 16:04:06 hannes Exp $ (LBL)";
31 #include <tcpdump-stdinc.h>
37 #include "addrtoname.h"
38 #include "interface.h"
39 #include "ethertype.h"
43 static void lmi_print(const u_char
*, u_int
);
45 #define FR_EA_BIT 0x01
48 /* Finds out Q.922 address length, DLCI and flags. Returns 0 on success */
49 static int parse_q922_addr(const u_char
*p
, u_int
*dlci
, u_int
*addr_len
,
52 static char flags
[32];
55 if ((p
[0] & FR_EA_BIT
))
60 *dlci
= ((p
[0] & 0xFC) << 2) | ((p
[1] & 0xF0) >> 4);
62 strcpy(flags
, (p
[0] & 0x02) ? "C!, " : "");
64 strcat(flags
, "FECN, ");
66 strcat(flags
, "BECN, ");
68 strcat(flags
, "DE, ");
72 flags
[len
- 2] = '\x0'; /* delete trailing comma and space */
75 return 0; /* 2-byte Q.922 address */
78 (*addr_len
)++; /* 3- or 4-byte Q.922 address */
79 if ((p
[0] & FR_EA_BIT
) == 0) {
80 *dlci
= (*dlci
<< 7) | (p
[0] >> 1);
81 (*addr_len
)++; /* 4-byte Q.922 address */
85 if ((p
[0] & FR_EA_BIT
) == 0)
86 return -1; /* more than 4 bytes of Q.922 address? */
90 snprintf(flags
+ len
, sizeof(flags
) - len
,
91 "%sdlcore %x", len
? ", " : "", p
[0] >> 2);
93 *dlci
= (*dlci
<< 6) | (p
[0] >> 2);
98 /* Frame Relay packet structure, with flags and CRC removed
100 +---------------------------+
104 +---------------------------+
105 | Control (UI = 0x03) |
106 +---------------------------+
107 | Optional Pad (0x00) |
108 +---------------------------+
110 +---------------------------+
117 +---------------------------+
119 * Q.922 addresses, as presently defined, are two octets and
120 contain a 10-bit DLCI. In some networks Q.922 addresses
121 may optionally be increased to three or four octets.
125 fr_hdrlen(const u_char
*p
, u_int addr_len
, u_int caplen
)
127 if ((caplen
> addr_len
+ 1 /* UI */ + 1 /* pad */) &&
128 !p
[addr_len
+ 1] /* pad exist */)
129 return addr_len
+ 1 /* UI */ + 1 /* pad */ + 1 /* NLPID */;
131 return addr_len
+ 1 /* UI */ + 1 /* NLPID */;
135 fr_hdr_print(int length
, u_int dlci
, char *flags
, u_char nlpid
)
138 (void)printf("DLCI %u, %s%slength %u: ",
139 dlci
, flags
, *flags
? ", " : "", length
);
141 (void)printf("DLCI %u, %s%sNLPID %s (0x%02x), length %u: ",
142 dlci
, flags
, *flags
? ", " : "",
143 tok2str(nlpid_values
,"unknown", nlpid
),
149 fr_if_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
151 register u_int length
= h
->len
;
152 register u_int caplen
= h
->caplen
;
153 u_short extracted_ethertype
;
162 if (caplen
< 4) { /* minimum frame header length */
167 if (parse_q922_addr(p
, &dlci
, &addr_len
, &flags
)) {
168 printf("Invalid Q.922 address");
172 hdr_len
= fr_hdrlen(p
, addr_len
, caplen
);
174 if (caplen
< hdr_len
) {
179 if (p
[addr_len
] != 0x03) {
181 /* lets figure out if we have cisco style encapsulation: */
182 extracted_ethertype
= EXTRACT_16BITS(p
+addr_len
);
185 printf("%s (0x%04x), length %u: ",
186 tok2str(ethertype_values
, "unknown", extracted_ethertype
),
190 if (ether_encap_print(extracted_ethertype
,
191 p
+addr_len
+ETHERTYPE_LEN
,
194 &extracted_ethertype
) == 0)
195 /* ether_type not known, probably it wasn't one */
196 printf("UI %02x! ", p
[addr_len
]);
201 if (!p
[addr_len
+ 1]) { /* pad byte should be used with 3-byte Q.922 */
204 } else if (addr_len
== 3)
207 nlpid
= p
[hdr_len
- 1];
214 fr_hdr_print(length
, dlci
, flags
, nlpid
);
223 ip6_print(p
, length
);
229 isoclns_print(p
, length
, caplen
);
233 orgcode
= EXTRACT_24BITS(p
);
234 et
= EXTRACT_16BITS(p
+ 3);
235 if (snap_print((const u_char
*)(p
+ 5), length
- 5,
236 caplen
- 5, &extracted_ethertype
, orgcode
, et
,
238 /* ether_type not known, print raw packet */
240 fr_hdr_print(length
+ hdr_len
,
242 if (extracted_ethertype
) {
244 etherproto_string(htons(extracted_ethertype
)));
246 if (!xflag
&& !qflag
)
247 default_print(p
- hdr_len
, caplen
+ hdr_len
);
252 lmi_print(p
, length
);
257 fr_hdr_print(length
+ hdr_len
,
260 default_print(p
, caplen
);
267 * Q.933 decoding portion for framerelay specific.
270 /* Q.933 packet format
271 Format of Other Protocols
273 +-------------------------------+
275 +---------------+---------------+
276 |Control 0x03 | NLPID 0x08 |
277 +---------------+---------------+
279 | octet 1 | octet 2 |
280 +-------------------------------+
282 | octet 2 | octet 2 |
283 +-------------------------------+
285 +-------------------------------+
287 +-------------------------------+
290 /* L2 (Octet 1)- Call Reference Usually is 0x0 */
293 * L2 (Octet 2)- Message Types definition 1 byte long.
296 #define MSG_TYPE_ESC_TO_NATIONAL 0x00
297 #define MSG_TYPE_ALERT 0x01
298 #define MSG_TYPE_CALL_PROCEEDING 0x02
299 #define MSG_TYPE_CONNECT 0x07
300 #define MSG_TYPE_CONNECT_ACK 0x0F
301 #define MSG_TYPE_PROGRESS 0x03
302 #define MSG_TYPE_SETUP 0x05
304 #define MSG_TYPE_DISCONNECT 0x45
305 #define MSG_TYPE_RELEASE 0x4D
306 #define MSG_TYPE_RELEASE_COMPLETE 0x5A
307 #define MSG_TYPE_RESTART 0x46
308 #define MSG_TYPE_RESTART_ACK 0x4E
310 #define MSG_TYPE_STATUS 0x7D
311 #define MSG_TYPE_STATUS_ENQ 0x75
313 #define MSG_ANSI_LOCKING_SHIFT 0x95
314 #define ONE_BYTE_IE_MASK 0xF0 /* details? */
316 #define ANSI_REPORT_TYPE_IE 0x01
317 #define ANSI_LINK_VERIFY_IE_91 0x19 /* details? */
318 #define ANSI_LINK_VERIFY_IE 0x03
319 #define ANSI_PVC_STATUS_IE 0x07
321 #define CCITT_REPORT_TYPE_IE 0x51
322 #define CCITT_LINK_VERIFY_IE 0x53
323 #define CCITT_PVC_STATUS_IE 0x57
325 struct common_ie_header
{
330 #define FULL_STATUS 0
331 #define LINK_VERIFY 1
335 /* Parses DLCI information element. */
336 static const char * parse_dlci_ie(const u_char
*p
, u_int ie_len
, char *buffer
,
343 ((ie_len
== 3) && !(p
[1] & 0x80)) ||
344 ((ie_len
== 4) && ((p
[1] & 0x80) || !(p
[2] & 0x80))) ||
345 ((ie_len
== 5) && ((p
[1] & 0x80) || (p
[2] & 0x80) ||
348 !(p
[ie_len
- 1] & 0x80))
349 return "Invalid DLCI IE";
351 dlci
= ((p
[0] & 0x3F) << 4) | ((p
[1] & 0x78) >> 3);
353 dlci
= (dlci
<< 6) | ((p
[2] & 0x7E) >> 1);
354 else if (ie_len
== 5)
355 dlci
= (dlci
<< 13) | (p
[2] & 0x7F) | ((p
[3] & 0x7E) >> 1);
357 snprintf(buffer
, buffer_len
, "DLCI %d: status %s%s", dlci
,
358 p
[ie_len
- 1] & 0x8 ? "New, " : "",
359 p
[ie_len
- 1] & 0x2 ? "Active" : "Inactive");
366 lmi_print(const u_char
*p
, u_int length
)
368 const u_char
*ptemp
= p
;
369 const char *decode_str
;
371 struct common_ie_header
*ie_p
;
374 if (length
< 9) { /* shortest: Q.933a LINK VERIFY */
379 if (p
[2] == MSG_ANSI_LOCKING_SHIFT
)
382 /* printing out header part */
383 printf(is_ansi
? "ANSI" : "CCITT");
385 printf(" Call Ref: %02x!", p
[0]);
389 case MSG_TYPE_STATUS
:
390 printf(" STATUS REPLY\n");
393 case MSG_TYPE_STATUS_ENQ
:
394 printf(" STATUS ENQUIRY\n");
398 printf(" UNKNOWN MSG Type %02x\n", p
[1]);
402 if (length
< (u_int
)(2 - is_ansi
)) {
406 length
-= 2 - is_ansi
;
407 ptemp
+= 2 + is_ansi
;
409 /* Loop through the rest of IE */
411 ie_p
= (struct common_ie_header
*)ptemp
;
412 if (length
< sizeof(struct common_ie_header
) ||
413 length
< sizeof(struct common_ie_header
) + ie_p
->ie_len
) {
418 if ((is_ansi
&& ie_p
->ie_id
== ANSI_REPORT_TYPE_IE
) ||
419 (!is_ansi
&& ie_p
->ie_id
== CCITT_REPORT_TYPE_IE
)) {
423 decode_str
= "FULL STATUS";
427 decode_str
= "LINK VERIFY";
431 decode_str
= "Async PVC Status";
435 decode_str
= "Reserved Value";
438 } else if ((is_ansi
&& (ie_p
->ie_id
== ANSI_LINK_VERIFY_IE_91
||
439 ie_p
->ie_id
== ANSI_LINK_VERIFY_IE
)) ||
440 (!is_ansi
&& ie_p
->ie_id
== CCITT_LINK_VERIFY_IE
)) {
441 snprintf(temp_str
, sizeof(temp_str
),
442 "TX Seq: %3d, RX Seq: %3d",
444 decode_str
= temp_str
;
445 } else if ((is_ansi
&& ie_p
->ie_id
== ANSI_PVC_STATUS_IE
) ||
446 (!is_ansi
&& ie_p
->ie_id
== CCITT_PVC_STATUS_IE
)) {
447 decode_str
= parse_dlci_ie(ptemp
+ 2, ie_p
->ie_len
,
448 temp_str
, sizeof(temp_str
));
450 decode_str
= "Non-decoded Value";
452 printf("\t\tIE: %02X Len: %d, %s\n",
453 ie_p
->ie_id
, ie_p
->ie_len
, decode_str
);
454 length
= length
- ie_p
->ie_len
- 2;
455 ptemp
= ptemp
+ ie_p
->ie_len
+ 2;