aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/docsis/packet-rngrsp.c
blob: 0c5551343f43be33cd7f96cf6c723bff3a3b9378 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/* packet-rngrsp.c
 * Routines for Ranging Response Message dissection
 * Copyright 2002, Anand V. Narwani <anand[AT]narwani.org>
 *
 * $Id$
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "moduleinfo.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <gmodule.h>

#include <epan/packet.h>

#define RNGRSP_TIMING 1
#define RNGRSP_PWR_LEVEL_ADJ 2
#define RNGRSP_OFFSET_FREQ_ADJ 3
#define RNGRSP_TRANSMIT_EQ_ADJ 4
#define RNGRSP_RANGING_STATUS 5
#define RNGRSP_DOWN_FREQ_OVER 6
#define RNGRSP_UP_CHID_OVER 7

/* Initialize the protocol and registered fields */
static int proto_docsis_rngrsp = -1;
static int hf_docsis_rngrsp = -1;
static int hf_docsis_rngrsp_upstream_chid = -1;
static int hf_docsis_rngrsp_sid = -1;
static int hf_docsis_rngrsp_timing_adj = -1;
static int hf_docsis_rngrsp_power_adj = -1;
static int hf_docsis_rngrsp_freq_adj = -1;
static int hf_docsis_rngrsp_xmit_eq_adj = -1;
static int hf_docsis_rngrsp_ranging_status = -1;
static int hf_docsis_rngrsp_down_freq_over = -1;
static int hf_docsis_rngrsp_upstream_ch_over = -1;

static const value_string rng_stat_vals[] = {
  {1, "Continue"},
  {2, "Abort"},
  {3, "Success"},
  {0, NULL}
};

/* Initialize the subtree pointers */
static gint ett_docsis_rngrsp = -1;

/* Code to actually dissect the packets */
static void
dissect_rngrsp (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
{
  proto_item *it;
  proto_tree *rngrsp_tree;
  guint8 tlvtype, tlvlen;
  int pos;
  gint length;
  guint8 upchid;
  guint16 sid;
  gint8 pwr;
  gint32 tim;

  sid = tvb_get_ntohs (tvb, 0);
  upchid = tvb_get_guint8 (tvb, 2);

  if (check_col (pinfo->cinfo, COL_INFO))
    {
      col_clear (pinfo->cinfo, COL_INFO);
      if (upchid > 0)
	col_add_fstr (pinfo->cinfo, COL_INFO,
		      "Ranging Response: SID = %u, Upstream Channel = %u (U%u)",
		      sid, upchid, upchid - 1);
      else
	col_add_fstr (pinfo->cinfo, COL_INFO,
		      "Ranging Response: SID = %u, Telephony Return", sid);

    }

  if (tree)
    {
      it =
	proto_tree_add_protocol_format (tree, proto_docsis_rngrsp, tvb, 0, -1,
					"Ranging Response");
      rngrsp_tree = proto_item_add_subtree (it, ett_docsis_rngrsp);
      proto_tree_add_item (rngrsp_tree, hf_docsis_rngrsp_sid, tvb, 0, 2,
			   FALSE);
      proto_tree_add_item (rngrsp_tree, hf_docsis_rngrsp_upstream_chid, tvb,
			   2, 1, FALSE);

      length = tvb_reported_length_remaining (tvb, 0);
      pos = 3;
      while (pos < length)
	{
	  tlvtype = tvb_get_guint8 (tvb, pos++);
	  tlvlen = tvb_get_guint8 (tvb, pos++);
	  switch (tlvtype)
	    {
	    case RNGRSP_TIMING:
	      if (tlvlen == 4)
		{
		  tim = tvb_get_ntohl (tvb, pos);
		  proto_tree_add_int (rngrsp_tree,
				      hf_docsis_rngrsp_timing_adj, tvb, pos,
				      tlvlen, tim);
		}
	      else
		{
		  THROW (ReportedBoundsError);
		}
	      break;
	    case RNGRSP_PWR_LEVEL_ADJ:
	      if (tlvlen == 1)
		{
		  pwr = tvb_get_guint8 (tvb, pos);
		  proto_tree_add_int (rngrsp_tree, hf_docsis_rngrsp_power_adj,
				      tvb, pos, tlvlen, pwr);
		}
	      else
		{
		  THROW (ReportedBoundsError);
		}
	      break;
	    case RNGRSP_OFFSET_FREQ_ADJ:
	      if (tlvlen == 2)
		{
		  proto_tree_add_item (rngrsp_tree, hf_docsis_rngrsp_freq_adj,
				       tvb, pos, tlvlen, FALSE);
		}
	      else
		{
		  THROW (ReportedBoundsError);
		}
	      break;
	    case RNGRSP_TRANSMIT_EQ_ADJ:
	      proto_tree_add_item (rngrsp_tree, hf_docsis_rngrsp_xmit_eq_adj,
				   tvb, pos, tlvlen, FALSE);
	      break;
	    case RNGRSP_RANGING_STATUS:
	      if (tlvlen == 1)
		proto_tree_add_item (rngrsp_tree,
				     hf_docsis_rngrsp_ranging_status, tvb,
				     pos, tlvlen, FALSE);
	      else
		{
		  THROW (ReportedBoundsError);
		}
	      break;
	    case RNGRSP_DOWN_FREQ_OVER:
	      if (tlvlen == 4)
		proto_tree_add_item (rngrsp_tree,
				     hf_docsis_rngrsp_down_freq_over, tvb,
				     pos, tlvlen, FALSE);
	      else
		{
		  THROW (ReportedBoundsError);
		}
	      break;
	    case RNGRSP_UP_CHID_OVER:
	      if (tlvlen == 1)
		proto_tree_add_item (rngrsp_tree,
				     hf_docsis_rngrsp_upstream_ch_over, tvb,
				     pos, tlvlen, FALSE);
	      else
		{
		  THROW (ReportedBoundsError);
		}
	      break;

	    }			/* switch(tlvtype) */
	  pos = pos + tlvlen;
	}			/* while (pos < length) */
    }				/* if (tree) */
}




/* Register the protocol with Ethereal */

/* this format is require because a script is used to build the C function
   that calls all the protocol registration.
*/


void
proto_register_docsis_rngrsp (void)
{

/* Setup list of header fields  See Section 1.6.1 for details*/
  static hf_register_info hf[] = {
    {&hf_docsis_rngrsp,
     {"RNG-RSP Message", "docsis.rngrsp",
      FT_BYTES, BASE_HEX, NULL, 0x0,
      "Ranging Response Message", HFILL}
     },
    {&hf_docsis_rngrsp_sid,
     {"Service Identifier", "docsis.rngrsp.sid",
      FT_UINT16, BASE_DEC, NULL, 0x0,
      "Service Identifier", HFILL}
     },
    {&hf_docsis_rngrsp_upstream_chid,
     {"Upstream Channel ID", "docsis.rngrsp.upchid",
      FT_UINT8, BASE_DEC, NULL, 0x0,
      "Upstream Channel ID", HFILL}
     },
    {&hf_docsis_rngrsp_timing_adj,
     {"Timing Adjust (6.25us/64)", "docsis.rngrsp.timingadj",
      FT_INT32, BASE_DEC, NULL, 0x0,
      "Timing Adjust", HFILL}
     },
    {&hf_docsis_rngrsp_power_adj,
     {"Power Level Adjust (0.25dB units)", "docsis.rngrsp.poweradj",
      FT_INT8, BASE_DEC, NULL, 0x0,
      "Power Level Adjust", HFILL}
     },
    {&hf_docsis_rngrsp_freq_adj,
     {"Offset Freq Adjust (Hz)", "docsis.rngrsp.freqadj",
      FT_INT16, BASE_DEC, NULL, 0x0,
      "Frequency Adjust", HFILL}
     },
    {&hf_docsis_rngrsp_xmit_eq_adj,
     {"Transmit Equalisation Adjust", "docsis.rngrsp.xmit_eq_adj",
      FT_BYTES, BASE_HEX, NULL, 0x0,
      "Timing Equalisation Adjust", HFILL}
     },
    {&hf_docsis_rngrsp_ranging_status,
     {"Ranging Status", "docsis.rngrsp.rng_stat",
      FT_UINT8, BASE_DEC, VALS (rng_stat_vals), 0x0,
      "Ranging Status", HFILL}
     },
    {&hf_docsis_rngrsp_down_freq_over,
     {"Downstream Frequency Override (Hz)", "docsis.rngrsp.freq_over",
      FT_UINT32, BASE_DEC, NULL, 0x0,
      "Downstream Frequency Override", HFILL}
     },
    {&hf_docsis_rngrsp_upstream_ch_over,
     {"Upstream Channel ID Override", "docsis.rngrsp.chid_override",
      FT_UINT8, BASE_DEC, NULL, 0x0,
      "Upstream Channel ID Override", HFILL}
     },

  };

/* Setup protocol subtree array */
  static gint *ett[] = {
    &ett_docsis_rngrsp,
  };

/* Register the protocol name and description */
  proto_docsis_rngrsp = proto_register_protocol ("DOCSIS Ranging Response",
						 "DOCSIS RNG-RSP",
						 "docsis_rngrsp");

/* Required function calls to register the header fields and subtrees used */
  proto_register_field_array (proto_docsis_rngrsp, hf, array_length (hf));
  proto_register_subtree_array (ett, array_length (ett));

  register_dissector ("docsis_rngrsp", dissect_rngrsp, proto_docsis_rngrsp);
}


/* If this dissector uses sub-dissector registration add a registration routine.
   This format is required because a script is used to find these routines and
   create the code that calls these routines.
*/
void
proto_reg_handoff_docsis_rngrsp (void)
{
  dissector_handle_t docsis_rngrsp_handle;

  docsis_rngrsp_handle = find_dissector ("docsis_rngrsp");
  dissector_add ("docsis_mgmt", 0x05, docsis_rngrsp_handle);

}