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.24 2004-10-07 16:16:02 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("DLCI %u, %s%scisco-ethertype %s (0x%04x), length %u: ",
189 tok2str(ethertype_values
, "unknown", extracted_ethertype
),
193 if (ether_encap_print(extracted_ethertype
,
194 p
+addr_len
+ETHERTYPE_LEN
,
197 &extracted_ethertype
) == 0)
198 /* ether_type not known, probably it wasn't one */
199 printf("UI %02x! ", p
[addr_len
]);
204 if (!p
[addr_len
+ 1]) { /* pad byte should be used with 3-byte Q.922 */
207 } else if (addr_len
== 3)
210 nlpid
= p
[hdr_len
- 1];
217 fr_hdr_print(length
, dlci
, flags
, nlpid
);
226 ip6_print(p
, length
);
232 isoclns_print(p
, length
, caplen
);
236 orgcode
= EXTRACT_24BITS(p
);
237 et
= EXTRACT_16BITS(p
+ 3);
238 if (snap_print((const u_char
*)(p
+ 5), length
- 5,
239 caplen
- 5, &extracted_ethertype
, orgcode
, et
,
241 /* ether_type not known, print raw packet */
243 fr_hdr_print(length
+ hdr_len
,
245 if (extracted_ethertype
) {
247 etherproto_string(htons(extracted_ethertype
)));
249 if (!xflag
&& !qflag
)
250 default_print(p
- hdr_len
, caplen
+ hdr_len
);
255 lmi_print(p
, length
);
260 fr_hdr_print(length
+ hdr_len
,
263 default_print(p
, caplen
);
270 * Q.933 decoding portion for framerelay specific.
273 /* Q.933 packet format
274 Format of Other Protocols
276 +-------------------------------+
278 +---------------+---------------+
279 |Control 0x03 | NLPID 0x08 |
280 +---------------+---------------+
282 | octet 1 | octet 2 |
283 +-------------------------------+
285 | octet 2 | octet 2 |
286 +-------------------------------+
288 +-------------------------------+
290 +-------------------------------+
293 /* L2 (Octet 1)- Call Reference Usually is 0x0 */
296 * L2 (Octet 2)- Message Types definition 1 byte long.
299 #define MSG_TYPE_ESC_TO_NATIONAL 0x00
300 #define MSG_TYPE_ALERT 0x01
301 #define MSG_TYPE_CALL_PROCEEDING 0x02
302 #define MSG_TYPE_CONNECT 0x07
303 #define MSG_TYPE_CONNECT_ACK 0x0F
304 #define MSG_TYPE_PROGRESS 0x03
305 #define MSG_TYPE_SETUP 0x05
307 #define MSG_TYPE_DISCONNECT 0x45
308 #define MSG_TYPE_RELEASE 0x4D
309 #define MSG_TYPE_RELEASE_COMPLETE 0x5A
310 #define MSG_TYPE_RESTART 0x46
311 #define MSG_TYPE_RESTART_ACK 0x4E
313 #define MSG_TYPE_STATUS 0x7D
314 #define MSG_TYPE_STATUS_ENQ 0x75
316 #define MSG_ANSI_LOCKING_SHIFT 0x95
317 #define ONE_BYTE_IE_MASK 0xF0 /* details? */
319 #define ANSI_REPORT_TYPE_IE 0x01
320 #define ANSI_LINK_VERIFY_IE_91 0x19 /* details? */
321 #define ANSI_LINK_VERIFY_IE 0x03
322 #define ANSI_PVC_STATUS_IE 0x07
324 #define CCITT_REPORT_TYPE_IE 0x51
325 #define CCITT_LINK_VERIFY_IE 0x53
326 #define CCITT_PVC_STATUS_IE 0x57
328 struct common_ie_header
{
333 #define FULL_STATUS 0
334 #define LINK_VERIFY 1
338 /* Parses DLCI information element. */
339 static const char * parse_dlci_ie(const u_char
*p
, u_int ie_len
, char *buffer
,
346 ((ie_len
== 3) && !(p
[1] & 0x80)) ||
347 ((ie_len
== 4) && ((p
[1] & 0x80) || !(p
[2] & 0x80))) ||
348 ((ie_len
== 5) && ((p
[1] & 0x80) || (p
[2] & 0x80) ||
351 !(p
[ie_len
- 1] & 0x80))
352 return "Invalid DLCI IE";
354 dlci
= ((p
[0] & 0x3F) << 4) | ((p
[1] & 0x78) >> 3);
356 dlci
= (dlci
<< 6) | ((p
[2] & 0x7E) >> 1);
357 else if (ie_len
== 5)
358 dlci
= (dlci
<< 13) | (p
[2] & 0x7F) | ((p
[3] & 0x7E) >> 1);
360 snprintf(buffer
, buffer_len
, "DLCI %d: status %s%s", dlci
,
361 p
[ie_len
- 1] & 0x8 ? "New, " : "",
362 p
[ie_len
- 1] & 0x2 ? "Active" : "Inactive");
369 lmi_print(const u_char
*p
, u_int length
)
371 const u_char
*ptemp
= p
;
372 const char *decode_str
;
374 struct common_ie_header
*ie_p
;
377 if (length
< 9) { /* shortest: Q.933a LINK VERIFY */
382 if (p
[2] == MSG_ANSI_LOCKING_SHIFT
)
385 /* printing out header part */
386 printf(is_ansi
? "ANSI" : "CCITT");
388 printf(" Call Ref: %02x!", p
[0]);
392 case MSG_TYPE_STATUS
:
393 printf(" STATUS REPLY\n");
396 case MSG_TYPE_STATUS_ENQ
:
397 printf(" STATUS ENQUIRY\n");
401 printf(" UNKNOWN MSG Type %02x\n", p
[1]);
405 if (length
< (u_int
)(2 - is_ansi
)) {
409 length
-= 2 - is_ansi
;
410 ptemp
+= 2 + is_ansi
;
412 /* Loop through the rest of IE */
414 ie_p
= (struct common_ie_header
*)ptemp
;
415 if (length
< sizeof(struct common_ie_header
) ||
416 length
< sizeof(struct common_ie_header
) + ie_p
->ie_len
) {
421 if ((is_ansi
&& ie_p
->ie_id
== ANSI_REPORT_TYPE_IE
) ||
422 (!is_ansi
&& ie_p
->ie_id
== CCITT_REPORT_TYPE_IE
)) {
426 decode_str
= "FULL STATUS";
430 decode_str
= "LINK VERIFY";
434 decode_str
= "Async PVC Status";
438 decode_str
= "Reserved Value";
441 } else if ((is_ansi
&& (ie_p
->ie_id
== ANSI_LINK_VERIFY_IE_91
||
442 ie_p
->ie_id
== ANSI_LINK_VERIFY_IE
)) ||
443 (!is_ansi
&& ie_p
->ie_id
== CCITT_LINK_VERIFY_IE
)) {
444 snprintf(temp_str
, sizeof(temp_str
),
445 "TX Seq: %3d, RX Seq: %3d",
447 decode_str
= temp_str
;
448 } else if ((is_ansi
&& ie_p
->ie_id
== ANSI_PVC_STATUS_IE
) ||
449 (!is_ansi
&& ie_p
->ie_id
== CCITT_PVC_STATUS_IE
)) {
450 decode_str
= parse_dlci_ie(ptemp
+ 2, ie_p
->ie_len
,
451 temp_str
, sizeof(temp_str
));
453 decode_str
= "Non-decoded Value";
455 printf("\t\tIE: %02X Len: %d, %s\n",
456 ie_p
->ie_id
, ie_p
->ie_len
, decode_str
);
457 length
= length
- ie_p
->ie_len
- 2;
458 ptemp
= ptemp
+ ie_p
->ie_len
+ 2;