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