2 * Routines for LAPD frame disassembly
3 * Gilbert Ramirez <gram@alumni.rice.edu>
5 * $Id: packet-lapd.c,v 1.34 2003/01/07 01:08:27 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;
52 static gint ett_lapd = -1;
53 static gint ett_lapd_address = -1;
54 static gint ett_lapd_control = -1;
56 static dissector_handle_t q931_handle;
57 static dissector_handle_t data_handle;
60 * Bits in the address field.
62 #define LAPD_SAPI 0xfc00 /* Service Access Point Identifier */
63 #define LAPD_SAPI_SHIFT 10
64 #define LAPD_CR 0x0200 /* Command/Response bit */
65 #define LAPD_EA1 0x0100 /* First Address Extension bit */
66 #define LAPD_TEI 0x00fe /* Terminal Endpoint Identifier */
67 #define LAPD_EA2 0x0001 /* Second Address Extension bit */
69 #define LAPD_SAPI_Q931 0 /* Q.931 call control procedure */
70 #define LAPD_SAPI_PM_Q931 1 /* Packet mode Q.931 call control procedure */
71 #define LAPD_SAPI_X25 16 /* X.25 Level 3 procedures */
72 #define LAPD_SAPI_L2 63 /* Layer 2 management procedures */
74 static const value_string lapd_sapi_vals[] = {
75 { LAPD_SAPI_Q931, "Q.931 Call control procedure" },
76 { LAPD_SAPI_PM_Q931, "Packet mode Q.931 Call control procedure" },
77 { LAPD_SAPI_X25, "X.25 Level 3 procedures" },
78 { LAPD_SAPI_L2, "Layer 2 management procedures" },
83 dissect_lapd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
85 proto_tree *lapd_tree, *addr_tree;
86 proto_item *lapd_ti, *addr_ti;
89 guint16 address, cr, sapi;
93 if (check_col(pinfo->cinfo, COL_PROTOCOL))
94 col_set_str(pinfo->cinfo, COL_PROTOCOL, "LAPD");
95 if (check_col(pinfo->cinfo, COL_INFO))
96 col_clear(pinfo->cinfo, COL_INFO);
98 address = tvb_get_ntohs(tvb, 0);
99 cr = address & LAPD_CR;
100 sapi = (address & LAPD_SAPI) >> LAPD_SAPI_SHIFT;
101 lapd_header_len = 2; /* address */
103 if (pinfo->p2p_dir == P2P_DIR_SENT) {
104 is_response = cr ? TRUE : FALSE;
105 if(check_col(pinfo->cinfo, COL_RES_DL_DST))
106 col_set_str(pinfo->cinfo, COL_RES_DL_DST, "Network");
107 if(check_col(pinfo->cinfo, COL_RES_DL_SRC))
108 col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "User");
111 /* XXX - what if the direction is unknown? */
112 is_response = cr ? FALSE : TRUE;
113 if(check_col(pinfo->cinfo, COL_RES_DL_DST))
114 col_set_str(pinfo->cinfo, COL_RES_DL_DST, "User");
115 if(check_col(pinfo->cinfo, COL_RES_DL_SRC))
116 col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "Network");
120 lapd_ti = proto_tree_add_item(tree, proto_lapd, tvb, 0, -1,
122 lapd_tree = proto_item_add_subtree(lapd_ti, ett_lapd);
124 addr_ti = proto_tree_add_uint(lapd_tree, hf_lapd_address, tvb,
126 addr_tree = proto_item_add_subtree(addr_ti, ett_lapd_address);
128 proto_tree_add_uint(addr_tree, hf_lapd_sapi,tvb, 0, 1, address);
129 proto_tree_add_uint(addr_tree, hf_lapd_cr, tvb, 0, 1, address);
130 proto_tree_add_uint(addr_tree, hf_lapd_ea1, tvb, 0, 1, address);
131 proto_tree_add_uint(addr_tree, hf_lapd_tei, tvb, 1, 1, address);
132 proto_tree_add_uint(addr_tree, hf_lapd_ea2, tvb, 1, 1, address);
139 control = dissect_xdlc_control(tvb, 2, pinfo, lapd_tree, hf_lapd_control,
140 ett_lapd_control, is_response, TRUE);
141 lapd_header_len += XDLC_CONTROL_LEN(control, TRUE);
144 proto_item_set_len(lapd_ti, lapd_header_len);
146 next_tvb = tvb_new_subset(tvb, lapd_header_len, -1, -1);
147 if (XDLC_IS_INFORMATION(control)) {
148 /* call next protocol */
152 call_dissector(q931_handle, next_tvb, pinfo, tree);
157 * XXX - handle some of the others, such as
160 call_dissector(data_handle, next_tvb, pinfo, tree);
164 call_dissector(data_handle,next_tvb, pinfo, tree);
168 proto_register_lapd(void)
170 static hf_register_info hf[] = {
172 { "Address Field", "lapd.address", FT_UINT16, BASE_HEX, NULL, 0x0,
176 { "SAPI", "lapd.sapi", FT_UINT16, BASE_DEC, VALS(lapd_sapi_vals), LAPD_SAPI,
177 "Service Access Point Identifier", HFILL }},
180 { "C/R", "lapd.cr", FT_UINT16, BASE_DEC, NULL, LAPD_CR,
181 "Command/Response bit", HFILL }},
184 { "EA1", "lapd.ea1", FT_UINT16, BASE_DEC, NULL, LAPD_EA1,
185 "First Address Extension bit", HFILL }},
188 { "TEI", "lapd.tei", FT_UINT16, BASE_DEC, NULL, LAPD_TEI,
189 "Terminal Endpoint Identifier", HFILL }},
192 { "EA2", "lapd.ea2", FT_UINT16, BASE_DEC, NULL, LAPD_EA2,
193 "Second Address Extension bit", HFILL }},
196 { "Control Field", "lapd.control", FT_UINT16, BASE_HEX, NULL, 0x0,
197 "Control field", HFILL }},
199 static gint *ett[] = {
205 proto_lapd = proto_register_protocol("Link Access Procedure, Channel D (LAPD)",
207 proto_register_field_array (proto_lapd, hf, array_length(hf));
208 proto_register_subtree_array(ett, array_length(ett));
210 register_dissector("lapd", dissect_lapd, proto_lapd);
214 proto_reg_handoff_lapd(void)
217 * Get handle for the Q.931 dissector.
219 q931_handle = find_dissector("q931");
220 data_handle = find_dissector("data");