Fixup: tvb_get_string(z) -> tvb_get_string(z)_enc
[metze/wireshark/wip.git] / epan / dissectors / packet-wap.c
1 /* packet-wap.c
2  *
3  * Utility routines for WAP dissectors
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * WAP dissector based on original work by Ben Fowler
10  * Updated by Neil Hunter <neil.hunter@energis-squared.com>
11  * WTLS support by Alexandre P. Ferreira (Splice IP)
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26  */
27
28 #include "config.h"
29
30 #include <glib.h>
31 #include <epan/packet.h>
32 #include "packet-wap.h"
33
34 /*
35  * Accessor to retrieve variable length int as used in WAP protocol.
36  * The value is encoded in the lower 7 bits. If the top bit is set, then the
37  * value continues into the next byte.
38  * The octetCount parameter holds the number of bytes read in order to return
39  * the final value. Can be pre-initialised to start at offset+count.
40 */
41 guint
42 tvb_get_guintvar (tvbuff_t *tvb, guint offset, guint *octetCount)
43 {
44     guint value   = 0;
45     guint octet;
46     guint counter = 0;
47     char  cont    = 1;
48
49 #ifdef DEBUG
50     if (octetCount != NULL)
51     {
52         fprintf (stderr, "dissect_wap: Starting tvb_get_guintvar at offset %d, count=%d\n", offset, *octetCount);
53         /* counter = *octetCount; */
54     }
55     else
56     {
57         fprintf (stderr, "dissect_wap: Starting tvb_get_guintvar at offset %d, count=NULL\n", offset);
58     }
59 #endif
60
61     while (cont != 0)
62     {
63         value <<= 7;  /* Value only exists in 7 of the 8 bits */
64         octet = tvb_get_guint8 (tvb, offset+counter);
65         counter += 1;
66         value   += (octet & 0x7F);
67         cont = (octet & 0x80);
68 #ifdef DEBUG
69         fprintf (stderr, "dissect_wap: computing: octet is %d (0x%02x), count=%d, value=%d, cont=%d\n",
70                  octet, octet, counter, value, cont);
71 #endif
72     }
73
74     if (octetCount != NULL)
75     {
76         *octetCount = counter;
77 #ifdef DEBUG
78         fprintf (stderr, "dissect_wap: Leaving tvb_get_guintvar count=%d, value=%u\n", *octetCount, value);
79 #endif
80     }
81
82     return (value);
83 }
84
85 /* See http://www.iana.org/assignments/character-sets for the MIBenum mapping */
86 /* Updated from 10/04/2012 version */
87 static const value_string wap_mib_enum_vals_character_sets[] = {
88     {    0, "*" },
89     {    3, "US-ASCII" },
90     {    4, "ISO-8859-1" },
91     {    5, "ISO-8859-2" },
92     {    6, "ISO-8859-3" },
93     {    7, "ISO-8859-4" },
94     {    8, "ISO-8859-5" },
95     {    9, "ISO-8859-6" },
96     {   10, "ISO-8859-7" },
97     {   11, "ISO-8859-8" },
98     {   12, "ISO-8859-9" },
99     {   13, "ISO-8859-10" },
100     {   14, "ISO_6937-2-add" },
101     {   15, "JIS_X0201" },
102     {   16, "JIS_Encoding" },
103     {   17, "Shift_JIS" },
104     {   18, "EUC-JP" },
105     {   19, "Extended_UNIX_Code_Fixed_Width_for_Japanese" },
106     {   20, "BS_4730" },
107     {   21, "SEN_850200_C" },
108     {   22, "IT" },
109     {   23, "ES" },
110     {   24, "DIN_66003" },
111     {   25, "NS_4551-1" },
112     {   26, "NF_Z_62-010" },
113     {   27, "ISO-10646-UTF-1" },
114     {   28, "ISO_646.basic:1983" },
115     {   29, "INVARIANT" },
116     {   30, "ISO_646.irv:1983" },
117     {   31, "NATS-SEFI" },
118     {   32, "NATS-SEFI-ADD" },
119     {   33, "NATS-DANO" },
120     {   34, "NATS-DANO-ADD" },
121     {   35, "SEN_850200_B" },
122     {   36, "KS_C_5601-1987" },
123     {   37, "ISO-2022-KR" },
124     {   38, "EUC-KR" },
125     {   39, "ISO-2022-JP" },
126     {   40, "ISO-2022-JP-2" },
127     {   41, "JIS_C6220-1969-jp" },
128     {   42, "JIS_C6220-1969-ro" },
129     {   43, "PT" },
130     {   44, "greek7-old" },
131     {   45, "latin-greek" },
132     {   46, "NF_Z_62-010_(1973)" },
133     {   47, "Latin-greek-1" },
134     {   48, "ISO_5427" },
135     {   49, "JIS_C6226-1978" },
136     {   50, "BS_viewdata" },
137     {   51, "INIS" },
138     {   52, "INIS-8" },
139     {   53, "INIS-cyrillic" },
140     {   54, "ISO_5427:1981" },
141     {   55, "ISO_5428:1980" },
142     {   56, "GB_1988-80" },
143     {   57, "GB_2312-80" },
144     {   58, "NS_4551-2" },
145     {   59, "videotex-suppl" },
146     {   60, "PT2" },
147     {   61, "ES2" },
148     {   62, "MSZ_7795.3" },
149     {   63, "JIS_C6226-1983" },
150     {   64, "greek7" },
151     {   65, "ASMO_449" },
152     {   66, "iso-ir-90" },
153     {   67, "JIS_C6229-1984-a" },
154     {   68, "JIS_C6229-1984-b" },
155     {   69, "JIS_C6229-1984-b-add" },
156     {   70, "JIS_C6229-1984-hand" },
157     {   71, "JIS_C6229-1984-hand-add" },
158     {   72, "JIS_C6229-1984-kana" },
159     {   73, "ISO_2033-1983" },
160     {   74, "ANSI_X3.110-1983" },
161     {   75, "T.61-7bit" },
162     {   76, "T.61-8bit" },
163     {   77, "ECMA-cyrillic" },
164     {   78, "CSA_Z243.4-1985-1" },
165     {   79, "CSA_Z243.4-1985-2" },
166     {   80, "CSA_Z243.4-1985-gr" },
167     {   81, "ISO-8859-6-E" },
168     {   82, "ISO-8859-6-I" },
169     {   83, "T.101-G2" },
170     {   84, "ISO-8859-8-E" },
171     {   85, "ISO-8859-8-I" },
172     {   86, "CSN_369103" },
173     {   87, "JUS_I.B1.002" },
174     {   88, "IEC_P27-1" },
175     {   89, "JUS_I.B1.003-serb" },
176     {   90, "JUS_I.B1.003-mac" },
177     {   91, "greek-ccitt" },
178     {   92, "NC_NC00-10:81" },
179     {   93, "ISO_6937-2-25" },
180     {   94, "GOST_19768-74" },
181     {   95, "ISO_8859-supp" },
182     {   96, "ISO_10367-box" },
183     {   97, "latin-lap" },
184     {   98, "JIS_X0212-1990" },
185     {   99, "DS_2089" },
186     {  100, "us-dk" },
187     {  101, "dk-us" },
188     {  102, "KSC5636" },
189     {  103, "UNICODE-1-1-UTF-7" },
190     {  104, "ISO-2022-CN" },
191     {  105, "ISO-2022-CN-EXT" },
192     {  106, "UTF-8" },
193     {  109, "ISO-8859-13" },
194     {  110, "ISO-8859-14" },
195     {  111, "ISO-8859-15" },
196     {  112, "ISO-8859-16" },
197     {  113, "GBK" },
198     {  114, "GB18030" },
199     {  115, "OSD_EBCDIC_DF04_15" },
200     {  116, "OSD_EBCDIC_DF03_IRV" },
201     {  117, "OSD_EBCDIC_DF04_1" },
202     {  118, "ISO-11548-1" },
203     {  119, "KZ-1048" },
204
205     { 1000, "ISO-10646-UCS-2" },
206     { 1001, "ISO-10646-UCS-4" },
207     { 1002, "ISO-10646-UCS-Basic" },
208     { 1003, "ISO-10646-Unicode-Latin1" },
209     { 1004, "ISO-10646-J-1" },
210     { 1005, "ISO-Unicode-IBM-1261" },
211     { 1006, "ISO-Unicode-IBM-1268" },
212     { 1007, "ISO-Unicode-IBM-1276" },
213     { 1008, "ISO-Unicode-IBM-1264" },
214     { 1009, "ISO-Unicode-IBM-1265" },
215     { 1010, "UNICODE-1-1" },
216     { 1011, "SCSU" },
217     { 1012, "UTF-7" },
218     { 1013, "UTF-16BE" },
219     { 1014, "UTF-16LE" },
220     { 1015, "UTF-16" },
221     { 1016, "CESU-8" },
222     { 1017, "UTF-32" },
223     { 1018, "UTF-32BE" },
224     { 1019, "UTF-32LE" },
225     { 1020, "BOCU-1" },
226
227     { 2000, "ISO-8859-1-Windows-3.0-Latin-1" },
228     { 2001, "ISO-8859-1-Windows-3.1-Latin-1" },
229     { 2002, "ISO-8859-2-Windows-Latin-2" },
230     { 2003, "ISO-8859-9-Windows-Latin-5" },
231     { 2004, "hp-roman8" },
232     { 2005, "Adobe-Standard-Encoding" },
233     { 2006, "Ventura-US" },
234     { 2007, "Ventura-International" },
235     { 2008, "DEC-MCS" },
236     { 2009, "IBM850" },
237     { 2010, "IBM852" },
238     { 2011, "IBM437" },
239     { 2012, "PC8-Danish-Norwegian" },
240     { 2013, "IBM862" },
241     { 2014, "PC8-Turkish" },
242     { 2015, "IBM-Symbols" },
243     { 2016, "IBM-Thai" },
244     { 2017, "HP-Legal" },
245     { 2018, "HP-Pi-font" },
246     { 2019, "HP-Math8" },
247     { 2020, "Adobe-Symbol-Encoding" },
248     { 2021, "HP-DeskTop" },
249     { 2022, "Ventura-Math" },
250     { 2023, "Microsoft-Publishing" },
251     { 2024, "Windows-31J" },
252     { 2025, "GB2312" },
253     { 2026, "Big5" },
254     { 2027, "macintosh" },
255     { 2028, "IBM037" },
256     { 2029, "IBM038" },
257     { 2030, "IBM273" },
258     { 2031, "IBM274" },
259     { 2032, "IBM275" },
260     { 2033, "IBM277" },
261     { 2034, "IBM278" },
262     { 2035, "IBM280" },
263     { 2036, "IBM281" },
264     { 2037, "IBM284" },
265     { 2038, "IBM285" },
266     { 2039, "IBM290" },
267     { 2040, "IBM297" },
268     { 2041, "IBM420" },
269     { 2042, "IBM423" },
270     { 2043, "IBM424" },
271     { 2044, "IBM500" },
272     { 2045, "IBM851" },
273     { 2046, "IBM855" },
274     { 2047, "IBM857" },
275     { 2048, "IBM860" },
276     { 2049, "IBM861" },
277     { 2050, "IBM863" },
278     { 2051, "IBM864" },
279     { 2052, "IBM865" },
280     { 2053, "IBM868" },
281     { 2054, "IBM869" },
282     { 2055, "IBM870" },
283     { 2056, "IBM871" },
284     { 2057, "IBM880" },
285     { 2058, "IBM891" },
286     { 2059, "IBM903" },
287     { 2060, "IBM904" },
288     { 2061, "IBM905" },
289     { 2062, "IBM918" },
290     { 2063, "IBM1026" },
291     { 2064, "EBCDIC-AT-DE" },
292     { 2065, "EBCDIC-AT-DE-A" },
293     { 2066, "EBCDIC-CA-FR" },
294     { 2067, "EBCDIC-DK-NO" },
295     { 2068, "EBCDIC-DK-NO-A" },
296     { 2069, "EBCDIC-FI-SE" },
297     { 2070, "EBCDIC-FI-SE-A" },
298     { 2071, "EBCDIC-FR" },
299     { 2072, "EBCDIC-IT" },
300     { 2073, "EBCDIC-PT" },
301     { 2074, "EBCDIC-ES" },
302     { 2075, "EBCDIC-ES-A" },
303     { 2076, "EBCDIC-ES-S" },
304     { 2077, "EBCDIC-UK" },
305     { 2078, "EBCDIC-US" },
306     { 2079, "UNKNOWN-8BIT" },
307     { 2080, "MNEMONIC" },
308     { 2081, "MNEM" },
309     { 2082, "VISCII" },
310     { 2083, "VIQR" },
311     { 2084, "KOI8-R" },
312     { 2085, "HZ-GB-2312" },
313     { 2086, "IBM866" },
314     { 2087, "IBM775" },
315     { 2088, "KOI8-U" },
316     { 2089, "IBM00858" },
317     { 2090, "IBM00924" },
318     { 2091, "IBM01140" },
319     { 2092, "IBM01141" },
320     { 2093, "IBM01142" },
321     { 2094, "IBM01143" },
322     { 2095, "IBM01144" },
323     { 2096, "IBM01145" },
324     { 2097, "IBM01146" },
325     { 2098, "IBM01147" },
326     { 2099, "IBM01148" },
327     { 2100, "IBM01149" },
328     { 2101, "Big5-HKSCS" },
329     { 2102, "IBM1047" },
330     { 2103, "PTCP154" },
331     { 2104, "Amiga-1251" },
332     { 2105, "KOI7-switched" },
333     { 2106, "BRF" },
334     { 2107, "TSCII" },
335     { 2108, "CP51932" },
336     { 2109, "windows-874" },
337
338     { 2250, "windows-1250" },
339     { 2251, "windows-1251" },
340     { 2252, "windows-1252" },
341     { 2253, "windows-1253" },
342     { 2254, "windows-1254" },
343     { 2255, "windows-1255" },
344     { 2256, "windows-1256" },
345     { 2257, "windows-1257" },
346     { 2258, "windows-1258" },
347     { 2259, "TIS-620" },
348     { 2260, "CP50220" },
349     { 0, NULL }
350 };
351 value_string_ext wap_mib_enum_vals_character_sets_ext = VALUE_STRING_EXT_INIT(wap_mib_enum_vals_character_sets);