FIXUP: WIP: verification_trailer
[wireshark-wip.git] / epan / dissectors / packet-pw-hdlc.c
blob3d84b8eaa4f8c84ae1583226fda2f4710996f3a4
1 /* packet-pw-hdlc.c
2 * Routines for HDLC PW dissection as per RFC4618.
3 * Copyright 2009, Dmitry Trebich, Artem Tamazov <artem.tamazov@tellabs.com>
5 * $Id$
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * History:
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.]
37 #include "config.h"
39 #include <glib.h>
41 #include <epan/packet.h>
43 #include "packet-mpls.h"
45 static dissector_handle_t ppp_handle;
46 static dissector_handle_t fr_handle;
48 static gint proto_pw_hdlc_nocw_fr = -1;
49 static gint proto_pw_hdlc_nocw_hdlc_ppp = -1;
51 static gint ett_pw_hdlc = -1;
53 /* static int hf_pw_hdlc = -1; */
54 static int hf_pw_hdlc_address_field = -1;
55 static int hf_pw_hdlc_address = -1;
56 static int hf_pw_hdlc_cr_bit = -1;
57 static int hf_pw_hdlc_control_field = -1;
58 static int hf_pw_hdlc_pf_bit = -1;
59 static int hf_pw_hdlc_modifier = -1;
61 static const value_string pw_hdlc_modifier_vals[] = {
62 {0x00, "UI - Unnumbered information" },
63 {0x08, "UP - Unnumbered poll" },
64 {0x10, "DISC/RD - Disconnect/Request disconnect" },
65 {0x18, "UA - Unnumbered acknowledgment" },
66 {0x20, "SNRM - Set normal response mode" },
67 {0x38, "TEST - Test" },
68 {0x01, "SIM/RIM - Set initialization mode/Request initialization mode" },
69 {0x21, "FRMR - Frame reject" },
70 {0x03, "SARM/DM - Set asynchronous response mode/Disconnect mode" },
71 {0x0B, "SABM - Set asynchronous balanced mode" },
72 {0x13, "SARME - Set asynchronous response extended mode" },
73 {0x1B, "SABME - Set asynchronous balanced extended mode" },
74 {0x23, "RSET - Reset" },
75 {0x2B, "XID - Exchange identification" },
76 {0x33, "SNRME - Set normal response extended mode" },
77 {0, NULL }
80 static void dissect_pw_hdlc_nocw_fr( tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree )
82 call_dissector( fr_handle, tvb, pinfo, tree );
86 static void dissect_pw_hdlc_nocw_hdlc_ppp( tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree )
88 if (tvb_reported_length_remaining(tvb, 0) < 2)
90 proto_tree_add_text(tree, tvb, 0, -1, "Error processing message");
91 return;
94 if (tree)
96 proto_tree *tr;
97 proto_item *item;
98 proto_item *item_address;
99 proto_item *item_control;
100 guint8 addr;
101 guint8 control;
103 addr = tvb_get_guint8(tvb, 0);
104 control = tvb_get_guint8(tvb, 1);
106 item = proto_tree_add_item( tree, proto_pw_hdlc_nocw_hdlc_ppp, tvb, 0, 2, ENC_NA );
108 tr = proto_item_add_subtree( item, ett_pw_hdlc );
110 item_address = proto_tree_add_item( tr, hf_pw_hdlc_address_field, tvb, 0, 1, ENC_NA );
111 item_control = proto_tree_add_item( tr, hf_pw_hdlc_control_field, tvb, 1, 1, ENC_NA );
113 tr = proto_item_add_subtree( item_address, ett_pw_hdlc );
115 if ( 0x3F == (( addr & 0xFC ) >> 2 ))
116 proto_tree_add_uint_format_value( tr, hf_pw_hdlc_address, tvb, 0, 1, 0xFC, "0x%x (All stations)", 0x3F );
117 else
118 proto_tree_add_uint( tr, hf_pw_hdlc_address, tvb, 0, 1, ( addr & 0xFC ) >> 2 );
120 proto_tree_add_uint( tr, hf_pw_hdlc_cr_bit, tvb, 0, 1, ( addr & 2 ) >> 1 );
122 tr = proto_item_add_subtree( item_control, ett_pw_hdlc );
124 if ( control & 1 )
126 if ( control & 2 )
128 proto_tree_add_text( tr, tvb, 1, 1, "U frame" );
130 proto_tree_add_uint( tr, hf_pw_hdlc_pf_bit, tvb, 1, 1, ( control & 0x10 ) >> 4 );
131 proto_tree_add_uint( tr, hf_pw_hdlc_modifier, tvb, 1, 1, (control & 0xEC) >> 2);
133 else
135 proto_tree_add_text( tr, tvb, 1, 1, "S frame" );
138 else
140 proto_tree_add_text( tr, tvb, 1, 1, "I frame" );
143 call_dissector( ppp_handle, tvb_new_subset_remaining(tvb, 2), pinfo, tree );
146 void proto_register_pw_hdlc(void)
148 static hf_register_info hf[] = {
149 #if 0
151 &hf_pw_hdlc,
153 "PW HDLC", "pw_hdlc", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL
156 #endif
158 &hf_pw_hdlc_address_field,
160 "Address field", "pw_hdlc.address_field",
161 FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL
165 &hf_pw_hdlc_address,
167 "Address", "pw_hdlc.address",
168 FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL
172 &hf_pw_hdlc_cr_bit,
174 "C/R bit", "pw_hdlc.cr_bit",
175 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL
179 &hf_pw_hdlc_control_field,
181 "Control field", "pw_hdlc.control_field",
182 FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL
186 &hf_pw_hdlc_pf_bit,
188 "Poll/Final bit", "pw_hdlc.pf_bit",
189 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL
193 &hf_pw_hdlc_modifier,
195 "Modifier", "pw_hdlc.modifier",
196 FT_UINT8, BASE_HEX, VALS(pw_hdlc_modifier_vals), 0x0, NULL, HFILL
201 static gint *ett[] = {
202 &ett_pw_hdlc
205 proto_pw_hdlc_nocw_fr = proto_register_protocol("HDLC PW, FR port mode (no CW)", /*not displayed*/
206 "HDLC PW, FR port mode (no CW)",
207 "pw_hdlc_nocw_fr" );
208 proto_pw_hdlc_nocw_hdlc_ppp = proto_register_protocol("HDLC-like framing for PPP",
209 "HDLC PW with PPP payload (no CW)",
210 "pw_hdlc_nocw_hdlc_ppp" );
212 proto_register_field_array(proto_pw_hdlc_nocw_fr, hf, array_length(hf));
213 proto_register_subtree_array(ett, array_length(ett));
215 register_dissector("pw_hdlc_nocw_fr", dissect_pw_hdlc_nocw_fr, proto_pw_hdlc_nocw_fr );
216 register_dissector("pw_hdlc_nocw_hdlc_ppp", dissect_pw_hdlc_nocw_hdlc_ppp, proto_pw_hdlc_nocw_hdlc_ppp );
219 void proto_reg_handoff_pw_hdlc(void)
221 dissector_handle_t handle;
223 handle = find_dissector("pw_hdlc_nocw_fr");
224 dissector_add_uint( "mpls.label", MPLS_LABEL_INVALID, handle );
226 handle = find_dissector("pw_hdlc_nocw_hdlc_ppp");
227 dissector_add_uint( "mpls.label", MPLS_LABEL_INVALID, handle );
229 ppp_handle = find_dissector( "ppp" );
230 fr_handle = find_dissector( "fr" );