aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-dxl.c
blob: 2c5202e61dac9eeb9891f18f0c075e3909ef11bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* 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);
void proto_reg_handoff_dxl(void);

static int proto_dxl;

static int hf_dxl_version;
static int hf_dxl_type;

static gint ett_dxl;

static expert_field ei_dxl_unsupported;

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_reg_handoff_dxl(void)
{
	msgpack_handle = find_dissector("msgpack");
}

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));
}

/*
 * Editor modelines  -  https://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:
 */