Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-selfm.c
blob4ca180bb8e8edb3a30f22c9da92d260bd843dafb
1 /* packet-selfm.c
2 * Routines for Schweitzer Engineering Laboratories (SEL) Protocols Dissection
3 * By Chris Bontje (cbontje[AT]gmail.com
4 * Copyright 2012-2021,
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 ************************************************************************************************
14 * Schweitzer Engineering Labs ("SEL") manufactures and sells digital protective relay equipment
15 * for use in industrial high-voltage installations. SEL Protocol evolved over time as a
16 * (semi)proprietary method for auto-configuration of connected SEL devices for retrieval of
17 * analog and digital status data. The protocol itself supports embedded binary messages
18 * (which are what this dissector looks for) slip-streamed in the data stream with normal
19 * ASCII text data. A combination of both are used for full auto-configuration of devices,
20 * but a wealth of information can be extracted from the binary messages alone.
22 * 'SEL Protocol' encompasses several message types, including
23 * - Fast Meter
24 * - Fast Operate
25 * - Fast SER
26 * - Fast Message
28 * Documentation on Fast Meter and Fast Message standards available from www.selinc.com in
29 * SEL Application Guides AG95-10_20091109.pdf and AG_200214.pdf
30 ************************************************************************************************
31 * Dissector Notes:
33 * 1) All SEL Protocol messages over TCP are normally tunneled via a Telnet connection. As Telnet
34 * has special handling for the 0xFF character ("IAC"), normally a pair of 0xFF's are inserted
35 * to represent an actual payload byte of 0xFF. A function from the packet-telnet.c dissector has
36 * been borrowed to automatically pre-process any Ethernet-based packet and remove these 'extra'
37 * 0xFF bytes. Wireshark Notes on Telnet 0xFF doubling are discussed here:
38 * https://lists.wireshark.org/archives/wireshark-bugs/201204/msg00198.html
40 * 2) The auto-configuration process for Fast Meter will exchange several "configuration" messages
41 * that describe various data regions (METER, DEMAND, PEAK, etc) that will later have corresponding
42 * "data" messages. This dissector code will currently save and accurately retrieve the 3 sets
43 * of these exchanges:
44 * 0xA5C1, 0xA5D1, "METER" region
45 * 0xA5C2, 0xA5D2, "DEMAND" region
46 * 0xA5C3, 0xA5D3, "PEAK" region
47 * The configuration messages are stored in structs that are managed using the wmem library and
48 * the Wireshark conversation functionality.
51 #define WS_LOG_DOMAIN "packet-selfm"
53 #include "config.h"
54 #include <wireshark.h>
56 #include <epan/packet.h>
57 #include "packet-tcp.h"
58 #include <epan/prefs.h>
59 #include <epan/to_str.h>
60 #include <epan/strutil.h>
61 #include <epan/reassemble.h>
62 #include <epan/expert.h>
63 #include <epan/crc16-tvb.h>
64 #include <epan/proto_data.h>
66 void proto_register_selfm(void);
68 /* Initialize the protocol and registered fields */
69 static int proto_selfm;
70 static int hf_selfm_msgtype;
71 static int hf_selfm_padbyte;
72 static int hf_selfm_checksum;
73 static int hf_selfm_relaydef_len;
74 static int hf_selfm_relaydef_numproto;
75 static int hf_selfm_relaydef_numfm;
76 static int hf_selfm_relaydef_numflags;
77 static int hf_selfm_relaydef_fmcfg_cmd;
78 static int hf_selfm_relaydef_fmdata_cmd;
79 static int hf_selfm_relaydef_statbit;
80 static int hf_selfm_relaydef_statbit_cmd;
81 static int hf_selfm_relaydef_proto;
82 static int hf_selfm_fmconfig_len;
83 static int hf_selfm_fmconfig_numflags;
84 static int hf_selfm_fmconfig_loc_sf;
85 static int hf_selfm_fmconfig_num_sf;
86 static int hf_selfm_fmconfig_num_ai;
87 static int hf_selfm_fmconfig_num_samp;
88 static int hf_selfm_fmconfig_num_dig;
89 static int hf_selfm_fmconfig_num_calc;
90 static int hf_selfm_fmconfig_ofs_ai;
91 static int hf_selfm_fmconfig_ofs_ts;
92 static int hf_selfm_fmconfig_ofs_dig;
93 static int hf_selfm_fmconfig_ai_type;
94 static int hf_selfm_fmconfig_ai_sf_type;
95 static int hf_selfm_fmconfig_ai_sf_ofs;
96 static int hf_selfm_fmconfig_cblk_rot;
97 static int hf_selfm_fmconfig_cblk_vconn;
98 static int hf_selfm_fmconfig_cblk_iconn;
99 static int hf_selfm_fmconfig_cblk_ctype;
100 static int hf_selfm_fmconfig_cblk_deskew_ofs;
101 static int hf_selfm_fmconfig_cblk_rs_ofs;
102 static int hf_selfm_fmconfig_cblk_xs_ofs;
103 static int hf_selfm_fmconfig_cblk_ia_idx;
104 static int hf_selfm_fmconfig_cblk_ib_idx;
105 static int hf_selfm_fmconfig_cblk_ic_idx;
106 static int hf_selfm_fmconfig_cblk_va_idx;
107 static int hf_selfm_fmconfig_cblk_vb_idx;
108 static int hf_selfm_fmconfig_cblk_vc_idx;
109 static int hf_selfm_fmconfig_ai_sf_float;
110 static int hf_selfm_fmdata_len;
111 static int hf_selfm_fmdata_flagbyte;
112 static int hf_selfm_fmdata_dig_b0;
113 static int hf_selfm_fmdata_dig_b1;
114 static int hf_selfm_fmdata_dig_b2;
115 static int hf_selfm_fmdata_dig_b3;
116 static int hf_selfm_fmdata_dig_b4;
117 static int hf_selfm_fmdata_dig_b5;
118 static int hf_selfm_fmdata_dig_b6;
119 static int hf_selfm_fmdata_dig_b7;
120 static int hf_selfm_fmdata_ai_sf_fp;
121 static int hf_selfm_foconfig_len;
122 static int hf_selfm_foconfig_num_brkr;
123 static int hf_selfm_foconfig_num_rb;
124 static int hf_selfm_foconfig_prb_supp;
125 static int hf_selfm_foconfig_reserved;
126 static int hf_selfm_foconfig_brkr_open;
127 static int hf_selfm_foconfig_brkr_close;
128 static int hf_selfm_foconfig_rb_cmd;
129 static int hf_selfm_fastop_len;
130 static int hf_selfm_fastop_rb_code;
131 static int hf_selfm_fastop_br_code;
132 static int hf_selfm_fastop_valid;
133 static int hf_selfm_alt_foconfig_len;
134 static int hf_selfm_alt_foconfig_num_ports;
135 static int hf_selfm_alt_foconfig_num_brkr;
136 static int hf_selfm_alt_foconfig_num_rb;
137 static int hf_selfm_alt_foconfig_funccode;
138 static int hf_selfm_alt_fastop_len;
139 static int hf_selfm_alt_fastop_code;
140 static int hf_selfm_alt_fastop_valid;
142 static int hf_selfm_fastmsg_len;
143 static int hf_selfm_fastmsg_routing_addr;
144 static int hf_selfm_fastmsg_status;
145 static int hf_selfm_fastmsg_funccode;
146 static int hf_selfm_fastmsg_response_code;
147 static int hf_selfm_fastmsg_seq;
148 static int hf_selfm_fastmsg_seq_fir;
149 static int hf_selfm_fastmsg_seq_fin;
150 static int hf_selfm_fastmsg_seq_cnt;
151 static int hf_selfm_fastmsg_resp_num;
152 static int hf_selfm_fastmsg_crc16;
153 static int hf_selfm_fastmsg_def_route_sup;
154 static int hf_selfm_fastmsg_def_rx_stat;
155 static int hf_selfm_fastmsg_def_tx_stat;
156 static int hf_selfm_fastmsg_def_rx_maxfr;
157 static int hf_selfm_fastmsg_def_tx_maxfr;
158 static int hf_selfm_fastmsg_def_rx_num_fc;
159 static int hf_selfm_fastmsg_def_rx_fc;
160 static int hf_selfm_fastmsg_def_tx_num_fc;
161 static int hf_selfm_fastmsg_def_tx_fc;
162 static int hf_selfm_fastmsg_uns_en_fc;
163 static int hf_selfm_fastmsg_uns_en_fc_data;
164 static int hf_selfm_fastmsg_uns_dis_fc;
165 static int hf_selfm_fastmsg_uns_dis_fc_data;
166 static int hf_selfm_fastmsg_baseaddr;
167 static int hf_selfm_fastmsg_numwords;
168 static int hf_selfm_fastmsg_flags;
169 static int hf_selfm_fastmsg_datafmt_resp_numitem;
170 static int hf_selfm_fastmsg_dataitem_qty;
171 static int hf_selfm_fastmsg_dataitem_type;
172 static int hf_selfm_fastmsg_dataitem_uint16;
173 static int hf_selfm_fastmsg_dataitem_int16;
174 static int hf_selfm_fastmsg_dataitem_uint32;
175 static int hf_selfm_fastmsg_dataitem_int32;
176 static int hf_selfm_fastmsg_dataitem_float;
177 static int hf_selfm_fastmsg_devdesc_num_region;
178 static int hf_selfm_fastmsg_devdesc_num_ctrl;
179 static int hf_selfm_fastmsg_unsresp_orig;
180 static int hf_selfm_fastmsg_unsresp_doy;
181 static int hf_selfm_fastmsg_unsresp_year;
182 static int hf_selfm_fastmsg_unsresp_todms;
183 static int hf_selfm_fastmsg_unsresp_num_elmt;
184 static int hf_selfm_fastmsg_unsresp_elmt_idx;
185 static int hf_selfm_fastmsg_unsresp_elmt_ts_ofs;
186 static int hf_selfm_fastmsg_unsresp_elmt_status;
187 static int hf_selfm_fastmsg_unsresp_eor;
188 static int hf_selfm_fastmsg_unsresp_elmt_statword;
189 static int hf_selfm_fastmsg_unswrite_addr1;
190 static int hf_selfm_fastmsg_unswrite_addr2;
191 static int hf_selfm_fastmsg_unswrite_num_reg;
192 static int hf_selfm_fastmsg_unswrite_reg_val;
193 static int hf_selfm_fastmsg_soe_req_orig;
194 static int hf_selfm_fastmsg_soe_resp_numblks;
195 static int hf_selfm_fastmsg_soe_resp_orig;
196 static int hf_selfm_fastmsg_soe_resp_numbits;
197 static int hf_selfm_fastmsg_soe_resp_pad;
198 static int hf_selfm_fastmsg_soe_resp_doy;
199 static int hf_selfm_fastmsg_soe_resp_year;
200 static int hf_selfm_fastmsg_soe_resp_tod;
201 static int hf_selfm_fastmsg_soe_resp_data;
202 /* Generated from convert_proto_tree_add_text.pl */
203 static int hf_selfm_fmconfig_ai_channel;
204 static int hf_selfm_fmdata_ai_value16;
205 static int hf_selfm_fmdata_ai_scale_factor;
206 static int hf_selfm_fmdata_ai_value_float;
207 static int hf_selfm_fmdata_ai_value_double;
208 static int hf_selfm_fmdata_data_type;
209 static int hf_selfm_fmdata_quantity;
210 static int hf_selfm_fmdata_ai_value_string;
211 static int hf_selfm_fastmsg_unsresp_elmt_ts_ofs_decoded;
212 static int hf_selfm_fid;
213 static int hf_selfm_rid;
214 static int hf_selfm_fastmsg_data_region_name;
215 static int hf_selfm_fmdata_timestamp;
216 static int hf_selfm_fmdata_frame_data_format_reference;
217 static int hf_selfm_fastmsg_bit_label_name;
219 /* Initialize the subtree pointers */
220 static int ett_selfm;
221 static int ett_selfm_relaydef;
222 static int ett_selfm_relaydef_fm;
223 static int ett_selfm_relaydef_proto;
224 static int ett_selfm_relaydef_flags;
225 static int ett_selfm_fmconfig;
226 static int ett_selfm_fmconfig_ai;
227 static int ett_selfm_fmconfig_calc;
228 static int ett_selfm_foconfig;
229 static int ett_selfm_foconfig_brkr;
230 static int ett_selfm_foconfig_rb;
231 static int ett_selfm_fastop;
232 static int ett_selfm_fmdata;
233 static int ett_selfm_fmdata_ai;
234 static int ett_selfm_fmdata_dig;
235 static int ett_selfm_fmdata_ai_ch;
236 static int ett_selfm_fmdata_dig_ch;
237 static int ett_selfm_fastmsg;
238 static int ett_selfm_fastmsg_seq;
239 static int ett_selfm_fastmsg_def_fc;
240 static int ett_selfm_fastmsg_datareg;
241 static int ett_selfm_fastmsg_soeblk;
242 static int ett_selfm_fastmsg_tag;
243 static int ett_selfm_fastmsg_element_list;
244 static int ett_selfm_fastmsg_element;
246 /* Expert fields */
247 static expert_field ei_selfm_crc16_incorrect;
249 static dissector_handle_t selfm_handle;
251 #define CMD_FAST_MSG 0xA546
252 #define CMD_CLEAR_STATBIT 0xA5B9
253 #define CMD_RELAY_DEF 0xA5C0
254 #define CMD_FM_CONFIG 0xA5C1
255 #define CMD_DFM_CONFIG 0xA5C2
256 #define CMD_PDFM_CONFIG 0xA5C3
257 #define CMD_FASTOP_RESETDEF 0xA5CD
258 #define CMD_FASTOP_CONFIG 0xA5CE
259 #define CMD_ALT_FASTOP_CONFIG 0xA5CF
260 #define CMD_FM_DATA 0xA5D1
261 #define CMD_DFM_DATA 0xA5D2
262 #define CMD_PDFM_DATA 0xA5D3
263 #define CMD_FASTOP_RB_CTRL 0xA5E0
264 #define CMD_FASTOP_BR_CTRL 0xA5E3
265 #define CMD_ALT_FASTOP_OPEN 0xA5E5
266 #define CMD_ALT_FASTOP_CLOSE 0xA5E6
267 #define CMD_ALT_FASTOP_SET 0xA5E7
268 #define CMD_ALT_FASTOP_CLEAR 0xA5E8
269 #define CMD_ALT_FASTOP_PULSE 0xA5E9
270 #define CMD_FASTOP_RESET 0xA5ED
272 #define FM_CONFIG_SF_LOC_FM 0
273 #define FM_CONFIG_SF_LOC_CFG 1
275 #define FM_CONFIG_ANA_CHNAME_LEN 6
276 #define FM_CONFIG_ANA_CHTYPE_INT16 0x00
277 #define FM_CONFIG_ANA_CHTYPE_FP 0x01
278 #define FM_CONFIG_ANA_CHTYPE_FPD 0x02
279 #define FM_CONFIG_ANA_CHTYPE_TS 0x03
280 #define FM_CONFIG_ANA_CHTYPE_TS_LEN 8
282 #define FM_CONFIG_ANA_SFTYPE_INT16 0x00
283 #define FM_CONFIG_ANA_SFTYPE_FP 0x01
284 #define FM_CONFIG_ANA_SFTYPE_FPD 0x02
285 #define FM_CONFIG_ANA_SFTYPE_TS 0x03
286 #define FM_CONFIG_ANA_SFTYPE_NONE 0xFF
289 /* Fast Message Function Codes, "response" or "ACK" messages are the same as the request, but have the MSB set */
290 #define FAST_MSG_CFG_BLOCK 0x00
291 #define FAST_MSG_EN_UNS_DATA 0x01
292 #define FAST_MSG_DIS_UNS_DATA 0x02
293 #define FAST_MSG_PING 0x05
294 #define FAST_MSG_READ_REQ 0x10
295 #define FAST_MSG_GEN_UNS_DATA 0x12
296 #define FAST_MSG_SOE_STATE_REQ 0x16
297 #define FAST_MSG_UNS_RESP 0x18
298 #define FAST_MSG_UNS_WRITE 0x20
299 #define FAST_MSG_UNS_WRITE_REQ 0x21
300 #define FAST_MSG_DEVDESC_REQ 0x30
301 #define FAST_MSG_DATAFMT_REQ 0x31
302 #define FAST_MSG_UNS_DATAFMT_RESP 0x32
303 #define FAST_MSG_BITLABEL_REQ 0x33
304 #define FAST_MSG_MGMT_REQ 0x40
305 #define FAST_MSG_CFG_BLOCK_RESP 0x80
306 #define FAST_MSG_EN_UNS_DATA_ACK 0x81
307 #define FAST_MSG_DIS_UNS_DATA_ACK 0x82
308 #define FAST_MSG_PING_ACK 0x85
309 #define FAST_MSG_READ_RESP 0x90
310 #define FAST_MSG_SOE_STATE_RESP 0x96
311 #define FAST_MSG_UNS_RESP_ACK 0x98
312 #define FAST_MSG_DEVDESC_RESP 0xB0
313 #define FAST_MSG_DATAFMT_RESP 0xB1
314 #define FAST_MSG_BITLABEL_RESP 0xB3
317 /* Fast Message Sequence Byte Masks */
318 #define FAST_MSG_SEQ_FIR 0x80
319 #define FAST_MSG_SEQ_FIN 0x40
320 #define FAST_MSG_SEQ_CNT 0x3f
322 /* Fast Message Tag Data Types */
323 #define FAST_MSG_TAGTYPE_CHAR8 0x0011 /* 1 x 8-bit character per item */
324 #define FAST_MSG_TAGTYPE_CHAR16 0x0012 /* 2 x 8-bit characters per item */
325 #define FAST_MSG_TAGTYPE_DIGWORD8_BL 0x0021 /* 8-bit binary item, with labels */
326 #define FAST_MSG_TAGTYPE_DIGWORD8 0x0022 /* 8-bit binary item, without labels */
327 #define FAST_MSG_TAGTYPE_DIGWORD16_BL 0x0023 /* 16-bit binary item, with labels */
328 #define FAST_MSG_TAGTYPE_DIGWORD16 0x0024 /* 16-bit binary item, without labels */
329 #define FAST_MSG_TAGTYPE_INT16 0x0031 /* 16-bit signed integer */
330 #define FAST_MSG_TAGTYPE_UINT16 0x0032 /* 16-bit unsigned integer */
331 #define FAST_MSG_TAGTYPE_INT32 0x0033 /* 32-bit signed integer */
332 #define FAST_MSG_TAGTYPE_UINT32 0x0034 /* 32-bit unsigned integer */
333 #define FAST_MSG_TAGTYPE_FLOAT 0x0041 /* 32-bit floating point */
336 /* Globals for SEL Protocol Preferences */
337 static bool selfm_desegment = true;
338 static bool selfm_telnet_clean = true;
339 static bool selfm_crc16; /* Default CRC16 validation to false */
340 static const char *selfm_ser_list;
342 /***************************************************************************************/
343 /* Fast Meter Message structs */
344 /***************************************************************************************/
345 /* Holds Configuration Information required to decode a Fast Meter analog value */
346 typedef struct {
347 char name[FM_CONFIG_ANA_CHNAME_LEN+1]; /* Name of Analog Channel, 6 char + a null */
348 uint8_t type; /* Analog Channel Type, Int, FP, etc */
349 uint8_t sf_type; /* Analog Scale Factor Type, none, etc */
350 uint16_t sf_offset; /* Analog Scale Factor Offset */
351 float sf_fp; /* Scale factor, if present in Cfg message */
352 } fm_analog_info;
355 /* Holds Information from a single "Fast Meter Configuration" frame. Required to dissect subsequent "Data" frames. */
356 typedef struct {
357 uint32_t fnum; /* frame number */
358 uint16_t cfg_cmd; /* holds ID of config command, ie: 0xa5c1 */
359 uint8_t num_flags; /* Number of Flag Bytes */
360 uint8_t sf_loc; /* Scale Factor Location */
361 uint8_t sf_num; /* Number of Scale Factors */
362 uint8_t num_ai; /* Number of Analog Inputs */
363 uint8_t num_ai_samples; /* Number samples per Analog Input */
364 uint16_t offset_ai; /* Start Offset of Analog Inputs */
365 uint8_t num_dig; /* Number of Digital Input Blocks */
366 uint16_t offset_dig; /* Start Offset of Digital Inputs */
367 uint16_t offset_ts; /* Start Offset of Time Stamp */
368 uint8_t num_calc; /* Number of Calculations */
369 fm_analog_info *analogs; /* Array of fm_analog_infos */
370 } fm_config_frame;
372 /**************************************************************************************/
373 /* Fast Message Data Item struct */
374 /**************************************************************************************/
375 /* Holds Configuration Information required to decode a Fast Message Data Item */
376 /* Each data region format is returned as a sequential list of tags, w/o reference to */
377 /* an absolute address. The format information will consist of a name, a data type */
378 /* and a quantity of values contained within the data item. We will retrieve this */
379 /* format information later while attempting to dissect Read Response frames */
380 typedef struct {
381 uint32_t fnum; /* frame number */
382 uint32_t base_address; /* Base address of Data Item Region */
383 uint8_t index_pos; /* Index Offset Position within data format message (1-16) */
384 char name[10+1]; /* Name of Data Item, 10 chars, null-terminated */
385 uint16_t quantity; /* Quantity of values within Data Item */
386 uint16_t data_type; /* Data Item Type, Char, Int, FP, etc */
387 } fastmsg_dataitem;
389 /**************************************************************************************/
390 /* Fast Message Data Region struct */
391 /**************************************************************************************/
392 /* Holds Configuration Information required to decode a Fast Message Data Region */
393 /* Each data region format is returned as a sequential list of tags, w/o reference to */
394 typedef struct {
395 char name[10+1]; /* Name of Data Region, 10 chars, null-terminated */
396 } fastmsg_dataregion;
398 /**************************************************************************************/
399 /* Fast Unsolicited SER Index Lookup */
400 /**************************************************************************************/
401 /* Holds user-configurable naming information for Unsolicited Fast SER word bits */
402 /* that will later be present in an 0xA546 msg with only an index position reference */
403 typedef struct {
404 char *name; /* Name of Word Bit, 8 chars, null-terminated */
405 } fastser_uns_wordbit;
408 /**************************************************************************************/
409 /* Fast Message Conversation struct */
410 /**************************************************************************************/
411 typedef struct {
412 wmem_list_t *fm_config_frames; /* List contains a fm_config_data struct for each Fast Meter configuration frame */
413 wmem_list_t *fastmsg_dataitems; /* List contains a fastmsg_dataitem struct for each Fast Message Data Item */
414 wmem_tree_t *fastmsg_dataregions; /* Tree contains a fastmsg_dataregion struct for each Fast Message Data Region */
415 wmem_tree_t *fastser_uns_wordbits; /* Tree contains a fastser_uns_wordbit struct for each comma-separated entry in the 'SER List' User Preference */
416 } fm_conversation;
419 static const value_string selfm_msgtype_vals[] = {
420 { CMD_FAST_MSG, "Fast Message Block" }, /* 0xA546 */
421 { CMD_CLEAR_STATBIT, "Clear Status Bits Command" }, /* 0xA5B9 */
422 { CMD_RELAY_DEF, "Relay Definition Block" }, /* 0xA5C0 */
423 { CMD_FM_CONFIG, "Fast Meter Configuration Block" }, /* 0xA5C1 */
424 { CMD_DFM_CONFIG, "Demand Fast Meter Configuration Block" }, /* 0xA5C2 */
425 { CMD_PDFM_CONFIG, "Peak Demand Fast Meter Configuration Block" }, /* 0xA5C3 */
426 { CMD_FASTOP_RESETDEF, "Fast Operate Reset Definition" }, /* 0xA5CD */
427 { CMD_FASTOP_CONFIG, "Fast Operate Configuration" }, /* 0xA5CE */
428 { CMD_ALT_FASTOP_CONFIG, "Alternate Fast Operate Configuration" }, /* 0xA5CF */
429 { CMD_FM_DATA, "Fast Meter Data Block" }, /* 0xA5D1 */
430 { CMD_DFM_DATA, "Demand Fast Meter Data Block" }, /* 0xA5D2 */
431 { CMD_PDFM_DATA, "Peak Demand Fast Meter Data Block" }, /* 0xA5D3 */
432 { CMD_FASTOP_RB_CTRL, "Fast Operate Remote Bit Control" }, /* 0xA5E0 */
433 { CMD_FASTOP_BR_CTRL, "Fast Operate Breaker Bit Control" }, /* 0xA5E3 */
434 { CMD_ALT_FASTOP_OPEN, "Alternate Fast Operate Open Breaker Control" }, /* 0xA5E5 */
435 { CMD_ALT_FASTOP_CLOSE, "Alternate Fast Operate Close Breaker Control" }, /* 0xA5E6 */
436 { CMD_ALT_FASTOP_SET, "Alternate Fast Operate Set Remote Bit Control" }, /* 0xA5E7 */
437 { CMD_ALT_FASTOP_CLEAR, "Alternate Fast Operate Clear Remote Bit Control" }, /* 0xA5E8 */
438 { CMD_ALT_FASTOP_PULSE, "Alternate Fast Operate Pulse Remote Bit Control" }, /* 0xA5E9 */
439 { CMD_FASTOP_RESET, "Fast Operate Reset" }, /* 0xA5ED */
440 { 0, NULL }
442 static value_string_ext selfm_msgtype_vals_ext = VALUE_STRING_EXT_INIT(selfm_msgtype_vals);
444 static const value_string selfm_relaydef_proto_vals[] = {
445 { 0x0000, "SEL Fast Meter" },
446 { 0x0001, "SEL Limited Multidrop (LMD)" },
447 { 0x0002, "Modbus" },
448 { 0x0003, "SY/MAX" },
449 { 0x0004, "SEL Relay-to-Relay" },
450 { 0x0005, "DNP 3.0" },
451 { 0x0006, "SEL Mirrored Bits" },
452 { 0x0007, "IEEE 37.118 Synchrophasors" },
453 { 0x0008, "IEC 61850" },
454 { 0x0100, "SEL Fast Meter w/ Fast Operate" },
455 { 0x0101, "SEL Limited Multidrop (LMD) w/ Fast Operate" },
456 { 0x0200, "SEL Fast Meter w/ Fast Message" },
457 { 0x0300, "SEL Fast Meter w/ Fast Operate and Fast Message" },
458 { 0x0301, "SEL Limited Multidrop (LMD) w/ Fast Operate and Fast Message" },
459 { 0, NULL }
461 static value_string_ext selfm_relaydef_proto_vals_ext = VALUE_STRING_EXT_INIT(selfm_relaydef_proto_vals);
463 static const value_string selfm_fmconfig_ai_chtype_vals[] = {
464 { FM_CONFIG_ANA_CHTYPE_INT16, "16-Bit Integer" },
465 { FM_CONFIG_ANA_CHTYPE_FP, "IEEE Floating Point" },
466 { FM_CONFIG_ANA_CHTYPE_FPD, "IEEE Floating Point (Double)" },
467 { FM_CONFIG_ANA_CHTYPE_TS, "8-byte Time Stamp" },
468 { 0, NULL }
471 static const value_string selfm_fmconfig_ai_sftype_vals[] = {
472 { FM_CONFIG_ANA_SFTYPE_INT16, "16-Bit Integer" },
473 { FM_CONFIG_ANA_SFTYPE_FP, "IEEE Floating Point" },
474 { FM_CONFIG_ANA_SFTYPE_FPD, "IEEE Floating Point (Double)" },
475 { FM_CONFIG_ANA_SFTYPE_TS, "8-byte Time Stamp" },
476 { FM_CONFIG_ANA_SFTYPE_NONE, "None" },
477 { 0, NULL }
480 static const value_string selfm_fmconfig_sfloc_vals[] = {
481 { FM_CONFIG_SF_LOC_FM, "In Fast Meter Message" },
482 { FM_CONFIG_SF_LOC_CFG, "In Configuration Message" },
483 { 0, NULL }
486 /* Depending on number of analog samples present in Fast Meter Messages, identification of data will change */
487 static const value_string selfm_fmconfig_numsamples1_vals[] = {
488 { 1, "Magnitudes Only" },
489 { 0, NULL }
492 static const value_string selfm_fmconfig_numsamples2_vals[] = {
493 { 1, "Imaginary Components" },
494 { 2, "Real Components" },
495 { 0, NULL }
498 static const value_string selfm_fmconfig_numsamples4_vals[] = {
499 { 1, "1st Quarter Cycle Data" },
500 { 2, "2nd Quarter Cycle Data" },
501 { 3, "5th Quarter-Cycle Data" },
502 { 4, "6th Quarter-Cycle Data" },
503 { 0, NULL }
506 /* Calculation Block lookup values */
507 static const value_string selfm_fmconfig_cblk_rot_vals[] = {
508 { 0x00, "ABC Rotation" },
509 { 0x01, "ACB Rotation" },
510 { 0, NULL }
513 static const value_string selfm_fmconfig_cblk_vconn_vals[] = {
514 { 0x00, "Y-Connected" },
515 { 0x01, "Delta-Connected (in seq. Vab, Vbc, Vca)" },
516 { 0x02, "Delta-Connected (in seq. Vac, Vba, Vcb)" },
517 { 0, NULL }
520 static const value_string selfm_fmconfig_cblk_iconn_vals[] = {
521 { 0x00, "Y-Connected" },
522 { 0x01, "Delta-Connected (in seq. Iab, Ibc, Ica)" },
523 { 0x02, "Delta-Connected (in seq. Iac, Iba, Icb)" },
524 { 0, NULL }
527 static const value_string selfm_fmconfig_cblk_ctype_vals[] = {
528 { 0, "Standard Power Calculations" },
529 { 1, "2-1/2 Element Delta Power Calculation" },
530 { 2, "Voltages-Only" },
531 { 3, "Currents-Only" },
532 { 4, "Single-Phase Ia and Va Only" },
533 { 5, "Standard Power Calcs with 2 sets of Currents" },
534 { 6, "2-1/2 Element Delta Power Calcs with 2 sets of Currents" },
535 { 0, NULL }
538 /* Fast Operate Remote Bit 'Pulse Supported' Lookup */
539 static const value_string selfm_foconfig_prb_supp_vals[] = {
540 { 0x00, "No" },
541 { 0x01, "Yes" },
542 { 0, NULL }
545 /* SER Status Value Lookup */
546 static const value_string selfm_ser_status_vals[] = {
547 { 0x00, "Deasserted" },
548 { 0x01, "Asserted" },
549 { 0, NULL }
552 /* Fast Operate Remote Bit Lookup */
553 static const value_string selfm_fo_rb_vals[] = {
554 { 0x00, "RB01 Clear" },
555 { 0x01, "RB02 Clear" },
556 { 0x02, "RB03 Clear" },
557 { 0x03, "RB04 Clear" },
558 { 0x04, "RB05 Clear" },
559 { 0x05, "RB06 Clear" },
560 { 0x06, "RB07 Clear" },
561 { 0x07, "RB08 Clear" },
562 { 0x08, "RB09 Clear" },
563 { 0x09, "RB10 Clear" },
564 { 0x0A, "RB11 Clear" },
565 { 0x0B, "RB12 Clear" },
566 { 0x0C, "RB13 Clear" },
567 { 0x0D, "RB14 Clear" },
568 { 0x0E, "RB15 Clear" },
569 { 0x0F, "RB16 Clear" },
570 { 0x10, "RB17 Clear" },
571 { 0x11, "RB18 Clear" },
572 { 0x12, "RB19 Clear" },
573 { 0x13, "RB20 Clear" },
574 { 0x14, "RB21 Clear" },
575 { 0x15, "RB22 Clear" },
576 { 0x16, "RB23 Clear" },
577 { 0x17, "RB24 Clear" },
578 { 0x18, "RB25 Clear" },
579 { 0x19, "RB26 Clear" },
580 { 0x1A, "RB27 Clear" },
581 { 0x1B, "RB28 Clear" },
582 { 0x1C, "RB29 Clear" },
583 { 0x1D, "RB30 Clear" },
584 { 0x1E, "RB31 Clear" },
585 { 0x1F, "RB32 Clear" },
586 { 0x20, "RB01 Set" },
587 { 0x21, "RB02 Set" },
588 { 0x22, "RB03 Set" },
589 { 0x23, "RB04 Set" },
590 { 0x24, "RB05 Set" },
591 { 0x25, "RB06 Set" },
592 { 0x26, "RB07 Set" },
593 { 0x27, "RB08 Set" },
594 { 0x28, "RB09 Set" },
595 { 0x29, "RB10 Set" },
596 { 0x2A, "RB11 Set" },
597 { 0x2B, "RB12 Set" },
598 { 0x2C, "RB13 Set" },
599 { 0x2D, "RB14 Set" },
600 { 0x2E, "RB15 Set" },
601 { 0x2F, "RB16 Set" },
602 { 0x30, "RB17 Set" },
603 { 0x31, "RB18 Set" },
604 { 0x32, "RB19 Set" },
605 { 0x33, "RB20 Set" },
606 { 0x34, "RB21 Set" },
607 { 0x35, "RB22 Set" },
608 { 0x36, "RB23 Set" },
609 { 0x37, "RB24 Set" },
610 { 0x38, "RB25 Set" },
611 { 0x39, "RB26 Set" },
612 { 0x3A, "RB27 Set" },
613 { 0x3B, "RB28 Set" },
614 { 0x3C, "RB29 Set" },
615 { 0x3D, "RB30 Set" },
616 { 0x3E, "RB31 Set" },
617 { 0x3F, "RB32 Set" },
618 { 0x40, "RB01 Pulse" },
619 { 0x41, "RB02 Pulse" },
620 { 0x42, "RB03 Pulse" },
621 { 0x43, "RB04 Pulse" },
622 { 0x44, "RB05 Pulse" },
623 { 0x45, "RB06 Pulse" },
624 { 0x46, "RB07 Pulse" },
625 { 0x47, "RB08 Pulse" },
626 { 0x48, "RB09 Pulse" },
627 { 0x49, "RB10 Pulse" },
628 { 0x4A, "RB11 Pulse" },
629 { 0x4B, "RB12 Pulse" },
630 { 0x4C, "RB13 Pulse" },
631 { 0x4D, "RB14 Pulse" },
632 { 0x4E, "RB15 Pulse" },
633 { 0x4F, "RB16 Pulse" },
634 { 0x50, "RB17 Pulse" },
635 { 0x51, "RB18 Pulse" },
636 { 0x52, "RB19 Pulse" },
637 { 0x53, "RB20 Pulse" },
638 { 0x54, "RB21 Pulse" },
639 { 0x55, "RB22 Pulse" },
640 { 0x56, "RB23 Pulse" },
641 { 0x57, "RB24 Pulse" },
642 { 0x58, "RB25 Pulse" },
643 { 0x59, "RB26 Pulse" },
644 { 0x5A, "RB27 Pulse" },
645 { 0x5B, "RB28 Pulse" },
646 { 0x5C, "RB29 Pulse" },
647 { 0x5D, "RB30 Pulse" },
648 { 0x5E, "RB31 Pulse" },
649 { 0x5F, "RB32 Pulse" },
650 { 0, NULL }
652 static value_string_ext selfm_fo_rb_vals_ext = VALUE_STRING_EXT_INIT(selfm_fo_rb_vals);
654 /* Fast Operate Breaker Bit Lookup */
655 static const value_string selfm_fo_br_vals[] = {
656 { 0x11, "Breaker Bit 1 Close (CC/CC1)" },
657 { 0x12, "Breaker Bit 2 Close (CC2)" },
658 { 0x13, "Breaker Bit 3 Close (CC3)" },
659 { 0x14, "Breaker Bit 4 Close (CC4)" },
660 { 0x15, "Breaker Bit 5 Close (CC5)" },
661 { 0x16, "Breaker Bit 6 Close (CC6)" },
662 { 0x17, "Breaker Bit 7 Close (CC7)" },
663 { 0x18, "Breaker Bit 8 Close (CC8)" },
664 { 0x19, "Breaker Bit 9 Close (CC9)" },
665 { 0x1A, "Breaker Bit 10 Close (CC10)" },
666 { 0x1B, "Breaker Bit 11 Close (CC11)" },
667 { 0x1C, "Breaker Bit 12 Close (CC12)" },
668 { 0x1D, "Breaker Bit 13 Close (CC13)" },
669 { 0x1E, "Breaker Bit 14 Close (CC14)" },
670 { 0x1F, "Breaker Bit 15 Close (CC15)" },
671 { 0x20, "Breaker Bit 16 Close (CC16)" },
672 { 0x21, "Breaker Bit 17 Close (CC17)" },
673 { 0x22, "Breaker Bit 18 Close (CC18)" },
674 { 0x31, "Breaker Bit 1 Open (OC/OC1)" },
675 { 0x32, "Breaker Bit 2 Open (OC2)" },
676 { 0x33, "Breaker Bit 3 Open (OC3)" },
677 { 0x34, "Breaker Bit 4 Open (OC4)" },
678 { 0x35, "Breaker Bit 5 Open (OC5)" },
679 { 0x36, "Breaker Bit 6 Open (OC6)" },
680 { 0x37, "Breaker Bit 7 Open (OC7)" },
681 { 0x38, "Breaker Bit 8 Open (OC8)" },
682 { 0x39, "Breaker Bit 9 Open (OC9)" },
683 { 0x3A, "Breaker Bit 10 Open (OC10)" },
684 { 0x3B, "Breaker Bit 11 Open (OC11)" },
685 { 0x3C, "Breaker Bit 12 Open (OC12)" },
686 { 0x3D, "Breaker Bit 13 Open (OC13)" },
687 { 0x3E, "Breaker Bit 14 Open (OC14)" },
688 { 0x3F, "Breaker Bit 15 Open (OC15)" },
689 { 0x40, "Breaker Bit 16 Open (OC16)" },
690 { 0x41, "Breaker Bit 17 Open (OC17)" },
691 { 0x42, "Breaker Bit 18 Open (OC18)" },
692 { 0, NULL }
694 static value_string_ext selfm_fo_br_vals_ext = VALUE_STRING_EXT_INIT(selfm_fo_br_vals);
696 /* Alternate Fast Operate Function Code Lookup */
697 static const value_string selfm_foconfig_alt_funccode_vals[] = {
698 { 0xE5, "Open Breaker Bit" },
699 { 0xE6, "Close Breaker Bit" },
700 { 0xE7, "Set Remote Bit" },
701 { 0xE8, "Clear Remote Bit" },
702 { 0xE9, "Pulse Remote Bit" },
703 { 0x00, "Unsupported" },
704 { 0, NULL }
707 /* Fast Message Function Codes */
708 static const value_string selfm_fastmsg_func_code_vals[] = {
709 { FAST_MSG_CFG_BLOCK, "Fast Message Configuration Block Request" },
710 { FAST_MSG_EN_UNS_DATA, "Enable Unsolicited Data" },
711 { FAST_MSG_DIS_UNS_DATA, "Disable Unsolicited Data" },
712 { FAST_MSG_PING, "Ping Message" },
713 { FAST_MSG_READ_REQ, "Read Request" },
714 { FAST_MSG_GEN_UNS_DATA, "Generic Unsolicited Data" },
715 { FAST_MSG_SOE_STATE_REQ, "SOE Present State Request" },
716 { FAST_MSG_UNS_RESP, "Unsolicited Fast SER Data Response" },
717 { FAST_MSG_UNS_WRITE, "Unsolicited Write" },
718 { FAST_MSG_UNS_WRITE_REQ, "Unsolicited Write Request" },
719 { FAST_MSG_DEVDESC_REQ, "Device Description Request" },
720 { FAST_MSG_DATAFMT_REQ, "Data Format Request" },
721 { FAST_MSG_UNS_DATAFMT_RESP, "Unsolicited Data Format Response" },
722 { FAST_MSG_BITLABEL_REQ, "Bit Label Request" },
723 { FAST_MSG_MGMT_REQ, "Management Request" },
724 { FAST_MSG_CFG_BLOCK_RESP, "Fast Message Configuration Block Response" },
725 { FAST_MSG_EN_UNS_DATA_ACK, "Enable Unsolicited Data ACK" },
726 { FAST_MSG_DIS_UNS_DATA_ACK, "Disable Unsolicited Data ACK" },
727 { FAST_MSG_PING_ACK, "Ping Message ACK" },
728 { FAST_MSG_READ_RESP, "Read Response" },
729 { FAST_MSG_SOE_STATE_RESP, "SOE Present State Response" },
730 { FAST_MSG_UNS_RESP_ACK, "Unsolicited Fast SER Data Response ACK" },
731 { FAST_MSG_DEVDESC_RESP, "Device Description Response" },
732 { FAST_MSG_DATAFMT_RESP, "Data Format Response" },
733 { FAST_MSG_BITLABEL_RESP, "Bit Label Response" },
734 { 0, NULL }
736 static value_string_ext selfm_fastmsg_func_code_vals_ext =
737 VALUE_STRING_EXT_INIT(selfm_fastmsg_func_code_vals);
739 static const value_string selfm_fastmsg_tagtype_vals[] = {
740 { FAST_MSG_TAGTYPE_CHAR8, "1 x 8-bit character per item" },
741 { FAST_MSG_TAGTYPE_CHAR16, "2 x 8-bit characters per item" },
742 { FAST_MSG_TAGTYPE_DIGWORD8_BL, "8-bit binary item, with labels" },
743 { FAST_MSG_TAGTYPE_DIGWORD8, "8-bit binary item, without labels" },
744 { FAST_MSG_TAGTYPE_DIGWORD16_BL, "16-bit binary item, with labels" },
745 { FAST_MSG_TAGTYPE_DIGWORD16, "16-bit binary item, without labels" },
746 { FAST_MSG_TAGTYPE_INT16, "16-bit Signed Integer" },
747 { FAST_MSG_TAGTYPE_UINT16, "16-bit Unsigned Integer" },
748 { FAST_MSG_TAGTYPE_INT32, "32-bit Signed Integer" },
749 { FAST_MSG_TAGTYPE_UINT32, "32-bit Unsigned Integer" },
750 { FAST_MSG_TAGTYPE_FLOAT, "IEEE Floating Point" },
751 { 0, NULL }
754 /* Fast Message ACK Response Codes */
755 static const value_string selfm_fastmsg_ack_responsecode_vals[] = {
756 { 0x0, "Success" },
757 { 0x1, "Function code not recognized" },
758 { 0x2, "Function code supported but disabled" },
759 { 0x3, "Invalid Data Address" },
760 { 0x4, "Bad Data" },
761 { 0x5, "Insufficient Memory" },
762 { 0x6, "Busy" },
763 { 0, NULL }
766 static value_string_ext selfm_fastmsg_ack_responsecode_vals_ext =
767 VALUE_STRING_EXT_INIT(selfm_fastmsg_ack_responsecode_vals);
769 /* Fast Message Unsolicited Write COM Port Codes */
770 static const value_string selfm_fastmsg_unswrite_com_vals[] = {
771 { 0x0100, "COM01" },
772 { 0x0200, "COM02" },
773 { 0x0300, "COM03" },
774 { 0x0400, "COM04" },
775 { 0x0500, "COM05" },
776 { 0x0600, "COM06" },
777 { 0x0700, "COM07" },
778 { 0x0800, "COM08" },
779 { 0x0900, "COM09" },
780 { 0x0A00, "COM10" },
781 { 0x0B00, "COM11" },
782 { 0x0C00, "COM12" },
783 { 0x0D00, "COM13" },
784 { 0x0E00, "COM14" },
785 { 0x0F00, "COM15" },
786 { 0, NULL }
788 static value_string_ext selfm_fastmsg_unswrite_com_vals_ext =
789 VALUE_STRING_EXT_INIT(selfm_fastmsg_unswrite_com_vals);
791 /* Tables for reassembly of fragments. */
792 static reassembly_table selfm_reassembly_table;
794 /* ************************************************************************* */
795 /* Header values for reassembly */
796 /* ************************************************************************* */
797 static int hf_selfm_fragment;
798 static int hf_selfm_fragments;
799 static int hf_selfm_fragment_overlap;
800 static int hf_selfm_fragment_overlap_conflict;
801 static int hf_selfm_fragment_multiple_tails;
802 static int hf_selfm_fragment_too_long_fragment;
803 static int hf_selfm_fragment_error;
804 static int hf_selfm_fragment_count;
805 static int hf_selfm_fragment_reassembled_in;
806 static int hf_selfm_fragment_reassembled_length;
807 static int ett_selfm_fragment;
808 static int ett_selfm_fragments;
810 static const fragment_items selfm_frag_items = {
811 &ett_selfm_fragment,
812 &ett_selfm_fragments,
813 &hf_selfm_fragments,
814 &hf_selfm_fragment,
815 &hf_selfm_fragment_overlap,
816 &hf_selfm_fragment_overlap_conflict,
817 &hf_selfm_fragment_multiple_tails,
818 &hf_selfm_fragment_too_long_fragment,
819 &hf_selfm_fragment_error,
820 &hf_selfm_fragment_count,
821 &hf_selfm_fragment_reassembled_in,
822 &hf_selfm_fragment_reassembled_length,
823 /* Reassembled data field */
824 NULL,
825 "SEL Fast Message fragments"
828 /**********************************************************************************************************/
829 /* Clean all instances of 0xFFFF from Telnet payload to compensate for IAC control code (replace w/ 0xFF) */
830 /* Function Duplicated from packet-telnet.c (unescape_and_tvbuffify_telnet_option) */
831 /**********************************************************************************************************/
832 static tvbuff_t *
833 clean_telnet_iac(packet_info *pinfo, tvbuff_t *tvb, int offset, int len, int *num_skip_byte)
835 tvbuff_t *telnet_tvb;
836 uint8_t *buf;
837 const uint8_t *spos;
838 uint8_t *dpos;
839 int len_remaining, skip_byte = 0;
841 spos=tvb_get_ptr(tvb, offset, len);
842 buf=(uint8_t *)wmem_alloc(pinfo->pool, len);
843 dpos=buf;
844 len_remaining = len;
845 while(len_remaining > 0){
847 /* Only analyze two sequential bytes of source tvb if we have at least two bytes left */
848 if (len_remaining > 1) {
849 /* If two sequential 0xFF's exist, increment skip_byte counter, decrement */
850 /* len_remaining by 2 and copy a single 0xFF to dest tvb. */
851 if((spos[0]==0xff) && (spos[1]==0xff)){
852 skip_byte++;
853 len_remaining -= 2;
854 *(dpos++)=0xff;
855 spos+=2;
856 continue;
859 /* If we only have a single byte left, or there were no sequential 0xFF's, copy byte from src tvb to dest tvb */
860 *(dpos++)=*(spos++);
861 len_remaining--;
863 telnet_tvb = tvb_new_child_real_data(tvb, buf, len-skip_byte, len-skip_byte);
864 add_new_data_source(pinfo, telnet_tvb, "Processed Telnet Data");
866 *num_skip_byte = skip_byte;
868 return telnet_tvb;
871 /******************************************************************************************************/
872 /* Execute dissection of Fast Meter configuration frames independent of any GUI access of said frames */
873 /* Load configuration information into fm_config_frame struct */
874 /******************************************************************************************************/
875 static fm_config_frame* fmconfig_frame_fast(tvbuff_t *tvb)
877 /* Set up structures needed to add the protocol subtree and manage it */
878 unsigned count, offset = 0;
879 fm_config_frame *frame;
881 /* get a new frame and initialize it */
882 frame = wmem_new(wmem_file_scope(), fm_config_frame);
884 /* Get data packet setup information from config message and copy into ai_info (if required) */
885 frame->cfg_cmd = tvb_get_ntohs(tvb, offset);
886 /* skip length byte, position offset+2 */
887 frame->num_flags = tvb_get_uint8(tvb, offset+3);
888 frame->sf_loc = tvb_get_uint8(tvb, offset+4);
889 frame->sf_num = tvb_get_uint8(tvb, offset+5);
890 frame->num_ai = tvb_get_uint8(tvb, offset+6);
891 frame->num_ai_samples = tvb_get_uint8(tvb, offset+7);
892 frame->num_dig = tvb_get_uint8(tvb, offset+8);
893 frame->num_calc = tvb_get_uint8(tvb, offset+9);
895 /* Update offset pointer */
896 offset += 10;
898 /* Get data packet analog/timestamp/digital offsets and copy into ai_info */
899 frame->offset_ai = tvb_get_ntohs(tvb, offset);
900 frame->offset_ts = tvb_get_ntohs(tvb, offset+2);
901 frame->offset_dig = tvb_get_ntohs(tvb, offset+4);
903 /* Update offset pointer */
904 offset += 6;
906 frame->analogs = (fm_analog_info *)wmem_alloc(wmem_file_scope(), frame->num_ai * sizeof(fm_analog_info));
908 /* Get AI Channel Details and copy into ai_info */
909 for (count = 0; count < frame->num_ai; count++) {
910 fm_analog_info *analog = &(frame->analogs[count]);
911 tvb_memcpy(tvb, analog->name, offset, FM_CONFIG_ANA_CHNAME_LEN);
912 analog->name[FM_CONFIG_ANA_CHNAME_LEN] = '\0'; /* Put a terminating null onto the end of the AI Channel name */
913 analog->type = tvb_get_uint8(tvb, offset+6);
914 analog->sf_type = tvb_get_uint8(tvb, offset+7);
915 analog->sf_offset = tvb_get_ntohs(tvb, offset+8);
917 /* If Scale Factors are present in the cfg message, retrieve and store them per analog */
918 /* Otherwise, default to Scale Factor of 1 for now */
919 if (frame->sf_loc == FM_CONFIG_SF_LOC_CFG) {
920 analog->sf_fp = tvb_get_ntohieee_float(tvb, analog->sf_offset);
922 else {
923 analog->sf_fp = 1;
926 offset += 10;
929 return frame;
933 /******************************************************************************************************/
934 /* Execute dissection of Data Item definition info before loading GUI tree */
935 /* Load configuration information into fastmsg_dataitem struct */
936 /******************************************************************************************************/
937 static fastmsg_dataitem* fastmsg_dataitem_save(tvbuff_t *tvb, int offset)
939 fastmsg_dataitem *dataitem;
941 /* get a new dataitem and initialize it */
942 dataitem = wmem_new(wmem_file_scope(), fastmsg_dataitem);
944 /* retrieve data item name and terminate with a null */
945 tvb_memcpy(tvb, dataitem->name, offset, 10);
946 dataitem->name[10] = '\0'; /* Put a terminating null onto the end of the string */
948 /* retrieve data item quantity and type */
949 dataitem->quantity = tvb_get_ntohs(tvb, offset+10);
950 dataitem->data_type = tvb_get_ntohs(tvb, offset+12);
952 return dataitem;
956 /******************************************************************************************************/
957 /* Execute dissection of Data Region definition info before loading GUI tree */
958 /* Load configuration information into fastmsg_dataregion struct */
959 /******************************************************************************************************/
960 static fastmsg_dataregion* fastmsg_dataregion_save(tvbuff_t *tvb, int offset)
962 fastmsg_dataregion *dataregion;
964 /* get a new dataregion and initialize it */
965 dataregion = wmem_new(wmem_file_scope(), fastmsg_dataregion);
967 /* retrieve data region name and terminate with a null */
968 tvb_memcpy(tvb, dataregion->name, offset, 10);
969 dataregion->name[10] = '\0'; /* Put a terminating null onto the end of the string */
971 return dataregion;
975 /********************************************************************************************************/
976 /* Lookup region name using current base address & saved conversation data. Return ptr to char string */
977 /********************************************************************************************************/
978 static const char*
979 region_lookup(packet_info *pinfo, uint32_t base_addr)
981 fm_conversation *conv;
982 fastmsg_dataregion *dataregion = NULL;
984 conv = (fm_conversation *)p_get_proto_data(wmem_file_scope(), pinfo, proto_selfm, 0);
985 if (conv) {
986 dataregion = (fastmsg_dataregion*)wmem_tree_lookup32(conv->fastmsg_dataregions, base_addr);
989 if (dataregion) {
990 return dataregion->name;
993 /* If we couldn't identify the region using the current base address, return a default string */
994 return "Unknown Region";
997 /***********************************************************************************************************/
998 /* Create Fast SER Unsolicited Word Bit item. Return item to calling function. 'index' parameter */
999 /* will be used to store 'name' parameter in lookup tree. Index 254 and 255 are special (hardcoded) cases */
1000 /***********************************************************************************************************/
1001 static fastser_uns_wordbit* fastser_uns_wordbit_save(uint8_t idx, const char *name)
1003 fastser_uns_wordbit *wordbit_item;
1005 /* get a new wordbit_item and initialize it */
1006 wordbit_item = wmem_new(wmem_file_scope(), fastser_uns_wordbit);
1008 if (idx <= 253) {
1009 wordbit_item->name = wmem_strdup(wmem_file_scope(), name);
1012 if (idx == 254) {
1013 wordbit_item->name = wmem_strdup(wmem_file_scope(), "POWER_UP");
1016 if (idx == 255) {
1017 wordbit_item->name = wmem_strdup(wmem_file_scope(), "SET_CHNG");
1020 return wordbit_item;
1024 /***************************************************************************************************************/
1025 /* Lookup uns wordbit name using current index position & saved conversation data. Return ptr to char string */
1026 /***************************************************************************************************************/
1027 static const char*
1028 fastser_uns_wordbit_lookup(packet_info *pinfo, uint8_t idx)
1030 fm_conversation *conv;
1031 fastser_uns_wordbit *wordbit = NULL;
1033 conv = (fm_conversation *)p_get_proto_data(wmem_file_scope(), pinfo, proto_selfm, 0);
1035 if (conv) {
1036 wordbit = (fastser_uns_wordbit*)wmem_tree_lookup32(conv->fastser_uns_wordbits, idx);
1039 if (wordbit) {
1040 return wordbit->name;
1043 /* If we couldn't identify the bit using the index, return a default string */
1044 return "Unknown";
1048 /******************************************************************************************************/
1049 /* Code to Dissect Relay Definition Frames */
1050 /******************************************************************************************************/
1051 static int
1052 dissect_relaydef_frame(tvbuff_t *tvb, proto_tree *tree, int offset)
1054 /* Set up structures needed to add the protocol subtree and manage it */
1055 proto_item *relaydef_fm_item, *relaydef_flags_item, *relaydef_proto_item;
1056 proto_tree *relaydef_tree, *relaydef_fm_tree, *relaydef_flags_tree, *relaydef_proto_tree;
1057 uint8_t len, num_proto, num_fm, num_flags;
1058 int count;
1060 len = tvb_get_uint8(tvb, offset);
1061 num_proto = tvb_get_uint8(tvb, offset+1);
1062 num_fm = tvb_get_uint8(tvb, offset+2);
1063 num_flags = tvb_get_uint8(tvb, offset+3);
1065 /* Add items to protocol tree specific to Relay Definition Block */
1066 relaydef_tree = proto_tree_add_subtree(tree, tvb, offset, len-2, ett_selfm_relaydef, NULL, "Relay Definition Block Details");
1068 /* Reported length */
1069 proto_tree_add_item(relaydef_tree, hf_selfm_relaydef_len, tvb, offset, 1, ENC_BIG_ENDIAN);
1071 /* Reported Number of Protocols Supported */
1072 relaydef_proto_item = proto_tree_add_item(relaydef_tree, hf_selfm_relaydef_numproto, tvb, offset+1, 1, ENC_BIG_ENDIAN);
1073 relaydef_proto_tree = proto_item_add_subtree(relaydef_proto_item, ett_selfm_relaydef_proto);
1075 /* Reported Number of Fast Meter Commands Supported */
1076 relaydef_fm_item = proto_tree_add_item(relaydef_tree, hf_selfm_relaydef_numfm, tvb, offset+2, 1, ENC_BIG_ENDIAN);
1077 relaydef_fm_tree = proto_item_add_subtree(relaydef_fm_item, ett_selfm_relaydef_fm);
1079 /* Reported Number of Status Bit Flags Supported */
1080 relaydef_flags_item = proto_tree_add_item(relaydef_tree, hf_selfm_relaydef_numflags, tvb, offset+3, 1, ENC_BIG_ENDIAN);
1081 relaydef_flags_tree = proto_item_add_subtree(relaydef_flags_item, ett_selfm_relaydef_flags);
1083 /* Get our offset up-to-date */
1084 offset += 4;
1086 /* Add each reported Fast Meter cfg/data message */
1087 for (count = 1; count <= num_fm; count++) {
1088 proto_tree_add_item(relaydef_fm_tree, hf_selfm_relaydef_fmcfg_cmd, tvb, offset, 2, ENC_BIG_ENDIAN);
1089 proto_tree_add_item(relaydef_fm_tree, hf_selfm_relaydef_fmdata_cmd, tvb, offset+2, 2, ENC_BIG_ENDIAN);
1090 offset += 4;
1093 /* Add each reported status bit flag, along with corresponding response command */
1094 for (count = 1; count <= num_flags; count++) {
1095 proto_tree_add_item(relaydef_flags_tree, hf_selfm_relaydef_statbit, tvb, offset, 2, ENC_BIG_ENDIAN);
1096 proto_tree_add_item(relaydef_flags_tree, hf_selfm_relaydef_statbit_cmd, tvb, offset+2, 6, ENC_NA);
1097 offset += 8;
1100 /* Add each supported protocol */
1101 for (count = 1; count <= num_proto; count++) {
1102 proto_tree_add_item(relaydef_proto_tree, hf_selfm_relaydef_proto, tvb, offset, 2, ENC_BIG_ENDIAN);
1103 offset += 2;
1106 /* Add Pad byte (if present) and checksum */
1107 if (tvb_reported_length_remaining(tvb, offset) > 1) {
1108 proto_tree_add_item(relaydef_tree, hf_selfm_padbyte, tvb, offset, 1, ENC_BIG_ENDIAN);
1109 offset += 1;
1112 proto_tree_add_checksum(relaydef_tree, tvb, offset, hf_selfm_checksum, -1, NULL, NULL, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
1113 offset += 1;
1115 return offset;
1118 /******************************************************************************************************/
1119 /* Code to dissect Fast Meter Configuration Frames */
1120 /******************************************************************************************************/
1121 static int
1122 dissect_fmconfig_frame(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, int offset)
1124 /* Set up structures needed to add the protocol subtree and manage it */
1125 proto_tree *fmconfig_tree, *fmconfig_ai_tree=NULL, *fmconfig_calc_tree=NULL;
1126 unsigned count;
1127 uint8_t len, sf_loc, num_sf, num_ai, num_calc;
1128 char* ai_name;
1130 len = tvb_get_uint8(tvb, offset);
1131 /* skip num_flags, position offset+1 */
1132 sf_loc = tvb_get_uint8(tvb, offset+2);
1133 num_sf = tvb_get_uint8(tvb, offset+3);
1134 num_ai = tvb_get_uint8(tvb, offset+4);
1135 /* skip num_samp, position offset+5 */
1136 /* skip num_dig, position offset+6 */
1137 num_calc = tvb_get_uint8(tvb, offset+7);
1139 fmconfig_tree = proto_tree_add_subtree(tree, tvb, offset, len-2, ett_selfm_fmconfig, NULL, "Fast Meter Configuration Details");
1141 /* Add items to protocol tree specific to Fast Meter Configuration Block */
1143 /* Get Setup Information for FM Config Block */
1144 proto_tree_add_item(fmconfig_tree, hf_selfm_fmconfig_len, tvb, offset, 1, ENC_BIG_ENDIAN);
1145 proto_tree_add_item(fmconfig_tree, hf_selfm_fmconfig_numflags, tvb, offset+1, 1, ENC_BIG_ENDIAN);
1146 proto_tree_add_item(fmconfig_tree, hf_selfm_fmconfig_loc_sf, tvb, offset+2, 1, ENC_BIG_ENDIAN);
1147 proto_tree_add_item(fmconfig_tree, hf_selfm_fmconfig_num_sf, tvb, offset+3, 1, ENC_BIG_ENDIAN);
1148 proto_tree_add_item(fmconfig_tree, hf_selfm_fmconfig_num_ai, tvb, offset+4, 1, ENC_BIG_ENDIAN);
1149 proto_tree_add_item(fmconfig_tree, hf_selfm_fmconfig_num_samp, tvb, offset+5, 1, ENC_BIG_ENDIAN);
1150 proto_tree_add_item(fmconfig_tree, hf_selfm_fmconfig_num_dig, tvb, offset+6, 1, ENC_BIG_ENDIAN);
1151 proto_tree_add_item(fmconfig_tree, hf_selfm_fmconfig_num_calc, tvb, offset+7, 1, ENC_BIG_ENDIAN);
1153 /* Update offset pointer */
1154 offset += 8;
1156 /* Add data packet offsets to tree and update offset pointer */
1157 proto_tree_add_item(fmconfig_tree, hf_selfm_fmconfig_ofs_ai, tvb, offset, 2, ENC_BIG_ENDIAN);
1158 proto_tree_add_item(fmconfig_tree, hf_selfm_fmconfig_ofs_ts, tvb, offset+2, 2, ENC_BIG_ENDIAN);
1159 proto_tree_add_item(fmconfig_tree, hf_selfm_fmconfig_ofs_dig, tvb, offset+4, 2, ENC_BIG_ENDIAN);
1160 offset += 6;
1162 /* Get AI Channel Details */
1163 for (count = 0; count < num_ai; count++) {
1164 ai_name = tvb_get_string_enc(pinfo->pool, tvb, offset, 6, ENC_ASCII);
1166 fmconfig_ai_tree = proto_tree_add_subtree_format(fmconfig_tree, tvb, offset, 10,
1167 ett_selfm_fmconfig_ai, NULL, "Analog Channel: %s", ai_name);
1169 /* Add Channel Name, Channel Data Type, Scale Factor Type and Scale Factor Offset to tree */
1170 proto_tree_add_item(fmconfig_ai_tree, hf_selfm_fmconfig_ai_channel, tvb, offset, 6, ENC_ASCII);
1171 proto_tree_add_item(fmconfig_ai_tree, hf_selfm_fmconfig_ai_type, tvb, offset+6, 1, ENC_BIG_ENDIAN);
1172 proto_tree_add_item(fmconfig_ai_tree, hf_selfm_fmconfig_ai_sf_type, tvb, offset+7, 1, ENC_BIG_ENDIAN);
1173 proto_tree_add_item(fmconfig_ai_tree, hf_selfm_fmconfig_ai_sf_ofs, tvb, offset+8, 2, ENC_BIG_ENDIAN);
1175 /* Update Offset Pointer */
1176 offset += 10;
1179 /* 14-byte Calculation block instances based on num_calc */
1180 for (count = 0; count < num_calc; count++) {
1181 fmconfig_calc_tree = proto_tree_add_subtree_format(fmconfig_tree, tvb, offset, 14,
1182 ett_selfm_fmconfig_calc, NULL, "Calculation Block: %d", count+1);
1184 /* Rotation, Voltage Connection and Current Connection are all bit-masked on the same byte */
1185 proto_tree_add_item(fmconfig_calc_tree, hf_selfm_fmconfig_cblk_rot, tvb, offset, 1, ENC_BIG_ENDIAN);
1186 proto_tree_add_item(fmconfig_calc_tree, hf_selfm_fmconfig_cblk_vconn, tvb, offset, 1, ENC_BIG_ENDIAN);
1187 proto_tree_add_item(fmconfig_calc_tree, hf_selfm_fmconfig_cblk_iconn, tvb, offset, 1, ENC_BIG_ENDIAN);
1189 proto_tree_add_item(fmconfig_calc_tree, hf_selfm_fmconfig_cblk_ctype, tvb, offset+1, 1, ENC_BIG_ENDIAN);
1190 proto_tree_add_item(fmconfig_calc_tree, hf_selfm_fmconfig_cblk_deskew_ofs, tvb, offset+2, 2, ENC_BIG_ENDIAN);
1191 proto_tree_add_item(fmconfig_calc_tree, hf_selfm_fmconfig_cblk_rs_ofs, tvb, offset+4, 2, ENC_BIG_ENDIAN);
1192 proto_tree_add_item(fmconfig_calc_tree, hf_selfm_fmconfig_cblk_xs_ofs, tvb, offset+6, 2, ENC_BIG_ENDIAN);
1193 proto_tree_add_item(fmconfig_calc_tree, hf_selfm_fmconfig_cblk_ia_idx, tvb, offset+8, 1, ENC_BIG_ENDIAN);
1194 proto_tree_add_item(fmconfig_calc_tree, hf_selfm_fmconfig_cblk_ib_idx, tvb, offset+9, 1, ENC_BIG_ENDIAN);
1195 proto_tree_add_item(fmconfig_calc_tree, hf_selfm_fmconfig_cblk_ic_idx, tvb, offset+10, 1, ENC_BIG_ENDIAN);
1196 proto_tree_add_item(fmconfig_calc_tree, hf_selfm_fmconfig_cblk_va_idx, tvb, offset+11, 1, ENC_BIG_ENDIAN);
1197 proto_tree_add_item(fmconfig_calc_tree, hf_selfm_fmconfig_cblk_vb_idx, tvb, offset+12, 1, ENC_BIG_ENDIAN);
1198 proto_tree_add_item(fmconfig_calc_tree, hf_selfm_fmconfig_cblk_vc_idx, tvb, offset+13, 1, ENC_BIG_ENDIAN);
1200 offset += 14;
1203 /* Add Config Message Scale Factor(s) (if present) */
1204 if ((num_sf != 0) && (sf_loc == FM_CONFIG_SF_LOC_CFG)) {
1205 for (count = 0; count < num_sf; count++) {
1206 proto_tree_add_item(fmconfig_tree, hf_selfm_fmconfig_ai_sf_float, tvb, offset, 4, ENC_BIG_ENDIAN);
1207 offset += 4;
1211 /* Add Pad byte (if present) and checksum */
1212 if (tvb_reported_length_remaining(tvb, offset) > 1) {
1213 proto_tree_add_item(fmconfig_tree, hf_selfm_padbyte, tvb, offset, 1, ENC_BIG_ENDIAN);
1214 offset += 1;
1217 proto_tree_add_checksum(fmconfig_tree, tvb, offset, hf_selfm_checksum, -1, NULL, NULL, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
1218 offset += 1;
1220 return offset;
1224 /******************************************************************************************************/
1225 /* Code to dissect Fast Meter Data Frames */
1226 /* Formatting depends heavily on previously-encountered Configuration Frames so search array instances for them */
1227 /******************************************************************************************************/
1228 static int
1229 dissect_fmdata_frame(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, int offset, uint16_t config_cmd_match)
1231 /* Set up structures needed to add the protocol subtree and manage it */
1232 proto_item *fmdata_item, *fmdata_dig_ch_item;
1233 proto_item *fmdata_ai_sf_item;
1234 proto_tree *fmdata_tree, *fmdata_ai_tree=NULL, *fmdata_dig_tree=NULL, *fmdata_ai_ch_tree=NULL, *fmdata_dig_ch_tree=NULL;
1235 uint8_t len, idx=0, j=0;
1236 uint16_t config_cmd;
1237 int16_t ai_int16val;
1238 int cnt = 0, ch_size=0;
1239 float ai_sf_fp;
1240 bool config_found = false;
1241 fm_conversation *conv;
1242 fm_config_frame *cfg_data = NULL;
1243 nstime_t datetime;
1244 struct tm tm;
1246 len = tvb_get_uint8(tvb, offset);
1248 fmdata_tree = proto_tree_add_subtree_format(tree, tvb, offset, len-2, ett_selfm_fmdata, &fmdata_item, "Fast Meter Data Details");
1250 /* Reported length */
1251 proto_tree_add_item(fmdata_tree, hf_selfm_fmdata_len, tvb, offset, 1, ENC_BIG_ENDIAN);
1252 offset += 1;
1254 /* Search for previously-encountered Configuration information to dissect the frame */
1256 conv = (fm_conversation *)p_get_proto_data(wmem_file_scope(), pinfo, proto_selfm, 0);
1258 if (conv) {
1259 wmem_list_frame_t *frame = wmem_list_head(conv->fm_config_frames);
1260 /* Cycle through possible instances of multiple fm_config_data_blocks, looking for match */
1261 while (frame && !config_found) {
1262 cfg_data = (fm_config_frame *)wmem_list_frame_data(frame);
1263 config_cmd = cfg_data->cfg_cmd;
1265 /* If the stored config_cmd matches the expected one we are looking for, mark that the config data was found */
1266 if (config_cmd == config_cmd_match) {
1267 proto_item_append_text(fmdata_item, ", using frame number %"PRIu32" as Configuration Frame",
1268 cfg_data->fnum);
1269 config_found = true;
1272 frame = wmem_list_frame_next(frame);
1275 if (config_found) {
1277 /* Retrieve number of Status Flag bytes and setup tree */
1278 if (cfg_data->num_flags == 1){
1279 proto_tree_add_item(fmdata_tree, hf_selfm_fmdata_flagbyte, tvb, offset, 1, ENC_BIG_ENDIAN);
1280 /*offset += 1;*/
1283 cnt = cfg_data->num_ai; /* actual number of analog values to available to dissect */
1285 /* Update our current tvb offset to the actual AI offset saved from the Configuration message */
1286 offset = cfg_data->offset_ai;
1288 /* Check that we actually have analog data to dissect */
1289 if (cnt > 0) {
1291 /* Include decoding for each Sample provided for the Analog Channels */
1292 for (j=0; j < cfg_data->num_ai_samples; j++) {
1294 /* Use different lookup strings, depending on how many samples are available per Analog Channel */
1295 if (cfg_data->num_ai_samples == 1) {
1296 fmdata_ai_tree = proto_tree_add_subtree_format(fmdata_tree, tvb, offset, ((cfg_data->offset_ts - cfg_data->offset_ai)/cfg_data->num_ai_samples),
1297 ett_selfm_fmdata_ai, NULL, "Analog Channels (%d), Sample: %d (%s)",
1298 cfg_data->num_ai, j+1, val_to_str_const(j+1, selfm_fmconfig_numsamples1_vals, "Unknown"));
1300 else if (cfg_data->num_ai_samples == 2) {
1301 fmdata_ai_tree = proto_tree_add_subtree_format(fmdata_tree, tvb, offset, ((cfg_data->offset_ts - cfg_data->offset_ai)/cfg_data->num_ai_samples),
1302 ett_selfm_fmdata_ai, NULL, "Analog Channels (%d), Sample: %d (%s)",
1303 cfg_data->num_ai, j+1, val_to_str_const(j+1, selfm_fmconfig_numsamples2_vals, "Unknown"));
1305 else if (cfg_data->num_ai_samples == 4) {
1306 fmdata_ai_tree = proto_tree_add_subtree_format(fmdata_tree, tvb, offset, ((cfg_data->offset_ts - cfg_data->offset_ai)/cfg_data->num_ai_samples),
1307 ett_selfm_fmdata_ai, NULL, "Analog Channels (%d), Sample: %d (%s)",
1308 cfg_data->num_ai, j+1, val_to_str_const(j+1, selfm_fmconfig_numsamples4_vals, "Unknown"));
1311 /* For each analog channel we encounter... */
1312 for (idx = 0; idx < cnt; idx++) {
1314 fm_analog_info *ai = &(cfg_data->analogs[idx]);
1316 /* Channel size (in bytes) determined by data type */
1317 switch (ai->type) {
1318 case FM_CONFIG_ANA_CHTYPE_INT16:
1319 ch_size = 2; /* 2 bytes */
1320 break;
1321 case FM_CONFIG_ANA_CHTYPE_FP:
1322 ch_size = 4; /* 4 bytes */
1323 break;
1324 case FM_CONFIG_ANA_CHTYPE_FPD:
1325 ch_size = 8; /* 8 bytes */
1326 break;
1327 default:
1328 break;
1331 /* Build sub-tree for each Analog Channel */
1332 fmdata_ai_ch_tree = proto_tree_add_subtree_format(fmdata_ai_tree, tvb, offset, ch_size,
1333 ett_selfm_fmdata_ai_ch, NULL, "Analog Channel %d: %s", idx+1, ai->name);
1335 /* XXX - Need more decoding options here for different data types, but I need packet capture examples first */
1336 /* Decode analog value appropriately, according to data type */
1337 switch (ai->type) {
1338 /* Channel type is 16-bit Integer */
1339 case FM_CONFIG_ANA_CHTYPE_INT16:
1340 ai_int16val = tvb_get_ntohs(tvb, offset);
1342 /* If we've got a scale factor, apply it before printing the analog */
1343 /* For scale factors present in the Fast Meter Data message... */
1344 if ((ai->sf_offset != 0) && (ai->sf_type == FM_CONFIG_ANA_SFTYPE_FP) && (cfg_data->sf_loc == FM_CONFIG_SF_LOC_FM)) {
1345 ai_sf_fp = tvb_get_ntohieee_float(tvb, ai->sf_offset);
1346 proto_tree_add_float(fmdata_ai_ch_tree, hf_selfm_fmdata_ai_sf_fp, tvb, ai->sf_offset, 4, ai_sf_fp);
1348 /* For scale factors present in the Fast Meter Configuration Message... */
1349 else if (cfg_data->sf_loc == FM_CONFIG_SF_LOC_CFG) {
1350 ai_sf_fp = ai->sf_fp;
1351 fmdata_ai_sf_item = proto_tree_add_float(fmdata_ai_ch_tree, hf_selfm_fmdata_ai_sf_fp, tvb, offset, ch_size, ai_sf_fp);
1352 proto_item_set_generated(fmdata_ai_sf_item);
1354 /* If there was no scale factor, default value to 1 */
1355 else {
1356 ai_sf_fp = 1;
1359 proto_tree_add_uint(fmdata_ai_ch_tree, hf_selfm_fmdata_ai_value16, tvb, offset, ch_size, ai_int16val);
1360 proto_tree_add_float(fmdata_ai_ch_tree, hf_selfm_fmdata_ai_scale_factor, tvb, offset, ch_size, ((float)ai_int16val*ai_sf_fp));
1361 offset += ch_size;
1362 break;
1363 /* Channel type is IEEE Floating point */
1364 case FM_CONFIG_ANA_CHTYPE_FP:
1365 proto_tree_add_item(fmdata_ai_ch_tree, hf_selfm_fmdata_ai_value_float, tvb, offset, ch_size, ENC_BIG_ENDIAN);
1366 offset += ch_size;
1367 break;
1368 /* Channel type is Double IEEE Floating point */
1369 case FM_CONFIG_ANA_CHTYPE_FPD:
1370 proto_tree_add_item(fmdata_ai_ch_tree, hf_selfm_fmdata_ai_value_double, tvb, offset, ch_size, ENC_BIG_ENDIAN);
1371 offset += ch_size;
1372 break;
1374 } /* channel type */
1376 } /* number of analog channels */
1378 } /* number of samples */
1380 } /* there were analogs */
1382 /* Check if we have a time-stamp in this message */
1383 if (cfg_data->offset_ts != 0xFFFF) {
1384 /* Retrieve timestamp from 8-byte format */
1385 /* Stored as: month, day, year (xx), hr, min, sec, msec (16-bit) */
1386 tm.tm_mon = tvb_get_uint8(tvb, offset) - 1;
1387 tm.tm_mday = tvb_get_uint8(tvb, offset+1);
1388 tm.tm_year = tvb_get_uint8(tvb, offset+2) + 100;
1389 tm.tm_hour = tvb_get_uint8(tvb, offset+3);
1390 tm.tm_min = tvb_get_uint8(tvb, offset+4);
1391 tm.tm_sec = tvb_get_uint8(tvb, offset+5);
1392 tm.tm_isdst = 0;
1394 datetime.nsecs = (tvb_get_ntohs(tvb, offset+6) % 1000) * 1000000;
1395 datetime.secs = mktime(&tm);
1397 proto_tree_add_time(fmdata_tree, hf_selfm_fmdata_timestamp, tvb, offset, 8, &datetime);
1399 offset += 8;
1402 /* Check that we actually have digital data */
1403 if (cfg_data->num_dig > 0) {
1405 fmdata_dig_tree = proto_tree_add_subtree_format(fmdata_tree, tvb, offset, cfg_data->num_dig,
1406 ett_selfm_fmdata_dig, NULL, "Digital Channels (%d)", cfg_data->num_dig);
1408 for (idx=0; idx < cfg_data->num_dig; idx++) {
1410 fmdata_dig_ch_tree = proto_tree_add_subtree_format(fmdata_dig_tree, tvb, offset, 1, ett_selfm_fmdata_dig_ch, &fmdata_dig_ch_item, "Digital Word Bit Row: %2d", idx+1);
1412 /* Display the bit pattern on the digital channel proto_item */
1413 proto_item_append_text(fmdata_dig_ch_item, " [ %d %d %d %d %d %d %d %d ]",
1414 ((tvb_get_uint8(tvb, offset) & 0x80) >> 7), ((tvb_get_uint8(tvb, offset) & 0x40) >> 6),
1415 ((tvb_get_uint8(tvb, offset) & 0x20) >> 5), ((tvb_get_uint8(tvb, offset) & 0x10) >> 4),
1416 ((tvb_get_uint8(tvb, offset) & 0x08) >> 3), ((tvb_get_uint8(tvb, offset) & 0x04) >> 2),
1417 ((tvb_get_uint8(tvb, offset) & 0x02) >> 1), (tvb_get_uint8(tvb, offset) & 0x01));
1419 proto_tree_add_item(fmdata_dig_ch_tree, hf_selfm_fmdata_dig_b0, tvb, offset, 1, ENC_BIG_ENDIAN);
1420 proto_tree_add_item(fmdata_dig_ch_tree, hf_selfm_fmdata_dig_b1, tvb, offset, 1, ENC_BIG_ENDIAN);
1421 proto_tree_add_item(fmdata_dig_ch_tree, hf_selfm_fmdata_dig_b2, tvb, offset, 1, ENC_BIG_ENDIAN);
1422 proto_tree_add_item(fmdata_dig_ch_tree, hf_selfm_fmdata_dig_b3, tvb, offset, 1, ENC_BIG_ENDIAN);
1423 proto_tree_add_item(fmdata_dig_ch_tree, hf_selfm_fmdata_dig_b4, tvb, offset, 1, ENC_BIG_ENDIAN);
1424 proto_tree_add_item(fmdata_dig_ch_tree, hf_selfm_fmdata_dig_b5, tvb, offset, 1, ENC_BIG_ENDIAN);
1425 proto_tree_add_item(fmdata_dig_ch_tree, hf_selfm_fmdata_dig_b6, tvb, offset, 1, ENC_BIG_ENDIAN);
1426 proto_tree_add_item(fmdata_dig_ch_tree, hf_selfm_fmdata_dig_b7, tvb, offset, 1, ENC_BIG_ENDIAN);
1428 offset += 1;
1431 } /* digital data was available */
1433 /* Add Pad byte (if present) and checksum */
1434 if (tvb_reported_length_remaining(tvb, offset) > 1) {
1435 proto_tree_add_item(fmdata_tree, hf_selfm_padbyte, tvb, offset, 1, ENC_BIG_ENDIAN);
1436 offset += 1;
1439 proto_tree_add_checksum(fmdata_tree, tvb, offset, hf_selfm_checksum, -1, NULL, pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
1440 offset += 1;
1442 } /* matching config frame message was found */
1444 } /* config data found */
1446 if (!config_found) {
1447 proto_item_append_text(fmdata_item, ", No Fast Meter Configuration frame found");
1448 offset += (len-3); /* Don't include the 2 header bytes or 1 length byte, those are already in the offset */
1449 return offset;
1453 return offset;
1457 /******************************************************************************************************/
1458 /* Code to Dissect Fast Operate Configuration Frames */
1459 /******************************************************************************************************/
1460 static int
1461 dissect_foconfig_frame(tvbuff_t *tvb, proto_tree *tree, int offset)
1463 /* Set up structures needed to add the protocol subtree and manage it */
1464 proto_item *foconfig_brkr_item, *foconfig_rb_item;
1465 proto_tree *foconfig_tree, *foconfig_brkr_tree=NULL, *foconfig_rb_tree=NULL;
1466 unsigned count;
1467 uint8_t len, num_brkr, prb_supp;
1468 uint16_t num_rb;
1470 len = tvb_get_uint8(tvb, offset);
1471 num_brkr = tvb_get_uint8(tvb, offset+1);
1472 num_rb = tvb_get_ntohs(tvb, offset+2);
1473 prb_supp = tvb_get_uint8(tvb, offset+4);
1475 foconfig_tree = proto_tree_add_subtree(tree, tvb, offset, len-2, ett_selfm_foconfig, NULL, "Fast Operate Configuration Details");
1477 /* Add items to protocol tree specific to Fast Operate Configuration Block */
1479 /* Reported length */
1480 proto_tree_add_item(foconfig_tree, hf_selfm_foconfig_len, tvb, offset, 1, ENC_BIG_ENDIAN);
1482 /* Supported Breaker Bits */
1483 foconfig_brkr_item = proto_tree_add_item(foconfig_tree, hf_selfm_foconfig_num_brkr, tvb, offset+1, 1, ENC_BIG_ENDIAN);
1485 /* Supported Remote Bits */
1486 foconfig_rb_item = proto_tree_add_item(foconfig_tree, hf_selfm_foconfig_num_rb, tvb, offset+2, 2, ENC_BIG_ENDIAN);
1488 /* Add "Remote Bit Pulse Supported?" and "Reserved Bit" to Tree */
1489 proto_tree_add_item(foconfig_tree, hf_selfm_foconfig_prb_supp, tvb, offset+4, 1, ENC_BIG_ENDIAN);
1490 proto_tree_add_item(foconfig_tree, hf_selfm_foconfig_reserved, tvb, offset+5, 1, ENC_BIG_ENDIAN);
1492 /* Update offset pointer */
1493 offset += 6;
1495 /* Get Breaker Bit Command Details */
1496 for (count = 1; count <= num_brkr; count++) {
1498 foconfig_brkr_tree = proto_item_add_subtree(foconfig_brkr_item, ett_selfm_foconfig_brkr);
1500 /* Add Breaker Open/Close commands to tree */
1501 proto_tree_add_item(foconfig_brkr_tree, hf_selfm_foconfig_brkr_open, tvb, offset, 1, ENC_BIG_ENDIAN);
1502 proto_tree_add_item(foconfig_brkr_tree, hf_selfm_foconfig_brkr_close, tvb, offset+1, 1, ENC_BIG_ENDIAN);
1504 offset += 2;
1507 /* Get Remote Bit Command Details */
1508 for (count = 1; count <= num_rb; count++) {
1510 foconfig_rb_tree = proto_item_add_subtree(foconfig_rb_item, ett_selfm_foconfig_rb);
1512 /* Add "Remote Bit Set" command to tree */
1513 proto_tree_add_item(foconfig_rb_tree, hf_selfm_foconfig_rb_cmd, tvb, offset, 1, ENC_BIG_ENDIAN);
1515 /* Print "Remote Bit Clear" command to tree */
1516 proto_tree_add_item(foconfig_rb_tree, hf_selfm_foconfig_rb_cmd, tvb, offset+1, 1, ENC_BIG_ENDIAN);
1518 /* If Remote Bit "pulse" is supported, retrieve that command as well */
1519 if (prb_supp) {
1520 proto_tree_add_item(foconfig_rb_tree, hf_selfm_foconfig_rb_cmd, tvb, offset+2, 1, ENC_BIG_ENDIAN);
1521 offset += 3;
1523 else{
1524 offset += 2;
1528 /* Add Pad byte (if present) and checksum */
1529 if (tvb_reported_length_remaining(tvb, offset) > 1) {
1530 proto_tree_add_item(foconfig_tree, hf_selfm_padbyte, tvb, offset, 1, ENC_BIG_ENDIAN);
1531 offset += 1;
1534 proto_tree_add_checksum(foconfig_tree, tvb, offset, hf_selfm_checksum, -1, NULL, NULL, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
1535 offset += 1;
1537 return offset;
1541 /******************************************************************************************************/
1542 /* Code to Dissect Alternate Fast Operate (AFO) Configuration Frames */
1543 /******************************************************************************************************/
1544 static int
1545 dissect_alt_fastop_config_frame(tvbuff_t *tvb, proto_tree *tree, int offset)
1547 /* Set up structures needed to add the protocol subtree and manage it */
1548 proto_tree *foconfig_tree;
1549 uint8_t len;
1551 len = tvb_get_uint8(tvb, offset);
1553 foconfig_tree = proto_tree_add_subtree(tree, tvb, offset, len-2,
1554 ett_selfm_foconfig, NULL, "Alternate Fast Operate Configuration Details");
1556 /* Add items to protocol tree specific to Fast Operate Configuration Block */
1558 /* Reported length */
1559 proto_tree_add_item(foconfig_tree, hf_selfm_alt_foconfig_len, tvb, offset, 1, ENC_BIG_ENDIAN);
1561 /* Number of Ports */
1562 proto_tree_add_item(foconfig_tree, hf_selfm_alt_foconfig_num_ports, tvb, offset+1, 1, ENC_BIG_ENDIAN);
1564 /* Number of Breaker Bits */
1565 proto_tree_add_item(foconfig_tree, hf_selfm_alt_foconfig_num_brkr, tvb, offset+2, 1, ENC_BIG_ENDIAN);
1567 /* Number of Remote Bits */
1568 proto_tree_add_item(foconfig_tree, hf_selfm_alt_foconfig_num_rb, tvb, offset+3, 1, ENC_BIG_ENDIAN);
1570 /* Function Code(s) Supported */
1571 proto_tree_add_item(foconfig_tree, hf_selfm_alt_foconfig_funccode, tvb, offset+4, 1, ENC_BIG_ENDIAN);
1572 proto_tree_add_item(foconfig_tree, hf_selfm_alt_foconfig_funccode, tvb, offset+5, 1, ENC_BIG_ENDIAN);
1573 proto_tree_add_item(foconfig_tree, hf_selfm_alt_foconfig_funccode, tvb, offset+6, 1, ENC_BIG_ENDIAN);
1574 proto_tree_add_item(foconfig_tree, hf_selfm_alt_foconfig_funccode, tvb, offset+7, 1, ENC_BIG_ENDIAN);
1575 proto_tree_add_item(foconfig_tree, hf_selfm_alt_foconfig_funccode, tvb, offset+8, 1, ENC_BIG_ENDIAN);
1577 offset += (len - 2);
1579 return offset;
1583 /******************************************************************************************************/
1584 /* Code to Dissect Fast Operate (Remote Bit or Breaker Bit) Frames */
1585 /******************************************************************************************************/
1586 static int
1587 dissect_fastop_frame(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, int offset)
1589 /* Set up structures needed to add the protocol subtree and manage it */
1590 proto_tree *fastop_tree;
1591 uint8_t len, opcode;
1592 uint16_t msg_type;
1594 msg_type = tvb_get_ntohs(tvb, offset-2);
1595 len = tvb_get_uint8(tvb, offset);
1597 fastop_tree = proto_tree_add_subtree(tree, tvb, offset, len-2, ett_selfm_fastop, NULL, "Fast Operate Details");
1599 /* Add Reported length to tree*/
1600 proto_tree_add_item(fastop_tree, hf_selfm_fastop_len, tvb, offset, 1, ENC_BIG_ENDIAN);
1601 offset += 1;
1603 /* Operate Code */
1604 opcode = tvb_get_uint8(tvb, offset);
1606 /* Use different lookup table for different msg_type */
1607 if (msg_type == CMD_FASTOP_RB_CTRL) {
1608 proto_tree_add_item(fastop_tree, hf_selfm_fastop_rb_code, tvb, offset, 1, ENC_BIG_ENDIAN);
1610 /* Append Column Info w/ Control Code Code */
1611 col_append_sep_str(pinfo->cinfo, COL_INFO, NULL, val_to_str_ext_const(opcode, &selfm_fo_rb_vals_ext, "Unknown Control Code"));
1613 else if (msg_type == CMD_FASTOP_BR_CTRL) {
1614 proto_tree_add_item(fastop_tree, hf_selfm_fastop_br_code, tvb, offset, 1, ENC_BIG_ENDIAN);
1616 /* Append Column Info w/ Control Code Code */
1617 col_append_sep_str(pinfo->cinfo, COL_INFO, NULL, val_to_str_ext_const(opcode, &selfm_fo_br_vals_ext, "Unknown Control Code"));
1619 offset += 1;
1621 /* Operate Code Validation */
1622 proto_tree_add_item(fastop_tree, hf_selfm_fastop_valid, tvb, offset, 1, ENC_BIG_ENDIAN);
1623 offset += 1;
1625 /* Add checksum */
1626 proto_tree_add_checksum(fastop_tree, tvb, offset, hf_selfm_checksum, -1, NULL, pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
1627 offset += 1;
1629 return offset;
1633 /******************************************************************************************************/
1634 /* Code to Dissect Alternate Fast Operate (AFO) Command Frames */
1635 /******************************************************************************************************/
1636 static int
1637 dissect_alt_fastop_frame(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, int offset)
1639 /* Set up structures needed to add the protocol subtree and manage it */
1640 proto_tree *fastop_tree;
1641 uint8_t len;
1642 uint16_t opcode;
1644 len = tvb_get_uint8(tvb, offset);
1646 fastop_tree = proto_tree_add_subtree(tree, tvb, offset, len-2, ett_selfm_fastop, NULL, "Alternate Fast Operate Details");
1648 /* Add Reported length to tree */
1649 proto_tree_add_item(fastop_tree, hf_selfm_alt_fastop_len, tvb, offset, 1, ENC_BIG_ENDIAN);
1650 offset += 1;
1652 /* Operate Code */
1653 opcode = tvb_get_ntohs(tvb, offset);
1655 /* Append Column Info w/ Control Code Code */
1656 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "%#x", opcode);
1658 proto_tree_add_item(fastop_tree, hf_selfm_alt_fastop_code, tvb, offset, 2, ENC_BIG_ENDIAN);
1660 offset += 2;
1662 /* Operate Code Validation */
1663 proto_tree_add_item(fastop_tree, hf_selfm_alt_fastop_valid, tvb, offset, 2, ENC_BIG_ENDIAN);
1664 offset += 2;
1666 return offset;
1670 /************************************************************************************************************************/
1671 /* Code to dissect Fast Message Read Response Messages */
1672 /************************************************************************************************************************/
1673 /* Each Read Response frame can have a maximum data size of 117 x 16-bit words (or 234 bytes) - this is due to the 20 */
1674 /* bytes of overhead and 254 max frame size. In the event of a larger data payload than 234 bytes, the FIR and FIN */
1675 /* bits will be used to indicate either the first frame, last frame, or a neither/middle frame. */
1676 /* We can use the FIN bit to attempt a reassembly of the data payload since all messages will arrive sequentially. */
1677 /************************************************************************************************************************/
1679 static int
1680 dissect_fastmsg_readresp_frame(tvbuff_t *tvb, proto_tree *fastmsg_tree, packet_info *pinfo, int offset, uint8_t seq_byte)
1682 proto_item *fastmsg_tag_value_item=NULL, *fmdata_dig_item=NULL;
1683 proto_item *pi_baseaddr=NULL, *pi_fnum=NULL, *pi_type=NULL, *pi_qty=NULL;
1684 proto_tree *fastmsg_tag_tree=NULL, *fmdata_dig_tree=NULL;
1685 uint32_t base_addr;
1686 uint16_t data_size, num_addr, cnt;
1687 uint8_t seq_cnt;
1688 bool seq_fir, seq_fin, save_fragmented;
1689 int payload_offset=0;
1690 fm_conversation *conv;
1691 fastmsg_dataitem *dataitem;
1692 tvbuff_t *data_tvb, *payload_tvb;
1694 /* Decode sequence byte components */
1695 seq_cnt = seq_byte & FAST_MSG_SEQ_CNT;
1696 seq_fir = ((seq_byte & FAST_MSG_SEQ_FIR) >> 7);
1697 seq_fin = ((seq_byte & FAST_MSG_SEQ_FIN) >> 6);
1699 base_addr = tvb_get_ntohl(tvb, offset); /* 32-bit field with base address to read */
1700 num_addr = tvb_get_ntohs(tvb, offset+4); /* 16-bit field with number of 16-bit addresses to read */
1702 /* Append Column Info w/ Base Address */
1703 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "%#x [%s]", base_addr, region_lookup(pinfo, base_addr));
1705 pi_baseaddr = proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_baseaddr, tvb, offset, 4, ENC_BIG_ENDIAN);
1706 proto_item_append_text(pi_baseaddr, " [%s]", region_lookup(pinfo, base_addr));
1708 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_numwords, tvb, offset+4, 2, ENC_BIG_ENDIAN);
1709 offset += 6;
1711 /* Setup a new tvb representing just the data payload of this particular message */
1712 data_tvb = tvb_new_subset_length(tvb, offset, (tvb_reported_length_remaining(tvb, offset)-2));
1714 save_fragmented = pinfo->fragmented;
1716 /* Check for fragmented packet by looking at the FIR and FIN bits */
1717 if (! (seq_fir && seq_fin)) {
1718 fragment_head *frag_msg;
1720 /* This is a fragmented packet, mark it as such */
1721 pinfo->fragmented = true;
1723 frag_msg = fragment_add_seq_next(&selfm_reassembly_table,
1724 data_tvb, 0, pinfo, 0, NULL,
1725 tvb_reported_length(data_tvb),
1726 !seq_fin);
1728 payload_tvb = process_reassembled_data(data_tvb, 0, pinfo,
1729 "Reassembled Data Response Payload", frag_msg, &selfm_frag_items,
1730 NULL, fastmsg_tree);
1732 if (payload_tvb) { /* Reassembled */
1733 /* We have the complete payload */
1734 col_append_sep_str(pinfo->cinfo, COL_INFO, NULL, "Reassembled Data Response");
1736 else
1738 /* We don't have the complete reassembled payload. */
1739 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "Response Data Fragment %u" , seq_cnt);
1744 /* No re-assembly required, setup the payload_tvb based on the single-frame data payload tvb */
1745 else {
1746 payload_tvb = data_tvb;
1747 add_new_data_source(pinfo, payload_tvb, "Data Response Payload");
1750 pinfo->fragmented = save_fragmented;
1752 /* If we had no need to re-assemble or this is the final packet of a reassembly, let's attempt to dissect the */
1753 /* data payload using any previously-captured data format information */
1754 if (payload_tvb) {
1756 /* Search for previously-encountered data format reference information to dissect the frame */
1757 conv = (fm_conversation *)p_get_proto_data(wmem_file_scope(), pinfo, proto_selfm, 0);
1759 if (conv) {
1760 /* Start at front of list and cycle through possible instances of multiple fastmsg_dataitem frames, looking for match */
1761 wmem_list_frame_t *frame = wmem_list_head(conv->fastmsg_dataitems);
1763 while (frame && (tvb_reported_length_remaining(payload_tvb, payload_offset) > 0)) {
1764 dataitem = (fastmsg_dataitem *)wmem_list_frame_data(frame);
1766 /* If the stored base address of the current data item matches the current base address of this response frame */
1767 /* mark that the config data was found and attempt further dissection */
1768 if (dataitem->base_address == base_addr) {
1770 /* Data Item size (in bytes) determined by data type and quantity within item */
1771 switch (dataitem->data_type) {
1772 case FAST_MSG_TAGTYPE_CHAR8:
1773 case FAST_MSG_TAGTYPE_DIGWORD8_BL:
1774 case FAST_MSG_TAGTYPE_DIGWORD8:
1775 data_size = 1 * dataitem->quantity; /* 1 byte per qty */
1776 break;
1777 case FAST_MSG_TAGTYPE_CHAR16:
1778 case FAST_MSG_TAGTYPE_DIGWORD16_BL:
1779 case FAST_MSG_TAGTYPE_DIGWORD16:
1780 case FAST_MSG_TAGTYPE_INT16:
1781 case FAST_MSG_TAGTYPE_UINT16:
1782 data_size = 2 * dataitem->quantity; /* 2 bytes per qty */
1783 break;
1784 case FAST_MSG_TAGTYPE_INT32:
1785 case FAST_MSG_TAGTYPE_UINT32:
1786 case FAST_MSG_TAGTYPE_FLOAT:
1787 data_size = 4 * dataitem->quantity; /* 4 bytes per qty */
1788 break;
1790 default:
1791 data_size = 0;
1792 break;
1795 fastmsg_tag_tree = proto_tree_add_subtree_format(fastmsg_tree, payload_tvb, payload_offset, data_size,
1796 ett_selfm_fastmsg_tag, NULL, "Data Item Name: %s", dataitem->name);
1798 /* Load some information from the stored Data Format Response message into the tree for reference */
1799 pi_fnum = proto_tree_add_uint_format(fastmsg_tag_tree, hf_selfm_fmdata_frame_data_format_reference, payload_tvb, payload_offset, data_size,
1800 dataitem->fnum, "Using frame number %d (Index Pos: %d) as Data Format Reference",dataitem->fnum, dataitem->index_pos );
1801 pi_type = proto_tree_add_uint(fastmsg_tag_tree, hf_selfm_fmdata_data_type, payload_tvb, payload_offset, 0, dataitem->data_type);
1802 pi_qty = proto_tree_add_uint(fastmsg_tag_tree, hf_selfm_fmdata_quantity, payload_tvb, payload_offset, 0, dataitem->quantity );
1804 proto_item_set_generated(pi_fnum);
1805 proto_item_set_generated(pi_type);
1806 proto_item_set_len(pi_type, data_size);
1807 proto_item_set_generated(pi_qty);
1808 proto_item_set_len(pi_qty, data_size);
1810 /* Data Item Type determines how to decode */
1811 switch (dataitem->data_type) {
1813 case FAST_MSG_TAGTYPE_DIGWORD8_BL:
1814 case FAST_MSG_TAGTYPE_DIGWORD8:
1816 for (cnt=1; cnt <= dataitem->quantity; cnt++) {
1818 fmdata_dig_tree = proto_tree_add_subtree_format(fastmsg_tag_tree, payload_tvb, payload_offset, 1,
1819 ett_selfm_fmdata_dig, &fmdata_dig_item, "8-bit Binary Items (Row: %2d)", cnt);
1821 /* Display the bit pattern on the digital channel proto_item */
1822 proto_item_append_text(fmdata_dig_item, " [ %d %d %d %d %d %d %d %d ]",
1823 ((tvb_get_uint8(payload_tvb, payload_offset) & 0x80) >> 7), ((tvb_get_uint8(payload_tvb, payload_offset) & 0x40) >> 6),
1824 ((tvb_get_uint8(payload_tvb, payload_offset) & 0x20) >> 5), ((tvb_get_uint8(payload_tvb, payload_offset) & 0x10) >> 4),
1825 ((tvb_get_uint8(payload_tvb, payload_offset) & 0x08) >> 3), ((tvb_get_uint8(payload_tvb, payload_offset) & 0x04) >> 2),
1826 ((tvb_get_uint8(payload_tvb, payload_offset) & 0x02) >> 1), (tvb_get_uint8(payload_tvb, payload_offset) & 0x01));
1828 proto_tree_add_item(fmdata_dig_tree, hf_selfm_fmdata_dig_b0, payload_tvb, payload_offset, 1, ENC_BIG_ENDIAN);
1829 proto_tree_add_item(fmdata_dig_tree, hf_selfm_fmdata_dig_b1, payload_tvb, payload_offset, 1, ENC_BIG_ENDIAN);
1830 proto_tree_add_item(fmdata_dig_tree, hf_selfm_fmdata_dig_b2, payload_tvb, payload_offset, 1, ENC_BIG_ENDIAN);
1831 proto_tree_add_item(fmdata_dig_tree, hf_selfm_fmdata_dig_b3, payload_tvb, payload_offset, 1, ENC_BIG_ENDIAN);
1832 proto_tree_add_item(fmdata_dig_tree, hf_selfm_fmdata_dig_b4, payload_tvb, payload_offset, 1, ENC_BIG_ENDIAN);
1833 proto_tree_add_item(fmdata_dig_tree, hf_selfm_fmdata_dig_b5, payload_tvb, payload_offset, 1, ENC_BIG_ENDIAN);
1834 proto_tree_add_item(fmdata_dig_tree, hf_selfm_fmdata_dig_b6, payload_tvb, payload_offset, 1, ENC_BIG_ENDIAN);
1835 proto_tree_add_item(fmdata_dig_tree, hf_selfm_fmdata_dig_b7, payload_tvb, payload_offset, 1, ENC_BIG_ENDIAN);
1837 payload_offset += 1;
1841 break;
1843 case FAST_MSG_TAGTYPE_CHAR8:
1844 case FAST_MSG_TAGTYPE_CHAR16:
1845 proto_tree_add_item(fastmsg_tag_tree, hf_selfm_fmdata_ai_value_string, payload_tvb, payload_offset, data_size, ENC_ASCII);
1846 payload_offset += data_size;
1847 break;
1849 case FAST_MSG_TAGTYPE_INT16:
1850 for (cnt=1; cnt <= dataitem->quantity; cnt++) {
1851 fastmsg_tag_value_item = proto_tree_add_item(fastmsg_tag_tree, hf_selfm_fastmsg_dataitem_int16, payload_tvb, payload_offset, data_size/dataitem->quantity, ENC_BIG_ENDIAN);
1852 proto_item_prepend_text(fastmsg_tag_value_item, "Value %d ", cnt);
1853 payload_offset += data_size/dataitem->quantity;
1855 break;
1857 case FAST_MSG_TAGTYPE_UINT16:
1858 for (cnt=1; cnt <= dataitem->quantity; cnt++) {
1859 fastmsg_tag_value_item = proto_tree_add_item(fastmsg_tag_tree, hf_selfm_fastmsg_dataitem_uint16, payload_tvb, payload_offset, data_size/dataitem->quantity, ENC_BIG_ENDIAN);
1860 proto_item_prepend_text(fastmsg_tag_value_item, "Value %d ", cnt);
1861 payload_offset += data_size/dataitem->quantity;
1863 break;
1865 case FAST_MSG_TAGTYPE_INT32:
1866 for (cnt=1; cnt <= dataitem->quantity; cnt++) {
1867 fastmsg_tag_value_item = proto_tree_add_item(fastmsg_tag_tree, hf_selfm_fastmsg_dataitem_int32, payload_tvb, payload_offset, data_size/dataitem->quantity, ENC_BIG_ENDIAN);
1868 proto_item_prepend_text(fastmsg_tag_value_item, "Value %d ", cnt);
1869 payload_offset += data_size/dataitem->quantity;
1871 break;
1873 case FAST_MSG_TAGTYPE_UINT32:
1874 for (cnt=1; cnt <= dataitem->quantity; cnt++) {
1875 fastmsg_tag_value_item = proto_tree_add_item(fastmsg_tag_tree, hf_selfm_fastmsg_dataitem_uint32, payload_tvb, payload_offset, data_size/dataitem->quantity, ENC_BIG_ENDIAN);
1876 proto_item_prepend_text(fastmsg_tag_value_item, "Value %d ", cnt);
1877 payload_offset += data_size/dataitem->quantity;
1879 break;
1881 case FAST_MSG_TAGTYPE_FLOAT:
1882 for (cnt=1; cnt <= dataitem->quantity; cnt++) {
1883 fastmsg_tag_value_item = proto_tree_add_item(fastmsg_tag_tree, hf_selfm_fastmsg_dataitem_float, payload_tvb, payload_offset, data_size/dataitem->quantity, ENC_BIG_ENDIAN);
1884 proto_item_prepend_text(fastmsg_tag_value_item, "Value %d ", cnt);
1885 payload_offset += data_size/dataitem->quantity;
1887 break;
1889 default:
1890 break;
1891 } /* data item type switch */
1893 } /* base address is correct */
1895 /* After processing this frame/data item, proceed to the next */
1896 frame = wmem_list_frame_next(frame);
1898 } /* while (frame) */
1900 } /* if (conv) found */
1902 } /* if payload_tvb */
1904 /* Update the offset field before we leave this frame */
1905 offset += num_addr*2;
1907 return offset;
1912 /******************************************************************************************************/
1913 /* Code to dissect Fast Message Frames */
1914 /******************************************************************************************************/
1915 static int
1916 dissect_fastmsg_frame(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, int offset)
1918 /* Set up structures needed to add the protocol subtree and manage it */
1919 proto_item *fastmsg_def_fc_item, *fastmsg_elementlist_item;
1920 proto_item *pi_baseaddr, *fastmsg_crc16_item;
1921 proto_tree *fastmsg_tree, *fastmsg_def_fc_tree=NULL, *fastmsg_elementlist_tree=NULL;
1922 proto_tree *fastmsg_element_tree=NULL, *fastmsg_datareg_tree=NULL, *fastmsg_tag_tree=NULL, *fastmsg_soeblk_tree=NULL;
1923 int cnt, cnt1, num_elements, elmt_status32_ofs=0, elmt_status, null_offset;
1924 uint8_t len, funccode, seq=0, rx_num_fc, tx_num_fc;
1925 uint8_t seq_cnt=0, elmt_idx, fc_enable, soe_num_reg;
1926 uint8_t *tag_name_ptr;
1927 uint16_t base_addr, num_addr, num_reg, addr1, addr2, crc16, crc16_calc, soe_num_blks;
1928 uint32_t tod_ms, elmt_status32, elmt_ts_offset;
1929 static int * const seq_fields[] = {
1930 &hf_selfm_fastmsg_seq_fir,
1931 &hf_selfm_fastmsg_seq_fin,
1932 &hf_selfm_fastmsg_seq_cnt,
1933 NULL
1936 len = tvb_get_uint8(tvb, offset);
1938 fastmsg_tree = proto_tree_add_subtree(tree, tvb, offset, len-2, ett_selfm_fastmsg, NULL, "Fast Message Details");
1940 /* Reported length */
1941 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_len, tvb, offset, 1, ENC_BIG_ENDIAN);
1943 /* 5-byte Future Routing Address */
1944 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_routing_addr, tvb, offset+1, 5, ENC_NA);
1945 offset += 6;
1947 /* Add Status Byte to tree */
1948 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_status, tvb, offset, 1, ENC_BIG_ENDIAN);
1949 offset += 1;
1951 /* Get Function Code, add to tree */
1952 funccode = tvb_get_uint8(tvb, offset);
1953 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_funccode, tvb, offset, 1, ENC_BIG_ENDIAN);
1955 /* Append Column Info w/ Function Code */
1956 col_append_sep_str(pinfo->cinfo, COL_INFO, NULL, val_to_str_ext_const(funccode, &selfm_fastmsg_func_code_vals_ext, "Unknown Function Code"));
1958 offset += 1;
1960 /* If this is an ACK message, process this byte as a Response Code. */
1961 if ((funccode == FAST_MSG_EN_UNS_DATA_ACK) ||
1962 (funccode == FAST_MSG_DIS_UNS_DATA_ACK) ||
1963 (funccode == FAST_MSG_UNS_RESP_ACK)) {
1964 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_response_code, tvb, offset, 1, ENC_BIG_ENDIAN);
1967 else {
1968 /* Otherwise, it is the sequence byte, add to Tree */
1969 seq = tvb_get_uint8(tvb, offset);
1970 seq_cnt = seq & FAST_MSG_SEQ_CNT;
1971 proto_tree_add_bitmask_with_flags(fastmsg_tree, tvb, offset, hf_selfm_fastmsg_seq, ett_selfm_fastmsg_seq,
1972 seq_fields, ENC_NA, BMT_NO_APPEND);
1975 offset += 1;
1977 /* Add Response Number to tree */
1978 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_resp_num, tvb, offset, 1, ENC_BIG_ENDIAN);
1979 offset += 1;
1981 /* Depending on Function Code used, remaining section of packet will be handled differently. */
1982 switch (funccode) {
1984 case FAST_MSG_EN_UNS_DATA: /* 0x01 - Enabled Unsolicited Data Transfers */
1986 /* Function code to enable */
1987 fc_enable = tvb_get_uint8(tvb, offset);
1988 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_uns_en_fc, tvb, offset, 1, ENC_BIG_ENDIAN);
1990 /* Append Column Info w/ "Enable" Function Code */
1991 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "Function to Enable (%#x)", fc_enable);
1993 /* 3-byte Function Code data */
1994 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_uns_en_fc_data, tvb, offset+1, 3, ENC_NA);
1996 offset += 4;
1998 break;
2000 case FAST_MSG_DIS_UNS_DATA: /* 0x02 - Disable Unsolicited Data Transfers */
2002 /* Function code to disable */
2003 fc_enable = tvb_get_uint8(tvb, offset);
2004 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_uns_dis_fc, tvb, offset, 1, ENC_BIG_ENDIAN);
2006 /* Append Column Info w/ "Disable" Function Code */
2007 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "Function to Disable (%#x)", fc_enable);
2009 /* 1-byte Function Code data */
2010 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_uns_dis_fc_data, tvb, offset+1, 1, ENC_NA);
2012 offset += 2;
2014 break;
2017 case FAST_MSG_READ_REQ: /* 0x10 - Read Request */
2019 base_addr = tvb_get_ntohl(tvb, offset); /* 32-bit field with base address to read */
2021 /* Append Column Info w/ Base Address */
2022 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "%#x [%s]", base_addr, region_lookup(pinfo, base_addr));
2024 pi_baseaddr = proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_baseaddr, tvb, offset, 4, ENC_BIG_ENDIAN);
2025 proto_item_append_text(pi_baseaddr, " [%s]", region_lookup(pinfo, base_addr));
2027 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_numwords, tvb, offset+4, 2, ENC_BIG_ENDIAN);
2028 offset += 6;
2029 break;
2031 case FAST_MSG_GEN_UNS_DATA: /* 0x12 - Generic Unsolicited Data */
2033 num_addr = len - 14; /* 12 header bytes + 2-byte CRC, whatever is left is the data portion of this message */
2034 num_reg = num_addr / 2;
2036 /* For the number of registers, step through and retrieve/print each 16-bit component */
2037 for (cnt=0; cnt < num_reg; cnt++) {
2038 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_unswrite_reg_val, tvb, offset, 2, ENC_BIG_ENDIAN);
2039 offset += 2;
2042 break;
2044 case FAST_MSG_SOE_STATE_REQ: /* 0x16 - SOE Present State Request */
2046 /* 4 bytes - "Origination Path" */
2047 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_soe_req_orig, tvb, offset, 4, ENC_NA);
2048 offset += 4;
2050 break;
2052 case FAST_MSG_UNS_RESP: /* 0x18 - Unsolicited Fast SER Data Response */
2054 /* 4 bytes - "Origination Path" */
2055 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_unsresp_orig, tvb, offset, 4, ENC_NA);
2056 offset += 4;
2058 /* Timestamp: 2-byte day-of-year, 2-byte year, 4-byte time-of-day in milliseconds */
2059 /* XXX - We can use a built-in function to convert the tod_ms to a readable time format, is there anything for day_of_year? */
2060 tod_ms = tvb_get_ntohl(tvb, offset+4);
2062 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_unsresp_doy, tvb, offset, 2, ENC_BIG_ENDIAN);
2063 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_unsresp_year, tvb, offset+2, 2, ENC_BIG_ENDIAN);
2064 proto_tree_add_uint_format_value(fastmsg_tree, hf_selfm_fastmsg_unsresp_todms, tvb, offset+4, 4,
2065 tod_ms, "%s", signed_time_msecs_to_str(pinfo->pool, tod_ms));
2066 offset += 8;
2068 /* Build element tree */
2069 /* Determine the number of elements returned in this unsolicited message */
2070 /* The general formula is: (Length - 34) / 4 */
2071 num_elements = (len-34) / 4;
2073 fastmsg_elementlist_item = proto_tree_add_uint(fastmsg_tree, hf_selfm_fastmsg_unsresp_num_elmt, tvb, offset, (4*num_elements), num_elements);
2074 fastmsg_elementlist_tree = proto_item_add_subtree(fastmsg_elementlist_item, ett_selfm_fastmsg_element_list);
2076 /* "Reported New Status" word for up to 32 index elements is following the upcoming 0xFFFFFFFE End-of-record indicator
2077 Search for that indicator and use the detected tvb offset+4 to retrieve the proper 32-bit status word.
2078 Save this word for use in the element index printing but don't print the word itself until the end of the tree dissection */
2079 for (cnt = offset; cnt < len; cnt++) {
2081 if (tvb_memeql(tvb, cnt, (const uint8_t*)"\xFF\xFF\xFF\xFE", 4) == 0) {
2082 elmt_status32_ofs = cnt+4;
2085 elmt_status32 = tvb_get_ntohl(tvb, elmt_status32_ofs );
2087 /* Cycle through each element we have detected that exists in the SER record */
2088 for (cnt=0; cnt<num_elements; cnt++) {
2090 /* Get Element Index and Timestamp Offset (in uSec) */
2091 elmt_idx = tvb_get_uint8(tvb, offset);
2092 elmt_ts_offset = (uint32_t)((tvb_get_uint8(tvb, offset+1) << 16) | (tvb_get_uint8(tvb, offset+2) << 8) | (tvb_get_uint8(tvb, offset+3)));
2094 /* Bit shift the appropriate element from the 32-bit elmt_status word to position 0 and get the bit state for use in the tree */
2095 elmt_status = ((elmt_status32 >> cnt) & 0x01);
2097 /* Build the tree */
2098 fastmsg_element_tree = proto_tree_add_subtree_format(fastmsg_elementlist_tree, tvb, offset, 4, ett_selfm_fastmsg_element, NULL,
2099 "Reported Event %d (Index: %d [%s], New State: %s)", cnt+1, elmt_idx, fastser_uns_wordbit_lookup(pinfo, elmt_idx),
2100 val_to_str_const(elmt_status, selfm_ser_status_vals, "Unknown"));
2102 /* Add Index Number and Timestamp offset to tree */
2103 proto_tree_add_item(fastmsg_element_tree, hf_selfm_fastmsg_unsresp_elmt_idx, tvb, offset, 1, ENC_BIG_ENDIAN);
2104 proto_tree_add_item(fastmsg_element_tree, hf_selfm_fastmsg_unsresp_elmt_ts_ofs, tvb, offset+1, 3, ENC_BIG_ENDIAN);
2105 proto_tree_add_uint_format_value(fastmsg_element_tree, hf_selfm_fastmsg_unsresp_elmt_ts_ofs_decoded, tvb, offset+1, 3,
2106 tod_ms + (elmt_ts_offset/1000), "%s", signed_time_msecs_to_str(pinfo->pool, tod_ms + (elmt_ts_offset/1000)));
2107 proto_tree_add_uint(fastmsg_element_tree, hf_selfm_fastmsg_unsresp_elmt_status, tvb, elmt_status32_ofs, 4, elmt_status);
2109 offset += 4;
2113 /* 4-byte End-of-Record Terminator 0xFFFFFFFE */
2114 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_unsresp_eor, tvb, offset, 4, ENC_NA);
2115 offset += 4;
2117 /* 4-byte Element Status word */
2118 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_unsresp_elmt_statword, tvb, offset, 4, ENC_BIG_ENDIAN);
2119 offset += 4;
2121 break;
2124 case FAST_MSG_UNS_WRITE: /* 0x20 - Unsolicited Write */
2126 /* Write Address Region #1 and #2, along with number of 16-bit registers */
2127 addr1 = tvb_get_ntohs(tvb, offset);
2128 addr2 = tvb_get_ntohs(tvb, offset+2);
2129 num_reg = tvb_get_ntohs(tvb, offset+4);
2131 /* Append Column Info w/ Address Information */
2132 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "%#x, %#x", addr1, addr2);
2134 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_unswrite_addr1, tvb, offset, 2, ENC_BIG_ENDIAN);
2135 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_unswrite_addr2, tvb, offset+2, 2, ENC_BIG_ENDIAN);
2136 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_unswrite_num_reg, tvb, offset+4, 2, ENC_BIG_ENDIAN);
2138 offset += 6;
2140 /* For the number of registers, step through and retrieve/print each 16-bit component */
2141 for (cnt=0; cnt < num_reg; cnt++) {
2142 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_unswrite_reg_val, tvb, offset, 2, ENC_BIG_ENDIAN);
2143 offset += 2;
2146 break;
2148 case FAST_MSG_DATAFMT_REQ: /* 0x31 - Data Format Request */
2150 base_addr = tvb_get_ntohl(tvb, offset); /* 32-bit field with base address to read */
2152 /* Append Column Info w/ Base Address */
2153 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "%#x [%s]", base_addr, region_lookup(pinfo, base_addr));
2155 /* Add Base Address to Tree */
2156 pi_baseaddr = proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_baseaddr, tvb, offset, 4, ENC_BIG_ENDIAN);
2157 proto_item_append_text(pi_baseaddr, " [%s]", region_lookup(pinfo, base_addr));
2159 offset += 4;
2161 break;
2163 case FAST_MSG_BITLABEL_REQ: /* 0x33 - Bit Label Request */
2165 base_addr = tvb_get_ntohl(tvb, offset); /* 32-bit field with base address to read */
2166 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_baseaddr, tvb, offset, 4, ENC_BIG_ENDIAN);
2167 offset += 4;
2169 /* Append Column Info w/ Base Address */
2170 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "%#x", base_addr);
2172 break;
2175 case FAST_MSG_CFG_BLOCK_RESP: /* 0x80 (resp to 0x00) - Fast Message Configuration Block Response */
2177 /* Routing Support */
2178 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_def_route_sup, tvb, offset, 1, ENC_BIG_ENDIAN);
2179 offset += 1;
2181 /* RX / TX Status */
2182 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_def_rx_stat, tvb, offset, 1, ENC_BIG_ENDIAN);
2183 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_def_tx_stat, tvb, offset+1, 1, ENC_BIG_ENDIAN);
2184 offset += 2;
2186 /* Max Frames RX/TX */
2187 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_def_rx_maxfr, tvb, offset, 1, ENC_BIG_ENDIAN);
2188 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_def_tx_maxfr, tvb, offset+1, 1, ENC_BIG_ENDIAN);
2189 offset += 2;
2191 /* 6 bytes of reserved space */
2192 offset += 6;
2194 /* Number of Supported RX Function Codes */
2195 rx_num_fc = tvb_get_uint8(tvb, offset);
2196 fastmsg_def_fc_item = proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_def_rx_num_fc, tvb, offset, 1, ENC_BIG_ENDIAN);
2197 fastmsg_def_fc_tree = proto_item_add_subtree(fastmsg_def_fc_item, ett_selfm_fastmsg_def_fc);
2198 offset += 1;
2200 /* Add Supported RX Function Codes to tree */
2201 for (cnt=0; cnt<rx_num_fc; cnt++) {
2202 proto_tree_add_item(fastmsg_def_fc_tree, hf_selfm_fastmsg_def_rx_fc, tvb, offset, 1, ENC_BIG_ENDIAN);
2203 offset += 2;
2206 /* Number of Supported TX Function Codes */
2207 tx_num_fc = tvb_get_uint8(tvb, offset);
2208 fastmsg_def_fc_item = proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_def_tx_num_fc, tvb, offset, 1, ENC_BIG_ENDIAN);
2209 fastmsg_def_fc_tree = proto_item_add_subtree(fastmsg_def_fc_item, ett_selfm_fastmsg_def_fc);
2210 offset += 1;
2212 /* Add Supported TX Function Codes to tree */
2213 for (cnt=0; cnt<tx_num_fc; cnt++) {
2214 proto_tree_add_item(fastmsg_def_fc_tree, hf_selfm_fastmsg_def_tx_fc, tvb, offset, 1, ENC_BIG_ENDIAN);
2215 offset += 2;
2218 break;
2220 case FAST_MSG_READ_RESP: /* 0x90 (resp to 0x10) - Read Response */
2222 offset = dissect_fastmsg_readresp_frame( tvb, fastmsg_tree, pinfo, offset, seq);
2224 break;
2226 case FAST_MSG_SOE_STATE_RESP: /* 0x96 - (resp to 0x16) SOE Present State Response */
2228 /* 16-bit field with number of blocks of present state data */
2229 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_soe_resp_numblks, tvb, offset, 2, ENC_BIG_ENDIAN);
2230 soe_num_blks = tvb_get_ntohs(tvb, offset);
2231 offset += 2;
2233 /* Loop through each one of these block based on the num_blocks */
2234 for (cnt=0; cnt<soe_num_blks; cnt++) {
2236 /* Blocks of 16 bits are packed into 16-bit registers, with any remainder into a final 16-bit register */
2237 if ((tvb_get_uint8(tvb, offset+4) % 16) == 0) {
2238 soe_num_reg = (tvb_get_uint8(tvb, offset+4) / 16);
2240 else {
2241 soe_num_reg = (tvb_get_uint8(tvb, offset+4) / 16) + 1;
2244 fastmsg_soeblk_tree = proto_tree_add_subtree_format(fastmsg_tree, tvb, offset, 14 + soe_num_reg*2,
2245 ett_selfm_fastmsg_soeblk, NULL, "Data Block #%d", cnt+1);
2247 proto_tree_add_item(fastmsg_soeblk_tree, hf_selfm_fastmsg_soe_resp_orig, tvb, offset, 4, ENC_NA);
2248 proto_tree_add_item(fastmsg_soeblk_tree, hf_selfm_fastmsg_soe_resp_numbits, tvb, offset+4, 1, ENC_BIG_ENDIAN);
2249 proto_tree_add_item(fastmsg_soeblk_tree, hf_selfm_fastmsg_soe_resp_pad, tvb, offset+5, 1, ENC_BIG_ENDIAN);
2250 proto_tree_add_item(fastmsg_soeblk_tree, hf_selfm_fastmsg_soe_resp_doy, tvb, offset+6, 2, ENC_BIG_ENDIAN);
2251 proto_tree_add_item(fastmsg_soeblk_tree, hf_selfm_fastmsg_soe_resp_year, tvb, offset+8, 2, ENC_BIG_ENDIAN);
2252 proto_tree_add_item(fastmsg_soeblk_tree, hf_selfm_fastmsg_soe_resp_tod, tvb, offset+10, 4, ENC_BIG_ENDIAN);
2253 offset += 14;
2255 for (cnt1=0; cnt1<soe_num_reg; cnt1++) {
2256 proto_tree_add_item(fastmsg_soeblk_tree, hf_selfm_fastmsg_soe_resp_data, tvb, offset, 2, ENC_BIG_ENDIAN);
2257 offset += 2;
2261 break;
2263 case FAST_MSG_DEVDESC_RESP: /* 0xB0 (resp to 0x30) - Device Description Response */
2265 /* Add FID / RID ASCII data to tree */
2266 proto_tree_add_item(fastmsg_tree, hf_selfm_fid, tvb, offset, 50, ENC_ASCII);
2267 proto_tree_add_item(fastmsg_tree, hf_selfm_rid, tvb, offset+50, 40, ENC_ASCII);
2268 offset += 90;
2270 /* 16-bit field with number of data areas */
2271 num_reg = tvb_get_ntohs(tvb, offset);
2272 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_devdesc_num_region, tvb, offset, 2, ENC_BIG_ENDIAN);
2273 offset += 2;
2275 /* Maximum size of 7 regions per message, check the seq_cnt to determine if we have stepped into
2276 the next sequential message where the remaining regions would be described */
2277 if ((num_reg >= 8) && (seq_cnt == 0)) {
2278 num_reg = 7;
2280 else{
2281 num_reg = num_reg - (seq_cnt * 7);
2284 /* 16-bit field with number of control areas */
2285 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_devdesc_num_ctrl, tvb, offset, 2, ENC_BIG_ENDIAN);
2286 offset += 2;
2288 /* Each 18-byte data area description has a 10 byte region name, followed by 32-bit base, */
2289 /* 16-bit message word count and 16-bit flag field */
2290 for (cnt=0; cnt<num_reg; cnt++) {
2292 fastmsg_datareg_tree = proto_tree_add_subtree_format(fastmsg_tree, tvb, offset, 18,
2293 ett_selfm_fastmsg_datareg, NULL, "Fast Message Data Region #%d", cnt+1);
2295 /* 10-Byte Region description */
2296 proto_tree_add_item(fastmsg_datareg_tree, hf_selfm_fastmsg_data_region_name, tvb, offset, 10, ENC_ASCII);
2297 offset += 10;
2299 /* 32-bit field with base address of data region */
2300 proto_tree_add_item(fastmsg_datareg_tree, hf_selfm_fastmsg_baseaddr, tvb, offset, 4, ENC_BIG_ENDIAN);
2301 offset += 4;
2303 /* 16-bit field with number of 16-bit words in region */
2304 proto_tree_add_item(fastmsg_datareg_tree, hf_selfm_fastmsg_numwords, tvb, offset, 2, ENC_BIG_ENDIAN);
2305 offset += 2;
2307 /* 16-bit flag field */
2308 proto_tree_add_item(fastmsg_datareg_tree, hf_selfm_fastmsg_flags, tvb, offset, 2, ENC_BIG_ENDIAN);
2309 offset += 2;
2313 /* Some relays (4xx) don't follow the standard here and include an 8-byte sequence of all 0x00's to represent */
2314 /* 'reserved' space for the control regions. Detect these and skip if they are present */
2315 if (tvb_reported_length_remaining(tvb, offset) > 2) {
2317 if (tvb_memeql(tvb, offset, (const uint8_t*)"\x00\x00\x00\x00\x00\x00\x00\x00", 8) == 0) {
2318 offset += 8;
2322 break;
2324 case FAST_MSG_DATAFMT_RESP: /* 0xB1 (resp to 0x31) - Data Format Response */
2326 base_addr = tvb_get_ntohl(tvb, offset); /* 32-bit field with base address to read */
2328 /* Add Base Address to Tree */
2329 pi_baseaddr = proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_baseaddr, tvb, offset, 4, ENC_BIG_ENDIAN);
2330 proto_item_append_text(pi_baseaddr, " [%s]", region_lookup(pinfo, base_addr));
2332 offset += 4;
2334 /* Append Column Info w/ Base Address */
2335 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "%#x [%s]", base_addr, region_lookup(pinfo, base_addr));
2337 /* 16-bit field with number of data items to follow */
2338 proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_datafmt_resp_numitem, tvb, offset, 2, ENC_BIG_ENDIAN);
2339 offset += 2;
2341 while ((tvb_reported_length_remaining(tvb, offset)) > 2) {
2342 /* Data Item record name 10 bytes */
2343 tag_name_ptr = tvb_get_string_enc(pinfo->pool, tvb, offset, 10, ENC_ASCII);
2344 fastmsg_tag_tree = proto_tree_add_subtree_format(fastmsg_tree, tvb, offset, 14, ett_selfm_fastmsg_tag, NULL, "Data Item Record Name: %s", tag_name_ptr);
2346 /* Data item qty and type */
2347 proto_tree_add_item(fastmsg_tag_tree, hf_selfm_fastmsg_dataitem_qty, tvb, offset+10, 2, ENC_BIG_ENDIAN);
2348 proto_tree_add_item(fastmsg_tag_tree, hf_selfm_fastmsg_dataitem_type, tvb, offset+12, 2, ENC_BIG_ENDIAN);
2350 offset += 14;
2352 break;
2354 case FAST_MSG_BITLABEL_RESP: /* 0xB3 (resp to 0x33) - Bit Label Response */
2356 /* The data in this response is a variable length string containing the names of 8 digital bits. */
2357 /* Each name is max 8 chars and each is null-separated */
2358 cnt=1;
2360 /* find the null separators and add the bit label text strings to the tree */
2361 for (null_offset = offset; null_offset < len; null_offset++) {
2362 if ((tvb_memeql(tvb, null_offset, (const uint8_t*)"\x00", 1) == 0) && (tvb_reported_length_remaining(tvb, offset) > 2)) {
2363 char* str = tvb_format_text(pinfo->pool, tvb, offset, (null_offset-offset));
2364 proto_tree_add_string_format(fastmsg_tree, hf_selfm_fastmsg_bit_label_name, tvb, offset, (null_offset-offset), str,
2365 "Bit Label #%d Name: %s", cnt, str);
2366 offset = null_offset+1; /* skip the null */
2367 cnt++;
2371 break;
2373 default:
2374 break;
2375 } /* func_code */
2377 /* Add CRC16 to Tree */
2378 fastmsg_crc16_item = proto_tree_add_item(fastmsg_tree, hf_selfm_fastmsg_crc16, tvb, offset, 2, ENC_BIG_ENDIAN);
2379 crc16 = tvb_get_ntohs(tvb, offset);
2380 offset += 2;
2382 /* If option is enabled, validate the CRC16 */
2383 if (selfm_crc16) {
2384 crc16_calc = crc16_plain_tvb_offset_seed(tvb, 0, len-2, 0xFFFF);
2385 if (crc16_calc != crc16) {
2386 expert_add_info_format(pinfo, fastmsg_crc16_item, &ei_selfm_crc16_incorrect, "Incorrect CRC - should be 0x%04x", crc16_calc);
2388 else {
2389 proto_item_append_text(fastmsg_crc16_item, " [OK]");
2394 return offset;
2399 /******************************************************************************************************/
2400 /* Code to dissect SEL Fast Message Protocol packets */
2401 /* Will call other sub-dissectors, as needed */
2402 /******************************************************************************************************/
2403 static int
2404 dissect_selfm(tvbuff_t *selfm_tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
2406 /* Set up structures needed to add the protocol subtree and manage it */
2407 proto_item *selfm_item=NULL;
2408 proto_tree *selfm_tree=NULL;
2409 int offset=0, cnt=0, consumed_bytes=0;
2410 uint32_t base_addr;
2411 uint16_t msg_type, len, num_items;
2412 uint8_t seq, seq_cnt;
2413 char **uns_ser_split_str;
2415 /* Make entries in Protocol column on summary display */
2416 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SEL Protocol");
2417 col_clear(pinfo->cinfo, COL_INFO);
2419 len = tvb_reported_length(selfm_tvb);
2421 msg_type = tvb_get_ntohs(selfm_tvb, offset);
2423 /* On first pass through the packets we have 4 tasks to complete - they are each noted below */
2424 if (!pinfo->fd->visited) {
2425 conversation_t *conversation;
2426 fm_conversation *fm_conv_data;
2428 /* Find a conversation, create a new if no one exists */
2429 conversation = find_or_create_conversation(pinfo);
2431 fm_conv_data = (fm_conversation *)conversation_get_proto_data(conversation, proto_selfm);
2433 if (fm_conv_data == NULL) {
2434 fm_conv_data = wmem_new(wmem_file_scope(), fm_conversation);
2435 fm_conv_data->fm_config_frames = wmem_list_new(wmem_file_scope());
2436 fm_conv_data->fastmsg_dataitems = wmem_list_new(wmem_file_scope());
2437 fm_conv_data->fastmsg_dataregions = wmem_tree_new(wmem_file_scope());
2438 fm_conv_data->fastser_uns_wordbits = wmem_tree_new(wmem_file_scope());
2439 conversation_add_proto_data(conversation, proto_selfm, (void *)fm_conv_data);
2441 uns_ser_split_str = wmem_strsplit(pinfo->pool, selfm_ser_list, ",", -1);
2443 for (cnt = 0; (uns_ser_split_str[cnt] != NULL); cnt++) {
2444 fastser_uns_wordbit *wordbit_ptr = fastser_uns_wordbit_save(cnt, uns_ser_split_str[cnt]);
2445 wmem_tree_insert32(fm_conv_data->fastser_uns_wordbits, cnt, wordbit_ptr);
2448 /* Power Up (254) and Settings Changed (255) Indexes */
2449 for (cnt = 254; (cnt <= 255); cnt++) {
2450 fastser_uns_wordbit *wordbit_ptr = fastser_uns_wordbit_save(cnt, "unused");
2451 wmem_tree_insert32(fm_conv_data->fastser_uns_wordbits, cnt, wordbit_ptr);
2455 p_add_proto_data(wmem_file_scope(), pinfo, proto_selfm, 0, fm_conv_data);
2457 /* 1. Configuration frames (0xA5C1, 0xA5C2, 0xA5C3) need special treatment during the first run */
2458 /* For each Fast Meter Configuration frame (0xA5Cx), a 'fm_config_frame' struct is created to hold the */
2459 /* information necessary to decode subsequent matching Fast Meter Data frames (0xA5Dx). A pointer to */
2460 /* this struct is saved in the conversation and is copied to the per-packet information if a */
2461 /* Fast Meter Data frame is dissected. */
2462 if ((CMD_FM_CONFIG == msg_type) || (CMD_DFM_CONFIG == msg_type) || (CMD_PDFM_CONFIG == msg_type)) {
2463 /* Fill the fm_config_frame */
2464 fm_config_frame *frame_ptr = fmconfig_frame_fast(selfm_tvb);
2465 frame_ptr->fnum = pinfo->num;
2466 wmem_list_prepend(fm_conv_data->fm_config_frames, frame_ptr);
2469 /* 2. Fill conversation data array with Fast Msg Data Item info from Data Format Response Messages. */
2470 /* These format definitions will later be retrieved to decode Read Response messages. */
2471 if ((CMD_FAST_MSG == msg_type) && (tvb_get_uint8(selfm_tvb, offset+9) == FAST_MSG_DATAFMT_RESP)) {
2473 seq = tvb_get_uint8(selfm_tvb, offset+10);
2474 seq_cnt = seq & FAST_MSG_SEQ_CNT;
2476 base_addr = tvb_get_ntohl(selfm_tvb, offset+12); /* 32-bit field with base address to read */
2477 num_items = tvb_get_ntohs(selfm_tvb, offset+16);
2479 /* When dealing with Data Format Response messages, there are a maximum of 16 items per frame */
2480 /* Use the sequence count if we have more 16 items to determine how many to expect in each frame */
2481 if ((num_items > 16) && (seq_cnt == 0)) {
2482 num_items = 16;
2484 else {
2485 num_items = num_items - (seq_cnt * 16);
2488 /* Set offset to start of data items */
2489 offset = 18;
2491 /* Enter the single frame multiple times, retrieving a single dataitem per entry */
2492 for (cnt = 1; (cnt <= num_items); cnt++) {
2493 fastmsg_dataitem *dataitem_ptr = fastmsg_dataitem_save(selfm_tvb, offset);
2494 dataitem_ptr->fnum = pinfo->num;
2495 dataitem_ptr->base_address = base_addr;
2496 dataitem_ptr->index_pos = cnt;
2498 /* Store the data item configuration info in the fastmsg_dataitems list */
2499 wmem_list_append(fm_conv_data->fastmsg_dataitems, dataitem_ptr);
2500 offset += 14;
2504 /* 3. Attempt re-assembly during first pass with Read Response Messages data payloads that span multiple */
2505 /* packets. The final data payload will be assembled on the packet with the seq_fin bit set. */
2506 if ((CMD_FAST_MSG == msg_type) && (tvb_get_uint8(selfm_tvb, offset+9) == FAST_MSG_READ_RESP)) {
2508 seq = tvb_get_uint8(selfm_tvb, offset+10);
2510 /* Set offset to where the dissect_fastmsg_readresp_frame function would normally be called, */
2511 /* right before base address & num_items */
2512 offset = 12;
2514 /* Call the same read response function that will be called during GUI dissection */
2515 offset = dissect_fastmsg_readresp_frame( selfm_tvb, tree, pinfo, offset, seq);
2517 /* Skip CRC16 */
2518 offset += 2;
2522 /* 4. Fill conversation data array with Fast Message Data Region info from Device Desc Response Messages. This */
2523 /* will retrieve a data region name (associated to an address) that can later be displayed in the tree. */
2524 if ((CMD_FAST_MSG == msg_type) && (tvb_get_uint8(selfm_tvb, offset+9) == FAST_MSG_DEVDESC_RESP)) {
2526 seq = tvb_get_uint8(selfm_tvb, offset+10);
2527 seq_cnt = seq & FAST_MSG_SEQ_CNT;
2529 num_items = tvb_get_ntohs(selfm_tvb, offset+102);
2531 /* When dealing with Device Description Response messages, there are a maximum of 7 regions per frame */
2532 /* Use the sequence count if we have more 7 items to determine how many to expect in each frame */
2533 if ((num_items >= 8) && (seq_cnt == 0)) {
2534 num_items = 7;
2536 else{
2537 num_items = num_items - (seq_cnt * 7);
2540 /* Set offset to start of data regions */
2541 offset = 106;
2543 /* Enter the single frame multiple times, retrieving a single data region per entry */
2544 for (cnt = 1; (cnt <= num_items); cnt++) {
2545 uint32_t base_address = tvb_get_ntohl(selfm_tvb, offset+10);
2546 fastmsg_dataregion *dataregion_ptr = fastmsg_dataregion_save(selfm_tvb, offset);
2548 /* Store the data region info in the fastmsg_dataregions tree */
2549 wmem_tree_insert32(fm_conv_data->fastmsg_dataregions, base_address, dataregion_ptr);
2550 offset += 18;
2553 offset = len;
2555 } /* if (!visited) */
2559 selfm_item = proto_tree_add_protocol_format(tree, proto_selfm, selfm_tvb, 0, len, "SEL Protocol");
2560 selfm_tree = proto_item_add_subtree(selfm_item, ett_selfm);
2562 /* Set INFO column with SEL Protocol Message Type */
2563 col_set_str(pinfo->cinfo, COL_INFO, val_to_str_ext_const(msg_type, &selfm_msgtype_vals_ext, "Unknown Message Type"));
2565 /* Add Message Type to Protocol Tree */
2566 proto_tree_add_item(selfm_tree, hf_selfm_msgtype, selfm_tvb, offset, 2, ENC_BIG_ENDIAN);
2567 offset += 2;
2568 consumed_bytes += 2;
2570 /* Determine correct message type and call appropriate dissector */
2571 if (tvb_reported_length_remaining(selfm_tvb, offset) > 0) {
2572 switch (msg_type) {
2573 case CMD_RELAY_DEF:
2574 consumed_bytes = dissect_relaydef_frame(selfm_tvb, selfm_tree, offset);
2575 break;
2576 case CMD_FM_CONFIG:
2577 case CMD_DFM_CONFIG:
2578 case CMD_PDFM_CONFIG:
2579 consumed_bytes = dissect_fmconfig_frame(selfm_tvb, selfm_tree, pinfo, offset);
2580 break;
2581 case CMD_FM_DATA:
2582 consumed_bytes = dissect_fmdata_frame(selfm_tvb, selfm_tree, pinfo, offset, CMD_FM_CONFIG);
2583 break;
2584 case CMD_DFM_DATA:
2585 consumed_bytes = dissect_fmdata_frame(selfm_tvb, selfm_tree, pinfo, offset, CMD_DFM_CONFIG);
2586 break;
2587 case CMD_PDFM_DATA:
2588 consumed_bytes = dissect_fmdata_frame(selfm_tvb, selfm_tree, pinfo, offset, CMD_PDFM_CONFIG);
2589 break;
2590 case CMD_FASTOP_CONFIG:
2591 consumed_bytes = dissect_foconfig_frame(selfm_tvb, selfm_tree, offset);
2592 break;
2593 case CMD_FAST_MSG:
2594 consumed_bytes = dissect_fastmsg_frame(selfm_tvb, selfm_tree, pinfo, offset);
2595 break;
2596 case CMD_FASTOP_RB_CTRL:
2597 case CMD_FASTOP_BR_CTRL:
2598 consumed_bytes = dissect_fastop_frame(selfm_tvb, selfm_tree, pinfo, offset);
2599 break;
2600 case CMD_ALT_FASTOP_CONFIG:
2601 consumed_bytes = dissect_alt_fastop_config_frame(selfm_tvb, selfm_tree, offset);
2602 break;
2603 case CMD_ALT_FASTOP_OPEN:
2604 case CMD_ALT_FASTOP_CLOSE:
2605 case CMD_ALT_FASTOP_SET:
2606 case CMD_ALT_FASTOP_CLEAR:
2607 case CMD_ALT_FASTOP_PULSE:
2608 consumed_bytes = dissect_alt_fastop_frame(selfm_tvb, selfm_tree, pinfo, offset);
2609 break;
2610 default:
2611 break;
2612 } /* msg_type */
2613 } /* remaining length > 0 */
2616 return consumed_bytes;
2619 /******************************************************************************************************/
2620 /* Dissect (and possibly re-assemble) SEL protocol payload data */
2621 /******************************************************************************************************/
2622 /* Since we are dealing with (usually) Telnet-encapsulated data with possible extra IAC bytes present,*/
2623 /* we cannot know the 'true' length of re-assembled TCP messages by just looking at the protocol PDU */
2624 /* header and it's included length byte. This precludes the use of tcp_dissect_pdus() and requires */
2625 /* us to do the reassembly efforts here. */
2626 /* The tvb structure is as follows: */
2627 /* tvb = original data tvb from TCP dissector */
2628 /* selfm_tvb = 'IAC-sanitized' (0xFF) version of tvb */
2629 /* selfm_pdu_tvb = with multiple PDUs in a single selfm_tvb, split them out for separate dissection */
2630 /* */
2631 /* tvb -> selfm_tvb -> selfm_pdu_tvb */
2632 /* -> selfm_pdu_tvb */
2633 /******************************************************************************************************/
2634 static int
2635 dissect_selfm_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
2638 tvbuff_t *selfm_tvb, *selfm_pdu_tvb;
2639 int skip_byte = 0, selfm_tvb_len, offset = 0;
2640 uint8_t selfm_PDU_len=0, new_selfm_PDU_len=0;
2641 int length = tvb_reported_length(tvb);
2643 /* Check for a SEL Protocol packet. It should begin with 0xA5 */
2644 if(length < 2 || tvb_get_uint8(tvb, 0) != 0xA5) {
2645 /* Not a SEL Protocol packet, just happened to use the same port */
2646 return 0;
2649 /* If the length of this packet is only 2 bytes, it's a scan message so just do a simple dissection */
2650 if (length == 2) {
2651 return dissect_selfm(tvb, pinfo, tree, data);
2654 selfm_PDU_len = tvb_get_uint8(tvb,2);
2656 /* If the reported selfm PDU length is greater than the present tvb length, request more data */
2657 if (length < selfm_PDU_len) {
2658 pinfo->desegment_offset = 0;
2659 pinfo->desegment_len = DESEGMENT_ONE_MORE_SEGMENT;
2660 return tvb_captured_length(tvb);
2663 /* If this is a Telnet-encapsulated Ethernet packet, let's clean out the IAC 0xFF instances */
2664 /* before we attempt any kind of re-assembly of the message */
2665 if ((pinfo->srcport) && selfm_telnet_clean) {
2666 selfm_tvb = clean_telnet_iac(pinfo, tvb, 0, length, &skip_byte);
2668 else {
2669 selfm_tvb = tvb_new_subset_length( tvb, 0, length);
2672 selfm_tvb_len = tvb_reported_length(selfm_tvb);
2674 /* If sanitized selfm_tvb length is still less than the reported selfm PDU length, there is more segment data to follow */
2675 if (selfm_tvb_len < selfm_PDU_len) {
2676 pinfo->desegment_offset = 0;
2677 pinfo->desegment_len = DESEGMENT_ONE_MORE_SEGMENT;
2678 return tvb_captured_length(tvb);
2681 /* If the available selfm_tvb length is greater than the reported selfm PDU length, */
2682 /* there is possibly a second PDU to follow so let's dig deeper... */
2683 if (selfm_tvb_len > selfm_PDU_len) {
2684 /* Check if additional data is actually selfm PDU data */
2685 if (tvb_get_uint8(selfm_tvb, selfm_PDU_len) == 0xA5) {
2686 new_selfm_PDU_len = tvb_get_uint8(selfm_tvb, selfm_PDU_len+2);
2687 /* If we still don't have enough data to accommodate the 2 PDUs... */
2688 if (selfm_tvb_len < (selfm_PDU_len + new_selfm_PDU_len)) {
2689 ws_debug("On Packet: %d, continuing to desegment. PDU: %d NewPDU: %d Still need %d bytes..", pinfo->fd->num, selfm_PDU_len, new_selfm_PDU_len, (selfm_PDU_len + new_selfm_PDU_len) - selfm_tvb_len);
2691 /* If the current selfm_tvb length is less than the combined reported selfm length of the 2 PDUs, continue TCP desegmentation */
2692 /* The desegment_len field will be used to report how many additional bytes remain to be reassembled */
2693 pinfo->desegment_offset = 0;
2694 pinfo->desegment_len = (selfm_PDU_len + new_selfm_PDU_len) - selfm_tvb_len;
2695 return tvb_captured_length(tvb);
2700 /* If multiple SEL protocol PDUs exist within a single tvb, dissect each of them sequentially */
2701 while (offset < selfm_tvb_len) {
2702 /* If random ASCII data makes its way onto the end of an SEL protocol PDU, ignore it */
2703 if (tvb_get_uint8(selfm_tvb, offset) != 0xA5) {
2704 ws_debug("On Packet: %d, extraneous data (starts with: %x)..", pinfo->fd->num, tvb_get_uint8(selfm_tvb, offset));
2705 break;
2707 /* Create new selfm_pdu_tvb that contains only a single PDU worth of data */
2708 selfm_pdu_tvb = tvb_new_subset_length( selfm_tvb, offset, tvb_get_uint8(selfm_tvb, offset+2));
2709 offset += dissect_selfm(selfm_pdu_tvb, pinfo, tree, data);
2712 /* Return the completed selfm_tvb dissected length + the count of any IAC skip bytes that were removed from the tvb payload */
2713 return selfm_tvb_len + skip_byte;
2716 /******************************************************************************************************/
2717 /* Register the protocol with Wireshark */
2718 /******************************************************************************************************/
2719 void proto_reg_handoff_selfm(void);
2721 void
2722 proto_register_selfm(void)
2724 /* SEL Protocol header fields */
2725 static hf_register_info selfm_hf[] = {
2726 { &hf_selfm_msgtype,
2727 { "Message Type", "selfm.msgtype", FT_UINT16, BASE_HEX|BASE_EXT_STRING, &selfm_msgtype_vals_ext, 0x0, NULL, HFILL }},
2728 { &hf_selfm_padbyte,
2729 { "Pad Byte", "selfm.padbyte", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},
2730 { &hf_selfm_checksum,
2731 { "Checksum", "selfm.checksum", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},
2732 /* "Relay Definition" specific fields */
2733 { &hf_selfm_relaydef_len,
2734 { "Length", "selfm.relaydef.len", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2735 { &hf_selfm_relaydef_numproto,
2736 { "Number of Protocols", "selfm.relaydef.numproto", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2737 { &hf_selfm_relaydef_numfm,
2738 { "Number of Fast Meter Messages", "selfm.relaydef.numfm", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2739 { &hf_selfm_relaydef_numflags,
2740 { "Number of Status Flags", "selfm.relaydef.numflags", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2741 { &hf_selfm_relaydef_fmcfg_cmd,
2742 { "Fast Meter Config Command", "selfm.relaydef.fmcfg_cmd", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
2743 { &hf_selfm_relaydef_fmdata_cmd,
2744 { "Fast Meter Data Command", "selfm.relaydef.fmdata_cmd", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
2745 { &hf_selfm_relaydef_statbit,
2746 { "Status Flag Bit", "selfm.relaydef.status_bit", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
2747 { &hf_selfm_relaydef_statbit_cmd,
2748 { "Status Flag Bit Response Command", "selfm.relaydef.status_bit_cmd", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
2749 { &hf_selfm_relaydef_proto,
2750 { "Supported Protocol", "selfm.relaydef.proto", FT_UINT16, BASE_HEX|BASE_EXT_STRING, &selfm_relaydef_proto_vals_ext, 0x0, NULL, HFILL }},
2751 /* "Fast Meter Configuration" specific fields */
2752 { &hf_selfm_fmconfig_len,
2753 { "Length", "selfm.fmconfig.len", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2754 { &hf_selfm_fmconfig_numflags,
2755 { "Number of Status Flags", "selfm.fmconfig.numflags", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2756 { &hf_selfm_fmconfig_loc_sf,
2757 { "Location of Scale Factor", "selfm.fmconfig.loc_sf", FT_UINT8, BASE_DEC, VALS(selfm_fmconfig_sfloc_vals), 0x0, NULL, HFILL }},
2758 { &hf_selfm_fmconfig_num_sf,
2759 { "Number of Scale Factors", "selfm.fmconfig.num_sf", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2760 { &hf_selfm_fmconfig_num_ai,
2761 { "Number of Analog Input Channels", "selfm.fmconfig.num_ai", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2762 { &hf_selfm_fmconfig_num_samp,
2763 { "Number of Samples per AI Channel", "selfm.fmconfig.num_samp", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2764 { &hf_selfm_fmconfig_num_dig,
2765 { "Number of Digital Banks", "selfm.fmconfig.num_dig", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2766 { &hf_selfm_fmconfig_num_calc,
2767 { "Number of Calculation Blocks", "selfm.fmconfig.num_calc", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2768 { &hf_selfm_fmconfig_ofs_ai,
2769 { "First Analog Channel Offset", "selfm.fmconfig.ofs_ai", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2770 { &hf_selfm_fmconfig_ofs_ts,
2771 { "Timestamp Offset", "selfm.fmconfig.ofs_ts", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2772 { &hf_selfm_fmconfig_ofs_dig,
2773 { "First Digital Bank Offset", "selfm.fmconfig.ofs_dig", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2774 { &hf_selfm_fmconfig_ai_type,
2775 { "Analog Channel Type", "selfm.fmconfig.ai_type", FT_UINT8, BASE_DEC, VALS(selfm_fmconfig_ai_chtype_vals), 0x0, NULL, HFILL }},
2776 { &hf_selfm_fmconfig_ai_sf_type,
2777 { "Analog Channel Scale Factor Type", "selfm.fmconfig.ai_sf_type", FT_UINT8, BASE_DEC, VALS(selfm_fmconfig_ai_sftype_vals), 0x0, NULL, HFILL }},
2778 { &hf_selfm_fmconfig_ai_sf_ofs,
2779 { "Analog Channel Scale Factor Offset", "selfm.fmconfig.ai_sf_ofs", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2780 { &hf_selfm_fmconfig_cblk_rot,
2781 { "Rotation", "selfm.fmconfig.cblk_rot", FT_UINT8, BASE_HEX, VALS(selfm_fmconfig_cblk_rot_vals), 0x01, NULL, HFILL }},
2782 { &hf_selfm_fmconfig_cblk_vconn,
2783 { "Voltage Connection", "selfm.fmconfig.cblk_vconn", FT_UINT8, BASE_HEX, VALS(selfm_fmconfig_cblk_vconn_vals), 0x06, NULL, HFILL }},
2784 { &hf_selfm_fmconfig_cblk_iconn,
2785 { "Current Connection", "selfm.fmconfig.cblk_iconn", FT_UINT8, BASE_HEX, VALS(selfm_fmconfig_cblk_iconn_vals), 0x18, NULL, HFILL }},
2786 { &hf_selfm_fmconfig_cblk_ctype,
2787 { "Calculation Type", "selfm.fmconfig.cblk_ctype", FT_UINT8, BASE_DEC, VALS(selfm_fmconfig_cblk_ctype_vals), 0x0, NULL, HFILL }},
2788 { &hf_selfm_fmconfig_cblk_deskew_ofs,
2789 { "Skew Correction Offset", "selfm.fmconfig.cblk_deskew_ofs", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2790 { &hf_selfm_fmconfig_cblk_rs_ofs,
2791 { "Rs Offset", "selfm.fmconfig.cblk_rs_ofs", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2792 { &hf_selfm_fmconfig_cblk_xs_ofs,
2793 { "Xs Offset", "selfm.fmconfig.cblk_xs_ofs", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2794 { &hf_selfm_fmconfig_cblk_ia_idx,
2795 { "Analog Record Ia Index Position", "selfm.fmconfig.cblk_ia_idx", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2796 { &hf_selfm_fmconfig_cblk_ib_idx,
2797 { "Analog Record Ib Index Position", "selfm.fmconfig.cblk_ib_idx", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2798 { &hf_selfm_fmconfig_cblk_ic_idx,
2799 { "Analog Record Ic Index Position", "selfm.fmconfig.cblk_ic_idx", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2800 { &hf_selfm_fmconfig_cblk_va_idx,
2801 { "Analog Record Va/Vab Index Position", "selfm.fmconfig.cblk_va_idx", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2802 { &hf_selfm_fmconfig_cblk_vb_idx,
2803 { "Analog Record Vb/Vbc Index Position", "selfm.fmconfig.cblk_vb_idx", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2804 { &hf_selfm_fmconfig_cblk_vc_idx,
2805 { "Analog Record Vc/Vca Index Position", "selfm.fmconfig.cblk_vc_idx", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2806 { &hf_selfm_fmconfig_ai_sf_float,
2807 { "AI Scale Factor (float)", "selfm.fmconfig.ai_sf_float", FT_FLOAT, BASE_NONE, NULL, 0x0, NULL, HFILL }},
2808 /* "Fast Meter Data" specific fields */
2809 { &hf_selfm_fmdata_len,
2810 { "Length", "selfm.fmdata.len", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2811 { &hf_selfm_fmdata_flagbyte,
2812 { "Status Flags Byte", "selfm.fmdata.flagbyte", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2813 { &hf_selfm_fmdata_ai_sf_fp,
2814 { "Using IEEE FP Format Scale Factor", "selfm.fmdata.ai.sf_fp",FT_FLOAT, BASE_NONE, NULL, 0x0, NULL, HFILL }},
2815 { &hf_selfm_fmdata_dig_b0,
2816 { "Bit 0", "selfm.fmdata.dig_b0", FT_BOOLEAN, 8, NULL, 0x01, NULL, HFILL }},
2817 { &hf_selfm_fmdata_dig_b1,
2818 { "Bit 1", "selfm.fmdata.dig_b1", FT_BOOLEAN, 8, NULL, 0x02, NULL, HFILL }},
2819 { &hf_selfm_fmdata_dig_b2,
2820 { "Bit 2", "selfm.fmdata.dig_b2", FT_BOOLEAN, 8, NULL, 0x04, NULL, HFILL }},
2821 { &hf_selfm_fmdata_dig_b3,
2822 { "Bit 3", "selfm.fmdata.dig_b3", FT_BOOLEAN, 8, NULL, 0x08, NULL, HFILL }},
2823 { &hf_selfm_fmdata_dig_b4,
2824 { "Bit 4", "selfm.fmdata.dig_b4", FT_BOOLEAN, 8, NULL, 0x10, NULL, HFILL }},
2825 { &hf_selfm_fmdata_dig_b5,
2826 { "Bit 5", "selfm.fmdata.dig_b5", FT_BOOLEAN, 8, NULL, 0x20, NULL, HFILL }},
2827 { &hf_selfm_fmdata_dig_b6,
2828 { "Bit 6", "selfm.fmdata.dig_b6", FT_BOOLEAN, 8, NULL, 0x40, NULL, HFILL }},
2829 { &hf_selfm_fmdata_dig_b7,
2830 { "Bit 7", "selfm.fmdata.dig_b7", FT_BOOLEAN, 8, NULL, 0x80, NULL, HFILL }},
2831 /* "Fast Operate Configuration" specific fields */
2832 { &hf_selfm_foconfig_len,
2833 { "Length", "selfm.foconfig.len", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2834 { &hf_selfm_foconfig_num_brkr,
2835 { "Number of Breaker Bits", "selfm.foconfig.num_brkr", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2836 { &hf_selfm_foconfig_num_rb,
2837 { "Number of Remote Bits", "selfm.foconfig.num_rb", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2838 { &hf_selfm_foconfig_prb_supp,
2839 { "Remote Bit Pulse Supported", "selfm.foconfig.prb_supp", FT_UINT8, BASE_DEC, VALS(selfm_foconfig_prb_supp_vals), 0x0, NULL, HFILL }},
2840 { &hf_selfm_foconfig_reserved,
2841 { "Reserved Bit (Future)", "selfm.foconfig.reserved", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2842 { &hf_selfm_foconfig_brkr_open,
2843 { "Breaker Bit Open Command", "selfm.foconfig.brkr_open", FT_UINT8, BASE_HEX | BASE_EXT_STRING, &selfm_fo_br_vals_ext, 0x0, NULL, HFILL }},
2844 { &hf_selfm_foconfig_brkr_close,
2845 { "Breaker Bit Close Command", "selfm.foconfig.brkr_close", FT_UINT8, BASE_HEX | BASE_EXT_STRING, &selfm_fo_br_vals_ext, 0x0, NULL, HFILL }},
2846 { &hf_selfm_foconfig_rb_cmd,
2847 { "Remote Bit Command", "selfm.foconfig.rb_cmd", FT_UINT8, BASE_HEX | BASE_EXT_STRING, &selfm_fo_rb_vals_ext, 0x0, NULL, HFILL }},
2848 /* "Alternate Fast Operate Configuration" specific fields */
2849 { &hf_selfm_alt_foconfig_len,
2850 { "Length", "selfm.alt_foconfig.len", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2851 { &hf_selfm_alt_foconfig_num_ports,
2852 { "Number of Ports Available", "selfm.alt_foconfig.num_ports", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2853 { &hf_selfm_alt_foconfig_num_brkr,
2854 { "Number of Breaker Bits per Port", "selfm.alt_foconfig.num_brkr", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2855 { &hf_selfm_alt_foconfig_num_rb,
2856 { "Number of Remote Bits per Port", "selfm.alt_foconfig.num_rb", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2857 { &hf_selfm_alt_foconfig_funccode,
2858 { "Supported Function Code", "selfm.alt_foconfig.funccode", FT_UINT8, BASE_HEX, VALS(selfm_foconfig_alt_funccode_vals), 0x0, NULL, HFILL }},
2859 /* "Fast Operate Command" specific fields */
2860 { &hf_selfm_fastop_len,
2861 { "Length", "selfm.fastop.len", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2862 { &hf_selfm_fastop_rb_code,
2863 { "Remote Bit Operate Code", "selfm.fastop.rb_code", FT_UINT8, BASE_HEX | BASE_EXT_STRING, &selfm_fo_rb_vals_ext, 0x0, NULL, HFILL }},
2864 { &hf_selfm_fastop_br_code,
2865 { "Breaker Bit Operate Code", "selfm.fastop.br_code", FT_UINT8, BASE_HEX | BASE_EXT_STRING, &selfm_fo_br_vals_ext, 0x0, NULL, HFILL }},
2866 { &hf_selfm_fastop_valid,
2867 { "Operate Code Validation", "selfm.fastop.valid", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},
2868 /* "Alternate Fast Operate Command" specific fields */
2869 { &hf_selfm_alt_fastop_len,
2870 { "Length", "selfm.alt_fastop.len", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2871 { &hf_selfm_alt_fastop_code,
2872 { "Operate Code", "selfm.alt_fastop.code", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
2873 { &hf_selfm_alt_fastop_valid,
2874 { "Operate Code Validation", "selfm.alt_fastop.valid", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
2875 /* "Fast Message" specific fields */
2876 { &hf_selfm_fastmsg_len,
2877 { "Length", "selfm.fastmsg.len", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2878 { &hf_selfm_fastmsg_routing_addr,
2879 { "Routing Address (future)", "selfm.fastmsg.routing_addr", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
2880 { &hf_selfm_fastmsg_status,
2881 { "Status Byte", "selfm.fastmsg.status", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2882 { &hf_selfm_fastmsg_funccode,
2883 { "Function Code", "selfm.fastmsg.funccode", FT_UINT8, BASE_HEX | BASE_EXT_STRING, &selfm_fastmsg_func_code_vals_ext, 0x0, NULL, HFILL }},
2884 { &hf_selfm_fastmsg_response_code,
2885 { "Response Code", "selfm.fastmsg.responsecode", FT_UINT8, BASE_HEX | BASE_EXT_STRING, &selfm_fastmsg_ack_responsecode_vals_ext, 0x0, NULL, HFILL }},
2886 { &hf_selfm_fastmsg_seq,
2887 { "Sequence Byte", "selfm.fastmsg.seq", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},
2888 { &hf_selfm_fastmsg_seq_fir,
2889 { "FIR", "selfm.fastmsg.seq_fir", FT_BOOLEAN, 8, NULL, FAST_MSG_SEQ_FIR, NULL, HFILL }},
2890 { &hf_selfm_fastmsg_seq_fin,
2891 { "FIN", "selfm.fastmsg.seq_fin", FT_BOOLEAN, 8, NULL, FAST_MSG_SEQ_FIN, NULL, HFILL }},
2892 { &hf_selfm_fastmsg_seq_cnt,
2893 { "Count", "selfm.fastmsg.seq_cnt", FT_UINT8, BASE_DEC, NULL, FAST_MSG_SEQ_CNT, "Frame Count Number", HFILL }},
2894 { &hf_selfm_fastmsg_resp_num,
2895 { "Response Number", "selfm.fastmsg.resp_num", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2896 { &hf_selfm_fastmsg_crc16,
2897 { "CRC-16", "selfm.fastmsg.crc16", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
2898 { &hf_selfm_fastmsg_def_route_sup,
2899 { "Routing Support", "selfm.fastmsg.def_route_sup", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2900 { &hf_selfm_fastmsg_def_rx_stat,
2901 { "Status RX", "selfm.fastmsg.def_rx_stat", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2902 { &hf_selfm_fastmsg_def_tx_stat,
2903 { "Status TX", "selfm.fastmsg.def_tx_stat", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2904 { &hf_selfm_fastmsg_def_rx_maxfr,
2905 { "Max Frames RX", "selfm.fastmsg.def_rx_maxfr", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2906 { &hf_selfm_fastmsg_def_tx_maxfr,
2907 { "Max Frames TX", "selfm.fastmsg.def_tx_maxfr", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2908 { &hf_selfm_fastmsg_def_rx_num_fc,
2909 { "Number of Supported RX Function Codes", "selfm.fastmsg.def_rx_num_fc", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2910 { &hf_selfm_fastmsg_def_rx_fc,
2911 { "Receive Function Code", "selfm.fastmsg.def_rx_fc", FT_UINT8, BASE_HEX | BASE_EXT_STRING, &selfm_fastmsg_func_code_vals_ext, 0x0, NULL, HFILL }},
2912 { &hf_selfm_fastmsg_def_tx_num_fc,
2913 { "Number of Supported TX Function Codes", "selfm.fastmsg.def_tx_num_fc", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2914 { &hf_selfm_fastmsg_def_tx_fc,
2915 { "Transmit Function Code", "selfm.fastmsg.def_tx_fc", FT_UINT8, BASE_HEX | BASE_EXT_STRING, &selfm_fastmsg_func_code_vals_ext, 0x0, NULL, HFILL }},
2916 { &hf_selfm_fastmsg_uns_en_fc,
2917 { "Function Code to Enable", "selfm.fastmsg.uns_en_fc", FT_UINT8, BASE_HEX | BASE_EXT_STRING, &selfm_fastmsg_func_code_vals_ext, 0x0, NULL, HFILL }},
2918 { &hf_selfm_fastmsg_uns_en_fc_data,
2919 { "Function Code Data", "selfm.fastmsg.uns_en_fc_data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
2920 { &hf_selfm_fastmsg_uns_dis_fc,
2921 { "Function Code to Disable", "selfm.fastmsg.uns_dis_fc", FT_UINT8, BASE_HEX | BASE_EXT_STRING, &selfm_fastmsg_func_code_vals_ext, 0x0, NULL, HFILL }},
2922 { &hf_selfm_fastmsg_uns_dis_fc_data,
2923 { "Function Code Data", "selfm.fastmsg.uns_dis_fc_data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
2924 { &hf_selfm_fastmsg_unsresp_orig,
2925 { "Origination path", "selfm.fastmsg.unsresp_orig", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
2926 { &hf_selfm_fastmsg_unsresp_doy,
2927 { "Day of Year", "selfm.fastmsg.unsresp_doy", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2928 { &hf_selfm_fastmsg_unsresp_year,
2929 { "Year", "selfm.fastmsg.unsresp_year", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2930 { &hf_selfm_fastmsg_unsresp_todms,
2931 { "Time of Day (in ms)", "selfm.fastmsg.unsresp_todms", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2932 { &hf_selfm_fastmsg_unsresp_num_elmt,
2933 { "Number of SER Elements", "selfm.fastmsg.unsresp_num_elmt", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2934 { &hf_selfm_fastmsg_unsresp_elmt_idx,
2935 { "SER Element Index", "selfm.fastmsg.unsresp_elmt_idx", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2936 { &hf_selfm_fastmsg_unsresp_elmt_ts_ofs,
2937 { "SER Element Timestamp Offset (us)", "selfm.fastmsg.unsresp_elmt_ts_ofs", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2938 { &hf_selfm_fastmsg_unsresp_elmt_status,
2939 { "SER Element Status", "selfm.fastmsg.unsresp_elmt_status", FT_UINT8, BASE_DEC, VALS(selfm_ser_status_vals), 0x0, NULL, HFILL }},
2940 { &hf_selfm_fastmsg_unsresp_eor,
2941 { "End of Record Indicator", "selfm.fastmsg.unsresp_eor", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
2942 { &hf_selfm_fastmsg_unsresp_elmt_statword,
2943 { "SER Element Status Word", "selfm.fastmsg.unsresp_elmt_statword", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }},
2944 { &hf_selfm_fastmsg_unswrite_addr1,
2945 { "Write Address Region #1", "selfm.fastmsg.unswrite_addr1", FT_UINT16, BASE_HEX | BASE_EXT_STRING, &selfm_fastmsg_unswrite_com_vals_ext, 0x0, NULL, HFILL }},
2946 { &hf_selfm_fastmsg_unswrite_addr2,
2947 { "Write Address Region #2", "selfm.fastmsg.unswrite_addr2", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
2948 { &hf_selfm_fastmsg_unswrite_num_reg,
2949 { "Number of Registers", "selfm.fastmsg.unswrite_num_reg", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2950 { &hf_selfm_fastmsg_unswrite_reg_val,
2951 { "Register Value", "selfm.fastmsg.unswrite_reg_val", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2952 { &hf_selfm_fastmsg_baseaddr,
2953 { "Base Address", "selfm.fastmsg.baseaddr", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }},
2954 { &hf_selfm_fastmsg_numwords,
2955 { "Number of 16-bit Words", "selfm.fastmsg.numwords", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2956 { &hf_selfm_fastmsg_flags,
2957 { "Flag Word", "selfm.fastmsg.flags", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
2958 { &hf_selfm_fastmsg_datafmt_resp_numitem,
2959 { "Number of Data Items Records", "selfm.fastmsg.datafmt_resp_numitem", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2960 { &hf_selfm_fastmsg_dataitem_qty,
2961 { "Data Item Quantity", "selfm.fastmsg.dataitem_qty", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2962 { &hf_selfm_fastmsg_dataitem_type,
2963 { "Data Item Type", "selfm.fastmsg.dataitem_type", FT_UINT16, BASE_HEX, VALS(selfm_fastmsg_tagtype_vals), 0x0, NULL, HFILL }},
2964 { &hf_selfm_fastmsg_dataitem_uint16,
2965 { "(uint16)", "selfm.fastmsg.dataitem_uint16", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2966 { &hf_selfm_fastmsg_dataitem_int16,
2967 { "(int16)", "selfm.fastmsg.dataitem_int16", FT_INT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2968 { &hf_selfm_fastmsg_dataitem_uint32,
2969 { "(uint32)", "selfm.fastmsg.dataitem_uint32", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2970 { &hf_selfm_fastmsg_dataitem_int32,
2971 { "(int32)", "selfm.fastmsg.dataitem_int32", FT_INT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2972 { &hf_selfm_fastmsg_dataitem_float,
2973 { "(float)", "selfm.fastmsg.dataitem_float", FT_FLOAT, BASE_NONE, NULL, 0x0, NULL, HFILL }},
2974 { &hf_selfm_fastmsg_devdesc_num_region,
2975 { "Number of Data Regions", "selfm.fastmsg.devdesc_num_region", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2976 { &hf_selfm_fastmsg_devdesc_num_ctrl,
2977 { "Number of Control Regions", "selfm.fastmsg.devdesc_num_ctrl", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2978 { &hf_selfm_fastmsg_soe_req_orig,
2979 { "Origination path", "selfm.fastmsg.soe_req_orig", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
2980 { &hf_selfm_fastmsg_soe_resp_numblks,
2981 { "Number of Blocks", "selfm.fastmsg.soe_resp_numblks", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2982 { &hf_selfm_fastmsg_soe_resp_orig,
2983 { "Origination path", "selfm.fastmsg.soe_resp_orig", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
2984 { &hf_selfm_fastmsg_soe_resp_numbits,
2985 { "Number of Bits", "selfm.fastmsg.soe_resp_numbits", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2986 { &hf_selfm_fastmsg_soe_resp_pad,
2987 { "Pad Byte", "selfm.fastmsg.soe_resp_pad", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2988 { &hf_selfm_fastmsg_soe_resp_doy,
2989 { "Day of Year", "selfm.fastmsg.soe_resp_doy", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2990 { &hf_selfm_fastmsg_soe_resp_year,
2991 { "Year", "selfm.fastmsg.soe_resp_year", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2992 { &hf_selfm_fastmsg_soe_resp_tod,
2993 { "Time of Day (ms)", "selfm.fastmsg.soe_resp_tod", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2994 { &hf_selfm_fastmsg_soe_resp_data,
2995 { "Packed Binary State Data", "selfm.fastmsg.soe_resp_data", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
2997 /* "Fast Message" Re-assembly header fields */
2998 { &hf_selfm_fragment,
2999 { "SEL Fast Msg Response Data Fragment", "selfm.respdata.fragment", FT_FRAMENUM, BASE_NONE, NULL, 0x0, "SEL Fast Message Response Data Fragment", HFILL }},
3000 { &hf_selfm_fragments,
3001 { "SEL Fast Msg Response Data Fragments", "selfm.respdata.fragments", FT_NONE, BASE_NONE, NULL, 0x0, "SEL Fast Message Response Data Fragments", HFILL }},
3002 { &hf_selfm_fragment_overlap,
3003 { "Fragment overlap", "selfm.respdata.fragment.overlap", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "Fragment overlaps with other fragments", HFILL }},
3004 { &hf_selfm_fragment_overlap_conflict,
3005 { "Conflicting data in fragment overlap", "selfm.respdata.fragment.overlap.conflict", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "Overlapping fragments contained conflicting data", HFILL }},
3006 { &hf_selfm_fragment_multiple_tails,
3007 { "Multiple tail fragments found", "selfm.respdata.fragment.multipletails", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "Several tails were found when defragmenting the packet", HFILL }},
3008 { &hf_selfm_fragment_too_long_fragment,
3009 { "Fragment too long", "selfm.respdata.fragment.toolongfragment", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "Fragment contained data past end of packet", HFILL }},
3010 { &hf_selfm_fragment_error,
3011 { "Defragmentation error", "selfm.respdata.fragment.error", FT_FRAMENUM, BASE_NONE, NULL, 0x0, "Defragmentation error due to illegal fragments", HFILL }},
3012 { &hf_selfm_fragment_count,
3013 { "Fragment count", "selfm.respdata.fragment.count", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
3014 { &hf_selfm_fragment_reassembled_in,
3015 { "Reassembled PDU In Frame", "selfm.respdata.fragment.reassembled_in", FT_FRAMENUM, BASE_NONE, NULL, 0x0, "This PDU is reassembled in this frame", HFILL }},
3016 { &hf_selfm_fragment_reassembled_length,
3017 { "Reassembled SEL Fast Msg length", "selfm.respdata.fragment.reassembled.length", FT_UINT32, BASE_DEC, NULL, 0x0, "The total length of the reassembled payload", HFILL }},
3018 /* Generated from convert_proto_tree_add_text.pl */
3019 { &hf_selfm_fmconfig_ai_channel, { "Analog Channel Name", "selfm.fmconfig.ai_channel", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
3020 { &hf_selfm_fmdata_ai_value16, { "Value (Raw)", "selfm.fmdata.ai.value16", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
3021 { &hf_selfm_fmdata_ai_scale_factor, { "Value (w/ Scale Factor)", "selfm.fmdata.ai.value_scale_factor", FT_FLOAT, BASE_NONE, NULL, 0x0, NULL, HFILL }},
3022 { &hf_selfm_fmdata_ai_value_float, { "Value", "selfm.fmdata.ai.value_float", FT_FLOAT, BASE_NONE, NULL, 0x0, NULL, HFILL }},
3023 { &hf_selfm_fmdata_ai_value_double, { "Value", "selfm.fmdata.ai.value_double", FT_DOUBLE, BASE_NONE, NULL, 0x0, NULL, HFILL }},
3024 { &hf_selfm_fmdata_data_type, { "Data_Type", "selfm.fmdata.data_type", FT_UINT32, BASE_DEC, VALS(selfm_fastmsg_tagtype_vals), 0x0, NULL, HFILL }},
3025 { &hf_selfm_fmdata_quantity, { "Quantity", "selfm.fmdata.quantity", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
3026 { &hf_selfm_fmdata_ai_value_string, { "Value", "selfm.fmdata.ai.value_string", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
3027 { &hf_selfm_fastmsg_unsresp_elmt_ts_ofs_decoded, { "SER Element Timestamp Offset (decoded)", "selfm.fastmsg.unsresp_elmt_ts_ofs.decoded", FT_UINT24, BASE_DEC, NULL, 0x0, NULL, HFILL }},
3028 { &hf_selfm_fid, { "FID", "selfm.fid", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
3029 { &hf_selfm_rid, { "RID", "selfm.rid", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
3030 { &hf_selfm_fastmsg_data_region_name, { "Data Region Name", "selfm.fastmsg.data_region_name", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
3031 { &hf_selfm_fmdata_timestamp, { "Timestamp", "selfm.fmdata.timestamp", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0x0, NULL, HFILL }},
3032 { &hf_selfm_fmdata_frame_data_format_reference, { "Frame Data Format Reference", "selfm.fmdata.frame_data_format_reference", FT_FRAMENUM, BASE_NONE, NULL, 0x0, NULL, HFILL }},
3033 { &hf_selfm_fastmsg_bit_label_name, { "Bit Label Name", "selfm.fastmsg.bit_label_name", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
3036 /* Register expert fields */
3037 static ei_register_info selfm_ei[] = {
3038 { &ei_selfm_crc16_incorrect, { "selfm.crc16.incorrect", PI_CHECKSUM, PI_WARN, "Incorrect CRC", EXPFILL }}
3041 /* Setup protocol subtree array */
3042 static int *ett[] = {
3043 &ett_selfm,
3044 &ett_selfm_relaydef,
3045 &ett_selfm_relaydef_fm,
3046 &ett_selfm_relaydef_proto,
3047 &ett_selfm_relaydef_flags,
3048 &ett_selfm_fmconfig,
3049 &ett_selfm_fmconfig_ai,
3050 &ett_selfm_fmconfig_calc,
3051 &ett_selfm_foconfig,
3052 &ett_selfm_foconfig_brkr,
3053 &ett_selfm_foconfig_rb,
3054 &ett_selfm_fastop,
3055 &ett_selfm_fmdata,
3056 &ett_selfm_fmdata_ai,
3057 &ett_selfm_fmdata_dig,
3058 &ett_selfm_fmdata_ai_ch,
3059 &ett_selfm_fmdata_dig_ch,
3060 &ett_selfm_fastmsg,
3061 &ett_selfm_fastmsg_seq,
3062 &ett_selfm_fastmsg_def_fc,
3063 &ett_selfm_fastmsg_tag,
3064 &ett_selfm_fastmsg_element_list,
3065 &ett_selfm_fastmsg_element,
3066 &ett_selfm_fastmsg_datareg,
3067 &ett_selfm_fastmsg_soeblk,
3068 &ett_selfm_fragment,
3069 &ett_selfm_fragments
3073 module_t *selfm_module;
3074 expert_module_t* expert_selfm;
3076 reassembly_table_register(&selfm_reassembly_table,
3077 &addresses_reassembly_table_functions);
3079 /* Register the protocol name and description */
3080 proto_selfm = proto_register_protocol("SEL Protocol", "SEL Protocol", "selfm");
3082 /* Registering protocol to be called by another dissector */
3083 selfm_handle = register_dissector("selfm", dissect_selfm_tcp, proto_selfm);
3085 /* Required function calls to register the header fields and subtrees used */
3086 proto_register_field_array(proto_selfm, selfm_hf, array_length(selfm_hf));
3087 proto_register_subtree_array(ett, array_length(ett));
3088 expert_selfm = expert_register_protocol(proto_selfm);
3089 expert_register_field_array(expert_selfm, selfm_ei, array_length(selfm_ei));
3092 /* Register required preferences for SEL Protocol register decoding */
3093 selfm_module = prefs_register_protocol(proto_selfm, NULL);
3095 /* SEL Protocol - Desegmentmentation; defaults to true for TCP desegmentation*/
3096 prefs_register_bool_preference(selfm_module, "desegment",
3097 "Desegment packets spanning multiple TCP segments",
3098 "Whether the SEL Protocol dissector should desegment all messages spanning multiple TCP segments",
3099 &selfm_desegment);
3101 /* SEL Protocol - Telnet protocol IAC (0xFF) processing; defaults to true to allow Telnet Encapsulated Data */
3102 prefs_register_bool_preference(selfm_module, "telnetclean",
3103 "Remove extra 0xFF (Telnet IAC) bytes",
3104 "Whether the SEL Protocol dissector should automatically pre-process Telnet data to remove duplicate 0xFF IAC bytes",
3105 &selfm_telnet_clean);
3107 /* SEL Protocol Preference - Disable/Enable CRC verification, */
3108 prefs_register_bool_preference(selfm_module, "crc_verification", "Validate Fast Message CRC16",
3109 "Perform CRC16 validation on Fast Messages",
3110 &selfm_crc16);
3112 prefs_register_string_preference(selfm_module, "ser_list",
3113 "SER Index List", "List of word bits contained in SER equations (Comma-separated, no Quotes or Checksums)", &selfm_ser_list);
3118 /******************************************************************************************************/
3119 /* If this dissector uses sub-dissector registration add a registration routine.
3120 This format is required because a script is used to find these routines and
3121 create the code that calls these routines.
3123 /******************************************************************************************************/
3124 void
3125 proto_reg_handoff_selfm(void)
3127 dissector_add_for_decode_as_with_preference("tcp.port", selfm_handle);
3128 dissector_add_for_decode_as("rtacser.data", selfm_handle);
3132 * Editor modelines - https://www.wireshark.org/tools/modelines.html
3134 * Local variables:
3135 * c-basic-offset: 4
3136 * tab-width: 8
3137 * indent-tabs-mode: nil
3138 * End:
3140 * vi: set shiftwidth=4 tabstop=8 expandtab:
3141 * :indentSize=4:tabSize=8:noTabs=true: