2 * Routines for Schweitzer Engineering Laboratories "Real-Time Automation Controller" (RTAC) Serial Line Dissection
3 * By Chris Bontje (cbontje[AT]gmail.com)
6 ************************************************************************************************
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
13 ************************************************************************************************
16 * The RTAC product family (SEL-3530, SEL-2241, SEL-3505) is a Linux-based Automation Controller
17 * product that is capable of interfacing with SEL and 3rd-party equipment using a variety of
18 * standard industrial protocols such as SEL FM, DNP3, Modbus, C37.118, Telegyr 8979 and others.
19 * Each protocol instance (master/client or slave/server) is configured to utilize either Ethernet
20 * or EIA-232/485 serial connectivity with protocol variations for each medium taken into account.
22 * The configuration software for the RTAC platform is named AcSELerator RTAC (SEL-5033) and
23 * is used to set up all communications and user logic for the controller as well as provide
24 * downloading and online debugging facilities. One particularly useful aspect of the online
25 * debugging capabilities is a robust Communication Monitor tool that can show raw data streams
26 * from either serial or Ethernet interfaces. Many similar products have this same capability
27 * but the RTAC software goes a step beyond by providing a "save-as" function to save all captured
28 * data into pcap format for further analysis in Wireshark.
30 * All Ethernet-style capture files will have a packets with a "Linux Cooked Capture" header
31 * including the "source" MAC address of the device responsible for the generation of the message
32 * and the TCP/IP header(s) maintained from the original conversation. The application data from the
33 * message will follow as per a standard Wireshark packet.
35 * Serial-based pcap capture files were originally stored using "User 0" DLT type 147 to specify a
36 * user-defined dissector for pcap data but this format was later modified to specify a custom DLT type
37 * known as LINKTYPE_RTAC_SERIAL (DLT 250). The pcap file data portion contains a standard 12-byte serial
38 * header followed by the application payload data from actual rx/tx activity on the line. Some useful
39 * information can be retrieved from the 12-byte header information, such as conversation time-stamps,
40 * UART function and EIA-232 serial control line states at the time of the message.
42 * This dissector will automatically be used for any newer-style DLT 250 files, and the payload protocol
43 * can be configured via built-in preferences to use whatever standardized industrial protocol is present
44 * on the line for attempted dissection (selfm, mbrtu, dnp3.udp, synphasor). Older pcap files of DLT type 147
45 * can be used by setting the DLT_USER preferences configuration of User 0 (DLT=147) with a 'Header Size'
46 * of '12' and a 'Header Protocol' of 'rtacser'. The payload protocol should be set to use the protocol
47 * dissector for the data that is present on the line (again, selfm, mbrtu, dnp3.udp or synphasor). */
51 #include <epan/packet.h>
52 #include <epan/prefs.h>
53 #include <epan/decode_as.h>
54 #include <wiretap/wtap.h>
56 void proto_register_rtacser(void);
58 /* Initialize the protocol and registered fields */
59 static int proto_rtacser
;
60 static int hf_rtacser_timestamp
;
61 static int hf_rtacser_event_type
;
62 static int hf_rtacser_ctrl_cts
;
63 static int hf_rtacser_ctrl_dcd
;
64 static int hf_rtacser_ctrl_dsr
;
65 static int hf_rtacser_ctrl_rts
;
66 static int hf_rtacser_ctrl_dtr
;
67 static int hf_rtacser_ctrl_ring
;
68 static int hf_rtacser_ctrl_mbok
;
69 static int hf_rtacser_footer
;
71 /* Initialize the subtree pointers */
72 static int ett_rtacser
;
73 static int ett_rtacser_cl
;
75 static dissector_handle_t rtacser_handle
;
76 static dissector_table_t subdissector_table
;
78 #define RTACSER_HEADER_LEN 12
80 /* Bit-masks for EIA-232 serial control lines */
81 #define RTACSER_CTRL_CTS 0x01
82 #define RTACSER_CTRL_DCD 0x02
83 #define RTACSER_CTRL_DSR 0x04
84 #define RTACSER_CTRL_RTS 0x08
85 #define RTACSER_CTRL_DTR 0x10
86 #define RTACSER_CTRL_RING 0x20
87 #define RTACSER_CTRL_MBOK 0x40
90 static const value_string rtacser_eventtype_vals
[] = {
91 { 0x00, "STATUS_CHANGE" },
92 { 0x01, "DATA_TX_START" },
93 { 0x02, "DATA_RX_START" },
94 { 0x03, "DATA_TX_END" },
95 { 0x04, "DATA_RX_END" },
96 { 0x05, "CAPTURE_DATA_LOST" },
97 { 0x06, "CAPTURE_COMPLETE" },
98 { 0x07, "FRAMING_ERROR" },
99 { 0x08, "PARITY_ERROR" },
100 { 0x09, "SERIAL_BREAK_EVENT" },
101 { 0x0A, "SERIAL_OVERFLOW_EVENT" },
106 rtacser_ppi_prompt(packet_info
*pinfo _U_
, char* result
)
108 snprintf(result
, MAX_DECODE_AS_PROMPT_LEN
, "Payload as");
111 /******************************************************************************************************/
112 /* Code to dissect RTAC Serial-Line Protocol packets */
113 /******************************************************************************************************/
115 dissect_rtacser_data(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
117 /* Set up structures needed to add the protocol subtree and manage it */
118 proto_item
*rtacser_item
, *cl_item
;
119 proto_tree
*rtacser_tree
, *cl_tree
;
122 bool cts
, dcd
, dsr
, rts
, dtr
, ring
, mbok
;
123 tvbuff_t
*payload_tvb
;
125 len
= RTACSER_HEADER_LEN
;
127 /* Make entries in Protocol column on summary display */
128 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "RTAC Serial");
129 col_clear(pinfo
->cinfo
, COL_INFO
);
131 rtacser_item
= proto_tree_add_protocol_format(tree
, proto_rtacser
, tvb
, 0, len
, "RTAC Serial Line");
132 rtacser_tree
= proto_item_add_subtree(rtacser_item
, ett_rtacser
);
134 /* Time-stamp is stored as 2 x 32-bit unsigned integers, the left and right-hand side of the decimal point respectively */
135 /* The format mirrors the timeval struct - absolute Epoch time (seconds since 1/1/1970) with an added microsecond component */
136 proto_tree_add_item(rtacser_tree
, hf_rtacser_timestamp
, tvb
, offset
, 8, ENC_TIME_SECS_USECS
|ENC_BIG_ENDIAN
);
139 /* Set INFO column with RTAC Serial Event Type */
140 event_type
= tvb_get_uint8(tvb
, offset
);
141 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "%-21s", val_to_str_const(event_type
, rtacser_eventtype_vals
, "Unknown Type"));
143 /* Add event type to tree */
144 proto_tree_add_item(rtacser_tree
, hf_rtacser_event_type
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
147 /* Retrieve EIA-232 serial control line states */
148 cts
= tvb_get_uint8(tvb
, offset
) & RTACSER_CTRL_CTS
;
149 dcd
= tvb_get_uint8(tvb
, offset
) & RTACSER_CTRL_DCD
;
150 dsr
= tvb_get_uint8(tvb
, offset
) & RTACSER_CTRL_DSR
;
151 rts
= tvb_get_uint8(tvb
, offset
) & RTACSER_CTRL_RTS
;
152 dtr
= tvb_get_uint8(tvb
, offset
) & RTACSER_CTRL_DTR
;
153 ring
= tvb_get_uint8(tvb
, offset
) & RTACSER_CTRL_RING
;
154 mbok
= tvb_get_uint8(tvb
, offset
) & RTACSER_CTRL_MBOK
;
156 cl_tree
= proto_tree_add_subtree(rtacser_tree
, tvb
, offset
, 1, ett_rtacser_cl
, &cl_item
, "Control Lines");
158 /* Add UART Control Line information to INFO column */
159 col_append_str(pinfo
->cinfo
, COL_INFO
, " ( ");
160 (cts
) ? col_append_str(pinfo
->cinfo
, COL_INFO
, "CTS") : col_append_str(pinfo
->cinfo
, COL_INFO
, "/CTS");
161 (dcd
) ? col_append_sep_str(pinfo
->cinfo
, COL_INFO
, NULL
, "DCD") : col_append_sep_str(pinfo
->cinfo
, COL_INFO
, NULL
, "/DCD");
162 (dsr
) ? col_append_sep_str(pinfo
->cinfo
, COL_INFO
, NULL
, "DSR") : col_append_sep_str(pinfo
->cinfo
, COL_INFO
, NULL
, "/DSR");
163 (rts
) ? col_append_sep_str(pinfo
->cinfo
, COL_INFO
, NULL
, "RTS") : col_append_sep_str(pinfo
->cinfo
, COL_INFO
, NULL
, "/RTS");
164 (dtr
) ? col_append_sep_str(pinfo
->cinfo
, COL_INFO
, NULL
, "DTR") : col_append_sep_str(pinfo
->cinfo
, COL_INFO
, NULL
, "/DTR");
165 (ring
) ? col_append_sep_str(pinfo
->cinfo
, COL_INFO
, NULL
, "RING") : col_append_sep_str(pinfo
->cinfo
, COL_INFO
, NULL
, "/RING");
166 (mbok
) ? col_append_sep_str(pinfo
->cinfo
, COL_INFO
, NULL
, "MBOK") : col_append_sep_str(pinfo
->cinfo
, COL_INFO
, NULL
, "/MBOK");
167 col_append_str(pinfo
->cinfo
, COL_INFO
, " )");
169 /* Add UART Control Line information to tree */
170 proto_item_append_text(cl_item
, " (");
171 (cts
) ? proto_item_append_text(cl_item
, "CTS, ") : proto_item_append_text(cl_item
, "/CTS, ");
172 (dcd
) ? proto_item_append_text(cl_item
, "DCD, ") : proto_item_append_text(cl_item
, "/DCD, ");
173 (dsr
) ? proto_item_append_text(cl_item
, "DSR, ") : proto_item_append_text(cl_item
, "/DSR, ");
174 (rts
) ? proto_item_append_text(cl_item
, "RTS, ") : proto_item_append_text(cl_item
, "/RTS, ");
175 (dtr
) ? proto_item_append_text(cl_item
, "DTR, ") : proto_item_append_text(cl_item
, "/DTR, ");
176 (ring
) ? proto_item_append_text(cl_item
, "RING, ") : proto_item_append_text(cl_item
, "/RING, ");
177 (mbok
) ? proto_item_append_text(cl_item
, "MBOK") : proto_item_append_text(cl_item
, "/MBOK");
178 proto_item_append_text(cl_item
, ")");
180 proto_tree_add_item(cl_tree
, hf_rtacser_ctrl_cts
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
181 proto_tree_add_item(cl_tree
, hf_rtacser_ctrl_dcd
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
182 proto_tree_add_item(cl_tree
, hf_rtacser_ctrl_dsr
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
183 proto_tree_add_item(cl_tree
, hf_rtacser_ctrl_rts
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
184 proto_tree_add_item(cl_tree
, hf_rtacser_ctrl_dtr
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
185 proto_tree_add_item(cl_tree
, hf_rtacser_ctrl_ring
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
186 proto_tree_add_item(cl_tree
, hf_rtacser_ctrl_mbok
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
190 proto_tree_add_item(rtacser_tree
, hf_rtacser_footer
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
193 if (tvb_reported_length_remaining(tvb
, offset
) > 0) {
194 payload_tvb
= tvb_new_subset_remaining(tvb
, RTACSER_HEADER_LEN
);
196 if (!dissector_try_payload_with_data(subdissector_table
, payload_tvb
, pinfo
, tree
, true, NULL
)){
197 call_data_dissector(payload_tvb
, pinfo
, tree
);
204 /******************************************************************************************************/
205 /* Dissect RTAC Serial-line protocol payload */
206 /******************************************************************************************************/
208 dissect_rtacser(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data _U_
)
210 int length
= tvb_captured_length(tvb
);
212 /* Check for a RTAC Serial packet. It should be at least 12 bytes */
218 dissect_rtacser_data(tvb
, pinfo
, tree
);
220 return tvb_captured_length(tvb
);
223 /******************************************************************************************************/
224 /* Register the protocol with Wireshark */
225 /******************************************************************************************************/
226 void proto_reg_handoff_rtacser(void);
229 proto_register_rtacser(void)
231 /* RTAC Serial Protocol header fields */
232 static hf_register_info rtacser_hf
[] = {
233 { &hf_rtacser_timestamp
,
234 { "Arrived At Time", "rtacser.timestamp", FT_RELATIVE_TIME
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}},
235 { &hf_rtacser_event_type
,
236 { "Event Type", "rtacser.eventtype", FT_UINT8
, BASE_HEX
, VALS(rtacser_eventtype_vals
), 0x0, NULL
, HFILL
}},
237 { &hf_rtacser_ctrl_cts
,
238 { "CTS", "rtacser.cts", FT_UINT8
, BASE_DEC
, NULL
, RTACSER_CTRL_CTS
, NULL
, HFILL
}},
239 { &hf_rtacser_ctrl_dcd
,
240 { "DCD", "rtacser.dcd", FT_UINT8
, BASE_DEC
, NULL
, RTACSER_CTRL_DCD
, NULL
, HFILL
}},
241 { &hf_rtacser_ctrl_dsr
,
242 { "DSR", "rtacser.dsr", FT_UINT8
, BASE_DEC
, NULL
, RTACSER_CTRL_DSR
, NULL
, HFILL
}},
243 { &hf_rtacser_ctrl_rts
,
244 { "RTS", "rtacser.rts", FT_UINT8
, BASE_DEC
, NULL
, RTACSER_CTRL_RTS
, NULL
, HFILL
}},
245 { &hf_rtacser_ctrl_dtr
,
246 { "DTR", "rtacser.dtr", FT_UINT8
, BASE_DEC
, NULL
, RTACSER_CTRL_DTR
, NULL
, HFILL
}},
247 { &hf_rtacser_ctrl_ring
,
248 { "RING", "rtacser.ring", FT_UINT8
, BASE_DEC
, NULL
, RTACSER_CTRL_RING
, NULL
, HFILL
}},
249 { &hf_rtacser_ctrl_mbok
,
250 { "MBOK", "rtacser.mbok", FT_UINT8
, BASE_DEC
, NULL
, RTACSER_CTRL_MBOK
, NULL
, HFILL
}},
251 { &hf_rtacser_footer
,
252 { "Footer", "rtacser.footer", FT_UINT16
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}},
255 /* Setup protocol subtree array */
256 static int *ett
[] = {
261 module_t
*rtacser_module
;
263 /* Register the protocol name and description */
264 proto_rtacser
= proto_register_protocol("RTAC Serial", "RTAC Serial", "rtacser");
266 /* Registering protocol to be called by another dissector */
267 rtacser_handle
= register_dissector("rtacser", dissect_rtacser
, proto_rtacser
);
269 /* Required function calls to register the header fields and subtrees used */
270 proto_register_field_array(proto_rtacser
, rtacser_hf
, array_length(rtacser_hf
));
271 proto_register_subtree_array(ett
, array_length(ett
));
273 /* Register required preferences for RTAC Serial Payload Protocol */
274 rtacser_module
= prefs_register_protocol_obsolete(proto_rtacser
);
276 /* RTAC Serial Preference - Payload Protocol in use */
277 prefs_register_obsolete_preference(rtacser_module
, "rtacserial_payload_proto");
279 subdissector_table
= register_decode_as_next_proto(proto_rtacser
, "rtacser.data",
280 "RTAC Serial Data Subdissector", rtacser_ppi_prompt
);
283 /******************************************************************************************************/
284 /* If this dissector uses sub-dissector registration add a registration routine.
285 This format is required because a script is used to find these routines and
286 create the code that calls these routines.
288 /******************************************************************************************************/
290 proto_reg_handoff_rtacser(void)
292 dissector_add_uint("wtap_encap", WTAP_ENCAP_RTAC_SERIAL
, rtacser_handle
);
296 * Editor modelines - https://www.wireshark.org/tools/modelines.html
301 * indent-tabs-mode: nil
304 * vi: set shiftwidth=4 tabstop=8 expandtab:
305 * :indentSize=4:tabSize=8:noTabs=true: