2 * Routines for use by various SDLC-derived protocols, such as HDLC
3 * and its derivatives LAPB, IEEE 802.2 LLC, etc..
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #include <epan/packet.h>
35 #include <epan/xdlc.h>
36 #include <epan/emem.h>
38 const value_string ftype_vals[] = {
39 { XDLC_I, "Information frame" },
40 { XDLC_S, "Supervisory frame" },
41 { XDLC_U, "Unnumbered frame" },
45 const value_string stype_vals[] = {
46 { XDLC_RR>>2, "Receiver ready" },
47 { XDLC_RNR>>2, "Receiver not ready" },
48 { XDLC_REJ>>2, "Reject" },
49 { XDLC_SREJ>>2, "Selective reject" },
53 static const value_string modifier_short_vals_cmd[] = {
56 { XDLC_DISC, "DISC" },
58 { XDLC_SNRM, "SNRM" },
59 { XDLC_SNRME, "SNRME" },
60 { XDLC_TEST, "TEST" },
62 { XDLC_FRMR, "FRMR" },
63 { XDLC_CFGR, "CFGR" },
64 { XDLC_SARM, "SARM" },
65 { XDLC_SABM, "SABM" },
66 { XDLC_SARME, "SARME" },
67 { XDLC_SABME, "SABME" },
68 { XDLC_RESET, "RESET" },
70 { XDLC_SNRME, "SNRME" },
75 const value_string modifier_vals_cmd[] = {
76 { XDLC_UI>>2, "Unnumbered Information" },
77 { XDLC_UP>>2, "Unnumbered Poll" },
78 { XDLC_DISC>>2, "Disconnect" },
79 { XDLC_UA>>2, "Unnumbered Acknowledge" },
80 { XDLC_SNRM>>2, "Set Normal Response Mode" },
81 { XDLC_TEST>>2, "Test" },
82 { XDLC_SIM>>2, "Set Initialization Mode" },
83 { XDLC_FRMR>>2, "Frame reject" },
84 { XDLC_CFGR>>2, "Configure" },
85 { XDLC_SARM>>2, "Set Asynchronous Response Mode" },
86 { XDLC_SABM>>2, "Set Asynchronous Balanced Mode" },
87 { XDLC_SARME>>2, "Set Asynchronous Response Mode Extended" },
88 { XDLC_SABME>>2, "Set Asynchronous Balanced Mode Extended" },
89 { XDLC_RESET>>2, "Reset" },
90 { XDLC_XID>>2, "Exchange identification" },
91 { XDLC_SNRME>>2, "Set Normal Response Mode Extended" },
92 { XDLC_BCN>>2, "Beacon" },
96 static const value_string modifier_short_vals_resp[] = {
101 { XDLC_SNRM, "SNRM" },
102 { XDLC_TEST, "TEST" },
104 { XDLC_FRMR, "FRMR" },
105 { XDLC_CFGR, "CFGR" },
107 { XDLC_SABM, "SABM" },
108 { XDLC_SARME, "SARME" },
109 { XDLC_SABME, "SABME" },
110 { XDLC_RESET, "RESET" },
112 { XDLC_SNRME, "SNRME" },
117 const value_string modifier_vals_resp[] = {
118 { XDLC_UI>>2, "Unnumbered Information" },
119 { XDLC_UP>>2, "Unnumbered Poll" },
120 { XDLC_RD>>2, "Request Disconnect" },
121 { XDLC_UA>>2, "Unnumbered Acknowledge" },
122 { XDLC_SNRM>>2, "Set Normal Response Mode" },
123 { XDLC_TEST>>2, "Test" },
124 { XDLC_RIM>>2, "Request Initialization Mode" },
125 { XDLC_FRMR>>2, "Frame reject" },
126 { XDLC_CFGR>>2, "Configure" },
127 { XDLC_DM>>2, "Disconnected mode" },
128 { XDLC_SABM>>2, "Set Asynchronous Balanced Mode" },
129 { XDLC_SARME>>2, "Set Asynchronous Response Mode Extended" },
130 { XDLC_SABME>>2, "Set Asynchronous Balanced Mode Extended" },
131 { XDLC_RESET>>2, "Reset" },
132 { XDLC_XID>>2, "Exchange identification" },
133 { XDLC_SNRME>>2, "Set Normal Response Mode Extended" },
134 { XDLC_BCN>>2, "Beacon" },
139 get_xdlc_control(const guchar *pd, int offset, int is_extended)
143 switch (pd[offset] & 0x03) {
148 * Supervisory or Information frame.
151 control = pletohs(&pd[offset]);
153 control = pd[offset];
160 * XXX - is this two octets, with a P/F bit, in HDLC extended
161 * operation? It's one octet in LLC, even though the control
162 * field of I and S frames is a 2-byte extended-operation field
163 * in LLC. Given that there are no sequence numbers in the
164 * control field of a U frame, there doesn't appear to be any
165 * need for it to be 2 bytes in extended operation.
167 control = pd[offset];
174 dissect_xdlc_control(tvbuff_t *tvb, int offset, packet_info *pinfo,
175 proto_tree *xdlc_tree, int hf_xdlc_control, gint ett_xdlc_control,
176 const xdlc_cf_items *cf_items_nonext, const xdlc_cf_items *cf_items_ext,
177 const value_string *u_modifier_short_vals_cmd,
178 const value_string *u_modifier_short_vals_resp, int is_response,
179 int is_extended, int append_info)
183 const xdlc_cf_items *cf_items;
184 const char *control_format;
187 proto_tree *tc, *control_tree;
188 const gchar *frame_type = NULL;
189 const gchar *modifier;
192 switch (tvb_get_guint8(tvb, offset) & 0x03) {
196 control = tvb_get_letohs(tvb, offset);
198 cf_items = cf_items_ext;
199 control_format = "Control field: %s (0x%04X)";
201 control = tvb_get_guint8(tvb, offset);
203 cf_items = cf_items_nonext;
204 control_format = "Control field: %s (0x%02X)";
209 switch (control & XDLC_S_FTYPE_MASK) {
227 poll_final = (control & XDLC_P_F_EXT);
228 g_snprintf(info, 80, "S%s, func=%s, N(R)=%u",
230 (is_response ? " F" : " P") :
233 (control & XDLC_N_R_EXT_MASK) >> XDLC_N_R_EXT_SHIFT);
235 poll_final = (control & XDLC_P_F);
236 g_snprintf(info, 80, "S%s, func=%s, N(R)=%u",
238 (is_response ? " F" : " P") :
241 (control & XDLC_N_R_MASK) >> XDLC_N_R_SHIFT);
243 if (check_col(pinfo->cinfo, COL_INFO)) {
245 col_append_str(pinfo->cinfo, COL_INFO, ", ");
246 col_append_str(pinfo->cinfo, COL_INFO, info);
248 col_add_str(pinfo->cinfo, COL_INFO, info);
251 tc = proto_tree_add_uint_format(xdlc_tree, hf_xdlc_control, tvb,
252 offset, control_len, control, control_format, info, control);
253 control_tree = proto_item_add_subtree(tc, ett_xdlc_control);
254 proto_tree_add_uint(control_tree, *cf_items->hf_xdlc_n_r,
255 tvb, offset, control_len, control);
257 proto_tree_add_boolean(control_tree,
258 (is_response ? *cf_items->hf_xdlc_f :
259 *cf_items->hf_xdlc_p),
260 tvb, offset, control_len, control);
262 proto_tree_add_uint(control_tree, *cf_items->hf_xdlc_s_ftype,
263 tvb, offset, control_len, control);
264 /* This will always say it's a supervisory frame */
265 proto_tree_add_uint(control_tree, *cf_items->hf_xdlc_ftype_s_u,
266 tvb, offset, control_len, control);
274 * XXX - is this two octets, with a P/F bit, in HDLC extended
275 * operation? It's one octet in LLC, even though the control
276 * field of I and S frames is a 2-byte extended-operation field
277 * in LLC. Given that there are no sequence numbers in the
278 * control field of a U frame, there doesn't appear to be any
279 * need for it to be 2 bytes in extended operation.
281 if (u_modifier_short_vals_cmd == NULL)
282 u_modifier_short_vals_cmd = modifier_short_vals_cmd;
283 if (u_modifier_short_vals_resp == NULL)
284 u_modifier_short_vals_resp = modifier_short_vals_resp;
285 control = tvb_get_guint8(tvb, offset);
287 cf_items = cf_items_nonext;
288 control_format = "Control field: %s (0x%02X)";
290 modifier = val_to_str(control & XDLC_U_MODIFIER_MASK,
291 u_modifier_short_vals_resp, "Unknown");
293 modifier = val_to_str(control & XDLC_U_MODIFIER_MASK,
294 u_modifier_short_vals_cmd, "Unknown");
296 poll_final = (control & XDLC_P_F);
297 g_snprintf(info, 80, "U%s, func=%s",
299 (is_response ? " F" : " P") :
302 if (check_col(pinfo->cinfo, COL_INFO)) {
304 col_append_str(pinfo->cinfo, COL_INFO, ", ");
305 col_append_str(pinfo->cinfo, COL_INFO, info);
307 col_add_str(pinfo->cinfo, COL_INFO, info);
310 tc = proto_tree_add_uint_format(xdlc_tree, hf_xdlc_control, tvb,
311 offset, control_len, control, control_format, info, control);
312 control_tree = proto_item_add_subtree(tc, ett_xdlc_control);
314 proto_tree_add_boolean(control_tree,
315 (is_response ? *cf_items->hf_xdlc_f:
316 *cf_items->hf_xdlc_p),
317 tvb, offset, control_len, control);
319 proto_tree_add_uint(control_tree,
320 (is_response ? *cf_items->hf_xdlc_u_modifier_resp :
321 *cf_items->hf_xdlc_u_modifier_cmd),
322 tvb, offset, control_len, control);
323 /* This will always say it's an unnumbered frame */
324 proto_tree_add_uint(control_tree, *cf_items->hf_xdlc_ftype_s_u,
325 tvb, offset, control_len, control);
334 control = tvb_get_letohs(tvb, offset);
336 cf_items = cf_items_ext;
337 control_format = "Control field: %s (0x%04X)";
338 poll_final = (control & XDLC_P_F_EXT);
339 g_snprintf(info, 80, "I%s, N(R)=%u, N(S)=%u",
340 ((control & XDLC_P_F_EXT) ? " P" : ""),
341 (control & XDLC_N_R_EXT_MASK) >> XDLC_N_R_EXT_SHIFT,
342 (control & XDLC_N_S_EXT_MASK) >> XDLC_N_S_EXT_SHIFT);
344 control = tvb_get_guint8(tvb, offset);
346 cf_items = cf_items_nonext;
347 control_format = "Control field: %s (0x%02X)";
348 poll_final = (control & XDLC_P_F);
349 g_snprintf(info, 80, "I%s, N(R)=%u, N(S)=%u",
350 ((control & XDLC_P_F) ? " P" : ""),
351 (control & XDLC_N_R_MASK) >> XDLC_N_R_SHIFT,
352 (control & XDLC_N_S_MASK) >> XDLC_N_S_SHIFT);
354 if (check_col(pinfo->cinfo, COL_INFO)) {
356 col_append_str(pinfo->cinfo, COL_INFO, ", ");
357 col_append_str(pinfo->cinfo, COL_INFO, info);
359 col_add_str(pinfo->cinfo, COL_INFO, info);
362 tc = proto_tree_add_uint_format(xdlc_tree, hf_xdlc_control, tvb,
363 offset, control_len, control, control_format, info, control);
364 control_tree = proto_item_add_subtree(tc, ett_xdlc_control);
365 proto_tree_add_uint(control_tree, *cf_items->hf_xdlc_n_r,
366 tvb, offset, control_len, control);
367 proto_tree_add_uint(control_tree, *cf_items->hf_xdlc_n_s,
368 tvb, offset, control_len, control);
370 proto_tree_add_boolean(control_tree, *cf_items->hf_xdlc_p,
371 tvb, offset, control_len, control);
373 /* This will always say it's an information frame */
374 proto_tree_add_uint(control_tree, *cf_items->hf_xdlc_ftype_i,
375 tvb, offset, control_len, control);