There's no need to keep a "FILE *" for the file being printed to in a
[obnox/wireshark/wip.git] / packet-wap.c
1 /* packet-wap.c
2  *
3  * Utility routines for WAP dissectors
4  *
5  * $Id: packet-wap.c,v 1.9 2004/01/13 20:59:37 obiot Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
9  * Copyright 1998 Gerald Combs
10  *
11  * WAP dissector based on original work by Ben Fowler
12  * Updated by Neil Hunter <neil.hunter@energis-squared.com>
13  * WTLS support by Alexandre P. Ferreira (Splice IP)
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
28  */
29
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #include <glib.h>
35 #include <epan/packet.h>
36 #include "packet-wap.h"
37
38 /*
39  * Accessor to retrieve variable length int as used in WAP protocol.
40  * The value is encoded in the lower 7 bits. If the top bit is set, then the
41  * value continues into the next byte.
42  * The octetCount parameter holds the number of bytes read in order to return
43  * the final value. Can be pre-initialised to start at offset+count.
44 */
45 guint
46 tvb_get_guintvar (tvbuff_t *tvb, guint offset, guint *octetCount)
47 {
48         guint value = 0;
49         guint octet;
50         guint counter = 0;
51         char cont = 1;
52
53 #ifdef DEBUG
54         if (octetCount != NULL)
55         {
56                 fprintf (stderr, "dissect_wap: Starting tvb_get_guintvar at offset %d, count=%d\n", offset, *octetCount);
57                 /* counter = *octetCount; */
58         }
59         else
60         {
61                 fprintf (stderr, "dissect_wap: Starting tvb_get_guintvar at offset %d, count=NULL\n", offset);
62         }
63 #endif
64
65         while (cont != 0)
66         {
67                 value<<=7;      /* Value only exists in 7 of the 8 bits */
68                 octet = tvb_get_guint8 (tvb, offset+counter);
69                 counter++;
70                 value += (octet & 0x7F);
71                 cont = (octet & 0x80);
72 #ifdef DEBUG
73                 fprintf (stderr, "dissect_wap: computing: octet is %d (0x%02x), count=%d, value=%d, cont=%d\n", octet, octet, counter, value, cont);
74 #endif
75         }
76
77         if (octetCount != NULL)
78         {
79                 *octetCount = counter;
80 #ifdef DEBUG
81                 fprintf (stderr, "dissect_wap: Leaving tvb_get_guintvar count=%d, value=%u\n", *octetCount, value);
82 #endif
83         }
84
85         return (value);
86 }
87
88 /* See http://www.iana.org/assignments/character-sets for the MIBenum mapping */
89 const value_string vals_character_sets[] = {
90         { 0x0000, "*" },
91         { 0x0003, "us-ascii" },
92         { 0x0004, "iso-8859-1" },
93         { 0x0005, "iso-8859-2" },
94         { 0x0006, "iso-8859-3" },
95         { 0x0007, "iso-8859-4" },
96         { 0x0008, "iso-8859-5" },
97         { 0x0009, "iso-8859-6" },
98         { 0x000A, "iso-8859-7" },
99         { 0x000B, "iso-8859-8" },
100         { 0x000C, "iso-8859-9" },
101         { 0x000D, "iso-8859-10" },
102         { 0x000E, "iso_6937-2-add" },
103         { 0x000F, "jis_x0201" },
104         { 0x0010, "jis_encoding" },
105         { 0x0011, "shift_jis" },
106         { 0x0012, "euc-jp" },
107         { 0x0013, "extended_unix_code_fixed_width_for_japanese" },
108         { 0x0014, "bs_4730" },
109         { 0x0015, "sen_850200_c" },
110         { 0x0016, "it" },
111         { 0x0017, "es" },
112         { 0x0018, "din_66003" },
113         { 0x0019, "ns_4551-1" },
114         { 0x001A, "nf_z_62-010" },
115         { 0x001B, "iso-10646-utf-1" },
116         { 0x001C, "iso_646.basic:1983" },
117         { 0x001D, "invariant" },
118         { 0x001E, "iso_646.irv:1983" },
119         { 0x001F, "nats-sefi" },
120         { 0x0020, "nats-sefi-add" },
121         { 0x0021, "nats-dano" },
122         { 0x0022, "nats-dano-add" },
123         { 0x0023, "sen_850200_b" },
124         { 0x0024, "ks_c_5601-1987" },
125         { 0x0025, "iso-2022-kr" },
126         { 0x0026, "euc-kr" },
127         { 0x0027, "iso-2022-jp" },
128         { 0x0028, "iso-2022-jp-2" },
129         { 0x0029, "jis_c6220-1969-jp" },
130         { 0x002A, "jis_c6220-1969-ro" },
131         { 0x002B, "pt" },
132         { 0x002C, "greek7-old" },
133         { 0x002D, "latin-greek" },
134         { 0x002E, "nf_z_62-010_(1973)" },
135         { 0x002F, "latin-greek-1" },
136         { 0x0030, "iso_5427" },
137         { 0x0031, "jis_c6226-1978" },
138         { 0x0032, "bs_viewdata" },
139         { 0x0033, "inis" },
140         { 0x0034, "inis-8" },
141         { 0x0035, "inis-cyrillic" },
142         { 0x0036, "iso_5427:1981" },
143         { 0x0037, "iso_5428:1980" },
144         { 0x0038, "gb_1988-80" },
145         { 0x0039, "gb_2312-80" },
146         { 0x003A, "ns_4551-2" },
147         { 0x003B, "videotex-suppl" },
148         { 0x003C, "pt2" },
149         { 0x003D, "es2" },
150         { 0x003E, "msz_7795.3" },
151         { 0x003F, "jis_c6226-1983" },
152         { 0x0040, "greek7" },
153         { 0x0041, "asmo_449" },
154         { 0x0042, "iso-ir-90" },
155         { 0x0043, "jis_c6229-1984-a" },
156         { 0x0044, "jis_c6229-1984-b" },
157         { 0x0045, "jis_c6229-1984-b-add" },
158         { 0x0046, "jis_c6229-1984-hand" },
159         { 0x0047, "jis_c6229-1984-hand-add" },
160         { 0x0048, "jis_c6229-1984-kana" },
161         { 0x0049, "iso_2033-1983" },
162         { 0x004A, "ansi_x3.110-1983" },
163         { 0x004B, "t.61-7bit" },
164         { 0x004C, "t.61-8bit" },
165         { 0x004D, "ecma-cyrillic" },
166         { 0x004E, "csa_z243.4-1985-1" },
167         { 0x004F, "csa_z243.4-1985-2" },
168         { 0x0050, "csa_z243.4-1985-gr" },
169         { 0x0051, "iso_8859-6-e" },
170         { 0x0052, "iso_8859-6-i" },
171         { 0x0053, "t.101-g2" },
172         { 0x0054, "iso_8859-8-e" },
173         { 0x0055, "iso_8859-8-i" },
174         { 0x0056, "csn_369103" },
175         { 0x0057, "jus_i.b1.002" },
176         { 0x0058, "iec_p27-1" },
177         { 0x0059, "jus_i.b1.003-serb" },
178         { 0x005A, "jus_i.b1.003-mac" },
179         { 0x005B, "greek-ccitt" },
180         { 0x005C, "nc_nc00-10:81" },
181         { 0x005D, "iso_6937-2-25" },
182         { 0x005E, "gost_19768-74" },
183         { 0x005F, "iso_8859-supp" },
184         { 0x0060, "iso_10367-box" },
185         { 0x0061, "latin-lap" },
186         { 0x0062, "jis_x0212-1990" },
187         { 0x0063, "ds_2089" },
188         { 0x0064, "us-dk" },
189         { 0x0065, "dk-us" },
190         { 0x0066, "ksc5636" },
191         { 0x0067, "unicode-1-1-utf-7" },
192         { 0x0068, "iso-2022-cn" },
193         { 0x0069, "iso-2022-cn-ext" },
194         { 0x006A, "utf-8" },
195         { 0x006D, "iso-8859-13" },
196         { 0x006E, "iso-8859-14" },
197         { 0x006F, "iso-8859-15" },
198         { 0x03E8, "iso-10646-ucs-2" },
199         { 0x03E9, "iso-10646-ucs-4" },
200         { 0x03EA, "iso-10646-ucs-basic" },
201         { 0x03EB, "iso-10646-j-1" },
202         { 0x03EB, "iso-10646-unicode-latin1" },
203         { 0x03ED, "iso-unicode-ibm-1261" },
204         { 0x03EE, "iso-unicode-ibm-1268" },
205         { 0x03EF, "iso-unicode-ibm-1276" },
206         { 0x03F0, "iso-unicode-ibm-1264" },
207         { 0x03F1, "iso-unicode-ibm-1265" },
208         { 0x03F2, "unicode-1-1" },
209         { 0x03F3, "scsu" },
210         { 0x03F4, "utf-7" },
211         { 0x03F5, "utf-16be" },
212         { 0x03F6, "utf-16le" },
213         { 0x03F7, "utf-16" },
214         { 0x07D0, "iso-8859-1-windows-3.0-latin-1" },
215         { 0x07D1, "iso-8859-1-windows-3.1-latin-1" },
216         { 0x07D2, "iso-8859-2-windows-latin-2" },
217         { 0x07D3, "iso-8859-9-windows-latin-5" },
218         { 0x07D4, "hp-roman8" },
219         { 0x07D5, "adobe-standard-encoding" },
220         { 0x07D6, "ventura-us" },
221         { 0x07D7, "ventura-international" },
222         { 0x07D8, "dec-mcs" },
223         { 0x07D9, "ibm850" },
224         { 0x07DA, "ibm852" },
225         { 0x07DB, "ibm437" },
226         { 0x07DC, "pc8-danish-norwegian" },
227         { 0x07DD, "ibm862" },
228         { 0x07DE, "pc8-turkish" },
229         { 0x07DF, "ibm-symbols" },
230         { 0x07E0, "ibm-thai" },
231         { 0x07E1, "hp-legal" },
232         { 0x07E2, "hp-pi-font" },
233         { 0x07E3, "hp-math8" },
234         { 0x07E4, "adobe-symbol-encoding" },
235         { 0x07E5, "hp-desktop" },
236         { 0x07E6, "ventura-math" },
237         { 0x07E7, "microsoft-publishing" },
238         { 0x07E8, "windows-31j" },
239         { 0x07E9, "gb2312" },
240         { 0x07EA, "big5" },
241         { 0x07EB, "macintosh" },
242         { 0x07EC, "ibm037" },
243         { 0x07ED, "ibm038" },
244         { 0x07EE, "ibm273" },
245         { 0x07EF, "ibm274" },
246         { 0x07F0, "ibm275" },
247         { 0x07F1, "ibm277" },
248         { 0x07F2, "ibm278" },
249         { 0x07F3, "ibm280" },
250         { 0x07F4, "ibm281" },
251         { 0x07F5, "ibm284" },
252         { 0x07F6, "ibm285" },
253         { 0x07F7, "ibm290" },
254         { 0x07F8, "ibm297" },
255         { 0x07F9, "ibm420" },
256         { 0x07FA, "ibm423" },
257         { 0x07FB, "ibm424" },
258         { 0x07FC, "ibm500" },
259         { 0x07FD, "ibm851" },
260         { 0x07FE, "ibm855" },
261         { 0x07FF, "ibm857" },
262         { 0x0800, "ibm860" },
263         { 0x0801, "ibm861" },
264         { 0x0802, "ibm863" },
265         { 0x0803, "ibm864" },
266         { 0x0804, "ibm865" },
267         { 0x0805, "ibm868" },
268         { 0x0806, "ibm869" },
269         { 0x0807, "ibm870" },
270         { 0x0808, "ibm871" },
271         { 0x0809, "ibm880" },
272         { 0x080A, "ibm891" },
273         { 0x080B, "ibm903" },
274         { 0x080C, "ibm904" },
275         { 0x080D, "ibm905" },
276         { 0x080E, "ibm918" },
277         { 0x080F, "ibm1026" },
278         { 0x0810, "ebcdic-at-de" },
279         { 0x0811, "ebcdic-at-de-a" },
280         { 0x0812, "ebcdic-ca-fr" },
281         { 0x0813, "ebcdic-dk-no" },
282         { 0x0814, "ebcdic-dk-no-a" },
283         { 0x0815, "ebcdic-fi-se" },
284         { 0x0816, "ebcdic-fi-se-a" },
285         { 0x0817, "ebcdic-fr" },
286         { 0x0818, "ebcdic-it" },
287         { 0x0819, "ebcdic-pt" },
288         { 0x081A, "ebcdic-es" },
289         { 0x081B, "ebcdic-es-a" },
290         { 0x081C, "ebcdic-es-s" },
291         { 0x081D, "ebcdic-uk" },
292         { 0x081E, "ebcdic-us" },
293         { 0x081F, "unknown-8bit" },
294         { 0x0820, "mnemonic" },
295         { 0x0821, "mnem" },
296         { 0x0822, "viscii" },
297         { 0x0823, "viqr" },
298         { 0x0824, "koi8-r" },
299         { 0x0825, "hz-gb-2312" },
300         { 0x0826, "ibm866" },
301         { 0x0827, "ibm775" },
302         { 0x0828, "koi8-u" },
303         { 0x0829, "ibm00858" },
304         { 0x082A, "ibm00924" },
305         { 0x082B, "ibm01140" },
306         { 0x082C, "ibm01141" },
307         { 0x082D, "ibm01142" },
308         { 0x082E, "ibm01143" },
309         { 0x082F, "ibm01144" },
310         { 0x0830, "ibm01145" },
311         { 0x0831, "ibm01146" },
312         { 0x0832, "ibm01147" },
313         { 0x0833, "ibm01148" },
314         { 0x0834, "ibm01149" },
315         { 0x0835, "big5-hkscs" },
316         { 0x08CA, "windows-1250" },
317         { 0x08CB, "windows-1251" },
318         { 0x08CC, "windows-1252" },
319         { 0x08CD, "windows-1253" },
320         { 0x08CE, "windows-1254" },
321         { 0x08CF, "windows-1255" },
322         { 0x08D0, "windows-1256" },
323         { 0x08D1, "windows-1257" },
324         { 0x08D2, "windows-1258" },
325         { 0x08D3, "tis-620" },
326         { 0x0000, NULL }
327 };