2 * Routines for LAPD frame disassembly
3 * Gilbert Ramirez <gram@alumni.rice.edu>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
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.
33 #include <epan/packet.h>
34 #include <epan/xdlc.h>
36 #include <epan/lapd_sapi.h>
38 /* ISDN/LAPD references:
40 * http://www.cisco.com/univercd/cc/td/doc/cisintwk/ito_doc/isdn.htm
41 * http://www.ece.wpi.edu/courses/ee535/hwk11cd95/agrebe/agrebe.html
42 * http://www.acacia-net.com/Clarinet/Protocol/q9213o84.htm
45 static int proto_lapd = -1;
46 static int hf_lapd_address = -1;
47 static int hf_lapd_sapi = -1;
48 static int hf_lapd_cr = -1;
49 static int hf_lapd_ea1 = -1;
50 static int hf_lapd_tei = -1;
51 static int hf_lapd_ea2 = -1;
52 static int hf_lapd_control = -1;
53 static int hf_lapd_n_r = -1;
54 static int hf_lapd_n_s = -1;
55 static int hf_lapd_p = -1;
56 static int hf_lapd_p_ext = -1;
57 static int hf_lapd_f = -1;
58 static int hf_lapd_f_ext = -1;
59 static int hf_lapd_s_ftype = -1;
60 static int hf_lapd_u_modifier_cmd = -1;
61 static int hf_lapd_u_modifier_resp = -1;
62 static int hf_lapd_ftype_i = -1;
63 static int hf_lapd_ftype_s_u = -1;
64 static int hf_lapd_ftype_s_u_ext = -1;
66 static gint ett_lapd = -1;
67 static gint ett_lapd_address = -1;
68 static gint ett_lapd_control = -1;
70 static dissector_table_t lapd_sapi_dissector_table;
72 static dissector_handle_t data_handle;
73 static dissector_handle_t tei_handle;
76 * Bits in the address field.
78 #define LAPD_SAPI 0xfc00 /* Service Access Point Identifier */
79 #define LAPD_SAPI_SHIFT 10
80 #define LAPD_CR 0x0200 /* Command/Response bit */
81 #define LAPD_EA1 0x0100 /* First Address Extension bit */
82 #define LAPD_TEI 0x00fe /* Terminal Endpoint Identifier */
83 #define LAPD_TEI_SHIFT 1
84 #define LAPD_EA2 0x0001 /* Second Address Extension bit */
86 static const value_string lapd_sapi_vals[] = {
87 { LAPD_SAPI_Q931, "Q.931 Call control procedure" },
88 { LAPD_SAPI_PM_Q931, "Packet mode Q.931 Call control procedure" },
89 { LAPD_SAPI_X25, "X.25 Level 3 procedures" },
90 { LAPD_SAPI_L2, "Layer 2 management procedures" },
94 /* Used only for U frames */
95 static const xdlc_cf_items lapd_cf_items = {
101 &hf_lapd_u_modifier_cmd,
102 &hf_lapd_u_modifier_resp,
107 /* Used only for I and S frames */
108 static const xdlc_cf_items lapd_cf_items_ext = {
117 &hf_lapd_ftype_s_u_ext
121 dissect_lapd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
123 proto_tree *lapd_tree, *addr_tree;
124 proto_item *lapd_ti, *addr_ti;
127 guint16 address, cr, sapi, tei;
128 gboolean is_response = 0;
133 if (check_col(pinfo->cinfo, COL_PROTOCOL))
134 col_set_str(pinfo->cinfo, COL_PROTOCOL, "LAPD");
135 if (check_col(pinfo->cinfo, COL_INFO))
136 col_clear(pinfo->cinfo, COL_INFO);
138 address = tvb_get_ntohs(tvb, 0);
139 cr = address & LAPD_CR;
140 tei = (address & LAPD_TEI) >> LAPD_TEI_SHIFT;
141 sapi = (address & LAPD_SAPI) >> LAPD_SAPI_SHIFT;
142 lapd_header_len = 2; /* address */
144 if (check_col(pinfo->cinfo, COL_TEI))
145 col_add_fstr(pinfo->cinfo, COL_TEI, "%u", tei);
147 if (pinfo->fd->lnk_t == WTAP_ENCAP_LINUX_LAPD) {
148 /* frame is captured via libpcap */
149 if (pinfo->pseudo_header->lapd.pkttype == 4 /*PACKET_OUTGOING*/) {
150 if (pinfo->pseudo_header->lapd.we_network) {
151 is_response = cr ? FALSE : TRUE;
152 srcname = "Local Network";
153 dstname = "Remote User";
155 srcname = "Local User";
156 dstname = "Remote Network";
159 else if (pinfo->pseudo_header->lapd.pkttype == 3 /*PACKET_OTHERHOST*/) {
160 // We must be a TE, sniffing what other TE transmit
162 is_response = cr ? TRUE : FALSE;
163 srcname = "Remote User";
164 dstname = "Remote Network";
167 // The frame is incoming
168 if (pinfo->pseudo_header->lapd.we_network) {
169 is_response = cr ? TRUE : FALSE;
170 srcname = "Remote User";
171 dstname = "Local Network";
173 is_response = cr ? FALSE : TRUE;
174 srcname = "Remote Network";
175 dstname = "Local User";
179 else if (pinfo->p2p_dir == P2P_DIR_SENT) {
180 is_response = cr ? FALSE : TRUE;
184 else if (pinfo->p2p_dir == P2P_DIR_RECV) {
185 is_response = cr ? TRUE : FALSE;
190 if(check_col(pinfo->cinfo, COL_RES_DL_SRC))
191 col_set_str(pinfo->cinfo, COL_RES_DL_SRC, srcname);
192 if(check_col(pinfo->cinfo, COL_RES_DL_DST))
193 col_set_str(pinfo->cinfo, COL_RES_DL_DST, dstname);
196 lapd_ti = proto_tree_add_item(tree, proto_lapd, tvb, 0, -1,
198 lapd_tree = proto_item_add_subtree(lapd_ti, ett_lapd);
200 addr_ti = proto_tree_add_uint(lapd_tree, hf_lapd_address, tvb,
202 addr_tree = proto_item_add_subtree(addr_ti, ett_lapd_address);
204 proto_tree_add_uint(addr_tree, hf_lapd_sapi,tvb, 0, 1, address);
205 proto_tree_add_uint(addr_tree, hf_lapd_cr, tvb, 0, 1, address);
206 proto_tree_add_uint(addr_tree, hf_lapd_ea1, tvb, 0, 1, address);
207 proto_tree_add_uint(addr_tree, hf_lapd_tei, tvb, 1, 1, address);
208 proto_tree_add_uint(addr_tree, hf_lapd_ea2, tvb, 1, 1, address);
215 control = dissect_xdlc_control(tvb, 2, pinfo, lapd_tree, hf_lapd_control,
216 ett_lapd_control, &lapd_cf_items, &lapd_cf_items_ext, NULL, NULL,
217 is_response, TRUE, FALSE);
218 lapd_header_len += XDLC_CONTROL_LEN(control, TRUE);
221 proto_item_set_len(lapd_ti, lapd_header_len);
223 next_tvb = tvb_new_subset(tvb, lapd_header_len, -1, -1);
224 if (XDLC_IS_INFORMATION(control)) {
225 /* call next protocol */
226 if (!dissector_try_port(lapd_sapi_dissector_table, sapi,
227 next_tvb, pinfo, tree))
228 call_dissector(data_handle,next_tvb, pinfo, tree);
230 call_dissector(data_handle,next_tvb, pinfo, tree);
234 proto_register_lapd(void)
236 static hf_register_info hf[] = {
238 { "Address Field", "lapd.address", FT_UINT16, BASE_HEX, NULL, 0x0,
242 { "SAPI", "lapd.sapi", FT_UINT16, BASE_DEC, VALS(lapd_sapi_vals), LAPD_SAPI,
243 "Service Access Point Identifier", HFILL }},
246 { "C/R", "lapd.cr", FT_UINT16, BASE_DEC, NULL, LAPD_CR,
247 "Command/Response bit", HFILL }},
250 { "EA1", "lapd.ea1", FT_UINT16, BASE_DEC, NULL, LAPD_EA1,
251 "First Address Extension bit", HFILL }},
254 { "TEI", "lapd.tei", FT_UINT16, BASE_DEC, NULL, LAPD_TEI,
255 "Terminal Endpoint Identifier", HFILL }},
258 { "EA2", "lapd.ea2", FT_UINT16, BASE_DEC, NULL, LAPD_EA2,
259 "Second Address Extension bit", HFILL }},
262 { "Control Field", "lapd.control", FT_UINT16, BASE_HEX, NULL, 0x0,
263 "Control field", HFILL }},
266 { "N(R)", "lapd.control.n_r", FT_UINT16, BASE_DEC,
267 NULL, XDLC_N_R_EXT_MASK, "", HFILL }},
270 { "N(S)", "lapd.control.n_s", FT_UINT16, BASE_DEC,
271 NULL, XDLC_N_S_EXT_MASK, "", HFILL }},
274 { "Poll", "lapd.control.p", FT_BOOLEAN, 8,
275 TFS(&flags_set_truth), XDLC_P_F, "", HFILL }},
278 { "Poll", "lapd.control.p", FT_BOOLEAN, 16,
279 TFS(&flags_set_truth), XDLC_P_F_EXT, "", HFILL }},
282 { "Final", "lapd.control.f", FT_BOOLEAN, 8,
283 TFS(&flags_set_truth), XDLC_P_F, "", HFILL }},
286 { "Final", "lapd.control.f", FT_BOOLEAN, 16,
287 TFS(&flags_set_truth), XDLC_P_F_EXT, "", HFILL }},
290 { "Supervisory frame type", "lapd.control.s_ftype", FT_UINT16, BASE_HEX,
291 VALS(stype_vals), XDLC_S_FTYPE_MASK, "", HFILL }},
293 { &hf_lapd_u_modifier_cmd,
294 { "Command", "lapd.control.u_modifier_cmd", FT_UINT8, BASE_HEX,
295 VALS(modifier_vals_cmd), XDLC_U_MODIFIER_MASK, "", HFILL }},
297 { &hf_lapd_u_modifier_resp,
298 { "Response", "lapd.control.u_modifier_resp", FT_UINT8, BASE_HEX,
299 VALS(modifier_vals_resp), XDLC_U_MODIFIER_MASK, "", HFILL }},
302 { "Frame type", "lapd.control.ftype", FT_UINT16, BASE_HEX,
303 VALS(ftype_vals), XDLC_I_MASK, "", HFILL }},
305 { &hf_lapd_ftype_s_u,
306 { "Frame type", "lapd.control.ftype", FT_UINT8, BASE_HEX,
307 VALS(ftype_vals), XDLC_S_U_MASK, "", HFILL }},
309 { &hf_lapd_ftype_s_u_ext,
310 { "Frame type", "lapd.control.ftype", FT_UINT16, BASE_HEX,
311 VALS(ftype_vals), XDLC_S_U_MASK, "", HFILL }},
313 static gint *ett[] = {
319 proto_lapd = proto_register_protocol("Link Access Procedure, Channel D (LAPD)",
321 proto_register_field_array (proto_lapd, hf, array_length(hf));
322 proto_register_subtree_array(ett, array_length(ett));
324 register_dissector("lapd", dissect_lapd, proto_lapd);
326 lapd_sapi_dissector_table = register_dissector_table("lapd.sapi",
327 "LAPD SAPI", FT_UINT16, BASE_DEC);
331 proto_reg_handoff_lapd(void)
333 dissector_handle_t lapd_handle;
335 data_handle = find_dissector("data");
336 tei_handle = find_dissector("tei");
339 lapd_handle = create_dissector_handle(dissect_lapd, proto_lapd);
340 dissector_add("wtap_encap", WTAP_ENCAP_LINUX_LAPD, lapd_handle);