HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / dissectors / packet-v5ef.c
blobbd130787b5ffbd4b708a44311d2edc92879adf0b
1 /* packet-v5ef.c
2 * Routines for V5 envelope function frame disassembly
3 * Rolf Fiedler <rolf.fiedler@innoventif.de>
5 * $Id$
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * V5 bitstream over HDLC handling
28 * V5 references:
30 * ETS 300 324-1
31 * ETS 300 347-1
34 #include "config.h"
36 #include <glib.h>
38 #include <epan/packet.h>
39 #include <epan/conversation.h>
40 #include <epan/xdlc.h>
41 #include <epan/crc16-tvb.h>
43 static int proto_v5ef = -1;
44 static int hf_v5ef_direction = -1;
45 static int hf_v5ef_address = -1;
46 static int hf_v5ef_eah = -1;
47 static int hf_v5ef_ea1 = -1;
48 static int hf_v5ef_eal = -1;
49 static int hf_v5ef_ea2 = -1;
51 static gint ett_v5ef = -1;
52 static gint ett_v5ef_address = -1;
54 static dissector_handle_t v5dl_handle, lapd_handle;
57 * Bits in the address field.
59 #define V5EF_EAH 0xfc00 /* Service Access Point Identifier */
60 #define V5EF_EAH_SHIFT 10
61 #define V5EF_EA1 0x0100 /* First Address Extension bit */
62 #define V5EF_EAL 0x00fe /* Terminal Endpoint Identifier */
63 #define V5EF_EAL_SHIFT 1
64 #define V5EF_EA2 0x0001 /* Second Address Extension bit */
66 static const value_string v5ef_direction_vals[] = {
67 { 0, "AN->LE"},
68 { 1, "LE->AN"},
69 { 0, NULL }
72 #define MAX_V5EF_PACKET_LEN 1024
74 static void
75 dissect_v5ef(tvbuff_t*, packet_info*, proto_tree*);
77 static void
78 dissect_v5ef(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
80 proto_tree *v5ef_tree, *addr_tree;
81 proto_item *v5ef_ti, *addr_ti;
82 int direction;
83 int v5ef_header_len;
84 guint16 addr, eah, eal, efaddr;
85 tvbuff_t *next_tvb;
86 const char *srcname = "src";
87 const char *dstname = "dst";
89 col_set_str(pinfo->cinfo, COL_PROTOCOL, "V5-EF");
90 col_clear(pinfo->cinfo, COL_INFO);
92 addr = tvb_get_ntohs(tvb, 0);
93 eah = (addr & V5EF_EAH) >> V5EF_EAH_SHIFT;
94 eal = (addr & V5EF_EAL) >> V5EF_EAL_SHIFT;
95 efaddr = (eah << 7) + eal;
96 v5ef_header_len = 2; /* addr */
98 direction = pinfo->pseudo_header->isdn.uton;
99 if (direction==0) {
100 srcname = "LE";
101 dstname = "AN";
102 } else if (direction > 0) {
103 srcname = "AN";
104 dstname = "LE";
106 col_set_str(pinfo->cinfo, COL_RES_DL_SRC, srcname);
107 col_set_str(pinfo->cinfo, COL_RES_DL_DST, dstname);
109 if (tree) {
110 proto_item *direction_ti;
112 v5ef_ti = proto_tree_add_item(tree, proto_v5ef, tvb, 0, -1,
113 ENC_NA);
114 v5ef_tree = proto_item_add_subtree(v5ef_ti, ett_v5ef);
117 * Don't show the direction if we don't know it.
119 if (direction != P2P_DIR_UNKNOWN) {
120 direction_ti = proto_tree_add_uint(v5ef_tree, hf_v5ef_direction,
121 tvb, 0, 0, direction);
122 PROTO_ITEM_SET_GENERATED(direction_ti);
125 addr_ti = proto_tree_add_uint(v5ef_tree, hf_v5ef_address, tvb,
126 0, 2, addr);
127 addr_tree = proto_item_add_subtree(addr_ti, ett_v5ef_address);
129 proto_tree_add_uint(addr_tree, hf_v5ef_eah, tvb, 0, 1, addr);
130 proto_tree_add_uint(addr_tree, hf_v5ef_ea1, tvb, 0, 1, addr);
131 proto_tree_add_uint(addr_tree, hf_v5ef_eal, tvb, 1, 1, addr);
132 proto_tree_add_uint(addr_tree, hf_v5ef_ea2, tvb, 1, 1, addr);
134 else {
135 v5ef_ti = NULL;
136 v5ef_tree = NULL;
139 if (tree)
140 proto_item_set_len(v5ef_ti, v5ef_header_len);
142 next_tvb = tvb_new_subset_remaining(tvb, v5ef_header_len);
144 if (efaddr>8175)
145 call_dissector(v5dl_handle,next_tvb, pinfo, tree);
146 else
147 call_dissector(lapd_handle,next_tvb, pinfo, tree);
150 void
151 proto_reg_handoff_v5ef(void);
153 void
154 proto_register_v5ef(void)
156 static hf_register_info hf[] = {
158 { &hf_v5ef_direction,
159 { "Direction", "v5ef.direction", FT_UINT8, BASE_DEC, VALS(v5ef_direction_vals), 0x0,
160 NULL, HFILL }},
162 { &hf_v5ef_address,
163 { "Address Field", "v5ef.address", FT_UINT16, BASE_HEX, NULL, 0x0,
164 "Address", HFILL }},
166 { &hf_v5ef_eah,
167 { "EAH", "v5ef.eah", FT_UINT16, BASE_DEC, NULL, V5EF_EAH,
168 "Envelope Address High Part", HFILL }},
170 { &hf_v5ef_ea1,
171 { "EA1", "v5ef.ea1", FT_UINT16, BASE_DEC, NULL, V5EF_EA1,
172 "First Address Extension bit", HFILL }},
174 { &hf_v5ef_eal,
175 { "EAL", "v5ef.eal", FT_UINT16, BASE_DEC, NULL, V5EF_EAL,
176 "Envelope Address Low Part", HFILL }},
178 { &hf_v5ef_ea2,
179 { "EA2", "v5ef.ea2", FT_UINT16, BASE_DEC, NULL, V5EF_EA2,
180 "Second Address Extension bit", HFILL }},
183 static gint *ett[] = {
184 &ett_v5ef,
185 &ett_v5ef_address,
188 proto_v5ef = proto_register_protocol("V5 Envelope Function (v5ef)",
189 "v5ef", "v5ef");
190 proto_register_field_array (proto_v5ef, hf, array_length(hf));
191 proto_register_subtree_array(ett, array_length(ett));
193 register_dissector("v5ef", dissect_v5ef, proto_v5ef);
197 void
198 proto_reg_handoff_v5ef(void)
200 dissector_handle_t v5ef_handle;
202 v5ef_handle = find_dissector("v5ef");
203 dissector_add_uint("wtap_encap", WTAP_ENCAP_V5_EF, v5ef_handle);
205 lapd_handle = find_dissector("lapd");
206 v5dl_handle = find_dissector("v5dl");