2 * Dissector for IEEE C37.118 synchrophasor frames.
4 * Copyright 2008, Jens Steinhauser <jens.steinhauser@omicron.at>
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include <epan/conversation.h>
29 #include <epan/crc16-tvb.h>
30 #include <epan/dissectors/packet-tcp.h>
31 #include <epan/packet.h>
32 #include <epan/prefs.h>
33 #include <epan/wmem/wmem.h>
37 #define PROTOCOL_NAME "IEEE C37.118 Synchrophasor Protocol"
38 #define PROTOCOL_SHORT_NAME "SYNCHROPHASOR"
39 #define PROTOCOL_ABBREV "synphasor"
41 /* forward references */
42 void proto_register_synphasor(void);
43 void proto_reg_handoff_synphasor(void);
45 /* global variables */
47 static int proto_synphasor = -1;
49 /* user preferences */
50 static guint global_pref_tcp_port = 4712;
51 static guint global_pref_udp_port = 4713;
53 /* the ett... variables hold the state (open/close) of the treeview in the GUI */
54 static gint ett_synphasor = -1; /* root element for this protocol */
55 /* used in the common header */
56 static gint ett_frtype = -1;
57 static gint ett_timequal = -1;
58 /* used for config frames */
59 static gint ett_conf = -1;
60 static gint ett_conf_station = -1;
61 static gint ett_conf_format = -1;
62 static gint ett_conf_phnam = -1;
63 static gint ett_conf_annam = -1;
64 static gint ett_conf_dgnam = -1;
65 static gint ett_conf_phconv = -1;
66 static gint ett_conf_anconv = -1;
67 static gint ett_conf_dgmask = -1;
68 /* used for data frames */
69 static gint ett_data = -1;
70 static gint ett_data_block = -1;
71 static gint ett_data_stat = -1;
72 static gint ett_data_phasors = -1;
73 static gint ett_data_analog = -1;
74 static gint ett_data_digital = -1;
75 /* used for command frames */
76 static gint ett_command = -1;
78 /* handles to the header fields hf[] in proto_register_synphasor() */
79 static int hf_sync = -1;
80 static int hf_sync_frtype = -1;
81 static int hf_sync_version = -1;
82 static int hf_idcode = -1;
83 static int hf_frsize = -1;
84 static int hf_soc = -1;
85 static int hf_timeqal_lsdir = -1;
86 static int hf_timeqal_lsocc = -1;
87 static int hf_timeqal_lspend = -1;
88 static int hf_timeqal_timequalindic = -1;
89 static int hf_fracsec = -1;
90 static int hf_conf_timebase = -1;
91 static int hf_conf_numpmu = -1;
92 static int hf_conf_formatb3 = -1;
93 static int hf_conf_formatb2 = -1;
94 static int hf_conf_formatb1 = -1;
95 static int hf_conf_formatb0 = -1;
96 static int hf_conf_fnom = -1;
97 static int hf_conf_cfgcnt = -1;
98 static int hf_data_statb15 = -1;
99 static int hf_data_statb14 = -1;
100 static int hf_data_statb13 = -1;
101 static int hf_data_statb12 = -1;
102 static int hf_data_statb11 = -1;
103 static int hf_data_statb10 = -1;
104 static int hf_data_statb05to04 = -1;
105 static int hf_data_statb03to00 = -1;
106 static int hf_command = -1;
108 static dissector_handle_t synphasor_udp_handle;
110 /* the five different frame types for this protocol */
119 /* the channel names in the protocol are all 16 bytes
120 * long (and don't have to be NULL terminated) */
123 /* Structures to save CFG frame content. */
125 /* type to indicate the format for (D)FREQ/PHASORS/ANALOG in data frame */
126 typedef enum { integer, /* 16 bit signed integer */
127 floating_point /* single precision floating point */
130 typedef enum { rect, polar } phasor_notation_e;
132 typedef enum { V, A } unit_e;
134 /* holds the information required to dissect a single phasor */
136 char name[CHNAM_LEN + 1];
138 guint32 conv; /* conversation factor in 10^-5 scale */
141 /* holds the information for an analog value */
143 char name[CHNAM_LEN + 1];
144 guint32 conv; /* conversation factor, user defined scaling (so it's pretty useless) */
147 /* holds information required to dissect a single PMU block in a data frame */
149 guint16 id; /* identifies source of block */
150 char name[CHNAM_LEN + 1]; /* holds STN */
151 data_format format_fr; /* data format of FREQ and DFREQ */
152 data_format format_ph; /* data format of PHASORS */
153 data_format format_an; /* data format of ANALOG */
154 phasor_notation_e phasor_notation; /* format of the phasors */
155 guint fnom; /* nominal line frequency */
156 guint num_dg; /* number of digital status words */
157 wmem_array_t *phasors; /* array of phasor_infos */
158 wmem_array_t *analogs; /* array of analog_infos */
161 /* holds the id the configuration comes from an and
162 * an array of config_block members */
164 guint32 fnum; /* frame number */
167 wmem_array_t *config_blocks; /* Contains a config_block struct for
168 * every PMU included in the config frame */
171 /* strings for type bits in SYNC */
172 static const value_string typenames[] = {
174 { 1, "Header Frame" },
175 { 2, "Configuration Frame 1" },
176 { 3, "Configuration Frame 2" },
177 { 4, "Command Frame" },
181 /* strings for version bits in SYNC */
182 static const value_string versionnames[] = {
183 { 1, "IEEE C37.118-2005 initial publication" },
187 /* strings for the time quality flags in FRACSEC */
188 static const value_string timequalcodes[] = {
189 { 0xF, "Clock failure, time not reliable" },
190 { 0xB, "Clock unlocked, time within 10 s" },
191 { 0xA, "Clock unlocked, time within 1 s" },
192 { 0x9, "Clock unlocked, time within 10^-1 s" },
193 { 0x8, "Clock unlocked, time within 10^-2 s" },
194 { 0x7, "Clock unlocked, time within 10^-3 s" },
195 { 0x6, "Clock unlocked, time within 10^-4 s" },
196 { 0x5, "Clock unlocked, time within 10^-5 s" },
197 { 0x4, "Clock unlocked, time within 10^-6 s" },
198 { 0x3, "Clock unlocked, time within 10^-7 s" },
199 { 0x2, "Clock unlocked, time within 10^-8 s" },
200 { 0x1, "Clock unlocked, time within 10^-9 s" },
201 { 0x0, "Normal operation, clock locked" },
205 /* strings for flags in the FORMAT word of a configuration frame */
206 static const true_false_string conf_formatb123names = {
210 static const true_false_string conf_formatb0names = {
215 /* strings to decode ANUNIT in configuration frame */
216 static const range_string conf_anconvnames[] = {
217 { 0, 0, "single point-on-wave" },
218 { 1, 1, "rms of analog input" },
219 { 2, 2, "peak of input" },
220 { 3, 4, "undefined" },
221 { 5, 64, "reserved" },
222 { 65, 255, "user defined" },
226 /* strings for the FNOM field */
227 static const true_false_string conf_fnomnames = {
232 /* strings for flags in the STAT word of a data frame */
233 static const true_false_string data_statb15names = {
237 static const true_false_string data_statb14names = {
241 static const true_false_string data_statb13names = {
242 "Synchronization lost",
243 "Clock is synchronized"
245 static const true_false_string data_statb12names = {
249 static const true_false_string data_statb11names = {
253 static const true_false_string data_statb10names = {
257 static const value_string data_statb05to04names[] = {
258 { 0, "Time locked, best quality" },
259 { 1, "Unlocked for 10s" },
260 { 2, "Unlocked for 100s" },
261 { 3, "Unlocked for over 1000s" },
264 static const value_string data_statb03to00names[] = {
266 { 0x1, "Magnitude low" },
267 { 0x2, "Magnitude high" },
268 { 0x3, "Phase-angel diff" },
269 { 0x4, "Frequency high/low" },
270 { 0x5, "df/dt high" },
273 { 0x8, "User defined" },
274 { 0x9, "User defined" },
275 { 0xA, "User defined" },
276 { 0xB, "User defined" },
277 { 0xC, "User defined" },
278 { 0xD, "User defined" },
279 { 0xE, "User defined" },
280 { 0xF, "User defined" },
284 /* strings to decode the commands */
285 static const value_string command_names[] = {
286 { 0, "unknown command" },
287 { 1, "data transmission off" },
288 { 2, "data transmission on" },
289 { 3, "send HDR frame" },
290 { 4, "send CFG-1 frame" },
291 { 5, "send CFG-2 frame" },
292 { 6, "unknown command" },
293 { 7, "unknown command" },
294 { 8, "extended frame" },
295 { 9, "unknown command" },
296 { 10, "unknown command" },
297 { 11, "unknown command" },
298 { 12, "unknown command" },
299 { 13, "unknown command" },
300 { 14, "unknown command" },
301 { 15, "unknown command" },
305 /* Dissects a configuration frame (only the most important stuff, tries
306 * to be fast, does no GUI stuff) and returns a pointer to a config_frame
307 * struct that contains all the information from the frame needed to
308 * dissect a DATA frame.
310 * use 'config_frame_free()' to free the config_frame again
312 static config_frame* config_frame_fast(tvbuff_t *tvb)
314 guint16 idcode, num_pmu;
318 /* get a new frame and initialize it */
319 frame = wmem_new(wmem_file_scope(), config_frame);
321 frame->config_blocks = wmem_array_new(wmem_file_scope(), sizeof(config_block));
323 idcode = tvb_get_ntohs(tvb, 4);
326 num_pmu = tvb_get_ntohs(tvb, 18);
327 offset = 20; /* start of repeating blocks */
330 guint16 format_flags;
340 /* initialize the block */
341 block.phasors = wmem_array_new(wmem_file_scope(), sizeof(phasor_info));
342 block.analogs = wmem_array_new(wmem_file_scope(), sizeof(analog_info));
343 /* copy the station name from the tvb to block, and add NULL byte */
344 tvb_memcpy(tvb, block.name, offset, CHNAM_LEN); offset += CHNAM_LEN;
345 block.name[CHNAM_LEN] = '\0';
347 block.id = tvb_get_ntohs(tvb, offset); offset += 2;
349 format_flags = tvb_get_ntohs(tvb, offset); offset += 2;
350 block.format_fr = (format_flags & 0x0008) ? floating_point : integer;
351 block.format_an = (format_flags & 0x0004) ? floating_point : integer;
352 block.format_ph = (format_flags & 0x0002) ? floating_point : integer;
353 block.phasor_notation = (format_flags & 0x0001) ? polar : rect;
355 num_ph = tvb_get_ntohs(tvb, offset); offset += 2;
356 num_an = tvb_get_ntohs(tvb, offset); offset += 2;
357 num_dg = tvb_get_ntohs(tvb, offset); offset += 2;
358 block.num_dg = num_dg;
360 /* the offset of the PHUNIT, ANUNIT, and FNOM blocks */
361 phunit = offset + (num_ph + num_an + num_dg * CHNAM_LEN) * CHNAM_LEN;
362 anunit = phunit + num_ph * 4;
363 fnom = anunit + num_an * 4 + num_dg * 4;
365 /* read num_ph phasor names and conversation factors */
366 for (i = 0; i != num_ph; i++) {
370 /* copy the phasor name from the tvb, and add NULL byte */
371 tvb_memcpy(tvb, pi.name, offset, CHNAM_LEN); offset += CHNAM_LEN;
372 pi.name[CHNAM_LEN] = '\0';
374 conv = tvb_get_ntohl(tvb, phunit + 4 * i);
375 pi.unit = conv & 0xFF000000 ? A : V;
376 pi.conv = conv & 0x00FFFFFF;
378 wmem_array_append_one(block.phasors, pi);
381 /* read num_an analog value names and conversation factors */
382 for (i = 0; i != num_an; i++) {
386 /* copy the phasor name from the tvb, and add NULL byte */
387 tvb_memcpy(tvb, ai.name, offset, CHNAM_LEN); offset += CHNAM_LEN;
388 ai.name[CHNAM_LEN] = '\0';
390 conv = tvb_get_ntohl(tvb, anunit + 4 * i);
393 wmem_array_append_one(block.analogs, ai);
396 /* the names for the bits in the digital status words aren't saved,
397 there is no space to display them in the GUI anyway */
400 block.fnom = tvb_get_ntohs(tvb, fnom) & 0x0001 ? 50 : 60;
406 wmem_array_append_one(frame->config_blocks, block);
413 /* Checks the CRC of a synchrophasor frame, 'tvb' has to include the whole
414 * frame, including CRC, the calculated CRC is returned in '*computedcrc'.
416 static gboolean check_crc(tvbuff_t *tvb, guint16 *computedcrc)
419 guint len = tvb_get_ntohs(tvb, 2);
421 crc = tvb_get_ntohs(tvb, len - 2);
422 *computedcrc = crc16_x25_ccitt_tvb(tvb, len - 2);
424 if (crc == *computedcrc)
430 /* forward declarations of the subdissectors for the data
431 * in the frame that is not common to all types of frames
433 static int dissect_config_frame (tvbuff_t *, proto_item *);
434 static int dissect_data_frame (tvbuff_t *, proto_item *, packet_info *);
435 static int dissect_command_frame(tvbuff_t *, proto_item *, packet_info *);
436 /* to keep 'dissect_common()' shorter */
437 static gint dissect_header(tvbuff_t *, proto_tree *);
439 /* Dissects the header (common to all types of frames) and then calls
440 * one of the subdissectors (declared above) for the rest of the frame.
442 static int dissect_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
446 guint tvbsize = tvb_length(tvb);
448 /* some heuristics */
449 if (tvbsize < 17 /* 17 bytes = header frame with only a
450 NULL character, useless but valid */
451 || tvb_get_guint8(tvb, 0) != 0xAA) /* every synchrophasor frame starts with 0xAA */
454 /* write the protocol name to the info column */
455 col_set_str(pinfo->cinfo, COL_PROTOCOL, PROTOCOL_SHORT_NAME);
457 frame_type = tvb_get_guint8(tvb, 1) >> 4;
459 col_add_fstr(pinfo->cinfo, COL_INFO, "%s", val_to_str_const(frame_type, typenames, "invalid packet type"));
461 /* CFG-2 and DATA frames need special treatment during the first run:
462 * For CFG-2 frames, a 'config_frame' struct is created to hold the
463 * information necessary to decode DATA frames. A pointer to this
464 * struct is saved in the conversation and is copied to the
465 * per-packet information if a DATA frame is dissected.
467 if (!pinfo->fd->flags.visited) {
468 if (CFG2 == frame_type &&
469 check_crc(tvb, &crc)) {
470 conversation_t *conversation;
472 /* fill the config_frame */
473 config_frame *frame = config_frame_fast(tvb);
474 frame->fnum = pinfo->fd->num;
476 /* find a conversation, create a new if no one exists */
477 conversation = find_or_create_conversation(pinfo);
479 /* remove data from a previous CFG-2 frame, only
480 * the most recent configuration frame is relevant */
481 if (conversation_get_proto_data(conversation, proto_synphasor))
482 conversation_delete_proto_data(conversation, proto_synphasor);
484 conversation_add_proto_data(conversation, proto_synphasor, frame);
486 else if (DATA == frame_type) {
487 conversation_t *conversation = find_conversation(pinfo->fd->num,
488 &pinfo->src, &pinfo->dst,
490 pinfo->srcport, pinfo->destport,
494 config_frame *conf = (config_frame *)conversation_get_proto_data(conversation, proto_synphasor);
495 /* no problem if 'conf' is NULL, the DATA frame dissector checks this again */
496 p_add_proto_data(wmem_file_scope(), pinfo, proto_synphasor, 0, conf);
499 } /* if (!visited) */
501 if (tree) { /* we are being asked for details */
502 proto_tree *synphasor_tree = NULL;
503 proto_item *temp_item = NULL;
504 proto_item *sub_item = NULL;
510 temp_item = proto_tree_add_item(tree, proto_synphasor, tvb, 0, -1, ENC_NA);
511 proto_item_append_text(temp_item, ", %s", val_to_str_const(frame_type, typenames,
512 ", invalid packet type"));
514 /* synphasor_tree is where from now on all new elements for this protocol get added */
515 synphasor_tree = proto_item_add_subtree(temp_item, ett_synphasor);
517 framesize = dissect_header(tvb, synphasor_tree);
518 offset = 14; /* header is 14 bytes long */
520 /* check CRC, call appropriate subdissector for the rest of the frame if CRC is correct*/
521 sub_item = proto_tree_add_text(synphasor_tree, tvb, offset , tvbsize - 16, "Data" );
522 temp_item = proto_tree_add_text(synphasor_tree, tvb, tvbsize - 2, 2 , "Checksum:");
523 if (!check_crc(tvb, &crc)) {
524 proto_item_append_text(sub_item, ", not dissected because of wrong checksum");
525 proto_item_append_text(temp_item, " 0x%04x [incorrect]", crc);
528 /* create a new tvb to pass to the subdissector
529 '-16': length of header + 2 CRC bytes */
530 sub_tvb = tvb_new_subset(tvb, offset, tvbsize - 16, framesize - 16);
532 /* call subdissector */
533 switch (frame_type) {
535 dissect_data_frame(sub_tvb, sub_item, pinfo);
537 case HEADER: /* no further dissection is done/needed */
538 proto_item_append_text(sub_item, "Header Frame");
542 dissect_config_frame(sub_tvb, sub_item);
545 dissect_command_frame(sub_tvb, sub_item, pinfo);
549 proto_item_append_text(sub_item, " of unknown type");
551 proto_item_append_text(temp_item, " 0x%04x [correct]", crc);
554 /*offset += 2;*/ /* CRC */
557 return tvb_length(tvb);
558 } /* dissect_synphasor() */
560 /* called for synchrophasors over UDP */
561 static int dissect_udp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
563 return dissect_common(tvb, pinfo, tree, data);
566 /* callback for 'tcp_dissect_pdus()' to give it the length of the frame */
567 static guint get_pdu_length(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
569 return tvb_get_ntohs(tvb, offset + 2);
572 static int dissect_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
574 tcp_dissect_pdus(tvb, pinfo, tree, TRUE, 4, get_pdu_length, dissect_common, data);
576 return tvb_length(tvb);
580 /* Dissects the common header of frames.
582 * Returns the framesize, in contrast to most
583 * other helper functions that return the offset.
585 static gint dissect_header(tvbuff_t *tvb, proto_tree *tree)
587 proto_tree *temp_tree;
588 proto_item *temp_item;
594 temp_item = proto_tree_add_item(tree, hf_sync, tvb, offset, 2, ENC_BIG_ENDIAN);
595 temp_tree = proto_item_add_subtree(temp_item, ett_frtype);
596 proto_tree_add_item(temp_tree, hf_sync_frtype, tvb, offset, 2, ENC_BIG_ENDIAN);
597 proto_tree_add_item(temp_tree, hf_sync_version, tvb, offset, 2, ENC_BIG_ENDIAN);
601 proto_tree_add_item(tree, hf_frsize, tvb, offset, 2, ENC_BIG_ENDIAN);
602 framesize = tvb_get_ntohs(tvb, offset); offset += 2;
605 proto_tree_add_item(tree, hf_idcode, tvb, offset, 2, ENC_BIG_ENDIAN);
610 /* can't use 'proto_tree_add_time()' because we need UTC */
613 time_t soc = tvb_get_ntohl(tvb, offset);
615 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", t);
616 proto_tree_add_string(tree, hf_soc, tvb, offset, 4, buf);
621 /* time quality flags */
622 temp_item = proto_tree_add_text(tree, tvb, offset, 1, "Time quality flags");
623 temp_tree = proto_item_add_subtree(temp_item, ett_timequal);
624 proto_tree_add_item(temp_tree, hf_timeqal_lsdir, tvb, offset, 1, ENC_BIG_ENDIAN);
625 proto_tree_add_item(temp_tree, hf_timeqal_lsocc, tvb, offset, 1, ENC_BIG_ENDIAN);
626 proto_tree_add_item(temp_tree, hf_timeqal_lspend, tvb, offset, 1, ENC_BIG_ENDIAN);
627 proto_tree_add_item(temp_tree, hf_timeqal_timequalindic, tvb, offset, 1, ENC_BIG_ENDIAN);
630 proto_tree_add_item(tree, hf_fracsec, tvb, offset, 3, ENC_BIG_ENDIAN);
636 /* forward declarations of helper functions for 'dissect_config_frame()' */
637 static gint dissect_CHNAM (tvbuff_t *tvb, proto_tree *tree, gint offset, gint cnt, const char *prefix);
638 static gint dissect_PHUNIT (tvbuff_t *tvb, proto_tree *tree, gint offset, gint cnt);
639 static gint dissect_ANUNIT (tvbuff_t *tvb, proto_tree *tree, gint offset, gint cnt);
640 static gint dissect_DIGUNIT(tvbuff_t *tvb, proto_tree *tree, gint offset, gint cnt);
642 /* dissects a configuration frame (type 1 and 2) and adds fields to 'config_item' */
643 static int dissect_config_frame(tvbuff_t *tvb, proto_item *config_item)
645 proto_tree *config_tree = NULL;
646 proto_item *temp_item = NULL;
647 proto_tree *temp_tree = NULL;
651 proto_item_set_text (config_item, "Configuration data");
652 config_tree = proto_item_add_subtree(config_item, ett_conf);
654 /* TIME_BASE and NUM_PMU */
655 offset += 1; /* skip the reserved byte */
656 proto_tree_add_item(config_tree, hf_conf_timebase, tvb, offset, 3, ENC_BIG_ENDIAN); offset += 3;
657 proto_tree_add_item(config_tree, hf_conf_numpmu, tvb, offset, 2, ENC_BIG_ENDIAN);
658 /* add number of included PMUs to the text in the list view */
659 num_pmu = tvb_get_ntohs(tvb, offset); offset += 2;
660 proto_item_append_text(config_item, ", %"G_GUINT16_FORMAT" PMU(s) included", num_pmu);
662 /* dissect the repeating PMU blocks */
663 for (j = 0; j < num_pmu; j++) {
664 guint16 num_ph, num_an, num_dg;
665 proto_item *station_item = NULL;
666 proto_tree *station_tree = NULL;
669 gint oldoffset = offset; /* to calculate the length of the whole PMU block later */
671 /* STN with new tree to add the rest of the PMU block */
672 str = tvb_get_string(wmem_packet_scope(), tvb, offset, CHNAM_LEN);
673 station_item = proto_tree_add_text(config_tree, tvb, offset, CHNAM_LEN, "Station #%i: \"%s\"", j + 1, str);
674 station_tree = proto_item_add_subtree(station_item, ett_conf_station);
678 proto_tree_add_item(station_tree, hf_idcode, tvb, offset, 2, ENC_BIG_ENDIAN); offset += 2;
681 temp_item = proto_tree_add_text(station_tree, tvb, offset, 2, "Data format in data frame");
682 temp_tree = proto_item_add_subtree(temp_item, ett_conf_format);
683 proto_tree_add_item(temp_tree, hf_conf_formatb3, tvb, offset, 2, ENC_BIG_ENDIAN);
684 proto_tree_add_item(temp_tree, hf_conf_formatb2, tvb, offset, 2, ENC_BIG_ENDIAN);
685 proto_tree_add_item(temp_tree, hf_conf_formatb1, tvb, offset, 2, ENC_BIG_ENDIAN);
686 proto_tree_add_item(temp_tree, hf_conf_formatb0, tvb, offset, 2, ENC_BIG_ENDIAN);
689 /* PHNMR, ANNMR, DGNMR */
690 num_ph = tvb_get_ntohs(tvb, offset );
691 num_an = tvb_get_ntohs(tvb, offset + 2);
692 num_dg = tvb_get_ntohs(tvb, offset + 4);
693 proto_tree_add_text(station_tree, tvb, offset , 2, "Number of phasors: %u", num_ph);
694 proto_tree_add_text(station_tree, tvb, offset + 2, 2, "Number of analog values: %u", num_an);
695 proto_tree_add_text(station_tree, tvb, offset + 4, 2, "Number of digital status words: %u", num_dg);
698 /* CHNAM, the channel names */
699 offset = dissect_CHNAM(tvb, station_tree, offset, num_ph , "Phasor name" );
700 offset = dissect_CHNAM(tvb, station_tree, offset, num_an , "Analog value" );
701 offset = dissect_CHNAM(tvb, station_tree, offset, num_dg * 16, "Digital status label");
703 /* PHUNIT, ANUINT and DIGUNIT */
704 offset = dissect_PHUNIT (tvb, station_tree, offset, num_ph);
705 offset = dissect_ANUNIT (tvb, station_tree, offset, num_an);
706 offset = dissect_DIGUNIT(tvb, station_tree, offset, num_dg);
708 /* FNOM and CFGCNT */
709 proto_tree_add_item(station_tree, hf_conf_fnom, tvb, offset, 2, ENC_BIG_ENDIAN); offset += 2;
710 proto_tree_add_item(station_tree, hf_conf_cfgcnt, tvb, offset, 2, ENC_BIG_ENDIAN); offset += 2;
712 /* set the correct length for the "Station :" item */
713 proto_item_set_len(station_item, offset - oldoffset);
714 } /* for() PMU blocks */
718 gint16 tmp = tvb_get_ntohs(tvb, offset);
719 temp_item = proto_tree_add_text(config_tree, tvb, offset, 2, "Rate of transmission: "); offset += 2;
721 proto_item_append_text(temp_item, "%"G_GINT16_FORMAT" frame(s) per second", tmp);
723 proto_item_append_text(temp_item, "1 frame per %"G_GINT16_FORMAT" second(s)", (gint16)-tmp);
727 } /* dissect_config_frame() */
729 /* forward declarations of helper functions for 'dissect_data_frame()' */
730 static gint dissect_PHASORS(tvbuff_t *tvb, proto_tree *tree, config_block *block, gint offset);
731 static gint dissect_DFREQ (tvbuff_t *tvb, proto_tree *tree, config_block *block, gint offset);
732 static gint dissect_ANALOG (tvbuff_t *tvb, proto_tree *tree, config_block *block, gint offset);
733 static gint dissect_DIGITAL(tvbuff_t *tvb, proto_tree *tree, config_block *block, gint offset);
734 /* calculates the size (in bytes) of a data frame that the config_block describes */
735 #define BLOCKSIZE(x) (2 /* STAT */ \
736 + wmem_array_get_count((x).phasors) * (integer == (x).format_ph ? 4 : 8) /* PHASORS */ \
737 + (integer == (x).format_fr ? 4 : 8) /* (D)FREQ */ \
738 + wmem_array_get_count((x).analogs) * (integer == (x).format_an ? 2 : 4) /* ANALOG */ \
739 + (x).num_dg * 2) /* DIGITAL */
741 /* Dissects a data frame */
742 static int dissect_data_frame(tvbuff_t *tvb,
743 proto_item *data_item, /* all items are placed beneath this item */
744 packet_info *pinfo) /* used to find the data from a CFG-2 frame */
746 proto_tree *data_tree = NULL;
751 proto_item_set_text(data_item, "Measurement data");
752 data_tree = proto_item_add_subtree(data_item, ett_data);
754 /* search for configuration information to dissect the frame */
756 gboolean config_found = FALSE;
757 conf = (config_frame *)p_get_proto_data(wmem_file_scope(), pinfo, proto_synphasor, 0);
760 /* check if the size of the current frame is the
761 size of the frame the config_frame describes */
762 size_t reported_size = 0;
763 for (i = 0; i < wmem_array_get_count(conf->config_blocks); i++) {
764 config_block *block = (config_block*)wmem_array_index(conf->config_blocks, i);
765 reported_size += BLOCKSIZE(*block);
768 if (tvb_length(tvb) == reported_size) {
769 proto_item_append_text(data_item, ", using frame number %"G_GUINT32_FORMAT" as configuration frame",
776 proto_item_append_text(data_item, ", no configuration frame found");
781 /* dissect a PMU block for every config_block in the frame */
782 for (i = 0; i < wmem_array_get_count(conf->config_blocks); i++) {
783 config_block *block = (config_block*)wmem_array_index(conf->config_blocks, i);
785 proto_item *block_item = proto_tree_add_text(data_tree, tvb, offset, BLOCKSIZE(*block),
786 "Station: \"%s\"", block->name);
787 proto_tree *block_tree = proto_item_add_subtree(block_item, ett_data_block);
790 proto_item *temp_item = proto_tree_add_text(block_tree, tvb, offset, 2, "Flags");
791 proto_tree *temp_tree = proto_item_add_subtree(temp_item, ett_data_stat);
792 proto_tree_add_item(temp_tree, hf_data_statb15, tvb, offset, 2, ENC_BIG_ENDIAN);
793 proto_tree_add_item(temp_tree, hf_data_statb14, tvb, offset, 2, ENC_BIG_ENDIAN);
794 proto_tree_add_item(temp_tree, hf_data_statb13, tvb, offset, 2, ENC_BIG_ENDIAN);
795 proto_tree_add_item(temp_tree, hf_data_statb12, tvb, offset, 2, ENC_BIG_ENDIAN);
796 proto_tree_add_item(temp_tree, hf_data_statb11, tvb, offset, 2, ENC_BIG_ENDIAN);
797 proto_tree_add_item(temp_tree, hf_data_statb10, tvb, offset, 2, ENC_BIG_ENDIAN);
798 proto_tree_add_item(temp_tree, hf_data_statb05to04, tvb, offset, 2, ENC_BIG_ENDIAN);
799 proto_tree_add_item(temp_tree, hf_data_statb03to00, tvb, offset, 2, ENC_BIG_ENDIAN);
802 /* PHASORS, (D)FREQ, ANALOG, and DIGITAL */
803 offset = dissect_PHASORS(tvb, block_item, block, offset);
804 offset = dissect_DFREQ (tvb, block_item, block, offset);
805 offset = dissect_ANALOG (tvb, block_item, block, offset);
806 offset = dissect_DIGITAL(tvb, block_item, block, offset);
809 } /* dissect_data_frame() */
811 /* Dissects a command frame and adds fields to config_item.
813 * 'pinfo' is used to add the type of command
814 * to the INFO column in the packet list.
816 static int dissect_command_frame(tvbuff_t *tvb,
817 proto_item *command_item,
820 proto_tree *command_tree = NULL;
821 guint tvbsize = tvb_length(tvb);
824 proto_item_set_text(command_item, "Command data");
825 command_tree = proto_item_add_subtree(command_item, ett_command);
828 proto_tree_add_item(command_tree, hf_command, tvb, 0, 2, ENC_BIG_ENDIAN);
830 s = val_to_str_const(tvb_get_ntohs(tvb, 0), command_names, "invalid command");
831 col_append_str(pinfo->cinfo, COL_INFO, ", ");
832 col_append_str(pinfo->cinfo, COL_INFO, s);
835 if (tvb_get_ntohs(tvb, 0) == 0x0008) {
836 /* Command: Extended Frame, the extra data is ok */
837 proto_item* i = proto_tree_add_text(command_tree, tvb, 2, tvbsize - 2, "Extended frame data");
839 proto_item_append_text(i, ", but size not multiple of 16-bit word");
842 proto_tree_add_text(command_tree, tvb, 2, tvbsize - 2, "Unknown data");
846 } /* dissect_command_frame() */
848 /****************************************************************/
849 /* after this line: helper functions for 'dissect_data_frame()' */
850 /****************************************************************/
852 /* Dissects a single phasor for 'dissect_PHASORS()' */
853 static int dissect_single_phasor(tvbuff_t *tvb, int offset,
854 double* mag, double* phase, /* returns the resulting values here */
855 data_format format, /* information needed to... */
856 phasor_notation_e notation) /* ...dissect the phasor */
858 if (floating_point == format) {
859 if (polar == notation) {
861 *mag = tvb_get_ntohieee_float(tvb, offset );
862 *phase = tvb_get_ntohieee_float(tvb, offset + 4);
867 real = tvb_get_ntohieee_float(tvb, offset );
868 imag = tvb_get_ntohieee_float(tvb, offset + 4);
870 *mag = sqrt(pow(real, 2) + pow(imag, 2));
871 *phase = atan2(imag, real);
875 if (polar == notation) {
877 *mag = (guint16)tvb_get_ntohs(tvb, offset );
878 *phase = (gint16) tvb_get_ntohs(tvb, offset + 2);
879 *phase /= 10000.0; /* angle is in radians*10^4 */
884 real = tvb_get_ntohs(tvb, offset );
885 imag = tvb_get_ntohs(tvb, offset + 2);
887 *mag = sqrt(pow(real, 2) + pow(imag, 2));
888 *phase = atan2(imag, real);
892 return floating_point == format ? 8 : 4;
895 /* used by 'dissect_data_frame()' to dissect the PHASORS field */
896 static gint dissect_PHASORS(tvbuff_t *tvb, proto_tree *tree, config_block *block, gint offset)
898 proto_item *temp_item = NULL;
899 proto_tree *phasor_tree = NULL;
902 cnt = wmem_array_get_count(block->phasors); /* number of phasors to dissect */
907 length = wmem_array_get_count(block->phasors) * (floating_point == block->format_ph ? 8 : 4);
908 temp_item = proto_tree_add_text(tree, tvb, offset, length, "Phasors (%u)", cnt);
909 phasor_tree = proto_item_add_subtree(temp_item, ett_data_phasors);
911 /* dissect a phasor for every phasor_info saved in the config_block */
912 for (j = 0; j < cnt; j++) {
916 pi = (phasor_info*)wmem_array_index(block->phasors, j);
917 temp_item = proto_tree_add_text(phasor_tree, tvb, offset,
918 floating_point == block->format_ph ? 8 : 4,
919 "Phasor #%u: \"%s\"", j + 1, pi->name);
921 offset += dissect_single_phasor(tvb, offset,
924 block->phasor_notation);
926 /* for values in integer format, apply conversation factor */
927 if (integer == block->format_ph)
928 mag = (mag * pi->conv) * 0.00001;
931 #define DEGREE "\xC2\xB0" /* DEGREE signs in UTF-8 */
933 proto_item_append_text(temp_item, ", %10.2f%c" ANGLE "%7.2f" DEGREE,
935 V == pi->unit ? 'V' : 'A',
943 /* used by 'dissect_data_frame()' to dissect the FREQ and DFREQ fields */
944 static gint dissect_DFREQ(tvbuff_t *tvb, proto_tree *tree, config_block *block, gint offset)
946 if (floating_point == block->format_fr) {
949 tmp = tvb_get_ntohieee_float(tvb, offset);
950 proto_tree_add_text(tree, tvb, offset, 4, "Actual frequency value: %fHz", tmp); offset += 4;
952 /* The standard doesn't clearly say how to interpret this value, but
953 * http://www.pes-psrc.org/h/C37_118_H11_FAQ_Jan2008.pdf provides further information.
954 * --> no scaling factor is applied to DFREQ
956 tmp = tvb_get_ntohieee_float(tvb, offset);
957 proto_tree_add_text(tree, tvb, offset, 4, "Rate of change of frequency: %fHz/s", tmp); offset += 4;
962 tmp = tvb_get_ntohs(tvb, offset);
963 proto_tree_add_text(tree, tvb, offset, 2,
964 "Frequency deviation from nominal: %" G_GINT16_FORMAT "mHz (actual frequency: %.3fHz)",
965 tmp, block->fnom + (tmp / 1000.0));
968 tmp = tvb_get_ntohs(tvb, offset);
969 proto_tree_add_text(tree, tvb, offset, 2, "Rate of change of frequency: %.3fHz/s", tmp / 100.0); offset += 2;
974 /* used by 'dissect_data_frame()' to dissect the ANALOG field */
975 static gint dissect_ANALOG(tvbuff_t *tvb, proto_tree *tree, config_block *block, gint offset)
977 proto_tree *analog_tree = NULL;
978 proto_item *temp_item = NULL;
981 cnt = wmem_array_get_count(block->analogs); /* number of analog values to dissect */
986 length = wmem_array_get_count(block->analogs) * (floating_point == block->format_an ? 4 : 2);
987 temp_item = proto_tree_add_text(tree, tvb, offset, length, "Analog values (%u)", cnt);
989 analog_tree = proto_item_add_subtree(temp_item, ett_data_analog);
991 for (j = 0; j < cnt; j++) {
992 analog_info *ai = (analog_info *)wmem_array_index(block->analogs, j);
994 temp_item = proto_tree_add_text(analog_tree, tvb, offset,
995 floating_point == block->format_an ? 4 : 2,
996 "Analog value #%u: \"%s\"", j + 1, ai->name);
998 if (floating_point == block->format_an) {
999 gfloat tmp = tvb_get_ntohieee_float(tvb, offset); offset += 4;
1000 proto_item_append_text(temp_item, ", %.3f", tmp);
1003 /* the "standard" doesn't say if this is signed or unsigned,
1004 * so I just use gint16, the scaling of the conversation factor
1005 * is also "user defined", so I just write it after the analog value */
1006 gint16 tmp = tvb_get_ntohs(tvb, offset); offset += 2;
1007 proto_item_append_text(temp_item, ", %" G_GINT16_FORMAT " (conversation factor: %#06x)",
1014 /* used by 'dissect_data_frame()' to dissect the DIGITAL field */
1015 static gint dissect_DIGITAL(tvbuff_t *tvb, proto_tree *tree, config_block *block, gint offset)
1017 proto_item *digital_item = NULL;
1019 cnt = block->num_dg; /* number of digital status words to dissect */
1024 digital_item = proto_tree_add_text(tree, tvb, offset, cnt * 2, "Digital status words (%u)", cnt);
1025 tree = proto_item_add_subtree(digital_item, ett_data_digital);
1027 for (j = 0; j < cnt; j++) {
1028 guint16 tmp = tvb_get_ntohs(tvb, offset);
1029 proto_tree_add_text(tree, tvb, offset, 2, "Digital status word #%u: 0x%04x", j + 1, tmp);
1035 /*******************************************************************/
1036 /* after this line: helper functions for 'dissect_config_frame()' */
1037 /*******************************************************************/
1039 /* used by 'dissect_config_frame()' to dissect the PHUNIT field */
1040 static gint dissect_PHUNIT(tvbuff_t *tvb, proto_tree *tree, gint offset, gint cnt)
1042 proto_item *temp_item = NULL;
1043 proto_tree *temp_tree = NULL;
1049 temp_item = proto_tree_add_text(tree, tvb, offset, 4 * cnt, "Phasor conversation factors (%u)", cnt);
1050 temp_tree = proto_item_add_subtree(temp_item, ett_conf_phconv);
1052 /* Conversion factor for phasor channels. Four bytes for each phasor.
1053 * MSB: 0 = voltage, 1 = current
1054 * Lower 3 Bytes: unsigned 24-bit word in 10^-5 V or A per bit to scale the phasor value
1056 for (i = 0; i < cnt; i++) {
1057 guint32 tmp = tvb_get_ntohl(tvb, offset);
1058 proto_tree_add_text(temp_tree, tvb, offset, 4,
1059 "#%u factor: %u * 10^-5, unit: %s",
1062 tmp & 0xFF000000 ? "Ampere" : "Volt");
1069 /* used by 'dissect_config_frame()' to dissect the ANUNIT field */
1070 static gint dissect_ANUNIT(tvbuff_t *tvb, proto_tree *tree, gint offset, gint cnt)
1072 proto_item *temp_item = NULL;
1073 proto_tree *temp_tree = NULL;
1079 temp_item = proto_tree_add_text(tree, tvb, offset, 4 * cnt, "Analog values conversation factors (%u)", cnt);
1080 temp_tree = proto_item_add_subtree(temp_item, ett_conf_anconv);
1082 /* Conversation factor for analog channels. Four bytes for each analog value.
1083 * MSB: see 'synphasor_conf_anconvnames' in 'synphasor_strings.c'
1084 * Lower 3 Bytes: signed 24-bit word, user-defined scaling
1086 for (i = 0; i < cnt; i++) {
1087 gint32 tmp = tvb_get_ntohl(tvb, offset);
1088 temp_item = proto_tree_add_text(temp_tree, tvb, offset, 4,
1089 "Factor for analog value #%i: %s",
1091 try_rval_to_str((tmp >> 24) & 0x000000FF, conf_anconvnames));
1094 if ( tmp & 0x00800000) /* sign bit set */
1097 proto_item_append_text(temp_item, ", value: %" G_GINT32_FORMAT, tmp);
1105 /* used by 'dissect_config_frame()' to dissect the DIGUNIT field */
1106 static gint dissect_DIGUNIT(tvbuff_t *tvb, proto_tree *tree, gint offset, gint cnt)
1108 proto_item *temp_item = NULL;
1109 proto_tree *temp_tree = NULL;
1115 temp_item = proto_tree_add_text(tree, tvb, offset, 4 * cnt, "Masks for digital status words (%u)", cnt);
1116 temp_tree = proto_item_add_subtree(temp_item, ett_conf_dgmask);
1118 /* Mask words for digital status words. Two 16-bit words for each digital word. The first
1119 * inidcates the normal status of the inputs, the second indicated the valid bits in
1122 for (i = 0; i < cnt; i++) {
1123 guint32 tmp = tvb_get_ntohl(tvb, offset);
1125 temp_item = proto_tree_add_text(temp_tree, tvb, offset, 4, "Mask for status word #%u: ", i + 1);
1126 proto_item_append_text(temp_item, "normal state: 0x%04"G_GINT16_MODIFIER"x", (guint16)((tmp & 0xFFFF0000) >> 16));
1127 proto_item_append_text(temp_item, ", valid bits: 0x%04"G_GINT16_MODIFIER"x", (guint16)( tmp & 0x0000FFFF));
1135 /* used by 'dissect_config_frame()' to dissect the "channel name"-fields */
1136 static gint dissect_CHNAM(tvbuff_t *tvb, proto_tree *tree, gint offset, gint cnt, const char *prefix)
1138 proto_item *temp_item = NULL;
1139 proto_tree *temp_tree = NULL;
1145 temp_item = proto_tree_add_text(tree, tvb, offset, CHNAM_LEN * cnt, "%ss (%u)", prefix, cnt);
1146 temp_tree = proto_item_add_subtree(temp_item, ett_conf_phnam);
1148 /* dissect the 'cnt' channel names */
1149 for (i = 0; i < cnt; i++) {
1151 str = tvb_get_string(wmem_packet_scope(), tvb, offset, CHNAM_LEN);
1152 proto_tree_add_text(temp_tree, tvb, offset, CHNAM_LEN,
1153 "%s #%i: \"%s\"", prefix, i+1, str);
1154 offset += CHNAM_LEN;
1160 void proto_register_synphasor(void)
1162 static hf_register_info hf[] = {
1165 { "Synchronization word", PROTOCOL_ABBREV ".sync", FT_UINT16, BASE_HEX,
1166 NULL, 0x0, NULL, HFILL }},
1167 /* Flags in the Sync word */
1169 { "Frame Type", PROTOCOL_ABBREV ".frtype", FT_UINT16, BASE_HEX,
1170 VALS(typenames), 0x0070, NULL, HFILL }},
1173 { "Version", PROTOCOL_ABBREV ".version", FT_UINT16, BASE_DEC,
1174 VALS(versionnames), 0x000F, NULL, HFILL }},
1177 { "Framesize", PROTOCOL_ABBREV ".frsize", FT_UINT16, BASE_DEC,
1178 NULL, 0x0, NULL, HFILL }},
1181 { "PMU/DC ID number", PROTOCOL_ABBREV ".idcode", FT_UINT16, BASE_DEC,
1182 NULL, 0x0, NULL, HFILL }},
1185 { "SOC time stamp (UTC)", PROTOCOL_ABBREV ".soc", FT_STRINGZ, BASE_NONE,
1186 NULL, 0x0, NULL, HFILL }},
1188 /* Time quality flags in fracsec */
1189 { &hf_timeqal_lsdir,
1190 { "Leap second direction", PROTOCOL_ABBREV ".timeqal.lsdir", FT_BOOLEAN, 8,
1191 NULL, 0x40, NULL, HFILL }},
1193 { &hf_timeqal_lsocc,
1194 { "Leap second occurred", PROTOCOL_ABBREV ".timeqal.lsocc", FT_BOOLEAN, 8,
1195 NULL, 0x20, NULL, HFILL }},
1197 { &hf_timeqal_lspend,
1198 { "Leap second pending", PROTOCOL_ABBREV ".timeqal.lspend", FT_BOOLEAN, 8,
1199 NULL, 0x10, NULL, HFILL }},
1201 { &hf_timeqal_timequalindic,
1202 { "Time Quality indicator code", PROTOCOL_ABBREV ".timeqal.timequalindic", FT_UINT8, BASE_HEX,
1203 VALS(timequalcodes), 0x0F, NULL, HFILL }},
1205 /* Fraction of second */
1207 { "Fraction of second (raw)", PROTOCOL_ABBREV ".fracsec", FT_UINT24, BASE_DEC,
1208 NULL, 0x0, NULL, HFILL }},
1210 /* Data types for configuration frames */
1211 { &hf_conf_timebase,
1212 { "Resolution of fractional second time stamp", PROTOCOL_ABBREV ".conf.timebase", FT_UINT24, BASE_DEC,
1213 NULL, 0x0, NULL, HFILL }},
1216 { "Number of PMU blocks included in the frame", PROTOCOL_ABBREV ".conf.numpmu", FT_UINT16, BASE_DEC,
1217 NULL, 0x0, NULL, HFILL }},
1219 /* Bits in the FORMAT word */
1220 { &hf_conf_formatb3,
1221 { "FREQ/DFREQ format", PROTOCOL_ABBREV ".conf.dfreq_format", FT_BOOLEAN, 16,
1222 TFS(&conf_formatb123names), 0x8, NULL, HFILL }},
1224 { &hf_conf_formatb2,
1225 { "Analog values format", PROTOCOL_ABBREV ".conf.analog_format", FT_BOOLEAN, 16,
1226 TFS(&conf_formatb123names), 0x4, NULL, HFILL }},
1228 { &hf_conf_formatb1,
1229 { "Phasor format", PROTOCOL_ABBREV ".conf.phasor_format", FT_BOOLEAN, 16,
1230 TFS(&conf_formatb123names), 0x2, NULL, HFILL }},
1232 { &hf_conf_formatb0,
1233 { "Phasor notation", PROTOCOL_ABBREV ".conf.phasor_notation", FT_BOOLEAN, 16,
1234 TFS(&conf_formatb0names), 0x1, NULL, HFILL }},
1237 { "Nominal line freqency", PROTOCOL_ABBREV ".conf.fnom", FT_BOOLEAN, 16,
1238 TFS(&conf_fnomnames), 0x0001, NULL, HFILL }},
1241 { "Configuration change count", PROTOCOL_ABBREV ".conf.cfgcnt", FT_UINT16, BASE_DEC,
1242 NULL, 0, NULL, HFILL }},
1244 /* Data types for data frames */
1245 /* Flags in the STAT word */
1247 { "Data valid", PROTOCOL_ABBREV ".data.valid", FT_BOOLEAN, 16,
1248 TFS(&data_statb15names), 0x8000, NULL, HFILL }},
1251 { "PMU error", PROTOCOL_ABBREV ".data.PMUerror", FT_BOOLEAN, 16,
1252 TFS(&data_statb14names), 0x4000, NULL, HFILL }},
1255 { "Time synchronized", PROTOCOL_ABBREV ".data.sync", FT_BOOLEAN, 16,
1256 TFS(&data_statb13names), 0x2000, NULL, HFILL }},
1259 { "Data sorting", PROTOCOL_ABBREV ".data.sorting", FT_BOOLEAN, 16,
1260 TFS(&data_statb12names), 0x1000, NULL, HFILL }},
1263 { "Trigger detected", PROTOCOL_ABBREV ".data.trigger", FT_BOOLEAN, 16,
1264 TFS(&data_statb11names), 0x0800, NULL, HFILL }},
1267 { "Configuration changed", PROTOCOL_ABBREV ".data.CFGchange", FT_BOOLEAN, 16,
1268 TFS(&data_statb10names), 0x0400, NULL, HFILL }},
1270 { &hf_data_statb05to04,
1271 { "Unlocked time", PROTOCOL_ABBREV ".data.t_unlock", FT_UINT16, BASE_HEX,
1272 VALS(data_statb05to04names), 0x0030, NULL, HFILL }},
1274 { &hf_data_statb03to00,
1275 { "Trigger reason", PROTOCOL_ABBREV ".data.trigger_reason", FT_UINT16, BASE_HEX,
1276 VALS(data_statb03to00names), 0x000F, NULL, HFILL }},
1278 /* Data type for command frame */
1280 { "Command", PROTOCOL_ABBREV ".command", FT_UINT16, BASE_HEX,
1281 VALS(command_names), 0x000F, NULL, HFILL }}
1284 /* protocol subtree array */
1285 static gint *ett[] = {
1307 module_t *synphasor_module;
1309 /* register protocol */
1310 proto_synphasor = proto_register_protocol(PROTOCOL_NAME,
1311 PROTOCOL_SHORT_NAME,
1314 /* Registering protocol to be called by another dissector */
1315 synphasor_udp_handle = new_register_dissector("synphasor", dissect_udp, proto_synphasor);
1317 proto_register_field_array(proto_synphasor, hf, array_length(hf));
1318 proto_register_subtree_array(ett, array_length(ett));
1320 /* register preferences */
1321 synphasor_module = prefs_register_protocol(proto_synphasor, proto_reg_handoff_synphasor);
1323 /* the port numbers of the lower level protocols */
1324 prefs_register_uint_preference(synphasor_module, "udp_port", "Synchrophasor UDP port",
1325 "Set the port number for synchrophasor frames over UDP" \
1326 "(if other than the default of 4713)",
1327 10, &global_pref_udp_port);
1328 prefs_register_uint_preference(synphasor_module, "tcp_port", "Synchrophasor TCP port",
1329 "Set the port number for synchrophasor frames over TCP" \
1330 "(if other than the default of 4712)",
1331 10, &global_pref_tcp_port);
1333 } /* proto_register_synphasor() */
1335 /* called at startup and when the preferences change */
1336 void proto_reg_handoff_synphasor(void)
1338 static gboolean initialized = FALSE;
1339 static dissector_handle_t synphasor_tcp_handle;
1340 static guint current_udp_port;
1341 static guint current_tcp_port;
1344 synphasor_tcp_handle = new_create_dissector_handle(dissect_tcp, proto_synphasor);
1349 /* update preferences */
1350 dissector_delete_uint("udp.port", current_udp_port, synphasor_udp_handle);
1351 dissector_delete_uint("tcp.port", current_tcp_port, synphasor_tcp_handle);
1354 current_udp_port = global_pref_udp_port;
1355 current_tcp_port = global_pref_tcp_port;
1357 dissector_add_uint("udp.port", current_udp_port, synphasor_udp_handle);
1358 dissector_add_uint("tcp.port", current_tcp_port, synphasor_tcp_handle);
1359 } /* proto_reg_handoff_synphasor() */