aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-isup_thin.c
blob: a60fa59811193ab59b5e7cf2537efb1cce317b46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/* packet-isup_thin.c
 * Routines for ISUP Thin dissection
 * Copyright 2005, Anders Broman <anders.broman[at]ericsson.com>
 *
 * $Id$
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@ethereal.com>
 * Copyright 1998 Gerald Combs
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <glib.h>
#include <epan/conversation.h>

#ifdef NEED_SNPRINTF_H
# include "snprintf.h"
#endif

#include <epan/packet.h>
#include "prefs.h"

static int ISUP_thinTCPPort = 0;
static int tcp_port = 0;

/* Initialize the protocol and registered fields */
static int proto_isup_thin		= -1;

/* Initialize the subtree pointers */
static int ett_isup_thin					= -1;

static int hf_isup_thin_count_type		= -1;
static int hf_isup_thin_count			= -1;
static int hf_isup_thin_message_class	= -1;
static int hf_isup_thin_version			= -1;
static int hf_isup_thin_message_type	= -1;
static int hf_isup_thin_serv_ind		= -1;
static int hf_isup_thin_subservind		= -1;
static int hf_isup_thin_priority		= -1;
static int hf_isup_thin_sls				= -1;
static int hf_isup_thin_opc				= -1;
static int hf_isup_thin_dpc				= -1;
static int hf_isup_thin_oam_message_name_code = -1;
static int hf_isup_thin_mtp_primitive_message_name_code = -1;
static int hf_isup_thin_isup_length		= -1;



static const value_string isup_thin_count_type_vals[] = {
	{0,		"64 octet count (Not used by t-ISUP)"}, 
	{1,		"4 octet count"},
	{ 0,	NULL }
};

static const value_string isup_thin_message_type_vals[] = {
	{0,		"OAM Message"}, 
	{1,		"MTP Primitive"},
	{2,		"Encapsulated ISUP Message format according to the used ISUP protocol"},
	{ 0,	NULL }
};

static const value_string isup_thin_oam_message_name_code_vals[] = {
	{1,		"Heartbeat"},
	{ 0,	NULL }
};
static const value_string isup_thin_mtp_message_name_code_vals[] = {
	{1,		"MTP_Pause"},
	{2,		"MTP_Resume"},
	{3,		"MTP_UP_Unavailable"},
	{4,		"MTP_Cong"},
	{6,		"MTP_Rest"},
	{7,		"MTP_Rest_End"},
	{ 0,	NULL }
};

dissector_handle_t isup_thin_handle;
dissector_handle_t isup_handle;


static int dissect_isup_thin(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);





/* Code to actually dissect the packets */
static int
dissect_isup_thin(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
	proto_item *ti;
	proto_tree *isup_thin_tree;
	tvbuff_t *next_tvb;
	gint offset = 0;
	gint octet;
	gint message_type;
	gint16 isup_message_length;


	/* Make entries in Protocol column and Info column on summary display */
	if (check_col(pinfo->cinfo, COL_PROTOCOL)) 
		col_set_str(pinfo->cinfo, COL_PROTOCOL, "isup_thin");

	/* Find the end line to be able to process the headers
	 * Note that in case of [content-stuff] headers and [content-stuff] is separated by CRLF
	 */



	if (tree) {
		ti = proto_tree_add_item(tree, proto_isup_thin, tvb, 0, -1, FALSE);
		isup_thin_tree = proto_item_add_subtree(ti, ett_isup_thin);

		octet = tvb_get_guint8(tvb,offset);
		proto_tree_add_item(isup_thin_tree, hf_isup_thin_count_type, tvb, offset, 1, FALSE);
		proto_tree_add_item(isup_thin_tree, hf_isup_thin_count, tvb, offset, 2, FALSE);
		offset = offset + 2;
		proto_tree_add_item(isup_thin_tree, hf_isup_thin_message_class, tvb, offset, 1, FALSE);
		proto_tree_add_item(isup_thin_tree, hf_isup_thin_version, tvb, offset, 2, FALSE);
		offset++;
		message_type = tvb_get_guint8(tvb,offset) & 0x7f ;
		proto_tree_add_item(isup_thin_tree, hf_isup_thin_message_type, tvb, offset, 1, FALSE);
		offset++;
		proto_tree_add_item(isup_thin_tree, hf_isup_thin_serv_ind, tvb, offset, 1, FALSE);
		/* SubServInd	*/
		proto_tree_add_item(isup_thin_tree, hf_isup_thin_subservind, tvb, offset, 1, FALSE);
		/* Priority		*/
		proto_tree_add_item(isup_thin_tree, hf_isup_thin_priority, tvb, offset, 1, FALSE);
		offset++;
		proto_tree_add_item(isup_thin_tree, hf_isup_thin_sls, tvb, offset, 1, FALSE);
		offset++;
		proto_tree_add_item(isup_thin_tree, hf_isup_thin_opc, tvb, offset, 3, FALSE);
		offset = offset +3;
		proto_tree_add_item(isup_thin_tree, hf_isup_thin_dpc, tvb, offset, 3, FALSE);
		offset = offset +3;

		/* 12 Bytes off measage header done */
		switch (message_type) {
			case 0:
				/* OAM message */
				proto_tree_add_item(isup_thin_tree, hf_isup_thin_oam_message_name_code, tvb, offset, 1, FALSE);
				offset++;
				break;
			case 1:
				/* MTP Primitive */
				proto_tree_add_item(isup_thin_tree, hf_isup_thin_mtp_primitive_message_name_code, tvb, offset, 1, FALSE);
				offset++;
				break;
			case 2:
				/*Encapsulated ISUP Message format according to the used ISUP protocol */
				isup_message_length = tvb_get_ntohs(tvb,offset);
				proto_tree_add_item(isup_thin_tree, hf_isup_thin_isup_length, tvb, offset, 2, FALSE);
				offset = offset +2;
				next_tvb = tvb_new_subset(tvb, offset, isup_message_length, isup_message_length);
				call_dissector(isup_handle, next_tvb, pinfo, tree);
				break;
			default:
				/* Unknown */
				return 0;
		}



	}/* if tree */
	return tvb_length(tvb); 

/* If this protocol has a sub-dissector call it here, see section 1.8 */
}


/* Register the protocol with Ethereal */
/* If this dissector uses sub-dissector registration add a registration routine.
   This format is required because a script is used to find these routines and
   create the code that calls these routines.
*/
void
proto_reg_handoff_isup_thin(void)
{
	static int Initialized=FALSE;
	
	if (!Initialized) {
		isup_thin_handle = new_create_dissector_handle(dissect_isup_thin, proto_isup_thin);
		Initialized=TRUE;
	}else{
		dissector_delete("tcp.port", tcp_port, isup_thin_handle);
	}

	tcp_port = ISUP_thinTCPPort;

	dissector_add("tcp.port", tcp_port, isup_thin_handle);
	isup_handle = find_dissector("isup");
}

void
proto_register_isup_thin(void)
{                 

/* Setup protocol subtree array */
	static gint *ett[] = {
		&ett_isup_thin,
	};

        /* Setup list of header fields */
	static hf_register_info hf[] = {
		{ &hf_isup_thin_count_type,
			{ "Count Type", 		"isup_thin.count.type",
			FT_UINT8, BASE_DEC,VALS(isup_thin_count_type_vals), 0x80,
			"Count Type", HFILL }
		},
		{ &hf_isup_thin_count,
			{ "Message length (counted according to bit 0) including the Message Header","isup_thin.count",
			FT_UINT16, BASE_DEC,NULL, 0x7fff,
			"Message length", HFILL }
		},
		{ &hf_isup_thin_message_class,
			{ "Message Class","isup_thin.message.class",
			FT_UINT8, BASE_DEC,NULL, 0xfc,
			"Message Class", HFILL }
		},
		{ &hf_isup_thin_version,
			{ "Version","isup_thin.count.version",
			FT_UINT16, BASE_DEC,NULL, 0x0380,
			"Version", HFILL }
		},
		{ &hf_isup_thin_message_type,
			{ "Message Type", 		"isup_thin.messaget.type",
			FT_UINT8, BASE_DEC,VALS(isup_thin_message_type_vals), 0x7f,
			"Message Type", HFILL }
		},
		{ &hf_isup_thin_serv_ind,
			{ "Service Indicator","isup_thin.servind",
			FT_UINT8, BASE_DEC,NULL, 0xf0,
			"Service Indicator", HFILL }
		},
		{ &hf_isup_thin_subservind,
			{ "Sub Service Field (Network Indicator)","isup_thin.subservind",
			FT_UINT8, BASE_DEC,NULL, 0x0c,
			"Sub Service Field (Network Indicator)", HFILL }
		},
		{ &hf_isup_thin_priority,
			{ "Priority","isup_thin.priority",
			FT_UINT8, BASE_DEC,NULL, 0x03,
			"Priority", HFILL }
		},
		{ &hf_isup_thin_sls,
			{ "Signalling Link Selection","isup_thin.sls",
			FT_UINT8, BASE_DEC,NULL, 0x0,
			"Signalling Link Selection", HFILL }
		},
		{ &hf_isup_thin_opc,
			{ "Originating Point Code","isup_thin.opc",
			FT_UINT32, BASE_DEC,NULL, 0x0,
			"Originating Point Code", HFILL }
		},
		{ &hf_isup_thin_dpc,
			{ "Destination Point Code","isup_thin.dpc",
			FT_UINT32, BASE_DEC,NULL, 0x0,
			"Destination Point Code", HFILL }
		},
		{ &hf_isup_thin_oam_message_name_code,
			{ "Message Name Code","isup_thin.oam.message.name",
			FT_UINT8, BASE_DEC,VALS(isup_thin_oam_message_name_code_vals), 0x0,
			"Message Name", HFILL }
		},
		{ &hf_isup_thin_mtp_primitive_message_name_code,
			{ "Message Name Code","isup_thin.mtp.message.name",
			FT_UINT8, BASE_DEC,VALS(isup_thin_mtp_message_name_code_vals), 0x0,
			"Message Name", HFILL }
		},
		{ &hf_isup_thin_isup_length,
			{ "ISUP message length","isup_thin.isup.message.length",
			FT_UINT16, BASE_DEC, NULL, 0x0,
			"ISUP message length", HFILL }
		},
	};

	module_t *isup_thin_module;
/* Register the protocol name and description */
	proto_isup_thin = proto_register_protocol("ISUP Thin Protocol","isup_thin", "isup_thin");

/* Required function calls to register the header fields and subtrees used */
	proto_register_field_array(proto_isup_thin, hf, array_length(hf));
	proto_register_subtree_array(ett, array_length(ett));


	isup_thin_module = prefs_register_protocol(proto_isup_thin, NULL);

	prefs_register_uint_preference(isup_thin_module, "tcp.port",
								   "ISUP Thin TCP Port",
								   "Set TCP port for ISUP Thin messages",
								   10,
								   &ISUP_thinTCPPort);
		
  /*
   * Register the dissector by name, so other dissectors can
   * grab it by name rather than just referring to it directly.
   */
  new_register_dissector("isup_thin", dissect_isup_thin, proto_isup_thin);

}