(Minor) Remove unneeded #includes.
[obnox/wireshark/wip.git] / plugins / docsis / packet-macmgmt.c
1 /* packet-macmgmt.c
2  * Routines for docsis Mac Management Header dissection
3  * Copyright 2002, Anand V. Narwani <anand[AT]narwani.org>
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
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.
15  *
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.
20  *
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <epan/packet.h>
31
32 #define MGT_SYNC 1
33 #define MGT_UCD 2
34 #define MGT_MAP 3
35 #define MGT_RNG_REQ 4
36 #define MGT_RNG_RSP 5
37 #define MGT_REG_REQ 6
38 #define MGT_REG_RSP 7
39 #define MGT_UCC_REQ 8
40 #define MGT_UCC_RSP 9
41 #define MGT_TRI_TCD 10
42 #define MGT_TRI_TSI 11
43 #define MGT_BPKM_REQ 12
44 #define MGT_BPKM_RSP 13
45 #define MGT_REG_ACK 14
46 #define MGT_DSA_REQ 15
47 #define MGT_DSA_RSP 16
48 #define MGT_DSA_ACK 17
49 #define MGT_DSC_REQ 18
50 #define MGT_DSC_RSP 19
51 #define MGT_DSC_ACK 20
52 #define MGT_DSD_REQ 21
53 #define MGT_DSD_RSP 22
54 #define MGT_DCC_REQ 23
55 #define MGT_DCC_RSP 24
56 #define MGT_DCC_ACK 25
57 #define MGT_DCI_REQ 26
58 #define MGT_DCI_RSP 27
59 #define MGT_UP_DIS 28
60 #define MGT_TYPE29UCD 29
61 #define MGT_INIT_RNG_REQ 30
62 #define MGT_B_INIT_RNG_REQ 34
63
64
65 /* Initialize the protocol and registered fields */
66 static int proto_docsis_mgmt = -1;
67 static int hf_docsis_mgt_hdr = -1;
68 static int hf_docsis_mgt_dst_addr = -1;
69 static int hf_docsis_mgt_src_addr = -1;
70 static int hf_docsis_mgt_msg_len = -1;
71 static int hf_docsis_mgt_dsap = -1;
72 static int hf_docsis_mgt_ssap = -1;
73 static int hf_docsis_mgt_control = -1;
74 static int hf_docsis_mgt_version = -1;
75 static int hf_docsis_mgt_type = -1;
76 static int hf_docsis_mgt_rsvd = -1;
77
78 static dissector_table_t docsis_mgmt_dissector_table;
79 static dissector_handle_t data_handle;
80
81 /* Initialize the subtree pointers */
82 static gint ett_docsis_mgmt = -1;
83 static gint ett_mgmt_pay = -1;
84
85
86 static const value_string mgmt_type_vals[] = {
87   {MGT_SYNC, "Timing Synchronisation"},
88   {MGT_UCD, "Upstream Channel Descriptor"},
89   {MGT_TYPE29UCD, "Upstream Channel Descriptor Type 29"},
90   {MGT_MAP, "Upstream Bandwidth Allocation"},
91   {MGT_RNG_REQ, "Ranging Request"},
92   {MGT_RNG_RSP, "Ranging Response"},
93   {MGT_REG_REQ, "Registration Request"},
94   {MGT_REG_RSP, "Registration Response"},
95   {MGT_UCC_REQ, "Upstream Channel Change Request"},
96   {MGT_UCC_RSP, "Upstream Channel Change Response"},
97   {MGT_TRI_TCD, "Telephony Channel Descriptor"},
98   {MGT_TRI_TSI, "Termination System Information"},
99   {MGT_BPKM_REQ, "Privacy Key Management Request"},
100   {MGT_BPKM_RSP, "Privacy Key Management Response"},
101   {MGT_REG_ACK, "Registration Acknowledge"},
102   {MGT_DSA_REQ, "Dynamic Service Addition Request"},
103   {MGT_DSA_RSP, "Dynamic Service Addition Response"},
104   {MGT_DSA_ACK, "Dynamic Service Addition  Acknowledge"},
105   {MGT_DSC_REQ, "Dynamic Service Change Request"},
106   {MGT_DSC_RSP, "Dynamic Service Change Response"},
107   {MGT_DSC_ACK, "Dynamic Service Change Acknowledge"},
108   {MGT_DSD_REQ, "Dynamic Service Delete Request"},
109   {MGT_DSD_RSP, "Dynamic Service Delete Response"},
110   {MGT_DCC_REQ, "Dynamic Channel Change Request"},
111   {MGT_DCC_RSP, "Dynamic Channel Change Response"},
112   {MGT_DCC_ACK, "Dynamic Channel Change Acknowledge"},
113   {MGT_DCI_REQ, "Device Class Identification Request"},
114   {MGT_DCI_RSP, "Device Class Identification Response"},
115   {MGT_UP_DIS, "Upstream Channel Disable"},
116   {MGT_INIT_RNG_REQ, "Initial Ranging Request"},
117   {MGT_B_INIT_RNG_REQ, "Bonded Initial Ranging Request"},
118   {0, NULL}
119 };
120
121 /* Code to actually dissect the packets */
122 static void
123 dissect_macmgmt (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
124 {
125
126   const guint8 *src, *dst;
127   guint16 msg_len;
128   proto_item *mgt_hdr_it;
129   proto_tree *mgt_hdr_tree;
130   tvbuff_t *payload_tvb;
131   guint8 type;
132   col_set_str (pinfo->cinfo, COL_PROTOCOL, "DOCSIS MGMT");
133
134   col_clear(pinfo->cinfo, COL_INFO);
135
136
137   src = tvb_get_ptr (tvb, 6, 6);
138   dst = tvb_get_ptr (tvb, 0, 6);
139   SET_ADDRESS (&pinfo->dl_src, AT_ETHER, 6, src);
140   SET_ADDRESS (&pinfo->src, AT_ETHER, 6, src);
141   SET_ADDRESS (&pinfo->dl_dst, AT_ETHER, 6, dst);
142   SET_ADDRESS (&pinfo->dst, AT_ETHER, 6, dst);
143
144   if (tree)
145     {
146       mgt_hdr_it =
147         proto_tree_add_protocol_format (tree, proto_docsis_mgmt, tvb, 0, 20,
148                                         "Mac Management");
149       mgt_hdr_tree = proto_item_add_subtree (mgt_hdr_it, ett_docsis_mgmt);
150       proto_tree_add_item (mgt_hdr_tree, hf_docsis_mgt_dst_addr, tvb, 0, 6,
151                            FALSE);
152       proto_tree_add_item (mgt_hdr_tree, hf_docsis_mgt_src_addr, tvb, 6, 6,
153                            FALSE);
154       proto_tree_add_item (mgt_hdr_tree, hf_docsis_mgt_msg_len, tvb, 12, 2,
155                            FALSE);
156       proto_tree_add_item (mgt_hdr_tree, hf_docsis_mgt_dsap, tvb, 14, 1,
157                            FALSE);
158       proto_tree_add_item (mgt_hdr_tree, hf_docsis_mgt_ssap, tvb, 15, 1,
159                            FALSE);
160       proto_tree_add_item (mgt_hdr_tree, hf_docsis_mgt_control, tvb, 16, 1,
161                            FALSE);
162       proto_tree_add_item (mgt_hdr_tree, hf_docsis_mgt_version, tvb, 17, 1,
163                            FALSE);
164       proto_tree_add_item (mgt_hdr_tree, hf_docsis_mgt_type, tvb, 18, 1,
165                            FALSE);
166       proto_tree_add_item (mgt_hdr_tree, hf_docsis_mgt_rsvd, tvb, 19, 1,
167                            FALSE);
168
169     }
170   /* Code to Call subdissector */
171   /* sub-dissectors are based on the type field */
172   type = tvb_get_guint8 (tvb, 18);
173   msg_len = tvb_get_ntohs (tvb, 12);
174   payload_tvb = tvb_new_subset (tvb, 20, msg_len - 6, msg_len - 6);
175
176   if (dissector_try_port
177       (docsis_mgmt_dissector_table, type, payload_tvb, pinfo, tree))
178     return;
179   else
180     call_dissector (data_handle, payload_tvb, pinfo, tree);
181
182
183 }
184
185
186 /* Register the protocol with Wireshark */
187
188 /* this format is require because a script is used to build the C function
189    that calls all the protocol registration.
190 */
191
192
193 void
194 proto_register_docsis_mgmt (void)
195 {
196
197 /* Setup list of header fields  See Section 1.6.1 for details*/
198   static hf_register_info hf[] = {
199     {&hf_docsis_mgt_hdr,
200      {"Mac Management Header", "docsis_mgmt",
201       FT_BYTES, BASE_NONE, NULL, 0x0,
202       NULL, HFILL}
203      },
204     {&hf_docsis_mgt_dst_addr,
205      {"Destination Address", "docsis_mgmt.dst",
206       FT_ETHER, BASE_NONE, NULL, 0x0,
207       NULL, HFILL}
208      },
209     {&hf_docsis_mgt_src_addr,
210      {"Source Address", "docsis_mgmt.src",
211       FT_ETHER, BASE_NONE, NULL, 0x0,
212       NULL, HFILL}
213      },
214     {&hf_docsis_mgt_msg_len,
215      {"Message Length - DSAP to End (Bytes)", "docsis_mgmt.msglen",
216       FT_UINT16, BASE_DEC, NULL, 0x0,
217       "Message Length", HFILL}
218      },
219     {&hf_docsis_mgt_dsap,
220      {"DSAP [0x00]", "docsis_mgmt.dsap",
221       FT_UINT8, BASE_HEX, NULL, 0x0,
222       "Destination SAP", HFILL}
223      },
224     {&hf_docsis_mgt_ssap,
225      {"SSAP [0x00]", "docsis_mgmt.ssap",
226       FT_UINT8, BASE_HEX, NULL, 0x0,
227       "Source SAP", HFILL}
228      },
229     {&hf_docsis_mgt_control,
230      {"Control [0x03]", "docsis_mgmt.control",
231       FT_UINT8, BASE_HEX, NULL, 0x0,
232       "Control", HFILL}
233      },
234     {&hf_docsis_mgt_version,
235      {"Version", "docsis_mgmt.version",
236       FT_UINT8, BASE_DEC, NULL, 0x0,
237       NULL, HFILL}
238      },
239     {&hf_docsis_mgt_type,
240      {"Type", "docsis_mgmt.type",
241       FT_UINT8, BASE_DEC, VALS (mgmt_type_vals), 0x0,
242       NULL, HFILL}
243      },
244     {&hf_docsis_mgt_rsvd,
245      {"Reserved [0x00]", "docsis_mgmt.rsvd",
246       FT_UINT8, BASE_DEC, NULL, 0x0,
247       "Reserved", HFILL}
248      },
249
250   };
251
252 /* Setup protocol subtree array */
253   static gint *ett[] = {
254     &ett_docsis_mgmt,
255     &ett_mgmt_pay,
256   };
257
258   docsis_mgmt_dissector_table = register_dissector_table ("docsis_mgmt",
259                                                           "DOCSIS Mac Management",
260                                                           FT_UINT8, BASE_DEC);
261
262
263 /* Register the protocol name and description */
264   proto_docsis_mgmt = proto_register_protocol ("DOCSIS Mac Management",
265                                                "DOCSIS MAC MGMT",
266                                                "docsis_mgmt");
267
268 /* Required function calls to register the header fields and subtrees used */
269   proto_register_field_array (proto_docsis_mgmt, hf, array_length (hf));
270   proto_register_subtree_array (ett, array_length (ett));
271
272   register_dissector ("docsis_mgmt", dissect_macmgmt, proto_docsis_mgmt);
273 }
274
275
276 /* If this dissector uses sub-dissector registration add a registration routine.
277    This format is required because a script is used to find these routines and
278    create the code that calls these routines.
279 */
280 void
281 proto_reg_handoff_docsis_mgmt (void)
282 {
283   dissector_handle_t docsis_mgmt_handle;
284
285   docsis_mgmt_handle = find_dissector ("docsis_mgmt");
286   data_handle = find_dissector ("data");
287
288   dissector_add ("docsis", 0x03, docsis_mgmt_handle);
289 }