From 94b3809a58db6aa843d06b7b802d9bc109b1bff7 Mon Sep 17 00:00:00 2001 From: Steve Karg Date: Sun, 5 Jan 2025 10:09:39 -0600 Subject: [PATCH] Bugfix/confirmed handlers empty service request (#885) * Added reject in all confirmed service handlers, except GetEventInformation, when confirmed services with zero length occur which rejects with required parameters are missing message. * Refactored errno use in service using debug_perror. Changed debug_perror usage to debug_fprintf. * Updated file and function headers in basic/service modules. * Changed NDPU priority on confirmed messages to use requested NDPU priority. * Renamed debug_aprintf to debug_printf_stdout for clarity. * Convert most debug_fprintf usage to debug_print to reduce text bloat in AVR build --- apps/abort/main.c | 1 - apps/ack-alarm/main.c | 1 - apps/add-list-element/main.c | 1 - apps/blinkt/blinkt.c | 1 + apps/blinkt/main.c | 2 - apps/create-object/main.c | 1 - apps/dcc/main.c | 1 - apps/delete-object/main.c | 1 - apps/epics/main.c | 1 - apps/error/main.c | 1 - apps/event/main.c | 1 - apps/fuzz-afl/main.c | 2 - apps/fuzz-libfuzzer/main.c | 2 - apps/gateway/main.c | 2 - apps/getevent/main.c | 1 - apps/iam/main.c | 1 - apps/iamrouter/main.c | 1 - apps/initrouter/main.c | 1 - apps/netnumis/main.c | 1 - apps/perl/perl_bindings.c | 1 + apps/piface/main.c | 2 - apps/ptransfer/h_pt.c | 42 +++----- apps/ptransfer/h_pt_a.c | 1 - apps/ptransfer/main.c | 1 - apps/readbdt/main.c | 1 - apps/readfdt/main.c | 1 - apps/readfile/main.c | 1 - apps/readprop/main.c | 1 - apps/readpropm/main.c | 1 - apps/readrange/main.c | 1 - apps/reinit/main.c | 1 - apps/remove-list-element/main.c | 1 - apps/router/main.c | 1 - apps/router/msgqueue.c | 1 - apps/scov/main.c | 33 +++--- apps/server-client/main.c | 2 +- apps/server-discover/main.c | 6 +- apps/timesync/main.c | 1 - apps/ucov/main.c | 1 - apps/uevent/main.c | 1 - apps/uptransfer/main.c | 1 - apps/whatisnetnum/main.c | 1 - apps/whohas/main.c | 1 - apps/whois/main.c | 1 - apps/whoisrouter/main.c | 1 - apps/writebdt/main.c | 1 - apps/writefile/main.c | 1 - apps/writeprop/main.c | 1 - apps/writepropm/main.c | 1 - ports/arduino_uno/bvlc-arduino.c | 2 +- ports/bsd/bip-init.c | 20 ++-- ports/bsd/bip6.c | 19 ++-- ports/bsd/bsc-event.c | 1 - ports/bsd/dlmstp.c | 20 ++-- ports/bsd/dlmstp_port.c | 18 ++-- ports/linux/bip-init.c | 22 ++-- ports/linux/bip6.c | 19 ++-- ports/linux/bsc-event.c | 1 - ports/linux/dlmstp.c | 19 ++-- ports/linux/dlmstp_port.c | 19 ++-- ports/win32/bip-init.c | 4 +- ports/win32/bip6.c | 4 +- ports/win32/bsc-event.c | 1 - src/bacnet/basic/bbmd/h_bbmd.c | 4 +- src/bacnet/basic/bbmd6/h_bbmd6.c | 8 +- src/bacnet/basic/client/bac-discover.c | 33 +++--- src/bacnet/basic/npdu/s_router.c | 13 +-- src/bacnet/basic/object/bi.c | 18 ++-- src/bacnet/basic/object/bv.c | 34 +++--- src/bacnet/basic/object/iv.c | 7 +- src/bacnet/basic/object/nc.c | 9 +- src/bacnet/basic/service/h_alarm_ack.c | 74 ++++--------- src/bacnet/basic/service/h_arf.c | 45 ++++---- src/bacnet/basic/service/h_awf.c | 41 +++----- src/bacnet/basic/service/h_ccov.c | 85 ++++++++------- src/bacnet/basic/service/h_ccov.h | 3 + src/bacnet/basic/service/h_cov.c | 46 +++----- src/bacnet/basic/service/h_create_object.c | 31 +++--- src/bacnet/basic/service/h_dcc.c | 87 +++++---------- src/bacnet/basic/service/h_delete_object.c | 30 +++--- src/bacnet/basic/service/h_get_alarm_sum.c | 41 +++----- src/bacnet/basic/service/h_getevent.c | 71 +++++++------ src/bacnet/basic/service/h_list_element.c | 59 +++++++---- src/bacnet/basic/service/h_lso.c | 56 ++++------ src/bacnet/basic/service/h_noserv.c | 12 +-- src/bacnet/basic/service/h_rd.c | 53 ++++------ src/bacnet/basic/service/h_rp.c | 63 ++++------- src/bacnet/basic/service/h_rp_a.c | 4 +- src/bacnet/basic/service/h_rpm.c | 117 ++++++++++----------- src/bacnet/basic/service/h_rpm_a.c | 20 ++-- src/bacnet/basic/service/h_rr.c | 65 +++++------- src/bacnet/basic/service/h_ucov.c | 82 ++++++++------- src/bacnet/basic/service/h_ucov.h | 3 + src/bacnet/basic/service/h_upt.c | 1 - src/bacnet/basic/service/h_whohas.c | 1 - src/bacnet/basic/service/h_whois.c | 1 - src/bacnet/basic/service/h_wp.c | 46 ++++---- src/bacnet/basic/service/h_wpm.c | 46 ++++---- src/bacnet/basic/service/h_write_group.c | 1 - src/bacnet/basic/service/s_abort.c | 1 - src/bacnet/basic/service/s_ack_alarm.c | 26 ++--- src/bacnet/basic/service/s_arfs.c | 37 +++---- src/bacnet/basic/service/s_awfs.c | 44 +++----- src/bacnet/basic/service/s_cevent.c | 37 +++---- src/bacnet/basic/service/s_cov.c | 31 ++---- src/bacnet/basic/service/s_create_object.c | 8 +- src/bacnet/basic/service/s_dcc.c | 46 +++----- src/bacnet/basic/service/s_delete_object.c | 12 +-- src/bacnet/basic/service/s_error.c | 37 ++++--- src/bacnet/basic/service/s_get_alarm_sum.c | 41 ++------ src/bacnet/basic/service/s_get_event.c | 46 +++----- src/bacnet/basic/service/s_getevent.c | 38 +++---- src/bacnet/basic/service/s_iam.c | 33 ++---- src/bacnet/basic/service/s_ihave.c | 22 ++-- src/bacnet/basic/service/s_list_element.c | 16 +-- src/bacnet/basic/service/s_lso.c | 47 ++++----- src/bacnet/basic/service/s_rd.c | 44 +++----- src/bacnet/basic/service/s_readrange.c | 46 ++++---- src/bacnet/basic/service/s_rp.c | 43 ++++---- src/bacnet/basic/service/s_rpm.c | 43 +++----- src/bacnet/basic/service/s_ts.c | 71 +++++-------- src/bacnet/basic/service/s_uevent.c | 27 ++--- src/bacnet/basic/service/s_upt.c | 38 ++++--- src/bacnet/basic/service/s_whohas.c | 58 ++++------ src/bacnet/basic/service/s_whois.c | 59 ++++++----- src/bacnet/basic/service/s_wp.c | 48 ++++----- src/bacnet/basic/service/s_wpm.c | 37 ++----- src/bacnet/basic/service/s_write_group.c | 15 +-- src/bacnet/basic/sys/debug.c | 63 +++++++++-- src/bacnet/basic/sys/debug.h | 37 ++++++- src/bacnet/datalink/bsc/bsc-datalink.c | 2 +- src/bacnet/datalink/bsc/bsc-util.c | 4 +- test/bacnet/basic/bbmd/src/main.c | 2 +- test/bacnet/basic/bbmd6/src/main.c | 2 +- test/unit/bacnet/bacerror/src/main.c | 2 - 135 files changed, 1166 insertions(+), 1609 deletions(-) diff --git a/apps/abort/main.c b/apps/abort/main.c index a7af3ba2..be22b01d 100644 --- a/apps/abort/main.c +++ b/apps/abort/main.c @@ -11,7 +11,6 @@ #include #include #include /* for time */ -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ diff --git a/apps/ack-alarm/main.c b/apps/ack-alarm/main.c index 79f6f464..dd693fd8 100644 --- a/apps/ack-alarm/main.c +++ b/apps/ack-alarm/main.c @@ -11,7 +11,6 @@ #include #include #include /* for time */ -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ diff --git a/apps/add-list-element/main.c b/apps/add-list-element/main.c index 1c437f44..d54dd0b9 100644 --- a/apps/add-list-element/main.c +++ b/apps/add-list-element/main.c @@ -11,7 +11,6 @@ #include #include #include -#include #define PRINT_ENABLED 1 /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" diff --git a/apps/blinkt/blinkt.c b/apps/blinkt/blinkt.c index a37722d5..56189bc6 100644 --- a/apps/blinkt/blinkt.c +++ b/apps/blinkt/blinkt.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "blinkt.h" #define BLINKT_DEFAULT_BRIGHTNESS 7 diff --git a/apps/blinkt/main.c b/apps/blinkt/main.c index 3c1d3ecd..c9d5aebf 100644 --- a/apps/blinkt/main.c +++ b/apps/blinkt/main.c @@ -99,8 +99,6 @@ static void Init_Service_Handlers(void) SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, handler_timesync); apdu_set_confirmed_handler( SERVICE_CONFIRMED_SUBSCRIBE_COV, handler_cov_subscribe); - apdu_set_unconfirmed_handler( - SERVICE_UNCONFIRMED_COV_NOTIFICATION, handler_ucov_notification); apdu_set_unconfirmed_handler( SERVICE_UNCONFIRMED_WRITE_GROUP, handler_write_group); /* handle communication so we can shutup when asked */ diff --git a/apps/create-object/main.c b/apps/create-object/main.c index 3e808fef..907c3246 100644 --- a/apps/create-object/main.c +++ b/apps/create-object/main.c @@ -11,7 +11,6 @@ #include #include #include -#include #define PRINT_ENABLED 1 /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" diff --git a/apps/dcc/main.c b/apps/dcc/main.c index cd77caad..6bbbaf76 100644 --- a/apps/dcc/main.c +++ b/apps/dcc/main.c @@ -11,7 +11,6 @@ #include #include #include /* for time */ -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ diff --git a/apps/delete-object/main.c b/apps/delete-object/main.c index d9aae7b9..65c54cf3 100644 --- a/apps/delete-object/main.c +++ b/apps/delete-object/main.c @@ -11,7 +11,6 @@ #include #include #include -#include #define PRINT_ENABLED 1 /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" diff --git a/apps/epics/main.c b/apps/epics/main.c index f0a6e2ce..a9a72510 100644 --- a/apps/epics/main.c +++ b/apps/epics/main.c @@ -14,7 +14,6 @@ #if (__STDC_VERSION__ >= 199901L) && defined(__STDC_ISO_10646__) #include #endif -#include #include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" diff --git a/apps/error/main.c b/apps/error/main.c index 3c1fb56d..0997eb15 100644 --- a/apps/error/main.c +++ b/apps/error/main.c @@ -11,7 +11,6 @@ #include #include #include /* for time */ -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ diff --git a/apps/event/main.c b/apps/event/main.c index 8924245e..4e8da690 100644 --- a/apps/event/main.c +++ b/apps/event/main.c @@ -11,7 +11,6 @@ #include #include #include /* for time */ -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ diff --git a/apps/fuzz-afl/main.c b/apps/fuzz-afl/main.c index 29a1e952..1b946098 100644 --- a/apps/fuzz-afl/main.c +++ b/apps/fuzz-afl/main.c @@ -60,8 +60,6 @@ static void Init_Service_Handlers() SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, handler_timesync); apdu_set_confirmed_handler( SERVICE_CONFIRMED_SUBSCRIBE_COV, handler_cov_subscribe); - apdu_set_unconfirmed_handler( - SERVICE_UNCONFIRMED_COV_NOTIFICATION, handler_ucov_notification); apdu_set_confirmed_handler( SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, handler_device_communication_control); diff --git a/apps/fuzz-libfuzzer/main.c b/apps/fuzz-libfuzzer/main.c index cdd4e5f3..14f4bda0 100644 --- a/apps/fuzz-libfuzzer/main.c +++ b/apps/fuzz-libfuzzer/main.c @@ -61,8 +61,6 @@ static void Init_Service_Handlers(void) SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, handler_timesync); apdu_set_confirmed_handler( SERVICE_CONFIRMED_SUBSCRIBE_COV, handler_cov_subscribe); - apdu_set_unconfirmed_handler( - SERVICE_UNCONFIRMED_COV_NOTIFICATION, handler_ucov_notification); apdu_set_confirmed_handler( SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, handler_device_communication_control); diff --git a/apps/gateway/main.c b/apps/gateway/main.c index 27d435b8..5fc4eb34 100644 --- a/apps/gateway/main.c +++ b/apps/gateway/main.c @@ -185,8 +185,6 @@ static void Init_Service_Handlers(uint32_t first_object_instance) SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, handler_timesync); apdu_set_confirmed_handler( SERVICE_CONFIRMED_SUBSCRIBE_COV, handler_cov_subscribe); - apdu_set_unconfirmed_handler( - SERVICE_UNCONFIRMED_COV_NOTIFICATION, handler_ucov_notification); /* handle communication so we can shutup when asked */ apdu_set_confirmed_handler( SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, diff --git a/apps/getevent/main.c b/apps/getevent/main.c index 0aaf1111..94071dd4 100644 --- a/apps/getevent/main.c +++ b/apps/getevent/main.c @@ -11,7 +11,6 @@ #include #include #include -#include #include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" diff --git a/apps/iam/main.c b/apps/iam/main.c index 69a5946b..c7354902 100644 --- a/apps/iam/main.c +++ b/apps/iam/main.c @@ -11,7 +11,6 @@ #include #include #include /* for time */ -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ diff --git a/apps/iamrouter/main.c b/apps/iamrouter/main.c index b0942773..cded5dd6 100644 --- a/apps/iamrouter/main.c +++ b/apps/iamrouter/main.c @@ -11,7 +11,6 @@ #include #include #include /* for time */ -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ diff --git a/apps/initrouter/main.c b/apps/initrouter/main.c index e21cd1b5..e9a4f0ef 100644 --- a/apps/initrouter/main.c +++ b/apps/initrouter/main.c @@ -12,7 +12,6 @@ #include #include #include /* for time */ -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ diff --git a/apps/netnumis/main.c b/apps/netnumis/main.c index 0ce3b179..14c9143f 100644 --- a/apps/netnumis/main.c +++ b/apps/netnumis/main.c @@ -11,7 +11,6 @@ #include #include #include /* for time */ -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ diff --git a/apps/perl/perl_bindings.c b/apps/perl/perl_bindings.c index a0e2a3cc..88d90e2b 100644 --- a/apps/perl/perl_bindings.c +++ b/apps/perl/perl_bindings.c @@ -1,3 +1,4 @@ +#include #include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" diff --git a/apps/piface/main.c b/apps/piface/main.c index ea2f40ac..15cc1d05 100644 --- a/apps/piface/main.c +++ b/apps/piface/main.c @@ -170,8 +170,6 @@ static void Init_Service_Handlers(void) SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, handler_timesync); apdu_set_confirmed_handler( SERVICE_CONFIRMED_SUBSCRIBE_COV, handler_cov_subscribe); - apdu_set_unconfirmed_handler( - SERVICE_UNCONFIRMED_COV_NOTIFICATION, handler_ucov_notification); /* handle communication so we can shutup when asked */ apdu_set_confirmed_handler( SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, diff --git a/apps/ptransfer/h_pt.c b/apps/ptransfer/h_pt.c index c23aedeb..4ed61a23 100644 --- a/apps/ptransfer/h_pt.c +++ b/apps/ptransfer/h_pt.c @@ -9,7 +9,6 @@ #include #include #include -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ @@ -17,8 +16,10 @@ #include "bacnet/apdu.h" #include "bacnet/npdu.h" #include "bacnet/abort.h" +#include "bacnet/reject.h" #include "bacnet/ptransfer.h" #include "bacnet/basic/services.h" +#include "bacnet/basic/sys/debug.h" #include "bacnet/basic/tsm/tsm.h" #define MYMAXSTR 32 @@ -185,24 +186,24 @@ void handler_conf_private_trans( error_class = ERROR_CLASS_OBJECT; error_code = ERROR_CODE_UNKNOWN_OBJECT; -#if PRINT_ENABLED - fprintf(stderr, "Received Confirmed Private Transfer Request!\n"); -#endif + debug_print("Received Confirmed Private Transfer Request!\n"); /* encode the NPDU portion of the response packet as it will be needed */ /* no matter what the outcome. */ - datalink_get_my_address(&my_address); - npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); + npdu_encode_npdu_data(&npdu_data, false, service_data->priority); pdu_len = npdu_encode_pdu( &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); - - if (service_data->segmented_message) { + if (service_len == 0) { + len = reject_encode_apdu( + &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, + REJECT_REASON_MISSING_REQUIRED_PARAMETER); + debug_print("CPT: Missing Required Parameter. Sending Reject!\n"); + goto CPT_ABORT; + } else if (service_data->segmented_message) { len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); -#if PRINT_ENABLED - fprintf(stderr, "CPT: Segmented Message. Sending Abort!\n"); -#endif + debug_print("CPT: Segmented Message. Sending Abort!\n"); goto CPT_ABORT; } @@ -212,9 +213,7 @@ void handler_conf_private_trans( len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_OTHER, true); -#if PRINT_ENABLED - fprintf(stderr, "CPT: Bad Encoding. Sending Abort!\n"); -#endif + debug_print("CPT: Bad Encoding. Sending Abort!\n"); goto CPT_ABORT; } @@ -234,9 +233,7 @@ void handler_conf_private_trans( error = true; error_class = ERROR_CLASS_SERVICES; error_code = ERROR_CODE_OTHER; -#if PRINT_ENABLED - fprintf(stderr, "CPT: Error servicing request!\n"); -#endif + debug_print("CPT: Error servicing request!\n"); } len = ptransfer_ack_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &data); @@ -245,9 +242,7 @@ void handler_conf_private_trans( error = true; error_class = ERROR_CLASS_SERVICES; error_code = ERROR_CODE_OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED; -#if PRINT_ENABLED - fprintf(stderr, "CPT: Not our Vendor ID or invalid service code!\n"); -#endif + debug_print("CPT: Not our Vendor ID or invalid service code!\n"); } if (error) { @@ -259,12 +254,7 @@ CPT_ABORT: pdu_len += len; bytes_sent = datalink_send_pdu( src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); - -#if PRINT_ENABLED - if (bytes_sent <= 0) { - fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); - } -#endif + debug_perror("CPT: Failed to send PDU"); return; } diff --git a/apps/ptransfer/h_pt_a.c b/apps/ptransfer/h_pt_a.c index f36bb440..ed58ec03 100644 --- a/apps/ptransfer/h_pt_a.c +++ b/apps/ptransfer/h_pt_a.c @@ -9,7 +9,6 @@ #include #include #include -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ diff --git a/apps/ptransfer/main.c b/apps/ptransfer/main.c index f79a9240..6f15111c 100644 --- a/apps/ptransfer/main.c +++ b/apps/ptransfer/main.c @@ -10,7 +10,6 @@ #include #include #include -#include #include /* for time */ #include /* for tupper */ #if defined(WIN32) || defined(__BORLANDC__) diff --git a/apps/readbdt/main.c b/apps/readbdt/main.c index 2c92f5d2..6ec62bee 100644 --- a/apps/readbdt/main.c +++ b/apps/readbdt/main.c @@ -11,7 +11,6 @@ #include #include #include /* for time */ -#include #include /* for toupper */ /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" diff --git a/apps/readfdt/main.c b/apps/readfdt/main.c index 4e6dbe5c..e267f994 100644 --- a/apps/readfdt/main.c +++ b/apps/readfdt/main.c @@ -11,7 +11,6 @@ #include #include #include /* for time */ -#include #include /* for toupper */ /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" diff --git a/apps/readfile/main.c b/apps/readfile/main.c index e4894da1..4213e800 100644 --- a/apps/readfile/main.c +++ b/apps/readfile/main.c @@ -11,7 +11,6 @@ #include #include #include /* for time */ -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ diff --git a/apps/readprop/main.c b/apps/readprop/main.c index e722cbe5..9e5685a2 100644 --- a/apps/readprop/main.c +++ b/apps/readprop/main.c @@ -11,7 +11,6 @@ #include #include #include -#include #include /* for time */ #if (__STDC_VERSION__ >= 199901L) && defined(__STDC_ISO_10646__) #include diff --git a/apps/readpropm/main.c b/apps/readpropm/main.c index 5b7bf244..ddac918b 100644 --- a/apps/readpropm/main.c +++ b/apps/readpropm/main.c @@ -11,7 +11,6 @@ #include #include #include -#include #include /* for time */ #if (__STDC_VERSION__ >= 199901L) && defined(__STDC_ISO_10646__) #include diff --git a/apps/readrange/main.c b/apps/readrange/main.c index 30a99fec..d1f224e0 100644 --- a/apps/readrange/main.c +++ b/apps/readrange/main.c @@ -12,7 +12,6 @@ #include #include #include -#include #include /* for time */ #if (__STDC_VERSION__ >= 199901L) && defined(__STDC_ISO_10646__) #include diff --git a/apps/reinit/main.c b/apps/reinit/main.c index 470f63d4..178fb4e2 100644 --- a/apps/reinit/main.c +++ b/apps/reinit/main.c @@ -12,7 +12,6 @@ #include #include #include /* for time */ -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ diff --git a/apps/remove-list-element/main.c b/apps/remove-list-element/main.c index 3d19ff4b..23a94754 100644 --- a/apps/remove-list-element/main.c +++ b/apps/remove-list-element/main.c @@ -11,7 +11,6 @@ #include #include #include -#include #define PRINT_ENABLED 1 /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" diff --git a/apps/router/main.c b/apps/router/main.c index 80268d62..98670e18 100644 --- a/apps/router/main.c +++ b/apps/router/main.c @@ -18,7 +18,6 @@ #include #include #include /* for time */ -#include #include #include #include /* read config files */ diff --git a/apps/router/msgqueue.c b/apps/router/msgqueue.c index 6e5e4f18..c4f92906 100644 --- a/apps/router/msgqueue.c +++ b/apps/router/msgqueue.c @@ -9,7 +9,6 @@ * SPDX-License-Identifier: MIT */ #include -#include #include #include #include diff --git a/apps/scov/main.c b/apps/scov/main.c index 6b1b9a68..326ba9a4 100644 --- a/apps/scov/main.c +++ b/apps/scov/main.c @@ -12,7 +12,6 @@ #include #include #include -#include #include /* for time */ #include /* for toupper */ #define PRINT_ENABLED 1 @@ -58,6 +57,9 @@ BACNET_SUBSCRIBE_COV_DATA *COV_Subscribe_Data = NULL; /* flags to signal early termination */ static bool Simple_Ack_Detected = false; static bool Cancel_Requested = false; +/* callback for printing the notifications */ +static BACNET_COV_NOTIFICATION Confirmed_COV_Notification_Callback; +static BACNET_COV_NOTIFICATION Unconfirmed_COV_Notification_Callback; static void MyErrorHandler( BACNET_ADDRESS *src, @@ -99,21 +101,6 @@ MyRejectHandler(BACNET_ADDRESS *src, uint8_t invoke_id, uint8_t reject_reason) } } -static void My_Unconfirmed_COV_Notification_Handler( - uint8_t *service_request, uint16_t service_len, BACNET_ADDRESS *src) -{ - handler_ucov_notification(service_request, service_len, src); -} - -static void My_Confirmed_COV_Notification_Handler( - uint8_t *service_request, - uint16_t service_len, - BACNET_ADDRESS *src, - BACNET_CONFIRMED_SERVICE_DATA *service_data) -{ - handler_ccov_notification(service_request, service_len, src, service_data); -} - static void MyWritePropertySimpleAckHandler(BACNET_ADDRESS *src, uint8_t invoke_id) { @@ -138,13 +125,17 @@ static void Init_Service_Handlers(void) /* we must implement read property - it's required! */ apdu_set_confirmed_handler( SERVICE_CONFIRMED_READ_PROPERTY, handler_read_property); - /* handle the data coming back from COV subscriptions */ + /* handle the data coming back from confirmed COV subscriptions */ apdu_set_confirmed_handler( - SERVICE_CONFIRMED_COV_NOTIFICATION, - My_Confirmed_COV_Notification_Handler); + SERVICE_CONFIRMED_COV_NOTIFICATION, handler_ccov_notification); + /* add a callback for printing the data */ + Confirmed_COV_Notification_Callback.callback = handler_ccov_data_print; + handler_ccov_notification_add(&Confirmed_COV_Notification_Callback); + Unconfirmed_COV_Notification_Callback.callback = handler_ucov_data_print; + handler_ucov_notification_add(&Unconfirmed_COV_Notification_Callback); + /* handle the data coming back from unconfirmed COV subscriptions */ apdu_set_unconfirmed_handler( - SERVICE_UNCONFIRMED_COV_NOTIFICATION, - My_Unconfirmed_COV_Notification_Handler); + SERVICE_UNCONFIRMED_COV_NOTIFICATION, handler_ucov_notification); /* handle the Simple ack coming back from SubscribeCOV */ apdu_set_confirmed_simple_ack_handler( SERVICE_CONFIRMED_SUBSCRIBE_COV, MyWritePropertySimpleAckHandler); diff --git a/apps/server-client/main.c b/apps/server-client/main.c index cd0c4d35..8b634149 100644 --- a/apps/server-client/main.c +++ b/apps/server-client/main.c @@ -32,7 +32,7 @@ #endif /* print with flush by default */ -#define PRINTF debug_aprintf +#define PRINTF debug_printf_stdout /* current version of the BACnet stack */ static const char *BACnet_Version = BACNET_VERSION_TEXT; diff --git a/apps/server-discover/main.c b/apps/server-discover/main.c index c6b797df..0314a2be 100644 --- a/apps/server-discover/main.c +++ b/apps/server-discover/main.c @@ -257,13 +257,13 @@ int main(int argc, char *argv[]) } } if (device_id > BACNET_MAX_INSTANCE) { - debug_perror( - "device-instance=%u - not greater than %u\n", device_id, + debug_fprintf( + stderr, "device-instance=%u - not greater than %u\n", device_id, BACNET_MAX_INSTANCE); return 1; } Device_Set_Object_Instance_Number(device_id); - debug_aprintf( + debug_printf_stdout( "BACnet Server-Discovery Demo\n" "BACnet Stack Version %s\n" "BACnet Device ID: %u\n" diff --git a/apps/timesync/main.c b/apps/timesync/main.c index 26cfa6d2..42e7e43e 100644 --- a/apps/timesync/main.c +++ b/apps/timesync/main.c @@ -12,7 +12,6 @@ #include #include #include -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ diff --git a/apps/ucov/main.c b/apps/ucov/main.c index 2036d005..224c5b46 100644 --- a/apps/ucov/main.c +++ b/apps/ucov/main.c @@ -11,7 +11,6 @@ #include #include #include /* for time */ -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ diff --git a/apps/uevent/main.c b/apps/uevent/main.c index 5c8eac8c..c72aabd7 100644 --- a/apps/uevent/main.c +++ b/apps/uevent/main.c @@ -11,7 +11,6 @@ #include #include #include /* for time */ -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ diff --git a/apps/uptransfer/main.c b/apps/uptransfer/main.c index 82668dc9..3283bd78 100644 --- a/apps/uptransfer/main.c +++ b/apps/uptransfer/main.c @@ -10,7 +10,6 @@ #include #include #include -#include #include /* for time */ #include /* for toupper */ #define PRINT_ENABLED 1 diff --git a/apps/whatisnetnum/main.c b/apps/whatisnetnum/main.c index 5a4a3aa1..53f855b4 100644 --- a/apps/whatisnetnum/main.c +++ b/apps/whatisnetnum/main.c @@ -11,7 +11,6 @@ #include #include #include /* for time */ -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ diff --git a/apps/whohas/main.c b/apps/whohas/main.c index 73237a88..0b704c11 100644 --- a/apps/whohas/main.c +++ b/apps/whohas/main.c @@ -13,7 +13,6 @@ #include #include #include /* for time */ -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ diff --git a/apps/whois/main.c b/apps/whois/main.c index fd6b7811..d19ba2ca 100644 --- a/apps/whois/main.c +++ b/apps/whois/main.c @@ -13,7 +13,6 @@ #include #include #include -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ diff --git a/apps/whoisrouter/main.c b/apps/whoisrouter/main.c index 8e0845e6..f6a5964a 100644 --- a/apps/whoisrouter/main.c +++ b/apps/whoisrouter/main.c @@ -12,7 +12,6 @@ #include #include #include /* for time */ -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ diff --git a/apps/writebdt/main.c b/apps/writebdt/main.c index 212dc024..e7c6d2da 100644 --- a/apps/writebdt/main.c +++ b/apps/writebdt/main.c @@ -13,7 +13,6 @@ #include #include #include /* for time */ -#include #include /* for toupper */ /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" diff --git a/apps/writefile/main.c b/apps/writefile/main.c index 93c48628..585cd506 100644 --- a/apps/writefile/main.c +++ b/apps/writefile/main.c @@ -12,7 +12,6 @@ #include #include #include /* for time */ -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ diff --git a/apps/writeprop/main.c b/apps/writeprop/main.c index df9a8741..16544ff3 100644 --- a/apps/writeprop/main.c +++ b/apps/writeprop/main.c @@ -15,7 +15,6 @@ #include #include /* for time */ #include -#include #include /* toupper */ /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" diff --git a/apps/writepropm/main.c b/apps/writepropm/main.c index d250e7c9..03438afa 100644 --- a/apps/writepropm/main.c +++ b/apps/writepropm/main.c @@ -14,7 +14,6 @@ #include #include #include -#include #include /* for time */ #define PRINT_ENABLED 1 /* BACnet Stack defines - first */ diff --git a/ports/arduino_uno/bvlc-arduino.c b/ports/arduino_uno/bvlc-arduino.c index f93ce92a..c8f417db 100644 --- a/ports/arduino_uno/bvlc-arduino.c +++ b/ports/arduino_uno/bvlc-arduino.c @@ -52,7 +52,7 @@ static int bvlc_encode_bvlc_result(uint8_t *pdu, BACNET_BVLC_RESULT result_code) * @param mtu - the bytes of data to send * @param mtu_len - the number of bytes of data to send * @return Upon successful completion, returns the number of bytes sent. - * Otherwise, -1 shall be returned and errno set to indicate the error. + * Otherwise, -1 shall be returned to indicate the error. */ static int bvlc_send_mpdu( const uint8_t *dest_addr, /* the destination address */ diff --git a/ports/bsd/bip-init.c b/ports/bsd/bip-init.c index dd38682d..b7b44904 100644 --- a/ports/bsd/bip-init.c +++ b/ports/bsd/bip-init.c @@ -1,10 +1,10 @@ -/************************************************************************** - * - * Copyright (C) 2005 Steve Karg - * - * SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0 - * - *********************************************************************/ +/** + * @file + * @brief Initializes BACnet/IP interface (BSD/MAC OS X) + * @author Steve Karg + * @date 2005 + * @copyright SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0 + */ #include /* for standard integer types uint8_t etc. */ #include /* for the standard bool type. */ #include @@ -15,8 +15,6 @@ #include "bacnet/basic/bbmd/h_bbmd.h" #include "bacport.h" -/** @file bsd/bip-init.c @brief Initializes BACnet/IP interface (BSD/MAC OS X). */ - /* unix sockets */ static int BIP_Socket = -1; static int BIP_Broadcast_Socket = -1; @@ -257,7 +255,7 @@ uint8_t bip_get_subnet_prefix(void) * @param mtu_len - the number of bytes of data to send * * @return Upon successful completion, returns the number of bytes sent. - * Otherwise, -1 shall be returned and errno set to indicate the error. + * Otherwise, -1 shall be returned to indicate the error. */ int bip_send_mpdu( const BACNET_IP_ADDRESS *dest, const uint8_t *mtu, uint16_t mtu_len) @@ -409,7 +407,7 @@ uint16_t bip_receive( * @param mtu - the bytes of data to send * @param mtu_len - the number of bytes of data to send * @return Upon successful completion, returns the number of bytes sent. - * Otherwise, -1 shall be returned and errno set to indicate the error. + * Otherwise, -1 shall be returned to indicate the error. */ int bip_send_pdu( BACNET_ADDRESS *dest, diff --git a/ports/bsd/bip6.c b/ports/bsd/bip6.c index 043ec4dc..bc232339 100644 --- a/ports/bsd/bip6.c +++ b/ports/bsd/bip6.c @@ -1,15 +1,16 @@ -/************************************************************************** - * - * Copyright (C) 2016 Steve Karg - * - * SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0 - * - *********************************************************************/ +/** + * @file + * @brief Initializes BACnet/IPv6 interface (BSD/MAC OS X) + * @author Steve Karg + * @date 2016 + * @copyright SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0 + */ #include #include #include #include /* for standard integer types uint8_t etc. */ #include /* for the standard bool type. */ +#include #include "bacnet/bacdcode.h" #include "bacnet/config.h" #include "bacnet/datalink/bip6.h" @@ -244,7 +245,7 @@ bool bip6_get_broadcast_addr(BACNET_IP6_ADDRESS *addr) * @param mtu_len - the number of bytes of data to send * * @return Upon successful completion, returns the number of bytes sent. - * Otherwise, -1 shall be returned and errno set to indicate the error. + * Otherwise, -1 shall be returned to indicate the error. */ int bip6_send_mpdu( const BACNET_IP6_ADDRESS *dest, const uint8_t *mtu, uint16_t mtu_len) @@ -286,7 +287,7 @@ int bip6_send_mpdu( * @param pdu - the bytes of data to send * @param pdu_len - the number of bytes of data to send * @return Upon successful completion, returns the number of bytes sent. - * Otherwise, -1 shall be returned and errno set to indicate the error. + * Otherwise, -1 shall be returned to indicate the error. */ int bip6_send_pdu(BACNET_ADDRESS *dest, BACNET_NPDU_DATA *npdu_data, diff --git a/ports/bsd/bsc-event.c b/ports/bsd/bsc-event.c index df5bea19..255d2706 100644 --- a/ports/bsd/bsc-event.c +++ b/ports/bsd/bsc-event.c @@ -11,7 +11,6 @@ #include #include #include -#include #include "bacnet/basic/sys/debug.h" #include "bacnet/datalink/bsc/bsc-event.h" diff --git a/ports/bsd/dlmstp.c b/ports/bsd/dlmstp.c index 5c2c2d51..36bfafa5 100644 --- a/ports/bsd/dlmstp.c +++ b/ports/bsd/dlmstp.c @@ -1,11 +1,11 @@ -/************************************************************************** - * - * Copyright (C) 2008 Steve Karg - * Updated by Nikola Jelic 2011 - * - * SPDX-License-Identifier: MIT - * - *********************************************************************/ +/** + * @file + * @brief Provides BSD-specific DataLink functions for MS/TP. + * @author Steve Karg + * @author Nikola Jelic 2011 + * @date 2008 + * @copyright SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0 + */ #include #include #include @@ -27,12 +27,8 @@ /* port specific */ #include "rs485.h" -/** @file bsd/dlmstp.c Provides BSD-specific DataLink functions for MS/TP. - */ - /* Number of MS/TP Packets Rx/Tx */ uint16_t MSTP_Packets = 0; - /* packet queues */ static DLMSTP_PACKET Receive_Packet; /* mechanism to wait for a packet */ diff --git a/ports/bsd/dlmstp_port.c b/ports/bsd/dlmstp_port.c index 026d2c0c..6697169a 100644 --- a/ports/bsd/dlmstp_port.c +++ b/ports/bsd/dlmstp_port.c @@ -1,10 +1,10 @@ -/************************************************************************** - * - * Copyright (C) 2008 Steve Karg - * - * SPDX-License-Identifier: MIT - * - *********************************************************************/ +/** + * @file + * @brief Provides BSD-specific DataLink functions for MS/TP. + * @author Steve Karg + * @date 2008 + * @copyright SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0 + */ #include #include #include @@ -12,6 +12,7 @@ #include #include #include +#include /* BSD includes */ #include /* BACnet Stack defines - first */ @@ -29,9 +30,6 @@ /* OS Specific include */ #include "bacport.h" -/** @file bsd/dlmstp_port.c Provides BSD-specific DataLink functions for MS/TP. - */ - #define BACNET_PDU_CONTROL_BYTE_OFFSET 1 #define BACNET_DATA_EXPECTING_REPLY_BIT 2 #define BACNET_DATA_EXPECTING_REPLY(control) \ diff --git a/ports/linux/bip-init.c b/ports/linux/bip-init.c index 6208bf31..cb6ea620 100644 --- a/ports/linux/bip-init.c +++ b/ports/linux/bip-init.c @@ -1,11 +1,10 @@ -/************************************************************************** - * - * Copyright (C) 2005 Steve Karg - * - * SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0 - * - *********************************************************************/ -/* linux Ethernet/IP specific */ +/** + * @file + * @brief Initializes BACnet/IP interface (Linux). + * @author Steve Karg + * @date 2005 + * @copyright SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0 + */ #include #include #include @@ -23,6 +22,7 @@ #include #include #include +#include /* BACnet specific */ #include "bacnet/bacdcode.h" #include "bacnet/bacint.h" @@ -31,8 +31,6 @@ #include "bacnet/basic/bbmd/h_bbmd.h" #include "bacport.h" -/** @file linux/bip-init.c Initializes BACnet/IP interface (Linux). */ - /* unix sockets */ static int BIP_Socket = -1; static int BIP_Broadcast_Socket = -1; @@ -273,7 +271,7 @@ uint8_t bip_get_subnet_prefix(void) * @param mtu_len - the number of bytes of data to send * * @return Upon successful completion, returns the number of bytes sent. - * Otherwise, -1 shall be returned and errno set to indicate the error. + * Otherwise, -1 shall be returned to indicate the error. */ int bip_send_mpdu( const BACNET_IP_ADDRESS *dest, const uint8_t *mtu, uint16_t mtu_len) @@ -425,7 +423,7 @@ uint16_t bip_receive( * @param mtu - the bytes of data to send * @param mtu_len - the number of bytes of data to send * @return Upon successful completion, returns the number of bytes sent. - * Otherwise, -1 shall be returned and errno set to indicate the error. + * Otherwise, -1 shall be returned to indicate the error. */ int bip_send_pdu( BACNET_ADDRESS *dest, diff --git a/ports/linux/bip6.c b/ports/linux/bip6.c index 71f2cbf1..37e16000 100644 --- a/ports/linux/bip6.c +++ b/ports/linux/bip6.c @@ -1,15 +1,16 @@ -/************************************************************************** - * - * Copyright (C) 2016 Steve Karg - * - * SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0 - * - *********************************************************************/ +/** + * @file + * @brief Initializes BACnet/IP interface (Linux). + * @author Steve Karg + * @date 2016 + * @copyright SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0 + */ #include #include #include #include /* for standard integer types uint8_t etc. */ #include /* for the standard bool type. */ +#include #include "bacnet/bacdcode.h" #include "bacnet/config.h" #include "bacnet/datalink/bip6.h" @@ -234,7 +235,7 @@ bool bip6_get_broadcast_addr(BACNET_IP6_ADDRESS *addr) * @param mtu_len - the number of bytes of data to send * * @return Upon successful completion, returns the number of bytes sent. - * Otherwise, -1 shall be returned and errno set to indicate the error. + * Otherwise, -1 shall be returned to indicate the error. */ int bip6_send_mpdu( const BACNET_IP6_ADDRESS *dest, const uint8_t *mtu, uint16_t mtu_len) @@ -278,7 +279,7 @@ int bip6_send_mpdu( * @param pdu - the bytes of data to send * @param pdu_len - the number of bytes of data to send * @return Upon successful completion, returns the number of bytes sent. - * Otherwise, -1 shall be returned and errno set to indicate the error. + * Otherwise, -1 shall be returned to indicate the error. */ int bip6_send_pdu( BACNET_ADDRESS *dest, diff --git a/ports/linux/bsc-event.c b/ports/linux/bsc-event.c index ddcc3547..71bb78f6 100644 --- a/ports/linux/bsc-event.c +++ b/ports/linux/bsc-event.c @@ -11,7 +11,6 @@ #include #include #include -#include #include "bacnet/basic/sys/debug.h" #include "bacnet/datalink/bsc/bsc-event.h" diff --git a/ports/linux/dlmstp.c b/ports/linux/dlmstp.c index ecb2c84d..a1783a17 100644 --- a/ports/linux/dlmstp.c +++ b/ports/linux/dlmstp.c @@ -1,11 +1,11 @@ -/************************************************************************** - * - * Copyright (C) 2008 Steve Karg - * Updated by Nikola Jelic 2011 - * - * SPDX-License-Identifier: MIT - * - *********************************************************************/ +/** + * @file + * @brief Provides Linux-specific DataLink functions for MS/TP. + * @author Steve Karg + * @author Nikola Jelic 2011 + * @date 2008 + * @copyright SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0 + */ #include #include #include @@ -27,9 +27,6 @@ /* port specific */ #include "rs485.h" -/** @file linux/dlmstp.c Provides Linux-specific DataLink functions for MS/TP. - */ - /* Number of MS/TP Packets Rx/Tx */ uint16_t MSTP_Packets = 0; diff --git a/ports/linux/dlmstp_port.c b/ports/linux/dlmstp_port.c index 0693895b..f1019988 100644 --- a/ports/linux/dlmstp_port.c +++ b/ports/linux/dlmstp_port.c @@ -1,10 +1,10 @@ -/************************************************************************** - * - * Copyright (C) 2008 Steve Karg - * - * SPDX-License-Identifier: MIT - * - *********************************************************************/ +/** + * @file + * @brief Provides Linux-specific DataLink functions for MS/TP. + * @author Steve Karg + * @date 2008 + * @copyright SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0 + */ #include #include #include @@ -12,6 +12,7 @@ #include #include #include +#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ @@ -27,10 +28,6 @@ /* OS Specific include */ #include "bacport.h" -/** @file linux/dlmstp_port.c Provides Linux-specific DataLink functions for - * MS/TP. - */ - #define BACNET_PDU_CONTROL_BYTE_OFFSET 1 #define BACNET_DATA_EXPECTING_REPLY_BIT 2 #define BACNET_DATA_EXPECTING_REPLY(control) \ diff --git a/ports/win32/bip-init.c b/ports/win32/bip-init.c index ed841868..8c7b5c22 100644 --- a/ports/win32/bip-init.c +++ b/ports/win32/bip-init.c @@ -413,7 +413,7 @@ uint8_t bip_get_subnet_prefix(void) * @param mtu_len - the number of bytes of data to send * * @return Upon successful completion, returns the number of bytes sent. - * Otherwise, -1 shall be returned and errno set to indicate the error. + * Otherwise, -1 shall be returned to indicate the error. */ int bip_send_mpdu( const BACNET_IP_ADDRESS *dest, const uint8_t *mtu, uint16_t mtu_len) @@ -563,7 +563,7 @@ uint16_t bip_receive( * @param mtu - the bytes of data to send * @param mtu_len - the number of bytes of data to send * @return Upon successful completion, returns the number of bytes sent. - * Otherwise, -1 shall be returned and errno set to indicate the error. + * Otherwise, -1 shall be returned to indicate the error. */ int bip_send_pdu( BACNET_ADDRESS *dest, diff --git a/ports/win32/bip6.c b/ports/win32/bip6.c index 75e20bbb..e2c2ffb0 100644 --- a/ports/win32/bip6.c +++ b/ports/win32/bip6.c @@ -346,7 +346,7 @@ bool bip6_get_broadcast_addr(BACNET_IP6_ADDRESS *addr) * @param mtu_len - the number of bytes of data to send * * @return Upon successful completion, returns the number of bytes sent. - * Otherwise, -1 shall be returned and errno set to indicate the error. + * Otherwise, -1 shall be returned to indicate the error. */ int bip6_send_mpdu( const BACNET_IP6_ADDRESS *dest, const uint8_t *mtu, uint16_t mtu_len) @@ -390,7 +390,7 @@ int bip6_send_mpdu( * @param pdu - the bytes of data to send * @param pdu_len - the number of bytes of data to send * @return Upon successful completion, returns the number of bytes sent. - * Otherwise, -1 shall be returned and errno set to indicate the error. + * Otherwise, -1 shall be returned to indicate the error. */ int bip6_send_pdu( BACNET_ADDRESS *dest, diff --git a/ports/win32/bsc-event.c b/ports/win32/bsc-event.c index 6e6891c8..f4ba2529 100644 --- a/ports/win32/bsc-event.c +++ b/ports/win32/bsc-event.c @@ -10,7 +10,6 @@ #include #include #include -#include #include "bacnet/datalink/bsc/bsc-event.h" #define DEBUG_BSC_EVENT 0 diff --git a/src/bacnet/basic/bbmd/h_bbmd.c b/src/bacnet/basic/bbmd/h_bbmd.c index fae36028..a725bc2b 100644 --- a/src/bacnet/basic/bbmd/h_bbmd.c +++ b/src/bacnet/basic/bbmd/h_bbmd.c @@ -576,7 +576,7 @@ static void bbmd_read_fdt_ack_handler( * @param mtu - the bytes of data to send * @param mtu_len - the number of bytes of data to send * @return Upon successful completion, returns the number of bytes sent. - * Otherwise, -1 shall be returned and errno set to indicate the error. + * Otherwise, -1 shall be returned to indicate the error. */ int bvlc_send_pdu( const BACNET_ADDRESS *dest, @@ -648,7 +648,7 @@ int bvlc_send_pdu( * @param result_code - BVLC result code * * @return Upon successful completion, returns the number of bytes sent. - * Otherwise, -1 shall be returned and errno set to indicate the error. + * Otherwise, -1 shall be returned to indicate the error. */ static int bvlc_send_result(const BACNET_IP_ADDRESS *dest_addr, uint16_t result_code) diff --git a/src/bacnet/basic/bbmd6/h_bbmd6.c b/src/bacnet/basic/bbmd6/h_bbmd6.c index c1a9d696..cfa5fd40 100644 --- a/src/bacnet/basic/bbmd6/h_bbmd6.c +++ b/src/bacnet/basic/bbmd6/h_bbmd6.c @@ -285,7 +285,7 @@ static bool bbmd6_address_from_bacnet_address( * @param pdu - the bytes of data to send * @param pdu_len - the number of bytes of data to send * @return Upon successful completion, returns the number of bytes sent. - * Otherwise, -1 shall be returned and errno set to indicate the error. + * Otherwise, -1 shall be returned to indicate the error. */ int bvlc6_send_pdu( const BACNET_ADDRESS *dest, @@ -452,7 +452,7 @@ static void bbmd6_send_forward_npdu( * @param result_code - BVLC result code * * @return Upon successful completion, returns the number of bytes sent. - * Otherwise, -1 shall be returned and errno set to indicate the error. + * Otherwise, -1 shall be returned to indicate the error. */ static int bvlc6_send_result( const BACNET_IP6_ADDRESS *dest_addr, @@ -476,7 +476,7 @@ static int bvlc6_send_result( * @param vmac_dst - Destination-Virtual-Address * * @return Upon successful completion, returns the number of bytes sent. - * Otherwise, -1 shall be returned and errno set to indicate the error. + * Otherwise, -1 shall be returned to indicate the error. */ static int bvlc6_send_address_resolution_ack( const BACNET_IP6_ADDRESS *dest_addr, uint32_t vmac_src, uint32_t vmac_dst) @@ -500,7 +500,7 @@ static int bvlc6_send_address_resolution_ack( * @param vmac_dst - Destination-Virtual-Address * * @return Upon successful completion, returns the number of bytes sent. - * Otherwise, -1 shall be returned and errno set to indicate the error. + * Otherwise, -1 shall be returned to indicate the error. */ static int bvlc6_send_virtual_address_resolution_ack( const BACNET_IP6_ADDRESS *dest_addr, uint32_t vmac_src, uint32_t vmac_dst) diff --git a/src/bacnet/basic/client/bac-discover.c b/src/bacnet/basic/client/bac-discover.c index d611777f..7f770c49 100644 --- a/src/bacnet/basic/client/bac-discover.c +++ b/src/bacnet/basic/client/bac-discover.c @@ -610,8 +610,8 @@ static void bacnet_device_object_property_add( device_data->Object_List, rp_data->object_type, rp_data->object_instance); if (!object_data) { - debug_perror( - "%s-%u object fail to add!\n", + debug_fprintf( + stderr, "%s-%u object fail to add!\n", bactext_object_type_name(rp_data->object_type), rp_data->object_instance); return; @@ -619,8 +619,8 @@ static void bacnet_device_object_property_add( property_data = bacnet_property_data_add( object_data->Property_List, rp_data->object_property); if (!property_data) { - debug_perror( - "%s-%u %s property fail to add!\n", + debug_fprintf( + stderr, "%s-%u %s property fail to add!\n", bactext_object_type_name(rp_data->object_type), rp_data->object_instance, bactext_property_name(rp_data->object_property)); @@ -640,8 +640,8 @@ static void bacnet_device_object_property_add( property_data->application_data, rp_data->application_data, rp_data->application_data_len); } else { - debug_perror( - "%s-%u %s property fail to allocate!\n", + debug_fprintf( + stderr, "%s-%u %s property fail to allocate!\n", bactext_object_type_name(rp_data->object_type), rp_data->object_instance, bactext_property_name(rp_data->object_property)); @@ -794,7 +794,8 @@ bacnet_discover_device_fsm(uint32_t device_id, BACNET_DEVICE_DATA *device_data) device_data->Discovery_State = BACNET_DISCOVER_STATE_OBJECT_LIST_SIZE_REQUEST; } else { - debug_perror("%u object-list-size fail to queue!\n", device_id); + debug_fprintf( + stderr, "%u object-list-size fail to queue!\n", device_id); } break; case BACNET_DISCOVER_STATE_OBJECT_LIST_SIZE_REQUEST: @@ -824,9 +825,9 @@ bacnet_discover_device_fsm(uint32_t device_id, BACNET_DEVICE_DATA *device_data) BACNET_DISCOVER_STATE_OBJECT_LIST_REQUEST; return; } else { - debug_perror( - "%u object-list[%u] %s-%u fail to queue!\n", device_id, - device_data->Object_List_Index, + debug_fprintf( + stderr, "%u object-list[%u] %s-%u fail to queue!\n", + device_id, device_data->Object_List_Index, bactext_object_type_name(object_type), (unsigned)object_instance); device_data->Object_List_Index--; @@ -862,9 +863,9 @@ bacnet_discover_device_fsm(uint32_t device_id, BACNET_DEVICE_DATA *device_data) BACNET_DISCOVER_STATE_OBJECT_GET_PROPERTY_REQUEST; device_data->Object_List_Index++; } else { - debug_perror( - "%u object-list[%u] %s-%u fail to queue!\n", device_id, - device_data->Object_List_Index, + debug_fprintf( + stderr, "%u object-list[%u] %s-%u fail to queue!\n", + device_id, device_data->Object_List_Index, bactext_object_type_name(object_type), (unsigned)object_instance); } @@ -886,8 +887,8 @@ bacnet_discover_device_fsm(uint32_t device_id, BACNET_DEVICE_DATA *device_data) } break; default: - debug_perror( - "%u unknown state %u!\n", device_id, + debug_fprintf( + stderr, "%u unknown state %u!\n", device_id, device_data->Discovery_State); break; } @@ -911,7 +912,7 @@ static void bacnet_discover_devices_task(void) for (device_index = 0; device_index < device_count; device_index++) { device_data = Keylist_Data_Index(Device_List, device_index); if (!device_data) { - debug_perror("device[%u] is NULL!\n", device_index); + debug_fprintf(stderr, "device[%u] is NULL!\n", device_index); continue; } if (Keylist_Index_Key(Device_List, device_index, &key)) { diff --git a/src/bacnet/basic/npdu/s_router.c b/src/bacnet/basic/npdu/s_router.c index 80a85032..705fa839 100644 --- a/src/bacnet/basic/npdu/s_router.c +++ b/src/bacnet/basic/npdu/s_router.c @@ -7,7 +7,6 @@ */ #include #include -#include #include #include "bacnet/bacdef.h" #include "bacnet/bacdcode.h" @@ -169,19 +168,13 @@ int Send_Network_Layer_Message( "Sending %s message to local BACnet network \n", bactext_network_layer_msg_name(network_message_type)); } - /* Now send the message */ bytes_sent = datalink_send_pdu( dst, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); -#if PRINT_ENABLED if (bytes_sent <= 0) { - int wasErrno = errno; /* preserve the errno */ - debug_printf( - "Failed to send %s message (%s)!\n", - bactext_network_layer_msg_name(network_message_type), - strerror(wasErrno)); + debug_perror("Failed to send message"); } -#endif + return bytes_sent; } @@ -236,7 +229,7 @@ void Send_Reject_Message_To_Network( iArgs[1] = dnet; Send_Network_Layer_Message( NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK, dst, iArgs); - debug_printf(" Reject Reason=%d, DNET=%u\n", reject_reason, dnet); + debug_printf("Reject Reason=%d, DNET=%u\n", reject_reason, dnet); } /** Send an Initialize Routing Table message, built from an optional DNET[] diff --git a/src/bacnet/basic/object/bi.c b/src/bacnet/basic/object/bi.c index e67d5db8..65d58a27 100644 --- a/src/bacnet/basic/object/bi.c +++ b/src/bacnet/basic/object/bi.c @@ -21,17 +21,14 @@ #include "bacnet/rp.h" #include "bacnet/wp.h" #include "bacnet/cov.h" +/* basic objects and services */ #include "bacnet/basic/object/device.h" #include "bacnet/basic/services.h" #include "bacnet/basic/sys/keylist.h" +#include "bacnet/basic/sys/debug.h" /* me! */ #include "bacnet/basic/object/bi.h" -#include "bacnet/basic/sys/debug.h" -#if !defined(PRINT) -#define PRINT debug_perror -#endif - static const char *Default_Active_Text = "Active"; static const char *Default_Inactive_Text = "Inactive"; struct object_data { @@ -1732,7 +1729,7 @@ int Binary_Input_Alarm_Summary( struct object_data *pObject = Binary_Input_Object_Index(index); if (getalarm_data == NULL) { - PRINT( + debug_printf( "[%s %d]: NULL pointer parameter! getalarm_data = %p\r\n", __FILE__, __LINE__, (void *)getalarm_data); return -2; @@ -1919,7 +1916,8 @@ void Binary_Input_Intrinsic_Reporting(uint32_t object_instance) pObject->Ack_notify_data.bSendAckNotify = false; /* copy toState */ ToState = pObject->Ack_notify_data.EventState; - PRINT("Binary-Input[%d]: Send AckNotification.\n", object_instance); + debug_printf( + "Binary-Input[%d]: Send AckNotification.\n", object_instance); characterstring_init_ansi(&msgText, "AckNotification"); /* Notify Type */ @@ -1999,7 +1997,7 @@ void Binary_Input_Intrinsic_Reporting(uint32_t object_instance) default: break; } /* switch (ToState) */ - PRINT( + debug_printf( "Binary-Input[%d]: Event_State goes from %.128s to %.128s.\n", object_instance, bactext_event_state_name(FromState), bactext_event_state_name(ToState)); @@ -2112,7 +2110,7 @@ void Binary_Input_Intrinsic_Reporting(uint32_t object_instance) } /* add data from notification class */ - PRINT( + debug_printf( "Binary-Input[%d]: Notification Class[%d]-%s " "%u/%u/%u-%u:%u:%u.%u!\n", object_instance, event_data.notificationClass, @@ -2129,7 +2127,7 @@ void Binary_Input_Intrinsic_Reporting(uint32_t object_instance) /* Ack required */ if ((event_data.notifyType != NOTIFY_ACK_NOTIFICATION) && (event_data.ackRequired == true)) { - PRINT("Binary-Input[%d]: Ack Required!\n", object_instance); + debug_printf("Binary-Input[%d]: Ack Required!\n", object_instance); switch (event_data.toState) { case EVENT_STATE_OFFNORMAL: pObject->Acked_Transitions[TRANSITION_TO_OFFNORMAL] diff --git a/src/bacnet/basic/object/bv.c b/src/bacnet/basic/object/bv.c index 9277283d..1f88338e 100644 --- a/src/bacnet/basic/object/bv.c +++ b/src/bacnet/basic/object/bv.c @@ -21,17 +21,14 @@ #include "bacnet/wp.h" #include "bacnet/rp.h" #include "bacnet/cov.h" +/* basic objects and services */ #include "bacnet/basic/services.h" #include "bacnet/basic/object/device.h" #include "bacnet/basic/sys/keylist.h" +#include "bacnet/basic/sys/debug.h" /* me! */ #include "bacnet/basic/object/bv.h" -#include "bacnet/basic/sys/debug.h" -#if !defined(PRINT) -#define PRINT debug_perror -#endif - static const char *Default_Active_Text = "Active"; static const char *Default_Inactive_Text = "Inactive"; struct object_data { @@ -285,7 +282,7 @@ BACNET_BINARY_PV Binary_Value_Present_Value(uint32_t object_instance) /** * @brief For a given object instance-number, checks the present-value for COV * @param pObject - specific object with valid data - * @param value - floating point analog value + * @param value - binary value */ static void Binary_Value_Present_Value_COV_Detect( struct object_data *pObject, BACNET_BINARY_PV value) @@ -525,7 +522,7 @@ bool Binary_Value_Present_Value_Set( * For a given object instance-number, sets the present-value * * @param object_instance - object-instance number of the object - * @param value - floating point analog value + * @param value - binary value * @param error_class - the BACnet error class * @param error_code - BACnet Error code * @@ -592,7 +589,7 @@ bool Binary_Value_Object_Name( if (pObject) { if (pObject->Object_Name == NULL) { snprintf( - text, sizeof(text), "BINARY INPUT %lu", + text, sizeof(text), "BINARY VALUE %lu", (unsigned long)object_instance); status = characterstring_init_ansi(object_name, text); } else { @@ -1273,7 +1270,7 @@ void Binary_Value_Write_Disable(uint32_t object_instance) } /** - * @brief Creates a Binary Output object + * @brief Creates a Binary Value object * @param object_instance - object-instance number of the object * @return the object-instance that was created, or BACNET_MAX_INSTANCE */ @@ -1345,7 +1342,7 @@ uint32_t Binary_Value_Create(uint32_t object_instance) } /** - * Initializes the Binary Input object data + * Deletes the Binary Value object data */ void Binary_Value_Cleanup(void) { @@ -1364,7 +1361,7 @@ void Binary_Value_Cleanup(void) } /** - * Creates a Binary Input object + * Deletes a Binary Value object */ bool Binary_Value_Delete(uint32_t object_instance) { @@ -1381,7 +1378,7 @@ bool Binary_Value_Delete(uint32_t object_instance) } /** - * Initializes the Binary Input object data + * Initializes the Binary Value object data */ void Binary_Value_Init(void) { @@ -1747,7 +1744,7 @@ int Binary_Value_Alarm_Summary( struct object_data *pObject = Binary_Value_Object_Index(index); if (getalarm_data == NULL) { - PRINT( + debug_printf( "[%s %d]: NULL pointer parameter! getalarm_data = %p\r\n", __FILE__, __LINE__, (void *)getalarm_data); return -2; @@ -1942,7 +1939,8 @@ void Binary_Value_Intrinsic_Reporting(uint32_t object_instance) pObject->Ack_notify_data.bSendAckNotify = false; /* copy toState */ ToState = pObject->Ack_notify_data.EventState; - PRINT("Binary-Input[%d]: Send AckNotification.\n", object_instance); + debug_printf( + "Binary-Value[%d]: Send AckNotification.\n", object_instance); characterstring_init_ansi(&msgText, "AckNotification"); /* Notify Type */ @@ -2022,8 +2020,8 @@ void Binary_Value_Intrinsic_Reporting(uint32_t object_instance) default: break; } /* switch (ToState) */ - PRINT( - "Binary-Input[%d]: Event_State goes from %.128s to %.128s.\n", + debug_printf( + "Binary-Value[%d]: Event_State goes from %.128s to %.128s.\n", object_instance, bactext_event_state_name(FromState), bactext_event_state_name(ToState)); /* Notify Type */ @@ -2135,7 +2133,7 @@ void Binary_Value_Intrinsic_Reporting(uint32_t object_instance) } /* add data from notification class */ - PRINT( + debug_printf( "Binary-Value[%d]: Notification Class[%d]-%s " "%u/%u/%u-%u:%u:%u.%u!\n", object_instance, event_data.notificationClass, @@ -2152,7 +2150,7 @@ void Binary_Value_Intrinsic_Reporting(uint32_t object_instance) /* Ack required */ if ((event_data.notifyType != NOTIFY_ACK_NOTIFICATION) && (event_data.ackRequired == true)) { - PRINT("Binary-Value[%d]: Ack Required!\n", object_instance); + debug_printf("Binary-Value[%d]: Ack Required!\n", object_instance); switch (event_data.toState) { case EVENT_STATE_OFFNORMAL: pObject->Acked_Transitions[TRANSITION_TO_OFFNORMAL] diff --git a/src/bacnet/basic/object/iv.c b/src/bacnet/basic/object/iv.c index de1fc084..3057f0bd 100644 --- a/src/bacnet/basic/object/iv.c +++ b/src/bacnet/basic/object/iv.c @@ -20,14 +20,13 @@ #include "bacnet/bacapp.h" #include "bacnet/bactext.h" #include "bacnet/proplist.h" +/* basic objects and services */ #include "bacnet/basic/object/device.h" #include "bacnet/basic/services.h" +#include "bacnet/basic/sys/debug.h" +#include "bacnet/basic/sys/keylist.h" /* me! */ #include "bacnet/basic/object/iv.h" -#include "bacnet/basic/sys/keylist.h" -#include "bacnet/basic/sys/debug.h" - -#define PRINTF debug_perror /* Key List for storing the object data sorted by instance number */ static OS_Keylist Object_List = NULL; diff --git a/src/bacnet/basic/object/nc.c b/src/bacnet/basic/object/nc.c index 4751921e..7fe1284d 100644 --- a/src/bacnet/basic/object/nc.c +++ b/src/bacnet/basic/object/nc.c @@ -19,6 +19,7 @@ #include "bacnet/datetime.h" #include "bacnet/event.h" #include "bacnet/wp.h" +/* basic objects and services */ #include "bacnet/basic/object/device.h" #include "bacnet/basic/object/nc.h" #include "bacnet/basic/binding/address.h" @@ -27,8 +28,6 @@ #include "bacnet/basic/tsm/tsm.h" #include "bacnet/datalink/datalink.h" -#define PRINTF debug_perror - #ifndef MAX_NOTIFICATION_CLASSES #define MAX_NOTIFICATION_CLASSES 2 #endif @@ -682,7 +681,7 @@ void Notification_Class_common_reporting_function( } /* send notifications for active recipients */ - PRINTF( + debug_printf_stderr( "Notification Class[%u]: send notifications\n", event_data->notificationClass); /* pointer to first recipient */ @@ -703,7 +702,7 @@ void Notification_Class_common_reporting_function( if (pBacDest->Recipient.tag == BACNET_RECIPIENT_TAG_DEVICE) { /* send notification to the specified device */ device_id = pBacDest->Recipient.type.device.instance; - PRINTF( + debug_printf_stderr( "Notification Class[%u]: send notification to %u\n", event_data->notificationClass, (unsigned)device_id); if (pBacDest->ConfirmedNotify == true) { @@ -713,7 +712,7 @@ void Notification_Class_common_reporting_function( } } else if ( pBacDest->Recipient.tag == BACNET_RECIPIENT_TAG_ADDRESS) { - PRINTF( + debug_printf_stderr( "Notification Class[%u]: send notification to ADDR\n", event_data->notificationClass); /* send notification to the address indicated */ diff --git a/src/bacnet/basic/service/h_alarm_ack.c b/src/bacnet/basic/service/h_alarm_ack.c index d08e873f..9a0460f7 100644 --- a/src/bacnet/basic/service/h_alarm_ack.c +++ b/src/bacnet/basic/service/h_alarm_ack.c @@ -11,7 +11,6 @@ #include #include #include -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ @@ -22,9 +21,11 @@ #include "bacnet/npdu.h" #include "bacnet/abort.h" #include "bacnet/alarm_ack.h" +#include "bacnet/reject.h" /* basic objects, services, TSM, and datalink */ #include "bacnet/basic/object/device.h" #include "bacnet/basic/tsm/tsm.h" +#include "bacnet/basic/sys/debug.h" #include "bacnet/basic/services.h" #include "bacnet/datalink/datalink.h" @@ -64,9 +65,7 @@ void handler_alarm_ack( { int len = 0; int pdu_len = 0; -#if PRINT_ENABLED int bytes_sent = 0; -#endif int ack_result = 0; BACNET_ADDRESS my_address; BACNET_NPDU_DATA npdu_data; @@ -75,51 +74,43 @@ void handler_alarm_ack( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); - npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); + npdu_encode_npdu_data(&npdu_data, false, service_data->priority); pdu_len = npdu_encode_pdu( &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); - if (service_data->segmented_message) { + if (service_len == 0) { + len = reject_encode_apdu( + &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, + REJECT_REASON_MISSING_REQUIRED_PARAMETER); + debug_print("Alarm Ack: Missing Required Parameter. Sending Reject!\n"); + goto AA_ABORT; + } else if (service_data->segmented_message) { /* we don't support segmentation - send an abort */ len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); -#if PRINT_ENABLED - fprintf(stderr, "Alarm Ack: Segmented message. Sending Abort!\n"); -#endif + debug_print("Alarm Ack: Segmented message. Sending Abort!\n"); goto AA_ABORT; } len = alarm_ack_decode_service_request(service_request, service_len, &data); -#if PRINT_ENABLED if (len <= 0) { - fprintf(stderr, "Alarm Ack: Unable to decode Request!\n"); + debug_print("Alarm Ack: Unable to decode Request!\n"); } -#endif if (len < 0) { /* bad decoding - send an abort */ len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_OTHER, true); -#if PRINT_ENABLED - fprintf(stderr, "Alarm Ack: Bad Encoding. Sending Abort!\n"); -#endif + debug_print("Alarm Ack: Bad Encoding. Sending Abort!\n"); goto AA_ABORT; } -#if PRINT_ENABLED - fprintf( + debug_fprintf( stderr, "Alarm Ack Operation: Received acknowledge for object id (%d, %lu) " "from %s for process id %lu \n", data.eventObjectIdentifier.type, (unsigned long)data.eventObjectIdentifier.instance, data.ackSource.value, (unsigned long)data.ackProcessIdentifier); -#endif - - /* BACnet Testing Observed Incident oi00105 - ACK of a non-existent object returned the incorrect error code - Revealed by BACnet Test Client v1.8.16 ( - www.bac-test.com/bacnet-test-client-download ) BC 135.1: 9.1.3.3-A Any - discussions can be directed to edward@bac-test.com */ if (!Device_Valid_Object_Id( data.eventObjectIdentifier.type, data.eventObjectIdentifier.instance)) { @@ -130,18 +121,12 @@ void handler_alarm_ack( } else if (Alarm_Ack[data.eventObjectIdentifier.type]) { ack_result = Alarm_Ack[data.eventObjectIdentifier.type](&data, &error_code); - switch (ack_result) { case 1: len = encode_simple_ack( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM); -#if PRINT_ENABLED - fprintf( - stderr, - "Alarm Acknowledge: " - "Sending Simple Ack!\n"); -#endif + debug_print("Alarm Acknowledge: Sending Simple Ack!\n"); break; case -1: @@ -149,20 +134,16 @@ void handler_alarm_ack( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, ERROR_CLASS_OBJECT, error_code); -#if PRINT_ENABLED - fprintf( + debug_fprintf( stderr, "Alarm Acknowledge: error %s!\n", bactext_error_code_name(error_code)); -#endif break; default: len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_OTHER, true); -#if PRINT_ENABLED - fprintf(stderr, "Alarm Acknowledge: abort other!\n"); -#endif + debug_print("Alarm Acknowledge: abort other!\n"); break; } } else { @@ -170,29 +151,16 @@ void handler_alarm_ack( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, ERROR_CLASS_OBJECT, ERROR_CODE_NO_ALARM_CONFIGURED); -#if PRINT_ENABLED - fprintf( - stderr, "Alarm Acknowledge: error %s!\n", - bactext_error_code_name(ERROR_CODE_NO_ALARM_CONFIGURED)); -#endif + debug_print("Alarm Acknowledge: No Alarm Configured!\n"); } AA_ABORT: pdu_len += len; -#if PRINT_ENABLED - bytes_sent = -#endif - datalink_send_pdu( - src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); -#if PRINT_ENABLED + bytes_sent = datalink_send_pdu( + src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { - fprintf( - stderr, - "Alarm Acknowledge: " - "Failed to send PDU (%s)!\n", - strerror(errno)); + debug_perror("Alarm Acknowledge: Failed to send PDU"); } -#endif return; } diff --git a/src/bacnet/basic/service/h_arf.c b/src/bacnet/basic/service/h_arf.c index 1ef0c3fd..bcfdd8d7 100644 --- a/src/bacnet/basic/service/h_arf.c +++ b/src/bacnet/basic/service/h_arf.c @@ -9,7 +9,6 @@ #include #include #include -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ @@ -18,6 +17,7 @@ #include "bacnet/apdu.h" #include "bacnet/npdu.h" #include "bacnet/abort.h" +#include "bacnet/reject.h" #include "bacnet/arf.h" /* basic objects, services, TSM, and datalink */ #if defined(BACFILE) @@ -25,6 +25,7 @@ #endif #include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/services.h" +#include "bacnet/basic/sys/debug.h" #include "bacnet/datalink/datalink.h" /* @@ -100,16 +101,20 @@ void handler_atomic_read_file( #endif /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); - npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); + npdu_encode_npdu_data(&npdu_data, false, service_data->priority); pdu_len = npdu_encode_pdu( &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); - if (service_data->segmented_message) { + if (service_len == 0) { + len = reject_encode_apdu( + &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, + REJECT_REASON_MISSING_REQUIRED_PARAMETER); + debug_print("ARF: Missing Required Parameter. Sending Reject!\n"); + goto ARF_ABORT; + } else if (service_data->segmented_message) { len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); -#if PRINT_ENABLED - fprintf(stderr, "ARF: Segmented Message. Sending Abort!\n"); -#endif + debug_print("ARF: Segmented Message. Sending Abort!\n"); goto ARF_ABORT; } len = arf_decode_service_request(service_request, service_len, &data); @@ -118,9 +123,7 @@ void handler_atomic_read_file( len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_OTHER, true); -#if PRINT_ENABLED - fprintf(stderr, "Bad Encoding. Sending Abort!\n"); -#endif + debug_print("ARF: Bad Encoding. Sending Abort!\n"); goto ARF_ABORT; } if (data.object_type == OBJECT_FILE) { @@ -130,12 +133,10 @@ void handler_atomic_read_file( if (data.type.stream.requestedOctetCount <= octetstring_capacity(&data.fileData[0])) { bacfile_read_stream_data(&data); -#if PRINT_ENABLED - fprintf( + debug_fprintf( stderr, "ARF: Stream offset %d, %d octets.\n", (int)data.type.stream.fileStartPosition, (int)data.type.stream.requestedOctetCount); -#endif len = arf_ack_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &data); @@ -143,12 +144,12 @@ void handler_atomic_read_file( len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); -#if PRINT_ENABLED - fprintf( - stderr, "Too Big To Send (%d >= %d). Sending Abort!\n", + debug_fprintf( + stderr, + "ARF: Too Big To Send (%d >= %d). " + "Sending Abort!\n", (int)data.type.stream.requestedOctetCount, (int)octetstring_capacity(&data.fileData[0])); -#endif } } else if (data.access == FILE_RECORD_ACCESS) { if (data.type.record.fileStartRecord >= @@ -157,12 +158,10 @@ void handler_atomic_read_file( error_code = ERROR_CODE_INVALID_FILE_START_POSITION; error = true; } else if (bacfile_read_stream_data(&data)) { -#if PRINT_ENABLED - fprintf( + debug_fprintf( stderr, "ARF: fileStartRecord %d, %u RecordCount.\n", (int)data.type.record.fileStartRecord, (unsigned)data.type.record.RecordCount); -#endif len = arf_ack_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &data); @@ -175,9 +174,7 @@ void handler_atomic_read_file( error = true; error_class = ERROR_CLASS_SERVICES; error_code = ERROR_CODE_INVALID_FILE_ACCESS_METHOD; -#if PRINT_ENABLED - fprintf(stderr, "Record Access Requested. Sending Error!\n"); -#endif + debug_print("ARF: Record Access Requested. Sending Error!\n"); } } else { error = true; @@ -193,11 +190,9 @@ ARF_ABORT: pdu_len += len; bytes_sent = datalink_send_pdu( src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); -#if PRINT_ENABLED if (bytes_sent <= 0) { - fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); + debug_perror("ARF: Failed to send PDU"); } -#endif return; } diff --git a/src/bacnet/basic/service/h_awf.c b/src/bacnet/basic/service/h_awf.c index 6fdf26c6..5fb4cacb 100644 --- a/src/bacnet/basic/service/h_awf.c +++ b/src/bacnet/basic/service/h_awf.c @@ -9,7 +9,6 @@ #include #include #include -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ @@ -19,11 +18,13 @@ #include "bacnet/apdu.h" #include "bacnet/npdu.h" #include "bacnet/abort.h" +#include "bacnet/reject.h" #include "bacnet/awf.h" /* basic objects, services, TSM, and datalink */ #include "bacnet/basic/object/device.h" #include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/services.h" +#include "bacnet/basic/sys/debug.h" #include "bacnet/datalink/datalink.h" #if defined(BACFILE) #include "bacnet/basic/object/bacfile.h" @@ -75,21 +76,23 @@ void handler_atomic_write_file( BACNET_ERROR_CLASS error_class = ERROR_CLASS_OBJECT; BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT; -#if PRINT_ENABLED - fprintf(stderr, "Received AtomicWriteFile Request!\n"); -#endif + debug_print("Received AtomicWriteFile Request!\n"); /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); - npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); + npdu_encode_npdu_data(&npdu_data, false, service_data->priority); pdu_len = npdu_encode_pdu( &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); - if (service_data->segmented_message) { + if (service_len == 0) { + len = reject_encode_apdu( + &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, + REJECT_REASON_MISSING_REQUIRED_PARAMETER); + debug_print("AWF: Missing Required Parameter. Sending Reject!\n"); + goto AWF_ABORT; + } else if (service_data->segmented_message) { len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); -#if PRINT_ENABLED - fprintf(stderr, "Segmented Message. Sending Abort!\n"); -#endif + debug_print("AWF:Segmented Message. Sending Abort!\n"); goto AWF_ABORT; } len = awf_decode_service_request(service_request, service_len, &data); @@ -98,9 +101,7 @@ void handler_atomic_write_file( len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_OTHER, true); -#if PRINT_ENABLED - fprintf(stderr, "Bad Encoding. Sending Abort!\n"); -#endif + debug_print("AWF: Bad Encoding. Sending Abort!\n"); goto AWF_ABORT; } if (data.object_type == OBJECT_FILE) { @@ -108,12 +109,10 @@ void handler_atomic_write_file( error = true; } else if (data.access == FILE_STREAM_ACCESS) { if (bacfile_write_stream_data(&data)) { -#if PRINT_ENABLED - fprintf( + debug_fprintf( stderr, "AWF: Stream offset %d, %d bytes\n", data.type.stream.fileStartPosition, (int)octetstring_length(&data.fileData[0])); -#endif len = awf_ack_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &data); @@ -124,12 +123,10 @@ void handler_atomic_write_file( } } else if (data.access == FILE_RECORD_ACCESS) { if (bacfile_write_record_data(&data)) { -#if PRINT_ENABLED - fprintf( + debug_fprintf( stderr, "AWF: StartRecord %d, RecordCount %u\n", data.type.record.fileStartRecord, data.type.record.returnedRecordCount); -#endif len = awf_ack_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &data); @@ -142,9 +139,7 @@ void handler_atomic_write_file( error = true; error_class = ERROR_CLASS_SERVICES; error_code = ERROR_CODE_INVALID_FILE_ACCESS_METHOD; -#if PRINT_ENABLED - fprintf(stderr, "Record Access Requested. Sending Error!\n"); -#endif + debug_print("AWF: Record Access Requested. Sending Error!\n"); } } else { error = true; @@ -160,11 +155,9 @@ AWF_ABORT: pdu_len += len; bytes_sent = datalink_send_pdu( src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); -#if PRINT_ENABLED if (bytes_sent <= 0) { - fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); + debug_perror("AWF: Failed to send PDU\n"); } -#endif return; } diff --git a/src/bacnet/basic/service/h_ccov.c b/src/bacnet/basic/service/h_ccov.c index dee4398c..87233447 100644 --- a/src/bacnet/basic/service/h_ccov.c +++ b/src/bacnet/basic/service/h_ccov.c @@ -9,7 +9,6 @@ #include #include #include -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ @@ -17,6 +16,7 @@ #include "bacnet/apdu.h" #include "bacnet/npdu.h" #include "bacnet/abort.h" +#include "bacnet/reject.h" #include "bacnet/cov.h" #include "bacnet/bactext.h" /* basic services, TSM, and datalink */ @@ -25,8 +25,6 @@ #include "bacnet/datalink/datalink.h" #include "bacnet/basic/sys/debug.h" -#define PRINTF debug_perror - /* max number of COV properties decoded in a COV notification */ #ifndef MAX_COV_PROPERTIES #define MAX_COV_PROPERTIES 2 @@ -74,6 +72,41 @@ void handler_ccov_notification_add(BACNET_COV_NOTIFICATION *cb) } while (head); } +/** + * @brief Print ConfirmedCOVNotification data + * @param cov_data - data decoded from the COV notification + */ +void handler_ccov_data_print(BACNET_COV_DATA *cov_data) +{ + BACNET_PROPERTY_VALUE *pProperty_value = NULL; + + debug_printf_stderr("CCOV: PID=%u ", cov_data->subscriberProcessIdentifier); + debug_printf_stderr("instance=%u ", cov_data->initiatingDeviceIdentifier); + debug_printf_stderr( + "%s %u ", + bactext_object_type_name(cov_data->monitoredObjectIdentifier.type), + cov_data->monitoredObjectIdentifier.instance); + debug_printf_stderr("time remaining=%u seconds ", cov_data->timeRemaining); + debug_printf_stderr("\n"); + pProperty_value = cov_data->listOfValues; + while (pProperty_value) { + debug_printf_stderr("CCOV: "); + if (pProperty_value->propertyIdentifier < 512) { + debug_printf_stderr( + "%s ", + bactext_property_name(pProperty_value->propertyIdentifier)); + } else { + debug_printf_stderr( + "proprietary %u ", pProperty_value->propertyIdentifier); + } + if (pProperty_value->propertyArrayIndex != BACNET_ARRAY_ALL) { + debug_printf_stderr("%u ", pProperty_value->propertyArrayIndex); + } + debug_printf_stderr("\n"); + pProperty_value = pProperty_value->next; + } +} + /* */ /** Handler for an Confirmed COV Notification. * @ingroup DSCOV @@ -97,7 +130,6 @@ void handler_ccov_notification( BACNET_NPDU_DATA npdu_data; BACNET_COV_DATA cov_data; BACNET_PROPERTY_VALUE property_value[MAX_COV_PROPERTIES]; - BACNET_PROPERTY_VALUE *pProperty_value = NULL; int len = 0; int pdu_len = 0; int bytes_sent = 0; @@ -109,15 +141,21 @@ void handler_ccov_notification( cov_data.listOfValues = &property_value[0]; /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); - npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); + npdu_encode_npdu_data(&npdu_data, false, service_data->priority); pdu_len = npdu_encode_pdu( &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); - PRINTF("CCOV: Received Notification!\n"); - if (service_data->segmented_message) { + debug_print("CCOV: Received Notification!\n"); + if (service_len == 0) { + len = reject_encode_apdu( + &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, + REJECT_REASON_MISSING_REQUIRED_PARAMETER); + debug_print("CCOV: Missing Required Parameter. Sending Reject!\n"); + goto CCOV_ABORT; + } else if (service_data->segmented_message) { len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); - PRINTF("CCOV: Segmented message. Sending Abort!\n"); + debug_print("CCOV: Segmented message. Sending Abort!\n"); goto CCOV_ABORT; } /* decode the service request only */ @@ -125,52 +163,27 @@ void handler_ccov_notification( service_request, service_len, &cov_data); if (len > 0) { handler_ccov_notification_callback(&cov_data); - PRINTF("CCOV: PID=%u ", cov_data.subscriberProcessIdentifier); - PRINTF("instance=%u ", cov_data.initiatingDeviceIdentifier); - PRINTF( - "%s %u ", - bactext_object_type_name(cov_data.monitoredObjectIdentifier.type), - cov_data.monitoredObjectIdentifier.instance); - PRINTF("time remaining=%u seconds ", cov_data.timeRemaining); - PRINTF("\n"); - pProperty_value = &property_value[0]; - while (pProperty_value) { - PRINTF("CCOV: "); - if (pProperty_value->propertyIdentifier < 512) { - PRINTF( - "%s ", - bactext_property_name(pProperty_value->propertyIdentifier)); - } else { - PRINTF("proprietary %u ", pProperty_value->propertyIdentifier); - } - if (pProperty_value->propertyArrayIndex != BACNET_ARRAY_ALL) { - PRINTF("%u ", pProperty_value->propertyArrayIndex); - } - PRINTF("\n"); - pProperty_value = pProperty_value->next; - } } /* bad decoding or something we didn't understand - send an abort */ if (len <= 0) { len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_OTHER, true); - PRINTF("CCOV: Bad Encoding. Sending Abort!\n"); + debug_print("CCOV: Bad Encoding. Sending Abort!\n"); goto CCOV_ABORT; } else { len = encode_simple_ack( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, SERVICE_CONFIRMED_COV_NOTIFICATION); - PRINTF("CCOV: Sending Simple Ack!\n"); + debug_print("CCOV: Sending Simple Ack!\n"); } CCOV_ABORT: pdu_len += len; bytes_sent = datalink_send_pdu( src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { - PRINTF("CCOV: Failed to send PDU (%s)!\n", strerror(errno)); + debug_perror("CCOV: Failed to send PDU"); } - (void)bytes_sent; return; } diff --git a/src/bacnet/basic/service/h_ccov.h b/src/bacnet/basic/service/h_ccov.h index 7459a0df..d9b9c454 100644 --- a/src/bacnet/basic/service/h_ccov.h +++ b/src/bacnet/basic/service/h_ccov.h @@ -23,6 +23,9 @@ extern "C" { BACNET_STACK_EXPORT void handler_ccov_notification_add(BACNET_COV_NOTIFICATION *callback); +BACNET_STACK_EXPORT +void handler_ccov_data_print(BACNET_COV_DATA *cov_data); + BACNET_STACK_EXPORT void handler_ccov_notification( uint8_t *service_request, diff --git a/src/bacnet/basic/service/h_cov.c b/src/bacnet/basic/service/h_cov.c index d0ef1d01..fb379012 100644 --- a/src/bacnet/basic/service/h_cov.c +++ b/src/bacnet/basic/service/h_cov.c @@ -9,7 +9,6 @@ #include #include #include -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ @@ -29,6 +28,7 @@ #include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/object/device.h" #include "bacnet/basic/services.h" +#include "bacnet/basic/sys/debug.h" #include "bacnet/datalink/datalink.h" #ifndef MAX_COV_PROPERTIES @@ -820,24 +820,25 @@ void handler_cov_subscribe( cov_data.error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED; /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); - npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); + npdu_encode_npdu_data(&npdu_data, false, service_data->priority); npdu_len = npdu_encode_pdu( &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); - if (service_data->segmented_message) { + if (service_len == 0) { + len = BACNET_STATUS_REJECT; + cov_data.error_code = ERROR_CODE_REJECT_MISSING_REQUIRED_PARAMETER; + debug_print("CCOV: Missing Required Parameter. Sending Reject!\n"); + error = true; + } else if (service_data->segmented_message) { /* we don't support segmentation - send an abort */ len = BACNET_STATUS_ABORT; -#if PRINT_ENABLED - fprintf(stderr, "SubscribeCOV: Segmented message. Sending Abort!\n"); -#endif + debug_print("SubscribeCOV: Segmented message. Sending Abort!\n"); error = true; } else { len = cov_subscribe_decode_service_request( service_request, service_len, &cov_data); -#if PRINT_ENABLED if (len <= 0) { - fprintf(stderr, "SubscribeCOV: Unable to decode Request!\n"); + debug_print("SubscribeCOV: Unable to decode Request!\n"); } -#endif if (len < 0) { error = true; } else { @@ -849,54 +850,39 @@ void handler_cov_subscribe( apdu_len = encode_simple_ack( &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, SERVICE_CONFIRMED_SUBSCRIBE_COV); -#if PRINT_ENABLED - fprintf(stderr, "SubscribeCOV: Sending Simple Ack!\n"); -#endif + debug_print("SubscribeCOV: Sending Simple Ack!\n"); } else { len = BACNET_STATUS_ERROR; error = true; -#if PRINT_ENABLED - fprintf(stderr, "SubscribeCOV: Sending Error!\n"); -#endif + debug_print("SubscribeCOV: Sending Error!\n"); } } } - /* Error? */ if (error) { if (len == BACNET_STATUS_ABORT) { apdu_len = abort_encode_apdu( &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, abort_convert_error_code(cov_data.error_code), true); -#if PRINT_ENABLED - fprintf(stderr, "SubscribeCOV: Sending Abort!\n"); -#endif + debug_print("SubscribeCOV: Sending Abort!\n"); } else if (len == BACNET_STATUS_ERROR) { apdu_len = bacerror_encode_apdu( &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, SERVICE_CONFIRMED_SUBSCRIBE_COV, cov_data.error_class, cov_data.error_code); -#if PRINT_ENABLED - fprintf(stderr, "SubscribeCOV: Sending Error!\n"); -#endif + debug_print("SubscribeCOV: Sending Error!\n"); } else if (len == BACNET_STATUS_REJECT) { apdu_len = reject_encode_apdu( &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, reject_convert_error_code(cov_data.error_code)); -#if PRINT_ENABLED - fprintf(stderr, "SubscribeCOV: Sending Reject!\n"); -#endif + debug_print("SubscribeCOV: Sending Reject!\n"); } } pdu_len = npdu_len + apdu_len; bytes_sent = datalink_send_pdu( src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { -#if PRINT_ENABLED - fprintf( - stderr, "SubscribeCOV: Failed to send PDU (%s)!\n", - strerror(errno)); -#endif + debug_perror("SubscribeCOV: Failed to send PDU"); } return; diff --git a/src/bacnet/basic/service/h_create_object.c b/src/bacnet/basic/service/h_create_object.c index 71f8f5f1..af9fb242 100644 --- a/src/bacnet/basic/service/h_create_object.c +++ b/src/bacnet/basic/service/h_create_object.c @@ -9,7 +9,6 @@ #include #include #include -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ @@ -60,15 +59,22 @@ void handler_create_object( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); - npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); + npdu_encode_npdu_data(&npdu_data, false, service_data->priority); pdu_len = npdu_encode_pdu( &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); - debug_perror("CreateObject: Received Request!\n"); - if (service_data->segmented_message) { + debug_print("CreateObject: Received Request!\n"); + if (service_len == 0) { + len = reject_encode_apdu( + &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, + REJECT_REASON_MISSING_REQUIRED_PARAMETER); + debug_print( + "CreateObject: Missing Required Parameter. Sending Reject!\n"); + status = false; + } else if (service_data->segmented_message) { len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); - debug_perror("CreateObject: Segmented message. Sending Abort!\n"); + debug_print("CreateObject: Segmented message. Sending Abort!\n"); status = false; } if (status) { @@ -76,12 +82,12 @@ void handler_create_object( len = create_object_decode_service_request( service_request, service_len, &data); if (len > 0) { - debug_perror( + debug_printf_stderr( "CreateObject: type=%lu instance=%lu\n", (unsigned long)data.object_type, (unsigned long)data.object_instance); } else { - debug_perror("CreateObject: Unable to decode request!\n"); + debug_print("CreateObject: Unable to decode request!\n"); } if (len <= 0) { /* bad decoding or something we didn't understand */ @@ -89,24 +95,24 @@ void handler_create_object( len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, abort_convert_error_code(data.error_code), true); - debug_perror("CreateObject: Sending Abort!\n"); + debug_print("CreateObject: Sending Abort!\n"); } else if (len == BACNET_STATUS_REJECT) { len = reject_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, reject_convert_error_code(data.error_code)); - debug_perror("CreateObject: Sending Reject!\n"); + debug_print("CreateObject: Sending Reject!\n"); } } else { if (Device_Create_Object(&data)) { len = create_object_ack_encode( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &data); - debug_perror("CreateObject: Sending ACK!\n"); + debug_print("CreateObject: Sending ACK!\n"); } else { len = create_object_error_ack_encode( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &data); - debug_perror("CreateObject: Sending Error!\n"); + debug_print("CreateObject: Sending Error!\n"); } } } @@ -117,8 +123,7 @@ void handler_create_object( src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); } if (bytes_sent <= 0) { - debug_perror( - "CreateObject: Failed to send PDU (%s)!\n", strerror(errno)); + debug_perror("CreateObject: Failed to send PDU"); } return; diff --git a/src/bacnet/basic/service/h_dcc.c b/src/bacnet/basic/service/h_dcc.c index 448b8162..bc0e0fe6 100644 --- a/src/bacnet/basic/service/h_dcc.c +++ b/src/bacnet/basic/service/h_dcc.c @@ -9,7 +9,6 @@ #include #include #include -#include #include "bacnet/bacdef.h" #include "bacnet/bacdcode.h" #include "bacnet/bacerror.h" @@ -22,6 +21,7 @@ #include "bacnet/basic/object/device.h" #include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/services.h" +#include "bacnet/basic/sys/debug.h" #include "bacnet/datalink/datalink.h" /* The byte length of a UTF-8 character can vary. @@ -97,47 +97,36 @@ void handler_device_communication_control( /* encode the NPDU portion of the reply packet */ datalink_get_my_address(&my_address); - npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); + npdu_encode_npdu_data(&npdu_data, false, service_data->priority); pdu_len = npdu_encode_pdu( &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); -#if PRINT_ENABLED - fprintf(stderr, "DeviceCommunicationControl!\n"); -#endif - if (service_data->segmented_message) { - len = abort_encode_apdu( - &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, - ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); -#if PRINT_ENABLED - fprintf( - stderr, - "DeviceCommunicationControl: " - "Sending Abort - segmented message.\n"); -#endif - goto DCC_FAILURE; - } - - if (!service_request || service_len == 0) { + debug_print("DeviceCommunicationControl!\n"); + if (service_len == 0) { len = reject_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, REJECT_REASON_MISSING_REQUIRED_PARAMETER); -#if PRINT_ENABLED - fprintf(stderr, "DCC: Sending Reject!\n"); -#endif + debug_print("DeviceCommunicationControl: " + "Missing Required Parameter. Sending Reject!\n"); + goto DCC_FAILURE; + } else if (service_data->segmented_message) { + len = abort_encode_apdu( + &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, + ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); + debug_print("DeviceCommunicationControl: " + "Sending Abort - segmented message.\n"); goto DCC_FAILURE; } /* decode the service request only */ len = dcc_decode_service_request( service_request, service_len, &timeDuration, &state, &password); -#if PRINT_ENABLED if (len > 0) { - fprintf( + debug_fprintf( stderr, "DeviceCommunicationControl: " "timeout=%u state=%u password=%s\n", (unsigned)timeDuration, (unsigned)state, characterstring_value(&password)); } -#endif /* bad decoding or invalid service parameter send an abort or reject */ if (len < 0) { @@ -145,16 +134,12 @@ void handler_device_communication_control( len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_OTHER, true); -#if PRINT_ENABLED - fprintf(stderr, "DCC: Sending Abort!\n"); -#endif + debug_print("DCC: Sending Abort!\n"); } else if (len == BACNET_STATUS_REJECT) { len = reject_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, REJECT_REASON_PARAMETER_OUT_OF_RANGE); -#if PRINT_ENABLED - fprintf(stderr, "DCC: Sending Reject!\n"); -#endif + debug_print("DCC: Sending Reject!\n"); } goto DCC_FAILURE; } @@ -167,12 +152,8 @@ void handler_device_communication_control( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, ERROR_CLASS_SERVICES, ERROR_CODE_SERVICE_REQUEST_DENIED); -#if PRINT_ENABLED - fprintf( - stderr, - "DeviceCommunicationControl: " - "Sending Error - DISABLE has been deprecated.\n"); -#endif + debug_print("DeviceCommunicationControl: " + "Sending Error - DISABLE has been deprecated.\n"); goto DCC_FAILURE; } #endif @@ -180,12 +161,8 @@ void handler_device_communication_control( len = reject_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, REJECT_REASON_UNDEFINED_ENUMERATION); -#if PRINT_ENABLED - fprintf( - stderr, - "DeviceCommunicationControl: " - "Sending Reject - undefined enumeration\n"); -#endif + debug_print("DeviceCommunicationControl: " + "Sending Reject - undefined enumeration\n"); } else { #ifdef BAC_ROUTING /* Check to see if the current Device supports this service. */ @@ -201,24 +178,16 @@ void handler_device_communication_control( len = encode_simple_ack( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL); -#if PRINT_ENABLED - fprintf( - stderr, - "DeviceCommunicationControl: " - "Sending Simple Ack!\n"); -#endif + debug_print("DeviceCommunicationControl: " + "Sending Simple Ack!\n"); dcc_set_status_duration(state, timeDuration); } else { len = bacerror_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, ERROR_CLASS_SECURITY, ERROR_CODE_PASSWORD_FAILURE); -#if PRINT_ENABLED - fprintf( - stderr, - "DeviceCommunicationControl: " - "Sending Error - password failure.\n"); -#endif + debug_print("DeviceCommunicationControl: " + "Sending Error - password failure.\n"); } } DCC_FAILURE: @@ -226,13 +195,7 @@ DCC_FAILURE: len = datalink_send_pdu( src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (len <= 0) { -#if PRINT_ENABLED - fprintf( - stderr, - "DeviceCommunicationControl: " - "Failed to send PDU (%s)!\n", - strerror(errno)); -#endif + debug_perror("DeviceCommunicationControl: Failed to send PDU"); } return; diff --git a/src/bacnet/basic/service/h_delete_object.c b/src/bacnet/basic/service/h_delete_object.c index 0c393041..05dbfebf 100644 --- a/src/bacnet/basic/service/h_delete_object.c +++ b/src/bacnet/basic/service/h_delete_object.c @@ -9,7 +9,6 @@ #include #include #include -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ @@ -60,15 +59,23 @@ void handler_delete_object( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); - npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); + npdu_encode_npdu_data(&npdu_data, false, service_data->priority); pdu_len = npdu_encode_pdu( &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); - debug_perror("DeleteObject: Received Request!\n"); - if (service_data->segmented_message) { + debug_print("DeleteObject: Received Request!\n"); + if (service_len == 0) { + len = reject_encode_apdu( + &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, + REJECT_REASON_MISSING_REQUIRED_PARAMETER); + debug_print("DeleteObject: Missing Required Parameter. " + "Sending Reject!\n"); + status = false; + } else if (service_data->segmented_message) { len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); - debug_perror("DeleteObject: Segmented message. Sending Abort!\n"); + debug_print("DeleteObject: Segmented message. " + "Sending Abort!\n"); status = false; } if (status) { @@ -76,19 +83,19 @@ void handler_delete_object( len = delete_object_decode_service_request( service_request, service_len, &data); if (len > 0) { - debug_perror( + debug_printf_stderr( "DeleteObject: type=%lu instance=%lu\n", (unsigned long)data.object_type, (unsigned long)data.object_instance); } else { - debug_perror("DeleteObject: Unable to decode request!\n"); + debug_print("DeleteObject: Unable to decode request!\n"); } /* bad decoding or something we didn't understand - send an abort */ if (len <= 0) { len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_OTHER, true); - debug_perror("DeleteObject: Bad Encoding. Sending Abort!\n"); + debug_print("DeleteObject: Bad Encoding. Sending Abort!\n"); status = false; } if (status) { @@ -96,13 +103,13 @@ void handler_delete_object( len = encode_simple_ack( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, SERVICE_CONFIRMED_DELETE_OBJECT); - debug_perror("DeleteObject: Sending Simple Ack!\n"); + debug_print("DeleteObject: Sending Simple Ack!\n"); } else { len = bacerror_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, SERVICE_CONFIRMED_DELETE_OBJECT, data.error_class, data.error_code); - debug_perror("DeleteObject: Sending Error!\n"); + debug_print("DeleteObject: Sending Error!\n"); } } } @@ -113,8 +120,7 @@ void handler_delete_object( src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); } if (bytes_sent <= 0) { - debug_perror( - "DeleteObject: Failed to send PDU (%s)!\n", strerror(errno)); + debug_perror("DeleteObject: Failed to send PDU"); } return; diff --git a/src/bacnet/basic/service/h_get_alarm_sum.c b/src/bacnet/basic/service/h_get_alarm_sum.c index 9de5c22a..8ef5a6bf 100644 --- a/src/bacnet/basic/service/h_get_alarm_sum.c +++ b/src/bacnet/basic/service/h_get_alarm_sum.c @@ -17,9 +17,11 @@ #include "bacnet/apdu.h" #include "bacnet/npdu.h" #include "bacnet/abort.h" +#include "bacnet/reject.h" /* basic services, TSM, and datalink */ #include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/services.h" +#include "bacnet/basic/sys/debug.h" #include "bacnet/datalink/datalink.h" static get_alarm_summary_function Get_Alarm_Summary[MAX_BACNET_OBJECT_TYPE]; @@ -54,20 +56,25 @@ void handler_get_alarm_summary( (void)service_len; /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); - npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); + npdu_encode_npdu_data(&npdu_data, false, service_data->priority); pdu_len = npdu_encode_pdu( &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); - if (service_data->segmented_message) { + if (service_len == 0) { + apdu_len = reject_encode_apdu( + &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, + REJECT_REASON_MISSING_REQUIRED_PARAMETER); + debug_print("GetAlarmSummary: Missing Required Parameter. " + "Sending Reject!\n"); + goto GET_ALARM_SUMMARY_ABORT; + } else if (service_data->segmented_message) { /* we don't support segmentation - send an abort */ apdu_len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); -#if PRINT_ENABLED - fprintf(stderr, "GetAlarmSummary: Segmented message. Sending Abort!\n"); -#endif + debug_print("GetAlarmSummary: Segmented message. " + "Sending Abort!\n"); goto GET_ALARM_SUMMARY_ABORT; } - /* init header */ apdu_len = get_alarm_summary_ack_encode_apdu_init( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id); @@ -92,11 +99,7 @@ void handler_get_alarm_summary( } } } - -#if PRINT_ENABLED - fprintf(stderr, "GetAlarmSummary: Sending response!\n"); -#endif - + debug_print("GetAlarmSummary: Sending response!\n"); GET_ALARM_SUMMARY_ERROR: if (error) { if (len == BACNET_STATUS_ABORT) { @@ -104,32 +107,22 @@ GET_ALARM_SUMMARY_ERROR: apdu_len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); -#if PRINT_ENABLED - fprintf( - stderr, "GetAlarmSummary: Reply too big to fit into APDU!\n"); -#endif + debug_print("GetAlarmSummary: Reply too big to fit into APDU!\n"); } else { apdu_len = bacerror_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, SERVICE_CONFIRMED_GET_ALARM_SUMMARY, ERROR_CLASS_PROPERTY, ERROR_CODE_OTHER); -#if PRINT_ENABLED - fprintf(stderr, "GetAlarmSummary: Sending Error!\n"); -#endif + debug_print("GetAlarmSummary: Sending Error!\n"); } } - GET_ALARM_SUMMARY_ABORT: pdu_len += apdu_len; bytes_sent = datalink_send_pdu( src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); -#if PRINT_ENABLED if (bytes_sent <= 0) { - /*fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); */ + debug_perror("GetAlarmSummary: Failed to send PDU"); } -#else - (void)bytes_sent; -#endif return; } diff --git a/src/bacnet/basic/service/h_getevent.c b/src/bacnet/basic/service/h_getevent.c index 8e0f6e78..c2b0be02 100644 --- a/src/bacnet/basic/service/h_getevent.c +++ b/src/bacnet/basic/service/h_getevent.c @@ -9,7 +9,6 @@ #include #include #include -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ @@ -18,17 +17,22 @@ #include "bacnet/apdu.h" #include "bacnet/npdu.h" #include "bacnet/abort.h" +#include "bacnet/reject.h" #include "bacnet/event.h" #include "bacnet/getevent.h" /* basic objects, services, TSM, and datalink */ #include "bacnet/basic/object/device.h" #include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/services.h" +#include "bacnet/basic/sys/debug.h" #include "bacnet/datalink/datalink.h" static get_event_info_function Get_Event_Info[MAX_BACNET_OBJECT_TYPE]; -/** print eventState +/** + * @brief print the data for a GetEventInformation service request + * @param data [in] The data to print + * @param device_id [in] The device id to print */ void ge_ack_print_data( BACNET_GET_EVENT_INFORMATION_DATA *data, uint32_t device_id) @@ -48,6 +52,11 @@ void ge_ack_print_data( printf("\n%u\t Total\n", count); } +/** + * @brief Set the handler for the GetEventInformation service. + * @param object_type [in] The BACNET_OBJECT_TYPE to set the handler for. + * @param pFunction [in] The handler function to set. + */ void handler_get_event_information_set( BACNET_OBJECT_TYPE object_type, get_event_info_function pFunction) { @@ -56,6 +65,19 @@ void handler_get_event_information_set( } } +/** + * @brief Handle a GetEventInformation service request. + * @details The GetEventInformation service is used by a client BACnet-user to + * obtain a summary of all "active event states". The term "active event states" + * refers to all event-initiating objects that have an Event_State property + * whose value is not equal to NORMAL, + * or have an Acked_Transitions property, which has at least one of the bits + * (TO-OFFNORMAL, TO-FAULT, TONORMAL) set to FALSE. + * @param service_request [in] The contents of the service request. + * @param service_len [in] The length of the service_request. + * @param src [in] BACNET_ADDRESS of the source of the message + * @param service_data [in] The BACNET_CONFIRMED_SERVICE_DATA information + */ void handler_get_event_information( uint8_t *service_request, uint16_t service_len, @@ -68,9 +90,7 @@ void handler_get_event_information( BACNET_NPDU_DATA npdu_data; bool error = false; bool more_events = false; -#if PRINT_ENABLED int bytes_sent = 0; -#endif BACNET_ERROR_CLASS error_class = ERROR_CLASS_OBJECT; BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT; BACNET_ADDRESS my_address; @@ -84,7 +104,7 @@ void handler_get_event_information( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); - npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); + npdu_encode_npdu_data(&npdu_data, false, service_data->priority); pdu_len = npdu_encode_pdu( &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); if (service_data->segmented_message) { @@ -92,15 +112,10 @@ void handler_get_event_information( len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); -#if PRINT_ENABLED - fprintf( - stderr, - "GetEventInformation: " - "Segmented message. Sending Abort!\n"); -#endif + debug_print("GetEventInformation: " + "Segmented message. Sending Abort!\n"); goto GET_EVENT_ABORT; } - len = getevent_decode_service_request( service_request, service_len, &object_id); if (len < 0) { @@ -108,9 +123,8 @@ void handler_get_event_information( len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_OTHER, true); -#if PRINT_ENABLED - fprintf(stderr, "GetEventInformation: Bad Encoding. Sending Abort!\n"); -#endif + debug_print("GetEventInformation: Bad Encoding. " + "Sending Abort!\n"); goto GET_EVENT_ABORT; } len = getevent_ack_encode_apdu_init( @@ -182,9 +196,7 @@ void handler_get_event_information( error = true; goto GET_EVENT_ERROR; } -#if PRINT_ENABLED - fprintf(stderr, "Got a GetEventInformation request: Sending Ack!\n"); -#endif + debug_print("Got a GetEventInformation request: Sending Ack!\n"); GET_EVENT_ERROR: if (error) { pdu_len = npdu_encode_pdu( @@ -195,33 +207,22 @@ GET_EVENT_ERROR: len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); -#if PRINT_ENABLED - fprintf( - stderr, - "GetEventInformation: " - "Reply too big to fit into APDU!\n"); -#endif + debug_print("GetEventInformation: " + "Reply too big to fit into APDU!\n"); } else { len = bacerror_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, SERVICE_CONFIRMED_READ_PROPERTY, error_class, error_code); -#if PRINT_ENABLED - fprintf(stderr, "GetEventInformation: Sending Error!\n"); -#endif + debug_print("GetEventInformation: Sending Error!\n"); } } GET_EVENT_ABORT: pdu_len += len; -#if PRINT_ENABLED - bytes_sent = -#endif - datalink_send_pdu( - src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); -#if PRINT_ENABLED + bytes_sent = datalink_send_pdu( + src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { - fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); + debug_perror("GetEventInformation: Failed to send PDU"); } -#endif return; } diff --git a/src/bacnet/basic/service/h_list_element.c b/src/bacnet/basic/service/h_list_element.c index 6d9d7c6a..c38ebc4b 100644 --- a/src/bacnet/basic/service/h_list_element.c +++ b/src/bacnet/basic/service/h_list_element.c @@ -9,7 +9,6 @@ #include #include #include -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ @@ -18,6 +17,7 @@ #include "bacnet/apdu.h" #include "bacnet/npdu.h" #include "bacnet/abort.h" +#include "bacnet/reject.h" #include "bacnet/list_element.h" /* basic objects, services, TSM, and datalink */ #include "bacnet/basic/object/device.h" @@ -59,15 +59,23 @@ void handler_add_list_element( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); - npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); + npdu_encode_npdu_data(&npdu_data, false, service_data->priority); pdu_len = npdu_encode_pdu( &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); - debug_perror("AddListElement: Received Request!\n"); - if (service_data->segmented_message) { + debug_print("AddListElement: Received Request!\n"); + if (service_len == 0) { + len = reject_encode_apdu( + &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, + REJECT_REASON_MISSING_REQUIRED_PARAMETER); + debug_print("AddListElement: Missing Required Parameter. " + "Sending Reject!\n"); + status = false; + } else if (service_data->segmented_message) { len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); - debug_perror("AddListElement: Segmented message. Sending Abort!\n"); + debug_print("AddListElement: Segmented message. " + "Sending Abort!\n"); status = false; } if (status) { @@ -75,7 +83,7 @@ void handler_add_list_element( len = list_element_decode_service_request( service_request, service_len, &list_element); if (len > 0) { - debug_perror( + debug_printf_stderr( "AddListElement: type=%lu instance=%lu property=%lu " "index=%ld\n", (unsigned long)list_element.object_type, @@ -83,14 +91,14 @@ void handler_add_list_element( (unsigned long)list_element.object_property, (long)list_element.array_index); } else { - debug_perror("AddListElement: Unable to decode request!\n"); + debug_print("AddListElement: Unable to decode request!\n"); } /* bad decoding or something we didn't understand - send an abort */ if (len <= 0) { len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_OTHER, true); - debug_perror("AddListElement: Bad Encoding. Sending Abort!\n"); + debug_print("AddListElement: Bad Encoding. Sending Abort!\n"); status = false; } if (status) { @@ -98,13 +106,13 @@ void handler_add_list_element( len = encode_simple_ack( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, SERVICE_CONFIRMED_ADD_LIST_ELEMENT); - debug_perror("AddListElement: Sending Simple Ack!\n"); + debug_print("AddListElement: Sending Simple Ack!\n"); } else { len = bacerror_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, SERVICE_CONFIRMED_ADD_LIST_ELEMENT, list_element.error_class, list_element.error_code); - debug_perror("AddListElement: Sending Error!\n"); + debug_print("AddListElement: Sending Error!\n"); } } } @@ -113,8 +121,7 @@ void handler_add_list_element( bytes_sent = datalink_send_pdu( src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { - debug_perror( - "AddListElement: Failed to send PDU (%s)!\n", strerror(errno)); + debug_perror("AddListElement: Failed to send PDU"); } return; @@ -153,15 +160,22 @@ void handler_remove_list_element( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); - npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); + npdu_encode_npdu_data(&npdu_data, false, service_data->priority); pdu_len = npdu_encode_pdu( &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); - debug_perror("RemoveListElement: Received Request!\n"); - if (service_data->segmented_message) { + debug_print("RemoveListElement: Received Request!\n"); + if (service_len == 0) { + len = reject_encode_apdu( + &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, + REJECT_REASON_MISSING_REQUIRED_PARAMETER); + debug_print("AddListElement: Missing Required Parameter. " + "Sending Reject!\n"); + status = false; + } else if (service_data->segmented_message) { len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); - debug_perror("RemoveListElement: Segmented message. Sending Abort!\n"); + debug_print("RemoveListElement: Segmented message. Sending Abort!\n"); status = false; } if (status) { @@ -169,7 +183,7 @@ void handler_remove_list_element( len = list_element_decode_service_request( service_request, service_len, &list_element); if (len > 0) { - debug_perror( + debug_printf_stderr( "RemoveListElement: type=%lu instance=%lu " "property=%lu index=%ld\n", (unsigned long)list_element.object_type, @@ -177,14 +191,14 @@ void handler_remove_list_element( (unsigned long)list_element.object_property, (long)list_element.array_index); } else { - debug_perror("RemoveListElement: Unable to decode request!\n"); + debug_print("RemoveListElement: Unable to decode request!\n"); } /* bad decoding or something we didn't understand - send an abort */ if (len <= 0) { len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_OTHER, true); - debug_perror("RemoveListElement: Bad Encoding. Sending Abort!\n"); + debug_print("RemoveListElement: Bad Encoding. Sending Abort!\n"); status = false; } if (status) { @@ -192,13 +206,13 @@ void handler_remove_list_element( len = encode_simple_ack( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, SERVICE_CONFIRMED_REMOVE_LIST_ELEMENT); - debug_perror("RemoveListElement: Sending Simple Ack!\n"); + debug_print("RemoveListElement: Sending Simple Ack!\n"); } else { len = bacerror_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, SERVICE_CONFIRMED_REMOVE_LIST_ELEMENT, list_element.error_class, list_element.error_code); - debug_perror("RemoveListElement: Sending Error!\n"); + debug_print("RemoveListElement: Sending Error!\n"); } } } @@ -207,8 +221,7 @@ void handler_remove_list_element( bytes_sent = datalink_send_pdu( src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { - debug_perror( - "RemoveListElement: Failed to send PDU (%s)!\n", strerror(errno)); + debug_perror("RemoveListElement: Failed to send PDU"); } return; diff --git a/src/bacnet/basic/service/h_lso.c b/src/bacnet/basic/service/h_lso.c index 89151a5a..cc356abc 100644 --- a/src/bacnet/basic/service/h_lso.c +++ b/src/bacnet/basic/service/h_lso.c @@ -9,7 +9,6 @@ #include #include #include -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ @@ -17,11 +16,13 @@ #include "bacnet/apdu.h" #include "bacnet/npdu.h" #include "bacnet/abort.h" +#include "bacnet/reject.h" #include "bacnet/lso.h" /* basic objects, services, TSM, and datalink */ #include "bacnet/basic/services.h" #include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/object/device.h" +#include "bacnet/basic/sys/debug.h" #include "bacnet/datalink/datalink.h" void handler_lso( @@ -34,82 +35,63 @@ void handler_lso( int len = 0; int pdu_len = 0; BACNET_NPDU_DATA npdu_data; -#if PRINT_ENABLED int bytes_sent = 0; -#endif BACNET_ADDRESS my_address; /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); - npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); + npdu_encode_npdu_data(&npdu_data, false, service_data->priority); pdu_len = npdu_encode_pdu( &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); - if (service_data->segmented_message) { + if (service_len == 0) { + len = reject_encode_apdu( + &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, + REJECT_REASON_MISSING_REQUIRED_PARAMETER); + debug_print("LSO: Missing Required Parameter. Sending Reject!\n"); + goto LSO_ABORT; + } else if (service_data->segmented_message) { /* we don't support segmentation - send an abort */ len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); -#if PRINT_ENABLED - fprintf(stderr, "LSO: Segmented message. Sending Abort!\n"); -#endif + debug_print("LSO: Segmented message. Sending Abort!\n"); goto LSO_ABORT; } len = lso_decode_service_request(service_request, service_len, &data); -#if PRINT_ENABLED if (len <= 0) { - fprintf(stderr, "LSO: Unable to decode Request!\n"); + debug_print("LSO: Unable to decode Request!\n"); } -#endif if (len < 0) { /* bad decoding - send an abort */ len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_OTHER, true); -#if PRINT_ENABLED - fprintf(stderr, "LSO: Bad Encoding. Sending Abort!\n"); -#endif + debug_print("LSO: Bad Encoding. Sending Abort!\n"); goto LSO_ABORT; } /* ** Process Life Safety Operation Here */ -#if PRINT_ENABLED - fprintf( + debug_fprintf( stderr, "Life Safety Operation: Received operation %d from process id %lu " "for object %lu\n", data.operation, (unsigned long)data.processId, (unsigned long)data.targetObject.instance); -#endif - len = encode_simple_ack( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, SERVICE_CONFIRMED_LIFE_SAFETY_OPERATION); -#if PRINT_ENABLED - fprintf( - stderr, - "Life Safety Operation: " - "Sending Simple Ack!\n"); -#endif - + debug_print("Life Safety Operation: " + "Sending Simple Ack!\n"); LSO_ABORT: pdu_len += len; -#if PRINT_ENABLED - bytes_sent = -#endif - datalink_send_pdu( - src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); -#if PRINT_ENABLED + bytes_sent = datalink_send_pdu( + src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { - fprintf( - stderr, - "Life Safety Operation: " - "Failed to send PDU (%s)!\n", - strerror(errno)); + debug_perror("Life Safety Operation: Failed to send PDU"); } -#endif return; } diff --git a/src/bacnet/basic/service/h_noserv.c b/src/bacnet/basic/service/h_noserv.c index 40713313..8e28b733 100644 --- a/src/bacnet/basic/service/h_noserv.c +++ b/src/bacnet/basic/service/h_noserv.c @@ -9,7 +9,6 @@ #include #include #include -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ @@ -21,6 +20,7 @@ #include "bacnet/basic/object/device.h" #include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/services.h" +#include "bacnet/basic/sys/debug.h" #include "bacnet/datalink/datalink.h" /** Handler to be invoked when a Service request is received for which no @@ -51,7 +51,7 @@ void handler_unrecognized_service( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); - npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); + npdu_encode_npdu_data(&npdu_data, false, service_data->priority); pdu_len = npdu_encode_pdu( &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); /* encode the APDU portion of the packet */ @@ -63,12 +63,8 @@ void handler_unrecognized_service( bytes_sent = datalink_send_pdu( src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent > 0) { -#if PRINT_ENABLED - fprintf(stderr, "Sent Reject!\n"); -#endif + debug_print("Sent Reject!\n"); } else { -#if PRINT_ENABLED - fprintf(stderr, "Failed to Send Reject (%s)!\n", strerror(errno)); -#endif + debug_perror("Failed to Send Reject"); } } diff --git a/src/bacnet/basic/service/h_rd.c b/src/bacnet/basic/service/h_rd.c index 9e987dc1..334a0453 100644 --- a/src/bacnet/basic/service/h_rd.c +++ b/src/bacnet/basic/service/h_rd.c @@ -9,7 +9,6 @@ #include #include #include -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ @@ -24,6 +23,7 @@ #include "bacnet/basic/object/device.h" #include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/services.h" +#include "bacnet/basic/sys/debug.h" #include "bacnet/datalink/datalink.h" /** Handler for a Reinitialize Device (RD) request. @@ -60,45 +60,42 @@ void handler_reinitialize_device( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); - npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); + npdu_encode_npdu_data(&npdu_data, false, service_data->priority); pdu_len = npdu_encode_pdu( &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); -#if PRINT_ENABLED - fprintf(stderr, "ReinitializeDevice!\n"); -#endif - if (service_data->segmented_message) { + debug_print("ReinitializeDevice!\n"); + if (service_len == 0) { + len = reject_encode_apdu( + &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, + REJECT_REASON_MISSING_REQUIRED_PARAMETER); + debug_print("ReinitializeDevice: Missing Required Parameter. " + "Sending Reject!\n"); + goto RD_ABORT; + } else if (service_data->segmented_message) { len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); -#if PRINT_ENABLED - fprintf( - stderr, "ReinitializeDevice: Sending Abort - segmented message.\n"); -#endif + debug_print("ReinitializeDevice: Sending Abort - segmented message.\n"); goto RD_ABORT; } /* decode the service request only */ len = rd_decode_service_request( service_request, service_len, &rd_data.state, &rd_data.password); -#if PRINT_ENABLED if (len > 0) { - fprintf( + debug_fprintf( stderr, "ReinitializeDevice: state=%u password=%*s\n", (unsigned)rd_data.state, (int)characterstring_length(&rd_data.password), characterstring_value(&rd_data.password)); } else { - fprintf(stderr, "ReinitializeDevice: Unable to decode request!\n"); + debug_print("ReinitializeDevice: Unable to decode request!\n"); } -#endif /* bad decoding or something we didn't understand - send an abort */ if (len < 0) { len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_OTHER, true); -#if PRINT_ENABLED - fprintf( - stderr, "ReinitializeDevice: Sending Abort - could not decode.\n"); -#endif + debug_print("ReinitializeDevice: Sending Abort - could not decode.\n"); goto RD_ABORT; } /* check the data from the request */ @@ -106,11 +103,8 @@ void handler_reinitialize_device( len = reject_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, REJECT_REASON_UNDEFINED_ENUMERATION); -#if PRINT_ENABLED - fprintf( - stderr, + debug_print( "ReinitializeDevice: Sending Reject - undefined enumeration\n"); -#endif } else { #ifdef BAC_ROUTING /* Check to see if the current Device supports this service. */ @@ -121,22 +115,17 @@ void handler_reinitialize_device( goto RD_ABORT; } #endif - if (Device_Reinitialize(&rd_data)) { len = encode_simple_ack( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, SERVICE_CONFIRMED_REINITIALIZE_DEVICE); -#if PRINT_ENABLED - fprintf(stderr, "ReinitializeDevice: Sending Simple Ack!\n"); -#endif + debug_print("ReinitializeDevice: Sending Simple Ack!\n"); } else { len = bacerror_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, SERVICE_CONFIRMED_REINITIALIZE_DEVICE, rd_data.error_class, rd_data.error_code); -#if PRINT_ENABLED - fprintf(stderr, "ReinitializeDevice: Sending Error.\n"); -#endif + debug_print("ReinitializeDevice: Sending Error.\n"); } } RD_ABORT: @@ -144,11 +133,7 @@ RD_ABORT: len = datalink_send_pdu( src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (len <= 0) { -#if PRINT_ENABLED - fprintf( - stderr, "ReinitializeDevice: Failed to send PDU (%s)!\n", - strerror(errno)); -#endif + debug_perror("ReinitializeDevice: Failed to send PDU"); } return; diff --git a/src/bacnet/basic/service/h_rp.c b/src/bacnet/basic/service/h_rp.c index 7d75d178..e42f126b 100644 --- a/src/bacnet/basic/service/h_rp.c +++ b/src/bacnet/basic/service/h_rp.c @@ -9,7 +9,6 @@ #include #include #include -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ @@ -28,6 +27,7 @@ #endif #include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/services.h" +#include "bacnet/basic/sys/debug.h" #include "bacnet/datalink/datalink.h" /** @file h_rp.c Handles Read Property requests. */ @@ -77,28 +77,19 @@ void handler_read_property( if (npdu_len <= 0) { /* If 0 or negative, there were problems with the data or encoding. */ len = BACNET_STATUS_ABORT; -#if PRINT_ENABLED - fprintf(stderr, "RP: npdu_encode_pdu error. Sending Abort!\n"); -#endif + debug_print("RP: npdu_encode_pdu error. Sending Abort!\n"); + } else if (service_len == 0) { + len = BACNET_STATUS_REJECT; + rpdata.error_code = ERROR_CODE_REJECT_MISSING_REQUIRED_PARAMETER; + debug_print("RP: Missing Required Parameter. Sending Reject!\n"); } else if (service_data->segmented_message) { /* we don't support segmentation - send an abort */ len = BACNET_STATUS_ABORT; -#if PRINT_ENABLED - fprintf(stderr, "RP: Segmented message. Sending Abort!\n"); -#endif + debug_print("RP: Segmented message. Sending Abort!\n"); } else { len = rp_decode_service_request(service_request, service_len, &rpdata); -#if PRINT_ENABLED if (len <= 0) { - fprintf(stderr, "RP: Unable to decode Request!\n"); - } -#endif - if (len < 0) { - /* bad decoding - skip to error/reject/abort handling */ - error = true; -#if PRINT_ENABLED - fprintf(stderr, "RP: Bad Encoding.\n"); -#endif + debug_print("RP: Unable to decode Request!\n"); } else { /* When the object-type in the Object Identifier parameter contains the value DEVICE and the instance in the 'Object @@ -147,65 +138,49 @@ void handler_read_property( rpdata.error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED; len = BACNET_STATUS_ABORT; -#if PRINT_ENABLED - fprintf(stderr, "RP: Message too large.\n"); -#endif + debug_print("RP: Message too large.\n"); } else { -#if PRINT_ENABLED - fprintf(stderr, "RP: Sending Ack!\n"); -#endif + debug_print("RP: Sending Ack!\n"); error = false; } } else { -#if PRINT_ENABLED - fprintf(stderr, "RP: Device_Read_Property: "); + debug_print("RP: Device_Read_Property: "); if (len == BACNET_STATUS_ABORT) { - fprintf(stderr, "Abort!\n"); + debug_print("Abort!\n"); } else if (len == BACNET_STATUS_ERROR) { - fprintf(stderr, "Error!\n"); + debug_print("Error!\n"); } else if (len == BACNET_STATUS_REJECT) { - fprintf(stderr, "Reject!\n"); + debug_print("Reject!\n"); } else { - fprintf(stderr, "Unknown Len=%d\n", len); + debug_print("Unknown Len!\n"); } -#endif } } } - if (error) { if (len == BACNET_STATUS_ABORT) { apdu_len = abort_encode_apdu( &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, abort_convert_error_code(rpdata.error_code), true); -#if PRINT_ENABLED - fprintf(stderr, "RP: Sending Abort!\n"); -#endif + debug_print("RP: Sending Abort!\n"); } else if (len == BACNET_STATUS_ERROR) { apdu_len = bacerror_encode_apdu( &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, SERVICE_CONFIRMED_READ_PROPERTY, rpdata.error_class, rpdata.error_code); -#if PRINT_ENABLED - fprintf(stderr, "RP: Sending Error!\n"); -#endif + debug_print("RP: Sending Error!\n"); } else if (len == BACNET_STATUS_REJECT) { apdu_len = reject_encode_apdu( &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, reject_convert_error_code(rpdata.error_code)); -#if PRINT_ENABLED - fprintf(stderr, "RP: Sending Reject!\n"); -#endif + debug_print("RP: Sending Reject!\n"); } } - pdu_len = npdu_len + apdu_len; bytes_sent = datalink_send_pdu( src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { -#if PRINT_ENABLED - fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); -#endif + debug_perror("RP: Failed to send PDU"); } return; diff --git a/src/bacnet/basic/service/h_rp_a.c b/src/bacnet/basic/service/h_rp_a.c index 567a0707..e733bc30 100644 --- a/src/bacnet/basic/service/h_rp_a.c +++ b/src/bacnet/basic/service/h_rp_a.c @@ -24,8 +24,8 @@ #include "bacnet/basic/sys/debug.h" #include "bacnet/datalink/datalink.h" -#define PRINTF debug_aprintf -#define PRINTF_ERR debug_perror +#define PRINTF debug_printf_stdout +#define PRINTF_ERR debug_printf_stderr /** For debugging... * @param [in] data portion of the ACK diff --git a/src/bacnet/basic/service/h_rpm.c b/src/bacnet/basic/service/h_rpm.c index e1d3df6a..31b91786 100644 --- a/src/bacnet/basic/service/h_rpm.c +++ b/src/bacnet/basic/service/h_rpm.c @@ -12,7 +12,6 @@ #include #include #include -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ @@ -220,20 +219,19 @@ void handler_read_property_multiple( int npdu_len = 0; int error = 0; - if (service_data && (service_len > 0)) { - /* jps_debug - see if we are utilizing all the buffer */ - /* memset(&Handler_Transmit_Buffer[0], 0xff, - * sizeof(Handler_Transmit_Buffer)); */ - /* encode the NPDU portion of the packet */ + if (service_data) { datalink_get_my_address(&my_address); - npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); + npdu_encode_npdu_data(&npdu_data, false, service_data->priority); npdu_len = npdu_encode_pdu( &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); - - if (service_data->segmented_message) { + if (service_len == 0) { + rpmdata.error_code = ERROR_CODE_REJECT_MISSING_REQUIRED_PARAMETER; + error = BACNET_STATUS_REJECT; + debug_print("RPM: Missing Required Parameter. Sending Reject!\n"); + } else if (service_data->segmented_message) { rpmdata.error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED; error = BACNET_STATUS_ABORT; - debug_fprintf(stderr, "RPM: Segmented message. Sending Abort!\r\n"); + debug_print("RPM: Segmented message. Sending Abort!\r\n"); } else { /* decode apdu request & encode apdu reply encode complex ack, invoke id, service choice */ @@ -250,8 +248,10 @@ void handler_read_property_multiple( decode_len += len; } else { /* bad encoding - skip to error/reject/abort handling */ - debug_fprintf(stderr, "RPM: Bad Encoding.\n"); + debug_print("RPM: Bad Encoding.\n"); error = len; + /* The berror flag ensures that + both loops will be broken! */ berror = true; break; } @@ -276,21 +276,19 @@ void handler_read_property_multiple( rpmdata.object_instance = Network_Port_Index_To_Instance(0); } #endif - /* Stick this object id into the reply - if it will fit */ len = rpm_ack_encode_apdu_object_begin(&Temp_Buf[0], &rpmdata); copy_len = memcopy( &Handler_Transmit_Buffer[npdu_len], &Temp_Buf[0], apdu_len, len, MAX_APDU); if (copy_len == 0) { - debug_fprintf(stderr, "RPM: Response too big!\r\n"); + debug_print("RPM: Response too big!\n"); rpmdata.error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED; error = BACNET_STATUS_ABORT; berror = true; break; } - apdu_len += copy_len; /* do each property of this object of the RPM request */ for (;;) { @@ -300,12 +298,12 @@ void handler_read_property_multiple( &rpmdata); if (len < 0) { /* bad encoding - skip to error/reject/abort handling */ - debug_fprintf(stderr, "RPM: Bad Encoding.\n"); + debug_print("RPM: Bad Encoding.\n"); error = len; + /* The berror flag ensures that + both loops will be broken! */ berror = true; - break; /* The berror flag ensures that both loops will - */ - /* be broken! */ + break; } decode_len += len; /* handle the special properties */ @@ -325,8 +323,7 @@ void handler_read_property_multiple( if (len > 0) { apdu_len += len; } else { - debug_fprintf( - stderr, "RPM: Too full for property!\r\n"); + debug_print("RPM: Too full for property!\n"); error = len; /* The berror flag ensures that both loops will be broken! */ @@ -345,15 +342,15 @@ void handler_read_property_multiple( &Temp_Buf[0], apdu_len, len, MAX_APDU); if (copy_len == 0) { - debug_fprintf( - stderr, - "RPM: Too full to encode property!\r\n"); + debug_print( + "RPM: Too full to encode property!\n"); rpmdata.error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED; error = BACNET_STATUS_ABORT; + /* The berror flag ensures that + both loops will be broken! */ berror = true; - break; /* The berror flag ensures that both */ - /* loops will be broken! */ + break; } apdu_len += len; @@ -366,15 +363,14 @@ void handler_read_property_multiple( &Temp_Buf[0], apdu_len, len, MAX_APDU); if (copy_len == 0) { - debug_fprintf( - stderr, - "RPM: Too full to encode error!\r\n"); + debug_print("RPM: Too full to encode error!\n"); rpmdata.error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED; error = BACNET_STATUS_ABORT; + /* The berror flag ensures that + both loops will be broken! */ berror = true; - break; /* The berror flag ensures that both */ - /* loops will be broken! */ + break; } apdu_len += len; } else { @@ -386,8 +382,7 @@ void handler_read_property_multiple( &property_list, special_object_property); if (property_count == 0) { - /* This only happens with the OPTIONAL property - */ + /* Only happens with the OPTIONAL property */ /* 135-2016bl-2. Clarify ReadPropertyMultiple response on OPTIONAL when empty. */ /* If no optional properties are supported then @@ -403,9 +398,8 @@ void handler_read_property_multiple( if (len > 0) { apdu_len += len; } else { - debug_fprintf( - stderr, - "RPM: Too full for property!\r\n"); + debug_print( + "RPM: Too full for property!\n"); error = len; /* The berror flag ensures that both loops will be broken! */ @@ -426,14 +420,13 @@ void handler_read_property_multiple( if (len > 0) { apdu_len += len; } else { - debug_fprintf( - stderr, - "RPM: Too full for property!\r\n"); + debug_print( + "RPM: Too full for property!\n"); error = len; + /* The berror flag ensures that + both loops will be broken! */ berror = true; - break; /* The berror flag ensures that - */ - /* both loops will be broken! */ + break; } } } @@ -446,13 +439,13 @@ void handler_read_property_multiple( if (len > 0) { apdu_len += len; } else { - debug_fprintf( - stderr, - "RPM: Too full for individual property!\r\n"); + debug_print( + "RPM: Too full for individual property!\n"); error = len; + /* The berror flag ensures that + both loops will be broken! */ berror = true; - break; /* The berror flag ensures that both loops */ - /* will be broken! */ + break; } } @@ -466,21 +459,22 @@ void handler_read_property_multiple( &Handler_Transmit_Buffer[npdu_len], &Temp_Buf[0], apdu_len, len, MAX_APDU); if (copy_len == 0) { - debug_fprintf( - stderr, - "RPM: Too full to encode object end!\r\n"); + debug_print( + "RPM: Too full to encode object end!\n"); rpmdata.error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED; error = BACNET_STATUS_ABORT; + /* The berror flag ensures that + both loops will be broken! */ berror = true; - break; /* The berror flag ensures that both loops */ - /* will be broken! */ + break; } else { apdu_len += copy_len; } - break; /* finished with this property list */ + /* finished with this property list */ + break; } - } /* for(;;) */ + } if (berror) { break; } @@ -488,8 +482,7 @@ void handler_read_property_multiple( /* Reached the end so finish up */ break; } - } /* for(;;) */ - + } /* If not having an error so far, check the remaining space. */ if (!berror) { if (apdu_len > service_data->max_resp) { @@ -497,39 +490,35 @@ void handler_read_property_multiple( rpmdata.error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED; error = BACNET_STATUS_ABORT; - debug_fprintf( - stderr, "RPM: Message too large. Sending Abort!\n"); + debug_print("RPM: Message too large. Sending Abort!\n"); } } } - /* Error fallback. */ if (error) { if (error == BACNET_STATUS_ABORT) { apdu_len = abort_encode_apdu( &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, abort_convert_error_code(rpmdata.error_code), true); - debug_fprintf(stderr, "RPM: Sending Abort!\n"); + debug_print("RPM: Sending Abort!\n"); } else if (error == BACNET_STATUS_ERROR) { apdu_len = bacerror_encode_apdu( &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, SERVICE_CONFIRMED_READ_PROP_MULTIPLE, rpmdata.error_class, rpmdata.error_code); - debug_fprintf(stderr, "RPM: Sending Error!\n"); + debug_print("RPM: Sending Error!\n"); } else if (error == BACNET_STATUS_REJECT) { apdu_len = reject_encode_apdu( &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, reject_convert_error_code(rpmdata.error_code)); - debug_fprintf(stderr, "RPM: Sending Reject!\n"); + debug_print("RPM: Sending Reject!\n"); } } - pdu_len = apdu_len + npdu_len; bytes_sent = datalink_send_pdu( src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { - debug_fprintf( - stderr, "RPM: Failed to send PDU (errno=%d)!\n", errno); + debug_perror("RPM: Failed to send PDU"); } } } diff --git a/src/bacnet/basic/service/h_rpm_a.c b/src/bacnet/basic/service/h_rpm_a.c index 525a8910..b7ada77a 100644 --- a/src/bacnet/basic/service/h_rpm_a.c +++ b/src/bacnet/basic/service/h_rpm_a.c @@ -1,10 +1,10 @@ -/************************************************************************** - * - * Copyright (C) 2008 Steve Karg - * - * SPDX-License-Identifier: MIT - * - *********************************************************************/ +/** + * @file + * @brief A basic ReadPropertyMultile-Ack service handler + * @author Steve Karg + * @date 2008 + * @copyright SPDX-License-Identifier: MIT + */ #include #include #include @@ -24,10 +24,8 @@ #include "bacnet/basic/tsm/tsm.h" #include "bacnet/datalink/datalink.h" -#define PRINTF debug_aprintf -#define PERROR debug_perror - -/** @file h_rpm_a.c Handles Read Property Multiple Acknowledgments. */ +#define PRINTF debug_printf_stdout +#define PERROR debug_printf_stderr /** Decode the received RPM data and make a linked list of the results. * @ingroup DSRPM diff --git a/src/bacnet/basic/service/h_rr.c b/src/bacnet/basic/service/h_rr.c index bbad1e30..d2aa92db 100644 --- a/src/bacnet/basic/service/h_rr.c +++ b/src/bacnet/basic/service/h_rr.c @@ -1,15 +1,14 @@ -/************************************************************************** - * - * Copyright (C) 2009 Steve Karg - * - * SPDX-License-Identifier: MIT - * - *********************************************************************/ +/** + * @file + * @brief Handles ReadRange-Request service + * @author Peter Mc Shane + * @date 2009 + * @copyright SPDX-License-Identifier: MIT + */ #include #include #include #include -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ @@ -18,15 +17,15 @@ #include "bacnet/apdu.h" #include "bacnet/npdu.h" #include "bacnet/abort.h" +#include "bacnet/reject.h" #include "bacnet/readrange.h" /* basic objects, services, TSM, and datalink */ #include "bacnet/basic/object/device.h" #include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/services.h" +#include "bacnet/basic/sys/debug.h" #include "bacnet/datalink/datalink.h" -/** @file h_rr.c Handles Read Range requests. */ - static uint8_t Temp_Buf[MAX_APDU] = { 0 }; /** @@ -116,42 +115,39 @@ void handler_read_range( int pdu_len = 0; BACNET_NPDU_DATA npdu_data; bool error = false; -#if PRINT_ENABLED int bytes_sent = 0; -#endif BACNET_ADDRESS my_address; data.error_class = ERROR_CLASS_OBJECT; data.error_code = ERROR_CODE_UNKNOWN_OBJECT; /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); - npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); + npdu_encode_npdu_data(&npdu_data, false, service_data->priority); pdu_len = npdu_encode_pdu( &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); - if (service_data->segmented_message) { + if (service_len == 0) { + len = reject_encode_apdu( + &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, + REJECT_REASON_MISSING_REQUIRED_PARAMETER); + debug_print("RR: Missing Required Parameter. Sending Reject!\n"); + } else if (service_data->segmented_message) { /* we don't support segmentation - send an abort */ len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); -#if PRINT_ENABLED - fprintf(stderr, "RR: Segmented message. Sending Abort!\n"); -#endif + debug_print("RR: Segmented message. Sending Abort!\n"); } else { memset(&data, 0, sizeof(data)); /* start with blank canvas */ len = rr_decode_service_request(service_request, service_len, &data); -#if PRINT_ENABLED if (len <= 0) { - fprintf(stderr, "RR: Unable to decode Request!\n"); + debug_print("RR: Unable to decode Request!\n"); } -#endif if (len < 0) { /* bad decoding - send an abort */ len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_OTHER, true); -#if PRINT_ENABLED - fprintf(stderr, "RR: Bad Encoding. Sending Abort!\n"); -#endif + debug_print("RR: Bad Encoding. Sending Abort!\n"); } else { /* assume that there is an error */ error = true; @@ -164,9 +160,7 @@ void handler_read_range( len = rr_ack_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, &data); -#if PRINT_ENABLED - fprintf(stderr, "RR: Sending Ack!\n"); -#endif + debug_print("RR: Sending Ack!\n"); error = false; } if (error) { @@ -177,33 +171,24 @@ void handler_read_range( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); -#if PRINT_ENABLED - fprintf(stderr, "RR: Reply too big to fit into APDU!\n"); -#endif + debug_print("RR: Reply too big to fit into APDU!\n"); } else { len = bacerror_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, SERVICE_CONFIRMED_READ_RANGE, data.error_class, data.error_code); -#if PRINT_ENABLED - fprintf(stderr, "RR: Sending Error!\n"); -#endif + debug_print("RR: Sending Error!\n"); } } } } pdu_len += len; -#if PRINT_ENABLED - bytes_sent = -#endif - datalink_send_pdu( - src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); -#if PRINT_ENABLED + bytes_sent = datalink_send_pdu( + src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { - fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); + debug_perror("RR: Failed to send PDU"); } -#endif return; } diff --git a/src/bacnet/basic/service/h_ucov.c b/src/bacnet/basic/service/h_ucov.c index e32b576d..92ea9a31 100644 --- a/src/bacnet/basic/service/h_ucov.c +++ b/src/bacnet/basic/service/h_ucov.c @@ -1,15 +1,14 @@ -/************************************************************************** - * - * Copyright (C) 2008 Steve Karg - * - * SPDX-License-Identifier: MIT - * - *********************************************************************/ +/** + * @file + * @brief Handles Unconfirmed COV Notifications. + * @author Steve Karg + * @date December 2010 + * @copyright SPDX-License-Identifier: MIT + */ #include #include #include #include -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ @@ -23,9 +22,6 @@ #include "bacnet/basic/sys/debug.h" #include "bacnet/basic/tsm/tsm.h" -/** @file h_ucov.c Handles Unconfirmed COV Notifications. */ -#define PRINTF debug_perror - #ifndef MAX_COV_PROPERTIES #define MAX_COV_PROPERTIES 2 #endif @@ -72,6 +68,41 @@ void handler_ucov_notification_add(BACNET_COV_NOTIFICATION *cb) } while (head); } +/** + * @brief Print the UnconfirmedCOV data + * @param cov_data - data decoded from the COV notification + */ +void handler_ucov_data_print(BACNET_COV_DATA *cov_data) +{ + BACNET_PROPERTY_VALUE *pProperty_value = NULL; + + debug_printf_stderr("UCOV: PID=%u ", cov_data->subscriberProcessIdentifier); + debug_printf_stderr("instance=%u ", cov_data->initiatingDeviceIdentifier); + debug_printf_stderr( + "%s %u ", + bactext_object_type_name(cov_data->monitoredObjectIdentifier.type), + cov_data->monitoredObjectIdentifier.instance); + debug_printf_stderr("time remaining=%u seconds ", cov_data->timeRemaining); + debug_printf_stderr("\n"); + pProperty_value = cov_data->listOfValues; + while (pProperty_value) { + debug_printf_stderr("UCOV: "); + if (pProperty_value->propertyIdentifier < 512) { + debug_printf_stderr( + "%s ", + bactext_property_name(pProperty_value->propertyIdentifier)); + } else { + debug_printf_stderr( + "proprietary %u ", pProperty_value->propertyIdentifier); + } + if (pProperty_value->propertyArrayIndex != BACNET_ARRAY_ALL) { + debug_printf_stderr("%u ", pProperty_value->propertyArrayIndex); + } + debug_printf_stderr("\n"); + pProperty_value = pProperty_value->next; + } +} + /* */ /** Handler for an Unconfirmed COV Notification. * @ingroup DSCOV @@ -89,7 +120,6 @@ void handler_ucov_notification( { BACNET_COV_DATA cov_data; BACNET_PROPERTY_VALUE property_value[MAX_COV_PROPERTIES]; - BACNET_PROPERTY_VALUE *pProperty_value = NULL; int len = 0; /* src not needed for this application */ @@ -98,37 +128,13 @@ void handler_ucov_notification( than one property value is expected */ bacapp_property_value_list_init(&property_value[0], MAX_COV_PROPERTIES); cov_data.listOfValues = &property_value[0]; - PRINTF("UCOV: Received Notification!\n"); + debug_print("UCOV: Received Notification!\n"); /* decode the service request only */ len = cov_notify_decode_service_request( service_request, service_len, &cov_data); if (len > 0) { handler_ucov_notification_callback(&cov_data); - PRINTF("UCOV: PID=%u ", cov_data.subscriberProcessIdentifier); - PRINTF("instance=%u ", cov_data.initiatingDeviceIdentifier); - PRINTF( - "%s %u ", - bactext_object_type_name(cov_data.monitoredObjectIdentifier.type), - cov_data.monitoredObjectIdentifier.instance); - PRINTF("time remaining=%u seconds ", cov_data.timeRemaining); - PRINTF("\n"); - pProperty_value = &property_value[0]; - while (pProperty_value) { - PRINTF("UCOV: "); - if (pProperty_value->propertyIdentifier < 512) { - PRINTF( - "%s ", - bactext_property_name(pProperty_value->propertyIdentifier)); - } else { - PRINTF("proprietary %u ", pProperty_value->propertyIdentifier); - } - if (pProperty_value->propertyArrayIndex != BACNET_ARRAY_ALL) { - PRINTF("%u ", pProperty_value->propertyArrayIndex); - } - PRINTF("\n"); - pProperty_value = pProperty_value->next; - } } else { - PRINTF("UCOV: Unable to decode service request!\n"); + debug_print("UCOV: Unable to decode service request!\n"); } } diff --git a/src/bacnet/basic/service/h_ucov.h b/src/bacnet/basic/service/h_ucov.h index 9e8d306a..a2e5e10a 100644 --- a/src/bacnet/basic/service/h_ucov.h +++ b/src/bacnet/basic/service/h_ucov.h @@ -27,6 +27,9 @@ extern "C" { BACNET_STACK_EXPORT void handler_ucov_notification_add(BACNET_COV_NOTIFICATION *callback); +BACNET_STACK_EXPORT +void handler_ucov_data_print(BACNET_COV_DATA *cov_data); + BACNET_STACK_EXPORT void handler_ucov_notification( uint8_t *service_request, uint16_t service_len, BACNET_ADDRESS *src); diff --git a/src/bacnet/basic/service/h_upt.c b/src/bacnet/basic/service/h_upt.c index 08e0fd6e..15f285f9 100644 --- a/src/bacnet/basic/service/h_upt.c +++ b/src/bacnet/basic/service/h_upt.c @@ -9,7 +9,6 @@ #include #include #include -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ diff --git a/src/bacnet/basic/service/h_whohas.c b/src/bacnet/basic/service/h_whohas.c index 558f3e79..276678d2 100644 --- a/src/bacnet/basic/service/h_whohas.c +++ b/src/bacnet/basic/service/h_whohas.c @@ -9,7 +9,6 @@ #include #include #include -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ diff --git a/src/bacnet/basic/service/h_whois.c b/src/bacnet/basic/service/h_whois.c index 77057065..42adab4d 100644 --- a/src/bacnet/basic/service/h_whois.c +++ b/src/bacnet/basic/service/h_whois.c @@ -9,7 +9,6 @@ #include #include #include -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ diff --git a/src/bacnet/basic/service/h_wp.c b/src/bacnet/basic/service/h_wp.c index 215b74f0..5c32a754 100644 --- a/src/bacnet/basic/service/h_wp.c +++ b/src/bacnet/basic/service/h_wp.c @@ -9,7 +9,6 @@ #include #include #include -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ @@ -18,11 +17,13 @@ #include "bacnet/apdu.h" #include "bacnet/npdu.h" #include "bacnet/abort.h" +#include "bacnet/reject.h" #include "bacnet/wp.h" /* basic objects, services, TSM, and datalink */ #include "bacnet/basic/object/device.h" #include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/services.h" +#include "bacnet/basic/sys/debug.h" #include "bacnet/datalink/datalink.h" /** @file h_wp.c Handles Write Property requests. */ @@ -61,28 +62,28 @@ void handler_write_property( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); - npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); + npdu_encode_npdu_data(&npdu_data, false, service_data->priority); pdu_len = npdu_encode_pdu( &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); -#if PRINT_ENABLED - fprintf(stderr, "WP: Received Request!\n"); -#endif - if (service_data->segmented_message) { + debug_print("WP: Received Request!\n"); + if (service_len == 0) { + len = reject_encode_apdu( + &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, + REJECT_REASON_MISSING_REQUIRED_PARAMETER); + debug_print("WP: Missing Required Parameter. Sending Reject!\n"); + bcontinue = false; + } else if (service_data->segmented_message) { len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); -#if PRINT_ENABLED - fprintf(stderr, "WP: Segmented message. Sending Abort!\n"); -#endif + debug_print("WP: Segmented message. Sending Abort!\n"); bcontinue = false; } - if (bcontinue) { /* decode the service request only */ len = wp_decode_service_request(service_request, service_len, &wp_data); -#if PRINT_ENABLED if (len > 0) { - fprintf( + debug_fprintf( stderr, "WP: type=%lu instance=%lu property=%lu priority=%lu " "index=%ld\n", @@ -91,48 +92,37 @@ void handler_write_property( (unsigned long)wp_data.object_property, (unsigned long)wp_data.priority, (long)wp_data.array_index); } else { - fprintf(stderr, "WP: Unable to decode Request!\n"); + debug_print("WP: Unable to decode Request!\n"); } -#endif /* bad decoding or something we didn't understand - send an abort */ if (len <= 0) { len = abort_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_OTHER, true); -#if PRINT_ENABLED - fprintf(stderr, "WP: Bad Encoding. Sending Abort!\n"); -#endif + debug_print("WP: Bad Encoding. Sending Abort!\n"); bcontinue = false; } - if (bcontinue) { if (Device_Write_Property(&wp_data)) { len = encode_simple_ack( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY); -#if PRINT_ENABLED - fprintf(stderr, "WP: Sending Simple Ack!\n"); -#endif + debug_print("WP: Sending Simple Ack!\n"); } else { len = bacerror_encode_apdu( &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY, wp_data.error_class, wp_data.error_code); -#if PRINT_ENABLED - fprintf(stderr, "WP: Sending Error!\n"); -#endif + debug_print("WP: Sending Error!\n"); } } } - /* Send PDU */ pdu_len += len; bytes_sent = datalink_send_pdu( src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { -#if PRINT_ENABLED - fprintf(stderr, "WP: Failed to send PDU (%s)!\n", strerror(errno)); -#endif + debug_perror("WP: Failed to send PDU"); } return; diff --git a/src/bacnet/basic/service/h_wpm.c b/src/bacnet/basic/service/h_wpm.c index 42744fe0..b2e00798 100644 --- a/src/bacnet/basic/service/h_wpm.c +++ b/src/bacnet/basic/service/h_wpm.c @@ -1,15 +1,14 @@ -/************************************************************************** - * - * Copyright (C) 2011 Krzysztof Malorny - * - * SPDX-License-Identifier: MIT - * - *********************************************************************/ +/** + * @file + * @brief Handles WritePropertyMultiple-Request service + * @author Krzysztof Malorny + * @date 2011 + * @copyright SPDX-License-Identifier: MIT + */ #include #include #include #include -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ @@ -28,9 +27,6 @@ #include "bacnet/basic/sys/debug.h" #include "bacnet/datalink/datalink.h" -/** @file h_wpm.c Handles Write Property Multiple requests. */ -#define PRINTF debug_perror - /** Decoding for an object property. * * @param apdu [in] The contents of the APDU buffer. @@ -68,7 +64,7 @@ static int write_property_multiple_decode( &apdu[offset], apdu_len - offset, wp_data); if (len > 0) { offset += len; - PRINTF( + debug_printf_stderr( "WPM: type=%lu instance=%lu property=%lu " "priority=%lu index=%ld\n", (unsigned long)wp_data->object_type, @@ -91,7 +87,7 @@ static int write_property_multiple_decode( } } } else { - PRINTF("WPM: Bad Encoding!\n"); + debug_printf_stderr("WPM: Bad Encoding!\n"); return len; } /* Closing tag 1 - List of Properties */ @@ -106,7 +102,7 @@ static int write_property_multiple_decode( } while (tag_number != 1); } } else { - PRINTF("WPM: Bad Encoding!\n"); + debug_printf_stderr("WPM: Bad Encoding!\n"); return len; } } while (offset < apdu_len); @@ -146,10 +142,16 @@ void handler_write_property_multiple( BACNET_ADDRESS my_address; int bytes_sent = 0; - if (service_data->segmented_message) { + if (service_len == 0) { + wp_data.error_code = ERROR_CODE_REJECT_MISSING_REQUIRED_PARAMETER; + len = BACNET_STATUS_REJECT; + debug_print("WPM: Missing Required Parameter. " + "Sending Reject!\n"); + } else if (service_data->segmented_message) { wp_data.error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED; len = BACNET_STATUS_ABORT; - PRINTF("WPM: Segmented message. Sending Abort!\n"); + debug_print("WPM: Segmented message. " + "Sending Abort!\n"); } else { /* first time - detect malformed request before writing any data */ len = write_property_multiple_decode( @@ -161,36 +163,36 @@ void handler_write_property_multiple( } /* encode the confirmed reply */ datalink_get_my_address(&my_address); - npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); + npdu_encode_npdu_data(&npdu_data, false, service_data->priority); npdu_len = npdu_encode_pdu( &Handler_Transmit_Buffer[0], src, &my_address, &npdu_data); if (len > 0) { apdu_len = wpm_ack_encode_apdu_init( &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id); - PRINTF("WPM: Sending Ack!\n"); + debug_print("WPM: Sending Ack!\n"); } else { /* handle any errors */ if (len == BACNET_STATUS_ABORT) { apdu_len = abort_encode_apdu( &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, abort_convert_error_code(wp_data.error_code), true); - PRINTF("WPM: Sending Abort!\n"); + debug_print("WPM: Sending Abort!\n"); } else if (len == BACNET_STATUS_ERROR) { apdu_len = wpm_error_ack_encode_apdu( &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, &wp_data); - PRINTF("WPM: Sending Error!\n"); + debug_print("WPM: Sending Error!\n"); } else if (len == BACNET_STATUS_REJECT) { apdu_len = reject_encode_apdu( &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, reject_convert_error_code(wp_data.error_code)); - PRINTF("WPM: Sending Reject!\n"); + debug_print("WPM: Sending Reject!\n"); } } pdu_len = npdu_len + apdu_len; bytes_sent = datalink_send_pdu( src, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { - PRINTF("Failed to send PDU (%s)!\n", strerror(errno)); + debug_perror("WPM: Failed to send PDU"); } } diff --git a/src/bacnet/basic/service/h_write_group.c b/src/bacnet/basic/service/h_write_group.c index 9b0c3485..8dda05ca 100644 --- a/src/bacnet/basic/service/h_write_group.c +++ b/src/bacnet/basic/service/h_write_group.c @@ -9,7 +9,6 @@ #include #include #include -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ diff --git a/src/bacnet/basic/service/s_abort.c b/src/bacnet/basic/service/s_abort.c index 314a158d..94065fb0 100644 --- a/src/bacnet/basic/service/s_abort.c +++ b/src/bacnet/basic/service/s_abort.c @@ -7,7 +7,6 @@ *********************************************************************/ #include #include -#include #include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" diff --git a/src/bacnet/basic/service/s_ack_alarm.c b/src/bacnet/basic/service/s_ack_alarm.c index dd1dc0e7..3bcb6bae 100644 --- a/src/bacnet/basic/service/s_ack_alarm.c +++ b/src/bacnet/basic/service/s_ack_alarm.c @@ -1,13 +1,12 @@ -/************************************************************************** - * - * Copyright (C) 2009 John Minack - * - * SPDX-License-Identifier: MIT - * - *********************************************************************/ +/** + * @file + * @brief Send an Alarm Acknowledgment. + * @author John Minack + * @date 2009 + * @copyright SPDX-License-Identifier: MIT + */ #include #include -#include #include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" @@ -26,9 +25,6 @@ #include "bacnet/basic/tsm/tsm.h" #include "bacnet/datalink/datalink.h" -/** @file s_ack_alarm.c Send an Alarm Acknowledgment. */ -#define PRINTF debug_perror - /** Sends an Confirmed Alarm Acknowledgment. * * @param pdu [in] the PDU buffer used for sending the message @@ -78,15 +74,13 @@ uint8_t Send_Alarm_Acknowledgement_Address( invoke_id, dest, &npdu_data, pdu, (uint16_t)pdu_len); bytes_sent = datalink_send_pdu(dest, &npdu_data, pdu, pdu_len); if (bytes_sent <= 0) { - PRINTF( - "Failed to Send Alarm Ack Request (%s)!\n", - strerror(errno)); + debug_perror("Failed to Send Alarm Ack Request"); } } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; - PRINTF("Failed to Send Alarm Ack Request " - "(exceeds destination maximum APDU)!\n"); + debug_printf_stderr("Failed to Send Alarm Ack Request " + "(exceeds destination maximum APDU)!\n"); } } diff --git a/src/bacnet/basic/service/s_arfs.c b/src/bacnet/basic/service/s_arfs.c index a4f60699..5f4c36f7 100644 --- a/src/bacnet/basic/service/s_arfs.c +++ b/src/bacnet/basic/service/s_arfs.c @@ -1,13 +1,12 @@ -/************************************************************************** - * - * Copyright (C) 2006 Steve Karg - * - * SPDX-License-Identifier: MIT - * - *********************************************************************/ +/** + * @file + * @brief Send part of an Atomic Read File Stream. + * @author Steve Karg + * @date 2006 + * @copyright SPDX-License-Identifier: MIT + */ #include #include -#include #include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" @@ -22,10 +21,9 @@ #include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/object/device.h" #include "bacnet/datalink/datalink.h" +#include "bacnet/basic/sys/debug.h" #include "bacnet/basic/services.h" -/** @file s_arfs.c Send part of an Atomic Read File Stream. */ - uint8_t Send_Atomic_Read_File_Stream( uint32_t device_id, uint32_t file_instance, @@ -40,9 +38,7 @@ uint8_t Send_Atomic_Read_File_Stream( bool status = false; int len = 0; int pdu_len = 0; -#if PRINT_ENABLED int bytes_sent = 0; -#endif BACNET_ATOMIC_READ_FILE_DATA data; /* if we are forbidden to send, don't send! */ @@ -80,27 +76,18 @@ uint8_t Send_Atomic_Read_File_Stream( tsm_set_confirmed_unsegmented_transaction( invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0], (uint16_t)pdu_len); -#if PRINT_ENABLED - bytes_sent = -#endif - datalink_send_pdu( - &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); -#if PRINT_ENABLED + bytes_sent = datalink_send_pdu( + &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { - fprintf( - stderr, "Failed to Send AtomicReadFile Request (%s)!\n", - strerror(errno)); + debug_perror("Failed to Send AtomicReadFile Request"); } -#endif } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; -#if PRINT_ENABLED - fprintf( + debug_fprintf( stderr, "Failed to Send AtomicReadFile Request " "(payload exceeds destination maximum APDU)!\n"); -#endif } } diff --git a/src/bacnet/basic/service/s_awfs.c b/src/bacnet/basic/service/s_awfs.c index fecc637f..2253757f 100644 --- a/src/bacnet/basic/service/s_awfs.c +++ b/src/bacnet/basic/service/s_awfs.c @@ -1,13 +1,12 @@ -/************************************************************************** - * - * Copyright (C) 2006 Steve Karg - * - * SPDX-License-Identifier: MIT - * - *********************************************************************/ +/** + * @file + * @brief Send part of an Atomic Write File Stream request. + * @author Steve Karg + * @date 2006 + * @copyright SPDX-License-Identifier: MIT + */ #include #include -#include #include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" @@ -22,10 +21,9 @@ #include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/object/device.h" #include "bacnet/datalink/datalink.h" +#include "bacnet/basic/sys/debug.h" #include "bacnet/basic/services.h" -/** @file s_awfs.c Send part of an Atomic Write File Stream request. */ - uint8_t Send_Atomic_Write_File_Stream( uint32_t device_id, uint32_t file_instance, @@ -40,16 +38,13 @@ uint8_t Send_Atomic_Write_File_Stream( bool status = false; int len = 0; int pdu_len = 0; -#if PRINT_ENABLED int bytes_sent = 0; -#endif BACNET_ATOMIC_WRITE_FILE_DATA data; /* if we are forbidden to send, don't send! */ if (!dcc_communication_enabled()) { return 0; } - /* is the device bound? */ status = address_get_by_device(device_id, &max_apdu, &dest); /* is there a tsm available? */ @@ -82,41 +77,28 @@ uint8_t Send_Atomic_Write_File_Stream( tsm_set_confirmed_unsegmented_transaction( invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0], (uint16_t)pdu_len); -#if PRINT_ENABLED - bytes_sent = -#endif - datalink_send_pdu( - &dest, &npdu_data, &Handler_Transmit_Buffer[0], - pdu_len); -#if PRINT_ENABLED + bytes_sent = datalink_send_pdu( + &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { - fprintf( - stderr, - "Failed to Send AtomicWriteFile Request (%s)!\n", - strerror(errno)); + debug_perror("Failed to Send AtomicWriteFile Request"); } -#endif } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; -#if PRINT_ENABLED - fprintf( + debug_fprintf( stderr, "Failed to Send AtomicWriteFile Request " "(payload [%d] exceeds destination maximum APDU [%u])!\n", pdu_len, max_apdu); -#endif } } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; -#if PRINT_ENABLED - fprintf( + debug_fprintf( stderr, "Failed to Send AtomicWriteFile Request " "(payload [%d] exceeds octet string capacity)!\n", pdu_len); -#endif } } diff --git a/src/bacnet/basic/service/s_cevent.c b/src/bacnet/basic/service/s_cevent.c index 8c519076..ba3d5a22 100644 --- a/src/bacnet/basic/service/s_cevent.c +++ b/src/bacnet/basic/service/s_cevent.c @@ -1,13 +1,12 @@ -/************************************************************************** - * - * Copyright (C) 2005 Steve Karg - * - * SPDX-License-Identifier: MIT - * - *********************************************************************/ +/** + * @file + * @brief Send a ConfirmedEventNotification Request. + * @author Steve Karg + * @date 2005 + * @copyright SPDX-License-Identifier: MIT + */ #include #include -#include #include #include "bacnet/event.h" #include "bacnet/dcc.h" @@ -16,10 +15,9 @@ #include "bacnet/datalink/datalink.h" #include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/binding/address.h" +#include "bacnet/basic/sys/debug.h" #include "bacnet/basic/services.h" -/** @file s_cevent.c Send a ConfirmedEventNotification Request. */ - /** Sends an Confirmed Alarm/Event Notification. * @ingroup EVNOTFCN * @@ -38,9 +36,7 @@ uint8_t Send_CEvent_Notify_Address( { int len = 0; int pdu_len = 0; -#if PRINT_ENABLED int bytes_sent = 0; -#endif BACNET_NPDU_DATA npdu_data; BACNET_ADDRESS my_address; uint8_t invoke_id = 0; @@ -69,27 +65,18 @@ uint8_t Send_CEvent_Notify_Address( if ((uint16_t)pdu_len < pdu_size) { tsm_set_confirmed_unsegmented_transaction( invoke_id, dest, &npdu_data, pdu, (uint16_t)pdu_len); -#if PRINT_ENABLED - bytes_sent = -#endif - datalink_send_pdu(dest, &npdu_data, pdu, pdu_len); -#if PRINT_ENABLED + bytes_sent = datalink_send_pdu(dest, &npdu_data, pdu, pdu_len); if (bytes_sent <= 0) { - fprintf( - stderr, - "Failed to Send ConfirmedEventNotification Request (%s)!\n", - strerror(errno)); + debug_perror( + "Failed to Send ConfirmedEventNotification Request"); } -#endif } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; -#if PRINT_ENABLED - fprintf( + debug_fprintf( stderr, "Failed to Send ConfirmedEventNotification Request " "(exceeds destination maximum APDU)!\n"); -#endif } } diff --git a/src/bacnet/basic/service/s_cov.c b/src/bacnet/basic/service/s_cov.c index 0cd00461..07b59780 100644 --- a/src/bacnet/basic/service/s_cov.c +++ b/src/bacnet/basic/service/s_cov.c @@ -1,13 +1,12 @@ -/************************************************************************** - * - * Copyright (C) 2008 Steve Karg - * - * SPDX-License-Identifier: MIT - * - *********************************************************************/ +/** + * @file + * @brief Send a COVNotification or SubscribeCOV-Request. + * @author Steve Karg + * @date 2008 + * @copyright SPDX-License-Identifier: MIT + */ #include #include -#include #include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" @@ -21,11 +20,9 @@ #include "bacnet/basic/binding/address.h" #include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/object/device.h" -#include "bacnet/datalink/datalink.h" #include "bacnet/basic/services.h" - -/** @file s_cov.c Send a Change of Value (COV) update or a Subscribe COV - * request. */ +#include "bacnet/basic/sys/debug.h" +#include "bacnet/datalink/datalink.h" /** Encodes an Unconfirmed COV Notification. * @ingroup DSCOV @@ -151,21 +148,15 @@ uint8_t Send_COV_Subscribe( bytes_sent = datalink_send_pdu( &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { -#if PRINT_ENABLED - fprintf( - stderr, "Failed to Send SubscribeCOV Request (%s)!\n", - strerror(errno)); -#endif + debug_perror("Failed to Send SubscribeCOV Request"); } } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; -#if PRINT_ENABLED - fprintf( + debug_fprintf( stderr, "Failed to Send SubscribeCOV Request " "(exceeds destination maximum APDU)!\n"); -#endif } } diff --git a/src/bacnet/basic/service/s_create_object.c b/src/bacnet/basic/service/s_create_object.c index 37f663a5..b4ff51b1 100644 --- a/src/bacnet/basic/service/s_create_object.c +++ b/src/bacnet/basic/service/s_create_object.c @@ -11,7 +11,6 @@ #include #include #include -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ @@ -104,15 +103,12 @@ uint8_t Send_Create_Object_Request_Data( bytes_sent = datalink_send_pdu( &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { - debug_perror( - "%s service: Failed to Send %i/%i (%s)!\n", - bactext_confirmed_service_name(service), bytes_sent, - pdu_len, strerror(errno)); + debug_perror("CreateObject: Failed to Send"); } } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; - debug_perror( + debug_printf_stderr( "%s service: Failed to Send " "(exceeds destination maximum APDU)!\n", bactext_confirmed_service_name(service)); diff --git a/src/bacnet/basic/service/s_dcc.c b/src/bacnet/basic/service/s_dcc.c index ec50a5b8..eb6728ce 100644 --- a/src/bacnet/basic/service/s_dcc.c +++ b/src/bacnet/basic/service/s_dcc.c @@ -1,13 +1,12 @@ -/************************************************************************** - * - * Copyright (C) 2006 Steve Karg - * - * SPDX-License-Identifier: MIT - * - *********************************************************************/ +/** + * @file + * @brief Send a Device Communication Control (DCC) request. + * @author Steve Karg + * @date 2006 + * @copyright SPDX-License-Identifier: MIT + */ #include #include -#include #include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" @@ -20,10 +19,9 @@ #include "bacnet/basic/binding/address.h" #include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/object/device.h" -#include "bacnet/datalink/datalink.h" #include "bacnet/basic/services.h" - -/** @file s_dcc.c Send a Device Communication Control (DCC) request. */ +#include "bacnet/basic/sys/debug.h" +#include "bacnet/datalink/datalink.h" /** Sends a Device Communication Control (DCC) request. * @ingroup DMDCC @@ -35,13 +33,12 @@ * @param password [in] Optional password, up to 20 chars. * @return The invokeID of the transmitted message, or 0 on failure. */ - uint8_t Send_Device_Communication_Control_Request( uint32_t device_id, - uint16_t timeDuration, /* 0=optional */ + uint16_t timeDuration, BACNET_COMMUNICATION_ENABLE_DISABLE state, const char *password) -{ /* NULL=optional */ +{ BACNET_ADDRESS dest; BACNET_ADDRESS my_address; unsigned max_apdu = 0; @@ -49,9 +46,7 @@ uint8_t Send_Device_Communication_Control_Request( bool status = false; int len = 0; int pdu_len = 0; -#if PRINT_ENABLED int bytes_sent = 0; -#endif BACNET_CHARACTER_STRING password_string; BACNET_NPDU_DATA npdu_data; @@ -87,28 +82,19 @@ uint8_t Send_Device_Communication_Control_Request( tsm_set_confirmed_unsegmented_transaction( invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0], (uint16_t)pdu_len); -#if PRINT_ENABLED - bytes_sent = -#endif - datalink_send_pdu( - &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); -#if PRINT_ENABLED + bytes_sent = datalink_send_pdu( + &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { - fprintf( - stderr, - "Failed to Send DeviceCommunicationControl Request (%s)!\n", - strerror(errno)); + debug_perror( + "Failed to Send DeviceCommunicationControl Request"); } -#endif } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; -#if PRINT_ENABLED - fprintf( + debug_fprintf( stderr, "Failed to Send DeviceCommunicationControl Request " "(exceeds destination maximum APDU)!\n"); -#endif } } diff --git a/src/bacnet/basic/service/s_delete_object.c b/src/bacnet/basic/service/s_delete_object.c index d341ea67..b611eac9 100644 --- a/src/bacnet/basic/service/s_delete_object.c +++ b/src/bacnet/basic/service/s_delete_object.c @@ -3,15 +3,12 @@ * @brief DeleteObject service initiation * @author Steve Karg * @date August 2023 - * @section LICENSE - * - * SPDX-License-Identifier: MIT + * @copyright SPDX-License-Identifier: MIT */ #include #include #include #include -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ @@ -102,15 +99,12 @@ uint8_t Send_Delete_Object_Request( bytes_sent = datalink_send_pdu( &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { - debug_perror( - "%s service: Failed to Send %i/%i (%s)!\n", - bactext_confirmed_service_name(service), bytes_sent, - pdu_len, strerror(errno)); + debug_perror("DeleteObject: Failed to Send"); } } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; - debug_perror( + debug_printf_stderr( "%s service: Failed to Send " "(exceeds destination maximum APDU)!\n", bactext_confirmed_service_name(service)); diff --git a/src/bacnet/basic/service/s_error.c b/src/bacnet/basic/service/s_error.c index 79543622..964ccc90 100644 --- a/src/bacnet/basic/service/s_error.c +++ b/src/bacnet/basic/service/s_error.c @@ -1,13 +1,12 @@ -/************************************************************************** - * - * Copyright (C) 2016 Steve Karg - * - * SPDX-License-Identifier: MIT - * - *********************************************************************/ +/** + * @file + * @brief Send an Error message + * @author Steve Karg + * @date 2016 + * @copyright SPDX-License-Identifier: MIT + */ #include #include -#include #include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" @@ -21,18 +20,20 @@ #include "bacnet/basic/binding/address.h" #include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/object/device.h" -#include "bacnet/datalink/datalink.h" #include "bacnet/basic/services.h" +#include "bacnet/basic/sys/debug.h" +#include "bacnet/datalink/datalink.h" -/** Encodes an Error message +/** + * @brief Encodes an Error message * @param buffer The buffer to build the message for sending. * @param dest - Destination address to send the message * @param src - Source address from which the message originates * @param npdu_data - buffer to hold NPDU data encoded * @param invoke_id - use to match up a reply - * @param reason - #BACNET_ABORT_REASON enumeration - * @param server - true or false - * + * @param service - BACNET_CONFIRMED_SERVICE enumeration + * @param error_class - #BACNET_ERROR_CLASS enumeration + * @param error_code - #BACNET_ERROR_CODE enumeration * @return Size of the message sent (bytes), or a negative value on error. */ int error_encode_pdu( @@ -60,13 +61,14 @@ int error_encode_pdu( return pdu_len; } -/** Sends an Abort message +/** + * @brief Sends a BACnet Error message * @param buffer The buffer to build the message for sending. * @param dest - Destination address to send the message * @param invoke_id - use to match up a reply - * @param reason - #BACNET_ABORT_REASON enumeration - * @param server - true or false - * + * @param service - BACNET_CONFIRMED_SERVICE enumeration + * @param error_class - #BACNET_ERROR_CLASS enumeration + * @param error_code - #BACNET_ERROR_CODE enumeration * @return Size of the message sent (bytes), or a negative value on error. */ int Send_Error_To_Network( @@ -87,6 +89,7 @@ int Send_Error_To_Network( buffer, dest, &src, &npdu_data, invoke_id, service, error_class, error_code); bytes_sent = datalink_send_pdu(dest, &npdu_data, &buffer[0], pdu_len); + debug_perror("BACnetError: Failed to send PDU"); return bytes_sent; } diff --git a/src/bacnet/basic/service/s_get_alarm_sum.c b/src/bacnet/basic/service/s_get_alarm_sum.c index dda3556d..cc763f1c 100644 --- a/src/bacnet/basic/service/s_get_alarm_sum.c +++ b/src/bacnet/basic/service/s_get_alarm_sum.c @@ -1,25 +1,16 @@ /** * @file + * @brief Get Alarm Summary Request * @author Daniel Blazevic * @date 2014 - * @brief Get Alarm Summary Request - * - * @section LICENSE - * - * Copyright (C) 2014 Daniel Blazevic - * - * SPDX-License-Identifier: MIT - * - * @section DESCRIPTION - * - * The Get Alarm Summary Request is used by a client BACnet-user to - * obtain a summary of "active alarms." The term "active alarm" refers to - * BACnet standard objects that have an Event_State property whose value is - * not equal to NORMAL and a Notify_Type property whose value is ALARM. + * @copyright SPDX-License-Identifier: MIT + * @details The Get Alarm Summary Request is used by a client BACnet-user to + * obtain a summary of "active alarms." The term "active alarm" refers to + * BACnet standard objects that have an Event_State property whose value is + * not equal to NORMAL and a Notify_Type property whose value is ALARM. */ #include #include -#include #include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" @@ -30,6 +21,7 @@ #include "bacnet/get_alarm_sum.h" #include "bacnet/basic/binding/address.h" #include "bacnet/basic/tsm/tsm.h" +#include "bacnet/basic/sys/debug.h" #include "bacnet/basic/object/device.h" #include "bacnet/datalink/datalink.h" #include "bacnet/basic/services.h" @@ -41,9 +33,7 @@ uint8_t Send_Get_Alarm_Summary_Address(BACNET_ADDRESS *dest, uint16_t max_apdu) uint8_t invoke_id = 0; BACNET_NPDU_DATA npdu_data; BACNET_ADDRESS my_address; -#if PRINT_ENABLED int bytes_sent = 0; -#endif /* is there a tsm available? */ invoke_id = tsm_next_free_invokeID(); @@ -63,27 +53,18 @@ uint8_t Send_Get_Alarm_Summary_Address(BACNET_ADDRESS *dest, uint16_t max_apdu) tsm_set_confirmed_unsegmented_transaction( invoke_id, dest, &npdu_data, &Handler_Transmit_Buffer[0], (uint16_t)pdu_len); -#if PRINT_ENABLED - bytes_sent = -#endif - datalink_send_pdu( - dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); -#if PRINT_ENABLED + bytes_sent = datalink_send_pdu( + dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { - fprintf( - stderr, "Failed to Send Get Alarm Summary Request (%s)!\n", - strerror(errno)); + debug_perror("Failed to Send Get Alarm Summary Request"); } -#endif } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; -#if PRINT_ENABLED - fprintf( + debug_fprintf( stderr, "Failed to Send Get Alarm Summary Request " "(exceeds destination maximum APDU)!\n"); -#endif } } diff --git a/src/bacnet/basic/service/s_get_event.c b/src/bacnet/basic/service/s_get_event.c index b076d040..18048462 100644 --- a/src/bacnet/basic/service/s_get_event.c +++ b/src/bacnet/basic/service/s_get_event.c @@ -1,27 +1,18 @@ /** * @file + * @brief Get Event Request * @author Daniel Blazevic * @date 2014 - * @brief Get Event Request - * - * @section LICENSE - * - * Copyright (C) 2014 Daniel Blazevic - * - * SPDX-License-Identifier: MIT - * - * @section DESCRIPTION - * - * The GetEventInformation service is used by a client BACnet-user to obtain - * a summary of all "active event states". The term "active event states" - * refers to all event-initiating objects that have an Event_State property - * whose value is not equal to NORMAL, or have an Acked_Transitions property, - * which has at least one of the bits (TO-OFFNORMAL, TO-FAULT, TONORMAL) - * set to FALSE. + * @copyright SPDX-License-Identifier: MIT + * @details The GetEventInformation service is used by a client BACnet-user + * to obtain a summary of all "active event states". + * The term "active event states" refers to all event-initiating objects + * that have an Event_State property whose value is not equal to NORMAL, + * or have an Acked_Transitions property, which has at least one of the + * bits (TO-OFFNORMAL, TO-FAULT, TONORMAL) set to FALSE. */ #include #include -#include #include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" @@ -34,6 +25,7 @@ #include "bacnet/basic/binding/address.h" #include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/object/device.h" +#include "bacnet/basic/sys/debug.h" #include "bacnet/datalink/datalink.h" #include "bacnet/basic/services.h" @@ -47,9 +39,7 @@ uint8_t Send_Get_Event_Information_Address( uint8_t invoke_id = 0; BACNET_NPDU_DATA npdu_data; BACNET_ADDRESS my_address; -#if PRINT_ENABLED int bytes_sent = 0; -#endif /* is there a tsm available? */ invoke_id = tsm_next_free_invokeID(); @@ -69,28 +59,18 @@ uint8_t Send_Get_Event_Information_Address( tsm_set_confirmed_unsegmented_transaction( invoke_id, dest, &npdu_data, &Handler_Transmit_Buffer[0], (uint16_t)pdu_len); -#if PRINT_ENABLED - bytes_sent = -#endif - datalink_send_pdu( - dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); -#if PRINT_ENABLED + bytes_sent = datalink_send_pdu( + dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { - fprintf( - stderr, - "Failed to Send Get Event Information Request (%s)!\n", - strerror(errno)); + debug_perror("Failed to Send Get Event Information Request"); } -#endif } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; -#if PRINT_ENABLED - fprintf( + debug_fprintf( stderr, "Failed to Send Get Event Information Request " "(exceeds destination maximum APDU)!\n"); -#endif } } diff --git a/src/bacnet/basic/service/s_getevent.c b/src/bacnet/basic/service/s_getevent.c index 6f13e8f8..839e5b91 100644 --- a/src/bacnet/basic/service/s_getevent.c +++ b/src/bacnet/basic/service/s_getevent.c @@ -1,13 +1,12 @@ -/************************************************************************** - * - * Copyright (C) 2015 bowe - * - * SPDX-License-Identifier: MIT - * - *********************************************************************/ +/** + * @file + * @brief Send a GetEventInformation request. + * @author Boris Weitsch + * @date 2015 + * @copyright SPDX-License-Identifier: MIT + */ #include #include -#include #include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" @@ -23,8 +22,7 @@ #include "bacnet/basic/object/device.h" #include "bacnet/datalink/datalink.h" #include "bacnet/basic/services.h" - -/** @file s_getevent.c Send a GetEventInformation request. */ +#include "bacnet/basic/sys/debug.h" /** Send a GetEventInformation request to a remote network for a specific * device, a range, or any device. @@ -36,9 +34,7 @@ uint8_t Send_GetEvent( { int len = 0; int pdu_len = 0; -#if PRINT_ENABLED int bytes_sent = 0; -#endif uint8_t invoke_id = 0; BACNET_NPDU_DATA npdu_data; BACNET_ADDRESS my_address; @@ -57,28 +53,18 @@ uint8_t Send_GetEvent( &Handler_Transmit_Buffer[pdu_len], invoke_id, lastReceivedObjectIdentifier); pdu_len += len; -#if PRINT_ENABLED - bytes_sent = -#endif - datalink_send_pdu( - target_address, &npdu_data, &Handler_Transmit_Buffer[0], - pdu_len); -#if PRINT_ENABLED + bytes_sent = datalink_send_pdu( + target_address, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { - fprintf( - stderr, "Failed to Send GetEventInformation Request (%s)!\n", - strerror(errno)); + debug_perror("Failed to Send GetEventInformation Request"); } -#endif } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; -#if PRINT_ENABLED - fprintf( + debug_fprintf( stderr, "Failed to Send GetEventInformation Request " "(exceeds destination maximum APDU)!\n"); -#endif } return invoke_id; } diff --git a/src/bacnet/basic/service/s_iam.c b/src/bacnet/basic/service/s_iam.c index 2e6afd53..cfc9d103 100644 --- a/src/bacnet/basic/service/s_iam.c +++ b/src/bacnet/basic/service/s_iam.c @@ -1,13 +1,12 @@ -/************************************************************************** - * - * Copyright (C) 2008 Steve Karg - * - * SPDX-License-Identifier: MIT - * - *********************************************************************/ +/** + * @file + * @brief Send an I-Am message. + * @author Steve Karg + * @date 2008 + * @copyright SPDX-License-Identifier: MIT + */ #include #include -#include #include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" @@ -23,8 +22,7 @@ #include "bacnet/basic/object/device.h" #include "bacnet/datalink/datalink.h" #include "bacnet/basic/services.h" - -/** @file s_iam.c Send an I-Am message. */ +#include "bacnet/basic/sys/debug.h" /** Send a I-Am request to a remote network for a specific device. * @param target_address [in] BACnet address of target router @@ -61,9 +59,7 @@ void Send_I_Am_To_Network( bytes_sent = datalink_send_pdu( target_address, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { -#if PRINT_ENABLED - fprintf(stderr, "Failed to Send I-Am Request (%s)!\n", strerror(errno)); -#endif + debug_perror("Failed to Send I-Am Request"); } } @@ -118,16 +114,12 @@ void Send_I_Am(uint8_t *buffer) if (!dcc_communication_enabled()) return 0; #endif - /* encode the data */ pdu_len = iam_encode_pdu(buffer, &dest, &npdu_data); /* send data */ bytes_sent = datalink_send_pdu(&dest, &npdu_data, &buffer[0], pdu_len); - if (bytes_sent <= 0) { -#if PRINT_ENABLED - fprintf(stderr, "Failed to Send I-Am Reply (%s)!\n", strerror(errno)); -#endif + debug_perror("Failed to Send I-Am Reply"); } } @@ -196,15 +188,12 @@ void Send_I_Am_Unicast(uint8_t *buffer, const BACNET_ADDRESS *src) if (!dcc_communication_enabled()) return 0; #endif - /* encode the data */ pdu_len = iam_unicast_encode_pdu(buffer, src, &dest, &npdu_data); /* send data */ bytes_sent = datalink_send_pdu(&dest, &npdu_data, &buffer[0], pdu_len); if (bytes_sent <= 0) { -#if PRINT_ENABLED - fprintf(stderr, "Failed to Send I-Am Reply (%s)!\n", strerror(errno)); -#endif + debug_perror("Failed to Send I-Am Reply"); } } diff --git a/src/bacnet/basic/service/s_ihave.c b/src/bacnet/basic/service/s_ihave.c index 9cd8a015..3b8dccdb 100644 --- a/src/bacnet/basic/service/s_ihave.c +++ b/src/bacnet/basic/service/s_ihave.c @@ -1,13 +1,12 @@ -/************************************************************************** - * - * Copyright (C) 2006 Steve Karg - * - * SPDX-License-Identifier: MIT - * - *********************************************************************/ +/** + * @file + * @brief Send an I-Have (property) message. + * @author Steve Karg + * @date 2006 + * @copyright SPDX-License-Identifier: MIT + */ #include #include -#include #include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" @@ -22,10 +21,9 @@ #include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/object/device.h" #include "bacnet/datalink/datalink.h" +#include "bacnet/basic/sys/debug.h" #include "bacnet/basic/services.h" -/** @file s_ihave.c Send an I-Have (property) message. */ - /** Broadcast an I Have message. * @ingroup DMDOB * @@ -72,8 +70,6 @@ void Send_I_Have( bytes_sent = datalink_send_pdu( &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { -#if PRINT_ENABLED - fprintf(stderr, "Failed to Send I-Have Reply (%s)!\n", strerror(errno)); -#endif + debug_perror("Failed to Send I-Have Reply"); } } diff --git a/src/bacnet/basic/service/s_list_element.c b/src/bacnet/basic/service/s_list_element.c index 9008de83..d74da858 100644 --- a/src/bacnet/basic/service/s_list_element.c +++ b/src/bacnet/basic/service/s_list_element.c @@ -3,17 +3,12 @@ * @brief AddListElement and RemoveListElement service initiation * @author Steve Karg * @date January 2023 - * @section LICENSE - * - * Copyright (C) 2023 Steve Karg - * - * SPDX-License-Identifier: MIT + * @copyright SPDX-License-Identifier: MIT */ #include #include #include #include -#include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ @@ -113,15 +108,12 @@ uint8_t Send_List_Element_Request_Data( bytes_sent = datalink_send_pdu( &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { - debug_perror( - "%s service: Failed to Send %i/%i (%s)!\n", - bactext_confirmed_service_name(service), bytes_sent, - pdu_len, strerror(errno)); + debug_perror("ListElement: Failed to Send"); } } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; - debug_perror( + debug_printf_stderr( "%s service: Failed to Send " "(exceeds destination maximum APDU)!\n", bactext_confirmed_service_name(service)); @@ -259,7 +251,7 @@ uint8_t Send_Remove_List_Element_Request( int apdu_len = 0, len = 0; while (object_value) { - debug_perror( + debug_printf_stderr( "RemoveListElement service: " "%s tag=%d\n", (object_value->context_specific ? "context" : "application"), diff --git a/src/bacnet/basic/service/s_lso.c b/src/bacnet/basic/service/s_lso.c index 71860cef..fe5d2aa2 100644 --- a/src/bacnet/basic/service/s_lso.c +++ b/src/bacnet/basic/service/s_lso.c @@ -1,13 +1,12 @@ -/************************************************************************** - * - * Copyright (C) 2009 John Minack - * - * SPDX-License-Identifier: MIT - * - *********************************************************************/ +/** + * @file + * @brief Send BACnet Life Safety Operation message. + * @author Steve Karg + * @date 2009 + * @copyright SPDX-License-Identifier: MIT + */ #include #include -#include #include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" @@ -24,11 +23,15 @@ #include "bacnet/basic/services.h" #include "bacnet/basic/object/device.h" #include "bacnet/datalink/datalink.h" +#include "bacnet/basic/sys/debug.h" -/** @file s_lso.c Send BACnet Life Safety Operation message. */ - -/* returns the invoke ID for confirmed request, or zero on failure */ - +/** + * @brief Send a Life Safety Operation service message + * @ingroup BIBB-AE-LS-A + * @param device_id [in] ID of the destination device + * @param data [in] The data representing the Life Safety Operation + * @return invoke id of outgoing message, or 0 on failure. + */ uint8_t Send_Life_Safety_Operation_Data(uint32_t device_id, const BACNET_LSO_DATA *data) { @@ -39,15 +42,12 @@ Send_Life_Safety_Operation_Data(uint32_t device_id, const BACNET_LSO_DATA *data) bool status = false; int len = 0; int pdu_len = 0; -#if PRINT_ENABLED int bytes_sent = 0; -#endif BACNET_NPDU_DATA npdu_data; if (!dcc_communication_enabled()) { return 0; } - /* is the device bound? */ status = address_get_by_device(device_id, &max_apdu, &dest); /* is there a tsm available? */ @@ -72,27 +72,18 @@ Send_Life_Safety_Operation_Data(uint32_t device_id, const BACNET_LSO_DATA *data) tsm_set_confirmed_unsegmented_transaction( invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0], (uint16_t)pdu_len); -#if PRINT_ENABLED - bytes_sent = -#endif - datalink_send_pdu( - &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); -#if PRINT_ENABLED + bytes_sent = datalink_send_pdu( + &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { - fprintf( - stderr, "Failed to Send Life Safe Op Request (%s)!\n", - strerror(errno)); + debug_perror("Failed to Send Life Safe Op Request"); } -#endif } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; -#if PRINT_ENABLED - fprintf( + debug_fprintf( stderr, "Failed to Send Life Safe Op Request " "(exceeds destination maximum APDU)!\n"); -#endif } } diff --git a/src/bacnet/basic/service/s_rd.c b/src/bacnet/basic/service/s_rd.c index 3883b587..69b1eba0 100644 --- a/src/bacnet/basic/service/s_rd.c +++ b/src/bacnet/basic/service/s_rd.c @@ -1,13 +1,12 @@ -/************************************************************************** - * - * Copyright (C) 2005 Steve Karg - * - * SPDX-License-Identifier: MIT - * - *********************************************************************/ +/** + * @file + * @brief Send BACnet ReinitializeDevice-Request. + * @author Steve Karg + * @date 2005 + * @copyright SPDX-License-Identifier: MIT + */ #include #include -#include #include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" @@ -23,12 +22,11 @@ #include "bacnet/basic/object/device.h" #include "bacnet/datalink/datalink.h" #include "bacnet/basic/services.h" +#include "bacnet/basic/sys/debug.h" -/** @file s_rd.c Send a Reinitialize Device request. */ - -/** Sends a Reinitialize Device (RD) request. - * @ingroup DMRD - * +/** + * @brief Sends a Reinitialize Device (RD) request. + * @ingroup BIBB-DM-RD-A * @param device_id [in] The index to the device address in our address cache. * @param state [in] Specifies the desired state of the device after * reinitialization. @@ -45,9 +43,7 @@ uint8_t Send_Reinitialize_Device_Request( bool status = false; int len = 0; int pdu_len = 0; -#if PRINT_ENABLED int bytes_sent = 0; -#endif BACNET_CHARACTER_STRING password_string; BACNET_NPDU_DATA npdu_data; @@ -55,7 +51,6 @@ uint8_t Send_Reinitialize_Device_Request( if (!dcc_communication_enabled()) { return 0; } - /* is the device bound? */ status = address_get_by_device(device_id, &max_apdu, &dest); /* is there a tsm available? */ @@ -83,27 +78,18 @@ uint8_t Send_Reinitialize_Device_Request( tsm_set_confirmed_unsegmented_transaction( invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0], (uint16_t)pdu_len); -#if PRINT_ENABLED - bytes_sent = -#endif - datalink_send_pdu( - &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); -#if PRINT_ENABLED + bytes_sent = datalink_send_pdu( + &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { - fprintf( - stderr, "Failed to Send ReinitializeDevice Request (%s)!\n", - strerror(errno)); + debug_perror("Failed to Send ReinitializeDevice Request"); } -#endif } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; -#if PRINT_ENABLED - fprintf( + debug_fprintf( stderr, "Failed to Send ReinitializeDevice Request " "(exceeds destination maximum APDU)!\n"); -#endif } } diff --git a/src/bacnet/basic/service/s_readrange.c b/src/bacnet/basic/service/s_readrange.c index 2a0ca3bc..77b5c445 100644 --- a/src/bacnet/basic/service/s_readrange.c +++ b/src/bacnet/basic/service/s_readrange.c @@ -1,13 +1,12 @@ -/************************************************************************** - * - * Copyright (C) 2008 Steve Karg - * - * SPDX-License-Identifier: MIT - * - *********************************************************************/ +/** + * @file + * @brief Send a ReadRange-Request message + * @author Peter Mc Shane + * @date 2009 + * @copyright SPDX-License-Identifier: MIT + */ #include #include -#include #include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" @@ -24,10 +23,14 @@ #include "bacnet/basic/object/device.h" #include "bacnet/datalink/datalink.h" #include "bacnet/basic/services.h" +#include "bacnet/basic/sys/debug.h" -/** @file s_readrange.c Send a ReadRange request. */ - -/* returns invoke id of 0 if device is not bound or no tsm available */ +/** + * @brief Send a ReadRange-Request message + * @param device_id [in] ID of the destination device + * @param data [in] The data representing the ReadRange-Request + * @return invoke id of outgoing message, or 0 on failure. + */ uint8_t Send_ReadRange_Request( uint32_t device_id, /* destination device */ const BACNET_READ_RANGE_DATA *read_access_data) @@ -39,22 +42,18 @@ uint8_t Send_ReadRange_Request( bool status = false; int len = 0; int pdu_len = 0; -#if PRINT_ENABLED int bytes_sent = 0; -#endif BACNET_NPDU_DATA npdu_data; if (!dcc_communication_enabled()) { return 0; } - /* is the device bound? */ status = address_get_by_device(device_id, &max_apdu, &dest); /* is there a tsm available? */ if (status) { invoke_id = tsm_next_free_invokeID(); } - if (invoke_id) { /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); @@ -79,27 +78,18 @@ uint8_t Send_ReadRange_Request( tsm_set_confirmed_unsegmented_transaction( invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0], (uint16_t)pdu_len); -#if PRINT_ENABLED - bytes_sent = -#endif - datalink_send_pdu( - &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); -#if PRINT_ENABLED + bytes_sent = datalink_send_pdu( + &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { - fprintf( - stderr, "Failed to Send ReadRange Request (%s)!\n", - strerror(errno)); + debug_perror("Failed to Send ReadRange Request"); } -#endif } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; -#if PRINT_ENABLED - fprintf( + debug_fprintf( stderr, "Failed to Send ReadRange Request (exceeds destination " "maximum APDU)!\n"); -#endif } } diff --git a/src/bacnet/basic/service/s_rp.c b/src/bacnet/basic/service/s_rp.c index 70f76f87..607646e1 100644 --- a/src/bacnet/basic/service/s_rp.c +++ b/src/bacnet/basic/service/s_rp.c @@ -1,13 +1,12 @@ -/************************************************************************** - * - * Copyright (C) 2005 Steve Karg - * - * SPDX-License-Identifier: MIT - * - *********************************************************************/ +/** + * @file + * @brief Send BACnet ReadProperty-Request. + * @author Steve Karg + * @date 2005 + * @copyright SPDX-License-Identifier: MIT + */ #include #include -#include #include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" @@ -18,17 +17,16 @@ #include "bacnet/dcc.h" #include "bacnet/rp.h" /* some demo stuff needed */ -#include "bacnet/basic/object/device.h" -#include "bacnet/datalink/datalink.h" #include "bacnet/basic/binding/address.h" +#include "bacnet/basic/object/device.h" #include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/services.h" +#include "bacnet/basic/sys/debug.h" +#include "bacnet/datalink/datalink.h" -/** @file s_rp.c Send Read Property request. */ - -/** Sends a Read Property request - * @ingroup DSRP - * +/** + * @brief Sends a Read Property request + * @ingroup BIBB-DS-RP-A * @param dest [in] BACNET_ADDRESS of the destination device * @param max_apdu [in] * @param object_type [in] Type of the object whose property is to be read. @@ -92,29 +90,24 @@ uint8_t Send_Read_Property_Request_Address( bytes_sent = datalink_send_pdu( dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { -#if PRINT_ENABLED - fprintf( - stderr, "Failed to Send ReadProperty Request (%s)!\n", - strerror(errno)); -#endif + debug_perror("Failed to Send ReadProperty Request"); } } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; -#if PRINT_ENABLED - fprintf( + debug_fprintf( stderr, "Failed to Send ReadProperty Request " "(exceeds destination maximum APDU)!\n"); -#endif } } return invoke_id; } -/** Sends a Read Property request. - * @ingroup DSRP +/** + * @brief Sends a Read Property request. + * @ingroup BIBB-DS-RP-A * * @param device_id [in] ID of the destination device * @param object_type [in] Type of the object whose property is to be read. diff --git a/src/bacnet/basic/service/s_rpm.c b/src/bacnet/basic/service/s_rpm.c index 8394a17d..a6dd2449 100644 --- a/src/bacnet/basic/service/s_rpm.c +++ b/src/bacnet/basic/service/s_rpm.c @@ -1,13 +1,12 @@ -/************************************************************************** - * - * Copyright (C) 2008 Steve Karg - * - * SPDX-License-Identifier: MIT - * - *********************************************************************/ +/** + * @file + * @brief Send Read Property Multiple request. + * @author Steve Karg + * @date 2008 + * @copyright SPDX-License-Identifier: MIT + */ #include #include -#include #include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" @@ -23,12 +22,11 @@ #include "bacnet/basic/binding/address.h" #include "bacnet/basic/tsm/tsm.h" #include "bacnet/basic/services.h" +#include "bacnet/basic/sys/debug.h" -/** @file s_rpm.c Send Read Property Multiple request. */ - -/** Sends a Read Property Multiple request. - * @ingroup DSRPM - * +/** + * @brief Sends a Read Property Multiple request. + * @ingroup BIBB-DS-RPM-A * @param pdu [out] Buffer to build the outgoing message into * @param max_pdu [in] Length of the pdu buffer. * @param device_id [in] ID of the destination device @@ -50,15 +48,12 @@ uint8_t Send_Read_Property_Multiple_Request( bool status = false; int len = 0; int pdu_len = 0; -#if PRINT_ENABLED int bytes_sent = 0; -#endif BACNET_NPDU_DATA npdu_data; if (!dcc_communication_enabled()) { return 0; } - /* is the device bound? */ status = address_get_by_device(device_id, &max_apdu, &dest); /* is there a tsm available? */ @@ -85,27 +80,17 @@ uint8_t Send_Read_Property_Multiple_Request( if ((unsigned)pdu_len < max_apdu) { tsm_set_confirmed_unsegmented_transaction( invoke_id, &dest, &npdu_data, &pdu[0], (uint16_t)pdu_len); -#if PRINT_ENABLED - bytes_sent = -#endif - datalink_send_pdu(&dest, &npdu_data, &pdu[0], pdu_len); -#if PRINT_ENABLED + bytes_sent = datalink_send_pdu(&dest, &npdu_data, &pdu[0], pdu_len); if (bytes_sent <= 0) { - fprintf( - stderr, - "Failed to Send ReadPropertyMultiple Request (%s)!\n", - strerror(errno)); + debug_perror("Failed to Send ReadPropertyMultiple Request"); } -#endif } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; -#if PRINT_ENABLED - fprintf( + debug_fprintf( stderr, "Failed to Send ReadPropertyMultiple Request " "(exceeds destination maximum APDU)!\n"); -#endif } } diff --git a/src/bacnet/basic/service/s_ts.c b/src/bacnet/basic/service/s_ts.c index 22a54895..b7ff9473 100644 --- a/src/bacnet/basic/service/s_ts.c +++ b/src/bacnet/basic/service/s_ts.c @@ -1,13 +1,12 @@ -/************************************************************************** - * - * Copyright (C) 2005 Steve Karg - * - * SPDX-License-Identifier: MIT - * - *********************************************************************/ +/** + * @file + * @brief Send TimeSync requests. + * @author Steve Karg + * @date 2005 + * @copyright SPDX-License-Identifier: MIT + */ #include #include -#include #include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" @@ -23,12 +22,11 @@ #include "bacnet/basic/services.h" #include "bacnet/basic/tsm/tsm.h" #include "bacnet/datalink/datalink.h" - -/** @file s_ts.c Send TimeSync requests. */ +#include "bacnet/basic/sys/debug.h" /** - * Sends a TimeSync message to a specific destination - * + * @brief Sends a TimeSync message to a specific destination + * @ingroup BIBB-DM-TS-A * @param dest - #BACNET_ADDRESS - the specific destination * @param bdate - #BACNET_DATE * @param btime - #BACNET_TIME @@ -38,16 +36,13 @@ void Send_TimeSync_Remote( { int len = 0; int pdu_len = 0; -#if PRINT_ENABLED int bytes_sent = 0; -#endif BACNET_NPDU_DATA npdu_data; BACNET_ADDRESS my_address; if (!dcc_communication_enabled()) { return; } - datalink_get_my_address(&my_address); /* encode the NPDU portion of the packet */ npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); @@ -57,23 +52,16 @@ void Send_TimeSync_Remote( len = timesync_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bdate, btime); pdu_len += len; /* send it out the datalink */ -#if PRINT_ENABLED - bytes_sent = -#endif - datalink_send_pdu( - dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); -#if PRINT_ENABLED + bytes_sent = datalink_send_pdu( + dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { - fprintf( - stderr, "Failed to Send Time-Synchronization Request (%s)!\n", - strerror(errno)); + debug_perror("Failed to Send Time-Synchronization Request"); } -#endif } /** - * Sends a TimeSync message as a broadcast - * + * @brief Sends a TimeSync message as a broadcast + * @ingroup BIBB-DM-TS-A * @param bdate - #BACNET_DATE * @param btime - #BACNET_TIME */ @@ -86,8 +74,8 @@ void Send_TimeSync(const BACNET_DATE *bdate, const BACNET_TIME *btime) } /** - * Sends a UTC TimeSync message to a specific destination - * + * @brief Sends a UTC TimeSync message to a specific destination + * @ingroup BIBB-DM-UTC-A * @param dest - #BACNET_ADDRESS - the specific destination * @param bdate - #BACNET_DATE * @param btime - #BACNET_TIME @@ -97,9 +85,7 @@ void Send_TimeSyncUTC_Remote( { int len = 0; int pdu_len = 0; -#if PRINT_ENABLED int bytes_sent = 0; -#endif BACNET_NPDU_DATA npdu_data; BACNET_ADDRESS my_address; @@ -116,23 +102,16 @@ void Send_TimeSyncUTC_Remote( len = timesync_utc_encode_apdu( &Handler_Transmit_Buffer[pdu_len], bdate, btime); pdu_len += len; -#if PRINT_ENABLED - bytes_sent = -#endif - datalink_send_pdu( - dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); -#if PRINT_ENABLED + bytes_sent = datalink_send_pdu( + dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { - fprintf( - stderr, "Failed to Send UTC-Time-Synchronization Request (%s)!\n", - strerror(errno)); + debug_perror("Failed to Send UTC-Time-Synchronization Request"); } -#endif } /** - * Sends a UTC TimeSync message as a broadcast - * + * @brief Sends a UTC TimeSync message as a broadcast + * @ingroup BIBB-DM-UTC-A * @param bdate - #BACNET_DATE * @param btime - #BACNET_TIME */ @@ -145,7 +124,8 @@ void Send_TimeSyncUTC(const BACNET_DATE *bdate, const BACNET_TIME *btime) } /** - * Sends a UTC TimeSync message using the local time from the device. + * @brief Sends a UTC TimeSync message using the local time from the device. + * @ingroup BIBB-DM-UTC-A */ void Send_TimeSyncUTC_Device(void) { @@ -166,7 +146,8 @@ void Send_TimeSyncUTC_Device(void) } /** - * Sends a TimeSync message using the local time from the device. + * @brief Sends a TimeSync message using the local time from the device. + * @ingroup BIBB-DM-TS-A */ void Send_TimeSync_Device(void) { diff --git a/src/bacnet/basic/service/s_uevent.c b/src/bacnet/basic/service/s_uevent.c index ebb9dfb9..5c7305f0 100644 --- a/src/bacnet/basic/service/s_uevent.c +++ b/src/bacnet/basic/service/s_uevent.c @@ -1,23 +1,21 @@ -/************************************************************************** - * - * Copyright (C) 2008 John Minack - * - * SPDX-License-Identifier: MIT - * - *********************************************************************/ +/** + * @file + * @brief Send an Unconfirmed Event Notification. + * @author Steve Karg + * @date 2009 + * @copyright SPDX-License-Identifier: MIT + */ #include #include -#include #include "bacnet/event.h" #include "bacnet/datalink/datalink.h" #include "bacnet/basic/services.h" #include "bacnet/basic/object/device.h" +#include "bacnet/basic/sys/debug.h" -/** @file s_uevent.c Send an Unconfirmed Event Notification. */ - -/** Sends an Unconfirmed Alarm/Event Notification. - * @ingroup EVNOTFCN - * +/** + * @brief Sends an Unconfirmed Alarm/Event Notification. + * @ingroup BIBB-AE-N-A * @param buffer [in,out] The buffer to build the message in for sending. * @param data [in] The information about the Event to be sent. * @param dest [in] The destination address information (may be a broadcast). @@ -43,6 +41,9 @@ int Send_UEvent_Notify( pdu_len += len; /* send the data */ bytes_sent = datalink_send_pdu(dest, &npdu_data, &buffer[0], pdu_len); + if (bytes_sent <= 0) { + debug_perror("Failed to Send EventNotification Request"); + } return bytes_sent; } diff --git a/src/bacnet/basic/service/s_upt.c b/src/bacnet/basic/service/s_upt.c index 01399382..2dbd7f7f 100644 --- a/src/bacnet/basic/service/s_upt.c +++ b/src/bacnet/basic/service/s_upt.c @@ -1,13 +1,12 @@ -/************************************************************************** - * - * Copyright (C) 2009 Steve Karg - * - * SPDX-License-Identifier: MIT - * - *********************************************************************/ +/** + * @file + * @brief Send an UnconfirmedPrivateTransfer-Request. + * @author Steve Karg + * @date 2009 + * @copyright SPDX-License-Identifier: MIT + */ #include #include -#include #include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" @@ -23,11 +22,17 @@ #include "bacnet/basic/services.h" #include "bacnet/basic/tsm/tsm.h" #include "bacnet/datalink/datalink.h" +#include "bacnet/basic/sys/debug.h" -/** @file s_upt.c Send an Unconfirmed Private Transfer request. */ - +/** + * @brief Sends an UnconfirmedPrivateTransfer-Request. + * @ingroup BIBB-PT-A + * @param dest [in] The destination address information (may be a broadcast). + * @param data [in] The information about the private transfer to be sent. + * @return Size of the message sent (bytes), or a negative value on error. + */ int Send_UnconfirmedPrivateTransfer( - BACNET_ADDRESS *dest, const BACNET_PRIVATE_TRANSFER_DATA *private_data) + BACNET_ADDRESS *dest, const BACNET_PRIVATE_TRANSFER_DATA *data) { int len = 0; int pdu_len = 0; @@ -38,25 +43,18 @@ int Send_UnconfirmedPrivateTransfer( if (!dcc_communication_enabled()) { return bytes_sent; } - datalink_get_my_address(&my_address); /* encode the NPDU portion of the packet */ npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); pdu_len = npdu_encode_pdu( &Handler_Transmit_Buffer[0], dest, &my_address, &npdu_data); - /* encode the APDU portion of the packet */ - len = - uptransfer_encode_apdu(&Handler_Transmit_Buffer[pdu_len], private_data); + len = uptransfer_encode_apdu(&Handler_Transmit_Buffer[pdu_len], data); pdu_len += len; bytes_sent = datalink_send_pdu( dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { -#if PRINT_ENABLED - fprintf( - stderr, "Failed to Send UnconfirmedPrivateTransfer Request (%s)!\n", - strerror(errno)); -#endif + debug_perror("Failed to Send UnconfirmedPrivateTransfer Request"); } return bytes_sent; diff --git a/src/bacnet/basic/service/s_whohas.c b/src/bacnet/basic/service/s_whohas.c index 9adf521b..91214db6 100644 --- a/src/bacnet/basic/service/s_whohas.c +++ b/src/bacnet/basic/service/s_whohas.c @@ -1,13 +1,12 @@ -/************************************************************************** - * - * Copyright (C) 2006 Steve Karg - * - * SPDX-License-Identifier: MIT - * - *********************************************************************/ +/** + * @file + * @brief Send BACnet Who-Has requests + * @author Steve Karg + * @date 2006 + * @copyright SPDX-License-Identifier: MIT + */ #include #include -#include #include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" @@ -21,13 +20,13 @@ #include "bacnet/basic/binding/address.h" #include "bacnet/basic/object/device.h" #include "bacnet/basic/services.h" +#include "bacnet/basic/sys/debug.h" #include "bacnet/basic/tsm/tsm.h" #include "bacnet/datalink/datalink.h" -/** @file s_whohas.c Send Who-Has requests. */ - -/** Send a Who-Has request for a device which has a named Object. - * @ingroup DMDOB +/** + * @brief Send a Who-Has request for a device which has a named Object. + * @ingroup BIBB-DM-DOB-A * If low_limit and high_limit both are -1, then the device ID range is * unlimited. If low_limit and high_limit have the same non-negative value, then * only that device will respond. Otherwise, low_limit must be less than @@ -42,9 +41,7 @@ void Send_WhoHas_Name( int len = 0; int pdu_len = 0; BACNET_ADDRESS dest; -#if PRINT_ENABLED int bytes_sent = 0; -#endif BACNET_WHO_HAS_DATA data; BACNET_NPDU_DATA npdu_data; BACNET_ADDRESS my_address; @@ -69,21 +66,17 @@ void Send_WhoHas_Name( len = whohas_encode_apdu(&Handler_Transmit_Buffer[pdu_len], &data); pdu_len += len; /* send the data */ -#if PRINT_ENABLED - bytes_sent = -#endif - datalink_send_pdu( - &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); -#if PRINT_ENABLED + bytes_sent = datalink_send_pdu( + &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { - fprintf( - stderr, "Failed to Send Who-Has Request (%s)!\n", strerror(errno)); + debug_perror("Failed to Send Who-Has Request"); } -#endif } -/** Send a Who-Has request for a device which has a specific Object type and ID. - * @ingroup DMDOB +/** + * @brief Send a Who-Has request for a device which has a specific + * Object type and ID. + * @ingroup BIBB-DM-DOB-A * If low_limit and high_limit both are -1, then the device ID range is * unlimited. If low_limit and high_limit have the same non-negative value, then * only that device will respond. Otherwise, low_limit must be less than @@ -102,9 +95,7 @@ void Send_WhoHas_Object( int len = 0; int pdu_len = 0; BACNET_ADDRESS dest; -#if PRINT_ENABLED int bytes_sent = 0; -#endif BACNET_WHO_HAS_DATA data; BACNET_NPDU_DATA npdu_data; BACNET_ADDRESS my_address; @@ -120,7 +111,6 @@ void Send_WhoHas_Object( npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); pdu_len = npdu_encode_pdu( &Handler_Transmit_Buffer[0], &dest, &my_address, &npdu_data); - /* encode the APDU portion of the packet */ data.low_limit = low_limit; data.high_limit = high_limit; @@ -129,15 +119,9 @@ void Send_WhoHas_Object( data.object.identifier.instance = object_instance; len = whohas_encode_apdu(&Handler_Transmit_Buffer[pdu_len], &data); pdu_len += len; -#if PRINT_ENABLED - bytes_sent = -#endif - datalink_send_pdu( - &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); -#if PRINT_ENABLED + bytes_sent = datalink_send_pdu( + &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { - fprintf( - stderr, "Failed to Send Who-Has Request (%s)!\n", strerror(errno)); + debug_perror("Failed to Send Who-Has Request"); } -#endif } diff --git a/src/bacnet/basic/service/s_whois.c b/src/bacnet/basic/service/s_whois.c index 25955353..29e3eb51 100644 --- a/src/bacnet/basic/service/s_whois.c +++ b/src/bacnet/basic/service/s_whois.c @@ -1,41 +1,38 @@ -/************************************************************************** - * - * Copyright (C) 2005 Steve Karg - * - * SPDX-License-Identifier: MIT - * - *********************************************************************/ +/** + * @file + * @brief Send BACnet Who-Is request. + * @author Steve Karg + * @date 2005 + * @copyright SPDX-License-Identifier: MIT + */ #include #include -#include #include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" /* BACnet Stack API */ #include "bacnet/bacdcode.h" -#include "bacnet/basic/binding/address.h" -#include "bacnet/basic/tsm/tsm.h" #include "bacnet/npdu.h" #include "bacnet/apdu.h" -#include "bacnet/basic/object/device.h" -#include "bacnet/datalink/datalink.h" #include "bacnet/dcc.h" #include "bacnet/whois.h" #include "bacnet/bacenum.h" /* some demo stuff needed */ +#include "bacnet/basic/binding/address.h" #include "bacnet/basic/object/device.h" #include "bacnet/basic/services.h" +#include "bacnet/basic/sys/debug.h" #include "bacnet/basic/tsm/tsm.h" #include "bacnet/datalink/datalink.h" -/** @file s_whois.c Send a Who-Is request. */ - -/** Send a Who-Is request to a remote network for a specific device, a range, - * or any device. +/** + * @brief Send a Who-Is request to a remote network for a specific device, + * a range, or any device. * If low_limit and high_limit both are -1, then the range is unlimited. * If low_limit and high_limit have the same non-negative value, then only * that device will respond. * Otherwise, low_limit must be less than high_limit. + * @ingroup BIBB-DM-DDB-A * @param target_address [in] BACnet address of target router * @param low_limit [in] Device Instance Low Range, 0 - 4,194,303 or -1 * @param high_limit [in] Device Instance High Range, 0 - 4,194,303 or -1 @@ -61,21 +58,19 @@ void Send_WhoIs_To_Network( pdu_len += len; bytes_sent = datalink_send_pdu( target_address, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); -#if PRINT_ENABLED if (bytes_sent <= 0) { - fprintf( - stderr, "Failed to Send Who-Is Request (%s)!\n", strerror(errno)); + debug_perror("Failed to Send Who-Is Request"); } -#else - (void)bytes_sent; -#endif } -/** Send a global Who-Is request for a specific device, a range, or any device. +/** + * @brief Send a global Who-Is request for a specific device, a range, + * or any device. * If low_limit and high_limit both are -1, then the range is unlimited. * If low_limit and high_limit have the same non-negative value, then only * that device will respond. * Otherwise, low_limit must be less than high_limit. + * @ingroup BIBB-DM-DDB-A * @param low_limit [in] Device Instance Low Range, 0 - 4,194,303 or -1 * @param high_limit [in] Device Instance High Range, 0 - 4,194,303 or -1 */ @@ -93,11 +88,14 @@ void Send_WhoIs_Global(int32_t low_limit, int32_t high_limit) Send_WhoIs_To_Network(&dest, low_limit, high_limit); } -/** Send a local Who-Is request for a specific device, a range, or any device. +/** + * @brief Send a local Who-Is request for a specific device, a range, + * or any device. * If low_limit and high_limit both are -1, then the range is unlimited. * If low_limit and high_limit have the same non-negative value, then only * that device will respond. * Otherwise, low_limit must be less than high_limit. + * @ingroup BIBB-DM-DDB-A * @param low_limit [in] Device Instance Low Range, 0 - 4,194,303 or -1 * @param high_limit [in] Device Instance High Range, 0 - 4,194,303 or -1 */ @@ -109,9 +107,10 @@ void Send_WhoIs_Local(int32_t low_limit, int32_t high_limit) Send_WhoIs_To_Network(&dest, low_limit, high_limit); } -/** Send a Who-Is request to a remote network for a specific device, a range, - * or any device. - * @ingroup DMDDB +/** + * @brief Send a Who-Is request to a remote network for a specific device, + * a range, or any device. + * @ingroup BIBB-DM-DDB-A * If low_limit and high_limit both are -1, then the range is unlimited. * If low_limit and high_limit have the same non-negative value, then only * that device will respond. @@ -130,8 +129,10 @@ void Send_WhoIs_Remote( Send_WhoIs_To_Network(target_address, low_limit, high_limit); } -/** Send a global Who-Is request for a specific device, a range, or any device. - * @ingroup DMDDB +/** + * @brief Send a global Who-Is request for a specific device, a range, + * or any device. + * @ingroup BIBB-DM-DDB-A * This was the original Who-Is broadcast but the code was moved to the more * descriptive Send_WhoIs_Global when Send_WhoIs_Local and Send_WhoIsRemote was * added. diff --git a/src/bacnet/basic/service/s_wp.c b/src/bacnet/basic/service/s_wp.c index 4f3c890e..b0fb36f3 100644 --- a/src/bacnet/basic/service/s_wp.c +++ b/src/bacnet/basic/service/s_wp.c @@ -1,13 +1,12 @@ -/************************************************************************** - * - * Copyright (C) 2005 Steve Karg - * - * SPDX-License-Identifier: MIT - * - *********************************************************************/ +/** + * @file + * @brief Send BACnet WriteProperty-Request + * @author Steve Karg + * @date 2005 + * @copyright SPDX-License-Identifier: MIT + */ #include #include -#include #include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" @@ -21,12 +20,17 @@ #include "bacnet/basic/binding/address.h" #include "bacnet/basic/object/device.h" #include "bacnet/basic/services.h" +#include "bacnet/basic/sys/debug.h" #include "bacnet/basic/tsm/tsm.h" #include "bacnet/datalink/datalink.h" -/** @file s_wp.c Send a Write Property request. */ - -/** returns the invoke ID for confirmed request, or zero on failure */ +/** + * @brief Send a WriteProperty-Request service message + * @ingroup BIBB-DS-WP-A + * @param device_id [in] ID of the destination device + * @param data [in] The data representing the Life Safety Operation + * @return invoke id of outgoing message, or zero on failure. + */ uint8_t Send_Write_Property_Request_Data( uint32_t device_id, BACNET_OBJECT_TYPE object_type, @@ -51,7 +55,6 @@ uint8_t Send_Write_Property_Request_Data( if (!dcc_communication_enabled()) { return 0; } - /* is the device bound? */ status = address_get_by_device(device_id, &max_apdu, &dest); /* is there a tsm available? */ @@ -89,30 +92,24 @@ uint8_t Send_Write_Property_Request_Data( bytes_sent = datalink_send_pdu( &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { -#if PRINT_ENABLED - fprintf( - stderr, "Failed to Send WriteProperty Request (%s)!\n", - strerror(errno)); -#endif + debug_perror("Failed to Send WriteProperty Request"); } } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; -#if PRINT_ENABLED - fprintf( + debug_fprintf( stderr, "Failed to Send WriteProperty Request " "(exceeds destination maximum APDU)!\n"); -#endif } } return invoke_id; } -/** Sends a Write Property request. - * @ingroup DSWP - * +/** + * @brief Sends a Write Property request. + * @ingroup BIBB-DS-WP-A * @param device_id [in] ID of the destination device * @param object_type [in] Type of the object whose property is to be written. * @param object_instance [in] Instance # of the object to be written. @@ -138,15 +135,12 @@ uint8_t Send_Write_Property_Request( int apdu_len = 0, len = 0; while (object_value) { -#if PRINT_ENABLED_DEBUG - fprintf( - stderr, + debug_printf( "WriteProperty service: " "%s tag=%d\n", (object_value->context_specific ? "context" : "application"), (int)(object_value->context_specific ? object_value->context_tag : object_value->tag)); -#endif len = bacapp_encode_data(&application_data[apdu_len], object_value); if ((len + apdu_len) < MAX_APDU) { apdu_len += len; diff --git a/src/bacnet/basic/service/s_wpm.c b/src/bacnet/basic/service/s_wpm.c index 4551c990..b0febcd8 100644 --- a/src/bacnet/basic/service/s_wpm.c +++ b/src/bacnet/basic/service/s_wpm.c @@ -1,18 +1,12 @@ /** * @file + * @brief Send Write Property Multiple request * @author Daniel Blazevic * @date 2013 - * @brief Send Write Property Multiple request - * - * @section LICENSE - * - * Copyright (C) 2013 Daniel Blazevic - * - * SPDX-License-Identifier: MIT + * @copyright SPDX-License-Identifier: MIT */ #include #include -#include #include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" @@ -23,15 +17,16 @@ #include "bacnet/dcc.h" #include "bacnet/wpm.h" /* some demo stuff needed */ -#include "bacnet/datalink/datalink.h" #include "bacnet/basic/binding/address.h" #include "bacnet/basic/object/device.h" #include "bacnet/basic/services.h" +#include "bacnet/basic/sys/debug.h" #include "bacnet/basic/tsm/tsm.h" +#include "bacnet/datalink/datalink.h" -/** @file s_wpm.c Send Write Property Multiple request. */ - -/** Sends a Write Property Multiple request. +/** + * @brief Sends a Write Property Multiple request. + * @ingroup BIBB-DS-WPM-A * @param pdu [out] Buffer to build the outgoing message into * @param max_pdu [in] Length of the pdu buffer. * @param device_id [in] ID of the destination device @@ -53,9 +48,7 @@ uint8_t Send_Write_Property_Multiple_Request( bool status = false; int len = 0; int pdu_len = 0; -#if PRINT_ENABLED int bytes_sent = 0; -#endif BACNET_NPDU_DATA npdu_data; /* if we are forbidden to send, don't send! */ @@ -88,27 +81,17 @@ uint8_t Send_Write_Property_Multiple_Request( if ((unsigned)pdu_len < max_apdu) { tsm_set_confirmed_unsegmented_transaction( invoke_id, &dest, &npdu_data, &pdu[0], (uint16_t)pdu_len); -#if PRINT_ENABLED - bytes_sent = -#endif - datalink_send_pdu(&dest, &npdu_data, &pdu[0], pdu_len); -#if PRINT_ENABLED + bytes_sent = datalink_send_pdu(&dest, &npdu_data, &pdu[0], pdu_len); if (bytes_sent <= 0) { - fprintf( - stderr, - "Failed to Send WritePropertyMultiple Request (%s)!\n", - strerror(errno)); + debug_perror("Failed to Send WritePropertyMultiple Request"); } -#endif } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; -#if PRINT_ENABLED - fprintf( + debug_fprintf( stderr, "Failed to Send WritePropertyMultiple Request " "(exceeds destination maximum APDU)!\n"); -#endif } } diff --git a/src/bacnet/basic/service/s_write_group.c b/src/bacnet/basic/service/s_write_group.c index 5040de80..27454d93 100644 --- a/src/bacnet/basic/service/s_write_group.c +++ b/src/bacnet/basic/service/s_write_group.c @@ -7,7 +7,6 @@ */ #include #include -#include #include /* BACnet Stack defines - first */ #include "bacnet/bacdef.h" @@ -20,9 +19,17 @@ /* some demo stuff needed */ #include "bacnet/basic/binding/address.h" #include "bacnet/basic/services.h" +#include "bacnet/basic/sys/debug.h" #include "bacnet/basic/tsm/tsm.h" #include "bacnet/datalink/datalink.h" +/** + * @brief Sends a WriteGroup-Request + * @ingroup BIBB-DS-WG-A + * @param dest [in] BACNET_ADDRESS of the destination device + * @param data [in] The data representing the WriteGroup-Request + * @return bytes sent, or a negative value on error + */ int Send_Write_Group(BACNET_ADDRESS *dest, const BACNET_WRITE_GROUP_DATA *data) { int len = 0; @@ -51,11 +58,7 @@ int Send_Write_Group(BACNET_ADDRESS *dest, const BACNET_WRITE_GROUP_DATA *data) bytes_sent = datalink_send_pdu( dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { -#if PRINT_ENABLED - fprintf( - stderr, "Failed to Send WriteGroup-Request (%s)!\n", - strerror(errno)); -#endif + debug_perror("Failed to Send WriteGroup-Request"); } return bytes_sent; diff --git a/src/bacnet/basic/sys/debug.c b/src/bacnet/basic/sys/debug.c index 7f15d57a..eb38fdeb 100644 --- a/src/bacnet/basic/sys/debug.c +++ b/src/bacnet/basic/sys/debug.c @@ -7,9 +7,12 @@ */ #include /* for standard integer types uint8_t etc. */ #include /* for the standard bool type. */ +#include +#if PRINT_ENABLED || DEBUG_ENABLED #include /* Standard I/O */ #include /* Standard Library */ -#include +#include +#endif #if DEBUG_ENABLED #include #include @@ -72,6 +75,17 @@ void debug_printf(const char *format, ...) } #endif +/** + * @brief Print with a printf string that does nothing + * @param format - printf format string + * @param ... - variable arguments + * @note useful when used with defines such as DEBUG_PRINTF + */ +void debug_printf_disabled(const char *format, ...) +{ + (void)format; +} + /** * @brief print format with HEX dump of a buffer * @param offset - starting address to print to the left side @@ -140,7 +154,7 @@ void debug_printf_hex( * PRINT_ENABLED is non-zero * @return number of characters printed */ -int debug_aprintf(const char *format, ...) +int debug_printf_stdout(const char *format, ...) { int length = 0; #if PRINT_ENABLED @@ -183,13 +197,25 @@ int debug_fprintf(FILE *stream, const char *format, ...) } /** - * @brief Print with a perror string + * @brief Print with a fprintf string that does nothing * @param format - printf format string * @param ... - variable arguments - * @note This function is only available if - * PRINT_ENABLED is non-zero + * @note useful when used with defines such as DEBUG_PRINTF */ -void debug_perror(const char *format, ...) +int debug_fprintf_disabled(FILE *stream, const char *format, ...) +{ + (void)stream; + (void)format; + return 0; +} + +/** + * @brief debug printf to stderr when PRINT_ENABLED is non-zero + * @param format - printf format string + * @param ... - variable arguments + * @note This function is only available if PRINT_ENABLED is non-zero + */ +void debug_printf_stderr(const char *format, ...) { #if PRINT_ENABLED va_list ap; @@ -203,13 +229,30 @@ void debug_perror(const char *format, ...) #endif } +#if PRINT_ENABLED /** - * @brief Print with a printf string that does nothing + * @brief debug printf to stderr when PRINT_ENABLED is non-zero * @param format - printf format string * @param ... - variable arguments - * @note useful when used with defines such as PRINTF + * @note This function is only available if PRINT_ENABLED is non-zero */ -void debug_printf_disabled(const char *format, ...) +void debug_print(const char *message) { - (void)format; + fprintf(stderr, "%s", message); + fflush(stderr); } +#endif + +#if PRINT_ENABLED +/** + * @brief Prints a textual description of the error code currently + * stored in the system variable errno to stderr. + * @param s - pointer to a null-terminated string with explanatory message + * @note This function is only available if PRINT_ENABLED is non-zero + */ +void debug_perror(const char *message) +{ + perror(message); + fflush(stderr); +} +#endif diff --git a/src/bacnet/basic/sys/debug.h b/src/bacnet/basic/sys/debug.h index f080728c..5d82bd0b 100644 --- a/src/bacnet/basic/sys/debug.h +++ b/src/bacnet/basic/sys/debug.h @@ -28,11 +28,19 @@ extern "C" { BACNET_STACK_EXPORT void debug_printf(const char *format, ...); BACNET_STACK_EXPORT -int debug_aprintf(const char *format, ...); +void debug_printf_disabled(const char *format, ...); + +BACNET_STACK_EXPORT +int debug_printf_stdout(const char *format, ...); + BACNET_STACK_EXPORT int debug_fprintf(FILE *stream, const char *format, ...); BACNET_STACK_EXPORT -void debug_perror(const char *format, ...); +int debug_fprintf_disabled(FILE *stream, const char *format, ...); + +BACNET_STACK_EXPORT +void debug_printf_stderr(const char *format, ...); + BACNET_STACK_EXPORT void debug_printf_hex( uint32_t offset, @@ -41,8 +49,31 @@ void debug_printf_hex( const char *format, ...); +#if PRINT_ENABLED BACNET_STACK_EXPORT -void debug_printf_disabled(const char *format, ...); +void debug_print(const char *message); +#else +#define debug_print(message) ((void)0) +#endif + +#if PRINT_ENABLED +BACNET_STACK_EXPORT +void debug_perror(const char *message); +#else +#define debug_perror(message) ((void)0) +#endif + +#if PRINT_ENABLED +#define DEBUG_FPRINTF debug_fprintf +#else +#define DEBUG_FPRINTF debug_fprintf_disabled +#endif + +#if DEBUG_ENABLED +#define DEBUG_PRINTF debug_printf +#else +#define DEBUG_PRINTF debug_printf_disabled +#endif #ifdef __cplusplus } diff --git a/src/bacnet/datalink/bsc/bsc-datalink.c b/src/bacnet/datalink/bsc/bsc-datalink.c index 1bef723a..f90f5325 100644 --- a/src/bacnet/datalink/bsc/bsc-datalink.c +++ b/src/bacnet/datalink/bsc/bsc-datalink.c @@ -22,7 +22,7 @@ #include "bacnet/basic/object/sc_netport.h" #include "bacnet/basic/object/bacfile.h" -#define PRINTF debug_perror +#define PRINTF debug_printf_stderr #define DEBUG_BSC_DATALINK 0 #if DEBUG_BSC_DATALINK == 1 #define DEBUG_PRINTF debug_printf diff --git a/src/bacnet/datalink/bsc/bsc-util.c b/src/bacnet/datalink/bsc/bsc-util.c index 427caeb6..a13e3ff7 100644 --- a/src/bacnet/datalink/bsc/bsc-util.c +++ b/src/bacnet/datalink/bsc/bsc-util.c @@ -13,8 +13,8 @@ #include "bacnet/basic/sys/debug.h" #include -#define PRINTF debug_aprintf -#define PRINTF_ERR debug_perror +#define PRINTF debug_printf_stdout +#define PRINTF_ERR debug_printf_stderr /** * @brief Map websocket return code to BACnet/SC return code diff --git a/test/bacnet/basic/bbmd/src/main.c b/test/bacnet/basic/bbmd/src/main.c index 7856bc1a..27eada6b 100644 --- a/test/bacnet/basic/bbmd/src/main.c +++ b/test/bacnet/basic/bbmd/src/main.c @@ -68,7 +68,7 @@ uint16_t bip_receive( * @param mtu_len - the number of bytes of data to send * * @return Upon successful completion, returns the number of bytes sent. - * Otherwise, -1 shall be returned and errno set to indicate the error. + * Otherwise, -1 shall be returned to indicate the error. */ int bip_send_mpdu( const BACNET_IP_ADDRESS *dest, const uint8_t *mtu, uint16_t mtu_len) diff --git a/test/bacnet/basic/bbmd6/src/main.c b/test/bacnet/basic/bbmd6/src/main.c index d868c47c..bc75abd5 100644 --- a/test/bacnet/basic/bbmd6/src/main.c +++ b/test/bacnet/basic/bbmd6/src/main.c @@ -73,7 +73,7 @@ uint16_t bip6_receive( * @param mtu_len - the number of bytes of data to send * * @return Upon successful completion, returns the number of bytes sent. - * Otherwise, -1 shall be returned and errno set to indicate the error. + * Otherwise, -1 shall be returned to indicate the error. */ int bip6_send_mpdu( const BACNET_IP6_ADDRESS *dest, const uint8_t *mtu, uint16_t mtu_len) diff --git a/test/unit/bacnet/bacerror/src/main.c b/test/unit/bacnet/bacerror/src/main.c index 2db26d8d..3f95e0e8 100644 --- a/test/unit/bacnet/bacerror/src/main.c +++ b/test/unit/bacnet/bacerror/src/main.c @@ -5,8 +5,6 @@ */ #include "bacnet/bacerror.h" - -#include #include #include #include