From Olivier Biot: have a separate subtree ett_ value for concatenated
[obnox/wireshark/wip.git] / packet-wbxml.c
1 /* packet-wbxml.c
2  * Routines for wbxml dissection
3  * Copyright 2003, Olivier Biot <olivier.biot (ad) siemens.com>
4  *
5  * $Id: packet-wbxml.c,v 1.12 2003/10/09 18:54:06 guy Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
9  * Copyright 1998 Gerald Combs
10  *
11  * WAP Binary XML decoding functionality provided by Olivier Biot.
12  * 
13  * The WAP specifications are found at the WAP Forum:
14  * http://www.wapforum.org/what/Technical.htm
15  * 
16  * This program is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU General Public License
18  * as published by the Free Software Foundation; either version 2
19  * of the License, or (at your option) any later version.
20  * 
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  * 
26  * You should have received a copy of the GNU General Public License
27  * along with this program; if not, write to the Free Software
28  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29  */
30
31 /* Edit this file with 4-space tabulation */
32
33 #ifdef HAVE_CONFIG_H
34 # include "config.h"
35 #endif
36
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40
41 #include <glib.h>
42
43 #ifdef NEED_SNPRINTF_H
44 # include "snprintf.h"
45 #endif
46
47 #include <epan/packet.h>
48
49 /* We need the function tvb_get_guintvar() */
50 #include "packet-wap.h"
51
52 /* The code in this source file dissects the WAP Binary XML content,
53  * and if possible renders it. WBXML mappings are defined in the
54  * "wbxml_map[]" array.
55  *
56  * NOTES:
57  *
58  *  - Code page switches only apply to the following token. In the WBXML/1.x
59  *    ABNF notation, it can be proven that the switch_page can only precede
60  *    the following tokens:
61  *      o  stag      : TAG | LITERAL | LITERAL_A | LITERAL_C | LITERAL_AC
62  *      o  attr      : ATTRSTART | ATTRVALUE
63  *      o  extension : EXT_I | EXT_T | EXT
64  *    Code page switches are displayed in a separate column. The only allowed
65  *    code page switches are from code page 0 to another codepage (by means of
66  *    a SWITCH_PAGE token), and from this other code page back to code page 0
67  *    (this happens automatically).
68  *
69  *  - In order to render the XML content, recursion is inevitable at some
70  *    point (when a tag with content occurs in the content of a tag with
71  *    content). The code will however not recurse if this is not strictly
72  *    required (e.g., tag without content in the content of a tag with
73  *    content).
74  *
75  *  - I found it useful to display the XML nesting level as a first "column",
76  *    followed by the abbreviated WBXML token interpretation. When a mapping
77  *    is defined for the parsed WBXML content, then the XML rendering is
78  *    displayed with appropriate indentation (maximum nesting level = 255,
79  *    after which the nesting and level will safely roll-over to 0).
80  *
81  *  - The WAP Forum defines the order of precedence for finding out the
82  *    WBXML content type (same rules for charset) as follows:
83  *      1. Look in the Content-Type WSP header
84  *      2. Look in the WBXML header
85  *    Currently there is no means of using content type parameters:
86  *      o  Type=<some_type>
87  *      o  Charset=<charset_of_the_content>
88  *    So it is possible some WBXML content types are incorrectly parsed.
89  *    This would only be the case when the content type declaration in the
90  *    WSP Content-Type header would be different (or would have parameters
91  *    which are relevant to the WBXML decoding) from the content type
92  *    identifier specified in the WBXML header.
93  *    TODO: investigate this and provide correct decoding at all times.
94  */
95
96 typedef struct _value_valuestring {
97   guint32 value;
98   const value_string *valstrptr;
99 } value_valuestring;
100
101 /* Tries to match val against each element in the value_value_string array vvs.
102  * Returns the associated value_string ptr on a match, or NULL on failure. */
103 static const value_string *
104 val_to_valstr(guint32 val, const value_valuestring *vvs)
105 {
106   gint i = 0;
107
108   while (vvs[i].valstrptr) {
109         if (vvs[i].value == val)
110       return(vvs[i].valstrptr);
111       i++;
112   }
113
114   return(NULL);
115 }
116
117
118 /************************** Variable declarations **************************/
119
120
121 /* Initialize the protocol and registered fields */
122 static int proto_wbxml = -1;
123 static int hf_wbxml_version = -1;
124 static int hf_wbxml_public_id_known = -1;
125 static int hf_wbxml_public_id_literal = -1;
126 static int hf_wbxml_charset = -1;
127
128 /* Initialize the subtree pointers */
129 static gint ett_wbxml = -1;
130 static gint ett_wbxml_str_tbl = -1;
131 static gint ett_wbxml_content = -1;
132
133
134 /**************** WBXML related declarations and definitions ****************/
135
136
137 /* WBXML public ID mappings. For an up-to-date list, see
138  * http://www.wapforum.org/wina/wbxml-public-docid.htm */
139 static const value_string vals_wbxml_public_ids[] = {
140         /* 0x00 = literal public identifier */
141         { 0x01, "Unknown / missing Public Identifier" },
142         { 0x02, "-//WAPFORUM//DTD WML 1.0//EN (WML 1.0)" },
143         { 0x03, "-//WAPFORUM//DTD WTA 1.0//EN (WTA Event 1.0) - Deprecated" },
144         { 0x04, "-//WAPFORUM//DTD WML 1.1//EN (WML 1.1)" },
145         { 0x05, "-//WAPFORUM//DTD SI 1.0//EN (Service Indication 1.0)" },
146         { 0x06, "-//WAPFORUM//DTD SL 1.0//EN (Service Loading 1.0)" },
147         { 0x07, "-//WAPFORUM//DTD CO 1.0//EN (Cache Operation 1.0)" },
148         { 0x08, "-//WAPFORUM//DTD CHANNEL 1.0//EN (Channel 1.1)" },
149         { 0x09, "-//WAPFORUM//DTD WML 1.2//EN (WML 1.2)" },
150         { 0x0a, "-//WAPFORUM//DTD WML 1.3//EN (WML 1.3)" },
151         { 0x0b, "-//WAPFORUM//DTD PROV 1.0//EN (Provisioning 1.0)" },
152         { 0x0c, "-//WAPFORUM//DTD WTA-WML 1.2//EN (WTA-WML 1.2)" },
153         { 0x0d, "-//WAPFORUM//DTD EMN 1.0//EN (Email Notification 1.0)" },
154         { 0x0e, "-//WAPFORUM//DTD DRMREL 1.0//EN (DRMREL 1.0)" },
155         
156         /* Registered values - www.syncml.org */
157         { 0x0fd1, "-//SYNCML//DTD SyncML 1.0//EN (SyncML 1.0)" },
158         { 0x0fd3, "-//SYNCML//DTD SyncML 1.1//EN (SyncML 1.1)" },
159
160         /* Registered values - www.wapforum.org/wina/ */
161         { 0x1100, "-//PHONE.COM//DTD ALERT 1.0//EN" },
162         { 0x1101, "-//PHONE.COM//DTD CACHE-OPERATION 1.0//EN" },
163         { 0x1102, "-//PHONE.COM//DTD SIGNAL 1.0//EN" },
164         { 0x1103, "-//PHONE.COM//DTD LIST 1.0//EN" },
165         { 0x1104, "-//PHONE.COM//DTD LISTCMD 1.0//EN" },
166         { 0x1105, "-//PHONE.COM//DTD CHANNEL 1.0//EN" },
167         { 0x1106, "-//PHONE.COM//DTD MMC 1.0//EN" },
168         { 0x1107, "-//PHONE.COM//DTD BEARER-CHOICE 1.0//EN" },
169         { 0x1108, "-//PHONE.COM//DTD WML 1.1//EN (WML+ 1.1)" },
170         { 0x1109, "-//PHONE.COM//DTD CHANNEL 1.1//EN" },
171         { 0x110a, "-//PHONE.COM//DTD LIST 1.1//EN" },
172         { 0x110b, "-//PHONE.COM//DTD LISTCMD 1.1//EN" },
173         { 0x110c, "-//PHONE.COM//DTD MMC 1.1//EN" },
174         { 0x110d, "-//PHONE.COM//DTD WML 1.3//EN (WML+ 1.3)" },
175         { 0x110e, "-//PHONE.COM//DTD MMC 2.0//EN" },
176         
177         { 0x00, NULL }
178 };
179
180 static const value_string vals_wbxml_versions[] = {
181         { 0x00, "1.0" },        /* WAP-104-WBXML */
182         { 0x01, "1.1" },        /* WAP-135-WBXML */
183         { 0x02, "1.2" },        /* WAP-154-WBXML */
184         { 0x03, "1.3" },        /* WAP-192-WBXML */
185         
186         { 0x00, NULL }
187 };
188
189 /* WBXML 1.0 global tokens: WAP-104-WBXML
190  * Same token mapping as in vals_wbxml1x_global_tokens, but:
191  *   { 0xC3, "RESERVED_2" }
192  */
193
194 /* WBXML 1.x (x>0) global tokens: WAP-135-WBXML, WAP-154-WBXML, WAP-192-WBXML
195  */
196 static const value_string vals_wbxml1x_global_tokens[] = {
197         { 0x00, "SWITCH_PAGE" },
198         { 0x01, "END" },
199         { 0x02, "ENTITY" },
200         { 0x03, "STR_I" },
201         { 0x04, "LITERAL" },
202
203         { 0x40, "EXT_I_0" },
204         { 0x41, "EXT_I_1" },
205         { 0x42, "EXT_I_2" },
206         { 0x43, "PI" },
207         { 0x44, "LITERAL_C" },
208
209         { 0x80, "EXT_T_0" },
210         { 0x81, "EXT_T_1" },
211         { 0x82, "EXT_T_2" },
212         { 0x83, "STR_T" },
213         { 0x84, "LITERAL_A" },
214
215         { 0xC0, "EXT_0" },
216         { 0xC1, "EXT_1" },
217         { 0xC2, "EXT_2" },
218         { 0xC3, "OPAQUE" },
219         { 0xC4, "LITERAL_AC" },
220
221         { 0x00, NULL }
222 };
223
224
225 /********************** WBXML token mapping definition **********************/
226
227
228 /* WML 1.0
229  * 
230  * Wireless Markup Language
231  ***************************************/
232
233 /*****   Global extension tokens   *****/
234 static const value_string wbxml_wmlc10_global_cp0[] = {
235         { 0x40, "Variable substitution - escaped" },
236         { 0x41, "Variable substitution - unescaped" },
237         { 0x42, "Variable substitution - no transformation" },
238         { 0x80, "Variable substitution - escaped" },
239         { 0x81, "Variable substitution - unescaped" },
240         { 0x82, "Variable substitution - no transformation" },
241         { 0xC0, "Reserved" },
242         { 0xC1, "Reserved" },
243         { 0xC2, "Reserved" },
244
245         { 0x00, NULL }
246 };
247
248 /*****         Tag tokens          *****/
249 static const value_string wbxml_wmlc10_tags_cp0[] = {
250         /* 0x00 -- 0x04 GLOBAL */
251         /* 0x05 -- 0xE1 */
252         { 0xE2, "A" },
253         { 0xE3, "ACCESS" },
254         { 0xE4, "B" },
255         { 0xE5, "BIG" },
256         { 0xE6, "BR" },
257         { 0xE7, "CARD" },
258         { 0xE8, "DO" },
259         { 0xE9, "EM" },
260         { 0xEA, "FIELDSET" },
261         { 0xEB, "GO" },
262         { 0xEC, "HEAD" },
263         { 0xED, "I" },
264         { 0xEE, "IMG" },
265         { 0xEF, "INPUT" },
266         { 0xF0, "META" },
267         { 0xF1, "NOOP" },
268         { 0xF2, "PREV" },
269         { 0xF3, "ONEVENT" },
270         { 0xF4, "OPTGROUP" },
271         { 0xF5, "OPTION" },
272         { 0xF6, "REFRESH" },
273         { 0xF7, "SELECT" },
274         { 0xF8, "SMALL" },
275         { 0xF9, "STRONG" },
276         { 0xFA, "TAB" },
277         { 0xFB, "TEMPLATE" },
278         { 0xFC, "TIMER" },
279         { 0xFD, "U" },
280         { 0xFE, "VAR" },
281         { 0xFF, "WML" },
282
283         { 0x00, NULL }
284 };
285
286 /*****    Attribute Start tokens   *****/
287 static const value_string wbxml_wmlc10_attrStart_cp0[] = {
288         /* 0x00 -- 0x04 GLOBAL */
289         { 0x05, "ACCEPT-CHARSET=" },
290         { 0x06, "ALIGN='BOTTOM'" },
291         { 0x07, "ALIGN='CENTER'" },
292         { 0x08, "ALIGN='LEFT'" },
293         { 0x09, "ALIGN='MIDDLE'" },
294         { 0x0A, "ALIGN='RIGHT'" },
295         { 0x0B, "ALIGN='TOP'" },
296         { 0x0C, "ALT=" },
297         { 0x0D, "CONTENT=" },
298         { 0x0E, "DEFAULT=" },
299         { 0x0F, "DOMAIN=" },
300         { 0x10, "EMPTYOK='FALSE'" },
301         { 0x11, "EMPTYOK='TRUE'" },
302         { 0x12, "FORMAT=" },
303         { 0x13, "HEIGHT=" },
304         { 0x14, "HSPACE=" },
305         { 0x15, "IDEFAULT=" },
306         { 0x16, "IKEY=" },
307         { 0x17, "KEY=" },
308         { 0x18, "LABEL=" },
309         { 0x19, "LOCALSRC=" },
310         { 0x1A, "MAXLENGTH=" },
311         { 0x1B, "METHOD='GET'" },
312         { 0x1C, "METHOD='POST'" },
313         { 0x1D, "MODE='NOWRAP'" },
314         { 0x1E, "MODE='WRAP'" },
315         { 0x1F, "MULTIPLE='FALSE'" },
316         { 0x20, "MULTIPLE='TRUE'" },
317         { 0x21, "NAME=" },
318         { 0x22, "NEWCONTEXT='FALSE'" },
319         { 0x23, "NEWCONTEXT='TRUE'" },
320         { 0x24, "ONCLICK=" },
321         { 0x25, "ONENTERBACKWARD=" },
322         { 0x26, "ONENTERFORWARD=" },
323         { 0x27, "ONTIMER=" },
324         { 0x28, "OPTIONAL='FALSE'" },
325         { 0x29, "OPTIONAL='TRUE'" },
326         { 0x2A, "PATH=" },
327         { 0x2B, "POSTDATA=" },
328         { 0x2C, "PUBLIC='FALSE'" },
329         { 0x2D, "PUBLIC='TRUE'" },
330         { 0x2E, "SCHEME=" },
331         { 0x2F, "SENDREFERER='FALSE'" },
332         { 0x30, "SENDREFERER='TRUE'" },
333         { 0x31, "SIZE=" },
334         { 0x32, "SRC=" },
335         { 0x33, "STYLE='LIST'" },
336         { 0x34, "STYLE='SET'" },
337         { 0x35, "TABINDEX=" },
338         { 0x36, "TITLE=" },
339         { 0x37, "TYPE=" },
340         { 0x38, "TYPE='ACCEPT'" },
341         { 0x39, "TYPE='DELETE'" },
342         { 0x3A, "TYPE='HELP'" },
343         { 0x3B, "TYPE='PASSWORD'" },
344         { 0x3C, "TYPE='ONCLICK'" },
345         { 0x3D, "TYPE='ONENTERBACKWARD'" },
346         { 0x3E, "TYPE='ONENTERFORWARD'" },
347         { 0x3F, "TYPE='ONTIMER'" },
348         /* 0x40 -- 0x44 GLOBAL */
349         { 0x45, "TYPE='OPTIONS'" },
350         { 0x46, "TYPE='PREV'" },
351         { 0x47, "TYPE='RESET'" },
352         { 0x48, "TYPE='TEXT'" },
353         { 0x49, "TYPE='vnd.'" },
354         { 0x4A, "URL=" },
355         { 0x4B, "URL='http://'" },
356         { 0x4C, "URL='https://'" },
357         { 0x4D, "USER-AGENT=" },
358         { 0x4E, "VALUE=" },
359         { 0x4F, "VSPACE=" },
360         { 0x50, "WIDTH=" },
361         { 0x51, "xml:lang=" },
362
363         { 0x00, NULL }
364 };
365
366 /*****    Attribute Value tokens   *****/
367 static const value_string wbxml_wmlc10_attrValue_cp0[] = {
368         /* 0x80 -- 0x84 GLOBAL */
369         { 0x85, "'.com/'" },
370         { 0x86, "'.edu/'" },
371         { 0x87, "'.net/'" },
372         { 0x88, "'.org/'" },
373         { 0x89, "'ACCEPT'" },
374         { 0x8A, "'BOTTOM'" },
375         { 0x8B, "'CLEAR'" },
376         { 0x8C, "'DELETE'" },
377         { 0x8D, "'HELP'" },
378         { 0x8E, "'http://'" },
379         { 0x8F, "'http://www.'" },
380         { 0x90, "'https://'" },
381         { 0x91, "'https://www.'" },
382         { 0x92, "'LIST'" },
383         { 0x93, "'MIDDLE'" },
384         { 0x94, "'NOWRAP'" },
385         { 0x95, "'ONCLICK'" },
386         { 0x96, "'ONENTERBACKWARD'" },
387         { 0x97, "'ONENTERFORWARD'" },
388         { 0x98, "'ONTIMER'" },
389         { 0x99, "'OPTIONS'" },
390         { 0x9A, "'PASSWORD'" },
391         { 0x9B, "'RESET'" },
392         { 0x9C, "'SET'" },
393         { 0x9D, "'TEXT'" },
394         { 0x9E, "'TOP'" },
395         { 0x9F, "'UNKNOWN'" },
396         { 0xA0, "'WRAP'" },
397         { 0xA1, "'www.'" },
398
399         { 0x00, NULL }
400 };
401
402 /***** Token code page aggregation *****/
403 static const value_valuestring wbxml_wmlc10_global[] = {
404         { 0, wbxml_wmlc10_global_cp0 },
405         { 0, NULL }
406 };
407
408 static const value_valuestring wbxml_wmlc10_tags[] = {
409         { 0, wbxml_wmlc10_tags_cp0 },
410         { 0, NULL }
411 };
412
413 static const value_valuestring wbxml_wmlc10_attrStart[] = {
414         { 0, wbxml_wmlc10_attrStart_cp0 },
415         { 0, NULL }
416 };
417
418 static const value_valuestring wbxml_wmlc10_attrValue[] = {
419         { 0, wbxml_wmlc10_attrValue_cp0 },
420         { 0, NULL }
421 };
422
423
424
425
426
427 /* WML 1.1
428  * 
429  * Wireless Markup Language
430  ***************************************/
431
432 /*****   Global extension tokens   *****/
433 /* Same as in WML 1.0 */
434
435 /*****         Tag tokens          *****/
436 static const value_string wbxml_wmlc11_tags_cp0[] = {
437         /* 0x00 -- 0x04 GLOBAL */
438         /* 0x05 -- 0x1B */
439         { 0x1C, "a" },
440         { 0x1D, "td" },
441         { 0x1E, "tr" },
442         { 0x1F, "table" },
443         { 0x20, "p" },
444         { 0x21, "postfield" },
445         { 0x22, "anchor" },
446         { 0x23, "access" },
447         { 0x24, "b" },
448         { 0x25, "big" },
449         { 0x26, "br" },
450         { 0x27, "card" },
451         { 0x28, "do" },
452         { 0x29, "em" },
453         { 0x2A, "fieldset" },
454         { 0x2B, "go" },
455         { 0x2C, "head" },
456         { 0x2D, "i" },
457         { 0x2E, "img" },
458         { 0x2F, "input" },
459         { 0x30, "meta" },
460         { 0x31, "noop" },
461         { 0x32, "prev" },
462         { 0x33, "onevent" },
463         { 0x34, "optgroup" },
464         { 0x35, "option" },
465         { 0x36, "refresh" },
466         { 0x37, "select" },
467         { 0x38, "small" },
468         { 0x39, "strong" },
469         /* 0x3A */
470         { 0x3B, "template" },
471         { 0x3C, "timer" },
472         { 0x3D, "u" },
473         { 0x3E, "setvar" },
474         { 0x3F, "wml" },
475
476         { 0x00, NULL }
477 };
478
479 /*****    Attribute Start tokens   *****/
480 static const value_string wbxml_wmlc11_attrStart_cp0[] = {
481         /* 0x00 -- 0x04 GLOBAL */
482         { 0x05, "accept-charset=" },
483         { 0x06, "align='bottom'" },
484         { 0x07, "align='center'" },
485         { 0x08, "align='left'" },
486         { 0x09, "align='middle'" },
487         { 0x0A, "align='right'" },
488         { 0x0B, "align='top'" },
489         { 0x0C, "alt=" },
490         { 0x0D, "content=" },
491         /* 0x0E */
492         { 0x0F, "domain=" },
493         { 0x10, "emptyok='false'" },
494         { 0x11, "emptyok='true'" },
495         { 0x12, "format=" },
496         { 0x13, "height=" },
497         { 0x14, "hspace=" },
498         { 0x15, "ivalue=" },
499         { 0x16, "iname=" },
500         /* 0x17 */
501         { 0x18, "label=" },
502         { 0x19, "localsrc=" },
503         { 0x1A, "maxlength=" },
504         { 0x1B, "method='get'" },
505         { 0x1C, "method='post'" },
506         { 0x1D, "mode='nowrap'" },
507         { 0x1E, "mode='wrap'" },
508         { 0x1F, "multiple='false'" },
509         { 0x20, "multiple='true'" },
510         { 0x21, "name=" },
511         { 0x22, "newcontext='false'" },
512         { 0x23, "newcontext='true'" },
513         { 0x24, "onpick=" },
514         { 0x25, "onenterbackward=" },
515         { 0x26, "onenterforward=" },
516         { 0x27, "ontimer=" },
517         { 0x28, "optional='false'" },
518         { 0x29, "optional='true'" },
519         { 0x2A, "path=" },
520         /* 0x2B -- 0x2D */
521         { 0x2E, "scheme=" },
522         { 0x2F, "sendreferer='false'" },
523         { 0x30, "sendreferer='true'" },
524         { 0x31, "size=" },
525         { 0x32, "src=" },
526         { 0x33, "ordered='false'" },
527         { 0x34, "ordered='true'" },
528         { 0x35, "tabindex=" },
529         { 0x36, "title=" },
530         { 0x37, "type=" },
531         { 0x38, "type='accept'" },
532         { 0x39, "type='delete'" },
533         { 0x3A, "type='help'" },
534         { 0x3B, "type='password'" },
535         { 0x3C, "type='onpick'" },
536         { 0x3D, "type='onenterbackward'" },
537         { 0x3E, "type='onenterforward'" },
538         { 0x3F, "type='ontimer'" },
539         /* 0x40 -- 0x44 GLOBAL */
540         { 0x45, "type='options'" },
541         { 0x46, "type='prev'" },
542         { 0x47, "type='reset'" },
543         { 0x48, "type='text'" },
544         { 0x49, "type='vnd.'" },
545         { 0x4A, "href=" },
546         { 0x4B, "href='http://'" },
547         { 0x4C, "href='https://'" },
548         { 0x4D, "value=" },
549         { 0x4E, "vspace=" },
550         { 0x4F, "width=" },
551         { 0x50, "xml:lang=" },
552         /* 0x51 */
553         { 0x52, "align=" },
554         { 0x53, "columns=" },
555         { 0x54, "class=" },
556         { 0x55, "id=" },
557         { 0x56, "forua='false'" },
558         { 0x57, "forua='true'" },
559         { 0x58, "src='http://'" },
560         { 0x59, "src='https://'" },
561         { 0x5A, "http-equiv=" },
562         { 0x5B, "http-equiv='Content-Type'" },
563         { 0x5C, "content='application/vnd.wap.wmlc;charset='" },
564         { 0x5D, "http-equiv='Expires'" },
565
566         { 0x00, NULL }
567 };
568
569 /*****    Attribute Value tokens   *****/
570 static const value_string wbxml_wmlc11_attrValue_cp0[] = {
571         /* 0x80 -- 0x84 GLOBAL */
572         { 0x85, "'.com/'" },
573         { 0x86, "'.edu/'" },
574         { 0x87, "'.net/'" },
575         { 0x88, "'.org/'" },
576         { 0x89, "'accept'" },
577         { 0x8A, "'bottom'" },
578         { 0x8B, "'clear'" },
579         { 0x8C, "'delete'" },
580         { 0x8D, "'help'" },
581         { 0x8E, "'http://'" },
582         { 0x8F, "'http://www.'" },
583         { 0x90, "'https://'" },
584         { 0x91, "'https://www.'" },
585         /* 0x92 */
586         { 0x93, "'middle'" },
587         { 0x94, "'nowrap'" },
588         { 0x95, "'onpick'" },
589         { 0x96, "'onenterbackward'" },
590         { 0x97, "'onenterforward'" },
591         { 0x98, "'ontimer'" },
592         { 0x99, "'options'" },
593         { 0x9A, "'password'" },
594         { 0x9B, "'reset'" },
595         /* 0x9C */
596         { 0x9D, "'text'" },
597         { 0x9E, "'top'" },
598         { 0x9F, "'unknown'" },
599         { 0xA0, "'wrap'" },
600         { 0xA1, "'www.'" },
601
602         { 0x00, NULL }
603 };
604
605 /***** Token code page aggregation *****/
606 static const value_valuestring wbxml_wmlc11_global[] = {
607         { 0, wbxml_wmlc10_global_cp0 }, /* Same as WML 1.0 */
608         { 0, NULL }
609 };
610
611 static const value_valuestring wbxml_wmlc11_tags[] = {
612         { 0, wbxml_wmlc11_tags_cp0 },
613         { 0, NULL }
614 };
615
616 static const value_valuestring wbxml_wmlc11_attrStart[] = {
617         { 0, wbxml_wmlc11_attrStart_cp0 },
618         { 0, NULL }
619 };
620
621 static const value_valuestring wbxml_wmlc11_attrValue[] = {
622         { 0, wbxml_wmlc11_attrValue_cp0 },
623         { 0, NULL }
624 };
625
626
627
628
629
630 /* WML 1.2
631  * 
632  * Wireless Markup Language
633  ***************************************/
634
635 /*****   Global extension tokens   *****/
636 /* Same as in WML 1.0 */
637
638 /*****         Tag tokens          *****/
639 static const value_string wbxml_wmlc12_tags_cp0[] = {
640         /* 0x00 -- 0x04 GLOBAL */
641         /* 0x05 -- 0x1A */
642         { 0x1B, "pre" },
643         { 0x1C, "a" },
644         { 0x1D, "td" },
645         { 0x1E, "tr" },
646         { 0x1F, "table" },
647         { 0x20, "p" },
648         { 0x21, "postfield" },
649         { 0x22, "anchor" },
650         { 0x23, "access" },
651         { 0x24, "b" },
652         { 0x25, "big" },
653         { 0x26, "br" },
654         { 0x27, "card" },
655         { 0x28, "do" },
656         { 0x29, "em" },
657         { 0x2A, "fieldset" },
658         { 0x2B, "go" },
659         { 0x2C, "head" },
660         { 0x2D, "i" },
661         { 0x2E, "img" },
662         { 0x2F, "input" },
663         { 0x30, "meta" },
664         { 0x31, "noop" },
665         { 0x32, "prev" },
666         { 0x33, "onevent" },
667         { 0x34, "optgroup" },
668         { 0x35, "option" },
669         { 0x36, "refresh" },
670         { 0x37, "select" },
671         { 0x38, "small" },
672         { 0x39, "strong" },
673         /* 0x3A */
674         { 0x3B, "template" },
675         { 0x3C, "timer" },
676         { 0x3D, "u" },
677         { 0x3E, "setvar" },
678         { 0x3F, "wml" },
679
680         { 0x00, NULL }
681 };
682
683 /*****    Attribute Start tokens   *****/
684 static const value_string wbxml_wmlc12_attrStart_cp0[] = {
685         /* 0x00 -- 0x04 GLOBAL */
686         { 0x05, "accept-charset=" },
687         { 0x06, "align='bottom'" },
688         { 0x07, "align='center'" },
689         { 0x08, "align='left'" },
690         { 0x09, "align='middle'" },
691         { 0x0A, "align='right'" },
692         { 0x0B, "align='top'" },
693         { 0x0C, "alt=" },
694         { 0x0D, "content=" },
695         /* 0x0E */
696         { 0x0F, "domain=" },
697         { 0x10, "emptyok='false'" },
698         { 0x11, "emptyok='true'" },
699         { 0x12, "format=" },
700         { 0x13, "height=" },
701         { 0x14, "hspace=" },
702         { 0x15, "ivalue=" },
703         { 0x16, "iname=" },
704         /* 0x17 */
705         { 0x18, "label=" },
706         { 0x19, "localsrc=" },
707         { 0x1A, "maxlength=" },
708         { 0x1B, "method='get'" },
709         { 0x1C, "method='post'" },
710         { 0x1D, "mode='nowrap'" },
711         { 0x1E, "mode='wrap'" },
712         { 0x1F, "multiple='false'" },
713         { 0x20, "multiple='true'" },
714         { 0x21, "name=" },
715         { 0x22, "newcontext='false'" },
716         { 0x23, "newcontext='true'" },
717         { 0x24, "onpick=" },
718         { 0x25, "onenterbackward=" },
719         { 0x26, "onenterforward=" },
720         { 0x27, "ontimer=" },
721         { 0x28, "optional='false'" },
722         { 0x29, "optional='true'" },
723         { 0x2A, "path=" },
724         /* 0x2B -- 0x2D */
725         { 0x2E, "scheme=" },
726         { 0x2F, "sendreferer='false'" },
727         { 0x30, "sendreferer='true'" },
728         { 0x31, "size=" },
729         { 0x32, "src=" },
730         { 0x33, "ordered='false'" },
731         { 0x34, "ordered='true'" },
732         { 0x35, "tabindex=" },
733         { 0x36, "title=" },
734         { 0x37, "type=" },
735         { 0x38, "type='accept'" },
736         { 0x39, "type='delete'" },
737         { 0x3A, "type='help'" },
738         { 0x3B, "type='password'" },
739         { 0x3C, "type='onpick'" },
740         { 0x3D, "type='onenterbackward'" },
741         { 0x3E, "type='onenterforward'" },
742         { 0x3F, "type='ontimer'" },
743         /* 0x40 -- 0x44 GLOBAL */
744         { 0x45, "type='options'" },
745         { 0x46, "type='prev'" },
746         { 0x47, "type='reset'" },
747         { 0x48, "type='text'" },
748         { 0x49, "type='vnd.'" },
749         { 0x4A, "href=" },
750         { 0x4B, "href='http://'" },
751         { 0x4C, "href='https://'" },
752         { 0x4D, "value=" },
753         { 0x4E, "vspace=" },
754         { 0x4F, "width=" },
755         { 0x50, "xml:lang=" },
756         /* 0x51 */
757         { 0x52, "align=" },
758         { 0x53, "columns=" },
759         { 0x54, "class=" },
760         { 0x55, "id=" },
761         { 0x56, "forua='false'" },
762         { 0x57, "forua='true'" },
763         { 0x58, "src='http://'" },
764         { 0x59, "src='https://'" },
765         { 0x5A, "http-equiv=" },
766         { 0x5B, "http-equiv='Content-Type'" },
767         { 0x5C, "content='application/vnd.wap.wmlc;charset='" },
768         { 0x5D, "http-equiv='Expires'" },
769         { 0x5E, "accesskey=" },
770         { 0x5F, "enctype=" },
771         { 0x60, "enctype='application/x-www-form-urlencoded'" },
772         { 0x61, "enctype='multipart/form-data'" },
773
774         { 0x00, NULL }
775 };
776
777 /*****    Attribute Value tokens   *****/
778 /* Same as in WML 1.1 */
779
780 /***** Token code page aggregation *****/
781 static const value_valuestring wbxml_wmlc12_global[] = {
782         { 0, wbxml_wmlc10_global_cp0 }, /* Same as WML 1.0 */
783         { 0, NULL }
784 };
785
786 static const value_valuestring wbxml_wmlc12_tags[] = {
787         { 0, wbxml_wmlc12_tags_cp0 },
788         { 0, NULL }
789 };
790
791 static const value_valuestring wbxml_wmlc12_attrStart[] = {
792         { 0, wbxml_wmlc12_attrStart_cp0 },
793         { 0, NULL }
794 };
795
796 static const value_valuestring wbxml_wmlc12_attrValue[] = {
797         { 0, wbxml_wmlc11_attrValue_cp0 }, /* Same as WML 1.1 */
798         { 0, NULL }
799 };
800
801
802
803
804
805 /* WML 1.3
806  * 
807  * Wireless Markup Language
808  ***************************************/
809
810 /*****   Global extension tokens   *****/
811 /* Same as in WML 1.0 */
812
813 /*****         Tag tokens          *****/
814 /* Same as in WML 1.2 */
815
816 /*****    Attribute Start tokens   *****/
817 static const value_string wbxml_wmlc13_attrStart_cp0[] = {
818         /* 0x00 -- 0x04 GLOBAL */
819         { 0x05, "accept-charset=" },
820         { 0x06, "align='bottom'" },
821         { 0x07, "align='center'" },
822         { 0x08, "align='left'" },
823         { 0x09, "align='middle'" },
824         { 0x0A, "align='right'" },
825         { 0x0B, "align='top'" },
826         { 0x0C, "alt=" },
827         { 0x0D, "content=" },
828         /* 0x0E */
829         { 0x0F, "domain=" },
830         { 0x10, "emptyok='false'" },
831         { 0x11, "emptyok='true'" },
832         { 0x12, "format=" },
833         { 0x13, "height=" },
834         { 0x14, "hspace=" },
835         { 0x15, "ivalue=" },
836         { 0x16, "iname=" },
837         /* 0x17 */
838         { 0x18, "label=" },
839         { 0x19, "localsrc=" },
840         { 0x1A, "maxlength=" },
841         { 0x1B, "method='get'" },
842         { 0x1C, "method='post'" },
843         { 0x1D, "mode='nowrap'" },
844         { 0x1E, "mode='wrap'" },
845         { 0x1F, "multiple='false'" },
846         { 0x20, "multiple='true'" },
847         { 0x21, "name=" },
848         { 0x22, "newcontext='false'" },
849         { 0x23, "newcontext='true'" },
850         { 0x24, "onpick=" },
851         { 0x25, "onenterbackward=" },
852         { 0x26, "onenterforward=" },
853         { 0x27, "ontimer=" },
854         { 0x28, "optional='false'" },
855         { 0x29, "optional='true'" },
856         { 0x2A, "path=" },
857         /* 0x2B -- 0x2D */
858         { 0x2E, "scheme=" },
859         { 0x2F, "sendreferer='false'" },
860         { 0x30, "sendreferer='true'" },
861         { 0x31, "size=" },
862         { 0x32, "src=" },
863         { 0x33, "ordered='false'" },
864         { 0x34, "ordered='true'" },
865         { 0x35, "tabindex=" },
866         { 0x36, "title=" },
867         { 0x37, "type=" },
868         { 0x38, "type='accept'" },
869         { 0x39, "type='delete'" },
870         { 0x3A, "type='help'" },
871         { 0x3B, "type='password'" },
872         { 0x3C, "type='onpick'" },
873         { 0x3D, "type='onenterbackward'" },
874         { 0x3E, "type='onenterforward'" },
875         { 0x3F, "type='ontimer'" },
876         /* 0x40 -- 0x44 GLOBAL */
877         { 0x45, "type='options'" },
878         { 0x46, "type='prev'" },
879         { 0x47, "type='reset'" },
880         { 0x48, "type='text'" },
881         { 0x49, "type='vnd.'" },
882         { 0x4A, "href=" },
883         { 0x4B, "href='http://'" },
884         { 0x4C, "href='https://'" },
885         { 0x4D, "value=" },
886         { 0x4E, "vspace=" },
887         { 0x4F, "width=" },
888         { 0x50, "xml:lang=" },
889         /* 0x51 */
890         { 0x52, "align=" },
891         { 0x53, "columns=" },
892         { 0x54, "class=" },
893         { 0x55, "id=" },
894         { 0x56, "forua='false'" },
895         { 0x57, "forua='true'" },
896         { 0x58, "src='http://'" },
897         { 0x59, "src='https://'" },
898         { 0x5A, "http-equiv=" },
899         { 0x5B, "http-equiv='Content-Type'" },
900         { 0x5C, "content='application/vnd.wap.wmlc;charset='" },
901         { 0x5D, "http-equiv='Expires'" },
902         { 0x5E, "accesskey=" },
903         { 0x5F, "enctype=" },
904         { 0x60, "enctype='application/x-www-form-urlencoded'" },
905         { 0x61, "enctype='multipart/form-data'" },
906         { 0x62, "xml:space='preserve'" },
907         { 0x63, "xml:space='default'" },
908         { 0x64, "cache-control='no-cache'" },
909
910         { 0x00, NULL }
911 };
912
913 /*****    Attribute Value tokens   *****/
914 /* Same as in WML 1.1 */
915
916 /***** Token code page aggregation *****/
917 static const value_valuestring wbxml_wmlc13_global[] = {
918         { 0, wbxml_wmlc10_global_cp0 }, /* Same as WML 1.0 */
919         { 0, NULL }
920 };
921
922 static const value_valuestring wbxml_wmlc13_tags[] = {
923         { 0, wbxml_wmlc12_tags_cp0 },
924         { 0, NULL }
925 };
926
927 static const value_valuestring wbxml_wmlc13_attrStart[] = {
928         { 0, wbxml_wmlc13_attrStart_cp0 },
929         { 0, NULL }
930 };
931
932 static const value_valuestring wbxml_wmlc13_attrValue[] = {
933         { 0, wbxml_wmlc11_attrValue_cp0 }, /* Same as WML 1.1 */
934         { 0, NULL }
935 };
936
937
938
939
940
941 /* SI 1.0
942  * 
943  * Service Indication
944  ***************************************/
945
946 /*****   Global extension tokens   *****/
947
948 /*****         Tag tokens          *****/
949 static const value_string wbxml_sic10_tags_cp0[] = {
950         /* 0x00 -- 0x04 GLOBAL */
951         { 0x05, "si" },
952         { 0x06, "indication" },
953         { 0x07, "info" },
954         { 0x08, "item" },
955
956         { 0x00, NULL }
957 };
958
959 /*****    Attribute Start tokens   *****/
960 static const value_string wbxml_sic10_attrStart_cp0[] = {
961         /* 0x00 -- 0x04 GLOBAL */
962         { 0x05, "action='signal-none'" },
963         { 0x06, "action='signal-low'" },
964         { 0x07, "action='signal-medium'" },
965         { 0x08, "action='signal-high'" },
966         { 0x09, "action='delete'" },
967         { 0x0a, "created=" },
968         { 0x0b, "href=" },
969         { 0x0c, "href='http://'" },
970         { 0x0d, "href='http://www.'" },
971         { 0x0e, "href='https://'" },
972         { 0x0f, "href='https://www.'" },
973         { 0x10, "si-expires=" },
974         { 0x11, "si-id=" },
975         { 0x12, "class=" },
976
977         { 0x00, NULL }
978 };
979
980 /*****    Attribute Value tokens   *****/
981 static const value_string wbxml_sic10_attrValue_cp0[] = {
982         /* 0x80 -- 0x84 GLOBAL */
983         { 0x85, "'.com/'" },
984         { 0x86, "'.edu/'" },
985         { 0x87, "'.net/'" },
986         { 0x88, "'.org/'" },
987
988         { 0x00, NULL }
989 };
990
991 /***** Token code page aggregation *****/
992 static const value_valuestring wbxml_sic10_tags[] = {
993         { 0, wbxml_sic10_tags_cp0 },
994         { 0, NULL }
995 };
996
997 static const value_valuestring wbxml_sic10_attrStart[] = {
998         { 0, wbxml_sic10_attrStart_cp0 },
999         { 0, NULL }
1000 };
1001
1002 static const value_valuestring wbxml_sic10_attrValue[] = {
1003         { 0, wbxml_sic10_attrValue_cp0 },
1004         { 0, NULL }
1005 };
1006
1007
1008
1009
1010
1011 /* SL 1.0
1012  * 
1013  * Service Loading
1014  ***************************************/
1015
1016 /*****   Global extension tokens   *****/
1017
1018 /*****         Tag tokens          *****/
1019 static const value_string wbxml_slc10_tags_cp0[] = {
1020         /* 0x00 -- 0x04 GLOBAL */
1021         { 0x05, "sl" },
1022
1023         { 0x00, NULL }
1024 };
1025
1026 /*****    Attribute Start tokens   *****/
1027 static const value_string wbxml_slc10_attrStart_cp0[] = {
1028         /* 0x00 -- 0x04 GLOBAL */
1029         { 0x05, "action='execute-low'" },
1030         { 0x06, "action='execute-high'" },
1031         { 0x07, "action='cache'" },
1032         { 0x08, "href=" },
1033         { 0x09, "href='http://'" },
1034         { 0x0a, "href='http://www.'" },
1035         { 0x0b, "href='https://'" },
1036         { 0x0c, "href='https://www.'" },
1037
1038         { 0x00, NULL }
1039 };
1040
1041 /*****    Attribute Value tokens   *****/
1042 /* Same as in SI 1.0 */
1043
1044 /***** Token code page aggregation *****/
1045 static const value_valuestring wbxml_slc10_tags[] = {
1046         { 0, wbxml_slc10_tags_cp0 },
1047         { 0, NULL }
1048 };
1049
1050 static const value_valuestring wbxml_slc10_attrStart[] = {
1051         { 0, wbxml_slc10_attrStart_cp0 },
1052         { 0, NULL }
1053 };
1054
1055 static const value_valuestring wbxml_slc10_attrValue[] = {
1056         { 0, wbxml_sic10_attrValue_cp0 }, /* Same as SI 1.0 */
1057         { 0, NULL }
1058 };
1059
1060
1061
1062
1063
1064 /* CO 1.0
1065  * 
1066  * Cache Operation
1067  ***************************************/
1068
1069 /*****   Global extension tokens   *****/
1070
1071 /*****         Tag tokens          *****/
1072 static const value_string wbxml_coc10_tags_cp0[] = {
1073         /* 0x00 -- 0x04 GLOBAL */
1074         { 0x05, "co" },
1075         { 0x06, "invalidate-object" },
1076         { 0x07, "invalidate-service" },
1077
1078         { 0x00, NULL }
1079 };
1080
1081 /*****    Attribute Start tokens   *****/
1082 static const value_string wbxml_coc10_attrStart_cp0[] = {
1083         /* 0x00 -- 0x04 GLOBAL */
1084         { 0x05, "uri=" },
1085         { 0x06, "uri='http://'" },
1086         { 0x07, "uri='http://www.'" },
1087         { 0x08, "uri='https://'" },
1088         { 0x09, "uri='https://www.'" },
1089
1090         { 0x00, NULL }
1091 };
1092
1093 /*****    Attribute Value tokens   *****/
1094 /* Same as in SI 1.0 */
1095
1096 /***** Token code page aggregation *****/
1097 static const value_valuestring wbxml_coc10_tags[] = {
1098         { 0, wbxml_coc10_tags_cp0 },
1099         { 0, NULL }
1100 };
1101
1102 static const value_valuestring wbxml_coc10_attrStart[] = {
1103         { 0, wbxml_coc10_attrStart_cp0 },
1104         { 0, NULL }
1105 };
1106
1107 static const value_valuestring wbxml_coc10_attrValue[] = {
1108         { 0, wbxml_sic10_attrValue_cp0 }, /* Same as SI 1.0 */
1109         { 0, NULL }
1110 };
1111
1112
1113
1114
1115
1116 /* PROV 1.0
1117  *
1118  * Client Provisioning
1119  ***************************************/
1120
1121 /*****   Global extension tokens   *****/
1122
1123 /*****         Tag tokens          *****/
1124 static const value_string wbxml_provc10_tags_cp0[] = {
1125         /* 0x00 -- 0x04 GLOBAL */
1126         { 0x05, "wap-provisioningdoc" },
1127         { 0x06, "characteristic" },
1128         { 0x07, "parm" },
1129
1130         { 0x00, NULL }
1131 };
1132
1133 /*****    Attribute Start tokens   *****/
1134 static const value_string wbxml_provc10_attrStart_cp0[] = {
1135         /* 0x00 -- 0x04 GLOBAL */
1136         { 0x05, "name=" },
1137         { 0x06, "value=" },
1138         { 0x07, "name='NAME'" },
1139         { 0x08, "name='NAP-ADDRESS'" },
1140         { 0x09, "name='NAP-ADDRTYPE'" },
1141         { 0x0A, "name='CALLTYPE'" },
1142         { 0x0B, "name='VALIDUNTIL'" },
1143         { 0x0C, "name='AUTHTYPE'" },
1144         { 0x0D, "name='AUTHNAME'" },
1145         { 0x0E, "name='AUTHSECRET'" },
1146         { 0x0F, "name='LINGER'" },
1147         { 0x10, "name='BEARER'" },
1148         { 0x11, "name='NAPID'" },
1149         { 0x12, "name='COUNTRY'" },
1150         { 0x13, "name='NETWORK'" },
1151         { 0x14, "name='INTERNET'" },
1152         { 0x15, "name='PROXY-ID'" },
1153         { 0x16, "name='PROXY-PROVIDER-ID'" },
1154         { 0x17, "name='DOMAIN'" },
1155         { 0x18, "name='PROVURL'" },
1156         { 0x19, "name='PXAUTH-TYPE'" },
1157         { 0x1A, "name='PXAUTH-ID'" },
1158         { 0x1B, "name='PXAUTH-PW'" },
1159         { 0x1C, "name='STARTPAGE'" },
1160         { 0x1D, "name='BASAUTH-ID'" },
1161         { 0x1E, "name='BASAUTH-PW'" },
1162         { 0x1F, "name='PUSHENABLED'" },
1163         { 0x20, "name='PXADDR'" },
1164         { 0x21, "name='PXADDRTYPE'" },
1165         { 0x22, "name='TO-NAPID'" },
1166         { 0x23, "name='PORTNBR'" },
1167         { 0x24, "name='SERVICE'" },
1168         { 0x25, "name='LINKSPEED'" },
1169         { 0x26, "name='DNLINKSPEED'" },
1170         { 0x27, "name='LOCAL-ADDR'" },
1171         { 0x28, "name='LOCAL-ADDRTYPE'" },
1172         { 0x29, "name='CONTEXT-ALLOW'" },
1173         { 0x2A, "name='TRUST'" },
1174         { 0x2B, "name='MASTER'" },
1175         { 0x2C, "name='SID'" },
1176         { 0x2D, "name='SOC'" },
1177         { 0x2E, "name='WSP-VERSION'" },
1178         { 0x2F, "name='PHYSICAL-PROXY-ID'" },
1179         { 0x30, "name='CLIENT-ID'" },
1180         { 0x31, "name='DELIVERY-ERR-SDU'" },
1181         { 0x32, "name='DELIVERY-ORDER'" },
1182         { 0x33, "name='TRAFFIC-CLASS'" },
1183         { 0x34, "name='MAX-SDU-SIZE'" },
1184         { 0x35, "name='MAX-BITRATE-UPLINK'" },
1185         { 0x36, "name='MAX-BITRATE-DNLINK'" },
1186         { 0x37, "name='RESIDUAL-BER'" },
1187         { 0x38, "name='SDU-ERROR-RATIO'" },
1188         { 0x39, "name='TRAFFIC-HANDL-PRIO'" },
1189         { 0x3A, "name='TRANSFER-DELAY'" },
1190         { 0x3B, "name='GUARANTEED-BITRATE-UPLINK'" },
1191         { 0x3C, "name='GUARANTEED-BITRATE-DNLINK'" },
1192         /* 0x3D -- 0x3F */
1193         /* 0x40 -- 0x44 GLOBAL */
1194         { 0x45, "version=" },
1195         { 0x46, "version='1.0'" },
1196         /* 0x47 -- 0x4F */
1197         { 0x50, "type=" },
1198         { 0x51, "type='PXLOGICAL'" },
1199         { 0x52, "type='PXPHYSICAL'" },
1200         { 0x53, "type='PORT'" },
1201         { 0x54, "type='VALIDITY'" },
1202         { 0x55, "type='NAPDEF'" },
1203         { 0x56, "type='BOOTSTRAP'" },
1204         { 0x57, "type='VENDORCONFIG'" },
1205         { 0x58, "type='CLIENTIDENTITY'" },
1206         { 0x59, "type='PXAUTHINFO'" },
1207         { 0x5A, "type='NAPAUTHINFO'" },
1208
1209         { 0x00, NULL }
1210 };
1211
1212 /*****    Attribute Start tokens   *****/
1213 static const value_string wbxml_provc10_attrValue_cp0[] = {
1214         /* 0x80 -- 0x84 GLOBAL */
1215         { 0x85, "'IPV4'" },
1216         { 0x86, "'IPV6'" },
1217         { 0x87, "'E164'" },
1218         { 0x88, "'ALPHA'" },
1219         { 0x89, "'APN'" },
1220         { 0x8A, "'SCODE'" },
1221         { 0x8B, "'TETRA-ITSI'" },
1222         { 0x8C, "'MAN'" },
1223         /* 0x8D -- 0x8F */
1224         { 0x90, "'ANALOG-MODEM'" },
1225         { 0x91, "'V.120'" },
1226         { 0x92, "'V.110'" },
1227         { 0x93, "'X.31'" },
1228         { 0x94, "'BIT-TRANSPARENT'" },
1229         { 0x95, "'DIRECT-ASYNCHRONOUS-DATA-SERVICE'" },
1230         /* 0x96 -- 0x99 */
1231         { 0x9A, "'PAP'" },
1232         { 0x9B, "'CHAP'" },
1233         { 0x9C, "'HTTP-BASIC'" },
1234         { 0x9D, "'HTTP-DIGEST'" },
1235         { 0x9E, "'WTLS-SS'" },
1236         /* 0x9F -- 0xA1 */
1237         { 0xA2, "'GSM-USSD'" },
1238         { 0xA3, "'GSM-SMS'" },
1239         { 0xA4, "'ANSI-136-GUTS'" },
1240         { 0xA5, "'IS-95-CDMA-SMS'" },
1241         { 0xA6, "'IS-95-CDMA-CSD'" },
1242         { 0xA7, "'IS-95-CDMA-PACKET'" },
1243         { 0xA8, "'ANSI-136-CSD'" },
1244         { 0xA9, "'ANSI-136-GPRS'" },
1245         { 0xAA, "'GSM-CSD'" },
1246         { 0xAB, "'GSM-GPRS'" },
1247         { 0xAC, "'AMPS-CDPD'" },
1248         { 0xAD, "'PDC-CSD'" },
1249         { 0xAE, "'PDC-PACKET'" },
1250         { 0xAF, "'IDEN-SMS'" },
1251         { 0xB0, "'IDEN-CSD'" },
1252         { 0xB1, "'IDEN-PACKET'" },
1253         { 0xB2, "'FLEX/REFLEX'" },
1254         { 0xB3, "'PHS-SMS'" },
1255         { 0xB4, "'PHS-CSD'" },
1256         { 0xB5, "'TETRA-SDS'" },
1257         { 0xB6, "'TETRA-PACKET'" },
1258         { 0xB7, "'ANSI-136-GHOST'" },
1259         { 0xB8, "'MOBITEX-MPAK'" },
1260         /* 0xB9 -- 0xBF */
1261         /* 0xC0 -- 0xC4 GLOBAL */
1262         { 0xC5, "'AUTOBAUDING'" },
1263         /* 0xC6 -- 0xC9 */
1264         { 0xCA, "'CL-WSP'" },
1265         { 0xCB, "'CO-WSP'" },
1266         { 0xCC, "'CL-SEC-WSP'" },
1267         { 0xCD, "'CO-SEC-WSP'" },
1268         { 0xCE, "'CL-SEC-WTA'" },
1269         { 0xCF, "'CO-SEC-WTA'" },
1270
1271         { 0x00, NULL }
1272 };
1273
1274 /***** Token code page aggregation *****/
1275 static const value_valuestring wbxml_provc10_tags[] = {
1276         { 0, wbxml_provc10_tags_cp0 },
1277         { 0, NULL }
1278 };
1279
1280 static const value_valuestring wbxml_provc10_attrStart[] = {
1281         { 0, wbxml_provc10_attrStart_cp0 },
1282         { 0, NULL }
1283 };
1284
1285 static const value_valuestring wbxml_provc10_attrValue[] = {
1286         { 0, wbxml_provc10_attrValue_cp0 },
1287         { 0, NULL }
1288 };
1289
1290
1291
1292
1293
1294 /* EMN 1.0
1295  * 
1296  * Email Notification
1297  ***************************************/
1298
1299 /*****   Global extension tokens   *****/
1300
1301 /*****         Tag tokens          *****/
1302 static const value_string wbxml_emnc10_tags_cp0[] = {
1303         /* 0x00 -- 0x04 GLOBAL */
1304         { 0x05, "emn" },
1305
1306         { 0x00, NULL }
1307 };
1308
1309 /*****    Attribute Start tokens   *****/
1310 static const value_string wbxml_emnc10_attrStart_cp0[] = {
1311         /* 0x00 -- 0x04 GLOBAL */
1312         { 0x05, "timestamp=" },
1313         { 0x06, "mailbox=" },
1314         { 0x07, "mailbox='mailat:'" },
1315         { 0x08, "mailbox='pop://'" },
1316         { 0x09, "mailbox='imap://'" },
1317         { 0x0a, "mailbox='http://'" },
1318         { 0x0b, "mailbox='http://www.'" },
1319         { 0x0c, "mailbox='https://'" },
1320         { 0x0D, "mailbox='https://www.'" },
1321
1322         { 0x00, NULL }
1323 };
1324
1325 /*****    Attribute Value tokens   *****/
1326 /* Same as in SI 1.0 */
1327
1328 /***** Token code page aggregation *****/
1329 static const value_valuestring wbxml_emnc10_tags[] = {
1330         { 0, wbxml_emnc10_tags_cp0 },
1331         { 0, NULL }
1332 };
1333
1334 static const value_valuestring wbxml_emnc10_attrStart[] = {
1335         { 0, wbxml_emnc10_attrStart_cp0 },
1336         { 0, NULL }
1337 };
1338
1339 static const value_valuestring wbxml_emnc10_attrValue[] = {
1340         { 0, wbxml_sic10_attrValue_cp0 }, /* Same as SI 1.0 */
1341         { 0, NULL }
1342 };
1343
1344
1345
1346
1347
1348 /* SyncML 1.0
1349  * 
1350  * SyncML Representation Protocol
1351  ***************************************/
1352
1353 /*****   Global extension tokens   *****/
1354
1355 /*****         Tag tokens          *****/
1356 static const value_string wbxml_syncmlc10_tags_cp0[] = { /* SyncML 1.0 */
1357         /* 0x00 -- 0x04 GLOBAL */
1358         { 0x05, "Add" },
1359         { 0x06, "Alert" },
1360         { 0x07, "Archive" },
1361         { 0x08, "Atomic" },
1362         { 0x09, "Chal" },
1363         { 0x0A, "Cmd" },
1364         { 0x0B, "CmdID" },
1365         { 0x0C, "CmdRef" },
1366         { 0x0D, "Copy" },
1367         { 0x0E, "Cred" },
1368         { 0x0F, "Data" },
1369         { 0x10, "Delete" },
1370         { 0x11, "Exec" },
1371         { 0x12, "Final" },
1372         { 0x13, "Get" },
1373         { 0x14, "Item" },
1374         { 0x15, "Lang" },
1375         { 0x16, "LocName" },
1376         { 0x17, "LocURI" },
1377         { 0x18, "Map" },
1378         { 0x19, "MapItem" },
1379         { 0x1A, "Meta" },
1380         { 0x1B, "MsgID" },
1381         { 0x1C, "MsgRef" },
1382         { 0x1D, "NoResp" },
1383         { 0x1E, "NoResults" },
1384         { 0x1F, "Put" },
1385         { 0x20, "Replace" },
1386         { 0x21, "RespURI" },
1387         { 0x22, "Results" },
1388         { 0x23, "Search" },
1389         { 0x24, "Sequence" },
1390         { 0x25, "SessionID" },
1391         { 0x26, "SftDel" },
1392         { 0x27, "Source" },
1393         { 0x28, "SourceRef" },
1394         { 0x29, "Status" },
1395         { 0x2A, "Sync" },
1396         { 0x2B, "SyncBody" },
1397         { 0x2C, "SyncHdr" },
1398         { 0x2D, "SyncML" },
1399         { 0x2E, "Target" },
1400         { 0x2F, "TargetRef" },
1401         /* 0x30 - Reserved */
1402         { 0x31, "VerDTD" },
1403         { 0x32, "VerProto" },
1404
1405         { 0x00, NULL }
1406 };
1407
1408 static const value_string wbxml_syncmlc10_tags_cp1[] = { /* MetInf 1.0 */
1409         /* 0x00 -- 0x04 GLOBAL */
1410         { 0x05, "Anchor" },
1411         { 0x06, "EMI" },
1412         { 0x07, "Format" },
1413         { 0x08, "FreeID" },
1414         { 0x09, "FreeMem" },
1415         { 0x0A, "Last" },
1416         { 0x0B, "Mark" },
1417         { 0x0C, "MaxMsgSize" },
1418         { 0x0D, "Mem" },
1419         { 0x0E, "MetInf" },
1420         { 0x0F, "Next" },
1421         { 0x10, "NextNonce" },
1422         { 0x11, "SharedMem" },
1423         { 0x12, "Size" },
1424         { 0x13, "Type" },
1425         { 0x14, "Version" },
1426
1427         { 0x00, NULL }
1428 };
1429
1430 /*****    Attribute Start tokens   *****/
1431
1432 /*****    Attribute Value tokens   *****/
1433
1434 /***** Token code page aggregation *****/
1435 static const value_valuestring wbxml_syncmlc10_tags[] = {
1436         { 0, wbxml_syncmlc10_tags_cp0 }, /* -//SYNCML//DTD SyncML 1.0//EN */
1437         { 0, wbxml_syncmlc10_tags_cp1 }, /* -//SYNCML//DTD MetInf 1.0//EN */
1438         { 0, NULL }
1439 };
1440
1441
1442
1443
1444
1445 /* SyncML 1.1
1446  * 
1447  * SyncML Representation Protocol
1448  ***************************************/
1449
1450 /*****   Global extension tokens   *****/
1451
1452 /*****         Tag tokens          *****/
1453 static const value_string wbxml_syncmlc11_tags_cp0[] = { /* SyncML 1.1 */
1454         /* 0x00 -- 0x04 GLOBAL */
1455         { 0x05, "Add" },
1456         { 0x06, "Alert" },
1457         { 0x07, "Archive" },
1458         { 0x08, "Atomic" },
1459         { 0x09, "Chal" },
1460         { 0x0a, "Cmd" },
1461         { 0x0b, "CmdID" },
1462         { 0x0c, "CmdRef" },
1463         { 0x0d, "Copy" },
1464         { 0x0e, "Cred" },
1465         { 0x0f, "Data" },
1466         { 0x10, "Delete" },
1467         { 0x11, "Exec" },
1468         { 0x12, "Final" },
1469         { 0x13, "Get" },
1470         { 0x14, "Item" },
1471         { 0x15, "Lang" },
1472         { 0x16, "LocName" },
1473         { 0x17, "LocURI" },
1474         { 0x18, "Map" },
1475         { 0x19, "MapItem" },
1476         { 0x1a, "Meta" },
1477         { 0x1b, "MsgID" },
1478         { 0x1c, "MsgRef" },
1479         { 0x1d, "NoResp" },
1480         { 0x1e, "NoResults" },
1481         { 0x1f, "Put" },
1482         { 0x20, "Replace" },
1483         { 0x21, "RespURI" },
1484         { 0x22, "Results" },
1485         { 0x23, "Search" },
1486         { 0x24, "Sequence" },
1487         { 0x25, "SessionID" },
1488         { 0x26, "SftDel" },
1489         { 0x27, "Source" },
1490         { 0x28, "SourceRef" },
1491         { 0x29, "Status" },
1492         { 0x2a, "Sync" },
1493         { 0x2b, "SyncBody" },
1494         { 0x2c, "SyncHdr" },
1495         { 0x2d, "SyncML" },
1496         { 0x2e, "Target" },
1497         { 0x2f, "TargetRef" },
1498         /* 0x30 - Reserved */
1499         { 0x31, "VerDTD" },
1500         { 0x32, "VerProto" },
1501         { 0x33, "NumberOfChanges" },
1502         { 0x34, "MoreData" },
1503
1504         { 0x00, NULL }
1505 };
1506
1507 static const value_string wbxml_syncmlc11_tags_cp1[] = { /* MetInf 1.1 */
1508         /* 0x00 -- 0x04 GLOBAL */
1509         { 0x05, "Anchor" },
1510         { 0x06, "EMI" },
1511         { 0x07, "Format" },
1512         { 0x08, "FreeID" },
1513         { 0x09, "FreeMem" },
1514         { 0x0A, "Last" },
1515         { 0x0B, "Mark" },
1516         { 0x0C, "MaxMsgSize" },
1517         { 0x0D, "Mem" },
1518         { 0x0E, "MetInf" },
1519         { 0x0F, "Next" },
1520         { 0x10, "NextNonce" },
1521         { 0x11, "SharedMem" },
1522         { 0x12, "Size" },
1523         { 0x13, "Type" },
1524         { 0x14, "Version" },
1525         { 0x15, "MaxObjSize" },
1526
1527         { 0x00, NULL }
1528 };
1529
1530 /*****    Attribute Start tokens   *****/
1531
1532 /*****    Attribute Value tokens   *****/
1533
1534 /***** Token code page aggregation *****/
1535 static const value_valuestring wbxml_syncmlc11_tags[] = {
1536         { 0, wbxml_syncmlc11_tags_cp0 }, /* -//SYNCML//DTD SyncML 1.1//EN */
1537         { 0, wbxml_syncmlc11_tags_cp1 }, /* -//SYNCML//DTD MetInf 1.1//EN */
1538         { 0, NULL }
1539 };
1540
1541
1542
1543
1544
1545 /* CHANNEL 1.0
1546  * 
1547  * WTA Channel
1548  ***************************************/
1549
1550 /*****   Global extension tokens   *****/
1551
1552 /*****         Tag tokens          *****/
1553 static const value_string wbxml_channelc10_tags_cp0[] = {
1554         /* 0x00 -- 0x04 GLOBAL */
1555         { 0x05, "channel" },
1556         { 0x06, "title" },
1557         { 0x07, "abstract" },
1558         { 0x08, "resource" },
1559
1560         { 0x00, NULL }
1561 };
1562
1563 /*****    Attribute Start tokens   *****/
1564 static const value_string wbxml_channelc10_attrStart_cp0[] = {
1565         /* 0x00 -- 0x04 GLOBAL */
1566         { 0x05, "maxspace" },
1567         { 0x06, "base" },
1568         { 0x07, "href" },
1569         { 0x08, "href='http://'" },
1570         { 0x09, "href='https://'" },
1571         { 0x0A, "lastmod" },
1572         { 0x0B, "etag" },
1573         { 0x0C, "md5" },
1574         { 0x0D, "success" },
1575         { 0x0E, "success='http://'" },
1576         { 0x0F, "success='https://'" },
1577         { 0x10, "failure" },
1578         { 0x11, "failure='http://'" },
1579         { 0x12, "failure='https://'" },
1580         { 0x13, "EventId" },
1581
1582         { 0x00, NULL }
1583 };
1584
1585 /*****    Attribute Value tokens   *****/
1586
1587 /***** Token code page aggregation *****/
1588 static const value_valuestring wbxml_channelc10_tags[] = {
1589         { 0, wbxml_channelc10_tags_cp0 },
1590         { 0, NULL }
1591 };
1592
1593 static const value_valuestring wbxml_channelc10_attrStart[] = {
1594         { 0, wbxml_channelc10_attrStart_cp0 },
1595         { 0, NULL }
1596 };
1597
1598
1599
1600
1601
1602 /********************** WBXML token mapping aggregation **********************/
1603
1604
1605 /* The following structure links content types to their token mapping and
1606  * contains arrays of pointers to value_string arrays (one per code page).
1607  */
1608 typedef struct _wbxml_token_map {
1609         const guint32 publicid;  /* WBXML DTD number - see WINA */
1610         const guint8 defined;    /* Are there mapping tables defined */
1611         const value_valuestring *global;     /* Global token map */
1612         const value_valuestring *tags;       /* Tag token map */
1613         const value_valuestring *attrStart;  /* Attribute Start token map */
1614         const value_valuestring *attrValue;  /* Attribute Value token map */
1615 } wbxml_token_map;
1616
1617 static const wbxml_token_map *wbxml_content_map (guint32 publicid);
1618
1619 /**
1620  ** Aggregation of content type and aggregated code pages
1621  ** Content type map lookup will stop at the 1st entry with 2nd member = FALSE
1622  **/
1623 static const wbxml_token_map map[] = {
1624 #ifdef Test_the_WBXML_parser_without_token_mappings
1625         { 0, FALSE, NULL, NULL, NULL, NULL },
1626 #endif
1627         { 0x02, TRUE, /* WML 1.0 */
1628                 wbxml_wmlc10_global,
1629                 wbxml_wmlc10_tags,
1630                 wbxml_wmlc10_attrStart,
1631                 wbxml_wmlc10_attrValue
1632         },
1633 #ifdef remove_directive_and_set_TRUE_if_mapping_available
1634         { 0x03, FALSE, /* WTA 1.0 (deprecated) */
1635                 NULL, NULL, NULL, NULL
1636         },
1637 #endif
1638         { 0x04, TRUE, /* WML 1.1 */
1639                 wbxml_wmlc11_global,
1640                 wbxml_wmlc11_tags,
1641                 wbxml_wmlc11_attrStart,
1642                 wbxml_wmlc11_attrValue
1643         },
1644         { 0x05, TRUE, /* SI 1.0 */
1645                 NULL, /* wbxml_sic10_global - does not exist */
1646                 wbxml_sic10_tags,
1647                 wbxml_sic10_attrStart,
1648                 wbxml_sic10_attrValue
1649         },
1650         { 0x06, TRUE, /* SL 1.0 */
1651                 NULL, /* wbxml_slc10_global - does not exist */
1652                 wbxml_slc10_tags,
1653                 wbxml_slc10_attrStart,
1654                 wbxml_slc10_attrValue
1655         },
1656         { 0x07, TRUE, /* CO 1.0 */
1657                 NULL, /* wbxml_coc10_global - does not exist */
1658                 wbxml_coc10_tags,
1659                 wbxml_coc10_attrStart,
1660                 wbxml_coc10_attrValue
1661         },
1662         { 0x08, TRUE, /* CHANNEL 1.0 (deprecated) */
1663                 NULL, /* wbxml_channelc10_global - does not exist */
1664                 wbxml_channelc10_tags,
1665                 wbxml_channelc10_attrStart,
1666                 NULL, /* wbxml_channelc10_attrValue - does not exist */
1667         },
1668         { 0x09, TRUE, /* WML 1.2 */
1669                 wbxml_wmlc12_global,
1670                 wbxml_wmlc12_tags,
1671                 wbxml_wmlc12_attrStart,
1672                 wbxml_wmlc12_attrValue
1673         },
1674         { 0x0A, TRUE, /* WML 1.3 */
1675                 wbxml_wmlc13_global,
1676                 wbxml_wmlc13_tags,
1677                 wbxml_wmlc13_attrStart,
1678                 wbxml_wmlc13_attrValue
1679         },
1680         { 0x0B, TRUE, /* PROV 1.0 */
1681                 NULL, /* wbxml_provc10_global - does not exist */
1682                 wbxml_provc10_tags,
1683                 wbxml_provc10_attrStart,
1684                 wbxml_provc10_attrValue
1685         },
1686 #ifdef remove_directive_and_set_TRUE_if_mapping_available
1687         { 0x0C, FALSE, /* WTA-WML 1.2 */
1688                 NULL, NULL, NULL, NULL
1689         },
1690 #endif
1691         { 0x0D, TRUE, /* EMN 1.0 */
1692                 NULL, /* wbxml_emnc10_global - does not exist */
1693                 wbxml_emnc10_tags,
1694                 wbxml_emnc10_attrStart,
1695                 wbxml_emnc10_attrValue
1696         },
1697 #ifdef remove_directive_and_set_TRUE_if_mapping_available
1698         { 0x0E, FALSE, /* DRMREL 1.0 */
1699                 NULL, NULL, NULL, NULL
1700         },
1701 #endif
1702         { 0x0FD1, TRUE, /* SyncML 1.0 */
1703                 NULL, /* wbxml_syncmlc10_global - does not exist */
1704                 wbxml_syncmlc10_tags,
1705                 NULL, /* wbxml_syncmlc10_attrStart - does not exist */
1706                 NULL, /* wbxml_syncmlc10_attrValue - does not exist */
1707         },
1708         { 0x0FD3, TRUE, /* SyncML 1.1 */
1709                 NULL, /* wbxml_syncmlc11_global - does not exist */
1710                 wbxml_syncmlc11_tags,
1711                 NULL, /* wbxml_syncmlc11_attrStart - does not exist */
1712                 NULL, /* wbxml_syncmlc11_attrValue - does not exist */
1713         },
1714         { 0x1108, TRUE, /* Phone.com - WML+ 1.1 */
1715                 /* Note: I assumed WML+ 1.1 would be not that different from WML 1.1,
1716                  *       the real mapping should come from Phone.com (OpenWave)! */
1717                 wbxml_wmlc11_global, /* Not 100% true */
1718                 wbxml_wmlc11_tags, /* Not 100% true */
1719                 wbxml_wmlc11_attrStart, /* Not 100% true */
1720                 wbxml_wmlc11_attrValue /* Not 100% true */
1721         },
1722         { 0x110D, TRUE, /* Phone.com - WML+ 1.3 */
1723                 /* Note: I assumed WML+ 1.3 would be not that different from WML 1.3,
1724                  *       the real mapping should come from Phone.com (OpenWave)! */
1725                 wbxml_wmlc13_global, /* Not 100% true */
1726                 wbxml_wmlc13_tags, /* Not 100% true */
1727                 wbxml_wmlc13_attrStart, /* Not 100% true */
1728                 wbxml_wmlc13_attrValue /* Not 100% true */
1729         },
1730         
1731         { 0, FALSE, NULL, NULL, NULL, NULL }
1732 };
1733
1734
1735 /* WBXML content token mapping depends on the following parameters:
1736  *   - Content type (guint32)
1737  *   - Token type (global, tags, attrStart, attrValue)
1738  *   - Code page for tag and attribute
1739  *
1740  * This results in the following steps:
1741  *   1. Retrieve content type mapping
1742  *   2. If exists, retrieve token type mapping
1743  *   3. If exists, retrieve required code page
1744  *   4. If exists, retrieve token mapping
1745  */
1746
1747 /* Return token mapping for a given content mapping entry. */
1748 static const char *
1749 map_token (const value_valuestring *token_map, guint8 codepage, guint8 token) {
1750         const value_string *vs;
1751         const char *s;
1752
1753         if (token_map) { /* Found map */
1754                 if ((vs = val_to_valstr (codepage, token_map))) {
1755                         /* Found codepage map */
1756                         s = match_strval (token, vs);
1757                         if (s) /* Found valid token */
1758                                         return s;
1759                         /* No valid token mapping in specified code page of token map */
1760                         return "(Requested token not defined for this content type)";
1761                 }
1762                 /* There is no token map entry for the requested code page */
1763                 return "(Requested token code page not defined for this content type)";
1764         }
1765         /* The token map does not exist */
1766         return "(Requested token map not defined for this content type)";
1767 }
1768
1769
1770 /* Returns a pointer to the WBXML token map for the given WBXML public
1771  * identifier value (see WINA for a table with defined identifiers). */
1772 static const wbxml_token_map *wbxml_content_map (guint32 publicid) {
1773         gint i = 0;
1774
1775         while (map[i].defined) {
1776                 if (map[i].publicid == publicid)
1777                         return &(map[i]);
1778                 i++;
1779         }
1780         return NULL;
1781 }
1782
1783
1784 /************************** Function prototypes **************************/
1785
1786
1787 static void
1788 dissect_wbxml(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
1789
1790 void
1791 proto_register_wbxml(void);
1792
1793 /* Parse and display the WBXML string table */
1794 static void
1795 show_wbxml_string_table (proto_tree *tree, tvbuff_t *tvb, guint32 str_tbl,
1796                 guint32 str_tbl_len);
1797
1798 /* Parse data while in STAG state */
1799 static void
1800 parse_wbxml_tag (proto_tree *tree, tvbuff_t *tvb, guint32 offset,
1801                 guint32 str_tbl, guint8 *level,
1802                 guint32 *parsed_length);
1803
1804 /* Parse data while in STAG state;
1805  * interpret tokens as defined by content type */
1806 static void
1807 parse_wbxml_tag_defined (proto_tree *tree, tvbuff_t *tvb, guint32 offset,
1808                 guint32 str_tbl, guint8 *level,
1809                 guint32 *parsed_length,
1810                 const wbxml_token_map *map);
1811
1812 /* Parse data while in ATTR state */
1813 static void
1814 parse_wbxml_attribute_list (proto_tree *tree, tvbuff_t *tvb,
1815                 guint32 offset, guint32 str_tbl, guint8 level,
1816                 guint32 *parsed_length);
1817
1818 /* Parse data while in ATTR state;
1819  * interpret tokens as defined by content type */
1820 static void
1821 parse_wbxml_attribute_list_defined (proto_tree *tree, tvbuff_t *tvb,
1822                 guint32 offset, guint32 str_tbl, guint8 level,
1823                 guint32 *parsed_length,
1824                 const wbxml_token_map *map);
1825
1826
1827 /****************** WBXML protocol dissection functions ******************/
1828
1829
1830 /* Code to actually dissect the packets */
1831 static void
1832 dissect_wbxml(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1833 {
1834         /* Set up structures needed to add the protocol subtree and manage it */
1835         proto_item *ti;
1836         proto_tree *wbxml_tree; /* Main WBXML tree */
1837         proto_tree *wbxml_str_tbl_tree; /* String table subtree */
1838         proto_tree *wbxml_content_tree; /* Content subtree */
1839         guint8 version;
1840         guint offset = 0;
1841         guint32 len;
1842         guint32 charset=0;
1843         guint32 charset_len;
1844         guint32 publicid;
1845         guint32 publicid_index = 0;
1846         guint32 publicid_len;
1847         guint32 str_tbl;
1848         guint32 str_tbl_len;
1849         guint8 level = 0; /* WBXML recursion level */
1850         const wbxml_token_map *content_map = NULL;
1851
1852         /* WBXML format
1853          * 
1854          * Version 1.0: version publicid         strtbl BODY
1855          * Version 1.x: version publicid charset strtbl BODY
1856          *
1857          * Last valid format: WBXML 1.3
1858          */
1859         switch ( version = tvb_get_guint8 (tvb, 0) ) {
1860                 case 0x00: /* WBXML/1.0 */
1861                         break;
1862
1863                 case 0x01: /* WBXML/1.1 */
1864                 case 0x02: /* WBXML/1.2 */
1865                 case 0x03: /* WBXML/1.3 */
1866                         break;
1867
1868                 default:
1869                         return;
1870         }
1871
1872         if (check_col(pinfo->cinfo, COL_INFO))
1873                 col_append_fstr(pinfo->cinfo, COL_INFO, " (WBXML %s:",
1874                                 match_strval (version, vals_wbxml_versions));
1875
1876         /* In the interest of speed, if "tree" is NULL, don't do any work not
1877            necessary to generate protocol tree items. */
1878         if ( tree ) {
1879                 /* create display subtree for the protocol */
1880                 ti = proto_tree_add_item (tree, proto_wbxml, tvb, 0, -1, FALSE);
1881                 wbxml_tree = proto_item_add_subtree(ti, ett_wbxml);
1882
1883                 /* WBXML Version */
1884                 proto_tree_add_uint (wbxml_tree, hf_wbxml_version,
1885                                 tvb, 0, 1, version);
1886
1887                 /* Public ID */
1888                 publicid = tvb_get_guintvar(tvb, 1, &publicid_len);
1889                 if (publicid) { /* Known Public ID */
1890                         if (check_col(pinfo->cinfo, COL_INFO))
1891                                 col_append_fstr(pinfo->cinfo, COL_INFO, " Public ID \"%s\")",
1892                                                 match_strval (publicid, vals_wbxml_public_ids));
1893                         proto_tree_add_uint(wbxml_tree, hf_wbxml_public_id_known,
1894                                         tvb, 1, publicid_len, publicid);
1895                 } else { /* Public identifier in string table */
1896                         publicid_index = tvb_get_guintvar (tvb, 1+publicid_len, &len);
1897                         publicid_len += len;
1898                 }
1899                 offset = 1 + publicid_len;
1900
1901                 /* Version-specific handling of Charset */
1902                 switch ( version ) {
1903                         case 0x00: /* WBXML/1.0 */
1904                                 /* No charset */
1905                                 break;
1906
1907                         case 0x01: /* WBXML/1.1 */
1908                         case 0x02: /* WBXML/1.2 */
1909                         case 0x03: /* WBXML/1.3 */
1910                                 /* Get charset */
1911                                 charset = tvb_get_guintvar (tvb, offset, &charset_len);
1912                                 offset += charset_len;
1913                                 break;
1914
1915                         default: /* Impossible since return already earlier */
1916                                 break;
1917                 }
1918
1919                 /* String table: read string table length in bytes */
1920                 str_tbl_len = tvb_get_guintvar (tvb, offset, &len);
1921                 str_tbl = offset + len; /* Start of 1st string in string table */
1922
1923                 /* Now we can add public ID, charset (if available),
1924                  * and string table */
1925                 if ( ! publicid ) { /* Read Public ID from string table */
1926                         len = tvb_strsize (tvb, str_tbl+publicid_index);
1927                         if (check_col(pinfo->cinfo, COL_INFO))
1928                                 col_append_fstr(pinfo->cinfo, COL_INFO, " Public ID \"%s\")",
1929                                                 tvb_format_text (tvb,
1930                                                     str_tbl+publicid_index,
1931                                                     len-1));
1932                         proto_tree_add_item (wbxml_tree, hf_wbxml_public_id_literal,
1933                                         tvb, 1, publicid_len, FALSE);
1934                 }
1935                 if ( version ) { /* Charset */
1936                         proto_tree_add_uint (wbxml_tree, hf_wbxml_charset,
1937                                         tvb, 1+publicid_len, charset_len, charset);
1938                 }
1939                 /* String Table */
1940                 ti = proto_tree_add_text(wbxml_tree,
1941                                 tvb, offset, len + str_tbl_len, "String table: %u bytes",
1942                                 str_tbl_len);
1943
1944                 if (wbxml_tree && str_tbl_len) { /* Display string table as subtree */
1945                         wbxml_str_tbl_tree = proto_item_add_subtree (ti,
1946                                         ett_wbxml_str_tbl);
1947                         show_wbxml_string_table (wbxml_str_tbl_tree, tvb,
1948                                         str_tbl, str_tbl_len);
1949                 }
1950
1951                 /* Data starts HERE */
1952                 offset += len + str_tbl_len;
1953
1954                 /* The WBXML BODY starts here */
1955                 ti = proto_tree_add_text (wbxml_tree, tvb, offset, -1,
1956                                 "Data representation");
1957                 wbxml_content_tree = proto_item_add_subtree (ti, ett_wbxml_content);
1958
1959                 /* The parse_wbxml_X() functions will process the content correctly,
1960                  * irrespective of the WBXML version used. For the WBXML body, this
1961                  * means that there is a different processing for the global token
1962                  * RESERVED_2 (WBXML 1.0) or OPAQUE (WBXML 1.x with x > 0).  */
1963                 if (wbxml_tree) { /* Show only if visible */
1964                         if (publicid) {
1965                                 /* Retrieve the content token mapping if available */
1966                                 content_map = wbxml_content_map (publicid);
1967                                 if (content_map) {
1968                                         /* Is there a defined token mapping for publicid? */
1969                                         if (content_map->defined) {
1970                                                 proto_tree_add_text (wbxml_content_tree, tvb,
1971                                                                 offset, -1,
1972                                                                 "Level | State | Codepage "
1973                                                                 "| WBXML Token Description         "
1974                                                                 "| Rendering");
1975                                                 parse_wbxml_tag_defined (wbxml_content_tree,
1976                                                                 tvb, offset, str_tbl, &level,
1977                                                                 &len, content_map);
1978                                                 return;
1979                                         }
1980                                 }
1981                                 proto_tree_add_text (wbxml_content_tree, tvb,
1982                                                 offset, -1,
1983                                                 "[Rendering of this content type"
1984                                                 " not (yet) supported]");
1985                         }
1986                         /* Default: WBXML only, no interpretation of the content */
1987                         proto_tree_add_text (wbxml_content_tree, tvb, offset, -1,
1988                                         "Level | State | Codepage "
1989                                         "| WBXML Token Description         "
1990                                         "| Rendering");
1991                         parse_wbxml_tag (wbxml_content_tree, tvb, offset,
1992                                         str_tbl, &level, &len);
1993                         return;
1994                 }
1995                 return;
1996         }
1997 }
1998
1999
2000 /* Parse and display the WBXML string table (in a 3-column table format).
2001  * This function displays:
2002  *  - the offset in the string table,
2003  *  - the length of the string
2004  *  - the string.
2005  */
2006 static void
2007 show_wbxml_string_table (proto_tree *tree, tvbuff_t *tvb, guint32 str_tbl,
2008                 guint32 str_tbl_len)
2009 {
2010         guint32 off = str_tbl;
2011         guint32 len = 0;
2012         guint32 end = str_tbl + str_tbl_len;
2013
2014         proto_tree_add_text (tree, tvb, off, end,
2015                         "Start  | Length | String");
2016         while (off < end) {
2017                 len = tvb_strsize (tvb, off);
2018                 proto_tree_add_text (tree, tvb, off, len,
2019                                 "%6d | %6d | '%s'",
2020                                 off - str_tbl, len,
2021                                 tvb_format_text (tvb, off, len-1));
2022                 off += len;
2023         }
2024 }
2025
2026
2027 /* Indentation code is based on a static const array of space characters.
2028  * At least one single space is returned */
2029 static const char indent_buffer[514] = " "
2030         "                                                                "
2031         "                                                                "
2032         "                                                                "
2033         "                                                                "
2034         "                                                                "
2035         "                                                                "
2036         "                                                                "
2037         "                                                                "
2038         ; /* Generate XML indentation (length = 1 + 2 * 256 + 1 for '\0') */
2039
2040 static const char * Indent (guint8 level) {
2041         return indent_buffer + (512 - 2 * (level));
2042 }
2043
2044
2045 /********************
2046  * WBXML tag tokens *
2047  ********************
2048  * 
2049  * Bit Mask  : Example
2050  * -------------------
2051  * 00.. .... : <tag />
2052  *
2053  * 01.. .... : <tag>
2054  *               CONTENT
2055  *             </tag>
2056  *
2057  * 10.. .... : <tag
2058  *               atrtribute1="value1"
2059  *               atrtribute2="value2"
2060  *             />
2061  * 
2062  * 11.. .... : <tag
2063  *               atrtribute1="value1"
2064  *               atrtribute2="value2"
2065  *             >
2066  *               CONTENT
2067  *             </tag>
2068  *
2069  * NOTES
2070  *   - An XML PI is parsed as an attribute list (same syntax).
2071  *   - A code page switch only applies to the single token that follows.
2072  */
2073
2074
2075 /* This function parses the WBXML and maps known token interpretations
2076  * to the WBXML tokens. As a result, the original XML document can be
2077  * recreated. Indentation is generated in order to ease reading.
2078  *
2079  * Attribute parsing is done in parse_wbxml_attribute_list_defined().
2080  *
2081  * The wbxml_token_map entry *map contains the actual token mapping.
2082  *
2083  * NOTE: In order to parse the content, some recursion is required.
2084  *       However, for performance reasons, recursion has been avoided
2085  *       where possible (tags without content within tags with content).
2086  *       This is achieved by means of the parsing_tag_content and tag_save*
2087  *       variables.
2088  *
2089  * NOTE: See above for known token mappings.
2090  *
2091  * NOTE: As tags can be opened and closed, a tag representation lookup
2092  *       may happen once or twice for a given tag. For efficiency reasons,
2093  *       the literal tag value is stored and used throughout the code.
2094  *       With the introduction of code page support, this solution is robust
2095  *       as the lookup only occurs once, removing the need for storage of
2096  *       the used code page.
2097  */
2098 static void
2099 parse_wbxml_tag_defined (proto_tree *tree, tvbuff_t *tvb, guint32 offset,
2100                 guint32 str_tbl, guint8 *level,
2101                 guint32 *parsed_length,
2102                 const wbxml_token_map *map)
2103 {
2104         guint32 tvb_len = tvb_reported_length (tvb);
2105         guint32 off = offset;
2106         guint32 len;
2107         guint str_len;
2108         guint32 ent;
2109         guint32 index;
2110         guint8 peek;
2111         guint32 tag_len; /* Length of the index (uintvar) from a LITERAL tag */
2112         guint8 tag_save_known = 0; /* Will contain peek & 0x3F (tag identity) */
2113         guint8 tag_new_known = 0; /* Will contain peek & 0x3F (tag identity) */
2114         const char *tag_save_literal; /* Will contain the LITERAL tag identity */
2115         const char *tag_new_literal; /* Will contain the LITERAL tag identity */
2116         guint8 codepage_stag = 0; /* Initial codepage in state = STAG */
2117         guint8 parsing_tag_content = FALSE; /* Are we parsing content from a
2118                                                                                    tag with content: <x>Content</x>
2119                                                                                    
2120                                                                                    The initial state is FALSE.
2121                                                                                    This state will trigger recursion. */
2122         tag_save_literal = NULL; /* Prevents compiler warning */
2123
2124 #ifdef DEBUG
2125         printf ("WBXML - parse_wbxml_tag_defined (level = %d, offset = %d)\n",
2126                         *level, offset);
2127 #endif
2128         while (off < tvb_len) {
2129                 peek = tvb_get_guint8 (tvb, off);
2130 #ifdef DEBUG
2131                 printf("WBXML - STAG: level = %3d, peek = 0x%02X, off = %d, "
2132                                 "tvb_len = %d\n",
2133                                 *level, peek, off, tvb_len);
2134 #endif
2135                 if ((peek & 0x3F) < 4) switch (peek) { /* Global tokens in state = STAG
2136                                                                                                   but not the LITERAL tokens */
2137                         case 0x00: /* SWITCH_PAGE */
2138                                 codepage_stag = tvb_get_guint8 (tvb, off+1);
2139                                 proto_tree_add_text (tree, tvb, off, 2,
2140                                                 "      | Tag   | T 0->%3d "
2141                                                 "| SWITCH_PAGE (Tag code page)     "
2142                                                 "|",
2143                                                 codepage_stag);
2144                                 off += 2;
2145                                 break;
2146                         case 0x01: /* END: only possible for Tag with Content */
2147                                 if (tag_save_known) { /* Known TAG */
2148                                         proto_tree_add_text (tree, tvb, off, 1,
2149                                                         "  %3d | Tag   |          "
2150                                                         "| END (Known Tag 0x%02X)            "
2151                                                         "| %s</%s>",
2152                                                         *level, tag_save_known, Indent (*level),
2153                                                         tag_save_literal); /* We already looked it up! */
2154                                 } else { /* Literal TAG */
2155                                         proto_tree_add_text (tree, tvb, off, 1,
2156                                                         "  %3d | Tag   |          "
2157                                                         "| END (Literal Tag)               "
2158                                                         "| %s</%s>",
2159                                                         *level, Indent (*level),
2160                                                         tag_save_literal);
2161                                 }
2162                                 (*level)--;
2163                                 off++;
2164                                 *parsed_length = off - offset;
2165                                 /* Reset code page: not needed as return from recursion */
2166                                 return;
2167                                 break;
2168                         case 0x02: /* ENTITY */
2169                                 ent = tvb_get_guintvar (tvb, off+1, &len);
2170                                 proto_tree_add_text (tree, tvb, off, 1+len,
2171                                                 "  %3d | Tag   |          "
2172                                                 "| ENTITY                          "
2173                                                 "| %s'&#%u;'",
2174                                                 *level, Indent (*level), ent);
2175                                 off += 1+len;
2176                                 break;
2177                         case 0x03: /* STR_I */
2178                                 len = tvb_strsize (tvb, off+1);
2179                                 proto_tree_add_text (tree, tvb, off, 1+len,
2180                                                 "  %3d | Tag   |          "
2181                                                 "| STR_I (Inline string)           "
2182                                                 "| %s\'%s\'",
2183                                                 *level, Indent(*level),
2184                                                 tvb_format_text (tvb, off+1, len-1));
2185                                 off += 1+len;
2186                                 break;
2187                         case 0x40: /* EXT_I_0 */
2188                         case 0x41: /* EXT_I_1 */
2189                         case 0x42: /* EXT_I_2 */
2190                                 /* Extension tokens */
2191                                 len = tvb_strsize (tvb, off+1);
2192                                 if (codepage_stag) { /* Not default code page */
2193                                         proto_tree_add_text (tree, tvb, off, 1+len,
2194                                                         "  %3d | Tag   | T %3d->0 "
2195                                                         "| EXT_I_%1x    (Extension Token)    "
2196                                                         "| %s(%s: \'%s\')",
2197                                                         *level, codepage_stag, peek & 0x0f, Indent (*level),
2198                                                         map_token (map->global, codepage_stag, peek),
2199                                                         tvb_format_text (tvb, off+1, len-1));
2200                                         /* Reset code page */
2201                                         codepage_stag = 0;
2202                                 } else { /* Code page 0 */
2203                                         proto_tree_add_text (tree, tvb, off, 1+len,
2204                                                         "  %3d | Tag   |          "
2205                                                         "| EXT_I_%1x    (Extension Token)    "
2206                                                         "| %s(%s: \'%s\')",
2207                                                         *level, peek & 0x0f, Indent (*level),
2208                                                         map_token (map->global, codepage_stag, peek),
2209                                                         tvb_format_text (tvb, off+1, len-1));
2210                                 }
2211                                 off += 1+len;
2212                                 break;
2213                         case 0x43: /* PI */
2214                                 proto_tree_add_text (tree, tvb, off, 1,
2215                                                 "  %3d | Tag   |          "
2216                                                 "| PI (XML Processing Instruction) "
2217                                                 "| %s<?xml",
2218                                                 *level, Indent (*level));
2219                                 parse_wbxml_attribute_list_defined (tree, tvb, off, str_tbl,
2220                                                 *level, &len, map);
2221                                 off += len;
2222                                 proto_tree_add_text (tree, tvb, off-1, 1,
2223                                                 "  %3d | Tag   |          "
2224                                                 "| END (PI)                        "
2225                                                 "| %s?>",
2226                                                 *level, Indent (*level));
2227                                 break;
2228                         case 0x80: /* EXT_T_0 */
2229                         case 0x81: /* EXT_T_1 */
2230                         case 0x82: /* EXT_T_2 */
2231                                 /* Extension tokens */
2232                                 index = tvb_get_guintvar (tvb, off+1, &len);
2233                                 str_len = tvb_strsize (tvb, str_tbl+index);
2234                                 if (codepage_stag) { /* Not default code page */
2235                                         proto_tree_add_text (tree, tvb, off, 1+len,
2236                                                         "  %3d | Tag   | T %3d->0 "
2237                                                         "| EXT_T_%1x    (Extension Token)    "
2238                                                         "| %s(%s: \'%s\')",
2239                                                         *level, codepage_stag, peek & 0x0f, Indent (*level),
2240                                                         map_token (map->global, codepage_stag, peek),
2241                                                         tvb_format_text (tvb, str_tbl+index, str_len-1));
2242                                         /* Reset code page */
2243                                         codepage_stag = 0;
2244                                 } else { /* Code page 0 */
2245                                         proto_tree_add_text (tree, tvb, off, 1+len,
2246                                                         "  %3d | Tag   |          "
2247                                                         "| EXT_T_%1x    (Extension Token)    "
2248                                                         "| %s(%s: \'%s\')",
2249                                                         *level, peek & 0x0f, Indent (*level),
2250                                                         map_token (map->global, codepage_stag, peek),
2251                                                         tvb_format_text (tvb, str_tbl+index, str_len-1));
2252                                 }
2253                                 off += 1+len;
2254                                 break;
2255                         case 0x83: /* STR_T */
2256                                 index = tvb_get_guintvar (tvb, off+1, &len);
2257                                 str_len = tvb_strsize (tvb, str_tbl+index);
2258                                 proto_tree_add_text (tree, tvb, off, 1+len,
2259                                                 "  %3d | Tag   |          "
2260                                                 "| STR_T (Tableref string)         "
2261                                                 "| %s\'%s\'",
2262                                                 *level, Indent (*level),
2263                                                 tvb_format_text (tvb, str_tbl+index, str_len-1));
2264                                 off += 1+len;
2265                                 break;
2266                         case 0xC0: /* EXT_0 */
2267                         case 0xC1: /* EXT_1 */
2268                         case 0xC2: /* EXT_2 */
2269                                 /* Extension tokens */
2270                                 if (codepage_stag) { /* Not default code page */
2271                                         proto_tree_add_text (tree, tvb, off, 1,
2272                                                         "  %3d | Tag   | T %3d->0 "
2273                                                         "| EXT_%1x      (Extension Token)    "
2274                                                         "| %s(%s)",
2275                                                         *level, codepage_stag, peek & 0x0f, Indent (*level),
2276                                                         map_token (map->global, codepage_stag, peek));
2277                                         /* Reset code page */
2278                                         codepage_stag = 0;
2279                                 } else { /* Code page 0 */
2280                                         proto_tree_add_text (tree, tvb, off, 1,
2281                                                         "  %3d | Tag   |          "
2282                                                         "| EXT_%1x      (Extension Token)    "
2283                                                         "| %s(%s)",
2284                                                         *level, peek & 0x0f, Indent (*level),
2285                                                         map_token (map->global, codepage_stag, peek));
2286                                 }
2287                                 off++;
2288                                 break;
2289                         case 0xC3: /* OPAQUE - WBXML 1.1 and newer */
2290                                 if (tvb_get_guint8 (tvb, 0)) { /* WBXML 1.x (x > 0) */
2291                                         index = tvb_get_guintvar (tvb, off+1, &len);
2292                                         proto_tree_add_text (tree, tvb, off, 1 + len + index,
2293                                                         "  %3d | Tag   |          "
2294                                                         "| OPAQUE (Opaque data)            "
2295                                                         "| %s(%d bytes of opaque data)",
2296                                                         *level, Indent (*level), index);
2297                                         off += 1+len+index;
2298                                 } else { /* WBXML 1.0 - RESERVED_2 token (invalid) */
2299                                         proto_tree_add_text (tree, tvb, off, 1,
2300                                                         "  %3d | Tag   |          "
2301                                                         "| RESERVED_2     (Invalid Token!) "
2302                                                         "| WBXML 1.0 parsing stops here.",
2303                                                         *level);
2304                                         /* Stop processing as it is impossible to parse now */
2305                                         off = tvb_len;
2306                                         *parsed_length = off - offset;
2307                                         return;
2308                                 }
2309                                 break;
2310
2311                                 /* No default clause, as all cases have been treated */
2312                 } else { /* LITERAL or Known TAG */
2313                         /* We must store the initial tag, and also retrieve the new tag.
2314                          * For efficiency reasons, we store the literal tag representation
2315                          * for known tags too, so we can easily close the tag without the
2316                          * need of a new lookup and avoiding storage of token codepage.
2317                          * 
2318                          * There are 4 possibilities:
2319                          *
2320                          *  1. Known tag followed by a known tag
2321                          *  2. Known tag followed by a LITERAL tag
2322                          *  3. LITERAL tag followed by Known tag
2323                          *  4. LITERAL tag followed by LITERAL tag
2324                          */
2325
2326                         /* Store the new tag */
2327                         tag_len = 0;
2328                         if ((peek & 0x3F) == 4) { /* LITERAL */
2329                                 index = tvb_get_guintvar (tvb, off+1, &tag_len);
2330                                 str_len = tvb_strsize (tvb, str_tbl+index);
2331                                 tag_new_literal = tvb_get_ptr (tvb, str_tbl+index, str_len);
2332                                 tag_new_known = 0; /* invalidate known tag_new */
2333                         } else { /* Known tag */
2334                                 tag_new_known = peek & 0x3F;
2335                                 tag_new_literal = map_token (map->tags, codepage_stag,
2336                                                                                 tag_new_known);
2337                                 /* Stored looked up tag name string */
2338                         }
2339
2340                         /* Parsing of TAG starts HERE */
2341                         if (peek & 0x40) { /* Content present */
2342                                 /* Content follows
2343                                  * [!] An explicit END token is expected in these cases!
2344                                  * ==> Recursion possible if we encounter a tag with content;
2345                                  *     recursion will return at the explicit END token.
2346                                  */
2347                                 if (parsing_tag_content) { /* Recurse */
2348 #ifdef DEBUG
2349                                         printf ("WBXML: Tag in Tag - RECURSE! (off = %d)\n",off);
2350 #endif
2351                                         /* Do not process the attribute list:
2352                                          * recursion will take care of it */
2353                                         (*level)++;
2354                                         parse_wbxml_tag_defined (tree, tvb, off, str_tbl, level,
2355                                                         &len, map);
2356                                         off += len;
2357                                 } else { /* Now we will have content to parse */
2358                                         /* Save the start tag so we can properly close it later. */
2359                                         if ((peek & 0x3F) == 4) { /* Literal tag */
2360                                                 tag_save_literal = tag_new_literal;
2361                                                 tag_save_known = 0;
2362                                         } else { /* Known tag */
2363                                                 tag_save_known = tag_new_known;
2364                                                 tag_save_literal = tag_new_literal;
2365                                                 /* The last statement avoids needless lookups */
2366                                         }
2367                                         /* Process the attribute list if present */
2368                                         if (peek & 0x80) { /* Content and Attribute list present */
2369                                                 if (tag_new_known) { /* Known tag */
2370                                                         if (codepage_stag) { /* Not default code page */
2371                                                                 proto_tree_add_text (tree, tvb, off, 1,
2372                                                                                 "  %3d | Tag   | T %3d->0 "
2373                                                                                 "|   Known Tag 0x%02X           (AC) "
2374                                                                                 "| %s<%s",
2375                                                                                 *level, codepage_stag, tag_new_known,
2376                                                                                 Indent (*level), tag_new_literal);
2377                                                                 /* Tag string already looked up earlier! */
2378                                                                 /* Reset code page */
2379                                                                 codepage_stag = 0;
2380                                                         } else { /* Code page 0 */
2381                                                                 proto_tree_add_text (tree, tvb, off, 1,
2382                                                                                 "  %3d | Tag   |          "
2383                                                                                 "|   Known Tag 0x%02X           (AC) "
2384                                                                                 "| %s<%s",
2385                                                                                 *level, tag_new_known,
2386                                                                                 Indent (*level), tag_new_literal);
2387                                                                 /* Tag string already looked up earlier! */
2388                                                         }
2389                                                         off++;
2390                                                 } else { /* LITERAL tag */
2391                                                         proto_tree_add_text (tree, tvb, off, 1,
2392                                                                         "  %3d | Tag   |          "
2393                                                                         "| LITERAL_AC (Literal tag)   (AC) "
2394                                                                         "| %s<%s",
2395                                                                         *level, Indent (*level), tag_new_literal);
2396                                                         off += 1 + tag_len;
2397                                                 }
2398                                                 parse_wbxml_attribute_list_defined (tree, tvb,
2399                                                                 off, str_tbl, *level, &len, map);
2400                                                 off += len;
2401                                                 proto_tree_add_text (tree, tvb, off-1, 1,
2402                                                                 "  %3d | Tag   |          "
2403                                                                 "| END (attribute list)            "
2404                                                                 "| %s>",
2405                                                                 *level, Indent (*level));
2406                                         } else { /* Content, no Attribute list */
2407                                                 if (tag_new_known) { /* Known tag */
2408                                                         if (codepage_stag) { /* Not default code page */
2409                                                                 proto_tree_add_text (tree, tvb, off, 1,
2410                                                                                 "  %3d | Tag   | T %3d->0 "
2411                                                                                 "|   Known Tag 0x%02X           (.C) "
2412                                                                                 "| %s<%s>",
2413                                                                                 *level, codepage_stag, tag_new_known,
2414                                                                                 Indent (*level),
2415                                                                                 tag_new_literal);
2416                                                                 /* Tag string already looked up earlier! */
2417                                                                 /* Reset code page */
2418                                                                 codepage_stag = 0;
2419                                                         } else { /* Code page 0 */
2420                                                                 proto_tree_add_text (tree, tvb, off, 1,
2421                                                                                 "  %3d | Tag   |          "
2422                                                                                 "|   Known Tag 0x%02X           (.C) "
2423                                                                                 "| %s<%s>",
2424                                                                                 *level, tag_new_known,
2425                                                                                 Indent (*level),
2426                                                                                 tag_new_literal);
2427                                                                 /* Tag string already looked up earlier! */
2428                                                         }
2429                                                         off++;
2430                                                 } else { /* LITERAL tag */
2431                                                         proto_tree_add_text (tree, tvb, off, 1,
2432                                                                         "  %3d | Tag   |          "
2433                                                                         "| LITERAL_C  (Literal Tag)   (.C) "
2434                                                                         "| %s<%s>",
2435                                                                         *level, Indent (*level), tag_new_literal);
2436                                                         off += 1 + tag_len;
2437                                                 }
2438                                         }
2439                                         /* The data that follows in the parsing process
2440                                          * represents content for the opening tag
2441                                          * we've just processed in the lines above.
2442                                          * Next time we encounter a tag with content: recurse
2443                                          */
2444                                         parsing_tag_content = TRUE;
2445 #ifdef DEBUG
2446                                         printf ("WBXML: Tag in Tag - No recursion this time! "
2447                                                         "(off = %d)\n", off);
2448 #endif
2449                                 }
2450                         } else { /* No Content */
2451 #ifdef DEBUG
2452                                 printf ("WBXML: <Tag/> in Tag - No recursion! "
2453                                                 "(off = %d)\n", off);
2454 #endif
2455                                 (*level)++;
2456                                 if (peek & 0x80) { /* No Content, Attribute list present */
2457                                         if (tag_new_known) { /* Known tag */
2458                                                 if (codepage_stag) { /* Not default code page */
2459                                                         proto_tree_add_text (tree, tvb, off, 1,
2460                                                                         "  %3d | Tag   | T %3d->0 "
2461                                                                         "|   Known Tag 0x%02X           (A.) "
2462                                                                         "| %s<%s",
2463                                                                         *level, codepage_stag, tag_new_known,
2464                                                                         Indent (*level), tag_new_literal);
2465                                                         /* Tag string already looked up earlier! */
2466                                                         /* Reset code page */
2467                                                         codepage_stag = 0;
2468                                                 } else { /* Code page 0 */
2469                                                         proto_tree_add_text (tree, tvb, off, 1,
2470                                                                         "  %3d | Tag   |          "
2471                                                                         "|   Known Tag 0x%02X           (A.) "
2472                                                                         "| %s<%s",
2473                                                                         *level, tag_new_known,
2474                                                                         Indent (*level), tag_new_literal);
2475                                                         /* Tag string already looked up earlier! */
2476                                                 }
2477                                                 off++;
2478                                                 parse_wbxml_attribute_list_defined (tree, tvb,
2479                                                                 off, str_tbl, *level, &len, map);
2480                                                 off += len;
2481                                                 proto_tree_add_text (tree, tvb, off-1, 1,
2482                                                                 "  %3d | Tag   |          "
2483                                                                 "| END (Known Tag)                 "
2484                                                                 "| %s/>",
2485                                                                 *level, Indent (*level));
2486                                         } else { /* LITERAL tag */
2487                                                 proto_tree_add_text (tree, tvb, off, 1,
2488                                                                 "  %3d | Tag   |          "
2489                                                                 "| LITERAL_A  (Literal Tag)   (A.) "
2490                                                                 "| %s<%s",
2491                                                                 *level, Indent (*level), tag_new_literal);
2492                                                 off += 1 + tag_len;
2493                                                 parse_wbxml_attribute_list_defined (tree, tvb,
2494                                                                 off, str_tbl, *level, &len, map);
2495                                                 off += len;
2496                                                 proto_tree_add_text (tree, tvb, off-1, 1,
2497                                                                 "  %3d | Tag   |          "
2498                                                                 "| END (Literal Tag)               "
2499                                                                 "| %s/>",
2500                                                                 *level, Indent (*level));
2501                                         }
2502                                 } else { /* No Content, No Attribute list */
2503                                         if (tag_new_known) { /* Known tag */
2504                                                 if (codepage_stag) { /* Not default code page */
2505                                                         proto_tree_add_text (tree, tvb, off, 1,
2506                                                                         "  %3d | Tag   | T %3d->0 "
2507                                                                         "|   Known Tag 0x%02x           (..) "
2508                                                                         "| %s<%s />",
2509                                                                         *level, codepage_stag, tag_new_known,
2510                                                                         Indent (*level), tag_new_literal);
2511                                                         /* Tag string already looked up earlier! */
2512                                                         /* Reset code page */
2513                                                         codepage_stag = 0;
2514                                                 } else { /* Code page 0 */
2515                                                         proto_tree_add_text (tree, tvb, off, 1,
2516                                                                         "  %3d | Tag   |          "
2517                                                                         "|   Known Tag 0x%02x           (..) "
2518                                                                         "| %s<%s />",
2519                                                                         *level, tag_new_known,
2520                                                                         Indent (*level), tag_new_literal);
2521                                                         /* Tag string already looked up earlier! */
2522                                                 }
2523                                                 off++;
2524                                         } else { /* LITERAL tag */
2525                                                 proto_tree_add_text (tree, tvb, off, 1,
2526                                                                 "  %3d | Tag   |          "
2527                                                                 "| LITERAL    (Literal Tag)   (..) "
2528                                                                 "| %s<%s />",
2529                                                                 *level, Indent (*level), tag_new_literal);
2530                                                 off += 1 + tag_len;
2531                                         }
2532                                 }
2533                                 (*level)--;
2534                                 /* TODO: Do I have to reset code page here? */
2535                         }
2536                 } /* if (tag & 0x3F) >= 5 */
2537         } /* while */
2538 }
2539
2540
2541 /* This function performs the WBXML decoding as in parse_wbxml_tag_defined()
2542  * but this time no WBXML mapping is performed.
2543  *
2544  * Attribute parsing is done in parse_wbxml_attribute_list().
2545  */
2546 static void
2547 parse_wbxml_tag (proto_tree *tree, tvbuff_t *tvb, guint32 offset,
2548                 guint32 str_tbl, guint8 *level,
2549                 guint32 *parsed_length)
2550 {
2551         guint32 tvb_len = tvb_reported_length (tvb);
2552         guint32 off = offset;
2553         guint32 len;
2554         guint str_len;
2555         guint32 ent;
2556         guint32 index;
2557         guint8 peek;
2558         guint32 tag_len; /* Length of the index (uintvar) from a LITERAL tag */
2559         guint8 tag_save_known = 0; /* Will contain peek & 0x3F (tag identity) */
2560         guint8 tag_new_known = 0; /* Will contain peek & 0x3F (tag identity) */
2561         const char *tag_save_literal; /* Will contain the LITERAL tag identity */
2562         const char *tag_new_literal; /* Will contain the LITERAL tag identity */
2563         char tag_save_buf[10]; /* Will contain "tag_0x%02X" */
2564         char tag_new_buf[10]; /* Will contain "tag_0x%02X" */
2565         guint8 codepage_stag = 0; /* Initial codepage in state = STAG */
2566         guint8 parsing_tag_content = FALSE; /* Are we parsing content from a
2567                                                                                    tag with content: <x>Content</x>
2568                                                                                    
2569                                                                                    The initial state is FALSE.
2570                                                                                    This state will trigger recursion. */
2571         tag_save_literal = NULL; /* Prevents compiler warning */
2572
2573 #ifdef DEBUG
2574         printf ("WBXML - parse_wbxml_tag (level = %d, offset = %d)\n",
2575                         *level, offset);
2576 #endif
2577         while (off < tvb_len) {
2578                 peek = tvb_get_guint8 (tvb, off);
2579 #ifdef DEBUG
2580                 printf("WBXML - STAG: level = %3d, peek = 0x%02X, off = %d, "
2581                                 "tvb_len = %d\n",
2582                                 *level, peek, off, tvb_len);
2583 #endif
2584                 if ((peek & 0x3F) < 4) switch (peek) { /* Global tokens in state = STAG
2585                                                                                                   but not the LITERAL tokens */
2586                         case 0x00: /* SWITCH_PAGE */
2587                                 codepage_stag = tvb_get_guint8 (tvb, off+1);
2588                                 proto_tree_add_text (tree, tvb, off, 2,
2589                                                 "      | Tag   | T 0->%3d "
2590                                                 "| SWITCH_PAGE (Tag code page)     "
2591                                                 "|",
2592                                                 codepage_stag);
2593                                 off += 2;
2594                                 break;
2595                         case 0x01: /* END: only possible for Tag with Content */
2596                                 if (tag_save_known) { /* Known TAG */
2597                                         proto_tree_add_text (tree, tvb, off, 1,
2598                                                         "  %3d | Tag   |          "
2599                                                         "| END (Known Tag 0x%02X)            "
2600                                                         "| %s</%s>",
2601                                                         *level, tag_save_known, Indent (*level),
2602                                                         tag_save_literal); /* We already looked it up! */
2603                                 } else { /* Literal TAG */
2604                                         proto_tree_add_text (tree, tvb, off, 1,
2605                                                         "  %3d | Tag   |          "
2606                                                         "| END (Literal Tag)               "
2607                                                         "| %s</%s>",
2608                                                         *level, Indent (*level),
2609                                                         tag_save_literal);
2610                                 }
2611                                 (*level)--;
2612                                 off++;
2613                                 *parsed_length = off - offset;
2614                                 /* Reset code page: not needed as return from recursion */
2615                                 return;
2616                                 break;
2617                         case 0x02: /* ENTITY */
2618                                 ent = tvb_get_guintvar (tvb, off+1, &len);
2619                                 proto_tree_add_text (tree, tvb, off, 1+len,
2620                                                 "  %3d | Tag   |          "
2621                                                 "| ENTITY                          "
2622                                                 "| %s'&#%u;'",
2623                                                 *level, Indent (*level), ent);
2624                                 off += 1+len;
2625                                 break;
2626                         case 0x03: /* STR_I */
2627                                 len = tvb_strsize (tvb, off+1);
2628                                 proto_tree_add_text (tree, tvb, off, 1+len,
2629                                                 "  %3d | Tag   |          "
2630                                                 "| STR_I (Inline string)           "
2631                                                 "| %s\'%s\'",
2632                                                 *level, Indent(*level),
2633                                                 tvb_format_text (tvb, off+1, len-1));
2634                                 off += 1+len;
2635                                 break;
2636                         case 0x40: /* EXT_I_0 */
2637                         case 0x41: /* EXT_I_1 */
2638                         case 0x42: /* EXT_I_2 */
2639                                 /* Extension tokens */
2640                                 len = tvb_strsize (tvb, off+1);
2641                                 if (codepage_stag) { /* Not default code page */
2642                                         proto_tree_add_text (tree, tvb, off, 1+len,
2643                                                         "  %3d | Tag   | T %3d->0 "
2644                                                         "| EXT_I_%1x    (Extension Token)    "
2645                                                         "| %s(Inline string extension: \'%s\')",
2646                                                         *level, codepage_stag, peek & 0x0f, Indent (*level),
2647                                                         tvb_format_text (tvb, off+1, len-1));
2648                                         /* Reset code page */
2649                                         codepage_stag = 0;
2650                                 } else { /* Code page 0 */
2651                                         proto_tree_add_text (tree, tvb, off, 1+len,
2652                                                         "  %3d | Tag   |          "
2653                                                         "| EXT_I_%1x    (Extension Token)    "
2654                                                         "| %s(Inline string extension: \'%s\')",
2655                                                         *level, peek & 0x0f, Indent (*level),
2656                                                         tvb_format_text (tvb, off+1, len-1));
2657                                 }
2658                                 off += 1+len;
2659                                 break;
2660                         case 0x43: /* PI */
2661                                 proto_tree_add_text (tree, tvb, off, 1,
2662                                                 "  %3d | Tag   |          "
2663                                                 "| PI (XML Processing Instruction) "
2664                                                 "| %s<?xml",
2665                                                 *level, Indent (*level));
2666                                 parse_wbxml_attribute_list (tree, tvb, off, str_tbl,
2667                                                 *level, &len);
2668                                 off += len;
2669                                 proto_tree_add_text (tree, tvb, off-1, 1,
2670                                                 "  %3d | Tag   |          "
2671                                                 "| END (PI)                        "
2672                                                 "| %s?>",
2673                                                 *level, Indent (*level));
2674                                 break;
2675                         case 0x80: /* EXT_T_0 */
2676                         case 0x81: /* EXT_T_1 */
2677                         case 0x82: /* EXT_T_2 */
2678                                 /* Extension tokens */
2679                                 index = tvb_get_guintvar (tvb, off+1, &len);
2680                                 str_len = tvb_strsize (tvb, str_tbl+index);
2681                                 if (codepage_stag) { /* Not default code page */
2682                                         proto_tree_add_text (tree, tvb, off, 1+len,
2683                                                         "  %3d | Tag   | T %3d->0 "
2684                                                         "| EXT_T_%1x    (Extension Token)    "
2685                                                         "| %s(Tableref string extension: \'%s\')",
2686                                                         *level, codepage_stag, peek & 0x0f, Indent (*level),
2687                                                         tvb_format_text (tvb, str_tbl+index, str_len-1));
2688                                         /* Reset code page */
2689                                         codepage_stag = 0;
2690                                 } else { /* Code page 0 */
2691                                         proto_tree_add_text (tree, tvb, off, 1+len,
2692                                                         "  %3d | Tag   |          "
2693                                                         "| EXT_T_%1x    (Extension Token)    "
2694                                                         "| %s(Tableref string extension: \'%s\')",
2695                                                         *level, peek & 0x0f, Indent (*level),
2696                                                         tvb_format_text (tvb, str_tbl+index, str_len-1));
2697                                 }
2698                                 off += 1+len;
2699                                 break;
2700                         case 0x83: /* STR_T */
2701                                 index = tvb_get_guintvar (tvb, off+1, &len);
2702                                 str_len = tvb_strsize (tvb, str_tbl+index);
2703                                 proto_tree_add_text (tree, tvb, off, 1+len,
2704                                                 "  %3d | Tag   |          "
2705                                                 "| STR_T (Tableref string)         "
2706                                                 "| %s\'%s\'",
2707                                                 *level, Indent (*level),
2708                                                 tvb_format_text (tvb, str_tbl+index, str_len-1));
2709                                 off += 1+len;
2710                                 break;
2711                         case 0xC0: /* EXT_0 */
2712                         case 0xC1: /* EXT_1 */
2713                         case 0xC2: /* EXT_2 */
2714                                 /* Extension tokens */
2715                                 if (codepage_stag) { /* Not default code page */
2716                                         proto_tree_add_text (tree, tvb, off, 1,
2717                                                         "  %3d | Tag   | T %3d->0 "
2718                                                         "| EXT_%1x      (Extension Token)    "
2719                                                         "| %s(Single-byte extension)",
2720                                                         *level, codepage_stag, peek & 0x0f,
2721                                                         Indent (*level));
2722                                         /* Reset code page */
2723                                         codepage_stag = 0;
2724                                 } else { /* Code page 0 */
2725                                         proto_tree_add_text (tree, tvb, off, 1,
2726                                                         "  %3d | Tag   |          "
2727                                                         "| EXT_%1x      (Extension Token)    "
2728                                                         "| %s(Single-byte extension)",
2729                                                         *level, peek & 0x0f, Indent (*level));
2730                                 }
2731                                 off++;
2732                                 break;
2733                         case 0xC3: /* OPAQUE - WBXML 1.1 and newer */
2734                                 if (tvb_get_guint8 (tvb, 0)) { /* WBXML 1.x (x > 0) */
2735                                         index = tvb_get_guintvar (tvb, off+1, &len);
2736                                         proto_tree_add_text (tree, tvb, off, 1 + len + index,
2737                                                         "  %3d | Tag   |          "
2738                                                         "| OPAQUE (Opaque data)            "
2739                                                         "| %s(%d bytes of opaque data)",
2740                                                         *level, Indent (*level), index);
2741                                         off += 1+len+index;
2742                                 } else { /* WBXML 1.0 - RESERVED_2 token (invalid) */
2743                                         proto_tree_add_text (tree, tvb, off, 1,
2744                                                         "  %3d | Tag   |          "
2745                                                         "| RESERVED_2     (Invalid Token!) "
2746                                                         "| WBXML 1.0 parsing stops here.",
2747                                                         *level);
2748                                         /* Stop processing as it is impossible to parse now */
2749                                         off = tvb_len;
2750                                         *parsed_length = off - offset;
2751                                         return;
2752                                 }
2753                                 break;
2754
2755                                 /* No default clause, as all cases have been treated */
2756                 } else { /* LITERAL or Known TAG */
2757                         /* We must store the initial tag, and also retrieve the new tag.
2758                          * For efficiency reasons, we store the literal tag representation
2759                          * for known tags too, so we can easily close the tag without the
2760                          * need of a new lookup and avoiding storage of token codepage.
2761                          * 
2762                          * There are 4 possibilities:
2763                          *
2764                          *  1. Known tag followed by a known tag
2765                          *  2. Known tag followed by a LITERAL tag
2766                          *  3. LITERAL tag followed by Known tag
2767                          *  4. LITERAL tag followed by LITERAL tag
2768                          */
2769
2770                         /* Store the new tag */
2771                         tag_len = 0;
2772                         if ((peek & 0x3F) == 4) { /* LITERAL */
2773                                 index = tvb_get_guintvar (tvb, off+1, &tag_len);
2774                                 str_len = tvb_strsize (tvb, str_tbl+index);
2775                                 tag_new_literal = tvb_get_ptr (tvb, str_tbl+index, str_len);
2776                                 tag_new_known = 0; /* invalidate known tag_new */
2777                         } else { /* Known tag */
2778                                 tag_new_known = peek & 0x3F;
2779                                 sprintf (tag_new_buf, "Tag_0x%02X",
2780                                                 tag_new_known);
2781                                 tag_new_literal = tag_new_buf;
2782                                 /* Stored looked up tag name string */
2783                         }
2784
2785                         /* Parsing of TAG starts HERE */
2786                         if (peek & 0x40) { /* Content present */
2787                                 /* Content follows
2788                                  * [!] An explicit END token is expected in these cases!
2789                                  * ==> Recursion possible if we encounter a tag with content;
2790                                  *     recursion will return at the explicit END token.
2791                                  */
2792                                 if (parsing_tag_content) { /* Recurse */
2793 #ifdef DEBUG
2794                                         printf ("WBXML: Tag in Tag - RECURSE! (off = %d)\n",off);
2795 #endif
2796                                         /* Do not process the attribute list:
2797                                          * recursion will take care of it */
2798                                         (*level)++;
2799                                         parse_wbxml_tag (tree, tvb, off, str_tbl, level,
2800                                                         &len);
2801                                         off += len;
2802                                 } else { /* Now we will have content to parse */
2803                                         /* Save the start tag so we can properly close it later. */
2804                                         if ((peek & 0x3F) == 4) { /* Literal tag */
2805                                                 tag_save_literal = tag_new_literal;
2806                                                 tag_save_known = 0;
2807                                         } else { /* Known tag */
2808                                                 tag_save_known = tag_new_known;
2809                                                 sprintf (tag_save_buf, "Tag_0x%02X",
2810                                                                 tag_new_known);
2811                                                 tag_save_literal = tag_save_buf;
2812                                                 /* The last statement avoids needless lookups */
2813                                         }
2814                                         /* Process the attribute list if present */
2815                                         if (peek & 0x80) { /* Content and Attribute list present */
2816                                                 if (tag_new_known) { /* Known tag */
2817                                                         if (codepage_stag) { /* Not default code page */
2818                                                                 proto_tree_add_text (tree, tvb, off, 1,
2819                                                                                 "  %3d | Tag   | T %3d->0 "
2820                                                                                 "|   Known Tag 0x%02X           (AC) "
2821                                                                                 "| %s<%s",
2822                                                                                 *level, codepage_stag, tag_new_known,
2823                                                                                 Indent (*level), tag_new_literal);
2824                                                                 /* Tag string already looked up earlier! */
2825                                                                 /* Reset code page */
2826                                                                 codepage_stag = 0;
2827                                                         } else { /* Code page 0 */
2828                                                                 proto_tree_add_text (tree, tvb, off, 1,
2829                                                                                 "  %3d | Tag   |          "
2830                                                                                 "|   Known Tag 0x%02X           (AC) "
2831                                                                                 "| %s<%s",
2832                                                                                 *level, tag_new_known,
2833                                                                                 Indent (*level), tag_new_literal);
2834                                                                 /* Tag string already looked up earlier! */
2835                                                         }
2836                                                         off++;
2837                                                 } else { /* LITERAL tag */
2838                                                         proto_tree_add_text (tree, tvb, off, 1,
2839                                                                         "  %3d | Tag   |          "
2840                                                                         "| LITERAL_AC (Literal tag)   (AC) "
2841                                                                         "| %s<%s",
2842                                                                         *level, Indent (*level), tag_new_literal);
2843                                                         off += 1 + tag_len;
2844                                                 }
2845                                                 parse_wbxml_attribute_list (tree, tvb,
2846                                                                 off, str_tbl, *level, &len);
2847                                                 off += len;
2848                                                 proto_tree_add_text (tree, tvb, off-1, 1,
2849                                                                 "  %3d | Tag   |          "
2850                                                                 "| END (attribute list)            "
2851                                                                 "| %s>",
2852                                                                 *level, Indent (*level));
2853                                         } else { /* Content, no Attribute list */
2854                                                 if (tag_new_known) { /* Known tag */
2855                                                         if (codepage_stag) { /* Not default code page */
2856                                                                 proto_tree_add_text (tree, tvb, off, 1,
2857                                                                                 "  %3d | Tag   | T %3d->0 "
2858                                                                                 "|   Known Tag 0x%02X           (.C) "
2859                                                                                 "| %s<%s>",
2860                                                                                 *level, codepage_stag, tag_new_known,
2861                                                                                 Indent (*level),
2862                                                                                 tag_new_literal);
2863                                                                 /* Tag string already looked up earlier! */
2864                                                                 /* Reset code page */
2865                                                                 codepage_stag = 0;
2866                                                         } else { /* Code page 0 */
2867                                                                 proto_tree_add_text (tree, tvb, off, 1,
2868                                                                                 "  %3d | Tag   |          "
2869                                                                                 "|   Known Tag 0x%02X           (.C) "
2870                                                                                 "| %s<%s>",
2871                                                                                 *level, tag_new_known,
2872                                                                                 Indent (*level),
2873                                                                                 tag_new_literal);
2874                                                                 /* Tag string already looked up earlier! */
2875                                                         }
2876                                                         off++;
2877                                                 } else { /* LITERAL tag */
2878                                                         proto_tree_add_text (tree, tvb, off, 1,
2879                                                                         "  %3d | Tag   |          "
2880                                                                         "| LITERAL_C  (Literal Tag)   (.C) "
2881                                                                         "| %s<%s>",
2882                                                                         *level, Indent (*level), tag_new_literal);
2883                                                         off += 1 + tag_len;
2884                                                 }
2885                                         }
2886                                         /* The data that follows in the parsing process
2887                                          * represents content for the opening tag
2888                                          * we've just processed in the lines above.
2889                                          * Next time we encounter a tag with content: recurse
2890                                          */
2891                                         parsing_tag_content = TRUE;
2892 #ifdef DEBUG
2893                                         printf ("WBXML: Tag in Tag - No recursion this time! "
2894                                                         "(off = %d)\n", off);
2895 #endif
2896                                 }
2897                         } else { /* No Content */
2898 #ifdef DEBUG
2899                                 printf ("WBXML: <Tag/> in Tag - No recursion! "
2900                                                 "(off = %d)\n", off);
2901 #endif
2902                                 (*level)++;
2903                                 if (peek & 0x80) { /* No Content, Attribute list present */
2904                                         if (tag_new_known) { /* Known tag */
2905                                                 if (codepage_stag) { /* Not default code page */
2906                                                         proto_tree_add_text (tree, tvb, off, 1,
2907                                                                         "  %3d | Tag   | T %3d->0 "
2908                                                                         "|   Known Tag 0x%02X           (A.) "
2909                                                                         "| %s<%s",
2910                                                                         *level, codepage_stag, tag_new_known,
2911                                                                         Indent (*level), tag_new_literal);
2912                                                         /* Tag string already looked up earlier! */
2913                                                         /* Reset code page */
2914                                                         codepage_stag = 0;
2915                                                 } else { /* Code page 0 */
2916                                                         proto_tree_add_text (tree, tvb, off, 1,
2917                                                                         "  %3d | Tag   |          "
2918                                                                         "|   Known Tag 0x%02X           (A.) "
2919                                                                         "| %s<%s",
2920                                                                         *level, tag_new_known,
2921                                                                         Indent (*level), tag_new_literal);
2922                                                         /* Tag string already looked up earlier! */
2923                                                 }
2924                                                 off++;
2925                                                 parse_wbxml_attribute_list (tree, tvb,
2926                                                                 off, str_tbl, *level, &len);
2927                                                 off += len;
2928                                                 proto_tree_add_text (tree, tvb, off-1, 1,
2929                                                                 "  %3d | Tag   |          "
2930                                                                 "| END (Known Tag)                 "
2931                                                                 "| %s/>",
2932                                                                 *level, Indent (*level));
2933                                         } else { /* LITERAL tag */
2934                                                 proto_tree_add_text (tree, tvb, off, 1,
2935                                                                 "  %3d | Tag   |          "
2936                                                                 "| LITERAL_A  (Literal Tag)   (A.) "
2937                                                                 "| %s<%s",
2938                                                                 *level, Indent (*level), tag_new_literal);
2939                                                 off += 1 + tag_len;
2940                                                 parse_wbxml_attribute_list (tree, tvb,
2941                                                                 off, str_tbl, *level, &len);
2942                                                 off += len;
2943                                                 proto_tree_add_text (tree, tvb, off-1, 1,
2944                                                                 "  %3d | Tag   |          "
2945                                                                 "| END (Literal Tag)               "
2946                                                                 "| %s/>",
2947                                                                 *level, Indent (*level));
2948                                         }
2949                                 } else { /* No Content, No Attribute list */
2950                                         if (tag_new_known) { /* Known tag */
2951                                                 if (codepage_stag) { /* Not default code page */
2952                                                         proto_tree_add_text (tree, tvb, off, 1,
2953                                                                         "  %3d | Tag   | T %3d->0 "
2954                                                                         "|   Known Tag 0x%02x           (..) "
2955                                                                         "| %s<%s />",
2956                                                                         *level, codepage_stag, tag_new_known,
2957                                                                         Indent (*level), tag_new_literal);
2958                                                         /* Tag string already looked up earlier! */
2959                                                         /* Reset code page */
2960                                                         codepage_stag = 0;
2961                                                 } else { /* Code page 0 */
2962                                                         proto_tree_add_text (tree, tvb, off, 1,
2963                                                                         "  %3d | Tag   |          "
2964                                                                         "|   Known Tag 0x%02x           (..) "
2965                                                                         "| %s<%s />",
2966                                                                         *level, tag_new_known,
2967                                                                         Indent (*level), tag_new_literal);
2968                                                         /* Tag string already looked up earlier! */
2969                                                 }
2970                                                 off++;
2971                                         } else { /* LITERAL tag */
2972                                                 proto_tree_add_text (tree, tvb, off, 1,
2973                                                                 "  %3d | Tag   |          "
2974                                                                 "| LITERAL    (Literal Tag)   (..) "
2975                                                                 "| %s<%s />",
2976                                                                 *level, Indent (*level), tag_new_literal);
2977                                                 off += 1 + tag_len;
2978                                         }
2979                                 }
2980                                 (*level)--;
2981                                 /* TODO: Do I have to reset code page here? */
2982                         }
2983                 } /* if (tag & 0x3F) >= 5 */
2984         } /* while */
2985 }
2986
2987
2988 /**************************
2989  * WBXML Attribute tokens *
2990  **************************
2991  * Bit Mask  : Example
2992  * -------------------
2993  * 0... .... : attr=             (attribute name)
2994  *             href='http://'    (attribute name with start of attribute value)
2995  * 1... .... : 'www.'            (attribute value, or part of it)
2996  * 
2997  */
2998
2999
3000 /* This function parses the WBXML and maps known token interpretations
3001  * to the WBXML tokens. As a result, the original XML document can be
3002  * recreated. Indentation is generated in order to ease reading.
3003  *
3004  * This function performs attribute list parsing.
3005  * 
3006  * The wbxml_token_map entry *map contains the actual token mapping.
3007  *
3008  * NOTE: See above for known token mappings.
3009  */
3010 static void
3011 parse_wbxml_attribute_list_defined (proto_tree *tree, tvbuff_t *tvb,
3012                 guint32 offset, guint32 str_tbl, guint8 level,
3013                 guint32 *parsed_length,
3014                 const wbxml_token_map *map)
3015 {
3016         guint32 tvb_len = tvb_reported_length (tvb);
3017         guint32 off = offset;
3018         guint32 len;
3019         guint str_len;
3020         guint32 ent;
3021         guint32 index;
3022         guint8 peek;
3023         guint8 codepage_attr = 0; /* Initial codepage in state = ATTR */
3024
3025 #ifdef DEBUG
3026         printf ("WBXML - parse_wbxml_attr_defined (level = %d, offset = %d)\n",
3027                         level, offset);
3028 #endif
3029         /* Parse attributes */
3030         while (off < tvb_len) {
3031                 peek = tvb_get_guint8 (tvb, off);
3032 #ifdef DEBUG
3033                 printf("WBXML - ATTR: level = %3d, peek = 0x%02X, off = %d, "
3034                                 "tvb_len = %d\n",
3035                                 level, peek, off, tvb_len);
3036 #endif
3037                 if ((peek & 0x3F) < 5) switch (peek) { /* Global tokens
3038                                                                                                   in state = ATTR */
3039                         case 0x00: /* SWITCH_PAGE */
3040                                 codepage_attr = tvb_get_guint8 (tvb, off+1);
3041                                 proto_tree_add_text (tree, tvb, off, 2,
3042                                                 "      |  Attr | A 0->%3d "
3043                                                 "| SWITCH_PAGE (Attr code page)    |",
3044                                                 codepage_attr);
3045                                 off += 2;
3046                                 break;
3047                         case 0x01: /* END */
3048                                 /* BEWARE
3049                                  *   The Attribute END token means either ">" or "/>"
3050                                  *   and as a consequence both must be treated separately.
3051                                  *   This is done in the TAG state parser.
3052                                  */
3053                                 off++;
3054                                 *parsed_length = off - offset;
3055                                 return;
3056                         case 0x02: /* ENTITY */
3057                                 ent = tvb_get_guintvar (tvb, off+1, &len);
3058                                 proto_tree_add_text (tree, tvb, off, 1+len,
3059                                                 "  %3d |  Attr |          "
3060                                                 "| ENTITY                          "
3061                                                 "|     %s'&#%u;'",
3062                                                 level, Indent (level), ent);
3063                                 off += 1+len;
3064                                 break;
3065                         case 0x03: /* STR_I */
3066                                 len = tvb_strsize (tvb, off+1);
3067                                 proto_tree_add_text (tree, tvb, off, 1+len,
3068                                                 "  %3d |  Attr |          "
3069                                                 "| STR_I (Inline string)           "
3070                                                 "|     %s\'%s\'",
3071                                                 level, Indent (level),
3072                                                 tvb_format_text (tvb, off+1, len-1));
3073                                 off += 1+len;
3074                                 break;
3075                         case 0x04: /* LITERAL */
3076                                 index = tvb_get_guintvar (tvb, off+1, &len);
3077                                 str_len = tvb_strsize (tvb, str_tbl+index);
3078                                 proto_tree_add_text (tree, tvb, off, 1+len,
3079                                                 "  %3d |  Attr |          "
3080                                                 "| LITERAL (Literal Attribute)     "
3081                                                 "|   %s<%s />",
3082                                                 level, Indent (level),
3083                                                 tvb_format_text (tvb, str_tbl+index, str_len-1));
3084                                 off += 1+len;
3085                                 break;
3086                         case 0x40: /* EXT_I_0 */
3087                         case 0x41: /* EXT_I_1 */
3088                         case 0x42: /* EXT_I_2 */
3089                                 /* Extension tokens */
3090                                 len = tvb_strsize (tvb, off+1);
3091                                 if (codepage_attr) { /* Not default code page */
3092                                         proto_tree_add_text (tree, tvb, off, 1+len,
3093                                                         "  %3d |  Attr | A %3d->0 "
3094                                                         "| EXT_I_%1x    (Extension Token)    "
3095                                                         "|     %s(%s: \'%s\')",
3096                                                         level, codepage_attr, peek & 0x0f, Indent (level),
3097                                                         map_token (map->global, codepage_attr, peek),
3098                                                         tvb_format_text (tvb, off+1, len-1));
3099                                         /* Reset code page */
3100                                         codepage_attr = 0;
3101                                 } else { /* Code page 0 */
3102                                         proto_tree_add_text (tree, tvb, off, 1+len,
3103                                                         "  %3d |  Attr |          "
3104                                                         "| EXT_I_%1x    (Extension Token)    "
3105                                                         "|     %s(%s: \'%s\')",
3106                                                         level, peek & 0x0f, Indent (level),
3107                                                         map_token (map->global, codepage_attr, peek),
3108                                                         tvb_format_text (tvb, off+1, len-1));
3109                                 }
3110                                 off += 1+len;
3111                                 break;
3112                         /* 0x43 impossible in ATTR state */
3113                         /* 0x44 impossible in ATTR state */
3114                         case 0x80: /* EXT_T_0 */
3115                         case 0x81: /* EXT_T_1 */
3116                         case 0x82: /* EXT_T_2 */
3117                                 /* Extension tokens */
3118                                 index = tvb_get_guintvar (tvb, off+1, &len);
3119                                 str_len = tvb_strsize (tvb, str_tbl+index);
3120                                 if (codepage_attr) { /* Not default code page */
3121                                         proto_tree_add_text (tree, tvb, off, 1+len,
3122                                                         "  %3d |  Attr | A %3d->0 "
3123                                                         "| EXT_T_%1x    (Extension Token)    "
3124                                                         "|     %s(%s: \'%s\')",
3125                                                         level, codepage_attr, peek & 0x0f, Indent (level),
3126                                                         map_token (map->global, codepage_attr, peek),
3127                                                         tvb_format_text (tvb, str_tbl+index, str_len-1));
3128                                         /* Reset code page */
3129                                         codepage_attr = 0;
3130                                 } else { /* Code page 0 */
3131                                         proto_tree_add_text (tree, tvb, off, 1+len,
3132                                                         "  %3d |  Attr |          "
3133                                                         "| EXT_T_%1x    (Extension Token)    "
3134                                                         "|     %s(%s: \'%s\')",
3135                                                         level, peek & 0x0f, Indent (level),
3136                                                         map_token (map->global, codepage_attr, peek),
3137                                                         tvb_format_text (tvb, str_tbl+index, str_len-1));
3138                                 }
3139                                 off += 1+len;
3140                                 break;
3141                         case 0x83: /* STR_T */
3142                                 index = tvb_get_guintvar (tvb, off+1, &len);
3143                                 str_len = tvb_strsize (tvb, str_tbl+index);
3144                                 proto_tree_add_text (tree, tvb, off, 1+len,
3145                                                 "  %3d |  Attr |          "
3146                                                 "| STR_T (Tableref string)         "
3147                                                 "|     %s\'%s\'",
3148                                                 level, Indent (level),
3149                                                 tvb_format_text (tvb, str_tbl+index, str_len-1));
3150                                 off += 1+len;
3151                                 break;
3152                         /* 0x84 impossible in ATTR state */
3153                         case 0xC0: /* EXT_0 */
3154                         case 0xC1: /* EXT_1 */
3155                         case 0xC2: /* EXT_2 */
3156                                 /* Extension tokens */
3157                                 if (codepage_attr) { /* Not default code page */
3158                                         proto_tree_add_text (tree, tvb, off, 1,
3159                                                         "  %3d |  Attr | A %3d->0 "
3160                                                         "| EXT_%1x      (Extension Token)    "
3161                                                         "|     %s(%s)",
3162                                                         level, codepage_attr, peek & 0x0f, Indent (level),
3163                                                         map_token (map->global, codepage_attr, peek));
3164                                         /* Reset code page */
3165                                         codepage_attr = 0;
3166                                 } else { /* Code page 0 */
3167                                         proto_tree_add_text (tree, tvb, off, 1,
3168                                                         "  %3d |  Attr |          "
3169                                                         "| EXT_%1x      (Extension Token)    "
3170                                                         "|     %s(%s)",
3171                                                         level, peek & 0x0f, Indent (level),
3172                                                         map_token (map->global, codepage_attr, peek));
3173                                 }
3174                                 off++;
3175                                 break;
3176                         case 0xC3: /* OPAQUE - WBXML 1.1 and newer */
3177                                 if (tvb_get_guint8 (tvb, 0)) { /* WBXML 1.x (x > 0) */
3178                                         index = tvb_get_guintvar (tvb, off+1, &len);
3179                                         proto_tree_add_text (tree, tvb, off, 1 + len + index,
3180                                                         "  %3d |  Attr |          "
3181                                                         "| OPAQUE (Opaque data)            "
3182                                                         "|       %s(%d bytes of opaque data)",
3183                                                         level, Indent (level), index);
3184                                         off += 1+len+index;
3185                                 } else { /* WBXML 1.0 - RESERVED_2 token (invalid) */
3186                                         proto_tree_add_text (tree, tvb, off, 1,
3187                                                         "  %3d |  Attr |          "
3188                                                         "| RESERVED_2     (Invalid Token!) "
3189                                                         "| WBXML 1.0 parsing stops here.",
3190                                                         level);
3191                                         /* Stop processing as it is impossible to parse now */
3192                                         off = tvb_len;
3193                                         *parsed_length = off - offset;
3194                                         return;
3195                                 }
3196                                 break;
3197                         /* 0xC4 impossible in ATTR state */
3198                         default:
3199                                 proto_tree_add_text (tree, tvb, off, 1,
3200                                                 "  %3d |  Attr |          "
3201                                                 "| %-10s     (Invalid Token!) "
3202                                                 "| WBXML parsing stops here.",
3203                                                 level, match_strval (peek, vals_wbxml1x_global_tokens));
3204                                 /* Move to end of buffer */
3205                                 off = tvb_len;
3206                                 break;
3207                 } else { /* Known atribute token */
3208                         if (peek & 0x80) { /* attrValue */
3209                                 if (codepage_attr) { /* Not default code page */
3210                                         proto_tree_add_text (tree, tvb, off, 1,
3211                                                         "  %3d |  Attr | A %3d->0 "
3212                                                         "|   Known attrValue 0x%02X          "
3213                                                         "|       %s%s",
3214                                                         level, codepage_attr, peek & 0x7f, Indent (level),
3215                                                         map_token (map->attrValue, codepage_attr, peek));
3216                                         /* Reset code page */
3217                                         codepage_attr = 0;
3218                                 } else { /* Code page 0 */
3219                                         proto_tree_add_text (tree, tvb, off, 1,
3220                                                         "  %3d |  Attr |          "
3221                                                         "|   Known attrValue 0x%02X          "
3222                                                         "|       %s%s",
3223                                                         level, peek & 0x7f, Indent (level),
3224                                                         map_token (map->attrValue, codepage_attr, peek));
3225                                 }
3226                                 off++;
3227                         } else { /* attrStart */
3228                                 if (codepage_attr) { /* Not default code page */
3229                                         proto_tree_add_text (tree, tvb, off, 1,
3230                                                         "  %3d |  Attr | A %3d->0 "
3231                                                         "|   Known attrStart 0x%02X          "
3232                                                         "|   %s%s",
3233                                                         level, codepage_attr, peek & 0x7f, Indent (level),
3234                                                         map_token (map->attrStart, codepage_attr, peek));
3235                                         /* Reset code page */
3236                                         codepage_attr = 0;
3237                                 } else { /* Code page 0 */
3238                                         proto_tree_add_text (tree, tvb, off, 1,
3239                                                         "  %3d |  Attr |          "
3240                                                         "|   Known attrStart 0x%02X          "
3241                                                         "|   %s%s",
3242                                                         level, peek & 0x7f, Indent (level),
3243                                                         map_token (map->attrStart, codepage_attr, peek));
3244                                 }
3245                                 off++;
3246                         }
3247                 }
3248         } /* End WHILE */
3249 }
3250
3251
3252 /* This function performs the WBXML attribute decoding as in
3253  * parse_wbxml_attribute_list_defined() but this time no WBXML mapping
3254  * is performed.
3255  *
3256  * This function performs attribute list parsing.
3257  * 
3258  * NOTE: Code page switches not yet processed in the code!
3259  */
3260 static void
3261 parse_wbxml_attribute_list (proto_tree *tree, tvbuff_t *tvb,
3262                 guint32 offset, guint32 str_tbl, guint8 level,
3263                 guint32 *parsed_length)
3264 {
3265         guint32 tvb_len = tvb_reported_length (tvb);
3266         guint32 off = offset;
3267         guint32 len;
3268         guint str_len;
3269         guint32 ent;
3270         guint32 index;
3271         guint8 peek;
3272         guint8 codepage_attr = 0; /* Initial codepage in state = ATTR */
3273
3274 #ifdef DEBUG
3275         printf ("WBXML - parse_wbxml_attr (level = %d, offset = %d)\n",
3276                         level, offset);
3277 #endif
3278         /* Parse attributes */
3279         while (off < tvb_len) {
3280                 peek = tvb_get_guint8 (tvb, off);
3281 #ifdef DEBUG
3282                 printf("WBXML - ATTR: level = %3d, peek = 0x%02X, off = %d, "
3283                                 "tvb_len = %d\n",
3284                                 level, peek, off, tvb_len);
3285 #endif
3286                 if ((peek & 0x3F) < 5) switch (peek) { /* Global tokens
3287                                                                                                   in state = ATTR */
3288                         case 0x00: /* SWITCH_PAGE */
3289                                 codepage_attr = tvb_get_guint8 (tvb, off+1);
3290                                 proto_tree_add_text (tree, tvb, off, 2,
3291                                                 "      |  Attr | A 0->%3d "
3292                                                 "| SWITCH_PAGE (Attr code page)    |",
3293                                                 codepage_attr);
3294                                 off += 2;
3295                                 break;
3296                         case 0x01: /* END */
3297                                 /* BEWARE
3298                                  *   The Attribute END token means either ">" or "/>"
3299                                  *   and as a consequence both must be treated separately.
3300                                  *   This is done in the TAG state parser.
3301                                  */
3302                                 off++;
3303                                 *parsed_length = off - offset;
3304                                 return;
3305                         case 0x02: /* ENTITY */
3306                                 ent = tvb_get_guintvar (tvb, off+1, &len);
3307                                 proto_tree_add_text (tree, tvb, off, 1+len,
3308                                                 "  %3d |  Attr |          "
3309                                                 "| ENTITY                          "
3310                                                 "|     %s'&#%u;'",
3311                                                 level, Indent (level), ent);
3312                                 off += 1+len;
3313                                 break;
3314                         case 0x03: /* STR_I */
3315                                 len = tvb_strsize (tvb, off+1);
3316                                 proto_tree_add_text (tree, tvb, off, 1+len,
3317                                                 "  %3d |  Attr |          "
3318                                                 "| STR_I (Inline string)           "
3319                                                 "|     %s\'%s\'",
3320                                                 level, Indent (level),
3321                                                 tvb_format_text (tvb, off+1, len-1));
3322                                 off += 1+len;
3323                                 break;
3324                         case 0x04: /* LITERAL */
3325                                 index = tvb_get_guintvar (tvb, off+1, &len);
3326                                 str_len = tvb_strsize (tvb, str_tbl+index);
3327                                 proto_tree_add_text (tree, tvb, off, 1+len,
3328                                                 "  %3d |  Attr |          "
3329                                                 "| LITERAL (Literal Attribute)     "
3330                                                 "|   %s<%s />",
3331                                                 level, Indent (level),
3332                                                 tvb_format_text (tvb, str_tbl+index, str_len-1));
3333                                 off += 1+len;
3334                                 break;
3335                         case 0x40: /* EXT_I_0 */
3336                         case 0x41: /* EXT_I_1 */
3337                         case 0x42: /* EXT_I_2 */
3338                                 /* Extension tokens */
3339                                 len = tvb_strsize (tvb, off+1);
3340                                 if (codepage_attr) { /* Not default code page */
3341                                         proto_tree_add_text (tree, tvb, off, 1+len,
3342                                                         "  %3d |  Attr | A %3d->0 "
3343                                                         "| EXT_I_%1x    (Extension Token)    "
3344                                                         "|     %s(Inline string extension: \'%s\')",
3345                                                         level, codepage_attr, peek & 0x0f, Indent (level),
3346                                                         tvb_format_text (tvb, off+1, len-1));
3347                                         /* Reset code page */
3348                                         codepage_attr = 0;
3349                                 } else { /* Code page 0 */
3350                                         proto_tree_add_text (tree, tvb, off, 1+len,
3351                                                         "  %3d |  Attr |          "
3352                                                         "| EXT_I_%1x    (Extension Token)    "
3353                                                         "|     %s(Inline string extension: \'%s\')",
3354                                                         level, peek & 0x0f, Indent (level),
3355                                                         tvb_format_text (tvb, off+1, len-1));
3356                                 }
3357                                 off += 1+len;
3358                                 break;
3359                         /* 0x43 impossible in ATTR state */
3360                         /* 0x44 impossible in ATTR state */
3361                         case 0x80: /* EXT_T_0 */
3362                         case 0x81: /* EXT_T_1 */
3363                         case 0x82: /* EXT_T_2 */
3364                                 /* Extension tokens */
3365                                 index = tvb_get_guintvar (tvb, off+1, &len);
3366                                 str_len = tvb_strsize (tvb, str_tbl+index);
3367                                 if (codepage_attr) { /* Not default code page */
3368                                         proto_tree_add_text (tree, tvb, off, 1+len,
3369                                                         "  %3d |  Attr | A %3d->0 "
3370                                                         "| EXT_T_%1x    (Extension Token)    "
3371                                                         "|     %s(Tableref string extension: \'%s\')",
3372                                                         level, codepage_attr, peek & 0x0f, Indent (level),
3373                                                         tvb_format_text (tvb, str_tbl+index, str_len-1));
3374                                         /* Reset code page */
3375                                         codepage_attr = 0;
3376                                 } else { /* Code page 0 */
3377                                         proto_tree_add_text (tree, tvb, off, 1+len,
3378                                                         "  %3d |  Attr |          "
3379                                                         "| EXT_T_%1x    (Extension Token)    "
3380                                                         "|     %s(Tableref string extension: \'%s\')",
3381                                                         level, peek & 0x0f, Indent (level),
3382                                                         tvb_format_text (tvb, str_tbl+index, str_len-1));
3383                                 }
3384                                 off += 1+len;
3385                                 break;
3386                         case 0x83: /* STR_T */
3387                                 index = tvb_get_guintvar (tvb, off+1, &len);
3388                                 str_len = tvb_strsize (tvb, str_tbl+index);
3389                                 proto_tree_add_text (tree, tvb, off, 1+len,
3390                                                 "  %3d |  Attr |          "
3391                                                 "| STR_T (Tableref string)         "
3392                                                 "|     %s\'%s\'",
3393                                                 level, Indent (level),
3394                                                 tvb_format_text (tvb, str_tbl+index, str_len-1));
3395                                 off += 1+len;
3396                                 break;
3397                         /* 0x84 impossible in ATTR state */
3398                         case 0xC0: /* EXT_0 */
3399                         case 0xC1: /* EXT_1 */
3400                         case 0xC2: /* EXT_2 */
3401                                 /* Extension tokens */
3402                                 if (codepage_attr) { /* Not default code page */
3403                                         proto_tree_add_text (tree, tvb, off, 1,
3404                                                         "  %3d |  Attr | A %3d->0 "
3405                                                         "| EXT_%1x      (Extension Token)    "
3406                                                         "|     %s(Single-byte extension)",
3407                                                         level, codepage_attr, peek & 0x0f, Indent (level));
3408                                         /* Reset code page */
3409                                         codepage_attr = 0;
3410                                 } else { /* Code page 0 */
3411                                         proto_tree_add_text (tree, tvb, off, 1,
3412                                                         "  %3d |  Attr |          "
3413                                                         "| EXT_%1x      (Extension Token)    "
3414                                                         "|     %s(Single-byte extension)",
3415                                                         level, peek & 0x0f, Indent (level));
3416                                 }
3417                                 off++;
3418                                 break;
3419                         case 0xC3: /* OPAQUE - WBXML 1.1 and newer */
3420                                 if (tvb_get_guint8 (tvb, 0)) { /* WBXML 1.x (x > 0) */
3421                                         index = tvb_get_guintvar (tvb, off+1, &len);
3422                                         proto_tree_add_text (tree, tvb, off, 1 + len + index,
3423                                                         "  %3d |  Attr |          "
3424                                                         "| OPAQUE (Opaque data)            "
3425                                                         "|       %s(%d bytes of opaque data)",
3426                                                         level, Indent (level), index);
3427                                         off += 1+len+index;
3428                                 } else { /* WBXML 1.0 - RESERVED_2 token (invalid) */
3429                                         proto_tree_add_text (tree, tvb, off, 1,
3430                                                         "  %3d |  Attr |          "
3431                                                         "| RESERVED_2     (Invalid Token!) "
3432                                                         "| WBXML 1.0 parsing stops here.",
3433                                                         level);
3434                                         /* Stop processing as it is impossible to parse now */
3435                                         off = tvb_len;
3436                                         *parsed_length = off - offset;
3437                                         return;
3438                                 }
3439                                 break;
3440                         /* 0xC4 impossible in ATTR state */
3441                         default:
3442                                 proto_tree_add_text (tree, tvb, off, 1,
3443                                                 "  %3d |  Attr |          "
3444                                                 "| %-10s     (Invalid Token!) "
3445                                                 "| WBXML parsing stops here.",
3446                                                 level, match_strval (peek, vals_wbxml1x_global_tokens));
3447                                 /* Move to end of buffer */
3448                                 off = tvb_len;
3449                                 break;
3450                 } else { /* Known atribute token */
3451                         if (peek & 0x80) { /* attrValue */
3452                                 if (codepage_attr) { /* Not default code page */
3453                                         proto_tree_add_text (tree, tvb, off, 1,
3454                                                         "  %3d |  Attr | A %3d->0 "
3455                                                         "|   Known attrValue 0x%02X          "
3456                                                         "|       %sattrValue_0x%02X",
3457                                                         level, codepage_attr, peek & 0x7f, Indent (level),
3458                                                         peek);
3459                                         /* Reset code page */
3460                                         codepage_attr = 0;
3461                                 } else { /* Code page 0 */
3462                                         proto_tree_add_text (tree, tvb, off, 1,
3463                                                         "  %3d |  Attr |          "
3464                                                         "|   Known attrValue 0x%02X          "
3465                                                         "|       %sattrValue_0x%02X",
3466                                                         level, peek & 0x7f, Indent (level),
3467                                                         peek);
3468                                 }
3469                                 off++;
3470                         } else { /* attrStart */
3471                                 if (codepage_attr) { /* Not default code page */
3472                                         proto_tree_add_text (tree, tvb, off, 1,
3473                                                         "  %3d |  Attr | A %3d->0 "
3474                                                         "|   Known attrStart 0x%02X          "
3475                                                         "|   %sattrStart_0x%02X",
3476                                                         level, codepage_attr, peek & 0x7f, Indent (level),
3477                                                         peek);
3478                                         /* Reset code page */
3479                                         codepage_attr = 0;
3480                                 } else { /* Code page 0 */
3481                                         proto_tree_add_text (tree, tvb, off, 1,
3482                                                         "  %3d |  Attr |          "
3483                                                         "|   Known attrStart 0x%02X          "
3484                                                         "|   %sattrStart_0x%02X",
3485                                                         level, peek & 0x7f, Indent (level),
3486                                                         peek);
3487                                 }
3488                                 off++;
3489                         }
3490                 }
3491         } /* End WHILE */
3492 }
3493
3494
3495 /****************** Register the protocol with Ethereal ******************/
3496
3497
3498 /* This format is required because a script is used to build the C function
3499  * that calls the protocol registration. */
3500
3501 void
3502 proto_register_wbxml(void)
3503 { /* Setup list of header fields. See Section 1.6.1 for details. */
3504         static hf_register_info hf[] = {
3505                 { &hf_wbxml_version,
3506                         { "Version",
3507                           "wbxml.version",
3508                           FT_UINT8, BASE_HEX,
3509                           VALS ( vals_wbxml_versions ), 0x00,
3510                           "WBXML Version", HFILL }
3511                 },
3512                 { &hf_wbxml_public_id_known,
3513                         { "Public Identifier (known)",
3514                           "wbxml.public_id.known",
3515                           FT_UINT32, BASE_HEX,
3516                           VALS ( vals_wbxml_public_ids ), 0x00,
3517                           "WBXML Known Public Identifier (integer)", HFILL }
3518                 },
3519                 { &hf_wbxml_public_id_literal,
3520                         { "Public Identifier (literal)",
3521                           "wbxml.public_id.literal",
3522                           FT_STRING, BASE_NONE,
3523                           NULL, 0x00,
3524                           "WBXML Literal Public Identifier (text string)", HFILL }
3525                 },
3526                 { &hf_wbxml_charset,
3527                         { "Character Set",
3528                           "wbxml.charset",
3529                           FT_UINT32, BASE_HEX,
3530                           VALS ( vals_character_sets ), 0x00,
3531                           "WBXML Character Set", HFILL }
3532                 },
3533         };
3534
3535         /* Setup protocol subtree array */
3536         static gint *ett[] = {
3537                 &ett_wbxml,
3538                 &ett_wbxml_str_tbl,
3539                 &ett_wbxml_content,
3540         };
3541
3542         /* Register the protocol name and description */
3543         proto_wbxml = proto_register_protocol(
3544                         "WAP Binary XML",
3545                         "WBXML",
3546                         "wbxml"
3547         );
3548
3549         /* Required function calls to register the header fields
3550          * and subtrees used */
3551         proto_register_field_array(proto_wbxml, hf, array_length(hf));
3552         proto_register_subtree_array(ett, array_length(ett));
3553
3554         register_dissector("wbxml", dissect_wbxml, proto_wbxml);
3555 };
3556
3557
3558 void
3559 proto_reg_handoff_wbxml(void)
3560 {
3561         dissector_handle_t wbxml_handle;
3562
3563         /* Heuristic dissectors would be declared by means of:
3564          * heur_dissector_add("wsp", dissect_wbxml_heur, proto_wbxml);
3565          */
3566
3567         wbxml_handle = create_dissector_handle(dissect_wbxml, proto_wbxml);
3568
3569         /* Register the WSP content types (defined as protocol port)
3570          * for WBXML dissection.
3571          * 
3572          * See http://www.wapforum.org/wina/wsp-content-type.htm
3573          */
3574
3575         /**** Well-known WBXML WSP Content-Type values ****/
3576         
3577         /* application/vnd.wap.wmlc */
3578         dissector_add("wsp.content_type.integer", 0x14, wbxml_handle);
3579         dissector_add_string("wsp.content_type.literal",
3580                         "application/vnd.wap.wmlc", wbxml_handle);
3581         
3582         /* application/vnd.wap.wta-eventc */
3583         dissector_add("wsp.content_type.integer", 0x16, wbxml_handle);
3584         dissector_add_string("wsp.content_type.literal",
3585                         "application/vnd.wap.wta-eventc", wbxml_handle);
3586         
3587         /* application/vnd.wap.wbxml */
3588         dissector_add("wsp.content_type.integer", 0x29, wbxml_handle);
3589         dissector_add_string("wsp.content_type.literal",
3590                         "application/vnd.wap.wbxml", wbxml_handle);
3591         
3592         /* application/vnd.wap.sic */
3593         dissector_add("wsp.content_type.integer", 0x2E, wbxml_handle);
3594         dissector_add_string("wsp.content_type.literal",
3595                         "application/vnd.wap.sic", wbxml_handle);
3596         
3597         /* application/vnd.wap.slc */
3598         dissector_add("wsp.content_type.integer", 0x30, wbxml_handle);
3599         dissector_add_string("wsp.content_type.literal",
3600                         "application/vnd.wap.slc", wbxml_handle);
3601         
3602         /* application/vnd.wap.coc */
3603         dissector_add("wsp.content_type.integer", 0x32, wbxml_handle);
3604         dissector_add_string("wsp.content_type.literal",
3605                         "application/vnd.wap.coc", wbxml_handle);
3606         
3607         /* application/vnd.wap.connectivity-wbxml */
3608         dissector_add("wsp.content_type.integer", 0x36, wbxml_handle);
3609         dissector_add_string("wsp.content_type.literal",
3610                         "application/vnd.wap.connectivity-wbxml", wbxml_handle);
3611         
3612         /* application/vnd.wap.locc+wbxml */
3613         dissector_add("wsp.content_type.integer", 0x40, wbxml_handle);
3614         dissector_add_string("wsp.content_type.literal",
3615                         "application/vnd.wap.locc+wbxml", wbxml_handle);
3616         
3617         /* application/vnd.syncml.dm+wbxml */
3618         dissector_add("wsp.content_type.integer", 0x42, wbxml_handle);
3619         dissector_add_string("wsp.content_type.literal",
3620                         "application/vnd.syncml.dm+wbxml", wbxml_handle);
3621         
3622         /* application/vnd.oma.drm.rights+wbxml */
3623         dissector_add("wsp.content_type.integer", 0x4B, wbxml_handle);
3624         dissector_add_string("wsp.content_type.literal",
3625                         "application/vnd.oma.drm.rights+wbxml", wbxml_handle);
3626
3627         /**** Registered WBXML WSP Content-Type values ****/
3628
3629         /* application/vnd.uplanet.cacheop-wbxml */
3630         dissector_add("wsp.content_type.integer", 0x0201, wbxml_handle);
3631         dissector_add_string("wsp.content_type.literal",
3632                         "application/vnd.uplanet.cacheop-wbxml", wbxml_handle);
3633         
3634         /* application/vnd.uplanet.alert-wbxml */
3635         dissector_add("wsp.content_type.integer", 0x0203, wbxml_handle);
3636         dissector_add_string("wsp.content_type.literal",
3637                         "application/vnd.uplanet.alert-wbxml", wbxml_handle);
3638         
3639         /* application/vnd.uplanet.list-wbxml */
3640         dissector_add("wsp.content_type.integer", 0x0204, wbxml_handle);
3641         dissector_add_string("wsp.content_type.literal",
3642                         "application/vnd.uplanet.list-wbxml", wbxml_handle);
3643         
3644         /* application/vnd.uplanet.listcmd-wbxml */
3645         dissector_add("wsp.content_type.integer", 0x0205, wbxml_handle);
3646         dissector_add_string("wsp.content_type.literal",
3647                         "application/vnd.uplanet.listcmd-wbxml", wbxml_handle);
3648         
3649         /* application/vnd.uplanet.channel-wbxml */
3650         dissector_add("wsp.content_type.integer", 0x0206, wbxml_handle);
3651         dissector_add_string("wsp.content_type.literal",
3652                         "application/vnd.uplanet.channel-wbxml", wbxml_handle);
3653         
3654         /* application/vnd.uplanet.bearer-choice-wbxml */
3655         dissector_add("wsp.content_type.integer", 0x0209, wbxml_handle);
3656         dissector_add_string("wsp.content_type.literal",
3657                         "application/vnd.uplanet.bearer-choice-wbxml", wbxml_handle);
3658         
3659         /* application/vnd.phonecom.mmc-wbxml */
3660         dissector_add("wsp.content_type.integer", 0x020A, wbxml_handle);
3661         dissector_add_string("wsp.content_type.literal",
3662                         "application/vnd.phonecom.mmc-wbxml", wbxml_handle);
3663         
3664         /* application/vnd.nokia.syncset+wbxml */
3665         dissector_add("wsp.content_type.integer", 0x020B, wbxml_handle);
3666         dissector_add_string("wsp.content_type.literal",
3667                         "application/vnd.nokia.syncset+wbxml", wbxml_handle);
3668
3669         /***** Content types that only have a textual representation *****/
3670         dissector_add_string("wsp.content_type.literal",
3671                         "application/x-wap-prov.browser-bookmarks", wbxml_handle);
3672         dissector_add_string("wsp.content_type.literal",
3673                         "application/x-wap-prov.browser-settings", wbxml_handle);
3674         
3675 }