Coverage Report

Created: 2026-01-02 06:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
UAT_VS_DEF(uat_devicenet_records, behavior, uat_devicenet_record_t, enum node_behavior, NODE_BEHAVIOR_8_8, "string")
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
    uint16_t class_id, instance, attribute;
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(devicenet_tree, hf_devicenet_class8,  tvb, offset, 1, ENC_LITTLE_ENDIAN);
283
0
    class_id = tvb_get_uint8(tvb, offset);
284
0
    offset++;
285
286
0
    proto_tree_add_item(devicenet_tree, hf_devicenet_instance8,  tvb, offset, 1, ENC_LITTLE_ENDIAN);
287
0
    instance = tvb_get_uint8(tvb, offset);
288
289
0
    offset++;
290
0
    if (data_length > 3)
291
0
    {
292
0
        attribute = tvb_get_uint8(tvb, offset);
293
0
        ti = proto_tree_add_item(devicenet_tree, hf_devicenet_attribute,  tvb, offset, 1, ENC_LITTLE_ENDIAN);
294
0
        att_info = cip_get_attribute(class_id, instance, attribute);
295
296
0
        if (att_info != NULL)
297
0
            proto_item_append_text(ti, " (%s)", att_info->text);
298
299
0
        offset++;
300
0
    }
301
302
0
    if (data_length > 4)
303
0
    {
304
0
        length = offset-start_offset;
305
0
        proto_tree_add_item(devicenet_tree, hf_devicenet_data, tvb, offset, length, ENC_NA);
306
0
        offset += length;
307
0
    }
308
0
    return offset;
309
0
}
310
311
static int body_type_8_over_16_dissection(uint8_t data_length, proto_tree *devicenet_tree,
312
                                           tvbuff_t *tvb, packet_info *pinfo _U_, int offset)
313
0
{
314
0
    uint16_t class_id, instance, attribute;
315
0
    const attribute_info_t* att_info;
316
0
    proto_item* ti;
317
318
0
    devicenet_tree = proto_tree_add_subtree(devicenet_tree, tvb, offset, -1, ett_devicenet_8_16, NULL, "DeviceNet 8/16");
319
320
0
    proto_tree_add_item(devicenet_tree, hf_devicenet_class8, tvb, offset, 1, ENC_LITTLE_ENDIAN);
321
0
    class_id = tvb_get_uint8(tvb, offset);
322
0
    offset++;
323
324
0
    proto_tree_add_item(devicenet_tree, hf_devicenet_instance16, tvb, offset, 2, ENC_LITTLE_ENDIAN);
325
0
    instance = tvb_get_letohs(tvb, offset);
326
327
0
    if (data_length > 4)
328
0
    {
329
0
        attribute = tvb_get_uint8(tvb, offset);
330
0
        ti = proto_tree_add_item(devicenet_tree, hf_devicenet_attribute,  tvb, offset, 1, ENC_LITTLE_ENDIAN);
331
0
        att_info = cip_get_attribute(class_id, instance, attribute);
332
333
0
        if (att_info != NULL)
334
0
            proto_item_append_text(ti, " (%s)", att_info->text);
335
336
0
        offset++;
337
0
    }
338
339
0
    return offset;
340
0
}
341
342
static int body_type_16_over_8_dissection(uint8_t data_length, proto_tree *devicenet_tree, tvbuff_t *tvb,
343
                                           packet_info *pinfo _U_, int offset)
344
0
{
345
0
    uint16_t class_id, instance, attribute;
346
0
    const attribute_info_t* att_info;
347
0
    proto_item* ti;
348
349
0
    devicenet_tree = proto_tree_add_subtree(devicenet_tree, tvb, offset, -1, ett_devicenet_16_8, NULL, "DeviceNet 16/8");
350
351
0
    proto_tree_add_item(devicenet_tree, hf_devicenet_class16, tvb, offset, 2, ENC_LITTLE_ENDIAN);
352
0
    class_id = tvb_get_letohs(tvb, offset);
353
0
    offset += 2;
354
355
0
    proto_tree_add_item(devicenet_tree, hf_devicenet_instance8, tvb, offset, 1, ENC_LITTLE_ENDIAN);
356
0
    instance = tvb_get_uint8(tvb, offset);
357
0
    offset++;
358
359
0
    if (data_length > 4)
360
0
    {
361
0
        attribute = tvb_get_uint8(tvb, offset);
362
0
        ti = proto_tree_add_item(devicenet_tree, hf_devicenet_attribute,  tvb, offset, 1, ENC_LITTLE_ENDIAN);
363
0
        att_info = cip_get_attribute(class_id, instance, attribute);
364
365
0
        if (att_info != NULL)
366
0
            proto_item_append_text(ti, " (%s)", att_info->text);
367
368
0
        offset++;
369
0
    }
370
371
0
    return offset;
372
0
}
373
374
static int body_type_16_over_16_dissection(uint8_t data_length, proto_tree *devicenet_tree, tvbuff_t *tvb,
375
                                            packet_info *pinfo _U_, int offset)
376
0
{
377
0
    uint16_t class_id, instance, attribute;
378
0
    const attribute_info_t* att_info;
379
0
    proto_item* ti;
380
381
0
    devicenet_tree = proto_tree_add_subtree(devicenet_tree, tvb, offset, 4, ett_devicenet_16_16, NULL, "DeviceNet 16/16");
382
383
0
    proto_tree_add_item(devicenet_tree, hf_devicenet_class16, tvb, offset, 2, ENC_LITTLE_ENDIAN);
384
0
    class_id = tvb_get_letohs(tvb, offset);
385
0
    offset += 2;
386
387
0
    proto_tree_add_item(devicenet_tree, hf_devicenet_instance16, tvb, offset, 2, ENC_LITTLE_ENDIAN);
388
0
    instance = tvb_get_letohs(tvb, offset);
389
0
    offset+=2;
390
391
0
    if (data_length > 5)
392
0
    {
393
0
        attribute = tvb_get_uint8(tvb, offset);
394
0
        ti = proto_tree_add_item(devicenet_tree, hf_devicenet_attribute,  tvb, offset, 1, ENC_LITTLE_ENDIAN);
395
0
        att_info = cip_get_attribute(class_id, instance, attribute);
396
397
0
        if (att_info != NULL)
398
0
            proto_item_append_text(ti, " (%s)", att_info->text);
399
400
0
        offset++;
401
0
    }
402
403
0
    return offset;
404
0
}
405
406
static int dissect_devicenet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
407
0
{
408
0
    proto_item *ti, *can_id_item,
409
0
               *msg_id_item, *service_item;
410
0
    proto_tree *devicenet_tree, *can_tree, *content_tree;
411
412
0
    int offset = 0;
413
0
    uint16_t message_id;
414
0
    uint32_t data_length = tvb_reported_length(tvb);
415
0
    uint8_t source_mac;
416
0
    struct can_info can_info;
417
0
    uint8_t service_rr;
418
0
    uint8_t *src_address, *dest_address;
419
420
0
    DISSECTOR_ASSERT(data);
421
0
    can_info = *((struct can_info*)data);
422
423
0
    if (can_info.id & (CAN_ERR_FLAG | CAN_RTR_FLAG | CAN_EFF_FLAG))
424
0
    {
425
        /* Error, RTR and frames with extended ids are not for us. */
426
0
        return 0;
427
0
    }
428
429
0
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "DeviceNet");
430
431
0
    ti = proto_tree_add_item(tree, proto_devicenet, tvb, offset, -1, ENC_NA);
432
0
    devicenet_tree = proto_item_add_subtree(ti, ett_devicenet);
433
434
0
    can_tree = proto_tree_add_subtree_format(devicenet_tree, tvb, 0, 0, ett_devicenet_can, NULL, "CAN Identifier: 0x%04x", can_info.id);
435
0
    can_id_item = proto_tree_add_uint(can_tree, hf_devicenet_can_id, tvb, 0, 0, can_info.id);
436
0
    proto_item_set_generated(can_id_item);
437
438
    /*
439
     * Message group 1
440
     */
441
0
    if ( can_info.id <= MESSAGE_GROUP_1_ID )
442
0
    {
443
0
        ti = proto_tree_add_uint(can_tree, hf_devicenet_grp_msg1_id, tvb, 0, 0, can_info.id);
444
0
        proto_item_set_generated(ti);
445
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);
446
0
        proto_item_set_generated(ti);
447
448
        /* Set source address */
449
0
        src_address = (uint8_t*)wmem_alloc(pinfo->pool, 1);
450
0
        *src_address = (uint8_t)(can_info.id & MESSAGE_GROUP_1_MAC_ID_MASK);
451
0
        set_address(&pinfo->src, devicenet_address_type, 1, (const void*)src_address);
452
453
0
        message_id = can_info.id & MESSAGE_GROUP_1_MSG_MASK;
454
0
        col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(message_id, devicenet_grp_msg1_vals, "Other Group 1 Message"));
455
456
0
        proto_tree_add_item(devicenet_tree, hf_devicenet_data, tvb, offset, data_length, ENC_NA);
457
0
    }
458
    /*
459
     * Message group 2
460
     */
461
0
    else if (can_info.id <= MESSAGE_GROUP_2_ID )
462
0
    {
463
0
        ti = proto_tree_add_uint(can_tree, hf_devicenet_grp_msg2_id, tvb, 0, 0, can_info.id);
464
0
        proto_item_set_generated(ti);
465
466
        /* create display subtree for the protocol */
467
0
        message_id = can_info.id & MESSAGE_GROUP_2_MSG_MASK;
468
0
        col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(message_id, devicenet_grp_msg2_vals, "Unknown"));
469
470
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);
471
0
        proto_item_set_generated(ti);
472
473
        /* Set source address */
474
0
        src_address = (uint8_t*)wmem_alloc(pinfo->pool, 1);
475
0
        *src_address = (uint8_t)((can_info.id & MESSAGE_GROUP_2_MAC_ID_MASK) >> 3);
476
0
        set_address(&pinfo->src, devicenet_address_type, 1, (const void*)src_address);
477
478
0
        content_tree = proto_tree_add_subtree(devicenet_tree, tvb, offset, -1, ett_devicenet_contents, NULL, "Contents");
479
480
0
        switch (message_id)
481
0
        {
482
0
        case 0x0:
483
0
        case 0x1:
484
0
        case 0x2:
485
0
        case 0x3:
486
0
        case 0x4:
487
0
        case 0x5:
488
0
            proto_tree_add_item(content_tree, hf_devicenet_data, tvb, offset, data_length, ENC_NA);
489
0
            break;
490
491
0
        case 0x6:
492
0
            proto_tree_add_item(content_tree, hf_devicenet_data, tvb, offset, data_length, ENC_NA);
493
0
            break;
494
495
0
        case 0x7:
496
0
            proto_tree_add_item(content_tree, hf_devicenet_dup_mac_id_rr_bit, tvb, offset, 1, ENC_LITTLE_ENDIAN);
497
0
            proto_tree_add_item(content_tree, hf_devicenet_dup_mac_id_physical_port_number, tvb, offset, 1, ENC_LITTLE_ENDIAN);
498
0
            offset ++;
499
500
0
            proto_tree_add_item(content_tree, hf_devicenet_dup_mac_id_vendor, tvb, offset, 2, ENC_LITTLE_ENDIAN);
501
0
            offset+=2;
502
503
0
            proto_tree_add_item(content_tree, hf_devicenet_dup_mac_id_serial_number, tvb, offset, 4, ENC_LITTLE_ENDIAN);
504
0
            break;
505
0
        }
506
0
    }
507
    /*
508
     * Message group 3
509
     */
510
0
    else if (can_info.id <= MESSAGE_GROUP_3_ID )
511
0
    {
512
0
        uint8_t byte1;
513
514
0
        msg_id_item = proto_tree_add_uint(can_tree, hf_devicenet_grp_msg3_id, tvb, 0, 0, can_info.id);
515
0
        proto_item_set_generated(msg_id_item);
516
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);
517
0
        proto_item_set_generated(ti);
518
519
        /* Set source address */
520
0
        src_address = (uint8_t*)wmem_alloc(pinfo->pool, 1);
521
0
        *src_address = (uint8_t)(can_info.id & MESSAGE_GROUP_3_MAC_ID_MASK);
522
0
        set_address(&pinfo->src, devicenet_address_type, 1, (const void*)src_address);
523
524
0
        message_id = can_info.id & MESSAGE_GROUP_3_MSG_MASK;
525
0
        col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(message_id, devicenet_grp_msg3_vals, "Unknown"));
526
527
0
        proto_tree_add_item(devicenet_tree, hf_devicenet_grp_msg3_frag, tvb, offset, 1, ENC_NA);
528
0
        proto_tree_add_item(devicenet_tree, hf_devicenet_grp_msg3_xid, tvb, offset, 1, ENC_NA);
529
0
        proto_tree_add_item(devicenet_tree, hf_devicenet_grp_msg3_dest_mac_id, tvb, offset, 1, ENC_LITTLE_ENDIAN);
530
0
        byte1 = tvb_get_uint8(tvb, offset);
531
0
        source_mac = byte1 & MESSAGE_GROUP_3_MAC_ID_MASK;
532
533
        /* Set destination address */
534
        /* XXX - This may be source address depending on message type.  Need to adjust accordingly) */
535
0
        dest_address = (uint8_t*)wmem_alloc(pinfo->pool, 1);
536
0
        *dest_address = (uint8_t)source_mac;
537
0
        set_address(&pinfo->dst, devicenet_address_type, 1, (const void*)dest_address);
538
0
        offset++;
539
540
0
        if (byte1 & MESSAGE_GROUP_3_FRAG_MASK)
541
0
        {
542
0
            col_set_str(pinfo->cinfo, COL_INFO, "Group 3 Message Fragment");
543
544
0
            content_tree = proto_tree_add_subtree(devicenet_tree, tvb, offset, -1, ett_devicenet_contents, NULL, "Fragmentation");
545
546
0
            proto_tree_add_item(content_tree, hf_devicenet_fragment_type, tvb, offset, 1, ENC_LITTLE_ENDIAN);
547
0
            proto_tree_add_item(content_tree, hf_devicenet_fragment_count, tvb, offset, 1, ENC_LITTLE_ENDIAN);
548
549
            /* TODO: Handle fragmentation */
550
0
            proto_tree_add_expert(content_tree, pinfo, &ei_devicenet_frag_not_supported, tvb, offset, -1);
551
552
0
            col_set_str(pinfo->cinfo, COL_INFO,
553
0
                        val_to_str_const((tvb_get_uint8(tvb, offset) & 0xC0) >> 6,
554
0
                                         devicenet_fragmented_message_type_vals,
555
0
                                         "Unknown fragmented message type"));
556
0
        }
557
0
        else
558
0
        {
559
0
            service_rr = tvb_get_uint8(tvb, offset);
560
561
0
            content_tree = proto_tree_add_subtree_format(devicenet_tree, tvb, offset, -1, ett_devicenet_contents, NULL,
562
0
                        "Service: %s (%s)", val_to_str_const(service_rr & CIP_SC_MASK, devicenet_service_code_vals, "Unknown"),
563
0
                        service_rr & CIP_SC_RESPONSE_MASK ? "Response" : "Request");
564
565
0
            proto_tree_add_item(content_tree, hf_devicenet_rr_bit, tvb, offset, 1, ENC_LITTLE_ENDIAN);
566
0
            service_item = proto_tree_add_item(content_tree, hf_devicenet_service_code, tvb, offset, 1, ENC_LITTLE_ENDIAN);
567
0
            offset++;
568
569
0
            col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(service_rr & CIP_SC_MASK, devicenet_service_code_vals, "Unknown Service Code"));
570
0
            if (service_rr & CIP_SC_RESPONSE_MASK)
571
0
            {
572
0
                col_append_str(pinfo->cinfo, COL_INFO, " - Response");
573
0
            }
574
0
            else
575
0
            {
576
0
                col_append_str(pinfo->cinfo, COL_INFO, " - Request");
577
0
            }
578
579
0
            switch(message_id)
580
0
            {
581
0
            case 0x140:
582
0
                switch(service_rr & CIP_SC_MASK)
583
0
                {
584
0
                case SC_OPEN_EXPLICIT_MESSAGE:
585
0
                case SC_CLOSE_EXPLICIT_MESSAGE:
586
0
                case SC_DEVICE_HEARTBEAT_MESSAGE:
587
0
                case SC_DEVICE_SHUTOWN_MESSAGE:
588
                /* XXX - ERROR RESPONSE? */
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 5", service_rr & CIP_SC_MASK);
593
0
                    break;
594
0
                }
595
0
                break;
596
0
            case 0x180:
597
0
                switch(service_rr & CIP_SC_MASK)
598
0
                {
599
0
                case SC_OPEN_EXPLICIT_MESSAGE:
600
0
                case SC_CLOSE_EXPLICIT_MESSAGE:
601
0
                    break;
602
0
                default:
603
0
                    expert_add_info_format(pinfo, service_item, &ei_devicenet_invalid_service,
604
0
                        "Invalid service code (0x%x) for Group 3 Message ID 6", service_rr & CIP_SC_MASK);
605
0
                    break;
606
0
                }
607
0
                break;
608
0
            case 0x1C0:
609
0
                expert_add_info_format(pinfo, msg_id_item, &ei_devicenet_invalid_msg_id,
610
0
                        "Invalid Group 3 Message ID (%d)", message_id);
611
0
                break;
612
0
            }
613
614
0
            switch(service_rr & CIP_SC_MASK)
615
0
            {
616
0
            case SC_OPEN_EXPLICIT_MESSAGE:
617
                /* XXX - Create conversation to track connections */
618
0
                if (service_rr & CIP_SC_RESPONSE_MASK)
619
0
                {
620
0
                    proto_tree_add_item(content_tree, hf_devicenet_open_exp_msg_reserved, tvb, offset, 1, ENC_LITTLE_ENDIAN);
621
0
                    proto_tree_add_item(content_tree, hf_devicenet_open_exp_msg_actual_body_format, tvb, offset, 1, ENC_LITTLE_ENDIAN);
622
0
                    offset++;
623
0
                    proto_tree_add_item(content_tree, hf_devicenet_open_exp_dest_message_id, tvb, offset, 1, ENC_LITTLE_ENDIAN);
624
0
                    proto_tree_add_item(content_tree, hf_devicenet_open_exp_src_message_id, tvb, offset, 1, ENC_LITTLE_ENDIAN);
625
0
                    offset++;
626
0
                    proto_tree_add_item(content_tree, hf_devicenet_connection_id, tvb, offset, 2, ENC_LITTLE_ENDIAN);
627
0
                }
628
0
                else
629
0
                {
630
0
                    proto_tree_add_item(content_tree, hf_devicenet_open_exp_msg_reserved, tvb, offset, 1, ENC_LITTLE_ENDIAN);
631
0
                    proto_tree_add_item(content_tree, hf_devicenet_open_exp_msg_req_body_format, tvb, offset, 1, ENC_LITTLE_ENDIAN);
632
0
                    offset++;
633
0
                    proto_tree_add_item(content_tree, hf_devicenet_open_exp_group_select, tvb, offset, 1, ENC_LITTLE_ENDIAN);
634
0
                    proto_tree_add_item(content_tree, hf_devicenet_open_exp_src_message_id, tvb, offset, 1, ENC_LITTLE_ENDIAN);
635
0
                }
636
0
                break;
637
0
            case SC_CLOSE_EXPLICIT_MESSAGE:
638
                /* XXX - Use conversation to track connections */
639
0
                if ((service_rr & CIP_SC_RESPONSE_MASK) == 0)
640
0
                {
641
0
                    proto_tree_add_item(content_tree, hf_devicenet_connection_id, tvb, offset, 2, ENC_LITTLE_ENDIAN);
642
0
                }
643
0
                break;
644
0
            default:
645
0
                if(service_rr & CIP_SC_MASK)
646
0
                {
647
0
                    proto_tree_add_item(devicenet_tree, hf_devicenet_data, tvb, offset, data_length - 2, ENC_NA);
648
0
                }
649
0
                else
650
0
                {
651
0
                    unsigned channel;
652
653
0
                    for (channel = 0; channel < num_devicenet_records_uat; channel++)
654
0
                    {
655
0
                        if (uat_devicenet_records[channel].mac_id == source_mac)
656
0
                        {
657
0
                            switch(uat_devicenet_records[channel].behavior)
658
0
                            {
659
0
                            case 0:
660
0
                                body_type_8_over_8_dissection(data_length, content_tree, tvb, pinfo, offset);
661
0
                                break;
662
0
                            case 1:
663
0
                                body_type_8_over_16_dissection(data_length, content_tree, tvb, pinfo, offset);
664
0
                                break;
665
0
                            case 2:
666
0
                                body_type_16_over_8_dissection(data_length, content_tree, tvb, pinfo, offset);
667
0
                                break;
668
0
                            case 3:
669
0
                                body_type_16_over_16_dissection(data_length, content_tree, tvb, pinfo, offset);
670
0
                                break;
671
0
                            default:
672
0
                                proto_tree_add_item(content_tree, hf_devicenet_data, tvb, offset, data_length, ENC_NA);
673
0
                                break;
674
0
                            }
675
0
                        }
676
0
                    }
677
678
                    /* Don't have a behavior defined for this address, default to 8 over 8 */
679
0
                    if (channel >= num_devicenet_records_uat)
680
0
                    {
681
0
                        body_type_8_over_8_dissection(data_length, content_tree, tvb, pinfo, offset);
682
0
                    }
683
0
                }
684
0
                break;
685
0
            }
686
0
        }
687
0
    }
688
    /*Message group 4*/
689
0
    else if (can_info.id <= MESSAGE_GROUP_4_ID )
690
0
    {
691
0
        ti = proto_tree_add_uint(can_tree, hf_devicenet_grp_msg4_id, tvb, 0, 0, can_info.id);
692
0
        proto_item_set_generated(ti);
693
694
0
        message_id = can_info.id & MESSAGE_GROUP_4_MSG_MASK;
695
0
        col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(message_id, devicenet_grp_msg4_vals, "Reserved Group 4 Message"));
696
697
0
        switch(message_id)
698
0
        {
699
0
        case GRP4_COMM_FAULT_RESPONSE:
700
0
        case GRP4_COMM_FAULT_REQUEST:
701
0
            if(data_length == 2)
702
0
            {
703
0
                proto_tree_add_item(devicenet_tree, hf_devicenet_comm_fault_rsv, tvb, offset, 1, ENC_LITTLE_ENDIAN);
704
0
                proto_tree_add_item(devicenet_tree, hf_devicenet_comm_fault_match, tvb, offset, 1, ENC_LITTLE_ENDIAN);
705
0
                proto_tree_add_item(devicenet_tree, hf_devicenet_comm_fault_value, tvb, offset, 1, ENC_LITTLE_ENDIAN);
706
0
                offset++;
707
708
0
                proto_tree_add_item(devicenet_tree, hf_devicenet_rr_bit, tvb, offset, 1, ENC_LITTLE_ENDIAN);
709
0
                proto_tree_add_item(devicenet_tree, hf_devicenet_service_code, tvb, offset, 1, ENC_LITTLE_ENDIAN);
710
711
0
                if( tvb_get_uint8(tvb, offset) & CIP_SC_RESPONSE_MASK)
712
0
                {
713
0
                    col_append_str(pinfo->cinfo, COL_INFO, " - Response");
714
0
                }
715
0
                else
716
0
                {
717
0
                    col_append_str(pinfo->cinfo, COL_INFO, " - Request");
718
0
                }
719
0
            }
720
0
            else if(data_length == 8)
721
0
            {
722
0
                proto_tree_add_item(devicenet_tree, hf_devicenet_comm_fault_rsv, tvb, offset, 1, ENC_LITTLE_ENDIAN);
723
0
                offset++;
724
725
0
                proto_tree_add_item(devicenet_tree, hf_devicenet_rr_bit, tvb, offset, 1, ENC_LITTLE_ENDIAN);
726
0
                proto_tree_add_item(devicenet_tree, hf_devicenet_service_code, tvb, offset, 1, ENC_LITTLE_ENDIAN);
727
728
0
                if( tvb_get_uint8(tvb, offset) & CIP_SC_RESPONSE_MASK)
729
0
                {
730
0
                    col_append_str(pinfo->cinfo, COL_INFO, " - Response");
731
0
                }
732
0
                else
733
0
                {
734
0
                    col_append_str(pinfo->cinfo, COL_INFO, " - Request");
735
0
                }
736
0
                offset++;
737
738
0
                proto_tree_add_item(devicenet_tree, hf_devicenet_vendor, tvb, offset, 2, ENC_LITTLE_ENDIAN);
739
0
                offset +=2;
740
0
                proto_tree_add_item(devicenet_tree, hf_devicenet_serial_number, tvb, offset, 4, ENC_LITTLE_ENDIAN);
741
0
            }
742
0
            break;
743
0
        case GRP4_OFFLINE_OWNER_REQUEST:
744
0
        case GRP4_OFFLINE_OWNER_RESPONSE:
745
0
            proto_tree_add_item(devicenet_tree, hf_devicenet_offline_ownership_reserved,  tvb, offset, 1, ENC_LITTLE_ENDIAN);
746
0
            proto_tree_add_item(devicenet_tree, hf_devicenet_offline_ownership_client_mac_id, tvb, offset, 1, ENC_LITTLE_ENDIAN);
747
0
            offset++;
748
749
0
            proto_tree_add_item(devicenet_tree, hf_devicenet_rr_bit, tvb, offset, 1, ENC_LITTLE_ENDIAN);
750
751
0
            if( tvb_get_uint8(tvb, offset) & CIP_SC_RESPONSE_MASK)
752
0
            {
753
0
                col_append_str(pinfo->cinfo, COL_INFO, " - Response");
754
0
            }
755
0
            else
756
0
            {
757
0
                col_append_str(pinfo->cinfo, COL_INFO, " - Request");
758
0
            }
759
760
0
            proto_tree_add_item(devicenet_tree, hf_devicenet_offline_ownership_allocate, tvb, offset, 1, ENC_LITTLE_ENDIAN);
761
0
            offset++;
762
0
            proto_tree_add_item(devicenet_tree, hf_devicenet_vendor, tvb, offset, 2, ENC_LITTLE_ENDIAN);
763
0
            offset +=2;
764
0
            proto_tree_add_item(devicenet_tree, hf_devicenet_serial_number, tvb, offset, 4, ENC_LITTLE_ENDIAN);
765
0
            break;
766
0
        }
767
0
    }
768
    /*Invalid CAN message*/
769
0
    else
770
0
    {
771
0
        col_add_fstr(pinfo->cinfo, COL_INFO, "Invalid CAN Message 0x%06X", can_info.id);
772
0
        expert_add_info_format(pinfo, can_id_item, &ei_devicenet_invalid_can_id,
773
0
                    "Invalid CAN Message 0x%04X", can_info.id);
774
0
    }
775
776
0
    return tvb_captured_length(tvb);
777
0
}
778
779
static int devicenet_addr_to_str(const address* addr, char *buf, int buf_len)
780
0
{
781
0
    const uint8_t *addrdata = (const uint8_t *)addr->data;
782
783
0
    uint32_to_str_buf(*addrdata, buf, buf_len);
784
0
    return (int)strlen(buf);
785
0
}
786
787
static int devicenet_addr_str_len(const address* addr _U_)
788
0
{
789
0
    return 11; /* Leaves required space (10 bytes) for uint_to_str_back() */
790
0
}
791
792
static int devicenet_addr_len(void)
793
0
{
794
0
    return 1;
795
0
}
796
797
void proto_register_devicenet(void)
798
14
{
799
14
    module_t *devicenet_module;
800
14
    expert_module_t*expert_devicenet;
801
802
14
    static hf_register_info hf[] = {
803
14
        { &hf_devicenet_can_id,
804
14
            {"CAN Identifier", "devicenet.can_id",
805
14
            FT_UINT16, BASE_HEX, NULL, DEVICENET_CANID_MASK,
806
14
            NULL, HFILL }
807
14
        },
808
14
        { &hf_devicenet_src_mac_id,
809
14
            { "Source MAC ID", "devicenet.src_mac_id",
810
14
            FT_UINT8, BASE_DEC, NULL, 0,
811
14
            NULL, HFILL }
812
14
        },
813
14
        { &hf_devicenet_connection_id,
814
14
            { "Connection ID", "devicenet.connection_id",
815
14
            FT_UINT16, BASE_DEC, NULL, 0,
816
14
            NULL, HFILL }
817
14
        },
818
14
        { &hf_devicenet_data,
819
14
            { "Data", "devicenet.data",
820
14
            FT_BYTES, BASE_NONE, NULL, 0,
821
14
            NULL, HFILL }
822
14
        },
823
14
        { &hf_devicenet_grp_msg1_id,
824
14
            { "Group 1 message ID", "devicenet.grp_msg1.id",
825
14
            FT_UINT16, BASE_DEC, NULL, MESSAGE_GROUP_1_MSG_MASK,
826
14
            NULL, HFILL }
827
14
        },
828
14
        { &hf_devicenet_grp_msg2_id,
829
14
            { "Group 2 message ID", "devicenet.grp_msg2.id",
830
14
            FT_UINT16, BASE_DEC, NULL, MESSAGE_GROUP_2_MSG_MASK,
831
14
            NULL, HFILL }
832
14
        },
833
14
        { &hf_devicenet_grp_msg3_id,
834
14
            { "Group 3 message ID", "devicenet.grp_msg3.id",
835
14
            FT_UINT16, BASE_DEC, NULL, MESSAGE_GROUP_3_MSG_MASK,
836
14
            NULL, HFILL }
837
14
        },
838
14
        { &hf_devicenet_grp_msg3_dest_mac_id,
839
14
            { "Destination MAC ID", "devicenet.dest_mac_id",
840
14
            FT_UINT8, BASE_DEC, NULL, 0x3F,
841
14
            NULL, HFILL }
842
14
        },
843
14
        { &hf_devicenet_grp_msg3_frag,
844
14
            { "Frag", "devicenet.grp_msg3.frag",
845
14
            FT_BOOLEAN, 8, NULL, MESSAGE_GROUP_3_FRAG_MASK,
846
14
            NULL, HFILL }
847
14
        },
848
14
        { &hf_devicenet_grp_msg3_xid,
849
14
            { "XID", "devicenet.grp_msg3.xid",
850
14
            FT_BOOLEAN, 8, NULL, MESSAGE_GROUP_3_XID_MASK,
851
14
            NULL, HFILL }
852
14
        },
853
14
        { &hf_devicenet_grp_msg4_id,
854
14
            { "Group 4 message ID", "devicenet.grp_msg4.id",
855
14
            FT_UINT16, BASE_DEC, NULL, MESSAGE_GROUP_4_MSG_MASK,
856
14
            NULL, HFILL }
857
14
        },
858
14
        { &hf_devicenet_rr_bit,
859
14
            { "Request/Response", "devicenet.rr",
860
14
            FT_UINT8, BASE_DEC, VALS(cip_sc_rr), CIP_SC_RESPONSE_MASK,
861
14
            "Request or Response message", HFILL }
862
14
        },
863
14
        { &hf_devicenet_service_code,
864
14
            { "Service Code", "devicenet.service",
865
14
            FT_UINT8, BASE_DEC, VALS(devicenet_service_code_vals), CIP_SC_MASK,
866
14
            NULL, HFILL }
867
14
        },
868
14
        { &hf_devicenet_open_exp_src_message_id,
869
14
            { "Source Message ID", "devicenet.open_message.src_message_id",
870
14
            FT_UINT8, BASE_DEC, NULL, 0x0F,
871
14
            NULL, HFILL }
872
14
        },
873
14
        { &hf_devicenet_open_exp_dest_message_id,
874
14
            { "Destination Message ID", "devicenet.open_message.dest_message_id",
875
14
            FT_UINT8, BASE_DEC, NULL, 0xF0,
876
14
            NULL, HFILL }
877
14
        },
878
14
        { &hf_devicenet_open_exp_msg_reserved,
879
14
            { "Reserved", "devicenet.open_message.reserved",
880
14
            FT_UINT8, BASE_DEC, NULL, 0xF0,
881
14
            NULL, HFILL }
882
14
        },
883
14
        { &hf_devicenet_open_exp_msg_req_body_format,
884
14
            { "Requested Message Body Format", "devicenet.open_message.req_body_format",
885
14
            FT_UINT8, BASE_DEC, VALS(devicenet_message_body_format_vals), 0x0F,
886
14
            NULL, HFILL }
887
14
        },
888
14
        { &hf_devicenet_open_exp_msg_actual_body_format,
889
14
            { "Actual Message Body Format", "devicenet.open_message.actual_body_format",
890
14
            FT_UINT8, BASE_DEC, VALS(devicenet_message_body_format_vals), 0x0F,
891
14
            NULL, HFILL }
892
14
        },
893
14
        { &hf_devicenet_open_exp_group_select,
894
14
            { "Group Select", "devicenet.open_message.group_select",
895
14
            FT_UINT8, BASE_DEC, VALS(devicenet_group_select_vals), 0xF0,
896
14
            NULL, HFILL }
897
14
        },
898
14
        { &hf_devicenet_dup_mac_id_rr_bit,
899
14
            { "Request/Response", "devicenet.dup_mac_id.rr",
900
14
            FT_UINT8, BASE_DEC, VALS(cip_sc_rr), CIP_SC_RESPONSE_MASK,
901
14
            "Duplicate MAC ID Request or Response message", HFILL }
902
14
        },
903
14
        { &hf_devicenet_dup_mac_id_physical_port_number,
904
14
            { "Physical port number", "devicenet.dup_mac_id.physical_port_number",
905
14
            FT_UINT8, BASE_DEC, NULL, 0x7F,
906
14
            "Duplicate MAC ID check message physical port number", HFILL }
907
14
        },
908
14
        { &hf_devicenet_dup_mac_id_vendor,
909
14
            { "Vendor ID", "devicenet.dup_mac_id.vendor",
910
14
            FT_UINT16, BASE_HEX|BASE_EXT_STRING, &cip_vendor_vals_ext, 0,
911
14
            NULL, HFILL }
912
14
        },
913
14
        { &hf_devicenet_dup_mac_id_serial_number,
914
14
            { "Serial Number", "devicenet.dup_mac_id.serial_number",
915
14
            FT_UINT32, BASE_HEX, NULL, 0x00,
916
14
            NULL, HFILL }
917
14
        },
918
14
        { &hf_devicenet_vendor,
919
14
            { "Vendor ID", "devicenet.vendor",
920
14
            FT_UINT16, BASE_HEX|BASE_EXT_STRING, &cip_vendor_vals_ext, 0,
921
14
            NULL, HFILL }
922
14
        },
923
14
        { &hf_devicenet_serial_number,
924
14
            { "Serial Number", "devicenet.serial_number",
925
14
            FT_UINT32, BASE_HEX, NULL, 0x00,
926
14
            NULL, HFILL }
927
14
        },
928
14
        { &hf_devicenet_instance8,
929
14
            { "Instance", "devicenet.instance",
930
14
            FT_UINT8, BASE_HEX, NULL, 0x00,
931
14
            NULL, HFILL }
932
14
        },
933
14
        { &hf_devicenet_instance16,
934
14
            { "Instance", "devicenet.instance",
935
14
            FT_UINT16, BASE_HEX, NULL, 0x00,
936
14
            NULL, HFILL }
937
14
        },
938
14
        { &hf_devicenet_attribute,
939
14
            { "Attribute", "devicenet.attribute",
940
14
            FT_UINT8, BASE_HEX, NULL, 0x00,
941
14
            NULL, HFILL }
942
14
        },
943
14
        { &hf_devicenet_fragment_type,
944
14
            { "Fragment Type", "devicenet.fragment_type",
945
14
            FT_UINT8, BASE_HEX, VALS(devicenet_fragmented_message_type_vals), 0xC0,
946
14
            NULL, HFILL }
947
14
        },
948
14
        { &hf_devicenet_fragment_count,
949
14
            { "Fragment Count", "devicenet.fragment_count",
950
14
            FT_UINT8, BASE_HEX_DEC, NULL, 0x3F,
951
14
            NULL, HFILL }
952
14
        },
953
14
        { &hf_devicenet_class8,
954
14
            { "Class",  "devicenet.class",
955
14
            FT_UINT8, BASE_HEX|BASE_EXT_STRING, &cip_class_names_vals_ext, 0,
956
14
            NULL, HFILL }
957
14
        },
958
14
        { &hf_devicenet_class16,
959
14
            { "Class",  "devicenet.class",
960
14
            FT_UINT16, BASE_HEX|BASE_EXT_STRING, &cip_class_names_vals_ext, 0,
961
14
            NULL, HFILL }
962
14
        },
963
14
        { &hf_devicenet_comm_fault_rsv,
964
14
            { "Reserved",  "devicenet.comm_fault.reserved",
965
14
            FT_UINT8, BASE_HEX, NULL, 0x80,
966
14
            NULL, HFILL }
967
14
        },
968
14
        { &hf_devicenet_comm_fault_match,
969
14
            { "Match", "devicenet.comm_fault.match",
970
14
            FT_UINT8, BASE_HEX, NULL, 0x40,
971
14
            NULL, HFILL }
972
14
        },
973
14
        {&hf_devicenet_comm_fault_value,
974
14
            { "Value", "devicenet.comm_fault.value",
975
14
            FT_UINT8, BASE_HEX, NULL, 0x3F,
976
14
            "Comm Fault Value", HFILL }
977
14
        },
978
14
        {&hf_devicenet_offline_ownership_reserved,
979
14
            { "Reserved", "devicenet.offline_ownership.reserved",
980
14
            FT_UINT8, BASE_HEX, NULL, 0xC0,
981
14
            "Offline ownership Response Message Reserved", HFILL }
982
14
        },
983
14
        {&hf_devicenet_offline_ownership_client_mac_id,
984
14
            { "Client MAC ID", "devicenet.offline_ownership.client_mac_id",
985
14
            FT_UINT8, BASE_HEX, NULL, MESSAGE_GROUP_4_MSG_MASK,
986
14
            "Offline ownership message client MAC ID", HFILL }
987
14
        },
988
14
        {&hf_devicenet_offline_ownership_allocate,
989
14
            { "Allocate", "devicenet.offline_ownership.allocate",
990
14
            FT_UINT8, BASE_HEX, NULL, CIP_SC_MASK,
991
14
            "Offline ownership response message allocate", HFILL }
992
14
        },
993
14
    };
994
995
14
    static int *ett[] = {
996
14
        &ett_devicenet,
997
14
        &ett_devicenet_can,
998
14
        &ett_devicenet_contents,
999
14
        &ett_devicenet_8_8,
1000
14
        &ett_devicenet_8_16,
1001
14
        &ett_devicenet_16_8,
1002
14
        &ett_devicenet_16_16
1003
14
    };
1004
1005
14
    static ei_register_info ei[] = {
1006
14
        { &ei_devicenet_invalid_service, { "devicenet.invalid_service", PI_PROTOCOL, PI_WARN, "Invalid service", EXPFILL }},
1007
14
        { &ei_devicenet_invalid_can_id, { "devicenet.invalid_can_id", PI_PROTOCOL, PI_WARN, "Invalid CAN ID", EXPFILL }},
1008
14
        { &ei_devicenet_invalid_msg_id, { "devicenet.invalid_msg_id", PI_PROTOCOL, PI_WARN, "Invalid Message ID", EXPFILL }},
1009
14
        { &ei_devicenet_frag_not_supported, { "devicenet.frag_not_supported", PI_UNDECODED, PI_WARN, "Fragmentation not currently supported", EXPFILL }},
1010
14
    };
1011
1012
14
    static uat_field_t devicenet_uat_flds[] = {
1013
14
        UAT_FLD_DEC(uat_devicenet_records, mac_id, "Option number", "Custom Option Number"),
1014
14
        UAT_FLD_VS(uat_devicenet_records, behavior, "Option type", devicenet_message_body_format_vals, "Option datatype"),
1015
14
        UAT_END_FIELDS
1016
14
    };
1017
1018
14
    proto_devicenet = proto_register_protocol("DeviceNet Protocol", "DeviceNet", "devicenet");
1019
1020
14
    proto_register_field_array(proto_devicenet, hf, array_length(hf));
1021
14
    proto_register_subtree_array(ett, array_length(ett));
1022
14
    expert_devicenet = expert_register_protocol(proto_devicenet);
1023
14
    expert_register_field_array(expert_devicenet, ei, array_length(ei));
1024
1025
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);
1026
1027
14
    devicenet_module = prefs_register_protocol(proto_devicenet, NULL);
1028
1029
14
    devicenet_uat = uat_new("Node bodytypes",
1030
14
                            sizeof(uat_devicenet_record_t), /* record size           */
1031
14
                            "devicenet_bodytypes",          /* filename              */
1032
14
                            true,                           /* from_profile          */
1033
14
                            &uat_devicenet_records,         /* data_ptr              */
1034
14
                            &num_devicenet_records_uat,     /* numitems_ptr          */
1035
14
                            UAT_AFFECTS_DISSECTION,         /* affects dissection of packets, but not set of named fields */
1036
14
                            NULL,                           /* help                  */
1037
14
                            NULL,   /* copy callback         */
1038
14
                            uat_devicenet_record_update_cb, /* update callback       */
1039
14
                            NULL,   /* free callback         */
1040
14
                            NULL,    /* post update callback  */
1041
14
                            NULL,   /* reset callback */
1042
14
                            devicenet_uat_flds);    /* UAT field definitions */
1043
1044
14
    prefs_register_uat_preference(devicenet_module,
1045
14
                                      "bodytype_table",
1046
14
                                      "Node bodytypes",
1047
14
                                      "Node bodytypes",
1048
14
                                      devicenet_uat);
1049
1050
14
    devicenet_handle = register_dissector("devicenet",  dissect_devicenet, proto_devicenet );
1051
14
}
1052
1053
void
1054
proto_reg_handoff_devicenet(void)
1055
14
{
1056
14
    dissector_add_for_decode_as("can.subdissector", devicenet_handle );
1057
14
}
1058
1059
/*
1060
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
1061
 *
1062
 * Local variables:
1063
 * c-basic-offset: 4
1064
 * tab-width: 8
1065
 * indent-tabs-mode: nil
1066
 * End:
1067
 *
1068
 * vi: set shiftwidth=4 tabstop=8 expandtab:
1069
 * :indentSize=4:tabSize=8:noTabs=true:
1070
 */