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.
26 #include <netdissect-stdinc.h>
31 #include "netdissect.h"
32 #include "addrtoname.h"
33 #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 1 on success,
96 * 0 on invalid address, -1 on truncated packet
97 * save the flags dep. on address length
99 static int parse_q922_addr(netdissect_options
*ndo
,
100 const u_char
*p
, u_int
*dlci
,
101 u_int
*addr_len
, uint8_t *flags
, u_int length
)
103 if (!ND_TTEST(p
[0]) || length
< 1)
105 if ((p
[0] & FR_EA_BIT
))
108 if (!ND_TTEST(p
[1]) || length
< 2)
111 *dlci
= ((p
[0] & 0xFC) << 2) | ((p
[1] & 0xF0) >> 4);
113 flags
[0] = p
[0] & 0x02; /* populate the first flag fields */
114 flags
[1] = p
[1] & 0x0c;
115 flags
[2] = 0; /* clear the rest of the flags */
118 if (p
[1] & FR_EA_BIT
)
119 return 1; /* 2-byte Q.922 address */
123 if (!ND_TTEST(p
[0]) || length
< 1)
125 (*addr_len
)++; /* 3- or 4-byte Q.922 address */
126 if ((p
[0] & FR_EA_BIT
) == 0) {
127 *dlci
= (*dlci
<< 7) | (p
[0] >> 1);
128 (*addr_len
)++; /* 4-byte Q.922 address */
133 if (!ND_TTEST(p
[0]) || length
< 1)
135 if ((p
[0] & FR_EA_BIT
) == 0)
136 return 0; /* more than 4 bytes of Q.922 address? */
138 flags
[3] = p
[0] & 0x02;
140 *dlci
= (*dlci
<< 6) | (p
[0] >> 2);
146 q922_string(netdissect_options
*ndo
, const u_char
*p
, u_int length
)
149 static u_int dlci
, addr_len
;
150 static uint8_t flags
[4];
151 static char buffer
[sizeof("DLCI xxxxxxxxxx")];
152 memset(buffer
, 0, sizeof(buffer
));
154 if (parse_q922_addr(ndo
, p
, &dlci
, &addr_len
, flags
, length
) == 1){
155 snprintf(buffer
, sizeof(buffer
), "DLCI %u", dlci
);
162 /* Frame Relay packet structure, with flags and CRC removed
164 +---------------------------+
168 +---------------------------+
169 | Control (UI = 0x03) |
170 +---------------------------+
171 | Optional Pad (0x00) |
172 +---------------------------+
174 +---------------------------+
181 +---------------------------+
183 * Q.922 addresses, as presently defined, are two octets and
184 contain a 10-bit DLCI. In some networks Q.922 addresses
185 may optionally be increased to three or four octets.
189 fr_hdr_print(netdissect_options
*ndo
,
190 int length
, u_int addr_len
, u_int dlci
, uint8_t *flags
, uint16_t nlpid
)
192 if (ndo
->ndo_qflag
) {
193 ND_PRINT((ndo
, "Q.922, DLCI %u, length %u: ",
197 if (nlpid
<= 0xff) /* if its smaller than 256 then its a NLPID */
198 ND_PRINT((ndo
, "Q.922, hdr-len %u, DLCI %u, Flags [%s], NLPID %s (0x%02x), length %u: ",
201 bittok2str(fr_header_flag_values
, "none", EXTRACT_32BITS(flags
)),
202 tok2str(nlpid_values
,"unknown", nlpid
),
205 else /* must be an ethertype */
206 ND_PRINT((ndo
, "Q.922, hdr-len %u, DLCI %u, Flags [%s], cisco-ethertype %s (0x%04x), length %u: ",
209 bittok2str(fr_header_flag_values
, "none", EXTRACT_32BITS(flags
)),
210 tok2str(ethertype_values
, "unknown", nlpid
),
217 fr_if_print(netdissect_options
*ndo
,
218 const struct pcap_pkthdr
*h
, register const u_char
*p
)
220 register u_int length
= h
->len
;
221 register u_int caplen
= h
->caplen
;
223 ND_TCHECK2(*p
, 4); /* minimum frame header length */
225 if ((length
= fr_print(ndo
, p
, length
)) == 0)
230 ND_PRINT((ndo
, "[|fr]"));
235 fr_print(netdissect_options
*ndo
,
236 register const u_char
*p
, u_int length
)
239 uint16_t extracted_ethertype
;
246 ret
= parse_q922_addr(ndo
, p
, &dlci
, &addr_len
, flags
, length
);
250 ND_PRINT((ndo
, "Q.922, invalid address"));
254 ND_TCHECK(p
[addr_len
]);
255 if (length
< addr_len
+ 1)
258 if (p
[addr_len
] != LLC_UI
&& dlci
!= 0) {
260 * Let's figure out if we have Cisco-style encapsulation,
261 * with an Ethernet type (Cisco HDLC type?) following the
264 if (!ND_TTEST2(p
[addr_len
], 2) || length
< addr_len
+ 2) {
266 ND_PRINT((ndo
, "UI %02x! ", p
[addr_len
]));
268 extracted_ethertype
= EXTRACT_16BITS(p
+addr_len
);
271 fr_hdr_print(ndo
, length
, addr_len
, dlci
,
272 flags
, extracted_ethertype
);
274 if (ethertype_print(ndo
, extracted_ethertype
,
275 p
+addr_len
+ETHERTYPE_LEN
,
276 length
-addr_len
-ETHERTYPE_LEN
,
277 length
-addr_len
-ETHERTYPE_LEN
) == 0)
278 /* ether_type not known, probably it wasn't one */
279 ND_PRINT((ndo
, "UI %02x! ", p
[addr_len
]));
285 ND_TCHECK(p
[addr_len
+1]);
286 if (length
< addr_len
+ 2)
289 if (p
[addr_len
+ 1] == 0) {
291 * Assume a pad byte after the control (UI) byte.
292 * A pad byte should only be used with 3-byte Q.922.
295 ND_PRINT((ndo
, "Pad! "));
296 hdr_len
= addr_len
+ 1 /* UI */ + 1 /* pad */ + 1 /* NLPID */;
300 * A pad byte should be used with 3-byte Q.922.
303 ND_PRINT((ndo
, "No pad! "));
304 hdr_len
= addr_len
+ 1 /* UI */ + 1 /* NLPID */;
307 ND_TCHECK(p
[hdr_len
- 1]);
308 if (length
< hdr_len
)
310 nlpid
= p
[hdr_len
- 1];
313 fr_hdr_print(ndo
, length
, addr_len
, dlci
, flags
, nlpid
);
319 ip_print(ndo
, p
, length
);
323 ip6_print(ndo
, p
, length
);
329 isoclns_print(ndo
, p
- 1, length
+ 1, length
+ 1); /* OSI printers need the NLPID field */
333 if (snap_print(ndo
, p
, length
, length
, NULL
, NULL
, 0) == 0) {
334 /* ether_type not known, print raw packet */
336 fr_hdr_print(ndo
, length
+ hdr_len
, hdr_len
,
338 if (!ndo
->ndo_suppress_default_print
)
339 ND_DEFAULTPRINT(p
- hdr_len
, length
+ hdr_len
);
344 q933_print(ndo
, p
, length
);
348 frf15_print(ndo
, p
, length
);
352 ppp_print(ndo
, p
, length
);
357 fr_hdr_print(ndo
, length
+ hdr_len
, addr_len
,
360 ND_DEFAULTPRINT(p
, length
);
366 ND_PRINT((ndo
, "[|fr]"));
372 mfr_if_print(netdissect_options
*ndo
,
373 const struct pcap_pkthdr
*h
, register const u_char
*p
)
375 register u_int length
= h
->len
;
376 register u_int caplen
= h
->caplen
;
378 ND_TCHECK2(*p
, 2); /* minimum frame header length */
380 if ((length
= mfr_print(ndo
, p
, length
)) == 0)
385 ND_PRINT((ndo
, "[|mfr]"));
390 #define MFR_CTRL_MSG_ADD_LINK 1
391 #define MFR_CTRL_MSG_ADD_LINK_ACK 2
392 #define MFR_CTRL_MSG_ADD_LINK_REJ 3
393 #define MFR_CTRL_MSG_HELLO 4
394 #define MFR_CTRL_MSG_HELLO_ACK 5
395 #define MFR_CTRL_MSG_REMOVE_LINK 6
396 #define MFR_CTRL_MSG_REMOVE_LINK_ACK 7
398 static const struct tok mfr_ctrl_msg_values
[] = {
399 { MFR_CTRL_MSG_ADD_LINK
, "Add Link" },
400 { MFR_CTRL_MSG_ADD_LINK_ACK
, "Add Link ACK" },
401 { MFR_CTRL_MSG_ADD_LINK_REJ
, "Add Link Reject" },
402 { MFR_CTRL_MSG_HELLO
, "Hello" },
403 { MFR_CTRL_MSG_HELLO_ACK
, "Hello ACK" },
404 { MFR_CTRL_MSG_REMOVE_LINK
, "Remove Link" },
405 { MFR_CTRL_MSG_REMOVE_LINK_ACK
, "Remove Link ACK" },
409 #define MFR_CTRL_IE_BUNDLE_ID 1
410 #define MFR_CTRL_IE_LINK_ID 2
411 #define MFR_CTRL_IE_MAGIC_NUM 3
412 #define MFR_CTRL_IE_TIMESTAMP 5
413 #define MFR_CTRL_IE_VENDOR_EXT 6
414 #define MFR_CTRL_IE_CAUSE 7
416 static const struct tok mfr_ctrl_ie_values
[] = {
417 { MFR_CTRL_IE_BUNDLE_ID
, "Bundle ID"},
418 { MFR_CTRL_IE_LINK_ID
, "Link ID"},
419 { MFR_CTRL_IE_MAGIC_NUM
, "Magic Number"},
420 { MFR_CTRL_IE_TIMESTAMP
, "Timestamp"},
421 { MFR_CTRL_IE_VENDOR_EXT
, "Vendor Extension"},
422 { MFR_CTRL_IE_CAUSE
, "Cause"},
426 #define MFR_ID_STRING_MAXLEN 50
428 struct ie_tlv_header_t
{
434 mfr_print(netdissect_options
*ndo
,
435 register const u_char
*p
, u_int length
)
437 u_int tlen
,idx
,hdr_len
= 0;
438 uint16_t sequence_num
;
439 uint8_t ie_type
,ie_len
;
444 * FRF.16 Link Integrity Control Frame
447 * +----+----+----+----+----+----+----+----+
448 * | B | E | C=1| 0 0 0 0 | EA |
449 * +----+----+----+----+----+----+----+----+
450 * | 0 0 0 0 0 0 0 0 |
451 * +----+----+----+----+----+----+----+----+
453 * +----+----+----+----+----+----+----+----+
456 ND_TCHECK2(*p
, 4); /* minimum frame header length */
458 if ((p
[0] & MFR_BEC_MASK
) == MFR_CTRL_FRAME
&& p
[1] == 0) {
459 ND_PRINT((ndo
, "FRF.16 Control, Flags [%s], %s, length %u",
460 bittok2str(frf_flag_values
,"none",(p
[0] & MFR_BEC_MASK
)),
461 tok2str(mfr_ctrl_msg_values
,"Unknown Message (0x%02x)",p
[2]),
470 while (tlen
>sizeof(struct ie_tlv_header_t
)) {
471 ND_TCHECK2(*tptr
, sizeof(struct ie_tlv_header_t
));
475 ND_PRINT((ndo
, "\n\tIE %s (%u), length %u: ",
476 tok2str(mfr_ctrl_ie_values
,"Unknown",ie_type
),
480 /* infinite loop check */
481 if (ie_type
== 0 || ie_len
<= sizeof(struct ie_tlv_header_t
))
484 ND_TCHECK2(*tptr
, ie_len
);
485 tptr
+=sizeof(struct ie_tlv_header_t
);
486 /* tlv len includes header */
487 ie_len
-=sizeof(struct ie_tlv_header_t
);
488 tlen
-=sizeof(struct ie_tlv_header_t
);
492 case MFR_CTRL_IE_MAGIC_NUM
:
493 ND_PRINT((ndo
, "0x%08x", EXTRACT_32BITS(tptr
)));
496 case MFR_CTRL_IE_BUNDLE_ID
: /* same message format */
497 case MFR_CTRL_IE_LINK_ID
:
498 for (idx
= 0; idx
< ie_len
&& idx
< MFR_ID_STRING_MAXLEN
; idx
++) {
499 if (*(tptr
+idx
) != 0) /* don't print null termination */
500 safeputchar(ndo
, *(tptr
+ idx
));
506 case MFR_CTRL_IE_TIMESTAMP
:
507 if (ie_len
== sizeof(struct timeval
)) {
508 ts_print(ndo
, (const struct timeval
*)tptr
);
511 /* fall through and hexdump if no unix timestamp */
514 * FIXME those are the defined IEs that lack a decoder
515 * you are welcome to contribute code ;-)
518 case MFR_CTRL_IE_VENDOR_EXT
:
519 case MFR_CTRL_IE_CAUSE
:
522 if (ndo
->ndo_vflag
<= 1)
523 print_unknown_data(ndo
, tptr
, "\n\t ", ie_len
);
527 /* do we want to see a hexdump of the IE ? */
528 if (ndo
->ndo_vflag
> 1 )
529 print_unknown_data(ndo
, tptr
, "\n\t ", ie_len
);
537 * FRF.16 Fragmentation Frame
540 * +----+----+----+----+----+----+----+----+
541 * | B | E | C=0|seq. (high 4 bits) | EA |
542 * +----+----+----+----+----+----+----+----+
543 * | sequence (low 8 bits) |
544 * +----+----+----+----+----+----+----+----+
545 * | DLCI (6 bits) | CR | EA |
546 * +----+----+----+----+----+----+----+----+
547 * | DLCI (4 bits) |FECN|BECN| DE | EA |
548 * +----+----+----+----+----+----+----+----+
551 sequence_num
= (p
[0]&0x1e)<<7 | p
[1];
552 /* whole packet or first fragment ? */
553 if ((p
[0] & MFR_BEC_MASK
) == MFR_FRAG_FRAME
||
554 (p
[0] & MFR_BEC_MASK
) == MFR_B_BIT
) {
555 ND_PRINT((ndo
, "FRF.16 Frag, seq %u, Flags [%s], ",
557 bittok2str(frf_flag_values
,"none",(p
[0] & MFR_BEC_MASK
))));
559 fr_print(ndo
, p
+hdr_len
,length
-hdr_len
);
563 /* must be a middle or the last fragment */
564 ND_PRINT((ndo
, "FRF.16 Frag, seq %u, Flags [%s]",
566 bittok2str(frf_flag_values
,"none",(p
[0] & MFR_BEC_MASK
))));
567 print_unknown_data(ndo
, p
, "\n\t", length
);
572 ND_PRINT((ndo
, "[|mfr]"));
576 /* an NLPID of 0xb1 indicates a 2-byte
580 * +----+----+----+----+----+----+----+----+
582 * +----+----+----+----+----+----+----+----+
583 * | NLPID (8 bits) | NLPID=0xb1
584 * +----+----+----+----+----+----+----+----+
585 * | B | E | C |seq. (high 4 bits) | R |
586 * +----+----+----+----+----+----+----+----+
587 * | sequence (low 8 bits) |
588 * +----+----+----+----+----+----+----+----+
591 #define FR_FRF15_FRAGTYPE 0x01
594 frf15_print(netdissect_options
*ndo
,
595 const u_char
*p
, u_int length
)
597 uint16_t sequence_num
, flags
;
599 flags
= p
[0]&MFR_BEC_MASK
;
600 sequence_num
= (p
[0]&0x1e)<<7 | p
[1];
602 ND_PRINT((ndo
, "FRF.15, seq 0x%03x, Flags [%s],%s Fragmentation, length %u",
604 bittok2str(frf_flag_values
,"none",flags
),
605 p
[0]&FR_FRF15_FRAGTYPE
? "Interface" : "End-to-End",
609 * depending on all permutations of the B, E and C bit
610 * dig as deep as we can - e.g. on the first (B) fragment
611 * there is enough payload to print the IP header
612 * on non (B) fragments it depends if the fragmentation
613 * model is end-to-end or interface based wether we want to print
614 * another Q.922 header
620 * Q.933 decoding portion for framerelay specific.
623 /* Q.933 packet format
624 Format of Other Protocols
626 +-------------------------------+
628 +---------------+---------------+
629 |Control 0x03 | NLPID 0x08 |
630 +---------------+---------------+
632 | octet 1 | octet 2 |
633 +-------------------------------+
635 | octet 2 | octet 2 |
636 +-------------------------------+
638 +-------------------------------+
640 +-------------------------------+
643 /* L2 (Octet 1)- Call Reference Usually is 0x0 */
646 * L2 (Octet 2)- Message Types definition 1 byte long.
649 #define MSG_TYPE_ESC_TO_NATIONAL 0x00
650 #define MSG_TYPE_ALERT 0x01
651 #define MSG_TYPE_CALL_PROCEEDING 0x02
652 #define MSG_TYPE_CONNECT 0x07
653 #define MSG_TYPE_CONNECT_ACK 0x0F
654 #define MSG_TYPE_PROGRESS 0x03
655 #define MSG_TYPE_SETUP 0x05
657 #define MSG_TYPE_DISCONNECT 0x45
658 #define MSG_TYPE_RELEASE 0x4D
659 #define MSG_TYPE_RELEASE_COMPLETE 0x5A
660 #define MSG_TYPE_RESTART 0x46
661 #define MSG_TYPE_RESTART_ACK 0x4E
663 #define MSG_TYPE_STATUS 0x7D
664 #define MSG_TYPE_STATUS_ENQ 0x75
666 static const struct tok fr_q933_msg_values
[] = {
667 { MSG_TYPE_ESC_TO_NATIONAL
, "ESC to National" },
668 { MSG_TYPE_ALERT
, "Alert" },
669 { MSG_TYPE_CALL_PROCEEDING
, "Call proceeding" },
670 { MSG_TYPE_CONNECT
, "Connect" },
671 { MSG_TYPE_CONNECT_ACK
, "Connect ACK" },
672 { MSG_TYPE_PROGRESS
, "Progress" },
673 { MSG_TYPE_SETUP
, "Setup" },
674 { MSG_TYPE_DISCONNECT
, "Disconnect" },
675 { MSG_TYPE_RELEASE
, "Release" },
676 { MSG_TYPE_RELEASE_COMPLETE
, "Release Complete" },
677 { MSG_TYPE_RESTART
, "Restart" },
678 { MSG_TYPE_RESTART_ACK
, "Restart ACK" },
679 { MSG_TYPE_STATUS
, "Status Reply" },
680 { MSG_TYPE_STATUS_ENQ
, "Status Enquiry" },
684 #define MSG_ANSI_LOCKING_SHIFT 0x95
686 #define FR_LMI_ANSI_REPORT_TYPE_IE 0x01
687 #define FR_LMI_ANSI_LINK_VERIFY_IE_91 0x19 /* details? */
688 #define FR_LMI_ANSI_LINK_VERIFY_IE 0x03
689 #define FR_LMI_ANSI_PVC_STATUS_IE 0x07
691 #define FR_LMI_CCITT_REPORT_TYPE_IE 0x51
692 #define FR_LMI_CCITT_LINK_VERIFY_IE 0x53
693 #define FR_LMI_CCITT_PVC_STATUS_IE 0x57
695 static const struct tok fr_q933_ie_values_codeset5
[] = {
696 { FR_LMI_ANSI_REPORT_TYPE_IE
, "ANSI Report Type" },
697 { FR_LMI_ANSI_LINK_VERIFY_IE_91
, "ANSI Link Verify" },
698 { FR_LMI_ANSI_LINK_VERIFY_IE
, "ANSI Link Verify" },
699 { FR_LMI_ANSI_PVC_STATUS_IE
, "ANSI PVC Status" },
700 { FR_LMI_CCITT_REPORT_TYPE_IE
, "CCITT Report Type" },
701 { FR_LMI_CCITT_LINK_VERIFY_IE
, "CCITT Link Verify" },
702 { FR_LMI_CCITT_PVC_STATUS_IE
, "CCITT PVC Status" },
706 #define FR_LMI_REPORT_TYPE_IE_FULL_STATUS 0
707 #define FR_LMI_REPORT_TYPE_IE_LINK_VERIFY 1
708 #define FR_LMI_REPORT_TYPE_IE_ASYNC_PVC 2
710 static const struct tok fr_lmi_report_type_ie_values
[] = {
711 { FR_LMI_REPORT_TYPE_IE_FULL_STATUS
, "Full Status" },
712 { FR_LMI_REPORT_TYPE_IE_LINK_VERIFY
, "Link verify" },
713 { FR_LMI_REPORT_TYPE_IE_ASYNC_PVC
, "Async PVC Status" },
717 /* array of 16 codepages - currently we only support codepage 1,5 */
718 static const struct tok
*fr_q933_ie_codesets
[] = {
720 fr_q933_ie_values_codeset5
,
724 fr_q933_ie_values_codeset5
,
737 static int fr_q933_print_ie_codeset5(netdissect_options
*ndo
,
738 const struct ie_tlv_header_t
*ie_p
, const u_char
*p
);
740 typedef int (*codeset_pr_func_t
)(netdissect_options
*,
741 const struct ie_tlv_header_t
*ie_p
, const u_char
*p
);
743 /* array of 16 codepages - currently we only support codepage 1,5 */
744 static const codeset_pr_func_t fr_q933_print_ie_codeset
[] = {
746 fr_q933_print_ie_codeset5
,
750 fr_q933_print_ie_codeset5
,
764 q933_print(netdissect_options
*ndo
,
765 const u_char
*p
, u_int length
)
767 const u_char
*ptemp
= p
;
768 const struct ie_tlv_header_t
*ie_p
;
772 u_int ie_is_known
= 0;
774 if (length
< 9) { /* shortest: Q.933a LINK VERIFY */
775 ND_PRINT((ndo
, "[|q.933]"));
779 codeset
= p
[2]&0x0f; /* extract the codeset */
781 if (p
[2] == MSG_ANSI_LOCKING_SHIFT
) {
785 ND_PRINT((ndo
, "%s", ndo
->ndo_eflag
? "" : "Q.933, "));
787 /* printing out header part */
788 ND_PRINT((ndo
, "%s, codeset %u", is_ansi
? "ANSI" : "CCITT", codeset
));
791 ND_PRINT((ndo
, ", Call Ref: 0x%02x", p
[0]));
793 if (ndo
->ndo_vflag
) {
794 ND_PRINT((ndo
, ", %s (0x%02x), length %u",
795 tok2str(fr_q933_msg_values
,
796 "unknown message", p
[1]),
800 ND_PRINT((ndo
, ", %s",
801 tok2str(fr_q933_msg_values
,
802 "unknown message 0x%02x", p
[1])));
805 olen
= length
; /* preserve the original length for non verbose mode */
807 if (length
< (u_int
)(2 - is_ansi
)) {
808 ND_PRINT((ndo
, "[|q.933]"));
811 length
-= 2 + is_ansi
;
812 ptemp
+= 2 + is_ansi
;
814 /* Loop through the rest of IE */
815 while (length
> sizeof(struct ie_tlv_header_t
)) {
816 ie_p
= (const struct ie_tlv_header_t
*)ptemp
;
817 if (length
< sizeof(struct ie_tlv_header_t
) ||
818 length
< sizeof(struct ie_tlv_header_t
) + ie_p
->ie_len
) {
819 if (ndo
->ndo_vflag
) { /* not bark if there is just a trailer */
820 ND_PRINT((ndo
, "\n[|q.933]"));
822 ND_PRINT((ndo
, ", length %u", olen
));
827 /* lets do the full IE parsing only in verbose mode
828 * however some IEs (DLCI Status, Link Verify)
829 * are also interestting in non-verbose mode */
830 if (ndo
->ndo_vflag
) {
831 ND_PRINT((ndo
, "\n\t%s IE (0x%02x), length %u: ",
832 tok2str(fr_q933_ie_codesets
[codeset
],
833 "unknown", ie_p
->ie_type
),
839 if (ie_p
->ie_type
== 0 || ie_p
->ie_len
== 0) {
843 if (fr_q933_print_ie_codeset
[codeset
] != NULL
) {
844 ie_is_known
= fr_q933_print_ie_codeset
[codeset
](ndo
, ie_p
, ptemp
);
847 if (ndo
->ndo_vflag
>= 1 && !ie_is_known
) {
848 print_unknown_data(ndo
, ptemp
+2, "\n\t", ie_p
->ie_len
);
851 /* do we want to see a hexdump of the IE ? */
852 if (ndo
->ndo_vflag
> 1 && ie_is_known
) {
853 print_unknown_data(ndo
, ptemp
+2, "\n\t ", ie_p
->ie_len
);
856 length
= length
- ie_p
->ie_len
- 2;
857 ptemp
= ptemp
+ ie_p
->ie_len
+ 2;
859 if (!ndo
->ndo_vflag
) {
860 ND_PRINT((ndo
, ", length %u", olen
));
865 fr_q933_print_ie_codeset5(netdissect_options
*ndo
,
866 const struct ie_tlv_header_t
*ie_p
, const u_char
*p
)
870 switch (ie_p
->ie_type
) {
872 case FR_LMI_ANSI_REPORT_TYPE_IE
: /* fall through */
873 case FR_LMI_CCITT_REPORT_TYPE_IE
:
874 if (ndo
->ndo_vflag
) {
875 ND_PRINT((ndo
, "%s (%u)",
876 tok2str(fr_lmi_report_type_ie_values
,"unknown",p
[2]),
881 case FR_LMI_ANSI_LINK_VERIFY_IE
: /* fall through */
882 case FR_LMI_CCITT_LINK_VERIFY_IE
:
883 case FR_LMI_ANSI_LINK_VERIFY_IE_91
:
884 if (!ndo
->ndo_vflag
) {
885 ND_PRINT((ndo
, ", "));
887 ND_PRINT((ndo
, "TX Seq: %3d, RX Seq: %3d", p
[2], p
[3]));
890 case FR_LMI_ANSI_PVC_STATUS_IE
: /* fall through */
891 case FR_LMI_CCITT_PVC_STATUS_IE
:
892 if (!ndo
->ndo_vflag
) {
893 ND_PRINT((ndo
, ", "));
895 /* now parse the DLCI information element. */
896 if ((ie_p
->ie_len
< 3) ||
898 ((ie_p
->ie_len
== 3) && !(p
[3] & 0x80)) ||
899 ((ie_p
->ie_len
== 4) && ((p
[3] & 0x80) || !(p
[4] & 0x80))) ||
900 ((ie_p
->ie_len
== 5) && ((p
[3] & 0x80) || (p
[4] & 0x80) ||
902 (ie_p
->ie_len
> 5) ||
903 !(p
[ie_p
->ie_len
+ 1] & 0x80)) {
904 ND_PRINT((ndo
, "Invalid DLCI IE"));
907 dlci
= ((p
[2] & 0x3F) << 4) | ((p
[3] & 0x78) >> 3);
908 if (ie_p
->ie_len
== 4) {
909 dlci
= (dlci
<< 6) | ((p
[4] & 0x7E) >> 1);
911 else if (ie_p
->ie_len
== 5) {
912 dlci
= (dlci
<< 13) | (p
[4] & 0x7F) | ((p
[5] & 0x7E) >> 1);
915 ND_PRINT((ndo
, "DLCI %u: status %s%s", dlci
,
916 p
[ie_p
->ie_len
+ 1] & 0x8 ? "New, " : "",
917 p
[ie_p
->ie_len
+ 1] & 0x2 ? "Active" : "Inactive"));
925 * c-style: whitesmith