Added a basic example Auditlog object. (#458)
Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
+2
@@ -178,6 +178,7 @@
|
|||||||
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\ai.c" />
|
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\ai.c" />
|
||||||
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\ao.c" />
|
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\ao.c" />
|
||||||
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\av.c" />
|
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\av.c" />
|
||||||
|
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\auditlog.c" />
|
||||||
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\bacfile.c" />
|
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\bacfile.c" />
|
||||||
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\bi.c" />
|
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\bi.c" />
|
||||||
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\bo.c" />
|
<ClCompile Include="..\..\..\..\src\bacnet\basic\object\bo.c" />
|
||||||
@@ -207,6 +208,7 @@
|
|||||||
<ClInclude Include="..\..\..\..\src\bacnet\basic\object\ai.h" />
|
<ClInclude Include="..\..\..\..\src\bacnet\basic\object\ai.h" />
|
||||||
<ClInclude Include="..\..\..\..\src\bacnet\basic\object\ao.h" />
|
<ClInclude Include="..\..\..\..\src\bacnet\basic\object\ao.h" />
|
||||||
<ClInclude Include="..\..\..\..\src\bacnet\basic\object\av.h" />
|
<ClInclude Include="..\..\..\..\src\bacnet\basic\object\av.h" />
|
||||||
|
<ClInclude Include="..\..\..\..\src\bacnet\basic\object\auditlog.h" />
|
||||||
<ClInclude Include="..\..\..\..\src\bacnet\basic\object\bacfile.h" />
|
<ClInclude Include="..\..\..\..\src\bacnet\basic\object\bacfile.h" />
|
||||||
<ClInclude Include="..\..\..\..\src\bacnet\basic\object\bi.h" />
|
<ClInclude Include="..\..\..\..\src\bacnet\basic\object\bi.h" />
|
||||||
<ClInclude Include="..\..\..\..\src\bacnet\basic\object\bo.h" />
|
<ClInclude Include="..\..\..\..\src\bacnet\basic\object\bo.h" />
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,258 @@
|
|||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief API for BACnetAuditNotification and BACnetAuditLogRecord codec used
|
||||||
|
* by Audit Log objects
|
||||||
|
* @author Mikhail Antropov <michail.antropov@dsr-corporation.com>
|
||||||
|
* @author Steve Karg <skarg@users.sourceforge.net>
|
||||||
|
* @date November 2024
|
||||||
|
* @copyright SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
#ifndef BACNET_AUDIT_H
|
||||||
|
#define BACNET_AUDIT_H
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
/* BACnet Stack defines - first */
|
||||||
|
#include "bacnet/bacdef.h"
|
||||||
|
/* BACnet Stack API */
|
||||||
|
#include "bacnet/bacdest.h"
|
||||||
|
#include "bacnet/cov.h"
|
||||||
|
#include "bacnet/datetime.h"
|
||||||
|
#include "bacnet/bacdevobjpropref.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Container to hold the target value or current value
|
||||||
|
* @note This must be a separate struct from BACapp to avoid
|
||||||
|
* recursive a recursive include.
|
||||||
|
* @note This is a union to save space. The application tag
|
||||||
|
* is used to determine which type is used.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
typedef struct BACnet_Audit_Value {
|
||||||
|
uint8_t tag; /* application tag data type */
|
||||||
|
union {
|
||||||
|
/* NULL - not needed as it is encoded in the tag alone */
|
||||||
|
bool boolean_value;
|
||||||
|
float real_value;
|
||||||
|
uint32_t enumerated_value;
|
||||||
|
uint32_t unsigned_value;
|
||||||
|
int32_t integer_value;
|
||||||
|
/* note: use ifdef for values larger than 32-bits are supported */
|
||||||
|
} type;
|
||||||
|
} BACNET_AUDIT_VALUE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Storage structures for Audit Log record
|
||||||
|
*
|
||||||
|
* @note I've tried to minimize the storage requirements here
|
||||||
|
* as the memory requirements for logging in embedded
|
||||||
|
* implementations are frequently a big issue. For PC or
|
||||||
|
* embedded Linux type setupz this may seem like overkill
|
||||||
|
* but if you have limited memory and need to squeeze as much
|
||||||
|
* logging capacity as possible every little byte counts!
|
||||||
|
*/
|
||||||
|
#if !( \
|
||||||
|
defined(BACNET_AUDIT_NOTIFICATION_MINIMAL_ENABLE) || \
|
||||||
|
defined(BACNET_AUDIT_NOTIFICATION_OPTIONAL_ENABLE) || \
|
||||||
|
defined(BACNET_AUDIT_NOTIFICATION_SOURCE_TIMESTAMP_ENABLE) || \
|
||||||
|
defined(BACNET_AUDIT_NOTIFICATION_TARGET_TIMESTAMP_ENABLE) || \
|
||||||
|
defined(BACNET_AUDIT_NOTIFICATION_SOURCE_OBJECT_ENABLE) || \
|
||||||
|
defined(BACNET_AUDIT_NOTIFICATION_SOURCE_COMMENT_ENABLE) || \
|
||||||
|
defined(BACNET_AUDIT_NOTIFICATION_TARGET_COMMENT_ENABLE) || \
|
||||||
|
defined(BACNET_AUDIT_NOTIFICATION_INVOKE_ID_ENABLE) || \
|
||||||
|
defined(BACNET_AUDIT_NOTIFICATION_SOURCE_USER_ID_ENABLE) || \
|
||||||
|
defined(BACNET_AUDIT_NOTIFICATION_SOURCE_USER_ROLE_ENABLE) || \
|
||||||
|
defined(BACNET_AUDIT_NOTIFICATION_TARGET_OBJECT_ENABLE) || \
|
||||||
|
defined(BACNET_AUDIT_NOTIFICATION_TARGET_PROPERTY_ENABLE) || \
|
||||||
|
defined(BACNET_AUDIT_NOTIFICATION_TARGET_PRIORITY_ENABLE) || \
|
||||||
|
defined(BACNET_AUDIT_NOTIFICATION_TARGET_VALUE_ENABLE) || \
|
||||||
|
defined(BACNET_AUDIT_NOTIFICATION_CURRENT_VALUE_ENABLE) || \
|
||||||
|
defined(BACNET_AUDIT_NOTIFICATION_RESULT_ENABLE))
|
||||||
|
#define BACNET_AUDIT_NOTIFICATION_OPTIONAL_ENABLE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef BACNET_AUDIT_NOTIFICATION_OPTIONAL_ENABLE
|
||||||
|
#define BACNET_AUDIT_NOTIFICATION_SOURCE_TIMESTAMP_ENABLE
|
||||||
|
#define BACNET_AUDIT_NOTIFICATION_TARGET_TIMESTAMP_ENABLE
|
||||||
|
#define BACNET_AUDIT_NOTIFICATION_SOURCE_OBJECT_ENABLE
|
||||||
|
#define BACNET_AUDIT_NOTIFICATION_SOURCE_COMMENT_ENABLE
|
||||||
|
#define BACNET_AUDIT_NOTIFICATION_TARGET_COMMENT_ENABLE
|
||||||
|
#define BACNET_AUDIT_NOTIFICATION_INVOKE_ID_ENABLE
|
||||||
|
#define BACNET_AUDIT_NOTIFICATION_SOURCE_USER_ID_ENABLE
|
||||||
|
#define BACNET_AUDIT_NOTIFICATION_SOURCE_USER_ROLE_ENABLE
|
||||||
|
#define BACNET_AUDIT_NOTIFICATION_TARGET_OBJECT_ENABLE
|
||||||
|
#define BACNET_AUDIT_NOTIFICATION_TARGET_PROPERTY_ENABLE
|
||||||
|
#define BACNET_AUDIT_NOTIFICATION_TARGET_PRIORITY_ENABLE
|
||||||
|
#define BACNET_AUDIT_NOTIFICATION_TARGET_VALUE_ENABLE
|
||||||
|
#define BACNET_AUDIT_NOTIFICATION_CURRENT_VALUE_ENABLE
|
||||||
|
#define BACNET_AUDIT_NOTIFICATION_RESULT_ENABLE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* BACnetAuditNotification ::= SEQUENCE {
|
||||||
|
* source-timestamp [0] BACnetTimeStamp OPTIONAL,
|
||||||
|
* target-timestamp [1] BACnetTimeStamp OPTIONAL,
|
||||||
|
* source-device [2] BACnetRecipient,
|
||||||
|
* source-object [3] BACnetObjectIdentifier OPTIONAL,
|
||||||
|
* operation [4] BACnetAuditOperation,
|
||||||
|
* source-comment [5] CharacterString OPTIONAL,
|
||||||
|
* target-comment [6] CharacterString OPTIONAL,
|
||||||
|
* invoke-id [7] Unsigned8 OPTIONAL,
|
||||||
|
* source-user-id [8] Unsigned16 OPTIONAL,
|
||||||
|
* source-user-role [9] Unsigned8 OPTIONAL,
|
||||||
|
* target-device [10] BACnetRecipient,
|
||||||
|
* target-object [11] BACnetObjectIdentifier OPTIONAL,
|
||||||
|
* target-property [12] BACnetPropertyReference OPTIONAL,
|
||||||
|
* target-priority [13] Unsigned (1..16) OPTIONAL,
|
||||||
|
* target-value [14] ABSTRACT-SYNTAX.&Type OPTIONAL,
|
||||||
|
* current-value [15] ABSTRACT-SYNTAX.&Type OPTIONAL,
|
||||||
|
* result [16] Error OPTIONAL
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
typedef struct BACnetAuditNotification {
|
||||||
|
#ifdef BACNET_AUDIT_NOTIFICATION_SOURCE_TIMESTAMP_ENABLE
|
||||||
|
/* source-timestamp [0] BACnetTimeStamp OPTIONAL */
|
||||||
|
BACNET_TIMESTAMP source_timestamp;
|
||||||
|
#endif
|
||||||
|
#ifdef BACNET_AUDIT_NOTIFICATION_TARGET_TIMESTAMP_ENABLE
|
||||||
|
/* target-timestamp [1] BACnetTimeStamp OPTIONAL */
|
||||||
|
BACNET_TIMESTAMP target_timestamp;
|
||||||
|
#endif
|
||||||
|
/* source-device [2] BACnetRecipient */
|
||||||
|
BACNET_RECIPIENT source_device;
|
||||||
|
#ifdef BACNET_AUDIT_NOTIFICATION_SOURCE_OBJECT_ENABLE
|
||||||
|
/* source-object [3] BACnetObjectIdentifier OPTIONAL */
|
||||||
|
BACNET_OBJECT_ID source_object;
|
||||||
|
#endif
|
||||||
|
/* operation [4] BACnetAuditOperation */
|
||||||
|
uint8_t operation;
|
||||||
|
#ifdef BACNET_AUDIT_NOTIFICATION_SOURCE_COMMENT_ENABLE
|
||||||
|
/* source-comment [5] CharacterString OPTIONAL */
|
||||||
|
BACNET_CHARACTER_STRING source_comment;
|
||||||
|
#endif
|
||||||
|
#ifdef BACNET_AUDIT_NOTIFICATION_TARGET_COMMENT_ENABLE
|
||||||
|
/* target-comment [6] CharacterString OPTIONAL */
|
||||||
|
BACNET_CHARACTER_STRING target_comment;
|
||||||
|
#endif
|
||||||
|
#ifdef BACNET_AUDIT_NOTIFICATION_INVOKE_ID_ENABLE
|
||||||
|
/* invoke-id [7] Unsigned8 OPTIONAL */
|
||||||
|
uint8_t invoke_id;
|
||||||
|
#endif
|
||||||
|
#ifdef BACNET_AUDIT_NOTIFICATION_SOURCE_USER_ID_ENABLE
|
||||||
|
/* source-user-id [8] Unsigned16 OPTIONAL */
|
||||||
|
uint16_t source_user_id;
|
||||||
|
#endif
|
||||||
|
#ifdef BACNET_AUDIT_NOTIFICATION_SOURCE_USER_ROLE_ENABLE
|
||||||
|
/* source-user-role [9] Unsigned8 OPTIONAL */
|
||||||
|
uint8_t source_user_role;
|
||||||
|
#endif
|
||||||
|
/* target-device [10] BACnetRecipient */
|
||||||
|
BACNET_RECIPIENT target_device;
|
||||||
|
#ifdef BACNET_AUDIT_NOTIFICATION_TARGET_OBJECT_ENABLE
|
||||||
|
/* target-object [11] BACnetObjectIdentifier OPTIONAL */
|
||||||
|
BACNET_OBJECT_ID target_object;
|
||||||
|
#endif
|
||||||
|
#ifdef BACNET_AUDIT_NOTIFICATION_TARGET_PROPERTY_ENABLE
|
||||||
|
/* target-property [12] BACnetPropertyReference OPTIONAL */
|
||||||
|
struct BACnetPropertyReference target_property;
|
||||||
|
#endif
|
||||||
|
#ifdef BACNET_AUDIT_NOTIFICATION_TARGET_PRIORITY_ENABLE
|
||||||
|
/* target-priority [13] Unsigned (1..16) OPTIONAL */
|
||||||
|
uint8_t target_priority;
|
||||||
|
#endif
|
||||||
|
#ifdef BACNET_AUDIT_NOTIFICATION_TARGET_VALUE_ENABLE
|
||||||
|
/* target-value [14] ABSTRACT-SYNTAX.&Type OPTIONAL */
|
||||||
|
BACNET_AUDIT_VALUE target_value;
|
||||||
|
#endif
|
||||||
|
#ifdef BACNET_AUDIT_NOTIFICATION_CURRENT_VALUE_ENABLE
|
||||||
|
/* current-value [15] ABSTRACT-SYNTAX.&Type OPTIONAL */
|
||||||
|
BACNET_AUDIT_VALUE current_value;
|
||||||
|
#endif
|
||||||
|
#ifdef BACNET_AUDIT_NOTIFICATION_RESULT_ENABLE
|
||||||
|
/* result [16] Error OPTIONAL */
|
||||||
|
BACNET_ERROR_CODE result;
|
||||||
|
#endif
|
||||||
|
} BACNET_AUDIT_NOTIFICATION;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Datum types associated with a BACnetAuditLogRecord.
|
||||||
|
* The tag numbers are used when encoding or decoding the log_datum field.
|
||||||
|
*/
|
||||||
|
#define AUDIT_LOG_DATUM_TAG_STATUS 0
|
||||||
|
#define AUDIT_LOG_DATUM_TAG_NOTIFICATION 1
|
||||||
|
#define AUDIT_LOG_DATUM_TAG_TIME_CHANGE 2
|
||||||
|
|
||||||
|
/*
|
||||||
|
* BACnetAuditLogRecord ::= SEQUENCE {
|
||||||
|
* timestamp [0] BACnetDateTime,
|
||||||
|
* log-datum [1] CHOICE {
|
||||||
|
* log-status [0] BACnetLogStatus,
|
||||||
|
* audit-notification [1] BACnetAuditNotification,
|
||||||
|
* time-change [2] REAL
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
typedef struct BACnetAuditLogRecord {
|
||||||
|
BACNET_DATE_TIME timestamp;
|
||||||
|
uint8_t tag;
|
||||||
|
union {
|
||||||
|
uint8_t log_status;
|
||||||
|
BACNET_AUDIT_NOTIFICATION notification;
|
||||||
|
float time_change;
|
||||||
|
} log_datum;
|
||||||
|
} BACNET_AUDIT_LOG_RECORD;
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
int bacnet_audit_log_record_encode(
|
||||||
|
uint8_t *apdu, const BACNET_AUDIT_LOG_RECORD *value);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
int bacnet_audit_log_record_decode(
|
||||||
|
const uint8_t *apdu, uint32_t apdu_size, BACNET_AUDIT_LOG_RECORD *value);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
bool bacnet_audit_log_record_same(
|
||||||
|
const BACNET_AUDIT_LOG_RECORD *value1,
|
||||||
|
const BACNET_AUDIT_LOG_RECORD *value2);
|
||||||
|
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
int bacnet_audit_log_notification_encode(
|
||||||
|
uint8_t *apdu, const BACNET_AUDIT_NOTIFICATION *value);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
int bacnet_audit_log_notification_decode(
|
||||||
|
const uint8_t *apdu, uint32_t apdu_size, BACNET_AUDIT_NOTIFICATION *value);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
int bacnet_audit_log_notification_context_decode(
|
||||||
|
const uint8_t *apdu,
|
||||||
|
uint16_t apdu_size,
|
||||||
|
uint8_t tag_number,
|
||||||
|
BACNET_AUDIT_NOTIFICATION *value);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
bool bacnet_audit_log_notification_same(
|
||||||
|
const BACNET_AUDIT_NOTIFICATION *value1,
|
||||||
|
const BACNET_AUDIT_NOTIFICATION *value2);
|
||||||
|
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
int bacnet_audit_value_encode(uint8_t *apdu, const BACNET_AUDIT_VALUE *value);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
int bacnet_audit_value_context_encode(
|
||||||
|
uint8_t *apdu, uint8_t tag_number, const BACNET_AUDIT_VALUE *value);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
int bacnet_audit_value_decode(
|
||||||
|
const uint8_t *apdu, uint32_t apdu_size, BACNET_AUDIT_VALUE *value);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
int bacnet_audit_value_context_decode(
|
||||||
|
const uint8_t *apdu,
|
||||||
|
uint16_t apdu_size,
|
||||||
|
uint8_t tag_number,
|
||||||
|
BACNET_AUDIT_VALUE *value);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
bool bacnet_audit_value_same(
|
||||||
|
const BACNET_AUDIT_VALUE *value1, const BACNET_AUDIT_VALUE *value2);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
#endif
|
||||||
@@ -1861,7 +1861,8 @@ typedef enum BACnetStatusFlags {
|
|||||||
typedef enum BACnetLogStatus {
|
typedef enum BACnetLogStatus {
|
||||||
LOG_STATUS_LOG_DISABLED = 0,
|
LOG_STATUS_LOG_DISABLED = 0,
|
||||||
LOG_STATUS_BUFFER_PURGED = 1,
|
LOG_STATUS_BUFFER_PURGED = 1,
|
||||||
LOG_STATUS_LOG_INTERRUPTED = 2
|
LOG_STATUS_LOG_INTERRUPTED = 2,
|
||||||
|
LOG_STATUS_MAX = 3
|
||||||
} BACNET_LOG_STATUS;
|
} BACNET_LOG_STATUS;
|
||||||
|
|
||||||
typedef enum BACnetLoggingType {
|
typedef enum BACnetLoggingType {
|
||||||
@@ -3123,7 +3124,8 @@ typedef enum BACnetAuditOperation {
|
|||||||
The enumerated values match the bit positions in
|
The enumerated values match the bit positions in
|
||||||
BACnetAuditOperationFlags. */
|
BACnetAuditOperationFlags. */
|
||||||
AUDIT_OPERATION_PROPRIETARY_MIN = 32,
|
AUDIT_OPERATION_PROPRIETARY_MIN = 32,
|
||||||
AUDIT_OPERATION_PROPRIETARY_MAX = 63
|
AUDIT_OPERATION_PROPRIETARY_MAX = 63,
|
||||||
|
AUDIT_OPERATION_MAX = 64
|
||||||
} BACNET_AUDIT_OPERATION;
|
} BACNET_AUDIT_OPERATION;
|
||||||
|
|
||||||
typedef enum BACnetSCHubConnectorState {
|
typedef enum BACnetSCHubConnectorState {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,124 @@
|
|||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @author Mikhail Antropov <michail.antropov@dsr-corporation.com>
|
||||||
|
* @date Jul 2023
|
||||||
|
* @brief Auditlog object, customize for your use
|
||||||
|
*
|
||||||
|
* @section DESCRIPTION
|
||||||
|
*
|
||||||
|
* An Audit Log object combines audit notifications from operation sources and
|
||||||
|
* operation targets and stores the combined record in an internal buffer for
|
||||||
|
* subsequent retrieval. Each timestamped buffer entry is called an audit log
|
||||||
|
* "record."
|
||||||
|
*
|
||||||
|
* @section LICENSE
|
||||||
|
*
|
||||||
|
* Copyright (C) 2023 Steve Karg <skarg@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
#ifndef AUDITLOG_H
|
||||||
|
#define AUDITLOG_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
/* BACnet Stack defines - first */
|
||||||
|
#include "bacnet/bacdef.h"
|
||||||
|
/* BACnet Stack API */
|
||||||
|
#include "bacnet/bacaudit.h"
|
||||||
|
#include "bacnet/bacdest.h"
|
||||||
|
#include "bacnet/cov.h"
|
||||||
|
#include "bacnet/datetime.h"
|
||||||
|
#include "bacnet/readrange.h"
|
||||||
|
#include "bacnet/rp.h"
|
||||||
|
#include "bacnet/wp.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
void Audit_Log_Property_Lists(
|
||||||
|
const int **pRequired, const int **pOptional, const int **pProprietary);
|
||||||
|
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
bool Audit_Log_Valid_Instance(uint32_t object_instance);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
unsigned Audit_Log_Count(void);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
uint32_t Audit_Log_Index_To_Instance(unsigned index);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
unsigned Audit_Log_Instance_To_Index(uint32_t instance);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
bool Audit_Log_Object_Instance_Add(uint32_t instance);
|
||||||
|
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
bool Audit_Log_Object_Name(
|
||||||
|
uint32_t object_instance, BACNET_CHARACTER_STRING *object_name);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
bool Audit_Log_Name_Set(uint32_t object_instance, const char *new_name);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
const char *Audit_Log_Name_ASCII(uint32_t object_instance);
|
||||||
|
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
const char *Audit_Log_Description(uint32_t instance);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
bool Audit_Log_Description_Set(uint32_t instance, const char *new_name);
|
||||||
|
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
int Audit_Log_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
bool Audit_Log_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
uint32_t Audit_Log_Create(uint32_t object_instance);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
bool Audit_Log_Delete(uint32_t object_instance);
|
||||||
|
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
void Audit_Log_Cleanup(void);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
void Audit_Log_Init(void);
|
||||||
|
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
uint32_t Audit_Log_Buffer_Size(uint32_t object_instance);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
bool Audit_Log_Buffer_Size_Set(uint32_t object_instance, uint32_t buffer_size);
|
||||||
|
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
uint32_t Audit_Log_Record_Count(uint32_t object_instance);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
uint32_t Audit_Log_Total_Record_Count(uint32_t object_instance);
|
||||||
|
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
void Audit_Log_Record_Status_Insert(
|
||||||
|
uint32_t instance, BACNET_LOG_STATUS eStatus, bool bState);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
void Audit_Log_Record_Notification_Insert(
|
||||||
|
uint32_t instance, BACNET_AUDIT_NOTIFICATION *notification);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
BACNET_AUDIT_LOG_RECORD *
|
||||||
|
Audit_Log_Record_Entry(uint32_t object_instance, uint32_t index);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
void Audit_Log_Record_Entry_Delete(uint32_t object_instance, uint32_t index);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
bool Audit_Log_Record_Entry_Add(
|
||||||
|
uint32_t object_instance, const BACNET_AUDIT_LOG_RECORD *value);
|
||||||
|
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
bool Audit_Log_Enable(uint32_t instance);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
bool Audit_Log_Enable_Set(uint32_t object_instance, bool enable);
|
||||||
|
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
int Audit_Log_Read_Range_By_Position(BACNET_READ_RANGE_DATA *pRequest);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
int Audit_Log_Read_Range_By_Sequence(BACNET_READ_RANGE_DATA *pRequest);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
int Audit_Log_Read_Range_By_Time(BACNET_READ_RANGE_DATA *pRequest);
|
||||||
|
BACNET_STACK_EXPORT
|
||||||
|
int Audit_Log_Read_Range(uint8_t *apdu, BACNET_READ_RANGE_DATA *pRequest);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
#endif
|
||||||
@@ -2688,6 +2688,45 @@ static const int Trend_Log_Multiple_Properties_Optional[] = {
|
|||||||
-1
|
-1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const int Audit_Log_Properties_Required[] = {
|
||||||
|
/* unordered list of properties */
|
||||||
|
PROP_OBJECT_IDENTIFIER,
|
||||||
|
PROP_OBJECT_NAME,
|
||||||
|
PROP_OBJECT_TYPE,
|
||||||
|
PROP_STATUS_FLAGS,
|
||||||
|
PROP_EVENT_STATE,
|
||||||
|
PROP_ENABLE,
|
||||||
|
PROP_BUFFER_SIZE,
|
||||||
|
PROP_LOG_BUFFER,
|
||||||
|
PROP_RECORD_COUNT,
|
||||||
|
PROP_TOTAL_RECORD_COUNT,
|
||||||
|
-1
|
||||||
|
};
|
||||||
|
|
||||||
|
static const int Audit_Log_Properties_Optional[] = {
|
||||||
|
/* unordered list of properties */
|
||||||
|
PROP_DESCRIPTION,
|
||||||
|
PROP_RELIABILITY,
|
||||||
|
PROP_MEMBER_OF,
|
||||||
|
PROP_DELETE_ON_FORWARD,
|
||||||
|
PROP_ISSUE_CONFIRMED_NOTIFICATIONS,
|
||||||
|
PROP_EVENT_DETECTION_ENABLE,
|
||||||
|
PROP_NOTIFICATION_CLASS,
|
||||||
|
PROP_EVENT_ENABLE,
|
||||||
|
PROP_ACKED_TRANSITIONS,
|
||||||
|
PROP_NOTIFY_TYPE,
|
||||||
|
PROP_EVENT_TIME_STAMPS,
|
||||||
|
PROP_EVENT_MESSAGE_TEXTS,
|
||||||
|
PROP_EVENT_MESSAGE_TEXTS_CONFIG,
|
||||||
|
PROP_RELIABILITY_EVALUATION_INHIBIT,
|
||||||
|
PROP_AUDIT_LEVEL,
|
||||||
|
PROP_AUDITABLE_OPERATIONS,
|
||||||
|
PROP_TAGS,
|
||||||
|
PROP_PROFILE_LOCATION,
|
||||||
|
PROP_PROFILE_NAME,
|
||||||
|
-1
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function that returns the list of all Optional properties
|
* Function that returns the list of all Optional properties
|
||||||
* of known standard objects.
|
* of known standard objects.
|
||||||
@@ -2891,6 +2930,9 @@ const int *property_list_optional(BACNET_OBJECT_TYPE object_type)
|
|||||||
case OBJECT_TREND_LOG_MULTIPLE:
|
case OBJECT_TREND_LOG_MULTIPLE:
|
||||||
pList = Trend_Log_Multiple_Properties_Optional;
|
pList = Trend_Log_Multiple_Properties_Optional;
|
||||||
break;
|
break;
|
||||||
|
case OBJECT_AUDIT_LOG:
|
||||||
|
pList = Audit_Log_Properties_Optional;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
pList = Default_Properties_Optional;
|
pList = Default_Properties_Optional;
|
||||||
break;
|
break;
|
||||||
@@ -3102,6 +3144,9 @@ const int *property_list_required(BACNET_OBJECT_TYPE object_type)
|
|||||||
case OBJECT_TREND_LOG_MULTIPLE:
|
case OBJECT_TREND_LOG_MULTIPLE:
|
||||||
pList = Trend_Log_Multiple_Properties_Required;
|
pList = Trend_Log_Multiple_Properties_Required;
|
||||||
break;
|
break;
|
||||||
|
case OBJECT_AUDIT_LOG:
|
||||||
|
pList = Audit_Log_Properties_Required;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
pList = Default_Properties_Required;
|
pList = Default_Properties_Required;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ list(APPEND testdirs
|
|||||||
bacnet/awf
|
bacnet/awf
|
||||||
bacnet/bacaddr
|
bacnet/bacaddr
|
||||||
bacnet/bacapp
|
bacnet/bacapp
|
||||||
|
bacnet/bacaudit
|
||||||
bacnet/bacdcode
|
bacnet/bacdcode
|
||||||
bacnet/bacdevobjpropref
|
bacnet/bacdevobjpropref
|
||||||
bacnet/bacdest
|
bacnet/bacdest
|
||||||
@@ -143,6 +144,7 @@ list(APPEND testdirs
|
|||||||
bacnet/basic/object/ai
|
bacnet/basic/object/ai
|
||||||
bacnet/basic/object/ao
|
bacnet/basic/object/ao
|
||||||
bacnet/basic/object/av
|
bacnet/basic/object/av
|
||||||
|
bacnet/basic/object/auditlog
|
||||||
bacnet/basic/object/bacfile
|
bacnet/basic/object/bacfile
|
||||||
bacnet/basic/object/bi
|
bacnet/basic/object/bi
|
||||||
bacnet/basic/object/bitstring_value
|
bacnet/basic/object/bitstring_value
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
|
||||||
|
|
||||||
|
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
|
||||||
|
project(test_${basename}
|
||||||
|
VERSION 1.0.0
|
||||||
|
LANGUAGES C)
|
||||||
|
|
||||||
|
|
||||||
|
string(REGEX REPLACE
|
||||||
|
"/test/bacnet/[a-zA-Z_/-]*$"
|
||||||
|
"/src"
|
||||||
|
SRC_DIR
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
string(REGEX REPLACE
|
||||||
|
"/test/bacnet/[a-zA-Z_/-]*$"
|
||||||
|
"/test"
|
||||||
|
TST_DIR
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
set(ZTST_DIR "${TST_DIR}/ztest/src")
|
||||||
|
|
||||||
|
add_compile_definitions(
|
||||||
|
BIG_ENDIAN=0
|
||||||
|
CONFIG_ZTEST=1
|
||||||
|
BACAPP_MINIMAL=1
|
||||||
|
BACAPP_DESTINATION=1
|
||||||
|
)
|
||||||
|
|
||||||
|
include_directories(
|
||||||
|
${SRC_DIR}
|
||||||
|
${TST_DIR}/ztest/include
|
||||||
|
)
|
||||||
|
|
||||||
|
add_executable(${PROJECT_NAME}
|
||||||
|
# File(s) under test
|
||||||
|
${SRC_DIR}/bacnet/bacaudit.c
|
||||||
|
# Support files and stubs (pathname alphabetical)
|
||||||
|
${SRC_DIR}/bacnet/access_rule.c
|
||||||
|
${SRC_DIR}/bacnet/bacaction.c
|
||||||
|
${SRC_DIR}/bacnet/bacaddr.c
|
||||||
|
${SRC_DIR}/bacnet/bacapp.c
|
||||||
|
${SRC_DIR}/bacnet/bacdcode.c
|
||||||
|
${SRC_DIR}/bacnet/bacdest.c
|
||||||
|
${SRC_DIR}/bacnet/bacdevobjpropref.c
|
||||||
|
${SRC_DIR}/bacnet/bacerror.c
|
||||||
|
${SRC_DIR}/bacnet/bacint.c
|
||||||
|
${SRC_DIR}/bacnet/bacreal.c
|
||||||
|
${SRC_DIR}/bacnet/bacstr.c
|
||||||
|
${SRC_DIR}/bacnet/bactext.c
|
||||||
|
${SRC_DIR}/bacnet/basic/sys/bigend.c
|
||||||
|
${SRC_DIR}/bacnet/datetime.c
|
||||||
|
${SRC_DIR}/bacnet/basic/sys/days.c
|
||||||
|
${SRC_DIR}/bacnet/indtext.c
|
||||||
|
${SRC_DIR}/bacnet/hostnport.c
|
||||||
|
${SRC_DIR}/bacnet/lighting.c
|
||||||
|
${SRC_DIR}/bacnet/timestamp.c
|
||||||
|
${SRC_DIR}/bacnet/timesync.c
|
||||||
|
${SRC_DIR}/bacnet/weeklyschedule.c
|
||||||
|
${SRC_DIR}/bacnet/bactimevalue.c
|
||||||
|
${SRC_DIR}/bacnet/dailyschedule.c
|
||||||
|
${SRC_DIR}/bacnet/calendar_entry.c
|
||||||
|
${SRC_DIR}/bacnet/special_event.c
|
||||||
|
${SRC_DIR}/bacnet/channel_value.c
|
||||||
|
${SRC_DIR}/bacnet/secure_connect.c
|
||||||
|
# Test and test library files
|
||||||
|
./src/main.c
|
||||||
|
${ZTST_DIR}/ztest_mock.c
|
||||||
|
${ZTST_DIR}/ztest.c
|
||||||
|
)
|
||||||
@@ -0,0 +1,259 @@
|
|||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief Unit test for for BACnetAuditNotification and BACnetAuditLogRecord
|
||||||
|
* @author Steve Karg <skarg@users.sourceforge.net>
|
||||||
|
* @date November 2024
|
||||||
|
* @copyright SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <zephyr/ztest.h>
|
||||||
|
#include <bacnet/bacaudit.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @addtogroup bacnet_tests
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(CONFIG_ZTEST_NEW_API)
|
||||||
|
ZTEST(bacnet_audit_tests, test_bacnet_audit_value)
|
||||||
|
#else
|
||||||
|
static void test_bacnet_audit_value(void)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
uint8_t apdu[MAX_APDU] = { 0 };
|
||||||
|
BACNET_AUDIT_VALUE value = { 0 }, test_value = { 0 };
|
||||||
|
int apdu_len = 0, null_len = 0, test_len = 0, tag_len = 0, value_len = 0;
|
||||||
|
uint8_t tag_number = 1;
|
||||||
|
bool status = false;
|
||||||
|
|
||||||
|
null_len = bacnet_audit_value_encode(NULL, &value);
|
||||||
|
apdu_len = bacnet_audit_value_encode(apdu, &value);
|
||||||
|
zassert_equal(apdu_len, null_len, NULL);
|
||||||
|
test_len = bacnet_audit_value_decode(apdu, apdu_len, &value);
|
||||||
|
zassert_equal(apdu_len, test_len, NULL);
|
||||||
|
zassert_true(bacnet_audit_value_same(&value, &test_value), NULL);
|
||||||
|
|
||||||
|
/* decoding, some negative tests */
|
||||||
|
test_len = bacnet_audit_value_decode(NULL, apdu_len, &test_value);
|
||||||
|
zassert_equal(test_len, BACNET_STATUS_ERROR, NULL);
|
||||||
|
test_len = bacnet_audit_value_decode(apdu, 0, &test_value);
|
||||||
|
zassert_equal(test_len, BACNET_STATUS_ERROR, NULL);
|
||||||
|
test_len = bacnet_audit_value_decode(apdu, apdu_len, NULL);
|
||||||
|
zassert_equal(test_len, BACNET_STATUS_ERROR, NULL);
|
||||||
|
/* out of range tag */
|
||||||
|
value.tag = 255;
|
||||||
|
apdu_len = bacnet_audit_value_encode(apdu, &value);
|
||||||
|
test_len = bacnet_audit_value_decode(apdu, apdu_len, &value);
|
||||||
|
zassert_equal(test_len, BACNET_STATUS_ERROR, NULL);
|
||||||
|
|
||||||
|
/* value type = boolean */
|
||||||
|
value.tag = BACNET_APPLICATION_TAG_BOOLEAN;
|
||||||
|
value.type.boolean_value = true;
|
||||||
|
null_len = bacnet_audit_value_encode(NULL, &value);
|
||||||
|
apdu_len = bacnet_audit_value_encode(apdu, &value);
|
||||||
|
zassert_equal(apdu_len, null_len, NULL);
|
||||||
|
test_len = bacnet_audit_value_decode(apdu, apdu_len, &test_value);
|
||||||
|
zassert_equal(apdu_len, test_len, NULL);
|
||||||
|
zassert_true(bacnet_audit_value_same(&value, &test_value), NULL);
|
||||||
|
|
||||||
|
/* value type = unsigned */
|
||||||
|
value.tag = BACNET_APPLICATION_TAG_UNSIGNED_INT;
|
||||||
|
value.type.unsigned_value = 1234;
|
||||||
|
null_len = bacnet_audit_value_encode(NULL, &value);
|
||||||
|
apdu_len = bacnet_audit_value_encode(apdu, &value);
|
||||||
|
zassert_equal(apdu_len, null_len, NULL);
|
||||||
|
test_len = bacnet_audit_value_decode(apdu, apdu_len, &test_value);
|
||||||
|
zassert_equal(apdu_len, test_len, NULL);
|
||||||
|
zassert_true(bacnet_audit_value_same(&value, &test_value), NULL);
|
||||||
|
|
||||||
|
/* value type = signed */
|
||||||
|
value.tag = BACNET_APPLICATION_TAG_SIGNED_INT;
|
||||||
|
value.type.integer_value = -1234;
|
||||||
|
null_len = bacnet_audit_value_encode(NULL, &value);
|
||||||
|
apdu_len = bacnet_audit_value_encode(apdu, &value);
|
||||||
|
zassert_equal(apdu_len, null_len, NULL);
|
||||||
|
test_len = bacnet_audit_value_decode(apdu, apdu_len, &test_value);
|
||||||
|
zassert_equal(apdu_len, test_len, NULL);
|
||||||
|
zassert_true(bacnet_audit_value_same(&value, &test_value), NULL);
|
||||||
|
|
||||||
|
/* value type = REAL */
|
||||||
|
value.tag = BACNET_APPLICATION_TAG_REAL;
|
||||||
|
value.type.real_value = 3.14159f;
|
||||||
|
null_len = bacnet_audit_value_encode(NULL, &value);
|
||||||
|
apdu_len = bacnet_audit_value_encode(apdu, &value);
|
||||||
|
zassert_equal(apdu_len, null_len, NULL);
|
||||||
|
test_len = bacnet_audit_value_decode(apdu, apdu_len, &test_value);
|
||||||
|
zassert_equal(apdu_len, test_len, NULL);
|
||||||
|
zassert_true(bacnet_audit_value_same(&value, &test_value), NULL);
|
||||||
|
|
||||||
|
/* value type = ENUMERATED */
|
||||||
|
value.tag = BACNET_APPLICATION_TAG_ENUMERATED;
|
||||||
|
value.type.enumerated_value = 1234;
|
||||||
|
null_len = bacnet_audit_value_encode(NULL, &value);
|
||||||
|
apdu_len = bacnet_audit_value_encode(apdu, &value);
|
||||||
|
zassert_equal(apdu_len, null_len, NULL);
|
||||||
|
test_len = bacnet_audit_value_decode(apdu, apdu_len, &test_value);
|
||||||
|
zassert_equal(apdu_len, test_len, NULL);
|
||||||
|
zassert_true(bacnet_audit_value_same(&value, &test_value), NULL);
|
||||||
|
|
||||||
|
/* negative tests */
|
||||||
|
null_len = bacnet_audit_value_encode(NULL, NULL);
|
||||||
|
zassert_equal(null_len, 0, NULL);
|
||||||
|
value.tag = 255;
|
||||||
|
null_len = bacnet_audit_value_encode(NULL, &value);
|
||||||
|
zassert_equal(null_len, 1, NULL);
|
||||||
|
|
||||||
|
/* context encoded */
|
||||||
|
value.tag = BACNET_APPLICATION_TAG_BOOLEAN;
|
||||||
|
value.type.boolean_value = true;
|
||||||
|
null_len = bacnet_audit_value_context_encode(NULL, tag_number, &value);
|
||||||
|
apdu_len = bacnet_audit_value_context_encode(apdu, tag_number, &value);
|
||||||
|
zassert_equal(apdu_len, null_len, NULL);
|
||||||
|
test_len = 0;
|
||||||
|
status = bacnet_is_opening_tag_number(apdu, apdu_len, tag_number, &tag_len);
|
||||||
|
zassert_true(status, NULL);
|
||||||
|
test_len += tag_len;
|
||||||
|
value_len = bacnet_audit_value_decode(
|
||||||
|
&apdu[test_len], apdu_len - test_len, &test_value);
|
||||||
|
test_len += value_len;
|
||||||
|
status = bacnet_is_closing_tag_number(
|
||||||
|
&apdu[test_len], apdu_len - test_len, tag_number, &tag_len);
|
||||||
|
zassert_true(status, NULL);
|
||||||
|
test_len += tag_len;
|
||||||
|
zassert_equal(apdu_len, test_len, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(CONFIG_ZTEST_NEW_API)
|
||||||
|
ZTEST(bacnet_audit_tests, test_bacnet_audit_log_notification)
|
||||||
|
#else
|
||||||
|
static void test_bacnet_audit_log_notification(void)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
uint8_t apdu[MAX_APDU] = { 0 };
|
||||||
|
BACNET_AUDIT_NOTIFICATION value = { 0 }, test_value = { 0 };
|
||||||
|
int apdu_len = 0, null_len = 0, test_len = 0;
|
||||||
|
|
||||||
|
null_len = bacnet_audit_log_notification_encode(NULL, &value);
|
||||||
|
apdu_len = bacnet_audit_log_notification_encode(apdu, &value);
|
||||||
|
zassert_equal(apdu_len, null_len, NULL);
|
||||||
|
test_len = bacnet_audit_log_notification_decode(apdu, apdu_len, &value);
|
||||||
|
zassert_equal(apdu_len, test_len, NULL);
|
||||||
|
zassert_true(bacnet_audit_log_notification_same(&value, &test_value), NULL);
|
||||||
|
|
||||||
|
/* decoding, some negative tests */
|
||||||
|
test_len =
|
||||||
|
bacnet_audit_log_notification_decode(NULL, apdu_len, &test_value);
|
||||||
|
zassert_equal(test_len, BACNET_STATUS_ERROR, NULL);
|
||||||
|
test_len = bacnet_audit_log_notification_decode(apdu, 0, &test_value);
|
||||||
|
zassert_equal(test_len, BACNET_STATUS_ERROR, NULL);
|
||||||
|
test_len = bacnet_audit_log_notification_decode(apdu, apdu_len, NULL);
|
||||||
|
zassert_equal(test_len, apdu_len, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t Test_APDU[MAX_APDU];
|
||||||
|
#if defined(CONFIG_ZTEST_NEW_API)
|
||||||
|
ZTEST(bacnet_audit_tests, test_bacnet_audit_log_record)
|
||||||
|
#else
|
||||||
|
static void test_bacnet_audit_log_record(void)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
uint8_t *apdu = Test_APDU;
|
||||||
|
BACNET_AUDIT_LOG_RECORD value = { 0 }, test_value = { 0 };
|
||||||
|
int apdu_len = 0, null_len = 0, test_len = 0;
|
||||||
|
bool status = false;
|
||||||
|
BACNET_AUDIT_NOTIFICATION *notification = NULL;
|
||||||
|
|
||||||
|
value.tag = AUDIT_LOG_DATUM_TAG_STATUS;
|
||||||
|
datetime_date_init_ascii(&value.timestamp.date, "2024/11/30");
|
||||||
|
datetime_time_init_ascii(&value.timestamp.time, "23:59:59.99");
|
||||||
|
null_len = bacnet_audit_log_record_encode(NULL, &value);
|
||||||
|
apdu_len = bacnet_audit_log_record_encode(apdu, &value);
|
||||||
|
zassert_equal(apdu_len, null_len, NULL);
|
||||||
|
test_len = bacnet_audit_log_record_decode(apdu, apdu_len, &test_value);
|
||||||
|
zassert_equal(apdu_len, test_len, NULL);
|
||||||
|
zassert_true(bacnet_audit_log_record_same(&value, &test_value), NULL);
|
||||||
|
|
||||||
|
/* decoding, some negative tests */
|
||||||
|
test_len = bacnet_audit_log_record_decode(NULL, apdu_len, &test_value);
|
||||||
|
zassert_equal(test_len, BACNET_STATUS_ERROR, NULL);
|
||||||
|
test_len = bacnet_audit_log_record_decode(apdu, 0, &test_value);
|
||||||
|
zassert_equal(test_len, BACNET_STATUS_ERROR, NULL);
|
||||||
|
test_len = bacnet_audit_log_record_decode(apdu, apdu_len, NULL);
|
||||||
|
zassert_equal(test_len, apdu_len, NULL);
|
||||||
|
status = bacnet_audit_log_record_same(&value, NULL);
|
||||||
|
zassert_false(status, NULL);
|
||||||
|
status = bacnet_audit_log_record_same(NULL, &value);
|
||||||
|
zassert_false(status, NULL);
|
||||||
|
value.tag = 255;
|
||||||
|
test_value.tag = 255;
|
||||||
|
status = bacnet_audit_log_record_same(&value, &test_value);
|
||||||
|
zassert_false(status, NULL);
|
||||||
|
|
||||||
|
/* record type = notification */
|
||||||
|
value.tag = AUDIT_LOG_DATUM_TAG_NOTIFICATION;
|
||||||
|
notification = &value.log_datum.notification;
|
||||||
|
|
||||||
|
bacapp_timestamp_sequence_set(¬ification->source_timestamp, 1234);
|
||||||
|
bacapp_timestamp_sequence_set(¬ification->target_timestamp, 5678);
|
||||||
|
notification->source_device.tag = BACNET_RECIPIENT_TAG_DEVICE;
|
||||||
|
notification->source_device.type.device.instance = 1234;
|
||||||
|
notification->source_device.type.device.type = OBJECT_DEVICE;
|
||||||
|
notification->source_object.type = OBJECT_ANALOG_INPUT;
|
||||||
|
notification->source_object.instance = 5678;
|
||||||
|
notification->operation = AUDIT_OPERATION_DEVICE_RESET;
|
||||||
|
characterstring_init_ansi(¬ification->source_comment, "Hello, World!");
|
||||||
|
characterstring_init_ansi(¬ification->target_comment, "Goodbye, World!");
|
||||||
|
notification->invoke_id = 123;
|
||||||
|
notification->source_user_id = 456;
|
||||||
|
notification->source_user_role = 7;
|
||||||
|
notification->target_device.tag = BACNET_RECIPIENT_TAG_DEVICE;
|
||||||
|
notification->target_device.type.device.instance = 5678;
|
||||||
|
notification->target_device.type.device.type = OBJECT_DEVICE;
|
||||||
|
notification->target_object.type = OBJECT_ANALOG_INPUT;
|
||||||
|
notification->target_object.instance = 1234;
|
||||||
|
notification->target_property.property_identifier = PROP_PRESENT_VALUE;
|
||||||
|
notification->target_property.property_array_index = BACNET_ARRAY_ALL;
|
||||||
|
notification->target_priority = 8;
|
||||||
|
notification->target_value.tag = BACNET_APPLICATION_TAG_REAL;
|
||||||
|
notification->target_value.type.real_value = 3.14159f;
|
||||||
|
notification->current_value.tag = BACNET_APPLICATION_TAG_REAL;
|
||||||
|
notification->current_value.type.real_value = 2.71828f;
|
||||||
|
notification->result = ERROR_CODE_OTHER;
|
||||||
|
null_len = bacnet_audit_log_record_encode(NULL, &value);
|
||||||
|
apdu_len = bacnet_audit_log_record_encode(apdu, &value);
|
||||||
|
zassert_equal(apdu_len, null_len, NULL);
|
||||||
|
test_len = bacnet_audit_log_record_decode(apdu, apdu_len, &test_value);
|
||||||
|
zassert_equal(apdu_len, test_len, NULL);
|
||||||
|
zassert_true(bacnet_audit_log_record_same(&value, &test_value), NULL);
|
||||||
|
|
||||||
|
/* record type = time-change */
|
||||||
|
value.tag = AUDIT_LOG_DATUM_TAG_TIME_CHANGE;
|
||||||
|
value.log_datum.time_change = 3.14159;
|
||||||
|
null_len = bacnet_audit_log_record_encode(NULL, &value);
|
||||||
|
apdu_len = bacnet_audit_log_record_encode(apdu, &value);
|
||||||
|
zassert_equal(apdu_len, null_len, NULL);
|
||||||
|
test_len = bacnet_audit_log_record_decode(apdu, apdu_len, &test_value);
|
||||||
|
zassert_equal(apdu_len, test_len, NULL);
|
||||||
|
zassert_true(bacnet_audit_log_record_same(&value, &test_value), NULL);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(CONFIG_ZTEST_NEW_API)
|
||||||
|
ZTEST_SUITE(bacnet_audit_tests, NULL, NULL, NULL, NULL, NULL);
|
||||||
|
#else
|
||||||
|
void test_main(void)
|
||||||
|
{
|
||||||
|
ztest_test_suite(
|
||||||
|
bacnet_audit_tests, ztest_unit_test(test_bacnet_audit_log_record),
|
||||||
|
ztest_unit_test(test_bacnet_audit_log_notification),
|
||||||
|
ztest_unit_test(test_bacnet_audit_value));
|
||||||
|
|
||||||
|
ztest_run_test_suite(bacnet_audit_tests);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
|
||||||
|
|
||||||
|
get_filename_component(basename ${CMAKE_CURRENT_SOURCE_DIR} NAME)
|
||||||
|
project(test_${basename}
|
||||||
|
VERSION 1.0.0
|
||||||
|
LANGUAGES C)
|
||||||
|
|
||||||
|
|
||||||
|
string(REGEX REPLACE
|
||||||
|
"/test/bacnet/[a-zA-Z_/-]*$"
|
||||||
|
"/src"
|
||||||
|
SRC_DIR
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
string(REGEX REPLACE
|
||||||
|
"/test/bacnet/[a-zA-Z_/-]*$"
|
||||||
|
"/test"
|
||||||
|
TST_DIR
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
set(ZTST_DIR "${TST_DIR}/ztest/src")
|
||||||
|
|
||||||
|
add_compile_definitions(
|
||||||
|
BIG_ENDIAN=0
|
||||||
|
CONFIG_ZTEST=1
|
||||||
|
BACAPP_MINIMAL=1
|
||||||
|
BACAPP_DATETIME=1
|
||||||
|
)
|
||||||
|
|
||||||
|
include_directories(
|
||||||
|
${SRC_DIR}
|
||||||
|
${TST_DIR}/ztest/include
|
||||||
|
${TST_DIR}/bacnet/basic/object/test
|
||||||
|
)
|
||||||
|
|
||||||
|
add_executable(${PROJECT_NAME}
|
||||||
|
# File(s) under test
|
||||||
|
${SRC_DIR}/bacnet/basic/object/auditlog.c
|
||||||
|
# Support files and stubs (pathname alphabetical)
|
||||||
|
${SRC_DIR}/bacnet/bacaddr.c
|
||||||
|
${SRC_DIR}/bacnet/bacaudit.c
|
||||||
|
${SRC_DIR}/bacnet/bacapp.c
|
||||||
|
${SRC_DIR}/bacnet/bacdcode.c
|
||||||
|
${SRC_DIR}/bacnet/bacdest.c
|
||||||
|
${SRC_DIR}/bacnet/bacdevobjpropref.c
|
||||||
|
${SRC_DIR}/bacnet/bacerror.c
|
||||||
|
${SRC_DIR}/bacnet/bacint.c
|
||||||
|
${SRC_DIR}/bacnet/bacreal.c
|
||||||
|
${SRC_DIR}/bacnet/bacstr.c
|
||||||
|
${SRC_DIR}/bacnet/bactext.c
|
||||||
|
${SRC_DIR}/bacnet/basic/sys/bigend.c
|
||||||
|
${SRC_DIR}/bacnet/basic/sys/debug.c
|
||||||
|
${SRC_DIR}/bacnet/basic/sys/keylist.c
|
||||||
|
${SRC_DIR}/bacnet/basic/sys/days.c
|
||||||
|
${SRC_DIR}/bacnet/datetime.c
|
||||||
|
${SRC_DIR}/bacnet/dcc.c
|
||||||
|
${SRC_DIR}/bacnet/indtext.c
|
||||||
|
${SRC_DIR}/bacnet/hostnport.c
|
||||||
|
${SRC_DIR}/bacnet/lighting.c
|
||||||
|
${SRC_DIR}/bacnet/timestamp.c
|
||||||
|
${SRC_DIR}/bacnet/wp.c
|
||||||
|
${SRC_DIR}/bacnet/weeklyschedule.c
|
||||||
|
${SRC_DIR}/bacnet/bactimevalue.c
|
||||||
|
${SRC_DIR}/bacnet/dailyschedule.c
|
||||||
|
${SRC_DIR}/bacnet/proplist.c
|
||||||
|
# Test and test library files
|
||||||
|
./src/main.c
|
||||||
|
${TST_DIR}/bacnet/basic/object/test/property_test.c
|
||||||
|
${TST_DIR}/bacnet/basic/object/test/device_mock.c
|
||||||
|
${TST_DIR}/bacnet/basic/object/test/datetime_local.c
|
||||||
|
${ZTST_DIR}/ztest_mock.c
|
||||||
|
${ZTST_DIR}/ztest.c
|
||||||
|
)
|
||||||
@@ -0,0 +1,200 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 Legrand North America, LLC.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* @file
|
||||||
|
* @brief test BACnet auditlog APIs
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <zephyr/ztest.h>
|
||||||
|
#include <bacnet/basic/object/auditlog.h>
|
||||||
|
#include <bacnet/bactext.h>
|
||||||
|
#include <bacnet/basic/object/device.h>
|
||||||
|
#include <property_test.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @addtogroup bacnet_tests
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Test Auditlog handling
|
||||||
|
|
||||||
|
*/
|
||||||
|
static void testAuditlog(void)
|
||||||
|
{
|
||||||
|
int len = 0, index = 0;
|
||||||
|
const uint32_t instance = 1;
|
||||||
|
uint32_t test_instance = 0;
|
||||||
|
const int skip_fail_property_list[] = { -1 };
|
||||||
|
bool status = false;
|
||||||
|
BACNET_WRITE_PROPERTY_DATA wp_data = { 0 };
|
||||||
|
uint32_t buffer_size = 0;
|
||||||
|
|
||||||
|
Audit_Log_Init();
|
||||||
|
len = Audit_Log_Count();
|
||||||
|
zassert_true(len == 0, NULL);
|
||||||
|
status = Audit_Log_Valid_Instance(instance);
|
||||||
|
zassert_false(status, NULL);
|
||||||
|
test_instance = Audit_Log_Create(instance);
|
||||||
|
zassert_true(test_instance == instance, NULL);
|
||||||
|
len = Audit_Log_Count();
|
||||||
|
zassert_true(len == 1, NULL);
|
||||||
|
test_instance = Audit_Log_Index_To_Instance(0);
|
||||||
|
zassert_true(test_instance == instance, NULL);
|
||||||
|
index = Audit_Log_Instance_To_Index(instance);
|
||||||
|
zassert_true(index == 0, NULL);
|
||||||
|
status = Audit_Log_Valid_Instance(instance);
|
||||||
|
zassert_true(status, NULL);
|
||||||
|
|
||||||
|
/* configure ReadProperty test */
|
||||||
|
/* perform a general test for RP/WP */
|
||||||
|
bacnet_object_properties_read_write_test(
|
||||||
|
OBJECT_AUDIT_LOG, instance, Audit_Log_Property_Lists,
|
||||||
|
Audit_Log_Read_Property, Audit_Log_Write_Property,
|
||||||
|
skip_fail_property_list);
|
||||||
|
|
||||||
|
wp_data.object_type = OBJECT_AUDIT_LOG;
|
||||||
|
wp_data.object_instance = instance;
|
||||||
|
wp_data.priority = BACNET_NO_PRIORITY;
|
||||||
|
wp_data.array_index = BACNET_ARRAY_ALL;
|
||||||
|
|
||||||
|
/* test buffer size */
|
||||||
|
buffer_size = 512;
|
||||||
|
wp_data.object_property = PROP_BUFFER_SIZE;
|
||||||
|
wp_data.application_data_len =
|
||||||
|
encode_application_unsigned(wp_data.application_data, buffer_size);
|
||||||
|
status = Audit_Log_Write_Property(&wp_data);
|
||||||
|
zassert_true(status, NULL);
|
||||||
|
buffer_size = INT_MAX;
|
||||||
|
buffer_size++;
|
||||||
|
wp_data.application_data_len =
|
||||||
|
encode_application_unsigned(wp_data.application_data, buffer_size);
|
||||||
|
status = Audit_Log_Write_Property(&wp_data);
|
||||||
|
/* error out of range */
|
||||||
|
zassert_false(status, NULL);
|
||||||
|
zassert_equal(wp_data.error_class, ERROR_CLASS_PROPERTY, NULL);
|
||||||
|
zassert_equal(wp_data.error_code, ERROR_CODE_VALUE_OUT_OF_RANGE, NULL);
|
||||||
|
|
||||||
|
wp_data.object_property = PROP_ENABLE;
|
||||||
|
wp_data.application_data_len =
|
||||||
|
encode_application_boolean(wp_data.application_data, true);
|
||||||
|
status = Audit_Log_Write_Property(&wp_data);
|
||||||
|
zassert_true(status, NULL);
|
||||||
|
|
||||||
|
wp_data.object_property = PROP_BUFFER_SIZE;
|
||||||
|
wp_data.application_data_len =
|
||||||
|
encode_application_unsigned(wp_data.application_data, buffer_size);
|
||||||
|
status = Audit_Log_Write_Property(&wp_data);
|
||||||
|
/* error when enabled=true */
|
||||||
|
zassert_false(status, NULL);
|
||||||
|
zassert_equal(wp_data.error_class, ERROR_CLASS_PROPERTY, NULL);
|
||||||
|
zassert_equal(wp_data.error_code, ERROR_CODE_WRITE_ACCESS_DENIED, NULL);
|
||||||
|
|
||||||
|
/* test object name */
|
||||||
|
bacnet_object_name_ascii_test(
|
||||||
|
instance, Audit_Log_Name_Set, Audit_Log_Name_ASCII);
|
||||||
|
bacnet_object_name_ascii_test(
|
||||||
|
instance, Audit_Log_Description_Set, Audit_Log_Description);
|
||||||
|
|
||||||
|
status = Audit_Log_Delete(instance);
|
||||||
|
zassert_true(status, NULL);
|
||||||
|
Audit_Log_Cleanup();
|
||||||
|
len = Audit_Log_Count();
|
||||||
|
zassert_true(len == 0, NULL);
|
||||||
|
status = Audit_Log_Valid_Instance(instance);
|
||||||
|
zassert_false(status, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void testLogs(void)
|
||||||
|
{
|
||||||
|
const uint32_t instance = 1;
|
||||||
|
uint32_t test_instance = 0;
|
||||||
|
int len = 0;
|
||||||
|
uint32_t buffer_size = 0, test_buffer_size = 0, original_buffer_size = 0;
|
||||||
|
uint32_t record_count = 0;
|
||||||
|
uint32_t total_record_count = 0;
|
||||||
|
bool status = false;
|
||||||
|
BACNET_AUDIT_LOG_RECORD *record;
|
||||||
|
|
||||||
|
Audit_Log_Init();
|
||||||
|
test_instance = Audit_Log_Create(instance);
|
||||||
|
zassert_true(test_instance == instance, NULL);
|
||||||
|
len = Audit_Log_Count();
|
||||||
|
zassert_true(len > 0, NULL);
|
||||||
|
/* Log Buffer settings */
|
||||||
|
buffer_size = Audit_Log_Buffer_Size(instance);
|
||||||
|
zassert_true(buffer_size > 0, NULL);
|
||||||
|
buffer_size = INT_MAX;
|
||||||
|
buffer_size++;
|
||||||
|
status = Audit_Log_Buffer_Size_Set(instance, buffer_size);
|
||||||
|
zassert_false(status, NULL);
|
||||||
|
original_buffer_size = Audit_Log_Buffer_Size(instance);
|
||||||
|
buffer_size = original_buffer_size / 2;
|
||||||
|
status = Audit_Log_Buffer_Size_Set(instance, buffer_size);
|
||||||
|
zassert_true(status, NULL);
|
||||||
|
test_buffer_size = Audit_Log_Buffer_Size(instance);
|
||||||
|
zassert_true(test_buffer_size == buffer_size, NULL);
|
||||||
|
status = Audit_Log_Buffer_Size_Set(instance, original_buffer_size);
|
||||||
|
zassert_true(status, NULL);
|
||||||
|
/* Log Buffer records manipulation */
|
||||||
|
record_count = Audit_Log_Record_Count(instance);
|
||||||
|
zassert_true(record_count == 0, NULL);
|
||||||
|
total_record_count = Audit_Log_Total_Record_Count(instance);
|
||||||
|
zassert_true(total_record_count == 0, NULL);
|
||||||
|
status = Audit_Log_Enable(instance);
|
||||||
|
zassert_false(status, NULL);
|
||||||
|
status = Audit_Log_Enable_Set(instance, false);
|
||||||
|
zassert_true(status, NULL);
|
||||||
|
/* start logging */
|
||||||
|
status = Audit_Log_Enable_Set(instance, true);
|
||||||
|
zassert_true(status, NULL);
|
||||||
|
record_count = Audit_Log_Record_Count(instance);
|
||||||
|
zassert_true(record_count == 1, NULL);
|
||||||
|
total_record_count = Audit_Log_Total_Record_Count(instance);
|
||||||
|
zassert_true(total_record_count == 1, NULL);
|
||||||
|
record = Audit_Log_Record_Entry(instance, 0);
|
||||||
|
zassert_not_null(record, NULL);
|
||||||
|
zassert_true(record->tag == AUDIT_LOG_DATUM_TAG_STATUS, NULL);
|
||||||
|
zassert_true(
|
||||||
|
BIT_CHECK(record->log_datum.log_status, LOG_STATUS_LOG_DISABLED) == 0,
|
||||||
|
NULL);
|
||||||
|
Audit_Log_Record_Status_Insert(instance, LOG_STATUS_LOG_INTERRUPTED, true);
|
||||||
|
record_count = Audit_Log_Record_Count(instance);
|
||||||
|
zassert_true(record_count == 2, NULL);
|
||||||
|
total_record_count = Audit_Log_Total_Record_Count(instance);
|
||||||
|
zassert_true(total_record_count == 2, NULL);
|
||||||
|
record = Audit_Log_Record_Entry(instance, 1);
|
||||||
|
zassert_not_null(record, NULL);
|
||||||
|
zassert_true(record->tag == AUDIT_LOG_DATUM_TAG_STATUS, NULL);
|
||||||
|
zassert_true(
|
||||||
|
BIT_CHECK(record->log_datum.log_status, LOG_STATUS_LOG_INTERRUPTED),
|
||||||
|
NULL);
|
||||||
|
Audit_Log_Record_Entry_Delete(instance, 1);
|
||||||
|
record_count = Audit_Log_Record_Count(instance);
|
||||||
|
zassert_true(record_count == 1, "record_count: %d", record_count);
|
||||||
|
total_record_count = Audit_Log_Total_Record_Count(instance);
|
||||||
|
zassert_true(total_record_count == 2, NULL);
|
||||||
|
record = Audit_Log_Record_Entry(instance, 0);
|
||||||
|
zassert_not_null(record, NULL);
|
||||||
|
zassert_true(record->tag == AUDIT_LOG_DATUM_TAG_STATUS, NULL);
|
||||||
|
zassert_true(
|
||||||
|
BIT_CHECK(record->log_datum.log_status, LOG_STATUS_LOG_DISABLED) == 0,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
Audit_Log_Cleanup();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
void test_main(void)
|
||||||
|
{
|
||||||
|
ztest_test_suite(
|
||||||
|
auditlog_tests, ztest_unit_test(testAuditlog),
|
||||||
|
ztest_unit_test(testLogs));
|
||||||
|
|
||||||
|
ztest_run_test_suite(auditlog_tests);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user