c432069608665280250bfed2bd2f46a0274ebcbf
[metze/wireshark/wip.git] / epan / dissectors / packet-ipxwan.c
1 /* packet-ipxwan.c
2  * Routines for NetWare IPX WAN Protocol
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #include "config.h"
24
25 #include <epan/packet.h>
26 #include <epan/expert.h>
27 #include "packet-ipx.h"
28
29 void proto_register_ipxwan(void);
30 void proto_reg_handoff_ipxwan(void);
31
32 /*
33  * See RFC 1362 for version 1 of this protocol; see the NetWare Link
34  * Services Protocol Specification, chapter 3, for version 2.
35  */
36 static int proto_ipxwan = -1;
37
38 static int hf_ipxwan_identifier = -1;
39 static int hf_ipxwan_packet_type = -1;
40 static int hf_ipxwan_node_id = -1;
41 static int hf_ipxwan_sequence_number = -1;
42 static int hf_ipxwan_num_options = -1;
43 static int hf_ipxwan_option_num = -1;
44 static int hf_ipxwan_accept_option = -1;
45 static int hf_ipxwan_option_data_len = -1;
46 static int hf_ipxwan_routing_type = -1;
47 static int hf_ipxwan_wan_link_delay = -1;
48 static int hf_ipxwan_common_network_number = -1;
49 static int hf_ipxwan_router_name = -1;
50 static int hf_ipxwan_delay = -1;
51 static int hf_ipxwan_throughput = -1;
52 static int hf_ipxwan_request_size = -1;
53 static int hf_ipxwan_delta_time = -1;
54 static int hf_ipxwan_extended_node_id = -1;
55 static int hf_ipxwan_node_number = -1;
56 static int hf_ipxwan_compression_type = -1;
57 static int hf_ipxwan_compression_options = -1;
58 static int hf_ipxwan_compression_slots = -1;
59 static int hf_ipxwan_compression_parameters = -1;
60 static int hf_ipxwan_padding = -1;
61 static int hf_ipxwan_option_value = -1;
62
63 static gint ett_ipxwan = -1;
64 static gint ett_ipxwan_option = -1;
65
66 static expert_field ei_ipxwan_option_data_len = EI_INIT;
67
68 static const value_string ipxwan_packet_type_vals[] = {
69         { 0,    "Timer Request" },
70         { 1,    "Timer Response" },
71         { 2,    "Information Request" },
72         { 3,    "Information Response" },
73         { 4,    "Throughput Request" },
74         { 5,    "Throughput Response" },
75         { 6,    "Delay Request" },
76         { 7,    "Delay Response" },
77         { 0xFF, "NAK" },
78         { 0,    NULL }
79 };
80
81 #define OPT_ROUTING_TYPE                0x00
82 #define OPT_RIP_SAP_INFO_EXCHANGE       0x01
83 #define OPT_NLSP_INFORMATION            0x02
84 #define OPT_NLSP_RAW_THROUGHPUT_DATA    0x03
85 #define OPT_EXTENDED_NODE_ID            0x04
86 #define OPT_NODE_NUMBER                 0x05
87 #define OPT_COMPRESSION                 0x80
88 #define OPT_PAD                         0xFF
89
90 static const value_string ipxwan_option_num_vals[] = {
91         { OPT_ROUTING_TYPE,             "Routing Type" },
92         { OPT_RIP_SAP_INFO_EXCHANGE,    "RIP/SAP Info Exchange" },
93         { OPT_NLSP_INFORMATION,         "NLSP Information" },
94         { OPT_NLSP_RAW_THROUGHPUT_DATA, "NLSP Raw Throughput Data" },
95         { OPT_EXTENDED_NODE_ID,         "Extended Node ID" },
96         { OPT_NODE_NUMBER,              "Node Number" },
97         { OPT_COMPRESSION,              "Compression" },
98         { OPT_PAD,                      "Pad" },
99         { 0,                            NULL }
100 };
101
102 static const value_string ipxwan_accept_option_vals[] = {
103         { 0, "No" },
104         { 1, "Yes" },
105         { 3, "Not Applicable" },
106         { 0, NULL }
107 };
108
109 static const value_string ipxwan_routing_type_vals[] = {
110         { 0, "RIP" },
111         { 1, "NLSP" },
112         { 2, "Unnumbered RIP" },
113         { 3, "On-demand, static routing" },
114         { 4, "Client-router connection" },
115         { 0, NULL }
116 };
117
118 #define COMP_TYPE_TELEBIT       0
119
120 static const value_string ipxwan_compression_type_vals[] = {
121         { COMP_TYPE_TELEBIT, "Telebit" },
122         { 0,                 NULL }
123 };
124
125 static int
126 dissect_ipxwan(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
127 {
128         proto_item *ti;
129         proto_tree *ipxwan_tree = NULL;
130         int offset = 0;
131         guint8 packet_type;
132         guint8 num_options;
133         guint8 option_number;
134         proto_tree *option_tree;
135         guint16 option_data_len;
136         guint16 wan_link_delay;
137         guint32 delay;
138         guint32 throughput;
139         guint32 delta_time;
140         guint8 compression_type;
141
142         col_set_str(pinfo->cinfo, COL_PROTOCOL, "IPX WAN");
143         col_clear(pinfo->cinfo, COL_INFO);
144
145         ti = proto_tree_add_item(tree, proto_ipxwan, tvb, 0, -1,
146                 ENC_NA);
147         ipxwan_tree = proto_item_add_subtree(ti, ett_ipxwan);
148
149         proto_tree_add_item(ipxwan_tree, hf_ipxwan_identifier, tvb,
150                     offset, 4, ENC_ASCII|ENC_NA);
151
152         offset += 4;
153         packet_type = tvb_get_guint8(tvb, offset);
154         col_add_str(pinfo->cinfo, COL_INFO,
155                     val_to_str(packet_type, ipxwan_packet_type_vals,
156                         "Unknown packet type %u"));
157
158         proto_tree_add_uint(ipxwan_tree, hf_ipxwan_packet_type, tvb,
159                 offset, 1, packet_type);
160         offset += 1;
161         proto_tree_add_item(ipxwan_tree, hf_ipxwan_node_id, tvb,
162                 offset, 4, ENC_BIG_ENDIAN);
163         offset += 4;
164         proto_tree_add_item(ipxwan_tree, hf_ipxwan_sequence_number, tvb,
165                 offset, 1, ENC_BIG_ENDIAN);
166         offset += 1;
167         num_options = tvb_get_guint8(tvb, offset);
168         proto_tree_add_uint(ipxwan_tree, hf_ipxwan_num_options, tvb,
169                 offset, 1, num_options);
170         offset += 1;
171
172         while (num_options != 0) {
173                 option_number = tvb_get_guint8(tvb, offset);
174                 option_tree = proto_tree_add_subtree_format(ipxwan_tree, tvb, offset, -1,
175                         ett_ipxwan_option, &ti, "Option: %s",
176                         val_to_str(option_number, ipxwan_option_num_vals,
177                             "Unknown (%u)"));
178
179                 proto_tree_add_uint(option_tree, hf_ipxwan_option_num,
180                         tvb, offset, 1, option_number);
181                 offset += 1;
182                 proto_tree_add_item(option_tree, hf_ipxwan_accept_option,
183                         tvb, offset, 1, ENC_BIG_ENDIAN);
184                 offset += 1;
185                 option_data_len = tvb_get_ntohs(tvb, offset);
186                 proto_tree_add_uint(option_tree, hf_ipxwan_option_data_len,
187                         tvb, offset, 2, option_data_len);
188                 offset += 2;
189                 proto_item_set_len(ti, option_data_len+4);
190                 switch (option_number) {
191
192                 case OPT_ROUTING_TYPE:
193                         if (option_data_len != 1) {
194                                 expert_add_info_format(pinfo, ti, &ei_ipxwan_option_data_len,
195                                         "Bogus length: %u, should be 1", option_data_len);
196                         } else {
197                                 proto_tree_add_item(option_tree,
198                                         hf_ipxwan_routing_type, tvb,
199                                         offset, 1, ENC_BIG_ENDIAN);
200                         }
201                         break;
202
203                 case OPT_RIP_SAP_INFO_EXCHANGE:
204                         if (option_data_len != 54) {
205                                 expert_add_info_format(pinfo, ti, &ei_ipxwan_option_data_len,
206                                         "Bogus length: %u, should be 54", option_data_len);
207                         } else {
208                                 wan_link_delay = tvb_get_ntohs(tvb,
209                                         offset);
210                                 proto_tree_add_uint_format_value(option_tree,
211                                         hf_ipxwan_wan_link_delay, tvb,
212                                         offset, 2, wan_link_delay,
213                                         "%ums",
214                                         wan_link_delay);
215                                 proto_tree_add_item(option_tree,
216                                         hf_ipxwan_common_network_number,
217                                         tvb, offset+2, 4, ENC_NA);
218                                 proto_tree_add_item(option_tree,
219                                         hf_ipxwan_router_name, tvb,
220                                         offset+6, 48, ENC_ASCII|ENC_NA);
221                         }
222                         break;
223
224                 case OPT_NLSP_INFORMATION:
225                         if (option_data_len != 8) {
226                                 expert_add_info_format(pinfo, ti, &ei_ipxwan_option_data_len,
227                                         "Bogus length: %u, should be 8", option_data_len);
228                         } else {
229                                 delay = tvb_get_ntohl(tvb, offset);
230                                 proto_tree_add_uint_format_value(option_tree,
231                                         hf_ipxwan_delay, tvb,
232                                         offset, 4, delay,
233                                         "%uus", delay);
234                                 throughput = tvb_get_ntohl(tvb, offset);
235                                 proto_tree_add_uint_format_value(option_tree,
236                                         hf_ipxwan_throughput, tvb,
237                                         offset, 4, throughput,
238                                         "%uus",
239                                         throughput);
240                         }
241                         break;
242
243                 case OPT_NLSP_RAW_THROUGHPUT_DATA:
244                         if (option_data_len != 8) {
245                                 expert_add_info_format(pinfo, ti, &ei_ipxwan_option_data_len,
246                                         "Bogus length: %u, should be 8", option_data_len);
247                         } else {
248                                 proto_tree_add_item(option_tree,
249                                         hf_ipxwan_request_size, tvb,
250                                         offset, 4, ENC_BIG_ENDIAN);
251                                 delta_time = tvb_get_ntohl(tvb, offset);
252                                 proto_tree_add_uint_format_value(option_tree,
253                                         hf_ipxwan_delta_time, tvb,
254                                         offset, 4, delta_time,
255                                         "%uus",
256                                         delta_time);
257                         }
258                         break;
259
260                 case OPT_EXTENDED_NODE_ID:
261                         if (option_data_len != 4) {
262                                 expert_add_info_format(pinfo, ti, &ei_ipxwan_option_data_len,
263                                         "Bogus length: %u, should be 4", option_data_len);
264                         } else {
265                                 proto_tree_add_item(option_tree,
266                                         hf_ipxwan_extended_node_id, tvb,
267                                         offset, 4, ENC_NA);
268                         }
269                         break;
270
271                 case OPT_NODE_NUMBER:
272                         if (option_data_len != 6) {
273                                 expert_add_info_format(pinfo, ti, &ei_ipxwan_option_data_len,
274                                         "Bogus length: %u, should be 6", option_data_len);
275                         } else {
276                                 proto_tree_add_item(option_tree,
277                                         hf_ipxwan_node_number, tvb,
278                                         offset, 6, ENC_NA);
279                         }
280                         break;
281
282                 case OPT_COMPRESSION:
283                         if (option_data_len < 1) {
284                                 expert_add_info_format(pinfo, ti, &ei_ipxwan_option_data_len,
285                                         "Bogus length: %u, should be >= 1", option_data_len);
286                         } else {
287                                 compression_type = tvb_get_guint8(tvb,
288                                         offset);
289                                 ti = proto_tree_add_uint(option_tree,
290                                         hf_ipxwan_compression_type, tvb,
291                                         offset, 1, compression_type);
292                                 switch (compression_type) {
293
294                                 case COMP_TYPE_TELEBIT:
295                                         if (option_data_len < 3) {
296                                                 expert_add_info_format(pinfo, ti, &ei_ipxwan_option_data_len,
297                                                         "Bogus length: %u, should be >= 3", option_data_len);
298                                         } else {
299                                                 proto_tree_add_item(option_tree, hf_ipxwan_compression_options,
300                                                         tvb, offset+1, 1, ENC_BIG_ENDIAN);
301                                                 proto_tree_add_item(option_tree, hf_ipxwan_compression_slots,
302                                                         tvb, offset+2, 1, ENC_BIG_ENDIAN);
303                                         }
304                                         break;
305
306                                 default:
307                                         proto_tree_add_item(option_tree, hf_ipxwan_compression_parameters,
308                                                 tvb, offset+1, option_data_len-1, ENC_NA);
309                                         break;
310                                 }
311                         }
312                         break;
313
314                 case OPT_PAD:
315                         proto_tree_add_item(option_tree, hf_ipxwan_padding,
316                                 tvb, offset, option_data_len, ENC_NA);
317                         break;
318
319                 default:
320                         proto_tree_add_item(option_tree, hf_ipxwan_option_value,
321                                 tvb, offset, option_data_len, ENC_NA);
322                         break;
323                 }
324
325                 offset += option_data_len;
326                 num_options--;
327         }
328         return tvb_captured_length(tvb);
329 }
330
331 void
332 proto_register_ipxwan(void)
333 {
334         static hf_register_info hf[] = {
335             { &hf_ipxwan_identifier,
336               { "Identifier",   "ipxwan.identifier",
337                 FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
338
339             { &hf_ipxwan_packet_type,
340               { "Packet Type", "ipxwan.packet_type",
341                 FT_UINT8, BASE_DEC, VALS(ipxwan_packet_type_vals), 0x0, NULL,
342                 HFILL }},
343
344             { &hf_ipxwan_node_id,
345               { "Node ID", "ipxwan.node_id", FT_UINT32,
346                  BASE_HEX, NULL, 0x0, NULL, HFILL }},
347
348             { &hf_ipxwan_sequence_number,
349               { "Sequence Number", "ipxwan.sequence_number", FT_UINT8,
350                  BASE_DEC, NULL, 0x0, NULL, HFILL }},
351
352             { &hf_ipxwan_num_options,
353               { "Number of Options", "ipxwan.num_options", FT_UINT8,
354                  BASE_DEC, NULL, 0x0, NULL, HFILL }},
355
356             { &hf_ipxwan_option_num,
357               { "Option Number", "ipxwan.option_num", FT_UINT8,
358                  BASE_HEX, VALS(ipxwan_option_num_vals), 0x0, NULL, HFILL }},
359
360             { &hf_ipxwan_accept_option,
361               { "Accept Option", "ipxwan.accept_option", FT_UINT8,
362                  BASE_DEC, VALS(ipxwan_accept_option_vals), 0x0, NULL, HFILL }},
363
364             { &hf_ipxwan_option_data_len,
365               { "Option Data Length", "ipxwan.option_data_len", FT_UINT16,
366                  BASE_DEC, NULL, 0x0, NULL, HFILL }},
367
368             { &hf_ipxwan_routing_type,
369               { "Routing Type", "ipxwan.routing_type", FT_UINT8,
370                  BASE_DEC, VALS(ipxwan_routing_type_vals), 0x0, NULL, HFILL }},
371
372             { &hf_ipxwan_wan_link_delay,
373               { "WAN Link Delay", "ipxwan.rip_sap_info_exchange.wan_link_delay",
374                  FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
375
376             { &hf_ipxwan_common_network_number,
377               { "Common Network Number", "ipxwan.rip_sap_info_exchange.common_network_number",
378                  FT_IPXNET, BASE_NONE, NULL, 0x0, NULL, HFILL }},
379
380             { &hf_ipxwan_router_name,
381               { "Router Name", "ipxwan.rip_sap_info_exchange.router_name",
382                  FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
383
384             { &hf_ipxwan_delay,
385               { "Delay", "ipxwan.nlsp_information.delay",
386                  FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
387
388             { &hf_ipxwan_throughput,
389               { "Throughput", "ipxwan.nlsp_information.throughput",
390                  FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
391
392             { &hf_ipxwan_request_size,
393               { "Request Size", "ipxwan.nlsp_raw_throughput_data.request_size",
394                  FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
395
396             { &hf_ipxwan_delta_time,
397               { "Delta Time", "ipxwan.nlsp_raw_throughput_data.delta_time",
398                  FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
399
400             { &hf_ipxwan_extended_node_id,
401               { "Extended Node ID", "ipxwan.extended_node_id",
402                  FT_IPXNET, BASE_NONE, NULL, 0x0, NULL, HFILL }},
403
404             { &hf_ipxwan_node_number,
405               { "Node Number", "ipxwan.node_number",
406                  FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }},
407
408             { &hf_ipxwan_compression_type,
409               { "Compression Type", "ipxwan.compression.type",
410                  FT_UINT8, BASE_DEC, VALS(ipxwan_compression_type_vals), 0x0,
411                  NULL, HFILL }},
412
413             { &hf_ipxwan_compression_options,
414               { "Compression options", "ipxwan.compression.options",
415                  FT_UINT8, BASE_HEX, NULL, 0x0,
416                  NULL, HFILL }},
417
418             { &hf_ipxwan_compression_slots,
419               { "Number of compression slots", "ipxwan.compression.slots",
420                  FT_UINT8, BASE_DEC, NULL, 0x0,
421                  NULL, HFILL }},
422
423             { &hf_ipxwan_compression_parameters,
424               { "Option parameters", "ipxwan.compression.parameters",
425                  FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
426
427             { &hf_ipxwan_padding,
428               { "Padding", "ipxwan.padding",
429                  FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
430
431             { &hf_ipxwan_option_value,
432               { "Option value", "ipxwan.option_value",
433                  FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
434         };
435         static gint *ett[] = {
436                 &ett_ipxwan,
437                 &ett_ipxwan_option,
438         };
439         static ei_register_info ei[] = {
440                 { &ei_ipxwan_option_data_len, { "ipxwan.option_data_len.invalid", PI_MALFORMED, PI_ERROR, "Wrong length", EXPFILL }},
441         };
442
443         expert_module_t* expert_ipxwan;
444
445         proto_ipxwan = proto_register_protocol("IPX WAN", "IPX WAN", "ipxwan");
446         proto_register_field_array(proto_ipxwan, hf, array_length(hf));
447         proto_register_subtree_array(ett, array_length(ett));
448         expert_ipxwan = expert_register_protocol(proto_ipxwan);
449         expert_register_field_array(expert_ipxwan, ei, array_length(ei));
450 }
451
452 void
453 proto_reg_handoff_ipxwan(void)
454 {
455         dissector_handle_t ipxwan_handle;
456
457         ipxwan_handle = create_dissector_handle(dissect_ipxwan,
458             proto_ipxwan);
459         dissector_add_uint("ipx.socket", IPX_SOCKET_IPXWAN, ipxwan_handle);
460 }
461
462 /*
463  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
464  *
465  * Local variables:
466  * c-basic-offset: 8
467  * tab-width: 8
468  * indent-tabs-mode: t
469  * End:
470  *
471  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
472  * :indentSize=8:tabSize=8:noTabs=false:
473  */