[Pkg-running-devel] [openambit] 01/131: Initial commit of wireshark dissector

Christian Perrier bubulle at moszumanska.debian.org
Thu Jul 17 20:19:05 UTC 2014


This is an automated email from the git hooks/post-receive script.

bubulle pushed a commit to branch master
in repository openambit.

commit e4e02e191ef7b25bccdb2c04b1a3afe0ede7a5e1
Author: Emil Ljungdahl <emil at kratern.se>
Date:   Mon Nov 4 21:14:26 2013 +0100

    Initial commit of wireshark dissector
---
 wireshark_dissector/AUTHORS                        |    2 +
 wireshark_dissector/CMakeLists.txt                 |   84 ++
 wireshark_dissector/COPYING                        |   22 +
 wireshark_dissector/ChangeLog                      |    2 +
 wireshark_dissector/INSTALL                        |    9 +
 wireshark_dissector/ambit-dissector.c              | 1047 ++++++++++++++++++++
 wireshark_dissector/cmake/COPYING-CMAKE-SCRIPTS    |   27 +
 wireshark_dissector/cmake/FindGLIB2.cmake          |  238 +++++
 wireshark_dissector/cmake/FindWireshark.cmake      |   28 +
 .../cmake/UseMakeDissectorReg.cmake                |   33 +
 wireshark_dissector/moduleinfo.h                   |   17 +
 wireshark_dissector/tools/make-dissector-reg       |  186 ++++
 wireshark_dissector/tools/make-dissector-reg.py    |  305 ++++++
 13 files changed, 2000 insertions(+)

diff --git a/wireshark_dissector/AUTHORS b/wireshark_dissector/AUTHORS
new file mode 100644
index 0000000..c6b30e1
--- /dev/null
+++ b/wireshark_dissector/AUTHORS
@@ -0,0 +1,2 @@
+Author:
+Emil Ljungdahl <emil at kratern.se>
diff --git a/wireshark_dissector/CMakeLists.txt b/wireshark_dissector/CMakeLists.txt
new file mode 100644
index 0000000..d6061aa
--- /dev/null
+++ b/wireshark_dissector/CMakeLists.txt
@@ -0,0 +1,84 @@
+# CMakeLists.txt
+#
+# $Id: CMakeLists.txt 31995 2010-02-24 22:32:10Z jmayer $
+#
+# Wireshark - Network traffic analyzer
+# By Gerald Combs <gerald at wireshark.org>
+# Copyright 1998 Gerald Combs
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#
+
+project(ambit-wireshark-plugin C)
+
+cmake_minimum_required(VERSION 2.6)
+set(CMAKE_BACKWARDS_COMPATIBILITY 2.6)
+set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
+set(CMAKE_INSTALL_LIBDIR ~/.wireshark)
+
+INCLUDE(UseMakeDissectorReg)
+  
+set(GLIB2_MIN_VERSION 2.4.0)
+
+find_package(GLIB2)
+include_directories (${GLIB2_INCLUDE_DIRS})
+
+find_package(Wireshark)
+include_directories (${WIRESHARK_INCLUDE_DIRS})
+
+set(LINK_MODE_LIB SHARED)
+set(LINK_MODE_MODULE MODULE)
+
+
+set(DISSECTOR_SRC
+	ambit-dissector.c
+)
+
+set(PLUGIN_FILES
+	plugin.c
+	${DISSECTOR_SRC}
+)
+
+set(CLEAN_FILES
+	${PLUGIN_FILES}
+)
+
+if (WERROR)
+	set_source_files_properties(
+		${CLEAN_FILES}
+		PROPERTIES
+		COMPILE_FLAGS -Werror
+	)
+endif()
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+
+register_dissector_files(plugin.c
+	plugin
+	${DISSECTOR_SRC}
+)
+
+add_library(ambit ${LINK_MODE_MODULE}
+	${PLUGIN_FILES}
+)
+set_target_properties(ambit PROPERTIES PREFIX "")
+set_target_properties(ambit PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
+
+target_link_libraries(ambit ${WIRESHARK_LIBRARIES})
+
+install(TARGETS ambit
+	LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/plugins NAMELINK_SKIP
+)
+
diff --git a/wireshark_dissector/COPYING b/wireshark_dissector/COPYING
new file mode 100644
index 0000000..53b6b71
--- /dev/null
+++ b/wireshark_dissector/COPYING
@@ -0,0 +1,22 @@
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+1. Redistributions of source code must retain the copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+3. The name of the author may not be used to endorse or promote products
+   derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/wireshark_dissector/ChangeLog b/wireshark_dissector/ChangeLog
new file mode 100644
index 0000000..429dc64
--- /dev/null
+++ b/wireshark_dissector/ChangeLog
@@ -0,0 +1,2 @@
+2013-11-04
+First version of the (Suunto Ambit 2) dissector plugin for wireshark
diff --git a/wireshark_dissector/INSTALL b/wireshark_dissector/INSTALL
new file mode 100644
index 0000000..ff62ac2
--- /dev/null
+++ b/wireshark_dissector/INSTALL
@@ -0,0 +1,9 @@
+This wireshark plugin is built with cmake (in a separate build/ directory):
+  mkdir build
+  cd build
+  cmake ..
+  make
+  make install
+
+This will build the .so plugin for wireshark and install it into the user's 
+~/.wireshark/plugins/ directory, where wireshark will load plugins from.
diff --git a/wireshark_dissector/ambit-dissector.c b/wireshark_dissector/ambit-dissector.c
new file mode 100644
index 0000000..43e5b53
--- /dev/null
+++ b/wireshark_dissector/ambit-dissector.c
@@ -0,0 +1,1047 @@
+#include "config.h"
+
+#include <glib.h>
+#include <epan/conversation.h>
+#include <epan/expert.h>
+#include <epan/packet.h>
+#include <epan/reassemble.h>
+#include <epan/dissectors/packet-usb.h>
+
+typedef struct ambit_reassembly_entry {
+    guint8 valid;
+    guint32 command;
+    guint32 start_frame;
+    guint32 frame_count;
+    guint32 size;
+    unsigned char *data;
+} ambit_reassembly_entry_t;
+
+typedef struct ambit_protocol_type {
+    guint32 command;
+    char *name;
+    gint (*dissector)(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_);
+} ambit_protocol_type_t;
+
+static const ambit_protocol_type_t *find_subdissector(guint32 command);
+static gint dissect_ambit_date_write(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_);
+static gint dissect_ambit_date_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_);
+static gint dissect_ambit_time_write(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_);
+static gint dissect_ambit_time_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_);
+static gint dissect_ambit_status_get(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_);
+static gint dissect_ambit_status_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_);
+static gint dissect_ambit_device_info_get(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_);
+static gint dissect_ambit_device_info_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_);
+static gint dissect_ambit_personal_settings_get(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_);
+static gint dissect_ambit_personal_settings_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_);
+static gint dissect_ambit_log_header_get(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_);
+static gint dissect_ambit_log_header_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_);
+static gint dissect_ambit_log_header_unwind_get(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_);
+static gint dissect_ambit_log_header_unwind_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_);
+static gint dissect_ambit_log_header_next_get(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_);
+static gint dissect_ambit_log_header_next_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_);
+static gint dissect_ambit_log_data_get(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_);
+static gint dissect_ambit_log_data_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_);
+
+/* protocols and header fields */
+#define D_AMBIT_USBID 0x3f
+static int proto_ambit = -1;
+static int hf_ambit_usbid = -1;
+static int hf_ambit_usblength = -1;
+static int hf_ambit_msgpart = -1;
+static int hf_ambit_msglength = -1;
+static int hf_ambit_msgsegs = -1;
+static int hf_ambit_msgseg = -1;
+static int hf_ambit_msgheaderchksum = -1;
+static int hf_ambit_requestcmd = -1;
+static int hf_ambit_pktseqno = -1;
+static int hf_ambit_pktlen = -1;
+static int hf_ambit_payloadchksum = -1;
+
+static int hf_ambit_unknown = -1;
+
+static int hf_ambit_date = -1;
+static int hf_ambit_time = -1;
+static int hf_ambit_charge = -1;
+static int hf_ambit_model = -1;
+static int hf_ambit_serial = -1;
+static int hf_ambit_fw_version = -1;
+static int hf_ambit_hw_version = -1;
+static int hf_ambit_personal_compass_declination = -1;
+static int hf_ambit_personal_map_orientation = -1;
+static int hf_ambit_personal_date_format = -1;
+static int hf_ambit_personal_time_format = -1;
+static int hf_ambit_personal_coordinate_system = -1;
+static int hf_ambit_personal_unit_system = -1;
+static int hf_ambit_personal_alarm_enable = -1;
+static int hf_ambit_personal_alarm_time = -1;
+static int hf_ambit_personal_dual_time = -1;
+static int hf_ambit_personal_gps_sync_time = -1;
+static int hf_ambit_personal_weight = -1;
+static int hf_ambit_personal_max_hb = -1;
+static int hf_ambit_personal_rest_hb = -1;
+static int hf_ambit_personal_birthyear = -1;
+static int hf_ambit_personal_length = -1;
+static int hf_ambit_personal_sex = -1;
+static int hf_ambit_personal_fitness_level = -1;
+static int hf_ambit_personal_alti_baro_fused_alti = -1;
+static int hf_ambit_personal_alti_baro_profile = -1;
+static int hf_ambit_personal_backlight_brightness = -1;
+static int hf_ambit_personal_backlight_mode = -1;
+static int hf_ambit_personal_display_contrast = -1;
+static int hf_ambit_personal_invert_display = -1;
+static int hf_ambit_personal_lock_sports_mode = -1;
+static int hf_ambit_personal_lock_time_mode = -1;
+static int hf_ambit_personal_tones = -1;
+
+static int hf_ambit_log_header_seq = -1;
+static int hf_ambit_log_header_length = -1;
+static int hf_ambit_log_header_sample_desc = -1;
+static int hf_ambit_log_header_date = -1;
+static int hf_ambit_log_header_time = -1;
+static int hf_ambit_log_header_duration = -1;
+static int hf_ambit_log_header_ascent = -1;
+static int hf_ambit_log_header_descent = -1;
+static int hf_ambit_log_header_ascent_time = -1;
+static int hf_ambit_log_header_descent_time = -1;
+static int hf_ambit_log_header_recovery = -1;
+static int hf_ambit_log_header_avg_speed = -1;
+static int hf_ambit_log_header_max_speed = -1;
+static int hf_ambit_log_header_altitude_max = -1;
+static int hf_ambit_log_header_altitude_min = -1;
+static int hf_ambit_log_header_hr_avg = -1;
+static int hf_ambit_log_header_hr_max = -1;
+static int hf_ambit_log_header_peak_effect = -1;
+static int hf_ambit_log_header_activity_type = -1;
+static int hf_ambit_log_header_activity_name = -1;
+static int hf_ambit_log_header_hr_min = -1;
+static int hf_ambit_log_header_distance = -1;
+static int hf_ambit_log_header_sample_count = -1;
+static int hf_ambit_log_header_energy = -1;
+static int hf_ambit_log_header_speed_max_time = -1;
+static int hf_ambit_log_header_alt_max_time = -1;
+static int hf_ambit_log_header_alt_min_time = -1;
+static int hf_ambit_log_header_hr_max_time = -1;
+static int hf_ambit_log_header_hr_min_time = -1;
+static int hf_ambit_log_header_temp_max_time = -1;
+static int hf_ambit_log_header_temp_min_time = -1;
+static int hf_ambit_log_header_time_first_fix = -1;
+static int hf_ambit_log_header_battery_start = -1;
+static int hf_ambit_log_header_battery_stop = -1;
+static int hf_ambit_log_header_distance_before_calib = -1;
+
+static int hf_ambit_log_header_more = -1;
+
+static int hf_ambit_log_data_address = -1;
+static int hf_ambit_log_data_length = -1;
+static int hf_ambit_log_data_sof = -1;
+static int hf_ambit_log_data_first_addr = -1;
+static int hf_ambit_log_data_last_addr = -1;
+static int hf_ambit_log_data_entry_count = -1;
+static int hf_ambit_log_data_next_free_addr = -1;
+static int hf_ambit_log_data_next_addr = -1;
+static int hf_ambit_log_data_prev_addr = -1;
+
+static gint ett_ambit = -1;
+static gint ett_ambit_data = -1;
+
+static expert_field ei_ambit_undecoded= EI_INIT;
+
+static ambit_reassembly_entry_t *reassembly_entries = NULL;
+static guint32 reassembly_entries_alloc = 0;
+
+static const value_string msgpart_index_vals[] = {
+    { 0x5d, "First part" },
+    { 0x5e, "Following part" },
+    { 0, NULL }
+};
+
+static const value_string log_header_more_vals[] = {
+    { 0x00000400, "More entries" },
+    { 0x00000c00, "No more entries" },
+    { 0, NULL }
+};
+
+static const ambit_protocol_type_t subdissectors[] = {
+    { 0x03000500, "Set time", dissect_ambit_time_write },
+    { 0x03000a00, "Time reply", dissect_ambit_time_reply },
+    { 0x03020500, "Set date", dissect_ambit_date_write },
+    { 0x03020a00, "Date reply", dissect_ambit_date_reply },
+    { 0x03060500, "Get device status", dissect_ambit_status_get },
+    { 0x03060a00, "Device status reply", dissect_ambit_status_reply },
+    { 0x00000100, "Get device info", dissect_ambit_device_info_get },
+    { 0x00020200, "Device info reply", dissect_ambit_device_info_reply },
+    { 0x0b000500, "Get personal settings", dissect_ambit_personal_settings_get },
+    { 0x0b000a00, "Personal settings reply", dissect_ambit_personal_settings_reply },
+    { 0x0b010500, "Write personal settings", dissect_ambit_personal_settings_reply },
+    { 0x0b010a00, "Personal settings write reply", dissect_ambit_personal_settings_get },
+    { 0x0b070500, "Log header unwind request", dissect_ambit_log_header_unwind_get },
+    { 0x0b070a00, "Log header unwind reply", dissect_ambit_log_header_unwind_reply },
+    { 0x0b080500, "Log header next request", dissect_ambit_log_header_next_get },
+    { 0x0b080a00, "Log header next reply", dissect_ambit_log_header_next_reply },
+    { 0x0b0b0500, "Get log header", dissect_ambit_log_header_get },
+    { 0x0b0b0a00, "Log header reply", dissect_ambit_log_header_reply },
+    { 0x0b170500, "Get log data", dissect_ambit_log_data_get },
+    { 0x0b170a00, "Log data reply", dissect_ambit_log_data_reply },
+    { 0, NULL, NULL }
+};
+
+static const ambit_protocol_type_t *find_subdissector(guint32 command)
+{
+    int i = 0;
+    const ambit_protocol_type_t *entry = &subdissectors[i++];
+
+    while (entry->command != 0) {
+        if (entry->command == command) {
+            return entry;
+        }
+        entry = &subdissectors[i++];
+    }
+
+    return NULL;
+}
+
+static void dissect_ambit_add_unknown(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset, gint len)
+{
+    proto_item *unknown_item = NULL;
+    unknown_item = proto_tree_add_item(tree, hf_ambit_unknown, tvb, offset, len, ENC_LITTLE_ENDIAN);
+    expert_add_info(pinfo, unknown_item, &ei_ambit_undecoded);
+}
+
+static gint dissect_ambit_date_write(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
+{
+    gint offset = 0;
+    guint16 year = tvb_get_letohs(tvb, 0);
+    guint8 month = tvb_get_guint8(tvb, 2);
+    guint8 day = tvb_get_guint8(tvb, 3);
+    proto_tree_add_string_format_value(tree, hf_ambit_date, tvb, offset, 4, "Date", "%04d-%02d-%02d", year, month, day);
+    offset += 4;
+    dissect_ambit_add_unknown(tvb, pinfo, tree, offset, 4);
+    offset += 4;
+}
+
+static gint dissect_ambit_date_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
+{
+}
+
+static gint dissect_ambit_time_write(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
+{
+    gint offset = 0;
+    guint8 hour = tvb_get_guint8(tvb, 4);
+    guint8 minute = tvb_get_guint8(tvb, 5);
+    guint16 seconds = tvb_get_letohs(tvb, 6) / 1000;
+    dissect_ambit_add_unknown(tvb, pinfo, tree, offset, 4);
+    offset += 4;
+    proto_tree_add_string_format_value(tree, hf_ambit_time, tvb, offset, 4, "Time", "%02d:%02d:%02d", hour, minute, seconds);
+    offset += 4;
+}
+
+static gint dissect_ambit_time_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
+{
+}
+
+static gint dissect_ambit_status_get(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
+{
+}
+
+static gint dissect_ambit_status_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
+{
+    gint offset = 0;
+    dissect_ambit_add_unknown(tvb, pinfo, tree, offset, 1);
+    offset += 1;
+    proto_tree_add_item(tree, hf_ambit_charge, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+    offset += 1;
+    dissect_ambit_add_unknown(tvb, pinfo, tree, offset, 1);
+    offset += 1;
+    dissect_ambit_add_unknown(tvb, pinfo, tree, offset, 1);
+    offset += 1;
+}
+
+static gint dissect_ambit_device_info_get(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
+{
+}
+
+static gint dissect_ambit_device_info_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
+{
+    guint8 fw1,fw2,fw3;
+    guint8 hw1,hw2;
+    guint16 hw3;
+    gint offset = 0;
+    proto_tree_add_item(tree, hf_ambit_model, tvb, offset, 16, ENC_LITTLE_ENDIAN);
+    offset += 16;
+    proto_tree_add_item(tree, hf_ambit_serial, tvb, offset, 16, ENC_LITTLE_ENDIAN);
+    offset += 16;
+    fw1 = tvb_get_guint8(tvb, offset);
+    fw2 = tvb_get_guint8(tvb, offset+1);
+    fw3 = tvb_get_guint8(tvb, offset+2);
+    proto_tree_add_string_format_value(tree, hf_ambit_fw_version, tvb, offset, 3, "FW version", "%d.%d.%d", fw1, fw2, fw3);
+    offset += 3;
+    offset += 1;
+    hw1 = tvb_get_guint8(tvb, offset);
+    hw2 = tvb_get_guint8(tvb, offset+1);
+    hw3 = tvb_get_letohs(tvb, offset+2);
+    proto_tree_add_string_format_value(tree, hf_ambit_hw_version, tvb, offset, 4, "HW version", "%d.%d.%d", hw1, hw2, hw3);
+    offset += 4;
+    dissect_ambit_add_unknown(tvb, pinfo, tree, offset, 8);
+    offset += 8;
+}
+
+static gint dissect_ambit_personal_settings_get(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
+{
+}
+
+static gint dissect_ambit_personal_settings_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
+{
+    gint offset = 1;
+    proto_tree_add_item(tree, hf_ambit_personal_lock_sports_mode, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+    offset = 2;
+    proto_tree_add_item(tree, hf_ambit_personal_lock_time_mode, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+    offset = 4;
+    guint8 declination_direction = tvb_get_guint8(tvb, offset);
+    guint8 declination_deg = tvb_get_guint8(tvb, offset + 1);
+    if (declination_direction == 0) {
+        proto_tree_add_string_format_value(tree, hf_ambit_personal_compass_declination, tvb, offset, 2, "Compass declination", "None");
+    }
+    else {
+        proto_tree_add_string_format_value(tree, hf_ambit_personal_compass_declination, tvb, offset, 2, "Compass declination", "%s %f", declination_direction == 1 ? "E" : "W", 0.5*declination_deg);
+    }
+    offset = 8;
+    proto_tree_add_item(tree, hf_ambit_personal_unit_system, tvb, offset, 8, ENC_LITTLE_ENDIAN);
+    offset = 19;
+    proto_tree_add_item(tree, hf_ambit_personal_coordinate_system, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+    offset = 21;
+    proto_tree_add_item(tree, hf_ambit_personal_map_orientation, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+    offset = 24;
+    proto_tree_add_item(tree, hf_ambit_personal_gps_sync_time, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+    offset = 25;
+    proto_tree_add_item(tree, hf_ambit_personal_time_format, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+    offset = 26;
+    guint8 alarm_hour = tvb_get_guint8(tvb, offset);
+    guint8 alarm_minute = tvb_get_guint8(tvb, offset + 1);
+    proto_tree_add_string_format_value(tree, hf_ambit_personal_alarm_time, tvb, offset, 2, "Alarm time", "%d:%d", alarm_hour, alarm_minute);
+    offset = 28;
+    proto_tree_add_item(tree, hf_ambit_personal_alarm_enable, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+    offset = 31;
+    guint8 dual_hour = tvb_get_guint8(tvb, offset);
+    guint8 dual_minute = tvb_get_guint8(tvb, offset + 1);
+    proto_tree_add_string_format_value(tree, hf_ambit_personal_dual_time, tvb, offset, 2, "Dual time", "%d:%d", dual_hour, dual_minute);
+    offset = 36;
+    proto_tree_add_item(tree, hf_ambit_personal_date_format, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+    offset = 40;
+    proto_tree_add_item(tree, hf_ambit_personal_tones, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+    offset = 44;
+    proto_tree_add_item(tree, hf_ambit_personal_backlight_mode, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+    offset = 45;
+    proto_tree_add_item(tree, hf_ambit_personal_backlight_brightness, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+    offset = 46;
+    proto_tree_add_item(tree, hf_ambit_personal_display_contrast, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+    offset = 47;
+    proto_tree_add_item(tree, hf_ambit_personal_invert_display, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+    offset = 48;
+    guint16 weight = tvb_get_letohs(tvb, offset);
+    proto_tree_add_float(tree, hf_ambit_personal_weight, tvb, offset, 2, ((float)weight)/100);
+    offset = 50;
+    proto_tree_add_item(tree, hf_ambit_personal_birthyear, tvb, offset, 2, ENC_LITTLE_ENDIAN); 
+    offset = 52;
+    proto_tree_add_item(tree, hf_ambit_personal_max_hb, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+    offset = 53;
+    proto_tree_add_item(tree, hf_ambit_personal_rest_hb, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+    offset = 54;
+    proto_tree_add_item(tree, hf_ambit_personal_fitness_level, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+    offset = 55;
+    guint8 sex = tvb_get_guint8(tvb, offset);
+    proto_tree_add_string_format_value(tree, hf_ambit_personal_sex, tvb, offset, 1, "Is male", "%s", sex == 1 ? "true" : "false");
+    offset = 56;
+    proto_tree_add_item(tree, hf_ambit_personal_length, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+    offset = 60;
+    proto_tree_add_item(tree, hf_ambit_personal_alti_baro_profile, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+    offset = 62;
+    proto_tree_add_item(tree, hf_ambit_personal_alti_baro_fused_alti, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+}
+
+static gint dissect_ambit_log_header_get(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
+{
+}
+
+static gint dissect_ambit_log_header_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
+{
+    gint offset = 0;
+    guint16 msg_id = tvb_get_letohs(tvb, 2);
+    guint32 datalen = tvb_get_letohl(tvb, 4);
+
+    dissect_ambit_add_unknown(tvb, pinfo, tree, offset, 2);
+    offset += 2;
+    proto_tree_add_item(tree, hf_ambit_log_header_seq, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+    offset += 2;
+    proto_tree_add_item(tree, hf_ambit_log_header_length, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+    offset += 4;
+    if (msg_id == 1) {
+        proto_tree_add_item(tree, hf_ambit_log_header_sample_desc, tvb, offset, datalen, ENC_LITTLE_ENDIAN);
+    }
+    else if (msg_id == 2) {
+        dissect_ambit_add_unknown(tvb, pinfo, tree, offset, 1);
+        offset += 1;
+        guint16 year = tvb_get_letohs(tvb, offset);
+        guint8 month = tvb_get_guint8(tvb, offset + 2);
+        guint8 day = tvb_get_guint8(tvb, offset + 3);
+        proto_tree_add_string_format_value(tree, hf_ambit_log_header_date, tvb, offset, 4, "Date", "%04d-%02d-%02d", year, month, day);
+        offset += 4;
+        guint8 hour = tvb_get_guint8(tvb, offset);
+        guint8 minute = tvb_get_guint8(tvb, offset + 1);
+        guint16 seconds = tvb_get_guint8(tvb, offset + 1);
+        proto_tree_add_string_format_value(tree, hf_ambit_log_header_time, tvb, offset, 3, "Time", "%02d:%02d:%02d", hour, minute, seconds);
+        offset += 3;
+        dissect_ambit_add_unknown(tvb, pinfo, tree, offset, 5);
+        offset += 5;
+        proto_tree_add_item(tree, hf_ambit_log_header_duration, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+        offset += 4;
+        proto_tree_add_item(tree, hf_ambit_log_header_ascent, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+        offset += 2;
+        proto_tree_add_item(tree, hf_ambit_log_header_descent, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+        offset += 2;
+        proto_tree_add_item(tree, hf_ambit_log_header_ascent_time, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+        offset += 4;
+        proto_tree_add_item(tree, hf_ambit_log_header_descent_time, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+        offset += 4;
+        proto_tree_add_item(tree, hf_ambit_log_header_recovery, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+        offset += 2;
+        proto_tree_add_item(tree, hf_ambit_log_header_avg_speed, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+        offset += 2;
+        proto_tree_add_item(tree, hf_ambit_log_header_max_speed, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+        offset += 2;
+        proto_tree_add_item(tree, hf_ambit_log_header_altitude_max, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+        offset += 2;
+        proto_tree_add_item(tree, hf_ambit_log_header_altitude_min, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+        offset += 2;
+        proto_tree_add_item(tree, hf_ambit_log_header_hr_avg, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+        offset += 1;
+        proto_tree_add_item(tree, hf_ambit_log_header_hr_max, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+        offset += 1;
+        proto_tree_add_item(tree, hf_ambit_log_header_peak_effect, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+        offset += 1;
+        proto_tree_add_item(tree, hf_ambit_log_header_activity_type, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+        offset += 1;
+        proto_tree_add_item(tree, hf_ambit_log_header_activity_name, tvb, offset, 16, ENC_LITTLE_ENDIAN);
+        offset += 16;
+        proto_tree_add_item(tree, hf_ambit_log_header_hr_min, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+        offset += 1;
+        dissect_ambit_add_unknown(tvb, pinfo, tree, offset, 5);
+        offset += 5;
+        proto_tree_add_item(tree, hf_ambit_log_header_distance, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+        offset += 4;
+        proto_tree_add_item(tree, hf_ambit_log_header_sample_count, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+        offset += 4;
+        proto_tree_add_item(tree, hf_ambit_log_header_energy, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+        offset += 4;
+        dissect_ambit_add_unknown(tvb, pinfo, tree, offset, 4);
+        offset += 4;
+        proto_tree_add_item(tree, hf_ambit_log_header_speed_max_time, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+        offset += 4;
+        proto_tree_add_item(tree, hf_ambit_log_header_alt_max_time, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+        offset += 4;
+        proto_tree_add_item(tree, hf_ambit_log_header_alt_min_time, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+        offset += 4;
+        proto_tree_add_item(tree, hf_ambit_log_header_hr_max_time, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+        offset += 4;
+        proto_tree_add_item(tree, hf_ambit_log_header_hr_min_time, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+        offset += 4;
+        proto_tree_add_item(tree, hf_ambit_log_header_temp_max_time, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+        offset += 4;
+        proto_tree_add_item(tree, hf_ambit_log_header_temp_min_time, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+        offset += 4;
+        dissect_ambit_add_unknown(tvb, pinfo, tree, offset, 8);
+        offset += 8;
+        proto_tree_add_item(tree, hf_ambit_log_header_time_first_fix, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+        offset += 2;
+        proto_tree_add_item(tree, hf_ambit_log_header_battery_start, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+        offset += 1;
+        proto_tree_add_item(tree, hf_ambit_log_header_battery_stop, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+        offset += 1;
+        dissect_ambit_add_unknown(tvb, pinfo, tree, offset, 4);
+        offset += 4;
+        proto_tree_add_item(tree, hf_ambit_log_header_distance_before_calib, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+        offset += 4;
+    }
+}
+
+static gint dissect_ambit_log_header_unwind_get(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
+{
+}
+
+static gint dissect_ambit_log_header_unwind_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
+{
+    proto_tree_add_item(tree, hf_ambit_log_header_more, tvb, 0, 4, ENC_LITTLE_ENDIAN);
+}
+
+static gint dissect_ambit_log_header_next_get(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
+{
+}
+
+static gint dissect_ambit_log_header_next_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
+{
+    proto_tree_add_item(tree, hf_ambit_log_header_more, tvb, 0, 4, ENC_LITTLE_ENDIAN);
+}
+
+static gint dissect_ambit_log_data_get(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
+{
+    gint offset = 0;
+    proto_tree_add_item(tree, hf_ambit_log_data_address, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+    offset += 4;
+    proto_tree_add_item(tree, hf_ambit_log_data_length, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+    offset += 4;
+}
+
+static gint dissect_ambit_log_data_reply(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
+{
+    gint offset = 0;
+    guint32 address = tvb_get_letohl(tvb, 0);
+    guint32 length = tvb_get_letohl(tvb, 4);
+    gint pmem_offset = -1;
+    guint16 header_1_len;
+
+    proto_tree_add_item(tree, hf_ambit_log_data_address, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+    offset += 4;
+    proto_tree_add_item(tree, hf_ambit_log_data_length, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+    offset += 4;
+
+    if (address == 0x000f4240) {
+        /* Known start address, then we know a bit about the header... */
+        proto_tree_add_item(tree, hf_ambit_log_data_last_addr, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+        offset += 4;
+        proto_tree_add_item(tree, hf_ambit_log_data_first_addr, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+        offset += 4;
+        proto_tree_add_item(tree, hf_ambit_log_data_entry_count, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+        offset += 4;
+        proto_tree_add_item(tree, hf_ambit_log_data_next_free_addr, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+        offset += 4;
+    }
+
+    // Loop through data to find PEM start
+    int i;
+    guint8 a,b,c,d;
+    for(i=0; i<length; i++) {
+        if((a = tvb_get_guint8(tvb, i)) == 'P') {
+            b = tvb_get_guint8(tvb, i+1);
+            c = tvb_get_guint8(tvb, i+2);
+            d = tvb_get_guint8(tvb, i+3);
+
+            if (b == 'M' && c == 'E' && d == 'M') {
+                offset = i;
+                proto_tree_add_item(tree, hf_ambit_log_data_sof, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+                offset += 4;
+                if (offset + 4 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_data_next_addr, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+                offset += 4;
+                if (offset + 4 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_data_prev_addr, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+                offset += 4;
+                if (offset + 2 >= length) break;
+                header_1_len = tvb_get_letohs(tvb, offset);
+                proto_tree_add_item(tree, hf_ambit_log_header_length, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+                offset += 2;
+                if (offset + header_1_len >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_sample_desc, tvb, offset, header_1_len, ENC_LITTLE_ENDIAN);
+                offset += header_1_len;
+                if (offset + 2 >= length) break;
+                header_1_len = tvb_get_letohs(tvb, offset);
+                proto_tree_add_item(tree, hf_ambit_log_header_length, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+                offset += 2;
+
+                if (offset + 1 >= length) break;
+                dissect_ambit_add_unknown(tvb, pinfo, tree, offset, 1);
+                offset += 1;
+                if (offset + 4 >= length) break;
+                guint16 year = tvb_get_letohs(tvb, offset);
+                guint8 month = tvb_get_guint8(tvb, offset + 2);
+                guint8 day = tvb_get_guint8(tvb, offset + 3);
+                proto_tree_add_string_format_value(tree, hf_ambit_log_header_date, tvb, offset, 4, "Date", "%04d-%02d-%02d", year, month, day);
+                offset += 4;
+                if (offset + 3 >= length) break;
+                guint8 hour = tvb_get_guint8(tvb, offset);
+                guint8 minute = tvb_get_guint8(tvb, offset + 1);
+                guint16 seconds = tvb_get_guint8(tvb, offset + 1);
+                proto_tree_add_string_format_value(tree, hf_ambit_log_header_time, tvb, offset, 3, "Time", "%02d:%02d:%02d", hour, minute, seconds);
+                offset += 3;
+                if (offset + 5 >= length) break;
+                dissect_ambit_add_unknown(tvb, pinfo, tree, offset, 5);
+                offset += 5;
+                if (offset + 4 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_duration, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+                offset += 4;
+                if (offset + 2 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_ascent, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+                offset += 2;
+                if (offset + 2 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_descent, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+                offset += 2;
+                if (offset + 4 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_ascent_time, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+                offset += 4;
+                if (offset + 4 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_descent_time, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+                offset += 4;
+                if (offset + 2 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_recovery, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+                offset += 2;
+                if (offset + 2 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_avg_speed, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+                offset += 2;
+                if (offset + 2 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_max_speed, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+                offset += 2;
+                if (offset + 2 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_altitude_max, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+                offset += 2;
+                if (offset + 2 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_altitude_min, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+                offset += 2;
+                if (offset + 1 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_hr_avg, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+                offset += 1;
+                if (offset + 1 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_hr_max, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+                offset += 1;
+                if (offset + 1 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_peak_effect, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+                offset += 1;
+                if (offset + 1 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_activity_type, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+                offset += 1;
+                if (offset + 16 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_activity_name, tvb, offset, 16, ENC_LITTLE_ENDIAN);
+                offset += 16;
+                if (offset + 1 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_hr_min, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+                offset += 1;
+                if (offset + 5 >= length) break;
+                dissect_ambit_add_unknown(tvb, pinfo, tree, offset, 5);
+                offset += 5;
+                if (offset + 4 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_distance, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+                offset += 4;
+                if (offset + 4 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_sample_count, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+                offset += 4;
+                if (offset + 4 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_energy, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+                offset += 4;
+                if (offset + 4 >= length) break;
+                dissect_ambit_add_unknown(tvb, pinfo, tree, offset, 4);
+                offset += 4;
+                if (offset + 4 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_speed_max_time, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+                offset += 4;
+                if (offset + 4 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_alt_max_time, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+                offset += 4;
+                if (offset + 4 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_alt_min_time, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+                offset += 4;
+                if (offset + 4 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_hr_max_time, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+                offset += 4;
+                if (offset + 4 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_hr_min_time, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+                offset += 4;
+                if (offset + 4 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_temp_max_time, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+                offset += 4;
+                if (offset + 4 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_temp_min_time, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+                offset += 4;
+                if (offset + 8 >= length) break;
+                dissect_ambit_add_unknown(tvb, pinfo, tree, offset, 8);
+                offset += 8;
+                if (offset + 2 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_time_first_fix, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+                offset += 2;
+                if (offset + 1 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_battery_start, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+                offset += 1;
+                if (offset + 1 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_battery_stop, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+                offset += 1;
+                if (offset + 4 >= length) break;
+                dissect_ambit_add_unknown(tvb, pinfo, tree, offset, 4);
+                offset += 4;
+                if (offset + 4 >= length) break;
+                proto_tree_add_item(tree, hf_ambit_log_header_distance_before_calib, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+                offset += 4;
+
+                i = offset;
+            }
+        }
+    }
+
+            static int hf_ambit_log_data_sof = -1;
+static int hf_ambit_log_data_first_addr = -1;
+static int hf_ambit_log_data_next_free_addr = -1;
+static int hf_ambit_log_data_next_addr = -1;
+static int hf_ambit_log_data_prev_addr = -1;
+}
+
+static gint
+dissect_ambit(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
+{
+    gint offset = 0;
+    guint8 usbid = tvb_get_guint8(tvb, 0);
+    guint8 len = tvb_get_guint8(tvb, 1) + 2;
+    guint8 msg_part = tvb_get_guint8(tvb, 2);
+    guint8 data_header_len = tvb_get_guint8(tvb, 3);
+    guint16 msg_count = tvb_get_letohs(tvb, 4);
+    guint32 command = tvb_get_ntohl(tvb, 8);
+    guint32 pkt_len = tvb_get_letohl(tvb, 16);
+    tvbuff_t *new_tvb = NULL, *next_tvb = NULL;
+    static guint32 fragments_start_frame;
+    static guint16 fragments_offset;
+    static guint16 fragments_data_len;
+    int data_len = 0;
+    const ambit_protocol_type_t *subdissector;
+
+    if (usbid == D_AMBIT_USBID) {
+        if (msg_part == 0x5d) {
+            data_len = data_header_len - 12;
+        }
+        else {
+            data_len = data_header_len;
+        }
+
+        while (pinfo->fd->num + 1 > reassembly_entries_alloc) {
+            reassembly_entries = g_realloc(reassembly_entries, sizeof(ambit_reassembly_entry_t)*(reassembly_entries_alloc + 10000));
+            memset(reassembly_entries+reassembly_entries_alloc, 0, sizeof(ambit_reassembly_entry_t)*10000);
+            reassembly_entries_alloc += 10000;
+        }
+        if (!pinfo->fd->flags.visited) {
+            if (msg_part == 0x5d && msg_count > 1) {
+                reassembly_entries[pinfo->fd->num].valid = 2;
+                reassembly_entries[pinfo->fd->num].command = command;
+                reassembly_entries[pinfo->fd->num].start_frame = pinfo->fd->num;
+                reassembly_entries[pinfo->fd->num].frame_count = msg_count;
+                reassembly_entries[pinfo->fd->num].size = pkt_len;
+                reassembly_entries[pinfo->fd->num].data = (unsigned char*)g_malloc(pkt_len);
+                fragments_start_frame = pinfo->fd->num;
+                fragments_offset = data_len;
+                fragments_data_len = pkt_len;
+
+                tvb_memcpy(tvb, reassembly_entries[pinfo->fd->num].data, 20, data_len);
+            }
+            else if (msg_part == 0x5e) {
+                if (fragments_data_len >= fragments_offset + data_len) {
+                    //fragments_start_frame = pinfo->fd->num-msg_count;
+                    reassembly_entries[pinfo->fd->num].valid = 2;
+                    reassembly_entries[pinfo->fd->num].command = reassembly_entries[fragments_start_frame].command;
+                    reassembly_entries[pinfo->fd->num].start_frame = fragments_start_frame;
+                    reassembly_entries[pinfo->fd->num].frame_count = reassembly_entries[fragments_start_frame].frame_count;
+                    reassembly_entries[pinfo->fd->num].size = fragments_data_len;
+                    reassembly_entries[pinfo->fd->num].data = reassembly_entries[fragments_start_frame].data;
+                    tvb_memcpy(tvb, &(reassembly_entries[fragments_start_frame].data[fragments_offset]), 8, data_len);
+                    fragments_offset += data_len;
+                }
+                else {
+                }
+            }
+            else {
+                reassembly_entries[pinfo->fd->num].valid = 1;
+                reassembly_entries[pinfo->fd->num].command = command;
+            }
+        }
+
+        if (tree) { /* we are being asked for details */
+            proto_item *ti = NULL;
+            proto_tree *ambit_tree = NULL;
+            proto_item *data_ti = NULL;
+            proto_tree *data_tree = NULL;
+
+            col_set_str(pinfo->cinfo, COL_PROTOCOL, "Ambit");
+
+            ti = proto_tree_add_item(tree, proto_ambit, tvb, 0, len, ENC_NA);
+            ambit_tree = proto_item_add_subtree(ti, ett_ambit);
+            offset = 2;
+            proto_tree_add_item(ambit_tree, hf_ambit_msgpart, tvb, offset, 1, ENC_BIG_ENDIAN);
+            offset += 1;
+            proto_tree_add_item(ambit_tree, hf_ambit_msglength, tvb, offset, 1, ENC_BIG_ENDIAN);
+            offset += 1;
+            if (msg_part == 0x5d) {
+                proto_tree_add_item(ambit_tree, hf_ambit_msgsegs, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+            }
+            else if (msg_part == 0x5e) {
+                proto_tree_add_item(ambit_tree, hf_ambit_msgseg, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+            }
+            offset += 2;
+            proto_tree_add_item(ambit_tree, hf_ambit_msgheaderchksum, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+            offset += 2;
+            if (msg_part == 0x5d) {
+                proto_tree_add_item(ambit_tree, hf_ambit_requestcmd, tvb, offset, 4, ENC_BIG_ENDIAN);
+                offset += 4;
+                offset += 2;
+                proto_tree_add_item(ambit_tree, hf_ambit_pktseqno, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+                offset += 2;
+                proto_tree_add_item(ambit_tree, hf_ambit_pktlen, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+                offset += 4;
+            }
+
+            if (reassembly_entries[pinfo->fd->num].valid == 1) {
+                new_tvb = tvb_new_subset_remaining(tvb, offset);
+                pkt_len = data_len;
+                col_add_fstr(pinfo->cinfo, COL_INFO, "");
+            }
+            else if (reassembly_entries[pinfo->fd->num].start_frame + reassembly_entries[pinfo->fd->num].frame_count - 1 == pinfo->fd->num) {
+                new_tvb = tvb_new_real_data(reassembly_entries[pinfo->fd->num].data, reassembly_entries[pinfo->fd->num].size, reassembly_entries[pinfo->fd->num].size);
+                //tvb_set_child_real_data_tvbuff(tvb, new_tvb);
+                add_new_data_source(pinfo, new_tvb, "Reassembled");
+                pkt_len = reassembly_entries[pinfo->fd->num].size;
+
+                col_add_fstr(pinfo->cinfo, COL_INFO, " (#%u of #%u) Reassembled", pinfo->fd->num-reassembly_entries[pinfo->fd->num].start_frame + 1, reassembly_entries[pinfo->fd->num].frame_count);
+            }
+            else {
+                col_add_fstr(pinfo->cinfo, COL_INFO, " (#%u of #%u)", pinfo->fd->num-reassembly_entries[pinfo->fd->num].start_frame + 1, reassembly_entries[pinfo->fd->num].frame_count);
+            }
+
+            subdissector = find_subdissector(reassembly_entries[pinfo->fd->num].command);
+            if (subdissector != NULL) {
+                col_prepend_fstr(pinfo->cinfo, COL_INFO, "%s", subdissector->name);
+            }
+
+            if (new_tvb != NULL) {
+                data_ti = proto_tree_add_item(ambit_tree, proto_ambit, new_tvb, 0, pkt_len, ENC_NA);
+                data_tree = proto_item_add_subtree(ambit_tree, ett_ambit_data);
+                //proto_tree_add_text(ambit_tree, new_tvb, offset, data_len, "Payload");
+
+                if (subdissector != NULL) {
+                    subdissector->dissector(new_tvb, pinfo, data_tree, data);
+                }
+            }
+
+            offset += data_len;
+            proto_tree_add_item(ambit_tree, hf_ambit_payloadchksum, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+            offset += 2;
+        }
+
+        return len;
+    }
+
+    return 0;
+}
+
+void
+proto_register_ambit(void)
+{
+    static hf_register_info hf[] = {
+        { &hf_ambit_unknown,
+          { "Unknown", "ambit.unknown", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } },
+        { &hf_ambit_usbid,
+          { "USB-ID", "ambit.usbid", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL } },
+        { &hf_ambit_usblength,
+          { "USB length", "ambit.usblen", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL } },
+        { &hf_ambit_msgpart,
+          { "msg part", "ambit.msgpart", FT_UINT8, BASE_HEX, VALS(msgpart_index_vals), 0, NULL, HFILL } },
+        { &hf_ambit_msglength,
+          { "msg length", "ambit.msglen", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL } },
+        { &hf_ambit_msgsegs,
+          { "msg parts", "ambit.msgsegs", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
+        { &hf_ambit_msgseg,
+          { "msg part", "ambit.msgseg", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
+        { &hf_ambit_msgheaderchksum,
+          { "msg header checksum", "ambit.msgheaderchksum", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL } },
+        { &hf_ambit_requestcmd,
+          { "Command", "ambit.command", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL } },
+        { &hf_ambit_pktseqno,
+          { "Packet sequence no", "ambit.pktseqno", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
+        { &hf_ambit_pktlen,
+          { "Packet length", "ambit.pktlen", FT_UINT32, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_payloadchksum,
+          { "Paypload checksum", "ambit.payloadchksum", FT_UINT16, BASE_HEX, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_date,
+          { "Date", "ambit.date", FT_STRING, BASE_NONE, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_time,
+          { "Time", "ambit.time", FT_STRING, BASE_NONE, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_charge,
+          { "Charge", "ambit.charge", FT_UINT8, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_model,
+          { "Model", "ambit.model", FT_STRING, BASE_NONE, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_serial,
+          { "Serial", "ambit.serial", FT_STRING, BASE_NONE, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_fw_version,
+          { "FW version", "ambit.fwversion", FT_STRING, BASE_NONE, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_hw_version,
+          { "HW version", "ambit.hwversion", FT_STRING, BASE_NONE, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_personal_compass_declination,
+          { "Compass declination", "ambit.personal.compass_declination", FT_STRING, BASE_NONE, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_personal_map_orientation,
+          { "Map orientation", "ambit.personal.map_orientation", FT_UINT8, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_personal_weight,
+          { "Weight", "ambit.personal.weight", FT_FLOAT, BASE_NONE, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_personal_date_format,
+          { "Date format", "ambit.personal.date_format", FT_UINT8, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_personal_time_format,
+          { "Time format", "ambit.personal.time_format", FT_UINT8, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_personal_coordinate_system,
+          { "Coordinate system", "ambit.personal.coordinate_system", FT_UINT8, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_personal_unit_system,
+          { "Units", "ambit.personal.units", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } },
+        { &hf_ambit_personal_alarm_enable,
+          { "Alarm enable", "ambit.personal.alarm_enable", FT_UINT8, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_personal_alarm_time,
+          { "Alarm time", "ambit.personal.alarm_time", FT_STRING, BASE_NONE, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_personal_dual_time,
+          { "Dual time", "ambit.personal.dual_time", FT_STRING, BASE_NONE, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_personal_gps_sync_time,
+          { "Sync time w. GPS", "ambit.personal.gps_sync_time", FT_UINT8, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_personal_alti_baro_fused_alti,
+          { "Fused altitude", "ambit.personal.fused_alti", FT_UINT8, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_personal_alti_baro_profile,
+          { "Baro profile", "ambit.personal.baro_profile", FT_UINT8, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_personal_max_hb,
+          { "Max heart beat", "ambit.personal.maxhb", FT_UINT8, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_personal_rest_hb,
+          { "Rest heart rate", "ambit.personal.resthb", FT_UINT8, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_personal_birthyear,
+          { "Birthyear", "ambit.personal.birthyear", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
+        { &hf_ambit_personal_length,
+          { "Length", "ambit.personal.length", FT_UINT8, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_personal_sex,
+          { "IsMale", "ambit.personal.ismale", FT_STRING, BASE_NONE, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_personal_fitness_level,
+          { "Fitness level", "ambit.personal.fitness_level", FT_UINT8, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_personal_backlight_brightness,
+          { "Backlight brightness", "ambit.personal.backlight_brightness", FT_UINT8, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_personal_backlight_mode,
+          { "Backlight mode", "ambit.personal.backlight_mode", FT_UINT8, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_personal_display_contrast,
+          { "Display contrast", "ambit.personal.display_contrast", FT_UINT8, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_personal_invert_display,
+          { "Invert display", "ambit.personal.invert_display", FT_UINT8, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_personal_lock_sports_mode,
+          { "Button lock, sports", "ambit.personal.lock_sportsmode", FT_UINT8, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_personal_lock_time_mode,
+          {  "Button lock, time", "ambit.personal.lock_timemode", FT_UINT8, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_personal_tones,
+          { "Tones", "ambit.personal.tones", FT_UINT8, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+
+        { &hf_ambit_log_header_seq,
+          { "Header part", "ambit.log_header.header_part", FT_UINT16, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_length,
+          { "Length", "ambit.log_header.length", FT_UINT32, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_sample_desc,
+          { "Samples description???", "ambit.log_header.samples_desc", FT_BYTES, BASE_NONE, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_date,
+          { "Date", "ambit.log_header.date", FT_STRING, BASE_NONE, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_time,
+          { "Time", "ambit.log_header.time", FT_STRING, BASE_NONE, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_duration,
+          { "Duration (1/10 sec)", "ambit.log_header.duration", FT_UINT32, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_ascent,
+          { "Ascent", "ambit.log_header.ascent", FT_UINT16, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_descent,
+          { "Descent", "ambit.log_header.descent", FT_UINT16, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_ascent_time,
+          { "Ascent time (sec)", "ambit.log_header.ascent_time", FT_UINT32, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_descent_time,
+          { "Descent time (sec)", "ambit.log_header.descent_time", FT_UINT32, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_recovery,
+          { "Recovery time (minutes)", "ambit.log_header.recovery", FT_UINT16, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_avg_speed,
+          { "Avg speed (km/h * 100)", "ambit.log_header.avg_speed", FT_UINT16, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_max_speed,
+          { "Max speed (km/h * 100)", "ambit.log_header.max_speed", FT_UINT16, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_altitude_max,
+          { "Altitude max", "ambit.log_header.alt_max", FT_UINT16, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_altitude_min,
+          { "Altitude min", "ambit.log_header.alt_min", FT_UINT16, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_hr_avg,
+          { "Heartrate avg", "ambit.log_header.hr_avg", FT_UINT8, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_hr_max,
+          { "Heartrate max", "ambit.log_header.hr_max", FT_UINT16, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_peak_effect,
+          { "Peak training effect (x10)", "ambit.log_header.peak_effect", FT_UINT8, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_activity_type,
+          { "Activity type", "ambit.log_header.activity_type", FT_UINT8, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_activity_name,
+          { "Activity name", "ambit.log_header.activity_name", FT_STRING, BASE_NONE, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_hr_min,
+          { "Heartrate min", "ambit.log_header.hr_min", FT_UINT8, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_distance,
+          { "Distance (m)", "ambit.log_header.distance", FT_UINT32, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_sample_count,
+          { "Sample count", "ambit.log_header.sample_count", FT_UINT32, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_energy,
+          { "Energy consumption (kcal)", "ambit.log_header.energy_consumption", FT_UINT32, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_speed_max_time,
+          { "Time max speed (ms)", "ambit.log_header.speed_maxtime", FT_UINT32, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_alt_max_time,
+          { "Time max altitude (ms)", "ambit.log_header.alt_maxtime", FT_UINT32, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_alt_min_time,
+          { "Time min altitude (ms)", "ambit.log_header.alt_mintime", FT_UINT32, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_hr_max_time,
+          { "Time max HR (ms)", "ambit.log_header.hr_maxtime", FT_UINT32, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_hr_min_time,
+          { "Time min HR (ms)", "ambit.log_header.hr_mintime", FT_UINT32, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_temp_max_time,
+          { "Time max temperature (ms)", "ambit.log_header.temp_maxtime", FT_UINT32, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_temp_min_time,
+          { "Time min temperature (ms)", "ambit.log_header.temp_mintime", FT_UINT32, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_time_first_fix,
+          { "Time of first fix", "ambit.log_header.time_first_fix", FT_UINT16, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_battery_start,
+          { "Battery at start", "ambit.log_header.battery_start", FT_UINT8, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_battery_stop,
+          { "Battery at end", "ambit.log_header.battery_stop", FT_UINT8, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_header_distance_before_calib,
+          { "Distance before calibration", "ambit.log_header.distance_before_calib", FT_UINT32, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+
+        { &hf_ambit_log_header_more,
+          { "More values", "ambit.log_header.more", FT_UINT32, BASE_HEX, VALS(log_header_more_vals), 0, NULL, HFILL } },
+
+        { &hf_ambit_log_data_address,
+          { "Address", "ambit.log_data.address", FT_UINT32, BASE_HEX, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_data_length,
+          { "Length", "ambit.log_data.length", FT_UINT32, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_data_sof,
+          { "Start of entry", "ambit.log_data.start_of_entry", FT_STRING, BASE_NONE, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_data_first_addr,
+          { "First entry address", "ambit.log_data.first_addr", FT_UINT32, BASE_HEX, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_data_last_addr,
+          { "Last entry address", "ambit.log_data.last_addr", FT_UINT32, BASE_HEX, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_data_entry_count,
+          { "Number of entries", "ambit.log_data.entry_count", FT_UINT32, BASE_DEC, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_data_next_free_addr,
+          { "Next free address", "ambit.log_data.next_free_addr", FT_UINT32, BASE_HEX, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_data_next_addr,
+          { "Next entry address", "ambit.log_data.next_addr", FT_UINT32, BASE_HEX, NULL, 0x0,NULL, HFILL } },
+        { &hf_ambit_log_data_prev_addr,
+          { "Previous entry address", "ambit.log_data.prev_addr", FT_UINT32, BASE_HEX, NULL, 0x0,NULL, HFILL } },
+    };
+
+    static gint *ett[] = {
+        &ett_ambit,
+        &ett_ambit_data,
+    };
+
+    static ei_register_info ei[] = {
+        { &ei_ambit_undecoded, { "ambit.undecoded", PI_UNDECODED, PI_WARN, "Not dissected yet", EXPFILL }},
+    };
+
+    expert_module_t *expert_ambit;
+
+    proto_ambit = proto_register_protocol (
+        "Suunto Ambit USB Protocol",
+        "Ambit",
+        "ambit"
+        );
+
+    proto_register_field_array(proto_ambit, hf, array_length(hf));
+    proto_register_subtree_array(ett, array_length(ett));
+    expert_ambit = expert_register_protocol(proto_ambit);
+    expert_register_field_array(expert_ambit, ei, array_length(ei));
+    //register_dissector("ambit", dissect_ambit, proto_ambit);
+}
+
+void
+proto_reg_handoff_ambit(void)
+{
+    static dissector_handle_t ambit_handle;
+
+    //ambit_handle = find_dissector("ambit");
+    ambit_handle = new_create_dissector_handle(dissect_ambit, proto_ambit);
+    dissector_add_uint("usb.interrupt", IF_CLASS_UNKNOWN, ambit_handle);
+    dissector_add_uint("usb.interrupt", IF_CLASS_HID, ambit_handle);
+}
diff --git a/wireshark_dissector/cmake/COPYING-CMAKE-SCRIPTS b/wireshark_dissector/cmake/COPYING-CMAKE-SCRIPTS
new file mode 100644
index 0000000..280ed6c
--- /dev/null
+++ b/wireshark_dissector/cmake/COPYING-CMAKE-SCRIPTS
@@ -0,0 +1,27 @@
+Copyright notice for the files copied from
+http://www.opensync.org/browser/branches/3rd-party-cmake-modules/modules
+
+$Id: COPYING-CMAKE-SCRIPTS 34248 2010-09-25 15:38:12Z jmayer $
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+1. Redistributions of source code must retain the copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+3. The name of the author may not be used to endorse or promote products
+   derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/wireshark_dissector/cmake/FindGLIB2.cmake b/wireshark_dissector/cmake/FindGLIB2.cmake
new file mode 100644
index 0000000..ae7badd
--- /dev/null
+++ b/wireshark_dissector/cmake/FindGLIB2.cmake
@@ -0,0 +1,238 @@
+#
+# $Id: FindGLIB2.cmake 34248 2010-09-25 15:38:12Z jmayer $
+#
+# - Try to find GLib2
+# Once done this will define
+#
+#  GLIB2_FOUND - system has GLib2
+#  GLIB2_INCLUDE_DIRS - the GLib2 include directory
+#  GLIB2_LIBRARIES - Link these to use GLib2
+#
+#  HAVE_GLIB_GREGEX_H  glib has gregex.h header and 
+#                      supports g_regex_match_simple
+#
+#  Copyright (c) 2006 Andreas Schneider <mail at cynapses.org>
+#  Copyright (c) 2006 Philippe Bernery <philippe.bernery at gmail.com>
+#  Copyright (c) 2007 Daniel Gollub <gollub at b1-systems.de>
+#  Copyright (c) 2007 Alban Browaeys <prahal at yahoo.com>
+#  Copyright (c) 2008 Michael Bell <michael.bell at web.de>
+#  Copyright (c) 2008-2009 Bjoern Ricks <bjoern.ricks at googlemail.com>
+#
+#  Redistribution and use is allowed according to the terms of the New
+#  BSD license.
+#  For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+#
+
+
+IF (GLIB2_LIBRARIES AND GLIB2_INCLUDE_DIRS )
+  # in cache already
+  SET(GLIB2_FOUND TRUE)
+ELSE (GLIB2_LIBRARIES AND GLIB2_INCLUDE_DIRS )
+
+  INCLUDE(FindPkgConfig)
+
+  ## Glib
+  IF ( GLIB2_FIND_REQUIRED )
+    SET( _pkgconfig_REQUIRED "REQUIRED" )
+  ELSE ( GLIB2_FIND_REQUIRED )
+    SET( _pkgconfig_REQUIRED "" )
+  ENDIF ( GLIB2_FIND_REQUIRED )
+
+  IF ( GLIB2_MIN_VERSION )
+    PKG_SEARCH_MODULE( GLIB2 ${_pkgconfig_REQUIRED} glib-2.0>=${GLIB2_MIN_VERSION} )
+  ELSE ( GLIB2_MIN_VERSION )
+    PKG_SEARCH_MODULE( GLIB2 ${_pkgconfig_REQUIRED} glib-2.0 )
+  ENDIF ( GLIB2_MIN_VERSION )
+  IF ( PKG_CONFIG_FOUND )
+    IF ( GLIB2_FOUND )
+      SET ( GLIB2_CORE_FOUND TRUE )
+    ELSE ( GLIB2_FOUND )
+      SET ( GLIB2_CORE_FOUND FALSE )
+    ENDIF ( GLIB2_FOUND )
+  ENDIF ( PKG_CONFIG_FOUND )
+
+  # Look for glib2 include dir and libraries w/o pkgconfig
+  IF ( NOT GLIB2_FOUND AND NOT PKG_CONFIG_FOUND )
+    FIND_PATH(
+      _glibconfig_include_DIR
+    NAMES
+      glibconfig.h
+    PATHS
+      /opt/gnome/lib64
+      /opt/gnome/lib
+      /opt/lib/
+      /opt/local/lib
+      /sw/lib/
+      /usr/lib64
+      /usr/lib
+      /usr/local/include
+      ${CMAKE_LIBRARY_PATH}
+    PATH_SUFFIXES
+      glib-2.0/include
+    )
+
+    FIND_PATH(
+      _glib2_include_DIR
+    NAMES
+      glib.h
+    PATHS
+      /opt/gnome/include
+      /opt/local/include
+      /sw/include
+      /usr/include
+      /usr/local/include
+    PATH_SUFFIXES
+      glib-2.0
+    )
+
+    #MESSAGE(STATUS "Glib headers: ${_glib2_include_DIR}")
+
+    FIND_LIBRARY(
+      _glib2_link_DIR
+    NAMES
+      glib-2.0
+      glib
+    PATHS
+      /opt/gnome/lib
+      /opt/local/lib
+      /sw/lib
+      /usr/lib
+      /usr/local/lib
+    )
+    IF ( _glib2_include_DIR AND _glib2_link_DIR )
+        SET ( _glib2_FOUND TRUE )
+    ENDIF ( _glib2_include_DIR AND _glib2_link_DIR )
+
+
+    IF ( _glib2_FOUND )
+        SET ( GLIB2_INCLUDE_DIRS ${_glib2_include_DIR} ${_glibconfig_include_DIR} )
+        SET ( GLIB2_LIBRARIES ${_glib2_link_DIR} )
+        SET ( GLIB2_CORE_FOUND TRUE )
+    ELSE ( _glib2_FOUND )
+        SET ( GLIB2_CORE_FOUND FALSE )
+    ENDIF ( _glib2_FOUND )
+
+    # Handle dependencies
+    # libintl
+    IF ( NOT LIBINTL_FOUND )
+      FIND_PATH(LIBINTL_INCLUDE_DIR
+      NAMES
+        libintl.h
+      PATHS
+        /opt/gnome/include
+        /opt/local/include
+        /sw/include
+        /usr/include
+        /usr/local/include
+      )
+
+      FIND_LIBRARY(LIBINTL_LIBRARY
+      NAMES
+        intl
+      PATHS
+        /opt/gnome/lib
+        /opt/local/lib
+        /sw/lib
+        /usr/local/lib
+        /usr/lib
+      )
+
+      IF (LIBINTL_LIBRARY AND LIBINTL_INCLUDE_DIR)
+        SET (LIBINTL_FOUND TRUE)
+      ENDIF (LIBINTL_LIBRARY AND LIBINTL_INCLUDE_DIR)
+    ENDIF ( NOT LIBINTL_FOUND )
+
+    # libiconv
+    IF ( NOT LIBICONV_FOUND )
+      FIND_PATH(LIBICONV_INCLUDE_DIR
+      NAMES
+        iconv.h
+      PATHS
+        /opt/gnome/include
+        /opt/local/include
+        /opt/local/include
+        /sw/include
+        /sw/include
+        /usr/local/include
+        /usr/include
+      PATH_SUFFIXES
+        glib-2.0
+      )
+
+      FIND_LIBRARY(LIBICONV_LIBRARY
+      NAMES
+        iconv
+      PATHS
+        /opt/gnome/lib
+        /opt/local/lib
+        /sw/lib
+        /usr/lib
+        /usr/local/lib
+      )
+
+      IF (LIBICONV_LIBRARY AND LIBICONV_INCLUDE_DIR)
+        SET (LIBICONV_FOUND TRUE)
+      ENDIF (LIBICONV_LIBRARY AND LIBICONV_INCLUDE_DIR)
+    ENDIF ( NOT LIBICONV_FOUND )
+
+    IF (LIBINTL_FOUND)
+      SET (GLIB2_LIBRARIES ${GLIB2_LIBRARIES} ${LIBINTL_LIBRARY})
+      SET (GLIB2_INCLUDE_DIRS ${GLIB2_INCLUDE_DIRS} ${LIBINTL_INCLUDE_DIR})
+    ENDIF (LIBINTL_FOUND)
+
+    IF (LIBICONV_FOUND)
+      SET (GLIB2_LIBRARIES ${GLIB2_LIBRARIES} ${LIBICONV_LIBRARY})
+      SET (GLIB2_INCLUDE_DIRS ${GLIB2_INCLUDE_DIRS} ${LIBICONV_INCLUDE_DIR})
+    ENDIF (LIBICONV_FOUND)
+
+  ENDIF ( NOT GLIB2_FOUND AND NOT PKG_CONFIG_FOUND )
+  ##
+
+  IF (GLIB2_CORE_FOUND AND GLIB2_INCLUDE_DIRS AND GLIB2_LIBRARIES)
+    SET (GLIB2_FOUND TRUE)
+  ENDIF (GLIB2_CORE_FOUND AND GLIB2_INCLUDE_DIRS AND GLIB2_LIBRARIES)
+
+  IF (GLIB2_FOUND)
+    IF (NOT GLIB2_FIND_QUIETLY)
+      MESSAGE (STATUS "Found GLib2: ${GLIB2_LIBRARIES} ${GLIB2_INCLUDE_DIRS}")
+    ENDIF (NOT GLIB2_FIND_QUIETLY)
+  ELSE (GLIB2_FOUND)
+    IF (GLIB2_FIND_REQUIRED)
+      MESSAGE (SEND_ERROR "Could not find GLib2")
+    ENDIF (GLIB2_FIND_REQUIRED)
+  ENDIF (GLIB2_FOUND)
+
+  # show the GLIB2_INCLUDE_DIRS and GLIB2_LIBRARIES variables only in the advanced view
+  MARK_AS_ADVANCED(GLIB2_INCLUDE_DIRS GLIB2_LIBRARIES)
+  MARK_AS_ADVANCED(LIBICONV_INCLUDE_DIR LIBICONV_LIBRARY)
+  MARK_AS_ADVANCED(LIBINTL_INCLUDE_DIR LIBINTL_LIBRARY)
+
+ENDIF (GLIB2_LIBRARIES AND GLIB2_INCLUDE_DIRS)
+
+IF ( WIN32 )
+    # include libiconv for win32
+    IF ( NOT LIBICONV_FOUND )
+      FIND_PATH(LIBICONV_INCLUDE_DIR iconv.h PATH_SUFFIXES glib-2.0)
+
+      FIND_LIBRARY(LIBICONV_LIBRARY NAMES iconv)
+
+      IF (LIBICONV_LIBRARY AND LIBICONV_INCLUDE_DIR)
+        SET (LIBICONV_FOUND TRUE)
+      ENDIF (LIBICONV_LIBRARY AND LIBICONV_INCLUDE_DIR)
+    ENDIF ( NOT LIBICONV_FOUND )
+    IF (LIBICONV_FOUND)
+      SET (GLIB2_LIBRARIES ${GLIB2_LIBRARIES} ${LIBICONV_LIBRARY})
+      SET (GLIB2_INCLUDE_DIRS ${GLIB2_INCLUDE_DIRS} ${LIBICONV_INCLUDE_DIR})
+    ENDIF (LIBICONV_FOUND)
+ENDIF ( WIN32 )
+
+IF ( GLIB2_FOUND )
+	# Check if system has a newer version of glib
+	# which supports g_regex_match_simple
+	INCLUDE( CheckIncludeFiles )
+	SET( CMAKE_REQUIRED_INCLUDES ${GLIB2_INCLUDE_DIRS} )
+	CHECK_INCLUDE_FILES ( glib/gregex.h HAVE_GLIB_GREGEX_H )
+	CHECK_INCLUDE_FILES ( glib/gchecksum.h HAVE_GLIB_GCHECKSUM_H )
+	# Reset CMAKE_REQUIRED_INCLUDES
+	SET( CMAKE_REQUIRED_INCLUDES "" )
+ENDIF( GLIB2_FOUND )
diff --git a/wireshark_dissector/cmake/FindWireshark.cmake b/wireshark_dissector/cmake/FindWireshark.cmake
new file mode 100644
index 0000000..2cfae6e
--- /dev/null
+++ b/wireshark_dissector/cmake/FindWireshark.cmake
@@ -0,0 +1,28 @@
+#
+# Try to find the wireshark library and its includes
+#
+# This snippet sets the following variables:
+#  WIRESHARK_FOUND             True if wireshark library got found
+#  WIRESHARK_INCLUDE_DIRS      Location of the wireshark headers 
+#  WIRESHARK_LIBRARIES         List of libraries to use wireshark
+#
+#  Copyright (c) 2011 Reinhold Kainhofer <reinhold at kainhofer.com>
+#
+#  Redistribution and use is allowed according to the terms of the New
+#  BSD license.
+#  For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+#
+
+# wireshark does not install its library with pkg-config information,
+# so we need to manually find the libraries and headers
+
+FIND_PATH( WIRESHARK_INCLUDE_DIRS epan/column_info.h PATH_SUFFIXES wireshark )
+FIND_LIBRARY( WIRESHARK_LIBRARIES wireshark PATH_SUFFIXES wireshark )
+
+# Report results
+IF ( WIRESHARK_LIBRARIES AND WIRESHARK_INCLUDE_DIRS )
+  SET( WIRESHARK_FOUND 1 )
+ELSE ( WIRESHARK_LIBRARIES AND WIRESHARK_INCLUDE_DIRS )
+  MESSAGE( SEND_ERROR "Could NOT find the wireshark library and headers" )
+ENDIF ( WIRESHARK_LIBRARIES AND WIRESHARK_INCLUDE_DIRS )
+
diff --git a/wireshark_dissector/cmake/UseMakeDissectorReg.cmake b/wireshark_dissector/cmake/UseMakeDissectorReg.cmake
new file mode 100644
index 0000000..e7e1a73
--- /dev/null
+++ b/wireshark_dissector/cmake/UseMakeDissectorReg.cmake
@@ -0,0 +1,33 @@
+#
+# $Id: UseMakeDissectorReg.cmake 33616 2010-07-22 12:18:36Z stig $
+#
+MACRO(REGISTER_DISSECTOR_FILES _outputfile _registertype )
+	# FIXME: Only the Python stuff has been implemented
+	#        Make this into a MACRO, to avoid duplication with plugins/.../
+	#register.c: $(plugin_src) $(ALL_DISSECTORS_SRC) $(top_srcdir)/tools/make-dissector-reg \
+	#    $(top_srcdir)/tools/make-dissector-reg.py
+	#        @if test -n "$(PYTHON)"; then \
+	#                echo Making register.c with python ; \
+	#                $(PYTHON) $(top_srcdir)/tools/make-dissector-reg.py $(srcdir) \
+	#                    dissectors $(ALL_DISSECTORS_SRC) ; \
+	#        else \
+	#                echo Making register.c with shell script ; \
+	#                $(top_srcdir)/tools/make-dissector-reg $(srcdir) \
+	#                   dissectors $(plugin_src) $(ALL_DISSECTORS_SRC) ; \
+	#        fi
+	set( _sources ${ARGN} )
+	ADD_CUSTOM_COMMAND(
+	    OUTPUT 
+	      ${_outputfile}
+	    COMMAND ${PYTHON_EXECUTABLE}
+	      ${CMAKE_SOURCE_DIR}/tools/make-dissector-reg.py
+	      ${CMAKE_CURRENT_SOURCE_DIR}
+	      ${_registertype}
+	      ${_sources}
+	    DEPENDS
+	      ${_sources}
+	      ${CMAKE_SOURCE_DIR}/tools/make-dissector-reg
+	      ${CMAKE_SOURCE_DIR}/tools/make-dissector-reg.py
+	)
+ENDMACRO(REGISTER_DISSECTOR_FILES)
+
diff --git a/wireshark_dissector/moduleinfo.h b/wireshark_dissector/moduleinfo.h
new file mode 100644
index 0000000..3bc54c2
--- /dev/null
+++ b/wireshark_dissector/moduleinfo.h
@@ -0,0 +1,17 @@
+/* Included *after* config.h, in order to re-define these macros */
+
+#ifdef PACKAGE
+#undef PACKAGE
+#endif
+
+/* Name of package */
+#define PACKAGE "ambit-usb"
+
+
+#ifdef VERSION
+#undef VERSION
+#endif
+
+/* Version number of package */
+#define VERSION "0.0.1"
+
diff --git a/wireshark_dissector/tools/make-dissector-reg b/wireshark_dissector/tools/make-dissector-reg
new file mode 100755
index 0000000..d2efa7c
--- /dev/null
+++ b/wireshark_dissector/tools/make-dissector-reg
@@ -0,0 +1,186 @@
+#! /bin/sh
+
+#
+# $Id: make-dissector-reg 21716 2007-05-07 17:55:42Z gal $
+#
+
+#
+# The first argument is the directory in which the source files live.
+#
+srcdir="$1"
+shift
+
+#
+# The second argument is either "plugin" or "dissectors"; if it's
+# "plugin", we build a plugin.c for a plugin, and if it's
+# "dissectors", we build a register.c for libwireshark.
+#
+registertype="$1"
+shift
+if [ "$registertype" = plugin ]
+then
+	outfile="plugin.c"
+elif [ "$registertype" = dissectors ]
+then
+	outfile="register.c"
+else
+	echo "Unknown output type '$registertype'" 1>&2
+	exit 1
+fi
+
+#
+# All subsequent arguments are the files to scan.
+#
+rm -f ${outfile}-tmp
+echo '/* Do not modify this file.  */' >${outfile}-tmp
+echo '/* It is created automatically by the Makefile. */'>>${outfile}-tmp
+if [ "$registertype" = plugin ]
+then
+	cat <<"EOF" >>${outfile}-tmp
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <gmodule.h>
+
+#include "moduleinfo.h"
+
+#ifndef ENABLE_STATIC
+G_MODULE_EXPORT const gchar version[] = VERSION;
+
+/* Start the functions we need for the plugin stuff */
+
+G_MODULE_EXPORT void
+plugin_register (void)
+{
+EOF
+#
+# Build code to call all the protocol registration routines.
+#
+for f in "$@"
+do
+	if [ -f $f ]
+	then
+		srcfile=$f
+	else
+		srcfile=$srcdir/$f
+	fi
+	grep '^proto_register_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
+done | sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/  {extern void \1 (void); \1 ();}/' >>${outfile}-tmp
+for f in "$@"
+do
+	if [ -f $f ]
+	then
+		srcfile=$f
+	else
+		srcfile=$srcdir/$f
+	fi
+	grep '^void proto_register_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
+done | sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/  {extern void \1 (void); \1 ();}/' >>${outfile}-tmp
+else
+	cat <<"EOF" >>${outfile}-tmp
+#include "register.h"
+void
+register_all_protocols(register_cb cb, gpointer client_data)
+{
+EOF
+#
+# Build code to call all the protocol registration routines.
+#
+for f in "$@"
+do
+	if [ -f $f ]
+	then
+		srcfile=$f
+	else
+		srcfile=$srcdir/$f
+	fi
+	grep '^proto_register_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
+done | sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/  {extern void \1 (void); if(cb) (*cb)(RA_REGISTER, \"\1\", client_data); \1 ();}/' >>${outfile}-tmp
+for f in "$@"
+do
+	if [ -f $f ]
+	then
+		srcfile=$f
+	else
+		srcfile=$srcdir/$f
+	fi
+	grep '^void proto_register_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
+done | sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/  {extern void \1 (void); if(cb) (*cb)(RA_REGISTER, \"\1\", client_data); \1 ();}/' >>${outfile}-tmp
+
+fi
+echo '}' >>${outfile}-tmp
+
+
+#
+# Build code to call all the protocol handoff registration routines.
+#
+if [ "$registertype" = plugin ]
+then
+	cat <<"EOF" >>${outfile}-tmp
+G_MODULE_EXPORT void
+plugin_reg_handoff(void)
+{
+EOF
+for f in "$@"
+do
+	if [ -f $f ]
+	then
+		srcfile=$f
+	else
+		srcfile=$srcdir/$f
+	fi
+	grep '^proto_reg_handoff_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
+done | sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/  {extern void \1 (void); \1 ();}/' >>${outfile}-tmp
+for f in "$@"
+do
+	if [ -f $f ]
+	then
+		srcfile=$f
+	else
+		srcfile=$srcdir/$f
+	fi
+	grep '^void proto_reg_handoff_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
+done | sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/  {extern void \1 (void); \1 ();}/' >>${outfile}-tmp
+else
+	cat <<"EOF" >>${outfile}-tmp
+void
+register_all_protocol_handoffs(register_cb cb, gpointer client_data)
+{
+EOF
+for f in "$@"
+do
+	if [ -f $f ]
+	then
+		srcfile=$f
+	else
+		srcfile=$srcdir/$f
+	fi
+	grep '^proto_reg_handoff_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
+done | sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/  {extern void \1 (void); if(cb) (*cb)(RA_HANDOFF, \"\1\", client_data); \1 ();}/' >>${outfile}-tmp
+for f in "$@"
+do
+	if [ -f $f ]
+	then
+		srcfile=$f
+	else
+		srcfile=$srcdir/$f
+	fi
+	grep '^void proto_reg_handoff_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
+done | sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/  {extern void \1 (void); if(cb) (*cb)(RA_HANDOFF, \"\1\", client_data); \1 ();}/' >>${outfile}-tmp
+fi
+echo '}' >>${outfile}-tmp
+if [ "$registertype" = plugin ]
+then
+	echo '#endif' >>${outfile}-tmp
+else 
+	cat <<"EOF" >>${outfile}-tmp
+gulong register_count(void)
+{
+EOF
+	proto_regs=`grep RA_REGISTER ${outfile}-tmp | wc -l`
+	handoff_regs=`grep RA_HANDOFF ${outfile}-tmp | wc -l`
+	echo "  return $proto_regs + $handoff_regs;" >>${outfile}-tmp
+	echo '}' >>${outfile}-tmp
+fi
+mv ${outfile}-tmp ${outfile}
diff --git a/wireshark_dissector/tools/make-dissector-reg.py b/wireshark_dissector/tools/make-dissector-reg.py
new file mode 100755
index 0000000..4497290
--- /dev/null
+++ b/wireshark_dissector/tools/make-dissector-reg.py
@@ -0,0 +1,305 @@
+#!/usr/bin/env python
+#
+# Looks for registration routines in the protocol dissectors,
+# and assembles C code to call all the routines.
+#
+# This is a Python version of the make-reg-dotc shell script.
+# Running the shell script on Win32 is very very slow because of
+# all the process-launching that goes on --- multiple greps and
+# seds for each input file.  I wrote this python version so that
+# less processes would have to be started.
+#
+# $Id: make-dissector-reg.py 30447 2009-10-09 20:47:18Z krj $
+
+import os
+import sys
+import re
+import pickle
+from stat import *
+
+VERSION_KEY = '_VERSION'
+CUR_VERSION = '$Id: make-dissector-reg.py 30447 2009-10-09 20:47:18Z krj $'
+
+#
+# The first argument is the directory in which the source files live.
+#
+srcdir = sys.argv[1]
+
+#
+# The second argument is either "plugin" or "dissectors"; if it's
+# "plugin", we build a plugin.c for a plugin, and if it's
+# "dissectors", we build a register.c for libwireshark.
+#
+registertype = sys.argv[2]
+if registertype == "plugin" or registertype == "plugin_wtap":
+	tmp_filename = "plugin.c-tmp"
+	final_filename = "plugin.c"
+	cache_filename = None
+	preamble = """\
+/*
+ * Do not modify this file.
+ *
+ * It is created automatically by Makefile or Makefile.nmake.
+ */
+"""
+elif registertype == "dissectors":
+	tmp_filename = "register.c-tmp"
+	final_filename = "register.c"
+	cache_filename = "register-cache.pkl"
+	preamble = """\
+/*
+ * Do not modify this file.
+ *
+ * It is created automatically by the "register.c" target in
+ * epan/dissectors/Makefile or Makefile.nmake using information in
+ * epan/dissectors/register-cache.pkl.
+ *
+ * You can force this file to be regenerated completely by deleting
+ * it along with epan/dissectors/register-cache.pkl.
+ */
+"""
+else:
+	print "Unknown output type '%s'" % registertype
+	sys.exit(1)
+
+
+#
+# All subsequent arguments are the files to scan.
+#
+files = sys.argv[3:]
+
+# Create the proper list of filenames
+filenames = []
+for file in files:
+	if os.path.isfile(file):
+		filenames.append(file)
+	else:
+		filenames.append(os.path.join(srcdir, file))
+
+if len(filenames) < 1:
+	print "No files found"
+	sys.exit(1)
+
+
+# Look through all files, applying the regex to each line.
+# If the pattern matches, save the "symbol" section to the
+# appropriate array.
+regs = {
+	'proto_reg': [],
+	'handoff_reg': [],
+	'wtap_register': [],
+	}
+
+# For those that don't know Python, r"" indicates a raw string,
+# devoid of Python escapes.
+proto_regex0 = r"^(?P<symbol>proto_register_[_A-Za-z0-9]+)\s*\([^;]+$"
+proto_regex1 = r"void\s+(?P<symbol>proto_register_[_A-Za-z0-9]+)\s*\([^;]+$"
+
+handoff_regex0 = r"^(?P<symbol>proto_reg_handoff_[_A-Za-z0-9]+)\s*\([^;]+$"
+handoff_regex1 = r"void\s+(?P<symbol>proto_reg_handoff_[_A-Za-z0-9]+)\s*\([^;]+$"
+
+wtap_reg_regex0 = r"^(?P<symbol>wtap_register_[_A-Za-z0-9]+)\s*\([^;]+$"
+wtap_reg_regex1 = r"void\s+(?P<symbol>wtap_register_[_A-Za-z0-9]+)\s*\([^;]+$"
+
+# This table drives the pattern-matching and symbol-harvesting
+patterns = [
+	( 'proto_reg', re.compile(proto_regex0) ),
+	( 'proto_reg', re.compile(proto_regex1) ),
+	( 'handoff_reg', re.compile(handoff_regex0) ),
+	( 'handoff_reg', re.compile(handoff_regex1) ),
+	( 'wtap_register', re.compile(wtap_reg_regex0) ),
+	( 'wtap_register', re.compile(wtap_reg_regex1) ),
+	]
+
+# Open our registration symbol cache
+cache = None
+if cache_filename:
+	try:
+		cache_file = open(cache_filename, 'rb')
+		cache = pickle.load(cache_file)
+		cache_file.close()
+		if not cache.has_key(VERSION_KEY) or cache[VERSION_KEY] != CUR_VERSION:
+			cache = {VERSION_KEY: CUR_VERSION}
+	except:
+		cache = {VERSION_KEY: CUR_VERSION}
+
+# Grep
+for filename in filenames:
+	file = open(filename)
+	cur_mtime = os.fstat(file.fileno())[ST_MTIME]
+	if cache and cache.has_key(filename):
+		cdict = cache[filename]
+		if cur_mtime == cdict['mtime']:
+#			print "Pulling %s from cache" % (filename)
+			regs['proto_reg'].extend(cdict['proto_reg'])
+			regs['handoff_reg'].extend(cdict['handoff_reg'])
+			regs['wtap_register'].extend(cdict['wtap_register'])
+			file.close()
+			continue
+	# We don't have a cache entry
+	if cache is not None:
+		cache[filename] = {
+			'mtime': cur_mtime,
+			'proto_reg': [],
+			'handoff_reg': [],
+			'wtap_register': [],
+			}
+#	print "Searching %s" % (filename)
+	for line in file.readlines():
+		for action in patterns:
+			regex = action[1]
+			match = regex.search(line)
+			if match:
+				symbol = match.group("symbol")
+				sym_type = action[0]
+				regs[sym_type].append(symbol)
+				if cache is not None:
+#					print "Caching %s for %s: %s" % (sym_type, filename, symbol)
+					cache[filename][sym_type].append(symbol)
+	file.close()
+
+if cache is not None and cache_filename is not None:
+	cache_file = open(cache_filename, 'wb')
+	pickle.dump(cache, cache_file)
+	cache_file.close()
+
+# Make sure we actually processed something
+if len(regs['proto_reg']) < 1:
+	print "No protocol registrations found"
+	sys.exit(1)
+
+# Sort the lists to make them pretty
+regs['proto_reg'].sort()
+regs['handoff_reg'].sort()
+regs['wtap_register'].sort()
+
+reg_code = open(tmp_filename, "w")
+
+reg_code.write(preamble)
+
+# Make the routine to register all protocols
+if registertype == "plugin" or registertype == "plugin_wtap":
+	reg_code.write("""
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <gmodule.h>
+
+#include "moduleinfo.h"
+
+#ifndef ENABLE_STATIC
+G_MODULE_EXPORT const gchar version[] = VERSION;
+
+/* Start the functions we need for the plugin stuff */
+
+G_MODULE_EXPORT void
+plugin_register (void)
+{
+""");
+else:
+	reg_code.write("""
+#include "register.h"
+void
+register_all_protocols(register_cb cb, gpointer client_data)
+{
+""");
+
+for symbol in regs['proto_reg']:
+	if registertype == "plugin" or registertype == "plugin_wtap":
+		line = "  {extern void %s (void); %s ();}\n" % (symbol, symbol)
+	else:
+		line = "  {extern void %s (void); if(cb) (*cb)(RA_REGISTER, \"%s\", client_data); %s ();}\n" % (symbol, symbol, symbol)
+	reg_code.write(line)
+
+reg_code.write("}\n")
+
+
+# Make the routine to register all protocol handoffs
+if registertype == "plugin" or registertype == "plugin_wtap":
+	reg_code.write("""
+G_MODULE_EXPORT void
+plugin_reg_handoff(void)
+{
+""");
+else:
+	reg_code.write("""
+void
+register_all_protocol_handoffs(register_cb cb, gpointer client_data)
+{
+""");
+
+for symbol in regs['handoff_reg']:
+	if registertype == "plugin" or registertype == "plugin_wtap":
+		line = "  {extern void %s (void); %s ();}\n" % (symbol, symbol)
+	else:
+		line = "  {extern void %s (void); if(cb) (*cb)(RA_HANDOFF, \"%s\", client_data); %s ();}\n" % (symbol, symbol, symbol)
+	reg_code.write(line)
+
+reg_code.write("}\n")
+
+if registertype == "plugin":
+	reg_code.write("#endif\n");
+elif registertype == "plugin_wtap":
+	reg_code.write("""
+G_MODULE_EXPORT void
+register_wtap_module(void)
+{
+""");
+
+	for symbol in regs['wtap_register']:
+		line = "  {extern void %s (void); %s ();}\n" % (symbol, symbol)
+		reg_code.write(line)
+
+	reg_code.write("}\n");
+        reg_code.write("#endif\n");
+else:
+	reg_code.write("""
+static gulong proto_reg_count(void)
+{
+""");
+
+	line = "  return %d;\n" % len(regs['proto_reg'])
+	reg_code.write(line)
+
+	reg_code.write("""
+}
+""");
+	reg_code.write("""
+static gulong handoff_reg_count(void)
+{
+""");
+
+	line = "  return %d;\n" % len(regs['handoff_reg'])
+	reg_code.write(line)
+
+	reg_code.write("""
+}
+""");
+	reg_code.write("""
+gulong register_count(void)
+{
+""");
+
+	line = "  return proto_reg_count() + handoff_reg_count();"
+	reg_code.write(line)
+
+	reg_code.write("""
+}\n
+""");
+
+
+# Close the file
+reg_code.close()
+
+# Remove the old final_file if it exists.
+try:
+	os.stat(final_filename)
+	os.remove(final_filename)
+except OSError:
+	pass
+
+# Move from tmp file to final file
+os.rename(tmp_filename, final_filename)
+
+

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-running/openambit.git



More information about the Pkg-running-devel mailing list