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.18 2002/03/31 21:09:00 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.
30 #ifdef HAVE_SYS_TYPES_H
31 # include <sys/types.h>
38 #include <epan/packet.h>
42 * N(S) and N(R) fields, in basic and extended operation.
44 #define XDLC_N_R_MASK 0xE0 /* basic */
45 #define XDLC_N_R_SHIFT 5
46 #define XDLC_N_R_EXT_MASK 0xFE00 /* extended */
47 #define XDLC_N_R_EXT_SHIFT 9
48 #define XDLC_N_S_MASK 0x0E /* basic */
49 #define XDLC_N_S_SHIFT 1
50 #define XDLC_N_S_EXT_MASK 0x00FE /* extended */
51 #define XDLC_N_S_EXT_SHIFT 1
54 * Poll/Final bit, in basic and extended operation.
56 #define XDLC_P_F 0x10 /* basic */
57 #define XDLC_P_F_EXT 0x0100 /* extended */
60 * S-format frame types.
62 #define XDLC_S_FTYPE_MASK 0x0C
63 #define XDLC_RR 0x00 /* Receiver ready */
64 #define XDLC_RNR 0x04 /* Receiver not ready */
65 #define XDLC_REJ 0x08 /* Reject */
66 #define XDLC_SREJ 0x0C /* Selective reject */
68 static const value_string stype_vals[] = {
69 { XDLC_RR, "Receiver ready" },
70 { XDLC_RNR, "Receiver not ready" },
71 { XDLC_REJ, "Reject" },
72 { XDLC_SREJ, "Selective reject" },
76 static const value_string modifier_short_vals_cmd[] = {
79 { XDLC_DISC, "DISC" },
81 { XDLC_SNRM, "SNRM" },
82 { XDLC_SNRME, "SNRME" },
83 { XDLC_TEST, "TEST" },
85 { XDLC_FRMR, "FRMR" },
86 { XDLC_CFGR, "CFGR" },
87 { XDLC_SARM, "SARM" },
88 { XDLC_SABM, "SABM" },
89 { XDLC_SARME, "SARME" },
90 { XDLC_SABME, "SABME" },
91 { XDLC_RESET, "RESET" },
93 { XDLC_SNRME, "SNRME" },
98 static const value_string modifier_vals_cmd[] = {
99 { XDLC_UI, "Unnumbered Information" },
100 { XDLC_UP, "Unnumbered Poll" },
101 { XDLC_DISC, "Disconnect" },
102 { XDLC_UA, "Unnumbered Acknowledge" },
103 { XDLC_SNRM, "Set Normal Response Mode" },
104 { XDLC_TEST, "Test" },
105 { XDLC_SIM, "Set Initialization Mode" },
106 { XDLC_FRMR, "Frame reject" },
107 { XDLC_CFGR, "Configure" },
108 { XDLC_SARM, "Set Asynchronous Response Mode" },
109 { XDLC_SABM, "Set Asynchronous Balanced Mode" },
110 { XDLC_SARME, "Set Asynchronous Response Mode Extended" },
111 { XDLC_SABME, "Set Asynchronous Balanced Mode Extended" },
112 { XDLC_RESET, "Reset" },
113 { XDLC_XID, "Exchange identification" },
114 { XDLC_SNRME, "Set Normal Response Mode Extended" },
115 { XDLC_BCN, "Beacon" },
119 static const value_string modifier_short_vals_resp[] = {
124 { XDLC_SNRM, "SNRM" },
125 { XDLC_TEST, "TEST" },
127 { XDLC_FRMR, "FRMR" },
128 { XDLC_CFGR, "CFGR" },
130 { XDLC_SABM, "SABM" },
131 { XDLC_SARME, "SARME" },
132 { XDLC_SABME, "SABME" },
133 { XDLC_RESET, "RESET" },
135 { XDLC_SNRME, "SNRME" },
140 static const value_string modifier_vals_resp[] = {
141 { XDLC_UI, "Unnumbered Information" },
142 { XDLC_UP, "Unnumbered Poll" },
143 { XDLC_RD, "Request Disconnect" },
144 { XDLC_UA, "Unnumbered Acknowledge" },
145 { XDLC_SNRM, "Set Normal Response Mode" },
146 { XDLC_TEST, "Test" },
147 { XDLC_RIM, "Request Initialization Mode" },
148 { XDLC_FRMR, "Frame reject" },
149 { XDLC_CFGR, "Configure" },
150 { XDLC_DM, "Disconnected mode" },
151 { XDLC_SABM, "Set Asynchronous Balanced Mode" },
152 { XDLC_SARME, "Set Asynchronous Response Mode Extended" },
153 { XDLC_SABME, "Set Asynchronous Balanced Mode Extended" },
154 { XDLC_RESET, "Reset" },
155 { XDLC_XID, "Exchange identification" },
156 { XDLC_SNRME, "Set Normal Response Mode Extended" },
157 { XDLC_BCN, "Beacon" },
162 get_xdlc_control(const u_char *pd, int offset, int is_extended)
166 switch (pd[offset] & 0x03) {
171 * Supervisory or Information frame.
174 control = pletohs(&pd[offset]);
176 control = pd[offset];
183 * XXX - is this two octets, with a P/F bit, in HDLC extended
184 * operation? It's one octet in LLC, even though the control
185 * field of I and S frames is a 2-byte extended-operation field
186 * in LLC. Given that there are no sequence numbers in the
187 * control field of a U frame, there doesn't appear to be any
188 * need for it to be 2 bytes in extended operation.
190 control = pd[offset];
197 dissect_xdlc_control(tvbuff_t *tvb, int offset, packet_info *pinfo,
198 proto_tree *xdlc_tree, int hf_xdlc_control, gint ett_xdlc_control,
199 int is_response, int is_extended)
203 proto_tree *tc, *control_tree;
204 gchar *frame_type = NULL;
207 switch (tvb_get_guint8(tvb, offset) & 0x03) {
214 control = tvb_get_letohs(tvb, offset);
216 control = tvb_get_guint8(tvb, offset);
217 switch (control & XDLC_S_FTYPE_MASK) {
235 sprintf(info, "S%s, %sN(R) = %u", frame_type,
236 ((control & XDLC_P_F_EXT) ?
237 (is_response ? "func = F, " : "func = P, ") :
239 (control & XDLC_N_R_EXT_MASK) >> XDLC_N_R_EXT_SHIFT);
241 sprintf(info, "S%s, %sN(R) = %u", frame_type,
242 ((control & XDLC_P_F) ?
243 (is_response ? "func = F, " : "func = P, ") :
245 (control & XDLC_N_R_MASK) >> XDLC_N_R_SHIFT);
247 if (check_col(pinfo->cinfo, COL_INFO))
248 col_add_str(pinfo->cinfo, COL_INFO, info);
251 tc = proto_tree_add_uint_format(xdlc_tree, hf_xdlc_control, tvb,
254 "Control field: %s (0x%04X)", info, control);
255 control_tree = proto_item_add_subtree(tc, ett_xdlc_control);
256 proto_tree_add_text(control_tree, tvb, offset, 2,
257 decode_numeric_bitfield(control, XDLC_N_R_EXT_MASK, 2*8,
259 if (control & XDLC_P_F_EXT) {
260 proto_tree_add_text(control_tree, tvb, offset, 2,
261 decode_boolean_bitfield(control, XDLC_P_F_EXT, 2*8,
262 (is_response ? "Final" : "Poll"), NULL));
264 proto_tree_add_text(control_tree, tvb, offset, 2,
265 decode_enumerated_bitfield(control, XDLC_S_FTYPE_MASK, 2*8,
266 stype_vals, "Supervisory frame - %s"));
267 /* This will always say it's a supervisory frame */
268 proto_tree_add_text(control_tree, tvb, offset, 2,
269 decode_boolean_bitfield(control, 0x03, 2*8,
270 "Supervisory frame", NULL));
272 tc = proto_tree_add_uint_format(xdlc_tree, hf_xdlc_control, tvb,
275 "Control field: %s (0x%02X)", info, control);
276 control_tree = proto_item_add_subtree(tc, ett_xdlc_control);
277 proto_tree_add_text(control_tree, tvb, offset, 1,
278 decode_numeric_bitfield(control, XDLC_N_R_MASK, 1*8,
280 if (control & XDLC_P_F) {
281 proto_tree_add_text(control_tree, tvb, offset, 1,
282 decode_boolean_bitfield(control, XDLC_P_F, 1*8,
283 (is_response ? "Final" : "Poll"), NULL));
285 proto_tree_add_text(control_tree, tvb, offset, 1,
286 decode_enumerated_bitfield(control, XDLC_S_FTYPE_MASK, 1*8,
288 /* This will always say it's a supervisory frame */
289 proto_tree_add_text(control_tree, tvb, offset, 1,
290 decode_boolean_bitfield(control, 0x03, 1*8,
291 "Supervisory frame", NULL));
300 * XXX - is this two octets, with a P/F bit, in HDLC extended
301 * operation? It's one octet in LLC, even though the control
302 * field of I and S frames is a 2-byte extended-operation field
303 * in LLC. Given that there are no sequence numbers in the
304 * control field of a U frame, there doesn't appear to be any
305 * need for it to be 2 bytes in extended operation.
307 control = tvb_get_guint8(tvb, offset);
309 modifier = match_strval(control & XDLC_U_MODIFIER_MASK,
310 modifier_short_vals_resp);
312 modifier = match_strval(control & XDLC_U_MODIFIER_MASK,
313 modifier_short_vals_cmd);
315 if (modifier == NULL)
316 modifier = "Unknown";
317 sprintf(info, "U%s, func = %s",
318 ((control & XDLC_P_F) ?
319 (is_response ? " F" : " P") :
322 if (check_col(pinfo->cinfo, COL_INFO))
323 col_add_str(pinfo->cinfo, COL_INFO, info);
325 tc = proto_tree_add_uint_format(xdlc_tree, hf_xdlc_control, tvb,
328 "Control field: %s (0x%02X)", info, control);
329 control_tree = proto_item_add_subtree(tc, ett_xdlc_control);
330 if (control & XDLC_P_F) {
331 proto_tree_add_text(control_tree, tvb, offset, 2,
332 decode_boolean_bitfield(control, XDLC_P_F, 1*8,
333 (is_response ? "Final" : "Poll"), NULL));
335 proto_tree_add_text(control_tree, tvb, offset, 1,
336 decode_enumerated_bitfield(control, XDLC_U_MODIFIER_MASK, 1*8,
337 (is_response ? modifier_vals_resp : modifier_vals_cmd),
339 /* This will always say it's an unnumbered frame */
340 proto_tree_add_text(control_tree, tvb, offset, 1,
341 decode_boolean_bitfield(control, 0x03, 1*8,
342 "Unnumbered frame", NULL));
351 control = tvb_get_letohs(tvb, offset);
353 control = tvb_get_guint8(tvb, offset);
355 sprintf(info, "I%s, N(R) = %u, N(S) = %u",
356 ((control & XDLC_P_F_EXT) ? " P" : ""),
357 (control & XDLC_N_R_EXT_MASK) >> XDLC_N_R_EXT_SHIFT,
358 (control & XDLC_N_S_EXT_MASK) >> XDLC_N_S_EXT_SHIFT);
360 sprintf(info, "I%s, N(R) = %u, N(S) = %u",
361 ((control & XDLC_P_F) ? " P" : ""),
362 (control & XDLC_N_R_MASK) >> XDLC_N_R_SHIFT,
363 (control & XDLC_N_S_MASK) >> XDLC_N_S_SHIFT);
365 if (check_col(pinfo->cinfo, COL_INFO))
366 col_add_str(pinfo->cinfo, COL_INFO, info);
368 tc = proto_tree_add_uint_format(xdlc_tree, hf_xdlc_control, tvb,
369 offset, (is_extended) ? 2 : 1,
371 (is_extended) ? "Control field: %s (0x%04X)"
372 : "Control field: %s (0x%02X)",
374 control_tree = proto_item_add_subtree(tc, ett_xdlc_control);
376 proto_tree_add_text(control_tree, tvb, offset, 2,
377 decode_numeric_bitfield(control, XDLC_N_R_EXT_MASK, 2*8,
379 proto_tree_add_text(control_tree, tvb, offset, 2,
380 decode_numeric_bitfield(control, XDLC_N_S_EXT_MASK, 2*8,
382 if (control & XDLC_P_F_EXT) {
383 proto_tree_add_text(control_tree, tvb, offset, 2,
384 decode_boolean_bitfield(control, XDLC_P_F_EXT, 2*8,
387 /* This will always say it's an information frame */
388 proto_tree_add_text(control_tree, tvb, offset, 2,
389 decode_boolean_bitfield(control, 0x01, 2*8,
390 NULL, "Information frame"));
392 proto_tree_add_text(control_tree, tvb, offset, 1,
393 decode_numeric_bitfield(control, XDLC_N_R_MASK, 1*8,
395 proto_tree_add_text(control_tree, tvb, offset, 1,
396 decode_numeric_bitfield(control, XDLC_N_S_MASK, 1*8,
398 if (control & XDLC_P_F) {
399 proto_tree_add_text(control_tree, tvb, offset, 1,
400 decode_boolean_bitfield(control, XDLC_P_F, 1*8,
403 /* This will always say it's an information frame */
404 proto_tree_add_text(control_tree, tvb, offset, 1,
405 decode_boolean_bitfield(control, 0x01, 1*8,
406 NULL, "Information frame"));