2 * Routines for kismet packet dissection
3 * Copyright 2006, Krzysztof Burghardt <krzysztof@burghardt.pl>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * Copied from packet-pop.c
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 #include <epan/packet.h>
37 #include <epan/strutil.h>
38 #include <epan/prefs.h>
40 static int proto_kismet = -1;
41 static int hf_kismet_response = -1;
42 static int hf_kismet_request = -1;
44 static gint ett_kismet = -1;
45 static gint ett_kismet_reqresp = -1;
47 static dissector_handle_t data_handle;
49 #define TCP_PORT_KISMET 2501
51 static guint global_kismet_tcp_port = TCP_PORT_KISMET;
53 static gboolean response_is_continuation(const guchar * data);
54 void proto_reg_handoff_kismet(void);
55 void proto_register_kismet(void);
58 dissect_kismet(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
61 gboolean is_continuation;
62 proto_tree *kismet_tree=NULL, *reqresp_tree=NULL;
71 const guchar *next_token;
74 * Find the end of the first line.
76 * Note that "tvb_find_line_end()" will return a value that is
77 * not longer than what's in the buffer, so the "tvb_get_ptr()"
78 * call won't throw an exception.
80 linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE);
81 line = tvb_get_ptr(tvb, offset, linelen);
84 * Check if it is an ASCII based protocol with reasonable length
85 * packets, if not return, and try annother dissector.
93 for (i = 0; i < 8; ++i) {
95 * Packet contains non-ASCII data
97 if (line[i] < 32 || line[i] > 128)
103 * If it is Kismet traffic set COL_PROTOCOL.
105 col_set_str(pinfo->cinfo, COL_PROTOCOL, "kismet");
108 * Check if it is request, reply or continuation.
110 if (pinfo->match_port == pinfo->destport) {
112 is_continuation = FALSE;
115 is_continuation = response_is_continuation (line);
118 if (check_col(pinfo->cinfo, COL_INFO)) {
120 * Put the first line from the buffer into the summary
121 * if it's a kismet request or reply (but leave out the
123 * Otherwise, just call it a continuation.
126 col_set_str(pinfo->cinfo, COL_INFO, "Continuation");
128 col_add_fstr(pinfo->cinfo, COL_INFO, "%s: %s",
129 is_request ? "Request" : "Response",
130 format_text(line, linelen));
134 ti = proto_tree_add_item(tree, proto_kismet, tvb, offset, -1, FALSE);
135 kismet_tree = proto_item_add_subtree(ti, ett_kismet);
138 if (is_continuation) {
140 * Put the whole packet into the tree as data.
142 call_dissector(data_handle, tvb, pinfo, kismet_tree);
147 tmp_item = proto_tree_add_boolean(kismet_tree,
148 hf_kismet_request, tvb, 0, 0, TRUE);
150 tmp_item = proto_tree_add_boolean(kismet_tree,
151 hf_kismet_response, tvb, 0, 0, TRUE);
153 PROTO_ITEM_SET_GENERATED (tmp_item);
155 while (tvb_offset_exists(tvb, offset)) {
157 * Find the end of the line.
159 linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE);
165 ti = proto_tree_add_text(kismet_tree, tvb, offset,
166 next_offset - offset, "%s",
167 tvb_format_text(tvb, offset,
168 next_offset - offset - 1));
169 reqresp_tree = proto_item_add_subtree(ti, ett_kismet_reqresp);
170 tokenlen = get_token_len(line, line + linelen, &next_token);
173 reqresp = tvb_get_ephemeral_string(tvb, offset, tokenlen);
176 * No request dissection
180 * *KISMET: {Version} {Start time} \001{Server name}\001 {Build Revision}
181 * two fields left undocumented: {???} {?ExtendedVersion?}
183 if (!strncmp(reqresp, "*KISMET", 7)) {
184 offset += (gint) (next_token - line);
185 linelen -= (int) (next_token - line);
187 tokenlen = get_token_len(line, line + linelen, &next_token);
188 proto_tree_add_text(reqresp_tree, tvb, offset,
189 tokenlen, "Kismet version: %s",
190 format_text(line, tokenlen));
192 offset += (gint) (next_token - line);
193 linelen -= (int) (next_token - line);
195 tokenlen = get_token_len(line, line + linelen, &next_token);
196 proto_tree_add_text(reqresp_tree, tvb, offset,
197 tokenlen, "Start time: %s",
198 format_text(line, tokenlen));
200 offset += (gint) (next_token - line);
201 linelen -= (int) (next_token - line);
203 tokenlen = get_token_len(line, line + linelen, &next_token);
204 proto_tree_add_text(reqresp_tree, tvb, offset,
205 tokenlen, "Server name: %s",
206 format_text(line + 1, tokenlen - 2));
208 offset += (gint) (next_token - line);
209 linelen -= (int) (next_token - line);
211 tokenlen = get_token_len(line, line + linelen, &next_token);
212 proto_tree_add_text(reqresp_tree, tvb, offset,
213 tokenlen, "Build revision: %s",
214 format_text(line, tokenlen));
216 offset += (gint) (next_token - line);
217 linelen -= (int) (next_token - line);
219 tokenlen = get_token_len(line, line + linelen, &next_token);
220 proto_tree_add_text(reqresp_tree, tvb, offset,
221 tokenlen, "Unknown field: %s",
222 format_text(line, tokenlen));
224 offset += (gint) (next_token - line);
225 linelen -= (int) (next_token - line);
227 tokenlen = get_token_len(line, line + linelen, &next_token);
228 proto_tree_add_text(reqresp_tree, tvb, offset,
230 "Extended version string: %s",
231 format_text(line, tokenlen));
236 if (!strncmp(reqresp, "*TIME", 5)) {
240 offset += (gint) (next_token - line);
241 linelen -= (int) (next_token - line);
243 tokenlen = get_token_len(line, line + linelen, &next_token);
246 * Convert form ascii to time_t
248 t = atoi(format_text (line, tokenlen));
251 * Format ascii representaion of time
257 ptr[strlen(ptr) - 1] = 0;
259 proto_tree_add_text(reqresp_tree, tvb, offset,
260 tokenlen, "Time: %s", ptr);
264 offset += (gint) (next_token - line);
265 linelen -= (int) (next_token - line);
269 offset = next_offset;
276 response_is_continuation(const guchar * data)
278 if (!strncmp(data, "*", 1))
281 if (!strncmp(data, "!", 1))
288 proto_register_kismet(void)
290 static hf_register_info hf[] = {
291 {&hf_kismet_response,
292 {"Response", "kismet.response", FT_BOOLEAN, BASE_NONE,
293 NULL, 0x0, "TRUE if kismet response", HFILL}},
296 {"Request", "kismet.request", FT_BOOLEAN, BASE_NONE,
297 NULL, 0x0, "TRUE if kismet request", HFILL}}
300 static gint *ett[] = {
304 module_t *kismet_module;
306 proto_kismet = proto_register_protocol("Kismet Client/Server Protocol", "Kismet", "kismet");
307 proto_register_field_array(proto_kismet, hf, array_length (hf));
308 proto_register_subtree_array(ett, array_length (ett));
310 /* Register our configuration options for Kismet, particularly our port */
312 kismet_module = prefs_register_protocol(proto_kismet, proto_reg_handoff_kismet);
314 prefs_register_uint_preference(kismet_module, "tcp.port",
315 "Kismet Server TCP Port",
316 "Set the port for Kismet Client/Server messages (if other"
317 " than the default of 2501)", 10,
318 &global_kismet_tcp_port);
322 proto_reg_handoff_kismet(void)
324 static gboolean kismet_prefs_initialized = FALSE;
325 static dissector_handle_t kismet_handle;
326 static guint tcp_port;
328 if (!kismet_prefs_initialized) {
329 kismet_handle = new_create_dissector_handle(dissect_kismet, proto_kismet);
330 data_handle = find_dissector("data");
331 kismet_prefs_initialized = TRUE;
333 dissector_delete("tcp.port", tcp_port, kismet_handle);
336 /* Set our port number for future use */
337 tcp_port = global_kismet_tcp_port;
339 dissector_add("tcp.port", global_kismet_tcp_port, kismet_handle);