Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-sdlc.c
blob969ec68608a2c9c4dde1be13b12256c9f85403db
1 /* packet-sdlc.c
2 * Routines for SDLC frame disassembly
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
11 #include "config.h"
13 #include <epan/packet.h>
14 #include <wiretap/wtap.h>
15 #include <epan/xdlc.h>
16 #include <epan/tfs.h>
17 #include <wsutil/array.h>
20 * See:
22 * http://web.archive.org/web/20020206033700/http://www.wanresources.com/snacell.html
24 * http://web.archive.org/web/20150522015710/http://www.protocols.com/pbook/sna.htm
26 * Systems Network Architecture Formats, GA27-3136-20:
27 * https://publibfp.dhe.ibm.com/epubs/pdf/d50a5007.pdf
29 void proto_register_sdlc(void);
30 void proto_reg_handoff_sdlc(void);
32 static dissector_handle_t sdlc_handle;
34 static int proto_sdlc;
35 static int hf_sdlc_address;
36 static int hf_sdlc_control;
37 static int hf_sdlc_n_r;
38 static int hf_sdlc_n_s;
39 static int hf_sdlc_p;
40 static int hf_sdlc_f;
41 static int hf_sdlc_s_ftype;
42 static int hf_sdlc_u_modifier_cmd;
43 static int hf_sdlc_u_modifier_resp;
44 static int hf_sdlc_ftype_i;
45 static int hf_sdlc_ftype_s_u;
47 static int ett_sdlc;
48 static int ett_sdlc_control;
50 static dissector_handle_t sna_handle;
52 static const xdlc_cf_items sdlc_cf_items = {
53 &hf_sdlc_n_r,
54 &hf_sdlc_n_s,
55 &hf_sdlc_p,
56 &hf_sdlc_f,
57 &hf_sdlc_s_ftype,
58 &hf_sdlc_u_modifier_cmd,
59 &hf_sdlc_u_modifier_resp,
60 &hf_sdlc_ftype_i,
61 &hf_sdlc_ftype_s_u
64 static int
65 dissect_sdlc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
67 proto_tree *sdlc_tree;
68 proto_item *sdlc_ti;
69 uint8_t addr;
70 uint16_t control;
71 int sdlc_header_len;
72 bool is_response;
73 tvbuff_t *next_tvb;
75 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SDLC");
76 col_clear(pinfo->cinfo, COL_INFO);
78 addr = tvb_get_uint8(tvb, 0);
79 sdlc_header_len = 1; /* address */
82 * XXX - is there something in the SDLC header that indicates
83 * how to interpret "command vs. response" based on the
84 * direction?
86 if (pinfo->p2p_dir == P2P_DIR_SENT) {
87 is_response = false;
88 col_set_str(pinfo->cinfo, COL_RES_DL_DST, "DCE");
89 col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "DTE");
91 else {
92 /* XXX - what if the direction is unknown? */
93 is_response = true;
94 col_set_str(pinfo->cinfo, COL_RES_DL_DST, "DTE");
95 col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "DCE");
98 sdlc_ti = proto_tree_add_item(tree, proto_sdlc, tvb, 0, -1,
99 ENC_NA);
100 sdlc_tree = proto_item_add_subtree(sdlc_ti, ett_sdlc);
102 proto_tree_add_uint(sdlc_tree, hf_sdlc_address, tvb, 0, 1,
103 addr);
106 * XXX - SDLC has a mod-128 mode as well as a mod-7 mode.
107 * We can infer the mode from an SNRM/SRME frame, but if
108 * we don't see one of them, we may have to have a preference
109 * to control what to use.
111 control = dissect_xdlc_control(tvb, 1, pinfo, sdlc_tree, hf_sdlc_control,
112 ett_sdlc_control, &sdlc_cf_items, NULL, NULL, NULL,
113 is_response, false, false);
114 sdlc_header_len += XDLC_CONTROL_LEN(control, false);
116 proto_item_set_len(sdlc_ti, sdlc_header_len);
119 * XXX - is there an FCS at the end, at least in Sniffer
120 * captures? (There doesn't appear to be.)
122 next_tvb = tvb_new_subset_remaining(tvb, sdlc_header_len);
123 if (XDLC_IS_INFORMATION(control)) {
124 /* call the SNA dissector */
125 call_dissector(sna_handle, next_tvb, pinfo, tree);
126 } else
127 call_data_dissector(next_tvb, pinfo, tree);
129 return tvb_captured_length(tvb);
132 void
133 proto_register_sdlc(void)
135 static hf_register_info hf[] = {
136 { &hf_sdlc_address,
137 { "Address Field", "sdlc.address", FT_UINT8, BASE_HEX,
138 NULL, 0x0, NULL, HFILL }},
140 { &hf_sdlc_control,
141 { "Control Field", "sdlc.control", FT_UINT16, BASE_HEX,
142 NULL, 0x0, NULL, HFILL }},
144 { &hf_sdlc_n_r,
145 { "N(R)", "sdlc.control.n_r", FT_UINT8, BASE_DEC,
146 NULL, XDLC_N_R_MASK, NULL, HFILL }},
148 { &hf_sdlc_n_s,
149 { "N(S)", "sdlc.control.n_s", FT_UINT8, BASE_DEC,
150 NULL, XDLC_N_S_MASK, NULL, HFILL }},
152 { &hf_sdlc_p,
153 { "Poll", "sdlc.control.p", FT_BOOLEAN, 8,
154 TFS(&tfs_set_notset), XDLC_P_F, NULL, HFILL }},
156 { &hf_sdlc_f,
157 { "Final", "sdlc.control.f", FT_BOOLEAN, 8,
158 TFS(&tfs_set_notset), XDLC_P_F, NULL, HFILL }},
160 { &hf_sdlc_s_ftype,
161 { "Supervisory frame type", "sdlc.control.s_ftype", FT_UINT8, BASE_HEX,
162 VALS(stype_vals), XDLC_S_FTYPE_MASK, NULL, HFILL }},
164 { &hf_sdlc_u_modifier_cmd,
165 { "Command", "sdlc.control.u_modifier_cmd", FT_UINT8, BASE_HEX,
166 VALS(modifier_vals_cmd), XDLC_U_MODIFIER_MASK, NULL, HFILL }},
168 { &hf_sdlc_u_modifier_resp,
169 { "Response", "sdlc.control.u_modifier_resp", FT_UINT8, BASE_HEX,
170 VALS(modifier_vals_resp), XDLC_U_MODIFIER_MASK, NULL, HFILL }},
172 { &hf_sdlc_ftype_i,
173 { "Frame type", "sdlc.control.ftype", FT_UINT8, BASE_HEX,
174 VALS(ftype_vals), XDLC_I_MASK, NULL, HFILL }},
176 { &hf_sdlc_ftype_s_u,
177 { "Frame type", "sdlc.control.ftype", FT_UINT8, BASE_HEX,
178 VALS(ftype_vals), XDLC_S_U_MASK, NULL, HFILL }},
180 static int *ett[] = {
181 &ett_sdlc,
182 &ett_sdlc_control,
185 proto_sdlc = proto_register_protocol("Synchronous Data Link Control (SDLC)", "SDLC", "sdlc");
186 proto_register_field_array(proto_sdlc, hf, array_length(hf));
187 proto_register_subtree_array(ett, array_length(ett));
189 sdlc_handle = register_dissector("sdlc", dissect_sdlc, proto_sdlc);
192 void
193 proto_reg_handoff_sdlc(void)
196 * Get handle for the SNA dissector.
198 sna_handle = find_dissector_add_dependency("sna", proto_sdlc);
200 dissector_add_uint("wtap_encap", WTAP_ENCAP_SDLC, sdlc_handle);
204 * Editor modelines - https://www.wireshark.org/tools/modelines.html
206 * Local variables:
207 * c-basic-offset: 8
208 * tab-width: 8
209 * indent-tabs-mode: t
210 * End:
212 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
213 * :indentSize=8:tabSize=8:noTabs=false: