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
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#define PRINT_ENABLED 1
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
+1
View File
@@ -8,6 +8,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <errno.h>
#include "blinkt.h"
#define BLINKT_DEFAULT_BRIGHTNESS 7
-2
View File
@@ -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 */
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#define PRINT_ENABLED 1
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#define PRINT_ENABLED 1
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
-1
View File
@@ -14,7 +14,6 @@
#if (__STDC_VERSION__ >= 199901L) && defined(__STDC_ISO_10646__)
#include <locale.h>
#endif
#include <errno.h>
#include <assert.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-2
View File
@@ -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);
-2
View File
@@ -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);
-2
View File
@@ -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,
-1
View File
@@ -11,7 +11,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -12,7 +12,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
+1
View File
@@ -1,3 +1,4 @@
#include <errno.h>
#include <time.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
-2
View File
@@ -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,
+16 -26
View File
@@ -9,7 +9,6 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
/* 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;
}
-1
View File
@@ -9,7 +9,6 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -10,7 +10,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h> /* for time */
#include <ctype.h> /* for tupper */
#if defined(WIN32) || defined(__BORLANDC__)
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
#include <ctype.h> /* for toupper */
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
#include <ctype.h> /* for toupper */
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -11,7 +11,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h> /* for time */
#if (__STDC_VERSION__ >= 199901L) && defined(__STDC_ISO_10646__)
#include <locale.h>
-1
View File
@@ -11,7 +11,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h> /* for time */
#if (__STDC_VERSION__ >= 199901L) && defined(__STDC_ISO_10646__)
#include <locale.h>
-1
View File
@@ -12,7 +12,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h> /* for time */
#if (__STDC_VERSION__ >= 199901L) && defined(__STDC_ISO_10646__)
#include <locale.h>
-1
View File
@@ -12,7 +12,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#define PRINT_ENABLED 1
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
-1
View File
@@ -18,7 +18,6 @@
#include <stdlib.h>
#include <string.h>
#include <time.h> /* for time */
#include <errno.h>
#include <assert.h>
#include <fcntl.h>
#include <libconfig.h> /* read config files */
-1
View File
@@ -9,7 +9,6 @@
* SPDX-License-Identifier: MIT
*/
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <pthread.h>
+12 -21
View File
@@ -12,7 +12,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h> /* for time */
#include <ctype.h> /* 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);
+1 -1
View File
@@ -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;
+3 -3
View File
@@ -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"
-1
View File
@@ -12,7 +12,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -10,7 +10,6 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h> /* for time */
#include <ctype.h> /* for toupper */
#define PRINT_ENABLED 1
-1
View File
@@ -11,7 +11,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -13,7 +13,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -13,7 +13,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -12,7 +12,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -13,7 +13,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
#include <ctype.h> /* for toupper */
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
-1
View File
@@ -12,7 +12,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#include <errno.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
-1
View File
@@ -15,7 +15,6 @@
#include <stdlib.h>
#include <time.h> /* for time */
#include <string.h>
#include <errno.h>
#include <ctype.h> /* toupper */
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
-1
View File
@@ -14,7 +14,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <time.h> /* for time */
#define PRINT_ENABLED 1
/* BACnet Stack defines - first */