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 ******************************************************************************/
29 #include <epan/packet.h>
30 #include "opcua_simpletypes.h"
32 /** NodeId encoding mask table */
33 static const value_string g_nodeidmasks[] = {
34 { 0, "Two byte encoded Numeric" },
35 { 1, "Four byte encoded Numeric" },
36 { 2, "Numeric of arbitrary length" },
45 /** Service type table */
46 extern const value_string g_requesttypes[];
48 static int hf_opcua_nodeid_encodingmask = -1;
49 static int hf_opcua_app_nsid = -1;
50 static int hf_opcua_app_numeric = -1;
52 /** header field definitions */
53 static hf_register_info hf[] =
55 { &hf_opcua_nodeid_encodingmask,
56 { "NodeId EncodingMask", "application.nodeid.encodingmask", FT_UINT8, BASE_HEX, VALS(g_nodeidmasks), 0x0, "", HFILL }
59 { "NodeId EncodingMask", "application.nodeid.nsid", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }
61 { &hf_opcua_app_numeric,
62 { "NodeId Identifier Numeric", "application.nodeid.numeric", FT_UINT32, BASE_DEC, VALS(g_requesttypes), 0x0, "", HFILL }
66 /** Register application layer types. */
67 void registerApplicationLayerTypes(int proto)
69 proto_register_field_array(proto, hf, array_length(hf));
72 /** Parses an OpcUa Service NodeId and returns the service type.
73 * In this cases the NodeId is always from type numeric and NSId = 0.
75 int parseServiceNodeId(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
77 gint iOffset = *pOffset;
78 guint8 EncodingMask, NSId = 0;
81 szFieldName = 0; /* avoid warning */
83 EncodingMask = tvb_get_guint8(tvb, iOffset);
84 proto_tree_add_item(tree, hf_opcua_nodeid_encodingmask, tvb, iOffset, 1, TRUE);
89 case 0x00: /* two byte node id */
90 Numeric = tvb_get_guint8(tvb, iOffset);
91 proto_tree_add_item(tree, hf_opcua_app_numeric, tvb, iOffset, 1, TRUE);
94 case 0x01: /* four byte node id */
95 NSId = tvb_get_guint8(tvb, iOffset);
96 proto_tree_add_item(tree, hf_opcua_app_nsid, tvb, iOffset, 1, TRUE);
98 Numeric = tvb_get_letohs(tvb, iOffset);
99 proto_tree_add_item(tree, hf_opcua_app_numeric, tvb, iOffset, 2, TRUE);
102 case 0x02: /* numeric, that does not fit into four bytes */
103 NSId = tvb_get_letohl(tvb, iOffset);
104 proto_tree_add_item(tree, hf_opcua_app_nsid, tvb, iOffset, 4, TRUE);
106 Numeric = tvb_get_letohl(tvb, iOffset);
107 proto_tree_add_item(tree, hf_opcua_app_numeric, tvb, iOffset, 4, TRUE);
110 case 0x03: /* string */
112 case 0x05: /* guid */
113 case 0x06: /* byte string */