Fix [-Wmissing-prototypes]
[metze/wireshark/wip.git] / epan / dissectors / packet-h221_nonstd.c
1 /* packet-h221_nonstd.c
2  * Routines for H.221 nonstandard parameters disassembly
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24
25 #include "config.h"
26
27 #include <glib.h>
28 #include <epan/packet.h>
29
30 void proto_register_nonstd(void);
31 void proto_reg_handoff_nonstd(void);
32
33 /* Define the nonstd proto */
34 static int proto_nonstd = -1;
35
36 /*
37  * Define the trees for nonstd
38  * We need one for nonstd itself and one for the nonstd paramters
39  */
40 static int ett_nonstd = -1;
41
42 const value_string ms_codec_vals[] = {
43     {  0x0111, "L&H CELP 4.8k" },
44     {  0x0200, "MS-ADPCM" },
45     {  0x0211, "L&H CELP 8k" },
46     {  0x0311, "L&H CELP 12k" },
47     {  0x0411, "L&H CELP 16k" },
48     {  0x1100, "IMA-ADPCM" },
49     {  0x3100, "MS-GSM" },
50     {  0xfeff, "E-AMR" },
51     {  0, NULL }
52 };
53
54 static void
55 dissect_ms_nonstd(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
56 {
57     proto_item *it;
58     proto_tree *tr;
59     guint32 offset=0;
60     gint tvb_len;
61     guint16 codec_value, codec_extra;
62
63     it=proto_tree_add_protocol_format(tree, proto_nonstd, tvb, 0, tvb_length(tvb), "Microsoft NonStd");
64     tr=proto_item_add_subtree(it, ett_nonstd);
65
66
67     tvb_len = tvb_length(tvb);
68
69     /*
70      * XXX - why do this test?  Are there any cases where throwing
71      * an exception if the tvbuff is too short causes subsequent stuff
72      * in the packet not to be dissected (e.g., if the octet string
73      * containing the non-standard data is too short for the data
74      * supposedly contained in it, and is followed by more items)?
75      *
76      * If so, the right fix might be to catch ReportedBoundsError in
77      * the dissector calling this dissector, and report a malformed
78      * nonStandardData item, and rethrow other exceptions (as a
79      * BoundsError means you really *have* run out of packet data).
80      */
81     if(tvb_len >= 23)
82     {
83
84         codec_value = tvb_get_ntohs(tvb,offset+20);
85         codec_extra = tvb_get_ntohs(tvb,offset+22);
86
87         if(codec_extra == 0x0100)
88         {
89
90             proto_tree_add_text(tr, tvb, offset+20, 2, "Microsoft NetMeeting Codec=0x%04X %s",
91                                 codec_value,val_to_str(codec_value, ms_codec_vals,"Unknown (%u)"));
92
93         }
94         else
95         {
96
97             proto_tree_add_text(tr, tvb, offset, -1, "Microsoft NetMeeting Non Standard");
98
99         }
100     }
101 }
102
103 /* Register all the bits needed with the filtering engine */
104
105 void
106 proto_register_nonstd(void)
107 {
108     static gint *ett[] = {
109         &ett_nonstd,
110     };
111
112     proto_nonstd = proto_register_protocol("H221NonStandard","h221nonstd", "h221nonstd");
113
114     proto_register_subtree_array(ett, array_length(ett));
115 }
116
117 /* The registration hand-off routine */
118 void
119 proto_reg_handoff_nonstd(void)
120 {
121     static dissector_handle_t ms_nonstd_handle;
122
123
124     ms_nonstd_handle = create_dissector_handle(dissect_ms_nonstd, proto_nonstd);
125
126     dissector_add_uint("h245.nsp.h221",0xb500534c, ms_nonstd_handle);
127     dissector_add_uint("h225.nsp.h221",0xb500534c, ms_nonstd_handle);
128
129 }