epan/dissectors/pidl/samr/samr.cnf cnf_dissect_lsa_BinaryString => lsarpc_dissect_str...
[wireshark-sm.git] / epan / dissectors / packet-fmtp.c
blobee2475b4b0a963ece02ce91706e551cbad8b6ffe
1 /* packet-fmtp.c
3 * Routines for FMTP version 2 packet dissection.
5 * The specifications of this public protocol can be found on Eurocontrol web site:
6 * http://www.eurocontrol.int/sites/default/files/publication/files/20070614-fmtp-spec-v2.0.pdf
8 * Copyright 2011, Christophe Paletou <c.paletou@free.fr>
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald@wireshark.org>
12 * Copyright 1998 Gerald Combs
14 * SPDX-License-Identifier: GPL-2.0-or-later
17 #include "config.h"
19 #include <epan/packet.h>
20 #include "packet-tcp.h"
22 void proto_register_fmtp(void);
23 void proto_reg_handoff_fmtp(void);
25 static int proto_fmtp;
26 static int hf_fmtp_pdu_version;
27 static int hf_fmtp_pdu_reserved;
28 static int hf_fmtp_pdu_type;
29 static int hf_fmtp_pdu_length;
30 static int ett_fmtp;
32 /* #define TCP_PORT_FMTP 8500 */
33 #define FMTP_HEADER_LEN 5
34 #define FMTP_MAX_DATA_LEN 10240
35 #define FMTP_MAX_LEN FMTP_HEADER_LEN + FMTP_MAX_DATA_LEN
37 #define FMTP_TYP_OPERATIONAL 1
38 #define FMTP_TYP_OPERATOR 2
39 #define FMTP_TYP_IDENTIFICATION 3
40 #define FMTP_TYP_SYSTEM 4
42 #define INFO_STR_SIZE 1024
44 static const value_string packet_type_names[] = {
45 { FMTP_TYP_OPERATIONAL, "Operational message" },
46 { FMTP_TYP_OPERATOR, "Operator message" },
47 { FMTP_TYP_IDENTIFICATION, "Identification message" },
48 { FMTP_TYP_SYSTEM , "System message" },
49 { 0, NULL }
52 static const value_string system_message_names[] = {
53 { 12337, "Startup" }, /* 0x3031 */
54 { 12336, "Shutdown" }, /* 0x3030 */
55 { 12339, "Heartbeat" }, /* 0x3033 */
56 { 0, NULL }
59 static int
60 dissect_fmtp_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
62 uint8_t packet_type;
63 uint16_t packet_len;
64 tvbuff_t *next_tvb;
65 proto_item *ti = NULL;
66 proto_tree *fmtp_tree = NULL;
68 packet_type = tvb_get_uint8(tvb, 4);
69 packet_len = tvb_get_ntohs(tvb, 2);
71 col_set_str(pinfo->cinfo, COL_PROTOCOL, "FMTP");
73 /* Clear out stuff in the info column */
74 col_clear(pinfo->cinfo, COL_INFO);
76 ti = proto_tree_add_item(tree, proto_fmtp, tvb, 0, -1, ENC_NA);
77 proto_item_append_text(ti, ", %s",
78 val_to_str(packet_type, packet_type_names, "Unknown (0x%02x)"));
80 switch (packet_type) {
82 case FMTP_TYP_IDENTIFICATION:
83 proto_item_append_text(ti, " (%s)",
84 tvb_get_string_enc(pinfo->pool, tvb, FMTP_HEADER_LEN, packet_len-FMTP_HEADER_LEN, ENC_ASCII));
85 col_add_fstr(pinfo->cinfo, COL_INFO, "%s (%s)",
86 val_to_str(packet_type, packet_type_names, "Unknown (0x%02x)"),
87 tvb_get_string_enc(pinfo->pool, tvb, FMTP_HEADER_LEN, packet_len-FMTP_HEADER_LEN, ENC_ASCII));
88 break;
90 case FMTP_TYP_SYSTEM:
91 proto_item_append_text(ti, " (%s)",
92 tvb_get_string_enc(pinfo->pool, tvb, FMTP_HEADER_LEN, packet_len-FMTP_HEADER_LEN, ENC_ASCII));
93 col_add_fstr(pinfo->cinfo, COL_INFO, "%s (%s)",
94 val_to_str(packet_type, packet_type_names, "Unknown (0x%02x)"),
95 val_to_str(tvb_get_ntohs(tvb, FMTP_HEADER_LEN), system_message_names, "Unknown (0x%02x)"));
96 break;
98 default:
99 col_add_str(pinfo->cinfo, COL_INFO,
100 val_to_str(packet_type, packet_type_names, "Unknown (0x%02x)"));
101 break;
103 if (tree) { /* we are being asked for details */
104 fmtp_tree = proto_item_add_subtree(ti, ett_fmtp);
105 proto_tree_add_item(fmtp_tree, hf_fmtp_pdu_version, tvb, 0, 1, ENC_BIG_ENDIAN);
106 proto_tree_add_item(fmtp_tree, hf_fmtp_pdu_reserved, tvb, 1, 1, ENC_BIG_ENDIAN);
107 proto_tree_add_item(fmtp_tree, hf_fmtp_pdu_length, tvb, 2, 2, ENC_BIG_ENDIAN);
108 proto_tree_add_item(fmtp_tree, hf_fmtp_pdu_type, tvb, 4, 1, ENC_BIG_ENDIAN);
110 next_tvb = tvb_new_subset_remaining(tvb, FMTP_HEADER_LEN);
111 call_data_dissector(next_tvb, pinfo, fmtp_tree);
114 return tvb_captured_length(tvb);
117 static unsigned
118 get_fmtp_message_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset, void *data _U_)
120 return (unsigned)tvb_get_ntohs(tvb, offset+2);
123 static bool
124 dissect_fmtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
126 uint16_t length;
128 if (tvb_captured_length(tvb) < 5)
129 return false;
131 * Check that packet looks like FMTP before going further
133 /* VERSION must currently be 0x02 */
134 if (tvb_get_uint8(tvb, 0) != 0x02) return false;
135 /* RESERVED must currently be 0x00 */
136 if (tvb_get_uint8(tvb, 1) != 0x00) return false;
137 length = tvb_get_ntohs(tvb, 2);
138 /* LENGTH must currently not exceed 5 (header) + 10240 (data) */
139 if ((length > FMTP_MAX_LEN) || (length < FMTP_HEADER_LEN)) return false;
140 /* TYP must currently be in range 0x01-0x04 */
141 if ((tvb_get_uint8(tvb, 4) < 0x01) || (tvb_get_uint8(tvb, 4) > 0x04))
142 return false;
144 tcp_dissect_pdus(tvb, pinfo, tree, true, FMTP_HEADER_LEN,
145 get_fmtp_message_len, dissect_fmtp_message, data);
146 return true;
149 void
150 proto_register_fmtp(void)
152 static hf_register_info hf[] = {
153 { &hf_fmtp_pdu_version,
154 { "Version", "fmtp.version",
155 FT_UINT8, BASE_DEC,
156 NULL, 0x0,
157 NULL, HFILL }
159 { &hf_fmtp_pdu_reserved,
160 { "Reserved", "fmtp.reserved",
161 FT_UINT8, BASE_DEC,
162 NULL, 0x0,
163 NULL, HFILL }
165 { &hf_fmtp_pdu_length,
166 { "Length", "fmtp.length",
167 FT_UINT16, BASE_DEC,
168 NULL, 0x0,
169 NULL, HFILL }
171 { &hf_fmtp_pdu_type,
172 { "Type", "fmtp.type",
173 FT_UINT8, BASE_DEC,
174 VALS(packet_type_names), 0x0,
175 NULL, HFILL }
179 /* Setup protocol subtree array */
180 static int *ett[] = {
181 &ett_fmtp
184 proto_fmtp = proto_register_protocol("Flight Message Transfer Protocol (FMTP)", "FMTP", "fmtp");
186 proto_register_field_array(proto_fmtp, hf, array_length(hf));
187 proto_register_subtree_array(ett, array_length(ett));
190 void
191 proto_reg_handoff_fmtp(void)
193 /* Register as heuristic dissector for TCP */
194 heur_dissector_add("tcp", dissect_fmtp, "FMTP over TCP", "fmtp_tcp", proto_fmtp, HEURISTIC_ENABLE);
198 * Editor modelines - https://www.wireshark.org/tools/modelines.html
200 * Local variables:
201 * c-basic-offset: 4
202 * tab-width: 8
203 * indent-tabs-mode: nil
204 * End:
206 * vi: set shiftwidth=4 tabstop=8 expandtab:
207 * :indentSize=4:tabSize=8:noTabs=true: