2 * Routines for Frame Relay dissection
4 * Copyright 2001, Paul Ionescu <paul@acorp.ro>
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
14 * https://web.archive.org/web/20150510093619/http://www.protocols.com/pbook/frame.htm
15 * https://www.broadband-forum.org/wp-content/uploads/2018/12/FRF.3.2.pdf
16 * ITU Recommendations Q.922 and Q.933
20 * https://web.archive.org/web/20030422173700/https://www.trillium.com/assets/legacyframe/white_paper/8771019.pdf
25 #include <epan/packet.h>
26 #include <epan/capture_dissectors.h>
27 #include <epan/prefs.h>
28 #include <epan/expert.h>
29 #include <epan/conversation.h>
30 #include <epan/arptypes.h>
33 #include "packet-llc.h"
34 #include "packet-chdlc.h"
35 #include "packet-juniper.h"
36 #include "packet-sflow.h"
37 #include "packet-l2tp.h"
38 #include <epan/xdlc.h>
39 #include <epan/etypes.h>
40 #include <epan/nlpid.h>
42 void proto_register_fr(void);
43 void proto_reg_handoff_fr(void);
46 * Bits in the address field.
48 #define FRELAY_EA 0x01 /* Address field extension bit */
50 #define FRELAY_UPPER_DLCI 0xFC /* Upper DLCI */
51 #define FRELAY_CR 0x02 /* Command/response bit in first octet */
53 #define FRELAY_SECOND_DLCI 0xF0 /* DLCI bits in FECN/BECN/DE octet */
54 #define FRELAY_FECN 0x08 /* Forward Explicit Congestion Notification */
55 #define FRELAY_BECN 0x04 /* Backward Explicit Congestion Notification */
56 #define FRELAY_DE 0x02 /* Discard Eligibility */
58 #define FRELAY_THIRD_DLCI 0xFE /* DLCI bits in third octet, if any */
60 #define FRELAY_LOWER_DLCI 0xFC /* Lower DLCI */
61 #define FRELAY_DC 0x02 /* DLCI or DL-CORE control indicator in last octet */
63 #define FROM_DCE 0x80 /* for direction setting */
67 static int ett_fr_address
;
68 static int ett_fr_control
;
70 static int hf_fr_upper_dlci
;
72 static int hf_fr_second_dlci
;
73 static int hf_fr_fecn
;
74 static int hf_fr_becn
;
76 static int hf_fr_third_dlci
;
77 static int hf_fr_dlcore_control
;
78 static int hf_fr_lower_dlci
;
80 static int hf_fr_dlci
;
81 static int hf_fr_control
;
85 static int hf_fr_p_ext
;
87 static int hf_fr_f_ext
;
88 static int hf_fr_s_ftype
;
89 static int hf_fr_u_modifier_cmd
;
90 static int hf_fr_u_modifier_resp
;
91 static int hf_fr_ftype_i
;
92 static int hf_fr_ftype_s_u
;
93 static int hf_fr_ftype_s_u_ext
;
94 static int hf_fr_nlpid
;
97 static int hf_fr_snaptype
;
98 static int hf_fr_chdlctype
;
99 static int hf_fr_first_addr_octet
;
100 static int hf_fr_second_addr_octet
;
101 static int hf_fr_third_addr_octet
;
103 static expert_field ei_fr_bogus_address
;
104 static expert_field ei_fr_frame_relay_lapf
;
105 static expert_field ei_fr_frame_relay_xid
;
107 static dissector_handle_t eth_withfcs_handle
;
108 static dissector_handle_t gprs_ns_handle
;
109 static dissector_handle_t lapb_handle
;
110 static dissector_handle_t data_handle
;
111 static dissector_handle_t fr_handle
;
113 static capture_dissector_handle_t chdlc_cap_handle
;
114 static capture_dissector_handle_t eth_cap_handle
;
116 static dissector_table_t chdlc_subdissector_table
;
117 static dissector_table_t osinl_incl_subdissector_table
;
118 static dissector_table_t ethertype_subdissector_table
;
121 * Encapsulation type.
122 * XXX - this should be per-DLCI as well.
124 #define FRF_3_2 0 /* FRF 3.2 or Cisco HDLC */
125 #define GPRS_NS 1 /* GPRS Network Services (3GPP TS 08.16) */
126 #define RAW_ETHER 2 /* Raw Ethernet */
127 #define LAPB 3 /* T.617a-1994 Annex G encapsuation of LAPB */
129 static int fr_encap
= FRF_3_2
;
131 static const true_false_string ctrl_string
= {
135 static const true_false_string ea_string
= {
141 * This isn't the same as "nlpid_vals[]"; 0x08 is Q.933, not Q.931,
142 * and 0x09 is LMI, not Q.2931, and we assume that it's an initial
143 * protocol identifier, so 0x01 is T.70, not X.29.
145 static const value_string fr_nlpid_vals
[] = {
146 { NLPID_NULL
, "NULL" },
147 { NLPID_IPI_T_70
, "T.70" }, /* XXX - IPI, or SPI? */
148 { NLPID_X_633
, "X.633" },
149 { NLPID_Q_931
, "Q.933" },
150 { NLPID_LMI
, "LMI" },
151 { NLPID_Q_2119
, "Q.2119" },
152 { NLPID_SNAP
, "SNAP" },
153 { NLPID_ISO8473_CLNP
, "CLNP" },
154 { NLPID_ISO9542_ESIS
, "ESIS" },
155 { NLPID_ISO10589_ISIS
, "ISIS" },
156 { NLPID_ISO10747_IDRP
, "IDRP" },
157 { NLPID_ISO9542X25_ESIS
, "ESIS (X.25)" },
158 { NLPID_ISO10030
, "ISO 10030" },
159 { NLPID_ISO11577
, "ISO 11577" },
160 { NLPID_COMPRESSED
, "Data compression protocol" },
162 { NLPID_IP6
, "IPv6" },
163 { NLPID_PPP
, "PPP" },
167 static dissector_table_t fr_subdissector_table
;
168 static dissector_table_t fr_osinl_subdissector_table
;
170 static void dissect_fr_nlpid(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo
,
171 proto_tree
*tree
, proto_item
*ti
,
172 proto_tree
*fr_tree
, uint8_t fr_ctrl
);
173 static void dissect_lapf(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
);
174 static void dissect_fr_xid(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
);
176 /* Used only for U frames */
177 static const xdlc_cf_items fr_cf_items
= {
183 &hf_fr_u_modifier_cmd
,
184 &hf_fr_u_modifier_resp
,
189 /* Used only for I and S frames */
190 static const xdlc_cf_items fr_cf_items_ext
= {
203 capture_fr(const unsigned char *pd
, int offset
, int len
, capture_packet_info_t
*cpinfo
, const union wtap_pseudo_header
*pseudo_header
)
211 * OK, fetch the address field - keep going until we get an EA bit.
213 if (!BYTES_ARE_IN_FRAME(offset
, len
, 1))
216 fr_octet
= pd
[offset
];
217 if (fr_octet
& FRELAY_EA
) {
219 * Bogus! There should be at least 2 octets.
220 * XXX - is this FRF.12 frame relay fragmentation? If so, can
226 * The first octet contains the upper 6 bits of the DLCI, as well
229 addr
= (fr_octet
& FRELAY_UPPER_DLCI
) >> 2;
233 * The second octet contains 4 more bits of DLCI, as well as FECN,
236 if (!BYTES_ARE_IN_FRAME(offset
, len
, 1))
239 fr_octet
= pd
[offset
];
240 addr
= (addr
<< 4) | ((fr_octet
& FRELAY_SECOND_DLCI
) >> 4);
243 if (!(fr_octet
& FRELAY_EA
)) {
245 * We have 3 or more address octets.
247 * The third octet contains 7 more bits of DLCI if EA isn't set,
248 * and lower DLCI or DL-CORE control plus the DLCI or DL-CORE
249 * control indicator flag if EA is set.
251 if (!BYTES_ARE_IN_FRAME(offset
, len
, 1))
254 fr_octet
= pd
[offset
];
255 if (!(fr_octet
& FRELAY_EA
)) {
257 * 7 more bits of DLCI.
259 addr
= (addr
<< 7) | ((fr_octet
& FRELAY_THIRD_DLCI
) >> 1);
261 if (!BYTES_ARE_IN_FRAME(offset
, len
, 1))
264 fr_octet
= pd
[offset
];
265 while (!(fr_octet
& FRELAY_EA
)) {
267 * Bogus! More than 4 octets of address.
270 if (!BYTES_ARE_IN_FRAME(offset
, len
, 1))
273 fr_octet
= pd
[offset
];
278 * Last octet - contains lower DLCI or DL-CORE control, DLCI or
279 * DL-CORE control indicator flag.
281 if (fr_octet
& FRELAY_DC
) {
287 * Last 6 bits of DLCI.
289 addr
= (addr
<< 6) | ((fr_octet
& FRELAY_LOWER_DLCI
) >> 2);
296 if (!BYTES_ARE_IN_FRAME(offset
, len
, 1))
299 fr_ctrl
= pd
[offset
];
300 if (fr_ctrl
== XDLC_U
) {
304 * XXX - treat DLCI 0 specially? On DLCI 0, an NLPID of 0x08
305 * means Q.933, but on other circuits it could be the "for
306 * protocols which do not have an NLPID assigned or do not
307 * have a SNAP encapsulation" stuff from RFC 2427.
309 if (!BYTES_ARE_IN_FRAME(offset
, len
, 1))
312 fr_nlpid
= pd
[offset
];
315 if (!BYTES_ARE_IN_FRAME(offset
, len
, 1))
318 fr_nlpid
= pd
[offset
];
321 return try_capture_dissector("fr.nlpid", fr_nlpid
, pd
, offset
, len
, cpinfo
, pseudo_header
);
325 * This must be some sort of LAPF on DLCI 0 for SVC
326 * because DLCI 0 is reserved for LMI and SVC signaling
327 * encapsulated in LAPF, and LMI is transmitted in
328 * unnumbered information (03), so this must be LAPF
331 * XXX - but what is it? Is Q.933 carried inside UI
332 * frames or other types of frames or both?
336 if (fr_ctrl
== (XDLC_U
|XDLC_XID
)) {
344 * If the data does not start with unnumbered information (03) and
345 * the DLCI# is not 0, then there may be Cisco Frame Relay encapsulation.
347 return call_capture_dissector(chdlc_cap_handle
, pd
, offset
, len
, cpinfo
, pseudo_header
);
356 return call_capture_dissector(eth_cap_handle
, pd
, offset
, len
, cpinfo
, pseudo_header
);
365 dissect_fr_common(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
,
366 bool has_direction
, bool decode_address
)
369 proto_item
*ti
= NULL
;
370 proto_tree
*fr_tree
= NULL
;
371 proto_tree
*octet_tree
= NULL
;
373 bool is_response
= false;
375 bool encap_is_frf_3_2
;
381 dissector_handle_t sub_dissector
;
384 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "FR");
385 col_clear(pinfo
->cinfo
, COL_INFO
);
388 if (pinfo
->pseudo_header
->dte_dce
.flags
& FROM_DCE
) {
389 col_set_str(pinfo
->cinfo
, COL_RES_DL_DST
, "DTE");
390 col_set_str(pinfo
->cinfo
, COL_RES_DL_SRC
, "DCE");
392 col_set_str(pinfo
->cinfo
, COL_RES_DL_DST
, "DCE");
393 col_set_str(pinfo
->cinfo
, COL_RES_DL_SRC
, "DTE");
398 ti
= proto_tree_add_protocol_format(tree
, proto_fr
, tvb
, 0, -1, "Frame Relay");
399 fr_tree
= proto_item_add_subtree(ti
, ett_fr
);
405 * OK, fetch the address field - keep going until we get an EA bit.
407 fr_octet
= tvb_get_uint8(tvb
, offset
);
409 if (fr_octet
& FRELAY_EA
) {
411 * Bogus! There should be at least 2 octets.
412 * XXX - is this FRF.12 frame relay fragmentation? If so, we
413 * should dissect it as such, if possible.
416 proto_tree_add_expert_format(fr_tree
, pinfo
, &ei_fr_bogus_address
, tvb
, offset
, 1,
417 "Bogus 1-octet address field");
420 static int * const first_address_bits
[] = {&hf_fr_upper_dlci
, &hf_fr_cr
, &hf_fr_ea
, NULL
};
421 static int * const second_address_bits
[] = {&hf_fr_second_dlci
, &hf_fr_fecn
,
422 &hf_fr_becn
, &hf_fr_de
, &hf_fr_ea
, NULL
};
423 static int * const third_address_bits
[] = {&hf_fr_third_dlci
, &hf_fr_ea
, NULL
};
426 * The first octet contains the upper 6 bits of the DLCI, as well
429 addr
= (fr_octet
& FRELAY_UPPER_DLCI
) >> 2;
430 is_response
= (fr_octet
& FRELAY_CR
);
432 proto_tree_add_bitmask(fr_tree
, tvb
, offset
, hf_fr_first_addr_octet
,
433 ett_fr_address
, first_address_bits
, ENC_NA
);
437 * The second octet contains 4 more bits of DLCI, as well as FECN,
440 fr_octet
= tvb_get_uint8(tvb
, offset
);
441 addr
= (addr
<< 4) | ((fr_octet
& FRELAY_SECOND_DLCI
) >> 4);
442 proto_tree_add_bitmask(fr_tree
, tvb
, offset
, hf_fr_second_addr_octet
,
443 ett_fr_address
, second_address_bits
, ENC_NA
);
446 if (!(fr_octet
& FRELAY_EA
)) {
448 * We have 3 or more address octets.
450 * The third octet contains 7 more bits of DLCI if EA isn't set,
451 * and lower DLCI or DL-CORE control plus the DLCI or DL-CORE
452 * control indicator flag if EA is set.
454 fr_octet
= tvb_get_uint8(tvb
, offset
);
455 if (!(fr_octet
& FRELAY_EA
)) {
457 * 7 more bits of DLCI.
459 addr
= (addr
<< 7) | ((fr_octet
& FRELAY_THIRD_DLCI
) >> 1);
460 proto_tree_add_bitmask(fr_tree
, tvb
, offset
, hf_fr_third_addr_octet
,
461 ett_fr_address
, third_address_bits
, ENC_NA
);
463 fr_octet
= tvb_get_uint8(tvb
, offset
);
464 while (!(fr_octet
& FRELAY_EA
)) {
466 * Bogus! More than 4 octets of address.
468 proto_tree_add_expert_format(fr_tree
, pinfo
, &ei_fr_bogus_address
, tvb
, offset
, 1,
469 "Bogus extra address octet");
471 fr_octet
= tvb_get_uint8(tvb
, offset
);
475 octet_tree
= proto_tree_add_subtree_format(fr_tree
, tvb
, offset
, 1,
476 ett_fr_address
, NULL
, "Final address octet: 0x%02x",
480 * Last octet - contains lower DLCI or DL-CORE control, DLCI or
481 * DL-CORE control indicator flag.
483 if (fr_octet
& FRELAY_DC
) {
487 proto_tree_add_uint(octet_tree
, hf_fr_dlcore_control
, tvb
, offset
, 1, fr_octet
);
490 * Last 6 bits of DLCI.
492 addr
= (addr
<< 6) | ((fr_octet
& FRELAY_LOWER_DLCI
) >> 2);
493 proto_tree_add_uint(octet_tree
, hf_fr_lower_dlci
, tvb
, offset
, 1, fr_octet
);
495 proto_tree_add_boolean(octet_tree
, hf_fr_dc
, tvb
, offset
, 1, fr_octet
);
496 proto_tree_add_boolean(octet_tree
, hf_fr_ea
, tvb
, offset
, 1, fr_octet
);
502 /* Put the full DLCI into the protocol tree. */
503 proto_tree_add_uint(fr_tree
, hf_fr_dlci
, tvb
, 0, offset
, addr
);
506 conversation_set_elements_by_id(pinfo
, CONVERSATION_DLCI
, addr
);
507 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "DLCI %u", addr
);
513 encap_is_frf_3_2
= false;
514 fr_ctrl
= tvb_get_uint8(tvb
, offset
);
515 if (fr_ctrl
== XDLC_U
) {
517 * It looks like an RFC 2427-encapsulation frame, with the
518 * default UI control field.
520 encap_is_frf_3_2
= true;
524 * This must be some sort of LAPF on DLCI 0 for SVC
525 * because DLCI 0 is reserved for LMI and SVC signaling
526 * encapsulated in LAPF, and LMI is transmitted in
527 * unnumbered information (03), so this must be LAPF
530 * XXX - but what is it? Is Q.933 carried inside UI
531 * frames or other types of frames or both?
533 dissect_xdlc_control(tvb
, offset
, pinfo
, fr_tree
,
534 hf_fr_control
, ett_fr_control
,
535 &fr_cf_items
, &fr_cf_items_ext
,
536 NULL
, NULL
, is_response
, true, true);
537 dissect_lapf(tvb_new_subset_remaining(tvb
,offset
),pinfo
,tree
);
540 if (fr_ctrl
== (XDLC_U
|XDLC_XID
)) {
542 * It looks like an RFC 2427-encapsulation frame, with the
543 * a UI control field and an XID command.
545 dissect_xdlc_control(tvb
, offset
, pinfo
, fr_tree
,
546 hf_fr_control
, ett_fr_control
,
547 &fr_cf_items
, &fr_cf_items_ext
,
548 NULL
, NULL
, is_response
, true, true);
549 dissect_fr_xid(tvb_new_subset_remaining(tvb
,offset
),pinfo
,tree
);
554 * If the data does not start with unnumbered information (03) and
555 * the DLCI# is not 0, then there may be Cisco Frame Relay encapsulation.
556 * See if, were we to treat the two octets after the DLCI as a Cisco
557 * HDLC type, we have a dissector for it.
559 if (tvb_bytes_exist(tvb
, offset
, 2)) {
560 fr_type
= tvb_get_ntohs(tvb
, offset
);
561 sub_dissector
= dissector_get_uint_handle(chdlc_subdissector_table
,
563 if (sub_dissector
!= NULL
) {
564 /* We have a dissector, so assume it's Cisco encapsulation. */
566 /* Include the Cisco HDLC type in the top-level protocol
568 proto_item_set_end(ti
, tvb
, offset
+2);
570 chdlctype(sub_dissector
, fr_type
, tvb
, offset
+2, pinfo
, tree
, fr_tree
,
576 * We don't have a dissector; this might be an RFC 2427-encapsulated
577 * See if we have a dissector for the putative NLPID.
579 nlpid_offset
= offset
;
580 control
= tvb_get_uint8(tvb
, nlpid_offset
);
582 /* Presumably a padding octet; the NLPID would be in the next octet. */
584 control
= tvb_get_uint8(tvb
, nlpid_offset
);
586 switch (control
& 0x03) {
591 * We assume we're in extended mode, with 2-octet supervisory
601 * XXX - one octet or 2 in extended mode?
609 * We assume we're in extended mode, with 2-octet supervisory
615 if (tvb_bytes_exist(tvb
, nlpid_offset
, 1)) {
616 fr_nlpid
= tvb_get_uint8(tvb
, nlpid_offset
);
617 sub_dissector
= dissector_get_uint_handle(fr_osinl_subdissector_table
,
619 if (sub_dissector
!= NULL
)
620 encap_is_frf_3_2
= true;
622 sub_dissector
= dissector_get_uint_handle(osinl_incl_subdissector_table
,
624 if (sub_dissector
!= NULL
)
625 encap_is_frf_3_2
= true;
627 if (fr_nlpid
== NLPID_SNAP
)
628 encap_is_frf_3_2
= true;
630 sub_dissector
= dissector_get_uint_handle(fr_subdissector_table
,
632 if (sub_dissector
!= NULL
)
633 encap_is_frf_3_2
= true;
641 if (encap_is_frf_3_2
) {
643 * We appear to have an NLPID for this dissector, so dissect
646 control
= dissect_xdlc_control(tvb
, offset
, pinfo
, fr_tree
,
647 hf_fr_control
, ett_fr_control
,
648 &fr_cf_items
, &fr_cf_items_ext
,
649 NULL
, NULL
, is_response
, true, true);
650 offset
+= XDLC_CONTROL_LEN(control
, true);
653 * XXX - treat DLCI 0 specially? On DLCI 0, an NLPID of 0x08
654 * means Q.933, but on other circuits it could be the "for
655 * protocols which do not have an NLPID assigned or do not
656 * have a SNAP encapsulation" stuff from RFC 2427.
658 dissect_fr_nlpid(tvb
, offset
, pinfo
, tree
, ti
, fr_tree
, fr_ctrl
);
661 * See if it looks like raw Ethernet.
663 uint16_t type_length
;
665 if (tvb_bytes_exist(tvb
, offset
+ 12, 2) &&
666 ((type_length
= tvb_get_ntohs(tvb
, offset
+ 12)) <= IEEE_802_3_MAX_LEN
||
667 dissector_get_uint_handle(ethertype_subdissector_table
, type_length
) != NULL
)) {
668 /* It looks like a length or is a known Ethertype; dissect as raw Etheret */
669 next_tvb
= tvb_new_subset_remaining(tvb
, offset
);
670 call_dissector(eth_withfcs_handle
, next_tvb
, pinfo
, tree
);
673 /* It doesn't - just dissect it as data. */
674 next_tvb
= tvb_new_subset_remaining(tvb
, offset
);
675 call_data_dissector(next_tvb
, pinfo
, tree
);
682 fr_ctrl
= tvb_get_uint8(tvb
, offset
);
683 control
= dissect_xdlc_control(tvb
, offset
, pinfo
, fr_tree
,
684 hf_fr_control
, ett_fr_control
,
685 &fr_cf_items
, &fr_cf_items_ext
,
686 NULL
, NULL
, is_response
, true, true);
687 offset
+= XDLC_CONTROL_LEN(control
, true);
688 dissect_fr_nlpid(tvb
, offset
, pinfo
, tree
, ti
, fr_tree
, fr_ctrl
);
690 next_tvb
= tvb_new_subset_remaining(tvb
, offset
);
691 call_dissector(gprs_ns_handle
, next_tvb
, pinfo
, tree
);
696 next_tvb
= tvb_new_subset_remaining(tvb
, offset
);
698 call_dissector(eth_withfcs_handle
, next_tvb
, pinfo
, tree
);
700 dissect_lapf(next_tvb
, pinfo
, tree
);
704 next_tvb
= tvb_new_subset_remaining(tvb
, offset
);
706 call_dissector(lapb_handle
, next_tvb
, pinfo
, tree
);
708 dissect_lapf(next_tvb
, pinfo
, tree
);
714 dissect_fr(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
716 dissect_fr_common(tvb
, pinfo
, tree
, false, true );
717 return tvb_captured_length(tvb
);
721 dissect_fr_phdr(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
723 dissect_fr_common(tvb
, pinfo
, tree
, true, true );
724 return tvb_captured_length(tvb
);
728 dissect_fr_stripped_address(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
730 dissect_fr_common(tvb
, pinfo
, tree
, true, false );
731 return tvb_captured_length(tvb
);
735 dissect_fr_uncompressed(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
740 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "FR");
741 col_clear(pinfo
->cinfo
, COL_INFO
);
743 ti
= proto_tree_add_protocol_format(tree
, proto_fr
, tvb
, 0, -1, "Frame Relay");
744 fr_tree
= proto_item_add_subtree(ti
, ett_fr
);
746 dissect_fr_nlpid(tvb
, 0, pinfo
, tree
, ti
, fr_tree
, XDLC_U
);
747 return tvb_captured_length(tvb
);
751 dissect_fr_nlpid(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo
,
752 proto_tree
*tree
, proto_item
*ti
,
753 proto_tree
*fr_tree
, uint8_t fr_ctrl
)
759 * Tentatively set the Frame Relay item not to include the NLPID,
760 * as OSI network layer protocols consider it to be part of
763 proto_item_set_end(ti
, tvb
, offset
);
764 fr_nlpid
= tvb_get_uint8 (tvb
,offset
);
766 proto_tree_add_uint_format(fr_tree
, hf_fr_nlpid
, tvb
, offset
, 1, fr_nlpid
, "Padding");
769 /* Include the padding in the top-level protocol tree item. */
770 proto_item_set_end(ti
, tvb
, offset
);
772 fr_nlpid
=tvb_get_uint8( tvb
,offset
);
776 * OSI network layer protocols consider the NLPID to be part
777 * of the frame, so we'll pass it as part of the payload and,
778 * if the protocol is one of those, add it as a hidden item here.
779 * We check both the generic OSI NLPID dissector table and
780 * the Frame Relay OSI NLPID dissector table - the latter is for
781 * NLPID's such as 0x08, which is Q.933 in Frame Relay but
782 * other protocols (e.g., Q.931) on other network layers.
784 * "OSI network layer protocols" includes Q.933.
786 * We check the Frame Relay table first, so that protocols for which
787 * the NLPID means something different on Frame Relay, i.e. Q.933 vs.
788 * Q.931, are handled appropriately for Frame Relay.
790 * XXX - note that an NLPID of 0x08 for Q.933 could either be a
791 * Q.933 signaling message or a message for a protocol
792 * identified by a 2-octet layer 2 protocol type and a
793 * 2-octet layer 3 protocol type, those protocol type
794 * octets having the values from octets 6, 6a, 7, and 7a
795 * of a Q.931 low layer compatibility information element
796 * (section 4.5.19 of Q.931; Q.933 says they have the values
797 * from a Q.933 low layer compatibility information element,
798 * but Q.933 low layer compatibility information elements
799 * don't have protocol values in them).
801 * Assuming that, as Q.933 seems to imply, that Q.933 messages
802 * look just like Q.931 messages except where it explicitly
803 * says they differ, then the octet after the NLPID would,
804 * in a Q.933 message, have its upper 4 bits zero (that's
805 * the length of the call reference value, in Q.931, and
806 * is limited to 15 or fewer octets). As appears to be the case,
807 * octet 6 of a Q.931 low layer compatibility element has the
808 * 0x40 bit set, so you can distinguish between a Q.933
809 * message and an encapsulated packet by checking whether
810 * the upper 4 bits of the octet after the NLPID are zero.
812 * Either that, or it's Q.933 iff the DLCI is 0.
814 next_tvb
= tvb_new_subset_remaining(tvb
,offset
);
815 if (dissector_try_uint(fr_osinl_subdissector_table
, fr_nlpid
, next_tvb
,
817 dissector_try_uint(osinl_incl_subdissector_table
, fr_nlpid
, next_tvb
,
820 * Yes, we got a match. Add the NLPID as a hidden item,
821 * so you can, at least, filter on it.
824 proto_item
*hidden_item
;
825 hidden_item
= proto_tree_add_uint(fr_tree
, hf_fr_nlpid
,
826 tvb
, offset
, 1, fr_nlpid
);
827 proto_item_set_hidden(hidden_item
);
833 * All other protocols don't.
835 * XXX - what about Cisco/Gang-of-Four LMI? Is the 0x09 considered
836 * to be part of the LMI PDU?
839 proto_tree_add_uint(fr_tree
, hf_fr_nlpid
, tvb
, offset
, 1, fr_nlpid
);
846 /* Include the NLPID and SNAP header in the top-level
847 protocol tree item. */
848 proto_item_set_end(ti
, tvb
, offset
+5);
850 dissect_snap(tvb
, offset
, pinfo
, tree
, fr_tree
, fr_ctrl
,
851 hf_fr_oui
, hf_fr_snaptype
, hf_fr_pid
, 0);
856 /* Include the NLPID in the top-level protocol tree item. */
857 proto_item_set_end(ti
, tvb
, offset
);
859 next_tvb
= tvb_new_subset_remaining(tvb
,offset
);
860 if (!dissector_try_uint(fr_subdissector_table
,fr_nlpid
,
861 next_tvb
, pinfo
, tree
))
862 call_dissector(data_handle
,next_tvb
, pinfo
, tree
);
868 dissect_lapf(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
870 proto_tree_add_expert(tree
, pinfo
, &ei_fr_frame_relay_lapf
, tvb
, 0, 0);
871 call_dissector(data_handle
,tvb_new_subset_remaining(tvb
,0),pinfo
,tree
);
875 dissect_fr_xid(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
877 proto_tree_add_expert(tree
, pinfo
, &ei_fr_frame_relay_xid
, tvb
, 0, 0);
878 call_dissector(data_handle
,tvb_new_subset_remaining(tvb
,0),pinfo
,tree
);
881 /* Register the protocol with Wireshark */
883 proto_register_fr(void)
885 static hf_register_info hf
[] = {
888 FT_BOOLEAN
, 8, TFS(&ea_string
), FRELAY_EA
,
889 "Extended Address", HFILL
}},
892 { "Upper DLCI", "fr.upper_dlci",
893 FT_UINT8
, BASE_HEX
, NULL
, FRELAY_UPPER_DLCI
,
894 "Upper bits of DLCI", HFILL
}},
898 FT_BOOLEAN
, 8, TFS(&tfs_command_response
), FRELAY_CR
,
899 "Command/Response", HFILL
}},
901 { &hf_fr_second_dlci
,
902 { "Second DLCI", "fr.second_dlci",
903 FT_UINT8
, BASE_HEX
, NULL
, FRELAY_SECOND_DLCI
,
904 "Bits below upper bits of DLCI", HFILL
}},
908 FT_BOOLEAN
, 8, NULL
, FRELAY_FECN
,
909 "Forward Explicit Congestion Notification", HFILL
}},
913 FT_BOOLEAN
, 8, NULL
, FRELAY_BECN
,
914 "Backward Explicit Congestion Notification", HFILL
}},
918 FT_BOOLEAN
, 8, NULL
, FRELAY_DE
,
919 "Discard Eligibility", HFILL
}},
922 { "Third DLCI", "fr.third_dlci",
923 FT_UINT8
, BASE_HEX
, NULL
, FRELAY_THIRD_DLCI
,
924 "Additional bits of DLCI", HFILL
}},
926 { &hf_fr_dlcore_control
,
927 { "DL-CORE Control", "fr.dlcore_control",
928 FT_UINT8
, BASE_HEX
, NULL
, FRELAY_LOWER_DLCI
,
929 "DL-Core control bits", HFILL
}},
932 { "Lower DLCI", "fr.lower_dlci",
933 FT_UINT8
, BASE_HEX
, NULL
, FRELAY_LOWER_DLCI
,
934 "Lower bits of DLCI", HFILL
}},
938 FT_BOOLEAN
, 8, TFS(&ctrl_string
), FRELAY_DC
,
939 "Address/Control", HFILL
}},
943 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
944 "Data-Link Connection Identifier", HFILL
}},
947 { "Control Field", "fr.control",
948 FT_UINT8
, BASE_HEX
, NULL
, 0x0,
952 { "N(R)", "fr.control.n_r",
953 FT_UINT16
, BASE_DEC
, NULL
, XDLC_N_R_EXT_MASK
,
957 { "N(S)", "fr.control.n_s",
958 FT_UINT16
, BASE_DEC
, NULL
, XDLC_N_S_EXT_MASK
,
962 { "Poll", "fr.control.p",
963 FT_BOOLEAN
, 8, TFS(&tfs_set_notset
), XDLC_P_F
,
967 { "Poll", "fr.control.p",
968 FT_BOOLEAN
, 16, TFS(&tfs_set_notset
), XDLC_P_F_EXT
,
972 { "Final", "fr.control.f",
973 FT_BOOLEAN
, 8, TFS(&tfs_set_notset
), XDLC_P_F
,
977 { "Final", "fr.control.f",
978 FT_BOOLEAN
, 16, TFS(&tfs_set_notset
), XDLC_P_F_EXT
,
982 { "Supervisory frame type", "fr.control.s_ftype",
983 FT_UINT16
, BASE_HEX
, VALS(stype_vals
), XDLC_S_FTYPE_MASK
,
986 { &hf_fr_u_modifier_cmd
,
987 { "Command", "fr.control.u_modifier_cmd",
988 FT_UINT8
, BASE_HEX
, VALS(modifier_vals_cmd
), XDLC_U_MODIFIER_MASK
,
991 { &hf_fr_u_modifier_resp
,
992 { "Response", "fr.control.u_modifier_resp",
993 FT_UINT8
, BASE_HEX
, VALS(modifier_vals_resp
), XDLC_U_MODIFIER_MASK
,
997 { "Frame type", "fr.control.ftype",
998 FT_UINT16
, BASE_HEX
, VALS(ftype_vals
), XDLC_I_MASK
,
1002 { "Frame type", "fr.control.ftype",
1003 FT_UINT8
, BASE_HEX
, VALS(ftype_vals
), XDLC_S_U_MASK
,
1006 { &hf_fr_ftype_s_u_ext
,
1007 { "Frame type", "fr.control.ftype",
1008 FT_UINT16
, BASE_HEX
, VALS(ftype_vals
), XDLC_S_U_MASK
,
1012 { "NLPID", "fr.nlpid",
1013 FT_UINT8
, BASE_HEX
, VALS(fr_nlpid_vals
), 0x0,
1014 "Frame Relay Encapsulated Protocol NLPID", HFILL
}},
1017 { "Organization Code", "fr.snap.oui",
1018 FT_UINT24
, BASE_OUI
, NULL
, 0x0,
1022 { "Protocol ID", "fr.snap.pid",
1023 FT_UINT16
, BASE_HEX
, NULL
, 0x0,
1027 { "Type", "fr.snaptype",
1028 FT_UINT16
, BASE_HEX
, VALS(etype_vals
), 0x0,
1029 "Frame Relay SNAP Encapsulated Protocol", HFILL
}},
1032 { "Type", "fr.chdlctype",
1033 FT_UINT16
, BASE_HEX
, VALS(chdlc_vals
), 0x0,
1034 "Frame Relay Cisco HDLC Encapsulated Protocol", HFILL
}},
1036 { &hf_fr_first_addr_octet
,
1037 { "First address octet", "fr.first_addr_octet",
1038 FT_UINT8
, BASE_HEX
, NULL
, 0x0,
1041 { &hf_fr_second_addr_octet
,
1042 { "Second address octet", "fr.second_addr_octet",
1043 FT_UINT8
, BASE_HEX
, NULL
, 0x0,
1046 { &hf_fr_third_addr_octet
,
1047 { "Third address octet", "fr.third_addr_octet",
1048 FT_UINT8
, BASE_HEX
, NULL
, 0x0,
1053 /* Setup protocol subtree array */
1054 static int *ett
[] = {
1059 static ei_register_info ei
[] = {
1060 { &ei_fr_bogus_address
, { "fr.bogus_address", PI_PROTOCOL
, PI_WARN
, "Bogus address", EXPFILL
}},
1061 { &ei_fr_frame_relay_lapf
, { "fr.frame_relay.lapf", PI_UNDECODED
, PI_WARN
, "Frame relay lapf not yet implemented", EXPFILL
}},
1062 { &ei_fr_frame_relay_xid
, { "fr.frame_relay.xid", PI_UNDECODED
, PI_WARN
, "Frame relay xid not yet implemented", EXPFILL
}},
1065 static const enum_val_t fr_encap_options
[] = {
1066 { "frf-3.2", "FRF 3.2/Cisco HDLC", FRF_3_2
},
1067 { "gprs-ns", "GPRS Network Service", GPRS_NS
},
1068 { "ethernet", "Raw Ethernet", RAW_ETHER
},
1069 { "lapb", "LAPB (T1.617a-1994 Annex G)", LAPB
},
1072 module_t
*frencap_module
;
1073 expert_module_t
* expert_fr
;
1075 proto_fr
= proto_register_protocol("Frame Relay", "FR", "fr");
1076 proto_register_field_array(proto_fr
, hf
, array_length(hf
));
1077 proto_register_subtree_array(ett
, array_length(ett
));
1078 expert_fr
= expert_register_protocol(proto_fr
);
1079 expert_register_field_array(expert_fr
, ei
, array_length(ei
));
1081 fr_subdissector_table
= register_dissector_table("fr.nlpid",
1082 "Frame Relay NLPID", proto_fr
, FT_UINT8
, BASE_HEX
);
1083 fr_osinl_subdissector_table
= register_dissector_table("fr.osinl",
1084 "Frame Relay OSI NLPID", proto_fr
, FT_UINT8
, BASE_HEX
);
1086 register_dissector("fr_uncompressed", dissect_fr_uncompressed
, proto_fr
);
1087 fr_handle
= register_dissector("fr", dissect_fr
, proto_fr
);
1088 register_dissector("fr_stripped_address", dissect_fr_stripped_address
, proto_fr
);
1090 frencap_module
= prefs_register_protocol(proto_fr
, NULL
);
1092 * XXX - this should really be per-circuit - I've seen at least one
1093 * capture where different DLCIs have different encapsulations - but
1094 * we don't yet have any support for per-circuit encapsulations.
1096 * Even with that, though, we might want a default encapsulation,
1097 * so that people dealing with GPRS can make gprs-ns the default.
1099 prefs_register_enum_preference(frencap_module
, "encap", "Encapsulation",
1100 "Encapsulation", &fr_encap
,
1101 fr_encap_options
, false);
1103 register_capture_dissector_table("fr.nlpid", "Frame Relay NLPID");
1107 proto_reg_handoff_fr(void)
1109 dissector_handle_t fr_phdr_handle
;
1110 capture_dissector_handle_t fr_cap_handle
;
1112 dissector_add_uint("gre.proto", ETHERTYPE_RAW_FR
, fr_handle
);
1113 dissector_add_uint("wtap_encap", WTAP_ENCAP_FRELAY
, fr_handle
);
1114 dissector_add_uint("juniper.proto", JUNIPER_PROTO_FRELAY
, fr_handle
);
1115 dissector_add_uint("sflow_245.header_protocol", SFLOW_245_HEADER_FRAME_RELAY
, fr_handle
);
1116 dissector_add_uint("atm.aal5.type", TRAF_FR
, fr_handle
);
1117 dissector_add_uint("l2tp.pw_type", L2TPv3_PW_FR
, fr_handle
);
1118 dissector_add_uint("sll.hatype", ARPHRD_FRAD
, fr_handle
);
1120 fr_phdr_handle
= create_dissector_handle(dissect_fr_phdr
, proto_fr
);
1121 dissector_add_uint("wtap_encap", WTAP_ENCAP_FRELAY_WITH_PHDR
, fr_phdr_handle
);
1123 fr_cap_handle
= create_capture_dissector_handle(capture_fr
, proto_fr
);
1124 capture_dissector_add_uint("wtap_encap", WTAP_ENCAP_FRELAY
, fr_cap_handle
);
1125 capture_dissector_add_uint("wtap_encap", WTAP_ENCAP_FRELAY_WITH_PHDR
, fr_cap_handle
);
1127 eth_withfcs_handle
= find_dissector_add_dependency("eth_withfcs", proto_fr
);
1128 gprs_ns_handle
= find_dissector_add_dependency("gprs_ns", proto_fr
);
1129 lapb_handle
= find_dissector_add_dependency("lapb", proto_fr
);
1130 data_handle
= find_dissector_add_dependency("data", proto_fr
);
1132 chdlc_subdissector_table
= find_dissector_table("chdlc.protocol");
1133 osinl_incl_subdissector_table
= find_dissector_table("osinl.incl");
1134 ethertype_subdissector_table
= find_dissector_table("ethertype");
1136 chdlc_cap_handle
= find_capture_dissector("chdlc");
1137 eth_cap_handle
= find_capture_dissector("eth");
1141 * Editor modelines - https://www.wireshark.org/tools/modelines.html
1146 * indent-tabs-mode: nil
1149 * ex: set shiftwidth=2 tabstop=8 expandtab:
1150 * :indentSize=2:tabSize=8:noTabs=true: