2 * Routines for Quake packet dissection
4 * Uwe Girlich <uwe@planetquake.com>
5 * http://www.idsoftware.com/q1source/q1source.zip
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * Copied from packet-tftp.c
13 * SPDX-License-Identifier: GPL-2.0-or-later
18 #include <epan/packet.h>
19 #include <epan/conversation.h>
21 #include <wsutil/array.h>
23 void proto_register_quake(void);
25 static int proto_quake
;
26 static int hf_quake_header_flags
;
27 static int hf_quake_header_flags_data
;
28 static int hf_quake_header_flags_ack
;
29 static int hf_quake_header_flags_no_ack
;
30 static int hf_quake_header_flags_endmsg
;
31 static int hf_quake_header_flags_unreliable
;
32 static int hf_quake_header_flags_control
;
33 static int hf_quake_header_length
;
34 static int hf_quake_header_sequence
;
35 static int hf_quake_control_command
;
37 static int hf_quake_CCREQ_CONNECT_game
;
38 static int hf_quake_CCREQ_CONNECT_version
;
39 static int hf_quake_CCREQ_SERVER_INFO_game
;
40 static int hf_quake_CCREQ_SERVER_INFO_version
;
41 static int hf_quake_CCREQ_PLAYER_INFO_player
;
42 static int hf_quake_CCREQ_RULE_INFO_lastrule
;
44 static int hf_quake_CCREP_ACCEPT_port
;
45 static int hf_quake_CCREP_REJECT_reason
;
46 static int hf_quake_CCREP_SERVER_INFO_address
;
47 static int hf_quake_CCREP_SERVER_INFO_server
;
48 static int hf_quake_CCREP_SERVER_INFO_map
;
49 static int hf_quake_CCREP_SERVER_INFO_num_player
;
50 static int hf_quake_CCREP_SERVER_INFO_max_player
;
51 static int hf_quake_CCREP_PLAYER_INFO_name
;
52 static int hf_quake_CCREP_PLAYER_INFO_colors
;
53 static int hf_quake_CCREP_PLAYER_INFO_colors_shirt
;
54 static int hf_quake_CCREP_PLAYER_INFO_colors_pants
;
55 static int hf_quake_CCREP_PLAYER_INFO_frags
;
56 static int hf_quake_CCREP_PLAYER_INFO_connect_time
;
57 static int hf_quake_CCREP_PLAYER_INFO_address
;
58 static int hf_quake_CCREP_RULE_INFO_rule
;
59 static int hf_quake_CCREP_RULE_INFO_value
;
63 static int ett_quake_control
;
64 static int ett_quake_control_colors
;
65 static int ett_quake_flags
;
67 static dissector_handle_t quake_handle
;
69 /* I took these names directly out of the Q1 source. */
70 #define NET_HEADERSIZE 8
71 #define DEFAULTnet_hostport 26000
73 #define NETFLAG_DATA 0x0001
74 #define NETFLAG_ACK 0x0002
75 #define NETFLAG_NAK 0x0004
76 #define NETFLAG_EOM 0x0008
77 #define NETFLAG_UNRELIABLE 0x0010
78 #define NETFLAG_CTL 0x8000
81 #define CCREQ_CONNECT 0x01
82 #define CCREQ_SERVER_INFO 0x02
83 #define CCREQ_PLAYER_INFO 0x03
84 #define CCREQ_RULE_INFO 0x04
86 #define CCREP_ACCEPT 0x81
87 #define CCREP_REJECT 0x82
88 #define CCREP_SERVER_INFO 0x83
89 #define CCREP_PLAYER_INFO 0x84
90 #define CCREP_RULE_INFO 0x85
92 static const value_string names_control_command
[] = {
93 { CCREQ_CONNECT
, "connect" },
94 { CCREQ_SERVER_INFO
, "server_info" },
95 { CCREQ_PLAYER_INFO
, "player_info" },
96 { CCREQ_RULE_INFO
, "rule_info" },
97 { CCREP_ACCEPT
, "accept" },
98 { CCREP_REJECT
, "reject" },
99 { CCREP_SERVER_INFO
, "server_info" },
100 { CCREP_PLAYER_INFO
, "player_info" },
101 { CCREP_RULE_INFO
, "rule_info" },
108 #define QUAKE_MAXSTRING 0x800
110 static const value_string names_control_direction
[] = {
111 { CCREQ
, "Request" },
117 static const value_string names_colors
[] = {
138 dissect_quake_CCREQ_CONNECT
139 (tvbuff_t
*tvb
, proto_tree
*tree
)
144 proto_tree_add_item_ret_length(tree
, hf_quake_CCREQ_CONNECT_game
,
145 tvb
, offset
, -1, ENC_ASCII
|ENC_NA
, &item_len
);
148 proto_tree_add_item(tree
, hf_quake_CCREQ_CONNECT_version
,
149 tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
154 dissect_quake_CCREQ_SERVER_INFO
155 (tvbuff_t
*tvb
, proto_tree
*tree
)
160 proto_tree_add_item_ret_length(tree
, hf_quake_CCREQ_SERVER_INFO_game
,
161 tvb
, offset
, -1, ENC_ASCII
|ENC_NA
, &item_len
);
163 proto_tree_add_item(tree
, hf_quake_CCREQ_SERVER_INFO_version
,
164 tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
169 dissect_quake_CCREQ_PLAYER_INFO
170 (tvbuff_t
*tvb
, proto_tree
*tree
)
172 proto_tree_add_item(tree
, hf_quake_CCREQ_PLAYER_INFO_player
,
173 tvb
, 0, 1, ENC_LITTLE_ENDIAN
);
178 dissect_quake_CCREQ_RULE_INFO
179 (tvbuff_t
*tvb
, proto_tree
*tree
)
181 proto_tree_add_item(tree
, hf_quake_CCREQ_RULE_INFO_lastrule
,
182 tvb
, 0, -1, ENC_ASCII
);
187 dissect_quake_CCREP_ACCEPT
188 (tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
193 port
= tvb_get_letohl(tvb
, 0);
194 c
= find_or_create_conversation(pinfo
);
195 conversation_set_dissector(c
, quake_handle
);
197 proto_tree_add_uint(tree
, hf_quake_CCREP_ACCEPT_port
,
203 dissect_quake_CCREP_REJECT
204 (tvbuff_t
*tvb
, proto_tree
*tree
)
206 proto_tree_add_item(tree
, hf_quake_CCREP_REJECT_reason
,
207 tvb
, 0, -1, ENC_ASCII
);
212 dissect_quake_CCREP_SERVER_INFO
213 (tvbuff_t
*tvb
, proto_tree
*tree
)
218 proto_tree_add_item_ret_length(tree
,
219 hf_quake_CCREP_SERVER_INFO_address
, tvb
, offset
, -1,
220 ENC_ASCII
|ENC_NA
, &item_len
);
223 proto_tree_add_item_ret_length(tree
,
224 hf_quake_CCREP_SERVER_INFO_server
, tvb
, offset
, -1,
225 ENC_ASCII
|ENC_NA
, &item_len
);
228 proto_tree_add_item_ret_length(tree
,
229 hf_quake_CCREP_SERVER_INFO_map
, tvb
, offset
, -1,
230 ENC_ASCII
|ENC_NA
, &item_len
);
233 proto_tree_add_item(tree
, hf_quake_CCREP_SERVER_INFO_num_player
,
234 tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
236 proto_tree_add_item(tree
, hf_quake_CCREP_SERVER_INFO_max_player
,
237 tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
239 proto_tree_add_item(tree
, hf_quake_CCREQ_SERVER_INFO_version
,
240 tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
245 dissect_quake_CCREP_PLAYER_INFO
246 (tvbuff_t
*tvb
, proto_tree
*tree
)
250 uint32_t color_shirt
;
251 uint32_t color_pants
;
252 proto_item
*colors_item
;
253 proto_tree
*colors_tree
;
256 proto_tree_add_item(tree
, hf_quake_CCREQ_PLAYER_INFO_player
,
257 tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
260 proto_tree_add_item_ret_length(tree
, hf_quake_CCREP_PLAYER_INFO_name
,
261 tvb
, offset
, -1, ENC_ASCII
|ENC_NA
, &item_len
);
264 colors
= tvb_get_letohl(tvb
, offset
+ 0);
265 color_shirt
= (colors
>> 4) & 0x0f;
266 color_pants
= (colors
) & 0x0f;
268 colors_item
= proto_tree_add_uint(tree
,
269 hf_quake_CCREP_PLAYER_INFO_colors
,
270 tvb
, offset
, 4, colors
);
271 colors_tree
= proto_item_add_subtree(colors_item
,
272 ett_quake_control_colors
);
273 proto_tree_add_uint(colors_tree
,
274 hf_quake_CCREP_PLAYER_INFO_colors_shirt
,
275 tvb
, offset
, 1, color_shirt
);
276 proto_tree_add_uint(colors_tree
,
277 hf_quake_CCREP_PLAYER_INFO_colors_pants
,
278 tvb
, offset
, 1, color_pants
);
280 proto_tree_add_item(tree
, hf_quake_CCREP_PLAYER_INFO_frags
,
281 tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
283 proto_tree_add_item(tree
, hf_quake_CCREP_PLAYER_INFO_connect_time
,
284 tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
287 proto_tree_add_item(tree
, hf_quake_CCREP_PLAYER_INFO_address
,
288 tvb
, offset
, -1, ENC_ASCII
);
293 dissect_quake_CCREP_RULE_INFO
294 (tvbuff_t
*tvb
, proto_tree
*tree
)
299 if (tvb_reported_length(tvb
) == 0) return;
301 proto_tree_add_item_ret_length(tree
, hf_quake_CCREP_RULE_INFO_rule
,
302 tvb
, offset
, -1, ENC_ASCII
|ENC_NA
, &item_len
);
305 proto_tree_add_item(tree
, hf_quake_CCREP_RULE_INFO_value
,
306 tvb
, offset
, -1, ENC_ASCII
);
311 dissect_quake_control(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
315 proto_tree
*control_tree
;
318 command
= tvb_get_uint8(tvb
, 0);
319 direction
= (command
& 0x80) ? CCREP
: CCREQ
;
321 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "%s %s",
322 val_to_str(command
,names_control_command
, "%u"),
323 val_to_str(direction
,names_control_direction
,"%u"));
325 control_tree
= proto_tree_add_subtree_format(tree
, tvb
,
326 0, -1, ett_quake_control
, NULL
, "Control %s: %s",
327 val_to_str(direction
, names_control_direction
, "%u"),
328 val_to_str(command
, names_control_command
, "%u"));
329 proto_tree_add_uint(control_tree
, hf_quake_control_command
,
332 next_tvb
= tvb_new_subset_remaining(tvb
, 1);
335 dissect_quake_CCREQ_CONNECT
336 (next_tvb
, control_tree
);
338 case CCREQ_SERVER_INFO
:
339 dissect_quake_CCREQ_SERVER_INFO
340 (next_tvb
, control_tree
);
342 case CCREQ_PLAYER_INFO
:
343 dissect_quake_CCREQ_PLAYER_INFO
344 (next_tvb
, control_tree
);
346 case CCREQ_RULE_INFO
:
347 dissect_quake_CCREQ_RULE_INFO
348 (next_tvb
, control_tree
);
351 dissect_quake_CCREP_ACCEPT
352 (next_tvb
, pinfo
, control_tree
);
355 dissect_quake_CCREP_REJECT
356 (next_tvb
, control_tree
);
358 case CCREP_SERVER_INFO
:
359 dissect_quake_CCREP_SERVER_INFO
360 (next_tvb
, control_tree
);
362 case CCREP_PLAYER_INFO
:
363 dissect_quake_CCREP_PLAYER_INFO
364 (next_tvb
, control_tree
);
366 case CCREP_RULE_INFO
:
367 dissect_quake_CCREP_RULE_INFO
368 (next_tvb
, control_tree
);
371 call_data_dissector(next_tvb
, pinfo
, control_tree
);
378 dissect_quake(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
380 proto_tree
*quake_tree
;
381 proto_item
*quake_item
;
383 proto_item
*flags_item
;
384 proto_tree
*flags_tree
;
385 uint32_t sequence
= 0;
388 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "QUAKE");
389 col_clear(pinfo
->cinfo
, COL_INFO
);
391 flags
= tvb_get_ntohs(tvb
, 2);
393 quake_item
= proto_tree_add_item(tree
, proto_quake
, tvb
, 0, -1, ENC_NA
);
394 quake_tree
= proto_item_add_subtree(quake_item
, ett_quake
);
396 flags_item
= proto_tree_add_item(quake_tree
, hf_quake_header_flags
,
397 tvb
, 2, 2, ENC_BIG_ENDIAN
);
398 flags_tree
= proto_item_add_subtree(flags_item
, ett_quake_flags
);
399 proto_tree_add_item(flags_tree
, hf_quake_header_flags_data
,
400 tvb
, 2, 2, ENC_BIG_ENDIAN
);
401 proto_tree_add_item(flags_tree
, hf_quake_header_flags_ack
,
402 tvb
, 2, 2, ENC_BIG_ENDIAN
);
403 proto_tree_add_item(flags_tree
, hf_quake_header_flags_no_ack
,
404 tvb
, 2, 2, ENC_BIG_ENDIAN
);
405 proto_tree_add_item(flags_tree
, hf_quake_header_flags_endmsg
,
406 tvb
, 2, 2, ENC_BIG_ENDIAN
);
407 proto_tree_add_item(flags_tree
, hf_quake_header_flags_unreliable
,
408 tvb
, 2, 2, ENC_BIG_ENDIAN
);
409 proto_tree_add_item(flags_tree
, hf_quake_header_flags_control
,
410 tvb
, 2, 2, ENC_BIG_ENDIAN
);
412 proto_tree_add_item(quake_tree
, hf_quake_header_length
, tvb
, 0, 2, ENC_BIG_ENDIAN
);
414 if (flags
== NETFLAG_CTL
) {
415 next_tvb
= tvb_new_subset_remaining(tvb
, 4);
416 dissect_quake_control(next_tvb
, pinfo
, quake_tree
);
417 return tvb_captured_length(tvb
);
420 sequence
= tvb_get_ntohl(tvb
, 4);
421 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "seq 0x%x", sequence
);
422 proto_tree_add_uint(quake_tree
, hf_quake_header_sequence
,
423 tvb
, 4, 4, sequence
);
425 next_tvb
= tvb_new_subset_remaining(tvb
, 8);
426 call_data_dissector(next_tvb
, pinfo
, quake_tree
);
427 return tvb_captured_length(tvb
);
431 void proto_reg_handoff_quake(void);
434 proto_register_quake(void)
436 static hf_register_info hf
[] = {
437 { &hf_quake_header_flags
,
438 { "Flags", "quake.header.flags",
439 FT_UINT16
, BASE_HEX
, NULL
, 0x0,
441 { &hf_quake_header_flags_data
,
442 { "Data", "quake.header.flags.data",
443 FT_BOOLEAN
, 16, TFS(&tfs_set_notset
), NETFLAG_DATA
,
445 { &hf_quake_header_flags_ack
,
446 { "Acknowledgment", "quake.header.flags.ack",
447 FT_BOOLEAN
, 16, TFS(&tfs_set_notset
), NETFLAG_ACK
,
449 { &hf_quake_header_flags_no_ack
,
450 { "No Acknowledgment", "quake.header.flags.no_ack",
451 FT_BOOLEAN
, 16, TFS(&tfs_set_notset
), NETFLAG_NAK
,
453 { &hf_quake_header_flags_endmsg
,
454 { "End Of Message", "quake.header.flags.endmsg",
455 FT_BOOLEAN
, 16, TFS(&tfs_set_notset
), NETFLAG_EOM
,
457 { &hf_quake_header_flags_unreliable
,
458 { "Unreliable", "quake.header.flags.unreliable",
459 FT_BOOLEAN
, 16, TFS(&tfs_set_notset
), NETFLAG_UNRELIABLE
,
461 { &hf_quake_header_flags_control
,
462 { "Control", "quake.header.flags.control",
463 FT_BOOLEAN
, 16, TFS(&tfs_set_notset
), NETFLAG_CTL
,
465 { &hf_quake_header_length
,
466 { "Length", "quake.header.length",
467 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
468 "full data length", HFILL
}},
469 { &hf_quake_header_sequence
,
470 { "Sequence", "quake.header.sequence",
471 FT_UINT32
, BASE_HEX
, NULL
, 0x0,
472 "Sequence Number", HFILL
}},
473 { &hf_quake_control_command
,
474 { "Command", "quake.control.command",
475 FT_UINT8
, BASE_HEX
, VALS(names_control_command
), 0x0,
476 "Control Command", HFILL
}},
477 { &hf_quake_CCREQ_CONNECT_game
,
478 { "Game", "quake.control.connect.game",
479 FT_STRINGZ
, BASE_NONE
, NULL
, 0x0,
480 "Game Name", HFILL
}},
481 { &hf_quake_CCREQ_CONNECT_version
,
482 { "Version", "quake.control.connect.version",
483 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
484 "Game Protocol Version Number", HFILL
}},
485 { &hf_quake_CCREQ_SERVER_INFO_game
,
486 { "Game", "quake.control.server_info.game",
487 FT_STRINGZ
, BASE_NONE
, NULL
, 0x0,
488 "Game Name", HFILL
}},
489 { &hf_quake_CCREQ_SERVER_INFO_version
,
490 { "Version", "quake.control.server_info.version",
491 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
492 "Game Protocol Version Number", HFILL
}},
493 { &hf_quake_CCREQ_PLAYER_INFO_player
,
494 { "Player", "quake.control.player_info.player",
495 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
497 { &hf_quake_CCREQ_RULE_INFO_lastrule
,
498 { "Last Rule", "quake.control.rule_info.lastrule",
499 FT_STRINGZ
, BASE_NONE
, NULL
, 0x0,
500 "Last Rule Name", HFILL
}},
501 { &hf_quake_CCREP_ACCEPT_port
,
502 { "Port", "quake.control.accept.port",
503 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
504 "Game Data Port", HFILL
}},
505 { &hf_quake_CCREP_REJECT_reason
,
506 { "Reason", "quake.control.reject.reason",
507 FT_STRINGZ
, BASE_NONE
, NULL
, 0x0,
508 "Reject Reason", HFILL
}},
509 { &hf_quake_CCREP_SERVER_INFO_address
,
510 { "Address", "quake.control.server_info.address",
511 FT_STRINGZ
, BASE_NONE
, NULL
, 0x0,
512 "Server Address", HFILL
}},
513 { &hf_quake_CCREP_SERVER_INFO_server
,
514 { "Server", "quake.control.server_info.server",
515 FT_STRINGZ
, BASE_NONE
, NULL
, 0x0,
516 "Server Name", HFILL
}},
517 { &hf_quake_CCREP_SERVER_INFO_map
,
518 { "Map", "quake.control.server_info.map",
519 FT_STRINGZ
, BASE_NONE
, NULL
, 0x0,
520 "Map Name", HFILL
}},
521 { &hf_quake_CCREP_SERVER_INFO_num_player
,
522 { "Number of Players", "quake.control.server_info.num_player",
523 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
524 "Current Number of Players", HFILL
}},
525 { &hf_quake_CCREP_SERVER_INFO_max_player
,
526 { "Maximal Number of Players", "quake.control.server_info.max_player",
527 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
529 { &hf_quake_CCREP_PLAYER_INFO_name
,
530 { "Name", "quake.control.player_info.name",
531 FT_STRINGZ
, BASE_NONE
, NULL
, 0x0,
532 "Player Name", HFILL
}},
533 { &hf_quake_CCREP_PLAYER_INFO_colors
,
534 { "Colors", "quake.control.player_info.colors",
535 FT_UINT32
, BASE_HEX
, NULL
, 0x0,
536 "Player Colors", HFILL
}},
537 { &hf_quake_CCREP_PLAYER_INFO_colors_shirt
,
538 { "Shirt", "quake.control.player_info.colors.shirt",
539 FT_UINT8
, BASE_DEC
, VALS(names_colors
), 0x0,
540 "Shirt Color", HFILL
}},
541 { &hf_quake_CCREP_PLAYER_INFO_colors_pants
,
542 { "Pants", "quake.control.player_info.colors.pants",
543 FT_UINT8
, BASE_DEC
, VALS(names_colors
), 0x0,
544 "Pants Color", HFILL
}},
545 { &hf_quake_CCREP_PLAYER_INFO_frags
,
546 { "Frags", "quake.control.player_info.frags",
547 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
548 "Player Frags", HFILL
}},
549 { &hf_quake_CCREP_PLAYER_INFO_connect_time
,
550 { "Connect Time", "quake.control.player_info.connect_time",
551 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
552 "Player Connect Time", HFILL
}},
553 { &hf_quake_CCREP_PLAYER_INFO_address
,
554 { "Address", "quake.control.player_info.address",
555 FT_STRINGZ
, BASE_NONE
, NULL
, 0x0,
556 "Player Address", HFILL
}},
557 { &hf_quake_CCREP_RULE_INFO_rule
,
558 { "Rule", "quake.control.rule_info.rule",
559 FT_STRINGZ
, BASE_NONE
, NULL
, 0x0,
560 "Rule Name", HFILL
}},
561 { &hf_quake_CCREP_RULE_INFO_value
,
562 { "Value", "quake.control.rule_info.value",
563 FT_STRINGZ
, BASE_NONE
, NULL
, 0x0,
564 "Rule Value", HFILL
}},
566 static int *ett
[] = {
569 &ett_quake_control_colors
,
573 proto_quake
= proto_register_protocol("Quake Network Protocol", "QUAKE", "quake");
574 proto_register_field_array(proto_quake
, hf
, array_length(hf
));
575 proto_register_subtree_array(ett
, array_length(ett
));
577 quake_handle
= register_dissector("quake", dissect_quake
, proto_quake
);
582 proto_reg_handoff_quake(void)
584 dissector_add_uint_with_preference("udp.port", DEFAULTnet_hostport
, quake_handle
);
588 * Editor modelines - https://www.wireshark.org/tools/modelines.html
593 * indent-tabs-mode: t
596 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
597 * :indentSize=8:tabSize=8:noTabs=false: