2 * Routines for afp packet dissection
3 * Copyright 2002, Didier Gautheron <dgautheron@magic.fr>
5 * $Id: packet-afp.c,v 1.1 2002/04/25 23:58:02 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
9 * Copyright 1998 Gerald Combs
11 * Copied from README.developer
12 * Copied from packet-dsi.c
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35 #ifdef HAVE_SYS_TYPES_H
36 # include <sys/types.h>
39 #ifdef HAVE_NETINET_IN_H
40 # include <netinet/in.h>
43 #ifdef NEED_SNPRINTF_H
49 # include "snprintf.h"
54 #include <epan/packet.h>
55 #include <epan/strutil.h>
56 #include <epan/conversation.h>
58 #include "packet-afp.h"
60 /* The information in this module (AFP) comes from:
62 AFP 2.1 & 2.2.pdf contained in AppleShare_IP_6.3_SDK
63 available from http://www.apple.com
65 AFP3.0.pdf from http://www.apple.com
67 The netatalk source code by Wesley Craig & Adrian Sun
68 http://netatalk.sf.net
70 /* from netatalk/include/afp.h */
71 #define AFPTRANS_NONE 0
72 #define AFPTRANS_DDP (1 << 0)
73 #define AFPTRANS_TCP (1 << 1)
74 #define AFPTRANS_ALL (AFPTRANS_DDP | AFPTRANS_TCP)
77 #define AFPSRVRINFO_COPY (1<<0) /* supports copyfile */
78 #define AFPSRVRINFO_PASSWD (1<<1) /* supports change password */
79 #define AFPSRVRINFO_NOSAVEPASSWD (1<<2) /* don't allow save password */
80 #define AFPSRVRINFO_SRVMSGS (1<<3) /* supports server messages */
81 #define AFPSRVRINFO_SRVSIGNATURE (1<<4) /* supports server signature */
82 #define AFPSRVRINFO_TCPIP (1<<5) /* supports tcpip */
83 #define AFPSRVRINFO_SRVNOTIFY (1<<6) /* supports server notifications */
84 #define AFPSRVRINFO_FASTBOZO (1<<15) /* fast copying */
86 /* AFP Attention Codes -- 4 bits */
87 #define AFPATTN_SHUTDOWN (1 << 15) /* shutdown/disconnect */
88 #define AFPATTN_CRASH (1 << 14) /* server crashed */
89 #define AFPATTN_MESG (1 << 13) /* server has message */
90 #define AFPATTN_NORECONNECT (1 << 12) /* don't reconnect */
91 /* server notification */
92 #define AFPATTN_NOTIFY (AFPATTN_MESG | AFPATTN_NORECONNECT)
94 /* extended bitmap -- 12 bits. volchanged is only useful w/ a server
95 * notification, and time is only useful for shutdown. */
96 #define AFPATTN_VOLCHANGED (1 << 0) /* volume has changed */
97 #define AFPATTN_TIME(x) ((x) & 0xfff) /* time in minutes */
100 #define AFP_BYTELOCK 1
101 #define AFP_CLOSEVOL 2
102 #define AFP_CLOSEDIR 3
103 #define AFP_CLOSEFORK 4
104 #define AFP_COPYFILE 5
105 #define AFP_CREATEDIR 6
106 #define AFP_CREATEFILE 7
108 #define AFP_ENUMERATE 9
110 #define AFP_FLUSHFORK 11
111 #define AFP_GETFORKPARAM 14
112 #define AFP_GETSRVINFO 15
113 #define AFP_GETSRVPARAM 16
114 #define AFP_GETVOLPARAM 17
116 #define AFP_LOGINCONT 19
117 #define AFP_LOGOUT 20
119 #define AFP_MAPNAME 22
121 #define AFP_OPENVOL 24
122 #define AFP_OPENDIR 25
123 #define AFP_OPENFORK 26
125 #define AFP_RENAME 28
126 #define AFP_SETDIRPARAM 29
127 #define AFP_SETFILEPARAM 30
128 #define AFP_SETFORKPARAM 31
129 #define AFP_SETVOLPARAM 32
131 #define AFP_GETFLDRPARAM 34
132 #define AFP_SETFLDRPARAM 35
133 #define AFP_CHANGEPW 36
134 #define AFP_GETSRVRMSG 38
135 #define AFP_CREATEID 39
136 #define AFP_DELETEID 40
137 #define AFP_RESOLVEID 41
138 #define AFP_EXCHANGEFILE 42
139 #define AFP_CATSEARCH 43
140 #define AFP_OPENDT 48
141 #define AFP_CLOSEDT 49
142 #define AFP_GETICON 51
143 #define AFP_GTICNINFO 52
144 #define AFP_ADDAPPL 53
145 #define AFP_RMVAPPL 54
146 #define AFP_GETAPPL 55
147 #define AFP_ADDCMT 56
148 #define AFP_RMVCMT 57
149 #define AFP_GETCMT 58
150 #define AFP_ADDICON 192
152 /* ----------------------------- */
153 static int proto_afp = -1;
154 static int hf_afp_flags = -1;
155 static int hf_afp_requestid = -1;
156 static int hf_afp_code = -1;
157 static int hf_afp_length = -1;
158 static int hf_afp_reserved = -1;
160 static int hf_afp_command = -1; /* CommandCode */
161 static int hf_afp_AFPVersion = -1;
162 static int hf_afp_UAM = -1;
163 static int hf_afp_user = -1;
164 static int hf_afp_passwd = -1;
165 static int hf_afp_pad = -1;
167 static int hf_afp_vol_bitmap = -1;
168 static int hf_afp_bitmap_offset = -1;
169 static int hf_afp_vol_id = -1;
170 static int hf_afp_vol_attribute = -1;
171 static int hf_afp_vol_name = -1;
172 static int hf_afp_vol_signature = -1;
173 static int hf_afp_vol_creation_date = -1;
174 static int hf_afp_vol_modification_date = -1;
175 static int hf_afp_vol_backup_date = -1;
176 static int hf_afp_vol_bytes_free = -1;
177 static int hf_afp_vol_bytes_total = -1;
178 static int hf_afp_vol_ex_bytes_free = -1;
179 static int hf_afp_vol_ex_bytes_total = -1;
180 static int hf_afp_vol_block_size = -1;
182 static int hf_afp_did = -1;
183 static int hf_afp_file_id = -1;
184 static int hf_afp_dir_bitmap = -1;
185 static int hf_afp_dir_off_spring = -1;
187 static int hf_afp_file_bitmap = -1;
188 static int hf_afp_req_count = -1;
189 static int hf_afp_start_index = -1;
190 static int hf_afp_max_reply_size = -1;
191 static int hf_afp_file_flag = -1;
192 static int hf_afp_struct_size = -1;
194 static int hf_afp_creation_date = -1;
195 static int hf_afp_modification_date = -1;
196 static int hf_afp_backup_date = -1;
197 static int hf_afp_finder_info = -1;
199 static int hf_afp_path_type = -1;
200 static int hf_afp_path_name = -1;
202 static int hf_afp_flag = -1;
203 static int hf_afp_ofork = -1;
204 static int hf_afp_offset = -1;
205 static int hf_afp_rw_count = 1;
206 static int hf_afp_fork_type = -1;
207 static int hf_afp_access_mode = -1;
208 static int hf_afp_access_read = -1;
209 static int hf_afp_access_write = -1;
210 static int hf_afp_access_deny_read = -1;
211 static int hf_afp_access_deny_write = -1;
213 static gint ett_afp = -1;
215 static gint ett_afp_vol_attribute = -1;
216 static gint ett_afp_enumerate = -1;
217 static gint ett_afp_enumerate_line = -1;
218 static gint ett_afp_access_mode = -1;
220 static gint ett_afp_vol_bitmap = -1;
221 static gint ett_afp_dir_bitmap = -1;
222 static gint ett_afp_file_bitmap = -1;
224 static dissector_handle_t afp_handle;
225 static dissector_handle_t data_handle;
227 static const value_string vol_signature_vals[] = {
229 {2, "Fixed Directory ID"},
230 {3, "Variable Directory ID (deprecated)"},
233 static const value_string CommandCode_vals[] = {
234 {AFP_BYTELOCK, "afpByteRangeLock" },
235 {AFP_CLOSEVOL, "afpVolClose" },
236 {AFP_CLOSEDIR, "afpDirClose" },
237 {AFP_CLOSEFORK, "afpForkClose" },
238 {AFP_COPYFILE, "afpCopyFile" },
239 {AFP_CREATEDIR, "afpDirCreate" },
240 {AFP_CREATEFILE, "afpFileCreate" },
241 {AFP_DELETE, "afpDelete" },
242 {AFP_ENUMERATE, "afpEnumerate" },
243 {AFP_FLUSH, "afpFlush" },
244 {AFP_FLUSHFORK, "afpForkFlush" },
245 {AFP_GETFORKPARAM,"afpGetForkParms" },
246 {AFP_GETSRVINFO, "afpGetSInfo" },
247 {AFP_GETSRVPARAM, "afpGetSParms" },
248 {AFP_GETVOLPARAM, "afpGetVolParms" },
249 {AFP_LOGIN, "afpLogin" },
250 {AFP_LOGINCONT, "afpContLogin" },
251 {AFP_LOGOUT, "afpLogout" },
252 {AFP_MAPID, "afpMapID" },
253 {AFP_MAPNAME, "afpMapName" },
254 {AFP_MOVE, "afpMove" },
255 {AFP_OPENVOL, "afpOpenVol" },
256 {AFP_OPENDIR, "afpOpenDir" },
257 {AFP_OPENFORK, "afpOpenFork" },
258 {AFP_READ, "afpRead" },
259 {AFP_RENAME, "afpRename" },
260 {AFP_SETDIRPARAM, "afpSetDirParms" },
261 {AFP_SETFILEPARAM,"afpSetFileParms" },
262 {AFP_SETFORKPARAM,"afpSetForkParms" },
263 {AFP_SETVOLPARAM, "afpSetVolParms" },
264 {AFP_WRITE, "afpWrite" },
265 {AFP_GETFLDRPARAM,"afpGetFlDrParms" },
266 {AFP_SETFLDRPARAM,"afpSetFlDrParms" },
267 {AFP_CHANGEPW, "afpChangePw" },
268 {AFP_GETSRVRMSG, "afpGetSrvrMsg" },
269 {AFP_CREATEID, "afpCreateID" },
270 {AFP_DELETEID, "afpDeleteID" },
271 {AFP_RESOLVEID, "afpResolveID" },
272 {AFP_EXCHANGEFILE,"afpExchangeFiles" },
273 {AFP_CATSEARCH, "afpCatSearch" },
274 {AFP_OPENDT, "afpDTOpen" },
275 {AFP_CLOSEDT, "afpDTClose" },
276 {AFP_GETICON, "afpGetIcon" },
277 {AFP_GTICNINFO, "afpGtIcnInfo" },
278 {AFP_ADDAPPL, "afpAddAPPL" },
279 {AFP_RMVAPPL, "afpRmvAPPL" },
280 {AFP_GETAPPL, "afpGetAPPL" },
281 {AFP_ADDCMT, "afpAddCmt" },
282 {AFP_RMVCMT, "afpRmvCmt" },
283 {AFP_GETCMT, "afpGetCmt" },
284 {AFP_ADDICON, "afpAddIcon" },
289 from Apple AFP3.0.pdf
292 #define kFPVolAttributeBit (1 << 0)
293 #define kFPVolSignatureBit (1 << 1)
294 #define kFPVolCreateDateBit (1 << 2)
295 #define kFPVolModDateBit (1 << 3)
296 #define kFPVolBackupDateBit (1 << 4)
297 #define kFPVolIDBit (1 << 5)
298 #define kFPVolBytesFreeBit (1 << 6)
299 #define kFPVolBytesTotalBit (1 << 7)
300 #define kFPVolNameBit (1 << 8)
301 #define kFPVolExtBytesFreeBit (1 << 9)
302 #define kFPVolExtBytesTotalBit (1 << 10)
303 #define kFPVolBlockSizeBit (1 << 11)
305 static int hf_afp_vol_bitmap_Attribute = -1;
306 static int hf_afp_vol_bitmap_Signature = -1;
307 static int hf_afp_vol_bitmap_CreateDate = -1;
308 static int hf_afp_vol_bitmap_ModDate = -1;
309 static int hf_afp_vol_bitmap_BackupDate = -1;
310 static int hf_afp_vol_bitmap_ID = -1;
311 static int hf_afp_vol_bitmap_BytesFree = -1;
312 static int hf_afp_vol_bitmap_BytesTotal = -1;
313 static int hf_afp_vol_bitmap_Name = -1;
314 static int hf_afp_vol_bitmap_ExtBytesFree = -1;
315 static int hf_afp_vol_bitmap_ExtBytesTotal = -1;
316 static int hf_afp_vol_bitmap_BlockSize = -1;
318 static int hf_afp_vol_attribute_ReadOnly = -1;
319 static int hf_afp_vol_attribute_HasVolumePassword = -1;
320 static int hf_afp_vol_attribute_SupportsFileIDs = -1;
321 static int hf_afp_vol_attribute_SupportsCatSearch = -1;
322 static int hf_afp_vol_attribute_SupportsBlankAccessPrivs = -1;
323 static int hf_afp_vol_attribute_SupportsUnixPrivs = -1;
324 static int hf_afp_vol_attribute_SupportsUTF8Names = -1;
326 static int hf_afp_dir_bitmap_Attribute = -1;
327 static int hf_afp_dir_bitmap_ParentDirID = -1;
328 static int hf_afp_dir_bitmap_CreateDate = -1;
329 static int hf_afp_dir_bitmap_ModDate = -1;
330 static int hf_afp_dir_bitmap_BackupDate = -1;
331 static int hf_afp_dir_bitmap_FinderInfo = -1;
332 static int hf_afp_dir_bitmap_LongName = -1;
333 static int hf_afp_dir_bitmap_ShortName = -1;
334 static int hf_afp_dir_bitmap_NodeID = -1;
335 static int hf_afp_dir_bitmap_OffspringCount = -1;
336 static int hf_afp_dir_bitmap_OwnerID = -1;
337 static int hf_afp_dir_bitmap_GroupID = -1;
338 static int hf_afp_dir_bitmap_AccessRights = -1;
339 static int hf_afp_dir_bitmap_UTF8Name = -1;
340 static int hf_afp_dir_bitmap_UnixPrivs = -1;
342 static int hf_afp_file_bitmap_Attribute = -1;
343 static int hf_afp_file_bitmap_ParentDirID = -1;
344 static int hf_afp_file_bitmap_CreateDate = -1;
345 static int hf_afp_file_bitmap_ModDate = -1;
346 static int hf_afp_file_bitmap_BackupDate = -1;
347 static int hf_afp_file_bitmap_FinderInfo = -1;
348 static int hf_afp_file_bitmap_LongName = -1;
349 static int hf_afp_file_bitmap_ShortName = -1;
350 static int hf_afp_file_bitmap_NodeID = -1;
351 static int hf_afp_file_bitmap_OffspringCount = -1;
352 static int hf_afp_file_bitmap_UTF8Name = -1;
353 static int hf_afp_file_bitmap_UnixPrivs = -1;
355 static const value_string vol_bitmap_vals[] = {
356 {kFPVolAttributeBit, "VolAttribute"},
357 {kFPVolSignatureBit, "VolSignature"},
358 {kFPVolCreateDateBit, "VolCreateDate"},
359 {kFPVolModDateBit, "VolModDate"},
360 {kFPVolBackupDateBit, "VolBackupDate"},
361 {kFPVolIDBit, "VolID"},
362 {kFPVolBytesFreeBit, "VolBytesFree"},
363 {kFPVolBytesTotalBit, "VolBytesTotal"},
364 {kFPVolNameBit, "VolNameBit"},
365 {kFPVolExtBytesFreeBit, "VolExtBytesFree"},
366 {kFPVolExtBytesTotalBit, "VolExtBytesTotal"},
367 {kFPVolBlockSizeBit, "VolBlockSize"},
370 static const value_string flag_vals[] = {
375 static const value_string path_type_vals[] = {
378 {3, "Unicode names" },
382 volume attribute from Apple AFP3.0.pdf
385 #define kReadOnly (1 << 0)
386 #define kHasVolumePassword (1 << 1)
387 #define kSupportsFileIDs (1 << 2)
388 #define kSupportsCatSearch (1 << 3)
389 #define kSupportsBlankAccessPrivs (1 << 4)
390 #define kSupportsUnixPrivs (1 << 5)
391 #define kSupportsUTF8Names (1 << 6)
394 directory bitmap from Apple AFP3.0.pdf
397 #define kFPAttributeBit (1 << 0)
398 #define kFPParentDirIDBit (1 << 1)
399 #define kFPCreateDateBit (1 << 2)
400 #define kFPModDateBit (1 << 3)
401 #define kFPBackupDateBit (1 << 4)
402 #define kFPFinderInfoBit (1 << 5)
403 #define kFPLongNameBit (1 << 6)
404 #define kFPShortNameBit (1 << 7)
405 #define kFPNodeIDBit (1 << 8)
406 #define kFPOffspringCountBit (1 << 9)
407 #define kFPOwnerIDBit (1 << 10)
408 #define kFPGroupIDBit (1 << 11)
409 #define kFPAccessRightsBit (1 << 12)
410 #define kFPUTF8NameBit (1 << 13)
411 #define kFPUnixPrivsBit (1 << 14)
414 file bitmap AFP3.0.pdf
417 kFPAttributeBit (bit 0)
418 kFPParentDirIDBit (bit 1)
419 kFPCreateDateBit (bit 2)
420 kFPModDateBit (bit 3)
421 kFPBackupDateBit (bit 4)
422 kFPFinderInfoBit (bit 5)
423 kFPLongNameBit (bit 6)
424 kFPShortNameBit (bit 7)
427 kFPUTF8NameBit (bit 13)
430 #define kFPDataForkLenBit (1 << 9)
431 #define kFPRsrcForkLenBit (1 << 10)
432 #define kFPExtDataForkLenBit (1 << 11)
433 #define kFPLaunchLimitBit (1 << 12)
435 #define kFPExtRsrcForkLenBit (1 << 14)
436 #define kFPUnixPrivsBit_file (1 << 15) /* :( */
438 #define hash_init_count 20
441 static gint afp_equal (gconstpointer v, gconstpointer v2);
442 static guint afp_hash (gconstpointer v);
444 static guint afp_packet_init_count = 200;
447 guint32 conversation;
455 static GHashTable *afp_request_hash = NULL;
456 static GMemChunk *afp_request_keys = NULL;
457 static GMemChunk *afp_request_vals = NULL;
460 static gint afp_equal (gconstpointer v, gconstpointer v2)
462 afp_request_key *val1 = (afp_request_key*)v;
463 afp_request_key *val2 = (afp_request_key*)v2;
465 if (val1->conversation == val2->conversation &&
466 val1->seq == val2->seq) {
472 static guint afp_hash (gconstpointer v)
474 afp_request_key *afp_key = (afp_request_key*)v;
478 /* --------------------------
480 #define PAD(x) { proto_tree_add_item(tree, hf_afp_pad, tvb, offset, x, FALSE); offset += x; }
483 decode_vol_bitmap (proto_tree *tree, tvbuff_t *tvb, gint offset)
485 proto_tree *sub_tree = NULL;
489 bitmap = tvb_get_ntohs(tvb, offset);
491 item = proto_tree_add_item(tree, hf_afp_vol_bitmap, tvb, offset, 2,FALSE);
492 sub_tree = proto_item_add_subtree(item, ett_afp_vol_bitmap);
495 proto_tree_add_item(sub_tree, hf_afp_vol_bitmap_Attribute, tvb, offset, 2,FALSE);
496 proto_tree_add_item(sub_tree, hf_afp_vol_bitmap_Signature, tvb, offset, 2,FALSE);
497 proto_tree_add_item(sub_tree, hf_afp_vol_bitmap_CreateDate, tvb, offset, 2,FALSE);
498 proto_tree_add_item(sub_tree, hf_afp_vol_bitmap_ModDate, tvb, offset, 2,FALSE);
499 proto_tree_add_item(sub_tree, hf_afp_vol_bitmap_BackupDate, tvb, offset, 2,FALSE);
500 proto_tree_add_item(sub_tree, hf_afp_vol_bitmap_ID, tvb, offset, 2,FALSE);
501 proto_tree_add_item(sub_tree, hf_afp_vol_bitmap_BytesFree, tvb, offset, 2,FALSE);
502 proto_tree_add_item(sub_tree, hf_afp_vol_bitmap_BytesTotal, tvb, offset, 2,FALSE);
503 proto_tree_add_item(sub_tree, hf_afp_vol_bitmap_Name, tvb, offset, 2,FALSE);
504 proto_tree_add_item(sub_tree, hf_afp_vol_bitmap_ExtBytesFree, tvb, offset, 2,FALSE);
505 proto_tree_add_item(sub_tree, hf_afp_vol_bitmap_ExtBytesTotal, tvb, offset, 2,FALSE);
506 proto_tree_add_item(sub_tree, hf_afp_vol_bitmap_BlockSize , tvb, offset, 2,FALSE);
511 /* -------------------------- */
513 decode_vol_attribute (proto_tree *tree, tvbuff_t *tvb, gint offset)
515 proto_tree *sub_tree = NULL;
519 bitmap = tvb_get_ntohs(tvb, offset);
521 item = proto_tree_add_item(tree, hf_afp_vol_attribute, tvb, offset, 2,FALSE);
522 sub_tree = proto_item_add_subtree(item, ett_afp_vol_attribute);
524 proto_tree_add_item(sub_tree, hf_afp_vol_attribute_ReadOnly ,tvb, offset, 2,FALSE);
525 proto_tree_add_item(sub_tree, hf_afp_vol_attribute_HasVolumePassword ,tvb, offset, 2,FALSE);
526 proto_tree_add_item(sub_tree, hf_afp_vol_attribute_SupportsFileIDs ,tvb, offset, 2,FALSE);
527 proto_tree_add_item(sub_tree, hf_afp_vol_attribute_SupportsCatSearch ,tvb, offset, 2,FALSE);
528 proto_tree_add_item(sub_tree, hf_afp_vol_attribute_SupportsBlankAccessPrivs,tvb, offset, 2,FALSE);
529 proto_tree_add_item(sub_tree, hf_afp_vol_attribute_SupportsUnixPrivs ,tvb, offset, 2,FALSE);
530 proto_tree_add_item(sub_tree, hf_afp_vol_attribute_SupportsUTF8Names ,tvb, offset, 2,FALSE);
535 /* -------------------------- */
537 parse_vol_bitmap (proto_tree *tree, tvbuff_t *tvb, gint offset, guint16 bitmap)
541 if ((bitmap & kFPVolAttributeBit)) {
542 decode_vol_attribute(tree,tvb,offset);
545 if ((bitmap & kFPVolSignatureBit)) {
546 proto_tree_add_item(tree, hf_afp_vol_signature,tvb, offset, 2, FALSE);
549 if ((bitmap & kFPVolCreateDateBit)) {
550 proto_tree_add_item(tree, hf_afp_vol_creation_date,tvb, offset, 4, FALSE);
553 if ((bitmap & kFPVolModDateBit)) {
554 proto_tree_add_item(tree, hf_afp_vol_modification_date,tvb, offset, 4, FALSE);
557 if ((bitmap & kFPVolBackupDateBit)) {
558 proto_tree_add_item(tree, hf_afp_vol_backup_date,tvb, offset, 4, FALSE);
561 if ((bitmap & kFPVolIDBit)) {
562 proto_tree_add_item(tree, hf_afp_vol_id, tvb, offset, 2,FALSE);
565 if ((bitmap & kFPVolBytesFreeBit)) {
566 proto_tree_add_item(tree, hf_afp_vol_bytes_free,tvb, offset, 4, FALSE);
569 if ((bitmap & kFPVolBytesTotalBit)) {
570 proto_tree_add_item(tree, hf_afp_vol_bytes_total,tvb, offset, 4, FALSE);
573 if ((bitmap & kFPVolNameBit)) {
574 nameoff = tvb_get_ntohs(tvb, offset);
575 proto_tree_add_item(tree, hf_afp_bitmap_offset,tvb, offset, 2, FALSE);
579 if ((bitmap & kFPVolExtBytesFreeBit)) {
580 proto_tree_add_item(tree, hf_afp_vol_ex_bytes_free,tvb, offset, 8, FALSE);
583 if ((bitmap & kFPVolExtBytesTotalBit)) {
584 proto_tree_add_item(tree, hf_afp_vol_ex_bytes_total,tvb, offset, 8, FALSE);
587 if ((bitmap & kFPVolBlockSizeBit)) {
588 proto_tree_add_item(tree, hf_afp_vol_block_size,tvb, offset, 4, FALSE);
594 len = tvb_get_guint8(tvb, offset);
595 proto_tree_add_item(tree, hf_afp_vol_name, tvb, offset, 1,FALSE);
602 /* -------------------------- */
604 decode_file_bitmap (proto_tree *tree, tvbuff_t *tvb, gint offset)
606 proto_tree *sub_tree = NULL;
610 bitmap = tvb_get_ntohs(tvb, offset);
612 item = proto_tree_add_item(tree, hf_afp_file_bitmap, tvb, offset, 2,FALSE);
613 sub_tree = proto_item_add_subtree(item, ett_afp_file_bitmap);
615 proto_tree_add_item(sub_tree, hf_afp_file_bitmap_Attribute , tvb, offset, 2,FALSE);
616 proto_tree_add_item(sub_tree, hf_afp_file_bitmap_ParentDirID , tvb, offset, 2,FALSE);
617 proto_tree_add_item(sub_tree, hf_afp_file_bitmap_CreateDate , tvb, offset, 2,FALSE);
618 proto_tree_add_item(sub_tree, hf_afp_file_bitmap_ModDate , tvb, offset, 2,FALSE);
619 proto_tree_add_item(sub_tree, hf_afp_file_bitmap_BackupDate , tvb, offset, 2,FALSE);
620 proto_tree_add_item(sub_tree, hf_afp_file_bitmap_FinderInfo , tvb, offset, 2,FALSE);
621 proto_tree_add_item(sub_tree, hf_afp_file_bitmap_LongName , tvb, offset, 2,FALSE);
622 proto_tree_add_item(sub_tree, hf_afp_file_bitmap_ShortName , tvb, offset, 2,FALSE);
623 proto_tree_add_item(sub_tree, hf_afp_file_bitmap_NodeID , tvb, offset, 2,FALSE);
625 proto_tree_add_item(sub_tree, hf_afp_file_bitmap_UTF8Name , tvb, offset, 2,FALSE);
627 proto_tree_add_item(sub_tree, hf_afp_dir_bitmap_UnixPrivs , tvb, offset, 2,FALSE);
632 /* -------------------------- */
634 parse_file_bitmap (proto_tree *tree, tvbuff_t *tvb, gint offset, guint16 bitmap)
636 guint16 lnameoff = 0;
637 guint16 snameoff = 0;
638 guint16 unameoff = 0;
641 gint org_offset = offset;
643 if ((bitmap & kFPAttributeBit)) {
646 if ((bitmap & kFPParentDirIDBit)) {
647 proto_tree_add_item(tree, hf_afp_did, tvb, offset, 4,FALSE);
650 if ((bitmap & kFPCreateDateBit)) {
651 proto_tree_add_item(tree, hf_afp_creation_date,tvb, offset, 4, FALSE);
654 if ((bitmap & kFPModDateBit)) {
655 proto_tree_add_item(tree, hf_afp_modification_date,tvb, offset, 4, FALSE);
658 if ((bitmap & kFPBackupDateBit)) {
659 proto_tree_add_item(tree, hf_afp_backup_date,tvb, offset, 4, FALSE);
662 if ((bitmap & kFPFinderInfoBit)) {
663 proto_tree_add_item(tree, hf_afp_finder_info,tvb, offset, 32, FALSE);
666 if ((bitmap & kFPLongNameBit)) {
669 lnameoff = tvb_get_ntohs(tvb, offset);
671 tp_ofs = lnameoff +org_offset;
672 proto_tree_add_item(tree, hf_afp_bitmap_offset,tvb, offset, 2, FALSE);
673 len = tvb_get_guint8(tvb, tp_ofs);
674 proto_tree_add_item(tree, hf_afp_path_name, tvb, tp_ofs, 1,FALSE);
676 max_offset = (tp_ofs >max_offset)?tp_ofs:max_offset;
680 if ((bitmap & kFPShortNameBit)) {
681 snameoff = tvb_get_ntohs(tvb, offset);
682 proto_tree_add_item(tree, hf_afp_bitmap_offset,tvb, offset, 2, FALSE);
685 if ((bitmap & kFPNodeIDBit)) {
686 proto_tree_add_item(tree, hf_afp_file_id, tvb, offset, 4,FALSE);
693 /* -------------------------- */
695 decode_dir_bitmap (proto_tree *tree, tvbuff_t *tvb, gint offset)
697 proto_tree *sub_tree = NULL;
701 bitmap = tvb_get_ntohs(tvb, offset);
703 item = proto_tree_add_item(tree, hf_afp_dir_bitmap, tvb, offset, 2,FALSE);
704 sub_tree = proto_item_add_subtree(item, ett_afp_dir_bitmap);
707 proto_tree_add_item(sub_tree, hf_afp_dir_bitmap_Attribute , tvb, offset, 2,FALSE);
708 proto_tree_add_item(sub_tree, hf_afp_dir_bitmap_ParentDirID , tvb, offset, 2,FALSE);
709 proto_tree_add_item(sub_tree, hf_afp_dir_bitmap_CreateDate , tvb, offset, 2,FALSE);
710 proto_tree_add_item(sub_tree, hf_afp_dir_bitmap_ModDate , tvb, offset, 2,FALSE);
711 proto_tree_add_item(sub_tree, hf_afp_dir_bitmap_BackupDate , tvb, offset, 2,FALSE);
712 proto_tree_add_item(sub_tree, hf_afp_dir_bitmap_FinderInfo , tvb, offset, 2,FALSE);
713 proto_tree_add_item(sub_tree, hf_afp_dir_bitmap_LongName , tvb, offset, 2,FALSE);
714 proto_tree_add_item(sub_tree, hf_afp_dir_bitmap_ShortName , tvb, offset, 2,FALSE);
715 proto_tree_add_item(sub_tree, hf_afp_dir_bitmap_NodeID , tvb, offset, 2,FALSE);
716 proto_tree_add_item(sub_tree, hf_afp_dir_bitmap_OffspringCount , tvb, offset, 2,FALSE);
717 proto_tree_add_item(sub_tree, hf_afp_dir_bitmap_OwnerID , tvb, offset, 2,FALSE);
718 proto_tree_add_item(sub_tree, hf_afp_dir_bitmap_GroupID , tvb, offset, 2,FALSE);
719 proto_tree_add_item(sub_tree, hf_afp_dir_bitmap_AccessRights , tvb, offset, 2,FALSE);
720 proto_tree_add_item(sub_tree, hf_afp_dir_bitmap_UTF8Name , tvb, offset, 2,FALSE);
721 proto_tree_add_item(sub_tree, hf_afp_dir_bitmap_UnixPrivs , tvb, offset, 2,FALSE);
726 /* -------------------------- */
728 parse_dir_bitmap (proto_tree *tree, tvbuff_t *tvb, gint offset, guint16 bitmap)
730 guint16 lnameoff = 0;
731 guint16 snameoff = 0;
732 guint16 unameoff = 0;
735 gint org_offset = offset;
737 if ((bitmap & kFPAttributeBit)) {
740 if ((bitmap & kFPParentDirIDBit)) {
741 proto_tree_add_item(tree, hf_afp_did, tvb, offset, 4,FALSE);
744 if ((bitmap & kFPCreateDateBit)) {
745 proto_tree_add_item(tree, hf_afp_creation_date,tvb, offset, 4, FALSE);
748 if ((bitmap & kFPModDateBit)) {
749 proto_tree_add_item(tree, hf_afp_modification_date,tvb, offset, 4, FALSE);
752 if ((bitmap & kFPBackupDateBit)) {
753 proto_tree_add_item(tree, hf_afp_backup_date,tvb, offset, 4, FALSE);
756 if ((bitmap & kFPFinderInfoBit)) {
757 proto_tree_add_item(tree, hf_afp_finder_info,tvb, offset, 32, FALSE);
760 if ((bitmap & kFPLongNameBit)) {
763 lnameoff = tvb_get_ntohs(tvb, offset);
765 tp_ofs = lnameoff +org_offset;
766 proto_tree_add_item(tree, hf_afp_bitmap_offset,tvb, offset, 2, FALSE);
767 len = tvb_get_guint8(tvb, tp_ofs);
768 proto_tree_add_item(tree, hf_afp_path_name, tvb, tp_ofs, 1,FALSE);
770 max_offset = (tp_ofs >max_offset)?tp_ofs:max_offset;
774 if ((bitmap & kFPShortNameBit)) {
775 snameoff = tvb_get_ntohs(tvb, offset);
776 proto_tree_add_item(tree, hf_afp_bitmap_offset,tvb, offset, 2, FALSE);
779 if ((bitmap & kFPNodeIDBit)) {
780 proto_tree_add_item(tree, hf_afp_file_id, tvb, offset, 4,FALSE);
783 if ((bitmap & kFPOffspringCountBit)) {
784 proto_tree_add_item(tree, hf_afp_dir_off_spring, tvb, offset, 2,FALSE);
785 offset += 2; /* error in AFP3.0.pdf */
787 if ((bitmap & kFPOwnerIDBit)) {
790 if ((bitmap & kFPGroupIDBit)) {
793 if ((bitmap & kFPAccessRightsBit)) {
796 if ((bitmap & kFPUTF8NameBit)) {
799 if ((bitmap & kFPUnixPrivsBit)) {
800 unameoff = tvb_get_ntohs(tvb, offset);
803 return (max_offset)?max_offset:offset;
806 /* -------------------------- */
808 name_in_bitmap(tvbuff_t *tvb, gint *offset, guint16 bitmap)
811 gint org_offset = *offset;
817 if ((bitmap & kFPAttributeBit))
819 if ((bitmap & kFPParentDirIDBit))
821 if ((bitmap & kFPCreateDateBit))
823 if ((bitmap & kFPModDateBit))
825 if ((bitmap & kFPBackupDateBit))
827 if ((bitmap & kFPFinderInfoBit))
830 if ((bitmap & kFPLongNameBit)) {
831 nameoff = tvb_get_ntohs(tvb, *offset);
833 tp_ofs = nameoff +org_offset;
834 len = tvb_get_guint8(tvb, tp_ofs);
836 if (!(name = g_malloc(len +1)))
838 tvb_memcpy(tvb, name, tp_ofs, len);
847 /* -------------------------- */
849 name_in_dbitmap(tvbuff_t *tvb, gint offset, guint16 bitmap)
853 name = name_in_bitmap(tvb, &offset, bitmap);
863 /* -------------------------- */
865 name_in_fbitmap(tvbuff_t *tvb, gint offset, guint16 bitmap)
869 name = name_in_bitmap(tvb, &offset, bitmap);
879 /* -------------------------- */
881 decode_vol_did_file_dir_bitmap (proto_tree *tree, tvbuff_t *tvb, gint offset)
883 proto_tree_add_item(tree, hf_afp_vol_id, tvb, offset, 2,FALSE);
886 proto_tree_add_item(tree, hf_afp_did, tvb, offset, 4,FALSE);
889 decode_file_bitmap(tree, tvb, offset);
892 decode_dir_bitmap(tree, tvb, offset);
898 /* -------------------------- */
900 decode_name (proto_tree *tree, tvbuff_t *tvb, gint offset)
904 proto_tree_add_item(tree, hf_afp_path_type, tvb, offset, 1,FALSE);
907 len = tvb_get_guint8(tvb, offset);
908 proto_tree_add_item(tree, hf_afp_path_name, tvb, offset, 1,FALSE);
914 /* ************************** */
916 dissect_query_afp_open_vol(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset)
922 decode_vol_bitmap(tree, tvb, offset);
925 len = tvb_get_guint8(tvb, offset);
927 if (check_col(pinfo->cinfo, COL_INFO)) {
930 if ((func_str = match_strval(afp_command, CommandCode_vals)))
932 col_add_fstr(pinfo->cinfo, COL_INFO, "%s %s", func_str, aspinfo->reply?"reply":"");
936 proto_tree_add_item(tree, hf_afp_vol_name, tvb, offset, 1,FALSE);
939 len = tvb_reported_length_remaining(tvb,offset);
941 /* optionnal password */
942 proto_tree_add_item(tree, hf_afp_passwd, tvb, offset, 8,FALSE);
948 /* -------------------------- */
950 dissect_reply_afp_open_vol(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset)
954 bitmap = decode_vol_bitmap(tree, tvb, offset);
956 offset = parse_vol_bitmap(tree, tvb, offset, bitmap);
961 /* ************************** */
963 dissect_query_afp_open_fork(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset)
965 proto_tree *sub_tree = NULL;
968 proto_tree_add_item(tree, hf_afp_fork_type, tvb, offset, 1,FALSE);
971 proto_tree_add_item(tree, hf_afp_vol_id, tvb, offset, 2,FALSE);
974 proto_tree_add_item(tree, hf_afp_did, tvb, offset, 4,FALSE);
977 decode_file_bitmap(tree, tvb, offset);
980 item = proto_tree_add_item(tree, hf_afp_access_mode, tvb, offset, 2,FALSE);
981 sub_tree = proto_item_add_subtree(item, ett_afp_access_mode);
983 item = proto_tree_add_item(sub_tree, hf_afp_access_read , tvb, offset, 2,FALSE);
984 item = proto_tree_add_item(sub_tree, hf_afp_access_write , tvb, offset, 2,FALSE);
985 item = proto_tree_add_item(sub_tree, hf_afp_access_deny_read , tvb, offset, 2,FALSE);
986 item = proto_tree_add_item(sub_tree, hf_afp_access_deny_write, tvb, offset, 2,FALSE);
990 offset = decode_name(tree,tvb, offset);
995 /* -------------------------- */
997 dissect_reply_afp_open_fork(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset)
1001 f_bitmap = decode_file_bitmap(tree, tvb, offset);
1004 proto_tree_add_item(tree, hf_afp_ofork, tvb, offset, 2,FALSE);
1007 offset = parse_file_bitmap(tree, tvb, offset, f_bitmap);
1012 /* ************************** */
1014 dissect_query_afp_enumerate(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset)
1018 offset = decode_vol_did_file_dir_bitmap(tree, tvb, offset);
1020 proto_tree_add_item(tree, hf_afp_req_count, tvb, offset, 2,FALSE);
1023 proto_tree_add_item(tree, hf_afp_start_index, tvb, offset, 2,FALSE);
1026 proto_tree_add_item(tree, hf_afp_max_reply_size, tvb, offset, 2,FALSE);
1029 offset = decode_name(tree,tvb, offset);
1034 /* -------------------------- */
1036 dissect_reply_afp_enumerate(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset)
1038 proto_tree *sub_tree = NULL;
1049 f_bitmap = decode_file_bitmap(tree, tvb, offset);
1052 d_bitmap = decode_dir_bitmap(tree, tvb, offset);
1055 count = tvb_get_ntohs(tvb, offset);
1057 item = proto_tree_add_item(tree, hf_afp_req_count, tvb, offset, 2,FALSE);
1058 sub_tree = proto_item_add_subtree(item, ett_afp_enumerate);
1062 if (tree) for (i = 0; i < count; i++) {
1065 size = tvb_get_guint8(tvb, offset);
1066 flags = tvb_get_guint8(tvb, offset +1);
1069 name = name_in_dbitmap(tvb, offset +2, d_bitmap);
1072 name = name_in_fbitmap(tvb, offset +2, f_bitmap);
1075 if (!(name = g_malloc(50))) { /* no memory ! */
1077 snprintf(name, 50,"line %d", i +1);
1079 item = proto_tree_add_text(sub_tree, tvb, offset, size, name);
1080 tree = proto_item_add_subtree(item, ett_afp_enumerate_line);
1082 proto_tree_add_item(tree, hf_afp_struct_size, tvb, offset, 1,FALSE);
1085 proto_tree_add_item(tree, hf_afp_file_flag, tvb, offset, 1,FALSE);
1088 offset = parse_dir_bitmap(tree, tvb, offset, d_bitmap);
1091 offset = parse_file_bitmap(tree, tvb, offset, f_bitmap);
1095 offset = org +size; /* play safe */
1096 g_free((gpointer)name);
1102 /* **************************/
1104 dissect_query_afp_get_vol_param(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset)
1109 proto_tree_add_item(tree, hf_afp_vol_id, tvb, offset, 2,FALSE);
1112 decode_vol_bitmap(tree, tvb, offset);
1118 /* ------------------------ */
1120 dissect_reply_afp_get_vol_param(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset)
1126 bitmap = decode_vol_bitmap(tree, tvb, offset);
1129 offset = parse_vol_bitmap(tree, tvb, offset, bitmap);
1134 /* ***************************/
1136 dissect_query_afp_login(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset)
1142 len = tvb_get_guint8(tvb, offset);
1143 proto_tree_add_item(tree, hf_afp_AFPVersion, tvb, offset, 1,FALSE);
1145 len = tvb_get_guint8(tvb, offset);
1146 proto_tree_add_item(tree, hf_afp_UAM, tvb, offset, 1,FALSE);
1150 len = tvb_get_guint8(tvb, offset);
1151 proto_tree_add_item(tree, hf_afp_user, tvb, offset, 1,FALSE);
1154 len = tvb_strsize(tvb, offset);
1155 proto_tree_add_item(tree, hf_afp_passwd, tvb, offset, len,FALSE);
1161 /* ************************** */
1163 dissect_query_afp_write(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset)
1169 proto_tree_add_item(tree, hf_afp_flag, tvb, offset, 1,FALSE);
1172 proto_tree_add_item(tree, hf_afp_ofork, tvb, offset, 2,FALSE);
1175 proto_tree_add_item(tree, hf_afp_offset, tvb, offset, 4,FALSE);
1178 proto_tree_add_item(tree, hf_afp_rw_count, tvb, offset, 4,FALSE);
1184 /* ************************** */
1186 dissect_query_afp_get_fldr_param(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset)
1191 offset = decode_vol_did_file_dir_bitmap(tree, tvb, offset);
1193 offset = decode_name(tree, tvb, offset);
1198 /* -------------------------- */
1200 dissect_reply_afp_get_fldr_param(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset)
1203 guint16 f_bitmap, d_bitmap;
1207 f_bitmap = decode_file_bitmap(tree, tvb, offset);
1210 d_bitmap = decode_dir_bitmap(tree, tvb, offset);
1213 flags = tvb_get_guint8(tvb, offset);
1214 proto_tree_add_item(tree, hf_afp_file_flag, tvb, offset, 1,FALSE);
1218 offset = parse_dir_bitmap(tree, tvb, offset, d_bitmap);
1221 offset = parse_file_bitmap(tree, tvb, offset, f_bitmap);
1226 /* ************************** */
1228 dissect_afp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1230 struct aspinfo *aspinfo = pinfo->private_data;
1231 proto_tree *afp_tree = NULL;
1233 conversation_t *conversation;
1235 afp_request_key request_key, *new_request_key;
1236 afp_request_val *request_val;
1240 guint8 afp_flags,afp_command;
1241 guint16 afp_requestid;
1244 guint32 afp_reserved;
1245 int len = tvb_reported_length_remaining(tvb,0);
1247 if (check_col(pinfo->cinfo, COL_PROTOCOL))
1248 col_set_str(pinfo->cinfo, COL_PROTOCOL, "AFP");
1249 if (check_col(pinfo->cinfo, COL_INFO))
1250 col_clear(pinfo->cinfo, COL_INFO);
1252 conversation = find_conversation(&pinfo->src, &pinfo->dst, pinfo->ptype,
1253 pinfo->srcport, pinfo->destport, 0);
1255 if (conversation == NULL)
1257 conversation = conversation_new(&pinfo->src, &pinfo->dst,
1258 pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
1261 request_key.conversation = conversation->index;
1262 request_key.seq = aspinfo->seq;
1264 request_val = (afp_request_val *) g_hash_table_lookup(
1265 afp_request_hash, &request_key);
1267 if (!request_val && !aspinfo->reply) {
1268 afp_command = tvb_get_guint8(tvb, offset);
1269 new_request_key = g_mem_chunk_alloc(afp_request_keys);
1270 *new_request_key = request_key;
1272 request_val = g_mem_chunk_alloc(afp_request_vals);
1273 request_val->command = tvb_get_guint8(tvb, offset);
1275 g_hash_table_insert(afp_request_hash, new_request_key,
1279 if (!request_val) { /* missing request */
1283 afp_command = request_val->command;
1284 if (check_col(pinfo->cinfo, COL_INFO)) {
1287 if ((func_str = match_strval(afp_command, CommandCode_vals)))
1289 col_add_fstr(pinfo->cinfo, COL_INFO, "%s %s", func_str, aspinfo->reply?"reply":"");
1295 ti = proto_tree_add_item(tree, proto_afp, tvb, offset, -1,FALSE);
1296 afp_tree = proto_item_add_subtree(ti, ett_afp);
1298 if (!aspinfo->reply) {
1299 proto_tree_add_uint(afp_tree, hf_afp_command, tvb,offset, 1, afp_command);
1301 switch(afp_command) {
1308 case AFP_CREATEFILE:
1312 offset = dissect_query_afp_enumerate(tvb, pinfo, afp_tree, offset);break;
1315 case AFP_GETFORKPARAM:
1316 case AFP_GETSRVINFO:
1317 case AFP_GETSRVPARAM:
1319 case AFP_GETVOLPARAM:
1320 offset = dissect_query_afp_get_vol_param(tvb, pinfo, afp_tree, offset);break;
1322 offset = dissect_query_afp_login(tvb, pinfo, afp_tree, offset);break;
1330 offset = dissect_query_afp_open_vol(tvb, pinfo, afp_tree, offset);break;
1334 offset = dissect_query_afp_open_fork(tvb, pinfo, afp_tree, offset);break;
1337 case AFP_SETDIRPARAM:
1338 case AFP_SETFILEPARAM:
1339 case AFP_SETFORKPARAM:
1340 case AFP_SETVOLPARAM:
1343 offset = dissect_query_afp_write(tvb, pinfo, afp_tree, offset);break;
1344 case AFP_GETFLDRPARAM:
1345 offset = dissect_query_afp_get_fldr_param(tvb, pinfo, afp_tree, offset);break;
1346 case AFP_SETFLDRPARAM:
1348 case AFP_GETSRVRMSG:
1352 case AFP_EXCHANGEFILE:
1369 switch(afp_command) {
1371 offset = dissect_reply_afp_enumerate(tvb, pinfo, afp_tree, offset);break;
1373 offset = dissect_reply_afp_open_vol(tvb, pinfo, afp_tree, offset);break;
1375 offset = dissect_reply_afp_open_fork(tvb, pinfo, afp_tree, offset);break;
1378 case AFP_GETFORKPARAM:
1379 case AFP_GETSRVINFO:
1380 case AFP_GETSRVPARAM:
1382 case AFP_GETVOLPARAM:
1383 offset = dissect_reply_afp_get_vol_param(tvb, pinfo, afp_tree, offset);break;
1384 case AFP_GETFLDRPARAM:
1385 offset = dissect_reply_afp_get_fldr_param(tvb, pinfo, afp_tree, offset);break;
1388 if (tree && offset < len)
1389 call_dissector(data_handle,tvb_new_subset(tvb, offset,-1,tvb_reported_length_remaining(tvb,offset)), pinfo, afp_tree);
1392 static void afp_reinit( void)
1395 if (afp_request_hash)
1396 g_hash_table_destroy(afp_request_hash);
1397 if (afp_request_keys)
1398 g_mem_chunk_destroy(afp_request_keys);
1399 if (afp_request_vals)
1400 g_mem_chunk_destroy(afp_request_vals);
1402 afp_request_hash = g_hash_table_new(afp_hash, afp_equal);
1404 afp_request_keys = g_mem_chunk_new("afp_request_keys",
1405 sizeof(afp_request_key),
1406 afp_packet_init_count * sizeof(afp_request_key),
1408 afp_request_vals = g_mem_chunk_new("afp_request_vals",
1409 sizeof(afp_request_val),
1410 afp_packet_init_count * sizeof(afp_request_val),
1416 proto_register_afp(void)
1419 static hf_register_info hf[] = {
1421 { "Command", "afp.command",
1422 FT_UINT8, BASE_DEC, VALS(CommandCode_vals), 0x0,
1423 "AFP function", HFILL }},
1427 FT_NONE, BASE_NONE, NULL, 0,
1428 "Pad Byte", HFILL }},
1430 { &hf_afp_AFPVersion,
1431 { "AFP Version", "afp.AFPVersion",
1432 FT_UINT_STRING, BASE_NONE, NULL, 0x0,
1433 "client AFP version", HFILL }},
1437 FT_UINT_STRING, BASE_NONE, NULL, 0x0,
1438 "USer Authentication method", HFILL }},
1441 { "user", "afp.user",
1442 FT_UINT_STRING, BASE_NONE, NULL, 0x0,
1446 { "password", "afp.passwd",
1447 FT_STRINGZ, BASE_NONE, NULL, 0x0,
1448 "password", HFILL }},
1450 { &hf_afp_vol_bitmap,
1451 { "bitmap", "afp.vol_bitmap",
1452 FT_UINT16, BASE_HEX, NULL, 0 /* 0x0FFF*/,
1453 "Volume bitmap", HFILL }},
1455 { &hf_afp_vol_bitmap_Attribute,
1456 { "attribute", "afp.vol_bitmap.attribute",
1457 FT_BOOLEAN, 16, NULL, kFPVolAttributeBit,
1458 "Volume attribute", HFILL }},
1460 { &hf_afp_vol_attribute, { "attribute", "afp.vol_attribute",
1461 FT_UINT16, BASE_HEX, NULL, 0 , "Volume attribute", HFILL }},
1463 { &hf_afp_vol_attribute_ReadOnly,
1464 { "read only", "afp.vol_attribute.read_only",
1465 FT_BOOLEAN, 16, NULL, kReadOnly,
1466 "Read only volume", HFILL }},
1468 { &hf_afp_vol_attribute_HasVolumePassword,
1469 { "volume password", "afp.vol_attribute.passwd",
1470 FT_BOOLEAN, 16, NULL, kHasVolumePassword,
1471 "Has a volume password", HFILL }},
1473 { &hf_afp_vol_attribute_SupportsFileIDs,
1474 { "files ID", "afp.vol_attribute.fileIDs",
1475 FT_BOOLEAN, 16, NULL, kSupportsFileIDs,
1476 "Supports files ID", HFILL }},
1478 { &hf_afp_vol_attribute_SupportsCatSearch,
1479 { "cat search", "afp.vol_attribute.cat_search",
1480 FT_BOOLEAN, 16, NULL, kSupportsCatSearch,
1481 "Supports cat search call", HFILL }},
1483 { &hf_afp_vol_attribute_SupportsBlankAccessPrivs,
1484 { "blank access privs", "afp.vol_attribute.blank_access_privs",
1485 FT_BOOLEAN, 16, NULL, kSupportsBlankAccessPrivs,
1486 "Supports blank access priv.", HFILL }},
1488 { &hf_afp_vol_attribute_SupportsUnixPrivs,
1489 { "blank access privs", "afp.vol_attribute.unix_privs",
1490 FT_BOOLEAN, 16, NULL, kSupportsUnixPrivs,
1491 "Supports Unix access priv.", HFILL }},
1493 { &hf_afp_vol_attribute_SupportsUTF8Names,
1494 { "blank access privs", "afp.vol_attribute.utf8_names",
1495 FT_BOOLEAN, 16, NULL, kSupportsUTF8Names,
1496 "Supports UTF8 names.", HFILL }},
1498 { &hf_afp_vol_bitmap_Signature,
1499 { "signature", "afp.vol_bitmap.signature",
1500 FT_BOOLEAN, 16, NULL, kFPVolSignatureBit,
1501 "Volume signature", HFILL }},
1502 { &hf_afp_vol_bitmap_CreateDate,
1503 { "creation date", "afp.vol_bitmap.create_date",
1504 FT_BOOLEAN, 16, NULL, kFPVolCreateDateBit,
1505 "Volume creation date", HFILL }},
1506 { &hf_afp_vol_bitmap_ModDate,
1507 { "modification date", "afp.vol_bitmap.mod_date",
1508 FT_BOOLEAN, 16, NULL, kFPVolModDateBit,
1509 "Volume modification date", HFILL }},
1510 { &hf_afp_vol_bitmap_BackupDate,
1511 { "backup date", "afp.vol_bitmap.backup_date",
1512 FT_BOOLEAN, 16, NULL, kFPVolBackupDateBit,
1513 "Volume backup date", HFILL }},
1514 { &hf_afp_vol_bitmap_ID,
1515 { "ID", "afp.vol_bitmap.id",
1516 FT_BOOLEAN, 16, NULL, kFPVolIDBit,
1517 "Volume ID", HFILL }},
1518 { &hf_afp_vol_bitmap_BytesFree,
1519 { "bytes free", "afp.vol_bitmap.bytes_free",
1520 FT_BOOLEAN, 16, NULL, kFPVolBytesFreeBit,
1521 "Volume free bytes", HFILL }},
1522 { &hf_afp_vol_bitmap_BytesTotal,
1523 { "bytes total", "afp.vol_bitmap.bytes_total",
1524 FT_BOOLEAN, 16, NULL, kFPVolBytesTotalBit,
1525 "Volume total bytes", HFILL }},
1526 { &hf_afp_vol_bitmap_Name,
1527 { "name", "afp.vol_bitmap.name",
1528 FT_BOOLEAN, 16, NULL, kFPVolNameBit,
1529 "Volume name", HFILL }},
1530 { &hf_afp_vol_bitmap_ExtBytesFree,
1531 { "ex. bytes free", "afp.vol_bitmap.ex_bytes_free",
1532 FT_BOOLEAN, 16, NULL, kFPVolExtBytesFreeBit,
1533 "Volume ext. free bytes", HFILL }},
1534 { &hf_afp_vol_bitmap_ExtBytesTotal,
1535 { "ex bytes total", "afp.vol_bitmap.ex_bytes_total",
1536 FT_BOOLEAN, 16, NULL, kFPVolExtBytesTotalBit,
1537 "Volume ex. total byte", HFILL }},
1538 { &hf_afp_vol_bitmap_BlockSize,
1539 { "block size", "afp.vol_bitmap.block_size",
1540 FT_BOOLEAN, 16, NULL, kFPVolBlockSizeBit,
1541 "Volume block size", HFILL }},
1543 { &hf_afp_dir_bitmap_Attribute,
1544 { "attribute", "afp.dir_bitmap.attribute",
1545 FT_BOOLEAN, 16, NULL, kFPAttributeBit,
1546 "directory attribute", HFILL }},
1547 { &hf_afp_dir_bitmap_ParentDirID,
1548 { "DID", "afp.dir_bitmap.did",
1549 FT_BOOLEAN, 16, NULL, kFPParentDirIDBit,
1550 "parent directory ID", HFILL }},
1551 { &hf_afp_dir_bitmap_CreateDate,
1552 { "creation date", "afp.dir_bitmap.create_date",
1553 FT_BOOLEAN, 16, NULL, kFPCreateDateBit,
1554 "directory creation date", HFILL }},
1555 { &hf_afp_dir_bitmap_ModDate,
1556 { "modification date", "afp.dir_bitmap.mod_date",
1557 FT_BOOLEAN, 16, NULL, kFPModDateBit,
1558 "directory modification date", HFILL }},
1559 { &hf_afp_dir_bitmap_BackupDate,
1560 { "backup date", "afp.dir_bitmap.backup_date",
1561 FT_BOOLEAN, 16, NULL, kFPBackupDateBit,
1562 "directory backup date", HFILL }},
1563 { &hf_afp_dir_bitmap_FinderInfo,
1564 { "Finder info", "afp.dir_bitmap.finder_info",
1565 FT_BOOLEAN, 16, NULL, kFPFinderInfoBit,
1566 "directory finder info", HFILL }},
1567 { &hf_afp_dir_bitmap_LongName,
1568 { "long name", "afp.dir_bitmap.long_name",
1569 FT_BOOLEAN, 16, NULL, kFPLongNameBit,
1570 "directory long name", HFILL }},
1571 { &hf_afp_dir_bitmap_ShortName,
1572 { "short name", "afp.dir_bitmap.short_name",
1573 FT_BOOLEAN, 16, NULL, kFPShortNameBit,
1574 "directory short name", HFILL }},
1575 { &hf_afp_dir_bitmap_NodeID,
1576 { "file ID", "afp.dir_bitmap.fid",
1577 FT_BOOLEAN, 16, NULL, kFPNodeIDBit,
1578 "directory file ID", HFILL }},
1579 { &hf_afp_dir_bitmap_OffspringCount,
1580 { "offspring count", "afp.dir_bitmap.off_spring_count",
1581 FT_BOOLEAN, 16, NULL, kFPOffspringCountBit,
1582 "directory offSpring count", HFILL }},
1583 { &hf_afp_dir_bitmap_OwnerID,
1584 { "owner id", "afp.dir_bitmap.owner_id",
1585 FT_BOOLEAN, 16, NULL, kFPOwnerIDBit,
1586 "directory owner id", HFILL }},
1587 { &hf_afp_dir_bitmap_GroupID,
1588 { "group id", "afp.dir_bitmap.group_id",
1589 FT_BOOLEAN, 16, NULL, kFPGroupIDBit,
1590 "directory group id", HFILL }},
1591 { &hf_afp_dir_bitmap_AccessRights,
1592 { "access rights", "afp.dir_bitmap.access_rights",
1593 FT_BOOLEAN, 16, NULL, kFPAccessRightsBit,
1594 "directory access rights", HFILL }},
1595 { &hf_afp_dir_bitmap_UTF8Name,
1596 { "UTF8 name", "afp.dir_bitmap.UTF8_name",
1597 FT_BOOLEAN, 16, NULL, kFPUTF8NameBit,
1598 "directory UTF8 name", HFILL }},
1599 { &hf_afp_dir_bitmap_UnixPrivs,
1600 { "unix privs", "afp.dir_bitmap.unix_privs",
1601 FT_BOOLEAN, 16, NULL, kFPUnixPrivsBit,
1602 "directory unix privs", HFILL }},
1604 { &hf_afp_file_bitmap_Attribute,
1605 { "attribute", "afp.file_bitmap.attribute",
1606 FT_BOOLEAN, 16, NULL, kFPAttributeBit,
1607 "file attribute", HFILL }},
1608 { &hf_afp_file_bitmap_ParentDirID,
1609 { "DID", "afp.file_bitmap.did",
1610 FT_BOOLEAN, 16, NULL, kFPParentDirIDBit,
1611 "parent directory ID", HFILL }},
1612 { &hf_afp_file_bitmap_CreateDate,
1613 { "creation date", "afp.file_bitmap.create_date",
1614 FT_BOOLEAN, 16, NULL, kFPCreateDateBit,
1615 "file creation date", HFILL }},
1616 { &hf_afp_file_bitmap_ModDate,
1617 { "modification date", "afp.file_bitmap.mod_date",
1618 FT_BOOLEAN, 16, NULL, kFPModDateBit,
1619 "file modification date", HFILL }},
1620 { &hf_afp_file_bitmap_BackupDate,
1621 { "backup date", "afp.file_bitmap.backup_date",
1622 FT_BOOLEAN, 16, NULL, kFPBackupDateBit,
1623 "file backup date", HFILL }},
1624 { &hf_afp_file_bitmap_FinderInfo,
1625 { "Finder info", "afp.file_bitmap.finder_info",
1626 FT_BOOLEAN, 16, NULL, kFPFinderInfoBit,
1627 "file finder info", HFILL }},
1628 { &hf_afp_file_bitmap_LongName,
1629 { "long name", "afp.file_bitmap.long_name",
1630 FT_BOOLEAN, 16, NULL, kFPLongNameBit,
1631 "file long name", HFILL }},
1632 { &hf_afp_file_bitmap_ShortName,
1633 { "short name", "afp.file_bitmap.short_name",
1634 FT_BOOLEAN, 16, NULL, kFPShortNameBit,
1635 "file short name", HFILL }},
1636 { &hf_afp_file_bitmap_NodeID,
1637 { "file ID", "afp.file_bitmap.fid",
1638 FT_BOOLEAN, 16, NULL, kFPNodeIDBit,
1639 "file file ID", HFILL }},
1640 { &hf_afp_file_bitmap_UTF8Name,
1641 { "UTF8 name", "afp.file_bitmap.UTF8_name",
1642 FT_BOOLEAN, 16, NULL, kFPUTF8NameBit,
1643 "file UTF8 name", HFILL }},
1644 { &hf_afp_file_bitmap_UnixPrivs,
1645 { "unix privs", "afp.file_bitmap.unix_privs",
1646 FT_BOOLEAN, 16, NULL, kFPUnixPrivsBit,
1647 "file unix privs", HFILL }},
1650 { "Volume", "afp.vol_name",
1651 FT_UINT_STRING, BASE_NONE, NULL, 0x0,
1652 "Volume name", HFILL }},
1654 { "volume id", "afp.vol_id",
1655 FT_UINT16, BASE_DEC, NULL, 0x0,
1656 "Volume id", HFILL }},
1657 { &hf_afp_vol_signature,
1658 { "signature", "afp.vol_signature",
1659 FT_UINT16, BASE_DEC, VALS(vol_signature_vals), 0x0,
1660 "Volume signature", HFILL }},
1661 { &hf_afp_bitmap_offset,
1662 { "offset", "afp.bitmap_offset",
1663 FT_UINT16, BASE_DEC, NULL, 0x0,
1664 "name offset in packet", HFILL }},
1665 { &hf_afp_vol_creation_date,
1666 { "creation date", "afp.vol_creation_date",
1667 FT_UINT32, BASE_HEX, NULL, 0x0,
1668 "volume creation date", HFILL }},
1669 { &hf_afp_vol_modification_date,
1670 { "modification date", "afp.vol_modification_date",
1671 FT_UINT32, BASE_HEX, NULL, 0x0,
1672 "volume modification date", HFILL }},
1673 { &hf_afp_vol_backup_date,
1674 { "backup date", "afp.vol_backup_date",
1675 FT_UINT32, BASE_HEX, NULL, 0x0,
1676 "volume backup date", HFILL }},
1677 { &hf_afp_vol_bytes_free,
1678 { "bytes free", "afp.vol_bytes_free",
1679 FT_UINT32, BASE_DEC, NULL, 0x0,
1680 "free space", HFILL }},
1681 { &hf_afp_vol_bytes_total,
1682 { "bytes total", "afp.vol_bytes_total",
1683 FT_UINT32, BASE_DEC, NULL, 0x0,
1684 "volume size ", HFILL }},
1685 { &hf_afp_vol_ex_bytes_free,
1686 { "ex. bytes free", "afp.vol_ex_bytes_free",
1687 FT_UINT64, BASE_DEC, NULL, 0x0,
1688 "ex. free space", HFILL }},
1689 { &hf_afp_vol_ex_bytes_total,
1690 { "ex. bytes total", "afp.vol_ex_bytes_total",
1691 FT_UINT64, BASE_DEC, NULL, 0x0,
1692 "ex. volume size ", HFILL }},
1693 { &hf_afp_vol_block_size,
1694 { "block size", "afp.vol_block_size",
1695 FT_UINT32, BASE_DEC, NULL, 0x0,
1696 "volume block size", HFILL }},
1700 FT_UINT32, BASE_DEC, NULL, 0x0,
1701 "parent directory id", HFILL }},
1703 { &hf_afp_dir_bitmap,
1704 { "dir bitmap", "afp.dir_bitmap",
1705 FT_UINT16, BASE_HEX, NULL, 0x0,
1706 "directory bitmap", HFILL }},
1708 { &hf_afp_dir_off_spring,
1709 { "off spring", "afp.dir_off_spring",
1710 FT_UINT16, BASE_DEC, NULL, 0x0,
1711 "directory offspring", HFILL }},
1713 { &hf_afp_creation_date,
1714 { "creation date", "afp.creation_date",
1715 FT_UINT32, BASE_HEX, NULL, 0x0,
1716 "creation date", HFILL }},
1717 { &hf_afp_modification_date,
1718 { "modification date", "afp.modification_date",
1719 FT_UINT32, BASE_HEX, NULL, 0x0,
1720 "modification date", HFILL }},
1721 { &hf_afp_backup_date,
1722 { "backup date", "afp.backup_date",
1723 FT_UINT32, BASE_HEX, NULL, 0x0,
1724 "backup date", HFILL }},
1726 { &hf_afp_finder_info,
1727 { "finder info", "afp.finder_info",
1728 FT_BYTES, BASE_HEX, NULL, 0x0,
1729 "finder info", HFILL }},
1732 { "file id", "afp.file_id",
1733 FT_UINT32, BASE_DEC, NULL, 0x0,
1734 "file/directory id", HFILL }},
1736 { &hf_afp_file_bitmap,
1737 { "file bitmap", "afp.file_bitmap",
1738 FT_UINT16, BASE_HEX, NULL, 0x0,
1739 "file bitmap", HFILL }},
1741 { &hf_afp_req_count,
1742 { "req count", "afp.req_count",
1743 FT_UINT16, BASE_DEC, NULL, 0x0,
1744 "Maximum number of structures returned", HFILL }},
1746 { & hf_afp_start_index,
1747 { "start index", "afp.start_index",
1748 FT_UINT16, BASE_DEC, NULL, 0x0,
1749 "first structure returned", HFILL }},
1751 { &hf_afp_max_reply_size,
1752 { "reply size", "afp.reply_size",
1753 FT_UINT16, BASE_DEC, NULL, 0x0,
1754 "first structure returned", HFILL }},
1756 { &hf_afp_file_flag,
1757 { "dir", "afp.flag",
1758 FT_BOOLEAN, 8, NULL, 0x80,
1759 "is a dir", HFILL }},
1761 { &hf_afp_struct_size,
1762 { "struct size", "afp.struct_size",
1763 FT_UINT8, BASE_DEC, NULL,0,
1764 "sizeof of struct", HFILL }},
1767 { "from", "afp.flag",
1768 FT_UINT8, BASE_HEX, VALS(flag_vals), 0x80,
1769 "offset is relative to start/end of the fork", HFILL }},
1772 { "fork", "afp.ofork",
1773 FT_UINT16, BASE_DEC, NULL, 0x0,
1774 "Open fork reference number", HFILL }},
1777 { "offset", "afp.offset",
1778 FT_INT32, BASE_DEC, NULL, 0x0,
1779 "offset ", HFILL }},
1782 { "count", "afp.rw_count",
1783 FT_INT32, BASE_DEC, NULL, 0x0,
1784 "number of bytes to be written ", HFILL }},
1786 { &hf_afp_path_type,
1787 { "path type ", "afp.path_type",
1788 FT_UINT8, BASE_HEX, VALS(path_type_vals), 0,
1789 "type of names", HFILL }},
1791 { &hf_afp_path_name,
1792 { "Name ", "afp.path_name",
1793 FT_UINT_STRING, BASE_NONE, NULL, 0x0,
1794 "path name", HFILL }},
1796 { &hf_afp_fork_type,
1797 { "ressource fork", "afp.fork_type",
1798 FT_BOOLEAN, 8, NULL, 0x80,
1799 "data/ressource fork", HFILL }},
1801 { &hf_afp_access_mode,
1802 { "access mode", "afp.access",
1803 FT_UINT8, BASE_HEX, NULL, 0x0,
1804 "fork access mode", HFILL }},
1805 { &hf_afp_access_read,
1806 { "read", "afp.access.read",
1807 FT_BOOLEAN, 8, NULL, 1,
1808 "open for reading", HFILL }},
1809 { &hf_afp_access_write,
1810 { "write", "afp.access.write",
1811 FT_BOOLEAN, 8, NULL, 1,
1812 "open for writing", HFILL }},
1813 { &hf_afp_access_deny_read,
1814 { "deny read", "afp.access.deny_read",
1815 FT_BOOLEAN, 8, NULL, 1,
1816 "deny read", HFILL }},
1817 { &hf_afp_access_deny_write,
1818 { "deny write", "afp.access.deny_write",
1819 FT_BOOLEAN, 8, NULL, 1,
1820 "deny write", HFILL }},
1824 static gint *ett[] = {
1826 &ett_afp_vol_bitmap,
1827 &ett_afp_vol_attribute,
1828 &ett_afp_dir_bitmap,
1829 &ett_afp_file_bitmap,
1831 &ett_afp_enumerate_line,
1832 &ett_afp_access_mode,
1835 proto_afp = proto_register_protocol("AppleTalk Filing Protocol", "AFP", "afp");
1836 proto_register_field_array(proto_afp, hf, array_length(hf));
1837 proto_register_subtree_array(ett, array_length(ett));
1839 register_init_routine( &afp_reinit);
1841 register_dissector("afp", dissect_afp, proto_afp);
1845 proto_reg_handoff_afp(void)
1847 data_handle = find_dissector("data");
1850 /* -------------------------------