forked from cisagov/icsnpp-bacnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.zeek
924 lines (797 loc) · 38.3 KB
/
main.zeek
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
##! main.zeek
##!
##! Binpac BACnet Protocol Analyzer - Contains the base script-layer functionality for processing
##! events emitted from the analyzer.
##!
##! Author: Stephen Kleinheider
##! Contact: [email protected]
##!
##! Copyright (c) 2023 Battelle Energy Alliance, LLC. All rights reserved.
module Bacnet;
export {
redef enum Log::ID += { LOG_BACNET,
LOG_BACNET_DISCOVERY,
LOG_BACNET_PROPERTY,
LOG_BACNET_DEVICE_CONTROL};
###############################################################################################
################################ BACnet_Header -> bacnet.log ################################
###############################################################################################
type BACnet_Header: record {
ts : time &log; # Timestamp of event
uid : string &log; # Zeek unique ID for connection
id : conn_id &log; # Zeek connection struct (addresses and ports)
is_orig : bool &log; # the message came from the originator/client or the responder/server
source_h : addr &log; # Source IP Address
source_p : port &log; # Source Port
destination_h : addr &log; # Destination IP Address
destination_p : port &log; # Destination Port
bvlc_function : string &log; # BVLC function (see bvlc_functions)
pdu_type : string &log; # APDU type (see apdu_types)
pdu_service : string &log; # APDU service (see unconfirmed_service_choice and confirmed_service_choice)
invoke_id : count &log; # Invoke ID
result_code : string &log; # See (abort_reasons, reject_reasons, and error_codes)
};
global log_bacnet: event(rec: BACnet_Header);
###############################################################################################
################## Who-Is, I-Am, Who-Has, & I-Have -> bacnet_discovery.log ##################
###############################################################################################
type BACnet_Discovery: record {
ts : time &log; # Timestamp of event
uid : string &log; # Zeek unique ID for connection
id : conn_id &log; # Zeek connection struct (addresses and ports)
is_orig : bool &log; # the message came from the originator/client or the responder/server
source_h : addr &log; # Source IP Address
source_p : port &log; # Source Port
destination_h : addr &log; # Destination IP Address
destination_p : port &log; # Destination Port
pdu_service : string &log; # who-is, i-am, who-has, or i-have
device_id_type : string &log; # BACnetObjectIdentifier device (see object_types)
device_id_number : count &log; # BACnetObjectIdentifier device instance number
object_type : string &log; # BACnetObjectIdentifier object (see object_types)
instance_number : count &log; # BACnetObjectIdentifier object instance number
vendor : string &log; # Vendor Name (i-am and i-have requests)
range : string &log; # Specify range of devices to return (in who-is and who-has requests)
object_name : string &log; # Object name searching for (who-has) or responding with (i-have)
};
global log_bacnet_discovery: event(rec: BACnet_Discovery);
###############################################################################################
################### Read-Property & Write-Property -> bacnet_property.log ###################
###############################################################################################
type BACnet_Property: record {
ts : time &log; # Timestamp of event
uid : string &log; # Zeek unique ID for connection
id : conn_id &log; # Zeek connection struct (addresses and ports)
is_orig : bool &log; # the message came from the originator/client or the responder/server
source_h : addr &log; # Source IP Address
source_p : port &log; # Source Port
destination_h : addr &log; # Destination IP Address
destination_p : port &log; # Destination Port
invoke_id : count &log; # invoke ID for help matching requests/responses
pdu_service : string &log; # read-property-request/ack, write-property-request
object_type : string &log; # BACnetObjectIdentifier object (see object_types)
instance_number : count &log; # BACnetObjectIdentifier instance number
property : string &log; # Property type (see property_identifiers)
array_index : count &log; # Array index of property
value : string &log; # Value of property
};
global log_bacnet_property: event(rec: BACnet_Property);
###############################################################################################
######### Reinitialize-Device & Device-Communication-Control -> bacnet_property.log #########
###############################################################################################
type BACnet_Device_Control: record {
ts : time &log; # Timestamp of event
uid : string &log; # Zeek unique ID for connection
id : conn_id &log; # Zeek connection struct (addresses and ports)
is_orig : bool &log; # the message came from the originator/client or the responder/server
source_h : addr &log; # Source IP Address
source_p : port &log; # Source Port
destination_h : addr &log; # Destination IP Address
destination_p : port &log; # Destination Port
invoke_id : count &log; # invoke ID for help matching requests/responses
pdu_service : string &log; # reinitialize_device or device_communication_control
time_duration : count &log; # number of minutes remote device should ignore other APDUs
device_state : string &log; # state to put device into
password : string &log; # password
result : string &log; # Success, Error, Reject, or Abort
result_code : string &log; # resulting Error/Reject/Abort Code
};
global log_bacnet_device_control: event(rec: BACnet_Device_Control);
## Log policies, for log filtering.
global log_policy: Log::PolicyHook;
global log_policy_discovery: Log::PolicyHook;
global log_policy_property: Log::PolicyHook;
global log_policy_device_control: Log::PolicyHook;
}
## Defines BACnet Ports
const ports = { 47808/udp };
redef likely_server_ports += { ports };
###################################################################################################
####### Defines Log Streams for bacnet.log, bacnet_discovery.log, and bacnet_property.log #######
###################################################################################################
event zeek_init() &priority=5{
Log::create_stream(Bacnet::LOG_BACNET, [$columns=BACnet_Header,
$ev=log_bacnet,
$path="bacnet",
$policy=log_policy]);
Log::create_stream(Bacnet::LOG_BACNET_DISCOVERY, [$columns=BACnet_Discovery,
$ev=log_bacnet_discovery,
$path="bacnet_discovery",
$policy=log_policy_discovery]);
Log::create_stream(Bacnet::LOG_BACNET_PROPERTY, [$columns=BACnet_Property,
$ev=log_bacnet_property,
$path="bacnet_property",
$policy=log_policy_property]);
Log::create_stream(Bacnet::LOG_BACNET_DEVICE_CONTROL, [$columns=BACnet_Device_Control,
$ev=log_bacnet_device_control,
$path="bacnet_device_control",
$policy=log_policy_device_control]);
Analyzer::register_for_ports(Analyzer::ANALYZER_BACNET, ports);
}
###################################################################################################
####### Ensure that conn.log:service is set if it has not already been #######
###################################################################################################
function set_service(c: connection) {
if ((!c?$service) || (|c$service| == 0))
add c$service["bacnet"];
}
###################################################################################################
################### Defines logging of bacnet_apdu_header event -> bacnet.log ###################
###################################################################################################
event bacnet_apdu_header(c: connection,
is_orig: bool,
bvlc_function: count,
pdu_type: count,
pdu_service: count,
invoke_id: count,
result_code: count){
set_service(c);
local bacnet_log: BACnet_Header;
bacnet_log$is_orig = is_orig;
bacnet_log$ts = network_time();
bacnet_log$uid = c$uid;
bacnet_log$id = c$id;
if(is_orig)
{
bacnet_log$source_h = c$id$orig_h;
bacnet_log$source_p = c$id$orig_p;
bacnet_log$destination_h = c$id$resp_h;
bacnet_log$destination_p = c$id$resp_p;
}else
{
bacnet_log$source_h = c$id$resp_h;
bacnet_log$source_p = c$id$resp_p;
bacnet_log$destination_h = c$id$orig_h;
bacnet_log$destination_p = c$id$orig_p;
}
bacnet_log$bvlc_function = bvlc_functions[bvlc_function];
if (bvlc_function == 0)
bacnet_log$result_code = bvlc_results[result_code];
if(pdu_type in apdu_types){
bacnet_log$pdu_type = apdu_types[pdu_type];
if (pdu_type != 1)
bacnet_log$invoke_id = invoke_id;
}
switch(pdu_type){
case 5:
bacnet_log$result_code = error_codes[result_code];
fallthrough;
case 0:
fallthrough;
case 2:
fallthrough;
case 3:
bacnet_log$pdu_service = confirmed_service_choice[pdu_service];
break;
case 1:
bacnet_log$pdu_service = unconfirmed_service_choice[pdu_service];
break;
case 6:
bacnet_log$result_code = reject_reasons[result_code];
break;
case 7:
bacnet_log$result_code = abort_reasons[result_code];
break;
default:
break;
}
Log::write(LOG_BACNET, bacnet_log);
}
###################################################################################################
################### Defines logging of bacnet_npdu_header event -> bacnet.log ###################
###################################################################################################
event bacnet_npdu_header(c: connection,
is_orig: bool,
bvlc_function: count,
npdu_message_type: count){
set_service(c);
local bacnet_log: BACnet_Header;
bacnet_log$is_orig = is_orig;
bacnet_log$ts = network_time();
bacnet_log$uid = c$uid;
bacnet_log$id = c$id;
if(is_orig)
{
bacnet_log$source_h = c$id$orig_h;
bacnet_log$source_p = c$id$orig_p;
bacnet_log$destination_h = c$id$resp_h;
bacnet_log$destination_p = c$id$resp_p;
}else
{
bacnet_log$source_h = c$id$resp_h;
bacnet_log$source_p = c$id$resp_p;
bacnet_log$destination_h = c$id$orig_h;
bacnet_log$destination_p = c$id$orig_p;
}
bacnet_log$bvlc_function = bvlc_functions[bvlc_function];
bacnet_log$pdu_type = "NPDU";
bacnet_log$pdu_service = npdu_message_types[npdu_message_type];
Log::write(LOG_BACNET, bacnet_log);
}
###################################################################################################
################ Defines logging of bacnet_who_is event -> bacnet_discovery.log #################
###################################################################################################
event bacnet_who_is(c: connection,
is_orig: bool,
low_limit: count,
high_limit: count){
set_service(c);
local bacnet_discovery: BACnet_Discovery;
bacnet_discovery$is_orig = is_orig;
bacnet_discovery$ts = network_time();
bacnet_discovery$uid = c$uid;
bacnet_discovery$id = c$id;
if(is_orig)
{
bacnet_discovery$source_h = c$id$orig_h;
bacnet_discovery$source_p = c$id$orig_p;
bacnet_discovery$destination_h = c$id$resp_h;
bacnet_discovery$destination_p = c$id$resp_p;
}else
{
bacnet_discovery$source_h = c$id$resp_h;
bacnet_discovery$source_p = c$id$resp_p;
bacnet_discovery$destination_h = c$id$orig_h;
bacnet_discovery$destination_p = c$id$orig_p;
}
bacnet_discovery$pdu_service = "who-is";
if(low_limit == UINT32_MAX)
bacnet_discovery$range = "All";
else
bacnet_discovery$range = fmt("%d-%d", low_limit, high_limit);
Log::write(LOG_BACNET_DISCOVERY, bacnet_discovery);
}
###################################################################################################
################# Defines logging of bacnet_i_am event -> bacnet_discovery.log ##################
###################################################################################################
event bacnet_i_am(c: connection,
is_orig: bool,
object_type: count,
instance_number: count,
max_apdu: count,
segmentation: count,
vendor_id: count){
set_service(c);
local bacnet_discovery: BACnet_Discovery;
bacnet_discovery$is_orig = is_orig;
bacnet_discovery$ts = network_time();
bacnet_discovery$uid = c$uid;
bacnet_discovery$id = c$id;
if(is_orig)
{
bacnet_discovery$source_h = c$id$orig_h;
bacnet_discovery$source_p = c$id$orig_p;
bacnet_discovery$destination_h = c$id$resp_h;
bacnet_discovery$destination_p = c$id$resp_p;
}else
{
bacnet_discovery$source_h = c$id$resp_h;
bacnet_discovery$source_p = c$id$resp_p;
bacnet_discovery$destination_h = c$id$orig_h;
bacnet_discovery$destination_p = c$id$orig_p;
}
bacnet_discovery$pdu_service = "i-am";
if(object_type != UINT32_MAX)
bacnet_discovery$object_type = object_types[object_type];
if(instance_number != UINT32_MAX)
bacnet_discovery$instance_number = instance_number;
bacnet_discovery$vendor = vendors[vendor_id];
Log::write(LOG_BACNET_DISCOVERY, bacnet_discovery);
}
###################################################################################################
################ Defines logging of bacnet_who_has event -> bacnet_discovery.log ################
###################################################################################################
event bacnet_who_has(c: connection,
is_orig: bool,
low_limit: count,
high_limit: count,
object_type: count,
instance_number: count,
object_name: string){
set_service(c);
local bacnet_discovery: BACnet_Discovery;
bacnet_discovery$is_orig = is_orig;
bacnet_discovery$ts = network_time();
bacnet_discovery$uid = c$uid;
bacnet_discovery$id = c$id;
if(is_orig)
{
bacnet_discovery$source_h = c$id$orig_h;
bacnet_discovery$source_p = c$id$orig_p;
bacnet_discovery$destination_h = c$id$resp_h;
bacnet_discovery$destination_p = c$id$resp_p;
}else
{
bacnet_discovery$source_h = c$id$resp_h;
bacnet_discovery$source_p = c$id$resp_p;
bacnet_discovery$destination_h = c$id$orig_h;
bacnet_discovery$destination_p = c$id$orig_p;
}
bacnet_discovery$pdu_service = "who-has";
if(instance_number != UINT32_MAX){
bacnet_discovery$object_type = object_types[object_type];
bacnet_discovery$instance_number = instance_number;
}
if(object_name == "")
bacnet_discovery$object_name = "N/A";
else
bacnet_discovery$object_name = object_name;
if(low_limit == UINT32_MAX)
bacnet_discovery$range = "All";
else
bacnet_discovery$range = fmt("%d-%d", low_limit, high_limit);
Log::write(LOG_BACNET_DISCOVERY, bacnet_discovery);
}
###################################################################################################
################ Defines logging of bacnet_i_have event -> bacnet_discovery.log #################
###################################################################################################
event bacnet_i_have(c: connection,
is_orig: bool,
device_object_type: count,
device_instance_num: count,
object_object_type: count,
object_instance_num: count,
object_name: string){
set_service(c);
local bacnet_discovery: BACnet_Discovery;
bacnet_discovery$is_orig = is_orig;
bacnet_discovery$ts = network_time();
bacnet_discovery$uid = c$uid;
bacnet_discovery$id = c$id;
if(is_orig)
{
bacnet_discovery$source_h = c$id$orig_h;
bacnet_discovery$source_p = c$id$orig_p;
bacnet_discovery$destination_h = c$id$resp_h;
bacnet_discovery$destination_p = c$id$resp_p;
}else
{
bacnet_discovery$source_h = c$id$resp_h;
bacnet_discovery$source_p = c$id$resp_p;
bacnet_discovery$destination_h = c$id$orig_h;
bacnet_discovery$destination_p = c$id$orig_p;
}
bacnet_discovery$pdu_service = "i-have";
if(device_object_type != UINT32_MAX)
bacnet_discovery$device_id_type = object_types[device_object_type];
if(device_instance_num != UINT32_MAX)
bacnet_discovery$device_id_number = device_instance_num;
if(object_object_type != UINT32_MAX)
bacnet_discovery$object_type = object_types[object_object_type];
if(object_instance_num != UINT32_MAX)
bacnet_discovery$instance_number = object_instance_num;
bacnet_discovery$object_name = object_name;
Log::write(LOG_BACNET_DISCOVERY, bacnet_discovery);
}
###################################################################################################
############# Defines logging of bacnet_read_property event -> bacnet_property.log ##############
###################################################################################################
event bacnet_read_property(c: connection,
is_orig: bool,
invoke_id: count,
pdu_service: string,
object_type: count,
instance_number: count,
property_identifier: count,
property_array_index: count){
set_service(c);
local bacnet_property: BACnet_Property;
bacnet_property$is_orig = is_orig;
bacnet_property$ts = network_time();
bacnet_property$uid = c$uid;
bacnet_property$id = c$id;
if(is_orig)
{
bacnet_property$source_h = c$id$orig_h;
bacnet_property$source_p = c$id$orig_p;
bacnet_property$destination_h = c$id$resp_h;
bacnet_property$destination_p = c$id$resp_p;
}else
{
bacnet_property$source_h = c$id$resp_h;
bacnet_property$source_p = c$id$resp_p;
bacnet_property$destination_h = c$id$orig_h;
bacnet_property$destination_p = c$id$orig_p;
}
bacnet_property$invoke_id = invoke_id;
bacnet_property$pdu_service = pdu_service;
bacnet_property$object_type = object_types[object_type];
bacnet_property$instance_number = instance_number;
bacnet_property$property = property_identifiers[property_identifier];
if( property_array_index != UINT32_MAX )
bacnet_property$array_index = property_array_index;
Log::write(LOG_BACNET_PROPERTY, bacnet_property);
}
###################################################################################################
########### Defines logging of bacnet_read_property_ack event -> bacnet_property.log ############
###################################################################################################
event bacnet_read_property_ack(c: connection,
is_orig: bool,
invoke_id: count,
pdu_service: string,
object_type: count,
instance_number: count,
property_identifier: count,
property_array_index: count,
property_value: string){
set_service(c);
local bacnet_property: BACnet_Property;
bacnet_property$is_orig = is_orig;
bacnet_property$ts = network_time();
bacnet_property$uid = c$uid;
bacnet_property$id = c$id;
if(is_orig)
{
bacnet_property$source_h = c$id$orig_h;
bacnet_property$source_p = c$id$orig_p;
bacnet_property$destination_h = c$id$resp_h;
bacnet_property$destination_p = c$id$resp_p;
}else
{
bacnet_property$source_h = c$id$resp_h;
bacnet_property$source_p = c$id$resp_p;
bacnet_property$destination_h = c$id$orig_h;
bacnet_property$destination_p = c$id$orig_p;
}
bacnet_property$invoke_id = invoke_id;
bacnet_property$pdu_service = pdu_service;
bacnet_property$object_type = object_types[object_type];
bacnet_property$instance_number = instance_number;
bacnet_property$property = property_identifiers[property_identifier];
if( property_array_index != UINT32_MAX )
bacnet_property$array_index = property_array_index;
if (property_value != "" && is_num(property_value)) {
switch(property_identifier){
case 36:
bacnet_property$value = event_states[to_count(property_value)];
break;
case 72:
bacnet_property$value = notify_type[to_count(property_value)];
break;
case 79:
bacnet_property$value = object_types[to_count(property_value)];
break;
case 103:
bacnet_property$value = reliability[to_count(property_value)];
break;
case 107:
bacnet_property$value = segmentation_supported_status[to_count(property_value)];
break;
case 112:
bacnet_property$value = device_status[to_count(property_value)];
break;
case 117:
bacnet_property$value = bacnet_units[to_count(property_value)];
break;
case 197:
bacnet_property$value = logging_type[to_count(property_value)];
break;
default:
if (property_value != "")
bacnet_property$value = property_value;
break;
}
} else if (property_value != "") {
bacnet_property$value = property_value;
}
Log::write(LOG_BACNET_PROPERTY, bacnet_property);
}
###################################################################################################
############# Defines logging of bacnet_write_property event -> bacnet_property.log #############
###################################################################################################
event bacnet_write_property(c: connection,
is_orig: bool,
invoke_id: count,
object_type: count,
instance_number: count,
property_identifier: count,
property_array_index: count,
priority: count,
property_value: string){
set_service(c);
local bacnet_property: BACnet_Property;
bacnet_property$is_orig = is_orig;
bacnet_property$ts = network_time();
bacnet_property$uid = c$uid;
bacnet_property$id = c$id;
if(is_orig)
{
bacnet_property$source_h = c$id$orig_h;
bacnet_property$source_p = c$id$orig_p;
bacnet_property$destination_h = c$id$resp_h;
bacnet_property$destination_p = c$id$resp_p;
}else
{
bacnet_property$source_h = c$id$resp_h;
bacnet_property$source_p = c$id$resp_p;
bacnet_property$destination_h = c$id$orig_h;
bacnet_property$destination_p = c$id$orig_p;
}
bacnet_property$invoke_id = invoke_id;
bacnet_property$pdu_service = "write-property";
bacnet_property$object_type = object_types[object_type];
bacnet_property$instance_number = instance_number;
bacnet_property$property = property_identifiers[property_identifier];
if( property_array_index != UINT32_MAX )
bacnet_property$array_index = property_array_index;
if (property_value != "" && is_num(property_value)) {
switch(property_identifier){
case 36:
bacnet_property$value = event_states[to_count(property_value)];
break;
case 72:
bacnet_property$value = notify_type[to_count(property_value)];
break;
case 79:
bacnet_property$value = object_types[to_count(property_value)];
break;
case 103:
bacnet_property$value = reliability[to_count(property_value)];
break;
case 107:
bacnet_property$value = segmentation_supported_status[to_count(property_value)];
break;
case 112:
bacnet_property$value = device_status[to_count(property_value)];
break;
case 117:
bacnet_property$value = bacnet_units[to_count(property_value)];
break;
case 197:
bacnet_property$value = logging_type[to_count(property_value)];
break;
default:
if (property_value != "")
bacnet_property$value = property_value;
break;
}
} else if (property_value != "") {
bacnet_property$value = property_value;
}
Log::write(LOG_BACNET_PROPERTY, bacnet_property);
}
###################################################################################################
############# Defines logging of bacnet_property_error event -> bacnet_property.log #############
###################################################################################################
event bacnet_property_error(c: connection,
is_orig: bool,
invoke_id: count,
pdu_type: count,
pdu_service: count,
result_code: count){
set_service(c);
local bacnet_property: BACnet_Property;
bacnet_property$is_orig = is_orig;
bacnet_property$ts = network_time();
bacnet_property$uid = c$uid;
bacnet_property$id = c$id;
if(is_orig)
{
bacnet_property$source_h = c$id$orig_h;
bacnet_property$source_p = c$id$orig_p;
bacnet_property$destination_h = c$id$resp_h;
bacnet_property$destination_p = c$id$resp_p;
}else
{
bacnet_property$source_h = c$id$resp_h;
bacnet_property$source_p = c$id$resp_p;
bacnet_property$destination_h = c$id$orig_h;
bacnet_property$destination_p = c$id$orig_p;
}
bacnet_property$invoke_id = invoke_id;
bacnet_property$pdu_service = "ERROR: " + confirmed_service_choice[pdu_service];
bacnet_property$object_type = error_codes[result_code];
Log::write(LOG_BACNET_PROPERTY, bacnet_property);
}
event bacnet_read_range(c: connection,
is_orig: bool,
invoke_id: count,
object_type: count,
instance_number: count,
property_identifier: count,
property_array_index: count){
set_service(c);
local bacnet_property: BACnet_Property;
bacnet_property$is_orig = is_orig;
bacnet_property$ts = network_time();
bacnet_property$uid = c$uid;
bacnet_property$id = c$id;
if(is_orig)
{
bacnet_property$source_h = c$id$orig_h;
bacnet_property$source_p = c$id$orig_p;
bacnet_property$destination_h = c$id$resp_h;
bacnet_property$destination_p = c$id$resp_p;
}else
{
bacnet_property$source_h = c$id$resp_h;
bacnet_property$source_p = c$id$resp_p;
bacnet_property$destination_h = c$id$orig_h;
bacnet_property$destination_p = c$id$orig_p;
}
bacnet_property$invoke_id = invoke_id;
bacnet_property$pdu_service = "read-range-request";
bacnet_property$object_type = object_types[object_type];
bacnet_property$instance_number = instance_number;
bacnet_property$property = property_identifiers[property_identifier];
if( property_array_index != UINT32_MAX )
bacnet_property$array_index = property_array_index;
Log::write(LOG_BACNET_PROPERTY, bacnet_property);
}
event bacnet_read_range_ack(c: connection,
is_orig: bool,
invoke_id: count,
object_type: count,
instance_number: count,
property_identifier: count,
property_array_index: count,
result_flags: count,
item_count: count){
set_service(c);
local bacnet_property: BACnet_Property;
bacnet_property$is_orig = is_orig;
bacnet_property$ts = network_time();
bacnet_property$uid = c$uid;
bacnet_property$id = c$id;
if(is_orig)
{
bacnet_property$source_h = c$id$orig_h;
bacnet_property$source_p = c$id$orig_p;
bacnet_property$destination_h = c$id$resp_h;
bacnet_property$destination_p = c$id$resp_p;
}else
{
bacnet_property$source_h = c$id$resp_h;
bacnet_property$source_p = c$id$resp_p;
bacnet_property$destination_h = c$id$orig_h;
bacnet_property$destination_p = c$id$orig_p;
}
bacnet_property$invoke_id = invoke_id;
bacnet_property$pdu_service = "read-range-ack";
bacnet_property$object_type = object_types[object_type];
bacnet_property$instance_number = instance_number;
bacnet_property$property = property_identifiers[property_identifier];
if( property_array_index != UINT32_MAX )
bacnet_property$array_index = property_array_index;
bacnet_property$value = fmt("item_count: %d",item_count);
Log::write(LOG_BACNET_PROPERTY, bacnet_property);
}
###################################################################################################
####### Defines logging of bacnet_reinitialize_device event -> bacnet_device_control.log ########
###################################################################################################
event bacnet_reinitialize_device(c: connection,
is_orig: bool,
invoke_id: count,
reinitialized_state: count,
password: string){
set_service(c);
local bacnet_device_control: BACnet_Device_Control;
bacnet_device_control$is_orig = is_orig;
bacnet_device_control$ts = network_time();
bacnet_device_control$uid = c$uid;
bacnet_device_control$id = c$id;
if(is_orig)
{
bacnet_device_control$source_h = c$id$orig_h;
bacnet_device_control$source_p = c$id$orig_p;
bacnet_device_control$destination_h = c$id$resp_h;
bacnet_device_control$destination_p = c$id$resp_p;
}else
{
bacnet_device_control$source_h = c$id$resp_h;
bacnet_device_control$source_p = c$id$resp_p;
bacnet_device_control$destination_h = c$id$orig_h;
bacnet_device_control$destination_p = c$id$orig_p;
}
bacnet_device_control$invoke_id = invoke_id;
bacnet_device_control$pdu_service = "reinitialize_device";
bacnet_device_control$device_state = reinitialize_device_states[reinitialized_state];
bacnet_device_control$password = password;
Log::write(LOG_BACNET_DEVICE_CONTROL, bacnet_device_control);
}
###################################################################################################
######## Defines logging of bacnet_device_control_response event -> bacnet_device_control.log #####
###################################################################################################
event bacnet_device_control_response(c: connection,
is_orig: bool,
invoke_id: count,
pdu_service: count,
pdu_type: count,
result_code: count){
set_service(c);
local bacnet_device_control: BACnet_Device_Control;
bacnet_device_control$is_orig = is_orig;
bacnet_device_control$ts = network_time();
bacnet_device_control$uid = c$uid;
bacnet_device_control$id = c$id;
if(is_orig)
{
bacnet_device_control$source_h = c$id$orig_h;
bacnet_device_control$source_p = c$id$orig_p;
bacnet_device_control$destination_h = c$id$resp_h;
bacnet_device_control$destination_p = c$id$resp_p;
}else
{
bacnet_device_control$source_h = c$id$resp_h;
bacnet_device_control$source_p = c$id$resp_p;
bacnet_device_control$destination_h = c$id$orig_h;
bacnet_device_control$destination_p = c$id$orig_p;
}
bacnet_device_control$invoke_id = invoke_id;
bacnet_device_control$pdu_service = confirmed_service_choice[pdu_service];
switch(pdu_type){
case 2:
bacnet_device_control$result = "SUCCESS";
break;
case 5:
bacnet_device_control$result = "ERROR";
bacnet_device_control$result_code = error_codes[result_code];
break;
case 6:
bacnet_device_control$result = "REJECT";
bacnet_device_control$result_code = reject_reasons[result_code];
break;
case 7:
bacnet_device_control$result = "ABORT";
bacnet_device_control$result_code = abort_reasons[result_code];
break;
default:
break;
}
Log::write(LOG_BACNET_DEVICE_CONTROL, bacnet_device_control);
}
###################################################################################################
### Defines logging of bacnet_device_communication_control event -> bacnet_device_control.log ###
###################################################################################################
event bacnet_device_communication_control(c: connection,
is_orig: bool,
invoke_id: count,
time_duration: count,
enable_disable: count,
password: string){
set_service(c);
local bacnet_device_control: BACnet_Device_Control;
bacnet_device_control$is_orig = is_orig;
bacnet_device_control$ts = network_time();
bacnet_device_control$uid = c$uid;
bacnet_device_control$id = c$id;
if(is_orig)
{
bacnet_device_control$source_h = c$id$orig_h;
bacnet_device_control$source_p = c$id$orig_p;
bacnet_device_control$destination_h = c$id$resp_h;
bacnet_device_control$destination_p = c$id$resp_p;
}else
{
bacnet_device_control$source_h = c$id$resp_h;
bacnet_device_control$source_p = c$id$resp_p;
bacnet_device_control$destination_h = c$id$orig_h;
bacnet_device_control$destination_p = c$id$orig_p;
}
bacnet_device_control$invoke_id = invoke_id;
bacnet_device_control$pdu_service = "device_communication_control";
if( time_duration != UINT32_MAX )
bacnet_device_control$time_duration = time_duration;
bacnet_device_control$device_state = device_communication_control_states[enable_disable];
bacnet_device_control$password = password;
Log::write(LOG_BACNET_DEVICE_CONTROL, bacnet_device_control);
}