nexmon – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 /******************************************************************************
2 ** Copyright (C) 2006-2009 ascolab GmbH. All Rights Reserved.
3 ** Web: http://www.ascolab.com
4 **
5 ** This program is free software; you can redistribute it and/or
6 ** modify it under the terms of the GNU General Public License
7 ** as published by the Free Software Foundation; either version 2
8 ** of the License, or (at your option) any later version.
9 **
10 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
11 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12 **
13 ** Project: OpcUa Wireshark Plugin
14 **
15 ** Description: OpcUa Transport Layer Decoder.
16 **
17 ** Author: Gerhard Gappmeier <gerhard.gappmeier@ascolab.com>
18 ******************************************************************************/
19  
20 #include "config.h"
21  
22 #include <epan/packet.h>
23 #include "opcua_security_layer.h"
24 #include "opcua_application_layer.h"
25 #include "opcua_simpletypes.h"
26 #include "opcua_transport_layer.h"
27 #include "opcua_servicetable.h"
28  
29 static int hf_opcua_transport_type = -1;
30 static int hf_opcua_transport_chunk = -1;
31 static int hf_opcua_transport_size = -1;
32 static int hf_opcua_transport_ver = -1;
33 static int hf_opcua_transport_scid = -1;
34 static int hf_opcua_transport_rbs = -1;
35 static int hf_opcua_transport_sbs = -1;
36 static int hf_opcua_transport_mms = -1;
37 static int hf_opcua_transport_mcc = -1;
38 static int hf_opcua_transport_endpoint = -1;
39 static int hf_opcua_transport_error = -1;
40 static int hf_opcua_transport_reason = -1;
41 static int hf_opcua_transport_spu = -1;
42 static int hf_opcua_transport_scert = -1;
43 static int hf_opcua_transport_rcthumb = -1;
44 static int hf_opcua_transport_seq = -1;
45 static int hf_opcua_transport_rqid = -1;
46  
47 /** subtree types */
48 extern gint ett_opcua_nodeid;
49 extern gint ett_opcua_extensionobject;
50  
51 /** Register transport layer types. */
52 void registerTransportLayerTypes(int proto)
53 {
54 static hf_register_info hf[] =
55 {
56 /* id full name abbreviation type display strings bitmask blurb HFILL */
57 {&hf_opcua_transport_type, {"Message Type", "opcua.transport.type", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}},
58 {&hf_opcua_transport_chunk, {"Chunk Type", "opcua.transport.chunk", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}},
59 {&hf_opcua_transport_size, {"Message Size", "opcua.transport.size", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL}},
60 {&hf_opcua_transport_ver, {"Version", "opcua.transport.ver", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL}},
61 {&hf_opcua_transport_scid, {"SecureChannelId", "opcua.transport.scid", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL}},
62 {&hf_opcua_transport_rbs, {"ReceiveBufferSize", "opcua.transport.rbs", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL}},
63 {&hf_opcua_transport_sbs, {"SendBufferSize", "opcua.transport.sbs", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL}},
64 {&hf_opcua_transport_mms, {"MaxMessageSize", "opcua.transport.mms", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL}},
65 {&hf_opcua_transport_mcc, {"MaxChunkCount", "opcua.transport.mcc", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL}},
66 {&hf_opcua_transport_endpoint, {"EndPointUrl", "opcua.transport.endpoint", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}},
67 {&hf_opcua_transport_error, {"Error", "opcua.transport.error", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL}},
68 {&hf_opcua_transport_reason, {"Reason", "opcua.transport.reason", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}},
69 {&hf_opcua_transport_spu, {"SecurityPolicyUri", "opcua.security.spu", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL}},
70 {&hf_opcua_transport_scert, {"SenderCertificate", "opcua.security.scert", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL}},
71 {&hf_opcua_transport_rcthumb, {"ReceiverCertificateThumbprint", "opcua.security.rcthumb", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL}},
72 {&hf_opcua_transport_seq, {"SequenceNumber", "opcua.security.seq", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL}},
73 {&hf_opcua_transport_rqid, {"RequestId", "opcua.security.rqid", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL}},
74 };
75  
76 proto_register_field_array(proto, hf, array_length(hf));
77 }
78  
79 /* Transport Layer: message parsers */
80 int parseHello(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, gint *pOffset)
81 {
82 proto_tree_add_item(tree, hf_opcua_transport_type, tvb, *pOffset, 3, ENC_ASCII|ENC_NA); *pOffset+=3;
83 proto_tree_add_item(tree, hf_opcua_transport_chunk, tvb, *pOffset, 1, ENC_ASCII|ENC_NA); *pOffset+=1;
84 proto_tree_add_item(tree, hf_opcua_transport_size, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
85 proto_tree_add_item(tree, hf_opcua_transport_ver, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
86 proto_tree_add_item(tree, hf_opcua_transport_rbs, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
87 proto_tree_add_item(tree, hf_opcua_transport_sbs, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
88 proto_tree_add_item(tree, hf_opcua_transport_mms, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
89 proto_tree_add_item(tree, hf_opcua_transport_mcc, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
90 parseString(tree, tvb, pinfo, pOffset, hf_opcua_transport_endpoint);
91 return -1;
92 }
93  
94 int parseAcknowledge(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint *pOffset)
95 {
96 proto_tree_add_item(tree, hf_opcua_transport_type, tvb, *pOffset, 3, ENC_ASCII|ENC_NA); *pOffset+=3;
97 proto_tree_add_item(tree, hf_opcua_transport_chunk, tvb, *pOffset, 1, ENC_ASCII|ENC_NA); *pOffset+=1;
98 proto_tree_add_item(tree, hf_opcua_transport_size, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
99 proto_tree_add_item(tree, hf_opcua_transport_ver, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
100 proto_tree_add_item(tree, hf_opcua_transport_rbs, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
101 proto_tree_add_item(tree, hf_opcua_transport_sbs, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
102 proto_tree_add_item(tree, hf_opcua_transport_mms, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
103 proto_tree_add_item(tree, hf_opcua_transport_mcc, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
104 return -1;
105 }
106  
107 int parseError(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, gint *pOffset)
108 {
109 proto_tree_add_item(tree, hf_opcua_transport_type, tvb, *pOffset, 3, ENC_ASCII|ENC_NA); *pOffset+=3;
110 proto_tree_add_item(tree, hf_opcua_transport_chunk, tvb, *pOffset, 1, ENC_ASCII|ENC_NA); *pOffset+=1;
111 proto_tree_add_item(tree, hf_opcua_transport_size, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
112 parseStatusCode(tree, tvb, pinfo, pOffset, hf_opcua_transport_error);
113 parseString(tree, tvb, pinfo, pOffset, hf_opcua_transport_reason);
114 return -1;
115 }
116  
117 int parseMessage(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo _U_, gint *pOffset)
118 {
119 proto_tree_add_item(tree, hf_opcua_transport_type, tvb, *pOffset, 3, ENC_ASCII|ENC_NA); *pOffset+=3;
120 proto_tree_add_item(tree, hf_opcua_transport_chunk, tvb, *pOffset, 1, ENC_ASCII|ENC_NA); *pOffset+=1;
121 proto_tree_add_item(tree, hf_opcua_transport_size, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
122 proto_tree_add_item(tree, hf_opcua_transport_scid, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
123  
124 /* message data contains the security layer */
125 parseSecurityLayer(tree, tvb, pOffset);
126  
127 return -1;
128 }
129  
130 int parseService(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, gint *pOffset)
131 {
132 proto_item *ti;
133 proto_item *ti_inner;
134 proto_tree *encobj_tree;
135 proto_tree *nodeid_tree;
136 int ServiceId = 0;
137  
138 /* AT THE MOMENT NO SECURITY IS IMPLEMENTED IN UA.
139 * WE CAN JUST JUMP INTO THE APPLICATION LAYER DATA.
140 * THIS WILL CHAHNGE IN THE FUTURE. */
141  
142 /* add encodeable object subtree */
143 encobj_tree = proto_tree_add_subtree(tree, tvb, *pOffset, -1, ett_opcua_extensionobject, &ti, "OpcUa Service : Encodeable Object");
144  
145 /* add nodeid subtree */
146 nodeid_tree = proto_tree_add_subtree(encobj_tree, tvb, *pOffset, -1, ett_opcua_nodeid, &ti_inner, "TypeId : ExpandedNodeId");
147 ServiceId = parseServiceNodeId(nodeid_tree, tvb, pOffset);
148 proto_item_set_end(ti_inner, tvb, *pOffset);
149  
150 dispatchService(encobj_tree, tvb, pinfo, pOffset, ServiceId);
151  
152 proto_item_set_end(ti, tvb, *pOffset);
153 return ServiceId;
154 }
155  
156 int parseOpenSecureChannel(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, gint *pOffset)
157 {
158 proto_item *ti;
159 proto_item *ti_inner;
160 proto_tree *encobj_tree;
161 proto_tree *nodeid_tree;
162 int ServiceId = 0;
163  
164 proto_tree_add_item(tree, hf_opcua_transport_type, tvb, *pOffset, 3, ENC_ASCII|ENC_NA); *pOffset+=3;
165 proto_tree_add_item(tree, hf_opcua_transport_chunk, tvb, *pOffset, 1, ENC_ASCII|ENC_NA); *pOffset+=1;
166 proto_tree_add_item(tree, hf_opcua_transport_size, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
167 proto_tree_add_item(tree, hf_opcua_transport_scid, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
168 parseString(tree, tvb, pinfo, pOffset, hf_opcua_transport_spu);
169 parseByteString(tree, tvb, pinfo, pOffset, hf_opcua_transport_scert);
170 parseByteString(tree, tvb, pinfo, pOffset, hf_opcua_transport_rcthumb);
171 proto_tree_add_item(tree, hf_opcua_transport_seq, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
172 proto_tree_add_item(tree, hf_opcua_transport_rqid, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
173  
174 /* add encodeable object subtree */
175 encobj_tree = proto_tree_add_subtree(tree, tvb, *pOffset, -1, ett_opcua_extensionobject, &ti, "Message : Encodeable Object");
176  
177 /* add nodeid subtree */
178 nodeid_tree = proto_tree_add_subtree(encobj_tree, tvb, *pOffset, -1, ett_opcua_nodeid, &ti_inner, "TypeId : ExpandedNodeId");
179 ServiceId = parseServiceNodeId(nodeid_tree, tvb, pOffset);
180 proto_item_set_end(ti_inner, tvb, *pOffset);
181  
182 dispatchService(encobj_tree, tvb, pinfo, pOffset, ServiceId);
183  
184 proto_item_set_end(ti, tvb, *pOffset);
185 return ServiceId;
186 }
187  
188 int parseCloseSecureChannel(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, gint *pOffset)
189 {
190 proto_item *ti;
191 proto_item *ti_inner;
192 proto_tree *encobj_tree;
193 proto_tree *nodeid_tree;
194 int ServiceId = 0;
195  
196 proto_tree_add_item(tree, hf_opcua_transport_type, tvb, *pOffset, 3, ENC_ASCII|ENC_NA); *pOffset+=3;
197 proto_tree_add_item(tree, hf_opcua_transport_chunk, tvb, *pOffset, 1, ENC_ASCII|ENC_NA); *pOffset+=1;
198 proto_tree_add_item(tree, hf_opcua_transport_size, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
199 proto_tree_add_item(tree, hf_opcua_transport_scid, tvb, *pOffset, 4, ENC_LITTLE_ENDIAN); *pOffset+=4;
200  
201 parseSecurityLayer(tree, tvb, pOffset);
202  
203 /* add encodeable object subtree */
204 encobj_tree = proto_tree_add_subtree(tree, tvb, *pOffset, -1, ett_opcua_extensionobject, &ti, "Message : Encodeable Object");
205  
206 /* add nodeid subtree */
207 nodeid_tree = proto_tree_add_subtree(encobj_tree, tvb, *pOffset, -1, ett_opcua_nodeid, &ti_inner, "TypeId : ExpandedNodeId");
208 ServiceId = parseServiceNodeId(nodeid_tree, tvb, pOffset);
209 proto_item_set_end(ti_inner, tvb, *pOffset);
210  
211 dispatchService(encobj_tree, tvb, pinfo, pOffset, ServiceId);
212  
213 proto_item_set_end(ti, tvb, *pOffset);
214 return ServiceId;
215 }
216  
217 /*
218 * Editor modelines - http://www.wireshark.org/tools/modelines.html
219 *
220 * Local variables:
221 * c-basic-offset: 4
222 * tab-width: 8
223 * indent-tabs-mode: nil
224 * End:
225 *
226 * vi: set shiftwidth=4 tabstop=8 expandtab:
227 * :indentSize=4:tabSize=8:noTabs=true:
228 */