860dd99449f61fefb358555dc5820a6a2efe450f
[obnox/wireshark/wip.git] / 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  *
6  * $Id: packet-aim.c,v 1.41 2004/05/05 09:30:56 guy Exp $
7  *
8  * Ethereal - Network traffic analyzer
9  * By Gerald Combs <gerald@ethereal.com>
10  * Copyright 1998 Gerald Combs
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25  */
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <ctype.h>
35
36 #include <glib.h>
37
38 #include <epan/packet.h>
39 #include <epan/strutil.h>
40
41 #include "packet-tcp.h"
42 #include "packet-aim.h"
43 #include "prefs.h"
44
45 #define TCP_PORT_AIM 5190
46
47 #define STRIP_TAGS 1
48
49 /* channels */
50 #define CHANNEL_NEW_CONN    0x01
51 #define CHANNEL_SNAC_DATA   0x02
52 #define CHANNEL_FLAP_ERR    0x03
53 #define CHANNEL_CLOSE_CONN  0x04
54 #define CHANNEL_KEEP_ALIVE  0x05
55
56 #define CLI_COOKIE                  0x01
57
58 #define FAMILY_ALL_ERROR_INVALID_HEADER                            0x0001
59 #define FAMILY_ALL_ERROR_SERVER_RATE_LIMIT_EXCEEDED    0x0002
60 #define FAMILY_ALL_ERROR_CLIENT_RATE_LIMIT_EXCEEDED    0x0003
61 #define FAMILY_ALL_ERROR_RECIPIENT_NOT_LOGGED_IN       0x0004
62 #define FAMILY_ALL_ERROR_REQUESTED_SERVICE_UNAVAILABLE 0x0005
63 #define FAMILY_ALL_ERROR_REQUESTED_SERVICE_NOT_DEFINED 0x0006
64 #define FAMILY_ALL_ERROR_OBSOLETE_SNAC                             0x0007
65 #define FAMILY_ALL_ERROR_NOT_SUPPORTED_BY_SERVER           0x0008
66 #define FAMILY_ALL_ERROR_NOT_SUPPORTED_BY_CLIENT           0x0009
67 #define FAMILY_ALL_ERROR_REFUSED_BY_CLIENT             0x000a
68 #define FAMILY_ALL_ERROR_REPLY_TOO_BIG                 0x000b
69 #define FAMILY_ALL_ERROR_RESPONSES_LOST                0x000c
70 #define FAMILY_ALL_ERROR_REQUEST_DENIED                0x000d
71 #define FAMILY_ALL_ERROR_INCORRECT_SNAC_FORMAT         0x000e
72 #define FAMILY_ALL_ERROR_INSUFFICIENT_RIGHTS           0x000f
73 #define FAMILY_ALL_ERROR_RECIPIENT_BLOCKED             0x0010
74 #define FAMILY_ALL_ERROR_SENDER_TOO_EVIL               0x0011
75 #define FAMILY_ALL_ERROR_RECEIVER_TOO_EVIL             0x0012
76 #define FAMILY_ALL_ERROR_USER_TEMP_UNAVAILABLE         0x0013
77 #define FAMILY_ALL_ERROR_NO_MATCH                      0x0014
78 #define FAMILY_ALL_ERROR_LIST_OVERFLOW                 0x0015
79 #define FAMILY_ALL_ERROR_REQUEST_AMBIGUOUS             0x0016
80 #define FAMILY_ALL_ERROR_SERVER_QUEUE_FULL             0x0017
81 #define FAMILY_ALL_ERROR_NOT_WHILE_ON_AOL              0x0018
82
83 static const value_string aim_flap_channels[] = {
84     { CHANNEL_NEW_CONN, "New Connection" },
85     { CHANNEL_SNAC_DATA, "SNAC Data" },
86     { CHANNEL_FLAP_ERR, "FLAP-Level Error" },
87     { CHANNEL_CLOSE_CONN, "Close Connection" },
88     { CHANNEL_KEEP_ALIVE, "Keep Alive" },
89     { 0, NULL }
90 };
91
92 static const value_string aim_snac_errors[] = {
93   { FAMILY_ALL_ERROR_INVALID_HEADER, "Invalid SNAC Header" },
94   { FAMILY_ALL_ERROR_SERVER_RATE_LIMIT_EXCEEDED, "Server rate limit exceeded" },
95   { FAMILY_ALL_ERROR_CLIENT_RATE_LIMIT_EXCEEDED, "Client rate limit exceeded" },
96   { FAMILY_ALL_ERROR_RECIPIENT_NOT_LOGGED_IN, "Recipient not logged in" },
97   { FAMILY_ALL_ERROR_REQUESTED_SERVICE_UNAVAILABLE, "Requested service unavailable" },
98   { FAMILY_ALL_ERROR_REQUESTED_SERVICE_NOT_DEFINED, "Requested service not defined" },
99   { FAMILY_ALL_ERROR_OBSOLETE_SNAC, "Obsolete SNAC issued" },
100   { FAMILY_ALL_ERROR_NOT_SUPPORTED_BY_SERVER, "Not supported by server" },
101   { FAMILY_ALL_ERROR_NOT_SUPPORTED_BY_CLIENT, "Not supported by client" },
102   { FAMILY_ALL_ERROR_REFUSED_BY_CLIENT, "Refused by client" },
103   { FAMILY_ALL_ERROR_REPLY_TOO_BIG, "Reply too big" },
104   { FAMILY_ALL_ERROR_RESPONSES_LOST, "Responses lost" },
105   { FAMILY_ALL_ERROR_REQUEST_DENIED, "Request denied" },
106   { FAMILY_ALL_ERROR_INCORRECT_SNAC_FORMAT, "Incorrect SNAC format" },
107   { FAMILY_ALL_ERROR_INSUFFICIENT_RIGHTS, "Insufficient rights" },
108   { FAMILY_ALL_ERROR_RECIPIENT_BLOCKED, "Recipient blocked" },
109   { FAMILY_ALL_ERROR_SENDER_TOO_EVIL, "Sender too evil" },
110   { FAMILY_ALL_ERROR_RECEIVER_TOO_EVIL, "Receiver too evil" },
111   { FAMILY_ALL_ERROR_USER_TEMP_UNAVAILABLE, "User temporarily unavailable" },
112   { FAMILY_ALL_ERROR_NO_MATCH, "No match" },
113   { FAMILY_ALL_ERROR_LIST_OVERFLOW, "List overflow" },
114   { FAMILY_ALL_ERROR_REQUEST_AMBIGUOUS, "Request ambiguous" },
115   { FAMILY_ALL_ERROR_SERVER_QUEUE_FULL, "Server queue full" },
116   { FAMILY_ALL_ERROR_NOT_WHILE_ON_AOL, "Not while on AOL" },
117   { 0, NULL }
118 };
119
120 #define AIM_CLIENT_TLV_SCREEN_NAME                              0x0001
121 #define AIM_CLIENT_TLV_ROASTED_PASSWORD                         0x0002
122 #define AIM_CLIENT_TLV_CLIENT_ID_STRING                         0x0003
123 #define AIM_CLIENT_TLV_ERRORURL                                 0x0004
124 #define AIM_CLIENT_TLV_BOS_SERVER_STRING       0x0005
125 #define AIM_CLIENT_TLV_AUTH_COOKIE             0x0006
126 #define AIM_CLIENT_TLV_ERRORCODE                            0x0008
127 #define AIM_CLIENT_TLV_GENERIC_SERVICE_ID      0x000d
128 #define AIM_CLIENT_TLV_CLIENT_COUNTRY          0x000e
129 #define AIM_CLIENT_TLV_CLIENT_LANGUAGE         0x000f
130 #define AIM_CLIENT_TLV_EMAILADDR                            0x0011
131 #define AIM_CLIENT_TLV_OLD_ROASTED_PASSWORD     0x0012
132 #define AIM_CLIENT_TLV_REGSTATUS                            0x0013
133 #define AIM_CLIENT_TLV_CLIENT_DISTRIBUTION_NUM 0x0014
134 #define AIM_CLIENT_TLV_INVITEMESSAGE                    0x0015
135 #define AIM_CLIENT_TLV_CLIENT_ID               0x0016
136 #define AIM_CLIENT_TLV_CLIENT_MAJOR_VERSION    0x0017
137 #define AIM_CLIENT_TLV_CLIENT_MINOR_VERSION    0x0018
138 #define AIM_CLIENT_TLV_CLIENT_LESSER_VERSION   0x0019
139 #define AIM_CLIENT_TLV_CLIENT_BUILD_NUMBER     0x001a
140 #define AIM_CLIENT_TLV_PASSWORD                         0x0025
141 #define AIM_CLIENT_TLV_LATESTBETABUILD          0x0040
142 #define AIM_CLIENT_TLV_LATESTBETAURL            0x0041
143 #define AIM_CLIENT_TLV_LATESTBETAINFO           0x0042
144 #define AIM_CLIENT_TLV_LATESTBETANAME           0x0043
145 #define AIM_CLIENT_TLV_LATESTRELEASEBUILD       0x0044
146 #define AIM_CLIENT_TLV_LATESTRELEASEURL         0x0045
147 #define AIM_CLIENT_TLV_LATESTRELEASEINFO        0x0046
148 #define AIM_CLIENT_TLV_LATESTRELEASENAME        0x0047
149 #define AIM_CLIENT_TLV_CLIENTUSESSI                     0x004a
150 #define AIM_CLIENT_TLV_CHANGE_PASSWORD_URL              0x0054
151
152 const aim_tlv client_tlvs[] = {
153   {  AIM_CLIENT_TLV_SCREEN_NAME, "Screen name", dissect_aim_tlv_value_string },
154   {  AIM_CLIENT_TLV_ROASTED_PASSWORD, "Roasted password array", dissect_aim_tlv_value_bytes  },
155   {  AIM_CLIENT_TLV_OLD_ROASTED_PASSWORD, "Old roasted password array", dissect_aim_tlv_value_bytes  },
156   {  AIM_CLIENT_TLV_CLIENT_ID_STRING, "Client id string (name, version)", dissect_aim_tlv_value_string },
157   {  AIM_CLIENT_TLV_CLIENT_ID, "Client id number", dissect_aim_tlv_value_uint16 },
158   {  AIM_CLIENT_TLV_CLIENT_MAJOR_VERSION, "Client major version", dissect_aim_tlv_value_uint16 },
159   {  AIM_CLIENT_TLV_CLIENT_MINOR_VERSION, "Client minor version", dissect_aim_tlv_value_uint16 },
160   {  AIM_CLIENT_TLV_CLIENT_LESSER_VERSION, "Client lesser version", dissect_aim_tlv_value_uint16 },
161   {  AIM_CLIENT_TLV_CLIENT_BUILD_NUMBER, "Client build number", dissect_aim_tlv_value_uint16 },
162   {  AIM_CLIENT_TLV_CLIENT_DISTRIBUTION_NUM, "Client distribution number", dissect_aim_tlv_value_uint16 },
163   {  AIM_CLIENT_TLV_CLIENT_LANGUAGE, "Client language", dissect_aim_tlv_value_string },
164   {  AIM_CLIENT_TLV_CLIENT_COUNTRY, "Client country", dissect_aim_tlv_value_string },
165   {  AIM_CLIENT_TLV_BOS_SERVER_STRING, "BOS server string", dissect_aim_tlv_value_string },
166   {  AIM_CLIENT_TLV_AUTH_COOKIE, "Authorization cookie", dissect_aim_tlv_value_bytes },
167   {  AIM_CLIENT_TLV_ERRORURL, "Error URL", dissect_aim_tlv_value_string },
168   {  AIM_CLIENT_TLV_ERRORCODE, "Error Code", dissect_aim_tlv_value_uint16 }, /* FIXME: Decode error codes too */
169   {  AIM_CLIENT_TLV_EMAILADDR, "Account Email address", dissect_aim_tlv_value_string },
170   {  AIM_CLIENT_TLV_REGSTATUS, "Registration Status", dissect_aim_tlv_value_uint16 },
171   {  AIM_CLIENT_TLV_LATESTBETABUILD, "Latest Beta Build", dissect_aim_tlv_value_uint32 },
172   {  AIM_CLIENT_TLV_LATESTBETAURL, "Latest Beta URL", dissect_aim_tlv_value_string },
173   {  AIM_CLIENT_TLV_LATESTBETAINFO, "Latest Beta Info", dissect_aim_tlv_value_string },
174   {  AIM_CLIENT_TLV_LATESTBETANAME, "Latest Beta Name", dissect_aim_tlv_value_string },
175   {  AIM_CLIENT_TLV_LATESTRELEASEBUILD, "Latest Release Build", dissect_aim_tlv_value_uint32 },
176   {  AIM_CLIENT_TLV_LATESTRELEASEURL, "Latest Release URL", dissect_aim_tlv_value_string },
177   {  AIM_CLIENT_TLV_LATESTRELEASEINFO, "Latest Release Info", dissect_aim_tlv_value_string  },
178   {  AIM_CLIENT_TLV_LATESTRELEASENAME, "Latest Release Name", dissect_aim_tlv_value_string },
179   {  AIM_CLIENT_TLV_CLIENTUSESSI, "Use SSI", dissect_aim_tlv_value_uint8 },
180   {  AIM_CLIENT_TLV_GENERIC_SERVICE_ID, "Service (Family) ID", dissect_aim_tlv_value_uint16 },
181   { AIM_CLIENT_TLV_CHANGE_PASSWORD_URL, "Change password url", dissect_aim_tlv_value_string },
182   { 0, "Unknown", NULL },
183 };
184
185
186 static int dissect_aim_tlv_value_userstatus(proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb);
187 static int dissect_aim_tlv_value_dcinfo(proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb);
188
189 #define AIM_ONLINEBUDDY_USERCLASS      0x0001
190 #define AIM_ONLINEBUDDY_ONSINCE        0x0003
191 #define AIM_ONLINEBUDDY_IDLETIME       0x0004
192 #define AIM_ONLINEBUDDY_MEMBERSINCE        0x0005
193 #define AIM_ONLINEBUDDY_STATUS         0x0006
194 #define AIM_ONLINEBUDDY_TIMEUPDATE         0x0011
195 #define AIM_ONLINEBUDDY_IPADDR         0x000a
196 #define AIM_ONLINEBUDDY_DCINFO             0x000c
197 #define AIM_ONLINEBUDDY_CAPINFO        0x000d
198 #define AIM_ONLINEBUDDY_UNKNOWN        0x000e
199 #define AIM_ONLINEBUDDY_SESSIONLEN     0x000f
200 #define AIM_ONLINEBUDDY_ICQSESSIONLEN  0x0010
201
202 const aim_tlv onlinebuddy_tlvs[] = {
203   { AIM_ONLINEBUDDY_USERCLASS, "User class", dissect_aim_tlv_value_userclass },
204   { AIM_ONLINEBUDDY_ONSINCE, "Online since", dissect_aim_tlv_value_uint32 },
205   { AIM_ONLINEBUDDY_IDLETIME, "Idle time (sec)", dissect_aim_tlv_value_uint16 },
206   { AIM_ONLINEBUDDY_STATUS, "Online status", dissect_aim_tlv_value_userstatus },
207   { AIM_ONLINEBUDDY_IPADDR, "User IP Address", dissect_aim_tlv_value_ipv4 },
208   { AIM_ONLINEBUDDY_DCINFO, "DC Info", dissect_aim_tlv_value_dcinfo},
209   { AIM_ONLINEBUDDY_CAPINFO, "Capability Info", dissect_aim_tlv_value_bytes },
210   { AIM_ONLINEBUDDY_MEMBERSINCE, "Member since", dissect_aim_tlv_value_time },
211   { AIM_ONLINEBUDDY_UNKNOWN, "Unknown", dissect_aim_tlv_value_uint16 },
212   { AIM_ONLINEBUDDY_TIMEUPDATE, "Time update", dissect_aim_tlv_value_bytes },
213   { AIM_ONLINEBUDDY_SESSIONLEN, "Session Length (sec)", dissect_aim_tlv_value_uint32 },
214   { AIM_ONLINEBUDDY_ICQSESSIONLEN, "ICQ Session Length (sec)", dissect_aim_tlv_value_uint32 },
215   { 0, "Unknown", NULL }
216 };
217
218 struct aim_family {
219         guint16 family;
220         const char *name;
221         const value_string *subtypes;
222 };
223
224 static GList *families = NULL;
225
226 #define AIM_MOTD_TLV_MOTD                                          0x000B
227
228 const aim_tlv motd_tlvs[] = {
229   { AIM_MOTD_TLV_MOTD, "Message of the day message", dissect_aim_tlv_value_string },
230   { 0, "Unknown", NULL }
231 };
232
233 #define FAMILY_GENERIC_REDIRECT_SERVER_ADDRESS             0x0005
234 #define FAMILY_GENERIC_REDIRECT_AUTH_COOKIE                        0x0006
235 #define FAMILY_GENERIC_REDIRECT_FAMILY_ID              0x000D
236
237 static const aim_tlv aim_fnac_family_generic_redirect_tlv[] = {
238   { FAMILY_GENERIC_REDIRECT_SERVER_ADDRESS, "Server address and (optional) port", dissect_aim_tlv_value_string },
239   { FAMILY_GENERIC_REDIRECT_AUTH_COOKIE, "Authorization cookie", dissect_aim_tlv_value_string },
240   { FAMILY_GENERIC_REDIRECT_FAMILY_ID, "Family ID", dissect_aim_tlv_value_uint16 },
241   { 0, "Unknown", NULL }
242 };
243
244 #define FAMILY_GENERIC_MOTD_MOTDTYPE_MDT_UPGRADE       0x0001
245 #define FAMILY_GENERIC_MOTD_MOTDTYPE_ADV_UPGRADE       0x0002
246 #define FAMILY_GENERIC_MOTD_MOTDTYPE_SYS_BULLETIN      0x0003
247 #define FAMILY_GENERIC_MOTD_MOTDTYPE_NORMAL            0x0004
248 #define FAMILY_GENERIC_MOTD_MOTDTYPE_NEWS              0x0006
249
250 static const value_string aim_snac_generic_motd_motdtypes[] = {
251   { FAMILY_GENERIC_MOTD_MOTDTYPE_MDT_UPGRADE, "Mandatory Upgrade Needed Notice" },
252   { FAMILY_GENERIC_MOTD_MOTDTYPE_ADV_UPGRADE, "Advisable Upgrade Notice" },
253   { FAMILY_GENERIC_MOTD_MOTDTYPE_SYS_BULLETIN, "AIM/ICQ Service System Announcements" },
254   { FAMILY_GENERIC_MOTD_MOTDTYPE_NORMAL, "Standard Notice" },
255   { FAMILY_GENERIC_MOTD_MOTDTYPE_NEWS, "News from AOL service" },
256   { 0, NULL }
257 };
258
259 #define CLASS_UNCONFIRMED            0x0001
260 #define CLASS_ADMINISTRATOR          0x0002
261 #define CLASS_AOL                    0x0004
262 #define CLASS_COMMERCIAL             0x0008
263 #define CLASS_FREE                   0x0010
264 #define CLASS_AWAY                   0x0020
265 #define CLASS_ICQ                    0x0040
266 #define CLASS_WIRELESS               0x0080
267 #define CLASS_UNKNOWN100             0x0100
268 #define CLASS_UNKNOWN200             0x0200
269 #define CLASS_UNKNOWN400             0x0400
270 #define CLASS_UNKNOWN800             0x0800
271
272 static int dissect_aim(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
273 static guint get_aim_pdu_len(tvbuff_t *tvb, int offset);
274 static void dissect_aim_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
275
276 static void dissect_aim_newconn(tvbuff_t *tvb, packet_info *pinfo, int offset, proto_tree *tree);
277 static void dissect_aim_snac(tvbuff_t *tvb, packet_info *pinfo, 
278                              int offset, proto_tree *tree, proto_tree *root_tree);
279 static void dissect_aim_flap_err(tvbuff_t *tvb, packet_info *pinfo, 
280                                  int offset, proto_tree *tree);
281 static void dissect_aim_keep_alive(tvbuff_t *tvb, packet_info *pinfo, 
282                                    int offset, proto_tree *tree);
283 static void dissect_aim_close_conn(tvbuff_t *tvb, packet_info *pinfo, 
284                                    int offset, proto_tree *tree);
285 static void dissect_aim_unknown_channel(tvbuff_t *tvb, packet_info *pinfo, 
286                                         int offset, proto_tree *tree);
287
288 static dissector_table_t subdissector_table;
289
290 /* Initialize the protocol and registered fields */
291 static int proto_aim = -1;
292 static int hf_aim_cmd_start = -1;
293 static int hf_aim_channel = -1;
294 static int hf_aim_seqno = -1;
295 static int hf_aim_data = -1;
296 static int hf_aim_data_len = -1;
297 static int hf_aim_signon_challenge_len = -1;
298 static int hf_aim_signon_challenge = -1;
299 static int hf_aim_fnac_family = -1;
300 static int hf_aim_fnac_subtype = -1;
301 static int hf_aim_fnac_flags = -1;
302 static int hf_aim_fnac_id = -1;
303 static int hf_aim_infotype = -1;
304 static int hf_aim_buddyname_len = -1;
305 static int hf_aim_buddyname = -1;
306 static int hf_aim_userinfo_warninglevel = -1;
307 static int hf_aim_snac_error = -1;
308 static int hf_aim_tlvcount = -1;
309 static int hf_aim_authcookie = -1;
310 static int hf_aim_userclass_unconfirmed = -1;
311 static int hf_aim_userclass_administrator = -1;
312 static int hf_aim_userclass_aol = -1;
313 static int hf_aim_userclass_commercial = -1;
314 static int hf_aim_userclass_free = -1;
315 static int hf_aim_userclass_away = -1;
316 static int hf_aim_userclass_icq = -1;
317 static int hf_aim_userclass_wireless = -1;
318 static int hf_aim_userclass_unknown100 = -1;
319 static int hf_aim_userclass_unknown200 = -1;
320 static int hf_aim_userclass_unknown400 = -1;
321 static int hf_aim_userclass_unknown800 = -1;
322
323 /* Initialize the subtree pointers */
324 static gint ett_aim          = -1;
325 static gint ett_aim_buddyname= -1;
326 static gint ett_aim_fnac     = -1;
327 static gint ett_aim_tlv      = -1;
328 static gint ett_aim_userclass = -1;
329
330 /* desegmentation of AIM over TCP */
331 static gboolean aim_desegment = TRUE;
332
333 /* Code to actually dissect the packets */
334 static int dissect_aim(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
335 {
336 /* check, if this is really an AIM packet, they start with 0x2a */
337 /* XXX - I've seen some stuff starting with 0x5a followed by 0x2a */
338
339   if(tvb_bytes_exist(tvb, 0, 1) && tvb_get_guint8(tvb, 0) != 0x2a) {
340     /* Not an instant messenger packet, just happened to use the same port */
341     /* XXX - if desegmentation disabled, this might be a continuation
342        packet, not a non-AIM packet */
343     return 0;
344   }
345
346   tcp_dissect_pdus(tvb, pinfo, tree, aim_desegment, 6, get_aim_pdu_len,
347         dissect_aim_pdu);
348   return tvb_length(tvb);
349 }
350
351 static guint get_aim_pdu_len(tvbuff_t *tvb, int offset)
352 {
353   guint16 plen;
354
355   /*
356    * Get the length of the AIM packet.
357    */
358   plen = tvb_get_ntohs(tvb, offset + 4);
359
360   /*
361    * That length doesn't include the length of the header itself; add that in.
362    */
363   return plen + 6;
364 }
365
366 static void dissect_aim_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
367 {
368   /* Header fields */
369   unsigned char  hdr_channel;           /* channel ID */
370   unsigned short hdr_sequence_no;       /* Internal frame sequence number, not needed */
371   unsigned short hdr_data_field_length; /* length of data within frame */
372
373   int offset=0;
374
375 /* Set up structures we will need to add the protocol subtree and manage it */
376   proto_item *ti;
377   proto_tree *aim_tree = NULL;
378
379 /* Make entries in Protocol column and Info column on summary display */
380   if (check_col(pinfo->cinfo, COL_PROTOCOL))
381     col_set_str(pinfo->cinfo, COL_PROTOCOL, "AIM");
382
383   if (check_col(pinfo->cinfo, COL_INFO))
384     col_add_str(pinfo->cinfo, COL_INFO, "AOL Instant Messenger");
385
386   /* get relevant header information */
387   offset += 1;          /* XXX - put the identifier into the tree? */   
388   hdr_channel           = tvb_get_guint8(tvb, offset);
389   offset += 1;
390   hdr_sequence_no       = tvb_get_ntohs(tvb, offset);
391   offset += 2;
392   hdr_data_field_length = tvb_get_ntohs(tvb, offset);
393   offset += 2;
394
395 /* In the interest of speed, if "tree" is NULL, don't do any work not
396    necessary to generate protocol tree items. */
397   if (tree) {
398     ti = proto_tree_add_item(tree, proto_aim, tvb, 0, -1, FALSE);
399     aim_tree = proto_item_add_subtree(ti, ett_aim);
400     proto_tree_add_uint(aim_tree, hf_aim_cmd_start, tvb, 0, 1, '*');
401     proto_tree_add_item(aim_tree, hf_aim_channel, tvb, 1, 1, FALSE);
402     proto_tree_add_uint(aim_tree, hf_aim_seqno, tvb, 2, 2, hdr_sequence_no);
403     proto_tree_add_uint(aim_tree, hf_aim_data_len, tvb, 4, 2, hdr_data_field_length);
404
405   }
406
407   switch(hdr_channel)
408   {
409     case CHANNEL_NEW_CONN:
410       dissect_aim_newconn(tvb, pinfo, offset, aim_tree);
411       break;
412     case CHANNEL_SNAC_DATA:
413       dissect_aim_snac(tvb, pinfo, offset, aim_tree, tree);
414       break;
415     case CHANNEL_FLAP_ERR:
416       dissect_aim_flap_err(tvb, pinfo, offset, aim_tree);
417       break;
418     case CHANNEL_CLOSE_CONN:
419       dissect_aim_close_conn(tvb, pinfo, offset, aim_tree);
420       break;
421     case CHANNEL_KEEP_ALIVE:
422      dissect_aim_keep_alive(tvb, pinfo, offset, aim_tree);
423      break;
424     default:
425       dissect_aim_unknown_channel(tvb, pinfo, offset, aim_tree);
426       break;
427   }
428
429 }
430
431 const char *aim_get_subtypename( guint16 famnum, guint16 subtype )
432 {
433         GList *gl = families;
434         while(gl) {
435                 struct aim_family *fam = gl->data;
436                 if(fam->family == famnum) return match_strval(subtype, fam->subtypes);
437                 gl = gl->next;
438         }
439
440         return NULL;
441
442 }
443
444 const char *aim_get_familyname( guint16 famnum ) 
445 {
446         GList *gl = families;
447         while(gl) {
448                 struct aim_family *fam = gl->data;
449                 if(fam->family == famnum) return fam->name;
450                 gl = gl->next;
451         }
452
453         return NULL;
454 }
455
456 int aim_get_buddyname( char *name, tvbuff_t *tvb, int len_offset, int name_offset)
457 {
458   guint8 buddyname_length;
459
460   buddyname_length = tvb_get_guint8(tvb, len_offset);
461
462   if(buddyname_length > MAX_BUDDYNAME_LENGTH ) buddyname_length = MAX_BUDDYNAME_LENGTH;
463   tvb_get_nstringz0(tvb, name_offset, buddyname_length + 1, name);
464
465   return buddyname_length;
466 }
467
468
469 void aim_get_message( guchar *msg, tvbuff_t *tvb, int msg_offset, int msg_length)
470 {
471   int i,j,c;
472   int bracket = FALSE;
473   int max, tagchars = 0;
474   int new_offset = msg_offset;
475   int new_length = msg_length;
476
477
478
479   /* make sure nothing bigger than 1000 bytes is printed */
480   if( msg_length > 999 ) return;
481
482   memset( msg, '\0', 1000);
483   i = 0;
484   c = 0;
485
486   /* loop until HTML tag is reached - quick&dirty way to find start of message
487    * (it is nearly impossible to find the correct start offset for all client versions) */
488   while( (tagchars < 6) && (new_length > 5) )
489   {
490      j = tvb_get_guint8(tvb, new_offset);
491      if( ( (j == '<') && (tagchars == 0) ) ||
492          ( (j == 'h') && (tagchars == 1) ) ||
493          ( (j == 'H') && (tagchars == 1) ) ||
494          ( (j == 't') && (tagchars == 2) ) ||
495          ( (j == 'T') && (tagchars == 2) ) ||
496          ( (j == 'm') && (tagchars == 3) ) ||
497          ( (j == 'M') && (tagchars == 3) ) ||
498          ( (j == 'l') && (tagchars == 4) ) ||
499          ( (j == 'L') && (tagchars == 4) ) ||
500          ( (j == '>') && (tagchars == 5) ) ) tagchars++;
501      new_offset++;
502      new_length--;
503   }
504
505   /* set offset and length of message to after the first HTML tag */
506   msg_offset = new_offset;
507   msg_length = new_length;
508   max = msg_length - 1;
509   tagchars = 0;
510
511   /* find the rest of the message until either a </html> is reached or the end of the frame.
512    * All other HTML tags are stripped to display only the raw message (printable characters) */
513   while( (c < max) && (tagchars < 7) )
514   {
515      j = tvb_get_guint8(tvb, msg_offset+c);
516
517
518      /* make sure this is an HTML tag by checking the order of the chars */
519      if( ( (j == '<') && (tagchars == 0) ) ||
520          ( (j == '/') && (tagchars == 1) ) ||
521          ( (j == 'h') && (tagchars == 2) ) ||
522          ( (j == 'H') && (tagchars == 2) ) ||
523          ( (j == 't') && (tagchars == 3) ) ||
524          ( (j == 'T') && (tagchars == 3) ) ||
525          ( (j == 'm') && (tagchars == 4) ) ||
526          ( (j == 'M') && (tagchars == 4) ) ||
527          ( (j == 'l') && (tagchars == 5) ) ||
528          ( (j == 'L') && (tagchars == 5) ) ||
529          ( (j == '>') && (tagchars == 6) ) ) tagchars++;
530
531 #ifdef STRIP_TAGS
532      if( j == '<' ) bracket = TRUE;
533      if( j == '>' ) bracket = FALSE;
534      if( (isprint(j) ) && (bracket == FALSE) && (j != '>'))
535 #else
536      if( isprint(j) )
537 #endif
538      {
539        msg[i] = j;
540        i++;
541      }
542      c++;
543   }
544 }
545
546 void aim_init_family(guint16 family, const char *name, const value_string *subtypes) 
547 {
548         struct aim_family *fam = g_new(struct aim_family, 1);
549         fam->name = g_strdup(name);
550         fam->family = family;
551         fam->subtypes = subtypes;
552         families = g_list_append(families, fam);
553 }
554
555 static void dissect_aim_newconn(tvbuff_t *tvb, packet_info *pinfo, 
556                                 int offset, proto_tree *tree)
557 {
558   if (check_col(pinfo->cinfo, COL_INFO)) 
559     col_add_fstr(pinfo->cinfo, COL_INFO, "New Connection");
560
561   if (tvb_length_remaining(tvb, offset) > 0) {
562           proto_tree_add_item(tree, hf_aim_authcookie, tvb, offset, 4, FALSE);
563           offset+=4;
564           while(tvb_reported_length_remaining(tvb, offset) > 0) {
565                   offset = dissect_aim_tlv(tvb, pinfo, offset, tree, client_tlvs);
566           }
567   }
568
569   if (tvb_length_remaining(tvb, offset) > 0)
570     proto_tree_add_item(tree, hf_aim_data, tvb, offset, -1, FALSE);
571 }
572
573
574 int dissect_aim_snac_error(tvbuff_t *tvb, packet_info *pinfo, 
575                              int offset, proto_tree *aim_tree)
576 {
577   char *name;
578   if ((name = match_strval(tvb_get_ntohs(tvb, offset), aim_snac_errors)) != NULL) {
579      if (check_col(pinfo->cinfo, COL_INFO))
580                 col_add_fstr(pinfo->cinfo, COL_INFO, name);
581   }
582
583   proto_tree_add_item (aim_tree, hf_aim_snac_error,
584                            tvb, offset, 2, FALSE);
585   return tvb_length_remaining(tvb, 2);
586 }
587
588 int dissect_aim_userinfo(tvbuff_t *tvb, packet_info *pinfo, 
589                                  int offset, proto_tree *tree) 
590 {
591         offset = dissect_aim_buddyname(tvb, pinfo, offset, tree);
592
593     proto_tree_add_item(tree, hf_aim_userinfo_warninglevel, tvb, offset, 2, FALSE);
594     offset += 2;
595
596         return dissect_aim_tlv_list(tvb, pinfo, offset, tree, onlinebuddy_tlvs);
597 }
598
599 static void dissect_aim_snac(tvbuff_t *tvb, packet_info *pinfo, 
600                              int offset, proto_tree *aim_tree, proto_tree *root_tree)
601 {
602   guint16 family;
603   guint16 subtype;
604   guint16 flags;
605   guint32 id;
606   proto_item *ti1;
607   struct aiminfo aiminfo;
608   const char *fam_name, *subtype_name;
609   proto_tree *aim_tree_fnac = NULL;
610   tvbuff_t *subtvb;
611   int orig_offset;
612
613   orig_offset = offset;
614   family = tvb_get_ntohs(tvb, offset);
615   fam_name = aim_get_familyname(family);
616   offset += 2;
617   subtype = tvb_get_ntohs(tvb, offset);
618   subtype_name = aim_get_subtypename(family, subtype);
619   offset += 2;
620   flags = tvb_get_ntohs(tvb, offset);
621   offset += 2;
622   id = tvb_get_ntohl(tvb, offset);
623   offset += 4;
624   
625   if (check_col(pinfo->cinfo, COL_INFO)) {
626     col_add_fstr(pinfo->cinfo, COL_INFO, "SNAC data");
627   }
628   
629   if( aim_tree )
630     {
631       offset = orig_offset;
632       ti1 = proto_tree_add_text(aim_tree, tvb, 6, 10, "FNAC");
633       aim_tree_fnac = proto_item_add_subtree(ti1, ett_aim_fnac);
634
635       proto_tree_add_text (aim_tree_fnac, 
636                            tvb, offset, 2, "Family: %s (0x%04x)", fam_name?fam_name:"Unknown", family);
637       offset += 2;
638
639       proto_tree_add_text (aim_tree_fnac, 
640                            tvb, offset, 2, "Subtype: %s (0x%04x)", subtype_name?subtype_name:"Unknown", subtype);
641       offset += 2;
642
643       proto_tree_add_uint(aim_tree_fnac, hf_aim_fnac_flags, tvb, offset, 
644                           2, flags);
645       offset += 2;
646       proto_tree_add_uint(aim_tree_fnac, hf_aim_fnac_id, tvb, offset,
647                           4, id);
648       offset += 4;
649     }
650
651   subtvb = tvb_new_subset(tvb, offset, -1, -1);
652   aiminfo.tcpinfo = pinfo->private_data;
653   aiminfo.family = family;
654   aiminfo.subtype = subtype;
655   pinfo->private_data = &aiminfo;
656   
657   if (check_col(pinfo->cinfo, COL_INFO)) {
658      if(fam_name) col_append_fstr(pinfo->cinfo, COL_INFO, ", %s", fam_name);
659          else col_append_fstr(pinfo->cinfo, COL_INFO, ", Family: 0x%04x", family);
660          if(subtype_name) col_append_fstr(pinfo->cinfo, COL_INFO, ", %s", subtype_name);
661          else col_append_fstr(pinfo->cinfo, COL_INFO, ", Subtype: 0x%04x", subtype);
662   }
663
664   if(tvb_length_remaining(tvb, offset) == 0 || !dissector_try_port(subdissector_table, family, subtvb, pinfo, root_tree)) {
665     /* Show the undissected payload */
666     if (tvb_length_remaining(tvb, offset) > 0)
667       proto_tree_add_item(aim_tree, hf_aim_data, tvb, offset, -1, FALSE);
668   }
669 }
670
671 static void dissect_aim_flap_err(tvbuff_t *tvb, packet_info *pinfo, 
672                                  int offset, proto_tree *tree)
673 {
674   if (check_col(pinfo->cinfo, COL_INFO)) {
675     col_add_fstr(pinfo->cinfo, COL_INFO, "FLAP error");
676   }
677
678   /* Show the undissected payload */
679   if (tvb_length_remaining(tvb, offset) > 0)
680     proto_tree_add_item(tree, hf_aim_data, tvb, offset, -1, FALSE);
681 }
682
683 static void dissect_aim_keep_alive(tvbuff_t *tvb, packet_info *pinfo, 
684                                    int offset, proto_tree *tree)
685 {
686   if (check_col(pinfo->cinfo, COL_INFO)) {
687     col_add_fstr(pinfo->cinfo, COL_INFO, "Keep Alive");
688   }
689
690   /* Show the undissected payload */
691   if (tvb_length_remaining(tvb, offset) > 0)
692     proto_tree_add_item(tree, hf_aim_data, tvb, offset, -1, FALSE);
693 }
694
695 static void dissect_aim_close_conn(tvbuff_t *tvb, packet_info *pinfo, 
696                                    int offset, proto_tree *tree)
697 {
698   if (check_col(pinfo->cinfo, COL_INFO)) {
699     col_add_fstr(pinfo->cinfo, COL_INFO, "Close Connection");
700   }       
701   
702   while(tvb_reported_length_remaining(tvb, offset) > 0) {
703           offset = dissect_aim_tlv(tvb, pinfo, offset, tree, client_tlvs);
704   }
705 }
706
707 static void dissect_aim_unknown_channel(tvbuff_t *tvb, packet_info *pinfo, 
708                                         int offset, proto_tree *tree)
709 {
710   if (check_col(pinfo->cinfo, COL_INFO)) {
711     col_add_fstr(pinfo->cinfo, COL_INFO, "Unknown Channel");
712   }
713
714   /* Show the undissected payload */
715   if (tvb_length_remaining(tvb, offset) > 0)
716     proto_tree_add_item(tree, hf_aim_data, tvb, offset, -1, FALSE);
717 }
718
719 int dissect_aim_buddyname(tvbuff_t *tvb, packet_info *pinfo _U_, int offset,
720                        proto_tree *tree)
721 {
722   guint8 buddyname_length = 0;
723   char *buddyname;
724   proto_item *ti = NULL;
725   proto_tree *buddy_tree = NULL;
726                                                                                                                               
727   buddyname_length = tvb_get_guint8(tvb, offset);
728   offset++;
729   buddyname = tvb_get_string(tvb, offset, buddyname_length);
730                                                                                                                               
731   if(tree) {
732       ti = proto_tree_add_text(tree, tvb, offset-1, 1+buddyname_length,"Buddy: %s", buddyname);
733       buddy_tree = proto_item_add_subtree(ti, ett_aim_buddyname);
734   }
735                                                                                                                               
736    proto_tree_add_item(buddy_tree, hf_aim_buddyname_len, tvb, offset-1, 1, FALSE);
737    proto_tree_add_item(buddy_tree, hf_aim_buddyname, tvb, offset, buddyname_length, FALSE);
738    return offset+buddyname_length;
739 }
740
741
742 int dissect_aim_tlv_value_client_capabilities(proto_item *ti _U_, guint16 valueid _U_, tvbuff_t *tvb)
743 {
744         /* FIXME */
745         return tvb_length(tvb);
746 }
747
748 int dissect_aim_tlv_value_time(proto_item *ti _U_, guint16 valueid _U_, tvbuff_t *tvb)
749 {
750         /* FIXME */
751         return tvb_length(tvb);
752 }
753
754 int dissect_aim_userclass(tvbuff_t *tvb, int offset, int len, proto_item *ti, guint32 flags)
755 {
756         proto_tree *entry;
757
758         entry = proto_item_add_subtree(ti, ett_aim_userclass);
759         proto_tree_add_boolean(entry, hf_aim_userclass_unconfirmed, tvb, offset, len, flags);
760         proto_tree_add_boolean(entry, hf_aim_userclass_administrator, tvb, offset, len, flags);
761         proto_tree_add_boolean(entry, hf_aim_userclass_aol, tvb, offset, len, flags);
762         proto_tree_add_boolean(entry, hf_aim_userclass_commercial, tvb, offset, len, flags);
763         proto_tree_add_boolean(entry, hf_aim_userclass_free, tvb, offset, len, flags);
764         proto_tree_add_boolean(entry, hf_aim_userclass_away, tvb, offset, len, flags);
765         proto_tree_add_boolean(entry, hf_aim_userclass_icq, tvb, offset, len, flags);
766         proto_tree_add_boolean(entry, hf_aim_userclass_wireless, tvb, offset, len, flags);
767         proto_tree_add_boolean(entry, hf_aim_userclass_unknown100, tvb, offset, len, flags);
768         proto_tree_add_boolean(entry, hf_aim_userclass_unknown200, tvb, offset, len, flags);
769         proto_tree_add_boolean(entry, hf_aim_userclass_unknown400, tvb, offset, len, flags);
770         proto_tree_add_boolean(entry, hf_aim_userclass_unknown800, tvb, offset, len, flags);
771         return offset+len;
772 }
773
774 int dissect_aim_tlv_value_userclass(proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb)
775 {
776         guint16 value16 = tvb_get_ntohs(tvb, 0);
777         proto_item_set_text(ti, "Value: 0x%04x", value16);
778         return dissect_aim_userclass(tvb, 0, 2, ti, value16);
779 }
780
781 static int dissect_aim_tlv_value_userstatus(proto_item *ti _U_, guint16 valueid _U_, tvbuff_t *tvb)
782 {
783         /* FIXME */
784         return tvb_length(tvb);
785 }
786
787 static int dissect_aim_tlv_value_dcinfo(proto_item *ti _U_, guint16 valueid _U_, tvbuff_t *tvb)
788 {
789         /* FIXME */
790         return tvb_length(tvb);
791 }
792
793 int dissect_aim_tlv_value_string (proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb)
794 {
795    guint8 *buf;
796    buf = tvb_get_string(tvb, 0, tvb_length(tvb));
797    proto_item_set_text(ti, "Value: %s", buf);
798    g_free(buf);
799    return tvb_length(tvb);
800 }
801
802 int dissect_aim_tlv_value_bytes (proto_item *ti _U_, guint16 valueid _U_, tvbuff_t *tvb _U_)
803 {
804    return tvb_length(tvb);
805 }
806
807 int dissect_aim_tlv_value_uint8 (proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb){
808   guint8 value8 = tvb_get_guint8(tvb, 0);
809   proto_item_set_text(ti, "Value: %d", value8);
810   return 1;
811 }
812
813 int dissect_aim_tlv_value_uint16 (proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb){
814   guint16 value16 = tvb_get_ntohs(tvb, 0);
815   proto_item_set_text(ti, "Value: %d", value16);
816   return 2;
817 }
818
819 int dissect_aim_tlv_value_ipv4 (proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb){
820   /* FIXME: Somewhat more readable format ? */
821   guint32 value32 = tvb_get_ntoh24(tvb, 0);
822   proto_item_set_text(ti, "Value: %d", value32);
823   return 4;
824 }
825
826 int dissect_aim_tlv_value_uint32 (proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb){
827   guint32 value32 = tvb_get_ntoh24(tvb, 0);
828   proto_item_set_text(ti, "Value: %d", value32);
829   return 4;
830 }
831
832 /* Dissect a TLV value */
833 int dissect_aim_tlv(tvbuff_t *tvb, packet_info *pinfo _U_, 
834                            int offset, proto_tree *tree, const aim_tlv *tlv)
835 {
836   guint16 valueid;
837   guint16 length;
838   int i = 0;
839   const aim_tlv *tmp;
840   proto_item *ti1;
841   proto_tree *tlv_tree;
842   int orig_offset;
843
844   /* Record the starting offset so we can reuse it at the second pass */
845   orig_offset = offset;
846
847   /* Get the value ID */
848   valueid = tvb_get_ntohs(tvb, offset);
849   offset += 2;
850
851   /* Figure out which entry applies from the tlv list */
852   tmp = tlv;
853   while (tmp[i].valueid) {
854     if (tmp[i].valueid == valueid) {
855       /* We found a match */
856       break;
857     }
858     i++;
859   }
860
861   /* At this point, we are either pointing at the correct record, or 
862      we didn't find the record, and are pointing at the last item in the 
863      list */
864
865   length = tvb_get_ntohs(tvb, offset);
866   offset += 2;
867   offset += length;
868
869   if (tree) {
870     offset = orig_offset;
871     
872         ti1 = proto_tree_add_text(tree, tvb, offset, length + 4, "TLV: %s", tmp[i].desc);
873
874     tlv_tree = proto_item_add_subtree(ti1, ett_aim_tlv);
875
876     proto_tree_add_text(tlv_tree, tvb, offset, 2,
877                         "Value ID: %s (0x%04x)", tmp[i].desc, valueid);
878     offset += 2;
879     
880     proto_tree_add_text(tlv_tree, tvb, offset, 2,
881                         "Length: %d", length);
882     offset += 2;
883
884     ti1 = proto_tree_add_text(tlv_tree, tvb, offset, length,
885                               "Value");
886         
887         if (tmp[i].dissector) {
888            tmp[i].dissector(ti1, valueid, tvb_new_subset(tvb, offset, length, length));
889         } 
890
891     offset += length;
892   }
893
894   /* Return the new length */
895   return offset;
896 }
897
898 int dissect_aim_tlv_list(tvbuff_t *tvb, packet_info *pinfo _U_, 
899                            int offset, proto_tree *tree, const aim_tlv *tlv_table)
900 {
901         guint16 i, tlv_count = tvb_get_ntohs(tvb, offset);
902     proto_tree_add_item(tree, hf_aim_tlvcount, tvb, offset, 2, FALSE);
903         offset += 2;
904
905         for(i = 0; i < tlv_count; i++) {
906             offset = dissect_aim_tlv(tvb, pinfo, offset, tree, tlv_table);
907         }
908         return offset;
909 }
910
911 /* Register the protocol with Ethereal */
912 void
913 proto_register_aim(void)
914 {
915
916 /* Setup list of header fields */
917   static hf_register_info hf[] = {
918     { &hf_aim_cmd_start,
919       { "Command Start", "aim.cmd_start", FT_UINT8, BASE_HEX, NULL, 0x0, "", HFILL }
920     },
921     { &hf_aim_channel,
922       { "Channel ID", "aim.channel", FT_UINT8, BASE_HEX, VALS(aim_flap_channels), 0x0, "", HFILL }
923     },
924     { &hf_aim_seqno,
925       { "Sequence Number", "aim.seqno", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }
926     },
927         { &hf_aim_authcookie,
928           { "Authentication Cookie", "aim.authcookie", FT_BYTES, BASE_DEC, NULL, 0x0, "", HFILL },
929         },
930     { &hf_aim_data_len,
931       { "Data Field Length", "aim.datalen", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }
932     },
933     { &hf_aim_data,
934       { "Data", "aim.data", FT_BYTES, BASE_HEX, NULL, 0x0, "", HFILL }
935     },
936     { &hf_aim_signon_challenge_len,
937       { "Signon challenge length", "aim.signon.challengelen", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }
938     },
939     { &hf_aim_signon_challenge,
940       { "Signon challenge", "aim.signon.challenge", FT_STRING, BASE_HEX, NULL, 0x0, "", HFILL }
941     },
942     { &hf_aim_fnac_family,
943       { "FNAC Family ID", "aim.fnac.family", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }
944     },
945     { &hf_aim_fnac_subtype,
946       { "FNAC Subtype ID", "aim.fnac.subtype", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }
947     },
948     { &hf_aim_fnac_flags,
949       { "FNAC Flags", "aim.fnac.flags", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }
950     },
951     { &hf_aim_fnac_id,
952       { "FNAC ID", "aim.fnac.id", FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL }
953     },
954     { &hf_aim_infotype,
955       { "Infotype", "aim.infotype", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }
956     },
957     { &hf_aim_buddyname_len,
958       { "Buddyname len", "aim.buddynamelen", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }
959     },
960     { &hf_aim_buddyname,
961       { "Buddy Name", "aim.buddyname", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }
962     },
963     { &hf_aim_tlvcount,
964       { "TLV Count", "aim.tlvcount", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL },
965     },
966         { &hf_aim_snac_error,
967           { "SNAC Error", "aim.snac.error", FT_UINT16,
968                   BASE_HEX, VALS(aim_snac_errors), 0x0, "", HFILL },
969         },
970         { &hf_aim_userclass_unconfirmed,
971                 { "AOL Unconfirmed user flag", "aim.userclass.unconfirmed", FT_BOOLEAN, 32, TFS(&flags_set_truth), CLASS_UNCONFIRMED, "", HFILL },
972         },
973         { &hf_aim_userclass_administrator,
974                 { "AOL Administrator flag", "aim.userclass.administrator", FT_BOOLEAN, 32, TFS(&flags_set_truth), CLASS_ADMINISTRATOR, "", HFILL },
975         },
976         { &hf_aim_userclass_aol,
977                 { "AOL Staff User Flag", "aim.userclass.staff", FT_BOOLEAN, 32, TFS(&flags_set_truth), CLASS_AOL, "", HFILL },
978         },
979         { &hf_aim_userclass_commercial,
980                 { "AOL commercial account flag", "aim.userclass.commercial", FT_BOOLEAN, 32, TFS(&flags_set_truth), CLASS_COMMERCIAL, "", HFILL },
981         },
982         { &hf_aim_userclass_free,
983                 { "ICQ non-commercial account flag", "aim.userclass.noncommercial", FT_BOOLEAN, 32, TFS(&flags_set_truth), CLASS_FREE, "", HFILL },
984         },
985         { &hf_aim_userclass_away,
986                 { "AOL away status flag", "aim.userclass.away", FT_BOOLEAN, 32, TFS(&flags_set_truth), CLASS_AWAY, "", HFILL },
987         },
988         { &hf_aim_userclass_icq,
989                 { "ICQ user sign", "aim.userclass.icq", FT_BOOLEAN, 32, TFS(&flags_set_truth), CLASS_ICQ, "", HFILL },
990         },
991         { &hf_aim_userclass_wireless,
992                 { "AOL wireless user", "aim.userclass.wireless", FT_BOOLEAN, 32, TFS(&flags_set_truth), CLASS_WIRELESS, "", HFILL },
993         },
994         { &hf_aim_userclass_unknown100,
995                 { "Unknown bit", "aim.userclass.unknown100", FT_BOOLEAN, 32, TFS(&flags_set_truth), CLASS_UNKNOWN100, "", HFILL },
996         },
997         { &hf_aim_userclass_unknown200,
998                 { "Unknown bit", "aim.userclass.unknown200", FT_BOOLEAN, 32, TFS(&flags_set_truth), CLASS_UNKNOWN200, "", HFILL },
999         },
1000         { &hf_aim_userclass_unknown400,
1001                 { "Unknown bit", "aim.userclass.unknown400", FT_BOOLEAN, 32, TFS(&flags_set_truth), CLASS_UNKNOWN400, "", HFILL },
1002         },
1003         { &hf_aim_userclass_unknown800,
1004                 { "Unknown bit", "aim.userclass.unknown800", FT_BOOLEAN, 32, TFS(&flags_set_truth), CLASS_UNKNOWN800, "", HFILL },
1005         },
1006         { &hf_aim_userinfo_warninglevel,
1007                 { "Warning Level", "aim.userinfo.warninglevel", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL },
1008         },
1009   };
1010
1011   /* Setup protocol subtree array */
1012   static gint *ett[] = {
1013           &ett_aim,
1014           &ett_aim_fnac,
1015           &ett_aim_tlv,
1016           &ett_aim_buddyname,
1017           &ett_aim_userclass
1018   };
1019   module_t *aim_module;
1020
1021   /* Register the protocol name and description */
1022   proto_aim = proto_register_protocol("AOL Instant Messenger", "AIM", "aim");
1023
1024 /* Required function calls to register the header fields and subtrees used */
1025   proto_register_field_array(proto_aim, hf, array_length(hf));
1026   proto_register_subtree_array(ett, array_length(ett));
1027
1028   aim_module = prefs_register_protocol(proto_aim, NULL);
1029   prefs_register_bool_preference(aim_module, "desegment",
1030     "Desegment all AIM messages spanning multiple TCP segments",
1031     "Whether the AIM dissector should desegment all messages spanning multiple TCP segments",
1032     &aim_desegment);
1033
1034   subdissector_table = register_dissector_table("aim.family", 
1035                 "Family ID", FT_UINT16, BASE_HEX);
1036 }
1037
1038 void
1039 proto_reg_handoff_aim(void)
1040 {
1041   dissector_handle_t aim_handle;
1042
1043   aim_handle = new_create_dissector_handle(dissect_aim, proto_aim);
1044   dissector_add("tcp.port", TCP_PORT_AIM, aim_handle);
1045 }