Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-v120.c
blob989e54826a7cf30debae213e17c6c3ee5ce1f5bc
1 /* packet-v120.c
2 * Routines for v120 frame disassembly
3 * Bert Driehuis <driehuis@playbeing.org>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include "config.h"
14 #include <epan/packet.h>
15 #include <epan/xdlc.h>
16 #include <epan/tfs.h>
17 #include <wsutil/array.h>
19 void proto_register_v120(void);
21 static int proto_v120;
22 static int hf_v120_address;
23 static int hf_v120_rc;
24 static int hf_v120_lli;
25 static int hf_v120_ea0;
26 static int hf_v120_ea1;
27 static int hf_v120_control;
28 static int hf_v120_n_r;
29 static int hf_v120_n_s;
30 static int hf_v120_p;
31 static int hf_v120_p_ext;
32 static int hf_v120_f;
33 static int hf_v120_f_ext;
34 static int hf_v120_s_ftype;
35 static int hf_v120_u_modifier_cmd;
36 static int hf_v120_u_modifier_resp;
37 static int hf_v120_ftype_i;
38 static int hf_v120_ftype_s_u;
39 static int hf_v120_ftype_s_u_ext;
40 static int hf_v120_header8;
41 static int hf_v120_header_ext8;
42 static int hf_v120_header_break8;
43 static int hf_v120_header_error_control8;
44 static int hf_v120_header_segb8;
45 static int hf_v120_header_segf8;
46 static int hf_v120_header16;
47 static int hf_v120_header_ext16;
48 static int hf_v120_header_break16;
49 static int hf_v120_header_error_control16;
50 static int hf_v120_header_segb16;
51 static int hf_v120_header_segf16;
52 static int hf_v120_header_e;
53 static int hf_v120_header_dr;
54 static int hf_v120_header_sr;
55 static int hf_v120_header_rr;
57 static int ett_v120;
58 static int ett_v120_address;
59 static int ett_v120_control;
60 static int ett_v120_header;
62 static int dissect_v120_header(tvbuff_t *tvb, int offset, proto_tree *tree);
64 /* Used only for U frames */
65 static const xdlc_cf_items v120_cf_items = {
66 NULL,
67 NULL,
68 &hf_v120_p,
69 &hf_v120_f,
70 NULL,
71 &hf_v120_u_modifier_cmd,
72 &hf_v120_u_modifier_resp,
73 NULL,
74 &hf_v120_ftype_s_u
77 /* Used only for I and S frames */
78 static const xdlc_cf_items v120_cf_items_ext = {
79 &hf_v120_n_r,
80 &hf_v120_n_s,
81 &hf_v120_p_ext,
82 &hf_v120_f_ext,
83 &hf_v120_s_ftype,
84 NULL,
85 NULL,
86 &hf_v120_ftype_i,
87 &hf_v120_ftype_s_u_ext
90 static int
91 dissect_v120(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
93 proto_tree *v120_tree, *address_tree;
94 proto_item *ti, *tc;
95 int is_response;
96 int v120len;
97 uint8_t byte0, byte1;
98 uint16_t control;
99 tvbuff_t *next_tvb;
101 col_set_str(pinfo->cinfo, COL_PROTOCOL, "V.120");
102 col_clear(pinfo->cinfo, COL_INFO);
104 byte0 = tvb_get_uint8(tvb, 0);
106 col_add_fstr(pinfo->cinfo, COL_RES_DL_SRC, "0x%02X", byte0);
108 byte1 = tvb_get_uint8(tvb, 1);
110 if ( ((byte0 & 0x01) != 0x00) && ((byte1 & 0x01) != 0x01) )
112 col_set_str(pinfo->cinfo, COL_INFO, "Invalid V.120 frame");
113 if (tree)
114 proto_tree_add_protocol_format(tree, proto_v120, tvb, 0, -1,
115 "Invalid V.120 frame");
116 return 2;
119 if (pinfo->p2p_dir == P2P_DIR_SENT) {
120 is_response = (byte0 & 0x02) ? false: true;
121 col_set_str(pinfo->cinfo, COL_RES_DL_DST, "DCE");
122 col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "DTE");
123 } else {
124 /* XXX - what if the direction is unknown? */
125 is_response = (byte0 & 0x02) ? true : false;
126 col_set_str(pinfo->cinfo, COL_RES_DL_DST, "DTE");
127 col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "DCE");
130 ti = proto_tree_add_protocol_format(tree, proto_v120, tvb, 0, -1, "V.120");
131 v120_tree = proto_item_add_subtree(ti, ett_v120);
132 tc = proto_tree_add_item(v120_tree, hf_v120_address, tvb, 0, 2, ENC_BIG_ENDIAN);
133 proto_item_append_text(tc, "LLI: %d C/R: %s",
134 ((byte0 & 0xfc) << 5) | ((byte1 & 0xfe) >> 1),
135 byte0 & 0x02 ? "R" : "C");
136 address_tree = proto_item_add_subtree(tc, ett_v120_address);
138 proto_tree_add_item(address_tree, hf_v120_rc, tvb, 0, 2, ENC_BIG_ENDIAN);
139 proto_tree_add_item(address_tree, hf_v120_lli, tvb, 0, 2, ENC_BIG_ENDIAN);
140 proto_tree_add_item(address_tree, hf_v120_ea0, tvb, 0, 2, ENC_BIG_ENDIAN);
141 proto_tree_add_item(address_tree, hf_v120_ea1, tvb, 0, 2, ENC_BIG_ENDIAN);
143 control = dissect_xdlc_control(tvb, 2, pinfo, v120_tree, hf_v120_control,
144 ett_v120_control, &v120_cf_items, &v120_cf_items_ext,
145 NULL, NULL, is_response, true, false);
147 v120len = 2 + XDLC_CONTROL_LEN(control, true);
149 if (tvb_bytes_exist(tvb, v120len, 1))
150 v120len += dissect_v120_header(tvb, v120len, v120_tree);
151 proto_item_set_len(ti, v120len);
152 next_tvb = tvb_new_subset_remaining(tvb, v120len);
153 call_data_dissector(next_tvb, pinfo, v120_tree);
155 return tvb_captured_length(tvb);
158 static int
159 dissect_v120_header(tvbuff_t *tvb, int offset, proto_tree *tree)
161 int header_len;
162 uint8_t byte0;
163 proto_tree *h_tree;
164 proto_item *tc;
166 byte0 = tvb_get_uint8(tvb, offset);
167 if (byte0 & 0x80) {
168 header_len = 1;
169 tc = proto_tree_add_item(tree, hf_v120_header8, tvb, 0, 1, ENC_BIG_ENDIAN);
171 h_tree = proto_item_add_subtree(tc, ett_v120_header);
172 proto_tree_add_item(h_tree, hf_v120_header_ext8, tvb, 0, 1, ENC_NA);
173 proto_tree_add_item(h_tree, hf_v120_header_break8, tvb, 0, 1, ENC_NA);
174 proto_tree_add_item(h_tree, hf_v120_header_error_control8, tvb, 0, 1, ENC_BIG_ENDIAN);
175 proto_tree_add_item(h_tree, hf_v120_header_segb8, tvb, 0, 1, ENC_NA);
176 proto_tree_add_item(h_tree, hf_v120_header_segf8, tvb, 0, 1, ENC_NA);
177 } else {
178 header_len = 2;
179 tc = proto_tree_add_item(tree, hf_v120_header16, tvb, 0, 2, ENC_BIG_ENDIAN);
180 h_tree = proto_item_add_subtree(tc, ett_v120_header);
181 proto_tree_add_item(h_tree, hf_v120_header_ext16, tvb, 0, 2, ENC_BIG_ENDIAN);
182 proto_tree_add_item(h_tree, hf_v120_header_break16, tvb, 0, 2, ENC_BIG_ENDIAN);
183 proto_tree_add_item(h_tree, hf_v120_header_error_control16, tvb, 0, 2, ENC_BIG_ENDIAN);
184 proto_tree_add_item(h_tree, hf_v120_header_segb16, tvb, 0, 2, ENC_BIG_ENDIAN);
185 proto_tree_add_item(h_tree, hf_v120_header_segf16, tvb, 0, 2, ENC_BIG_ENDIAN);
186 proto_tree_add_item(h_tree, hf_v120_header_e, tvb, 0, 2, ENC_BIG_ENDIAN);
187 proto_tree_add_item(h_tree, hf_v120_header_dr, tvb, 0, 2, ENC_BIG_ENDIAN);
188 proto_tree_add_item(h_tree, hf_v120_header_sr, tvb, 0, 2, ENC_BIG_ENDIAN);
189 proto_tree_add_item(h_tree, hf_v120_header_rr, tvb, 0, 2, ENC_BIG_ENDIAN);
192 proto_item_append_text(tc, " B: %d F: %d",
193 byte0 & 0x02 ? 1:0, byte0 & 0x01 ? 1:0);
195 return header_len;
198 void
199 proto_register_v120(void)
201 static hf_register_info hf[] = {
202 { &hf_v120_address,
203 { "Link Address", "v120.address", FT_UINT16, BASE_HEX, NULL,
204 0x0, NULL, HFILL }},
205 { &hf_v120_rc,
206 { "R/C", "v120.rc", FT_BOOLEAN, 16, TFS(&tfs_response_command),
207 0x0002, NULL, HFILL }},
208 { &hf_v120_lli,
209 { "LLI", "v120.lli", FT_UINT16, BASE_HEX, NULL,
210 0xfefc, NULL, HFILL }},
211 { &hf_v120_ea0,
212 { "EA0", "v120.ea0", FT_BOOLEAN, 16, TFS(&tfs_error_ok),
213 0x0001, NULL, HFILL }},
214 { &hf_v120_ea1,
215 { "EA1", "v120.ea1", FT_BOOLEAN, 16, TFS(&tfs_ok_error),
216 0x0100, NULL, HFILL }},
217 { &hf_v120_control,
218 { "Control Field", "v120.control", FT_UINT16, BASE_HEX, NULL, 0x0,
219 NULL, HFILL }},
220 { &hf_v120_n_r,
221 { "N(R)", "v120.control.n_r", FT_UINT16, BASE_DEC,
222 NULL, XDLC_N_R_EXT_MASK, NULL, HFILL }},
223 { &hf_v120_n_s,
224 { "N(S)", "v120.control.n_s", FT_UINT16, BASE_DEC,
225 NULL, XDLC_N_S_EXT_MASK, NULL, HFILL }},
226 { &hf_v120_p,
227 { "Poll", "v120.control.p", FT_BOOLEAN, 8,
228 TFS(&tfs_set_notset), XDLC_P_F, NULL, HFILL }},
229 { &hf_v120_p_ext,
230 { "Poll", "v120.control.p", FT_BOOLEAN, 16,
231 TFS(&tfs_set_notset), XDLC_P_F_EXT, NULL, HFILL }},
232 { &hf_v120_f,
233 { "Final", "v120.control.f", FT_BOOLEAN, 8,
234 TFS(&tfs_set_notset), XDLC_P_F, NULL, HFILL }},
235 { &hf_v120_f_ext,
236 { "Final", "v120.control.f", FT_BOOLEAN, 16,
237 TFS(&tfs_set_notset), XDLC_P_F_EXT, NULL, HFILL }},
238 { &hf_v120_s_ftype,
239 { "Supervisory frame type", "v120.control.s_ftype", FT_UINT16, BASE_HEX,
240 VALS(stype_vals), XDLC_S_FTYPE_MASK, NULL, HFILL }},
241 { &hf_v120_u_modifier_cmd,
242 { "Command", "v120.control.u_modifier_cmd", FT_UINT8, BASE_HEX,
243 VALS(modifier_vals_cmd), XDLC_U_MODIFIER_MASK, NULL, HFILL }},
244 { &hf_v120_u_modifier_resp,
245 { "Response", "v120.control.u_modifier_resp", FT_UINT8, BASE_HEX,
246 VALS(modifier_vals_resp), XDLC_U_MODIFIER_MASK, NULL, HFILL }},
247 { &hf_v120_ftype_i,
248 { "Frame type", "v120.control.ftype", FT_UINT16, BASE_HEX,
249 VALS(ftype_vals), XDLC_I_MASK, NULL, HFILL }},
250 { &hf_v120_ftype_s_u,
251 { "Frame type", "v120.control.ftype", FT_UINT8, BASE_HEX,
252 VALS(ftype_vals), XDLC_S_U_MASK, NULL, HFILL }},
253 { &hf_v120_ftype_s_u_ext,
254 { "Frame type", "v120.control.ftype", FT_UINT16, BASE_HEX,
255 VALS(ftype_vals), XDLC_S_U_MASK, NULL, HFILL }},
256 { &hf_v120_header8,
257 { "Header", "v120.header", FT_UINT8, BASE_HEX, NULL, 0x0,
258 NULL, HFILL }},
259 { &hf_v120_header_ext8,
260 { "Extension octet", "v120.header.ext", FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x80,
261 NULL, HFILL }},
262 { &hf_v120_header_break8,
263 { "Break condition", "v120.header.break", FT_BOOLEAN, 8, TFS(&tfs_yes_no), 0x40,
264 NULL, HFILL }},
265 { &hf_v120_header_error_control8,
266 { "Error control C1/C2", "v120.error_control", FT_UINT8, BASE_HEX, NULL, 0x0C,
267 NULL, HFILL }},
268 { &hf_v120_header_segb8,
269 { "Bit B", "v120.header.segb", FT_BOOLEAN, 8, TFS(&tfs_segmentation_no_segmentation), 0x02,
270 NULL, HFILL }},
271 { &hf_v120_header_segf8,
272 { "Bit F", "v120.header.segf", FT_BOOLEAN, 8, TFS(&tfs_segmentation_no_segmentation), 0x01,
273 NULL, HFILL }},
274 { &hf_v120_header16,
275 { "Header", "v120.header", FT_UINT16, BASE_HEX, NULL, 0x0,
276 NULL, HFILL }},
277 { &hf_v120_header_ext16,
278 { "Extension octet", "v120.header.ext", FT_BOOLEAN, 16, TFS(&tfs_yes_no), 0x0080,
279 NULL, HFILL }},
280 { &hf_v120_header_break16,
281 { "Break condition", "v120.header.break", FT_BOOLEAN, 16, TFS(&tfs_yes_no), 0x0040,
282 NULL, HFILL }},
283 { &hf_v120_header_error_control16,
284 { "Error control C1/C2", "v120.error_control", FT_UINT16, BASE_HEX, NULL, 0x0C,
285 NULL, HFILL }},
286 { &hf_v120_header_segb16,
287 { "Bit B", "v120.header.segb", FT_BOOLEAN, 16, TFS(&tfs_segmentation_no_segmentation), 0x0002,
288 NULL, HFILL }},
289 { &hf_v120_header_segf16,
290 { "Bit F", "v120.header.segf", FT_BOOLEAN, 16, TFS(&tfs_segmentation_no_segmentation), 0x0001,
291 NULL, HFILL }},
292 { &hf_v120_header_e,
293 { "E", "v120.header.e", FT_BOOLEAN, 16, TFS(&tfs_yes_no), 0x8000,
294 NULL, HFILL }},
295 { &hf_v120_header_dr,
296 { "DR", "v120.header.dr", FT_BOOLEAN, 16, TFS(&tfs_yes_no), 0x4000,
297 NULL, HFILL }},
298 { &hf_v120_header_sr,
299 { "SR", "v120.header.sr", FT_BOOLEAN, 16, TFS(&tfs_yes_no), 0x2000,
300 NULL, HFILL }},
301 { &hf_v120_header_rr,
302 { "RR", "v120.header.rr", FT_BOOLEAN, 16, TFS(&tfs_yes_no), 0x1000,
303 NULL, HFILL }},
305 static int *ett[] = {
306 &ett_v120,
307 &ett_v120_address,
308 &ett_v120_control,
309 &ett_v120_header,
312 proto_v120 = proto_register_protocol("Async data over ISDN (V.120)",
313 "V.120", "v120");
314 proto_register_field_array (proto_v120, hf, array_length(hf));
315 proto_register_subtree_array(ett, array_length(ett));
317 register_dissector("v120", dissect_v120, proto_v120);
321 * Editor modelines - https://www.wireshark.org/tools/modelines.html
323 * Local variables:
324 * c-basic-offset: 8
325 * tab-width: 8
326 * indent-tabs-mode: t
327 * End:
329 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
330 * :indentSize=8:tabSize=8:noTabs=false: