For proto_tree_add_item(..., proto_xxx, ...)use ENC_NA as the encoding arg.
[obnox/wireshark/wip.git] / epan / dissectors / packet-synphasor.c
index 8f7f85aa33cdf99702c0d4a8f75e3fc4c22c98ad..c6686960965f3b77393375331e5191e59f610b6b 100644 (file)
@@ -30,7 +30,7 @@
 
 #include <glib.h>
 #include <epan/conversation.h>
-#include <epan/crc16.h>
+#include <epan/crc16-tvb.h>
 #include <epan/dissectors/packet-tcp.h>
 #include <epan/packet.h>
 #include <epan/prefs.h>
@@ -49,10 +49,6 @@ void proto_reg_handoff_synphasor(void);
 static int     proto_synphasor  = -1;
 static GSList *config_frame_list = NULL;
 
-#if ! GLIB_CHECK_VERSION(2,10,0)
-static GMemChunk *frame_chunks   = NULL;
-#endif
-
 /* user preferences */
 static guint global_pref_tcp_port = 4712;
 static guint global_pref_udp_port = 4713;
@@ -319,11 +315,7 @@ static config_frame* config_frame_fast(tvbuff_t *tvb)
        config_frame *frame;
 
        /* get a new frame and initialize it */
-#if GLIB_CHECK_VERSION(2,10,0)
        frame = g_slice_new(config_frame);
-#else
-        frame = g_mem_chunk_alloc(frame_chunks);
-#endif
 
        frame->config_blocks = g_array_new(FALSE, TRUE, sizeof(config_block));
 
@@ -437,11 +429,7 @@ static void config_frame_free(config_frame *frame)
        g_array_free(frame->config_blocks, TRUE);
 
        /* and the config_frame */
-#if GLIB_CHECK_VERSION(2,10,0)
        g_slice_free1(sizeof(config_frame), frame);
-#else
-        g_mem_chunk_free(frame_chunks, frame);
-#endif
 }
 
 /* called every time the user loads a capture file or starts to capture */
@@ -456,15 +444,6 @@ static void synphasor_init(void)
                config_frame_list = NULL;
        }
 
-#if ! GLIB_CHECK_VERSION(2,10,0)
-        if (frame_chunks != NULL) {
-            g_mem_chunk_destroy(frame_chunks);
-        }
-        frame_chunks = g_mem_chunk_new("Frame_Chunks",
-                                       sizeof(config_frame),
-                                       10*(sizeof(config_frame)),
-                                       G_ALLOC_AND_FREE);
-#endif
 }
 
 /* the main dissection routine */
@@ -590,7 +569,7 @@ static void dissect_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                guint16  framesize;
                tvbuff_t *sub_tvb;
 
-               temp_item = proto_tree_add_item(tree, proto_synphasor, tvb, 0, -1, FALSE);
+               temp_item = proto_tree_add_item(tree, proto_synphasor, tvb, 0, -1, ENC_NA);
                proto_item_append_text(temp_item, ", %s", val_to_str(frame_type, typenames,
                                                                     ", invalid packet type"));
 
@@ -650,22 +629,22 @@ static gint dissect_header(tvbuff_t *tvb, proto_tree *tree)
        proto_item *temp_item;
 
        gint    offset = 0;
-       guint16 framesize, idcode;
+       guint16 framesize;
 
        /* SYNC and flags */
-       temp_item = proto_tree_add_item(tree, hf_sync, tvb, offset, 2, FALSE);
+       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, FALSE);
-               proto_tree_add_item(temp_tree, hf_sync_version, tvb, offset, 2, FALSE);
+               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 */
-       proto_tree_add_item(tree, hf_frsize, tvb, offset, 2, FALSE);
+       proto_tree_add_item(tree, hf_frsize, tvb, offset, 2, ENC_BIG_ENDIAN);
        framesize = tvb_get_ntohs(tvb, offset); offset += 2;
 
        /* IDCODE */
-       proto_tree_add_item(tree, hf_idcode, tvb, offset, 2, FALSE);
-       idcode = tvb_get_ntohs(tvb, offset); offset += 2;
+       proto_tree_add_item(tree, hf_idcode, tvb, offset, 2, ENC_BIG_ENDIAN);
+       offset += 2;
 
        /* SOC */
        {
@@ -683,13 +662,13 @@ static gint dissect_header(tvbuff_t *tvb, proto_tree *tree)
        /* 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, FALSE);
-               proto_tree_add_item(temp_tree, hf_timeqal_lsocc,         tvb, offset, 1, FALSE);
-               proto_tree_add_item(temp_tree, hf_timeqal_lspend,        tvb, offset, 1, FALSE);
-               proto_tree_add_item(temp_tree, hf_timeqal_timequalindic, tvb, offset, 1, FALSE);
+               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, FALSE); offset += 3;
+       proto_tree_add_item(tree, hf_fracsec,  tvb, offset, 3, ENC_BIG_ENDIAN); offset += 3;
 
        return framesize;
 }
@@ -714,8 +693,8 @@ static int dissect_config_frame(tvbuff_t *tvb, proto_item *config_item)
 
        /* TIME_BASE and NUM_PMU */
        offset += 1; /* skip the reserved byte */
-       proto_tree_add_item(config_tree, hf_conf_timebase, tvb, offset, 3, FALSE); offset += 3;
-       proto_tree_add_item(config_tree, hf_conf_numpmu,   tvb, offset, 2, FALSE);
+       proto_tree_add_item(config_tree, hf_conf_timebase, tvb, offset, 3, ENC_BIG_ENDIAN); offset += 3;
+       proto_tree_add_item(config_tree, hf_conf_numpmu,   tvb, offset, 2, ENC_BIG_ENDIAN);
        /* add number of included PMUs to the text in the list view  */
        num_pmu = tvb_get_ntohs(tvb, offset); offset += 2;
        proto_item_append_text(config_item, ", %"G_GUINT16_FORMAT" PMU(s) included", num_pmu);
@@ -736,15 +715,15 @@ static int dissect_config_frame(tvbuff_t *tvb, proto_item *config_item)
                offset += CHNAM_LEN;
 
                /* IDCODE */
-               proto_tree_add_item(station_tree, hf_idcode, tvb, offset, 2, FALSE); offset += 2;
+               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, FALSE);
-                       proto_tree_add_item(temp_tree, hf_conf_formatb2, tvb, offset, 2, FALSE);
-                       proto_tree_add_item(temp_tree, hf_conf_formatb1, tvb, offset, 2, FALSE);
-                       proto_tree_add_item(temp_tree, hf_conf_formatb0, tvb, offset, 2, FALSE);
+                       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 */
@@ -767,8 +746,8 @@ static int dissect_config_frame(tvbuff_t *tvb, proto_item *config_item)
                offset = dissect_DIGUNIT(tvb, station_tree, offset, num_dg);
 
                /* FNOM and CFGCNT */
-               proto_tree_add_item(station_tree, hf_conf_fnom,   tvb, offset, 2, FALSE); offset += 2;
-               proto_tree_add_item(station_tree, hf_conf_cfgcnt, tvb, offset, 2, FALSE); offset += 2;
+               proto_tree_add_item(station_tree, hf_conf_fnom,   tvb, offset, 2, ENC_BIG_ENDIAN); offset += 2;
+               proto_tree_add_item(station_tree, hf_conf_cfgcnt, tvb, offset, 2, ENC_BIG_ENDIAN); offset += 2;
 
                /* set the correct length for the "Station :" item */
                proto_item_set_len(station_item, offset - oldoffset);
@@ -850,14 +829,14 @@ static int dissect_data_frame(tvbuff_t      *tvb,
                /* 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, FALSE);
-                       proto_tree_add_item(temp_tree, hf_data_statb14,     tvb, offset, 2, FALSE);
-                       proto_tree_add_item(temp_tree, hf_data_statb13,     tvb, offset, 2, FALSE);
-                       proto_tree_add_item(temp_tree, hf_data_statb12,     tvb, offset, 2, FALSE);
-                       proto_tree_add_item(temp_tree, hf_data_statb11,     tvb, offset, 2, FALSE);
-                       proto_tree_add_item(temp_tree, hf_data_statb10,     tvb, offset, 2, FALSE);
-                       proto_tree_add_item(temp_tree, hf_data_statb05to04, tvb, offset, 2, FALSE);
-                       proto_tree_add_item(temp_tree, hf_data_statb03to00, tvb, offset, 2, FALSE);
+                       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 */
@@ -885,7 +864,7 @@ static int dissect_command_frame(tvbuff_t    *tvb,
        command_tree = proto_item_add_subtree(command_item, ett_command);
 
        /* CMD */
-       proto_tree_add_item(command_tree, hf_command, tvb, 0, 2, FALSE);
+       proto_tree_add_item(command_tree, hf_command, tvb, 0, 2, ENC_BIG_ENDIAN);
        if (check_col(pinfo->cinfo, COL_INFO)) {
                const char *s = val_to_str(tvb_get_ntohs(tvb, 0), command_names, "invalid command");
                col_append_str(pinfo->cinfo, COL_INFO, ", ");
@@ -1313,7 +1292,7 @@ void proto_register_synphasor(void)
                  TFS(&data_statb14names), 0x4000, NULL, HFILL }},
 
                { &hf_data_statb13,
-               { "Time syncronized", PROTOCOL_ABBREV ".data.sync", FT_BOOLEAN, 16,
+               { "Time synchronized", PROTOCOL_ABBREV ".data.sync", FT_BOOLEAN, 16,
                  TFS(&data_statb13names), 0x2000, NULL, HFILL }},
 
                { &hf_data_statb12,
@@ -1330,11 +1309,11 @@ void proto_register_synphasor(void)
 
                { &hf_data_statb05to04,
                { "Unlocked time", PROTOCOL_ABBREV  ".data.t_unlock", FT_UINT16, BASE_HEX,
-                 VALS(&data_statb05to04names), 0x0030, NULL, HFILL }},
+                 VALS(data_statb05to04names), 0x0030, NULL, HFILL }},
 
                { &hf_data_statb03to00,
                { "Trigger reason", PROTOCOL_ABBREV  ".data.trigger_reason", FT_UINT16, BASE_HEX,
-                 VALS(&data_statb03to00names), 0x000F, NULL, HFILL }},
+                 VALS(data_statb03to00names), 0x000F, NULL, HFILL }},
 
        /* Data type for command frame */
                { &hf_command,
@@ -1409,14 +1388,13 @@ void proto_reg_handoff_synphasor(void)
        }
        else {
                /* update preferences */
-               dissector_delete("udp.port", current_udp_port, synphasor_udp_handle);
-               dissector_delete("tcp.port", current_tcp_port, synphasor_tcp_handle);
+               dissector_delete_uint("udp.port", current_udp_port, synphasor_udp_handle);
+               dissector_delete_uint("tcp.port", current_tcp_port, synphasor_tcp_handle);
        }
 
        current_udp_port = global_pref_udp_port;
        current_tcp_port = global_pref_tcp_port;
 
-       dissector_add("udp.port", current_udp_port, synphasor_udp_handle);
-       dissector_add("tcp.port", current_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() */
-