b41f8ad2ec69308aab979d3b36cec67cae8c7db5
[obnox/wireshark/wip.git] / asn1 / h248 / packet-h248-template.c
1 /* packet-h248.c
2  * Routines for H.248/MEGACO packet dissection
3  *
4  * Ronnie Sahlberg 2004
5  *
6  * Luis Ontanon 2005 - Context and Transaction Tracing
7  *
8  * $Id$
9  *
10  * Wireshark - Network traffic analyzer
11  * By Gerald Combs <gerald@wireshark.org>
12  * Copyright 1998 Gerald Combs
13  *
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version 2
17  * of the License, or (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include "packet-h248.h"
33 #include <epan/tap.h>
34 #include "packet-tpkt.h"
35 #include <ctype.h>
36
37 #define PNAME  "H.248 MEGACO"
38 #define PSNAME "H248"
39 #define PFNAME "h248"
40
41 #define GATEWAY_CONTROL_PROTOCOL_USER_ID 14
42
43
44 /* Initialize the protocol and registered fields */
45 static int proto_h248                   = -1;
46 static int hf_h248_mtpaddress_ni        = -1;
47 static int hf_h248_mtpaddress_pc        = -1;
48 static int hf_h248_pkg_name             = -1;
49 static int hf_248_pkg_param             = -1;
50 static int hf_h248_event_name           = -1;
51 static int hf_h248_signal_name          = -1;
52 static int hf_h248_signal_code          = -1;
53 static int hf_h248_event_code           = -1;
54 static int hf_h248_pkg_bcp_BNCChar_PDU  = -1;
55
56
57
58 static int hf_h248_context_id = -1;
59 static int hf_h248_error_code = -1;
60 static int hf_h248_term_wild_type = -1;
61 static int hf_h248_term_wild_level = -1;
62 static int hf_h248_term_wild_position = -1;
63
64 static int hf_h248_no_pkg = -1;
65 static int hf_h248_no_sig = -1;
66 static int hf_h248_no_evt = -1;
67 static int hf_h248_param = -1;
68
69 static int hf_h248_serviceChangeReasonStr = -1;
70
71 /* h248v1 support */
72 static int hf_h248_auditValueReplyV1 = -1;
73
74 #include "packet-h248-hf.c"
75
76 /* Initialize the subtree pointers */
77 static gint ett_h248 = -1;
78 static gint ett_mtpaddress = -1;
79 static gint ett_packagename = -1;
80 static gint ett_codec = -1;
81 static gint ett_wildcard = -1;
82
83 static gint ett_h248_no_pkg = -1;
84 static gint ett_h248_no_sig = -1;
85 static gint ett_h248_no_evt = -1;
86
87 static int h248_tap = -1;
88
89 static gcp_hf_ett_t h248_arrel = {{-1,-1,-1,-1,-1,-1},{-1,-1,-1,-1}};
90
91 #include "packet-h248-ett.c"
92
93 static dissector_handle_t h248_term_handle;
94
95 static emem_tree_t* msgs = NULL;
96 static emem_tree_t* trxs = NULL;
97 static emem_tree_t* ctxs_by_trx = NULL;
98 static emem_tree_t* ctxs = NULL;
99
100 static gboolean keep_persistent_data = FALSE;
101 static guint    global_udp_port = 2945;
102 static guint    global_tcp_port = 2945;
103 static gboolean h248_desegment = TRUE;
104
105
106
107 static proto_tree *h248_tree;
108 static tvbuff_t* h248_tvb;
109
110 static dissector_handle_t h248_handle;
111 static dissector_handle_t h248_term_handle;
112 static dissector_handle_t h248_tpkt_handle;
113
114 /* Forward declarations */
115 static int dissect_h248_ServiceChangeReasonStr(gboolean implicit_tag, tvbuff_t *tvb, int offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index);
116
117 /* h248v1 support */
118 static int dissect_h248_AuditReplyV1(gboolean implicit_tag, tvbuff_t *tvb, int offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index);
119 static int dissect_h248_ValueV1(gboolean implicit_tag, tvbuff_t *tvb, int offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index);
120 static int dissect_h248_EventParameterV1(gboolean implicit_tag, tvbuff_t *tvb, int offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index);
121 static int dissect_h248_PropertyParmV1(gboolean implicit_tag, tvbuff_t *tvb, int offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index);
122 static int dissect_h248_SigParameterV1(gboolean implicit_tag, tvbuff_t *tvb, int offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index);
123
124 /* 2010-11-15: New entries added based on: http://www.iana.org/assignments/megaco-h248 last updated 2010-10-01 */
125 static const value_string package_name_vals[] = {
126     {   0x0000, "Media stream properties H.248.1 Annex C" },
127     {   0x0001, "Generic H.248.1 Annex E" },
128     {   0x0002, "root H.248.1 Annex E" },
129     {   0x0003, "tonegen H.248.1 Annex E" },
130     {   0x0004, "tonedet H.248.1 Annex E" },
131     {   0x0005, "dg H.248.1 Annex E" },
132     {   0x0006, "dd H.248.1 Annex E" },
133     {   0x0007, "cg H.248.1 Annex E" },
134     {   0x0008, "cd H.248.1 Annex E" },
135     {   0x0009, "al H.248.1 Annex E" },
136     {   0x000a, "ct H.248.1 Annex E" },
137     {   0x000b, "nt H.248.1 Annex E" },
138     {   0x000c, "rtp H.248.1 Annex E" },
139     {   0x000d, "tdmc H.248.1 Annex E" },
140     {   0x000e, "ftmd H.248.1 Annex E" },
141     {   0x000f, "txc H.248.2" },                                          /* H.248.2 */
142     {   0x0010, "txp H.248.2" },
143     {   0x0011, "ctyp H.248.2" },
144     {   0x0012, "fax H.248.2" },
145     {   0x0013, "ipfax H.248.2" },
146     {   0x0014, "dis H.248.3" },                                          /* H.248.3 */
147     {   0x0015, "key H.248.3" },
148     {   0x0016, "kp H.248.3" },
149     {   0x0017, "labelkey H.248.3" },
150     {   0x0018, "kf H.248.3" },
151     {   0x0019, "ind H.248.3" },
152     {   0x001a, "ks H.248.3" },
153     {   0x001b, "anci H.248.3" },
154     {   0x001c, "dtd H.248.6" },                                              /* H.248.6 */
155     {   0x001d, "an H.248.7" },                                               /* H.248.7 */
156     {   0x001e, "Bearer Characteristics Q.1950 Annex A" },                    /* Q.1950 Annex A */
157     {   0x001f, "Bearer Network Connection Cut Q.1950 Annex A" },
158     {   0x0020, "Reuse Idle Q.1950 Annex A" },
159     {   0x0021, "Generic Bearer Connection Q.1950 Annex A" },
160     {   0x0022, "Bearer Control Tunnelling Q.1950 Annex A" },
161     {   0x0023, "Basic Call Progress Tones Q.1950 Annex A" },
162     {   0x0024, "Expanded Call Progress Tones Q.1950 Annex A" },
163     {   0x0025, "Basic Services Tones Q.1950 Annex A" },
164     {   0x0026, "Expanded Services Tones Q.1950 Annex A" },
165     {   0x0027, "Intrusion Tones Q.1950 Annex A" },
166     {   0x0028, "Business Tones Q.1950 Annex A" },
167     {   0x0029, "Media Gateway Resource Congestion Handling H.248.10" },      /* H.248.10 */
168     {   0x002a, "H245 package H248.12" },                                     /* H.248.12 */
169     {   0x002b, "H323 bearer control package H.248.12" },                     /* H.248.12 */
170     {   0x002c, "H324 package H.248.12" },                                    /* H.248.12 */
171     {   0x002d, "H245 command package H.248.12" },                            /* H.248.12 */
172     {   0x002e, "H245 indication package H.248.12" },                         /* H.248.12 */
173     {   0x002f, "3G User Plane" },                                            /* 3GPP TS 29.232 v4.1.0 */
174     {   0x0030, "3G Circuit Switched Data" },
175     {   0x0031, "3G TFO Control" },
176     {   0x0032, "3G Expanded Call Progress Tones" },
177     {   0x0033, "Advanced Audio Server (AAS Base)" },                         /* H.248.9 */
178     {   0x0034, "AAS Digit Collection" },                                     /* H.248.9 */
179     {   0x0035, "AAS Recording" },                                            /* H.248.9 */
180     {   0x0036, "AAS Segment Management" },                                   /* H.248.9 */
181     {   0x0037, "Quality Alert Ceasing" },                                    /* H.248.13 */
182     {   0x0038, "Conferencing Tones Generation" },                            /* H.248.27 */
183     {   0x0039, "Diagnostic Tones Generation" },                              /* H.248.27 */
184     {   0x003a, "Carrier Tones Generation Package H.248.23" },                /* H.248.27 */
185     {   0x003b, "Enhanced Alerting Package H.248.23" },                       /* H.248.23 */
186     {   0x003c, "Analog Display Signalling Package H.248.23" },               /* H.248.23 */
187     {   0x003d, "Multi-Frequency Tone Generation Package H.248.24" },         /* H.248.24 */
188     {   0x003e, "H.248.23Multi-Frequency Tone Detection Package H.248.24" },  /* H.248.24 */
189     {   0x003f, "Basic CAS Package H.248.25" },                               /* H.248.25 */
190     {   0x0040, "Robbed Bit Signalling Package H.248.25" },                   /* H.248.25 */
191     {   0x0041, "Operator Services and Emergency Services Package H.248.25" },
192     {   0x0042, "Operator Services Extension Package H.248.25" },
193     {   0x0043, "Extended Analog Line Supervision Package H.248.26" },
194     {   0x0044, "Automatic Metering Package H.248.26" },
195     {   0x0045, "Inactivity Timer Package H.248.14" },
196     {   0x0046, "3G Modification of Link Characteristics Bearer Capability" }, /* 3GPP TS 29.232 v4.4.0 */
197     {   0x0047, "Base Announcement Syntax H.248.9" },
198     {   0x0048, "Voice Variable Syntax H.248.9" },
199     {   0x0049, "Announcement Set Syntax H.248.9" },
200     {   0x004a, "Phrase Variable Syntax H.248.9" },
201     {   0x004b, "Basic NAS package" },
202     {   0x004c, "NAS incoming package" },
203     {   0x004d, "NAS outgoing package" },
204     {   0x004e, "NAS control package" },
205     {   0x004f, "NAS root package" },
206     {   0x0050, "Profile Handling Package H.248.18" },
207     {   0x0051, "Media Gateway Overload Control Package H.248.11" },
208     {   0x0052, "Extended DTMF Detection Package H.248.16" },
209     {   0x0053, "Quiet Termination Line Test" },
210     {   0x0054, "Loopback Line Test Response" },                              /* H.248.17 */
211     {   0x0055, "ITU 404Hz Line Test" },                                      /* H.248.17 */
212     {   0x0056, "ITU 816Hz Line Test" },                                      /* H.248.17 */
213     {   0x0057, "ITU 1020Hz Line Test" },                                     /* H.248.17 */
214     {   0x0058, "ITU 2100Hz Disable Tone Line Test" },                        /* H.248.17 */
215     {   0x0059, "ITU 2100Hz Disable Echo Canceller Tone Line Test" },         /* H.248.17 */
216     {   0x005a, "ITU 2804Hz Tone Line Test" },                                /* H.248.17 */
217     {   0x005b, "ITU Noise Test Tone Line Test" },                            /* H.248.17 */
218     {   0x005c, "ITU Digital Pseudo Random Test Line Test" },                 /* H.248.17 */
219     {   0x005d, "ITU ATME No.2 Test Line Response" },                         /* H.248.17 */
220     {   0x005e, "ANSI 1004Hz Test Tone Line Test" },                          /* H.248.17 */
221     {   0x005f, "ANSI Test Responder Line Test" },                            /* H.248.17 */
222     {   0x0060, "ANSI 2225Hz Test Progress Tone Line Test" },                 /* H.248.17 */
223     {   0x0061, "ANSI Digital Test Signal Line Test" },                       /* H.248.17 */
224     {   0x0062, "ANSI Inverting Loopback Line Test Response" },               /* H.248.17 */
225     {   0x0063, "Extended H.324 Packages H.248.12 Annex A" },
226     {   0x0064, "Extended H.245 Command Package H.248.12 Annex A" },
227     {   0x0065, "Extended H.245 Indication Package H.248.12 Annex A" },
228     {   0x0066, "Enhanced DTMF Detection Package H.248.16" },
229     {   0x0067, "Connection Group Identity Package Q.1950 Annex E" },
230     {   0x0068, "CTM Text Transport 3GPP TS 29.232 v5.2.0" },
231     {   0x0069, "SPNE Control Package Q.115.0" },
232     {   0x006a, "Semi-permanent Connection Package H.248.21" },
233     {   0x006b, "Shared Risk Group Package H.248.22" },
234     {   0x006c, "isuptn Annex B of ITU-T Rec. J.171" },
235     {   0x006d, "Basic CAS Addressing Package H.248.25" },
236     {   0x006e, "Floor Control Package H.248.19" },
237     {   0x006f, "Indication of Being Viewed Package H.248.19" },
238     {   0x0070, "Volume Control Package H.248.19" },
239     {   0x0071, "UNASSIGNED" },
240     {   0x0072, "Volume Detection Package H.248.19" },
241     {   0x0073, "Volume Level Mixing Package H.248.19" },
242     {   0x0074, "Mixing Volume Level Control Package H.248.19" },
243     {   0x0075, "Voice Activated Video Switch Package H.248.19" },
244     {   0x0076, "Lecture Video Mode Package H.248.19" },
245     {   0x0077, "Contributing Video Source Package H.248.19" },
246     {   0x0078, "Video Window Package H.248.19" },
247     {   0x0079, "Tiled Window Package H.248.19" },
248     {   0x007a, "Adaptive Jitter Buffer Package H.248.31" },
249     {   0x007b, "International CAS Package H.248.28" },
250     {   0x007c, "CAS Blocking Package H.248.28" },
251     {   0x007d, "International CAS Compelled Package H.248.29" },
252     {   0x007e, "International CAS Compelled with Overlap Package H.248.29" },
253     {   0x007f, "International CAS Compelled with End-to-end Package H.248.29" },
254     {   0x0080, "RTCP XR Package H.248.30" },
255     {   0x0081, "RTCP XR Burst Metrics Package H.248.30" },
256     {   0x0082, "threegcsden 3G Circuit Switched Data" },                     /* 3GPP TS 29.232 v5.6.0 */
257     {   0x0083, "threegiptra 3G Circuit Switched Data" },                     /* 3GPP TS 29.232 v5.6.0 */
258     {   0x0084, "threegflex 3G Circuit Switched Data" },                      /* 3GPP TS 29.232 v5.6.0 */
259     {   0x0085, "H.248 PCMSB" },
260     {   0x008a, "TIPHON Extended H.248/MEGACO Package" },                     /* ETSI specification TS 101 3 */
261     {   0x008b, "Differentiated Services Package" },                          /* Annex A of ETSI TS 102 333 */
262     {   0x008c, "Gate Management Package" },                                  /* Annex B of ETSI TS 102 333 */
263     {   0x008d, "Traffic Management Package" },                               /* Annex C of ETSI TS 102 333 */
264     {   0x008e, "Gate Recovery Information Package" },                        /* Annex D of ETSI TS 102 333 */
265     {   0x008f, "NAT Traversal Package" },                                    /* Annex E of ETSI TS 102 333 */
266     {   0x0090, "MPLS Package" },                                             /* Annex F of ETSI TS 102 333 */
267     {   0x0091, "VLAN Package" },                                             /* Annex G of ETSI TS 102 333 */
268     {   0x0092, "Detailed Congestion Reporting Package" },                    /* H.248.32 */
269     {   0x0093, "Stimulus Analogue Lines Package" },                          /* H.248.34 */
270     {   0x0094, "icascgen" },                                                 /* H.248.29 Annex B */
271     {   0x0095, "Coin Operated Phone Control Package" },                      /* H.248.35 */
272     {   0x0096, "Metering Pulse Detection Package" },                         /* H.248.26 Amendment 1 */
273     {   0x0097, "Trace Package" },                                            /* 3GPP TS 29.232 v6.3.0 */
274     {   0x0098, "Hanging Termination Package" },                              /* H.248.36 */
275     {   0x0099, "IP NAPT Traversal Package" },                                /* H.248.37 */
276     {   0x009a, "Notification Behaviour Package" },                           /* H.248.1v3 */
277     {   0x009b, "Base Context Package" },                                     /* H.248.38 */
278     {   0x009c, "Application Data Inactivity Detection Package" },            /* H.248.40 */
279     {   0x009d, "Domain Connection Package " },                               /* H.248.41 */
280     {   0x009e, "Digital Circuit Multiplication Equipment Package" },         /* H.248.42 */
281     {   0x009f, "Multi-level Precedence and Pre-emption Package" },           /* H.248.44 */
282     {   0x00a0, "MGC Information Package" },                                  /* H.248.45 */
283     {   0x00a1, "Text Overlay Package" },                                     /* H.248.19 Amendment 1 */
284     {   0x00a2, "Border and Background Package" },                            /* H.248.19 Amendment 1 */
285     {   0x00a3, "Segmentation Package" },                                     /* H.248.1v3 */
286     {   0x00a4, "ETSI notification behaviour package" },                      /* ETSI ES 283 039-3 */
287     {   0x00a5, "ETSI notification rate package" },                           /* ETSI ES 283 039-4 */
288     {   0x00a6, "Automatic Speech Recognition Package" },                     /* H.248.9 Amendment 1 */
289     {   0x00a7, "Set extension to basic syntax for TTS enhancement Package" },/* H.248.9 Amendment 1 */
290     {   0x00a8, "Advanced audio server base package for TTS enhancement" },   /* H.248.9 Amendment 1 */
291     {   0x00a9, "Multimedia Play Package" },                                  /* H.248.9 Amendment 1 */
292     {   0x00aa, "Floor Status Detection Package" },                           /* H.248.19 Amendment 2 */
293     {   0x00ab, "Floor Control Policy Package" },                             /* H.248.19 Amendment 2 */
294     {   0x00ac, "Address Reporting Package" },                                /* H.248.37 Amendment 1 */
295     {   0x00ad, "Connection Capability Control Package" },                    /* H.248.46 */
296     {   0x00ae, "Statistic Conditional Reporting Package" },                  /* H.248.47 Amendment 1 */
297     {   0x00af, "RTCP HR QoS Statistics Package" },                           /* H.248.48 */
298     {   0x00b0, "Received RTCP XR Package" },                                 /* H.248.30 (01/2007) */
299     {   0x00b1, "Received RTCP XR Burst Metrics Package" },                   /* H.248.30 (01/2007) */
300     {   0x00b2, "ASCI Group call package" },                                  /* 3GPP TS 29.232 v7.4.0 */
301     {   0x00b3, "Multimedia Recording Package" },                             /* H.248.9 Amendment 1 */
302     {   0x00b4, "H.245 Transport Package" },                                  /* H.248.12 Amendment 2 */
303     {   0x00b5, "RTCP Handling package" },                                    /* H.248.57 */
304     {   0x00b6, "Gate Management - Outgoing Destination Address/Port Filtering Package" },/* H.248.43 */
305     {   0x00b7, "Gate Management - Incoming Protocol Filtering Package" },    /* H.248.43 */
306     {   0x00b8, "Gate Management - Outgoing Protocol Filtering Package" },    /* H.248.43 */
307     {   0x00b9, "Gate Management - Incoming Filtering Behaviour Package" },   /* H.248.43 */
308     {   0x00ba, "Gate Management - Outgoing Filtering Behaviour Package" },   /* H.248.43 */
309     {   0x00bb, "Session Description Protocol RFC Package" },                 /* H.248.49 */
310     {   0x00bc, "Session Description Protocol Capabilities Package" },        /* H.248.49 */
311     {   0x00bd, "NAT Traversal Toolkit - STUN Base Package" },                /* H.248.50 */
312     {   0x00be, "NAT Traversal Toolkit - MG STUN Client Package" },           /* H.248.50 */
313     {   0x00bf, "NAT Traversal Toolkit - MG TURN Client Package" },           /* H.248.50 */
314     {   0x00c0, "NAT Traversal Toolkit - MGC STUN Client Package" },          /* H.248.50 */
315     {   0x00c1, "NAT Traversal Toolkit - STUN Information Package" },         /* H.248.50 */
316     {   0x00c2, "NAT Traversal Toolkit - MG Act-as STUN Server Package" },    /* H.248.50 */
317     {   0x00c3, "NAT Traversal Toolkit - Originate STUN Continuity Check Package" },  /* H.248.50 */
318     {   0x00c4, "NAT Traversal Toolkit - MGC Originated STUN Request Package" },      /* H.248.50 */
319     {   0x00c5, "NAT Traversal Toolkit - RTP NOOP Request Package" },         /* H.248.50 */
320     {   0x00c6, "Termination Connection Model Package" },                     /* H.248.51 */
321     {   0x00c7, "QoS Class Package" },                                        /* H.248.52 */
322     {   0x00c8, "Traffic Policing Statistics Package" },                      /* H.248.53 */
323     {   0x00c9, "Packet Size Package" },                                      /* H.248.53 */
324     {   0x00ca, "Pull Mode Package" },                                        /* H.248.55 */
325     {   0x00cb, "RTP Application Data Package" },                             /* H.248.58 */
326     {   0x00cc, "Event Timestamp Notification Package" },                     /* H.248.59 */
327     {   0x00cd, "Resource Management Rules Package" },                        /* H.248.63 */
328     {   0x00ce, "Resource Management Configuration Package" },                /* H.248.63 */
329     {   0x00cf, "Abstract Resource Management Packages" },                    /* H.248.63 */
330
331     {   0x00d0, "IP layer octets count statistics Package" },                 /* H.248.61 */
332     {   0x00d1, "Content of Communication Identity Package" },                /* H.248.60 */
333     {   0x00d2, "RSVP extension package" },                                   /* H.248.65 */
334     {   0x00d3, "GCP Transport Mode Indication Package" },                    /* H.248.67 */
335     {   0x00d4, "IP Router Package" },                                        /* H.248.64 */
336     {   0x00d5, "Media Resource Identification Package" },                    /* H.248.66 */
337     {   0x00d6, "Range Format Support Package" },                             /* H.248.66 */
338     {   0x00d7, "Media Resource Description Expiry Package" },                /* H.248.66 */
339     {   0x00d8, "Media Block Size Package" },                                 /* H.248.66 */
340     {   0x00d9, "RTSP Media Resource Syntax Package" },                       /* H.248.66 */
341     {   0x00da, "RTSP Play Package" },                                        /* H.248.66 */
342     {   0x00db, "Signal Pause Package" },                                     /* H.248.66 */
343     {   0x00dc, "Data Delivery Speed Adjustme Package" },                     /* H.248.66 */
344     {   0x00dd, "Playback Relative Scale Adjustment Package" },               /* H.248.66 */
345     {   0x00de, "RTP Information Package" },                                  /* H.248.66 */
346     {   0x00df, "RTP Interleaving Package" },                                 /* H.248.66 */
347     {   0x00e0, "IP Realm Availability Package" },                            /* H.248.41 Amendment 1 */
348     {   0x00e1, "General IP Header QoS Octet Package" },                      /* H.248.52  */
349     {   0x00e2, "Re-answer Package" },                                        /* H.248.62  */
350     {   0x00e3, "3G Interface Type package" },                                /* 3GPP TS 29.232 v8.4.0 */
351     {   0x00e4, "Latch Statistics Package" },                                 /* H.248.37 */
352     {   0x00e5, "Floor Control Signalling Package" },                         /* H.248.19 Amendment 2 */
353     {   0x00e6, "Include Participant in Mix Package" },                       /* H.248.19 Amendment 2 */
354     {   0x00e7, "Speaker Reporting Package" },                                /* H.248.19 Amendment 2 */
355     {   0x00e8, "IP Layer Packet Count Statistics Package" },                 /* H.248.61 */
356     {   0x00e9, "Removal of Digits and Tones Package" },                      /* H.248.68 */
357     {   0x00ea, "MSRP Statistics Package" },                                  /* H.248.69 */
358     {   0x00eb, "MSRP Connection Status Package" },                           /* H.248.69 */
359     {   0x00ec, "Play Message Package" },                                     /* H.248.69 */
360     {   0x00ed, "Delete Stored Message Package" },                            /* H.248.69 */
361     {   0x00ee, "Message Session Information Package" },                      /* H.248.69 */
362     {   0x00ef, "Message Filtering Package" },                                /* H.248.69 */
363     {   0x00f0, "Stored Message Information Package" },                       /* H.248.69 */
364     {   0x00f1, "Record Message Package" },                                   /* H.248.69 */
365     {   0x00f2, "Digit Dialling Method Information Package" },                /* H.248.70 */
366     {   0x00f3, "Digit Dialling Method Information for Extended Digitmap Detection Package" }, /* H.248.70 */
367     {   0x00f4, "Digit Dialling Method Information for Enhanced Digitmap Detection Package" }, /* H.248.70 */
368     {   0x00f5, "Received RTCP Package " },                                   /* H.248.71 */
369     {   0x00f6, "RTP Cumulative Loss Package" },                              /* H.248.71 */
370     {   0x00f7, "H.245 Transport Package for SPC use" },                      /* H.248.72 */
371     {   0x00f8, "MONA Preference Package" },                                  /* H.248.72 */
372     {   0x00f9, "TDM Gain Control Package" },                                 /* H.248.73 */
373     {   0x00fa, "Media Start Package" },                                      /* H.248.74 */
374     {   0x00fb, "Trim Package" },                                             /* H.248.74 */
375     {   0x00fc, "Enhanced Recording Package" },                               /* H.248.74 */
376     {   0x00fd, "Enhanced ASR Package" },                                     /* H.248.74      */
377     {   0x00fe, "Enhanced TTS Package" },                                     /* H.248.74 */
378     {   0x00ff, "Play Offset Control Package" },                              /* H.248.74 */
379     {   0x0100, "Enhanced DTMF Detection Package" },                          /* H.248.9 Revised 2009 */
380     {   0x0101, "IP Router NAT Package" },                                    /* H.248.64 */
381     {   0x0102, "Voice Enrolled Grammar Package" },                           /* H.248.74 */
382     {   0x0103, "Filter Group Package" },                                     /* H.248.76 */
383     {   0x0104, "RTCP Source Description Package" },                          /* H.248.71 */
384     {   0x0105, "Speaker Verification and Identification Package" },          /* H.248.74 */
385     {   0x0106, "Package Identifier Publishing and Application Package" },    /* H.248 */
386     {   0x0107, "Secure RTP Package " },                                      /* H.248.77 */
387     {   0x0108, "MGC Controlled Bearer Level ALG Package" },                  /* H.248.78 */
388     {   0x0109, "Enhanced Revised Offer/Answer SDP Support Package" },        /* H.248.80 */
389     {   0x010a, "Enhanced SDP Media Capabilities Negotiation Support Package" }, /* H.248.80 */
390
391     {   0x8000, "Ericsson IU" },
392     {   0x8001, "Ericsson UMTS and GSM Circuit" },
393     {   0x8002, "Ericsson Tone Generator Package" },
394     {   0x8003, "Ericsson Line Test Package" },
395     {   0x8004, "Nokia Advanced TFO Package" },
396     {   0x8005, "Nokia IWF Package" },
397     {   0x8006, "Nokia Root Package" },
398     {   0x8007, "Nokia Trace Package" },
399     {   0x8008, "Ericsson  V5.2 Layer" },
400     {   0x8009, "Ericsson Detailed Termination Information Package" },
401     {   0x800a, "Nokia Bearer Characteristics Package" },
402     {   0x800b, "Nokia Test Call Package" },
403     {   0x800c, "Nokia Extended Continuity Package" },
404     {   0x800d, "Nokia IPnwR Package" },
405     {   0x800e, "Ericsson Tracing Enhancements Package" },
406     {   0x800f, "Ericsson Partially Wildcarded TerminationID Package" },
407     {   0x8010, "SCTP Stream Handling Package" },
408
409     {0,     NULL}
410 };
411 static value_string_ext package_name_vals_ext = VALUE_STRING_EXT_INIT(package_name_vals);
412
413 /*
414  * This table consist of PackageName + EventName and its's corresponding string
415  *
416  */
417 static const value_string event_name_vals[] = {
418     {   0x00000000, "Media stream properties H.248.1 Annex C" },
419     {   0x00010000, "g H.248.1 Annex E" },
420     {   0x00010001, "g/Cause" },
421     {   0x00010002, "g/Signal Completion" },
422     {   0x00040000, "tonedet H.248.1 Annex E" },
423     {   0x00040001, "tonedet/std(Start tone detected)" },
424     {   0x00040002, "tonedet/etd(End tone detected)" },
425     {   0x00040003, "tonedet/ltd(Long tone detected)" },
426     {   0x00060000, "dd H.248.1 Annex E" },
427     {   0x00060001, "dd/std" },
428     {   0x00060002, "dd/etd" },
429     {   0x00060003, "dd/ltd" },
430     {   0x00060004, "dd, DigitMap Completion Event" },
431     {   0x00060010, "dd/d0, DTMF character 0" },
432     {   0x00060011, "dd/d1, DTMF character 1" },
433     {   0x00060012, "dd/d2, DTMF character 2" },
434     {   0x00060013, "dd/d3, DTMF character 3" },
435     {   0x00060014, "dd/d4, DTMF character 4" },
436     {   0x00060015, "dd/d5, DTMF character 5" },
437     {   0x00060016, "dd/d6, DTMF character 6" },
438     {   0x00060017, "dd/d7, DTMF character 7" },
439     {   0x00060018, "dd/d8, DTMF character 8" },
440     {   0x00060019, "dd/d9, DTMF character 9" },
441     {   0x0006001a, "dd/a, DTMF character A" },
442     {   0x0006001b, "dd/b, DTMF character B" },
443     {   0x0006001c, "dd/c, DTMF character C" },
444     {   0x0006001d, "dd/d, DTMF character D" },
445     {   0x00060020, "dd/*, DTMF character *" },
446     {   0x00060021, "dd/#, DTMF character #" },
447     {   0x00080030, "cd, Dial Tone" },
448     {   0x00080031, "cd, Ringing Tone" },
449     {   0x00080032, "cd, Busy Tone" },
450     {   0x00080033, "cd, Congestion Tone" },
451     {   0x00080034, "cd, Special Information Tone" },
452     {   0x00080035, "cd, (Recording) Warning Tone" },
453     {   0x00080036, "cd, Payphone Recognition Tone" },
454     {   0x00080037, "cd, Call Waiting Tone" },
455     {   0x00080038, "cd, Caller Waiting Tone" },
456     {   0x00090004, "al, onhook" },
457     {   0x00090005, "al, offhook" },
458     {   0x00090006, "al, flashhook" },
459     {   0x0009ffff, "al, *" },
460     {   0x000a0005, "ct, Completion of Continuity test" },
461     {   0x000b0005, "nt, network failure" },
462     {   0x000b0006, "nt, quality alert" },
463     {   0x000c0001, "rtp, Payload Transition" },
464     {   0x00210000, "Generic Bearer Connection Q.1950 Annex A" },
465     {   0x00210001, "GB/BNCChange" },
466     {   0x00220001, "BT/TIND (Tunnel Indication)" },
467     {   0x002a0001, "H.245/h245msg (Incoming H.245 Message)" },
468     {   0x002a0004, "H.245/h245ChC (H.245 Channel Closed)" },
469     {   0x00450000, "Inactivity Timer H.248.14" },
470     {   0x00450001, "it/ito" },
471     {   0x00450002, "it/ito" },
472     {   0x00460001, "threegmlc/mod_link_supp (Bearer Modification Support Event)" },
473     {   0x00980000, "Hanging Termination Package" },
474     {   0x00980001, "Termination Heartbeat" },
475     {   0x800a0000, "Nokia Bearer Characteristics Package" },
476     {0,     NULL}
477 };
478 static value_string_ext event_name_vals_ext = VALUE_STRING_EXT_INIT(event_name_vals);
479
480 /*
481  * This table consist of PackageName + SignalName and its's corresponding string
482  */
483 static const value_string signal_name_vals[] = {
484     {   0x00000000, "Media stream properties H.248.1 Annex C" },
485     {   0x00010000, "g H.248.1 Annex E" },
486     {   0x00030001, "tonegen/pt(Play tone)" },
487     {   0x00050010, "dg, DTMF character 0" },
488     {   0x00050011, "dg, DTMF character 1" },
489     {   0x00050012, "dg, DTMF character 2" },
490     {   0x00050013, "dg, DTMF character 3" },
491     {   0x00050014, "dg, DTMF character 4" },
492     {   0x00050015, "dg, DTMF character 5" },
493     {   0x00050016, "dg, DTMF character 6" },
494     {   0x00050017, "dg, DTMF character 7" },
495     {   0x00050018, "dg, DTMF character 8" },
496     {   0x00050019, "dg, DTMF character 9" },
497     {   0x0005001a, "dg, DTMF character A" },
498     {   0x0005001b, "dg, DTMF character B" },
499     {   0x0005001c, "dg, DTMF character C" },
500     {   0x0005001d, "dg, DTMF character D" },
501     {   0x00050020, "dg, DTMF character *" },
502     {   0x00050021, "dg, DTMF character #" },
503     {   0x00070030, "cg, Dial Tone" },
504     {   0x00070031, "cg/rt (Ringing Tone)" },
505     {   0x00070032, "cg, Busy Tone" },
506     {   0x00070033, "cg, Congestion Tone" },
507     {   0x00070034, "cg, Special Information Tone" },
508     {   0x00070035, "cg, (Recording) Warning Tone" },
509     {   0x00070036, "cg, Payphone Recognition Tone" },
510     {   0x00070037, "cg, Call Waiting Tone" },
511     {   0x00070038, "cg, Caller Waiting Tone" },
512     {   0x00090002, "al, ring" },
513     {   0x0009ffff, "al, *" },
514     {   0x000a0003, "ct, Continuity test" },
515     {   0x000a0004, "ct, Continuity respond" },
516     {   0x00210000, "GB Generic Bearer Connection Q.1950 Annex A" },
517     {   0x00210001, "GB/EstBNC(Establish BNC)" },
518     {   0x00210002, "GB/ModBNC (Modify BNC)" },
519     {   0x00210003, "GB/RelBNC(Release BNC)" },
520
521     {   0x002a0001, "H.245/cs (channel state)" },
522     {   0x002a0002, "H.245/termtype (Terminal Type)" },
523
524     {   0x002c0001, "H.324/cmod (Communication mode)" },
525     {   0x002c0002, "H.324/muxlv (Highest Multiplexing level)" },
526     {   0x002c0003, "H.324/demux (Demultiplex)" },
527     {   0x002c0004, "H.324/h223capr (Remote H.223 capability)" },
528     {   0x002c0005, "H.324/muxtbl_in (Incoming Multiplex Table)" },
529     {   0x002c0006, "H.324/muxtbl_out (Outgoing Multiplex Table)" },
530
531     {   0x800a0000, "Nokia Bearer Characteristics Package" },
532     {0,     NULL}
533 };
534 static value_string_ext signal_name_vals_ext = VALUE_STRING_EXT_INIT(signal_name_vals);
535
536 #if 0
537 static const value_string context_id_type[] = {
538     {NULL_CONTEXT,"0 (Null Context)"},
539     {CHOOSE_CONTEXT,"$ (Choose Context)"},
540     {ALL_CONTEXTS,"* (All Contexts)"},
541     {0,NULL}
542 };
543 #endif
544
545
546
547 static const value_string h248_reasons[] = {
548     { 400, "Syntax error in message"},
549     { 401, "Protocol Error"},
550     { 402, "Unauthorized"},
551     { 403, "Syntax error in transaction request"},
552     { 406, "Version Not Supported"},
553     { 410, "Incorrect identifier"},
554     { 411, "The transaction refers to an unknown ContextId"},
555     { 412, "No ContextIDs available"},
556     { 413, "Number of transactions in message exceeds maximum"},    /* [H.248.8 (08/07)] */
557     { 421, "Unknown action or illegal combination of actions"},
558     { 422, "Syntax Error in Action"},
559     { 430, "Unknown TerminationID"},
560     { 431, "No TerminationID matched a wildcard"},
561     { 432, "Out of TerminationIDs or No TerminationID available"},
562     { 433, "TerminationID is already in a Context"},
563     { 434, "Max number of Terminations in a Context exceeded"},
564     { 435, "Termination ID is not in specified Context"},
565     { 440, "Unsupported or unknown Package"},
566     { 441, "Missing Remote or Local Descriptor"},
567     { 442, "Syntax Error in Command"},
568     { 443, "Unsupported or Unknown Command"},
569     { 444, "Unsupported or Unknown Descriptor"},
570     { 445, "Unsupported or Unknown Property"},
571     { 446, "Unsupported or Unknown Parameter"},
572     { 447, "Descriptor not legal in this command"},
573     { 448, "Descriptor appears twice in a command"},
574     { 449, "Unsupported or Unknown Parameter or Property Value"},
575     { 450, "No such property in this package"},
576     { 451, "No such event in this package"},
577     { 452, "No such signal in this package"},
578     { 453, "No such statistic in this package"},
579     { 454, "No such parameter value in this package"},
580     { 455, "Property illegal in this Descriptor"},
581     { 456, "Property appears twice in this Descriptor"},
582     { 457, "Missing parameter in signal or event"},
583     { 458, "Unexpected Event/Request ID"},
584     { 459, "Unsupported or Unknown Profile"},
585     { 460, "Unable to set statistic on stream"},
586     { 461, "Unsupported or Unknown Profile"},                               /*[H.248.18] */
587
588     { 471, "Implied Add for Multiplex failure"},
589     { 472, "Required Information Missing"},                                 /*[H.248.8 (08/07)] */
590     { 473, "Conflicting Property Values"},                                  /*[H.248.8 (08/07)] */
591     { 474, "Invalid SDP Syntax"},                                           /*[H.248.49] */
592     { 475, "Unable to pause the playout of the signal"},                    /*[H.248.66] */
593     { 476, "Unable to adjust the data delivery speed of the Signal"},       /*[H.248.66] */
594
595     { 477, "Unable to adjust the playback relative scale of the signal"},   /*[H.248.66] */
596
597     { 478, "Behaviour Contradicts Resource Rule"},                          /*[H.248.63] */
598
599     { 500, "Internal software Failure in MG"},
600     { 501, "Not Implemented"},
601     { 502, "Not ready"},
602     { 503, "Service Unavailable"},
603     { 504, "Command Received from unauthorized entity"},
604     { 505, "Transaction Request Received before a Service Change Reply has been received"},
605     { 506, "Number of Transaction Pendings Exceeded"},
606     { 510, "Insufficient resources"},
607     { 511, "Temporarily Busy"},                                     /* [H.248.8 (08/07)] */
608     { 512, "Media Gateway unequipped to detect requested Event"},
609     { 513, "Media Gateway unequipped to generate requested Signals"},
610     { 514, "Media Gateway cannot send the specified announcement"},
611     { 515, "Unsupported Media Type"},
612     { 517, "Unsupported or invalid mode"},
613     { 518, "Event buffer full"},
614     { 519, "Out of space to store digit map"},
615     { 520, "Digit Map undefined in the MG"},
616     { 521, "Termination is ServiceChangeing"},
617     { 522, "Functionality Requested in Topology Triple Not Supported"},
618     { 526, "Insufficient bandwidth"},
619     { 529, "Internal hardware failure in MG"},
620     { 530, "Temporary Network failure"},
621     { 531, "Permanent Network failure"},
622     { 532, "Audited Property, Statistic, Event or Signal does not exist"},
623     { 533, "Response exceeds maximum transport PDU size"},
624     { 534, "Illegal write or read only property"},
625     { 540, "Unexpected initial hook state"},
626     { 541, "Unexpected Spare Bit State"},                               /* [H.248.33] */
627     { 542, "Command is not allowed on this termination"},
628     { 543, "MGC requested event detection timestamp not supported"},    /* [H.248.8 (08/07)] */
629     { 581, "Does Not Exist"},
630     { 600, "Illegal syntax within an announcement specification"},
631     { 601, "Variable type not supported"},
632     { 602, "Variable value out of range"},
633     { 603, "Category not supported"},
634     { 604, "Selector type not supported"},
635     { 605, "Selector value not supported"},
636     { 606, "Unknown segment ID"},
637     { 607, "Mismatch between play specification and provisioned data"},
638     { 608, "Provisioning error"},
639     { 609, "Invalid offset"},
640     { 610, "No free segment IDs"},
641     { 611, "Temporary segment not found"},
642     { 612, "Segment in use"},
643     { 613, "ISP port limit overrun"},
644     { 614, "No modems available"},
645     { 615, "Calling number unacceptable"},
646     { 616, "Called number unacceptable"},
647     { 617, "Reserved for H.248.9 return code"},     /* [H.248.9] */
648     { 618, "Reserved for H.248.9 return code"},     /* [H.248.9] */
649     { 622, "Reserved for H.248.9 return code"},     /* [H.248.9] */
650     { 623, "Reserved for H.248.9 return code"},     /* [H.248.9] */
651     { 624, "Reserved for H.248.9 return code"},     /* [H.248.9] */
652     { 625, "Reserved for H.248.9 return code"},     /* [H.248.9 Amendment 1] */
653     { 626, "Reserved for H.248.9 return code"},     /* [H.248.9 Amendment 1] */
654     { 627, "Reserved for H.248.9 return code"},     /* [H.248.9 Amendment 1] */
655     { 628, "Reserved for H.248.9 return code"},     /* [H.248.9 Amendment 1] */
656     { 629, "Reserved for H.248.9 return code"},     /* [H.248.9 Amendment 1] */
657     { 700, "Sieve Script Syntax Error"},            /* [H.248.69] */
658     { 701, "Unsupported Sieve Require Error"},      /* [H.248.69] */
659     { 702, "Sieve Actions Exceeded Error"},         /* [H.248.69] */
660
661     { 900, "Service Restored"},
662     { 901, "Cold Boot"},
663     { 902, "Warm Boot"},
664     { 903, "MGC Directed Change"},
665     { 904, "Termination malfunctioning"},
666     { 905, "Termination taken out of service"},
667     { 906, "Loss of lower layer connectivity (e.g. downstream sync)"},
668     { 907, "Transmission Failure"},
669     { 908, "MG Impending Failure"},
670     { 909, "MGC Impending Failure"},
671     { 910, "Media Capability Failure"},
672     { 911, "Modem Capability Failure"},
673     { 912, "Mux Capability Failure"},
674     { 913, "Signal Capability Failure"},
675     { 914, "Event Capability Failure"},
676     { 915, "State Loss"},
677     { 916, "Packages Change"},
678     { 917, "Capabilities Change"},
679     { 918, "Cancel Graceful"},
680     { 919, "Warm Failover"},
681     { 920, "Cold Failover"},
682     {0,NULL}
683 };
684 static value_string_ext h248_reasons_ext = VALUE_STRING_EXT_INIT(h248_reasons);
685
686 static const value_string wildcard_modes[] = {
687     { 0, "Choose" },
688     { 1, "All" },
689     { 0, NULL }
690 };
691
692 static const value_string wildcard_levels[] = {
693     { 0, "This One Level" },
694     { 1, "This Level and those below" },
695     { 0, NULL }
696 };
697
698 static h248_curr_info_t curr_info = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
699 static guint32 error_code;
700 static guint32 h248_version = 0; /* h248v1 support */
701 static gcp_wildcard_t wild_term;
702 static guint8 wild_card = 0xFF; /* place to store wildcardField */
703
704 extern void h248_param_ber_integer(proto_tree* tree, tvbuff_t* tvb, packet_info* pinfo, int hfid, h248_curr_info_t* u _U_, void* implicit) {
705     asn1_ctx_t asn1_ctx;
706     asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
707     dissect_ber_integer(implicit ? *((gboolean*)implicit) : FALSE, &asn1_ctx, tree, tvb, 0, hfid, NULL);
708 }
709
710 extern void h248_param_ber_octetstring(proto_tree* tree, tvbuff_t* tvb, packet_info* pinfo, int hfid, h248_curr_info_t* u _U_, void* implicit) {
711     asn1_ctx_t asn1_ctx;
712     asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
713     dissect_ber_octet_string(implicit ? *((gboolean*)implicit) : FALSE, &asn1_ctx, tree, tvb, 0, hfid, NULL);
714 }
715
716 extern void h248_param_ber_boolean(proto_tree* tree, tvbuff_t* tvb, packet_info* pinfo, int hfid, h248_curr_info_t* u _U_, void* implicit) {
717     asn1_ctx_t asn1_ctx;
718     asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
719     dissect_ber_boolean(implicit ? *((gboolean*)implicit) : FALSE, &asn1_ctx, tree, tvb, 0, hfid, NULL);
720 }
721
722 extern void h248_param_item(proto_tree* tree,
723                              tvbuff_t* tvb,
724                              packet_info* pinfo _U_,
725                              int hfid,
726                              h248_curr_info_t* h248_info _U_,
727                              void* lenp ) {
728     int len = lenp ? *((int*)lenp) : -1;
729     proto_tree_add_item(tree,hfid,tvb,0,len,FALSE);
730 }
731
732 extern void h248_param_external_dissector(proto_tree* tree, tvbuff_t* tvb, packet_info* pinfo , int hfid _U_, h248_curr_info_t* u _U_, void* dissector_hdl) {
733     call_dissector((dissector_handle_t) dissector_hdl,tvb,pinfo,tree);
734 }
735
736
737 static const h248_package_t no_package = { 0xffff, &hf_h248_no_pkg, &ett_h248_no_pkg, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
738 static const h248_pkg_sig_t no_signal = { 0, &hf_h248_no_sig, &ett_h248_no_sig, NULL, NULL };
739 static const h248_pkg_param_t no_param = { 0, &hf_h248_param, h248_param_item,  NULL };
740 static const h248_pkg_evt_t no_event = { 0, &hf_h248_no_evt, &ett_h248_no_evt, NULL, NULL };
741
742 static GPtrArray* packages = NULL;
743
744 extern void h248_param_PkgdName(proto_tree* tree, tvbuff_t* tvb, packet_info* pinfo , int hfid _U_, h248_curr_info_t* u1 _U_, void* u2 _U_) {
745     tvbuff_t *new_tvb = NULL;
746     proto_tree *package_tree=NULL;
747     guint16 name_major, name_minor;
748     int old_offset;
749     const h248_package_t* pkg = NULL;
750     guint i;
751     int offset = 0;
752     asn1_ctx_t asn1_ctx;
753     asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
754
755     old_offset=offset;
756     offset = dissect_ber_octet_string(FALSE, &asn1_ctx, tree, tvb, offset, hfid , &new_tvb);
757
758     if (new_tvb) {
759         /* this field is always 4 bytes  so just read it into two integers */
760         name_major=tvb_get_ntohs(new_tvb, 0);
761         name_minor=tvb_get_ntohs(new_tvb, 2);
762
763         /* do the prettification */
764         proto_item_append_text(asn1_ctx.created_item, "  %s (%04x)",
765                                val_to_str_ext_const(name_major, &package_name_vals_ext, "Unknown Package"),
766                                name_major);
767
768         if(tree){
769             proto_item* pi;
770             const gchar* strval;
771
772             package_tree = proto_item_add_subtree(asn1_ctx.created_item, ett_packagename);
773             proto_tree_add_uint(package_tree, hf_h248_pkg_name, tvb, offset-4, 2, name_major);
774
775             for(i=0; i < packages->len; i++) {
776                 pkg = g_ptr_array_index(packages,i);
777
778                 if (name_major == pkg->id) {
779                     break;
780                 } else {
781                     pkg = NULL;
782                 }
783             }
784
785             if (! pkg ) pkg = &no_package;
786
787
788             pi = proto_tree_add_uint(package_tree, hf_248_pkg_param, tvb, offset-2, 2, name_minor);
789
790             if (pkg->signal_names && ( strval = match_strval(name_minor, pkg->signal_names) )) {
791                 strval = ep_strdup_printf("%s (%d)",strval,name_minor);
792             } else {
793                 strval = ep_strdup_printf("Unknown (%d)",name_minor);
794             }
795
796             proto_item_set_text(pi,"Signal ID: %s", strval);
797         }
798
799     }
800 }
801
802
803 static int dissect_h248_trx_id(gboolean implicit_tag, packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, guint32* trx_id_p) {
804     guint64 trx_id = 0;
805     gint8 class;
806     gboolean pc;
807     gint32 tag;
808     guint32 len;
809     guint32 i;
810
811     if(!implicit_tag){
812         offset=dissect_ber_identifier(pinfo, tree, tvb, offset, &class, &pc, &tag);
813         offset=dissect_ber_length(pinfo, tree, tvb, offset, &len, NULL);
814     } else {
815         len=tvb_length_remaining(tvb, offset);
816     }
817
818
819     if (len > 8 || len < 1) {
820         THROW(BoundsError);
821     } else {
822         for(i=1;i<=len;i++){
823             trx_id=(trx_id<<8)|tvb_get_guint8(tvb, offset);
824             offset++;
825         }
826         if (trx_id > 0xffffffff) {
827             proto_item* pi = proto_tree_add_text(tree, tvb, offset-len, len,"transactionId %" G_GINT64_MODIFIER "u", trx_id);
828             proto_item_set_expert_flags(pi, PI_MALFORMED, PI_WARN);
829
830             *trx_id_p = 0;
831
832         } else {
833             proto_tree_add_uint(tree, hf_h248_transactionId, tvb, offset-len, len, (guint32)trx_id);
834             *trx_id_p = (guint32)trx_id;
835         }
836     }
837
838     return offset;
839 }
840
841 static int dissect_h248_ctx_id(gboolean implicit_tag, packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, guint32* ctx_id_p) {
842     gint8 class;
843     gboolean pc;
844     gint32 tag;
845     guint32 len;
846     guint64 ctx_id = 0;
847     guint32 i;
848
849     if(!implicit_tag){
850         offset=dissect_ber_identifier(pinfo, tree, tvb, offset, &class, &pc, &tag);
851         offset=dissect_ber_length(pinfo, tree, tvb, offset, &len, NULL);
852     } else {
853         len=tvb_length_remaining(tvb, offset);
854     }
855
856
857     if (len > 8 || len < 1) {
858         THROW(BoundsError);
859     } else {
860         for(i=1;i<=len;i++){
861             ctx_id=(ctx_id<<8)|tvb_get_guint8(tvb, offset);
862             offset++;
863         }
864
865         if (ctx_id > 0xffffffff) {
866             proto_item* pi = proto_tree_add_text(tree, tvb, offset-len, len,
867                                                  "contextId: %" G_GINT64_MODIFIER "u", ctx_id);
868             proto_item_set_expert_flags(pi, PI_MALFORMED, PI_WARN);
869
870             *ctx_id_p = 0xfffffffd;
871
872         } else {
873             proto_item* pi = proto_tree_add_uint(tree, hf_h248_context_id, tvb, offset-len, len, (guint32)ctx_id);
874
875             if ( ctx_id ==  NULL_CONTEXT ) {
876                 proto_item_set_text(pi,"contextId: Null Context(0)");
877             } else if ( ctx_id ==  CHOOSE_CONTEXT ) {
878                 proto_item_set_text(pi,"contextId: $ (Choose Context = 0xfffffffe)");
879             } else if ( ctx_id ==  ALL_CONTEXTS ) {
880                 proto_item_set_text(pi,"contextId: * (All Contexts = 0xffffffff)");
881             }
882
883             *ctx_id_p = (guint32) ctx_id;
884         }
885     }
886
887     return offset;
888 }
889
890 void h248_register_package(const h248_package_t* pkg) {
891     if (! packages) packages = g_ptr_array_new();
892
893     g_ptr_array_add(packages,(void*)pkg);
894 }
895
896 static guint32 packageandid;
897
898 static int dissect_h248_PkgdName(gboolean implicit_tag, tvbuff_t *tvb, int offset, asn1_ctx_t *actx _U_, proto_tree *tree, int hf_index) {
899     tvbuff_t *new_tvb = NULL;
900     proto_tree *package_tree=NULL;
901     guint16 name_major, name_minor;
902     int old_offset;
903     const h248_package_t* pkg = NULL;
904     guint i;
905
906     old_offset=offset;
907     offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index, &new_tvb);
908
909     if (new_tvb) {
910         /* this field is always 4 bytes  so just read it into two integers */
911         name_major=tvb_get_ntohs(new_tvb, 0);
912         name_minor=tvb_get_ntohs(new_tvb, 2);
913         packageandid=(name_major<<16)|name_minor;
914
915         /* do the prettification */
916         proto_item_append_text(actx->created_item, "  %s (%04x)",
917                                val_to_str_ext_const(name_major, &package_name_vals_ext, "Unknown Package"),
918                                name_major);
919
920         if(tree){
921             package_tree = proto_item_add_subtree(actx->created_item, ett_packagename);
922             proto_tree_add_uint(package_tree, hf_h248_pkg_name, tvb, offset-4, 2, name_major);
923         }
924
925         for(i=0; i < packages->len; i++) {
926             pkg = g_ptr_array_index(packages,i);
927
928             if (name_major == pkg->id) {
929                 break;
930             } else {
931                 pkg = NULL;
932             }
933         }
934
935         if (! pkg ) pkg = &no_package;
936
937         {
938             proto_item* pi = proto_tree_add_uint(package_tree, hf_248_pkg_param, tvb, offset-2, 2, name_minor);
939             const gchar* strval;
940
941             if (pkg->param_names && ( strval = match_strval(name_minor, pkg->param_names) )) {
942                 strval = ep_strdup_printf("%s (%d)",strval,name_minor);
943             } else {
944                 strval = ep_strdup_printf("Unknown (%d)",name_minor);
945             }
946
947             proto_item_set_text(pi,"Parameter: %s", strval);
948         }
949     } else {
950         pkg = &no_package;
951     }
952
953     curr_info.pkg = pkg;
954
955     return offset;
956 }
957
958 static int dissect_h248_EventName(gboolean implicit_tag, tvbuff_t *tvb, int offset, asn1_ctx_t *actx _U_, proto_tree *tree, int hf_index) {
959     tvbuff_t *new_tvb;
960     proto_tree *package_tree=NULL;
961     guint16 name_major, name_minor;
962     int old_offset;
963     const h248_package_t* pkg = NULL;
964     const h248_pkg_evt_t* evt = NULL;
965     guint i;
966
967     old_offset=offset;
968     offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index, &new_tvb);
969
970     if (new_tvb) {
971         /* this field is always 4 bytes  so just read it into two integers */
972         name_major=tvb_get_ntohs(new_tvb, 0);
973         name_minor=tvb_get_ntohs(new_tvb, 2);
974         packageandid=(name_major<<16)|name_minor;
975
976         /* do the prettification */
977         proto_item_append_text(actx->created_item, "  %s (%04x)",
978                                val_to_str_ext_const(name_major, &package_name_vals_ext, "Unknown Package"),
979                                name_major);
980         if(tree){
981             package_tree = proto_item_add_subtree(actx->created_item, ett_packagename);
982         }
983         proto_tree_add_uint(package_tree, hf_h248_pkg_name, tvb, offset-4, 2, name_major);
984
985
986         for(i=0; i < packages->len; i++) {
987             pkg = g_ptr_array_index(packages,i);
988
989             if (name_major == pkg->id) {
990                 break;
991             } else {
992                 pkg = NULL;
993             }
994         }
995
996         if (! pkg ) pkg = &no_package;
997
998         curr_info.pkg = pkg;
999
1000         if (pkg->events) {
1001             for (evt = pkg->events; evt->hfid; evt++) {
1002                 if (name_minor == evt->id) {
1003                     break;
1004                 }
1005             }
1006
1007             if (! evt->hfid) evt = &no_event;
1008         } else {
1009             evt = &no_event;
1010         }
1011
1012         curr_info.evt = evt;
1013
1014         {
1015             proto_item* pi = proto_tree_add_uint(package_tree, hf_h248_event_code, tvb, offset-2, 2, name_minor);
1016             const gchar* strval;
1017
1018             if (pkg->event_names && ( strval = match_strval(name_minor, pkg->event_names) )) {
1019                 strval = ep_strdup_printf("%s (%d)",strval,name_minor);
1020             } else {
1021                 strval = ep_strdup_printf("Unknown (%d)",name_minor);
1022             }
1023
1024             proto_item_set_text(pi,"Event ID: %s", strval);
1025         }
1026
1027     } else {
1028         curr_info.pkg = &no_package;
1029         curr_info.evt = &no_event;
1030     }
1031
1032     return offset;
1033 }
1034
1035
1036
1037 static int dissect_h248_SignalName(gboolean implicit_tag , tvbuff_t *tvb, int offset,  asn1_ctx_t *actx _U_, proto_tree *tree, int hf_index) {
1038     tvbuff_t *new_tvb;
1039     proto_tree *package_tree=NULL;
1040     guint16 name_major, name_minor;
1041     int old_offset;
1042     const h248_package_t* pkg = NULL;
1043     const h248_pkg_sig_t* sig;
1044     guint i;
1045
1046     old_offset=offset;
1047     offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index, &new_tvb);
1048
1049     if (new_tvb) {
1050         /* this field is always 4 bytes so just read it into two integers */
1051         name_major=tvb_get_ntohs(new_tvb, 0);
1052         name_minor=tvb_get_ntohs(new_tvb, 2);
1053         packageandid=(name_major<<16)|name_minor;
1054
1055         /* do the prettification */
1056         proto_item_append_text(actx->created_item, "  %s (%04x)",
1057                                val_to_str_ext_const(name_major, &package_name_vals_ext, "Unknown Package"),
1058                                name_major);
1059         if(tree){
1060             package_tree = proto_item_add_subtree(actx->created_item, ett_packagename);
1061         }
1062         proto_tree_add_uint(package_tree, hf_h248_pkg_name, tvb, offset-4, 2, name_major);
1063
1064         for(i=0; i < packages->len; i++) {
1065             pkg = g_ptr_array_index(packages,i);
1066
1067             if (name_major == pkg->id) {
1068                 break;
1069             } else {
1070                 pkg = NULL;
1071             }
1072         }
1073
1074         if (! pkg ) pkg = &no_package;
1075
1076         if (pkg->signals) {
1077             for (sig = pkg->signals; sig->hfid; sig++) {
1078                 if (name_minor == sig->id) {
1079                     break;
1080                 }
1081             }
1082
1083             if (! sig->hfid) sig = &no_signal;
1084
1085             curr_info.pkg = pkg;
1086             curr_info.sig = sig;
1087         } else {
1088             curr_info.pkg = &no_package;
1089             curr_info.sig = &no_signal;
1090         }
1091
1092         {
1093             proto_item* pi = proto_tree_add_uint(package_tree, hf_h248_signal_code, tvb, offset-2, 2, name_minor);
1094             const gchar* strval;
1095
1096             if (pkg->signal_names && ( strval = match_strval(name_minor, pkg->signal_names) )) {
1097                 strval = ep_strdup_printf("%s (%d)",strval,name_minor);
1098             } else {
1099                 strval = ep_strdup_printf("Unknown (%d)",name_minor);
1100             }
1101
1102             proto_item_set_text(pi,"Signal ID: %s", strval);
1103         }
1104
1105     } else {
1106         curr_info.pkg = &no_package;
1107         curr_info.sig = &no_signal;
1108     }
1109
1110     return offset;
1111 }
1112
1113 static int dissect_h248_PropertyID(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset,  asn1_ctx_t *actx _U_, proto_tree *tree, int hf_index _U_) {
1114
1115     gint8 class;
1116     gboolean pc, ind;
1117     gint32 tag;
1118     guint32 len;
1119     guint16 name_major;
1120     guint16 name_minor;
1121     int old_offset, end_offset;
1122     tvbuff_t *next_tvb;
1123     const h248_package_t* pkg;
1124     const h248_pkg_param_t* prop;
1125
1126     old_offset=offset;
1127     offset=dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &class, &pc, &tag);
1128     offset=dissect_ber_length(actx->pinfo, tree, tvb, offset, &len, &ind);
1129     end_offset=offset+len;
1130
1131     if( (class!=BER_CLASS_UNI)
1132       ||(tag!=BER_UNI_TAG_OCTETSTRING) ){
1133         proto_tree_add_text(tree, tvb, offset-2, 2, "H.248 BER Error: OctetString expected but Class:%d PC:%d Tag:%d was unexpected", class, pc, tag);
1134         return end_offset;
1135     }
1136
1137
1138     next_tvb = tvb_new_subset(tvb, offset , len , len );
1139     name_major = packageandid >> 16;
1140     name_minor = packageandid & 0xffff;
1141
1142     pkg = (curr_info.pkg) ? curr_info.pkg : &no_package;
1143
1144     if (pkg->properties) {
1145         for (prop = pkg->properties; prop && prop->hfid; prop++) {
1146             if (name_minor == prop->id) {
1147                 break;
1148             }
1149         }
1150     } else {
1151         prop = &no_param;
1152     }
1153
1154     if (prop && prop->hfid ) {
1155         if (!prop->dissector) prop = &no_param;
1156         prop->dissector(tree, next_tvb, actx->pinfo, *(prop->hfid), &curr_info, prop->data);
1157     }
1158
1159     return end_offset;
1160 }
1161
1162
1163 static int dissect_h248_SigParameterName(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset,  asn1_ctx_t *actx _U_, proto_tree *tree, int hf_index _U_) {
1164     tvbuff_t *next_tvb;
1165     guint32 param_id = 0xffffffff;
1166     const h248_pkg_param_t* sigpar;
1167     const gchar* strval;
1168     proto_item* pi;
1169
1170     offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset,  hf_index, &next_tvb);
1171     pi = actx->created_item;
1172
1173     switch(tvb_length(next_tvb)) {
1174         case 4: param_id = tvb_get_ntohl(next_tvb,0); break;
1175         case 3: param_id = tvb_get_ntoh24(next_tvb,0); break;
1176         case 2: param_id = tvb_get_ntohs(next_tvb,0); break;
1177         case 1: param_id = tvb_get_guint8(next_tvb,0); break;
1178         default: break;
1179     }
1180
1181     curr_info.par = &no_param;
1182
1183     if (curr_info.sig && curr_info.sig->parameters) {
1184         for(sigpar = curr_info.sig->parameters; sigpar->hfid; sigpar++) {
1185             if (sigpar->id == param_id) {
1186                 curr_info.par = sigpar;
1187                 break;
1188             }
1189         }
1190     }
1191
1192     if (curr_info.sig && curr_info.sig->param_names && ( strval = match_strval(param_id, curr_info.sig->param_names) )) {
1193         strval = ep_strdup_printf("%s (%d)",strval,param_id);
1194     } else {
1195         strval = ep_strdup_printf("Unknown (%d)",param_id);
1196     }
1197
1198     proto_item_set_text(pi,"Parameter: %s", strval);
1199
1200     return offset;
1201 }
1202
1203 static int dissect_h248_SigParamValue(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset,  asn1_ctx_t *actx _U_, proto_tree *tree, int hf_index _U_) {
1204     tvbuff_t *next_tvb;
1205     int old_offset, end_offset;
1206     gint8 class;
1207     gboolean pc, ind;
1208     gint32 tag;
1209     guint32 len;
1210
1211     old_offset=offset;
1212     offset=dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &class, &pc, &tag);
1213     offset=dissect_ber_length(actx->pinfo, tree, tvb, offset, &len, &ind);
1214     end_offset=offset+len;
1215
1216     if( (class!=BER_CLASS_UNI)
1217         ||(tag!=BER_UNI_TAG_OCTETSTRING) ){
1218         proto_tree_add_text(tree, tvb, offset-2, 2, "H.248 BER Error: OctetString expected but Class:%d PC:%d Tag:%d was unexpected", class, pc, tag);
1219         return end_offset;
1220     }
1221
1222
1223     next_tvb = tvb_new_subset(tvb,offset,len,len);
1224
1225     if ( curr_info.par && curr_info.par->dissector) {
1226         curr_info.par->dissector(tree, next_tvb, actx->pinfo, *(curr_info.par->hfid), &curr_info, curr_info.par->data);
1227     }
1228
1229     return end_offset;
1230 }
1231
1232 static int dissect_h248_EventParameterName(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset,  asn1_ctx_t *actx _U_, proto_tree *tree, int hf_index _U_) {
1233     tvbuff_t *next_tvb;
1234     guint32 param_id = 0xffffffff;
1235     const h248_pkg_param_t* evtpar;
1236     const gchar* strval;
1237     proto_item* pi;
1238
1239     offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index, &next_tvb);
1240     pi = actx->created_item;
1241
1242     if (next_tvb) {
1243         switch(tvb_length(next_tvb)) {
1244             case 4: param_id = tvb_get_ntohl(next_tvb,0); break;
1245             case 3: param_id = tvb_get_ntoh24(next_tvb,0); break;
1246             case 2: param_id = tvb_get_ntohs(next_tvb,0); break;
1247             case 1: param_id = tvb_get_guint8(next_tvb,0); break;
1248             default: break;
1249         }
1250     }
1251
1252
1253     curr_info.par = &no_param;
1254
1255     if (curr_info.evt && curr_info.evt->parameters) {
1256         for(evtpar = curr_info.evt->parameters; evtpar->hfid; evtpar++) {
1257             if (evtpar->id == param_id) {
1258                 curr_info.par = evtpar;
1259                 break;
1260             }
1261         }
1262     } else {
1263         curr_info.par = &no_param;
1264     }
1265
1266     if (curr_info.evt && curr_info.evt->param_names && ( strval = match_strval(param_id, curr_info.evt->param_names) )) {
1267         strval = ep_strdup_printf("%s (%d)",strval,param_id);
1268     } else {
1269         strval = ep_strdup_printf("Unknown (%d)",param_id);
1270     }
1271
1272     proto_item_set_text(pi,"Parameter: %s", strval);
1273
1274
1275     return offset;
1276 }
1277
1278 static int dissect_h248_EventParamValue(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset,  asn1_ctx_t *actx _U_, proto_tree *tree, int hf_index _U_) {
1279     tvbuff_t *next_tvb;
1280     int old_offset, end_offset;
1281     gint8 class;
1282     gboolean pc, ind;
1283     gint32 tag;
1284     guint32 len;
1285
1286     old_offset=offset;
1287     offset=dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &class, &pc, &tag);
1288     offset=dissect_ber_length(actx->pinfo, tree, tvb, offset, &len, &ind);
1289     end_offset=offset+len;
1290
1291     if( (class!=BER_CLASS_UNI)
1292         ||(tag!=BER_UNI_TAG_OCTETSTRING) ){
1293         proto_tree_add_text(tree, tvb, offset-2, 2, "H.248 BER Error: OctetString expected but Class:%d PC:%d Tag:%d was unexpected", class, pc, tag);
1294         return end_offset;
1295     }
1296
1297
1298     next_tvb = tvb_new_subset(tvb,offset,len,len);
1299
1300     if ( curr_info.par && curr_info.par->dissector) {
1301         curr_info.par->dissector(tree, next_tvb, actx->pinfo, *(curr_info.par->hfid), &curr_info, curr_info.par->data);
1302     }
1303
1304     return end_offset;
1305 }
1306
1307 static int dissect_h248_MtpAddress(gboolean implicit_tag, tvbuff_t *tvb, int offset,  asn1_ctx_t *actx _U_, proto_tree *tree, int hf_index) {
1308     tvbuff_t *new_tvb;
1309     proto_tree *mtp_tree=NULL;
1310     guint32 val;
1311     int i, len, old_offset;
1312
1313     old_offset=offset;
1314     offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index, &new_tvb);
1315
1316     if (new_tvb) {
1317         /* this field is either 2 or 4 bytes  so just read it into an integer */
1318         val=0;
1319         len=tvb_length(new_tvb);
1320         for(i=0;i<len;i++){
1321             val= (val<<8)|tvb_get_guint8(new_tvb, i);
1322         }
1323
1324         /* do the prettification */
1325         proto_item_append_text(actx->created_item, "  NI = %d, PC = %d ( %d-%d )", val&0x03,val>>2,val&0x03,val>>2);
1326         if(tree){
1327             mtp_tree = proto_item_add_subtree(actx->created_item, ett_mtpaddress);
1328         }
1329         proto_tree_add_uint(mtp_tree, hf_h248_mtpaddress_ni, tvb, old_offset, offset-old_offset, val&0x03);
1330         proto_tree_add_uint(mtp_tree, hf_h248_mtpaddress_pc, tvb, old_offset, offset-old_offset, val>>2);
1331     }
1332
1333     return offset;
1334 }
1335
1336 #define H248_TAP() do { if (keep_persistent_data && curr_info.cmd) tap_queue_packet(h248_tap, actx->pinfo, curr_info.cmd); } while(0)
1337
1338 #include "packet-h248-fn.c"
1339
1340 static void dissect_h248_tpkt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
1341     dissect_tpkt_encap(tvb, pinfo, tree, h248_desegment, h248_handle);
1342 }
1343
1344 static void
1345 dissect_h248(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1346 {
1347     proto_item *h248_item;
1348     asn1_ctx_t asn1_ctx;
1349     h248_tree = NULL;
1350     h248_tvb = NULL;
1351
1352     asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
1353
1354     curr_info.msg = NULL;
1355     curr_info.trx = NULL;
1356     curr_info.ctx = NULL;
1357     curr_info.cmd = NULL;
1358     curr_info.term = NULL;
1359     curr_info.pkg = NULL;
1360     curr_info.evt = NULL;
1361     curr_info.sig = NULL;
1362     curr_info.stat = NULL;
1363     curr_info.par = NULL;
1364
1365     /* Check if it is actually a text-based H.248 encoding, which we
1366        dissect with the "megaco" dissector in Wireshark.  (Both
1367        encodings are MEGACO (RFC 3015) and both are H.248.)
1368      */
1369     if(tvb_length(tvb)>=6){
1370         if(!tvb_strneql(tvb, 0, "MEGACO", 6)){
1371             static dissector_handle_t megaco_handle=NULL;
1372             if(!megaco_handle){
1373                 megaco_handle = find_dissector("megaco");
1374             }
1375             if(megaco_handle){
1376                 call_dissector(megaco_handle, tvb, pinfo, tree);
1377                 return;
1378             }
1379         }
1380     }
1381
1382     /* Make entry in the Protocol column on summary display */
1383     col_set_str(pinfo->cinfo, COL_PROTOCOL, "H.248");
1384
1385     if (tree) {
1386         h248_item = proto_tree_add_item(tree, proto_h248, tvb, 0, -1, FALSE);
1387         h248_tree = proto_item_add_subtree(h248_item, ett_h248);
1388     }
1389
1390     dissect_h248_MegacoMessage(FALSE, tvb, 0, &asn1_ctx, h248_tree, -1);
1391
1392 }
1393
1394 /*--- proto_register_h248 ----------------------------------------------*/
1395 void proto_reg_handoff_h248(void);
1396
1397 void proto_register_h248(void) {
1398
1399     /* List of fields */
1400     static hf_register_info hf[] = {
1401         { &hf_h248_mtpaddress_ni, {
1402                 "NI", "h248.mtpaddress.ni", FT_UINT32, BASE_DEC,
1403                 NULL, 0, NULL, HFILL }},
1404         { &hf_h248_mtpaddress_pc, {
1405                 "PC", "h248.mtpaddress.pc", FT_UINT32, BASE_DEC,
1406                 NULL, 0, NULL, HFILL }},
1407         { &hf_h248_pkg_name, {
1408                 "Package", "h248.package_name", FT_UINT16, BASE_HEX|BASE_EXT_STRING,
1409                 &package_name_vals_ext, 0, NULL, HFILL }},
1410         { &hf_248_pkg_param, {
1411                 "Parameter ID", "h248.package_paramid", FT_UINT16, BASE_HEX,
1412                 NULL, 0, NULL, HFILL }},
1413         { &hf_h248_signal_code, {
1414                 "Signal ID", "h248.package_signalid", FT_UINT16, BASE_HEX,
1415                 NULL, 0, "Parameter ID", HFILL }},
1416         { &hf_h248_event_code, {
1417                 "Event ID", "h248.package_eventid", FT_UINT16, BASE_HEX,
1418                 NULL, 0, "Parameter ID", HFILL }},
1419         { &hf_h248_event_name, {
1420                 "Package and Event name", "h248.event_name", FT_UINT32, BASE_HEX|BASE_EXT_STRING,
1421                 &event_name_vals_ext, 0, "Package", HFILL }},
1422         { &hf_h248_signal_name, {
1423                 "Package and Signal name", "h248.signal_name", FT_UINT32, BASE_HEX|BASE_EXT_STRING,
1424                 &signal_name_vals_ext, 0, "Package", HFILL }},
1425         { &hf_h248_pkg_bcp_BNCChar_PDU,
1426           { "BNCChar", "h248.package_bcp.BNCChar",
1427             FT_UINT32, BASE_DEC, VALS(gcp_term_types), 0,
1428             NULL, HFILL }},
1429
1430         { &hf_h248_error_code,
1431           { "errorCode", "h248.errorCode",
1432             FT_UINT32, BASE_DEC|BASE_EXT_STRING, &h248_reasons_ext, 0,
1433             "ErrorDescriptor/errorCode", HFILL }},
1434         { &hf_h248_context_id,
1435           { "contextId", "h248.contextId",
1436             FT_UINT32, BASE_HEX, NULL, 0,
1437             "Context ID", HFILL }},
1438         { &hf_h248_term_wild_type,
1439           { "Wildcard Mode", "h248.term.wildcard.mode",
1440             FT_UINT8, BASE_DEC, VALS(wildcard_modes), 0x80,
1441             NULL, HFILL }},
1442         { &hf_h248_term_wild_level,
1443           { "Wildcarding Level", "h248.term.wildcard.level",
1444             FT_UINT8, BASE_DEC, VALS(wildcard_levels), 0x40,
1445             NULL, HFILL }},
1446         { &hf_h248_term_wild_position,
1447           { "Wildcarding Position", "h248.term.wildcard.pos",
1448             FT_UINT8, BASE_DEC, NULL, 0x3F,
1449             NULL, HFILL }},
1450
1451         { &hf_h248_no_pkg,
1452           { "Unknown Package", "h248.pkg.unknown",
1453             FT_BYTES, BASE_NONE, NULL, 0,
1454             NULL, HFILL }},
1455         { &hf_h248_no_sig,
1456           { "Unknown Signal", "h248.pkg.unknown.sig",
1457             FT_BYTES, BASE_NONE, NULL, 0,
1458             NULL, HFILL }},
1459         { &hf_h248_no_evt,
1460           { "Unknown Event", "h248.pkg.unknown.evt",
1461             FT_BYTES, BASE_NONE, NULL, 0,
1462             NULL, HFILL }},
1463         { &hf_h248_param,
1464           { "Parameter", "h248.pkg.unknown.param",
1465             FT_BYTES, BASE_NONE, NULL, 0,
1466             NULL, HFILL }},
1467         { &hf_h248_serviceChangeReasonStr,
1468           { "ServiceChangeReasonStr", "h248.serviceChangeReasonstr",
1469             FT_STRING, BASE_NONE, NULL, 0,
1470             "h248.IA5String", HFILL }},
1471
1472 /* h248v1 support */
1473         { &hf_h248_auditValueReplyV1,
1474           { "auditValueReplyV1", "h248.auditValueReplyV1",
1475             FT_NONE, BASE_NONE, NULL, 0,
1476             NULL, HFILL }},
1477
1478 #include "packet-h248-hfarr.c"
1479
1480         GCP_HF_ARR_ELEMS("h248",h248_arrel)
1481
1482     };
1483
1484     /* List of subtrees */
1485     static gint *ett[] = {
1486         &ett_h248,
1487         &ett_mtpaddress,
1488         &ett_packagename,
1489         &ett_codec,
1490         &ett_wildcard,
1491         &ett_h248_no_pkg,
1492         &ett_h248_no_sig,
1493         &ett_h248_no_evt,
1494         GCP_ETT_ARR_ELEMS(h248_arrel),
1495
1496 #include "packet-h248-ettarr.c"
1497     };
1498
1499     module_t *h248_module;
1500
1501
1502     /* Register protocol */
1503     proto_h248 = proto_register_protocol(PNAME, PSNAME, PFNAME);
1504     register_dissector("h248", dissect_h248, proto_h248);
1505     register_dissector("h248.tpkt", dissect_h248_tpkt, proto_h248);
1506
1507     /* Register fields and subtrees */
1508     proto_register_field_array(proto_h248, hf, array_length(hf));
1509     proto_register_subtree_array(ett, array_length(ett));
1510
1511     h248_module = prefs_register_protocol(proto_h248, proto_reg_handoff_h248);
1512     prefs_register_bool_preference(h248_module, "ctx_info",
1513                                    "Track Context",
1514                                    "Mantain relationships between transactions and contexts and display an extra tree showing context data",
1515                                    &keep_persistent_data);
1516     prefs_register_uint_preference(h248_module, "udp_port",
1517                                    "UDP port",
1518                                    "Port to be decoded as h248",
1519                                    10,
1520                                    &global_udp_port);
1521     prefs_register_uint_preference(h248_module, "tcp_port",
1522                                    "TCP port",
1523                                    "Port to be decoded as h248",
1524                                    10,
1525                                    &global_tcp_port);
1526     prefs_register_bool_preference(h248_module, "desegment",
1527                                    "Desegment H.248 over TCP",
1528                                    "Desegment H.248 messages that span more TCP segments",
1529                                    &h248_desegment);
1530
1531     msgs = se_tree_create(EMEM_TREE_TYPE_RED_BLACK, "h248_msgs");
1532     trxs = se_tree_create(EMEM_TREE_TYPE_RED_BLACK, "h248_trxs");
1533     ctxs_by_trx = se_tree_create(EMEM_TREE_TYPE_RED_BLACK, "h248_ctxs_by_trx");
1534     ctxs = se_tree_create(EMEM_TREE_TYPE_RED_BLACK, "h248_ctxs");
1535
1536     h248_tap = register_tap("h248");
1537
1538     gcp_init();
1539 }
1540
1541 /*--- proto_reg_handoff_h248 -------------------------------------------*/
1542 void proto_reg_handoff_h248(void) {
1543
1544     static gboolean initialized = FALSE;
1545     static guint32 udp_port;
1546     static guint32 tcp_port;
1547
1548     if (!initialized) {
1549         h248_handle = find_dissector("h248");
1550         h248_tpkt_handle = find_dissector("h248.tpkt");
1551         dissector_add("mtp3.service_indicator", GATEWAY_CONTROL_PROTOCOL_USER_ID, h248_handle);
1552         h248_term_handle = find_dissector("h248term");
1553         initialized = TRUE;
1554     } else {
1555         if (udp_port != 0)
1556             dissector_delete("udp.port", udp_port, h248_handle);
1557
1558         if (tcp_port != 0)
1559             dissector_delete("tcp.port", tcp_port, h248_tpkt_handle);
1560     }
1561
1562     udp_port = global_udp_port;
1563     tcp_port = global_tcp_port;
1564
1565     if (udp_port != 0) {
1566         dissector_add("udp.port", udp_port, h248_handle);
1567     }
1568
1569     if (tcp_port != 0) {
1570         dissector_add("tcp.port", tcp_port, h248_tpkt_handle);
1571     }
1572 }
1573