Secure ReadProperty decoding and BACnetActionCommand (#702)

* Refactored and secured BACnetActionCommand codec into bacaction.c module for command object and added to bacapp module encode/decode with define for enabling and pseudo application tag for internal use.

* Simplified bacapp_data_len() and moved into bacdcode module as bacnet_enclosed_data_len() function.

* Secured ReadProperty-REQUEST and -ACK decoding.

* Removed deprecated Keylist_Key() functions from usage.

* Removed pseudo application datatypes from bacapp_data_decode() which only uses primitive application tag encoded values.

* Defined INT_MAX when it is not already defined by compiler or libc.

* Deprecated bacapp_decode_application_data_len() and bacapp_decode_context_data_len() as they are no longer used in any code in the library.

* Added BACnetScale to bacapp module. Improved complex property value decoding. Refactored bacapp_decode_known_property() function.

* Refactored and improved the bacapp_snprintf() function for printing EPICS.

* Fixed Lighting Output WriteProperty to handle known property decoding.
This commit is contained in:
Steve Karg
2024-07-25 17:12:08 -05:00
committed by GitHub
parent 923eaf2313
commit 4326128e72
191 changed files with 3856 additions and 2099 deletions
+50 -6
View File
@@ -8,12 +8,14 @@
#ifndef BACNET_APP_H
#define BACNET_APP_H
#include <stdarg.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
/* BACnet Stack defines - first */
#include "bacnet/bacdef.h"
/* BACnet Stack API */
#include "bacnet/bacaction.h"
#include "bacnet/bacdest.h"
#include "bacnet/bacint.h"
#include "bacnet/bacstr.h"
@@ -32,6 +34,19 @@
#endif
#endif
/** BACnetScale ::= CHOICE {
float-scale [0] REAL,
integer-scale [1] INTEGER
}
*/
typedef struct BACnetScale {
bool float_scale;
union {
float real_scale;
int32_t integer_scale;
} type;
} BACNET_SCALE;
struct BACnet_Application_Data_Value;
typedef struct BACnet_Application_Data_Value {
bool context_specific; /* true if context specific data */
@@ -125,6 +140,12 @@ typedef struct BACnet_Application_Data_Value {
#endif
#if defined (BACAPP_FDT_ENTRY)
BACNET_FDT_ENTRY FDT_Entry;
#endif
#if defined (BACAPP_ACTION_COMMAND)
BACNET_ACTION_LIST Action_Command;
#endif
#if defined (BACAPP_SCALE)
BACNET_SCALE Scale;
#endif
} type;
/* simple linked list if needed */
@@ -203,6 +224,12 @@ extern "C" {
uint8_t * apdu,
BACNET_APPLICATION_DATA_VALUE * value);
BACNET_STACK_EXPORT
int bacapp_encode_known_property(
uint8_t *apdu,
BACNET_APPLICATION_DATA_VALUE *value,
BACNET_OBJECT_TYPE object_type,
BACNET_PROPERTY_ID property);
BACNET_STACK_EXPORT
int bacapp_data_decode(
uint8_t * apdu,
uint32_t apdu_size,
@@ -241,6 +268,7 @@ extern "C" {
BACNET_APPLICATION_DATA_VALUE * value,
BACNET_PROPERTY_ID property);
BACNET_STACK_DEPRECATED("Use bacapp_encode_known_property() instead")
BACNET_STACK_EXPORT
int bacapp_encode_context_data(
uint8_t * apdu,
@@ -253,17 +281,25 @@ extern "C" {
uint8_t context_tag_number,
BACNET_APPLICATION_DATA_VALUE * value);
BACNET_STACK_DEPRECATED("Use bacapp_known_property_tag() instead")
BACNET_STACK_EXPORT
BACNET_APPLICATION_TAG bacapp_context_tag_type(
BACNET_PROPERTY_ID property,
uint8_t tag_number);
BACNET_STACK_DEPRECATED("Use bacapp_encode_known_property() instead")
BACNET_STACK_EXPORT
int bacapp_decode_generic_property(
uint8_t * apdu,
int max_apdu_len,
BACNET_APPLICATION_DATA_VALUE * value,
BACNET_PROPERTY_ID prop);
BACNET_STACK_EXPORT
int bacapp_decode_application_tag_value(
uint8_t *apdu,
size_t apdu_size,
BACNET_APPLICATION_TAG tag,
BACNET_APPLICATION_DATA_VALUE *value);
BACNET_STACK_EXPORT
int bacapp_decode_known_property(uint8_t *apdu,
int max_apdu_len,
@@ -281,24 +317,27 @@ extern "C" {
BACNET_APPLICATION_DATA_VALUE * dest_value,
BACNET_APPLICATION_DATA_VALUE * src_value);
/* returns the length of data between an opening tag and a closing tag.
Expects that the first octet contain the opening tag.
Include a value property identifier for context specific data
such as the value received in a WriteProperty request */
BACNET_STACK_DEPRECATED("Use bacnet_enclosed_data_length() instead")
BACNET_STACK_EXPORT
int bacapp_data_len(
uint8_t * apdu,
unsigned max_apdu_len,
BACNET_PROPERTY_ID property);
BACNET_STACK_DEPRECATED("Use bacnet_application_data_length() instead")
BACNET_STACK_EXPORT
int bacapp_decode_data_len(
uint8_t * apdu,
uint8_t tag_data_type,
uint32_t len_value_type);
BACNET_STACK_DEPRECATED("Use bacnet_enclosed_data_length() instead")
BACNET_STACK_EXPORT
int bacapp_decode_application_data_len(
uint8_t * apdu,
unsigned max_apdu_len);
BACNET_STACK_DEPRECATED("Use bacnet_enclosed_data_length() instead")
BACNET_STACK_EXPORT
int bacapp_decode_context_data_len(
uint8_t * apdu,
@@ -306,10 +345,15 @@ extern "C" {
BACNET_PROPERTY_ID property);
BACNET_STACK_EXPORT
int bacapp_snprintf(
char *buffer,
size_t count,
const char *format, ...);
BACNET_STACK_EXPORT
int bacapp_snprintf_shift(
int len,
char **buf,
size_t *buf_size);
size_t *buf_size);
BACNET_STACK_EXPORT
int bacapp_snprintf_value(
char *str,