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 */
28 #include "netdissect-stdinc.h"
33 #include "netdissect.h"
34 #include "addrtoname.h"
35 #include "ethertype.h"
40 static void frf15_print(netdissect_options
*ndo
, const u_char
*, u_int
);
43 * the frame relay header has a variable length
45 * the EA bit determines if there is another byte
48 * minimum header length is 2 bytes
49 * maximum header length is 4 bytes
52 * +----+----+----+----+----+----+----+----+
53 * | DLCI (6 bits) | CR | EA |
54 * +----+----+----+----+----+----+----+----+
55 * | DLCI (4 bits) |FECN|BECN| DE | EA |
56 * +----+----+----+----+----+----+----+----+
57 * | DLCI (7 bits) | EA |
58 * +----+----+----+----+----+----+----+----+
59 * | DLCI (6 bits) |SDLC| EA |
60 * +----+----+----+----+----+----+----+----+
63 #define FR_EA_BIT 0x01
65 #define FR_CR_BIT 0x02000000
66 #define FR_DE_BIT 0x00020000
67 #define FR_BECN_BIT 0x00040000
68 #define FR_FECN_BIT 0x00080000
69 #define FR_SDLC_BIT 0x00000002
72 static const struct tok fr_header_flag_values
[] = {
75 { FR_BECN_BIT
, "BECN" },
76 { FR_FECN_BIT
, "FECN" },
77 { FR_SDLC_BIT
, "sdlcore" },
82 #define MFR_B_BIT 0x80
83 #define MFR_E_BIT 0x40
84 #define MFR_C_BIT 0x20
85 #define MFR_BEC_MASK (MFR_B_BIT | MFR_E_BIT | MFR_C_BIT)
86 #define MFR_CTRL_FRAME (MFR_B_BIT | MFR_E_BIT | MFR_C_BIT)
87 #define MFR_FRAG_FRAME (MFR_B_BIT | MFR_E_BIT )
89 static const struct tok frf_flag_values
[] = {
90 { MFR_B_BIT
, "Begin" },
92 { MFR_C_BIT
, "Control" },
96 /* Finds out Q.922 address length, DLCI and flags. Returns 1 on success,
97 * 0 on invalid address, -1 on truncated packet
98 * save the flags dep. on address length
100 static int parse_q922_header(netdissect_options
*ndo
,
101 const u_char
*p
, u_int
*dlci
,
102 u_int
*addr_len
, uint32_t *flags
, u_int length
)
104 if (!ND_TTEST_1(p
) || length
< 1)
106 if ((GET_U_1(p
) & FR_EA_BIT
))
109 if (!ND_TTEST_1(p
+ 1) || length
< 2)
112 *dlci
= ((GET_U_1(p
) & 0xFC) << 2) | ((GET_U_1(p
+ 1) & 0xF0) >> 4);
114 *flags
= ((GET_U_1(p
) & 0x02) << 24) | /* CR flag */
115 ((GET_U_1(p
+ 1) & 0x0e) << 16); /* FECN,BECN,DE flags */
117 if (GET_U_1(p
+ 1) & FR_EA_BIT
)
118 return 1; /* 2-byte Q.922 address */
122 if (!ND_TTEST_1(p
) || length
< 1)
124 (*addr_len
)++; /* 3- or 4-byte Q.922 address */
125 if ((GET_U_1(p
) & FR_EA_BIT
) == 0) {
126 *dlci
= (*dlci
<< 7) | (GET_U_1(p
) >> 1);
127 (*addr_len
)++; /* 4-byte Q.922 address */
132 if (!ND_TTEST_1(p
) || length
< 1)
134 if ((GET_U_1(p
) & FR_EA_BIT
) == 0)
135 return 0; /* more than 4 bytes of Q.922 address? */
137 *flags
= *flags
| (GET_U_1(p
) & 0x02); /* SDLC flag */
139 *dlci
= (*dlci
<< 6) | (GET_U_1(p
) >> 2);
145 q922_string(netdissect_options
*ndo
, const u_char
*p
, u_int length
)
148 static u_int dlci
, addr_len
;
149 static uint32_t flags
;
150 static char buffer
[sizeof("DLCI xxxxxxxxxx")];
151 memset(buffer
, 0, sizeof(buffer
));
153 if (parse_q922_header(ndo
, p
, &dlci
, &addr_len
, &flags
, length
) == 1){
154 snprintf(buffer
, sizeof(buffer
), "DLCI %u", dlci
);
161 /* Frame Relay packet structure, with flags and CRC removed
163 +---------------------------+
167 +---------------------------+
168 | Control (UI = 0x03) |
169 +---------------------------+
170 | Optional Pad (0x00) |
171 +---------------------------+
173 +---------------------------+
180 +---------------------------+
182 * Q.922 addresses, as presently defined, are two octets and
183 contain a 10-bit DLCI. In some networks Q.922 addresses
184 may optionally be increased to three or four octets.
188 fr_hdr_print(netdissect_options
*ndo
, int length
, u_int addr_len
,
189 u_int dlci
, uint32_t flags
, uint16_t nlpid
)
191 if (ndo
->ndo_qflag
) {
192 ND_PRINT("Q.922, DLCI %u, length %u: ",
196 if (nlpid
<= 0xff) /* if its smaller than 256 then its a NLPID */
197 ND_PRINT("Q.922, hdr-len %u, DLCI %u, Flags [%s], NLPID %s (0x%02x), length %u: ",
200 bittok2str(fr_header_flag_values
, "none", flags
),
201 tok2str(nlpid_values
,"unknown", nlpid
),
204 else /* must be an ethertype */
205 ND_PRINT("Q.922, hdr-len %u, DLCI %u, Flags [%s], cisco-ethertype %s (0x%04x), length %u: ",
208 bittok2str(fr_header_flag_values
, "none", flags
),
209 tok2str(ethertype_values
, "unknown", nlpid
),
217 fr_if_print(netdissect_options
*ndo
,
218 const struct pcap_pkthdr
*h
, const u_char
*p
)
220 u_int length
= h
->len
;
221 u_int caplen
= h
->caplen
;
223 ndo
->ndo_protocol
= "fr";
224 if (caplen
< 4) { /* minimum frame header length */
226 ndo
->ndo_ll_hdr_len
+= caplen
;
230 ndo
->ndo_ll_hdr_len
+= fr_print(ndo
, p
, length
);
234 fr_print(netdissect_options
*ndo
,
235 const u_char
*p
, u_int length
)
238 uint16_t extracted_ethertype
;
245 ndo
->ndo_protocol
= "fr";
246 ret
= parse_q922_header(ndo
, p
, &dlci
, &addr_len
, &flags
, length
);
250 ND_PRINT("Q.922, invalid address");
254 ND_TCHECK_1(p
+ addr_len
);
255 if (length
< addr_len
+ 1)
258 if (GET_U_1(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_TTEST_2(p
+ addr_len
) || length
< addr_len
+ 2) {
266 ND_PRINT("UI %02x! ", GET_U_1(p
+ addr_len
));
268 extracted_ethertype
= GET_BE_U_2(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 ND_BYTES_AVAILABLE_AFTER(p
)-addr_len
-ETHERTYPE_LEN
,
279 /* ether_type not known, probably it wasn't one */
280 ND_PRINT("UI %02x! ", GET_U_1(p
+ addr_len
));
286 ND_TCHECK_1(p
+ addr_len
+ 1);
287 if (length
< addr_len
+ 2)
290 if (GET_U_1(p
+ addr_len
+ 1) == 0) {
292 * Assume a pad byte after the control (UI) byte.
293 * A pad byte should only be used with 3-byte Q.922.
297 hdr_len
= addr_len
+ 1 /* UI */ + 1 /* pad */ + 1 /* NLPID */;
301 * A pad byte should be used with 3-byte Q.922.
304 ND_PRINT("No pad! ");
305 hdr_len
= addr_len
+ 1 /* UI */ + 1 /* NLPID */;
308 ND_TCHECK_1(p
+ hdr_len
- 1);
309 if (length
< hdr_len
)
311 nlpid
= GET_U_1(p
+ hdr_len
- 1);
314 fr_hdr_print(ndo
, length
, addr_len
, dlci
, flags
, nlpid
);
320 ip_print(ndo
, p
, length
);
324 ip6_print(ndo
, p
, length
);
330 isoclns_print(ndo
, p
- 1, length
+ 1); /* OSI printers need the NLPID field */
334 if (snap_print(ndo
, p
, length
, ND_BYTES_AVAILABLE_AFTER(p
), NULL
, NULL
, 0) == 0) {
335 /* ether_type not known, print raw packet */
337 fr_hdr_print(ndo
, length
+ hdr_len
, hdr_len
,
339 if (!ndo
->ndo_suppress_default_print
)
340 ND_DEFAULTPRINT(p
- hdr_len
, length
+ hdr_len
);
345 q933_print(ndo
, p
, length
);
349 frf15_print(ndo
, p
, length
);
353 ppp_print(ndo
, p
, length
);
358 fr_hdr_print(ndo
, length
+ hdr_len
, addr_len
,
361 ND_DEFAULTPRINT(p
, length
);
372 /* Multi Link Frame Relay (FRF.16) */
374 mfr_if_print(netdissect_options
*ndo
,
375 const struct pcap_pkthdr
*h
, const u_char
*p
)
377 u_int length
= h
->len
;
378 u_int caplen
= h
->caplen
;
380 ndo
->ndo_protocol
= "mfr";
381 if (caplen
< 2) { /* minimum frame header length */
383 ndo
->ndo_ll_hdr_len
+= caplen
;
387 ndo
->ndo_ll_hdr_len
+= mfr_print(ndo
, p
, length
);
391 #define MFR_CTRL_MSG_ADD_LINK 1
392 #define MFR_CTRL_MSG_ADD_LINK_ACK 2
393 #define MFR_CTRL_MSG_ADD_LINK_REJ 3
394 #define MFR_CTRL_MSG_HELLO 4
395 #define MFR_CTRL_MSG_HELLO_ACK 5
396 #define MFR_CTRL_MSG_REMOVE_LINK 6
397 #define MFR_CTRL_MSG_REMOVE_LINK_ACK 7
399 static const struct tok mfr_ctrl_msg_values
[] = {
400 { MFR_CTRL_MSG_ADD_LINK
, "Add Link" },
401 { MFR_CTRL_MSG_ADD_LINK_ACK
, "Add Link ACK" },
402 { MFR_CTRL_MSG_ADD_LINK_REJ
, "Add Link Reject" },
403 { MFR_CTRL_MSG_HELLO
, "Hello" },
404 { MFR_CTRL_MSG_HELLO_ACK
, "Hello ACK" },
405 { MFR_CTRL_MSG_REMOVE_LINK
, "Remove Link" },
406 { MFR_CTRL_MSG_REMOVE_LINK_ACK
, "Remove Link ACK" },
410 #define MFR_CTRL_IE_BUNDLE_ID 1
411 #define MFR_CTRL_IE_LINK_ID 2
412 #define MFR_CTRL_IE_MAGIC_NUM 3
413 #define MFR_CTRL_IE_TIMESTAMP 5
414 #define MFR_CTRL_IE_VENDOR_EXT 6
415 #define MFR_CTRL_IE_CAUSE 7
417 static const struct tok mfr_ctrl_ie_values
[] = {
418 { MFR_CTRL_IE_BUNDLE_ID
, "Bundle ID"},
419 { MFR_CTRL_IE_LINK_ID
, "Link ID"},
420 { MFR_CTRL_IE_MAGIC_NUM
, "Magic Number"},
421 { MFR_CTRL_IE_TIMESTAMP
, "Timestamp"},
422 { MFR_CTRL_IE_VENDOR_EXT
, "Vendor Extension"},
423 { MFR_CTRL_IE_CAUSE
, "Cause"},
427 #define MFR_ID_STRING_MAXLEN 50
429 struct ie_tlv_header_t
{
435 mfr_print(netdissect_options
*ndo
,
436 const u_char
*p
, u_int length
)
438 u_int tlen
,idx
,hdr_len
= 0;
439 uint16_t sequence_num
;
440 uint8_t ie_type
,ie_len
;
445 * FRF.16 Link Integrity Control Frame
448 * +----+----+----+----+----+----+----+----+
449 * | B | E | C=1| 0 0 0 0 | EA |
450 * +----+----+----+----+----+----+----+----+
451 * | 0 0 0 0 0 0 0 0 |
452 * +----+----+----+----+----+----+----+----+
454 * +----+----+----+----+----+----+----+----+
457 ndo
->ndo_protocol
= "mfr";
459 if (length
< 4) { /* minimum frame header length */
460 ND_PRINT("[length %u < 4]", length
);
461 nd_print_invalid(ndo
);
466 if ((GET_U_1(p
) & MFR_BEC_MASK
) == MFR_CTRL_FRAME
&& GET_U_1(p
+ 1) == 0) {
467 ND_PRINT("FRF.16 Control, Flags [%s], %s, length %u",
468 bittok2str(frf_flag_values
,"none",(GET_U_1(p
) & MFR_BEC_MASK
)),
469 tok2str(mfr_ctrl_msg_values
,"Unknown Message (0x%02x)",GET_U_1(p
+ 2)),
478 while (tlen
>sizeof(struct ie_tlv_header_t
)) {
479 ND_TCHECK_LEN(tptr
, sizeof(struct ie_tlv_header_t
));
480 ie_type
=GET_U_1(tptr
);
481 ie_len
=GET_U_1(tptr
+ 1);
483 ND_PRINT("\n\tIE %s (%u), length %u: ",
484 tok2str(mfr_ctrl_ie_values
,"Unknown",ie_type
),
488 /* infinite loop check */
489 if (ie_type
== 0 || ie_len
<= sizeof(struct ie_tlv_header_t
))
492 ND_TCHECK_LEN(tptr
, ie_len
);
493 tptr
+=sizeof(struct ie_tlv_header_t
);
494 /* tlv len includes header */
495 ie_len
-=sizeof(struct ie_tlv_header_t
);
496 tlen
-=sizeof(struct ie_tlv_header_t
);
500 case MFR_CTRL_IE_MAGIC_NUM
:
501 /* FRF.16.1 Section 3.4.3 Magic Number Information Element */
503 ND_PRINT("[IE data length %d != 4]", ie_len
);
504 nd_print_invalid(ndo
);
507 ND_PRINT("0x%08x", GET_BE_U_4(tptr
));
510 case MFR_CTRL_IE_BUNDLE_ID
: /* same message format */
511 case MFR_CTRL_IE_LINK_ID
:
512 for (idx
= 0; idx
< ie_len
&& idx
< MFR_ID_STRING_MAXLEN
; idx
++) {
513 if (GET_U_1(tptr
+ idx
) != 0) /* don't print null termination */
514 fn_print_char(ndo
, GET_U_1(tptr
+ idx
));
520 case MFR_CTRL_IE_TIMESTAMP
:
521 if (ie_len
== sizeof(struct timeval
)) {
522 ts_print(ndo
, (const struct timeval
*)tptr
);
525 /* fall through and hexdump if no unix timestamp */
529 * FIXME those are the defined IEs that lack a decoder
530 * you are welcome to contribute code ;-)
533 case MFR_CTRL_IE_VENDOR_EXT
:
534 case MFR_CTRL_IE_CAUSE
:
537 if (ndo
->ndo_vflag
<= 1)
538 print_unknown_data(ndo
, tptr
, "\n\t ", ie_len
);
542 /* do we want to see a hexdump of the IE ? */
543 if (ndo
->ndo_vflag
> 1 )
544 print_unknown_data(ndo
, tptr
, "\n\t ", ie_len
);
552 * FRF.16 Fragmentation Frame
555 * +----+----+----+----+----+----+----+----+
556 * | B | E | C=0|seq. (high 4 bits) | EA |
557 * +----+----+----+----+----+----+----+----+
558 * | sequence (low 8 bits) |
559 * +----+----+----+----+----+----+----+----+
560 * | DLCI (6 bits) | CR | EA |
561 * +----+----+----+----+----+----+----+----+
562 * | DLCI (4 bits) |FECN|BECN| DE | EA |
563 * +----+----+----+----+----+----+----+----+
566 sequence_num
= (GET_U_1(p
)&0x1e)<<7 | GET_U_1(p
+ 1);
567 /* whole packet or first fragment ? */
568 if ((GET_U_1(p
) & MFR_BEC_MASK
) == MFR_FRAG_FRAME
||
569 (GET_U_1(p
) & MFR_BEC_MASK
) == MFR_B_BIT
) {
570 ND_PRINT("FRF.16 Frag, seq %u, Flags [%s], ",
572 bittok2str(frf_flag_values
,"none",(GET_U_1(p
) & MFR_BEC_MASK
)));
574 fr_print(ndo
, p
+hdr_len
,length
-hdr_len
);
578 /* must be a middle or the last fragment */
579 ND_PRINT("FRF.16 Frag, seq %u, Flags [%s]",
581 bittok2str(frf_flag_values
,"none",(GET_U_1(p
) & MFR_BEC_MASK
)));
582 print_unknown_data(ndo
, p
, "\n\t", length
);
591 /* an NLPID of 0xb1 indicates a 2-byte
595 * +----+----+----+----+----+----+----+----+
597 * +----+----+----+----+----+----+----+----+
598 * | NLPID (8 bits) | NLPID=0xb1
599 * +----+----+----+----+----+----+----+----+
600 * | B | E | C |seq. (high 4 bits) | R |
601 * +----+----+----+----+----+----+----+----+
602 * | sequence (low 8 bits) |
603 * +----+----+----+----+----+----+----+----+
606 #define FR_FRF15_FRAGTYPE 0x01
609 frf15_print(netdissect_options
*ndo
,
610 const u_char
*p
, u_int length
)
612 uint16_t sequence_num
, flags
;
617 flags
= GET_U_1(p
)&MFR_BEC_MASK
;
618 sequence_num
= (GET_U_1(p
)&0x1e)<<7 | GET_U_1(p
+ 1);
620 ND_PRINT("FRF.15, seq 0x%03x, Flags [%s],%s Fragmentation, length %u",
622 bittok2str(frf_flag_values
,"none",flags
),
623 GET_U_1(p
)&FR_FRF15_FRAGTYPE
? "Interface" : "End-to-End",
627 * depending on all permutations of the B, E and C bit
628 * dig as deep as we can - e.g. on the first (B) fragment
629 * there is enough payload to print the IP header
630 * on non (B) fragments it depends if the fragmentation
631 * model is end-to-end or interface based whether we want to print
632 * another Q.922 header
641 * Q.933 decoding portion for framerelay specific.
644 /* Q.933 packet format
645 Format of Other Protocols
647 +-------------------------------+
649 +---------------+---------------+
650 |Control 0x03 | NLPID 0x08 |
651 +---------------+---------------+
653 | octet 1 | octet 2 |
654 +-------------------------------+
656 | octet 2 | octet 2 |
657 +-------------------------------+
659 +-------------------------------+
661 +-------------------------------+
664 /* L2 (Octet 1)- Call Reference Usually is 0x0 */
667 * L2 (Octet 2)- Message Types definition 1 byte long.
670 #define MSG_TYPE_ESC_TO_NATIONAL 0x00
671 #define MSG_TYPE_ALERT 0x01
672 #define MSG_TYPE_CALL_PROCEEDING 0x02
673 #define MSG_TYPE_CONNECT 0x07
674 #define MSG_TYPE_CONNECT_ACK 0x0F
675 #define MSG_TYPE_PROGRESS 0x03
676 #define MSG_TYPE_SETUP 0x05
678 #define MSG_TYPE_DISCONNECT 0x45
679 #define MSG_TYPE_RELEASE 0x4D
680 #define MSG_TYPE_RELEASE_COMPLETE 0x5A
681 #define MSG_TYPE_RESTART 0x46
682 #define MSG_TYPE_RESTART_ACK 0x4E
684 #define MSG_TYPE_STATUS 0x7D
685 #define MSG_TYPE_STATUS_ENQ 0x75
687 static const struct tok fr_q933_msg_values
[] = {
688 { MSG_TYPE_ESC_TO_NATIONAL
, "ESC to National" },
689 { MSG_TYPE_ALERT
, "Alert" },
690 { MSG_TYPE_CALL_PROCEEDING
, "Call proceeding" },
691 { MSG_TYPE_CONNECT
, "Connect" },
692 { MSG_TYPE_CONNECT_ACK
, "Connect ACK" },
693 { MSG_TYPE_PROGRESS
, "Progress" },
694 { MSG_TYPE_SETUP
, "Setup" },
695 { MSG_TYPE_DISCONNECT
, "Disconnect" },
696 { MSG_TYPE_RELEASE
, "Release" },
697 { MSG_TYPE_RELEASE_COMPLETE
, "Release Complete" },
698 { MSG_TYPE_RESTART
, "Restart" },
699 { MSG_TYPE_RESTART_ACK
, "Restart ACK" },
700 { MSG_TYPE_STATUS
, "Status Reply" },
701 { MSG_TYPE_STATUS_ENQ
, "Status Enquiry" },
705 #define IE_IS_SINGLE_OCTET(iecode) ((iecode) & 0x80)
706 #define IE_IS_SHIFT(iecode) (((iecode) & 0xF0) == 0x90)
707 #define IE_SHIFT_IS_NON_LOCKING(iecode) ((iecode) & 0x08)
708 #define IE_SHIFT_IS_LOCKING(iecode) (!(IE_SHIFT_IS_NON_LOCKING(iecode)))
709 #define IE_SHIFT_CODESET(iecode) ((iecode) & 0x07)
711 #define FR_LMI_ANSI_REPORT_TYPE_IE 0x01
712 #define FR_LMI_ANSI_LINK_VERIFY_IE_91 0x19 /* details? */
713 #define FR_LMI_ANSI_LINK_VERIFY_IE 0x03
714 #define FR_LMI_ANSI_PVC_STATUS_IE 0x07
716 #define FR_LMI_CCITT_REPORT_TYPE_IE 0x51
717 #define FR_LMI_CCITT_LINK_VERIFY_IE 0x53
718 #define FR_LMI_CCITT_PVC_STATUS_IE 0x57
720 static const struct tok fr_q933_ie_values_codeset_0_5
[] = {
721 { FR_LMI_ANSI_REPORT_TYPE_IE
, "ANSI Report Type" },
722 { FR_LMI_ANSI_LINK_VERIFY_IE_91
, "ANSI Link Verify" },
723 { FR_LMI_ANSI_LINK_VERIFY_IE
, "ANSI Link Verify" },
724 { FR_LMI_ANSI_PVC_STATUS_IE
, "ANSI PVC Status" },
725 { FR_LMI_CCITT_REPORT_TYPE_IE
, "CCITT Report Type" },
726 { FR_LMI_CCITT_LINK_VERIFY_IE
, "CCITT Link Verify" },
727 { FR_LMI_CCITT_PVC_STATUS_IE
, "CCITT PVC Status" },
731 #define FR_LMI_REPORT_TYPE_IE_FULL_STATUS 0
732 #define FR_LMI_REPORT_TYPE_IE_LINK_VERIFY 1
733 #define FR_LMI_REPORT_TYPE_IE_ASYNC_PVC 2
735 static const struct tok fr_lmi_report_type_ie_values
[] = {
736 { FR_LMI_REPORT_TYPE_IE_FULL_STATUS
, "Full Status" },
737 { FR_LMI_REPORT_TYPE_IE_LINK_VERIFY
, "Link verify" },
738 { FR_LMI_REPORT_TYPE_IE_ASYNC_PVC
, "Async PVC Status" },
742 /* array of 16 codesets - currently we only support codepage 0 and 5 */
743 static const struct tok
*fr_q933_ie_codesets
[] = {
744 fr_q933_ie_values_codeset_0_5
,
749 fr_q933_ie_values_codeset_0_5
,
762 static int fr_q933_print_ie_codeset_0_5(netdissect_options
*ndo
, u_int iecode
,
763 u_int ielength
, const u_char
*p
);
765 typedef int (*codeset_pr_func_t
)(netdissect_options
*, u_int iecode
,
766 u_int ielength
, const u_char
*p
);
768 /* array of 16 codesets - currently we only support codepage 0 and 5 */
769 static const codeset_pr_func_t fr_q933_print_ie_codeset
[] = {
770 fr_q933_print_ie_codeset_0_5
,
775 fr_q933_print_ie_codeset_0_5
,
791 * p points to octet 2, the octet containing the length of the
792 * call reference value, so p[n] is octet n+2 ("octet X" is as
793 * used in Q.931/Q.933).
795 * XXX - actually used both for Q.931 and Q.933.
798 q933_print(netdissect_options
*ndo
,
799 const u_char
*p
, u_int length
)
802 u_int call_ref_length
, i
;
803 uint8_t call_ref
[15]; /* maximum length - length field is 4 bits */
810 u_int non_locking_shift
;
811 u_int unshift_codeset
;
813 ndo
->ndo_protocol
= "q.933";
814 ND_PRINT("%s", ndo
->ndo_eflag
? "" : "Q.933");
816 if (length
== 0 || !ND_TTEST_1(p
)) {
819 ND_PRINT("length %u", length
);
824 * Get the length of the call reference value.
826 olen
= length
; /* preserve the original length for display */
827 call_ref_length
= GET_U_1(p
) & 0x0f;
832 * Get the call reference value.
834 for (i
= 0; i
< call_ref_length
; i
++) {
835 if (length
== 0 || !ND_TTEST_1(p
)) {
838 ND_PRINT("length %u", olen
);
841 call_ref
[i
] = GET_U_1(p
);
847 * Get the message type.
849 if (length
== 0 || !ND_TTEST_1(p
)) {
852 ND_PRINT("length %u", olen
);
855 msgtype
= GET_U_1(p
);
860 * Peek ahead to see if we start with a shift.
862 non_locking_shift
= 0;
863 unshift_codeset
= codeset
;
865 if (!ND_TTEST_1(p
)) {
868 ND_PRINT("length %u", olen
);
872 if (IE_IS_SHIFT(iecode
)) {
874 * It's a shift. Skip over it.
882 codeset
= IE_SHIFT_CODESET(iecode
);
885 * If it's a locking shift to codeset 5,
886 * mark this as ANSI. (XXX - 5 is actually
887 * for national variants in general, not
888 * the US variant in particular, but maybe
889 * this is more American exceptionalism. :-))
891 if (IE_SHIFT_IS_LOCKING(iecode
)) {
893 * It's a locking shift.
897 * It's a locking shift to
898 * codeset 5, so this is
905 * It's a non-locking shift.
906 * Remember the current codeset, so we
907 * can revert to it after the next IE.
909 non_locking_shift
= 1;
915 /* printing out header part */
918 ND_PRINT("%s, codeset %u", is_ansi
? "ANSI" : "CCITT", codeset
);
920 if (call_ref_length
!= 0) {
921 if (call_ref_length
> 1 || GET_U_1(p
) != 0) {
923 * Not a dummy call reference.
925 ND_PRINT(", Call Ref: 0x");
926 for (i
= 0; i
< call_ref_length
; i
++)
927 ND_PRINT("%02x", call_ref
[i
]);
930 if (ndo
->ndo_vflag
) {
931 ND_PRINT(", %s (0x%02x), length %u",
932 tok2str(fr_q933_msg_values
,
933 "unknown message", msgtype
),
938 tok2str(fr_q933_msg_values
,
939 "unknown message 0x%02x", msgtype
));
942 /* Loop through the rest of the IEs */
943 while (length
!= 0) {
945 * What's the state of any non-locking shifts?
947 if (non_locking_shift
== 1) {
949 * There's a non-locking shift in effect for
950 * this IE. Count it, so we reset the codeset
951 * before the next IE.
953 non_locking_shift
= 2;
954 } else if (non_locking_shift
== 2) {
958 codeset
= unshift_codeset
;
959 non_locking_shift
= 0;
963 * Get the first octet of the IE.
965 if (!ND_TTEST_1(p
)) {
966 if (!ndo
->ndo_vflag
) {
967 ND_PRINT(", length %u", olen
);
975 /* Single-octet IE? */
976 if (IE_IS_SINGLE_OCTET(iecode
)) {
978 * Yes. Is it a shift?
980 if (IE_IS_SHIFT(iecode
)) {
982 * Yes. Is it locking?
984 if (IE_SHIFT_IS_LOCKING(iecode
)) {
988 non_locking_shift
= 0;
991 * No. Remember the current
992 * codeset, so we can revert
993 * to it after the next IE.
995 non_locking_shift
= 1;
996 unshift_codeset
= codeset
;
1002 codeset
= IE_SHIFT_CODESET(iecode
);
1006 * No. Get the IE length.
1008 if (length
== 0 || !ND_TTEST_1(p
)) {
1009 if (!ndo
->ndo_vflag
) {
1010 ND_PRINT(", length %u", olen
);
1014 ielength
= GET_U_1(p
);
1018 /* lets do the full IE parsing only in verbose mode
1019 * however some IEs (DLCI Status, Link Verify)
1020 * are also interesting in non-verbose mode */
1021 if (ndo
->ndo_vflag
) {
1022 ND_PRINT("\n\t%s IE (0x%02x), length %u: ",
1023 tok2str(fr_q933_ie_codesets
[codeset
],
1030 if (iecode
== 0 || ielength
== 0) {
1033 if (length
< ielength
|| !ND_TTEST_LEN(p
, ielength
)) {
1034 if (!ndo
->ndo_vflag
) {
1035 ND_PRINT(", length %u", olen
);
1041 if (fr_q933_print_ie_codeset
[codeset
] != NULL
) {
1042 ie_is_known
= fr_q933_print_ie_codeset
[codeset
](ndo
, iecode
, ielength
, p
);
1047 * Known IE; do we want to see a hexdump
1050 if (ndo
->ndo_vflag
> 1) {
1052 print_unknown_data(ndo
, p
, "\n\t ", ielength
);
1056 * Unknown IE; if we're printing verbosely,
1057 * print its content in hex.
1059 if (ndo
->ndo_vflag
>= 1) {
1060 print_unknown_data(ndo
, p
, "\n\t", ielength
);
1068 if (!ndo
->ndo_vflag
) {
1069 ND_PRINT(", length %u", olen
);
1074 nd_print_trunc(ndo
);
1078 fr_q933_print_ie_codeset_0_5(netdissect_options
*ndo
, u_int iecode
,
1079 u_int ielength
, const u_char
*p
)
1085 case FR_LMI_ANSI_REPORT_TYPE_IE
: /* fall through */
1086 case FR_LMI_CCITT_REPORT_TYPE_IE
:
1088 if (!ndo
->ndo_vflag
) {
1091 ND_PRINT("Invalid REPORT TYPE IE");
1094 if (ndo
->ndo_vflag
) {
1096 tok2str(fr_lmi_report_type_ie_values
,"unknown",GET_U_1(p
)),
1101 case FR_LMI_ANSI_LINK_VERIFY_IE
: /* fall through */
1102 case FR_LMI_CCITT_LINK_VERIFY_IE
:
1103 case FR_LMI_ANSI_LINK_VERIFY_IE_91
:
1104 if (!ndo
->ndo_vflag
) {
1108 ND_PRINT("Invalid LINK VERIFY IE");
1111 ND_PRINT("TX Seq: %3d, RX Seq: %3d", GET_U_1(p
), GET_U_1(p
+ 1));
1114 case FR_LMI_ANSI_PVC_STATUS_IE
: /* fall through */
1115 case FR_LMI_CCITT_PVC_STATUS_IE
:
1116 if (!ndo
->ndo_vflag
) {
1119 /* now parse the DLCI information element. */
1120 if ((ielength
< 3) ||
1121 (GET_U_1(p
) & 0x80) ||
1122 ((ielength
== 3) && !(GET_U_1(p
+ 1) & 0x80)) ||
1124 ((GET_U_1(p
+ 1) & 0x80) || !(GET_U_1(p
+ 2) & 0x80))) ||
1126 ((GET_U_1(p
+ 1) & 0x80) || (GET_U_1(p
+ 2) & 0x80) ||
1127 !(GET_U_1(p
+ 3) & 0x80))) ||
1129 !(GET_U_1(p
+ ielength
- 1) & 0x80)) {
1130 ND_PRINT("Invalid DLCI in PVC STATUS IE");
1134 dlci
= ((GET_U_1(p
) & 0x3F) << 4) | ((GET_U_1(p
+ 1) & 0x78) >> 3);
1135 if (ielength
== 4) {
1136 dlci
= (dlci
<< 6) | ((GET_U_1(p
+ 2) & 0x7E) >> 1);
1138 else if (ielength
== 5) {
1139 dlci
= (dlci
<< 13) | (GET_U_1(p
+ 2) & 0x7F) | ((GET_U_1(p
+ 3) & 0x7E) >> 1);
1142 ND_PRINT("DLCI %u: status %s%s", dlci
,
1143 GET_U_1(p
+ ielength
- 1) & 0x8 ? "New, " : "",
1144 GET_U_1(p
+ ielength
- 1) & 0x2 ? "Active" : "Inactive");