2 * Routines for Appletalk packet disassembly (DDP, currently).
4 * $Id: packet-atalk.c,v 1.67 2002/04/28 22:19:49 guy Exp $
6 * Simon Wilkinson <sxw@dcs.ed.ac.uk>
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
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.
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.
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.
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
35 #ifdef HAVE_NETINET_IN_H
36 # include <netinet/in.h>
40 #include <epan/packet.h>
44 #include <epan/atalk-utils.h>
45 #include <epan/conversation.h>
47 #include "packet-afp.h"
49 static dissector_handle_t afp_handle;
51 static int proto_llap = -1;
52 static int hf_llap_dst = -1;
53 static int hf_llap_src = -1;
54 static int hf_llap_type = -1;
56 static int proto_ddp = -1;
57 static int hf_ddp_hopcount = -1;
58 static int hf_ddp_len = -1;
59 static int hf_ddp_checksum = -1;
60 static int hf_ddp_dst_net = -1;
61 static int hf_ddp_src_net = -1;
62 static int hf_ddp_dst_node = -1;
63 static int hf_ddp_src_node = -1;
64 static int hf_ddp_dst_socket = -1;
65 static int hf_ddp_src_socket = -1;
66 static int hf_ddp_type = -1;
69 /* --------------------------------------
70 * ATP protocol parameters
71 * from netatalk/include/atalk/atp.h
73 #define ATP_MAXDATA (578+4) /* maximum ATP data size */
74 #define ATP_BUFSIZ 587 /* maximum packet size */
75 #define ATP_HDRSIZE 5 /* includes DDP type field */
77 #define ATP_TRELMASK 0x07 /* mask all but TREL */
78 #define ATP_RELTIME 30 /* base release timer (in secs) */
80 #define ATP_TREL30 0x0 /* release time codes */
81 #define ATP_TREL1M 0x1 /* these are passed in flags of */
82 #define ATP_TREL2M 0x2 /* atp_sreq call, and set in the */
83 #define ATP_TREL4M 0x3 /* packet control info. */
84 #define ATP_TREL8M 0x4
86 /* flags for ATP options (and control byte)
88 #define ATP_XO 0x20 /* (1<<5) eXactly Once mode */
89 #define ATP_EOM 0x10 /* (1<<4) End Of Message */
90 #define ATP_STS 0x08 /* (1<<3) Transaction Status */
94 #define ATP_FUNCMASK (3<<6) /* mask all but function */
96 #define ATP_TREQ 1 /* (1<<6) Trans. REQuest */
97 #define ATP_TRESP 2 /* (2<<6) Trans. RESPonse */
98 #define ATP_TREL 3 /* (3<<6) Trans. RELease */
100 /* ------------------------- */
101 static dissector_handle_t asp_handle;
103 static int proto_atp = -1;
104 static int hf_atp_ctrlinfo = -1; /* u_int8_t control information */
105 static int hf_atp_function = -1; /* bits 7,6 function */
106 static int hf_atp_xo = -1; /* bit 5 exactly-once */
107 static int hf_atp_eom = -1; /* bit 4 end-of-message */
108 static int hf_atp_sts = -1; /* bit 3 send transaction status */
109 static int hf_atp_treltimer = -1; /* bits 2,1,0 TRel timeout indicator */
111 static int hf_atp_bitmap = -1; /* u_int8_t bitmap or sequence number */
112 static int hf_atp_tid = -1; /* u_int16_t transaction id. */
114 /* --------------------------------
115 * from netatalk/include/atalk/ats.h
118 #define ASPFUNC_CLOSE 1
119 #define ASPFUNC_CMD 2
120 #define ASPFUNC_STAT 3
121 #define ASPFUNC_OPEN 4
122 #define ASPFUNC_TICKLE 5
123 #define ASPFUNC_WRITE 6
124 #define ASPFUNC_WRTCONT 7
125 #define ASPFUNC_ATTN 8
128 #define ASPERR_OK 0x0000
129 #define ASPERR_BADVERS 0xfbd6
130 #define ASPERR_BUFSMALL 0xfbd5
131 #define ASPERR_NOSESS 0xfbd4
132 #define ASPERR_NOSERV 0xfbd3
133 #define ASPERR_PARM 0xfbd2
134 #define ASPERR_SERVBUSY 0xfbd1
135 #define ASPERR_SESSCLOS 0xfbd0
136 #define ASPERR_SIZERR 0xfbcf
137 #define ASPERR_TOOMANY 0xfbce
138 #define ASPERR_NOACK 0xfbcd
140 static int proto_asp = -1;
141 static int hf_asp_func = -1;
142 static int hf_asp_error = -1;
144 static guint asp_packet_init_count = 200;
147 guint32 conversation;
155 static GHashTable *asp_request_hash = NULL;
156 static GMemChunk *asp_request_keys = NULL;
157 static GMemChunk *asp_request_vals = NULL;
160 static gint asp_equal (gconstpointer v, gconstpointer v2)
162 asp_request_key *val1 = (asp_request_key*)v;
163 asp_request_key *val2 = (asp_request_key*)v2;
165 if (val1->conversation == val2->conversation &&
166 val1->seq == val2->seq) {
172 static guint asp_hash (gconstpointer v)
174 asp_request_key *asp_key = (asp_request_key*)v;
178 /* ------------------------------------ */
179 static int proto_nbp = -1;
180 static int hf_nbp_op = -1;
181 static int hf_nbp_info = -1;
182 static int hf_nbp_count = -1;
183 static int hf_nbp_tid = -1;
185 static int hf_nbp_node_net = -1;
186 static int hf_nbp_node_port = -1;
187 static int hf_nbp_node_node = -1;
188 static int hf_nbp_node_enum = -1;
189 static int hf_nbp_node_object = -1;
190 static int hf_nbp_node_type = -1;
191 static int hf_nbp_node_zone = -1;
193 static int proto_rtmp = -1;
194 static int hf_rtmp_net = -1;
195 static int hf_rtmp_node_len = -1;
196 static int hf_rtmp_node = -1;
197 static int hf_rtmp_tuple_net = -1;
198 static int hf_rtmp_tuple_range_start = -1;
199 static int hf_rtmp_tuple_range_end = -1;
200 static int hf_rtmp_tuple_dist = -1;
201 static int hf_rtmp_function = -1;
203 static gint ett_atp = -1;
205 static gint ett_atp_info = -1;
206 static gint ett_asp = -1;
208 static gint ett_nbp = -1;
209 static gint ett_nbp_info = -1;
210 static gint ett_nbp_node = -1;
211 static gint ett_rtmp = -1;
212 static gint ett_rtmp_tuple = -1;
213 static gint ett_ddp = -1;
214 static gint ett_llap = -1;
215 static gint ett_pstring = -1;
217 static dissector_table_t ddp_dissector_table;
219 static dissector_handle_t data_handle;
221 #define DDP_SHORT_HEADER_SIZE 5
224 * P = Padding, H = Hops, L = Len
228 * Assumes the argument is in host byte order.
230 #define ddp_hops(x) ( ( x >> 10) & 0x3C )
231 #define ddp_len(x) ( x & 0x03ff )
232 typedef struct _e_ddp {
233 guint16 hops_len; /* combines pad, hops, and len */
234 guint16 sum,dnet,snet;
240 #define DDP_HEADER_SIZE 13
243 static const value_string op_vals[] = {
244 {DDP_RTMPDATA, "AppleTalk Routing Table response or data" },
245 {DDP_NBP, "AppleTalk Name Binding Protocol packet"},
246 {DDP_ATP, "AppleTalk Transaction Protocol packet"},
247 {DDP_AEP, "AppleTalk Echo Protocol packet"},
248 {DDP_RTMPREQ, "AppleTalk Routing Table request"},
249 {DDP_ZIP, "AppleTalk Zone Information Protocol packet"},
250 {DDP_ADSP, "AppleTalk Data Stream Protocol"},
251 {DDP_EIGRP, "Cisco EIGRP for AppleTalk"},
255 static const value_string rtmp_function_vals[] = {
257 {2, "Route Data Request (split horizon processed)"},
258 {3, "Route Data Request (no split horizon processing)"},
263 #define NBP_FORWARD 4
266 static const value_string nbp_op_vals[] = {
267 {NBP_LOOKUP, "lookup"},
268 {NBP_FORWARD, "forward request"},
269 {NBP_REPLY, "reply"},
273 static const value_string atp_function_vals[] = {
274 {ATP_TREQ ,"REQuest"},
275 {ATP_TRESP ,"RESPonse"},
276 {ATP_TREL ,"RELease"},
280 static const value_string atp_trel_timer_vals[] = {
291 static const value_string asp_func_vals[] = {
292 {ASPFUNC_CLOSE, "CloseSession" },
293 {ASPFUNC_CMD, "Command" },
294 {ASPFUNC_STAT, "GetStatus" },
295 {ASPFUNC_OPEN, "OpenSession" },
296 {ASPFUNC_TICKLE, "Tickle" },
297 {ASPFUNC_WRITE, "Write" },
298 {ASPFUNC_WRTCONT, "Write Cont" },
299 {ASPFUNC_ATTN, "Attention" },
302 const value_string asp_error_vals[] = {
303 {AFP_OK , "success"},
304 {AFPERR_ACCESS , "permission denied" },
305 {AFPERR_AUTHCONT , "logincont" },
306 {AFPERR_BADUAM , "uam doesn't exist" },
307 {AFPERR_BADVERS , "bad afp version number" },
308 {AFPERR_BITMAP , "invalid bitmap" },
309 {AFPERR_CANTMOVE , "can't move file" },
310 {AFPERR_DENYCONF , "file synchronization locks conflict" },
311 {AFPERR_DIRNEMPT , "directory not empty" },
312 {AFPERR_DFULL , "disk full" },
313 {AFPERR_EOF , "end of file" },
314 {AFPERR_BUSY , "FileBusy" },
315 {AFPERR_FLATVOL , "volume doesn't support directories" },
316 {AFPERR_NOITEM , "ItemNotFound" },
317 {AFPERR_LOCK , "LockErr" },
318 {AFPERR_MISC , "misc. err" },
319 {AFPERR_NLOCK , "no more locks" },
320 {AFPERR_NOSRVR , "no response by server at that address" },
321 {AFPERR_EXIST , "object already exists" },
322 {AFPERR_NOOBJ , "object not found" },
323 {AFPERR_PARAM , "parameter error" },
324 {AFPERR_NORANGE , "no range lock" },
325 {AFPERR_RANGEOVR , "range overlap" },
326 {AFPERR_SESSCLOS , "session closed" },
327 {AFPERR_NOTAUTH , "user not authenticated" },
328 {AFPERR_NOOP , "command not supported" },
329 {AFPERR_BADTYPE , "object is the wrong type" },
330 {AFPERR_NFILE , "too many files open" },
331 {AFPERR_SHUTDOWN , "server is going down" },
332 {AFPERR_NORENAME , "can't rename" },
333 {AFPERR_NODIR , "couldn't find directory" },
334 {AFPERR_ITYPE , "wrong icon type" },
335 {AFPERR_VLOCK , "volume locked" },
336 {AFPERR_OLOCK , "object locked" },
337 {AFPERR_CTNSHRD , "share point contains a share point" },
338 {AFPERR_NOID , "file thread not found" },
339 {AFPERR_EXISTID , "file already has an id" },
340 {AFPERR_DIFFVOL , "different volume" },
341 {AFPERR_CATCHNG , "catalog has changed" },
342 {AFPERR_SAMEOBJ , "source file == destination file" },
343 {AFPERR_BADID , "non-existent file id" },
344 {AFPERR_PWDSAME , "same password/can't change password" },
345 {AFPERR_PWDSHORT , "password too short" },
346 {AFPERR_PWDEXPR , "password expired" },
347 {AFPERR_INSHRD , "folder being shared is inside a shared folder." },
348 {AFPERR_INTRASH , "shared folder in trash." },
349 {AFPERR_PWDCHNG , "password needs to be changed" },
350 {AFPERR_PWDPOLCY , "password fails policy check" },
351 {AFPERR_USRLOGIN , "user already logged on" },
355 * XXX - do this with an FT_UINT_STRING?
356 * Unfortunately, you can't extract from an FT_UINT_STRING the string,
357 * which we'd want to do in order to put it into the "Data:" portion.
359 * Are these always in the Mac extended character set?
361 int dissect_pascal_string(tvbuff_t *tvb, int offset, proto_tree *tree,
366 len = tvb_get_guint8(tvb, offset);
376 * XXX - if we could do this inside the protocol tree
377 * code, we could perhaps avoid allocating and freeing
378 * this string buffer.
380 tmp = g_malloc( len+1 );
381 tvb_memcpy(tvb, tmp, offset, len);
383 item = proto_tree_add_string(tree, hf_index, tvb, offset-1, len+1, tmp);
385 subtree = proto_item_add_subtree(item, ett_pstring);
386 proto_tree_add_text(subtree, tvb, offset-1, 1, "Length: %d", len);
387 proto_tree_add_text(subtree, tvb, offset, len, "Data: %s", tmp);
397 dissect_rtmp_request(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
398 proto_tree *rtmp_tree;
402 if (check_col(pinfo->cinfo, COL_PROTOCOL))
403 col_set_str(pinfo->cinfo, COL_PROTOCOL, "RTMP");
404 if (check_col(pinfo->cinfo, COL_INFO))
405 col_clear(pinfo->cinfo, COL_INFO);
407 function = tvb_get_guint8(tvb, 0);
409 if (check_col(pinfo->cinfo, COL_INFO))
410 col_add_fstr(pinfo->cinfo, COL_INFO, "%s",
411 val_to_str(function, rtmp_function_vals, "Unknown function (%02)"));
414 ti = proto_tree_add_item(tree, proto_rtmp, tvb, 0, 1, FALSE);
415 rtmp_tree = proto_item_add_subtree(ti, ett_rtmp);
417 proto_tree_add_uint(rtmp_tree, hf_rtmp_function, tvb, 0, 1, function);
422 dissect_rtmp_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
423 proto_tree *rtmp_tree;
427 guint8 nodelen,nodelen_bits;
428 guint16 node; /* might be more than 8 bits */
431 if (check_col(pinfo->cinfo, COL_PROTOCOL))
432 col_set_str(pinfo->cinfo, COL_PROTOCOL, "RTMP");
433 if (check_col(pinfo->cinfo, COL_INFO))
434 col_clear(pinfo->cinfo, COL_INFO);
436 net = tvb_get_ntohs(tvb, offset);
437 nodelen_bits = tvb_get_guint8(tvb, offset+2);
438 if ( nodelen_bits <= 8 ) {
439 node = tvb_get_guint8(tvb, offset)+1;
442 node = tvb_get_ntohs(tvb, offset);
446 if (check_col(pinfo->cinfo, COL_INFO))
447 col_add_fstr(pinfo->cinfo, COL_INFO, "Net: %u Node Len: %u Node: %u",
448 net, nodelen_bits, node);
451 ti = proto_tree_add_item(tree, proto_rtmp, tvb, offset, -1, FALSE);
452 rtmp_tree = proto_item_add_subtree(ti, ett_rtmp);
454 proto_tree_add_uint(rtmp_tree, hf_rtmp_net, tvb, offset, 2, net);
455 proto_tree_add_uint(rtmp_tree, hf_rtmp_node_len, tvb, offset+2, 1,
457 proto_tree_add_uint(rtmp_tree, hf_rtmp_node, tvb, offset+3, nodelen,
459 offset += 3 + nodelen;
462 while (tvb_offset_exists(tvb, offset)) {
463 proto_tree *tuple_item, *tuple_tree;
466 guint16 tuple_range_end;
468 tuple_net = tvb_get_ntohs(tvb, offset);
469 tuple_dist = tvb_get_guint8(tvb, offset+2);
471 if (tuple_dist & 0x80) {
472 tuple_range_end = tvb_get_ntohs(tvb, offset+3);
473 tuple_item = proto_tree_add_text(rtmp_tree, tvb, offset, 6,
474 "Tuple %d: Range Start: %u Dist: %u Range End: %u",
475 i, tuple_net, tuple_dist&0x7F, tuple_range_end);
477 tuple_item = proto_tree_add_text(rtmp_tree, tvb, offset, 3,
478 "Tuple %d: Net: %u Dist: %u",
479 i, tuple_net, tuple_dist);
481 tuple_tree = proto_item_add_subtree(tuple_item, ett_rtmp_tuple);
483 if (tuple_dist & 0x80) {
484 proto_tree_add_uint(tuple_tree, hf_rtmp_tuple_range_start, tvb, offset, 2,
487 proto_tree_add_uint(tuple_tree, hf_rtmp_tuple_net, tvb, offset, 2,
490 proto_tree_add_uint(tuple_tree, hf_rtmp_tuple_dist, tvb, offset+2, 1,
493 if (tuple_dist & 0x80) {
495 * Extended network tuple.
497 proto_tree_add_item(tuple_tree, hf_rtmp_tuple_range_end, tvb, offset+3, 2,
509 dissect_nbp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
510 proto_tree *nbp_tree;
511 proto_tree *nbp_info_tree;
512 proto_item *ti, *info_item;
518 if (check_col(pinfo->cinfo, COL_PROTOCOL))
519 col_set_str(pinfo->cinfo, COL_PROTOCOL, "NBP");
520 if (check_col(pinfo->cinfo, COL_INFO))
521 col_clear(pinfo->cinfo, COL_INFO);
523 info = tvb_get_guint8(tvb, offset);
527 if (check_col(pinfo->cinfo, COL_INFO))
528 col_add_fstr(pinfo->cinfo, COL_INFO, "Op: %s Count: %u",
529 val_to_str(op, nbp_op_vals, "Unknown (0x%01x)"), count);
532 ti = proto_tree_add_item(tree, proto_nbp, tvb, offset, -1, FALSE);
533 nbp_tree = proto_item_add_subtree(ti, ett_nbp);
535 info_item = proto_tree_add_uint_format(nbp_tree, hf_nbp_info, tvb, offset, 1,
537 "Info: 0x%01X Operation: %s Count: %u", info,
538 val_to_str(op, nbp_op_vals, "Unknown (0x%01X)"),
540 nbp_info_tree = proto_item_add_subtree(info_item, ett_nbp_info);
541 proto_tree_add_uint(nbp_info_tree, hf_nbp_op, tvb, offset, 1, info);
542 proto_tree_add_uint(nbp_info_tree, hf_nbp_count, tvb, offset, 1, info);
543 proto_tree_add_item(nbp_tree, hf_nbp_tid, tvb, offset+1, 1, FALSE);
546 for (i=0; i<count; i++) {
547 proto_tree *node_item,*node_tree;
548 int soffset = offset;
550 node_item = proto_tree_add_text(nbp_tree, tvb, offset, -1,
552 node_tree = proto_item_add_subtree(node_item, ett_nbp_node);
554 proto_tree_add_item(node_tree, hf_nbp_node_net, tvb, offset, 2, FALSE);
556 proto_tree_add_item(node_tree, hf_nbp_node_node, tvb, offset, 1, FALSE);
558 proto_tree_add_item(node_tree, hf_nbp_node_port, tvb, offset, 1, FALSE);
560 proto_tree_add_item(node_tree, hf_nbp_node_enum, tvb, offset, 1, FALSE);
563 offset = dissect_pascal_string(tvb, offset, node_tree, hf_nbp_node_object);
564 offset = dissect_pascal_string(tvb, offset, node_tree, hf_nbp_node_type);
565 offset = dissect_pascal_string(tvb, offset, node_tree, hf_nbp_node_zone);
567 proto_item_set_len(node_item, offset-soffset);
574 /* -----------------------------
575 FIXME : need desegmentation
576 atp.function == 0x80 (response)
578 until atp.option == 0x10 (end of message)
581 dissect_atp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
582 proto_tree *atp_tree;
584 proto_tree *atp_info_tree;
585 proto_item *info_item;
590 struct aspinfo aspinfo;
594 if (check_col(pinfo->cinfo, COL_PROTOCOL))
595 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ATP");
596 if (check_col(pinfo->cinfo, COL_INFO))
597 col_clear(pinfo->cinfo, COL_INFO);
599 ctrlinfo = tvb_get_guint8(tvb, offset);
601 tid = tvb_get_ntohs(tvb, offset +2);
603 if (check_col(pinfo->cinfo, COL_INFO)) {
604 col_add_fstr(pinfo->cinfo, COL_INFO, "%s transaction %d",
605 val_to_str(op, atp_function_vals, "Unknown (0x%01x)"),
608 aspinfo.reply = (0x80 == (ctrlinfo & ATP_FUNCMASK))?1:0;
609 aspinfo.release = (0xC0 == (ctrlinfo & ATP_FUNCMASK))?1:0;
615 ti = proto_tree_add_item(tree, proto_atp, tvb, offset, -1, FALSE);
616 atp_tree = proto_item_add_subtree(ti, ett_atp);
617 proto_item_set_len(atp_tree, ATP_HDRSIZE -1);
619 info_item = proto_tree_add_item(atp_tree, hf_atp_ctrlinfo, tvb, offset, 1, FALSE);
620 atp_info_tree = proto_item_add_subtree(info_item, ett_atp_info);
622 proto_tree_add_item(atp_info_tree, hf_atp_function, tvb, offset, 1, FALSE);
623 proto_tree_add_item(atp_info_tree, hf_atp_xo, tvb, offset, 1, FALSE);
624 proto_tree_add_item(atp_info_tree, hf_atp_eom, tvb, offset, 1, FALSE);
625 proto_tree_add_item(atp_info_tree, hf_atp_sts, tvb, offset, 1, FALSE);
626 if ((ctrlinfo & (ATP_FUNCMASK|ATP_XO)) == (0x40|ATP_XO)) {
627 /* TReq with XO set */
628 proto_tree_add_item(atp_info_tree, hf_atp_treltimer, tvb, offset, 1, FALSE);
631 if (!aspinfo.reply) {
632 guint8 bitmap = tvb_get_guint8(tvb, offset +1);
640 proto_tree_add_text(atp_tree, tvb, offset +1, 1,
641 "Bitmap: 0x%02x %d packet(s) max", bitmap, nbe);
644 proto_tree_add_item(atp_tree, hf_atp_bitmap, tvb, offset +1, 1, FALSE);
646 proto_tree_add_item(atp_tree, hf_atp_tid, tvb, offset +2, 2, FALSE);
649 pinfo->private_data = &aspinfo;
650 len = tvb_reported_length_remaining(tvb,ATP_HDRSIZE -1);
651 new_tvb = tvb_new_subset(tvb, ATP_HDRSIZE -1,-1,len);
652 call_dissector(asp_handle, new_tvb, pinfo, tree);
657 /* ----------------------------- */
659 dissect_asp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
661 struct aspinfo *aspinfo = pinfo->private_data;
663 proto_tree *asp_tree = NULL;
668 conversation_t *conversation;
669 asp_request_key request_key, *new_request_key;
670 asp_request_val *request_val;
672 if (check_col(pinfo->cinfo, COL_PROTOCOL))
673 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ASP");
674 if (check_col(pinfo->cinfo, COL_INFO))
675 col_clear(pinfo->cinfo, COL_INFO);
677 conversation = find_conversation(&pinfo->src, &pinfo->dst, pinfo->ptype,
678 pinfo->srcport, pinfo->destport, 0);
680 if (conversation == NULL)
682 conversation = conversation_new(&pinfo->src, &pinfo->dst,
683 pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
686 request_key.conversation = conversation->index;
687 request_key.seq = aspinfo->seq;
689 request_val = (asp_request_val *) g_hash_table_lookup(
690 asp_request_hash, &request_key);
692 if (!request_val && !aspinfo->reply && !aspinfo->release) {
693 fn = tvb_get_guint8(tvb, offset);
694 new_request_key = g_mem_chunk_alloc(asp_request_keys);
695 *new_request_key = request_key;
697 request_val = g_mem_chunk_alloc(asp_request_vals);
698 request_val->command = fn;
700 g_hash_table_insert(asp_request_hash, new_request_key,
708 fn = request_val->command;
710 if (check_col(pinfo->cinfo, COL_INFO)) {
712 col_add_fstr(pinfo->cinfo, COL_INFO, "Reply tid %d",aspinfo->seq);
713 else if (aspinfo->release)
714 col_add_fstr(pinfo->cinfo, COL_INFO, "Release tid %d",aspinfo->seq);
716 col_add_fstr(pinfo->cinfo, COL_INFO, "Function: %s tid %d",
717 val_to_str(fn, asp_func_vals, "Unknown (0x%01x)"), aspinfo->seq);
721 ti = proto_tree_add_item(tree, proto_asp, tvb, offset, -1, FALSE);
722 asp_tree = proto_item_add_subtree(ti, ett_asp);
723 if (!aspinfo->reply && !aspinfo->release) {
724 proto_tree_add_item(asp_tree, hf_asp_func, tvb, offset, 1, FALSE);
726 else { /* error code */
727 error = tvb_get_ntohl(tvb, offset);
729 proto_tree_add_item(asp_tree, hf_asp_error, tvb, offset, 4, FALSE);
732 aspinfo->command = fn;
734 len = tvb_reported_length_remaining(tvb,offset);
735 if (!aspinfo->release &&
736 (fn == ASPFUNC_CMD || fn == ASPFUNC_WRITE)) {
740 proto_item_set_len(asp_tree, 4);
741 new_tvb = tvb_new_subset(tvb, offset,-1,len);
742 call_dissector(afp_handle, new_tvb, pinfo, tree);
745 call_dissector(data_handle,tvb_new_subset(tvb, offset,-1,len), pinfo, tree);
751 dissect_ddp_short(tvbuff_t *tvb, packet_info *pinfo, guint8 dnode,
752 guint8 snode, proto_tree *tree)
758 proto_tree *ddp_tree = NULL;
760 static struct atalk_ddp_addr src, dst;
763 if (check_col(pinfo->cinfo, COL_PROTOCOL))
764 col_set_str(pinfo->cinfo, COL_PROTOCOL, "DDP");
765 if (check_col(pinfo->cinfo, COL_INFO))
766 col_clear(pinfo->cinfo, COL_INFO);
769 ti = proto_tree_add_item(tree, proto_ddp, tvb, 0, DDP_SHORT_HEADER_SIZE,
771 ddp_tree = proto_item_add_subtree(ti, ett_ddp);
773 len = tvb_get_ntohs(tvb, 0);
775 proto_tree_add_uint(ddp_tree, hf_ddp_len, tvb, 0, 2, len);
776 dport = tvb_get_guint8(tvb, 2);
778 proto_tree_add_uint(ddp_tree, hf_ddp_dst_socket, tvb, 2, 1, dport);
779 sport = tvb_get_guint8(tvb, 3);
781 proto_tree_add_uint(ddp_tree, hf_ddp_src_socket, tvb, 3, 1, sport);
782 type = tvb_get_guint8(tvb, 4);
790 SET_ADDRESS(&pinfo->net_src, AT_ATALK, sizeof src, (guint8 *)&src);
791 SET_ADDRESS(&pinfo->src, AT_ATALK, sizeof src, (guint8 *)&src);
792 SET_ADDRESS(&pinfo->net_dst, AT_ATALK, sizeof dst, (guint8 *)&dst);
793 SET_ADDRESS(&pinfo->dst, AT_ATALK, sizeof dst, (guint8 *)&dst);
795 if (check_col(pinfo->cinfo, COL_INFO)) {
796 col_add_str(pinfo->cinfo, COL_INFO,
797 val_to_str(type, op_vals, "Unknown DDP protocol (%02x)"));
800 proto_tree_add_uint(ddp_tree, hf_ddp_type, tvb, 4, 1, type);
802 new_tvb = tvb_new_subset(tvb, DDP_SHORT_HEADER_SIZE, -1, -1);
804 if (!dissector_try_port(ddp_dissector_table, type, new_tvb, pinfo, tree))
805 call_dissector(data_handle,new_tvb, pinfo, tree);
809 dissect_ddp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
812 proto_tree *ddp_tree;
814 static struct atalk_ddp_addr src, dst;
817 if (check_col(pinfo->cinfo, COL_PROTOCOL))
818 col_set_str(pinfo->cinfo, COL_PROTOCOL, "DDP");
819 if (check_col(pinfo->cinfo, COL_INFO))
820 col_clear(pinfo->cinfo, COL_INFO);
822 tvb_memcpy(tvb, (guint8 *)&ddp, 0, sizeof(e_ddp));
823 ddp.dnet=ntohs(ddp.dnet);
824 ddp.snet=ntohs(ddp.snet);
825 ddp.sum=ntohs(ddp.sum);
826 ddp.hops_len=ntohs(ddp.hops_len);
829 src.node = ddp.snode;
830 src.port = ddp.sport;
832 dst.node = ddp.dnode;
833 dst.port = ddp.dport;
834 SET_ADDRESS(&pinfo->net_src, AT_ATALK, sizeof src, (guint8 *)&src);
835 SET_ADDRESS(&pinfo->src, AT_ATALK, sizeof src, (guint8 *)&src);
836 SET_ADDRESS(&pinfo->net_dst, AT_ATALK, sizeof dst, (guint8 *)&dst);
837 SET_ADDRESS(&pinfo->dst, AT_ATALK, sizeof dst, (guint8 *)&dst);
839 if (check_col(pinfo->cinfo, COL_INFO))
840 col_add_str(pinfo->cinfo, COL_INFO,
841 val_to_str(ddp.type, op_vals, "Unknown DDP protocol (%02x)"));
844 ti = proto_tree_add_item(tree, proto_ddp, tvb, 0, DDP_HEADER_SIZE,
846 ddp_tree = proto_item_add_subtree(ti, ett_ddp);
847 proto_tree_add_uint(ddp_tree, hf_ddp_hopcount, tvb, 0, 1,
848 ddp_hops(ddp.hops_len));
849 proto_tree_add_uint(ddp_tree, hf_ddp_len, tvb, 0, 2,
850 ddp_len(ddp.hops_len));
851 proto_tree_add_uint(ddp_tree, hf_ddp_checksum, tvb, 2, 2,
853 proto_tree_add_uint(ddp_tree, hf_ddp_dst_net, tvb, 4, 2,
855 proto_tree_add_uint(ddp_tree, hf_ddp_src_net, tvb, 6, 2,
857 proto_tree_add_uint(ddp_tree, hf_ddp_dst_node, tvb, 8, 1,
859 proto_tree_add_uint(ddp_tree, hf_ddp_src_node, tvb, 9, 1,
861 proto_tree_add_uint(ddp_tree, hf_ddp_dst_socket, tvb, 10, 1,
863 proto_tree_add_uint(ddp_tree, hf_ddp_src_socket, tvb, 11, 1,
865 proto_tree_add_uint(ddp_tree, hf_ddp_type, tvb, 12, 1,
869 new_tvb = tvb_new_subset(tvb, DDP_HEADER_SIZE, -1, -1);
871 if (!dissector_try_port(ddp_dissector_table, ddp.type, new_tvb, pinfo, tree))
872 call_dissector(data_handle,new_tvb, pinfo, tree);
875 static const value_string llap_type_vals[] = {
879 {0x82, "Acknowledgement"},
886 capture_llap(packet_counts *ld)
892 dissect_llap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
897 proto_tree *llap_tree = NULL;
901 if (check_col(pinfo->cinfo, COL_PROTOCOL))
902 col_set_str(pinfo->cinfo, COL_PROTOCOL, "LLAP");
903 if (check_col(pinfo->cinfo, COL_INFO))
904 col_clear(pinfo->cinfo, COL_INFO);
907 ti = proto_tree_add_item(tree, proto_llap, tvb, 0, 3, FALSE);
908 llap_tree = proto_item_add_subtree(ti, ett_llap);
911 dnode = tvb_get_guint8(tvb, 0);
913 proto_tree_add_uint(llap_tree, hf_llap_dst, tvb, 0, 1, dnode);
914 snode = tvb_get_guint8(tvb, 1);
916 proto_tree_add_uint(llap_tree, hf_llap_src, tvb, 1, 1, snode);
917 type = tvb_get_guint8(tvb, 2);
918 if (check_col(pinfo->cinfo, COL_INFO)) {
919 col_add_str(pinfo->cinfo, COL_INFO,
920 val_to_str(type, llap_type_vals, "Unknown LLAP type (%02x)"));
923 proto_tree_add_uint(llap_tree, hf_llap_type, tvb, 2, 1, type);
925 new_tvb = tvb_new_subset(tvb, 3, -1, -1);
927 if (proto_is_protocol_enabled(proto_ddp)) {
928 pinfo->current_proto = "DDP";
932 dissect_ddp_short(new_tvb, pinfo, dnode, snode, tree);
936 dissect_ddp(new_tvb, pinfo, tree);
940 call_dissector(data_handle,new_tvb, pinfo, tree);
943 static void asp_reinit( void)
946 if (asp_request_hash)
947 g_hash_table_destroy(asp_request_hash);
948 if (asp_request_keys)
949 g_mem_chunk_destroy(asp_request_keys);
950 if (asp_request_vals)
951 g_mem_chunk_destroy(asp_request_vals);
953 asp_request_hash = g_hash_table_new(asp_hash, asp_equal);
955 asp_request_keys = g_mem_chunk_new("asp_request_keys",
956 sizeof(asp_request_key),
957 asp_packet_init_count * sizeof(asp_request_key),
959 asp_request_vals = g_mem_chunk_new("asp_request_vals",
960 sizeof(asp_request_val),
961 asp_packet_init_count * sizeof(asp_request_val),
967 proto_register_atalk(void)
969 static hf_register_info hf_llap[] = {
971 { "Destination Node", "llap.dst", FT_UINT8, BASE_DEC, NULL, 0x0,
975 { "Source Node", "llap.src", FT_UINT8, BASE_DEC, NULL, 0x0,
979 { "Type", "llap.type", FT_UINT8, BASE_HEX, VALS(llap_type_vals), 0x0,
983 static hf_register_info hf_ddp[] = {
985 { "Hop count", "ddp.hopcount", FT_UINT8, BASE_DEC, NULL, 0x0,
989 { "Datagram length", "ddp.len", FT_UINT16, BASE_DEC, NULL, 0x0,
993 { "Checksum", "ddp.checksum", FT_UINT16, BASE_DEC, NULL, 0x0,
997 { "Destination Net", "ddp.dst.net", FT_UINT16, BASE_DEC, NULL, 0x0,
1001 { "Source Net", "ddp.src.net", FT_UINT16, BASE_DEC, NULL, 0x0,
1005 { "Destination Node", "ddp.dst.node", FT_UINT8, BASE_DEC, NULL, 0x0,
1009 { "Source Node", "ddp.src.node", FT_UINT8, BASE_DEC, NULL, 0x0,
1012 { &hf_ddp_dst_socket,
1013 { "Destination Socket", "ddp.dst.socket", FT_UINT8, BASE_DEC, NULL, 0x0,
1016 { &hf_ddp_src_socket,
1017 { "Source Socket", "ddp.src.socket", FT_UINT8, BASE_DEC, NULL, 0x0,
1021 { "Protocol type", "ddp.type", FT_UINT8, BASE_DEC, VALS(op_vals), 0x0,
1025 static hf_register_info hf_nbp[] = {
1027 { "Operation", "nbp.op", FT_UINT8, BASE_DEC,
1028 VALS(nbp_op_vals), 0xF0, "Operation", HFILL }},
1030 { "Info", "nbp.info", FT_UINT8, BASE_HEX,
1031 NULL, 0x0, "Info", HFILL }},
1033 { "Count", "nbp.count", FT_UINT8, BASE_DEC,
1034 NULL, 0x0F, "Count", HFILL }},
1036 { "Network", "nbp.net", FT_UINT16, BASE_DEC,
1037 NULL, 0x0, "Network", HFILL }},
1038 { &hf_nbp_node_node,
1039 { "Node", "nbp.node", FT_UINT8, BASE_DEC,
1040 NULL, 0x0, "Node", HFILL }},
1041 { &hf_nbp_node_port,
1042 { "Port", "nbp.port", FT_UINT8, BASE_DEC,
1043 NULL, 0x0, "Port", HFILL }},
1044 { &hf_nbp_node_enum,
1045 { "Enumerator", "nbp.enum", FT_UINT8, BASE_DEC,
1046 NULL, 0x0, "Enumerator", HFILL }},
1047 { &hf_nbp_node_object,
1048 { "Object", "nbp.object", FT_STRING, BASE_DEC,
1049 NULL, 0x0, "Object", HFILL }},
1050 { &hf_nbp_node_type,
1051 { "Type", "nbp.type", FT_STRING, BASE_DEC,
1052 NULL, 0x0, "Type", HFILL }},
1053 { &hf_nbp_node_zone,
1054 { "Zone", "nbp.zone", FT_STRING, BASE_DEC,
1055 NULL, 0x0, "Zone", HFILL }},
1057 { "Transaction ID", "nbp.tid", FT_UINT8, BASE_DEC,
1058 NULL, 0x0, "Transaction ID", HFILL }}
1061 static hf_register_info hf_rtmp[] = {
1063 { "Net", "rtmp.net", FT_UINT16, BASE_DEC,
1064 NULL, 0x0, "Net", HFILL }},
1066 { "Node", "nbp.nodeid", FT_UINT8, BASE_DEC,
1067 NULL, 0x0, "Node", HFILL }},
1068 { &hf_rtmp_node_len,
1069 { "Node Length", "nbp.nodeid.length", FT_UINT8, BASE_DEC,
1070 NULL, 0x0, "Node Length", HFILL }},
1071 { &hf_rtmp_tuple_net,
1072 { "Net", "rtmp.tuple.net", FT_UINT16, BASE_DEC,
1073 NULL, 0x0, "Net", HFILL }},
1074 { &hf_rtmp_tuple_range_start,
1075 { "Range Start", "rtmp.tuple.range_start", FT_UINT16, BASE_DEC,
1076 NULL, 0x0, "Range Start", HFILL }},
1077 { &hf_rtmp_tuple_range_end,
1078 { "Range End", "rtmp.tuple.range_end", FT_UINT16, BASE_DEC,
1079 NULL, 0x0, "Range End", HFILL }},
1080 { &hf_rtmp_tuple_dist,
1081 { "Distance", "rtmp.tuple.dist", FT_UINT16, BASE_DEC,
1082 NULL, 0x0, "Distance", HFILL }},
1083 { &hf_rtmp_function,
1084 { "Function", "rtmp.function", FT_UINT8, BASE_DEC,
1085 VALS(rtmp_function_vals), 0x0, "Request Function", HFILL }}
1088 static hf_register_info hf_atp[] = {
1090 { "Control info", "atp.ctrlinfo", FT_UINT8, BASE_HEX,
1091 NULL, 0, "control info", HFILL }},
1094 { "Function", "atp.function", FT_UINT8, BASE_DEC,
1095 VALS(atp_function_vals), ATP_FUNCMASK, "function code", HFILL }},
1099 { "XO", "atp.xo", FT_BOOLEAN, 8,
1100 NULL, ATP_XO, "Exactly-once flag", HFILL }},
1103 { "EOM", "atp.eom", FT_BOOLEAN, 8,
1104 NULL, ATP_EOM, "End-of-message", HFILL }},
1107 { "STS", "atp.sts", FT_BOOLEAN, 8,
1108 NULL, ATP_STS, "Send transaction status", HFILL }},
1110 { &hf_atp_treltimer,
1111 { "TRel timer", "atp.treltimer", FT_UINT8, BASE_DEC,
1112 VALS(atp_trel_timer_vals), 0x07, "TRel timer", HFILL }},
1115 { "Bitmap", "atp.bitmap", FT_UINT8, BASE_HEX,
1116 NULL, 0x0, "bitmap or sequence number", HFILL }},
1118 { "tid", "atp.tid", FT_UINT16, BASE_DEC,
1119 NULL, 0, "transaction id", HFILL }},
1122 static hf_register_info hf_asp[] = {
1124 { "asp function", "asp.function", FT_UINT8, BASE_DEC,
1125 VALS(asp_func_vals), 0, "asp function", HFILL }},
1128 { "asp error", "asp.error", FT_INT32, BASE_DEC,
1129 VALS(asp_error_vals), 0, "return error code", HFILL }},
1132 static gint *ett[] = {
1146 proto_llap = proto_register_protocol("LocalTalk Link Access Protocol", "LLAP", "llap");
1147 proto_register_field_array(proto_llap, hf_llap, array_length(hf_llap));
1149 proto_ddp = proto_register_protocol("Datagram Delivery Protocol", "DDP", "ddp");
1150 proto_register_field_array(proto_ddp, hf_ddp, array_length(hf_ddp));
1152 proto_nbp = proto_register_protocol("Name Binding Protocol", "NBP", "nbp");
1153 proto_register_field_array(proto_nbp, hf_nbp, array_length(hf_nbp));
1155 proto_atp = proto_register_protocol("AppleTalk Transaction Protocol packet", "ATP", "atp");
1156 proto_register_field_array(proto_atp, hf_atp, array_length(hf_atp));
1158 proto_asp = proto_register_protocol("AppleTalk Session Protocol", "ASP", "asp");
1159 proto_register_field_array(proto_asp, hf_asp, array_length(hf_asp));
1161 proto_rtmp = proto_register_protocol("Routing Table Maintenance Protocol",
1163 proto_register_field_array(proto_rtmp, hf_rtmp, array_length(hf_rtmp));
1165 proto_register_subtree_array(ett, array_length(ett));
1167 /* subdissector code */
1168 ddp_dissector_table = register_dissector_table("ddp.type", "DDP packet type",
1169 FT_UINT8, BASE_HEX);
1173 proto_reg_handoff_atalk(void)
1175 dissector_handle_t ddp_handle, nbp_handle, rtmp_request_handle;
1176 dissector_handle_t atp_handle;
1177 dissector_handle_t rtmp_data_handle, llap_handle;
1179 ddp_handle = create_dissector_handle(dissect_ddp, proto_ddp);
1180 dissector_add("ethertype", ETHERTYPE_ATALK, ddp_handle);
1181 dissector_add("chdlctype", ETHERTYPE_ATALK, ddp_handle);
1182 dissector_add("ppp.protocol", PPP_AT, ddp_handle);
1183 dissector_add("null.type", BSD_AF_APPLETALK, ddp_handle);
1185 nbp_handle = create_dissector_handle(dissect_nbp, proto_nbp);
1186 dissector_add("ddp.type", DDP_NBP, nbp_handle);
1188 atp_handle = create_dissector_handle(dissect_atp, proto_atp);
1189 dissector_add("ddp.type", DDP_ATP, atp_handle);
1191 asp_handle = create_dissector_handle(dissect_asp, proto_asp);
1193 rtmp_request_handle = create_dissector_handle(dissect_rtmp_request, proto_rtmp);
1194 rtmp_data_handle = create_dissector_handle(dissect_rtmp_data, proto_rtmp);
1195 dissector_add("ddp.type", DDP_RTMPREQ, rtmp_request_handle);
1196 dissector_add("ddp.type", DDP_RTMPDATA, rtmp_data_handle);
1198 llap_handle = create_dissector_handle(dissect_llap, proto_llap);
1199 dissector_add("wtap_encap", WTAP_ENCAP_LOCALTALK, llap_handle);
1201 register_init_routine( &asp_reinit);
1203 afp_handle = find_dissector("afp");
1204 data_handle = find_dissector("data");