minor update preparations to have a dissector table for property identifiers
[obnox/wireshark/wip.git] / asn1 / h248 / packet-h248-template.c
1 /* packet-h248.c
2  * Routines for H.248/MEGACO packet dissection
3  * Ronnie Sahlberg 2004
4  *
5  * $Id$
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <glib.h>
31 #include <epan/packet.h>
32 #include <epan/conversation.h>
33
34 #include <stdio.h>
35 #include <string.h>
36
37 #include "packet-ber.h"
38 #include "packet-h248.h"
39
40 #define PNAME  "H.248 MEGACO"
41 #define PSNAME "H248"
42 #define PFNAME "h248"
43
44 /*XXX this define should be moved to packet-m3ua.h ? */
45 #define GATEWAY_CONTROL_PROTOCOL_USER_ID 14
46
47 /* Initialize the protocol and registered fields */
48 static int proto_h248 = -1;
49 static int hf_h248_mtpaddress_ni = -1;
50 static int hf_h248_mtpaddress_pc = -1;
51 static int hf_h248_package_name = -1;
52 #include "packet-h248-hf.c"
53
54 /* Initialize the subtree pointers */
55 static gint ett_h248 = -1;
56 static gint ett_mtpaddress = -1;
57 static gint ett_packagename = -1;
58 #include "packet-h248-ett.c"
59
60
61 static const value_string package_name_vals[] = {
62   {   0x0000, "Media stream properties H.248.1 Annex C" },
63   {   0x0001, "g H.248.1 Annex E" },
64   {   0x0002, "root H.248.1 Annex E" },
65   {   0x0003, "tonegen H.248.1 Annex E" },
66   {   0x0004, "tonedet H.248.1 Annex E" },
67   {   0x0005, "dg H.248.1 Annex E" },
68   {   0x0006, "dd H.248.1 Annex E" },
69   {   0x0007, "cg H.248.1 Annex E" }, 
70   {   0x0008, "cd H.248.1 Annex E" },
71   {   0x0009, "al H.248.1 Annex E" },
72   {   0x000a, "ct H.248.1 Annex E" }, 
73   {   0x000b, "nt H.248.1 Annex E" },
74   {   0x000c, "rtp H.248.1 Annex E" },
75   {   0x000d, "tdmc H.248.1 Annex E" },
76   {   0x000e, "ftmd H.248.1 Annex E" },
77   {   0x000f, "txc H.248.2" },                                                                                  /* H.248.2 */
78   {   0x0010, "txp H.248.2" },
79   {   0x0011, "ctyp H.248.2" },
80   {   0x0012, "fax H.248.2" },
81   {   0x0013, "ipfax H.248.2" },
82   {   0x0014, "dis H.248.3" },                                                                                  /* H.248.3 */
83   {   0x0015, "key H.248.3" },
84   {   0x0016, "kp H.248.3" },
85   {   0x0017, "labelkey H.248.3" },   
86   {   0x0018, "kf H.248.3" },
87   {   0x0019, "ind H.248.3" },
88   {   0x001a, "ks H.248.3" },
89   {   0x001b, "anci H.248.3" },
90   {   0x001c, "dtd H.248.6" },                                                                                  /* H.248.6 */
91   {   0x001d, "an H.248.7" },                                                                                   /* H.248.7 */
92   {   0x001e, "Bearer Characteristics Q.1950 Annex A" },                                /* Q.1950 Annex A */ 
93   {   0x001f, "Bearer Network Connection Cut Q.1950 Annex A" },
94   {   0x0020, "Reuse Idle Q.1950 Annex A" },
95   {   0x0021, "Generic Bearer Connection Q.1950 Annex A" }, 
96   {   0x0022, "Bearer Control Tunnelling Q.1950 Annex A" },
97   {   0x0023, "Basic Call Progress Tones Q.1950 Annex A" },
98   {   0x0024, "Expanded Call Progress Tones Q.1950 Annex A" },
99   {   0x0025, "Basic Services Tones Q.1950 Annex A" },
100   {   0x0026, "Expanded Services Tones Q.1950 Annex A" },
101   {   0x0027, "Intrusion Tones Q.1950 Annex A" },
102   {   0x0028, "Business Tones Q.1950 Annex A" },
103   {   0x0029, "Media Gateway Resource Congestion Handling H.248.10" },  /* H.248.10 */
104   {   0x002a, "H245 package H248.12" },                                                                 /* H.248.12 */
105   {   0x002b, "H323 bearer control package H.248.12" },                                 /* H.248.12 */
106   {   0x002c, "H324 package H.248.12" },                                                                /* H.248.12 */
107   {   0x002d, "H245 command package H.248.12" },                                                /* H.248.12 */
108   {   0x002e, "H245 indication package H.248.12" },                                             /* H.248.12 */
109   {   0x002f, "3G User Plane" },                                                                                /* 3GPP TS 29.232 v4.1.0 */
110   {   0x0030, "3G Circuit Switched Data" },
111   {   0x0031, "3G TFO Control" },
112   {   0x0032, "3G Expanded Call Progress Tones" },
113   {   0x0033, "Advanced Audio Server (AAS) Base)" },                                    /* H.248.9 */
114   {   0x0034, "AAS Digit Collection" },                                                                 /* H.248.9 */
115   {   0x0035, "AAS Recording" },                                                                                /* H.248.9 */
116   {   0x0036, "AAS Segment Management" },                                                               /* H.248.9 */ 
117   {   0x0037, "Quality Alert Ceasing" },                                                                /* H.248.13 */
118   {   0x0038, "Conferencing Tones Generation" },                                                /* H.248.27 */
119   {   0x0039, "Diagnostic Tones Generation" },                                                  /* H.248.27 */
120   {   0x003a, "Carrier Tones Generation Package H.248.23" },                    /* H.248.27 */
121   {   0x003b, "Enhanced Alerting Package H.248.23" },                                   /* H.248.23 */
122   {   0x003c, "Analog Display Signalling Package H.248.23" },                   /* H.248.23 */
123   {   0x003d, "Multi-Frequency Tone Generation Package H.248.24" },             /* H.248.24 */                                                                                             
124   {   0x003e, "H.248.23Multi-Frequency Tone Detection Package H.248.24" }, /* H.248.24 */
125   {   0x003f, "Basic CAS Package H.248.25" },                                                   /* H.248.25 */                                                                                             
126   {   0x0040, "Robbed Bit Signalling Package H.248.25" },                       /* H.248.25 */
127   {   0x0041, "Operator Services and Emgergency Services Package H.248.25" },                                                                                              
128   {   0x0042, "Operator Services Extension Package H.248.25" },
129   {   0x0043, "Extended Analog Line Supervision Package H.248.26" },
130   {   0x0044, "Automatic Metering Package H.248.26" },  
131   {   0x0045, "Inactivity Timer Package H.248.14" },      
132   {   0x0046, "3G Modification of Link Characteristics Bearer Capability" }, /* 3GPP TS 29.232 v4.4.0 */ 
133   {   0x0047, "Base Announcement Syntax H.248.9" },
134   {   0x0048, "Voice Variable Syntax H.248.9" },
135   {   0x0049, "Announcement Set Syntax H.248.9" },
136   {   0x004a, "Phrase Variable Syntax H.248.9" },
137   {   0x004b, "Basic NAS package" },
138   {   0x004c, "NAS incoming package" },
139   {   0x004d, "NAS outgoing package" },
140   {   0x004e, "NAS control package" },
141   {   0x004f, "NAS root package" },
142   {   0x0050, "Profile Handling Package H.248.18" }, 
143   {   0x0051, "Media Gateway Overload Control Package H.248.11" }, 
144   {   0x0052, "Extended DTMF Detection Package H.248.16" },
145   {   0x0053, "Quiet Termination Line Test" },
146   {   0x0054, "Loopback Line Test Response" },                                                  /* H.248.17 */
147   {   0x0055, "ITU 404Hz Line Test" },                                                                  /* H.248.17 */
148   {   0x0056, "ITU 816Hz Line Test" },                                                                  /* H.248.17 */
149   {   0x0057, "ITU 1020Hz Line Test" },                                                                 /* H.248.17 */
150   {   0x0058, "ITU 2100Hz Disable Tone Line Test" },                                    /* H.248.17 */
151   {   0x0059, "ITU 2100Hz Disable Echo Canceller Tone Line Test" },             /* H.248.17 */
152   {   0x005a, "ITU 2804Hz Tone Line Test" },                                                    /* H.248.17 */
153   {   0x005b, "ITU Noise Test Tone Line Test" },                                                /* H.248.17 */
154   {   0x005c, "ITU Digital Pseudo Random Test Line Test" },                             /* H.248.17 */
155   {   0x005d, "ITU ATME No.2 Test Line Response" },                                             /* H.248.17 */
156   {   0x005e, "ANSI 1004Hz Test Tone Line Test" },                                              /* H.248.17 */
157   {   0x005f, "ANSI Test Responder Line Test" },                                                /* H.248.17 */
158   {   0x0060, "ANSI 2225Hz Test Progress Tone Line Test" },                             /* H.248.17 */
159   {   0x0061, "ANSI Digital Test Signal Line Test" },                                   /* H.248.17 */
160   {   0x0062, "ANSI Inverting Loopback Line Test Repsonse" },                   /* H.248.17 */
161   {   0x0063, "Extended H.324 Packages H.248.12 Annex A" },
162   {   0x0064, "Extended H.245 Command Package H.248.12 Annex A" },
163   {   0x0065, "Extended H.245 Indication Package H.248.12 Annex A" },
164   {   0x0066, "Enhanced DTMF Detection Package H.248.16" }, 
165   {   0x0067, "Connection Group Identity Package Q.1950 Annex E" }, 
166   {   0x0068, "CTM Text Transport 3GPP TS 29.232 v5.2.0" }, 
167   {   0x0069, "SPNE Control Package Q.115.0" },
168   {   0x006a, "Semi-permanent Connection Package H.248.21" },
169   {   0x006b, "Shared Risk Group Package H.248.22" },
170   {   0x006c, "isuptn Annex B of ITU-T Rec. J.171" },
171   {   0x006d, "Basic CAS Addressing Package H.248.25" },
172   {   0x006e, "Floor Control Package H.248.19" },
173   {   0x006f, "Indication of Being Viewed Package H.248.19" },
174   {   0x0070, "Volume Control Package H.248.19" },
175   {   0x0071, "UNASSIGNED" },
176   {   0x0072, "Volume Detection Package H.248.19" },
177   {   0x0073, "Volume Level Mixing Package H.248.19" },
178   {   0x0074, "Mixing Volume Level Control Package H.248.19" },
179   {   0x0075, "Voice Activated Video Switch Package H.248.19" },
180   {   0x0076, "Lecture Video Mode Package H.248.19" },
181   {   0x0077, "Contributing Video Source Package H.248.19" },
182   {   0x0078, "Video Window Package H.248.19" },
183   {   0x0079, "Tiled Window Package H.248.19" },
184   {   0x007a, "Adaptive Jitter Buffer Package H.248.31" },
185   {   0x007b, "International CAS Package H.248.28" },
186   {   0x007c, "CAS Blocking Package H.248.28" },
187   {   0x007d, "International CAS Compelled Package H.248.29" },
188   {   0x007e, "International CAS Compelled with Overlap Package H.248.29" },
189   {   0x007f, "International CAS Compelled with End-to-end Package H.248.29" },
190   {   0x0080, "RTCP XR Package H.248.30" },
191   {   0x0081, "RTCP XR Burst Metrics Package H.248.30" },
192   {   0x0082, "threegcsden 3G Circuit Switched Data" },                         /* 3GPP TS 29.232 v5.6.0 */
193   {   0x0083, "threegiptra 3G Circuit Switched Data" },                         /* 3GPP TS 29.232 v5.6.0 */
194   {   0x0084, "threegflex 3G Circuit Switched Data" },                          /* 3GPP TS 29.232 v5.6.0 */                                                                                                
195   {   0x0085, "H.248 PCMSB" },
196   {   0x008a, "TIPHON Extended H.248/MEGACO Package" },                         /* ETSI specification TS 101 3 */
197   {   0x008b, "Differentiated Services Package" },                                      /* Annex A of ETSI TS 102 333 */
198   {   0x008c, "Gate Management Package" },                                                      /* Annex B of ETSI TS 102 333 */
199   {   0x008d, "Traffic Management Package" },                                           /* Annex C of ETSI TS 102 333 */
200   {   0x008e, "Gate Recovery Information Package" },                            /* Annex D of ETSI TS 102 333 */
201   {   0x008f, "NAT Traversal Package" },                                                        /* Annex E of ETSI TS 102 333 */
202   {   0x0090, "MPLS Package" },                                                                         /* Annex F of ETSI TS 102 333 */
203   {   0x0091, "VLAN Package" },                                                                         /* Annex G of ETSI TS 102 333 */
204   {   0x8000, "Ericsson IU" }, 
205   {   0x8001, "Ericsson UMTS and GSM Circuit" },
206   {   0x8002, "Ericsson Tone Generator Package" },
207   {   0x8003, "Ericsson Line Test Package" },
208   {   0x8004, "Nokia Advanced TFO Package" },
209   {   0x8005, "Nokia IWF Package" },
210   {   0x8006, "Nokia Root Package" },
211   {   0x8007, "Nokia Trace Package" },
212   {   0x8008, "Ericsson  V5.2 Layer" },
213   {   0x8009, "Ericsson Detailed Termination Information Package" },
214   {   0x800a, "Nokia Bearer Characteristics Package" },
215         {0,     NULL}
216 };
217
218 static int 
219 dissect_h248_PkgdName(gboolean implicit_tag, tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, int hf_index) {
220   tvbuff_t *new_tvb;
221   proto_tree *package_tree=NULL;
222   guint32 name_major, name_minor;
223   int old_offset;
224
225   old_offset=offset;
226   offset = dissect_ber_octet_string(implicit_tag, pinfo, tree, tvb, offset, hf_index, &new_tvb);
227
228
229   /* this field is always 4 bytes  so just read it into two integers */
230   name_major=tvb_get_ntohs(new_tvb, 0);
231   name_minor=tvb_get_ntohs(new_tvb, 2);
232
233   /* do the prettification */
234   proto_item_append_text(ber_last_created_item, "  %s (%04x)", val_to_str(name_major, package_name_vals, "Unknown Package"), name_major);
235   if(tree){
236     package_tree = proto_item_add_subtree(ber_last_created_item, ett_packagename);
237   }
238   proto_tree_add_uint(package_tree, hf_h248_package_name, tvb, offset-4, 2, name_major);
239
240
241   return offset;
242 }
243
244 static int
245 dissect_h248_PropertyID(gboolean implicit_tag, tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, int hf_index) {
246   offset = dissect_ber_octet_string(implicit_tag, pinfo, tree, tvb, offset, hf_index, NULL);
247
248   return offset;
249 }
250
251
252
253 static int 
254 dissect_h248_MtpAddress(gboolean implicit_tag, tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, int hf_index) {
255   tvbuff_t *new_tvb;
256   proto_tree *mtp_tree=NULL;
257   guint32 val;
258   int i, len, old_offset;
259
260   old_offset=offset;
261   offset = dissect_ber_octet_string(implicit_tag, pinfo, tree, tvb, offset, hf_index, &new_tvb);
262
263
264   /* this field is either 2 or 4 bytes  so just read it into an integer */
265   val=0;
266   len=tvb_length(new_tvb);
267   for(i=0;i<len;i++){
268     val= (val<<8)|tvb_get_guint8(new_tvb, i);
269   }
270
271   /* do the prettification */
272   proto_item_append_text(ber_last_created_item, "  NI = %d, PC = %d ( %d-%d )", val&0x03,val>>2,val&0x03,val>>2);
273   if(tree){
274     mtp_tree = proto_item_add_subtree(ber_last_created_item, ett_mtpaddress);
275   }
276   proto_tree_add_uint(mtp_tree, hf_h248_mtpaddress_ni, tvb, old_offset, offset-old_offset, val&0x03);
277   proto_tree_add_uint(mtp_tree, hf_h248_mtpaddress_pc, tvb, old_offset, offset-old_offset, val>>2);
278
279
280   return offset;
281 }
282
283
284 #include "packet-h248-fn.c"
285
286
287 static void
288 dissect_h248(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
289 {
290   proto_item *h248_item;
291   proto_tree *h248_tree = NULL;
292
293   /* Make entry in the Protocol column on summary display */
294   if (check_col(pinfo->cinfo, COL_PROTOCOL))
295     col_set_str(pinfo->cinfo, COL_PROTOCOL, "H.248");
296
297   if (tree) {
298     h248_item = proto_tree_add_item(tree, proto_h248, tvb, 0, -1, FALSE);
299     h248_tree = proto_item_add_subtree(h248_item, ett_h248);
300   }
301
302   dissect_h248_MegacoMessage(FALSE, tvb, 0, pinfo, h248_tree, -1);
303   
304 }
305
306 /*--- proto_register_h248 ----------------------------------------------*/
307 void proto_register_h248(void) {
308
309   /* List of fields */
310   static hf_register_info hf[] = {
311     { &hf_h248_mtpaddress_ni, {
312       "NI", "h248.mtpaddress.ni", FT_UINT32, BASE_DEC,
313       NULL, 0, "NI", HFILL }},
314     { &hf_h248_mtpaddress_pc, {
315       "PC", "h248.mtpaddress.pc", FT_UINT32, BASE_DEC,
316       NULL, 0, "PC", HFILL }},
317     { &hf_h248_package_name, {
318       "Package", "h248.package_name", FT_UINT32, BASE_HEX,
319       VALS(package_name_vals), 0, "Package", HFILL }},
320 #include "packet-h248-hfarr.c"
321   };
322
323   /* List of subtrees */
324   static gint *ett[] = {
325     &ett_h248,
326     &ett_mtpaddress,
327     &ett_packagename,
328 #include "packet-h248-ettarr.c"
329   };
330
331   /* Register protocol */
332   proto_h248 = proto_register_protocol(PNAME, PSNAME, PFNAME);
333
334   register_dissector("h248", dissect_h248, proto_h248);
335
336   /* Register fields and subtrees */
337   proto_register_field_array(proto_h248, hf, array_length(hf));
338   proto_register_subtree_array(ett, array_length(ett));
339
340 }
341
342
343 /*--- proto_reg_handoff_h248 -------------------------------------------*/
344 void proto_reg_handoff_h248(void) {
345   dissector_handle_t h248_handle;
346
347   h248_handle = find_dissector("h248");
348
349   dissector_add("m3ua.protocol_data_si", GATEWAY_CONTROL_PROTOCOL_USER_ID, h248_handle);
350 }
351