2005-05-14 21:00:43 +00:00
|
|
|
/* packet-armagetronad.c
|
|
|
|
* Routines for the Armagetronad packet dissection
|
|
|
|
* Copyright 2005, Guillaume Chazarain <guichaz@yahoo.fr>
|
|
|
|
*
|
2006-05-21 04:49:01 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2005-05-14 21:00:43 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2011-10-21 02:10:19 +00:00
|
|
|
*
|
2005-05-14 21:00:43 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2011-10-21 02:10:19 +00:00
|
|
|
*
|
2005-05-14 21:00:43 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 23:18:38 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2005-05-14 21:00:43 +00:00
|
|
|
*/
|
|
|
|
|
2012-09-20 02:03:38 +00:00
|
|
|
#include "config.h"
|
2005-05-14 21:00:43 +00:00
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include <epan/packet.h>
|
2013-09-12 20:37:30 +00:00
|
|
|
#include <epan/wmem/wmem.h>
|
2005-05-14 21:00:43 +00:00
|
|
|
|
2013-03-13 21:14:20 +00:00
|
|
|
void proto_register_armagetronad(void);
|
|
|
|
void proto_reg_handoff_armagetronad(void);
|
|
|
|
|
2005-05-14 21:00:43 +00:00
|
|
|
/* Initialize the protocol and registered fields */
|
|
|
|
static int proto_armagetronad = -1;
|
|
|
|
static int hf_armagetronad_descriptor_id = -1;
|
|
|
|
static int hf_armagetronad_message_id = -1;
|
|
|
|
static int hf_armagetronad_data_len = -1;
|
|
|
|
static int hf_armagetronad_data = -1;
|
|
|
|
static int hf_armagetronad_sender_id = -1;
|
|
|
|
static int hf_armagetronad_msg_subtree = -1;
|
|
|
|
|
|
|
|
/* Initialize the subtree pointers */
|
|
|
|
static gint ett_armagetronad = -1;
|
|
|
|
static gint ett_message = -1;
|
|
|
|
|
|
|
|
#define UDP_PORT_ARMAGETRONAD 4534
|
|
|
|
#define UDP_PORT_MASTER 4533
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The ACK packet is so common that we treat it
|
|
|
|
* differently: it has no MessageID
|
|
|
|
*/
|
|
|
|
#define ACK 1
|
|
|
|
|
|
|
|
/*
|
2007-06-18 19:15:48 +00:00
|
|
|
* armagetronad-0.2.8.2.1
|
|
|
|
* The numbers and names were retrieved at runtime using the
|
2005-05-14 21:00:43 +00:00
|
|
|
* 'nDescriptor* descriptors[MAXDESCRIPTORS]' array
|
|
|
|
*/
|
2008-08-14 23:51:52 +00:00
|
|
|
static const value_string descriptors[] = {
|
2014-10-04 15:28:35 +00:00
|
|
|
{ 1, "ack"},
|
|
|
|
{ 2, "req_info"},
|
|
|
|
{ 3, "login_deny"},
|
|
|
|
{ 4, "login_ignore"},
|
|
|
|
{ 5, "login_accept"},
|
|
|
|
{ 6, "login1"},
|
|
|
|
{ 7, "logout"},
|
|
|
|
{ 8, "sn_ConsoleOut"},
|
|
|
|
{ 9, "client_cen"},
|
|
|
|
{ 10, "version"},
|
|
|
|
{ 11, "login2"},
|
|
|
|
{ 20, "req_id"},
|
|
|
|
{ 21, "id_req_handler"},
|
|
|
|
{ 22, "net_destroy"},
|
|
|
|
{ 23, "net_control"},
|
|
|
|
{ 24, "net_sync"},
|
|
|
|
{ 25, "ready to get objects"},
|
|
|
|
{ 26, "net_clear"},
|
|
|
|
{ 27, "sync_ack"},
|
|
|
|
{ 28, "sync_msg"},
|
|
|
|
{ 40, "password_request"},
|
|
|
|
{ 41, "password_answer"},
|
|
|
|
{ 50, "small_server"},
|
|
|
|
{ 51, "big_server"},
|
|
|
|
{ 52, "small_request"},
|
|
|
|
{ 53, "big_request"},
|
|
|
|
{ 54, "big_server_master"},
|
|
|
|
{ 55, "big_request_master"},
|
|
|
|
{ 60, "transfer config"},
|
2005-05-14 21:00:43 +00:00
|
|
|
{200, "Chat"},
|
|
|
|
{201, "ePlayerNetID"},
|
|
|
|
{202, "player_removed_from_game"},
|
2007-06-18 19:15:48 +00:00
|
|
|
{203, "Chat Client"},
|
2005-05-14 21:00:43 +00:00
|
|
|
{210, "eTimer"},
|
|
|
|
{220, "eTeam"},
|
|
|
|
{230, "vote cast"},
|
2007-06-18 19:15:48 +00:00
|
|
|
{231, "Kick vote"},
|
|
|
|
{232, "Server controlled vote"},
|
|
|
|
{233, "Server controlled vote expired"},
|
2005-05-14 21:00:43 +00:00
|
|
|
{300, "gNetPlayerWall"},
|
|
|
|
{310, "game"},
|
|
|
|
{311, "client_gamestate"},
|
|
|
|
{320, "cycle"},
|
2008-12-17 17:23:37 +00:00
|
|
|
{321, "destination"},
|
2005-05-14 21:00:43 +00:00
|
|
|
{330, "gAIPlayer"},
|
|
|
|
{331, "gAITeam"},
|
2007-06-18 19:15:48 +00:00
|
|
|
{340, "zone"},
|
2005-05-14 21:00:43 +00:00
|
|
|
{0, NULL}
|
|
|
|
};
|
|
|
|
|
2008-07-11 15:16:03 +00:00
|
|
|
static gboolean
|
|
|
|
is_armagetronad_packet(tvbuff_t * tvb)
|
2005-05-14 21:00:43 +00:00
|
|
|
{
|
|
|
|
gint offset = 0;
|
|
|
|
|
|
|
|
/* For each message in the frame */
|
2014-06-19 17:18:16 +00:00
|
|
|
while (tvb_length_remaining(tvb, offset) > 2) {
|
2007-06-18 19:15:48 +00:00
|
|
|
gint data_len = tvb_get_ntohs(tvb, offset + 4) * 2;
|
2005-05-14 21:00:43 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* If the descriptor_id is not in the table it's possibly
|
|
|
|
* because the protocol evoluated, losing synchronization
|
|
|
|
* with the table, that's why we don't consider that as
|
|
|
|
* a heuristic
|
|
|
|
*/
|
2013-03-29 00:26:23 +00:00
|
|
|
if (!try_val_to_str(tvb_get_ntohs(tvb, offset), descriptors))
|
2005-05-14 21:00:43 +00:00
|
|
|
/* DescriptorID not found in the table */
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!tvb_bytes_exist(tvb, offset + 6, data_len))
|
|
|
|
/* Advertised length too long */
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
offset += 6 + data_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The packed should end with a 2 bytes ID */
|
2014-06-19 17:18:16 +00:00
|
|
|
return tvb_length_remaining(tvb, offset) == 2;
|
2005-05-14 21:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-07-10 13:42:51 +00:00
|
|
|
add_message_data(tvbuff_t * tvb, gint offset, gint data_len, proto_tree * tree)
|
2005-05-14 21:00:43 +00:00
|
|
|
{
|
2008-07-11 15:16:03 +00:00
|
|
|
gchar *data = NULL;
|
2014-10-04 15:28:35 +00:00
|
|
|
gchar tmp;
|
|
|
|
int i;
|
2005-05-14 21:00:43 +00:00
|
|
|
|
2008-07-11 15:16:03 +00:00
|
|
|
if (!tree)
|
|
|
|
return;
|
2008-07-10 13:42:51 +00:00
|
|
|
|
2013-09-12 20:37:30 +00:00
|
|
|
data = (gchar *)tvb_memcpy(tvb, wmem_alloc(wmem_packet_scope(), data_len + 1), offset, data_len);
|
2008-07-11 15:16:03 +00:00
|
|
|
data[data_len] = '\0';
|
|
|
|
|
|
|
|
for (i = 0; i < data_len; i += 2) {
|
|
|
|
/*
|
|
|
|
* There must be a better way to tell
|
|
|
|
* Wireshark not to stop on null bytes
|
|
|
|
* as the length is known
|
|
|
|
*/
|
|
|
|
if (!data[i])
|
|
|
|
data[i] = ' ';
|
|
|
|
|
|
|
|
if (!data[i+1])
|
|
|
|
data[i+1] = ' ';
|
|
|
|
|
|
|
|
/* Armagetronad swaps unconditionally */
|
|
|
|
tmp = data[i];
|
|
|
|
data[i] = data[i+1];
|
|
|
|
data[i+1] = tmp;
|
2005-07-22 22:45:36 +00:00
|
|
|
}
|
2005-05-14 21:00:43 +00:00
|
|
|
|
2008-07-11 15:16:03 +00:00
|
|
|
proto_tree_add_string(tree, hf_armagetronad_data, tvb, offset,
|
|
|
|
data_len, (gchar *) data);
|
2005-05-14 21:00:43 +00:00
|
|
|
}
|
|
|
|
|
2008-07-11 15:16:03 +00:00
|
|
|
static gint
|
2013-09-12 20:37:30 +00:00
|
|
|
add_message(tvbuff_t * tvb, gint offset, proto_tree * tree, wmem_strbuf_t * info)
|
2005-05-14 21:00:43 +00:00
|
|
|
{
|
2014-10-04 15:28:35 +00:00
|
|
|
guint16 descriptor_id, message_id;
|
|
|
|
gint data_len;
|
|
|
|
proto_item *msg;
|
|
|
|
proto_tree *msg_tree;
|
2005-05-14 21:00:43 +00:00
|
|
|
const gchar *descriptor;
|
|
|
|
|
|
|
|
descriptor_id = tvb_get_ntohs(tvb, offset);
|
|
|
|
message_id = tvb_get_ntohs(tvb, offset + 2);
|
|
|
|
data_len = tvb_get_ntohs(tvb, offset + 4) * 2;
|
|
|
|
|
|
|
|
/* Message subtree */
|
|
|
|
descriptor = val_to_str(descriptor_id, descriptors, "Unknown (%u)");
|
|
|
|
if (descriptor_id == ACK)
|
|
|
|
msg = proto_tree_add_none_format(tree,
|
|
|
|
hf_armagetronad_msg_subtree,
|
|
|
|
tvb, offset, data_len + 6,
|
|
|
|
"ACK %d messages",
|
|
|
|
data_len / 2);
|
|
|
|
else
|
|
|
|
msg = proto_tree_add_none_format(tree,
|
|
|
|
hf_armagetronad_msg_subtree,
|
|
|
|
tvb, offset, data_len + 6,
|
|
|
|
"Message 0x%04x [%s]",
|
|
|
|
message_id, descriptor);
|
|
|
|
|
|
|
|
msg_tree = proto_item_add_subtree(msg, ett_message);
|
|
|
|
|
|
|
|
/* DescriptorID field */
|
|
|
|
proto_tree_add_item(msg_tree, hf_armagetronad_descriptor_id, tvb,
|
2011-09-26 05:52:58 +00:00
|
|
|
offset, 2, ENC_BIG_ENDIAN);
|
2005-05-14 21:00:43 +00:00
|
|
|
if (info)
|
2013-09-12 20:37:30 +00:00
|
|
|
wmem_strbuf_append_printf(info, "%s, ", descriptor);
|
2005-05-14 21:00:43 +00:00
|
|
|
|
|
|
|
/* MessageID field */
|
|
|
|
proto_tree_add_item(msg_tree, hf_armagetronad_message_id, tvb,
|
2011-09-26 05:52:58 +00:00
|
|
|
offset + 2, 2, ENC_BIG_ENDIAN);
|
2005-05-14 21:00:43 +00:00
|
|
|
|
|
|
|
/* DataLen field */
|
|
|
|
proto_tree_add_item(msg_tree, hf_armagetronad_data_len, tvb,
|
2011-09-26 05:52:58 +00:00
|
|
|
offset + 4, 2, ENC_BIG_ENDIAN);
|
2005-05-14 21:00:43 +00:00
|
|
|
|
|
|
|
/* Data field */
|
|
|
|
add_message_data(tvb, offset + 6, data_len, msg_tree);
|
|
|
|
|
|
|
|
return data_len + 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Code to actually dissect the packets */
|
|
|
|
static gint
|
2012-09-10 21:40:21 +00:00
|
|
|
dissect_armagetronad(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void * data _U_)
|
2005-05-14 21:00:43 +00:00
|
|
|
{
|
2014-10-04 15:28:35 +00:00
|
|
|
proto_item *ti;
|
|
|
|
proto_tree *armagetronad_tree;
|
|
|
|
guint16 sender;
|
|
|
|
gint offset = 0;
|
2013-09-12 20:37:30 +00:00
|
|
|
wmem_strbuf_t *info;
|
2014-10-04 15:28:35 +00:00
|
|
|
gsize new_len;
|
2005-05-14 21:00:43 +00:00
|
|
|
|
|
|
|
if (!is_armagetronad_packet(tvb))
|
|
|
|
return 0;
|
|
|
|
|
2013-09-12 20:37:30 +00:00
|
|
|
info = wmem_strbuf_new(wmem_packet_scope(), "");
|
2005-05-14 21:00:43 +00:00
|
|
|
|
2009-08-09 06:26:46 +00:00
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "Armagetronad");
|
2005-05-14 21:00:43 +00:00
|
|
|
|
2011-09-26 05:52:58 +00:00
|
|
|
col_clear(pinfo->cinfo, COL_INFO);
|
2005-05-14 21:00:43 +00:00
|
|
|
|
2011-10-21 02:10:19 +00:00
|
|
|
ti = proto_tree_add_item(tree, proto_armagetronad, tvb, 0, -1, ENC_NA);
|
2005-05-14 21:00:43 +00:00
|
|
|
armagetronad_tree = proto_item_add_subtree(ti, ett_armagetronad);
|
|
|
|
|
|
|
|
/* For each message in the frame */
|
2014-06-19 17:18:16 +00:00
|
|
|
while (tvb_length_remaining(tvb, offset) > 2)
|
2005-05-14 21:00:43 +00:00
|
|
|
offset += add_message(tvb, offset, armagetronad_tree, info);
|
|
|
|
|
|
|
|
/* After the messages, comes the SenderID */
|
|
|
|
sender = tvb_get_ntohs(tvb, offset);
|
|
|
|
proto_tree_add_item(ti, hf_armagetronad_sender_id, tvb, offset, 2,
|
2011-09-26 05:52:58 +00:00
|
|
|
ENC_BIG_ENDIAN);
|
|
|
|
|
2013-09-12 20:37:30 +00:00
|
|
|
new_len = wmem_strbuf_get_len(info) - 2; /* Remove the trailing ", " */
|
2011-09-26 05:52:58 +00:00
|
|
|
if (new_len > 0)
|
2013-09-12 20:37:30 +00:00
|
|
|
wmem_strbuf_truncate(info, new_len);
|
2011-09-26 05:52:58 +00:00
|
|
|
else
|
2013-09-12 20:37:30 +00:00
|
|
|
info = wmem_strbuf_new(wmem_packet_scope(), "No message");
|
2011-09-26 05:52:58 +00:00
|
|
|
|
|
|
|
col_add_fstr(pinfo->cinfo, COL_INFO, "[%s] from 0x%04x",
|
2013-09-12 20:37:30 +00:00
|
|
|
wmem_strbuf_get_str(info), sender);
|
2005-05-14 21:00:43 +00:00
|
|
|
|
|
|
|
return offset + 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
void proto_register_armagetronad(void)
|
|
|
|
{
|
|
|
|
static hf_register_info hf[] = {
|
|
|
|
{&hf_armagetronad_descriptor_id,
|
|
|
|
{"Descriptor", "armagetronad.descriptor_id",
|
|
|
|
FT_UINT16, BASE_DEC, VALS(descriptors), 0x0,
|
|
|
|
"The ID of the descriptor (the command)", HFILL}
|
|
|
|
},
|
|
|
|
{&hf_armagetronad_message_id,
|
|
|
|
{"MessageID", "armagetronad.message_id",
|
|
|
|
FT_UINT16, BASE_HEX, NULL, 0x0,
|
|
|
|
"The ID of the message (to ack it)", HFILL}
|
|
|
|
},
|
|
|
|
{&hf_armagetronad_data_len,
|
|
|
|
{"DataLen", "armagetronad.data_len",
|
|
|
|
FT_UINT16, BASE_DEC, NULL, 0x0,
|
|
|
|
"The length of the data (in shorts)", HFILL}
|
|
|
|
},
|
|
|
|
{&hf_armagetronad_data,
|
|
|
|
{"Data", "armagetronad.data",
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
FT_STRING, BASE_NONE, NULL, 0x0,
|
2005-05-14 21:00:43 +00:00
|
|
|
"The actual data (array of shorts in network order)", HFILL}
|
|
|
|
},
|
|
|
|
{&hf_armagetronad_sender_id,
|
|
|
|
{"SenderID", "armagetronad.sender_id",
|
|
|
|
FT_UINT16, BASE_HEX, NULL, 0x0,
|
|
|
|
"The ID of the sender (0x0000 for the server)", HFILL}
|
|
|
|
},
|
|
|
|
{&hf_armagetronad_msg_subtree,
|
|
|
|
{"Message", "armagetronad.message",
|
From Kovarththanan Rajaratnam via bug 3548:
(1) Trailing/leading spaces are removed from 'name's/'blurb's
(2) Duplicate 'blurb's are replaced with NULL
(3) Empty ("") 'blurb's are replaced with NULL
(4) BASE_NONE, NULL, 0x0 are used for 'display', 'strings' and 'bitmask' fields
for FT_NONE, FT_BYTES, FT_IPv4, FT_IPv6, FT_ABSOLUTE_TIME, FT_RELATIVE_TIME,
FT_PROTOCOL, FT_STRING and FT_STRINGZ field types
(5) Only allow non-zero value for 'display' if 'bitmask' is non-zero
svn path=/trunk/; revision=28770
2009-06-18 21:30:42 +00:00
|
|
|
FT_NONE, BASE_NONE, NULL, 0x0,
|
2005-05-14 21:00:43 +00:00
|
|
|
"A message", HFILL}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_armagetronad,
|
|
|
|
&ett_message
|
|
|
|
};
|
|
|
|
|
|
|
|
proto_armagetronad =
|
|
|
|
proto_register_protocol("The Armagetron Advanced OpenGL Tron clone",
|
|
|
|
"Armagetronad", "armagetronad");
|
|
|
|
|
|
|
|
proto_register_field_array(proto_armagetronad, hf, array_length(hf));
|
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
|
|
|
new_register_dissector("armagetronad", dissect_armagetronad,
|
|
|
|
proto_armagetronad);
|
|
|
|
}
|
|
|
|
|
|
|
|
void proto_reg_handoff_armagetronad(void)
|
|
|
|
{
|
|
|
|
dissector_handle_t armagetronad_handle;
|
|
|
|
|
|
|
|
armagetronad_handle = find_dissector("armagetronad");
|
|
|
|
|
2010-12-20 05:35:29 +00:00
|
|
|
dissector_add_uint("udp.port", UDP_PORT_ARMAGETRONAD, armagetronad_handle);
|
|
|
|
dissector_add_uint("udp.port", UDP_PORT_MASTER, armagetronad_handle);
|
2005-05-14 21:00:43 +00:00
|
|
|
}
|
2014-10-04 15:28:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 8
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: t
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* vi: set shiftwidth=8 tabstop=8 noexpandtab:
|
|
|
|
* :indentSize=8:tabSize=8:noTabs=false:
|
|
|
|
*/
|