Fix [-Wmissing-prototypes]
[metze/wireshark/wip.git] / epan / dissectors / packet-ismp.c
1 /* packet-ismp.c
2  * Routines for ISMP dissection
3  * Enterasys Networks Home: http://www.enterasys.com/
4  * Copyright 2003, Joshua Craig Douglas <jdouglas@enterasys.com>
5  *
6  * $Id$
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1998 Gerald Combs
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  */
26
27 #include "config.h"
28
29 #include <glib.h>
30
31 #include <epan/packet.h>
32 #include <epan/to_str.h>
33 #include <epan/strutil.h>
34 #include <epan/etypes.h>
35
36 void proto_register_ismp(void);
37 void proto_reg_handoff_ismp(void);
38
39 /* Initialize the protocol and registered fields */
40 static int proto_ismp = -1;
41 static int hf_ismp_version = -1;
42 static int hf_ismp_message_type = -1;
43 static int hf_ismp_seq_num = -1;
44 static int hf_ismp_code_length = -1;
45 static int hf_ismp_auth_data = -1;
46
47 /* Enterasys/Cabletron Dicovery Protocol fields*/
48 static int hf_ismp_edp = -1;
49 static int hf_ismp_edp_version = -1;
50 static int hf_ismp_edp_module_ip = -1;
51 static int hf_ismp_edp_module_mac = -1;
52 static int hf_ismp_edp_module_port = -1;
53 static int hf_ismp_edp_chassis_mac =-1;
54 static int hf_ismp_edp_chassis_ip = -1;
55 static int hf_ismp_edp_device_type = -1;
56 static int hf_ismp_edp_module_rev = -1;
57 static int hf_ismp_edp_options = -1;
58 static int hf_ismp_edp_sfs_option_unused1 = -1;
59 static int hf_ismp_edp_sfs_option_sfssup = -1;
60 static int hf_ismp_edp_sfs_option_lsp = -1;
61 static int hf_ismp_edp_sfs_option_flood = -1;
62 static int hf_ismp_edp_sfs_option_resolve = -1;
63 static int hf_ismp_edp_sfs_option_unused2 = -1;
64 static int hf_ismp_edp_sfs_option_tagflood = -1;
65 static int hf_ismp_edp_sfs_option_calltap = -1;
66 static int hf_ismp_edp_sfs_option_conmsg = -1;
67 static int hf_ismp_edp_sfs_option_redun = -1;
68 static int hf_ismp_edp_sfs_option_isolated = -1;
69 static int hf_ismp_edp_sfs_option_uplink_switch = -1;
70 static int hf_ismp_edp_sfs_option_uplink_core = -1;
71 static int hf_ismp_edp_sfs_option_uplink_port = -1;
72 static int hf_ismp_edp_sfs_option_uplink_flood = -1;
73 static int hf_ismp_edp_rtr_option_ssr = -1;
74 static int hf_ismp_edp_rtr_option_igmp = -1;
75 static int hf_ismp_edp_rtr_option_rip = -1;
76 static int hf_ismp_edp_rtr_option_bgp = -1;
77 static int hf_ismp_edp_rtr_option_ospf = -1;
78 static int hf_ismp_edp_rtr_option_dvmrp = -1;
79 static int hf_ismp_edp_rtr_option_8021q = -1;
80 static int hf_ismp_edp_rtr_option_gvrp = -1;
81 static int hf_ismp_edp_rtr_option_gmrp = -1;
82 static int hf_ismp_edp_rtr_option_igmp_snoop = -1;
83 static int hf_ismp_edp_rtr_option_route = -1;
84 static int hf_ismp_edp_rtr_option_trans = -1;
85 static int hf_ismp_edp_rtr_option_level1 = -1;
86 static int hf_ismp_edp_switch_option_8021q = -1;
87 static int hf_ismp_edp_switch_option_gvrp = -1;
88 static int hf_ismp_edp_switch_option_gmrp = -1;
89 static int hf_ismp_edp_switch_option_igmp = -1;
90 static int hf_ismp_edp_switch_option_route = -1;
91 static int hf_ismp_edp_switch_option_trans = -1;
92 static int hf_ismp_edp_switch_option_level1 = -1;
93 static int hf_ismp_edp_end_station_option_dhcp = -1;
94 static int hf_ismp_edp_end_station_option_dns = -1;
95 static int hf_ismp_edp_end_station_option_ad = -1;
96 static int hf_ismp_edp_num_neighbors = -1;
97 static int hf_ismp_edp_neighbors = -1;
98 static int hf_ismp_edp_num_tuples = -1;
99 static int hf_ismp_edp_tuples = -1;
100
101
102 /* Initialize the subtree pointers */
103 static gint ett_ismp = -1;
104 static gint ett_ismp_edp = -1;
105 static gint ett_ismp_edp_options = -1;
106 static gint ett_ismp_edp_neighbors = -1;
107 static gint ett_ismp_edp_neighbors_leaf = -1;
108 static gint ett_ismp_edp_tuples = -1;
109 static gint ett_ismp_edp_tuples_leaf = -1;
110
111 /* ISMP TYPES */
112 #define ISMPTYPE_EDP    2
113
114
115 /* EDP DEVICE TYPES */
116 #define EDP_DEVICE_TYPE_SFS17           1
117 #define EDP_DEVICE_TYPE_SFS18           2
118 #define EDP_DEVICE_TYPE_ROUTER          3
119 #define EDP_DEVICE_TYPE_BRIDGE          4
120 #define EDP_DEVICE_TYPE_VLANMAN         5
121 #define EDP_DEVICE_TYPE_NTSERVER        6
122 #define EDP_DEVICE_TYPE_NTCLIENT        7
123 #define EDP_DEVICE_TYPE_WIN95           8
124 #define EDP_DEVICE_TYPE_WIN98           9
125 #define EDP_DEVICE_TYPE_UNIXSERVER      10
126 #define EDP_DEVICE_TYPE_UNIXCLIENT      11
127 #define EDP_DEVICE_TYPE_ACCESSPOINT     12
128
129
130 static const value_string edp_device_types[] = {
131         { EDP_DEVICE_TYPE_SFS17,       "Network Switch running SecureFast version 1.7 or lower" },
132         { EDP_DEVICE_TYPE_SFS18,         "Network Switch running SecureFast version 1.8 or greater" },
133         { EDP_DEVICE_TYPE_ROUTER,         "Router" },
134         { EDP_DEVICE_TYPE_BRIDGE,         "Bridge" },
135         { EDP_DEVICE_TYPE_VLANMAN,         "Cabletron VLAN Manager" },
136         { EDP_DEVICE_TYPE_NTSERVER,         "Network Server (NT)" },
137         { EDP_DEVICE_TYPE_NTCLIENT,    "Network Workstation (NT)" },
138         { EDP_DEVICE_TYPE_WIN95,     "Windows95" },
139         { EDP_DEVICE_TYPE_WIN98,        "Windows98" },
140         { EDP_DEVICE_TYPE_UNIXSERVER,       "UNIX Server" },
141         { EDP_DEVICE_TYPE_UNIXCLIENT, "UNIX Workstation" },
142         { EDP_DEVICE_TYPE_ACCESSPOINT,     "Roamabout wireless access point" },
143         { 0,                    NULL },
144 };
145
146
147 /* EDP SFS Options */
148 #define EDP_SFS_OPTION_UNUSED1          0x1
149 #define EDP_SFS_OPTION_SFSSUP           0x2
150 #define EDP_SFS_OPTION_LSP              0x4
151 #define EDP_SFS_OPTION_FLOOD            0x8
152 #define EDP_SFS_OPTION_RESOLVE          0x10
153 #define EDP_SFS_OPTION_UNUSED2          0x20
154 #define EDP_SFS_OPTION_TAGFLOOD         0x40
155 #define EDP_SFS_OPTION_CALLTAP          0x80
156 #define EDP_SFS_OPTION_CONMSG           0x100
157 #define EDP_SFS_OPTION_REDUN            0x200
158 #define EDP_SFS_OPTION_ISOLATED         0x400
159 #define EDP_SFS_OPTION_UPLINK_SWITCH    0x800
160 #define EDP_SFS_OPTION_UPLINK_CORE      0x1000
161 #define EDP_SFS_OPTION_UPLINK_PORT      0x2000
162 #define EDP_SFS_OPTION_UPLINK_FLOOD     0x4000
163
164 /* EDP Router Options */
165 #define EDP_RTR_OPTION_SSR              0x1
166 #define EDP_RTR_OPTION_IGMP             0x2
167 #define EDP_RTR_OPTION_RIP              0x4
168 #define EDP_RTR_OPTION_BGP              0x8
169 #define EDP_RTR_OPTION_OSPF             0x10
170 #define EDP_RTR_OPTION_DVMRP            0x20
171 #define EDP_RTR_OPTION_8021Q            0x40
172 #define EDP_RTR_OPTION_GVRP             0x80
173 #define EDP_RTR_OPTION_GMRP             0x100
174 #define EDP_RTR_OPTION_IGMP_SNOOP       0x200
175 #define EDP_RTR_OPTION_ROUTE            0x400
176 #define EDP_RTR_OPTION_TRANS            0x800
177 #define EDP_RTR_OPTION_LEVEL1           0x1000
178
179 /* EDP Switch Options */
180 #define EDP_SWITCH_OPTION_8021Q         0x1
181 #define EDP_SWITCH_OPTION_GVRP          0x2
182 #define EDP_SWITCH_OPTION_GMRP          0x4
183 #define EDP_SWITCH_OPTION_IGMP          0x8
184 #define EDP_SWITCH_OPTION_ROUTE         0x10
185 #define EDP_SWITCH_OPTION_TRANS         0x20
186 #define EDP_SWITCH_OPTION_LEVEL1        0x40
187
188 /* EDP End Station and Server Options */
189 #define EDP_END_STATION_OPTION_DHCP     0x1
190 #define EDP_END_STATION_OPTION_DNS      0x2
191 #define EDP_END_STATION_OPTION_AD       0x4
192
193 /* EDP Tuple Types */
194 #define EDP_TUPLE_UNKNOWN               0
195 #define EDP_TUPLE_HOLD                  1
196 #define EDP_TUPLE_INT_NAME              2
197 #define EDP_TUPLE_SYS_DESCRIPT  3
198 #define EDP_TUPLE_IPX_ADDR              4
199
200 static const value_string edp_tuple_types[] =
201 {
202         { EDP_TUPLE_UNKNOWN,"Unknown" },
203         { EDP_TUPLE_HOLD,"Hold Time" },
204         { EDP_TUPLE_INT_NAME,"Interface Name" },
205         { EDP_TUPLE_SYS_DESCRIPT,"System Description" },
206         { EDP_TUPLE_IPX_ADDR,"IPX Address" },
207         { 0,NULL }
208 };
209
210 /* Is value set? */
211 static const true_false_string is_set = {
212         "set",
213         "not set"
214 };
215
216
217 /* Function to dissect EDP portion of ISMP message */
218 static void
219 dissect_ismp_edp(tvbuff_t *tvb, packet_info *pinfo, int offset, proto_tree *ismp_tree)
220 {
221         /* local variables used for EDP dissection */
222         int neighbors_count = 0;
223         int tuples_count = 0;
224         guint16 device_type = 0;
225         guint32 options = 0;
226         guint16 num_neighbors = 0;
227         guint16 num_tuples = 0;
228         guint16 tuple_type = 0;
229         guint16 tuple_length = 0;
230
231         /* Set up structures needed to add the protocol subtree and manage it */
232         proto_item *edp_ti;
233         proto_tree *edp_tree;
234
235         proto_item *edp_options_ti;
236         proto_tree *edp_options_tree;
237
238         proto_item *edp_neighbors_ti;
239         proto_tree *edp_neighbors_tree;
240
241         proto_item *edp_neighbors_leaf_ti;
242         proto_tree *edp_neighbors_leaf_tree;
243
244         proto_item *edp_tuples_ti;
245         proto_tree *edp_tuples_tree;
246
247         proto_item *edp_tuples_leaf_ti;
248         proto_tree *edp_tuples_leaf_tree;
249
250         /* add column iformation marking this as EDP (Enterasys Discover Protocol */
251         col_set_str(pinfo->cinfo, COL_PROTOCOL, "ISMP.EDP");
252         col_clear(pinfo->cinfo, COL_INFO);
253
254         /* create display subtree for EDP */
255         if (ismp_tree) {
256                 edp_ti  = proto_tree_add_item(ismp_tree, hf_ismp_edp, tvb, offset,
257                         tvb_length_remaining(tvb, offset), ENC_NA);
258                 edp_tree = proto_item_add_subtree(edp_ti, ett_ismp_edp);
259
260                 col_add_fstr(pinfo->cinfo, COL_INFO, "MIP %s, MMAC %s, ifIdx %d",
261                         tvb_ip_to_str(tvb, offset+2),
262                         tvb_ether_to_str(tvb, offset+6),
263                         tvb_get_ntohl(tvb, offset+12));
264
265                 proto_tree_add_item(edp_tree, hf_ismp_edp_version, tvb, offset, 2, ENC_BIG_ENDIAN);
266                 offset += 2;
267                 proto_tree_add_item(edp_tree, hf_ismp_edp_module_ip, tvb, offset, 4, ENC_BIG_ENDIAN);
268                 offset += 4;
269                 proto_tree_add_item(edp_tree, hf_ismp_edp_module_mac, tvb, offset, 6, ENC_NA);
270                 offset += 6;
271                 proto_tree_add_item(edp_tree, hf_ismp_edp_module_port, tvb, offset, 4, ENC_BIG_ENDIAN);
272                 offset += 4;
273                 proto_tree_add_item(edp_tree, hf_ismp_edp_chassis_mac, tvb, offset, 6, ENC_NA);
274                 offset += 6;
275                 proto_tree_add_item(edp_tree, hf_ismp_edp_chassis_ip, tvb, offset, 4, ENC_BIG_ENDIAN);
276                 offset += 4;
277                 device_type = tvb_get_ntohs(tvb, offset);
278                 proto_tree_add_item(edp_tree, hf_ismp_edp_device_type, tvb, offset, 2, ENC_BIG_ENDIAN);
279                 offset += 2;
280                 proto_tree_add_uint_format_value(edp_tree, hf_ismp_edp_module_rev, tvb, offset, 4, tvb_get_ntohl(tvb, offset),
281                         "%02x.%02x.%02x.%02x", tvb_get_guint8(tvb, offset),
282                         tvb_get_guint8(tvb, offset+1), tvb_get_guint8(tvb, offset+2), tvb_get_guint8(tvb, offset+3));
283                 offset += 4;
284
285                 /* create display subtree for EDP options */
286                 options = tvb_get_ntohl(tvb, offset);
287                 edp_options_ti = proto_tree_add_uint_format(edp_tree, hf_ismp_edp_options, tvb, offset, 4,
288                         options,"Options: 0x%08x",options);
289                 edp_options_tree = proto_item_add_subtree(edp_options_ti, ett_ismp_edp_options);
290
291                 /* depending on device_type, show the appropriate options */
292                 switch (device_type) {
293                         case EDP_DEVICE_TYPE_SFS17:
294                         case EDP_DEVICE_TYPE_SFS18:
295                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_sfs_option_uplink_flood, tvb, offset, 4, ENC_BIG_ENDIAN);
296                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_sfs_option_uplink_port, tvb, offset, 4, ENC_BIG_ENDIAN);
297                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_sfs_option_uplink_core, tvb, offset, 4, ENC_BIG_ENDIAN);
298                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_sfs_option_uplink_switch, tvb, offset, 4, ENC_BIG_ENDIAN);
299                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_sfs_option_isolated, tvb, offset, 4, ENC_BIG_ENDIAN);
300                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_sfs_option_redun, tvb, offset, 4, ENC_BIG_ENDIAN);
301                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_sfs_option_conmsg, tvb, offset, 4, ENC_BIG_ENDIAN);
302                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_sfs_option_calltap, tvb, offset, 4, ENC_BIG_ENDIAN);
303                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_sfs_option_tagflood, tvb, offset, 4, ENC_BIG_ENDIAN);
304                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_sfs_option_unused2, tvb, offset, 4, ENC_BIG_ENDIAN);
305                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_sfs_option_resolve, tvb, offset, 4, ENC_BIG_ENDIAN);
306                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_sfs_option_flood, tvb, offset, 4, ENC_BIG_ENDIAN);
307                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_sfs_option_lsp, tvb, offset, 4, ENC_BIG_ENDIAN);
308                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_sfs_option_sfssup, tvb, offset, 4, ENC_BIG_ENDIAN);
309                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_sfs_option_unused1, tvb, offset, 4, ENC_BIG_ENDIAN);
310                                 break;
311                         case EDP_DEVICE_TYPE_ROUTER:
312                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_rtr_option_level1, tvb, offset, 4, ENC_BIG_ENDIAN);
313                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_rtr_option_trans, tvb, offset, 4, ENC_BIG_ENDIAN);
314                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_rtr_option_route, tvb, offset, 4, ENC_BIG_ENDIAN);
315                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_rtr_option_igmp_snoop, tvb, offset, 4, ENC_BIG_ENDIAN);
316                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_rtr_option_gmrp, tvb, offset, 4, ENC_BIG_ENDIAN);
317                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_rtr_option_gvrp, tvb, offset, 4, ENC_BIG_ENDIAN);
318                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_rtr_option_8021q, tvb, offset, 4, ENC_BIG_ENDIAN);
319                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_rtr_option_dvmrp, tvb, offset, 4, ENC_BIG_ENDIAN);
320                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_rtr_option_ospf, tvb, offset, 4, ENC_BIG_ENDIAN);
321                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_rtr_option_bgp, tvb, offset, 4, ENC_BIG_ENDIAN);
322                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_rtr_option_rip, tvb, offset, 4, ENC_BIG_ENDIAN);
323                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_rtr_option_igmp, tvb, offset, 4, ENC_BIG_ENDIAN);
324                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_rtr_option_ssr, tvb, offset, 4, ENC_BIG_ENDIAN);
325                                 break;
326                         case EDP_DEVICE_TYPE_BRIDGE:
327                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_switch_option_level1, tvb, offset, 4, ENC_BIG_ENDIAN);
328                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_switch_option_trans, tvb, offset, 4, ENC_BIG_ENDIAN);
329                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_switch_option_route, tvb, offset, 4, ENC_BIG_ENDIAN);
330                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_switch_option_igmp, tvb, offset, 4, ENC_BIG_ENDIAN);
331                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_switch_option_gmrp, tvb, offset, 4, ENC_BIG_ENDIAN);
332                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_switch_option_gvrp, tvb, offset, 4, ENC_BIG_ENDIAN);
333                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_switch_option_8021q, tvb, offset, 4, ENC_BIG_ENDIAN);
334                                 break;
335                         case EDP_DEVICE_TYPE_VLANMAN:
336                                 break;
337                         case EDP_DEVICE_TYPE_NTSERVER:
338                         case EDP_DEVICE_TYPE_NTCLIENT:
339                         case EDP_DEVICE_TYPE_WIN95:
340                         case EDP_DEVICE_TYPE_WIN98:
341                         case EDP_DEVICE_TYPE_UNIXSERVER:
342                         case EDP_DEVICE_TYPE_UNIXCLIENT:
343                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_end_station_option_ad, tvb, offset, 4, ENC_BIG_ENDIAN);
344                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_end_station_option_dns, tvb, offset, 4, ENC_BIG_ENDIAN);
345                                 proto_tree_add_item(edp_options_tree, hf_ismp_edp_end_station_option_dhcp, tvb, offset, 4, ENC_BIG_ENDIAN);
346                                 break;
347                         case EDP_DEVICE_TYPE_ACCESSPOINT:
348                         default:
349                                 break;
350                 }
351                 offset += 4;
352
353                 /* determine the number of neighbors and create EDP neighbors subtree */
354                 num_neighbors = tvb_get_ntohs(tvb, offset);
355                 proto_tree_add_item(edp_tree, hf_ismp_edp_num_neighbors, tvb, offset, 2, ENC_BIG_ENDIAN);
356                 offset += 2;
357                 if (num_neighbors > 0)
358                 {
359                         edp_neighbors_ti = proto_tree_add_item(edp_tree, hf_ismp_edp_neighbors, tvb,
360                                                                                 offset, num_neighbors*10, ENC_NA);
361                         edp_neighbors_tree = proto_item_add_subtree(edp_neighbors_ti, ett_ismp_edp_neighbors);
362                         while ( neighbors_count < num_neighbors && tvb_reported_length_remaining(tvb, offset) >= 10)
363                         {
364                                 edp_neighbors_leaf_ti = proto_tree_add_text(edp_neighbors_tree, tvb, offset, 10,
365                                                                                 "Neighbor%d", (neighbors_count+1));
366                                 edp_neighbors_leaf_tree = proto_item_add_subtree(edp_neighbors_leaf_ti, ett_ismp_edp_neighbors_leaf);
367
368                                 proto_tree_add_text(edp_neighbors_leaf_tree, tvb, offset, 6,
369                                         "MAC Address: %s", tvb_ether_to_str(tvb, offset));
370                                 proto_tree_add_text(edp_neighbors_leaf_tree, tvb, offset, 4,
371                                         "Assigned Neighbor State 0x%04x", tvb_get_ntohl(tvb, offset));
372                                 offset += 10;
373                                 neighbors_count++;
374                         }
375                         if (neighbors_count != num_neighbors)
376                         {
377                                 proto_tree_add_text(edp_tree, tvb, offset, tvb_reported_length_remaining(tvb, offset),
378                                 "MALFORMED PACKET");
379                                 return;
380                         }
381                 }
382
383                 /* determine data remains, if so, count tuples
384                    and create EDP tuples subtree */
385                 if (tvb_reported_length_remaining(tvb, offset) != 0 &&
386                         tvb_reported_length_remaining(tvb, offset) >= 2)
387                 {
388                         num_tuples = tvb_get_ntohs(tvb, offset);
389                         proto_tree_add_item(edp_tree, hf_ismp_edp_num_tuples, tvb, offset, 2, ENC_BIG_ENDIAN);
390                         offset += 2;
391                 }
392                 else if (tvb_reported_length_remaining(tvb, offset) > 0) {
393                         proto_tree_add_text(edp_tree, tvb, offset,
394                                 tvb_reported_length_remaining(tvb, offset), "MALFORMED PACKET");
395                         return;
396                 }
397                 else
398                 {
399                         return;
400                 }
401
402                 /* start populating tuple information */
403                 if (num_tuples && tvb_reported_length_remaining(tvb, offset) >= 4)
404                 {
405                         edp_tuples_ti = proto_tree_add_bytes_format(edp_tree, hf_ismp_edp_tuples, tvb,
406                                 offset, tvb_reported_length_remaining(tvb, offset), NULL, "Tuples");
407                         edp_tuples_tree = proto_item_add_subtree(edp_tuples_ti, ett_ismp_edp_tuples);
408
409                         while ( (tuples_count < num_tuples) && (tvb_reported_length_remaining(tvb, offset) >= 4) )
410                         {
411
412                                 tuple_length = tvb_get_ntohs(tvb, offset+2);
413                                 edp_tuples_leaf_ti = proto_tree_add_text(edp_tuples_tree, tvb, offset, tuple_length,
414                                         "Tuple%d", tuples_count+1);
415
416                                 edp_tuples_leaf_tree = proto_item_add_subtree(edp_tuples_leaf_ti, ett_ismp_edp_tuples_leaf);
417
418                                 tuple_type = tvb_get_ntohs(tvb, offset);
419                                 proto_tree_add_text(edp_tuples_leaf_tree, tvb, offset, 2,
420                                         "Tuple Type: %s(%d)", val_to_str_const( tuple_type, edp_tuple_types, "Unknown"), tuple_type );
421                                 offset += 2;
422                                 proto_tree_add_text(edp_tuples_leaf_tree, tvb, offset, 2,
423                                         "Tuple Length: %d", tuple_length);
424                                 offset += 2;
425
426                                 if (tvb_reported_length_remaining(tvb, offset) >= tuple_length)
427                                 {
428                                         tvb_ensure_bytes_exist(tvb, offset, tuple_length);
429                                         switch (tuple_type)
430                                         {
431                                                 case EDP_TUPLE_HOLD:
432                                                         proto_tree_add_text(edp_tuples_leaf_tree, tvb, offset, tuple_length,
433                                                                 "Hold Time = %d", tvb_get_ntohs(tvb, offset));
434                                                         break;
435                                                 case EDP_TUPLE_INT_NAME:
436                                                         proto_tree_add_text(edp_tuples_leaf_tree, tvb, offset, tuple_length,
437                                                                 "Interface Name = %s", tvb_format_text(tvb, offset, tuple_length));
438                                                         col_append_fstr(pinfo->cinfo, COL_INFO, ", ifName %s",
439                                                                 tvb_format_text(tvb, offset, tuple_length));
440                                                         break;
441                                                 case EDP_TUPLE_SYS_DESCRIPT:
442                                                         proto_tree_add_text(edp_tuples_leaf_tree, tvb, offset, tuple_length,
443                                                                 "System Description = %s", tvb_format_text(tvb, offset, tuple_length));
444                                                         break;
445                                                 case EDP_TUPLE_IPX_ADDR:
446                                                         proto_tree_add_text(edp_tuples_leaf_tree, tvb, offset, tuple_length,
447                                                                 "Interface IPX_address = %s",
448                                                                 ipx_addr_to_str(tvb_get_ntohl(tvb, offset),
449                                                                 tvb_get_string(wmem_packet_scope(), tvb, offset+4, tuple_length-4)));
450                                                         break;
451                                                 case EDP_TUPLE_UNKNOWN:
452                                                 default:
453                                                         proto_tree_add_text(edp_tuples_leaf_tree, tvb, offset, tuple_length,
454                                                                 "Unknown Tuple Data %s", tvb_format_text(tvb, offset, tuple_length));
455                                                         break;
456                                         }
457                                 }
458                                 offset += tuple_length;
459
460                                 tuples_count++;
461                         }
462                         if (tuples_count != num_tuples)
463                         {
464                                 proto_tree_add_text(edp_tree, tvb, offset,
465                                         tvb_reported_length_remaining(tvb, offset), "MALFORMED PACKET");
466                                 return;
467                         }
468                         else
469                         {
470                                 return;
471                         }
472                 }
473
474         }
475
476
477 }
478
479
480 /* Code to actually dissect the packets */
481 static void
482 dissect_ismp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
483 {
484         int offset = 0;
485         guint16 message_type = 0;
486         guint8 code_length = 0;
487         guint8 weird_stuff[3] = { 0x42, 0x42, 0x03 };
488
489 /* Set up structures needed to add the protocol subtree and manage it */
490         proto_item *ti;
491         proto_tree *ismp_tree;
492
493 /* Make entries in Protocol column and Info column on summary display */
494         col_set_str(pinfo->cinfo, COL_PROTOCOL, "ISMP");
495         col_clear(pinfo->cinfo, COL_INFO);
496
497         /*
498          * XXX - I've seen captures with packets that have the ISMP
499          * Ethernet frame type, but with the payload being 0x42 0x42 0x03
500          * followed by what appears to be an ISMP frame.
501          *
502          * 0x4242 is not a valid ISMP version number.
503          */
504         if (tvb_memeql(tvb, offset, weird_stuff, sizeof weird_stuff) == 0)
505                 offset += 3;    /* skip the weird stuff, for now */
506         if (tree) {
507                 /* create display subtree for ismp */
508                 ti = proto_tree_add_item(tree, proto_ismp, tvb, offset, -1, ENC_NA);
509
510                 ismp_tree = proto_item_add_subtree(ti, ett_ismp);
511
512                 /* add an items to the subtree */
513                 proto_tree_add_item(ismp_tree, hf_ismp_version, tvb, offset, 2, ENC_BIG_ENDIAN);
514                 offset += 2;
515                 message_type = tvb_get_ntohs(tvb, offset);
516                 proto_tree_add_item(ismp_tree, hf_ismp_message_type, tvb, offset, 2, ENC_BIG_ENDIAN);
517                 offset += 2;
518                 proto_tree_add_item(ismp_tree, hf_ismp_seq_num, tvb, offset, 2, ENC_BIG_ENDIAN);
519                 offset += 2;
520                 code_length = tvb_get_guint8(tvb, offset);
521                 proto_tree_add_item(ismp_tree, hf_ismp_code_length, tvb, offset, 1, ENC_BIG_ENDIAN);
522                 offset += 1;
523                 proto_tree_add_item(ismp_tree, hf_ismp_auth_data, tvb, offset, code_length, ENC_NA);
524                 offset += code_length;
525
526                 /* if Enterasys Discover Protocol, dissect it */
527                 if(message_type == ISMPTYPE_EDP)
528                         dissect_ismp_edp(tvb, pinfo, offset, tree);
529         }
530
531 }
532
533
534 /* Register this protocol with Wireshark */
535 void
536 proto_register_ismp(void)
537 {
538
539 /* Setup list of header fields  See Section 1.6.1 for details*/
540         static hf_register_info hf[] = {
541 #if 0
542                 { &hf_ismp,
543                         { "ISMP", "ismp",
544                         FT_PROTOCOL, BASE_NONE, NULL, 0x0,
545                         "Inter Switch Message Protocol", HFILL }
546                 },
547 #endif
548                 { &hf_ismp_version,
549                         { "Version",           "ismp.version",
550                         FT_UINT16, BASE_DEC, NULL, 0x0,
551                         NULL, HFILL }
552                 },
553                 { &hf_ismp_message_type,
554                         { "Message Type", "ismp.msgtype",
555                         FT_UINT16, BASE_DEC, NULL, 0x0,
556                         NULL, HFILL }
557                 },
558                 { &hf_ismp_seq_num,
559                         { "Sequence Number", "ismp.seqnum",
560                         FT_UINT16, BASE_DEC, NULL, 0x0,
561                         NULL, HFILL }
562                 },
563                 { &hf_ismp_code_length,
564                         { "Auth Code Length", "ismp.codelen",
565                         FT_UINT8, BASE_DEC, NULL, 0x0,
566                         NULL, HFILL }
567                 },
568                 { &hf_ismp_auth_data,
569                         { "Auth Data", "ismp.authdata",
570                         FT_BYTES, BASE_NONE, NULL, 0x0,
571                         NULL, HFILL }
572                 },
573                 { &hf_ismp_edp,
574                         { "EDP", "ismp.edp",
575                         FT_PROTOCOL, BASE_NONE, NULL, 0x0,
576                         "Enterasys Discovery Protocol", HFILL }
577                 },
578                 { &hf_ismp_edp_version,
579                         { "Version", "ismp.edp.version",
580                         FT_UINT16, BASE_DEC, NULL, 0x0,
581                         NULL, HFILL }
582                 },
583                 { &hf_ismp_edp_module_ip,
584                         { "Module IP Address", "ismp.edp.modip",
585                         FT_IPv4, BASE_NONE, NULL, 0x0,
586                         NULL, HFILL }
587                 },
588                 { &hf_ismp_edp_module_mac,
589                         { "Module MAC Address", "ismp.edp.modmac",
590                         FT_ETHER, BASE_NONE, NULL, 0x0,
591                         NULL, HFILL }
592                 },
593                 { &hf_ismp_edp_module_port,
594                         { "Module Port (ifIndex num)", "ismp.edp.modport",
595                         FT_UINT32, BASE_DEC, NULL, 0x0,
596                         NULL, HFILL }
597                 },
598                 { &hf_ismp_edp_chassis_mac,
599                         { "Chassis MAC Address", "ismp.edp.chassismac",
600                         FT_ETHER, BASE_NONE, NULL, 0x0,
601                         NULL, HFILL }
602                 },
603                 { &hf_ismp_edp_chassis_ip,
604                         { "Chassis IP Address", "ismp.edp.chassisip",
605                         FT_IPv4, BASE_NONE, NULL, 0x0,
606                         NULL, HFILL }
607                 },
608                 { &hf_ismp_edp_device_type,
609                         { "Device Type", "ismp.edp.devtype",
610                         FT_UINT16, BASE_DEC, edp_device_types, 0x0,
611                         NULL, HFILL }
612                 },
613                 { &hf_ismp_edp_module_rev,
614                         { "Module Firmware Revision", "ismp.edp.rev",
615                         FT_UINT32, BASE_DEC, NULL, 0x0,
616                         NULL, HFILL }
617                 },
618                 { &hf_ismp_edp_options,
619                         { "Device Options", "ismp.edp.options",
620                         FT_UINT32, BASE_DEC, NULL, 0x0,
621                         NULL, HFILL }
622                 },
623                 { &hf_ismp_edp_sfs_option_unused1,
624                         { "Unused", "ismp.edp.sfs_option_unused1",
625                         FT_BOOLEAN, 32, TFS(&is_set), EDP_SFS_OPTION_UNUSED1,
626                         NULL, HFILL }
627                 },
628                 { &hf_ismp_edp_sfs_option_sfssup,
629                         { "SFS Support", "ismp.edp.sfs_option_sfssup",
630                         FT_BOOLEAN, 32, TFS(&is_set), EDP_SFS_OPTION_SFSSUP,
631                         NULL, HFILL }
632                 },
633                 { &hf_ismp_edp_sfs_option_lsp,
634                         { "LSP Support", "ismp.edp.sfs_option_lsp",
635                         FT_BOOLEAN, 32, TFS(&is_set), EDP_SFS_OPTION_LSP,
636                         NULL, HFILL }
637                 },
638                 { &hf_ismp_edp_sfs_option_flood,
639                         { "Flood Path Support", "ismp.edp.sfs_option_flood",
640                         FT_BOOLEAN, 32, TFS(&is_set), EDP_SFS_OPTION_FLOOD,
641                         NULL, HFILL }
642                 },
643                 { &hf_ismp_edp_sfs_option_resolve,
644                         { "Resolve Support", "ismp.edp.sfs_option_resolve",
645                         FT_BOOLEAN, 32, TFS(&is_set), EDP_SFS_OPTION_RESOLVE,
646                         NULL, HFILL }
647                 },
648                 { &hf_ismp_edp_sfs_option_unused2,
649                         { "Unused", "ismp.edp.sfs_option_unused2",
650                         FT_BOOLEAN, 32, TFS(&is_set), EDP_SFS_OPTION_UNUSED2,
651                         NULL, HFILL }
652                 },
653                 { &hf_ismp_edp_sfs_option_tagflood,
654                         { "Tagged Flood Support", "ismp.edp.sfs_option_tagflood",
655                         FT_BOOLEAN, 32, TFS(&is_set), EDP_SFS_OPTION_TAGFLOOD,
656                         NULL, HFILL }
657                 },
658                 { &hf_ismp_edp_sfs_option_calltap,
659                         { "Call Tap Support", "ismp.edp.sfs_option_calltap",
660                         FT_BOOLEAN, 32, TFS(&is_set), EDP_SFS_OPTION_CALLTAP,
661                         NULL, HFILL }
662                 },
663                 { &hf_ismp_edp_sfs_option_conmsg,
664                         { "Connection Message Support", "ismp.edp.sfs_option_conmsg",
665                         FT_BOOLEAN, 32, TFS(&is_set), EDP_SFS_OPTION_CONMSG,
666                         NULL, HFILL }
667                 },
668                 { &hf_ismp_edp_sfs_option_redun,
669                         { "Redundant Access Support", "ismp.edp.sfs_option_redun",
670                         FT_BOOLEAN, 32, TFS(&is_set), EDP_SFS_OPTION_REDUN,
671                         NULL, HFILL }
672                 },
673                 { &hf_ismp_edp_sfs_option_isolated,
674                         { "Isolated Switch", "ismp.edp.sfs_option_isolated",
675                         FT_BOOLEAN, 32, TFS(&is_set), EDP_SFS_OPTION_ISOLATED,
676                         NULL, HFILL }
677                 },
678                 { &hf_ismp_edp_sfs_option_uplink_switch,
679                         { "Uplink Switch", "ismp.edp.sfs_option_uplink_switch",
680                         FT_BOOLEAN, 32, TFS(&is_set), EDP_SFS_OPTION_UPLINK_SWITCH,
681                         NULL, HFILL }
682                 },
683                 { &hf_ismp_edp_sfs_option_uplink_core,
684                         { "Uplink Core", "ismp.edp.sfs_option_uplink_core",
685                         FT_BOOLEAN, 32, TFS(&is_set), EDP_SFS_OPTION_UPLINK_CORE,
686                         NULL, HFILL }
687                 },
688                 { &hf_ismp_edp_sfs_option_uplink_port,
689                         { "Uplink Port", "ismp.edp.sfs_option_uplink_port",
690                         FT_BOOLEAN, 32, TFS(&is_set), EDP_SFS_OPTION_UPLINK_PORT,
691                         NULL, HFILL }
692                 },
693                 { &hf_ismp_edp_sfs_option_uplink_flood,
694                         { "Uplink Flood Support", "ismp.edp.sfs_option_uplink_flood",
695                         FT_BOOLEAN, 32, TFS(&is_set), EDP_SFS_OPTION_UPLINK_FLOOD,
696                         NULL, HFILL }
697                 },
698                 { &hf_ismp_edp_rtr_option_ssr,
699                         { "SSR Type Device", "ismp.edp.rtr_option_ssr",
700                         FT_BOOLEAN, 32, TFS(&is_set), EDP_RTR_OPTION_SSR,
701                         NULL, HFILL }
702                 },
703                 { &hf_ismp_edp_rtr_option_igmp,
704                         { "IGMP Active", "ismp.edp.rtr_option_igmp",
705                         FT_BOOLEAN, 32, TFS(&is_set), EDP_RTR_OPTION_IGMP,
706                         NULL, HFILL }
707                 },
708                 { &hf_ismp_edp_rtr_option_rip,
709                         { "RIP Active", "ismp.edp.rtr_option_rip",
710                         FT_BOOLEAN, 32, TFS(&is_set), EDP_RTR_OPTION_RIP,
711                         NULL, HFILL }
712                 },
713                 { &hf_ismp_edp_rtr_option_bgp,
714                         { "BGP Active", "ismp.edp.rtr_option_bgp",
715                         FT_BOOLEAN, 32, TFS(&is_set), EDP_RTR_OPTION_BGP,
716                         NULL, HFILL }
717                 },
718                 { &hf_ismp_edp_rtr_option_ospf,
719                         { "OSPF Active", "ismp.edp.rtr_option_ospf",
720                         FT_BOOLEAN, 32, TFS(&is_set), EDP_RTR_OPTION_OSPF,
721                         NULL, HFILL }
722                 },
723                 { &hf_ismp_edp_rtr_option_dvmrp,
724                         { "DVMRP Active", "ismp.edp.rtr_option_dvmrp",
725                         FT_BOOLEAN, 32, TFS(&is_set), EDP_RTR_OPTION_DVMRP,
726                         NULL, HFILL }
727                 },
728                 { &hf_ismp_edp_rtr_option_8021q,
729                         { "802.1Q Support", "ismp.edp.rtr_option_8021q",
730                         FT_BOOLEAN, 32, TFS(&is_set), EDP_RTR_OPTION_8021Q,
731                         NULL, HFILL }
732                 },
733                 { &hf_ismp_edp_rtr_option_gvrp,
734                         { "GVRP Support", "ismp.edp.rtr_option_gvrp",
735                         FT_BOOLEAN, 32, TFS(&is_set), EDP_RTR_OPTION_GVRP,
736                         NULL, HFILL }
737                 },
738                 { &hf_ismp_edp_rtr_option_gmrp,
739                         { "GMRP Support", "ismp.edp.rtr_option_gmrp",
740                         FT_BOOLEAN, 32, TFS(&is_set), EDP_RTR_OPTION_GMRP,
741                         NULL, HFILL }
742                 },
743                 { &hf_ismp_edp_rtr_option_igmp_snoop,
744                         { "IGMP Snooping Support", "ismp.edp.rtr_option_igmp_snoop",
745                         FT_BOOLEAN, 32, TFS(&is_set), EDP_RTR_OPTION_IGMP_SNOOP,
746                         NULL, HFILL }
747                 },
748                 { &hf_ismp_edp_rtr_option_route,
749                         { "Route Bridging", "ismp.edp.rtr_option_route",
750                         FT_BOOLEAN, 32, TFS(&is_set), EDP_RTR_OPTION_ROUTE,
751                         NULL, HFILL }
752                 },
753                 { &hf_ismp_edp_rtr_option_trans,
754                         { "Transparent Bridging", "ismp.edp.rtr_option_trans",
755                         FT_BOOLEAN, 32, TFS(&is_set), EDP_RTR_OPTION_TRANS,
756                         NULL, HFILL }
757                 },
758                 { &hf_ismp_edp_rtr_option_level1,
759                         { "Level 1 Functionality", "ismp.edp.rtr_option_level1",
760                         FT_BOOLEAN, 32, TFS(&is_set), EDP_RTR_OPTION_LEVEL1,
761                         NULL, HFILL }
762                 },
763                 { &hf_ismp_edp_switch_option_8021q,
764                         { "802.1Q Support", "ismp.edp.switch_option_8021q",
765                         FT_BOOLEAN, 32, TFS(&is_set), EDP_SWITCH_OPTION_8021Q,
766                         NULL, HFILL }
767                 },
768                 { &hf_ismp_edp_switch_option_gvrp,
769                         { "GVRP Support", "ismp.edp.switch_option_gvrp",
770                         FT_BOOLEAN, 32, TFS(&is_set), EDP_SWITCH_OPTION_GVRP,
771                         NULL, HFILL }
772                 },
773                 { &hf_ismp_edp_switch_option_gmrp,
774                         { "GMRP Support", "ismp.edp.switch_option_gmrp",
775                         FT_BOOLEAN, 32, TFS(&is_set), EDP_SWITCH_OPTION_GMRP,
776                         NULL, HFILL }
777                 },
778                 { &hf_ismp_edp_switch_option_igmp,
779                         { "IGMP Snooping Support", "ismp.edp.switch_option_igmp",
780                         FT_BOOLEAN, 32, TFS(&is_set), EDP_SWITCH_OPTION_IGMP,
781                         NULL, HFILL }
782                 },
783                 { &hf_ismp_edp_switch_option_route,
784                         { "Route Bridging", "ismp.edp.switch_option_route",
785                         FT_BOOLEAN, 32, TFS(&is_set), EDP_SWITCH_OPTION_ROUTE,
786                         NULL, HFILL }
787                 },
788                 { &hf_ismp_edp_switch_option_trans,
789                         { "Transparent Bridging", "ismp.edp.switch_option_trans",
790                         FT_BOOLEAN, 32, TFS(&is_set), EDP_SWITCH_OPTION_TRANS,
791                         NULL, HFILL }
792                 },
793                 { &hf_ismp_edp_switch_option_level1,
794                         { "Level 1 Functionality", "ismp.edp.switch_option_level1",
795                         FT_BOOLEAN, 32, TFS(&is_set), EDP_SWITCH_OPTION_LEVEL1,
796                         NULL, HFILL }
797                 },
798                 { &hf_ismp_edp_end_station_option_dhcp,
799                         { "DHCP Enabled", "ismp.edp.end_station_option_dhcp",
800                         FT_BOOLEAN, 32, TFS(&is_set), EDP_END_STATION_OPTION_DHCP,
801                         NULL, HFILL }
802                 },
803                 { &hf_ismp_edp_end_station_option_dns,
804                         { "DNS Enabled", "ismp.edp.end_station_option_dns",
805                         FT_BOOLEAN, 32, TFS(&is_set), EDP_END_STATION_OPTION_DNS,
806                         NULL, HFILL }
807                 },
808                 { &hf_ismp_edp_end_station_option_ad,
809                         { "Active Directory Enabled", "ismp.edp.end_station_option_ad",
810                         FT_BOOLEAN, 32, TFS(&is_set), EDP_END_STATION_OPTION_AD,
811                         NULL, HFILL }
812                 },
813                 { &hf_ismp_edp_num_neighbors,
814                         { "Number of Known Neighbors", "ismp.edp.maccount",
815                         FT_UINT16, BASE_DEC, NULL, 0x0,
816                         NULL, HFILL }
817                 },
818                 { &hf_ismp_edp_neighbors,
819                         { "Neighbors", "ismp.edp.nbrs",
820                         FT_BYTES, BASE_NONE, NULL, 0x0,
821                         NULL, HFILL }
822                 },
823                 { &hf_ismp_edp_num_tuples,
824                         { "Number of Tuples", "ismp.edp.numtups",
825                         FT_UINT16, BASE_DEC, NULL, 0x0,
826                         NULL, HFILL }
827                 },
828                 { &hf_ismp_edp_tuples,
829                         { "Number of Tuples", "ismp.edp.tups",
830                         FT_BYTES, BASE_NONE, NULL, 0x0,
831                         NULL, HFILL }
832                 },
833         };
834
835 /* Setup protocol subtree array */
836         static gint *ett[] = {
837                 &ett_ismp,
838                 &ett_ismp_edp,
839                 &ett_ismp_edp_options,
840                 &ett_ismp_edp_neighbors,
841                 &ett_ismp_edp_neighbors_leaf,
842                 &ett_ismp_edp_tuples,
843                 &ett_ismp_edp_tuples_leaf,
844         };
845
846 /* Register the protocol name and description */
847         proto_ismp = proto_register_protocol("InterSwitch Message Protocol",
848             "ISMP", "ismp");
849
850 /* Required function calls to register the header fields and subtrees used */
851         proto_register_field_array(proto_ismp, hf, array_length(hf));
852         proto_register_subtree_array(ett, array_length(ett));
853 }
854
855
856 /* If this dissector uses sub-dissector registration add a registration routine.
857    This format is required because a script is used to find these routines and
858    create the code that calls these routines.
859 */
860 void
861 proto_reg_handoff_ismp(void)
862 {
863         dissector_handle_t ismp_handle;
864
865         ismp_handle = create_dissector_handle(dissect_ismp,
866             proto_ismp);
867         dissector_add_uint("ethertype", ETHERTYPE_ISMP, ismp_handle);
868 }