HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / dissectors / packet-sita.c
blob5878c3d06cbb9f5266a162746db6b643e3ab6721
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 * $Id$
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
11 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28 /* Use indentation = 4 */
30 #include "config.h"
32 #include <string.h>
34 #include <glib.h>
36 #include <epan/packet.h>
37 #include <wiretap/wtap.h>
38 #include <epan/wmem/wmem.h>
40 static dissector_table_t sita_dissector_table;
41 static dissector_handle_t data_handle;
42 static gint ett_sita = -1;
43 static gint ett_sita_flags = -1;
44 static gint ett_sita_signals = -1;
45 static gint ett_sita_errors1 = -1;
46 static gint ett_sita_errors2 = -1;
47 static int proto_sita = -1; /* Initialize the protocol and registered fields */
48 static int hf_dir = -1;
49 static int hf_framing = -1;
50 static int hf_parity = -1;
51 static int hf_collision = -1;
52 static int hf_longframe = -1;
53 static int hf_shortframe = -1;
54 static int hf_droppedframe = -1;
55 static int hf_nonaligned = -1;
56 static int hf_abort = -1;
57 static int hf_lostcd = -1;
58 static int hf_lostcts = -1;
59 static int hf_rxdpll = -1;
60 static int hf_overrun = -1;
61 static int hf_length = -1;
62 static int hf_crc = -1;
63 static int hf_break = -1;
64 static int hf_underrun = -1;
65 static int hf_uarterror = -1;
66 static int hf_rtxlimit = -1;
67 static int hf_proto = -1;
68 static int hf_dsr = -1;
69 static int hf_dtr = -1;
70 static int hf_cts = -1;
71 static int hf_rts = -1;
72 static int hf_dcd = -1;
74 #define MAX_FLAGS_LEN 64 /* max size of a 'flags' decoded string */
75 #define IOP "Local"
76 #define REMOTE "Remote"
78 static const gchar *
79 format_flags_string(guchar value, const gchar *array[])
81 int i;
82 guint bpos;
83 wmem_strbuf_t *buf;
84 const char *sep = "";
86 buf = wmem_strbuf_sized_new(wmem_packet_scope(), MAX_FLAGS_LEN, MAX_FLAGS_LEN);
87 for (i = 0; i < 8; i++) {
88 bpos = 1 << i;
89 if (value & bpos) {
90 if (array[i][0]) {
91 /* there is a string to emit... */
92 wmem_strbuf_append_printf(buf, "%s%s", sep,
93 array[i]);
94 sep = ", ";
98 return wmem_strbuf_get_str(buf);
101 static void
102 dissect_sita(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
104 proto_item *ti;
105 guchar flags, signals, errors1, errors2, proto;
106 const gchar *errors1_string, *errors2_string, *signals_string, *flags_string;
107 proto_tree *sita_tree = NULL;
108 proto_tree *sita_flags_tree = NULL;
109 proto_tree *sita_errors1_tree = NULL;
110 proto_tree *sita_errors2_tree = NULL;
111 proto_tree *sita_signals_tree = NULL;
112 static const gchar *rx_errors1_str[] = {"Framing", "Parity", "Collision", "Long-frame", "Short-frame", "", "", "" };
113 static const gchar *rx_errors2_str[] = {"Non-Aligned", "Abort", "CD-lost", "DPLL", "Overrun", "Length", "CRC", "Break" };
114 #if 0
115 static const gchar *tx_errors1_str[] = {"", "", "", "", "", "", "", "" };
116 #endif
117 static const gchar *tx_errors2_str[] = {"Underrun", "CTS-lost", "UART", "ReTx-limit", "", "", "", "" };
118 static const gchar *signals_str[] = {"DSR", "DTR", "CTS", "RTS", "DCD", "", "", "" };
119 static const gchar *flags_str[] = {"", "", "", "", "", "", "", "No-buffers" };
121 col_clear(pinfo->cinfo, COL_PROTOCOL); /* erase the protocol */
122 col_clear(pinfo->cinfo, COL_INFO); /* and info columns so that the next decoder can fill them in */
124 flags = pinfo->pseudo_header->sita.sita_flags;
125 signals = pinfo->pseudo_header->sita.sita_signals;
126 errors1 = pinfo->pseudo_header->sita.sita_errors1;
127 errors2 = pinfo->pseudo_header->sita.sita_errors2;
128 proto = pinfo->pseudo_header->sita.sita_proto;
130 if ((flags & SITA_FRAME_DIR) == SITA_FRAME_DIR_TXED) {
131 col_set_str(pinfo->cinfo, COL_DEF_SRC, IOP); /* set the source (direction) column accordingly */
132 } else {
133 col_set_str(pinfo->cinfo, COL_DEF_SRC, REMOTE);
136 col_set_str(pinfo->cinfo, COL_INFO, "");
138 if (tree) {
139 ti = proto_tree_add_protocol_format(tree, proto_sita, tvb, 0, 0, "Link Layer");
140 sita_tree = proto_item_add_subtree(ti, ett_sita);
142 proto_tree_add_uint(sita_tree, hf_proto, tvb, 0, 0, proto);
144 flags_string = format_flags_string(flags, flags_str);
145 ti = proto_tree_add_text(sita_tree, tvb, 0, 0, "Flags: 0x%02x (From %s)%s%s",
146 flags,
147 ((flags & SITA_FRAME_DIR) == SITA_FRAME_DIR_TXED) ? IOP : REMOTE,
148 strlen(flags_string) ? ", " : "",
149 flags_string);
150 sita_flags_tree = proto_item_add_subtree(ti, ett_sita_flags);
151 proto_tree_add_boolean(sita_flags_tree, hf_droppedframe, tvb, 0, 0, flags);
152 proto_tree_add_boolean(sita_flags_tree, hf_dir, tvb, 0, 0, flags);
154 signals_string = format_flags_string(signals, signals_str);
155 ti = proto_tree_add_text(sita_tree, tvb, 0, 0, "Signals: 0x%02x %s", signals, signals_string);
156 sita_signals_tree = proto_item_add_subtree(ti, ett_sita_signals);
157 proto_tree_add_boolean(sita_signals_tree, hf_dcd, tvb, 0, 0, signals);
158 proto_tree_add_boolean(sita_signals_tree, hf_rts, tvb, 0, 0, signals);
159 proto_tree_add_boolean(sita_signals_tree, hf_cts, tvb, 0, 0, signals);
160 proto_tree_add_boolean(sita_signals_tree, hf_dtr, tvb, 0, 0, signals);
161 proto_tree_add_boolean(sita_signals_tree, hf_dsr, tvb, 0, 0, signals);
163 if ((flags & SITA_FRAME_DIR) == SITA_FRAME_DIR_RXED) {
164 errors1_string = format_flags_string(errors1, rx_errors1_str);
165 ti = proto_tree_add_text(sita_tree, tvb, 0, 0, "Receive Status: 0x%02x %s", errors1, errors1_string);
166 sita_errors1_tree = proto_item_add_subtree(ti, ett_sita_errors1);
167 proto_tree_add_boolean(sita_errors1_tree, hf_shortframe, tvb, 0, 0, errors1);
168 proto_tree_add_boolean(sita_errors1_tree, hf_longframe, tvb, 0, 0, errors1);
169 proto_tree_add_boolean(sita_errors1_tree, hf_collision, tvb, 0, 0, errors1);
170 proto_tree_add_boolean(sita_errors1_tree, hf_parity, tvb, 0, 0, errors1);
171 proto_tree_add_boolean(sita_errors1_tree, hf_framing, tvb, 0, 0, errors1);
173 errors2_string = format_flags_string(errors2, rx_errors2_str);
174 ti = proto_tree_add_text(sita_tree, tvb, 0, 0, "Receive Status: 0x%02x %s", errors2, errors2_string);
175 sita_errors2_tree = proto_item_add_subtree(ti, ett_sita_errors2);
176 proto_tree_add_boolean(sita_errors2_tree, hf_break, tvb, 0, 0, errors2);
177 proto_tree_add_boolean(sita_errors2_tree, hf_crc, tvb, 0, 0, errors2);
178 proto_tree_add_boolean(sita_errors2_tree, hf_length, tvb, 0, 0, errors2);
179 proto_tree_add_boolean(sita_errors2_tree, hf_overrun, tvb, 0, 0, errors2);
180 proto_tree_add_boolean(sita_errors2_tree, hf_rxdpll, tvb, 0, 0, errors2);
181 proto_tree_add_boolean(sita_errors2_tree, hf_lostcd, tvb, 0, 0, errors2);
182 proto_tree_add_boolean(sita_errors2_tree, hf_abort, tvb, 0, 0, errors2);
183 proto_tree_add_boolean(sita_errors2_tree, hf_nonaligned, tvb, 0, 0, errors2);
184 } else {
185 errors2_string = format_flags_string(errors2, tx_errors2_str);
186 ti = proto_tree_add_text(sita_tree, tvb, 0, 0, "Transmit Status: 0x%02x %s", errors2, errors2_string);
187 sita_errors1_tree = proto_item_add_subtree(ti, ett_sita_errors1);
188 proto_tree_add_boolean(sita_errors1_tree, hf_rtxlimit, tvb, 0, 0, errors2);
189 proto_tree_add_boolean(sita_errors1_tree, hf_uarterror, tvb, 0, 0, errors2);
190 proto_tree_add_boolean(sita_errors1_tree, hf_lostcts, tvb, 0, 0, errors2);
191 proto_tree_add_boolean(sita_errors1_tree, hf_underrun, tvb, 0, 0, errors2);
195 /* try to find and run an applicable dissector */
196 if (!dissector_try_uint(sita_dissector_table, pinfo->pseudo_header->sita.sita_proto, tvb, pinfo, tree)) {
197 /* if one can't be found... tell them we don't know how to decode this protocol
198 and give them the details then */
199 col_set_str(pinfo->cinfo, COL_PROTOCOL, "UNKNOWN");
200 col_add_fstr(pinfo->cinfo, COL_INFO, "IOP protocol number: %u", pinfo->pseudo_header->sita.sita_proto);
201 call_dissector(data_handle, tvb, pinfo, tree); /* call the generic (hex display) decoder instead */
205 static const true_false_string tfs_sita_flags = { "From Remote", "From Local" };
206 static const true_false_string tfs_sita_error = { "Error", "" };
207 static const true_false_string tfs_sita_violation = { "Violation", "" };
208 static const true_false_string tfs_sita_received = { "Received", "" };
209 static const true_false_string tfs_sita_lost = { "Lost", "" };
210 static const true_false_string tfs_sita_exceeded = { "Exceeded", "" };
211 static const true_false_string tfs_sita_on_off = { "On", "Off" };
213 static const value_string tfs_sita_proto[] = {
214 { SITA_PROTO_UNUSED, "Unused" },
215 { SITA_PROTO_BOP_LAPB, "LAPB" },
216 { SITA_PROTO_ETHERNET, "Ethernet" },
217 { SITA_PROTO_ASYNC_INTIO, "Async (Interrupt I/O)" },
218 { SITA_PROTO_ASYNC_BLKIO, "Async (Block I/O)" },
219 { SITA_PROTO_ALC, "IPARS" },
220 { SITA_PROTO_UTS, "UTS" },
221 { SITA_PROTO_PPP_HDLC, "PPP/HDLC" },
222 { SITA_PROTO_SDLC, "SDLC" },
223 { SITA_PROTO_TOKENRING, "Token Ring" },
224 { SITA_PROTO_I2C, "I2C" },
225 { SITA_PROTO_DPM_LINK, "DPM Link" },
226 { SITA_PROTO_BOP_FRL, "Frame Relay" },
227 { 0, NULL }
230 void
231 proto_register_sita(void)
233 static hf_register_info hf[] = {
234 { &hf_proto,
235 { "Protocol", "sita.errors.protocol",
236 FT_UINT8, BASE_HEX, VALS(tfs_sita_proto), 0,
237 "Protocol value", HFILL }
240 { &hf_dir,
241 { "Direction", "sita.flags.flags",
242 FT_BOOLEAN, 8, TFS(&tfs_sita_flags), SITA_FRAME_DIR,
243 "TRUE 'from Remote', FALSE 'from Local'", HFILL }
245 { &hf_droppedframe,
246 { "No Buffers", "sita.flags.droppedframe",
247 FT_BOOLEAN, 8, TFS(&tfs_sita_error), SITA_ERROR_NO_BUFFER,
248 "TRUE if Buffer Failure", HFILL }
251 { &hf_framing,
252 { "Framing", "sita.errors.framing",
253 FT_BOOLEAN, 8, TFS(&tfs_sita_error), SITA_ERROR_RX_FRAMING,
254 "TRUE if Framing Error", HFILL }
256 { &hf_parity,
257 { "Parity", "sita.errors.parity",
258 FT_BOOLEAN, 8, TFS(&tfs_sita_error), SITA_ERROR_RX_PARITY,
259 "TRUE if Parity Error", HFILL }
261 { &hf_collision,
262 { "Collision", "sita.errors.collision",
263 FT_BOOLEAN, 8, TFS(&tfs_sita_error), SITA_ERROR_RX_COLLISION,
264 "TRUE if Collision", HFILL }
266 { &hf_longframe,
267 { "Long Frame", "sita.errors.longframe",
268 FT_BOOLEAN, 8, TFS(&tfs_sita_error), SITA_ERROR_RX_FRAME_LONG,
269 "TRUE if Long Frame Received", HFILL }
271 { &hf_shortframe,
272 { "Short Frame", "sita.errors.shortframe",
273 FT_BOOLEAN, 8, TFS(&tfs_sita_error), SITA_ERROR_RX_FRAME_SHORT,
274 "TRUE if Short Frame", HFILL }
276 { &hf_nonaligned,
277 { "NonAligned", "sita.errors.nonaligned",
278 FT_BOOLEAN, 8, TFS(&tfs_sita_error), SITA_ERROR_RX_NONOCTET_ALIGNED,
279 "TRUE if NonAligned Frame", HFILL }
281 { &hf_abort,
282 { "Abort", "sita.errors.abort",
283 FT_BOOLEAN, 8, TFS(&tfs_sita_received), SITA_ERROR_RX_ABORT,
284 "TRUE if Abort Received", HFILL }
286 { &hf_lostcd,
287 { "Carrier", "sita.errors.lostcd",
288 FT_BOOLEAN, 8, TFS(&tfs_sita_lost), SITA_ERROR_RX_CD_LOST,
289 "TRUE if Carrier Lost", HFILL }
291 { &hf_rxdpll,
292 { "DPLL", "sita.errors.rxdpll",
293 FT_BOOLEAN, 8, TFS(&tfs_sita_error), SITA_ERROR_RX_DPLL,
294 "TRUE if DPLL Error", HFILL }
296 { &hf_overrun,
297 { "Overrun", "sita.errors.overrun",
298 FT_BOOLEAN, 8, TFS(&tfs_sita_error), SITA_ERROR_RX_OVERRUN,
299 "TRUE if Overrun Error", HFILL }
301 { &hf_length,
302 { "Length", "sita.errors.length",
303 FT_BOOLEAN, 8, TFS(&tfs_sita_violation), SITA_ERROR_RX_FRAME_LEN_VIOL,
304 "TRUE if Length Violation", HFILL }
306 { &hf_crc,
307 { "CRC", "sita.errors.crc",
308 FT_BOOLEAN, 8, TFS(&tfs_sita_error), SITA_ERROR_RX_CRC,
309 "TRUE if CRC Error", HFILL }
311 { &hf_break,
312 { "Break", "sita.errors.break",
313 FT_BOOLEAN, 8, TFS(&tfs_sita_received), SITA_ERROR_RX_BREAK,
314 "TRUE if Break Received", HFILL }
317 { &hf_underrun,
318 { "Underrun", "sita.errors.underrun",
319 FT_BOOLEAN, 8, TFS(&tfs_sita_error), SITA_ERROR_TX_UNDERRUN,
320 "TRUE if Tx Underrun", HFILL }
322 { &hf_lostcts,
323 { "Clear To Send", "sita.errors.lostcts",
324 FT_BOOLEAN, 8, TFS(&tfs_sita_lost), SITA_ERROR_TX_CTS_LOST,
325 "TRUE if Clear To Send Lost", HFILL }
327 { &hf_uarterror,
328 { "UART", "sita.errors.uarterror",
329 FT_BOOLEAN, 8, TFS(&tfs_sita_error), SITA_ERROR_TX_UART_ERROR,
330 "TRUE if UART Error", HFILL }
332 { &hf_rtxlimit,
333 { "Retx Limit", "sita.errors.rtxlimit",
334 FT_BOOLEAN, 8, TFS(&tfs_sita_exceeded), SITA_ERROR_TX_RETX_LIMIT,
335 "TRUE if Retransmit Limit reached", HFILL }
338 { &hf_dsr,
339 { "DSR", "sita.signals.dsr",
340 FT_BOOLEAN, 8, TFS(&tfs_sita_on_off), SITA_SIG_DSR,
341 "TRUE if Data Set Ready", HFILL }
343 { &hf_dtr,
344 { "DTR", "sita.signals.dtr",
345 FT_BOOLEAN, 8, TFS(&tfs_sita_on_off), SITA_SIG_DTR,
346 "TRUE if Data Terminal Ready", HFILL }
348 { &hf_cts,
349 { "CTS", "sita.signals.cts",
350 FT_BOOLEAN, 8, TFS(&tfs_sita_on_off), SITA_SIG_CTS,
351 "TRUE if Clear To Send", HFILL }
353 { &hf_rts,
354 { "RTS", "sita.signals.rts",
355 FT_BOOLEAN, 8, TFS(&tfs_sita_on_off), SITA_SIG_RTS,
356 "TRUE if Request To Send", HFILL }
358 { &hf_dcd,
359 { "DCD", "sita.signals.dcd",
360 FT_BOOLEAN, 8, TFS(&tfs_sita_on_off), SITA_SIG_DCD,
361 "TRUE if Data Carrier Detect", HFILL }
366 static gint *ett[] = {
367 &ett_sita,
368 &ett_sita_flags,
369 &ett_sita_signals,
370 &ett_sita_errors1,
371 &ett_sita_errors2,
374 proto_sita = proto_register_protocol("Societe Internationale de Telecommunications Aeronautiques", "SITA", "sita"); /* name, short name,abbreviation */
375 sita_dissector_table = register_dissector_table("sita.proto", "SITA protocol number", FT_UINT8, BASE_HEX);
376 proto_register_field_array(proto_sita, hf, array_length(hf));
377 proto_register_subtree_array(ett, array_length(ett));
378 register_dissector("sita", dissect_sita, proto_sita);
381 void
382 proto_reg_handoff_sita(void)
384 dissector_handle_t lapb_handle;
385 dissector_handle_t frame_relay_handle;
386 dissector_handle_t uts_handle;
387 dissector_handle_t ipars_handle;
388 dissector_handle_t sita_handle;
390 lapb_handle = find_dissector("lapb");
391 frame_relay_handle = find_dissector("fr");
392 uts_handle = find_dissector("uts");
393 ipars_handle = find_dissector("ipars");
394 sita_handle = find_dissector("sita");
395 data_handle = find_dissector("data");
397 dissector_add_uint("sita.proto", SITA_PROTO_BOP_LAPB, lapb_handle);
398 dissector_add_uint("sita.proto", SITA_PROTO_BOP_FRL, frame_relay_handle);
399 dissector_add_uint("sita.proto", SITA_PROTO_UTS, uts_handle);
400 dissector_add_uint("sita.proto", SITA_PROTO_ALC, ipars_handle);
401 dissector_add_uint("wtap_encap", WTAP_ENCAP_SITA, sita_handle);