- some radcom files seem to have a different magic key than the one we
[obnox/wireshark/wip.git] / packet-yhoo.c
1 /* packet-yhoo.c
2  * Routines for yahoo messenger packet dissection
3  * Copyright 1999, Nathan Neulinger <nneul@umr.edu>
4  *
5  * $Id: packet-yhoo.c,v 1.25 2002/08/28 21:00:40 jmayer Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
9  * Copyright 1998 Gerald Combs
10  *
11  * Copied from packet-tftp.c
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <stdio.h>
33
34 #include <string.h>
35 #include <glib.h>
36 #include <epan/packet.h>
37 #include "packet-yhoo.h"
38
39 static int proto_yhoo = -1;
40 static int hf_yhoo_version = -1;
41 static int hf_yhoo_len = -1;
42 static int hf_yhoo_service = -1;
43 static int hf_yhoo_connection_id = -1;
44 static int hf_yhoo_magic_id = -1;
45 static int hf_yhoo_unknown1 = -1;
46 static int hf_yhoo_msgtype = -1;
47 static int hf_yhoo_nick1 = -1;
48 static int hf_yhoo_nick2 = -1;
49 static int hf_yhoo_content = -1;
50
51 static gint ett_yhoo = -1;
52
53 #define TCP_PORT_YHOO   5050
54
55 static const value_string yhoo_service_vals[] = {
56         {YAHOO_SERVICE_LOGON, "Pager Logon"},
57         {YAHOO_SERVICE_LOGOFF, "Pager Logoff"},
58         {YAHOO_SERVICE_ISAWAY, "Is Away"},
59         {YAHOO_SERVICE_ISBACK, "Is Back"},
60         {YAHOO_SERVICE_IDLE, "Idle"},
61         {YAHOO_SERVICE_MESSAGE, "Message"},
62         {YAHOO_SERVICE_IDACT, "Activate Identity"},
63         {YAHOO_SERVICE_IDDEACT, "Deactivate Identity"},
64         {YAHOO_SERVICE_MAILSTAT, "Mail Status"},
65         {YAHOO_SERVICE_USERSTAT, "User Status"},
66         {YAHOO_SERVICE_NEWMAIL, "New Mail"},
67         {YAHOO_SERVICE_CHATINVITE, "Chat Invitation"},
68         {YAHOO_SERVICE_CALENDAR, "Calendar Reminder"},
69         {YAHOO_SERVICE_NEWPERSONALMAIL, "New Personals Mail"},
70         {YAHOO_SERVICE_NEWCONTACT, "New Friend"},
71         {YAHOO_SERVICE_GROUPRENAME, "Group Renamed"},
72         {YAHOO_SERVICE_ADDIDENT, "Add Identity"},
73         {YAHOO_SERVICE_ADDIGNORE, "Add Ignore"},
74         {YAHOO_SERVICE_PING, "Ping"},
75         {YAHOO_SERVICE_SYSMESSAGE, "System Message"},
76         {YAHOO_SERVICE_CONFINVITE, "Conference Invitation"},
77         {YAHOO_SERVICE_CONFLOGON, "Conference Logon"},
78         {YAHOO_SERVICE_CONFDECLINE, "Conference Decline"},
79         {YAHOO_SERVICE_CONFLOGOFF, "Conference Logoff"},
80         {YAHOO_SERVICE_CONFMSG, "Conference Message"},
81         {YAHOO_SERVICE_CONFADDINVITE, "Conference Additional Invitation"},
82         {YAHOO_SERVICE_CHATLOGON, "Chat Logon"},
83         {YAHOO_SERVICE_CHATLOGOFF, "Chat Logoff"},
84         {YAHOO_SERVICE_CHATMSG, "Chat Message"},
85         {YAHOO_SERVICE_FILETRANSFER, "File Transfer"},
86         {YAHOO_SERVICE_PASSTHROUGH2, "Passthrough 2"},
87         {0, NULL}
88 };
89
90 static const value_string yhoo_msgtype_vals[] = {
91         {YAHOO_MSGTYPE_NONE, "None"},
92         {YAHOO_MSGTYPE_NORMAL, "Normal"},
93         {YAHOO_MSGTYPE_BOUNCE, "Bounce"},
94         {YAHOO_MSGTYPE_STATUS, "Status Update"},
95         {YAHOO_MSGTYPE_OFFLINE, "Request Offline"},
96         {0, NULL}
97 };
98
99 static gboolean
100 dissect_yhoo(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
101 {
102         proto_tree      *yhoo_tree, *ti;
103         int offset = 0;
104
105         if (pinfo->srcport != TCP_PORT_YHOO && pinfo->destport != TCP_PORT_YHOO) {
106                 /* Not the Yahoo port - not a Yahoo Messenger packet. */
107                 return FALSE;
108         }
109
110         /* get at least a full packet structure */
111         if ( !tvb_bytes_exist(tvb, 0, sizeof(struct yahoo_rawpacket)) ) {
112                 /* Not enough data captured; maybe it is a Yahoo
113                    Messenger packet, but it contains too little data to
114                    tell. */
115                 return FALSE;
116         }
117
118         if (memcmp(tvb_get_ptr(tvb, offset, 4), "YPNS", 4) != 0 &&
119             memcmp(tvb_get_ptr(tvb, offset, 4), "YHOO", 4) != 0) {
120                 /* Not a Yahoo Messenger packet. */
121                 return FALSE;
122         }
123
124         if (check_col(pinfo->cinfo, COL_PROTOCOL))
125                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "YHOO");
126
127         offset = 0;
128         if (check_col(pinfo->cinfo, COL_INFO)) {
129                 col_add_fstr(pinfo->cinfo, COL_INFO,
130                         "%s: %s",
131                         ( strncmp(tvb_get_ptr(tvb, offset + 0, 4), "YPNS", 4) == 0 ) ? "Request" : "Response",
132                         val_to_str(tvb_get_letohl(tvb, offset + 12),
133                                  yhoo_service_vals, "Unknown Service: %u")
134                 );
135         }
136
137         if (tree) {
138                 ti = proto_tree_add_item(tree, proto_yhoo, tvb, offset, -1,
139                         FALSE);
140                 yhoo_tree = proto_item_add_subtree(ti, ett_yhoo);
141
142                 proto_tree_add_item(yhoo_tree, hf_yhoo_version, tvb,
143                         offset, 8, TRUE);
144                 offset += 8;
145
146                 proto_tree_add_item(yhoo_tree, hf_yhoo_len, tvb,
147                         offset, 4, TRUE);
148                 offset += 4;
149
150                 proto_tree_add_item(yhoo_tree, hf_yhoo_service, tvb,
151                         offset, 4, TRUE);
152                 offset += 4;
153
154                 proto_tree_add_item(yhoo_tree, hf_yhoo_connection_id, tvb,
155                         offset, 4, TRUE);
156                 offset += 4;
157
158                 proto_tree_add_item(yhoo_tree, hf_yhoo_magic_id, tvb,
159                         offset, 4, TRUE);
160                 offset += 4;
161
162                 proto_tree_add_item(yhoo_tree, hf_yhoo_unknown1, tvb,
163                         offset, 4, TRUE);
164                 offset += 4;
165
166                 proto_tree_add_item(yhoo_tree, hf_yhoo_msgtype, tvb,
167                         offset, 4, TRUE);
168                 offset += 4;
169
170                 proto_tree_add_item(yhoo_tree, hf_yhoo_nick1, tvb,
171                         offset, 36, TRUE);
172                 offset += 36;
173
174                 proto_tree_add_item(yhoo_tree, hf_yhoo_nick2, tvb,
175                         offset, 36, TRUE);
176                 offset += 36;
177
178                 proto_tree_add_item(yhoo_tree, hf_yhoo_content, tvb, -1,
179                         offset, TRUE);
180         }
181
182         return TRUE;
183 }
184
185 void
186 proto_register_yhoo(void)
187 {
188         static hf_register_info hf[] = {
189                         { &hf_yhoo_service, {
190                                 "Service Type", "yhoo.service", FT_UINT32, BASE_DEC,
191                                 VALS(yhoo_service_vals), 0, "Service Type", HFILL }},
192                         { &hf_yhoo_msgtype, {
193                                 "Message Type", "yhoo.msgtype", FT_UINT32, BASE_DEC,
194                                 VALS(yhoo_msgtype_vals), 0, "Message Type Flags", HFILL }},
195                         { &hf_yhoo_connection_id, {
196                                 "Connection ID", "yhoo.connection_id", FT_UINT32, BASE_HEX,
197                                 NULL, 0, "Connection ID", HFILL }},
198                         { &hf_yhoo_magic_id, {
199                                 "Magic ID", "yhoo.magic_id", FT_UINT32, BASE_HEX,
200                                 NULL, 0, "Magic ID", HFILL }},
201                         { &hf_yhoo_unknown1, {
202                                 "Unknown 1", "yhoo.unknown1", FT_UINT32, BASE_HEX,
203                                 NULL, 0, "Unknown 1", HFILL }},
204                         { &hf_yhoo_len, {
205                                 "Packet Length", "yhoo.len", FT_UINT32, BASE_DEC,
206                                 NULL, 0, "Packet Length", HFILL }},
207                         { &hf_yhoo_nick1, {
208                                 "Real Nick (nick1)", "yhoo.nick1", FT_STRING, 0,
209                                 NULL, 0, "Real Nick (nick1)", HFILL }},
210                         { &hf_yhoo_nick2, {
211                                 "Active Nick (nick2)", "yhoo.nick2", FT_STRING, 0,
212                                 NULL, 0, "Active Nick (nick2)", HFILL }},
213                         { &hf_yhoo_content, {
214                                 "Content", "yhoo.content", FT_STRING, 0,
215                                 NULL, 0, "Data portion of the packet", HFILL }},
216                         { &hf_yhoo_version, {
217                                 "Version", "yhoo.version", FT_STRING, 0,
218                                 NULL, 0, "Packet version identifier", HFILL }},
219         };
220         static gint *ett[] = {
221                 &ett_yhoo,
222         };
223
224         proto_yhoo = proto_register_protocol("Yahoo Messenger Protocol",
225             "YHOO", "yhoo");
226
227         proto_register_field_array(proto_yhoo, hf, array_length(hf));
228
229         proto_register_subtree_array(ett, array_length(ett));
230 }
231
232 void
233 proto_reg_handoff_yhoo(void)
234 {
235         heur_dissector_add("tcp", dissect_yhoo, proto_yhoo);
236 }