2 * Routines for packet dissection of ip.access GSM over IP
3 * Copyright 2009 by Harald Welte <laforge@gnumonks.org>
4 * Copyright 2009, 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 #include <epan/packet.h>
34 #include <epan/ipproto.h>
35 #include <epan/prefs.h>
37 #define IPA_TCP_PORTS "3002,3003,3006,5000"
38 #define IPA_UDP_PORTS "3006"
40 static dissector_handle_t ipa_handle;
41 static range_t *global_ipa_tcp_ports = NULL;
42 static range_t *global_ipa_udp_ports = NULL;
43 static gboolean global_ipa_in_root = FALSE;
44 static gboolean global_ipa_in_info = FALSE;
46 /* Initialize the protocol and registered fields */
47 static int proto_ipa = -1;
48 static int proto_ipaccess = -1;
50 static int hf_ipa_data_len = -1;
51 static int hf_ipa_protocol = -1;
52 static int hf_ipa_hsl_debug = -1;
54 static int hf_ipaccess_msgtype = -1;
55 static int hf_ipaccess_attr_tag = -1;
56 static int hf_ipaccess_attr_string = -1;
58 /* Initialize the subtree pointers */
59 static gint ett_ipa = -1;
60 static gint ett_ipaccess = -1;
72 static dissector_handle_t sub_handles[SUB_MAX];
74 #define ABISIP_RSL_MAX 0x20
75 #define HSL_DEBUG 0xdd
78 #define ABISIP_IPACCESS 0xfe
79 #define ABISIP_OML 0xff
81 static const value_string ipa_protocol_vals[] = {
83 { 0xdd, "HSL Debug" },
91 static const value_string ipaccess_msgtype_vals[] = {
94 { 0x04, "IDENTITY REQUEST" },
95 { 0x05, "IDENTITY RESPONSE" },
96 { 0x06, "IDENTITY ACK" },
97 { 0x07, "IDENTITY NACK" },
98 { 0x08, "PROXY REQUEST" },
99 { 0x09, "PROXY ACK" },
100 { 0x0a, "PROXY NACK" },
104 static const value_string ipaccess_idtag_vals[] = {
105 { 0x00, "Serial Number" },
106 { 0x01, "Unit Name" },
107 { 0x02, "Location" },
108 { 0x03, "Unit Type" },
109 { 0x04, "Equipment Version" },
110 { 0x05, "Software Version" },
111 { 0x06, "IP Address" },
112 { 0x07, "MAC Address" },
118 dissect_ipa_attr(tvbuff_t *tvb, int base_offs, proto_tree *tree)
120 guint8 len, attr_type;
122 int offset = base_offs;
124 while (tvb_reported_length_remaining(tvb, offset) > 0) {
125 attr_type = tvb_get_guint8(tvb, offset);
128 case 0x00: /* a string prefixed by its length */
129 len = tvb_get_guint8(tvb, offset+1);
130 proto_tree_add_item(tree, hf_ipaccess_attr_tag,
131 tvb, offset+2, 1, FALSE);
132 proto_tree_add_item(tree, hf_ipaccess_attr_string,
133 tvb, offset+3, len-1, FALSE);
135 case 0x01: /* a single-byte reqest for a certain attr */
137 proto_tree_add_item(tree, hf_ipaccess_attr_tag,
138 tvb, offset+1, 1, FALSE);
142 proto_tree_add_text(tree, tvb, offset+1, 1,
143 "unknown attribute type 0x%02x",
152 /* Dissect an ip.access specific message */
154 dissect_ipaccess(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
157 proto_tree *ipaccess_tree;
160 msg_type = tvb_get_guint8(tvb, 0);
162 col_append_fstr(pinfo->cinfo, COL_INFO, "%s ",
163 val_to_str(msg_type, ipaccess_msgtype_vals,
166 ti = proto_tree_add_item(tree, proto_ipaccess, tvb, 0, -1, FALSE);
167 ipaccess_tree = proto_item_add_subtree(ti, ett_ipaccess);
168 proto_tree_add_item(ipaccess_tree, hf_ipaccess_msgtype,
173 dissect_ipa_attr(tvb, 1, ipaccess_tree);
182 /* Code to actually dissect the packets */
184 dissect_ipa(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
187 gint header_length = 3;
190 col_set_str(pinfo->cinfo, COL_PROTOCOL, "IPA");
191 col_clear(pinfo->cinfo, COL_INFO);
193 while ((remaining = tvb_reported_length_remaining(tvb, offset)) > 0) {
195 proto_tree *ipa_tree = NULL;
196 guint16 len, msg_type;
199 len = tvb_get_ntohs(tvb, offset);
200 msg_type = tvb_get_guint8(tvb, offset+2);
202 col_append_fstr(pinfo->cinfo, COL_INFO, "%s ",
203 val_to_str(msg_type, ipa_protocol_vals,
207 * The IPA header is different depending on the transport protocol.
208 * With UDP there seems to be a fourth byte for the IPA header.
209 * We attempt to detect this by checking if the length from the
210 * header + four bytes of the IPA header equals the remaining size.
212 if ((pinfo->ipproto == IP_PROTO_UDP) && (len + 4 == remaining)) {
217 ti = proto_tree_add_protocol_format(tree, proto_ipa,
218 tvb, offset, len+header_length,
219 "IPA protocol ip.access, type: %s",
220 val_to_str(msg_type, ipa_protocol_vals,
222 ipa_tree = proto_item_add_subtree(ti, ett_ipa);
223 proto_tree_add_item(ipa_tree, hf_ipa_data_len,
224 tvb, offset, 2, FALSE);
225 proto_tree_add_item(ipa_tree, hf_ipa_protocol,
226 tvb, offset+2, 1, FALSE);
229 next_tvb = tvb_new_subset(tvb, offset+header_length, len, len);
233 /* hand this off to the standard A-bis OML dissector */
234 if (sub_handles[SUB_OML])
235 call_dissector(sub_handles[SUB_OML], next_tvb,
238 case ABISIP_IPACCESS:
239 dissect_ipaccess(next_tvb, pinfo, tree);
242 /* hand this off to the standard SCCP dissector */
243 call_dissector(sub_handles[SUB_SCCP], next_tvb, pinfo, tree);
246 /* hand this off to the standard MGCP dissector */
247 call_dissector(sub_handles[SUB_MGCP], next_tvb, pinfo, tree);
251 proto_tree_add_item(ipa_tree, hf_ipa_hsl_debug,
252 next_tvb, 0, len, FALSE);
253 if (global_ipa_in_root == TRUE)
254 proto_tree_add_item(tree, hf_ipa_hsl_debug,
255 next_tvb, 0, len, FALSE);
257 if (global_ipa_in_info == TRUE)
258 col_append_fstr(pinfo->cinfo, COL_INFO, "%s ",
259 tvb_get_stringz(next_tvb, 0, NULL));
262 if (msg_type < ABISIP_RSL_MAX) {
263 /* hand this off to the standard A-bis RSL dissector */
264 call_dissector(sub_handles[SUB_RSL], next_tvb, pinfo, tree);
268 offset += len + header_length;
272 void proto_reg_handoff_gsm_ipa(void);
274 void proto_register_ipa(void)
276 module_t *ipa_module;
278 static hf_register_info hf[] = {
280 {"DataLen", "ipa.data_len",
281 FT_UINT16, BASE_DEC, NULL, 0x0,
282 "The length of the data (in bytes)", HFILL}
285 {"Protocol", "ipa.protocol",
286 FT_UINT8, BASE_HEX, VALS(ipa_protocol_vals), 0x0,
287 "The IPA Sub-Protocol", HFILL}
290 {"Debug Message", "ipa.hsl_debug",
291 FT_STRING, BASE_NONE, NULL, 0,
292 "Hay Systems Limited debug message", HFILL}
295 static hf_register_info hf_ipa[] = {
296 {&hf_ipaccess_msgtype,
297 {"MessageType", "ipaccess.msg_type",
298 FT_UINT8, BASE_HEX, VALS(ipaccess_msgtype_vals), 0x0,
299 "Type of ip.access messsage", HFILL}
301 {&hf_ipaccess_attr_tag,
302 {"Tag", "ipaccess.attr_tag",
303 FT_UINT8, BASE_HEX, VALS(ipaccess_idtag_vals), 0x0,
304 "Attribute Tag", HFILL}
306 {&hf_ipaccess_attr_string,
307 {"String", "ipaccess.attr_string",
308 FT_STRING, BASE_NONE, NULL, 0x0,
309 "String attribute", HFILL}
313 static gint *ett[] = {
319 proto_register_protocol("GSM over IP protocol as used by ip.access",
320 "GSM over IP", "gsm_ipa");
322 proto_register_protocol("GSM over IP ip.access CCM sub-protocol",
325 proto_register_field_array(proto_ipa, hf, array_length(hf));
326 proto_register_field_array(proto_ipaccess, hf_ipa, array_length(hf_ipa));
327 proto_register_subtree_array(ett, array_length(ett));
329 register_dissector("gsm_ipa", dissect_ipa, proto_ipa);
331 range_convert_str(&global_ipa_tcp_ports, IPA_TCP_PORTS, MAX_TCP_PORT);
332 range_convert_str(&global_ipa_udp_ports, IPA_UDP_PORTS, MAX_UDP_PORT);
333 ipa_module = prefs_register_protocol(proto_ipa,
334 proto_reg_handoff_gsm_ipa);
336 prefs_register_range_preference(ipa_module, "tcp_ports",
337 "GSM IPA TCP Port(s)",
338 "Set the port(s) for ip.access IPA"
339 " (default: " IPA_TCP_PORTS ")",
340 &global_ipa_tcp_ports, MAX_TCP_PORT);
341 prefs_register_range_preference(ipa_module, "udp_ports",
342 "GSM IPA UDP Port(s)",
343 "Set the port(s) for ip.access IPA"
344 " (default: " IPA_UDP_PORTS ")",
345 &global_ipa_udp_ports, MAX_UDP_PORT);
347 prefs_register_bool_preference(ipa_module, "hsl_debug_in_root_tree",
348 "HSL Debug messages in root protocol tree",
349 NULL, &global_ipa_in_root);
350 prefs_register_bool_preference(ipa_module, "hsl_debug_in_info",
351 "HSL Debug messages in INFO column",
352 NULL, &global_ipa_in_info);
355 static void ipa_tcp_delete_callback(guint32 port)
358 dissector_delete_uint("tcp.port", port, ipa_handle);
361 static void ipa_udp_delete_callback(guint32 port)
364 dissector_delete_uint("udp.port", port, ipa_handle);
367 static void ipa_tcp_add_callback(guint32 port)
370 dissector_add_uint("tcp.port", port, ipa_handle);
373 static void ipa_udp_add_callback(guint32 port)
376 dissector_add_uint("udp.port", port, ipa_handle);
379 void proto_reg_handoff_gsm_ipa(void)
381 static gboolean ipa_initialized = FALSE;
382 static range_t *ipa_tcp_ports, *ipa_udp_ports;
384 if (!ipa_initialized) {
385 sub_handles[SUB_RSL] = find_dissector("gsm_abis_rsl");
386 sub_handles[SUB_OML] = find_dissector("gsm_abis_oml");
387 sub_handles[SUB_SCCP] = find_dissector("sccp");
388 sub_handles[SUB_MGCP] = find_dissector("mgcp");
390 ipa_handle = create_dissector_handle(dissect_ipa, proto_ipa);
391 ipa_initialized = TRUE;
393 range_foreach(ipa_tcp_ports, ipa_tcp_delete_callback);
394 g_free(ipa_tcp_ports);
395 range_foreach(ipa_udp_ports, ipa_udp_delete_callback);
396 g_free(ipa_udp_ports);
399 ipa_tcp_ports = range_copy(global_ipa_tcp_ports);
400 ipa_udp_ports = range_copy(global_ipa_udp_ports);
402 range_foreach(ipa_tcp_ports, ipa_tcp_add_callback);
403 range_foreach(ipa_udp_ports, ipa_udp_add_callback);