HACK: 2nd try to match RowsetProperties
[wireshark-wip.git] / epan / dissectors / packet-asf.c
blobb03ab52d2588ddd15222bdec5bd6ad7d6bee712e
1 /* packet-asf.c
2 * Routines for ASF packet dissection
4 * Duncan Laurie <duncan@sun.com>
6 * $Id$
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * Copied from packet-rmcp.c
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include "config.h"
31 #include <glib.h>
32 #include <epan/packet.h>
33 #include <epan/expert.h>
34 #include <epan/sminmpec.h>
37 * See
38 * http://www.dmtf.org/standards/standard_alert.php
39 * http://www.dmtf.org/standards/documents/ASF/DSP0136.pdf
42 void proto_register_asf(void);
43 void proto_reg_handoff_asf(void);
45 #define RMCP_CLASS_ASF 0x06
47 static int proto_asf = -1;
48 static int hf_asf_iana = -1;
49 static int hf_asf_type = -1;
50 static int hf_asf_tag = -1;
51 static int hf_asf_len = -1;
52 static int hf_asf_rssp_status_code = -1;
53 static int hf_asf_mgt_console_id = -1;
54 static int hf_asf_client_id = -1;
55 static int hf_asf_payload = -1;
56 static int hf_asf_payload_type = -1;
57 static int hf_asf_payload_len = -1;
58 static int hf_asf_payload_data = -1;
59 static int hf_asf_auth_alg = -1;
60 static int hf_asf_integrity_alg = -1;
61 static int hf_asf_reserved = -1;
63 static dissector_handle_t data_handle;
64 static gint ett_asf = -1;
65 static gint ett_asf_payload = -1;
66 static gint ett_asf_alg_payload = -1;
68 static expert_field ei_asf_payload_too_short = EI_INIT;
71 #define ASF_TYPE_RESET 0x10
72 #define ASF_TYPE_PWR_UP 0x11
73 #define ASF_TYPE_PWR_DOWN 0x12
74 #define ASF_TYPE_PWR_CYCLE 0x13
75 #define ASF_TYPE_PRES_PONG 0x40
76 #define ASF_TYPE_CAP_RESP 0x41
77 #define ASF_TYPE_SYS_STATE_RESP 0x42
78 #define ASF_TYPE_OPEN_SESS_RESP 0x43
79 #define ASF_TYPE_CLOSE_SESS_RESP 0x44
80 #define ASF_TYPE_PRES_PING 0x80
81 #define ASF_TYPE_CAP_RQST 0x81
82 #define ASF_TYPE_SYS_STATE_RQST 0x82
83 #define ASF_TYPE_OPEN_SESS_RQST 0x83
84 #define ASF_TYPE_CLOSE_SESS_RQST 0x84
85 #define ASF_TYPE_RAKP_MSG_1 0xC0
86 #define ASF_TYPE_RAKP_MSG_2 0xC1
87 #define ASF_TYPE_RAKP_MSG_3 0xC2
89 static const value_string asf_type_vals[] = {
90 { ASF_TYPE_RESET, "Reset" },
91 { ASF_TYPE_PWR_UP, "Power-up" },
92 { ASF_TYPE_PWR_DOWN, "Unconditional Power-down" },
93 { ASF_TYPE_PWR_CYCLE, "Power Cycle" },
94 { ASF_TYPE_PRES_PONG, "Presence Pong" },
95 { ASF_TYPE_CAP_RESP, "Capabilities Response" },
96 { ASF_TYPE_SYS_STATE_RESP, "System State Response" },
97 { ASF_TYPE_OPEN_SESS_RESP, "Open Session Response" },
98 { ASF_TYPE_CLOSE_SESS_RESP, "Close Session Response" },
99 { ASF_TYPE_PRES_PING, "Presence Ping" },
100 { ASF_TYPE_CAP_RQST, "Capabilities Request" },
101 { ASF_TYPE_SYS_STATE_RQST, "System State Request" },
102 { ASF_TYPE_OPEN_SESS_RQST, "Open Session Request" },
103 { ASF_TYPE_CLOSE_SESS_RQST, "Close Session Request" },
104 { ASF_TYPE_RAKP_MSG_1, "RAKP Message 1" },
105 { ASF_TYPE_RAKP_MSG_2, "RAKP Message 2" },
106 { ASF_TYPE_RAKP_MSG_3, "RAKP Message 3" },
107 { 0x00, NULL }
110 static const value_string asf_rssp_status_code_vals[] = {
111 { 0x00, "No errors" },
112 { 0x01, "Insufficient resources to create a session" },
113 { 0x02, "Invalid session ID" },
114 { 0x03, "Invalid payload type" },
115 { 0x04, "Invalid authentication algorithm" },
116 { 0x05, "Invalid integrity algorithm" },
117 { 0x06, "No matching authentication payload" },
118 { 0x07, "No matching integrity payload" },
119 { 0x00, NULL }
122 #define ASF_PAYLOAD_TYPE_NONE 0x00
123 #define ASF_PAYLOAD_TYPE_AUTHENTICATION 0x01
124 #define ASF_PAYLOAD_TYPE_INTEGRITY 0x02
126 static const value_string asf_payload_type_vals[] = {
127 { ASF_PAYLOAD_TYPE_NONE, "No payload present (end of list)" },
128 { ASF_PAYLOAD_TYPE_AUTHENTICATION, "Authentication algorithm payload" },
129 { ASF_PAYLOAD_TYPE_INTEGRITY, "Integrity algorithm payload" },
130 { 0x00, NULL }
133 static const value_string asf_authentication_type_vals[] = {
134 { 0x01, "RAKP-HMAC-SHA1" },
135 { 0x00, NULL }
138 static const value_string asf_integrity_type_vals[] = {
139 { 0x01, "HMAC-SHA1-96" },
140 { 0x00, NULL }
143 static void dissect_asf_open_session_request(tvbuff_t *tvb, packet_info *pinfo,
144 proto_tree *tree, gint offset, gint len);
145 static void dissect_asf_open_session_response(tvbuff_t *tvb, packet_info *pinfo,
146 proto_tree *tree, gint offset, gint len);
147 static void dissect_asf_payloads(tvbuff_t *tvb, packet_info *pinfo,
148 proto_tree *tree, gint offset, gint len);
149 static void dissect_asf_payload_authentication(tvbuff_t *tvb, proto_tree *tree,
150 gint offset, gint len);
151 static void dissect_asf_payload_integrity(tvbuff_t *tvb, proto_tree *tree,
152 gint offset, gint len);
154 static int
155 dissect_asf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
157 proto_tree *asf_tree = NULL;
158 proto_item *ti;
159 guint8 type;
160 guint8 len;
161 tvbuff_t *next_tvb;
163 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ASF");
165 col_clear(pinfo->cinfo, COL_INFO);
167 type = tvb_get_guint8(tvb, 4);
168 len = tvb_get_guint8(tvb, 7);
170 col_add_str(pinfo->cinfo, COL_INFO,
171 val_to_str(type, asf_type_vals, "Unknown (0x%02x)"));
173 if (tree) {
174 ti = proto_tree_add_item(tree, proto_asf, tvb, 0, 8,ENC_NA);
175 asf_tree = proto_item_add_subtree(ti, ett_asf);
176 proto_tree_add_item(asf_tree, hf_asf_iana, tvb, 0, 4,ENC_BIG_ENDIAN);
177 proto_tree_add_item(asf_tree, hf_asf_type, tvb, 4, 1,ENC_BIG_ENDIAN);
178 proto_tree_add_item(asf_tree, hf_asf_tag, tvb, 5, 1,ENC_BIG_ENDIAN);
179 proto_tree_add_item(asf_tree, hf_asf_len, tvb, 7, 1,ENC_BIG_ENDIAN);
182 if (len) {
183 switch(type) {
184 case ASF_TYPE_OPEN_SESS_RQST:
185 dissect_asf_open_session_request(tvb, pinfo, asf_tree, 8, len);
186 break;
187 case ASF_TYPE_OPEN_SESS_RESP:
188 dissect_asf_open_session_response(tvb, pinfo, asf_tree, 8, len);
189 break;
191 /* TODO: Add the rest as captures become available to test. */
193 default:
194 next_tvb = tvb_new_subset(tvb, 8, len, len);
195 call_dissector(data_handle, next_tvb, pinfo, tree);
196 break;
199 return 8 + len;
202 static void
203 dissect_asf_open_session_request(tvbuff_t *tvb, packet_info *pinfo,
204 proto_tree *tree, gint offset, gint len)
206 proto_tree_add_item(tree, hf_asf_mgt_console_id, tvb, offset, 4,ENC_BIG_ENDIAN);
207 offset += 4;
208 len -= 4;
209 dissect_asf_payloads(tvb, pinfo, tree, offset, len);
212 static void
213 dissect_asf_open_session_response(tvbuff_t *tvb, packet_info *pinfo,
214 proto_tree *tree, gint offset, gint len)
216 proto_tree_add_item(tree, hf_asf_rssp_status_code, tvb, offset, 1,ENC_BIG_ENDIAN);
217 proto_tree_add_item(tree, hf_asf_mgt_console_id, tvb, offset + 4, 4,ENC_BIG_ENDIAN);
218 proto_tree_add_item(tree, hf_asf_client_id, tvb, offset + 8, 4,ENC_BIG_ENDIAN);
219 offset += 12;
220 len -= 12;
221 dissect_asf_payloads(tvb, pinfo, tree, offset, len);
224 static void
225 dissect_asf_payloads(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
226 gint offset, gint len)
228 guint8 ptype;
229 guint16 plen;
230 proto_item *ti;
231 proto_tree *ptree;
233 while ( len >= 4 )
235 ptype = tvb_get_guint8(tvb, offset);
236 plen = tvb_get_ntohs(tvb, offset + 2);
238 ti = proto_tree_add_none_format(tree, hf_asf_payload, tvb, offset,
239 plen, "%s: %u bytes",
240 val_to_str(ptype, asf_payload_type_vals, "Unknown (%u)"), plen);
241 ptree = proto_item_add_subtree(ti, ett_asf_payload);
242 proto_tree_add_item(ptree, hf_asf_payload_type, tvb, offset, 1,ENC_BIG_ENDIAN);
243 ti = proto_tree_add_item(ptree, hf_asf_payload_len, tvb, offset + 2, 2,ENC_BIG_ENDIAN);
244 if (plen < 4)
246 expert_add_info(pinfo, ti, &ei_asf_payload_too_short);
247 break;
249 if ( ptype && (plen > 4) )
251 switch ( ptype )
253 case ASF_PAYLOAD_TYPE_AUTHENTICATION:
254 dissect_asf_payload_authentication(tvb, ptree,
255 offset + 4, plen - 4);
256 break;
257 case ASF_PAYLOAD_TYPE_INTEGRITY:
258 dissect_asf_payload_integrity(tvb, ptree,
259 offset + 4, plen - 4);
260 break;
261 default:
262 proto_tree_add_item(ptree, hf_asf_payload_data, tvb,
263 offset + 4, plen - 4,ENC_NA);
264 break;
267 offset += plen;
268 len -= plen;
272 static void
273 dissect_asf_payload_authentication(tvbuff_t *tvb, proto_tree *tree,
274 gint offset, gint len)
276 guint8 alg;
277 proto_item *ti;
278 proto_tree *atree;
280 alg = tvb_get_guint8(tvb, offset);
281 ti = proto_tree_add_none_format(tree, hf_asf_payload_data, tvb, offset,
282 len, "Authentication Algorithm: %s",
283 val_to_str(alg, asf_authentication_type_vals, "Unknown (%u)"));
284 atree = proto_item_add_subtree(ti, ett_asf_alg_payload);
285 proto_tree_add_item(atree, hf_asf_auth_alg, tvb, offset, 1,ENC_BIG_ENDIAN);
286 proto_tree_add_item(atree, hf_asf_reserved, tvb, offset + 1, len - 1,ENC_NA);
289 static void
290 dissect_asf_payload_integrity(tvbuff_t *tvb, proto_tree *tree,
291 gint offset, gint len)
293 guint8 alg;
294 proto_item *ti;
295 proto_tree *atree;
297 alg = tvb_get_guint8(tvb, offset);
298 ti = proto_tree_add_none_format(tree, hf_asf_payload_data, tvb, offset,
299 len, "Integrity Algorithm: %s",
300 val_to_str(alg, asf_integrity_type_vals, "Unknown (%u)"));
301 atree = proto_item_add_subtree(ti, ett_asf_alg_payload);
302 proto_tree_add_item(atree, hf_asf_integrity_alg, tvb, offset, 1,ENC_BIG_ENDIAN);
303 proto_tree_add_item(atree, hf_asf_reserved, tvb, offset + 1, len - 1,ENC_NA);
306 void
307 proto_register_asf(void)
309 static hf_register_info hf[] = {
310 { &hf_asf_iana, {
311 "IANA Enterprise Number", "asf.iana",
312 FT_UINT32, BASE_DEC|BASE_EXT_STRING, &sminmpec_values_ext, 0,
313 NULL, HFILL }},
314 { &hf_asf_type, {
315 "Message Type", "asf.type",
316 FT_UINT8, BASE_HEX, VALS(asf_type_vals), 0,
317 "ASF Message Type", HFILL }},
318 { &hf_asf_tag, {
319 "Message Tag", "asf.tag",
320 FT_UINT8, BASE_HEX, NULL, 0,
321 "ASF Message Tag", HFILL }},
322 { &hf_asf_len, {
323 "Data Length", "asf.len",
324 FT_UINT8, BASE_DEC, NULL, 0,
325 "ASF Data Length", HFILL }},
326 { &hf_asf_rssp_status_code, {
327 "Status Code", "asf.rssp_status_code",
328 FT_UINT8, BASE_DEC, VALS(asf_rssp_status_code_vals), 0,
329 "Identifies the status of the previous message", HFILL }},
330 { &hf_asf_mgt_console_id, {
331 "Mgt Console Session ID", "asf.mgt_console_id",
332 FT_UINT32, BASE_DEC, NULL, 0,
333 NULL, HFILL }},
334 { &hf_asf_client_id, {
335 "Managed Client Session ID", "asf.client_id",
336 FT_UINT32, BASE_DEC, NULL, 0,
337 NULL, HFILL }},
338 { &hf_asf_payload, {
339 "Payload", "asf.payload",
340 FT_NONE, BASE_NONE, NULL, 0,
341 NULL, HFILL }},
342 { &hf_asf_payload_type, {
343 "Payload Type", "asf.payload.type",
344 FT_UINT8, BASE_DEC, VALS(asf_payload_type_vals), 0,
345 "Identifies the type of payload that follows", HFILL }},
346 { &hf_asf_payload_len, {
347 "Payload Length", "asf.payload.len",
348 FT_UINT16, BASE_DEC, NULL, 0,
349 "The total length in bytes of the payload including the header",
350 HFILL }},
351 { &hf_asf_payload_data, {
352 "Data", "asf.payload.data",
353 FT_NONE, BASE_NONE, NULL, 0,
354 NULL, HFILL }},
355 { &hf_asf_auth_alg, {
356 "Authentication Algorithm", "asf.auth_alg",
357 FT_UINT8, BASE_DEC, VALS(asf_authentication_type_vals), 0,
358 NULL, HFILL }},
359 { &hf_asf_integrity_alg, {
360 "Integrity Algorithm", "asf.integrity_alg",
361 FT_UINT8, BASE_DEC, VALS(asf_integrity_type_vals), 0,
362 NULL, HFILL }},
363 { &hf_asf_reserved, {
364 "Reserved", "asf.reserved",
365 FT_NONE, BASE_NONE, NULL, 0,
366 NULL, HFILL }},
368 static gint *ett[] = {
369 &ett_asf,
370 &ett_asf_payload,
371 &ett_asf_alg_payload
374 static ei_register_info ei[] = {
375 { &ei_asf_payload_too_short, { "asf.payload_too_short", PI_MALFORMED, PI_ERROR, "Payload length too short to include the type and length", EXPFILL }},
378 expert_module_t* expert_asf;
380 proto_asf = proto_register_protocol(
381 "Alert Standard Forum", "ASF", "asf");
383 proto_register_field_array(proto_asf, hf, array_length(hf));
384 proto_register_subtree_array(ett, array_length(ett));
385 expert_asf = expert_register_protocol(proto_asf);
386 expert_register_field_array(expert_asf, ei, array_length(ei));
389 void
390 proto_reg_handoff_asf(void)
392 dissector_handle_t asf_handle;
394 data_handle = find_dissector("data");
396 asf_handle = new_create_dissector_handle(dissect_asf, proto_asf);
397 dissector_add_uint("rmcp.class", RMCP_CLASS_ASF, asf_handle);