1 /******************************************************************************
4 ** Copyright (C) 2006-2007 ascolab GmbH. All Rights Reserved.
5 ** Web: http://www.ascolab.com
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.
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.
15 ** Project: OpcUa Wireshark Plugin
17 ** Description: Implementation of OpcUa built-in type parsers.
18 ** This contains all the simple types and some complex types.
20 ** Author: Gerhard Gappmeier <gerhard.gappmeier@ascolab.com>
21 ** Last change by: $Author: gergap $
23 ******************************************************************************/
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 "opcua_extensionobjectids.h"
35 #include <epan/emem.h>
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
56 /* Chosen arbitrarily */
57 #define MAX_ARRAY_LEN 10000
59 void dispatchExtensionObjectType(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int TypeId);
61 static int hf_opcua_diag_mask_symbolicflag = -1;
62 static int hf_opcua_diag_mask_namespaceflag = -1;
63 static int hf_opcua_diag_mask_localizedtextflag = -1;
64 static int hf_opcua_diag_mask_additionalinfoflag = -1;
65 static int hf_opcua_diag_mask_innerstatuscodeflag = -1;
66 static int hf_opcua_diag_mask_innerdiaginfoflag = -1;
67 static int hf_opcua_loctext_mask_localeflag = -1;
68 static int hf_opcua_loctext_mask_textflag = -1;
69 static int hf_opcua_datavalue_mask_valueflag = -1;
70 static int hf_opcua_datavalue_mask_statuscodeflag = -1;
71 static int hf_opcua_datavalue_mask_sourcetimestampflag = -1;
72 static int hf_opcua_datavalue_mask_servertimestampflag = -1;
73 static int hf_opcua_datavalue_mask_sourcepicoseconds = -1;
74 static int hf_opcua_datavalue_mask_serverpicoseconds = -1;
75 static int hf_opcua_nodeid_encodingmask = -1;
76 static int hf_opcua_variant_encodingmask = -1;
77 static int hf_opcua_nodeid_nsid = -1;
78 static int hf_opcua_nodeid_numeric = -1;
79 static int hf_opcua_localizedtext_locale = -1;
80 static int hf_opcua_localizedtext_text = -1;
81 static int hf_opcua_qualifiedname_id = -1;
82 static int hf_opcua_qualifiedname_name = -1;
83 static int hf_opcua_SourceTimestamp = -1;
84 static int hf_opcua_SourcePicoseconds = -1;
85 static int hf_opcua_ServerTimestamp = -1;
86 static int hf_opcua_ServerPicoseconds = -1;
87 static int hf_opcua_diag_symbolicid = -1;
88 static int hf_opcua_diag_namespace = -1;
89 static int hf_opcua_diag_localizedtext = -1;
90 static int hf_opcua_diag_additionalinfo = -1;
91 static int hf_opcua_diag_innerstatuscode = -1;
92 static int hf_opcua_extobj_mask_binbodyflag = -1;
93 static int hf_opcua_extobj_mask_xmlbodyflag = -1;
94 static int hf_opcua_ArraySize = -1;
95 static int hf_opcua_Uri = -1;
96 static int hf_opcua_ServerIndex = -1;
98 /** NodeId encoding mask table */
99 static const value_string g_nodeidmasks[] = {
100 { 0, "Two byte encoded Numeric" },
101 { 1, "Four byte encoded Numeric" },
102 { 2, "Numeric of arbitrary length" },
111 /** UA Variant Type enum */
112 typedef enum _OpcUa_BuiltInType
115 OpcUaType_Boolean = 1,
119 OpcUaType_UInt16 = 5,
121 OpcUaType_UInt32 = 7,
123 OpcUaType_UInt64 = 9,
124 OpcUaType_Float = 10,
125 OpcUaType_Double = 11,
126 OpcUaType_String = 12,
127 OpcUaType_DateTime = 13,
129 OpcUaType_ByteString = 15,
130 OpcUaType_XmlElement = 16,
131 OpcUaType_NodeId = 17,
132 OpcUaType_ExpandedNodeId = 18,
133 OpcUaType_StatusCode = 19,
134 OpcUaType_QualifiedName = 20,
135 OpcUaType_LocalizedText = 21,
136 OpcUaType_ExtensionObject = 22,
137 OpcUaType_DataValue = 23,
138 OpcUaType_Variant = 24,
139 OpcUaType_DiagnosticInfo = 25
143 /** Variant encoding mask table */
144 static const value_string g_VariantTypes[] = {
160 { 15, "ByteString" },
161 { 16, "XmlElement" },
163 { 18, "ExpandedNodeId" },
164 { 19, "StatusCode" },
165 { 20, "QualifiedName" },
166 { 21, "LocalizedText" },
167 { 22, "ExtensionObject" },
170 { 25, "DiagnosticInfo" },
171 { 0x80, "Array of Null" },
172 { 0x80+1, "Array of Boolean" },
173 { 0x80+2, "Array of SByte" },
174 { 0x80+3, "Array of Byte" },
175 { 0x80+4, "Array of Int16" },
176 { 0x80+5, "Array of UInt16" },
177 { 0x80+6, "Array of Int32" },
178 { 0x80+7, "Array of UInt32" },
179 { 0x80+8, "Array of Int64" },
180 { 0x80+9, "Array of UInt64" },
181 { 0x80+10, "Array of Float" },
182 { 0x80+11, "Array of Double" },
183 { 0x80+12, "Array of String" },
184 { 0x80+13, "Array of DateTime" },
185 { 0x80+14, "Array of Guid" },
186 { 0x80+15, "Array of ByteString" },
187 { 0x80+16, "Array of XmlElement" },
188 { 0x80+17, "Array of NodeId" },
189 { 0x80+18, "Array of ExpandedNodeId" },
190 { 0x80+19, "Array of StatusCode" },
191 { 0x80+20, "Array of QualifiedName" },
192 { 0x80+21, "Array of LocalizedText" },
193 { 0x80+22, "Array of ExtensionObject" },
194 { 0x80+23, "Array of DataValue" },
195 { 0x80+24, "Array of Variant" },
196 { 0x80+25, "Array of DiagnosticInfo" },
199 #define VARIANT_ARRAYDIMENSIONS 0x40
200 #define VARIANT_ARRAYMASK 0x80
203 static gint ett_opcua_array = -1;
204 static gint ett_opcua_diagnosticinfo = -1;
205 static gint ett_opcua_nodeid = -1;
206 static gint ett_opcua_localeid = -1;
207 static gint ett_opcua_localizedtext = -1;
208 static gint ett_opcua_qualifiedname = -1;
209 static gint ett_opcua_datavalue = -1;
210 static gint ett_opcua_variant = -1;
211 static gint ett_opcua_extensionobject = -1;
212 static gint ett_opcua_extobj_encodingmask = -1;
216 &ett_opcua_diagnosticinfo,
219 &ett_opcua_localizedtext,
220 &ett_opcua_qualifiedname,
221 &ett_opcua_datavalue,
223 &ett_opcua_extensionobject,
224 &ett_opcua_extobj_encodingmask
227 void registerSimpleTypes(int proto)
229 static hf_register_info hf[] =
231 /* full name , abbreviation , type , display , strings, bitmask, blurb, id, parent, ref_count, bitshift */
232 { &hf_opcua_diag_mask_symbolicflag,
233 { "has symbolic id", "opcua.has_symbolic_id", FT_BOOLEAN, 8, NULL, DIAGNOSTICINFO_ENCODINGMASK_SYMBOLICID_FLAG, NULL, HFILL }
235 { &hf_opcua_diag_mask_namespaceflag,
236 { "has namespace", "opcua.has_namespace", FT_BOOLEAN, 8, NULL, DIAGNOSTICINFO_ENCODINGMASK_NAMESPACE_FLAG, NULL, HFILL }
238 { &hf_opcua_diag_mask_localizedtextflag,
239 { "has localizedtext", "opcua.has_localizedtext", FT_BOOLEAN, 8, NULL, DIAGNOSTICINFO_ENCODINGMASK_LOCALIZEDTEXT_FLAG, NULL, HFILL }
241 { &hf_opcua_diag_mask_additionalinfoflag,
242 { "has additional info", "opcua.has_additional_info", FT_BOOLEAN, 8, NULL, DIAGNOSTICINFO_ENCODINGMASK_ADDITIONALINFO_FLAG, NULL, HFILL }
244 { &hf_opcua_diag_mask_innerstatuscodeflag,
245 { "has inner statuscode", "opcua.has_inner_statuscode", FT_BOOLEAN, 8, NULL, DIAGNOSTICINFO_ENCODINGMASK_INNERSTATUSCODE_FLAG, NULL, HFILL }
247 { &hf_opcua_diag_mask_innerdiaginfoflag,
248 { "has inner diagnostic info", "opcua.has_inner_diagnostic_code", FT_BOOLEAN, 8, NULL, DIAGNOSTICINFO_ENCODINGMASK_INNERDIAGNOSTICINFO_FLAG, NULL, HFILL }
250 { &hf_opcua_loctext_mask_localeflag,
251 { "has locale information", "opcua.has_locale_information", FT_BOOLEAN, 8, NULL, LOCALIZEDTEXT_ENCODINGBYTE_LOCALE, NULL, HFILL }
253 { &hf_opcua_loctext_mask_textflag,
254 { "has text", "opcua.has_text", FT_BOOLEAN, 8, NULL, LOCALIZEDTEXT_ENCODINGBYTE_TEXT, NULL, HFILL }
256 { &hf_opcua_nodeid_encodingmask,
257 { "NodeId EncodingMask", "application.nodeid.encodingmask", FT_UINT8, BASE_HEX, VALS(g_nodeidmasks), 0x0, NULL, HFILL }
259 { &hf_opcua_nodeid_nsid,
260 { "NodeId Namespace Id", "application.nodeid.nsid", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
262 { &hf_opcua_nodeid_numeric,
263 { "NodeId Identifier Numeric", "application.nodeid.numeric", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
265 { &hf_opcua_localizedtext_locale, { "Locale", "opcua.Locale", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } },
266 { &hf_opcua_localizedtext_text, { "Text", "opcua.Text", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } },
267 { &hf_opcua_qualifiedname_id, { "Id", "opcua.Id", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
268 { &hf_opcua_qualifiedname_name, { "Name", "opcua.Name", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } },
269 { &hf_opcua_datavalue_mask_valueflag, { "has value", "opcua.has_value", FT_BOOLEAN, 8, NULL, DATAVALUE_ENCODINGBYTE_VALUE, NULL, HFILL } },
270 { &hf_opcua_datavalue_mask_statuscodeflag, { "has statuscode", "opcua.has_statuscode", FT_BOOLEAN, 8, NULL, DATAVALUE_ENCODINGBYTE_STATUSCODE, NULL, HFILL } },
271 { &hf_opcua_datavalue_mask_sourcetimestampflag, { "has source timestamp", "opcua.has_source_timestamp", FT_BOOLEAN, 8, NULL, DATAVALUE_ENCODINGBYTE_SOURCETIMESTAMP, NULL, HFILL } },
272 { &hf_opcua_datavalue_mask_servertimestampflag, { "has server timestamp", "opcua.has_server_timestamp", FT_BOOLEAN, 8, NULL, DATAVALUE_ENCODINGBYTE_SERVERTIMESTAMP, NULL, HFILL } },
273 { &hf_opcua_datavalue_mask_sourcepicoseconds, { "has source picoseconds", "opcua.has_source_picoseconds", FT_BOOLEAN, 8, NULL, DATAVALUE_ENCODINGBYTE_SOURCEPICOSECONDS, NULL, HFILL } },
274 { &hf_opcua_datavalue_mask_serverpicoseconds, { "has server picoseconds", "opcua.has_server_picoseconds", FT_BOOLEAN, 8, NULL, DATAVALUE_ENCODINGBYTE_SERVERPICOSECONDS, NULL, HFILL } },
275 { &hf_opcua_variant_encodingmask, { "Variant Type", "opcua.has_value", FT_UINT8, BASE_HEX, VALS(g_VariantTypes), 0x0, NULL, HFILL } },
276 { &hf_opcua_SourceTimestamp, { "SourceTimestamp", "opcua.SourceTimestamp", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0x0, NULL, HFILL } },
277 { &hf_opcua_SourcePicoseconds, { "SourcePicoseconds", "opcua.SourcePicoseconds", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
278 { &hf_opcua_ServerTimestamp, { "ServerTimestamp", "opcua.ServerTimestamp", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0x0, NULL, HFILL } },
279 { &hf_opcua_ServerPicoseconds, { "ServerPicoseconds", "opcua.ServerPicoseconds", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
280 { &hf_opcua_diag_symbolicid, { "SymbolicId", "opcua.SymbolicId", FT_INT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
281 { &hf_opcua_diag_namespace, { "Namespace", "opcua.Namespace", FT_INT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
282 { &hf_opcua_diag_localizedtext, { "LocaliezdText", "opcua.LocaliezdText", FT_INT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
283 { &hf_opcua_diag_additionalinfo, { "AdditionalInfo", "opcua.AdditionalInfo", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } },
284 { &hf_opcua_diag_innerstatuscode, { "InnerStatusCode", "opcua.InnerStatusCode", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL } },
285 { &hf_opcua_extobj_mask_binbodyflag, { "has binary body", "opcua.has_binary_body", FT_BOOLEAN, 8, NULL, EXTOBJ_ENCODINGMASK_BINBODY_FLAG, NULL, HFILL } },
286 { &hf_opcua_extobj_mask_xmlbodyflag, { "has xml body", "opcua.has_xml_body", FT_BOOLEAN, 8, NULL, EXTOBJ_ENCODINGMASK_XMLBODY_FLAG, NULL, HFILL } },
287 { &hf_opcua_ArraySize, { "ArraySize", "opcua.ArraySize", FT_INT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
288 { &hf_opcua_Uri, { "Uri", "opcua.Uri", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } },
289 { &hf_opcua_ServerIndex, { "ServerIndex", "opcua.ServerIndex", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } }
292 proto_register_field_array(proto, hf, array_length(hf));
293 proto_register_subtree_array(ett, array_length(ett));
296 void parseBoolean(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
298 proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 1, TRUE); *pOffset+=1;
301 void parseByte(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
303 proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 1, TRUE); *pOffset+=1;
306 void parseSByte(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
308 proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 1, TRUE); *pOffset+=1;
311 void parseUInt16(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
313 proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 2, TRUE); *pOffset+=2;
316 void parseInt16(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
318 proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 2, TRUE); *pOffset+=2;
321 void parseUInt32(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
323 proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 4, TRUE); *pOffset+=4;
326 void parseInt32(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
328 proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 4, TRUE); *pOffset+=4;
331 void parseUInt64(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
333 proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 8, TRUE); *pOffset+=8;
336 void parseInt64(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
338 proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 8, TRUE); *pOffset+=8;
341 void parseString(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
344 gint iOffset = *pOffset;
345 gint32 iLen = tvb_get_letohl(tvb, *pOffset);
350 proto_item *item = proto_tree_add_item(tree, hfIndex, tvb, iOffset, 0, TRUE);
351 proto_item_append_text(item, "[OpcUa Null String]");
355 proto_item *item = proto_tree_add_item(tree, hfIndex, tvb, iOffset, 0, TRUE);
356 proto_item_append_text(item, "[OpcUa Empty String]");
360 proto_tree_add_item(tree, hfIndex, tvb, iOffset, iLen, TRUE);
361 iOffset += iLen; /* eat the whole string */
365 proto_item *item = proto_tree_add_item(tree, hfIndex, tvb, iOffset, 0, TRUE);
366 szValue = ep_strdup_printf("[Invalid String] Invalid length: %d", iLen);
367 proto_item_append_text(item, "%s", szValue);
373 void parseStatusCode(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
375 proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 4, TRUE);
379 void parseLocalizedText(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
381 gint iOffset = *pOffset;
383 proto_tree *mask_tree;
387 ti = proto_tree_add_text(tree, tvb, 0, -1, "%s: LocalizedText", szFieldName);
388 subtree = proto_item_add_subtree(ti, ett_opcua_localizedtext);
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, ENC_LITTLE_ENDIAN);
395 proto_tree_add_item(mask_tree, hf_opcua_loctext_mask_textflag, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
398 if (EncodingMask & LOCALIZEDTEXT_ENCODINGBYTE_LOCALE)
400 parseString(subtree, tvb, &iOffset, hf_opcua_localizedtext_locale);
403 if (EncodingMask & LOCALIZEDTEXT_ENCODINGBYTE_TEXT)
405 parseString(subtree, tvb, &iOffset, hf_opcua_localizedtext_text);
411 void parseGuid(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
413 proto_tree_add_item(tree, hfIndex, tvb, *pOffset, GUID_LEN, TRUE); *pOffset+=GUID_LEN;
416 void parseByteString(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
419 int iOffset = *pOffset;
420 gint32 iLen = tvb_get_letohl(tvb, iOffset);
425 proto_item *item = proto_tree_add_item(tree, hfIndex, tvb, iOffset, 0, TRUE);
426 proto_item_append_text(item, "[OpcUa Null ByteString]");
430 proto_item *item = proto_tree_add_item(tree, hfIndex, tvb, iOffset, 0, TRUE);
431 proto_item_append_text(item, "[OpcUa Empty ByteString]");
435 proto_tree_add_item(tree, hfIndex, tvb, iOffset, iLen, TRUE);
436 iOffset += iLen; /* eat the whole bytestring */
440 proto_item *item = proto_tree_add_item(tree, hfIndex, tvb, iOffset, 0, TRUE);
441 szValue = ep_strdup_printf("[Invalid ByteString] Invalid length: %d", iLen);
442 proto_item_append_text(item, "%s", szValue);
448 void parseXmlElement(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
450 parseByteString(tree, tvb, pOffset, hfIndex);
453 void parseFloat(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
455 proto_tree_add_item(tree, hfIndex, tvb, *pOffset, sizeof(gfloat), TRUE);
456 *pOffset += sizeof(gfloat);
459 void parseDouble(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
461 proto_tree_add_item(tree, hfIndex, tvb, *pOffset, sizeof(gdouble), TRUE);
462 *pOffset += sizeof(gdouble);
465 void parseDateTime(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
467 *pOffset = dissect_nt_64bit_time(tvb, tree, *pOffset, hfIndex);
470 void parseDiagnosticInfo(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
472 gint iOffset = *pOffset;
474 proto_tree *mask_tree;
478 ti = proto_tree_add_text(tree, tvb, 0, -1, "%s: DiagnosticInfo", szFieldName);
479 subtree = proto_item_add_subtree(ti, ett_opcua_diagnosticinfo);
481 /* parse encoding mask */
482 EncodingMask = tvb_get_guint8(tvb, iOffset);
483 ti = proto_tree_add_text(subtree, tvb, 0, -1, "EncodingMask");
484 mask_tree = proto_item_add_subtree(ti, ett_opcua_diagnosticinfo);
485 proto_tree_add_item(mask_tree, hf_opcua_diag_mask_symbolicflag, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
486 proto_tree_add_item(mask_tree, hf_opcua_diag_mask_namespaceflag, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
487 proto_tree_add_item(mask_tree, hf_opcua_diag_mask_localizedtextflag, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
488 proto_tree_add_item(mask_tree, hf_opcua_diag_mask_additionalinfoflag, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
489 proto_tree_add_item(mask_tree, hf_opcua_diag_mask_innerstatuscodeflag, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
490 proto_tree_add_item(mask_tree, hf_opcua_diag_mask_innerdiaginfoflag, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
493 if (EncodingMask & DIAGNOSTICINFO_ENCODINGMASK_SYMBOLICID_FLAG)
495 parseInt32(subtree, tvb, &iOffset, hf_opcua_diag_symbolicid);
497 if (EncodingMask & DIAGNOSTICINFO_ENCODINGMASK_NAMESPACE_FLAG)
499 parseInt32(subtree, tvb, &iOffset, hf_opcua_diag_namespace);
501 if (EncodingMask & DIAGNOSTICINFO_ENCODINGMASK_LOCALIZEDTEXT_FLAG)
503 parseInt32(subtree, tvb, &iOffset, hf_opcua_diag_localizedtext);
505 if (EncodingMask & DIAGNOSTICINFO_ENCODINGMASK_ADDITIONALINFO_FLAG)
507 parseString(subtree, tvb, &iOffset, hf_opcua_diag_additionalinfo);
509 if (EncodingMask & DIAGNOSTICINFO_ENCODINGMASK_INNERSTATUSCODE_FLAG)
511 parseStatusCode(subtree, tvb, &iOffset, hf_opcua_diag_innerstatuscode);
513 if (EncodingMask & DIAGNOSTICINFO_ENCODINGMASK_INNERDIAGNOSTICINFO_FLAG)
515 parseDiagnosticInfo(subtree, tvb, &iOffset, "Inner DiagnosticInfo");
521 void parseQualifiedName(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
523 proto_item *ti = proto_tree_add_text(tree, tvb, 0, -1, "%s: QualifiedName", szFieldName);
524 proto_tree *subtree = proto_item_add_subtree(ti, ett_opcua_qualifiedname);
526 parseUInt16(subtree, tvb, pOffset, hf_opcua_qualifiedname_id);
527 parseString(subtree, tvb, pOffset, hf_opcua_qualifiedname_name);
530 void parseDataValue(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
532 proto_item *ti = proto_tree_add_text(tree, tvb, 0, -1, "%s: DataValue", szFieldName);
533 proto_tree *subtree = proto_item_add_subtree(ti, ett_opcua_datavalue);
534 proto_tree *mask_tree;
535 gint iOffset = *pOffset;
538 EncodingMask = tvb_get_guint8(tvb, iOffset);
539 ti = proto_tree_add_text(subtree, tvb, 0, -1, "EncodingMask");
540 mask_tree = proto_item_add_subtree(ti, ett_opcua_datavalue);
541 proto_tree_add_item(mask_tree, hf_opcua_datavalue_mask_valueflag, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
542 proto_tree_add_item(mask_tree, hf_opcua_datavalue_mask_statuscodeflag, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
543 proto_tree_add_item(mask_tree, hf_opcua_datavalue_mask_sourcetimestampflag, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
544 proto_tree_add_item(mask_tree, hf_opcua_datavalue_mask_servertimestampflag, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
545 proto_tree_add_item(mask_tree, hf_opcua_datavalue_mask_sourcepicoseconds, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
546 proto_tree_add_item(mask_tree, hf_opcua_datavalue_mask_serverpicoseconds, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
549 if (EncodingMask & DATAVALUE_ENCODINGBYTE_VALUE)
551 parseVariant(subtree, tvb, &iOffset, "Value");
553 if (EncodingMask & DATAVALUE_ENCODINGBYTE_STATUSCODE)
555 parseStatusCode(subtree, tvb, &iOffset, hf_opcua_StatusCode);
557 if (EncodingMask & DATAVALUE_ENCODINGBYTE_SOURCETIMESTAMP)
559 parseDateTime(subtree, tvb, &iOffset, hf_opcua_SourceTimestamp);
561 if (EncodingMask & DATAVALUE_ENCODINGBYTE_SOURCEPICOSECONDS)
563 parseUInt16(subtree, tvb, &iOffset, hf_opcua_SourcePicoseconds);
565 if (EncodingMask & DATAVALUE_ENCODINGBYTE_SERVERTIMESTAMP)
567 parseDateTime(subtree, tvb, &iOffset, hf_opcua_ServerTimestamp);
569 if (EncodingMask & DATAVALUE_ENCODINGBYTE_SERVERPICOSECONDS)
571 parseUInt16(subtree, tvb, &iOffset, hf_opcua_ServerPicoseconds);
577 void parseVariant(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
579 proto_item *ti = proto_tree_add_text(tree, tvb, 0, -1, "%s: Variant", szFieldName);
580 proto_tree *subtree = proto_item_add_subtree(ti, ett_opcua_variant);
581 gint iOffset = *pOffset;
583 gint32 ArrayLength = 0;
585 EncodingMask = tvb_get_guint8(tvb, iOffset);
586 proto_tree_add_item(subtree, hf_opcua_variant_encodingmask, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
589 if (EncodingMask & VARIANT_ARRAYMASK)
591 ArrayLength = tvb_get_letohl(tvb, iOffset);
593 /* type is encoded in bits 0-5 */
594 switch(EncodingMask & 0x3f)
596 case OpcUaType_Null: break;
597 case OpcUaType_Boolean: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Boolean, parseBoolean); break;
598 case OpcUaType_SByte: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_SByte, parseSByte); break;
599 case OpcUaType_Byte: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Byte, parseByte); break;
600 case OpcUaType_Int16: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Int16, parseInt16); break;
601 case OpcUaType_UInt16: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_UInt16, parseUInt16); break;
602 case OpcUaType_Int32: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Int32, parseInt32); break;
603 case OpcUaType_UInt32: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_UInt32, parseUInt32); break;
604 case OpcUaType_Int64: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Int64, parseInt64); break;
605 case OpcUaType_UInt64: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_UInt64, parseUInt64); break;
606 case OpcUaType_Float: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Float, parseFloat); break;
607 case OpcUaType_Double: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Double, parseDouble); break;
608 case OpcUaType_String: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_String, parseString); break;
609 case OpcUaType_DateTime: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_DateTime, parseDateTime); break;
610 case OpcUaType_Guid: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_Guid, parseGuid); break;
611 case OpcUaType_ByteString: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_ByteString, parseByteString); break;
612 case OpcUaType_XmlElement: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_XmlElement, parseXmlElement); break;
613 case OpcUaType_NodeId: parseArrayComplex(subtree, tvb, &iOffset, "NodeId", parseNodeId); break;
614 case OpcUaType_ExpandedNodeId: parseArrayComplex(subtree, tvb, &iOffset, "ExpandedNodeId", parseExpandedNodeId); break;
615 case OpcUaType_StatusCode: parseArraySimple(subtree, tvb, &iOffset, hf_opcua_StatusCode, parseStatusCode); break;
616 case OpcUaType_DiagnosticInfo: parseArrayComplex(subtree, tvb, &iOffset, "DiagnosticInfo", parseDiagnosticInfo); break;
617 case OpcUaType_QualifiedName: parseArrayComplex(subtree, tvb, &iOffset, "QualifiedName", parseQualifiedName); break;
618 case OpcUaType_LocalizedText: parseArrayComplex(subtree, tvb, &iOffset, "LocalizedText", parseLocalizedText); break;
619 case OpcUaType_ExtensionObject: parseArrayComplex(subtree, tvb, &iOffset, "ExtensionObject", parseExtensionObject); break;
620 case OpcUaType_DataValue: parseArrayComplex(subtree, tvb, &iOffset, "DataValue", parseDataValue); break;
621 case OpcUaType_Variant: parseArrayComplex(subtree, tvb, &iOffset, "Variant", parseVariant); break;
624 if (EncodingMask & VARIANT_ARRAYDIMENSIONS)
626 proto_item *ti_2 = proto_tree_add_text(tree, tvb, 0, -1, "Array Dimensions");
627 proto_tree *subtree_2 = proto_item_add_subtree(ti_2, ett_opcua_array);
630 if (ArrayLength < MAX_ARRAY_LEN)
632 for (i=0; i<ArrayLength; i++)
634 parseInt32(subtree_2, tvb, pOffset, hf_opcua_Int32);
640 /* XXX - This should be expert_add_info_format, but we need pinfo for that */
641 pi = proto_tree_add_text(tree, tvb, iOffset, 4, "Array length %d too large to process", ArrayLength);
642 PROTO_ITEM_SET_GENERATED(pi);
648 /* type is encoded in bits 0-5 */
649 switch(EncodingMask & 0x3f)
651 case OpcUaType_Null: break;
652 case OpcUaType_Boolean: parseBoolean(subtree, tvb, &iOffset, hf_opcua_Boolean); break;
653 case OpcUaType_SByte: parseSByte(subtree, tvb, &iOffset, hf_opcua_SByte); break;
654 case OpcUaType_Byte: parseByte(subtree, tvb, &iOffset, hf_opcua_Byte); break;
655 case OpcUaType_Int16: parseInt16(subtree, tvb, &iOffset, hf_opcua_Int16); break;
656 case OpcUaType_UInt16: parseUInt16(subtree, tvb, &iOffset, hf_opcua_UInt16); break;
657 case OpcUaType_Int32: parseInt32(subtree, tvb, &iOffset, hf_opcua_Int32); break;
658 case OpcUaType_UInt32: parseUInt32(subtree, tvb, &iOffset, hf_opcua_UInt32); break;
659 case OpcUaType_Int64: parseInt64(subtree, tvb, &iOffset, hf_opcua_Int64); break;
660 case OpcUaType_UInt64: parseUInt64(subtree, tvb, &iOffset, hf_opcua_UInt64); break;
661 case OpcUaType_Float: parseFloat(subtree, tvb, &iOffset, hf_opcua_Float); break;
662 case OpcUaType_Double: parseDouble(subtree, tvb, &iOffset, hf_opcua_Double); break;
663 case OpcUaType_String: parseString(subtree, tvb, &iOffset, hf_opcua_String); break;
664 case OpcUaType_DateTime: parseDateTime(subtree, tvb, &iOffset, hf_opcua_DateTime); break;
665 case OpcUaType_Guid: parseGuid(subtree, tvb, &iOffset, hf_opcua_Guid); break;
666 case OpcUaType_ByteString: parseByteString(subtree, tvb, &iOffset, hf_opcua_ByteString); break;
667 case OpcUaType_XmlElement: parseXmlElement(subtree, tvb, &iOffset, hf_opcua_XmlElement); break;
668 case OpcUaType_NodeId: parseNodeId(subtree, tvb, &iOffset, "Value"); break;
669 case OpcUaType_ExpandedNodeId: parseExpandedNodeId(subtree, tvb, &iOffset, "Value"); break;
670 case OpcUaType_StatusCode: parseStatusCode(subtree, tvb, &iOffset, hf_opcua_StatusCode); break;
671 case OpcUaType_DiagnosticInfo: parseDiagnosticInfo(subtree, tvb, &iOffset, "Value"); break;
672 case OpcUaType_QualifiedName: parseQualifiedName(subtree, tvb, &iOffset, "Value"); break;
673 case OpcUaType_LocalizedText: parseLocalizedText(subtree, tvb, &iOffset, "Value"); break;
674 case OpcUaType_ExtensionObject: parseExtensionObject(subtree, tvb, &iOffset, "Value"); break;
675 case OpcUaType_DataValue: parseDataValue(subtree, tvb, &iOffset, "Value"); break;
676 case OpcUaType_Variant: parseVariant(subtree, tvb, &iOffset, "Value"); break;
683 /** General parsing function for arrays of simple types.
684 * All arrays have one 4 byte signed integer length information,
685 * followed by n data elements.
687 void parseArraySimple(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex, fctSimpleTypeParser pParserFunction)
689 char szFieldName[] = "Array of Simple 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);
695 /* read array length */
696 iLen = tvb_get_letohl(tvb, *pOffset);
697 proto_tree_add_item(subtree, hf_opcua_ArraySize, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN);
699 if (iLen > MAX_ARRAY_LEN)
702 pi = proto_tree_add_text(tree, tvb, *pOffset, 4, "Array length %d too large to process", iLen);
703 PROTO_ITEM_SET_GENERATED(pi);
708 for (i=0; i<iLen; i++)
710 (*pParserFunction)(subtree, tvb, pOffset, hfIndex);
714 /** General parsing function for arrays of enums.
715 * All arrays have one 4 byte signed integer length information,
716 * followed by n data elements.
718 void parseArrayEnum(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, fctEnumParser pParserFunction)
720 char szFieldName[] = "Array of Enum Type";
721 proto_item *ti = proto_tree_add_text(tree, tvb, 0, -1, "%s", szFieldName);
722 proto_tree *subtree = proto_item_add_subtree(ti, ett_opcua_array);
726 /* read array length */
727 iLen = tvb_get_letohl(tvb, *pOffset);
728 proto_tree_add_item(subtree, hf_opcua_ArraySize, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN);
730 if (iLen > MAX_ARRAY_LEN)
733 pi = proto_tree_add_text(tree, tvb, *pOffset, 4, "Array length %d too large to process", iLen);
734 PROTO_ITEM_SET_GENERATED(pi);
739 for (i=0; i<iLen; i++)
741 (*pParserFunction)(subtree, tvb, pOffset);
745 /** General parsing function for arrays of complex types.
746 * All arrays have one 4 byte signed integer length information,
747 * followed by n data elements.
749 void parseArrayComplex(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName, fctComplexTypeParser pParserFunction)
751 proto_item *ti = proto_tree_add_text(tree, tvb, 0, -1, "Array of %s", szFieldName);
752 proto_tree *subtree = proto_item_add_subtree(ti, ett_opcua_array);
756 /* read array length */
757 iLen = tvb_get_letohl(tvb, *pOffset);
758 proto_tree_add_item(subtree, hf_opcua_ArraySize, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN);
760 if (iLen > MAX_ARRAY_LEN)
763 pi = proto_tree_add_text(tree, tvb, *pOffset, 4, "Array length %d too large to process", iLen);
764 PROTO_ITEM_SET_GENERATED(pi);
769 for (i=0; i<iLen; i++)
772 g_snprintf(szNum, 20, "[%i]", i);
773 (*pParserFunction)(subtree, tvb, pOffset, szNum);
777 void parseNodeId(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
779 proto_item *ti = proto_tree_add_text(tree, tvb, 0, -1, "%s: NodeId", szFieldName);
780 proto_tree *subtree = proto_item_add_subtree(ti, ett_opcua_nodeid);
781 gint iOffset = *pOffset;
784 EncodingMask = tvb_get_guint8(tvb, iOffset);
785 proto_tree_add_item(subtree, hf_opcua_nodeid_encodingmask, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
790 case 0x00: /* two byte node id */
791 proto_tree_add_item(subtree, hf_opcua_nodeid_numeric, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
794 case 0x01: /* four byte node id */
795 proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
797 proto_tree_add_item(subtree, hf_opcua_nodeid_numeric, tvb, iOffset, 2, ENC_LITTLE_ENDIAN);
800 case 0x02: /* numeric, that does not fit into four bytes */
801 proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 2, ENC_LITTLE_ENDIAN);
803 proto_tree_add_item(subtree, hf_opcua_nodeid_numeric, tvb, iOffset, 4, ENC_LITTLE_ENDIAN);
806 case 0x03: /* string */
807 proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 2, ENC_LITTLE_ENDIAN);
809 parseString(subtree, tvb, &iOffset, hf_opcua_String);
811 case 0x04: /* guid */
812 proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 2, ENC_LITTLE_ENDIAN);
814 parseGuid(subtree, tvb, &iOffset, hf_opcua_Guid);
816 case 0x05: /* byte string */
817 proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 4, ENC_LITTLE_ENDIAN);
819 parseByteString(subtree, tvb, &iOffset, hf_opcua_ByteString);
826 void parseExtensionObject(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
828 gint iOffset = *pOffset;
831 proto_tree *extobj_tree;
832 proto_tree *mask_tree;
835 /* add extension object subtree */
836 ti = proto_tree_add_text(tree, tvb, 0, -1, "%s : ExtensionObject", szFieldName);
837 extobj_tree = proto_item_add_subtree(ti, ett_opcua_extensionobject);
839 /* add nodeid subtree */
840 TypeId = getExtensionObjectType(tvb, &iOffset);
841 parseExpandedNodeId(extobj_tree, tvb, &iOffset, "TypeId");
843 /* parse encoding mask */
844 EncodingMask = tvb_get_guint8(tvb, iOffset);
845 ti = proto_tree_add_text(extobj_tree, tvb, 0, -1, "EncodingMask");
846 mask_tree = proto_item_add_subtree(ti, ett_opcua_extobj_encodingmask);
847 proto_tree_add_item(mask_tree, hf_opcua_extobj_mask_binbodyflag, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
848 proto_tree_add_item(mask_tree, hf_opcua_extobj_mask_xmlbodyflag, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
851 if (EncodingMask & EXTOBJ_ENCODINGMASK_BINBODY_FLAG) /* has binary body ? */
853 dispatchExtensionObjectType(extobj_tree, tvb, &iOffset, TypeId);
859 void parseExpandedNodeId(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
861 proto_item *ti = proto_tree_add_text(tree, tvb, 0, -1, "%s: ExpandedNodeId", szFieldName);
862 proto_tree *subtree = proto_item_add_subtree(ti, ett_opcua_nodeid);
863 gint iOffset = *pOffset;
866 EncodingMask = tvb_get_guint8(tvb, iOffset);
867 proto_tree_add_item(subtree, hf_opcua_nodeid_encodingmask, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
872 case 0x00: /* two byte node id */
873 proto_tree_add_item(subtree, hf_opcua_nodeid_numeric, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
876 case 0x01: /* four byte node id */
877 proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
879 proto_tree_add_item(subtree, hf_opcua_nodeid_numeric, tvb, iOffset, 2, ENC_LITTLE_ENDIAN);
882 case 0x02: /* numeric, that does not fit into four bytes */
883 proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 2, ENC_LITTLE_ENDIAN);
885 proto_tree_add_item(subtree, hf_opcua_nodeid_numeric, tvb, iOffset, 4, ENC_LITTLE_ENDIAN);
888 case 0x03: /* string */
889 proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 2, ENC_LITTLE_ENDIAN);
891 parseString(subtree, tvb, &iOffset, hf_opcua_String);
893 case 0x04: /* guid */
894 proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 2, ENC_LITTLE_ENDIAN);
896 parseGuid(subtree, tvb, &iOffset, hf_opcua_Guid);
898 case 0x05: /* byte string */
899 proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 2, ENC_LITTLE_ENDIAN);
901 parseByteString(subtree, tvb, &iOffset, hf_opcua_ByteString);
905 if (EncodingMask & NODEID_URIMASK)
907 parseString(subtree, tvb, &iOffset, hf_opcua_Uri);
909 if (EncodingMask & NODEID_SERVERINDEXFLAG)
911 parseUInt32(subtree, tvb, &iOffset, hf_opcua_ServerIndex);
917 guint32 getExtensionObjectType(tvbuff_t *tvb, gint *pOffset)
919 gint iOffset = *pOffset;
923 EncodingMask = tvb_get_guint8(tvb, iOffset);
928 case 0x00: /* two byte node id */
929 Numeric = tvb_get_guint8(tvb, iOffset);
932 case 0x01: /* four byte node id */
934 Numeric = tvb_get_letohs(tvb, iOffset);
936 case 0x02: /* numeric, that does not fit into four bytes */
938 Numeric = tvb_get_letohl(tvb, iOffset);
940 case 0x03: /* string */
942 case 0x05: /* guid */
943 case 0x06: /* byte string */