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