From Gerhard Gappmeier:
[metze/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 /* string buffer */
38 #define MAX_BUFFER 256
39
40 #define DIAGNOSTICINFO_ENCODINGMASK_SYMBOLICID_FLAG           0x01
41 #define DIAGNOSTICINFO_ENCODINGMASK_NAMESPACE_FLAG            0x02
42 #define DIAGNOSTICINFO_ENCODINGMASK_LOCALIZEDTEXT_FLAG        0x04
43 #define DIAGNOSTICINFO_ENCODINGMASK_ADDITIONALINFO_FLAG       0x08
44 #define DIAGNOSTICINFO_ENCODINGMASK_INNERSTATUSCODE_FLAG      0x10
45 #define DIAGNOSTICINFO_ENCODINGMASK_INNERDIAGNOSTICINFO_FLAG  0x20
46 #define LOCALIZEDTEXT_ENCODINGBYTE_LOCALE                     0x01
47 #define LOCALIZEDTEXT_ENCODINGBYTE_TEXT                       0x02
48 #define NODEID_URIMASK                                        0x80
49 #define NODEID_SERVERINDEXFLAG                                0x40
50 #define DATAVALUE_ENCODINGBYTE_VALUE                          0x01
51 #define DATAVALUE_ENCODINGBYTE_STATUSCODE                     0x02
52 #define DATAVALUE_ENCODINGBYTE_SOURCETIMESTAMP                0x04
53 #define DATAVALUE_ENCODINGBYTE_SERVERTIMESTAMP                0x08
54 #define DATAVALUE_ENCODINGBYTE_SOURCEPICOSECONDS              0x10
55 #define DATAVALUE_ENCODINGBYTE_SERVERPICOSECONDS              0x20
56 #define EXTOBJ_ENCODINGMASK_BINBODY_FLAG                      0x01
57 #define EXTOBJ_ENCODINGMASK_XMLBODY_FLAG                      0x02
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
226 static hf_register_info hf[] =
227 {
228     /* full name  ,           abbreviation  ,       type     , display  , strings, bitmask, blurb, id, parent, ref_count, bitshift */
229     { &hf_opcua_diag_mask_symbolicflag,
230     {  "has symbolic id",           "", FT_BOOLEAN, 8, NULL, DIAGNOSTICINFO_ENCODINGMASK_SYMBOLICID_FLAG, "", HFILL }
231     },
232     { &hf_opcua_diag_mask_namespaceflag,
233     {  "has namespace",             "", FT_BOOLEAN, 8, NULL, DIAGNOSTICINFO_ENCODINGMASK_NAMESPACE_FLAG, "", HFILL }
234     },
235     { &hf_opcua_diag_mask_localizedtextflag,
236     {  "has localizedtext",         "", FT_BOOLEAN, 8, NULL, DIAGNOSTICINFO_ENCODINGMASK_LOCALIZEDTEXT_FLAG, "", HFILL }
237     },
238     { &hf_opcua_diag_mask_additionalinfoflag,
239     {  "has additional info",       "", FT_BOOLEAN, 8, NULL, DIAGNOSTICINFO_ENCODINGMASK_ADDITIONALINFO_FLAG, "", HFILL }
240     },
241     { &hf_opcua_diag_mask_innerstatuscodeflag,
242     {  "has inner statuscode",      "", FT_BOOLEAN, 8, NULL, DIAGNOSTICINFO_ENCODINGMASK_INNERSTATUSCODE_FLAG, "", HFILL }
243     },
244     { &hf_opcua_diag_mask_innerdiaginfoflag,
245     {  "has inner diagnostic info", "", FT_BOOLEAN, 8, NULL, DIAGNOSTICINFO_ENCODINGMASK_INNERDIAGNOSTICINFO_FLAG, "", HFILL }
246     },
247     { &hf_opcua_loctext_mask_localeflag,
248     {  "has locale information", "", FT_BOOLEAN, 8, NULL, LOCALIZEDTEXT_ENCODINGBYTE_LOCALE, "", HFILL }
249     },
250     { &hf_opcua_loctext_mask_textflag,
251     {  "has text", "", FT_BOOLEAN, 8, NULL, LOCALIZEDTEXT_ENCODINGBYTE_TEXT, "", HFILL }
252     },
253     { &hf_opcua_nodeid_encodingmask,
254     {  "NodeId EncodingMask",        "application.nodeid.encodingmask", FT_UINT8,   BASE_HEX,  VALS(g_nodeidmasks), 0x0,    "",    HFILL }
255     },
256     { &hf_opcua_nodeid_nsid,
257     {  "NodeId Namespace Id",        "application.nodeid.nsid",         FT_UINT16,  BASE_DEC,  NULL, 0x0,    "",    HFILL }
258     },
259     { &hf_opcua_nodeid_numeric,
260     {  "NodeId Identifier Numeric",  "application.nodeid.numeric",      FT_UINT32,  BASE_DEC,  NULL, 0x0,    "",    HFILL }
261     },
262     { &hf_opcua_localizedtext_locale, { "Locale", "", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL } },
263     { &hf_opcua_localizedtext_text,   { "Text",   "", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL } },
264     { &hf_opcua_qualifiedname_id,     { "Id",     "", FT_UINT16, BASE_DEC,  NULL, 0x0, "", HFILL } },
265     { &hf_opcua_qualifiedname_name,   { "Name",   "", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL } },
266     { &hf_opcua_datavalue_mask_valueflag,           {  "has value", "",            FT_BOOLEAN, 8, NULL, DATAVALUE_ENCODINGBYTE_VALUE, "", HFILL } },
267     { &hf_opcua_datavalue_mask_statuscodeflag,      {  "has statuscode", "",       FT_BOOLEAN, 8, NULL, DATAVALUE_ENCODINGBYTE_STATUSCODE, "", HFILL } },
268     { &hf_opcua_datavalue_mask_sourcetimestampflag, {  "has source timestamp", "", FT_BOOLEAN, 8, NULL, DATAVALUE_ENCODINGBYTE_SOURCETIMESTAMP, "", HFILL } },
269     { &hf_opcua_datavalue_mask_servertimestampflag, {  "has server timestamp", "", FT_BOOLEAN, 8, NULL, DATAVALUE_ENCODINGBYTE_SERVERTIMESTAMP, "", HFILL } },
270     { &hf_opcua_datavalue_mask_sourcepicoseconds, {  "has source picoseconds", "", FT_BOOLEAN, 8, NULL, DATAVALUE_ENCODINGBYTE_SOURCEPICOSECONDS, "", HFILL } },
271     { &hf_opcua_datavalue_mask_serverpicoseconds, {  "has server picoseconds", "", FT_BOOLEAN, 8, NULL, DATAVALUE_ENCODINGBYTE_SERVERPICOSECONDS, "", HFILL } },
272     { &hf_opcua_variant_encodingmask, { "Variant Type", "", FT_UINT8, BASE_HEX, VALS(g_VariantTypes), 0x0, "", HFILL } },
273     { &hf_opcua_SourceTimestamp, { "SourceTimestamp", "", FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x0, "", HFILL } },
274     { &hf_opcua_SourcePicoseconds, { "SourcePicoseconds", "", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL } },
275     { &hf_opcua_ServerTimestamp, { "ServerTimestamp", "", FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x0, "", HFILL } },
276     { &hf_opcua_ServerPicoseconds, { "ServerPicoseconds", "", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL } },
277     { &hf_opcua_diag_symbolicid,      { "SymbolicId", "",       FT_INT32, BASE_DEC, NULL, 0x0, "", HFILL } },
278     { &hf_opcua_diag_namespace,       { "Namespace", "",       FT_INT32, BASE_DEC, NULL, 0x0, "", HFILL } },
279     { &hf_opcua_diag_localizedtext,   { "LocaliezdText", "",   FT_INT32, BASE_DEC, NULL, 0x0, "", HFILL } },
280     { &hf_opcua_diag_additionalinfo,  { "AdditionalInfo", "",  FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL } },
281     { &hf_opcua_diag_innerstatuscode, { "InnerStatusCode", "", FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL } },
282     { &hf_opcua_extobj_mask_binbodyflag, {  "has binary body", "", FT_BOOLEAN, 8, NULL, EXTOBJ_ENCODINGMASK_BINBODY_FLAG, "", HFILL } },
283     { &hf_opcua_extobj_mask_xmlbodyflag, {  "has xml body",    "", FT_BOOLEAN, 8, NULL, EXTOBJ_ENCODINGMASK_XMLBODY_FLAG, "", HFILL } },
284     { &hf_opcua_ArraySize, { "ArraySize", "", FT_INT32, BASE_DEC, NULL, 0x0, "", HFILL } },
285     { &hf_opcua_Uri, { "Uri", "", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL } },
286     { &hf_opcua_ServerIndex, { "ServerIndex", "", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL } }
287 };
288
289 void registerSimpleTypes(int proto)
290 {
291     proto_register_field_array(proto, hf, array_length(hf));
292     proto_register_subtree_array(ett, array_length(ett));
293 }
294
295 void parseBoolean(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
296 {
297     proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 1, TRUE); *pOffset+=1;
298 }
299
300 void parseByte(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
301 {
302     proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 1, TRUE); *pOffset+=1;
303 }
304
305 void parseSByte(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
306 {
307     proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 1, TRUE); *pOffset+=1;
308 }
309
310 void parseUInt16(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
311 {
312     proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 2, TRUE); *pOffset+=2;
313 }
314
315 void parseInt16(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
316 {
317     proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 2, TRUE); *pOffset+=2;
318 }
319
320 void parseUInt32(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
321 {
322     proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 4, TRUE); *pOffset+=4;
323 }
324
325 void parseInt32(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
326 {
327     proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 4, TRUE); *pOffset+=4;
328 }
329
330 void parseUInt64(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
331 {
332     proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 8, TRUE); *pOffset+=8;
333 }
334
335 void parseInt64(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
336 {
337     proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 8, TRUE); *pOffset+=8;
338 }
339
340 void parseString(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
341 {
342     char *szValue = ep_alloc(MAX_BUFFER);
343     gint iOffset = *pOffset;
344     gint32 iLen = tvb_get_letohl(tvb, *pOffset);
345     iOffset+=4;
346
347     if (szValue)
348     {
349         if (iLen == -1)
350         {
351             g_snprintf(szValue, MAX_BUFFER, "[OpcUa Null String]");
352         }
353         else if (iLen >= 0)
354         {
355             int iStrLen = iLen;
356             if (iStrLen > (MAX_BUFFER-1)) iStrLen = MAX_BUFFER - 1;
357             /* copy non null terminated string of length iStrlen */
358             strncpy(szValue, (char*)&tvb->real_data[iOffset], iStrLen);
359             /* set null terminator */
360             szValue[iStrLen] = 0;
361             iOffset += iLen; /* eat the whole string */
362         }
363         else
364         {
365             g_snprintf(szValue, MAX_BUFFER, "[Invalid String] Ups, something is wrong with this message.");
366         }
367
368         proto_tree_add_string(tree, hfIndex, tvb, *pOffset, (iOffset - *pOffset), szValue);
369         *pOffset = iOffset;
370     }
371 }
372
373 void parseStatusCode(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
374 {
375     proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 4, TRUE); 
376     *pOffset += 4;
377 }
378
379 void parseLocalizedText(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
380 {
381     gint        iOffset = *pOffset;
382     guint8      EncodingMask;
383     proto_tree *mask_tree;
384     proto_tree *subtree;
385     proto_item *ti;
386
387     ti = proto_tree_add_text(tree, tvb, 0, -1, "%s: LocalizedText", szFieldName);
388     subtree = proto_item_add_subtree(ti, ett_opcua_localizedtext);
389
390     /* parse encoding mask */
391     EncodingMask = tvb_get_guint8(tvb, iOffset);
392     ti = proto_tree_add_text(subtree, tvb, 0, -1, "EncodingMask");
393     mask_tree = proto_item_add_subtree(ti, ett_opcua_localizedtext);
394     proto_tree_add_item(mask_tree, hf_opcua_loctext_mask_localeflag, tvb, iOffset, 1, TRUE);
395     proto_tree_add_item(mask_tree, hf_opcua_loctext_mask_textflag,   tvb, iOffset, 1, TRUE);
396     iOffset++;
397
398     if (EncodingMask & LOCALIZEDTEXT_ENCODINGBYTE_LOCALE)
399     {
400         parseString(subtree, tvb, &iOffset, hf_opcua_localizedtext_locale);
401     }
402
403     if (EncodingMask & LOCALIZEDTEXT_ENCODINGBYTE_TEXT)
404     {
405         parseString(subtree, tvb, &iOffset, hf_opcua_localizedtext_text);
406     }
407
408     *pOffset = iOffset;
409 }
410
411 void parseGuid(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
412 {
413     proto_tree_add_item(tree, hfIndex, tvb, *pOffset, GUID_LEN, TRUE); *pOffset+=GUID_LEN;
414 }
415
416 void parseByteString(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
417 {
418     int iOffset = *pOffset;
419     gint32 iLen = tvb_get_letohl(tvb, iOffset);
420     iOffset += 4;
421
422     if (iLen == -1)
423     {
424     }
425     else if (iLen >= 0)
426     {
427         iOffset += iLen;
428     }
429     proto_tree_add_item(tree, hfIndex, tvb, *pOffset, (iOffset - *pOffset), TRUE);
430     *pOffset = iOffset;
431 }
432
433 void parseXmlElement(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
434 {
435     parseByteString(tree, tvb, pOffset, hfIndex);
436 }
437
438 void parseFloat(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
439 {
440          proto_tree_add_item(tree, hfIndex, tvb, *pOffset, sizeof(gfloat), TRUE);
441      *pOffset += sizeof(gfloat);
442 }
443
444 void parseDouble(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
445 {
446          proto_tree_add_item(tree, hfIndex, tvb, *pOffset, sizeof(gdouble), TRUE);
447      *pOffset += sizeof(gdouble);
448 }
449
450 void parseDateTime(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
451 {
452     *pOffset = dissect_nt_64bit_time(tvb, tree, *pOffset, hfIndex);
453 }
454
455 void parseDiagnosticInfo(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
456 {
457     gint        iOffset = *pOffset;
458     guint8      EncodingMask;
459     proto_tree *mask_tree;
460     proto_tree *subtree;
461     proto_item *ti;
462
463     ti = proto_tree_add_text(tree, tvb, 0, -1, "%s: DiagnosticInfo", szFieldName);
464     subtree = proto_item_add_subtree(ti, ett_opcua_diagnosticinfo);
465
466     /* parse encoding mask */
467     EncodingMask = tvb_get_guint8(tvb, iOffset);
468     ti = proto_tree_add_text(subtree, tvb, 0, -1, "EncodingMask");
469     mask_tree = proto_item_add_subtree(ti, ett_opcua_diagnosticinfo);
470     proto_tree_add_item(mask_tree, hf_opcua_diag_mask_symbolicflag,        tvb, iOffset, 1, TRUE);
471     proto_tree_add_item(mask_tree, hf_opcua_diag_mask_namespaceflag,       tvb, iOffset, 1, TRUE);
472     proto_tree_add_item(mask_tree, hf_opcua_diag_mask_localizedtextflag,   tvb, iOffset, 1, TRUE);
473     proto_tree_add_item(mask_tree, hf_opcua_diag_mask_additionalinfoflag,  tvb, iOffset, 1, TRUE);
474     proto_tree_add_item(mask_tree, hf_opcua_diag_mask_innerstatuscodeflag, tvb, iOffset, 1, TRUE);
475     proto_tree_add_item(mask_tree, hf_opcua_diag_mask_innerdiaginfoflag,   tvb, iOffset, 1, TRUE);
476     iOffset++;
477
478     if (EncodingMask & DIAGNOSTICINFO_ENCODINGMASK_SYMBOLICID_FLAG)
479     {
480         parseInt32(subtree, tvb, &iOffset, hf_opcua_diag_symbolicid);
481     }
482     if (EncodingMask & DIAGNOSTICINFO_ENCODINGMASK_NAMESPACE_FLAG)
483     {
484         parseInt32(subtree, tvb, &iOffset, hf_opcua_diag_namespace);
485     }
486     if (EncodingMask & DIAGNOSTICINFO_ENCODINGMASK_LOCALIZEDTEXT_FLAG)
487     {
488         parseInt32(subtree, tvb, &iOffset, hf_opcua_diag_localizedtext);
489     }
490     if (EncodingMask & DIAGNOSTICINFO_ENCODINGMASK_ADDITIONALINFO_FLAG)
491     {
492         parseString(subtree, tvb, &iOffset, hf_opcua_diag_additionalinfo);
493     }
494     if (EncodingMask & DIAGNOSTICINFO_ENCODINGMASK_INNERSTATUSCODE_FLAG)
495     {
496         parseStatusCode(subtree, tvb, &iOffset, hf_opcua_diag_innerstatuscode);
497     }
498     if (EncodingMask & DIAGNOSTICINFO_ENCODINGMASK_INNERDIAGNOSTICINFO_FLAG)
499     {
500         parseDiagnosticInfo(subtree, tvb, &iOffset, "Inner DiagnosticInfo");
501     }
502
503     *pOffset = iOffset;
504 }
505
506 void parseQualifiedName(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
507 {
508     proto_item *ti = proto_tree_add_text(tree, tvb, 0, -1, "%s: QualifiedName", szFieldName);
509     proto_tree *subtree = proto_item_add_subtree(ti, ett_opcua_qualifiedname);
510
511     parseUInt16(subtree, tvb, pOffset, hf_opcua_qualifiedname_id);
512     parseString(subtree, tvb, pOffset, hf_opcua_qualifiedname_name);
513 }
514
515 void parseDataValue(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
516 {
517     proto_item *ti = proto_tree_add_text(tree, tvb, 0, -1, "%s: DataValue", szFieldName);
518     proto_tree *subtree = proto_item_add_subtree(ti, ett_opcua_datavalue);
519     proto_tree *mask_tree;
520     gint    iOffset = *pOffset;
521     guint8  EncodingMask;
522
523     EncodingMask = tvb_get_guint8(tvb, iOffset);
524     ti = proto_tree_add_text(subtree, tvb, 0, -1, "EncodingMask");
525     mask_tree = proto_item_add_subtree(ti, ett_opcua_datavalue);
526     proto_tree_add_item(mask_tree, hf_opcua_datavalue_mask_valueflag,           tvb, iOffset, 1, TRUE);
527     proto_tree_add_item(mask_tree, hf_opcua_datavalue_mask_statuscodeflag,      tvb, iOffset, 1, TRUE);
528     proto_tree_add_item(mask_tree, hf_opcua_datavalue_mask_sourcetimestampflag, tvb, iOffset, 1, TRUE);
529     proto_tree_add_item(mask_tree, hf_opcua_datavalue_mask_servertimestampflag, tvb, iOffset, 1, TRUE);
530     proto_tree_add_item(mask_tree, hf_opcua_datavalue_mask_sourcepicoseconds,   tvb, iOffset, 1, TRUE);
531     proto_tree_add_item(mask_tree, hf_opcua_datavalue_mask_serverpicoseconds,   tvb, iOffset, 1, TRUE);
532     iOffset++;
533
534     if (EncodingMask & DATAVALUE_ENCODINGBYTE_VALUE)
535     {
536         parseVariant(subtree, tvb, &iOffset, "Value");
537     }
538     if (EncodingMask & DATAVALUE_ENCODINGBYTE_STATUSCODE)
539     {
540         parseStatusCode(subtree, tvb, &iOffset, hf_opcua_StatusCode);
541     }
542     if (EncodingMask & DATAVALUE_ENCODINGBYTE_SOURCETIMESTAMP)
543     {
544         parseDateTime(subtree, tvb, &iOffset, hf_opcua_SourceTimestamp);
545     }
546     if (EncodingMask & DATAVALUE_ENCODINGBYTE_SOURCEPICOSECONDS)
547     {
548         parseUInt16(subtree, tvb, &iOffset, hf_opcua_SourcePicoseconds);
549     }
550     if (EncodingMask & DATAVALUE_ENCODINGBYTE_SERVERTIMESTAMP)
551     {
552         parseDateTime(subtree, tvb, &iOffset, hf_opcua_ServerTimestamp);
553     }
554     if (EncodingMask & DATAVALUE_ENCODINGBYTE_SERVERPICOSECONDS)
555     {
556         parseUInt16(subtree, tvb, &iOffset, hf_opcua_ServerPicoseconds);
557     }
558
559     *pOffset = iOffset;
560 }
561
562 void parseVariant(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
563 {
564     proto_item *ti = proto_tree_add_text(tree, tvb, 0, -1, "%s: Variant", szFieldName);
565     proto_tree *subtree = proto_item_add_subtree(ti, ett_opcua_variant);
566     gint    iOffset = *pOffset;
567     guint8  EncodingMask;
568     gint32  ArrayLength;
569
570     EncodingMask = tvb_get_guint8(tvb, iOffset);
571     proto_tree_add_item(subtree, hf_opcua_variant_encodingmask, tvb, iOffset, 1, TRUE);
572     iOffset++;
573     ArrayLength = tvb_get_letohl(tvb, iOffset);
574
575     if (EncodingMask & VARIANT_ARRAYMASK)
576     {
577         /* type is encoded in bits 0-5 */
578         switch(EncodingMask & 0x3f)
579         {
580         case OpcUaType_Null: break;
581         case OpcUaType_Boolean: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Boolean, parseBoolean); break;
582         case OpcUaType_SByte: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_SByte, parseSByte); break;
583         case OpcUaType_Byte: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Byte, parseByte); break;
584         case OpcUaType_Int16: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Int16, parseInt16); break;
585         case OpcUaType_UInt16: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_UInt16, parseUInt16); break;
586         case OpcUaType_Int32: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Int32, parseInt32); break;
587         case OpcUaType_UInt32: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_UInt32, parseUInt32); break;
588         case OpcUaType_Int64: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Int64, parseInt64); break;
589         case OpcUaType_UInt64: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_UInt64, parseUInt64); break;
590         case OpcUaType_Float: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Float, parseFloat); break;
591         case OpcUaType_Double: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Double, parseDouble); break;
592         case OpcUaType_String: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_String, parseString); break;
593         case OpcUaType_DateTime: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_DateTime, parseDateTime); break;
594         case OpcUaType_Guid: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Guid, parseGuid); break;
595         case OpcUaType_ByteString: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_ByteString, parseByteString); break;
596         case OpcUaType_XmlElement: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_XmlElement, parseXmlElement); break;
597         case OpcUaType_NodeId: parseArrayComplex(subtree, tvb, &iOffset, "NodeId", parseNodeId); break;
598         case OpcUaType_ExpandedNodeId: parseArrayComplex(subtree, tvb, &iOffset, "ExpandedNodeId", parseExpandedNodeId); break;
599         case OpcUaType_StatusCode: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_StatusCode, parseStatusCode); break;
600         case OpcUaType_DiagnosticInfo: parseArrayComplex(subtree, tvb, &iOffset, "DiagnosticInfo", parseDiagnosticInfo); break;
601         case OpcUaType_QualifiedName: parseArrayComplex(subtree, tvb, &iOffset, "QualifiedName", parseQualifiedName); break;
602         case OpcUaType_LocalizedText: parseArrayComplex(subtree, tvb, &iOffset, "LocalizedText", parseLocalizedText); break;
603         case OpcUaType_ExtensionObject: parseArrayComplex(subtree, tvb, &iOffset, "ExtensionObject", parseExtensionObject); break;
604         case OpcUaType_DataValue: parseArrayComplex(subtree, tvb, &iOffset, "DataValue", parseDataValue); break;
605         case OpcUaType_Variant: parseArrayComplex(subtree, tvb, &iOffset, "Variant", parseVariant); break;
606         }
607     }
608     else
609     {
610         /* type is encoded in bits 0-5 */
611         switch(EncodingMask & 0x3f)
612         {
613         case OpcUaType_Null: break;
614         case OpcUaType_Boolean: parseBoolean(subtree, tvb, &iOffset, hf_opcua_Boolean); break;
615         case OpcUaType_SByte: parseSByte(subtree, tvb, &iOffset, hf_opcua_SByte); break;
616         case OpcUaType_Byte: parseByte(subtree, tvb, &iOffset, hf_opcua_Byte); break;
617         case OpcUaType_Int16: parseInt16(subtree, tvb, &iOffset, hf_opcua_Int16); break;
618         case OpcUaType_UInt16: parseUInt16(subtree, tvb, &iOffset, hf_opcua_UInt16); break;
619         case OpcUaType_Int32: parseInt32(subtree, tvb, &iOffset, hf_opcua_Int32); break;
620         case OpcUaType_UInt32: parseUInt32(subtree, tvb, &iOffset, hf_opcua_UInt32); break;
621         case OpcUaType_Int64: parseInt64(subtree, tvb, &iOffset, hf_opcua_Int64); break;
622         case OpcUaType_UInt64: parseUInt64(subtree, tvb, &iOffset, hf_opcua_UInt64); break;
623         case OpcUaType_Float: parseFloat(subtree, tvb, &iOffset, hf_opcua_Float); break;
624         case OpcUaType_Double: parseDouble(subtree, tvb, &iOffset, hf_opcua_Double); break;
625         case OpcUaType_String: parseString(subtree, tvb, &iOffset, hf_opcua_String); break;
626         case OpcUaType_DateTime: parseDateTime(subtree, tvb, &iOffset, hf_opcua_DateTime); break;
627         case OpcUaType_Guid: parseGuid(subtree, tvb, &iOffset, hf_opcua_Guid); break;
628         case OpcUaType_ByteString: parseByteString(subtree, tvb, &iOffset, hf_opcua_ByteString); break;
629         case OpcUaType_XmlElement: parseXmlElement(subtree, tvb, &iOffset, hf_opcua_XmlElement); break;
630         case OpcUaType_NodeId: parseNodeId(subtree, tvb, &iOffset, "Value"); break;
631         case OpcUaType_ExpandedNodeId: parseExpandedNodeId(subtree, tvb, &iOffset, "Value"); break;
632         case OpcUaType_StatusCode: parseStatusCode(subtree, tvb, &iOffset, hf_opcua_StatusCode); break;
633         case OpcUaType_DiagnosticInfo: parseDiagnosticInfo(subtree, tvb, &iOffset, "Value"); break;
634         case OpcUaType_QualifiedName: parseQualifiedName(subtree, tvb, &iOffset, "Value"); break;
635         case OpcUaType_LocalizedText: parseLocalizedText(subtree, tvb, &iOffset, "Value"); break;
636         case OpcUaType_ExtensionObject: parseExtensionObject(subtree, tvb, &iOffset, "Value"); break;
637         case OpcUaType_DataValue: parseDataValue(subtree, tvb, &iOffset, "Value"); break;
638         case OpcUaType_Variant: parseVariant(subtree, tvb, &iOffset, "Value"); break;
639         }
640     }
641     
642     if (EncodingMask & VARIANT_ARRAYDIMENSIONS)
643     {
644         proto_item *ti = proto_tree_add_text(tree, tvb, 0, -1, "Array Dimensions");
645         proto_tree *subtree = proto_item_add_subtree(ti, ett_opcua_array);
646         int i;
647
648         for (i=0; i<ArrayLength; i++)
649         {
650             parseInt32(subtree, tvb, pOffset, hf_opcua_Int32);
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     *pOffset += 4;
673
674     if (iLen == -1) return; /* no array */
675     if (iLen == 0)  return; /* array with zero elements*/
676
677     for (i=0; i<iLen; i++)
678     {
679         (*pParserFunction)(subtree, tvb, pOffset, hfIndex);
680     }
681 }
682
683 /** General parsing function for arrays of enums.
684  * All arrays have one 4 byte signed integer length information,
685  * followed by n data elements.
686  */
687 void parseArrayEnum(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, fctEnumParser pParserFunction)
688 {
689     char szFieldName[] = "Array of Enum Type";
690     proto_item *ti = proto_tree_add_text(tree, tvb, 0, -1, "%s", szFieldName);
691     proto_tree *subtree = proto_item_add_subtree(ti, ett_opcua_array);
692     int i;
693     gint32 iLen;
694
695     /* read array length */
696     iLen = tvb_get_letohl(tvb, *pOffset);
697     proto_tree_add_item(subtree, hf_opcua_ArraySize, tvb, *pOffset, 4, TRUE);
698     *pOffset += 4;
699
700     if (iLen == -1) return; /* no array */
701     if (iLen == 0)  return; /* array with zero elements*/
702
703     for (i=0; i<iLen; i++)
704     {
705         (*pParserFunction)(subtree, tvb, pOffset);
706     }
707 }
708
709 /** General parsing function for arrays of complex types.
710  * All arrays have one 4 byte signed integer length information,
711  * followed by n data elements.
712  */
713 void parseArrayComplex(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName, fctComplexTypeParser pParserFunction)
714 {
715     proto_item *ti = proto_tree_add_text(tree, tvb, 0, -1, "Array of %s", szFieldName);
716     proto_tree *subtree = proto_item_add_subtree(ti, ett_opcua_array);
717     int i;
718     gint32 iLen;
719
720     /* read array length */
721     iLen = tvb_get_letohl(tvb, *pOffset);
722     proto_tree_add_item(subtree, hf_opcua_ArraySize, tvb, *pOffset, 4, TRUE);
723     *pOffset += 4;
724
725     if (iLen == -1) return; /* no array */
726     if (iLen == 0)  return; /* array with zero elements*/
727
728     for (i=0; i<iLen; i++)
729     {
730         char szNum[20];
731         g_snprintf(szNum, 20, "[%i]", i);
732         (*pParserFunction)(subtree, tvb, pOffset, szNum);
733     }
734 }
735
736 void parseNodeId(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
737 {
738     proto_item *ti = proto_tree_add_text(tree, tvb, 0, -1, "%s: NodeId", szFieldName);
739     proto_tree *subtree = proto_item_add_subtree(ti, ett_opcua_nodeid);
740     gint    iOffset = *pOffset;
741     guint8  EncodingMask;
742
743     EncodingMask = tvb_get_guint8(tvb, iOffset);
744     proto_tree_add_item(subtree, hf_opcua_nodeid_encodingmask, tvb, iOffset, 1, TRUE);
745     iOffset++;
746
747     switch(EncodingMask)
748     {
749     case 0x00: /* two byte node id */
750         proto_tree_add_item(subtree, hf_opcua_nodeid_numeric, tvb, iOffset, 1, TRUE);
751         iOffset+=1;
752         break;
753     case 0x01: /* four byte node id */
754         proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 1, TRUE);
755         iOffset+=1;
756         proto_tree_add_item(subtree, hf_opcua_nodeid_numeric, tvb, iOffset, 2, TRUE);
757         iOffset+=2;
758         break;
759     case 0x02: /* numeric, that does not fit into four bytes */
760         proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 2, TRUE);
761         iOffset+=2;
762         proto_tree_add_item(subtree, hf_opcua_nodeid_numeric, tvb, iOffset, 4, TRUE);
763         iOffset+=4;
764         break;
765     case 0x03: /* string */
766         proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 2, TRUE);
767         iOffset+=2;
768         parseString(subtree, tvb, &iOffset, hf_opcua_String);
769         break;
770     case 0x04: /* guid */
771         proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 2, TRUE);
772         iOffset+=2;
773         parseGuid(subtree, tvb, &iOffset, hf_opcua_Guid);
774         break;
775     case 0x05: /* byte string */
776         proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 4, TRUE);
777         iOffset+=4;
778         parseByteString(subtree, tvb, &iOffset, hf_opcua_ByteString);
779         break;
780     };
781
782     *pOffset = iOffset;
783 }
784
785 void parseExtensionObject(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
786 {
787     gint    iOffset = *pOffset;
788     guint8  EncodingMask;
789     proto_tree *extobj_tree;
790     proto_tree *mask_tree;
791     proto_item *ti;
792
793     /* add extension object subtree */
794     ti = proto_tree_add_text(tree, tvb, 0, -1, "%s : ExtensionObject", szFieldName);
795     extobj_tree = proto_item_add_subtree(ti, ett_opcua_extensionobject);
796
797     /* add nodeid subtree */
798     parseExpandedNodeId(extobj_tree, tvb, &iOffset, "TypeId");
799
800     /* parse encoding mask */
801     EncodingMask = tvb_get_guint8(tvb, iOffset);
802     ti = proto_tree_add_text(extobj_tree, tvb, 0, -1, "EncodingMask");
803     mask_tree = proto_item_add_subtree(ti, ett_opcua_extobj_encodingmask);
804     proto_tree_add_item(mask_tree, hf_opcua_extobj_mask_binbodyflag, tvb, iOffset, 1, TRUE);
805     proto_tree_add_item(mask_tree, hf_opcua_extobj_mask_xmlbodyflag, tvb, iOffset, 1, TRUE);
806     iOffset++;
807
808     if (EncodingMask & EXTOBJ_ENCODINGMASK_BINBODY_FLAG) /* has binary body ? */
809     {
810         parseByteString(extobj_tree, tvb, &iOffset, hf_opcua_ByteString);
811     }
812
813     *pOffset = iOffset;
814 }
815
816 void parseExpandedNodeId(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
817 {
818     proto_item *ti = proto_tree_add_text(tree, tvb, 0, -1, "%s: ExpandedNodeId", szFieldName);
819     proto_tree *subtree = proto_item_add_subtree(ti, ett_opcua_nodeid);
820     gint    iOffset = *pOffset;
821     guint8  EncodingMask;
822
823     EncodingMask = tvb_get_guint8(tvb, iOffset);
824     proto_tree_add_item(subtree, hf_opcua_nodeid_encodingmask, tvb, iOffset, 1, TRUE);
825     iOffset++;
826
827     switch(EncodingMask)
828     {
829     case 0x00: /* two byte node id */
830         proto_tree_add_item(subtree, hf_opcua_nodeid_numeric, tvb, iOffset, 1, TRUE);
831         iOffset+=1;
832         break;
833     case 0x01: /* four byte node id */
834         proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 1, TRUE);
835         iOffset+=1;
836         proto_tree_add_item(subtree, hf_opcua_nodeid_numeric, tvb, iOffset, 2, TRUE);
837         iOffset+=2;
838         break;
839     case 0x02: /* numeric, that does not fit into four bytes */
840         proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 2, TRUE);
841         iOffset+=2;
842         proto_tree_add_item(subtree, hf_opcua_nodeid_numeric, tvb, iOffset, 4, TRUE);
843         iOffset+=4;
844         break;
845     case 0x03: /* string */
846         proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 2, TRUE);
847         iOffset+=2;
848         parseString(subtree, tvb, &iOffset, hf_opcua_String);
849         break;
850     case 0x04: /* guid */
851         proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 2, TRUE);
852         iOffset+=2;
853         parseGuid(subtree, tvb, &iOffset, hf_opcua_Guid);
854         break;
855     case 0x05: /* byte string */
856         proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 2, TRUE);
857         iOffset+=2;
858         parseByteString(subtree, tvb, &iOffset, hf_opcua_ByteString);
859         break;
860     };
861
862     if (EncodingMask & NODEID_URIMASK)
863     {
864         parseString(subtree, tvb, &iOffset, hf_opcua_Uri);
865     }
866     if (EncodingMask & NODEID_SERVERINDEXFLAG)
867     {
868         parseUInt32(subtree, tvb, &iOffset, hf_opcua_ServerIndex);
869     }
870
871     *pOffset = iOffset;
872 }