HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / dissectors / packet-aim-ssi.c
blob062be49ceee9c442725588e6c4b3fe19862cebba
1 /* packet-aim-ssi.c
2 * Routines for AIM Instant Messenger (OSCAR) dissection, SNAC SSI
3 * Copyright 2004, Jelmer Vernooij <jelmer@samba.org>
4 * Copyright 2000, Ralf Hoelzer <ralf@well.com>
6 * $Id$
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "config.h"
29 #include <glib.h>
31 #include <epan/packet.h>
33 #include "packet-aim.h"
35 void proto_register_aim_ssi(void);
36 void proto_reg_handoff_aim_ssi(void);
38 #define FAMILY_SSI 0x0013
41 #define FAMILY_SSI_TYPE_BUDDY 0x0000
42 #define FAMILY_SSI_TYPE_GROUP 0x0001
43 #define FAMILY_SSI_TYPE_PERMIT 0x0002
44 #define FAMILY_SSI_TYPE_DENY 0x0003
45 #define FAMILY_SSI_TYPE_PDINFO 0x0004
46 #define FAMILY_SSI_TYPE_PRESENCEPREFS 0x0005
47 #define FAMILY_SSI_TYPE_ICONINFO 0x0014
49 static const value_string aim_fnac_family_ssi_types[] = {
50 { FAMILY_SSI_TYPE_BUDDY, "Buddy" },
51 { FAMILY_SSI_TYPE_GROUP, "Group" },
52 { FAMILY_SSI_TYPE_PERMIT, "Permit" },
53 { FAMILY_SSI_TYPE_DENY, "Deny" },
54 { FAMILY_SSI_TYPE_PDINFO, "PDINFO" },
55 { FAMILY_SSI_TYPE_PRESENCEPREFS, "Presence Preferences" },
56 { FAMILY_SSI_TYPE_ICONINFO, "Icon Info" },
57 { 0, NULL }
60 #define SSI_RIGHTSINFO_TLV_MAX_ITEMS 0x0004
62 static const aim_tlv aim_ssi_rightsinfo_tlvs[] = {
63 { SSI_RIGHTSINFO_TLV_MAX_ITEMS, "Maximums For Items", dissect_aim_tlv_value_bytes },
64 { 0, NULL, NULL },
67 /* Initialize the protocol and registered fields */
68 static int proto_aim_ssi = -1;
69 static int hf_aim_fnac_subtype_ssi_version = -1;
70 static int hf_aim_fnac_subtype_ssi_numitems = -1;
71 static int hf_aim_fnac_subtype_ssi_last_change_time = -1;
72 static int hf_aim_fnac_subtype_ssi_buddyname_len = -1;
73 static int hf_aim_fnac_subtype_ssi_buddyname_len8 = -1;
74 static int hf_aim_fnac_subtype_ssi_buddyname = -1;
75 static int hf_aim_fnac_subtype_ssi_gid = -1;
76 static int hf_aim_fnac_subtype_ssi_bid = -1;
77 static int hf_aim_fnac_subtype_ssi_type = -1;
78 static int hf_aim_fnac_subtype_ssi_tlvlen = -1;
79 /* static int hf_aim_fnac_subtype_ssi_data = -1; */
80 static int hf_aim_fnac_subtype_ssi_reason_str_len = -1;
81 static int hf_aim_fnac_subtype_ssi_reason_str = -1;
82 static int hf_aim_fnac_subtype_ssi_grant_auth_unkn = -1;
83 static int hf_aim_fnac_subtype_ssi_allow_auth = -1;
85 /* Initialize the subtree pointers */
86 static gint ett_aim_ssi = -1;
87 static gint ett_ssi = -1;
89 /** Calculate size of SSI entry
90 * Size of SSI entry can be calculated as:
91 * sizeof(buddy name length field) = sizeof(guint16) = 2
92 * + sizeof(buddy name string) = buddy name length field = N
93 * + sizeof(group ID) = sizeof(guint16) = 2
94 * + sizeof(buddy ID) = sizeof(guint16) = 2
95 * + sizeof(buddy type) = sizeof(guint16) = 2
96 * + sizeof(TLV length) = sizeof(guint16) = 2
97 * + sizeof(TLVs) = TLV length = M
98 * = 2 + N + 2 * 4 + M
100 static int calc_ssi_entry_size(tvbuff_t *tvb, int offset)
102 gint ssi_entry_size = 2 + tvb_get_ntohs(tvb, offset) + 2 * 3;
103 ssi_entry_size += tvb_get_ntohs(tvb, offset + ssi_entry_size) + 2;
104 return ssi_entry_size;
107 static int dissect_ssi_item(tvbuff_t *tvb, packet_info *pinfo _U_, int offset, proto_tree *ssi_entry)
109 guint16 buddyname_length = 0;
110 int endoffset;
111 guint16 tlv_len = 0;
113 /* Buddy Name Length */
114 buddyname_length = tvb_get_ntohs(tvb, offset);
115 proto_tree_add_item(ssi_entry, hf_aim_fnac_subtype_ssi_buddyname_len, tvb, offset, 2, ENC_BIG_ENDIAN);
116 offset += 2;
118 /* Buddy Name */
119 if (buddyname_length > 0) {
120 proto_tree_add_item(ssi_entry, hf_aim_fnac_subtype_ssi_buddyname, tvb, offset, buddyname_length, ENC_ASCII|ENC_NA);
121 offset += buddyname_length;
124 /* Buddy group ID */
125 proto_tree_add_item(ssi_entry, hf_aim_fnac_subtype_ssi_gid, tvb, offset, 2, ENC_BIG_ENDIAN);
126 offset += 2;
128 /* Buddy ID */
129 proto_tree_add_item(ssi_entry, hf_aim_fnac_subtype_ssi_bid, tvb, offset, 2, ENC_BIG_ENDIAN);
130 offset += 2;
132 /* Buddy Type */
133 proto_tree_add_item(ssi_entry, hf_aim_fnac_subtype_ssi_type, tvb, offset, 2, ENC_BIG_ENDIAN);
134 offset += 2;
136 /* Size of the following TLV in bytes (as opposed to the number of
137 TLV objects in the chain) */
138 tlv_len = tvb_get_ntohs(tvb, offset);
139 proto_tree_add_item(ssi_entry, hf_aim_fnac_subtype_ssi_tlvlen, tvb, offset, 2, ENC_BIG_ENDIAN);
140 offset += 2;
142 endoffset = offset;
143 /* For now, we just dump the TLV contents as-is, since there is not a
144 TLV dissection utility that works based on total chain length */
145 while(endoffset < offset+tlv_len) {
146 endoffset = dissect_aim_tlv(tvb, pinfo, endoffset, ssi_entry, aim_client_tlvs);
148 return endoffset;
151 static int dissect_ssi_ssi_item(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ssi_entry)
153 return dissect_ssi_item(tvb, pinfo, 0, ssi_entry);
156 static int dissect_ssi_ssi_items(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
158 int offset = 0;
159 gint ssi_entry_size;
160 proto_item *ti;
161 proto_tree *ssi_entry = NULL;
162 int size = tvb_length(tvb);
163 while (size > offset)
165 ssi_entry_size = calc_ssi_entry_size(tvb, offset);
166 ti = proto_tree_add_text(tree, tvb, offset, ssi_entry_size, "SSI Entry");
167 ssi_entry = proto_item_add_subtree(ti, ett_aim_ssi);
168 offset = dissect_ssi_item(tvb, pinfo, offset, ssi_entry);
170 return offset;
173 static int dissect_aim_ssi_rightsinfo(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ssi_tree)
175 return dissect_aim_tlv_sequence(tvb, pinfo, 0, ssi_tree, aim_ssi_rightsinfo_tlvs);
178 static int dissect_aim_ssi_was_added(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ssi_tree)
180 return dissect_aim_buddyname(tvb, pinfo, 0, ssi_tree);
183 static int dissect_aim_snac_ssi_time_and_items_num(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
185 int offset = 0;
187 /* get timestamp */
188 nstime_t tmptime;
189 tmptime.secs = tvb_get_ntohl(tvb, offset);
190 tmptime.nsecs = 0;
191 proto_tree_add_time(tree, hf_aim_fnac_subtype_ssi_last_change_time, tvb, offset, 4, &tmptime);
192 offset += 4;
194 /* get number of SSI items */
195 proto_tree_add_item(tree, hf_aim_fnac_subtype_ssi_numitems, tvb, offset, 2, ENC_BIG_ENDIAN);
196 offset += 2;
198 return offset;
201 static int dissect_aim_snac_ssi_list(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
203 int offset = 0;
204 proto_item *ti;
205 proto_tree *ssi_entry = NULL;
206 guint16 num_items, i;
207 nstime_t tmptime;
208 gint ssi_entry_size;
210 /* SSI Version */
211 proto_tree_add_item(tree, hf_aim_fnac_subtype_ssi_version, tvb, offset, 1, ENC_BIG_ENDIAN);
212 offset += 1;
214 /* Number of items */
215 proto_tree_add_item(tree, hf_aim_fnac_subtype_ssi_numitems, tvb, offset, 2, ENC_BIG_ENDIAN);
216 num_items = tvb_get_ntohs(tvb, offset);
217 offset += 2;
219 for(i = 0; i < num_items; i++) {
220 ssi_entry_size = calc_ssi_entry_size(tvb, offset);
221 ti = proto_tree_add_text(tree, tvb, offset, ssi_entry_size, "SSI Entry %u", i);
222 ssi_entry = proto_item_add_subtree(ti, ett_aim_ssi);
223 offset = dissect_ssi_item(tvb, pinfo, offset, ssi_entry);
225 tmptime.secs = tvb_get_ntohl(tvb, offset);
226 tmptime.nsecs = 0;
227 proto_tree_add_time(tree, hf_aim_fnac_subtype_ssi_last_change_time, tvb, offset, 4, &tmptime);
229 return offset;
232 static int dissect_aim_snac_ssi_auth_request(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
234 int offset = 0;
235 guint16 reason_length;
236 /*guint16 unknown;*/
238 /* get buddy length (1 byte) */
239 guint8 buddyname_length = tvb_get_guint8(tvb, offset);
240 proto_tree_add_item(tree, hf_aim_fnac_subtype_ssi_buddyname_len8, tvb, offset, 1, ENC_BIG_ENDIAN);
241 offset += 1;
243 /* show buddy name */
244 if (buddyname_length > 0) {
245 proto_tree_add_item(tree, hf_aim_fnac_subtype_ssi_buddyname, tvb, offset, buddyname_length, ENC_ASCII|ENC_NA);
246 offset += buddyname_length;
248 /* get reason message length (2 bytes) */
249 reason_length = tvb_get_ntohs(tvb, offset);
250 proto_tree_add_item(tree, hf_aim_fnac_subtype_ssi_reason_str_len, tvb, offset, 2, ENC_BIG_ENDIAN);
251 offset += 2;
253 /* show reason message if present */
254 if (reason_length > 0) {
255 proto_tree_add_item(tree, hf_aim_fnac_subtype_ssi_reason_str, tvb, offset, reason_length, ENC_ASCII|ENC_NA);
256 offset += reason_length;
259 /* unknown (always 0x0000 ???) */
260 /*unknown = tvb_get_ntohs(tvb, offset);*/
261 proto_tree_add_item(tree, hf_aim_fnac_subtype_ssi_grant_auth_unkn, tvb, offset, 2, ENC_BIG_ENDIAN);
262 offset += 2;
264 return offset;
267 static int dissect_aim_snac_ssi_auth_reply(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
269 int offset = 0;
270 guint16 reason_length;
272 /* get buddy length (1 byte) */
273 guint8 buddyname_length = tvb_get_guint8(tvb, offset);
274 proto_tree_add_item(tree, hf_aim_fnac_subtype_ssi_buddyname_len8, tvb, offset, 1, ENC_BIG_ENDIAN);
275 offset += 1;
277 /* show buddy name */
278 if (buddyname_length > 0) {
279 proto_tree_add_item(tree, hf_aim_fnac_subtype_ssi_buddyname, tvb, offset, buddyname_length, ENC_ASCII|ENC_NA);
280 offset += buddyname_length;
283 /* accept/reject authorization flag */
284 proto_tree_add_item(tree, hf_aim_fnac_subtype_ssi_allow_auth, tvb, offset, 1, ENC_BIG_ENDIAN);
285 offset += 1;
287 /* get reason message length (2 bytes) */
288 reason_length = tvb_get_ntohs(tvb, offset);
289 proto_tree_add_item(tree, hf_aim_fnac_subtype_ssi_reason_str_len, tvb, offset, 2, ENC_BIG_ENDIAN);
290 offset += 2;
292 /* show reason message if present */
293 if (reason_length > 0) {
294 proto_tree_add_item(tree, hf_aim_fnac_subtype_ssi_reason_str, tvb, offset, reason_length, ENC_ASCII|ENC_NA);
295 offset += reason_length;
298 return offset;
302 static const aim_subtype aim_fnac_family_ssi[] = {
303 { 0x0001, "Error", dissect_aim_snac_error },
304 { 0x0002, "Request Rights", NULL },
305 { 0x0003, "Rights Info", dissect_aim_ssi_rightsinfo },
306 { 0x0004, "Request List (first time)", NULL },
307 { 0x0005, "Request List", dissect_aim_snac_ssi_time_and_items_num },
308 { 0x0006, "List", dissect_aim_snac_ssi_list },
309 { 0x0007, "Activate", NULL },
310 { 0x0008, "Add Buddy", dissect_ssi_ssi_item },
311 { 0x0009, "Modify Buddy", dissect_ssi_ssi_items },
312 { 0x000a, "Delete Buddy", dissect_ssi_ssi_item },
313 { 0x000e, "Server Ack", dissect_aim_ssi_result },
314 { 0x000f, "No List", dissect_aim_snac_ssi_time_and_items_num },
315 { 0x0011, "Edit Start", NULL },
316 { 0x0012, "Edit Stop", NULL },
317 { 0x0014, "Grant Future Authorization to Buddy", dissect_aim_snac_ssi_auth_request },
318 { 0x0015, "Future Authorization Granted", dissect_aim_snac_ssi_auth_request },
319 { 0x0018, "Send Authentication Request", dissect_aim_snac_ssi_auth_request },
320 { 0x0019, "Authentication Request", dissect_aim_snac_ssi_auth_request },
321 { 0x001a, "Send Authentication Reply", dissect_aim_snac_ssi_auth_reply },
322 { 0x001b, "Authentication Reply", dissect_aim_snac_ssi_auth_reply },
323 { 0x001c, "Remote User Added Client To List", dissect_aim_ssi_was_added },
324 { 0, NULL, NULL }
328 /* Register the protocol with Wireshark */
329 void
330 proto_register_aim_ssi(void)
332 /* Setup list of header fields */
333 static hf_register_info hf[] = {
334 { &hf_aim_fnac_subtype_ssi_version,
335 { "SSI Version", "aim_ssi.fnac.version", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }
337 { &hf_aim_fnac_subtype_ssi_numitems,
338 { "SSI Object count", "aim_ssi.fnac.numitems", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
340 { &hf_aim_fnac_subtype_ssi_last_change_time,
341 { "SSI Last Change Time", "aim_ssi.fnac.last_change_time", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0x0, NULL, HFILL }
343 { &hf_aim_fnac_subtype_ssi_buddyname_len,
344 { "SSI Buddy Name length", "aim_ssi.fnac.buddyname_len", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
346 { &hf_aim_fnac_subtype_ssi_buddyname,
347 { "Buddy Name", "aim_ssi.fnac.buddyname", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
349 { &hf_aim_fnac_subtype_ssi_gid,
350 { "SSI Buddy Group ID", "aim_ssi.fnac.gid", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
352 { &hf_aim_fnac_subtype_ssi_bid,
353 { "SSI Buddy ID", "aim_ssi.fnac.bid", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
355 { &hf_aim_fnac_subtype_ssi_type,
356 { "SSI Buddy type", "aim_ssi.fnac.type", FT_UINT16, BASE_HEX, VALS(aim_fnac_family_ssi_types), 0x0, NULL, HFILL }
358 { &hf_aim_fnac_subtype_ssi_tlvlen,
359 { "SSI TLV Len", "aim_ssi.fnac.tlvlen", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
361 #if 0
362 { &hf_aim_fnac_subtype_ssi_data,
363 { "SSI Buddy Data", "aim_ssi.fnac.data", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
365 #endif
366 { &hf_aim_fnac_subtype_ssi_buddyname_len8,
367 { "SSI Buddy Name length", "aim_ssi.fnac.buddyname_len8", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }
369 { &hf_aim_fnac_subtype_ssi_reason_str_len,
370 { "Reason Message length", "aim_ssi.fnac.reason_len", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
372 { &hf_aim_fnac_subtype_ssi_reason_str,
373 { "Reason Message", "aim_ssi.fnac.reason", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }
375 { &hf_aim_fnac_subtype_ssi_grant_auth_unkn,
376 { "Unknown", "aim_ssi.fnac.auth_unkn", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
378 { &hf_aim_fnac_subtype_ssi_allow_auth,
379 { "Allow flag", "aim_ssi.fnac.allow_auth_flag", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }
383 /* Setup protocol subtree array */
384 static gint *ett[] = {
385 &ett_aim_ssi,
386 &ett_ssi,
389 /* Register the protocol name and description */
390 proto_aim_ssi = proto_register_protocol("AIM Server Side Info", "AIM SSI", "aim_ssi");
392 /* Required function calls to register the header fields and subtrees used */
393 proto_register_field_array(proto_aim_ssi, hf, array_length(hf));
394 proto_register_subtree_array(ett, array_length(ett));
397 void proto_reg_handoff_aim_ssi(void)
399 aim_init_family(proto_aim_ssi, ett_aim_ssi, FAMILY_SSI, aim_fnac_family_ssi);