MSWSP: fix dissect_mswsp_smb()
[wireshark-wip.git] / epan / dissectors / packet-selfm.c
blobd4915007141897afd796b63a195dbeed1df82e73
1 /* packet-selfm.c
2 * Routines for Schweitzer Engineering Laboratories Fast Message Protocol (SEL FM) Dissection
3 * By Chris Bontje (cbontje[AT]gmail.com
4 * Copyright Nov/Dec 2012,
6 * $Id$
9 ************************************************************************************************
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald@wireshark.org>
12 * Copyright 1998 Gerald Combs
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 ************************************************************************************************
29 * Schweitzer Engineering Labs ("SEL") manufactures and sells digital protective relay equipment
30 * for use in industrial high-voltage installations. SEL FM protocol evolved over time as a
31 * (semi)proprietary method for auto-configuration of connected SEL devices for retrieval of
32 * analog and digital status data. The protocol itself supports embedded binary messages
33 * (which are what this dissector looks for) slip-streamed in the data stream with normal
34 * ASCII text data. A combination of both are used for full auto-configuration of devices,
35 * but a wealth of information can be extracted from the binary messages alone.
37 * Documentation on Fast Meter and Fast SER messages available from www.selinc.com in
38 * SEL Application Guides AG95-10_20091109.pdf and AG_200214.pdf
39 ************************************************************************************************
40 * Dissector Notes:
42 * 1) SEL Fast Message protocol over TCP is normally tunneled via a Telnet connection. As Telnet
43 * has special handling for the 0xFF character ("IAC"), normally a pair of 0xFF's are inserted
44 * to represent an actual payload byte of 0xFF. A function from the packet-telnet.c dissector has
45 * been borrowed to automatically pre-process any Ethernet-based packet and remove these 'extra'
46 * 0xFF bytes. Wireshark Notes on Telnet 0xFF doubling are discussed here:
47 * http://www.wireshark.org/lists/wireshark-bugs/201204/msg00198.html
49 * 2) The auto-configuration process itself will exchange several "configuration" messages that
50 * describe various data regions (METER, DEMAND, PEAK, etc) that will later have corresponding
51 * "data" messages. This dissector code will currently save and accurately retrieve the 3 sets
52 * of these exchanges:
53 * 0xA5C1, 0xA5D1, "METER" region
54 * 0xA5C2, 0xA5D2, "DEMAND" region
55 * 0xA5C3, 0xA5D3, "PEAK" region
56 * The configuration messages are stored in structs that are managed using the wmem library and
57 * the Wireshark conversation functionality.
60 #include "config.h"
62 #include <epan/packet.h>
63 #include "packet-tcp.h"
64 #include <epan/prefs.h>
65 #include <epan/reassemble.h>
66 #include <epan/expert.h>
67 #include <epan/conversation.h>
68 #include <epan/wmem/wmem.h>
70 /* Initialize the protocol and registered fields */
71 static int proto_selfm = -1;
72 static int hf_selfm_msgtype = -1;
73 static int hf_selfm_padbyte = -1;
74 static int hf_selfm_checksum = -1;
75 static int hf_selfm_relaydef_len = -1;
76 static int hf_selfm_relaydef_numproto = -1;
77 static int hf_selfm_relaydef_numfm = -1;
78 static int hf_selfm_relaydef_numflags = -1;
79 static int hf_selfm_relaydef_fmcfg_cmd = -1;
80 static int hf_selfm_relaydef_fmdata_cmd = -1;
81 static int hf_selfm_relaydef_statbit = -1;
82 static int hf_selfm_relaydef_statbit_cmd = -1;
83 static int hf_selfm_relaydef_proto = -1;
84 static int hf_selfm_fmconfig_len = -1;
85 static int hf_selfm_fmconfig_numflags = -1;
86 static int hf_selfm_fmconfig_loc_sf = -1;
87 static int hf_selfm_fmconfig_num_sf = -1;
88 static int hf_selfm_fmconfig_num_ai = -1;
89 static int hf_selfm_fmconfig_num_samp = -1;
90 static int hf_selfm_fmconfig_num_dig = -1;
91 static int hf_selfm_fmconfig_num_calc = -1;
92 static int hf_selfm_fmconfig_ofs_ai = -1;
93 static int hf_selfm_fmconfig_ofs_ts = -1;
94 static int hf_selfm_fmconfig_ofs_dig = -1;
95 static int hf_selfm_fmconfig_ai_type = -1;
96 static int hf_selfm_fmconfig_ai_sf_type = -1;
97 static int hf_selfm_fmconfig_ai_sf_ofs = -1;
98 static int hf_selfm_fmconfig_cblk_rot = -1;
99 static int hf_selfm_fmconfig_cblk_vconn = -1;
100 static int hf_selfm_fmconfig_cblk_iconn = -1;
101 static int hf_selfm_fmconfig_cblk_ctype = -1;
102 static int hf_selfm_fmconfig_cblk_deskew_ofs = -1;
103 static int hf_selfm_fmconfig_cblk_rs_ofs = -1;
104 static int hf_selfm_fmconfig_cblk_xs_ofs = -1;
105 static int hf_selfm_fmconfig_cblk_ia_idx = -1;
106 static int hf_selfm_fmconfig_cblk_ib_idx = -1;
107 static int hf_selfm_fmconfig_cblk_ic_idx = -1;
108 static int hf_selfm_fmconfig_cblk_va_idx = -1;
109 static int hf_selfm_fmconfig_cblk_vb_idx = -1;
110 static int hf_selfm_fmconfig_cblk_vc_idx = -1;
111 static int hf_selfm_fmdata_len = -1;
112 static int hf_selfm_fmdata_flagbyte = -1;
113 static int hf_selfm_fmdata_dig_b0 = -1;
114 static int hf_selfm_fmdata_dig_b1 = -1;
115 static int hf_selfm_fmdata_dig_b2 = -1;
116 static int hf_selfm_fmdata_dig_b3 = -1;
117 static int hf_selfm_fmdata_dig_b4 = -1;
118 static int hf_selfm_fmdata_dig_b5 = -1;
119 static int hf_selfm_fmdata_dig_b6 = -1;
120 static int hf_selfm_fmdata_dig_b7 = -1;
121 static int hf_selfm_fmdata_ai_sf_fp = -1;
122 static int hf_selfm_foconfig_len = -1;
123 static int hf_selfm_foconfig_num_brkr = -1;
124 static int hf_selfm_foconfig_num_rb = -1;
125 static int hf_selfm_foconfig_prb_supp = -1;
126 static int hf_selfm_foconfig_reserved = -1;
127 static int hf_selfm_foconfig_brkr_open = -1;
128 static int hf_selfm_foconfig_brkr_close = -1;
129 static int hf_selfm_foconfig_rb_cmd = -1;
130 static int hf_selfm_fastop_len = -1;
131 static int hf_selfm_fastop_rb_code = -1;
132 static int hf_selfm_fastop_br_code = -1;
133 static int hf_selfm_fastop_valid = -1;
134 static int hf_selfm_alt_foconfig_len = -1;
135 static int hf_selfm_alt_foconfig_num_ports = -1;
136 static int hf_selfm_alt_foconfig_num_brkr = -1;
137 static int hf_selfm_alt_foconfig_num_rb = -1;
138 static int hf_selfm_alt_foconfig_funccode = -1;
139 static int hf_selfm_alt_fastop_len = -1;
140 static int hf_selfm_alt_fastop_code = -1;
141 static int hf_selfm_alt_fastop_valid = -1;
143 static int hf_selfm_fastser_len = -1;
144 static int hf_selfm_fastser_routing_addr = -1;
145 static int hf_selfm_fastser_status = -1;
146 static int hf_selfm_fastser_funccode = -1;
147 static int hf_selfm_fastser_seq = -1;
148 static int hf_selfm_fastser_seq_fir = -1;
149 static int hf_selfm_fastser_seq_fin = -1;
150 static int hf_selfm_fastser_seq_cnt = -1;
151 static int hf_selfm_fastser_resp_num = -1;
152 static int hf_selfm_fastser_crc16 = -1;
153 static int hf_selfm_fastser_def_route_sup = -1;
154 static int hf_selfm_fastser_def_rx_stat = -1;
155 static int hf_selfm_fastser_def_tx_stat = -1;
156 static int hf_selfm_fastser_def_rx_maxfr = -1;
157 static int hf_selfm_fastser_def_tx_maxfr = -1;
158 static int hf_selfm_fastser_def_rx_num_fc = -1;
159 static int hf_selfm_fastser_def_rx_fc = -1;
160 static int hf_selfm_fastser_def_tx_num_fc = -1;
161 static int hf_selfm_fastser_def_tx_fc = -1;
162 static int hf_selfm_fastser_uns_en_fc = -1;
163 static int hf_selfm_fastser_uns_en_fc_data = -1;
164 static int hf_selfm_fastser_uns_dis_fc = -1;
165 static int hf_selfm_fastser_uns_dis_fc_data = -1;
166 static int hf_selfm_fastser_baseaddr = -1;
167 static int hf_selfm_fastser_numwords = -1;
168 static int hf_selfm_fastser_flags = -1;
169 static int hf_selfm_fastser_datafmt_resp_numitem = -1;
170 static int hf_selfm_fastser_dataitem_qty = -1;
171 static int hf_selfm_fastser_dataitem_type = -1;
172 static int hf_selfm_fastser_dataitem_uint16 = -1;
173 static int hf_selfm_fastser_dataitem_int16 = -1;
174 static int hf_selfm_fastser_dataitem_uint32 = -1;
175 static int hf_selfm_fastser_dataitem_int32 = -1;
176 static int hf_selfm_fastser_dataitem_float = -1;
177 static int hf_selfm_fastser_devdesc_num_region = -1;
178 static int hf_selfm_fastser_devdesc_num_ctrl = -1;
179 static int hf_selfm_fastser_unsresp_orig = -1;
180 static int hf_selfm_fastser_unsresp_doy = -1;
181 static int hf_selfm_fastser_unsresp_year = -1;
182 static int hf_selfm_fastser_unsresp_todms = -1;
183 static int hf_selfm_fastser_unsresp_num_elmt = -1;
184 static int hf_selfm_fastser_unsresp_elmt_idx = -1;
185 static int hf_selfm_fastser_unsresp_elmt_ts_ofs = -1;
186 static int hf_selfm_fastser_unsresp_elmt_status = -1;
187 static int hf_selfm_fastser_unsresp_eor = -1;
188 static int hf_selfm_fastser_unsresp_elmt_statword = -1;
189 static int hf_selfm_fastser_unswrite_addr1 = -1;
190 static int hf_selfm_fastser_unswrite_addr2 = -1;
191 static int hf_selfm_fastser_unswrite_num_reg = -1;
192 static int hf_selfm_fastser_unswrite_reg_val = -1;
193 static int hf_selfm_fastser_soe_req_orig = -1;
194 static int hf_selfm_fastser_soe_resp_numblks = -1;
195 static int hf_selfm_fastser_soe_resp_orig = -1;
196 static int hf_selfm_fastser_soe_resp_numbits = -1;
197 static int hf_selfm_fastser_soe_resp_pad = -1;
198 static int hf_selfm_fastser_soe_resp_doy = -1;
199 static int hf_selfm_fastser_soe_resp_year = -1;
200 static int hf_selfm_fastser_soe_resp_tod = -1;
201 /* static int hf_selfm_fastser_soe_resp_data = -1; */
204 /* Initialize the subtree pointers */
205 static gint ett_selfm = -1;
206 static gint ett_selfm_relaydef = -1;
207 static gint ett_selfm_relaydef_fm = -1;
208 static gint ett_selfm_relaydef_proto = -1;
209 static gint ett_selfm_relaydef_flags = -1;
210 static gint ett_selfm_fmconfig = -1;
211 static gint ett_selfm_fmconfig_ai = -1;
212 static gint ett_selfm_fmconfig_calc = -1;
213 static gint ett_selfm_foconfig = -1;
214 static gint ett_selfm_foconfig_brkr = -1;
215 static gint ett_selfm_foconfig_rb = -1;
216 static gint ett_selfm_fastop = -1;
217 static gint ett_selfm_fmdata = -1;
218 static gint ett_selfm_fmdata_ai = -1;
219 static gint ett_selfm_fmdata_dig = -1;
220 static gint ett_selfm_fmdata_ai_ch = -1;
221 static gint ett_selfm_fmdata_dig_ch = -1;
222 static gint ett_selfm_fastser = -1;
223 static gint ett_selfm_fastser_seq = -1;
224 static gint ett_selfm_fastser_def_fc = -1;
225 static gint ett_selfm_fastser_datareg = -1;
226 static gint ett_selfm_fastser_tag = -1;
227 static gint ett_selfm_fastser_element_list = -1;
228 static gint ett_selfm_fastser_element = -1;
230 #define PORT_SELFM 0
232 #define CMD_FAST_SER 0xA546
233 #define CMD_CLEAR_STATBIT 0xA5B9
234 #define CMD_RELAY_DEF 0xA5C0
235 #define CMD_FM_CONFIG 0xA5C1
236 #define CMD_DFM_CONFIG 0xA5C2
237 #define CMD_PDFM_CONFIG 0xA5C3
238 #define CMD_FASTOP_RESETDEF 0xA5CD
239 #define CMD_FASTOP_CONFIG 0xA5CE
240 #define CMD_ALT_FASTOP_CONFIG 0xA5CF
241 #define CMD_FM_DATA 0xA5D1
242 #define CMD_DFM_DATA 0xA5D2
243 #define CMD_PDFM_DATA 0xA5D3
244 #define CMD_FASTOP_RB_CTRL 0xA5E0
245 #define CMD_FASTOP_BR_CTRL 0xA5E3
246 #define CMD_ALT_FASTOP_OPEN 0xA5E5
247 #define CMD_ALT_FASTOP_CLOSE 0xA5E6
248 #define CMD_ALT_FASTOP_SET 0xA5E7
249 #define CMD_ALT_FASTOP_CLEAR 0xA5E8
250 #define CMD_ALT_FASTOP_PULSE 0xA5E9
251 #define CMD_FASTOP_RESET 0xA5ED
253 #define FM_CONFIG_SF_LOC_FM 0
254 #define FM_CONFIG_SF_LOC_CFG 1
256 #define FM_CONFIG_ANA_CHNAME_LEN 6
257 #define FM_CONFIG_ANA_CHTYPE_INT16 0x00
258 #define FM_CONFIG_ANA_CHTYPE_FP 0x01
259 #define FM_CONFIG_ANA_CHTYPE_FPD 0x02
260 #define FM_CONFIG_ANA_CHTYPE_TS 0x03
261 #define FM_CONFIG_ANA_CHTYPE_TS_LEN 8
263 #define FM_CONFIG_ANA_SFTYPE_INT16 0x00
264 #define FM_CONFIG_ANA_SFTYPE_FP 0x01
265 #define FM_CONFIG_ANA_SFTYPE_FPD 0x02
266 #define FM_CONFIG_ANA_SFTYPE_TS 0x03
267 #define FM_CONFIG_ANA_SFTYPE_NONE 0xFF
270 /* Fast SER Function Codes, "response" or "ACK" messages are the same as the request, but have the MSB set */
271 #define FAST_SER_MESSAGE_DEF 0x00
272 #define FAST_SER_EN_UNS_DATA 0x01
273 #define FAST_SER_DIS_UNS_DATA 0x02
274 #define FAST_SER_PING 0x05
275 #define FAST_SER_READ_REQ 0x10
276 #define FAST_SER_GEN_UNS_DATA 0x12
277 #define FAST_SER_SOE_STATE_REQ 0x16
278 #define FAST_SER_UNS_RESP 0x18
279 #define FAST_SER_UNS_WRITE 0x20
280 #define FAST_SER_UNS_WRITE_REQ 0x21
281 #define FAST_SER_DEVDESC_REQ 0x30
282 #define FAST_SER_DATAFMT_REQ 0x31
283 #define FAST_SER_UNS_DATAFMT_RESP 0x32
284 #define FAST_SER_BITLABEL_REQ 0x33
285 #define FAST_SER_MGMT_REQ 0x40
286 #define FAST_SER_MESSAGE_DEF_ACK 0x80
287 #define FAST_SER_EN_UNS_DATA_ACK 0x81
288 #define FAST_SER_DIS_UNS_DATA_ACK 0x82
289 #define FAST_SER_PING_ACK 0x85
290 #define FAST_SER_READ_RESP 0x90
291 #define FAST_SER_SOE_STATE_RESP 0x96
292 #define FAST_SER_UNS_RESP_ACK 0x98
293 #define FAST_SER_DEVDESC_RESP 0xB0
294 #define FAST_SER_DATAFMT_RESP 0xB1
295 #define FAST_SER_BITLABEL_RESP 0xB3
298 /* Fast SER Sequence Byte Masks */
299 #define FAST_SER_SEQ_FIR 0x80
300 #define FAST_SER_SEQ_FIN 0x40
301 #define FAST_SER_SEQ_CNT 0x3f
303 /* Fast SER Tag Data Types */
304 #define FAST_SER_TAGTYPE_CHAR8 0x0011 /* 1 x 8-bit character per item */
305 #define FAST_SER_TAGTYPE_CHAR16 0x0012 /* 2 x 8-bit characters per item */
306 #define FAST_SER_TAGTYPE_DIGWORD8_BL 0x0021 /* 8-bit binary item, with labels */
307 #define FAST_SER_TAGTYPE_DIGWORD8 0x0022 /* 8-bit binary item, without labels */
308 #define FAST_SER_TAGTYPE_DIGWORD16_BL 0x0023 /* 16-bit binary item, with labels */
309 #define FAST_SER_TAGTYPE_DIGWORD16 0x0024 /* 16-bit binary item, without labels */
310 #define FAST_SER_TAGTYPE_INT16 0x0031 /* 16-bit signed integer */
311 #define FAST_SER_TAGTYPE_UINT16 0x0032 /* 16-bit unsigned integer */
312 #define FAST_SER_TAGTYPE_INT32 0x0033 /* 32-bit signed integer */
313 #define FAST_SER_TAGTYPE_UINT32 0x0034 /* 32-bit unsigned integer */
314 #define FAST_SER_TAGTYPE_FLOAT 0x0041 /* 32-bit floating point */
317 /* Globals for SEL Protocol Preferences */
318 static gboolean selfm_desegment = TRUE;
319 static gboolean selfm_telnet_clean = TRUE;
320 static guint global_selfm_tcp_port = PORT_SELFM; /* Port 0, by default */
322 /***************************************************************************************/
323 /* Fast Meter Message structs */
324 /***************************************************************************************/
325 /* Holds Configuration Information required to decode a Fast Meter analog value */
326 typedef struct {
327 gchar name[FM_CONFIG_ANA_CHNAME_LEN+1]; /* Name of Analog Channel, 6 char + a null */
328 guint8 type; /* Analog Channel Type, Int, FP, etc */
329 guint8 sf_type; /* Analog Scale Factor Type, none, etc */
330 guint16 sf_offset; /* Analog Scale Factor Offset */
331 } fm_analog_info;
333 /* Holds Information from a single "Fast Meter Configuration" frame. Required to dissect subsequent "Data" frames. */
334 typedef struct {
335 guint32 fnum; /* frame number */
336 guint16 cfg_cmd; /* holds ID of config command, ie: 0xa5c1 */
337 guint8 num_flags; /* Number of Flag Bytes */
338 guint8 num_ai; /* Number of Analog Inputs */
339 guint8 num_ai_samples; /* Number samples per Analog Input */
340 guint16 offset_ai; /* Start Offset of Analog Inputs */
341 guint8 num_dig; /* Number of Digital Input Blocks */
342 guint16 offset_dig; /* Start Offset of Digital Inputs */
343 guint16 offset_ts; /* Start Offset of Time Stamp */
344 guint8 num_calc; /* Number of Calculations */
345 fm_analog_info *analogs; /* Array of fm_analog_infos */
346 } fm_config_frame;
348 /**************************************************************************************/
349 /* Fast SER Message Data Item struct */
350 /**************************************************************************************/
351 /* Holds Configuration Information required to decode a Fast SER Data Item */
352 /* Each data region format is returned as a sequential list of tags, w/o reference to */
353 /* an absolute address. The format information will consist of a name, a data type */
354 /* and a quantity of values contained within the data item. We will retrieve this */
355 /* format information later while attempting to dissect Read Response frames */
356 typedef struct {
357 guint32 fnum; /* frame number */
358 guint32 base_address; /* Base address of Data Item Region */
359 guint8 index_pos; /* Index Offset Position within data format message (1-16) */
360 gchar name[10+1]; /* Name of Data Item, 10 chars, null-terminated */
361 guint16 quantity; /* Quantity of values within Data Item */
362 guint16 data_type; /* Data Item Type, Char, Int, FP, etc */
363 } fastser_dataitem;
365 /**************************************************************************************/
366 /* Fast SER Message Data Region struct */
367 /**************************************************************************************/
368 /* Holds Configuration Information required to decode a Fast SER Data Region */
369 /* Each data region format is returned as a sequential list of tags, w/o reference to */
370 typedef struct {
371 gchar name[10+1]; /* Name of Data Region, 10 chars, null-terminated */
372 } fastser_dataregion;
374 /**************************************************************************************/
375 /* Fast Message Conversation struct */
376 /**************************************************************************************/
377 typedef struct {
378 wmem_list_t *fm_config_frames; /* List contains a fm_config_data struct for each Fast Meter configuration frame */
379 wmem_list_t *fastser_dataitems; /* List contains a fastser_dataitem struct for each Fast SER Data Item */
380 wmem_tree_t *fastser_dataregions; /* Tree contains a fastser_dataregion struct for each Fast SER Data Region */
381 } fm_conversation;
384 static const value_string selfm_msgtype_vals[] = {
385 { CMD_FAST_SER, "Fast SER Block" }, /* 0xA546 */
386 { CMD_CLEAR_STATBIT, "Clear Status Bits Command" }, /* 0xA5B9 */
387 { CMD_RELAY_DEF, "Relay Definition Block" }, /* 0xA5C0 */
388 { CMD_FM_CONFIG, "Fast Meter Configuration Block" }, /* 0xA5C1 */
389 { CMD_DFM_CONFIG, "Demand Fast Meter Configuration Block" }, /* 0xA5C2 */
390 { CMD_PDFM_CONFIG, "Peak Demand Fast Meter Configuration Block" }, /* 0xA5C3 */
391 { CMD_FASTOP_RESETDEF, "Fast Operate Reset Definition" }, /* 0xA5CD */
392 { CMD_FASTOP_CONFIG, "Fast Operate Configuration" }, /* 0xA5CE */
393 { CMD_ALT_FASTOP_CONFIG, "Alternate Fast Operate Configuration" }, /* 0xA5CF */
394 { CMD_FM_DATA, "Fast Meter Data Block" }, /* 0xA5D1 */
395 { CMD_DFM_DATA, "Demand Fast Meter Data Block" }, /* 0xA5D2 */
396 { CMD_PDFM_DATA, "Peak Demand Fast Meter Data Block" }, /* 0xA5D3 */
397 { CMD_FASTOP_RB_CTRL, "Fast Operate Remote Bit Control" }, /* 0xA5E0 */
398 { CMD_FASTOP_BR_CTRL, "Fast Operate Breaker Bit Control" }, /* 0xA5E3 */
399 { CMD_ALT_FASTOP_OPEN, "Alternate Fast Operate Open Breaker Control" }, /* 0xA5E5 */
400 { CMD_ALT_FASTOP_CLOSE, "Alternate Fast Operate Close Breaker Control" }, /* 0xA5E6 */
401 { CMD_ALT_FASTOP_SET, "Alternate Fast Operate Set Remote Bit Control" }, /* 0xA5E7 */
402 { CMD_ALT_FASTOP_CLEAR, "Alternate Fast Operate Clear Remote Bit Control" }, /* 0xA5E8 */
403 { CMD_ALT_FASTOP_PULSE, "Alternate Fast Operate Pulse Remote Bit Control" }, /* 0xA5E9 */
404 { CMD_FASTOP_RESET, "Fast Operate Reset" }, /* 0xA5ED */
405 { 0, NULL }
407 static value_string_ext selfm_msgtype_vals_ext = VALUE_STRING_EXT_INIT(selfm_msgtype_vals);
409 static const value_string selfm_relaydef_proto_vals[] = {
410 { 0x0000, "SEL Fast Meter" },
411 { 0x0001, "SEL Limited Multidrop (LMD)" },
412 { 0x0002, "Modbus" },
413 { 0x0003, "SY/MAX" },
414 { 0x0004, "SEL Relay-to-Relay" },
415 { 0x0005, "DNP 3.0" },
416 { 0x0006, "SEL Mirrored Bits" },
417 { 0x0007, "IEEE 37.118 Synchrophasors" },
418 { 0x0008, "IEC 61850" },
419 { 0x0100, "SEL Fast Meter w/ Fast Operate" },
420 { 0x0101, "SEL Limited Multidrop (LMD) w/ Fast Operate" },
421 { 0x0200, "SEL Fast Meter w/ Fast SER" },
422 { 0x0300, "SEL Fast Meter w/ Fast Operate and Fast SER" },
423 { 0x0301, "SEL Limited Multidrop (LMD) w/ Fast Operate and Fast SER" },
424 { 0, NULL }
426 static value_string_ext selfm_relaydef_proto_vals_ext = VALUE_STRING_EXT_INIT(selfm_relaydef_proto_vals);
428 static const value_string selfm_fmconfig_ai_chtype_vals[] = {
429 { FM_CONFIG_ANA_CHTYPE_INT16, "16-Bit Integer" },
430 { FM_CONFIG_ANA_CHTYPE_FP, "IEEE Floating Point" },
431 { FM_CONFIG_ANA_CHTYPE_FPD, "IEEE Floating Point (Double)" },
432 { FM_CONFIG_ANA_CHTYPE_TS, "8-byte Time Stamp" },
433 { 0, NULL }
436 static const value_string selfm_fmconfig_ai_sftype_vals[] = {
437 { FM_CONFIG_ANA_SFTYPE_INT16, "16-Bit Integer" },
438 { FM_CONFIG_ANA_SFTYPE_FP, "IEEE Floating Point" },
439 { FM_CONFIG_ANA_SFTYPE_FPD, "IEEE Floating Point (Double)" },
440 { FM_CONFIG_ANA_SFTYPE_TS, "8-byte Time Stamp" },
441 { FM_CONFIG_ANA_SFTYPE_NONE, "None" },
442 { 0, NULL }
445 static const value_string selfm_fmconfig_sfloc_vals[] = {
446 { FM_CONFIG_SF_LOC_FM, "In Fast Meter Message" },
447 { FM_CONFIG_SF_LOC_CFG, "In Configuration Message" },
448 { 0, NULL }
451 /* Depending on number of analog samples present in Fast Meter Messages, identification of data will change */
452 static const value_string selfm_fmconfig_numsamples1_vals[] = {
453 { 1, "Magnitudes Only" },
454 { 0, NULL }
457 static const value_string selfm_fmconfig_numsamples2_vals[] = {
458 { 1, "Imaginary Components" },
459 { 2, "Real Components" },
460 { 0, NULL }
463 static const value_string selfm_fmconfig_numsamples4_vals[] = {
464 { 1, "1st Quarter Cycle Data" },
465 { 2, "2nd Quarter Cycle Data" },
466 { 3, "5th Quarter-Cycle Data" },
467 { 4, "6th Quarter-Cycle Data" },
468 { 0, NULL }
471 /* Calculation Block lookup values */
472 static const value_string selfm_fmconfig_cblk_rot_vals[] = {
473 { 0x00, "ABC Rotation" },
474 { 0x01, "ACB Rotation" },
475 { 0, NULL }
478 static const value_string selfm_fmconfig_cblk_vconn_vals[] = {
479 { 0x00, "Y-Connected" },
480 { 0x01, "Delta-Connected (in seq. Vab, Vbc, Vca)" },
481 { 0x02, "Delta-Connected (in seq. Vac, Vba, Vcb)" },
482 { 0, NULL }
485 static const value_string selfm_fmconfig_cblk_iconn_vals[] = {
486 { 0x00, "Y-Connected" },
487 { 0x01, "Delta-Connected (in seq. Iab, Ibc, Ica)" },
488 { 0x02, "Delta-Connected (in seq. Iac, Iba, Icb)" },
489 { 0, NULL }
492 static const value_string selfm_fmconfig_cblk_ctype_vals[] = {
493 { 0, "Standard Power Calculations" },
494 { 1, "2-1/2 Element Delta Power Calculation" },
495 { 2, "Voltages-Only" },
496 { 3, "Currents-Only" },
497 { 4, "Single-Phase Ia and Va Only" },
498 { 5, "Standard Power Calcs with 2 sets of Currents" },
499 { 6, "2-1/2 Element Delta Power Calcs with 2 sets of Currents" },
500 { 0, NULL }
503 /* Fast Operate Remote Bit 'Pulse Supported' Lookup */
504 static const value_string selfm_foconfig_prb_supp_vals[] = {
505 { 0x00, "No" },
506 { 0x01, "Yes" },
507 { 0, NULL }
510 /* SER Status Value Lookup */
511 static const value_string selfm_ser_status_vals[] = {
512 { 0x00, "Deasserted" },
513 { 0x01, "Asserted" },
514 { 0, NULL }
517 /* Fast Operate Remote Bit Lookup */
518 static const value_string selfm_fo_rb_vals[] = {
519 { 0x00, "RB01 Clear" },
520 { 0x20, "RB01 Set" },
521 { 0x40, "RB01 Pulse" },
522 { 0x01, "RB02 Clear" },
523 { 0x21, "RB02 Set" },
524 { 0x41, "RB02 Pulse" },
525 { 0x02, "RB03 Clear" },
526 { 0x22, "RB03 Set" },
527 { 0x42, "RB03 Pulse" },
528 { 0x03, "RB04 Clear" },
529 { 0x23, "RB04 Set" },
530 { 0x43, "RB04 Pulse" },
531 { 0x04, "RB05 Clear" },
532 { 0x24, "RB05 Set" },
533 { 0x44, "RB05 Pulse" },
534 { 0x05, "RB06 Clear" },
535 { 0x25, "RB06 Set" },
536 { 0x45, "RB06 Pulse" },
537 { 0x06, "RB07 Clear" },
538 { 0x26, "RB07 Set" },
539 { 0x46, "RB07 Pulse" },
540 { 0x07, "RB08 Clear" },
541 { 0x27, "RB08 Set" },
542 { 0x47, "RB08 Pulse" },
543 { 0x08, "RB09 Clear" },
544 { 0x28, "RB09 Set" },
545 { 0x48, "RB09 Pulse" },
546 { 0x09, "RB10 Clear" },
547 { 0x29, "RB10 Set" },
548 { 0x49, "RB10 Pulse" },
549 { 0x0A, "RB11 Clear" },
550 { 0x2A, "RB11 Set" },
551 { 0x4A, "RB11 Pulse" },
552 { 0x0B, "RB12 Clear" },
553 { 0x2B, "RB12 Set" },
554 { 0x4B, "RB12 Pulse" },
555 { 0x0C, "RB13 Clear" },
556 { 0x2C, "RB13 Set" },
557 { 0x4C, "RB13 Pulse" },
558 { 0x0D, "RB14 Clear" },
559 { 0x2D, "RB14 Set" },
560 { 0x4D, "RB14 Pulse" },
561 { 0x0E, "RB15 Clear" },
562 { 0x2E, "RB15 Set" },
563 { 0x4E, "RB15 Pulse" },
564 { 0x0F, "RB16 Clear" },
565 { 0x2F, "RB16 Set" },
566 { 0x4F, "RB16 Pulse" },
567 { 0x10, "RB17 Clear" },
568 { 0x30, "RB17 Set" },
569 { 0x50, "RB17 Pulse" },
570 { 0x11, "RB18 Clear" },
571 { 0x31, "RB18 Set" },
572 { 0x51, "RB18 Pulse" },
573 { 0x12, "RB19 Clear" },
574 { 0x32, "RB19 Set" },
575 { 0x52, "RB19 Pulse" },
576 { 0x13, "RB20 Clear" },
577 { 0x33, "RB20 Set" },
578 { 0x53, "RB20 Pulse" },
579 { 0x14, "RB21 Clear" },
580 { 0x34, "RB21 Set" },
581 { 0x54, "RB21 Pulse" },
582 { 0x15, "RB22 Clear" },
583 { 0x35, "RB22 Set" },
584 { 0x55, "RB22 Pulse" },
585 { 0x16, "RB23 Clear" },
586 { 0x36, "RB23 Set" },
587 { 0x56, "RB23 Pulse" },
588 { 0x17, "RB24 Clear" },
589 { 0x37, "RB24 Set" },
590 { 0x57, "RB24 Pulse" },
591 { 0x18, "RB25 Clear" },
592 { 0x38, "RB25 Set" },
593 { 0x58, "RB25 Pulse" },
594 { 0x19, "RB26 Clear" },
595 { 0x39, "RB26 Set" },
596 { 0x59, "RB26 Pulse" },
597 { 0x1A, "RB27 Clear" },
598 { 0x3A, "RB27 Set" },
599 { 0x5A, "RB27 Pulse" },
600 { 0x1B, "RB28 Clear" },
601 { 0x3B, "RB28 Set" },
602 { 0x5B, "RB28 Pulse" },
603 { 0x1C, "RB29 Clear" },
604 { 0x3C, "RB29 Set" },
605 { 0x5C, "RB29 Pulse" },
606 { 0x1D, "RB30 Clear" },
607 { 0x3D, "RB30 Set" },
608 { 0x5D, "RB30 Pulse" },
609 { 0x1E, "RB31 Clear" },
610 { 0x3E, "RB31 Set" },
611 { 0x5E, "RB31 Pulse" },
612 { 0x1F, "RB32 Clear" },
613 { 0x3F, "RB32 Set" },
614 { 0x5F, "RB32 Pulse" },
615 { 0, NULL }
618 /* Fast Operate Breaker Bit Lookup */
619 static const value_string selfm_fo_br_vals[] = {
620 { 0x31, "Breaker Bit 1 Open (OC/OC1)" },
621 { 0x11, "Breaker Bit 1 Close (CC/CC1)" },
622 { 0x32, "Breaker Bit 2 Open (OC2)" },
623 { 0x12, "Breaker Bit 2 Close (CC2)" },
624 { 0x33, "Breaker Bit 3 Open (OC3)" },
625 { 0x13, "Breaker Bit 3 Close (CC3)" },
626 { 0x34, "Breaker Bit 4 Open (OC4)" },
627 { 0x14, "Breaker Bit 4 Close (CC4)" },
628 { 0x35, "Breaker Bit 5 Open (OC5)" },
629 { 0x15, "Breaker Bit 5 Close (CC5)" },
630 { 0x36, "Breaker Bit 6 Open (OC6)" },
631 { 0x16, "Breaker Bit 6 Close (CC6)" },
632 { 0x37, "Breaker Bit 7 Open (OC7)" },
633 { 0x17, "Breaker Bit 7 Close (CC7)" },
634 { 0x38, "Breaker Bit 8 Open (OC8)" },
635 { 0x18, "Breaker Bit 8 Close (CC8)" },
636 { 0x39, "Breaker Bit 9 Open (OC9)" },
637 { 0x19, "Breaker Bit 9 Close (CC9)" },
638 { 0x3A, "Breaker Bit 10 Open (OC10)" },
639 { 0x1A, "Breaker Bit 10 Close (CC10)" },
640 { 0x3B, "Breaker Bit 11 Open (OC11)" },
641 { 0x1B, "Breaker Bit 11 Close (CC11)" },
642 { 0x3C, "Breaker Bit 12 Open (OC12)" },
643 { 0x1C, "Breaker Bit 12 Close (CC12)" },
644 { 0x3D, "Breaker Bit 13 Open (OC13)" },
645 { 0x1D, "Breaker Bit 13 Close (CC13)" },
646 { 0x3E, "Breaker Bit 14 Open (OC14)" },
647 { 0x1E, "Breaker Bit 14 Close (CC14)" },
648 { 0x3F, "Breaker Bit 15 Open (OC15)" },
649 { 0x1F, "Breaker Bit 15 Close (CC15)" },
650 { 0x40, "Breaker Bit 16 Open (OC16)" },
651 { 0x20, "Breaker Bit 16 Close (CC16)" },
652 { 0x41, "Breaker Bit 17 Open (OC17)" },
653 { 0x21, "Breaker Bit 17 Close (CC17)" },
654 { 0x42, "Breaker Bit 18 Open (OC18)" },
655 { 0x22, "Breaker Bit 18 Close (CC18)" },
656 { 0, NULL }
659 /* Alternate Fast Operate Function Code Lookup */
660 static const value_string selfm_foconfig_alt_funccode_vals[] = {
661 { 0xE5, "Open Breaker Bit" },
662 { 0xE6, "Close Breaker Bit" },
663 { 0xE7, "Set Remote Bit" },
664 { 0xE8, "Clear Remote Bit" },
665 { 0xE9, "Pulse Remote Bit" },
666 { 0x00, "Unsupported" },
667 { 0, NULL }
670 /* Fast SER Message Function Codes */
671 static const value_string selfm_fastser_func_code_vals[] = {
672 { FAST_SER_MESSAGE_DEF, "Fast SER Message Definition Block" },
673 { FAST_SER_MESSAGE_DEF_ACK, "Fast SER Message Definition Block ACK" },
674 { FAST_SER_EN_UNS_DATA, "Enable Unsolicited Data" },
675 { FAST_SER_EN_UNS_DATA_ACK, "Enable Unsolicited Data ACK" },
676 { FAST_SER_DIS_UNS_DATA, "Disable Unsolicited Data" },
677 { FAST_SER_DIS_UNS_DATA_ACK, "Disable Unsolicited Data ACK" },
678 { FAST_SER_PING, "Ping Message" },
679 { FAST_SER_PING_ACK, "Ping Message ACK" },
680 { FAST_SER_READ_REQ, "Read Request" },
681 { FAST_SER_READ_RESP, "Read Response" },
682 { FAST_SER_GEN_UNS_DATA, "Generic Unsolicited Data" },
683 { FAST_SER_SOE_STATE_REQ, "SOE Present State Request" },
684 { FAST_SER_SOE_STATE_RESP, "SOE Present State Response" },
685 { FAST_SER_UNS_RESP, "Unsolicited Fast SER Data Response" },
686 { FAST_SER_UNS_RESP_ACK, "Unsolicited Fast SER Data Response ACK" },
687 { FAST_SER_UNS_WRITE, "Unsolicited Write" },
688 { FAST_SER_UNS_WRITE_REQ, "Unsolicited Write Request" },
689 { FAST_SER_DEVDESC_REQ, "Device Description Request" },
690 { FAST_SER_DEVDESC_RESP, "Device Description Response" },
691 { FAST_SER_DATAFMT_REQ, "Data Format Request" },
692 { FAST_SER_DATAFMT_RESP, "Data Format Response" },
693 { FAST_SER_UNS_DATAFMT_RESP, "Unsolicited Data Format Response" },
694 { FAST_SER_BITLABEL_REQ, "Bit Label Request" },
695 { FAST_SER_BITLABEL_RESP, "Bit Label Response" },
696 { FAST_SER_MGMT_REQ, "Management Request" },
697 { 0, NULL }
700 #if 0
701 static const value_string selfm_fastser_seq_vals[] = {
702 { FAST_SER_SEQ_FIN, "FIN" },
703 { FAST_SER_SEQ_FIR, "FIR" },
704 { 0, NULL }
706 #endif
708 static const value_string selfm_fastser_tagtype_vals[] = {
709 { FAST_SER_TAGTYPE_CHAR8, "1 x 8-bit character per item" },
710 { FAST_SER_TAGTYPE_CHAR16, "2 x 8-bit characters per item" },
711 { FAST_SER_TAGTYPE_DIGWORD8_BL, "8-bit binary item, with labels" },
712 { FAST_SER_TAGTYPE_DIGWORD8, "8-bit binary item, without labels" },
713 { FAST_SER_TAGTYPE_DIGWORD16_BL, "16-bit binary item, with labels" },
714 { FAST_SER_TAGTYPE_DIGWORD16, "16-bit binary item, without labels" },
715 { FAST_SER_TAGTYPE_INT16, "16-bit Signed Integer" },
716 { FAST_SER_TAGTYPE_UINT16, "16-bit Unsigned Integer" },
717 { FAST_SER_TAGTYPE_INT32, "32-bit Signed Integer" },
718 { FAST_SER_TAGTYPE_UINT32, "32-bit Unsigned Integer" },
719 { FAST_SER_TAGTYPE_FLOAT, "IEEE Floating Point" },
720 { 0, NULL }
724 /* Fast Message Unsolicited Write COM Port Codes */
725 static const value_string selfm_fastser_unswrite_com_vals[] = {
726 { 0x0100, "COM01" },
727 { 0x0200, "COM02" },
728 { 0x0300, "COM03" },
729 { 0x0400, "COM04" },
730 { 0x0500, "COM05" },
731 { 0x0600, "COM06" },
732 { 0x0700, "COM07" },
733 { 0x0800, "COM08" },
734 { 0x0900, "COM09" },
735 { 0x0A00, "COM10" },
736 { 0x0B00, "COM11" },
737 { 0x0C00, "COM12" },
738 { 0x0D00, "COM13" },
739 { 0x0E00, "COM14" },
740 { 0x0F00, "COM15" },
741 { 0, NULL }
744 /* Tables for reassembly of fragments. */
745 static reassembly_table selfm_reassembly_table;
747 /* ************************************************************************* */
748 /* Header values for reassembly */
749 /* ************************************************************************* */
750 static int hf_selfm_fragment = -1;
751 static int hf_selfm_fragments = -1;
752 static int hf_selfm_fragment_overlap = -1;
753 static int hf_selfm_fragment_overlap_conflict = -1;
754 static int hf_selfm_fragment_multiple_tails = -1;
755 static int hf_selfm_fragment_too_long_fragment = -1;
756 static int hf_selfm_fragment_error = -1;
757 static int hf_selfm_fragment_count = -1;
758 static int hf_selfm_fragment_reassembled_in = -1;
759 static int hf_selfm_fragment_reassembled_length = -1;
760 static gint ett_selfm_fragment = -1;
761 static gint ett_selfm_fragments = -1;
763 static const fragment_items selfm_frag_items = {
764 &ett_selfm_fragment,
765 &ett_selfm_fragments,
766 &hf_selfm_fragments,
767 &hf_selfm_fragment,
768 &hf_selfm_fragment_overlap,
769 &hf_selfm_fragment_overlap_conflict,
770 &hf_selfm_fragment_multiple_tails,
771 &hf_selfm_fragment_too_long_fragment,
772 &hf_selfm_fragment_error,
773 &hf_selfm_fragment_count,
774 &hf_selfm_fragment_reassembled_in,
775 &hf_selfm_fragment_reassembled_length,
776 /* Reassembled data field */
777 NULL,
778 "SEL Fast Message fragments"
781 /**********************************************************************************************************/
782 /* Clean all instances of 0xFFFF from Telnet payload to compensate for IAC control code (replace w/ 0xFF) */
783 /* Function Duplicated from packet-telnet.c (unescape_and_tvbuffify_telnet_option) */
784 /**********************************************************************************************************/
785 static tvbuff_t *
786 clean_telnet_iac(packet_info *pinfo, tvbuff_t *tvb, int offset, int len)
788 tvbuff_t *telnet_tvb;
789 guint8 *buf;
790 const guint8 *spos;
791 guint8 *dpos;
792 int skip_byte, len_remaining;
794 spos=tvb_get_ptr(tvb, offset, len);
795 buf=(guint8 *)g_malloc(len);
796 dpos=buf;
797 skip_byte = 0;
798 len_remaining = len;
799 while(len_remaining > 0){
801 /* Only analyze two sequential bytes of source tvb if we have at least two bytes left */
802 if (len_remaining > 1) {
803 /* If two sequential 0xFF's exist, increment skip_byte counter, decrement */
804 /* len_remaining by 2 and copy a single 0xFF to dest tvb. */
805 if((spos[0]==0xff) && (spos[1]==0xff)){
806 skip_byte++;
807 len_remaining -= 2;
808 *(dpos++)=0xff;
809 spos+=2;
810 continue;
813 /* If we only have a single byte left, or there were no sequential 0xFF's, copy byte from src tvb to dest tvb */
814 *(dpos++)=*(spos++);
815 len_remaining--;
817 telnet_tvb = tvb_new_child_real_data(tvb, buf, len-skip_byte, len-skip_byte);
818 tvb_set_free_cb(telnet_tvb, g_free);
819 add_new_data_source(pinfo, telnet_tvb, "Processed Telnet Data");
821 return telnet_tvb;
824 /******************************************************************************************************/
825 /* Execute dissection of Fast Meter configuration frames independent of any GUI access of said frames */
826 /* Load configuration information into fm_config_frame struct */
827 /******************************************************************************************************/
828 static fm_config_frame* fmconfig_frame_fast(tvbuff_t *tvb)
830 /* Set up structures needed to add the protocol subtree and manage it */
831 guint count, offset = 0;
832 fm_config_frame *frame;
834 /* get a new frame and initialize it */
835 frame = wmem_new(wmem_file_scope(), fm_config_frame);
837 /* Get data packet setup information from config message and copy into ai_info (if required) */
838 frame->cfg_cmd = tvb_get_ntohs(tvb, offset);
839 /* skip length byte, position offset+2 */
840 frame->num_flags = tvb_get_guint8(tvb, offset+3);
841 /* skip scale factor location, position offset+4 */
842 /* skip number of scale factors, position offset+5 */
843 frame->num_ai = tvb_get_guint8(tvb, offset+6);
844 frame->num_ai_samples = tvb_get_guint8(tvb, offset+7);
845 frame->num_dig = tvb_get_guint8(tvb, offset+8);
846 frame->num_calc = tvb_get_guint8(tvb, offset+9);
848 /* Update offset pointer */
849 offset += 10;
851 /* Get data packet analog/timestamp/digital offsets and copy into ai_info */
852 frame->offset_ai = tvb_get_ntohs(tvb, offset);
853 frame->offset_ts = tvb_get_ntohs(tvb, offset+2);
854 frame->offset_dig = tvb_get_ntohs(tvb, offset+4);
856 /* Update offset pointer */
857 offset += 6;
859 frame->analogs = (fm_analog_info *)wmem_alloc(wmem_file_scope(), frame->num_ai * sizeof(fm_analog_info));
861 /* Get AI Channel Details and copy into ai_info */
862 for (count = 0; count < frame->num_ai; count++) {
863 fm_analog_info *analog = &(frame->analogs[count]);
864 tvb_memcpy(tvb, analog->name, offset, FM_CONFIG_ANA_CHNAME_LEN);
865 analog->name[FM_CONFIG_ANA_CHNAME_LEN] = '\0'; /* Put a terminating null onto the end of the AI Channel name */
866 analog->type = tvb_get_guint8(tvb, offset+6);
867 analog->sf_type = tvb_get_guint8(tvb, offset+7);
868 analog->sf_offset = tvb_get_ntohs(tvb, offset+8);
870 offset += 10;
873 return frame;
877 /******************************************************************************************************/
878 /* Execute dissection of Data Item definition info before loading GUI tree */
879 /* Load configuration information into fastser_dataitem struct */
880 /******************************************************************************************************/
881 static fastser_dataitem* fastser_dataitem_save(tvbuff_t *tvb, int offset)
883 fastser_dataitem *dataitem;
885 /* get a new dataitem and initialize it */
886 dataitem = wmem_new(wmem_file_scope(), fastser_dataitem);
888 /* retrieve data item name and terminate with a null */
889 tvb_memcpy(tvb, dataitem->name, offset, 10);
890 dataitem->name[10] = '\0'; /* Put a terminating null onto the end of the string */
892 /* retrieve data item quantity and type */
893 dataitem->quantity = tvb_get_ntohs(tvb, offset+10);
894 dataitem->data_type = tvb_get_ntohs(tvb, offset+12);
896 return dataitem;
900 /******************************************************************************************************/
901 /* Execute dissection of Data Region definition info before loading GUI tree */
902 /* Load configuration information into fastser_dataregion struct */
903 /******************************************************************************************************/
904 static fastser_dataregion* fastser_dataregion_save(tvbuff_t *tvb, int offset)
906 fastser_dataregion *dataregion;
908 /* get a new dataregion and initialize it */
909 dataregion = wmem_new(wmem_file_scope(), fastser_dataregion);
911 /* retrieve data region name and terminate with a null */
912 tvb_memcpy(tvb, dataregion->name, offset, 10);
913 dataregion->name[10] = '\0'; /* Put a terminating null onto the end of the string */
915 return dataregion;
919 /********************************************************************************************************/
920 /* Lookup region name using current base address & saved conversation data. Return ptr to gchar string */
921 /********************************************************************************************************/
922 const gchar*
923 region_lookup(packet_info *pinfo, guint32 base_addr)
925 fm_conversation *conv;
926 fastser_dataregion *dataregion = NULL;
928 conv = (fm_conversation *)p_get_proto_data(pinfo->fd, proto_selfm, 0);
929 if (conv) {
930 dataregion = (fastser_dataregion*)wmem_tree_lookup32(conv->fastser_dataregions, base_addr);
933 if (dataregion) {
934 return dataregion->name;
937 /* If we couldn't identify the region using the current base address, return a default string */
938 return "Unknown Region";
941 /******************************************************************************************************/
942 /* Code to Dissect Relay Definition Frames */
943 /******************************************************************************************************/
944 static int
945 dissect_relaydef_frame(tvbuff_t *tvb, proto_tree *tree, int offset)
947 /* Set up structures needed to add the protocol subtree and manage it */
948 proto_item *relaydef_item, *relaydef_fm_item, *relaydef_flags_item, *relaydef_proto_item;
949 proto_tree *relaydef_tree, *relaydef_fm_tree, *relaydef_flags_tree, *relaydef_proto_tree;
950 guint8 len, num_proto, num_fm, num_flags;
951 int count;
953 len = tvb_get_guint8(tvb, offset);
954 num_proto = tvb_get_guint8(tvb, offset+1);
955 num_fm = tvb_get_guint8(tvb, offset+2);
956 num_flags = tvb_get_guint8(tvb, offset+3);
958 /* Add items to protocol tree specific to Relay Definition Block */
959 relaydef_item = proto_tree_add_text(tree, tvb, offset, len-2, "Relay Definition Block Details");
960 relaydef_tree = proto_item_add_subtree(relaydef_item, ett_selfm_relaydef);
962 /* Reported length */
963 proto_tree_add_item(relaydef_tree, hf_selfm_relaydef_len, tvb, offset, 1, ENC_BIG_ENDIAN);
965 /* Reported Number of Protocols Supported */
966 relaydef_proto_item = proto_tree_add_item(relaydef_tree, hf_selfm_relaydef_numproto, tvb, offset+1, 1, ENC_BIG_ENDIAN);
967 relaydef_proto_tree = proto_item_add_subtree(relaydef_proto_item, ett_selfm_relaydef_proto);
969 /* Reported Number of Fast Meter Commands Supported */
970 relaydef_fm_item = proto_tree_add_item(relaydef_tree, hf_selfm_relaydef_numfm, tvb, offset+2, 1, ENC_BIG_ENDIAN);
971 relaydef_fm_tree = proto_item_add_subtree(relaydef_fm_item, ett_selfm_relaydef_fm);
973 /* Reported Number of Status Bit Flags Supported */
974 relaydef_flags_item = proto_tree_add_item(relaydef_tree, hf_selfm_relaydef_numflags, tvb, offset+3, 1, ENC_BIG_ENDIAN);
975 relaydef_flags_tree = proto_item_add_subtree(relaydef_flags_item, ett_selfm_relaydef_flags);
977 /* Get our offset up-to-date */
978 offset += 4;
980 /* Add each reported Fast Meter cfg/data message */
981 for (count = 1; count <= num_fm; count++) {
982 proto_tree_add_item(relaydef_fm_tree, hf_selfm_relaydef_fmcfg_cmd, tvb, offset, 2, ENC_BIG_ENDIAN);
983 proto_tree_add_item(relaydef_fm_tree, hf_selfm_relaydef_fmdata_cmd, tvb, offset+2, 2, ENC_BIG_ENDIAN);
984 offset += 4;
987 /* Add each reported status bit flag, along with corresponding response command */
988 for (count = 1; count <= num_flags; count++) {
989 proto_tree_add_item(relaydef_flags_tree, hf_selfm_relaydef_statbit, tvb, offset, 2, ENC_BIG_ENDIAN);
990 proto_tree_add_item(relaydef_flags_tree, hf_selfm_relaydef_statbit_cmd, tvb, offset+2, 6, ENC_NA);
991 offset += 8;
994 /* Add each supported protocol */
995 for (count = 1; count <= num_proto; count++) {
996 proto_tree_add_item(relaydef_proto_tree, hf_selfm_relaydef_proto, tvb, offset, 2, ENC_BIG_ENDIAN);
997 offset += 2;
1000 /* Add Pad byte (if present) and checksum */
1001 if (tvb_reported_length_remaining(tvb, offset) > 1) {
1002 proto_tree_add_item(relaydef_tree, hf_selfm_padbyte, tvb, offset, 1, ENC_BIG_ENDIAN);
1003 offset += 1;
1006 proto_tree_add_item(relaydef_tree, hf_selfm_checksum, tvb, offset, 1, ENC_BIG_ENDIAN);
1008 return tvb_length(tvb);
1012 /******************************************************************************************************/
1013 /* Code to dissect Fast Meter Configuration Frames */
1014 /******************************************************************************************************/
1015 static int
1016 dissect_fmconfig_frame(tvbuff_t *tvb, proto_tree *tree, int offset)
1018 /* Set up structures needed to add the protocol subtree and manage it */
1019 proto_item *fmconfig_item, *fmconfig_ai_item=NULL, *fmconfig_calc_item=NULL;
1020 proto_tree *fmconfig_tree, *fmconfig_ai_tree=NULL, *fmconfig_calc_tree=NULL;
1021 guint count;
1022 guint8 len, num_ai, num_calc;
1023 gchar ai_name[FM_CONFIG_ANA_CHNAME_LEN+1]; /* 6 Characters + a Null */
1025 len = tvb_get_guint8(tvb, offset);
1026 /* skip num_flags, position offset+1 */
1027 /* skip sf_loc, position offset+2 */
1028 /* skip num_sf, position offset+3 */
1029 num_ai = tvb_get_guint8(tvb, offset+4);
1030 /* skip num_samp, position offset+5 */
1031 /* skip num_dig, position offset+6 */
1032 num_calc = tvb_get_guint8(tvb, offset+7);
1034 fmconfig_item = proto_tree_add_text(tree, tvb, offset, len, "Fast Meter Configuration Details");
1035 fmconfig_tree = proto_item_add_subtree(fmconfig_item, ett_selfm_fmconfig);
1037 /* Add items to protocol tree specific to Fast Meter Configuration Block */
1039 /* Get Setup Information for FM Config Block */
1040 proto_tree_add_item(fmconfig_tree, hf_selfm_fmconfig_len, tvb, offset, 1, ENC_BIG_ENDIAN);
1041 proto_tree_add_item(fmconfig_tree, hf_selfm_fmconfig_numflags, tvb, offset+1, 1, ENC_BIG_ENDIAN);
1042 proto_tree_add_item(fmconfig_tree, hf_selfm_fmconfig_loc_sf, tvb, offset+2, 1, ENC_BIG_ENDIAN);
1043 proto_tree_add_item(fmconfig_tree, hf_selfm_fmconfig_num_sf, tvb, offset+3, 1, ENC_BIG_ENDIAN);
1044 proto_tree_add_item(fmconfig_tree, hf_selfm_fmconfig_num_ai, tvb, offset+4, 1, ENC_BIG_ENDIAN);
1045 proto_tree_add_item(fmconfig_tree, hf_selfm_fmconfig_num_samp, tvb, offset+5, 1, ENC_BIG_ENDIAN);
1046 proto_tree_add_item(fmconfig_tree, hf_selfm_fmconfig_num_dig, tvb, offset+6, 1, ENC_BIG_ENDIAN);
1047 proto_tree_add_item(fmconfig_tree, hf_selfm_fmconfig_num_calc, tvb, offset+7, 1, ENC_BIG_ENDIAN);
1049 /* Update offset pointer */
1050 offset += 8;
1052 /* Add data packet offsets to tree and update offset pointer */
1053 proto_tree_add_item(fmconfig_tree, hf_selfm_fmconfig_ofs_ai, tvb, offset, 2, ENC_BIG_ENDIAN);
1054 proto_tree_add_item(fmconfig_tree, hf_selfm_fmconfig_ofs_ts, tvb, offset+2, 2, ENC_BIG_ENDIAN);
1055 proto_tree_add_item(fmconfig_tree, hf_selfm_fmconfig_ofs_dig, tvb, offset+4, 2, ENC_BIG_ENDIAN);
1056 offset += 6;
1058 /* Get AI Channel Details */
1059 for (count = 0; count < num_ai; count++) {
1060 tvb_memcpy(tvb, &ai_name, offset, 6);
1061 ai_name[FM_CONFIG_ANA_CHNAME_LEN] = '\0'; /* Put a terminating null onto the end of the AI name, in case none exists */
1063 fmconfig_ai_item = proto_tree_add_text(fmconfig_tree, tvb, offset, 10, "Analog Channel: %s", ai_name);
1064 fmconfig_ai_tree = proto_item_add_subtree(fmconfig_ai_item, ett_selfm_fmconfig_ai);
1066 /* Add Channel Name, Channel Data Type, Scale Factor Type and Scale Factor Offset to tree */
1067 proto_tree_add_text(fmconfig_ai_tree, tvb, offset, 6, "Analog Channel Name: %s", ai_name);
1068 proto_tree_add_item(fmconfig_ai_tree, hf_selfm_fmconfig_ai_type, tvb, offset+6, 1, ENC_BIG_ENDIAN);
1069 proto_tree_add_item(fmconfig_ai_tree, hf_selfm_fmconfig_ai_sf_type, tvb, offset+7, 1, ENC_BIG_ENDIAN);
1070 proto_tree_add_item(fmconfig_ai_tree, hf_selfm_fmconfig_ai_sf_ofs, tvb, offset+8, 2, ENC_BIG_ENDIAN);
1072 /* Update Offset Pointer */
1073 offset += 10;
1076 /* 14-byte Calculation block instances based on num_calc */
1077 for (count = 0; count < num_calc; count++) {
1078 fmconfig_calc_item = proto_tree_add_text(fmconfig_tree, tvb, offset, 14, "Calculation Block: %d", count+1);
1079 fmconfig_calc_tree = proto_item_add_subtree(fmconfig_calc_item, ett_selfm_fmconfig_calc);
1081 /* Rotation, Voltage Connection and Current Connection are all bit-masked on the same byte */
1082 proto_tree_add_item(fmconfig_calc_tree, hf_selfm_fmconfig_cblk_rot, tvb, offset, 1, ENC_BIG_ENDIAN);
1083 proto_tree_add_item(fmconfig_calc_tree, hf_selfm_fmconfig_cblk_vconn, tvb, offset, 1, ENC_BIG_ENDIAN);
1084 proto_tree_add_item(fmconfig_calc_tree, hf_selfm_fmconfig_cblk_iconn, tvb, offset, 1, ENC_BIG_ENDIAN);
1086 proto_tree_add_item(fmconfig_calc_tree, hf_selfm_fmconfig_cblk_ctype, tvb, offset+1, 1, ENC_BIG_ENDIAN);
1087 proto_tree_add_item(fmconfig_calc_tree, hf_selfm_fmconfig_cblk_deskew_ofs, tvb, offset+2, 2, ENC_BIG_ENDIAN);
1088 proto_tree_add_item(fmconfig_calc_tree, hf_selfm_fmconfig_cblk_rs_ofs, tvb, offset+4, 2, ENC_BIG_ENDIAN);
1089 proto_tree_add_item(fmconfig_calc_tree, hf_selfm_fmconfig_cblk_xs_ofs, tvb, offset+6, 2, ENC_BIG_ENDIAN);
1090 proto_tree_add_item(fmconfig_calc_tree, hf_selfm_fmconfig_cblk_ia_idx, tvb, offset+8, 1, ENC_BIG_ENDIAN);
1091 proto_tree_add_item(fmconfig_calc_tree, hf_selfm_fmconfig_cblk_ib_idx, tvb, offset+9, 1, ENC_BIG_ENDIAN);
1092 proto_tree_add_item(fmconfig_calc_tree, hf_selfm_fmconfig_cblk_ic_idx, tvb, offset+10, 1, ENC_BIG_ENDIAN);
1093 proto_tree_add_item(fmconfig_calc_tree, hf_selfm_fmconfig_cblk_va_idx, tvb, offset+11, 1, ENC_BIG_ENDIAN);
1094 proto_tree_add_item(fmconfig_calc_tree, hf_selfm_fmconfig_cblk_vb_idx, tvb, offset+12, 1, ENC_BIG_ENDIAN);
1095 proto_tree_add_item(fmconfig_calc_tree, hf_selfm_fmconfig_cblk_vc_idx, tvb, offset+13, 1, ENC_BIG_ENDIAN);
1097 offset += 14;
1100 /* Add Pad byte (if present) and checksum */
1101 if (tvb_reported_length_remaining(tvb, offset) > 1) {
1102 proto_tree_add_item(fmconfig_tree, hf_selfm_padbyte, tvb, offset, 1, ENC_BIG_ENDIAN);
1103 offset += 1;
1106 proto_tree_add_item(fmconfig_tree, hf_selfm_checksum, tvb, offset, 1, ENC_BIG_ENDIAN);
1108 return tvb_length(tvb);
1112 /******************************************************************************************************/
1113 /* Code to dissect Fast Meter Data Frames */
1114 /* Formatting depends heavily on previously-encountered Configuration Frames so search array instances for them */
1115 /******************************************************************************************************/
1116 static int
1117 dissect_fmdata_frame(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, int offset, guint16 config_cmd_match)
1119 /* Set up structures needed to add the protocol subtree and manage it */
1120 proto_item *fmdata_item, *fmdata_ai_item=NULL, *fmdata_dig_item=NULL, *fmdata_ai_ch_item=NULL, *fmdata_dig_ch_item=NULL;
1121 proto_tree *fmdata_tree, *fmdata_ai_tree=NULL, *fmdata_dig_tree=NULL, *fmdata_ai_ch_tree=NULL, *fmdata_dig_ch_tree=NULL;
1122 guint8 len, i=0, j=0, ts_mon, ts_day, ts_year, ts_hour, ts_min, ts_sec;
1123 guint16 config_cmd, ts_msec, ai_int16val;
1124 gfloat ai_fpval, ai_sf_fp;
1125 gdouble ai_fpd_val;
1126 gboolean config_found = FALSE;
1127 fm_conversation *conv;
1128 fm_config_frame *cfg_data;
1129 gint cnt = 0, ch_size=0;
1131 len = tvb_get_guint8(tvb, offset);
1133 fmdata_item = proto_tree_add_text(tree, tvb, offset, len-2, "Fast Meter Data Details");
1134 fmdata_tree = proto_item_add_subtree(fmdata_item, ett_selfm_fmdata);
1136 /* Reported length */
1137 proto_tree_add_item(fmdata_tree, hf_selfm_fmdata_len, tvb, offset, 1, ENC_BIG_ENDIAN);
1138 offset += 1;
1140 /* Search for previously-encountered Configuration information to dissect the frame */
1142 conv = (fm_conversation *)p_get_proto_data(pinfo->fd, proto_selfm, 0);
1144 if (conv) {
1145 wmem_list_frame_t *frame = wmem_list_head(conv->fm_config_frames);
1146 /* Cycle through possible instances of multiple fm_config_data_blocks, looking for match */
1147 while (frame && !config_found) {
1148 cfg_data = (fm_config_frame *)wmem_list_frame_data(frame);
1149 config_cmd = cfg_data->cfg_cmd;
1151 /* If the stored config_cmd matches the expected one we are looking for, mark that the config data was found */
1152 if (config_cmd == config_cmd_match) {
1153 proto_item_append_text(fmdata_item, ", using frame number %"G_GUINT32_FORMAT" as Configuration Frame",
1154 cfg_data->fnum);
1155 config_found = TRUE;
1158 frame = wmem_list_frame_next(frame);
1161 if (config_found) {
1163 /* Retrieve number of Status Flag bytes and setup tree */
1164 if (cfg_data->num_flags == 1){
1165 proto_tree_add_item(fmdata_tree, hf_selfm_fmdata_flagbyte, tvb, offset, 1, ENC_BIG_ENDIAN);
1166 /*offset += 1;*/
1169 cnt = cfg_data->num_ai; /* actual number of analog values to available to dissect */
1171 /* Update our current tvb offset to the actual AI offset saved from the Configuration message */
1172 offset = cfg_data->offset_ai;
1174 /* Check that we actually have analog data to dissect */
1175 if (cnt > 0) {
1177 /* Include decoding for each Sample provided for the Analog Channels */
1178 for (j=0; j < cfg_data->num_ai_samples; j++) {
1180 /* Use different lookup strings, depending on how many samples are available per Analog Channel */
1181 if (cfg_data->num_ai_samples == 1) {
1182 fmdata_ai_item = proto_tree_add_text(fmdata_tree, tvb, offset, ((cfg_data->offset_ts - cfg_data->offset_ai)/cfg_data->num_ai_samples),
1183 "Analog Channels (%d), Sample: %d (%s)",
1184 cfg_data->num_ai, j+1, val_to_str_const(j+1, selfm_fmconfig_numsamples1_vals, "Unknown"));
1185 fmdata_ai_tree = proto_item_add_subtree(fmdata_ai_item, ett_selfm_fmdata_ai);
1187 else if (cfg_data->num_ai_samples == 2) {
1188 fmdata_ai_item = proto_tree_add_text(fmdata_tree, tvb, offset, ((cfg_data->offset_ts - cfg_data->offset_ai)/cfg_data->num_ai_samples),
1189 "Analog Channels (%d), Sample: %d (%s)",
1190 cfg_data->num_ai, j+1, val_to_str_const(j+1, selfm_fmconfig_numsamples2_vals, "Unknown"));
1191 fmdata_ai_tree = proto_item_add_subtree(fmdata_ai_item, ett_selfm_fmdata_ai);
1193 else if (cfg_data->num_ai_samples == 4) {
1194 fmdata_ai_item = proto_tree_add_text(fmdata_tree, tvb, offset, ((cfg_data->offset_ts - cfg_data->offset_ai)/cfg_data->num_ai_samples),
1195 "Analog Channels (%d), Sample: %d (%s)",
1196 cfg_data->num_ai, j+1, val_to_str_const(j+1, selfm_fmconfig_numsamples4_vals, "Unknown"));
1197 fmdata_ai_tree = proto_item_add_subtree(fmdata_ai_item, ett_selfm_fmdata_ai);
1200 /* For each analog channel we encounter... */
1201 for (i = 0; i < cnt; i++) {
1203 fm_analog_info *ai = &(cfg_data->analogs[i]);
1205 /* Channel size (in bytes) determined by data type */
1206 switch (ai->type) {
1207 case FM_CONFIG_ANA_CHTYPE_INT16:
1208 ch_size = 2; /* 2 bytes */
1209 break;
1210 case FM_CONFIG_ANA_CHTYPE_FP:
1211 ch_size = 4; /* 4 bytes */
1212 break;
1213 case FM_CONFIG_ANA_CHTYPE_FPD:
1214 ch_size = 8; /* 8 bytes */
1215 break;
1216 default:
1217 break;
1220 /* Build sub-tree for each Analog Channel */
1221 fmdata_ai_ch_item = proto_tree_add_text(fmdata_ai_tree, tvb, offset, ch_size, "Analog Channel %d: %s", i+1, ai->name);
1222 fmdata_ai_ch_tree = proto_item_add_subtree(fmdata_ai_ch_item, ett_selfm_fmdata_ai_ch);
1224 /* XXX - Need more decoding options here for different data types, but I need packet capture examples first */
1225 /* Decode analog value appropriately, according to data type */
1226 switch (ai->type) {
1227 /* Channel type is 16-bit Integer */
1228 case FM_CONFIG_ANA_CHTYPE_INT16:
1229 ai_int16val = tvb_get_ntohs(tvb, offset);
1231 /* If we've got a scale factor offset, apply it before printing the analog */
1232 if ((ai->sf_offset != 0) && (ai->sf_type == FM_CONFIG_ANA_SFTYPE_FP)){
1233 ai_sf_fp = tvb_get_ntohieee_float(tvb, ai->sf_offset);
1234 proto_tree_add_float(fmdata_ai_ch_tree, hf_selfm_fmdata_ai_sf_fp, tvb, ai->sf_offset, 4, ai_sf_fp);
1236 else {
1237 ai_sf_fp = 1;
1240 proto_tree_add_text(fmdata_ai_ch_tree, tvb, offset, ch_size, "Value (Raw): %d", ai_int16val);
1241 proto_tree_add_text(fmdata_ai_ch_tree, tvb, offset, ch_size, "Value (w/ Scale Factor): %f", ((gfloat)ai_int16val*ai_sf_fp));
1242 offset += ch_size;
1243 break;
1244 /* Channel type is IEEE Floating point */
1245 case FM_CONFIG_ANA_CHTYPE_FP:
1246 ai_fpval = tvb_get_ntohieee_float(tvb, offset);
1247 proto_tree_add_text(fmdata_ai_ch_tree, tvb, offset, ch_size, "Value: %f", ai_fpval);
1248 offset += ch_size;
1249 break;
1250 /* Channel type is Double IEEE Floating point */
1251 case FM_CONFIG_ANA_CHTYPE_FPD:
1252 ai_fpd_val = tvb_get_ntohieee_double(tvb, offset);
1253 proto_tree_add_text(fmdata_ai_ch_tree, tvb, offset, ch_size, "Value: %f", ai_fpd_val);
1254 offset += ch_size;
1255 break;
1257 } /* channel type */
1259 } /* number of analog channels */
1261 } /* number of samples */
1263 } /* there were analogs */
1265 /* Check if we have a time-stamp in this message */
1266 if (cfg_data->offset_ts != 0xFFFF) {
1267 /* Retrieve timestamp from 8-byte format */
1268 /* Stored as: month, day, year (xx), hr, min, sec, msec (16-bit) */
1269 ts_mon = tvb_get_guint8(tvb, offset);
1270 ts_day = tvb_get_guint8(tvb, offset+1);
1271 ts_year = tvb_get_guint8(tvb, offset+2);
1272 ts_hour = tvb_get_guint8(tvb, offset+3);
1273 ts_min = tvb_get_guint8(tvb, offset+4);
1274 ts_sec = tvb_get_guint8(tvb, offset+5);
1275 ts_msec = tvb_get_ntohs(tvb, offset+6);
1276 proto_tree_add_text(fmdata_tree, tvb, offset, 8, "Timestamp: %.2d/%.2d/%.2d %.2d:%.2d:%.2d.%.3d", ts_mon, ts_day, ts_year, ts_hour, ts_min, ts_sec, ts_msec);
1278 offset += 8;
1281 /* Check that we actually have digital data */
1282 if (cfg_data->num_dig > 0) {
1284 fmdata_dig_item = proto_tree_add_text(fmdata_tree, tvb, offset, cfg_data->num_dig, "Digital Channels (%d)", cfg_data->num_dig);
1285 fmdata_dig_tree = proto_item_add_subtree(fmdata_dig_item, ett_selfm_fmdata_dig);
1287 for (i=0; i < cfg_data->num_dig; i++) {
1289 fmdata_dig_ch_item = proto_tree_add_text(fmdata_dig_tree, tvb, offset, 1, "Digital Word Bit Row: %2d", i+1);
1290 fmdata_dig_ch_tree = proto_item_add_subtree(fmdata_dig_ch_item, ett_selfm_fmdata_dig_ch);
1292 /* Display the bit pattern on the digital channel proto_item */
1293 proto_item_append_text(fmdata_dig_ch_item, " [ %d %d %d %d %d %d %d %d ]",
1294 ((tvb_get_guint8(tvb, offset) & 0x80) >> 7), ((tvb_get_guint8(tvb, offset) & 0x40) >> 6),
1295 ((tvb_get_guint8(tvb, offset) & 0x20) >> 5), ((tvb_get_guint8(tvb, offset) & 0x10) >> 4),
1296 ((tvb_get_guint8(tvb, offset) & 0x08) >> 3), ((tvb_get_guint8(tvb, offset) & 0x04) >> 2),
1297 ((tvb_get_guint8(tvb, offset) & 0x02) >> 1), (tvb_get_guint8(tvb, offset) & 0x01));
1299 proto_tree_add_item(fmdata_dig_ch_tree, hf_selfm_fmdata_dig_b0, tvb, offset, 1, ENC_BIG_ENDIAN);
1300 proto_tree_add_item(fmdata_dig_ch_tree, hf_selfm_fmdata_dig_b1, tvb, offset, 1, ENC_BIG_ENDIAN);
1301 proto_tree_add_item(fmdata_dig_ch_tree, hf_selfm_fmdata_dig_b2, tvb, offset, 1, ENC_BIG_ENDIAN);
1302 proto_tree_add_item(fmdata_dig_ch_tree, hf_selfm_fmdata_dig_b3, tvb, offset, 1, ENC_BIG_ENDIAN);
1303 proto_tree_add_item(fmdata_dig_ch_tree, hf_selfm_fmdata_dig_b4, tvb, offset, 1, ENC_BIG_ENDIAN);
1304 proto_tree_add_item(fmdata_dig_ch_tree, hf_selfm_fmdata_dig_b5, tvb, offset, 1, ENC_BIG_ENDIAN);
1305 proto_tree_add_item(fmdata_dig_ch_tree, hf_selfm_fmdata_dig_b6, tvb, offset, 1, ENC_BIG_ENDIAN);
1306 proto_tree_add_item(fmdata_dig_ch_tree, hf_selfm_fmdata_dig_b7, tvb, offset, 1, ENC_BIG_ENDIAN);
1308 offset += 1;
1311 } /* digital data was available */
1313 /* Add Pad byte (if present) and checksum */
1314 if (tvb_reported_length_remaining(tvb, offset) > 1) {
1315 proto_tree_add_item(fmdata_tree, hf_selfm_padbyte, tvb, offset, 1, ENC_BIG_ENDIAN);
1316 offset += 1;
1319 proto_tree_add_item(fmdata_tree, hf_selfm_checksum, tvb, offset, 1, ENC_BIG_ENDIAN);
1321 } /* matching config frame message was found */
1323 } /* config data found */
1325 if (!config_found) {
1326 proto_item_append_text(fmdata_item, ", No Fast Meter Configuration frame found");
1327 return 0;
1331 return tvb_length(tvb);
1335 /******************************************************************************************************/
1336 /* Code to Dissect Fast Operate Configuration Frames */
1337 /******************************************************************************************************/
1338 static int
1339 dissect_foconfig_frame(tvbuff_t *tvb, proto_tree *tree, int offset)
1341 /* Set up structures needed to add the protocol subtree and manage it */
1342 proto_item *foconfig_item, *foconfig_brkr_item, *foconfig_rb_item;
1343 proto_tree *foconfig_tree, *foconfig_brkr_tree=NULL, *foconfig_rb_tree=NULL;
1344 guint count;
1345 guint8 len, num_brkr, prb_supp;
1346 guint16 num_rb;
1348 len = tvb_get_guint8(tvb, offset);
1349 num_brkr = tvb_get_guint8(tvb, offset+1);
1350 num_rb = tvb_get_ntohs(tvb, offset+2);
1351 prb_supp = tvb_get_guint8(tvb, offset+4);
1353 foconfig_item = proto_tree_add_text(tree, tvb, offset, len-2, "Fast Operate Configuration Details");
1354 foconfig_tree = proto_item_add_subtree(foconfig_item, ett_selfm_foconfig);
1356 /* Add items to protocol tree specific to Fast Operate Configuration Block */
1358 /* Reported length */
1359 proto_tree_add_item(foconfig_tree, hf_selfm_foconfig_len, tvb, offset, 1, ENC_BIG_ENDIAN);
1361 /* Supported Breaker Bits */
1362 foconfig_brkr_item = proto_tree_add_item(foconfig_tree, hf_selfm_foconfig_num_brkr, tvb, offset+1, 1, ENC_BIG_ENDIAN);
1364 /* Supported Remote Bits */
1365 foconfig_rb_item = proto_tree_add_item(foconfig_tree, hf_selfm_foconfig_num_rb, tvb, offset+2, 2, ENC_BIG_ENDIAN);
1367 /* Add "Remote Bit Pulse Supported?" and "Reserved Bit" to Tree */
1368 proto_tree_add_item(foconfig_tree, hf_selfm_foconfig_prb_supp, tvb, offset+4, 1, ENC_BIG_ENDIAN);
1369 proto_tree_add_item(foconfig_tree, hf_selfm_foconfig_reserved, tvb, offset+5, 1, ENC_BIG_ENDIAN);
1371 /* Update offset pointer */
1372 offset += 6;
1374 /* Get Breaker Bit Command Details */
1375 for (count = 1; count <= num_brkr; count++) {
1377 foconfig_brkr_tree = proto_item_add_subtree(foconfig_brkr_item, ett_selfm_foconfig_brkr);
1379 /* Add Breaker Open/Close commands to tree */
1380 proto_tree_add_item(foconfig_brkr_tree, hf_selfm_foconfig_brkr_open, tvb, offset, 1, ENC_BIG_ENDIAN);
1381 proto_tree_add_item(foconfig_brkr_tree, hf_selfm_foconfig_brkr_close, tvb, offset+1, 1, ENC_BIG_ENDIAN);
1383 offset += 2;
1386 /* Get Remote Bit Command Details */
1387 for (count = 1; count <= num_rb; count++) {
1389 foconfig_rb_tree = proto_item_add_subtree(foconfig_rb_item, ett_selfm_foconfig_rb);
1391 /* Add "Remote Bit Set" command to tree */
1392 proto_tree_add_item(foconfig_rb_tree, hf_selfm_foconfig_rb_cmd, tvb, offset, 1, ENC_BIG_ENDIAN);
1394 /* Print "Remote Bit Clear" command to tree */
1395 proto_tree_add_item(foconfig_rb_tree, hf_selfm_foconfig_rb_cmd, tvb, offset+1, 1, ENC_BIG_ENDIAN);
1397 /* If Remote Bit "pulse" is supported, retrieve that command as well */
1398 if (prb_supp) {
1399 proto_tree_add_item(foconfig_rb_tree, hf_selfm_foconfig_rb_cmd, tvb, offset+2, 1, ENC_BIG_ENDIAN);
1400 offset += 3;
1402 else{
1403 offset += 2;
1407 /* Add Pad byte (if present) and checksum */
1408 if (tvb_reported_length_remaining(tvb, offset) > 1) {
1409 proto_tree_add_item(foconfig_tree, hf_selfm_padbyte, tvb, offset, 1, ENC_BIG_ENDIAN);
1410 offset += 1;
1413 proto_tree_add_item(foconfig_tree, hf_selfm_checksum, tvb, offset, 1, ENC_BIG_ENDIAN);
1416 return tvb_length(tvb);
1420 /******************************************************************************************************/
1421 /* Code to Dissect Alternate Fast Operate (AFO) Configuration Frames */
1422 /******************************************************************************************************/
1423 static int
1424 dissect_alt_fastop_config_frame(tvbuff_t *tvb, proto_tree *tree, int offset)
1426 /* Set up structures needed to add the protocol subtree and manage it */
1427 proto_item *foconfig_item=NULL;
1428 proto_tree *foconfig_tree=NULL;
1429 guint8 len;
1431 len = tvb_get_guint8(tvb, offset);
1433 foconfig_item = proto_tree_add_text(tree, tvb, offset, len-2, "Alternate Fast Operate Configuration Details");
1434 foconfig_tree = proto_item_add_subtree(foconfig_item, ett_selfm_foconfig);
1436 /* Add items to protocol tree specific to Fast Operate Configuration Block */
1438 /* Reported length */
1439 proto_tree_add_item(foconfig_tree, hf_selfm_alt_foconfig_len, tvb, offset, 1, ENC_BIG_ENDIAN);
1441 /* Number of Ports */
1442 proto_tree_add_item(foconfig_tree, hf_selfm_alt_foconfig_num_ports, tvb, offset+1, 1, ENC_BIG_ENDIAN);
1444 /* Number of Breaker Bits */
1445 proto_tree_add_item(foconfig_tree, hf_selfm_alt_foconfig_num_brkr, tvb, offset+2, 1, ENC_BIG_ENDIAN);
1447 /* Number of Remote Bits */
1448 proto_tree_add_item(foconfig_tree, hf_selfm_alt_foconfig_num_rb, tvb, offset+3, 1, ENC_BIG_ENDIAN);
1450 /* Function Code(s) Supported */
1451 proto_tree_add_item(foconfig_tree, hf_selfm_alt_foconfig_funccode, tvb, offset+4, 1, ENC_BIG_ENDIAN);
1452 proto_tree_add_item(foconfig_tree, hf_selfm_alt_foconfig_funccode, tvb, offset+5, 1, ENC_BIG_ENDIAN);
1453 proto_tree_add_item(foconfig_tree, hf_selfm_alt_foconfig_funccode, tvb, offset+6, 1, ENC_BIG_ENDIAN);
1454 proto_tree_add_item(foconfig_tree, hf_selfm_alt_foconfig_funccode, tvb, offset+7, 1, ENC_BIG_ENDIAN);
1455 proto_tree_add_item(foconfig_tree, hf_selfm_alt_foconfig_funccode, tvb, offset+8, 1, ENC_BIG_ENDIAN);
1457 return tvb_length(tvb);
1461 /******************************************************************************************************/
1462 /* Code to Dissect Fast Operate (Remote Bit or Breaker Bit) Frames */
1463 /******************************************************************************************************/
1464 static int
1465 dissect_fastop_frame(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, int offset)
1467 /* Set up structures needed to add the protocol subtree and manage it */
1468 proto_item *fastop_item;
1469 proto_tree *fastop_tree;
1470 guint8 len, opcode;
1471 guint16 msg_type;
1473 msg_type = tvb_get_ntohs(tvb, offset-2);
1474 len = tvb_get_guint8(tvb, offset);
1476 fastop_item = proto_tree_add_text(tree, tvb, offset, len-2, "Fast Operate Details");
1477 fastop_tree = proto_item_add_subtree(fastop_item, ett_selfm_fastop);
1479 /* Add Reported length to tree*/
1480 proto_tree_add_item(fastop_tree, hf_selfm_fastop_len, tvb, offset, 1, ENC_BIG_ENDIAN);
1481 offset += 1;
1483 /* Operate Code */
1484 opcode = tvb_get_guint8(tvb, offset);
1486 /* Use different lookup table for different msg_type */
1487 if (msg_type == CMD_FASTOP_RB_CTRL) {
1488 proto_tree_add_item(fastop_tree, hf_selfm_fastop_rb_code, tvb, offset, 1, ENC_BIG_ENDIAN);
1490 /* Append Column Info w/ Control Code Code */
1491 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "%s", val_to_str_const(opcode, selfm_fo_rb_vals, "Unknown Control Code"));
1493 else if (msg_type == CMD_FASTOP_BR_CTRL) {
1494 proto_tree_add_item(fastop_tree, hf_selfm_fastop_br_code, tvb, offset, 1, ENC_BIG_ENDIAN);
1496 /* Append Column Info w/ Control Code Code */
1497 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "%s", val_to_str_const(opcode, selfm_fo_br_vals, "Unknown Control Code"));
1499 offset += 1;
1501 /* Operate Code Validation */
1502 proto_tree_add_item(fastop_tree, hf_selfm_fastop_valid, tvb, offset, 1, ENC_BIG_ENDIAN);
1503 offset += 1;
1505 /* Add checksum */
1506 proto_tree_add_item(fastop_tree, hf_selfm_checksum, tvb, offset, 1, ENC_BIG_ENDIAN);
1508 return tvb_length(tvb);
1512 /******************************************************************************************************/
1513 /* Code to Dissect Alternate Fast Operate (AFO) Command Frames */
1514 /******************************************************************************************************/
1515 static int
1516 dissect_alt_fastop_frame(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, int offset)
1518 /* Set up structures needed to add the protocol subtree and manage it */
1519 proto_item *fastop_item;
1520 proto_tree *fastop_tree;
1521 guint8 len;
1522 guint16 opcode;
1524 len = tvb_get_guint8(tvb, offset);
1526 fastop_item = proto_tree_add_text(tree, tvb, offset, len-2, "Alternate Fast Operate Details");
1527 fastop_tree = proto_item_add_subtree(fastop_item, ett_selfm_fastop);
1529 /* Add Reported length to tree */
1530 proto_tree_add_item(fastop_tree, hf_selfm_alt_fastop_len, tvb, offset, 1, ENC_BIG_ENDIAN);
1531 offset += 1;
1533 /* Operate Code */
1534 opcode = tvb_get_ntohs(tvb, offset);
1536 /* Append Column Info w/ Control Code Code */
1537 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "%#x", opcode);
1539 proto_tree_add_item(fastop_tree, hf_selfm_alt_fastop_code, tvb, offset, 2, ENC_BIG_ENDIAN);
1541 offset += 2;
1543 /* Operate Code Validation */
1544 proto_tree_add_item(fastop_tree, hf_selfm_alt_fastop_valid, tvb, offset, 2, ENC_BIG_ENDIAN);
1546 return tvb_length(tvb);
1550 /**************************************************************************************************************************/
1551 /* Code to dissect Fast SER Read Response Messages */
1552 /**************************************************************************************************************************/
1553 /* 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 */
1554 /* the 20 bytes of overhead and 254 max frame size. In the event of a larger data payload than 234 bytes, the FIR and FIN */
1555 /* bits will be used to indicate either the first frame, last frame, or a neither/middle frame. */
1556 /* We can use the FIN bit to attempt a reassembly of the data payload since all messages will arrive sequentially. */
1557 /**************************************************************************************************************************/
1559 static int
1560 dissect_fastser_readresp_frame(tvbuff_t *tvb, proto_tree *fastser_tree, packet_info *pinfo, int offset, guint8 seq_byte)
1562 proto_item *fastser_tag_item=NULL, *fastser_tag_value_item=NULL, *fmdata_dig_item=NULL;
1563 proto_item *pi_baseaddr=NULL, *pi_fnum=NULL, *pi_type=NULL, *pi_qty=NULL;
1564 proto_tree *fastser_tag_tree=NULL, *fmdata_dig_tree=NULL;
1565 guint32 base_addr;
1566 guint16 data_size, num_addr, cnt;
1567 guint8 *item_val_str_ptr;
1568 guint8 seq_cnt;
1569 gboolean seq_fir, seq_fin, save_fragmented;
1570 int payload_offset=0;
1571 fm_conversation *conv;
1572 fastser_dataitem *dataitem;
1573 tvbuff_t *data_tvb, *payload_tvb;
1575 /* Decode sequence byte components */
1576 seq_cnt = seq_byte & FAST_SER_SEQ_CNT;
1577 seq_fir = ((seq_byte & FAST_SER_SEQ_FIR) >> 7);
1578 seq_fin = ((seq_byte & FAST_SER_SEQ_FIN) >> 6);
1580 base_addr = tvb_get_ntohl(tvb, offset); /* 32-bit field with base address to read */
1581 num_addr = tvb_get_ntohs(tvb, offset+4); /* 16-bit field with number of 16-bit addresses to read */
1583 /* Append Column Info w/ Base Address */
1584 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "%#x [%s]", base_addr, region_lookup(pinfo, base_addr));
1586 pi_baseaddr = proto_tree_add_item(fastser_tree, hf_selfm_fastser_baseaddr, tvb, offset, 4, ENC_BIG_ENDIAN);
1587 proto_item_append_text(pi_baseaddr, " [%s]", region_lookup(pinfo, base_addr));
1589 proto_tree_add_item(fastser_tree, hf_selfm_fastser_numwords, tvb, offset+4, 2, ENC_BIG_ENDIAN);
1590 offset += 6;
1592 /* Setup a new tvb representing just the data payload of this particular message */
1593 data_tvb = tvb_new_subset( tvb, offset, (tvb_reported_length_remaining(tvb, offset)-2), (tvb_reported_length_remaining(tvb, offset)-2));
1595 save_fragmented = pinfo->fragmented;
1597 /* Check for fragmented packet by looking at the FIR and FIN bits */
1598 if (! (seq_fir && seq_fin)) {
1599 fragment_head *frag_msg;
1601 /* This is a fragmented packet, mark it as such */
1602 pinfo->fragmented = TRUE;
1604 frag_msg = fragment_add_seq_next(&selfm_reassembly_table,
1605 data_tvb, 0, pinfo, 0, NULL,
1606 tvb_reported_length(data_tvb),
1607 !seq_fin);
1609 payload_tvb = process_reassembled_data(data_tvb, 0, pinfo,
1610 "Reassembled Data Response Payload", frag_msg, &selfm_frag_items,
1611 NULL, fastser_tree);
1613 if (payload_tvb) { /* Reassembled */
1614 /* We have the complete payload */
1615 col_append_sep_str(pinfo->cinfo, COL_INFO, NULL, "Reassembled Data Response");
1617 else
1619 /* We don't have the complete reassembled payload. */
1620 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "Response Data Fragment %u" , seq_cnt);
1625 /* No re-assembly required, setup the payload_tvb based on the single-frame data payload tvb */
1626 else {
1627 payload_tvb = data_tvb;
1628 add_new_data_source(pinfo, payload_tvb, "Data Response Payload");
1631 pinfo->fragmented = save_fragmented;
1633 /* If we had no need to re-assemble or this is the final packet of a reassembly, let's attempt to dissect the */
1634 /* data payload using any previously-captured data format information */
1635 if (payload_tvb) {
1637 /* Search for previously-encountered data format reference information to dissect the frame */
1638 conv = (fm_conversation *)p_get_proto_data(pinfo->fd, proto_selfm, 0);
1640 if (conv) {
1641 /* Start at front of list and cycle through possible instances of multiple fastser_dataitem frames, looking for match */
1642 wmem_list_frame_t *frame = wmem_list_head(conv->fastser_dataitems);
1644 while (frame) {
1645 dataitem = (fastser_dataitem *)wmem_list_frame_data(frame);
1647 /* If the stored base address of the current data item matches the current base address of this response frame */
1648 /* mark that the config data was found and attempt further dissection */
1649 if (dataitem->base_address == base_addr) {
1651 /* Data Item size (in bytes) determined by data type and quantity within item */
1652 switch (dataitem->data_type) {
1653 case FAST_SER_TAGTYPE_CHAR8:
1654 case FAST_SER_TAGTYPE_DIGWORD8_BL:
1655 case FAST_SER_TAGTYPE_DIGWORD8:
1656 data_size = 1 * dataitem->quantity; /* 1 byte per qty */
1657 break;
1658 case FAST_SER_TAGTYPE_CHAR16:
1659 case FAST_SER_TAGTYPE_DIGWORD16_BL:
1660 case FAST_SER_TAGTYPE_DIGWORD16:
1661 case FAST_SER_TAGTYPE_INT16:
1662 case FAST_SER_TAGTYPE_UINT16:
1663 data_size = 2 * dataitem->quantity; /* 2 bytes per qty */
1664 break;
1665 case FAST_SER_TAGTYPE_INT32:
1666 case FAST_SER_TAGTYPE_UINT32:
1667 case FAST_SER_TAGTYPE_FLOAT:
1668 data_size = 4 * dataitem->quantity; /* 4 bytes per qty */
1669 break;
1671 default:
1672 data_size = 0;
1673 break;
1676 fastser_tag_item = proto_tree_add_text(fastser_tree, payload_tvb, payload_offset, data_size, "Data Item Name: %s", dataitem->name);
1677 fastser_tag_tree = proto_item_add_subtree(fastser_tag_item, ett_selfm_fastser_tag);
1679 /* Load some information from the stored Data Format Response message into the tree for reference */
1680 pi_fnum = proto_tree_add_text(fastser_tag_tree, payload_tvb, payload_offset, data_size, "Using frame number %d (Index Pos: %d) as Data Format Reference",dataitem->fnum, dataitem->index_pos );
1681 pi_type = proto_tree_add_text(fastser_tag_tree, payload_tvb, payload_offset, data_size, "Data_Type: %s (%#x)",
1682 val_to_str_const(dataitem->data_type, selfm_fastser_tagtype_vals, "Unknown Data Type"), dataitem->data_type);
1683 pi_qty = proto_tree_add_text(fastser_tag_tree, payload_tvb, payload_offset, data_size, "Quantity: %d",dataitem->quantity );
1685 PROTO_ITEM_SET_GENERATED(pi_fnum);
1686 PROTO_ITEM_SET_GENERATED(pi_type);
1687 PROTO_ITEM_SET_GENERATED(pi_qty);
1689 /* Data Item Type determines how to decode */
1690 switch (dataitem->data_type) {
1692 case FAST_SER_TAGTYPE_DIGWORD8_BL:
1693 case FAST_SER_TAGTYPE_DIGWORD8:
1695 for (cnt=1; cnt <= dataitem->quantity; cnt++) {
1697 fmdata_dig_item = proto_tree_add_text(fastser_tag_tree, payload_tvb, payload_offset, 1, "8-bit Binary Items (Row: %2d)", cnt);
1698 fmdata_dig_tree = proto_item_add_subtree(fmdata_dig_item, ett_selfm_fmdata_dig);
1700 /* Display the bit pattern on the digital channel proto_item */
1701 proto_item_append_text(fmdata_dig_item, " [ %d %d %d %d %d %d %d %d ]",
1702 ((tvb_get_guint8(payload_tvb, payload_offset) & 0x80) >> 7), ((tvb_get_guint8(payload_tvb, payload_offset) & 0x40) >> 6),
1703 ((tvb_get_guint8(payload_tvb, payload_offset) & 0x20) >> 5), ((tvb_get_guint8(payload_tvb, payload_offset) & 0x10) >> 4),
1704 ((tvb_get_guint8(payload_tvb, payload_offset) & 0x08) >> 3), ((tvb_get_guint8(payload_tvb, payload_offset) & 0x04) >> 2),
1705 ((tvb_get_guint8(payload_tvb, payload_offset) & 0x02) >> 1), (tvb_get_guint8(payload_tvb, payload_offset) & 0x01));
1707 proto_tree_add_item(fmdata_dig_tree, hf_selfm_fmdata_dig_b0, payload_tvb, payload_offset, 1, ENC_BIG_ENDIAN);
1708 proto_tree_add_item(fmdata_dig_tree, hf_selfm_fmdata_dig_b1, payload_tvb, payload_offset, 1, ENC_BIG_ENDIAN);
1709 proto_tree_add_item(fmdata_dig_tree, hf_selfm_fmdata_dig_b2, payload_tvb, payload_offset, 1, ENC_BIG_ENDIAN);
1710 proto_tree_add_item(fmdata_dig_tree, hf_selfm_fmdata_dig_b3, payload_tvb, payload_offset, 1, ENC_BIG_ENDIAN);
1711 proto_tree_add_item(fmdata_dig_tree, hf_selfm_fmdata_dig_b4, payload_tvb, payload_offset, 1, ENC_BIG_ENDIAN);
1712 proto_tree_add_item(fmdata_dig_tree, hf_selfm_fmdata_dig_b5, payload_tvb, payload_offset, 1, ENC_BIG_ENDIAN);
1713 proto_tree_add_item(fmdata_dig_tree, hf_selfm_fmdata_dig_b6, payload_tvb, payload_offset, 1, ENC_BIG_ENDIAN);
1714 proto_tree_add_item(fmdata_dig_tree, hf_selfm_fmdata_dig_b7, payload_tvb, payload_offset, 1, ENC_BIG_ENDIAN);
1716 payload_offset += 1;
1720 break;
1722 case FAST_SER_TAGTYPE_CHAR8:
1723 case FAST_SER_TAGTYPE_CHAR16:
1724 item_val_str_ptr = tvb_get_string(wmem_packet_scope(), payload_tvb, payload_offset, data_size);
1725 proto_tree_add_text(fastser_tag_tree, payload_tvb, payload_offset, data_size, "Value: %s", item_val_str_ptr);
1726 payload_offset += data_size;
1727 break;
1729 case FAST_SER_TAGTYPE_INT16:
1730 for (cnt=1; cnt <= dataitem->quantity; cnt++) {
1731 fastser_tag_value_item = proto_tree_add_item(fastser_tag_tree, hf_selfm_fastser_dataitem_int16, payload_tvb, payload_offset, data_size/dataitem->quantity, ENC_BIG_ENDIAN);
1732 proto_item_prepend_text(fastser_tag_value_item, "Value %d ", cnt);
1733 payload_offset += data_size/dataitem->quantity;
1735 break;
1737 case FAST_SER_TAGTYPE_UINT16:
1738 for (cnt=1; cnt <= dataitem->quantity; cnt++) {
1739 fastser_tag_value_item = proto_tree_add_item(fastser_tag_tree, hf_selfm_fastser_dataitem_uint16, payload_tvb, payload_offset, data_size/dataitem->quantity, ENC_BIG_ENDIAN);
1740 proto_item_prepend_text(fastser_tag_value_item, "Value %d ", cnt);
1741 payload_offset += data_size/dataitem->quantity;
1743 break;
1745 case FAST_SER_TAGTYPE_INT32:
1746 for (cnt=1; cnt <= dataitem->quantity; cnt++) {
1747 fastser_tag_value_item = proto_tree_add_item(fastser_tag_tree, hf_selfm_fastser_dataitem_int32, payload_tvb, payload_offset, data_size/dataitem->quantity, ENC_BIG_ENDIAN);
1748 proto_item_prepend_text(fastser_tag_value_item, "Value %d ", cnt);
1749 payload_offset += data_size/dataitem->quantity;
1751 break;
1753 case FAST_SER_TAGTYPE_UINT32:
1754 for (cnt=1; cnt <= dataitem->quantity; cnt++) {
1755 fastser_tag_value_item = proto_tree_add_item(fastser_tag_tree, hf_selfm_fastser_dataitem_uint32, payload_tvb, payload_offset, data_size/dataitem->quantity, ENC_BIG_ENDIAN);
1756 proto_item_prepend_text(fastser_tag_value_item, "Value %d ", cnt);
1757 payload_offset += data_size/dataitem->quantity;
1759 break;
1761 case FAST_SER_TAGTYPE_FLOAT:
1762 for (cnt=1; cnt <= dataitem->quantity; cnt++) {
1763 fastser_tag_value_item = proto_tree_add_item(fastser_tag_tree, hf_selfm_fastser_dataitem_float, payload_tvb, payload_offset, data_size/dataitem->quantity, ENC_BIG_ENDIAN);
1764 proto_item_prepend_text(fastser_tag_value_item, "Value %d ", cnt);
1765 payload_offset += data_size/dataitem->quantity;
1767 break;
1769 default:
1770 break;
1771 } /* data item type switch */
1773 } /* base address is correct */
1775 /* After processing this frame/data item, proceed to the next */
1776 frame = wmem_list_frame_next(frame);
1778 } /* while (frame) */
1780 } /* if (conv) found */
1782 } /* if payload_tvb */
1784 /* Update the offset field before we leave this frame */
1785 offset += num_addr*2;
1787 return offset;
1792 /******************************************************************************************************/
1793 /* Code to dissect Fast SER Frames */
1794 /******************************************************************************************************/
1795 static int
1796 dissect_fastser_frame(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, int offset)
1798 /* Set up structures needed to add the protocol subtree and manage it */
1799 proto_item *fastser_item, *fastser_def_fc_item=NULL, *fastser_seq_item=NULL, *fastser_elementlist_item=NULL;
1800 proto_item *fastser_element_item=NULL, *fastser_datareg_item=NULL, *fastser_tag_item=NULL;
1801 proto_item *pi_baseaddr=NULL;
1802 proto_tree *fastser_tree, *fastser_def_fc_tree=NULL, *fastser_seq_tree=NULL, *fastser_elementlist_tree=NULL;
1803 proto_tree *fastser_element_tree=NULL, *fastser_datareg_tree=NULL, *fastser_tag_tree=NULL;
1804 gint cnt, num_elements, elmt_status32_ofs=0, elmt_status, null_offset;
1805 guint8 len, funccode, seq, rx_num_fc, tx_num_fc;
1806 guint8 seq_cnt, seq_fir, seq_fin, elmt_idx, fc_enable;
1807 guint8 *fid_str_ptr, *rid_str_ptr, *region_name_ptr, *tag_name_ptr;
1808 guint16 base_addr, num_addr, num_reg, addr1, addr2;
1809 guint32 tod_ms, elmt_status32, elmt_ts_offset;
1812 len = tvb_get_guint8(tvb, offset);
1814 fastser_item = proto_tree_add_text(tree, tvb, offset, len-2, "Fast SER Message Details");
1815 fastser_tree = proto_item_add_subtree(fastser_item, ett_selfm_fastser);
1817 /* Reported length */
1818 proto_tree_add_item(fastser_tree, hf_selfm_fastser_len, tvb, offset, 1, ENC_BIG_ENDIAN);
1820 /* 5-byte Future Routing Address */
1821 proto_tree_add_item(fastser_tree, hf_selfm_fastser_routing_addr, tvb, offset+1, 5, ENC_NA);
1822 offset += 6;
1824 /* Add Status Byte to tree */
1825 proto_tree_add_item(fastser_tree, hf_selfm_fastser_status, tvb, offset, 1, ENC_BIG_ENDIAN);
1826 offset += 1;
1828 /* Get Function Code, add to tree */
1829 funccode = tvb_get_guint8(tvb, offset);
1830 proto_tree_add_item(fastser_tree, hf_selfm_fastser_funccode, tvb, offset, 1, ENC_BIG_ENDIAN);
1832 /* Append Column Info w/ Function Code */
1833 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "%s", val_to_str_const(funccode, selfm_fastser_func_code_vals, "Unknown Function Code"));
1835 offset += 1;
1837 /* Get Sequence Byte, add to Tree */
1838 seq = tvb_get_guint8(tvb, offset);
1839 seq_cnt = seq & FAST_SER_SEQ_CNT;
1840 seq_fir = seq & FAST_SER_SEQ_FIR;
1841 seq_fin = seq & FAST_SER_SEQ_FIN;
1843 fastser_seq_item = proto_tree_add_uint_format_value(fastser_tree, hf_selfm_fastser_seq, tvb, offset, 1, seq, "0x%02x (", seq);
1844 if (seq_fir) proto_item_append_text(fastser_seq_item, "FIR, ");
1845 if (seq_fin) proto_item_append_text(fastser_seq_item, "FIN, ");
1846 proto_item_append_text(fastser_seq_item, "Count %u)", seq_cnt);
1848 fastser_seq_tree = proto_item_add_subtree(fastser_seq_item, ett_selfm_fastser_seq);
1849 proto_tree_add_boolean(fastser_seq_tree, hf_selfm_fastser_seq_fir, tvb, offset, 1, seq);
1850 proto_tree_add_boolean(fastser_seq_tree, hf_selfm_fastser_seq_fin, tvb, offset, 1, seq);
1851 proto_tree_add_item(fastser_seq_tree, hf_selfm_fastser_seq_cnt, tvb, offset, 1, ENC_BIG_ENDIAN);
1852 offset += 1;
1854 /* Add Response Number to tree */
1855 proto_tree_add_item(fastser_tree, hf_selfm_fastser_resp_num, tvb, offset, 1, ENC_BIG_ENDIAN);
1856 offset += 1;
1858 /* Depending on Function Code used, remaining section of packet will be handled differently. */
1859 switch (funccode) {
1861 case FAST_SER_EN_UNS_DATA: /* 0x01 - Enabled Unsolicited Data Transfers */
1863 /* Function code to enable */
1864 fc_enable = tvb_get_guint8(tvb, offset);
1865 proto_tree_add_item(fastser_tree, hf_selfm_fastser_uns_en_fc, tvb, offset, 1, ENC_BIG_ENDIAN);
1867 /* Append Column Info w/ "Enable" Function Code */
1868 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "Function to Enable (%#x)", fc_enable);
1870 /* 3-byte Function Code data */
1871 proto_tree_add_item(fastser_tree, hf_selfm_fastser_uns_en_fc_data, tvb, offset+1, 3, ENC_NA);
1873 offset += 4;
1875 break;
1877 case FAST_SER_DIS_UNS_DATA: /* 0x02 - Disable Unsolicited Data Transfers */
1879 /* Function code to disable */
1880 fc_enable = tvb_get_guint8(tvb, offset);
1881 proto_tree_add_item(fastser_tree, hf_selfm_fastser_uns_dis_fc, tvb, offset, 1, ENC_BIG_ENDIAN);
1883 /* Append Column Info w/ "Disable" Function Code */
1884 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "Function to Disable (%#x)", fc_enable);
1886 /* 1-byte Function Code data */
1887 proto_tree_add_item(fastser_tree, hf_selfm_fastser_uns_dis_fc_data, tvb, offset+1, 1, ENC_NA);
1889 offset += 2;
1891 break;
1894 case FAST_SER_READ_REQ: /* 0x10 - Read Request */
1896 base_addr = tvb_get_ntohl(tvb, offset); /* 32-bit field with base address to read */
1898 /* Append Column Info w/ Base Address */
1899 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "%#x [%s]", base_addr, region_lookup(pinfo, base_addr));
1901 pi_baseaddr = proto_tree_add_item(fastser_tree, hf_selfm_fastser_baseaddr, tvb, offset, 4, ENC_BIG_ENDIAN);
1902 proto_item_append_text(pi_baseaddr, " [%s]", region_lookup(pinfo, base_addr));
1904 proto_tree_add_item(fastser_tree, hf_selfm_fastser_numwords, tvb, offset+4, 2, ENC_BIG_ENDIAN);
1905 offset += 6;
1906 break;
1908 case FAST_SER_GEN_UNS_DATA: /* 0x12 - Generic Unsolicited Data */
1910 num_addr = len - 14; /* 12 header bytes + 2-byte CRC, whatever is left is the data portion of this message */
1911 num_reg = num_addr / 2;
1913 /* For the number of registers, step through and retrieve/print each 16-bit component */
1914 for (cnt=0; cnt < num_reg; cnt++) {
1915 proto_tree_add_item(fastser_tree, hf_selfm_fastser_unswrite_reg_val, tvb, offset, 2, ENC_BIG_ENDIAN);
1916 offset += 2;
1919 break;
1921 case FAST_SER_SOE_STATE_REQ: /* 0x16 - SOE Present State Request */
1923 /* 4 bytes - "Origination Path" */
1924 proto_tree_add_item(fastser_tree, hf_selfm_fastser_soe_req_orig, tvb, offset, 4, ENC_NA);
1925 offset += 4;
1927 break;
1929 case FAST_SER_UNS_RESP: /* 0x18 - Unsolicited Fast SER Data Response */
1931 /* 4 bytes - "Origination Path" */
1932 proto_tree_add_item(fastser_tree, hf_selfm_fastser_unsresp_orig, tvb, offset, 4, ENC_NA);
1933 offset += 4;
1935 /* Timestamp: 2-byte day-of-year, 2-byte year, 4-byte time-of-day in milliseconds */
1936 /* 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? */
1937 tod_ms = tvb_get_ntohl(tvb, offset+4);
1939 proto_tree_add_item(fastser_tree, hf_selfm_fastser_unsresp_doy, tvb, offset, 2, ENC_BIG_ENDIAN);
1940 proto_tree_add_item(fastser_tree, hf_selfm_fastser_unsresp_year, tvb, offset+2, 2, ENC_BIG_ENDIAN);
1941 proto_tree_add_item(fastser_tree, hf_selfm_fastser_unsresp_todms, tvb, offset+4, 4, ENC_BIG_ENDIAN);
1942 proto_tree_add_text(fastser_tree, tvb, offset+4, 4, "Time of Day (decoded): %s", time_msecs_to_str(tod_ms));
1943 offset += 8;
1945 /* Build element tree */
1946 /* Determine the number of elements returned in this unsolicited message */
1947 /* The general formula is: (Length - 34) / 4 */
1948 num_elements = (len-34) / 4;
1950 fastser_elementlist_item = proto_tree_add_uint(fastser_tree, hf_selfm_fastser_unsresp_num_elmt, tvb, offset, (4*num_elements), num_elements);
1951 fastser_elementlist_tree = proto_item_add_subtree(fastser_elementlist_item, ett_selfm_fastser_element_list);
1953 /* "Reported New Status" word for up to 32 index elements is following the upcoming 0xFFFFFFFE End-of-record indicator
1954 Search for that indicator and use the detected tvb offset+4 to retrieve the proper 32-bit status word.
1955 Save this word for use in the element index printing but don't print the word itself until the end of the tree dissection */
1956 for (cnt = offset; cnt < len; cnt++) {
1958 if (tvb_memeql(tvb, cnt, "\xFF\xFF\xFF\xFE", 4) == 0) {
1959 elmt_status32_ofs = cnt+4;
1962 elmt_status32 = tvb_get_ntohl(tvb, elmt_status32_ofs );
1964 /* Cycle through each element we have detected that exists in the SER record */
1965 for (cnt=0; cnt<num_elements; cnt++) {
1967 /* Get Element Index and Timestamp Offset (in uSec) */
1968 elmt_idx = tvb_get_guint8(tvb, offset);
1969 elmt_ts_offset = (guint32)((tvb_get_guint8(tvb, offset+1) << 16) | (tvb_get_guint8(tvb, offset+2) << 8) | (tvb_get_guint8(tvb, offset+3)));
1971 /* 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 */
1972 elmt_status = ((elmt_status32 >> cnt) & 0x01);
1974 /* Build the tree */
1975 fastser_element_item = proto_tree_add_text(fastser_elementlist_tree, tvb, offset, 4,
1976 "Reported Event %d (Index: %d, New State: %s)", cnt+1, elmt_idx, val_to_str_const(elmt_status, selfm_ser_status_vals, "Unknown"));
1977 fastser_element_tree = proto_item_add_subtree(fastser_element_item, ett_selfm_fastser_element);
1979 /* Add Index Number and Timestamp offset to tree */
1980 proto_tree_add_item(fastser_element_tree, hf_selfm_fastser_unsresp_elmt_idx, tvb, offset, 1, ENC_BIG_ENDIAN);
1981 proto_tree_add_item(fastser_element_tree, hf_selfm_fastser_unsresp_elmt_ts_ofs, tvb, offset+1, 3, ENC_NA);
1982 proto_tree_add_text(fastser_element_tree, tvb, offset+1, 3,
1983 "SER Element Timestamp Offset (decoded): %s", time_msecs_to_str(tod_ms + (elmt_ts_offset/1000)));
1984 proto_tree_add_uint(fastser_element_tree, hf_selfm_fastser_unsresp_elmt_status, tvb, elmt_status32_ofs, 4, elmt_status);
1986 offset += 4;
1990 /* 4-byte End-of-Record Terminator 0xFFFFFFFE */
1991 proto_tree_add_item(fastser_tree, hf_selfm_fastser_unsresp_eor, tvb, offset, 4, ENC_NA);
1992 offset += 4;
1994 /* 4-byte Element Status word */
1995 proto_tree_add_item(fastser_tree, hf_selfm_fastser_unsresp_elmt_statword, tvb, offset, 4, ENC_BIG_ENDIAN);
1996 offset += 4;
1998 break;
2001 case FAST_SER_UNS_WRITE: /* 0x20 - Unsolicited Write */
2003 /* Write Address Region #1 and #2, along with number of 16-bit registers */
2004 addr1 = tvb_get_ntohs(tvb, offset);
2005 addr2 = tvb_get_ntohs(tvb, offset+2);
2006 num_reg = tvb_get_ntohs(tvb, offset+4);
2008 /* Append Column Info w/ Address Information */
2009 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "%#x, %#x", addr1, addr2);
2011 proto_tree_add_item(fastser_tree, hf_selfm_fastser_unswrite_addr1, tvb, offset, 2, ENC_BIG_ENDIAN);
2012 proto_tree_add_item(fastser_tree, hf_selfm_fastser_unswrite_addr2, tvb, offset+2, 2, ENC_BIG_ENDIAN);
2013 proto_tree_add_item(fastser_tree, hf_selfm_fastser_unswrite_num_reg, tvb, offset+4, 2, ENC_BIG_ENDIAN);
2015 offset += 6;
2017 /* For the number of registers, step through and retrieve/print each 16-bit component */
2018 for (cnt=0; cnt < num_reg; cnt++) {
2019 proto_tree_add_item(fastser_tree, hf_selfm_fastser_unswrite_reg_val, tvb, offset, 2, ENC_BIG_ENDIAN);
2020 offset += 2;
2023 break;
2025 case FAST_SER_DATAFMT_REQ: /* 0x31 - Data Format Request */
2027 base_addr = tvb_get_ntohl(tvb, offset); /* 32-bit field with base address to read */
2029 /* Append Column Info w/ Base Address */
2030 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "%#x [%s]", base_addr, region_lookup(pinfo, base_addr));
2032 /* Add Base Address to Tree */
2033 pi_baseaddr = proto_tree_add_item(fastser_tree, hf_selfm_fastser_baseaddr, tvb, offset, 4, ENC_BIG_ENDIAN);
2034 proto_item_append_text(pi_baseaddr, " [%s]", region_lookup(pinfo, base_addr));
2036 offset += 4;
2038 break;
2040 case FAST_SER_BITLABEL_REQ: /* 0x33 - Bit Label Request */
2042 base_addr = tvb_get_ntohl(tvb, offset); /* 32-bit field with base address to read */
2043 proto_tree_add_item(fastser_tree, hf_selfm_fastser_baseaddr, tvb, offset, 4, ENC_BIG_ENDIAN);
2044 offset += 4;
2046 /* Append Column Info w/ Base Address */
2047 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "%#x", base_addr);
2049 break;
2052 case FAST_SER_MESSAGE_DEF_ACK: /* 0x80 (resp to 0x00) - Fast SER Message Definition Acknowledge */
2054 /* Routing Support */
2055 proto_tree_add_item(fastser_tree, hf_selfm_fastser_def_route_sup, tvb, offset, 1, ENC_BIG_ENDIAN);
2056 offset += 1;
2058 /* RX / TX Status */
2059 proto_tree_add_item(fastser_tree, hf_selfm_fastser_def_rx_stat, tvb, offset, 1, ENC_BIG_ENDIAN);
2060 proto_tree_add_item(fastser_tree, hf_selfm_fastser_def_tx_stat, tvb, offset+1, 1, ENC_BIG_ENDIAN);
2061 offset += 2;
2063 /* Max Frames RX/TX */
2064 proto_tree_add_item(fastser_tree, hf_selfm_fastser_def_rx_maxfr, tvb, offset, 1, ENC_BIG_ENDIAN);
2065 proto_tree_add_item(fastser_tree, hf_selfm_fastser_def_tx_maxfr, tvb, offset+1, 1, ENC_BIG_ENDIAN);
2066 offset += 2;
2068 /* 6 bytes of reserved space */
2069 offset += 6;
2071 /* Number of Supported RX Function Codes */
2072 rx_num_fc = tvb_get_guint8(tvb, offset);
2073 fastser_def_fc_item = proto_tree_add_item(fastser_tree, hf_selfm_fastser_def_rx_num_fc, tvb, offset, 1, ENC_BIG_ENDIAN);
2074 fastser_def_fc_tree = proto_item_add_subtree(fastser_def_fc_item, ett_selfm_fastser_def_fc);
2075 offset += 1;
2077 /* Add Supported RX Function Codes to tree */
2078 for (cnt=0; cnt<rx_num_fc; cnt++) {
2079 proto_tree_add_item(fastser_def_fc_tree, hf_selfm_fastser_def_rx_fc, tvb, offset, 1, ENC_BIG_ENDIAN);
2080 offset += 2;
2083 /* Number of Supported TX Function Codes */
2084 tx_num_fc = tvb_get_guint8(tvb, offset);
2085 fastser_def_fc_item = proto_tree_add_item(fastser_tree, hf_selfm_fastser_def_tx_num_fc, tvb, offset, 1, ENC_BIG_ENDIAN);
2086 fastser_def_fc_tree = proto_item_add_subtree(fastser_def_fc_item, ett_selfm_fastser_def_fc);
2087 offset += 1;
2089 /* Add Supported TX Function Codes to tree */
2090 for (cnt=0; cnt<tx_num_fc; cnt++) {
2091 proto_tree_add_item(fastser_def_fc_tree, hf_selfm_fastser_def_tx_fc, tvb, offset, 1, ENC_BIG_ENDIAN);
2092 offset += 2;
2095 break;
2097 case FAST_SER_READ_RESP: /* 0x90 (resp to 0x10) - Read Response */
2099 offset = dissect_fastser_readresp_frame( tvb, fastser_tree, pinfo, offset, seq);
2101 break;
2103 case FAST_SER_SOE_STATE_RESP: /* 0x96 - (resp to 0x16) SOE Present State Response */
2106 /* 16-bit field with number of blocks of present state data */
2107 proto_tree_add_item(fastser_tree, hf_selfm_fastser_soe_resp_numblks, tvb, offset, 2, ENC_BIG_ENDIAN);
2108 offset += 2;
2110 /* XXX - With examples, need to loop through each one of these items based on the num_blocks */
2111 proto_tree_add_item(fastser_tree, hf_selfm_fastser_soe_resp_orig, tvb, offset, 4, ENC_BIG_ENDIAN);
2112 proto_tree_add_item(fastser_tree, hf_selfm_fastser_soe_resp_numbits, tvb, offset+4, 1, ENC_BIG_ENDIAN);
2113 proto_tree_add_item(fastser_tree, hf_selfm_fastser_soe_resp_pad, tvb, offset+5, 1, ENC_BIG_ENDIAN);
2114 proto_tree_add_item(fastser_tree, hf_selfm_fastser_soe_resp_doy, tvb, offset+6, 2, ENC_BIG_ENDIAN);
2115 proto_tree_add_item(fastser_tree, hf_selfm_fastser_soe_resp_year, tvb, offset+8, 2, ENC_BIG_ENDIAN);
2116 proto_tree_add_item(fastser_tree, hf_selfm_fastser_soe_resp_tod, tvb, offset+10, 4, ENC_BIG_ENDIAN);
2117 /* proto_tree_add_item(fastser_tree, hf_selfm_fastser_soe_resp_data, tvb, offset+14, 2, ENC_BIG_ENDIAN); */
2119 offset += 14;
2121 break;
2123 case FAST_SER_DEVDESC_RESP: /* 0xB0 (resp to 0x30) - Device Description Response */
2125 fid_str_ptr = tvb_get_string(wmem_packet_scope(), tvb, offset, 50); /* Add FID / RID ASCII data to tree */
2126 rid_str_ptr = tvb_get_string(wmem_packet_scope(), tvb, offset+50, 40);
2127 proto_tree_add_text(fastser_tree, tvb, offset, 50, "FID: %s", fid_str_ptr);
2128 proto_tree_add_text(fastser_tree, tvb, offset+50, 40, "RID: %s", rid_str_ptr);
2129 offset += 90;
2131 /* 16-bit field with number of data areas */
2132 num_reg = tvb_get_ntohs(tvb, offset);
2133 proto_tree_add_item(fastser_tree, hf_selfm_fastser_devdesc_num_region, tvb, offset, 2, ENC_BIG_ENDIAN);
2134 offset += 2;
2136 /* Maximum size of 7 regions per message, check the seq_cnt to determine if we have stepped into
2137 the next sequential message where the remaining regions would be described */
2138 if ((num_reg >= 8) && (seq_cnt == 0)) {
2139 num_reg = 7;
2141 else{
2142 num_reg = num_reg - (seq_cnt * 7);
2145 /* 16-bit field with number of control areas */
2146 proto_tree_add_item(fastser_tree, hf_selfm_fastser_devdesc_num_ctrl, tvb, offset, 2, ENC_BIG_ENDIAN);
2147 offset += 2;
2149 /* Each 18-byte data area description has a 10 byte region name, followed by 32-bit base, */
2150 /* 16-bit message word count and 16-bit flag field */
2151 for (cnt=0; cnt<num_reg; cnt++) {
2153 fastser_datareg_item = proto_tree_add_text(fastser_tree, tvb, offset, 18, "Fast SER Data Region #%d", cnt+1);
2154 fastser_datareg_tree = proto_item_add_subtree(fastser_datareg_item, ett_selfm_fastser_datareg);
2156 /* 10-Byte Region description */
2157 region_name_ptr = tvb_get_string(wmem_packet_scope(), tvb, offset, 10);
2158 proto_tree_add_text(fastser_datareg_tree, tvb, offset, 10, "Data Region Name: %s", region_name_ptr);
2159 offset += 10;
2161 /* 32-bit field with base address of data region */
2162 proto_tree_add_item(fastser_datareg_tree, hf_selfm_fastser_baseaddr, tvb, offset, 4, ENC_BIG_ENDIAN);
2163 offset += 4;
2165 /* 16-bit field with number of 16-bit words in region */
2166 proto_tree_add_item(fastser_datareg_tree, hf_selfm_fastser_numwords, tvb, offset, 2, ENC_BIG_ENDIAN);
2167 offset += 2;
2169 /* 16-bit flag field */
2170 proto_tree_add_item(fastser_datareg_tree, hf_selfm_fastser_flags, tvb, offset, 2, ENC_BIG_ENDIAN);
2171 offset += 2;
2175 /* Some relays (4xx) don't follow the standard here and include an 8-byte sequence of all 0x00's to represent */
2176 /* 'reserved' space for the control regions. Detect these and skip if they are present */
2177 for (cnt = offset; cnt < len; cnt++) {
2179 if (tvb_memeql(tvb, cnt, "\x00\x00\x00\x00\x00\x00\x00\x00", 8) == 0) {
2180 offset = cnt+8;
2184 break;
2186 case FAST_SER_DATAFMT_RESP: /* 0xB1 (resp to 0x31) - Data Format Response */
2188 base_addr = tvb_get_ntohl(tvb, offset); /* 32-bit field with base address to read */
2190 /* Add Base Address to Tree */
2191 pi_baseaddr = proto_tree_add_item(fastser_tree, hf_selfm_fastser_baseaddr, tvb, offset, 4, ENC_BIG_ENDIAN);
2192 proto_item_append_text(pi_baseaddr, " [%s]", region_lookup(pinfo, base_addr));
2194 offset += 4;
2196 /* Append Column Info w/ Base Address */
2197 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "%#x [%s]", base_addr, region_lookup(pinfo, base_addr));
2199 /* 16-bit field with number of data items to follow */
2200 proto_tree_add_item(fastser_tree, hf_selfm_fastser_datafmt_resp_numitem, tvb, offset, 2, ENC_BIG_ENDIAN);
2201 offset += 2;
2203 while ((tvb_reported_length_remaining(tvb, offset)) > 2) {
2204 tag_name_ptr = tvb_get_string(wmem_packet_scope(), tvb, offset, 10); /* Data Item record name 10 bytes */
2205 fastser_tag_item = proto_tree_add_text(fastser_tree, tvb, offset, 14, "Data Item Record Name: %s", tag_name_ptr);
2206 fastser_tag_tree = proto_item_add_subtree(fastser_tag_item, ett_selfm_fastser_tag);
2208 /* Data item qty and type */
2209 proto_tree_add_item(fastser_tag_tree, hf_selfm_fastser_dataitem_qty, tvb, offset+10, 2, ENC_BIG_ENDIAN);
2210 proto_tree_add_item(fastser_tag_tree, hf_selfm_fastser_dataitem_type, tvb, offset+12, 2, ENC_BIG_ENDIAN);
2212 offset += 14;
2214 break;
2216 case FAST_SER_BITLABEL_RESP: /* 0xB3 (resp to 0x33) - Bit Label Response */
2218 /* The data in this response is a variable length string containing the names of 8 digital bits. */
2219 /* Each name is max 8 chars and each is null-seperated */
2220 cnt=1;
2222 /* find the null separators and add the bit label text strings to the tree */
2223 for (null_offset = offset; null_offset < len; null_offset++) {
2224 if ((tvb_memeql(tvb, null_offset, "\x00", 1) == 0) && (tvb_reported_length_remaining(tvb, offset) > 2)) {
2225 proto_tree_add_text(fastser_tree, tvb, offset, (null_offset-offset), "Bit Label #%d Name: %s", cnt,
2226 tvb_format_text(tvb, offset, (null_offset-offset)));
2227 offset = null_offset+1; /* skip the null */
2228 cnt++;
2232 break;
2234 default:
2235 break;
2236 } /* func_code */
2238 /* XXX - Should eventually get a function here to validate this CRC16 */
2239 proto_tree_add_item(fastser_tree, hf_selfm_fastser_crc16, tvb, offset, 2, ENC_BIG_ENDIAN);
2241 return tvb_length(tvb);
2246 /******************************************************************************************************/
2247 /* Code to dissect SEL Fast Message Protocol packets */
2248 /* Will call other sub-dissectors, as needed */
2249 /******************************************************************************************************/
2250 static int
2251 dissect_selfm(tvbuff_t *selfm_tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
2253 /* Set up structures needed to add the protocol subtree and manage it */
2254 proto_item *selfm_item=NULL;
2255 proto_tree *selfm_tree=NULL;
2256 int offset=0, cnt=0;
2257 guint32 base_addr;
2258 guint16 msg_type, len, num_items;
2259 guint8 seq, seq_cnt;
2261 /* Make entries in Protocol column on summary display */
2262 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SEL Fast Msg");
2263 col_clear(pinfo->cinfo, COL_INFO);
2265 len = tvb_length(selfm_tvb);
2267 msg_type = tvb_get_ntohs(selfm_tvb, offset);
2269 /* On first pass through the packets we have 4 tasks to complete - they are each noted below */
2270 if (!pinfo->fd->flags.visited) {
2271 conversation_t *conversation;
2272 fm_conversation *fm_conv_data;
2274 /* Find a conversation, create a new if no one exists */
2275 conversation = find_or_create_conversation(pinfo);
2277 fm_conv_data = (fm_conversation *)conversation_get_proto_data(conversation, proto_selfm);
2279 if (fm_conv_data == NULL) {
2280 fm_conv_data = wmem_new(wmem_file_scope(), fm_conversation);
2281 fm_conv_data->fm_config_frames = wmem_list_new(wmem_file_scope());
2282 fm_conv_data->fastser_dataitems = wmem_list_new(wmem_file_scope());
2283 fm_conv_data->fastser_dataregions = wmem_tree_new(wmem_file_scope());
2284 conversation_add_proto_data(conversation, proto_selfm, (void *)fm_conv_data);
2287 p_add_proto_data(pinfo->fd, proto_selfm, 0, fm_conv_data);
2289 /* 1. Configuration frames (0xA5C1, 0xA5C2, 0xA5C3) need special treatment during the first run */
2290 /* For each Fast Meter Configuration frame (0xA5Cx), a 'fm_config_frame' struct is created to hold the */
2291 /* information necessary to decode subsequent matching Fast Meter Data frames (0xA5Dx). A pointer to */
2292 /* this struct is saved in the conversation and is copied to the per-packet information if a */
2293 /* Fast Meter Data frame is dissected. */
2294 if ((CMD_FM_CONFIG == msg_type) || (CMD_DFM_CONFIG == msg_type) || (CMD_PDFM_CONFIG == msg_type)) {
2295 /* Fill the fm_config_frame */
2296 fm_config_frame *frame_ptr = fmconfig_frame_fast(selfm_tvb);
2297 frame_ptr->fnum = pinfo->fd->num;
2298 wmem_list_prepend(fm_conv_data->fm_config_frames, frame_ptr);
2301 /* 2. Fill conversation data array with Fast SER Data Item info from Data Format Response Messages. */
2302 /* These format definitions will later be retrieved to decode Read Response messages. */
2303 if ((CMD_FAST_SER == msg_type) && (tvb_get_guint8(selfm_tvb, offset+9) == FAST_SER_DATAFMT_RESP)) {
2305 seq = tvb_get_guint8(selfm_tvb, offset+10);
2306 seq_cnt = seq & FAST_SER_SEQ_CNT;
2308 base_addr = tvb_get_ntohl(selfm_tvb, offset+12); /* 32-bit field with base address to read */
2309 num_items = tvb_get_ntohs(selfm_tvb, offset+16);
2311 /* When dealing with Data Format Response messages, there are a maximum of 16 items per frame */
2312 /* Use the sequence count if we have more 16 items to determine how many to expect in each frame */
2313 if ((num_items > 16) && (seq_cnt == 0)) {
2314 num_items = 16;
2316 else {
2317 num_items = num_items - (seq_cnt * 16);
2320 /* Set offset to start of data items */
2321 offset = 18;
2323 /* Enter the single frame multiple times, retrieving a single dataitem per entry */
2324 for (cnt = 1; (cnt <= num_items); cnt++) {
2325 fastser_dataitem *dataitem_ptr = fastser_dataitem_save(selfm_tvb, offset);
2326 dataitem_ptr->fnum = pinfo->fd->num;
2327 dataitem_ptr->base_address = base_addr;
2328 dataitem_ptr->index_pos = cnt;
2330 /* Store the data item configuration info in the fastser_dataitems list */
2331 wmem_list_append(fm_conv_data->fastser_dataitems, dataitem_ptr);
2332 offset += 14;
2336 /* 3. Attempt re-assembly during first pass with Read Response Messages data payloads that span multiple */
2337 /* packets. The final data payload will be assembled on the packet with the seq_fin bit set. */
2338 if ((CMD_FAST_SER == msg_type) && (tvb_get_guint8(selfm_tvb, offset+9) == FAST_SER_READ_RESP)) {
2340 seq = tvb_get_guint8(selfm_tvb, offset+10);
2342 /* Set offset to where the dissect_fastser_readresp_frame function would normally be called, */
2343 /* right before base address & num_items */
2344 offset = 12;
2346 /* Call the same read response function that will be called during GUI dissection */
2347 offset = dissect_fastser_readresp_frame( selfm_tvb, tree, pinfo, offset, seq);
2351 /* 4. Fill conversation data array with Fast SER Data Region info from Device Desc Response Messages. This */
2352 /* will retrieve a data region name (associated to an address) that can later be displayed in the tree. */
2353 if ((CMD_FAST_SER == msg_type) && (tvb_get_guint8(selfm_tvb, offset+9) == FAST_SER_DEVDESC_RESP)) {
2355 seq = tvb_get_guint8(selfm_tvb, offset+10);
2356 seq_cnt = seq & FAST_SER_SEQ_CNT;
2358 num_items = tvb_get_ntohs(selfm_tvb, offset+102);
2360 /* When dealing with Device Description Response messages, there are a maximum of 7 regions per frame */
2361 /* Use the sequence count if we have more 7 items to determine how many to expect in each frame */
2362 if ((num_items >= 8) && (seq_cnt == 0)) {
2363 num_items = 7;
2365 else{
2366 num_items = num_items - (seq_cnt * 7);
2369 /* Set offset to start of data regions */
2370 offset = 106;
2372 /* Enter the single frame multiple times, retrieving a single data region per entry */
2373 for (cnt = 1; (cnt <= num_items); cnt++) {
2374 guint32 base_address = tvb_get_ntohl(selfm_tvb, offset+10);
2375 fastser_dataregion *dataregion_ptr = fastser_dataregion_save(selfm_tvb, offset);
2377 /* Store the data region info in the fastser_dataregions tree */
2378 wmem_tree_insert32(fm_conv_data->fastser_dataregions, base_address, dataregion_ptr);
2379 offset += 18;
2384 } /* if (!visited) */
2386 if (tree) {
2388 selfm_item = proto_tree_add_protocol_format(tree, proto_selfm, selfm_tvb, 0, len, "SEL Fast Message");
2389 selfm_tree = proto_item_add_subtree(selfm_item, ett_selfm);
2391 /* Set INFO column with SEL Protocol Message Type */
2392 col_add_fstr(pinfo->cinfo, COL_INFO, "%s", val_to_str_const(msg_type, selfm_msgtype_vals, "Unknown Message Type"));
2394 /* Add Message Type to Protocol Tree */
2395 proto_tree_add_item(selfm_tree, hf_selfm_msgtype, selfm_tvb, offset, 2, ENC_BIG_ENDIAN);
2396 offset += 2;
2398 /* Determine correct message type and call appropriate dissector */
2399 if (tvb_reported_length_remaining(selfm_tvb, offset) > 0) {
2400 switch (msg_type) {
2401 case CMD_RELAY_DEF:
2402 dissect_relaydef_frame(selfm_tvb, selfm_tree, offset);
2403 break;
2404 case CMD_FM_CONFIG:
2405 case CMD_DFM_CONFIG:
2406 case CMD_PDFM_CONFIG:
2407 dissect_fmconfig_frame(selfm_tvb, selfm_tree, offset);
2408 break;
2409 case CMD_FM_DATA:
2410 dissect_fmdata_frame(selfm_tvb, selfm_tree, pinfo, offset, CMD_FM_CONFIG);
2411 break;
2412 case CMD_DFM_DATA:
2413 dissect_fmdata_frame(selfm_tvb, selfm_tree, pinfo, offset, CMD_DFM_CONFIG);
2414 break;
2415 case CMD_PDFM_DATA:
2416 dissect_fmdata_frame(selfm_tvb, selfm_tree, pinfo, offset, CMD_PDFM_CONFIG);
2417 break;
2418 case CMD_FASTOP_CONFIG:
2419 dissect_foconfig_frame(selfm_tvb, selfm_tree, offset);
2420 break;
2421 case CMD_FAST_SER:
2422 dissect_fastser_frame(selfm_tvb, selfm_tree, pinfo, offset);
2423 break;
2424 case CMD_FASTOP_RB_CTRL:
2425 case CMD_FASTOP_BR_CTRL:
2426 dissect_fastop_frame(selfm_tvb, selfm_tree, pinfo, offset);
2427 break;
2428 case CMD_ALT_FASTOP_CONFIG:
2429 dissect_alt_fastop_config_frame(selfm_tvb, selfm_tree, offset);
2430 break;
2431 case CMD_ALT_FASTOP_OPEN:
2432 case CMD_ALT_FASTOP_CLOSE:
2433 case CMD_ALT_FASTOP_SET:
2434 case CMD_ALT_FASTOP_CLEAR:
2435 case CMD_ALT_FASTOP_PULSE:
2436 dissect_alt_fastop_frame(selfm_tvb, selfm_tree, pinfo, offset);
2437 break;
2438 default:
2439 break;
2440 } /* msg_type */
2441 } /* remaining length > 0 */
2442 } /* tree */
2444 return tvb_length(selfm_tvb);
2447 /******************************************************************************************************/
2448 /* Return length of SEL Protocol over TCP message (used for re-assembly) */
2449 /* SEL Protocol "Scan" messages are generally 2-bytes in length and only include a 16-bit message type */
2450 /* SEL Protocol "Response" messages include a "length" byte in offset 2 of each response message */
2451 /******************************************************************************************************/
2452 static guint
2453 get_selfm_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset _U_)
2455 guint message_len=0; /* message length, inclusive of header, data, crc */
2457 /* Get length byte from message */
2458 if (tvb_length(tvb) > 2) {
2459 message_len = tvb_get_guint8(tvb, 2);
2461 /* for 2-byte poll messages, set the length to 2 */
2462 else if (tvb_length(tvb) == 2) {
2463 message_len = 2;
2466 return message_len;
2469 /******************************************************************************************************/
2470 /* Dissect (and possibly Re-assemble) SEL protocol payload data */
2471 /******************************************************************************************************/
2472 static gboolean
2473 dissect_selfm_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
2476 tvbuff_t *selfm_tvb;
2477 gint length = tvb_length(tvb);
2479 /* Check for a SEL FM packet. It should begin with 0xA5 */
2480 if(length < 2 || tvb_get_guint8(tvb, 0) != 0xA5) {
2481 /* Not a SEL Protocol packet, just happened to use the same port */
2482 return FALSE;
2485 /* If this is a Telnet-encapsulated Ethernet, let's clean out the IAC 0xFF instances */
2486 /* before we attempt any kind of re-assembly of the message */
2487 if ((pinfo->srcport) && selfm_telnet_clean) {
2488 selfm_tvb = clean_telnet_iac(pinfo, tvb, 0, length);
2490 else {
2491 selfm_tvb = tvb_new_subset( tvb, 0, length, length);
2495 tcp_dissect_pdus(selfm_tvb, pinfo, tree, selfm_desegment, 2,
2496 get_selfm_len, dissect_selfm, data);
2498 return TRUE;
2501 /******************************************************************************************************/
2502 /* Dissect "simple" SEL protocol payload (no TCP re-assembly) */
2503 /******************************************************************************************************/
2504 static gboolean
2505 dissect_selfm_simple(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
2507 gint length = tvb_length(tvb);
2509 /* Check for a SEL FM packet. It should begin with 0xA5 */
2510 if(length < 2 || tvb_get_guint8(tvb, 0) != 0xA5) {
2511 /* Not a SEL Protocol packet, just happened to use the same port */
2512 return FALSE;
2515 dissect_selfm(tvb, pinfo, tree, data);
2517 return TRUE;
2520 /******************************************************************************************************/
2521 /* SEL Fast Message Dissector initialization */
2522 /******************************************************************************************************/
2523 static void
2524 selfm_init(void)
2527 reassembly_table_init(&selfm_reassembly_table,
2528 &addresses_reassembly_table_functions);
2531 /******************************************************************************************************/
2532 /* Register the protocol with Wireshark */
2533 /******************************************************************************************************/
2534 void proto_reg_handoff_selfm(void);
2536 void
2537 proto_register_selfm(void)
2539 /* SEL Protocol header fields */
2540 static hf_register_info selfm_hf[] = {
2541 { &hf_selfm_msgtype,
2542 { "Message Type", "selfm.msgtype", FT_UINT16, BASE_HEX|BASE_EXT_STRING, &selfm_msgtype_vals_ext, 0x0, NULL, HFILL }},
2543 { &hf_selfm_padbyte,
2544 { "Pad Byte", "selfm.padbyte", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},
2545 { &hf_selfm_checksum,
2546 { "Checksum", "selfm.checksum", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},
2547 /* "Relay Definition" specific fields */
2548 { &hf_selfm_relaydef_len,
2549 { "Length", "selfm.relaydef.len", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2550 { &hf_selfm_relaydef_numproto,
2551 { "Number of Protocols", "selfm.relaydef.numproto", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2552 { &hf_selfm_relaydef_numfm,
2553 { "Number of Fast Meter Messages", "selfm.relaydef.numfm", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2554 { &hf_selfm_relaydef_numflags,
2555 { "Number of Status Flags", "selfm.relaydef.numflags", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2556 { &hf_selfm_relaydef_fmcfg_cmd,
2557 { "Fast Meter Config Command", "selfm.relaydef.fmcfg_cmd", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
2558 { &hf_selfm_relaydef_fmdata_cmd,
2559 { "Fast Meter Data Command", "selfm.relaydef.fmdata_cmd", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
2560 { &hf_selfm_relaydef_statbit,
2561 { "Status Flag Bit", "selfm.relaydef.status_bit", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
2562 { &hf_selfm_relaydef_statbit_cmd,
2563 { "Status Flag Bit Response Command", "selfm.relaydef.status_bit_cmd", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
2564 { &hf_selfm_relaydef_proto,
2565 { "Supported Protocol", "selfm.relaydef.proto", FT_UINT16, BASE_HEX|BASE_EXT_STRING, &selfm_relaydef_proto_vals_ext, 0x0, NULL, HFILL }},
2566 /* "Fast Meter Configuration" specific fields */
2567 { &hf_selfm_fmconfig_len,
2568 { "Length", "selfm.fmconfig.len", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2569 { &hf_selfm_fmconfig_numflags,
2570 { "Number of Status Flags", "selfm.fmconfig.numflags", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2571 { &hf_selfm_fmconfig_loc_sf,
2572 { "Location of Scale Factor", "selfm.fmconfig.loc_sf", FT_UINT8, BASE_DEC, VALS(selfm_fmconfig_sfloc_vals), 0x0, NULL, HFILL }},
2573 { &hf_selfm_fmconfig_num_sf,
2574 { "Number of Scale Factors", "selfm.fmconfig.num_sf", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2575 { &hf_selfm_fmconfig_num_ai,
2576 { "Number of Analog Input Channels", "selfm.fmconfig.num_ai", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2577 { &hf_selfm_fmconfig_num_samp,
2578 { "Number of Samples per AI Channel", "selfm.fmconfig.num_samp", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2579 { &hf_selfm_fmconfig_num_dig,
2580 { "Number of Digital Banks", "selfm.fmconfig.num_dig", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2581 { &hf_selfm_fmconfig_num_calc,
2582 { "Number of Calculation Blocks", "selfm.fmconfig.num_calc", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2583 { &hf_selfm_fmconfig_ofs_ai,
2584 { "First Analog Channel Offset", "selfm.fmconfig.ofs_ai", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2585 { &hf_selfm_fmconfig_ofs_ts,
2586 { "Timestamp Offset", "selfm.fmconfig.ofs_ts", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2587 { &hf_selfm_fmconfig_ofs_dig,
2588 { "First Digital Bank Offset", "selfm.fmconfig.ofs_dig", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2589 { &hf_selfm_fmconfig_ai_type,
2590 { "Analog Channel Type", "selfm.fmconfig.ai_type", FT_UINT8, BASE_DEC, VALS(selfm_fmconfig_ai_chtype_vals), 0x0, NULL, HFILL }},
2591 { &hf_selfm_fmconfig_ai_sf_type,
2592 { "Analog Channel Scale Factor Type", "selfm.fmconfig.ai_sf_type", FT_UINT8, BASE_DEC, VALS(selfm_fmconfig_ai_sftype_vals), 0x0, NULL, HFILL }},
2593 { &hf_selfm_fmconfig_ai_sf_ofs,
2594 { "Analog Channel Scale Factor Offset", "selfm.fmconfig.ai_sf_ofs", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2595 { &hf_selfm_fmconfig_cblk_rot,
2596 { "Rotation", "selfm.fmconfig.cblk_rot", FT_UINT8, BASE_HEX, VALS(selfm_fmconfig_cblk_rot_vals), 0x01, NULL, HFILL }},
2597 { &hf_selfm_fmconfig_cblk_vconn,
2598 { "Voltage Connection", "selfm.fmconfig.cblk_vconn", FT_UINT8, BASE_HEX, VALS(selfm_fmconfig_cblk_vconn_vals), 0x06, NULL, HFILL }},
2599 { &hf_selfm_fmconfig_cblk_iconn,
2600 { "Current Connection", "selfm.fmconfig.cblk_iconn", FT_UINT8, BASE_HEX, VALS(selfm_fmconfig_cblk_iconn_vals), 0x18, NULL, HFILL }},
2601 { &hf_selfm_fmconfig_cblk_ctype,
2602 { "Calculation Type", "selfm.fmconfig.cblk_ctype", FT_UINT8, BASE_DEC, VALS(selfm_fmconfig_cblk_ctype_vals), 0x0, NULL, HFILL }},
2603 { &hf_selfm_fmconfig_cblk_deskew_ofs,
2604 { "Skew Correction Offset", "selfm.fmconfig.cblk_deskew_ofs", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2605 { &hf_selfm_fmconfig_cblk_rs_ofs,
2606 { "Rs Offset", "selfm.fmconfig.cblk_rs_ofs", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2607 { &hf_selfm_fmconfig_cblk_xs_ofs,
2608 { "Xs Offset", "selfm.fmconfig.cblk_xs_ofs", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2609 { &hf_selfm_fmconfig_cblk_ia_idx,
2610 { "Analog Record Ia Index Position", "selfm.fmconfig.cblk_ia_idx", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2611 { &hf_selfm_fmconfig_cblk_ib_idx,
2612 { "Analog Record Ib Index Position", "selfm.fmconfig.cblk_ib_idx", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2613 { &hf_selfm_fmconfig_cblk_ic_idx,
2614 { "Analog Record Ic Index Position", "selfm.fmconfig.cblk_ic_idx", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2615 { &hf_selfm_fmconfig_cblk_va_idx,
2616 { "Analog Record Va/Vab Index Position", "selfm.fmconfig.cblk_va_idx", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2617 { &hf_selfm_fmconfig_cblk_vb_idx,
2618 { "Analog Record Vb/Vbc Index Position", "selfm.fmconfig.cblk_vb_idx", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2619 { &hf_selfm_fmconfig_cblk_vc_idx,
2620 { "Analog Record Vc/Vca Index Position", "selfm.fmconfig.cblk_vc_idx", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2621 /* "Fast Meter Data" specific fields */
2622 { &hf_selfm_fmdata_len,
2623 { "Length", "selfm.fmdata.len", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2624 { &hf_selfm_fmdata_flagbyte,
2625 { "Status Flags Byte", "selfm.fmdata.flagbyte", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2626 { &hf_selfm_fmdata_ai_sf_fp,
2627 { "Using IEEE FP Format Scale Factor", "selfm.fmdata.ai.sf_fp",FT_FLOAT, BASE_NONE, NULL, 0x0, NULL, HFILL }},
2628 { &hf_selfm_fmdata_dig_b0,
2629 { "Bit 0", "selfm.fmdata.dig_b0", FT_BOOLEAN, 8, NULL, 0x01, NULL, HFILL }},
2630 { &hf_selfm_fmdata_dig_b1,
2631 { "Bit 1", "selfm.fmdata.dig_b1", FT_BOOLEAN, 8, NULL, 0x02, NULL, HFILL }},
2632 { &hf_selfm_fmdata_dig_b2,
2633 { "Bit 2", "selfm.fmdata.dig_b2", FT_BOOLEAN, 8, NULL, 0x04, NULL, HFILL }},
2634 { &hf_selfm_fmdata_dig_b3,
2635 { "Bit 3", "selfm.fmdata.dig_b3", FT_BOOLEAN, 8, NULL, 0x08, NULL, HFILL }},
2636 { &hf_selfm_fmdata_dig_b4,
2637 { "Bit 4", "selfm.fmdata.dig_b4", FT_BOOLEAN, 8, NULL, 0x10, NULL, HFILL }},
2638 { &hf_selfm_fmdata_dig_b5,
2639 { "Bit 5", "selfm.fmdata.dig_b5", FT_BOOLEAN, 8, NULL, 0x20, NULL, HFILL }},
2640 { &hf_selfm_fmdata_dig_b6,
2641 { "Bit 6", "selfm.fmdata.dig_b6", FT_BOOLEAN, 8, NULL, 0x40, NULL, HFILL }},
2642 { &hf_selfm_fmdata_dig_b7,
2643 { "Bit 7", "selfm.fmdata.dig_b7", FT_BOOLEAN, 8, NULL, 0x80, NULL, HFILL }},
2644 /* "Fast Operate Configuration" specific fields */
2645 { &hf_selfm_foconfig_len,
2646 { "Length", "selfm.foconfig.len", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2647 { &hf_selfm_foconfig_num_brkr,
2648 { "Number of Breaker Bits", "selfm.foconfig.num_brkr", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2649 { &hf_selfm_foconfig_num_rb,
2650 { "Number of Remote Bits", "selfm.foconfig.num_rb", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2651 { &hf_selfm_foconfig_prb_supp,
2652 { "Remote Bit Pulse Supported", "selfm.foconfig.prb_supp", FT_UINT8, BASE_DEC, VALS(selfm_foconfig_prb_supp_vals), 0x0, NULL, HFILL }},
2653 { &hf_selfm_foconfig_reserved,
2654 { "Reserved Bit (Future)", "selfm.foconfig.reserved", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2655 { &hf_selfm_foconfig_brkr_open,
2656 { "Breaker Bit Open Command", "selfm.foconfig.brkr_open", FT_UINT8, BASE_HEX, VALS(selfm_fo_br_vals), 0x0, NULL, HFILL }},
2657 { &hf_selfm_foconfig_brkr_close,
2658 { "Breaker Bit Close Command", "selfm.foconfig.brkr_close", FT_UINT8, BASE_HEX, VALS(selfm_fo_br_vals), 0x0, NULL, HFILL }},
2659 { &hf_selfm_foconfig_rb_cmd,
2660 { "Remote Bit Command", "selfm.foconfig.rb_cmd", FT_UINT8, BASE_HEX, VALS(selfm_fo_rb_vals), 0x0, NULL, HFILL }},
2661 /* "Alternate Fast Operate Configuration" specific fields */
2662 { &hf_selfm_alt_foconfig_len,
2663 { "Length", "selfm.alt_foconfig.len", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2664 { &hf_selfm_alt_foconfig_num_ports,
2665 { "Number of Ports Available", "selfm.alt_foconfig.num_ports", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2666 { &hf_selfm_alt_foconfig_num_brkr,
2667 { "Number of Breaker Bits per Port", "selfm.alt_foconfig.num_brkr", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2668 { &hf_selfm_alt_foconfig_num_rb,
2669 { "Number of Remote Bits per Port", "selfm.alt_foconfig.num_rb", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2670 { &hf_selfm_alt_foconfig_funccode,
2671 { "Supported Function Code", "selfm.alt_foconfig.funccode", FT_UINT8, BASE_HEX, VALS(selfm_foconfig_alt_funccode_vals), 0x0, NULL, HFILL }},
2672 /* "Fast Operate Command" specific fields */
2673 { &hf_selfm_fastop_len,
2674 { "Length", "selfm.fastop.len", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2675 { &hf_selfm_fastop_rb_code,
2676 { "Remote Bit Operate Code", "selfm.fastop.rb_code", FT_UINT8, BASE_HEX, VALS(selfm_fo_rb_vals), 0x0, NULL, HFILL }},
2677 { &hf_selfm_fastop_br_code,
2678 { "Breaker Bit Operate Code", "selfm.fastop.br_code", FT_UINT8, BASE_HEX, VALS(selfm_fo_br_vals), 0x0, NULL, HFILL }},
2679 { &hf_selfm_fastop_valid,
2680 { "Operate Code Validation", "selfm.fastop.valid", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},
2681 /* "Alternate Fast Operate Command" specific fields */
2682 { &hf_selfm_alt_fastop_len,
2683 { "Length", "selfm.alt_fastop.len", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2684 { &hf_selfm_alt_fastop_code,
2685 { "Operate Code", "selfm.alt_fastop.code", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
2686 { &hf_selfm_alt_fastop_valid,
2687 { "Operate Code Validation", "selfm.alt_fastop.valid", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
2688 /* "Fast SER Message" specific fields */
2689 { &hf_selfm_fastser_len,
2690 { "Length", "selfm.fastser.len", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2691 { &hf_selfm_fastser_routing_addr,
2692 { "Routing Address (future)", "selfm.fastser.routing_addr", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
2693 { &hf_selfm_fastser_status,
2694 { "Status Byte", "selfm.fastser.status", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2695 { &hf_selfm_fastser_funccode,
2696 { "Function Code", "selfm.fastser.funccode", FT_UINT8, BASE_HEX, VALS(selfm_fastser_func_code_vals), 0x0, NULL, HFILL }},
2697 { &hf_selfm_fastser_seq,
2698 { "Sequence Byte", "selfm.fastser.seq", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }},
2699 { &hf_selfm_fastser_seq_fir,
2700 { "FIR", "selfm.fastser.seq_fir", FT_BOOLEAN, 8, NULL, FAST_SER_SEQ_FIR, NULL, HFILL }},
2701 { &hf_selfm_fastser_seq_fin,
2702 { "FIN", "selfm.fastser.seq_fin", FT_BOOLEAN, 8, NULL, FAST_SER_SEQ_FIN, NULL, HFILL }},
2703 { &hf_selfm_fastser_seq_cnt,
2704 { "Count", "selfm.fastser.seq_cnt", FT_UINT8, BASE_DEC, NULL, FAST_SER_SEQ_CNT, "Frame Count Number", HFILL }},
2705 { &hf_selfm_fastser_resp_num,
2706 { "Response Number", "selfm.fastser.resp_num", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2707 { &hf_selfm_fastser_crc16,
2708 { "CRC-16", "selfm.fastser.crc16", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
2709 { &hf_selfm_fastser_def_route_sup,
2710 { "Routing Support", "selfm.fastser.def_route_sup", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2711 { &hf_selfm_fastser_def_rx_stat,
2712 { "Status RX", "selfm.fastser.def_rx_stat", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2713 { &hf_selfm_fastser_def_tx_stat,
2714 { "Status TX", "selfm.fastser.def_tx_stat", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2715 { &hf_selfm_fastser_def_rx_maxfr,
2716 { "Max Frames RX", "selfm.fastser.def_rx_maxfr", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2717 { &hf_selfm_fastser_def_tx_maxfr,
2718 { "Max Frames TX", "selfm.fastser.def_tx_maxfr", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2719 { &hf_selfm_fastser_def_rx_num_fc,
2720 { "Number of Supported RX Function Codes", "selfm.fastser.def_rx_num_fc", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2721 { &hf_selfm_fastser_def_rx_fc,
2722 { "Receive Function Code", "selfm.fastser.def_rx_fc", FT_UINT8, BASE_HEX, VALS(selfm_fastser_func_code_vals), 0x0, NULL, HFILL }},
2723 { &hf_selfm_fastser_def_tx_num_fc,
2724 { "Number of Supported TX Function Codes", "selfm.fastser.def_tx_num_fc", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2725 { &hf_selfm_fastser_def_tx_fc,
2726 { "Transmit Function Code", "selfm.fastser.def_tx_fc", FT_UINT8, BASE_HEX, VALS(selfm_fastser_func_code_vals), 0x0, NULL, HFILL }},
2727 { &hf_selfm_fastser_uns_en_fc,
2728 { "Function Code to Enable", "selfm.fastser.uns_en_fc", FT_UINT8, BASE_HEX, VALS(selfm_fastser_func_code_vals), 0x0, NULL, HFILL }},
2729 { &hf_selfm_fastser_uns_en_fc_data,
2730 { "Function Code Data", "selfm.fastser.uns_en_fc_data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
2731 { &hf_selfm_fastser_uns_dis_fc,
2732 { "Function Code to Disable", "selfm.fastser.uns_dis_fc", FT_UINT8, BASE_HEX, VALS(selfm_fastser_func_code_vals), 0x0, NULL, HFILL }},
2733 { &hf_selfm_fastser_uns_dis_fc_data,
2734 { "Function Code Data", "selfm.fastser.uns_dis_fc_data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
2735 { &hf_selfm_fastser_unsresp_orig,
2736 { "Origination path", "selfm.fastser.unsresp_orig", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
2737 { &hf_selfm_fastser_unsresp_doy,
2738 { "Day of Year", "selfm.fastser.unsresp_doy", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2739 { &hf_selfm_fastser_unsresp_year,
2740 { "Year", "selfm.fastser.unsresp_year", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2741 { &hf_selfm_fastser_unsresp_todms,
2742 { "Time of Day (in ms)", "selfm.fastser.unsresp_todms", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2743 { &hf_selfm_fastser_unsresp_num_elmt,
2744 { "Number of SER Elements", "selfm.fastser.unsresp_num_elmt", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2745 { &hf_selfm_fastser_unsresp_elmt_idx,
2746 { "SER Element Index", "selfm.fastser.unsresp_elmt_idx", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2747 { &hf_selfm_fastser_unsresp_elmt_ts_ofs,
2748 { "SER Element Timestamp Offset (us)", "selfm.fastser.unsresp_elmt_ts_ofs", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2749 { &hf_selfm_fastser_unsresp_elmt_status,
2750 { "SER Element Status", "selfm.fastser.unsresp_elmt_status", FT_UINT8, BASE_DEC, VALS(selfm_ser_status_vals), 0x0, NULL, HFILL }},
2751 { &hf_selfm_fastser_unsresp_eor,
2752 { "End of Record Indicator", "selfm.fastser.unsresp_eor", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
2753 { &hf_selfm_fastser_unsresp_elmt_statword,
2754 { "SER Element Status Word", "selfm.fastser.unsresp_elmt_statword", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }},
2755 { &hf_selfm_fastser_unswrite_addr1,
2756 { "Write Address Region #1", "selfm.fastser.unswrite_addr1", FT_UINT16, BASE_HEX, VALS(selfm_fastser_unswrite_com_vals), 0x0, NULL, HFILL }},
2757 { &hf_selfm_fastser_unswrite_addr2,
2758 { "Write Address Region #2", "selfm.fastser.unswrite_addr2", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
2759 { &hf_selfm_fastser_unswrite_num_reg,
2760 { "Number of Registers", "selfm.fastser.unswrite_num_reg", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2761 { &hf_selfm_fastser_unswrite_reg_val,
2762 { "Register Value", "selfm.fastser.unswrite_reg_val", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2763 { &hf_selfm_fastser_baseaddr,
2764 { "Base Address", "selfm.fastser.baseaddr", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }},
2765 { &hf_selfm_fastser_numwords,
2766 { "Number of 16-bit Words", "selfm.fastser.numwords", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2767 { &hf_selfm_fastser_flags,
2768 { "Flag Word", "selfm.fastser.flags", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
2769 { &hf_selfm_fastser_datafmt_resp_numitem,
2770 { "Number of Data Items Records", "selfm.fastser.datafmt_resp_numitem", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2771 { &hf_selfm_fastser_dataitem_qty,
2772 { "Data Item Quantity", "selfm.fastser.dataitem_qty", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2773 { &hf_selfm_fastser_dataitem_type,
2774 { "Data Item Type", "selfm.fastser.dataitem_type", FT_UINT16, BASE_HEX, VALS(selfm_fastser_tagtype_vals), 0x0, NULL, HFILL }},
2775 { &hf_selfm_fastser_dataitem_uint16,
2776 { "(uint16)", "selfm.fastser.dataitem_uint16", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2777 { &hf_selfm_fastser_dataitem_int16,
2778 { "(int16)", "selfm.fastser.dataitem_int16", FT_INT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2779 { &hf_selfm_fastser_dataitem_uint32,
2780 { "(uint32)", "selfm.fastser.dataitem_uint32", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2781 { &hf_selfm_fastser_dataitem_int32,
2782 { "(int32)", "selfm.fastser.dataitem_int32", FT_INT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2783 { &hf_selfm_fastser_dataitem_float,
2784 { "(float)", "selfm.fastser.dataitem_float", FT_FLOAT, BASE_NONE, NULL, 0x0, NULL, HFILL }},
2785 { &hf_selfm_fastser_devdesc_num_region,
2786 { "Number of Data Regions", "selfm.fastser.devdesc_num_region", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2787 { &hf_selfm_fastser_devdesc_num_ctrl,
2788 { "Number of Control Regions", "selfm.fastser.devdesc_num_ctrl", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2789 { &hf_selfm_fastser_soe_req_orig,
2790 { "Origination path", "selfm.fastser.soe_req_orig", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
2791 { &hf_selfm_fastser_soe_resp_numblks,
2792 { "Number of Blocks", "selfm.fastser.soe_resp_numblks", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2793 { &hf_selfm_fastser_soe_resp_orig,
2794 { "Origination path", "selfm.fastser.soe_resp_orig", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
2795 { &hf_selfm_fastser_soe_resp_numbits,
2796 { "Number of Bits", "selfm.fastser.soe_resp_numbits", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2797 { &hf_selfm_fastser_soe_resp_pad,
2798 { "Pad Byte", "selfm.fastser.soe_resp_pad", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2799 { &hf_selfm_fastser_soe_resp_doy,
2800 { "Day of Year", "selfm.fastser.soe_resp_doy", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2801 { &hf_selfm_fastser_soe_resp_year,
2802 { "Year", "selfm.fastser.soe_resp_year", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2803 { &hf_selfm_fastser_soe_resp_tod,
2804 { "Time of Day (ms)", "selfm.fastser.soe_resp_tod", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2805 /* { &hf_selfm_fastser_soe_resp_data,
2806 { "Packed Binary State Data", "selfm.fastser.soe_resp_data", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }}, */
2808 /* "Fast SER Message" Re-assembly header fields */
2809 { &hf_selfm_fragment,
2810 { "SEL Fast Msg Response Data Fragment", "selfm.respdata.fragment", FT_FRAMENUM, BASE_NONE, NULL, 0x0, "SEL Fast Message Response Data Fragment", HFILL }},
2811 { &hf_selfm_fragments,
2812 { "SEL Fast Msg Response Data Fragments", "selfm.respdata.fragments", FT_NONE, BASE_NONE, NULL, 0x0, "SEL Fast Message Response Data Fragments", HFILL }},
2813 { &hf_selfm_fragment_overlap,
2814 { "Fragment overlap", "selfm.respdata.fragment.overlap", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "Fragment overlaps with other fragments", HFILL }},
2815 { &hf_selfm_fragment_overlap_conflict,
2816 { "Conflicting data in fragment overlap", "selfm.respdata.fragment.overlap.conflict", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "Overlapping fragments contained conflicting data", HFILL }},
2817 { &hf_selfm_fragment_multiple_tails,
2818 { "Multiple tail fragments found", "selfm.respdata.fragment.multipletails", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "Several tails were found when defragmenting the packet", HFILL }},
2819 { &hf_selfm_fragment_too_long_fragment,
2820 { "Fragment too long", "selfm.respdata.fragment.toolongfragment", FT_BOOLEAN, BASE_NONE, NULL, 0x0, "Fragment contained data past end of packet", HFILL }},
2821 { &hf_selfm_fragment_error,
2822 { "Defragmentation error", "selfm.respdata.fragment.error", FT_FRAMENUM, BASE_NONE, NULL, 0x0, "Defragmentation error due to illegal fragments", HFILL }},
2823 { &hf_selfm_fragment_count,
2824 { "Fragment count", "selfm.respdata.fragment.count", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2825 { &hf_selfm_fragment_reassembled_in,
2826 { "Reassembled PDU In Frame", "selfm.respdata.fragment.reassembled_in", FT_FRAMENUM, BASE_NONE, NULL, 0x0, "This PDU is reassembled in this frame", HFILL }},
2827 { &hf_selfm_fragment_reassembled_length,
2828 { "Reassembled SEL Fast Msg length", "selfm.respdata.fragment.reassembled.length", FT_UINT32, BASE_DEC, NULL, 0x0, "The total length of the reassembled payload", HFILL }
2832 /* Setup protocol subtree array */
2833 static gint *ett[] = {
2834 &ett_selfm,
2835 &ett_selfm_relaydef,
2836 &ett_selfm_relaydef_fm,
2837 &ett_selfm_relaydef_proto,
2838 &ett_selfm_relaydef_flags,
2839 &ett_selfm_fmconfig,
2840 &ett_selfm_fmconfig_ai,
2841 &ett_selfm_fmconfig_calc,
2842 &ett_selfm_foconfig,
2843 &ett_selfm_foconfig_brkr,
2844 &ett_selfm_foconfig_rb,
2845 &ett_selfm_fastop,
2846 &ett_selfm_fmdata,
2847 &ett_selfm_fmdata_ai,
2848 &ett_selfm_fmdata_dig,
2849 &ett_selfm_fmdata_ai_ch,
2850 &ett_selfm_fmdata_dig_ch,
2851 &ett_selfm_fastser,
2852 &ett_selfm_fastser_seq,
2853 &ett_selfm_fastser_def_fc,
2854 &ett_selfm_fastser_tag,
2855 &ett_selfm_fastser_element_list,
2856 &ett_selfm_fastser_element,
2857 &ett_selfm_fastser_datareg,
2858 &ett_selfm_fragment,
2859 &ett_selfm_fragments
2863 module_t *selfm_module;
2865 /* Register protocol init routine */
2866 register_init_routine(&selfm_init);
2868 /* Register the protocol name and description */
2869 proto_selfm = proto_register_protocol("SEL Fast Message", "SEL Fast Message", "selfm");
2871 /* Registering protocol to be called by another dissector */
2872 new_register_dissector("selfm", dissect_selfm_simple, proto_selfm);
2874 /* Required function calls to register the header fields and subtrees used */
2875 proto_register_field_array(proto_selfm, selfm_hf, array_length(selfm_hf));
2876 proto_register_subtree_array(ett, array_length(ett));
2879 /* Register required preferences for SEL Protocol register decoding */
2880 selfm_module = prefs_register_protocol(proto_selfm, proto_reg_handoff_selfm);
2882 /* SEL Protocol - Desegmentmentation; defaults to TRUE for TCP desegmentation*/
2883 prefs_register_bool_preference(selfm_module, "desegment",
2884 "Desegment all SEL Fast Message Protocol packets spanning multiple TCP segments",
2885 "Whether the SEL Protocol dissector should desegment all messages spanning multiple TCP segments",
2886 &selfm_desegment);
2888 /* SEL Protocol - Telnet protocol IAC (0xFF) processing; defaults to TRUE to allow Telnet Encapsulated Data */
2889 prefs_register_bool_preference(selfm_module, "telnetclean",
2890 "Enable Automatic pre-processing of Telnet-encapsulated data to remove extra 0xFF (IAC) bytes",
2891 "Whether the SEL Protocol dissector should automatically pre-process Telnet data to remove IAC bytes",
2892 &selfm_telnet_clean);
2894 /* SEL Protocol Preference - Default TCP Port, allows for "user" port either than 0. */
2895 prefs_register_uint_preference(selfm_module, "tcp.port", "SEL Protocol Port",
2896 "Set the TCP port for SEL FM Protocol packets (if other"
2897 " than the default of 0)",
2898 10, &global_selfm_tcp_port);
2902 /******************************************************************************************************/
2903 /* If this dissector uses sub-dissector registration add a registration routine.
2904 This format is required because a script is used to find these routines and
2905 create the code that calls these routines.
2907 /******************************************************************************************************/
2908 void
2909 proto_reg_handoff_selfm(void)
2911 static int selfm_prefs_initialized = FALSE;
2912 static dissector_handle_t selfm_handle;
2913 static unsigned int selfm_port;
2915 /* Make sure to use SEL FM Protocol Preferences field to determine default TCP port */
2916 if (! selfm_prefs_initialized) {
2917 selfm_handle = new_create_dissector_handle(dissect_selfm_tcp, proto_selfm);
2918 selfm_prefs_initialized = TRUE;
2920 else {
2921 dissector_delete_uint("tcp.port", selfm_port, selfm_handle);
2924 selfm_port = global_selfm_tcp_port;
2926 dissector_add_uint("tcp.port", selfm_port, selfm_handle);
2930 * Editor modelines - http://www.wireshark.org/tools/modelines.html
2932 * Local variables:
2933 * c-basic-offset: 4
2934 * tab-width: 8
2935 * indent-tabs-mode: nil
2936 * End:
2938 * vi: set shiftwidth=4 tabstop=8 expandtab:
2939 * :indentSize=4:tabSize=8:noTabs=true: