Coverage Report

Created: 2025-08-04 07:15

/src/wireshark/epan/dissectors/packet-bacnet.c
Line
Count
Source (jump to first uncovered line)
1
/* packet-bacnet.c
2
 * Routines for BACnet (NPDU) dissection
3
 * Copyright 2001, Hartmut Mueller <hartmut@abmlinux.org>, FH Dortmund
4
 * Enhanced by Steve Karg, 2005, <skarg@users.sourceforge.net>
5
 *
6
 * Wireshark - Network traffic analyzer
7
 * By Gerald Combs <gerald@wireshark.org>
8
 * Copyright 1998 Gerald Combs
9
 *
10
 * Copied from README.developer,v 1.23
11
 *
12
 * SPDX-License-Identifier: GPL-2.0-or-later
13
 */
14
15
#include "config.h"
16
17
#include <epan/packet.h>
18
#include <epan/tfs.h>
19
#include <epan/llcsaps.h>
20
#include "packet-bacnet.h"
21
22
void proto_register_bacnet(void);
23
void proto_reg_handoff_bacnet(void);
24
25
static dissector_handle_t bacapp_handle;
26
/* Defined to allow vendor identifier registration of private transfer dissectors */
27
static dissector_table_t bacnet_dissector_table;
28
29
static const range_string bacnet_msgtype_rvals[] = {
30
  { 0x00, 0x00, "Who-Is-Router-To-Network" },
31
  { 0x01, 0x01, "I-Am-Router-To-Network" },
32
  { 0x02, 0x02, "I-Could-Be-Router-To-Network" },
33
  { 0x03, 0x03, "Reject-Message-To-Network" },
34
  { 0x04, 0x04, "Router-Busy-To-Network" },
35
  { 0x05, 0x05, "Router-Available-To-Network" },
36
  { 0x06, 0x06, "Initialize-Routing-Table" },
37
  { 0x07, 0x07, "Initialize-Routing-Table-Ack" },
38
  { 0x08, 0x08, "Establish-Connection-To-Network" },
39
  { 0x09, 0x09, "Disconnect-Connection-To-Network" },
40
  { 0x0A, 0x0A, "Challenge-Request" },
41
  { 0x0B, 0x0B, "Security-Payload" },
42
  { 0x0C, 0x0C, "Security-Response" },
43
  { 0x0D, 0x0D, "Request-Key-Update" },
44
  { 0x0E, 0x0E, "Update-Keyset" },
45
  { 0x0F, 0x0F, "Update-distribution-Key" },
46
  { 0x10, 0x10, "Request-Masterkey" },
47
  { 0x11, 0x11, "Set-Masterkey" },
48
  { 0x12, 0x12, "What-Is-Networknumber" },
49
  { 0x13, 0x13, "Networknumber-Is" },
50
  { 0x14, 0x7F, "Reserved for Use by ASHRAE" },
51
  { 0x80, 0xFF, "Vendor Proprietary Message" },
52
  { 0, 0, NULL }
53
};
54
55
static const range_string bacnet_rejectreason_name_rvals[] = {
56
  { 0x00, 0x00, "Other error." },
57
  { 0x01, 0x01, "The router is not directly connected to DNET and cannot find a router to DNET on any directly connected network using Who-Is-Router-To-Network messages." },
58
  { 0x02, 0x02, "The router is busy and unable to accept messages for the specified DNET at the present time." },
59
  { 0x03, 0x03, "It is an unknown network layer message type." },
60
  { 0x04, 0x04, "The message is too long to be routed to this DNET." },
61
  { 0x05, 0x05, "The router is no longer directly connected to DNET but can reconnect if requested." },
62
  { 0x06, 0x06, "The router is no longer directly connected to DNET and cannot reconnect even if requested." },
63
  { 0x07, 0xFF, "Invalid Rejection Reason." },
64
  { 0, 0, NULL }
65
};
66
67
/* Network Layer Control Information */
68
18.5k
#define BAC_CONTROL_NET   0x80
69
14
#define BAC_CONTROL_RES1  0x40
70
18.6k
#define BAC_CONTROL_DEST  0x20
71
14
#define BAC_CONTROL_RES2  0x10
72
9.33k
#define BAC_CONTROL_SRC   0x08
73
14
#define BAC_CONTROL_EXPECT  0x04
74
14
#define BAC_CONTROL_PRIO_HIGH 0x02
75
14
#define BAC_CONTROL_PRIO_LOW  0x01
76
77
/* Network Layer Wrapper Control Information */
78
19
#define BAC_WRAPPER_CONTROL_NET   0x80
79
179
#define BAC_WRAPPER_MSG_ENCRYPED  0x40
80
14
#define BAC_WRAPPER_RESERVED    0x20
81
155
#define BAC_WRAPPER_AUTHD_PRESENT 0x10
82
14
#define BAC_WRAPPER_DO_NOT_UNWRAP 0x08
83
14
#define BAC_WRAPPER_DO_NOT_DECRPT 0x04
84
14
#define BAC_WRAPPER_NO_TRUST_SRC  0x02
85
14
#define BAC_WRAPPER_SECURE_BY_RTR 0x01
86
87
/* Network Layer Update Keyset Control Information */
88
45
#define BAC_UPDATE_CONTROL_SET1_TIMES_PRESENT   0x80
89
45
#define BAC_UPDATE_CONTROL_SET1_PARAMS_PRESENT    0x40
90
14
#define BAC_UPDATE_CONTROL_CLEAR_SET1       0x20
91
45
#define BAC_UPDATE_CONTROL_SET2_TIMES_PRESENT   0x10
92
45
#define BAC_UPDATE_CONTROL_SET2_PARAMS_PRESENT    0x08
93
14
#define BAC_UPDATE_CONTROL_CLEAR_SET2       0x04
94
14
#define BAC_UPDATE_CONTROL_MORE_FOLLOWS       0x02
95
14
#define BAC_UPDATE_CONTROL_REMOVE_KEYS        0x01
96
97
/* Network Layer Message Types */
98
81
#define BAC_NET_WHO_R   0x00
99
96
#define BAC_NET_IAM_R   0x01
100
8
#define BAC_NET_ICB_R   0x02
101
2
#define BAC_NET_REJ     0x03
102
11
#define BAC_NET_R_BUSY    0x04
103
83
#define BAC_NET_R_AVA   0x05
104
27
#define BAC_NET_INIT_RTAB 0x06
105
47
#define BAC_NET_INIT_RTAB_ACK 0x07
106
7
#define BAC_NET_EST_CON   0x08
107
18
#define BAC_NET_DISC_CON  0x09
108
11
#define BAC_NET_CHALL_REQ 0x0A
109
5
#define BAC_NET_SECUR_PAY 0x0B
110
18
#define BAC_NET_SECUR_RESP  0x0C
111
4
#define BAC_NET_REQ_KEY_UP  0x0D
112
33
#define BAC_NET_UPD_KEYSET  0x0E
113
7
#define BAC_NET_UPD_DKEY  0x0F
114
23
#define BAC_NET_REQ_MKEY  0x10
115
6
#define BAC_NET_SET_MKEY  0x11
116
2
#define BAC_NET_WHAT_NETNR  0x12
117
2
#define BAC_NET_NETNR_IS  0x13
118
119
120
static const true_false_string control_net_set_high = {
121
  "network layer message, message type field present.",
122
  "BACnet APDU, message type field absent."
123
};
124
125
static const true_false_string control_res_high = {
126
  "Shall be zero, but is one.",
127
  "Shall be zero and is zero."
128
};
129
static const true_false_string control_dest_high = {
130
  "DNET, DLEN and Hop Count present. If DLEN=0: broadcast, dest. address field absent.",
131
  "DNET, DLEN, DADR and Hop Count absent."
132
};
133
134
static const true_false_string control_src_high = {
135
  "SNET, SLEN and SADR present, SLEN=0 invalid, SLEN specifies length of SADR",
136
  "SNET, SLEN and SADR absent"
137
};
138
139
static const true_false_string control_expect_high = {
140
  "BACnet-Confirmed-Request-PDU, a segment of BACnet-ComplexACK-PDU or Network Message expecting a reply present.",
141
  "Other than a BACnet-Confirmed-Request-PDU, segment of BACnet-ComplexACK-PDU or network layer message expecting a reply present."
142
};
143
144
static const true_false_string control_prio_high_high = {
145
  "Life Safety or Critical Equipment message.",
146
  "Not a Life Safety or Critical Equipment message."
147
};
148
149
static const true_false_string control_prio_low_high = {
150
  "Urgent message",
151
  "Normal message"
152
};
153
154
static const true_false_string wrapper_control_msg_net = {
155
  "Message is networklayer message",
156
  "Message is applicationlayer message"
157
};
158
159
static const true_false_string wrapper_control_msg_crypted = {
160
  "Message is encrypted message",
161
  "Message is not encrypted message"
162
};
163
164
static const true_false_string wrapper_control_reserved = {
165
  "Shall be zero, but is one.",
166
  "Shall be zero and is zero."
167
};
168
169
static const true_false_string wrapper_control_do_not_unwrap = {
170
  "Do not unwrap message",
171
  "Message may be unwrapped"
172
};
173
174
static const true_false_string wrapper_control_do_not_decrypt = {
175
  "Do not decrypt message",
176
  "Message may be decrypted"
177
};
178
179
static const true_false_string wrapper_control_trusted_source = {
180
  "Message received from trusted source",
181
  "Message received from untrusted source"
182
};
183
184
static const true_false_string security_msg_challenged = {
185
  "Message is challenged",
186
  "Message is not challenged"
187
};
188
189
static const true_false_string update_key_control_remove_keys = {
190
  "Do Remove Keys",
191
  "Do Not Remove Keys"
192
};
193
194
static const true_false_string tfs_clear_do_not_clear = {
195
  "Clear",
196
  "Do Not Clear"
197
};
198
199
static int proto_bacnet;
200
static int hf_bacnet_version;
201
static int hf_bacnet_control;
202
static int hf_bacnet_control_net;
203
static int hf_bacnet_control_res1;
204
static int hf_bacnet_control_dest;
205
static int hf_bacnet_control_res2;
206
static int hf_bacnet_control_src;
207
static int hf_bacnet_control_expect;
208
static int hf_bacnet_control_prio_high;
209
static int hf_bacnet_control_prio_low;
210
static int hf_bacnet_dnet;
211
static int hf_bacnet_dlen;
212
static int hf_bacnet_dadr_eth;
213
static int hf_bacnet_dadr_mstp;
214
static int hf_bacnet_dadr_tmp;
215
static int hf_bacnet_snet;
216
static int hf_bacnet_slen;
217
static int hf_bacnet_sadr_eth;
218
static int hf_bacnet_sadr_mstp;
219
static int hf_bacnet_sadr_tmp;
220
static int hf_bacnet_hopc;
221
static int hf_bacnet_mesgtyp;
222
static int hf_bacnet_vendor;
223
static int hf_bacnet_perf;
224
static int hf_bacnet_rejectreason;
225
static int hf_bacnet_rportnum;
226
static int hf_bacnet_portid;
227
static int hf_bacnet_pinfo;
228
static int hf_bacnet_pinfolen;
229
static int hf_bacnet_term_time_value;
230
static int hf_bacnet_netno_status;
231
232
static int hf_bacnet_wrapper_control;
233
static int hf_bacnet_wrapper_control_secured_by_router;
234
static int hf_bacnet_wrapper_control_non_trusted_source;
235
static int hf_bacnet_wrapper_control_do_not_decrypt;
236
static int hf_bacnet_wrapper_control_do_not_unwrap;
237
static int hf_bacnet_wrapper_control_auth_data_present;
238
static int hf_bacnet_wrapper_control_reserved;
239
static int hf_bacnet_wrapper_control_msg_is_encrypted;
240
static int hf_bacnet_wrapper_control_msg_is_networklayer;
241
static int hf_bacnet_wrapper_key_revision;
242
static int hf_bacnet_wrapper_key_identifier;
243
static int hf_bacnet_wrapper_src_dev_instance;
244
static int hf_bacnet_wrapper_message_id;
245
static int hf_bacnet_wrapper_time_stamp;
246
static int hf_bacnet_wrapper_dst_dev_instance;
247
static int hf_bacnet_wrapper_dnet;
248
static int hf_bacnet_wrapper_dlen;
249
static int hf_bacnet_wrapper_dadr;
250
static int hf_bacnet_wrapper_snet;
251
static int hf_bacnet_wrapper_slen;
252
static int hf_bacnet_wrapper_sadr;
253
static int hf_bacnet_wrapper_auth_mech;
254
static int hf_bacnet_wrapper_auth_usr_id;
255
static int hf_bacnet_wrapper_auth_usr_role;
256
static int hf_bacnet_wrapper_auth_len;
257
static int hf_bacnet_wrapper_auth_data;
258
static int hf_bacnet_wrapper_signature;
259
static int hf_bacnet_wrapper_encrypted_data;
260
static int hf_bacnet_msg_is_challenged;
261
static int hf_bacnet_security_original_message_id;
262
static int hf_bacnet_security_original_time_stamp;
263
static int hf_bacnet_security_msg_len;
264
static int hf_bacnet_security_response_code;
265
static int hf_bacnet_security_response_expected_time_stamp;
266
static int hf_bacnet_security_response_key_algo;
267
static int hf_bacnet_security_response_key_id;
268
static int hf_bacnet_security_response_original_authentication_mech;
269
static int hf_bacnet_security_response_vendor_id;
270
static int hf_bacnet_security_response_key_revision;
271
static int hf_bacnet_security_response_number_keys;
272
static int hf_bacnet_security_set1_key_reveision;
273
static int hf_bacnet_security_set1_activation_time_stamp;
274
static int hf_bacnet_security_set1_expiration_time_stamp;
275
static int hf_bacnet_security_set1_key_algo;
276
static int hf_bacnet_security_set1_key_id;
277
static int hf_bacnet_security_set1_key_data;
278
static int hf_bacnet_security_set2_key_reveision;
279
static int hf_bacnet_security_set2_activation_time_stamp;
280
static int hf_bacnet_security_set2_expiration_time_stamp;
281
static int hf_bacnet_security_set2_key_algo;
282
static int hf_bacnet_security_set2_key_id;
283
static int hf_bacnet_security_set2_key_data;
284
static int hf_bacnet_security_dist_key_revision;
285
static int hf_bacnet_security_dist_key_algo;
286
static int hf_bacnet_security_dist_key_id;
287
static int hf_bacnet_security_dist_key_data;
288
static int hf_bacnet_security_master_key_algo;
289
static int hf_bacnet_security_master_key_id;
290
static int hf_bacnet_security_master_key_data;
291
static int hf_bacnet_update_control;
292
static int hf_bacnet_update_control_remove;
293
static int hf_bacnet_update_control_more_follows;
294
static int hf_bacnet_update_control_clear_set2;
295
static int hf_bacnet_update_control_set2_params_present;
296
static int hf_bacnet_update_control_set2_times_present;
297
static int hf_bacnet_update_control_clear_set1;
298
static int hf_bacnet_update_control_set1_params_present;
299
static int hf_bacnet_update_control_set1_times_present;
300
301
static int ett_bacnet;
302
static int ett_bacnet_control;
303
static int ett_bacnet_wrapper_control;
304
static int ett_bacnet_update_control;
305
306
static dissector_handle_t bacnet_handle;
307
308
static int * const control_flags[] = {
309
  &hf_bacnet_control_net,
310
  &hf_bacnet_control_res1,
311
  &hf_bacnet_control_dest,
312
  &hf_bacnet_control_res2,
313
  &hf_bacnet_control_src,
314
  &hf_bacnet_control_expect,
315
  &hf_bacnet_control_prio_high,
316
  &hf_bacnet_control_prio_low,
317
  NULL
318
};
319
320
static int * const update_control_flags[] = {
321
  &hf_bacnet_update_control_remove,
322
  &hf_bacnet_update_control_more_follows,
323
  &hf_bacnet_update_control_clear_set2,
324
  &hf_bacnet_update_control_set2_params_present,
325
  &hf_bacnet_update_control_set2_times_present,
326
  &hf_bacnet_update_control_clear_set1,
327
  &hf_bacnet_update_control_set1_params_present,
328
  &hf_bacnet_update_control_set1_times_present,
329
  NULL
330
};
331
332
static int * const wrapper_control_flags[] = {
333
  &hf_bacnet_wrapper_control_secured_by_router,
334
  &hf_bacnet_wrapper_control_non_trusted_source,
335
  &hf_bacnet_wrapper_control_do_not_decrypt,
336
  &hf_bacnet_wrapper_control_do_not_unwrap,
337
  &hf_bacnet_wrapper_control_auth_data_present,
338
  &hf_bacnet_wrapper_control_reserved,
339
  &hf_bacnet_wrapper_control_msg_is_encrypted,
340
  &hf_bacnet_wrapper_control_msg_is_networklayer,
341
  NULL
342
};
343
344
345
int
346
bacnet_dissect_sec_wrapper(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree,
347
          int offset, bool *pis_net_msg_flg)
348
165
{
349
165
  uint8_t bacnet_dlen;
350
165
  uint8_t bacnet_wrapper_control;
351
165
  uint16_t bacnet_len;
352
165
  int len;
353
354
  /* get control octet from wrapper */
355
165
  bacnet_wrapper_control = tvb_get_uint8(tvb, offset);
356
165
  if (pis_net_msg_flg)
357
5
    *pis_net_msg_flg = (bacnet_wrapper_control & BAC_WRAPPER_CONTROL_NET) != 0;
358
359
165
  proto_tree_add_bitmask(tree, tvb, offset, hf_bacnet_wrapper_control,
360
165
    ett_bacnet_wrapper_control, wrapper_control_flags, ENC_NA);
361
165
  offset++;
362
363
165
  proto_tree_add_item(tree, hf_bacnet_wrapper_key_revision,
364
165
    tvb, offset, 1, ENC_BIG_ENDIAN);
365
165
  offset++;
366
367
165
  proto_tree_add_item(tree, hf_bacnet_wrapper_key_identifier,
368
165
    tvb, offset, 2, ENC_BIG_ENDIAN);
369
165
  offset += 2;
370
371
165
  proto_tree_add_item(tree, hf_bacnet_wrapper_src_dev_instance,
372
165
    tvb, offset, 3, ENC_BIG_ENDIAN);
373
165
  offset += 3;
374
375
165
  proto_tree_add_item(tree, hf_bacnet_wrapper_message_id,
376
165
    tvb, offset, 4, ENC_BIG_ENDIAN);
377
165
  offset += 4;
378
379
165
  proto_tree_add_item(tree, hf_bacnet_wrapper_time_stamp,
380
165
    tvb, offset, 4, ENC_BIG_ENDIAN);
381
165
  offset += 4;
382
383
  /* we only can use unencrypted data here */
384
165
  if ((bacnet_wrapper_control & BAC_WRAPPER_MSG_ENCRYPED) == 0) {
385
141
    proto_tree_add_item(tree, hf_bacnet_wrapper_dst_dev_instance,
386
141
      tvb, offset, 3, ENC_BIG_ENDIAN);
387
141
    offset += 3;
388
389
141
    proto_tree_add_item(tree, hf_bacnet_wrapper_dnet,
390
141
      tvb, offset, 2, ENC_BIG_ENDIAN);
391
141
    offset += 2;
392
393
141
    bacnet_dlen = tvb_get_uint8(tvb, offset);
394
141
    proto_tree_add_item(tree, hf_bacnet_wrapper_dlen,
395
141
      tvb, offset, 1, ENC_BIG_ENDIAN);
396
141
    offset++;
397
398
141
    proto_tree_add_item(tree,
399
141
      hf_bacnet_wrapper_dadr, tvb, offset,
400
141
      bacnet_dlen, ENC_NA);
401
141
    offset += bacnet_dlen;
402
403
141
    proto_tree_add_item(tree, hf_bacnet_wrapper_snet,
404
141
      tvb, offset, 2, ENC_BIG_ENDIAN);
405
141
    offset += 2;
406
407
141
    bacnet_dlen = tvb_get_uint8(tvb, offset);
408
141
    proto_tree_add_item(tree, hf_bacnet_wrapper_slen,
409
141
      tvb, offset, 1, ENC_BIG_ENDIAN);
410
141
    offset++;
411
412
141
    proto_tree_add_item(tree,
413
141
      hf_bacnet_wrapper_sadr, tvb, offset,
414
141
      bacnet_dlen, ENC_NA);
415
141
    offset += bacnet_dlen;
416
417
    /* additional authentication data is optional */
418
141
    if ((bacnet_wrapper_control & BAC_WRAPPER_AUTHD_PRESENT) != 0) {
419
6
      bacnet_dlen = tvb_get_uint8(tvb, offset);
420
6
      proto_tree_add_item(tree, hf_bacnet_wrapper_auth_mech,
421
6
        tvb, offset, 1, ENC_BIG_ENDIAN);
422
6
      offset++;
423
424
6
      proto_tree_add_item(tree, hf_bacnet_wrapper_auth_usr_id,
425
6
        tvb, offset, 2, ENC_BIG_ENDIAN);
426
6
      offset += 2;
427
428
6
      proto_tree_add_item(tree, hf_bacnet_wrapper_auth_usr_role,
429
6
        tvb, offset, 1, ENC_BIG_ENDIAN);
430
6
      offset++;
431
432
      /* extra authentication data present if authentication mechanism != 0 */
433
6
      if (bacnet_dlen != 0) {
434
2
        bacnet_len = tvb_get_uint16(tvb, offset, ENC_BIG_ENDIAN);
435
2
        proto_tree_add_item(tree, hf_bacnet_wrapper_auth_len,
436
2
          tvb, offset, 2, ENC_BIG_ENDIAN);
437
2
        offset += 2;
438
439
2
        proto_tree_add_item(tree,
440
2
          hf_bacnet_wrapper_auth_data, tvb, offset,
441
2
          bacnet_len, ENC_NA);
442
2
        offset += bacnet_len;
443
2
      }
444
6
    }
445
446
    /* signature is always present and not encryped in the last 16
447
       bytes of a secured BACnet frame */
448
141
    len = tvb_reported_length_remaining(tvb, 0) - 16;
449
141
    proto_tree_add_item(tree,
450
141
      hf_bacnet_wrapper_signature, tvb, len,
451
141
      16, ENC_NA);
452
453
    /* offset is pointing to the start of the secured service data which
454
       is followed by the signature which we already have listed as part
455
       of the wrapper so we remove the signature now */
456
141
    tvb_set_reported_length(tvb, len);
457
141
  }
458
24
  else {
459
    /* signature is always present and not encryped in the last 16
460
    bytes of a secured BACnet frame */
461
24
    len = tvb_reported_length_remaining(tvb, 0) - 16;
462
24
    proto_tree_add_item(tree,
463
24
      hf_bacnet_wrapper_signature, tvb, len,
464
24
      16, ENC_NA);
465
    /* print the encrypted data now because we are not able to decode it anyway */
466
24
    len = tvb_reported_length_remaining(tvb, offset) - 16;
467
24
    proto_tree_add_item(tree,
468
24
      hf_bacnet_wrapper_encrypted_data, tvb, offset,
469
24
      len, ENC_NA);
470
    /* no further decoding possible */
471
24
    tvb_set_reported_length(tvb, 0);
472
24
    offset = -1;
473
24
  }
474
475
165
  return offset;
476
165
}
477
478
479
static int
480
// NOLINTNEXTLINE(misc-no-recursion)
481
dissect_bacnet_npdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset)
482
9.32k
{
483
9.32k
  proto_item *ti;
484
9.32k
  proto_tree *bacnet_tree;
485
486
9.32k
  uint8_t bacnet_version;
487
9.32k
  uint8_t bacnet_control;
488
9.32k
  uint8_t bacnet_update_control;
489
9.32k
  uint8_t bacnet_dlen;
490
9.32k
  uint8_t bacnet_slen;
491
9.32k
  uint8_t bacnet_mesgtyp;
492
9.32k
  uint8_t bacnet_rportnum;
493
9.32k
  uint8_t bacnet_pinfolen;
494
9.32k
  uint8_t i;
495
9.32k
  tvbuff_t *next_tvb;
496
9.32k
  uint32_t vendor_id;
497
498
9.32k
  col_set_str(pinfo->cinfo, COL_PROTOCOL, "BACnet-NPDU");
499
9.32k
  col_set_str(pinfo->cinfo, COL_INFO, "Building Automation and Control Network NPDU");
500
501
9.32k
  bacnet_version = tvb_get_uint8(tvb, offset);
502
9.32k
  bacnet_control = tvb_get_uint8(tvb, offset+1);
503
504
  /* I don't know the length of the NPDU yet; Setting the length after dissection */
505
9.32k
  ti = proto_tree_add_item(tree, proto_bacnet, tvb, 0, -1, ENC_NA);
506
507
9.32k
  bacnet_tree = proto_item_add_subtree(ti, ett_bacnet);
508
509
9.32k
  proto_tree_add_uint_format_value(bacnet_tree, hf_bacnet_version, tvb,
510
9.32k
           offset, 1,
511
9.32k
           bacnet_version,"0x%02x (%s)",bacnet_version,
512
9.32k
           (bacnet_version == 0x01)?"ASHRAE 135-1995":"unknown");
513
9.32k
  offset ++;
514
9.32k
  proto_tree_add_bitmask(bacnet_tree, tvb, offset, hf_bacnet_control,
515
9.32k
          ett_bacnet_control, control_flags, ENC_NA);
516
9.32k
  offset ++;
517
9.32k
  if (bacnet_control & BAC_CONTROL_DEST) { /* DNET, DLEN, DADR */
518
1.09k
    proto_tree_add_item(bacnet_tree, hf_bacnet_dnet,
519
1.09k
      tvb, offset, 2, ENC_BIG_ENDIAN);
520
1.09k
    offset += 2;
521
1.09k
    bacnet_dlen = tvb_get_uint8(tvb, offset);
522
    /* DLEN = 0 is broadcast on dest.network */
523
1.09k
    if( bacnet_dlen == 0) {
524
      /* append to hf_bacnet_dlen: broadcast */
525
345
      proto_tree_add_uint_format_value(bacnet_tree,
526
345
          hf_bacnet_dlen, tvb, offset, 1, bacnet_dlen,
527
345
          "%d indicates Broadcast on Destination Network",
528
345
          bacnet_dlen);
529
345
      offset ++;
530
      /* going to SNET */
531
745
    } else if (bacnet_dlen==6) {
532
9
      proto_tree_add_item(bacnet_tree, hf_bacnet_dlen,
533
9
        tvb, offset, 1, ENC_BIG_ENDIAN);
534
9
      offset ++;
535
      /* Ethernet MAC */
536
9
      proto_tree_add_item(bacnet_tree,
537
9
        hf_bacnet_dadr_eth, tvb, offset,
538
9
        bacnet_dlen, ENC_NA);
539
9
      offset += bacnet_dlen;
540
736
    } else if (bacnet_dlen==1) {
541
54
      proto_tree_add_item(bacnet_tree, hf_bacnet_dlen,
542
54
        tvb, offset, 1, ENC_BIG_ENDIAN);
543
54
      offset ++;
544
      /* MS/TP or ARCNET MAC */
545
54
      proto_tree_add_item(bacnet_tree,
546
54
        hf_bacnet_dadr_mstp, tvb, offset,
547
54
        bacnet_dlen, ENC_BIG_ENDIAN);
548
54
      offset += bacnet_dlen;
549
682
    } else if (bacnet_dlen<7) {
550
49
      proto_tree_add_item(bacnet_tree, hf_bacnet_dlen,
551
49
        tvb, offset, 1, ENC_BIG_ENDIAN);
552
49
      offset ++;
553
      /* Other MAC formats should be included here */
554
49
      proto_tree_add_item(bacnet_tree,
555
49
        hf_bacnet_dadr_tmp, tvb, offset,
556
49
        bacnet_dlen, ENC_NA);
557
49
      offset += bacnet_dlen;
558
633
    } else {
559
633
      proto_tree_add_uint_format_value(bacnet_tree,
560
633
          hf_bacnet_dlen, tvb, offset, 1, bacnet_dlen,
561
633
          "%d invalid!",
562
633
          bacnet_dlen);
563
633
    }
564
1.09k
  }
565
9.32k
  if (bacnet_control & BAC_CONTROL_SRC) { /* SNET, SLEN, SADR */
566
    /* SNET */
567
1.26k
    proto_tree_add_item(bacnet_tree, hf_bacnet_snet,
568
1.26k
      tvb, offset, 2, ENC_BIG_ENDIAN);
569
1.26k
    offset += 2;
570
1.26k
    bacnet_slen = tvb_get_uint8(tvb, offset);
571
1.26k
    if( bacnet_slen == 0) { /* SLEN = 0 invalid */
572
326
      proto_tree_add_uint_format_value(bacnet_tree,
573
326
          hf_bacnet_slen, tvb, offset, 1, bacnet_slen,
574
326
          "%d invalid!",
575
326
          bacnet_slen);
576
326
      offset ++;
577
942
    } else if (bacnet_slen==6) {
578
      /* SLEN */
579
19
       proto_tree_add_item(bacnet_tree, hf_bacnet_slen,
580
19
        tvb, offset, 1, ENC_BIG_ENDIAN);
581
19
      offset ++;
582
      /* Ethernet MAC */
583
19
      proto_tree_add_item(bacnet_tree,
584
19
        hf_bacnet_sadr_eth, tvb, offset,
585
19
        bacnet_slen, ENC_NA);
586
19
      offset += bacnet_slen;
587
923
    } else if (bacnet_slen==1) {
588
      /* SLEN */
589
55
       proto_tree_add_item(bacnet_tree, hf_bacnet_slen,
590
55
        tvb, offset, 1, ENC_BIG_ENDIAN);
591
55
      offset ++;
592
      /* MS/TP or ARCNET MAC */
593
55
      proto_tree_add_item(bacnet_tree,
594
55
        hf_bacnet_sadr_mstp, tvb, offset,
595
55
        bacnet_slen, ENC_BIG_ENDIAN);
596
55
      offset += bacnet_slen;
597
868
    } else if (bacnet_slen<6) { /* LON MAC */
598
      /* SLEN */
599
77
       proto_tree_add_item(bacnet_tree, hf_bacnet_slen,
600
77
        tvb, offset, 1, ENC_BIG_ENDIAN);
601
77
      offset ++;
602
      /* Other MAC formats should be included here */
603
77
      proto_tree_add_item(bacnet_tree,
604
77
        hf_bacnet_sadr_tmp, tvb, offset,
605
77
        bacnet_slen, ENC_NA);
606
77
      offset += bacnet_slen;
607
791
    } else {
608
791
      proto_tree_add_uint_format_value(bacnet_tree,
609
791
      hf_bacnet_slen, tvb, offset, 1, bacnet_slen,
610
791
          "%d invalid!",
611
791
          bacnet_slen);
612
791
      offset ++;
613
791
    }
614
1.26k
  }
615
9.32k
  if (bacnet_control & BAC_CONTROL_DEST) { /* Hopcount */
616
1.08k
    proto_tree_add_item(bacnet_tree, hf_bacnet_hopc,
617
1.08k
      tvb, offset, 1, ENC_BIG_ENDIAN);
618
1.08k
    offset ++;
619
1.08k
  }
620
  /* Network Layer Message Type */
621
9.32k
  if (bacnet_control & BAC_CONTROL_NET) {
622
435
    bacnet_mesgtyp =  tvb_get_uint8(tvb, offset);
623
435
    proto_tree_add_uint(bacnet_tree, hf_bacnet_mesgtyp, tvb, offset, 1, bacnet_mesgtyp);
624
    /* Put the NPDU Type in the info column */
625
435
    col_add_str(pinfo->cinfo, COL_INFO, rval_to_str_const(bacnet_mesgtyp, bacnet_msgtype_rvals, "Unknown"));
626
435
    offset++;
627
435
    switch (bacnet_mesgtyp) {
628
    /* Performance Index (in I-Could-Be-Router-To-Network) */
629
8
    case BAC_NET_ICB_R:
630
8
      proto_tree_add_item(bacnet_tree, hf_bacnet_dnet,
631
8
        tvb, offset, 2, ENC_BIG_ENDIAN);
632
8
      offset += 2;
633
8
      proto_tree_add_item(bacnet_tree, hf_bacnet_perf,
634
8
        tvb, offset, 1, ENC_BIG_ENDIAN);
635
8
      offset ++;
636
8
      break;
637
    /* Reason, DNET (in Reject-Message-To-Network) */
638
2
    case BAC_NET_REJ:
639
2
      proto_tree_add_item(bacnet_tree,
640
2
        hf_bacnet_rejectreason,
641
2
        tvb, offset, 1, ENC_NA);
642
2
      offset ++;
643
2
      proto_tree_add_item(bacnet_tree, hf_bacnet_dnet,
644
2
        tvb, offset, 2, ENC_BIG_ENDIAN);
645
2
      offset += 2;
646
2
      break;
647
    /* N*DNET (in Router-Busy-To-Network,Router-Available-To-Network) */
648
11
    case BAC_NET_R_BUSY:
649
81
    case BAC_NET_WHO_R:
650
83
    case BAC_NET_R_AVA:
651
96
    case BAC_NET_IAM_R:
652
1.75k
      while(tvb_reported_length_remaining(tvb, offset) > 1 ) {
653
1.65k
        proto_tree_add_item(bacnet_tree, hf_bacnet_dnet,
654
1.65k
          tvb, offset, 2, ENC_BIG_ENDIAN);
655
1.65k
        offset += 2;
656
1.65k
      }
657
96
      break;
658
    /* Initialize-Routing-Table */
659
27
    case BAC_NET_INIT_RTAB:
660
47
    case BAC_NET_INIT_RTAB_ACK:
661
47
      bacnet_rportnum = tvb_get_uint8(tvb, offset);
662
      /* number of ports */
663
47
      proto_tree_add_item(bacnet_tree, hf_bacnet_rportnum,
664
47
        tvb, offset, 1, ENC_BIG_ENDIAN);
665
47
      offset ++;
666
197
      for (i = 0; tvb_reported_length_remaining(tvb, offset) > 1 && i < bacnet_rportnum; i++) {
667
          /* Connected DNET */
668
150
          proto_tree_add_item(bacnet_tree, hf_bacnet_dnet,
669
150
          tvb, offset, 2, ENC_BIG_ENDIAN);
670
150
          offset += 2;
671
          /* Port ID */
672
150
          proto_tree_add_item(bacnet_tree, hf_bacnet_portid,
673
150
          tvb, offset, 1, ENC_BIG_ENDIAN);
674
150
          offset ++;
675
          /* Port Info Length */
676
150
          bacnet_pinfolen = tvb_get_uint8(tvb, offset);
677
150
          proto_tree_add_item(bacnet_tree, hf_bacnet_pinfolen,
678
150
          tvb, offset, 1, ENC_BIG_ENDIAN);
679
150
          offset ++;
680
150
          proto_tree_add_item(bacnet_tree, hf_bacnet_pinfo, tvb, offset,
681
150
          bacnet_pinfolen, ENC_NA);
682
150
          offset += bacnet_pinfolen;
683
150
      }
684
47
      break;
685
    /* Establish-Connection-To-Network */
686
7
    case BAC_NET_EST_CON:
687
7
      proto_tree_add_item(bacnet_tree, hf_bacnet_dnet,
688
7
        tvb, offset, 2, ENC_BIG_ENDIAN);
689
7
      offset += 2;
690
7
      proto_tree_add_item(bacnet_tree, hf_bacnet_term_time_value,
691
7
        tvb, offset, 1, ENC_BIG_ENDIAN);
692
7
      offset ++;
693
7
      break;
694
    /* Disconnect-Connection-To-Network */
695
18
    case BAC_NET_DISC_CON:
696
18
      proto_tree_add_item(bacnet_tree, hf_bacnet_dnet,
697
18
        tvb, offset, 2, ENC_BIG_ENDIAN);
698
18
      offset += 2;
699
18
      break;
700
    /* What-Is-Networknumber */
701
2
    case BAC_NET_WHAT_NETNR:
702
2
      break;
703
    /* Networknumber-Is */
704
2
    case BAC_NET_NETNR_IS:
705
2
      proto_tree_add_item(bacnet_tree, hf_bacnet_dnet,
706
2
        tvb, offset, 2, ENC_BIG_ENDIAN);
707
2
      offset += 2;
708
2
      proto_tree_add_item(bacnet_tree, hf_bacnet_netno_status,
709
2
        tvb, offset, 1, ENC_BIG_ENDIAN);
710
2
      offset++;
711
2
      break;
712
    /* Challenge-Request */
713
11
    case BAC_NET_CHALL_REQ:
714
11
      offset = bacnet_dissect_sec_wrapper(tvb, pinfo, tree, offset, NULL);
715
11
      if (offset < 0) {
716
4
        call_data_dissector(tvb, pinfo, tree);
717
4
        return tvb_captured_length(tvb);
718
4
      }
719
720
7
      proto_tree_add_item(tree, hf_bacnet_msg_is_challenged,
721
7
        tvb, offset, 1, ENC_BIG_ENDIAN);
722
7
      offset++;
723
724
7
      proto_tree_add_item(tree, hf_bacnet_security_original_message_id,
725
7
        tvb, offset, 4, ENC_BIG_ENDIAN);
726
7
      offset += 4;
727
728
7
      proto_tree_add_item(tree, hf_bacnet_security_original_time_stamp,
729
7
        tvb, offset, 4, ENC_BIG_ENDIAN);
730
7
      offset += 4;
731
7
      break;
732
    /* Security-Payload */
733
5
    case BAC_NET_SECUR_PAY:
734
5
    {
735
5
      bool is_net_msg_flg;
736
5
      uint16_t bacnet_len;
737
738
5
      offset = bacnet_dissect_sec_wrapper(tvb, pinfo, tree, offset, &is_net_msg_flg);
739
5
      if (offset < 0) {
740
1
        call_data_dissector(tvb, pinfo, tree);
741
1
        return tvb_captured_length(tvb);
742
1
      }
743
      /* get payload length */
744
4
      bacnet_len = tvb_get_uint16(tvb, offset, ENC_BIG_ENDIAN);
745
4
      proto_tree_add_item(tree, hf_bacnet_security_msg_len,
746
4
        tvb, offset, 2, ENC_BIG_ENDIAN);
747
4
      offset += 2;
748
      /* set length to reported length in header */
749
4
      tvb_set_reported_length(tvb, bacnet_len);
750
4
      if (is_net_msg_flg) {
751
        /* decode network layer message */
752
2
        increment_dissection_depth(pinfo);
753
2
        int npdu_len = dissect_bacnet_npdu(tvb, pinfo, tree, offset);
754
2
        decrement_dissection_depth(pinfo);
755
2
        return npdu_len;
756
2
      }
757
      /* APDU - call the APDU dissector */
758
2
      next_tvb = tvb_new_subset_remaining(tvb, offset);
759
2
      call_dissector(bacapp_handle, next_tvb, pinfo, tree);
760
2
      return tvb_captured_length(tvb);
761
4
    }
762
    /* Security-Response */
763
18
    case BAC_NET_SECUR_RESP:
764
18
    {
765
18
      uint8_t bacnet_responsecode;
766
767
18
      offset = bacnet_dissect_sec_wrapper(tvb, pinfo, tree, offset, NULL);
768
18
      if (offset < 0) {
769
2
        call_data_dissector(tvb, pinfo, tree);
770
2
        return tvb_captured_length(tvb);
771
2
      }
772
773
16
      bacnet_responsecode = tvb_get_uint8(tvb, offset);
774
16
      proto_tree_add_item(tree, hf_bacnet_security_response_code,
775
16
        tvb, offset, 1, ENC_BIG_ENDIAN);
776
16
      offset++;
777
778
16
      proto_tree_add_item(tree, hf_bacnet_security_original_message_id,
779
16
        tvb, offset, 4, ENC_BIG_ENDIAN);
780
16
      offset += 4;
781
782
16
      proto_tree_add_item(tree, hf_bacnet_security_original_time_stamp,
783
16
        tvb, offset, 4, ENC_BIG_ENDIAN);
784
16
      offset += 4;
785
786
16
      switch (bacnet_responsecode)
787
16
      {
788
1
      case 0x00: /* success */
789
2
      case 0x01: /* accessDenied */
790
2
      case 0x02: /* badDestinationAddress */
791
2
      case 0x03: /* badDestinationDeviceId */
792
2
      case 0x04: /* badSignature */
793
2
      case 0x05: /* badSourceAddress */
794
2
      case 0x08: /* cannotVerifyMessageId */
795
2
      case 0x09: /* correctKeyRevision */
796
2
      case 0x0A: /* destinationDeviceIdRequired */
797
2
      case 0x0B: /* duplicateMessage */
798
2
      case 0x0C: /* encryptionNotConfigured */
799
2
      case 0x0D: /* encryptionRequired */
800
2
      case 0x10: /* keyUpdateInProgress */
801
2
      case 0x11: /* malformedMessage */
802
2
      case 0x12: /* notKeyServer */
803
2
      case 0x13: /* securityNotConfigured */
804
2
      case 0x14: /* sourceSecurityRequired */
805
2
      case 0x19: /* unknownSourceMessage */
806
2
      default:
807
        /* no parameters are expected here */
808
2
        break;
809
2
      case 0x06: /* badTimestamp */
810
0
        proto_tree_add_item(tree, hf_bacnet_security_response_expected_time_stamp,
811
0
          tvb, offset, 4, ENC_BIG_ENDIAN);
812
0
        offset += 4;
813
0
        break;
814
1
      case 0x07: /* cannotUseKey */
815
2
      case 0x0F: /* invalidKeyData */
816
4
      case 0x17: /* unknownKey */
817
4
        proto_tree_add_item(tree, hf_bacnet_security_response_key_algo,
818
4
          tvb, offset, 1, ENC_BIG_ENDIAN);
819
4
        offset++;
820
4
        proto_tree_add_item(tree, hf_bacnet_security_response_key_id,
821
4
          tvb, offset, 1, ENC_BIG_ENDIAN);
822
4
        offset++;
823
4
        break;
824
8
      case 0x0E: /* incorrectKey */
825
8
        bacnet_responsecode = tvb_get_uint8(tvb, offset);
826
8
        offset++;
827
93
        while (tvb_reported_length_remaining(tvb, offset) > 1 && bacnet_responsecode > 0) {
828
85
          proto_tree_add_item(tree, hf_bacnet_security_response_key_algo,
829
85
            tvb, offset, 1, ENC_BIG_ENDIAN);
830
85
          offset++;
831
85
          proto_tree_add_item(tree, hf_bacnet_security_response_key_id,
832
85
            tvb, offset, 1, ENC_BIG_ENDIAN);
833
85
          offset++;
834
85
          bacnet_responsecode--;
835
85
        }
836
8
        break;
837
1
      case 0x16: /* unknownAuthenticationType */
838
1
        proto_tree_add_item(tree, hf_bacnet_security_response_original_authentication_mech,
839
1
          tvb, offset, 1, ENC_BIG_ENDIAN);
840
1
        offset++;
841
1
        proto_tree_add_item(tree, hf_bacnet_security_response_vendor_id,
842
1
          tvb, offset, 2, ENC_BIG_ENDIAN);
843
1
        offset += 2;
844
1
        break;
845
1
      case 0x18: /* unknownKeyRevision */
846
1
        proto_tree_add_item(tree, hf_bacnet_security_response_key_revision,
847
1
          tvb, offset, 1, ENC_BIG_ENDIAN);
848
1
        offset++;
849
1
        break;
850
0
      case 0x15: /* tooManyKeys */
851
0
        proto_tree_add_item(tree, hf_bacnet_security_response_number_keys,
852
0
          tvb, offset, 1, ENC_BIG_ENDIAN);
853
0
        offset++;
854
0
        break;
855
16
      }
856
16
    }
857
16
      break;
858
    /* Request-Key-Update */
859
16
    case BAC_NET_REQ_KEY_UP:
860
4
      offset = bacnet_dissect_sec_wrapper(tvb, pinfo, tree, offset, NULL);
861
4
      if (offset < 0) {
862
2
        call_data_dissector(tvb, pinfo, tree);
863
2
        return tvb_captured_length(tvb);
864
2
      }
865
866
2
      proto_tree_add_item(tree, hf_bacnet_security_set1_key_reveision,
867
2
        tvb, offset, 1, ENC_BIG_ENDIAN);
868
2
      offset++;
869
2
      proto_tree_add_item(tree, hf_bacnet_security_set1_activation_time_stamp,
870
2
        tvb, offset, 4, ENC_BIG_ENDIAN);
871
2
      offset += 4;
872
2
      proto_tree_add_item(tree, hf_bacnet_security_set1_expiration_time_stamp,
873
2
        tvb, offset, 4, ENC_BIG_ENDIAN);
874
2
      offset += 4;
875
876
2
      proto_tree_add_item(tree, hf_bacnet_security_set2_key_reveision,
877
2
        tvb, offset, 1, ENC_BIG_ENDIAN);
878
2
      offset++;
879
2
      proto_tree_add_item(tree, hf_bacnet_security_set2_activation_time_stamp,
880
2
        tvb, offset, 4, ENC_BIG_ENDIAN);
881
2
      offset += 4;
882
2
      proto_tree_add_item(tree, hf_bacnet_security_set2_expiration_time_stamp,
883
2
        tvb, offset, 4, ENC_BIG_ENDIAN);
884
2
      offset += 4;
885
886
2
      proto_tree_add_item(tree, hf_bacnet_security_dist_key_revision,
887
2
        tvb, offset, 1, ENC_BIG_ENDIAN);
888
2
      offset++;
889
2
      break;
890
    /* Update-Keyset */
891
33
    case BAC_NET_UPD_KEYSET:
892
33
      offset = bacnet_dissect_sec_wrapper(tvb, pinfo, tree, offset, NULL);
893
33
      if (offset < 0) {
894
2
        call_data_dissector(tvb, pinfo, tree);
895
2
        return tvb_captured_length(tvb);
896
2
      }
897
898
31
      bacnet_update_control = tvb_get_uint8(tvb, offset);
899
31
      proto_tree_add_bitmask(tree, tvb, offset, hf_bacnet_update_control,
900
31
        ett_bacnet_update_control, update_control_flags, ENC_NA);
901
31
      offset++;
902
903
31
      if (bacnet_update_control & BAC_UPDATE_CONTROL_SET1_TIMES_PRESENT) {
904
14
        proto_tree_add_item(tree, hf_bacnet_security_set1_key_reveision,
905
14
          tvb, offset, 1, ENC_BIG_ENDIAN);
906
14
        offset++;
907
14
        proto_tree_add_item(tree, hf_bacnet_security_set1_activation_time_stamp,
908
14
          tvb, offset, 4, ENC_BIG_ENDIAN);
909
14
        offset += 4;
910
14
        proto_tree_add_item(tree, hf_bacnet_security_set1_expiration_time_stamp,
911
14
          tvb, offset, 4, ENC_BIG_ENDIAN);
912
14
        offset += 4;
913
14
      }
914
915
31
      if (bacnet_update_control & BAC_UPDATE_CONTROL_SET1_PARAMS_PRESENT) {
916
16
        uint8_t keycount;
917
918
16
        keycount = tvb_get_uint8(tvb, offset);
919
16
        offset++;
920
921
151
        for (i = 0; tvb_reported_length_remaining(tvb, offset) > 1 && i < keycount; i++)  {
922
135
          proto_tree_add_item(tree, hf_bacnet_security_set1_key_algo,
923
135
            tvb, offset, 1, ENC_BIG_ENDIAN);
924
135
          offset++;
925
135
          proto_tree_add_item(tree, hf_bacnet_security_set1_key_id,
926
135
            tvb, offset, 1, ENC_BIG_ENDIAN);
927
135
          offset++;
928
929
135
          bacnet_dlen = tvb_get_uint8(tvb, offset);
930
135
          offset++;
931
932
135
          proto_tree_add_item(tree,
933
135
            hf_bacnet_security_set1_key_data, tvb, offset,
934
135
            bacnet_dlen, ENC_NA);
935
135
          offset += bacnet_dlen;
936
135
        }
937
16
      }
938
939
31
      if (bacnet_update_control & BAC_UPDATE_CONTROL_SET2_TIMES_PRESENT) {
940
5
        proto_tree_add_item(tree, hf_bacnet_security_set2_key_reveision,
941
5
          tvb, offset, 1, ENC_BIG_ENDIAN);
942
5
        offset++;
943
5
        proto_tree_add_item(tree, hf_bacnet_security_set2_activation_time_stamp,
944
5
          tvb, offset, 4, ENC_BIG_ENDIAN);
945
5
        offset += 4;
946
5
        proto_tree_add_item(tree, hf_bacnet_security_set2_expiration_time_stamp,
947
5
          tvb, offset, 4, ENC_BIG_ENDIAN);
948
5
        offset += 4;
949
5
      }
950
951
31
      if (bacnet_update_control & BAC_UPDATE_CONTROL_SET2_PARAMS_PRESENT) {
952
14
        uint8_t keycount;
953
954
14
        keycount = tvb_get_uint8(tvb, offset);
955
14
        offset++;
956
957
111
        for (i = 0; tvb_reported_length_remaining(tvb, offset) > 1 && i < keycount; i++)  {
958
97
          proto_tree_add_item(tree, hf_bacnet_security_set2_key_algo,
959
97
            tvb, offset, 1, ENC_BIG_ENDIAN);
960
97
          offset++;
961
97
          proto_tree_add_item(tree, hf_bacnet_security_set2_key_id,
962
97
            tvb, offset, 1, ENC_BIG_ENDIAN);
963
97
          offset++;
964
965
97
          bacnet_dlen = tvb_get_uint8(tvb, offset);
966
97
          offset++;
967
968
97
          proto_tree_add_item(tree,
969
97
            hf_bacnet_security_set2_key_data, tvb, offset,
970
97
            bacnet_dlen, ENC_NA);
971
97
          offset += bacnet_dlen;
972
97
        }
973
14
      }
974
31
      break;
975
    /* Update-distribution-Key */
976
7
    case BAC_NET_UPD_DKEY:
977
7
      offset = bacnet_dissect_sec_wrapper(tvb, pinfo, tree, offset, NULL);
978
7
      if (offset < 0) {
979
2
        call_data_dissector(tvb, pinfo, tree);
980
2
        return tvb_captured_length(tvb);
981
2
      }
982
983
5
      proto_tree_add_item(tree, hf_bacnet_security_dist_key_revision,
984
5
        tvb, offset, 1, ENC_BIG_ENDIAN);
985
5
      offset++;
986
5
      proto_tree_add_item(tree, hf_bacnet_security_dist_key_algo,
987
5
        tvb, offset, 1, ENC_BIG_ENDIAN);
988
5
      offset++;
989
5
      proto_tree_add_item(tree, hf_bacnet_security_dist_key_id,
990
5
        tvb, offset, 1, ENC_BIG_ENDIAN);
991
5
      offset++;
992
993
5
      bacnet_dlen = tvb_get_uint8(tvb, offset);
994
5
      offset++;
995
996
5
      proto_tree_add_item(tree,
997
5
        hf_bacnet_security_dist_key_data, tvb, offset,
998
5
        bacnet_dlen, ENC_NA);
999
5
      offset += bacnet_dlen;
1000
5
      break;
1001
    /* Request-Masterkey */
1002
23
    case BAC_NET_REQ_MKEY:
1003
23
    {
1004
23
      uint8_t keycount;
1005
1006
23
      offset = bacnet_dissect_sec_wrapper(tvb, pinfo, tree, offset, NULL);
1007
23
      if (offset < 0) {
1008
2
        call_data_dissector(tvb, pinfo, tree);
1009
2
        return tvb_captured_length(tvb);
1010
2
      }
1011
1012
21
      keycount = tvb_get_uint8(tvb, offset);
1013
21
      offset++;
1014
509
      while (tvb_reported_length_remaining(tvb, offset) > 1 && keycount > 0) {
1015
488
        proto_tree_add_item(tree, hf_bacnet_security_master_key_algo,
1016
488
          tvb, offset, 1, ENC_BIG_ENDIAN);
1017
488
        offset++;
1018
488
        keycount--;
1019
488
      }
1020
21
      break;
1021
23
    }
1022
    /* Set-Masterkey */
1023
6
    case BAC_NET_SET_MKEY:
1024
6
      offset = bacnet_dissect_sec_wrapper(tvb, pinfo, tree, offset, NULL);
1025
6
      if (offset < 0) {
1026
2
        call_data_dissector(tvb, pinfo, tree);
1027
2
        return tvb_captured_length(tvb);
1028
2
      }
1029
1030
4
      proto_tree_add_item(tree, hf_bacnet_security_master_key_algo,
1031
4
        tvb, offset, 1, ENC_BIG_ENDIAN);
1032
4
      offset++;
1033
4
      proto_tree_add_item(tree, hf_bacnet_security_master_key_id,
1034
4
        tvb, offset, 1, ENC_BIG_ENDIAN);
1035
4
      offset++;
1036
1037
4
      bacnet_dlen = tvb_get_uint8(tvb, offset);
1038
4
      offset++;
1039
1040
4
      proto_tree_add_item(tree,
1041
4
        hf_bacnet_security_master_key_data, tvb, offset,
1042
4
        bacnet_dlen, ENC_NA);
1043
4
      offset += bacnet_dlen;
1044
4
      break;
1045
145
    default:
1046
      /* Vendor ID
1047
      * The standard says: "If Bit 7 of the control octet is 1 and
1048
      * the Message Type field contains a value in the range
1049
      * X'80' - X'FF', then a Vendor ID field shall be present (...)."
1050
      * We should not go any further in dissecting the packet if it's
1051
      * not present, but we don't know about that: No length field...
1052
      */
1053
145
      if (bacnet_mesgtyp > 0x7f) {
1054
        /* Note: our next_tvb includes message type and vendor id! */
1055
60
        next_tvb = tvb_new_subset_remaining(tvb, offset-1);
1056
60
        vendor_id = tvb_get_ntohs(tvb, offset);
1057
60
        proto_tree_add_item(bacnet_tree, hf_bacnet_vendor, tvb,
1058
60
            offset, 2, ENC_BIG_ENDIAN);
1059
60
        offset += 2;  /* vendor_id */
1060
60
        if (dissector_try_uint(bacnet_dissector_table,
1061
60
            vendor_id, next_tvb, pinfo, bacnet_tree)) {
1062
            /* we parsed it so skip over length and we are done */
1063
            /* Note: offset has now been bumped for message type and vendor
1064
               id so we take that out of our next_tvb size */
1065
0
            offset += tvb_reported_length(next_tvb) -3;
1066
0
        }
1067
60
      }
1068
145
      break;
1069
435
    }
1070
435
  }
1071
1072
  /* Now set NPDU length */
1073
9.24k
  proto_item_set_len(ti, offset);
1074
1075
  /* dissect BACnet APDU */
1076
9.24k
  next_tvb = tvb_new_subset_remaining(tvb,offset);
1077
9.24k
  if (bacnet_control & BAC_CONTROL_NET) {
1078
    /* Unknown function - dissect the payload as data */
1079
355
    call_data_dissector(next_tvb, pinfo, tree);
1080
8.88k
  } else {
1081
    /* APDU - call the APDU dissector */
1082
8.88k
    call_dissector(bacapp_handle, next_tvb, pinfo, tree);
1083
8.88k
  }
1084
9.24k
  return tvb_captured_length(tvb);
1085
9.32k
}
1086
1087
static int
1088
dissect_bacnet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
1089
9.32k
{
1090
9.32k
  return dissect_bacnet_npdu(tvb, pinfo, tree, 0);
1091
9.32k
}
1092
1093
void
1094
proto_register_bacnet(void)
1095
14
{
1096
14
  static hf_register_info hf[] = {
1097
14
    { &hf_bacnet_version,
1098
14
      { "Version",
1099
14
      "bacnet.version",
1100
14
      FT_UINT8, BASE_DEC, NULL, 0,
1101
14
      "BACnet Version", HFILL }
1102
14
    },
1103
14
    { &hf_bacnet_control,
1104
14
      { "Control",
1105
14
      "bacnet.control",
1106
14
      FT_UINT8, BASE_HEX, NULL, 0,
1107
14
      "BACnet Control", HFILL }
1108
14
    },
1109
14
    { &hf_bacnet_control_net,
1110
14
      { "NSDU contains",
1111
14
      "bacnet.control_net",
1112
14
      FT_BOOLEAN, 8, TFS(&control_net_set_high),
1113
14
      BAC_CONTROL_NET, "BACnet Control", HFILL }
1114
14
    },
1115
14
    { &hf_bacnet_control_res1,
1116
14
      { "Reserved",
1117
14
      "bacnet.control_res1",
1118
14
      FT_BOOLEAN, 8, TFS(&control_res_high),
1119
14
      BAC_CONTROL_RES1, "BACnet Control", HFILL }
1120
14
    },
1121
14
    { &hf_bacnet_control_dest,
1122
14
      { "Destination Specifier",
1123
14
      "bacnet.control_dest",
1124
14
      FT_BOOLEAN, 8, TFS(&control_dest_high),
1125
14
      BAC_CONTROL_DEST, "BACnet Control", HFILL }
1126
14
    },
1127
14
    { &hf_bacnet_control_res2,
1128
14
      { "Reserved",
1129
14
      "bacnet.control_res2",
1130
14
      FT_BOOLEAN, 8, TFS(&control_res_high),
1131
14
      BAC_CONTROL_RES2, "BACnet Control", HFILL }
1132
14
    },
1133
14
    { &hf_bacnet_control_src,
1134
14
      { "Source specifier",
1135
14
      "bacnet.control_src",
1136
14
      FT_BOOLEAN, 8, TFS(&control_src_high),
1137
14
      BAC_CONTROL_SRC, "BACnet Control", HFILL }
1138
14
    },
1139
14
    { &hf_bacnet_control_expect,
1140
14
      { "Expecting Reply",
1141
14
      "bacnet.control_expect",
1142
14
      FT_BOOLEAN, 8, TFS(&control_expect_high),
1143
14
      BAC_CONTROL_EXPECT, "BACnet Control", HFILL }
1144
14
    },
1145
14
    { &hf_bacnet_control_prio_high,
1146
14
      { "Priority",
1147
14
      "bacnet.control_prio_high",
1148
14
      FT_BOOLEAN, 8, TFS(&control_prio_high_high),
1149
14
      BAC_CONTROL_PRIO_HIGH, "BACnet Control", HFILL }
1150
14
    },
1151
14
    { &hf_bacnet_control_prio_low,
1152
14
      { "Priority",
1153
14
      "bacnet.control_prio_low",
1154
14
      FT_BOOLEAN, 8, TFS(&control_prio_low_high),
1155
14
      BAC_CONTROL_PRIO_LOW, "BACnet Control", HFILL }
1156
14
    },
1157
14
    { &hf_bacnet_dnet,
1158
14
      { "Destination Network Address",
1159
14
      "bacnet.dnet",
1160
14
      FT_UINT16, BASE_DEC, NULL, 0,
1161
14
      NULL, HFILL }
1162
14
    },
1163
14
    { &hf_bacnet_dlen,
1164
14
      { "Destination MAC Layer Address Length",
1165
14
      "bacnet.dlen",
1166
14
      FT_UINT8, BASE_DEC, NULL, 0,
1167
14
      NULL, HFILL }
1168
14
    },
1169
14
    { &hf_bacnet_dadr_eth,
1170
14
      { "Destination ISO 8802-3 MAC Address",
1171
14
      "bacnet.dadr_eth",
1172
14
      FT_ETHER, BASE_NONE, NULL, 0,
1173
14
      NULL, HFILL }
1174
14
    },
1175
14
    { &hf_bacnet_dadr_mstp,
1176
14
      { "DADR",
1177
14
      "bacnet.dadr_mstp",
1178
14
      FT_UINT8, BASE_DEC, NULL, 0,
1179
14
      "Destination MS/TP or ARCNET MAC Address", HFILL }
1180
14
    },
1181
14
    { &hf_bacnet_dadr_tmp,
1182
14
      { "Unknown Destination MAC",
1183
14
      "bacnet.dadr_tmp",
1184
14
      FT_BYTES, BASE_NONE, NULL, 0,
1185
14
      NULL, HFILL }
1186
14
    },
1187
14
    { &hf_bacnet_snet,
1188
14
      { "Source Network Address",
1189
14
      "bacnet.snet",
1190
14
      FT_UINT16, BASE_DEC, NULL, 0,
1191
14
      NULL, HFILL }
1192
14
    },
1193
14
    { &hf_bacnet_slen,
1194
14
      { "Source MAC Layer Address Length",
1195
14
      "bacnet.slen",
1196
14
      FT_UINT8, BASE_DEC, NULL, 0,
1197
14
      NULL, HFILL }
1198
14
    },
1199
14
    { &hf_bacnet_sadr_eth,
1200
14
      { "SADR",
1201
14
      "bacnet.sadr_eth",
1202
14
      FT_ETHER, BASE_NONE, NULL, 0,
1203
14
      "Source ISO 8802-3 MAC Address", HFILL }
1204
14
    },
1205
14
    { &hf_bacnet_sadr_mstp,
1206
14
      { "SADR",
1207
14
      "bacnet.sadr_mstp",
1208
14
      FT_UINT8, BASE_DEC, NULL, 0,
1209
14
      "Source MS/TP or ARCNET MAC Address", HFILL }
1210
14
    },
1211
14
    { &hf_bacnet_sadr_tmp,
1212
14
      { "Unknown Source MAC",
1213
14
      "bacnet.sadr_tmp",
1214
14
      FT_BYTES, BASE_NONE, NULL, 0,
1215
14
      NULL, HFILL }
1216
14
    },
1217
14
    { &hf_bacnet_hopc,
1218
14
      { "Hop Count",
1219
14
      "bacnet.hopc",
1220
14
      FT_UINT8, BASE_DEC, NULL, 0,
1221
14
      NULL, HFILL }
1222
14
    },
1223
14
    { &hf_bacnet_mesgtyp,
1224
14
      { "Network Layer Message Type",
1225
14
      "bacnet.mesgtyp",
1226
14
      FT_UINT8, BASE_HEX | BASE_RANGE_STRING, RVALS(bacnet_msgtype_rvals), 0,
1227
14
      NULL, HFILL }
1228
14
    },
1229
14
    { &hf_bacnet_vendor,
1230
14
      { "Vendor ID",
1231
14
      "bacnet.vendor",
1232
14
      FT_UINT16, BASE_DEC, NULL, 0,
1233
14
      NULL, HFILL }
1234
14
    },
1235
14
    { &hf_bacnet_perf,
1236
14
      { "Performance Index",
1237
14
      "bacnet.perf",
1238
14
      FT_UINT8, BASE_DEC, NULL, 0,
1239
14
      NULL, HFILL }
1240
14
    },
1241
14
    { &hf_bacnet_rejectreason,
1242
14
      { "Reject Reason",
1243
14
      "bacnet.rejectreason",
1244
14
      FT_UINT8, BASE_DEC| BASE_RANGE_STRING, RVALS(bacnet_rejectreason_name_rvals), 0,
1245
14
      NULL, HFILL }
1246
14
    },
1247
14
    { &hf_bacnet_rportnum,
1248
14
      { "Number of Port Mappings",
1249
14
      "bacnet.rportnum",
1250
14
      FT_UINT8, BASE_DEC, NULL, 0,
1251
14
      NULL, HFILL }
1252
14
    },
1253
14
    { &hf_bacnet_pinfolen,
1254
14
      { "Port Info Length",
1255
14
      "bacnet.pinfolen",
1256
14
      FT_UINT8, BASE_DEC, NULL, 0,
1257
14
      NULL, HFILL }
1258
14
    },
1259
14
    { &hf_bacnet_pinfo,
1260
14
      { "Port Inf",
1261
14
      "bacnet.pinfo",
1262
14
      FT_BYTES, BASE_NONE, NULL, 0,
1263
14
      NULL, HFILL }
1264
14
    },
1265
14
    { &hf_bacnet_portid,
1266
14
      { "Port ID",
1267
14
      "bacnet.portid",
1268
14
      FT_UINT8, BASE_HEX, NULL, 0,
1269
14
      NULL, HFILL }
1270
14
    },
1271
14
    { &hf_bacnet_term_time_value,
1272
14
      { "Termination Time Value (seconds)",
1273
14
      "bacnet.term_time_value",
1274
14
      FT_UINT8, BASE_DEC, NULL, 0,
1275
14
      NULL, HFILL }
1276
14
    },
1277
14
    { &hf_bacnet_netno_status,
1278
14
      { "Network number status (enumerated)",
1279
14
      "bacnet.netno_status",
1280
14
      FT_UINT8, BASE_DEC, NULL, 0,
1281
14
      NULL, HFILL }
1282
14
    },
1283
14
    { &hf_bacnet_wrapper_control,
1284
14
      { "Wrapper control",
1285
14
      "bacnet.wrappercontrol",
1286
14
      FT_UINT8, BASE_HEX, NULL, 0,
1287
14
      "BACnet wrapper control", HFILL }
1288
14
    },
1289
14
    { &hf_bacnet_wrapper_control_secured_by_router,
1290
14
      { "Secured by router",
1291
14
      "bacnet.wrappercontrol_secured_by_router",
1292
14
      FT_BOOLEAN, 8, TFS(&tfs_yes_no),
1293
14
      BAC_WRAPPER_SECURE_BY_RTR, "BACnet wrapper control", HFILL }
1294
14
    },
1295
14
    { &hf_bacnet_wrapper_control_non_trusted_source,
1296
14
      { "Non trusted source",
1297
14
      "bacnet.wrappercontrol_non_trusted_source",
1298
14
      FT_BOOLEAN, 8, TFS(&wrapper_control_trusted_source),
1299
14
      BAC_WRAPPER_NO_TRUST_SRC, "BACnet wrapper control", HFILL }
1300
14
    },
1301
14
    { &hf_bacnet_wrapper_control_do_not_decrypt,
1302
14
      { "Do not decrypt",
1303
14
      "bacnet.wrappercontrol_do_not_decrypt",
1304
14
      FT_BOOLEAN, 8, TFS(&wrapper_control_do_not_decrypt),
1305
14
      BAC_WRAPPER_DO_NOT_DECRPT, "BACnet wrapper control", HFILL }
1306
14
    },
1307
14
    { &hf_bacnet_wrapper_control_do_not_unwrap,
1308
14
      { "Do not unwrap",
1309
14
      "bacnet.wrappercontrol_do_not_unwrap",
1310
14
      FT_BOOLEAN, 8, TFS(&wrapper_control_do_not_unwrap),
1311
14
      BAC_WRAPPER_DO_NOT_UNWRAP, "BACnet wrapper control", HFILL }
1312
14
    },
1313
14
    { &hf_bacnet_wrapper_control_auth_data_present,
1314
14
      { "Authentication data present",
1315
14
      "bacnet.wrappercontrol_auth_data_present",
1316
14
      FT_BOOLEAN, 8, TFS(&tfs_present_not_present),
1317
14
      BAC_WRAPPER_AUTHD_PRESENT, "BACnet wrapper control", HFILL }
1318
14
    },
1319
14
    { &hf_bacnet_wrapper_control_reserved,
1320
14
      { "Reserved",
1321
14
      "bacnet.wrappercontrol_reserved",
1322
14
      FT_BOOLEAN, 8, TFS(&wrapper_control_reserved),
1323
14
      BAC_WRAPPER_RESERVED, "BACnet wrapper control", HFILL }
1324
14
    },
1325
14
    { &hf_bacnet_wrapper_control_msg_is_encrypted,
1326
14
      { "Message is encrypted message",
1327
14
      "bacnet.wrappercontrol_msg_is_crypted",
1328
14
      FT_BOOLEAN, 8, TFS(&wrapper_control_msg_crypted),
1329
14
      BAC_WRAPPER_MSG_ENCRYPED, "BACnet wrapper control", HFILL }
1330
14
    },
1331
14
    { &hf_bacnet_wrapper_control_msg_is_networklayer,
1332
14
      { "Message is networklayer message",
1333
14
      "bacnet.wrappercontrol_msg_is_netlayer",
1334
14
      FT_BOOLEAN, 8, TFS(&wrapper_control_msg_net),
1335
14
      BAC_WRAPPER_CONTROL_NET, "BACnet wrapper control", HFILL }
1336
14
    },
1337
14
    { &hf_bacnet_wrapper_key_revision,
1338
14
      { "Wrapper Key Revision",
1339
14
      "bacnet.wrapper_key_revision",
1340
14
      FT_UINT8, BASE_DEC, NULL, 0,
1341
14
      NULL, HFILL }
1342
14
    },
1343
14
    { &hf_bacnet_wrapper_key_identifier,
1344
14
      { "Wrapper Key Identifier",
1345
14
      "bacnet.wrapper_key_identifier",
1346
14
      FT_UINT16, BASE_DEC, NULL, 0,
1347
14
      NULL, HFILL }
1348
14
    },
1349
14
    { &hf_bacnet_wrapper_src_dev_instance,
1350
14
      { "Wrapper Source Device Instance",
1351
14
      "bacnet.wrapper_src_device_instance",
1352
14
      FT_UINT24, BASE_DEC, NULL, 0,
1353
14
      NULL, HFILL }
1354
14
    },
1355
14
    { &hf_bacnet_wrapper_message_id,
1356
14
      { "Wrapper Message Id",
1357
14
      "bacnet.wrapper_msg_id",
1358
14
      FT_UINT32, BASE_DEC, NULL, 0,
1359
14
      NULL, HFILL }
1360
14
    },
1361
14
    { &hf_bacnet_wrapper_time_stamp,
1362
14
      { "Wrapper Message Timestamp",
1363
14
      "bacnet.wrapper_time_stamp",
1364
14
      FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0,
1365
14
      NULL, HFILL }
1366
14
    },
1367
14
    { &hf_bacnet_wrapper_dst_dev_instance,
1368
14
      { "Wrapper Destination Device Instance",
1369
14
      "bacnet.wrapper_dst_device_instance",
1370
14
      FT_UINT24, BASE_DEC, NULL, 0,
1371
14
      NULL, HFILL }
1372
14
    },
1373
14
    { &hf_bacnet_wrapper_dnet,
1374
14
      { "Wrapper Destination Network Address",
1375
14
      "bacnet.wrapper_dnet",
1376
14
      FT_UINT16, BASE_DEC, NULL, 0,
1377
14
      NULL, HFILL }
1378
14
    },
1379
14
    { &hf_bacnet_wrapper_dlen,
1380
14
      { "Wrapper Destination MAC Layer Address Length",
1381
14
      "bacnet.wrapper_dlen",
1382
14
      FT_UINT8, BASE_DEC, NULL, 0,
1383
14
      NULL, HFILL }
1384
14
    },
1385
14
    { &hf_bacnet_wrapper_dadr,
1386
14
      { "Wrapper Destination MAC",
1387
14
      "bacnet.wrapper_dadr",
1388
14
      FT_BYTES, BASE_NONE, NULL, 0,
1389
14
      NULL, HFILL }
1390
14
    },
1391
14
    { &hf_bacnet_wrapper_snet,
1392
14
      { "Wrapper Source Network Address",
1393
14
      "bacnet.wrapper_snet",
1394
14
      FT_UINT16, BASE_DEC, NULL, 0,
1395
14
      NULL, HFILL }
1396
14
    },
1397
14
    { &hf_bacnet_wrapper_slen,
1398
14
      { "Wrapper Source MAC Layer Address Length",
1399
14
      "bacnet.wrapper_slen",
1400
14
      FT_UINT8, BASE_DEC, NULL, 0,
1401
14
      NULL, HFILL }
1402
14
    },
1403
14
    { &hf_bacnet_wrapper_sadr,
1404
14
      { "Wrapper Source MAC",
1405
14
      "bacnet.wrapper_sadr",
1406
14
      FT_BYTES, BASE_NONE, NULL, 0,
1407
14
      NULL, HFILL }
1408
14
    },
1409
14
    { &hf_bacnet_wrapper_auth_mech,
1410
14
      { "Wrapper Authentication Mechanism",
1411
14
      "bacnet.wrapper_auth_mech",
1412
14
      FT_UINT8, BASE_DEC, NULL, 0,
1413
14
      NULL, HFILL }
1414
14
    },
1415
14
    { &hf_bacnet_wrapper_auth_usr_id,
1416
14
      { "Wrapper Authentication User Id",
1417
14
      "bacnet.wrapper_auth_usr_id",
1418
14
      FT_UINT16, BASE_DEC, NULL, 0,
1419
14
      NULL, HFILL }
1420
14
    },
1421
14
    { &hf_bacnet_wrapper_auth_usr_role,
1422
14
      { "Wrapper Authentication User Role",
1423
14
      "bacnet.wrapper_auth_usr_role",
1424
14
      FT_UINT8, BASE_DEC, NULL, 0,
1425
14
      NULL, HFILL }
1426
14
    },
1427
14
    { &hf_bacnet_wrapper_auth_len,
1428
14
      { "Wrapper Authentication Length",
1429
14
      "bacnet.wrapper_auth_len",
1430
14
      FT_UINT16, BASE_DEC, NULL, 0,
1431
14
      NULL, HFILL }
1432
14
    },
1433
14
    { &hf_bacnet_wrapper_auth_data,
1434
14
      { "Wrapper Authentication Data",
1435
14
      "bacnet.wrapper_auth_data",
1436
14
      FT_BYTES, BASE_NONE, NULL, 0,
1437
14
      NULL, HFILL }
1438
14
    },
1439
14
    { &hf_bacnet_wrapper_signature,
1440
14
      { "Wrapper Signature",
1441
14
      "bacnet.wrapper_signature",
1442
14
      FT_BYTES, BASE_NONE, NULL, 0,
1443
14
      NULL, HFILL }
1444
14
    },
1445
14
    { &hf_bacnet_wrapper_encrypted_data,
1446
14
      { "Wrapper Encrypted Data",
1447
14
      "bacnet.wrapper_encrypted_data",
1448
14
      FT_BYTES, BASE_NONE, NULL, 0,
1449
14
      NULL, HFILL }
1450
14
    },
1451
14
    { &hf_bacnet_msg_is_challenged,
1452
14
      { "Message is challenged message",
1453
14
      "bacnet.is_challenged_message",
1454
14
      FT_BOOLEAN, 8, TFS(&security_msg_challenged),
1455
14
      1, "BACnet security", HFILL }
1456
14
    },
1457
14
    { &hf_bacnet_security_original_message_id,
1458
14
      { "Security Original Message Id",
1459
14
      "bacnet.security_original_message_id",
1460
14
      FT_UINT32, BASE_DEC, NULL, 0,
1461
14
      NULL, HFILL }
1462
14
    },
1463
14
    { &hf_bacnet_security_original_time_stamp,
1464
14
      { "Security Original Message Timestamp",
1465
14
      "bacnet.security_original_time_stamp",
1466
14
      FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0,
1467
14
      NULL, HFILL }
1468
14
    },
1469
14
    { &hf_bacnet_security_msg_len,
1470
14
      { "Security Message Length",
1471
14
      "bacnet.security_message_length",
1472
14
      FT_UINT16, BASE_DEC, NULL, 0,
1473
14
      NULL, HFILL }
1474
14
    },
1475
14
    { &hf_bacnet_security_response_code,
1476
14
      { "Security Response Code",
1477
14
      "bacnet.security_response_code",
1478
14
      FT_UINT8, BASE_DEC, NULL, 0,
1479
14
      NULL, HFILL }
1480
14
    },
1481
14
    { &hf_bacnet_security_response_expected_time_stamp,
1482
14
      { "Security Expected Timestamp",
1483
14
      "bacnet.security_response_expected_time_stamp",
1484
14
      FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0,
1485
14
      NULL, HFILL }
1486
14
    },
1487
14
    { &hf_bacnet_security_response_key_algo,
1488
14
      { "Security Response Key Algorithm",
1489
14
      "bacnet.security_response_key_algorithm",
1490
14
      FT_UINT8, BASE_DEC, NULL, 0,
1491
14
      NULL, HFILL }
1492
14
    },
1493
14
    { &hf_bacnet_security_response_key_id,
1494
14
      { "Security Response Key ID",
1495
14
      "bacnet.security_response_key_id",
1496
14
      FT_UINT8, BASE_DEC, NULL, 0,
1497
14
      NULL, HFILL }
1498
14
    },
1499
14
    { &hf_bacnet_security_response_original_authentication_mech,
1500
14
      { "Security Response Original Authentication Mechanism",
1501
14
      "bacnet.security_response_original_authentication_mechanism",
1502
14
      FT_UINT8, BASE_DEC, NULL, 0,
1503
14
      NULL, HFILL }
1504
14
    },
1505
14
    { &hf_bacnet_security_response_vendor_id,
1506
14
      { "Security Response Vendor ID",
1507
14
      "bacnet.security_response_vendor_id",
1508
14
      FT_UINT16, BASE_DEC, NULL, 0,
1509
14
      NULL, HFILL }
1510
14
    },
1511
14
    { &hf_bacnet_security_response_key_revision,
1512
14
      { "Security Response Key Revision",
1513
14
      "bacnet.security_response_key_revision",
1514
14
      FT_UINT8, BASE_DEC, NULL, 0,
1515
14
      NULL, HFILL }
1516
14
    },
1517
14
    { &hf_bacnet_security_response_number_keys,
1518
14
      { "Security Response Number Of Keys",
1519
14
      "bacnet.security_response_number_of_keys",
1520
14
      FT_UINT8, BASE_DEC, NULL, 0,
1521
14
      NULL, HFILL }
1522
14
    },
1523
14
    { &hf_bacnet_security_set1_key_reveision,
1524
14
      { "Security Set 1 Key Revision",
1525
14
      "bacnet.security_set1_key_revision",
1526
14
      FT_UINT8, BASE_DEC, NULL, 0,
1527
14
      NULL, HFILL }
1528
14
    },
1529
14
    { &hf_bacnet_security_set1_activation_time_stamp,
1530
14
      { "Security Set 1 Activation Timestamp",
1531
14
      "bacnet.security_set1_activation_time_stamp",
1532
14
      FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0,
1533
14
      NULL, HFILL }
1534
14
    },
1535
14
    { &hf_bacnet_security_set1_expiration_time_stamp,
1536
14
      { "Security Set 1 Expiration Timestamp",
1537
14
      "bacnet.security_set1_expiration_time_stamp",
1538
14
      FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0,
1539
14
      NULL, HFILL }
1540
14
    },
1541
14
    { &hf_bacnet_security_set1_key_algo,
1542
14
      { "Security Keyset 1 Algorithm",
1543
14
      "bacnet.security_set1_key_algorithm",
1544
14
      FT_UINT8, BASE_DEC, NULL, 0,
1545
14
      NULL, HFILL }
1546
14
    },
1547
14
    { &hf_bacnet_security_set1_key_id,
1548
14
      { "Security Keyset 1 Key ID",
1549
14
      "bacnet.security_set1_key_id",
1550
14
      FT_UINT8, BASE_DEC, NULL, 0,
1551
14
      NULL, HFILL }
1552
14
    },
1553
14
    { &hf_bacnet_security_set1_key_data,
1554
14
      { "Security Keyset 1 Key Data",
1555
14
      "bacnet.security_set1_key_data",
1556
14
      FT_BYTES, BASE_NONE, NULL, 0,
1557
14
      NULL, HFILL }
1558
14
    },
1559
14
    { &hf_bacnet_security_set2_key_reveision,
1560
14
      { "Security Set 2 Key Revision",
1561
14
      "bacnet.security_set2_key_revision",
1562
14
      FT_UINT8, BASE_DEC, NULL, 0,
1563
14
      NULL, HFILL }
1564
14
    },
1565
14
    { &hf_bacnet_security_set2_activation_time_stamp,
1566
14
      { "Security Set 2 Activation Timestamp",
1567
14
      "bacnet.security_set2_activation_time_stamp",
1568
14
      FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0,
1569
14
      NULL, HFILL }
1570
14
    },
1571
14
    { &hf_bacnet_security_set2_expiration_time_stamp,
1572
14
      { "Security Set 2 Expiration Timestamp",
1573
14
      "bacnet.security_set2_expiration_time_stamp",
1574
14
      FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0,
1575
14
      NULL, HFILL }
1576
14
    },
1577
14
    { &hf_bacnet_security_set2_key_algo,
1578
14
      { "Security Keyset 2 Algorithm",
1579
14
      "bacnet.security_set2_key_algorithm",
1580
14
      FT_UINT8, BASE_DEC, NULL, 0,
1581
14
      NULL, HFILL }
1582
14
    },
1583
14
    { &hf_bacnet_security_set2_key_id,
1584
14
      { "Security Keyset 2 Key ID",
1585
14
      "bacnet.security_set2_key_id",
1586
14
      FT_UINT8, BASE_DEC, NULL, 0,
1587
14
      NULL, HFILL }
1588
14
    },
1589
14
    { &hf_bacnet_security_set2_key_data,
1590
14
      { "Security Keyset 2 Key Data",
1591
14
      "bacnet.security_set2_key_data",
1592
14
      FT_BYTES, BASE_NONE, NULL, 0,
1593
14
      NULL, HFILL }
1594
14
    },
1595
14
    { &hf_bacnet_security_dist_key_revision,
1596
14
      { "Security Distribution Key Revision",
1597
14
      "bacnet.security_distribution_key_revision",
1598
14
      FT_UINT8, BASE_DEC, NULL, 0,
1599
14
      NULL, HFILL }
1600
14
    },
1601
14
    { &hf_bacnet_security_dist_key_algo,
1602
14
      { "Security Keyset 2 Algorithm",
1603
14
      "bacnet.security_distribution_key_algorithm",
1604
14
      FT_UINT8, BASE_DEC, NULL, 0,
1605
14
      NULL, HFILL }
1606
14
    },
1607
14
    { &hf_bacnet_security_dist_key_id,
1608
14
      { "Security Keyset 2 Key ID",
1609
14
      "bacnet.security_distribution_key_id",
1610
14
      FT_UINT8, BASE_DEC, NULL, 0,
1611
14
      NULL, HFILL }
1612
14
    },
1613
14
    { &hf_bacnet_security_dist_key_data,
1614
14
      { "Security Keyset 2 Key Data",
1615
14
      "bacnet.security_distribution_key_data",
1616
14
      FT_BYTES, BASE_NONE, NULL, 0,
1617
14
      NULL, HFILL }
1618
14
    },
1619
14
    { &hf_bacnet_security_master_key_algo,
1620
14
      { "Security Master Key Algorithm",
1621
14
      "bacnet.security_master_key_algorithm",
1622
14
      FT_UINT8, BASE_DEC, NULL, 0,
1623
14
      NULL, HFILL }
1624
14
    },
1625
14
    { &hf_bacnet_security_master_key_id,
1626
14
      { "Security Master Key ID",
1627
14
      "bacnet.security_master_key_id",
1628
14
      FT_UINT8, BASE_DEC, NULL, 0,
1629
14
      NULL, HFILL }
1630
14
    },
1631
14
    { &hf_bacnet_security_master_key_data,
1632
14
      { "Security Master Key Data",
1633
14
      "bacnet.security_master_key_data",
1634
14
      FT_BYTES, BASE_NONE, NULL, 0,
1635
14
      NULL, HFILL }
1636
14
    },
1637
14
    { &hf_bacnet_update_control,
1638
14
      { "Update control",
1639
14
      "bacnet.update_control",
1640
14
      FT_UINT8, BASE_HEX, NULL, 0,
1641
14
      "BACnet update control", HFILL }
1642
14
    },
1643
14
    { &hf_bacnet_update_control_remove,
1644
14
      { "Key Update Control Remove Keys",
1645
14
      "bacnet.update_control_remove_keys",
1646
14
      FT_BOOLEAN, 8, TFS(&update_key_control_remove_keys),
1647
14
      BAC_UPDATE_CONTROL_REMOVE_KEYS, "BACnet update keys control", HFILL }
1648
14
    },
1649
14
    { &hf_bacnet_update_control_more_follows,
1650
14
      { "Key Update Control More Keys Follow",
1651
14
      "bacnet.update_control_more_keys_follow",
1652
14
      FT_BOOLEAN, 8, TFS(&tfs_yes_no),
1653
14
      BAC_UPDATE_CONTROL_MORE_FOLLOWS, "BACnet update keys control", HFILL }
1654
14
    },
1655
14
    { &hf_bacnet_update_control_clear_set2,
1656
14
      { "Key Update Control Set 2 Clear",
1657
14
      "bacnet.update_control_set2_clear",
1658
14
      FT_BOOLEAN, 8, TFS(&tfs_clear_do_not_clear),
1659
14
      BAC_UPDATE_CONTROL_CLEAR_SET2, "BACnet update keys control", HFILL }
1660
14
    },
1661
14
    { &hf_bacnet_update_control_set2_params_present,
1662
14
      { "Key Update Control Set 2 Params Present",
1663
14
      "bacnet.update_control_set2_params_present",
1664
14
      FT_BOOLEAN, 8, TFS(&tfs_present_not_present),
1665
14
      BAC_UPDATE_CONTROL_SET2_PARAMS_PRESENT, "BACnet update keys control", HFILL }
1666
14
    },
1667
14
    { &hf_bacnet_update_control_set2_times_present,
1668
14
      { "Key Update Control Set 2 Time Present",
1669
14
      "bacnet.update_control_set2_time_present",
1670
14
      FT_BOOLEAN, 8, TFS(&tfs_present_not_present),
1671
14
      BAC_UPDATE_CONTROL_SET2_TIMES_PRESENT, "BACnet update keys control", HFILL }
1672
14
    },
1673
14
    { &hf_bacnet_update_control_clear_set1,
1674
14
      { "Key Update Control Set 1 Clear",
1675
14
      "bacnet.update_control_set1_clear",
1676
14
      FT_BOOLEAN, 8, TFS(&tfs_clear_do_not_clear),
1677
14
      BAC_UPDATE_CONTROL_CLEAR_SET1, "BACnet update keys control", HFILL }
1678
14
    },
1679
14
    { &hf_bacnet_update_control_set1_params_present,
1680
14
      { "Key Update Control Set 1 Params Present",
1681
14
      "bacnet.update_control_set1_params_present",
1682
14
      FT_BOOLEAN, 8, TFS(&tfs_present_not_present),
1683
14
      BAC_UPDATE_CONTROL_SET1_PARAMS_PRESENT, "BACnet update keys control", HFILL }
1684
14
    },
1685
14
    { &hf_bacnet_update_control_set1_times_present,
1686
14
      { "Key Update Control Set 1 Time Present",
1687
14
      "bacnet.update_control_set1_time_present",
1688
14
      FT_BOOLEAN, 8, TFS(&tfs_present_not_present),
1689
14
      BAC_UPDATE_CONTROL_SET1_TIMES_PRESENT, "BACnet update keys control", HFILL }
1690
14
    },
1691
14
  };
1692
1693
14
  static int *ett[] = {
1694
14
    &ett_bacnet,
1695
14
    &ett_bacnet_control,
1696
14
    &ett_bacnet_wrapper_control,
1697
14
    &ett_bacnet_update_control,
1698
14
  };
1699
1700
14
  proto_bacnet = proto_register_protocol("Building Automation and Control Network NPDU", "BACnet", "bacnet");
1701
1702
14
  proto_register_field_array(proto_bacnet, hf, array_length(hf));
1703
14
  proto_register_subtree_array(ett, array_length(ett));
1704
1705
14
  bacnet_handle = register_dissector("bacnet", dissect_bacnet, proto_bacnet);
1706
1707
14
  bacnet_dissector_table = register_dissector_table("bacnet.vendor",
1708
14
                "BACnet Vendor Identifier", proto_bacnet,
1709
14
                FT_UINT8, BASE_HEX);
1710
14
}
1711
1712
void
1713
proto_reg_handoff_bacnet(void)
1714
14
{
1715
14
  dissector_add_uint("bvlc.function", 0x04, bacnet_handle);
1716
14
  dissector_add_uint("bvlc.function", 0x09, bacnet_handle);
1717
14
  dissector_add_uint("bvlc.function", 0x0a, bacnet_handle);
1718
14
  dissector_add_uint("bvlc.function", 0x0b, bacnet_handle);
1719
14
  dissector_add_uint("bvlc.function_ipv6", 0x01, bacnet_handle);
1720
14
  dissector_add_uint("bvlc.function_ipv6", 0x02, bacnet_handle);
1721
14
  dissector_add_uint("bvlc.function_ipv6", 0x0c, bacnet_handle);
1722
14
  dissector_add_uint("bvlc.function_ipv6", 0x08, bacnet_handle);
1723
14
  dissector_add_uint("bscvlc.function", 0x01, bacnet_handle);
1724
14
  dissector_add_uint("llc.dsap", SAP_BACNET, bacnet_handle);
1725
14
  bacapp_handle = find_dissector_add_dependency("bacapp", proto_bacnet);
1726
14
}
1727
1728
/*
1729
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
1730
 *
1731
 * Local variables:
1732
 * c-basic-offset: 8
1733
 * tab-width: 8
1734
 * indent-tabs-mode: t
1735
 * End:
1736
 *
1737
 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
1738
 * :indentSize=8:tabSize=8:noTabs=false:
1739
 */