2 * Routines for use by various SDLC-derived protocols, such as HDLC
3 * and its derivatives LAPB, IEEE 802.2 LLC, etc..
5 * $Id: xdlc.c,v 1.24 2004/01/20 20:27:11 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
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>
37 const value_string ftype_vals[] = {
38 { XDLC_I, "Information frame" },
39 { XDLC_S, "Supervisory frame" },
40 { XDLC_U, "Unnumbered frame" },
44 const value_string stype_vals[] = {
45 { XDLC_RR>>2, "Receiver ready" },
46 { XDLC_RNR>>2, "Receiver not ready" },
47 { XDLC_REJ>>2, "Reject" },
48 { XDLC_SREJ>>2, "Selective reject" },
52 static const value_string modifier_short_vals_cmd[] = {
55 { XDLC_DISC, "DISC" },
57 { XDLC_SNRM, "SNRM" },
58 { XDLC_SNRME, "SNRME" },
59 { XDLC_TEST, "TEST" },
61 { XDLC_FRMR, "FRMR" },
62 { XDLC_CFGR, "CFGR" },
63 { XDLC_SARM, "SARM" },
64 { XDLC_SABM, "SABM" },
65 { XDLC_SARME, "SARME" },
66 { XDLC_SABME, "SABME" },
67 { XDLC_RESET, "RESET" },
69 { XDLC_SNRME, "SNRME" },
74 const value_string modifier_vals_cmd[] = {
75 { XDLC_UI>>2, "Unnumbered Information" },
76 { XDLC_UP>>2, "Unnumbered Poll" },
77 { XDLC_DISC>>2, "Disconnect" },
78 { XDLC_UA>>2, "Unnumbered Acknowledge" },
79 { XDLC_SNRM>>2, "Set Normal Response Mode" },
80 { XDLC_TEST>>2, "Test" },
81 { XDLC_SIM>>2, "Set Initialization Mode" },
82 { XDLC_FRMR>>2, "Frame reject" },
83 { XDLC_CFGR>>2, "Configure" },
84 { XDLC_SARM>>2, "Set Asynchronous Response Mode" },
85 { XDLC_SABM>>2, "Set Asynchronous Balanced Mode" },
86 { XDLC_SARME>>2, "Set Asynchronous Response Mode Extended" },
87 { XDLC_SABME>>2, "Set Asynchronous Balanced Mode Extended" },
88 { XDLC_RESET>>2, "Reset" },
89 { XDLC_XID>>2, "Exchange identification" },
90 { XDLC_SNRME>>2, "Set Normal Response Mode Extended" },
91 { XDLC_BCN>>2, "Beacon" },
95 static const value_string modifier_short_vals_resp[] = {
100 { XDLC_SNRM, "SNRM" },
101 { XDLC_TEST, "TEST" },
103 { XDLC_FRMR, "FRMR" },
104 { XDLC_CFGR, "CFGR" },
106 { XDLC_SABM, "SABM" },
107 { XDLC_SARME, "SARME" },
108 { XDLC_SABME, "SABME" },
109 { XDLC_RESET, "RESET" },
111 { XDLC_SNRME, "SNRME" },
116 const value_string modifier_vals_resp[] = {
117 { XDLC_UI>>2, "Unnumbered Information" },
118 { XDLC_UP>>2, "Unnumbered Poll" },
119 { XDLC_RD>>2, "Request Disconnect" },
120 { XDLC_UA>>2, "Unnumbered Acknowledge" },
121 { XDLC_SNRM>>2, "Set Normal Response Mode" },
122 { XDLC_TEST>>2, "Test" },
123 { XDLC_RIM>>2, "Request Initialization Mode" },
124 { XDLC_FRMR>>2, "Frame reject" },
125 { XDLC_CFGR>>2, "Configure" },
126 { XDLC_DM>>2, "Disconnected mode" },
127 { XDLC_SABM>>2, "Set Asynchronous Balanced Mode" },
128 { XDLC_SARME>>2, "Set Asynchronous Response Mode Extended" },
129 { XDLC_SABME>>2, "Set Asynchronous Balanced Mode Extended" },
130 { XDLC_RESET>>2, "Reset" },
131 { XDLC_XID>>2, "Exchange identification" },
132 { XDLC_SNRME>>2, "Set Normal Response Mode Extended" },
133 { XDLC_BCN>>2, "Beacon" },
138 get_xdlc_control(const guchar *pd, int offset, int is_extended)
142 switch (pd[offset] & 0x03) {
147 * Supervisory or Information frame.
150 control = pletohs(&pd[offset]);
152 control = pd[offset];
159 * XXX - is this two octets, with a P/F bit, in HDLC extended
160 * operation? It's one octet in LLC, even though the control
161 * field of I and S frames is a 2-byte extended-operation field
162 * in LLC. Given that there are no sequence numbers in the
163 * control field of a U frame, there doesn't appear to be any
164 * need for it to be 2 bytes in extended operation.
166 control = pd[offset];
173 dissect_xdlc_control(tvbuff_t *tvb, int offset, packet_info *pinfo,
174 proto_tree *xdlc_tree, int hf_xdlc_control, gint ett_xdlc_control,
175 const xdlc_cf_items *cf_items_nonext, const xdlc_cf_items *cf_items_ext,
176 const value_string *u_modifier_short_vals_cmd,
177 const value_string *u_modifier_short_vals_resp, int is_response,
178 int is_extended, int append_info)
182 const xdlc_cf_items *cf_items;
183 char *control_format;
186 proto_tree *tc, *control_tree;
187 gchar *frame_type = NULL;
190 switch (tvb_get_guint8(tvb, offset) & 0x03) {
194 control = tvb_get_letohs(tvb, offset);
196 cf_items = cf_items_ext;
197 control_format = "Control field: %s (0x%04X)";
199 control = tvb_get_guint8(tvb, offset);
201 cf_items = cf_items_nonext;
202 control_format = "Control field: %s (0x%02X)";
207 switch (control & XDLC_S_FTYPE_MASK) {
225 poll_final = (control & XDLC_P_F_EXT);
226 sprintf(info, "S%s, func=%s, N(R)=%u", frame_type,
228 (is_response ? " F" : " P") :
230 (control & XDLC_N_R_EXT_MASK) >> XDLC_N_R_EXT_SHIFT);
232 poll_final = (control & XDLC_P_F);
233 sprintf(info, "S%s, func=%s, N(R)=%u",
235 (is_response ? " F" : " P") :
238 (control & XDLC_N_R_MASK) >> XDLC_N_R_SHIFT);
240 if (check_col(pinfo->cinfo, COL_INFO)) {
242 col_append_str(pinfo->cinfo, COL_INFO, ", ");
243 col_append_str(pinfo->cinfo, COL_INFO, info);
245 col_add_str(pinfo->cinfo, COL_INFO, info);
248 tc = proto_tree_add_uint_format(xdlc_tree, hf_xdlc_control, tvb,
249 offset, control_len, control, control_format, info, control);
250 control_tree = proto_item_add_subtree(tc, ett_xdlc_control);
251 proto_tree_add_uint(control_tree, *cf_items->hf_xdlc_n_r,
252 tvb, offset, control_len, control);
254 proto_tree_add_boolean(control_tree,
255 (is_response ? *cf_items->hf_xdlc_f :
256 *cf_items->hf_xdlc_p),
257 tvb, offset, control_len, control);
259 proto_tree_add_uint(control_tree, *cf_items->hf_xdlc_s_ftype,
260 tvb, offset, control_len, control);
261 /* This will always say it's a supervisory frame */
262 proto_tree_add_uint(control_tree, *cf_items->hf_xdlc_ftype_s_u,
263 tvb, offset, control_len, control);
271 * XXX - is this two octets, with a P/F bit, in HDLC extended
272 * operation? It's one octet in LLC, even though the control
273 * field of I and S frames is a 2-byte extended-operation field
274 * in LLC. Given that there are no sequence numbers in the
275 * control field of a U frame, there doesn't appear to be any
276 * need for it to be 2 bytes in extended operation.
278 if (u_modifier_short_vals_cmd == NULL)
279 u_modifier_short_vals_cmd = modifier_short_vals_cmd;
280 if (u_modifier_short_vals_resp == NULL)
281 u_modifier_short_vals_resp = modifier_short_vals_resp;
282 control = tvb_get_guint8(tvb, offset);
284 cf_items = cf_items_nonext;
285 control_format = "Control field: %s (0x%02X)";
287 modifier = match_strval(control & XDLC_U_MODIFIER_MASK,
288 u_modifier_short_vals_resp);
290 modifier = match_strval(control & XDLC_U_MODIFIER_MASK,
291 u_modifier_short_vals_cmd);
293 if (modifier == NULL)
294 modifier = "Unknown";
295 poll_final = (control & XDLC_P_F);
296 sprintf(info, "U%s, func=%s",
298 (is_response ? " F" : " P") :
301 if (check_col(pinfo->cinfo, COL_INFO)) {
303 col_append_str(pinfo->cinfo, COL_INFO, ", ");
304 col_append_str(pinfo->cinfo, COL_INFO, info);
306 col_add_str(pinfo->cinfo, COL_INFO, info);
309 tc = proto_tree_add_uint_format(xdlc_tree, hf_xdlc_control, tvb,
310 offset, control_len, control, control_format, info, control);
311 control_tree = proto_item_add_subtree(tc, ett_xdlc_control);
313 proto_tree_add_boolean(control_tree,
314 (is_response ? *cf_items->hf_xdlc_f:
315 *cf_items->hf_xdlc_p),
316 tvb, offset, control_len, control);
318 proto_tree_add_uint(control_tree,
319 (is_response ? *cf_items->hf_xdlc_u_modifier_resp :
320 *cf_items->hf_xdlc_u_modifier_cmd),
321 tvb, offset, control_len, control);
322 /* This will always say it's an unnumbered frame */
323 proto_tree_add_uint(control_tree, *cf_items->hf_xdlc_ftype_s_u,
324 tvb, offset, control_len, control);
333 control = tvb_get_letohs(tvb, offset);
335 cf_items = cf_items_ext;
336 control_format = "Control field: %s (0x%04X)";
337 poll_final = (control & XDLC_P_F_EXT);
338 sprintf(info, "I%s, N(R)=%u, N(S)=%u",
339 ((control & XDLC_P_F_EXT) ? " P" : ""),
340 (control & XDLC_N_R_EXT_MASK) >> XDLC_N_R_EXT_SHIFT,
341 (control & XDLC_N_S_EXT_MASK) >> XDLC_N_S_EXT_SHIFT);
343 control = tvb_get_guint8(tvb, offset);
345 cf_items = cf_items_nonext;
346 control_format = "Control field: %s (0x%02X)";
347 poll_final = (control & XDLC_P_F);
348 sprintf(info, "I%s, N(R)=%u, N(S)=%u",
349 ((control & XDLC_P_F) ? " P" : ""),
350 (control & XDLC_N_R_MASK) >> XDLC_N_R_SHIFT,
351 (control & XDLC_N_S_MASK) >> XDLC_N_S_SHIFT);
353 if (check_col(pinfo->cinfo, COL_INFO)) {
355 col_append_str(pinfo->cinfo, COL_INFO, ", ");
356 col_append_str(pinfo->cinfo, COL_INFO, info);
358 col_add_str(pinfo->cinfo, COL_INFO, info);
361 tc = proto_tree_add_uint_format(xdlc_tree, hf_xdlc_control, tvb,
362 offset, control_len, control, control_format, info, control);
363 control_tree = proto_item_add_subtree(tc, ett_xdlc_control);
364 proto_tree_add_uint(control_tree, *cf_items->hf_xdlc_n_r,
365 tvb, offset, control_len, control);
366 proto_tree_add_uint(control_tree, *cf_items->hf_xdlc_n_s,
367 tvb, offset, control_len, control);
369 proto_tree_add_boolean(control_tree, *cf_items->hf_xdlc_p,
370 tvb, offset, control_len, control);
372 /* This will always say it's an information frame */
373 proto_tree_add_uint(control_tree, *cf_items->hf_xdlc_ftype_i,
374 tvb, offset, control_len, control);