diff options
author | Dario Lombardo <lomato@gmail.com> | 2018-07-01 12:51:35 +0200 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2018-07-22 08:04:12 +0000 |
commit | 8eafe0e41b7c8fc1aa070184cb55965159dc0977 (patch) | |
tree | 8550e8c0c6d89c9ebd6c6145dd962b6a403ef837 /epan/dissectors/packet-dxl.c | |
parent | b93ece3780752163ce6b90f9036c9faa91a61b99 (diff) |
add DXL dissector.
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>
Diffstat (limited to 'epan/dissectors/packet-dxl.c')
-rw-r--r-- | epan/dissectors/packet-dxl.c | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/epan/dissectors/packet-dxl.c b/epan/dissectors/packet-dxl.c new file mode 100644 index 0000000000..8a8d5f9117 --- /dev/null +++ b/epan/dissectors/packet-dxl.c @@ -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: + */ |