HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / dissectors / packet-aim-messaging.c
blob365b64e739eb54531036307c68625b21dbd7e421
1 /* packet-aim-messaging.c
2 * Routines for AIM Instant Messenger (OSCAR) dissection, SNAC Messaging
3 * Copyright 2004, Jelmer Vernooij <jelmer@samba.org>
4 * Copyright 2000, Ralf Hoelzer <ralf@well.com>
5 * Copyright 2004, Devin Heitmueller <dheitmueller@netilla.com>
7 * $Id$
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
11 * Copyright 1998 Gerald Combs
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include "config.h"
31 #include <glib.h>
33 #include <string.h>
35 #include <epan/packet.h>
36 #include <epan/strutil.h>
38 #include "packet-aim.h"
40 void proto_register_aim_messaging(void);
41 void proto_reg_handoff_aim_messaging(void);
44 #define FAMILY_MESSAGING 0x0004
47 #define INCOMING_CH1_MESSAGE_BLOCK 0x0002
48 #define INCOMING_CH1_SERVER_ACK_REQ 0x0003
49 #define INCOMING_CH1_MESSAGE_AUTH_RESP 0x0004
50 #define INCOMING_CH1_MESSAGE_OFFLINE 0x0006
51 #define INCOMING_CH1_ICON_PRESENT 0x0008
52 #define INCOMING_CH1_BUDDY_REQ 0x0009
53 #define INCOMING_CH1_TYPING 0x000b
55 static const aim_tlv aim_messaging_incoming_ch1_tlvs[] = {
56 { INCOMING_CH1_MESSAGE_BLOCK, "Message Block", dissect_aim_tlv_value_messageblock },
57 { INCOMING_CH1_SERVER_ACK_REQ, "Server Ack Requested", dissect_aim_tlv_value_bytes },
58 { INCOMING_CH1_MESSAGE_AUTH_RESP, "Message is Auto Response", dissect_aim_tlv_value_bytes },
59 { INCOMING_CH1_MESSAGE_OFFLINE, "Message was received offline", dissect_aim_tlv_value_bytes },
60 { INCOMING_CH1_ICON_PRESENT, "Icon present", dissect_aim_tlv_value_bytes },
61 { INCOMING_CH1_BUDDY_REQ, "Buddy Req", dissect_aim_tlv_value_bytes },
62 { INCOMING_CH1_TYPING, "Non-direct connect typing notification", dissect_aim_tlv_value_bytes },
63 { 0, NULL, NULL },
66 static int dissect_aim_tlv_value_rendezvous(proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo);
67 static int dissect_aim_tlv_value_extended_data(proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_);
69 #define ICBM_CHANNEL_IM 0x0001
70 #define ICBM_CHANNEL_RENDEZVOUS 0x0002
72 static const value_string icbm_channel_types[] = {
73 { ICBM_CHANNEL_IM, "IM" },
74 { ICBM_CHANNEL_RENDEZVOUS, "Rendezvous" },
75 { 0, NULL },
78 #define INCOMING_CH2_SERVER_ACK_REQ 0x0003
79 #define INCOMING_CH2_RENDEZVOUS_DATA 0x0005
81 static const aim_tlv aim_messaging_incoming_ch2_tlvs[] = {
82 { INCOMING_CH2_SERVER_ACK_REQ, "Server Ack Requested", dissect_aim_tlv_value_bytes },
83 { INCOMING_CH2_RENDEZVOUS_DATA, "Rendez Vous Data", dissect_aim_tlv_value_rendezvous },
84 { 0, NULL, NULL },
87 #define RENDEZVOUS_TLV_CHANNEL 0x0001
88 #define RENDEZVOUS_TLV_IP_ADDR 0x0002
89 #define RENDEZVOUS_TLV_INT_IP 0x0003
90 #define RENDEZVOUS_TLV_EXT_IP 0x0004
91 #define RENDEZVOUS_TLV_EXT_PORT 0x0005
92 #define RENDEZVOUS_TLV_DOWNLOAD_URL 0x0006
93 #define RENDEZVOUS_TLV_VERIFIED_DOWNLOAD_URL 0x0008
94 #define RENDEZVOUS_TLV_SEQ_NUM 0x000A
95 #define RENDEZVOUS_TLV_CANCEL_REASON 0x000B
96 #define RENDEZVOUS_TLV_INVITATION 0x000C
97 #define RENDEZVOUS_TLV_INVITE_MIME_CHARSET 0x000D
98 #define RENDEZVOUS_TLV_INVITE_MIME_LANG 0x000E
99 #define RENDEZVOUS_TLV_REQ_HOST_CHECK 0x000F
100 #define RENDEZVOUS_TLV_REQ_USE_ARS 0x0010
101 #define RENDEZVOUS_TLV_REQ_SECURE 0x0011
102 #define RENDEZVOUS_TLV_MAX_PROTOCOL_VER 0x0012
103 #define RENDEZVOUS_TLV_MIN_PROTOCOL_VER 0x0013
104 #define RENDEZVOUS_TLV_COUNTER_REASON 0x0014
105 #define RENDEZVOUS_TLV_INVITE_MIME_TYPE 0x0015
106 #define RENDEZVOUS_TLV_IP_ADDR_XOR 0x0016
107 #define RENDEZVOUS_TLV_PORT_XOR 0x0017
108 #define RENDEZVOUS_TLV_ADDR_LIST 0x0018
109 #define RENDEZVOUS_TLV_SESSION_ID 0x0019
110 #define RENDEZVOUS_TLV_ROLLOVER_ID 0x001A
111 #define RENDEZVOUS_TLV_EXTENDED_DATA 0x2711
112 #define RENDEZVOUS_TLV_ICHAT_INVITEES_DATA 0x277E
114 static const aim_tlv aim_rendezvous_tlvs[] = {
115 { RENDEZVOUS_TLV_CHANNEL, "Rendezvous ICBM Channel", dissect_aim_tlv_value_uint16 },
116 { RENDEZVOUS_TLV_IP_ADDR, "Rendezvous IP", dissect_aim_tlv_value_ipv4 },
117 { RENDEZVOUS_TLV_INT_IP, "Internal IP", dissect_aim_tlv_value_ipv4 },
118 { RENDEZVOUS_TLV_EXT_IP, "External IP", dissect_aim_tlv_value_ipv4 },
119 { RENDEZVOUS_TLV_EXT_PORT, "External Port", dissect_aim_tlv_value_uint16 },
120 { RENDEZVOUS_TLV_DOWNLOAD_URL, "Service Support Download URL", dissect_aim_tlv_value_string },
121 { RENDEZVOUS_TLV_VERIFIED_DOWNLOAD_URL, "Verified Service Support Download URL", dissect_aim_tlv_value_string },
122 { RENDEZVOUS_TLV_SEQ_NUM, "Sequence Number", dissect_aim_tlv_value_uint16 },
123 { RENDEZVOUS_TLV_CANCEL_REASON, "Cancel Reason", dissect_aim_tlv_value_uint16 },
124 { RENDEZVOUS_TLV_INVITATION, "Invitation Text", dissect_aim_tlv_value_string },
125 { RENDEZVOUS_TLV_INVITE_MIME_CHARSET, "Data MIME Type", dissect_aim_tlv_value_string },
126 { RENDEZVOUS_TLV_INVITE_MIME_LANG, "Data Language", dissect_aim_tlv_value_string },
127 { RENDEZVOUS_TLV_REQ_HOST_CHECK, "Request Host Check", NULL },
128 { RENDEZVOUS_TLV_REQ_USE_ARS, "Request Data via Rendezvous Server", NULL },
129 { RENDEZVOUS_TLV_REQ_SECURE, "Request SSL Connection", NULL },
130 { RENDEZVOUS_TLV_MAX_PROTOCOL_VER, "Maximum Protocol Version", dissect_aim_tlv_value_uint16 },
131 { RENDEZVOUS_TLV_MIN_PROTOCOL_VER, "Minimum Protocol Version", dissect_aim_tlv_value_uint16 },
132 { RENDEZVOUS_TLV_COUNTER_REASON, "Counter Proposal Reason", dissect_aim_tlv_value_uint16 },
133 { RENDEZVOUS_TLV_INVITE_MIME_TYPE, "Data MIME Type", dissect_aim_tlv_value_string },
134 { RENDEZVOUS_TLV_IP_ADDR_XOR, "XORed Rendezvous IP", dissect_aim_tlv_value_ipv4 },
135 { RENDEZVOUS_TLV_PORT_XOR, "XORed Port", dissect_aim_tlv_value_uint16 },
136 { RENDEZVOUS_TLV_ADDR_LIST, "Address/Port List", dissect_aim_tlv_value_string08_array },
137 { RENDEZVOUS_TLV_SESSION_ID, "Session ID", dissect_aim_tlv_value_string },
138 { RENDEZVOUS_TLV_ROLLOVER_ID, "Rollover ID", dissect_aim_tlv_value_string },
140 The dissect_aim_tlv_value_extended_data function does not work for iChat generated rendezvous data
141 { RENDEZVOUS_TLV_EXTENDED_DATA, "Extended Data", dissect_aim_tlv_value_extended_data },
143 { RENDEZVOUS_TLV_EXTENDED_DATA, "Extended Data", NULL },
144 { RENDEZVOUS_TLV_ICHAT_INVITEES_DATA, "iChat Invitees Data", NULL },
145 { 0, NULL, NULL },
148 #define MINITYPING_FINISHED_SIGN 0x0000
149 #define MINITYPING_TEXT_TYPED_SIGN 0x0001
150 #define MINITYPING_BEGUN_SIGN 0x0002
152 static const value_string minityping_type[] _U_ = {
153 {MINITYPING_FINISHED_SIGN, "Typing finished sign" },
154 {MINITYPING_TEXT_TYPED_SIGN, "Text typed sign" },
155 {MINITYPING_BEGUN_SIGN, "Typing begun sign" },
156 {0, NULL }
159 #define RENDEZVOUS_MSG_REQUEST 0
160 #define RENDEZVOUS_MSG_CANCEL 1
161 #define RENDEZVOUS_MSG_ACCEPT 2
163 static const value_string rendezvous_msg_types[] = {
164 { RENDEZVOUS_MSG_REQUEST, "Request" },
165 { RENDEZVOUS_MSG_CANCEL, "Cancel" },
166 { RENDEZVOUS_MSG_ACCEPT, "Accept" },
167 { 0, NULL },
170 #define CLIENT_ERR__REASON_UNSUPPORTED_CHANNEL 1
171 #define CLIENT_ERR__REASON_BUSTED_PAYLOAD 2
172 #define CLIENT_ERR__REASON_CHANNEL_SPECIFIC 3
174 static const value_string client_err_reason_types[] = {
175 { CLIENT_ERR__REASON_UNSUPPORTED_CHANNEL, "Unsupported Channel" },
176 { CLIENT_ERR__REASON_BUSTED_PAYLOAD, "Busted Payload" },
177 { CLIENT_ERR__REASON_CHANNEL_SPECIFIC, "Channel Specific Error" },
178 { 0, NULL },
181 #define RENDEZVOUS_NAK_PROPOSAL_UNSUPPORTED 0
182 #define RENDEZVOUS_NAK_PROPOSAL_DENIED 1
183 #define RENDEZVOUS_NAK_PROPOSAL_IGNORED 2
184 #define RENDEZVOUS_NAK_BUSTED_PARAMETERS 3
185 #define RENDEZVOUS_NAK_PROPOSAL_TIMED_OUT 4
186 #define RENDEZVOUS_NAK_ONLINE_BUT_NOT_AVAILABLE 5
187 #define RENDEZVOUS_NAK_INSUFFICIENT_RESOURCES 6
188 #define RENDEZVOUS_NAK_RATE_LIMITED 7
189 #define RENDEZVOUS_NAK_NO_DATA 8
190 #define RENDEZVOUS_NAK_VERSION_MISMATCH 9
191 #define RENDEZVOUS_NAK_SECURITY_MISMATCH 10
192 #define RENDEZVOUS_NAK_SERVICE_SPECIFIC_REASON 15
194 static const value_string rendezvous_nak_reason_types[] = {
195 { RENDEZVOUS_NAK_PROPOSAL_UNSUPPORTED, "Proposal UUID not supported" },
196 { RENDEZVOUS_NAK_PROPOSAL_DENIED, "Not authorized, or user declined" },
197 { RENDEZVOUS_NAK_PROPOSAL_IGNORED, "Proposal ignored" },
198 { RENDEZVOUS_NAK_BUSTED_PARAMETERS, "Proposal malformed" },
199 { RENDEZVOUS_NAK_PROPOSAL_TIMED_OUT, "Attempt to act on proposal (e.g. connect) timed out" },
200 { RENDEZVOUS_NAK_ONLINE_BUT_NOT_AVAILABLE, "Recipient away or busy" },
201 { RENDEZVOUS_NAK_INSUFFICIENT_RESOURCES, "Recipient had internal error" },
202 { RENDEZVOUS_NAK_RATE_LIMITED, "Recipient was ratelimited" },
203 { RENDEZVOUS_NAK_NO_DATA, "Recipient had nothing to send" },
204 { RENDEZVOUS_NAK_VERSION_MISMATCH, "Incompatible versions" },
205 { RENDEZVOUS_NAK_SECURITY_MISMATCH, "Incompatible security settings" },
206 { RENDEZVOUS_NAK_SERVICE_SPECIFIC_REASON, "Service-specific reject defined by client" },
207 { 0, NULL },
210 #define EXTENDED_DATA_MTYPE_PLAIN 0x01
211 #define EXTENDED_DATA_MTYPE_CHAT 0x02
212 #define EXTENDED_DATA_MTYPE_FILEREQ 0x03
213 #define EXTENDED_DATA_MTYPE_URL 0x04
214 #define EXTENDED_DATA_MTYPE_AUTHREQ 0x06
215 #define EXTENDED_DATA_MTYPE_AUTHDENY 0x07
216 #define EXTENDED_DATA_MTYPE_AUTHOK 0x08
217 #define EXTENDED_DATA_MTYPE_SERVER 0x09
218 #define EXTENDED_DATA_MTYPE_ADDED 0x0C
219 #define EXTENDED_DATA_MTYPE_WWP 0x0D
220 #define EXTENDED_DATA_MTYPE_EEXPRESS 0x0E
221 #define EXTENDED_DATA_MTYPE_CONTACTS 0x13
222 #define EXTENDED_DATA_MTYPE_PLUGIN 0x1A
223 #define EXTENDED_DATA_MTYPE_AUTOAWAY 0xE8
224 #define EXTENDED_DATA_MTYPE_AUTOBUSY 0xE9
225 #define EXTENDED_DATA_MTYPE_AUTONA 0xEA
226 #define EXTENDED_DATA_MTYPE_AUTODND 0xEB
227 #define EXTENDED_DATA_MTYPE_AUTOFFC 0xEC
229 static const value_string extended_data_message_types[] = {
230 {EXTENDED_DATA_MTYPE_PLAIN, "Plain text (simple) message"},
231 {EXTENDED_DATA_MTYPE_CHAT, "Chat request message"},
232 {EXTENDED_DATA_MTYPE_FILEREQ, "File request / file ok message"},
233 {EXTENDED_DATA_MTYPE_URL, "URL message (0xFE formatted)"},
234 {EXTENDED_DATA_MTYPE_AUTHREQ, "Authorization request message (0xFE formatted)"},
235 {EXTENDED_DATA_MTYPE_AUTHDENY, "Authorization denied message (0xFE formatted)"},
236 {EXTENDED_DATA_MTYPE_AUTHOK, "Authorization given message (empty)"},
237 {EXTENDED_DATA_MTYPE_SERVER, "Message from OSCAR server (0xFE formatted)"},
238 {EXTENDED_DATA_MTYPE_ADDED, "\"You-were-added\" message (0xFE formatted)"},
239 {EXTENDED_DATA_MTYPE_WWP, "Web pager message (0xFE formatted)"},
240 {EXTENDED_DATA_MTYPE_EEXPRESS, "Email express message (0xFE formatted)"},
241 {EXTENDED_DATA_MTYPE_CONTACTS, "Contact list message"},
242 {EXTENDED_DATA_MTYPE_PLUGIN, "Plugin message described by text string"},
243 {EXTENDED_DATA_MTYPE_AUTOAWAY, "Auto away message"},
244 {EXTENDED_DATA_MTYPE_AUTOBUSY, "Auto occupied message"},
245 {EXTENDED_DATA_MTYPE_AUTONA, "Auto not available message"},
246 {EXTENDED_DATA_MTYPE_AUTODND, "Auto do not disturb message"},
247 {EXTENDED_DATA_MTYPE_AUTOFFC, "Auto free for chat message"},
248 { 0, NULL },
251 #define EXTENDED_DATA_MFLAG_NORMAL 0x01
252 #define EXTENDED_DATA_MFLAG_AUTO 0x03
253 #define EXTENDED_DATA_MFLAG_MULTI 0x80
255 #define EVIL_ORIGIN_ANONYMOUS 1
256 #define EVIL_ORIGIN_NONANONYMOUS 2
258 static const value_string evil_origins[] = {
259 {EVIL_ORIGIN_ANONYMOUS, "Anonymous"},
260 {EVIL_ORIGIN_NONANONYMOUS, "Non-Anonymous"},
261 {0, NULL },
264 /* Initialize the protocol and registered fields */
265 static int proto_aim_messaging = -1;
266 static int hf_aim_icbm_channel = -1;
267 static int hf_aim_icbm_cookie = -1;
268 static int hf_aim_icbm_msg_flags = -1;
269 static int hf_aim_icbm_max_sender_warnlevel = -1;
270 static int hf_aim_icbm_max_receiver_warnlevel = -1;
271 static int hf_aim_icbm_max_snac_size = -1;
272 static int hf_aim_icbm_min_msg_interval = -1;
273 static int hf_aim_icbm_notification_cookie = -1;
274 static int hf_aim_icbm_notification_channel = -1;
275 static int hf_aim_icbm_notification_type = -1;
276 static int hf_aim_icbm_rendezvous_nak = -1;
277 static int hf_aim_icbm_rendezvous_nak_length = -1;
278 static int hf_aim_message_channel_id = -1;
279 static int hf_aim_icbm_evil = -1;
280 static int hf_aim_evil_warn_level = -1;
281 static int hf_aim_evil_new_warn_level = -1;
282 static int hf_aim_rendezvous_msg_type = -1;
283 static int hf_aim_icbm_client_err_reason = -1;
284 static int hf_aim_icbm_client_err_protocol_version = -1;
285 static int hf_aim_icbm_client_err_client_caps_flags = -1;
286 static int hf_aim_rendezvous_extended_data_message_type = -1;
287 static int hf_aim_rendezvous_extended_data_message_flags = -1;
288 static int hf_aim_rendezvous_extended_data_message_flags_normal = -1;
289 static int hf_aim_rendezvous_extended_data_message_flags_auto = -1;
290 static int hf_aim_rendezvous_extended_data_message_flags_multi = -1;
291 static int hf_aim_rendezvous_extended_data_message_status_code = -1;
292 static int hf_aim_rendezvous_extended_data_message_priority_code = -1;
293 static int hf_aim_rendezvous_extended_data_message_text_length = -1;
294 /* static int hf_aim_rendezvous_extended_data_message_text = -1; */
296 /* Initialize the subtree pointers */
297 static gint ett_aim_messaging = -1;
298 static gint ett_aim_rendezvous_data = -1;
299 static gint ett_aim_extended_data = -1;
300 static gint ett_aim_extended_data_message_flags = -1;
302 static int
303 dissect_aim_tlv_value_rendezvous(proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo)
305 int offset = 0;
306 proto_tree *entry = proto_item_add_subtree(ti, ett_aim_rendezvous_data);
307 proto_tree_add_item(entry, hf_aim_rendezvous_msg_type, tvb, offset, 2, ENC_BIG_ENDIAN);
308 offset += 2;
310 proto_tree_add_item(entry, hf_aim_icbm_cookie, tvb, offset, 8, ENC_NA);
311 offset += 8;
313 offset = dissect_aim_capability(entry, tvb, offset);
315 return dissect_aim_tlv_sequence(tvb, pinfo, offset, entry,
316 aim_rendezvous_tlvs);
319 static int
320 dissect_aim_msg_outgoing(tvbuff_t *tvb, packet_info *pinfo, proto_tree *msg_tree)
322 int offset = 0;
323 const aim_tlv *aim_ch_tlvs = NULL;
324 guint16 channel_id;
325 guchar buddyname[MAX_BUDDYNAME_LENGTH+1];
326 int buddyname_length;
328 /* ICBM Cookie */
329 proto_tree_add_item(msg_tree, hf_aim_icbm_cookie, tvb, offset, 8, ENC_NA);
330 offset += 8;
332 /* Message Channel ID */
333 channel_id = tvb_get_ntohs(tvb, offset);
334 proto_tree_add_item(msg_tree, hf_aim_message_channel_id, tvb, offset, 2,
335 ENC_BIG_ENDIAN);
336 offset += 2;
338 /* Add the outgoing username to the info column */
339 buddyname_length = aim_get_buddyname(buddyname, tvb, offset,
340 offset + 1);
341 col_append_fstr(pinfo->cinfo, COL_INFO, " to: %s",
342 format_text(buddyname, buddyname_length));
344 offset = dissect_aim_buddyname(tvb, pinfo, offset, msg_tree);
346 switch(channel_id) {
347 case ICBM_CHANNEL_IM: aim_ch_tlvs = aim_messaging_incoming_ch1_tlvs; break;
348 case ICBM_CHANNEL_RENDEZVOUS: aim_ch_tlvs = aim_messaging_incoming_ch2_tlvs; break;
349 default: return offset;
352 return dissect_aim_tlv_sequence(tvb, pinfo, offset, msg_tree, aim_ch_tlvs);
356 static int
357 dissect_aim_msg_incoming(tvbuff_t *tvb, packet_info *pinfo, proto_tree *msg_tree)
359 int offset = 0;
360 const aim_tlv *aim_ch_tlvs;
361 guint16 channel_id;
363 /* ICBM Cookie */
364 proto_tree_add_item(msg_tree, hf_aim_icbm_cookie, tvb, offset, 8, ENC_NA);
365 offset += 8;
367 /* Message Channel ID */
368 proto_tree_add_item(msg_tree, hf_aim_message_channel_id, tvb, offset, 2,
369 ENC_BIG_ENDIAN);
370 channel_id = tvb_get_ntohs(tvb, offset);
371 offset += 2;
373 offset = dissect_aim_userinfo(tvb, pinfo, offset, msg_tree);
375 switch(channel_id) {
376 case ICBM_CHANNEL_IM: aim_ch_tlvs = aim_messaging_incoming_ch1_tlvs; break;
377 case ICBM_CHANNEL_RENDEZVOUS: aim_ch_tlvs = aim_messaging_incoming_ch2_tlvs; break;
378 default: return offset;
381 return dissect_aim_tlv_sequence(tvb, pinfo, offset, msg_tree, aim_ch_tlvs);
384 static int
385 dissect_aim_msg_params(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *msg_tree)
387 int offset = 0;
388 proto_tree_add_item(msg_tree, hf_aim_icbm_channel, tvb, offset, 2, ENC_BIG_ENDIAN); offset+=2;
389 proto_tree_add_item(msg_tree, hf_aim_icbm_msg_flags, tvb, offset, 4, ENC_BIG_ENDIAN); offset+=4;
390 proto_tree_add_item(msg_tree, hf_aim_icbm_max_snac_size, tvb, offset, 2, ENC_BIG_ENDIAN); offset+=2;
391 proto_tree_add_item(msg_tree, hf_aim_icbm_max_sender_warnlevel, tvb, offset, 2, ENC_BIG_ENDIAN); offset+=2;
392 proto_tree_add_item(msg_tree, hf_aim_icbm_max_receiver_warnlevel, tvb, offset, 2, ENC_BIG_ENDIAN); offset+=2;
393 proto_tree_add_item(msg_tree, hf_aim_icbm_min_msg_interval, tvb, offset, 4, ENC_BIG_ENDIAN); offset+=4;
394 return offset;
397 static int
398 dissect_aim_msg_evil_req(tvbuff_t *tvb, packet_info *pinfo, proto_tree *msg_tree)
400 int offset = 0;
401 proto_tree_add_item(msg_tree, hf_aim_icbm_evil, tvb, offset, 2, ENC_BIG_ENDIAN); offset+=2;
402 return dissect_aim_buddyname(tvb, pinfo, offset, msg_tree);
406 static int
407 dissect_aim_msg_evil_repl(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *msg_tree)
409 int offset = 0;
410 proto_tree_add_item(msg_tree, hf_aim_evil_warn_level, tvb, offset, 2, ENC_BIG_ENDIAN); offset+=2;
411 proto_tree_add_item(msg_tree, hf_aim_evil_new_warn_level, tvb, offset, 2, ENC_BIG_ENDIAN); offset+=2;
412 return offset;
415 static int
416 dissect_aim_msg_minityping(tvbuff_t *tvb, packet_info *pinfo, proto_tree *msg_tree)
418 int offset = 0;
419 proto_tree_add_item(msg_tree,hf_aim_icbm_notification_cookie, tvb, offset, 8, ENC_NA); offset+=8;
420 proto_tree_add_item(msg_tree,hf_aim_icbm_notification_channel, tvb, offset, 2, ENC_BIG_ENDIAN); offset+=2;
421 offset = dissect_aim_buddyname(tvb, pinfo, offset, msg_tree);
422 proto_tree_add_item(msg_tree,hf_aim_icbm_notification_type, tvb, offset, 2, ENC_BIG_ENDIAN); offset+=2;
423 return offset;
426 typedef struct _aim_client_plugin
428 const char *name;
429 e_uuid_t uuid;
430 } aim_client_plugin;
432 static const aim_client_plugin known_client_plugins[] = {
433 { "None",
434 {0x0, 0x0, 0x0,
435 {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}},
437 { "Status Manager",
438 {0xD140CF10, 0xE94F, 0x11D3,
439 {0xBC, 0xD2, 0x00, 0x04, 0xAC, 0x96, 0xDD, 0x96}}},
441 { NULL, {0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } } }
444 static const
445 aim_client_plugin *aim_find_plugin ( e_uuid_t uuid)
447 int i;
449 for(i = 0; known_client_plugins[i].name; i++)
451 const aim_client_plugin *plugin = &(known_client_plugins[i]);
453 if(memcmp(&(plugin->uuid), &uuid, sizeof(e_uuid_t)) == 0)
454 return plugin;
457 return NULL;
460 static int
461 dissect_aim_plugin(proto_tree *entry, tvbuff_t *tvb, int offset, e_uuid_t* out_plugin_uuid)
463 const aim_client_plugin *plugin = NULL;
464 e_uuid_t uuid;
466 uuid.Data1 = tvb_get_ntohl(tvb, offset);
467 uuid.Data2 = tvb_get_ntohs(tvb, offset+4);
468 uuid.Data3 = tvb_get_ntohs(tvb, offset+6);
469 tvb_memcpy(tvb, uuid.Data4, offset+8, 8);
470 if (out_plugin_uuid)
471 *out_plugin_uuid = uuid;
473 plugin = aim_find_plugin(uuid);
475 proto_tree_add_text(entry, tvb, offset, 16,
476 "Plugin: %s {%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
477 plugin ? plugin->name:"Unknown", uuid.Data1, uuid.Data2,
478 uuid.Data3, uuid.Data4[0], uuid.Data4[1], uuid.Data4[2],
479 uuid.Data4[3], uuid.Data4[4], uuid.Data4[5], uuid.Data4[6],
480 uuid.Data4[7]
483 return offset+16;
486 static int
487 dissect_aim_rendezvous_extended_message(tvbuff_t *tvb, proto_tree *msg_tree)
489 guint8 /*message_type,*/message_flags;
490 int offset = 0;
491 proto_item *ti_flags;
492 proto_tree *flags_entry;
493 guint16 text_length;
494 guint8* text;
496 /* TODO: parse and present message_type */
497 /* message_type = tvb_get_guint8(tvb, offset); */
498 proto_tree_add_item(msg_tree, hf_aim_rendezvous_extended_data_message_type, tvb, offset, 1, ENC_BIG_ENDIAN); offset+=1;
499 message_flags = tvb_get_guint8(tvb, offset);
500 ti_flags = proto_tree_add_uint(msg_tree, hf_aim_rendezvous_extended_data_message_flags, tvb, offset, 1, message_flags);
501 flags_entry = proto_item_add_subtree(ti_flags, ett_aim_extended_data_message_flags);
502 proto_tree_add_boolean(flags_entry, hf_aim_rendezvous_extended_data_message_flags_normal, tvb, offset, 1, message_flags);
503 proto_tree_add_boolean(flags_entry, hf_aim_rendezvous_extended_data_message_flags_auto, tvb, offset, 1, message_flags);
504 proto_tree_add_boolean(flags_entry, hf_aim_rendezvous_extended_data_message_flags_multi, tvb, offset, 1, message_flags);
505 offset+=1;
506 proto_tree_add_item(msg_tree, hf_aim_rendezvous_extended_data_message_status_code, tvb, offset, 2, ENC_BIG_ENDIAN); offset+=2;
507 proto_tree_add_item(msg_tree, hf_aim_rendezvous_extended_data_message_priority_code, tvb, offset, 2, ENC_BIG_ENDIAN); offset+=2;
508 text_length = tvb_get_letohs(tvb, offset);
509 proto_tree_add_item(msg_tree, hf_aim_rendezvous_extended_data_message_text_length, tvb, offset, 2, ENC_BIG_ENDIAN); offset+=2;
510 text = tvb_get_string(wmem_packet_scope(), tvb, offset, text_length);
511 proto_tree_add_text(msg_tree, tvb, offset, text_length, "Text: %s", text); /* offset+=text_length; */
513 offset = tvb_length(tvb);
515 return offset;
518 static int
519 is_uuid_null(e_uuid_t uuid)
521 return (uuid.Data1 == 0) &&
522 (uuid.Data2 == 0) &&
523 (uuid.Data3 == 0) &&
524 (uuid.Data4[0] == 0) &&
525 (uuid.Data4[1] == 0) &&
526 (uuid.Data4[2] == 0) &&
527 (uuid.Data4[3] == 0) &&
528 (uuid.Data4[4] == 0) &&
529 (uuid.Data4[5] == 0) &&
530 (uuid.Data4[6] == 0) &&
531 (uuid.Data4[7] == 0);
534 static int
535 dissect_aim_tlv_value_extended_data(proto_item *ti, guint16 valueid _U_, tvbuff_t *tvb, packet_info *pinfo _U_)
537 int offset = 0;
538 guint16 length/*, protocol_version*/;
539 int start_offset;
540 proto_tree *entry;
541 e_uuid_t plugin_uuid;
543 entry = proto_item_add_subtree(ti, ett_aim_extended_data);
544 length = tvb_get_letohs(tvb, offset);
545 proto_tree_add_text(entry, tvb, offset, 2, "Length: %d", length); offset+=2;
546 start_offset = offset;
547 /* TODO: parse and present protocol version */
548 /* protocol_version = tvb_get_ntohs(tvb, offset); */
549 proto_tree_add_item(entry, hf_aim_icbm_client_err_protocol_version, tvb, offset, 2, ENC_BIG_ENDIAN); offset+=2;
551 offset = dissect_aim_plugin(entry, tvb, offset, &plugin_uuid);
552 proto_tree_add_text(entry, tvb, offset, 2, "Unknown"); offset += 2;
553 proto_tree_add_item(entry, hf_aim_icbm_client_err_client_caps_flags, tvb, offset, 4, ENC_BIG_ENDIAN); offset+=4;
554 proto_tree_add_text(entry, tvb, offset, 1, "Unknown"); offset += 1;
555 proto_tree_add_text(entry, tvb, offset, 2, "Downcounter?"); /* offset += 2;*/
557 offset = start_offset + length;
559 length = tvb_get_letohs(tvb, offset);
560 proto_tree_add_text(entry, tvb, offset, 2, "Length: %d", length); offset+=2;
561 start_offset = offset;
562 proto_tree_add_text(entry, tvb, offset, 2, "Downcounter?"); offset += 2;
563 proto_tree_add_text(entry, tvb, offset, length-2, "Unknown");
564 offset = start_offset + length;
566 if (is_uuid_null(plugin_uuid))
568 /* a message follows */
569 tvbuff_t *subtvb = tvb_new_subset_remaining(tvb, offset);
570 /* offset += */ dissect_aim_rendezvous_extended_message(subtvb, entry);
572 else
574 /* plugin-specific data follows */
575 proto_tree_add_text(entry, tvb, offset, -1, "Plugin-specific data");
577 offset = tvb_length(tvb);
579 return offset;
582 static int
583 dissect_aim_msg_ack(tvbuff_t *tvb, packet_info *pinfo, proto_tree *msg_tree)
585 int offset = 0;
587 proto_tree_add_item(msg_tree,hf_aim_icbm_cookie, tvb, offset, 8, ENC_NA); offset+=8;
589 proto_tree_add_item(msg_tree, hf_aim_message_channel_id, tvb, offset, 2,
590 ENC_BIG_ENDIAN); offset += 2;
592 offset = dissect_aim_buddyname(tvb, pinfo, offset, msg_tree);
594 return offset;
597 static int
598 dissect_aim_msg_client_err(tvbuff_t *tvb, packet_info *pinfo, proto_tree *msg_tree)
600 int offset = 0;
601 guint16 channel, reason;
603 proto_tree_add_item(msg_tree,hf_aim_icbm_cookie, tvb, offset, 8, ENC_NA); offset+=8;
604 channel = tvb_get_ntohs(tvb, offset);
605 proto_tree_add_item(msg_tree,hf_aim_icbm_channel, tvb, offset, 2, ENC_BIG_ENDIAN); offset+=2;
606 offset = dissect_aim_buddyname(tvb, pinfo, offset, msg_tree);
607 reason = tvb_get_ntohs(tvb, offset);
608 proto_tree_add_item(msg_tree, hf_aim_icbm_client_err_reason, tvb, offset, 2, ENC_BIG_ENDIAN); offset+=2;
610 if (reason == CLIENT_ERR__REASON_CHANNEL_SPECIFIC && tvb_length_remaining(tvb, offset) > 0)
612 switch (channel)
614 case ICBM_CHANNEL_RENDEZVOUS:
615 proto_tree_add_item(msg_tree, hf_aim_icbm_rendezvous_nak_length, tvb, offset, 2, ENC_BIG_ENDIAN); offset+=2;
616 proto_tree_add_item(msg_tree, hf_aim_icbm_rendezvous_nak, tvb, offset, 2, ENC_BIG_ENDIAN); offset+=2;
617 break;
619 default:
621 tvbuff_t *subtvb = tvb_new_subset_remaining(tvb, offset);
622 proto_item *ti_extended_data = proto_tree_add_text(msg_tree, tvb, offset, -1, "Extended Data");
623 dissect_aim_tlv_value_extended_data(ti_extended_data, 0, subtvb, pinfo);
624 break;
629 return offset;
632 static const aim_subtype aim_fnac_family_messaging[] = {
633 { 0x0001, "Error", dissect_aim_snac_error },
634 { 0x0002, "Set ICBM Parameter", dissect_aim_msg_params },
635 { 0x0003, "Reset ICBM Parameter", NULL },
636 { 0x0004, "Request Parameter Info", NULL},
637 { 0x0005, "Parameter Info", dissect_aim_msg_params },
638 { 0x0006, "Outgoing", dissect_aim_msg_outgoing },
639 { 0x0007, "Incoming", dissect_aim_msg_incoming },
640 { 0x0008, "Evil Request", dissect_aim_msg_evil_req },
641 { 0x0009, "Evil Response", dissect_aim_msg_evil_repl },
642 { 0x000a, "Missed Call", NULL },
643 { 0x000b, "Client Error", dissect_aim_msg_client_err },
644 { 0x000c, "Acknowledge", dissect_aim_msg_ack },
645 { 0x0014, "Mini Typing Notifications (MTN)", dissect_aim_msg_minityping },
646 { 0, NULL, NULL }
651 /* Register the protocol with Wireshark */
652 void
653 proto_register_aim_messaging(void)
656 /* Setup list of header fields */
657 static hf_register_info hf[] = {
658 { &hf_aim_icbm_channel,
659 { "Channel", "aim_messaging.icbm.channel", FT_UINT16, BASE_HEX, VALS(icbm_channel_types), 0x0, NULL, HFILL },
661 { &hf_aim_icbm_msg_flags,
662 { "Message Flags", "aim_messaging.icbm.flags", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL },
664 { &hf_aim_icbm_max_snac_size,
665 { "Max SNAC Size", "aim_messaging.icbm.max_snac", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL },
667 { &hf_aim_icbm_max_sender_warnlevel,
668 { "Max sender warn level", "aim_messaging.icbm.max_sender_warn-level", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL },
670 { &hf_aim_icbm_max_receiver_warnlevel,
671 { "max receiver warn level", "aim_messaging.icbm.max_receiver_warnlevel", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL },
673 { &hf_aim_icbm_min_msg_interval,
674 { "Minimum message interval (milliseconds)", "aim_messaging.icbm.min_msg_interval", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL },
676 { &hf_aim_icbm_cookie,
677 { "ICBM Cookie", "aim_messaging.icbmcookie", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
679 { &hf_aim_message_channel_id,
680 { "Message Channel ID", "aim_messaging.channelid", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
682 { &hf_aim_icbm_evil,
683 { "Send Evil Bit As", "aim_messaging.evilreq.origin", FT_UINT16, BASE_DEC, VALS(evil_origins), 0x0, NULL, HFILL },
685 { &hf_aim_evil_warn_level,
686 { "Old warning level", "aim_messaging.evil.warn_level", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL },
688 { &hf_aim_evil_new_warn_level,
689 { "New warning level", "aim_messaging.evil.new_warn_level", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL },
691 { &hf_aim_icbm_notification_cookie,
692 { "Notification Cookie", "aim_messaging.notification.cookie", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL },
694 { &hf_aim_icbm_notification_channel,
695 { "Notification Channel", "aim_messaging.notification.channel", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL },
697 { &hf_aim_icbm_notification_type,
698 { "Notification Type", "aim_messaging.notification.type", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL },
700 { &hf_aim_icbm_rendezvous_nak,
701 { "Rendezvous NAK reason", "aim_messaging.rendezvous_nak", FT_UINT16, BASE_HEX, VALS(rendezvous_nak_reason_types), 0x0, NULL, HFILL },
703 { &hf_aim_icbm_rendezvous_nak_length,
704 { "Rendezvous NAK reason length", "aim_messaging.rendezvous_nak_length", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL },
706 { &hf_aim_rendezvous_msg_type,
707 { "Message Type", "aim_messaging.rendezvous.msg_type", FT_UINT16, BASE_HEX, VALS(rendezvous_msg_types), 0x0, NULL, HFILL },
709 { &hf_aim_icbm_client_err_reason,
710 { "Reason", "aim_messaging.clienterr.reason", FT_UINT16, BASE_DEC, VALS(client_err_reason_types), 0x0, NULL, HFILL },
712 { &hf_aim_icbm_client_err_protocol_version,
713 { "Version", "aim_messaging.clienterr.protocol_version", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL },
715 { &hf_aim_icbm_client_err_client_caps_flags,
716 { "Client Capabilities Flags", "aim_messaging.clienterr.client_caps_flags", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL },
718 { &hf_aim_rendezvous_extended_data_message_type,
719 { "Message Type", "aim_messaging.icbm.extended_data.message.type", FT_UINT8, BASE_HEX, VALS(extended_data_message_types), 0x0, NULL, HFILL },
721 { &hf_aim_rendezvous_extended_data_message_flags,
722 { "Message Flags", "aim_messaging.icbm.extended_data.message.flags", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL },
724 { &hf_aim_rendezvous_extended_data_message_flags_normal,
725 { "Normal Message", "aim_messaging.icbm.extended_data.message.flags.normal", FT_BOOLEAN, 16, TFS(&tfs_set_notset), EXTENDED_DATA_MFLAG_NORMAL, NULL, HFILL },
727 { &hf_aim_rendezvous_extended_data_message_flags_auto,
728 { "Auto Message", "aim_messaging.icbm.extended_data.message.flags.auto", FT_BOOLEAN, 16, TFS(&tfs_set_notset), EXTENDED_DATA_MFLAG_AUTO, NULL, HFILL },
730 { &hf_aim_rendezvous_extended_data_message_flags_multi,
731 { "Multiple Recipients Message", "aim_messaging.icbm.rendezvous.extended_data.message.flags.multi", FT_BOOLEAN, 16, TFS(&tfs_set_notset), EXTENDED_DATA_MFLAG_MULTI, NULL, HFILL },
733 { &hf_aim_rendezvous_extended_data_message_status_code,
734 { "Status Code", "aim_messaging.icbm.extended_data.message.status_code", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL },
736 { &hf_aim_rendezvous_extended_data_message_priority_code,
737 { "Priority Code", "aim_messaging.icbm.extended_data.message.priority_code", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL },
739 { &hf_aim_rendezvous_extended_data_message_text_length,
740 { "Text Length", "aim_messaging.icbm.extended_data.message.text_length", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL },
742 #if 0
743 { &hf_aim_rendezvous_extended_data_message_text,
744 { "Text", "aim_messaging.icbm.extended_data.message.text", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL },
746 #endif
749 /* Setup protocol subtree array */
750 static gint *ett[] = {
751 &ett_aim_messaging,
752 &ett_aim_rendezvous_data,
753 &ett_aim_extended_data,
754 &ett_aim_extended_data_message_flags
757 /* Register the protocol name and description */
758 proto_aim_messaging = proto_register_protocol("AIM Messaging", "AIM Messaging", "aim_messaging");
760 /* Required function calls to register the header fields and subtrees used */
761 proto_register_field_array(proto_aim_messaging, hf, array_length(hf));
762 proto_register_subtree_array(ett, array_length(ett));
765 void
766 proto_reg_handoff_aim_messaging(void)
768 aim_init_family(proto_aim_messaging, ett_aim_messaging, FAMILY_MESSAGING, aim_fnac_family_messaging);