Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-sita.c
blob59a4b5f0915b796ecd8186af6a8bb5ebbfecfc19
1 /* packet-sita.c
2 * Routines for SITA protocol dissection (ALC, UTS, Frame Relay, X.25)
3 * with a SITA specific link layer information header
5 * Copyright 2007, Fulko Hew, SITA INC Canada, Inc.
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * SPDX-License-Identifier: GPL-2.0-or-later
14 /* Use indentation = 4 */
16 #include "config.h"
19 #include <epan/packet.h>
20 #include <epan/tfs.h>
21 #include <wsutil/array.h>
22 #include <wiretap/wtap.h>
23 void proto_register_sita(void);
24 void proto_reg_handoff_sita(void);
26 static dissector_table_t sita_dissector_table;
27 static int ett_sita;
28 static int ett_sita_flags;
29 static int ett_sita_signals;
30 static int ett_sita_errors1;
31 static int ett_sita_errors2;
32 static int proto_sita; /* Initialize the protocol and registered fields */
33 static int hf_dir;
34 static int hf_framing;
35 static int hf_parity;
36 static int hf_collision;
37 static int hf_longframe;
38 static int hf_shortframe;
39 static int hf_droppedframe;
40 static int hf_nonaligned;
41 static int hf_abort;
42 static int hf_lostcd;
43 static int hf_lostcts;
44 static int hf_rxdpll;
45 static int hf_overrun;
46 static int hf_length;
47 static int hf_crc;
48 static int hf_break;
49 static int hf_underrun;
50 static int hf_uarterror;
51 static int hf_rtxlimit;
52 static int hf_proto;
53 static int hf_dsr;
54 static int hf_dtr;
55 static int hf_cts;
56 static int hf_rts;
57 static int hf_dcd;
58 static int hf_signals;
60 static dissector_handle_t sita_handle;
62 #define MAX_FLAGS_LEN 64 /* max size of a 'flags' decoded string */
63 #define IOP "Local"
64 #define REMOTE "Remote"
66 static const char *
67 format_flags_string(wmem_allocator_t *scope, unsigned char value, const char *array[])
69 int i;
70 unsigned bpos;
71 wmem_strbuf_t *buf;
72 const char *sep = "";
74 buf = wmem_strbuf_new_sized(scope, MAX_FLAGS_LEN);
75 for (i = 0; i < 8; i++) {
76 bpos = 1 << i;
77 if (value & bpos) {
78 if (array[i][0]) {
79 /* there is a string to emit... */
80 wmem_strbuf_append_printf(buf, "%s%s", sep,
81 array[i]);
82 sep = ", ";
86 return wmem_strbuf_get_str(buf);
89 static int
90 dissect_sita(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
92 proto_item *ti;
93 unsigned char flags, signals, errors1, errors2, proto;
94 const char *errors1_string, *errors2_string, *flags_string;
95 proto_tree *sita_tree = NULL;
96 proto_tree *sita_flags_tree = NULL;
97 proto_tree *sita_errors1_tree = NULL;
98 proto_tree *sita_errors2_tree = NULL;
99 static const char *rx_errors1_str[] = {"Framing", "Parity", "Collision", "Long-frame", "Short-frame", "", "", "" };
100 static const char *rx_errors2_str[] = {"Non-Aligned", "Abort", "CD-lost", "DPLL", "Overrun", "Length", "CRC", "Break" };
101 #if 0
102 static const char *tx_errors1_str[] = {"", "", "", "", "", "", "", "" };
103 #endif
104 static const char *tx_errors2_str[] = {"Underrun", "CTS-lost", "UART", "ReTx-limit", "", "", "", "" };
105 static const char *flags_str[] = {"", "", "", "", "", "", "", "No-buffers" };
108 static int * const signal_flags[] = {
109 &hf_dcd,
110 &hf_rts,
111 &hf_cts,
112 &hf_dtr,
113 &hf_dsr,
114 NULL
117 col_clear(pinfo->cinfo, COL_PROTOCOL); /* erase the protocol */
118 col_clear(pinfo->cinfo, COL_INFO); /* and info columns so that the next decoder can fill them in */
120 flags = pinfo->pseudo_header->sita.sita_flags;
121 signals = pinfo->pseudo_header->sita.sita_signals;
122 errors1 = pinfo->pseudo_header->sita.sita_errors1;
123 errors2 = pinfo->pseudo_header->sita.sita_errors2;
124 proto = pinfo->pseudo_header->sita.sita_proto;
126 if ((flags & SITA_FRAME_DIR) == SITA_FRAME_DIR_TXED) {
127 col_set_str(pinfo->cinfo, COL_DEF_SRC, IOP); /* set the source (direction) column accordingly */
128 } else {
129 col_set_str(pinfo->cinfo, COL_DEF_SRC, REMOTE);
132 col_clear(pinfo->cinfo, COL_INFO);
134 if (tree) {
135 ti = proto_tree_add_protocol_format(tree, proto_sita, tvb, 0, 0, "Link Layer");
136 sita_tree = proto_item_add_subtree(ti, ett_sita);
138 proto_tree_add_uint(sita_tree, hf_proto, tvb, 0, 0, proto);
140 flags_string = format_flags_string(pinfo->pool, flags, flags_str);
141 sita_flags_tree = proto_tree_add_subtree_format(sita_tree, tvb, 0, 0,
142 ett_sita_flags, NULL, "Flags: 0x%02x (From %s)%s%s",
143 flags,
144 ((flags & SITA_FRAME_DIR) == SITA_FRAME_DIR_TXED) ? IOP : REMOTE,
145 strlen(flags_string) ? ", " : "",
146 flags_string);
147 proto_tree_add_boolean(sita_flags_tree, hf_droppedframe, tvb, 0, 0, flags);
148 proto_tree_add_boolean(sita_flags_tree, hf_dir, tvb, 0, 0, flags);
150 proto_tree_add_bitmask_value_with_flags(sita_tree, tvb, 0, hf_signals, ett_sita_signals,
151 signal_flags, signals, BMT_NO_FALSE|BMT_NO_TFS);
153 if ((flags & SITA_FRAME_DIR) == SITA_FRAME_DIR_RXED) {
154 static int * const errors1_flags[] = {
155 &hf_shortframe,
156 &hf_longframe,
157 &hf_collision,
158 &hf_parity,
159 &hf_framing,
160 NULL
163 static int * const errors2_flags[] = {
164 &hf_break,
165 &hf_crc,
166 &hf_length,
167 &hf_overrun,
168 &hf_rxdpll,
169 &hf_lostcd,
170 &hf_abort,
171 &hf_nonaligned,
172 NULL
175 errors1_string = format_flags_string(pinfo->pool, errors1, rx_errors1_str);
176 sita_errors1_tree = proto_tree_add_subtree_format(sita_tree, tvb, 0, 0,
177 ett_sita_errors1, NULL, "Receive Status: 0x%02x %s", errors1, errors1_string);
178 proto_tree_add_bitmask_list_value(sita_errors1_tree, tvb, 0, 0, errors1_flags, errors1);
180 errors2_string = format_flags_string(pinfo->pool, errors2, rx_errors2_str);
181 sita_errors2_tree = proto_tree_add_subtree_format(sita_tree, tvb, 0, 0,
182 ett_sita_errors2, NULL, "Receive Status: 0x%02x %s", errors2, errors2_string);
183 proto_tree_add_bitmask_list_value(sita_errors2_tree, tvb, 0, 0, errors2_flags, errors2);
184 } else {
185 static int * const errors2_flags[] = {
186 &hf_rtxlimit,
187 &hf_uarterror,
188 &hf_lostcts,
189 &hf_underrun,
190 NULL
193 errors2_string = format_flags_string(pinfo->pool, errors2, tx_errors2_str);
194 sita_errors1_tree = proto_tree_add_subtree_format(sita_tree, tvb, 0, 0,
195 ett_sita_errors1, NULL, "Transmit Status: 0x%02x %s", errors2, errors2_string);
196 proto_tree_add_bitmask_list_value(sita_errors1_tree, tvb, 0, 0, errors2_flags, errors2);
200 /* try to find and run an applicable dissector */
201 if (!dissector_try_uint(sita_dissector_table, pinfo->pseudo_header->sita.sita_proto, tvb, pinfo, tree)) {
202 /* if one can't be found... tell them we don't know how to decode this protocol
203 and give them the details then */
204 col_set_str(pinfo->cinfo, COL_PROTOCOL, "UNKNOWN");
205 col_add_fstr(pinfo->cinfo, COL_INFO, "IOP protocol number: %u", pinfo->pseudo_header->sita.sita_proto);
206 call_data_dissector(tvb, pinfo, tree); /* call the generic (hex display) decoder instead */
208 return tvb_captured_length(tvb);
211 static const true_false_string tfs_sita_flags = { "From Remote", "From Local" };
212 static const true_false_string tfs_sita_error = { "Error", "" };
213 static const true_false_string tfs_sita_violation = { "Violation", "" };
214 static const true_false_string tfs_sita_received = { "Received", "" };
215 static const true_false_string tfs_sita_lost = { "Lost", "" };
216 static const true_false_string tfs_sita_exceeded = { "Exceeded", "" };
218 static const value_string tfs_sita_proto[] = {
219 { SITA_PROTO_UNUSED, "Unused" },
220 { SITA_PROTO_BOP_LAPB, "LAPB" },
221 { SITA_PROTO_ETHERNET, "Ethernet" },
222 { SITA_PROTO_ASYNC_INTIO, "Async (Interrupt I/O)" },
223 { SITA_PROTO_ASYNC_BLKIO, "Async (Block I/O)" },
224 { SITA_PROTO_ALC, "IPARS" },
225 { SITA_PROTO_UTS, "UTS" },
226 { SITA_PROTO_PPP_HDLC, "PPP/HDLC" },
227 { SITA_PROTO_SDLC, "SDLC" },
228 { SITA_PROTO_TOKENRING, "Token Ring" },
229 { SITA_PROTO_I2C, "I2C" },
230 { SITA_PROTO_DPM_LINK, "DPM Link" },
231 { SITA_PROTO_BOP_FRL, "Frame Relay" },
232 { 0, NULL }
235 void
236 proto_register_sita(void)
238 static hf_register_info hf[] = {
239 { &hf_proto,
240 { "Protocol", "sita.errors.protocol",
241 FT_UINT8, BASE_HEX, VALS(tfs_sita_proto), 0,
242 "Protocol value", HFILL }
245 { &hf_dir,
246 { "Direction", "sita.flags.flags",
247 FT_BOOLEAN, 8, TFS(&tfs_sita_flags), SITA_FRAME_DIR,
248 "true 'from Remote', false 'from Local'", HFILL }
250 { &hf_droppedframe,
251 { "No Buffers", "sita.flags.droppedframe",
252 FT_BOOLEAN, 8, TFS(&tfs_sita_error), SITA_ERROR_NO_BUFFER,
253 "true if Buffer Failure", HFILL }
256 { &hf_framing,
257 { "Framing", "sita.errors.framing",
258 FT_BOOLEAN, 8, TFS(&tfs_sita_error), SITA_ERROR_RX_FRAMING,
259 "true if Framing Error", HFILL }
261 { &hf_parity,
262 { "Parity", "sita.errors.parity",
263 FT_BOOLEAN, 8, TFS(&tfs_sita_error), SITA_ERROR_RX_PARITY,
264 "true if Parity Error", HFILL }
266 { &hf_collision,
267 { "Collision", "sita.errors.collision",
268 FT_BOOLEAN, 8, TFS(&tfs_sita_error), SITA_ERROR_RX_COLLISION,
269 "true if Collision", HFILL }
271 { &hf_longframe,
272 { "Long Frame", "sita.errors.longframe",
273 FT_BOOLEAN, 8, TFS(&tfs_sita_error), SITA_ERROR_RX_FRAME_LONG,
274 "true if Long Frame Received", HFILL }
276 { &hf_shortframe,
277 { "Short Frame", "sita.errors.shortframe",
278 FT_BOOLEAN, 8, TFS(&tfs_sita_error), SITA_ERROR_RX_FRAME_SHORT,
279 "true if Short Frame", HFILL }
281 { &hf_nonaligned,
282 { "NonAligned", "sita.errors.nonaligned",
283 FT_BOOLEAN, 8, TFS(&tfs_sita_error), SITA_ERROR_RX_NONOCTET_ALIGNED,
284 "true if NonAligned Frame", HFILL }
286 { &hf_abort,
287 { "Abort", "sita.errors.abort",
288 FT_BOOLEAN, 8, TFS(&tfs_sita_received), SITA_ERROR_RX_ABORT,
289 "true if Abort Received", HFILL }
291 { &hf_lostcd,
292 { "Carrier", "sita.errors.lostcd",
293 FT_BOOLEAN, 8, TFS(&tfs_sita_lost), SITA_ERROR_RX_CD_LOST,
294 "true if Carrier Lost", HFILL }
296 { &hf_rxdpll,
297 { "DPLL", "sita.errors.rxdpll",
298 FT_BOOLEAN, 8, TFS(&tfs_sita_error), SITA_ERROR_RX_DPLL,
299 "true if DPLL Error", HFILL }
301 { &hf_overrun,
302 { "Overrun", "sita.errors.overrun",
303 FT_BOOLEAN, 8, TFS(&tfs_sita_error), SITA_ERROR_RX_OVERRUN,
304 "true if Overrun Error", HFILL }
306 { &hf_length,
307 { "Length", "sita.errors.length",
308 FT_BOOLEAN, 8, TFS(&tfs_sita_violation), SITA_ERROR_RX_FRAME_LEN_VIOL,
309 "true if Length Violation", HFILL }
311 { &hf_crc,
312 { "CRC", "sita.errors.crc",
313 FT_BOOLEAN, 8, TFS(&tfs_sita_error), SITA_ERROR_RX_CRC,
314 "true if CRC Error", HFILL }
316 { &hf_break,
317 { "Break", "sita.errors.break",
318 FT_BOOLEAN, 8, TFS(&tfs_sita_received), SITA_ERROR_RX_BREAK,
319 "true if Break Received", HFILL }
322 { &hf_underrun,
323 { "Underrun", "sita.errors.underrun",
324 FT_BOOLEAN, 8, TFS(&tfs_sita_error), SITA_ERROR_TX_UNDERRUN,
325 "true if Tx Underrun", HFILL }
327 { &hf_lostcts,
328 { "Clear To Send", "sita.errors.lostcts",
329 FT_BOOLEAN, 8, TFS(&tfs_sita_lost), SITA_ERROR_TX_CTS_LOST,
330 "true if Clear To Send Lost", HFILL }
332 { &hf_uarterror,
333 { "UART", "sita.errors.uarterror",
334 FT_BOOLEAN, 8, TFS(&tfs_sita_error), SITA_ERROR_TX_UART_ERROR,
335 "true if UART Error", HFILL }
337 { &hf_rtxlimit,
338 { "Retx Limit", "sita.errors.rtxlimit",
339 FT_BOOLEAN, 8, TFS(&tfs_sita_exceeded), SITA_ERROR_TX_RETX_LIMIT,
340 "true if Retransmit Limit reached", HFILL }
343 { &hf_dsr,
344 { "DSR", "sita.signals.dsr",
345 FT_BOOLEAN, 8, TFS(&tfs_on_off), SITA_SIG_DSR,
346 "true if Data Set Ready", HFILL }
348 { &hf_dtr,
349 { "DTR", "sita.signals.dtr",
350 FT_BOOLEAN, 8, TFS(&tfs_on_off), SITA_SIG_DTR,
351 "true if Data Terminal Ready", HFILL }
353 { &hf_cts,
354 { "CTS", "sita.signals.cts",
355 FT_BOOLEAN, 8, TFS(&tfs_on_off), SITA_SIG_CTS,
356 "true if Clear To Send", HFILL }
358 { &hf_rts,
359 { "RTS", "sita.signals.rts",
360 FT_BOOLEAN, 8, TFS(&tfs_on_off), SITA_SIG_RTS,
361 "true if Request To Send", HFILL }
363 { &hf_dcd,
364 { "DCD", "sita.signals.dcd",
365 FT_BOOLEAN, 8, TFS(&tfs_on_off), SITA_SIG_DCD,
366 "true if Data Carrier Detect", HFILL }
368 { &hf_signals,
369 { "Signals", "sita.signals",
370 FT_UINT8, BASE_HEX, NULL, 0,
371 NULL, HFILL }
375 static int *ett[] = {
376 &ett_sita,
377 &ett_sita_flags,
378 &ett_sita_signals,
379 &ett_sita_errors1,
380 &ett_sita_errors2,
383 proto_sita = proto_register_protocol("Societe Internationale de Telecommunications Aeronautiques", "SITA", "sita"); /* name, short name,abbreviation */
384 sita_dissector_table = register_dissector_table("sita.proto", "SITA protocol number", proto_sita, FT_UINT8, BASE_HEX);
385 proto_register_field_array(proto_sita, hf, array_length(hf));
386 proto_register_subtree_array(ett, array_length(ett));
387 sita_handle = register_dissector("sita", dissect_sita, proto_sita);
390 void
391 proto_reg_handoff_sita(void)
393 dissector_handle_t lapb_handle;
394 dissector_handle_t frame_relay_handle;
395 dissector_handle_t uts_handle;
396 dissector_handle_t ipars_handle;
398 lapb_handle = find_dissector("lapb");
399 frame_relay_handle = find_dissector("fr");
400 uts_handle = find_dissector("uts");
401 ipars_handle = find_dissector("ipars");
403 dissector_add_uint("sita.proto", SITA_PROTO_BOP_LAPB, lapb_handle);
404 dissector_add_uint("sita.proto", SITA_PROTO_BOP_FRL, frame_relay_handle);
405 dissector_add_uint("sita.proto", SITA_PROTO_UTS, uts_handle);
406 dissector_add_uint("sita.proto", SITA_PROTO_ALC, ipars_handle);
407 dissector_add_uint("wtap_encap", WTAP_ENCAP_SITA, sita_handle);
411 * Editor modelines - https://www.wireshark.org/tools/modelines.html
413 * Local variables:
414 * c-basic-offset: 4
415 * tab-width: 8
416 * indent-tabs-mode: nil
417 * End:
419 * vi: set shiftwidth=4 tabstop=8 expandtab:
420 * :indentSize=4:tabSize=8:noTabs=true: