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: OpcUa Application Layer Decoder.
19 ** Author: Gerhard Gappmeier <gerhard.gappmeier@ascolab.com>
20 ** Last change by: $Author: gergap $
22 ******************************************************************************/
27 #include <epan/packet.h>
28 #include "opcua_simpletypes.h"
29 #include "opcua_application_layer.h"
31 /** NodeId encoding mask table */
32 static const value_string g_nodeidmasks[] = {
33 { 0, "Two byte encoded Numeric" },
34 { 1, "Four byte encoded Numeric" },
35 { 2, "Numeric of arbitrary length" },
44 /** Service type table */
45 extern const value_string g_requesttypes[];
47 static int hf_opcua_nodeid_encodingmask = -1;
48 static int hf_opcua_app_nsid = -1;
49 static int hf_opcua_app_numeric = -1;
51 /** Register application layer types. */
52 void registerApplicationLayerTypes(int proto)
54 /** header field definitions */
55 static hf_register_info hf[] =
57 { &hf_opcua_nodeid_encodingmask,
58 { "NodeId EncodingMask", "application.nodeid.encodingmask", FT_UINT8, BASE_HEX, VALS(g_nodeidmasks), 0x0, NULL, HFILL }
61 { "NodeId EncodingMask", "application.nodeid.nsid", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
63 { &hf_opcua_app_numeric,
64 { "NodeId Identifier Numeric", "application.nodeid.numeric", FT_UINT32, BASE_DEC, VALS(g_requesttypes), 0x0, NULL, HFILL }
68 proto_register_field_array(proto, hf, array_length(hf));
71 /** Parses an OpcUa Service NodeId and returns the service type.
72 * In this cases the NodeId is always from type numeric and NSId = 0.
74 int parseServiceNodeId(proto_tree *tree, tvbuff_t *tvb, gint *pOffset)
76 gint iOffset = *pOffset;
80 EncodingMask = tvb_get_guint8(tvb, iOffset);
81 proto_tree_add_item(tree, hf_opcua_nodeid_encodingmask, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
86 case 0x00: /* two byte node id */
87 Numeric = tvb_get_guint8(tvb, iOffset);
88 proto_tree_add_item(tree, hf_opcua_app_numeric, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
91 case 0x01: /* four byte node id */
92 proto_tree_add_item(tree, hf_opcua_app_nsid, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
94 Numeric = tvb_get_letohs(tvb, iOffset);
95 proto_tree_add_item(tree, hf_opcua_app_numeric, tvb, iOffset, 2, ENC_LITTLE_ENDIAN);
98 case 0x02: /* numeric, that does not fit into four bytes */
99 proto_tree_add_item(tree, hf_opcua_app_nsid, tvb, iOffset, 4, ENC_LITTLE_ENDIAN);
101 Numeric = tvb_get_letohl(tvb, iOffset);
102 proto_tree_add_item(tree, hf_opcua_app_numeric, tvb, iOffset, 4, ENC_LITTLE_ENDIAN);
105 case 0x03: /* string */
107 case 0x05: /* guid */
108 case 0x06: /* byte string */