2 * Routines for HDLC PW dissection as per RFC4618.
3 * Copyright 2009, Dmitry Trebich, Artem Tamazov <artem.tamazov@tellabs.com>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * ---------------------------------
25 * 02.03.2009 Initial implementation, supports:
26 * - HDLC mode (rfc4618 5.1), no CW, payload is PPP (PPP in HDLC-like Framing (rfc1662)).
27 * - FR port mode (rfc4618 5.2), no CW.
29 * [informative: Not supported yet:
30 * - All kinds of HDLC PW with CW.
31 * - PPP mode (rfc4618 5.3).
32 * - For HDLC mode, decoding payloads other than PPP.]
39 #include <epan/packet.h>
41 #include "packet-mpls.h"
43 void proto_register_pw_hdlc(void);
44 void proto_reg_handoff_pw_hdlc(void);
46 static dissector_handle_t ppp_handle;
47 static dissector_handle_t fr_handle;
49 static gint proto_pw_hdlc_nocw_fr = -1;
50 static gint proto_pw_hdlc_nocw_hdlc_ppp = -1;
52 static gint ett_pw_hdlc = -1;
54 /* static int hf_pw_hdlc = -1; */
55 static int hf_pw_hdlc_address_field = -1;
56 static int hf_pw_hdlc_address = -1;
57 static int hf_pw_hdlc_cr_bit = -1;
58 static int hf_pw_hdlc_control_field = -1;
59 static int hf_pw_hdlc_pf_bit = -1;
60 static int hf_pw_hdlc_modifier = -1;
62 static const value_string pw_hdlc_modifier_vals[] = {
63 {0x00, "UI - Unnumbered information" },
64 {0x08, "UP - Unnumbered poll" },
65 {0x10, "DISC/RD - Disconnect/Request disconnect" },
66 {0x18, "UA - Unnumbered acknowledgment" },
67 {0x20, "SNRM - Set normal response mode" },
68 {0x38, "TEST - Test" },
69 {0x01, "SIM/RIM - Set initialization mode/Request initialization mode" },
70 {0x21, "FRMR - Frame reject" },
71 {0x03, "SARM/DM - Set asynchronous response mode/Disconnect mode" },
72 {0x0B, "SABM - Set asynchronous balanced mode" },
73 {0x13, "SARME - Set asynchronous response extended mode" },
74 {0x1B, "SABME - Set asynchronous balanced extended mode" },
75 {0x23, "RSET - Reset" },
76 {0x2B, "XID - Exchange identification" },
77 {0x33, "SNRME - Set normal response extended mode" },
81 static void dissect_pw_hdlc_nocw_fr( tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree )
83 call_dissector( fr_handle, tvb, pinfo, tree );
87 static void dissect_pw_hdlc_nocw_hdlc_ppp( tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree )
89 if (tvb_reported_length_remaining(tvb, 0) < 2)
91 proto_tree_add_text(tree, tvb, 0, -1, "Error processing message");
99 proto_item *item_address;
100 proto_item *item_control;
104 addr = tvb_get_guint8(tvb, 0);
105 control = tvb_get_guint8(tvb, 1);
107 item = proto_tree_add_item( tree, proto_pw_hdlc_nocw_hdlc_ppp, tvb, 0, 2, ENC_NA );
109 tr = proto_item_add_subtree( item, ett_pw_hdlc );
111 item_address = proto_tree_add_item( tr, hf_pw_hdlc_address_field, tvb, 0, 1, ENC_NA );
112 item_control = proto_tree_add_item( tr, hf_pw_hdlc_control_field, tvb, 1, 1, ENC_NA );
114 tr = proto_item_add_subtree( item_address, ett_pw_hdlc );
116 if ( 0x3F == (( addr & 0xFC ) >> 2 ))
117 proto_tree_add_uint_format_value( tr, hf_pw_hdlc_address, tvb, 0, 1, 0xFC, "0x%x (All stations)", 0x3F );
119 proto_tree_add_uint( tr, hf_pw_hdlc_address, tvb, 0, 1, ( addr & 0xFC ) >> 2 );
121 proto_tree_add_uint( tr, hf_pw_hdlc_cr_bit, tvb, 0, 1, ( addr & 2 ) >> 1 );
123 tr = proto_item_add_subtree( item_control, ett_pw_hdlc );
129 proto_tree_add_text( tr, tvb, 1, 1, "U frame" );
131 proto_tree_add_uint( tr, hf_pw_hdlc_pf_bit, tvb, 1, 1, ( control & 0x10 ) >> 4 );
132 proto_tree_add_uint( tr, hf_pw_hdlc_modifier, tvb, 1, 1, (control & 0xEC) >> 2);
136 proto_tree_add_text( tr, tvb, 1, 1, "S frame" );
141 proto_tree_add_text( tr, tvb, 1, 1, "I frame" );
144 call_dissector( ppp_handle, tvb_new_subset_remaining(tvb, 2), pinfo, tree );
147 void proto_register_pw_hdlc(void)
149 static hf_register_info hf[] = {
154 "PW HDLC", "pw_hdlc", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL
159 &hf_pw_hdlc_address_field,
161 "Address field", "pw_hdlc.address_field",
162 FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL
168 "Address", "pw_hdlc.address",
169 FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL
175 "C/R bit", "pw_hdlc.cr_bit",
176 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL
180 &hf_pw_hdlc_control_field,
182 "Control field", "pw_hdlc.control_field",
183 FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL
189 "Poll/Final bit", "pw_hdlc.pf_bit",
190 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL
194 &hf_pw_hdlc_modifier,
196 "Modifier", "pw_hdlc.modifier",
197 FT_UINT8, BASE_HEX, VALS(pw_hdlc_modifier_vals), 0x0, NULL, HFILL
202 static gint *ett[] = {
206 proto_pw_hdlc_nocw_fr = proto_register_protocol("HDLC PW, FR port mode (no CW)", /*not displayed*/
207 "HDLC PW, FR port mode (no CW)",
209 proto_pw_hdlc_nocw_hdlc_ppp = proto_register_protocol("HDLC-like framing for PPP",
210 "HDLC PW with PPP payload (no CW)",
211 "pw_hdlc_nocw_hdlc_ppp" );
213 proto_register_field_array(proto_pw_hdlc_nocw_fr, hf, array_length(hf));
214 proto_register_subtree_array(ett, array_length(ett));
216 register_dissector("pw_hdlc_nocw_fr", dissect_pw_hdlc_nocw_fr, proto_pw_hdlc_nocw_fr );
217 register_dissector("pw_hdlc_nocw_hdlc_ppp", dissect_pw_hdlc_nocw_hdlc_ppp, proto_pw_hdlc_nocw_hdlc_ppp );
220 void proto_reg_handoff_pw_hdlc(void)
222 dissector_handle_t handle;
224 handle = find_dissector("pw_hdlc_nocw_fr");
225 dissector_add_uint( "mpls.label", MPLS_LABEL_INVALID, handle );
227 handle = find_dissector("pw_hdlc_nocw_hdlc_ppp");
228 dissector_add_uint( "mpls.label", MPLS_LABEL_INVALID, handle );
230 ppp_handle = find_dissector( "ppp" );
231 fr_handle = find_dissector( "fr" );