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