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:
@@ -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 */
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user