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"
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 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;
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" },
109 /** UA Variant Type enum */
110 typedef enum _OpcUa_BuiltInType
113 OpcUaType_Boolean = 1,
117 OpcUaType_UInt16 = 5,
119 OpcUaType_UInt32 = 7,
121 OpcUaType_UInt64 = 9,
122 OpcUaType_Float = 10,
123 OpcUaType_Double = 11,
124 OpcUaType_String = 12,
125 OpcUaType_DateTime = 13,
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
141 /** Variant encoding mask table */
142 static const value_string g_VariantTypes[] = {
158 { 15, "ByteString" },
159 { 16, "XmlElement" },
161 { 18, "ExpandedNodeId" },
162 { 19, "StatusCode" },
163 { 20, "DiagnosticInfo" },
164 { 21, "QualifiedName" },
165 { 22, "LocalizedText" },
166 { 23, "ExtensionObject" },
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" },
197 #define VARIANT_ARRAYDIMENSIONS 0x40
198 #define VARIANT_ARRAYMASK 0x80
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;
214 &ett_opcua_diagnosticinfo,
217 &ett_opcua_localizedtext,
218 &ett_opcua_qualifiedname,
219 &ett_opcua_datavalue,
221 &ett_opcua_extensionobject,
222 &ett_opcua_extobj_encodingmask
225 void registerSimpleTypes(int proto)
227 static hf_register_info hf[] =
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 }
233 { &hf_opcua_diag_mask_namespaceflag,
234 { "has namespace", "", FT_BOOLEAN, 8, NULL, DIAGNOSTICINFO_ENCODINGMASK_NAMESPACE_FLAG, NULL, HFILL }
236 { &hf_opcua_diag_mask_localizedtextflag,
237 { "has localizedtext", "", FT_BOOLEAN, 8, NULL, DIAGNOSTICINFO_ENCODINGMASK_LOCALIZEDTEXT_FLAG, NULL, HFILL }
239 { &hf_opcua_diag_mask_additionalinfoflag,
240 { "has additional info", "", FT_BOOLEAN, 8, NULL, DIAGNOSTICINFO_ENCODINGMASK_ADDITIONALINFO_FLAG, NULL, HFILL }
242 { &hf_opcua_diag_mask_innerstatuscodeflag,
243 { "has inner statuscode", "", FT_BOOLEAN, 8, NULL, DIAGNOSTICINFO_ENCODINGMASK_INNERSTATUSCODE_FLAG, NULL, HFILL }
245 { &hf_opcua_diag_mask_innerdiaginfoflag,
246 { "has inner diagnostic info", "", FT_BOOLEAN, 8, NULL, DIAGNOSTICINFO_ENCODINGMASK_INNERDIAGNOSTICINFO_FLAG, NULL, HFILL }
248 { &hf_opcua_loctext_mask_localeflag,
249 { "has locale information", "", FT_BOOLEAN, 8, NULL, LOCALIZEDTEXT_ENCODINGBYTE_LOCALE, NULL, HFILL }
251 { &hf_opcua_loctext_mask_textflag,
252 { "has text", "", FT_BOOLEAN, 8, NULL, LOCALIZEDTEXT_ENCODINGBYTE_TEXT, NULL, HFILL }
254 { &hf_opcua_nodeid_encodingmask,
255 { "NodeId EncodingMask", "application.nodeid.encodingmask", FT_UINT8, BASE_HEX, VALS(g_nodeidmasks), 0x0, NULL, HFILL }
257 { &hf_opcua_nodeid_nsid,
258 { "NodeId Namespace Id", "application.nodeid.nsid", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
260 { &hf_opcua_nodeid_numeric,
261 { "NodeId Identifier Numeric", "application.nodeid.numeric", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }
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 } }
290 proto_register_field_array(proto, hf, array_length(hf));
291 proto_register_subtree_array(ett, array_length(ett));
294 void parseBoolean(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
296 proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 1, TRUE); *pOffset+=1;
299 void parseByte(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
301 proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 1, TRUE); *pOffset+=1;
304 void parseSByte(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
306 proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 1, TRUE); *pOffset+=1;
309 void parseUInt16(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
311 proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 2, TRUE); *pOffset+=2;
314 void parseInt16(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
316 proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 2, TRUE); *pOffset+=2;
319 void parseUInt32(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
321 proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 4, TRUE); *pOffset+=4;
324 void parseInt32(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
326 proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 4, TRUE); *pOffset+=4;
329 void parseUInt64(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
331 proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 8, TRUE); *pOffset+=8;
334 void parseInt64(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
336 proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 8, TRUE); *pOffset+=8;
339 void parseString(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
342 gint iOffset = *pOffset;
343 gint32 iLen = tvb_get_letohl(tvb, *pOffset);
348 proto_tree_add_string(tree, hfIndex, tvb, *pOffset, (iOffset - *pOffset),
349 "[OpcUa Null String]");
353 iOffset += iLen; /* eat the whole string */
354 proto_tree_add_item(tree, hfIndex, tvb, *pOffset, (iOffset - *pOffset), TRUE);
358 szValue = ep_strdup_printf("[Invalid String] Invalid length: %d", iLen);
359 proto_tree_add_string(tree, hfIndex, tvb, *pOffset, (iOffset - *pOffset), szValue);
365 void parseStatusCode(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
367 proto_tree_add_item(tree, hfIndex, tvb, *pOffset, 4, TRUE);
371 void parseLocalizedText(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
373 gint iOffset = *pOffset;
375 proto_tree *mask_tree;
379 ti = proto_tree_add_text(tree, tvb, 0, -1, "%s: LocalizedText", szFieldName);
380 subtree = proto_item_add_subtree(ti, ett_opcua_localizedtext);
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);
390 if (EncodingMask & LOCALIZEDTEXT_ENCODINGBYTE_LOCALE)
392 parseString(subtree, tvb, &iOffset, hf_opcua_localizedtext_locale);
395 if (EncodingMask & LOCALIZEDTEXT_ENCODINGBYTE_TEXT)
397 parseString(subtree, tvb, &iOffset, hf_opcua_localizedtext_text);
403 void parseGuid(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
405 proto_tree_add_item(tree, hfIndex, tvb, *pOffset, GUID_LEN, TRUE); *pOffset+=GUID_LEN;
408 void parseByteString(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
410 int iOffset = *pOffset;
411 gint32 iLen = tvb_get_letohl(tvb, iOffset);
421 proto_tree_add_item(tree, hfIndex, tvb, *pOffset, (iOffset - *pOffset), TRUE);
425 void parseXmlElement(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
427 parseByteString(tree, tvb, pOffset, hfIndex);
430 void parseFloat(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
432 proto_tree_add_item(tree, hfIndex, tvb, *pOffset, sizeof(gfloat), TRUE);
433 *pOffset += sizeof(gfloat);
436 void parseDouble(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
438 proto_tree_add_item(tree, hfIndex, tvb, *pOffset, sizeof(gdouble), TRUE);
439 *pOffset += sizeof(gdouble);
442 void parseDateTime(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex)
444 *pOffset = dissect_nt_64bit_time(tvb, tree, *pOffset, hfIndex);
447 void parseDiagnosticInfo(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
449 gint iOffset = *pOffset;
451 proto_tree *mask_tree;
455 ti = proto_tree_add_text(tree, tvb, 0, -1, "%s: DiagnosticInfo", szFieldName);
456 subtree = proto_item_add_subtree(ti, ett_opcua_diagnosticinfo);
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);
470 if (EncodingMask & DIAGNOSTICINFO_ENCODINGMASK_SYMBOLICID_FLAG)
472 parseInt32(subtree, tvb, &iOffset, hf_opcua_diag_symbolicid);
474 if (EncodingMask & DIAGNOSTICINFO_ENCODINGMASK_NAMESPACE_FLAG)
476 parseInt32(subtree, tvb, &iOffset, hf_opcua_diag_namespace);
478 if (EncodingMask & DIAGNOSTICINFO_ENCODINGMASK_LOCALIZEDTEXT_FLAG)
480 parseInt32(subtree, tvb, &iOffset, hf_opcua_diag_localizedtext);
482 if (EncodingMask & DIAGNOSTICINFO_ENCODINGMASK_ADDITIONALINFO_FLAG)
484 parseString(subtree, tvb, &iOffset, hf_opcua_diag_additionalinfo);
486 if (EncodingMask & DIAGNOSTICINFO_ENCODINGMASK_INNERSTATUSCODE_FLAG)
488 parseStatusCode(subtree, tvb, &iOffset, hf_opcua_diag_innerstatuscode);
490 if (EncodingMask & DIAGNOSTICINFO_ENCODINGMASK_INNERDIAGNOSTICINFO_FLAG)
492 parseDiagnosticInfo(subtree, tvb, &iOffset, "Inner DiagnosticInfo");
498 void parseQualifiedName(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
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);
503 parseUInt16(subtree, tvb, pOffset, hf_opcua_qualifiedname_id);
504 parseString(subtree, tvb, pOffset, hf_opcua_qualifiedname_name);
507 void parseDataValue(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
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;
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);
526 if (EncodingMask & DATAVALUE_ENCODINGBYTE_VALUE)
528 parseVariant(subtree, tvb, &iOffset, "Value");
530 if (EncodingMask & DATAVALUE_ENCODINGBYTE_STATUSCODE)
532 parseStatusCode(subtree, tvb, &iOffset, hf_opcua_StatusCode);
534 if (EncodingMask & DATAVALUE_ENCODINGBYTE_SOURCETIMESTAMP)
536 parseDateTime(subtree, tvb, &iOffset, hf_opcua_SourceTimestamp);
538 if (EncodingMask & DATAVALUE_ENCODINGBYTE_SOURCEPICOSECONDS)
540 parseUInt16(subtree, tvb, &iOffset, hf_opcua_SourcePicoseconds);
542 if (EncodingMask & DATAVALUE_ENCODINGBYTE_SERVERTIMESTAMP)
544 parseDateTime(subtree, tvb, &iOffset, hf_opcua_ServerTimestamp);
546 if (EncodingMask & DATAVALUE_ENCODINGBYTE_SERVERPICOSECONDS)
548 parseUInt16(subtree, tvb, &iOffset, hf_opcua_ServerPicoseconds);
554 void parseVariant(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
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;
562 EncodingMask = tvb_get_guint8(tvb, iOffset);
563 proto_tree_add_item(subtree, hf_opcua_variant_encodingmask, tvb, iOffset, 1, TRUE);
565 ArrayLength = tvb_get_letohl(tvb, iOffset);
567 if (EncodingMask & VARIANT_ARRAYMASK)
569 /* type is encoded in bits 0-5 */
570 switch(EncodingMask & 0x3f)
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;
602 /* type is encoded in bits 0-5 */
603 switch(EncodingMask & 0x3f)
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;
634 if (EncodingMask & VARIANT_ARRAYDIMENSIONS)
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);
640 if (ArrayLength < MAX_ARRAY_LEN)
642 for (i=0; i<ArrayLength; i++)
644 parseInt32(subtree, tvb, pOffset, hf_opcua_Int32);
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));
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.
661 void parseArraySimple(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, int hfIndex, fctSimpleTypeParser pParserFunction)
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);
669 /* read array length */
670 iLen = tvb_get_letohl(tvb, *pOffset);
671 proto_tree_add_item(subtree, hf_opcua_ArraySize, tvb, *pOffset, 4, TRUE);
673 if (iLen == -1) return; /* no array */
674 if (iLen == 0) return; /* array with zero elements*/
676 if (iLen > MAX_ARRAY_LEN)
678 PROTO_ITEM_SET_GENERATED(proto_tree_add_text(tree, tvb, *pOffset, 4, "Array length %d too large to process", iLen));
683 for (i=0; i<iLen; i++)
685 (*pParserFunction)(subtree, tvb, pOffset, hfIndex);
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.
693 void parseArrayEnum(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, fctEnumParser pParserFunction)
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);
701 /* read array length */
702 iLen = tvb_get_letohl(tvb, *pOffset);
703 proto_tree_add_item(subtree, hf_opcua_ArraySize, tvb, *pOffset, 4, TRUE);
705 if (iLen == -1) return; /* no array */
706 if (iLen == 0) return; /* array with zero elements*/
708 if (iLen > MAX_ARRAY_LEN)
710 PROTO_ITEM_SET_GENERATED(proto_tree_add_text(tree, tvb, *pOffset, 4, "Array length %d too large to process", iLen));
715 for (i=0; i<iLen; i++)
717 (*pParserFunction)(subtree, tvb, pOffset);
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.
725 void parseArrayComplex(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName, fctComplexTypeParser pParserFunction)
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);
732 /* read array length */
733 iLen = tvb_get_letohl(tvb, *pOffset);
734 proto_tree_add_item(subtree, hf_opcua_ArraySize, tvb, *pOffset, 4, TRUE);
736 if (iLen == -1) return; /* no array */
737 if (iLen == 0) return; /* array with zero elements*/
739 if (iLen > MAX_ARRAY_LEN)
741 PROTO_ITEM_SET_GENERATED(proto_tree_add_text(tree, tvb, *pOffset, 4, "Array length %d too large to process", iLen));
746 for (i=0; i<iLen; i++)
749 g_snprintf(szNum, 20, "[%i]", i);
750 (*pParserFunction)(subtree, tvb, pOffset, szNum);
754 void parseNodeId(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
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;
761 EncodingMask = tvb_get_guint8(tvb, iOffset);
762 proto_tree_add_item(subtree, hf_opcua_nodeid_encodingmask, tvb, iOffset, 1, TRUE);
767 case 0x00: /* two byte node id */
768 proto_tree_add_item(subtree, hf_opcua_nodeid_numeric, tvb, iOffset, 1, TRUE);
771 case 0x01: /* four byte node id */
772 proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 1, TRUE);
774 proto_tree_add_item(subtree, hf_opcua_nodeid_numeric, tvb, iOffset, 2, TRUE);
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);
780 proto_tree_add_item(subtree, hf_opcua_nodeid_numeric, tvb, iOffset, 4, TRUE);
783 case 0x03: /* string */
784 proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 2, TRUE);
786 parseString(subtree, tvb, &iOffset, hf_opcua_String);
788 case 0x04: /* guid */
789 proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 2, TRUE);
791 parseGuid(subtree, tvb, &iOffset, hf_opcua_Guid);
793 case 0x05: /* byte string */
794 proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 4, TRUE);
796 parseByteString(subtree, tvb, &iOffset, hf_opcua_ByteString);
803 void parseExtensionObject(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
805 gint iOffset = *pOffset;
807 proto_tree *extobj_tree;
808 proto_tree *mask_tree;
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);
815 /* add nodeid subtree */
816 parseExpandedNodeId(extobj_tree, tvb, &iOffset, "TypeId");
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);
826 if (EncodingMask & EXTOBJ_ENCODINGMASK_BINBODY_FLAG) /* has binary body ? */
828 parseByteString(extobj_tree, tvb, &iOffset, hf_opcua_ByteString);
834 void parseExpandedNodeId(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
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;
841 EncodingMask = tvb_get_guint8(tvb, iOffset);
842 proto_tree_add_item(subtree, hf_opcua_nodeid_encodingmask, tvb, iOffset, 1, TRUE);
847 case 0x00: /* two byte node id */
848 proto_tree_add_item(subtree, hf_opcua_nodeid_numeric, tvb, iOffset, 1, TRUE);
851 case 0x01: /* four byte node id */
852 proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 1, TRUE);
854 proto_tree_add_item(subtree, hf_opcua_nodeid_numeric, tvb, iOffset, 2, TRUE);
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);
860 proto_tree_add_item(subtree, hf_opcua_nodeid_numeric, tvb, iOffset, 4, TRUE);
863 case 0x03: /* string */
864 proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 2, TRUE);
866 parseString(subtree, tvb, &iOffset, hf_opcua_String);
868 case 0x04: /* guid */
869 proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 2, TRUE);
871 parseGuid(subtree, tvb, &iOffset, hf_opcua_Guid);
873 case 0x05: /* byte string */
874 proto_tree_add_item(subtree, hf_opcua_nodeid_nsid, tvb, iOffset, 2, TRUE);
876 parseByteString(subtree, tvb, &iOffset, hf_opcua_ByteString);
880 if (EncodingMask & NODEID_URIMASK)
882 parseString(subtree, tvb, &iOffset, hf_opcua_Uri);
884 if (EncodingMask & NODEID_SERVERINDEXFLAG)
886 parseUInt32(subtree, tvb, &iOffset, hf_opcua_ServerIndex);