2 * Routines for Ranging Response Message dissection
3 * Copyright 2002, Anand V. Narwani <anand[AT]narwani.org>
5 * $Id: packet-rngrsp.c,v 1.5 2003/05/28 14:52:52 gerald Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
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.
30 #include "plugins/plugin_api.h"
31 #include "plugins/plugin_api_defs.h"
32 #include "moduleinfo.h"
40 #include <epan/packet.h>
42 #define RNGRSP_TIMING 1
43 #define RNGRSP_PWR_LEVEL_ADJ 2
44 #define RNGRSP_OFFSET_FREQ_ADJ 3
45 #define RNGRSP_TRANSMIT_EQ_ADJ 4
46 #define RNGRSP_RANGING_STATUS 5
47 #define RNGRSP_DOWN_FREQ_OVER 6
48 #define RNGRSP_UP_CHID_OVER 7
50 /* Initialize the protocol and registered fields */
51 static int proto_docsis_rngrsp = -1;
52 static int hf_docsis_rngrsp = -1;
53 static int hf_docsis_rngrsp_upstream_chid = -1;
54 static int hf_docsis_rngrsp_sid = -1;
55 static int hf_docsis_rngrsp_timing_adj = -1;
56 static int hf_docsis_rngrsp_power_adj = -1;
57 static int hf_docsis_rngrsp_freq_adj = -1;
58 static int hf_docsis_rngrsp_xmit_eq_adj = -1;
59 static int hf_docsis_rngrsp_ranging_status = -1;
60 static int hf_docsis_rngrsp_down_freq_over = -1;
61 static int hf_docsis_rngrsp_upstream_ch_over = -1;
63 static const value_string rng_stat_vals[] = {
70 /* Initialize the subtree pointers */
71 static gint ett_docsis_rngrsp = -1;
73 /* These Routines convert the specified type to a signed integer
74 * using a Two's Compliment Format */
77 byte_to_signed (guint8 i)
93 short_to_signed (guint16 i)
99 val = (gint16) ((~i) + 1);
111 long_to_signed (guint32 i)
117 val = (gint32) ((~i) + 1);
129 /* Code to actually dissect the packets */
131 dissect_rngrsp (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
134 proto_tree *rngrsp_tree;
135 guint8 tlvtype, tlvlen;
142 sid = tvb_get_ntohs (tvb, 0);
143 upchid = tvb_get_guint8 (tvb, 2);
145 if (check_col (pinfo->cinfo, COL_INFO))
147 col_clear (pinfo->cinfo, COL_INFO);
149 col_add_fstr (pinfo->cinfo, COL_INFO,
150 "Ranging Response: SID = %u, Upstream Channel = %u (U%u)",
151 sid, upchid, upchid - 1);
153 col_add_fstr (pinfo->cinfo, COL_INFO,
154 "Ranging Response: SID = %u, Telephony Return", sid);
161 proto_tree_add_protocol_format (tree, proto_docsis_rngrsp, tvb, 0,
162 tvb_length_remaining (tvb, 0),
164 rngrsp_tree = proto_item_add_subtree (it, ett_docsis_rngrsp);
165 proto_tree_add_item (rngrsp_tree, hf_docsis_rngrsp_sid, tvb, 0, 2,
167 proto_tree_add_item (rngrsp_tree, hf_docsis_rngrsp_upstream_chid, tvb,
170 length = tvb_length_remaining (tvb, 0);
174 tlvtype = tvb_get_guint8 (tvb, pos++);
175 tlvlen = tvb_get_guint8 (tvb, pos++);
181 tim = long_to_signed (tvb_get_ntohl (tvb, pos));
182 proto_tree_add_int (rngrsp_tree,
183 hf_docsis_rngrsp_timing_adj, tvb, pos,
188 THROW (ReportedBoundsError);
191 case RNGRSP_PWR_LEVEL_ADJ:
194 pwr = byte_to_signed (tvb_get_guint8 (tvb, pos));
195 proto_tree_add_int (rngrsp_tree, hf_docsis_rngrsp_power_adj,
196 tvb, pos, tlvlen, pwr);
200 THROW (ReportedBoundsError);
203 case RNGRSP_OFFSET_FREQ_ADJ:
206 proto_tree_add_item (rngrsp_tree, hf_docsis_rngrsp_freq_adj,
207 tvb, pos, tlvlen, FALSE);
211 THROW (ReportedBoundsError);
214 case RNGRSP_TRANSMIT_EQ_ADJ:
215 proto_tree_add_item (rngrsp_tree, hf_docsis_rngrsp_xmit_eq_adj,
216 tvb, pos, tlvlen, FALSE);
218 case RNGRSP_RANGING_STATUS:
220 proto_tree_add_item (rngrsp_tree,
221 hf_docsis_rngrsp_ranging_status, tvb,
225 THROW (ReportedBoundsError);
228 case RNGRSP_DOWN_FREQ_OVER:
230 proto_tree_add_item (rngrsp_tree,
231 hf_docsis_rngrsp_down_freq_over, tvb,
235 THROW (ReportedBoundsError);
238 case RNGRSP_UP_CHID_OVER:
240 proto_tree_add_item (rngrsp_tree,
241 hf_docsis_rngrsp_upstream_ch_over, tvb,
245 THROW (ReportedBoundsError);
249 } /* switch(tlvtype) */
251 } /* while (pos < length) */
258 /* Register the protocol with Ethereal */
260 /* this format is require because a script is used to build the C function
261 that calls all the protocol registration.
266 proto_register_docsis_rngrsp (void)
269 /* Setup list of header fields See Section 1.6.1 for details*/
270 static hf_register_info hf[] = {
272 {"RNG-RSP Message", "docsis.rngrsp",
273 FT_BYTES, BASE_HEX, NULL, 0x0,
274 "Ranging Response Message", HFILL}
276 {&hf_docsis_rngrsp_sid,
277 {"Service Identifier", "docsis.rngrsp.sid",
278 FT_UINT16, BASE_DEC, NULL, 0x0,
279 "Service Identifier", HFILL}
281 {&hf_docsis_rngrsp_upstream_chid,
282 {"Upstream Channel ID", "docsis.rngrsp.upchid",
283 FT_UINT8, BASE_DEC, NULL, 0x0,
284 "Upstream Channel ID", HFILL}
286 {&hf_docsis_rngrsp_timing_adj,
287 {"Timing Adjust (6.25us/64)", "docsis.rngrsp.timingadj",
288 FT_INT32, BASE_DEC, NULL, 0x0,
289 "Timing Adjust", HFILL}
291 {&hf_docsis_rngrsp_power_adj,
292 {"Power Level Adjust (0.25dB units)", "docsis.rngrsp.poweradj",
293 FT_INT8, BASE_DEC, NULL, 0x0,
294 "Power Level Adjust", HFILL}
296 {&hf_docsis_rngrsp_freq_adj,
297 {"Offset Freq Adjust (Hz)", "docsis.rngrsp.freqadj",
298 FT_INT16, BASE_DEC, NULL, 0x0,
299 "Frequency Adjust", HFILL}
301 {&hf_docsis_rngrsp_xmit_eq_adj,
302 {"Transmit Equalisation Adjust", "docsis.rngrsp.xmit_eq_adj",
303 FT_BYTES, BASE_HEX, NULL, 0x0,
304 "Timing Equalisation Adjust", HFILL}
306 {&hf_docsis_rngrsp_ranging_status,
307 {"Ranging Status", "docsis.rngrsp.rng_stat",
308 FT_UINT8, BASE_DEC, VALS (rng_stat_vals), 0x0,
309 "Ranging Status", HFILL}
311 {&hf_docsis_rngrsp_down_freq_over,
312 {"Downstream Frequency Override (Hz)", "docsis.rngrsp.freq_over",
313 FT_UINT32, BASE_DEC, NULL, 0x0,
314 "Downstream Frequency Override", HFILL}
316 {&hf_docsis_rngrsp_upstream_ch_over,
317 {"Upstream Channel ID Override", "docsis.rngrsp.chid_override",
318 FT_UINT8, BASE_DEC, NULL, 0x0,
319 "Upstream Channel ID Override", HFILL}
324 /* Setup protocol subtree array */
325 static gint *ett[] = {
329 /* Register the protocol name and description */
330 proto_docsis_rngrsp = proto_register_protocol ("DOCSIS Ranging Response",
334 /* Required function calls to register the header fields and subtrees used */
335 proto_register_field_array (proto_docsis_rngrsp, hf, array_length (hf));
336 proto_register_subtree_array (ett, array_length (ett));
338 register_dissector ("docsis_rngrsp", dissect_rngrsp, proto_docsis_rngrsp);
342 /* If this dissector uses sub-dissector registration add a registration routine.
343 This format is required because a script is used to find these routines and
344 create the code that calls these routines.
347 proto_reg_handoff_docsis_rngrsp (void)
349 dissector_handle_t docsis_rngrsp_handle;
351 docsis_rngrsp_handle = find_dissector ("docsis_rngrsp");
352 dissector_add ("docsis_mgmt", 0x05, docsis_rngrsp_handle);