Register the MMSE dissector with the "http.content_type" dissector
[obnox/wireshark/wip.git] / tap-h225counter.c
1 /* tap_h225counter.c
2  * h225 message counter for ethereal
3  * Copyright 2003 Lars Roland
4  *
5  * $Id: tap-h225counter.c,v 1.1 2003/10/28 00:31:16 guy Exp $
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 <stdio.h>
31
32 #ifdef HAVE_SYS_TYPES_H
33 # include <sys/types.h>
34 #endif
35
36 #include <string.h>
37 #include "epan/packet_info.h"
38 #include "tap.h"
39 #include "epan/value_string.h"
40 #include "register.h"
41 #include "packet-h225.h"
42
43 /* following values represent the size of their valuestring arrays */
44
45 #define RAS_MSG_TYPES 33
46 #define CS_MSG_TYPES 13
47
48 #define GRJ_REASONS 8
49 #define RRJ_REASONS 18
50 #define URQ_REASONS 6
51 #define URJ_REASONS 6
52 #define ARJ_REASONS 22
53 #define BRJ_REASONS 8
54 #define DRQ_REASONS 3
55 #define DRJ_REASONS 4
56 #define LRJ_REASONS 16
57 #define IRQNAK_REASONS 4
58 #define REL_CMP_REASONS 26
59 #define FACILITY_REASONS 11
60
61
62
63 static const value_string RasMessage_vals[] = {
64         { 0, "gatekeeperRequest" },
65         { 1, "gatekeeperConfirm" },
66         { 2, "gatekeeperReject" },
67         { 3, "registrationRequest" },
68         { 4, "registrationConfirm" },
69         { 5, "registrationReject" },
70         { 6, "unregistrationRequest" },
71         { 7, "unregistrationConfirm" },
72         { 8, "unregistrationReject" },
73         { 9, "admissionRequest" },
74         {10, "admissionConfirm" },
75         {11, "admissionReject" },
76         {12, "bandwidthRequest" },
77         {13, "bandwidthConfirm" },
78         {14, "bandwidthReject" },
79         {15, "disengageRequest" },
80         {16, "disengageConfirm" },
81         {17, "disengageReject" },
82         {18, "locationRequest" },
83         {19, "locationConfirm" },
84         {20, "locationReject" },
85         {21, "infoRequest" },
86         {22, "infoRequestResponse" },
87         {23, "nonStandardMessage" },
88         {24, "unknownMessageResponse" },
89         {25, "requestInProgress" },
90         {26, "resourcesAvailableIndicate" },
91         {27, "resourcesAvailableConfirm" },
92         {28, "infoRequestAck" },
93         {29, "infoRequestNak" },
94         {30, "serviceControlIndication" },
95         {31, "serviceControlResponse" },
96         {32, "admissionConfirmSequence" },
97         { 0, NULL}
98 };
99
100 static const value_string h323_message_body_vals[] = {
101         { 0, "setup" },
102         { 1, "callProceeding" },
103         { 2, "connect" },
104         { 3, "alerting" },
105         { 4, "information" },
106         { 5, "releaseComplete" },
107         { 6, "facility" },
108         { 7, "progress" },
109         { 8, "empty" },
110         { 9, "status" },
111         { 10, "statusInquiry" },
112         { 11, "setupAcknowledge" },
113         { 12, "notify" },
114         { 0, NULL}
115 };
116
117 static const value_string FacilityReason_vals[] = {
118         { 0, "routeCallToGatekeeper" },
119         { 1, "callForwarded" },
120         { 2, "routeCallToMC" },
121         { 3, "undefinedReason" },
122         { 4, "conferenceListChoice" },
123         { 5, "startH245" },
124         { 6, "noH245" },
125         { 7, "newTokens" },
126         { 8, "featureSetUpdate" },
127         { 9, "forwardedElements" },
128         { 10, "transportedInformation" },
129         { 0, NULL}
130 };
131
132 static const value_string GatekeeperRejectReason_vals[] = {
133         { 0, "resourceUnavailable" },
134         { 1, "terminalExcluded" },
135         { 2, "invalidRevision" },
136         { 3, "undefinedReason" },
137         { 4, "securityDenial" },
138         { 5, "genericDataReason" },
139         { 6, "neededFeatureNotSupported" },
140         { 7, "securityError" },
141         { 0, NULL}
142 };
143
144 static const value_string UnregRequestReason_vals[] = {
145         { 0, "reregistrationRequired" },
146         { 1, "ttlExpired" },
147         { 2, "securityDenial" },
148         { 3, "undefinedReason" },
149         { 4, "maintenance" },
150         { 5, "securityError" },
151         { 0, NULL}
152 };
153
154 static const value_string UnregRejectReason_vals[] = {
155         { 0, "notCurrentlyRegistered" },
156         { 1, "callInProgress" },
157         { 2, "undefinedReason" },
158         { 3, "permissionDenied" },
159         { 4, "securityDenial" },
160         { 5, "securityError" },
161         { 0, NULL}
162 };
163
164 static const value_string BandRejectReason_vals[] = {
165         { 0, "notBound" },
166         { 1, "invalidConferenceID" },
167         { 2, "invalidPermission" },
168         { 3, "insufficientResources" },
169         { 4, "invalidRevision" },
170         { 5, "undefinedReason" },
171         { 6, "securityDenial" },
172         { 7, "securityError" },
173         { 0, NULL}
174 };
175
176 static const value_string DisengageReason_vals[] = {
177         { 0, "forcedDrop" },
178         { 1, "normalDrop" },
179         { 2, "undefinedReason" },
180         { 0, NULL}
181 };
182
183 static const value_string DisengageRejectReason_vals[] = {
184         { 0, "notRegistered" },
185         { 1, "requestToDropOther" },
186         { 2, "securityDenial" },
187         { 3, "securityError" },
188         { 0, NULL}
189 };
190
191 static const value_string InfoRequestNakReason_vals[] = {
192         { 0, "notRegistered" },
193         { 1, "securityDenial" },
194         { 2, "undefinedReason" },
195         { 3, "securityError" },
196         { 0, NULL}
197 };
198
199 static const value_string ReleaseCompleteReason_vals[] = {
200         { 0, "noBandwidth" },
201         { 1, "gatekeeperResources" },
202         { 2, "unreachableDestination" },
203         { 3, "destinationRejection" },
204         { 4, "invalidRevision" },
205         { 5, "noPermission" },
206         { 6, "unreachableGatekeeper" },
207         { 7, "gatewayResources" },
208         { 8, "badFormatAddress" },
209         { 9, "adaptiveBusy" },
210         { 10, "inConf" },
211         { 11, "undefinedReason" },
212         { 12, "facilityCallDeflection" },
213         { 13, "securityDenied" },
214         { 14, "calledPartyNotRegistered" },
215         { 15, "callerNotRegistered" },
216         { 16, "newConnectionNeeded" },
217         { 17, "nonStandardReason" },
218         { 18, "replaceWithConferenceInvite" },
219         { 19, "genericDataReason" },
220         { 20, "neededFeatureNotSupported" },
221         { 21, "tunnelledSignallingRejected" },
222         { 22, "invalidCID" },
223         { 23, "invalidCID" },
224         { 24, "securityError" },
225         { 25, "hopCountExceeded" },
226         { 0, NULL}
227 };
228
229 static const value_string AdmissionRejectReason_vals[] = {
230         { 0, "calledPartyNotRegistered" },
231         { 1, "invalidPermission" },
232         { 2, "requestDenied" },
233         { 3, "undefinedReason" },
234         { 4, "callerNotRegistered" },
235         { 5, "routeCallToGatekeeper" },
236         { 6, "invalidEndpointIdentifier" },
237         { 7, "resourceUnavailable" },
238         { 8, "securityDenial" },
239         { 9, "qosControlNotSupported" },
240         { 10, "incompleteAddress" },
241         { 11, "aliasesInconsistent" },
242         { 12, "routeCallToSCN" },
243         { 13, "exceedsCallCapacity" },
244         { 14, "collectDestination" },
245         { 15, "collectPIN" },
246         { 16, "genericDataReason" },
247         { 17, "neededFeatureNotSupported" },
248         { 18, "securityErrors" },
249         { 19, "securityDHmismatch" },
250         { 20, "noRouteToDestination" },
251         { 21, "unallocatedNumber" },
252         { 0, NULL}
253 };
254
255 static const value_string LocationRejectReason_vals[] = {
256         { 0, "notRegistered" },
257         { 1, "invalidPermission" },
258         { 2, "requestDenied" },
259         { 3, "undefinedReason" },
260         { 4, "securityDenial" },
261         { 5, "aliasesInconsistent" },
262         { 6, "routeCalltoSCN" },
263         { 7, "resourceUnavailable" },
264         { 8, "genericDataReason" },
265         { 9, "neededFeatureNotSupported" },
266         {10, "hopCountExceeded" },
267         {11, "incompleteAddress" },
268         {12, "securityError" },
269         {13, "securityDHmismatch" },
270         {14, "noRouteToDestination" },
271         {15, "unallocatedNumber" },
272         { 0, NULL}
273 };
274
275 static const value_string RegistrationRejectReason_vals[] = {
276         { 0, "discoveryRequired" },
277         { 1, "invalidRevision" },
278         { 2, "invalidCallSignalAddress" },
279         { 3, "invalidRASAddress" },
280         { 4, "duplicateAlias" },
281         { 5, "invalidTerminalType" },
282         { 6, "undefinedReason" },
283         { 7, "transportNotSupported" },
284         { 8, "transportQOSNotSupported" },
285         { 9, "resourceUnavailable" },
286         { 10, "invalidAlias" },
287         { 11, "securityDenial" },
288         { 12, "fullRegistrationRequired" },
289         { 13, "additiveRegistrationNotSupported" },
290         { 14, "invalidTerminalAliases" },
291         { 15, "genericDataReason" },
292         { 16, "neededFeatureNotSupported" },
293         { 17, "securityError" },
294         { 0, NULL}
295 };
296
297 /* used to keep track of the statistics for an entire program interface */
298 typedef struct _h225counter_t {
299         char *filter;
300         guint32 ras_msg[RAS_MSG_TYPES + 1];
301         guint32 cs_msg[CS_MSG_TYPES + 1];
302         guint32 grj_reason[GRJ_REASONS + 1];
303         guint32 rrj_reason[RRJ_REASONS + 1];
304         guint32 urq_reason[URQ_REASONS + 1];
305         guint32 urj_reason[URJ_REASONS + 1];
306         guint32 arj_reason[ARJ_REASONS + 1];
307         guint32 brj_reason[BRJ_REASONS + 1];
308         guint32 drq_reason[DRQ_REASONS + 1];
309         guint32 drj_reason[DRJ_REASONS + 1];
310         guint32 lrj_reason[LRJ_REASONS + 1];
311         guint32 irqnak_reason[IRQNAK_REASONS + 1];
312         guint32 rel_cmp_reason[REL_CMP_REASONS + 1];
313         guint32 facility_reason[FACILITY_REASONS + 1];
314 } h225counter_t;
315
316
317 static void
318 h225counter_reset(void *phs)
319 {
320         h225counter_t *hs=(h225counter_t *)phs;
321         int i;
322
323         for(i=0;i<=RAS_MSG_TYPES;i++) {
324                 hs->ras_msg[i] = 0;
325         }
326         for(i=0;i<=CS_MSG_TYPES;i++) {
327                 hs->cs_msg[i] = 0;
328         }
329         for(i=0;i<=GRJ_REASONS;i++) {
330                 hs->grj_reason[i] = 0;
331         }
332         for(i=0;i<=RRJ_REASONS;i++) {
333                 hs->rrj_reason[i] = 0;
334         }
335         for(i=0;i<=URQ_REASONS;i++) {
336                 hs->urq_reason[i] = 0;
337         }
338         for(i=0;i<=URJ_REASONS;i++) {
339                 hs->urj_reason[i] = 0;
340         }
341         for(i=0;i<=ARJ_REASONS;i++) {
342                 hs->arj_reason[i] = 0;
343         }
344         for(i=0;i<=BRJ_REASONS;i++) {
345                 hs->brj_reason[i] = 0;
346         }
347         for(i=0;i<=DRQ_REASONS;i++) {
348                 hs->drq_reason[i] = 0;
349         }
350         for(i=0;i<=DRJ_REASONS;i++) {
351                 hs->drj_reason[i] = 0;
352         }
353         for(i=0;i<=LRJ_REASONS;i++) {
354                 hs->lrj_reason[i] = 0;
355         }
356         for(i=0;i<=IRQNAK_REASONS;i++) {
357                 hs->irqnak_reason[i] = 0;
358         }
359         for(i=0;i<=REL_CMP_REASONS;i++) {
360                 hs->rel_cmp_reason[i] = 0;
361         }
362         for(i=0;i<=FACILITY_REASONS;i++) {
363                 hs->facility_reason[i] = 0;
364         }
365 }
366
367 static int
368 h225counter_packet(void *phs, packet_info *pinfo _U_, epan_dissect_t *edt _U_, void *phi)
369 {
370         h225counter_t *hs=(h225counter_t *)phs;
371         h225_packet_info *pi=phi;
372
373         switch (pi->msg_type) {
374
375         case H225_RAS:
376                 if(pi->msg_tag==-1) { /* uninitialized */
377                         return 0;
378                 }
379                 else if (pi->msg_tag >= RAS_MSG_TYPES) { /* unknown */
380                         hs->ras_msg[RAS_MSG_TYPES]++;
381                 }
382                 else {
383                         hs->ras_msg[pi->msg_tag]++;
384                 }
385
386                 /* Look for reason tag */
387                 if(pi->reason==-1) { /* uninitialized */
388                         break;
389                 }
390
391                 switch(pi->msg_tag) {
392
393                 case 2: /* GRJ */
394                         if(pi->reason < GRJ_REASONS)
395                                 hs->grj_reason[pi->reason]++;
396                         else
397                                 hs->grj_reason[GRJ_REASONS]++;
398                         break;
399                 case 5: /* RRJ */
400                         if(pi->reason < RRJ_REASONS)
401                                 hs->rrj_reason[pi->reason]++;
402                         else
403                                 hs->rrj_reason[RRJ_REASONS]++;
404                         break;
405                 case 6: /* URQ */
406                         if(pi->reason < URQ_REASONS)
407                                 hs->urq_reason[pi->reason]++;
408                         else
409                                 hs->urq_reason[URQ_REASONS]++;
410                         break;
411                 case 8: /* URJ */
412                         if(pi->reason < URJ_REASONS)
413                                 hs->urj_reason[pi->reason]++;
414                         else
415                                 hs->urj_reason[URJ_REASONS]++;
416                         break;
417                 case 11: /* ARJ */
418                         if(pi->reason < ARJ_REASONS)
419                                 hs->arj_reason[pi->reason]++;
420                         else
421                                 hs->arj_reason[ARJ_REASONS]++;
422                         break;
423                 case 14: /* BRJ */
424                         if(pi->reason < BRJ_REASONS)
425                                 hs->brj_reason[pi->reason]++;
426                         else
427                                 hs->brj_reason[BRJ_REASONS]++;
428                         break;
429                 case 15: /* DRQ */
430                         if(pi->reason < DRQ_REASONS)
431                                 hs->drq_reason[pi->reason]++;
432                         else
433                                 hs->drq_reason[DRQ_REASONS]++;
434                         break;
435                 case 17: /* DRJ */
436                         if(pi->reason < DRJ_REASONS)
437                                 hs->drj_reason[pi->reason]++;
438                         else
439                                 hs->drj_reason[DRJ_REASONS]++;
440                         break;
441                 case 20: /* LRJ */
442                         if(pi->reason < LRJ_REASONS)
443                                 hs->lrj_reason[pi->reason]++;
444                         else
445                                 hs->lrj_reason[LRJ_REASONS]++;
446                         break;
447                 case 29: /* IRQ Nak */
448                         if(pi->reason < IRQNAK_REASONS)
449                                 hs->irqnak_reason[pi->reason]++;
450                         else
451                                 hs->irqnak_reason[IRQNAK_REASONS]++;
452                         break;
453
454                 default:
455                         /* do nothing */
456                         break;
457                 }
458
459                 break;
460
461         case H225_CS:
462                 if(pi->msg_tag==-1) { /* uninitialized */
463                         return 0;
464                 }
465                 else if (pi->msg_tag >= CS_MSG_TYPES) { /* unknown */
466                         hs->cs_msg[CS_MSG_TYPES]++;
467                 }
468                 else {
469                         hs->cs_msg[pi->msg_tag]++;
470                 }
471
472                 /* Look for reason tag */
473                 if(pi->reason==-1) { /* uninitialized */
474                         break;
475                 }
476
477                 switch(pi->msg_tag) {
478
479                 case 5: /* ReleaseComplete */
480                         if(pi->reason < REL_CMP_REASONS)
481                                 hs->rel_cmp_reason[pi->reason]++;
482                         else
483                                 hs->rel_cmp_reason[REL_CMP_REASONS]++;
484                         break;
485                 case 6: /* Facility */
486                         if(pi->reason < FACILITY_REASONS)
487                                 hs->facility_reason[pi->reason]++;
488                         else
489                                 hs->facility_reason[FACILITY_REASONS]++;
490                         break;
491                 default:
492                         /* do nothing */
493                         break;
494                 }
495
496                 break;
497
498         default:
499                 return 0;
500                 break;
501         }
502
503         return 1;
504 }
505
506
507 static void
508 h225counter_draw(void *phs)
509 {
510         h225counter_t *hs=(h225counter_t *)phs;
511         int i,j;
512
513         printf("================== H225 Message and Reason Counter ==================\n");
514         printf("RAS-Messages:\n");
515         for(i=0;i<=RAS_MSG_TYPES;i++) {
516                 if(hs->ras_msg[i]!=0) {
517                         printf("  %s : %u\n", val_to_str(i,RasMessage_vals,"unknown ras-messages  "), hs->ras_msg[i]);
518                         /* reason counter */
519                         switch(i) {
520                         case 2: /* GRJ */
521                                 for(j=0;j<=GRJ_REASONS;j++) {
522                                         if(hs->grj_reason[j]!=0) {
523                                                 printf("    %s : %u\n", val_to_str(j,GatekeeperRejectReason_vals,"unknown reason   "), hs->grj_reason[j]);
524                                         }
525                                 }
526                                 break;
527                         case 5: /* RRJ */
528                                 for(j=0;j<=RRJ_REASONS;j++) {
529                                         if(hs->rrj_reason[j]!=0) {
530                                                 printf("    %s : %u\n", val_to_str(j,RegistrationRejectReason_vals,"unknown reason   "), hs->rrj_reason[j]);
531                                         }
532                                 }
533                                 break;
534                         case 6: /* URQ */
535                                 for(j=0;j<=URQ_REASONS;j++) {
536                                         if(hs->urq_reason[j]!=0) {
537                                                 printf("    %s : %u\n", val_to_str(j,UnregRequestReason_vals,"unknown reason   "), hs->urq_reason[j]);
538                                         }
539                                 }
540                                 break;
541                         case 8: /* URJ */
542                                 for(j=0;j<=URJ_REASONS;j++) {
543                                         if(hs->urj_reason[j]!=0) {
544                                                 printf("    %s : %u\n", val_to_str(j,UnregRejectReason_vals,"unknown reason   "), hs->urj_reason[j]);
545                                         }
546                                 }
547                                 break;
548                         case 11: /* ARJ */
549                                 for(j=0;j<=ARJ_REASONS;j++) {
550                                         if(hs->arj_reason[j]!=0) {
551                                                 printf("    %s : %u\n", val_to_str(j,AdmissionRejectReason_vals,"unknown reason   "), hs->arj_reason[j]);
552                                         }
553                                 }
554                                 break;
555                         case 14: /* BRJ */
556                                 for(j=0;j<=BRJ_REASONS;j++) {
557                                         if(hs->brj_reason[j]!=0) {
558                                                 printf("    %s : %u\n", val_to_str(j,BandRejectReason_vals,"unknown reason   "), hs->brj_reason[j]);
559                                         }
560                                 }
561                                 break;
562                         case 15: /* DRQ */
563                                 for(j=0;j<=DRQ_REASONS;j++) {
564                                         if(hs->drq_reason[j]!=0) {
565                                                 printf("    %s : %u\n", val_to_str(j,DisengageReason_vals,"unknown reason   "), hs->drq_reason[j]);
566                                         }
567                                 }
568                                 break;
569                         case 17: /* DRJ */
570                                 for(j=0;j<=DRJ_REASONS;j++) {
571                                         if(hs->drj_reason[j]!=0) {
572                                                 printf("    %s : %u\n", val_to_str(j,DisengageRejectReason_vals,"unknown reason   "), hs->drj_reason[j]);
573                                         }
574                                 }
575                                 break;
576                         case 20: /* LRJ */
577                                 for(j=0;j<=LRJ_REASONS;j++) {
578                                         if(hs->lrj_reason[j]!=0) {
579                                                 printf("    %s : %u\n", val_to_str(j,LocationRejectReason_vals,"unknown reason   "), hs->lrj_reason[j]);
580                                         }
581                                 }
582                         case 29: /* IRQNak */
583                                 for(j=0;j<=IRQNAK_REASONS;j++) {
584                                         if(hs->irqnak_reason[j]!=0) {
585                                                 printf("    %s : %u\n", val_to_str(j,InfoRequestNakReason_vals,"unknown reason   "), hs->irqnak_reason[j]);
586                                         }
587                                 }
588                                 break;
589                         default:
590                                 break;
591                         }
592                         /* end of reason counter*/
593                 }
594         }
595         printf("Call Signalling:\n");
596         for(i=0;i<=CS_MSG_TYPES;i++) {
597                 if(hs->cs_msg[i]!=0) {
598                         printf("  %s : %u\n", val_to_str(i,h323_message_body_vals,"unknown cs-messages   "), hs->cs_msg[i]);
599                         /* reason counter */
600                         switch(i) {
601                         case 5: /* ReleaseComplete */
602                                 for(j=0;j<=REL_CMP_REASONS;j++) {
603                                         if(hs->rel_cmp_reason[j]!=0) {
604                                                 printf("    %s : %u\n", val_to_str(j,ReleaseCompleteReason_vals,"unknown reason   "), hs->rel_cmp_reason[j]);
605                                         }
606                                 }
607                                 break;
608                         case 6: /* Facility */
609                                 for(j=0;j<=FACILITY_REASONS;j++) {
610                                         if(hs->facility_reason[j]!=0) {
611                                                 printf("    %s : %u\n", val_to_str(j,FacilityReason_vals,"unknown reason   "), hs->facility_reason[j]);
612                                         }
613                                 }
614                                 break;
615                         default:
616                                 break;
617                         }
618                 }
619         }
620         printf("=====================================================================\n");
621 }
622
623
624 static void
625 h225counter_init(char *optarg)
626 {
627         h225counter_t *hs;
628         char *filter=NULL;
629         GString *error_string;
630
631         if(!strncmp(optarg,"h225,counter,",13)){
632                 filter=optarg+13;
633         } else {
634                 filter=g_malloc(1);
635                 *filter='\0';
636         }
637
638         hs = g_malloc(sizeof(h225counter_t));
639         hs->filter=g_malloc(strlen(filter)+1);
640         strcpy(hs->filter, filter);
641
642         h225counter_reset(hs);
643
644         error_string=register_tap_listener("h225", hs, filter, NULL, h225counter_packet, h225counter_draw);
645         if(error_string){
646                 /* error, we failed to attach to the tap. clean up */
647                 g_free(hs->filter);
648                 g_free(hs);
649
650                 fprintf(stderr, "tethereal: Couldn't register h225,counter tap: %s\n",
651                     error_string->str);
652                 g_string_free(error_string, TRUE);
653                 exit(1);
654         }
655 }
656
657
658 void
659 register_tap_listener_h225counter(void)
660 {
661         register_ethereal_tap("h225,counter", h225counter_init);
662 }