Adjust proto_tree_add_[float|double]_format_value calls to use unit string
[metze/wireshark/wip.git] / epan / dissectors / packet-synphasor.c
index 1d4c89a236f36b48e6b80e65467b2a27aa58041d..4c37e281cb04ccfcfe94827342df1380b9e4ca4a 100644 (file)
@@ -3,8 +3,6 @@
  *
  * Copyright 2008, Jens Steinhauser <jens.steinhauser@omicron.at>
  *
- * $Id$
- *
  * Wireshark - Network traffic analyzer
  * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
 
 #include "config.h"
 
-#include <glib.h>
-#include <epan/conversation.h>
-#include <epan/crc16-tvb.h>
-#include <epan/dissectors/packet-tcp.h>
+#include <math.h>
+
 #include <epan/packet.h>
-#include <epan/prefs.h>
+#include <epan/crc16-tvb.h>
+#include <epan/expert.h>
+#include <epan/proto_data.h>
+#include "packet-tcp.h"
 
-#include <math.h>
+#include <wsutil/utf8_entities.h>
 
 #define PROTOCOL_NAME      "IEEE C37.118 Synchrophasor Protocol"
 #define PROTOCOL_SHORT_NAME "SYNCHROPHASOR"
 #define PROTOCOL_ABBREV            "synphasor"
 
 /* forward references */
+void proto_register_synphasor(void);
 void proto_reg_handoff_synphasor(void);
 
 /* global variables */
 
-static int     proto_synphasor  = -1;
-static GSList *config_frame_list = NULL;
+static int proto_synphasor      = -1;
 
 /* user preferences */
-static guint global_pref_tcp_port = 4712;
-static guint global_pref_udp_port = 4713;
+#define SYNPHASOR_TCP_PORT  4712 /* Not IANA registered */
+#define SYNPHASOR_UDP_PORT  4713 /* Not IANA registered */
 
 /* the ett... variables hold the state (open/close) of the treeview in the GUI */
 static gint ett_synphasor         = -1; /* root element for this protocol */
@@ -75,6 +74,7 @@ static gint ett_synphasor        = -1; /* root element for this protocol */
       static gint ett_data_digital = -1;
   /* used for command frames */
   static gint ett_command         = -1;
+  static gint ett_status_word_mask = -1;
 
 /* handles to the header fields hf[] in proto_register_synphasor() */
 static int hf_sync                 = -1;
@@ -106,6 +106,31 @@ static int hf_data_statb05to04         = -1;
 static int hf_data_statb03to00     = -1;
 static int hf_command              = -1;
 
+/* Generated from convert_proto_tree_add_text.pl */
+static int hf_synphasor_data = -1;
+static int hf_synphasor_checksum = -1;
+static int hf_synphasor_checksum_status = -1;
+static int hf_synphasor_num_phasors = -1;
+static int hf_synphasor_num_analog_values = -1;
+static int hf_synphasor_num_digital_status_words = -1;
+static int hf_synphasor_rate_of_transmission = -1;
+static int hf_synphasor_phasor = -1;
+static int hf_synphasor_actual_frequency_value = -1;
+static int hf_synphasor_rate_change_frequency = -1;
+static int hf_synphasor_frequency_deviation_from_nominal = -1;
+static int hf_synphasor_analog_value = -1;
+static int hf_synphasor_digital_status_word = -1;
+static int hf_synphasor_conversion_factor = -1;
+static int hf_synphasor_factor_for_analog_value = -1;
+static int hf_synphasor_channel_name = -1;
+static int hf_synphasor_extended_frame_data = -1;
+static int hf_synphasor_unknown_data = -1;
+static int hf_synphasor_status_word_mask_normal_state = -1;
+static int hf_synphasor_status_word_mask_valid_bits = -1;
+
+static expert_field ei_synphasor_extended_frame_data = EI_INIT;
+static expert_field ei_synphasor_checksum = EI_INIT;
+
 static dissector_handle_t synphasor_udp_handle;
 
 /* the five different frame types for this protocol */
@@ -147,16 +172,16 @@ typedef struct {
 
 /* holds information required to dissect a single PMU block in a data frame */
 typedef struct {
-       guint16         id;                  /* identifies source of block     */
-       char            name[CHNAM_LEN + 1]; /* holds STN                      */
-       data_format     format_fr;           /* data format of FREQ and DFREQ  */
-       data_format     format_ph;           /* data format of PHASORS         */
-       data_format     format_an;           /* data format of ANALOG          */
-       phasor_notation_e phasor_notation;   /* format of the phasors          */
-       guint           fnom;                /* nominal line frequency         */
-       guint           num_dg;              /* number of digital status words */
-       GArray         *phasors;             /* array of phasor_infos          */
-       GArray         *analogs;             /* array of analog_infos          */
+       guint16            id;                  /* identifies source of block     */
+       char               name[CHNAM_LEN + 1]; /* holds STN                      */
+       data_format        format_fr;           /* data format of FREQ and DFREQ  */
+       data_format        format_ph;           /* data format of PHASORS         */
+       data_format        format_an;           /* data format of ANALOG          */
+       phasor_notation_e  phasor_notation;     /* format of the phasors          */
+       guint              fnom;                /* nominal line frequency         */
+       guint              num_dg;              /* number of digital status words */
+       wmem_array_t      *phasors;             /* array of phasor_infos          */
+       wmem_array_t      *analogs;             /* array of analog_infos          */
 } config_block;
 
 /* holds the id the configuration comes from an and
@@ -165,7 +190,7 @@ typedef struct {
        guint32  fnum;          /* frame number */
 
        guint16  id;
-       GArray  *config_blocks; /* Contains a config_block struct for
+       wmem_array_t    *config_blocks; /* Contains a config_block struct for
                                 * every PMU included in the config frame */
 } config_frame;
 
@@ -310,16 +335,16 @@ static const value_string command_names[] = {
  *
  * use 'config_frame_free()' to free the config_frame again
  */
-static config_frameconfig_frame_fast(tvbuff_t *tvb)
+static config_frame *config_frame_fast(tvbuff_t *tvb)
 {
        guint16       idcode, num_pmu;
        gint          offset;
        config_frame *frame;
 
        /* get a new frame and initialize it */
-       frame = g_slice_new(config_frame);
+       frame = wmem_new(wmem_file_scope(), config_frame);
 
-       frame->config_blocks = g_array_new(FALSE, TRUE, sizeof(config_block));
+       frame->config_blocks = wmem_array_new(wmem_file_scope(), sizeof(config_block));
 
        idcode = tvb_get_ntohs(tvb, 4);
        frame->id       = idcode;
@@ -339,8 +364,8 @@ static config_frame* config_frame_fast(tvbuff_t *tvb)
                config_block block;
 
                /* initialize the block */
-               block.phasors = g_array_new(FALSE, TRUE, sizeof(phasor_info));
-               block.analogs = g_array_new(FALSE, TRUE, sizeof(analog_info));
+               block.phasors = wmem_array_new(wmem_file_scope(), sizeof(phasor_info));
+               block.analogs = wmem_array_new(wmem_file_scope(), sizeof(analog_info));
                /* copy the station name from the tvb to block, and add NULL byte */
                tvb_memcpy(tvb, block.name, offset, CHNAM_LEN); offset += CHNAM_LEN;
                block.name[CHNAM_LEN] = '\0';
@@ -376,7 +401,7 @@ static config_frame* config_frame_fast(tvbuff_t *tvb)
                        pi.unit = conv & 0xFF000000 ? A : V;
                        pi.conv = conv & 0x00FFFFFF;
 
-                       g_array_append_val(block.phasors, pi);
+                       wmem_array_append_one(block.phasors, pi);
                }
 
                /* read num_an analog value names and conversation factors */
@@ -391,7 +416,7 @@ static config_frame* config_frame_fast(tvbuff_t *tvb)
                        conv = tvb_get_ntohl(tvb, anunit + 4 * i);
                        ai.conv = conv;
 
-                       g_array_append_val(block.analogs, ai);
+                       wmem_array_append_one(block.analogs, ai);
                }
 
                /* the names for the bits in the digital status words aren't saved,
@@ -404,74 +429,13 @@ static config_frame* config_frame_fast(tvbuff_t *tvb)
                /* skip CFGCNT */
                offset += 2;
 
-               g_array_append_val(frame->config_blocks, block);
+               wmem_array_append_one(frame->config_blocks, block);
                num_pmu--;
        }
 
        return frame;
 }
 
-/* Frees the memory pointed to by 'frame' and all the contained
- * config_blocks and the data in their GArrays.
- */
-static void config_frame_free(config_frame *frame)
-{
-       int i = frame->config_blocks->len;
-
-       /* free all the config_blocks this frame contains */
-       while (i--) {
-               config_block *block;
-
-               block = &g_array_index(frame->config_blocks, config_block, i);
-               g_array_free(block->phasors, TRUE);
-               g_array_free(block->analogs, TRUE);
-       }
-
-       /* free the array of config blocks itself */
-       g_array_free(frame->config_blocks, TRUE);
-
-       /* and the config_frame */
-       g_slice_free1(sizeof(config_frame), frame);
-}
-
-/* called every time the user loads a capture file or starts to capture */
-static void synphasor_init(void)
-{
-       /* free stuff in the list from a previous run */
-       if (config_frame_list) {
-               g_slist_foreach(config_frame_list, (GFunc) config_frame_free, NULL);
-
-               g_slist_free(config_frame_list);
-
-               config_frame_list = NULL;
-       }
-
-}
-
-/* the main dissection routine */
-static void dissect_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
-
-/* called for synchrophasors over UDP */
-static int dissect_udp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
-{
-       dissect_common(tvb, pinfo, tree);
-
-       return tvb_length(tvb);
-}
-
-/* callback for 'tcp_dissect_pdus()' to give it the length of the frame */
-static guint get_pdu_length(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
-{
-       return tvb_get_ntohs(tvb, offset + 2);
-}
-
-static int dissect_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
-{
-       tcp_dissect_pdus(tvb, pinfo, tree, TRUE, 4, get_pdu_length, dissect_common);
-
-       return tvb_length(tvb);
-}
-
 /* Checks the CRC of a synchrophasor frame, 'tvb' has to include the whole
  * frame, including CRC, the calculated CRC is returned in '*computedcrc'.
  */
@@ -501,24 +465,23 @@ static gint dissect_header(tvbuff_t *, proto_tree *);
 /* Dissects the header (common to all types of frames) and then calls
  * one of the subdissectors (declared above) for the rest of the frame.
  */
-static void dissect_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+static int dissect_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
 {
        guint8  frame_type;
        guint16 crc;
-       guint   tvbsize = tvb_length(tvb);
+       guint   tvbsize = tvb_reported_length(tvb);
 
        /* some heuristics */
        if (tvbsize < 17                    /* 17 bytes = header frame with only a
                                               NULL character, useless but valid */
         || tvb_get_guint8(tvb, 0) != 0xAA) /* every synchrophasor frame starts with 0xAA */
-               return;
+               return 0;
 
        /* write the protocol name to the info column */
        col_set_str(pinfo->cinfo, COL_PROTOCOL, PROTOCOL_SHORT_NAME);
 
        frame_type = tvb_get_guint8(tvb, 1) >> 4;
 
-       col_clear(pinfo->cinfo, COL_INFO); /* clear out stuff in the info column */
        col_add_fstr(pinfo->cinfo, COL_INFO, "%s", val_to_str_const(frame_type, typenames, "invalid packet type"));
 
        /* CFG-2 and DATA frames need special treatment during the first run:
@@ -534,11 +497,9 @@ static void dissect_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 
                        /* fill the config_frame */
                        config_frame *frame = config_frame_fast(tvb);
-                       frame->fnum = pinfo->fd->num;
-                       /* so we can cleanup later */
-                       config_frame_list = g_slist_append(config_frame_list, frame);
+                       frame->fnum = pinfo->num;
 
-                       /* find a conversation, create a new if no one exists */
+                       /* find a conversation, create a new one if none exists */
                        conversation = find_or_create_conversation(pinfo);
 
                        /* remove data from a previous CFG-2 frame, only
@@ -549,7 +510,7 @@ static void dissect_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                        conversation_add_proto_data(conversation, proto_synphasor, frame);
                }
                else if (DATA == frame_type) {
-                       conversation_t *conversation = find_conversation(pinfo->fd->num,
+                       conversation_t *conversation = find_conversation(pinfo->num,
                                                                         &pinfo->src, &pinfo->dst,
                                                                         pinfo->ptype,
                                                                         pinfo->srcport, pinfo->destport,
@@ -558,19 +519,20 @@ static void dissect_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                        if (conversation) {
                                config_frame *conf = (config_frame *)conversation_get_proto_data(conversation, proto_synphasor);
                                /* no problem if 'conf' is NULL, the DATA frame dissector checks this again */
-                       p_add_proto_data(pinfo->fd, proto_synphasor, 0, conf);
+                       p_add_proto_data(wmem_file_scope(), pinfo, proto_synphasor, 0, conf);
                        }
                }
        } /* if (!visited) */
 
-       if (tree) { /* we are being asked for details */
-               proto_tree *synphasor_tree = NULL;
-               proto_item *temp_item      = NULL;
-               proto_item *sub_item       = NULL;
+       {
+               proto_tree *synphasor_tree;
+               proto_item *temp_item;
+               proto_item *sub_item;
 
-               gint     offset;
-               guint16  framesize;
-               tvbuff_t *sub_tvb;
+               gint        offset;
+               guint16     framesize;
+               tvbuff_t   *sub_tvb;
+               gboolean   crc_good;
 
                temp_item = proto_tree_add_item(tree, proto_synphasor, tvb, 0, -1, ENC_NA);
                proto_item_append_text(temp_item, ", %s", val_to_str_const(frame_type, typenames,
@@ -583,11 +545,12 @@ static void dissect_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                offset = 14; /* header is 14 bytes long */
 
                /* check CRC, call appropriate subdissector for the rest of the frame if CRC is correct*/
-               sub_item  = proto_tree_add_text(synphasor_tree, tvb, offset     , tvbsize - 16, "Data"     );
-               temp_item = proto_tree_add_text(synphasor_tree, tvb, tvbsize - 2, 2           , "Checksum:");
-               if (!check_crc(tvb, &crc)) {
+               sub_item  = proto_tree_add_item(synphasor_tree, hf_synphasor_data, tvb, offset, tvbsize - 16, ENC_NA);
+               crc_good = check_crc(tvb, &crc);
+               proto_tree_add_checksum(synphasor_tree, tvb, tvbsize - 2, hf_synphasor_checksum, hf_synphasor_checksum_status, &ei_synphasor_checksum,
+                                                               pinfo, crc16_x25_ccitt_tvb(tvb, tvb_get_ntohs(tvb, 2) - 2), ENC_BIG_ENDIAN, PROTO_CHECKSUM_VERIFY);
+               if (!crc_good) {
                        proto_item_append_text(sub_item,  ", not dissected because of wrong checksum");
-                       proto_item_append_text(temp_item, " 0x%04x [incorrect]", crc);
                }
                else {
                        /* create a new tvb to pass to the subdissector
@@ -613,13 +576,36 @@ static void dissect_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                                default:
                                        proto_item_append_text(sub_item, " of unknown type");
                        }
-                       proto_item_append_text(temp_item, " 0x%04x [correct]", crc);
+                       proto_item_append_text(temp_item, " [correct]");
                }
 
                /*offset += 2;*/ /* CRC */
-       } /* if (tree) */
+       }
+
+       return tvb_reported_length(tvb);
 } /* dissect_synphasor() */
 
+/* called for synchrophasors over UDP */
+static int dissect_udp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
+{
+       return dissect_common(tvb, pinfo, tree, data);
+}
+
+/* callback for 'tcp_dissect_pdus()' to give it the length of the frame */
+static guint get_pdu_length(packet_info *pinfo _U_, tvbuff_t *tvb,
+                            int offset, void *data _U_)
+{
+       return tvb_get_ntohs(tvb, offset + 2);
+}
+
+static int dissect_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
+{
+       tcp_dissect_pdus(tvb, pinfo, tree, TRUE, 4, get_pdu_length, dissect_common, data);
+
+       return tvb_reported_length(tvb);
+}
+
+
 /* Dissects the common header of frames.
  *
  * Returns the framesize, in contrast to most
@@ -636,8 +622,8 @@ static gint dissect_header(tvbuff_t *tvb, proto_tree *tree)
        /* SYNC and flags */
        temp_item = proto_tree_add_item(tree, hf_sync, tvb, offset, 2, ENC_BIG_ENDIAN);
        temp_tree = proto_item_add_subtree(temp_item, ett_frtype);
-               proto_tree_add_item(temp_tree, hf_sync_frtype,  tvb, offset, 2, ENC_BIG_ENDIAN);
-               proto_tree_add_item(temp_tree, hf_sync_version, tvb, offset, 2, ENC_BIG_ENDIAN);
+       proto_tree_add_item(temp_tree, hf_sync_frtype,  tvb, offset, 2, ENC_BIG_ENDIAN);
+       proto_tree_add_item(temp_tree, hf_sync_version, tvb, offset, 2, ENC_BIG_ENDIAN);
        offset += 2;
 
        /* FRAMESIZE */
@@ -649,25 +635,16 @@ static gint dissect_header(tvbuff_t *tvb, proto_tree *tree)
        offset += 2;
 
        /* SOC */
-       {
-               /* can't use 'proto_tree_add_time()' because we need UTC */
-               char   buf[20];
-               struct tm* t;
-               time_t soc = tvb_get_ntohl(tvb, offset);
-               t = gmtime(&soc);
-               strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", t);
-               proto_tree_add_string(tree, hf_soc, tvb, offset, 4, buf);
-               offset += 4;
-       }
+       proto_tree_add_item(tree, hf_soc, tvb, offset, 4, ENC_TIME_TIMESPEC | ENC_BIG_ENDIAN);
+       offset += 4;
 
        /* FRACSEC */
        /* time quality flags */
-       temp_item = proto_tree_add_text(tree, tvb, offset, 1, "Time quality flags");
-       temp_tree = proto_item_add_subtree(temp_item, ett_timequal);
-               proto_tree_add_item(temp_tree, hf_timeqal_lsdir,         tvb, offset, 1, ENC_BIG_ENDIAN);
-               proto_tree_add_item(temp_tree, hf_timeqal_lsocc,         tvb, offset, 1, ENC_BIG_ENDIAN);
-               proto_tree_add_item(temp_tree, hf_timeqal_lspend,        tvb, offset, 1, ENC_BIG_ENDIAN);
-               proto_tree_add_item(temp_tree, hf_timeqal_timequalindic, tvb, offset, 1, ENC_BIG_ENDIAN);
+       temp_tree = proto_tree_add_subtree(tree, tvb, offset, 1, ett_timequal, NULL, "Time quality flags");
+       proto_tree_add_item(temp_tree, hf_timeqal_lsdir,         tvb, offset, 1, ENC_BIG_ENDIAN);
+       proto_tree_add_item(temp_tree, hf_timeqal_lsocc,         tvb, offset, 1, ENC_BIG_ENDIAN);
+       proto_tree_add_item(temp_tree, hf_timeqal_lspend,        tvb, offset, 1, ENC_BIG_ENDIAN);
+       proto_tree_add_item(temp_tree, hf_timeqal_timequalindic, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;
 
        proto_tree_add_item(tree, hf_fracsec,  tvb, offset, 3, ENC_BIG_ENDIAN);
@@ -685,11 +662,9 @@ static gint dissect_DIGUNIT(tvbuff_t *tvb, proto_tree *tree, gint offset, gint c
 /* dissects a configuration frame (type 1 and 2) and adds fields to 'config_item' */
 static int dissect_config_frame(tvbuff_t *tvb, proto_item *config_item)
 {
-       proto_tree *config_tree = NULL;
-       proto_item *temp_item   = NULL;
-       proto_tree *temp_tree   = NULL;
-       gint     offset = 0, j;
-       guint16  num_pmu;
+       proto_tree *config_tree;
+       gint        offset = 0, j;
+       guint16     num_pmu;
 
        proto_item_set_text   (config_item, "Configuration data");
        config_tree = proto_item_add_subtree(config_item, ett_conf);
@@ -704,38 +679,40 @@ static int dissect_config_frame(tvbuff_t *tvb, proto_item *config_item)
 
        /* dissect the repeating PMU blocks */
        for (j = 0; j < num_pmu; j++) {
-               guint16  num_ph, num_an, num_dg;
-               proto_item *station_item = NULL;
-               proto_tree *station_tree = NULL;
-               char *str;
+               guint16     num_ph, num_an, num_dg;
+               proto_item *station_item;
+               proto_tree *station_tree;
+               proto_tree *temp_tree;
+               char       *str;
 
                gint oldoffset = offset; /* to calculate the length of the whole PMU block later */
 
                /* STN with new tree to add the rest of the PMU block */
-               str = tvb_get_ephemeral_string(tvb, offset, CHNAM_LEN);
-               station_item = proto_tree_add_text(config_tree, tvb, offset, CHNAM_LEN, "Station #%i: \"%s\"", j + 1, str);
-               station_tree = proto_item_add_subtree(station_item, ett_conf_station);
+               str = tvb_get_string_enc(wmem_packet_scope(), tvb, offset, CHNAM_LEN, ENC_ASCII);
+               station_tree = proto_tree_add_subtree_format(config_tree, tvb, offset, CHNAM_LEN,
+                                                            ett_conf_station, &station_item,
+                                                            "Station #%i: \"%s\"", j + 1, str);
                offset += CHNAM_LEN;
 
                /* IDCODE */
                proto_tree_add_item(station_tree, hf_idcode, tvb, offset, 2, ENC_BIG_ENDIAN); offset += 2;
 
                /* FORMAT */
-               temp_item = proto_tree_add_text(station_tree, tvb, offset, 2, "Data format in data frame");
-               temp_tree = proto_item_add_subtree(temp_item, ett_conf_format);
-                       proto_tree_add_item(temp_tree, hf_conf_formatb3, tvb, offset, 2, ENC_BIG_ENDIAN);
-                       proto_tree_add_item(temp_tree, hf_conf_formatb2, tvb, offset, 2, ENC_BIG_ENDIAN);
-                       proto_tree_add_item(temp_tree, hf_conf_formatb1, tvb, offset, 2, ENC_BIG_ENDIAN);
-                       proto_tree_add_item(temp_tree, hf_conf_formatb0, tvb, offset, 2, ENC_BIG_ENDIAN);
+               temp_tree = proto_tree_add_subtree(station_tree, tvb, offset, 2, ett_conf_format, NULL,
+                                                  "Data format in data frame");
+               proto_tree_add_item(temp_tree, hf_conf_formatb3, tvb, offset, 2, ENC_BIG_ENDIAN);
+               proto_tree_add_item(temp_tree, hf_conf_formatb2, tvb, offset, 2, ENC_BIG_ENDIAN);
+               proto_tree_add_item(temp_tree, hf_conf_formatb1, tvb, offset, 2, ENC_BIG_ENDIAN);
+               proto_tree_add_item(temp_tree, hf_conf_formatb0, tvb, offset, 2, ENC_BIG_ENDIAN);
                offset += 2;
 
                /* PHNMR, ANNMR, DGNMR */
                num_ph = tvb_get_ntohs(tvb, offset    );
                num_an = tvb_get_ntohs(tvb, offset + 2);
                num_dg = tvb_get_ntohs(tvb, offset + 4);
-               proto_tree_add_text(station_tree, tvb, offset    , 2, "Number of phasors: %u",              num_ph);
-               proto_tree_add_text(station_tree, tvb, offset + 2, 2, "Number of analog values: %u",        num_an);
-               proto_tree_add_text(station_tree, tvb, offset + 4, 2, "Number of digital status words: %u", num_dg);
+               proto_tree_add_uint(station_tree, hf_synphasor_num_phasors, tvb, offset, 2, num_ph);
+               proto_tree_add_uint(station_tree, hf_synphasor_num_analog_values, tvb, offset + 2, 2, num_an);
+               proto_tree_add_uint(station_tree, hf_synphasor_num_digital_status_words, tvb, offset + 4, 2, num_dg);
                offset += 6;
 
                /* CHNAM, the channel names */
@@ -759,11 +736,13 @@ static int dissect_config_frame(tvbuff_t *tvb, proto_item *config_item)
        /* DATA_RATE */
        {
                gint16 tmp = tvb_get_ntohs(tvb, offset);
-               temp_item  = proto_tree_add_text(config_tree, tvb, offset, 2, "Rate of transmission: "); offset += 2;
                if (tmp > 0)
-                       proto_item_append_text(temp_item, "%"G_GINT16_FORMAT" frame(s) per second", tmp);
+                       proto_tree_add_int_format_value(config_tree, hf_synphasor_rate_of_transmission, tvb, offset, 2, tmp,
+                        "%d frame(s) per second", tmp);
                else
-                       proto_item_append_text(temp_item, "1 frame per %"G_GINT16_FORMAT" second(s)", (gint16)-tmp);
+                       proto_tree_add_int_format_value(config_tree, hf_synphasor_rate_of_transmission, tvb, offset, 2, tmp,
+                        "1 frame per %d second(s)", (gint16)-tmp);
+               offset += 2;
        }
 
        return offset;
@@ -774,11 +753,12 @@ static gint dissect_PHASORS(tvbuff_t *tvb, proto_tree *tree, config_block *block
 static gint dissect_DFREQ  (tvbuff_t *tvb, proto_tree *tree, config_block *block, gint offset);
 static gint dissect_ANALOG (tvbuff_t *tvb, proto_tree *tree, config_block *block, gint offset);
 static gint dissect_DIGITAL(tvbuff_t *tvb, proto_tree *tree, config_block *block, gint offset);
+
 /* calculates the size (in bytes) of a data frame that the config_block describes */
-#define BLOCKSIZE(x) (2                                                           /* STAT    */ \
-                  + (x).phasors->len * (integer == (x).format_ph ? 4 : 8) /* PHASORS */ \
-                  +                    (integer == (x).format_fr ? 4 : 8) /* (D)FREQ */ \
-                  + (x).analogs->len * (integer == (x).format_an ? 2 : 4) /* ANALOG  */ \
+#define SYNP_BLOCKSIZE(x) (2                                                      /* STAT    */ \
+                  + wmem_array_get_count((x).phasors) * (integer == (x).format_ph ? 4 : 8) /* PHASORS */ \
+                  +                                     (integer == (x).format_fr ? 4 : 8) /* (D)FREQ */ \
+                  + wmem_array_get_count((x).analogs) * (integer == (x).format_an ? 2 : 4) /* ANALOG  */ \
                   + (x).num_dg * 2)                                       /* DIGITAL */
 
 /* Dissects a data frame */
@@ -786,7 +766,7 @@ static int dissect_data_frame(tvbuff_t        *tvb,
                              proto_item  *data_item, /* all items are placed beneath this item   */
                              packet_info *pinfo)     /* used to find the data from a CFG-2 frame */
 {
-       proto_tree   *data_tree  = NULL;
+       proto_tree   *data_tree;
        gint          offset     = 0;
        guint         i;
        config_frame *conf;
@@ -797,18 +777,18 @@ static int dissect_data_frame(tvbuff_t      *tvb,
        /* search for configuration information to dissect the frame */
        {
                gboolean config_found = FALSE;
-               conf = (config_frame *)p_get_proto_data(pinfo->fd, proto_synphasor, 0);
+               conf = (config_frame *)p_get_proto_data(wmem_file_scope(), pinfo, proto_synphasor, 0);
 
                if (conf) {
                        /* check if the size of the current frame is the
                           size of the frame the config_frame describes */
                        size_t reported_size = 0;
-                       for (i = 0; i < conf->config_blocks->len; i++) {
-                               config_block *block = &g_array_index(conf->config_blocks, config_block, i);
-                               reported_size += BLOCKSIZE(*block);
+                       for (i = 0; i < wmem_array_get_count(conf->config_blocks); i++) {
+                               config_block *block = (config_block*)wmem_array_index(conf->config_blocks, i);
+                               reported_size += SYNP_BLOCKSIZE(*block);
                        }
 
-                       if (tvb_length(tvb) == reported_size) {
+                       if (tvb_reported_length(tvb) == reported_size) {
                                proto_item_append_text(data_item, ", using frame number %"G_GUINT32_FORMAT" as configuration frame",
                                                       conf->fnum);
                                config_found = TRUE;
@@ -822,31 +802,31 @@ static int dissect_data_frame(tvbuff_t      *tvb,
        }
 
        /* dissect a PMU block for every config_block in the frame */
-       for (i = 0; i < conf->config_blocks->len; i++) {
-               config_block *block = &g_array_index(conf->config_blocks, config_block, i);
+       for (i = 0; i < wmem_array_get_count(conf->config_blocks); i++) {
+               config_block *block = (config_block*)wmem_array_index(conf->config_blocks, i);
 
-               proto_item *block_item = proto_tree_add_text(data_tree, tvb, offset, BLOCKSIZE(*block),
-                                                "Station: \"%s\"", block->name);
-               proto_tree *block_tree = proto_item_add_subtree(block_item, ett_data_block);
+               proto_tree *block_tree = proto_tree_add_subtree_format(data_tree, tvb, offset, SYNP_BLOCKSIZE(*block),
+                                                                      ett_data_block, NULL,
+                                                                      "Station: \"%s\"", block->name);
 
                /* STAT */
-               proto_item *temp_item = proto_tree_add_text(block_tree, tvb, offset, 2, "Flags");
-               proto_tree *temp_tree = proto_item_add_subtree(temp_item, ett_data_stat);
-                       proto_tree_add_item(temp_tree, hf_data_statb15,     tvb, offset, 2, ENC_BIG_ENDIAN);
-                       proto_tree_add_item(temp_tree, hf_data_statb14,     tvb, offset, 2, ENC_BIG_ENDIAN);
-                       proto_tree_add_item(temp_tree, hf_data_statb13,     tvb, offset, 2, ENC_BIG_ENDIAN);
-                       proto_tree_add_item(temp_tree, hf_data_statb12,     tvb, offset, 2, ENC_BIG_ENDIAN);
-                       proto_tree_add_item(temp_tree, hf_data_statb11,     tvb, offset, 2, ENC_BIG_ENDIAN);
-                       proto_tree_add_item(temp_tree, hf_data_statb10,     tvb, offset, 2, ENC_BIG_ENDIAN);
-                       proto_tree_add_item(temp_tree, hf_data_statb05to04, tvb, offset, 2, ENC_BIG_ENDIAN);
-                       proto_tree_add_item(temp_tree, hf_data_statb03to00, tvb, offset, 2, ENC_BIG_ENDIAN);
+               proto_tree *temp_tree = proto_tree_add_subtree(block_tree, tvb, offset, 2, ett_data_stat, NULL, "Flags");
+
+               proto_tree_add_item(temp_tree, hf_data_statb15,     tvb, offset, 2, ENC_BIG_ENDIAN);
+               proto_tree_add_item(temp_tree, hf_data_statb14,     tvb, offset, 2, ENC_BIG_ENDIAN);
+               proto_tree_add_item(temp_tree, hf_data_statb13,     tvb, offset, 2, ENC_BIG_ENDIAN);
+               proto_tree_add_item(temp_tree, hf_data_statb12,     tvb, offset, 2, ENC_BIG_ENDIAN);
+               proto_tree_add_item(temp_tree, hf_data_statb11,     tvb, offset, 2, ENC_BIG_ENDIAN);
+               proto_tree_add_item(temp_tree, hf_data_statb10,     tvb, offset, 2, ENC_BIG_ENDIAN);
+               proto_tree_add_item(temp_tree, hf_data_statb05to04, tvb, offset, 2, ENC_BIG_ENDIAN);
+               proto_tree_add_item(temp_tree, hf_data_statb03to00, tvb, offset, 2, ENC_BIG_ENDIAN);
                offset += 2;
 
                /* PHASORS, (D)FREQ, ANALOG, and DIGITAL */
-               offset = dissect_PHASORS(tvb, block_item, block, offset);
-               offset = dissect_DFREQ  (tvb, block_item, block, offset);
-               offset = dissect_ANALOG (tvb, block_item, block, offset);
-               offset = dissect_DIGITAL(tvb, block_item, block, offset);
+               offset = dissect_PHASORS(tvb, block_tree, block, offset);
+               offset = dissect_DFREQ  (tvb, block_tree, block, offset);
+               offset = dissect_ANALOG (tvb, block_tree, block, offset);
+               offset = dissect_DIGITAL(tvb, block_tree, block, offset);
        }
        return offset;
 } /* dissect_data_frame() */
@@ -860,8 +840,8 @@ static int dissect_command_frame(tvbuff_t    *tvb,
                                 proto_item  *command_item,
                                 packet_info *pinfo)
 {
-       proto_tree *command_tree  = NULL;
-       guint       tvbsize       = tvb_length(tvb);
+       proto_tree *command_tree;
+       guint       tvbsize       = tvb_reported_length(tvb);
        const char *s;
 
        proto_item_set_text(command_item, "Command data");
@@ -877,12 +857,12 @@ static int dissect_command_frame(tvbuff_t    *tvb,
        if (tvbsize > 2) {
                if (tvb_get_ntohs(tvb, 0) == 0x0008) {
                        /* Command: Extended Frame, the extra data is ok */
-                               proto_item* i = proto_tree_add_text(command_tree, tvb, 2, tvbsize - 2, "Extended frame data");
-                               if (tvbsize % 2)
-                                       proto_item_append_text(i, ", but size not multiple of 16-bit word");
+                       proto_item *ti = proto_tree_add_item(command_tree, hf_synphasor_extended_frame_data, tvb, 2, tvbsize - 2, ENC_NA);
+                       if (tvbsize % 2)
+                               expert_add_info(pinfo, ti, &ei_synphasor_extended_frame_data);
                }
                else
-                       proto_tree_add_text(command_tree, tvb, 2, tvbsize - 2, "Unknown data");
+                       proto_tree_add_item(command_tree, hf_synphasor_unknown_data, tvb, 2, tvbsize - 2, ENC_NA);
        }
 
        return tvbsize;
@@ -894,9 +874,9 @@ static int dissect_command_frame(tvbuff_t    *tvb,
 
 /* Dissects a single phasor for 'dissect_PHASORS()' */
 static int dissect_single_phasor(tvbuff_t *tvb, int offset,
-                                       double* mag, double* phase, /* returns the resulting values here */
+                                       double *mag, double *phase, /* returns the resulting values here */
                                        data_format     format,     /* information needed to... */
-                                       phasor_notation_e notation)   /*         ...dissect the phasor  */
+                                       phasor_notation_e notation) /*  ...dissect the phasor   */
 {
        if (floating_point == format) {
                if (polar == notation) {
@@ -938,27 +918,27 @@ static int dissect_single_phasor(tvbuff_t *tvb, int offset,
 /* used by 'dissect_data_frame()' to dissect the PHASORS field */
 static gint dissect_PHASORS(tvbuff_t *tvb, proto_tree *tree, config_block *block, gint offset)
 {
-       proto_item *temp_item   = NULL;
-       proto_tree *phasor_tree = NULL;
+       proto_tree *phasor_tree;
        guint       length;
-       gint        j,
-                   cnt = block->phasors->len; /* number of phasors to dissect */
+       gint        j;
+       gint        cnt = wmem_array_get_count(block->phasors); /* number of phasors to dissect */
 
        if (0 == cnt)
                return offset;
 
-       length      = block->phasors->len * (floating_point == block->format_ph ? 8 : 4);
-       temp_item   = proto_tree_add_text(tree, tvb, offset, length, "Phasors (%u)", cnt);
-       phasor_tree = proto_item_add_subtree(temp_item, ett_data_phasors);
+       length      = wmem_array_get_count(block->phasors) * (floating_point == block->format_ph ? 8 : 4);
+       phasor_tree = proto_tree_add_subtree_format(tree, tvb, offset, length, ett_data_phasors, NULL,
+                                                   "Phasors (%u)", cnt);
 
        /* dissect a phasor for every phasor_info saved in the config_block */
        for (j = 0; j < cnt; j++) {
+               proto_item  *temp_item;
                double       mag, phase;
                phasor_info *pi;
 
-               pi = &g_array_index(block->phasors, phasor_info, j);
-               temp_item = proto_tree_add_text(phasor_tree, tvb, offset,
-                                               floating_point == block->format_ph ? 8 : 4,
+               pi = (phasor_info *)wmem_array_index(block->phasors, j);
+               temp_item = proto_tree_add_string_format(phasor_tree, hf_synphasor_phasor, tvb, offset,
+                                               floating_point == block->format_ph ? 8 : 4, pi->name,
                                                "Phasor #%u: \"%s\"", j + 1, pi->name);
 
                offset += dissect_single_phasor(tvb, offset,
@@ -970,15 +950,13 @@ static gint dissect_PHASORS(tvbuff_t *tvb, proto_tree *tree, config_block *block
                if (integer == block->format_ph)
                        mag = (mag * pi->conv) * 0.00001;
 
-               #define ANGLE  "/_"
-               #define DEGREE "\xC2\xB0" /* DEGREE signs in UTF-8 */
+               #define SYNP_ANGLE  "/_"
 
-               proto_item_append_text(temp_item, ", %10.2f%c" ANGLE "%7.2f" DEGREE,
+               proto_item_append_text(temp_item, ", %10.2f%c" SYNP_ANGLE "%7.2f" UTF8_DEGREE_SIGN,
                                                  mag,
                                                  V == pi->unit ? 'V' : 'A',
                                                  phase *180.0/G_PI);
-               #undef ANGLE
-               #undef DEGREE
+               #undef SYNP_ANGLE
        }
        return offset;
 }
@@ -987,29 +965,26 @@ static gint dissect_PHASORS(tvbuff_t *tvb, proto_tree *tree, config_block *block
 static gint dissect_DFREQ(tvbuff_t *tvb, proto_tree *tree, config_block *block, gint offset)
 {
        if (floating_point == block->format_fr) {
-               gfloat tmp;
-
-               tmp = tvb_get_ntohieee_float(tvb, offset);
-               proto_tree_add_text(tree, tvb, offset, 4, "Actual frequency value: %fHz", tmp); offset += 4;
+               proto_tree_add_item(tree, hf_synphasor_actual_frequency_value, tvb, offset, 4, ENC_BIG_ENDIAN);
+               offset += 4;
 
                /* The standard doesn't clearly say how to interpret this value, but
                 * http://www.pes-psrc.org/h/C37_118_H11_FAQ_Jan2008.pdf provides further information.
                 * --> no scaling factor is applied to DFREQ
                 */
-               tmp = tvb_get_ntohieee_float(tvb, offset);
-               proto_tree_add_text(tree, tvb, offset, 4, "Rate of change of frequency: %fHz/s", tmp); offset += 4;
+               proto_tree_add_item(tree, hf_synphasor_rate_change_frequency, tvb, offset, 4, ENC_BIG_ENDIAN);
+               offset += 4;
        }
        else {
                gint16 tmp;
 
                tmp = tvb_get_ntohs(tvb, offset);
-               proto_tree_add_text(tree, tvb, offset, 2,
-                                   "Frequency deviation from nominal: %" G_GINT16_FORMAT "mHz (actual frequency: %.3fHz)",
-                                   tmp, block->fnom + (tmp / 1000.0));
+               proto_tree_add_int_format_value(tree, hf_synphasor_frequency_deviation_from_nominal, tvb, offset, 2, tmp,
+                                   "%dmHz (actual frequency: %.3fHz)", tmp, block->fnom + (tmp / 1000.0));
                offset += 2;
 
                tmp = tvb_get_ntohs(tvb, offset);
-               proto_tree_add_text(tree, tvb, offset, 2, "Rate of change of frequency: %.3fHz/s", tmp / 100.0); offset += 2;
+               proto_tree_add_float_format_value(tree, hf_synphasor_rate_change_frequency, tvb, offset, 2, (gfloat)(tmp / 100.0), "%.3fHz/s", tmp / 100.0); offset += 2;
        }
        return offset;
 }
@@ -1017,25 +992,24 @@ static gint dissect_DFREQ(tvbuff_t *tvb, proto_tree *tree, config_block *block,
 /* used by 'dissect_data_frame()' to dissect the ANALOG field */
 static gint dissect_ANALOG(tvbuff_t *tvb, proto_tree *tree, config_block *block, gint offset)
 {
-       proto_tree *analog_tree = NULL;
-       proto_item *temp_item   = NULL;
+       proto_tree *analog_tree;
        guint       length;
-       gint        j,
-                   cnt = block->analogs->len; /* number of analog values to dissect */
+       gint        j;
+       gint        cnt = wmem_array_get_count(block->analogs); /* number of analog values to dissect */
 
        if (0 == cnt)
                return offset;
 
-       length      = block->analogs->len * (floating_point == block->format_an ? 4 : 2);
-       temp_item   = proto_tree_add_text(tree, tvb, offset, length, "Analog values (%u)", cnt);
-
-       analog_tree = proto_item_add_subtree(temp_item, ett_data_analog);
+       length      = wmem_array_get_count(block->analogs) * (floating_point == block->format_an ? 4 : 2);
+       analog_tree = proto_tree_add_subtree_format(tree, tvb, offset, length, ett_data_analog, NULL,
+                                                   "Analog values (%u)", cnt);
 
        for (j = 0; j < cnt; j++) {
-               analog_info *ai = &g_array_index(block->analogs, analog_info, j);
+               proto_item *temp_item;
+               analog_info *ai = (analog_info *)wmem_array_index(block->analogs, j);
 
-               temp_item = proto_tree_add_text(analog_tree, tvb, offset,
-                                               floating_point == block->format_an ? 4 : 2,
+               temp_item = proto_tree_add_string_format(analog_tree, hf_synphasor_analog_value, tvb, offset,
+                                               floating_point == block->format_an ? 4 : 2, ai->name,
                                                "Analog value #%u: \"%s\"", j + 1, ai->name);
 
                if (floating_point == block->format_an) {
@@ -1044,7 +1018,7 @@ static gint dissect_ANALOG(tvbuff_t *tvb, proto_tree *tree, config_block *block,
                }
                else {
                        /* the "standard" doesn't say if this is signed or unsigned,
-                        * so I just use gint16, the scaling of the conversation factor
+                        * so I just use gint16; the scaling of the conversation factor
                         * is also "user defined", so I just write it after the analog value */
                        gint16 tmp = tvb_get_ntohs(tvb, offset); offset += 2;
                        proto_item_append_text(temp_item, ", %" G_GINT16_FORMAT " (conversation factor: %#06x)",
@@ -1057,19 +1031,18 @@ static gint dissect_ANALOG(tvbuff_t *tvb, proto_tree *tree, config_block *block,
 /* used by 'dissect_data_frame()' to dissect the DIGITAL field */
 static gint dissect_DIGITAL(tvbuff_t *tvb, proto_tree *tree, config_block *block, gint offset)
 {
-       proto_item *digital_item = NULL;
-       gint        j,
-                   cnt = block->num_dg; /* number of digital status words to dissect */
+       gint        j;
+       gint        cnt = block->num_dg; /* number of digital status words to dissect */
 
        if (0 == cnt)
                return offset;
 
-       digital_item = proto_tree_add_text(tree, tvb, offset, cnt * 2, "Digital status words (%u)", cnt);
-       tree         = proto_item_add_subtree(digital_item, ett_data_digital);
+       tree = proto_tree_add_subtree_format(tree, tvb, offset, cnt * 2, ett_data_digital, NULL,
+                                            "Digital status words (%u)", cnt);
 
        for (j = 0; j < cnt; j++) {
                guint16 tmp = tvb_get_ntohs(tvb, offset);
-               proto_tree_add_text(tree, tvb, offset, 2, "Digital status word #%u: 0x%04x", j + 1, tmp);
+               proto_tree_add_uint_format(tree, hf_synphasor_digital_status_word, tvb, offset, 2, tmp, "Digital status word #%u: 0x%04x", j + 1, tmp);
                offset += 2;
        }
        return offset;
@@ -1082,15 +1055,14 @@ static gint dissect_DIGITAL(tvbuff_t *tvb, proto_tree *tree, config_block *block
 /* used by 'dissect_config_frame()' to dissect the PHUNIT field */
 static gint dissect_PHUNIT(tvbuff_t *tvb, proto_tree *tree, gint offset, gint cnt)
 {
-       proto_item *temp_item = NULL;
-       proto_tree *temp_tree = NULL;
+       proto_tree *temp_tree;
        int i;
 
        if (0 == cnt)
                return offset;
 
-       temp_item = proto_tree_add_text(tree, tvb, offset, 4 * cnt, "Phasor conversation factors (%u)", cnt);
-       temp_tree = proto_item_add_subtree(temp_item, ett_conf_phconv);
+       temp_tree = proto_tree_add_subtree_format(tree, tvb, offset, 4 * cnt, ett_conf_phconv, NULL,
+                                                 "Phasor conversation factors (%u)", cnt);
 
        /* Conversion factor for phasor channels. Four bytes for each phasor.
         * MSB:           0 = voltage, 1 = current
@@ -1098,8 +1070,8 @@ static gint dissect_PHUNIT(tvbuff_t *tvb, proto_tree *tree, gint offset, gint cn
         */
        for (i = 0; i < cnt; i++) {
                guint32 tmp = tvb_get_ntohl(tvb, offset);
-               proto_tree_add_text(temp_tree, tvb, offset, 4,
-                                   "#%u factor: %u * 10^-5, unit: %s",
+               proto_tree_add_uint_format(temp_tree, hf_synphasor_conversion_factor, tvb, offset, 4,
+                                   tmp, "#%u factor: %u * 10^-5, unit: %s",
                                    i + 1,
                                    tmp & 0x00FFFFFF,
                                    tmp & 0xFF000000 ? "Ampere" : "Volt");
@@ -1112,15 +1084,15 @@ static gint dissect_PHUNIT(tvbuff_t *tvb, proto_tree *tree, gint offset, gint cn
 /* used by 'dissect_config_frame()' to dissect the ANUNIT field */
 static gint dissect_ANUNIT(tvbuff_t *tvb, proto_tree *tree, gint offset, gint cnt)
 {
-       proto_item *temp_item = NULL;
-       proto_tree *temp_tree = NULL;
+       proto_item *temp_item;
+       proto_tree *temp_tree;
        int i;
 
        if (0 == cnt)
                return offset;
 
-       temp_item = proto_tree_add_text(tree, tvb, offset, 4 * cnt, "Analog values conversation factors (%u)", cnt);
-       temp_tree = proto_item_add_subtree(temp_item, ett_conf_anconv);
+       temp_tree = proto_tree_add_subtree_format(tree, tvb, offset, 4 * cnt, ett_conf_anconv, NULL,
+                                                 "Analog values conversation factors (%u)", cnt);
 
        /* Conversation factor for analog channels. Four bytes for each analog value.
         * MSB: see 'synphasor_conf_anconvnames' in 'synphasor_strings.c'
@@ -1128,12 +1100,12 @@ static gint dissect_ANUNIT(tvbuff_t *tvb, proto_tree *tree, gint offset, gint cn
         */
        for (i = 0; i < cnt; i++) {
                gint32 tmp = tvb_get_ntohl(tvb, offset);
-               temp_item = proto_tree_add_text(temp_tree, tvb, offset, 4,
-                                               "Factor for analog value #%i: %s",
+               temp_item = proto_tree_add_uint_format(temp_tree, hf_synphasor_factor_for_analog_value, tvb, offset, 4,
+                                               tmp, "Factor for analog value #%i: %s",
                                                i + 1,
                                                try_rval_to_str((tmp >> 24) & 0x000000FF, conf_anconvnames));
 
-                       tmp &= 0x00FFFFFF;
+               tmp &= 0x00FFFFFF;
                if (    tmp &  0x00800000) /* sign bit set */
                        tmp |= 0xFF000000;
 
@@ -1148,26 +1120,24 @@ static gint dissect_ANUNIT(tvbuff_t *tvb, proto_tree *tree, gint offset, gint cn
 /* used by 'dissect_config_frame()' to dissect the DIGUNIT field */
 static gint dissect_DIGUNIT(tvbuff_t *tvb, proto_tree *tree, gint offset, gint cnt)
 {
-       proto_item *temp_item = NULL;
-       proto_tree *temp_tree = NULL;
+       proto_tree *temp_tree, *mask_tree;
        int i;
 
        if (0 == cnt)
                return offset;
 
-       temp_item = proto_tree_add_text(tree, tvb, offset, 4 * cnt, "Masks for digital status words (%u)", cnt);
-       temp_tree = proto_item_add_subtree(temp_item, ett_conf_dgmask);
+       temp_tree = proto_tree_add_subtree_format(tree, tvb, offset, 4 * cnt, ett_conf_dgmask, NULL,
+                                                 "Masks for digital status words (%u)", cnt);
 
        /* Mask words for digital status words. Two 16-bit words for each digital word. The first
-        * inidcates the normal status of the inputs, the second indicated the valid bits in
+        * indicates the normal status of the inputs, the second indicated the valid bits in
         * the status word
         */
        for (i = 0; i < cnt; i++) {
-               guint32 tmp = tvb_get_ntohl(tvb, offset);
 
-               temp_item = proto_tree_add_text(temp_tree, tvb, offset, 4, "Mask for status word #%u: ", i + 1);
-               proto_item_append_text(temp_item, "normal state: 0x%04"G_GINT16_MODIFIER"x", (guint16)((tmp & 0xFFFF0000) >> 16));
-               proto_item_append_text(temp_item, ", valid bits: 0x%04"G_GINT16_MODIFIER"x", (guint16)( tmp & 0x0000FFFF));
+               mask_tree = proto_tree_add_subtree_format(temp_tree, tvb, offset, 4, ett_status_word_mask, NULL, "Mask for status word #%u: ", i + 1);
+               proto_tree_add_item(mask_tree, hf_synphasor_status_word_mask_normal_state, tvb, offset, 4, ENC_BIG_ENDIAN);
+               proto_tree_add_item(mask_tree, hf_synphasor_status_word_mask_valid_bits, tvb, offset, 4, ENC_BIG_ENDIAN);
 
                offset += 4;
        }
@@ -1178,22 +1148,21 @@ static gint dissect_DIGUNIT(tvbuff_t *tvb, proto_tree *tree, gint offset, gint c
 /* used by 'dissect_config_frame()' to dissect the "channel name"-fields */
 static gint dissect_CHNAM(tvbuff_t *tvb, proto_tree *tree, gint offset, gint cnt, const char *prefix)
 {
-       proto_item *temp_item = NULL;
-       proto_tree *temp_tree = NULL;
+       proto_tree *temp_tree;
        int i;
 
        if (0 == cnt)
                return offset;
 
-       temp_item = proto_tree_add_text(tree, tvb, offset, CHNAM_LEN * cnt, "%ss (%u)", prefix, cnt);
-       temp_tree = proto_item_add_subtree(temp_item, ett_conf_phnam);
+       temp_tree = proto_tree_add_subtree_format(tree, tvb, offset, CHNAM_LEN * cnt, ett_conf_phnam, NULL,
+                                                 "%ss (%u)", prefix, cnt);
 
        /* dissect the 'cnt' channel names */
        for (i = 0; i < cnt; i++) {
                char *str;
-               str = tvb_get_ephemeral_string(tvb, offset, CHNAM_LEN);
-               proto_tree_add_text(temp_tree, tvb, offset, CHNAM_LEN,
-                                   "%s #%i: \"%s\"", prefix, i+1, str);
+               str = tvb_get_string_enc(wmem_packet_scope(), tvb, offset, CHNAM_LEN, ENC_ASCII);
+               proto_tree_add_string_format(temp_tree, hf_synphasor_channel_name, tvb, offset, CHNAM_LEN,
+                                   str, "%s #%i: \"%s\"", prefix, i+1, str);
                offset += CHNAM_LEN;
        }
 
@@ -1205,123 +1174,146 @@ void proto_register_synphasor(void)
        static hf_register_info hf[] = {
                /* Sync word */
                { &hf_sync,
-               { "Synchronization word", PROTOCOL_ABBREV ".sync", FT_UINT16, BASE_HEX,
+               { "Synchronization word", "synphasor.sync", FT_UINT16, BASE_HEX,
                  NULL, 0x0, NULL, HFILL }},
-                       /* Flags in the Sync word */
+
+               /* Flags in the Sync word */
                        { &hf_sync_frtype,
-                       { "Frame Type", PROTOCOL_ABBREV ".frtype", FT_UINT16, BASE_HEX,
+                       { "Frame Type", "synphasor.frtype", FT_UINT16, BASE_HEX,
                          VALS(typenames), 0x0070, NULL, HFILL }},
 
                        { &hf_sync_version,
-                       { "Version",    PROTOCOL_ABBREV ".version", FT_UINT16, BASE_DEC,
+                       { "Version",    "synphasor.version", FT_UINT16, BASE_DEC,
                          VALS(versionnames), 0x000F, NULL, HFILL }},
 
                { &hf_frsize,
-               { "Framesize", PROTOCOL_ABBREV ".frsize", FT_UINT16, BASE_DEC,
+               { "Framesize", "synphasor.frsize", FT_UINT16, BASE_DEC,
                  NULL, 0x0, NULL, HFILL }},
 
                { &hf_idcode,
-               { "PMU/DC ID number", PROTOCOL_ABBREV ".idcode", FT_UINT16, BASE_DEC,
+               { "PMU/DC ID number", "synphasor.idcode", FT_UINT16, BASE_DEC,
                  NULL, 0x0, NULL, HFILL }},
 
                { &hf_soc,
-               { "SOC time stamp (UTC)", PROTOCOL_ABBREV ".soc", FT_STRINGZ, BASE_NONE,
+               { "SOC time stamp", "synphasor.soc", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_UTC,
                  NULL, 0x0, NULL, HFILL }},
 
                /* Time quality flags in fracsec */
                { &hf_timeqal_lsdir,
-               { "Leap second direction", PROTOCOL_ABBREV ".timeqal.lsdir", FT_BOOLEAN, 8,
+               { "Leap second direction", "synphasor.timeqal.lsdir", FT_BOOLEAN, 8,
                  NULL, 0x40, NULL, HFILL }},
 
                { &hf_timeqal_lsocc,
-               { "Leap second occurred", PROTOCOL_ABBREV ".timeqal.lsocc", FT_BOOLEAN, 8,
+               { "Leap second occurred", "synphasor.timeqal.lsocc", FT_BOOLEAN, 8,
                  NULL, 0x20, NULL, HFILL }},
 
                { &hf_timeqal_lspend,
-               { "Leap second pending", PROTOCOL_ABBREV ".timeqal.lspend", FT_BOOLEAN, 8,
+               { "Leap second pending", "synphasor.timeqal.lspend", FT_BOOLEAN, 8,
                  NULL, 0x10, NULL, HFILL }},
 
                { &hf_timeqal_timequalindic,
-               { "Time Quality indicator code", PROTOCOL_ABBREV ".timeqal.timequalindic", FT_UINT8, BASE_HEX,
+               { "Time Quality indicator code", "synphasor.timeqal.timequalindic", FT_UINT8, BASE_HEX,
                  VALS(timequalcodes), 0x0F, NULL, HFILL }},
 
                /* Fraction of second */
                { &hf_fracsec,
-               { "Fraction of second (raw)", PROTOCOL_ABBREV ".fracsec", FT_UINT24, BASE_DEC,
+               { "Fraction of second (raw)", "synphasor.fracsec", FT_UINT24, BASE_DEC,
                  NULL, 0x0, NULL, HFILL }},
 
        /* Data types for configuration frames */
                { &hf_conf_timebase,
-               { "Resolution of fractional second time stamp", PROTOCOL_ABBREV ".conf.timebase", FT_UINT24, BASE_DEC,
+               { "Resolution of fractional second time stamp", "synphasor.conf.timebase", FT_UINT24, BASE_DEC,
                  NULL, 0x0, NULL, HFILL }},
 
                { &hf_conf_numpmu,
-               { "Number of PMU blocks included in the frame", PROTOCOL_ABBREV ".conf.numpmu", FT_UINT16, BASE_DEC,
+               { "Number of PMU blocks included in the frame", "synphasor.conf.numpmu", FT_UINT16, BASE_DEC,
                  NULL, 0x0, NULL, HFILL }},
 
                /* Bits in the FORMAT word */
                { &hf_conf_formatb3,
-               { "FREQ/DFREQ format", PROTOCOL_ABBREV ".conf.dfreq_format", FT_BOOLEAN, 16,
+               { "FREQ/DFREQ format", "synphasor.conf.dfreq_format", FT_BOOLEAN, 16,
                  TFS(&conf_formatb123names), 0x8, NULL, HFILL }},
 
                { &hf_conf_formatb2,
-               { "Analog values format", PROTOCOL_ABBREV ".conf.analog_format", FT_BOOLEAN, 16,
+               { "Analog values format", "synphasor.conf.analog_format", FT_BOOLEAN, 16,
                  TFS(&conf_formatb123names), 0x4, NULL, HFILL }},
 
                { &hf_conf_formatb1,
-               { "Phasor format", PROTOCOL_ABBREV ".conf.phasor_format", FT_BOOLEAN, 16,
+               { "Phasor format", "synphasor.conf.phasor_format", FT_BOOLEAN, 16,
                  TFS(&conf_formatb123names), 0x2, NULL, HFILL }},
 
                { &hf_conf_formatb0,
-               { "Phasor notation", PROTOCOL_ABBREV ".conf.phasor_notation", FT_BOOLEAN, 16,
+               { "Phasor notation", "synphasor.conf.phasor_notation", FT_BOOLEAN, 16,
                  TFS(&conf_formatb0names), 0x1, NULL, HFILL }},
 
                { &hf_conf_fnom,
-               { "Nominal line freqency", PROTOCOL_ABBREV ".conf.fnom", FT_BOOLEAN, 16,
+               { "Nominal line frequency", "synphasor.conf.fnom", FT_BOOLEAN, 16,
                  TFS(&conf_fnomnames), 0x0001, NULL, HFILL }},
 
                { &hf_conf_cfgcnt,
-               { "Configuration change count", PROTOCOL_ABBREV ".conf.cfgcnt", FT_UINT16, BASE_DEC,
+               { "Configuration change count", "synphasor.conf.cfgcnt", FT_UINT16, BASE_DEC,
                  NULL, 0, NULL, HFILL }},
 
        /* Data types for data frames */
                /* Flags in the STAT word */
                { &hf_data_statb15,
-               { "Data valid", PROTOCOL_ABBREV ".data.valid", FT_BOOLEAN, 16,
+               { "Data valid", "synphasor.data.valid", FT_BOOLEAN, 16,
                  TFS(&data_statb15names), 0x8000, NULL, HFILL }},
 
                { &hf_data_statb14,
-               { "PMU error", PROTOCOL_ABBREV ".data.PMUerror", FT_BOOLEAN, 16,
+               { "PMU error", "synphasor.data.PMUerror", FT_BOOLEAN, 16,
                  TFS(&data_statb14names), 0x4000, NULL, HFILL }},
 
                { &hf_data_statb13,
-               { "Time synchronized", PROTOCOL_ABBREV ".data.sync", FT_BOOLEAN, 16,
+               { "Time synchronized", "synphasor.data.sync", FT_BOOLEAN, 16,
                  TFS(&data_statb13names), 0x2000, NULL, HFILL }},
 
                { &hf_data_statb12,
-               { "Data sorting", PROTOCOL_ABBREV ".data.sorting", FT_BOOLEAN, 16,
+               { "Data sorting", "synphasor.data.sorting", FT_BOOLEAN, 16,
                  TFS(&data_statb12names), 0x1000, NULL, HFILL }},
 
                { &hf_data_statb11,
-               { "Trigger detected", PROTOCOL_ABBREV ".data.trigger", FT_BOOLEAN, 16,
+               { "Trigger detected", "synphasor.data.trigger", FT_BOOLEAN, 16,
                  TFS(&data_statb11names), 0x0800, NULL, HFILL }},
 
                { &hf_data_statb10,
-               { "Configuration changed", PROTOCOL_ABBREV ".data.CFGchange", FT_BOOLEAN, 16,
+               { "Configuration changed", "synphasor.data.CFGchange", FT_BOOLEAN, 16,
                  TFS(&data_statb10names), 0x0400, NULL, HFILL }},
 
                { &hf_data_statb05to04,
-               { "Unlocked time", PROTOCOL_ABBREV  ".data.t_unlock", FT_UINT16, BASE_HEX,
+               { "Unlocked time", "synphasor.data.t_unlock", FT_UINT16, BASE_HEX,
                  VALS(data_statb05to04names), 0x0030, NULL, HFILL }},
 
                { &hf_data_statb03to00,
-               { "Trigger reason", PROTOCOL_ABBREV  ".data.trigger_reason", FT_UINT16, BASE_HEX,
+               { "Trigger reason", "synphasor.data.trigger_reason", FT_UINT16, BASE_HEX,
                  VALS(data_statb03to00names), 0x000F, NULL, HFILL }},
 
        /* Data type for command frame */
                { &hf_command,
-               { "Command", PROTOCOL_ABBREV ".command", FT_UINT16, BASE_HEX,
-                 VALS(command_names), 0x000F, NULL, HFILL }}
+               { "Command", "synphasor.command", FT_UINT16, BASE_HEX,
+                 VALS(command_names), 0x000F, NULL, HFILL }},
+
+      /* Generated from convert_proto_tree_add_text.pl */
+      { &hf_synphasor_data, { "Data", "synphasor.data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
+      { &hf_synphasor_checksum, { "Checksum", "synphasor.checksum", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
+      { &hf_synphasor_checksum_status, { "Checksum Status", "synphasor.checksum.status", FT_UINT8, BASE_NONE, VALS(proto_checksum_vals), 0x0, NULL, HFILL }},
+      { &hf_synphasor_num_phasors, { "Number of phasors", "synphasor.num_phasors", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
+      { &hf_synphasor_num_analog_values, { "Number of analog values", "synphasor.num_analog_values", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
+      { &hf_synphasor_num_digital_status_words, { "Number of digital status words", "synphasor.num_digital_status_words", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
+      { &hf_synphasor_rate_of_transmission, { "Rate of transmission", "synphasor.rate_of_transmission", FT_INT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
+      { &hf_synphasor_phasor, { "Phasor", "synphasor.phasor", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
+      { &hf_synphasor_actual_frequency_value, { "Actual frequency value", "synphasor.actual_frequency_value", FT_FLOAT, BASE_NONE|BASE_UNIT_STRING, &units_hz, 0x0, NULL, HFILL }},
+      { &hf_synphasor_rate_change_frequency, { "Rate of change of frequency", "synphasor.rate_change_frequency", FT_FLOAT, BASE_NONE|BASE_UNIT_STRING, &units_hz_s, 0x0, NULL, HFILL }},
+      { &hf_synphasor_frequency_deviation_from_nominal, { "Frequency deviation from nominal", "synphasor.frequency_deviation_from_nominal", FT_INT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
+      { &hf_synphasor_analog_value, { "Analog value", "synphasor.analog_value", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
+      { &hf_synphasor_digital_status_word, { "Digital status word", "synphasor.digital_status_word", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
+      { &hf_synphasor_conversion_factor, { "conversion factor", "synphasor.conversion_factor", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }},
+      { &hf_synphasor_factor_for_analog_value, { "Factor for analog value", "synphasor.factor_for_analog_value", FT_UINT32, BASE_DEC, NULL, 0x000000FF, NULL, HFILL }},
+      { &hf_synphasor_channel_name, { "Channel name", "synphasor.channel_name", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
+      { &hf_synphasor_extended_frame_data, { "Extended frame data", "synphasor.extended_frame_data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
+      { &hf_synphasor_unknown_data, { "Unknown data", "synphasor.data.unknown", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
+      { &hf_synphasor_status_word_mask_normal_state, { "Normal state", "synphasor.status_word_mask.normal_state", FT_UINT32, BASE_HEX, NULL, 0xFFFF0000, NULL, HFILL }},
+      { &hf_synphasor_status_word_mask_valid_bits, { "Valid bits", "synphasor.status_word_mask.valid_bits", FT_UINT32, BASE_HEX, NULL, 0x0000FFFF, NULL, HFILL }},
        };
 
        /* protocol subtree array */
@@ -1344,10 +1336,16 @@ void proto_register_synphasor(void)
                &ett_data_phasors,
                &ett_data_analog,
                &ett_data_digital,
-               &ett_command
+               &ett_command,
+               &ett_status_word_mask
+       };
+
+       static ei_register_info ei[] = {
+               { &ei_synphasor_extended_frame_data, { "synphasor.extended_frame_data.unaligned", PI_PROTOCOL, PI_WARN, "Size not multiple of 16-bit word", EXPFILL }},
+               { &ei_synphasor_checksum, { "synphasor.bad_checksum", PI_CHECKSUM, PI_ERROR, "Bad checksum", EXPFILL }},
        };
 
-       module_t *synphasor_module;
+       expert_module_t* expert_synphasor;
 
        /* register protocol */
        proto_synphasor = proto_register_protocol(PROTOCOL_NAME,
@@ -1355,50 +1353,36 @@ void proto_register_synphasor(void)
                                                  PROTOCOL_ABBREV);
 
        /* Registering protocol to be called by another dissector */
-       synphasor_udp_handle = new_register_dissector("synphasor", dissect_udp, proto_synphasor);
+       synphasor_udp_handle = register_dissector("synphasor", dissect_udp, proto_synphasor);
 
        proto_register_field_array(proto_synphasor, hf, array_length(hf));
        proto_register_subtree_array(ett, array_length(ett));
+       expert_synphasor = expert_register_protocol(proto_synphasor);
+       expert_register_field_array(expert_synphasor, ei, array_length(ei));
 
-       /* register preferences */
-       synphasor_module = prefs_register_protocol(proto_synphasor, proto_reg_handoff_synphasor);
-
-       /* the port numbers of the lower level protocols */
-       prefs_register_uint_preference(synphasor_module, "udp_port", "Synchrophasor UDP port",
-                                      "Set the port number for synchrophasor frames over UDP" \
-                                      "(if other than the default of 4713)",
-                                      10, &global_pref_udp_port);
-       prefs_register_uint_preference(synphasor_module, "tcp_port", "Synchrophasor TCP port",
-                                      "Set the port number for synchrophasor frames over TCP" \
-                                      "(if other than the default of 4712)",
-                                      10, &global_pref_tcp_port);
-
-       /* register the initalization routine */
-       register_init_routine(&synphasor_init);
 } /* proto_register_synphasor() */
 
 /* called at startup and when the preferences change */
 void proto_reg_handoff_synphasor(void)
 {
-       static gboolean           initialized = FALSE;
-       static dissector_handle_t synphasor_tcp_handle;
-       static guint              current_udp_port;
-       static guint              current_tcp_port;
-
-       if (!initialized) {
-               synphasor_tcp_handle = new_create_dissector_handle(dissect_tcp, proto_synphasor);
-
-               initialized = TRUE;
-       }
-       else {
-               /* update preferences */
-               dissector_delete_uint("udp.port", current_udp_port, synphasor_udp_handle);
-               dissector_delete_uint("tcp.port", current_tcp_port, synphasor_tcp_handle);
-       }
+       dissector_handle_t synphasor_tcp_handle;
 
-       current_udp_port = global_pref_udp_port;
-       current_tcp_port = global_pref_tcp_port;
+       synphasor_tcp_handle = create_dissector_handle(dissect_tcp, proto_synphasor);
+       dissector_add_for_decode_as("rtacser.data", synphasor_udp_handle);
+       dissector_add_uint_with_preference("udp.port", SYNPHASOR_UDP_PORT, synphasor_udp_handle);
+       dissector_add_uint_with_preference("tcp.port", SYNPHASOR_TCP_PORT, synphasor_tcp_handle);
 
-       dissector_add_uint("udp.port", current_udp_port, synphasor_udp_handle);
-       dissector_add_uint("tcp.port", current_tcp_port, synphasor_tcp_handle);
 } /* proto_reg_handoff_synphasor() */
+
+/*
+ * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
+ *
+ * Local variables:
+ * c-basic-offset: 8
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * End:
+ *
+ * vi: set shiftwidth=8 tabstop=8 noexpandtab:
+ * :indentSize=8:tabSize=8:noTabs=false:
+ */