aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-v5ef.c
blob: 89afcd1aed5c04bfed1d2c6d506509d6ad9711b9 (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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/* packet-v5ef.c
 * Routines for V5 envelope function frame disassembly
 * Rolf Fiedler <rolf.fiedler@innoventif.de>
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */
/*
 * V5 bitstream over HDLC handling
 *
 * V5 references:
 *
 * ETS 300 324-1
 * ETS 300 347-1
 */

#include "config.h"

#include <epan/packet.h>
#include <wiretap/wtap.h>

void proto_register_v5ef(void);
void proto_reg_handoff_v5ef(void);

static int proto_v5ef = -1;
static int hf_v5ef_direction = -1;
static int hf_v5ef_address = -1;
static int hf_v5ef_eah = -1;
static int hf_v5ef_ea1 = -1;
static int hf_v5ef_eal = -1;
static int hf_v5ef_ea2 = -1;

static gint ett_v5ef = -1;
static gint ett_v5ef_address = -1;

static dissector_handle_t v5dl_handle, lapd_phdr_handle, v5ef_handle;


/*
 * Bits in the address field.
 */
#define	V5EF_EAH		0xfc00	/* Service Access Point Identifier */
#define	V5EF_EAH_SHIFT		10
#define	V5EF_EA1		0x0100	/* First Address Extension bit */
#define	V5EF_EAL		0x00fe	/* Terminal Endpoint Identifier */
#define	V5EF_EAL_SHIFT		1
#define	V5EF_EA2		0x0001	/* Second Address Extension bit */

static const value_string v5ef_direction_vals[] = {
	{ 0,		"AN->LE"},
	{ 1,		"LE->AN"},
	{ 0,		NULL }
};

#define MAX_V5EF_PACKET_LEN 1024

static int
dissect_v5ef(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
{
	struct isdn_phdr *isdn = (struct isdn_phdr *)data;
	proto_tree	*v5ef_tree, *addr_tree;
	proto_item	*v5ef_ti, *addr_ti;
	int		 direction;
	int		 v5ef_header_len;
	guint16		 addr, eah, eal, efaddr;
	tvbuff_t	*next_tvb;
	const char	*srcname = "src";
	const char	*dstname = "dst";

	col_set_str(pinfo->cinfo, COL_PROTOCOL, "V5-EF");
	col_clear(pinfo->cinfo, COL_INFO);

	addr		= tvb_get_ntohs(tvb, 0);
	eah		= (addr & V5EF_EAH) >> V5EF_EAH_SHIFT;
	eal		= (addr & V5EF_EAL) >> V5EF_EAL_SHIFT;
	efaddr		= (eah << 7) + eal;
	v5ef_header_len = 2;	/* addr */

	direction = isdn->uton;
	if (direction==0) {
	        srcname = "LE";
	        dstname = "AN";
	 } else if (direction > 0) {
	        srcname = "AN";
	        dstname = "LE";
	}
	col_set_str(pinfo->cinfo, COL_RES_DL_SRC, srcname);
	col_set_str(pinfo->cinfo, COL_RES_DL_DST, dstname);

	if (tree) {
		proto_item *direction_ti;

		v5ef_ti = proto_tree_add_item(tree, proto_v5ef, tvb, 0, -1,
		    ENC_NA);
		v5ef_tree = proto_item_add_subtree(v5ef_ti, ett_v5ef);

		/*
		 * Don't show the direction if we don't know it.
		 */
		if (direction != P2P_DIR_UNKNOWN) {
			direction_ti = proto_tree_add_uint(v5ef_tree, hf_v5ef_direction,
			                                   tvb, 0, 0, direction);
			proto_item_set_generated(direction_ti);
		}

		addr_ti = proto_tree_add_uint(v5ef_tree, hf_v5ef_address, tvb,
		    0, 2, addr);
		addr_tree = proto_item_add_subtree(addr_ti, ett_v5ef_address);

		proto_tree_add_uint(addr_tree, hf_v5ef_eah,  tvb, 0, 1, addr);
		proto_tree_add_uint(addr_tree, hf_v5ef_ea1, tvb, 0, 1, addr);
		proto_tree_add_uint(addr_tree, hf_v5ef_eal, tvb, 1, 1, addr);
		proto_tree_add_uint(addr_tree, hf_v5ef_ea2, tvb, 1, 1, addr);
	}
	else {
		v5ef_ti	  = NULL;
		v5ef_tree = NULL;
	}

	if (tree)
		proto_item_set_len(v5ef_ti, v5ef_header_len);

	next_tvb = tvb_new_subset_remaining(tvb, v5ef_header_len);

	if (efaddr>8175)
		call_dissector(v5dl_handle,next_tvb, pinfo, tree);
	else
		call_dissector_with_data(lapd_phdr_handle, next_tvb, pinfo, tree, isdn);

	return tvb_captured_length(tvb);
}

void
proto_register_v5ef(void)
{
	static hf_register_info hf[] = {

	{ &hf_v5ef_direction,
	  { "Direction", "v5ef.direction", FT_UINT8, BASE_DEC, VALS(v5ef_direction_vals), 0x0,
	  	NULL, HFILL }},

	{ &hf_v5ef_address,
	  { "Address Field", "v5ef.address", FT_UINT16, BASE_HEX, NULL, 0x0,
	  	"Address", HFILL }},

	{ &hf_v5ef_eah,
	  { "EAH", "v5ef.eah", FT_UINT16, BASE_DEC, NULL, V5EF_EAH,
	  	"Envelope Address High Part", HFILL }},

	{ &hf_v5ef_ea1,
	  { "EA1", "v5ef.ea1", FT_UINT16, BASE_DEC, NULL, V5EF_EA1,
	  	"First Address Extension bit", HFILL }},

	{ &hf_v5ef_eal,
	  { "EAL", "v5ef.eal", FT_UINT16, BASE_DEC, NULL, V5EF_EAL,
	  	"Envelope Address Low Part", HFILL }},

	{ &hf_v5ef_ea2,
	  { "EA2", "v5ef.ea2", FT_UINT16, BASE_DEC, NULL, V5EF_EA2,
	  	"Second Address Extension bit", HFILL }},
	};

	static gint *ett[] = {
		&ett_v5ef,
		&ett_v5ef_address,
	};

	proto_v5ef = proto_register_protocol("V5 Envelope Function (v5ef)",
					 "v5ef", "v5ef");
	proto_register_field_array (proto_v5ef, hf, array_length(hf));
	proto_register_subtree_array(ett, array_length(ett));

	v5ef_handle = register_dissector("v5ef", dissect_v5ef, proto_v5ef);
}

void
proto_reg_handoff_v5ef(void)
{
	dissector_add_uint("wtap_encap", WTAP_ENCAP_V5_EF, v5ef_handle);

	lapd_phdr_handle = find_dissector_add_dependency("lapd-phdr", proto_v5ef);
	v5dl_handle = find_dissector_add_dependency("v5dl", proto_v5ef);
}

/*
 * 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:
 */