2 * Routines for SDLC frame disassembly
4 * $Id: packet-sdlc.c,v 1.1 2003/01/03 22:31:24 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #include <epan/packet.h>
38 * http://www.protocols.com/pbook/sna.htm
41 static int proto_sdlc = -1;
42 static int hf_sdlc_address = -1;
43 static int hf_sdlc_control = -1;
45 static gint ett_sdlc = -1;
46 static gint ett_sdlc_control = -1;
48 static dissector_handle_t sna_handle;
49 static dissector_handle_t data_handle;
52 dissect_sdlc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
54 proto_tree *sdlc_tree;
62 if (check_col(pinfo->cinfo, COL_PROTOCOL))
63 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SDLC");
64 if (check_col(pinfo->cinfo, COL_INFO))
65 col_clear(pinfo->cinfo, COL_INFO);
67 address = tvb_get_guint8(tvb, 0);
68 sdlc_header_len = 1; /* address */
71 * XXX - is there something in the SDLC header that indicates
72 * how to interpret "command vs. response" based on the
75 if (pinfo->p2p_dir == P2P_DIR_SENT) {
77 if (check_col(pinfo->cinfo, COL_RES_DL_DST))
78 col_set_str(pinfo->cinfo, COL_RES_DL_DST, "DCE");
79 if (check_col(pinfo->cinfo, COL_RES_DL_SRC))
80 col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "DTE");
83 /* XXX - what if the direction is unknown? */
85 if (check_col(pinfo->cinfo, COL_RES_DL_DST))
86 col_set_str(pinfo->cinfo, COL_RES_DL_DST, "DTE");
87 if (check_col(pinfo->cinfo, COL_RES_DL_SRC))
88 col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "DCE");
92 sdlc_ti = proto_tree_add_item(tree, proto_sdlc, tvb, 0, -1,
94 sdlc_tree = proto_item_add_subtree(sdlc_ti, ett_sdlc);
96 proto_tree_add_uint(sdlc_tree, hf_sdlc_address, tvb, 0, 1,
104 * XXX - SDLC has a mod-128 mode as well as a mod-7 mode.
105 * We can infer the mode from an SNRM/SRME frame, but if
106 * we don't see one of them, we may have to have a preference
107 * to control what to use.
109 control = dissect_xdlc_control(tvb, 1, pinfo, sdlc_tree, hf_sdlc_control,
110 ett_sdlc_control, is_response, FALSE);
111 sdlc_header_len += XDLC_CONTROL_LEN(control, FALSE);
114 proto_item_set_len(sdlc_ti, sdlc_header_len);
117 * XXX - is there an FCS at the end, at least in Sniffer
118 * captures? (There doesn't appear to be.)
120 next_tvb = tvb_new_subset(tvb, sdlc_header_len, -1, -1);
121 if (XDLC_IS_INFORMATION(control)) {
122 /* call the SNA dissector */
123 call_dissector(sna_handle, next_tvb, pinfo, tree);
125 call_dissector(data_handle, next_tvb, pinfo, tree);
129 proto_register_sdlc(void)
131 static hf_register_info hf[] = {
133 { "Address Field", "sdlc.address", FT_UINT8, BASE_HEX,
134 NULL, 0x0, "Address", HFILL }},
137 { "Control Field", "sdlc.control", FT_UINT16, BASE_HEX,
138 NULL, 0x0, "Control field", HFILL }},
140 static gint *ett[] = {
145 proto_sdlc = proto_register_protocol(
146 "Synchronous Data Link Control (SDLC)", "SDLC", "sdlc");
147 proto_register_field_array(proto_sdlc, hf, array_length(hf));
148 proto_register_subtree_array(ett, array_length(ett));
152 proto_reg_handoff_sdlc(void)
154 dissector_handle_t sdlc_handle;
157 * Get handle for the SNA dissector.
159 sna_handle = find_dissector("sna");
160 data_handle = find_dissector("data");
162 sdlc_handle = create_dissector_handle(dissect_sdlc, proto_sdlc);
163 dissector_add("wtap_encap", WTAP_ENCAP_SDLC, sdlc_handle);