Use register_dissector_files in the plugins dissectors
[obnox/wireshark/wip.git] / plugins / opcua / opcua_simpletypes.c
1 /******************************************************************************
2 ** $Id$
3 **
4 ** Copyright (C) 2006-2007 ascolab GmbH. All Rights Reserved.
5 ** Web: http://www.ascolab.com
6 ** 
7 ** This program is free software; you can redistribute it and/or
8 ** modify it under the terms of the GNU General Public License
9 ** as published by the Free Software Foundation; either version 2
10 ** of the License, or (at your option) any later version.
11 ** 
12 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14 ** 
15 ** Project: OpcUa Wireshark Plugin
16 **
17 ** Description: Implementation of OpcUa built-in type parsers.
18 **              This contains all the simple types and some complex types.
19 **
20 ** Author: Gerhard Gappmeier <gerhard.gappmeier@ascolab.com>
21 ** Last change by: $Author: gergap $
22 **
23 ******************************************************************************/
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <glib.h>
30 #include <epan/packet.h>
31 #include <epan/dissectors/packet-windows-common.h>
32 #include "opcua_simpletypes.h"
33 #include "opcua_hfindeces.h"
34 #include <string.h>
35 #include <epan/emem.h>
36
37 #define DIAGNOSTICINFO_ENCODINGMASK_SYMBOLICID_FLAG           0x01
38 #define DIAGNOSTICINFO_ENCODINGMASK_NAMESPACE_FLAG            0x02
39 #define DIAGNOSTICINFO_ENCODINGMASK_LOCALIZEDTEXT_FLAG        0x04
40 #define DIAGNOSTICINFO_ENCODINGMASK_ADDITIONALINFO_FLAG       0x08
41 #define DIAGNOSTICINFO_ENCODINGMASK_INNERSTATUSCODE_FLAG      0x10
42 #define DIAGNOSTICINFO_ENCODINGMASK_INNERDIAGNOSTICINFO_FLAG  0x20
43 #define LOCALIZEDTEXT_ENCODINGBYTE_LOCALE                     0x01
44 #define LOCALIZEDTEXT_ENCODINGBYTE_TEXT                       0x02
45 #define NODEID_URIMASK                                        0x80
46 #define NODEID_SERVERINDEXFLAG                                0x40
47 #define DATAVALUE_ENCODINGBYTE_VALUE                          0x01
48 #define DATAVALUE_ENCODINGBYTE_STATUSCODE                     0x02
49 #define DATAVALUE_ENCODINGBYTE_SOURCETIMESTAMP                0x04
50 #define DATAVALUE_ENCODINGBYTE_SERVERTIMESTAMP                0x08
51 #define DATAVALUE_ENCODINGBYTE_SOURCEPICOSECONDS              0x10
52 #define DATAVALUE_ENCODINGBYTE_SERVERPICOSECONDS              0x20
53 #define EXTOBJ_ENCODINGMASK_BINBODY_FLAG                      0x01
54 #define EXTOBJ_ENCODINGMASK_XMLBODY_FLAG                      0x02
55
56 /* Chosen arbitrarily */
57 #define MAX_ARRAY_LEN 10000
58
59 static int hf_opcua_diag_mask_symbolicflag = -1;
60 static int hf_opcua_diag_mask_namespaceflag = -1;
61 static int hf_opcua_diag_mask_localizedtextflag = -1;
62 static int hf_opcua_diag_mask_additionalinfoflag = -1;
63 static int hf_opcua_diag_mask_innerstatuscodeflag = -1;
64 static int hf_opcua_diag_mask_innerdiaginfoflag = -1;
65 static int hf_opcua_loctext_mask_localeflag = -1;
66 static int hf_opcua_loctext_mask_textflag = -1;
67 static int hf_opcua_datavalue_mask_valueflag = -1;
68 static int hf_opcua_datavalue_mask_statuscodeflag = -1;
69 static int hf_opcua_datavalue_mask_sourcetimestampflag = -1;
70 static int hf_opcua_datavalue_mask_servertimestampflag = -1;
71 static int hf_opcua_datavalue_mask_sourcepicoseconds = -1;
72 static int hf_opcua_datavalue_mask_serverpicoseconds = -1;
73 static int hf_opcua_nodeid_encodingmask = -1;
74 static int hf_opcua_variant_encodingmask = -1;
75 static int hf_opcua_nodeid_nsid = -1;
76 static int hf_opcua_nodeid_numeric = -1;
77 static int hf_opcua_localizedtext_locale = -1;
78 static int hf_opcua_localizedtext_text = -1;
79 static int hf_opcua_qualifiedname_id = -1;
80 static int hf_opcua_qualifiedname_name = -1;
81 static int hf_opcua_SourceTimestamp = -1;
82 static int hf_opcua_SourcePicoseconds = -1;
83 static int hf_opcua_ServerTimestamp = -1;
84 static int hf_opcua_ServerPicoseconds = -1;
85 static int hf_opcua_diag_symbolicid = -1;
86 static int hf_opcua_diag_namespace = -1;
87 static int hf_opcua_diag_localizedtext = -1;
88 static int hf_opcua_diag_additionalinfo = -1;
89 static int hf_opcua_diag_innerstatuscode = -1;
90 static int hf_opcua_extobj_mask_binbodyflag = -1;
91 static int hf_opcua_extobj_mask_xmlbodyflag = -1;
92 static int hf_opcua_ArraySize = -1;
93 static int hf_opcua_Uri = -1;
94 static int hf_opcua_ServerIndex = -1;
95
96 /** NodeId encoding mask table */
97 static const value_string g_nodeidmasks[] = {
98     { 0, "Two byte encoded Numeric" },
99     { 1, "Four byte encoded Numeric" },
100     { 2, "Numeric of arbitrary length" },
101     { 3, "String" },
102     { 4, "URI" },
103     { 5, "GUID" },
104     { 6, "ByteString" },
105     { 0x80, "UriMask" },
106     { 0, NULL }
107 };
108
109 /** UA Variant Type enum */
110 typedef enum _OpcUa_BuiltInType
111 {
112     OpcUaType_Null = 0,
113     OpcUaType_Boolean = 1,
114     OpcUaType_SByte = 2,
115     OpcUaType_Byte = 3,
116     OpcUaType_Int16 = 4,
117     OpcUaType_UInt16 = 5,
118     OpcUaType_Int32 = 6,
119     OpcUaType_UInt32 = 7,
120     OpcUaType_Int64 = 8,
121     OpcUaType_UInt64 = 9,
122     OpcUaType_Float = 10,
123     OpcUaType_Double = 11,
124     OpcUaType_String = 12,
125     OpcUaType_DateTime = 13,
126     OpcUaType_Guid = 14,
127     OpcUaType_ByteString = 15,
128     OpcUaType_XmlElement = 16,
129     OpcUaType_NodeId = 17,
130     OpcUaType_ExpandedNodeId = 18,
131     OpcUaType_StatusCode = 19,
132     OpcUaType_QualifiedName = 20,
133     OpcUaType_LocalizedText = 21,
134     OpcUaType_ExtensionObject = 22,
135     OpcUaType_DataValue = 23,
136     OpcUaType_Variant = 24,
137     OpcUaType_DiagnosticInfo = 25
138 }
139 OpcUa_BuiltInType;
140
141 /** Variant encoding mask table */
142 static const value_string g_VariantTypes[] = {
143     { 0, "Null" },
144     { 1, "Boolean" },
145     { 2, "SByte" },
146     { 3, "Byte" },
147     { 4, "Int16" },
148     { 5, "UInt16" },
149     { 6, "Int32" },
150     { 7, "UInt32" },
151     { 8, "Int64" },
152     { 9, "UInt64" },
153     { 10, "Float" },
154     { 11, "Double" },
155     { 12, "String" },
156     { 13, "DateTime" },
157     { 14, "Guid" },
158     { 15, "ByteString" },
159     { 16, "XmlElement" },
160     { 17, "NodeId" },
161     { 18, "ExpandedNodeId" },
162     { 19, "StatusCode" },
163     { 20, "DiagnosticInfo" },
164     { 21, "QualifiedName" },
165     { 22, "LocalizedText" },
166     { 23, "ExtensionObject" },
167     { 24, "DataValue" },
168     { 25, "Variant" },
169     { 0x80,   "Array of Null" },
170     { 0x80+1, "Array of Boolean" },
171     { 0x80+2, "Array of SByte" },
172     { 0x80+3, "Array of Byte" },
173     { 0x80+4, "Array of Int16" },
174     { 0x80+5, "Array of UInt16" },
175     { 0x80+6, "Array of Int32" },
176     { 0x80+7, "Array of UInt32" },
177     { 0x80+8, "Array of Int64" },
178     { 0x80+9, "Array of UInt64" },
179     { 0x80+10, "Array of Float" },
180     { 0x80+11, "Array of Double" },
181     { 0x80+12, "Array of String" },
182     { 0x80+13, "Array of DateTime" },
183     { 0x80+14, "Array of Guid" },
184     { 0x80+15, "Array of ByteString" },
185     { 0x80+16, "Array of XmlElement" },
186     { 0x80+17, "Array of NodeId" },
187     { 0x80+18, "Array of ExpandedNodeId" },
188     { 0x80+19, "Array of StatusCode" },
189     { 0x80+20, "Array of DiagnosticInfo" },
190     { 0x80+21, "Array of QualifiedName" },
191     { 0x80+22, "Array of LocalizedText" },
192     { 0x80+23, "Array of ExtensionObject" },
193     { 0x80+24, "Array of DataValue" },
194     { 0x80+25, "Array of Variant" },
195     { 0, NULL }
196 };
197 #define VARIANT_ARRAYDIMENSIONS 0x40
198 #define VARIANT_ARRAYMASK 0x80
199
200 /* trees */
201 static gint ett_opcua_array = -1;
202 static gint ett_opcua_diagnosticinfo = -1;
203 static gint ett_opcua_nodeid = -1;
204 static gint ett_opcua_localeid = -1;
205 static gint ett_opcua_localizedtext = -1;
206 static gint ett_opcua_qualifiedname = -1;
207 static gint ett_opcua_datavalue = -1;
208 static gint ett_opcua_variant = -1;
209 static gint ett_opcua_extensionobject = -1;
210 static gint ett_opcua_extobj_encodingmask = -1;
211 static gint *ett[] =
212 {
213   &ett_opcua_array,
214   &ett_opcua_diagnosticinfo,
215   &ett_opcua_nodeid,
216   &ett_opcua_localeid,
217   &ett_opcua_localizedtext,
218   &ett_opcua_qualifiedname,
219   &ett_opcua_datavalue,
220   &ett_opcua_variant,
221   &ett_opcua_extensionobject,
222   &ett_opcua_extobj_encodingmask
223 };
224
225 void registerSimpleTypes(int proto)
226 {
227     static hf_register_info hf[] =
228     {
229         /* full name  ,           abbreviation  ,       type     , display  , strings, bitmask, blurb, id, parent, ref_count, bitshift */
230         { &hf_opcua_diag_mask_symbolicflag,
231         {  "has symbolic id",           "", FT_BOOLEAN, 8, NULL, DIAGNOSTICINFO_ENCODINGMASK_SYMBOLICID_FLAG, NULL, HFILL }
232         },
233         { &hf_opcua_diag_mask_namespaceflag,
234         {  "has namespace",             "", FT_BOOLEAN, 8, NULL, DIAGNOSTICINFO_ENCODINGMASK_NAMESPACE_FLAG, NULL, HFILL }
235         },
236         { &hf_opcua_diag_mask_localizedtextflag,
237         {  "has localizedtext",         "", FT_BOOLEAN, 8, NULL, DIAGNOSTICINFO_ENCODINGMASK_LOCALIZEDTEXT_FLAG, NULL, HFILL }
238         },
239         { &hf_opcua_diag_mask_additionalinfoflag,
240         {  "has additional info",       "", FT_BOOLEAN, 8, NULL, DIAGNOSTICINFO_ENCODINGMASK_ADDITIONALINFO_FLAG, NULL, HFILL }
241         },
242         { &hf_opcua_diag_mask_innerstatuscodeflag,
243         {  "has inner statuscode",      "", FT_BOOLEAN, 8, NULL, DIAGNOSTICINFO_ENCODINGMASK_INNERSTATUSCODE_FLAG, NULL, HFILL }
244         },
245         { &hf_opcua_diag_mask_innerdiaginfoflag,
246         {  "has inner diagnostic info", "", FT_BOOLEAN, 8, NULL, DIAGNOSTICINFO_ENCODINGMASK_INNERDIAGNOSTICINFO_FLAG, NULL, HFILL }
247         },
248         { &hf_opcua_loctext_mask_localeflag,
249         {  "has locale information", "", FT_BOOLEAN, 8, NULL, LOCALIZEDTEXT_ENCODINGBYTE_LOCALE, NULL, HFILL }
250         },
251         { &hf_opcua_loctext_mask_textflag,
252         {  "has text", "", FT_BOOLEAN, 8, NULL, LOCALIZEDTEXT_ENCODINGBYTE_TEXT, NULL, HFILL }
253         },
254         { &hf_opcua_nodeid_encodingmask,
255         {  "NodeId EncodingMask",        "application.nodeid.encodingmask", FT_UINT8,   BASE_HEX,  VALS(g_nodeidmasks), 0x0,    NULL,    HFILL }
256         },
257         { &hf_opcua_nodeid_nsid,
258         {  "NodeId Namespace Id",        "application.nodeid.nsid",         FT_UINT16,  BASE_DEC,  NULL, 0x0,    NULL,    HFILL }
259         },
260         { &hf_opcua_nodeid_numeric,
261         {  "NodeId Identifier Numeric",  "application.nodeid.numeric",      FT_UINT32,  BASE_DEC,  NULL, 0x0,    NULL,    HFILL }
262         },
263         { &hf_opcua_localizedtext_locale, { "Locale", "", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } },
264         { &hf_opcua_localizedtext_text,   { "Text",   "", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } },
265         { &hf_opcua_qualifiedname_id,     { "Id",     "", FT_UINT16, BASE_DEC,  NULL, 0x0, NULL, HFILL } },
266         { &hf_opcua_qualifiedname_name,   { "Name",   "", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } },
267         { &hf_opcua_datavalue_mask_valueflag,           {  "has value", "",            FT_BOOLEAN, 8, NULL, DATAVALUE_ENCODINGBYTE_VALUE, NULL, HFILL } },
268         { &hf_opcua_datavalue_mask_statuscodeflag,      {  "has statuscode", "",       FT_BOOLEAN, 8, NULL, DATAVALUE_ENCODINGBYTE_STATUSCODE, NULL, HFILL } },
269         { &hf_opcua_datavalue_mask_sourcetimestampflag, {  "has source timestamp", "", FT_BOOLEAN, 8, NULL, DATAVALUE_ENCODINGBYTE_SOURCETIMESTAMP, NULL, HFILL } },
270         { &hf_opcua_datavalue_mask_servertimestampflag, {  "has server timestamp", "", FT_BOOLEAN, 8, NULL, DATAVALUE_ENCODINGBYTE_SERVERTIMESTAMP, NULL, HFILL } },
271         { &hf_opcua_datavalue_mask_sourcepicoseconds, {  "has source picoseconds", "", FT_BOOLEAN, 8, NULL, DATAVALUE_ENCODINGBYTE_SOURCEPICOSECONDS, NULL, HFILL } },
272         { &hf_opcua_datavalue_mask_serverpicoseconds, {  "has server picoseconds", "", FT_BOOLEAN, 8, NULL, DATAVALUE_ENCODINGBYTE_SERVERPICOSECONDS, NULL, HFILL } },
273         { &hf_opcua_variant_encodingmask, { "Variant Type", "", FT_UINT8, BASE_HEX, VALS(g_VariantTypes), 0x0, NULL, HFILL } },
274         { &hf_opcua_SourceTimestamp, { "SourceTimestamp", "", FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x0, NULL, HFILL } },
275         { &hf_opcua_SourcePicoseconds, { "SourcePicoseconds", "", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
276         { &hf_opcua_ServerTimestamp, { "ServerTimestamp", "", FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x0, NULL, HFILL } },
277         { &hf_opcua_ServerPicoseconds, { "ServerPicoseconds", "", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
278         { &hf_opcua_diag_symbolicid,      { "SymbolicId", "",       FT_INT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
279         { &hf_opcua_diag_namespace,       { "Namespace", "",       FT_INT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
280         { &hf_opcua_diag_localizedtext,   { "LocaliezdText", "",   FT_INT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
281         { &hf_opcua_diag_additionalinfo,  { "AdditionalInfo", "",  FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } },
282         { &hf_opcua_diag_innerstatuscode, { "InnerStatusCode", "", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL } },
283         { &hf_opcua_extobj_mask_binbodyflag, {  "has binary body", "", FT_BOOLEAN, 8, NULL, EXTOBJ_ENCODINGMASK_BINBODY_FLAG, NULL, HFILL } },
284         { &hf_opcua_extobj_mask_xmlbodyflag, {  "has xml body",    "", FT_BOOLEAN, 8, NULL, EXTOBJ_ENCODINGMASK_XMLBODY_FLAG, NULL, HFILL } },
285         { &hf_opcua_ArraySize, { "ArraySize", "", FT_INT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
286         { &hf_opcua_Uri, { "Uri", "", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } },
287         { &hf_opcua_ServerIndex, { "ServerIndex", "", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } }
288     };
289
290     proto_register_field_array(proto, hf, array_length(hf));
291     proto_register_subtree_array(ett, array_length(ett));
292 }
293
294 void parseBoolean(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
295 {
296     proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 1, TRUE); *pOffset+=1;
297 }
298
299 void parseByte(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
300 {
301     proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 1, TRUE); *pOffset+=1;
302 }
303
304 void parseSByte(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
305 {
306     proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 1, TRUE); *pOffset+=1;
307 }
308
309 void parseUInt16(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
310 {
311     proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 2, TRUE); *pOffset+=2;
312 }
313
314 void parseInt16(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
315 {
316     proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 2, TRUE); *pOffset+=2;
317 }
318
319 void parseUInt32(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
320 {
321     proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 4, TRUE); *pOffset+=4;
322 }
323
324 void parseInt32(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
325 {
326     proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 4, TRUE); *pOffset+=4;
327 }
328
329 void parseUInt64(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
330 {
331     proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 8, TRUE); *pOffset+=8;
332 }
333
334 void parseInt64(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
335 {
336     proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 8, TRUE); *pOffset+=8;
337 }
338
339 void parseString(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
340 {
341     char *szValue;
342     gint iOffset = *pOffset;
343     gint32 iLen = tvb_get_letohl(tvb, *pOffset);
344     iOffset+=4;
345
346     if (iLen == -1)
347     {
348         proto_tree_add_string(tree, hfIndex, tvb, *pOffset, (iOffset - *pOffset),
349                               "[OpcUa Null String]");
350     }
351     else if (iLen >= 0)
352     {
353         iOffset += iLen; /* eat the whole string */
354         proto_tree_add_item(tree, hfIndex, tvb, *pOffset, (iOffset - *pOffset), TRUE);
355     }
356     else
357     {
358         szValue = ep_strdup_printf("[Invalid String] Invalid length: %d", iLen);
359         proto_tree_add_string(tree, hfIndex, tvb, *pOffset, (iOffset - *pOffset), szValue);
360     }
361
362     *pOffset = iOffset;
363 }
364
365 void parseStatusCode(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
366 {
367     proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 4, TRUE); 
368     *pOffset += 4;
369 }
370
371 void parseLocalizedText(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
372 {
373     gint        iOffset = *pOffset;
374     guint8      EncodingMask;
375     proto_tree *mask_tree;
376     proto_tree *subtree;
377     proto_item *ti;
378
379     ti = proto_tree_add_text(tree, tvb, 0, -1, "%s: LocalizedText", szFieldName);
380     subtree = proto_item_add_subtree(ti, ett_opcua_localizedtext);
381
382     /* parse encoding mask */
383     EncodingMask = tvb_get_guint8(tvb, iOffset);
384     ti = proto_tree_add_text(subtree, tvb, 0, -1, "EncodingMask");
385     mask_tree = proto_item_add_subtree(ti, ett_opcua_localizedtext);
386     proto_tree_add_item(mask_tree, hf_opcua_loctext_mask_localeflag, tvb, iOffset, 1, TRUE);
387     proto_tree_add_item(mask_tree, hf_opcua_loctext_mask_textflag,   tvb, iOffset, 1, TRUE);
388     iOffset++;
389
390     if (EncodingMask & LOCALIZEDTEXT_ENCODINGBYTE_LOCALE)
391     {
392         parseString(subtree, tvb, &iOffset, hf_opcua_localizedtext_locale);
393     }
394
395     if (EncodingMask & LOCALIZEDTEXT_ENCODINGBYTE_TEXT)
396     {
397         parseString(subtree, tvb, &iOffset, hf_opcua_localizedtext_text);
398     }
399
400     *pOffset = iOffset;
401 }
402
403 void parseGuid(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
404 {
405     proto_tree_add_item(tree, hfIndex, tvb, *pOffset, GUID_LEN, TRUE); *pOffset+=GUID_LEN;
406 }
407
408 void parseByteString(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
409 {
410     int iOffset = *pOffset;
411     gint32 iLen = tvb_get_letohl(tvb, iOffset);
412     iOffset += 4;
413
414     if (iLen == -1)
415     {
416     }
417     else if (iLen >= 0)
418     {
419         iOffset += iLen;
420     }
421     proto_tree_add_item(tree, hfIndex, tvb, *pOffset, (iOffset - *pOffset), TRUE);
422     *pOffset = iOffset;
423 }
424
425 void parseXmlElement(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
426 {
427     parseByteString(tree, tvb, pOffset, hfIndex);
428 }
429
430 void parseFloat(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
431 {
432          proto_tree_add_item(tree, hfIndex, tvb, *pOffset, sizeof(gfloat), TRUE);
433      *pOffset += sizeof(gfloat);
434 }
435
436 void parseDouble(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
437 {
438          proto_tree_add_item(tree, hfIndex, tvb, *pOffset, sizeof(gdouble), TRUE);
439      *pOffset += sizeof(gdouble);
440 }
441
442 void parseDateTime(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
443 {
444     *pOffset = dissect_nt_64bit_time(tvb, tree, *pOffset, hfIndex);
445 }
446
447 void parseDiagnosticInfo(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
448 {
449     gint        iOffset = *pOffset;
450     guint8      EncodingMask;
451     proto_tree *mask_tree;
452     proto_tree *subtree;
453     proto_item *ti;
454
455     ti = proto_tree_add_text(tree, tvb, 0, -1, "%s: DiagnosticInfo", szFieldName);
456     subtree = proto_item_add_subtree(ti, ett_opcua_diagnosticinfo);
457
458     /* parse encoding mask */
459     EncodingMask = tvb_get_guint8(tvb, iOffset);
460     ti = proto_tree_add_text(subtree, tvb, 0, -1, "EncodingMask");
461     mask_tree = proto_item_add_subtree(ti, ett_opcua_diagnosticinfo);
462     proto_tree_add_item(mask_tree, hf_opcua_diag_mask_symbolicflag,        tvb, iOffset, 1, TRUE);
463     proto_tree_add_item(mask_tree, hf_opcua_diag_mask_namespaceflag,       tvb, iOffset, 1, TRUE);
464     proto_tree_add_item(mask_tree, hf_opcua_diag_mask_localizedtextflag,   tvb, iOffset, 1, TRUE);
465     proto_tree_add_item(mask_tree, hf_opcua_diag_mask_additionalinfoflag,  tvb, iOffset, 1, TRUE);
466     proto_tree_add_item(mask_tree, hf_opcua_diag_mask_innerstatuscodeflag, tvb, iOffset, 1, TRUE);
467     proto_tree_add_item(mask_tree, hf_opcua_diag_mask_innerdiaginfoflag,   tvb, iOffset, 1, TRUE);
468     iOffset++;
469
470     if (EncodingMask & DIAGNOSTICINFO_ENCODINGMASK_SYMBOLICID_FLAG)
471     {
472         parseInt32(subtree, tvb, &iOffset, hf_opcua_diag_symbolicid);
473     }
474     if (EncodingMask & DIAGNOSTICINFO_ENCODINGMASK_NAMESPACE_FLAG)
475     {
476         parseInt32(subtree, tvb, &iOffset, hf_opcua_diag_namespace);
477     }
478     if (EncodingMask & DIAGNOSTICINFO_ENCODINGMASK_LOCALIZEDTEXT_FLAG)
479     {
480         parseInt32(subtree, tvb, &iOffset, hf_opcua_diag_localizedtext);
481     }
482     if (EncodingMask & DIAGNOSTICINFO_ENCODINGMASK_ADDITIONALINFO_FLAG)
483     {
484         parseString(subtree, tvb, &iOffset, hf_opcua_diag_additionalinfo);
485     }
486     if (EncodingMask & DIAGNOSTICINFO_ENCODINGMASK_INNERSTATUSCODE_FLAG)
487     {
488         parseStatusCode(subtree, tvb, &iOffset, hf_opcua_diag_innerstatuscode);
489     }
490     if (EncodingMask & DIAGNOSTICINFO_ENCODINGMASK_INNERDIAGNOSTICINFO_FLAG)
491     {
492         parseDiagnosticInfo(subtree, tvb, &iOffset, "Inner DiagnosticInfo");
493     }
494
495     *pOffset = iOffset;
496 }
497
498 void parseQualifiedName(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
499 {
500     proto_item *ti = proto_tree_add_text(tree, tvb, 0, -1, "%s: QualifiedName", szFieldName);
501     proto_tree *subtree = proto_item_add_subtree(ti, ett_opcua_qualifiedname);
502
503     parseUInt16(subtree, tvb, pOffset, hf_opcua_qualifiedname_id);
504     parseString(subtree, tvb, pOffset, hf_opcua_qualifiedname_name);
505 }
506
507 void parseDataValue(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
508 {
509     proto_item *ti = proto_tree_add_text(tree, tvb, 0, -1, "%s: DataValue", szFieldName);
510     proto_tree *subtree = proto_item_add_subtree(ti, ett_opcua_datavalue);
511     proto_tree *mask_tree;
512     gint    iOffset = *pOffset;
513     guint8  EncodingMask;
514
515     EncodingMask = tvb_get_guint8(tvb, iOffset);
516     ti = proto_tree_add_text(subtree, tvb, 0, -1, "EncodingMask");
517     mask_tree = proto_item_add_subtree(ti, ett_opcua_datavalue);
518     proto_tree_add_item(mask_tree, hf_opcua_datavalue_mask_valueflag,           tvb, iOffset, 1, TRUE);
519     proto_tree_add_item(mask_tree, hf_opcua_datavalue_mask_statuscodeflag,      tvb, iOffset, 1, TRUE);
520     proto_tree_add_item(mask_tree, hf_opcua_datavalue_mask_sourcetimestampflag, tvb, iOffset, 1, TRUE);
521     proto_tree_add_item(mask_tree, hf_opcua_datavalue_mask_servertimestampflag, tvb, iOffset, 1, TRUE);
522     proto_tree_add_item(mask_tree, hf_opcua_datavalue_mask_sourcepicoseconds,   tvb, iOffset, 1, TRUE);
523     proto_tree_add_item(mask_tree, hf_opcua_datavalue_mask_serverpicoseconds,   tvb, iOffset, 1, TRUE);
524     iOffset++;
525
526     if (EncodingMask & DATAVALUE_ENCODINGBYTE_VALUE)
527     {
528         parseVariant(subtree, tvb, &iOffset, "Value");
529     }
530     if (EncodingMask & DATAVALUE_ENCODINGBYTE_STATUSCODE)
531     {
532         parseStatusCode(subtree, tvb, &iOffset, hf_opcua_StatusCode);
533     }
534     if (EncodingMask & DATAVALUE_ENCODINGBYTE_SOURCETIMESTAMP)
535     {
536         parseDateTime(subtree, tvb, &iOffset, hf_opcua_SourceTimestamp);
537     }
538     if (EncodingMask & DATAVALUE_ENCODINGBYTE_SOURCEPICOSECONDS)
539     {
540         parseUInt16(subtree, tvb, &iOffset, hf_opcua_SourcePicoseconds);
541     }
542     if (EncodingMask & DATAVALUE_ENCODINGBYTE_SERVERTIMESTAMP)
543     {
544         parseDateTime(subtree, tvb, &iOffset, hf_opcua_ServerTimestamp);
545     }
546     if (EncodingMask & DATAVALUE_ENCODINGBYTE_SERVERPICOSECONDS)
547     {
548         parseUInt16(subtree, tvb, &iOffset, hf_opcua_ServerPicoseconds);
549     }
550
551     *pOffset = iOffset;
552 }
553
554 void parseVariant(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
555 {
556     proto_item *ti = proto_tree_add_text(tree, tvb, 0, -1, "%s: Variant", szFieldName);
557     proto_tree *subtree = proto_item_add_subtree(ti, ett_opcua_variant);
558     gint    iOffset = *pOffset;
559     guint8  EncodingMask;
560     gint32  ArrayLength;
561
562     EncodingMask = tvb_get_guint8(tvb, iOffset);
563     proto_tree_add_item(subtree, hf_opcua_variant_encodingmask, tvb, iOffset, 1, TRUE);
564     iOffset++;
565     ArrayLength = tvb_get_letohl(tvb, iOffset);
566
567     if (EncodingMask & VARIANT_ARRAYMASK)
568     {
569         /* type is encoded in bits 0-5 */
570         switch(EncodingMask & 0x3f)
571         {
572         case OpcUaType_Null: break;
573         case OpcUaType_Boolean: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Boolean, parseBoolean); break;
574         case OpcUaType_SByte: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_SByte, parseSByte); break;
575         case OpcUaType_Byte: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Byte, parseByte); break;
576         case OpcUaType_Int16: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Int16, parseInt16); break;
577         case OpcUaType_UInt16: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_UInt16, parseUInt16); break;
578         case OpcUaType_Int32: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Int32, parseInt32); break;
579         case OpcUaType_UInt32: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_UInt32, parseUInt32); break;
580         case OpcUaType_Int64: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Int64, parseInt64); break;
581         case OpcUaType_UInt64: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_UInt64, parseUInt64); break;
582         case OpcUaType_Float: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Float, parseFloat); break;
583         case OpcUaType_Double: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Double, parseDouble); break;
584         case OpcUaType_String: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_String, parseString); break;
585         case OpcUaType_DateTime: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_DateTime, parseDateTime); break;
586         case OpcUaType_Guid: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Guid, parseGuid); break;
587         case OpcUaType_ByteString: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_ByteString, parseByteString); break;
588         case OpcUaType_XmlElement: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_XmlElement, parseXmlElement); break;
589         case OpcUaType_NodeId: parseArrayComplex(subtree, tvb, &iOffset, "NodeId", parseNodeId); break;
590         case OpcUaType_ExpandedNodeId: parseArrayComplex(subtree, tvb, &iOffset, "ExpandedNodeId", parseExpandedNodeId); break;
591         case OpcUaType_StatusCode: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_StatusCode, parseStatusCode); break;
592         case OpcUaType_DiagnosticInfo: parseArrayComplex(subtree, tvb, &iOffset, "DiagnosticInfo", parseDiagnosticInfo); break;
593         case OpcUaType_QualifiedName: parseArrayComplex(subtree, tvb, &iOffset, "QualifiedName", parseQualifiedName); break;
594         case OpcUaType_LocalizedText: parseArrayComplex(subtree, tvb, &iOffset, "LocalizedText", parseLocalizedText); break;
595         case OpcUaType_ExtensionObject: parseArrayComplex(subtree, tvb, &iOffset, "ExtensionObject", parseExtensionObject); break;
596         case OpcUaType_DataValue: parseArrayComplex(subtree, tvb, &iOffset, "DataValue", parseDataValue); break;
597         case OpcUaType_Variant: parseArrayComplex(subtree, tvb, &iOffset, "Variant", parseVariant); break;
598         }
599     }
600     else
601     {
602         /* type is encoded in bits 0-5 */
603         switch(EncodingMask & 0x3f)
604         {
605         case OpcUaType_Null: break;
606         case OpcUaType_Boolean: parseBoolean(subtree, tvb, &iOffset, hf_opcua_Boolean); break;
607         case OpcUaType_SByte: parseSByte(subtree, tvb, &iOffset, hf_opcua_SByte); break;
608         case OpcUaType_Byte: parseByte(subtree, tvb, &iOffset, hf_opcua_Byte); break;
609         case OpcUaType_Int16: parseInt16(subtree, tvb, &iOffset, hf_opcua_Int16); break;
610         case OpcUaType_UInt16: parseUInt16(subtree, tvb, &iOffset, hf_opcua_UInt16); break;
611         case OpcUaType_Int32: parseInt32(subtree, tvb, &iOffset, hf_opcua_Int32); break;
612         case OpcUaType_UInt32: parseUInt32(subtree, tvb, &iOffset, hf_opcua_UInt32); break;
613         case OpcUaType_Int64: parseInt64(subtree, tvb, &iOffset, hf_opcua_Int64); break;
614         case OpcUaType_UInt64: parseUInt64(subtree, tvb, &iOffset, hf_opcua_UInt64); break;
615         case OpcUaType_Float: parseFloat(subtree, tvb, &iOffset, hf_opcua_Float); break;
616         case OpcUaType_Double: parseDouble(subtree, tvb, &iOffset, hf_opcua_Double); break;
617         case OpcUaType_String: parseString(subtree, tvb, &iOffset, hf_opcua_String); break;
618         case OpcUaType_DateTime: parseDateTime(subtree, tvb, &iOffset, hf_opcua_DateTime); break;
619         case OpcUaType_Guid: parseGuid(subtree, tvb, &iOffset, hf_opcua_Guid); break;
620         case OpcUaType_ByteString: parseByteString(subtree, tvb, &iOffset, hf_opcua_ByteString); break;
621         case OpcUaType_XmlElement: parseXmlElement(subtree, tvb, &iOffset, hf_opcua_XmlElement); break;
622         case OpcUaType_NodeId: parseNodeId(subtree, tvb, &iOffset, "Value"); break;
623         case OpcUaType_ExpandedNodeId: parseExpandedNodeId(subtree, tvb, &iOffset, "Value"); break;
624         case OpcUaType_StatusCode: parseStatusCode(subtree, tvb, &iOffset, hf_opcua_StatusCode); break;
625         case OpcUaType_DiagnosticInfo: parseDiagnosticInfo(subtree, tvb, &iOffset, "Value"); break;
626         case OpcUaType_QualifiedName: parseQualifiedName(subtree, tvb, &iOffset, "Value"); break;
627         case OpcUaType_LocalizedText: parseLocalizedText(subtree, tvb, &iOffset, "Value"); break;
628         case OpcUaType_ExtensionObject: parseExtensionObject(subtree, tvb, &iOffset, "Value"); break;
629         case OpcUaType_DataValue: parseDataValue(subtree, tvb, &iOffset, "Value"); break;
630         case OpcUaType_Variant: parseVariant(subtree, tvb, &iOffset, "Value"); break;
631         }
632     }
633     
634     if (EncodingMask & VARIANT_ARRAYDIMENSIONS)
635     {
636         proto_item *ti = proto_tree_add_text(tree, tvb, 0, -1, "Array Dimensions");
637         proto_tree *subtree = proto_item_add_subtree(ti, ett_opcua_array);
638         int i;
639
640         if (ArrayLength < MAX_ARRAY_LEN)
641         {
642             for (i=0; i<ArrayLength; i++)
643             {
644                 parseInt32(subtree, tvb, pOffset, hf_opcua_Int32);
645             }
646         }
647         else
648         {
649             /* XXX - This should be expert_add_info_format, but we need pinfo for that */
650             PROTO_ITEM_SET_GENERATED(proto_tree_add_text(tree, tvb, iOffset, 4, "Array length %d too large to process", ArrayLength));
651         }
652     }
653
654     *pOffset = iOffset;
655 }
656
657 /** General parsing function for arrays of simple types.
658  * All arrays have one 4 byte signed integer length information,
659  * followed by n data elements.
660  */
661 void parseArraySimple(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex, fctSimpleTypeParser pParserFunction)
662 {
663     char szFieldName[] = "Array of Simple Type";
664     proto_item *ti = proto_tree_add_text(tree, tvb, 0, -1, "%s", szFieldName);
665     proto_tree *subtree = proto_item_add_subtree(ti, ett_opcua_array);
666     int i;
667     gint32 iLen;
668
669     /* read array length */
670     iLen = tvb_get_letohl(tvb, *pOffset);
671     proto_tree_add_item(subtree, hf_opcua_ArraySize, tvb, *pOffset, 4, TRUE);
672
673     if (iLen == -1) return; /* no array */
674     if (iLen == 0)  return; /* array with zero elements*/
675
676     if (iLen > MAX_ARRAY_LEN)
677     {
678         PROTO_ITEM_SET_GENERATED(proto_tree_add_text(tree, tvb, *pOffset, 4, "Array length %d too large to process", iLen));
679         return;
680     }
681
682     *pOffset += 4;
683     for (i=0; i<iLen; i++)
684     {
685         (*pParserFunction)(subtree, tvb, pOffset, hfIndex);
686     }
687 }
688
689 /** General parsing function for arrays of enums.
690  * All arrays have one 4 byte signed integer length information,
691  * followed by n data elements.
692  */
693 void parseArrayEnum(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, fctEnumParser pParserFunction)
694 {
695     char szFieldName[] = "Array of Enum Type";
696     proto_item *ti = proto_tree_add_text(tree, tvb, 0, -1, "%s", szFieldName);
697     proto_tree *subtree = proto_item_add_subtree(ti, ett_opcua_array);
698     int i;
699     gint32 iLen;
700
701     /* read array length */
702     iLen = tvb_get_letohl(tvb, *pOffset);
703     proto_tree_add_item(subtree, hf_opcua_ArraySize, tvb, *pOffset, 4, TRUE);
704
705     if (iLen == -1) return; /* no array */
706     if (iLen == 0)  return; /* array with zero elements*/
707
708     if (iLen > MAX_ARRAY_LEN)
709     {
710         PROTO_ITEM_SET_GENERATED(proto_tree_add_text(tree, tvb, *pOffset, 4, "Array length %d too large to process", iLen));
711         return;
712     }
713
714     *pOffset += 4;
715     for (i=0; i<iLen; i++)
716     {
717         (*pParserFunction)(subtree, tvb, pOffset);
718     }
719 }
720
721 /** General parsing function for arrays of complex types.
722  * All arrays have one 4 byte signed integer length information,
723  * followed by n data elements.
724  */
725 void parseArrayComplex(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName, fctComplexTypeParser pParserFunction)
726 {
727     proto_item *ti = proto_tree_add_text(tree, tvb, 0, -1, "Array of %s", szFieldName);
728     proto_tree *subtree = proto_item_add_subtree(ti, ett_opcua_array);
729     int i;
730     gint32 iLen;
731
732     /* read array length */
733     iLen = tvb_get_letohl(tvb, *pOffset);
734     proto_tree_add_item(subtree, hf_opcua_ArraySize, tvb, *pOffset, 4, TRUE);
735
736     if (iLen == -1) return; /* no array */
737     if (iLen == 0)  return; /* array with zero elements*/
738
739     if (iLen > MAX_ARRAY_LEN)
740     {
741         PROTO_ITEM_SET_GENERATED(proto_tree_add_text(tree, tvb, *pOffset, 4, "Array length %d too large to process", iLen));
742         return;
743     }
744
745     *pOffset += 4;
746     for (i=0; i<iLen; i++)
747     {
748         char szNum[20];
749         g_snprintf(szNum, 20, "[%i]", i);
750         (*pParserFunction)(subtree, tvb, pOffset, szNum);
751     }
752 }
753
754 void parseNodeId(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
755 {
756     proto_item *ti = proto_tree_add_text(tree, tvb, 0, -1, "%s: NodeId", szFieldName);
757     proto_tree *subtree = proto_item_add_subtree(ti, ett_opcua_nodeid);
758     gint    iOffset = *pOffset;
759     guint8  EncodingMask;
760
761     EncodingMask = tvb_get_guint8(tvb, iOffset);
762     proto_tree_add_item(subtree, hf_opcua_nodeid_encodingmask, tvb, iOffset, 1, TRUE);
763     iOffset++;
764
765     switch(EncodingMask)
766     {
767     case 0x00: /* two byte node id */
768         proto_tree_add_item(subtree, hf_opcua_nodeid_numeric, tvb, iOffset, 1, TRUE);
769         iOffset+=1;
770         break;
771     case 0x01: /* four byte node id */
772         proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 1, TRUE);
773         iOffset+=1;
774         proto_tree_add_item(subtree, hf_opcua_nodeid_numeric, tvb, iOffset, 2, TRUE);
775         iOffset+=2;
776         break;
777     case 0x02: /* numeric, that does not fit into four bytes */
778         proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 2, TRUE);
779         iOffset+=2;
780         proto_tree_add_item(subtree, hf_opcua_nodeid_numeric, tvb, iOffset, 4, TRUE);
781         iOffset+=4;
782         break;
783     case 0x03: /* string */
784         proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 2, TRUE);
785         iOffset+=2;
786         parseString(subtree, tvb, &iOffset, hf_opcua_String);
787         break;
788     case 0x04: /* guid */
789         proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 2, TRUE);
790         iOffset+=2;
791         parseGuid(subtree, tvb, &iOffset, hf_opcua_Guid);
792         break;
793     case 0x05: /* byte string */
794         proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 4, TRUE);
795         iOffset+=4;
796         parseByteString(subtree, tvb, &iOffset, hf_opcua_ByteString);
797         break;
798     };
799
800     *pOffset = iOffset;
801 }
802
803 void parseExtensionObject(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
804 {
805     gint    iOffset = *pOffset;
806     guint8  EncodingMask;
807     proto_tree *extobj_tree;
808     proto_tree *mask_tree;
809     proto_item *ti;
810
811     /* add extension object subtree */
812     ti = proto_tree_add_text(tree, tvb, 0, -1, "%s : ExtensionObject", szFieldName);
813     extobj_tree = proto_item_add_subtree(ti, ett_opcua_extensionobject);
814
815     /* add nodeid subtree */
816     parseExpandedNodeId(extobj_tree, tvb, &iOffset, "TypeId");
817
818     /* parse encoding mask */
819     EncodingMask = tvb_get_guint8(tvb, iOffset);
820     ti = proto_tree_add_text(extobj_tree, tvb, 0, -1, "EncodingMask");
821     mask_tree = proto_item_add_subtree(ti, ett_opcua_extobj_encodingmask);
822     proto_tree_add_item(mask_tree, hf_opcua_extobj_mask_binbodyflag, tvb, iOffset, 1, TRUE);
823     proto_tree_add_item(mask_tree, hf_opcua_extobj_mask_xmlbodyflag, tvb, iOffset, 1, TRUE);
824     iOffset++;
825
826     if (EncodingMask & EXTOBJ_ENCODINGMASK_BINBODY_FLAG) /* has binary body ? */
827     {
828         parseByteString(extobj_tree, tvb, &iOffset, hf_opcua_ByteString);
829     }
830
831     *pOffset = iOffset;
832 }
833
834 void parseExpandedNodeId(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
835 {
836     proto_item *ti = proto_tree_add_text(tree, tvb, 0, -1, "%s: ExpandedNodeId", szFieldName);
837     proto_tree *subtree = proto_item_add_subtree(ti, ett_opcua_nodeid);
838     gint    iOffset = *pOffset;
839     guint8  EncodingMask;
840
841     EncodingMask = tvb_get_guint8(tvb, iOffset);
842     proto_tree_add_item(subtree, hf_opcua_nodeid_encodingmask, tvb, iOffset, 1, TRUE);
843     iOffset++;
844
845     switch(EncodingMask)
846     {
847     case 0x00: /* two byte node id */
848         proto_tree_add_item(subtree, hf_opcua_nodeid_numeric, tvb, iOffset, 1, TRUE);
849         iOffset+=1;
850         break;
851     case 0x01: /* four byte node id */
852         proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 1, TRUE);
853         iOffset+=1;
854         proto_tree_add_item(subtree, hf_opcua_nodeid_numeric, tvb, iOffset, 2, TRUE);
855         iOffset+=2;
856         break;
857     case 0x02: /* numeric, that does not fit into four bytes */
858         proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 2, TRUE);
859         iOffset+=2;
860         proto_tree_add_item(subtree, hf_opcua_nodeid_numeric, tvb, iOffset, 4, TRUE);
861         iOffset+=4;
862         break;
863     case 0x03: /* string */
864         proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 2, TRUE);
865         iOffset+=2;
866         parseString(subtree, tvb, &iOffset, hf_opcua_String);
867         break;
868     case 0x04: /* guid */
869         proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 2, TRUE);
870         iOffset+=2;
871         parseGuid(subtree, tvb, &iOffset, hf_opcua_Guid);
872         break;
873     case 0x05: /* byte string */
874         proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 2, TRUE);
875         iOffset+=2;
876         parseByteString(subtree, tvb, &iOffset, hf_opcua_ByteString);
877         break;
878     };
879
880     if (EncodingMask & NODEID_URIMASK)
881     {
882         parseString(subtree, tvb, &iOffset, hf_opcua_Uri);
883     }
884     if (EncodingMask & NODEID_SERVERINDEXFLAG)
885     {
886         parseUInt32(subtree, tvb, &iOffset, hf_opcua_ServerIndex);
887     }
888
889     *pOffset = iOffset;
890 }