From Tim Potter: dissect some of the LSA RPCs stub data.
[obnox/wireshark/wip.git] / packet-atalk.c
1 /* packet-atalk.c
2  * Routines for Appletalk packet disassembly (DDP, currently).
3  *
4  * $Id: packet-atalk.c,v 1.60 2001/12/10 00:25:26 guy Exp $
5  *
6  * Simon Wilkinson <sxw@dcs.ed.ac.uk>
7  *
8  * Ethereal - Network traffic analyzer
9  * By Gerald Combs <gerald@ethereal.com>
10  * Copyright 1998
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  * 
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  * 
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
33 #endif
34
35 #ifdef HAVE_NETINET_IN_H
36 # include <netinet/in.h>
37 #endif
38
39 #include <glib.h>
40 #include "packet.h"
41 #include "etypes.h"
42 #include "ppptypes.h"
43 #include "aftypes.h"
44 #include "atalk-utils.h"
45
46 static int proto_llap = -1;
47 static int hf_llap_dst = -1;
48 static int hf_llap_src = -1;
49 static int hf_llap_type = -1;
50
51 static int proto_ddp = -1;
52 static int hf_ddp_hopcount = -1;
53 static int hf_ddp_len = -1;
54 static int hf_ddp_checksum = -1;
55 static int hf_ddp_dst_net = -1;
56 static int hf_ddp_src_net = -1;
57 static int hf_ddp_dst_node = -1;
58 static int hf_ddp_src_node = -1;
59 static int hf_ddp_dst_socket = -1;
60 static int hf_ddp_src_socket = -1;
61 static int hf_ddp_type = -1;
62
63 static int proto_nbp = -1;
64 static int hf_nbp_op = -1;
65 static int hf_nbp_info = -1;
66 static int hf_nbp_count = -1;
67 static int hf_nbp_tid = -1;
68
69 static int hf_nbp_node_net = -1;
70 static int hf_nbp_node_port = -1;
71 static int hf_nbp_node_node = -1;
72 static int hf_nbp_node_enum = -1;
73 static int hf_nbp_node_object = -1;
74 static int hf_nbp_node_type = -1;
75 static int hf_nbp_node_zone = -1;
76
77 static int proto_rtmp = -1;
78 static int hf_rtmp_net = -1;
79 static int hf_rtmp_node_len = -1;
80 static int hf_rtmp_node = -1;
81 static int hf_rtmp_tuple_net = -1;
82 static int hf_rtmp_tuple_range_start = -1;
83 static int hf_rtmp_tuple_range_end = -1;
84 static int hf_rtmp_tuple_dist = -1;
85 static int hf_rtmp_function = -1;
86
87 static gint ett_nbp = -1;
88 static gint ett_nbp_info = -1;
89 static gint ett_nbp_node = -1;
90 static gint ett_rtmp = -1;
91 static gint ett_rtmp_tuple = -1;
92 static gint ett_ddp = -1;
93 static gint ett_llap = -1;
94 static gint ett_pstring = -1;
95
96 static dissector_table_t ddp_dissector_table;
97
98 static dissector_handle_t data_handle;
99
100 #define DDP_SHORT_HEADER_SIZE 5
101
102 /*
103  * P = Padding, H = Hops, L = Len
104  *
105  * PPHHHHLL LLLLLLLL
106  *
107  * Assumes the argument is in host byte order.
108  */
109 #define ddp_hops(x)     ( ( x >> 10) & 0x3C )
110 #define ddp_len(x)              ( x & 0x03ff )
111 typedef struct _e_ddp {
112   guint16       hops_len; /* combines pad, hops, and len */
113   guint16       sum,dnet,snet;
114   guint8        dnode,snode;
115   guint8        dport,sport;
116   guint8        type;
117 } e_ddp;
118
119 #define DDP_HEADER_SIZE 13
120
121
122 static const value_string op_vals[] = {
123   {DDP_RTMPDATA, "AppleTalk Routing Table response or data" },
124   {DDP_NBP, "AppleTalk Name Binding Protocol packet"},
125   {DDP_ATP, "AppleTalk Transaction Protocol packet"},
126   {DDP_AEP, "AppleTalk Echo Protocol packet"},
127   {DDP_RTMPREQ, "AppleTalk Routing Table request"},
128   {DDP_ZIP, "AppleTalk Zone Information Protocol packet"},
129   {DDP_ADSP, "AppleTalk Data Stream Protocol"},
130   {DDP_EIGRP, "Cisco EIGRP for AppleTalk"},
131   {0, NULL}
132 };
133
134 static const value_string rtmp_function_vals[] = {
135   {1, "Request"},
136   {2, "Route Data Request (split horizon processed)"},
137   {3, "Route Data Request (no split horizon processing)"},
138   {0, NULL}
139 };
140
141 #define NBP_LOOKUP 2
142 #define NBP_FORWARD 4
143 #define NBP_REPLY 3
144
145 static const value_string nbp_op_vals[] = {
146   {NBP_LOOKUP, "lookup"},
147   {NBP_FORWARD, "forward request"},
148   {NBP_REPLY, "reply"},
149   {0, NULL}
150 };
151
152 /*
153  * XXX - do this with an FT_UINT_STRING?
154  * Unfortunately, you can't extract from an FT_UINT_STRING the string,
155  * which we'd want to do in order to put it into the "Data:" portion.
156  */
157 int dissect_pascal_string(tvbuff_t *tvb, int offset, proto_tree *tree,
158         int hf_index)
159 {
160         int len;
161         
162         len = tvb_get_guint8(tvb, offset);
163         offset++;
164
165         if ( tree )
166         {
167                 char *tmp;
168                 proto_tree *item;
169                 proto_tree *subtree;
170                 
171                 /*
172                  * XXX - if we could do this inside the protocol tree
173                  * code, we could perhaps avoid allocating and freeing
174                  * this string buffer.
175                  */
176                 tmp = g_malloc( len+1 );
177                 tvb_memcpy(tvb, tmp, offset, len);
178                 tmp[len] = 0;
179                 item = proto_tree_add_string(tree, hf_index, tvb, offset-1, len+1, tmp);
180
181                 subtree = proto_item_add_subtree(item, ett_pstring);
182                 proto_tree_add_text(subtree, tvb, offset-1, 1, "Length: %d", len);
183                 proto_tree_add_text(subtree, tvb, offset, len, "Data: %s", tmp);
184                 
185                 g_free(tmp);
186         }
187         offset += len;
188         
189         return offset;  
190 }
191
192 static void
193 dissect_rtmp_request(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
194   proto_tree *rtmp_tree;
195   proto_item *ti;
196   guint8 function;
197
198   if (check_col(pinfo->cinfo, COL_PROTOCOL))
199     col_set_str(pinfo->cinfo, COL_PROTOCOL, "RTMP");
200   if (check_col(pinfo->cinfo, COL_INFO))
201     col_clear(pinfo->cinfo, COL_INFO);
202
203   function = tvb_get_guint8(tvb, 0);
204
205   if (check_col(pinfo->cinfo, COL_INFO))
206     col_add_fstr(pinfo->cinfo, COL_INFO, "%s",
207         val_to_str(function, rtmp_function_vals, "Unknown function (%02)"));
208   
209   if (tree) {
210     ti = proto_tree_add_item(tree, proto_rtmp, tvb, 0, 1, FALSE);
211     rtmp_tree = proto_item_add_subtree(ti, ett_rtmp);
212
213     proto_tree_add_uint(rtmp_tree, hf_rtmp_function, tvb, 0, 1, function);
214   }
215 }
216
217 static void
218 dissect_rtmp_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
219   proto_tree *rtmp_tree;
220   proto_item *ti;
221   int offset = 0;
222   guint16 net;
223   guint8 nodelen,nodelen_bits;
224   guint16 node; /* might be more than 8 bits */
225   int i;
226
227   if (check_col(pinfo->cinfo, COL_PROTOCOL))
228     col_set_str(pinfo->cinfo, COL_PROTOCOL, "RTMP");
229   if (check_col(pinfo->cinfo, COL_INFO))
230     col_clear(pinfo->cinfo, COL_INFO);
231
232   net = tvb_get_ntohs(tvb, offset);
233   nodelen_bits = tvb_get_guint8(tvb, offset+2);
234   if ( nodelen_bits <= 8 ) {
235     node = tvb_get_guint8(tvb, offset)+1;
236     nodelen = 1;
237   } else {
238     node = tvb_get_ntohs(tvb, offset);
239     nodelen = 2;
240   }
241   
242   if (check_col(pinfo->cinfo, COL_INFO))
243     col_add_fstr(pinfo->cinfo, COL_INFO, "Net: %u  Node Len: %u  Node: %u",
244                 net, nodelen_bits, node);
245   
246   if (tree) {
247     ti = proto_tree_add_item(tree, proto_rtmp, tvb, offset,
248                              tvb_length_remaining(tvb, offset), FALSE);
249     rtmp_tree = proto_item_add_subtree(ti, ett_rtmp);
250
251     proto_tree_add_uint(rtmp_tree, hf_rtmp_net, tvb, offset, 2, net);
252     proto_tree_add_uint(rtmp_tree, hf_rtmp_node_len, tvb, offset+2, 1,
253                         nodelen_bits);
254     proto_tree_add_uint(rtmp_tree, hf_rtmp_node, tvb, offset+3, nodelen,
255                         node);
256     offset += 3 + nodelen;
257
258     i = 1;
259     while (tvb_offset_exists(tvb, offset)) {
260       proto_tree *tuple_item, *tuple_tree;
261       guint16 tuple_net;
262       guint8 tuple_dist;
263       guint16 tuple_range_end;
264
265       tuple_net = tvb_get_ntohs(tvb, offset);
266       tuple_dist = tvb_get_guint8(tvb, offset+2);
267
268       if (tuple_dist & 0x80) {
269         tuple_range_end = tvb_get_ntohs(tvb, offset+3);
270         tuple_item = proto_tree_add_text(rtmp_tree, tvb, offset, 6,
271                         "Tuple %d:  Range Start: %u  Dist: %u  Range End: %u",
272                         i, tuple_net, tuple_dist&0x7F, tuple_range_end);
273       } else {
274         tuple_item = proto_tree_add_text(rtmp_tree, tvb, offset, 3,
275                         "Tuple %d:  Net: %u  Dist: %u",
276                         i, tuple_net, tuple_dist);
277       }
278       tuple_tree = proto_item_add_subtree(tuple_item, ett_rtmp_tuple);
279
280       if (tuple_dist & 0x80) {
281         proto_tree_add_uint(tuple_tree, hf_rtmp_tuple_range_start, tvb, offset, 2, 
282                         tuple_net);
283       } else {
284         proto_tree_add_uint(tuple_tree, hf_rtmp_tuple_net, tvb, offset, 2, 
285                         tuple_net);
286       }
287       proto_tree_add_uint(tuple_tree, hf_rtmp_tuple_dist, tvb, offset+2, 1,
288                         tuple_dist & 0x7F);
289
290       if (tuple_dist & 0x80) {
291         /*
292          * Extended network tuple.
293          */
294         proto_tree_add_item(tuple_tree, hf_rtmp_tuple_range_end, tvb, offset+3, 2, 
295                                 FALSE);
296         offset += 6;
297       } else
298         offset += 3;
299
300       i++;
301     }
302   }
303 }
304
305 static void
306 dissect_nbp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
307   proto_tree *nbp_tree;
308   proto_tree *nbp_info_tree;
309   proto_item *ti, *info_item;
310   int offset = 0;
311   guint8 info;
312   guint op, count;
313   unsigned int i;
314
315   if (check_col(pinfo->cinfo, COL_PROTOCOL))
316     col_set_str(pinfo->cinfo, COL_PROTOCOL, "NBP");
317   if (check_col(pinfo->cinfo, COL_INFO))
318     col_clear(pinfo->cinfo, COL_INFO);
319
320   info = tvb_get_guint8(tvb, offset);
321   op = info >> 4;
322   count = info & 0x0F;
323
324   if (check_col(pinfo->cinfo, COL_INFO))
325     col_add_fstr(pinfo->cinfo, COL_INFO, "Op: %s  Count: %u",
326       val_to_str(op, nbp_op_vals, "Unknown (0x%01x)"), count);
327   
328   if (tree) {
329     ti = proto_tree_add_item(tree, proto_nbp, tvb, offset,
330                 tvb_length_remaining(tvb, offset), FALSE);
331     nbp_tree = proto_item_add_subtree(ti, ett_nbp);
332
333     info_item = proto_tree_add_uint_format(nbp_tree, hf_nbp_info, tvb, offset, 1,
334                 info,
335                 "Info: 0x%01X  Operation: %s  Count: %u", info,
336                 val_to_str(op, nbp_op_vals, "Unknown (0x%01X)"),
337                 count);
338     nbp_info_tree = proto_item_add_subtree(info_item, ett_nbp_info);
339     proto_tree_add_uint(nbp_info_tree, hf_nbp_op, tvb, offset, 1, info);
340     proto_tree_add_uint(nbp_info_tree, hf_nbp_count, tvb, offset, 1, info);
341     proto_tree_add_item(nbp_tree, hf_nbp_tid, tvb, offset+1, 1, FALSE);
342     offset += 2;
343
344     for (i=0; i<count; i++) {
345       proto_tree *node_item,*node_tree;
346       int soffset = offset;
347
348       node_item = proto_tree_add_text(nbp_tree, tvb, offset, 4, 
349                         "Node %d", i+1);
350       node_tree = proto_item_add_subtree(node_item, ett_nbp_node);
351
352       proto_tree_add_item(node_tree, hf_nbp_node_net, tvb, offset, 2, FALSE);
353       offset += 2;
354       proto_tree_add_item(node_tree, hf_nbp_node_node, tvb, offset, 1, FALSE);
355       offset++;
356       proto_tree_add_item(node_tree, hf_nbp_node_port, tvb, offset, 1, FALSE);
357       offset++;
358       proto_tree_add_item(node_tree, hf_nbp_node_enum, tvb, offset, 1, FALSE);
359       offset++;
360
361       offset = dissect_pascal_string(tvb, offset, node_tree, hf_nbp_node_object);
362       offset = dissect_pascal_string(tvb, offset, node_tree, hf_nbp_node_type);
363       offset = dissect_pascal_string(tvb, offset, node_tree, hf_nbp_node_zone);
364
365       proto_item_set_len(node_item, offset-soffset);
366     }
367   }
368
369   return;
370 }
371
372 static void
373 dissect_ddp_short(tvbuff_t *tvb, packet_info *pinfo, guint8 dnode,
374                   guint8 snode, proto_tree *tree)
375 {
376   guint16 len;
377   guint8  dport;
378   guint8  sport;
379   guint8  type;
380   proto_tree *ddp_tree = NULL;
381   proto_item *ti;
382   static struct atalk_ddp_addr src, dst;
383   tvbuff_t   *new_tvb;
384
385   if (check_col(pinfo->cinfo, COL_PROTOCOL))
386     col_set_str(pinfo->cinfo, COL_PROTOCOL, "DDP");
387   if (check_col(pinfo->cinfo, COL_INFO))
388     col_clear(pinfo->cinfo, COL_INFO);
389
390   if (tree) {
391     ti = proto_tree_add_item(tree, proto_ddp, tvb, 0, DDP_SHORT_HEADER_SIZE,
392                              FALSE);
393     ddp_tree = proto_item_add_subtree(ti, ett_ddp);
394   }
395   len = tvb_get_ntohs(tvb, 0);
396   if (tree)
397       proto_tree_add_uint(ddp_tree, hf_ddp_len, tvb, 0, 2, len);
398   dport = tvb_get_guint8(tvb, 2);
399   if (tree)
400     proto_tree_add_uint(ddp_tree, hf_ddp_dst_socket, tvb, 2, 1, dport);
401   sport = tvb_get_guint8(tvb, 3);
402   if (tree)
403     proto_tree_add_uint(ddp_tree, hf_ddp_src_socket, tvb, 3, 1, sport);
404   type = tvb_get_guint8(tvb, 4);
405   
406   src.net = 0;
407   src.node = snode;
408   src.port = sport;
409   dst.net = 0;
410   dst.node = dnode;
411   dst.port = dport;
412   SET_ADDRESS(&pinfo->net_src, AT_ATALK, sizeof src, (guint8 *)&src);
413   SET_ADDRESS(&pinfo->src, AT_ATALK, sizeof src, (guint8 *)&src);
414   SET_ADDRESS(&pinfo->net_dst, AT_ATALK, sizeof dst, (guint8 *)&dst);
415   SET_ADDRESS(&pinfo->dst, AT_ATALK, sizeof dst, (guint8 *)&dst);
416
417   if (check_col(pinfo->cinfo, COL_INFO)) {
418     col_add_str(pinfo->cinfo, COL_INFO,
419       val_to_str(type, op_vals, "Unknown DDP protocol (%02x)"));
420   }
421   if (tree)
422     proto_tree_add_uint(ddp_tree, hf_ddp_type, tvb, 4, 1, type);
423   
424   new_tvb = tvb_new_subset(tvb, DDP_SHORT_HEADER_SIZE, -1, -1);
425
426   if (!dissector_try_port(ddp_dissector_table, type, new_tvb, pinfo, tree))
427     call_dissector(data_handle,new_tvb, pinfo, tree);
428 }
429
430 static void
431 dissect_ddp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
432 {
433   e_ddp       ddp;
434   proto_tree *ddp_tree;
435   proto_item *ti;
436   static struct atalk_ddp_addr src, dst;
437   tvbuff_t   *new_tvb;
438
439   if (check_col(pinfo->cinfo, COL_PROTOCOL))
440     col_set_str(pinfo->cinfo, COL_PROTOCOL, "DDP");
441   if (check_col(pinfo->cinfo, COL_INFO))
442     col_clear(pinfo->cinfo, COL_INFO);
443
444   tvb_memcpy(tvb, (guint8 *)&ddp, 0, sizeof(e_ddp));
445   ddp.dnet=ntohs(ddp.dnet);
446   ddp.snet=ntohs(ddp.snet);
447   ddp.sum=ntohs(ddp.sum);
448   ddp.hops_len=ntohs(ddp.hops_len);
449   
450   src.net = ddp.snet;
451   src.node = ddp.snode;
452   src.port = ddp.sport;
453   dst.net = ddp.dnet;
454   dst.node = ddp.dnode;
455   dst.port = ddp.dport;
456   SET_ADDRESS(&pinfo->net_src, AT_ATALK, sizeof src, (guint8 *)&src);
457   SET_ADDRESS(&pinfo->src, AT_ATALK, sizeof src, (guint8 *)&src);
458   SET_ADDRESS(&pinfo->net_dst, AT_ATALK, sizeof dst, (guint8 *)&dst);
459   SET_ADDRESS(&pinfo->dst, AT_ATALK, sizeof dst, (guint8 *)&dst);
460
461   if (check_col(pinfo->cinfo, COL_INFO))
462     col_add_str(pinfo->cinfo, COL_INFO,
463       val_to_str(ddp.type, op_vals, "Unknown DDP protocol (%02x)"));
464   
465   if (tree) {
466     ti = proto_tree_add_item(tree, proto_ddp, tvb, 0, DDP_HEADER_SIZE,
467                              FALSE);
468     ddp_tree = proto_item_add_subtree(ti, ett_ddp);
469     proto_tree_add_uint(ddp_tree, hf_ddp_hopcount,   tvb, 0, 1,
470                         ddp_hops(ddp.hops_len));
471     proto_tree_add_uint(ddp_tree, hf_ddp_len,        tvb, 0, 2, 
472                         ddp_len(ddp.hops_len));
473     proto_tree_add_uint(ddp_tree, hf_ddp_checksum,   tvb, 2,  2,
474                         ddp.sum);
475     proto_tree_add_uint(ddp_tree, hf_ddp_dst_net,    tvb, 4,  2,
476                         ddp.dnet);
477     proto_tree_add_uint(ddp_tree, hf_ddp_src_net,    tvb, 6,  2,
478                         ddp.snet);
479     proto_tree_add_uint(ddp_tree, hf_ddp_dst_node,   tvb, 8,  1,
480                         ddp.dnode);
481     proto_tree_add_uint(ddp_tree, hf_ddp_src_node,   tvb, 9,  1,
482                         ddp.snode);
483     proto_tree_add_uint(ddp_tree, hf_ddp_dst_socket, tvb, 10, 1,
484                         ddp.dport);
485     proto_tree_add_uint(ddp_tree, hf_ddp_src_socket, tvb, 11, 1,
486                         ddp.sport);
487     proto_tree_add_uint(ddp_tree, hf_ddp_type,       tvb, 12, 1,
488                         ddp.type);  
489   }
490
491   new_tvb = tvb_new_subset(tvb, DDP_HEADER_SIZE, -1, -1);
492
493   if (!dissector_try_port(ddp_dissector_table, ddp.type, new_tvb, pinfo, tree))
494     call_dissector(data_handle,new_tvb, pinfo, tree);
495 }
496
497 static const value_string llap_type_vals[] = {
498   {0x01, "Short DDP"},
499   {0x02, "DDP" },
500   {0x81, "Enquiry"},
501   {0x82, "Acknowledgement"},
502   {0x84, "RTS"},
503   {0x85, "CTS"},
504   {0, NULL}
505 };
506
507 void
508 capture_llap(const u_char *pd, int len, packet_counts *ld)
509 {
510   ld->other++;
511 }
512
513 static void
514 dissect_llap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
515 {
516   guint8 dnode;
517   guint8 snode;
518   guint8 type;
519   proto_tree *llap_tree = NULL;
520   proto_item *ti;
521   tvbuff_t   *new_tvb;
522
523   if (check_col(pinfo->cinfo, COL_PROTOCOL))
524     col_set_str(pinfo->cinfo, COL_PROTOCOL, "LLAP");
525   if (check_col(pinfo->cinfo, COL_INFO))
526     col_clear(pinfo->cinfo, COL_INFO);
527
528   if (tree) {
529     ti = proto_tree_add_item(tree, proto_llap, tvb, 0, 3, FALSE);
530     llap_tree = proto_item_add_subtree(ti, ett_llap);
531   }
532
533   dnode = tvb_get_guint8(tvb, 0);
534   if (tree)  
535     proto_tree_add_uint(llap_tree, hf_llap_dst, tvb, 0, 1, dnode);
536   snode = tvb_get_guint8(tvb, 1);
537   if (tree)
538     proto_tree_add_uint(llap_tree, hf_llap_src, tvb, 1, 1, snode);
539   type = tvb_get_guint8(tvb, 2);
540   if (check_col(pinfo->cinfo, COL_INFO)) {
541     col_add_str(pinfo->cinfo, COL_INFO,
542       val_to_str(type, llap_type_vals, "Unknown LLAP type (%02x)"));
543   }
544   if (tree)
545     proto_tree_add_uint(llap_tree, hf_llap_type, tvb, 2, 1, type);
546   
547   new_tvb = tvb_new_subset(tvb, 3, -1, -1);
548
549   if (proto_is_protocol_enabled(proto_ddp)) {
550     pinfo->current_proto = "DDP";
551     switch (type) {
552
553     case 0x01:
554       dissect_ddp_short(new_tvb, pinfo, dnode, snode, tree);
555       return;
556
557     case 0x02:
558       dissect_ddp(new_tvb, pinfo, tree);
559       return;
560     }
561   }
562   call_dissector(data_handle,new_tvb, pinfo, tree);
563 }
564
565 void
566 proto_register_atalk(void)
567 {
568   static hf_register_info hf_llap[] = {
569     { &hf_llap_dst,
570       { "Destination Node",     "llap.dst",     FT_UINT8,  BASE_DEC, NULL, 0x0,
571         "", HFILL }},
572
573     { &hf_llap_src,
574       { "Source Node",          "llap.src",     FT_UINT8,  BASE_DEC, NULL, 0x0,
575         "", HFILL }},
576
577     { &hf_llap_type,
578       { "Type",                 "llap.type",    FT_UINT8,  BASE_HEX, VALS(llap_type_vals), 0x0,
579         "", HFILL }},
580   };
581
582   static hf_register_info hf_ddp[] = {
583     { &hf_ddp_hopcount,
584       { "Hop count",            "ddp.hopcount", FT_UINT8,  BASE_DEC, NULL, 0x0,
585         "", HFILL }},
586
587     { &hf_ddp_len,
588       { "Datagram length",      "ddp.len",      FT_UINT16, BASE_DEC, NULL, 0x0,
589         "", HFILL }},
590
591     { &hf_ddp_checksum,
592       { "Checksum",             "ddp.checksum", FT_UINT16, BASE_DEC, NULL, 0x0,
593         "", HFILL }},
594
595     { &hf_ddp_dst_net,
596       { "Destination Net",      "ddp.dst.net",  FT_UINT16, BASE_DEC, NULL, 0x0,
597         "", HFILL }},
598
599     { &hf_ddp_src_net,
600       { "Source Net",           "ddp.src.net",  FT_UINT16, BASE_DEC, NULL, 0x0,
601         "", HFILL }},
602
603     { &hf_ddp_dst_node,
604       { "Destination Node",     "ddp.dst.node", FT_UINT8,  BASE_DEC, NULL, 0x0,
605         "", HFILL }},
606
607     { &hf_ddp_src_node,
608       { "Source Node",          "ddp.src.node", FT_UINT8,  BASE_DEC, NULL, 0x0,
609         "", HFILL }},
610
611     { &hf_ddp_dst_socket,
612       { "Destination Socket",   "ddp.dst.socket", FT_UINT8,  BASE_DEC, NULL, 0x0,
613         "", HFILL }},
614
615     { &hf_ddp_src_socket,
616       { "Source Socket",        "ddp.src.socket", FT_UINT8,  BASE_DEC, NULL, 0x0,
617         "", HFILL }},
618
619     { &hf_ddp_type,
620       { "Protocol type",        "ddp.type",     FT_UINT8,  BASE_DEC, VALS(op_vals), 0x0,
621         "", HFILL }},
622   };
623
624   static hf_register_info hf_nbp[] = {
625     { &hf_nbp_op,
626       { "Operation",            "nbp.op",       FT_UINT8,  BASE_DEC, 
627                 VALS(nbp_op_vals), 0xF0, "Operation", HFILL }},
628     { &hf_nbp_info,
629       { "Info",         "nbp.info",     FT_UINT8,  BASE_HEX, 
630                 NULL, 0x0, "Info", HFILL }},
631     { &hf_nbp_count,
632       { "Count",                "nbp.count",    FT_UINT8,  BASE_DEC, 
633                 NULL, 0x0F, "Count", HFILL }},
634     { &hf_nbp_node_net,
635       { "Network",              "nbp.net",      FT_UINT16,  BASE_DEC, 
636                 NULL, 0x0, "Network", HFILL }},
637     { &hf_nbp_node_node,
638       { "Node",         "nbp.node",     FT_UINT8,  BASE_DEC, 
639                 NULL, 0x0, "Node", HFILL }},
640     { &hf_nbp_node_port,
641       { "Port",         "nbp.port",     FT_UINT8,  BASE_DEC, 
642                 NULL, 0x0, "Port", HFILL }},
643     { &hf_nbp_node_enum,
644       { "Enumerator",           "nbp.enum",     FT_UINT8,  BASE_DEC, 
645                 NULL, 0x0, "Enumerator", HFILL }},
646     { &hf_nbp_node_object,
647       { "Object",               "nbp.object",   FT_STRING,  BASE_DEC, 
648                 NULL, 0x0, "Object", HFILL }},
649     { &hf_nbp_node_type,
650       { "Type",         "nbp.type",     FT_STRING,  BASE_DEC, 
651                 NULL, 0x0, "Type", HFILL }},
652     { &hf_nbp_node_zone,
653       { "Zone",         "nbp.zone",     FT_STRING,  BASE_DEC, 
654                 NULL, 0x0, "Zone", HFILL }},
655     { &hf_nbp_tid,
656       { "Transaction ID",               "nbp.tid",      FT_UINT8,  BASE_DEC, 
657                 NULL, 0x0, "Transaction ID", HFILL }}
658   };
659
660   static hf_register_info hf_rtmp[] = {
661     { &hf_rtmp_net,
662       { "Net",          "rtmp.net",     FT_UINT16,  BASE_DEC, 
663                 NULL, 0x0, "Net", HFILL }},
664     { &hf_rtmp_node,
665       { "Node",         "nbp.nodeid",   FT_UINT8,  BASE_DEC, 
666                 NULL, 0x0, "Node", HFILL }},
667     { &hf_rtmp_node_len,
668       { "Node Length",          "nbp.nodeid.length",    FT_UINT8,  BASE_DEC, 
669                 NULL, 0x0, "Node Length", HFILL }},
670     { &hf_rtmp_tuple_net,
671       { "Net",          "rtmp.tuple.net",       FT_UINT16,  BASE_DEC, 
672                 NULL, 0x0, "Net", HFILL }},
673     { &hf_rtmp_tuple_range_start,
674       { "Range Start",          "rtmp.tuple.range_start",       FT_UINT16,  BASE_DEC, 
675                 NULL, 0x0, "Range Start", HFILL }},
676     { &hf_rtmp_tuple_range_end,
677       { "Range End",            "rtmp.tuple.range_end", FT_UINT16,  BASE_DEC, 
678                 NULL, 0x0, "Range End", HFILL }},
679     { &hf_rtmp_tuple_dist,
680       { "Distance",             "rtmp.tuple.dist",      FT_UINT16,  BASE_DEC, 
681                 NULL, 0x0, "Distance", HFILL }},
682     { &hf_rtmp_function,
683       { "Function",             "rtmp.function",        FT_UINT8,  BASE_DEC, 
684                 VALS(rtmp_function_vals), 0x0, "Request Function", HFILL }}
685   };
686
687
688   static gint *ett[] = {
689         &ett_llap,
690         &ett_ddp,
691         &ett_nbp,
692         &ett_nbp_info,
693         &ett_nbp_node,
694         &ett_pstring,
695         &ett_rtmp,
696         &ett_rtmp_tuple
697   };
698
699   proto_llap = proto_register_protocol("LocalTalk Link Access Protocol", "LLAP", "llap");
700   proto_register_field_array(proto_llap, hf_llap, array_length(hf_llap));
701
702   proto_ddp = proto_register_protocol("Datagram Delivery Protocol", "DDP", "ddp");
703   proto_register_field_array(proto_ddp, hf_ddp, array_length(hf_ddp));
704
705   proto_nbp = proto_register_protocol("Name Binding Protocol", "NBP", "nbp");
706   proto_register_field_array(proto_nbp, hf_nbp, array_length(hf_nbp));
707
708   proto_rtmp = proto_register_protocol("Routing Table Maintenance Protocol",
709                                        "RTMP", "rtmp");
710   proto_register_field_array(proto_rtmp, hf_rtmp, array_length(hf_rtmp));
711
712   proto_register_subtree_array(ett, array_length(ett));
713
714   /* subdissector code */
715   ddp_dissector_table = register_dissector_table("ddp.type", "DDP packet type",
716                                                  FT_UINT8, BASE_HEX);
717 }
718
719 void
720 proto_reg_handoff_atalk(void)
721 {
722   dissector_handle_t ddp_handle, nbp_handle, rtmp_request_handle;
723   dissector_handle_t rtmp_data_handle, llap_handle;
724
725   ddp_handle = create_dissector_handle(dissect_ddp, proto_ddp);
726   dissector_add("ethertype", ETHERTYPE_ATALK, ddp_handle);
727   dissector_add("chdlctype", ETHERTYPE_ATALK, ddp_handle);
728   dissector_add("ppp.protocol", PPP_AT, ddp_handle);
729   dissector_add("null.type", BSD_AF_APPLETALK, ddp_handle);
730
731   nbp_handle = create_dissector_handle(dissect_nbp, proto_nbp);
732   dissector_add("ddp.type", DDP_NBP, nbp_handle);
733
734   rtmp_request_handle = create_dissector_handle(dissect_rtmp_request, proto_rtmp);
735   rtmp_data_handle = create_dissector_handle(dissect_rtmp_data, proto_rtmp);
736   dissector_add("ddp.type", DDP_RTMPREQ, rtmp_request_handle);
737   dissector_add("ddp.type", DDP_RTMPDATA, rtmp_data_handle);
738
739   llap_handle = create_dissector_handle(dissect_llap, proto_llap);
740   dissector_add("wtap_encap", WTAP_ENCAP_LOCALTALK, llap_handle);
741
742   data_handle = find_dissector("data");
743 }