Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / plugins / epan / opcua / opcua_application_layer.c
blob8006a36696fc7e84b26c733734c0ad40b9189f08
1 /******************************************************************************
2 ** Copyright (C) 2006-2007 ascolab GmbH. All Rights Reserved.
3 ** Web: http://www.ascolab.com
4 **
5 ** SPDX-License-Identifier: GPL-2.0-or-later
6 **
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.
9 **
10 ** Project: OpcUa Wireshark Plugin
12 ** Description: OpcUa Application Layer Decoder.
14 ** Author: Gerhard Gappmeier <gerhard.gappmeier@ascolab.com>
15 ******************************************************************************/
17 #include "config.h"
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" },
27 { 0x03, "String" },
28 { 0x04, "GUID" },
29 { 0x05, "Opaque" },
30 { 0, NULL }
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)
60 uint8_t EncodingMask;
61 uint32_t Numeric = 0;
63 EncodingMask = tvb_get_uint8(tvb, offset);
64 offset++;
66 switch(EncodingMask)
68 case 0x00: /* two byte node id */
69 Numeric = tvb_get_uint8(tvb, offset);
70 break;
71 case 0x01: /* four byte node id */
72 offset+=1;
73 Numeric = tvb_get_letohs(tvb, offset);
74 break;
75 case 0x02: /* numeric, that does not fit into four bytes */
76 offset+=2;
77 Numeric = tvb_get_letohl(tvb, offset);
78 break;
79 case 0x03: /* string */
80 case 0x04: /* guid */
81 case 0x05: /* opaque*/
82 /* NOT USED */
83 break;
86 return Numeric;
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;
95 uint8_t EncodingMask;
96 uint32_t Numeric = 0;
98 EncodingMask = tvb_get_uint8(tvb, iOffset);
99 proto_tree_add_item(tree, hf_opcua_nodeid_encodingmask, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
100 iOffset++;
102 switch(EncodingMask)
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);
107 iOffset+=1;
108 break;
109 case 0x01: /* four byte node id */
110 proto_tree_add_item(tree, hf_opcua_app_nsid, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
111 iOffset+=1;
112 Numeric = tvb_get_letohs(tvb, iOffset);
113 proto_tree_add_item(tree, hf_opcua_app_numeric, tvb, iOffset, 2, ENC_LITTLE_ENDIAN);
114 iOffset+=2;
115 break;
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);
118 iOffset+=2;
119 Numeric = tvb_get_letohl(tvb, iOffset);
120 proto_tree_add_item(tree, hf_opcua_app_numeric, tvb, iOffset, 4, ENC_LITTLE_ENDIAN);
121 iOffset+=4;
122 break;
123 case 0x03: /* string */
124 case 0x04: /* guid */
125 case 0x05: /* opaque*/
126 /* NOT USED */
127 break;
130 *pOffset = iOffset;
132 return Numeric;
136 * Editor modelines - https://www.wireshark.org/tools/modelines.html
138 * Local variables:
139 * c-basic-offset: 4
140 * tab-width: 8
141 * indent-tabs-mode: nil
142 * End:
144 * vi: set shiftwidth=4 tabstop=8 expandtab:
145 * :indentSize=4:tabSize=8:noTabs=true: