HACK: 2nd try to match RowsetProperties
[wireshark-wip.git] / epan / dissectors / packet-maap.c
blob2880e82c75172fc3e8c9f6257416ef49f23cd4b3
1 /* packet-maap.c
2 * Routines for 802.3 MAC Address Allocation Protocol defined by IEEE1722
3 * Copyright 2012, Jason Damori, Biamp Systems <jdamori at biamp dot com>
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.
28 #include "config.h"
30 #include <epan/packet.h>
31 #include <epan/to_str.h>
32 #include <epan/etypes.h>
34 /* MAAP starts after common 1722 header */
35 #define MAAP_START_OFFSET 1
37 /* MAAP Field Offsets */
38 #define MAAP_MSG_TYPE_OFFSET 0+MAAP_START_OFFSET
39 #define MAAP_VERSION_OFFSET 1+MAAP_START_OFFSET
40 #define MAAP_STREAM_ID_OFFSET 3+MAAP_START_OFFSET
41 #define MAAP_REQ_START_ADDR_OFFSET 11+MAAP_START_OFFSET
42 #define MAAP_REQ_COUNT_OFFSET 17+MAAP_START_OFFSET
43 #define MAAP_CONFLICT_START_ADDR_OFFSET 19+MAAP_START_OFFSET
44 #define MAAP_CONFLICT_COUNT_OFFSET 25+MAAP_START_OFFSET
46 /* Bit Field Masks */
47 #define MAAP_MSG_TYPE_MASK 0x0f
48 #define MAAP_VERSION_MASK 0xf8
49 #define MAAP_DATA_LEN_MASK 0x07ff
51 /* MAAP message_type */
52 #define MAAP_MSG_TYPE_RESERVED_0 0x00
53 #define MAAP_MSG_TYPE_PROBE 0x01
54 #define MAAP_MSG_TYPE_DEFEND 0x02
55 #define MAAP_MSG_TYPE_ANNOUNCE 0x03
56 #define MAAP_MSG_TYPE_RESERVED_4 0x04
57 #define MAAP_MSG_TYPE_RESERVED_5 0x05
59 static const value_string maap_msg_type_vals [] = {
60 {MAAP_MSG_TYPE_PROBE, "MAAP_PROBE"},
61 {MAAP_MSG_TYPE_DEFEND, "MAAP_DEFEND"},
62 {MAAP_MSG_TYPE_ANNOUNCE, "MAAP_ANNOUNCE"},
63 {0, NULL}
66 /**********************************************************/
67 /* Initialize the protocol and registered fields */
68 /**********************************************************/
69 static int proto_maap = -1;
71 /* MAAP PDU */
72 static int hf_maap_message_type = -1;
73 static int hf_maap_version = -1;
74 static int hf_maap_data_length = -1;
75 static int hf_maap_stream_id = -1;
76 static int hf_maap_req_start_addr = -1;
77 static int hf_maap_req_count = -1;
78 static int hf_maap_conflict_start_addr = -1;
79 static int hf_maap_conflict_count = -1;
81 /* Initialize the subtree pointers */
82 static int ett_maap = -1;
84 static void
85 dissect_maap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
87 guint8 maap_msg_type;
88 proto_item *maap_item = NULL;
89 proto_tree *maap_tree = NULL;
91 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MAAP");
92 col_clear(pinfo->cinfo, COL_INFO);
94 /* The maap msg type will be handy in a moment */
95 maap_msg_type = tvb_get_guint8(tvb, MAAP_MSG_TYPE_OFFSET);
96 maap_msg_type &= 0x0f;
98 /* Display the name of the packet type in the info column. */
99 col_add_fstr(pinfo->cinfo, COL_INFO, "%s:",
100 val_to_str(maap_msg_type, maap_msg_type_vals,
101 "Unknown Type(0x%02x)"));
103 /* Now, we'll add the start and conflict addresses and counts to the info column as appropriate */
104 switch (maap_msg_type)
106 case MAAP_MSG_TYPE_PROBE:
107 case MAAP_MSG_TYPE_ANNOUNCE:
108 col_append_fstr(pinfo->cinfo, COL_INFO, " req_start=%s, cnt=%d",
109 tvb_ether_to_str(tvb, MAAP_REQ_START_ADDR_OFFSET),
110 tvb_get_ntohs(tvb, MAAP_REQ_COUNT_OFFSET));
112 break;
113 case MAAP_MSG_TYPE_DEFEND:
114 col_append_fstr(pinfo->cinfo, COL_INFO, " conflict_start=%s, cnt=%d",
115 tvb_ether_to_str(tvb, MAAP_CONFLICT_START_ADDR_OFFSET),
116 tvb_get_ntohs(tvb, MAAP_CONFLICT_COUNT_OFFSET));
117 break;
118 default:
119 /* no info for reserved or unknown msg types */
120 break;
124 if (tree) {
125 maap_item = proto_tree_add_item(tree, proto_maap, tvb, MAAP_START_OFFSET, -1, ENC_NA);
126 maap_tree = proto_item_add_subtree(maap_item, ett_maap);
128 proto_tree_add_item(maap_tree, hf_maap_message_type, tvb, MAAP_MSG_TYPE_OFFSET, 1, ENC_BIG_ENDIAN);
129 proto_tree_add_item(maap_tree, hf_maap_version, tvb, MAAP_VERSION_OFFSET, 1, ENC_BIG_ENDIAN);
130 proto_tree_add_item(maap_tree, hf_maap_data_length, tvb, MAAP_VERSION_OFFSET, 2, ENC_BIG_ENDIAN);
131 proto_tree_add_item(maap_tree, hf_maap_stream_id, tvb, MAAP_STREAM_ID_OFFSET, 8, ENC_BIG_ENDIAN);
132 proto_tree_add_item(maap_tree, hf_maap_req_start_addr, tvb, MAAP_REQ_START_ADDR_OFFSET, 6, ENC_NA);
133 proto_tree_add_item(maap_tree, hf_maap_req_count, tvb, MAAP_REQ_COUNT_OFFSET, 2, ENC_BIG_ENDIAN);
134 proto_tree_add_item(maap_tree, hf_maap_conflict_start_addr, tvb, MAAP_CONFLICT_START_ADDR_OFFSET, 6, ENC_NA);
135 proto_tree_add_item(maap_tree, hf_maap_conflict_count, tvb, MAAP_CONFLICT_COUNT_OFFSET, 2, ENC_BIG_ENDIAN);
137 } /* end dissect_maap() */
139 /* Register the protocol with Wireshark */
140 void
141 proto_register_maap(void)
143 static hf_register_info hf[] = {
144 { &hf_maap_message_type,
145 { "Message Type", "maap.message_type",
146 FT_UINT8, BASE_HEX,
147 VALS(maap_msg_type_vals), MAAP_MSG_TYPE_MASK,
148 NULL, HFILL }},
150 { &hf_maap_version,
151 { "MAAP Version", "maap.version",
152 FT_UINT8, BASE_HEX,
153 NULL, MAAP_VERSION_MASK,
154 NULL, HFILL }},
156 { &hf_maap_data_length,
157 { "Data Length", "maap.data_length",
158 FT_UINT16, BASE_HEX,
159 NULL, MAAP_DATA_LEN_MASK,
160 NULL, HFILL }},
162 { &hf_maap_stream_id,
163 { "Stream ID", "maap.stream_id",
164 FT_UINT64, BASE_HEX,
165 NULL, 0x00,
166 NULL, HFILL }},
168 { &hf_maap_req_start_addr,
169 { "Requested Start Address", "maap.req_start_addr",
170 FT_ETHER, BASE_NONE,
171 NULL, 0x00,
172 NULL, HFILL }},
174 { &hf_maap_req_count,
175 { "Request Count", "maap.req_count",
176 FT_UINT16, BASE_HEX,
177 NULL, 0x00,
178 NULL, HFILL }},
180 { &hf_maap_conflict_start_addr,
181 { "Conflict Start Address", "maap.conflict_start_addr",
182 FT_ETHER, BASE_NONE,
183 NULL, 0x00,
184 NULL, HFILL }},
186 { &hf_maap_conflict_count,
187 { "Conflict Count", "maap.conflict_count",
188 FT_UINT16, BASE_HEX,
189 NULL, 0x00,
190 NULL, HFILL }}
191 }; /* end of static hf_register_info hf[] = */
193 /* Setup protocol subtree array */
194 static gint *ett[] = { &ett_maap };
196 /* Register the protocol name and description */
197 proto_maap = proto_register_protocol (
198 "IEEE 1722 MAAP Protocol", /* name */
199 "MAAP", /* short name */
200 "maap" /* abbrev */
203 /* Required function calls to register the header fields and subtrees used */
204 proto_register_field_array(proto_maap, hf, array_length(hf));
205 proto_register_subtree_array(ett, array_length(ett));
207 } /* end proto_register_maap() */
209 void
210 proto_reg_handoff_maap(void)
212 dissector_handle_t maap_handle;
214 maap_handle = create_dissector_handle(dissect_maap, proto_maap);
215 dissector_add_uint("ieee1722.subtype", 0x7E, maap_handle);