Frame numbers are unsigned.
[obnox/wireshark/wip.git] / packet-vines.c
1 /* packet-vines.c
2  * Routines for Banyan VINES protocol packet disassembly
3  *
4  * $Id: packet-vines.c,v 1.58 2003/04/22 08:50:07 guy Exp $
5  *
6  * Don Lafontaine <lafont02@cn.ca>
7  *
8  * Ethereal - Network traffic analyzer
9  * By Gerald Combs <gerald@ethereal.com>
10  * Copyright 1998 Gerald Combs
11  * Joerg Mayer <jmayer@loplof.de>
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #include <string.h>
33 #include <glib.h>
34 #include <epan/packet.h>
35 #include "packet-vines.h"
36 #include "etypes.h"
37 #include "ppptypes.h"
38 #include "ipproto.h"
39 #include "arcnet_pids.h"
40 #include "llcsaps.h"
41
42 #define UDP_PORT_VINES  573
43
44 static int proto_vines_frp = -1;
45
46 static gint ett_vines_frp = -1;
47
48 static int proto_vines_llc = -1;
49
50 static gint ett_vines_llc = -1;
51
52 static int proto_vines_ip = -1;
53 static int hf_vines_ip_protocol = -1;
54
55 static gint ett_vines_ip = -1;
56 static gint ett_vines_ip_tctl = -1;
57
58 static int proto_vines_echo = -1;
59
60 static gint ett_vines_echo = -1;
61
62 static int proto_vines_ipc = -1;
63
64 static gint ett_vines_ipc = -1;
65 static gint ett_vines_ipc_control = -1;
66
67 static int proto_vines_spp = -1;
68
69 static gint ett_vines_spp = -1;
70 static gint ett_vines_spp_control = -1;
71
72 static int proto_vines_arp = -1;
73
74 static gint ett_vines_arp = -1;
75
76 static int proto_vines_rtp = -1;
77
78 static gint ett_vines_rtp = -1;
79 static gint ett_vines_rtp_compatibility_flags = -1;
80 static gint ett_vines_rtp_req_info = -1;
81 static gint ett_vines_rtp_control_flags = -1;
82 static gint ett_vines_rtp_mtype = -1;
83 static gint ett_vines_rtp_flags = -1;
84
85 static int proto_vines_icp = -1;
86
87 static gint ett_vines_icp = -1;
88
89 void
90 capture_vines(packet_counts *ld)
91 {
92         ld->vines++;
93 }
94
95 static dissector_handle_t vines_ip_handle;
96 static dissector_handle_t data_handle;
97
98 /* AFAIK Vines FRP (Fragmentation Protocol) is used on all media except
99  * Ethernet and TR (and probably FDDI) - Fragmentation on these media types
100  * is not possible
101  * FIXME: Do we need to use this header with PPP too?
102  */
103 static void
104 dissect_vines_frp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
105 {
106         guint8   vines_frp_ctrl;
107         proto_tree *vines_frp_tree;
108         proto_item *ti;
109         gchar   frp_flags_str[32];
110         tvbuff_t *next_tvb;
111
112         if (check_col(pinfo->cinfo, COL_PROTOCOL))
113                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Vines FRP");
114         if (check_col(pinfo->cinfo, COL_INFO))
115                 col_clear(pinfo->cinfo, COL_INFO);
116
117         if (tree) {
118                 ti = proto_tree_add_item(tree, proto_vines_frp, tvb, 0, 2,
119                     FALSE);
120                 vines_frp_tree = proto_item_add_subtree(ti, ett_vines_frp);
121
122                 vines_frp_ctrl = tvb_get_guint8(tvb, 0);
123
124                 /*
125                  * 1: first fragment of vines packet
126                  * 2: last fragment of vines packet
127                  * 4 ... 80: unused
128                  */
129                 switch (vines_frp_ctrl) {
130
131                 case 0:
132                         strcpy(frp_flags_str, "middle");
133                         break;
134
135                 case 1:
136                         strcpy(frp_flags_str, "first");
137                         break;
138
139                 case 2:
140                         strcpy(frp_flags_str, "last");
141                         break;
142
143                 case 3:
144                         strcpy(frp_flags_str, "only");
145                         break;
146
147                 default:
148                         strcpy(frp_flags_str, "please report: unknown");
149                         break;
150                 }
151
152                 proto_tree_add_text(vines_frp_tree, tvb, 0, 1,
153                                     "Control Flags: 0x%02x = %s fragment",
154                                     vines_frp_ctrl, frp_flags_str);
155
156                 proto_tree_add_text(vines_frp_tree, tvb, 1, 1,
157                                     "Sequence Number: 0x%02x",
158                                     tvb_get_guint8(tvb, 1));
159         }
160
161         /* Decode the "real" Vines now */
162         next_tvb = tvb_new_subset(tvb, 2, -1, -1);
163         call_dissector(vines_ip_handle, next_tvb, pinfo, tree);
164 }
165
166 void
167 proto_register_vines_frp(void)
168 {
169         static gint *ett[] = {
170                 &ett_vines_frp,
171         };
172
173         proto_vines_frp = proto_register_protocol(
174             "Banyan Vines Fragmentation Protocol", "Vines FRP", "vines_frp");
175         proto_register_subtree_array(ett, array_length(ett));
176 }
177
178 void
179 proto_reg_handoff_vines_frp(void)
180 {
181         dissector_handle_t vines_frp_handle;
182
183         vines_frp_handle = create_dissector_handle(dissect_vines_frp,
184             proto_vines_frp);
185         dissector_add("ip.proto", IP_PROTO_VINES, vines_frp_handle);
186
187         /* XXX: AFAIK, src and dst port must be the same; should
188            the dissector check for that? */
189         dissector_add("udp.port", UDP_PORT_VINES, vines_frp_handle);
190 }
191
192 static dissector_table_t vines_llc_dissector_table;
193
194 #define VINES_LLC_IP    0xba
195 #define VINES_LLC_ECHO  0xbb
196
197 static const value_string vines_llc_ptype_vals[] = {
198         { VINES_LLC_IP,   "Vines IP" },
199         { VINES_LLC_ECHO, "Vines Echo" },
200         { 0,              NULL }
201 };
202
203 static void
204 dissect_vines_llc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
205 {
206         guint8   ptype;
207         proto_tree *vines_llc_tree;
208         proto_item *ti;
209         tvbuff_t *next_tvb;
210
211         if (check_col(pinfo->cinfo, COL_PROTOCOL))
212                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Vines LLC");
213         if (check_col(pinfo->cinfo, COL_INFO))
214                 col_clear(pinfo->cinfo, COL_INFO);
215
216         ptype = tvb_get_guint8(tvb, 0);
217         if (check_col(pinfo->cinfo, COL_INFO))
218                 col_add_str(pinfo->cinfo, COL_INFO,
219                     val_to_str(ptype, vines_llc_ptype_vals,
220                       "Unknown protocol 0x%02x"));
221         if (tree) {
222                 ti = proto_tree_add_item(tree, proto_vines_llc, tvb, 0, 1,
223                     FALSE);
224                 vines_llc_tree = proto_item_add_subtree(ti, ett_vines_llc);
225
226                 proto_tree_add_text(vines_llc_tree, tvb, 0, 1,
227                                     "Packet Type: %s (0x%02x)",
228                                     val_to_str(ptype, vines_llc_ptype_vals,
229                                         "Unknown"),
230                                     ptype);
231         }
232
233         next_tvb = tvb_new_subset(tvb, 1, -1, -1);
234         if (!dissector_try_port(vines_llc_dissector_table, ptype,
235             next_tvb, pinfo, tree))
236                 call_dissector(data_handle, next_tvb, pinfo, tree);
237 }
238
239 void
240 proto_register_vines_llc(void)
241 {
242         static gint *ett[] = {
243                 &ett_vines_llc,
244         };
245
246         proto_vines_llc = proto_register_protocol(
247             "Banyan Vines LLC", "Vines LLC", "vines_llc");
248         proto_register_subtree_array(ett, array_length(ett));
249
250         /* subdissector code */
251         vines_llc_dissector_table = register_dissector_table("vines_llc.ptype",
252             "Vines LLC protocol", FT_UINT8, BASE_HEX);
253 }
254
255 void
256 proto_reg_handoff_vines_llc(void)
257 {
258         dissector_handle_t vines_llc_handle;
259
260         vines_llc_handle = create_dissector_handle(dissect_vines_llc,
261             proto_vines_llc);
262         dissector_add("llc.dsap", SAP_VINES2, vines_llc_handle);
263 }
264
265 static dissector_table_t vines_ip_dissector_table;
266
267 static const value_string class_vals[] = {
268         { 0x00, "Reachable regardless of cost" },
269         { 0x10, "Reachable without cost" },
270         { 0x20, "Reachable with low cost (>= 4800 bps)" },
271         { 0x30, "Reachable via LAN" },
272         { 0,    NULL }
273 };
274
275 static const value_string proto_vals[] = {
276         { VIP_PROTO_IPC, "IPC" },
277         { VIP_PROTO_SPP, "SPP" },
278         { VIP_PROTO_ARP, "ARP" },
279         { VIP_PROTO_RTP, "RTP" },
280         { VIP_PROTO_ICP, "ICP" },
281         { 0,             NULL }
282 };
283
284 static const guint8 bcast_addr[VINES_ADDR_LEN] = {
285         0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
286 };
287
288 static void
289 dissect_vines_ip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
290 {
291         int         offset = 0;
292         e_vip       viph;
293         proto_tree *vip_tree, *tctl_tree;
294         proto_item *ti;
295         const guint8     *dst_addr, *src_addr;
296         gboolean is_broadcast = FALSE;
297         int  hops = 0;
298         tvbuff_t *next_tvb;
299
300         if (check_col(pinfo->cinfo, COL_PROTOCOL))
301                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Vines IP");
302         if (check_col(pinfo->cinfo, COL_INFO))
303                 col_clear(pinfo->cinfo, COL_INFO);
304
305         /* To do: check for runts, errs, etc. */
306
307         /* Avoids alignment problems on many architectures. */
308         tvb_memcpy(tvb, (guint8 *)&viph, offset, sizeof(e_vip));
309
310         viph.vip_chksum = g_ntohs(viph.vip_chksum);
311         viph.vip_pktlen = g_ntohs(viph.vip_pktlen);
312
313         if (check_col(pinfo->cinfo, COL_INFO)) {
314                 col_add_fstr(pinfo->cinfo, COL_INFO, "%s (0x%02x)",
315                     val_to_str(viph.vip_proto, proto_vals,
316                         "Unknown VIP protocol"),
317                     viph.vip_proto);
318         }
319
320         src_addr = tvb_get_ptr(tvb, offset+12, VINES_ADDR_LEN);
321         SET_ADDRESS(&pinfo->net_src, AT_VINES, VINES_ADDR_LEN, src_addr);
322         SET_ADDRESS(&pinfo->src, AT_VINES, VINES_ADDR_LEN, src_addr);
323         dst_addr = tvb_get_ptr(tvb, offset+6, VINES_ADDR_LEN);
324         SET_ADDRESS(&pinfo->net_dst, AT_VINES, VINES_ADDR_LEN,dst_addr);
325         SET_ADDRESS(&pinfo->dst, AT_VINES, VINES_ADDR_LEN, dst_addr);
326
327         /* helpers to transport control */
328         if (memcmp(viph.vip_dst, bcast_addr, VINES_ADDR_LEN) == 0)
329                 is_broadcast = TRUE;
330         hops = viph.vip_tctl & 0xf;
331
332         /*
333          * Adjust the length of this tvbuff to include only the Vines IP
334          * datagram.
335          */
336         set_actual_length(tvb, viph.vip_pktlen);
337
338         if (tree) {
339                 ti = proto_tree_add_item(tree, proto_vines_ip, tvb,
340                                          offset, viph.vip_pktlen,
341                                          FALSE);
342                 vip_tree = proto_item_add_subtree(ti, ett_vines_ip);
343                 proto_tree_add_text(vip_tree, tvb, offset,      2,
344                                     "Packet checksum: 0x%04x",
345                                     viph.vip_chksum);
346                 proto_tree_add_text(vip_tree, tvb, offset +  2, 2,
347                                     "Packet length: %u",
348                                     viph.vip_pktlen);
349                 ti = proto_tree_add_text(vip_tree, tvb, offset +  4, 1,
350                                     "Transport control: 0x%02x",
351                                     viph.vip_tctl);
352                 tctl_tree = proto_item_add_subtree(ti, ett_vines_ip_tctl);
353                 /*
354                  * XXX - bit 0x80 is "Normal" if 0; what is it if 1?
355                  */
356                 if (is_broadcast) {
357                         proto_tree_add_text(tctl_tree, tvb, offset + 4, 1,
358                             decode_boolean_bitfield(viph.vip_tctl, 0x40, 1*8,
359                               "Router nodes",
360                               "All nodes"));
361                         proto_tree_add_text(tctl_tree, tvb, offset + 4, 1, "%s",
362                             decode_enumerated_bitfield(viph.vip_tctl, 0x30, 1*8,
363                                       class_vals, "%s"));
364                 } else {
365                         proto_tree_add_text(tctl_tree, tvb, offset + 4, 1,
366                             decode_boolean_bitfield(viph.vip_tctl, 0x40, 1*8,
367                               "Forwarding router can handle redirect packets",
368                               "Forwarding router cannot handle redirect packets"));
369                         proto_tree_add_text(tctl_tree, tvb, offset + 4, 1,
370                             decode_boolean_bitfield(viph.vip_tctl, 0x20, 1*8,
371                               "Return metric notification packet",
372                               "Do not return metric notification packet"));
373                         proto_tree_add_text(tctl_tree, tvb, offset + 4, 1,
374                             decode_boolean_bitfield(viph.vip_tctl, 0x10, 1*8,
375                               "Return exception notification packet",
376                               "Do not return exception notification packet"));
377                 }
378                 proto_tree_add_text(tctl_tree, tvb, offset + 4, 1,
379                     decode_numeric_bitfield(viph.vip_tctl, 0x0F, 1*8,
380                         "Hop count remaining = %u"));
381                 proto_tree_add_uint(vip_tree, hf_vines_ip_protocol, tvb,
382                                     offset +  5, 1,
383                                     viph.vip_proto);
384                 proto_tree_add_text(vip_tree, tvb, offset +  6,
385                                     VINES_ADDR_LEN,
386                                     "Destination: %s",
387                                     vines_addr_to_str(dst_addr));
388                 proto_tree_add_text(vip_tree, tvb, offset +  12,
389                                     VINES_ADDR_LEN,
390                                     "Source: %s",
391                                     vines_addr_to_str(src_addr));
392         }
393
394         offset += 18;
395         next_tvb = tvb_new_subset(tvb, offset, -1, -1);
396         if (!dissector_try_port(vines_ip_dissector_table, viph.vip_proto,
397             next_tvb, pinfo, tree))
398                 call_dissector(data_handle, next_tvb, pinfo, tree);
399 }
400
401 void
402 proto_register_vines_ip(void)
403 {
404         static gint *ett[] = {
405                 &ett_vines_ip,
406                 &ett_vines_ip_tctl,
407         };
408
409         static hf_register_info hf[] = {
410           { &hf_vines_ip_protocol,
411             { "Protocol",                       "vines_ip.protocol",
412               FT_UINT8,         BASE_HEX,       VALS(proto_vals),       0x0,
413               "Vines protocol", HFILL }}
414         };
415
416         proto_vines_ip = proto_register_protocol("Banyan Vines IP", "Vines IP",
417             "vines_ip");
418         proto_register_field_array(proto_vines_ip, hf, array_length(hf));
419         proto_register_subtree_array(ett, array_length(ett));
420
421         /* subdissector code */
422         vines_ip_dissector_table = register_dissector_table("vines_ip.protocol",
423             "Vines protocol", FT_UINT8, BASE_HEX);
424
425         vines_ip_handle = create_dissector_handle(dissect_vines_ip,
426             proto_vines_ip);
427 }
428
429 void
430 proto_reg_handoff_vines_ip(void)
431 {
432         dissector_add("ethertype", ETHERTYPE_VINES_IP, vines_ip_handle);
433         dissector_add("ppp.protocol", PPP_VINES, vines_ip_handle);
434         dissector_add("arcnet.protocol_id", ARCNET_PROTO_BANYAN,
435             vines_ip_handle);
436         dissector_add("vines_llc.ptype", VINES_LLC_IP, vines_ip_handle);
437         data_handle = find_dissector("data");
438 }
439
440 static void
441 dissect_vines_echo(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
442 {
443         proto_tree *vines_echo_tree = NULL;
444         proto_item *ti;
445
446         if (check_col(pinfo->cinfo, COL_PROTOCOL))
447                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Vines Echo");
448         if (check_col(pinfo->cinfo, COL_INFO))
449                 col_clear(pinfo->cinfo, COL_INFO);
450
451         if (tree) {
452                 ti = proto_tree_add_item(tree, proto_vines_echo, tvb, 0, -1,
453                     FALSE);
454                 vines_echo_tree = proto_item_add_subtree(ti, ett_vines_echo);
455                 proto_tree_add_text(vines_echo_tree, tvb, 0, -1, "Data");
456         }
457 }
458
459 void
460 proto_register_vines_echo(void)
461 {
462         static gint *ett[] = {
463                 &ett_vines_echo,
464         };
465
466         proto_vines_icp = proto_register_protocol(
467             "Banyan Vines Echo", "Vines Echo", "vines_echo");
468         proto_register_subtree_array(ett, array_length(ett));
469 }
470
471 void
472 proto_reg_handoff_vines_echo(void)
473 {
474         dissector_handle_t vines_echo_handle;
475
476         vines_echo_handle = create_dissector_handle(dissect_vines_echo,
477             proto_vines_echo);
478         dissector_add("vines_llc.ptype", VINES_LLC_ECHO, vines_echo_handle);
479         dissector_add("ethertype", ETHERTYPE_VINES_ECHO, vines_echo_handle);
480 }
481
482 static const value_string pkttype_vals[] = {
483         { PKTTYPE_DGRAM, "Datagram" },
484         { PKTTYPE_DATA,  "Data" },
485         { PKTTYPE_ERR,   "Error" },
486         { PKTTYPE_DISC,  "Disconnect" },
487         { PKTTYPE_PROBE, "Probe" },
488         { PKTTYPE_ACK,   "Ack" },
489         { 0,             NULL }
490 };
491
492 static heur_dissector_list_t vines_ipc_heur_subdissector_list;
493
494 static const value_string vipc_err_vals[] = {
495         { 151, "Bad socket descriptor" },
496         { 152, "Address already in use" },
497         { 153, "Invalid operation" },
498         { 154, "User address parameter fault" },
499         { 155, "Net/host unreachable" },
500         { 156, "Message overflow error" },
501         { 157, "Destination socket does not exist" },
502         { 158, "Address family does not exist" },
503         { 159, "Socket type does not exist" },
504         { 160, "Protocol does not exist" },
505         { 161, "No more sockets available" },
506         { 162, "No buffer space available" },
507         { 163, "Timeout event" },
508         { 164, "Operation not supported" },
509         { 165, "Resource not available" },
510         { 166, "Internal communication service failure" },
511         { 167, "Controller reset failure" },
512         { 0,   NULL }
513 };
514
515 static void
516 dissect_vines_ipc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
517 {
518         int          offset = 0;
519         e_vipc       viph;
520         proto_tree *vipc_tree = NULL, *control_tree;
521         proto_item *ti;
522         tvbuff_t *next_tvb;
523
524         if (check_col(pinfo->cinfo, COL_PROTOCOL))
525                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "VIPC");
526         if (check_col(pinfo->cinfo, COL_INFO))
527                 col_clear(pinfo->cinfo, COL_INFO);
528
529         /* To do: check for runts, errs, etc. */
530
531         /* Avoids alignment problems on many architectures. */
532         tvb_memcpy(tvb, (guint8 *)&viph, offset, sizeof(e_vipc));
533
534         viph.vipc_sport = g_ntohs(viph.vipc_sport);
535         viph.vipc_dport = g_ntohs(viph.vipc_dport);
536         viph.vipc_lclid = g_ntohs(viph.vipc_lclid);
537         viph.vipc_rmtid = g_ntohs(viph.vipc_rmtid);
538         viph.vipc_seqno = g_ntohs(viph.vipc_seqno);
539         viph.vipc_ack = g_ntohs(viph.vipc_ack);
540         viph.vipc_err_len = g_ntohs(viph.vipc_err_len);
541
542         if (check_col(pinfo->cinfo, COL_PROTOCOL))
543                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Vines IPC");
544         if (check_col(pinfo->cinfo, COL_INFO)) {
545                 switch (viph.vipc_pkttype) {
546
547                 case PKTTYPE_DGRAM:
548                         col_add_fstr(pinfo->cinfo, COL_INFO,
549                                      "%s D=%04x S=%04x",
550                                      val_to_str(viph.vipc_pkttype, pkttype_vals,
551                                          "Unknown packet type (0x%02x)"),
552                                      viph.vipc_dport, viph.vipc_sport);
553                         break;
554
555                 case PKTTYPE_ERR:
556                         col_add_fstr(pinfo->cinfo, COL_INFO,
557                                      "%s NS=%u NR=%u Err=%s RID=%04x LID=%04x D=%04x S=%04x",
558                                      val_to_str(viph.vipc_pkttype, pkttype_vals,
559                                          "Unknown packet type (0x%02x)"),
560                                      viph.vipc_seqno, viph.vipc_ack,
561                                      val_to_str(viph.vipc_err_len,
562                                          vipc_err_vals, "Unknown (%u)"),
563                                      viph.vipc_rmtid, viph.vipc_lclid,
564                                      viph.vipc_dport, viph.vipc_sport);
565                         break;
566
567                 default:
568                         col_add_fstr(pinfo->cinfo, COL_INFO,
569                                      "%s NS=%u NR=%u Len=%u RID=%04x LID=%04x D=%04x S=%04x",
570                                      val_to_str(viph.vipc_pkttype, pkttype_vals,
571                                          "Unknown packet type (0x%02x)"),
572                                      viph.vipc_seqno, viph.vipc_ack,
573                                      viph.vipc_err_len, viph.vipc_rmtid,
574                                      viph.vipc_lclid, viph.vipc_dport,
575                                      viph.vipc_sport);
576                         break;
577                 }
578         }
579
580         if (tree) {
581                 ti = proto_tree_add_item(tree, proto_vines_ipc, tvb, offset,
582                     sizeof(viph), FALSE);
583                 vipc_tree = proto_item_add_subtree(ti, ett_vines_ipc);
584                 proto_tree_add_text(vipc_tree, tvb, offset,      2,
585                                     "Source port: 0x%04x", viph.vipc_sport);
586         }
587         offset += 2;
588         if (tree) {
589                 proto_tree_add_text(vipc_tree, tvb, offset,  2,
590                                     "Destination port: 0x%04x",
591                                     viph.vipc_dport);
592         }
593         offset += 2;
594         if (tree) {
595                 proto_tree_add_text(vipc_tree, tvb, offset,  1,
596                                     "Packet type: 0x%02x (%s)",
597                                     viph.vipc_pkttype,
598                                     val_to_str(viph.vipc_pkttype, pkttype_vals,
599                                         "Unknown"));
600         }
601         offset += 1;
602         if (viph.vipc_pkttype != PKTTYPE_DGRAM) {
603                 if (tree) {
604                         ti = proto_tree_add_text(vipc_tree, tvb, offset,  1,
605                                             "Control: 0x%02x",
606                                             viph.vipc_control);
607                         control_tree = proto_item_add_subtree(ti,
608                             ett_vines_ipc_control);
609                         /*
610                          * XXX - do reassembly based on BOM/EOM bits.
611                          */
612                         proto_tree_add_text(control_tree, tvb, offset, 1,
613                             decode_boolean_bitfield(viph.vipc_control, 0x80,
614                               1*8,
615                               "Send immediate acknowledgment",
616                               "Do not send immediate acknowledgement"));
617                         proto_tree_add_text(control_tree, tvb, offset, 1,
618                             decode_boolean_bitfield(viph.vipc_control, 0x40,
619                               1*8,
620                               "End of message",
621                               "Not end of message"));
622                         proto_tree_add_text(control_tree, tvb, offset, 1,
623                             decode_boolean_bitfield(viph.vipc_control, 0x20,
624                               1*8,
625                               "Beginning of message",
626                               "Not beginning of message"));
627                         proto_tree_add_text(control_tree, tvb, offset, 1,
628                             decode_boolean_bitfield(viph.vipc_control, 0x10,
629                               1*8,
630                               "Abort current message",
631                               "Do not abort current message"));
632                 }
633         }
634         offset += 1;
635         if (viph.vipc_pkttype != PKTTYPE_DGRAM) {
636                 if (tree) {
637                         proto_tree_add_text(vipc_tree, tvb, offset,  2,
638                                             "Local Connection ID: 0x%04x",
639                                             viph.vipc_lclid);
640                 }
641                 offset += 2;
642                 if (tree) {
643                         proto_tree_add_text(vipc_tree, tvb, offset,  2,
644                                             "Remote Connection ID: 0x%04x",
645                                             viph.vipc_rmtid);
646                 }
647                 offset += 2;
648                 if (tree) {
649                         proto_tree_add_text(vipc_tree, tvb, offset, 2,
650                                             "Sequence number: %u",
651                                             viph.vipc_seqno);
652                 }
653                 offset += 2;
654                 if (tree) {
655                         proto_tree_add_text(vipc_tree, tvb, offset, 2,
656                                             "Ack number: %u", viph.vipc_ack);
657                 }
658                 offset += 2;
659                 if (tree) {
660                         if (viph.vipc_pkttype == PKTTYPE_ERR) {
661                                 proto_tree_add_text(vipc_tree, tvb, offset, 2,
662                                                     "Error: %s (%u)",
663                                                     val_to_str(viph.vipc_err_len,
664                                                         vipc_err_vals,
665                                                         "Unknown"),
666                                                     viph.vipc_err_len);
667                         } else {
668                                 proto_tree_add_text(vipc_tree, tvb, offset, 2,
669                                                     "Length: %u",
670                                                     viph.vipc_err_len);
671                         }
672                 }
673                 offset += 2;
674         }
675
676         /*
677          * For data packets, try the heuristic dissectors for Vines SPP;
678          * if none of them accept the packet, or if it's not a data packet,
679          * dissect it as data.
680          */
681         next_tvb = tvb_new_subset(tvb, offset, -1, -1);
682         if (viph.vipc_pkttype != PKTTYPE_DATA ||
683             !dissector_try_heuristic(vines_ipc_heur_subdissector_list,
684               next_tvb, pinfo, tree))
685                 call_dissector(data_handle, next_tvb, pinfo, tree);
686 }
687
688 void
689 proto_register_vines_ipc(void)
690 {
691         static gint *ett[] = {
692                 &ett_vines_ipc,
693                 &ett_vines_ipc_control,
694         };
695
696         proto_vines_ipc = proto_register_protocol("Banyan Vines IPC",
697             "Vines IPC", "vines_ipc");
698         proto_register_subtree_array(ett, array_length(ett));
699
700         register_heur_dissector_list("vines_ipc",
701             &vines_ipc_heur_subdissector_list);
702 }
703
704 void
705 proto_reg_handoff_vines_ipc(void)
706 {
707         dissector_handle_t vines_ipc_handle;
708
709         vines_ipc_handle = create_dissector_handle(dissect_vines_ipc,
710             proto_vines_ipc);
711         dissector_add("vines_ip.protocol", VIP_PROTO_IPC, vines_ipc_handle);
712 }
713
714 static heur_dissector_list_t vines_spp_heur_subdissector_list;
715
716 static void
717 dissect_vines_spp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
718 {
719         int          offset = 0;
720         e_vspp       viph;
721         proto_tree  *vspp_tree, *control_tree;
722         proto_item  *ti;
723         tvbuff_t    *next_tvb;
724
725         if (check_col(pinfo->cinfo, COL_PROTOCOL))
726                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "VSPP");
727         if (check_col(pinfo->cinfo, COL_INFO))
728                 col_clear(pinfo->cinfo, COL_INFO);
729
730         /* To do: check for runts, errs, etc. */
731
732         /* Avoids alignment problems on many architectures. */
733         tvb_memcpy(tvb, (guint8 *)&viph, offset, sizeof(e_vspp));
734
735         viph.vspp_sport = g_ntohs(viph.vspp_sport);
736         viph.vspp_dport = g_ntohs(viph.vspp_dport);
737         viph.vspp_lclid = g_ntohs(viph.vspp_lclid);
738         viph.vspp_rmtid = g_ntohs(viph.vspp_rmtid);
739         viph.vspp_seqno = g_ntohs(viph.vspp_seqno);
740         viph.vspp_ack = g_ntohs(viph.vspp_ack);
741         viph.vspp_win = g_ntohs(viph.vspp_win);
742
743         if (check_col(pinfo->cinfo, COL_PROTOCOL))
744                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Vines SPP");
745         if (check_col(pinfo->cinfo, COL_INFO))
746                 col_add_fstr(pinfo->cinfo, COL_INFO,
747                              "%s NS=%u NR=%u Window=%u RID=%04x LID=%04x D=%04x S=%04x",
748                              val_to_str(viph.vspp_pkttype, pkttype_vals,
749                                  "Unknown packet type (0x%02x)"),
750                              viph.vspp_seqno, viph.vspp_ack, viph.vspp_win,
751                              viph.vspp_rmtid, viph.vspp_lclid, viph.vspp_dport,
752                              viph.vspp_sport);
753
754         if (tree) {
755                 ti = proto_tree_add_item(tree, proto_vines_spp, tvb, offset,
756                     sizeof(viph), FALSE);
757                 vspp_tree = proto_item_add_subtree(ti, ett_vines_spp);
758                 proto_tree_add_text(vspp_tree, tvb, offset,      2,
759                                     "Source port: 0x%04x", viph.vspp_sport);
760                 proto_tree_add_text(vspp_tree, tvb, offset + 2,  2,
761                                     "Destination port: 0x%04x",
762                                     viph.vspp_dport);
763                 proto_tree_add_text(vspp_tree, tvb, offset + 4,  1,
764                                     "Packet type: 0x%02x (%s)",
765                                     viph.vspp_pkttype,
766                                     val_to_str(viph.vspp_pkttype, pkttype_vals,
767                                         "Unknown"));
768                 ti = proto_tree_add_text(vspp_tree, tvb, offset + 5,  1,
769                                     "Control: 0x%02x", viph.vspp_control);
770                 control_tree = proto_item_add_subtree(ti, ett_vines_spp_control);
771                 /*
772                  * XXX - do reassembly based on BOM/EOM bits.
773                  */
774                 proto_tree_add_text(control_tree, tvb, offset + 5, 1,
775                     decode_boolean_bitfield(viph.vspp_control, 0x80, 1*8,
776                       "Send immediate acknowledgment",
777                       "Do not send immediate acknowledgement"));
778                 proto_tree_add_text(control_tree, tvb, offset + 5, 1,
779                     decode_boolean_bitfield(viph.vspp_control, 0x40, 1*8,
780                       "End of message",
781                       "Not end of message"));
782                 proto_tree_add_text(control_tree, tvb, offset + 5, 1,
783                     decode_boolean_bitfield(viph.vspp_control, 0x20, 1*8,
784                       "Beginning of message",
785                       "Not beginning of message"));
786                 proto_tree_add_text(control_tree, tvb, offset + 5, 1,
787                     decode_boolean_bitfield(viph.vspp_control, 0x10, 1*8,
788                       "Abort current message",
789                       "Do not abort current message"));
790                 proto_tree_add_text(vspp_tree, tvb, offset + 6,  2,
791                                     "Local Connection ID: 0x%04x",
792                                     viph.vspp_lclid);
793                 proto_tree_add_text(vspp_tree, tvb, offset + 8,  2,
794                                     "Remote Connection ID: 0x%04x",
795                                     viph.vspp_rmtid);
796                 proto_tree_add_text(vspp_tree, tvb, offset + 10, 2,
797                                     "Sequence number: %u",
798                                     viph.vspp_seqno);
799                 proto_tree_add_text(vspp_tree, tvb, offset + 12, 2,
800                                     "Ack number: %u", viph.vspp_ack);
801                 proto_tree_add_text(vspp_tree, tvb, offset + 14, 2,
802                                     "Window: %u", viph.vspp_win);
803         }
804         offset += 16; /* sizeof SPP */
805
806         /*
807          * For data packets, try the heuristic dissectors for Vines SPP;
808          * if none of them accept the packet, or if it's not a data packet,
809          * dissect it as data.
810          */
811         next_tvb = tvb_new_subset(tvb, offset, -1, -1);
812         if (viph.vspp_pkttype != PKTTYPE_DATA ||
813             !dissector_try_heuristic(vines_spp_heur_subdissector_list,
814               next_tvb, pinfo, tree))
815                 call_dissector(data_handle, next_tvb, pinfo, tree);
816 }
817
818 void
819 proto_register_vines_spp(void)
820 {
821         static gint *ett[] = {
822                 &ett_vines_spp,
823                 &ett_vines_spp_control,
824         };
825
826         proto_vines_spp = proto_register_protocol("Banyan Vines SPP",
827             "Vines SPP", "vines_spp");
828         proto_register_subtree_array(ett, array_length(ett));
829
830         register_heur_dissector_list("vines_spp",
831             &vines_spp_heur_subdissector_list);
832 }
833
834 void
835 proto_reg_handoff_vines_spp(void)
836 {
837         dissector_handle_t vines_spp_handle;
838
839         vines_spp_handle = create_dissector_handle(dissect_vines_spp,
840             proto_vines_spp);
841         dissector_add("vines_ip.protocol", VIP_PROTO_SPP, vines_spp_handle);
842 }
843
844 #define VINES_VERS_PRE_5_5      0x00
845 #define VINES_VERS_5_5          0x01
846
847 static const value_string vines_version_vals[] = {
848         { VINES_VERS_PRE_5_5, "Pre-5.50" },
849         { VINES_VERS_5_5,     "5.50" },
850         { 0,                  NULL }
851 };
852
853 #define VARP_QUERY_REQ          0x00
854 #define VARP_SERVICE_RESP       0x01
855 #define VARP_ASSIGNMENT_REQ     0x02
856 #define VARP_ASSIGNMENT_RESP    0x03
857
858 static const value_string vines_arp_packet_type_vals[] = {
859         { VARP_QUERY_REQ,       "Query request" },
860         { VARP_SERVICE_RESP,    "Service response" },
861         { VARP_ASSIGNMENT_REQ,  "Assignment request" },
862         { VARP_ASSIGNMENT_RESP, "Assignment response" },
863         { 0,                    NULL }
864 };
865
866 static void
867 dissect_vines_arp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
868 {
869         proto_tree *vines_arp_tree = NULL;
870         proto_item *ti;
871         guint8   version;
872         guint8   packet_type;
873         guint16  metric;
874
875         if (check_col(pinfo->cinfo, COL_PROTOCOL))
876                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Vines ARP");
877         if (check_col(pinfo->cinfo, COL_INFO))
878                 col_clear(pinfo->cinfo, COL_INFO);
879
880         if (tree) {
881                 ti = proto_tree_add_item(tree, proto_vines_arp, tvb, 0, -1,
882                     FALSE);
883                 vines_arp_tree = proto_item_add_subtree(ti, ett_vines_arp);
884         }
885
886         version = tvb_get_guint8(tvb, 0);
887         if (tree) {
888                 proto_tree_add_text(vines_arp_tree, tvb, 0, 1,
889                                     "Version: %s (0x%02x)",
890                                     val_to_str(version, vines_version_vals,
891                                       "Unknown"),
892                                     version);
893         }
894         if (version == VINES_VERS_5_5) {
895                 /*
896                  * Sequenced ARP.
897                  */
898                 if (check_col(pinfo->cinfo, COL_PROTOCOL))
899                         col_set_str(pinfo->cinfo, COL_PROTOCOL, "Vines SARP");
900                 packet_type = tvb_get_guint8(tvb, 1);
901                 if (check_col(pinfo->cinfo, COL_INFO)) {
902                         col_add_str(pinfo->cinfo, COL_INFO,
903                             val_to_str(packet_type, vines_arp_packet_type_vals,
904                               "Unknown (0x%02x)"));
905                 }
906                 if (tree) {
907                         proto_tree_add_text(vines_arp_tree, tvb, 1, 1,
908                                             "Packet Type: %s (0x%02x)",
909                                             val_to_str(packet_type,
910                                               vines_arp_packet_type_vals,
911                                               "Unknown"),
912                                             packet_type);
913                 }
914                 if (packet_type == VARP_ASSIGNMENT_RESP) {
915                         if (check_col(pinfo->cinfo, COL_INFO)) {
916                                 col_append_fstr(pinfo->cinfo, COL_INFO,
917                                             ", Address = %s",
918                                             vines_addr_to_str(tvb_get_ptr(tvb, 2, VINES_ADDR_LEN)));
919                         }
920                         if (tree) {
921                                 proto_tree_add_text(vines_arp_tree, tvb, 2,
922                                                     VINES_ADDR_LEN,
923                                                     "Address: %s",
924                                                     vines_addr_to_str(tvb_get_ptr(tvb, 2, VINES_ADDR_LEN)));
925                         }
926                 }
927                 if (tree) {
928                         proto_tree_add_text(vines_arp_tree, tvb,
929                                             2+VINES_ADDR_LEN, 4,
930                                             "Sequence Number: %u",
931                                             tvb_get_ntohl(tvb, 2+VINES_ADDR_LEN));
932                         metric = tvb_get_ntohs(tvb, 2+VINES_ADDR_LEN+4);
933                         proto_tree_add_text(vines_arp_tree, tvb,
934                                             2+VINES_ADDR_LEN+4, 2,
935                                             "Interface Metric: %u ticks (%g seconds)",
936                                             metric, metric*.2);
937                 }
938         } else {
939                 /*
940                  * Non-sequenced ARP.
941                  */
942                 packet_type = tvb_get_ntohs(tvb, 0);
943                 if (check_col(pinfo->cinfo, COL_INFO)) {
944                         col_add_str(pinfo->cinfo, COL_INFO,
945                             val_to_str(packet_type, vines_arp_packet_type_vals,
946                               "Unknown (0x%02x)"));
947                 }
948                 if (tree) {
949                         proto_tree_add_text(vines_arp_tree, tvb, 0, 2,
950                                             "Packet Type: %s (0x%04x)",
951                                             val_to_str(packet_type,
952                                               vines_arp_packet_type_vals,
953                                               "Unknown"),
954                                             packet_type);
955                 }
956                 if (packet_type == VARP_ASSIGNMENT_RESP) {
957                         if (check_col(pinfo->cinfo, COL_INFO)) {
958                                 col_append_fstr(pinfo->cinfo, COL_INFO,
959                                             ", Address = %s",
960                                             vines_addr_to_str(tvb_get_ptr(tvb, 2, VINES_ADDR_LEN)));
961                         }
962                         if (tree) {
963                                 proto_tree_add_text(vines_arp_tree, tvb, 2,
964                                                     VINES_ADDR_LEN,
965                                                     "Address: %s",
966                                                     vines_addr_to_str(tvb_get_ptr(tvb, 2, VINES_ADDR_LEN)));
967                         }
968                 }
969         }
970 }
971
972 void
973 proto_register_vines_arp(void)
974 {
975         static gint *ett[] = {
976                 &ett_vines_arp,
977         };
978
979         proto_vines_arp = proto_register_protocol(
980             "Banyan Vines ARP", "Vines ARP", "vines_arp");
981         proto_register_subtree_array(ett, array_length(ett));
982 }
983
984 void
985 proto_reg_handoff_vines_arp(void)
986 {
987         dissector_handle_t vines_arp_handle;
988
989         vines_arp_handle = create_dissector_handle(dissect_vines_arp,
990             proto_vines_arp);
991         dissector_add("vines_ip.protocol", VIP_PROTO_ARP, vines_arp_handle);
992 }
993
994 #define VRTP_OP_REQUEST         0x01
995 #define VRTP_OP_UPDATE_RESPONSE 0x02
996 #define VRTP_OP_REDIRECT        0x03
997 #define VRTP_OP_REINITIALIZE    0x04
998 #define VRTP_OP_REDIRECT2       0x06
999
1000 static const value_string vines_rtp_operation_type_vals[] = {
1001         { VRTP_OP_REQUEST,         "Request" },
1002         { VRTP_OP_UPDATE_RESPONSE, "Update/response" },
1003         { VRTP_OP_REDIRECT,        "Redirect" },
1004         { VRTP_OP_REINITIALIZE,    "Reinitialize" },
1005         { VRTP_OP_REDIRECT2,       "Redirect" },
1006         { 0,                       NULL }
1007 };
1008
1009 static const value_string vines_rtp_node_type_vals[] = {
1010         { 0x01, "Host" },
1011         { 0x02, "Router" },
1012         { 0,    NULL }
1013 };
1014
1015 static const value_string vines_rtp_controller_type_vals[] = {
1016         { 0x00, "Default Card" },
1017         { 0x01, "Multibuffer" },
1018         { 0,    NULL }
1019 };
1020
1021 static const value_string vines_rtp_compatibility_flags_vals[] = {
1022         { 0x00, "Same Revision" },
1023         { 0x01, "Version Mismatch" },
1024         { 0x02, "Old Neighbors" },
1025         { 0x03, "Automatic" },
1026         { 0,    NULL }
1027 };
1028
1029 static const value_string vines_rtp_info_type_vals[] = {
1030         { 0x00, "Update" },
1031         { 0x01, "Update" },
1032         { 0x02, "Response" },
1033         { 0,    NULL }
1034 };
1035
1036 static void rtp_show_machine_type(proto_tree *tree, tvbuff_t *tvb, int offset,
1037     char *tag);
1038 static void rtp_show_flags(proto_tree *tree, tvbuff_t *tvb, int offset,
1039     char *tag);
1040 static int srtp_show_machine_info(proto_tree *tree, tvbuff_t *tvb, int offset,
1041     char *tag);
1042 static int rtp_show_gateway_info(proto_tree *tree, tvbuff_t *tvb, int offset,
1043     guint8 link_addr_length, guint8 source_route_length);
1044
1045 static void
1046 dissect_vines_rtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1047 {
1048         int offset = 0;
1049         proto_tree *vines_rtp_tree = NULL;
1050         proto_item *ti;
1051         proto_tree *subtree;
1052         guint16  version;
1053         guint8   operation_type;
1054         guint8   node_type;
1055         guint8   controller_type;
1056         guint8   compatibility_flags;
1057         guint8   link_addr_length;
1058         guint8   source_route_length;
1059         guint8   requested_info;
1060         guint8   info_type;
1061         guint8   control_flags;
1062         guint16  metric;
1063
1064         if (check_col(pinfo->cinfo, COL_PROTOCOL))
1065                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Vines RTP");
1066         if (check_col(pinfo->cinfo, COL_INFO))
1067                 col_clear(pinfo->cinfo, COL_INFO);
1068
1069         if (tree) {
1070                 ti = proto_tree_add_item(tree, proto_vines_rtp, tvb, 0, -1,
1071                     FALSE);
1072                 vines_rtp_tree = proto_item_add_subtree(ti, ett_vines_rtp);
1073         }
1074
1075         if (tvb_get_guint8(tvb, 0) != 0) {
1076                 /*
1077                  * Non-sequenced RTP.
1078                  */
1079                 operation_type = tvb_get_guint8(tvb, offset);
1080                 if (check_col(pinfo->cinfo, COL_INFO)) {
1081                         col_add_str(pinfo->cinfo, COL_INFO,
1082                             val_to_str(operation_type, vines_rtp_operation_type_vals,
1083                               "Unknown (0x%02x)"));
1084                 }
1085                 if (tree) {
1086                         proto_tree_add_text(vines_rtp_tree, tvb, offset, 1,
1087                                             "Operation Type: %s (0x%02x)",
1088                                             val_to_str(operation_type,
1089                                               vines_rtp_operation_type_vals,
1090                                               "Unknown"),
1091                                             operation_type);
1092                         offset += 1;
1093                         node_type = tvb_get_guint8(tvb, offset);
1094                         proto_tree_add_text(vines_rtp_tree, tvb, offset, 1,
1095                                             "Node Type: %s (0x%02x)",
1096                                             val_to_str(node_type,
1097                                               vines_rtp_node_type_vals,
1098                                               "Unknown"),
1099                                             node_type);
1100                         offset += 1;
1101                         controller_type = tvb_get_guint8(tvb, offset);
1102                         proto_tree_add_text(vines_rtp_tree, tvb, offset, 1,
1103                                             "Controller Type: %s (0x%02x)",
1104                                             val_to_str(controller_type,
1105                                               vines_rtp_controller_type_vals,
1106                                               "Unknown"),
1107                                             controller_type);
1108                         offset += 1;
1109                         rtp_show_machine_type(vines_rtp_tree, tvb, offset,
1110                             NULL);
1111                         offset += 1;
1112                         switch (operation_type) {
1113
1114                         case VRTP_OP_REDIRECT:
1115                         case VRTP_OP_REDIRECT2:
1116                                 proto_tree_add_text(vines_rtp_tree, tvb,
1117                                                     offset, 2,
1118                                                     "Version: 0x%02x",
1119                                                     tvb_get_ntohs(tvb, offset));
1120                                 offset += 2;
1121                                 link_addr_length = tvb_get_guint8(tvb, offset);
1122                                 proto_tree_add_text(vines_rtp_tree, tvb,
1123                                                     offset, 1,
1124                                                     "Link Address Length: %u",
1125                                                     link_addr_length);
1126                                 offset += 1;
1127                                 source_route_length = tvb_get_guint8(tvb, offset);
1128                                 proto_tree_add_text(vines_rtp_tree, tvb,
1129                                                     offset, 1,
1130                                                     "Source Route Length: %u",
1131                                                     source_route_length);
1132                                 offset += 1;
1133                                 offset = srtp_show_machine_info(vines_rtp_tree,
1134                                     tvb, offset, "Destination");
1135                                 offset += 1;
1136                                 offset = srtp_show_machine_info(vines_rtp_tree,
1137                                     tvb, offset, "Preferred Gateway");
1138                                 offset += 1;
1139                                 offset = rtp_show_gateway_info(vines_rtp_tree,
1140                                     tvb,offset, link_addr_length,
1141                                     source_route_length);
1142                                 break;
1143
1144                         default:
1145                                 while (tvb_reported_length_remaining(tvb, offset) > 0) {
1146                                         proto_tree_add_text(vines_rtp_tree, tvb,
1147                                                     offset, 4,
1148                                                     "Network Number: 0x%08x",
1149                                                     tvb_get_ntohl(tvb, offset));
1150                                         offset += 4;
1151                                         metric = tvb_get_ntohs(tvb, offset);
1152                                         proto_tree_add_text(vines_rtp_tree, tvb,
1153                                                     offset, 2,
1154                                                     "Neighbor Metric: %u ticks (%g seconds)",
1155                                                     metric,
1156                                                     metric*.2);
1157                                         offset += 2;
1158                                 }
1159                                 break;
1160                         }
1161                 }
1162         } else {
1163                 if (check_col(pinfo->cinfo, COL_PROTOCOL))
1164                         col_set_str(pinfo->cinfo, COL_PROTOCOL, "Vines SRTP");
1165                 if (tree) {
1166                         version = tvb_get_ntohs(tvb, offset);
1167                         proto_tree_add_text(vines_rtp_tree, tvb, offset, 2,
1168                                             "Version: %s (0x%04x)",
1169                                             val_to_str(version, vines_version_vals,
1170                                               "Unknown"),
1171                                             version);
1172                 }
1173                 offset += 2;
1174                 operation_type = tvb_get_guint8(tvb, offset);
1175                 if (check_col(pinfo->cinfo, COL_INFO)) {
1176                         col_add_str(pinfo->cinfo, COL_INFO,
1177                             val_to_str(operation_type, vines_rtp_operation_type_vals,
1178                               "Unknown (0x%02x)"));
1179                 }
1180                 if (tree) {
1181                         proto_tree_add_text(vines_rtp_tree, tvb, offset, 1,
1182                                             "Operation Type: %s (0x%02x)",
1183                                             val_to_str(operation_type,
1184                                               vines_rtp_operation_type_vals,
1185                                               "Unknown"),
1186                                             operation_type);
1187                         offset += 1;
1188                         node_type = tvb_get_guint8(tvb, offset);
1189                         proto_tree_add_text(vines_rtp_tree, tvb, offset, 1,
1190                                             "Node Type: %s (0x%02x)",
1191                                             val_to_str(node_type,
1192                                               vines_rtp_node_type_vals,
1193                                               "Unknown"),
1194                                             node_type);
1195                         offset += 1;
1196                         compatibility_flags = tvb_get_guint8(tvb, offset);
1197                         ti = proto_tree_add_text(vines_rtp_tree, tvb, offset, 1,
1198                                             "Compatibility Flags: 0x%02x",
1199                                             compatibility_flags);
1200                         subtree = proto_item_add_subtree(ti,
1201                             ett_vines_rtp_compatibility_flags);
1202                         proto_tree_add_text(subtree, tvb,
1203                             offset, 1,
1204                             decode_boolean_bitfield(compatibility_flags,
1205                               0x04, 1*8,
1206                               "Auto-configured non-Vines-reachable neighbor router",
1207                               "Not an auto-configured non-Vines-reachable neighbor router"));
1208                         proto_tree_add_text(subtree, tvb,
1209                             offset, 1,
1210                             decode_boolean_bitfield(compatibility_flags,
1211                               0x02, 1*8,
1212                               "Not all neighbor routers support Sequenced RTP",
1213                               "All neighbor routers support Sequenced RTP"));
1214                         proto_tree_add_text(subtree, tvb,
1215                             offset, 1,
1216                             decode_boolean_bitfield(compatibility_flags,
1217                               0x01, 1*8,
1218                               "Sequenced RTP version mismatch",
1219                               "No Sequenced RTP version mismatch"));
1220                         offset += 1;
1221                         offset += 1;    /* reserved */
1222                         switch (operation_type) {
1223
1224                         case VRTP_OP_REQUEST:
1225                                 requested_info = tvb_get_guint8(tvb, offset);
1226                                 proto_tree_add_text(vines_rtp_tree, tvb,
1227                                                     offset, 1,
1228                                                     "Requested Info: 0x%02x",
1229                                                     requested_info);
1230                                 break;
1231
1232                         case VRTP_OP_UPDATE_RESPONSE:
1233                                 info_type = tvb_get_guint8(tvb, offset);
1234                                 proto_tree_add_text(vines_rtp_tree, tvb,
1235                                             offset, 1,
1236                                             "Information Type: %s (0x%02x)",
1237                                             val_to_str(info_type,
1238                                               vines_rtp_info_type_vals,
1239                                               "Unknown"),
1240                                             compatibility_flags);
1241                                 offset += 1;
1242                                 control_flags = tvb_get_guint8(tvb, offset);
1243                                 ti = proto_tree_add_text(vines_rtp_tree, tvb,
1244                                                     offset, 1,
1245                                                     "Control Flags: 0x%02x",
1246                                                     control_flags);
1247                                 subtree = proto_item_add_subtree(ti,
1248                                     ett_vines_rtp_control_flags);
1249                                 proto_tree_add_text(subtree, tvb,
1250                                     offset, 1,
1251                                     decode_boolean_bitfield(control_flags,
1252                                       0x10, 1*8,
1253                                       "Part of routing table synchronization broadcast",
1254                                       "Not part of routing table synchronization broadcast"));
1255                                 proto_tree_add_text(subtree, tvb,
1256                                     offset, 1,
1257                                     decode_boolean_bitfield(control_flags,
1258                                       0x08, 1*8,
1259                                       "Part of full topology update",
1260                                       "Not part of full topology update"));
1261                                 proto_tree_add_text(subtree, tvb,
1262                                     offset, 1,
1263                                     decode_boolean_bitfield(control_flags,
1264                                       0x04, 1*8,
1265                                       "Contains info specifically requested or network changes",
1266                                       "Not a response to a specific request"));
1267                                 /* XXX - need reassembly? */
1268                                 proto_tree_add_text(subtree, tvb,
1269                                     offset, 1,
1270                                     decode_boolean_bitfield(control_flags,
1271                                       0x02, 1*8,
1272                                       "End of message",
1273                                       "Not end of message"));
1274                                 proto_tree_add_text(subtree, tvb,
1275                                     offset, 1,
1276                                     decode_boolean_bitfield(control_flags,
1277                                       0x01, 1*8,
1278                                       "Beginning of message",
1279                                       "Not beginning of message"));
1280                                 offset += 1;
1281                                 proto_tree_add_text(vines_rtp_tree, tvb,
1282                                             offset, 2,
1283                                             "Packet ID: %u",
1284                                             tvb_get_ntohs(tvb, offset));
1285                                 offset += 2;
1286                                 proto_tree_add_text(vines_rtp_tree, tvb,
1287                                             offset, 2,
1288                                             "Data Offset: %u",
1289                                             tvb_get_ntohs(tvb, offset));
1290                                 offset += 2;
1291                                 proto_tree_add_text(vines_rtp_tree, tvb,
1292                                             offset, 4,
1293                                             "Router Sequence Number: %u",
1294                                             tvb_get_ntohl(tvb, offset));
1295                                 offset += 4;
1296                                 metric = tvb_get_ntohs(tvb, offset);
1297                                 proto_tree_add_text(vines_rtp_tree, tvb,
1298                                             offset, 2,
1299                                             "Metric: %u ticks (%g seconds)",
1300                                             metric, metric*.2);
1301                                 offset += 2;
1302                                 while (tvb_reported_length_remaining(tvb, offset) > 0) {
1303                                         proto_tree_add_text(vines_rtp_tree, tvb,
1304                                                     offset, 4,
1305                                                     "Network Number: 0x%08x",
1306                                                     tvb_get_ntohl(tvb, offset));
1307                                         offset += 4;
1308                                         metric = tvb_get_ntohs(tvb, offset);
1309                                         if (metric == 0xffff) {
1310                                                 proto_tree_add_text(vines_rtp_tree, tvb,
1311                                                             offset, 2,
1312                                                             "Neighbor Metric: Unreachable");
1313                                         } else {
1314                                                 proto_tree_add_text(vines_rtp_tree, tvb,
1315                                                             offset, 2,
1316                                                             "Neighbor Metric: %u ticks (%g seconds)",
1317                                                             metric, metric*.2);
1318                                         }
1319                                         offset += 2;
1320                                         proto_tree_add_text(vines_rtp_tree, tvb,
1321                                                     offset, 4,
1322                                                     "Sequence Number: %u",
1323                                                     tvb_get_ntohl(tvb, offset));
1324                                         offset += 4;
1325                                         rtp_show_flags(vines_rtp_tree, tvb,
1326                                             offset, "Network");
1327                                         offset += 1;
1328                                         offset += 1;    /* reserved */
1329                                 }
1330                                 break;
1331
1332                         case VRTP_OP_REDIRECT:
1333                                 link_addr_length = tvb_get_guint8(tvb, offset);
1334                                 proto_tree_add_text(vines_rtp_tree, tvb,
1335                                                     offset, 1,
1336                                                     "Link Address Length: %u",
1337                                                     link_addr_length);
1338                                 offset += 1;
1339                                 source_route_length = tvb_get_guint8(tvb, offset);
1340                                 proto_tree_add_text(vines_rtp_tree, tvb,
1341                                                     offset, 1,
1342                                                     "Source Route Length: %u",
1343                                                     source_route_length);
1344                                 offset += 1;
1345                                 proto_tree_add_text(vines_rtp_tree, tvb,
1346                                                     offset, VINES_ADDR_LEN,
1347                                                     "Destination: %s",
1348                                                     vines_addr_to_str(tvb_get_ptr(tvb, offset, VINES_ADDR_LEN)));
1349                                 offset += VINES_ADDR_LEN;
1350                                 metric = tvb_get_ntohs(tvb, offset);
1351                                 proto_tree_add_text(vines_rtp_tree, tvb,
1352                                                     offset, 2,
1353                                                     "Metric to Destination: %u ticks (%g seconds)",
1354                                                     metric, metric*.2);
1355                                 offset += 2;
1356                                 node_type = tvb_get_guint8(tvb, offset);
1357                                 proto_tree_add_text(vines_rtp_tree, tvb,
1358                                             offset, 1,
1359                                             "Destination Node Type: %s (0x%02x)",
1360                                             val_to_str(node_type,
1361                                               vines_rtp_node_type_vals,
1362                                               "Unknown"),
1363                                             node_type);
1364                                 offset += 1;
1365                                 rtp_show_flags(vines_rtp_tree, tvb,
1366                                     offset, "Destination");
1367                                 offset += 1;
1368                                 proto_tree_add_text(vines_rtp_tree, tvb,
1369                                             offset, 4,
1370                                             "Destination Sequence Number: %u",
1371                                             tvb_get_ntohl(tvb, offset));
1372                                 offset += 4;
1373                                 proto_tree_add_text(vines_rtp_tree, tvb,
1374                                                     offset, VINES_ADDR_LEN,
1375                                                     "Preferred Gateway: %s",
1376                                                     vines_addr_to_str(tvb_get_ptr(tvb, offset, VINES_ADDR_LEN)));
1377                                 offset += VINES_ADDR_LEN;
1378                                 metric = tvb_get_ntohs(tvb, offset);
1379                                 proto_tree_add_text(vines_rtp_tree, tvb,
1380                                                     offset, 2,
1381                                                     "Metric to Preferred Gateway: %u ticks (%g seconds)",
1382                                                     metric, metric*.2);
1383                                 offset += 2;
1384                                 node_type = tvb_get_guint8(tvb, offset);
1385                                 proto_tree_add_text(vines_rtp_tree, tvb,
1386                                             offset, 1,
1387                                             "Preferred Gateway Node Type: %s (0x%02x)",
1388                                             val_to_str(node_type,
1389                                               vines_rtp_node_type_vals,
1390                                               "Unknown"),
1391                                             node_type);
1392                                 offset += 1;
1393                                 rtp_show_flags(vines_rtp_tree, tvb,
1394                                     offset, "Preferred Gateway");
1395                                 offset += 1;
1396                                 proto_tree_add_text(vines_rtp_tree, tvb,
1397                                             offset, 4,
1398                                             "Preferred Gateway Sequence Number: %u",
1399                                             tvb_get_ntohl(tvb, offset));
1400                                 offset += 4;
1401                                 offset = rtp_show_gateway_info(vines_rtp_tree,
1402                                     tvb,offset, link_addr_length,
1403                                     source_route_length);
1404                                 break;
1405
1406                         case VRTP_OP_REINITIALIZE:
1407                                 break;
1408                         }
1409
1410                 }
1411         }
1412 }
1413
1414 static void
1415 rtp_show_machine_type(proto_tree *tree, tvbuff_t *tvb, int offset, char *tag)
1416 {
1417         guint8 machine_type;
1418         proto_item *ti;
1419         proto_tree *subtree;
1420
1421         machine_type = tvb_get_guint8(tvb, offset);
1422         ti = proto_tree_add_text(tree, tvb, offset, 1,
1423             "%s%sMachine Type: 0x%02x",
1424             tag == NULL ? "" : tag,
1425             tag == NULL ? "" : " ",
1426             machine_type);
1427         subtree = proto_item_add_subtree(ti, ett_vines_rtp_mtype);
1428         proto_tree_add_text(subtree, tvb, offset, 1,
1429             decode_boolean_bitfield(machine_type, 0x04, 1*8,
1430               "Sequenced RTP supported",
1431               "Sequenced RTP not supported"));
1432         proto_tree_add_text(subtree, tvb, offset, 1,
1433             decode_boolean_bitfield(machine_type, 0x02, 1*8,
1434               "TCP/IP supported",
1435               "TCP/IP not supported"));
1436         proto_tree_add_text(subtree, tvb, offset, 1,
1437             decode_boolean_bitfield(machine_type, 0x01, 1*8,
1438               "Fast bus",
1439               "Slow bus"));
1440 }
1441
1442 static void
1443 rtp_show_flags(proto_tree *tree, tvbuff_t *tvb, int offset, char *tag)
1444 {
1445         guint8 flags;
1446         proto_item *ti;
1447         proto_tree *flags_tree;
1448
1449         flags = tvb_get_guint8(tvb, offset);
1450         ti = proto_tree_add_text(tree, tvb, offset, 1, "%s Flags: 0x%02x",
1451             tag, flags);
1452         flags_tree = proto_item_add_subtree(ti, ett_vines_rtp_flags);
1453         proto_tree_add_text(flags_tree, tvb, offset, 1,
1454             decode_boolean_bitfield(flags, 0x08, 1*8,
1455               "Network doesn't support Sequenced RTP",
1456               "Network supports Sequenced RTP"));
1457         proto_tree_add_text(flags_tree, tvb, offset, 1,
1458             decode_boolean_bitfield(flags, 0x04, 1*8,
1459               "Network accessed point-to-point on non-Vines network",
1460               "Network not accessed point-to-point on non-Vines network"));
1461         proto_tree_add_text(flags_tree, tvb, offset, 1,
1462             decode_boolean_bitfield(flags, 0x02, 1*8,
1463               "Data link to network uses point-to-point connection",
1464               "Data link to network doesn't use point-to-point connection"));
1465         proto_tree_add_text(flags_tree, tvb, offset, 1,
1466             decode_boolean_bitfield(flags, 0x01, 1*8,
1467               "Network accessed across broadcast medium",
1468               "Network not accessed across broadcast medium"));
1469 }
1470
1471 static int
1472 srtp_show_machine_info(proto_tree *tree, tvbuff_t *tvb, int offset, char *tag)
1473 {
1474         guint16 metric;
1475         guint8 node_type;
1476         guint8 controller_type;
1477
1478         proto_tree_add_text(tree, tvb, offset, VINES_ADDR_LEN,
1479             "%s: %s", tag,
1480             vines_addr_to_str(tvb_get_ptr(tvb, offset, VINES_ADDR_LEN)));
1481         offset += VINES_ADDR_LEN;
1482         metric = tvb_get_ntohs(tvb, offset);
1483         proto_tree_add_text(tree, tvb, offset, 2,
1484             "Metric to %s: %u ticks (%g seconds)", tag, metric, metric*.2);
1485         offset += 2;
1486         node_type = tvb_get_guint8(tvb, offset);
1487         proto_tree_add_text(tree, tvb, offset, 1,
1488             "%s Node Type: %s (0x%02x)", tag,
1489             val_to_str(node_type, vines_rtp_node_type_vals, "Unknown"),
1490             node_type);
1491         offset += 1;
1492         rtp_show_machine_type(tree, tvb, offset, tag);
1493         offset += 1;
1494         controller_type = tvb_get_guint8(tvb, offset);
1495         proto_tree_add_text(tree, tvb, offset, 1,
1496             "%s Controller Type: %s (0x%02x)", tag,
1497             val_to_str(controller_type, vines_rtp_controller_type_vals, "Unknown"),
1498             controller_type);
1499         offset += 1;
1500         return offset;
1501 }
1502
1503 static int
1504 rtp_show_gateway_info(proto_tree *tree, tvbuff_t *tvb, int offset,
1505     guint8 link_addr_length, guint8 source_route_length)
1506 {
1507         if (link_addr_length != 0) {
1508                 proto_tree_add_text(tree, tvb, offset, link_addr_length,
1509                     "Preferred Gateway Data Link Address: %s",
1510                     link_addr_length == 6 ?
1511                     ether_to_str(tvb_get_ptr(tvb, offset, link_addr_length)) :
1512                     tvb_bytes_to_str(tvb, offset, link_addr_length));
1513                 offset += link_addr_length;
1514         }
1515         if (source_route_length != 0) {
1516                 proto_tree_add_text(tree, tvb, offset, source_route_length,
1517                     "Preferred Gateway Source Route: %s",
1518                     tvb_bytes_to_str(tvb, offset, source_route_length));
1519                 offset += source_route_length;
1520         }
1521         return offset;
1522 }
1523
1524 void
1525 proto_register_vines_rtp(void)
1526 {
1527         static gint *ett[] = {
1528                 &ett_vines_rtp,
1529                 &ett_vines_rtp_compatibility_flags,
1530                 &ett_vines_rtp_req_info,
1531                 &ett_vines_rtp_control_flags,
1532                 &ett_vines_rtp_mtype,
1533                 &ett_vines_rtp_flags,
1534         };
1535
1536         proto_vines_rtp = proto_register_protocol(
1537             "Banyan Vines RTP", "Vines RTP", "vines_rtp");
1538         proto_register_subtree_array(ett, array_length(ett));
1539 }
1540
1541 void
1542 proto_reg_handoff_vines_rtp(void)
1543 {
1544         dissector_handle_t vines_rtp_handle;
1545
1546         vines_rtp_handle = create_dissector_handle(dissect_vines_rtp,
1547             proto_vines_rtp);
1548         dissector_add("vines_ip.protocol", VIP_PROTO_RTP, vines_rtp_handle);
1549 }
1550
1551 #define VICP_EXCEPTION_NOTIFICATION     0x0000
1552 #define VICP_METRIC_NOTIFICATION        0x0001
1553
1554 static const value_string vines_icp_packet_type_vals[] = {
1555         { VICP_EXCEPTION_NOTIFICATION, "Exception notification" },
1556         { VICP_METRIC_NOTIFICATION,    "Metric notification" },
1557         { 0,                           NULL }
1558 };
1559
1560 static void
1561 dissect_vines_icp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1562 {
1563         int offset = 0;
1564         proto_tree *vines_icp_tree = NULL;
1565         proto_item *ti;
1566         guint16  packet_type;
1567         guint16  exception_code;
1568         guint16  metric;
1569         gboolean save_in_error_pkt;
1570         tvbuff_t *next_tvb;
1571
1572         if (check_col(pinfo->cinfo, COL_PROTOCOL))
1573                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Vines ICP");
1574         if (check_col(pinfo->cinfo, COL_INFO))
1575                 col_clear(pinfo->cinfo, COL_INFO);
1576
1577         if (tree) {
1578                 ti = proto_tree_add_item(tree, proto_vines_icp, tvb, 0, -1,
1579                     FALSE);
1580                 vines_icp_tree = proto_item_add_subtree(ti, ett_vines_icp);
1581         }
1582
1583         packet_type = tvb_get_ntohs(tvb, offset);
1584         if (check_col(pinfo->cinfo, COL_INFO)) {
1585                 col_add_str(pinfo->cinfo, COL_INFO,
1586                     val_to_str(packet_type, vines_icp_packet_type_vals,
1587                       "Unknown (0x%02x)"));
1588         }
1589         if (tree) {
1590                 proto_tree_add_text(vines_icp_tree, tvb, offset, 2,
1591                                     "Packet Type: %s (0x%04x)",
1592                                     val_to_str(packet_type,
1593                                       vines_icp_packet_type_vals,
1594                                       "Unknown"),
1595                                     packet_type);
1596         }
1597         offset += 2;
1598
1599         switch (packet_type) {
1600
1601         case VICP_EXCEPTION_NOTIFICATION:
1602                 exception_code = tvb_get_ntohs(tvb, offset);
1603                 if (check_col(pinfo->cinfo, COL_INFO)) {
1604                         col_append_fstr(pinfo->cinfo, COL_INFO, ", %s",
1605                             val_to_str(exception_code, vipc_err_vals,
1606                                 "Unknown exception code (%u)"));
1607                 }
1608                 if (tree) {
1609                         proto_tree_add_text(vines_icp_tree, tvb, offset, 2,
1610                                             "Exception Code: %s (%u)",
1611                                             val_to_str(exception_code,
1612                                               vipc_err_vals,
1613                                               "Unknown"),
1614                                             exception_code);
1615                 }
1616                 break;
1617
1618         case VICP_METRIC_NOTIFICATION:
1619                 metric = tvb_get_ntohs(tvb, offset);
1620                 if (check_col(pinfo->cinfo, COL_INFO)) {
1621                         col_append_fstr(pinfo->cinfo, COL_INFO, ", metric %u",
1622                             metric);
1623                 }
1624                 if (tree) {
1625                         proto_tree_add_text(vines_icp_tree, tvb, offset, 2,
1626                                             "Metric: %u", metric);
1627                 }
1628                 break;
1629         }
1630         offset += 2;
1631
1632         /*
1633          * Save the current value of the "we're inside an error packet"
1634          * flag, and set that flag; subdissectors may treat packets
1635          * that are the payload of error packets differently from
1636          * "real" packets.
1637          */
1638         save_in_error_pkt = pinfo->in_error_pkt;
1639         pinfo->in_error_pkt = TRUE;
1640
1641         /* Decode the first 40 bytes of the original VIP datagram. */
1642         next_tvb = tvb_new_subset(tvb, offset, -1, -1);
1643         call_dissector(vines_ip_handle, next_tvb, pinfo, vines_icp_tree);
1644
1645         /* Restore the "we're inside an error packet" flag. */
1646         pinfo->in_error_pkt = save_in_error_pkt;
1647 }
1648
1649 void
1650 proto_register_vines_icp(void)
1651 {
1652         static gint *ett[] = {
1653                 &ett_vines_icp,
1654         };
1655
1656         proto_vines_icp = proto_register_protocol(
1657             "Banyan Vines ICP", "Vines ICP", "vines_icp");
1658         proto_register_subtree_array(ett, array_length(ett));
1659 }
1660
1661 void
1662 proto_reg_handoff_vines_icp(void)
1663 {
1664         dissector_handle_t vines_icp_handle;
1665
1666         vines_icp_handle = create_dissector_handle(dissect_vines_icp,
1667             proto_vines_icp);
1668         dissector_add("vines_ip.protocol", VIP_PROTO_ICP, vines_icp_handle);
1669 }