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_header(netdissect_options
*ndo
,
102 const u_char
*p
, u_int
*dlci
,
103 u_int
*addr_len
, uint32_t *flags
, u_int length
)
105 if (!ND_TTEST_1(p
) || length
< 1)
107 if ((GET_U_1(p
) & FR_EA_BIT
))
110 if (!ND_TTEST_1(p
+ 1) || length
< 2)
113 *dlci
= ((GET_U_1(p
) & 0xFC) << 2) | ((GET_U_1(p
+ 1) & 0xF0) >> 4);
115 *flags
= ((GET_U_1(p
) & 0x02) << 24) | /* CR flag */
116 ((GET_U_1(p
+ 1) & 0x0e) << 16); /* FECN,BECN,DE flags */
118 if (GET_U_1(p
+ 1) & FR_EA_BIT
)
119 return 1; /* 2-byte Q.922 address */
123 if (!ND_TTEST_1(p
) || length
< 1)
125 (*addr_len
)++; /* 3- or 4-byte Q.922 address */
126 if ((GET_U_1(p
) & FR_EA_BIT
) == 0) {
127 *dlci
= (*dlci
<< 7) | (GET_U_1(p
) >> 1);
128 (*addr_len
)++; /* 4-byte Q.922 address */
133 if (!ND_TTEST_1(p
) || length
< 1)
135 if ((GET_U_1(p
) & FR_EA_BIT
) == 0)
136 return 0; /* more than 4 bytes of Q.922 address? */
138 *flags
= *flags
| (GET_U_1(p
) & 0x02); /* SDLC flag */
140 *dlci
= (*dlci
<< 6) | (GET_U_1(p
) >> 2);
146 q922_string(netdissect_options
*ndo
, const u_char
*p
, u_int length
)
149 static u_int dlci
, addr_len
;
150 static uint32_t flags
;
151 static char buffer
[sizeof("DLCI xxxxxxxxxx")];
152 memset(buffer
, 0, sizeof(buffer
));
154 if (parse_q922_header(ndo
, p
, &dlci
, &addr_len
, &flags
, length
) == 1){
155 nd_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
, int length
, u_int addr_len
,
190 u_int dlci
, uint32_t flags
, uint16_t nlpid
)
192 if (ndo
->ndo_qflag
) {
193 ND_PRINT("Q.922, DLCI %u, length %u: ",
197 if (nlpid
<= 0xff) /* if its smaller than 256 then its a NLPID */
198 ND_PRINT("Q.922, hdr-len %u, DLCI %u, Flags [%s], NLPID %s (0x%02x), length %u: ",
201 bittok2str(fr_header_flag_values
, "none", flags
),
202 tok2str(nlpid_values
,"unknown", nlpid
),
205 else /* must be an ethertype */
206 ND_PRINT("Q.922, hdr-len %u, DLCI %u, Flags [%s], cisco-ethertype %s (0x%04x), length %u: ",
209 bittok2str(fr_header_flag_values
, "none", flags
),
210 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_if";
224 ND_TCHECK_4(p
); /* minimum frame header length */
226 if ((length
= fr_print(ndo
, p
, length
)) == 0)
236 fr_print(netdissect_options
*ndo
,
237 const u_char
*p
, u_int length
)
240 uint16_t extracted_ethertype
;
247 ndo
->ndo_protocol
= "fr";
248 ret
= parse_q922_header(ndo
, p
, &dlci
, &addr_len
, &flags
, length
);
252 ND_PRINT("Q.922, invalid address");
256 ND_TCHECK_1(p
+ addr_len
);
257 if (length
< addr_len
+ 1)
260 if (GET_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("UI %02x! ", GET_U_1(p
+ addr_len
));
270 extracted_ethertype
= GET_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("UI %02x! ", GET_U_1(p
+ addr_len
));
288 ND_TCHECK_1(p
+ addr_len
+ 1);
289 if (length
< addr_len
+ 2)
292 if (GET_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.
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("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
= GET_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
);
375 mfr_if_print(netdissect_options
*ndo
,
376 const struct pcap_pkthdr
*h
, const u_char
*p
)
378 u_int length
= h
->len
;
379 u_int caplen
= h
->caplen
;
381 ndo
->ndo_protocol
= "mfr_if";
382 ND_TCHECK_2(p
); /* minimum frame header length */
384 if ((length
= mfr_print(ndo
, p
, length
)) == 0)
394 #define MFR_CTRL_MSG_ADD_LINK 1
395 #define MFR_CTRL_MSG_ADD_LINK_ACK 2
396 #define MFR_CTRL_MSG_ADD_LINK_REJ 3
397 #define MFR_CTRL_MSG_HELLO 4
398 #define MFR_CTRL_MSG_HELLO_ACK 5
399 #define MFR_CTRL_MSG_REMOVE_LINK 6
400 #define MFR_CTRL_MSG_REMOVE_LINK_ACK 7
402 static const struct tok mfr_ctrl_msg_values
[] = {
403 { MFR_CTRL_MSG_ADD_LINK
, "Add Link" },
404 { MFR_CTRL_MSG_ADD_LINK_ACK
, "Add Link ACK" },
405 { MFR_CTRL_MSG_ADD_LINK_REJ
, "Add Link Reject" },
406 { MFR_CTRL_MSG_HELLO
, "Hello" },
407 { MFR_CTRL_MSG_HELLO_ACK
, "Hello ACK" },
408 { MFR_CTRL_MSG_REMOVE_LINK
, "Remove Link" },
409 { MFR_CTRL_MSG_REMOVE_LINK_ACK
, "Remove Link ACK" },
413 #define MFR_CTRL_IE_BUNDLE_ID 1
414 #define MFR_CTRL_IE_LINK_ID 2
415 #define MFR_CTRL_IE_MAGIC_NUM 3
416 #define MFR_CTRL_IE_TIMESTAMP 5
417 #define MFR_CTRL_IE_VENDOR_EXT 6
418 #define MFR_CTRL_IE_CAUSE 7
420 static const struct tok mfr_ctrl_ie_values
[] = {
421 { MFR_CTRL_IE_BUNDLE_ID
, "Bundle ID"},
422 { MFR_CTRL_IE_LINK_ID
, "Link ID"},
423 { MFR_CTRL_IE_MAGIC_NUM
, "Magic Number"},
424 { MFR_CTRL_IE_TIMESTAMP
, "Timestamp"},
425 { MFR_CTRL_IE_VENDOR_EXT
, "Vendor Extension"},
426 { MFR_CTRL_IE_CAUSE
, "Cause"},
430 #define MFR_ID_STRING_MAXLEN 50
432 struct ie_tlv_header_t
{
438 mfr_print(netdissect_options
*ndo
,
439 const u_char
*p
, u_int length
)
441 u_int tlen
,idx
,hdr_len
= 0;
442 uint16_t sequence_num
;
443 uint8_t ie_type
,ie_len
;
448 * FRF.16 Link Integrity Control Frame
451 * +----+----+----+----+----+----+----+----+
452 * | B | E | C=1| 0 0 0 0 | EA |
453 * +----+----+----+----+----+----+----+----+
454 * | 0 0 0 0 0 0 0 0 |
455 * +----+----+----+----+----+----+----+----+
457 * +----+----+----+----+----+----+----+----+
460 ndo
->ndo_protocol
= "mfr";
461 ND_TCHECK_4(p
); /* minimum frame header length */
463 if ((GET_U_1(p
) & MFR_BEC_MASK
) == MFR_CTRL_FRAME
&& GET_U_1(p
+ 1) == 0) {
464 ND_PRINT("FRF.16 Control, Flags [%s], %s, length %u",
465 bittok2str(frf_flag_values
,"none",(GET_U_1(p
) & MFR_BEC_MASK
)),
466 tok2str(mfr_ctrl_msg_values
,"Unknown Message (0x%02x)",GET_U_1(p
+ 2)),
475 while (tlen
>sizeof(struct ie_tlv_header_t
)) {
476 ND_TCHECK_LEN(tptr
, sizeof(struct ie_tlv_header_t
));
477 ie_type
=GET_U_1(tptr
);
478 ie_len
=GET_U_1(tptr
+ 1);
480 ND_PRINT("\n\tIE %s (%u), length %u: ",
481 tok2str(mfr_ctrl_ie_values
,"Unknown",ie_type
),
485 /* infinite loop check */
486 if (ie_type
== 0 || ie_len
<= sizeof(struct ie_tlv_header_t
))
489 ND_TCHECK_LEN(tptr
, ie_len
);
490 tptr
+=sizeof(struct ie_tlv_header_t
);
491 /* tlv len includes header */
492 ie_len
-=sizeof(struct ie_tlv_header_t
);
493 tlen
-=sizeof(struct ie_tlv_header_t
);
497 case MFR_CTRL_IE_MAGIC_NUM
:
498 ND_PRINT("0x%08x", GET_BE_U_4(tptr
));
501 case MFR_CTRL_IE_BUNDLE_ID
: /* same message format */
502 case MFR_CTRL_IE_LINK_ID
:
503 for (idx
= 0; idx
< ie_len
&& idx
< MFR_ID_STRING_MAXLEN
; idx
++) {
504 if (GET_U_1(tptr
+ idx
) != 0) /* don't print null termination */
505 fn_print_char(ndo
, GET_U_1(tptr
+ idx
));
511 case MFR_CTRL_IE_TIMESTAMP
:
512 if (ie_len
== sizeof(struct timeval
)) {
513 ts_print(ndo
, (const struct timeval
*)tptr
);
516 /* fall through and hexdump if no unix timestamp */
520 * FIXME those are the defined IEs that lack a decoder
521 * you are welcome to contribute code ;-)
524 case MFR_CTRL_IE_VENDOR_EXT
:
525 case MFR_CTRL_IE_CAUSE
:
528 if (ndo
->ndo_vflag
<= 1)
529 print_unknown_data(ndo
, tptr
, "\n\t ", ie_len
);
533 /* do we want to see a hexdump of the IE ? */
534 if (ndo
->ndo_vflag
> 1 )
535 print_unknown_data(ndo
, tptr
, "\n\t ", ie_len
);
543 * FRF.16 Fragmentation Frame
546 * +----+----+----+----+----+----+----+----+
547 * | B | E | C=0|seq. (high 4 bits) | EA |
548 * +----+----+----+----+----+----+----+----+
549 * | sequence (low 8 bits) |
550 * +----+----+----+----+----+----+----+----+
551 * | DLCI (6 bits) | CR | EA |
552 * +----+----+----+----+----+----+----+----+
553 * | DLCI (4 bits) |FECN|BECN| DE | EA |
554 * +----+----+----+----+----+----+----+----+
557 sequence_num
= (GET_U_1(p
)&0x1e)<<7 | GET_U_1(p
+ 1);
558 /* whole packet or first fragment ? */
559 if ((GET_U_1(p
) & MFR_BEC_MASK
) == MFR_FRAG_FRAME
||
560 (GET_U_1(p
) & MFR_BEC_MASK
) == MFR_B_BIT
) {
561 ND_PRINT("FRF.16 Frag, seq %u, Flags [%s], ",
563 bittok2str(frf_flag_values
,"none",(GET_U_1(p
) & MFR_BEC_MASK
)));
565 fr_print(ndo
, p
+hdr_len
,length
-hdr_len
);
569 /* must be a middle or the last fragment */
570 ND_PRINT("FRF.16 Frag, seq %u, Flags [%s]",
572 bittok2str(frf_flag_values
,"none",(GET_U_1(p
) & MFR_BEC_MASK
)));
573 print_unknown_data(ndo
, p
, "\n\t", length
);
582 /* an NLPID of 0xb1 indicates a 2-byte
586 * +----+----+----+----+----+----+----+----+
588 * +----+----+----+----+----+----+----+----+
589 * | NLPID (8 bits) | NLPID=0xb1
590 * +----+----+----+----+----+----+----+----+
591 * | B | E | C |seq. (high 4 bits) | R |
592 * +----+----+----+----+----+----+----+----+
593 * | sequence (low 8 bits) |
594 * +----+----+----+----+----+----+----+----+
597 #define FR_FRF15_FRAGTYPE 0x01
600 frf15_print(netdissect_options
*ndo
,
601 const u_char
*p
, u_int length
)
603 uint16_t sequence_num
, flags
;
609 flags
= GET_U_1(p
)&MFR_BEC_MASK
;
610 sequence_num
= (GET_U_1(p
)&0x1e)<<7 | GET_U_1(p
+ 1);
612 ND_PRINT("FRF.15, seq 0x%03x, Flags [%s],%s Fragmentation, length %u",
614 bittok2str(frf_flag_values
,"none",flags
),
615 GET_U_1(p
)&FR_FRF15_FRAGTYPE
? "Interface" : "End-to-End",
619 * depending on all permutations of the B, E and C bit
620 * dig as deep as we can - e.g. on the first (B) fragment
621 * there is enough payload to print the IP header
622 * on non (B) fragments it depends if the fragmentation
623 * model is end-to-end or interface based wether we want to print
624 * another Q.922 header
633 * Q.933 decoding portion for framerelay specific.
636 /* Q.933 packet format
637 Format of Other Protocols
639 +-------------------------------+
641 +---------------+---------------+
642 |Control 0x03 | NLPID 0x08 |
643 +---------------+---------------+
645 | octet 1 | octet 2 |
646 +-------------------------------+
648 | octet 2 | octet 2 |
649 +-------------------------------+
651 +-------------------------------+
653 +-------------------------------+
656 /* L2 (Octet 1)- Call Reference Usually is 0x0 */
659 * L2 (Octet 2)- Message Types definition 1 byte long.
662 #define MSG_TYPE_ESC_TO_NATIONAL 0x00
663 #define MSG_TYPE_ALERT 0x01
664 #define MSG_TYPE_CALL_PROCEEDING 0x02
665 #define MSG_TYPE_CONNECT 0x07
666 #define MSG_TYPE_CONNECT_ACK 0x0F
667 #define MSG_TYPE_PROGRESS 0x03
668 #define MSG_TYPE_SETUP 0x05
670 #define MSG_TYPE_DISCONNECT 0x45
671 #define MSG_TYPE_RELEASE 0x4D
672 #define MSG_TYPE_RELEASE_COMPLETE 0x5A
673 #define MSG_TYPE_RESTART 0x46
674 #define MSG_TYPE_RESTART_ACK 0x4E
676 #define MSG_TYPE_STATUS 0x7D
677 #define MSG_TYPE_STATUS_ENQ 0x75
679 static const struct tok fr_q933_msg_values
[] = {
680 { MSG_TYPE_ESC_TO_NATIONAL
, "ESC to National" },
681 { MSG_TYPE_ALERT
, "Alert" },
682 { MSG_TYPE_CALL_PROCEEDING
, "Call proceeding" },
683 { MSG_TYPE_CONNECT
, "Connect" },
684 { MSG_TYPE_CONNECT_ACK
, "Connect ACK" },
685 { MSG_TYPE_PROGRESS
, "Progress" },
686 { MSG_TYPE_SETUP
, "Setup" },
687 { MSG_TYPE_DISCONNECT
, "Disconnect" },
688 { MSG_TYPE_RELEASE
, "Release" },
689 { MSG_TYPE_RELEASE_COMPLETE
, "Release Complete" },
690 { MSG_TYPE_RESTART
, "Restart" },
691 { MSG_TYPE_RESTART_ACK
, "Restart ACK" },
692 { MSG_TYPE_STATUS
, "Status Reply" },
693 { MSG_TYPE_STATUS_ENQ
, "Status Enquiry" },
697 #define IE_IS_SINGLE_OCTET(iecode) ((iecode) & 0x80)
698 #define IE_IS_SHIFT(iecode) (((iecode) & 0xF0) == 0x90)
699 #define IE_SHIFT_IS_NON_LOCKING(iecode) ((iecode) & 0x08)
700 #define IE_SHIFT_IS_LOCKING(iecode) (!(IE_SHIFT_IS_NON_LOCKING(iecode)))
701 #define IE_SHIFT_CODESET(iecode) ((iecode) & 0x07)
703 #define FR_LMI_ANSI_REPORT_TYPE_IE 0x01
704 #define FR_LMI_ANSI_LINK_VERIFY_IE_91 0x19 /* details? */
705 #define FR_LMI_ANSI_LINK_VERIFY_IE 0x03
706 #define FR_LMI_ANSI_PVC_STATUS_IE 0x07
708 #define FR_LMI_CCITT_REPORT_TYPE_IE 0x51
709 #define FR_LMI_CCITT_LINK_VERIFY_IE 0x53
710 #define FR_LMI_CCITT_PVC_STATUS_IE 0x57
712 static const struct tok fr_q933_ie_values_codeset_0_5
[] = {
713 { FR_LMI_ANSI_REPORT_TYPE_IE
, "ANSI Report Type" },
714 { FR_LMI_ANSI_LINK_VERIFY_IE_91
, "ANSI Link Verify" },
715 { FR_LMI_ANSI_LINK_VERIFY_IE
, "ANSI Link Verify" },
716 { FR_LMI_ANSI_PVC_STATUS_IE
, "ANSI PVC Status" },
717 { FR_LMI_CCITT_REPORT_TYPE_IE
, "CCITT Report Type" },
718 { FR_LMI_CCITT_LINK_VERIFY_IE
, "CCITT Link Verify" },
719 { FR_LMI_CCITT_PVC_STATUS_IE
, "CCITT PVC Status" },
723 #define FR_LMI_REPORT_TYPE_IE_FULL_STATUS 0
724 #define FR_LMI_REPORT_TYPE_IE_LINK_VERIFY 1
725 #define FR_LMI_REPORT_TYPE_IE_ASYNC_PVC 2
727 static const struct tok fr_lmi_report_type_ie_values
[] = {
728 { FR_LMI_REPORT_TYPE_IE_FULL_STATUS
, "Full Status" },
729 { FR_LMI_REPORT_TYPE_IE_LINK_VERIFY
, "Link verify" },
730 { FR_LMI_REPORT_TYPE_IE_ASYNC_PVC
, "Async PVC Status" },
734 /* array of 16 codesets - currently we only support codepage 0 and 5 */
735 static const struct tok
*fr_q933_ie_codesets
[] = {
736 fr_q933_ie_values_codeset_0_5
,
741 fr_q933_ie_values_codeset_0_5
,
754 static int fr_q933_print_ie_codeset_0_5(netdissect_options
*ndo
, u_int iecode
,
755 u_int ielength
, const u_char
*p
);
757 typedef int (*codeset_pr_func_t
)(netdissect_options
*, u_int iecode
,
758 u_int ielength
, const u_char
*p
);
760 /* array of 16 codesets - currently we only support codepage 0 and 5 */
761 static const codeset_pr_func_t fr_q933_print_ie_codeset
[] = {
762 fr_q933_print_ie_codeset_0_5
,
767 fr_q933_print_ie_codeset_0_5
,
783 * p points to octet 2, the octet containing the length of the
784 * call reference value, so p[n] is octet n+2 ("octet X" is as
785 * used in Q.931/Q.933).
787 * XXX - actually used both for Q.931 and Q.933.
790 q933_print(netdissect_options
*ndo
,
791 const u_char
*p
, u_int length
)
794 u_int call_ref_length
, i
;
795 uint8_t call_ref
[15]; /* maximum length - length field is 4 bits */
802 u_int non_locking_shift
;
803 u_int unshift_codeset
;
805 ndo
->ndo_protocol
= "q.933";
806 ND_PRINT("%s", ndo
->ndo_eflag
? "" : "Q.933");
808 if (length
== 0 || !ND_TTEST_1(p
)) {
811 ND_PRINT("length %u", length
);
816 * Get the length of the call reference value.
818 olen
= length
; /* preserve the original length for display */
819 call_ref_length
= GET_U_1(p
) & 0x0f;
824 * Get the call reference value.
826 for (i
= 0; i
< call_ref_length
; i
++) {
827 if (length
== 0 || !ND_TTEST_1(p
)) {
830 ND_PRINT("length %u", olen
);
833 call_ref
[i
] = GET_U_1(p
);
839 * Get the message type.
841 if (length
== 0 || !ND_TTEST_1(p
)) {
844 ND_PRINT("length %u", olen
);
847 msgtype
= GET_U_1(p
);
852 * Peek ahead to see if we start with a shift.
854 non_locking_shift
= 0;
855 unshift_codeset
= codeset
;
857 if (!ND_TTEST_1(p
)) {
860 ND_PRINT("length %u", olen
);
864 if (IE_IS_SHIFT(iecode
)) {
866 * It's a shift. Skip over it.
874 codeset
= IE_SHIFT_CODESET(iecode
);
877 * If it's a locking shift to codeset 5,
878 * mark this as ANSI. (XXX - 5 is actually
879 * for national variants in general, not
880 * the US variant in particular, but maybe
881 * this is more American exceptionalism. :-))
883 if (IE_SHIFT_IS_LOCKING(iecode
)) {
885 * It's a locking shift.
889 * It's a locking shift to
890 * codeset 5, so this is
897 * It's a non-locking shift.
898 * Remember the current codeset, so we
899 * can revert to it after the next IE.
901 non_locking_shift
= 1;
907 /* printing out header part */
910 ND_PRINT("%s, codeset %u", is_ansi
? "ANSI" : "CCITT", codeset
);
912 if (call_ref_length
!= 0) {
914 if (call_ref_length
> 1 || GET_U_1(p
) != 0) {
916 * Not a dummy call reference.
918 ND_PRINT(", Call Ref: 0x");
919 for (i
= 0; i
< call_ref_length
; i
++)
920 ND_PRINT("%02x", call_ref
[i
]);
923 if (ndo
->ndo_vflag
) {
924 ND_PRINT(", %s (0x%02x), length %u",
925 tok2str(fr_q933_msg_values
,
926 "unknown message", msgtype
),
931 tok2str(fr_q933_msg_values
,
932 "unknown message 0x%02x", msgtype
));
935 /* Loop through the rest of the IEs */
936 while (length
!= 0) {
938 * What's the state of any non-locking shifts?
940 if (non_locking_shift
== 1) {
942 * There's a non-locking shift in effect for
943 * this IE. Count it, so we reset the codeset
944 * before the next IE.
946 non_locking_shift
= 2;
947 } else if (non_locking_shift
== 2) {
951 codeset
= unshift_codeset
;
952 non_locking_shift
= 0;
956 * Get the first octet of the IE.
958 if (!ND_TTEST_1(p
)) {
959 if (!ndo
->ndo_vflag
) {
960 ND_PRINT(", length %u", olen
);
968 /* Single-octet IE? */
969 if (IE_IS_SINGLE_OCTET(iecode
)) {
971 * Yes. Is it a shift?
973 if (IE_IS_SHIFT(iecode
)) {
975 * Yes. Is it locking?
977 if (IE_SHIFT_IS_LOCKING(iecode
)) {
981 non_locking_shift
= 0;
984 * No. Remember the current
985 * codeset, so we can revert
986 * to it after the next IE.
988 non_locking_shift
= 1;
989 unshift_codeset
= codeset
;
995 codeset
= IE_SHIFT_CODESET(iecode
);
999 * No. Get the IE length.
1001 if (length
== 0 || !ND_TTEST_1(p
)) {
1002 if (!ndo
->ndo_vflag
) {
1003 ND_PRINT(", length %u", olen
);
1007 ielength
= GET_U_1(p
);
1011 /* lets do the full IE parsing only in verbose mode
1012 * however some IEs (DLCI Status, Link Verify)
1013 * are also interesting in non-verbose mode */
1014 if (ndo
->ndo_vflag
) {
1015 ND_PRINT("\n\t%s IE (0x%02x), length %u: ",
1016 tok2str(fr_q933_ie_codesets
[codeset
],
1023 if (iecode
== 0 || ielength
== 0) {
1026 if (length
< ielength
|| !ND_TTEST_LEN(p
, ielength
)) {
1027 if (!ndo
->ndo_vflag
) {
1028 ND_PRINT(", length %u", olen
);
1034 if (fr_q933_print_ie_codeset
[codeset
] != NULL
) {
1035 ie_is_known
= fr_q933_print_ie_codeset
[codeset
](ndo
, iecode
, ielength
, p
);
1040 * Known IE; do we want to see a hexdump
1043 if (ndo
->ndo_vflag
> 1) {
1045 print_unknown_data(ndo
, p
, "\n\t ", ielength
);
1049 * Unknown IE; if we're printing verbosely,
1050 * print its content in hex.
1052 if (ndo
->ndo_vflag
>= 1) {
1053 print_unknown_data(ndo
, p
, "\n\t", ielength
);
1061 if (!ndo
->ndo_vflag
) {
1062 ND_PRINT(", length %u", olen
);
1067 nd_print_trunc(ndo
);
1071 fr_q933_print_ie_codeset_0_5(netdissect_options
*ndo
, u_int iecode
,
1072 u_int ielength
, const u_char
*p
)
1078 case FR_LMI_ANSI_REPORT_TYPE_IE
: /* fall through */
1079 case FR_LMI_CCITT_REPORT_TYPE_IE
:
1081 if (!ndo
->ndo_vflag
) {
1084 ND_PRINT("Invalid REPORT TYPE IE");
1087 if (ndo
->ndo_vflag
) {
1089 tok2str(fr_lmi_report_type_ie_values
,"unknown",GET_U_1(p
)),
1094 case FR_LMI_ANSI_LINK_VERIFY_IE
: /* fall through */
1095 case FR_LMI_CCITT_LINK_VERIFY_IE
:
1096 case FR_LMI_ANSI_LINK_VERIFY_IE_91
:
1097 if (!ndo
->ndo_vflag
) {
1101 ND_PRINT("Invalid LINK VERIFY IE");
1104 ND_PRINT("TX Seq: %3d, RX Seq: %3d", GET_U_1(p
), GET_U_1(p
+ 1));
1107 case FR_LMI_ANSI_PVC_STATUS_IE
: /* fall through */
1108 case FR_LMI_CCITT_PVC_STATUS_IE
:
1109 if (!ndo
->ndo_vflag
) {
1112 /* now parse the DLCI information element. */
1113 if ((ielength
< 3) ||
1114 (GET_U_1(p
) & 0x80) ||
1115 ((ielength
== 3) && !(GET_U_1(p
+ 1) & 0x80)) ||
1117 ((GET_U_1(p
+ 1) & 0x80) || !(GET_U_1(p
+ 2) & 0x80))) ||
1119 ((GET_U_1(p
+ 1) & 0x80) || (GET_U_1(p
+ 2) & 0x80) ||
1120 !(GET_U_1(p
+ 3) & 0x80))) ||
1122 !(GET_U_1(p
+ ielength
- 1) & 0x80)) {
1123 ND_PRINT("Invalid DLCI in PVC STATUS IE");
1127 dlci
= ((GET_U_1(p
) & 0x3F) << 4) | ((GET_U_1(p
+ 1) & 0x78) >> 3);
1128 if (ielength
== 4) {
1129 dlci
= (dlci
<< 6) | ((GET_U_1(p
+ 2) & 0x7E) >> 1);
1131 else if (ielength
== 5) {
1132 dlci
= (dlci
<< 13) | (GET_U_1(p
+ 2) & 0x7F) | ((GET_U_1(p
+ 3) & 0x7E) >> 1);
1135 ND_PRINT("DLCI %u: status %s%s", dlci
,
1136 GET_U_1(p
+ ielength
- 1) & 0x8 ? "New, " : "",
1137 GET_U_1(p
+ ielength
- 1) & 0x2 ? "Active" : "Inactive");