1 /******************************************************************************
2 ** Copyright (C) 2006-2007 ascolab GmbH. All Rights Reserved.
3 ** Web: http://www.ascolab.com
5 ** SPDX-License-Identifier: GPL-2.0-or-later
7 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
8 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
10 ** Project: OpcUa Wireshark Plugin
12 ** Description: Implementation of OpcUa built-in type parsers.
13 ** This contains all the simple types and some complex types.
15 ** Author: Gerhard Gappmeier <gerhard.gappmeier@ascolab.com>
16 ******************************************************************************/
20 #include <epan/packet.h>
21 #include <epan/expert.h>
22 #include <epan/proto.h>
23 #include <epan/proto_data.h>
24 #include <epan/asn1.h>
25 #include <epan/dissectors/packet-windows-common.h>
26 #include <epan/dissectors/packet-x509af.h>
27 #include "opcua_simpletypes.h"
28 #include "opcua_hfindeces.h"
29 #include "opcua_statuscode.h"
31 #define DIAGNOSTICINFO_ENCODINGMASK_SYMBOLICID_FLAG 0x01
32 #define DIAGNOSTICINFO_ENCODINGMASK_NAMESPACE_FLAG 0x02
33 #define DIAGNOSTICINFO_ENCODINGMASK_LOCALIZEDTEXT_FLAG 0x04
34 #define DIAGNOSTICINFO_ENCODINGMASK_LOCALE_FLAG 0x08
35 #define DIAGNOSTICINFO_ENCODINGMASK_ADDITIONALINFO_FLAG 0x10
36 #define DIAGNOSTICINFO_ENCODINGMASK_INNERSTATUSCODE_FLAG 0x20
37 #define DIAGNOSTICINFO_ENCODINGMASK_INNERDIAGNOSTICINFO_FLAG 0x40
38 #define LOCALIZEDTEXT_ENCODINGBYTE_LOCALE 0x01
39 #define LOCALIZEDTEXT_ENCODINGBYTE_TEXT 0x02
40 #define NODEID_NAMESPACEURIFLAG 0x80
41 #define NODEID_SERVERINDEXFLAG 0x40
42 #define DATAVALUE_ENCODINGBYTE_VALUE 0x01
43 #define DATAVALUE_ENCODINGBYTE_STATUSCODE 0x02
44 #define DATAVALUE_ENCODINGBYTE_SOURCETIMESTAMP 0x04
45 #define DATAVALUE_ENCODINGBYTE_SERVERTIMESTAMP 0x08
46 #define DATAVALUE_ENCODINGBYTE_SOURCEPICOSECONDS 0x10
47 #define DATAVALUE_ENCODINGBYTE_SERVERPICOSECONDS 0x20
48 #define EXTOBJ_ENCODINGMASK_BINBODY_FLAG 0x01
49 #define EXTOBJ_ENCODINGMASK_XMLBODY_FLAG 0x02
50 #define STATUSCODE_STRUCTURECHANGED 0x8000
51 #define STATUSCODE_SEMANTICSCHANGED 0x4000
52 #define STATUSCODE_INFOTYPE_DATAVALUE 0x00000400
53 #define STATUSCODE_INFOBIT_OVERFLOW 0x0080
54 #define STATUSCODE_INFOBIT_HISTORIAN_PARTIAL 0x0004
55 #define STATUSCODE_INFOBIT_HISTORIAN_EXTRADATA 0x0008
56 #define STATUSCODE_INFOBIT_HISTORIAN_MULTIVALUE 0x0010
57 #define RETURNDIAGNOSTICS_SERVICELEVEL_SYMBOLICID 0x0001
58 #define RETURNDIAGNOSTICS_SERVICELEVEL_LOCALIZEDTEXT 0x0002
59 #define RETURNDIAGNOSTICS_SERVICELEVEL_ADDITIONALINFO 0x0004
60 #define RETURNDIAGNOSTICS_SERVICELEVEL_INNERSTATUSCODE 0x0008
61 #define RETURNDIAGNOSTICS_SERVICELEVEL_INNERDIAGNOSTICS 0x0010
62 #define RETURNDIAGNOSTICS_OPERATIONLEVEL_SYMBOLICID 0x0020
63 #define RETURNDIAGNOSTICS_OPERATIONLEVEL_LOCALIZEDTEXT 0x0040
64 #define RETURNDIAGNOSTICS_OPERATIONLEVEL_ADDITIONALINFO 0x0080
65 #define RETURNDIAGNOSTICS_OPERATIONLEVEL_INNERSTATUSCODE 0x0100
66 #define RETURNDIAGNOSTICS_OPERATIONLEVEL_INNERDIAGNOSTICS 0x0200
67 #define NODECLASSMASK_ALL 0x0000
68 #define NODECLASSMASK_OBJECT 0x0001
69 #define NODECLASSMASK_VARIABLE 0x0002
70 #define NODECLASSMASK_METHOD 0x0004
71 #define NODECLASSMASK_OBJECTTYPE 0x0008
72 #define NODECLASSMASK_VARIABLETYPE 0x0010
73 #define NODECLASSMASK_REFERENCETYPE 0x0020
74 #define NODECLASSMASK_DATATYPE 0x0040
75 #define NODECLASSMASK_VIEW 0x0080
76 #define RESULTMASK_REFERENCETYPE 0x0001
77 #define RESULTMASK_ISFORWARD 0x0002
78 #define RESULTMASK_NODECLASS 0x0004
79 #define RESULTMASK_BROWSENAME 0x0008
80 #define RESULTMASK_DISPLAYNAME 0x0010
81 #define RESULTMASK_TYPEDEFINITION 0x0020
82 #define RESULTMASK_ALL 0x003F
85 /* Chosen arbitrarily */
86 #define MAX_ARRAY_LEN 10000
87 #define MAX_NESTING_DEPTH 100
89 static int hf_opcua_diag_mask
;
90 static int hf_opcua_diag_mask_symbolicflag
;
91 static int hf_opcua_diag_mask_namespaceflag
;
92 static int hf_opcua_diag_mask_localizedtextflag
;
93 static int hf_opcua_diag_mask_localeflag
;
94 static int hf_opcua_diag_mask_additionalinfoflag
;
95 static int hf_opcua_diag_mask_innerstatuscodeflag
;
96 static int hf_opcua_diag_mask_innerdiaginfoflag
;
97 static int hf_opcua_loctext_mask
;
98 static int hf_opcua_loctext_mask_localeflag
;
99 static int hf_opcua_loctext_mask_textflag
;
100 static int hf_opcua_datavalue_mask
;
101 static int hf_opcua_datavalue_mask_valueflag
;
102 static int hf_opcua_datavalue_mask_statuscodeflag
;
103 static int hf_opcua_datavalue_mask_sourcetimestampflag
;
104 static int hf_opcua_datavalue_mask_servertimestampflag
;
105 static int hf_opcua_datavalue_mask_sourcepicoseconds
;
106 static int hf_opcua_datavalue_mask_serverpicoseconds
;
107 static int hf_opcua_nodeid_encodingmask
;
108 static int hf_opcua_expandednodeid_mask
;
109 static int hf_opcua_expandednodeid_mask_namespaceuri
;
110 static int hf_opcua_expandednodeid_mask_serverindex
;
111 static int hf_opcua_variant_encodingmask
;
112 static int hf_opcua_nodeid_nsindex
;
113 static int hf_opcua_nodeid_numeric
;
114 static int hf_opcua_nodeid_string
;
115 static int hf_opcua_nodeid_guid
;
116 static int hf_opcua_nodeid_bytestring
;
117 static int hf_opcua_localizedtext_locale
;
118 static int hf_opcua_localizedtext_text
;
119 static int hf_opcua_qualifiedname_id
;
120 static int hf_opcua_qualifiedname_name
;
121 static int hf_opcua_SourceTimestamp
;
122 static int hf_opcua_SourcePicoseconds
;
123 static int hf_opcua_ServerTimestamp
;
124 static int hf_opcua_ServerPicoseconds
;
125 static int hf_opcua_diag_symbolicid
;
126 static int hf_opcua_diag_namespace
;
127 static int hf_opcua_diag_localizedtext
;
128 static int hf_opcua_diag_locale
;
129 static int hf_opcua_diag_additionalinfo
;
130 static int hf_opcua_diag_innerstatuscode
;
131 static int hf_opcua_extobj_mask
;
132 static int hf_opcua_extobj_mask_binbodyflag
;
133 static int hf_opcua_extobj_mask_xmlbodyflag
;
134 static int hf_opcua_ArraySize
;
135 static int hf_opcua_ServerIndex
;
136 static int hf_opcua_status_StructureChanged
;
137 static int hf_opcua_status_SemanticsChanged
;
138 static int hf_opcua_status_InfoBit_Limit_Overflow
;
139 static int hf_opcua_status_InfoBit_Historian_Partial
;
140 static int hf_opcua_status_InfoBit_Historian_ExtraData
;
141 static int hf_opcua_status_InfoBit_Historian_MultiValue
;
142 static int hf_opcua_status_InfoType
;
143 static int hf_opcua_status_Limit
;
144 static int hf_opcua_status_Historian
;
145 int hf_opcua_returnDiag
;
146 int hf_opcua_returnDiag_mask_sl_symbolicId
;
147 int hf_opcua_returnDiag_mask_sl_localizedText
;
148 int hf_opcua_returnDiag_mask_sl_additionalinfo
;
149 int hf_opcua_returnDiag_mask_sl_innerstatuscode
;
150 int hf_opcua_returnDiag_mask_sl_innerdiagnostics
;
151 int hf_opcua_returnDiag_mask_ol_symbolicId
;
152 int hf_opcua_returnDiag_mask_ol_localizedText
;
153 int hf_opcua_returnDiag_mask_ol_additionalinfo
;
154 int hf_opcua_returnDiag_mask_ol_innerstatuscode
;
155 int hf_opcua_returnDiag_mask_ol_innerdiagnostics
;
156 int hf_opcua_nodeClassMask
;
157 int hf_opcua_nodeClassMask_all
;
158 int hf_opcua_nodeClassMask_object
;
159 int hf_opcua_nodeClassMask_variable
;
160 int hf_opcua_nodeClassMask_method
;
161 int hf_opcua_nodeClassMask_objecttype
;
162 int hf_opcua_nodeClassMask_variabletype
;
163 int hf_opcua_nodeClassMask_referencetype
;
164 int hf_opcua_nodeClassMask_datatype
;
165 int hf_opcua_nodeClassMask_view
;
166 int hf_opcua_resultMask
;
167 int hf_opcua_resultMask_all
;
168 int hf_opcua_resultMask_referencetype
;
169 int hf_opcua_resultMask_isforward
;
170 int hf_opcua_resultMask_nodeclass
;
171 int hf_opcua_resultMask_browsename
;
172 int hf_opcua_resultMask_displayname
;
173 int hf_opcua_resultMask_typedefinition
;
175 static expert_field ei_array_length
;
176 static expert_field ei_nesting_depth
;
178 extern int proto_opcua
;
180 /** NodeId encoding mask table */
181 static const value_string g_nodeidmasks
[] = {
182 { 0x00, "Two byte encoded Numeric" },
183 { 0x01, "Four byte encoded Numeric" },
184 { 0x02, "Numeric of arbitrary length" },
191 /** StatusCode info types */
192 static const value_string g_infotype
[] = {
193 { 0x00, "Not used" },
194 { 0x01, "DataValue" },
195 { 0x02, "Reserved" },
196 { 0x03, "Reserved" },
200 /** StatusCode Limit types */
201 static const value_string g_limit
[] = {
205 { 0x03, "Constant" },
209 /** StatusCode Historian types */
210 static const value_string g_historian
[] = {
212 { 0x01, "Calculated" },
213 { 0x02, "Interpolated" },
214 { 0x03, "Reserved" },
218 /** UA Variant Type enum */
219 typedef enum _OpcUa_BuiltInType
222 OpcUaType_Boolean
= 1,
226 OpcUaType_UInt16
= 5,
228 OpcUaType_UInt32
= 7,
230 OpcUaType_UInt64
= 9,
231 OpcUaType_Float
= 10,
232 OpcUaType_Double
= 11,
233 OpcUaType_String
= 12,
234 OpcUaType_DateTime
= 13,
236 OpcUaType_ByteString
= 15,
237 OpcUaType_XmlElement
= 16,
238 OpcUaType_NodeId
= 17,
239 OpcUaType_ExpandedNodeId
= 18,
240 OpcUaType_StatusCode
= 19,
241 OpcUaType_QualifiedName
= 20,
242 OpcUaType_LocalizedText
= 21,
243 OpcUaType_ExtensionObject
= 22,
244 OpcUaType_DataValue
= 23,
245 OpcUaType_Variant
= 24,
246 OpcUaType_DiagnosticInfo
= 25
250 /** Variant encoding mask table */
251 static const value_string g_VariantTypes
[] = {
267 { 15, "ByteString" },
268 { 16, "XmlElement" },
270 { 18, "ExpandedNodeId" },
271 { 19, "StatusCode" },
272 { 20, "QualifiedName" },
273 { 21, "LocalizedText" },
274 { 22, "ExtensionObject" },
277 { 25, "DiagnosticInfo" },
278 { 0x80, "Array of Null" },
279 { 0x80+1, "Array of Boolean" },
280 { 0x80+2, "Array of SByte" },
281 { 0x80+3, "Array of Byte" },
282 { 0x80+4, "Array of Int16" },
283 { 0x80+5, "Array of UInt16" },
284 { 0x80+6, "Array of Int32" },
285 { 0x80+7, "Array of UInt32" },
286 { 0x80+8, "Array of Int64" },
287 { 0x80+9, "Array of UInt64" },
288 { 0x80+10, "Array of Float" },
289 { 0x80+11, "Array of Double" },
290 { 0x80+12, "Array of String" },
291 { 0x80+13, "Array of DateTime" },
292 { 0x80+14, "Array of Guid" },
293 { 0x80+15, "Array of ByteString" },
294 { 0x80+16, "Array of XmlElement" },
295 { 0x80+17, "Array of NodeId" },
296 { 0x80+18, "Array of ExpandedNodeId" },
297 { 0x80+19, "Array of StatusCode" },
298 { 0x80+20, "Array of QualifiedName" },
299 { 0x80+21, "Array of LocalizedText" },
300 { 0x80+22, "Array of ExtensionObject" },
301 { 0x80+23, "Array of DataValue" },
302 { 0x80+24, "Array of Variant" },
303 { 0x80+25, "Array of DiagnosticInfo" },
304 { 0xC0, "Matrix of Null" },
305 { 0xC0+1, "Matrix of Boolean" },
306 { 0xC0+2, "Matrix of SByte" },
307 { 0xC0+3, "Matrix of Byte" },
308 { 0xC0+4, "Matrix of Int16" },
309 { 0xC0+5, "Matrix of UInt16" },
310 { 0xC0+6, "Matrix of Int32" },
311 { 0xC0+7, "Matrix of UInt32" },
312 { 0xC0+8, "Matrix of Int64" },
313 { 0xC0+9, "Matrix of UInt64" },
314 { 0xC0+10, "Matrix of Float" },
315 { 0xC0+11, "Matrix of Double" },
316 { 0xC0+12, "Matrix of String" },
317 { 0xC0+13, "Matrix of DateTime" },
318 { 0xC0+14, "Matrix of Guid" },
319 { 0xC0+15, "Matrix of ByteString" },
320 { 0xC0+16, "Matrix of XmlElement" },
321 { 0xC0+17, "Matrix of NodeId" },
322 { 0xC0+18, "Matrix of ExpandedNodeId" },
323 { 0xC0+19, "Matrix of StatusCode" },
324 { 0xC0+20, "Matrix of QualifiedName" },
325 { 0xC0+21, "Matrix of LocalizedText" },
326 { 0xC0+22, "Matrix of ExtensionObject" },
327 { 0xC0+23, "Matrix of DataValue" },
328 { 0xC0+24, "Matrix of Variant" },
329 { 0xC0+25, "Matrix of DiagnosticInfo" },
332 #define VARIANT_ARRAYDIMENSIONS 0x40
333 #define VARIANT_ARRAYMASK 0x80
335 /** BrowseRequest's BrowseDescription's NodeClassMaskTable enum table */
336 static const value_string g_NodeClassMask
[] = {
337 { NODECLASSMASK_ALL
, "All" },
341 /* BrowseRequest's BrowseDescription's ResultMaskTable enum table */
342 static const value_string g_ResultMask
[] = {
343 { RESULTMASK_ALL
, "All" },
348 static int ett_opcua_diagnosticinfo
;
349 static int ett_opcua_diagnosticinfo_encodingmask
;
350 static int ett_opcua_nodeid
;
351 static int ett_opcua_expandednodeid
;
352 static int ett_opcua_expandednodeid_encodingmask
;
353 static int ett_opcua_localizedtext
;
354 static int ett_opcua_localizedtext_encodingmask
;
355 static int ett_opcua_qualifiedname
;
356 static int ett_opcua_datavalue
;
357 static int ett_opcua_datavalue_encodingmask
;
358 static int ett_opcua_variant
;
359 static int ett_opcua_variant_arraydims
;
360 static int ett_opcua_extensionobject
;
361 static int ett_opcua_extensionobject_encodingmask
;
362 static int ett_opcua_statuscode
;
363 static int ett_opcua_statuscode_info
;
364 int ett_opcua_array_Boolean
;
365 int ett_opcua_array_SByte
;
366 int ett_opcua_array_Byte
;
367 int ett_opcua_array_Int16
;
368 int ett_opcua_array_UInt16
;
369 int ett_opcua_array_Int32
;
370 int ett_opcua_array_UInt32
;
371 int ett_opcua_array_Int64
;
372 int ett_opcua_array_UInt64
;
373 int ett_opcua_array_Float
;
374 int ett_opcua_array_Double
;
375 int ett_opcua_array_String
;
376 int ett_opcua_array_DateTime
;
377 int ett_opcua_array_Guid
;
378 int ett_opcua_array_ByteString
;
379 int ett_opcua_array_XmlElement
;
380 int ett_opcua_array_NodeId
;
381 int ett_opcua_array_ExpandedNodeId
;
382 int ett_opcua_array_StatusCode
;
383 int ett_opcua_array_DiagnosticInfo
;
384 int ett_opcua_array_QualifiedName
;
385 int ett_opcua_array_LocalizedText
;
386 int ett_opcua_array_ExtensionObject
;
387 int ett_opcua_array_DataValue
;
388 int ett_opcua_array_Variant
;
389 int ett_opcua_returnDiagnostics
;
390 int ett_opcua_nodeClassMask
;
391 int ett_opcua_resultMask
;
395 &ett_opcua_diagnosticinfo
,
396 &ett_opcua_diagnosticinfo_encodingmask
,
398 &ett_opcua_expandednodeid
,
399 &ett_opcua_expandednodeid_encodingmask
,
400 &ett_opcua_localizedtext
,
401 &ett_opcua_localizedtext_encodingmask
,
402 &ett_opcua_qualifiedname
,
403 &ett_opcua_datavalue
,
404 &ett_opcua_datavalue_encodingmask
,
406 &ett_opcua_variant_arraydims
,
407 &ett_opcua_extensionobject
,
408 &ett_opcua_extensionobject_encodingmask
,
409 &ett_opcua_statuscode
,
410 &ett_opcua_statuscode_info
,
411 &ett_opcua_array_Boolean
,
412 &ett_opcua_array_SByte
,
413 &ett_opcua_array_Byte
,
414 &ett_opcua_array_Int16
,
415 &ett_opcua_array_UInt16
,
416 &ett_opcua_array_Int32
,
417 &ett_opcua_array_UInt32
,
418 &ett_opcua_array_Int64
,
419 &ett_opcua_array_UInt64
,
420 &ett_opcua_array_Float
,
421 &ett_opcua_array_Double
,
422 &ett_opcua_array_String
,
423 &ett_opcua_array_DateTime
,
424 &ett_opcua_array_Guid
,
425 &ett_opcua_array_ByteString
,
426 &ett_opcua_array_XmlElement
,
427 &ett_opcua_array_NodeId
,
428 &ett_opcua_array_ExpandedNodeId
,
429 &ett_opcua_array_StatusCode
,
430 &ett_opcua_array_DiagnosticInfo
,
431 &ett_opcua_array_QualifiedName
,
432 &ett_opcua_array_LocalizedText
,
433 &ett_opcua_array_ExtensionObject
,
434 &ett_opcua_array_DataValue
,
435 &ett_opcua_array_Variant
,
436 &ett_opcua_returnDiagnostics
,
437 &ett_opcua_nodeClassMask
,
438 &ett_opcua_resultMask
441 void registerSimpleTypes(int proto
)
443 expert_module_t
* expert_proto
;
445 static hf_register_info hf
[] =
447 /* id full name abbreviation type display strings bitmask blurb HFILL */
448 {&hf_opcua_diag_mask
, {"EncodingMask", "opcua.diag.mask", FT_UINT8
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}},
449 {&hf_opcua_diag_mask_symbolicflag
, {"has symbolic id", "opcua.diag.has_symbolic_id", FT_BOOLEAN
, 8, NULL
, DIAGNOSTICINFO_ENCODINGMASK_SYMBOLICID_FLAG
, NULL
, HFILL
}},
450 {&hf_opcua_diag_mask_namespaceflag
, {"has namespace", "opcua.diag.has_namespace", FT_BOOLEAN
, 8, NULL
, DIAGNOSTICINFO_ENCODINGMASK_NAMESPACE_FLAG
, NULL
, HFILL
}},
451 {&hf_opcua_diag_mask_localizedtextflag
, {"has localizedtext", "opcua.diag.has_localizedtext", FT_BOOLEAN
, 8, NULL
, DIAGNOSTICINFO_ENCODINGMASK_LOCALIZEDTEXT_FLAG
, NULL
, HFILL
}},
452 {&hf_opcua_diag_mask_localeflag
, {"has locale", "opcua.diag.has_locale", FT_BOOLEAN
, 8, NULL
, DIAGNOSTICINFO_ENCODINGMASK_LOCALE_FLAG
, NULL
, HFILL
}},
453 {&hf_opcua_diag_mask_additionalinfoflag
, {"has additional info", "opcua.diag.has_additional_info", FT_BOOLEAN
, 8, NULL
, DIAGNOSTICINFO_ENCODINGMASK_ADDITIONALINFO_FLAG
, NULL
, HFILL
}},
454 {&hf_opcua_diag_mask_innerstatuscodeflag
, {"has inner statuscode", "opcua.diag.has_inner_statuscode", FT_BOOLEAN
, 8, NULL
, DIAGNOSTICINFO_ENCODINGMASK_INNERSTATUSCODE_FLAG
, NULL
, HFILL
}},
455 {&hf_opcua_diag_mask_innerdiaginfoflag
, {"has inner diagnostic info", "opcua.diag.has_inner_diagnostic_code", FT_BOOLEAN
, 8, NULL
, DIAGNOSTICINFO_ENCODINGMASK_INNERDIAGNOSTICINFO_FLAG
, NULL
, HFILL
}},
456 {&hf_opcua_loctext_mask
, {"EncodingMask", "opcua.loctext.mask", FT_UINT8
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}},
457 {&hf_opcua_loctext_mask_localeflag
, {"has locale information", "opcua.loctext.has_locale_information", FT_BOOLEAN
, 8, NULL
, LOCALIZEDTEXT_ENCODINGBYTE_LOCALE
, NULL
, HFILL
}},
458 {&hf_opcua_loctext_mask_textflag
, {"has text", "opcua.loctext.has_text", FT_BOOLEAN
, 8, NULL
, LOCALIZEDTEXT_ENCODINGBYTE_TEXT
, NULL
, HFILL
}},
459 {&hf_opcua_nodeid_encodingmask
, {"EncodingMask", "opcua.nodeid.encodingmask", FT_UINT8
, BASE_HEX
, VALS(g_nodeidmasks
), 0x0F, NULL
, HFILL
}},
460 {&hf_opcua_nodeid_nsindex
, {"Namespace Index", "opcua.nodeid.nsindex", FT_UINT16
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
}},
461 {&hf_opcua_nodeid_numeric
, {"Identifier Numeric", "opcua.nodeid.numeric", FT_UINT32
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
}},
462 {&hf_opcua_nodeid_string
, {"Identifier String", "opcua.nodeid.string", FT_STRING
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}},
463 {&hf_opcua_nodeid_guid
, {"Identifier Guid", "opcua.nodeid.guid", FT_GUID
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}},
464 {&hf_opcua_nodeid_bytestring
, {"Identifier ByteString", "opcua.nodeid.bytestring", FT_BYTES
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}},
465 {&hf_opcua_expandednodeid_mask
, {"EncodingMask", "opcua.expandednodeid.mask", FT_UINT8
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}},
466 {&hf_opcua_expandednodeid_mask_namespaceuri
, {"has namespace uri", "opcua.expandednodeid.has_namespace_uri", FT_BOOLEAN
, 8, NULL
, NODEID_NAMESPACEURIFLAG
, NULL
, HFILL
}},
467 {&hf_opcua_expandednodeid_mask_serverindex
, {"has server index", "opcua.expandednodeid.has_server_index", FT_BOOLEAN
, 8, NULL
, NODEID_SERVERINDEXFLAG
, NULL
, HFILL
}},
468 {&hf_opcua_localizedtext_locale
, {"Locale", "opcua.loctext.Locale", FT_STRING
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}},
469 {&hf_opcua_localizedtext_text
, {"Text", "opcua.loctext.Text", FT_STRING
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}},
470 {&hf_opcua_qualifiedname_id
, {"Id", "opcua.qualname.Id", FT_UINT16
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
}},
471 {&hf_opcua_qualifiedname_name
, {"Name", "opcua.qualname.Name", FT_STRING
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}},
472 {&hf_opcua_datavalue_mask
, {"EncodingMask", "opcua.datavalue.mask", FT_UINT8
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}},
473 {&hf_opcua_datavalue_mask_valueflag
, {"has value", "opcua.datavalue.has_value", FT_BOOLEAN
, 8, NULL
, DATAVALUE_ENCODINGBYTE_VALUE
, NULL
, HFILL
}},
474 {&hf_opcua_datavalue_mask_statuscodeflag
, {"has statuscode", "opcua.datavalue.has_statuscode", FT_BOOLEAN
, 8, NULL
, DATAVALUE_ENCODINGBYTE_STATUSCODE
, NULL
, HFILL
}},
475 {&hf_opcua_datavalue_mask_sourcetimestampflag
, {"has source timestamp", "opcua.datavalue.has_source_timestamp", FT_BOOLEAN
, 8, NULL
, DATAVALUE_ENCODINGBYTE_SOURCETIMESTAMP
, NULL
, HFILL
}},
476 {&hf_opcua_datavalue_mask_servertimestampflag
, {"has server timestamp", "opcua.datavalue.has_server_timestamp", FT_BOOLEAN
, 8, NULL
, DATAVALUE_ENCODINGBYTE_SERVERTIMESTAMP
, NULL
, HFILL
}},
477 {&hf_opcua_datavalue_mask_sourcepicoseconds
, {"has source picoseconds", "opcua.datavalue.has_source_picoseconds", FT_BOOLEAN
, 8, NULL
, DATAVALUE_ENCODINGBYTE_SOURCEPICOSECONDS
, NULL
, HFILL
}},
478 {&hf_opcua_datavalue_mask_serverpicoseconds
, {"has server picoseconds", "opcua.datavalue.has_server_picoseconds", FT_BOOLEAN
, 8, NULL
, DATAVALUE_ENCODINGBYTE_SERVERPICOSECONDS
, NULL
, HFILL
}},
479 {&hf_opcua_variant_encodingmask
, {"Variant Type", "opcua.variant.has_value", FT_UINT8
, BASE_HEX
, VALS(g_VariantTypes
), 0x0, NULL
, HFILL
}},
480 {&hf_opcua_SourceTimestamp
, {"SourceTimestamp", "opcua.datavalue.SourceTimestamp", FT_ABSOLUTE_TIME
, ABSOLUTE_TIME_LOCAL
, NULL
, 0x0, NULL
, HFILL
}},
481 {&hf_opcua_SourcePicoseconds
, {"SourcePicoseconds", "opcua.datavalue.SourcePicoseconds", FT_UINT16
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
}},
482 {&hf_opcua_ServerTimestamp
, {"ServerTimestamp", "opcua.datavalue.ServerTimestamp", FT_ABSOLUTE_TIME
, ABSOLUTE_TIME_LOCAL
, NULL
, 0x0, NULL
, HFILL
}},
483 {&hf_opcua_ServerPicoseconds
, {"ServerPicoseconds", "opcua.datavalue.ServerPicoseconds", FT_UINT16
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
}},
484 {&hf_opcua_diag_symbolicid
, {"SymbolicId", "opcua.diag.SymbolicId", FT_INT32
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
}},
485 {&hf_opcua_diag_namespace
, {"Namespace", "opcua.diag.Namespace", FT_INT32
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
}},
486 {&hf_opcua_diag_localizedtext
, {"LocalizedText", "opcua.diag.LocalizedText", FT_INT32
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
}},
487 {&hf_opcua_diag_locale
, {"Locale", "opcua.diag.Locale", FT_INT32
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
}},
488 {&hf_opcua_diag_additionalinfo
, {"AdditionalInfo", "opcua.diag.AdditionalInfo", FT_STRING
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}},
489 {&hf_opcua_diag_innerstatuscode
, {"InnerStatusCode", "opcua.diag.InnerStatusCode", FT_UINT32
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}},
490 {&hf_opcua_extobj_mask
, {"EncodingMask", "opcua.extobj.mask", FT_UINT8
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}},
491 {&hf_opcua_extobj_mask_binbodyflag
, {"has binary body", "opcua.extobj.has_binary_body", FT_BOOLEAN
, 8, NULL
, EXTOBJ_ENCODINGMASK_BINBODY_FLAG
, NULL
, HFILL
}},
492 {&hf_opcua_extobj_mask_xmlbodyflag
, {"has xml body", "opcua.extobj.has_xml_body", FT_BOOLEAN
, 8, NULL
, EXTOBJ_ENCODINGMASK_XMLBODY_FLAG
, NULL
, HFILL
}},
493 {&hf_opcua_ArraySize
, {"ArraySize", "opcua.variant.ArraySize", FT_INT32
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
}},
494 {&hf_opcua_ServerIndex
, {"ServerIndex", "opcua.expandednodeid.ServerIndex", FT_UINT32
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
}},
495 {&hf_opcua_status_StructureChanged
, {"StructureChanged", "opcua.statuscode.structureChanged", FT_BOOLEAN
, 16, NULL
, STATUSCODE_STRUCTURECHANGED
, NULL
, HFILL
}},
496 {&hf_opcua_status_SemanticsChanged
, {"SemanticsChanged", "opcua.statuscode.semanticsChanged", FT_BOOLEAN
, 16, NULL
, STATUSCODE_SEMANTICSCHANGED
, NULL
, HFILL
}},
497 {&hf_opcua_status_InfoBit_Limit_Overflow
, {"Overflow", "opcua.statuscode.overflow", FT_BOOLEAN
, 16, NULL
, STATUSCODE_INFOBIT_OVERFLOW
, NULL
, HFILL
}},
498 {&hf_opcua_status_InfoBit_Historian_Partial
, {"HistorianBit: Partial", "opcua.statuscode.historian.partial", FT_BOOLEAN
, 16, NULL
, STATUSCODE_INFOBIT_HISTORIAN_PARTIAL
, NULL
, HFILL
}},
499 {&hf_opcua_status_InfoBit_Historian_ExtraData
, {"HistorianBit: ExtraData", "opcua.statuscode.historian.extraData", FT_BOOLEAN
, 16, NULL
, STATUSCODE_INFOBIT_HISTORIAN_EXTRADATA
, NULL
, HFILL
}},
500 {&hf_opcua_status_InfoBit_Historian_MultiValue
, {"HistorianBit: MultiValue", "opcua.statuscode.historian.multiValue", FT_BOOLEAN
, 16, NULL
, STATUSCODE_INFOBIT_HISTORIAN_MULTIVALUE
, NULL
, HFILL
}},
501 {&hf_opcua_status_InfoType
, {"InfoType", "opcua.statuscode.infoType", FT_UINT16
, BASE_HEX
, VALS(g_infotype
), 0x0C00, NULL
, HFILL
}},
502 {&hf_opcua_status_Limit
, {"Limit", "opcua.statuscode.limit", FT_UINT16
, BASE_HEX
, VALS(g_limit
), 0x0300, NULL
, HFILL
}},
503 {&hf_opcua_status_Historian
, {"Historian", "opcua.statuscode.historian", FT_UINT16
, BASE_HEX
, VALS(g_historian
), 0x0003, NULL
, HFILL
}},
504 {&hf_opcua_returnDiag
, {"Return Diagnostics", "opcua.returndiag", FT_UINT32
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}},
505 {&hf_opcua_returnDiag_mask_sl_symbolicId
, {"ServiceLevel / SymbolicId", "opcua.returndiag.servicelevel.symbolicid", FT_BOOLEAN
, 16, NULL
, RETURNDIAGNOSTICS_SERVICELEVEL_SYMBOLICID
, NULL
, HFILL
}},
506 {&hf_opcua_returnDiag_mask_sl_localizedText
, {"ServiceLevel / LocalizedText", "opcua.returndiag.servicelevel.localizedtext", FT_BOOLEAN
, 16, NULL
, RETURNDIAGNOSTICS_SERVICELEVEL_LOCALIZEDTEXT
, NULL
, HFILL
}},
507 {&hf_opcua_returnDiag_mask_sl_additionalinfo
, {"ServiceLevel / AdditionalInfo", "opcua.returndiag.servicelevel.additionalinfo", FT_BOOLEAN
, 16, NULL
, RETURNDIAGNOSTICS_SERVICELEVEL_ADDITIONALINFO
, NULL
, HFILL
}},
508 {&hf_opcua_returnDiag_mask_sl_innerstatuscode
, {"ServiceLevel / Inner StatusCode", "opcua.returndiag.servicelevel.innerstatuscode", FT_BOOLEAN
, 16, NULL
, RETURNDIAGNOSTICS_SERVICELEVEL_INNERSTATUSCODE
, NULL
, HFILL
}},
509 {&hf_opcua_returnDiag_mask_sl_innerdiagnostics
, {"ServiceLevel / Inner Diagnostics", "opcua.returndiag.servicelevel.innerdiagnostics", FT_BOOLEAN
, 16, NULL
, RETURNDIAGNOSTICS_SERVICELEVEL_INNERDIAGNOSTICS
, NULL
, HFILL
}},
510 {&hf_opcua_returnDiag_mask_ol_symbolicId
, {"OperationLevel / SymbolicId", "opcua.returndiag.operationlevel.symbolicid", FT_BOOLEAN
, 16, NULL
, RETURNDIAGNOSTICS_OPERATIONLEVEL_SYMBOLICID
, NULL
, HFILL
}},
511 {&hf_opcua_returnDiag_mask_ol_localizedText
, {"OperationLevel / LocalizedText", "opcua.returndiag.operationlevel.localizedtext", FT_BOOLEAN
, 16, NULL
, RETURNDIAGNOSTICS_OPERATIONLEVEL_LOCALIZEDTEXT
, NULL
, HFILL
}},
512 {&hf_opcua_returnDiag_mask_ol_additionalinfo
, {"OperationLevel / AdditionalInfo", "opcua.returndiag.operationlevel.additionalinfo", FT_BOOLEAN
, 16, NULL
, RETURNDIAGNOSTICS_OPERATIONLEVEL_ADDITIONALINFO
, NULL
, HFILL
}},
513 {&hf_opcua_returnDiag_mask_ol_innerstatuscode
, {"OperationLevel / Inner StatusCode", "opcua.returndiag.operationlevel.innerstatuscode", FT_BOOLEAN
, 16, NULL
, RETURNDIAGNOSTICS_OPERATIONLEVEL_INNERSTATUSCODE
, NULL
, HFILL
}},
514 {&hf_opcua_returnDiag_mask_ol_innerdiagnostics
, {"OperationLevel / Inner Diagnostics", "opcua.returndiag.operationlevel.innerdiagnostics", FT_BOOLEAN
, 16, NULL
, RETURNDIAGNOSTICS_OPERATIONLEVEL_INNERDIAGNOSTICS
, NULL
, HFILL
}},
515 {&hf_opcua_nodeClassMask
, {"Node Class Mask", "opcua.nodeclassmask", FT_UINT32
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}},
516 {&hf_opcua_nodeClassMask_all
, {"Node Class Mask", "opcua.nodeclassmask.all", FT_UINT32
, BASE_HEX
, VALS(g_NodeClassMask
), 0x0, NULL
, HFILL
}},
517 {&hf_opcua_nodeClassMask_object
, {"Object", "opcua.nodeclassmask.object", FT_BOOLEAN
, 16, NULL
, NODECLASSMASK_OBJECT
, NULL
, HFILL
}},
518 {&hf_opcua_nodeClassMask_variable
, {"Variable", "opcua.nodeclassmask.variable", FT_BOOLEAN
, 16, NULL
, NODECLASSMASK_VARIABLE
, NULL
, HFILL
}},
519 {&hf_opcua_nodeClassMask_method
, {"Method", "opcua.nodeclassmask.method", FT_BOOLEAN
, 16, NULL
, NODECLASSMASK_METHOD
, NULL
, HFILL
}},
520 {&hf_opcua_nodeClassMask_objecttype
, {"ObjectType", "opcua.nodeclassmask.objecttype", FT_BOOLEAN
, 16, NULL
, NODECLASSMASK_OBJECTTYPE
, NULL
, HFILL
}},
521 {&hf_opcua_nodeClassMask_variabletype
, {"VariableType", "opcua.nodeclassmask.variabletype", FT_BOOLEAN
, 16, NULL
, NODECLASSMASK_VARIABLETYPE
, NULL
, HFILL
}},
522 {&hf_opcua_nodeClassMask_referencetype
, {"ReferenceType", "opcua.nodeclassmask.referencetype", FT_BOOLEAN
, 16, NULL
, NODECLASSMASK_REFERENCETYPE
, NULL
, HFILL
}},
523 {&hf_opcua_nodeClassMask_datatype
, {"DataType", "opcua.nodeclassmask.datatype", FT_BOOLEAN
, 16, NULL
, NODECLASSMASK_DATATYPE
, NULL
, HFILL
}},
524 {&hf_opcua_nodeClassMask_view
, {"View", "opcua.nodeclassmask.view", FT_BOOLEAN
, 16, NULL
, NODECLASSMASK_VIEW
, NULL
, HFILL
}},
525 {&hf_opcua_resultMask
, {"Result Mask", "opcua.resultmask", FT_UINT32
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}},
526 {&hf_opcua_resultMask_referencetype
, {"Reference Type", "opcua.resultmask.referencetype", FT_BOOLEAN
, 16, NULL
, RESULTMASK_REFERENCETYPE
, NULL
, HFILL
}},
527 {&hf_opcua_resultMask_isforward
, {"Is Forward", "opcua.resultmask.isforward", FT_BOOLEAN
, 16, NULL
, RESULTMASK_ISFORWARD
, NULL
, HFILL
}},
528 {&hf_opcua_resultMask_nodeclass
, {"Node Class", "opcua.resultmask.nodeclass", FT_BOOLEAN
, 16, NULL
, RESULTMASK_NODECLASS
, NULL
, HFILL
}},
529 {&hf_opcua_resultMask_browsename
, {"Browse Name", "opcua.resultmask.browsename", FT_BOOLEAN
, 16, NULL
, RESULTMASK_BROWSENAME
, NULL
, HFILL
}},
530 {&hf_opcua_resultMask_displayname
, {"Display Name", "opcua.resultmask.displayname", FT_BOOLEAN
, 16, NULL
, RESULTMASK_DISPLAYNAME
, NULL
, HFILL
}},
531 {&hf_opcua_resultMask_typedefinition
, {"Type Definition", "opcua.resultmask.typedefinition", FT_BOOLEAN
, 16, NULL
, RESULTMASK_TYPEDEFINITION
, NULL
, HFILL
}},
532 {&hf_opcua_resultMask_all
, {"Result Mask", "opcua.resultmask.all", FT_UINT32
, BASE_HEX
, VALS(g_ResultMask
), 0x0, NULL
, HFILL
}},
535 static ei_register_info ei
[] = {
536 { &ei_array_length
, { "opcua.array.length", PI_UNDECODED
, PI_ERROR
, "Max array length exceeded", EXPFILL
}},
537 { &ei_nesting_depth
, { "opcua.nestingdepth", PI_UNDECODED
, PI_ERROR
, "Max nesting depth exceeded", EXPFILL
}},
540 proto_register_field_array(proto
, hf
, array_length(hf
));
541 proto_register_subtree_array(ett
, array_length(ett
));
543 expert_proto
= expert_register_protocol(proto
);
544 expert_register_field_array(expert_proto
, ei
, array_length(ei
));
547 proto_item
* parseBoolean(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo _U_
, int *pOffset
, int hfIndex
)
549 proto_item
*item
= proto_tree_add_item(tree
, hfIndex
, tvb
, *pOffset
, 1, ENC_LITTLE_ENDIAN
);
554 proto_item
* parseByte(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo _U_
, int *pOffset
, int hfIndex
)
556 proto_item
*item
= proto_tree_add_item(tree
, hfIndex
, tvb
, *pOffset
, 1, ENC_LITTLE_ENDIAN
);
561 proto_item
* parseSByte(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo _U_
, int *pOffset
, int hfIndex
)
563 proto_item
*item
= proto_tree_add_item(tree
, hfIndex
, tvb
, *pOffset
, 1, ENC_LITTLE_ENDIAN
);
568 proto_item
* parseUInt16(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo _U_
, int *pOffset
, int hfIndex
)
570 proto_item
*item
= proto_tree_add_item(tree
, hfIndex
, tvb
, *pOffset
, 2, ENC_LITTLE_ENDIAN
);
575 proto_item
* parseInt16(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo _U_
, int *pOffset
, int hfIndex
)
577 proto_item
*item
= proto_tree_add_item(tree
, hfIndex
, tvb
, *pOffset
, 2, ENC_LITTLE_ENDIAN
);
582 proto_item
* parseUInt32(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo _U_
, int *pOffset
, int hfIndex
)
584 proto_item
*item
= proto_tree_add_item(tree
, hfIndex
, tvb
, *pOffset
, 4, ENC_LITTLE_ENDIAN
);
589 proto_item
* parseInt32(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo _U_
, int *pOffset
, int hfIndex
)
591 proto_item
*item
= proto_tree_add_item(tree
, hfIndex
, tvb
, *pOffset
, 4, ENC_LITTLE_ENDIAN
);
596 proto_item
* parseUInt64(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo _U_
, int *pOffset
, int hfIndex
)
598 proto_item
*item
= proto_tree_add_item(tree
, hfIndex
, tvb
, *pOffset
, 8, ENC_LITTLE_ENDIAN
);
603 proto_item
* parseInt64(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo _U_
, int *pOffset
, int hfIndex
)
605 proto_item
*item
= proto_tree_add_item(tree
, hfIndex
, tvb
, *pOffset
, 8, ENC_LITTLE_ENDIAN
);
610 proto_item
* parseString(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo _U_
, int *pOffset
, int hfIndex
)
612 proto_item
*item
= NULL
;
614 int iOffset
= *pOffset
;
615 int32_t iLen
= tvb_get_letohl(tvb
, *pOffset
);
620 item
= proto_tree_add_item(tree
, hfIndex
, tvb
, *pOffset
, 0, ENC_NA
);
621 proto_item_append_text(item
, "[OpcUa Null String]");
622 proto_item_set_end(item
, tvb
, *pOffset
+ 4);
626 item
= proto_tree_add_item(tree
, hfIndex
, tvb
, *pOffset
, 0, ENC_NA
);
627 proto_item_append_text(item
, "[OpcUa Empty String]");
628 proto_item_set_end(item
, tvb
, *pOffset
+ 4);
632 item
= proto_tree_add_item(tree
, hfIndex
, tvb
, iOffset
, iLen
, ENC_UTF_8
|ENC_NA
);
633 iOffset
+= iLen
; /* eat the whole string */
637 item
= proto_tree_add_item(tree
, hfIndex
, tvb
, *pOffset
, 0, ENC_NA
);
638 szValue
= wmem_strdup_printf(pinfo
->pool
, "[Invalid String] Invalid length: %d", iLen
);
639 proto_item_append_text(item
, "%s", szValue
);
640 proto_item_set_end(item
, tvb
, *pOffset
+ 4);
647 proto_item
* parseString_ret_string_and_length(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo _U_
, int *pOffset
, int hfIndex
, const uint8_t **retval
, int *lenretval
)
649 proto_item
*item
= NULL
;
651 int iOffset
= *pOffset
;
652 int32_t iLen
= tvb_get_letohl(tvb
, *pOffset
);
664 item
= proto_tree_add_item(tree
, hfIndex
, tvb
, *pOffset
, 0, ENC_NA
);
665 proto_item_append_text(item
, "[OpcUa Null String]");
666 proto_item_set_end(item
, tvb
, *pOffset
+ 4);
670 item
= proto_tree_add_item(tree
, hfIndex
, tvb
, *pOffset
, 0, ENC_NA
);
671 proto_item_append_text(item
, "[OpcUa Empty String]");
672 proto_item_set_end(item
, tvb
, *pOffset
+ 4);
676 item
= proto_tree_add_item_ret_string_and_length(tree
, hfIndex
, tvb
, iOffset
, iLen
, ENC_UTF_8
|ENC_NA
, NULL
, retval
, lenretval
);
677 iOffset
+= iLen
; /* eat the whole string */
681 item
= proto_tree_add_item(tree
, hfIndex
, tvb
, *pOffset
, 0, ENC_NA
);
682 szValue
= wmem_strdup_printf(pinfo
->pool
, "[Invalid String] Invalid length: %d", iLen
);
683 proto_item_append_text(item
, "%s", szValue
);
684 proto_item_set_end(item
, tvb
, *pOffset
+ 4);
691 proto_item
* parseStatusCode(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo _U_
, int *pOffset
, int hfIndex
)
693 proto_item
*item
= NULL
;
694 uint32_t uStatusCode
= 0;
695 const char *szStatusCode
= NULL
;
697 item
= proto_tree_add_item(tree
, hfIndex
, tvb
, *pOffset
, 4, ENC_LITTLE_ENDIAN
);
699 uStatusCode
= tvb_get_letohl(tvb
, *pOffset
);
700 szStatusCode
= val_to_str_const(uStatusCode
& 0xFFFF0000, g_statusCodes
, "Unknown Status Code");
701 proto_item_append_text(item
, " [%s]", szStatusCode
);
703 /* check for status code info flags */
704 if (uStatusCode
& 0x0000FFFF)
706 int iOffset
= *pOffset
;
707 proto_tree
*flags_tree
;
708 proto_item
*ti_inner
;
710 flags_tree
= proto_item_add_subtree(item
, ett_opcua_statuscode
);
712 proto_tree_add_item(flags_tree
, hf_opcua_status_StructureChanged
, tvb
, iOffset
, 2, ENC_LITTLE_ENDIAN
);
713 proto_tree_add_item(flags_tree
, hf_opcua_status_SemanticsChanged
, tvb
, iOffset
, 2, ENC_LITTLE_ENDIAN
);
714 ti_inner
= proto_tree_add_item(flags_tree
, hf_opcua_status_InfoType
, tvb
, iOffset
, 2, ENC_LITTLE_ENDIAN
);
716 switch (uStatusCode
& 0x00000C00)
718 case STATUSCODE_INFOTYPE_DATAVALUE
:
720 /* InfoType == DataValue */
721 proto_tree
*tree_inner
;
723 tree_inner
= proto_item_add_subtree(ti_inner
, ett_opcua_statuscode_info
);
725 proto_tree_add_item(tree_inner
, hf_opcua_status_Limit
, tvb
, iOffset
, 2, ENC_LITTLE_ENDIAN
);
726 proto_tree_add_item(tree_inner
, hf_opcua_status_InfoBit_Limit_Overflow
, tvb
, iOffset
, 2, ENC_LITTLE_ENDIAN
);
727 proto_tree_add_item(tree_inner
, hf_opcua_status_InfoBit_Historian_MultiValue
, tvb
, iOffset
, 2, ENC_LITTLE_ENDIAN
);
728 proto_tree_add_item(tree_inner
, hf_opcua_status_InfoBit_Historian_ExtraData
, tvb
, iOffset
, 2, ENC_LITTLE_ENDIAN
);
729 proto_tree_add_item(tree_inner
, hf_opcua_status_InfoBit_Historian_Partial
, tvb
, iOffset
, 2, ENC_LITTLE_ENDIAN
);
730 proto_tree_add_item(tree_inner
, hf_opcua_status_Historian
, tvb
, iOffset
, 2, ENC_LITTLE_ENDIAN
);
741 void parseLocalizedText(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo
, int *pOffset
, const char *szFieldName
)
743 static int * const loctext_mask
[] = {&hf_opcua_loctext_mask_localeflag
,
744 &hf_opcua_loctext_mask_textflag
,
747 int iOffset
= *pOffset
;
748 uint8_t EncodingMask
;
752 subtree
= proto_tree_add_subtree_format(tree
, tvb
, *pOffset
, -1, ett_opcua_localizedtext
, &ti
, "%s: LocalizedText", szFieldName
);
754 /* parse encoding mask */
755 EncodingMask
= tvb_get_uint8(tvb
, iOffset
);
756 proto_tree_add_bitmask(subtree
, tvb
, iOffset
, hf_opcua_loctext_mask
, ett_opcua_localizedtext_encodingmask
, loctext_mask
, ENC_LITTLE_ENDIAN
);
759 if (EncodingMask
& LOCALIZEDTEXT_ENCODINGBYTE_LOCALE
)
761 parseString(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_localizedtext_locale
);
764 if (EncodingMask
& LOCALIZEDTEXT_ENCODINGBYTE_TEXT
)
766 parseString(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_localizedtext_text
);
769 proto_item_set_end(ti
, tvb
, iOffset
);
773 proto_item
* parseGuid(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo _U_
, int *pOffset
, int hfIndex
)
775 proto_item
*item
= proto_tree_add_item(tree
, hfIndex
, tvb
, *pOffset
, GUID_LEN
, ENC_LITTLE_ENDIAN
);
780 proto_item
* parseByteString(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo _U_
, int *pOffset
, int hfIndex
)
782 proto_item
*item
= NULL
;
784 int iOffset
= *pOffset
;
785 int32_t iLen
= tvb_get_letohl(tvb
, iOffset
);
790 item
= proto_tree_add_item(tree
, hfIndex
, tvb
, *pOffset
, 0, ENC_NA
);
791 proto_item_append_text(item
, "[OpcUa Null ByteString]");
792 proto_item_set_end(item
, tvb
, *pOffset
+ 4);
796 item
= proto_tree_add_item(tree
, hfIndex
, tvb
, *pOffset
, 0, ENC_NA
);
797 proto_item_append_text(item
, "[OpcUa Empty ByteString]");
798 proto_item_set_end(item
, tvb
, *pOffset
+ 4);
802 item
= proto_tree_add_item(tree
, hfIndex
, tvb
, iOffset
, iLen
, ENC_NA
);
803 iOffset
+= iLen
; /* eat the whole bytestring */
807 item
= proto_tree_add_item(tree
, hfIndex
, tvb
, *pOffset
, 0, ENC_NA
);
808 szValue
= wmem_strdup_printf(pinfo
->pool
, "[Invalid ByteString] Invalid length: %d", iLen
);
809 proto_item_append_text(item
, "%s", szValue
);
810 proto_item_set_end(item
, tvb
, *pOffset
+ 4);
817 proto_item
* parseXmlElement(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo
, int *pOffset
, int hfIndex
)
819 return parseByteString(tree
, tvb
, pinfo
, pOffset
, hfIndex
);
822 proto_item
* parseFloat(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo _U_
, int *pOffset
, int hfIndex
)
824 proto_item
*item
= proto_tree_add_item(tree
, hfIndex
, tvb
, *pOffset
, (int)sizeof(float), ENC_LITTLE_ENDIAN
);
825 *pOffset
+= (int)sizeof(float);
829 proto_item
* parseDouble(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo _U_
, int *pOffset
, int hfIndex
)
831 proto_item
*item
= proto_tree_add_item(tree
, hfIndex
, tvb
, *pOffset
, (int)sizeof(double), ENC_LITTLE_ENDIAN
);
832 *pOffset
+= (int)sizeof(double);
836 proto_item
* parseDateTime(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo _U_
, int *pOffset
, int hfIndex
)
838 proto_item
*item
= dissect_nttime(tvb
, tree
, *pOffset
, hfIndex
, ENC_LITTLE_ENDIAN
);
843 // NOLINTNEXTLINE(misc-no-recursion)
844 void parseDiagnosticInfo(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo
, int *pOffset
, const char *szFieldName
)
846 static int * const diag_mask
[] = {&hf_opcua_diag_mask_symbolicflag
,
847 &hf_opcua_diag_mask_namespaceflag
,
848 &hf_opcua_diag_mask_localizedtextflag
,
849 &hf_opcua_diag_mask_localeflag
,
850 &hf_opcua_diag_mask_additionalinfoflag
,
851 &hf_opcua_diag_mask_innerstatuscodeflag
,
852 &hf_opcua_diag_mask_innerdiaginfoflag
,
855 int iOffset
= *pOffset
;
856 uint8_t EncodingMask
;
859 unsigned opcua_nested_count
;
861 subtree
= proto_tree_add_subtree_format(tree
, tvb
, *pOffset
, -1, ett_opcua_diagnosticinfo
, &ti
, "%s: DiagnosticInfo", szFieldName
);
863 /* prevent a too high nesting depth */
864 opcua_nested_count
= GPOINTER_TO_UINT(p_get_proto_data(pinfo
->pool
, pinfo
, proto_opcua
, 0));
865 if (opcua_nested_count
>= MAX_NESTING_DEPTH
)
867 expert_add_info(pinfo
, ti
, &ei_nesting_depth
);
870 opcua_nested_count
++;
871 p_add_proto_data(pinfo
->pool
, pinfo
, proto_opcua
, 0, GUINT_TO_POINTER(opcua_nested_count
));
873 /* parse encoding mask */
874 EncodingMask
= tvb_get_uint8(tvb
, iOffset
);
875 proto_tree_add_bitmask(subtree
, tvb
, iOffset
, hf_opcua_diag_mask
, ett_opcua_diagnosticinfo_encodingmask
, diag_mask
, ENC_LITTLE_ENDIAN
);
878 increment_dissection_depth(pinfo
);
879 if (EncodingMask
& DIAGNOSTICINFO_ENCODINGMASK_SYMBOLICID_FLAG
)
881 parseInt32(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_diag_symbolicid
);
883 if (EncodingMask
& DIAGNOSTICINFO_ENCODINGMASK_NAMESPACE_FLAG
)
885 parseInt32(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_diag_namespace
);
887 if (EncodingMask
& DIAGNOSTICINFO_ENCODINGMASK_LOCALE_FLAG
)
889 parseInt32(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_diag_locale
);
891 if (EncodingMask
& DIAGNOSTICINFO_ENCODINGMASK_LOCALIZEDTEXT_FLAG
)
893 parseInt32(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_diag_localizedtext
);
895 if (EncodingMask
& DIAGNOSTICINFO_ENCODINGMASK_ADDITIONALINFO_FLAG
)
897 parseString(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_diag_additionalinfo
);
899 if (EncodingMask
& DIAGNOSTICINFO_ENCODINGMASK_INNERSTATUSCODE_FLAG
)
901 parseStatusCode(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_diag_innerstatuscode
);
903 if (EncodingMask
& DIAGNOSTICINFO_ENCODINGMASK_INNERDIAGNOSTICINFO_FLAG
)
905 parseDiagnosticInfo(subtree
, tvb
, pinfo
, &iOffset
, "Inner DiagnosticInfo");
907 decrement_dissection_depth(pinfo
);
909 proto_item_set_end(ti
, tvb
, iOffset
);
912 opcua_nested_count
--;
913 p_add_proto_data(pinfo
->pool
, pinfo
, proto_opcua
, 0, GUINT_TO_POINTER(opcua_nested_count
));
916 void parseQualifiedName(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo
, int *pOffset
, const char *szFieldName
)
919 proto_tree
*subtree
= proto_tree_add_subtree_format(tree
, tvb
, *pOffset
, -1,
920 ett_opcua_qualifiedname
, &ti
, "%s: QualifiedName", szFieldName
);
922 parseUInt16(subtree
, tvb
, pinfo
, pOffset
, hf_opcua_qualifiedname_id
);
923 parseString(subtree
, tvb
, pinfo
, pOffset
, hf_opcua_qualifiedname_name
);
925 proto_item_set_end(ti
, tvb
, *pOffset
);
928 void parseCertificate(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo
, int *pOffset
, int hfIndex
)
930 proto_item
*item
= NULL
;
932 int iOffset
= *pOffset
;
933 int32_t iLen
= tvb_get_letohl(tvb
, iOffset
);
938 item
= proto_tree_add_bytes_with_length(tree
, hfIndex
, tvb
, *pOffset
, 4, NULL
, 0);
939 proto_item_append_text(item
, "[OpcUa Null ByteString]");
943 item
= proto_tree_add_bytes_with_length(tree
, hfIndex
, tvb
, *pOffset
, 4, NULL
, 0);
944 proto_item_append_text(item
, "[OpcUa Empty ByteString]");
949 asn1_ctx_init(&asn1_ctx
, ASN1_ENC_BER
, true, pinfo
);
950 dissect_x509af_Certificate(false, tvb
, iOffset
, &asn1_ctx
, tree
, hfIndex
);
951 iOffset
+= iLen
; /* eat the whole bytestring */
955 item
= proto_tree_add_bytes_with_length(tree
, hfIndex
, tvb
, *pOffset
, 4, NULL
, 0);
956 szValue
= wmem_strdup_printf(pinfo
->pool
, "[Invalid ByteString] Invalid length: %d", iLen
);
957 proto_item_append_text(item
, "%s", szValue
);
963 // NOLINTNEXTLINE(misc-no-recursion)
964 void parseDataValue(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo
, int *pOffset
, const char *szFieldName
)
966 static int * const datavalue_mask
[] = {&hf_opcua_datavalue_mask_valueflag
,
967 &hf_opcua_datavalue_mask_statuscodeflag
,
968 &hf_opcua_datavalue_mask_sourcetimestampflag
,
969 &hf_opcua_datavalue_mask_servertimestampflag
,
970 &hf_opcua_datavalue_mask_sourcepicoseconds
,
971 &hf_opcua_datavalue_mask_serverpicoseconds
,
975 proto_tree
*subtree
= proto_tree_add_subtree_format(tree
, tvb
, *pOffset
, -1,
976 ett_opcua_datavalue
, &ti
, "%s: DataValue", szFieldName
);
977 int iOffset
= *pOffset
;
978 uint8_t EncodingMask
;
980 EncodingMask
= tvb_get_uint8(tvb
, iOffset
);
981 proto_tree_add_bitmask(subtree
, tvb
, iOffset
, hf_opcua_datavalue_mask
, ett_opcua_datavalue_encodingmask
, datavalue_mask
, ENC_LITTLE_ENDIAN
);
984 increment_dissection_depth(pinfo
);
985 if (EncodingMask
& DATAVALUE_ENCODINGBYTE_VALUE
)
987 parseVariant(subtree
, tvb
, pinfo
, &iOffset
, "Value");
989 if (EncodingMask
& DATAVALUE_ENCODINGBYTE_STATUSCODE
)
991 parseStatusCode(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_StatusCode
);
993 if (EncodingMask
& DATAVALUE_ENCODINGBYTE_SOURCETIMESTAMP
)
995 parseDateTime(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_SourceTimestamp
);
997 if (EncodingMask
& DATAVALUE_ENCODINGBYTE_SOURCEPICOSECONDS
)
999 parseUInt16(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_SourcePicoseconds
);
1001 if (EncodingMask
& DATAVALUE_ENCODINGBYTE_SERVERTIMESTAMP
)
1003 parseDateTime(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_ServerTimestamp
);
1005 if (EncodingMask
& DATAVALUE_ENCODINGBYTE_SERVERPICOSECONDS
)
1007 parseUInt16(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_ServerPicoseconds
);
1009 decrement_dissection_depth(pinfo
);
1011 proto_item_set_end(ti
, tvb
, iOffset
);
1015 // NOLINTNEXTLINE(misc-no-recursion)
1016 void parseVariant(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo
, int *pOffset
, const char *szFieldName
)
1019 proto_tree
*subtree
= proto_tree_add_subtree_format(tree
, tvb
, *pOffset
, -1,
1020 ett_opcua_variant
, &ti
, "%s: Variant", szFieldName
);
1021 int iOffset
= *pOffset
;
1022 uint8_t EncodingMask
;
1023 int32_t ArrayDimensions
= 0;
1024 unsigned opcua_nested_count
;
1026 /* prevent a too high nesting depth */
1027 opcua_nested_count
= GPOINTER_TO_UINT(p_get_proto_data(pinfo
->pool
, pinfo
, proto_opcua
, 0));
1028 if (opcua_nested_count
>= MAX_NESTING_DEPTH
)
1030 expert_add_info(pinfo
, ti
, &ei_nesting_depth
);
1033 opcua_nested_count
++;
1034 p_add_proto_data(pinfo
->pool
, pinfo
, proto_opcua
, 0, GUINT_TO_POINTER(opcua_nested_count
));
1036 EncodingMask
= tvb_get_uint8(tvb
, iOffset
);
1037 proto_tree_add_item(subtree
, hf_opcua_variant_encodingmask
, tvb
, iOffset
, 1, ENC_LITTLE_ENDIAN
);
1040 if (EncodingMask
& VARIANT_ARRAYMASK
)
1042 /* type is encoded in bits 0-5 */
1043 increment_dissection_depth(pinfo
);
1044 switch(EncodingMask
& 0x3f)
1046 case OpcUaType_Null
: break;
1047 case OpcUaType_Boolean
: parseArraySimple(subtree
, tvb
, pinfo
, &iOffset
, "Boolean", "Boolean", hf_opcua_Boolean
, parseBoolean
, ett_opcua_array_Boolean
); break;
1048 case OpcUaType_SByte
: parseArraySimple(subtree
, tvb
, pinfo
, &iOffset
, "SByte", "SByte", hf_opcua_SByte
, parseSByte
, ett_opcua_array_SByte
); break;
1049 case OpcUaType_Byte
: parseArraySimple(subtree
, tvb
, pinfo
, &iOffset
, "Byte", "Byte", hf_opcua_Byte
, parseByte
, ett_opcua_array_Byte
); break;
1050 case OpcUaType_Int16
: parseArraySimple(subtree
, tvb
, pinfo
, &iOffset
, "Int16", "Int16", hf_opcua_Int16
, parseInt16
, ett_opcua_array_Int16
); break;
1051 case OpcUaType_UInt16
: parseArraySimple(subtree
, tvb
, pinfo
, &iOffset
, "UInt16", "UInt16", hf_opcua_UInt16
, parseUInt16
, ett_opcua_array_UInt16
); break;
1052 case OpcUaType_Int32
: parseArraySimple(subtree
, tvb
, pinfo
, &iOffset
, "Int32", "Int32", hf_opcua_Int32
, parseInt32
, ett_opcua_array_Int32
); break;
1053 case OpcUaType_UInt32
: parseArraySimple(subtree
, tvb
, pinfo
, &iOffset
, "UInt32", "UInt32", hf_opcua_UInt32
, parseUInt32
, ett_opcua_array_UInt32
); break;
1054 case OpcUaType_Int64
: parseArraySimple(subtree
, tvb
, pinfo
, &iOffset
, "Int64", "Int64", hf_opcua_Int64
, parseInt64
, ett_opcua_array_Int64
); break;
1055 case OpcUaType_UInt64
: parseArraySimple(subtree
, tvb
, pinfo
, &iOffset
, "UInt64", "UInt64", hf_opcua_UInt64
, parseUInt64
, ett_opcua_array_UInt64
); break;
1056 case OpcUaType_Float
: parseArraySimple(subtree
, tvb
, pinfo
, &iOffset
, "Float", "Float", hf_opcua_Float
, parseFloat
, ett_opcua_array_Float
); break;
1057 case OpcUaType_Double
: parseArraySimple(subtree
, tvb
, pinfo
, &iOffset
, "Double", "Double", hf_opcua_Double
, parseDouble
, ett_opcua_array_Double
); break;
1058 case OpcUaType_String
: parseArraySimple(subtree
, tvb
, pinfo
, &iOffset
, "String", "String", hf_opcua_String
, parseString
, ett_opcua_array_String
); break;
1059 case OpcUaType_DateTime
: parseArraySimple(subtree
, tvb
, pinfo
, &iOffset
, "DateTime", "DateTime", hf_opcua_DateTime
, parseDateTime
, ett_opcua_array_DateTime
); break;
1060 case OpcUaType_Guid
: parseArraySimple(subtree
, tvb
, pinfo
, &iOffset
, "Guid", "Guid", hf_opcua_Guid
, parseGuid
, ett_opcua_array_Guid
); break;
1061 case OpcUaType_ByteString
: parseArraySimple(subtree
, tvb
, pinfo
, &iOffset
, "ByteString", "ByteString", hf_opcua_ByteString
, parseByteString
, ett_opcua_array_ByteString
); break;
1062 case OpcUaType_XmlElement
: parseArraySimple(subtree
, tvb
, pinfo
, &iOffset
, "XmlElement", "XmlElement", hf_opcua_XmlElement
, parseXmlElement
, ett_opcua_array_XmlElement
); break;
1063 case OpcUaType_NodeId
: parseArrayComplex(subtree
, tvb
, pinfo
, &iOffset
, "NodeId", "NodeId", parseNodeId
, ett_opcua_array_NodeId
); break;
1064 case OpcUaType_ExpandedNodeId
: parseArrayComplex(subtree
, tvb
, pinfo
, &iOffset
, "ExpandedNodeId", "ExpandedNodeId", parseExpandedNodeId
, ett_opcua_array_ExpandedNodeId
); break;
1065 case OpcUaType_StatusCode
: parseArraySimple(subtree
, tvb
, pinfo
, &iOffset
, "StatusCode", "StatusCode", hf_opcua_StatusCode
, parseStatusCode
, ett_opcua_array_StatusCode
); break;
1066 case OpcUaType_DiagnosticInfo
: parseArrayComplex(subtree
, tvb
, pinfo
, &iOffset
, "DiagnosticInfo", "DiagnosticInfo", parseDiagnosticInfo
, ett_opcua_array_DiagnosticInfo
); break;
1067 case OpcUaType_QualifiedName
: parseArrayComplex(subtree
, tvb
, pinfo
, &iOffset
, "QualifiedName", "QualifiedName", parseQualifiedName
, ett_opcua_array_QualifiedName
); break;
1068 case OpcUaType_LocalizedText
: parseArrayComplex(subtree
, tvb
, pinfo
, &iOffset
, "LocalizedText", "LocalizedText", parseLocalizedText
, ett_opcua_array_LocalizedText
); break;
1069 case OpcUaType_ExtensionObject
: parseArrayComplex(subtree
, tvb
, pinfo
, &iOffset
, "ExtensionObject", "ExtensionObject", parseExtensionObject
, ett_opcua_array_ExtensionObject
); break;
1070 case OpcUaType_DataValue
: parseArrayComplex(subtree
, tvb
, pinfo
, &iOffset
, "DataValue", "DataValue", parseDataValue
, ett_opcua_array_DataValue
); break;
1071 case OpcUaType_Variant
: parseArrayComplex(subtree
, tvb
, pinfo
, &iOffset
, "Variant", "Variant", parseVariant
, ett_opcua_array_Variant
); break;
1073 decrement_dissection_depth(pinfo
);
1075 if (EncodingMask
& VARIANT_ARRAYDIMENSIONS
)
1078 proto_tree
*subtree_2
= proto_tree_add_subtree(subtree
, tvb
, iOffset
, -1,
1079 ett_opcua_variant_arraydims
, &ti_2
, "ArrayDimensions");
1082 /* read array length */
1083 ArrayDimensions
= tvb_get_letohl(tvb
, iOffset
);
1084 proto_tree_add_item(subtree_2
, hf_opcua_ArraySize
, tvb
, iOffset
, 4, ENC_LITTLE_ENDIAN
);
1086 if (ArrayDimensions
> MAX_ARRAY_LEN
)
1088 proto_tree_add_expert_format(subtree_2
, pinfo
, &ei_array_length
, tvb
, iOffset
, 4, "ArrayDimensions length %d too large to process", ArrayDimensions
);
1093 for (i
=0; i
<ArrayDimensions
; i
++)
1095 parseInt32(subtree_2
, tvb
, pinfo
, &iOffset
, hf_opcua_Int32
);
1097 proto_item_set_end(ti_2
, tvb
, iOffset
);
1102 /* type is encoded in bits 0-5 */
1103 increment_dissection_depth(pinfo
);
1104 switch(EncodingMask
& 0x3f)
1106 case OpcUaType_Null
: break;
1107 case OpcUaType_Boolean
: parseBoolean(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_Boolean
); break;
1108 case OpcUaType_SByte
: parseSByte(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_SByte
); break;
1109 case OpcUaType_Byte
: parseByte(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_Byte
); break;
1110 case OpcUaType_Int16
: parseInt16(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_Int16
); break;
1111 case OpcUaType_UInt16
: parseUInt16(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_UInt16
); break;
1112 case OpcUaType_Int32
: parseInt32(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_Int32
); break;
1113 case OpcUaType_UInt32
: parseUInt32(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_UInt32
); break;
1114 case OpcUaType_Int64
: parseInt64(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_Int64
); break;
1115 case OpcUaType_UInt64
: parseUInt64(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_UInt64
); break;
1116 case OpcUaType_Float
: parseFloat(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_Float
); break;
1117 case OpcUaType_Double
: parseDouble(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_Double
); break;
1118 case OpcUaType_String
: parseString(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_String
); break;
1119 case OpcUaType_DateTime
: parseDateTime(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_DateTime
); break;
1120 case OpcUaType_Guid
: parseGuid(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_Guid
); break;
1121 case OpcUaType_ByteString
: parseByteString(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_ByteString
); break;
1122 case OpcUaType_XmlElement
: parseXmlElement(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_XmlElement
); break;
1123 case OpcUaType_NodeId
: parseNodeId(subtree
, tvb
, pinfo
, &iOffset
, "Value"); break;
1124 case OpcUaType_ExpandedNodeId
: parseExpandedNodeId(subtree
, tvb
, pinfo
, &iOffset
, "Value"); break;
1125 case OpcUaType_StatusCode
: parseStatusCode(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_StatusCode
); break;
1126 case OpcUaType_DiagnosticInfo
: parseDiagnosticInfo(subtree
, tvb
, pinfo
, &iOffset
, "Value"); break;
1127 case OpcUaType_QualifiedName
: parseQualifiedName(subtree
, tvb
, pinfo
, &iOffset
, "Value"); break;
1128 case OpcUaType_LocalizedText
: parseLocalizedText(subtree
, tvb
, pinfo
, &iOffset
, "Value"); break;
1129 case OpcUaType_ExtensionObject
: parseExtensionObject(subtree
, tvb
, pinfo
, &iOffset
, "Value"); break;
1130 case OpcUaType_DataValue
: parseDataValue(subtree
, tvb
, pinfo
, &iOffset
, "Value"); break;
1131 case OpcUaType_Variant
: parseVariant(subtree
, tvb
, pinfo
, &iOffset
, "Value"); break;
1133 decrement_dissection_depth(pinfo
);
1136 proto_item_set_end(ti
, tvb
, iOffset
);
1139 opcua_nested_count
--;
1140 p_add_proto_data(pinfo
->pool
, pinfo
, proto_opcua
, 0, GUINT_TO_POINTER(opcua_nested_count
));
1143 /** General parsing function for arrays of simple types.
1144 * All arrays have one 4 byte signed integer length information,
1145 * followed by n data elements.
1147 void parseArraySimple(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo
, int *pOffset
, const char *szFieldName
, const char *szTypeName
, int hfIndex
, fctSimpleTypeParser pParserFunction
, const int idx
)
1150 proto_tree
*subtree
= proto_tree_add_subtree_format(tree
, tvb
, *pOffset
, -1, idx
, &ti
, "%s: Array of %s", szFieldName
, szTypeName
);
1154 /* read array length */
1155 iLen
= tvb_get_letohl(tvb
, *pOffset
);
1156 proto_tree_add_item(subtree
, hf_opcua_ArraySize
, tvb
, *pOffset
, 4, ENC_LITTLE_ENDIAN
);
1158 if (iLen
> MAX_ARRAY_LEN
)
1160 proto_tree_add_expert_format(subtree
, pinfo
, &ei_array_length
, tvb
, *pOffset
, 4, "Array length %d too large to process", iLen
);
1165 for (i
=0; i
<iLen
; i
++)
1167 proto_item
*arrayItem
= (*pParserFunction
)(subtree
, tvb
, pinfo
, pOffset
, hfIndex
);
1168 if (arrayItem
!= NULL
)
1170 proto_item_prepend_text(arrayItem
, "[%i]: ", i
);
1173 proto_item_set_end(ti
, tvb
, *pOffset
);
1176 /** General parsing function for arrays of enums.
1177 * All arrays have one 4 byte signed integer length information,
1178 * followed by n data elements.
1180 void parseArrayEnum(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo
, int *pOffset
, const char *szFieldName
, const char *szTypeName
, fctEnumParser pParserFunction
, const int idx
)
1183 proto_tree
*subtree
= proto_tree_add_subtree_format(tree
, tvb
, *pOffset
, -1, idx
, &ti
, "%s: Array of %s", szFieldName
, szTypeName
);
1187 /* read array length */
1188 iLen
= tvb_get_letohl(tvb
, *pOffset
);
1189 proto_tree_add_item(subtree
, hf_opcua_ArraySize
, tvb
, *pOffset
, 4, ENC_LITTLE_ENDIAN
);
1191 if (iLen
> MAX_ARRAY_LEN
)
1193 proto_tree_add_expert_format(subtree
, pinfo
, &ei_array_length
, tvb
, *pOffset
, 4, "Array length %d too large to process", iLen
);
1198 for (i
=0; i
<iLen
; i
++)
1200 (*pParserFunction
)(subtree
, tvb
, pinfo
, pOffset
);
1202 proto_item_set_end(ti
, tvb
, *pOffset
);
1205 /** General parsing function for arrays of complex types.
1206 * All arrays have one 4 byte signed integer length information,
1207 * followed by n data elements.
1209 void parseArrayComplex(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo
, int *pOffset
, const char *szFieldName
, const char *szTypeName
, fctComplexTypeParser pParserFunction
, const int idx
)
1212 proto_tree
*subtree
= proto_tree_add_subtree_format(tree
, tvb
, *pOffset
, -1, idx
, &ti
, "%s: Array of %s", szFieldName
, szTypeName
);
1216 /* read array length */
1217 iLen
= tvb_get_letohl(tvb
, *pOffset
);
1218 proto_tree_add_item(subtree
, hf_opcua_ArraySize
, tvb
, *pOffset
, 4, ENC_LITTLE_ENDIAN
);
1220 if (iLen
> MAX_ARRAY_LEN
)
1222 proto_tree_add_expert_format(subtree
, pinfo
, &ei_array_length
, tvb
, *pOffset
, 4, "Array length %d too large to process", iLen
);
1227 for (i
=0; i
<iLen
; i
++)
1230 snprintf(szNum
, 20, "[%i]", i
);
1231 (*pParserFunction
)(subtree
, tvb
, pinfo
, pOffset
, szNum
);
1233 proto_item_set_end(ti
, tvb
, *pOffset
);
1236 void parseNodeId(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo
, int *pOffset
, const char *szFieldName
)
1239 proto_tree
*subtree
= proto_tree_add_subtree_format(tree
, tvb
, *pOffset
, -1, ett_opcua_nodeid
, &ti
, "%s: NodeId", szFieldName
);
1240 int iOffset
= *pOffset
;
1241 uint8_t EncodingMask
;
1243 EncodingMask
= tvb_get_uint8(tvb
, iOffset
);
1244 proto_tree_add_item(subtree
, hf_opcua_nodeid_encodingmask
, tvb
, iOffset
, 1, ENC_LITTLE_ENDIAN
);
1247 switch(EncodingMask
)
1249 case 0x00: /* two byte node id */
1250 proto_tree_add_item(subtree
, hf_opcua_nodeid_numeric
, tvb
, iOffset
, 1, ENC_LITTLE_ENDIAN
);
1253 case 0x01: /* four byte node id */
1254 proto_tree_add_item(subtree
, hf_opcua_nodeid_nsindex
, tvb
, iOffset
, 1, ENC_LITTLE_ENDIAN
);
1256 proto_tree_add_item(subtree
, hf_opcua_nodeid_numeric
, tvb
, iOffset
, 2, ENC_LITTLE_ENDIAN
);
1259 case 0x02: /* numeric, that does not fit into four bytes */
1260 proto_tree_add_item(subtree
, hf_opcua_nodeid_nsindex
, tvb
, iOffset
, 2, ENC_LITTLE_ENDIAN
);
1262 proto_tree_add_item(subtree
, hf_opcua_nodeid_numeric
, tvb
, iOffset
, 4, ENC_LITTLE_ENDIAN
);
1265 case 0x03: /* string */
1266 proto_tree_add_item(subtree
, hf_opcua_nodeid_nsindex
, tvb
, iOffset
, 2, ENC_LITTLE_ENDIAN
);
1268 parseString(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_nodeid_string
);
1270 case 0x04: /* guid */
1271 proto_tree_add_item(subtree
, hf_opcua_nodeid_nsindex
, tvb
, iOffset
, 2, ENC_LITTLE_ENDIAN
);
1273 parseGuid(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_nodeid_guid
);
1275 case 0x05: /* byte string */
1276 proto_tree_add_item(subtree
, hf_opcua_nodeid_nsindex
, tvb
, iOffset
, 2, ENC_LITTLE_ENDIAN
);
1278 parseByteString(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_nodeid_bytestring
);
1282 proto_item_set_end(ti
, tvb
, iOffset
);
1286 void parseExtensionObject(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo
, int *pOffset
, const char *szFieldName
)
1288 static int * const extobj_mask
[] = {&hf_opcua_extobj_mask_binbodyflag
,
1289 &hf_opcua_extobj_mask_xmlbodyflag
,
1292 int iOffset
= *pOffset
;
1293 uint8_t EncodingMask
;
1295 proto_tree
*extobj_tree
;
1297 unsigned opcua_nested_count
;
1299 /* add extension object subtree */
1300 extobj_tree
= proto_tree_add_subtree_format(tree
, tvb
, *pOffset
, -1, ett_opcua_extensionobject
, &ti
, "%s: ExtensionObject", szFieldName
);
1302 /* prevent a too high nesting depth */
1303 opcua_nested_count
= GPOINTER_TO_UINT(p_get_proto_data(pinfo
->pool
, pinfo
, proto_opcua
, 0));
1304 if (opcua_nested_count
>= MAX_NESTING_DEPTH
)
1306 expert_add_info(pinfo
, ti
, &ei_nesting_depth
);
1309 opcua_nested_count
++;
1310 p_add_proto_data(pinfo
->pool
, pinfo
, proto_opcua
, 0, GUINT_TO_POINTER(opcua_nested_count
));
1312 /* add nodeid subtree */
1313 TypeId
= getExtensionObjectType(tvb
, &iOffset
);
1314 parseNodeId(extobj_tree
, tvb
, pinfo
, &iOffset
, "TypeId");
1316 /* parse encoding mask */
1317 EncodingMask
= tvb_get_uint8(tvb
, iOffset
);
1318 proto_tree_add_bitmask(extobj_tree
, tvb
, iOffset
, hf_opcua_extobj_mask
, ett_opcua_extensionobject_encodingmask
, extobj_mask
, ENC_LITTLE_ENDIAN
);
1321 if (EncodingMask
& EXTOBJ_ENCODINGMASK_BINBODY_FLAG
) /* has binary body ? */
1323 dispatchExtensionObjectType(extobj_tree
, tvb
, pinfo
, &iOffset
, TypeId
);
1326 proto_item_set_end(ti
, tvb
, iOffset
);
1329 opcua_nested_count
--;
1330 p_add_proto_data(pinfo
->pool
, pinfo
, proto_opcua
, 0, GUINT_TO_POINTER(opcua_nested_count
));
1333 void parseExpandedNodeId(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo
, int *pOffset
, const char *szFieldName
)
1335 static int * const expandednodeid_mask
[] = {&hf_opcua_nodeid_encodingmask
,
1336 &hf_opcua_expandednodeid_mask_serverindex
,
1337 &hf_opcua_expandednodeid_mask_namespaceuri
,
1341 proto_tree
*subtree
= proto_tree_add_subtree_format(tree
, tvb
, *pOffset
, -1,
1342 ett_opcua_expandednodeid
, &ti
, "%s: ExpandedNodeId", szFieldName
);
1343 int iOffset
= *pOffset
;
1344 uint8_t EncodingMask
;
1346 EncodingMask
= tvb_get_uint8(tvb
, iOffset
);
1347 proto_tree_add_bitmask(subtree
, tvb
, iOffset
, hf_opcua_expandednodeid_mask
, ett_opcua_expandednodeid_encodingmask
, expandednodeid_mask
, ENC_LITTLE_ENDIAN
);
1350 switch(EncodingMask
& 0x0F)
1352 case 0x00: /* two byte node id */
1353 proto_tree_add_item(subtree
, hf_opcua_nodeid_numeric
, tvb
, iOffset
, 1, ENC_LITTLE_ENDIAN
);
1356 case 0x01: /* four byte node id */
1357 proto_tree_add_item(subtree
, hf_opcua_nodeid_nsindex
, tvb
, iOffset
, 1, ENC_LITTLE_ENDIAN
);
1359 proto_tree_add_item(subtree
, hf_opcua_nodeid_numeric
, tvb
, iOffset
, 2, ENC_LITTLE_ENDIAN
);
1362 case 0x02: /* numeric, that does not fit into four bytes */
1363 proto_tree_add_item(subtree
, hf_opcua_nodeid_nsindex
, tvb
, iOffset
, 2, ENC_LITTLE_ENDIAN
);
1365 proto_tree_add_item(subtree
, hf_opcua_nodeid_numeric
, tvb
, iOffset
, 4, ENC_LITTLE_ENDIAN
);
1368 case 0x03: /* string */
1369 proto_tree_add_item(subtree
, hf_opcua_nodeid_nsindex
, tvb
, iOffset
, 2, ENC_LITTLE_ENDIAN
);
1371 parseString(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_nodeid_string
);
1373 case 0x04: /* guid */
1374 proto_tree_add_item(subtree
, hf_opcua_nodeid_nsindex
, tvb
, iOffset
, 2, ENC_LITTLE_ENDIAN
);
1376 parseGuid(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_nodeid_guid
);
1378 case 0x05: /* byte string */
1379 proto_tree_add_item(subtree
, hf_opcua_nodeid_nsindex
, tvb
, iOffset
, 2, ENC_LITTLE_ENDIAN
);
1381 parseByteString(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_nodeid_bytestring
);
1385 if (EncodingMask
& NODEID_NAMESPACEURIFLAG
)
1387 parseString(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_NamespaceUri
);
1389 if (EncodingMask
& NODEID_SERVERINDEXFLAG
)
1391 parseUInt32(subtree
, tvb
, pinfo
, &iOffset
, hf_opcua_ServerIndex
);
1394 proto_item_set_end(ti
, tvb
, iOffset
);
1398 uint32_t getExtensionObjectType(tvbuff_t
*tvb
, int *pOffset
)
1400 int iOffset
= *pOffset
;
1401 uint8_t EncodingMask
;
1402 uint32_t Numeric
= 0;
1404 EncodingMask
= tvb_get_uint8(tvb
, iOffset
);
1407 switch(EncodingMask
)
1409 case 0x00: /* two byte node id */
1410 Numeric
= tvb_get_uint8(tvb
, iOffset
);
1413 case 0x01: /* four byte node id */
1415 Numeric
= tvb_get_letohs(tvb
, iOffset
);
1417 case 0x02: /* numeric, that does not fit into four bytes */
1419 Numeric
= tvb_get_letohl(tvb
, iOffset
);
1421 case 0x03: /* string */
1422 case 0x04: /* uri */
1423 case 0x05: /* guid */
1424 case 0x06: /* byte string */
1432 void parseNodeClassMask(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo _U_
, int *pOffset
)
1434 static int * const nodeclass_mask
[] = {
1435 &hf_opcua_nodeClassMask_object
,
1436 &hf_opcua_nodeClassMask_variable
,
1437 &hf_opcua_nodeClassMask_method
,
1438 &hf_opcua_nodeClassMask_objecttype
,
1439 &hf_opcua_nodeClassMask_variabletype
,
1440 &hf_opcua_nodeClassMask_referencetype
,
1441 &hf_opcua_nodeClassMask_datatype
,
1442 &hf_opcua_nodeClassMask_view
,
1445 uint8_t NodeClassMask
= tvb_get_uint8(tvb
, *pOffset
);
1446 if(NodeClassMask
== NODECLASSMASK_ALL
)
1448 proto_tree_add_item(tree
, hf_opcua_nodeClassMask_all
, tvb
, *pOffset
, 4, ENC_LITTLE_ENDIAN
);
1452 proto_tree_add_bitmask(tree
, tvb
, *pOffset
, hf_opcua_nodeClassMask
, ett_opcua_nodeClassMask
, nodeclass_mask
, ENC_LITTLE_ENDIAN
);
1457 void parseResultMask(proto_tree
*tree
, tvbuff_t
*tvb
, packet_info
*pinfo _U_
, int *pOffset
)
1459 static int * const browseresult_mask
[] = {
1460 &hf_opcua_resultMask_referencetype
,
1461 &hf_opcua_resultMask_isforward
,
1462 &hf_opcua_resultMask_nodeclass
,
1463 &hf_opcua_resultMask_browsename
,
1464 &hf_opcua_resultMask_displayname
,
1465 &hf_opcua_resultMask_typedefinition
,
1468 uint8_t ResultMask
= tvb_get_uint8(tvb
, *pOffset
);
1469 if(ResultMask
== RESULTMASK_ALL
)
1471 proto_tree_add_item(tree
, hf_opcua_resultMask_all
, tvb
, *pOffset
, 4, ENC_LITTLE_ENDIAN
);
1475 proto_tree_add_bitmask(tree
, tvb
, *pOffset
, hf_opcua_resultMask
, ett_opcua_resultMask
, browseresult_mask
, ENC_LITTLE_ENDIAN
);
1481 * Editor modelines - https://www.wireshark.org/tools/modelines.html
1486 * indent-tabs-mode: nil
1489 * vi: set shiftwidth=4 tabstop=8 expandtab:
1490 * :indentSize=4:tabSize=8:noTabs=true: