2 * Routines for HDLC PW dissection as per RFC4618.
3 * Copyright 2009, Dmitry Trebich, Artem Tamazov <artem.tamazov@tellabs.com>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 * ---------------------------------
27 * 02.03.2009 Initial implementation, supports:
28 * - HDLC mode (rfc4618 5.1), no CW, payload is PPP (PPP in HDLC-like Framing (rfc1662)).
29 * - FR port mode (rfc4618 5.2), no CW.
31 * [informative: Not supported yet:
32 * - All kinds of HDLC PW with CW.
33 * - PPP mode (rfc4618 5.3).
34 * - For HDLC mode, decoding payloads other than PPP.]
43 #include <epan/packet.h>
45 #include "packet-mpls.h"
47 static dissector_handle_t ppp_handle;
48 static dissector_handle_t fr_handle;
50 static gint proto_pw_hdlc_nocw_fr = -1;
51 static gint proto_pw_hdlc_nocw_hdlc_ppp = -1;
53 static gint ett_pw_hdlc = -1;
55 static int hf_pw_hdlc = -1;
56 static int hf_pw_hdlc_address_field = -1;
57 static int hf_pw_hdlc_address = -1;
58 static int hf_pw_hdlc_cr_bit = -1;
59 static int hf_pw_hdlc_control_field = -1;
60 static int hf_pw_hdlc_pf_bit = -1;
62 static void dissect_pw_hdlc_nocw_fr( tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree )
64 call_dissector( fr_handle, tvb, pinfo, tree );
68 static void dissect_pw_hdlc_nocw_hdlc_ppp( tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree )
70 if (tvb_reported_length_remaining(tvb, 0) < 2)
74 proto_tree_add_text(tree, tvb, 0, -1, "Error processing message");
83 proto_item *item_address;
84 proto_item *item_control;
88 addr = tvb_get_guint8(tvb, 0);
89 control = tvb_get_guint8(tvb, 1);
91 item = proto_tree_add_item( tree, proto_pw_hdlc_nocw_hdlc_ppp, tvb, 0, 2, FALSE );
93 tr = proto_item_add_subtree( item, ett_pw_hdlc );
95 item_address = proto_tree_add_uint( tr, hf_pw_hdlc_address_field, tvb, 0, 1, addr );
96 item_control = proto_tree_add_uint_format( tr, hf_pw_hdlc_control_field, tvb, 1, 1, control, "Control field: 0x%x", control );
98 tr = proto_item_add_subtree( item_address, ett_pw_hdlc );
100 if ( 0x3F == (( addr & 0xFC ) >> 2 ))
101 proto_tree_add_uint_format( tr, hf_pw_hdlc_address, tvb, 0, 1, 0xFC, "Address: 0x%x (All stations)", 0x3F );
103 proto_tree_add_uint( tr, hf_pw_hdlc_address, tvb, 0, 1, ( addr & 0xFC ) >> 2 );
105 proto_tree_add_uint( tr, hf_pw_hdlc_cr_bit, tvb, 0, 1, ( addr & 2 ) >> 1 );
107 tr = proto_item_add_subtree( item_control, ett_pw_hdlc );
116 proto_tree_add_text( tr, tvb, 1, 1, "U frame" );
118 proto_tree_add_uint( tr, hf_pw_hdlc_pf_bit, tvb, 1, 1, ( control & 0x10 ) >> 4 );
120 modifier2 = (( control & 0xC ) >> 2 );
121 modifier3 = (( control & 0xE0 ) >> 5 );
123 /**/ if ( modifier2 == 0 && modifier3 == 0 )
124 proto_tree_add_text( tr, tvb, 1, 1,
125 "Modifier: UI - Unnumbered information" );
126 else if ( modifier2 == 0 && modifier3 == 1 )
127 proto_tree_add_text( tr, tvb, 1, 1,
128 "Modifier: UP - Unnumbered poll" );
129 else if ( modifier2 == 0 && modifier3 == 2 )
130 proto_tree_add_text( tr, tvb, 1, 1,
131 "Modifier: DISC/RD - Disconnect/Request disconnect" );
132 else if ( modifier2 == 0 && modifier3 == 3 )
133 proto_tree_add_text( tr, tvb, 1, 1,
134 "Modifier: UA - Unnumbered acknowledgment" );
135 else if ( modifier2 == 0 && modifier3 == 4 )
136 proto_tree_add_text( tr, tvb, 1, 1,
137 "Modifier: SNRM - Set normal response mode" );
138 else if ( modifier2 == 0 && modifier3 == 7 )
139 proto_tree_add_text( tr, tvb, 1, 1,
140 "Modifier: TEST - Test" );
141 else if ( modifier2 == 1 && modifier3 == 0 )
142 proto_tree_add_text( tr, tvb, 1, 1,
144 " - Set initialization mode/Request initialization mode" );
145 else if ( modifier2 == 1 && modifier3 == 4 )
146 proto_tree_add_text( tr, tvb, 1, 1,
147 "Modifier: FRMR - Frame reject" );
148 else if ( modifier2 == 3 && modifier3 == 0 )
149 proto_tree_add_text( tr, tvb, 1, 1,
151 " - Set asynchronous response mode/Disconnect mode" );
152 else if ( modifier2 == 3 && modifier3 == 1 )
153 proto_tree_add_text( tr, tvb, 1, 1,
154 "Modifier: SABM - Set asynchronous balanced mode" );
155 else if ( modifier2 == 3 && modifier3 == 2 )
156 proto_tree_add_text( tr, tvb, 1, 1,
157 "Modifier: SARME - Set asynchronous response extended mode" );
158 else if ( modifier2 == 3 && modifier3 == 3 )
159 proto_tree_add_text( tr, tvb, 1, 1,
160 "Modifier: SABME - Set asynchronous balanced extended mode" );
161 else if ( modifier2 == 3 && modifier3 == 4 )
162 proto_tree_add_text( tr, tvb, 1, 1,
163 "Modifier: RSET - Reset" );
164 else if ( modifier2 == 3 && modifier3 == 5 )
165 proto_tree_add_text( tr, tvb, 1, 1,
166 "Modifier: XID - Exchange identification" );
167 else if ( modifier2 == 3 && modifier3 == 6 )
168 proto_tree_add_text( tr, tvb, 1, 1,
169 "Modifier: SNRME - Set normal response extended mode" );
173 proto_tree_add_text( tr, tvb, 1, 1, "S frame" );
178 proto_tree_add_text( tr, tvb, 1, 1, "I frame" );
181 call_dissector( ppp_handle, tvb_new_subset_remaining(tvb, 2), pinfo, tree );
184 void proto_register_pw_hdlc(void)
186 static hf_register_info hf[] = {
190 "PW HDLC", "pw_hdlc", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL
194 &hf_pw_hdlc_address_field,
196 "Address field", "pw_hdlc.address_field",
197 FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL
203 "Address", "pw_hdlc.address",
204 FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL
210 "C/R bit", "pw_hdlc.cr_bit",
211 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL
215 &hf_pw_hdlc_control_field,
217 "Control field", "pw_hdlc.control_field",
218 FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL
224 "Poll/Final bit", "pw_hdlc.pf_bit",
225 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL
230 static gint *ett[] = {
234 proto_pw_hdlc_nocw_fr = proto_register_protocol("HDLC PW, FR port mode (no CW)", /*not displayed*/
235 "HDLC PW, FR port mode (no CW)",
237 proto_pw_hdlc_nocw_hdlc_ppp = proto_register_protocol("HDLC-like framing for PPP",
238 "HDLC PW with PPP payload (no CW)",
239 "pw_hdlc_nocw_hdlc_ppp" );
241 proto_register_field_array(proto_pw_hdlc_nocw_fr, hf, array_length(hf));
242 proto_register_subtree_array(ett, array_length(ett));
244 register_dissector("pw_hdlc_nocw_fr", dissect_pw_hdlc_nocw_fr, proto_pw_hdlc_nocw_fr );
245 register_dissector("pw_hdlc_nocw_hdlc_ppp", dissect_pw_hdlc_nocw_hdlc_ppp, proto_pw_hdlc_nocw_hdlc_ppp );
248 void proto_reg_handoff_pw_hdlc(void)
250 dissector_handle_t handle;
252 handle = find_dissector("pw_hdlc_nocw_fr");
253 dissector_add( "mpls.label", LABEL_INVALID, handle );
255 handle = find_dissector("pw_hdlc_nocw_hdlc_ppp");
256 dissector_add( "mpls.label", LABEL_INVALID, handle );
258 ppp_handle = find_dissector( "ppp" );
259 fr_handle = find_dissector( "fr" );