change a whole bunch of ethereal into wireshark
[obnox/wireshark/wip.git] / epan / dissectors / packet-aim.c
1 /* packet-aim.c
2  * Routines for AIM Instant Messenger (OSCAR) dissection
3  * Copyright 2000, Ralf Hoelzer <ralf@well.com>
4  * Copyright 2004, Jelmer Vernooij <jelmer@samba.org>
5  * Copyright 2004, Devin Heitmueller <dheitmueller@netilla.com>
6  *
7  * $Id$
8  *
9  * Wireshark - Network traffic analyzer
10  * By Gerald Combs <gerald@wireshark.org>
11  * Copyright 1998 Gerald Combs
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <ctype.h>
36
37 #include <glib.h>
38
39 #include "isprint.h"
40
41 #include <epan/packet.h>
42 #include <epan/strutil.h>
43 #include <epan/emem.h>
44
45 #include "packet-tcp.h"
46 #include "packet-aim.h"
47 #include <epan/prefs.h>
48
49 #define TCP_PORT_AIM 5190
50
51 #define STRIP_TAGS 1
52
53 /* channels */
54 #define CHANNEL_NEW_CONN    0x01
55 #define CHANNEL_SNAC_DATA   0x02
56 #define CHANNEL_FLAP_ERR    0x03
57 #define CHANNEL_CLOSE_CONN  0x04
58 #define CHANNEL_KEEP_ALIVE  0x05
59
60 #define FAMILY_ALL_ERROR_INVALID_HEADER                            0x0001
61 #define FAMILY_ALL_ERROR_SERVER_RATE_LIMIT_EXCEEDED    0x0002
62 #define FAMILY_ALL_ERROR_CLIENT_RATE_LIMIT_EXCEEDED    0x0003
63 #define FAMILY_ALL_ERROR_RECIPIENT_NOT_LOGGED_IN       0x0004
64 #define FAMILY_ALL_ERROR_REQUESTED_SERVICE_UNAVAILABLE 0x0005
65 #define FAMILY_ALL_ERROR_REQUESTED_SERVICE_NOT_DEFINED 0x0006
66 #define FAMILY_ALL_ERROR_OBSOLETE_SNAC                             0x0007
67 #define FAMILY_ALL_ERROR_NOT_SUPPORTED_BY_SERVER           0x0008
68 #define FAMILY_ALL_ERROR_NOT_SUPPORTED_BY_CLIENT           0x0009
69 #define FAMILY_ALL_ERROR_REFUSED_BY_CLIENT             0x000a
70 #define FAMILY_ALL_ERROR_REPLY_TOO_BIG                 0x000b
71 #define FAMILY_ALL_ERROR_RESPONSES_LOST                0x000c
72 #define FAMILY_ALL_ERROR_REQUEST_DENIED                0x000d
73 #define FAMILY_ALL_ERROR_INCORRECT_SNAC_FORMAT         0x000e
74 #define FAMILY_ALL_ERROR_INSUFFICIENT_RIGHTS           0x000f
75 #define FAMILY_ALL_ERROR_RECIPIENT_BLOCKED             0x0010
76 #define FAMILY_ALL_ERROR_SENDER_TOO_EVIL               0x0011
77 #define FAMILY_ALL_ERROR_RECEIVER_TOO_EVIL             0x0012
78 #define FAMILY_ALL_ERROR_USER_TEMP_UNAVAILABLE         0x0013
79 #define FAMILY_ALL_ERROR_NO_MATCH                      0x0014
80 #define FAMILY_ALL_ERROR_LIST_OVERFLOW                 0x0015
81 #define FAMILY_ALL_ERROR_REQUEST_AMBIGUOUS             0x0016
82 #define FAMILY_ALL_ERROR_SERVER_QUEUE_FULL             0x0017
83 #define FAMILY_ALL_ERROR_NOT_WHILE_ON_AOL              0x0018
84
85 static const value_string aim_flap_channels[] = {
86     { CHANNEL_NEW_CONN, "New Connection" },
87     { CHANNEL_SNAC_DATA, "SNAC Data" },
88     { CHANNEL_FLAP_ERR, "FLAP-Level Error" },
89     { CHANNEL_CLOSE_CONN, "Close Connection" },
90     { CHANNEL_KEEP_ALIVE, "Keep Alive" },
91     { 0, NULL }
92 };
93
94 static const value_string aim_snac_errors[] = {
95   { FAMILY_ALL_ERROR_INVALID_HEADER, "Invalid SNAC Header" },
96   { FAMILY_ALL_ERROR_SERVER_RATE_LIMIT_EXCEEDED, "Server rate limit exceeded" },
97   { FAMILY_ALL_ERROR_CLIENT_RATE_LIMIT_EXCEEDED, "Client rate limit exceeded" },
98   { FAMILY_ALL_ERROR_RECIPIENT_NOT_LOGGED_IN, "Recipient not logged in" },
99   { FAMILY_ALL_ERROR_REQUESTED_SERVICE_UNAVAILABLE, "Requested service unavailable" },
100   { FAMILY_ALL_ERROR_REQUESTED_SERVICE_NOT_DEFINED, "Requested service not defined" },
101   { FAMILY_ALL_ERROR_OBSOLETE_SNAC, "Obsolete SNAC issued" },
102   { FAMILY_ALL_ERROR_NOT_SUPPORTED_BY_SERVER, "Not supported by server" },
103   { FAMILY_ALL_ERROR_NOT_SUPPORTED_BY_CLIENT, "Not supported by client" },
104   { FAMILY_ALL_ERROR_REFUSED_BY_CLIENT, "Refused by client" },
105   { FAMILY_ALL_ERROR_REPLY_TOO_BIG, "Reply too big" },
106   { FAMILY_ALL_ERROR_RESPONSES_LOST, "Responses lost" },
107   { FAMILY_ALL_ERROR_REQUEST_DENIED, "Request denied" },
108   { FAMILY_ALL_ERROR_INCORRECT_SNAC_FORMAT, "Incorrect SNAC format" },
109   { FAMILY_ALL_ERROR_INSUFFICIENT_RIGHTS, "Insufficient rights" },
110   { FAMILY_ALL_ERROR_RECIPIENT_BLOCKED, "Recipient blocked" },
111   { FAMILY_ALL_ERROR_SENDER_TOO_EVIL, "Sender too evil" },
112   { FAMILY_ALL_ERROR_RECEIVER_TOO_EVIL, "Receiver too evil" },
113   { FAMILY_ALL_ERROR_USER_TEMP_UNAVAILABLE, "User temporarily unavailable" },
114   { FAMILY_ALL_ERROR_NO_MATCH, "No match" },
115   { FAMILY_ALL_ERROR_LIST_OVERFLOW, "List overflow" },
116   { FAMILY_ALL_ERROR_REQUEST_AMBIGUOUS, "Request ambiguous" },
117   { FAMILY_ALL_ERROR_SERVER_QUEUE_FULL, "Server queue full" },
118   { FAMILY_ALL_ERROR_NOT_WHILE_ON_AOL, "Not while on AOL" },
119   { 0, NULL }
120 };
121
122 #define AIM_CLIENT_TLV_SCREEN_NAME                              0x0001
123 #define AIM_CLIENT_TLV_NEW_ROASTED_PASSWORD                             0x0002
124 #define AIM_CLIENT_TLV_CLIENT_ID_STRING                         0x0003
125 #define AIM_CLIENT_TLV_ERRORURL                                 0x0004
126 #define AIM_CLIENT_TLV_BOS_SERVER_STRING       0x0005
127 #define AIM_CLIENT_TLV_AUTH_COOKIE             0x0006
128 #define AIM_CLIENT_TLV_ERRORCODE                            0x0008
129 #define AIM_CLIENT_TLV_DISCONNECT_REASON                0x0009
130 #define AIM_CLIENT_TLV_RECONNECT_HOST              0x000a
131 #define AIM_CLIENT_TLV_URL                                         0x000b
132 #define AIM_CLIENT_TLV_DEBUG_DATA                          0x000c
133 #define AIM_CLIENT_TLV_FAMILY_ID                       0x000d
134 #define AIM_CLIENT_TLV_CLIENT_COUNTRY          0x000e
135 #define AIM_CLIENT_TLV_CLIENT_LANGUAGE         0x000f
136 #define AIM_CLIENT_TLV_EMAILADDR                            0x0011
137 #define AIM_CLIENT_TLV_OLD_ROASTED_PASSWORD     0x0012
138 #define AIM_CLIENT_TLV_REGSTATUS                            0x0013
139 #define AIM_CLIENT_TLV_CLIENT_DISTRIBUTION_NUM 0x0014
140 #define AIM_CLIENT_TLV_INVITEMESSAGE                    0x0015
141 #define AIM_CLIENT_TLV_CLIENT_ID               0x0016
142 #define AIM_CLIENT_TLV_CLIENT_MAJOR_VERSION    0x0017
143 #define AIM_CLIENT_TLV_CLIENT_MINOR_VERSION    0x0018
144 #define AIM_CLIENT_TLV_CLIENT_LESSER_VERSION   0x0019
145 #define AIM_CLIENT_TLV_CLIENT_BUILD_NUMBER     0x001a
146 #define AIM_CLIENT_TLV_PASSWORD_MD5                     0x0025
147 #define AIM_CLIENT_TLV_LATESTBETABUILD          0x0040
148 #define AIM_CLIENT_TLV_LATESTBETAURL            0x0041
149 #define AIM_CLIENT_TLV_LATESTBETAINFO           0x0042
150 #define AIM_CLIENT_TLV_LATESTBETANAME           0x0043
151 #define AIM_CLIENT_TLV_LATESTRELEASEBUILD       0x0044
152 #define AIM_CLIENT_TLV_LATESTRELEASEURL         0x0045
153 #define AIM_CLIENT_TLV_LATESTRELEASEINFO        0x0046
154 #define AIM_CLIENT_TLV_LATESTRELEASENAME        0x0047
155 #define AIM_CLIENT_TLV_BETA_DIGEST_SIG          0x0048
156 #define AIM_CLIENT_TLV_RELEASE_DIGEST_SIG   0x0049
157 #define AIM_CLIENT_TLV_CLIENTUSESSI                     0x004a
158 #define AIM_CLIENT_TLV_CHANGE_PASSWORD_URL              0x0054
159 #define AIM_CLIENT_TLV_AWAITING_AUTH            0x0066
160 #define AIM_CLIENT_TLV_MEMBERS                          0x00c8
161 #define AIM_CLIENT_TLV_VISIBILITY_BITS          0x00c9
162 #define AIM_CLIENT_TLV_PRIVACY                          0x00ca
163 #define AIM_CLIENT_TLV_VISIBLE_CLASS            0x00cb
164 #define AIM_CLIENT_TLV_VISIBLE_MISC                     0x00cc
165 #define AIM_CLIENT_TLV_ICQ2K_SHORTCUT           0x00cd
166 #define AIM_CLIENT_TLV_FIRST_LOADED_TIME        0x00d4
167 #define AIM_CLIENT_TLV_BUDDY_ICON_MD5SUM        0x00d5
168 #define AIM_CLIENT_TLV_GIVEN_NAME                       0x0131
169 #define AIM_CLIENT_TLV_LOCAL_EMAIL                      0x0137
170 #define AIM_CLIENT_TLV_LOCAL_SMS                        0x013a
171 #define AIM_CLIENT_TLV_LOCAL_COMMENT            0x013c
172 #define AIM_CLIENT_TLV_LOCAL_PERSONAL_ALERT 0x013d
173 #define AIM_CLIENT_TLV_LOCAL_PERSONAL_SOUND     0x013e
174 #define AIM_CLIENT_TLV_FIRST_MESSAGE_SENT       0x0145
175
176 const aim_tlv client_tlvs[] = {
177   {  AIM_CLIENT_TLV_SCREEN_NAME, "Screen name", dissect_aim_tlv_value_string },
178   {  AIM_CLIENT_TLV_NEW_ROASTED_PASSWORD, "Roasted password array", dissect_aim_tlv_value_bytes  },
179   {  AIM_CLIENT_TLV_OLD_ROASTED_PASSWORD, "Old roasted password array", dissect_aim_tlv_value_bytes  },
180   {  AIM_CLIENT_TLV_CLIENT_ID_STRING, "Client id string (name, version)", dissect_aim_tlv_value_string },
181   {  AIM_CLIENT_TLV_CLIENT_ID, "Client id number", dissect_aim_tlv_value_uint16 },
182   {  AIM_CLIENT_TLV_CLIENT_MAJOR_VERSION, "Client major version", dissect_aim_tlv_value_uint16 },
183   {  AIM_CLIENT_TLV_CLIENT_MINOR_VERSION, "Client minor version", dissect_aim_tlv_value_uint16 },
184   {  AIM_CLIENT_TLV_CLIENT_LESSER_VERSION, "Client lesser version", dissect_aim_tlv_value_uint16 },
185   {  AIM_CLIENT_TLV_CLIENT_BUILD_NUMBER, "Client build number", dissect_aim_tlv_value_uint16 },
186   {  AIM_CLIENT_TLV_PASSWORD_MD5, "Password Hash (MD5)", dissect_aim_tlv_value_bytes },
187   {  AIM_CLIENT_TLV_CLIENT_DISTRIBUTION_NUM, "Client distribution number", dissect_aim_tlv_value_uint16 },
188   {  AIM_CLIENT_TLV_CLIENT_LANGUAGE, "Client language", dissect_aim_tlv_value_string },
189   {  AIM_CLIENT_TLV_CLIENT_COUNTRY, "Client country", dissect_aim_tlv_value_string },
190   {  AIM_CLIENT_TLV_BOS_SERVER_STRING, "BOS server string", dissect_aim_tlv_value_string },
191   {  AIM_CLIENT_TLV_AUTH_COOKIE, "Authorization cookie", dissect_aim_tlv_value_bytes },
192   {  AIM_CLIENT_TLV_ERRORURL, "Error URL", dissect_aim_tlv_value_string },
193   {  AIM_CLIENT_TLV_ERRORCODE, "Error Code", dissect_aim_tlv_value_uint16 }, 
194   {  AIM_CLIENT_TLV_DISCONNECT_REASON, "Disconnect Reason", dissect_aim_tlv_value_uint16 },
195   {  AIM_CLIENT_TLV_RECONNECT_HOST, "Reconnect Hostname", dissect_aim_tlv_value_string },
196   {  AIM_CLIENT_TLV_URL, "URL", dissect_aim_tlv_value_string },
197   {  AIM_CLIENT_TLV_DEBUG_DATA, "Debug Data", dissect_aim_tlv_value_uint16 },
198   {  AIM_CLIENT_TLV_EMAILADDR, "Account Email address", dissect_aim_tlv_value_string },
199   {  AIM_CLIENT_TLV_REGSTATUS, "Registration Status", dissect_aim_tlv_value_uint16 },
200   {  AIM_CLIENT_TLV_LATESTBETABUILD, "Latest Beta Build", dissect_aim_tlv_value_uint32 },
201   {  AIM_CLIENT_TLV_LATESTBETAURL, "Latest Beta URL", dissect_aim_tlv_value_string },
202   {  AIM_CLIENT_TLV_LATESTBETAINFO, "Latest Beta Info", dissect_aim_tlv_value_string },
203   {  AIM_CLIENT_TLV_LATESTBETANAME, "Latest Beta Name", dissect_aim_tlv_value_string },
204   {  AIM_CLIENT_TLV_LATESTRELEASEBUILD, "Latest Release Build", dissect_aim_tlv_value_uint32 },
205   {  AIM_CLIENT_TLV_LATESTRELEASEURL, "Latest Release URL", dissect_aim_tlv_value_string },
206   {  AIM_CLIENT_TLV_LATESTRELEASEINFO, "Latest Release Info", dissect_aim_tlv_value_string  },
207   {  AIM_CLIENT_TLV_LATESTRELEASENAME, "Latest Release Name", dissect_aim_tlv_value_string },
208   {  AIM_CLIENT_TLV_BETA_DIGEST_SIG, "Beta Digest Signature (MD5)" , dissect_aim_tlv_value_bytes },
209   {  AIM_CLIENT_TLV_RELEASE_DIGEST_SIG, "Release Digest Signature (MD5)", dissect_aim_tlv_value_bytes },
210   {  AIM_CLIENT_TLV_CLIENTUSESSI, "Use SSI", dissect_aim_tlv_value_uint8 },
211   {  AIM_CLIENT_TLV_FAMILY_ID, "Service (SNAC Family) ID", dissect_aim_tlv_value_uint16 },
212   { AIM_CLIENT_TLV_CHANGE_PASSWORD_URL, "Change password url", dissect_aim_tlv_value_string },
213   { AIM_CLIENT_TLV_AWAITING_AUTH, "Awaiting Authorization", dissect_aim_tlv_value_bytes },
214   { AIM_CLIENT_TLV_MEMBERS, "Members of this Group", dissect_aim_tlv_value_bytes },
215   { AIM_CLIENT_TLV_VISIBILITY_BITS, "Bitfield", dissect_aim_tlv_value_bytes },
216   { AIM_CLIENT_TLV_PRIVACY, "Privacy Settings" , dissect_aim_tlv_value_uint8 },
217   { AIM_CLIENT_TLV_VISIBLE_CLASS, "Visible To Classes", dissect_aim_tlv_value_userclass },
218   { AIM_CLIENT_TLV_VISIBLE_MISC, "Allow Others to See Data", dissect_aim_tlv_value_bytes },
219   { AIM_CLIENT_TLV_ICQ2K_SHORTCUT, "ICQ2K Shortcut List", dissect_aim_tlv_value_string },
220   { AIM_CLIENT_TLV_FIRST_LOADED_TIME, "First Time Buddy Was Added (Unix Timestamp)" , dissect_aim_tlv_value_uint32 },
221   { AIM_CLIENT_TLV_BUDDY_ICON_MD5SUM, "MD5SUM of Current Buddy Icon", dissect_aim_tlv_value_bytes },
222   { AIM_CLIENT_TLV_GIVEN_NAME, "Locally Specified Buddy Name", dissect_aim_tlv_value_string },
223   { AIM_CLIENT_TLV_LOCAL_EMAIL, "Locally Specified Buddy Email", dissect_aim_tlv_value_string },
224   { AIM_CLIENT_TLV_LOCAL_SMS, "Locally Specified Buddy SMS", dissect_aim_tlv_value_string },
225   { AIM_CLIENT_TLV_LOCAL_COMMENT, "Locally Specified Buddy Comment", dissect_aim_tlv_value_string },
226   { AIM_CLIENT_TLV_LOCAL_PERSONAL_ALERT, "Personal Alert for Buddy", dissect_aim_tlv_value_uint16 },
227   { AIM_CLIENT_TLV_LOCAL_PERSONAL_SOUND, "Personal Sound for Buddy", dissect_aim_tlv_value_string },
228   { AIM_CLIENT_TLV_FIRST_MESSAGE_SENT, " First Time Message Sent to Buddy (Unix Timestamp)", dissect_aim_tlv_value_uint32 },
229   { 0, NULL, NULL },
230 };
231
232
233 static int dissect_aim_tlv_value_userstatus(proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_);
234 static int dissect_aim_tlv_value_dcinfo(proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_);
235
236 #define AIM_ONLINEBUDDY_USERCLASS      0x0001
237 #define AIM_ONLINEBUDDY_ONSINCE        0x0003
238 #define AIM_ONLINEBUDDY_IDLETIME       0x0004
239 #define AIM_ONLINEBUDDY_MEMBERSINCE        0x0005
240 #define AIM_ONLINEBUDDY_STATUS         0x0006
241 #define AIM_ONLINEBUDDY_TIMEUPDATE         0x0011
242 #define AIM_ONLINEBUDDY_IPADDR         0x000a
243 #define AIM_ONLINEBUDDY_DCINFO             0x000c
244 #define AIM_ONLINEBUDDY_CAPINFO        0x000d
245 #define AIM_ONLINEBUDDY_UNKNOWN        0x000e
246 #define AIM_ONLINEBUDDY_SESSIONLEN     0x000f
247 #define AIM_ONLINEBUDDY_ICQSESSIONLEN  0x0010
248 #define AIM_ONLINEBUDDY_AVAILMSG           0x001d
249
250 const aim_tlv onlinebuddy_tlvs[] = {
251   { AIM_ONLINEBUDDY_USERCLASS, "User class", dissect_aim_tlv_value_userclass },
252   { AIM_ONLINEBUDDY_ONSINCE, "Online since", dissect_aim_tlv_value_uint32 },
253   { AIM_ONLINEBUDDY_IDLETIME, "Idle time (sec)", dissect_aim_tlv_value_uint16 },
254   { AIM_ONLINEBUDDY_STATUS, "Online status", dissect_aim_tlv_value_userstatus },
255   { AIM_ONLINEBUDDY_IPADDR, "User IP Address", dissect_aim_tlv_value_ipv4 },
256   { AIM_ONLINEBUDDY_DCINFO, "DC Info", dissect_aim_tlv_value_dcinfo},
257   { AIM_ONLINEBUDDY_CAPINFO, "Capability Info", dissect_aim_tlv_value_client_capabilities },
258   { AIM_ONLINEBUDDY_MEMBERSINCE, "Member since", dissect_aim_tlv_value_time },
259   { AIM_ONLINEBUDDY_UNKNOWN, "Unknown", dissect_aim_tlv_value_uint16 },
260   { AIM_ONLINEBUDDY_TIMEUPDATE, "Time update", dissect_aim_tlv_value_bytes },
261   { AIM_ONLINEBUDDY_SESSIONLEN, "Session Length (sec)", dissect_aim_tlv_value_uint32 },
262   { AIM_ONLINEBUDDY_ICQSESSIONLEN, "ICQ Session Length (sec)", dissect_aim_tlv_value_uint32 },
263   { AIM_ONLINEBUDDY_AVAILMSG, "Available Message", dissect_aim_tlv_value_bytes },
264   { 0, NULL, NULL }
265 };
266
267 #define DC_DISABLED             0x0000
268 #define DC_HTTPS                0x0001
269 #define DC_SOCKS                0x0002
270 #define DC_NORMAL               0x0003
271 #define DC_IMPOSSIBLE   0x0004
272
273 static const value_string dc_types[] = {
274         { DC_DISABLED, "DC disabled" },
275         { DC_HTTPS, "DC thru firewall or HTTPS proxy" },
276         { DC_SOCKS, "DC thru SOCKS proxy" },
277         { DC_NORMAL, "Regular connection" },
278         { DC_IMPOSSIBLE, "DC not possible " },
279         { 0, NULL },
280 };
281
282 #define PROTO_VERSION_ICQ98             0x0004
283 #define PROTO_VERSION_ICQ99             0x0006
284 #define PROTO_VERSION_ICQ2K             0x0007
285 #define PROTO_VERSION_ICQ2K1    0x0008
286 #define PROTO_VERSION_ICQLITE   0x0009
287 #define PROTO_VERSION_ICQ2K3B   0x000A
288
289 static const value_string protocol_versions[] = {
290         { PROTO_VERSION_ICQ98, "ICQ '98" },
291         { PROTO_VERSION_ICQ99, "ICQ '99" },
292         { PROTO_VERSION_ICQ2K, "ICQ 2000" },
293         { PROTO_VERSION_ICQ2K1, "ICQ 2001" },
294         { PROTO_VERSION_ICQLITE, "ICQ Lite" },
295         { PROTO_VERSION_ICQ2K3B, "ICQ 2003B" },
296         { 0, NULL },
297 };
298
299 static GList *families = NULL;
300
301 #define AIM_MOTD_TLV_MOTD                                          0x000B
302
303 const aim_tlv motd_tlvs[] = {
304   { AIM_MOTD_TLV_MOTD, "Message of the day message", dissect_aim_tlv_value_string },
305   { 0, NULL, NULL }
306 };
307
308 #define CLASS_UNCONFIRMED            0x0001
309 #define CLASS_ADMINISTRATOR          0x0002
310 #define CLASS_AOL                    0x0004
311 #define CLASS_COMMERCIAL             0x0008
312 #define CLASS_FREE                   0x0010
313 #define CLASS_AWAY                   0x0020
314 #define CLASS_ICQ                    0x0040
315 #define CLASS_WIRELESS               0x0080
316 #define CLASS_UNKNOWN100             0x0100
317 #define CLASS_UNKNOWN200             0x0200
318 #define CLASS_UNKNOWN400             0x0400
319 #define CLASS_UNKNOWN800             0x0800
320
321 #define FNAC_FLAG_NEXT_IS_RELATED        0x0001
322 #define FNAC_FLAG_CONTAINS_VERSION       0x8000
323
324 #define FNAC_TLV_FAMILY_VERSION  0x0001
325
326 static const aim_tlv fnac_tlvs[] = {
327   { FNAC_TLV_FAMILY_VERSION, "SNAC Family Version", dissect_aim_tlv_value_uint16 },
328   { 0, NULL, NULL }
329 };
330
331 static int dissect_aim(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
332 static guint get_aim_pdu_len(tvbuff_t *tvb, int offset);
333 static void dissect_aim_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
334
335 static void dissect_aim_newconn(tvbuff_t *tvb, packet_info *pinfo, int offset, proto_tree *tree);
336 static void dissect_aim_snac(tvbuff_t *tvb, packet_info *pinfo, 
337                              int offset, proto_tree *tree, proto_tree *root_tree);
338 static void dissect_aim_flap_err(tvbuff_t *tvb, packet_info *pinfo, 
339                                  int offset, proto_tree *tree);
340 static void dissect_aim_keep_alive(tvbuff_t *tvb, packet_info *pinfo, 
341                                    int offset, proto_tree *tree);
342 static void dissect_aim_close_conn(tvbuff_t *tvb, packet_info *pinfo, 
343                                    int offset, proto_tree *tree);
344 static void dissect_aim_unknown_channel(tvbuff_t *tvb, packet_info *pinfo, 
345                                         int offset, proto_tree *tree);
346
347 static dissector_table_t subdissector_table;
348
349 /* Initialize the protocol and registered fields */
350 static int proto_aim = -1;
351 static int hf_aim_cmd_start = -1;
352 static int hf_aim_channel = -1;
353 static int hf_aim_seqno = -1;
354 static int hf_aim_data = -1;
355 static int hf_aim_data_len = -1;
356 static int hf_aim_signon_challenge_len = -1;
357 static int hf_aim_signon_challenge = -1;
358 static int hf_aim_fnac_family = -1;
359 static int hf_aim_fnac_subtype = -1;
360 static int hf_aim_fnac_flags = -1;
361 static int hf_aim_fnac_flag_next_is_related = -1;
362 static int hf_aim_fnac_flag_contains_version = -1;
363 static int hf_aim_fnac_id = -1;
364 static int hf_aim_infotype = -1;
365 static int hf_aim_buddyname_len = -1;
366 static int hf_aim_buddyname = -1;
367 static int hf_aim_userinfo_warninglevel = -1;
368 static int hf_aim_snac_error = -1;
369 static int hf_aim_tlvcount = -1;
370 static int hf_aim_version = -1;
371 static int hf_aim_userclass_unconfirmed = -1;
372 static int hf_aim_userclass_administrator = -1;
373 static int hf_aim_userclass_aol = -1;
374 static int hf_aim_userclass_commercial = -1;
375 static int hf_aim_userclass_free = -1;
376 static int hf_aim_userclass_away = -1;
377 static int hf_aim_userclass_icq = -1;
378 static int hf_aim_userclass_wireless = -1;
379 static int hf_aim_userclass_unknown100 = -1;
380 static int hf_aim_userclass_unknown200 = -1;
381 static int hf_aim_userclass_unknown400 = -1;
382 static int hf_aim_userclass_unknown800 = -1;
383 static int hf_aim_messageblock_featuresdes = -1;
384 static int hf_aim_messageblock_featureslen = -1;
385 static int hf_aim_messageblock_features = -1;
386 static int hf_aim_messageblock_info = -1;
387 static int hf_aim_messageblock_len = -1;
388 static int hf_aim_messageblock_charset = -1;
389 static int hf_aim_messageblock_charsubset = -1;
390 static int hf_aim_messageblock_message = -1;
391
392 static int hf_aim_dcinfo_ip = -1;
393 static int hf_aim_dcinfo_tcpport = -1;
394 static int hf_aim_dcinfo_type = -1;
395 static int hf_aim_dcinfo_proto_version = -1;
396 static int hf_aim_dcinfo_auth_cookie = -1;
397 static int hf_aim_dcinfo_webport = -1;
398 static int hf_aim_dcinfo_client_future = -1;
399 static int hf_aim_dcinfo_last_info_update = -1;
400 static int hf_aim_dcinfo_last_ext_info_update = -1;
401 static int hf_aim_dcinfo_last_ext_status_update = -1;
402 static int hf_aim_dcinfo_unknown = -1;
403
404 /* Initialize the subtree pointers */
405 static gint ett_aim          = -1;
406 static gint ett_aim_dcinfo       = -1;
407 static gint ett_aim_buddyname= -1;
408 static gint ett_aim_fnac     = -1;
409 static gint ett_aim_fnac_flags = -1;
410 static gint ett_aim_tlv      = -1;
411 static gint ett_aim_userclass = -1;
412 static gint ett_aim_messageblock = -1;
413 static gint ett_aim_client_capabilities = -1;
414
415 /* desegmentation of AIM over TCP */
416 static gboolean aim_desegment = TRUE;
417
418 /* Code to actually dissect the packets */
419 static int dissect_aim(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
420 {
421 /* check, if this is really an AIM packet, they start with 0x2a */
422 /* XXX - I've seen some stuff starting with 0x5a followed by 0x2a */
423
424   if(tvb_bytes_exist(tvb, 0, 1) && tvb_get_guint8(tvb, 0) != 0x2a) {
425     /* Not an instant messenger packet, just happened to use the same port */
426     /* XXX - if desegmentation disabled, this might be a continuation
427        packet, not a non-AIM packet */
428     return 0;
429   }
430
431   tcp_dissect_pdus(tvb, pinfo, tree, aim_desegment, 6, get_aim_pdu_len,
432         dissect_aim_pdu);
433   return tvb_length(tvb);
434 }
435
436 static guint get_aim_pdu_len(tvbuff_t *tvb, int offset)
437 {
438   guint16 plen;
439
440   /*
441    * Get the length of the AIM packet.
442    */
443   plen = tvb_get_ntohs(tvb, offset + 4);
444
445   /*
446    * That length doesn't include the length of the header itself; add that in.
447    */
448   return plen + 6;
449 }
450
451 static void dissect_aim_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
452 {
453   /* Header fields */
454   unsigned char  hdr_channel;           /* channel ID */
455   unsigned short hdr_sequence_no;       /* Internal frame sequence number, not needed */
456   unsigned short hdr_data_field_length; /* length of data within frame */
457
458   int offset=0;
459
460 /* Set up structures we will need to add the protocol subtree and manage it */
461   proto_item *ti;
462   proto_tree *aim_tree = NULL;
463
464 /* Make entries in Protocol column and Info column on summary display */
465   if (check_col(pinfo->cinfo, COL_PROTOCOL))
466     col_set_str(pinfo->cinfo, COL_PROTOCOL, "AIM");
467
468   if (check_col(pinfo->cinfo, COL_INFO))
469     col_add_str(pinfo->cinfo, COL_INFO, "AOL Instant Messenger");
470
471   /* get relevant header information */
472   offset += 1;          /* XXX - put the identifier into the tree? */   
473   hdr_channel           = tvb_get_guint8(tvb, offset);
474   offset += 1;
475   hdr_sequence_no       = tvb_get_ntohs(tvb, offset);
476   offset += 2;
477   hdr_data_field_length = tvb_get_ntohs(tvb, offset);
478   offset += 2;
479
480 /* In the interest of speed, if "tree" is NULL, don't do any work not
481    necessary to generate protocol tree items. */
482   if (tree) {
483     ti = proto_tree_add_item(tree, proto_aim, tvb, 0, -1, FALSE);
484     aim_tree = proto_item_add_subtree(ti, ett_aim);
485     proto_tree_add_uint(aim_tree, hf_aim_cmd_start, tvb, 0, 1, '*');
486     proto_tree_add_item(aim_tree, hf_aim_channel, tvb, 1, 1, FALSE);
487     proto_tree_add_uint(aim_tree, hf_aim_seqno, tvb, 2, 2, hdr_sequence_no);
488     proto_tree_add_uint(aim_tree, hf_aim_data_len, tvb, 4, 2, hdr_data_field_length);
489
490   }
491
492   switch(hdr_channel)
493   {
494     case CHANNEL_NEW_CONN:
495       dissect_aim_newconn(tvb, pinfo, offset, aim_tree);
496       break;
497     case CHANNEL_SNAC_DATA:
498       dissect_aim_snac(tvb, pinfo, offset, aim_tree, tree);
499       break;
500     case CHANNEL_FLAP_ERR:
501       dissect_aim_flap_err(tvb, pinfo, offset, aim_tree);
502       break;
503     case CHANNEL_CLOSE_CONN:
504       dissect_aim_close_conn(tvb, pinfo, offset, aim_tree);
505       break;
506     case CHANNEL_KEEP_ALIVE:
507      dissect_aim_keep_alive(tvb, pinfo, offset, aim_tree);
508      break;
509     default:
510       dissect_aim_unknown_channel(tvb, pinfo, offset, aim_tree);
511       break;
512   }
513
514 }
515 const aim_subtype *aim_get_subtype( guint16 famnum, guint16 subtype )
516 {
517         GList *gl = families;
518         while(gl) {
519                 aim_family *fam = gl->data;
520                 if(fam->family == famnum) {
521                         int i;
522                         for(i = 0; fam->subtypes[i].name; i++) {
523                                 if(fam->subtypes[i].id == subtype) return &(fam->subtypes[i]);
524                         }
525                 }
526                 gl = gl->next;
527         }
528
529         return NULL;
530
531 }
532
533 const aim_family *aim_get_family( guint16 famnum ) 
534 {
535         GList *gl = families;
536         while(gl) {
537                 aim_family *fam = gl->data;
538                 if(fam->family == famnum) return fam;
539                 gl = gl->next;
540         }
541
542         return NULL;
543 }
544
545 int aim_get_buddyname( char *name, tvbuff_t *tvb, int len_offset, int name_offset)
546 {
547   guint8 buddyname_length;
548
549   buddyname_length = tvb_get_guint8(tvb, len_offset);
550
551   if(buddyname_length > MAX_BUDDYNAME_LENGTH ) buddyname_length = MAX_BUDDYNAME_LENGTH;
552   tvb_get_nstringz0(tvb, name_offset, buddyname_length + 1, name);
553
554   return buddyname_length;
555 }
556
557
558 void aim_get_message( guchar *msg, tvbuff_t *tvb, int msg_offset, int msg_length)
559 {
560   int i,j,c;
561   int bracket = FALSE;
562   int max, tagchars = 0;
563   int new_offset = msg_offset;
564   int new_length = msg_length;
565
566
567
568   /* make sure nothing bigger than 1000 bytes is printed */
569   if( msg_length > 999 ) return;
570
571   memset( msg, '\0', 1000);
572   i = 0;
573   c = 0;
574
575   /* loop until HTML tag is reached - quick&dirty way to find start of message
576    * (it is nearly impossible to find the correct start offset for all client versions) */
577   while( (tagchars < 6) && (new_length > 5) )
578   {
579      j = tvb_get_guint8(tvb, new_offset);
580      if( ( (j == '<') && (tagchars == 0) ) ||
581          ( (j == 'h') && (tagchars == 1) ) ||
582          ( (j == 'H') && (tagchars == 1) ) ||
583          ( (j == 't') && (tagchars == 2) ) ||
584          ( (j == 'T') && (tagchars == 2) ) ||
585          ( (j == 'm') && (tagchars == 3) ) ||
586          ( (j == 'M') && (tagchars == 3) ) ||
587          ( (j == 'l') && (tagchars == 4) ) ||
588          ( (j == 'L') && (tagchars == 4) ) ||
589          ( (j == '>') && (tagchars == 5) ) ) tagchars++;
590      new_offset++;
591      new_length--;
592   }
593
594   /* set offset and length of message to after the first HTML tag */
595   msg_offset = new_offset;
596   msg_length = new_length;
597   max = msg_length - 1;
598   tagchars = 0;
599
600   /* find the rest of the message until either a </html> is reached or the end of the frame.
601    * All other HTML tags are stripped to display only the raw message (printable characters) */
602   while( (c < max) && (tagchars < 7) )
603   {
604      j = tvb_get_guint8(tvb, msg_offset+c);
605
606
607      /* make sure this is an HTML tag by checking the order of the chars */
608      if( ( (j == '<') && (tagchars == 0) ) ||
609          ( (j == '/') && (tagchars == 1) ) ||
610          ( (j == 'h') && (tagchars == 2) ) ||
611          ( (j == 'H') && (tagchars == 2) ) ||
612          ( (j == 't') && (tagchars == 3) ) ||
613          ( (j == 'T') && (tagchars == 3) ) ||
614          ( (j == 'm') && (tagchars == 4) ) ||
615          ( (j == 'M') && (tagchars == 4) ) ||
616          ( (j == 'l') && (tagchars == 5) ) ||
617          ( (j == 'L') && (tagchars == 5) ) ||
618          ( (j == '>') && (tagchars == 6) ) ) tagchars++;
619
620 #ifdef STRIP_TAGS
621      if( j == '<' ) bracket = TRUE;
622      if( j == '>' ) bracket = FALSE;
623      if( (isprint(j) ) && (bracket == FALSE) && (j != '>'))
624 #else
625      if( isprint(j) )
626 #endif
627      {
628        msg[i] = j;
629        i++;
630      }
631      c++;
632   }
633 }
634
635 void aim_init_family(int proto, int ett, guint16 family, const aim_subtype *subtypes) 
636 {
637         aim_family *fam = g_new(aim_family, 1);
638         fam->proto = find_protocol_by_id(proto);
639         fam->name = proto_get_protocol_short_name(fam->proto);
640         fam->family = family;
641         fam->subtypes = subtypes;
642         families = g_list_append(families, fam);
643
644         fam->proto_id = proto;
645         fam->ett = ett;
646 }
647
648 static void dissect_aim_newconn(tvbuff_t *tvb, packet_info *pinfo, 
649                                 int offset, proto_tree *tree)
650 {
651   if (check_col(pinfo->cinfo, COL_INFO)) 
652     col_add_fstr(pinfo->cinfo, COL_INFO, "New Connection");
653
654   if (tvb_length_remaining(tvb, offset) > 0) {
655           proto_tree_add_item(tree, hf_aim_version, tvb, offset, 4, FALSE);
656           offset+=4;
657           offset = dissect_aim_tlv_sequence(tvb, pinfo, offset, tree, client_tlvs);
658   }
659
660   if (tvb_length_remaining(tvb, offset) > 0)
661     proto_tree_add_item(tree, hf_aim_data, tvb, offset, -1, FALSE);
662 }
663
664
665 int dissect_aim_snac_error(tvbuff_t *tvb, packet_info *pinfo, 
666                              proto_tree *aim_tree)
667 {
668   const char *name;
669
670   if ((name = match_strval(tvb_get_ntohs(tvb, 0), aim_snac_errors)) != NULL) {
671      if (check_col(pinfo->cinfo, COL_INFO))
672                 col_add_fstr(pinfo->cinfo, COL_INFO, name);
673   }
674
675   proto_tree_add_item (aim_tree, hf_aim_snac_error,
676                            tvb, 0, 2, FALSE);
677   
678   return dissect_aim_tlv_sequence(tvb, pinfo, 2, aim_tree, client_tlvs);
679 }
680
681 int dissect_aim_userinfo(tvbuff_t *tvb, packet_info *pinfo, 
682                                  int offset, proto_tree *tree) 
683 {
684     offset = dissect_aim_buddyname(tvb, pinfo, offset, tree);
685
686     proto_tree_add_item(tree, hf_aim_userinfo_warninglevel, tvb, offset, 2, FALSE);
687     offset += 2;
688
689     return dissect_aim_tlv_list(tvb, pinfo, offset, tree, onlinebuddy_tlvs);
690 }
691
692 static int dissect_aim_fnac_flags(tvbuff_t *tvb, int offset, int len, proto_item *ti, guint16 flags)
693 {
694         proto_tree *entry = proto_item_add_subtree(ti, ett_aim_fnac_flags);
695         proto_tree_add_boolean(entry, hf_aim_fnac_flag_next_is_related, tvb, offset, len, flags);
696         proto_tree_add_boolean(entry, hf_aim_fnac_flag_contains_version, tvb, offset, len, flags);
697         return offset + len;
698 }
699
700 static void dissect_aim_snac(tvbuff_t *tvb, packet_info *pinfo, 
701                              int offset, proto_tree *aim_tree, proto_tree *root_tree)
702 {
703   guint16 family_id;
704   guint16 subtype_id;
705   guint16 flags;
706   guint32 id;
707   proto_item *ti1;
708   struct aiminfo aiminfo;
709   proto_tree *aim_tree_fnac = NULL;
710   tvbuff_t *subtvb;
711   int orig_offset;
712   const aim_subtype *subtype;
713   proto_tree *family_tree = NULL;
714   const aim_family *family;
715
716   orig_offset = offset;
717   family_id = tvb_get_ntohs(tvb, offset);
718   family = aim_get_family(family_id);
719   offset += 2;
720   subtype_id = tvb_get_ntohs(tvb, offset);
721   subtype = aim_get_subtype(family_id, subtype_id);
722   offset += 2;
723   flags = tvb_get_ntohs(tvb, offset);
724   offset += 2;
725   id = tvb_get_ntohl(tvb, offset);
726   offset += 4;
727   
728  
729   if( aim_tree )
730     {
731       offset = orig_offset;
732       ti1 = proto_tree_add_text(aim_tree, tvb, 6, 10, "FNAC: Family: %s (0x%04x), Subtype: %s (0x%04x)",
733                                 family?family->name:"Unknown", family_id,
734                                 (subtype && subtype->name)?subtype->name:"Unknown", subtype_id);
735       aim_tree_fnac = proto_item_add_subtree(ti1, ett_aim_fnac);
736
737       proto_tree_add_text (aim_tree_fnac, 
738                            tvb, offset, 2, "Family: %s (0x%04x)", family?family->name:"Unknown", family_id);
739       offset += 2;
740
741       proto_tree_add_text (aim_tree_fnac, 
742                            tvb, offset, 2, "Subtype: %s (0x%04x)", (subtype && subtype->name)?subtype->name:"Unknown", subtype_id);
743       offset += 2;
744
745       ti1 = proto_tree_add_uint(aim_tree_fnac, hf_aim_fnac_flags, tvb, offset, 
746                           2, flags);
747
748           offset = dissect_aim_fnac_flags(tvb, offset, 2, ti1, flags);
749
750       proto_tree_add_uint(aim_tree_fnac, hf_aim_fnac_id, tvb, offset,
751                           4, id);
752       offset += 4;
753     }
754   
755   if(flags & FNAC_FLAG_CONTAINS_VERSION) {
756         guint16 len = tvb_get_ntohs(tvb, offset); 
757         int oldoffset;
758         offset+=2;
759         oldoffset = offset;
760         
761         while(offset < oldoffset + len) {
762           offset = dissect_aim_tlv(tvb, pinfo, offset, aim_tree, fnac_tlvs);
763         }
764   }
765
766   subtvb = tvb_new_subset(tvb, offset, -1, -1);
767   aiminfo.tcpinfo = pinfo->private_data;
768   aiminfo.family = family_id;
769   aiminfo.subtype = subtype_id;
770   pinfo->private_data = &aiminfo;
771
772   if (check_col(pinfo->cinfo, COL_PROTOCOL) && family) {
773         col_set_str(pinfo->cinfo, COL_PROTOCOL, family->name);
774   }
775   
776   if (check_col(pinfo->cinfo, COL_INFO)) {
777          if(subtype && family) {
778                  col_set_str(pinfo->cinfo, COL_INFO, family->name);
779                  col_append_fstr(pinfo->cinfo, COL_INFO, ", %s", subtype->name);
780          } else {
781             col_set_str(pinfo->cinfo, COL_INFO, "SNAC data");
782           
783         if(family) col_append_fstr(pinfo->cinfo, COL_INFO, ", %s", family->name);
784                 else col_append_fstr(pinfo->cinfo, COL_INFO, ", Family: 0x%04x", family_id);
785
786                 col_append_fstr(pinfo->cinfo, COL_INFO, ", Subtype: 0x%04x", subtype_id);
787          }
788   }
789
790   if(aim_tree && family) 
791   {
792         proto_item *ti = proto_tree_add_item(root_tree, family->proto_id, subtvb, 0, -1, FALSE); 
793         family_tree = proto_item_add_subtree(ti, family->ett);
794         if(subtype) proto_item_append_text(ti, ", %s", subtype->name);
795   }
796
797   if(tvb_length_remaining(tvb, offset) > 0 && subtype && subtype->dissector) {
798           subtype->dissector(subtvb, pinfo, family_tree);        
799   }
800 }
801
802 static void dissect_aim_flap_err(tvbuff_t *tvb, packet_info *pinfo, 
803                                  int offset, proto_tree *tree)
804 {
805   if (check_col(pinfo->cinfo, COL_INFO)) {
806     col_add_fstr(pinfo->cinfo, COL_INFO, "FLAP error");
807   }
808
809   /* Show the undissected payload */
810   if (tvb_length_remaining(tvb, offset) > 0)
811     proto_tree_add_item(tree, hf_aim_data, tvb, offset, -1, FALSE);
812 }
813
814 static void dissect_aim_keep_alive(tvbuff_t *tvb, packet_info *pinfo, 
815                                    int offset, proto_tree *tree)
816 {
817   if (check_col(pinfo->cinfo, COL_INFO)) {
818     col_add_fstr(pinfo->cinfo, COL_INFO, "Keep Alive");
819   }
820
821   /* Show the undissected payload */
822   if (tvb_length_remaining(tvb, offset) > 0)
823     proto_tree_add_item(tree, hf_aim_data, tvb, offset, -1, FALSE);
824 }
825
826 static void dissect_aim_close_conn(tvbuff_t *tvb, packet_info *pinfo, 
827                                    int offset, proto_tree *tree)
828 {
829   if (check_col(pinfo->cinfo, COL_INFO)) {
830     col_add_fstr(pinfo->cinfo, COL_INFO, "Close Connection");
831   }       
832   
833   offset = dissect_aim_tlv_sequence(tvb, pinfo, offset, tree, client_tlvs);
834 }
835
836 static void dissect_aim_unknown_channel(tvbuff_t *tvb, packet_info *pinfo, 
837                                         int offset, proto_tree *tree)
838 {
839   if (check_col(pinfo->cinfo, COL_INFO)) {
840     col_add_fstr(pinfo->cinfo, COL_INFO, "Unknown Channel");
841   }
842
843   /* Show the undissected payload */
844   if (tvb_length_remaining(tvb, offset) > 0)
845     proto_tree_add_item(tree, hf_aim_data, tvb, offset, -1, FALSE);
846 }
847
848 int dissect_aim_buddyname(tvbuff_t *tvb, packet_info *pinfo _U_, int offset,
849                        proto_tree *tree)
850 {
851   guint8 buddyname_length = 0;
852   proto_item *ti = NULL;
853   proto_tree *buddy_tree = NULL;
854
855   buddyname_length = tvb_get_guint8(tvb, offset);
856   offset++;
857
858   if(tree) {
859       ti = proto_tree_add_text(tree, tvb, offset-1, 1+buddyname_length,
860                                "Buddy: %s",
861                                tvb_format_text(tvb, offset, buddyname_length));
862       buddy_tree = proto_item_add_subtree(ti, ett_aim_buddyname);
863       proto_tree_add_item(buddy_tree, hf_aim_buddyname_len, tvb, offset-1, 1, FALSE);
864       proto_tree_add_item(buddy_tree, hf_aim_buddyname, tvb, offset, buddyname_length, FALSE);
865   }
866
867    return offset+buddyname_length;
868 }
869
870 typedef struct _aim_client_capability
871 {
872         const char *name;
873         e_uuid_t clsid; 
874 } aim_client_capability;
875
876 static const aim_client_capability known_client_caps[] = {
877         { "Send File", 
878           {0x09461343, 0x4c7f, 0x11d1,
879             { 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}},
880
881         { "Recv File",
882             { 0x09461348, 0x4c7f, 0x11d1,
883                    { 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}},
884         
885         { "iChat",
886          {0x09460000, 0x4c7f, 0x11d1, 
887            { 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}},
888
889         { "Security",
890          {0x09460001, 0x4c7f, 0x11d1, 
891            { 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}},
892
893         { "Video Chat",
894          {0x09460100, 0x4c7f, 0x11d1, 
895            { 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}},
896
897         { "Live Video",
898          {0x09460101, 0x4c7f, 0x11d1, 
899            { 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}},
900
901         { "Camera",
902          {0x09460102, 0x4c7f, 0x11d1, 
903            { 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}},
904
905         { "iChatAV info",
906          {0x09460105, 0x4c7f, 0x11d1, 
907            { 0x82, 0x22, 0x44, 0x45, 0x45, 0x53, 0x54, 0x00}}},
908
909         { "Hiptop",
910          {0x09461323, 0x4c7f, 0x11d1, 
911            { 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}},
912
913         { "Voice Chat",
914          {0x09461341, 0x4c7f, 0x11d1, 
915                  { 0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}},
916
917         { "Direct ICQ Communication",
918          {0x09461344, 0x4c7f, 0x11d1, 
919                  {0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}},
920
921         { "Direct Instant Messaging",
922          {0x09461345, 0x4c7f, 0x11d1, 
923                  {0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}},
924
925         { "Buddy Icon",
926          {0x09461346, 0x4c7f, 0x11d1, 
927                  {0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}},
928
929         { "Add-Ins",
930          {0x09461347, 0x4c7f, 0x11d1,
931                  {0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}},
932
933         { "ICQ Server Relaying",
934          {0x09461349, 0x4c7f, 0x11d1,
935                  {0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}},
936
937         { "Games",
938          {0x0946134a, 0x4c7f, 0x11d1,
939                  {0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}},
940         
941         { "Games",
942          {0x0946134a, 0x4c7f, 0x11d1,
943                  {0x22, 0x82, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}},
944
945         { "Send Buddy List",
946          {0x0946134b, 0x4c7f, 0x11d1,
947                  {0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}},
948
949         { "AIM/ICQ Interoperability",
950          {0x0946134d, 0x4c7f, 0x11d1,
951                  {0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}},
952
953         { "ICQ UTF8 Support",
954          {0x0946134e, 0x4c7f, 0x11d1,
955                  {0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}},
956
957         { "Old ICQ UTF8 Support",
958          {0x2e7a6475, 0xfadf, 0x4dc8,
959                  {0x88, 0x6f, 0xea, 0x35, 0x95, 0xfd, 0xb6, 0xdf}}},
960
961         { "Chat",
962          {0x748f2420, 0x6287, 0x11d1, 
963                  {0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}},
964
965         { "ICQ Rich Text Format Messages",
966          {0x97b12751, 0x243c, 0x4334,
967                  {0xad, 0x22, 0xd6, 0xab, 0xf7, 0x3f, 0x14, 0x92}}},
968
969         { "AP User", 
970          {0xaa4a32b5, 0xf884, 0x48c6,
971                  {0xa3, 0xd7, 0x8c, 0x50, 0x97, 0x19, 0xfd, 0x5b}}},
972
973         { "Trillian Encryption",
974          {0xf2e7c7f4, 0xfead, 0x4dfb,
975                  {0xb2, 0x35, 0x36, 0x79, 0x8b, 0xdf, 0x00, 0x00}}},
976
977         { "Unknown 1", 
978          {0x0946f004, 0x4c7f, 0x11d1, 
979                  {0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}},
980
981         { "Unknown 2", 
982          {0x0946f004, 0x4c7f, 0x11d1, 
983                  {0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}},
984
985         { "Unknown 3",
986          {0x09460103, 0x4c7f, 0x11d1,
987                  {0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}},
988
989         { "Unknown 4",
990          {0x0946f003, 0x4c7f, 0x11d1,
991                  {0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}},
992
993         { NULL, {0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } } }
994 };
995
996 static const aim_client_capability *aim_find_capability ( e_uuid_t clsid)
997 {
998         int i;
999
1000         for(i = 0; known_client_caps[i].name; i++) 
1001         {
1002                 const aim_client_capability *caps = &(known_client_caps[i]);
1003
1004                 if(memcmp(&(caps->clsid), &clsid, sizeof(e_uuid_t)) == 0)
1005                         return caps;
1006         }
1007
1008         return NULL;
1009 }
1010
1011 int dissect_aim_capability(proto_tree *entry, tvbuff_t *tvb, int offset)
1012 {
1013         const aim_client_capability *caps = NULL;
1014         e_uuid_t clsid;
1015
1016         clsid.Data1 = tvb_get_ntohl(tvb, offset);
1017         clsid.Data2 = tvb_get_ntohs(tvb, offset+4);
1018         clsid.Data3 = tvb_get_ntohs(tvb, offset+6);
1019         tvb_memcpy(tvb, clsid.Data4, offset+8, 8);
1020
1021         caps = aim_find_capability(clsid);
1022
1023         proto_tree_add_text(entry, tvb, offset, 16, 
1024                 "%s {%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", 
1025                 caps?caps->name:"Unknown", clsid.Data1, clsid.Data2, 
1026                 clsid.Data3, clsid.Data4[0], clsid.Data4[1], clsid.Data4[2], 
1027                 clsid.Data4[3], clsid.Data4[4], clsid.Data4[5], clsid.Data4[6], 
1028                         clsid.Data4[7]
1029         );
1030
1031         return offset+16;
1032 }
1033
1034 int dissect_aim_tlv_value_client_capabilities(proto_item *ti _U_, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_)
1035 {
1036         int offset = 0;
1037         proto_tree *entry;
1038
1039         proto_item_set_text(ti, "Client Capabilities List");
1040
1041         entry = proto_item_add_subtree(ti, ett_aim_client_capabilities);
1042         
1043         while (tvb_length_remaining(tvb, offset) > 0) {
1044                 offset = dissect_aim_capability(entry, tvb, offset);
1045         }
1046
1047         return tvb_length(tvb);
1048 }
1049
1050 int dissect_aim_tlv_value_time(proto_item *ti _U_, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_)
1051 {
1052         /* FIXME */
1053         return tvb_length(tvb);
1054 }
1055
1056 int dissect_aim_userclass(tvbuff_t *tvb, int offset, int len, proto_item *ti, guint32 flags)
1057 {
1058         proto_tree *entry;
1059
1060         entry = proto_item_add_subtree(ti, ett_aim_userclass);
1061         proto_tree_add_boolean(entry, hf_aim_userclass_unconfirmed, tvb, offset, len, flags);
1062         proto_tree_add_boolean(entry, hf_aim_userclass_administrator, tvb, offset, len, flags);
1063         proto_tree_add_boolean(entry, hf_aim_userclass_aol, tvb, offset, len, flags);
1064         proto_tree_add_boolean(entry, hf_aim_userclass_commercial, tvb, offset, len, flags);
1065         proto_tree_add_boolean(entry, hf_aim_userclass_free, tvb, offset, len, flags);
1066         proto_tree_add_boolean(entry, hf_aim_userclass_away, tvb, offset, len, flags);
1067         proto_tree_add_boolean(entry, hf_aim_userclass_icq, tvb, offset, len, flags);
1068         proto_tree_add_boolean(entry, hf_aim_userclass_wireless, tvb, offset, len, flags);
1069         proto_tree_add_boolean(entry, hf_aim_userclass_unknown100, tvb, offset, len, flags);
1070         proto_tree_add_boolean(entry, hf_aim_userclass_unknown200, tvb, offset, len, flags);
1071         proto_tree_add_boolean(entry, hf_aim_userclass_unknown400, tvb, offset, len, flags);
1072         proto_tree_add_boolean(entry, hf_aim_userclass_unknown800, tvb, offset, len, flags);
1073         return offset+len;
1074 }
1075
1076 int dissect_aim_tlv_value_userclass(proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_)
1077 {
1078         guint16 value16 = tvb_get_ntohs(tvb, 0);
1079         proto_item_set_text(ti, "Value: 0x%04x", value16);
1080         return dissect_aim_userclass(tvb, 0, 2, ti, value16);
1081 }
1082
1083 static int dissect_aim_tlv_value_userstatus(proto_item *ti _U_, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_)
1084 {
1085         /* FIXME */
1086         return tvb_length(tvb);
1087 }
1088
1089 static int dissect_aim_tlv_value_dcinfo(proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_)
1090 {
1091         int offset = 0;
1092         
1093         proto_tree *dctree = proto_item_add_subtree(ti, ett_aim_dcinfo);
1094         
1095         proto_tree_add_item(dctree, hf_aim_dcinfo_ip , tvb, offset, 4, FALSE); offset+=4;
1096         proto_tree_add_item(dctree, hf_aim_dcinfo_tcpport, tvb, offset, 4, FALSE); offset+=4;
1097         proto_tree_add_item(dctree, hf_aim_dcinfo_type, tvb, offset, 1, FALSE); offset+=1;
1098         proto_tree_add_item(dctree, hf_aim_dcinfo_proto_version, tvb, offset, 2, FALSE); offset+=2;
1099         proto_tree_add_item(dctree, hf_aim_dcinfo_auth_cookie, tvb, offset, 4, FALSE); offset+=2;
1100         proto_tree_add_item(dctree, hf_aim_dcinfo_webport, tvb, offset, 4, FALSE); offset+=4;
1101         proto_tree_add_item(dctree, hf_aim_dcinfo_client_future, tvb, offset, 4, FALSE); offset+=4;
1102         proto_tree_add_item(dctree, hf_aim_dcinfo_last_info_update, tvb, offset, 4, FALSE); offset+=4;
1103         proto_tree_add_item(dctree, hf_aim_dcinfo_last_ext_info_update, tvb, offset, 4, FALSE); offset+=4;
1104         proto_tree_add_item(dctree, hf_aim_dcinfo_last_ext_status_update, tvb, offset, 4, FALSE); offset+=4;
1105         proto_tree_add_item(dctree, hf_aim_dcinfo_unknown, tvb, offset, 2, FALSE); offset+=2;
1106
1107         return offset;
1108 }
1109
1110 int dissect_aim_tlv_value_string (proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_)
1111 {
1112    guint8 *buf;
1113    gint string_len;
1114
1115    string_len = tvb_length(tvb);
1116    buf = tvb_get_ephemeral_string(tvb, 0, string_len);
1117    proto_item_set_text(ti, "Value: %s", format_text(buf, string_len));
1118    return string_len;
1119 }
1120
1121 int dissect_aim_tlv_value_bytes (proto_item *ti _U_, guint16 valueid _U_, tvbuff_t *tvb _U_, packet_info *pinfo _U_)
1122 {
1123    return tvb_length(tvb);
1124 }
1125
1126 int dissect_aim_tlv_value_uint8 (proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_){
1127   guint8 value8 = tvb_get_guint8(tvb, 0);
1128   proto_item_set_text(ti, "Value: %d", value8);
1129   return 1;
1130 }
1131
1132 int dissect_aim_tlv_value_uint16 (proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_){
1133   guint16 value16 = tvb_get_ntohs(tvb, 0);
1134   proto_item_set_text(ti, "Value: %d", value16);
1135   return 2;
1136 }
1137
1138 int dissect_aim_tlv_value_ipv4 (proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_){
1139   /* FIXME: Somewhat more readable format ? */
1140   guint32 value32 = tvb_get_ntoh24(tvb, 0);
1141   proto_item_set_text(ti, "Value: %d", value32);
1142   return 4;
1143 }
1144
1145 int dissect_aim_tlv_value_uint32 (proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_){
1146   guint32 value32 = tvb_get_ntoh24(tvb, 0);
1147   proto_item_set_text(ti, "Value: %d", value32);
1148   return 4;
1149 }
1150
1151 int dissect_aim_tlv_value_messageblock (proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_){
1152   proto_tree *entry;
1153   guint8 *buf;
1154   guint16 featurelen;
1155   guint16 blocklen;
1156   int offset=0;
1157
1158   /* Setup a new subtree */
1159   entry = proto_item_add_subtree(ti, ett_aim_messageblock);
1160
1161   /* Features descriptor */
1162   proto_tree_add_item(entry, hf_aim_messageblock_featuresdes, tvb, offset, 2,
1163                       FALSE);
1164   offset += 2;
1165
1166   /* Features Length */
1167   featurelen = tvb_get_ntohs(tvb, offset);
1168   proto_tree_add_item(entry, hf_aim_messageblock_featureslen, tvb, offset, 2,
1169                       FALSE);
1170   offset += 2;
1171
1172   /* Features (should be expanded further @@@@@@@ ) */
1173   proto_tree_add_item(entry, hf_aim_messageblock_features, tvb, offset, 
1174                       featurelen, FALSE);
1175   offset += featurelen;
1176
1177   /* There can be multiple messages in this message block */
1178   while (tvb_length_remaining(tvb, offset) > 0) {
1179     /* Info field */
1180     proto_tree_add_item(entry, hf_aim_messageblock_info, tvb, offset, 2,
1181                         FALSE);
1182     offset += 2;
1183     
1184     /* Block length (includes charset and charsubset) */
1185     blocklen = tvb_get_ntohs(tvb, offset);
1186     if (blocklen <= 4) {
1187       proto_tree_add_text(entry, tvb, offset, 2, "Invalid block length: %d",
1188         blocklen);
1189       break;
1190     }
1191     proto_tree_add_item(entry, hf_aim_messageblock_len, tvb, offset, 2,
1192                         FALSE);
1193     offset += 2;
1194     
1195     /* Character set */
1196     proto_tree_add_item(entry, hf_aim_messageblock_charset, tvb, offset, 2,
1197                         FALSE);
1198     offset += 2;
1199     
1200     /* Character subset */
1201     proto_tree_add_item(entry, hf_aim_messageblock_charsubset, tvb, offset, 2,
1202                         FALSE);
1203     offset += 2;
1204
1205     /* The actual message */
1206     buf = tvb_get_ephemeral_string(tvb, offset, blocklen - 4 );
1207     proto_item_set_text(ti, "Message: %s",
1208                         format_text(buf, blocklen - 4));
1209     proto_tree_add_item(entry, hf_aim_messageblock_message, tvb, offset, 
1210                         blocklen-4,
1211                         FALSE);
1212     offset += tvb_length_remaining(tvb, offset);
1213   }
1214
1215   return offset;
1216 }
1217
1218 /* Dissect a TLV value */
1219 int dissect_aim_tlv(tvbuff_t *tvb, packet_info *pinfo _U_, 
1220                            int offset, proto_tree *tree, const aim_tlv *tlv)
1221 {
1222   guint16 valueid;
1223   guint16 length;
1224   int i = 0;
1225   const aim_tlv *tmp;
1226   const char *desc;
1227   proto_item *ti1;
1228   proto_tree *tlv_tree;
1229   int orig_offset;
1230
1231   /* Record the starting offset so we can reuse it at the second pass */
1232   orig_offset = offset;
1233
1234   /* Get the value ID */
1235   valueid = tvb_get_ntohs(tvb, offset);
1236   offset += 2;
1237
1238   /* Figure out which entry applies from the tlv list */
1239   tmp = tlv;
1240   while (tmp[i].valueid) {
1241     if (tmp[i].valueid == valueid) {
1242       /* We found a match */
1243       break;
1244     }
1245     i++;
1246   }
1247
1248   /* At this point, we are either pointing at the correct record, or 
1249      we didn't find the record, and are pointing at the last item in the 
1250      list */
1251
1252   length = tvb_get_ntohs(tvb, offset);
1253   offset += 2;
1254   offset += length;
1255
1256   if (tree) {
1257     offset = orig_offset;
1258
1259     if (tmp[i].desc != NULL)
1260       desc = tmp[i].desc;
1261     else
1262       desc = "Unknown";
1263     
1264     ti1 = proto_tree_add_text(tree, tvb, offset, length + 4, "TLV: %s", desc);
1265
1266     tlv_tree = proto_item_add_subtree(ti1, ett_aim_tlv);
1267
1268     proto_tree_add_text(tlv_tree, tvb, offset, 2,
1269                         "Value ID: %s (0x%04x)", desc, valueid);
1270     offset += 2;
1271     
1272     proto_tree_add_text(tlv_tree, tvb, offset, 2,
1273                         "Length: %d", length);
1274     offset += 2;
1275
1276     ti1 = proto_tree_add_text(tlv_tree, tvb, offset, length,
1277                               "Value");
1278         
1279     if (tmp[i].dissector) {
1280       tmp[i].dissector(ti1, valueid, tvb_new_subset(tvb, offset, length, length), pinfo);
1281     } 
1282
1283     offset += length;
1284   }
1285
1286   /* Return the new length */
1287   return offset;
1288 }
1289
1290 int dissect_aim_tlv_sequence(tvbuff_t *tvb, packet_info *pinfo, 
1291                                                          int offset, proto_tree *tree, const aim_tlv *tlv_table)
1292 {
1293         while (tvb_length_remaining(tvb, offset) > 0) {
1294                 offset = dissect_aim_tlv(tvb, pinfo, offset, tree, tlv_table);
1295         }
1296         return offset;
1297 }
1298
1299 int dissect_aim_tlv_list(tvbuff_t *tvb, packet_info *pinfo, 
1300                            int offset, proto_tree *tree, const aim_tlv *tlv_table)
1301 {
1302     guint16 i, tlv_count = tvb_get_ntohs(tvb, offset);
1303
1304     proto_tree_add_item(tree, hf_aim_tlvcount, tvb, offset, 2, FALSE);
1305     offset += 2;
1306
1307     for(i = 0; i < tlv_count; i++) {
1308       offset = dissect_aim_tlv(tvb, pinfo, offset, tree, tlv_table);
1309     }
1310     return offset;
1311 }
1312
1313 /* Register the protocol with Wireshark */
1314 void
1315 proto_register_aim(void)
1316 {
1317
1318 /* Setup list of header fields */
1319   static hf_register_info hf[] = {
1320     { &hf_aim_cmd_start,
1321       { "Command Start", "aim.cmd_start", FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }
1322     },
1323     { &hf_aim_channel,
1324       { "Channel ID", "aim.channel", FT_UINT8, BASE_HEX, VALS(aim_flap_channels), 0x0, "", HFILL }
1325     },
1326     { &hf_aim_seqno,
1327       { "Sequence Number", "aim.seqno", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }
1328     },
1329         { &hf_aim_version,
1330           { "Protocol Version", "aim.version", FT_BYTES, BASE_DEC, NULL, 0x0, "", HFILL },
1331         },
1332     { &hf_aim_data_len,
1333       { "Data Field Length", "aim.datalen", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }
1334     },
1335     { &hf_aim_data,
1336       { "Data", "aim.data", FT_BYTES, BASE_HEX, NULL, 0x0, "", HFILL }
1337     },
1338     { &hf_aim_signon_challenge_len,
1339       { "Signon challenge length", "aim.signon.challengelen", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }
1340     },
1341     { &hf_aim_signon_challenge,
1342       { "Signon challenge", "aim.signon.challenge", FT_STRING, BASE_HEX, NULL, 0x0, "", HFILL }
1343     },
1344     { &hf_aim_fnac_family,
1345       { "FNAC Family ID", "aim.fnac.family", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }
1346     },
1347     { &hf_aim_fnac_subtype,
1348       { "FNAC Subtype ID", "aim.fnac.subtype", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }
1349     },
1350     { &hf_aim_fnac_flags,
1351       { "FNAC Flags", "aim.fnac.flags", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }
1352     },
1353     { &hf_aim_fnac_id,
1354       { "FNAC ID", "aim.fnac.id", FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL }
1355     },
1356     { &hf_aim_infotype,
1357       { "Infotype", "aim.infotype", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }
1358     },
1359     { &hf_aim_buddyname_len,
1360       { "Buddyname len", "aim.buddynamelen", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }
1361     },
1362     { &hf_aim_buddyname,
1363       { "Buddy Name", "aim.buddyname", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }
1364     },
1365     { &hf_aim_tlvcount,
1366       { "TLV Count", "aim.tlvcount", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL },
1367     },
1368         { &hf_aim_snac_error,
1369           { "SNAC Error", "aim.snac.error", FT_UINT16,
1370                   BASE_HEX, VALS(aim_snac_errors), 0x0, "", HFILL },
1371         },
1372         { &hf_aim_userclass_unconfirmed,
1373                 { "AOL Unconfirmed user flag", "aim.userclass.unconfirmed", FT_BOOLEAN, 32, TFS(&flags_set_truth), CLASS_UNCONFIRMED, "", HFILL },
1374         },
1375         { &hf_aim_userclass_administrator,
1376                 { "AOL Administrator flag", "aim.userclass.administrator", FT_BOOLEAN, 32, TFS(&flags_set_truth), CLASS_ADMINISTRATOR, "", HFILL },
1377         },
1378         { &hf_aim_userclass_aol,
1379                 { "AOL Staff User Flag", "aim.userclass.staff", FT_BOOLEAN, 32, TFS(&flags_set_truth), CLASS_AOL, "", HFILL },
1380         },
1381         { &hf_aim_userclass_commercial,
1382                 { "AOL commercial account flag", "aim.userclass.commercial", FT_BOOLEAN, 32, TFS(&flags_set_truth), CLASS_COMMERCIAL, "", HFILL },
1383         },
1384         { &hf_aim_userclass_free,
1385                 { "ICQ non-commercial account flag", "aim.userclass.noncommercial", FT_BOOLEAN, 32, TFS(&flags_set_truth), CLASS_FREE, "", HFILL },
1386         },
1387         { &hf_aim_userclass_away,
1388                 { "AOL away status flag", "aim.userclass.away", FT_BOOLEAN, 32, TFS(&flags_set_truth), CLASS_AWAY, "", HFILL },
1389         },
1390         { &hf_aim_userclass_icq,
1391                 { "ICQ user sign", "aim.userclass.icq", FT_BOOLEAN, 32, TFS(&flags_set_truth), CLASS_ICQ, "", HFILL },
1392         },
1393         { &hf_aim_userclass_wireless,
1394                 { "AOL wireless user", "aim.userclass.wireless", FT_BOOLEAN, 32, TFS(&flags_set_truth), CLASS_WIRELESS, "", HFILL },
1395         },
1396         { &hf_aim_userclass_unknown100,
1397                 { "Unknown bit", "aim.userclass.unknown100", FT_BOOLEAN, 32, TFS(&flags_set_truth), CLASS_UNKNOWN100, "", HFILL },
1398         },
1399         { &hf_aim_userclass_unknown200,
1400                 { "Unknown bit", "aim.userclass.unknown200", FT_BOOLEAN, 32, TFS(&flags_set_truth), CLASS_UNKNOWN200, "", HFILL },
1401         },
1402         { &hf_aim_userclass_unknown400,
1403                 { "Unknown bit", "aim.userclass.unknown400", FT_BOOLEAN, 32, TFS(&flags_set_truth), CLASS_UNKNOWN400, "", HFILL },
1404         },
1405         { &hf_aim_userclass_unknown800,
1406                 { "Unknown bit", "aim.userclass.unknown800", FT_BOOLEAN, 32, TFS(&flags_set_truth), CLASS_UNKNOWN800, "", HFILL },
1407         },
1408         { &hf_aim_fnac_flag_next_is_related,
1409                 { "Followed By SNAC with related information", "aim.fnac.flags.next_is_related", FT_BOOLEAN, 16, TFS(&flags_set_truth), FNAC_FLAG_NEXT_IS_RELATED, "", HFILL },
1410         },
1411         { &hf_aim_fnac_flag_contains_version,
1412                 { "Contains Version of Family this SNAC is in", "aim.fnac.flags.contains_version", FT_BOOLEAN, 16, TFS(&flags_set_truth), FNAC_FLAG_CONTAINS_VERSION, "", HFILL },
1413         },
1414         { &hf_aim_userinfo_warninglevel,
1415                 { "Warning Level", "aim.userinfo.warninglevel", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL },
1416         },
1417     { &hf_aim_messageblock_featuresdes,
1418                 { "Features", "aim.messageblock.featuresdes", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL },
1419         },
1420     { &hf_aim_messageblock_featureslen,
1421                 { "Features Length", "aim.messageblock.featureslen", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL },
1422         },
1423     { &hf_aim_messageblock_features,
1424                 { "Features", "aim.messageblock.features", FT_BYTES, BASE_HEX, NULL, 0x0, "", HFILL },
1425         },
1426     { &hf_aim_messageblock_info,
1427                 { "Block info", "aim.messageblock.info", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL },
1428         },
1429     { &hf_aim_messageblock_len,
1430                 { "Block length", "aim.messageblock.length", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL },
1431         },
1432     { &hf_aim_messageblock_charset,
1433                 { "Block Character set", "aim.messageblock.charset", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL },
1434         },
1435     { &hf_aim_messageblock_charsubset,
1436                 { "Block Character subset", "aim.messageblock.charsubset", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL },
1437         },
1438     { &hf_aim_messageblock_message,
1439                 { "Message", "aim.messageblock.message", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL },
1440         },
1441         { &hf_aim_dcinfo_ip,
1442                 { "Internal IP address", "aim.dcinfo.addr", FT_IPv4, BASE_NONE, NULL, 0x0, "", HFILL },
1443         },
1444         { &hf_aim_dcinfo_tcpport,
1445                 { "TCP Port", "aim.dcinfo.tcpport", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL },
1446         },
1447         { &hf_aim_dcinfo_type,
1448                 { "Type", "aim.dcinfo.type", FT_UINT8, BASE_HEX, VALS(dc_types), 0x0, "", HFILL },
1449         },
1450         { &hf_aim_dcinfo_proto_version,
1451                 { "Protocol Version", "aim.dcinfo.proto_version", FT_UINT16, BASE_DEC, VALS(protocol_versions), 0x0, "", HFILL },
1452         },
1453         { &hf_aim_dcinfo_auth_cookie,
1454                 { "Authorization Cookie", "aim.dcinfo.auth_cookie", FT_BYTES, BASE_NONE, NULL, 0x0, "", HFILL },
1455         },
1456         { &hf_aim_dcinfo_webport,
1457                 { "Web Front Port", "aim.dcinfo.webport", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL },
1458         },
1459         { &hf_aim_dcinfo_client_future,
1460                 { "Client Futures", "aim.dcinfo.client_futures", FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL },
1461         },
1462         { &hf_aim_dcinfo_last_info_update,
1463                 { "Last Info Update", "aim.dcinfo.last_info_update", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL },
1464         },
1465         { &hf_aim_dcinfo_last_ext_info_update,
1466                 { "Last Extended Info Update", "aim.dcinfo.last_ext_info_update", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL },
1467         },
1468         { &hf_aim_dcinfo_last_ext_status_update,
1469                 { "Last Extended Status Update", "aim.dcinfo.last_ext_status_update", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL },
1470         },
1471         { &hf_aim_dcinfo_unknown,
1472                 { "Unknown", "aim.dcinfo.unknown", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL },
1473         },
1474
1475   };
1476
1477   /* Setup protocol subtree array */
1478   static gint *ett[] = {
1479           &ett_aim,
1480           &ett_aim_dcinfo,
1481           &ett_aim_fnac,
1482           &ett_aim_fnac_flags,
1483           &ett_aim_tlv,
1484           &ett_aim_buddyname,
1485           &ett_aim_userclass,
1486           &ett_aim_messageblock,
1487           &ett_aim_client_capabilities
1488   };
1489   module_t *aim_module;
1490
1491   /* Register the protocol name and description */
1492   proto_aim = proto_register_protocol("AOL Instant Messenger", "AIM", "aim");
1493
1494 /* Required function calls to register the header fields and subtrees used */
1495   proto_register_field_array(proto_aim, hf, array_length(hf));
1496   proto_register_subtree_array(ett, array_length(ett));
1497
1498   aim_module = prefs_register_protocol(proto_aim, NULL);
1499   prefs_register_bool_preference(aim_module, "desegment",
1500     "Reassemble AIM messages spanning multiple TCP segments",
1501     "Whether the AIM dissector should reassemble messages spanning multiple TCP segments."
1502     " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
1503     &aim_desegment);
1504
1505   subdissector_table = register_dissector_table("aim.family", 
1506                 "Family ID", FT_UINT16, BASE_HEX);
1507 }
1508
1509 void
1510 proto_reg_handoff_aim(void)
1511 {
1512   dissector_handle_t aim_handle;
1513
1514   aim_handle = new_create_dissector_handle(dissect_aim, proto_aim);
1515   dissector_add("tcp.port", TCP_PORT_AIM, aim_handle);
1516 }