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 */
19 #include <epan/packet.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
;
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 */
34 static int hf_framing
;
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
;
43 static int hf_lostcts
;
45 static int hf_overrun
;
49 static int hf_underrun
;
50 static int hf_uarterror
;
51 static int hf_rtxlimit
;
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 */
64 #define REMOTE "Remote"
67 format_flags_string(wmem_allocator_t
*scope
, unsigned char value
, const char *array
[])
74 buf
= wmem_strbuf_new_sized(scope
, MAX_FLAGS_LEN
);
75 for (i
= 0; i
< 8; i
++) {
79 /* there is a string to emit... */
80 wmem_strbuf_append_printf(buf
, "%s%s", sep
,
86 return wmem_strbuf_get_str(buf
);
90 dissect_sita(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
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" };
102 static const char *tx_errors1_str
[] = {"", "", "", "", "", "", "", "" };
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
[] = {
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 */
129 col_set_str(pinfo
->cinfo
, COL_DEF_SRC
, REMOTE
);
132 col_clear(pinfo
->cinfo
, COL_INFO
);
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",
144 ((flags
& SITA_FRAME_DIR
) == SITA_FRAME_DIR_TXED
) ? IOP
: REMOTE
,
145 strlen(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
[] = {
163 static int * const errors2_flags
[] = {
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
);
185 static int * const errors2_flags
[] = {
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" },
236 proto_register_sita(void)
238 static hf_register_info hf
[] = {
240 { "Protocol", "sita.errors.protocol",
241 FT_UINT8
, BASE_HEX
, VALS(tfs_sita_proto
), 0,
242 "Protocol value", HFILL
}
246 { "Direction", "sita.flags.flags",
247 FT_BOOLEAN
, 8, TFS(&tfs_sita_flags
), SITA_FRAME_DIR
,
248 "true 'from Remote', false 'from Local'", HFILL
}
251 { "No Buffers", "sita.flags.droppedframe",
252 FT_BOOLEAN
, 8, TFS(&tfs_sita_error
), SITA_ERROR_NO_BUFFER
,
253 "true if Buffer Failure", HFILL
}
257 { "Framing", "sita.errors.framing",
258 FT_BOOLEAN
, 8, TFS(&tfs_sita_error
), SITA_ERROR_RX_FRAMING
,
259 "true if Framing Error", HFILL
}
262 { "Parity", "sita.errors.parity",
263 FT_BOOLEAN
, 8, TFS(&tfs_sita_error
), SITA_ERROR_RX_PARITY
,
264 "true if Parity Error", HFILL
}
267 { "Collision", "sita.errors.collision",
268 FT_BOOLEAN
, 8, TFS(&tfs_sita_error
), SITA_ERROR_RX_COLLISION
,
269 "true if Collision", HFILL
}
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
}
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
}
282 { "NonAligned", "sita.errors.nonaligned",
283 FT_BOOLEAN
, 8, TFS(&tfs_sita_error
), SITA_ERROR_RX_NONOCTET_ALIGNED
,
284 "true if NonAligned Frame", HFILL
}
287 { "Abort", "sita.errors.abort",
288 FT_BOOLEAN
, 8, TFS(&tfs_sita_received
), SITA_ERROR_RX_ABORT
,
289 "true if Abort Received", HFILL
}
292 { "Carrier", "sita.errors.lostcd",
293 FT_BOOLEAN
, 8, TFS(&tfs_sita_lost
), SITA_ERROR_RX_CD_LOST
,
294 "true if Carrier Lost", HFILL
}
297 { "DPLL", "sita.errors.rxdpll",
298 FT_BOOLEAN
, 8, TFS(&tfs_sita_error
), SITA_ERROR_RX_DPLL
,
299 "true if DPLL Error", HFILL
}
302 { "Overrun", "sita.errors.overrun",
303 FT_BOOLEAN
, 8, TFS(&tfs_sita_error
), SITA_ERROR_RX_OVERRUN
,
304 "true if Overrun Error", HFILL
}
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
}
312 { "CRC", "sita.errors.crc",
313 FT_BOOLEAN
, 8, TFS(&tfs_sita_error
), SITA_ERROR_RX_CRC
,
314 "true if CRC Error", HFILL
}
317 { "Break", "sita.errors.break",
318 FT_BOOLEAN
, 8, TFS(&tfs_sita_received
), SITA_ERROR_RX_BREAK
,
319 "true if Break Received", HFILL
}
323 { "Underrun", "sita.errors.underrun",
324 FT_BOOLEAN
, 8, TFS(&tfs_sita_error
), SITA_ERROR_TX_UNDERRUN
,
325 "true if Tx Underrun", HFILL
}
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
}
333 { "UART", "sita.errors.uarterror",
334 FT_BOOLEAN
, 8, TFS(&tfs_sita_error
), SITA_ERROR_TX_UART_ERROR
,
335 "true if UART Error", HFILL
}
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
}
344 { "DSR", "sita.signals.dsr",
345 FT_BOOLEAN
, 8, TFS(&tfs_on_off
), SITA_SIG_DSR
,
346 "true if Data Set Ready", HFILL
}
349 { "DTR", "sita.signals.dtr",
350 FT_BOOLEAN
, 8, TFS(&tfs_on_off
), SITA_SIG_DTR
,
351 "true if Data Terminal Ready", HFILL
}
354 { "CTS", "sita.signals.cts",
355 FT_BOOLEAN
, 8, TFS(&tfs_on_off
), SITA_SIG_CTS
,
356 "true if Clear To Send", HFILL
}
359 { "RTS", "sita.signals.rts",
360 FT_BOOLEAN
, 8, TFS(&tfs_on_off
), SITA_SIG_RTS
,
361 "true if Request To Send", HFILL
}
364 { "DCD", "sita.signals.dcd",
365 FT_BOOLEAN
, 8, TFS(&tfs_on_off
), SITA_SIG_DCD
,
366 "true if Data Carrier Detect", HFILL
}
369 { "Signals", "sita.signals",
370 FT_UINT8
, BASE_HEX
, NULL
, 0,
375 static int *ett
[] = {
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
);
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
416 * indent-tabs-mode: nil
419 * vi: set shiftwidth=4 tabstop=8 expandtab:
420 * :indentSize=4:tabSize=8:noTabs=true: