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.32 2005-04-06 21:32:39 mcr Exp $ (LBL)";
31 #include <tcpdump-stdinc.h>
37 #include "addrtoname.h"
38 #include "interface.h"
39 #include "ethertype.h"
44 static void frf15_print(const u_char
*, u_int
);
47 * the frame relay header has a variable length
49 * the EA bit determines if there is another byte
52 * minimum header length is 2 bytes
53 * maximum header length is 4 bytes
56 * +----+----+----+----+----+----+----+----+
57 * | DLCI (6 bits) | CR | EA |
58 * +----+----+----+----+----+----+----+----+
59 * | DLCI (4 bits) |FECN|BECN| DE | EA |
60 * +----+----+----+----+----+----+----+----+
61 * | DLCI (7 bits) | EA |
62 * +----+----+----+----+----+----+----+----+
63 * | DLCI (6 bits) |SDLC| EA |
64 * +----+----+----+----+----+----+----+----+
67 #define FR_EA_BIT 0x01
69 #define FR_CR_BIT 0x02000000
70 #define FR_DE_BIT 0x00020000
71 #define FR_BECN_BIT 0x00040000
72 #define FR_FECN_BIT 0x00080000
73 #define FR_SDLC_BIT 0x00000002
76 struct tok fr_header_flag_values
[] = {
79 { FR_BECN_BIT
, "BECN" },
80 { FR_FECN_BIT
, "FECN" },
81 { FR_SDLC_BIT
, "sdlcore" },
86 /* Finds out Q.922 address length, DLCI and flags. Returns 0 on success
87 * save the flags dep. on address length
89 static int parse_q922_addr(const u_char
*p
, u_int
*dlci
, u_int
*sdlcore
,
90 u_int
*addr_len
, u_int8_t
*flags
)
92 if ((p
[0] & FR_EA_BIT
))
96 *dlci
= ((p
[0] & 0xFC) << 2) | ((p
[1] & 0xF0) >> 4);
98 flags
[0] = p
[0] & 0x02; /* populate the first flag fields */
99 flags
[1] = p
[1] & 0x0c;
101 if (p
[1] & FR_EA_BIT
)
102 return 0; /* 2-byte Q.922 address */
105 (*addr_len
)++; /* 3- or 4-byte Q.922 address */
106 if ((p
[0] & FR_EA_BIT
) == 0) {
107 *dlci
= (*dlci
<< 7) | (p
[0] >> 1);
108 (*addr_len
)++; /* 4-byte Q.922 address */
112 if ((p
[0] & FR_EA_BIT
) == 0)
113 return -1; /* more than 4 bytes of Q.922 address? */
115 flags
[3] = p
[0] & 0x02;
118 *sdlcore
= p
[0] >> 2;
120 *dlci
= (*dlci
<< 6) | (p
[0] >> 2);
125 /* Frame Relay packet structure, with flags and CRC removed
127 +---------------------------+
131 +---------------------------+
132 | Control (UI = 0x03) |
133 +---------------------------+
134 | Optional Pad (0x00) |
135 +---------------------------+
137 +---------------------------+
144 +---------------------------+
146 * Q.922 addresses, as presently defined, are two octets and
147 contain a 10-bit DLCI. In some networks Q.922 addresses
148 may optionally be increased to three or four octets.
152 fr_hdrlen(const u_char
*p
, u_int addr_len
, u_int caplen
)
154 if ((caplen
> addr_len
+ 1 /* UI */ + 1 /* pad */) &&
155 !p
[addr_len
+ 1] /* pad exist */)
156 return addr_len
+ 1 /* UI */ + 1 /* pad */ + 1 /* NLPID */;
158 return addr_len
+ 1 /* UI */ + 1 /* NLPID */;
162 fr_hdr_print(int length
, u_int addr_len
, u_int dlci
, u_int8_t
*flags
, u_int16_t nlpid
)
165 (void)printf("Q.922, DLCI %u, length %u: ",
169 if (nlpid
<= 0xff) /* if its smaller than 256 then its a NLPID */
170 (void)printf("Q.922, hdr-len %u, DLCI %u, Flags [%s], NLPID %s (0x%02x), length %u: ",
173 bittok2str(fr_header_flag_values
, "none", EXTRACT_32BITS(flags
)),
174 tok2str(nlpid_values
,"unknown", nlpid
),
177 else /* must be an ethertype */
178 (void)printf("Q.922, hdr-len %u, DLCI %u, Flags [%s], cisco-ethertype %s (0x%04x), length %u: ",
181 bittok2str(fr_header_flag_values
, "none", EXTRACT_32BITS(flags
)),
182 tok2str(ethertype_values
, "unknown", nlpid
),
189 fr_if_print(const struct pcap_pkthdr
*h
, register const u_char
*p
)
191 register u_int length
= h
->len
;
192 register u_int caplen
= h
->caplen
;
193 u_int16_t extracted_ethertype
;
203 if (caplen
< 4) { /* minimum frame header length */
208 if (parse_q922_addr(p
, &dlci
, &sdlcore
, &addr_len
, flags
)) {
209 printf("Q.922, invalid address");
213 hdr_len
= fr_hdrlen(p
, addr_len
, caplen
);
215 if (caplen
< hdr_len
) {
220 if (p
[addr_len
] != 0x03 && dlci
!= 0) {
222 /* lets figure out if we have cisco style encapsulation: */
223 extracted_ethertype
= EXTRACT_16BITS(p
+addr_len
);
226 fr_hdr_print(length
, addr_len
, dlci
, flags
, extracted_ethertype
);
228 if (ether_encap_print(extracted_ethertype
,
229 p
+addr_len
+ETHERTYPE_LEN
,
230 length
-addr_len
-ETHERTYPE_LEN
,
231 caplen
-addr_len
-ETHERTYPE_LEN
,
232 &extracted_ethertype
) == 0)
233 /* ether_type not known, probably it wasn't one */
234 printf("UI %02x! ", p
[addr_len
]);
239 if (!p
[addr_len
+ 1]) { /* pad byte should be used with 3-byte Q.922 */
242 } else if (addr_len
== 3)
245 nlpid
= p
[hdr_len
- 1];
248 fr_hdr_print(length
, addr_len
, dlci
, flags
, nlpid
);
256 ip_print(gndo
, p
, length
);
261 ip6_print(p
, length
);
267 isoclns_print(p
-1, length
+1, caplen
+1); /* OSI printers need the NLPID field */
271 orgcode
= EXTRACT_24BITS(p
);
272 et
= EXTRACT_16BITS(p
+ 3);
275 (void)printf("SNAP, oui %s (0x%06x), ethertype %s (0x%04x): ",
276 tok2str(oui_values
,"Unknown",orgcode
),
278 tok2str(ethertype_values
,"Unknown", et
),
281 if (snap_print((const u_char
*)(p
+ 5), length
- 5,
282 caplen
- 5, &extracted_ethertype
, orgcode
, et
,
284 /* ether_type not known, print raw packet */
286 fr_hdr_print(length
+ hdr_len
, hdr_len
,
288 if (!xflag
&& !qflag
)
289 default_print(p
- hdr_len
, caplen
+ hdr_len
);
294 q933_print(p
, length
);
298 frf15_print(p
, length
);
303 fr_hdr_print(length
+ hdr_len
, addr_len
,
306 default_print(p
, caplen
);
312 /* an NLPID of 0xb1 indicates a 2-byte
316 * +----+----+----+----+----+----+----+----+
318 * +----+----+----+----+----+----+----+----+
319 * | NLPID (8 bits) | NLPID=0xb1
320 * +----+----+----+----+----+----+----+----+
321 * | B | E | C |seq. (high 4 bits) | R |
322 * +----+----+----+----+----+----+----+----+
323 * | sequence (low 8 bits) |
324 * +----+----+----+----+----+----+----+----+
327 struct tok frf15_flag_values
[] = {
334 #define FR_FRF15_FRAGTYPE 0x01
337 frf15_print (const u_char
*p
, u_int length
) {
339 u_int16_t sequence_num
, flags
;
342 sequence_num
= (p
[0]&0x1e)<<7 | p
[1];
344 printf("FRF.15, seq 0x%03x, Flags [%s],%s Fragmentation, length %u",
346 bittok2str(frf15_flag_values
,"none",flags
),
347 flags
&FR_FRF15_FRAGTYPE
? "Interface" : "End-to-End",
351 * depending on all permutations of the B, E and C bit
352 * dig as deep as we can - e.g. on the first (B) fragment
353 * there is enough payload to print the IP header
354 * on non (B) fragments it depends if the fragmentation
355 * model is end-to-end or interface based wether we want to print
356 * another Q.922 header
362 * Q.933 decoding portion for framerelay specific.
365 /* Q.933 packet format
366 Format of Other Protocols
368 +-------------------------------+
370 +---------------+---------------+
371 |Control 0x03 | NLPID 0x08 |
372 +---------------+---------------+
374 | octet 1 | octet 2 |
375 +-------------------------------+
377 | octet 2 | octet 2 |
378 +-------------------------------+
380 +-------------------------------+
382 +-------------------------------+
385 /* L2 (Octet 1)- Call Reference Usually is 0x0 */
388 * L2 (Octet 2)- Message Types definition 1 byte long.
391 #define MSG_TYPE_ESC_TO_NATIONAL 0x00
392 #define MSG_TYPE_ALERT 0x01
393 #define MSG_TYPE_CALL_PROCEEDING 0x02
394 #define MSG_TYPE_CONNECT 0x07
395 #define MSG_TYPE_CONNECT_ACK 0x0F
396 #define MSG_TYPE_PROGRESS 0x03
397 #define MSG_TYPE_SETUP 0x05
399 #define MSG_TYPE_DISCONNECT 0x45
400 #define MSG_TYPE_RELEASE 0x4D
401 #define MSG_TYPE_RELEASE_COMPLETE 0x5A
402 #define MSG_TYPE_RESTART 0x46
403 #define MSG_TYPE_RESTART_ACK 0x4E
405 #define MSG_TYPE_STATUS 0x7D
406 #define MSG_TYPE_STATUS_ENQ 0x75
408 struct tok fr_q933_msg_values
[] = {
409 { MSG_TYPE_ESC_TO_NATIONAL
, "ESC to National" },
410 { MSG_TYPE_ALERT
, "Alert" },
411 { MSG_TYPE_CALL_PROCEEDING
, "Call proceeding" },
412 { MSG_TYPE_CONNECT
, "Connect" },
413 { MSG_TYPE_CONNECT_ACK
, "Connect ACK" },
414 { MSG_TYPE_PROGRESS
, "Progress" },
415 { MSG_TYPE_SETUP
, "Setup" },
416 { MSG_TYPE_DISCONNECT
, "Disconnect" },
417 { MSG_TYPE_RELEASE
, "Release" },
418 { MSG_TYPE_RELEASE_COMPLETE
, "Release Complete" },
419 { MSG_TYPE_RESTART
, "Restart" },
420 { MSG_TYPE_RESTART_ACK
, "Restart ACK" },
421 { MSG_TYPE_STATUS
, "Status Reply" },
422 { MSG_TYPE_STATUS_ENQ
, "Status Enquiry" },
426 #define MSG_ANSI_LOCKING_SHIFT 0x95
428 #define FR_LMI_ANSI_REPORT_TYPE_IE 0x01
429 #define FR_LMI_ANSI_LINK_VERIFY_IE_91 0x19 /* details? */
430 #define FR_LMI_ANSI_LINK_VERIFY_IE 0x03
431 #define FR_LMI_ANSI_PVC_STATUS_IE 0x07
433 #define FR_LMI_CCITT_REPORT_TYPE_IE 0x51
434 #define FR_LMI_CCITT_LINK_VERIFY_IE 0x53
435 #define FR_LMI_CCITT_PVC_STATUS_IE 0x57
437 struct tok fr_q933_ie_values_codeset5
[] = {
438 { FR_LMI_ANSI_REPORT_TYPE_IE
, "ANSI Report Type" },
439 { FR_LMI_ANSI_LINK_VERIFY_IE_91
, "ANSI Link Verify" },
440 { FR_LMI_ANSI_LINK_VERIFY_IE
, "ANSI Link Verify" },
441 { FR_LMI_ANSI_PVC_STATUS_IE
, "ANSI PVC Status" },
442 { FR_LMI_CCITT_REPORT_TYPE_IE
, "CCITT Report Type" },
443 { FR_LMI_CCITT_LINK_VERIFY_IE
, "CCITT Link Verify" },
444 { FR_LMI_CCITT_PVC_STATUS_IE
, "CCITT PVC Status" },
448 #define FR_LMI_REPORT_TYPE_IE_FULL_STATUS 0
449 #define FR_LMI_REPORT_TYPE_IE_LINK_VERIFY 1
450 #define FR_LMI_REPORT_TYPE_IE_ASYNC_PVC 2
452 struct tok fr_lmi_report_type_ie_values
[] = {
453 { FR_LMI_REPORT_TYPE_IE_FULL_STATUS
, "Full Status" },
454 { FR_LMI_REPORT_TYPE_IE_LINK_VERIFY
, "Link verify" },
455 { FR_LMI_REPORT_TYPE_IE_ASYNC_PVC
, "Async PVC Status" },
459 /* array of 16 codepages - currently we only support codepage 5 */
460 static struct tok
*fr_q933_ie_codesets
[] = {
466 fr_q933_ie_values_codeset5
,
480 struct common_ie_header
{
486 q933_print(const u_char
*p
, u_int length
)
488 const u_char
*ptemp
= p
;
489 struct common_ie_header
*ie_p
;
494 if (length
< 9) { /* shortest: Q.933a LINK VERIFY */
499 codeset
= p
[2]&0x0f; /* extract the codeset */
501 if (p
[2] == MSG_ANSI_LOCKING_SHIFT
)
504 printf("%s", eflag
? "" : "Q.933, ");
506 /* printing out header part */
507 printf(is_ansi
? "ANSI" : "CCITT ");
510 printf(", Call Ref: 0x%02x", p
[0]);
513 printf(", %s (0x%02x), length %u",
514 tok2str(fr_q933_msg_values
,"unknown message",p
[1]),
519 tok2str(fr_q933_msg_values
,"unknown message 0x%02x",p
[1]));
521 olen
= length
; /* preserve the original length for non verbose mode */
523 if (length
< (u_int
)(2 - is_ansi
)) {
527 length
-= 2 - is_ansi
;
528 ptemp
+= 2 + is_ansi
;
530 /* Loop through the rest of IE */
531 while (length
> sizeof(struct common_ie_header
)) {
532 ie_p
= (struct common_ie_header
*)ptemp
;
533 if (length
< sizeof(struct common_ie_header
) ||
534 length
< sizeof(struct common_ie_header
) + ie_p
->ie_len
) {
535 if (vflag
) /* not bark if there is just a trailer */
536 printf("\n[|q.933]");
538 printf(", length %u",olen
);
542 /* lets do the full IE parsing only in verbose mode
543 * however some IEs (DLCI Status, Link Verify)
544 * are also intereststing in non-verbose mode */
546 printf("\n\t%s IE (%u), length %u: ",
547 tok2str(fr_q933_ie_codesets
[codeset
],"unknown",ie_p
->ie_id
),
551 switch (ie_p
->ie_id
) {
553 case FR_LMI_ANSI_REPORT_TYPE_IE
: /* fall through */
554 case FR_LMI_CCITT_REPORT_TYPE_IE
:
557 tok2str(fr_lmi_report_type_ie_values
,"unknown",ptemp
[2]),
561 case FR_LMI_ANSI_LINK_VERIFY_IE
: /* fall through */
562 case FR_LMI_CCITT_LINK_VERIFY_IE
:
563 case FR_LMI_ANSI_LINK_VERIFY_IE_91
:
566 printf("TX Seq: %3d, RX Seq: %3d", ptemp
[2], ptemp
[3]);
568 case FR_LMI_ANSI_PVC_STATUS_IE
: /* fall through */
569 case FR_LMI_CCITT_PVC_STATUS_IE
:
572 /* now parse the DLCI information element. */
573 if ((ie_p
->ie_len
< 3) ||
575 ((ie_p
->ie_len
== 3) && !(ptemp
[3] & 0x80)) ||
576 ((ie_p
->ie_len
== 4) && ((ptemp
[3] & 0x80) || !(ptemp
[4] & 0x80))) ||
577 ((ie_p
->ie_len
== 5) && ((ptemp
[3] & 0x80) || (ptemp
[4] & 0x80) ||
578 !(ptemp
[5] & 0x80))) ||
579 (ie_p
->ie_len
> 5) ||
580 !(ptemp
[ie_p
->ie_len
+ 1] & 0x80))
581 printf("Invalid DLCI IE");
583 dlci
= ((ptemp
[2] & 0x3F) << 4) | ((ptemp
[3] & 0x78) >> 3);
584 if (ie_p
->ie_len
== 4)
585 dlci
= (dlci
<< 6) | ((ptemp
[4] & 0x7E) >> 1);
586 else if (ie_p
->ie_len
== 5)
587 dlci
= (dlci
<< 13) | (ptemp
[4] & 0x7F) | ((ptemp
[5] & 0x7E) >> 1);
589 printf("DLCI %u: status %s%s", dlci
,
590 ptemp
[ie_p
->ie_len
+ 1] & 0x8 ? "New, " : "",
591 ptemp
[ie_p
->ie_len
+ 1] & 0x2 ? "Active" : "Inactive");
596 print_unknown_data(ptemp
+2,"\n\t",ie_p
->ie_len
);
600 /* do we want to see a hexdump of the IE ? */
602 print_unknown_data(ptemp
+2,"\n\t ",ie_p
->ie_len
);
604 length
= length
- ie_p
->ie_len
- 2;
605 ptemp
= ptemp
+ ie_p
->ie_len
+ 2;
608 printf(", length %u",olen
);