MSWSP: fix dissect_mswsp_smb()
[wireshark-wip.git] / plugins / docsis / packet-rngrsp.c
blobdf2f0947a55cde9693e0d5dad154b173b8ed127b
1 /* packet-rngrsp.c
2 * Routines for Ranging Response Message dissection
3 * Copyright 2002, Anand V. Narwani <anand[AT]narwani.org>
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.
26 #include "config.h"
28 #include <epan/packet.h>
29 #include <epan/exceptions.h>
31 #define RNGRSP_TIMING 1
32 #define RNGRSP_PWR_LEVEL_ADJ 2
33 #define RNGRSP_OFFSET_FREQ_ADJ 3
34 #define RNGRSP_TRANSMIT_EQ_ADJ 4
35 #define RNGRSP_RANGING_STATUS 5
36 #define RNGRSP_DOWN_FREQ_OVER 6
37 #define RNGRSP_UP_CHID_OVER 7
39 /* Initialize the protocol and registered fields */
40 static int proto_docsis_rngrsp = -1;
41 static int hf_docsis_rngrsp_upstream_chid = -1;
42 static int hf_docsis_rngrsp_sid = -1;
43 static int hf_docsis_rngrsp_timing_adj = -1;
44 static int hf_docsis_rngrsp_power_adj = -1;
45 static int hf_docsis_rngrsp_freq_adj = -1;
46 static int hf_docsis_rngrsp_xmit_eq_adj = -1;
47 static int hf_docsis_rngrsp_ranging_status = -1;
48 static int hf_docsis_rngrsp_down_freq_over = -1;
49 static int hf_docsis_rngrsp_upstream_ch_over = -1;
51 static const value_string rng_stat_vals[] = {
52 {1, "Continue"},
53 {2, "Abort"},
54 {3, "Success"},
55 {0, NULL}
58 /* Initialize the subtree pointers */
59 static gint ett_docsis_rngrsp = -1;
61 /* Code to actually dissect the packets */
62 static void
63 dissect_rngrsp (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
65 proto_item *it;
66 proto_tree *rngrsp_tree;
67 guint8 tlvtype, tlvlen;
68 int pos;
69 gint length;
70 guint8 upchid;
71 guint16 sid;
72 gint8 pwr;
73 gint32 tim;
75 sid = tvb_get_ntohs (tvb, 0);
76 upchid = tvb_get_guint8 (tvb, 2);
78 if (upchid > 0)
79 col_add_fstr (pinfo->cinfo, COL_INFO,
80 "Ranging Response: SID = %u, Upstream Channel = %u (U%u)",
81 sid, upchid, upchid - 1);
82 else
83 col_add_fstr (pinfo->cinfo, COL_INFO,
84 "Ranging Response: SID = %u, Telephony Return", sid);
87 if (tree)
89 it =
90 proto_tree_add_protocol_format (tree, proto_docsis_rngrsp, tvb, 0, -1,
91 "Ranging Response");
92 rngrsp_tree = proto_item_add_subtree (it, ett_docsis_rngrsp);
93 proto_tree_add_item (rngrsp_tree, hf_docsis_rngrsp_sid, tvb, 0, 2,
94 ENC_BIG_ENDIAN);
95 proto_tree_add_item (rngrsp_tree, hf_docsis_rngrsp_upstream_chid, tvb,
96 2, 1, ENC_BIG_ENDIAN);
98 length = tvb_reported_length_remaining (tvb, 0);
99 pos = 3;
100 while (pos < length)
102 tlvtype = tvb_get_guint8 (tvb, pos++);
103 tlvlen = tvb_get_guint8 (tvb, pos++);
104 switch (tlvtype)
106 case RNGRSP_TIMING:
107 if (tlvlen == 4)
109 tim = tvb_get_ntohl (tvb, pos);
110 proto_tree_add_int (rngrsp_tree,
111 hf_docsis_rngrsp_timing_adj, tvb, pos,
112 tlvlen, tim);
114 else
116 THROW (ReportedBoundsError);
118 break;
119 case RNGRSP_PWR_LEVEL_ADJ:
120 if (tlvlen == 1)
122 pwr = tvb_get_guint8 (tvb, pos);
123 proto_tree_add_int (rngrsp_tree, hf_docsis_rngrsp_power_adj,
124 tvb, pos, tlvlen, pwr);
126 else
128 THROW (ReportedBoundsError);
130 break;
131 case RNGRSP_OFFSET_FREQ_ADJ:
132 if (tlvlen == 2)
134 proto_tree_add_item (rngrsp_tree, hf_docsis_rngrsp_freq_adj,
135 tvb, pos, tlvlen, ENC_BIG_ENDIAN);
137 else
139 THROW (ReportedBoundsError);
141 break;
142 case RNGRSP_TRANSMIT_EQ_ADJ:
143 proto_tree_add_item (rngrsp_tree, hf_docsis_rngrsp_xmit_eq_adj,
144 tvb, pos, tlvlen, ENC_NA);
145 break;
146 case RNGRSP_RANGING_STATUS:
147 if (tlvlen == 1)
148 proto_tree_add_item (rngrsp_tree,
149 hf_docsis_rngrsp_ranging_status, tvb,
150 pos, tlvlen, ENC_BIG_ENDIAN);
151 else
153 THROW (ReportedBoundsError);
155 break;
156 case RNGRSP_DOWN_FREQ_OVER:
157 if (tlvlen == 4)
158 proto_tree_add_item (rngrsp_tree,
159 hf_docsis_rngrsp_down_freq_over, tvb,
160 pos, tlvlen, ENC_BIG_ENDIAN);
161 else
163 THROW (ReportedBoundsError);
165 break;
166 case RNGRSP_UP_CHID_OVER:
167 if (tlvlen == 1)
168 proto_tree_add_item (rngrsp_tree,
169 hf_docsis_rngrsp_upstream_ch_over, tvb,
170 pos, tlvlen, ENC_BIG_ENDIAN);
171 else
173 THROW (ReportedBoundsError);
175 break;
177 } /* switch(tlvtype) */
178 pos = pos + tlvlen;
179 } /* while (pos < length) */
180 } /* if (tree) */
186 /* Register the protocol with Wireshark */
188 /* this format is require because a script is used to build the C function
189 that calls all the protocol registration.
193 void
194 proto_register_docsis_rngrsp (void)
197 /* Setup list of header fields See Section 1.6.1 for details*/
198 static hf_register_info hf[] = {
199 {&hf_docsis_rngrsp_sid,
200 {"Service Identifier", "docsis_rngrsp.sid",
201 FT_UINT16, BASE_DEC, NULL, 0x0,
202 NULL, HFILL}
204 {&hf_docsis_rngrsp_upstream_chid,
205 {"Upstream Channel ID", "docsis_rngrsp.upchid",
206 FT_UINT8, BASE_DEC, NULL, 0x0,
207 NULL, HFILL}
209 {&hf_docsis_rngrsp_timing_adj,
210 {"Timing Adjust (6.25us/64)", "docsis_rngrsp.timingadj",
211 FT_INT32, BASE_DEC, NULL, 0x0,
212 "Timing Adjust", HFILL}
214 {&hf_docsis_rngrsp_power_adj,
215 {"Power Level Adjust (0.25dB units)", "docsis_rngrsp.poweradj",
216 FT_INT8, BASE_DEC, NULL, 0x0,
217 "Power Level Adjust", HFILL}
219 {&hf_docsis_rngrsp_freq_adj,
220 {"Offset Freq Adjust (Hz)", "docsis_rngrsp.freqadj",
221 FT_INT16, BASE_DEC, NULL, 0x0,
222 "Frequency Adjust", HFILL}
224 {&hf_docsis_rngrsp_xmit_eq_adj,
225 {"Transmit Equalisation Adjust", "docsis_rngrsp.xmit_eq_adj",
226 FT_BYTES, BASE_NONE, NULL, 0x0,
227 "Timing Equalisation Adjust", HFILL}
229 {&hf_docsis_rngrsp_ranging_status,
230 {"Ranging Status", "docsis_rngrsp.rng_stat",
231 FT_UINT8, BASE_DEC, VALS (rng_stat_vals), 0x0,
232 NULL, HFILL}
234 {&hf_docsis_rngrsp_down_freq_over,
235 {"Downstream Frequency Override (Hz)", "docsis_rngrsp.freq_over",
236 FT_UINT32, BASE_DEC, NULL, 0x0,
237 "Downstream Frequency Override", HFILL}
239 {&hf_docsis_rngrsp_upstream_ch_over,
240 {"Upstream Channel ID Override", "docsis_rngrsp.chid_override",
241 FT_UINT8, BASE_DEC, NULL, 0x0,
242 NULL, HFILL}
247 /* Setup protocol subtree array */
248 static gint *ett[] = {
249 &ett_docsis_rngrsp,
252 /* Register the protocol name and description */
253 proto_docsis_rngrsp = proto_register_protocol ("DOCSIS Ranging Response",
254 "DOCSIS RNG-RSP",
255 "docsis_rngrsp");
257 /* Required function calls to register the header fields and subtrees used */
258 proto_register_field_array (proto_docsis_rngrsp, hf, array_length (hf));
259 proto_register_subtree_array (ett, array_length (ett));
261 register_dissector ("docsis_rngrsp", dissect_rngrsp, proto_docsis_rngrsp);
265 /* If this dissector uses sub-dissector registration add a registration routine.
266 This format is required because a script is used to find these routines and
267 create the code that calls these routines.
269 void
270 proto_reg_handoff_docsis_rngrsp (void)
272 dissector_handle_t docsis_rngrsp_handle;
274 docsis_rngrsp_handle = find_dissector ("docsis_rngrsp");
275 dissector_add_uint ("docsis_mgmt", 0x05, docsis_rngrsp_handle);