Add support for Exif decoding (initial framework).
[obnox/wireshark/wip.git] / packet-asf.c
1 /* packet-asf.c
2  * Routines for ASF packet dissection
3  *
4  * Duncan Laurie <duncan@sun.com>
5  *
6  * $Id: packet-asf.c,v 1.2 2003/06/04 08:51:36 guy Exp $
7  *
8  * Ethereal - Network traffic analyzer
9  * By Gerald Combs <gerald@ethereal.com>
10  * Copyright 1998 Gerald Combs
11  *
12  * Copied from packet-rmcp.c
13  *
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.
18  *
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.
23  *
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., 59 Temple Place - Suite 330, Boston, MA 
27  * 02111-1307, USA.
28  */
29
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include <glib.h>
35 #include <epan/packet.h>
36
37 /*
38  * See
39  *
40  *      http://www.dmtf.org/standards/standard_alert.php
41  */
42
43 #define RMCP_CLASS_ASF 0x06
44
45 static int proto_asf = -1;
46 static int hf_asf_iana = -1;
47 static int hf_asf_type = -1;
48 static int hf_asf_tag = -1;
49 static int hf_asf_len = -1;
50
51 static dissector_handle_t data_handle;
52 static gint ett_asf = -1;
53
54 static const value_string asf_type_vals[] = {
55         { 0x10, "Reset" },
56         { 0x11, "Power-up" },
57         { 0x12, "Unconditional Power-down" },
58         { 0x13, "Power Cycle" },
59         { 0x40, "Presence Pong" },
60         { 0x41, "Capabilities Response" },
61         { 0x42, "System State Response" },
62         { 0x80, "Presence Ping" },
63         { 0x81, "Capabilities Request" },
64         { 0x82, "System State Request" },
65         { 0x00, NULL }
66 };
67
68 static void
69 dissect_asf(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
70 {
71         proto_tree      *asf_tree = NULL;
72         proto_item      *ti;
73         guint8          type;
74         guint8          len;
75         tvbuff_t        *next_tvb;
76
77         if (check_col(pinfo->cinfo, COL_PROTOCOL))
78                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ASF");
79
80         if (check_col(pinfo->cinfo, COL_INFO))
81                 col_clear(pinfo->cinfo, COL_INFO);
82
83         type = tvb_get_guint8(tvb, 4);
84         len = tvb_get_guint8(tvb, 7);
85
86         if (check_col(pinfo->cinfo, COL_INFO))
87                 col_add_fstr(pinfo->cinfo, COL_INFO, "%s",
88                      val_to_str(type, asf_type_vals, "Unknown (0x%02x)"));
89
90         if (tree) {
91                 ti = proto_tree_add_item(tree, proto_asf, tvb, 0, 8, TRUE);
92                 asf_tree = proto_item_add_subtree(ti, ett_asf);
93                 proto_tree_add_item(asf_tree, hf_asf_iana, tvb, 0, 4, TRUE);
94                 proto_tree_add_item(asf_tree, hf_asf_type, tvb, 4, 1, TRUE);
95                 proto_tree_add_item(asf_tree, hf_asf_tag, tvb, 5, 1, TRUE);
96                 proto_tree_add_item(asf_tree, hf_asf_len, tvb, 7, 1, TRUE);
97         }
98
99         if (len) {
100                 next_tvb = tvb_new_subset(tvb, 8, -1, len);
101                 call_dissector(data_handle, next_tvb, pinfo, tree);
102         }
103 }
104
105 void
106 proto_register_asf(void)
107 {
108         static hf_register_info hf[] = {
109                 { &hf_asf_iana, {
110                         "IANA Enterprise Number", "asf.iana",
111                         FT_UINT32, BASE_HEX, NULL, 0,
112                         "ASF IANA Enterprise Number", HFILL }},
113                 { &hf_asf_type, {
114                         "Message Type", "asf.type",
115                         FT_UINT8, BASE_HEX, VALS(asf_type_vals), 0,
116                         "ASF Message Type", HFILL }},
117                 { &hf_asf_tag, {
118                         "Message Tag", "asf.tag",
119                         FT_UINT8, BASE_HEX, NULL, 0,
120                         "ASF Message Tag", HFILL }},
121                 { &hf_asf_len, {
122                         "Data Length", "asf.len",
123                         FT_UINT8, BASE_DEC, NULL, 0,
124                         "ASF Data Length", HFILL }},
125         };
126         static gint *ett[] = {
127                 &ett_asf,
128         };
129
130         proto_asf = proto_register_protocol(
131                 "Alert Standard Forum", "ASF", "asf");
132
133         proto_register_field_array(proto_asf, hf, array_length(hf));
134         proto_register_subtree_array(ett, array_length(ett));
135 }
136
137 void
138 proto_reg_handoff_asf(void)
139 {
140         dissector_handle_t asf_handle;
141
142         data_handle = find_dissector("data");
143
144         asf_handle = create_dissector_handle(dissect_asf, proto_asf);
145         dissector_add("rmcp.class", RMCP_CLASS_ASF, asf_handle);
146 }