2 * Routines for Frame Relay dissection
4 * Copyright 2001, Paul Ionescu <paul@acorp.ro>
6 * $Id: packet-fr.c,v 1.34 2003/04/29 17:56:47 guy Exp $
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 * http://www.protocols.com/pbook/frame.htm
29 * http://www.frforum.com/5000/Approved/FRF.3/FRF.3.2.pdf
30 * ITU Recommendation Q.933
34 * http://www.trillium.com/whats-new/wp_frmrly.html
47 #include <epan/packet.h>
48 #include "packet-llc.h"
49 #include "packet-chdlc.h"
55 #include <epan/conversation.h>
58 * Bits in the address field.
60 #define FRELAY_DLCI 0xfcf0 /* 2 byte DLCI Address */
61 #define FRELAY_CR 0x0200 /* Command/Response bit */
62 #define FRELAY_EA 0x0001 /* Address Extension bit */
63 #define FRELAY_FECN 0x0008 /* Forward Explicit Congestion Notification */
64 #define FRELAY_BECN 0x0004 /* Backward Explicit Congestion Notification */
65 #define FRELAY_DE 0x0002 /* Discard Eligibility */
66 #define FRELAY_DC 0x0002 /* Control bits */
69 * Extract the DLCI from the address field.
71 #define EXTRACT_DLCI(addr) ((((addr)&0xfc00) >> 6) | (((addr)&0xf0) >> 4))
73 #define FROM_DCE 0x80 /* for direction setting */
75 static gint proto_fr = -1;
76 static gint ett_fr = -1;
77 static gint hf_fr_dlci = -1;
78 static gint hf_fr_cr = -1;
79 static gint hf_fr_becn = -1;
80 static gint hf_fr_fecn = -1;
81 static gint hf_fr_de = -1;
82 static gint hf_fr_ea = -1;
83 static gint hf_fr_dc = -1;
84 static gint hf_fr_nlpid = -1;
85 static gint hf_fr_oui = -1;
86 static gint hf_fr_pid = -1;
87 static gint hf_fr_snaptype = -1;
88 static gint hf_fr_chdlctype = -1;
90 static dissector_handle_t data_handle;
92 static dissector_table_t osinl_subdissector_table;
94 static const true_false_string cmd_string = {
98 static const true_false_string ctrl_string = {
102 static const true_false_string ea_string = {
108 * This isn't the same as "nlpid_vals[]"; 0x08 is Q.933, not Q.931,
109 * and 0x09 is LMI, not Q.2931, and we assume that it's an initial
110 * protocol identifier, so 0x01 is T.70, not X.29.
112 static const value_string fr_nlpid_vals[] = {
113 { NLPID_NULL, "NULL" },
114 { NLPID_IPI_T_70, "T.70" }, /* XXX - IPI, or SPI? */
115 { NLPID_X_633, "X.633" },
116 { NLPID_Q_931, "Q.933" },
117 { NLPID_LMI, "LMI" },
118 { NLPID_Q_2119, "Q.2119" },
119 { NLPID_SNAP, "SNAP" },
120 { NLPID_ISO8473_CLNP, "CLNP" },
121 { NLPID_ISO9542_ESIS, "ESIS" },
122 { NLPID_ISO10589_ISIS, "ISIS" },
123 { NLPID_ISO10747_IDRP, "IDRP" },
124 { NLPID_ISO9542X25_ESIS, "ESIS (X.25)" },
125 { NLPID_ISO10030, "ISO 10030" },
126 { NLPID_ISO11577, "ISO 11577" },
127 { NLPID_COMPRESSED, "Data compression protocol" },
129 { NLPID_IP6, "IPv6" },
130 { NLPID_PPP, "PPP" },
134 static dissector_table_t fr_subdissector_table;
136 static void dissect_fr_nlpid(tvbuff_t *tvb, int offset, packet_info *pinfo,
137 proto_tree *tree, proto_item *ti,
138 proto_tree *fr_tree, guint8 fr_ctrl);
139 static void dissect_lapf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
140 static void dissect_fr_xid(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
142 static void dissect_fr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
144 proto_item *ti = NULL;
145 proto_tree *fr_tree = NULL;
146 guint16 fr_header,fr_type,offset=2; /* default header length of FR is 2 bytes */
151 if (check_col(pinfo->cinfo, COL_PROTOCOL))
152 col_set_str(pinfo->cinfo, COL_PROTOCOL, "FR");
154 if (pinfo->pseudo_header->x25.flags & FROM_DCE) {
155 if(check_col(pinfo->cinfo, COL_RES_DL_DST))
156 col_set_str(pinfo->cinfo, COL_RES_DL_DST, "DTE");
157 if(check_col(pinfo->cinfo, COL_RES_DL_SRC))
158 col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "DCE");
161 if(check_col(pinfo->cinfo, COL_RES_DL_DST))
162 col_set_str(pinfo->cinfo, COL_RES_DL_DST, "DCE");
163 if(check_col(pinfo->cinfo, COL_RES_DL_SRC))
164 col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "DTE");
167 /*XXX We should check the EA bits and use that to generate the address. */
169 fr_header = tvb_get_ntohs(tvb, 0);
170 fr_ctrl = tvb_get_guint8( tvb, 2);
171 address = EXTRACT_DLCI(fr_header);
172 pinfo->ctype = CT_DLCI;
173 pinfo->circuit_id = address;
175 if (check_col(pinfo->cinfo, COL_INFO))
176 col_add_fstr(pinfo->cinfo, COL_INFO, "DLCI %u", address);
179 ti = proto_tree_add_protocol_format(tree, proto_fr, tvb, 0, 3, "Frame Relay");
180 fr_tree = proto_item_add_subtree(ti, ett_fr);
182 decode_bitfield_value(buf, fr_header, FRELAY_DLCI, 16);
183 proto_tree_add_uint_format(fr_tree, hf_fr_dlci, tvb, 0, 2, address,
184 "%sDLCI: %u", buf, address);
185 proto_tree_add_boolean(fr_tree, hf_fr_cr, tvb, 0, offset, fr_header);
186 proto_tree_add_boolean(fr_tree, hf_fr_fecn, tvb, 0, offset, fr_header);
187 proto_tree_add_boolean(fr_tree, hf_fr_becn, tvb, 0, offset, fr_header);
188 proto_tree_add_boolean(fr_tree, hf_fr_de, tvb, 0, offset, fr_header);
189 proto_tree_add_boolean(fr_tree, hf_fr_ea, tvb, 0, offset, fr_header);
192 if (fr_ctrl == XDLC_U) {
194 proto_tree_add_text(fr_tree, tvb, offset, 0, "------- Q.933 Encapsulation -------");
196 * XXX - if we're going to show this as Unnumbered
197 * Information, should we just hand it to
198 * "dissect_xdlc_control()"?
200 proto_tree_add_text(fr_tree, tvb, offset, 1, "Unnumbered Information");
204 dissect_fr_nlpid(tvb, offset, pinfo, tree, ti, fr_tree, fr_ctrl);
207 /* this must be some sort of lapf on DLCI 0 for SVC */
208 /* because DLCI 0 is rezerved for LMI and SVC signaling encaplulated in lapf */
209 /* and LMI is transmitted in unnumbered information (03) */
210 /* so this must be lapf (guessing) */
211 dissect_lapf(tvb_new_subset(tvb,offset,-1,-1),pinfo,tree);
214 if (fr_ctrl == (XDLC_U|XDLC_XID)) {
215 dissect_fr_xid(tvb_new_subset(tvb,offset,-1,-1),pinfo,tree);
220 * If the data does not start with unnumbered information (03) and
221 * the DLCI# is not 0, then there may be Cisco Frame Relay encapsulation.
223 proto_tree_add_text(fr_tree, tvb, offset, 0, "------- Cisco Encapsulation -------");
224 fr_type = tvb_get_ntohs(tvb, offset);
226 /* Include the Cisco HDLC type in the top-level protocol
228 proto_item_set_len(ti, offset+2);
230 chdlctype(fr_type, tvb, offset+2, pinfo, tree, fr_tree, hf_fr_chdlctype);
235 static void dissect_fr_uncompressed(tvbuff_t *tvb, packet_info *pinfo,
238 proto_item *ti = NULL;
239 proto_tree *fr_tree = NULL;
241 if (check_col(pinfo->cinfo, COL_PROTOCOL))
242 col_set_str(pinfo->cinfo, COL_PROTOCOL, "FR");
243 if (check_col(pinfo->cinfo, COL_INFO))
244 col_clear(pinfo->cinfo, COL_INFO);
247 ti = proto_tree_add_protocol_format(tree, proto_fr, tvb, 0, 4, "Frame Relay");
248 fr_tree = proto_item_add_subtree(ti, ett_fr);
250 dissect_fr_nlpid(tvb, 0, pinfo, tree, ti, fr_tree, XDLC_U);
253 static void dissect_fr_nlpid(tvbuff_t *tvb, int offset, packet_info *pinfo,
254 proto_tree *tree, proto_item *ti,
255 proto_tree *fr_tree, guint8 fr_ctrl)
260 fr_nlpid = tvb_get_guint8 (tvb,offset);
263 proto_tree_add_text(fr_tree, tvb, offset, 1, "Padding");
266 /* Include the padding in the top-level protocol tree item. */
267 proto_item_set_len(ti, offset);
269 fr_nlpid=tvb_get_guint8( tvb,offset);
273 * OSI network layer protocols consider the NLPID to be part
274 * of the frame, so we'll pass it as part of the payload and,
275 * if the protocol is one of those, add it as a hidden item here.
277 next_tvb = tvb_new_subset(tvb,offset,-1,-1);
278 if (dissector_try_port(osinl_subdissector_table, fr_nlpid, next_tvb,
281 * Yes, we got a match. Add the NLPID as a hidden item,
282 * so you can, at least, filter on it.
285 proto_tree_add_uint_hidden(fr_tree, hf_fr_nlpid,
286 tvb, offset, 1, fr_nlpid );
291 * All other protocols don't.
293 * XXX - not true for Q.933 and LMI, but we don't yet have a
294 * Q.933 dissector (it'd be similar to the Q.931 dissector,
295 * but I don't think it'd be identical, although it's less
296 * different than is the Q.2931 dissector), and the LMI
297 * dissector doesn't yet put the protocol discriminator
298 * (NLPID) into the tree.
300 * Note that an NLPID of 0x08 for Q.933 could either be a
301 * Q.933 signaling message or a message for a protocol
302 * identified by a 2-octet layer 2 protocol type and a
303 * 2-octet layer 3 protocol type, those protocol type
304 * octets having the values from octets 6, 6a, 7, and 7a
305 * of a Q.931 low layer compatibility information element
306 * (section 4.5.19 of Q.931; Q.933 says they have the values
307 * from a Q.933 low layer compatibility information element,
308 * but Q.933 low layer compatibility information elements
309 * don't have protocol values in them).
311 * Assuming that, as Q.933 seems to imply, that Q.933 messages
312 * look just like Q.931 messages except where it explicitly
313 * says they differ, then the octet after the NLPID would,
314 * in a Q.933 message, have its upper 4 bits zero (that's
315 * the length of the call reference value, in Q.931, and
316 * is limited to 15 or fewer octets). As appears to be the case,
317 * octet 6 of a Q.931 low layer compatibility element has the
318 * 0x40 bit set, so you can distinguish between a Q.933
319 * message and an encapsulated packet by checking whether
320 * the upper 4 bits of the octet after the NLPID are zero.
322 * To handle this, we'd handle Q.933's NLPID specially, which
323 * we'd want to do anyway, so that we give it a tvbuff that
324 * includes the NLPID.
327 proto_tree_add_uint(fr_tree, hf_fr_nlpid, tvb, offset, 1, fr_nlpid );
334 /* Include the NLPID and SNAP header in the top-level
335 protocol tree item. */
336 proto_item_set_len(ti, offset+5);
338 dissect_snap(tvb, offset, pinfo, tree, fr_tree, fr_ctrl,
339 hf_fr_oui, hf_fr_snaptype, hf_fr_pid, 0);
344 /* Include the NLPID in the top-level protocol tree item. */
345 proto_item_set_len(ti, offset);
347 next_tvb = tvb_new_subset(tvb,offset,-1,-1);
348 if (!dissector_try_port(fr_subdissector_table,fr_nlpid,
349 next_tvb, pinfo, tree))
350 call_dissector(data_handle,next_tvb, pinfo, tree);
355 static void dissect_lapf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
357 proto_tree_add_text(tree, tvb, 0, 0, "Frame relay lapf not yet implemented");
358 call_dissector(data_handle,tvb_new_subset(tvb,0,-1,-1),pinfo,tree);
360 static void dissect_fr_xid(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
362 proto_tree_add_text(tree, tvb, 0, 0, "Frame relay xid not yet implemented");
363 call_dissector(data_handle,tvb_new_subset(tvb,0,-1,-1),pinfo,tree);
366 /* Register the protocol with Ethereal */
367 void proto_register_fr(void)
369 static hf_register_info hf[] = {
372 "DLCI", "fr.dlci", FT_UINT16, BASE_DEC,
373 NULL, FRELAY_DLCI, "Data-Link Connection Identifier", HFILL }},
375 "CR", "fr.cr", FT_BOOLEAN, 16, TFS(&cmd_string),
376 FRELAY_CR, "Command/Response", HFILL }},
378 "DC", "fr.dc", FT_BOOLEAN, 16, TFS(&ctrl_string),
379 FRELAY_CR, "Address/Control", HFILL }},
382 "FECN", "fr.fecn", FT_BOOLEAN, 16,
383 NULL, FRELAY_FECN, "Forward Explicit Congestion Notification", HFILL }},
385 "BECN", "fr.becn", FT_BOOLEAN, 16,
386 NULL, FRELAY_BECN, "Backward Explicit Congestion Notification", HFILL }},
388 "DE", "fr.de", FT_BOOLEAN, 16,
389 NULL, FRELAY_DE, "Discard Eligibility", HFILL }},
391 "EA", "fr.ea", FT_BOOLEAN, 16, TFS(&ea_string),
392 FRELAY_EA, "Extended Address", HFILL }},
394 "NLPID", "fr.nlpid", FT_UINT8, BASE_HEX,
395 VALS(fr_nlpid_vals), 0x0, "FrameRelay Encapsulated Protocol NLPID", HFILL }},
397 "Organization Code", "fr.snap.oui", FT_UINT24, BASE_HEX,
398 VALS(oui_vals), 0x0, "", HFILL }},
400 "Protocol ID", "fr.snap.pid", FT_UINT16, BASE_HEX,
401 NULL, 0x0, "", HFILL }},
403 "Type", "fr.snaptype", FT_UINT16, BASE_HEX,
404 VALS(etype_vals), 0x0, "FrameRelay SNAP Encapsulated Protocol", HFILL }},
405 { &hf_fr_chdlctype, {
406 "Type", "fr.chdlctype", FT_UINT16, BASE_HEX,
407 VALS(chdlc_vals), 0x0, "FrameRelay Cisco HDLC Encapsulated Protocol", HFILL }},
411 /* Setup protocol subtree array */
412 static gint *ett[] = {
416 proto_fr = proto_register_protocol("Frame Relay", "FR", "fr");
417 proto_register_field_array(proto_fr, hf, array_length(hf));
418 proto_register_subtree_array(ett, array_length(ett));
420 fr_subdissector_table = register_dissector_table("fr.ietf",
421 "Frame Relay NLPID", FT_UINT8, BASE_HEX);
423 register_dissector("fr_uncompressed", dissect_fr_uncompressed, proto_fr);
424 register_dissector("fr", dissect_fr, proto_fr);
427 void proto_reg_handoff_fr(void)
429 dissector_handle_t fr_handle;
431 fr_handle = create_dissector_handle(dissect_fr, proto_fr);
432 dissector_add("wtap_encap", WTAP_ENCAP_FRELAY, fr_handle);
433 dissector_add("wtap_encap", WTAP_ENCAP_FRELAY_WITH_PHDR, fr_handle);
434 dissector_add("gre.proto", GRE_FR, fr_handle);
435 data_handle = find_dissector("data");
437 osinl_subdissector_table = find_dissector_table("osinl");