2 * Routines for SDLC frame disassembly
4 * $Id: packet-sdlc.c,v 1.4 2004/01/18 08:32:46 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;
44 static int hf_sdlc_n_r = -1;
45 static int hf_sdlc_n_s = -1;
46 static int hf_sdlc_p = -1;
47 static int hf_sdlc_f = -1;
48 static int hf_sdlc_s_ftype = -1;
49 static int hf_sdlc_u_modifier_cmd = -1;
50 static int hf_sdlc_u_modifier_resp = -1;
51 static int hf_sdlc_ftype_i = -1;
52 static int hf_sdlc_ftype_s_u = -1;
54 static gint ett_sdlc = -1;
55 static gint ett_sdlc_control = -1;
57 static dissector_handle_t sna_handle;
58 static dissector_handle_t data_handle;
60 static const xdlc_cf_items sdlc_cf_items = {
66 &hf_sdlc_u_modifier_cmd,
67 &hf_sdlc_u_modifier_resp,
73 dissect_sdlc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
75 proto_tree *sdlc_tree;
83 if (check_col(pinfo->cinfo, COL_PROTOCOL))
84 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SDLC");
85 if (check_col(pinfo->cinfo, COL_INFO))
86 col_clear(pinfo->cinfo, COL_INFO);
88 address = tvb_get_guint8(tvb, 0);
89 sdlc_header_len = 1; /* address */
92 * XXX - is there something in the SDLC header that indicates
93 * how to interpret "command vs. response" based on the
96 if (pinfo->p2p_dir == P2P_DIR_SENT) {
98 if (check_col(pinfo->cinfo, COL_RES_DL_DST))
99 col_set_str(pinfo->cinfo, COL_RES_DL_DST, "DCE");
100 if (check_col(pinfo->cinfo, COL_RES_DL_SRC))
101 col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "DTE");
104 /* XXX - what if the direction is unknown? */
106 if (check_col(pinfo->cinfo, COL_RES_DL_DST))
107 col_set_str(pinfo->cinfo, COL_RES_DL_DST, "DTE");
108 if (check_col(pinfo->cinfo, COL_RES_DL_SRC))
109 col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "DCE");
113 sdlc_ti = proto_tree_add_item(tree, proto_sdlc, tvb, 0, -1,
115 sdlc_tree = proto_item_add_subtree(sdlc_ti, ett_sdlc);
117 proto_tree_add_uint(sdlc_tree, hf_sdlc_address, tvb, 0, 1,
125 * XXX - SDLC has a mod-128 mode as well as a mod-7 mode.
126 * We can infer the mode from an SNRM/SRME frame, but if
127 * we don't see one of them, we may have to have a preference
128 * to control what to use.
130 control = dissect_xdlc_control(tvb, 1, pinfo, sdlc_tree, hf_sdlc_control,
131 ett_sdlc_control, &sdlc_cf_items, NULL, NULL, NULL,
132 is_response, FALSE, FALSE);
133 sdlc_header_len += XDLC_CONTROL_LEN(control, FALSE);
136 proto_item_set_len(sdlc_ti, sdlc_header_len);
139 * XXX - is there an FCS at the end, at least in Sniffer
140 * captures? (There doesn't appear to be.)
142 next_tvb = tvb_new_subset(tvb, sdlc_header_len, -1, -1);
143 if (XDLC_IS_INFORMATION(control)) {
144 /* call the SNA dissector */
145 call_dissector(sna_handle, next_tvb, pinfo, tree);
147 call_dissector(data_handle, next_tvb, pinfo, tree);
151 proto_register_sdlc(void)
153 static hf_register_info hf[] = {
155 { "Address Field", "sdlc.address", FT_UINT8, BASE_HEX,
156 NULL, 0x0, "Address", HFILL }},
159 { "Control Field", "sdlc.control", FT_UINT16, BASE_HEX,
160 NULL, 0x0, "Control field", HFILL }},
163 { "N(R)", "sdlc.control.n_r", FT_UINT8, BASE_DEC,
164 NULL, XDLC_N_R_MASK, "", HFILL }},
167 { "N(S)", "sdlc.control.n_s", FT_UINT8, BASE_DEC,
168 NULL, XDLC_N_S_MASK, "", HFILL }},
171 { "Poll", "sdlc.control.p", FT_BOOLEAN, 8,
172 TFS(&flags_set_truth), XDLC_P_F, "", HFILL }},
175 { "Final", "sdlc.control.f", FT_BOOLEAN, 8,
176 TFS(&flags_set_truth), XDLC_P_F, "", HFILL }},
179 { "Supervisory frame type", "sdlc.control.s_ftype", FT_UINT8, BASE_HEX,
180 VALS(stype_vals), XDLC_S_FTYPE_MASK, "", HFILL }},
182 { &hf_sdlc_u_modifier_cmd,
183 { "Command", "sdlc.control.u_modifier_cmd", FT_UINT8, BASE_HEX,
184 VALS(modifier_vals_cmd), XDLC_U_MODIFIER_MASK, "", HFILL }},
186 { &hf_sdlc_u_modifier_resp,
187 { "Response", "sdlc.control.u_modifier_resp", FT_UINT8, BASE_HEX,
188 VALS(modifier_vals_resp), XDLC_U_MODIFIER_MASK, "", HFILL }},
191 { "Frame type", "sdlc.control.ftype", FT_UINT8, BASE_HEX,
192 VALS(ftype_vals), XDLC_I_MASK, "", HFILL }},
194 { &hf_sdlc_ftype_s_u,
195 { "Frame type", "sdlc.control.ftype", FT_UINT8, BASE_HEX,
196 VALS(ftype_vals), XDLC_S_U_MASK, "", HFILL }},
198 static gint *ett[] = {
203 proto_sdlc = proto_register_protocol(
204 "Synchronous Data Link Control (SDLC)", "SDLC", "sdlc");
205 proto_register_field_array(proto_sdlc, hf, array_length(hf));
206 proto_register_subtree_array(ett, array_length(ett));
210 proto_reg_handoff_sdlc(void)
212 dissector_handle_t sdlc_handle;
215 * Get handle for the SNA dissector.
217 sna_handle = find_dissector("sna");
218 data_handle = find_dissector("data");
220 sdlc_handle = create_dissector_handle(dissect_sdlc, proto_sdlc);
221 dissector_add("wtap_encap", WTAP_ENCAP_SDLC, sdlc_handle);