1 /* packet-armagetronad.c
2 * Routines for the Armagetronad packet dissection
3 * Copyright 2005, Guillaume Chazarain <guichaz@yahoo.fr>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
14 #include <epan/packet.h>
15 void proto_register_armagetronad(void);
16 void proto_reg_handoff_armagetronad(void);
18 /* Initialize the protocol and registered fields */
19 static int proto_armagetronad
;
20 static int hf_armagetronad_descriptor_id
;
21 static int hf_armagetronad_message_id
;
22 static int hf_armagetronad_data_len
;
23 static int hf_armagetronad_data
;
24 static int hf_armagetronad_sender_id
;
25 static int hf_armagetronad_msg_subtree
;
27 /* Initialize the subtree pointers */
28 static int ett_armagetronad
;
29 static int ett_message
;
31 static dissector_handle_t armagetronad_handle
;
33 #define ARMAGETRONAD_UDP_PORT_RANGE "4533-4534" /* 4533 is not IANA registered, 4534 is */
36 * The ACK packet is so common that we treat it
37 * differently: it has no MessageID
42 * armagetronad-0.2.8.2.1
43 * The numbers and names were retrieved at runtime using the
44 * 'nDescriptor* descriptors[MAXDESCRIPTORS]' array
46 static const value_string descriptors
[] = {
54 { 8, "sn_ConsoleOut"},
59 { 21, "id_req_handler"},
63 { 25, "ready to get objects"},
67 { 40, "password_request"},
68 { 41, "password_answer"},
69 { 50, "small_server"},
71 { 52, "small_request"},
73 { 54, "big_server_master"},
74 { 55, "big_request_master"},
75 { 60, "transfer config"},
77 {201, "ePlayerNetID"},
78 {202, "player_removed_from_game"},
84 {232, "Server controlled vote"},
85 {233, "Server controlled vote expired"},
86 {300, "gNetPlayerWall"},
88 {311, "client_gamestate"},
98 is_armagetronad_packet(tvbuff_t
* tvb
)
102 /* For each message in the frame */
103 while (tvb_captured_length_remaining(tvb
, offset
) > 2) {
104 int data_len
= tvb_get_ntohs(tvb
, offset
+ 4) * 2;
108 * If the descriptor_id is not in the table it's possibly
109 * because the protocol evoluated, losing synchronization
110 * with the table, that's why we don't consider that as
113 if (!try_val_to_str(tvb_get_ntohs(tvb
, offset
), descriptors
))
114 /* DescriptorID not found in the table */
118 if (!tvb_bytes_exist(tvb
, offset
+ 6, data_len
))
119 /* Advertised length too long */
122 offset
+= 6 + data_len
;
125 /* The packed should end with a 2 bytes ID */
126 return tvb_captured_length_remaining(tvb
, offset
) == 2;
130 add_message_data(tvbuff_t
* tvb
, int offset
, int data_len
, proto_tree
* tree
)
136 * XXX - if these are text strings, as the original dissector
137 * treated them as, why the byte swapping? That would make
138 * sense only if they're UCS-2 strings, but the rest of the
139 * code wasn't treating them as such.
141 * Just treat it as a byte array. If that's wrong, submit
142 * a change, with a sample packet, that treats it as whatever
143 * it is, an with a comment that *states* what it is.
145 * XXX - this claimed that "Armagetronad swaps unconditionally",
146 * but I'm not seeing any obvious unconditional byte-swapping
147 * in the code, and if somebody's never seen a big-endian
148 * machine in their life, they may well confuse "convert to
149 * network byte order" with "unconditionally swap". So
150 * if you want to dump this out as a sequence of shorts,
151 * fetch the shorts one at a time using ENC_BIG_ENDIAN.
153 proto_tree_add_item(tree
, hf_armagetronad_data
, tvb
, offset
,
158 add_message(tvbuff_t
* tvb
, int offset
, proto_tree
* tree
, wmem_strbuf_t
* info
)
160 uint16_t descriptor_id
, message_id
;
163 proto_tree
*msg_tree
;
164 const char *descriptor
;
166 descriptor_id
= tvb_get_ntohs(tvb
, offset
);
167 message_id
= tvb_get_ntohs(tvb
, offset
+ 2);
168 data_len
= tvb_get_ntohs(tvb
, offset
+ 4) * 2;
170 /* Message subtree */
171 descriptor
= val_to_str(descriptor_id
, descriptors
, "Unknown (%u)");
172 if (descriptor_id
== ACK
)
173 msg
= proto_tree_add_none_format(tree
,
174 hf_armagetronad_msg_subtree
,
175 tvb
, offset
, data_len
+ 6,
179 msg
= proto_tree_add_none_format(tree
,
180 hf_armagetronad_msg_subtree
,
181 tvb
, offset
, data_len
+ 6,
182 "Message 0x%04x [%s]",
183 message_id
, descriptor
);
185 msg_tree
= proto_item_add_subtree(msg
, ett_message
);
187 /* DescriptorID field */
188 proto_tree_add_item(msg_tree
, hf_armagetronad_descriptor_id
, tvb
,
189 offset
, 2, ENC_BIG_ENDIAN
);
191 wmem_strbuf_append_printf(info
, "%s, ", descriptor
);
193 /* MessageID field */
194 proto_tree_add_item(msg_tree
, hf_armagetronad_message_id
, tvb
,
195 offset
+ 2, 2, ENC_BIG_ENDIAN
);
198 proto_tree_add_item(msg_tree
, hf_armagetronad_data_len
, tvb
,
199 offset
+ 4, 2, ENC_BIG_ENDIAN
);
202 add_message_data(tvb
, offset
+ 6, data_len
, msg_tree
);
207 /* Code to actually dissect the packets */
209 dissect_armagetronad(tvbuff_t
* tvb
, packet_info
* pinfo
, proto_tree
* tree
, void * data _U_
)
212 proto_tree
*armagetronad_tree
;
218 if (!is_armagetronad_packet(tvb
))
221 info
= wmem_strbuf_new(pinfo
->pool
, "");
223 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "Armagetronad");
225 col_clear(pinfo
->cinfo
, COL_INFO
);
227 ti
= proto_tree_add_item(tree
, proto_armagetronad
, tvb
, 0, -1, ENC_NA
);
228 armagetronad_tree
= proto_item_add_subtree(ti
, ett_armagetronad
);
230 /* For each message in the frame */
231 while (tvb_reported_length_remaining(tvb
, offset
) > 2)
232 offset
+= add_message(tvb
, offset
, armagetronad_tree
, info
);
234 /* After the messages, comes the SenderID */
235 sender
= tvb_get_ntohs(tvb
, offset
);
236 proto_tree_add_item(ti
, hf_armagetronad_sender_id
, tvb
, offset
, 2,
239 new_len
= wmem_strbuf_get_len(info
) - 2; /* Remove the trailing ", " */
241 wmem_strbuf_truncate(info
, new_len
);
243 info
= wmem_strbuf_new(pinfo
->pool
, "No message");
245 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "[%s] from 0x%04x",
246 wmem_strbuf_get_str(info
), sender
);
251 void proto_register_armagetronad(void)
253 static hf_register_info hf
[] = {
254 {&hf_armagetronad_descriptor_id
,
255 {"Descriptor", "armagetronad.descriptor_id",
256 FT_UINT16
, BASE_DEC
, VALS(descriptors
), 0x0,
257 "The ID of the descriptor (the command)", HFILL
}
259 {&hf_armagetronad_message_id
,
260 {"MessageID", "armagetronad.message_id",
261 FT_UINT16
, BASE_HEX
, NULL
, 0x0,
262 "The ID of the message (to ack it)", HFILL
}
264 {&hf_armagetronad_data_len
,
265 {"DataLen", "armagetronad.data_len",
266 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
267 "The length of the data (in shorts)", HFILL
}
269 {&hf_armagetronad_data
,
270 {"Data", "armagetronad.data",
271 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
272 "The actual data (array of shorts in network order)", HFILL
}
274 {&hf_armagetronad_sender_id
,
275 {"SenderID", "armagetronad.sender_id",
276 FT_UINT16
, BASE_HEX
, NULL
, 0x0,
277 "The ID of the sender (0x0000 for the server)", HFILL
}
279 {&hf_armagetronad_msg_subtree
,
280 {"Message", "armagetronad.message",
281 FT_NONE
, BASE_NONE
, NULL
, 0x0,
286 static int *ett
[] = {
291 proto_armagetronad
= proto_register_protocol("The Armagetron Advanced OpenGL Tron clone", "Armagetronad", "armagetronad");
293 proto_register_field_array(proto_armagetronad
, hf
, array_length(hf
));
294 proto_register_subtree_array(ett
, array_length(ett
));
295 armagetronad_handle
= register_dissector("armagetronad", dissect_armagetronad
, proto_armagetronad
);
298 void proto_reg_handoff_armagetronad(void)
300 dissector_add_uint_range_with_preference("udp.port", ARMAGETRONAD_UDP_PORT_RANGE
, armagetronad_handle
);
304 * Editor modelines - https://www.wireshark.org/tools/modelines.html
309 * indent-tabs-mode: t
312 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
313 * :indentSize=8:tabSize=8:noTabs=false: