HACK: 2nd try to match RowsetProperties
[wireshark-wip.git] / epan / dissectors / packet-ipxwan.c
blob15e12c991e5e68ac927ac6c675bbd56c5d3fe00a
1 /* packet-ipxwan.c
2 * Routines for NetWare IPX WAN Protocol
4 * $Id$
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include "config.h"
27 #include <glib.h>
28 #include <epan/packet.h>
29 #include <epan/expert.h>
30 #include "packet-ipx.h"
33 * See RFC 1362 for version 1 of this protocol; see the NetWare Link
34 * Services Protocol Specification, chapter 3, for version 2.
36 static int proto_ipxwan = -1;
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;
63 static gint ett_ipxwan = -1;
64 static gint ett_ipxwan_option = -1;
66 static expert_field ei_ipxwan_option_data_len = EI_INIT;
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 }
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
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 }
102 static const value_string ipxwan_accept_option_vals[] = {
103 { 0, "No" },
104 { 1, "Yes" },
105 { 3, "Not Applicable" },
106 { 0, NULL }
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 }
118 #define COMP_TYPE_TELEBIT 0
120 static const value_string ipxwan_compression_type_vals[] = {
121 { COMP_TYPE_TELEBIT, "Telebit" },
122 { 0, NULL }
125 static void
126 dissect_ipxwan(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
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;
142 col_set_str(pinfo->cinfo, COL_PROTOCOL, "IPX WAN");
143 col_clear(pinfo->cinfo, COL_INFO);
145 if (tree) {
146 ti = proto_tree_add_item(tree, proto_ipxwan, tvb, 0, -1,
147 ENC_NA);
148 ipxwan_tree = proto_item_add_subtree(ti, ett_ipxwan);
151 if (tree) {
152 proto_tree_add_item(ipxwan_tree, hf_ipxwan_identifier, tvb,
153 offset, 4, ENC_ASCII|ENC_NA);
155 offset += 4;
156 packet_type = tvb_get_guint8(tvb, offset);
157 col_add_str(pinfo->cinfo, COL_INFO,
158 val_to_str(packet_type, ipxwan_packet_type_vals,
159 "Unknown packet type %u"));
161 if (tree) {
162 proto_tree_add_uint(ipxwan_tree, hf_ipxwan_packet_type, tvb,
163 offset, 1, packet_type);
164 offset += 1;
165 proto_tree_add_item(ipxwan_tree, hf_ipxwan_node_id, tvb,
166 offset, 4, ENC_BIG_ENDIAN);
167 offset += 4;
168 proto_tree_add_item(ipxwan_tree, hf_ipxwan_sequence_number, tvb,
169 offset, 1, ENC_BIG_ENDIAN);
170 offset += 1;
171 num_options = tvb_get_guint8(tvb, offset);
172 proto_tree_add_uint(ipxwan_tree, hf_ipxwan_num_options, tvb,
173 offset, 1, num_options);
174 offset += 1;
176 while (num_options != 0) {
177 option_number = tvb_get_guint8(tvb, offset);
178 ti = proto_tree_add_text(ipxwan_tree, tvb, offset, -1,
179 "Option: %s",
180 val_to_str(option_number, ipxwan_option_num_vals,
181 "Unknown (%u)"));
182 option_tree = proto_item_add_subtree(ti,
183 ett_ipxwan_option);
185 proto_tree_add_uint(option_tree, hf_ipxwan_option_num,
186 tvb, offset, 1, option_number);
187 offset += 1;
188 proto_tree_add_item(option_tree, hf_ipxwan_accept_option,
189 tvb, offset, 1, ENC_BIG_ENDIAN);
190 offset += 1;
191 option_data_len = tvb_get_ntohs(tvb, offset);
192 proto_tree_add_uint(option_tree, hf_ipxwan_option_data_len,
193 tvb, offset, 2, option_data_len);
194 offset += 2;
195 proto_item_set_len(ti, option_data_len+4);
196 switch (option_number) {
198 case OPT_ROUTING_TYPE:
199 if (option_data_len != 1) {
200 expert_add_info_format(pinfo, ti, &ei_ipxwan_option_data_len,
201 "Bogus length: %u, should be 1", option_data_len);
202 } else {
203 proto_tree_add_item(option_tree,
204 hf_ipxwan_routing_type, tvb,
205 offset, 1, ENC_BIG_ENDIAN);
207 break;
209 case OPT_RIP_SAP_INFO_EXCHANGE:
210 if (option_data_len != 54) {
211 expert_add_info_format(pinfo, ti, &ei_ipxwan_option_data_len,
212 "Bogus length: %u, should be 54", option_data_len);
213 } else {
214 wan_link_delay = tvb_get_ntohs(tvb,
215 offset);
216 proto_tree_add_uint_format_value(option_tree,
217 hf_ipxwan_wan_link_delay, tvb,
218 offset, 2, wan_link_delay,
219 "%ums",
220 wan_link_delay);
221 proto_tree_add_item(option_tree,
222 hf_ipxwan_common_network_number,
223 tvb, offset+2, 4, ENC_NA);
224 proto_tree_add_item(option_tree,
225 hf_ipxwan_router_name, tvb,
226 offset+6, 48, ENC_ASCII|ENC_NA);
228 break;
230 case OPT_NLSP_INFORMATION:
231 if (option_data_len != 8) {
232 expert_add_info_format(pinfo, ti, &ei_ipxwan_option_data_len,
233 "Bogus length: %u, should be 8", option_data_len);
234 } else {
235 delay = tvb_get_ntohl(tvb, offset);
236 proto_tree_add_uint_format_value(option_tree,
237 hf_ipxwan_delay, tvb,
238 offset, 4, delay,
239 "%uus", delay);
240 throughput = tvb_get_ntohl(tvb, offset);
241 proto_tree_add_uint_format_value(option_tree,
242 hf_ipxwan_throughput, tvb,
243 offset, 4, throughput,
244 "%uus",
245 throughput);
247 break;
249 case OPT_NLSP_RAW_THROUGHPUT_DATA:
250 if (option_data_len != 8) {
251 expert_add_info_format(pinfo, ti, &ei_ipxwan_option_data_len,
252 "Bogus length: %u, should be 8", option_data_len);
253 } else {
254 proto_tree_add_item(option_tree,
255 hf_ipxwan_request_size, tvb,
256 offset, 4, ENC_BIG_ENDIAN);
257 delta_time = tvb_get_ntohl(tvb, offset);
258 proto_tree_add_uint_format_value(option_tree,
259 hf_ipxwan_delta_time, tvb,
260 offset, 4, delta_time,
261 "%uus",
262 delta_time);
264 break;
266 case OPT_EXTENDED_NODE_ID:
267 if (option_data_len != 4) {
268 expert_add_info_format(pinfo, ti, &ei_ipxwan_option_data_len,
269 "Bogus length: %u, should be 4", option_data_len);
270 } else {
271 proto_tree_add_item(option_tree,
272 hf_ipxwan_extended_node_id, tvb,
273 offset, 4, ENC_NA);
275 break;
277 case OPT_NODE_NUMBER:
278 if (option_data_len != 6) {
279 expert_add_info_format(pinfo, ti, &ei_ipxwan_option_data_len,
280 "Bogus length: %u, should be 6", option_data_len);
281 } else {
282 proto_tree_add_item(option_tree,
283 hf_ipxwan_node_number, tvb,
284 offset, 6, ENC_NA);
286 break;
288 case OPT_COMPRESSION:
289 if (option_data_len < 1) {
290 expert_add_info_format(pinfo, ti, &ei_ipxwan_option_data_len,
291 "Bogus length: %u, should be >= 1", option_data_len);
292 } else {
293 compression_type = tvb_get_guint8(tvb,
294 offset);
295 ti = proto_tree_add_uint(option_tree,
296 hf_ipxwan_compression_type, tvb,
297 offset, 1, compression_type);
298 switch (compression_type) {
300 case COMP_TYPE_TELEBIT:
301 if (option_data_len < 3) {
302 expert_add_info_format(pinfo, ti, &ei_ipxwan_option_data_len,
303 "Bogus length: %u, should be >= 3", option_data_len);
304 } else {
305 proto_tree_add_item(option_tree, hf_ipxwan_compression_options,
306 tvb, offset+1, 1, ENC_BIG_ENDIAN);
307 proto_tree_add_item(option_tree, hf_ipxwan_compression_slots,
308 tvb, offset+2, 1, ENC_BIG_ENDIAN);
310 break;
312 default:
313 proto_tree_add_item(option_tree, hf_ipxwan_compression_parameters,
314 tvb, offset+1, option_data_len-1, ENC_NA);
315 break;
318 break;
320 case OPT_PAD:
321 proto_tree_add_item(option_tree, hf_ipxwan_padding,
322 tvb, offset, option_data_len, ENC_NA);
323 break;
325 default:
326 proto_tree_add_item(option_tree, hf_ipxwan_option_value,
327 tvb, offset, option_data_len, ENC_NA);
328 break;
331 offset += option_data_len;
332 num_options--;
337 void
338 proto_register_ipxwan(void)
340 static hf_register_info hf[] = {
341 { &hf_ipxwan_identifier,
342 { "Identifier", "ipxwan.identifier",
343 FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
345 { &hf_ipxwan_packet_type,
346 { "Packet Type", "ipxwan.packet_type",
347 FT_UINT8, BASE_DEC, VALS(ipxwan_packet_type_vals), 0x0, NULL,
348 HFILL }},
350 { &hf_ipxwan_node_id,
351 { "Node ID", "ipxwan.node_id", FT_UINT32,
352 BASE_HEX, NULL, 0x0, NULL, HFILL }},
354 { &hf_ipxwan_sequence_number,
355 { "Sequence Number", "ipxwan.sequence_number", FT_UINT8,
356 BASE_DEC, NULL, 0x0, NULL, HFILL }},
358 { &hf_ipxwan_num_options,
359 { "Number of Options", "ipxwan.num_options", FT_UINT8,
360 BASE_DEC, NULL, 0x0, NULL, HFILL }},
362 { &hf_ipxwan_option_num,
363 { "Option Number", "ipxwan.option_num", FT_UINT8,
364 BASE_HEX, VALS(ipxwan_option_num_vals), 0x0, NULL, HFILL }},
366 { &hf_ipxwan_accept_option,
367 { "Accept Option", "ipxwan.accept_option", FT_UINT8,
368 BASE_DEC, VALS(ipxwan_accept_option_vals), 0x0, NULL, HFILL }},
370 { &hf_ipxwan_option_data_len,
371 { "Option Data Length", "ipxwan.option_data_len", FT_UINT16,
372 BASE_DEC, NULL, 0x0, NULL, HFILL }},
374 { &hf_ipxwan_routing_type,
375 { "Routing Type", "ipxwan.routing_type", FT_UINT8,
376 BASE_DEC, VALS(ipxwan_routing_type_vals), 0x0, NULL, HFILL }},
378 { &hf_ipxwan_wan_link_delay,
379 { "WAN Link Delay", "ipxwan.rip_sap_info_exchange.wan_link_delay",
380 FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
382 { &hf_ipxwan_common_network_number,
383 { "Common Network Number", "ipxwan.rip_sap_info_exchange.common_network_number",
384 FT_IPXNET, BASE_NONE, NULL, 0x0, NULL, HFILL }},
386 { &hf_ipxwan_router_name,
387 { "Router Name", "ipxwan.rip_sap_info_exchange.router_name",
388 FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
390 { &hf_ipxwan_delay,
391 { "Delay", "ipxwan.nlsp_information.delay",
392 FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
394 { &hf_ipxwan_throughput,
395 { "Throughput", "ipxwan.nlsp_information.throughput",
396 FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
398 { &hf_ipxwan_request_size,
399 { "Request Size", "ipxwan.nlsp_raw_throughput_data.request_size",
400 FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
402 { &hf_ipxwan_delta_time,
403 { "Delta Time", "ipxwan.nlsp_raw_throughput_data.delta_time",
404 FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
406 { &hf_ipxwan_extended_node_id,
407 { "Extended Node ID", "ipxwan.extended_node_id",
408 FT_IPXNET, BASE_NONE, NULL, 0x0, NULL, HFILL }},
410 { &hf_ipxwan_node_number,
411 { "Node Number", "ipxwan.node_number",
412 FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }},
414 { &hf_ipxwan_compression_type,
415 { "Compression Type", "ipxwan.compression.type",
416 FT_UINT8, BASE_DEC, VALS(ipxwan_compression_type_vals), 0x0,
417 NULL, HFILL }},
419 { &hf_ipxwan_compression_options,
420 { "Compression options", "ipxwan.compression.options",
421 FT_UINT8, BASE_HEX, NULL, 0x0,
422 NULL, HFILL }},
424 { &hf_ipxwan_compression_slots,
425 { "Number of compression slots", "ipxwan.compression.slots",
426 FT_UINT8, BASE_DEC, NULL, 0x0,
427 NULL, HFILL }},
429 { &hf_ipxwan_compression_parameters,
430 { "Option parameters", "ipxwan.compression.parameters",
431 FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
433 { &hf_ipxwan_padding,
434 { "Padding", "ipxwan.padding",
435 FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
437 { &hf_ipxwan_option_value,
438 { "Option value", "ipxwan.option_value",
439 FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
441 static gint *ett[] = {
442 &ett_ipxwan,
443 &ett_ipxwan_option,
445 static ei_register_info ei[] = {
446 { &ei_ipxwan_option_data_len, { "ipxwan.option_data_len.invalid", PI_MALFORMED, PI_ERROR, "Wrong length", EXPFILL }},
449 expert_module_t* expert_ipxwan;
451 proto_ipxwan = proto_register_protocol("IPX WAN", "IPX WAN", "ipxwan");
452 proto_register_field_array(proto_ipxwan, hf, array_length(hf));
453 proto_register_subtree_array(ett, array_length(ett));
454 expert_ipxwan = expert_register_protocol(proto_ipxwan);
455 expert_register_field_array(expert_ipxwan, ei, array_length(ei));
458 void
459 proto_reg_handoff_ipxwan(void)
461 dissector_handle_t ipxwan_handle;
463 ipxwan_handle = create_dissector_handle(dissect_ipxwan,
464 proto_ipxwan);
465 dissector_add_uint("ipx.socket", IPX_SOCKET_IPXWAN, ipxwan_handle);