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: OpcUa Application Layer Decoder.
14 ** Author: Gerhard Gappmeier <gerhard.gappmeier@ascolab.com>
15 ******************************************************************************/
19 #include <epan/packet.h>
20 #include "opcua_application_layer.h"
22 /** NodeId encoding mask table */
23 static const value_string g_nodeidmasks
[] = {
24 { 0x00, "Two byte encoded Numeric" },
25 { 0x01, "Four byte encoded Numeric" },
26 { 0x02, "Numeric of arbitrary length" },
33 /** Service type table */
34 extern const value_string g_requesttypes
[];
36 static int hf_opcua_nodeid_encodingmask
;
37 static int hf_opcua_app_nsid
;
38 static int hf_opcua_app_numeric
;
40 /** Register application layer types. */
41 void registerApplicationLayerTypes(int proto
)
43 /** header field definitions */
44 static hf_register_info hf
[] =
46 /* id full name abbreviation type display strings bitmask blurb HFILL */
47 {&hf_opcua_nodeid_encodingmask
, {"NodeId EncodingMask", "opcua.servicenodeid.encodingmask", FT_UINT8
, BASE_HEX
, VALS(g_nodeidmasks
), 0x0, NULL
, HFILL
}},
48 {&hf_opcua_app_nsid
, {"NodeId Namespace Index", "opcua.servicenodeid.nsid", FT_UINT8
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
}},
49 {&hf_opcua_app_numeric
, {"NodeId Identifier Numeric", "opcua.servicenodeid.numeric", FT_UINT32
, BASE_DEC
, VALS(g_requesttypes
), 0x0, NULL
, HFILL
}}
52 proto_register_field_array(proto
, hf
, array_length(hf
));
55 /** Decodes the service nodeid without modifying the tree or offset.
56 * Service NodeIds are alsways numeric.
58 int getServiceNodeId(tvbuff_t
*tvb
, int offset
)
63 EncodingMask
= tvb_get_uint8(tvb
, offset
);
68 case 0x00: /* two byte node id */
69 Numeric
= tvb_get_uint8(tvb
, offset
);
71 case 0x01: /* four byte node id */
73 Numeric
= tvb_get_letohs(tvb
, offset
);
75 case 0x02: /* numeric, that does not fit into four bytes */
77 Numeric
= tvb_get_letohl(tvb
, offset
);
79 case 0x03: /* string */
81 case 0x05: /* opaque*/
89 /** Parses an OpcUa Service NodeId and returns the service type.
90 * In this cases the NodeId is always from type numeric and NSId = 0.
92 int parseServiceNodeId(proto_tree
*tree
, tvbuff_t
*tvb
, int *pOffset
)
94 int iOffset
= *pOffset
;
98 EncodingMask
= tvb_get_uint8(tvb
, iOffset
);
99 proto_tree_add_item(tree
, hf_opcua_nodeid_encodingmask
, tvb
, iOffset
, 1, ENC_LITTLE_ENDIAN
);
104 case 0x00: /* two byte node id */
105 Numeric
= tvb_get_uint8(tvb
, iOffset
);
106 proto_tree_add_item(tree
, hf_opcua_app_numeric
, tvb
, iOffset
, 1, ENC_LITTLE_ENDIAN
);
109 case 0x01: /* four byte node id */
110 proto_tree_add_item(tree
, hf_opcua_app_nsid
, tvb
, iOffset
, 1, ENC_LITTLE_ENDIAN
);
112 Numeric
= tvb_get_letohs(tvb
, iOffset
);
113 proto_tree_add_item(tree
, hf_opcua_app_numeric
, tvb
, iOffset
, 2, ENC_LITTLE_ENDIAN
);
116 case 0x02: /* numeric, that does not fit into four bytes */
117 proto_tree_add_item(tree
, hf_opcua_app_nsid
, tvb
, iOffset
, 2, ENC_LITTLE_ENDIAN
);
119 Numeric
= tvb_get_letohl(tvb
, iOffset
);
120 proto_tree_add_item(tree
, hf_opcua_app_numeric
, tvb
, iOffset
, 4, ENC_LITTLE_ENDIAN
);
123 case 0x03: /* string */
124 case 0x04: /* guid */
125 case 0x05: /* opaque*/
136 * Editor modelines - https://www.wireshark.org/tools/modelines.html
141 * indent-tabs-mode: nil
144 * vi: set shiftwidth=4 tabstop=8 expandtab:
145 * :indentSize=4:tabSize=8:noTabs=true: