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