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.15 2000/05/31 03:58:55 gram Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@zing.org>
9 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
43 * N(S) and N(R) fields, in basic and extended operation.
45 #define XDLC_N_R_MASK 0xE0 /* basic */
46 #define XDLC_N_R_SHIFT 5
47 #define XDLC_N_R_EXT_MASK 0xFE00 /* extended */
48 #define XDLC_N_R_EXT_SHIFT 9
49 #define XDLC_N_S_MASK 0x0E /* basic */
50 #define XDLC_N_S_SHIFT 1
51 #define XDLC_N_S_EXT_MASK 0x00FE /* extended */
52 #define XDLC_N_S_EXT_SHIFT 1
55 * Poll/Final bit, in basic and extended operation.
57 #define XDLC_P_F 0x10 /* basic */
58 #define XDLC_P_F_EXT 0x0100 /* extended */
61 * S-format frame types.
63 #define XDLC_S_FTYPE_MASK 0x0C
64 #define XDLC_RR 0x00 /* Receiver ready */
65 #define XDLC_RNR 0x04 /* Receiver not ready */
66 #define XDLC_REJ 0x08 /* Reject */
67 #define XDLC_SREJ 0x0C /* Selective reject */
69 static const value_string stype_vals[] = {
70 { XDLC_RR, "Receiver ready" },
71 { XDLC_RNR, "Receiver not ready" },
72 { XDLC_REJ, "Reject" },
73 { XDLC_SREJ, "Selective reject" },
77 static const value_string modifier_short_vals_cmd[] = {
80 { XDLC_DISC, "DISC" },
82 { XDLC_SNRM, "SNRM" },
83 { XDLC_SNRME, "SNRME" },
84 { XDLC_TEST, "TEST" },
86 { XDLC_FRMR, "FRMR" },
87 { XDLC_CFGR, "CFGR" },
88 { XDLC_SARM, "SARM" },
89 { XDLC_SABM, "SABM" },
90 { XDLC_SARME, "SARME" },
91 { XDLC_SABME, "SABME" },
92 { XDLC_RESET, "RESET" },
94 { XDLC_SNRME, "SNRME" },
99 static const value_string modifier_vals_cmd[] = {
100 { XDLC_UI, "Unnumbered Information" },
101 { XDLC_UP, "Unnumbered Poll" },
102 { XDLC_DISC, "Disconnect" },
103 { XDLC_UA, "Unnumbered Acknowledge" },
104 { XDLC_SNRM, "Set Normal Response Mode" },
105 { XDLC_TEST, "Test" },
106 { XDLC_SIM, "Set Initialization Mode" },
107 { XDLC_FRMR, "Frame reject" },
108 { XDLC_CFGR, "Configure" },
109 { XDLC_SARM, "Set Asynchronous Response Mode" },
110 { XDLC_SABM, "Set Asynchronous Balanced Mode" },
111 { XDLC_SARME, "Set Asynchronous Response Mode Extended" },
112 { XDLC_SABME, "Set Asynchronous Balanced Mode Extended" },
113 { XDLC_RESET, "Reset" },
114 { XDLC_XID, "Exchange identification" },
115 { XDLC_SNRME, "Set Normal Response Mode Extended" },
116 { XDLC_BCN, "Beacon" },
120 static const value_string modifier_short_vals_resp[] = {
125 { XDLC_SNRM, "SNRM" },
126 { XDLC_TEST, "TEST" },
128 { XDLC_FRMR, "FRMR" },
129 { XDLC_CFGR, "CFGR" },
131 { XDLC_SABM, "SABM" },
132 { XDLC_SARME, "SARME" },
133 { XDLC_SABME, "SABME" },
134 { XDLC_RESET, "RESET" },
136 { XDLC_SNRME, "SNRME" },
141 static const value_string modifier_vals_resp[] = {
142 { XDLC_UI, "Unnumbered Information" },
143 { XDLC_UP, "Unnumbered Poll" },
144 { XDLC_RD, "Request Disconnect" },
145 { XDLC_UA, "Unnumbered Acknowledge" },
146 { XDLC_SNRM, "Set Normal Response Mode" },
147 { XDLC_TEST, "Test" },
148 { XDLC_RIM, "Request Initialization Mode" },
149 { XDLC_FRMR, "Frame reject" },
150 { XDLC_CFGR, "Configure" },
151 { XDLC_DM, "Disconnected mode" },
152 { XDLC_SABM, "Set Asynchronous Balanced Mode" },
153 { XDLC_SARME, "Set Asynchronous Response Mode Extended" },
154 { XDLC_SABME, "Set Asynchronous Balanced Mode Extended" },
155 { XDLC_RESET, "Reset" },
156 { XDLC_XID, "Exchange identification" },
157 { XDLC_SNRME, "Set Normal Response Mode Extended" },
158 { XDLC_BCN, "Beacon" },
163 get_xdlc_control(const u_char *pd, int offset, int is_response, int is_extended)
167 switch (pd[offset] & 0x03) {
172 * Supervisory or Information frame.
175 control = pletohs(&pd[offset]);
177 control = pd[offset];
184 * XXX - is this two octets, with a P/F bit, in HDLC extended
185 * operation? It's one octet in LLC, even though the control
186 * field of I and S frames is a 2-byte extended-operation field
187 * in LLC. Given that there are no sequence numbers in the
188 * control field of a U frame, there doesn't appear to be any
189 * need for it to be 2 bytes in extended operation.
191 control = pd[offset];
198 dissect_xdlc_control(tvbuff_t *tvb, int offset, packet_info *pinfo,
199 proto_tree *xdlc_tree, int hf_xdlc_control, gint ett_xdlc_control,
200 int is_response, int is_extended)
204 proto_tree *tc, *control_tree;
205 gchar *frame_type = NULL;
208 switch (tvb_get_guint8(tvb, offset) & 0x03) {
215 control = tvb_get_letohs(tvb, offset);
217 control = tvb_get_guint8(tvb, offset);
218 switch (control & XDLC_S_FTYPE_MASK) {
236 sprintf(info, "S%s, %sN(R) = %u", frame_type,
237 ((control & XDLC_P_F_EXT) ?
238 (is_response ? "func = F, " : "func = P, ") :
240 (control & XDLC_N_R_EXT_MASK) >> XDLC_N_R_EXT_SHIFT);
242 sprintf(info, "S%s, %sN(R) = %u", frame_type,
243 ((control & XDLC_P_F) ?
244 (is_response ? "func = F, " : "func = P, ") :
246 (control & XDLC_N_R_MASK) >> XDLC_N_R_SHIFT);
248 if (check_col(pinfo->fd, COL_INFO))
249 col_add_str(pinfo->fd, COL_INFO, info);
252 tc = proto_tree_add_uint_format(xdlc_tree, hf_xdlc_control, tvb,
255 "Control field: %s (0x%04X)", info, control);
256 control_tree = proto_item_add_subtree(tc, ett_xdlc_control);
257 proto_tree_add_text(control_tree, tvb, offset, 2,
258 decode_numeric_bitfield(control, XDLC_N_R_EXT_MASK, 2*8,
260 if (control & XDLC_P_F_EXT) {
261 proto_tree_add_text(control_tree, tvb, offset, 2,
262 decode_boolean_bitfield(control, XDLC_P_F_EXT, 2*8,
263 (is_response ? "Final" : "Poll"), NULL));
265 proto_tree_add_text(control_tree, tvb, offset, 2,
266 decode_enumerated_bitfield(control, XDLC_S_FTYPE_MASK, 2*8,
267 stype_vals, "Supervisory frame - %s"));
268 /* This will always say it's a supervisory frame */
269 proto_tree_add_text(control_tree, tvb, offset, 2,
270 decode_boolean_bitfield(control, 0x03, 2*8,
271 "Supervisory frame", NULL));
273 tc = proto_tree_add_uint_format(xdlc_tree, hf_xdlc_control, tvb,
276 "Control field: %s (0x%02X)", info, control);
277 control_tree = proto_item_add_subtree(tc, ett_xdlc_control);
278 proto_tree_add_text(control_tree, tvb, offset, 1,
279 decode_numeric_bitfield(control, XDLC_N_R_MASK, 1*8,
281 if (control & XDLC_P_F) {
282 proto_tree_add_text(control_tree, tvb, offset, 1,
283 decode_boolean_bitfield(control, XDLC_P_F, 1*8,
284 (is_response ? "Final" : "Poll"), NULL));
286 proto_tree_add_text(control_tree, tvb, offset, 1,
287 decode_enumerated_bitfield(control, XDLC_S_FTYPE_MASK, 1*8,
289 /* This will always say it's a supervisory frame */
290 proto_tree_add_text(control_tree, tvb, offset, 1,
291 decode_boolean_bitfield(control, 0x03, 1*8,
292 "Supervisory frame", NULL));
301 * XXX - is this two octets, with a P/F bit, in HDLC extended
302 * operation? It's one octet in LLC, even though the control
303 * field of I and S frames is a 2-byte extended-operation field
304 * in LLC. Given that there are no sequence numbers in the
305 * control field of a U frame, there doesn't appear to be any
306 * need for it to be 2 bytes in extended operation.
308 control = tvb_get_guint8(tvb, offset);
310 modifier = match_strval(control & XDLC_U_MODIFIER_MASK,
311 modifier_short_vals_resp);
313 modifier = match_strval(control & XDLC_U_MODIFIER_MASK,
314 modifier_short_vals_cmd);
316 if (modifier == NULL)
317 modifier = "Unknown";
318 sprintf(info, "U%s, func = %s",
319 ((control & XDLC_P_F) ?
320 (is_response ? " F" : " P") :
323 if (check_col(pinfo->fd, COL_INFO))
324 col_add_str(pinfo->fd, COL_INFO, info);
326 tc = proto_tree_add_uint_format(xdlc_tree, hf_xdlc_control, tvb,
329 "Control field: %s (0x%02X)", info, control);
330 control_tree = proto_item_add_subtree(tc, ett_xdlc_control);
331 if (control & XDLC_P_F) {
332 proto_tree_add_text(control_tree, tvb, offset, 2,
333 decode_boolean_bitfield(control, XDLC_P_F, 1*8,
334 (is_response ? "Final" : "Poll"), NULL));
336 proto_tree_add_text(control_tree, tvb, offset, 1,
337 decode_enumerated_bitfield(control, XDLC_U_MODIFIER_MASK, 1*8,
338 (is_response ? modifier_vals_resp : modifier_vals_cmd),
340 /* This will always say it's an unnumbered frame */
341 proto_tree_add_text(control_tree, tvb, offset, 1,
342 decode_boolean_bitfield(control, 0x03, 1*8,
343 "Unnumbered frame", NULL));
352 control = tvb_get_letohs(tvb, offset);
354 control = tvb_get_guint8(tvb, offset);
356 sprintf(info, "I%s, N(R) = %u, N(S) = %u",
357 ((control & XDLC_P_F_EXT) ? " P" : ""),
358 (control & XDLC_N_R_EXT_MASK) >> XDLC_N_R_EXT_SHIFT,
359 (control & XDLC_N_S_EXT_MASK) >> XDLC_N_S_EXT_SHIFT);
361 sprintf(info, "I%s, N(R) = %u, N(S) = %u",
362 ((control & XDLC_P_F) ? " P" : ""),
363 (control & XDLC_N_R_MASK) >> XDLC_N_R_SHIFT,
364 (control & XDLC_N_S_MASK) >> XDLC_N_S_SHIFT);
366 if (check_col(pinfo->fd, COL_INFO))
367 col_add_str(pinfo->fd, COL_INFO, info);
369 tc = proto_tree_add_uint_format(xdlc_tree, hf_xdlc_control, tvb,
370 offset, (is_extended) ? 2 : 1,
372 (is_extended) ? "Control field: %s (0x%04X)"
373 : "Control field: %s (0x%02X)",
375 control_tree = proto_item_add_subtree(tc, ett_xdlc_control);
377 proto_tree_add_text(control_tree, tvb, offset, 2,
378 decode_numeric_bitfield(control, XDLC_N_R_EXT_MASK, 2*8,
380 proto_tree_add_text(control_tree, tvb, offset, 2,
381 decode_numeric_bitfield(control, XDLC_N_S_EXT_MASK, 2*8,
383 if (control & XDLC_P_F_EXT) {
384 proto_tree_add_text(control_tree, tvb, offset, 2,
385 decode_boolean_bitfield(control, XDLC_P_F_EXT, 2*8,
388 /* This will always say it's an information frame */
389 proto_tree_add_text(control_tree, tvb, offset, 2,
390 decode_boolean_bitfield(control, 0x01, 2*8,
391 NULL, "Information frame"));
393 proto_tree_add_text(control_tree, tvb, offset, 1,
394 decode_numeric_bitfield(control, XDLC_N_R_MASK, 1*8,
396 proto_tree_add_text(control_tree, tvb, offset, 1,
397 decode_numeric_bitfield(control, XDLC_N_S_MASK, 1*8,
399 if (control & XDLC_P_F) {
400 proto_tree_add_text(control_tree, tvb, offset, 1,
401 decode_boolean_bitfield(control, XDLC_P_F, 1*8,
404 /* This will always say it's an information frame */
405 proto_tree_add_text(control_tree, tvb, offset, 1,
406 decode_boolean_bitfield(control, 0x01, 1*8,
407 NULL, "Information frame"));