2 * Routines for ISDN packet disassembly
4 * $Id: packet-isdn.c,v 1.5 2003/12/21 12:07:09 jmayer Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #include <epan/packet.h>
32 #include <epan/circuit.h>
34 static int proto_isdn = -1;
35 static int hf_isdn_channel = -1;
37 static gint ett_isdn = -1;
39 static dissector_handle_t lapd_handle;
40 static dissector_handle_t ppp_hdlc_handle;
41 static dissector_handle_t v120_handle;
42 static dissector_handle_t data_handle;
44 static const value_string channel_vals[] = {
80 dissect_isdn(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
82 proto_tree *isdn_tree;
84 static const guint8 v120_sabme[3] = { 0x08, 0x01, 0x7F };
85 static const guint8 ppp[2] = { 0xFF, 0x03 };
88 if (check_col(pinfo->cinfo, COL_PROTOCOL))
89 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ISDN");
91 if (pinfo->pseudo_header->isdn.uton) {
92 if (check_col(pinfo->cinfo, COL_RES_DL_DST))
93 col_set_str(pinfo->cinfo, COL_RES_DL_DST, "Network");
94 if (check_col(pinfo->cinfo, COL_RES_DL_SRC))
95 col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "User");
97 if (check_col(pinfo->cinfo, COL_RES_DL_DST))
98 col_set_str(pinfo->cinfo, COL_RES_DL_DST, "User");
99 if (check_col(pinfo->cinfo, COL_RES_DL_SRC))
100 col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "Network");
103 pinfo->ctype = CT_ISDN;
104 pinfo->circuit_id = pinfo->pseudo_header->isdn.channel;
107 ti = proto_tree_add_item(tree, proto_isdn, tvb, 0, 0, FALSE);
108 isdn_tree = proto_item_add_subtree(ti, ett_isdn);
110 proto_tree_add_uint(isdn_tree, hf_isdn_channel, tvb, 0, 0,
111 pinfo->pseudo_header->isdn.channel);
115 * Set up a circuit for this channel, and assign it a dissector.
117 circuit = find_circuit(pinfo->ctype, pinfo->circuit_id, pinfo->fd->num);
119 circuit = circuit_new(pinfo->ctype, pinfo->circuit_id,
122 if (circuit_get_dissector(circuit) == NULL) {
124 * We don't yet know the type of traffic on the circuit.
126 switch (pinfo->pseudo_header->isdn.channel) {
130 * D-channel. Treat it as LAPD.
132 circuit_set_dissector(circuit, lapd_handle);
139 * We don't know yet whether the datastream is
140 * V.120 or not; this heuristic tries to figure
143 * We cannot glean this from the Q.931 SETUP message,
144 * because no commercial V.120 implementation I've
145 * seen actually sets the V.120 protocol discriminator
146 * (that, or I'm misreading the spec badly).
148 * TODO: close the circuit after a close on the B
149 * channel is detected.
151 * -Bert Driehuis (from the i4btrace reader;
152 * this heuristic was moved from there to
155 * XXX - I don't know that one can guarantee that
156 * the SABME will appear in the first frame on
157 * the channels, so we probably can't just say
158 * "it must be PPP" if we don't immediately see
159 * the V.120 SABME frame, so we do so only if
160 * we see the 0xFF 0x03. Unfortunately, that
161 * won't do the right thing if the PPP-over-HDLC
162 * headers aren't being used....
164 if (tvb_memeql(tvb, 0, v120_sabme, 3) == 0) {
166 * We assume this is V.120.
168 circuit_set_dissector(circuit, v120_handle);
169 } else if (tvb_memeql(tvb, 0, ppp, 2) == 0) {
171 * We assume this is PPP.
173 circuit_set_dissector(circuit, ppp_hdlc_handle);
179 if (!try_circuit_dissector(pinfo->ctype, pinfo->circuit_id,
180 pinfo->fd->num, tvb, pinfo, tree))
181 call_dissector(data_handle, tvb, pinfo, tree);
185 proto_register_isdn(void)
187 static hf_register_info hf[] = {
189 { "Channel", "isdn.channel", FT_UINT8, BASE_DEC,
190 VALS(channel_vals), 0x0, "", HFILL }},
192 static gint *ett[] = {
195 proto_isdn = proto_register_protocol("ISDN", "ISDN", "isdn");
196 proto_register_field_array(proto_isdn, hf, array_length(hf));
197 proto_register_subtree_array(ett, array_length(ett));
201 proto_reg_handoff_isdn(void)
203 dissector_handle_t isdn_handle;
206 * Get handles for the LAPD, PPP, and V.120 dissectors.
208 lapd_handle = find_dissector("lapd");
209 ppp_hdlc_handle = find_dissector("ppp_hdlc");
210 v120_handle = find_dissector("v120");
211 data_handle = find_dissector("data");
213 isdn_handle = create_dissector_handle(dissect_isdn, proto_isdn);
215 dissector_add("wtap_encap", WTAP_ENCAP_ISDN, isdn_handle);