add DXL dissector.
authorDario Lombardo <lomato@gmail.com>
Sun, 1 Jul 2018 10:51:35 +0000 (12:51 +0200)
committerAnders Broman <a.broman58@gmail.com>
Sun, 22 Jul 2018 08:04:12 +0000 (08:04 +0000)
Change-Id: I5aeccf54d1ab6b9b4098fb3dbf529550c57319e8
Reviewed-on: https://code.wireshark.org/review/28662
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
docbook/release-notes.asciidoc
epan/dissectors/CMakeLists.txt
epan/dissectors/packet-dxl.c [new file with mode: 0644]

index b7e2d00dce209f97988ad93d781f670930320148..2893af1a699601dfe2b59e1f997ac41dee4710ae 100644 (file)
@@ -80,6 +80,7 @@ Cisco Meraki Discovery Protocol (MDP)
 XnAP (5G) protocol
 E1AP (5G) protocol
 MsgPack protocol
+DXL protocol
 --
 
 === Updated Protocol Support
index 1a10a2c1e574b1ba27d2cdd573bec05779e4094f..08df528892a2ce2ff07b1c21683b8e91ef0fe1d5 100644 (file)
@@ -933,6 +933,7 @@ set(DISSECTOR_SRC
        ${CMAKE_CURRENT_SOURCE_DIR}/packet-dvb-tot.c
        ${CMAKE_CURRENT_SOURCE_DIR}/packet-dvbci.c
        ${CMAKE_CURRENT_SOURCE_DIR}/packet-dvmrp.c
+       ${CMAKE_CURRENT_SOURCE_DIR}/packet-dxl.c
        ${CMAKE_CURRENT_SOURCE_DIR}/packet-e100.c
        ${CMAKE_CURRENT_SOURCE_DIR}/packet-e164.c
        ${CMAKE_CURRENT_SOURCE_DIR}/packet-e212.c
diff --git a/epan/dissectors/packet-dxl.c b/epan/dissectors/packet-dxl.c
new file mode 100644 (file)
index 0000000..8a8d5f9
--- /dev/null
@@ -0,0 +1,153 @@
+/* packet-dxl.c
+ *
+ * Routines for DXL dissection
+ * Github projects:
+ *  https://github.com/opendxl
+ *
+ * Copyright 2018, Dario Lombardo <lomato@gmail.com>
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "config.h"
+
+#include <epan/packet.h>
+#include <epan/tvbuff.h>
+#include <epan/expert.h>
+
+void proto_register_dxl(void);
+
+static int proto_dxl = -1;
+
+static int hf_dxl_version = -1;
+static int hf_dxl_type = -1;
+
+static gint ett_dxl = -1;
+
+static expert_field ei_dxl_unsupported = EI_INIT;
+
+static dissector_handle_t msgpack_handle;
+
+#define DXL_REQUEST 0
+#define DXL_RESPONSE 1
+#define DXL_EVENT 2
+#define DXL_ERROR 3
+
+static const value_string dxl_message_types[] = {
+       { DXL_REQUEST, "Request" },
+       { DXL_RESPONSE, "Response" },
+       { DXL_EVENT, "Event" },
+       { DXL_ERROR, "Error" },
+       { 0, NULL }
+};
+
+static void dissect_dxl_event(tvbuff_t* tvb, packet_info* pinfo, proto_tree* dxl_tree, gint* offset)
+{
+       tvbuff_t* tvb_msgpack;
+
+       tvb_msgpack = tvb_new_subset_remaining(tvb, *offset);
+       *offset = call_dissector_with_data(msgpack_handle, tvb_msgpack, pinfo, dxl_tree, "Message ID");
+
+       tvb_msgpack = tvb_new_subset_remaining(tvb_msgpack, *offset);
+       *offset = call_dissector_with_data(msgpack_handle, tvb_msgpack, pinfo, dxl_tree, "Client ID");
+
+       tvb_msgpack = tvb_new_subset_remaining(tvb_msgpack, *offset);
+       *offset = call_dissector_with_data(msgpack_handle, tvb_msgpack, pinfo, dxl_tree, "Source Broker ID");
+
+       tvb_msgpack = tvb_new_subset_remaining(tvb_msgpack, *offset);
+       *offset = call_dissector_with_data(msgpack_handle, tvb_msgpack, pinfo, dxl_tree, "Broker IDs");
+
+       tvb_msgpack = tvb_new_subset_remaining(tvb_msgpack, *offset);
+       *offset = call_dissector_with_data(msgpack_handle, tvb_msgpack, pinfo, dxl_tree, "Client IDs");
+
+       tvb_msgpack = tvb_new_subset_remaining(tvb_msgpack, *offset);
+       *offset = call_dissector_with_data(msgpack_handle, tvb_msgpack, pinfo, dxl_tree, "Payload");
+
+       tvb_msgpack = tvb_new_subset_remaining(tvb_msgpack, *offset);
+       *offset = call_dissector_with_data(msgpack_handle, tvb_msgpack, pinfo, dxl_tree, "Reply to topic");
+
+       tvb_msgpack = tvb_new_subset_remaining(tvb_msgpack, *offset);
+       *offset = call_dissector_with_data(msgpack_handle, tvb_msgpack, pinfo, dxl_tree, "Service ID");
+}
+
+static int dissect_dxl(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, void* data _U_)
+{
+       gint offset = 0;
+       proto_item* ti;
+       proto_tree* dxl_tree;
+       guint8 type;
+
+       ti = proto_tree_add_item(tree, proto_dxl, tvb, 0, -1, ENC_NA);
+       dxl_tree = proto_item_add_subtree(ti, ett_dxl);
+
+       proto_tree_add_item(dxl_tree, hf_dxl_version, tvb, offset, 1, ENC_NA);
+       offset += 1;
+
+       type = tvb_get_guint8(tvb, offset);
+
+       proto_tree_add_item(dxl_tree, hf_dxl_type, tvb, offset, 1, ENC_NA);
+       offset += 1;
+
+       switch (type) {
+               case DXL_REQUEST:
+               case DXL_RESPONSE:
+               case DXL_ERROR:
+                       expert_add_info_format(pinfo, tree, &ei_dxl_unsupported, "Type 0x%x is unsupported", type);
+                       break;
+               case DXL_EVENT:
+                       dissect_dxl_event(tvb, pinfo, dxl_tree, &offset);
+                       break;
+       }
+
+       return offset;
+}
+
+void proto_register_dxl(void)
+{
+       expert_module_t* expert_dxl;
+
+       static hf_register_info hf[] = {
+               { &hf_dxl_version,
+                       { "Version", "dxl.version", FT_UINT8, BASE_DEC, NULL, 0x00, NULL, HFILL }
+               },
+               { &hf_dxl_type,
+                       { "Type", "dxl.type", FT_UINT8, BASE_HEX, VALS(dxl_message_types), 0x00, NULL, HFILL }
+               }
+       };
+
+       static gint* ett[] = {
+               &ett_dxl
+       };
+
+       proto_dxl = proto_register_protocol("Data Exchange Layer", "DXL", "dxl");
+       register_dissector("dxl", dissect_dxl, proto_dxl);
+
+       proto_register_field_array(proto_dxl, hf, array_length(hf));
+       proto_register_subtree_array(ett, array_length(ett));
+
+       static ei_register_info ei[] = {
+               { &ei_dxl_unsupported, { "dxl.type.unsupported", PI_UNDECODED, PI_WARN, "Unsupported DXL message", EXPFILL }}
+       };
+
+       expert_dxl = expert_register_protocol(proto_dxl);
+       expert_register_field_array(expert_dxl, ei, array_length(ei));
+
+       msgpack_handle = find_dissector("msgpack");
+}
+
+/*
+ * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
+ *
+ * Local variables:
+ * c-basic-offset: 8
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * End:
+ *
+ * vi: set shiftwidth=8 tabstop=8 noexpandtab:
+ * :indentSize=8:tabSize=8:noTabs=false:
+ */