aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/docsis/packet-tlv-cmctrl.c
blob: b51d6d2a04dce0338810862084a269977a0a7672 (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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
/* packet-tlv-cmctrl.c
 * Routines to Dissect TLV's for CM-Control Messages
 * Copyright 2010, Guido Reismueller <g.reismueller[AT]avm.de>
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "config.h"

#include <epan/packet.h>
#include <epan/expert.h>

#define CM_CTRL_MUTE 1
#define CM_CTRL_MUTE_TIMEOUT 2
#define CM_CTRL_REINIT 3
#define CM_CTRL_DISABLE_FWD 4
#define CM_CTRL_DS_EVENT 5
#define CM_CTRL_US_EVENT 6
#define CM_CTRL_EVENT 7

#define DS_EVENT_CH_ID 1
#define DS_EVENT_MASK 2

#define US_EVENT_CH_ID 1
#define US_EVENT_MASK 2

void proto_register_cmctrl_tlv(void);
void proto_reg_handoff_cmctrl_tlv(void);

/* Initialize the protocol and registered fields */
static int proto_cmctrl_tlv = -1;
static int hf_cmctrl_tlv_mute = -1;
static int hf_cmctrl_tlv_mute_timeout = -1;
static int hf_cmctrl_tlv_reinit = -1;
static int hf_cmctrl_tlv_disable_fwd = -1;
static int hf_cmctrl_tlv_ds_event = -1;
/* static int hf_cmctrl_tlv_us_event = -1; */
static int hf_cmctrl_tlv_event = -1;

static int hf_ds_event_ch_id = -1;
static int hf_ds_event_mask = -1;

static int hf_us_event_ch_id = -1;
static int hf_us_event_mask = -1;

/* Initialize the subtree pointers */
static gint ett_cmctrl_tlv = -1;
static gint ett_cmctrl_tlv_ds_event = -1;
static gint ett_cmctrl_tlv_us_event = -1;

static expert_field ei_docsis_cmctrl_tlv_tlvlen_bad = EI_INIT;

/* Dissection */
static void
dissect_ds_event(tvbuff_t * tvb, packet_info* pinfo, proto_tree *tree, int start, guint16 len)
{
  guint8 type, length;
  proto_tree *event_tree;
  proto_item *event_item;
  int pos = start;

  event_tree =
    proto_tree_add_subtree_format(tree, tvb, start, len, ett_cmctrl_tlv_ds_event, &event_item,
                         "Override Downstream Status Event Event Mask (Length = %u)", len);

  while (pos < (start + len))
    {
      type = tvb_get_guint8 (tvb, pos++);
      length = tvb_get_guint8 (tvb, pos++);
      switch (type)
        {
        case DS_EVENT_CH_ID:
      if (length == 1)
        {
          proto_tree_add_item (event_tree, hf_ds_event_ch_id,
                               tvb, pos, length, ENC_BIG_ENDIAN);
        }
      else
        {
          expert_add_info_format(pinfo, event_item, &ei_docsis_cmctrl_tlv_tlvlen_bad, "Wrong TLV length: %u", length);
        }
          break;
        case DS_EVENT_MASK:
      if (length == 2)
        {
          proto_tree_add_item (event_tree, hf_ds_event_mask,
                               tvb, pos, length, ENC_NA);
        }
      else
        {
          expert_add_info_format(pinfo, event_item, &ei_docsis_cmctrl_tlv_tlvlen_bad, "Wrong TLV length: %u", length);
        }
          break;
        }                       /* switch */
      pos = pos + length;
    }                           /* while */
}

static void
dissect_us_event(tvbuff_t * tvb, packet_info* pinfo, proto_tree *tree, int start, guint16 len)
{
  guint8 type, length;
  proto_tree *event_tree;
  proto_item *event_item;
  int pos = start;

  event_tree =
    proto_tree_add_subtree_format(tree, tvb, start, len, ett_cmctrl_tlv_us_event, &event_item,
                         "Override Upstream Status Enable Event Mask (Length = %u)", len);

  while (pos < (start + len))
    {
      type = tvb_get_guint8 (tvb, pos++);
      length = tvb_get_guint8 (tvb, pos++);
      switch (type)
        {
        case US_EVENT_CH_ID:
      if (length == 1)
        {
          proto_tree_add_item (event_tree, hf_us_event_ch_id,
                               tvb, pos, length, ENC_BIG_ENDIAN);
        }
      else
        {
          expert_add_info_format(pinfo, event_item, &ei_docsis_cmctrl_tlv_tlvlen_bad, "Wrong TLV length: %u", length);
        }
          break;
        case US_EVENT_MASK:
      if (length == 2)
        {
          proto_tree_add_item (event_tree, hf_us_event_mask,
                               tvb, pos, length, ENC_NA);
        }
      else
        {
          expert_add_info_format(pinfo, event_item, &ei_docsis_cmctrl_tlv_tlvlen_bad, "Wrong TLV length: %u", length);
        }
          break;
        }                       /* switch */
      pos = pos + length;
    }                           /* while */
}

static int
dissect_cmctrl_tlv (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void* data _U_)
{
  proto_item *it;
  proto_tree *tlv_tree;
  int pos = 0;
  gint total_len;
  guint8 type, length;

  total_len = tvb_reported_length_remaining (tvb, 0);

  it =
    proto_tree_add_protocol_format (tree, proto_cmctrl_tlv, tvb, 0,
                                    total_len, "TLV Data");
  tlv_tree = proto_item_add_subtree (it, ett_cmctrl_tlv);

  while (pos < total_len)
    {
      type = tvb_get_guint8 (tvb, pos++);
      length = tvb_get_guint8 (tvb, pos++);
      switch (type)
        {
        case CM_CTRL_MUTE:
          if (length == 1)
            {
              proto_tree_add_item (tlv_tree, hf_cmctrl_tlv_mute,
                                   tvb, pos, length, ENC_BIG_ENDIAN);
            }
          else
            {
              expert_add_info_format(pinfo, it, &ei_docsis_cmctrl_tlv_tlvlen_bad, "Wrong TLV length: %u", length);
            }
          break;
        case CM_CTRL_MUTE_TIMEOUT:
          if (length == 4 || length == 1) /* response TLV always with len 1 */
            {
              proto_tree_add_item (tlv_tree, hf_cmctrl_tlv_mute_timeout,
                                   tvb, pos, length, ENC_BIG_ENDIAN);
            }
          else
            {
              expert_add_info_format(pinfo, it, &ei_docsis_cmctrl_tlv_tlvlen_bad, "Wrong TLV length: %u", length);
            }
          break;
        case CM_CTRL_REINIT:
          if (length == 1)
            {
              proto_tree_add_item (tlv_tree, hf_cmctrl_tlv_reinit,
                                   tvb, pos, length, ENC_BIG_ENDIAN);
            }
          else
            {
               expert_add_info_format(pinfo, it, &ei_docsis_cmctrl_tlv_tlvlen_bad, "Wrong TLV length: %u", length);
            }
          break;
        case CM_CTRL_DISABLE_FWD:
          if (length == 1)
            {
              proto_tree_add_item (tlv_tree, hf_cmctrl_tlv_disable_fwd,
                                   tvb, pos, length, ENC_BIG_ENDIAN);
            }
          else
            {
               expert_add_info_format(pinfo, it, &ei_docsis_cmctrl_tlv_tlvlen_bad, "Wrong TLV length: %u", length);
            }
          break;
        case CM_CTRL_DS_EVENT:
          if (length == 1)
            proto_tree_add_item (tlv_tree, hf_cmctrl_tlv_ds_event,
                                 tvb, pos, length, ENC_NA);
          else
            dissect_ds_event(tvb, pinfo, tlv_tree, pos, length);
          break;
        case CM_CTRL_US_EVENT:
          if (length == 1)
            proto_tree_add_item (tlv_tree, hf_cmctrl_tlv_ds_event,
                                 tvb, pos, length, ENC_NA);
          else
            dissect_us_event(tvb, pinfo, tlv_tree, pos, length);
          break;
        case CM_CTRL_EVENT:
          if (length == 2 || length == 1) /* response TLV always with len 1 */
            {
              proto_tree_add_item (tlv_tree, hf_cmctrl_tlv_event,
                                   tvb, pos, length, ENC_NA);
            }
          else
            {
               expert_add_info_format(pinfo, it, &ei_docsis_cmctrl_tlv_tlvlen_bad, "Wrong TLV length: %u", length);
            }
          break;

        } /* switch */
      pos = pos + length;
    } /* while */
    return tvb_captured_length(tvb);
}

/* Register the protocol with Wireshark */
void
proto_register_cmctrl_tlv (void)
{
  static hf_register_info hf[] = {
    {&hf_cmctrl_tlv_mute,
     {"1 Upstream Channel RF Mute", "cmctrl_tlv.mute",
      FT_UINT8, BASE_DEC, NULL, 0x0,
      "Upstream Channel RF Mute", HFILL}
    },
    {&hf_cmctrl_tlv_mute_timeout,
     {"2 RF Mute Timeout Interval", "cmctrl_tlv.mute_timeout",
      FT_UINT32, BASE_DEC, NULL, 0x0,
      "RF Mute Timeout Interval", HFILL}
    },
    {&hf_cmctrl_tlv_reinit,
     {"3 CM Reinitialize", "cmctrl_tlv.reinit",
      FT_UINT8, BASE_DEC, NULL, 0x0,
      "CM Reinitialize", HFILL}
    },
    {&hf_cmctrl_tlv_disable_fwd,
     {"4 Disable Forwarding", "cmctrl_tlv.disable_fwd",
      FT_UINT8, BASE_DEC, NULL, 0x0,
      "Disable Forwarding", HFILL}
    },
    {&hf_cmctrl_tlv_ds_event,
     {"5 Override Downstream Events", "cmctrl_tlv.ds_event",
      FT_BYTES, BASE_NONE, NULL, 0x0,
      "Override Downstream Events", HFILL}
    },
    {&hf_ds_event_ch_id,
     {".1 Downstream Channel ID", "cmctrl_tlv.ds_event.chid",
      FT_UINT8, BASE_DEC, NULL, 0x0,
      "Downstream Channel ID", HFILL}
    },
    {&hf_ds_event_mask,
     {".2 Downstream Status Event Enable Bitmask", "cmctrl_tlv.ds_event.mask",
      FT_BYTES, BASE_NONE, NULL, 0x0,
      "Downstream Status Event Enable Bitmask", HFILL}
    },
#if 0
    {&hf_cmctrl_tlv_us_event,
     {"6 Override Upstream Events", "cmctrl_tlv.us_event",
      FT_BYTES, BASE_NONE, NULL, 0x0,
      "Override Downstream Events", HFILL}
    },
#endif
    {&hf_us_event_ch_id,
     {".1 Upstream Channel ID", "cmctrl_tlv.us_event.chid",
      FT_UINT8, BASE_DEC, NULL, 0x0,
      "Upstream Channel ID", HFILL}
    },
    {&hf_us_event_mask,
     {".2 Upstream Status Event Enable Bitmask", "cmctrl_tlv.us_event.mask",
      FT_BYTES, BASE_NONE, NULL, 0x0,
      "Upstream Status Event Enable Bitmask", HFILL}
    },
    {&hf_cmctrl_tlv_event,
     {"7 Override Non-Channel-Specific Events", "cmctrl_tlv.event",
      FT_BYTES, BASE_NONE, NULL, 0x0,
      "Override Non-Channel-Specific Events", HFILL}
    },
  };

  static gint *ett[] = {
    &ett_cmctrl_tlv,
    &ett_cmctrl_tlv_ds_event,
    &ett_cmctrl_tlv_us_event,
  };

  static ei_register_info ei[] = {
    {&ei_docsis_cmctrl_tlv_tlvlen_bad, { "cmctrl_tlv.tlvlenbad", PI_MALFORMED, PI_ERROR, "Bad TLV length", EXPFILL}},
  };

  expert_module_t* expert_docsis_cmctrl_tlv;

  proto_cmctrl_tlv = proto_register_protocol ("DOCSIS CM-CTRL TLV's",
                                              "DOCSIS CM-CTRL TLVs", "cmctrl_tlv");

  proto_register_field_array (proto_cmctrl_tlv, hf, array_length (hf));
  proto_register_subtree_array (ett, array_length (ett));
  expert_docsis_cmctrl_tlv = expert_register_protocol(proto_cmctrl_tlv);
  expert_register_field_array(expert_docsis_cmctrl_tlv, ei, array_length(ei));

  register_dissector ("cmctrl_tlv", dissect_cmctrl_tlv, proto_cmctrl_tlv);
}

void
proto_reg_handoff_cmctrl_tlv (void)
{
#if 0
  dissector_handle_t cmctrl_tlv_handle;

  cmctrl_tlv_handle = find_dissector ("cmctrl_tlv");

  dissector_add_uint ("docsis", 0xFE, cmctrl_tlv_handle);
#endif
}

/*
 * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
 *
 * Local Variables:
 * c-basic-offset: 2
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * ex: set shiftwidth=2 tabstop=8 expandtab:
 * :indentSize=2:tabSize=8:noTabs=true:
 */