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"
41 static void frf15_print(netdissect_options
*ndo
, const u_char
*, u_int
);
44 * the frame relay header has a variable length
46 * the EA bit determines if there is another byte
49 * minimum header length is 2 bytes
50 * maximum header length is 4 bytes
53 * +----+----+----+----+----+----+----+----+
54 * | DLCI (6 bits) | CR | EA |
55 * +----+----+----+----+----+----+----+----+
56 * | DLCI (4 bits) |FECN|BECN| DE | EA |
57 * +----+----+----+----+----+----+----+----+
58 * | DLCI (7 bits) | EA |
59 * +----+----+----+----+----+----+----+----+
60 * | DLCI (6 bits) |SDLC| EA |
61 * +----+----+----+----+----+----+----+----+
64 #define FR_EA_BIT 0x01
66 #define FR_CR_BIT 0x02000000
67 #define FR_DE_BIT 0x00020000
68 #define FR_BECN_BIT 0x00040000
69 #define FR_FECN_BIT 0x00080000
70 #define FR_SDLC_BIT 0x00000002
73 static const struct tok fr_header_flag_values
[] = {
76 { FR_BECN_BIT
, "BECN" },
77 { FR_FECN_BIT
, "FECN" },
78 { FR_SDLC_BIT
, "sdlcore" },
83 #define MFR_B_BIT 0x80
84 #define MFR_E_BIT 0x40
85 #define MFR_C_BIT 0x20
86 #define MFR_BEC_MASK (MFR_B_BIT | MFR_E_BIT | MFR_C_BIT)
87 #define MFR_CTRL_FRAME (MFR_B_BIT | MFR_E_BIT | MFR_C_BIT)
88 #define MFR_FRAG_FRAME (MFR_B_BIT | MFR_E_BIT )
90 static const struct tok frf_flag_values
[] = {
91 { MFR_B_BIT
, "Begin" },
93 { MFR_C_BIT
, "Control" },
97 /* Finds out Q.922 address length, DLCI and flags. Returns 1 on success,
98 * 0 on invalid address, -1 on truncated packet
99 * save the flags dep. on address length
101 static int parse_q922_addr(netdissect_options
*ndo
,
102 const u_char
*p
, u_int
*dlci
,
103 u_int
*addr_len
, uint8_t *flags
, u_int length
)
105 if (!ND_TTEST_1(p
) || length
< 1)
107 if ((EXTRACT_U_1(p
) & FR_EA_BIT
))
110 if (!ND_TTEST_1(p
+ 1) || length
< 2)
113 *dlci
= ((EXTRACT_U_1(p
) & 0xFC) << 2) | ((EXTRACT_U_1(p
+ 1) & 0xF0) >> 4);
115 flags
[0] = EXTRACT_U_1(p
) & 0x02; /* populate the first flag fields */
116 flags
[1] = EXTRACT_U_1(p
+ 1) & 0x0c;
117 flags
[2] = 0; /* clear the rest of the flags */
120 if (EXTRACT_U_1(p
+ 1) & FR_EA_BIT
)
121 return 1; /* 2-byte Q.922 address */
125 if (!ND_TTEST_1(p
) || length
< 1)
127 (*addr_len
)++; /* 3- or 4-byte Q.922 address */
128 if ((EXTRACT_U_1(p
) & FR_EA_BIT
) == 0) {
129 *dlci
= (*dlci
<< 7) | (EXTRACT_U_1(p
) >> 1);
130 (*addr_len
)++; /* 4-byte Q.922 address */
135 if (!ND_TTEST_1(p
) || length
< 1)
137 if ((EXTRACT_U_1(p
) & FR_EA_BIT
) == 0)
138 return 0; /* more than 4 bytes of Q.922 address? */
140 flags
[3] = EXTRACT_U_1(p
) & 0x02;
142 *dlci
= (*dlci
<< 6) | (EXTRACT_U_1(p
) >> 2);
148 q922_string(netdissect_options
*ndo
, const u_char
*p
, u_int length
)
151 static u_int dlci
, addr_len
;
152 static uint8_t flags
[4];
153 static char buffer
[sizeof("DLCI xxxxxxxxxx")];
154 memset(buffer
, 0, sizeof(buffer
));
156 if (parse_q922_addr(ndo
, p
, &dlci
, &addr_len
, flags
, length
) == 1){
157 snprintf(buffer
, sizeof(buffer
), "DLCI %u", dlci
);
164 /* Frame Relay packet structure, with flags and CRC removed
166 +---------------------------+
170 +---------------------------+
171 | Control (UI = 0x03) |
172 +---------------------------+
173 | Optional Pad (0x00) |
174 +---------------------------+
176 +---------------------------+
183 +---------------------------+
185 * Q.922 addresses, as presently defined, are two octets and
186 contain a 10-bit DLCI. In some networks Q.922 addresses
187 may optionally be increased to three or four octets.
191 fr_hdr_print(netdissect_options
*ndo
,
192 int length
, u_int addr_len
, u_int dlci
, uint8_t *flags
, uint16_t nlpid
)
194 if (ndo
->ndo_qflag
) {
195 ND_PRINT((ndo
, "Q.922, DLCI %u, length %u: ",
199 if (nlpid
<= 0xff) /* if its smaller than 256 then its a NLPID */
200 ND_PRINT((ndo
, "Q.922, hdr-len %u, DLCI %u, Flags [%s], NLPID %s (0x%02x), length %u: ",
203 bittok2str(fr_header_flag_values
, "none", EXTRACT_BE_U_4(flags
)),
204 tok2str(nlpid_values
,"unknown", nlpid
),
207 else /* must be an ethertype */
208 ND_PRINT((ndo
, "Q.922, hdr-len %u, DLCI %u, Flags [%s], cisco-ethertype %s (0x%04x), length %u: ",
211 bittok2str(fr_header_flag_values
, "none", EXTRACT_BE_U_4(flags
)),
212 tok2str(ethertype_values
, "unknown", nlpid
),
219 fr_if_print(netdissect_options
*ndo
,
220 const struct pcap_pkthdr
*h
, register const u_char
*p
)
222 register u_int length
= h
->len
;
223 register u_int caplen
= h
->caplen
;
225 ND_TCHECK_4(p
); /* minimum frame header length */
227 if ((length
= fr_print(ndo
, p
, length
)) == 0)
232 ND_PRINT((ndo
, "[|fr]"));
237 fr_print(netdissect_options
*ndo
,
238 register const u_char
*p
, u_int length
)
241 uint16_t extracted_ethertype
;
248 ret
= parse_q922_addr(ndo
, p
, &dlci
, &addr_len
, flags
, length
);
252 ND_PRINT((ndo
, "Q.922, invalid address"));
256 ND_TCHECK_1(p
+ addr_len
);
257 if (length
< addr_len
+ 1)
260 if (EXTRACT_U_1(p
+ addr_len
) != LLC_UI
&& dlci
!= 0) {
262 * Let's figure out if we have Cisco-style encapsulation,
263 * with an Ethernet type (Cisco HDLC type?) following the
266 if (!ND_TTEST_2(p
+ addr_len
) || length
< addr_len
+ 2) {
268 ND_PRINT((ndo
, "UI %02x! ", EXTRACT_U_1(p
+ addr_len
)));
270 extracted_ethertype
= EXTRACT_BE_U_2(p
+ addr_len
);
273 fr_hdr_print(ndo
, length
, addr_len
, dlci
,
274 flags
, extracted_ethertype
);
276 if (ethertype_print(ndo
, extracted_ethertype
,
277 p
+addr_len
+ETHERTYPE_LEN
,
278 length
-addr_len
-ETHERTYPE_LEN
,
279 ndo
->ndo_snapend
-p
-addr_len
-ETHERTYPE_LEN
,
281 /* ether_type not known, probably it wasn't one */
282 ND_PRINT((ndo
, "UI %02x! ", EXTRACT_U_1(p
+ addr_len
)));
288 ND_TCHECK_1(p
+ addr_len
+ 1);
289 if (length
< addr_len
+ 2)
292 if (EXTRACT_U_1(p
+ addr_len
+ 1) == 0) {
294 * Assume a pad byte after the control (UI) byte.
295 * A pad byte should only be used with 3-byte Q.922.
298 ND_PRINT((ndo
, "Pad! "));
299 hdr_len
= addr_len
+ 1 /* UI */ + 1 /* pad */ + 1 /* NLPID */;
303 * A pad byte should be used with 3-byte Q.922.
306 ND_PRINT((ndo
, "No pad! "));
307 hdr_len
= addr_len
+ 1 /* UI */ + 1 /* NLPID */;
310 ND_TCHECK_1(p
+ hdr_len
- 1);
311 if (length
< hdr_len
)
313 nlpid
= EXTRACT_U_1(p
+ hdr_len
- 1);
316 fr_hdr_print(ndo
, length
, addr_len
, dlci
, flags
, nlpid
);
322 ip_print(ndo
, p
, length
);
326 ip6_print(ndo
, p
, length
);
332 isoclns_print(ndo
, p
- 1, length
+ 1); /* OSI printers need the NLPID field */
336 if (snap_print(ndo
, p
, length
, ndo
->ndo_snapend
- p
, NULL
, NULL
, 0) == 0) {
337 /* ether_type not known, print raw packet */
339 fr_hdr_print(ndo
, length
+ hdr_len
, hdr_len
,
341 if (!ndo
->ndo_suppress_default_print
)
342 ND_DEFAULTPRINT(p
- hdr_len
, length
+ hdr_len
);
347 q933_print(ndo
, p
, length
);
351 frf15_print(ndo
, p
, length
);
355 ppp_print(ndo
, p
, length
);
360 fr_hdr_print(ndo
, length
+ hdr_len
, addr_len
,
363 ND_DEFAULTPRINT(p
, length
);
369 ND_PRINT((ndo
, "[|fr]"));
375 mfr_if_print(netdissect_options
*ndo
,
376 const struct pcap_pkthdr
*h
, register const u_char
*p
)
378 register u_int length
= h
->len
;
379 register u_int caplen
= h
->caplen
;
381 ND_TCHECK_2(p
); /* minimum frame header length */
383 if ((length
= mfr_print(ndo
, p
, length
)) == 0)
388 ND_PRINT((ndo
, "[|mfr]"));
393 #define MFR_CTRL_MSG_ADD_LINK 1
394 #define MFR_CTRL_MSG_ADD_LINK_ACK 2
395 #define MFR_CTRL_MSG_ADD_LINK_REJ 3
396 #define MFR_CTRL_MSG_HELLO 4
397 #define MFR_CTRL_MSG_HELLO_ACK 5
398 #define MFR_CTRL_MSG_REMOVE_LINK 6
399 #define MFR_CTRL_MSG_REMOVE_LINK_ACK 7
401 static const struct tok mfr_ctrl_msg_values
[] = {
402 { MFR_CTRL_MSG_ADD_LINK
, "Add Link" },
403 { MFR_CTRL_MSG_ADD_LINK_ACK
, "Add Link ACK" },
404 { MFR_CTRL_MSG_ADD_LINK_REJ
, "Add Link Reject" },
405 { MFR_CTRL_MSG_HELLO
, "Hello" },
406 { MFR_CTRL_MSG_HELLO_ACK
, "Hello ACK" },
407 { MFR_CTRL_MSG_REMOVE_LINK
, "Remove Link" },
408 { MFR_CTRL_MSG_REMOVE_LINK_ACK
, "Remove Link ACK" },
412 #define MFR_CTRL_IE_BUNDLE_ID 1
413 #define MFR_CTRL_IE_LINK_ID 2
414 #define MFR_CTRL_IE_MAGIC_NUM 3
415 #define MFR_CTRL_IE_TIMESTAMP 5
416 #define MFR_CTRL_IE_VENDOR_EXT 6
417 #define MFR_CTRL_IE_CAUSE 7
419 static const struct tok mfr_ctrl_ie_values
[] = {
420 { MFR_CTRL_IE_BUNDLE_ID
, "Bundle ID"},
421 { MFR_CTRL_IE_LINK_ID
, "Link ID"},
422 { MFR_CTRL_IE_MAGIC_NUM
, "Magic Number"},
423 { MFR_CTRL_IE_TIMESTAMP
, "Timestamp"},
424 { MFR_CTRL_IE_VENDOR_EXT
, "Vendor Extension"},
425 { MFR_CTRL_IE_CAUSE
, "Cause"},
429 #define MFR_ID_STRING_MAXLEN 50
431 struct ie_tlv_header_t
{
437 mfr_print(netdissect_options
*ndo
,
438 register const u_char
*p
, u_int length
)
440 u_int tlen
,idx
,hdr_len
= 0;
441 uint16_t sequence_num
;
442 uint8_t ie_type
,ie_len
;
447 * FRF.16 Link Integrity Control Frame
450 * +----+----+----+----+----+----+----+----+
451 * | B | E | C=1| 0 0 0 0 | EA |
452 * +----+----+----+----+----+----+----+----+
453 * | 0 0 0 0 0 0 0 0 |
454 * +----+----+----+----+----+----+----+----+
456 * +----+----+----+----+----+----+----+----+
459 ND_TCHECK_4(p
); /* minimum frame header length */
461 if ((EXTRACT_U_1(p
) & MFR_BEC_MASK
) == MFR_CTRL_FRAME
&& EXTRACT_U_1(p
+ 1) == 0) {
462 ND_PRINT((ndo
, "FRF.16 Control, Flags [%s], %s, length %u",
463 bittok2str(frf_flag_values
,"none",(EXTRACT_U_1(p
) & MFR_BEC_MASK
)),
464 tok2str(mfr_ctrl_msg_values
,"Unknown Message (0x%02x)",EXTRACT_U_1(p
+ 2)),
473 while (tlen
>sizeof(struct ie_tlv_header_t
)) {
474 ND_TCHECK2(*tptr
, sizeof(struct ie_tlv_header_t
));
478 ND_PRINT((ndo
, "\n\tIE %s (%u), length %u: ",
479 tok2str(mfr_ctrl_ie_values
,"Unknown",ie_type
),
483 /* infinite loop check */
484 if (ie_type
== 0 || ie_len
<= sizeof(struct ie_tlv_header_t
))
487 ND_TCHECK2(*tptr
, ie_len
);
488 tptr
+=sizeof(struct ie_tlv_header_t
);
489 /* tlv len includes header */
490 ie_len
-=sizeof(struct ie_tlv_header_t
);
491 tlen
-=sizeof(struct ie_tlv_header_t
);
495 case MFR_CTRL_IE_MAGIC_NUM
:
496 ND_PRINT((ndo
, "0x%08x", EXTRACT_BE_U_4(tptr
)));
499 case MFR_CTRL_IE_BUNDLE_ID
: /* same message format */
500 case MFR_CTRL_IE_LINK_ID
:
501 for (idx
= 0; idx
< ie_len
&& idx
< MFR_ID_STRING_MAXLEN
; idx
++) {
502 if (*(tptr
+idx
) != 0) /* don't print null termination */
503 safeputchar(ndo
, *(tptr
+ idx
));
509 case MFR_CTRL_IE_TIMESTAMP
:
510 if (ie_len
== sizeof(struct timeval
)) {
511 ts_print(ndo
, (const struct timeval
*)tptr
);
514 /* fall through and hexdump if no unix timestamp */
518 * FIXME those are the defined IEs that lack a decoder
519 * you are welcome to contribute code ;-)
522 case MFR_CTRL_IE_VENDOR_EXT
:
523 case MFR_CTRL_IE_CAUSE
:
526 if (ndo
->ndo_vflag
<= 1)
527 print_unknown_data(ndo
, tptr
, "\n\t ", ie_len
);
531 /* do we want to see a hexdump of the IE ? */
532 if (ndo
->ndo_vflag
> 1 )
533 print_unknown_data(ndo
, tptr
, "\n\t ", ie_len
);
541 * FRF.16 Fragmentation Frame
544 * +----+----+----+----+----+----+----+----+
545 * | B | E | C=0|seq. (high 4 bits) | EA |
546 * +----+----+----+----+----+----+----+----+
547 * | sequence (low 8 bits) |
548 * +----+----+----+----+----+----+----+----+
549 * | DLCI (6 bits) | CR | EA |
550 * +----+----+----+----+----+----+----+----+
551 * | DLCI (4 bits) |FECN|BECN| DE | EA |
552 * +----+----+----+----+----+----+----+----+
555 sequence_num
= (EXTRACT_U_1(p
)&0x1e)<<7 | EXTRACT_U_1(p
+ 1);
556 /* whole packet or first fragment ? */
557 if ((EXTRACT_U_1(p
) & MFR_BEC_MASK
) == MFR_FRAG_FRAME
||
558 (EXTRACT_U_1(p
) & MFR_BEC_MASK
) == MFR_B_BIT
) {
559 ND_PRINT((ndo
, "FRF.16 Frag, seq %u, Flags [%s], ",
561 bittok2str(frf_flag_values
,"none",(EXTRACT_U_1(p
) & MFR_BEC_MASK
))));
563 fr_print(ndo
, p
+hdr_len
,length
-hdr_len
);
567 /* must be a middle or the last fragment */
568 ND_PRINT((ndo
, "FRF.16 Frag, seq %u, Flags [%s]",
570 bittok2str(frf_flag_values
,"none",(EXTRACT_U_1(p
) & MFR_BEC_MASK
))));
571 print_unknown_data(ndo
, p
, "\n\t", length
);
576 ND_PRINT((ndo
, "[|mfr]"));
580 /* an NLPID of 0xb1 indicates a 2-byte
584 * +----+----+----+----+----+----+----+----+
586 * +----+----+----+----+----+----+----+----+
587 * | NLPID (8 bits) | NLPID=0xb1
588 * +----+----+----+----+----+----+----+----+
589 * | B | E | C |seq. (high 4 bits) | R |
590 * +----+----+----+----+----+----+----+----+
591 * | sequence (low 8 bits) |
592 * +----+----+----+----+----+----+----+----+
595 #define FR_FRF15_FRAGTYPE 0x01
598 frf15_print(netdissect_options
*ndo
,
599 const u_char
*p
, u_int length
)
601 uint16_t sequence_num
, flags
;
607 flags
= EXTRACT_U_1(p
)&MFR_BEC_MASK
;
608 sequence_num
= (EXTRACT_U_1(p
)&0x1e)<<7 | EXTRACT_U_1(p
+ 1);
610 ND_PRINT((ndo
, "FRF.15, seq 0x%03x, Flags [%s],%s Fragmentation, length %u",
612 bittok2str(frf_flag_values
,"none",flags
),
613 EXTRACT_U_1(p
)&FR_FRF15_FRAGTYPE
? "Interface" : "End-to-End",
617 * depending on all permutations of the B, E and C bit
618 * dig as deep as we can - e.g. on the first (B) fragment
619 * there is enough payload to print the IP header
620 * on non (B) fragments it depends if the fragmentation
621 * model is end-to-end or interface based wether we want to print
622 * another Q.922 header
627 ND_PRINT((ndo
, "[|frf.15]"));
631 * Q.933 decoding portion for framerelay specific.
634 /* Q.933 packet format
635 Format of Other Protocols
637 +-------------------------------+
639 +---------------+---------------+
640 |Control 0x03 | NLPID 0x08 |
641 +---------------+---------------+
643 | octet 1 | octet 2 |
644 +-------------------------------+
646 | octet 2 | octet 2 |
647 +-------------------------------+
649 +-------------------------------+
651 +-------------------------------+
654 /* L2 (Octet 1)- Call Reference Usually is 0x0 */
657 * L2 (Octet 2)- Message Types definition 1 byte long.
660 #define MSG_TYPE_ESC_TO_NATIONAL 0x00
661 #define MSG_TYPE_ALERT 0x01
662 #define MSG_TYPE_CALL_PROCEEDING 0x02
663 #define MSG_TYPE_CONNECT 0x07
664 #define MSG_TYPE_CONNECT_ACK 0x0F
665 #define MSG_TYPE_PROGRESS 0x03
666 #define MSG_TYPE_SETUP 0x05
668 #define MSG_TYPE_DISCONNECT 0x45
669 #define MSG_TYPE_RELEASE 0x4D
670 #define MSG_TYPE_RELEASE_COMPLETE 0x5A
671 #define MSG_TYPE_RESTART 0x46
672 #define MSG_TYPE_RESTART_ACK 0x4E
674 #define MSG_TYPE_STATUS 0x7D
675 #define MSG_TYPE_STATUS_ENQ 0x75
677 static const struct tok fr_q933_msg_values
[] = {
678 { MSG_TYPE_ESC_TO_NATIONAL
, "ESC to National" },
679 { MSG_TYPE_ALERT
, "Alert" },
680 { MSG_TYPE_CALL_PROCEEDING
, "Call proceeding" },
681 { MSG_TYPE_CONNECT
, "Connect" },
682 { MSG_TYPE_CONNECT_ACK
, "Connect ACK" },
683 { MSG_TYPE_PROGRESS
, "Progress" },
684 { MSG_TYPE_SETUP
, "Setup" },
685 { MSG_TYPE_DISCONNECT
, "Disconnect" },
686 { MSG_TYPE_RELEASE
, "Release" },
687 { MSG_TYPE_RELEASE_COMPLETE
, "Release Complete" },
688 { MSG_TYPE_RESTART
, "Restart" },
689 { MSG_TYPE_RESTART_ACK
, "Restart ACK" },
690 { MSG_TYPE_STATUS
, "Status Reply" },
691 { MSG_TYPE_STATUS_ENQ
, "Status Enquiry" },
695 #define IE_IS_SINGLE_OCTET(iecode) ((iecode) & 0x80)
696 #define IE_IS_SHIFT(iecode) (((iecode) & 0xF0) == 0x90)
697 #define IE_SHIFT_IS_NON_LOCKING(iecode) ((iecode) & 0x08)
698 #define IE_SHIFT_IS_LOCKING(iecode) (!(IE_SHIFT_IS_NON_LOCKING(iecode)))
699 #define IE_SHIFT_CODESET(iecode) ((iecode) & 0x07)
701 #define FR_LMI_ANSI_REPORT_TYPE_IE 0x01
702 #define FR_LMI_ANSI_LINK_VERIFY_IE_91 0x19 /* details? */
703 #define FR_LMI_ANSI_LINK_VERIFY_IE 0x03
704 #define FR_LMI_ANSI_PVC_STATUS_IE 0x07
706 #define FR_LMI_CCITT_REPORT_TYPE_IE 0x51
707 #define FR_LMI_CCITT_LINK_VERIFY_IE 0x53
708 #define FR_LMI_CCITT_PVC_STATUS_IE 0x57
710 static const struct tok fr_q933_ie_values_codeset_0_5
[] = {
711 { FR_LMI_ANSI_REPORT_TYPE_IE
, "ANSI Report Type" },
712 { FR_LMI_ANSI_LINK_VERIFY_IE_91
, "ANSI Link Verify" },
713 { FR_LMI_ANSI_LINK_VERIFY_IE
, "ANSI Link Verify" },
714 { FR_LMI_ANSI_PVC_STATUS_IE
, "ANSI PVC Status" },
715 { FR_LMI_CCITT_REPORT_TYPE_IE
, "CCITT Report Type" },
716 { FR_LMI_CCITT_LINK_VERIFY_IE
, "CCITT Link Verify" },
717 { FR_LMI_CCITT_PVC_STATUS_IE
, "CCITT PVC Status" },
721 #define FR_LMI_REPORT_TYPE_IE_FULL_STATUS 0
722 #define FR_LMI_REPORT_TYPE_IE_LINK_VERIFY 1
723 #define FR_LMI_REPORT_TYPE_IE_ASYNC_PVC 2
725 static const struct tok fr_lmi_report_type_ie_values
[] = {
726 { FR_LMI_REPORT_TYPE_IE_FULL_STATUS
, "Full Status" },
727 { FR_LMI_REPORT_TYPE_IE_LINK_VERIFY
, "Link verify" },
728 { FR_LMI_REPORT_TYPE_IE_ASYNC_PVC
, "Async PVC Status" },
732 /* array of 16 codesets - currently we only support codepage 0 and 5 */
733 static const struct tok
*fr_q933_ie_codesets
[] = {
734 fr_q933_ie_values_codeset_0_5
,
739 fr_q933_ie_values_codeset_0_5
,
752 static int fr_q933_print_ie_codeset_0_5(netdissect_options
*ndo
, u_int iecode
,
753 u_int ielength
, const u_char
*p
);
755 typedef int (*codeset_pr_func_t
)(netdissect_options
*, u_int iecode
,
756 u_int ielength
, const u_char
*p
);
758 /* array of 16 codesets - currently we only support codepage 0 and 5 */
759 static const codeset_pr_func_t fr_q933_print_ie_codeset
[] = {
760 fr_q933_print_ie_codeset_0_5
,
765 fr_q933_print_ie_codeset_0_5
,
781 * p points to octet 2, the octet containing the length of the
782 * call reference value, so p[n] is octet n+2 ("octet X" is as
783 * used in Q.931/Q.933).
785 * XXX - actually used both for Q.931 and Q.933.
788 q933_print(netdissect_options
*ndo
,
789 const u_char
*p
, u_int length
)
792 u_int call_ref_length
, i
;
793 uint8_t call_ref
[15]; /* maximum length - length field is 4 bits */
800 u_int non_locking_shift
;
801 u_int unshift_codeset
;
803 ND_PRINT((ndo
, "%s", ndo
->ndo_eflag
? "" : "Q.933"));
805 if (length
== 0 || !ND_TTEST(*p
)) {
807 ND_PRINT((ndo
, ", "));
808 ND_PRINT((ndo
, "length %u", length
));
813 * Get the length of the call reference value.
815 olen
= length
; /* preserve the original length for display */
816 call_ref_length
= EXTRACT_U_1(p
) & 0x0f;
821 * Get the call reference value.
823 for (i
= 0; i
< call_ref_length
; i
++) {
824 if (length
== 0 || !ND_TTEST(*p
)) {
826 ND_PRINT((ndo
, ", "));
827 ND_PRINT((ndo
, "length %u", olen
));
830 call_ref
[i
] = EXTRACT_U_1(p
);
836 * Get the message type.
838 if (length
== 0 || !ND_TTEST(*p
)) {
840 ND_PRINT((ndo
, ", "));
841 ND_PRINT((ndo
, "length %u", olen
));
844 msgtype
= EXTRACT_U_1(p
);
849 * Peek ahead to see if we start with a shift.
851 non_locking_shift
= 0;
852 unshift_codeset
= codeset
;
856 ND_PRINT((ndo
, ", "));
857 ND_PRINT((ndo
, "length %u", olen
));
860 iecode
= EXTRACT_U_1(p
);
861 if (IE_IS_SHIFT(iecode
)) {
863 * It's a shift. Skip over it.
871 codeset
= IE_SHIFT_CODESET(iecode
);
874 * If it's a locking shift to codeset 5,
875 * mark this as ANSI. (XXX - 5 is actually
876 * for national variants in general, not
877 * the US variant in particular, but maybe
878 * this is more American exceptionalism. :-))
880 if (IE_SHIFT_IS_LOCKING(iecode
)) {
882 * It's a locking shift.
886 * It's a locking shift to
887 * codeset 5, so this is
894 * It's a non-locking shift.
895 * Remember the current codeset, so we
896 * can revert to it after the next IE.
898 non_locking_shift
= 1;
904 /* printing out header part */
906 ND_PRINT((ndo
, ", "));
907 ND_PRINT((ndo
, "%s, codeset %u", is_ansi
? "ANSI" : "CCITT", codeset
));
909 if (call_ref_length
!= 0) {
911 if (call_ref_length
> 1 || EXTRACT_U_1(p
) != 0) {
913 * Not a dummy call reference.
915 ND_PRINT((ndo
, ", Call Ref: 0x"));
916 for (i
= 0; i
< call_ref_length
; i
++)
917 ND_PRINT((ndo
, "%02x", call_ref
[i
]));
920 if (ndo
->ndo_vflag
) {
921 ND_PRINT((ndo
, ", %s (0x%02x), length %u",
922 tok2str(fr_q933_msg_values
,
923 "unknown message", msgtype
),
927 ND_PRINT((ndo
, ", %s",
928 tok2str(fr_q933_msg_values
,
929 "unknown message 0x%02x", msgtype
)));
932 /* Loop through the rest of the IEs */
933 while (length
!= 0) {
935 * What's the state of any non-locking shifts?
937 if (non_locking_shift
== 1) {
939 * There's a non-locking shift in effect for
940 * this IE. Count it, so we reset the codeset
941 * before the next IE.
943 non_locking_shift
= 2;
944 } else if (non_locking_shift
== 2) {
948 codeset
= unshift_codeset
;
949 non_locking_shift
= 0;
953 * Get the first octet of the IE.
956 if (!ndo
->ndo_vflag
) {
957 ND_PRINT((ndo
, ", length %u", olen
));
961 iecode
= EXTRACT_U_1(p
);
965 /* Single-octet IE? */
966 if (IE_IS_SINGLE_OCTET(iecode
)) {
968 * Yes. Is it a shift?
970 if (IE_IS_SHIFT(iecode
)) {
972 * Yes. Is it locking?
974 if (IE_SHIFT_IS_LOCKING(iecode
)) {
978 non_locking_shift
= 0;
981 * No. Remember the current
982 * codeset, so we can revert
983 * to it after the next IE.
985 non_locking_shift
= 1;
986 unshift_codeset
= codeset
;
992 codeset
= IE_SHIFT_CODESET(iecode
);
996 * No. Get the IE length.
998 if (length
== 0 || !ND_TTEST(*p
)) {
999 if (!ndo
->ndo_vflag
) {
1000 ND_PRINT((ndo
, ", length %u", olen
));
1004 ielength
= EXTRACT_U_1(p
);
1008 /* lets do the full IE parsing only in verbose mode
1009 * however some IEs (DLCI Status, Link Verify)
1010 * are also interesting in non-verbose mode */
1011 if (ndo
->ndo_vflag
) {
1012 ND_PRINT((ndo
, "\n\t%s IE (0x%02x), length %u: ",
1013 tok2str(fr_q933_ie_codesets
[codeset
],
1020 if (iecode
== 0 || ielength
== 0) {
1023 if (length
< ielength
|| !ND_TTEST2(*p
, ielength
)) {
1024 if (!ndo
->ndo_vflag
) {
1025 ND_PRINT((ndo
, ", length %u", olen
));
1031 if (fr_q933_print_ie_codeset
[codeset
] != NULL
) {
1032 ie_is_known
= fr_q933_print_ie_codeset
[codeset
](ndo
, iecode
, ielength
, p
);
1037 * Known IE; do we want to see a hexdump
1040 if (ndo
->ndo_vflag
> 1) {
1042 print_unknown_data(ndo
, p
, "\n\t ", ielength
);
1046 * Unknown IE; if we're printing verbosely,
1047 * print its content in hex.
1049 if (ndo
->ndo_vflag
>= 1) {
1050 print_unknown_data(ndo
, p
, "\n\t", ielength
);
1058 if (!ndo
->ndo_vflag
) {
1059 ND_PRINT((ndo
, ", length %u", olen
));
1064 ND_PRINT((ndo
, "[|q.933]"));
1068 fr_q933_print_ie_codeset_0_5(netdissect_options
*ndo
, u_int iecode
,
1069 u_int ielength
, const u_char
*p
)
1075 case FR_LMI_ANSI_REPORT_TYPE_IE
: /* fall through */
1076 case FR_LMI_CCITT_REPORT_TYPE_IE
:
1078 if (!ndo
->ndo_vflag
) {
1079 ND_PRINT((ndo
, ", "));
1081 ND_PRINT((ndo
, "Invalid REPORT TYPE IE"));
1084 if (ndo
->ndo_vflag
) {
1085 ND_PRINT((ndo
, "%s (%u)",
1086 tok2str(fr_lmi_report_type_ie_values
,"unknown",EXTRACT_U_1(p
)),
1091 case FR_LMI_ANSI_LINK_VERIFY_IE
: /* fall through */
1092 case FR_LMI_CCITT_LINK_VERIFY_IE
:
1093 case FR_LMI_ANSI_LINK_VERIFY_IE_91
:
1094 if (!ndo
->ndo_vflag
) {
1095 ND_PRINT((ndo
, ", "));
1098 ND_PRINT((ndo
, "Invalid LINK VERIFY IE"));
1101 ND_PRINT((ndo
, "TX Seq: %3d, RX Seq: %3d", EXTRACT_U_1(p
), EXTRACT_U_1(p
+ 1)));
1104 case FR_LMI_ANSI_PVC_STATUS_IE
: /* fall through */
1105 case FR_LMI_CCITT_PVC_STATUS_IE
:
1106 if (!ndo
->ndo_vflag
) {
1107 ND_PRINT((ndo
, ", "));
1109 /* now parse the DLCI information element. */
1110 if ((ielength
< 3) ||
1111 (EXTRACT_U_1(p
) & 0x80) ||
1112 ((ielength
== 3) && !(EXTRACT_U_1(p
+ 1) & 0x80)) ||
1114 ((EXTRACT_U_1(p
+ 1) & 0x80) || !(EXTRACT_U_1(p
+ 2) & 0x80))) ||
1116 ((EXTRACT_U_1(p
+ 1) & 0x80) || (EXTRACT_U_1(p
+ 2) & 0x80) ||
1117 !(EXTRACT_U_1(p
+ 3) & 0x80))) ||
1119 !(EXTRACT_U_1(p
+ ielength
- 1) & 0x80)) {
1120 ND_PRINT((ndo
, "Invalid DLCI in PVC STATUS IE"));
1124 dlci
= ((EXTRACT_U_1(p
) & 0x3F) << 4) | ((EXTRACT_U_1(p
+ 1) & 0x78) >> 3);
1125 if (ielength
== 4) {
1126 dlci
= (dlci
<< 6) | ((EXTRACT_U_1(p
+ 2) & 0x7E) >> 1);
1128 else if (ielength
== 5) {
1129 dlci
= (dlci
<< 13) | (EXTRACT_U_1(p
+ 2) & 0x7F) | ((EXTRACT_U_1(p
+ 3) & 0x7E) >> 1);
1132 ND_PRINT((ndo
, "DLCI %u: status %s%s", dlci
,
1133 EXTRACT_U_1(p
+ ielength
- 1) & 0x8 ? "New, " : "",
1134 EXTRACT_U_1(p
+ ielength
- 1) & 0x2 ? "Active" : "Inactive"));
1142 * c-style: whitesmith