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.21 2003/09/02 19:18:52 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>
38 * N(S) and N(R) fields, in basic and extended operation.
40 #define XDLC_N_R_MASK 0xE0 /* basic */
41 #define XDLC_N_R_SHIFT 5
42 #define XDLC_N_R_EXT_MASK 0xFE00 /* extended */
43 #define XDLC_N_R_EXT_SHIFT 9
44 #define XDLC_N_S_MASK 0x0E /* basic */
45 #define XDLC_N_S_SHIFT 1
46 #define XDLC_N_S_EXT_MASK 0x00FE /* extended */
47 #define XDLC_N_S_EXT_SHIFT 1
50 * Poll/Final bit, in basic and extended operation.
52 #define XDLC_P_F 0x10 /* basic */
53 #define XDLC_P_F_EXT 0x0100 /* extended */
56 * S-format frame types.
58 #define XDLC_S_FTYPE_MASK 0x0C
59 #define XDLC_RR 0x00 /* Receiver ready */
60 #define XDLC_RNR 0x04 /* Receiver not ready */
61 #define XDLC_REJ 0x08 /* Reject */
62 #define XDLC_SREJ 0x0C /* Selective reject */
64 static const value_string stype_vals[] = {
65 { XDLC_RR, "Receiver ready" },
66 { XDLC_RNR, "Receiver not ready" },
67 { XDLC_REJ, "Reject" },
68 { XDLC_SREJ, "Selective reject" },
72 static const value_string modifier_short_vals_cmd[] = {
75 { XDLC_DISC, "DISC" },
77 { XDLC_SNRM, "SNRM" },
78 { XDLC_SNRME, "SNRME" },
79 { XDLC_TEST, "TEST" },
81 { XDLC_FRMR, "FRMR" },
82 { XDLC_CFGR, "CFGR" },
83 { XDLC_SARM, "SARM" },
84 { XDLC_SABM, "SABM" },
85 { XDLC_SARME, "SARME" },
86 { XDLC_SABME, "SABME" },
87 { XDLC_RESET, "RESET" },
89 { XDLC_SNRME, "SNRME" },
94 static const value_string modifier_vals_cmd[] = {
95 { XDLC_UI, "Unnumbered Information" },
96 { XDLC_UP, "Unnumbered Poll" },
97 { XDLC_DISC, "Disconnect" },
98 { XDLC_UA, "Unnumbered Acknowledge" },
99 { XDLC_SNRM, "Set Normal Response Mode" },
100 { XDLC_TEST, "Test" },
101 { XDLC_SIM, "Set Initialization Mode" },
102 { XDLC_FRMR, "Frame reject" },
103 { XDLC_CFGR, "Configure" },
104 { XDLC_SARM, "Set Asynchronous Response Mode" },
105 { XDLC_SABM, "Set Asynchronous Balanced Mode" },
106 { XDLC_SARME, "Set Asynchronous Response Mode Extended" },
107 { XDLC_SABME, "Set Asynchronous Balanced Mode Extended" },
108 { XDLC_RESET, "Reset" },
109 { XDLC_XID, "Exchange identification" },
110 { XDLC_SNRME, "Set Normal Response Mode Extended" },
111 { XDLC_BCN, "Beacon" },
115 static const value_string modifier_short_vals_resp[] = {
120 { XDLC_SNRM, "SNRM" },
121 { XDLC_TEST, "TEST" },
123 { XDLC_FRMR, "FRMR" },
124 { XDLC_CFGR, "CFGR" },
126 { XDLC_SABM, "SABM" },
127 { XDLC_SARME, "SARME" },
128 { XDLC_SABME, "SABME" },
129 { XDLC_RESET, "RESET" },
131 { XDLC_SNRME, "SNRME" },
136 static const value_string modifier_vals_resp[] = {
137 { XDLC_UI, "Unnumbered Information" },
138 { XDLC_UP, "Unnumbered Poll" },
139 { XDLC_RD, "Request Disconnect" },
140 { XDLC_UA, "Unnumbered Acknowledge" },
141 { XDLC_SNRM, "Set Normal Response Mode" },
142 { XDLC_TEST, "Test" },
143 { XDLC_RIM, "Request Initialization Mode" },
144 { XDLC_FRMR, "Frame reject" },
145 { XDLC_CFGR, "Configure" },
146 { XDLC_DM, "Disconnected mode" },
147 { XDLC_SABM, "Set Asynchronous Balanced Mode" },
148 { XDLC_SARME, "Set Asynchronous Response Mode Extended" },
149 { XDLC_SABME, "Set Asynchronous Balanced Mode Extended" },
150 { XDLC_RESET, "Reset" },
151 { XDLC_XID, "Exchange identification" },
152 { XDLC_SNRME, "Set Normal Response Mode Extended" },
153 { XDLC_BCN, "Beacon" },
158 get_xdlc_control(const guchar *pd, int offset, int is_extended)
162 switch (pd[offset] & 0x03) {
167 * Supervisory or Information frame.
170 control = pletohs(&pd[offset]);
172 control = pd[offset];
179 * XXX - is this two octets, with a P/F bit, in HDLC extended
180 * operation? It's one octet in LLC, even though the control
181 * field of I and S frames is a 2-byte extended-operation field
182 * in LLC. Given that there are no sequence numbers in the
183 * control field of a U frame, there doesn't appear to be any
184 * need for it to be 2 bytes in extended operation.
186 control = pd[offset];
193 dissect_xdlc_control(tvbuff_t *tvb, int offset, packet_info *pinfo,
194 proto_tree *xdlc_tree, int hf_xdlc_control, gint ett_xdlc_control,
195 int is_response, int is_extended, int append_info)
199 proto_tree *tc, *control_tree;
200 gchar *frame_type = NULL;
203 switch (tvb_get_guint8(tvb, offset) & 0x03) {
210 control = tvb_get_letohs(tvb, offset);
212 control = tvb_get_guint8(tvb, offset);
213 switch (control & XDLC_S_FTYPE_MASK) {
231 sprintf(info, "S%s, %sN(R) = %u", frame_type,
232 ((control & XDLC_P_F_EXT) ?
233 (is_response ? "func = F, " : "func = P, ") :
235 (control & XDLC_N_R_EXT_MASK) >> XDLC_N_R_EXT_SHIFT);
237 sprintf(info, "S%s, %sN(R) = %u", frame_type,
238 ((control & XDLC_P_F) ?
239 (is_response ? "func = F, " : "func = 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);
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->cinfo, COL_INFO)) {
325 col_append_str(pinfo->cinfo, COL_INFO, ", ");
326 col_append_str(pinfo->cinfo, COL_INFO, info);
328 col_add_str(pinfo->cinfo, COL_INFO, info);
331 tc = proto_tree_add_uint_format(xdlc_tree, hf_xdlc_control, tvb,
334 "Control field: %s (0x%02X)", info, control);
335 control_tree = proto_item_add_subtree(tc, ett_xdlc_control);
336 if (control & XDLC_P_F) {
337 proto_tree_add_text(control_tree, tvb, offset, 2,
338 decode_boolean_bitfield(control, XDLC_P_F, 1*8,
339 (is_response ? "Final" : "Poll"), NULL));
341 proto_tree_add_text(control_tree, tvb, offset, 1,
342 decode_enumerated_bitfield(control, XDLC_U_MODIFIER_MASK, 1*8,
343 (is_response ? modifier_vals_resp : modifier_vals_cmd),
345 /* This will always say it's an unnumbered frame */
346 proto_tree_add_text(control_tree, tvb, offset, 1,
347 decode_boolean_bitfield(control, 0x03, 1*8,
348 "Unnumbered frame", NULL));
357 control = tvb_get_letohs(tvb, offset);
359 control = tvb_get_guint8(tvb, offset);
361 sprintf(info, "I%s, N(R) = %u, N(S) = %u",
362 ((control & XDLC_P_F_EXT) ? " P" : ""),
363 (control & XDLC_N_R_EXT_MASK) >> XDLC_N_R_EXT_SHIFT,
364 (control & XDLC_N_S_EXT_MASK) >> XDLC_N_S_EXT_SHIFT);
366 sprintf(info, "I%s, N(R) = %u, N(S) = %u",
367 ((control & XDLC_P_F) ? " P" : ""),
368 (control & XDLC_N_R_MASK) >> XDLC_N_R_SHIFT,
369 (control & XDLC_N_S_MASK) >> XDLC_N_S_SHIFT);
371 if (check_col(pinfo->cinfo, COL_INFO)) {
373 col_append_str(pinfo->cinfo, COL_INFO, ", ");
374 col_append_str(pinfo->cinfo, COL_INFO, info);
376 col_add_str(pinfo->cinfo, COL_INFO, info);
379 tc = proto_tree_add_uint_format(xdlc_tree, hf_xdlc_control, tvb,
380 offset, (is_extended) ? 2 : 1,
382 (is_extended) ? "Control field: %s (0x%04X)"
383 : "Control field: %s (0x%02X)",
385 control_tree = proto_item_add_subtree(tc, ett_xdlc_control);
387 proto_tree_add_text(control_tree, tvb, offset, 2,
388 decode_numeric_bitfield(control, XDLC_N_R_EXT_MASK, 2*8,
390 proto_tree_add_text(control_tree, tvb, offset, 2,
391 decode_numeric_bitfield(control, XDLC_N_S_EXT_MASK, 2*8,
393 if (control & XDLC_P_F_EXT) {
394 proto_tree_add_text(control_tree, tvb, offset, 2,
395 decode_boolean_bitfield(control, XDLC_P_F_EXT, 2*8,
398 /* This will always say it's an information frame */
399 proto_tree_add_text(control_tree, tvb, offset, 2,
400 decode_boolean_bitfield(control, 0x01, 2*8,
401 NULL, "Information frame"));
403 proto_tree_add_text(control_tree, tvb, offset, 1,
404 decode_numeric_bitfield(control, XDLC_N_R_MASK, 1*8,
406 proto_tree_add_text(control_tree, tvb, offset, 1,
407 decode_numeric_bitfield(control, XDLC_N_S_MASK, 1*8,
409 if (control & XDLC_P_F) {
410 proto_tree_add_text(control_tree, tvb, offset, 1,
411 decode_boolean_bitfield(control, XDLC_P_F, 1*8,
414 /* This will always say it's an information frame */
415 proto_tree_add_text(control_tree, tvb, offset, 1,
416 decode_boolean_bitfield(control, 0x01, 1*8,
417 NULL, "Information frame"));