/src/wireshark/epan/dissectors/packet-devicenet.c
Line | Count | Source |
1 | | /* packet-devicenet.c |
2 | | * Routines for dissection of DeviceNet |
3 | | * DeviceNet Home: www.odva.org |
4 | | * |
5 | | * This dissector includes items from: |
6 | | * CIP Volume 3: DeviceNet Adaptation of CIP, Edition 1.14 |
7 | | * |
8 | | * Michael Mann |
9 | | * Erik Ivarsson <eriki@student.chalmers.se> |
10 | | * Hans-Jorgen Gunnarsson <hag@hms.se> |
11 | | * Copyright 2012 |
12 | | * |
13 | | * Wireshark - Network traffic analyzer |
14 | | * By Gerald Combs <gerald@wireshark.org> |
15 | | * Copyright 1998 Gerald Combs |
16 | | * |
17 | | * SPDX-License-Identifier: GPL-2.0-or-later |
18 | | */ |
19 | | #include "config.h" |
20 | | |
21 | | #include <epan/packet.h> |
22 | | #include <epan/uat.h> |
23 | | #include <epan/prefs.h> |
24 | | #include <epan/expert.h> |
25 | | #include <epan/address_types.h> |
26 | | #include <epan/to_str.h> |
27 | | |
28 | | #include "packet-cip.h" |
29 | | #include "packet-socketcan.h" |
30 | | |
31 | | void proto_register_devicenet(void); |
32 | | void proto_reg_handoff_devicenet(void); |
33 | | |
34 | | static dissector_handle_t devicenet_handle; |
35 | | |
36 | 14 | #define DEVICENET_CANID_MASK CAN_SFF_MASK |
37 | 0 | #define MESSAGE_GROUP_1_ID 0x03FF |
38 | 14 | #define MESSAGE_GROUP_1_MSG_MASK 0x03C0 |
39 | 0 | #define MESSAGE_GROUP_1_MAC_ID_MASK 0x003F |
40 | | |
41 | 0 | #define MESSAGE_GROUP_2_ID 0x05FF |
42 | 14 | #define MESSAGE_GROUP_2_MSG_MASK 0x0007 |
43 | 0 | #define MESSAGE_GROUP_2_MAC_ID_MASK 0x01F8 |
44 | | |
45 | 0 | #define MESSAGE_GROUP_3_ID 0x07BF |
46 | 14 | #define MESSAGE_GROUP_3_MSG_MASK 0x01C0 |
47 | 0 | #define MESSAGE_GROUP_3_MAC_ID_MASK 0x3F |
48 | 14 | #define MESSAGE_GROUP_3_FRAG_MASK 0x80 |
49 | 14 | #define MESSAGE_GROUP_3_XID_MASK 0x40 |
50 | | |
51 | 0 | #define MESSAGE_GROUP_4_ID 0x07EF |
52 | 28 | #define MESSAGE_GROUP_4_MSG_MASK 0x3F |
53 | | |
54 | | static int proto_devicenet; |
55 | | |
56 | | static int hf_devicenet_can_id; |
57 | | static int hf_devicenet_src_mac_id; |
58 | | static int hf_devicenet_data; |
59 | | static int hf_devicenet_grp_msg1_id; |
60 | | static int hf_devicenet_grp_msg2_id; |
61 | | static int hf_devicenet_grp_msg3_id; |
62 | | static int hf_devicenet_grp_msg3_frag; |
63 | | static int hf_devicenet_grp_msg3_xid; |
64 | | static int hf_devicenet_grp_msg3_dest_mac_id; |
65 | | static int hf_devicenet_grp_msg4_id; |
66 | | static int hf_devicenet_rr_bit; |
67 | | static int hf_devicenet_service_code; |
68 | | static int hf_devicenet_connection_id; |
69 | | static int hf_devicenet_open_exp_src_message_id; |
70 | | static int hf_devicenet_open_exp_dest_message_id; |
71 | | static int hf_devicenet_open_exp_msg_req_body_format; |
72 | | static int hf_devicenet_open_exp_msg_actual_body_format; |
73 | | static int hf_devicenet_open_exp_group_select; |
74 | | static int hf_devicenet_open_exp_msg_reserved; |
75 | | static int hf_devicenet_dup_mac_id_rr_bit; |
76 | | static int hf_devicenet_dup_mac_id_physical_port_number; |
77 | | static int hf_devicenet_dup_mac_id_serial_number; |
78 | | static int hf_devicenet_dup_mac_id_vendor; |
79 | | static int hf_devicenet_comm_fault_rsv; |
80 | | static int hf_devicenet_comm_fault_match; |
81 | | static int hf_devicenet_comm_fault_value; |
82 | | static int hf_devicenet_offline_ownership_reserved; |
83 | | static int hf_devicenet_offline_ownership_client_mac_id; |
84 | | static int hf_devicenet_offline_ownership_allocate; |
85 | | static int hf_devicenet_vendor; |
86 | | static int hf_devicenet_serial_number; |
87 | | static int hf_devicenet_class8; |
88 | | static int hf_devicenet_class16; |
89 | | static int hf_devicenet_instance8; |
90 | | static int hf_devicenet_instance16; |
91 | | static int hf_devicenet_attribute; |
92 | | static int hf_devicenet_fragment_type; |
93 | | static int hf_devicenet_fragment_count; |
94 | | |
95 | | static int ett_devicenet; |
96 | | static int ett_devicenet_can; |
97 | | static int ett_devicenet_contents; |
98 | | static int ett_devicenet_8_8; |
99 | | static int ett_devicenet_8_16; |
100 | | static int ett_devicenet_16_8; |
101 | | static int ett_devicenet_16_16; |
102 | | |
103 | | static expert_field ei_devicenet_invalid_service; |
104 | | static expert_field ei_devicenet_invalid_can_id; |
105 | | static expert_field ei_devicenet_invalid_msg_id; |
106 | | static expert_field ei_devicenet_frag_not_supported; |
107 | | |
108 | | static int devicenet_address_type = -1; |
109 | | |
110 | | enum node_behavior { |
111 | | NODE_BEHAVIOR_8_8 = 0, |
112 | | NODE_BEHAVIOR_8_16 = 1, |
113 | | NODE_BEHAVIOR_16_8 = 2, |
114 | | NODE_BEHAVIOR_16_16 = 3 |
115 | | }; |
116 | | |
117 | | /* UAT entry structure. */ |
118 | | typedef struct { |
119 | | unsigned mac_id; |
120 | | enum node_behavior behavior; |
121 | | |
122 | | } uat_devicenet_record_t; |
123 | | |
124 | | static uat_devicenet_record_t *uat_devicenet_records; |
125 | | static uat_t *devicenet_uat; |
126 | | static unsigned num_devicenet_records_uat; |
127 | | |
128 | 0 | static bool uat_devicenet_record_update_cb(void* r, char** err) { |
129 | 0 | uat_devicenet_record_t* rec = (uat_devicenet_record_t *)r; |
130 | |
|
131 | 0 | if (rec->mac_id > 63) { |
132 | 0 | *err = g_strdup("MAC ID must be between 0-63"); |
133 | 0 | return false; |
134 | 0 | } |
135 | 0 | return true; |
136 | 0 | } |
137 | | |
138 | 0 | UAT_DEC_CB_DEF(uat_devicenet_records, mac_id, uat_devicenet_record_t) Unexecuted instantiation: packet-devicenet.c:uat_devicenet_records_mac_id_set_cb Unexecuted instantiation: packet-devicenet.c:uat_devicenet_records_mac_id_tostr_cb |
139 | 0 | UAT_VS_DEF(uat_devicenet_records, behavior, uat_devicenet_record_t, enum node_behavior, NODE_BEHAVIOR_8_8, "string") Unexecuted instantiation: packet-devicenet.c:uat_devicenet_records_behavior_set_cb Unexecuted instantiation: packet-devicenet.c:uat_devicenet_records_behavior_tostr_cb |
140 | | |
141 | | #if 0 |
142 | | static const enum_val_t bodytype_devicenet_protocol_options[] = { |
143 | | { "eightovereight", "8/8", 0 }, |
144 | | { "eightoversixteen", "8/16", 1 }, |
145 | | { "sixteenovereight", "16/8", 2 }, |
146 | | { "sixteenoversixteen", "16/16", 3 }, |
147 | | { NULL, NULL, 0 } |
148 | | }; |
149 | | #endif |
150 | | |
151 | 0 | #define SC_OPEN_EXPLICIT_MESSAGE 0x4B |
152 | 0 | #define SC_CLOSE_EXPLICIT_MESSAGE 0x4C |
153 | 0 | #define SC_DEVICE_HEARTBEAT_MESSAGE 0x4D |
154 | 0 | #define SC_DEVICE_SHUTOWN_MESSAGE 0x4E |
155 | | |
156 | | static const value_string devicenet_service_code_vals[] = { |
157 | | GENERIC_SC_LIST |
158 | | |
159 | | { SC_OPEN_EXPLICIT_MESSAGE, "Open Explicit Message Connection Request" }, |
160 | | { SC_CLOSE_EXPLICIT_MESSAGE, "Close Connection Request" }, |
161 | | { SC_DEVICE_HEARTBEAT_MESSAGE, "Device Heartbeat Message" }, |
162 | | { SC_DEVICE_SHUTOWN_MESSAGE, "Device Shutdown Message" }, |
163 | | { 0, NULL } |
164 | | }; |
165 | | |
166 | | static const value_string devicenet_grp_msg1_vals[] = { |
167 | | { 0x0300, "Slave's I/O Multicast Poll Response" }, |
168 | | { 0x0340, "Slave's I/O Change of State or Cyclic Message" }, |
169 | | { 0x0380, "Slave's I/O Bit-Strobe Response Message" }, |
170 | | { 0x03C0, "Slave's I/O Poll Response or COS/Cyclic Ack Message" }, |
171 | | { 0, NULL } |
172 | | }; |
173 | | |
174 | | static const value_string devicenet_grp_msg2_vals[] = { |
175 | | { 0x00, "Master's I/O Bit-Strobe Command Message" }, |
176 | | { 0x01, "Master's I/O Multicast Poll Group ID" }, |
177 | | { 0x02, "Master's Change of State or Cyclic Acknowledge Message" }, |
178 | | { 0x03, "Slave's Explicit/Unconnected Response Messages" }, |
179 | | { 0x04, "Master's Explicit Request Messages" }, |
180 | | { 0x05, "Master's I/O Poll Command/COS/Cyclic Messages" }, |
181 | | { 0x06, "Group 2 Only Unconnected Explicit Request Messages" }, |
182 | | { 0x07, "Duplicate MAC ID Check Messages" }, |
183 | | { 0, NULL } |
184 | | }; |
185 | | |
186 | | static const value_string devicenet_grp_msg3_vals[] = { |
187 | | { 0x000, "Group 3 Message" }, |
188 | | { 0x040, "Group 3 Message" }, |
189 | | { 0x080, "Group 3 Message" }, |
190 | | { 0x0C0, "Group 3 Message" }, |
191 | | { 0x100, "Group 3 Message" }, |
192 | | { 0x140, "Unconnected Explicit Response Message" }, |
193 | | { 0x180, "Unconnected Explicit Request Message" }, |
194 | | { 0x1C0, "Invalid Group 3 Message" }, |
195 | | { 0, NULL } |
196 | | }; |
197 | | |
198 | 0 | #define GRP4_COMM_FAULT_RESPONSE 0x2C |
199 | 0 | #define GRP4_COMM_FAULT_REQUEST 0x2D |
200 | 0 | #define GRP4_OFFLINE_OWNER_RESPONSE 0x2E |
201 | 0 | #define GRP4_OFFLINE_OWNER_REQUEST 0x2F |
202 | | |
203 | | static const value_string devicenet_grp_msg4_vals[] = { |
204 | | { GRP4_COMM_FAULT_RESPONSE, "Communication Faulted Response Message" }, |
205 | | { GRP4_COMM_FAULT_REQUEST, "Communication Faulted Request Message" }, |
206 | | { GRP4_OFFLINE_OWNER_RESPONSE, "Offline Ownership Response Message" }, |
207 | | { GRP4_OFFLINE_OWNER_REQUEST, "Offline Ownership Request Message" }, |
208 | | { 0, NULL } |
209 | | }; |
210 | | |
211 | | static const value_string devicenet_message_body_format_vals[] = { |
212 | | { 0x00, "DeviceNet 8/8. Class ID = 8 bit integer, Instance ID = 8 bit integer" }, |
213 | | { 0x01, "DeviceNet 8/16. Class ID = 8 bit integer, Instance ID = 16 bit integer" }, |
214 | | { 0x02, "DeviceNet 16/16. Class ID = 16 bit integer. Instance ID = 16 bit integer" }, |
215 | | { 0x03, "DeviceNet 16/8. Class ID = 16 bit integer. Instance ID = 8 bit integer" }, |
216 | | { 0x04, "CIP Path. The addressing size is variable and is provided as a Packed EPATH on each request" }, |
217 | | { 0x05, "Reserved by DeviceNet" }, |
218 | | { 0x06, "Reserved by DeviceNet" }, |
219 | | { 0x07, "Reserved by DeviceNet" }, |
220 | | { 0x08, "Reserved by DeviceNet" }, |
221 | | { 0x09, "Reserved by DeviceNet" }, |
222 | | { 0x0A, "Reserved by DeviceNet" }, |
223 | | { 0x0B, "Reserved by DeviceNet" }, |
224 | | { 0x0C, "Reserved by DeviceNet" }, |
225 | | { 0x0D, "Reserved by DeviceNet" }, |
226 | | { 0x0E, "Reserved by DeviceNet" }, |
227 | | { 0x0F, "Reserved by DeviceNet" }, |
228 | | { 0, NULL } |
229 | | }; |
230 | | |
231 | | static const value_string devicenet_group_select_vals[] = { |
232 | | { 0x00, "Message Group 1" }, |
233 | | { 0x01, "Message Group 2" }, |
234 | | { 0x02, "Reserved" }, |
235 | | { 0x03, "Message Group 3" }, |
236 | | { 0x04, "Reserved by DeviceNet" }, |
237 | | { 0x05, "Reserved by DeviceNet" }, |
238 | | { 0x06, "Reserved by DeviceNet" }, |
239 | | { 0x07, "Reserved by DeviceNet" }, |
240 | | { 0x08, "Reserved by DeviceNet" }, |
241 | | { 0x09, "Reserved by DeviceNet" }, |
242 | | { 0x0A, "Reserved by DeviceNet" }, |
243 | | { 0x0B, "Reserved by DeviceNet" }, |
244 | | { 0x0C, "Reserved by DeviceNet" }, |
245 | | { 0x0D, "Reserved by DeviceNet" }, |
246 | | { 0x0E, "Reserved by DeviceNet" }, |
247 | | { 0x0F, "Reserved by Node Ping" }, |
248 | | { 0, NULL } |
249 | | }; |
250 | | |
251 | | static const value_string devicenet_fragmented_message_type_vals[] = { |
252 | | { 0, "First Fragment" }, |
253 | | { 1, "Middle fragment" }, |
254 | | { 2, "Last fragment" }, |
255 | | { 3, "Fragment Acknowledge" }, |
256 | | { 0, NULL } |
257 | | }; |
258 | | |
259 | | #if 0 |
260 | | static const value_string devicenet_io_attribute_vals[] = { |
261 | | {0x01, "Vendor ID"}, |
262 | | {0x02, "Device Type"}, |
263 | | {0x03, "Product Code"}, |
264 | | {0x04, "Revision"}, |
265 | | {0x05, "Status"}, |
266 | | {0x06, "Serial Number"}, |
267 | | {0x07, "Product Name"}, |
268 | | { 0, NULL } |
269 | | }; |
270 | | #endif |
271 | | |
272 | | static int body_type_8_over_8_dissection(uint8_t data_length, proto_tree *devicenet_tree, |
273 | | tvbuff_t *tvb, packet_info *pinfo _U_, int offset) |
274 | 0 | { |
275 | 0 | uint8_t class_id, attribute, instance; |
276 | 0 | const attribute_info_t* att_info; |
277 | 0 | int start_offset = offset, length; |
278 | 0 | proto_item* ti; |
279 | |
|
280 | 0 | devicenet_tree = proto_tree_add_subtree(devicenet_tree, tvb, offset, -1, ett_devicenet_8_8, NULL, "DeviceNet 8/8"); |
281 | |
|
282 | 0 | proto_tree_add_item_ret_uint8(devicenet_tree, hf_devicenet_class8, tvb, offset, 1, ENC_LITTLE_ENDIAN, &class_id); |
283 | 0 | offset++; |
284 | |
|
285 | 0 | proto_tree_add_item_ret_uint8(devicenet_tree, hf_devicenet_instance8, tvb, offset, 1, ENC_LITTLE_ENDIAN, &instance); |
286 | |
|
287 | 0 | offset++; |
288 | 0 | if (data_length > 3) |
289 | 0 | { |
290 | 0 | ti = proto_tree_add_item_ret_uint8(devicenet_tree, hf_devicenet_attribute, tvb, offset, 1, ENC_LITTLE_ENDIAN, &attribute); |
291 | 0 | att_info = cip_get_attribute(class_id, instance, attribute); |
292 | |
|
293 | 0 | if (att_info != NULL) |
294 | 0 | proto_item_append_text(ti, " (%s)", att_info->text); |
295 | |
|
296 | 0 | offset++; |
297 | 0 | } |
298 | |
|
299 | 0 | if (data_length > 4) |
300 | 0 | { |
301 | 0 | length = offset-start_offset; |
302 | 0 | proto_tree_add_item(devicenet_tree, hf_devicenet_data, tvb, offset, length, ENC_NA); |
303 | 0 | offset += length; |
304 | 0 | } |
305 | 0 | return offset; |
306 | 0 | } |
307 | | |
308 | | static int body_type_8_over_16_dissection(uint8_t data_length, proto_tree *devicenet_tree, |
309 | | tvbuff_t *tvb, packet_info *pinfo _U_, int offset) |
310 | 0 | { |
311 | 0 | uint32_t class_id, instance, attribute; |
312 | 0 | const attribute_info_t* att_info; |
313 | 0 | proto_item* ti; |
314 | |
|
315 | 0 | devicenet_tree = proto_tree_add_subtree(devicenet_tree, tvb, offset, -1, ett_devicenet_8_16, NULL, "DeviceNet 8/16"); |
316 | |
|
317 | 0 | proto_tree_add_item_ret_uint(devicenet_tree, hf_devicenet_class8, tvb, offset, 1, ENC_LITTLE_ENDIAN, &class_id); |
318 | 0 | offset++; |
319 | |
|
320 | 0 | proto_tree_add_item_ret_uint(devicenet_tree, hf_devicenet_instance16, tvb, offset, 2, ENC_LITTLE_ENDIAN, &instance); |
321 | |
|
322 | 0 | if (data_length > 4) |
323 | 0 | { |
324 | 0 | ti = proto_tree_add_item_ret_uint(devicenet_tree, hf_devicenet_attribute, tvb, offset, 1, ENC_LITTLE_ENDIAN, &attribute); |
325 | 0 | att_info = cip_get_attribute(class_id, instance, attribute); |
326 | |
|
327 | 0 | if (att_info != NULL) |
328 | 0 | proto_item_append_text(ti, " (%s)", att_info->text); |
329 | |
|
330 | 0 | offset++; |
331 | 0 | } |
332 | |
|
333 | 0 | return offset; |
334 | 0 | } |
335 | | |
336 | | static int body_type_16_over_8_dissection(uint8_t data_length, proto_tree *devicenet_tree, tvbuff_t *tvb, |
337 | | packet_info *pinfo _U_, int offset) |
338 | 0 | { |
339 | 0 | uint32_t class_id, instance, attribute; |
340 | 0 | const attribute_info_t* att_info; |
341 | 0 | proto_item* ti; |
342 | |
|
343 | 0 | devicenet_tree = proto_tree_add_subtree(devicenet_tree, tvb, offset, -1, ett_devicenet_16_8, NULL, "DeviceNet 16/8"); |
344 | |
|
345 | 0 | proto_tree_add_item_ret_uint(devicenet_tree, hf_devicenet_class16, tvb, offset, 2, ENC_LITTLE_ENDIAN, &class_id); |
346 | 0 | offset += 2; |
347 | |
|
348 | 0 | proto_tree_add_item_ret_uint(devicenet_tree, hf_devicenet_instance8, tvb, offset, 1, ENC_LITTLE_ENDIAN, &instance); |
349 | 0 | offset++; |
350 | |
|
351 | 0 | if (data_length > 4) |
352 | 0 | { |
353 | 0 | ti = proto_tree_add_item_ret_uint(devicenet_tree, hf_devicenet_attribute, tvb, offset, 1, ENC_LITTLE_ENDIAN, &attribute); |
354 | 0 | att_info = cip_get_attribute(class_id, instance, attribute); |
355 | |
|
356 | 0 | if (att_info != NULL) |
357 | 0 | proto_item_append_text(ti, " (%s)", att_info->text); |
358 | |
|
359 | 0 | offset++; |
360 | 0 | } |
361 | |
|
362 | 0 | return offset; |
363 | 0 | } |
364 | | |
365 | | static int body_type_16_over_16_dissection(uint8_t data_length, proto_tree *devicenet_tree, tvbuff_t *tvb, |
366 | | packet_info *pinfo _U_, int offset) |
367 | 0 | { |
368 | 0 | uint16_t class_id, instance, attribute; |
369 | 0 | const attribute_info_t* att_info; |
370 | 0 | proto_item* ti; |
371 | |
|
372 | 0 | devicenet_tree = proto_tree_add_subtree(devicenet_tree, tvb, offset, 4, ett_devicenet_16_16, NULL, "DeviceNet 16/16"); |
373 | |
|
374 | 0 | proto_tree_add_item_ret_uint16(devicenet_tree, hf_devicenet_class16, tvb, offset, 2, ENC_LITTLE_ENDIAN, &class_id); |
375 | 0 | offset += 2; |
376 | |
|
377 | 0 | proto_tree_add_item_ret_uint16(devicenet_tree, hf_devicenet_instance16, tvb, offset, 2, ENC_LITTLE_ENDIAN, &instance); |
378 | 0 | offset+=2; |
379 | |
|
380 | 0 | if (data_length > 5) |
381 | 0 | { |
382 | 0 | ti = proto_tree_add_item_ret_uint16(devicenet_tree, hf_devicenet_attribute, tvb, offset, 1, ENC_LITTLE_ENDIAN, &attribute); |
383 | 0 | att_info = cip_get_attribute(class_id, instance, attribute); |
384 | |
|
385 | 0 | if (att_info != NULL) |
386 | 0 | proto_item_append_text(ti, " (%s)", att_info->text); |
387 | |
|
388 | 0 | offset++; |
389 | 0 | } |
390 | |
|
391 | 0 | return offset; |
392 | 0 | } |
393 | | |
394 | | static int dissect_devicenet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data) |
395 | 0 | { |
396 | 0 | proto_item *ti, *can_id_item, |
397 | 0 | *msg_id_item, *service_item; |
398 | 0 | proto_tree *devicenet_tree, *can_tree, *content_tree; |
399 | |
|
400 | 0 | unsigned offset = 0; |
401 | 0 | uint16_t message_id; |
402 | 0 | uint32_t data_length = tvb_reported_length(tvb); |
403 | 0 | uint8_t source_mac; |
404 | 0 | struct can_info can_info; |
405 | 0 | uint8_t service_rr; |
406 | 0 | uint8_t *src_address, *dest_address; |
407 | |
|
408 | 0 | DISSECTOR_ASSERT(data); |
409 | 0 | can_info = *((struct can_info*)data); |
410 | |
|
411 | 0 | if (can_info.id & (CAN_ERR_FLAG | CAN_RTR_FLAG | CAN_EFF_FLAG)) |
412 | 0 | { |
413 | | /* Error, RTR and frames with extended ids are not for us. */ |
414 | 0 | return 0; |
415 | 0 | } |
416 | | |
417 | 0 | col_set_str(pinfo->cinfo, COL_PROTOCOL, "DeviceNet"); |
418 | |
|
419 | 0 | ti = proto_tree_add_item(tree, proto_devicenet, tvb, offset, -1, ENC_NA); |
420 | 0 | devicenet_tree = proto_item_add_subtree(ti, ett_devicenet); |
421 | |
|
422 | 0 | can_tree = proto_tree_add_subtree_format(devicenet_tree, tvb, 0, 0, ett_devicenet_can, NULL, "CAN Identifier: 0x%04x", can_info.id); |
423 | 0 | can_id_item = proto_tree_add_uint(can_tree, hf_devicenet_can_id, tvb, 0, 0, can_info.id); |
424 | 0 | proto_item_set_generated(can_id_item); |
425 | | |
426 | | /* |
427 | | * Message group 1 |
428 | | */ |
429 | 0 | if ( can_info.id <= MESSAGE_GROUP_1_ID ) |
430 | 0 | { |
431 | 0 | ti = proto_tree_add_uint(can_tree, hf_devicenet_grp_msg1_id, tvb, 0, 0, can_info.id); |
432 | 0 | proto_item_set_generated(ti); |
433 | 0 | ti = proto_tree_add_uint(can_tree, hf_devicenet_src_mac_id, tvb, 0, 0, can_info.id & MESSAGE_GROUP_1_MAC_ID_MASK); |
434 | 0 | proto_item_set_generated(ti); |
435 | | |
436 | | /* Set source address */ |
437 | 0 | src_address = (uint8_t*)wmem_alloc(pinfo->pool, 1); |
438 | 0 | *src_address = (uint8_t)(can_info.id & MESSAGE_GROUP_1_MAC_ID_MASK); |
439 | 0 | set_address(&pinfo->src, devicenet_address_type, 1, (const void*)src_address); |
440 | |
|
441 | 0 | message_id = can_info.id & MESSAGE_GROUP_1_MSG_MASK; |
442 | 0 | col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(message_id, devicenet_grp_msg1_vals, "Other Group 1 Message")); |
443 | |
|
444 | 0 | proto_tree_add_item(devicenet_tree, hf_devicenet_data, tvb, offset, data_length, ENC_NA); |
445 | 0 | } |
446 | | /* |
447 | | * Message group 2 |
448 | | */ |
449 | 0 | else if (can_info.id <= MESSAGE_GROUP_2_ID ) |
450 | 0 | { |
451 | 0 | ti = proto_tree_add_uint(can_tree, hf_devicenet_grp_msg2_id, tvb, 0, 0, can_info.id); |
452 | 0 | proto_item_set_generated(ti); |
453 | | |
454 | | /* create display subtree for the protocol */ |
455 | 0 | message_id = can_info.id & MESSAGE_GROUP_2_MSG_MASK; |
456 | 0 | col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(message_id, devicenet_grp_msg2_vals, "Unknown")); |
457 | |
|
458 | 0 | ti = proto_tree_add_uint(can_tree, hf_devicenet_src_mac_id, tvb, 0, 0, (can_info.id & MESSAGE_GROUP_2_MAC_ID_MASK) >> 3); |
459 | 0 | proto_item_set_generated(ti); |
460 | | |
461 | | /* Set source address */ |
462 | 0 | src_address = (uint8_t*)wmem_alloc(pinfo->pool, 1); |
463 | 0 | *src_address = (uint8_t)((can_info.id & MESSAGE_GROUP_2_MAC_ID_MASK) >> 3); |
464 | 0 | set_address(&pinfo->src, devicenet_address_type, 1, (const void*)src_address); |
465 | |
|
466 | 0 | content_tree = proto_tree_add_subtree(devicenet_tree, tvb, offset, -1, ett_devicenet_contents, NULL, "Contents"); |
467 | |
|
468 | 0 | switch (message_id) |
469 | 0 | { |
470 | 0 | case 0x0: |
471 | 0 | case 0x1: |
472 | 0 | case 0x2: |
473 | 0 | case 0x3: |
474 | 0 | case 0x4: |
475 | 0 | case 0x5: |
476 | 0 | proto_tree_add_item(content_tree, hf_devicenet_data, tvb, offset, data_length, ENC_NA); |
477 | 0 | break; |
478 | | |
479 | 0 | case 0x6: |
480 | 0 | proto_tree_add_item(content_tree, hf_devicenet_data, tvb, offset, data_length, ENC_NA); |
481 | 0 | break; |
482 | | |
483 | 0 | case 0x7: |
484 | 0 | proto_tree_add_item(content_tree, hf_devicenet_dup_mac_id_rr_bit, tvb, offset, 1, ENC_LITTLE_ENDIAN); |
485 | 0 | proto_tree_add_item(content_tree, hf_devicenet_dup_mac_id_physical_port_number, tvb, offset, 1, ENC_LITTLE_ENDIAN); |
486 | 0 | offset ++; |
487 | |
|
488 | 0 | proto_tree_add_item(content_tree, hf_devicenet_dup_mac_id_vendor, tvb, offset, 2, ENC_LITTLE_ENDIAN); |
489 | 0 | offset+=2; |
490 | |
|
491 | 0 | proto_tree_add_item(content_tree, hf_devicenet_dup_mac_id_serial_number, tvb, offset, 4, ENC_LITTLE_ENDIAN); |
492 | 0 | break; |
493 | 0 | } |
494 | 0 | } |
495 | | /* |
496 | | * Message group 3 |
497 | | */ |
498 | 0 | else if (can_info.id <= MESSAGE_GROUP_3_ID ) |
499 | 0 | { |
500 | 0 | uint8_t byte1; |
501 | |
|
502 | 0 | msg_id_item = proto_tree_add_uint(can_tree, hf_devicenet_grp_msg3_id, tvb, 0, 0, can_info.id); |
503 | 0 | proto_item_set_generated(msg_id_item); |
504 | 0 | ti = proto_tree_add_uint(can_tree, hf_devicenet_src_mac_id, tvb, 0, 0, can_info.id & MESSAGE_GROUP_3_MAC_ID_MASK); |
505 | 0 | proto_item_set_generated(ti); |
506 | | |
507 | | /* Set source address */ |
508 | 0 | src_address = (uint8_t*)wmem_alloc(pinfo->pool, 1); |
509 | 0 | *src_address = (uint8_t)(can_info.id & MESSAGE_GROUP_3_MAC_ID_MASK); |
510 | 0 | set_address(&pinfo->src, devicenet_address_type, 1, (const void*)src_address); |
511 | |
|
512 | 0 | message_id = can_info.id & MESSAGE_GROUP_3_MSG_MASK; |
513 | 0 | col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(message_id, devicenet_grp_msg3_vals, "Unknown")); |
514 | |
|
515 | 0 | proto_tree_add_item(devicenet_tree, hf_devicenet_grp_msg3_frag, tvb, offset, 1, ENC_NA); |
516 | 0 | proto_tree_add_item(devicenet_tree, hf_devicenet_grp_msg3_xid, tvb, offset, 1, ENC_NA); |
517 | 0 | proto_tree_add_item(devicenet_tree, hf_devicenet_grp_msg3_dest_mac_id, tvb, offset, 1, ENC_LITTLE_ENDIAN); |
518 | 0 | byte1 = tvb_get_uint8(tvb, offset); |
519 | 0 | source_mac = byte1 & MESSAGE_GROUP_3_MAC_ID_MASK; |
520 | | |
521 | | /* Set destination address */ |
522 | | /* XXX - This may be source address depending on message type. Need to adjust accordingly) */ |
523 | 0 | dest_address = (uint8_t*)wmem_alloc(pinfo->pool, 1); |
524 | 0 | *dest_address = (uint8_t)source_mac; |
525 | 0 | set_address(&pinfo->dst, devicenet_address_type, 1, (const void*)dest_address); |
526 | 0 | offset++; |
527 | |
|
528 | 0 | if (byte1 & MESSAGE_GROUP_3_FRAG_MASK) |
529 | 0 | { |
530 | 0 | col_set_str(pinfo->cinfo, COL_INFO, "Group 3 Message Fragment"); |
531 | |
|
532 | 0 | content_tree = proto_tree_add_subtree(devicenet_tree, tvb, offset, -1, ett_devicenet_contents, NULL, "Fragmentation"); |
533 | |
|
534 | 0 | proto_tree_add_item(content_tree, hf_devicenet_fragment_type, tvb, offset, 1, ENC_LITTLE_ENDIAN); |
535 | 0 | proto_tree_add_item(content_tree, hf_devicenet_fragment_count, tvb, offset, 1, ENC_LITTLE_ENDIAN); |
536 | | |
537 | | /* TODO: Handle fragmentation */ |
538 | 0 | proto_tree_add_expert_remaining(content_tree, pinfo, &ei_devicenet_frag_not_supported, tvb, offset); |
539 | |
|
540 | 0 | col_set_str(pinfo->cinfo, COL_INFO, |
541 | 0 | val_to_str_const((tvb_get_uint8(tvb, offset) & 0xC0) >> 6, |
542 | 0 | devicenet_fragmented_message_type_vals, |
543 | 0 | "Unknown fragmented message type")); |
544 | 0 | } |
545 | 0 | else |
546 | 0 | { |
547 | 0 | service_rr = tvb_get_uint8(tvb, offset); |
548 | |
|
549 | 0 | content_tree = proto_tree_add_subtree_format(devicenet_tree, tvb, offset, -1, ett_devicenet_contents, NULL, |
550 | 0 | "Service: %s (%s)", val_to_str_const(service_rr & CIP_SC_MASK, devicenet_service_code_vals, "Unknown"), |
551 | 0 | service_rr & CIP_SC_RESPONSE_MASK ? "Response" : "Request"); |
552 | |
|
553 | 0 | proto_tree_add_item(content_tree, hf_devicenet_rr_bit, tvb, offset, 1, ENC_LITTLE_ENDIAN); |
554 | 0 | service_item = proto_tree_add_item(content_tree, hf_devicenet_service_code, tvb, offset, 1, ENC_LITTLE_ENDIAN); |
555 | 0 | offset++; |
556 | |
|
557 | 0 | col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(service_rr & CIP_SC_MASK, devicenet_service_code_vals, "Unknown Service Code")); |
558 | 0 | if (service_rr & CIP_SC_RESPONSE_MASK) |
559 | 0 | { |
560 | 0 | col_append_str(pinfo->cinfo, COL_INFO, " - Response"); |
561 | 0 | } |
562 | 0 | else |
563 | 0 | { |
564 | 0 | col_append_str(pinfo->cinfo, COL_INFO, " - Request"); |
565 | 0 | } |
566 | |
|
567 | 0 | switch(message_id) |
568 | 0 | { |
569 | 0 | case 0x140: |
570 | 0 | switch(service_rr & CIP_SC_MASK) |
571 | 0 | { |
572 | 0 | case SC_OPEN_EXPLICIT_MESSAGE: |
573 | 0 | case SC_CLOSE_EXPLICIT_MESSAGE: |
574 | 0 | case SC_DEVICE_HEARTBEAT_MESSAGE: |
575 | 0 | case SC_DEVICE_SHUTOWN_MESSAGE: |
576 | | /* XXX - ERROR RESPONSE? */ |
577 | 0 | break; |
578 | 0 | default: |
579 | 0 | expert_add_info_format(pinfo, service_item, &ei_devicenet_invalid_service, |
580 | 0 | "Invalid service code (0x%x) for Group 3 Message ID 5", service_rr & CIP_SC_MASK); |
581 | 0 | break; |
582 | 0 | } |
583 | 0 | break; |
584 | 0 | case 0x180: |
585 | 0 | switch(service_rr & CIP_SC_MASK) |
586 | 0 | { |
587 | 0 | case SC_OPEN_EXPLICIT_MESSAGE: |
588 | 0 | case SC_CLOSE_EXPLICIT_MESSAGE: |
589 | 0 | break; |
590 | 0 | default: |
591 | 0 | expert_add_info_format(pinfo, service_item, &ei_devicenet_invalid_service, |
592 | 0 | "Invalid service code (0x%x) for Group 3 Message ID 6", service_rr & CIP_SC_MASK); |
593 | 0 | break; |
594 | 0 | } |
595 | 0 | break; |
596 | 0 | case 0x1C0: |
597 | 0 | expert_add_info_format(pinfo, msg_id_item, &ei_devicenet_invalid_msg_id, |
598 | 0 | "Invalid Group 3 Message ID (%d)", message_id); |
599 | 0 | break; |
600 | 0 | } |
601 | | |
602 | 0 | switch(service_rr & CIP_SC_MASK) |
603 | 0 | { |
604 | 0 | case SC_OPEN_EXPLICIT_MESSAGE: |
605 | | /* XXX - Create conversation to track connections */ |
606 | 0 | if (service_rr & CIP_SC_RESPONSE_MASK) |
607 | 0 | { |
608 | 0 | proto_tree_add_item(content_tree, hf_devicenet_open_exp_msg_reserved, tvb, offset, 1, ENC_LITTLE_ENDIAN); |
609 | 0 | proto_tree_add_item(content_tree, hf_devicenet_open_exp_msg_actual_body_format, tvb, offset, 1, ENC_LITTLE_ENDIAN); |
610 | 0 | offset++; |
611 | 0 | proto_tree_add_item(content_tree, hf_devicenet_open_exp_dest_message_id, tvb, offset, 1, ENC_LITTLE_ENDIAN); |
612 | 0 | proto_tree_add_item(content_tree, hf_devicenet_open_exp_src_message_id, tvb, offset, 1, ENC_LITTLE_ENDIAN); |
613 | 0 | offset++; |
614 | 0 | proto_tree_add_item(content_tree, hf_devicenet_connection_id, tvb, offset, 2, ENC_LITTLE_ENDIAN); |
615 | 0 | } |
616 | 0 | else |
617 | 0 | { |
618 | 0 | proto_tree_add_item(content_tree, hf_devicenet_open_exp_msg_reserved, tvb, offset, 1, ENC_LITTLE_ENDIAN); |
619 | 0 | proto_tree_add_item(content_tree, hf_devicenet_open_exp_msg_req_body_format, tvb, offset, 1, ENC_LITTLE_ENDIAN); |
620 | 0 | offset++; |
621 | 0 | proto_tree_add_item(content_tree, hf_devicenet_open_exp_group_select, tvb, offset, 1, ENC_LITTLE_ENDIAN); |
622 | 0 | proto_tree_add_item(content_tree, hf_devicenet_open_exp_src_message_id, tvb, offset, 1, ENC_LITTLE_ENDIAN); |
623 | 0 | } |
624 | 0 | break; |
625 | 0 | case SC_CLOSE_EXPLICIT_MESSAGE: |
626 | | /* XXX - Use conversation to track connections */ |
627 | 0 | if ((service_rr & CIP_SC_RESPONSE_MASK) == 0) |
628 | 0 | { |
629 | 0 | proto_tree_add_item(content_tree, hf_devicenet_connection_id, tvb, offset, 2, ENC_LITTLE_ENDIAN); |
630 | 0 | } |
631 | 0 | break; |
632 | 0 | default: |
633 | 0 | if(service_rr & CIP_SC_MASK) |
634 | 0 | { |
635 | 0 | proto_tree_add_item(devicenet_tree, hf_devicenet_data, tvb, offset, data_length - 2, ENC_NA); |
636 | 0 | } |
637 | 0 | else |
638 | 0 | { |
639 | 0 | unsigned channel; |
640 | |
|
641 | 0 | for (channel = 0; channel < num_devicenet_records_uat; channel++) |
642 | 0 | { |
643 | 0 | if (uat_devicenet_records[channel].mac_id == source_mac) |
644 | 0 | { |
645 | 0 | switch(uat_devicenet_records[channel].behavior) |
646 | 0 | { |
647 | 0 | case 0: |
648 | 0 | body_type_8_over_8_dissection(data_length, content_tree, tvb, pinfo, offset); |
649 | 0 | break; |
650 | 0 | case 1: |
651 | 0 | body_type_8_over_16_dissection(data_length, content_tree, tvb, pinfo, offset); |
652 | 0 | break; |
653 | 0 | case 2: |
654 | 0 | body_type_16_over_8_dissection(data_length, content_tree, tvb, pinfo, offset); |
655 | 0 | break; |
656 | 0 | case 3: |
657 | 0 | body_type_16_over_16_dissection(data_length, content_tree, tvb, pinfo, offset); |
658 | 0 | break; |
659 | 0 | default: |
660 | 0 | proto_tree_add_item(content_tree, hf_devicenet_data, tvb, offset, data_length, ENC_NA); |
661 | 0 | break; |
662 | 0 | } |
663 | 0 | } |
664 | 0 | } |
665 | | |
666 | | /* Don't have a behavior defined for this address, default to 8 over 8 */ |
667 | 0 | if (channel >= num_devicenet_records_uat) |
668 | 0 | { |
669 | 0 | body_type_8_over_8_dissection(data_length, content_tree, tvb, pinfo, offset); |
670 | 0 | } |
671 | 0 | } |
672 | 0 | break; |
673 | 0 | } |
674 | 0 | } |
675 | 0 | } |
676 | | /*Message group 4*/ |
677 | 0 | else if (can_info.id <= MESSAGE_GROUP_4_ID ) |
678 | 0 | { |
679 | 0 | ti = proto_tree_add_uint(can_tree, hf_devicenet_grp_msg4_id, tvb, 0, 0, can_info.id); |
680 | 0 | proto_item_set_generated(ti); |
681 | |
|
682 | 0 | message_id = can_info.id & MESSAGE_GROUP_4_MSG_MASK; |
683 | 0 | col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(message_id, devicenet_grp_msg4_vals, "Reserved Group 4 Message")); |
684 | |
|
685 | 0 | switch(message_id) |
686 | 0 | { |
687 | 0 | case GRP4_COMM_FAULT_RESPONSE: |
688 | 0 | case GRP4_COMM_FAULT_REQUEST: |
689 | 0 | if(data_length == 2) |
690 | 0 | { |
691 | 0 | proto_tree_add_item(devicenet_tree, hf_devicenet_comm_fault_rsv, tvb, offset, 1, ENC_LITTLE_ENDIAN); |
692 | 0 | proto_tree_add_item(devicenet_tree, hf_devicenet_comm_fault_match, tvb, offset, 1, ENC_LITTLE_ENDIAN); |
693 | 0 | proto_tree_add_item(devicenet_tree, hf_devicenet_comm_fault_value, tvb, offset, 1, ENC_LITTLE_ENDIAN); |
694 | 0 | offset++; |
695 | |
|
696 | 0 | proto_tree_add_item(devicenet_tree, hf_devicenet_rr_bit, tvb, offset, 1, ENC_LITTLE_ENDIAN); |
697 | 0 | proto_tree_add_item(devicenet_tree, hf_devicenet_service_code, tvb, offset, 1, ENC_LITTLE_ENDIAN); |
698 | |
|
699 | 0 | if( tvb_get_uint8(tvb, offset) & CIP_SC_RESPONSE_MASK) |
700 | 0 | { |
701 | 0 | col_append_str(pinfo->cinfo, COL_INFO, " - Response"); |
702 | 0 | } |
703 | 0 | else |
704 | 0 | { |
705 | 0 | col_append_str(pinfo->cinfo, COL_INFO, " - Request"); |
706 | 0 | } |
707 | 0 | } |
708 | 0 | else if(data_length == 8) |
709 | 0 | { |
710 | 0 | proto_tree_add_item(devicenet_tree, hf_devicenet_comm_fault_rsv, tvb, offset, 1, ENC_LITTLE_ENDIAN); |
711 | 0 | offset++; |
712 | |
|
713 | 0 | proto_tree_add_item(devicenet_tree, hf_devicenet_rr_bit, tvb, offset, 1, ENC_LITTLE_ENDIAN); |
714 | 0 | proto_tree_add_item(devicenet_tree, hf_devicenet_service_code, tvb, offset, 1, ENC_LITTLE_ENDIAN); |
715 | |
|
716 | 0 | if( tvb_get_uint8(tvb, offset) & CIP_SC_RESPONSE_MASK) |
717 | 0 | { |
718 | 0 | col_append_str(pinfo->cinfo, COL_INFO, " - Response"); |
719 | 0 | } |
720 | 0 | else |
721 | 0 | { |
722 | 0 | col_append_str(pinfo->cinfo, COL_INFO, " - Request"); |
723 | 0 | } |
724 | 0 | offset++; |
725 | |
|
726 | 0 | proto_tree_add_item(devicenet_tree, hf_devicenet_vendor, tvb, offset, 2, ENC_LITTLE_ENDIAN); |
727 | 0 | offset +=2; |
728 | 0 | proto_tree_add_item(devicenet_tree, hf_devicenet_serial_number, tvb, offset, 4, ENC_LITTLE_ENDIAN); |
729 | 0 | } |
730 | 0 | break; |
731 | 0 | case GRP4_OFFLINE_OWNER_REQUEST: |
732 | 0 | case GRP4_OFFLINE_OWNER_RESPONSE: |
733 | 0 | proto_tree_add_item(devicenet_tree, hf_devicenet_offline_ownership_reserved, tvb, offset, 1, ENC_LITTLE_ENDIAN); |
734 | 0 | proto_tree_add_item(devicenet_tree, hf_devicenet_offline_ownership_client_mac_id, tvb, offset, 1, ENC_LITTLE_ENDIAN); |
735 | 0 | offset++; |
736 | |
|
737 | 0 | proto_tree_add_item(devicenet_tree, hf_devicenet_rr_bit, tvb, offset, 1, ENC_LITTLE_ENDIAN); |
738 | |
|
739 | 0 | if( tvb_get_uint8(tvb, offset) & CIP_SC_RESPONSE_MASK) |
740 | 0 | { |
741 | 0 | col_append_str(pinfo->cinfo, COL_INFO, " - Response"); |
742 | 0 | } |
743 | 0 | else |
744 | 0 | { |
745 | 0 | col_append_str(pinfo->cinfo, COL_INFO, " - Request"); |
746 | 0 | } |
747 | |
|
748 | 0 | proto_tree_add_item(devicenet_tree, hf_devicenet_offline_ownership_allocate, tvb, offset, 1, ENC_LITTLE_ENDIAN); |
749 | 0 | offset++; |
750 | 0 | proto_tree_add_item(devicenet_tree, hf_devicenet_vendor, tvb, offset, 2, ENC_LITTLE_ENDIAN); |
751 | 0 | offset +=2; |
752 | 0 | proto_tree_add_item(devicenet_tree, hf_devicenet_serial_number, tvb, offset, 4, ENC_LITTLE_ENDIAN); |
753 | 0 | break; |
754 | 0 | } |
755 | 0 | } |
756 | | /*Invalid CAN message*/ |
757 | 0 | else |
758 | 0 | { |
759 | 0 | col_add_fstr(pinfo->cinfo, COL_INFO, "Invalid CAN Message 0x%06X", can_info.id); |
760 | 0 | expert_add_info_format(pinfo, can_id_item, &ei_devicenet_invalid_can_id, |
761 | 0 | "Invalid CAN Message 0x%04X", can_info.id); |
762 | 0 | } |
763 | | |
764 | 0 | return tvb_captured_length(tvb); |
765 | 0 | } |
766 | | |
767 | | static int devicenet_addr_to_str(const address* addr, char *buf, int buf_len) |
768 | 0 | { |
769 | 0 | const uint8_t *addrdata = (const uint8_t *)addr->data; |
770 | |
|
771 | 0 | uint32_to_str_buf(*addrdata, buf, buf_len); |
772 | 0 | return (int)strlen(buf); |
773 | 0 | } |
774 | | |
775 | | static int devicenet_addr_str_len(const address* addr _U_) |
776 | 0 | { |
777 | 0 | return 11; /* Leaves required space (10 bytes) for uint_to_str_back() */ |
778 | 0 | } |
779 | | |
780 | | static int devicenet_addr_len(void) |
781 | 0 | { |
782 | 0 | return 1; |
783 | 0 | } |
784 | | |
785 | | void proto_register_devicenet(void) |
786 | 14 | { |
787 | 14 | module_t *devicenet_module; |
788 | 14 | expert_module_t*expert_devicenet; |
789 | | |
790 | 14 | static hf_register_info hf[] = { |
791 | 14 | { &hf_devicenet_can_id, |
792 | 14 | {"CAN Identifier", "devicenet.can_id", |
793 | 14 | FT_UINT16, BASE_HEX, NULL, DEVICENET_CANID_MASK, |
794 | 14 | NULL, HFILL } |
795 | 14 | }, |
796 | 14 | { &hf_devicenet_src_mac_id, |
797 | 14 | { "Source MAC ID", "devicenet.src_mac_id", |
798 | 14 | FT_UINT8, BASE_DEC, NULL, 0, |
799 | 14 | NULL, HFILL } |
800 | 14 | }, |
801 | 14 | { &hf_devicenet_connection_id, |
802 | 14 | { "Connection ID", "devicenet.connection_id", |
803 | 14 | FT_UINT16, BASE_DEC, NULL, 0, |
804 | 14 | NULL, HFILL } |
805 | 14 | }, |
806 | 14 | { &hf_devicenet_data, |
807 | 14 | { "Data", "devicenet.data", |
808 | 14 | FT_BYTES, BASE_NONE, NULL, 0, |
809 | 14 | NULL, HFILL } |
810 | 14 | }, |
811 | 14 | { &hf_devicenet_grp_msg1_id, |
812 | 14 | { "Group 1 message ID", "devicenet.grp_msg1.id", |
813 | 14 | FT_UINT16, BASE_DEC, NULL, MESSAGE_GROUP_1_MSG_MASK, |
814 | 14 | NULL, HFILL } |
815 | 14 | }, |
816 | 14 | { &hf_devicenet_grp_msg2_id, |
817 | 14 | { "Group 2 message ID", "devicenet.grp_msg2.id", |
818 | 14 | FT_UINT16, BASE_DEC, NULL, MESSAGE_GROUP_2_MSG_MASK, |
819 | 14 | NULL, HFILL } |
820 | 14 | }, |
821 | 14 | { &hf_devicenet_grp_msg3_id, |
822 | 14 | { "Group 3 message ID", "devicenet.grp_msg3.id", |
823 | 14 | FT_UINT16, BASE_DEC, NULL, MESSAGE_GROUP_3_MSG_MASK, |
824 | 14 | NULL, HFILL } |
825 | 14 | }, |
826 | 14 | { &hf_devicenet_grp_msg3_dest_mac_id, |
827 | 14 | { "Destination MAC ID", "devicenet.dest_mac_id", |
828 | 14 | FT_UINT8, BASE_DEC, NULL, 0x3F, |
829 | 14 | NULL, HFILL } |
830 | 14 | }, |
831 | 14 | { &hf_devicenet_grp_msg3_frag, |
832 | 14 | { "Frag", "devicenet.grp_msg3.frag", |
833 | 14 | FT_BOOLEAN, 8, NULL, MESSAGE_GROUP_3_FRAG_MASK, |
834 | 14 | NULL, HFILL } |
835 | 14 | }, |
836 | 14 | { &hf_devicenet_grp_msg3_xid, |
837 | 14 | { "XID", "devicenet.grp_msg3.xid", |
838 | 14 | FT_BOOLEAN, 8, NULL, MESSAGE_GROUP_3_XID_MASK, |
839 | 14 | NULL, HFILL } |
840 | 14 | }, |
841 | 14 | { &hf_devicenet_grp_msg4_id, |
842 | 14 | { "Group 4 message ID", "devicenet.grp_msg4.id", |
843 | 14 | FT_UINT16, BASE_DEC, NULL, MESSAGE_GROUP_4_MSG_MASK, |
844 | 14 | NULL, HFILL } |
845 | 14 | }, |
846 | 14 | { &hf_devicenet_rr_bit, |
847 | 14 | { "Request/Response", "devicenet.rr", |
848 | 14 | FT_UINT8, BASE_DEC, VALS(cip_sc_rr), CIP_SC_RESPONSE_MASK, |
849 | 14 | "Request or Response message", HFILL } |
850 | 14 | }, |
851 | 14 | { &hf_devicenet_service_code, |
852 | 14 | { "Service Code", "devicenet.service", |
853 | 14 | FT_UINT8, BASE_DEC, VALS(devicenet_service_code_vals), CIP_SC_MASK, |
854 | 14 | NULL, HFILL } |
855 | 14 | }, |
856 | 14 | { &hf_devicenet_open_exp_src_message_id, |
857 | 14 | { "Source Message ID", "devicenet.open_message.src_message_id", |
858 | 14 | FT_UINT8, BASE_DEC, NULL, 0x0F, |
859 | 14 | NULL, HFILL } |
860 | 14 | }, |
861 | 14 | { &hf_devicenet_open_exp_dest_message_id, |
862 | 14 | { "Destination Message ID", "devicenet.open_message.dest_message_id", |
863 | 14 | FT_UINT8, BASE_DEC, NULL, 0xF0, |
864 | 14 | NULL, HFILL } |
865 | 14 | }, |
866 | 14 | { &hf_devicenet_open_exp_msg_reserved, |
867 | 14 | { "Reserved", "devicenet.open_message.reserved", |
868 | 14 | FT_UINT8, BASE_DEC, NULL, 0xF0, |
869 | 14 | NULL, HFILL } |
870 | 14 | }, |
871 | 14 | { &hf_devicenet_open_exp_msg_req_body_format, |
872 | 14 | { "Requested Message Body Format", "devicenet.open_message.req_body_format", |
873 | 14 | FT_UINT8, BASE_DEC, VALS(devicenet_message_body_format_vals), 0x0F, |
874 | 14 | NULL, HFILL } |
875 | 14 | }, |
876 | 14 | { &hf_devicenet_open_exp_msg_actual_body_format, |
877 | 14 | { "Actual Message Body Format", "devicenet.open_message.actual_body_format", |
878 | 14 | FT_UINT8, BASE_DEC, VALS(devicenet_message_body_format_vals), 0x0F, |
879 | 14 | NULL, HFILL } |
880 | 14 | }, |
881 | 14 | { &hf_devicenet_open_exp_group_select, |
882 | 14 | { "Group Select", "devicenet.open_message.group_select", |
883 | 14 | FT_UINT8, BASE_DEC, VALS(devicenet_group_select_vals), 0xF0, |
884 | 14 | NULL, HFILL } |
885 | 14 | }, |
886 | 14 | { &hf_devicenet_dup_mac_id_rr_bit, |
887 | 14 | { "Request/Response", "devicenet.dup_mac_id.rr", |
888 | 14 | FT_UINT8, BASE_DEC, VALS(cip_sc_rr), CIP_SC_RESPONSE_MASK, |
889 | 14 | "Duplicate MAC ID Request or Response message", HFILL } |
890 | 14 | }, |
891 | 14 | { &hf_devicenet_dup_mac_id_physical_port_number, |
892 | 14 | { "Physical port number", "devicenet.dup_mac_id.physical_port_number", |
893 | 14 | FT_UINT8, BASE_DEC, NULL, 0x7F, |
894 | 14 | "Duplicate MAC ID check message physical port number", HFILL } |
895 | 14 | }, |
896 | 14 | { &hf_devicenet_dup_mac_id_vendor, |
897 | 14 | { "Vendor ID", "devicenet.dup_mac_id.vendor", |
898 | 14 | FT_UINT16, BASE_HEX|BASE_EXT_STRING, &cip_vendor_vals_ext, 0, |
899 | 14 | NULL, HFILL } |
900 | 14 | }, |
901 | 14 | { &hf_devicenet_dup_mac_id_serial_number, |
902 | 14 | { "Serial Number", "devicenet.dup_mac_id.serial_number", |
903 | 14 | FT_UINT32, BASE_HEX, NULL, 0x00, |
904 | 14 | NULL, HFILL } |
905 | 14 | }, |
906 | 14 | { &hf_devicenet_vendor, |
907 | 14 | { "Vendor ID", "devicenet.vendor", |
908 | 14 | FT_UINT16, BASE_HEX|BASE_EXT_STRING, &cip_vendor_vals_ext, 0, |
909 | 14 | NULL, HFILL } |
910 | 14 | }, |
911 | 14 | { &hf_devicenet_serial_number, |
912 | 14 | { "Serial Number", "devicenet.serial_number", |
913 | 14 | FT_UINT32, BASE_HEX, NULL, 0x00, |
914 | 14 | NULL, HFILL } |
915 | 14 | }, |
916 | 14 | { &hf_devicenet_instance8, |
917 | 14 | { "Instance", "devicenet.instance", |
918 | 14 | FT_UINT8, BASE_HEX, NULL, 0x00, |
919 | 14 | NULL, HFILL } |
920 | 14 | }, |
921 | 14 | { &hf_devicenet_instance16, |
922 | 14 | { "Instance", "devicenet.instance", |
923 | 14 | FT_UINT16, BASE_HEX, NULL, 0x00, |
924 | 14 | NULL, HFILL } |
925 | 14 | }, |
926 | 14 | { &hf_devicenet_attribute, |
927 | 14 | { "Attribute", "devicenet.attribute", |
928 | 14 | FT_UINT8, BASE_HEX, NULL, 0x00, |
929 | 14 | NULL, HFILL } |
930 | 14 | }, |
931 | 14 | { &hf_devicenet_fragment_type, |
932 | 14 | { "Fragment Type", "devicenet.fragment_type", |
933 | 14 | FT_UINT8, BASE_HEX, VALS(devicenet_fragmented_message_type_vals), 0xC0, |
934 | 14 | NULL, HFILL } |
935 | 14 | }, |
936 | 14 | { &hf_devicenet_fragment_count, |
937 | 14 | { "Fragment Count", "devicenet.fragment_count", |
938 | 14 | FT_UINT8, BASE_HEX_DEC, NULL, 0x3F, |
939 | 14 | NULL, HFILL } |
940 | 14 | }, |
941 | 14 | { &hf_devicenet_class8, |
942 | 14 | { "Class", "devicenet.class", |
943 | 14 | FT_UINT8, BASE_HEX|BASE_EXT_STRING, &cip_class_names_vals_ext, 0, |
944 | 14 | NULL, HFILL } |
945 | 14 | }, |
946 | 14 | { &hf_devicenet_class16, |
947 | 14 | { "Class", "devicenet.class", |
948 | 14 | FT_UINT16, BASE_HEX|BASE_EXT_STRING, &cip_class_names_vals_ext, 0, |
949 | 14 | NULL, HFILL } |
950 | 14 | }, |
951 | 14 | { &hf_devicenet_comm_fault_rsv, |
952 | 14 | { "Reserved", "devicenet.comm_fault.reserved", |
953 | 14 | FT_UINT8, BASE_HEX, NULL, 0x80, |
954 | 14 | NULL, HFILL } |
955 | 14 | }, |
956 | 14 | { &hf_devicenet_comm_fault_match, |
957 | 14 | { "Match", "devicenet.comm_fault.match", |
958 | 14 | FT_UINT8, BASE_HEX, NULL, 0x40, |
959 | 14 | NULL, HFILL } |
960 | 14 | }, |
961 | 14 | {&hf_devicenet_comm_fault_value, |
962 | 14 | { "Value", "devicenet.comm_fault.value", |
963 | 14 | FT_UINT8, BASE_HEX, NULL, 0x3F, |
964 | 14 | "Comm Fault Value", HFILL } |
965 | 14 | }, |
966 | 14 | {&hf_devicenet_offline_ownership_reserved, |
967 | 14 | { "Reserved", "devicenet.offline_ownership.reserved", |
968 | 14 | FT_UINT8, BASE_HEX, NULL, 0xC0, |
969 | 14 | "Offline ownership Response Message Reserved", HFILL } |
970 | 14 | }, |
971 | 14 | {&hf_devicenet_offline_ownership_client_mac_id, |
972 | 14 | { "Client MAC ID", "devicenet.offline_ownership.client_mac_id", |
973 | 14 | FT_UINT8, BASE_HEX, NULL, MESSAGE_GROUP_4_MSG_MASK, |
974 | 14 | "Offline ownership message client MAC ID", HFILL } |
975 | 14 | }, |
976 | 14 | {&hf_devicenet_offline_ownership_allocate, |
977 | 14 | { "Allocate", "devicenet.offline_ownership.allocate", |
978 | 14 | FT_UINT8, BASE_HEX, NULL, CIP_SC_MASK, |
979 | 14 | "Offline ownership response message allocate", HFILL } |
980 | 14 | }, |
981 | 14 | }; |
982 | | |
983 | 14 | static int *ett[] = { |
984 | 14 | &ett_devicenet, |
985 | 14 | &ett_devicenet_can, |
986 | 14 | &ett_devicenet_contents, |
987 | 14 | &ett_devicenet_8_8, |
988 | 14 | &ett_devicenet_8_16, |
989 | 14 | &ett_devicenet_16_8, |
990 | 14 | &ett_devicenet_16_16 |
991 | 14 | }; |
992 | | |
993 | 14 | static ei_register_info ei[] = { |
994 | 14 | { &ei_devicenet_invalid_service, { "devicenet.invalid_service", PI_PROTOCOL, PI_WARN, "Invalid service", EXPFILL }}, |
995 | 14 | { &ei_devicenet_invalid_can_id, { "devicenet.invalid_can_id", PI_PROTOCOL, PI_WARN, "Invalid CAN ID", EXPFILL }}, |
996 | 14 | { &ei_devicenet_invalid_msg_id, { "devicenet.invalid_msg_id", PI_PROTOCOL, PI_WARN, "Invalid Message ID", EXPFILL }}, |
997 | 14 | { &ei_devicenet_frag_not_supported, { "devicenet.frag_not_supported", PI_UNDECODED, PI_WARN, "Fragmentation not currently supported", EXPFILL }}, |
998 | 14 | }; |
999 | | |
1000 | 14 | static uat_field_t devicenet_uat_flds[] = { |
1001 | 14 | UAT_FLD_DEC(uat_devicenet_records, mac_id, "Option number", "Custom Option Number"), |
1002 | 14 | UAT_FLD_VS(uat_devicenet_records, behavior, "Option type", devicenet_message_body_format_vals, "Option datatype"), |
1003 | 14 | UAT_END_FIELDS |
1004 | 14 | }; |
1005 | | |
1006 | 14 | proto_devicenet = proto_register_protocol("DeviceNet Protocol", "DeviceNet", "devicenet"); |
1007 | | |
1008 | 14 | proto_register_field_array(proto_devicenet, hf, array_length(hf)); |
1009 | 14 | proto_register_subtree_array(ett, array_length(ett)); |
1010 | 14 | expert_devicenet = expert_register_protocol(proto_devicenet); |
1011 | 14 | expert_register_field_array(expert_devicenet, ei, array_length(ei)); |
1012 | | |
1013 | 14 | devicenet_address_type = address_type_dissector_register("AT_DEVICENET", "DeviceNet Address", devicenet_addr_to_str, devicenet_addr_str_len, NULL, NULL, devicenet_addr_len, NULL, NULL); |
1014 | | |
1015 | 14 | devicenet_module = prefs_register_protocol(proto_devicenet, NULL); |
1016 | | |
1017 | 14 | devicenet_uat = uat_new("Node bodytypes", |
1018 | 14 | sizeof(uat_devicenet_record_t), /* record size */ |
1019 | 14 | "devicenet_bodytypes", /* filename */ |
1020 | 14 | true, /* from_profile */ |
1021 | 14 | &uat_devicenet_records, /* data_ptr */ |
1022 | 14 | &num_devicenet_records_uat, /* numitems_ptr */ |
1023 | 14 | UAT_AFFECTS_DISSECTION, /* affects dissection of packets, but not set of named fields */ |
1024 | 14 | NULL, /* help */ |
1025 | 14 | NULL, /* copy callback */ |
1026 | 14 | uat_devicenet_record_update_cb, /* update callback */ |
1027 | 14 | NULL, /* free callback */ |
1028 | 14 | NULL, /* post update callback */ |
1029 | 14 | NULL, /* reset callback */ |
1030 | 14 | devicenet_uat_flds); /* UAT field definitions */ |
1031 | | |
1032 | 14 | prefs_register_uat_preference(devicenet_module, |
1033 | 14 | "bodytype_table", |
1034 | 14 | "Node bodytypes", |
1035 | 14 | "Node bodytypes", |
1036 | 14 | devicenet_uat); |
1037 | | |
1038 | 14 | devicenet_handle = register_dissector("devicenet", dissect_devicenet, proto_devicenet ); |
1039 | 14 | } |
1040 | | |
1041 | | void |
1042 | | proto_reg_handoff_devicenet(void) |
1043 | 14 | { |
1044 | 14 | dissector_add_for_decode_as("can.subdissector", devicenet_handle ); |
1045 | 14 | } |
1046 | | |
1047 | | /* |
1048 | | * Editor modelines - https://www.wireshark.org/tools/modelines.html |
1049 | | * |
1050 | | * Local variables: |
1051 | | * c-basic-offset: 4 |
1052 | | * tab-width: 8 |
1053 | | * indent-tabs-mode: nil |
1054 | | * End: |
1055 | | * |
1056 | | * vi: set shiftwidth=4 tabstop=8 expandtab: |
1057 | | * :indentSize=4:tabSize=8:noTabs=true: |
1058 | | */ |