aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/docsis/packet-macmgmt.c
blob: fbf6c2cdea4b803642e4f5c69ea6aba577333bb5 (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
/* packet-macmgmt.c
 * Routines for docsis Mac Management Header 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 <glib.h>

#include <epan/packet.h>

#define MGT_SYNC 1
#define MGT_UCD 2
#define MGT_MAP 3
#define MGT_RNG_REQ 4
#define MGT_RNG_RSP 5
#define MGT_REG_REQ 6
#define MGT_REG_RSP 7
#define MGT_UCC_REQ 8
#define MGT_UCC_RSP 9
#define MGT_TRI_TCD 10
#define MGT_TRI_TSI 11
#define MGT_BPKM_REQ 12
#define MGT_BPKM_RSP 13
#define MGT_REG_ACK 14
#define MGT_DSA_REQ 15
#define MGT_DSA_RSP 16
#define MGT_DSA_ACK 17
#define MGT_DSC_REQ 18
#define MGT_DSC_RSP 19
#define MGT_DSC_ACK 20
#define MGT_DSD_REQ 21
#define MGT_DSD_RSP 22
#define MGT_DCC_REQ 23
#define MGT_DCC_RSP 24
#define MGT_DCC_ACK 25
#define MGT_DCI_REQ 26
#define MGT_DCI_RSP 27
#define MGT_UP_DIS 28
#define MGT_TYPE29UCD 29


/* Initialize the protocol and registered fields */
static int proto_docsis_mgmt = -1;
static int hf_docsis_mgt_hdr = -1;
static int hf_docsis_mgt_dst_addr = -1;
static int hf_docsis_mgt_src_addr = -1;
static int hf_docsis_mgt_msg_len = -1;
static int hf_docsis_mgt_dsap = -1;
static int hf_docsis_mgt_ssap = -1;
static int hf_docsis_mgt_control = -1;
static int hf_docsis_mgt_version = -1;
static int hf_docsis_mgt_type = -1;
static int hf_docsis_mgt_rsvd = -1;

static dissector_table_t docsis_mgmt_dissector_table;
static dissector_handle_t data_handle;

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


static const value_string mgmt_type_vals[] = {
  {MGT_SYNC, "Timing Synchronisation"},
  {MGT_UCD, "Upstream Channel Descriptor"},
  {MGT_TYPE29UCD, "Upstream Channel Descriptor Type 29"},
  {MGT_MAP, "Upstream Bandwidth Allocation"},
  {MGT_RNG_REQ, "Ranging Request"},
  {MGT_RNG_RSP, "Ranging Response"},
  {MGT_REG_REQ, "Registration Request"},
  {MGT_REG_RSP, "Registration Response"},
  {MGT_UCC_REQ, "Upstream Channel Change Request"},
  {MGT_UCC_RSP, "Upstream Channel Change Response"},
  {MGT_TRI_TCD, "Telephony Channel Descriptor"},
  {MGT_TRI_TSI, "Termination System Information"},
  {MGT_BPKM_REQ, "Privacy Key Management Request"},
  {MGT_BPKM_RSP, "Privacy Key Management Response"},
  {MGT_REG_ACK, "Registration Acknowledge"},
  {MGT_DSA_REQ, "Dynamic Service Addition Request"},
  {MGT_DSA_RSP, "Dynamic Service Addition Response"},
  {MGT_DSA_ACK, "Dynamic Service Addition  Acknowledge"},
  {MGT_DSC_REQ, "Dynamic Service Change Request"},
  {MGT_DSC_RSP, "Dynamic Service Change Response"},
  {MGT_DSC_ACK, "Dynamic Service Change Acknowledge"},
  {MGT_DSD_REQ, "Dynamic Service Delete Request"},
  {MGT_DSD_RSP, "Dynamic Service Delete Response"},
  {MGT_DCC_REQ, "Dynamic Channel Change Request"},
  {MGT_DCC_RSP, "Dynamic Channel Change Response"},
  {MGT_DCC_ACK, "Dynamic Channel Change Acknowledge"},
  {MGT_DCI_REQ, "Device Class Identification Request"},
  {MGT_DCI_RSP, "Device Class Identification Response"},
  {MGT_UP_DIS, "Upstream Channel Disable"},
  {0, NULL}
};

/* Code to actually dissect the packets */
static void
dissect_macmgmt (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
{

  const guint8 *src, *dst;
  guint16 msg_len;
  proto_item *mgt_hdr_it;
  proto_tree *mgt_hdr_tree;
  tvbuff_t *payload_tvb;
  guint8 type;
  if (check_col (pinfo->cinfo, COL_PROTOCOL))
    col_set_str (pinfo->cinfo, COL_PROTOCOL, "DOCSIS MGMT");

  if (check_col (pinfo->cinfo, COL_INFO))
    col_clear (pinfo->cinfo, COL_INFO);


  src = tvb_get_ptr (tvb, 6, 6);
  dst = tvb_get_ptr (tvb, 0, 6);
  SET_ADDRESS (&pinfo->dl_src, AT_ETHER, 6, src);
  SET_ADDRESS (&pinfo->src, AT_ETHER, 6, src);
  SET_ADDRESS (&pinfo->dl_dst, AT_ETHER, 6, dst);
  SET_ADDRESS (&pinfo->dst, AT_ETHER, 6, dst);

  if (tree)
    {
      mgt_hdr_it =
	proto_tree_add_protocol_format (tree, proto_docsis_mgmt, tvb, 0, 20,
					"Mac Management");
      mgt_hdr_tree = proto_item_add_subtree (mgt_hdr_it, ett_docsis_mgmt);
      proto_tree_add_item (mgt_hdr_tree, hf_docsis_mgt_dst_addr, tvb, 0, 6,
			   FALSE);
      proto_tree_add_item (mgt_hdr_tree, hf_docsis_mgt_src_addr, tvb, 6, 6,
			   FALSE);
      proto_tree_add_item (mgt_hdr_tree, hf_docsis_mgt_msg_len, tvb, 12, 2,
			   FALSE);
      proto_tree_add_item (mgt_hdr_tree, hf_docsis_mgt_dsap, tvb, 14, 1,
			   FALSE);
      proto_tree_add_item (mgt_hdr_tree, hf_docsis_mgt_ssap, tvb, 15, 1,
			   FALSE);
      proto_tree_add_item (mgt_hdr_tree, hf_docsis_mgt_control, tvb, 16, 1,
			   FALSE);
      proto_tree_add_item (mgt_hdr_tree, hf_docsis_mgt_version, tvb, 17, 1,
			   FALSE);
      proto_tree_add_item (mgt_hdr_tree, hf_docsis_mgt_type, tvb, 18, 1,
			   FALSE);
      proto_tree_add_item (mgt_hdr_tree, hf_docsis_mgt_rsvd, tvb, 19, 1,
			   FALSE);

    }
  /* Code to Call subdissector */
  /* sub-dissectors are based on the type field */
  type = tvb_get_guint8 (tvb, 18);
  msg_len = tvb_get_ntohs (tvb, 12);
  payload_tvb = tvb_new_subset (tvb, 20, msg_len - 6, msg_len - 6);

  if (dissector_try_port
      (docsis_mgmt_dissector_table, type, payload_tvb, pinfo, tree))
    return;
  else
    call_dissector (data_handle, payload_tvb, pinfo, 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_mgmt (void)
{

/* Setup list of header fields  See Section 1.6.1 for details*/
  static hf_register_info hf[] = {
    {&hf_docsis_mgt_hdr,
     {"Mac Management Header", "docsis.mgmt",
      FT_BYTES, BASE_HEX, NULL, 0x0,
      "Mac Management Header", HFILL}
     },
    {&hf_docsis_mgt_dst_addr,
     {"Destination Address", "docsis.mgmt.dst",
      FT_ETHER, BASE_HEX, NULL, 0x0,
      "Destination Address", HFILL}
     },
    {&hf_docsis_mgt_src_addr,
     {"Source Address", "docsis.mgmt.src",
      FT_ETHER, BASE_HEX, NULL, 0x0,
      "Source Address", HFILL}
     },
    {&hf_docsis_mgt_msg_len,
     {"Message Length - DSAP to End (Bytes)", "docsis.mgmt.msglen",
      FT_UINT16, BASE_DEC, NULL, 0x0,
      "Message Length", HFILL}
     },
    {&hf_docsis_mgt_dsap,
     {"DSAP [0x00]", "docsis.mgmt.dsap",
      FT_UINT8, BASE_HEX, NULL, 0x0,
      "Destination SAP", HFILL}
     },
    {&hf_docsis_mgt_ssap,
     {"SSAP [0x00]", "docsis.mgmt.ssap",
      FT_UINT8, BASE_HEX, NULL, 0x0,
      "Source SAP", HFILL}
     },
    {&hf_docsis_mgt_control,
     {"Control [0x03]", "docsis.mgmt.control",
      FT_UINT8, BASE_HEX, NULL, 0x0,
      "Control", HFILL}
     },
    {&hf_docsis_mgt_version,
     {"Version", "docsis.mgmt.version",
      FT_UINT8, BASE_DEC, NULL, 0x0,
      "Version", HFILL}
     },
    {&hf_docsis_mgt_type,
     {"Type", "docsis.mgmt.type",
      FT_UINT8, BASE_DEC, VALS (mgmt_type_vals), 0x0,
      "Type", HFILL}
     },
    {&hf_docsis_mgt_rsvd,
     {"Reserved [0x00]", "docsis.mgmt.rsvd",
      FT_UINT8, BASE_DEC, NULL, 0x0,
      "Reserved", HFILL}
     },

  };

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

  docsis_mgmt_dissector_table = register_dissector_table ("docsis_mgmt",
							  "DOCSIS Mac Management",
							  FT_UINT8, BASE_DEC);


/* Register the protocol name and description */
  proto_docsis_mgmt = proto_register_protocol ("DOCSIS Mac Management",
					       "DOCSIS MAC MGMT",
					       "docsis_mgmt");

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

  register_dissector ("docsis_mgmt", dissect_macmgmt, proto_docsis_mgmt);
}


/* 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_mgmt (void)
{
  dissector_handle_t docsis_mgmt_handle;

  docsis_mgmt_handle = find_dissector ("docsis_mgmt");
  data_handle = find_dissector ("data");

  dissector_add ("docsis", 0x03, docsis_mgmt_handle);
}