From 454806eeff5bd53d1283bbc2fafe86cdf0eddd48 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Tue, 2 Sep 2003 19:18:52 +0000 Subject: [PATCH] Use "dissect_xdlc_control()" to dissect the control field of Frame Relay packets that have one. Add an argument to "dissect_xdlc_control()" to indicate whether it should append the information to the Info field or just put it in the Info field. Use the #defines for the DLCI bitfields to extract the DLCI bits when constructing the DLCI. svn path=/trunk/; revision=8335 --- packet-fr.c | 41 +++++++++++++++++++++++++---------------- packet-lapb.c | 4 ++-- packet-lapd.c | 4 ++-- packet-llc.c | 4 ++-- packet-sdlc.c | 4 ++-- packet-v120.c | 4 ++-- xdlc.c | 31 +++++++++++++++++++++++-------- xdlc.h | 4 ++-- 8 files changed, 60 insertions(+), 36 deletions(-) diff --git a/packet-fr.c b/packet-fr.c index a7080f695e..7819554323 100644 --- a/packet-fr.c +++ b/packet-fr.c @@ -3,7 +3,7 @@ * * Copyright 2001, Paul Ionescu * - * $Id: packet-fr.c,v 1.36 2003/09/02 18:45:06 guy Exp $ + * $Id: packet-fr.c,v 1.37 2003/09/02 19:18:51 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -77,6 +77,7 @@ static gint proto_fr = -1; static gint ett_fr = -1; static gint ett_fr_address = -1; +static gint ett_fr_control = -1; static gint hf_fr_ea = -1; static gint hf_fr_upper_dlci = -1; static gint hf_fr_cr = -1; @@ -89,6 +90,7 @@ static gint hf_fr_dlcore_control = -1; static gint hf_fr_lower_dlci = -1; static gint hf_fr_dc = -1; static gint hf_fr_dlci = -1; +static gint hf_fr_control = -1; static gint hf_fr_nlpid = -1; static gint hf_fr_oui = -1; static gint hf_fr_pid = -1; @@ -157,6 +159,7 @@ dissect_fr_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_item *octet_item = NULL; proto_tree *octet_tree = NULL; guint8 fr_octet; + int is_response = FALSE; guint32 address; guint8 fr_ctrl; guint16 fr_type; @@ -203,7 +206,8 @@ dissect_fr_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, * The first octet contains the upper 6 bits of the DLCI, as well * as the C/R bit. */ - address = (fr_octet & 0xFC) >> 2; + address = (fr_octet & FRELAY_UPPER_DLCI) >> 2; + is_response = (fr_octet & FRELAY_CR); if (tree) { octet_item = proto_tree_add_text(fr_tree, tvb, offset, 1, "First address octet: 0x%02x", fr_octet); @@ -219,7 +223,7 @@ dissect_fr_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, * BECN, and DE. */ fr_octet = tvb_get_guint8(tvb, offset); - address = (address << 4) | ((fr_octet & 0xF0) >> 4); + address = (address << 4) | ((fr_octet & FRELAY_SECOND_DLCI) >> 4); if (tree) { octet_item = proto_tree_add_text(fr_tree, tvb, offset, 1, "Second address octet: 0x%02x", @@ -246,7 +250,7 @@ dissect_fr_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, /* * 7 more bits of DLCI. */ - address = (address << 7) | ((fr_octet & 0xFE) >> 1); + address = (address << 7) | ((fr_octet & FRELAY_THIRD_DLCI) >> 1); if (tree) { octet_item = proto_tree_add_text(fr_tree, tvb, offset, 1, "Third address octet: 0x%02x", @@ -289,7 +293,7 @@ dissect_fr_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, /* * Last 6 bits of DLCI. */ - address = (address << 6) | ((fr_octet & 0xFC) >> 2); + address = (address << 6) | ((fr_octet & FRELAY_LOWER_DLCI) >> 2); proto_tree_add_uint(octet_tree, hf_fr_lower_dlci, tvb, offset, 1, fr_octet); } proto_tree_add_boolean(octet_tree, hf_fr_dc, tvb, offset, 1, fr_octet); @@ -309,15 +313,10 @@ dissect_fr_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, fr_ctrl = tvb_get_guint8(tvb, offset); if (fr_ctrl == XDLC_U) { - if (tree) { + if (tree) proto_tree_add_text(fr_tree, tvb, offset, 0, "------- Q.922 Encapsulation -------"); - /* - * XXX - if we're going to show this as Unnumbered - * Information, should we just hand it to - * "dissect_xdlc_control()"? - */ - proto_tree_add_text(fr_tree, tvb, offset, 1, "Unnumbered Information"); - } + dissect_xdlc_control(tvb, offset, pinfo, fr_tree, hf_fr_control, + ett_fr_control, is_response, FALSE, TRUE); offset++; dissect_fr_nlpid(tvb, offset, pinfo, tree, ti, fr_tree, fr_ctrl); @@ -327,10 +326,16 @@ dissect_fr_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, /* because DLCI 0 is rezerved for LMI and SVC signaling encaplulated in lapf */ /* and LMI is transmitted in unnumbered information (03) */ /* so this must be lapf (guessing) */ + dissect_xdlc_control(tvb, offset, pinfo, fr_tree, + hf_fr_control, ett_fr_control, + is_response, FALSE, TRUE); dissect_lapf(tvb_new_subset(tvb,offset,-1,-1),pinfo,tree); return; } if (fr_ctrl == (XDLC_U|XDLC_XID)) { + dissect_xdlc_control(tvb, offset, pinfo, fr_tree, + hf_fr_control, ett_fr_control, + is_response, FALSE, TRUE); dissect_fr_xid(tvb_new_subset(tvb,offset,-1,-1),pinfo,tree); return; } @@ -539,9 +544,12 @@ void proto_register_fr(void) { &hf_fr_dlci, { "DLCI", "fr.dlci", FT_UINT32, BASE_DEC, NULL, 0x0, "Data-Link Connection Identifier", HFILL }}, + { &hf_fr_control, { + "Control Field", "fr.control", FT_UINT8, BASE_HEX, + NULL, 0x0, "Control field", HFILL }}, { &hf_fr_nlpid, { "NLPID", "fr.nlpid", FT_UINT8, BASE_HEX, - VALS(fr_nlpid_vals), 0x0, "FrameRelay Encapsulated Protocol NLPID", HFILL }}, + VALS(fr_nlpid_vals), 0x0, "Frame Relay Encapsulated Protocol NLPID", HFILL }}, { &hf_fr_oui, { "Organization Code", "fr.snap.oui", FT_UINT24, BASE_HEX, VALS(oui_vals), 0x0, "", HFILL }}, @@ -550,10 +558,10 @@ void proto_register_fr(void) NULL, 0x0, "", HFILL }}, { &hf_fr_snaptype, { "Type", "fr.snaptype", FT_UINT16, BASE_HEX, - VALS(etype_vals), 0x0, "FrameRelay SNAP Encapsulated Protocol", HFILL }}, + VALS(etype_vals), 0x0, "Frame Relay SNAP Encapsulated Protocol", HFILL }}, { &hf_fr_chdlctype, { "Type", "fr.chdlctype", FT_UINT16, BASE_HEX, - VALS(chdlc_vals), 0x0, "FrameRelay Cisco HDLC Encapsulated Protocol", HFILL }}, + VALS(chdlc_vals), 0x0, "Frame Relay Cisco HDLC Encapsulated Protocol", HFILL }}, }; @@ -561,6 +569,7 @@ void proto_register_fr(void) static gint *ett[] = { &ett_fr, &ett_fr_address, + &ett_fr_control, }; proto_fr = proto_register_protocol("Frame Relay", "FR", "fr"); diff --git a/packet-lapb.c b/packet-lapb.c index 5ab75c33e6..5486029678 100644 --- a/packet-lapb.c +++ b/packet-lapb.c @@ -2,7 +2,7 @@ * Routines for lapb frame disassembly * Olivier Abad * - * $Id: packet-lapb.c,v 1.38 2002/09/01 14:30:30 oabad Exp $ + * $Id: packet-lapb.c,v 1.39 2003/09/02 19:18:52 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -97,7 +97,7 @@ dissect_lapb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) lapb_tree = NULL; dissect_xdlc_control(tvb, 1, pinfo, lapb_tree, hf_lapb_control, - ett_lapb_control, is_response, FALSE); + ett_lapb_control, is_response, FALSE, FALSE); /* not end of frame ==> X.25 */ if (tvb_reported_length(tvb) > 2) { diff --git a/packet-lapd.c b/packet-lapd.c index 12a8676cd9..f69b5cbce6 100644 --- a/packet-lapd.c +++ b/packet-lapd.c @@ -2,7 +2,7 @@ * Routines for LAPD frame disassembly * Gilbert Ramirez * - * $Id: packet-lapd.c,v 1.34 2003/01/07 01:08:27 guy Exp $ + * $Id: packet-lapd.c,v 1.35 2003/09/02 19:18:52 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -137,7 +137,7 @@ dissect_lapd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) } control = dissect_xdlc_control(tvb, 2, pinfo, lapd_tree, hf_lapd_control, - ett_lapd_control, is_response, TRUE); + ett_lapd_control, is_response, TRUE, FALSE); lapd_header_len += XDLC_CONTROL_LEN(control, TRUE); if (tree) diff --git a/packet-llc.c b/packet-llc.c index 35afe43e9d..c930997f5c 100644 --- a/packet-llc.c +++ b/packet-llc.c @@ -2,7 +2,7 @@ * Routines for IEEE 802.2 LLC layer * Gilbert Ramirez * - * $Id: packet-llc.c,v 1.112 2003/08/28 01:29:15 guy Exp $ + * $Id: packet-llc.c,v 1.113 2003/09/02 19:18:52 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -351,7 +351,7 @@ dissect_llc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) */ control = dissect_xdlc_control(tvb, 2, pinfo, llc_tree, hf_llc_ctrl, ett_llc_ctrl, - ssap & SSAP_CR_BIT, TRUE); + ssap & SSAP_CR_BIT, TRUE, FALSE); llc_header_len += XDLC_CONTROL_LEN(control, TRUE); if (is_snap) llc_header_len += 5; /* 3 bytes of OUI, 2 bytes of protocol ID */ diff --git a/packet-sdlc.c b/packet-sdlc.c index b485f971ae..8983090ee6 100644 --- a/packet-sdlc.c +++ b/packet-sdlc.c @@ -1,7 +1,7 @@ /* packet-sdlc.c * Routines for SDLC frame disassembly * - * $Id: packet-sdlc.c,v 1.1 2003/01/03 22:31:24 guy Exp $ + * $Id: packet-sdlc.c,v 1.2 2003/09/02 19:18:52 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -107,7 +107,7 @@ dissect_sdlc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) * to control what to use. */ control = dissect_xdlc_control(tvb, 1, pinfo, sdlc_tree, hf_sdlc_control, - ett_sdlc_control, is_response, FALSE); + ett_sdlc_control, is_response, FALSE, FALSE); sdlc_header_len += XDLC_CONTROL_LEN(control, FALSE); if (tree) diff --git a/packet-v120.c b/packet-v120.c index 5c6a856351..25dc238d4e 100644 --- a/packet-v120.c +++ b/packet-v120.c @@ -2,7 +2,7 @@ * Routines for v120 frame disassembly * Bert Driehuis * - * $Id: packet-v120.c,v 1.30 2002/10/31 07:43:10 guy Exp $ + * $Id: packet-v120.c,v 1.31 2003/09/02 19:18:52 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -126,7 +126,7 @@ dissect_v120(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) ti = NULL; } control = dissect_xdlc_control(tvb, 2, pinfo, v120_tree, hf_v120_control, - ett_v120_control, is_response, TRUE); + ett_v120_control, is_response, TRUE, FALSE); if (tree) { v120len = 2 + XDLC_CONTROL_LEN(control, TRUE); if (tvb_bytes_exist(tvb, v120len, 1)) diff --git a/xdlc.c b/xdlc.c index 6bdca9f51a..85bd1df316 100644 --- a/xdlc.c +++ b/xdlc.c @@ -2,7 +2,7 @@ * Routines for use by various SDLC-derived protocols, such as HDLC * and its derivatives LAPB, IEEE 802.2 LLC, etc.. * - * $Id: xdlc.c,v 1.20 2002/08/28 21:00:41 jmayer Exp $ + * $Id: xdlc.c,v 1.21 2003/09/02 19:18:52 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -192,7 +192,7 @@ get_xdlc_control(const guchar *pd, int offset, int is_extended) int dissect_xdlc_control(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *xdlc_tree, int hf_xdlc_control, gint ett_xdlc_control, - int is_response, int is_extended) + int is_response, int is_extended, int append_info) { guint16 control; char info[80]; @@ -240,8 +240,13 @@ dissect_xdlc_control(tvbuff_t *tvb, int offset, packet_info *pinfo, ""), (control & XDLC_N_R_MASK) >> XDLC_N_R_SHIFT); } - if (check_col(pinfo->cinfo, COL_INFO)) - col_add_str(pinfo->cinfo, COL_INFO, info); + if (check_col(pinfo->cinfo, COL_INFO)) { + if (append_info) { + col_append_str(pinfo->cinfo, COL_INFO, ", "); + col_append_str(pinfo->cinfo, COL_INFO, info); + } else + col_add_str(pinfo->cinfo, COL_INFO, info); + } if (xdlc_tree) { if (is_extended) { tc = proto_tree_add_uint_format(xdlc_tree, hf_xdlc_control, tvb, @@ -315,8 +320,13 @@ dissect_xdlc_control(tvbuff_t *tvb, int offset, packet_info *pinfo, (is_response ? " F" : " P") : ""), modifier); - if (check_col(pinfo->cinfo, COL_INFO)) - col_add_str(pinfo->cinfo, COL_INFO, info); + if (check_col(pinfo->cinfo, COL_INFO)) { + if (append_info) { + col_append_str(pinfo->cinfo, COL_INFO, ", "); + col_append_str(pinfo->cinfo, COL_INFO, info); + } else + col_add_str(pinfo->cinfo, COL_INFO, info); + } if (xdlc_tree) { tc = proto_tree_add_uint_format(xdlc_tree, hf_xdlc_control, tvb, offset, 1, @@ -358,8 +368,13 @@ dissect_xdlc_control(tvbuff_t *tvb, int offset, packet_info *pinfo, (control & XDLC_N_R_MASK) >> XDLC_N_R_SHIFT, (control & XDLC_N_S_MASK) >> XDLC_N_S_SHIFT); } - if (check_col(pinfo->cinfo, COL_INFO)) - col_add_str(pinfo->cinfo, COL_INFO, info); + if (check_col(pinfo->cinfo, COL_INFO)) { + if (append_info) { + col_append_str(pinfo->cinfo, COL_INFO, ", "); + col_append_str(pinfo->cinfo, COL_INFO, info); + } else + col_add_str(pinfo->cinfo, COL_INFO, info); + } if (xdlc_tree) { tc = proto_tree_add_uint_format(xdlc_tree, hf_xdlc_control, tvb, offset, (is_extended) ? 2 : 1, diff --git a/xdlc.h b/xdlc.h index 5684c5fa18..376eaf5950 100644 --- a/xdlc.h +++ b/xdlc.h @@ -2,7 +2,7 @@ * Define *DLC frame types, and routine to dissect the control field of * a *DLC frame. * - * $Id: xdlc.h,v 1.17 2002/08/28 21:00:41 jmayer Exp $ + * $Id: xdlc.h,v 1.18 2003/09/02 19:18:52 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -84,6 +84,6 @@ int get_xdlc_control(const guchar *pd, int offset, int dissect_xdlc_control(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *xdlc_tree, int hf_xdlc_control, gint ett_xdlc_control, - int is_response, int extended); + int is_response, int extended, int append_info); #endif