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 /* \summary: Frame Relay printer */
26 #include "netdissect-stdinc.h"
31 #include "netdissect.h"
32 #include "addrtoname.h"
33 #include "ethertype.h"
38 static void frf15_print(netdissect_options
*ndo
, const u_char
*, u_int
);
41 * the frame relay header has a variable length
43 * the EA bit determines if there is another byte
46 * minimum header length is 2 bytes
47 * maximum header length is 4 bytes
50 * +----+----+----+----+----+----+----+----+
51 * | DLCI (6 bits) | CR | EA |
52 * +----+----+----+----+----+----+----+----+
53 * | DLCI (4 bits) |FECN|BECN| DE | EA |
54 * +----+----+----+----+----+----+----+----+
55 * | DLCI (7 bits) | EA |
56 * +----+----+----+----+----+----+----+----+
57 * | DLCI (6 bits) |SDLC| EA |
58 * +----+----+----+----+----+----+----+----+
61 #define FR_EA_BIT 0x01
63 #define FR_CR_BIT 0x02000000
64 #define FR_DE_BIT 0x00020000
65 #define FR_BECN_BIT 0x00040000
66 #define FR_FECN_BIT 0x00080000
67 #define FR_SDLC_BIT 0x00000002
70 static const struct tok fr_header_flag_values
[] = {
73 { FR_BECN_BIT
, "BECN" },
74 { FR_FECN_BIT
, "FECN" },
75 { FR_SDLC_BIT
, "sdlcore" },
80 #define MFR_B_BIT 0x80
81 #define MFR_E_BIT 0x40
82 #define MFR_C_BIT 0x20
83 #define MFR_BEC_MASK (MFR_B_BIT | MFR_E_BIT | MFR_C_BIT)
84 #define MFR_CTRL_FRAME (MFR_B_BIT | MFR_E_BIT | MFR_C_BIT)
85 #define MFR_FRAG_FRAME (MFR_B_BIT | MFR_E_BIT )
87 static const struct tok frf_flag_values
[] = {
88 { MFR_B_BIT
, "Begin" },
90 { MFR_C_BIT
, "Control" },
94 /* Finds out Q.922 address length, DLCI and flags. Returns 1 on success,
95 * 0 on invalid address, -1 on truncated packet
96 * save the flags dep. on address length
98 static int parse_q922_header(netdissect_options
*ndo
,
99 const u_char
*p
, u_int
*dlci
,
100 u_int
*addr_len
, uint32_t *flags
, u_int length
)
102 if (!ND_TTEST_1(p
) || length
< 1)
104 if ((GET_U_1(p
) & FR_EA_BIT
))
107 if (!ND_TTEST_1(p
+ 1) || length
< 2)
110 *dlci
= ((GET_U_1(p
) & 0xFC) << 2) | ((GET_U_1(p
+ 1) & 0xF0) >> 4);
112 *flags
= ((GET_U_1(p
) & 0x02) << 24) | /* CR flag */
113 ((GET_U_1(p
+ 1) & 0x0e) << 16); /* FECN,BECN,DE flags */
115 if (GET_U_1(p
+ 1) & FR_EA_BIT
)
116 return 1; /* 2-byte Q.922 address */
120 if (!ND_TTEST_1(p
) || length
< 1)
122 (*addr_len
)++; /* 3- or 4-byte Q.922 address */
123 if ((GET_U_1(p
) & FR_EA_BIT
) == 0) {
124 *dlci
= (*dlci
<< 7) | (GET_U_1(p
) >> 1);
125 (*addr_len
)++; /* 4-byte Q.922 address */
130 if (!ND_TTEST_1(p
) || length
< 1)
132 if ((GET_U_1(p
) & FR_EA_BIT
) == 0)
133 return 0; /* more than 4 bytes of Q.922 address? */
135 *flags
= *flags
| (GET_U_1(p
) & 0x02); /* SDLC flag */
137 *dlci
= (*dlci
<< 6) | (GET_U_1(p
) >> 2);
143 q922_string(netdissect_options
*ndo
, const u_char
*p
, u_int length
)
146 static u_int dlci
, addr_len
;
147 static uint32_t flags
;
148 static char buffer
[sizeof("parse_q922_header() returned XXXXXXXXXXX")];
150 memset(buffer
, 0, sizeof(buffer
));
152 ret
= parse_q922_header(ndo
, p
, &dlci
, &addr_len
, &flags
, length
);
154 snprintf(buffer
, sizeof(buffer
), "DLCI %u", dlci
);
156 } else if (ret
== 0) {
157 return "<Invalid DLCI>";
158 } else if (ret
== -1) {
159 return "<Truncated>";
161 snprintf(buffer
, sizeof(buffer
), "parse_q922_header() returned %d", ret
);
167 /* Frame Relay packet structure, with flags and CRC removed
169 +---------------------------+
173 +---------------------------+
174 | Control (UI = 0x03) |
175 +---------------------------+
176 | Optional Pad (0x00) |
177 +---------------------------+
179 +---------------------------+
186 +---------------------------+
188 * Q.922 addresses, as presently defined, are two octets and
189 contain a 10-bit DLCI. In some networks Q.922 addresses
190 may optionally be increased to three or four octets.
194 fr_hdr_print(netdissect_options
*ndo
, int length
, u_int addr_len
,
195 u_int dlci
, uint32_t flags
, uint16_t nlpid
)
197 if (ndo
->ndo_qflag
) {
198 ND_PRINT("Q.922, DLCI %u, length %u: ",
202 if (nlpid
<= 0xff) /* if its smaller than 256 then its a NLPID */
203 ND_PRINT("Q.922, hdr-len %u, DLCI %u, Flags [%s], NLPID %s (0x%02x), length %u: ",
206 bittok2str(fr_header_flag_values
, "none", flags
),
207 tok2str(nlpid_values
,"unknown", nlpid
),
210 else /* must be an ethertype */
211 ND_PRINT("Q.922, hdr-len %u, DLCI %u, Flags [%s], cisco-ethertype %s (0x%04x), length %u: ",
214 bittok2str(fr_header_flag_values
, "none", flags
),
215 tok2str(ethertype_values
, "unknown", nlpid
),
223 fr_if_print(netdissect_options
*ndo
,
224 const struct pcap_pkthdr
*h
, const u_char
*p
)
226 u_int length
= h
->len
;
227 u_int caplen
= h
->caplen
;
229 ndo
->ndo_protocol
= "fr";
230 if (caplen
< 4) { /* minimum frame header length */
232 ndo
->ndo_ll_hdr_len
+= caplen
;
236 ndo
->ndo_ll_hdr_len
+= fr_print(ndo
, p
, length
);
240 fr_print(netdissect_options
*ndo
,
241 const u_char
*p
, u_int length
)
244 uint16_t extracted_ethertype
;
251 ndo
->ndo_protocol
= "fr";
252 ret
= parse_q922_header(ndo
, p
, &dlci
, &addr_len
, &flags
, length
);
256 ND_PRINT("Q.922, invalid address");
260 ND_TCHECK_1(p
+ addr_len
);
261 if (length
< addr_len
+ 1)
264 if (GET_U_1(p
+ addr_len
) != LLC_UI
&& dlci
!= 0) {
266 * Let's figure out if we have Cisco-style encapsulation,
267 * with an Ethernet type (Cisco HDLC type?) following the
270 if (!ND_TTEST_2(p
+ addr_len
) || length
< addr_len
+ 2) {
272 ND_PRINT("UI %02x! ", GET_U_1(p
+ addr_len
));
274 extracted_ethertype
= GET_BE_U_2(p
+ addr_len
);
277 fr_hdr_print(ndo
, length
, addr_len
, dlci
,
278 flags
, extracted_ethertype
);
280 if (ethertype_print(ndo
, extracted_ethertype
,
281 p
+addr_len
+ETHERTYPE_LEN
,
282 length
-addr_len
-ETHERTYPE_LEN
,
283 ND_BYTES_AVAILABLE_AFTER(p
)-addr_len
-ETHERTYPE_LEN
,
285 /* ether_type not known, probably it wasn't one */
286 ND_PRINT("UI %02x! ", GET_U_1(p
+ addr_len
));
292 ND_TCHECK_1(p
+ addr_len
+ 1);
293 if (length
< addr_len
+ 2)
296 if (GET_U_1(p
+ addr_len
+ 1) == 0) {
298 * Assume a pad byte after the control (UI) byte.
299 * A pad byte should only be used with 3-byte Q.922.
303 hdr_len
= addr_len
+ 1 /* UI */ + 1 /* pad */ + 1 /* NLPID */;
307 * A pad byte should be used with 3-byte Q.922.
310 ND_PRINT("No pad! ");
311 hdr_len
= addr_len
+ 1 /* UI */ + 1 /* NLPID */;
314 ND_TCHECK_1(p
+ hdr_len
- 1);
315 if (length
< hdr_len
)
317 nlpid
= GET_U_1(p
+ hdr_len
- 1);
320 fr_hdr_print(ndo
, length
, addr_len
, dlci
, flags
, nlpid
);
326 ip_print(ndo
, p
, length
);
330 ip6_print(ndo
, p
, length
);
336 isoclns_print(ndo
, p
- 1, length
+ 1); /* OSI printers need the NLPID field */
340 if (snap_print(ndo
, p
, length
, ND_BYTES_AVAILABLE_AFTER(p
), NULL
, NULL
, 0) == 0) {
341 /* ether_type not known, print raw packet */
343 fr_hdr_print(ndo
, length
+ hdr_len
, hdr_len
,
345 if (!ndo
->ndo_suppress_default_print
)
346 ND_DEFAULTPRINT(p
- hdr_len
, length
+ hdr_len
);
351 q933_print(ndo
, p
, length
);
355 frf15_print(ndo
, p
, length
);
359 ppp_print(ndo
, p
, length
);
364 fr_hdr_print(ndo
, length
+ hdr_len
, addr_len
,
367 ND_DEFAULTPRINT(p
, length
);
378 /* Multi Link Frame Relay (FRF.16) */
380 mfr_if_print(netdissect_options
*ndo
,
381 const struct pcap_pkthdr
*h
, const u_char
*p
)
383 u_int length
= h
->len
;
384 u_int caplen
= h
->caplen
;
386 ndo
->ndo_protocol
= "mfr";
387 if (caplen
< 2) { /* minimum frame header length */
389 ndo
->ndo_ll_hdr_len
+= caplen
;
393 ndo
->ndo_ll_hdr_len
+= mfr_print(ndo
, p
, length
);
397 #define MFR_CTRL_MSG_ADD_LINK 1
398 #define MFR_CTRL_MSG_ADD_LINK_ACK 2
399 #define MFR_CTRL_MSG_ADD_LINK_REJ 3
400 #define MFR_CTRL_MSG_HELLO 4
401 #define MFR_CTRL_MSG_HELLO_ACK 5
402 #define MFR_CTRL_MSG_REMOVE_LINK 6
403 #define MFR_CTRL_MSG_REMOVE_LINK_ACK 7
405 static const struct tok mfr_ctrl_msg_values
[] = {
406 { MFR_CTRL_MSG_ADD_LINK
, "Add Link" },
407 { MFR_CTRL_MSG_ADD_LINK_ACK
, "Add Link ACK" },
408 { MFR_CTRL_MSG_ADD_LINK_REJ
, "Add Link Reject" },
409 { MFR_CTRL_MSG_HELLO
, "Hello" },
410 { MFR_CTRL_MSG_HELLO_ACK
, "Hello ACK" },
411 { MFR_CTRL_MSG_REMOVE_LINK
, "Remove Link" },
412 { MFR_CTRL_MSG_REMOVE_LINK_ACK
, "Remove Link ACK" },
416 #define MFR_CTRL_IE_BUNDLE_ID 1
417 #define MFR_CTRL_IE_LINK_ID 2
418 #define MFR_CTRL_IE_MAGIC_NUM 3
419 #define MFR_CTRL_IE_TIMESTAMP 5
420 #define MFR_CTRL_IE_VENDOR_EXT 6
421 #define MFR_CTRL_IE_CAUSE 7
423 static const struct tok mfr_ctrl_ie_values
[] = {
424 { MFR_CTRL_IE_BUNDLE_ID
, "Bundle ID"},
425 { MFR_CTRL_IE_LINK_ID
, "Link ID"},
426 { MFR_CTRL_IE_MAGIC_NUM
, "Magic Number"},
427 { MFR_CTRL_IE_TIMESTAMP
, "Timestamp"},
428 { MFR_CTRL_IE_VENDOR_EXT
, "Vendor Extension"},
429 { MFR_CTRL_IE_CAUSE
, "Cause"},
433 #define MFR_ID_STRING_MAXLEN 50
435 struct ie_tlv_header_t
{
441 mfr_print(netdissect_options
*ndo
,
442 const u_char
*p
, u_int length
)
444 u_int tlen
,hdr_len
= 0;
445 uint16_t sequence_num
;
446 uint8_t ie_type
,ie_len
;
451 * FRF.16 Link Integrity Control Frame
454 * +----+----+----+----+----+----+----+----+
455 * | B | E | C=1| 0 0 0 0 | EA |
456 * +----+----+----+----+----+----+----+----+
457 * | 0 0 0 0 0 0 0 0 |
458 * +----+----+----+----+----+----+----+----+
460 * +----+----+----+----+----+----+----+----+
463 ndo
->ndo_protocol
= "mfr";
465 if (length
< 4) { /* minimum frame header length */
466 ND_PRINT("[length %u < 4]", length
);
467 nd_print_invalid(ndo
);
472 if ((GET_U_1(p
) & MFR_BEC_MASK
) == MFR_CTRL_FRAME
&& GET_U_1(p
+ 1) == 0) {
473 ND_PRINT("FRF.16 Control, Flags [%s], %s, length %u",
474 bittok2str(frf_flag_values
,"none",(GET_U_1(p
) & MFR_BEC_MASK
)),
475 tok2str(mfr_ctrl_msg_values
,"Unknown Message (0x%02x)",GET_U_1(p
+ 2)),
484 while (tlen
>sizeof(struct ie_tlv_header_t
)) {
485 ND_TCHECK_LEN(tptr
, sizeof(struct ie_tlv_header_t
));
486 ie_type
=GET_U_1(tptr
);
487 ie_len
=GET_U_1(tptr
+ 1);
489 ND_PRINT("\n\tIE %s (%u), length %u: ",
490 tok2str(mfr_ctrl_ie_values
,"Unknown",ie_type
),
494 /* infinite loop check */
495 if (ie_type
== 0 || ie_len
<= sizeof(struct ie_tlv_header_t
))
498 ND_TCHECK_LEN(tptr
, ie_len
);
499 tptr
+=sizeof(struct ie_tlv_header_t
);
500 /* tlv len includes header */
501 ie_len
-=sizeof(struct ie_tlv_header_t
);
502 tlen
-=sizeof(struct ie_tlv_header_t
);
506 case MFR_CTRL_IE_MAGIC_NUM
:
507 /* FRF.16.1 Section 3.4.3 Magic Number Information Element */
509 ND_PRINT("[IE data length %d != 4]", ie_len
);
510 nd_print_invalid(ndo
);
513 ND_PRINT("0x%08x", GET_BE_U_4(tptr
));
516 case MFR_CTRL_IE_BUNDLE_ID
: /* same message format */
517 case MFR_CTRL_IE_LINK_ID
:
518 nd_printjnp(ndo
, tptr
, ND_MIN(ie_len
, MFR_ID_STRING_MAXLEN
));
521 case MFR_CTRL_IE_TIMESTAMP
:
523 * FRF.16.1 Section 3.4.4 Timestamp Information Element
525 * The maximum length is 14 octets. Format is implementation
529 ND_PRINT("[Timestamp IE length %d > 14]", ie_len
);
530 nd_print_invalid(ndo
);
533 /* fall through and hexdump */
537 * FIXME those are the defined IEs that lack a decoder
538 * you are welcome to contribute code ;-)
541 case MFR_CTRL_IE_VENDOR_EXT
:
542 case MFR_CTRL_IE_CAUSE
:
545 if (ndo
->ndo_vflag
<= 1)
546 print_unknown_data(ndo
, tptr
, "\n\t ", ie_len
);
550 /* do we want to see a hexdump of the IE ? */
551 if (ndo
->ndo_vflag
> 1 )
552 print_unknown_data(ndo
, tptr
, "\n\t ", ie_len
);
560 * FRF.16 Fragmentation Frame
563 * +----+----+----+----+----+----+----+----+
564 * | B | E | C=0|seq. (high 4 bits) | EA |
565 * +----+----+----+----+----+----+----+----+
566 * | sequence (low 8 bits) |
567 * +----+----+----+----+----+----+----+----+
568 * | DLCI (6 bits) | CR | EA |
569 * +----+----+----+----+----+----+----+----+
570 * | DLCI (4 bits) |FECN|BECN| DE | EA |
571 * +----+----+----+----+----+----+----+----+
574 sequence_num
= (GET_U_1(p
)&0x1e)<<7 | GET_U_1(p
+ 1);
575 /* whole packet or first fragment ? */
576 if ((GET_U_1(p
) & MFR_BEC_MASK
) == MFR_FRAG_FRAME
||
577 (GET_U_1(p
) & MFR_BEC_MASK
) == MFR_B_BIT
) {
578 ND_PRINT("FRF.16 Frag, seq %u, Flags [%s], ",
580 bittok2str(frf_flag_values
,"none",(GET_U_1(p
) & MFR_BEC_MASK
)));
582 fr_print(ndo
, p
+hdr_len
,length
-hdr_len
);
586 /* must be a middle or the last fragment */
587 ND_PRINT("FRF.16 Frag, seq %u, Flags [%s]",
589 bittok2str(frf_flag_values
,"none",(GET_U_1(p
) & MFR_BEC_MASK
)));
590 print_unknown_data(ndo
, p
, "\n\t", length
);
599 /* an NLPID of 0xb1 indicates a 2-byte
603 * +----+----+----+----+----+----+----+----+
605 * +----+----+----+----+----+----+----+----+
606 * | NLPID (8 bits) | NLPID=0xb1
607 * +----+----+----+----+----+----+----+----+
608 * | B | E | C |seq. (high 4 bits) | R |
609 * +----+----+----+----+----+----+----+----+
610 * | sequence (low 8 bits) |
611 * +----+----+----+----+----+----+----+----+
614 #define FR_FRF15_FRAGTYPE 0x01
617 frf15_print(netdissect_options
*ndo
,
618 const u_char
*p
, u_int length
)
620 uint16_t sequence_num
, flags
;
625 flags
= GET_U_1(p
)&MFR_BEC_MASK
;
626 sequence_num
= (GET_U_1(p
)&0x1e)<<7 | GET_U_1(p
+ 1);
628 ND_PRINT("FRF.15, seq 0x%03x, Flags [%s],%s Fragmentation, length %u",
630 bittok2str(frf_flag_values
,"none",flags
),
631 GET_U_1(p
)&FR_FRF15_FRAGTYPE
? "Interface" : "End-to-End",
635 * depending on all permutations of the B, E and C bit
636 * dig as deep as we can - e.g. on the first (B) fragment
637 * there is enough payload to print the IP header
638 * on non (B) fragments it depends if the fragmentation
639 * model is end-to-end or interface based whether we want to print
640 * another Q.922 header
649 * Q.933 decoding portion for framerelay specific.
652 /* Q.933 packet format
653 Format of Other Protocols
655 +-------------------------------+
657 +---------------+---------------+
658 |Control 0x03 | NLPID 0x08 |
659 +---------------+---------------+
661 | octet 1 | octet 2 |
662 +-------------------------------+
664 | octet 2 | octet 2 |
665 +-------------------------------+
667 +-------------------------------+
669 +-------------------------------+
672 /* L2 (Octet 1)- Call Reference Usually is 0x0 */
675 * L2 (Octet 2)- Message Types definition 1 byte long.
678 #define MSG_TYPE_ESC_TO_NATIONAL 0x00
679 #define MSG_TYPE_ALERT 0x01
680 #define MSG_TYPE_CALL_PROCEEDING 0x02
681 #define MSG_TYPE_CONNECT 0x07
682 #define MSG_TYPE_CONNECT_ACK 0x0F
683 #define MSG_TYPE_PROGRESS 0x03
684 #define MSG_TYPE_SETUP 0x05
686 #define MSG_TYPE_DISCONNECT 0x45
687 #define MSG_TYPE_RELEASE 0x4D
688 #define MSG_TYPE_RELEASE_COMPLETE 0x5A
689 #define MSG_TYPE_RESTART 0x46
690 #define MSG_TYPE_RESTART_ACK 0x4E
692 #define MSG_TYPE_STATUS 0x7D
693 #define MSG_TYPE_STATUS_ENQ 0x75
695 static const struct tok fr_q933_msg_values
[] = {
696 { MSG_TYPE_ESC_TO_NATIONAL
, "ESC to National" },
697 { MSG_TYPE_ALERT
, "Alert" },
698 { MSG_TYPE_CALL_PROCEEDING
, "Call proceeding" },
699 { MSG_TYPE_CONNECT
, "Connect" },
700 { MSG_TYPE_CONNECT_ACK
, "Connect ACK" },
701 { MSG_TYPE_PROGRESS
, "Progress" },
702 { MSG_TYPE_SETUP
, "Setup" },
703 { MSG_TYPE_DISCONNECT
, "Disconnect" },
704 { MSG_TYPE_RELEASE
, "Release" },
705 { MSG_TYPE_RELEASE_COMPLETE
, "Release Complete" },
706 { MSG_TYPE_RESTART
, "Restart" },
707 { MSG_TYPE_RESTART_ACK
, "Restart ACK" },
708 { MSG_TYPE_STATUS
, "Status Reply" },
709 { MSG_TYPE_STATUS_ENQ
, "Status Enquiry" },
713 #define IE_IS_SINGLE_OCTET(iecode) ((iecode) & 0x80)
714 #define IE_IS_SHIFT(iecode) (((iecode) & 0xF0) == 0x90)
715 #define IE_SHIFT_IS_NON_LOCKING(iecode) ((iecode) & 0x08)
716 #define IE_SHIFT_IS_LOCKING(iecode) (!(IE_SHIFT_IS_NON_LOCKING(iecode)))
717 #define IE_SHIFT_CODESET(iecode) ((iecode) & 0x07)
719 #define FR_LMI_ANSI_REPORT_TYPE_IE 0x01
720 #define FR_LMI_ANSI_LINK_VERIFY_IE_91 0x19 /* details? */
721 #define FR_LMI_ANSI_LINK_VERIFY_IE 0x03
722 #define FR_LMI_ANSI_PVC_STATUS_IE 0x07
724 #define FR_LMI_CCITT_REPORT_TYPE_IE 0x51
725 #define FR_LMI_CCITT_LINK_VERIFY_IE 0x53
726 #define FR_LMI_CCITT_PVC_STATUS_IE 0x57
728 static const struct tok fr_q933_ie_values_codeset_0_5
[] = {
729 { FR_LMI_ANSI_REPORT_TYPE_IE
, "ANSI Report Type" },
730 { FR_LMI_ANSI_LINK_VERIFY_IE_91
, "ANSI Link Verify" },
731 { FR_LMI_ANSI_LINK_VERIFY_IE
, "ANSI Link Verify" },
732 { FR_LMI_ANSI_PVC_STATUS_IE
, "ANSI PVC Status" },
733 { FR_LMI_CCITT_REPORT_TYPE_IE
, "CCITT Report Type" },
734 { FR_LMI_CCITT_LINK_VERIFY_IE
, "CCITT Link Verify" },
735 { FR_LMI_CCITT_PVC_STATUS_IE
, "CCITT PVC Status" },
739 #define FR_LMI_REPORT_TYPE_IE_FULL_STATUS 0
740 #define FR_LMI_REPORT_TYPE_IE_LINK_VERIFY 1
741 #define FR_LMI_REPORT_TYPE_IE_ASYNC_PVC 2
743 static const struct tok fr_lmi_report_type_ie_values
[] = {
744 { FR_LMI_REPORT_TYPE_IE_FULL_STATUS
, "Full Status" },
745 { FR_LMI_REPORT_TYPE_IE_LINK_VERIFY
, "Link verify" },
746 { FR_LMI_REPORT_TYPE_IE_ASYNC_PVC
, "Async PVC Status" },
750 /* array of 16 codesets - currently we only support codepage 0 and 5 */
751 static const struct tok
*fr_q933_ie_codesets
[] = {
752 fr_q933_ie_values_codeset_0_5
,
757 fr_q933_ie_values_codeset_0_5
,
770 static int fr_q933_print_ie_codeset_0_5(netdissect_options
*ndo
, u_int iecode
,
771 u_int ielength
, const u_char
*p
);
773 typedef int (*codeset_pr_func_t
)(netdissect_options
*, u_int iecode
,
774 u_int ielength
, const u_char
*p
);
776 /* array of 16 codesets - currently we only support codepage 0 and 5 */
777 static const codeset_pr_func_t fr_q933_print_ie_codeset
[] = {
778 fr_q933_print_ie_codeset_0_5
,
783 fr_q933_print_ie_codeset_0_5
,
799 * p points to octet 2, the octet containing the length of the
800 * call reference value, so p[n] is octet n+2 ("octet X" is as
801 * used in Q.931/Q.933).
803 * XXX - actually used both for Q.931 and Q.933.
806 q933_print(netdissect_options
*ndo
,
807 const u_char
*p
, u_int length
)
810 u_int call_ref_length
, i
;
811 uint8_t call_ref
[15]; /* maximum length - length field is 4 bits */
818 u_int non_locking_shift
;
819 u_int unshift_codeset
;
821 ndo
->ndo_protocol
= "q.933";
822 ND_PRINT("%s", ndo
->ndo_eflag
? "" : "Q.933");
824 if (length
== 0 || !ND_TTEST_1(p
)) {
827 ND_PRINT("length %u", length
);
832 * Get the length of the call reference value.
834 olen
= length
; /* preserve the original length for display */
835 call_ref_length
= GET_U_1(p
) & 0x0f;
840 * Get the call reference value.
842 for (i
= 0; i
< call_ref_length
; i
++) {
843 if (length
== 0 || !ND_TTEST_1(p
)) {
846 ND_PRINT("length %u", olen
);
849 call_ref
[i
] = GET_U_1(p
);
855 * Get the message type.
857 if (length
== 0 || !ND_TTEST_1(p
)) {
860 ND_PRINT("length %u", olen
);
863 msgtype
= GET_U_1(p
);
868 * Peek ahead to see if we start with a shift.
870 non_locking_shift
= 0;
871 unshift_codeset
= codeset
;
873 if (!ND_TTEST_1(p
)) {
876 ND_PRINT("length %u", olen
);
880 if (IE_IS_SHIFT(iecode
)) {
882 * It's a shift. Skip over it.
890 codeset
= IE_SHIFT_CODESET(iecode
);
893 * If it's a locking shift to codeset 5,
894 * mark this as ANSI. (XXX - 5 is actually
895 * for national variants in general, not
896 * the US variant in particular, but maybe
897 * this is more American exceptionalism. :-))
899 if (IE_SHIFT_IS_LOCKING(iecode
)) {
901 * It's a locking shift.
905 * It's a locking shift to
906 * codeset 5, so this is
913 * It's a non-locking shift.
914 * Remember the current codeset, so we
915 * can revert to it after the next IE.
917 non_locking_shift
= 1;
923 /* printing out header part */
926 ND_PRINT("%s, codeset %u", is_ansi
? "ANSI" : "CCITT", codeset
);
928 if (call_ref_length
!= 0) {
929 if (call_ref_length
> 1 || GET_U_1(p
) != 0) {
931 * Not a dummy call reference.
933 ND_PRINT(", Call Ref: 0x");
934 for (i
= 0; i
< call_ref_length
; i
++)
935 ND_PRINT("%02x", call_ref
[i
]);
938 if (ndo
->ndo_vflag
) {
939 ND_PRINT(", %s (0x%02x), length %u",
940 tok2str(fr_q933_msg_values
,
941 "unknown message", msgtype
),
946 tok2str(fr_q933_msg_values
,
947 "unknown message 0x%02x", msgtype
));
950 /* Loop through the rest of the IEs */
951 while (length
!= 0) {
953 * What's the state of any non-locking shifts?
955 if (non_locking_shift
== 1) {
957 * There's a non-locking shift in effect for
958 * this IE. Count it, so we reset the codeset
959 * before the next IE.
961 non_locking_shift
= 2;
962 } else if (non_locking_shift
== 2) {
966 codeset
= unshift_codeset
;
967 non_locking_shift
= 0;
971 * Get the first octet of the IE.
973 if (!ND_TTEST_1(p
)) {
974 if (!ndo
->ndo_vflag
) {
975 ND_PRINT(", length %u", olen
);
983 /* Single-octet IE? */
984 if (IE_IS_SINGLE_OCTET(iecode
)) {
986 * Yes. Is it a shift?
988 if (IE_IS_SHIFT(iecode
)) {
990 * Yes. Is it locking?
992 if (IE_SHIFT_IS_LOCKING(iecode
)) {
996 non_locking_shift
= 0;
999 * No. Remember the current
1000 * codeset, so we can revert
1001 * to it after the next IE.
1003 non_locking_shift
= 1;
1004 unshift_codeset
= codeset
;
1010 codeset
= IE_SHIFT_CODESET(iecode
);
1014 * No. Get the IE length.
1016 if (length
== 0 || !ND_TTEST_1(p
)) {
1017 if (!ndo
->ndo_vflag
) {
1018 ND_PRINT(", length %u", olen
);
1022 ielength
= GET_U_1(p
);
1026 /* lets do the full IE parsing only in verbose mode
1027 * however some IEs (DLCI Status, Link Verify)
1028 * are also interesting in non-verbose mode */
1029 if (ndo
->ndo_vflag
) {
1030 ND_PRINT("\n\t%s IE (0x%02x), length %u: ",
1031 tok2str(fr_q933_ie_codesets
[codeset
],
1038 if (iecode
== 0 || ielength
== 0) {
1041 if (length
< ielength
|| !ND_TTEST_LEN(p
, ielength
)) {
1042 if (!ndo
->ndo_vflag
) {
1043 ND_PRINT(", length %u", olen
);
1049 if (fr_q933_print_ie_codeset
[codeset
] != NULL
) {
1050 ie_is_known
= fr_q933_print_ie_codeset
[codeset
](ndo
, iecode
, ielength
, p
);
1055 * Known IE; do we want to see a hexdump
1058 if (ndo
->ndo_vflag
> 1) {
1060 print_unknown_data(ndo
, p
, "\n\t ", ielength
);
1064 * Unknown IE; if we're printing verbosely,
1065 * print its content in hex.
1067 if (ndo
->ndo_vflag
>= 1) {
1068 print_unknown_data(ndo
, p
, "\n\t", ielength
);
1076 if (!ndo
->ndo_vflag
) {
1077 ND_PRINT(", length %u", olen
);
1082 nd_print_trunc(ndo
);
1086 fr_q933_print_ie_codeset_0_5(netdissect_options
*ndo
, u_int iecode
,
1087 u_int ielength
, const u_char
*p
)
1093 case FR_LMI_ANSI_REPORT_TYPE_IE
: /* fall through */
1094 case FR_LMI_CCITT_REPORT_TYPE_IE
:
1096 if (!ndo
->ndo_vflag
) {
1099 ND_PRINT("Invalid REPORT TYPE IE");
1102 if (ndo
->ndo_vflag
) {
1104 tok2str(fr_lmi_report_type_ie_values
,"unknown",GET_U_1(p
)),
1109 case FR_LMI_ANSI_LINK_VERIFY_IE
: /* fall through */
1110 case FR_LMI_CCITT_LINK_VERIFY_IE
:
1111 case FR_LMI_ANSI_LINK_VERIFY_IE_91
:
1112 if (!ndo
->ndo_vflag
) {
1116 ND_PRINT("Invalid LINK VERIFY IE");
1119 ND_PRINT("TX Seq: %3d, RX Seq: %3d", GET_U_1(p
), GET_U_1(p
+ 1));
1122 case FR_LMI_ANSI_PVC_STATUS_IE
: /* fall through */
1123 case FR_LMI_CCITT_PVC_STATUS_IE
:
1124 if (!ndo
->ndo_vflag
) {
1127 /* now parse the DLCI information element. */
1128 if ((ielength
< 3) ||
1129 (GET_U_1(p
) & 0x80) ||
1130 ((ielength
== 3) && !(GET_U_1(p
+ 1) & 0x80)) ||
1132 ((GET_U_1(p
+ 1) & 0x80) || !(GET_U_1(p
+ 2) & 0x80))) ||
1134 ((GET_U_1(p
+ 1) & 0x80) || (GET_U_1(p
+ 2) & 0x80) ||
1135 !(GET_U_1(p
+ 3) & 0x80))) ||
1137 !(GET_U_1(p
+ ielength
- 1) & 0x80)) {
1138 ND_PRINT("Invalid DLCI in PVC STATUS IE");
1142 dlci
= ((GET_U_1(p
) & 0x3F) << 4) | ((GET_U_1(p
+ 1) & 0x78) >> 3);
1143 if (ielength
== 4) {
1144 dlci
= (dlci
<< 6) | ((GET_U_1(p
+ 2) & 0x7E) >> 1);
1145 } else if (ielength
== 5) {
1146 dlci
= (dlci
<< 13) | (GET_U_1(p
+ 2) & 0x7F) | ((GET_U_1(p
+ 3) & 0x7E) >> 1);
1149 ND_PRINT("DLCI %u: status %s%s", dlci
,
1150 GET_U_1(p
+ ielength
- 1) & 0x8 ? "New, " : "",
1151 GET_U_1(p
+ ielength
- 1) & 0x2 ? "Active" : "Inactive");