add the list of DISSECTOR_INCLUDES
[obnox/wireshark/wip.git] / plugins / opcua / ua_application_layer.c
1 /******************************************************************************
2 ** $Id$
3 **
4 ** Copyright (C) 2006-2007 ascolab GmbH. All Rights Reserved.
5 ** Web: http://www.ascolab.com
6 ** 
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.
11 ** 
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.
14 ** 
15 ** Project: OpcUa Wireshark Plugin
16 **
17 ** Description: OpcUa Application Layer Decoder.
18 **
19 ** Author: Gerhard Gappmeier <gerhard.gappmeier@ascolab.com>
20 ** Last change by: $Author: gergap $
21 **
22 ******************************************************************************/
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include <gmodule.h>
29 #include <epan/packet.h>
30 #include "opcua_simpletypes.h"
31
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" },
37     { 3, "String" },
38     { 4, "URI" },
39     { 5, "GUID" },
40     { 6, "ByteString" },
41     { 0x80, "UriMask" },
42     { 0, NULL }
43 };
44
45 /** Service type table */
46 extern const value_string g_requesttypes[];
47
48 static int hf_opcua_nodeid_encodingmask = -1;
49 static int hf_opcua_app_nsid = -1;
50 static int hf_opcua_app_numeric = -1;
51
52 /** header field definitions */
53 static hf_register_info hf[] =
54 {
55     { &hf_opcua_nodeid_encodingmask,
56     {  "NodeId EncodingMask",        "application.nodeid.encodingmask", FT_UINT8,   BASE_HEX,  VALS(g_nodeidmasks), 0x0,    "",    HFILL }
57     },
58     { &hf_opcua_app_nsid,
59     {  "NodeId EncodingMask",        "application.nodeid.nsid",         FT_UINT8,   BASE_DEC,  NULL, 0x0,    "",    HFILL }
60     },
61     { &hf_opcua_app_numeric,
62     {  "NodeId Identifier Numeric",  "application.nodeid.numeric",      FT_UINT32,  BASE_DEC,  VALS(g_requesttypes), 0x0,    "",    HFILL }
63     }
64 };
65
66 /** Register application layer types. */
67 void registerApplicationLayerTypes(int proto)
68 {
69     proto_register_field_array(proto, hf, array_length(hf));
70 }
71
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.
74  */
75 int parseServiceNodeId(proto_tree *tree, tvbuff_t *tvb, gint *pOffset, char *szFieldName)
76 {
77     gint    iOffset = *pOffset;
78     guint8  EncodingMask, NSId = 0;
79     guint32 Numeric = 0;
80
81         szFieldName = 0; /* avoid warning */
82
83     EncodingMask = tvb_get_guint8(tvb, iOffset);
84     proto_tree_add_item(tree, hf_opcua_nodeid_encodingmask, tvb, iOffset, 1, TRUE);
85     iOffset++;
86
87     switch(EncodingMask)
88     {
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);
92         iOffset+=1;
93         break;
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);
97         iOffset+=1;
98         Numeric = tvb_get_letohs(tvb, iOffset);
99         proto_tree_add_item(tree, hf_opcua_app_numeric, tvb, iOffset, 2, TRUE);
100         iOffset+=2;
101         break;
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);
105         iOffset+=4;
106         Numeric = tvb_get_letohl(tvb, iOffset);
107         proto_tree_add_item(tree, hf_opcua_app_numeric, tvb, iOffset, 4, TRUE);
108         iOffset+=4;
109         break;
110     case 0x03: /* string */
111     case 0x04: /* uri */
112     case 0x05: /* guid */
113     case 0x06: /* byte string */
114         /* NOT USED */
115         break;
116     };
117
118     *pOffset = iOffset;
119
120     return Numeric;
121 }
122