Sanitize epan includes
[obnox/wireshark/wip.git] / epan / dissectors / packet-nt-sonmp.c
1 /* packet-sonmp.c
2 * Routines for the disassembly of the "Nortel Networks / SynOptics Network Management Protocol"
3 * (c) Copyright Giles Scott <giles.scott1 [AT] arubanetworks.com>
4 *
5 * $Id$
6 *
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
10
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 * GNU General Public License for more details.
20
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24 */
25
26 #include "config.h"
27
28 #ifdef HAVE_SYS_TYPES_H
29 #include <sys/types.h>
30 #endif
31
32 #include <stdlib.h>
33 #include <string.h>
34
35 #include <glib.h>
36 #include <epan/packet.h>
37 #include <epan/nlpid.h>
38
39 /* Although this protocol is propietary it is documented in the SynOptics MIB's
40 * So I'm not giving anything away :-)
41 * The only thing I have not done is decode the segment identifier;
42 * This changes so much depending on whether the chassis supports
43 * multi-segment autotopology. As the 5000 is now EOL don't see much point.
44 *
45 * MIB's s5emt104.mib, s5tcs112.mib, synro199.mib these should be available via
46 * http://www.nortelnetworks.com
47 */
48
49   
50 /* chassis types */
51 /* From  synro199.mib - SnpxChassisType */
52 static const value_string sonmp_chassis_val[] =
53 {
54         {2, "m3000"},
55         {3, "m3030"},
56         {4, "m2310"},
57         {5, "m2810"},
58         {6, "m2912"},
59         {7, "m2914"},
60         {8, "m271x"},
61         {9, "m2813"},
62         {10, "m2814"},
63         {11, "m2915"},
64         {12, "m5000"},
65         {13, "m2813SA"},
66         {14, "m2814SA"},
67         {15, "m810M"},
68         {16, "m1032x Ethercell"},
69         {17, "5005"},
70         {18, "Alcatel Ethernet workgroup conc"},
71         {20, "m2715SA"},
72         {21, "m2486"},
73         {22, "m28xxx"},
74         {23, "m23xxx"},
75         {24, "5DN000"},
76         {25, "NBayStack"},
77         {26, "m2310x"},
78         {27, "BayStack100 hub"},
79         {28, "M3000 Fast ethernet"},
80         {29, "Xedia"},
81         {31, "28200"},
82         {32, "Centillion-sixSlot"},
83         {33, "Centillion-twelveSlot"},
84         {34, "Centillion-singleSlot"},
85         {35, "BayStack301"},
86         {36, "BayStackTr"},
87         {37, "FVC Multimedia Switch"},
88         {38, "SwitchNode"},
89         {39, "BayStack 302"},
90         {40, "BayStack 350"},
91         {41, "BayStack 150"},
92         {42, "Centillion 50"},
93         {43, "Centillion 50tr"},
94         {44, "BayStack 303-304"},
95         {45, "BayStack 200"},
96         {46, "BayStack 250"},
97         {47, "StackProbe"},
98         {48, "BayStack 450"},
99         {49, "BayStack 303-24T"},
100         {50, "Accelar 1200 L3 switch"},
101         {51, "Accelar 1250 L3 switch"},
102         {52, "Accelar 1100 L3 switch"},
103         {53, "Accelar 1150 L3 switch"},
104         {54, "Accelar 1050 L3 switch"},
105         {55, "Accelar 1051 L3 switch"},
106         {56, "Accelar 8610 L3 switch"},
107         {57, "Accelar 8006"},
108         {58, "Accelar 8010"},
109         {59, "Accelar 8006"},
110         {60, "BayStack 670"},
111         {61, "Accelar 740"},
112         {62, "Accelar 750"},
113         {63, "Accelar 790"},
114         {64, "Business Policy switch 2000"},
115         {65, "Accelar 8110 L2 switch"},
116         {66, "Accelar 8106 L2 switch"},
117         {67, "BayStack 3580"},
118         {68, "Baystack 10 PSU"},
119         {69, "BayStack 420"},
120         {70, "OPTera Metro 1200ESM"},
121         {71, "OPTera 8010co"},
122         {72, "OPTera 8610co L3 switch"},
123         {73, "OPTera 8110co L2 switch"},
124         {74, "OPTera 8003"},
125         {75, "OPTera 8603 L3 switch"},
126         {76, "OPTera 8103 L2 switch"},
127         {77, "Baystack 380 10/100/1000 switch"},
128         {78, "Baystack 470 10/100 switch"},
129         {79, "OPTera Metro 1450ESM"},
130         {80, "OPTera Metro 1400ESM"},
131         {81, "Alteon switch family"},
132         {82, "BayStack 460-24T-PWR"},
133         {83, "OPTera Metro 8010 OPM L2 Switch"},
134         {84, "OPTera Metro 8010co OPM L2 Switch"},
135         {85, "OPTera Metro 8006 OPM L2 Switch"},
136         {86, "OPTera Metro 8003 OPM L2 Switch"},
137         {87, "Alteon 180e"},
138         {88, "Alteon AD3"},
139         {89, "Alteon 184"},
140         {90, "Alteon AD4"},
141         {91, "Passport 1424 L3 switch"},
142         {92, "Passport 1648 L3 switch"},
143         {93, "Passport 1612 L3 switch"},
144         {94, "Passport 1624 L3 switch"},
145         {95, "BayStack 380-24F Fiber 1000 switch"},
146         {96, "BayStack 4700 24T switch"},
147         {97, "BayStack 4700 48T switch"},
148         {98, "BayStack 5510 24-port"},
149         {99, "BayStack 2200 Wireless LAN AP"},
150         {100, "Passport RBS 2402 L3 switch"},
151         {101, "Alteon AAS 2424"},
152         {102, "Alteon AAS 2224"},
153         {103, "Alteon AAS 2208"},
154         {104, "Alteon AAS 2216"},
155         {105, "Alteon AAS 3408"},
156         {106, "Alteon AAS 3416"}, 
157         {107, "WLAN SecuritySwitch 2250"},
158         {108, "BayStack 425 48-port"},
159         {109, "Baystack 425 24-port"},
160         {110, "WLAN AP 2221"},
161         {0, NULL}
162 };
163
164 /* from synro179.mib - SnpxBackplaneType */
165 static const value_string sonmp_backplane_val[] =
166 {
167         {1, "Other"},
168         {2, "ethernet"},
169         {3, "ethernet and tokenring"},
170         {4, "ethernet and FDDI"},
171         {5, "ethernet, tokenring and FDDI"},
172         {6, "ethernet and tokenring with redundant power"},
173         {7, "ethernet, tokenring, FDDI with redundant power"},
174         {8, "token ring"},
175         {9, "ethernet, tokenring and fast ethernet"},
176         {10, "ethernet and fast ethernet"},
177         {11, "ethernet, tokenring, fast ethernet with redundant power"},
178         {12, "ethernet, fast ethernet and gigabit ethernet"},
179         {0, NULL}
180 };
181
182 static const value_string sonmp_nmm_state_val[] =
183 {
184         {1, "Topology Change"},
185         {2, "Heartbeat"},
186         {3, "New"},
187         {0, NULL}
188 };
189
190
191 /* Offsets in SONMP NMM Hello structure. */
192 #define SONMP_IP_ADDRESS 0
193 #define SONMP_SEGMENT_IDENTIFIER 4
194 #define SONMP_CHASSIS_TYPE 7
195 #define SONMP_BACKPLANE_TYPE 8
196 #define SONMP_NMM_STATE 9
197 #define SONMP_NUMBER_OF_LINKS 10
198
199 static int proto_sonmp = -1;
200 static int hf_sonmp_ip_address = -1;
201 static int hf_sonmp_segment_identifier = -1; 
202 static int hf_sonmp_chassis_type = -1;
203 static int hf_sonmp_backplane_type = -1;
204 static int hf_sonmp_nmm_state = -1;
205 static int hf_sonmp_number_of_links = -1;
206
207 static gint ett_sonmp = -1;
208
209
210 static void 
211 dissect_sonmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
212 {
213         const char *hello_type;
214         proto_tree *sonmp_tree = NULL;
215         proto_item *ti;
216         
217         col_set_str(pinfo->cinfo, COL_PROTOCOL, "SONMP");
218         
219         if (check_col(pinfo->cinfo, COL_INFO)) {
220                 hello_type = "";
221                 if (pinfo->dl_dst.type == AT_ETHER) {
222                         const guint8 *dstmac = pinfo->dl_dst.data;
223
224                         switch (dstmac[5]) {
225
226                         case 0:
227                                 hello_type = "Segment ";
228                                 break;
229
230                         case 1:
231                                 hello_type = "FlatNet ";
232                                 break;
233                         }
234                 }
235                 col_add_fstr(pinfo->cinfo, COL_INFO, "SONMP - %sHello",
236                     hello_type);
237         }
238         
239         if (tree) {
240                 ti = proto_tree_add_protocol_format(tree, proto_sonmp, tvb, 0, 11,
241                         "Nortel Networks / SynOptics Network Management Protocol");
242                 sonmp_tree = proto_item_add_subtree(ti, ett_sonmp);
243                 
244                 proto_tree_add_item(sonmp_tree, hf_sonmp_ip_address, tvb,
245                         SONMP_IP_ADDRESS, 4, FALSE);
246                 
247                 
248                 proto_tree_add_item(sonmp_tree, hf_sonmp_segment_identifier, tvb, 
249                         SONMP_SEGMENT_IDENTIFIER, 3, FALSE);
250                 
251                 
252                 proto_tree_add_item(sonmp_tree, hf_sonmp_chassis_type, tvb,
253                         SONMP_CHASSIS_TYPE, 1, FALSE);
254                 
255                 proto_tree_add_item(sonmp_tree, hf_sonmp_backplane_type, tvb,
256                         SONMP_BACKPLANE_TYPE, 1, FALSE);
257                 
258                 
259                 proto_tree_add_item(sonmp_tree, hf_sonmp_nmm_state, tvb,
260                         SONMP_NMM_STATE, 1, FALSE);
261                 
262                 proto_tree_add_item(sonmp_tree, hf_sonmp_number_of_links, tvb,
263                         SONMP_NUMBER_OF_LINKS, 1, FALSE);
264         }
265         
266         
267 }
268
269
270
271 void
272 proto_register_sonmp(void)
273 {
274     static hf_register_info hf[] = {
275                 { &hf_sonmp_ip_address,
276                 { "NMM IP address",             "sonmp.ipaddress",  FT_IPv4, BASE_NONE, NULL, 0x0,
277                 "IP address of the agent (NMM)", HFILL }},
278                 
279                 { &hf_sonmp_segment_identifier,
280                 { "Segment Identifier",         "sonmp.segmentident", FT_UINT24, BASE_HEX, NULL, 0x0,
281                 "Segment id of the segment from which the agent is sending the topology message", HFILL }},
282                 
283                 { &hf_sonmp_chassis_type,
284                 { "Chassis type",               "sonmp.chassis", FT_UINT8, BASE_DEC, 
285                 VALS(sonmp_chassis_val), 0x0,
286                 "Chassis type of the agent sending the topology message", HFILL }},
287                 
288                 { &hf_sonmp_backplane_type,
289                 { "Backplane type",             "sonmp.backplane", FT_UINT8, BASE_DEC,
290                  VALS(sonmp_backplane_val), 0x0,
291                 "Backplane type of the agent sending the topology message", HFILL }},
292                 
293                 { &hf_sonmp_nmm_state,
294                 { "NMM state",          "sonmp.nmmstate", FT_UINT8, BASE_DEC,
295                  VALS(sonmp_nmm_state_val), 0x0,
296                 "Current state of this agent", HFILL }},
297                 
298                 { &hf_sonmp_number_of_links,
299                 { "Number of links",            "sonmp.numberoflinks", FT_UINT8, BASE_DEC, NULL, 0x0,
300                 "Number of interconnect ports", HFILL }},
301     };
302         
303     static gint *ett[] = {
304                 &ett_sonmp,
305     };
306     proto_sonmp = proto_register_protocol("Nortel SONMP", "SONMP", "sonmp");
307     proto_register_field_array(proto_sonmp, hf, array_length(hf));
308     proto_register_subtree_array(ett, array_length(ett));
309         
310     register_dissector("sonmp", dissect_sonmp, proto_sonmp);
311 }
312
313 void
314 proto_reg_handoff_sonmp(void)
315 {
316         dissector_handle_t sonmp_handle;
317         
318         sonmp_handle = find_dissector("sonmp");
319         
320         dissector_add("llc.nortel_pid", 0x01a1, sonmp_handle); /* flatnet hello */
321         dissector_add("llc.nortel_pid", 0x01a2, sonmp_handle); /* Segment hello */ 
322         /* not got round to adding this but its really old, so I'm not sure people will see it */
323         /* it uses a different packet format */
324         /*      dissector_add("llc.nortel_pid", 0x01a3, sonmp_handle); */ /* Bridge hello */
325 }