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.
22 #define NETDISSECT_REWORKED
27 #include <tcpdump-stdinc.h>
32 #include "interface.h"
33 #include "addrtoname.h"
34 #include "ethertype.h"
39 static void frf15_print(netdissect_options
*ndo
, const u_char
*, u_int
);
42 * the frame relay header has a variable length
44 * the EA bit determines if there is another byte
47 * minimum header length is 2 bytes
48 * maximum header length is 4 bytes
51 * +----+----+----+----+----+----+----+----+
52 * | DLCI (6 bits) | CR | EA |
53 * +----+----+----+----+----+----+----+----+
54 * | DLCI (4 bits) |FECN|BECN| DE | EA |
55 * +----+----+----+----+----+----+----+----+
56 * | DLCI (7 bits) | EA |
57 * +----+----+----+----+----+----+----+----+
58 * | DLCI (6 bits) |SDLC| EA |
59 * +----+----+----+----+----+----+----+----+
62 #define FR_EA_BIT 0x01
64 #define FR_CR_BIT 0x02000000
65 #define FR_DE_BIT 0x00020000
66 #define FR_BECN_BIT 0x00040000
67 #define FR_FECN_BIT 0x00080000
68 #define FR_SDLC_BIT 0x00000002
71 static const struct tok fr_header_flag_values
[] = {
74 { FR_BECN_BIT
, "BECN" },
75 { FR_FECN_BIT
, "FECN" },
76 { FR_SDLC_BIT
, "sdlcore" },
81 #define MFR_B_BIT 0x80
82 #define MFR_E_BIT 0x40
83 #define MFR_C_BIT 0x20
84 #define MFR_BEC_MASK (MFR_B_BIT | MFR_E_BIT | MFR_C_BIT)
85 #define MFR_CTRL_FRAME (MFR_B_BIT | MFR_E_BIT | MFR_C_BIT)
86 #define MFR_FRAG_FRAME (MFR_B_BIT | MFR_E_BIT )
88 static const struct tok frf_flag_values
[] = {
89 { MFR_B_BIT
, "Begin" },
91 { MFR_C_BIT
, "Control" },
95 /* Finds out Q.922 address length, DLCI and flags. Returns 0 on success
96 * save the flags dep. on address length
98 static int parse_q922_addr(const u_char
*p
, u_int
*dlci
,
99 u_int
*addr_len
, uint8_t *flags
)
101 if ((p
[0] & FR_EA_BIT
))
105 *dlci
= ((p
[0] & 0xFC) << 2) | ((p
[1] & 0xF0) >> 4);
107 flags
[0] = p
[0] & 0x02; /* populate the first flag fields */
108 flags
[1] = p
[1] & 0x0c;
109 flags
[2] = 0; /* clear the rest of the flags */
112 if (p
[1] & FR_EA_BIT
)
113 return 0; /* 2-byte Q.922 address */
116 (*addr_len
)++; /* 3- or 4-byte Q.922 address */
117 if ((p
[0] & FR_EA_BIT
) == 0) {
118 *dlci
= (*dlci
<< 7) | (p
[0] >> 1);
119 (*addr_len
)++; /* 4-byte Q.922 address */
123 if ((p
[0] & FR_EA_BIT
) == 0)
124 return -1; /* more than 4 bytes of Q.922 address? */
126 flags
[3] = p
[0] & 0x02;
128 *dlci
= (*dlci
<< 6) | (p
[0] >> 2);
133 char *q922_string(const u_char
*p
) {
135 static u_int dlci
, addr_len
;
136 static uint8_t flags
[4];
137 static char buffer
[sizeof("DLCI xxxxxxxxxx")];
138 memset(buffer
, 0, sizeof(buffer
));
140 if (parse_q922_addr(p
, &dlci
, &addr_len
, flags
) == 0){
141 snprintf(buffer
, sizeof(buffer
), "DLCI %u", dlci
);
148 /* Frame Relay packet structure, with flags and CRC removed
150 +---------------------------+
154 +---------------------------+
155 | Control (UI = 0x03) |
156 +---------------------------+
157 | Optional Pad (0x00) |
158 +---------------------------+
160 +---------------------------+
167 +---------------------------+
169 * Q.922 addresses, as presently defined, are two octets and
170 contain a 10-bit DLCI. In some networks Q.922 addresses
171 may optionally be increased to three or four octets.
175 fr_hdrlen(const u_char
*p
, u_int addr_len
)
177 if (!p
[addr_len
+ 1] /* pad exist */)
178 return addr_len
+ 1 /* UI */ + 1 /* pad */ + 1 /* NLPID */;
180 return addr_len
+ 1 /* UI */ + 1 /* NLPID */;
184 fr_hdr_print(netdissect_options
*ndo
,
185 int length
, u_int addr_len
, u_int dlci
, uint8_t *flags
, uint16_t nlpid
)
187 if (ndo
->ndo_qflag
) {
188 ND_PRINT((ndo
, "Q.922, DLCI %u, length %u: ",
192 if (nlpid
<= 0xff) /* if its smaller than 256 then its a NLPID */
193 ND_PRINT((ndo
, "Q.922, hdr-len %u, DLCI %u, Flags [%s], NLPID %s (0x%02x), length %u: ",
196 bittok2str(fr_header_flag_values
, "none", EXTRACT_32BITS(flags
)),
197 tok2str(nlpid_values
,"unknown", nlpid
),
200 else /* must be an ethertype */
201 ND_PRINT((ndo
, "Q.922, hdr-len %u, DLCI %u, Flags [%s], cisco-ethertype %s (0x%04x), length %u: ",
204 bittok2str(fr_header_flag_values
, "none", EXTRACT_32BITS(flags
)),
205 tok2str(ethertype_values
, "unknown", nlpid
),
212 fr_if_print(netdissect_options
*ndo
,
213 const struct pcap_pkthdr
*h
, register const u_char
*p
)
215 register u_int length
= h
->len
;
216 register u_int caplen
= h
->caplen
;
218 ND_TCHECK2(*p
, 4); /* minimum frame header length */
220 if ((length
= fr_print(ndo
, p
, length
)) == 0)
225 ND_PRINT((ndo
, "[|fr]"));
230 fr_print(netdissect_options
*ndo
,
231 register const u_char
*p
, u_int length
)
233 uint16_t extracted_ethertype
;
240 if (parse_q922_addr(p
, &dlci
, &addr_len
, flags
)) {
241 ND_PRINT((ndo
, "Q.922, invalid address"));
245 ND_TCHECK2(*p
, addr_len
+1+1);
246 hdr_len
= fr_hdrlen(p
, addr_len
);
247 ND_TCHECK2(*p
, hdr_len
);
249 if (p
[addr_len
] != 0x03 && dlci
!= 0) {
251 /* lets figure out if we have cisco style encapsulation: */
252 extracted_ethertype
= EXTRACT_16BITS(p
+addr_len
);
255 fr_hdr_print(ndo
, length
, addr_len
, dlci
, flags
, extracted_ethertype
);
257 if (ethertype_print(ndo
, extracted_ethertype
,
258 p
+addr_len
+ETHERTYPE_LEN
,
259 length
-addr_len
-ETHERTYPE_LEN
,
260 length
-addr_len
-ETHERTYPE_LEN
) == 0)
261 /* ether_type not known, probably it wasn't one */
262 ND_PRINT((ndo
, "UI %02x! ", p
[addr_len
]));
267 if (!p
[addr_len
+ 1]) { /* pad byte should be used with 3-byte Q.922 */
269 ND_PRINT((ndo
, "Pad! "));
270 } else if (addr_len
== 3)
271 ND_PRINT((ndo
, "No pad! "));
273 nlpid
= p
[hdr_len
- 1];
276 fr_hdr_print(ndo
, length
, addr_len
, dlci
, flags
, nlpid
);
282 ip_print(ndo
, p
, length
);
286 ip6_print(ndo
, p
, length
);
292 isoclns_print(ndo
, p
- 1, length
+ 1, length
+ 1); /* OSI printers need the NLPID field */
296 if (snap_print(ndo
, p
, length
, length
, 0) == 0) {
297 /* ether_type not known, print raw packet */
299 fr_hdr_print(ndo
, length
+ hdr_len
, hdr_len
,
301 if (!ndo
->ndo_suppress_default_print
)
302 ND_DEFAULTPRINT(p
- hdr_len
, length
+ hdr_len
);
307 q933_print(ndo
, p
, length
);
311 frf15_print(ndo
, p
, length
);
315 ppp_print(ndo
, p
, length
);
320 fr_hdr_print(ndo
, length
+ hdr_len
, addr_len
,
323 ND_DEFAULTPRINT(p
, length
);
329 ND_PRINT((ndo
, "[|fr]"));
335 mfr_if_print(netdissect_options
*ndo
,
336 const struct pcap_pkthdr
*h
, register const u_char
*p
)
338 register u_int length
= h
->len
;
339 register u_int caplen
= h
->caplen
;
341 ND_TCHECK2(*p
, 2); /* minimum frame header length */
343 if ((length
= mfr_print(ndo
, p
, length
)) == 0)
348 ND_PRINT((ndo
, "[|mfr]"));
353 #define MFR_CTRL_MSG_ADD_LINK 1
354 #define MFR_CTRL_MSG_ADD_LINK_ACK 2
355 #define MFR_CTRL_MSG_ADD_LINK_REJ 3
356 #define MFR_CTRL_MSG_HELLO 4
357 #define MFR_CTRL_MSG_HELLO_ACK 5
358 #define MFR_CTRL_MSG_REMOVE_LINK 6
359 #define MFR_CTRL_MSG_REMOVE_LINK_ACK 7
361 static const struct tok mfr_ctrl_msg_values
[] = {
362 { MFR_CTRL_MSG_ADD_LINK
, "Add Link" },
363 { MFR_CTRL_MSG_ADD_LINK_ACK
, "Add Link ACK" },
364 { MFR_CTRL_MSG_ADD_LINK_REJ
, "Add Link Reject" },
365 { MFR_CTRL_MSG_HELLO
, "Hello" },
366 { MFR_CTRL_MSG_HELLO_ACK
, "Hello ACK" },
367 { MFR_CTRL_MSG_REMOVE_LINK
, "Remove Link" },
368 { MFR_CTRL_MSG_REMOVE_LINK_ACK
, "Remove Link ACK" },
372 #define MFR_CTRL_IE_BUNDLE_ID 1
373 #define MFR_CTRL_IE_LINK_ID 2
374 #define MFR_CTRL_IE_MAGIC_NUM 3
375 #define MFR_CTRL_IE_TIMESTAMP 5
376 #define MFR_CTRL_IE_VENDOR_EXT 6
377 #define MFR_CTRL_IE_CAUSE 7
379 static const struct tok mfr_ctrl_ie_values
[] = {
380 { MFR_CTRL_IE_BUNDLE_ID
, "Bundle ID"},
381 { MFR_CTRL_IE_LINK_ID
, "Link ID"},
382 { MFR_CTRL_IE_MAGIC_NUM
, "Magic Number"},
383 { MFR_CTRL_IE_TIMESTAMP
, "Timestamp"},
384 { MFR_CTRL_IE_VENDOR_EXT
, "Vendor Extension"},
385 { MFR_CTRL_IE_CAUSE
, "Cause"},
389 #define MFR_ID_STRING_MAXLEN 50
391 struct ie_tlv_header_t
{
397 mfr_print(netdissect_options
*ndo
,
398 register const u_char
*p
, u_int length
)
400 u_int tlen
,idx
,hdr_len
= 0;
401 uint16_t sequence_num
;
402 uint8_t ie_type
,ie_len
;
407 * FRF.16 Link Integrity Control Frame
410 * +----+----+----+----+----+----+----+----+
411 * | B | E | C=1| 0 0 0 0 | EA |
412 * +----+----+----+----+----+----+----+----+
413 * | 0 0 0 0 0 0 0 0 |
414 * +----+----+----+----+----+----+----+----+
416 * +----+----+----+----+----+----+----+----+
419 ND_TCHECK2(*p
, 4); /* minimum frame header length */
421 if ((p
[0] & MFR_BEC_MASK
) == MFR_CTRL_FRAME
&& p
[1] == 0) {
422 ND_PRINT((ndo
, "FRF.16 Control, Flags [%s], %s, length %u",
423 bittok2str(frf_flag_values
,"none",(p
[0] & MFR_BEC_MASK
)),
424 tok2str(mfr_ctrl_msg_values
,"Unknown Message (0x%02x)",p
[2]),
433 while (tlen
>sizeof(struct ie_tlv_header_t
)) {
434 ND_TCHECK2(*tptr
, sizeof(struct ie_tlv_header_t
));
438 ND_PRINT((ndo
, "\n\tIE %s (%u), length %u: ",
439 tok2str(mfr_ctrl_ie_values
,"Unknown",ie_type
),
443 /* infinite loop check */
444 if (ie_type
== 0 || ie_len
<= sizeof(struct ie_tlv_header_t
))
447 ND_TCHECK2(*tptr
, ie_len
);
448 tptr
+=sizeof(struct ie_tlv_header_t
);
449 /* tlv len includes header */
450 ie_len
-=sizeof(struct ie_tlv_header_t
);
451 tlen
-=sizeof(struct ie_tlv_header_t
);
455 case MFR_CTRL_IE_MAGIC_NUM
:
456 ND_PRINT((ndo
, "0x%08x", EXTRACT_32BITS(tptr
)));
459 case MFR_CTRL_IE_BUNDLE_ID
: /* same message format */
460 case MFR_CTRL_IE_LINK_ID
:
461 for (idx
= 0; idx
< ie_len
&& idx
< MFR_ID_STRING_MAXLEN
; idx
++) {
462 if (*(tptr
+idx
) != 0) /* don't print null termination */
463 safeputchar(ndo
, *(tptr
+ idx
));
469 case MFR_CTRL_IE_TIMESTAMP
:
470 if (ie_len
== sizeof(struct timeval
)) {
471 ts_print(ndo
, (const struct timeval
*)tptr
);
474 /* fall through and hexdump if no unix timestamp */
477 * FIXME those are the defined IEs that lack a decoder
478 * you are welcome to contribute code ;-)
481 case MFR_CTRL_IE_VENDOR_EXT
:
482 case MFR_CTRL_IE_CAUSE
:
485 if (ndo
->ndo_vflag
<= 1)
486 print_unknown_data(ndo
, tptr
, "\n\t ", ie_len
);
490 /* do we want to see a hexdump of the IE ? */
491 if (ndo
->ndo_vflag
> 1 )
492 print_unknown_data(ndo
, tptr
, "\n\t ", ie_len
);
500 * FRF.16 Fragmentation Frame
503 * +----+----+----+----+----+----+----+----+
504 * | B | E | C=0|seq. (high 4 bits) | EA |
505 * +----+----+----+----+----+----+----+----+
506 * | sequence (low 8 bits) |
507 * +----+----+----+----+----+----+----+----+
508 * | DLCI (6 bits) | CR | EA |
509 * +----+----+----+----+----+----+----+----+
510 * | DLCI (4 bits) |FECN|BECN| DE | EA |
511 * +----+----+----+----+----+----+----+----+
514 sequence_num
= (p
[0]&0x1e)<<7 | p
[1];
515 /* whole packet or first fragment ? */
516 if ((p
[0] & MFR_BEC_MASK
) == MFR_FRAG_FRAME
||
517 (p
[0] & MFR_BEC_MASK
) == MFR_B_BIT
) {
518 ND_PRINT((ndo
, "FRF.16 Frag, seq %u, Flags [%s], ",
520 bittok2str(frf_flag_values
,"none",(p
[0] & MFR_BEC_MASK
))));
522 fr_print(ndo
, p
+hdr_len
,length
-hdr_len
);
526 /* must be a middle or the last fragment */
527 ND_PRINT((ndo
, "FRF.16 Frag, seq %u, Flags [%s]",
529 bittok2str(frf_flag_values
,"none",(p
[0] & MFR_BEC_MASK
))));
530 print_unknown_data(ndo
, p
, "\n\t", length
);
535 ND_PRINT((ndo
, "[|mfr]"));
539 /* an NLPID of 0xb1 indicates a 2-byte
543 * +----+----+----+----+----+----+----+----+
545 * +----+----+----+----+----+----+----+----+
546 * | NLPID (8 bits) | NLPID=0xb1
547 * +----+----+----+----+----+----+----+----+
548 * | B | E | C |seq. (high 4 bits) | R |
549 * +----+----+----+----+----+----+----+----+
550 * | sequence (low 8 bits) |
551 * +----+----+----+----+----+----+----+----+
554 #define FR_FRF15_FRAGTYPE 0x01
557 frf15_print(netdissect_options
*ndo
,
558 const u_char
*p
, u_int length
) {
560 uint16_t sequence_num
, flags
;
562 flags
= p
[0]&MFR_BEC_MASK
;
563 sequence_num
= (p
[0]&0x1e)<<7 | p
[1];
565 ND_PRINT((ndo
, "FRF.15, seq 0x%03x, Flags [%s],%s Fragmentation, length %u",
567 bittok2str(frf_flag_values
,"none",flags
),
568 p
[0]&FR_FRF15_FRAGTYPE
? "Interface" : "End-to-End",
572 * depending on all permutations of the B, E and C bit
573 * dig as deep as we can - e.g. on the first (B) fragment
574 * there is enough payload to print the IP header
575 * on non (B) fragments it depends if the fragmentation
576 * model is end-to-end or interface based wether we want to print
577 * another Q.922 header
583 * Q.933 decoding portion for framerelay specific.
586 /* Q.933 packet format
587 Format of Other Protocols
589 +-------------------------------+
591 +---------------+---------------+
592 |Control 0x03 | NLPID 0x08 |
593 +---------------+---------------+
595 | octet 1 | octet 2 |
596 +-------------------------------+
598 | octet 2 | octet 2 |
599 +-------------------------------+
601 +-------------------------------+
603 +-------------------------------+
606 /* L2 (Octet 1)- Call Reference Usually is 0x0 */
609 * L2 (Octet 2)- Message Types definition 1 byte long.
612 #define MSG_TYPE_ESC_TO_NATIONAL 0x00
613 #define MSG_TYPE_ALERT 0x01
614 #define MSG_TYPE_CALL_PROCEEDING 0x02
615 #define MSG_TYPE_CONNECT 0x07
616 #define MSG_TYPE_CONNECT_ACK 0x0F
617 #define MSG_TYPE_PROGRESS 0x03
618 #define MSG_TYPE_SETUP 0x05
620 #define MSG_TYPE_DISCONNECT 0x45
621 #define MSG_TYPE_RELEASE 0x4D
622 #define MSG_TYPE_RELEASE_COMPLETE 0x5A
623 #define MSG_TYPE_RESTART 0x46
624 #define MSG_TYPE_RESTART_ACK 0x4E
626 #define MSG_TYPE_STATUS 0x7D
627 #define MSG_TYPE_STATUS_ENQ 0x75
629 static const struct tok fr_q933_msg_values
[] = {
630 { MSG_TYPE_ESC_TO_NATIONAL
, "ESC to National" },
631 { MSG_TYPE_ALERT
, "Alert" },
632 { MSG_TYPE_CALL_PROCEEDING
, "Call proceeding" },
633 { MSG_TYPE_CONNECT
, "Connect" },
634 { MSG_TYPE_CONNECT_ACK
, "Connect ACK" },
635 { MSG_TYPE_PROGRESS
, "Progress" },
636 { MSG_TYPE_SETUP
, "Setup" },
637 { MSG_TYPE_DISCONNECT
, "Disconnect" },
638 { MSG_TYPE_RELEASE
, "Release" },
639 { MSG_TYPE_RELEASE_COMPLETE
, "Release Complete" },
640 { MSG_TYPE_RESTART
, "Restart" },
641 { MSG_TYPE_RESTART_ACK
, "Restart ACK" },
642 { MSG_TYPE_STATUS
, "Status Reply" },
643 { MSG_TYPE_STATUS_ENQ
, "Status Enquiry" },
647 #define MSG_ANSI_LOCKING_SHIFT 0x95
649 #define FR_LMI_ANSI_REPORT_TYPE_IE 0x01
650 #define FR_LMI_ANSI_LINK_VERIFY_IE_91 0x19 /* details? */
651 #define FR_LMI_ANSI_LINK_VERIFY_IE 0x03
652 #define FR_LMI_ANSI_PVC_STATUS_IE 0x07
654 #define FR_LMI_CCITT_REPORT_TYPE_IE 0x51
655 #define FR_LMI_CCITT_LINK_VERIFY_IE 0x53
656 #define FR_LMI_CCITT_PVC_STATUS_IE 0x57
658 static const struct tok fr_q933_ie_values_codeset5
[] = {
659 { FR_LMI_ANSI_REPORT_TYPE_IE
, "ANSI Report Type" },
660 { FR_LMI_ANSI_LINK_VERIFY_IE_91
, "ANSI Link Verify" },
661 { FR_LMI_ANSI_LINK_VERIFY_IE
, "ANSI Link Verify" },
662 { FR_LMI_ANSI_PVC_STATUS_IE
, "ANSI PVC Status" },
663 { FR_LMI_CCITT_REPORT_TYPE_IE
, "CCITT Report Type" },
664 { FR_LMI_CCITT_LINK_VERIFY_IE
, "CCITT Link Verify" },
665 { FR_LMI_CCITT_PVC_STATUS_IE
, "CCITT PVC Status" },
669 #define FR_LMI_REPORT_TYPE_IE_FULL_STATUS 0
670 #define FR_LMI_REPORT_TYPE_IE_LINK_VERIFY 1
671 #define FR_LMI_REPORT_TYPE_IE_ASYNC_PVC 2
673 static const struct tok fr_lmi_report_type_ie_values
[] = {
674 { FR_LMI_REPORT_TYPE_IE_FULL_STATUS
, "Full Status" },
675 { FR_LMI_REPORT_TYPE_IE_LINK_VERIFY
, "Link verify" },
676 { FR_LMI_REPORT_TYPE_IE_ASYNC_PVC
, "Async PVC Status" },
680 /* array of 16 codepages - currently we only support codepage 1,5 */
681 static const struct tok
*fr_q933_ie_codesets
[] = {
683 fr_q933_ie_values_codeset5
,
687 fr_q933_ie_values_codeset5
,
700 static int fr_q933_print_ie_codeset5(netdissect_options
*ndo
,
701 const struct ie_tlv_header_t
*ie_p
, const u_char
*p
);
703 typedef int (*codeset_pr_func_t
)(netdissect_options
*,
704 const struct ie_tlv_header_t
*ie_p
, const u_char
*p
);
706 /* array of 16 codepages - currently we only support codepage 1,5 */
707 static const codeset_pr_func_t fr_q933_print_ie_codeset
[] = {
709 fr_q933_print_ie_codeset5
,
713 fr_q933_print_ie_codeset5
,
727 q933_print(netdissect_options
*ndo
,
728 const u_char
*p
, u_int length
)
730 const u_char
*ptemp
= p
;
731 struct ie_tlv_header_t
*ie_p
;
735 u_int ie_is_known
= 0;
737 if (length
< 9) { /* shortest: Q.933a LINK VERIFY */
738 ND_PRINT((ndo
, "[|q.933]"));
742 codeset
= p
[2]&0x0f; /* extract the codeset */
744 if (p
[2] == MSG_ANSI_LOCKING_SHIFT
) {
748 ND_PRINT((ndo
, "%s", ndo
->ndo_eflag
? "" : "Q.933, "));
750 /* printing out header part */
751 ND_PRINT((ndo
, "%s, codeset %u", is_ansi
? "ANSI" : "CCITT", codeset
));
754 ND_PRINT((ndo
, ", Call Ref: 0x%02x", p
[0]));
756 if (ndo
->ndo_vflag
) {
757 ND_PRINT((ndo
, ", %s (0x%02x), length %u",
758 tok2str(fr_q933_msg_values
,
759 "unknown message", p
[1]),
763 ND_PRINT((ndo
, ", %s",
764 tok2str(fr_q933_msg_values
,
765 "unknown message 0x%02x", p
[1])));
768 olen
= length
; /* preserve the original length for non verbose mode */
770 if (length
< (u_int
)(2 - is_ansi
)) {
771 ND_PRINT((ndo
, "[|q.933]"));
774 length
-= 2 + is_ansi
;
775 ptemp
+= 2 + is_ansi
;
777 /* Loop through the rest of IE */
778 while (length
> sizeof(struct ie_tlv_header_t
)) {
779 ie_p
= (struct ie_tlv_header_t
*)ptemp
;
780 if (length
< sizeof(struct ie_tlv_header_t
) ||
781 length
< sizeof(struct ie_tlv_header_t
) + ie_p
->ie_len
) {
782 if (ndo
->ndo_vflag
) { /* not bark if there is just a trailer */
783 ND_PRINT((ndo
, "\n[|q.933]"));
785 ND_PRINT((ndo
, ", length %u", olen
));
790 /* lets do the full IE parsing only in verbose mode
791 * however some IEs (DLCI Status, Link Verify)
792 * are also interestting in non-verbose mode */
793 if (ndo
->ndo_vflag
) {
794 ND_PRINT((ndo
, "\n\t%s IE (0x%02x), length %u: ",
795 tok2str(fr_q933_ie_codesets
[codeset
],
796 "unknown", ie_p
->ie_type
),
802 if (ie_p
->ie_type
== 0 || ie_p
->ie_len
== 0) {
806 if (fr_q933_print_ie_codeset
[codeset
] != NULL
) {
807 ie_is_known
= fr_q933_print_ie_codeset
[codeset
](ndo
, ie_p
, ptemp
);
810 if (ndo
->ndo_vflag
>= 1 && !ie_is_known
) {
811 print_unknown_data(ndo
, ptemp
+2, "\n\t", ie_p
->ie_len
);
814 /* do we want to see a hexdump of the IE ? */
815 if (ndo
->ndo_vflag
> 1 && ie_is_known
) {
816 print_unknown_data(ndo
, ptemp
+2, "\n\t ", ie_p
->ie_len
);
819 length
= length
- ie_p
->ie_len
- 2;
820 ptemp
= ptemp
+ ie_p
->ie_len
+ 2;
822 if (!ndo
->ndo_vflag
) {
823 ND_PRINT((ndo
, ", length %u", olen
));
828 fr_q933_print_ie_codeset5(netdissect_options
*ndo
,
829 const struct ie_tlv_header_t
*ie_p
, const u_char
*p
)
833 switch (ie_p
->ie_type
) {
835 case FR_LMI_ANSI_REPORT_TYPE_IE
: /* fall through */
836 case FR_LMI_CCITT_REPORT_TYPE_IE
:
837 if (ndo
->ndo_vflag
) {
838 ND_PRINT((ndo
, "%s (%u)",
839 tok2str(fr_lmi_report_type_ie_values
,"unknown",p
[2]),
844 case FR_LMI_ANSI_LINK_VERIFY_IE
: /* fall through */
845 case FR_LMI_CCITT_LINK_VERIFY_IE
:
846 case FR_LMI_ANSI_LINK_VERIFY_IE_91
:
847 if (!ndo
->ndo_vflag
) {
848 ND_PRINT((ndo
, ", "));
850 ND_PRINT((ndo
, "TX Seq: %3d, RX Seq: %3d", p
[2], p
[3]));
853 case FR_LMI_ANSI_PVC_STATUS_IE
: /* fall through */
854 case FR_LMI_CCITT_PVC_STATUS_IE
:
855 if (!ndo
->ndo_vflag
) {
856 ND_PRINT((ndo
, ", "));
858 /* now parse the DLCI information element. */
859 if ((ie_p
->ie_len
< 3) ||
861 ((ie_p
->ie_len
== 3) && !(p
[3] & 0x80)) ||
862 ((ie_p
->ie_len
== 4) && ((p
[3] & 0x80) || !(p
[4] & 0x80))) ||
863 ((ie_p
->ie_len
== 5) && ((p
[3] & 0x80) || (p
[4] & 0x80) ||
865 (ie_p
->ie_len
> 5) ||
866 !(p
[ie_p
->ie_len
+ 1] & 0x80)) {
867 ND_PRINT((ndo
, "Invalid DLCI IE"));
870 dlci
= ((p
[2] & 0x3F) << 4) | ((p
[3] & 0x78) >> 3);
871 if (ie_p
->ie_len
== 4) {
872 dlci
= (dlci
<< 6) | ((p
[4] & 0x7E) >> 1);
874 else if (ie_p
->ie_len
== 5) {
875 dlci
= (dlci
<< 13) | (p
[4] & 0x7F) | ((p
[5] & 0x7E) >> 1);
878 ND_PRINT((ndo
, "DLCI %u: status %s%s", dlci
,
879 p
[ie_p
->ie_len
+ 1] & 0x8 ? "New, " : "",
880 p
[ie_p
->ie_len
+ 1] & 0x2 ? "Active" : "Inactive"));
888 * c-style: whitesmith