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
This commit is contained in:
Steve Karg
2025-01-05 10:09:39 -06:00
committed by GitHub
parent 1f41e2c933
commit 94b3809a58
135 changed files with 1166 additions and 1609 deletions
+25 -62
View File
@@ -9,7 +9,6 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#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;