From Jamie Fournier: AFS 4 UPDATE server support.
[obnox/wireshark/wip.git] / packet-sccpmg.c
1 /* packet-sccp.c
2  * Routines for Signalling Connection Control Part (SCCP) Management dissection
3  * It is hopefully compliant to:
4  *   ANSI T1.112.3-1996
5  *   ITU-T Q.713 7/1996
6  *
7  * Copyright 2002, Jeff Morriss <jeff.morriss[AT]ulticom.com>
8  *
9  * $Id: packet-sccpmg.c,v 1.1 2002/09/20 09:22:46 sahlberg Exp $
10  *
11  * Ethereal - Network traffic analyzer
12  * By Gerald Combs <gerald@ethereal.com>
13  * Copyright 1998 Gerald Combs
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28  */
29
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include "epan/packet.h"
35 #include "packet-mtp3.h"
36
37 #define SCCPMG_SSN 1
38
39 #define SCCPMG_MESSAGE_TYPE_SSA 0x01
40 #define SCCPMG_MESSAGE_TYPE_SSP 0x02
41 #define SCCPMG_MESSAGE_TYPE_SST 0x03
42 #define SCCPMG_MESSAGE_TYPE_SOR 0x04
43 #define SCCPMG_MESSAGE_TYPE_SOG 0x05
44 /* SSC is ITU only */
45 #define SCCPMG_MESSAGE_TYPE_SSC 0x06
46 /* Below are ANSI only */
47 #define SCCPMG_MESSAGE_TYPE_SBR 0xfd
48 #define SCCPMG_MESSAGE_TYPE_SNR 0xfe
49 #define SCCPMG_MESSAGE_TYPE_SRT 0xff
50
51 /* Same as below but with names typed out */
52 static const value_string sccpmg_message_type_values[] = {
53   { SCCPMG_MESSAGE_TYPE_SSA,   "SubSystem Allowed" },
54   { SCCPMG_MESSAGE_TYPE_SSP,   "SubSystem Prohibited" },
55   { SCCPMG_MESSAGE_TYPE_SST,   "Subsystem Status Test" },
56   { SCCPMG_MESSAGE_TYPE_SOR,   "Subsystem Out of service Request" },
57   { SCCPMG_MESSAGE_TYPE_SOG,   "Subsystem Out of service Grant" },
58   { SCCPMG_MESSAGE_TYPE_SSC,   "SubSystem Congested (ITU)" },
59   { SCCPMG_MESSAGE_TYPE_SBR,   "Subsystem Backup Routing (ANSI)" },
60   { SCCPMG_MESSAGE_TYPE_SNR,   "Subsystem Normal Routing (ANSI)" },
61   { SCCPMG_MESSAGE_TYPE_SRT,   "Subsystem Routing status Test (ANSI)" },
62   { 0,                       NULL } };
63
64 /* Same as above but in acronym for (for the Info column) */
65 static const value_string sccpmg_message_type_acro_values[] = {
66   { SCCPMG_MESSAGE_TYPE_SSA,   "SSA" },
67   { SCCPMG_MESSAGE_TYPE_SSP,   "SSP" },
68   { SCCPMG_MESSAGE_TYPE_SST,   "SST" },
69   { SCCPMG_MESSAGE_TYPE_SOR,   "SOR" },
70   { SCCPMG_MESSAGE_TYPE_SOG,   "SOG" },
71   { SCCPMG_MESSAGE_TYPE_SSC,   "SSC" },
72   { SCCPMG_MESSAGE_TYPE_SBR,   "SBR" },
73   { SCCPMG_MESSAGE_TYPE_SNR,   "SNR" },
74   { SCCPMG_MESSAGE_TYPE_SRT,   "SRT" },
75   { 0,                       NULL } };
76
77
78 #define SCCPMG_MESSAGE_TYPE_OFFSET 0
79 #define SCCPMG_MESSAGE_TYPE_LENGTH 1
80
81 #define SCCPMG_AFFECTED_SSN_OFFSET SCCPMG_MESSAGE_TYPE_LENGTH
82 #define SCCPMG_AFFECTED_SSN_LENGTH 1
83
84 #define SCCPMG_AFFECTED_PC_OFFSET (SCCPMG_AFFECTED_SSN_OFFSET + SCCPMG_AFFECTED_SSN_LENGTH)
85 #define ITU_SCCPMG_AFFECTED_PC_LENGTH 2
86 #define ANSI_SCCPMG_AFFECTED_PC_LENGTH 3
87
88 #define ITU_SCCPMG_SMI_OFFSET (SCCPMG_AFFECTED_PC_OFFSET + ITU_SCCPMG_AFFECTED_PC_LENGTH)
89 #define ANSI_SCCPMG_SMI_OFFSET (SCCPMG_AFFECTED_PC_OFFSET + ANSI_SCCPMG_AFFECTED_PC_LENGTH)
90 #define SCCPMG_SMI_LENGTH 1
91 #define SCCPMG_SMI_MASK 0x3
92
93 #define ITU_SCCPMG_CONGESTION_OFFSET (ITU_SCCPMG_SMI_OFFSET + SCCPMG_SMI_LENGTH)
94 #define ITU_SCCPMG_CONGESTION_LENGTH 1
95 #define ITU_SCCPMG_CONGESTION_MASK 0x0f
96
97 #define SCCPMG_SSN_LENGTH    1
98
99 /* Initialize the protocol and registered fields */
100 static int proto_sccpmg = -1;
101 static int hf_sccpmg_message_type = -1;
102 static int hf_sccpmg_affected_ssn = -1;
103 static int hf_sccpmg_affected_pc = -1;
104 static int hf_sccpmg_affected_pc_member = -1;
105 static int hf_sccpmg_affected_pc_cluster = -1;
106 static int hf_sccpmg_affected_pc_network = -1;
107 static int hf_sccpmg_smi = -1;
108 static int hf_sccpmg_congestion_level = -1;
109
110 /* Initialize the subtree pointers */
111 static gint ett_sccpmg = -1;
112 static gint ett_sccpmg_affected_pc = -1;
113
114 static void
115 dissect_sccpmg_unknown_message(tvbuff_t *message_tvb, proto_tree *sccpmg_tree)
116 {
117         guint32 message_length;
118
119         message_length = tvb_length(message_tvb);
120
121         proto_tree_add_text(sccpmg_tree, message_tvb, 0, message_length,
122                             "Unknown message (%u byte%s)", message_length,
123                             plurality(message_length, "", "s"));
124 }
125
126 static void
127 dissect_sccpmg_affected_ssn(tvbuff_t *tvb, proto_tree *sccpmg_tree)
128 {
129         proto_tree_add_item(sccpmg_tree, hf_sccpmg_affected_ssn, tvb,
130                             SCCPMG_AFFECTED_SSN_OFFSET, SCCPMG_SSN_LENGTH,
131                             FALSE);
132 }
133
134 static void
135 dissect_sccpmg_affected_pc(tvbuff_t *tvb, proto_tree *sccpmg_tree)
136 {
137         proto_item *pc_item = 0;
138         proto_tree *pc_tree = 0;
139         guint32 dpc;
140         guint8 offset = SCCPMG_AFFECTED_PC_OFFSET;
141
142         if (mtp3_standard == ITU_STANDARD) {
143                 proto_tree_add_item(sccpmg_tree, hf_sccpmg_affected_pc, tvb,
144                                     offset, ITU_PC_LENGTH, TRUE);
145         } else if (mtp3_standard == ANSI_STANDARD) {
146                 /* create the DPC tree; modified from that in packet-sccp.c */
147                 dpc = tvb_get_ntoh24(tvb, offset);
148                 pc_item = proto_tree_add_text(sccpmg_tree, tvb, offset,
149                                               ANSI_PC_LENGTH, "PC (%d-%d-%d)",
150                                               (dpc & ANSI_NETWORK_MASK),
151                                               ((dpc & ANSI_CLUSTER_MASK) >> 8),
152                                               ((dpc & ANSI_MEMBER_MASK) >> 16));
153
154                 pc_tree = proto_item_add_subtree(pc_item,
155                                                  ett_sccpmg_affected_pc);
156
157                 proto_tree_add_uint(pc_tree, hf_sccpmg_affected_pc_member, tvb,
158                                     offset, ANSI_NCM_LENGTH, dpc);
159                 offset += ANSI_NCM_LENGTH;
160                 proto_tree_add_uint(pc_tree, hf_sccpmg_affected_pc_cluster, tvb,
161                                     offset, ANSI_NCM_LENGTH, dpc);
162                 offset += ANSI_NCM_LENGTH;
163                 proto_tree_add_uint(pc_tree, hf_sccpmg_affected_pc_network,
164                                     tvb, offset, ANSI_NCM_LENGTH, dpc);
165         }
166 }
167
168 static void
169 dissect_sccpmg_smi(tvbuff_t *tvb, proto_tree *sccpmg_tree)
170 {
171         guint8 offset = 0;
172
173         if (mtp3_standard == ITU_STANDARD)
174                 offset = ITU_SCCPMG_SMI_OFFSET;
175         else
176                 offset = ANSI_SCCPMG_SMI_OFFSET;
177
178         proto_tree_add_item(sccpmg_tree, hf_sccpmg_smi, tvb, offset,
179                             SCCPMG_SMI_LENGTH, FALSE);
180 }
181
182 static void
183 dissect_sccpmg_congestion_level(tvbuff_t *tvb, proto_tree *sccpmg_tree)
184 {
185         proto_tree_add_item(sccpmg_tree, hf_sccpmg_congestion_level, tvb,
186                             ITU_SCCPMG_CONGESTION_OFFSET,
187                             ITU_SCCPMG_CONGESTION_LENGTH, FALSE);
188 }
189
190 static void
191 dissect_sccpmg_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *sccpmg_tree)
192 {
193         guint8 message_type;
194         guint8 offset = 0;
195
196         /* Extract the message type;  all other processing is based on this */
197         message_type   = tvb_get_guint8(tvb, SCCPMG_MESSAGE_TYPE_OFFSET);
198         offset = SCCPMG_MESSAGE_TYPE_LENGTH;
199
200         if (check_col(pinfo->cinfo, COL_INFO)) {
201                 col_append_fstr(pinfo->cinfo, COL_INFO, "(%s) ",
202                                 val_to_str(message_type,
203                                            sccpmg_message_type_acro_values,
204                                            "Unknown"));
205         }
206
207         if (sccpmg_tree) {
208                 /* add the message type to the protocol tree */
209                 proto_tree_add_uint(sccpmg_tree, hf_sccpmg_message_type, tvb,
210                                     SCCPMG_MESSAGE_TYPE_OFFSET,
211                                     SCCPMG_MESSAGE_TYPE_LENGTH, message_type);
212         }
213
214         switch(message_type) {
215         case SCCPMG_MESSAGE_TYPE_SBR:
216         case SCCPMG_MESSAGE_TYPE_SNR:
217         case SCCPMG_MESSAGE_TYPE_SRT:
218                 if (mtp3_standard == ITU_STANDARD)
219                 {
220                         dissect_sccpmg_unknown_message(tvb, sccpmg_tree);
221                         break;
222                 }
223                 /* else fallthrough */
224         case SCCPMG_MESSAGE_TYPE_SSA:
225         case SCCPMG_MESSAGE_TYPE_SSP:
226         case SCCPMG_MESSAGE_TYPE_SST:
227         case SCCPMG_MESSAGE_TYPE_SOR:
228         case SCCPMG_MESSAGE_TYPE_SOG:
229                 dissect_sccpmg_affected_ssn(tvb, sccpmg_tree);
230                 dissect_sccpmg_affected_pc(tvb, sccpmg_tree);
231                 dissect_sccpmg_smi(tvb, sccpmg_tree);
232
233                 break;
234         case SCCPMG_MESSAGE_TYPE_SSC:
235                 if (mtp3_standard == ITU_STANDARD)
236                 {
237                         dissect_sccpmg_affected_ssn(tvb, sccpmg_tree);
238                         dissect_sccpmg_affected_pc(tvb, sccpmg_tree);
239                         dissect_sccpmg_smi(tvb, sccpmg_tree);
240                         dissect_sccpmg_congestion_level(tvb, sccpmg_tree);
241                 }
242                 /* else fallthrough */
243
244         default:
245                 dissect_sccpmg_unknown_message(tvb, sccpmg_tree);
246         }
247 }
248
249 static void
250 dissect_sccpmg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
251 {
252         proto_item *sccpmg_item;
253         proto_tree *sccpmg_tree = NULL;
254
255         /* Make entry in the Protocol column on summary display */
256         if (check_col(pinfo->cinfo, COL_PROTOCOL))
257                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SCCPMG");
258
259         /* In the interest of speed, if "tree" is NULL, don't do any work not
260            necessary to generate protocol tree items. */
261         if (tree) {
262                 /* create the sccpmg protocol tree */
263                 sccpmg_item = proto_tree_add_item(tree, proto_sccpmg, tvb, 0,
264                                                   -1, FALSE);
265                 sccpmg_tree = proto_item_add_subtree(sccpmg_item, ett_sccpmg);
266         }
267
268         /* dissect the message */
269         dissect_sccpmg_message(tvb, pinfo, sccpmg_tree);
270 }
271
272 /* Register the protocol with Ethereal */
273 void
274 proto_register_sccpmg(void)
275 {
276         /* Setup list of header fields */
277         static hf_register_info hf[] = {
278           { &hf_sccpmg_message_type,
279             { "Message Type", "sccpmg.message_type",
280             FT_UINT8, BASE_HEX, VALS(sccpmg_message_type_values), 0x0,
281             "", HFILL}},
282           { &hf_sccpmg_affected_ssn,
283             { "Affected SubSystem Number", "sccpmg.ssn",
284             FT_UINT8, BASE_DEC, NULL, 0x0,
285             "", HFILL}},
286           { &hf_sccpmg_affected_pc,
287             { "Affected Point Code", "sccpmg.pc",
288             FT_UINT16, BASE_DEC, NULL, ITU_PC_MASK,
289             "", HFILL}},
290           { &hf_sccpmg_affected_pc_network,
291             { "Affected PC Network",
292             "sccpmg.network",
293             FT_UINT24, BASE_DEC, NULL, ANSI_NETWORK_MASK,
294             "", HFILL}},
295           { &hf_sccpmg_affected_pc_cluster,
296             { "Affected PC Cluster",
297             "sccpmg.cluster",
298             FT_UINT24, BASE_DEC, NULL, ANSI_CLUSTER_MASK,
299             "", HFILL}},
300           { &hf_sccpmg_affected_pc_member,
301             { "Affected PC Member",
302             "sccpmg.member",
303             FT_UINT24, BASE_DEC, NULL, ANSI_MEMBER_MASK,
304             "", HFILL}},
305           { &hf_sccpmg_smi,
306             { "Subsystem Multiplicity Indicator",
307             "sccpmg.smi",
308             FT_UINT8, BASE_DEC, NULL, SCCPMG_SMI_MASK,
309             "", HFILL}},
310           { &hf_sccpmg_congestion_level,
311             { "SCCP Congestionl Level (ITU)",
312             "sccpmg.congestion",
313             FT_UINT8, BASE_DEC, NULL, ITU_SCCPMG_CONGESTION_MASK,
314             "", HFILL}}
315         };
316
317         /* Setup protocol subtree array */
318         static gint *ett[] = {
319                 &ett_sccpmg,
320                 &ett_sccpmg_affected_pc
321         };
322
323         /* Register the protocol name and description */
324         proto_sccpmg = proto_register_protocol("Signalling Connection Control Part Management",
325                                                "SCCPMG", "sccpmg");
326
327         /* Required function calls to register the header fields and subtrees
328            used */
329         proto_register_field_array(proto_sccpmg, hf, array_length(hf));
330         proto_register_subtree_array(ett, array_length(ett));
331 }
332
333 void
334 proto_reg_handoff_sccpmg(void)
335 {
336         dissector_handle_t sccpmg_handle;
337
338         sccpmg_handle = create_dissector_handle(dissect_sccpmg, proto_sccpmg);
339
340         /* Register for SCCP SSN=1 messages */
341         dissector_add("sccp.ssn", SCCPMG_SSN, sccpmg_handle);
342 }
343