Removed trailing whitespaces from .h and .c files using the
[obnox/wireshark/wip.git] / packet-m3ua.c
1 /* packet-m3ua.c
2  * Routines for MTP3 User Adaptation Layer dissection
3  * It is hopefully (needs testing) compilant to
4  * http://www.ietf.org/internet-drafts/draft-ietf-sigtran-m3ua-06.txt
5  * http://www.ietf.org/internet-drafts/draft-ietf-sigtran-m3ua-12.txt
6  * To do: - clean up the code
7  *        - provide better handling of length parameters
8  *        - provide good information in summary window
9  *
10  * Copyright 2000, 2001, 2002, Michael Tuexen <Michael.Tuexen@icn.siemens.de>
11  *
12  * $Id: packet-m3ua.c,v 1.20 2002/08/02 23:35:54 jmayer Exp $
13  *
14  * Ethereal - Network traffic analyzer
15  * By Gerald Combs <gerald@ethereal.com>
16  * Copyright 1998 Gerald Combs
17  *
18  * Copied from README.developer
19  * 
20  * This program is free software; you can redistribute it and/or
21  * modify it under the terms of the GNU General Public License
22  * as published by the Free Software Foundation; either version 2
23  * of the License, or (at your option) any later version.
24  * 
25  * This program is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28  * GNU General Public License for more details.
29  * 
30  * You should have received a copy of the GNU General Public License
31  * along with this program; if not, write to the Free Software
32  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33  */
34
35 #ifdef HAVE_CONFIG_H
36 # include "config.h"
37 #endif
38
39 #include <stdio.h>
40 #include <stdlib.h>
41
42
43 #include <string.h>
44 #include <glib.h>
45
46 #include <epan/packet.h>
47 #include "prefs.h"
48
49 #define SCTP_PORT_M3UA         2905
50 #define M3UA_PAYLOAD_PROTO_ID  3
51
52 #define VERSION_LENGTH         1
53 #define RESERVED_LENGTH        1
54 #define MESSAGE_CLASS_LENGTH   1
55 #define MESSAGE_TYPE_LENGTH    1
56 #define MESSAGE_LENGTH_LENGTH  4
57 #define COMMON_HEADER_LENGTH   (VERSION_LENGTH + RESERVED_LENGTH + MESSAGE_CLASS_LENGTH + \
58                                 MESSAGE_TYPE_LENGTH + MESSAGE_LENGTH_LENGTH)
59
60 #define VERSION_OFFSET         0
61 #define RESERVED_OFFSET        (VERSION_OFFSET + VERSION_LENGTH)
62 #define MESSAGE_CLASS_OFFSET   (RESERVED_OFFSET + RESERVED_LENGTH)
63 #define MESSAGE_TYPE_OFFSET    (MESSAGE_CLASS_OFFSET + MESSAGE_CLASS_LENGTH)
64 #define MESSAGE_LENGTH_OFFSET  (MESSAGE_TYPE_OFFSET + MESSAGE_TYPE_LENGTH)
65
66 #define PARAMETER_TAG_LENGTH    2
67 #define PARAMETER_LENGTH_LENGTH 2
68 #define PARAMETER_HEADER_LENGTH (PARAMETER_TAG_LENGTH + PARAMETER_LENGTH_LENGTH)
69
70 #define PARAMETER_TAG_OFFSET    0
71 #define PARAMETER_LENGTH_OFFSET (PARAMETER_TAG_OFFSET + PARAMETER_TAG_LENGTH)
72 #define PARAMETER_VALUE_OFFSET  (PARAMETER_LENGTH_OFFSET + PARAMETER_LENGTH_LENGTH)
73 #define PARAMETER_HEADER_OFFSET PARAMETER_TAG_OFFSET
74
75 #define V6_NETWORK_APPEARANCE_PARAMETER_TAG            1
76 #define V6_PROTOCOL_DATA_1_PARAMETER_TAG               2
77 #define V6_PROTOCOL_DATA_2_PARAMETER_TAG               3
78 #define V6_INFO_PARAMETER_TAG                          4
79 #define V6_AFFECTED_DESTINATIONS_PARAMETER_TAG         5
80 #define V6_ROUTING_CONTEXT_PARAMETER_TAG               6
81 #define V6_DIAGNOSTIC_INFORMATION_PARAMETER_TAG        7
82 #define V6_HEARTBEAT_DATA_PARAMETER_TAG                8
83 #define V6_USER_CAUSE_PARAMETER_TAG                    9
84 #define V6_REASON_PARAMETER_TAG                       10
85 #define V6_TRAFFIC_MODE_TYPE_PARAMETER_TAG            11
86 #define V6_ERROR_CODE_PARAMETER_TAG                   12
87 #define V6_STATUS_PARAMETER_TAG                       13
88 #define V6_CONGESTION_INDICATION_PARAMETER_TAG        14
89 #define V6_CONCERNED_DESTINATION_PARAMETER_TAG        15
90 #define V6_ROUTING_KEY_PARAMETER_TAG                  16
91 #define V6_REGISTRATION_RESULT_PARAMETER_TAG          17
92 #define V6_DEREGISTRATION_RESULT_PARAMETER_TAG        18
93 #define V6_LOCAL_ROUTING_KEY_IDENTIFIER_PARAMETER_TAG 19
94 #define V6_DESTINATION_POINT_CODE_PARAMETER_TAG       20
95 #define V6_SERVICE_INDICATORS_PARAMETER_TAG           21
96 #define V6_SUBSYSTEM_NUMBERS_PARAMETER_TAG            22
97 #define V6_ORIGINATING_POINT_CODE_LIST_PARAMETER_TAG  23
98 #define V6_CIRCUIT_RANGE_PARAMETER_TAG                24
99 #define V6_REGISTRATION_RESULTS_PARAMETER_TAG         25
100 #define V6_DEREGISTRATION_RESULTS_PARAMETER_TAG       26
101
102 static const value_string m3ua_v6_parameter_tag_values[] = {
103   { V6_NETWORK_APPEARANCE_PARAMETER_TAG,           "Network appearance" },
104   { V6_PROTOCOL_DATA_1_PARAMETER_TAG,              "Protocol data 1" },
105   { V6_PROTOCOL_DATA_2_PARAMETER_TAG,              "Protocol data 2" },
106   { V6_INFO_PARAMETER_TAG,                         "Info" },
107   { V6_AFFECTED_DESTINATIONS_PARAMETER_TAG,        "Affected destinations" },
108   { V6_ROUTING_CONTEXT_PARAMETER_TAG,              "Routing context" },
109   { V6_DIAGNOSTIC_INFORMATION_PARAMETER_TAG,       "Diagnostic information" },
110   { V6_HEARTBEAT_DATA_PARAMETER_TAG,               "Heartbeat data" },
111   { V6_USER_CAUSE_PARAMETER_TAG,                   "User / Cause" },
112   { V6_REASON_PARAMETER_TAG,                       "Reason" },
113   { V6_TRAFFIC_MODE_TYPE_PARAMETER_TAG,            "Traffic mode type" },
114   { V6_ERROR_CODE_PARAMETER_TAG,                   "Error code" },
115   { V6_STATUS_PARAMETER_TAG,                       "Status" }, 
116   { V6_CONGESTION_INDICATION_PARAMETER_TAG,        "Congestion indication" },
117   { V6_CONCERNED_DESTINATION_PARAMETER_TAG,        "Concerned destination" },
118   { V6_ROUTING_KEY_PARAMETER_TAG,                  "Routing Key" },
119   { V6_REGISTRATION_RESULT_PARAMETER_TAG,          "Registration result" },
120   { V6_DEREGISTRATION_RESULT_PARAMETER_TAG,        "De-registration result" },
121   { V6_LOCAL_ROUTING_KEY_IDENTIFIER_PARAMETER_TAG, "Local routing key identifier" },
122   { V6_DESTINATION_POINT_CODE_PARAMETER_TAG,       "Destination point code" },
123   { V6_SERVICE_INDICATORS_PARAMETER_TAG,           "Service indicators" },
124   { V6_SUBSYSTEM_NUMBERS_PARAMETER_TAG,            "Subsystem numbers" },
125   { V6_ORIGINATING_POINT_CODE_LIST_PARAMETER_TAG,  "Originating point code list" },
126   { V6_CIRCUIT_RANGE_PARAMETER_TAG,                "Circuit range" },
127   { V6_REGISTRATION_RESULTS_PARAMETER_TAG,         "Registration results" },
128   { V6_DEREGISTRATION_RESULTS_PARAMETER_TAG,       "De-registration results" },
129   { 0,                           NULL } };
130   
131 #define V12_INFO_STRING_PARAMETER_TAG                  0x0004
132 #define V12_ROUTING_CONTEXT_PARAMETER_TAG              0x0006
133 #define V12_DIAGNOSTIC_INFORMATION_PARAMETER_TAG       0x0007
134 #define V12_HEARTBEAT_DATA_PARAMETER_TAG               0x0009
135 #define V12_TRAFFIC_MODE_TYPE_PARAMETER_TAG            0x000b
136 #define V12_ERROR_CODE_PARAMETER_TAG                   0x000c
137 #define V12_STATUS_PARAMETER_TAG                       0x000d
138 #define V12_ASP_IDENTIFIER_PARAMETER_TAG               0x0011
139 #define V12_AFFECTED_POINT_CODE_PARAMETER_TAG          0x0012
140 #define V12_CORRELATION_IDENTIFIER_PARAMETER_TAG       0x0013
141
142 #define V12_NETWORK_APPEARANCE_PARAMETER_TAG           0x0200
143 #define V12_USER_CAUSE_PARAMETER_TAG                   0x0204
144 #define V12_CONGESTION_INDICATIONS_PARAMETER_TAG       0x0205
145 #define V12_CONCERNED_DESTINATION_PARAMETER_TAG        0x0206
146 #define V12_ROUTING_KEY_PARAMETER_TAG                  0x0207
147 #define V12_REGISTRATION_RESULT_PARAMETER_TAG          0x0208
148 #define V12_DEREGISTRATION_RESULT_PARAMETER_TAG        0x0209
149 #define V12_LOCAL_ROUTING_KEY_IDENTIFIER_PARAMETER_TAG 0x020a
150 #define V12_DESTINATION_POINT_CODE_PARAMETER_TAG       0x020b
151 #define V12_SERVICE_INDICATORS_PARAMETER_TAG           0x020c
152 #define V12_ORIGINATING_POINT_CODE_LIST_PARAMETER_TAG  0x020e
153 #define V12_CIRCUIT_RANGE_PARAMETER_TAG                0x020f
154 #define V12_PROTOCOL_DATA_PARAMETER_TAG                0x0210
155 #define V12_REGISTRATION_STATUS_PARAMETER_TAG          0x0212
156 #define V12_DEREGISTRATION_STATUS_PARAMETER_TAG        0x0213
157
158 static const value_string m3ua_v12_parameter_tag_values[] = {
159   { V12_INFO_STRING_PARAMETER_TAG,                  "Info string" } ,
160   { V12_ROUTING_CONTEXT_PARAMETER_TAG,              "Routing context" } ,
161   { V12_DIAGNOSTIC_INFORMATION_PARAMETER_TAG,       "Diagnostic Information" } ,
162   { V12_HEARTBEAT_DATA_PARAMETER_TAG,               "Heartbeat data" } ,
163   { V12_TRAFFIC_MODE_TYPE_PARAMETER_TAG,            "Traffic mode type" } ,
164   { V12_ERROR_CODE_PARAMETER_TAG,                   "Error code" } ,
165   { V12_STATUS_PARAMETER_TAG,                       "Status" } ,
166   { V12_ASP_IDENTIFIER_PARAMETER_TAG,               "ASP identifier" } ,
167   { V12_AFFECTED_POINT_CODE_PARAMETER_TAG,          "Affected point code" } ,
168   { V12_CORRELATION_IDENTIFIER_PARAMETER_TAG,       "Correlation identifier" } ,
169   { V12_NETWORK_APPEARANCE_PARAMETER_TAG,           "Network appearance" } ,
170   { V12_USER_CAUSE_PARAMETER_TAG,                   "User / cause" } ,
171   { V12_CONGESTION_INDICATIONS_PARAMETER_TAG,       "Congestion indications" } ,
172   { V12_CONCERNED_DESTINATION_PARAMETER_TAG,        "Concerned destination" } ,
173   { V12_ROUTING_KEY_PARAMETER_TAG,                  "Routing key" } ,
174   { V12_REGISTRATION_RESULT_PARAMETER_TAG,          "Registration result" } ,
175   { V12_DEREGISTRATION_RESULT_PARAMETER_TAG,        "Deregistration result" } ,
176   { V12_LOCAL_ROUTING_KEY_IDENTIFIER_PARAMETER_TAG, "Local routing key identifier" } ,
177   { V12_DESTINATION_POINT_CODE_PARAMETER_TAG,       "Destination point code" } ,
178   { V12_SERVICE_INDICATORS_PARAMETER_TAG,           "Service indicators" } ,
179   { V12_ORIGINATING_POINT_CODE_LIST_PARAMETER_TAG,  "Originating point code list" } ,
180   { V12_CIRCUIT_RANGE_PARAMETER_TAG,                "Circuit range" } ,
181   { V12_PROTOCOL_DATA_PARAMETER_TAG,                "Protocol data" } ,
182   { V12_REGISTRATION_STATUS_PARAMETER_TAG,          "Registration status" } ,
183   { V12_DEREGISTRATION_STATUS_PARAMETER_TAG,        "Deregistration status" } ,
184   { 0,                           NULL } };
185
186 #define PROTOCOL_VERSION_RELEASE_1             1
187
188 static const value_string m3ua_protocol_version_values[] = {
189   { PROTOCOL_VERSION_RELEASE_1,  "Release 1" },
190   { 0,                           NULL } };
191
192 #define MESSAGE_CLASS_MGMT_MESSAGE        0
193 #define MESSAGE_CLASS_TFER_MESSAGE        1
194 #define MESSAGE_CLASS_SSNM_MESSAGE        2
195 #define MESSAGE_CLASS_ASPSM_MESSAGE       3
196 #define MESSAGE_CLASS_ASPTM_MESSAGE       4
197 #define MESSAGE_CLASS_RKM_MESSAGE         9
198
199 static const value_string m3ua_message_class_values[] = {
200   { MESSAGE_CLASS_MGMT_MESSAGE,   "Management messages" },
201   { MESSAGE_CLASS_TFER_MESSAGE,   "Transfer messages" },
202   { MESSAGE_CLASS_SSNM_MESSAGE,   "SS7 signalling network management messages" },
203   { MESSAGE_CLASS_ASPSM_MESSAGE,  "ASP state maintenance messages" },
204   { MESSAGE_CLASS_ASPTM_MESSAGE,  "ASP traffic maintenance messages" },
205   { MESSAGE_CLASS_RKM_MESSAGE,    "Routing key management messages" },
206   { 0,                           NULL } };
207
208 #define MESSAGE_TYPE_ERR                  0
209 #define MESSAGE_TYPE_NTFY                 1
210
211 #define MESSAGE_TYPE_DATA                 1
212
213 #define MESSAGE_TYPE_DUNA                 1
214 #define MESSAGE_TYPE_DAVA                 2
215 #define MESSAGE_TYPE_DAUD                 3
216 #define MESSAGE_TYPE_SCON                 4
217 #define MESSAGE_TYPE_DUPU                 5
218 #define MESSAGE_TYPE_DRST                 6
219
220 #define MESSAGE_TYPE_UP                   1
221 #define MESSAGE_TYPE_DOWN                 2
222 #define MESSAGE_TYPE_BEAT                 3
223 #define MESSAGE_TYPE_UP_ACK               4
224 #define MESSAGE_TYPE_DOWN_ACK             5
225 #define MESSAGE_TYPE_BEAT_ACK             6
226
227 #define MESSAGE_TYPE_ACTIVE               1
228 #define MESSAGE_TYPE_INACTIVE             2
229 #define MESSAGE_TYPE_ACTIVE_ACK           3
230 #define MESSAGE_TYPE_INACTIVE_ACK         4
231
232 #define MESSAGE_TYPE_REG_REQ              1
233 #define MESSAGE_TYPE_REG_RSP              2
234 #define MESSAGE_TYPE_DEREG_REQ            3
235 #define MESSAGE_TYPE_DEREG_RSP            4
236
237
238 static const value_string m3ua_message_class_type_values[] = {
239   { MESSAGE_CLASS_MGMT_MESSAGE  * 256 + MESSAGE_TYPE_ERR,           "Error (ERR)" },
240   { MESSAGE_CLASS_MGMT_MESSAGE  * 256 + MESSAGE_TYPE_NTFY,          "Notify (NTFY)" },
241   { MESSAGE_CLASS_TFER_MESSAGE  * 256 + MESSAGE_TYPE_DATA,          "Payload data (DATA)" },
242   { MESSAGE_CLASS_SSNM_MESSAGE  * 256 + MESSAGE_TYPE_DUNA,          "Destination unavailable (DUNA)" },
243   { MESSAGE_CLASS_SSNM_MESSAGE  * 256 + MESSAGE_TYPE_DAVA,          "Destination available (DAVA)" },
244   { MESSAGE_CLASS_SSNM_MESSAGE  * 256 + MESSAGE_TYPE_DAUD,          "Destination state audit (DAUD)" },
245   { MESSAGE_CLASS_SSNM_MESSAGE  * 256 + MESSAGE_TYPE_SCON,          "SS7 Network congestion state (SCON)" },
246   { MESSAGE_CLASS_SSNM_MESSAGE  * 256 + MESSAGE_TYPE_DUPU,          "Destination userpart unavailable (DUPU)" },
247   { MESSAGE_CLASS_SSNM_MESSAGE  * 256 + MESSAGE_TYPE_DRST,          "Destination Restricted (DRST)" },
248   { MESSAGE_CLASS_ASPSM_MESSAGE * 256 + MESSAGE_TYPE_UP,            "ASP up (UP)" },
249   { MESSAGE_CLASS_ASPSM_MESSAGE * 256 + MESSAGE_TYPE_DOWN,          "ASP down (DOWN)" },
250   { MESSAGE_CLASS_ASPSM_MESSAGE * 256 + MESSAGE_TYPE_BEAT,          "Heartbeat (BEAT)" },
251   { MESSAGE_CLASS_ASPSM_MESSAGE * 256 + MESSAGE_TYPE_UP_ACK,        "ASP up ack (UP ACK)" },
252   { MESSAGE_CLASS_ASPSM_MESSAGE * 256 + MESSAGE_TYPE_DOWN_ACK,      "ASP down ack (DOWN ACK)" },
253   { MESSAGE_CLASS_ASPSM_MESSAGE * 256 + MESSAGE_TYPE_BEAT_ACK,      "Heartbeat ack (BEAT ACK)" },
254   { MESSAGE_CLASS_ASPTM_MESSAGE * 256 + MESSAGE_TYPE_ACTIVE ,       "ASP active (ACTIVE)" },
255   { MESSAGE_CLASS_ASPTM_MESSAGE * 256 + MESSAGE_TYPE_INACTIVE ,     "ASP inactive (INACTIVE)" },
256   { MESSAGE_CLASS_ASPTM_MESSAGE * 256 + MESSAGE_TYPE_ACTIVE_ACK ,   "ASP active ack (ACTIVE ACK)" },
257   { MESSAGE_CLASS_ASPTM_MESSAGE * 256 + MESSAGE_TYPE_INACTIVE_ACK , "ASP inactive ack (INACTIVE ACK)" },
258   { MESSAGE_CLASS_RKM_MESSAGE   * 256 + MESSAGE_TYPE_REG_REQ ,      "Registration request (REG_REQ)" },
259   { MESSAGE_CLASS_RKM_MESSAGE   * 256 + MESSAGE_TYPE_REG_RSP ,      "Registration response (REG_RSP)" },
260   { MESSAGE_CLASS_RKM_MESSAGE   * 256 + MESSAGE_TYPE_DEREG_REQ ,    "Deregistration request (DEREG_REQ)" },
261   { MESSAGE_CLASS_RKM_MESSAGE   * 256 + MESSAGE_TYPE_DEREG_RSP ,    "Deregistration response (DEREG_RSP)" },
262   { 0,                           NULL } };
263
264 static const value_string m3ua_message_class_type_acro_values[] = {
265   { MESSAGE_CLASS_MGMT_MESSAGE  * 256 + MESSAGE_TYPE_ERR,           "ERR" },
266   { MESSAGE_CLASS_MGMT_MESSAGE  * 256 + MESSAGE_TYPE_NTFY,          "NTFY" },
267   { MESSAGE_CLASS_TFER_MESSAGE  * 256 + MESSAGE_TYPE_DATA,          "DATA" },
268   { MESSAGE_CLASS_SSNM_MESSAGE  * 256 + MESSAGE_TYPE_DUNA,          "DUNA" },
269   { MESSAGE_CLASS_SSNM_MESSAGE  * 256 + MESSAGE_TYPE_DAVA,          "DAVA" },
270   { MESSAGE_CLASS_SSNM_MESSAGE  * 256 + MESSAGE_TYPE_DAUD,          "DAUD" },
271   { MESSAGE_CLASS_SSNM_MESSAGE  * 256 + MESSAGE_TYPE_SCON,          "SCON" },
272   { MESSAGE_CLASS_SSNM_MESSAGE  * 256 + MESSAGE_TYPE_DUPU,          "DUPU" },
273   { MESSAGE_CLASS_SSNM_MESSAGE  * 256 + MESSAGE_TYPE_DRST,          "DRST" },
274   { MESSAGE_CLASS_ASPSM_MESSAGE * 256 + MESSAGE_TYPE_UP,            "ASP_UP" },
275   { MESSAGE_CLASS_ASPSM_MESSAGE * 256 + MESSAGE_TYPE_DOWN,          "ASP_DOWN" },
276   { MESSAGE_CLASS_ASPSM_MESSAGE * 256 + MESSAGE_TYPE_BEAT,          "BEAT" },
277   { MESSAGE_CLASS_ASPSM_MESSAGE * 256 + MESSAGE_TYPE_UP_ACK,        "ASP_UP_ACK" },
278   { MESSAGE_CLASS_ASPSM_MESSAGE * 256 + MESSAGE_TYPE_DOWN_ACK,      "ASP_DOWN_ACK" },
279   { MESSAGE_CLASS_ASPSM_MESSAGE * 256 + MESSAGE_TYPE_BEAT_ACK,      "BEAT_ACK" },
280   { MESSAGE_CLASS_ASPTM_MESSAGE * 256 + MESSAGE_TYPE_ACTIVE ,       "ASP_ACTIVE" },
281   { MESSAGE_CLASS_ASPTM_MESSAGE * 256 + MESSAGE_TYPE_INACTIVE ,     "ASP_INACTIVE" },
282   { MESSAGE_CLASS_ASPTM_MESSAGE * 256 + MESSAGE_TYPE_ACTIVE_ACK ,   "ASP_ACTIVE_ACK" },
283   { MESSAGE_CLASS_ASPTM_MESSAGE * 256 + MESSAGE_TYPE_INACTIVE_ACK , "ASP_INACTIVE_ACK" },
284   { MESSAGE_CLASS_RKM_MESSAGE   * 256 + MESSAGE_TYPE_REG_REQ ,      "REG_REQ" },
285   { MESSAGE_CLASS_RKM_MESSAGE   * 256 + MESSAGE_TYPE_REG_RSP ,      "REG_RSP" },
286   { MESSAGE_CLASS_RKM_MESSAGE   * 256 + MESSAGE_TYPE_DEREG_REQ ,    "DEREG_REQ" },
287   { MESSAGE_CLASS_RKM_MESSAGE   * 256 + MESSAGE_TYPE_DEREG_RSP ,    "DEREG_RSP" },
288   { 0,                           NULL } };
289
290
291
292
293
294 #define PROTOCOL_DATA_OFFSET PARAMETER_VALUE_OFFSET
295
296
297 #define UNSPECIFIED_REASON          0
298 #define USER_UNAVAILABLE_REASON     1
299 #define MANAGEMENT_BLOCKING_REASON  2
300
301 static const value_string m3ua_reason_values[] = {
302   { UNSPECIFIED_REASON,                             "Unspecified" },
303   { USER_UNAVAILABLE_REASON,                        "User unavailable" },
304   { MANAGEMENT_BLOCKING_REASON,                     "Management blocking" },
305   {0,                           NULL } };
306
307 #define REASON_LENGTH 4
308 #define REASON_OFFSET PARAMETER_VALUE_OFFSET
309
310 #define TRAFFIC_MODE_TYPE_LENGTH 4
311 #define TRAFFIC_MODE_TYPE_OFFSET PARAMETER_VALUE_OFFSET
312
313 /* Initialize the protocol and registered fields */
314 static int proto_m3ua = -1;
315 static int hf_m3ua_version = -1;
316 static int hf_m3ua_reserved = -1;
317 static int hf_m3ua_message_class = -1;
318 static int hf_m3ua_message_type = -1;
319 static int hf_m3ua_message_length = -1;
320 static int hf_m3ua_parameter_tag = -1;
321 static int hf_m3ua_parameter_length = -1;
322 static int hf_m3ua_parameter_value = -1;
323 static int hf_m3ua_parameter_padding = -1;
324 static int hf_m3ua_network_appearance = -1;
325 static int hf_m3ua_info_string = -1;
326 static int hf_m3ua_routing_context = -1;
327 static int hf_m3ua_diagnostic_information = -1;
328 static int hf_m3ua_heartbeat_data = -1;
329 static int hf_m3ua_error_code = -1;
330 static int hf_m3ua_status_type = -1;
331 static int hf_m3ua_status_info = -1;
332 static int hf_m3ua_asp_identifier = -1;
333 static int hf_m3ua_affected_point_code_mask = -1;
334 static int hf_m3ua_affected_point_code_pc = -1;
335 static int hf_m3ua_unavailability_cause = -1;
336 static int hf_m3ua_user_identity = -1;
337 static int hf_m3ua_reason = -1;
338 static int hf_m3ua_traffic_mode_type = -1;
339 static int hf_m3ua_congestion_reserved = -1;
340 static int hf_m3ua_congestion_level = -1;
341 static int hf_m3ua_concerned_dest_reserved = -1;
342 static int hf_m3ua_concerned_dest_pc = -1;
343 static int hf_m3ua_local_rk_identifier = -1;
344 static int hf_m3ua_dpc_mask = -1;
345 static int hf_m3ua_dpc_pc = -1;
346 static int hf_m3ua_si = -1;
347 static int hf_m3ua_ssn = -1;
348 static int hf_m3ua_opc_list_mask = -1;
349 static int hf_m3ua_opc_list_pc = -1;
350 static int hf_m3ua_cic_range_mask = -1;
351 static int hf_m3ua_cic_range_pc = -1;
352 static int hf_m3ua_cic_range_upper = -1;
353 static int hf_m3ua_cic_range_lower = -1;
354 static int hf_m3ua_protocol_data_opc = -1;
355 static int hf_m3ua_protocol_data_dpc = -1;
356 static int hf_m3ua_protocol_data_si = -1;
357 static int hf_m3ua_protocol_data_ni = -1;
358 static int hf_m3ua_protocol_data_mp = -1;
359 static int hf_m3ua_protocol_data_sls = -1;
360 static int hf_m3ua_correlation_identifier = -1;
361 static int hf_m3ua_registration_status = -1;
362 static int hf_m3ua_deregistration_status = -1;
363 static int hf_m3ua_registration_result_identifier = -1;
364 static int hf_m3ua_registration_result_status = -1;
365 static int hf_m3ua_registration_result_context = -1;
366 static int hf_m3ua_deregistration_result_status = -1;
367 static int hf_m3ua_deregistration_result_context = -1;
368 static int hf_m3ua_li = -1;
369
370 /* Initialize the subtree pointers */
371 static gint ett_m3ua = -1;
372 static gint ett_m3ua_parameter = -1;
373
374 static module_t *m3ua_module;
375 static dissector_handle_t mtp3_handle, data_handle;
376 static dissector_table_t m3ua_si_dissector_table;
377
378 /* stuff for supporting multiple versions */
379 #define M3UA_V6            1
380 #define M3UA_V12           2
381 static gint m3ua_version = M3UA_V12;
382
383 static void
384 dissect_m3ua_parameters(tvbuff_t *, packet_info *, proto_tree *, proto_tree *);
385
386 static guint 
387 nr_of_padding_bytes (guint length)
388 {
389   guint remainder;
390
391   remainder = length % 4;
392
393   if (remainder == 0)
394     return 0;
395   else
396     return 4 - remainder;
397 }
398
399 static void
400 dissect_m3ua_common_header(tvbuff_t *common_header_tvb, packet_info *pinfo, proto_tree *m3ua_tree)
401 {
402   guint8  version, reserved, message_class, message_type;
403   guint32 message_length;
404   
405   /* Extract the common header */
406   version        = tvb_get_guint8(common_header_tvb, VERSION_OFFSET);
407   reserved       = tvb_get_guint8(common_header_tvb, RESERVED_OFFSET);
408   message_class  = tvb_get_guint8(common_header_tvb, MESSAGE_CLASS_OFFSET);
409   message_type   = tvb_get_guint8(common_header_tvb, MESSAGE_TYPE_OFFSET);
410   message_length = tvb_get_ntohl (common_header_tvb, MESSAGE_LENGTH_OFFSET);
411
412   if (check_col(pinfo->cinfo, COL_INFO)) {
413     col_append_str(pinfo->cinfo, COL_INFO, val_to_str(message_class * 256 + message_type, m3ua_message_class_type_acro_values, "reserved"));
414     col_append_str(pinfo->cinfo, COL_INFO, " ");
415   }
416
417   if (m3ua_tree) {
418     /* add the components of the common header to the protocol tree */
419     proto_tree_add_uint(m3ua_tree, hf_m3ua_version, common_header_tvb, VERSION_OFFSET, VERSION_LENGTH, version);
420     proto_tree_add_uint(m3ua_tree, hf_m3ua_reserved, common_header_tvb, RESERVED_OFFSET, RESERVED_LENGTH, reserved);
421     proto_tree_add_uint(m3ua_tree, hf_m3ua_message_class, common_header_tvb, MESSAGE_CLASS_OFFSET, MESSAGE_CLASS_LENGTH, message_class);
422     proto_tree_add_uint_format(m3ua_tree, hf_m3ua_message_type, common_header_tvb, MESSAGE_TYPE_OFFSET, MESSAGE_TYPE_LENGTH, message_type,
423                                "Message type: %s (%u)", 
424                                val_to_str(message_class * 256 + message_type, m3ua_message_class_type_values, "reserved"), message_type);
425     proto_tree_add_uint(m3ua_tree, hf_m3ua_message_length, common_header_tvb, MESSAGE_LENGTH_OFFSET, MESSAGE_LENGTH_LENGTH, message_length);
426   }
427 }
428
429 #define INFO_STRING_OFFSET PARAMETER_VALUE_OFFSET
430
431 static void
432 dissect_m3ua_info_string_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
433 {
434   guint16 length, info_string_length;
435   char *info_string;
436
437   length = tvb_get_ntohs(parameter_tvb, PARAMETER_LENGTH_OFFSET);
438   
439   info_string_length = length - PARAMETER_HEADER_LENGTH;
440   info_string = (char *)tvb_get_ptr(parameter_tvb, INFO_STRING_OFFSET, info_string_length);
441   proto_tree_add_string(parameter_tree, hf_m3ua_info_string, parameter_tvb, INFO_STRING_OFFSET, info_string_length, info_string);
442   proto_item_set_text(parameter_item, "Info String (%.*s)", info_string_length, info_string);
443 }
444
445 #define ROUTING_CONTEXT_LENGTH 4
446
447 static void
448 dissect_m3ua_routing_context_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
449 {
450   guint16 length, number_of_contexts, context_number;
451   guint32 context;
452   gint context_offset;
453
454   length = tvb_get_ntohs(parameter_tvb, PARAMETER_LENGTH_OFFSET);
455   number_of_contexts = (length - PARAMETER_HEADER_LENGTH) / 4;
456   context_offset = PARAMETER_VALUE_OFFSET;
457   for(context_number=1; context_number <= number_of_contexts; context_number++) {
458     context = tvb_get_ntohl(parameter_tvb, context_offset);
459     proto_tree_add_uint(parameter_tree, hf_m3ua_routing_context, parameter_tvb, context_offset, ROUTING_CONTEXT_LENGTH, context);
460     context_offset += ROUTING_CONTEXT_LENGTH;
461   }
462   proto_item_set_text(parameter_item, "Routing context parameter (%u context%s)", number_of_contexts, plurality(number_of_contexts, "", "s"));
463 }
464
465 static void
466 dissect_m3ua_diagnostic_information_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
467 {
468   guint16 length, diagnostic_info_length;
469   
470   length = tvb_get_ntohs(parameter_tvb, PARAMETER_LENGTH_OFFSET);
471   diagnostic_info_length = length - PARAMETER_HEADER_LENGTH;
472
473   proto_tree_add_bytes(parameter_tree, hf_m3ua_diagnostic_information, parameter_tvb, PARAMETER_VALUE_OFFSET, diagnostic_info_length,
474                                    tvb_get_ptr(parameter_tvb, PARAMETER_VALUE_OFFSET, diagnostic_info_length));
475
476   proto_item_set_text(parameter_item, "Diagnostic information (%u byte%s)", diagnostic_info_length, plurality(diagnostic_info_length, "", "s"));
477 }
478
479 static void
480 dissect_m3ua_heartbeat_data_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
481 {
482   guint16 length, heartbeat_data_length;
483   
484   length = tvb_get_ntohs(parameter_tvb, PARAMETER_LENGTH_OFFSET);
485   
486   heartbeat_data_length = length - PARAMETER_HEADER_LENGTH;
487
488   proto_tree_add_bytes(parameter_tree, hf_m3ua_heartbeat_data, parameter_tvb, PARAMETER_VALUE_OFFSET, heartbeat_data_length,
489                                    tvb_get_ptr(parameter_tvb, PARAMETER_VALUE_OFFSET, heartbeat_data_length));
490
491   proto_item_set_text(parameter_item, "Heartbeat data (%u byte%s)", heartbeat_data_length, plurality(heartbeat_data_length, "", "s"));
492 }
493
494 #define OVER_RIDE_TYPE           1
495 #define LOAD_SHARE_TYPE          2
496 #define OVER_RIDE_STANDBY_TYPE   3
497 #define LOAD_SHARE_STANDBY_TYPE  4
498
499 static const value_string m3ua_v6_traffic_mode_type_values[] = {
500   { OVER_RIDE_TYPE ,                             "Over-ride" },
501   { LOAD_SHARE_TYPE,                             "Load-share" },
502   { OVER_RIDE_STANDBY_TYPE,                      "Over-ride (standby)" },
503   { LOAD_SHARE_STANDBY_TYPE,                     "Load-share (standby)" },
504   {0,                           NULL } };
505
506 static void
507 dissect_m3ua_v6_traffic_mode_type_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
508 {
509   guint32 traffic_mode_type;
510
511   traffic_mode_type = tvb_get_ntohl(parameter_tvb, TRAFFIC_MODE_TYPE_OFFSET);
512
513   proto_tree_add_uint_format(parameter_tree, hf_m3ua_traffic_mode_type, parameter_tvb, TRAFFIC_MODE_TYPE_OFFSET, TRAFFIC_MODE_TYPE_LENGTH, traffic_mode_type,
514                              "Traffic mode type: %u (%s)", traffic_mode_type, val_to_str(traffic_mode_type, m3ua_v6_traffic_mode_type_values, "unknown"));
515   proto_item_set_text(parameter_item, "Traffic mode type parameter (%s)", val_to_str(traffic_mode_type, m3ua_v6_traffic_mode_type_values, "unknown"));
516 }
517
518 #define BROADCAST_TYPE   3
519
520 static const value_string m3ua_v12_traffic_mode_type_values[] = {
521   { OVER_RIDE_TYPE ,                             "Over-ride" },
522   { LOAD_SHARE_TYPE,                             "Load-share" },
523   { BROADCAST_TYPE,                              "Broadcast" },
524   {0,                           NULL } };
525
526 static void
527 dissect_m3ua_v12_traffic_mode_type_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
528 {
529   guint32 traffic_mode_type;
530
531   traffic_mode_type = tvb_get_ntohl(parameter_tvb, TRAFFIC_MODE_TYPE_OFFSET);
532
533   proto_tree_add_uint_format(parameter_tree, hf_m3ua_traffic_mode_type, 
534                                                parameter_tvb, TRAFFIC_MODE_TYPE_OFFSET, TRAFFIC_MODE_TYPE_LENGTH,
535                                                traffic_mode_type, "Traffic mode type: %u (%s)",
536                                                traffic_mode_type, val_to_str(traffic_mode_type, m3ua_v12_traffic_mode_type_values, "unknown"));
537   proto_item_set_text(parameter_item, "Traffic mode type parameter (%s)", val_to_str(traffic_mode_type, m3ua_v12_traffic_mode_type_values, "unknown"));
538 }
539
540 #define V6_INVALID_VERSION_ERROR_CODE               1
541 #define V6_INVALID_NETWORK_APPEARANCE_ERROR_CODE    2
542 #define V6_UNSUPPORTED_MESSAGE_CLASS_ERROR_CODE     3
543 #define V6_UNSUPPORTED_MESSAGE_TYPE_ERROR_CODE      4
544 #define V6_INVALID_TRAFFIC_HANDLING_MODE_ERROR_CODE 5
545 #define V6_UNEXPECTED_MESSAGE_ERROR_CODE            6
546 #define V6_PROTOCOL_ERROR_ERROR_CODE                7
547 #define V6_INVALID_ROUTING_CONTEXT_ERROR_CODE       8
548 #define V6_INVALID_STREAM_IDENTIFIER_ERROR_CODE     9
549 #define V6_INVALID_PARAMETER_VALUE_ERROR_CODE      10
550
551 static const value_string m3ua_v6_error_code_values[] = {
552   { V6_INVALID_VERSION_ERROR_CODE,               "Invalid version" },
553   { V6_INVALID_NETWORK_APPEARANCE_ERROR_CODE,    "Invalid network appearance" },
554   { V6_UNSUPPORTED_MESSAGE_CLASS_ERROR_CODE,     "Unsupported message class" },
555   { V6_UNSUPPORTED_MESSAGE_TYPE_ERROR_CODE,      "Unsupported message type" },
556   { V6_INVALID_TRAFFIC_HANDLING_MODE_ERROR_CODE, "Invalid traffic handling mode" },
557   { V6_UNEXPECTED_MESSAGE_ERROR_CODE,            "Unexpected message" },
558   { V6_PROTOCOL_ERROR_ERROR_CODE,                "Protocol error" },
559   { V6_INVALID_ROUTING_CONTEXT_ERROR_CODE,       "Invalid routing context" },
560   { V6_INVALID_STREAM_IDENTIFIER_ERROR_CODE,     "Invalid stream identifier" },
561   { V6_INVALID_PARAMETER_VALUE_ERROR_CODE,       "Invalid parameter value" },
562   { 0,                           NULL } };
563
564 #define ERROR_CODE_LENGTH 4
565 #define ERROR_CODE_OFFSET PARAMETER_VALUE_OFFSET
566
567 static void
568 dissect_m3ua_v6_error_code_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
569 {
570   guint32 error_code;
571
572   error_code = tvb_get_ntohl(parameter_tvb, ERROR_CODE_OFFSET);
573   proto_tree_add_uint_format(parameter_tree, hf_m3ua_error_code, parameter_tvb, ERROR_CODE_OFFSET, ERROR_CODE_LENGTH, error_code,
574                              "Error code: %u (%s)", error_code, val_to_str(error_code, m3ua_v6_error_code_values, "unknown"));
575   proto_item_set_text(parameter_item, "Error code parameter (%s)", val_to_str(error_code, m3ua_v6_error_code_values, "unknown"));
576 }
577
578
579 #define V12_INVALID_VERSION_ERROR_CODE                   0x01
580 #define V12_UNSUPPORTED_MESSAGE_CLASS_ERROR_CODE         0x03
581 #define V12_UNSUPPORTED_MESSAGE_TYPE_ERROR_CODE          0x04
582 #define V12_UNSUPPORTED_TRAFFIC_HANDLING_MODE_ERROR_CODE 0x05
583 #define V12_UNEXPECTED_MESSAGE_ERROR_CODE                0x06
584 #define V12_PROTOCOL_ERROR_ERROR_CODE                    0x07
585 #define V12_INVALID_STREAM_IDENTIFIER_ERROR_CODE         0x09
586 #define V12_REFUSED_ERROR_CODE                           0x0d
587 #define V12_ASP_IDENTIFIER_REQUIRED_ERROR_CODE           0x0e
588 #define V12_INVALID_ASP_IDENTIFIER_ERROR_CODE            0x0f
589 #define V12_INVALID_PARAMETER_VALUE_ERROR_CODE           0x11
590 #define V12_PARAMETER_FIELD_ERROR_CODE                   0x12
591 #define V12_UNEXPECTED_PARAMETER_ERROR_CODE              0x13
592 #define V12_DESTINATION_STATUS_UNKNOWN_ERROR_CODE        0x14
593 #define V12_INVALID_NETWORK_APPEARANCE_ERROR_CODE        0x15
594 #define V12_MISSING_PARAMETER_ERROR_CODE                 0x16
595 #define V12_INVALID_ROUTING_CONTEXT_ERROR_CODE           0x19
596 #define V12_NO_CONFIGURED_AS_FOR_ASP_ERROR_CODE          0x1a
597
598 static const value_string m3ua_v12_error_code_values[] = {
599   { V12_INVALID_VERSION_ERROR_CODE,                   "Invalid version" },
600   { V12_UNSUPPORTED_MESSAGE_CLASS_ERROR_CODE,         "Unsupported message class" },
601   { V12_UNSUPPORTED_MESSAGE_TYPE_ERROR_CODE,          "Unsupported message type" },
602   { V12_UNSUPPORTED_TRAFFIC_HANDLING_MODE_ERROR_CODE, "Unsupported traffic handling mode" },
603   { V12_UNEXPECTED_MESSAGE_ERROR_CODE,                "Unexpected message" },
604   { V12_PROTOCOL_ERROR_ERROR_CODE,                    "Protocol error" },
605   { V12_INVALID_STREAM_IDENTIFIER_ERROR_CODE,         "Invalid stream identifier" },
606   { V12_REFUSED_ERROR_CODE,                           "Refused - management blocking" },
607   { V12_ASP_IDENTIFIER_REQUIRED_ERROR_CODE,           "ASP identifier required" },
608   { V12_INVALID_ASP_IDENTIFIER_ERROR_CODE,            "Invalid ASP identifier" },
609   { V12_INVALID_PARAMETER_VALUE_ERROR_CODE,           "Invalid parameter value" },
610   { V12_PARAMETER_FIELD_ERROR_CODE,                   "Parameter field error" },
611   { V12_UNEXPECTED_PARAMETER_ERROR_CODE,              "Unexpected parameter" },
612   { V12_DESTINATION_STATUS_UNKNOWN_ERROR_CODE,        "Destination status unknown" },
613   { V12_INVALID_NETWORK_APPEARANCE_ERROR_CODE,        "Invalid network appearance" },
614   { V12_MISSING_PARAMETER_ERROR_CODE,                 "Missing parameter" },
615   { V12_INVALID_ROUTING_CONTEXT_ERROR_CODE,           "Invalid routing context" },
616   { V12_NO_CONFIGURED_AS_FOR_ASP_ERROR_CODE,          "No configured AS for ASP" },
617   { 0,                                            NULL } };
618
619 static void
620 dissect_m3ua_v12_error_code_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
621 {
622   guint32 error_code;
623
624   error_code = tvb_get_ntohl(parameter_tvb, ERROR_CODE_OFFSET);
625   proto_tree_add_uint_format(parameter_tree, hf_m3ua_error_code, parameter_tvb, ERROR_CODE_OFFSET, ERROR_CODE_LENGTH, error_code,
626                              "Error code: %u (%s)",error_code, val_to_str(error_code, m3ua_v12_error_code_values, "unknown"));
627   proto_item_set_text(parameter_item, "Error code parameter (%s)", val_to_str(error_code, m3ua_v12_error_code_values, "unknown"));
628 }
629
630 #define AS_STATE_CHANGE_TYPE       1
631 #define OTHER_TYPE                 2
632
633 static const value_string m3ua_status_type_values[] = {
634   { AS_STATE_CHANGE_TYPE,            "Application server state change" },
635   { OTHER_TYPE,                      "Other" },
636   { 0,                           NULL } };
637
638 #define RESERVED_INFO              1
639 #define AS_INACTIVE_INFO           2
640 #define AS_ACTIVE_INFO             3
641 #define AS_PENDING_INFO            4
642
643 #define INSUFFICIENT_ASP_RES_INFO  1
644 #define ALTERNATE_ASP_ACTIVE_INFO  2
645 #define ASP_FAILURE_INFO           3
646
647 static const value_string m3ua_status_type_info_values[] = {
648   { AS_STATE_CHANGE_TYPE * 256 * 256 + RESERVED_INFO,             "Reserved" },
649   { AS_STATE_CHANGE_TYPE * 256 * 256 + AS_INACTIVE_INFO,          "Application server inactive" },
650   { AS_STATE_CHANGE_TYPE * 256 * 256 + AS_ACTIVE_INFO,            "Application server active" },
651   { AS_STATE_CHANGE_TYPE * 256 * 256 + AS_PENDING_INFO,           "Application server pending" },
652   { OTHER_TYPE           * 256 * 256 + INSUFFICIENT_ASP_RES_INFO, "Insufficient ASP resources active in AS" },
653   { OTHER_TYPE           * 256 * 256 + ALTERNATE_ASP_ACTIVE_INFO, "Alternate ASP active" },
654   { OTHER_TYPE           * 256 * 256 + ASP_FAILURE_INFO,          "ASP Failure" },
655   {0,                           NULL } };
656
657 #define STATUS_TYPE_LENGTH 2
658 #define STATUS_INFO_LENGTH 2
659
660 #define STATUS_TYPE_OFFSET PARAMETER_VALUE_OFFSET
661 #define STATUS_INFO_OFFSET (STATUS_TYPE_OFFSET + STATUS_TYPE_LENGTH)
662
663 static void
664 dissect_m3ua_status_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
665 {
666   guint16 status_type, status_info;
667
668   status_type = tvb_get_ntohs(parameter_tvb, STATUS_TYPE_OFFSET);
669   status_info = tvb_get_ntohs(parameter_tvb, STATUS_INFO_OFFSET);
670
671   proto_tree_add_uint(parameter_tree, hf_m3ua_status_type, parameter_tvb, STATUS_TYPE_OFFSET, STATUS_TYPE_LENGTH, status_type);
672   proto_tree_add_uint_format(parameter_tree, hf_m3ua_status_info, parameter_tvb, STATUS_INFO_OFFSET, STATUS_INFO_LENGTH, status_info,
673                              "Status info: %s (%u)", val_to_str(status_type * 256 * 256 + status_info, m3ua_status_type_info_values, "unknown"), status_info);
674
675   proto_item_set_text(parameter_item, 
676                       "Status type / ID (%s)", val_to_str(status_type * 256 * 256 + status_info, m3ua_status_type_info_values, "unknown status information"));
677 }
678
679 #define ASP_IDENTIFIER_OFFSET PARAMETER_VALUE_OFFSET
680 #define ASP_IDENTIFIER_LENGTH  4
681
682 static void
683 dissect_m3ua_asp_identifier_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
684 {
685   guint32 identifier;
686   
687   identifier = tvb_get_ntohl(parameter_tvb, ASP_IDENTIFIER_OFFSET);
688   proto_tree_add_uint(parameter_tree, hf_m3ua_asp_identifier, parameter_tvb, ASP_IDENTIFIER_OFFSET, ASP_IDENTIFIER_LENGTH, identifier);
689   proto_item_set_text(parameter_item, "ASP identifier (%u)", identifier);
690 }
691
692 #define AFFECTED_MASK_LENGTH       1
693 #define AFFECTED_PC_LENGTH         3
694 #define AFFECTED_POINT_CODE_LENGTH (AFFECTED_MASK_LENGTH + AFFECTED_PC_LENGTH)
695
696 #define AFFECTED_MASK_OFFSET        0
697 #define AFFECTED_PC_OFFSET         (AFFECTED_MASK_OFFSET + AFFECTED_MASK_LENGTH)
698
699 static void
700 dissect_m3ua_affected_point_code_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
701 {
702   guint8  mask;
703   guint16 length, number_of_point_codes, point_code_number;
704   guint32 pc;
705   gint point_code_offset;
706
707   length                = tvb_get_ntohs(parameter_tvb, PARAMETER_LENGTH_OFFSET);
708   number_of_point_codes = (length - PARAMETER_HEADER_LENGTH) / AFFECTED_POINT_CODE_LENGTH;
709
710   point_code_offset = PARAMETER_VALUE_OFFSET;
711   for(point_code_number=1; point_code_number <= number_of_point_codes; point_code_number++) {
712     mask = tvb_get_guint8(parameter_tvb, point_code_offset + AFFECTED_MASK_OFFSET);
713     pc   = tvb_get_ntoh24(parameter_tvb, point_code_offset + AFFECTED_PC_OFFSET);
714     proto_tree_add_uint(parameter_tree, hf_m3ua_affected_point_code_mask, parameter_tvb, point_code_offset + AFFECTED_MASK_OFFSET, AFFECTED_MASK_LENGTH, mask);
715     proto_tree_add_uint(parameter_tree, hf_m3ua_affected_point_code_pc, parameter_tvb, point_code_offset + AFFECTED_PC_OFFSET, AFFECTED_PC_LENGTH, pc);
716     point_code_offset += AFFECTED_POINT_CODE_LENGTH;
717   };
718   proto_item_set_text(parameter_item, "Affected point code parameter (%u point code%s)", number_of_point_codes, plurality(number_of_point_codes, "", "s"));
719
720 }
721
722 #define NETWORK_APPEARANCE_LENGTH 4
723 #define NETWORK_APPEARANCE_OFFSET PARAMETER_VALUE_OFFSET
724
725 static void
726 dissect_m3ua_network_appearance_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
727 {
728   guint32 network_appearance;
729
730   network_appearance = tvb_get_ntohl(parameter_tvb, NETWORK_APPEARANCE_OFFSET);
731   proto_tree_add_uint(parameter_tree, hf_m3ua_network_appearance, parameter_tvb, NETWORK_APPEARANCE_OFFSET, NETWORK_APPEARANCE_LENGTH, network_appearance);
732   proto_item_set_text(parameter_item, "Network appearance: %u", network_appearance);
733 }
734
735 #define UNKNOWN_UNAVAIL_CAUSE                  0
736 #define UNEQUIPPED_REMOTE_USER_UNAVAIL_CAUSE   1
737 #define INACCESSABLE_REMOTE_USER_UNAVAIL_CAUSE 2
738
739 static const value_string m3ua_unavailability_cause_values[] = {
740   { UNKNOWN_UNAVAIL_CAUSE,                             "Unknown" },
741   { UNEQUIPPED_REMOTE_USER_UNAVAIL_CAUSE,              "Unequipped remote user" },
742   { INACCESSABLE_REMOTE_USER_UNAVAIL_CAUSE,            "Inaccessable remote user" },
743   {0,                           NULL } };
744
745 #define RESERVED_0_USER_ID                0
746 #define RESERVED_1_USER_ID                1
747 #define RESERVED_2_USER_ID                2
748 #define SCCP_USER_ID                      3
749 #define TUP_USER_ID                       4
750 #define ISUP_USER_ID                      5
751 #define RESERVED_6_USER_ID                6
752 #define RESERVED_7_USER_ID                7
753 #define RESERVED_8_USER_ID                8
754 #define BROADBAND_ISUP_USER_ID            9
755 #define SATELLITE_ISUP_USER_ID           10
756
757 static const value_string m3ua_user_identity_values[] = {
758   { RESERVED_0_USER_ID,                             "Reserved" },
759   { RESERVED_1_USER_ID,                             "Reserved" },
760   { RESERVED_2_USER_ID,                             "Reserved" },
761   { SCCP_USER_ID,                                   "SCCP" },
762   { TUP_USER_ID,                                    "TUP" },
763   { ISUP_USER_ID,                                   "ISUP" },
764   { RESERVED_6_USER_ID,                             "Reserved" },
765   { RESERVED_7_USER_ID,                             "Reserved" },
766   { RESERVED_8_USER_ID,                             "Reserved" },
767   { BROADBAND_ISUP_USER_ID,                         "Broadband ISUP" },
768   { SATELLITE_ISUP_USER_ID,                         "Satellite ISUP" },
769   {0,                           NULL } };
770
771 #define CAUSE_LENGTH 2
772 #define USER_LENGTH  2
773
774 #define CAUSE_OFFSET  PARAMETER_VALUE_OFFSET
775 #define USER_OFFSET   (CAUSE_OFFSET + CAUSE_LENGTH)
776
777 static void
778 dissect_m3ua_user_cause_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
779 {
780   guint16 cause, user;
781
782   cause = tvb_get_ntohs(parameter_tvb, CAUSE_OFFSET);
783   user  = tvb_get_ntohs(parameter_tvb, USER_OFFSET);
784
785   proto_tree_add_uint(parameter_tree, hf_m3ua_unavailability_cause, parameter_tvb, CAUSE_OFFSET, CAUSE_LENGTH, cause);
786   proto_tree_add_uint(parameter_tree, hf_m3ua_user_identity, parameter_tvb, USER_OFFSET, USER_LENGTH, user);
787   proto_item_set_text(parameter_item, "User / Cause parameter (%s: %s)",
788                                   val_to_str(user, m3ua_user_identity_values, "Unknown user"),
789                       val_to_str(cause, m3ua_unavailability_cause_values, "unknown cause"));
790 }
791
792 static void
793 dissect_m3ua_protocol_data_1_parameter(tvbuff_t *parameter_tvb, packet_info *pinfo, proto_tree *tree, proto_item *parameter_item)
794 {
795   guint16 length, protocol_data_length;
796   tvbuff_t *payload_tvb;
797
798   length = tvb_get_ntohs(parameter_tvb, PARAMETER_LENGTH_OFFSET);
799   protocol_data_length = length - PARAMETER_HEADER_LENGTH;
800   payload_tvb          = tvb_new_subset(parameter_tvb, PROTOCOL_DATA_OFFSET, protocol_data_length, protocol_data_length);
801   proto_item_set_text(parameter_item, "Protocol data (SS7 message of %u byte%s)", protocol_data_length, plurality(protocol_data_length, "", "s"));
802   proto_item_set_len(parameter_item, PARAMETER_HEADER_LENGTH);
803   call_dissector(mtp3_handle, payload_tvb, pinfo, tree);
804
805 }
806
807 #define LI_OCTETT_LENGTH 1
808 #define LI_OCTETT_OFFSET PARAMETER_VALUE_OFFSET
809
810 static void
811 dissect_m3ua_protocol_data_2_parameter(tvbuff_t *parameter_tvb, packet_info *pinfo, proto_tree *tree, proto_tree *parameter_tree, proto_item *parameter_item)
812 {
813   guint8 li;
814   guint16 length, protocol_data_length;
815   tvbuff_t *payload_tvb;
816
817   length               = tvb_get_ntohs(parameter_tvb, PARAMETER_LENGTH_OFFSET);
818   li                   = tvb_get_guint8(parameter_tvb, LI_OCTETT_OFFSET);
819   protocol_data_length = length - PARAMETER_HEADER_LENGTH - LI_OCTETT_LENGTH;
820   payload_tvb          = tvb_new_subset(parameter_tvb, PROTOCOL_DATA_OFFSET + LI_OCTETT_LENGTH, protocol_data_length, protocol_data_length);
821   proto_tree_add_uint(parameter_tree, hf_m3ua_li, parameter_tvb, LI_OCTETT_OFFSET, LI_OCTETT_LENGTH, li);
822   proto_item_set_text(parameter_item, "Protocol data (SS7 message of %u byte%s)", protocol_data_length, plurality(protocol_data_length, "", "s"));
823   proto_item_set_len(parameter_item, PARAMETER_HEADER_LENGTH + LI_OCTETT_LENGTH);
824   call_dissector(mtp3_handle, payload_tvb, pinfo, tree);
825 }
826
827 static void
828 dissect_m3ua_reason_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
829 {
830   guint32 reason;
831
832   reason = tvb_get_ntohl(parameter_tvb, REASON_OFFSET);
833
834   proto_tree_add_uint(parameter_tree, hf_m3ua_reason, parameter_tvb, REASON_OFFSET, REASON_LENGTH, reason);
835   proto_item_set_text(parameter_item, "Reason parameter (%s)", val_to_str(reason, m3ua_reason_values, "unknown"));
836 }
837
838 #define NO_CONGESTION_LEVEL         0
839 #define CONGESTION_LEVEL_1_LEVEL    1
840 #define CONGESTION_LEVEL_2_LEVEL    2
841 #define CONGESTION_LEVEL_3_LEVEL    3
842
843 static const value_string m3ua_congestion_level_values[] = {
844   { NO_CONGESTION_LEVEL,                             "No congestion or undefined" },
845   { CONGESTION_LEVEL_1_LEVEL,                        "Congestion level 1" },
846   { CONGESTION_LEVEL_2_LEVEL,                        "Congestion level 2" },
847   { CONGESTION_LEVEL_3_LEVEL,                        "Congestion level 3" },
848   {0,                           NULL } };
849
850 #define CONG_IND_RESERVED_LENGTH    3
851 #define CONG_IND_LEVEL_LENGTH       1
852
853 #define CONG_IND_RESERVED_OFFSET     PARAMETER_VALUE_OFFSET
854 #define CONG_IND_LEVEL_OFFSET        (CONG_IND_RESERVED_OFFSET + CONG_IND_RESERVED_LENGTH)
855
856 static void
857 dissect_m3ua_congestion_indication_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
858 {
859   guint8 level;
860   
861   level = tvb_get_guint8(parameter_tvb, CONG_IND_LEVEL_OFFSET);
862
863   proto_tree_add_bytes(parameter_tree, hf_m3ua_congestion_reserved, parameter_tvb, CONG_IND_RESERVED_OFFSET, CONG_IND_RESERVED_LENGTH,
864                        tvb_get_ptr(parameter_tvb, CONG_IND_RESERVED_OFFSET, CONG_IND_RESERVED_LENGTH));
865   proto_tree_add_uint(parameter_tree, hf_m3ua_congestion_level, parameter_tvb, CONG_IND_LEVEL_OFFSET, CONG_IND_LEVEL_LENGTH, level);
866   proto_item_set_text(parameter_item, "Congestion indication(%s)", val_to_str(level, m3ua_congestion_level_values, "unknown"));
867 }
868
869 #define CON_DEST_RESERVED_LENGTH    1
870 #define CON_DEST_PC_LENGTH          3
871
872 #define CON_DEST_RESERVED_OFFSET    PARAMETER_VALUE_OFFSET
873 #define CON_DEST_PC_OFFSET          (CON_DEST_RESERVED_OFFSET + CON_DEST_RESERVED_LENGTH)
874
875 static void
876 dissect_m3ua_concerned_destination_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
877 {
878   guint32 pc;
879   
880   pc = tvb_get_ntoh24(parameter_tvb, CON_DEST_PC_OFFSET);
881
882   proto_tree_add_bytes(parameter_tree, hf_m3ua_concerned_dest_reserved, parameter_tvb, CON_DEST_RESERVED_OFFSET, CON_DEST_RESERVED_LENGTH,
883                        tvb_get_ptr(parameter_tvb, CON_DEST_RESERVED_OFFSET, CON_DEST_RESERVED_LENGTH));
884   proto_tree_add_uint(parameter_tree, hf_m3ua_concerned_dest_pc, parameter_tvb, CON_DEST_PC_OFFSET, CON_DEST_PC_LENGTH, pc);
885   proto_item_set_text(parameter_item, "Concerned destination (%u)", pc);
886 }
887
888 static void
889 dissect_m3ua_routing_key_parameter(tvbuff_t *parameter_tvb, packet_info *pinfo, proto_tree *tree, proto_tree *parameter_tree, proto_item *parameter_item)
890 {
891   tvbuff_t *parameters_tvb;
892   guint16 length, parameters_length;
893   
894   length = tvb_get_ntohs(parameter_tvb, PARAMETER_LENGTH_OFFSET);
895   parameters_length = length - PARAMETER_HEADER_LENGTH;
896   parameters_tvb          = tvb_new_subset(parameter_tvb, PARAMETER_VALUE_OFFSET, parameters_length, parameters_length);
897   dissect_m3ua_parameters(parameters_tvb, pinfo, tree, parameter_tree);
898   proto_item_set_text(parameter_item, "Routing key");
899 }
900
901 static const value_string m3ua_registration_result_status_values[] = {
902   { 0,           "Successfully Registered" } ,
903   { 1,           "Error - Unknown" } ,
904   { 2,           "Error - Invalid DPC" } ,
905   { 3,           "Error - Invalid Network Appearance" } ,
906   { 4,           "Error - Invalid Routing Key" } ,
907   { 5,           "Error - Permission Denied" } ,
908   { 6,           "Error - Overlapping (Non-unique) Routing Key" } ,
909   { 7,           "Error - Routing Key not Provisioned" } ,
910   { 8,           "Error - Insufficient Resources" } ,
911   { 0,           NULL } };
912
913 #define REG_RES_IDENTIFIER_LENGTH 4
914 #define REG_RES_STATUS_LENGTH     4
915 #define REG_RES_CONTEXT_LENGTH    4
916
917 #define REG_RES_IDENTIFIER_OFFSET PARAMETER_VALUE_OFFSET
918 #define REG_RES_STATUS_OFFSET     (REG_RES_IDENTIFIER_OFFSET + REG_RES_IDENTIFIER_LENGTH)
919 #define REG_RES_CONTEXT_OFFSET    (REG_RES_STATUS_OFFSET + REG_RES_STATUS_LENGTH)
920
921 static void
922 dissect_m3ua_v6_registration_result_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
923 {
924   guint32 id, status, context;
925
926   id      = tvb_get_ntohl(parameter_tvb, REG_RES_IDENTIFIER_OFFSET);
927   status  = tvb_get_ntohl(parameter_tvb, REG_RES_STATUS_OFFSET);
928   context = tvb_get_ntohl(parameter_tvb, REG_RES_CONTEXT_OFFSET);
929
930   proto_tree_add_uint(parameter_tree, hf_m3ua_registration_result_identifier, parameter_tvb, REG_RES_IDENTIFIER_OFFSET, REG_RES_IDENTIFIER_LENGTH, id);
931   proto_tree_add_uint(parameter_tree, hf_m3ua_registration_result_status, parameter_tvb, REG_RES_STATUS_OFFSET, REG_RES_STATUS_LENGTH, status);
932   proto_tree_add_uint(parameter_tree, hf_m3ua_registration_result_context, parameter_tvb, REG_RES_CONTEXT_OFFSET, REG_RES_CONTEXT_LENGTH, context); 
933   proto_item_set_text(parameter_item, "Registration result");
934 }
935
936 static void
937 dissect_m3ua_v12_registration_result_parameter(tvbuff_t *parameter_tvb, packet_info *pinfo, proto_tree *tree, proto_tree *parameter_tree, proto_item *parameter_item)
938 {
939   tvbuff_t *parameters_tvb;
940   guint16 length, parameters_length;
941   
942   length = tvb_get_ntohs(parameter_tvb, PARAMETER_LENGTH_OFFSET);
943   parameters_length = length - PARAMETER_HEADER_LENGTH;
944   parameters_tvb          = tvb_new_subset(parameter_tvb, PARAMETER_VALUE_OFFSET, parameters_length, parameters_length);
945   dissect_m3ua_parameters(parameters_tvb, pinfo, tree, parameter_tree);
946   proto_item_set_text(parameter_item, "Registration result");
947 }
948
949 static const value_string m3ua_deregistration_result_status_values[] = {
950   { 0,           "Successfully De-registered" } ,
951   { 1,           "Error - Unknown" } ,
952   { 2,           "Error - Invalid Routing context" } ,
953   { 3,           "Error - Permission Denied" } ,
954   { 4,           "Error - Not registered" } ,
955   { 0,           NULL } };
956
957 #define DEREG_RES_CONTEXT_LENGTH 4
958 #define DEREG_RES_STATUS_LENGTH  4
959
960 #define DEREG_RES_CONTEXT_OFFSET PARAMETER_VALUE_OFFSET
961 #define DEREG_RES_STATUS_OFFSET  (DEREG_RES_CONTEXT_OFFSET + DEREG_RES_CONTEXT_LENGTH)
962
963 static void
964 dissect_m3ua_v6_deregistration_result_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
965 {
966   guint32 status, context;
967
968   context = tvb_get_ntohl(parameter_tvb, DEREG_RES_CONTEXT_OFFSET);
969   status  = tvb_get_ntohl(parameter_tvb, DEREG_RES_STATUS_OFFSET);
970
971   proto_tree_add_uint(parameter_tree, hf_m3ua_deregistration_result_context, parameter_tvb, DEREG_RES_CONTEXT_OFFSET, DEREG_RES_CONTEXT_LENGTH, context); 
972   proto_tree_add_uint(parameter_tree, hf_m3ua_deregistration_result_status, parameter_tvb, DEREG_RES_STATUS_OFFSET, DEREG_RES_STATUS_LENGTH, status);
973   proto_item_set_text(parameter_item, "De-registration result");
974
975 }
976
977 static void
978 dissect_m3ua_v12_deregistration_result_parameter(tvbuff_t *parameter_tvb, packet_info *pinfo, proto_tree *tree, proto_tree *parameter_tree, proto_item *parameter_item)
979 {
980   tvbuff_t *parameters_tvb;
981   guint16 length, parameters_length;
982   
983   length = tvb_get_ntohs(parameter_tvb, PARAMETER_LENGTH_OFFSET);
984   parameters_length = length - PARAMETER_HEADER_LENGTH;
985   parameters_tvb          = tvb_new_subset(parameter_tvb, PARAMETER_VALUE_OFFSET, parameters_length, parameters_length);
986   dissect_m3ua_parameters(parameters_tvb, pinfo, tree, parameter_tree);
987   proto_item_set_text(parameter_item, "Deregistration result");
988 }
989
990
991 #define LOCAL_RK_IDENTIFIER_OFFSET PARAMETER_VALUE_OFFSET
992 #define LOCAL_RK_IDENTIFIER_LENGTH 4
993
994 static void
995 dissect_m3ua_local_routing_key_identifier_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
996 {
997   guint32 id;
998   
999   id = tvb_get_ntohl(parameter_tvb, LOCAL_RK_IDENTIFIER_OFFSET);
1000   proto_tree_add_uint(parameter_tree, hf_m3ua_local_rk_identifier, parameter_tvb, LOCAL_RK_IDENTIFIER_OFFSET, LOCAL_RK_IDENTIFIER_LENGTH, id);
1001   proto_item_set_text(parameter_item, "Local routing key identifier (%u)", id);
1002 }
1003
1004 #define DPC_MASK_LENGTH    1
1005 #define DPC_PC_LENGTH      3
1006
1007 #define DPC_MASK_OFFSET    PARAMETER_VALUE_OFFSET
1008 #define DPC_PC_OFFSET      (DPC_MASK_OFFSET + DPC_MASK_LENGTH)
1009
1010 static void
1011 dissect_m3ua_destination_point_code_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
1012 {
1013   guint32 pc;
1014   guint8  mask;
1015  
1016   mask = tvb_get_guint8(parameter_tvb, DPC_MASK_OFFSET);
1017   pc   = tvb_get_ntoh24(parameter_tvb, DPC_PC_OFFSET);
1018
1019   proto_tree_add_uint(parameter_tree, hf_m3ua_dpc_mask, parameter_tvb, DPC_MASK_OFFSET, DPC_MASK_LENGTH, mask);
1020   proto_tree_add_uint(parameter_tree, hf_m3ua_dpc_pc, parameter_tvb, DPC_PC_OFFSET, DPC_PC_LENGTH, pc);
1021   proto_item_set_text(parameter_item, "Destination point code (%u)", pc);
1022 }
1023
1024 #define SI_LENGTH 1
1025
1026 static void
1027 dissect_m3ua_service_indicators_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
1028 {
1029   guint8  si;
1030   guint16 length, number_of_sis, si_number;
1031   gint si_offset;
1032
1033   length        = tvb_get_ntohs(parameter_tvb, PARAMETER_LENGTH_OFFSET);
1034   number_of_sis = length - PARAMETER_HEADER_LENGTH;
1035
1036   si_offset = PARAMETER_VALUE_OFFSET;
1037   for(si_number=1; si_number <= number_of_sis; si_number++) {
1038     si = tvb_get_guint8(parameter_tvb, si_offset);
1039     proto_tree_add_uint(parameter_tree, hf_m3ua_si, parameter_tvb, si_offset, SI_LENGTH, si);
1040     si_offset += SI_LENGTH;
1041   };
1042   proto_item_set_text(parameter_item, "Service indicators (%u indicator%s)", number_of_sis, plurality(number_of_sis, "", "s"));
1043
1044 }
1045 #define SSN_LENGTH 1
1046
1047 static void
1048 dissect_m3ua_subsystem_numbers_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
1049 {
1050   guint8  ssn;
1051   guint16 length, number_of_ssns, ssn_number;
1052   gint ssn_offset;
1053
1054   length         = tvb_get_ntohs(parameter_tvb, PARAMETER_LENGTH_OFFSET);
1055   number_of_ssns = length - PARAMETER_HEADER_LENGTH;
1056
1057   ssn_offset = PARAMETER_VALUE_OFFSET;
1058   for(ssn_number=1; ssn_number <= number_of_ssns; ssn_number++) {
1059     ssn = tvb_get_guint8(parameter_tvb, ssn_offset);
1060     proto_tree_add_uint(parameter_tree, hf_m3ua_ssn, parameter_tvb, ssn_offset, SSN_LENGTH, ssn);
1061     ssn_offset += SSN_LENGTH;
1062   };
1063   proto_item_set_text(parameter_item, "Subsystem numbers (%u number%s)", number_of_ssns, plurality(number_of_ssns, "", "s"));
1064
1065 }
1066
1067 #define OPC_MASK_LENGTH             1
1068 #define OPC_PC_LENGTH               3
1069 #define OPC_LENGTH                  (OPC_MASK_LENGTH + OPC_PC_LENGTH)
1070 #define OPC_MASK_OFFSET             0
1071 #define OPC_PC_OFFSET               (OPC_MASK_OFFSET + OPC_MASK_LENGTH)
1072
1073 static void
1074 dissect_m3ua_originating_point_code_list_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
1075 {
1076   guint8  mask;
1077   guint16 length, number_of_point_codes, point_code_number;
1078   guint32 pc;
1079   gint point_code_offset;
1080
1081   length                = tvb_get_ntohs(parameter_tvb, PARAMETER_LENGTH_OFFSET);
1082   number_of_point_codes = (length - PARAMETER_HEADER_LENGTH) / 4;
1083
1084   point_code_offset = PARAMETER_VALUE_OFFSET;
1085   for(point_code_number=1; point_code_number <= number_of_point_codes; point_code_number++) {
1086     mask = tvb_get_guint8(parameter_tvb, point_code_offset + AFFECTED_MASK_OFFSET);
1087     pc   = tvb_get_ntoh24(parameter_tvb, point_code_offset + AFFECTED_PC_OFFSET);
1088     proto_tree_add_uint(parameter_tree, hf_m3ua_opc_list_mask, parameter_tvb, point_code_offset + OPC_MASK_OFFSET, OPC_MASK_LENGTH, mask);
1089     proto_tree_add_uint(parameter_tree, hf_m3ua_opc_list_pc, parameter_tvb, point_code_offset + OPC_PC_OFFSET, OPC_PC_LENGTH, pc);
1090     point_code_offset += OPC_LENGTH;
1091   };
1092   proto_item_set_text(parameter_item, "Originating point code list (%u point code%s)", number_of_point_codes, plurality(number_of_point_codes, "", "s"));
1093 }
1094
1095 #define CIC_RANGE_MASK_LENGTH             1
1096 #define CIC_RANGE_PC_LENGTH               3
1097 #define CIC_RANGE_LOWER_LENGTH            2
1098 #define CIC_RANGE_UPPER_LENGTH            2
1099 #define CIC_RANGE_LENGTH                  (CIC_RANGE_MASK_LENGTH + CIC_RANGE_PC_LENGTH + CIC_RANGE_LOWER_LENGTH + CIC_RANGE_UPPER_LENGTH)
1100 #define CIC_RANGE_MASK_OFFSET             0
1101 #define CIC_RANGE_PC_OFFSET               (CIC_RANGE_MASK_OFFSET + CIC_RANGE_MASK_LENGTH)
1102 #define CIC_RANGE_LOWER_OFFSET            (CIC_RANGE_PC_OFFSET + CIC_RANGE_PC_LENGTH)
1103 #define CIC_RANGE_UPPER_OFFSET            (CIC_RANGE_LOWER_OFFSET + CIC_RANGE_LOWER_LENGTH)
1104
1105 static void
1106 dissect_m3ua_circuit_range_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
1107 {
1108   guint8  mask;
1109   guint16 length, number_of_point_codes, point_code_number, lower, upper;
1110   guint32 pc;
1111   gint point_code_offset;
1112
1113   length                = tvb_get_ntohs(parameter_tvb, PARAMETER_LENGTH_OFFSET);
1114   number_of_point_codes = (length - PARAMETER_HEADER_LENGTH) / CIC_RANGE_LENGTH;
1115
1116   point_code_offset = PARAMETER_VALUE_OFFSET;
1117   for(point_code_number = 1; point_code_number <= number_of_point_codes; point_code_number++) {
1118     mask  = tvb_get_guint8(parameter_tvb, point_code_offset + CIC_RANGE_MASK_OFFSET);
1119     pc    = tvb_get_ntoh24(parameter_tvb, point_code_offset + CIC_RANGE_PC_OFFSET);
1120     lower = tvb_get_ntohs(parameter_tvb, point_code_offset + CIC_RANGE_LOWER_OFFSET);
1121     upper = tvb_get_ntohs(parameter_tvb, point_code_offset + CIC_RANGE_UPPER_OFFSET);
1122
1123     proto_tree_add_uint(parameter_tree, hf_m3ua_cic_range_mask, parameter_tvb, point_code_offset + CIC_RANGE_MASK_OFFSET, CIC_RANGE_MASK_LENGTH, mask);
1124     proto_tree_add_uint(parameter_tree, hf_m3ua_cic_range_pc, parameter_tvb, point_code_offset + CIC_RANGE_PC_OFFSET, CIC_RANGE_PC_LENGTH, pc);
1125     proto_tree_add_uint(parameter_tree, hf_m3ua_cic_range_lower, parameter_tvb, point_code_offset + CIC_RANGE_LOWER_OFFSET, CIC_RANGE_LOWER_LENGTH, lower);
1126     proto_tree_add_uint(parameter_tree, hf_m3ua_cic_range_upper, parameter_tvb, point_code_offset + CIC_RANGE_UPPER_OFFSET, CIC_RANGE_UPPER_LENGTH, upper);
1127     point_code_offset += CIC_RANGE_LENGTH;
1128   };
1129   proto_item_set_text(parameter_item, "Circuit range (%u range%s)", number_of_point_codes, plurality(number_of_point_codes, "", "s"));
1130 }
1131
1132 #define DATA_OPC_LENGTH   4
1133 #define DATA_DPC_LENGTH   4
1134 #define DATA_SI_LENGTH    1
1135 #define DATA_NI_LENGTH    1
1136 #define DATA_MP_LENGTH    1
1137 #define DATA_SLS_LENGTH   1
1138 #define DATA_HDR_LENGTH   (DATA_OPC_LENGTH + DATA_DPC_LENGTH + DATA_SI_LENGTH + DATA_NI_LENGTH + DATA_MP_LENGTH + DATA_SLS_LENGTH)
1139
1140 #define DATA_OPC_OFFSET   PARAMETER_VALUE_OFFSET
1141 #define DATA_DPC_OFFSET   (DATA_OPC_OFFSET + DATA_OPC_LENGTH)
1142 #define DATA_SI_OFFSET    (DATA_DPC_OFFSET + DATA_DPC_LENGTH)
1143 #define DATA_NI_OFFSET    (DATA_SI_OFFSET + DATA_SI_LENGTH)
1144 #define DATA_MP_OFFSET    (DATA_NI_OFFSET + DATA_NI_LENGTH)
1145 #define DATA_SLS_OFFSET   (DATA_MP_OFFSET + DATA_MP_LENGTH)
1146 #define DATA_ULP_OFFSET   (DATA_SLS_OFFSET + DATA_SLS_LENGTH)
1147
1148 static void
1149 dissect_m3ua_protocol_data_parameter(tvbuff_t *parameter_tvb, packet_info *pinfo, proto_tree *tree, proto_tree *parameter_tree, proto_item *parameter_item)
1150 {
1151   guint32 opc, dpc;
1152   guint16 length, ulp_length;
1153   guint8 si, ni, mp, sls;
1154   tvbuff_t *payload_tvb;
1155
1156   length = tvb_get_ntohs(parameter_tvb, PARAMETER_LENGTH_OFFSET);
1157   ulp_length = length - PARAMETER_HEADER_LENGTH - DATA_HDR_LENGTH;
1158   payload_tvb          = tvb_new_subset(parameter_tvb, DATA_ULP_OFFSET, ulp_length, ulp_length);
1159   opc = tvb_get_ntohl(parameter_tvb, DATA_OPC_OFFSET);
1160   dpc = tvb_get_ntohl(parameter_tvb, DATA_DPC_OFFSET);
1161   si  = tvb_get_guint8(parameter_tvb, DATA_SI_OFFSET);
1162   ni  = tvb_get_guint8(parameter_tvb, DATA_NI_OFFSET);
1163   mp  = tvb_get_guint8(parameter_tvb, DATA_MP_OFFSET);
1164   sls = tvb_get_guint8(parameter_tvb, DATA_SLS_OFFSET);
1165   proto_tree_add_uint(parameter_tree, hf_m3ua_protocol_data_opc, parameter_tvb, DATA_OPC_OFFSET, DATA_OPC_LENGTH, opc);
1166   proto_tree_add_uint(parameter_tree, hf_m3ua_protocol_data_dpc, parameter_tvb, DATA_DPC_OFFSET, DATA_DPC_LENGTH, dpc);
1167   proto_tree_add_uint(parameter_tree, hf_m3ua_protocol_data_si,  parameter_tvb, DATA_SI_OFFSET,  DATA_SI_LENGTH,  si);
1168   proto_tree_add_uint(parameter_tree, hf_m3ua_protocol_data_ni,  parameter_tvb, DATA_NI_OFFSET,  DATA_NI_LENGTH,  ni);
1169   proto_tree_add_uint(parameter_tree, hf_m3ua_protocol_data_mp,  parameter_tvb, DATA_MP_OFFSET,  DATA_MP_LENGTH,  mp);
1170   proto_tree_add_uint(parameter_tree, hf_m3ua_protocol_data_sls, parameter_tvb, DATA_SLS_OFFSET, DATA_SLS_LENGTH, sls);
1171
1172   proto_item_set_text(parameter_item, "Protocol data (SS7 message of %u byte%s)", ulp_length, plurality(ulp_length, "", "s"));
1173   proto_item_set_len(parameter_item, PARAMETER_HEADER_LENGTH + DATA_HDR_LENGTH);
1174   
1175   if (!dissector_try_port(m3ua_si_dissector_table, si, payload_tvb, pinfo, tree)) {
1176     call_dissector(data_handle, payload_tvb, pinfo, tree);
1177   }
1178 }
1179
1180 #define CORR_ID_OFFSET PARAMETER_VALUE_OFFSET
1181 #define CORR_ID_LENGTH 4
1182
1183 static void
1184 dissect_m3ua_correlation_identifier_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
1185 {
1186   guint32 id;
1187   
1188   id = tvb_get_ntohl(parameter_tvb, CORR_ID_OFFSET);
1189   proto_tree_add_uint(parameter_tree, hf_m3ua_correlation_identifier, parameter_tvb, CORR_ID_OFFSET, CORR_ID_LENGTH, id);
1190   proto_item_set_text(parameter_item, "Correlation Identifer (%u)", id);
1191 }
1192
1193 #define REG_STATUS_LENGTH  4
1194 #define REG_STATUS_OFFSET  PARAMETER_VALUE_OFFSET
1195
1196 static const value_string m3ua_registration_status_values[] = {
1197   {  0,           "Successfully Registered" },
1198   {  1,           "Error - Unknown" },
1199   {  2,           "Error - Invalid DPC" },
1200   {  3,           "Error - Invalid Network Appearance" },
1201   {  4,           "Error - Invalid Routing Key" },
1202   {  5,           "Error - Permission Denied" },
1203   {  6,           "Error - Cannot Support Unique Routing" },
1204   {  7,           "Error - Routing Key not Currently Provisioned" },
1205   {  8,           "Error - Insufficient Resources" },
1206   {  9,           "Error - Unsupported RK parameter Field" },
1207   { 10,           "Error - Unsupported/Invalid Traffic Handling Mode" },
1208   {  0,           NULL } };
1209
1210 static void
1211 dissect_m3ua_registration_status_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
1212 {
1213   guint32 status;
1214   
1215   status = tvb_get_ntohl(parameter_tvb, REG_STATUS_OFFSET);
1216   proto_tree_add_uint(parameter_tree, hf_m3ua_registration_status, parameter_tvb, REG_STATUS_OFFSET, REG_STATUS_LENGTH, status);
1217   proto_item_set_text(parameter_item, "Registration status (%s)", val_to_str(status, m3ua_registration_status_values, "unknown"));
1218 }
1219
1220 #define DEREG_STATUS_LENGTH  4
1221 #define DEREG_STATUS_OFFSET  PARAMETER_VALUE_OFFSET
1222
1223 static const value_string m3ua_deregistration_status_values[] = {
1224   { 0,          "Successfully Deregistered" },
1225   { 1,          "Error - Unknown" },
1226   { 2,          "Error - Invalid Routing Context" },
1227   { 3,          "Error - Permission Denied" },
1228   { 4,          "Error - Not Registered" },
1229   { 5,          "Error - ASP Currently Active for Routing Context" },
1230   { 0,          NULL } };
1231
1232 static void
1233 dissect_m3ua_deregistration_status_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
1234 {
1235   guint32 status;
1236   
1237   status = tvb_get_ntohl(parameter_tvb, DEREG_STATUS_OFFSET);
1238   proto_tree_add_uint(parameter_tree, hf_m3ua_deregistration_status, parameter_tvb, DEREG_STATUS_OFFSET, DEREG_STATUS_LENGTH, status);
1239   proto_item_set_text(parameter_item, "Deregistration status (%s)", val_to_str(status, m3ua_deregistration_status_values, "unknown"));
1240 }
1241
1242 static void
1243 dissect_m3ua_registration_results_parameter(tvbuff_t *parameter_tvb, packet_info *pinfo, proto_tree *tree, proto_tree *parameter_tree, proto_item *parameter_item)
1244 {
1245   tvbuff_t *parameters_tvb;
1246   guint16 length, parameters_length;
1247   
1248   length            = tvb_get_ntohs(parameter_tvb, PARAMETER_LENGTH_OFFSET);
1249   parameters_length = length - PARAMETER_HEADER_LENGTH;
1250   parameters_tvb    = tvb_new_subset(parameter_tvb, PARAMETER_VALUE_OFFSET, parameters_length, parameters_length);
1251   dissect_m3ua_parameters(parameters_tvb, pinfo, tree, parameter_tree);
1252   proto_item_set_text(parameter_item, "Registration results");
1253 }
1254
1255 static void
1256 dissect_m3ua_deregistration_results_parameter(tvbuff_t *parameter_tvb, packet_info *pinfo, proto_tree *tree, proto_tree *parameter_tree, proto_item *parameter_item)
1257 {
1258   tvbuff_t *parameters_tvb;
1259   guint16 length, parameters_length;
1260   
1261   length            = tvb_get_ntohs(parameter_tvb, PARAMETER_LENGTH_OFFSET);
1262   parameters_length = length - PARAMETER_HEADER_LENGTH;
1263   parameters_tvb    = tvb_new_subset(parameter_tvb, PARAMETER_VALUE_OFFSET, parameters_length, parameters_length);
1264   dissect_m3ua_parameters(parameters_tvb, pinfo, tree, parameter_tree);
1265   proto_item_set_text(parameter_item, "Deregistration results");
1266 }
1267
1268 static void
1269 dissect_m3ua_unknown_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
1270 {
1271   guint16 tag, length, parameter_value_length;
1272   
1273   tag    = tvb_get_ntohs(parameter_tvb, PARAMETER_TAG_OFFSET);
1274   length = tvb_get_ntohs(parameter_tvb, PARAMETER_LENGTH_OFFSET);
1275   
1276   parameter_value_length = length - PARAMETER_HEADER_LENGTH;
1277
1278   proto_tree_add_bytes(parameter_tree, hf_m3ua_parameter_value, parameter_tvb, PARAMETER_VALUE_OFFSET, parameter_value_length, 
1279                        tvb_get_ptr(parameter_tvb, PARAMETER_VALUE_OFFSET, parameter_value_length));
1280
1281   proto_item_set_text(parameter_item, "Parameter with tag %u and %u byte%s value", tag, parameter_value_length, plurality(parameter_value_length, "", "s"));
1282 }
1283
1284 static void
1285 dissect_m3ua_v6_parameter(tvbuff_t *parameter_tvb, packet_info *pinfo, proto_tree *tree, proto_tree *m3ua_tree)
1286 {
1287   guint16 tag, length, padding_length, total_length;
1288   proto_item *parameter_item;
1289   proto_tree *parameter_tree;
1290
1291   /* extract tag and length from the parameter */
1292   tag            = tvb_get_ntohs(parameter_tvb, PARAMETER_TAG_OFFSET);
1293   length         = tvb_get_ntohs(parameter_tvb, PARAMETER_LENGTH_OFFSET);
1294
1295   /* calculate padding and total length */
1296   padding_length = tvb_length(parameter_tvb) - length;
1297   total_length   = length + padding_length;
1298
1299   /* create proto_tree stuff */
1300   parameter_item   = proto_tree_add_text(m3ua_tree, parameter_tvb, PARAMETER_HEADER_OFFSET, total_length, "Incomplete parameter");
1301   parameter_tree   = proto_item_add_subtree(parameter_item, ett_m3ua_parameter);
1302
1303   /* add tag and length to the m3ua tree */
1304   proto_tree_add_uint_format(parameter_tree, hf_m3ua_parameter_tag, parameter_tvb, PARAMETER_TAG_OFFSET, PARAMETER_TAG_LENGTH, tag, 
1305                              "Parameter tag: %s (0x%x)", val_to_str(tag, m3ua_v6_parameter_tag_values, "unknown"), tag);
1306   proto_tree_add_uint(parameter_tree, hf_m3ua_parameter_length, parameter_tvb, PARAMETER_LENGTH_OFFSET, PARAMETER_LENGTH_LENGTH, length);
1307
1308   switch(tag) {
1309   case V6_NETWORK_APPEARANCE_PARAMETER_TAG:
1310     dissect_m3ua_network_appearance_parameter(parameter_tvb, parameter_tree, parameter_item);
1311     break;
1312   case V6_PROTOCOL_DATA_1_PARAMETER_TAG:
1313     dissect_m3ua_protocol_data_1_parameter(parameter_tvb, pinfo, tree, parameter_item);
1314     break;
1315   case V6_PROTOCOL_DATA_2_PARAMETER_TAG:
1316     dissect_m3ua_protocol_data_2_parameter(parameter_tvb, pinfo, tree, parameter_tree, parameter_item);
1317     break;
1318   case V6_INFO_PARAMETER_TAG:
1319     dissect_m3ua_info_string_parameter(parameter_tvb, parameter_tree, parameter_item);
1320     break;
1321   case V6_AFFECTED_DESTINATIONS_PARAMETER_TAG:
1322     dissect_m3ua_affected_point_code_parameter(parameter_tvb, parameter_tree, parameter_item);
1323     break;
1324   case V6_ROUTING_CONTEXT_PARAMETER_TAG:
1325     dissect_m3ua_routing_context_parameter(parameter_tvb, parameter_tree, parameter_item);
1326     break;
1327   case V6_DIAGNOSTIC_INFORMATION_PARAMETER_TAG:
1328     dissect_m3ua_diagnostic_information_parameter(parameter_tvb, parameter_tree, parameter_item);
1329     break;
1330   case V6_HEARTBEAT_DATA_PARAMETER_TAG:
1331     dissect_m3ua_heartbeat_data_parameter(parameter_tvb, parameter_tree, parameter_item);
1332     break;
1333   case V6_USER_CAUSE_PARAMETER_TAG:
1334     dissect_m3ua_user_cause_parameter(parameter_tvb, parameter_tree, parameter_item);
1335     break;
1336   case V6_REASON_PARAMETER_TAG:
1337     dissect_m3ua_reason_parameter(parameter_tvb, parameter_tree, parameter_item);
1338     break;
1339   case V6_TRAFFIC_MODE_TYPE_PARAMETER_TAG:
1340     dissect_m3ua_v6_traffic_mode_type_parameter(parameter_tvb, parameter_tree, parameter_item);
1341     break;
1342   case V6_ERROR_CODE_PARAMETER_TAG:
1343     dissect_m3ua_v6_error_code_parameter(parameter_tvb, parameter_tree, parameter_item);
1344     break;
1345   case V6_STATUS_PARAMETER_TAG:
1346     dissect_m3ua_status_parameter(parameter_tvb, parameter_tree, parameter_item);
1347     break;
1348   case V6_CONGESTION_INDICATION_PARAMETER_TAG:
1349     dissect_m3ua_congestion_indication_parameter(parameter_tvb, parameter_tree, parameter_item);
1350     break;
1351   case V6_CONCERNED_DESTINATION_PARAMETER_TAG:
1352     dissect_m3ua_concerned_destination_parameter(parameter_tvb, parameter_tree, parameter_item);
1353     break;
1354   case V6_ROUTING_KEY_PARAMETER_TAG:
1355     dissect_m3ua_routing_key_parameter(parameter_tvb, pinfo, tree, parameter_tree, parameter_item);
1356     break;
1357   case V6_REGISTRATION_RESULT_PARAMETER_TAG:
1358     dissect_m3ua_v6_registration_result_parameter(parameter_tvb, parameter_tree, parameter_item);
1359     break;
1360   case V6_DEREGISTRATION_RESULT_PARAMETER_TAG:
1361     dissect_m3ua_v6_deregistration_result_parameter(parameter_tvb, parameter_tree, parameter_item);
1362     break;
1363   case V6_LOCAL_ROUTING_KEY_IDENTIFIER_PARAMETER_TAG:
1364     dissect_m3ua_local_routing_key_identifier_parameter(parameter_tvb, parameter_tree, parameter_item);
1365     break;
1366   case V6_DESTINATION_POINT_CODE_PARAMETER_TAG:
1367     dissect_m3ua_destination_point_code_parameter(parameter_tvb, parameter_tree, parameter_item);
1368     break;
1369   case V6_SERVICE_INDICATORS_PARAMETER_TAG:
1370     dissect_m3ua_service_indicators_parameter(parameter_tvb, parameter_tree, parameter_item);
1371     break;
1372   case V6_SUBSYSTEM_NUMBERS_PARAMETER_TAG:
1373     dissect_m3ua_subsystem_numbers_parameter(parameter_tvb, parameter_tree, parameter_item);
1374     break;
1375   case V6_ORIGINATING_POINT_CODE_LIST_PARAMETER_TAG:
1376     dissect_m3ua_originating_point_code_list_parameter(parameter_tvb, parameter_tree, parameter_item);
1377     break;
1378   case V6_CIRCUIT_RANGE_PARAMETER_TAG:
1379     dissect_m3ua_circuit_range_parameter(parameter_tvb, parameter_tree, parameter_item);
1380     break;
1381   case V6_REGISTRATION_RESULTS_PARAMETER_TAG:
1382     dissect_m3ua_registration_results_parameter(parameter_tvb, pinfo, tree, parameter_tree, parameter_item);
1383     break;
1384   case V6_DEREGISTRATION_RESULTS_PARAMETER_TAG:
1385     dissect_m3ua_deregistration_results_parameter(parameter_tvb, pinfo, tree, parameter_tree, parameter_item);
1386     break;
1387   default:
1388     dissect_m3ua_unknown_parameter(parameter_tvb, parameter_tree, parameter_item);
1389     break;
1390   };
1391
1392   if (padding_length > 0)
1393     proto_tree_add_bytes(parameter_tree, hf_m3ua_parameter_padding, parameter_tvb, PARAMETER_HEADER_OFFSET + length, padding_length, 
1394                          tvb_get_ptr(parameter_tvb, PARAMETER_HEADER_OFFSET + length, padding_length));
1395 }
1396
1397 static void
1398 dissect_m3ua_v12_parameter(tvbuff_t *parameter_tvb, packet_info *pinfo, proto_tree *tree, proto_tree *m3ua_tree)
1399 {
1400   guint16 tag, length, padding_length, total_length;
1401   proto_item *parameter_item;
1402   proto_tree *parameter_tree;
1403
1404   /* extract tag and length from the parameter */
1405   tag            = tvb_get_ntohs(parameter_tvb, PARAMETER_TAG_OFFSET);
1406   length         = tvb_get_ntohs(parameter_tvb, PARAMETER_LENGTH_OFFSET);
1407
1408   /* calculate padding and total length */
1409   padding_length = tvb_length(parameter_tvb) - length;
1410   total_length   = length + padding_length;
1411
1412   /* create proto_tree stuff */
1413   parameter_item   = proto_tree_add_text(m3ua_tree, parameter_tvb, PARAMETER_HEADER_OFFSET, total_length, "Incomplete parameter");
1414   parameter_tree   = proto_item_add_subtree(parameter_item, ett_m3ua_parameter);
1415
1416   /* add tag and length to the m3ua tree */
1417   proto_tree_add_uint_format(parameter_tree, hf_m3ua_parameter_tag, parameter_tvb, PARAMETER_TAG_OFFSET, PARAMETER_TAG_LENGTH, tag, 
1418                              "Parameter tag: %s (0x%x)", val_to_str(tag, m3ua_v12_parameter_tag_values, "unknown"), tag);
1419   proto_tree_add_uint(parameter_tree, hf_m3ua_parameter_length, parameter_tvb, PARAMETER_LENGTH_OFFSET, PARAMETER_LENGTH_LENGTH, length);
1420
1421   switch(tag) {
1422   case V12_INFO_STRING_PARAMETER_TAG:
1423     dissect_m3ua_info_string_parameter(parameter_tvb, parameter_tree, parameter_item);
1424     break;
1425   case V12_ROUTING_CONTEXT_PARAMETER_TAG:
1426     dissect_m3ua_routing_context_parameter(parameter_tvb, parameter_tree, parameter_item);
1427     break;
1428   case V12_DIAGNOSTIC_INFORMATION_PARAMETER_TAG:
1429     dissect_m3ua_diagnostic_information_parameter(parameter_tvb, parameter_tree, parameter_item);
1430     break;
1431   case V12_HEARTBEAT_DATA_PARAMETER_TAG:
1432     dissect_m3ua_heartbeat_data_parameter(parameter_tvb, parameter_tree, parameter_item);
1433     break;
1434   case V12_TRAFFIC_MODE_TYPE_PARAMETER_TAG:
1435     dissect_m3ua_v12_traffic_mode_type_parameter(parameter_tvb, parameter_tree, parameter_item);
1436     break;
1437   case V12_ERROR_CODE_PARAMETER_TAG:
1438     dissect_m3ua_v12_error_code_parameter(parameter_tvb, parameter_tree, parameter_item);
1439     break;
1440   case V12_STATUS_PARAMETER_TAG:
1441     dissect_m3ua_status_parameter(parameter_tvb, parameter_tree, parameter_item);
1442     break;
1443   case V12_ASP_IDENTIFIER_PARAMETER_TAG:
1444     dissect_m3ua_asp_identifier_parameter(parameter_tvb, parameter_tree, parameter_item);
1445     break;
1446   case V12_AFFECTED_POINT_CODE_PARAMETER_TAG:
1447     dissect_m3ua_affected_point_code_parameter(parameter_tvb, parameter_tree, parameter_item);
1448     break;
1449   case V12_NETWORK_APPEARANCE_PARAMETER_TAG:
1450     dissect_m3ua_network_appearance_parameter(parameter_tvb, parameter_tree, parameter_item);
1451     break;
1452   case V12_USER_CAUSE_PARAMETER_TAG:
1453     dissect_m3ua_user_cause_parameter(parameter_tvb, parameter_tree, parameter_item);
1454     break;
1455   case V12_CONGESTION_INDICATIONS_PARAMETER_TAG:
1456     dissect_m3ua_congestion_indication_parameter(parameter_tvb, parameter_tree, parameter_item);
1457     break;
1458   case V12_CONCERNED_DESTINATION_PARAMETER_TAG:
1459     dissect_m3ua_concerned_destination_parameter(parameter_tvb, parameter_tree, parameter_item);
1460     break;
1461   case V12_ROUTING_KEY_PARAMETER_TAG:
1462     dissect_m3ua_routing_key_parameter(parameter_tvb, pinfo, tree, parameter_tree, parameter_item);
1463     break;
1464   case V12_REGISTRATION_RESULT_PARAMETER_TAG:
1465     dissect_m3ua_v12_registration_result_parameter(parameter_tvb, pinfo, tree, parameter_tree, parameter_item);
1466     break;
1467   case V12_DEREGISTRATION_RESULT_PARAMETER_TAG:
1468     dissect_m3ua_v12_deregistration_result_parameter(parameter_tvb, pinfo, tree, parameter_tree, parameter_item);
1469     break;
1470   case V12_LOCAL_ROUTING_KEY_IDENTIFIER_PARAMETER_TAG:
1471     dissect_m3ua_local_routing_key_identifier_parameter(parameter_tvb, parameter_tree, parameter_item);
1472     break;
1473   case V12_DESTINATION_POINT_CODE_PARAMETER_TAG:
1474     dissect_m3ua_destination_point_code_parameter(parameter_tvb, parameter_tree, parameter_item);
1475     break;
1476   case V12_SERVICE_INDICATORS_PARAMETER_TAG:
1477     dissect_m3ua_service_indicators_parameter(parameter_tvb, parameter_tree, parameter_item);
1478     break;
1479   case V12_ORIGINATING_POINT_CODE_LIST_PARAMETER_TAG:
1480     dissect_m3ua_originating_point_code_list_parameter(parameter_tvb, parameter_tree, parameter_item);
1481     break;
1482   case V12_CIRCUIT_RANGE_PARAMETER_TAG:
1483     dissect_m3ua_circuit_range_parameter(parameter_tvb, parameter_tree, parameter_item);
1484     break;
1485   case V12_PROTOCOL_DATA_PARAMETER_TAG:
1486     dissect_m3ua_protocol_data_parameter(parameter_tvb, pinfo, tree, parameter_tree, parameter_item);
1487     break;
1488   case V12_CORRELATION_IDENTIFIER_PARAMETER_TAG:
1489     dissect_m3ua_correlation_identifier_parameter(parameter_tvb, parameter_tree, parameter_item);
1490     break;
1491   case V12_REGISTRATION_STATUS_PARAMETER_TAG:
1492     dissect_m3ua_registration_status_parameter(parameter_tvb, parameter_tree, parameter_item);
1493     break;
1494   case V12_DEREGISTRATION_STATUS_PARAMETER_TAG:
1495     dissect_m3ua_deregistration_status_parameter(parameter_tvb, parameter_tree, parameter_item);
1496     break;
1497   default:
1498     dissect_m3ua_unknown_parameter(parameter_tvb, parameter_tree, parameter_item);
1499     break;
1500   };
1501
1502   if (padding_length > 0)
1503     proto_tree_add_bytes(parameter_tree, hf_m3ua_parameter_padding, parameter_tvb, PARAMETER_HEADER_OFFSET + length, padding_length, 
1504                          tvb_get_ptr(parameter_tvb, PARAMETER_HEADER_OFFSET + length, padding_length));
1505 }
1506
1507 static void
1508 dissect_m3ua_parameters(tvbuff_t *parameters_tvb, packet_info *pinfo, proto_tree *tree, proto_tree *m3ua_tree)
1509 {
1510   gint offset, length, padding_length, total_length, remaining_length;
1511   tvbuff_t *parameter_tvb;
1512
1513   offset = 0;
1514   while((remaining_length = tvb_reported_length_remaining(parameters_tvb, offset))) {
1515     length         = tvb_get_ntohs(parameters_tvb, offset + PARAMETER_LENGTH_OFFSET);
1516     padding_length = nr_of_padding_bytes(length);
1517     if (remaining_length >= length)
1518       total_length = MIN(length + padding_length, remaining_length);
1519     else
1520       total_length = length + padding_length;
1521     /* create a tvb for the parameter including the padding bytes */
1522     parameter_tvb    = tvb_new_subset(parameters_tvb, offset, total_length, total_length);
1523     switch(m3ua_version) {
1524       case M3UA_V6:
1525         dissect_m3ua_v6_parameter(parameter_tvb, pinfo, tree, m3ua_tree); 
1526         break;
1527       case M3UA_V12:
1528         dissect_m3ua_v12_parameter(parameter_tvb, pinfo, tree, m3ua_tree);
1529         break;
1530     }
1531     /* get rid of the handled parameter */
1532     offset += total_length;
1533   }
1534 }
1535
1536
1537 static void
1538 dissect_m3ua_message(tvbuff_t *message_tvb, packet_info *pinfo, proto_tree *tree, proto_tree *m3ua_tree)
1539 {
1540   tvbuff_t *common_header_tvb, *parameters_tvb;
1541
1542   common_header_tvb = tvb_new_subset(message_tvb, 0, COMMON_HEADER_LENGTH, COMMON_HEADER_LENGTH);
1543   parameters_tvb    = tvb_new_subset(message_tvb, COMMON_HEADER_LENGTH, -1, -1);
1544   dissect_m3ua_common_header(common_header_tvb, pinfo, m3ua_tree);  
1545   if (m3ua_tree)
1546     dissect_m3ua_parameters(parameters_tvb, pinfo, tree, m3ua_tree);
1547 }
1548
1549 static void
1550 dissect_m3ua(tvbuff_t *message_tvb, packet_info *pinfo, proto_tree *tree)
1551 {
1552   proto_item *m3ua_item;
1553   proto_tree *m3ua_tree;
1554
1555   /* make entry in the Protocol column on summary display */
1556   if (check_col(pinfo->cinfo, COL_PROTOCOL)) 
1557     col_set_str(pinfo->cinfo, COL_PROTOCOL, "M3UA");
1558   
1559   /* In the interest of speed, if "tree" is NULL, don't do any work not
1560      necessary to generate protocol tree items. */
1561   if (tree) {
1562     /* create the m3ua protocol tree */
1563     m3ua_item = proto_tree_add_item(tree, proto_m3ua, message_tvb, 0, -1, FALSE);
1564     m3ua_tree = proto_item_add_subtree(m3ua_item, ett_m3ua);
1565   } else {
1566     m3ua_tree = NULL;
1567   };
1568   /* dissect the message */
1569   dissect_m3ua_message(message_tvb, pinfo, tree, m3ua_tree);
1570 }
1571
1572 /* Register the protocol with Ethereal */
1573 void
1574 proto_register_m3ua(void)
1575 {                 
1576
1577   /* Setup list of header fields */
1578   static hf_register_info hf[] = {
1579     { &hf_m3ua_version,
1580       { "Version", "m3ua.version",
1581               FT_UINT8, BASE_DEC, VALS(m3ua_protocol_version_values), 0x0,          
1582         "", HFILL }
1583     },
1584     { &hf_m3ua_reserved,
1585       { "Reserved", "m3ua.reserved",
1586               FT_UINT8, BASE_HEX, NULL, 0x0,          
1587               "", HFILL }
1588     }, 
1589     { &hf_m3ua_message_class,
1590       { "Message class", "m3ua.message_class",
1591         FT_UINT8, BASE_DEC, VALS(m3ua_message_class_values), 0x0,          
1592               "", HFILL }
1593     },
1594     { &hf_m3ua_message_type,
1595       { "Message Type", "m3ua.message_type",
1596               FT_UINT8, BASE_DEC, NULL, 0x0,          
1597               "", HFILL }
1598     },
1599     { &hf_m3ua_message_length,
1600       { "Message length", "m3ua.message_length",
1601         FT_UINT32, BASE_DEC, NULL, 0x0,          
1602               "", HFILL }
1603     }, 
1604     { &hf_m3ua_parameter_tag,
1605       { "Parameter Tag", "m3ua.parameter_tag",
1606         FT_UINT16, BASE_DEC, NULL, 0x0,          
1607         "", HFILL }
1608     },
1609     { &hf_m3ua_parameter_length,
1610       { "Parameter length", "m3ua.parameter_length",
1611         FT_UINT16, BASE_DEC, NULL, 0x0,          
1612               "", HFILL }
1613     }, 
1614     { &hf_m3ua_parameter_value,
1615       { "Parameter value", "m3ua.parameter_value",
1616               FT_BYTES, BASE_NONE, NULL, 0x0,          
1617               "", HFILL }
1618     },    
1619     { &hf_m3ua_parameter_padding,
1620       { "Padding", "m3ua.parameter_padding",
1621               FT_BYTES, BASE_NONE, NULL, 0x0,          
1622               "", HFILL }
1623     },    
1624     { &hf_m3ua_info_string,
1625       { "Info string", "m3ua.info_string",
1626               FT_STRING, BASE_DEC, NULL, 0x0,          
1627               "", HFILL }
1628     }, 
1629     { &hf_m3ua_routing_context,
1630       { "Routing context", "m3ua.routing_context",
1631               FT_UINT32, BASE_DEC, NULL, 0x0,          
1632         "", HFILL }
1633     }, 
1634     { &hf_m3ua_diagnostic_information,
1635       { "Diagnostic information", "m3ua.diagnostic_information",
1636               FT_BYTES, BASE_NONE, NULL, 0x0,          
1637               "", HFILL }
1638     },    
1639     { &hf_m3ua_heartbeat_data,
1640       { "Heartbeat data", "m3ua.heartbeat_data",
1641               FT_BYTES, BASE_NONE, NULL, 0x0,          
1642               "", HFILL }
1643     },    
1644     { &hf_m3ua_error_code,
1645       { "Error code", "m3ua.error_code",
1646         FT_UINT32, BASE_DEC, NULL, 0x0,          
1647               "", HFILL }
1648     }, 
1649     { &hf_m3ua_status_type,
1650       { "Status type", "m3ua.status_type",
1651               FT_UINT16, BASE_DEC, VALS(m3ua_status_type_values), 0x0,          
1652               "", HFILL }
1653     }, 
1654     { &hf_m3ua_status_info,
1655       { "Status info", "m3ua.status_info",
1656               FT_UINT16, BASE_DEC, NULL, 0x0,          
1657               "", HFILL }
1658     }, 
1659     { &hf_m3ua_asp_identifier,
1660       { "ASP identifier", "m3ua.asp_identifier",
1661               FT_UINT32, BASE_DEC, NULL, 0x0,          
1662               "", HFILL }
1663     },    
1664     { &hf_m3ua_affected_point_code_mask,
1665       { "Mask", "m3ua.affected_point_code_mask",
1666         FT_UINT8, BASE_DEC, NULL, 0x0,          
1667               "", HFILL }
1668     }, 
1669     { &hf_m3ua_affected_point_code_pc,
1670       { "Affected point code", "m3ua.affected_point_code_pc",
1671               FT_UINT24, BASE_DEC, NULL, 0x0,          
1672               "", HFILL }
1673     }, 
1674     { &hf_m3ua_network_appearance,
1675       { "Network appearance", "m3ua.network_appearance",
1676               FT_UINT32, BASE_DEC, NULL, 0x0,          
1677               "", HFILL }
1678     }, 
1679     { &hf_m3ua_unavailability_cause,
1680       { "Unavailability cause", "m3ua.unavailability_cause",
1681               FT_UINT16, BASE_DEC, VALS(m3ua_unavailability_cause_values), 0x0,          
1682         "", HFILL }
1683     }, 
1684     { &hf_m3ua_user_identity,
1685       { "User Identity", "m3ua.user_identity",
1686                FT_UINT16, BASE_DEC, VALS(m3ua_user_identity_values), 0x0,          
1687                "", HFILL }
1688     }, 
1689     { &hf_m3ua_congestion_reserved,
1690       { "Reserved", "m3ua.congestion_reserved",
1691               FT_BYTES, BASE_NONE, NULL, 0x0,          
1692               "", HFILL }
1693     },    
1694     { &hf_m3ua_congestion_level,
1695       { "Congestion level", "m3ua.congestion_level",
1696                FT_UINT8, BASE_DEC, VALS(m3ua_congestion_level_values), 0x0,          
1697                "", HFILL }
1698     }, 
1699     { &hf_m3ua_concerned_dest_reserved,
1700       { "Reserved", "m3ua.concerned_reserved",
1701               FT_BYTES, BASE_NONE, NULL, 0x0,          
1702               "", HFILL }
1703     },    
1704     { &hf_m3ua_concerned_dest_pc,
1705       { "Concerned DPC", "m3ua.concerned_dpc",
1706                FT_UINT24, BASE_DEC, NULL, 0x0,          
1707                "", HFILL }
1708     }, 
1709     { &hf_m3ua_dpc_mask,
1710       { "Mask", "m3ua.dpc_mask",
1711               FT_UINT8, BASE_DEC, NULL, 0x0,          
1712               "", HFILL }
1713     },    
1714     { &hf_m3ua_dpc_pc,
1715       { "Destination point code", "m3ua.dpc_pc",
1716                FT_UINT24, BASE_DEC, NULL, 0x0,          
1717                "", HFILL }
1718     }, 
1719     { &hf_m3ua_si,
1720       { "Service indicator", "m3ua_si",
1721         FT_UINT8, BASE_DEC, VALS(m3ua_user_identity_values), 0x0,          
1722               "", HFILL }
1723     }, 
1724     { &hf_m3ua_ssn,
1725       { "Subsystem number", "m3ua_ssn",
1726         FT_UINT8, BASE_DEC, NULL, 0x0,          
1727               "", HFILL }
1728     }, 
1729     { &hf_m3ua_opc_list_mask,
1730       { "Mask", "m3ua.opc_list_mask",
1731               FT_UINT8, BASE_DEC, NULL, 0x0,          
1732               "", HFILL }
1733     },    
1734     { &hf_m3ua_opc_list_pc,
1735       { "Originating point code", "m3ua.opc_list_pc",
1736                FT_UINT24, BASE_DEC, NULL, 0x0,          
1737                "", HFILL }
1738     }, 
1739     { &hf_m3ua_cic_range_mask,
1740       { "Mask", "m3ua.cic_range_mask",
1741               FT_UINT8, BASE_DEC, NULL, 0x0,          
1742               "", HFILL }
1743     },    
1744     { &hf_m3ua_cic_range_pc,
1745       { "Originating point code", "m3ua.cic_range_pc",
1746                FT_UINT24, BASE_DEC, NULL, 0x0,          
1747                "", HFILL }
1748     }, 
1749     { &hf_m3ua_cic_range_lower,
1750       { "Lower CIC value", "m3ua.cic_range_lower",
1751               FT_UINT16, BASE_DEC, NULL, 0x0,          
1752               "", HFILL }
1753     },    
1754     { &hf_m3ua_cic_range_upper,
1755       { "Upper CIC value", "m3ua.cic_range_upper",
1756                FT_UINT16, BASE_DEC, NULL, 0x0,          
1757                "", HFILL }
1758     }, 
1759     { &hf_m3ua_local_rk_identifier,
1760       { "Local routing key identifier", "m3ua.local_rk_identifier",
1761               FT_UINT32, BASE_DEC, NULL, 0x0,          
1762               "", HFILL }
1763     }, 
1764     { &hf_m3ua_li,
1765       { "Length indicator", "m3ua.protocol_data_2_li",
1766               FT_UINT8, BASE_DEC, NULL, 0x0,          
1767               "", HFILL }
1768     }, 
1769     { &hf_m3ua_protocol_data_opc,
1770       { "OPC", "m3ua.protocol_data_opc",
1771               FT_UINT32, BASE_DEC, NULL, 0x0,          
1772               "", HFILL }
1773     }, 
1774     { &hf_m3ua_protocol_data_dpc,
1775       { "DPC", "m3ua.protocol_data_dpc",
1776               FT_UINT32, BASE_DEC, NULL, 0x0,          
1777               "", HFILL }
1778     }, 
1779     { &hf_m3ua_protocol_data_si,
1780       { "SI", "m3ua.protocol_data_si",
1781               FT_UINT8, BASE_DEC, NULL, 0x0,          
1782               "", HFILL }
1783     }, 
1784     { &hf_m3ua_protocol_data_ni,
1785       { "NI", "m3ua.protocol_data_ni",
1786               FT_UINT8, BASE_DEC, NULL, 0x0,          
1787               "", HFILL }
1788     }, 
1789     { &hf_m3ua_protocol_data_mp,
1790       { "MP", "m3ua.protocol_data_mp",
1791               FT_UINT8, BASE_DEC, NULL, 0x0,          
1792               "", HFILL }
1793     }, 
1794     { &hf_m3ua_protocol_data_sls,
1795       { "SLS", "m3ua.protocol_data_sls",
1796               FT_UINT8, BASE_DEC, NULL, 0x0,          
1797               "", HFILL }
1798     }, 
1799     { &hf_m3ua_correlation_identifier,
1800       { "Correlation Identifier", "m3ua.correlation_identifier",
1801               FT_UINT32, BASE_DEC, NULL, 0x0,          
1802               "", HFILL }
1803     },
1804     { &hf_m3ua_registration_status,
1805       { "Registration status", "m3ua.registration_status",
1806               FT_UINT32, BASE_DEC, VALS(m3ua_registration_status_values), 0x0,          
1807               "", HFILL }
1808     },
1809     { &hf_m3ua_deregistration_status,
1810       { "Deregistration status", "m3ua.deregistration_status",
1811               FT_UINT32, BASE_DEC, VALS(m3ua_deregistration_status_values), 0x0,          
1812               "", HFILL }
1813     },
1814     { &hf_m3ua_reason,
1815       { "Reason", "m3ua_reason",
1816         FT_UINT32, BASE_DEC, VALS(m3ua_reason_values), 0x0,          
1817         "", HFILL }
1818     }, 
1819     { &hf_m3ua_traffic_mode_type,
1820       { "Traffic mode Type", "m3ua.traffic_mode_type",
1821               FT_UINT32, BASE_DEC, NULL, 0x0,          
1822               "", HFILL }
1823     }, 
1824     { &hf_m3ua_registration_result_identifier,
1825       { "Local RK-identifier value", "m3ua.registration_result_identifier",
1826               FT_UINT32, BASE_DEC, NULL, 0x0,          
1827               "", HFILL }
1828     }, 
1829     { &hf_m3ua_registration_result_status,
1830       { "Registration status", "m3ua.registration_results_status",
1831               FT_UINT32, BASE_DEC, VALS(m3ua_registration_result_status_values), 0x0,          
1832               "", HFILL }
1833     }, 
1834     { &hf_m3ua_registration_result_context,
1835       { "Routing context", "m3ua.registration_result_routing_context",
1836               FT_UINT32, BASE_DEC, NULL, 0x0,          
1837               "", HFILL }
1838     }, 
1839     { &hf_m3ua_deregistration_result_status,
1840       { "De-Registration status", "m3ua.deregistration_results_status",
1841               FT_UINT32, BASE_DEC, VALS(m3ua_deregistration_result_status_values), 0x0,          
1842               "", HFILL }
1843     }, 
1844     { &hf_m3ua_deregistration_result_context,
1845       { "Routing context", "m3ua.deregistration_result_routing_context",
1846               FT_UINT32, BASE_DEC, NULL, 0x0,          
1847               "", HFILL }
1848     }, 
1849   };
1850   
1851   /* Setup protocol subtree array */
1852   static gint *ett[] = {
1853     &ett_m3ua,
1854     &ett_m3ua_parameter,
1855   };
1856   
1857   static enum_val_t m3ua_options[] = {
1858     { "Internet Draft version 6",        M3UA_V6 },
1859     { "Internet Draft version 12",       M3UA_V12 },
1860     { NULL, 0 }
1861   };
1862
1863   /* Register the protocol name and description */
1864   proto_m3ua = proto_register_protocol("MTP 3 User Adaptation Layer", "M3UA",  "m3ua");
1865   m3ua_module = prefs_register_protocol(proto_m3ua, NULL);
1866   prefs_register_enum_preference(m3ua_module,
1867                                                          "version", "M3UA Version", "Internet Draft version used by Ethereal",
1868                                                          &m3ua_version, m3ua_options, FALSE);
1869
1870   /* Required function calls to register the header fields and subtrees used */
1871   proto_register_field_array(proto_m3ua, hf, array_length(hf));
1872   proto_register_subtree_array(ett, array_length(ett));
1873   m3ua_si_dissector_table = register_dissector_table("m3ua.protocol_data_si", "MTP3 Service indicator", FT_UINT8, BASE_HEX);
1874
1875 };
1876
1877 void
1878 proto_reg_handoff_m3ua(void)
1879 {
1880   dissector_handle_t m3ua_handle;
1881
1882   /*
1883    * Get a handle for the MTP3 dissector.
1884    */
1885   mtp3_handle = find_dissector("mtp3");
1886   data_handle = find_dissector("data");
1887   m3ua_handle = create_dissector_handle(dissect_m3ua, proto_m3ua);
1888   dissector_add("sctp.ppi",  M3UA_PAYLOAD_PROTO_ID, m3ua_handle);
1889   dissector_add("sctp.port", SCTP_PORT_M3UA, m3ua_handle);
1890 }