2 * Routines for use by various SDLC-derived protocols, such as HDLC
3 * and its derivatives LAPB, IEEE 802.2 LLC, etc..
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 #include <epan/packet.h>
31 #include <epan/xdlc.h>
32 #include <wsutil/pint.h>
34 const value_string ftype_vals[] = {
35 { XDLC_I, "Information frame" },
36 { XDLC_S, "Supervisory frame" },
37 { XDLC_U, "Unnumbered frame" },
41 const value_string stype_vals[] = {
42 { XDLC_RR>>2, "Receiver ready" },
43 { XDLC_RNR>>2, "Receiver not ready" },
44 { XDLC_REJ>>2, "Reject" },
45 { XDLC_SREJ>>2, "Selective reject" },
49 static const value_string modifier_short_vals_cmd[] = {
52 { XDLC_DISC, "DISC" },
54 { XDLC_SNRM, "SNRM" },
55 { XDLC_SNRME, "SNRME" },
56 { XDLC_TEST, "TEST" },
58 { XDLC_FRMR, "FRMR" },
59 { XDLC_CFGR, "CFGR" },
60 { XDLC_SARM, "SARM" },
61 { XDLC_SABM, "SABM" },
62 { XDLC_SARME, "SARME" },
63 { XDLC_SABME, "SABME" },
64 { XDLC_RESET, "RESET" },
66 { XDLC_SNRME, "SNRME" },
71 const value_string modifier_vals_cmd[] = {
72 { XDLC_UI>>2, "Unnumbered Information" },
73 { XDLC_UP>>2, "Unnumbered Poll" },
74 { XDLC_DISC>>2, "Disconnect" },
75 { XDLC_UA>>2, "Unnumbered Acknowledge" },
76 { XDLC_SNRM>>2, "Set Normal Response Mode" },
77 { XDLC_TEST>>2, "Test" },
78 { XDLC_SIM>>2, "Set Initialization Mode" },
79 { XDLC_FRMR>>2, "Frame reject" },
80 { XDLC_CFGR>>2, "Configure" },
81 { XDLC_SARM>>2, "Set Asynchronous Response Mode" },
82 { XDLC_SABM>>2, "Set Asynchronous Balanced Mode" },
83 { XDLC_SARME>>2, "Set Asynchronous Response Mode Extended" },
84 { XDLC_SABME>>2, "Set Asynchronous Balanced Mode Extended" },
85 { XDLC_RESET>>2, "Reset" },
86 { XDLC_XID>>2, "Exchange identification" },
87 { XDLC_SNRME>>2, "Set Normal Response Mode Extended" },
88 { XDLC_BCN>>2, "Beacon" },
92 static const value_string modifier_short_vals_resp[] = {
97 { XDLC_SNRM, "SNRM" },
98 { XDLC_TEST, "TEST" },
100 { XDLC_FRMR, "FRMR" },
101 { XDLC_CFGR, "CFGR" },
103 { XDLC_SABM, "SABM" },
104 { XDLC_SARME, "SARME" },
105 { XDLC_SABME, "SABME" },
106 { XDLC_RESET, "RESET" },
108 { XDLC_SNRME, "SNRME" },
113 const value_string modifier_vals_resp[] = {
114 { XDLC_UI>>2, "Unnumbered Information" },
115 { XDLC_UP>>2, "Unnumbered Poll" },
116 { XDLC_RD>>2, "Request Disconnect" },
117 { XDLC_UA>>2, "Unnumbered Acknowledge" },
118 { XDLC_SNRM>>2, "Set Normal Response Mode" },
119 { XDLC_TEST>>2, "Test" },
120 { XDLC_RIM>>2, "Request Initialization Mode" },
121 { XDLC_FRMR>>2, "Frame reject" },
122 { XDLC_CFGR>>2, "Configure" },
123 { XDLC_DM>>2, "Disconnected mode" },
124 { XDLC_SABM>>2, "Set Asynchronous Balanced Mode" },
125 { XDLC_SARME>>2, "Set Asynchronous Response Mode Extended" },
126 { XDLC_SABME>>2, "Set Asynchronous Balanced Mode Extended" },
127 { XDLC_RESET>>2, "Reset" },
128 { XDLC_XID>>2, "Exchange identification" },
129 { XDLC_SNRME>>2, "Set Normal Response Mode Extended" },
130 { XDLC_BCN>>2, "Beacon" },
135 get_xdlc_control(const guchar *pd, int offset, gboolean is_extended)
139 switch (pd[offset] & 0x03) {
144 * Supervisory or Information frame.
147 control = pletoh16(&pd[offset]);
149 control = pd[offset];
156 * XXX - is this two octets, with a P/F bit, in HDLC extended
157 * operation? It's one octet in LLC, even though the control
158 * field of I and S frames is a 2-byte extended-operation field
159 * in LLC. Given that there are no sequence numbers in the
160 * control field of a U frame, there doesn't appear to be any
161 * need for it to be 2 bytes in extended operation.
163 control = pd[offset];
170 dissect_xdlc_control(tvbuff_t *tvb, int offset, packet_info *pinfo,
171 proto_tree *xdlc_tree, int hf_xdlc_control, gint ett_xdlc_control,
172 const xdlc_cf_items *cf_items_nonext, const xdlc_cf_items *cf_items_ext,
173 const value_string *u_modifier_short_vals_cmd,
174 const value_string *u_modifier_short_vals_resp, gboolean is_response,
175 gboolean is_extended, gboolean append_info)
179 const xdlc_cf_items *cf_items;
180 const char *control_format;
183 proto_tree *tc, *control_tree;
184 const gchar *frame_type = NULL;
185 const gchar *modifier;
187 info=(char *)wmem_alloc(wmem_packet_scope(), 80);
188 switch (tvb_get_guint8(tvb, offset) & 0x03) {
195 control = tvb_get_letohs(tvb, offset);
197 cf_items = cf_items_ext;
198 control_format = "Control field: %s (0x%04X)";
200 control = tvb_get_guint8(tvb, offset);
202 cf_items = cf_items_nonext;
203 control_format = "Control field: %s (0x%02X)";
205 switch (control & XDLC_S_FTYPE_MASK) {
223 poll_final = (control & XDLC_P_F_EXT);
224 g_snprintf(info, 80, "S%s, func=%s, N(R)=%u",
226 (is_response ? " F" : " P") :
229 (control & XDLC_N_R_EXT_MASK) >> XDLC_N_R_EXT_SHIFT);
231 poll_final = (control & XDLC_P_F);
232 g_snprintf(info, 80, "S%s, func=%s, N(R)=%u",
234 (is_response ? " F" : " P") :
237 (control & XDLC_N_R_MASK) >> XDLC_N_R_SHIFT);
240 col_append_str(pinfo->cinfo, COL_INFO, ", ");
241 col_append_str(pinfo->cinfo, COL_INFO, info);
243 col_add_str(pinfo->cinfo, COL_INFO, info);
246 tc = proto_tree_add_uint_format(xdlc_tree, hf_xdlc_control, tvb,
247 offset, control_len, control, control_format, info, control);
248 control_tree = proto_item_add_subtree(tc, ett_xdlc_control);
249 proto_tree_add_uint(control_tree, *cf_items->hf_xdlc_n_r,
250 tvb, offset, control_len, control);
252 proto_tree_add_boolean(control_tree,
253 (is_response ? *cf_items->hf_xdlc_f :
254 *cf_items->hf_xdlc_p),
255 tvb, offset, control_len, control);
257 proto_tree_add_uint(control_tree, *cf_items->hf_xdlc_s_ftype,
258 tvb, offset, control_len, control);
259 /* This will always say it's a supervisory frame */
260 proto_tree_add_uint(control_tree, *cf_items->hf_xdlc_ftype_s_u,
261 tvb, offset, control_len, control);
269 * XXX - is this two octets, with a P/F bit, in HDLC extended
270 * operation? It's one octet in LLC, even though the control
271 * field of I and S frames is a 2-byte extended-operation field
272 * in LLC. Given that there are no sequence numbers in the
273 * control field of a U frame, there doesn't appear to be any
274 * need for it to be 2 bytes in extended operation.
276 if (u_modifier_short_vals_cmd == NULL)
277 u_modifier_short_vals_cmd = modifier_short_vals_cmd;
278 if (u_modifier_short_vals_resp == NULL)
279 u_modifier_short_vals_resp = modifier_short_vals_resp;
280 control = tvb_get_guint8(tvb, offset);
282 cf_items = cf_items_nonext;
283 control_format = "Control field: %s (0x%02X)";
285 modifier = val_to_str(control & XDLC_U_MODIFIER_MASK,
286 u_modifier_short_vals_resp, "Unknown");
288 modifier = val_to_str(control & XDLC_U_MODIFIER_MASK,
289 u_modifier_short_vals_cmd, "Unknown");
291 poll_final = (control & XDLC_P_F);
292 g_snprintf(info, 80, "U%s, func=%s",
294 (is_response ? " F" : " P") :
298 col_append_str(pinfo->cinfo, COL_INFO, ", ");
299 col_append_str(pinfo->cinfo, COL_INFO, info);
301 col_add_str(pinfo->cinfo, COL_INFO, info);
304 tc = proto_tree_add_uint_format(xdlc_tree, hf_xdlc_control, tvb,
305 offset, control_len, control, control_format, info, control);
306 control_tree = proto_item_add_subtree(tc, ett_xdlc_control);
308 proto_tree_add_boolean(control_tree,
309 (is_response ? *cf_items->hf_xdlc_f:
310 *cf_items->hf_xdlc_p),
311 tvb, offset, control_len, control);
313 proto_tree_add_uint(control_tree,
314 (is_response ? *cf_items->hf_xdlc_u_modifier_resp :
315 *cf_items->hf_xdlc_u_modifier_cmd),
316 tvb, offset, control_len, control);
317 /* This will always say it's an unnumbered frame */
318 proto_tree_add_uint(control_tree, *cf_items->hf_xdlc_ftype_s_u,
319 tvb, offset, control_len, control);
328 control = tvb_get_letohs(tvb, offset);
330 cf_items = cf_items_ext;
331 control_format = "Control field: %s (0x%04X)";
332 poll_final = (control & XDLC_P_F_EXT);
333 g_snprintf(info, 80, "I%s, N(R)=%u, N(S)=%u",
334 ((control & XDLC_P_F_EXT) ? " P" : ""),
335 (control & XDLC_N_R_EXT_MASK) >> XDLC_N_R_EXT_SHIFT,
336 (control & XDLC_N_S_EXT_MASK) >> XDLC_N_S_EXT_SHIFT);
338 control = tvb_get_guint8(tvb, offset);
340 cf_items = cf_items_nonext;
341 control_format = "Control field: %s (0x%02X)";
342 poll_final = (control & XDLC_P_F);
343 g_snprintf(info, 80, "I%s, N(R)=%u, N(S)=%u",
344 ((control & XDLC_P_F) ? " P" : ""),
345 (control & XDLC_N_R_MASK) >> XDLC_N_R_SHIFT,
346 (control & XDLC_N_S_MASK) >> XDLC_N_S_SHIFT);
349 col_append_str(pinfo->cinfo, COL_INFO, ", ");
350 col_append_str(pinfo->cinfo, COL_INFO, info);
352 col_add_str(pinfo->cinfo, COL_INFO, info);
355 tc = proto_tree_add_uint_format(xdlc_tree, hf_xdlc_control, tvb,
356 offset, control_len, control, control_format, info, control);
357 control_tree = proto_item_add_subtree(tc, ett_xdlc_control);
358 proto_tree_add_uint(control_tree, *cf_items->hf_xdlc_n_r,
359 tvb, offset, control_len, control);
360 proto_tree_add_uint(control_tree, *cf_items->hf_xdlc_n_s,
361 tvb, offset, control_len, control);
363 proto_tree_add_boolean(control_tree, *cf_items->hf_xdlc_p,
364 tvb, offset, control_len, control);
366 /* This will always say it's an information frame */
367 proto_tree_add_uint(control_tree, *cf_items->hf_xdlc_ftype_i,
368 tvb, offset, control_len, control);
376 * Editor modelines - http://www.wireshark.org/tools/modelines.html
381 * indent-tabs-mode: nil
384 * vi: set shiftwidth=4 tabstop=8 expandtab:
385 * :indentSize=4:tabSize=8:noTabs=true: