2 * Routines for LAPD frame disassembly
3 * Gilbert Ramirez <gram@alumni.rice.edu>
5 * $Id: packet-lapd.c,v 1.29 2002/02/22 08:54:54 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.
30 #ifdef HAVE_SYS_TYPES_H
31 # include <sys/types.h>
37 #include <epan/packet.h>
40 /* ISDN/LAPD references:
42 * http://www.cisco.com/univercd/cc/td/doc/cisintwk/ito_doc/isdn.htm
43 * http://www.ece.wpi.edu/courses/ee535/hwk11cd95/agrebe/agrebe.html
44 * http://www.acacia-net.com/Clarinet/Protocol/q9213o84.htm
47 static int proto_lapd = -1;
48 static int hf_lapd_address = -1;
49 static int hf_lapd_sapi = -1;
50 static int hf_lapd_cr = -1;
51 static int hf_lapd_ea1 = -1;
52 static int hf_lapd_tei = -1;
53 static int hf_lapd_ea2 = -1;
54 static int hf_lapd_control = -1;
56 static gint ett_lapd = -1;
57 static gint ett_lapd_address = -1;
58 static gint ett_lapd_control = -1;
60 static dissector_handle_t q931_handle;
61 static dissector_handle_t data_handle;
64 * Bits in the address field.
66 #define LAPD_SAPI 0xfc00 /* Service Access Point Identifier */
67 #define LAPD_SAPI_SHIFT 10
68 #define LAPD_CR 0x0200 /* Command/Response bit */
69 #define LAPD_EA1 0x0100 /* First Address Extension bit */
70 #define LAPD_TEI 0x00fe /* Terminal Endpoint Identifier */
71 #define LAPD_EA2 0x0001 /* Second Address Extension bit */
73 #define LAPD_SAPI_Q931 0 /* Q.931 call control procedure */
74 #define LAPD_SAPI_PM_Q931 1 /* Packet mode Q.931 call control procedure */
75 #define LAPD_SAPI_X25 16 /* X.25 Level 3 procedures */
76 #define LAPD_SAPI_L2 63 /* Layer 2 management procedures */
78 static const value_string lapd_sapi_vals[] = {
79 { LAPD_SAPI_Q931, "Q.931 Call control procedure" },
80 { LAPD_SAPI_PM_Q931, "Packet mode Q.931 Call control procedure" },
81 { LAPD_SAPI_X25, "X.25 Level 3 procedures" },
82 { LAPD_SAPI_L2, "Layer 2 management procedures" },
87 dissect_lapd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
89 proto_tree *lapd_tree, *addr_tree;
90 proto_item *lapd_ti, *addr_ti;
93 guint16 address, cr, sapi;
97 if (check_col(pinfo->cinfo, COL_PROTOCOL))
98 col_set_str(pinfo->cinfo, COL_PROTOCOL, "LAPD");
99 if (check_col(pinfo->cinfo, COL_INFO))
100 col_clear(pinfo->cinfo, COL_INFO);
102 address = tvb_get_ntohs(tvb, 0);
103 cr = address & LAPD_CR;
104 sapi = (address & LAPD_SAPI) >> LAPD_SAPI_SHIFT;
105 lapd_header_len = 2; /* address */
107 if (pinfo->pseudo_header->p2p.sent) {
108 is_response = cr ? TRUE : FALSE;
109 if(check_col(pinfo->cinfo, COL_RES_DL_DST))
110 col_set_str(pinfo->cinfo, COL_RES_DL_DST, "Network");
111 if(check_col(pinfo->cinfo, COL_RES_DL_SRC))
112 col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "User");
115 is_response = cr ? FALSE : TRUE;
116 if(check_col(pinfo->cinfo, COL_RES_DL_DST))
117 col_set_str(pinfo->cinfo, COL_RES_DL_DST, "User");
118 if(check_col(pinfo->cinfo, COL_RES_DL_SRC))
119 col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "Network");
123 lapd_ti = proto_tree_add_item(tree, proto_lapd, tvb, 0, -1,
125 lapd_tree = proto_item_add_subtree(lapd_ti, ett_lapd);
127 addr_ti = proto_tree_add_uint(lapd_tree, hf_lapd_address, tvb,
129 addr_tree = proto_item_add_subtree(addr_ti, ett_lapd_address);
131 proto_tree_add_uint(addr_tree, hf_lapd_sapi,tvb, 0, 1, address);
132 proto_tree_add_uint(addr_tree, hf_lapd_cr, tvb, 0, 1, address);
133 proto_tree_add_uint(addr_tree, hf_lapd_ea1, tvb, 0, 1, address);
134 proto_tree_add_uint(addr_tree, hf_lapd_tei, tvb, 1, 1, address);
135 proto_tree_add_uint(addr_tree, hf_lapd_ea2, tvb, 1, 1, address);
142 control = dissect_xdlc_control(tvb, 2, pinfo, lapd_tree, hf_lapd_control,
143 ett_lapd_control, is_response, TRUE);
144 lapd_header_len += XDLC_CONTROL_LEN(control, TRUE);
147 proto_item_set_len(lapd_ti, lapd_header_len);
149 next_tvb = tvb_new_subset(tvb, lapd_header_len, -1, -1);
150 if (XDLC_IS_INFORMATION(control)) {
151 /* call next protocol */
155 call_dissector(q931_handle, next_tvb, pinfo, tree);
159 call_dissector(data_handle,next_tvb, pinfo, tree);
163 call_dissector(data_handle,next_tvb, pinfo, tree);
167 proto_register_lapd(void)
169 static hf_register_info hf[] = {
171 { "Address Field", "lapd.address", FT_UINT16, BASE_HEX, NULL, 0x0,
175 { "SAPI", "lapd.sapi", FT_UINT16, BASE_DEC, VALS(lapd_sapi_vals), LAPD_SAPI,
176 "Service Access Point Identifier", HFILL }},
179 { "C/R", "lapd.cr", FT_UINT16, BASE_DEC, NULL, LAPD_CR,
180 "Command/Response bit", HFILL }},
183 { "EA1", "lapd.ea1", FT_UINT16, BASE_DEC, NULL, LAPD_EA1,
184 "First Address Extension bit", HFILL }},
187 { "TEI", "lapd.tei", FT_UINT16, BASE_DEC, NULL, LAPD_TEI,
188 "Terminal Endpoint Identifier", HFILL }},
191 { "EA2", "lapd.ea2", FT_UINT16, BASE_DEC, NULL, LAPD_EA2,
192 "Second Address Extension bit", HFILL }},
195 { "Control Field", "lapd.control", FT_UINT16, BASE_HEX, NULL, 0x0,
196 "Control field", HFILL }},
198 static gint *ett[] = {
204 proto_lapd = proto_register_protocol("Link Access Procedure, Channel D (LAPD)",
206 proto_register_field_array (proto_lapd, hf, array_length(hf));
207 proto_register_subtree_array(ett, array_length(ett));
211 proto_reg_handoff_lapd(void)
213 dissector_handle_t lapd_handle;
216 * Get handle for the Q.931 dissector.
218 q931_handle = find_dissector("q931");
219 data_handle = find_dissector("data");
221 lapd_handle = create_dissector_handle(dissect_lapd, proto_lapd);
222 dissector_add("wtap_encap", WTAP_ENCAP_LAPD, lapd_handle);