2 * Routines for v120 frame disassembly
3 * Bert Driehuis <driehuis@playbeing.org>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
9 * SPDX-License-Identifier: GPL-2.0-or-later
14 #include <epan/packet.h>
15 #include <epan/xdlc.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
;
31 static int hf_v120_p_ext
;
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
;
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
= {
71 &hf_v120_u_modifier_cmd
,
72 &hf_v120_u_modifier_resp
,
77 /* Used only for I and S frames */
78 static const xdlc_cf_items v120_cf_items_ext
= {
87 &hf_v120_ftype_s_u_ext
91 dissect_v120(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
93 proto_tree
*v120_tree
, *address_tree
;
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");
114 proto_tree_add_protocol_format(tree
, proto_v120
, tvb
, 0, -1,
115 "Invalid V.120 frame");
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");
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
);
159 dissect_v120_header(tvbuff_t
*tvb
, int offset
, proto_tree
*tree
)
166 byte0
= tvb_get_uint8(tvb
, offset
);
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
);
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);
199 proto_register_v120(void)
201 static hf_register_info hf
[] = {
203 { "Link Address", "v120.address", FT_UINT16
, BASE_HEX
, NULL
,
206 { "R/C", "v120.rc", FT_BOOLEAN
, 16, TFS(&tfs_response_command
),
207 0x0002, NULL
, HFILL
}},
209 { "LLI", "v120.lli", FT_UINT16
, BASE_HEX
, NULL
,
210 0xfefc, NULL
, HFILL
}},
212 { "EA0", "v120.ea0", FT_BOOLEAN
, 16, TFS(&tfs_error_ok
),
213 0x0001, NULL
, HFILL
}},
215 { "EA1", "v120.ea1", FT_BOOLEAN
, 16, TFS(&tfs_ok_error
),
216 0x0100, NULL
, HFILL
}},
218 { "Control Field", "v120.control", FT_UINT16
, BASE_HEX
, NULL
, 0x0,
221 { "N(R)", "v120.control.n_r", FT_UINT16
, BASE_DEC
,
222 NULL
, XDLC_N_R_EXT_MASK
, NULL
, HFILL
}},
224 { "N(S)", "v120.control.n_s", FT_UINT16
, BASE_DEC
,
225 NULL
, XDLC_N_S_EXT_MASK
, NULL
, HFILL
}},
227 { "Poll", "v120.control.p", FT_BOOLEAN
, 8,
228 TFS(&tfs_set_notset
), XDLC_P_F
, NULL
, HFILL
}},
230 { "Poll", "v120.control.p", FT_BOOLEAN
, 16,
231 TFS(&tfs_set_notset
), XDLC_P_F_EXT
, NULL
, HFILL
}},
233 { "Final", "v120.control.f", FT_BOOLEAN
, 8,
234 TFS(&tfs_set_notset
), XDLC_P_F
, NULL
, HFILL
}},
236 { "Final", "v120.control.f", FT_BOOLEAN
, 16,
237 TFS(&tfs_set_notset
), XDLC_P_F_EXT
, NULL
, HFILL
}},
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
}},
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
}},
257 { "Header", "v120.header", FT_UINT8
, BASE_HEX
, NULL
, 0x0,
259 { &hf_v120_header_ext8
,
260 { "Extension octet", "v120.header.ext", FT_BOOLEAN
, 8, TFS(&tfs_yes_no
), 0x80,
262 { &hf_v120_header_break8
,
263 { "Break condition", "v120.header.break", FT_BOOLEAN
, 8, TFS(&tfs_yes_no
), 0x40,
265 { &hf_v120_header_error_control8
,
266 { "Error control C1/C2", "v120.error_control", FT_UINT8
, BASE_HEX
, NULL
, 0x0C,
268 { &hf_v120_header_segb8
,
269 { "Bit B", "v120.header.segb", FT_BOOLEAN
, 8, TFS(&tfs_segmentation_no_segmentation
), 0x02,
271 { &hf_v120_header_segf8
,
272 { "Bit F", "v120.header.segf", FT_BOOLEAN
, 8, TFS(&tfs_segmentation_no_segmentation
), 0x01,
275 { "Header", "v120.header", FT_UINT16
, BASE_HEX
, NULL
, 0x0,
277 { &hf_v120_header_ext16
,
278 { "Extension octet", "v120.header.ext", FT_BOOLEAN
, 16, TFS(&tfs_yes_no
), 0x0080,
280 { &hf_v120_header_break16
,
281 { "Break condition", "v120.header.break", FT_BOOLEAN
, 16, TFS(&tfs_yes_no
), 0x0040,
283 { &hf_v120_header_error_control16
,
284 { "Error control C1/C2", "v120.error_control", FT_UINT16
, BASE_HEX
, NULL
, 0x0C,
286 { &hf_v120_header_segb16
,
287 { "Bit B", "v120.header.segb", FT_BOOLEAN
, 16, TFS(&tfs_segmentation_no_segmentation
), 0x0002,
289 { &hf_v120_header_segf16
,
290 { "Bit F", "v120.header.segf", FT_BOOLEAN
, 16, TFS(&tfs_segmentation_no_segmentation
), 0x0001,
293 { "E", "v120.header.e", FT_BOOLEAN
, 16, TFS(&tfs_yes_no
), 0x8000,
295 { &hf_v120_header_dr
,
296 { "DR", "v120.header.dr", FT_BOOLEAN
, 16, TFS(&tfs_yes_no
), 0x4000,
298 { &hf_v120_header_sr
,
299 { "SR", "v120.header.sr", FT_BOOLEAN
, 16, TFS(&tfs_yes_no
), 0x2000,
301 { &hf_v120_header_rr
,
302 { "RR", "v120.header.rr", FT_BOOLEAN
, 16, TFS(&tfs_yes_no
), 0x1000,
305 static int *ett
[] = {
312 proto_v120
= proto_register_protocol("Async data over ISDN (V.120)",
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
326 * indent-tabs-mode: t
329 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
330 * :indentSize=8:tabSize=8:noTabs=false: