48ed47271b8f4fbf349f5c6c090b1f2ad62aef6e
[obnox/wireshark/wip.git] / asn1 / h460 / packet-h460-template.c
1 /* packet-h460.c
2  * Routines for H.460.x packet dissection
3  * 2007  Tomas Kukosa
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
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 #include <epan/oids.h>
34 #include <epan/asn1.h>
35
36 #include <stdio.h>
37 #include <string.h>
38
39 #include "packet-per.h"
40 #include "packet-h225.h"
41 #include "packet-h235.h"
42 #include "packet-h245.h"
43
44 #define PNAME  "H.460 Supplementary Services"
45 #define PSNAME "H.460"
46 #define PFNAME "h460"
47
48 /* Initialize the protocol and registered fields */
49 int proto_h460 = -1;
50 #include "packet-h460-hf.c"
51
52 /* Initialize the subtree pointers */
53 #include "packet-h460-ett.c"
54
55 /* Subdissectors */
56 static dissector_handle_t q931_ie_handle = NULL; 
57 static dissector_handle_t h225_ras_handle = NULL; 
58
59 #include "packet-h460-fn.c"
60
61 static int 
62 dissect_ies(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
63   int offset = 0;
64
65   if (q931_ie_handle) {
66     call_dissector(q931_ie_handle, tvb, pinfo, tree);
67     offset += tvb_length_remaining(tvb, offset);
68   }
69   return offset;
70 }
71
72 static int 
73 dissect_ras(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
74   int offset = 0;
75
76   if (h225_ras_handle) {
77     call_dissector(h225_ras_handle, tvb, pinfo, tree);
78     offset += tvb_length_remaining(tvb, offset);
79   }
80   return offset;
81 }
82
83 typedef struct _h460_feature_t {
84   guint32 opt;
85   const gchar *id;
86   const gchar *name;
87   new_dissector_t content_pdu;
88   /*---*/
89   const gchar *key_gd;
90   const gchar *key_fd;
91   const gchar *key_gm;
92   const gchar *key_gi;
93   dissector_handle_t content_hnd;
94 } h460_feature_t;
95
96 /* Fill in the items after content_pdu */
97 #define FFILL   NULL, NULL, NULL, NULL, NULL
98
99 /* options */
100 #define GD 0x01  /* present in H.225 GenericData */
101 #define FD 0x02  /* present in H.225 FeatureDescriptor */
102 #define GM 0x04  /* present in H.245 GenericMessage */
103 #define GI 0x08  /* present in H.245 GenericInformation */
104
105 static h460_feature_t h460_feature_tab[] = {
106   /* H.460.3 */
107   { GD|FD,  "2",   "Number Portability", NULL, FFILL },
108   { GD|FD,  "2/1", "NumberPortabilityData", dissect_h460_2_NumberPortabilityInfo_PDU, FFILL },
109   /* H.460.3 */
110   { GD|FD,  "3",   "Circuit Status", NULL, FFILL },
111   { GD|FD,  "3/1", "Circuit Status Map", dissect_h460_3_CircuitStatus_PDU, FFILL },
112   /* H.460.4 */
113   { GD|FD,  "4",   "CallPriorityDesignation", NULL, FFILL },
114   { GD|FD,  "4/1", "CallPriorityRequest", dissect_h460_4_CallPriorityInfo_PDU, FFILL },
115   { GD|FD,  "4/2", "CallPriorityConfirm", dissect_h460_4_CallPriorityInfo_PDU, FFILL },
116   { GD|FD,  "4/3", "Country/InternationalNetworkCallOriginationRequest", dissect_h460_4_CountryInternationalNetworkCallOriginationIdentification_PDU, FFILL },
117   { GD|FD,  "4/4", "Country/InternationalNetworkCallOriginationConfirm", dissect_h460_4_CountryInternationalNetworkCallOriginationIdentification_PDU, FFILL },
118   /* H.460.5 */
119   { GD|FD,  "5",   "DuplicateIEs", NULL, FFILL },
120   { GD|FD,  "5/1", "IEsString", dissect_ies, FFILL },
121   /* H.460.6 */
122   { GD|FD,  "6",   "Extended Fast Connect", NULL, FFILL },
123   { GD|FD,  "6/1", "EFC Proposal", NULL, FFILL },
124   { GD|FD,  "6/2", "EFC Close All Media Channels", NULL, FFILL },
125   { GD|FD,  "6/3", "EFC Request New Proposals", NULL, FFILL },
126   { GD|FD,  "6/4", "EFC Require Symmetric Operation", NULL, FFILL },
127   /* H.460.7 */
128   { GD|FD,  "7",   "Digit Maps", NULL, FFILL },
129   {    FD,  "7/1", "Digit Maps Length", NULL, FFILL },
130   {    FD,  "7/2", "Digit Map Length for Overlapped Sending", NULL, FFILL },
131   {    FD,  "7/3", "HTTP Digit Maps Download Capability", NULL, FFILL },
132   { GD   ,  "7/1", "Start Timer", NULL, FFILL },
133   { GD   ,  "7/2", "Short Timer", NULL, FFILL },
134   { GD   ,  "7/3", "Long Timer", NULL, FFILL },
135   { GD   ,  "7/4", "Digit Map String", NULL, FFILL },
136   { GD   ,  "7/5",   "ToN Associated Digit Map", NULL, FFILL },
137   { GD   ,  "7/5/1", "Type of Number", NULL, FFILL },
138   { GD   ,  "7/5/2", "Digit Map Strings for ToN", NULL, FFILL },
139   { GD   ,  "7/6", "Digit Map URL", NULL, FFILL },
140   /* H.460.8 */
141   { GD|FD,  "8",   "Querying for Alternate Routes", NULL, FFILL },
142   { GD|FD,  "8/1", "Query Count", NULL, FFILL },
143   { GD|FD,  "8/2", "Call Termination Cause", NULL, FFILL },
144   /* H.460.9 */
145   { GD|FD,  "9",   "QoS-monitoring Reporting", NULL, FFILL },
146   { GD|FD,  "9/1", "qosMonitoringFinalOnly", NULL, FFILL },
147   { GD|FD,  "9/2", "qosMonitoringReportData", dissect_h460_9_QosMonitoringReportData_PDU, FFILL },
148   { GD|FD,  "9/3", "qosMonitoringExtendedRTPMetrics", dissect_h460_9_ExtendedRTPMetrics_PDU, FFILL },
149   /* H.460.10 */
150   { GD|FD, "10",   "Call Party Category", NULL, FFILL },
151   { GD|FD, "10/1", "Call party category info", dissect_h460_10_CallPartyCategoryInfo_PDU, FFILL },
152   /* H.460.11 */
153   { GD|FD, "11",   "Delayed Call Establishment", NULL, FFILL },
154   { GD|FD, "11/1", "Delay Point Indicator", NULL, FFILL },
155   { GD|FD, "11/2", "Implicit DCE Release", NULL, FFILL },
156   { GD|FD, "11/3", "Delay Point Reached", NULL, FFILL },
157   { GD|FD, "11/4", "DCE Release", NULL, FFILL },
158   /* H.460.12 */
159   { GD|FD, "12",   "Glare Control Indicator", NULL, FFILL },
160   { GD|FD, "12/1", "Glare Control Indicator Parameter", NULL, FFILL },
161   /* H.460.13 */
162   { GD|FD, "13",   "Called User Release Control", NULL, FFILL },
163   { GD|FD, "13/1", "Called User Release Control", NULL, FFILL },
164   /* H.460.14 */
165   { GD|FD, "14",   "Multi-Level Precedence and Preemption", NULL, FFILL },
166   { GD|FD, "14/1", "MLPP Information", dissect_h460_14_MLPPInfo_PDU, FFILL },
167   /* H.460.15 */
168   { GD|FD, "15",   "Call signalling transport channel suspension and redirection", NULL, FFILL },
169   { GD|FD, "15/1", "Signalling channel suspend and redirect", dissect_h460_15_SignallingChannelData_PDU, FFILL },
170   /* H.460.16 */
171   { GD|FD, "16",   "Multiple-message Release Sequence", NULL, FFILL },
172   { GD|FD, "16/1", "MMRS use required", NULL, FFILL },
173   { GD|FD, "16/2", "MMRS procedure", NULL, FFILL },
174   { GD|FD, "16/3", "MMRS additional IEs", dissect_ies, FFILL },
175   /* H.460.17 */
176   { GD|FD, "17",   "RAS over H.225.0", NULL, FFILL },
177   { GD|FD, "17/1", "RAS message", dissect_ras, FFILL },
178   /* H.460.18 */
179   { GD|FD|GM, "18",   "Signalling Traversal", NULL, FFILL },
180   { GD|FD   , "18/1", "IncomingCallIndication", dissect_h460_18_IncomingCallIndication_PDU, FFILL },
181   { GD|FD   , "18/2", "LRQKeepAliveData", dissect_h460_18_LRQKeepAliveData_PDU, FFILL },
182   {       GM, "18-1",   "connectionCorrelation", NULL, FFILL },
183   {       GM, "18-1/1", "callIdentifier", NULL, FFILL },
184   {       GM, "18-1/2", "answerCall", NULL, FFILL },
185   /* H.460.19 */
186   { GD|FD|GI, "19", "mediaNATFWTraversal", NULL, FFILL },
187   { GD|FD   , "19/1", "supportTransmitMultiplexedMedia", NULL, FFILL },
188   { GD|FD   , "19/2", "mediaTraversalServer", NULL, FFILL },
189   {       GI, "19/1", "Traversal Parameters", dissect_h460_19_TraversalParameters_PDU, FFILL },
190   /* H.460.20 */
191   { GD|FD, "20",   "LocationSourceAddress", NULL, FFILL },
192   { GD|FD, "20/1", "LocationSourceAddress", dissect_h225_ExtendedAliasAddress_PDU, FFILL },
193   /* H.460.21 */
194   { GD|FD, "21",   "Message Broadcast", NULL, FFILL },
195   { GD|FD, "21/1", "MessageBroadcastParameter", dissect_h460_21_CapabilityAdvertisement_PDU, FFILL },
196   /* H.460.22 */
197   { GD|FD, "22",     "securityProtocolNegotiation", NULL, FFILL },
198   { GD|FD, "22/1",   "tlsSecurityProtocol", NULL, FFILL },
199   { GD|FD, "22/1/1", "priority", NULL, FFILL },
200   { GD|FD, "22/1/2", "connectionAddress", NULL, FFILL },
201   { GD|FD, "22/2",   "ipsecSecurityProtocol", NULL, FFILL },
202   { GD|FD, "22/2/1", "priority", NULL, FFILL },
203   { 0, NULL, NULL, NULL, FFILL },
204 };                                 
205
206 static h460_feature_t *find_ftr(const gchar *key) {
207   h460_feature_t *ftr = NULL;
208   h460_feature_t *f;
209
210   for (f=h460_feature_tab; f->id; f++) {
211     if (f->key_gd && !strcmp(key, f->key_gd)) { ftr = f; break; }
212     if (f->key_fd && !strcmp(key, f->key_fd)) { ftr = f; break; }
213     if (f->key_gm && !strcmp(key, f->key_gm)) { ftr = f; break; }
214     if (f->key_gi && !strcmp(key, f->key_gi)) { ftr = f; break; }
215   }
216   return ftr;
217 }
218
219 /*--- dissect_h460_name -------------------------------------------*/
220 static int
221 dissect_h460_name(tvbuff_t *tvb _U_, packet_info *pinfo, proto_tree *tree) {
222   int offset = 0;
223   asn1_ctx_t *actx;
224   h460_feature_t *ftr;
225
226   actx = get_asn1_ctx(pinfo->private_data);
227   DISSECTOR_ASSERT(actx);
228   if (tree) {
229     /* DEBUG */ /*proto_tree_add_text(tree, tvb, 0, 0, "*** DEBUG dissect_h460_name: %s", pinfo->match_string);*/
230     ftr = find_ftr(pinfo->match_string);
231     /* DEBUG */ /*proto_tree_add_text(tree, tvb, 0, 0, "*** DEBUG dissect_h460_name: ftr %s", (ftr)?ftr->name:"-none-");*/
232     if (ftr) {
233       proto_item_append_text(actx->created_item, " - %s", ftr->name);
234       proto_item_append_text(proto_item_get_parent(proto_tree_get_parent(tree)), ": %s", ftr->name);
235     } else {
236       proto_item_append_text(actx->created_item, " - unknown(%s)", pinfo->match_string);
237     }
238   }
239
240   return offset;
241 }
242
243 /*--- proto_register_h460 ----------------------------------------------*/
244 void proto_register_h460(void) {
245   h460_feature_t *ftr;
246
247   /* List of fields */
248   static hf_register_info hf[] = {
249 #include "packet-h460-hfarr.c"
250   };
251
252   /* List of subtrees */
253   static gint *ett[] = {
254 #include "packet-h460-ettarr.c"
255   };
256
257   /* Register protocol */
258   proto_h460 = proto_register_protocol(PNAME, PSNAME, PFNAME);
259
260   /* Register fields and subtrees */
261   proto_register_field_array(proto_h460, hf, array_length(hf));
262   proto_register_subtree_array(ett, array_length(ett));
263
264   for (ftr=h460_feature_tab; ftr->id; ftr++) {
265     if (ftr->opt & GD) ftr->key_gd = g_strdup_printf("GenericData/%s", ftr->id);
266     if (ftr->opt & FD) ftr->key_fd = g_strdup_printf("FeatureDescriptor/%s", ftr->id);
267     if (ftr->opt & GM) ftr->key_gm = g_strdup_printf("GenericMessage/%s", ftr->id);
268     if (ftr->opt & GI) ftr->key_gi = g_strdup_printf("GenericInformation/%s", ftr->id);
269     if (ftr->content_pdu) ftr->content_hnd = new_create_dissector_handle(ftr->content_pdu, proto_h460);
270   }
271 }
272
273 /*--- proto_reg_handoff_h460 -------------------------------------------*/
274 void proto_reg_handoff_h460(void) 
275 {
276   h460_feature_t *ftr;
277   dissector_handle_t h460_name_handle;
278
279   q931_ie_handle = find_dissector("q931.ie");
280   h225_ras_handle = find_dissector("h225.ras");
281
282   h460_name_handle = new_create_dissector_handle(dissect_h460_name, proto_h460);
283   for (ftr=h460_feature_tab; ftr->id; ftr++) {
284     if (ftr->key_gd) dissector_add_string("h225.gef.name", ftr->key_gd, h460_name_handle);
285     if (ftr->key_fd) dissector_add_string("h225.gef.name", ftr->key_fd, h460_name_handle);
286     if (ftr->key_gm) dissector_add_string("h245.gef.name", ftr->key_gm, h460_name_handle);
287     if (ftr->key_gi) dissector_add_string("h245.gef.name", ftr->key_gi, h460_name_handle);
288     if (ftr->content_hnd) {
289       if (ftr->key_gd) dissector_add_string("h225.gef.content", ftr->key_gd, ftr->content_hnd);
290       if (ftr->key_fd) dissector_add_string("h225.gef.content", ftr->key_fd, ftr->content_hnd);
291       if (ftr->key_gm) dissector_add_string("h245.gef.content", ftr->key_gm, ftr->content_hnd);
292       if (ftr->key_gi) dissector_add_string("h245.gef.content", ftr->key_gi, ftr->content_hnd);
293     }
294   }
295
296 }