2 * Routines for LAPD frame disassembly
3 * Gilbert Ramirez <gram@alumni.rice.edu>
5 * $Id: packet-lapd.c,v 1.37 2004/01/18 08:32:45 guy Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
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>
36 /* ISDN/LAPD references:
38 * http://www.cisco.com/univercd/cc/td/doc/cisintwk/ito_doc/isdn.htm
39 * http://www.ece.wpi.edu/courses/ee535/hwk11cd95/agrebe/agrebe.html
40 * http://www.acacia-net.com/Clarinet/Protocol/q9213o84.htm
43 static int proto_lapd = -1;
44 static int hf_lapd_address = -1;
45 static int hf_lapd_sapi = -1;
46 static int hf_lapd_cr = -1;
47 static int hf_lapd_ea1 = -1;
48 static int hf_lapd_tei = -1;
49 static int hf_lapd_ea2 = -1;
50 static int hf_lapd_control = -1;
51 static int hf_lapd_n_r = -1;
52 static int hf_lapd_n_s = -1;
53 static int hf_lapd_p = -1;
54 static int hf_lapd_p_ext = -1;
55 static int hf_lapd_f = -1;
56 static int hf_lapd_f_ext = -1;
57 static int hf_lapd_s_ftype = -1;
58 static int hf_lapd_u_modifier_cmd = -1;
59 static int hf_lapd_u_modifier_resp = -1;
60 static int hf_lapd_ftype_i = -1;
61 static int hf_lapd_ftype_s_u = -1;
62 static int hf_lapd_ftype_s_u_ext = -1;
64 static gint ett_lapd = -1;
65 static gint ett_lapd_address = -1;
66 static gint ett_lapd_control = -1;
68 static dissector_handle_t q931_handle;
69 static dissector_handle_t data_handle;
72 * Bits in the address field.
74 #define LAPD_SAPI 0xfc00 /* Service Access Point Identifier */
75 #define LAPD_SAPI_SHIFT 10
76 #define LAPD_CR 0x0200 /* Command/Response bit */
77 #define LAPD_EA1 0x0100 /* First Address Extension bit */
78 #define LAPD_TEI 0x00fe /* Terminal Endpoint Identifier */
79 #define LAPD_EA2 0x0001 /* Second Address Extension bit */
81 #define LAPD_SAPI_Q931 0 /* Q.931 call control procedure */
82 #define LAPD_SAPI_PM_Q931 1 /* Packet mode Q.931 call control procedure */
83 #define LAPD_SAPI_X25 16 /* X.25 Level 3 procedures */
84 #define LAPD_SAPI_L2 63 /* Layer 2 management procedures */
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;
128 gboolean is_response;
131 if (check_col(pinfo->cinfo, COL_PROTOCOL))
132 col_set_str(pinfo->cinfo, COL_PROTOCOL, "LAPD");
133 if (check_col(pinfo->cinfo, COL_INFO))
134 col_clear(pinfo->cinfo, COL_INFO);
136 address = tvb_get_ntohs(tvb, 0);
137 cr = address & LAPD_CR;
138 sapi = (address & LAPD_SAPI) >> LAPD_SAPI_SHIFT;
139 lapd_header_len = 2; /* address */
141 if (pinfo->p2p_dir == P2P_DIR_SENT) {
142 is_response = cr ? TRUE : FALSE;
143 if(check_col(pinfo->cinfo, COL_RES_DL_DST))
144 col_set_str(pinfo->cinfo, COL_RES_DL_DST, "Network");
145 if(check_col(pinfo->cinfo, COL_RES_DL_SRC))
146 col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "User");
149 /* XXX - what if the direction is unknown? */
150 is_response = cr ? FALSE : TRUE;
151 if(check_col(pinfo->cinfo, COL_RES_DL_DST))
152 col_set_str(pinfo->cinfo, COL_RES_DL_DST, "User");
153 if(check_col(pinfo->cinfo, COL_RES_DL_SRC))
154 col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "Network");
158 lapd_ti = proto_tree_add_item(tree, proto_lapd, tvb, 0, -1,
160 lapd_tree = proto_item_add_subtree(lapd_ti, ett_lapd);
162 addr_ti = proto_tree_add_uint(lapd_tree, hf_lapd_address, tvb,
164 addr_tree = proto_item_add_subtree(addr_ti, ett_lapd_address);
166 proto_tree_add_uint(addr_tree, hf_lapd_sapi,tvb, 0, 1, address);
167 proto_tree_add_uint(addr_tree, hf_lapd_cr, tvb, 0, 1, address);
168 proto_tree_add_uint(addr_tree, hf_lapd_ea1, tvb, 0, 1, address);
169 proto_tree_add_uint(addr_tree, hf_lapd_tei, tvb, 1, 1, address);
170 proto_tree_add_uint(addr_tree, hf_lapd_ea2, tvb, 1, 1, address);
177 control = dissect_xdlc_control(tvb, 2, pinfo, lapd_tree, hf_lapd_control,
178 ett_lapd_control, &lapd_cf_items, &lapd_cf_items_ext, NULL, NULL,
179 is_response, TRUE, FALSE);
180 lapd_header_len += XDLC_CONTROL_LEN(control, TRUE);
183 proto_item_set_len(lapd_ti, lapd_header_len);
185 next_tvb = tvb_new_subset(tvb, lapd_header_len, -1, -1);
186 if (XDLC_IS_INFORMATION(control)) {
187 /* call next protocol */
191 call_dissector(q931_handle, next_tvb, pinfo, tree);
196 * XXX - handle some of the others, such as
199 call_dissector(data_handle, next_tvb, pinfo, tree);
203 call_dissector(data_handle,next_tvb, pinfo, tree);
207 proto_register_lapd(void)
209 static hf_register_info hf[] = {
211 { "Address Field", "lapd.address", FT_UINT16, BASE_HEX, NULL, 0x0,
215 { "SAPI", "lapd.sapi", FT_UINT16, BASE_DEC, VALS(lapd_sapi_vals), LAPD_SAPI,
216 "Service Access Point Identifier", HFILL }},
219 { "C/R", "lapd.cr", FT_UINT16, BASE_DEC, NULL, LAPD_CR,
220 "Command/Response bit", HFILL }},
223 { "EA1", "lapd.ea1", FT_UINT16, BASE_DEC, NULL, LAPD_EA1,
224 "First Address Extension bit", HFILL }},
227 { "TEI", "lapd.tei", FT_UINT16, BASE_DEC, NULL, LAPD_TEI,
228 "Terminal Endpoint Identifier", HFILL }},
231 { "EA2", "lapd.ea2", FT_UINT16, BASE_DEC, NULL, LAPD_EA2,
232 "Second Address Extension bit", HFILL }},
235 { "Control Field", "lapd.control", FT_UINT16, BASE_HEX, NULL, 0x0,
236 "Control field", HFILL }},
239 { "N(R)", "lapd.control.n_r", FT_UINT16, BASE_DEC,
240 NULL, XDLC_N_R_EXT_MASK, "", HFILL }},
243 { "N(S)", "lapd.control.n_s", FT_UINT16, BASE_DEC,
244 NULL, XDLC_N_S_EXT_MASK, "", HFILL }},
247 { "Poll", "lapd.control.p", FT_BOOLEAN, 8,
248 TFS(&flags_set_truth), XDLC_P_F, "", HFILL }},
251 { "Poll", "lapd.control.p", FT_BOOLEAN, 16,
252 TFS(&flags_set_truth), XDLC_P_F_EXT, "", HFILL }},
255 { "Final", "lapd.control.f", FT_BOOLEAN, 8,
256 TFS(&flags_set_truth), XDLC_P_F, "", HFILL }},
259 { "Final", "lapd.control.f", FT_BOOLEAN, 16,
260 TFS(&flags_set_truth), XDLC_P_F_EXT, "", HFILL }},
263 { "Supervisory frame type", "lapd.control.s_ftype", FT_UINT16, BASE_HEX,
264 VALS(stype_vals), XDLC_S_FTYPE_MASK, "", HFILL }},
266 { &hf_lapd_u_modifier_cmd,
267 { "Command", "lapd.control.u_modifier_cmd", FT_UINT8, BASE_HEX,
268 VALS(modifier_vals_cmd), XDLC_U_MODIFIER_MASK, "", HFILL }},
270 { &hf_lapd_u_modifier_resp,
271 { "Response", "lapd.control.u_modifier_resp", FT_UINT8, BASE_HEX,
272 VALS(modifier_vals_resp), XDLC_U_MODIFIER_MASK, "", HFILL }},
275 { "Frame type", "lapd.control.ftype", FT_UINT16, BASE_HEX,
276 VALS(ftype_vals), XDLC_I_MASK, "", HFILL }},
278 { &hf_lapd_ftype_s_u,
279 { "Frame type", "lapd.control.ftype", FT_UINT8, BASE_HEX,
280 VALS(ftype_vals), XDLC_S_U_MASK, "", HFILL }},
282 { &hf_lapd_ftype_s_u_ext,
283 { "Frame type", "lapd.control.ftype", FT_UINT16, BASE_HEX,
284 VALS(ftype_vals), XDLC_S_U_MASK, "", HFILL }},
286 static gint *ett[] = {
292 proto_lapd = proto_register_protocol("Link Access Procedure, Channel D (LAPD)",
294 proto_register_field_array (proto_lapd, hf, array_length(hf));
295 proto_register_subtree_array(ett, array_length(ett));
297 register_dissector("lapd", dissect_lapd, proto_lapd);
301 proto_reg_handoff_lapd(void)
304 * Get handle for the Q.931 dissector.
306 q931_handle = find_dissector("q931");
307 data_handle = find_dissector("data");