2 * Routines for IP Device Control (SS7 over IP) dissection
3 * Copyright Lucent Technologies 2004
4 * Josh Bailey <joshbailey@lucent.com> and Ruud Linders <ruud@lucent.com>
6 * Using IPDC spec 0.20.2
10 * Ethereal - Network traffic analyzer
11 * By Gerald Combs <gerald@ethereal.com>
12 * Copyright 1998 Gerald Combs
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
40 #ifdef NEED_SNPRINTF_H
41 # include "snprintf.h"
44 #include <epan/packet.h>
45 #include "packet-ipdc.h"
46 #include "packet-tcp.h"
47 #include <epan/packet.h>
48 #include <epan/ipproto.h>
49 #include <epan/prefs.h>
51 static int proto_ipdc = -1;
52 static int hf_ipdc_nr = -1;
53 static int hf_ipdc_ns = -1;
54 static int hf_ipdc_payload_len = -1;
55 static int hf_ipdc_protocol_id = -1;
56 static int hf_ipdc_trans_id_size = -1;
57 static int hf_ipdc_trans_id = -1;
58 static int hf_ipdc_message_code = -1;
60 static gint ett_ipdc = -1;
61 static gint ett_ipdc_tag = -1;
63 static gboolean ipdc_desegment = TRUE;
64 static gint ipdc_port_pref = TCP_PORT_IPDC;
65 static gboolean new_packet = FALSE;
67 static dissector_handle_t q931_handle;
69 void proto_reg_handoff_ipdc(void);
73 get_ipdc_pdu_len(tvbuff_t *tvb, int offset)
75 return tvb_get_ntohs(tvb,offset+2)+4;
79 dissect_ipdc_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
82 proto_tree *ipdc_tree;
90 char tmp_tag_text[IPDC_STR_LEN + 1];
91 const value_string *val_ptr;
99 gshort nr = tvb_get_guint8(tvb,0);
100 gshort ns = tvb_get_guint8(tvb,1);
101 guint16 payload_len = (guint16) get_ipdc_pdu_len(tvb,0);
104 gshort trans_id_size;
106 guint16 message_code;
109 /* display IPDC protocol ID */
110 if (check_col(pinfo->cinfo, COL_PROTOCOL))
111 col_set_str(pinfo->cinfo, COL_PROTOCOL, "IPDC");
117 /* clear info column and display send/receive sequence numbers */
118 if (check_col(pinfo->cinfo, COL_INFO)) {
119 if (new_packet == TRUE) {
120 col_clear(pinfo->cinfo, COL_INFO);
123 col_append_fstr(pinfo->cinfo, COL_INFO, "r=%u s=%u ",
127 if (payload_len == 4) {
131 ti = proto_tree_add_item(tree, proto_ipdc, tvb, 0, -1, FALSE);
132 ipdc_tree = proto_item_add_subtree(ti, ett_ipdc);
133 proto_tree_add_item(ipdc_tree, hf_ipdc_nr, tvb, 0, 1, nr);
134 proto_tree_add_item(ipdc_tree, hf_ipdc_ns, tvb, 1, 1, ns);
135 proto_tree_add_uint(ipdc_tree, hf_ipdc_payload_len, tvb, 2, 2,
141 /* IPDC tags present - display message code and trans. ID */
142 protocol_id = tvb_get_guint8(tvb,4);
143 trans_id_size = TRANS_ID_SIZE_IPDC;
144 trans_id = tvb_get_ntohl(tvb,6);
145 message_code = tvb_get_ntohs(tvb,6+trans_id_size);
146 offset = 6 + trans_id_size + 2; /* past message_code */
148 if (check_col(pinfo->cinfo, COL_INFO))
149 col_append_fstr(pinfo->cinfo, COL_INFO,
152 val_to_str(message_code, message_code_vals,
158 ti = proto_tree_add_item(tree, proto_ipdc, tvb, 0, -1, FALSE);
159 ipdc_tree = proto_item_add_subtree(ti, ett_ipdc);
161 proto_tree_add_item(ipdc_tree, hf_ipdc_nr, tvb, 0, 1, nr);
162 proto_tree_add_item(ipdc_tree, hf_ipdc_ns, tvb, 1, 1, ns);
163 proto_tree_add_uint(ipdc_tree, hf_ipdc_payload_len, tvb,
166 proto_tree_add_item(ipdc_tree, hf_ipdc_protocol_id, tvb,
168 proto_tree_add_item(ipdc_tree, hf_ipdc_trans_id_size, tvb,
169 5, 1, trans_id_size);
170 proto_tree_add_item(ipdc_tree, hf_ipdc_trans_id, tvb,
171 6, trans_id_size, trans_id);
172 proto_tree_add_item(ipdc_tree, hf_ipdc_message_code, tvb,
173 6 + trans_id_size + 1, 1, message_code);
175 ipdc_tag = proto_tree_add_text(ipdc_tree, tvb, offset,
176 payload_len - offset, "IPDC tags");
177 tag_tree = proto_item_add_subtree(ipdc_tag, ett_ipdc_tag);
179 /* iterate through tags. first byte is tag, second is length,
180 in bytes, following is tag data. tag of 0x0 should be
183 tag = tvb_get_guint8(tvb, offset);
186 if (offset == payload_len - 1) {
187 proto_tree_add_text(tag_tree, tvb,
188 offset, 1, "end of tags");
190 proto_tree_add_text(tag_tree, tvb,
191 offset, 1, "data trailing end of tags");
197 len = tvb_get_guint8(tvb,offset+1);
198 des = val_to_str(tag, tag_description, TEXT_UNDEFINED);
199 /* lookup tag type */
200 for (i = 0; (ipdc_tag_types[i].tag != tag &&
201 ipdc_tag_types[i].type != IPDC_UNKNOWN); i++)
203 type = ipdc_tag_types[i].type;
208 /* simple IPDC_ASCII strings */
210 tmp_str = tvb_memdup(tvb, offset + 2, len);
211 strncpy(tmp_tag_text, tmp_str, len);
212 tmp_tag_text[len] = 0;
214 proto_tree_add_text(tag_tree, tvb, offset,
215 len + 2, "0x%2.2x: %s: %s", tag, des,
219 /* unsigned integers, or bytes */
222 for (i = 0; i < len; i++)
223 tmp_tag += tvb_get_guint8(tvb,
224 offset + 2 + i) * (guint32)
225 pow(256, len - (i + 1));
229 val_to_str(IPDC_TAG(tag) +
231 tag_enum_type, TEXT_UNDEFINED);
234 strcmp(enum_val, TEXT_UNDEFINED) != 0) {
235 proto_tree_add_text(tag_tree, tvb,
240 proto_tree_add_text(tag_tree, tvb,
251 g_snprintf(tmp_tag_text,
254 tvb_get_guint8(tvb, offset + 2),
255 tvb_get_guint8(tvb, offset + 3),
256 tvb_get_guint8(tvb, offset + 4),
257 tvb_get_guint8(tvb, offset + 5)
262 g_snprintf(tmp_tag_text,
265 tvb_get_guint8(tvb, offset + 2),
266 tvb_get_guint8(tvb, offset + 3),
267 tvb_get_guint8(tvb, offset + 4),
268 tvb_get_guint8(tvb, offset + 5),
269 tvb_get_ntohs(tvb, offset + 6));
273 g_snprintf(tmp_tag_text,
275 "Invalid IP address length %u",
279 proto_tree_add_text(tag_tree, tvb,
282 tag, des, tmp_tag_text);
285 /* Line status arrays */
286 case IPDC_LINESTATUS:
287 case IPDC_CHANNELSTATUS:
288 proto_tree_add_text(tag_tree, tvb, offset,
289 len + 2, "0x%2.2x: %s", tag, des);
290 val_ptr = (type == IPDC_LINESTATUS) ?
291 line_status_vals : channel_status_vals;
293 for (i = 0; i < len; i++) {
294 status = tvb_get_guint8(tvb,offset+2+i);
296 proto_tree_add_text(tag_tree, tvb,
308 tvb_new_subset(tvb, offset+2, len, len);
309 call_dissector(q931_handle,q931_tvb,pinfo,tree);
313 proto_tree_add_text(tag_tree, tvb,
316 tag, des, val_to_str(
317 tvb_get_guint8(tvb,offset+2),
322 proto_tree_add_text(tag_tree, tvb,
326 tvb_get_guint8(tvb,offset+3));
332 proto_tree_add_text(tag_tree, tvb, offset,
333 len + 2, "0x%2.2x: %s", tag, des);
341 dissect_ipdc_tcp_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
343 dissect_ipdc_common(tvb, pinfo, tree);
347 dissect_ipdc_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
350 tcp_dissect_pdus(tvb, pinfo, tree, ipdc_desegment, 4,
351 get_ipdc_pdu_len, dissect_ipdc_tcp_pdu);
355 proto_register_ipdc(void)
358 static hf_register_info hf[] = {
361 FT_UINT8, BASE_DEC, NULL, 0x0,
362 "Receive sequence number", HFILL }
367 FT_UINT8, BASE_DEC, NULL, 0x0,
368 "Transmit sequence number", HFILL }
371 { &hf_ipdc_payload_len,
372 { "Payload length", "ipdc.length",
373 FT_UINT16, BASE_DEC, NULL, 0x0,
374 "Payload length", HFILL }
377 { &hf_ipdc_protocol_id,
378 { "Protocol ID", "ipdc.protocol_id",
379 FT_UINT8, BASE_HEX, NULL, 0x0,
380 "Protocol ID", HFILL }
383 { &hf_ipdc_trans_id_size,
384 { "Transaction ID size", "ipdc.trans_id_size",
385 FT_UINT8, BASE_DEC, NULL, 0x0,
386 "Transaction ID size", HFILL }
390 { "Transaction ID", "ipdc.trans_id",
391 FT_BYTES, BASE_HEX, NULL, 0x0,
392 "Transaction ID", HFILL }
395 { &hf_ipdc_message_code,
396 { "Message code", "ipdc.message_code",
397 FT_UINT16, BASE_HEX, VALS(message_code_vals), 0x0,
398 "Message Code", HFILL }
402 static gint *ett[] = {
407 module_t *ipdc_module;
409 proto_ipdc = proto_register_protocol("IP Device Control (SS7 over IP)",
411 proto_register_field_array(proto_ipdc, hf, array_length(hf));
412 proto_register_subtree_array(ett, array_length(ett));
414 ipdc_module = prefs_register_protocol(proto_ipdc, proto_reg_handoff_ipdc);
415 prefs_register_bool_preference(ipdc_module, "desegment_ipdc_messages",
416 "Reassemble IPDC messages spanning multiple TCP segments",
417 "Whether the IPDC dissector should reassemble messages spanning multiple TCP segments."
418 " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
420 prefs_register_uint_preference(ipdc_module, "tcp.port",
421 "IPDC monitoring port",
422 "Set the IPDC monitoring port", 10,
427 proto_reg_handoff_ipdc(void)
429 static gint last_ipdc_port_pref = 0;
430 static dissector_handle_t ipdc_tcp_handle = NULL;
432 if (ipdc_tcp_handle) {
433 dissector_delete("tcp.port", last_ipdc_port_pref,
437 create_dissector_handle(dissect_ipdc_tcp, proto_ipdc);
438 q931_handle = find_dissector("q931");
441 last_ipdc_port_pref = ipdc_port_pref;
442 dissector_add("tcp.port", ipdc_port_pref, ipdc_tcp_handle);