Remove trailing whitespace
[metze/wireshark/wip.git] / plugins / opcua / opcua_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 #include "config.h"
25
26 #include <glib.h>
27 #include <epan/packet.h>
28 #include "opcua_simpletypes.h"
29 #include "opcua_application_layer.h"
30
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" },
36     { 3, "String" },
37     { 4, "URI" },
38     { 5, "GUID" },
39     { 6, "ByteString" },
40     { 0x80, "UriMask" },
41     { 0, NULL }
42 };
43
44 /** Service type table */
45 extern const value_string g_requesttypes[];
46
47 static int hf_opcua_nodeid_encodingmask = -1;
48 static int hf_opcua_app_nsid = -1;
49 static int hf_opcua_app_numeric = -1;
50
51 /** Register application layer types. */
52 void registerApplicationLayerTypes(int proto)
53 {
54     /** header field definitions */
55     static hf_register_info hf[] =
56     {
57         { &hf_opcua_nodeid_encodingmask,
58         {  "NodeId EncodingMask",        "application.nodeid.encodingmask", FT_UINT8,   BASE_HEX,  VALS(g_nodeidmasks), 0x0,    NULL,    HFILL }
59         },
60         { &hf_opcua_app_nsid,
61         {  "NodeId EncodingMask",        "application.nodeid.nsid",         FT_UINT8,   BASE_DEC,  NULL, 0x0,    NULL,    HFILL }
62         },
63         { &hf_opcua_app_numeric,
64         {  "NodeId Identifier Numeric",  "application.nodeid.numeric",      FT_UINT32,  BASE_DEC,  VALS(g_requesttypes), 0x0,    NULL,    HFILL }
65         }
66     };
67
68     proto_register_field_array(proto, hf, array_length(hf));
69 }
70
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.
73  */
74 int parseServiceNodeId(proto_tree *tree, tvbuff_t *tvb, gint *pOffset)
75 {
76     gint    iOffset = *pOffset;
77     guint8  EncodingMask;
78     guint32 Numeric = 0;
79
80     EncodingMask = tvb_get_guint8(tvb, iOffset);
81     proto_tree_add_item(tree, hf_opcua_nodeid_encodingmask, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
82     iOffset++;
83
84     switch(EncodingMask)
85     {
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);
89         iOffset+=1;
90         break;
91     case 0x01: /* four byte node id */
92         proto_tree_add_item(tree, hf_opcua_app_nsid, tvb, iOffset, 1, ENC_LITTLE_ENDIAN);
93         iOffset+=1;
94         Numeric = tvb_get_letohs(tvb, iOffset);
95         proto_tree_add_item(tree, hf_opcua_app_numeric, tvb, iOffset, 2, ENC_LITTLE_ENDIAN);
96         iOffset+=2;
97         break;
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);
100         iOffset+=4;
101         Numeric = tvb_get_letohl(tvb, iOffset);
102         proto_tree_add_item(tree, hf_opcua_app_numeric, tvb, iOffset, 4, ENC_LITTLE_ENDIAN);
103         iOffset+=4;
104         break;
105     case 0x03: /* string */
106     case 0x04: /* uri */
107     case 0x05: /* guid */
108     case 0x06: /* byte string */
109         /* NOT USED */
110         break;
111     };
112
113     *pOffset = iOffset;
114
115     return Numeric;
116 }
117
118