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