HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / dissectors / packet-sccpmg.c
blob26b2092709987d235031418e9baa59d0078f1bf5
1 /* packet-sccpmg.c
2 * Routines for Signalling Connection Control Part (SCCP) Management dissection
4 * It is hopefully compliant to:
5 * ANSI T1.112.3-1996
6 * ITU-T Q.713 7/1996
7 * YDN 038-1997 (Chinese ITU variant)
8 * JT-Q714 and NTT-Q714 (Japan)
10 * Note that NTT Annex E (SCCP Management Procedure (Global Title Status
11 * Management)) is not implemented (yet)
13 * Copyright 2002, Jeff Morriss <jeff.morriss.ws [AT] gmail.com>
15 * $Id$
17 * Wireshark - Network traffic analyzer
18 * By Gerald Combs <gerald@wireshark.org>
19 * Copyright 1998 Gerald Combs
21 * This program is free software; you can redistribute it and/or
22 * modify it under the terms of the GNU General Public License
23 * as published by the Free Software Foundation; either version 2
24 * of the License, or (at your option) any later version.
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
31 * You should have received a copy of the GNU General Public License
32 * along with this program; if not, write to the Free Software
33 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
36 #include "config.h"
38 #include <glib.h>
40 #include <epan/packet.h>
41 #include "packet-mtp3.h"
43 #define SCCPMG_SSN 1
45 #define SCCPMG_MESSAGE_TYPE_SSA 0x01
46 #define SCCPMG_MESSAGE_TYPE_SSP 0x02
47 #define SCCPMG_MESSAGE_TYPE_SST 0x03
48 #define SCCPMG_MESSAGE_TYPE_SOR 0x04
49 #define SCCPMG_MESSAGE_TYPE_SOG 0x05
50 /* SSC is ITU only */
51 #define SCCPMG_MESSAGE_TYPE_SSC 0x06
52 /* Below are ANSI only */
53 #define SCCPMG_MESSAGE_TYPE_SBR 0xfd
54 #define SCCPMG_MESSAGE_TYPE_SNR 0xfe
55 #define SCCPMG_MESSAGE_TYPE_SRT 0xff
57 /* Same as below but with names typed out */
58 static const value_string sccpmg_message_type_values[] = {
59 { SCCPMG_MESSAGE_TYPE_SSA, "SubSystem Allowed" },
60 { SCCPMG_MESSAGE_TYPE_SSP, "SubSystem Prohibited" },
61 { SCCPMG_MESSAGE_TYPE_SST, "Subsystem Status Test" },
62 { SCCPMG_MESSAGE_TYPE_SOR, "Subsystem Out of service Request" },
63 { SCCPMG_MESSAGE_TYPE_SOG, "Subsystem Out of service Grant" },
64 { SCCPMG_MESSAGE_TYPE_SSC, "SubSystem Congested (ITU)" },
65 { SCCPMG_MESSAGE_TYPE_SBR, "Subsystem Backup Routing (ANSI)" },
66 { SCCPMG_MESSAGE_TYPE_SNR, "Subsystem Normal Routing (ANSI)" },
67 { SCCPMG_MESSAGE_TYPE_SRT, "Subsystem Routing status Test (ANSI)" },
68 { 0, NULL } };
70 /* Same as above but in acronym for (for the Info column) */
71 static const value_string sccpmg_message_type_acro_values[] = {
72 { SCCPMG_MESSAGE_TYPE_SSA, "SSA" },
73 { SCCPMG_MESSAGE_TYPE_SSP, "SSP" },
74 { SCCPMG_MESSAGE_TYPE_SST, "SST" },
75 { SCCPMG_MESSAGE_TYPE_SOR, "SOR" },
76 { SCCPMG_MESSAGE_TYPE_SOG, "SOG" },
77 { SCCPMG_MESSAGE_TYPE_SSC, "SSC" },
78 { SCCPMG_MESSAGE_TYPE_SBR, "SBR" },
79 { SCCPMG_MESSAGE_TYPE_SNR, "SNR" },
80 { SCCPMG_MESSAGE_TYPE_SRT, "SRT" },
81 { 0, NULL } };
84 #define SCCPMG_MESSAGE_TYPE_OFFSET 0
85 #define SCCPMG_MESSAGE_TYPE_LENGTH 1
87 #define SCCPMG_AFFECTED_SSN_OFFSET SCCPMG_MESSAGE_TYPE_LENGTH
88 #define SCCPMG_AFFECTED_SSN_LENGTH 1
90 #define SCCPMG_AFFECTED_PC_OFFSET (SCCPMG_AFFECTED_SSN_OFFSET + SCCPMG_AFFECTED_SSN_LENGTH)
91 #define ITU_SCCPMG_AFFECTED_PC_LENGTH 2
92 #define ANSI_SCCPMG_AFFECTED_PC_LENGTH 3
94 #define ITU_SCCPMG_SMI_OFFSET (SCCPMG_AFFECTED_PC_OFFSET + ITU_SCCPMG_AFFECTED_PC_LENGTH)
95 #define ANSI_SCCPMG_SMI_OFFSET (SCCPMG_AFFECTED_PC_OFFSET + ANSI_SCCPMG_AFFECTED_PC_LENGTH)
96 #define SCCPMG_SMI_LENGTH 1
97 #define SCCPMG_SMI_MASK 0x3
99 #define ITU_SCCPMG_CONGESTION_OFFSET (ITU_SCCPMG_SMI_OFFSET + SCCPMG_SMI_LENGTH)
100 #define ITU_SCCPMG_CONGESTION_LENGTH 1
101 #define ITU_SCCPMG_CONGESTION_MASK 0x0f
102 #define CHINESE_ITU_SCCPMG_CONGESTION_OFFSET (ANSI_SCCPMG_SMI_OFFSET + SCCPMG_SMI_LENGTH)
104 #define SCCPMG_SSN_LENGTH 1
106 /* Initialize the protocol and registered fields */
107 static int proto_sccpmg = -1;
108 static int hf_sccpmg_message_type = -1;
109 static int hf_sccpmg_affected_ssn = -1;
110 static int hf_sccpmg_affected_itu_pc = -1;
111 static int hf_sccpmg_affected_japan_pc = -1;
112 static int hf_sccpmg_affected_ansi_pc = -1;
113 static int hf_sccpmg_affected_chinese_pc = -1;
114 static int hf_sccpmg_affected_pc_member = -1;
115 static int hf_sccpmg_affected_pc_cluster = -1;
116 static int hf_sccpmg_affected_pc_network = -1;
117 static int hf_sccpmg_smi = -1;
118 static int hf_sccpmg_congestion_level = -1;
120 /* Initialize the subtree pointers */
121 static gint ett_sccpmg = -1;
122 static gint ett_sccpmg_affected_pc = -1;
124 static void
125 dissect_sccpmg_unknown_message(tvbuff_t *message_tvb, proto_tree *sccpmg_tree)
127 guint32 message_length;
129 message_length = tvb_length(message_tvb);
131 proto_tree_add_text(sccpmg_tree, message_tvb, 0, message_length,
132 "Unknown message (%u byte%s)", message_length,
133 plurality(message_length, "", "s"));
136 static void
137 dissect_sccpmg_affected_ssn(tvbuff_t *tvb, proto_tree *sccpmg_tree)
139 proto_tree_add_item(sccpmg_tree, hf_sccpmg_affected_ssn, tvb,
140 SCCPMG_AFFECTED_SSN_OFFSET, SCCPMG_SSN_LENGTH,
141 ENC_BIG_ENDIAN);
144 static void
145 dissect_sccpmg_affected_pc(tvbuff_t *tvb, proto_tree *sccpmg_tree)
147 guint8 offset = SCCPMG_AFFECTED_PC_OFFSET;
149 if (mtp3_standard == ITU_STANDARD) {
150 proto_tree_add_item(sccpmg_tree, hf_sccpmg_affected_itu_pc, tvb,
151 offset, ITU_PC_LENGTH, ENC_LITTLE_ENDIAN);
152 } else if (mtp3_standard == JAPAN_STANDARD) {
153 proto_tree_add_item(sccpmg_tree, hf_sccpmg_affected_japan_pc,
154 tvb, offset, JAPAN_PC_LENGTH, ENC_LITTLE_ENDIAN);
155 } else /* ANSI_STANDARD and CHINESE_ITU_STANDARD */ {
156 int *hf_affected_pc;
158 if (mtp3_standard == ANSI_STANDARD)
160 hf_affected_pc = &hf_sccpmg_affected_ansi_pc;
161 } else /* CHINESE_ITU_STANDARD */ {
162 hf_affected_pc = &hf_sccpmg_affected_chinese_pc;
165 /* create and fill the PC tree */
166 dissect_mtp3_3byte_pc(tvb, offset, sccpmg_tree,
167 ett_sccpmg_affected_pc, *hf_affected_pc,
168 hf_sccpmg_affected_pc_network,
169 hf_sccpmg_affected_pc_cluster,
170 hf_sccpmg_affected_pc_member, 0, 0);
175 static void
176 dissect_sccpmg_smi(tvbuff_t *tvb, proto_tree *sccpmg_tree)
178 guint8 offset = 0;
180 if (mtp3_standard == ITU_STANDARD || mtp3_standard == JAPAN_STANDARD)
181 offset = ITU_SCCPMG_SMI_OFFSET;
182 else /* ANSI_STANDARD and CHINESE_ITU_STANDARD */
183 offset = ANSI_SCCPMG_SMI_OFFSET;
185 proto_tree_add_item(sccpmg_tree, hf_sccpmg_smi, tvb, offset,
186 SCCPMG_SMI_LENGTH, ENC_BIG_ENDIAN);
189 static void
190 dissect_sccpmg_congestion_level(tvbuff_t *tvb, proto_tree *sccpmg_tree)
192 guint8 offset = 0;
194 if (mtp3_standard == CHINESE_ITU_STANDARD)
195 offset = CHINESE_ITU_SCCPMG_CONGESTION_OFFSET;
196 else /* ITU_STANDARD or JAPAN_STANDARD */
197 offset = ITU_SCCPMG_CONGESTION_OFFSET;
199 proto_tree_add_item(sccpmg_tree, hf_sccpmg_congestion_level, tvb,
200 offset, ITU_SCCPMG_CONGESTION_LENGTH, ENC_BIG_ENDIAN);
203 static void
204 dissect_sccpmg_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *sccpmg_tree)
206 guint8 message_type;
208 /* Extract the message type; all other processing is based on this */
209 message_type = tvb_get_guint8(tvb, SCCPMG_MESSAGE_TYPE_OFFSET);
211 col_add_fstr(pinfo->cinfo, COL_INFO, "%s ", val_to_str_const(message_type, sccpmg_message_type_acro_values, "Unknown"));
213 if (sccpmg_tree) {
214 /* add the message type to the protocol tree */
215 proto_tree_add_uint(sccpmg_tree, hf_sccpmg_message_type, tvb,
216 SCCPMG_MESSAGE_TYPE_OFFSET,
217 SCCPMG_MESSAGE_TYPE_LENGTH, message_type);
220 switch(message_type) {
221 case SCCPMG_MESSAGE_TYPE_SBR:
222 case SCCPMG_MESSAGE_TYPE_SNR:
223 case SCCPMG_MESSAGE_TYPE_SRT:
224 if (mtp3_standard != ANSI_STANDARD)
226 dissect_sccpmg_unknown_message(tvb, sccpmg_tree);
227 break;
229 /* else fallthrough */
230 case SCCPMG_MESSAGE_TYPE_SSA:
231 case SCCPMG_MESSAGE_TYPE_SSP:
232 case SCCPMG_MESSAGE_TYPE_SST:
233 case SCCPMG_MESSAGE_TYPE_SOR:
234 case SCCPMG_MESSAGE_TYPE_SOG:
235 dissect_sccpmg_affected_ssn(tvb, sccpmg_tree);
236 dissect_sccpmg_affected_pc(tvb, sccpmg_tree);
237 dissect_sccpmg_smi(tvb, sccpmg_tree);
239 break;
240 case SCCPMG_MESSAGE_TYPE_SSC:
241 if (mtp3_standard != ANSI_STANDARD)
243 dissect_sccpmg_affected_ssn(tvb, sccpmg_tree);
244 dissect_sccpmg_affected_pc(tvb, sccpmg_tree);
245 dissect_sccpmg_smi(tvb, sccpmg_tree);
246 dissect_sccpmg_congestion_level(tvb, sccpmg_tree);
248 /* else fallthrough */
250 default:
251 dissect_sccpmg_unknown_message(tvb, sccpmg_tree);
255 static void
256 dissect_sccpmg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
258 proto_item *sccpmg_item;
259 proto_tree *sccpmg_tree = NULL;
261 /* Make entry in the Protocol column on summary display */
262 switch(mtp3_standard) {
263 case ITU_STANDARD:
264 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SCCPMG (Int. ITU)");
265 break;
266 case ANSI_STANDARD:
267 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SCCPMG (ANSI)");
268 break;
269 case CHINESE_ITU_STANDARD:
270 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SCCPMG (Chin. ITU)");
271 break;
274 /* In the interest of speed, if "tree" is NULL, don't do any work not
275 necessary to generate protocol tree items. */
276 if (tree) {
277 /* create the sccpmg protocol tree */
278 sccpmg_item = proto_tree_add_item(tree, proto_sccpmg, tvb, 0,
279 -1, ENC_NA);
280 sccpmg_tree = proto_item_add_subtree(sccpmg_item, ett_sccpmg);
283 /* dissect the message */
284 dissect_sccpmg_message(tvb, pinfo, sccpmg_tree);
287 /* Register the protocol with Wireshark */
288 void
289 proto_register_sccpmg(void)
291 /* Setup list of header fields */
292 static hf_register_info hf[] = {
293 { &hf_sccpmg_message_type,
294 { "Message Type", "sccpmg.message_type",
295 FT_UINT8, BASE_HEX, VALS(sccpmg_message_type_values), 0x0,
296 NULL, HFILL}},
297 { &hf_sccpmg_affected_ssn,
298 { "Affected SubSystem Number", "sccpmg.ssn",
299 FT_UINT8, BASE_DEC, NULL, 0x0,
300 NULL, HFILL}},
301 { &hf_sccpmg_affected_itu_pc,
302 { "Affected Point Code", "sccpmg.pc",
303 FT_UINT16, BASE_DEC, NULL, ITU_PC_MASK,
304 NULL, HFILL}},
305 { &hf_sccpmg_affected_japan_pc,
306 { "Affected Point Code", "sccpmg.pc",
307 FT_UINT16, BASE_DEC, NULL, 0x0,
308 NULL, HFILL}},
309 { &hf_sccpmg_affected_ansi_pc,
310 { "Affected Point Code", "sccpmg.ansi_pc",
311 FT_STRING, BASE_NONE, NULL, 0x0,
312 NULL, HFILL}},
313 { &hf_sccpmg_affected_chinese_pc,
314 { "Affected Point Code", "sccpmg.chinese_pc",
315 FT_STRING, BASE_NONE, NULL, 0x0,
316 NULL, HFILL}},
317 { &hf_sccpmg_affected_pc_network,
318 { "Affected PC Network", "sccpmg.network",
319 FT_UINT24, BASE_DEC, NULL, ANSI_NETWORK_MASK,
320 NULL, HFILL}},
321 { &hf_sccpmg_affected_pc_cluster,
322 { "Affected PC Cluster", "sccpmg.cluster",
323 FT_UINT24, BASE_DEC, NULL, ANSI_CLUSTER_MASK,
324 NULL, HFILL}},
325 { &hf_sccpmg_affected_pc_member,
326 { "Affected PC Member", "sccpmg.member",
327 FT_UINT24, BASE_DEC, NULL, ANSI_MEMBER_MASK,
328 NULL, HFILL}},
329 { &hf_sccpmg_smi,
330 { "Subsystem Multiplicity Indicator", "sccpmg.smi",
331 FT_UINT8, BASE_DEC, NULL, SCCPMG_SMI_MASK,
332 NULL, HFILL}},
333 { &hf_sccpmg_congestion_level,
334 { "SCCP Congestion Level (ITU)", "sccpmg.congestion",
335 FT_UINT8, BASE_DEC, NULL, ITU_SCCPMG_CONGESTION_MASK,
336 NULL, HFILL}}
339 /* Setup protocol subtree array */
340 static gint *ett[] = {
341 &ett_sccpmg,
342 &ett_sccpmg_affected_pc
345 /* Register the protocol name and description */
346 proto_sccpmg = proto_register_protocol("Signalling Connection Control Part Management",
347 "SCCPMG", "sccpmg");
349 /* Required function calls to register the header fields and subtrees
350 used */
351 proto_register_field_array(proto_sccpmg, hf, array_length(hf));
352 proto_register_subtree_array(ett, array_length(ett));
355 void
356 proto_reg_handoff_sccpmg(void)
358 dissector_handle_t sccpmg_handle;
360 sccpmg_handle = create_dissector_handle(dissect_sccpmg, proto_sccpmg);
362 /* Register for SCCP SSN=1 messages */
363 dissector_add_uint("sccp.ssn", SCCPMG_SSN, sccpmg_handle);