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