aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/docsis/packet-vendor.c
blob: e87ae16e426029ea30a9566f8599c09038fdf6a3 (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
/* packet-vendor.c
 * Routines for Vendor Specific Encodings dissection
 * Copyright 2002, Anand V. Narwani <anand[AT]narwani.org>
 *
 * 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.
 */


/* Notes to Adding dissectors for Vendor specific TLV's:
 * 1. Create a dissect_<vendorname> function with the following prototype:
 *   dissect_foovendor(tvbuff_t *tvb, proto_tree *tree, gint vsif_len)
 * 2. vsif_len will be the *entire* length of the vsif TLV (including the
 *   Vendor Id TLV, which is 5 bytes long).
 * 3. Create a new 'case' statement in dissect_vsif, for your specific Vendor
 *   id.
 * 4. In that 'case' statement you will make the following calls:
 *   (assume for this example that your vendor id is 0x000054)
 *   #define VENDOR_FOOVENDOR 0x00054
 *   case VENDOR_FOOVENDOR:
 *      proto_item_append_text (it, " (foo vendor)");
 *      dissect_foovendor (tvb, vsif_tree, vsif_len);
 *      break;
 * 5.  Please see dissect_cisco for an example of how to do this.
 */

#include "config.h"

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

/* Define Vendor ID's here */
#define VENDOR_CISCO 0x00000C

void proto_register_docsis_vsif(void);
void proto_reg_handoff_docsis_vsif(void);

/* Initialize the protocol and registered fields */
static int proto_docsis_vsif = -1;
static int hf_docsis_vsif_vendorid = -1;
static int hf_docsis_vsif_vendor_unknown = -1;
static int hf_docsis_vsif_cisco_numphones = -1;
/* static int hf_docsis_vsif_cisco_ipprec = -1; */
static int hf_docsis_vsif_cisco_ipprec_val = -1;
static int hf_docsis_vsif_cisco_ipprec_bw = -1;
static int hf_docsis_vsif_cisco_config_file = -1;

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

static const value_string vendorid_vals[] = {
  {VENDOR_CISCO, "Cisco Systems, Inc."},
  {0, NULL},
};

/* Forward Declarations for vendor specific dissectors */
static void dissect_cisco (tvbuff_t * tvb, proto_tree * tree,
                           gint vsif_len);

/* Dissection */
static int
dissect_vsif (tvbuff_t * tvb, packet_info * pinfo _U_, proto_tree * tree, void* data _U_)
{
  proto_item *it;
  proto_tree *vsif_tree;
  guint8 type;
  guint8 length;
  guint32 value;
  gint vsif_len;

  /* get the reported length of the VSIF TLV */
  vsif_len = tvb_reported_length_remaining (tvb, 0);

  /* The first TLV in the VSIF encodings must be type 0x08 (Vendor ID) and
   * length 3.
   */
  type = tvb_get_guint8 (tvb, 0);
  if (type != 0x08)
    {
      THROW (ReportedBoundsError);
    }

  length = tvb_get_guint8 (tvb, 1);
  if (length != 3)
    {
      THROW (ReportedBoundsError);
    }

  /* Extract the Value of the Vendor ID */
  value = tvb_get_ntoh24 (tvb, 2);
  if (tree)
    {
      it =
        proto_tree_add_protocol_format (tree, proto_docsis_vsif, tvb, 0, -1,
                                        "VSIF Encodings");
      vsif_tree = proto_item_add_subtree (it, ett_docsis_vsif);
      proto_tree_add_item (vsif_tree, hf_docsis_vsif_vendorid, tvb, 2, 3, ENC_BIG_ENDIAN);

      /* switch on the Vendor ID */
      switch (value)
        {
          case VENDOR_CISCO:
            proto_item_append_text (it, " (Cisco)");
            dissect_cisco (tvb, vsif_tree, vsif_len);
            break;
          default:
            proto_item_append_text (it, " (Unknown)");
            proto_tree_add_item (vsif_tree, hf_docsis_vsif_vendor_unknown, tvb,
                                 0, -1, ENC_NA);
            break;
        }

    }                           /* if(tree) */

    return tvb_captured_length(tvb);
}

/* Dissector for Cisco Vendor Specific TLV's */

#define NUM_PHONES      0x0a
#define IOS_CONFIG_FILE 0x80
#define IP_PREC         0x0b
#define IP_PREC_VAL     0x01
#define IP_PREC_BW      0x02

static void
dissect_cisco (tvbuff_t * tvb, proto_tree * tree, gint vsif_len)
{
  /* Start at pos = 5, since tvb includes the Vendor ID field */
  int pos = 5;
  guint8 type, length;
  proto_tree *ipprec_tree;
  int templen;

  while (pos < vsif_len)
    {
      /* Extract the type and length Fields from the TLV */
      type = tvb_get_guint8 (tvb, pos++);
      length = tvb_get_guint8 (tvb, pos++);
      switch (type)
        {
          case NUM_PHONES:
            proto_tree_add_item (tree, hf_docsis_vsif_cisco_numphones, tvb,
                                 pos, length, ENC_BIG_ENDIAN);
            break;
          case IP_PREC:
            ipprec_tree =
              proto_tree_add_subtree(tree, tvb, pos, length, ett_docsis_vsif_ipprec, NULL, "IP Precedence");
            /* Handle Sub-TLVs in IP Precedence */
            templen = pos + length;
            while (pos < templen)
              {
                type = tvb_get_guint8 (tvb, pos++);
                length = tvb_get_guint8 (tvb, pos++);
                switch (type)
                  {
                    case IP_PREC_VAL:
                      if (length != 1)
                        THROW (ReportedBoundsError);
                      proto_tree_add_item (ipprec_tree,
                                           hf_docsis_vsif_cisco_ipprec_val, tvb,
                                           pos, length, ENC_BIG_ENDIAN);
                      break;
                    case IP_PREC_BW:
                      if (length != 4)
                        THROW (ReportedBoundsError);
                      proto_tree_add_item (ipprec_tree,
                                           hf_docsis_vsif_cisco_ipprec_bw, tvb,
                                           pos, length, ENC_BIG_ENDIAN);
                      break;
                    default:
                      THROW (ReportedBoundsError);
                  }
                pos += length;
              }
            break;
          case IOS_CONFIG_FILE:
            proto_tree_add_item (tree, hf_docsis_vsif_cisco_config_file, tvb,
                                 pos, length, ENC_ASCII|ENC_NA);
        }
      pos += length;
    }
}

/* Register the protocol with Wireshark */
void
proto_register_docsis_vsif (void)
{
  static hf_register_info hf[] = {
    {&hf_docsis_vsif_vendorid,
     {"Vendor Id", "docsis_vsif.vendorid",
      FT_UINT24, BASE_HEX, VALS(vendorid_vals), 0x0,
      "Vendor Identifier", HFILL}
    },
    {&hf_docsis_vsif_vendor_unknown,
     {"VSIF Encodings", "docsis_vsif.unknown",
      FT_BYTES, BASE_NONE, NULL, 0x0,
      "Unknown Vendor", HFILL}
    },
    {&hf_docsis_vsif_cisco_numphones,
     {"Number of phone lines", "docsis_vsif.cisco.numphones",
      FT_UINT8, BASE_DEC, NULL, 0x0,
      NULL, HFILL}
    },
#if 0
    {&hf_docsis_vsif_cisco_ipprec,
     {"IP Precedence Encodings", "docsis_vsif.cisco.ipprec",
      FT_BYTES, BASE_NONE, NULL, 0x0,
      NULL, HFILL}
    },
#endif
    {&hf_docsis_vsif_cisco_ipprec_val,
     {"IP Precedence Value", "docsis_vsif.cisco.ipprec.value",
      FT_UINT8, BASE_DEC, NULL, 0x0,
      NULL, HFILL}
    },
    {&hf_docsis_vsif_cisco_ipprec_bw,
     {"IP Precedence Bandwidth", "docsis_vsif.cisco.ipprec.bw",
      FT_UINT8, BASE_DEC, NULL, 0x0,
      NULL, HFILL}
    },
    {&hf_docsis_vsif_cisco_config_file,
     {"IOS Config File", "docsis_vsif.cisco.iosfile",
      FT_STRING, BASE_NONE, NULL, 0x0,
      NULL, HFILL}
    },
  };

  static gint *ett[] = {
    &ett_docsis_vsif,
    &ett_docsis_vsif_ipprec,
  };

  proto_docsis_vsif =
    proto_register_protocol ("DOCSIS Vendor Specific Encodings",
                             "DOCSIS VSIF", "docsis_vsif");

  proto_register_field_array (proto_docsis_vsif, hf, array_length (hf));
  proto_register_subtree_array (ett, array_length (ett));

  register_dissector ("docsis_vsif", dissect_vsif, proto_docsis_vsif);
}

void
proto_reg_handoff_docsis_vsif (void)
{
#if 0
  dissector_handle_t docsis_vsif_handle;

  docsis_vsif_handle = find_dissector ("docsis_vsif");
  dissector_add_uint ("docsis", 0xFD, docsis_vsif_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:
 */