:${CMAKE_CURRENT_LIST_DIR}/src/collectors/collector_system_information.c>
${CMAKE_CURRENT_LIST_DIR}/src/model/objects/object_network_activity_ext.c
${CMAKE_CURRENT_LIST_DIR}/src/utils/irand.c
${CMAKE_CURRENT_LIST_DIR}/src/utils/itime.c
- ${CMAKE_CURRENT_LIST_DIR}/src/utils/iuuid.c
${CMAKE_CURRENT_LIST_DIR}/src/utils/os_utils.c
+ ${CMAKE_CURRENT_LIST_DIR}/src/utils/ievent_loop.c
)
add_library("azrtos::${PROJECT_NAME}" ALIAS ${PROJECT_NAME})
@@ -55,6 +73,7 @@ target_include_directories(${PROJECT_NAME}
${AZURE_IOT_SECURITY_MODULE}
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}/inc
+ ${CMAKE_CURRENT_LIST_DIR}/inc/configs/${IOT_SECURITY_MODULE_DIST_TARGET}
)
@@ -72,6 +91,7 @@ target_link_libraries(asc_security_core
target_include_directories(asc_security_core
PRIVATE
inc
+ ${CMAKE_CURRENT_LIST_DIR}/inc/configs/${IOT_SECURITY_MODULE_DIST_TARGET}
)
# Define any required dependencies between this library and others
diff --git a/addons/azure_iot/azure_iot_security_module/configs/L4_BASE.dist b/addons/azure_iot/azure_iot_security_module/configs/L4_BASE.dist
new file mode 100644
index 00000000..151c6a4f
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/configs/L4_BASE.dist
@@ -0,0 +1,7 @@
+# set default configuration from specific parent dist
+CONF_DEFINE_BASE(${g_plat_config_path} RTOS_BASE.dist)
+
+# DIST: overwrite configuration for specific distribution
+
+set(ASC_COLLECTOR_NETWORK_ACTIVITY_ICMP_DISABLED ON)
+set(ASC_COLLECTOR_NETWORK_ACTIVITY_CAPTURE_UNICAST_ONLY OFF)
diff --git a/addons/azure_iot/azure_iot_security_module/configs/RTOS_BASE.dist b/addons/azure_iot/azure_iot_security_module/configs/RTOS_BASE.dist
new file mode 100644
index 00000000..1dfc3ef5
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/configs/RTOS_BASE.dist
@@ -0,0 +1,35 @@
+# set default configuration from specific parent dist
+CONF_DEFINE_BASE(${g_core_config_path} base_dist.cmake)
+
+# DIST: overwrite configuration for specific distribution
+set(SECURITY_MODULE_VERSION_MAJOR 3)
+set(SECURITY_MODULE_VERSION_MINOR 5)
+set(SECURITY_MODULE_VERSION_PATCH 4)
+
+set(ASC_COMPONENT_CONFIGURATION OFF)
+
+set(ASC_COLLECTOR_HEARTBEAT_ENABLED ON)
+set(ASC_COLLECTOR_SYSTEM_INFORMATION_ENABLED ON)
+set(ASC_COLLECTOR_NETWORK_ACTIVITY_ENABLED ON)
+
+set(ASC_COMPONENT_SECURITY_MODULE ON)
+
+set(ASC_COMPONENT_CORE_SUPPORTS_RESTART OFF)
+set(ASC_NOTIFIERS_OBJECT_POOL_ENTRIES 2)
+set(ASC_LOG_TIMESTAMP_DEFAULT OFF)
+
+set(ASC_BEST_EFFORT_EVENT_LOOP ON)
+set(ASC_SECURITY_MODULE_SEND_MESSAGE_RETRY_TIME 3)
+set(ASC_SECURITY_MODULE_PENDING_TIME 60*5)
+
+set(ASC_COLLECTOR_NETWORK_ACTIVITY_CAPTURE_UNICAST_ONLY ON)
+set(ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV4_OBJECTS_IN_CACHE 64)
+set(ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE 64)
+
+if(ASC_COMPONENT_CORE_SUPPORTS_RESTART)
+set(ASC_BE_TIMERS_OBJECT_POOL_ENTRIES 3)
+else()
+set(ASC_BE_TIMERS_OBJECT_POOL_ENTRIES 2)
+endif()
+set(FLATCC_NO_ASSERT OFF)
+set(FLATCC_ASSERT NX_ASSERT)
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/configs/RTOS_BASE_UT.dist b/addons/azure_iot/azure_iot_security_module/configs/RTOS_BASE_UT.dist
new file mode 100644
index 00000000..caedf490
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/configs/RTOS_BASE_UT.dist
@@ -0,0 +1,16 @@
+# set default configuration from specific parent dist
+CONF_DEFINE_BASE(${g_plat_config_path} RTOS_BASE.dist)
+
+# DIST: overwrite configuration for specific distribution
+set(ASC_FIRST_FORCE_COLLECTION_INTERVAL 2)
+set(ASC_EXTRA_NOTIFIERS_OBJECT_POOL_ENTRIES 1)
+set(ASC_SECURITY_MODULE_MAX_HUB_DEVICES 128)
+set(ASC_FLATCC_JSON_PRINTER_OVERWRITE ON)
+if (NOT DEFINED log_level_cmdline)
+ set(ASC_LOG_LEVEL 0)
+endif()
+set(ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV4_OBJECTS_IN_CACHE 4)
+set(ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE 4)
+set(run_unittests ON CACHE BOOL "set run_unittests to ON to run unittests (default is OFF)")
+set(run_coverage ON CACHE BOOL "set run_unittests to ON to run unittests (default is OFF)")
+set(FLATCC_ASSERT 0)
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/configs/asc_config.h.in b/addons/azure_iot/azure_iot_security_module/configs/asc_config.h.in
new file mode 100644
index 00000000..97ae5790
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/configs/asc_config.h.in
@@ -0,0 +1,37 @@
+
+/************************
+* Platform configuration
+*************************/
+#ifdef FLATCC_ASSERT
+#undef FLATCC_ASSERT
+#endif
+
+#ifndef __ASC_CONFIG_EXCLUDE_PORT__H__
+#include "tx_port.h"
+#include "nx_port.h"
+#include "nx_api.h"
+
+/* Flat buffer serializer platform */
+#cmakedefine FLATCC_ASSERT @FLATCC_ASSERT@
+
+#endif /* __ASC_CONFIG_EXCLUDE_PORT__H__ */
+
+/* Security Module pending time, in seconds */
+#cmakedefine ASC_SECURITY_MODULE_PENDING_TIME @ASC_SECURITY_MODULE_PENDING_TIME@
+#cmakedefine ASC_SECURITY_MODULE_SEND_MESSAGE_RETRY_TIME @ASC_SECURITY_MODULE_SEND_MESSAGE_RETRY_TIME@
+#cmakedefine ASC_SECURITY_MODULE_MAX_HUB_DEVICES @ASC_SECURITY_MODULE_MAX_HUB_DEVICES@
+#ifndef ASC_SECURITY_MODULE_MAX_HUB_DEVICES
+#define ASC_SECURITY_MODULE_MAX_HUB_DEVICES 64
+#endif
+
+/* Collector network activity. */
+#cmakedefine ASC_COLLECTOR_NETWORK_ACTIVITY_TCP_DISABLED
+#cmakedefine ASC_COLLECTOR_NETWORK_ACTIVITY_UDP_DISABLED
+#cmakedefine ASC_COLLECTOR_NETWORK_ACTIVITY_ICMP_DISABLED
+#cmakedefine ASC_COLLECTOR_NETWORK_ACTIVITY_CAPTURE_UNICAST_ONLY
+
+/* The maximum number of IPv4 network events to store in memory. */
+#ifdef NX_DISABLE_IPV6
+#undef ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE
+#define ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE 0
+#endif
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/extensions/custom_builder_allocator.h b/addons/azure_iot/azure_iot_security_module/configs/license
similarity index 71%
rename from addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/extensions/custom_builder_allocator.h
rename to addons/azure_iot/azure_iot_security_module/configs/license
index 0592c9fc..639866c2 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/extensions/custom_builder_allocator.h
+++ b/addons/azure_iot/azure_iot_security_module/configs/license
@@ -9,13 +9,3 @@
/* */
/**************************************************************************/
-#ifndef CUSTOM_BUILDER_ALLOCATOR_H
-#define CUSTOM_BUILDER_ALLOCATOR_H
-
-#include "flatcc/flatcc_builder.h"
-
-int serializer_custom_allocator(void *alloc_context, flatcc_iovec_t *b, size_t request, int zero_fill, int alloc_type);
-
-void serializer_custom_allocator_reset();
-
-#endif /* CUSTOM_BUILDER_ALLOCATOR_H */
diff --git a/addons/azure_iot/azure_iot_security_module/docs/nx_azure_iot_security_module.md b/addons/azure_iot/azure_iot_security_module/docs/nx_azure_iot_security_module.md
new file mode 100644
index 00000000..06e1b51b
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/docs/nx_azure_iot_security_module.md
@@ -0,0 +1,70 @@
+# Azure RTOS IoT Security Module API
+
+## Azure IoT Security Module
+
+**nx_azure_iot_security_module_enable**
+***
+ Enable Azure IoT Security Module
+
+**Prototype**
+```c
+UINT nx_azure_iot_security_module_enable(NX_AZURE_IOT *nx_azure_iot_ptr);
+```
+**Description**
+
+This routine enables the Azure IoT Security Module subsystem. An internal state machine manage security events collection and sends them to Azure IoT Hub. Only one NX_AZURE_IOT_SECURITY_MODULE instance exists at most and needed to manage data collection.
+
+**Parameters**
+| Name | Description |
+| - |:-|
+| nx_azure_iot_ptr [in] | A pointer to a `NX_AZURE_IOT` |
+
+
+**Return Values**
+* NX_AZURE_IOT_SUCCESS Successfully enabled Azure IoT Security Module.
+* NX_AZURE_IOT_FAILURE Fail to enable Azure IoT Security Module due to internal error.
+* NX_AZURE_IOT_INVALID_PARAMETER Security module requires valid #NX_AZURE_IOT instance.
+
+**Allowed From**
+
+Threads
+
+**Example**
+
+**See Also**
+
+
+
+**nx_azure_iot_security_module_disable**
+***
+ Disable Azure IoT Security Module
+
+**Prototype**
+```c
+UINT nx_azure_iot_security_module_disable(NX_AZURE_IOT *nx_azure_iot_ptr);
+```
+**Description**
+
+This routine disables the Azure IoT Security Module subsystem.
+
+**Parameters**
+
+| Name | Description |
+| - |:-|
+| nx_azure_iot_ptr [in] | A pointer to a `NX_AZURE_IOT`, if NULL the singleton instance will be disabled. |
+
+
+**Return Values**
+* NX_AZURE_IOT_SUCCESS Successful if Azure IoT Security Module has been disabled successfully.
+* NX_AZURE_IOT_INVALID_PARAMETER Azure IoT Hub instance differ than the singleton composite instance.
+* NX_AZURE_IOT_FAILURE Fail to disable Azure IoT Security Module due to internal error.
+
+**Allowed From**
+
+Threads
+
+**Example**
+
+**See Also**
+
+
diff --git a/addons/azure_iot/azure_iot_security_module/inc/asc_port.h b/addons/azure_iot/azure_iot_security_module/inc/asc_port.h
deleted file mode 100644
index dbb66a77..00000000
--- a/addons/azure_iot/azure_iot_security_module/inc/asc_port.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
-
-#ifndef ASC_PORT_H
-#define ASC_PORT_H
-
-#include "nx_api.h"
-#include "asc_security_core/version.h"
-
-/* Security Module ID - A unique identifier of the device. */
-#ifndef ASC_SECURITY_MODULE_ID
-#define ASC_SECURITY_MODULE_ID "iot_security_module"
-#endif
-
-/* Security Module pending time, in seconds */
-#ifndef ASC_SECURITY_MODULE_PENDING_TIME
-#define ASC_SECURITY_MODULE_PENDING_TIME (60 * 5)
-#endif
-
-/* Collection intervals, in seconds. */
-#ifndef ASC_HIGH_PRIORITY_INTERVAL
-#define ASC_HIGH_PRIORITY_INTERVAL 10
-#endif
-#ifndef ASC_MEDIUM_PRIORITY_INTERVAL
-#define ASC_MEDIUM_PRIORITY_INTERVAL 30
-#endif
-#ifndef ASC_LOW_PRIORITY_INTERVAL
-#define ASC_LOW_PRIORITY_INTERVAL 60
-#endif
-
-/* Enable Collectors */
-#define COLLECTOR_HEARTBEAT_ENABLED
-#define COLLECTOR_SYSTEM_INFORMATION_ENABLED
-#define COLLECTOR_NETWORK_ACTIVITY_ENABLED
-
-/* Collector network activity. */
-/* #define ASC_COLLECTOR_NETWORK_ACTIVITY_TCP_DISABLED */
-/* #define ASC_COLLECTOR_NETWORK_ACTIVITY_UDP_DISABLED */
-/* #define ASC_COLLECTOR_NETWORK_ACTIVITY_ICMP_DISABLED */
-#define ASC_COLLECTOR_NETWORK_ACTIVITY_CAPTURE_UNICAST_ONLY
-
-/* The maximum number of IPv4 network events to store in memory. */
-#ifndef ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV4_OBJECTS_IN_CACHE
-#define ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV4_OBJECTS_IN_CACHE 4
-#endif
-/* The maximum number of IPv6 network events to store in memory. */
-#ifndef ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE
-#ifdef NX_DISABLE_IPV6
-#define ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE 0
-#else
-#define ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE 4
-#endif /* NX_DISABLE_IPV6 */
-#endif
-
-
-/* Serializer custom allocator uses static memory instead of heap memory. Desired behaviour in Azure RTOS devices. */
-#ifndef ASC_SERIALIZER_USE_CUSTOM_ALLOCATOR
-#define ASC_SERIALIZER_USE_CUSTOM_ALLOCATOR
-#endif
-
-#endif /* ASC_PORT_H */
diff --git a/addons/azure_iot/azure_iot_security_module/inc/asc_version.h b/addons/azure_iot/azure_iot_security_module/inc/asc_version.h
deleted file mode 100644
index 78b70b3c..00000000
--- a/addons/azure_iot/azure_iot_security_module/inc/asc_version.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#ifndef SECURITY_MODULE_VERSION_MAJOR
-#define SECURITY_MODULE_VERSION_MAJOR 2
-#endif
-
-#ifndef SECURITY_MODULE_VERSION_MINOR
-#define SECURITY_MODULE_VERSION_MINOR 0
-#endif
-
-#ifndef SECURITY_MODULE_VERSION_PATCH
-#define SECURITY_MODULE_VERSION_PATCH 3
-#endif
diff --git a/addons/azure_iot/azure_iot_security_module/inc/configs/L4_BASE/asc_config.h b/addons/azure_iot/azure_iot_security_module/inc/configs/L4_BASE/asc_config.h
new file mode 100644
index 00000000..87384977
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/inc/configs/L4_BASE/asc_config.h
@@ -0,0 +1,188 @@
+/**************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure RTOS. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
+/* and in the root directory of this software. */
+/* */
+/**************************************************************************/
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Distribution L4_BASE */
+#ifndef __ASC_CONFIG_H__
+#define __ASC_CONFIG_H__
+
+/********************
+* Core configuration
+*********************/
+/* Based on 2022.07.19-3.5.3 core tag */
+
+/* ID and version */
+#define ASC_SECURITY_MODULE_ID "defender-iot-micro-agent"
+#define SECURITY_MODULE_VERSION_MAJOR 3
+#define SECURITY_MODULE_VERSION_MINOR 5
+#define SECURITY_MODULE_VERSION_PATCH 4
+#ifndef SECURITY_MODULE_VERSION_MAJOR
+#define SECURITY_MODULE_VERSION_MAJOR 0
+#endif
+#ifndef SECURITY_MODULE_VERSION_MINOR
+#define SECURITY_MODULE_VERSION_MINOR 0
+#endif
+#ifndef SECURITY_MODULE_VERSION_PATCH
+#define SECURITY_MODULE_VERSION_PATCH 0
+#endif
+
+/* Collectors definitions */
+/* #undef ASC_DYNAMIC_COLLECTORS_MAX */
+#ifndef ASC_DYNAMIC_COLLECTORS_MAX
+#define ASC_DYNAMIC_COLLECTORS_MAX 0
+#endif
+#define ASC_COLLECTOR_HEARTBEAT_ENABLED
+
+/* #undef ASC_COLLECTOR_BASELINE_ENABLED */
+/* #undef ASC_BASELINE_REPORT_POOL_ENTRIES */
+
+/* #undef ASC_COLLECTOR_LOG_ENABLED */
+/* #undef ASC_LOG_REPORT_POOL_ENTRIES */
+
+#define ASC_COLLECTOR_NETWORK_ACTIVITY_ENABLED
+/* #undef ASC_COLLECTOR_NETWORK_ACTIVITY_SEND_EMPTY_EVENTS */
+#define ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV4_OBJECTS_IN_CACHE 64
+#define ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE 64
+#ifndef ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV4_OBJECTS_IN_CACHE
+#define ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV4_OBJECTS_IN_CACHE 0
+#endif
+#ifndef ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE
+#define ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE 0
+#endif
+
+/* #undef ASC_COLLECTOR_PROCESS_ENABLED */
+/* #undef ASC_COLLECTOR_PROCESS_SEND_EMPTY_EVENTS */
+/* #undef ASC_COLLECTOR_PROCESS_IN_CACHE */
+#ifndef ASC_COLLECTOR_PROCESS_IN_CACHE
+#define ASC_COLLECTOR_PROCESS_IN_CACHE 0
+#endif
+
+#define ASC_COLLECTOR_SYSTEM_INFORMATION_ENABLED
+
+/* #undef ASC_COLLECTOR_LISTENING_PORTS_ENABLED */
+
+/* Components definitions */
+/* #undef ASC_DYNAMIC_FACTORY_ENABLED */
+/* #undef ASC_DYNAMIC_FACTORY_PATH */
+/* #undef ASC_DYNAMIC_FACTORY_PATH_RUNTIME_SET */
+/* #undef ASC_DYNAMIC_COMPONENTS_MAX */
+#ifndef ASC_DYNAMIC_COMPONENTS_MAX
+#define ASC_DYNAMIC_COMPONENTS_MAX 0
+#endif
+
+/* #undef ASC_COMPONENT_COMMAND_EXECUTOR */
+/* #undef ASC_OPERATIONS_POOL_ENTRIES */
+
+/* #undef ASC_COMPONENT_CONFIGURATION */
+/* #undef ASC_COMPONENT_CONFIGURATION_PLAT */
+
+#define ASC_COMPONENT_SECURITY_MODULE
+
+/* Collection definitions */
+#define ASC_FIRST_COLLECTION_INTERVAL 30
+#define ASC_HIGH_PRIORITY_INTERVAL 10
+#define ASC_MEDIUM_PRIORITY_INTERVAL 30
+#define ASC_LOW_PRIORITY_INTERVAL 60
+
+/* Dynamic/Static memory */
+/* #undef ASC_DYNAMIC_MEMORY_ENABLED */
+
+/* ROM reduce */
+/* #undef ASC_COMPONENT_CORE_SUPPORTS_RESTART */
+/* #undef ASC_COLLECTORS_INFO_SUPPORT */
+/* #undef ASC_LINKED_LIST_NODE_SUPPORT */
+
+/* Log */
+// Highest compiled log level
+/* #undef ASC_LOG_LEVEL */
+/* #undef ASC_TIME_H_SUPPORT */
+/* #undef ASC_LOG_TIMESTAMP_DEFAULT */
+
+/* Notifier definitions */
+#define ASC_NOTIFIERS_OBJECT_POOL_ENTRIES 2
+
+/* Event loop best effort */
+#define ASC_BEST_EFFORT_EVENT_LOOP
+#define ASC_BE_TIMERS_OBJECT_POOL_ENTRIES 2
+
+/* Flat buffer serializer */
+#define ASC_SERIALIZER_USE_CUSTOM_ALLOCATOR
+/* #undef ASC_FLATCC_JSON_PRINTER_OVERWRITE */
+#define ASC_EMITTER_PAGE_CACHE_SIZE 1
+/* #undef FLATCC_NO_ASSERT */
+/* FLATCC_ASSERT might be redefined in platform area */
+#define FLATCC_ASSERT NX_ASSERT
+#define FLATCC_USE_GENERIC_ALIGNED_ALLOC
+/* #undef FLATCC_EMITTER_PAGE_SIZE */
+
+/* Tests definitions */
+// Set ASC_FIRST_FORCE_COLLECTION_INTERVAL to '-1' to force immediatly collecting
+/* #undef ASC_FIRST_FORCE_COLLECTION_INTERVAL */
+/* #undef ASC_EXTRA_BE_TIMERS_OBJECT_POOL_ENTRIES */
+/* #undef ASC_EXTRA_NOTIFIERS_OBJECT_POOL_ENTRIES */
+/* #undef ASC_EXTRA_COMPONENTS_COUNT */
+#ifndef ASC_EXTRA_COMPONENTS_COUNT
+#define ASC_EXTRA_COMPONENTS_COUNT 0
+#endif
+/* #undef ASC_EXTRA_COLLECTORS_COUNT */
+#ifndef ASC_EXTRA_COLLECTORS_COUNT
+#define ASC_EXTRA_COLLECTORS_COUNT 0
+#endif
+
+#define LOOP_ASSERT_FAIL for (;;) { }
+#define LOOP_ASSERT(s) if (!(s)) {LOOP_ASSERT_FAIL}
+
+/************************
+* Platform configuration
+*************************/
+#ifdef FLATCC_ASSERT
+#undef FLATCC_ASSERT
+#endif
+
+#ifndef __ASC_CONFIG_EXCLUDE_PORT__H__
+#include "tx_port.h"
+#include "nx_port.h"
+#include "nx_api.h"
+
+/* Flat buffer serializer platform */
+#define FLATCC_ASSERT NX_ASSERT
+
+#endif /* __ASC_CONFIG_EXCLUDE_PORT__H__ */
+
+/* Security Module pending time, in seconds */
+#define ASC_SECURITY_MODULE_PENDING_TIME 60*5
+#define ASC_SECURITY_MODULE_SEND_MESSAGE_RETRY_TIME 3
+/* #undef ASC_SECURITY_MODULE_MAX_HUB_DEVICES */
+#ifndef ASC_SECURITY_MODULE_MAX_HUB_DEVICES
+#define ASC_SECURITY_MODULE_MAX_HUB_DEVICES 64
+#endif
+
+/* Collector network activity. */
+/* #undef ASC_COLLECTOR_NETWORK_ACTIVITY_TCP_DISABLED */
+/* #undef ASC_COLLECTOR_NETWORK_ACTIVITY_UDP_DISABLED */
+#define ASC_COLLECTOR_NETWORK_ACTIVITY_ICMP_DISABLED
+/* #undef ASC_COLLECTOR_NETWORK_ACTIVITY_CAPTURE_UNICAST_ONLY */
+
+/* The maximum number of IPv4 network events to store in memory. */
+#ifdef NX_DISABLE_IPV6
+#undef ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE
+#define ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE 0
+#endif
+
+#endif /* __ASC_CONFIG_H__ */
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/addons/azure_iot/azure_iot_security_module/inc/configs/RTOS_BASE/asc_config.h b/addons/azure_iot/azure_iot_security_module/inc/configs/RTOS_BASE/asc_config.h
new file mode 100644
index 00000000..de0fdc6f
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/inc/configs/RTOS_BASE/asc_config.h
@@ -0,0 +1,188 @@
+/**************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure RTOS. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
+/* and in the root directory of this software. */
+/* */
+/**************************************************************************/
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Distribution RTOS_BASE */
+#ifndef __ASC_CONFIG_H__
+#define __ASC_CONFIG_H__
+
+/********************
+* Core configuration
+*********************/
+/* Based on 2022.07.19-3.5.3 core tag */
+
+/* ID and version */
+#define ASC_SECURITY_MODULE_ID "defender-iot-micro-agent"
+#define SECURITY_MODULE_VERSION_MAJOR 3
+#define SECURITY_MODULE_VERSION_MINOR 5
+#define SECURITY_MODULE_VERSION_PATCH 4
+#ifndef SECURITY_MODULE_VERSION_MAJOR
+#define SECURITY_MODULE_VERSION_MAJOR 0
+#endif
+#ifndef SECURITY_MODULE_VERSION_MINOR
+#define SECURITY_MODULE_VERSION_MINOR 0
+#endif
+#ifndef SECURITY_MODULE_VERSION_PATCH
+#define SECURITY_MODULE_VERSION_PATCH 0
+#endif
+
+/* Collectors definitions */
+/* #undef ASC_DYNAMIC_COLLECTORS_MAX */
+#ifndef ASC_DYNAMIC_COLLECTORS_MAX
+#define ASC_DYNAMIC_COLLECTORS_MAX 0
+#endif
+#define ASC_COLLECTOR_HEARTBEAT_ENABLED
+
+/* #undef ASC_COLLECTOR_BASELINE_ENABLED */
+/* #undef ASC_BASELINE_REPORT_POOL_ENTRIES */
+
+/* #undef ASC_COLLECTOR_LOG_ENABLED */
+/* #undef ASC_LOG_REPORT_POOL_ENTRIES */
+
+#define ASC_COLLECTOR_NETWORK_ACTIVITY_ENABLED
+/* #undef ASC_COLLECTOR_NETWORK_ACTIVITY_SEND_EMPTY_EVENTS */
+#define ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV4_OBJECTS_IN_CACHE 64
+#define ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE 64
+#ifndef ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV4_OBJECTS_IN_CACHE
+#define ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV4_OBJECTS_IN_CACHE 0
+#endif
+#ifndef ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE
+#define ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE 0
+#endif
+
+/* #undef ASC_COLLECTOR_PROCESS_ENABLED */
+/* #undef ASC_COLLECTOR_PROCESS_SEND_EMPTY_EVENTS */
+/* #undef ASC_COLLECTOR_PROCESS_IN_CACHE */
+#ifndef ASC_COLLECTOR_PROCESS_IN_CACHE
+#define ASC_COLLECTOR_PROCESS_IN_CACHE 0
+#endif
+
+#define ASC_COLLECTOR_SYSTEM_INFORMATION_ENABLED
+
+/* #undef ASC_COLLECTOR_LISTENING_PORTS_ENABLED */
+
+/* Components definitions */
+/* #undef ASC_DYNAMIC_FACTORY_ENABLED */
+/* #undef ASC_DYNAMIC_FACTORY_PATH */
+/* #undef ASC_DYNAMIC_FACTORY_PATH_RUNTIME_SET */
+/* #undef ASC_DYNAMIC_COMPONENTS_MAX */
+#ifndef ASC_DYNAMIC_COMPONENTS_MAX
+#define ASC_DYNAMIC_COMPONENTS_MAX 0
+#endif
+
+/* #undef ASC_COMPONENT_COMMAND_EXECUTOR */
+/* #undef ASC_OPERATIONS_POOL_ENTRIES */
+
+/* #undef ASC_COMPONENT_CONFIGURATION */
+/* #undef ASC_COMPONENT_CONFIGURATION_PLAT */
+
+#define ASC_COMPONENT_SECURITY_MODULE
+
+/* Collection definitions */
+#define ASC_FIRST_COLLECTION_INTERVAL 30
+#define ASC_HIGH_PRIORITY_INTERVAL 10
+#define ASC_MEDIUM_PRIORITY_INTERVAL 30
+#define ASC_LOW_PRIORITY_INTERVAL 60
+
+/* Dynamic/Static memory */
+/* #undef ASC_DYNAMIC_MEMORY_ENABLED */
+
+/* ROM reduce */
+/* #undef ASC_COMPONENT_CORE_SUPPORTS_RESTART */
+/* #undef ASC_COLLECTORS_INFO_SUPPORT */
+/* #undef ASC_LINKED_LIST_NODE_SUPPORT */
+
+/* Log */
+// Highest compiled log level
+/* #undef ASC_LOG_LEVEL */
+/* #undef ASC_TIME_H_SUPPORT */
+/* #undef ASC_LOG_TIMESTAMP_DEFAULT */
+
+/* Notifier definitions */
+#define ASC_NOTIFIERS_OBJECT_POOL_ENTRIES 2
+
+/* Event loop best effort */
+#define ASC_BEST_EFFORT_EVENT_LOOP
+#define ASC_BE_TIMERS_OBJECT_POOL_ENTRIES 2
+
+/* Flat buffer serializer */
+#define ASC_SERIALIZER_USE_CUSTOM_ALLOCATOR
+/* #undef ASC_FLATCC_JSON_PRINTER_OVERWRITE */
+#define ASC_EMITTER_PAGE_CACHE_SIZE 1
+/* #undef FLATCC_NO_ASSERT */
+/* FLATCC_ASSERT might be redefined in platform area */
+#define FLATCC_ASSERT NX_ASSERT
+#define FLATCC_USE_GENERIC_ALIGNED_ALLOC
+/* #undef FLATCC_EMITTER_PAGE_SIZE */
+
+/* Tests definitions */
+// Set ASC_FIRST_FORCE_COLLECTION_INTERVAL to '-1' to force immediatly collecting
+/* #undef ASC_FIRST_FORCE_COLLECTION_INTERVAL */
+/* #undef ASC_EXTRA_BE_TIMERS_OBJECT_POOL_ENTRIES */
+/* #undef ASC_EXTRA_NOTIFIERS_OBJECT_POOL_ENTRIES */
+/* #undef ASC_EXTRA_COMPONENTS_COUNT */
+#ifndef ASC_EXTRA_COMPONENTS_COUNT
+#define ASC_EXTRA_COMPONENTS_COUNT 0
+#endif
+/* #undef ASC_EXTRA_COLLECTORS_COUNT */
+#ifndef ASC_EXTRA_COLLECTORS_COUNT
+#define ASC_EXTRA_COLLECTORS_COUNT 0
+#endif
+
+#define LOOP_ASSERT_FAIL for (;;) { }
+#define LOOP_ASSERT(s) if (!(s)) {LOOP_ASSERT_FAIL}
+
+/************************
+* Platform configuration
+*************************/
+#ifdef FLATCC_ASSERT
+#undef FLATCC_ASSERT
+#endif
+
+#ifndef __ASC_CONFIG_EXCLUDE_PORT__H__
+#include "tx_port.h"
+#include "nx_port.h"
+#include "nx_api.h"
+
+/* Flat buffer serializer platform */
+#define FLATCC_ASSERT NX_ASSERT
+
+#endif /* __ASC_CONFIG_EXCLUDE_PORT__H__ */
+
+/* Security Module pending time, in seconds */
+#define ASC_SECURITY_MODULE_PENDING_TIME 60*5
+#define ASC_SECURITY_MODULE_SEND_MESSAGE_RETRY_TIME 3
+/* #undef ASC_SECURITY_MODULE_MAX_HUB_DEVICES */
+#ifndef ASC_SECURITY_MODULE_MAX_HUB_DEVICES
+#define ASC_SECURITY_MODULE_MAX_HUB_DEVICES 64
+#endif
+
+/* Collector network activity. */
+/* #undef ASC_COLLECTOR_NETWORK_ACTIVITY_TCP_DISABLED */
+/* #undef ASC_COLLECTOR_NETWORK_ACTIVITY_UDP_DISABLED */
+/* #undef ASC_COLLECTOR_NETWORK_ACTIVITY_ICMP_DISABLED */
+#define ASC_COLLECTOR_NETWORK_ACTIVITY_CAPTURE_UNICAST_ONLY
+
+/* The maximum number of IPv4 network events to store in memory. */
+#ifdef NX_DISABLE_IPV6
+#undef ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE
+#define ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE 0
+#endif
+
+#endif /* __ASC_CONFIG_H__ */
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/addons/azure_iot/azure_iot_security_module/inc/configs/RTOS_BASE_UT/asc_config.h b/addons/azure_iot/azure_iot_security_module/inc/configs/RTOS_BASE_UT/asc_config.h
new file mode 100644
index 00000000..8fdaa8db
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/inc/configs/RTOS_BASE_UT/asc_config.h
@@ -0,0 +1,188 @@
+/**************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure RTOS. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
+/* and in the root directory of this software. */
+/* */
+/**************************************************************************/
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Distribution RTOS_BASE_UT */
+#ifndef __ASC_CONFIG_H__
+#define __ASC_CONFIG_H__
+
+/********************
+* Core configuration
+*********************/
+/* Based on 2022.07.19-3.5.3 core tag */
+
+/* ID and version */
+#define ASC_SECURITY_MODULE_ID "defender-iot-micro-agent"
+#define SECURITY_MODULE_VERSION_MAJOR 3
+#define SECURITY_MODULE_VERSION_MINOR 5
+#define SECURITY_MODULE_VERSION_PATCH 4
+#ifndef SECURITY_MODULE_VERSION_MAJOR
+#define SECURITY_MODULE_VERSION_MAJOR 0
+#endif
+#ifndef SECURITY_MODULE_VERSION_MINOR
+#define SECURITY_MODULE_VERSION_MINOR 0
+#endif
+#ifndef SECURITY_MODULE_VERSION_PATCH
+#define SECURITY_MODULE_VERSION_PATCH 0
+#endif
+
+/* Collectors definitions */
+/* #undef ASC_DYNAMIC_COLLECTORS_MAX */
+#ifndef ASC_DYNAMIC_COLLECTORS_MAX
+#define ASC_DYNAMIC_COLLECTORS_MAX 0
+#endif
+#define ASC_COLLECTOR_HEARTBEAT_ENABLED
+
+/* #undef ASC_COLLECTOR_BASELINE_ENABLED */
+/* #undef ASC_BASELINE_REPORT_POOL_ENTRIES */
+
+/* #undef ASC_COLLECTOR_LOG_ENABLED */
+/* #undef ASC_LOG_REPORT_POOL_ENTRIES */
+
+#define ASC_COLLECTOR_NETWORK_ACTIVITY_ENABLED
+/* #undef ASC_COLLECTOR_NETWORK_ACTIVITY_SEND_EMPTY_EVENTS */
+#define ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV4_OBJECTS_IN_CACHE 4
+#define ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE 4
+#ifndef ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV4_OBJECTS_IN_CACHE
+#define ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV4_OBJECTS_IN_CACHE 0
+#endif
+#ifndef ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE
+#define ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE 0
+#endif
+
+/* #undef ASC_COLLECTOR_PROCESS_ENABLED */
+/* #undef ASC_COLLECTOR_PROCESS_SEND_EMPTY_EVENTS */
+/* #undef ASC_COLLECTOR_PROCESS_IN_CACHE */
+#ifndef ASC_COLLECTOR_PROCESS_IN_CACHE
+#define ASC_COLLECTOR_PROCESS_IN_CACHE 0
+#endif
+
+#define ASC_COLLECTOR_SYSTEM_INFORMATION_ENABLED
+
+/* #undef ASC_COLLECTOR_LISTENING_PORTS_ENABLED */
+
+/* Components definitions */
+/* #undef ASC_DYNAMIC_FACTORY_ENABLED */
+/* #undef ASC_DYNAMIC_FACTORY_PATH */
+/* #undef ASC_DYNAMIC_FACTORY_PATH_RUNTIME_SET */
+/* #undef ASC_DYNAMIC_COMPONENTS_MAX */
+#ifndef ASC_DYNAMIC_COMPONENTS_MAX
+#define ASC_DYNAMIC_COMPONENTS_MAX 0
+#endif
+
+/* #undef ASC_COMPONENT_COMMAND_EXECUTOR */
+/* #undef ASC_OPERATIONS_POOL_ENTRIES */
+
+/* #undef ASC_COMPONENT_CONFIGURATION */
+/* #undef ASC_COMPONENT_CONFIGURATION_PLAT */
+
+#define ASC_COMPONENT_SECURITY_MODULE
+
+/* Collection definitions */
+#define ASC_FIRST_COLLECTION_INTERVAL 30
+#define ASC_HIGH_PRIORITY_INTERVAL 10
+#define ASC_MEDIUM_PRIORITY_INTERVAL 30
+#define ASC_LOW_PRIORITY_INTERVAL 60
+
+/* Dynamic/Static memory */
+/* #undef ASC_DYNAMIC_MEMORY_ENABLED */
+
+/* ROM reduce */
+/* #undef ASC_COMPONENT_CORE_SUPPORTS_RESTART */
+/* #undef ASC_COLLECTORS_INFO_SUPPORT */
+/* #undef ASC_LINKED_LIST_NODE_SUPPORT */
+
+/* Log */
+// Highest compiled log level
+/* #undef ASC_LOG_LEVEL */
+/* #undef ASC_TIME_H_SUPPORT */
+/* #undef ASC_LOG_TIMESTAMP_DEFAULT */
+
+/* Notifier definitions */
+#define ASC_NOTIFIERS_OBJECT_POOL_ENTRIES 2
+
+/* Event loop best effort */
+#define ASC_BEST_EFFORT_EVENT_LOOP
+#define ASC_BE_TIMERS_OBJECT_POOL_ENTRIES 2
+
+/* Flat buffer serializer */
+#define ASC_SERIALIZER_USE_CUSTOM_ALLOCATOR
+#define ASC_FLATCC_JSON_PRINTER_OVERWRITE
+#define ASC_EMITTER_PAGE_CACHE_SIZE 1
+/* #undef FLATCC_NO_ASSERT */
+/* FLATCC_ASSERT might be redefined in platform area */
+/* #undef FLATCC_ASSERT */
+#define FLATCC_USE_GENERIC_ALIGNED_ALLOC
+/* #undef FLATCC_EMITTER_PAGE_SIZE */
+
+/* Tests definitions */
+// Set ASC_FIRST_FORCE_COLLECTION_INTERVAL to '-1' to force immediatly collecting
+#define ASC_FIRST_FORCE_COLLECTION_INTERVAL 2
+/* #undef ASC_EXTRA_BE_TIMERS_OBJECT_POOL_ENTRIES */
+#define ASC_EXTRA_NOTIFIERS_OBJECT_POOL_ENTRIES 1
+/* #undef ASC_EXTRA_COMPONENTS_COUNT */
+#ifndef ASC_EXTRA_COMPONENTS_COUNT
+#define ASC_EXTRA_COMPONENTS_COUNT 0
+#endif
+/* #undef ASC_EXTRA_COLLECTORS_COUNT */
+#ifndef ASC_EXTRA_COLLECTORS_COUNT
+#define ASC_EXTRA_COLLECTORS_COUNT 0
+#endif
+
+#define LOOP_ASSERT_FAIL for (;;) { }
+#define LOOP_ASSERT(s) if (!(s)) {LOOP_ASSERT_FAIL}
+
+/************************
+* Platform configuration
+*************************/
+#ifdef FLATCC_ASSERT
+#undef FLATCC_ASSERT
+#endif
+
+#ifndef __ASC_CONFIG_EXCLUDE_PORT__H__
+#include "tx_port.h"
+#include "nx_port.h"
+#include "nx_api.h"
+
+/* Flat buffer serializer platform */
+/* #undef FLATCC_ASSERT */
+
+#endif /* __ASC_CONFIG_EXCLUDE_PORT__H__ */
+
+/* Security Module pending time, in seconds */
+#define ASC_SECURITY_MODULE_PENDING_TIME 60*5
+#define ASC_SECURITY_MODULE_SEND_MESSAGE_RETRY_TIME 3
+#define ASC_SECURITY_MODULE_MAX_HUB_DEVICES 128
+#ifndef ASC_SECURITY_MODULE_MAX_HUB_DEVICES
+#define ASC_SECURITY_MODULE_MAX_HUB_DEVICES 64
+#endif
+
+/* Collector network activity. */
+/* #undef ASC_COLLECTOR_NETWORK_ACTIVITY_TCP_DISABLED */
+/* #undef ASC_COLLECTOR_NETWORK_ACTIVITY_UDP_DISABLED */
+/* #undef ASC_COLLECTOR_NETWORK_ACTIVITY_ICMP_DISABLED */
+#define ASC_COLLECTOR_NETWORK_ACTIVITY_CAPTURE_UNICAST_ONLY
+
+/* The maximum number of IPv4 network events to store in memory. */
+#ifdef NX_DISABLE_IPV6
+#undef ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE
+#define ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE 0
+#endif
+
+#endif /* __ASC_CONFIG_H__ */
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/addons/azure_iot/azure_iot_security_module/inc/iot_security_module/model/objects/object_network_activity_ext.h b/addons/azure_iot/azure_iot_security_module/inc/iot_security_module/model/objects/object_network_activity_ext.h
index 4a8b11f8..4252b2ee 100644
--- a/addons/azure_iot/azure_iot_security_module/inc/iot_security_module/model/objects/object_network_activity_ext.h
+++ b/addons/azure_iot/azure_iot_security_module/inc/iot_security_module/model/objects/object_network_activity_ext.h
@@ -12,11 +12,12 @@
#ifndef OBJECT_NETWORK_ACTIVITY_EXT_H
#define OBJECT_NETWORK_ACTIVITY_EXT_H
+#include
+
#ifdef __cplusplus
extern "C" {
#endif
-#include "asc_security_core/configuration.h"
#include "asc_security_core/utils/collection/hashset.h"
#include "asc_security_core/model/objects/network_activity.h"
diff --git a/addons/azure_iot/azure_iot_security_module/inc/iot_security_module/mti.h b/addons/azure_iot/azure_iot_security_module/inc/iot_security_module/mti.h
index 11511647..63a99629 100644
--- a/addons/azure_iot/azure_iot_security_module/inc/iot_security_module/mti.h
+++ b/addons/azure_iot/azure_iot_security_module/inc/iot_security_module/mti.h
@@ -9,6 +9,8 @@
/* */
/**************************************************************************/
+#include
+
#ifndef MTI_RTOS_H
#define MTI_RTOS_H
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/CMakeLists.txt b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/CMakeLists.txt
index 4fe194de..a1417981 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/CMakeLists.txt
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/CMakeLists.txt
@@ -1,138 +1,134 @@
-cmake_minimum_required(VERSION 3.13)
-
-set(TARGET_NAME "asc_security_core")
-project(${TARGET_NAME})
-
-
-set(build_pedantic ON CACHE BOOL "use -Wpedantic flag in compilation")
-
-# Include the common build rules for the security module core
-include(cmake-modules/asc_security_coreBuild.cmake)
-include(cmake-modules/asc_security_core_build_rules.cmake)
-
-# the following variables are project-wide and can be used with cmake-gui
-set(run_unittests OFF CACHE BOOL "set run_unittests to ON to run unittests (default is OFF)")
-set(run_coverage OFF CACHE BOOL "set run_coverage to ON to gather coverage info (default is OFF)")
-set(use_dynamic_memory OFF CACHE BOOL "use the stack memory instead of using heap memory")
-set(disable_asc_port OFF CACHE BOOL "explicitly disable ASC_PORT include")
-set(serializer_custom_allocator OFF CACHE BOOL "Use custom allocator for flatcc")
-set(build_json_printer OFF CACHE BOOL "Build the json printer")
-
-# collector options
-set(collector_force_first_interval 0 CACHE STRING "Force first collector interval")
-set(collector_heartbeat_enabled ON CACHE BOOL "Enable the heartbeat collector")
-set(collector_network_activity_enabled OFF CACHE BOOL "Enable the network activity collector")
-set(collector_system_information_enabled OFF CACHE BOOL "Enable the system information collector")
-set(collector_listening_ports_enabled OFF CACHE BOOL "Enable the listening ports collector")
-set(collector_baseline_enabled OFF CACHE BOOL "Enable the baseline collector")
-set(build_as_32 OFF CACHE BOOL "build as 32 bit")
-
-# components options
-set(component_command_executor_enabled OFF CACHE BOOL "Enable the command executor component")
-set(best_effort_event_loop_enabled OFF CACHE BOOL "Compile best effort event loop")
-
-# reslove logger log level
-set(LOG_LEVELS NOTSET DEBUG INFO WARNING ERROR FATAL)
-set(log_level NOTSET CACHE STRING "log_level: ${log_level} (default is NOTSET)")
-set_property(CACHE log_level PROPERTY STRINGS NOTSET DEBUG INFO WARNING ERROR FATAL)
-list(FIND LOG_LEVELS ${log_level} log_level_index)
-if(log_level_index EQUAL -1)
- message(FATAL_ERROR "log_level must be one of ${LOG_LEVELS}")
-endif()
-
-list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake-modules")
-
-if(${collector_force_first_interval})
- message("Forcing first collection interval to ${collector_force_first_interval}")
- add_definitions(
- -DASC_FIRST_FORCE_COLLECTION_INTERVAL=${collector_force_first_interval}
- )
-endif()
-
-if(${run_unittests})
- FILE(REMOVE ${CMAKE_BINARY_DIR}/valgrind_targets.lst)
-
- set(disable_asc_port ON)
- set(collector_heartbeat_enabled ON)
- set(component_command_executor_enabled ON)
- set(best_effort_event_loop_enabled ON)
-
- if (${run_coverage})
- include(asc_security_coreCodeCoverage)
- include(asc_security_coreCreateCodeCoverageTargets)
- include(asc_security_coreCheckAndIncludeCodeCov)
- endif ()
-endif()
-
-add_library(${TARGET_NAME} STATIC
- # componets
- $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/command_executor.c>
-
- $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/collectors/collector_heartbeat.c>
- $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/collectors/baseline.c>
- $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/serializer/baseline.c>
- $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/model/objects/object_baseline_ext.c>
- $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/serializer/heartbeat.c>
- $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/serializer/listening_ports.c>
- $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/serializer/network_activity.c>
- $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/serializer/system_information.c>
-
- $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/serializer/extensions/custom_builder_allocator.c>
- $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/serializer/extensions/page_allocator.c>
-
- src/collector_collection_factory.c
- src/collector_collection_internal.c
- src/collector_collection.c
- src/collectors_info.c
- src/core.c
- src/logger.c
- src/model/collector.c
- src/model/security_message.c
- src/serializer/serializer_private.c
- src/serializer/serializer.c
- src/utils/notifier.c
- $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/utils/event_loop_be.c>
- src/utils/string_utils.c
-)
-
-target_compile_definitions(${TARGET_NAME} PUBLIC
- LOG_LEVEL=${log_level_index}
-
- $<$:DISABLE_ASC_PORT>
- $<$:DYNAMIC_MEMORY_ENABLED>
- $<$:ASC_SERIALIZER_USE_CUSTOM_ALLOCATOR>
-
- $<$:CONFIG_COMPONENT_COMMAND_EXECUTOR>
-)
-
-target_include_directories(${TARGET_NAME} PUBLIC inc)
-
-add_subdirectory(deps)
-target_link_libraries(${TARGET_NAME} PRIVATE
- flatccrt
-)
-target_include_directories(flatccrt PRIVATE inc)
-
-if(${serializer_custom_allocator})
- target_link_libraries(flatccrt PRIVATE asc_security_core)
- target_sources(flatccrt PRIVATE src/serializer/extensions/custom_emitter.c)
- target_include_directories(flatccrt PRIVATE deps/flatcc/src/runtime)
-endif()
-
-if (${run_unittests})
- enable_testing()
- include(CTest)
-
- add_definitions(
- -DEXTRA_BE_TIMERS_OBJECT_POOL_ENTRIES=10
- -DEXTRA_NOTIFIERS_OBJECT_POOL_ENTRIES=1
- # we have 7 test collectors
- -DEXTRA_COLLECTORS_OBJECT_POOL_COUNT=7
- )
-
- add_subdirectory(tests)
-
-endif ()
-
-setTargetCompileOptions(${TARGET_NAME})
-compileTargetAsC99(${TARGET_NAME})
+cmake_minimum_required(VERSION 3.13)
+
+set(TARGET_NAME "asc_security_core")
+project(${TARGET_NAME})
+
+# Include the common build rules for the security module core
+include(cmake-modules/asc_security_coreBuild.cmake)
+include(cmake-modules/asc_security_core_build_rules.cmake)
+
+include(configs/functions.cmake)
+
+CONF_LOG_LEVEL()
+
+CONF_INC_CLEAN()
+
+if(DEFINED dist_test)
+ include_directories(${CMAKE_SOURCE_DIR}/inc/configs/${dist_test})
+ CONF_CREATE_DIST(
+ ${dist_test}
+ ${CMAKE_SOURCE_DIR}/configs/test/
+ ${CMAKE_SOURCE_DIR}/configs/test/plat/
+ ${CMAKE_SOURCE_DIR}/inc/configs/${dist_test}/asc_config_test.h
+ __ASC_CONFIG_TEST_H__
+ OFF
+ ON
+ )
+endif()
+
+if(NOT DEFINED IOT_SECURITY_MODULE_DIST_TARGET AND NOT DEFINED DEFENDER_IOT_MICRO_AGENT_DIST_CORE)
+ message(FATAL_ERROR "Target Distribution Undefined")
+endif()
+
+if(DEFINED DEFENDER_IOT_MICRO_AGENT_DIST_CORE)
+ include_directories(${CMAKE_SOURCE_DIR}/inc/configs/${DEFENDER_IOT_MICRO_AGENT_DIST_CORE})
+ CONF_CREATE_DIST(
+ ${DEFENDER_IOT_MICRO_AGENT_DIST_CORE}
+ ${CMAKE_SOURCE_DIR}/configs/
+ ${CMAKE_SOURCE_DIR}/configs/
+ ${CMAKE_SOURCE_DIR}/inc/configs/${DEFENDER_IOT_MICRO_AGENT_DIST_CORE}/asc_config.h
+ __ASC_CONFIG_H__
+ ON
+ OFF
+ )
+endif()
+
+if (DEFINED asc_config_h_only)
+ if (${asc_config_h_only})
+ message("asc_config_h_only is ${asc_config_h_only} - configuration finished")
+ return()
+ endif()
+endif()
+
+set(build_pedantic ON CACHE BOOL "use -Wpedantic flag in compilation")
+
+# the following variables are project-wide and can be used with cmake-gui
+set(build_as_32 OFF CACHE BOOL "build as 32 bit")
+
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake-modules")
+
+if(${run_core_unittests})
+ FILE(REMOVE ${CMAKE_BINARY_DIR}/valgrind_targets.lst)
+
+ if (${run_core_coverage})
+ include(asc_security_coreCodeCoverage)
+ include(asc_security_coreCreateCodeCoverageTargets)
+ include(asc_security_coreCheckAndIncludeCodeCov)
+ endif ()
+endif()
+
+add_library(${TARGET_NAME} STATIC
+ # components
+ $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/cli_plat.c>
+
+ $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/command_executor.c>
+ $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/configuration.c>
+
+ $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/collectors/collector_heartbeat.c>
+ $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/collectors/baseline.c>
+ $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/serializer/baseline.c>
+ $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/model/objects/object_baseline_ext.c>
+ $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/serializer/log.c>
+ $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/serializer/heartbeat.c>
+ $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/serializer/process.c>
+ $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/serializer/listening_ports.c>
+ $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/serializer/network_activity.c>
+ $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/serializer/system_information.c>
+
+ $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/serializer/extensions/custom_builder_allocator.c>
+ $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/serializer/extensions/page_allocator.c>
+
+ src/components_factory.c
+ src/components_manager.c
+ src/collector_collection.c
+ $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/collectors_info.c>
+ src/core.c
+ src/logger.c
+ src/model/collector.c
+ src/model/security_message.c
+ src/serializer/serializer_private.c
+ src/serializer/serializer.c
+ src/utils/iconv.c
+ src/utils/notifier.c
+ src/utils/uuid.c
+ src/utils/collection/bit_vector.c
+ src/utils/collection/stack.c
+ src/utils/collection/list.c
+ src/utils/collection/hashtable.c
+ $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/utils/collection/linked_list_node.c>
+ $,src/object_pool_dynamic.c,src/object_pool_static.c>
+ $<$:${CMAKE_CURRENT_SOURCE_DIR}/src/utils/event_loop_be.c>
+ src/utils/string_utils.c
+)
+
+target_include_directories(${TARGET_NAME} PUBLIC inc)
+
+add_subdirectory(deps)
+target_link_libraries(${TARGET_NAME} PRIVATE
+ flatccrt
+)
+
+if(${ASC_SERIALIZER_USE_CUSTOM_ALLOCATOR})
+ target_link_libraries(flatccrt PRIVATE asc_security_core)
+ target_include_directories(flatccrt PRIVATE deps/flatcc/src/runtime)
+endif()
+
+if (${run_core_unittests})
+ enable_testing()
+ include(CTest)
+ add_subdirectory(tests)
+
+endif ()
+
+setTargetCompileOptions(${TARGET_NAME})
+compileTargetAsC99(${TARGET_NAME})
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/cmake-modules/asc_security_coreBuild.cmake b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/cmake-modules/asc_security_coreBuild.cmake
index c1957acc..0d79a56c 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/cmake-modules/asc_security_coreBuild.cmake
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/cmake-modules/asc_security_coreBuild.cmake
@@ -51,12 +51,12 @@ function(setTargetCompileOptions target)
"-Wfloat-equal"
"-Wmissing-declarations"
"-Wno-unused-parameter"
- "-Wno-cast-function-type"
+ "-Wjump-misses-init"
)
if(${build_pedantic})
message(STATUS "Using '-Wpedantic' flag for compilation as warning only for target ${target}")
- target_compile_options(${target} PRIVATE "-Wno-error=pedantic" "-Wpedantic" "-Wshadow")
+ target_compile_options(${target} PRIVATE "-Wpedantic" "-Wshadow")
#Temopary hack
target_compile_options(${target} PRIVATE "-Wno-error=overlength-strings")
endif()
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/cmake-modules/asc_security_core_build_rules.cmake b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/cmake-modules/asc_security_core_build_rules.cmake
index 7c1e3608..c81db82a 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/cmake-modules/asc_security_core_build_rules.cmake
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/cmake-modules/asc_security_core_build_rules.cmake
@@ -54,3 +54,68 @@ function(usePermissiveRulesForSamplesAndTests)
endif()
endfunction()
+function(add_exec_target _TARGET_NAME)
+
+ set(one_value_arguments
+ )
+
+ set(multi_value_arguments
+ SOURCES
+ COMPILE_OPTIONS
+ MOCK_FUNCTIONS
+ PRIVATE_ACCESS
+ LINK_TARGETS
+ )
+
+ cmake_parse_arguments(_add_exec_target
+ ""
+ "${one_value_arguments}"
+ "${multi_value_arguments}"
+ ${ARGN}
+ )
+
+ if (NOT DEFINED _add_exec_target_SOURCES)
+ message(FATAL_ERROR "No sources provided for target ${_TARGET_NAME}")
+ endif()
+
+ add_executable(${_TARGET_NAME} ${_add_exec_target_SOURCES})
+
+ if (DEFINED _add_exec_target_COMPILE_OPTIONS)
+ target_compile_options(${_TARGET_NAME}
+ PRIVATE ${_add_exec_target_COMPILE_OPTIONS}
+ )
+ endif()
+
+ if (DEFINED _add_exec_target_LINK_TARGETS)
+ target_link_libraries(${_TARGET_NAME}
+ PRIVATE
+ ${_add_exec_target_LINK_TARGETS}
+ )
+ endif()
+
+ if (DEFINED _add_exec_target_MOCK_FUNCTIONS)
+ set(functions "")
+ foreach(function ${_add_exec_target_MOCK_FUNCTIONS})
+ set(functions "${functions} -Wl,--wrap=${function}")
+ endforeach()
+
+ set_target_properties(${_TARGET_NAME}
+ PROPERTIES LINK_FLAGS
+ ${functions}
+ )
+
+ # Used for apply mocks in Azure RTOS
+ get_target_property(libs ${_TARGET_NAME} LINK_LIBRARIES)
+ foreach(function ${_add_exec_target_MOCK_FUNCTIONS})
+ list(INSERT libs 0
+ -Wl,-wrap,${function}
+ )
+ endforeach()
+ set_target_properties(${TARGET_NAME} PROPERTIES LINK_LIBRARIES "${libs}")
+ endif()
+
+ setTargetCompileOptions(${TARGET_NAME})
+ compileTargetAsC99(${_TARGET_NAME})
+
+endfunction (add_exec_target)
+
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/configs/asc_config.h.in b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/configs/asc_config.h.in
new file mode 100644
index 00000000..96c46284
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/configs/asc_config.h.in
@@ -0,0 +1,125 @@
+/********************
+* Core configuration
+*********************/
+/* Based on 2022.07.19-3.5.3 core tag */
+
+/* ID and version */
+#cmakedefine ASC_SECURITY_MODULE_ID "@ASC_SECURITY_MODULE_ID@"
+#cmakedefine SECURITY_MODULE_VERSION_MAJOR @SECURITY_MODULE_VERSION_MAJOR@
+#cmakedefine SECURITY_MODULE_VERSION_MINOR @SECURITY_MODULE_VERSION_MINOR@
+#cmakedefine SECURITY_MODULE_VERSION_PATCH @SECURITY_MODULE_VERSION_PATCH@
+#ifndef SECURITY_MODULE_VERSION_MAJOR
+#define SECURITY_MODULE_VERSION_MAJOR 0
+#endif
+#ifndef SECURITY_MODULE_VERSION_MINOR
+#define SECURITY_MODULE_VERSION_MINOR 0
+#endif
+#ifndef SECURITY_MODULE_VERSION_PATCH
+#define SECURITY_MODULE_VERSION_PATCH 0
+#endif
+
+/* Collectors definitions */
+#cmakedefine ASC_DYNAMIC_COLLECTORS_MAX @ASC_DYNAMIC_COLLECTORS_MAX@
+#ifndef ASC_DYNAMIC_COLLECTORS_MAX
+#define ASC_DYNAMIC_COLLECTORS_MAX 0
+#endif
+#cmakedefine ASC_COLLECTOR_HEARTBEAT_ENABLED
+
+#cmakedefine ASC_COLLECTOR_BASELINE_ENABLED
+#cmakedefine ASC_BASELINE_REPORT_POOL_ENTRIES @ASC_BASELINE_REPORT_POOL_ENTRIES@
+
+#cmakedefine ASC_COLLECTOR_LOG_ENABLED
+#cmakedefine ASC_LOG_REPORT_POOL_ENTRIES @ASC_LOG_REPORT_POOL_ENTRIES@
+
+#cmakedefine ASC_COLLECTOR_NETWORK_ACTIVITY_ENABLED
+#cmakedefine ASC_COLLECTOR_NETWORK_ACTIVITY_SEND_EMPTY_EVENTS
+#cmakedefine ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV4_OBJECTS_IN_CACHE @ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV4_OBJECTS_IN_CACHE@
+#cmakedefine ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE @ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE@
+#ifndef ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV4_OBJECTS_IN_CACHE
+#define ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV4_OBJECTS_IN_CACHE 0
+#endif
+#ifndef ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE
+#define ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE 0
+#endif
+
+#cmakedefine ASC_COLLECTOR_PROCESS_ENABLED
+#cmakedefine ASC_COLLECTOR_PROCESS_SEND_EMPTY_EVENTS
+#cmakedefine ASC_COLLECTOR_PROCESS_IN_CACHE @ASC_COLLECTOR_PROCESS_IN_CACHE@
+#ifndef ASC_COLLECTOR_PROCESS_IN_CACHE
+#define ASC_COLLECTOR_PROCESS_IN_CACHE 0
+#endif
+
+#cmakedefine ASC_COLLECTOR_SYSTEM_INFORMATION_ENABLED
+
+#cmakedefine ASC_COLLECTOR_LISTENING_PORTS_ENABLED
+
+/* Components definitions */
+#cmakedefine ASC_DYNAMIC_FACTORY_ENABLED
+#cmakedefine ASC_DYNAMIC_FACTORY_PATH "@ASC_DYNAMIC_FACTORY_PATH@"
+#cmakedefine ASC_DYNAMIC_FACTORY_PATH_RUNTIME_SET
+#cmakedefine ASC_DYNAMIC_COMPONENTS_MAX @ASC_DYNAMIC_COMPONENTS_MAX@
+#ifndef ASC_DYNAMIC_COMPONENTS_MAX
+#define ASC_DYNAMIC_COMPONENTS_MAX 0
+#endif
+
+#cmakedefine ASC_COMPONENT_COMMAND_EXECUTOR
+#cmakedefine ASC_OPERATIONS_POOL_ENTRIES @ASC_OPERATIONS_POOL_ENTRIES@
+
+#cmakedefine ASC_COMPONENT_CONFIGURATION
+#cmakedefine ASC_COMPONENT_CONFIGURATION_PLAT
+
+#cmakedefine ASC_COMPONENT_SECURITY_MODULE
+
+/* Collection definitions */
+#cmakedefine ASC_FIRST_COLLECTION_INTERVAL @ASC_FIRST_COLLECTION_INTERVAL@
+#cmakedefine ASC_HIGH_PRIORITY_INTERVAL @ASC_HIGH_PRIORITY_INTERVAL@
+#cmakedefine ASC_MEDIUM_PRIORITY_INTERVAL @ASC_MEDIUM_PRIORITY_INTERVAL@
+#cmakedefine ASC_LOW_PRIORITY_INTERVAL @ASC_LOW_PRIORITY_INTERVAL@
+
+/* Dynamic/Static memory */
+#cmakedefine ASC_DYNAMIC_MEMORY_ENABLED
+
+/* ROM reduce */
+#cmakedefine ASC_COMPONENT_CORE_SUPPORTS_RESTART
+#cmakedefine ASC_COLLECTORS_INFO_SUPPORT
+#cmakedefine ASC_LINKED_LIST_NODE_SUPPORT
+
+/* Log */
+// Highest compiled log level
+#cmakedefine ASC_LOG_LEVEL @ASC_LOG_LEVEL@
+#cmakedefine ASC_TIME_H_SUPPORT
+#cmakedefine ASC_LOG_TIMESTAMP_DEFAULT
+
+/* Notifier definitions */
+#cmakedefine ASC_NOTIFIERS_OBJECT_POOL_ENTRIES @ASC_NOTIFIERS_OBJECT_POOL_ENTRIES@
+
+/* Event loop best effort */
+#cmakedefine ASC_BEST_EFFORT_EVENT_LOOP
+#cmakedefine ASC_BE_TIMERS_OBJECT_POOL_ENTRIES @ASC_BE_TIMERS_OBJECT_POOL_ENTRIES@
+
+/* Flat buffer serializer */
+#cmakedefine ASC_SERIALIZER_USE_CUSTOM_ALLOCATOR
+#cmakedefine ASC_FLATCC_JSON_PRINTER_OVERWRITE
+#cmakedefine ASC_EMITTER_PAGE_CACHE_SIZE @ASC_EMITTER_PAGE_CACHE_SIZE@
+#cmakedefine FLATCC_NO_ASSERT
+/* FLATCC_ASSERT might be redefined in platform area */
+#cmakedefine FLATCC_ASSERT @FLATCC_ASSERT@
+#cmakedefine FLATCC_USE_GENERIC_ALIGNED_ALLOC
+#cmakedefine FLATCC_EMITTER_PAGE_SIZE @FLATCC_EMITTER_PAGE_SIZE@
+
+/* Tests definitions */
+// Set ASC_FIRST_FORCE_COLLECTION_INTERVAL to '-1' to force immediatly collecting
+#cmakedefine ASC_FIRST_FORCE_COLLECTION_INTERVAL @ASC_FIRST_FORCE_COLLECTION_INTERVAL@
+#cmakedefine ASC_EXTRA_BE_TIMERS_OBJECT_POOL_ENTRIES @ASC_EXTRA_BE_TIMERS_OBJECT_POOL_ENTRIES@
+#cmakedefine ASC_EXTRA_NOTIFIERS_OBJECT_POOL_ENTRIES @ASC_EXTRA_NOTIFIERS_OBJECT_POOL_ENTRIES@
+#cmakedefine ASC_EXTRA_COMPONENTS_COUNT @ASC_EXTRA_COMPONENTS_COUNT@
+#ifndef ASC_EXTRA_COMPONENTS_COUNT
+#define ASC_EXTRA_COMPONENTS_COUNT 0
+#endif
+#cmakedefine ASC_EXTRA_COLLECTORS_COUNT @ASC_EXTRA_COLLECTORS_COUNT@
+#ifndef ASC_EXTRA_COLLECTORS_COUNT
+#define ASC_EXTRA_COLLECTORS_COUNT 0
+#endif
+
+#define LOOP_ASSERT_FAIL for (\;\;) { }
+#define LOOP_ASSERT(s) if (!(s)) {LOOP_ASSERT_FAIL}
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/configs/base_dist.cmake b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/configs/base_dist.cmake
new file mode 100644
index 00000000..9a6a3a72
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/configs/base_dist.cmake
@@ -0,0 +1,37 @@
+set(ASC_SECURITY_MODULE_ID "defender-iot-micro-agent")
+set(ASC_FIRST_COLLECTION_INTERVAL 30)
+set(ASC_HIGH_PRIORITY_INTERVAL 10)
+set(ASC_MEDIUM_PRIORITY_INTERVAL 30)
+set(ASC_LOW_PRIORITY_INTERVAL 60)
+
+set(ASC_COLLECTOR_HEARTBEAT_ENABLED ON)
+set(ASC_COLLECTOR_BASELINE_ENABLED OFF)
+set(ASC_COLLECTOR_NETWORK_ACTIVITY_ENABLED OFF)
+set(ASC_COLLECTOR_PROCESS_ENABLED OFF)
+set(ASC_COLLECTOR_SYSTEM_INFORMATION_ENABLED OFF)
+set(ASC_COLLECTOR_LISTENING_PORTS_ENABLED OFF)
+
+set(ASC_COMPONENT_COMMAND_EXECUTOR OFF)
+set(ASC_COMPONENT_CONFIGURATION OFF)
+set(ASC_COMPONENT_SECURITY_MODULE OFF)
+
+set(ASC_OPERATIONS_POOL_ENTRIES 50)
+set(ASC_BASELINE_REPORT_POOL_ENTRIES 100)
+set(ASC_LOG_REPORT_POOL_ENTRIES 100)
+set(ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV4_OBJECTS_IN_CACHE 64)
+set(ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE 64)
+set(ASC_COLLECTOR_PROCESS_IN_CACHE 32)
+
+set(ASC_DYNAMIC_MEMORY_ENABLED OFF)
+
+set(ASC_BEST_EFFORT_EVENT_LOOP OFF)
+
+set(ASC_LOG_TIMESTAMP_DEFAULT ON)
+
+set(run_core_unittests OFF)
+set(run_core_coverage OFF)
+set(build_json_printer OFF)
+set(FLATCC_NO_ASSERT OFF)
+set(FLATCC_USE_GENERIC_ALIGNED_ALLOC ON)
+set(ASC_FLATCC_JSON_PRINTER_OVERWRITE OFF)
+set(ASC_COMPONENT_CORE_SUPPORTS_RESTART ON)
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/configs/depends_configuration.cmake b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/configs/depends_configuration.cmake
new file mode 100644
index 00000000..a4b67b4a
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/configs/depends_configuration.cmake
@@ -0,0 +1,47 @@
+if(NOT ASC_COMPONENT_CONFIGURATION)
+ set(ASC_COMPONENT_CONFIGURATION_PLAT OFF)
+endif()
+
+if(NOT ASC_COMPONENT_COMMAND_EXECUTOR)
+ set(ASC_OPERATIONS_POOL_ENTRIES 0)
+ set(ASC_COMPONENT_CONFIGURATION_PLAT OFF)
+endif()
+
+if(NOT ASC_COLLECTOR_BASELINE_ENABLED)
+ set(ASC_BASELINE_REPORT_POOL_ENTRIES 0)
+ set(ASC_COMPONENT_BASELINE_PLAT OFF)
+endif()
+
+if(NOT ASC_COLLECTOR_LOG_ENABLED)
+ set(ASC_LOG_REPORT_POOL_ENTRIES 0)
+endif()
+
+if(NOT ASC_COLLECTOR_NETWORK_ACTIVITY_ENABLED)
+ set(ASC_COLLECTOR_NETWORK_ACTIVITY_SEND_EMPTY_EVENTS OFF)
+ set(ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV4_OBJECTS_IN_CACHE 0)
+ set(ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE 0)
+endif()
+
+if(NOT ASC_COLLECTOR_PROCESS_ENABLED)
+ set(ASC_COLLECTOR_PROCESS_SEND_EMPTY_EVENTS OFF)
+ set(ASC_COLLECTOR_PROCESS_IN_CACHE 0)
+ set(ASC_COLLECTOR_PROCESS_MODE_AGGREGATED_DISABLE OFF)
+endif()
+
+if(NOT ASC_DYNAMIC_FACTORY_ENABLED)
+ set(ASC_DYNAMIC_COMPONENTS_MAX 0)
+ set(ASC_DYNAMIC_COLLECTORS_MAX 0)
+ set(ASC_DYNAMIC_FACTORY_PATH OFF)
+ set(ASC_DYNAMIC_FACTORY_PATH_RUNTIME_SET OFF)
+endif()
+
+if(FLATCC_NO_ASSERT)
+ set(FLATCC_ASSERT OFF)
+endif()
+
+if(NOT ASC_DYNAMIC_MEMORY_ENABLED)
+ set(ASC_SERIALIZER_USE_CUSTOM_ALLOCATOR ON)
+ set(ASC_EMITTER_PAGE_CACHE_SIZE 1)
+else()
+ set(FLATCC_EMITTER_PAGE_SIZE 14016)
+endif()
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/configs/functions.cmake b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/configs/functions.cmake
new file mode 100644
index 00000000..904d82de
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/configs/functions.cmake
@@ -0,0 +1,102 @@
+macro(CONF_DEPENDS_OPTIONS __core_config_dir)
+ # include default depends configuration
+ include(${__core_config_dir}depends_configuration.cmake)
+endmacro()
+
+macro(CONF_DEFINE_BASE __config_path __base)
+ # include default configuration from specific base dist
+ include(${__config_path}${__base})
+endmacro()
+
+macro(CONF_IN_FILE_OPEN __core_config_dir __plat_config_dir __dist __path __ifdef __cpp)
+ FILE(REMOVE ${__path})
+ if(NOT "${__core_config_dir}" STREQUAL "${__plat_config_dir}")
+ file(READ ${__plat_config_dir}/license __license_body)
+ else()
+ file(READ ${__core_config_dir}/license __license_body)
+ endif()
+ FILE(APPEND ${__path} ${__license_body})
+ if (${__cpp})
+ FILE(APPEND ${__path} "\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n")
+ endif()
+
+ FILE(APPEND ${__path} "/* Distribution ")
+ FILE(APPEND ${__path} ${__dist} " */")
+ FILE(APPEND ${__path} \n)
+ FILE(APPEND ${__path} "#ifndef " ${__ifdef}\n)
+ FILE(APPEND ${__path} "#define " ${__ifdef}\n\n)
+endmacro()
+
+macro(CONF_IN_FILE_BODY __core_config_dir __plat_config_dir __path)
+ file(READ ${__core_config_dir}/asc_config.h.in __cfg_body)
+ FILE(APPEND ${__path} ${__cfg_body})
+ if(NOT "${__core_config_dir}" STREQUAL "${__plat_config_dir}")
+ message("Merging platform asc_config.h.in")
+ file(READ ${__plat_config_dir}/asc_config.h.in __cfg_body)
+ FILE(APPEND ${__path} ${__cfg_body})
+ endif()
+ set(__cfg_body "")
+endmacro()
+
+macro(CONF_IN_FILE_CLOSE __path __def __cpp)
+ FILE(APPEND ${__path} \n)
+ FILE(APPEND ${__path} "#endif /* ${__def} */")
+ if (${__cpp})
+ FILE(APPEND ${__path} "\n\n#ifdef __cplusplus\n}\n#endif")
+ endif()
+endmacro()
+
+macro(CONF_IN_CREATE __core_config_dir __plat_config_dir __dist __path __ifdef __cpp)
+ CONF_IN_FILE_OPEN(${__core_config_dir} ${__plat_config_dir} ${__dist} ${__path} ${__ifdef} ${__cpp})
+ CONF_IN_FILE_BODY(${__core_config_dir} ${__plat_config_dir} ${__path})
+ CONF_IN_FILE_CLOSE(${__path} ${__ifdef} ${__cpp})
+endmacro()
+
+macro(CONF_CREATE_DIST __dist __core_config_dir __plat_config_dir __output __ifdef __check_dist __cpp)
+ if (${__check_dist})
+ if (EXISTS ${CMAKE_BINARY_DIR}/built_dist.conf)
+ FILE(READ ${CMAKE_BINARY_DIR}/built_dist.conf _stored_dist)
+ if(DEFINED _stored_dist)
+ if ((NOT (${_stored_dist} STREQUAL "")) AND (NOT (${_stored_dist} STREQUAL ${__dist})))
+ message(FATAL_ERROR "Stored dist '${_stored_dist}' is not equal to current dist '${__dist}' - perform rebuild")
+ endif()
+ endif()
+ endif()
+ endif()
+ message("Seting distribution " ${__config_dir}${__dist})
+ set(g_core_config_path ${__core_config_dir})
+ set(g_plat_config_path ${__plat_config_dir})
+
+ # configure target dist
+ include(${__plat_config_dir}${__dist}.dist)
+
+ # set depends from ${__core_config_dir}depends_configuration.cmake
+ CONF_DEPENDS_OPTIONS(${__core_config_dir})
+
+ # create asc_config.h.in.tmp for target dist
+ CONF_IN_CREATE(${__core_config_dir} ${__plat_config_dir} ${__dist} ${CMAKE_BINARY_DIR}/asc_config.h.in.tmp ${__ifdef} ${__cpp})
+ configure_file(${CMAKE_BINARY_DIR}/asc_config.h.in.tmp ${__output} @ONLY)
+
+ # store current dist
+ if (${__check_dist})
+ FILE(WRITE ${CMAKE_BINARY_DIR}/built_dist.conf ${__dist})
+ endif()
+
+ # clean up
+ FILE(REMOVE ${CMAKE_BINARY_DIR}/asc_config.h.in.tmp)
+endmacro()
+
+macro(CONF_LOG_LEVEL)
+ if(NOT DEFINED log_level)
+ set(log_level NOTSET)
+ endif()
+ set(LOG_LEVELS NOTSET FATAL ERROR WARNING INFO DEBUG)
+ list(FIND LOG_LEVELS ${log_level} log_level_index)
+ if(log_level_index EQUAL -1)
+ message(FATAL_ERROR "log_level must be one of ${LOG_LEVELS}")
+ endif()
+ set(ASC_LOG_LEVEL ${log_level_index})
+endmacro()
+
+macro(CONF_INC_CLEAN)
+endmacro()
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/CMakeLists.txt b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/CMakeLists.txt
index d6c5c108..ef172e14 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/CMakeLists.txt
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/CMakeLists.txt
@@ -7,16 +7,11 @@ set(build_as_32 OFF CACHE BOOL "build as 32 bit")
# Build flatcc runtime library
add_library(flatccrt STATIC
- $<$>:${CMAKE_CURRENT_SOURCE_DIR}/flatcc/src/runtime/emitter.c>
-
+ flatcc/src/runtime/emitter.c
flatcc/src/runtime/builder.c
flatcc/src/runtime/refmap.c
)
-target_compile_definitions(flatccrt PUBLIC
- FLATCC_NO_ASSERT
- $<$>:FLATCC_EMITTER_PAGE_SIZE=14016>
-)
target_include_directories(flatccrt PUBLIC flatcc/include)
target_compile_options(flatccrt
@@ -24,7 +19,7 @@ target_compile_options(flatccrt
$<$:-m32>
)
-if(${run_unittests} OR ${build_json_printer})
+if(${run_core_unittests} OR ${build_json_printer})
add_library(flatccrt_json STATIC
flatcc/src/runtime/json_printer.c
)
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/flatcc_alloc.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/flatcc_alloc.h
index af6b79fc..06ca4a0b 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/flatcc_alloc.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/flatcc_alloc.h
@@ -45,16 +45,16 @@ extern "C" {
#include
+#include
/* ASC Disable memory allocation usage */
+#ifdef ASC_SERIALIZER_USE_CUSTOM_ALLOCATOR
#define FLATCC_ALLOC(n) NULL
#define FLATCC_FREE(p) NULL
#define FLATCC_REALLOC(p,n) NULL
#define FLATCC_CALLOC(nm,n) NULL
#define FLATCC_ALIGNED_ALLOC(a,n) NULL
#define FLATCC_ALIGNED_FREE(p) NULL
-#ifndef FLATCC_USE_GENERIC_ALIGNED_ALLOC
-#define FLATCC_USE_GENERIC_ALIGNED_ALLOC
-#endif
+#endif /* ASC_SERIALIZER_USE_CUSTOM_ALLOCATOR */
#ifndef FLATCC_ALLOC
#define FLATCC_ALLOC(n) malloc(n)
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/flatcc_assert.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/flatcc_assert.h
index 3db3e7b0..7e9ccd3b 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/flatcc_assert.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/flatcc_assert.h
@@ -1,5 +1,6 @@
#ifndef FLATCC_ASSERT_H
#define FLATCC_ASSERT_H
+#include
#ifdef __cplusplus
extern "C" {
@@ -31,6 +32,13 @@ extern "C" {
#define FLATCC_ASSERT(x) ((void)0)
/* Grisu3 is used for floating point conversion in JSON processing. */
#define GRISU3_NO_ASSERT
+#define __SET_ASSERT__
+#define __ASSERT_VAL__
+#define __ASSERT_REASON__
+#else
+extern int __SET_ASSERT__;
+extern int __ASSERT_VAL__;
+extern const char *__ASSERT_REASON__;
#endif
#ifndef FLATCC_ASSERT
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/flatcc_emitter.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/flatcc_emitter.h
index 6216c516..69026e4e 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/flatcc_emitter.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/flatcc_emitter.h
@@ -5,6 +5,9 @@
extern "C" {
#endif
+#ifdef ASC_SERIALIZER_USE_CUSTOM_ALLOCATOR
+#include "asc_security_core/serializer/page_allocator.h"
+#endif
/*
* Default implementation of a flatbuilder emitter.
*
@@ -16,6 +19,8 @@ extern "C" {
#include
#include
+#include
+
#include "flatcc/flatcc_types.h"
#include "flatcc/flatcc_iov.h"
#include "flatcc/flatcc_alloc.h"
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/flatcc_endian.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/flatcc_endian.h
index 0592f313..c07b7bce 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/flatcc_endian.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/flatcc_endian.h
@@ -97,11 +97,11 @@ extern "C" {
/* flatcc/portable/pendian.h sets LITTLE/BIG flags if possible, and always defines le16toh. */
#ifndef flatbuffers_is_native_pe
-#if defined(__LITTLE_ENDIAN__) || FLATBUFFERS_LITTLEENDIAN
+#if (__LITTLE_ENDIAN__==1) || FLATBUFFERS_LITTLEENDIAN
#undef FLATBUFFERS_LITTLEENDIAN
#define FLATBUFFERS_LITTLEENDIAN 1
#define flatbuffers_is_native_pe() (FLATBUFFERS_PROTOCOL_IS_LE)
-#elif defined(__BIG_ENDIAN__) || (defined(FLATBUFFERS_LITTLEENDIAN) && !FLATBUFFERS_LITTLEENDIAN)
+#elif (__BIG_ENDIAN__==1) || (defined(FLATBUFFERS_LITTLEENDIAN) && !FLATBUFFERS_LITTLEENDIAN)
#undef FLATBUFFERS_LITTLEENDIAN
#define FLATBUFFERS_LITTLEENDIAN 0
#define flatbuffers_is_native_pe() (FLATBUFFERS_PROTOCOL_IS_BE)
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/portable/pendian.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/portable/pendian.h
index 122ba8e2..3b174ba0 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/portable/pendian.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/portable/pendian.h
@@ -131,7 +131,7 @@ extern "C" {
/* Assume it goes for all. */
#if !defined(le16toh)
-#if defined(__LITTLE_ENDIAN__)
+#if (__LITTLE_ENDIAN__==1)
#define le16toh(v) (v)
#define le32toh(v) (v)
@@ -149,7 +149,7 @@ extern "C" {
#define htobe32(v) bswap32(v)
#define htobe64(v) bswap64(v)
-#elif defined(__BIG_ENDIAN__)
+#elif (__BIG_ENDIAN__==1)
#define le16toh(v) bswap16(v)
#define le32toh(v) bswap32(v)
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/portable/pendian_detect.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/portable/pendian_detect.h
index 1dd62c04..5b8bf054 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/portable/pendian_detect.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/portable/pendian_detect.h
@@ -33,11 +33,11 @@ extern "C" {
#ifdef __BYTE_ORDER__
-#if defined(__LITTLE_ENDIAN__) && __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__
+#if (__LITTLE_ENDIAN__ == 1) && __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__
#error __LITTLE_ENDIAN__ inconsistent with __BYTE_ORDER__
#endif
-#if defined(__BIG_ENDIAN__) && __BYTE_ORDER__ != __ORDER_BIG_ENDIAN__
+#if (__BIG_ENDIAN__ == 1) && __BYTE_ORDER__ != __ORDER_BIG_ENDIAN__
#error __BIG_ENDIAN__ inconsistent with __BYTE_ORDER__
#endif
@@ -45,7 +45,7 @@ extern "C" {
#if \
- defined(__LITTLE_ENDIAN__) || \
+ (__LITTLE_ENDIAN__ == 1) || \
(defined(__BYTE_ORDER) && __BYTE_ORDER == __ORDER_LITTLE_ENDIAN) || \
defined(__ARMEL__) || defined(__THUMBEL__) || \
defined(__AARCH64EL__) || \
@@ -57,20 +57,20 @@ extern "C" {
defined(_M_IA64) || defined(_M_ALPHA) || \
defined(__amd64) || defined(__amd64__) || defined(_M_AMD64) || \
defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \
- defined(__bfin__)
+ defined(__bfin__) || defined(__LIT)
#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
#endif
#if \
- defined (__BIG_ENDIAN__) || \
+ (__BIG_ENDIAN__ == 1) || \
(defined(__BYTE_ORDER) && __BYTE_ORDER == __ORDER_BIG_ENDIAN) || \
defined(__ARMEB__) || defined(THUMBEB__) || defined (__AARCH64EB__) || \
defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__) || \
defined(__sparc) || defined(__sparc__) || \
defined(_POWER) || defined(__powerpc__) || defined(__ppc__) || \
- defined(__hpux) || defined(__hppa) || defined(__s390__)
+ defined(__hpux) || defined(__hppa) || defined(__s390__) || defined(__BIG)
#define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__
@@ -107,7 +107,7 @@ extern "C" {
#endif
#endif /* __BYTE_ORDER__ */
-#if defined(__LITTLE_ENDIAN__) && defined(__BIG_ENDIAN__)
+#if (__LITTLE_ENDIAN__ == 1) && (__BIG_ENDIAN__ == 1)
#error conflicting definitions of __LITTLE_ENDIAN__ and __BIG_ENDIAN__
#endif
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/portable/pstdalign.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/portable/pstdalign.h
index 207ecfc5..65e51a48 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/portable/pstdalign.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/portable/pstdalign.h
@@ -124,7 +124,9 @@ extern "C" {
#define _Alignas(t) __declspec (align(t))
#define _Alignof(t) __alignof(t)
-
+#elif defined(__CCRX__)
+#define alignas(t)
+#define alignof(t)
#else
#error please update pstdalign.h with support for current compiler and library
#endif
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/portable/pstdint.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/portable/pstdint.h
index 14444aa7..844662f0 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/portable/pstdint.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/include/flatcc/portable/pstdint.h
@@ -190,7 +190,9 @@
#include
#include
+#if !defined(__CCRX__)
#include
+#endif
/*
* For gcc with _STDINT_H, fill in the PRINTF_INT*_MODIFIER macros, and
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/src/runtime/builder.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/src/runtime/builder.c
index d77f1830..7ea58f19 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/src/runtime/builder.c
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/src/runtime/builder.c
@@ -18,7 +18,13 @@
#include "flatcc/flatcc_builder.h"
#include "flatcc/flatcc_emitter.h"
+#include "flatcc/flatcc_assert.h"
+#ifndef FLATCC_NO_ASSERT
+int __SET_ASSERT__ = 0;
+int __ASSERT_VAL__ = 0;
+const char *__ASSERT_REASON__ = "";
+#endif
/*
* `check` is designed to handle incorrect use errors that can be
* ignored in production of a tested product.
@@ -314,7 +320,7 @@ static inline void *reserve_buffer(flatcc_builder_t *B, int alloc_type, size_t u
if (used + need > buf->iov_len) {
if (B->alloc(B->alloc_context, buf, used + need, zero_init, alloc_type)) {
- check(0, "memory allocation failed");
+ check(__SET_ASSERT__, "memory allocation failed");
return 0;
}
}
@@ -664,11 +670,11 @@ static inline flatcc_builder_ref_t emit_front(flatcc_builder_t *B, iov_state_t *
(iov->len > 16 && iov->len - 16 > FLATBUFFERS_UOFFSET_MAX) ||
#endif
ref >= B->emit_start) {
- check(0, "buffer too large to represent");
+ check(__SET_ASSERT__, "buffer too large to represent");
return 0;
}
if (B->emit(B->emit_context, iov->iov, iov->count, ref, iov->len)) {
- check(0, "emitter rejected buffer content");
+ check(__SET_ASSERT__, "emitter rejected buffer content");
return 0;
}
return B->emit_start = ref;
@@ -690,11 +696,11 @@ static inline flatcc_builder_ref_t emit_back(flatcc_builder_t *B, iov_state_t *i
* separately.
*/
if (B->emit_end < ref) {
- check(0, "buffer too large to represent");
+ check(__SET_ASSERT__, "buffer too large to represent");
return 0;
}
if (B->emit(B->emit_context, iov->iov, iov->count, ref, iov->len)) {
- check(0, "emitter rejected buffer content");
+ check(__SET_ASSERT__, "emitter rejected buffer content");
return 0;
}
/*
@@ -719,7 +725,7 @@ static int align_to_block(flatcc_builder_t *B, uint16_t *align, uint16_t block_a
init_iov();
push_iov(_pad, end_pad);
if (0 == emit_back(B, &iov)) {
- check(0, "emitter rejected buffer content");
+ check(__SET_ASSERT__, "emitter rejected buffer content");
return -1;
}
}
@@ -789,7 +795,7 @@ flatcc_builder_ref_t flatcc_builder_create_buffer(flatcc_builder_t *B,
}
write_uoffset(&object_offset, (uoffset_t)object_ref - buffer_base);
if (0 == (buffer_ref = emit_front(B, &iov))) {
- check(0, "emitter rejected buffer content");
+ check(__SET_ASSERT__, "emitter rejected buffer content");
return 0;
}
return buffer_ref;
@@ -1482,7 +1488,7 @@ static flatcc_builder_ref_t _create_offset_vector_direct(flatcc_builder_t *B,
if (types) {
check(types[i] == 0, "union vector cannot have null element without type NONE");
} else {
- check(0, "offset vector cannot have null element");
+ check(__SET_ASSERT__, "offset vector cannot have null element");
}
}
}
@@ -1729,7 +1735,6 @@ flatcc_builder_ref_t flatcc_builder_create_string(flatcc_builder_t *B, const cha
uoffset_t s_pad;
uoffset_t length_prefix;
iov_state_t iov;
- //int size_exceeded = (uint64_t)len > (uint64_t)max_string_len;
#if max_string_len < UINT32_MAX
if (len > max_string_len) {
@@ -1812,7 +1817,7 @@ void *flatcc_builder_table_add(flatcc_builder_t *B, int id, size_t size, uint16_
}
#else
if (B->vs[id] != 0) {
- check(0, "table field already set");
+ check(__SET_ASSERT__, "table field already set");
return 0;
}
#endif
@@ -1847,7 +1852,7 @@ flatcc_builder_ref_t *flatcc_builder_table_add_offset(flatcc_builder_t *B, int i
}
#else
if (B->vs[id] != 0) {
- check(0, "table field already set");
+ check(__SET_ASSERT__, "table field already set");
return 0;
}
#endif
@@ -1972,11 +1977,11 @@ void *flatcc_builder_finalize_buffer(flatcc_builder_t *B, size_t *size_out)
buffer = FLATCC_BUILDER_ALLOC(size);
if (!buffer) {
- check(0, "failed to allocated memory for finalized buffer");
+ check(__SET_ASSERT__, "failed to allocated memory for finalized buffer");
goto done;
}
if (!flatcc_builder_copy_buffer(B, buffer, size)) {
- check(0, "default emitter declined to copy buffer");
+ check(__SET_ASSERT__, "default emitter declined to copy buffer");
FLATCC_BUILDER_FREE(buffer);
buffer = 0;
}
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/extensions/custom_emitter.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/src/runtime/emitter.c
similarity index 89%
rename from addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/extensions/custom_emitter.c
rename to addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/src/runtime/emitter.c
index e443dbff..fe89d234 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/extensions/custom_emitter.c
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/src/runtime/emitter.c
@@ -1,27 +1,13 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
-
-
-
-
+#include
-#include "page_allocator.h"
+#include
#ifdef ASC_SERIALIZER_USE_CUSTOM_ALLOCATOR
+#include "asc_security_core/serializer/page_allocator.h"
+
#define FLATCC_EMITTER_ALLOC serializer_page_alloc
#define FLATCC_EMITTER_FREE serializer_page_free
-#endif /* ASC_SERIALIZER_USE_CUSTOM_ALLOCATOR */
-
-/* flatcc/src/runtime/emitter.c */
-#include
+#endif
#include "flatcc/flatcc_rtconfig.h"
#include "flatcc/flatcc_emitter.h"
@@ -290,5 +276,3 @@ void *flatcc_emitter_copy_buffer(flatcc_emitter_t *E, void *buf, size_t size)
memcpy(buf, p->page, FLATCC_EMITTER_PAGE_SIZE - E->back_left);
return buf;
}
-
-
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/src/runtime/refmap.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/src/runtime/refmap.c
index a2497f02..e346dad5 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/src/runtime/refmap.c
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/deps/flatcc/src/runtime/refmap.c
@@ -102,7 +102,7 @@ int flatcc_refmap_resize(flatcc_refmap_t *refmap, size_t count)
refmap->table = _flatcc_refmap_calloc(buckets, sizeof(refmap->table[0]));
if (refmap->table == 0) {
refmap->table = T_old;
- FLATCC_ASSERT(0); /* out of memory */
+ FLATCC_ASSERT(__SET_ASSERT__); /* out of memory */
return -1;
}
}
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/asc_result.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/asc_result.h
index 9835be01..fb290e0c 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/asc_result.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/asc_result.h
@@ -1,16 +1,17 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef ASC_RESULT_H
#define ASC_RESULT_H
+#include
typedef enum {
ASC_RESULT_OK = 0,
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collector.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collector.h
index f9f53863..4ac97c76 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collector.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collector.h
@@ -1,13 +1,13 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef COLLECTOR_H
#define COLLECTOR_H
@@ -15,18 +15,15 @@
#include
#include
-#include "asc_security_core/utils/itime.h"
+#include
+
#include "asc_security_core/asc_result.h"
-#include "asc_security_core/collector_enums.h"
+#include "asc_security_core/component_info.h"
+
#include "asc_security_core/object_pool.h"
#include "asc_security_core/serializer.h"
-#include "asc_security_core/utils/collection/linked_list.h"
-#ifndef EXTRA_COLLECTORS_OBJECT_POOL_COUNT
-#define COLLECTOR_OBJECT_POOL_COUNT COLLECTOR_TYPE_COUNT
-#else
-#define COLLECTOR_OBJECT_POOL_COUNT (COLLECTOR_TYPE_COUNT + EXTRA_COLLECTORS_OBJECT_POOL_COUNT)
-#endif
+#define COLLECTOR_OBJECT_POOL_COUNT COLLECTORS_COUNT
typedef struct collector_internal_t collector_internal_t;
@@ -51,20 +48,19 @@ typedef asc_result_t (*collector_init_function_t)(collector_internal_t *collecto
*/
typedef asc_result_t (*collector_serialize_function_t)(collector_internal_t *collector_internal_ptr, serializer_t *serializer);
-/**
- * @brief Function which used in order to free a specific collector.
- *
- * @param collector_internal_ptr A handle to the collector internal to deinitialize.
- */
-typedef void (*collector_deinit_function_t)(collector_internal_t *collector_internal_ptr);
+typedef enum {
+ COLLECTOR_PRIORITY_HIGH = 0,
+ COLLECTOR_PRIORITY_MEDIUM = 1,
+ COLLECTOR_PRIORITY_LOW = 2,
+ COLLECTOR_PRIORITY_COUNT = 3
+} collector_priority_t;
struct collector_internal_t {
- collector_type_t type;
+ collector_enum_t type;
collector_priority_t priority;
+ unsigned long interval;
collector_serialize_function_t collect_function;
- collector_deinit_function_t deinit_function;
-
void *state;
};
@@ -80,10 +76,11 @@ typedef enum {
*
*/
typedef struct collector_t {
+ /* This macro must be first in object */
COLLECTION_INTERFACE(struct collector_t);
/*@{*/
- bool enabled; /**< Indicates if the collector is enabled. */
+ bool disabled; /**< Indicates if the collector is disabled. */
collector_status_t status;
unsigned int failure_count;
/*@}*/
@@ -92,34 +89,29 @@ typedef struct collector_t {
* @name Timestamps
*/
/*@{*/
- uint32_t last_collected_timestamp;
- uint32_t last_sent_timestamp;
+ unsigned long last_collected_timestamp;
+ unsigned long last_sent_timestamp;
/*@}*/
collector_internal_t internal;
} collector_t;
OBJECT_POOL_DECLARATIONS(collector_t)
-LINKED_LIST_DECLARATIONS(collector_t)
-
/**
- * @brief Initialize a Collector
+ * @brief Default allocate and initialize collector
*
- * @param init_function The initialization function of the collector internal
+ * @param id The component ID provided by component manager on init function
+ * @param type The collector type
+ * @param priority The collector priority
+ * @param event_queue_max_size The event queue max capacity
+ * @param collect_function The collect function of the collector
+ * @param interval The interval of sending security messages
+ * @param state The initial state value
*
- * @return collector ptr
+ * @return ASC_RESULT_OK on success, corresponding error code otherwise.
*/
-collector_t *collector_init(collector_init_function_t init_function);
-
-
-/**
- * @brief Deinitialize Collector
- *
- * @param collector_ptr collector ptr
- */
-void collector_deinit(collector_t *collector_ptr);
-
+asc_result_t collector_default_create(component_id_t id, collector_enum_t type, collector_priority_t priority, collector_serialize_function_t collect_function, unsigned long interval, void *state);
/**
* @brief Collector priority getter
@@ -130,7 +122,6 @@ void collector_deinit(collector_t *collector_ptr);
*/
collector_priority_t collector_get_priority(collector_t *collector_ptr);
-
/**
* @brief Collector last collected timestamp getter
*
@@ -138,8 +129,7 @@ collector_priority_t collector_get_priority(collector_t *collector_ptr);
*
* @return Collector last collected timestamp
*/
-uint32_t collector_get_last_collected_timestamp(collector_t *collector_ptr);
-
+unsigned long collector_get_last_collected_timestamp(collector_t *collector_ptr);
/**
* @brief Collector last collected timestamp setter
@@ -147,10 +137,9 @@ uint32_t collector_get_last_collected_timestamp(collector_t *collector_ptr);
* @param collector_ptr collector_t*
* @param last_collected_timestamp the timestamp
*
- * @return ASC_RESULT_OK on success, ASC_RESULT_EXCEPTION otherwise
+ * @return ASC_RESULT_OK on success, corresponding error code otherwise.
*/
-asc_result_t collector_set_last_collected_timestamp(collector_t *collector_ptr, uint32_t last_collected_timestamp);
-
+asc_result_t collector_set_last_collected_timestamp(collector_t *collector_ptr, unsigned long last_collected_timestamp);
/**
* @brief Serialize the events in the collector
@@ -164,5 +153,58 @@ asc_result_t collector_set_last_collected_timestamp(collector_t *collector_ptr,
*/
asc_result_t collector_serialize_events(collector_t *collector, serializer_t *serializer);
+/**
+ * @brief Default collector subscribe to core function
+ *
+ * @param id The component ID provided by component manager
+ *
+ * @return ASC_RESULT_OK on success, ASC_RESULT_MEMORY_EXCEPTION otherwise
+ */
+asc_result_t collector_default_subscribe(component_id_t id);
+
+/**
+ * @brief Default collector unsubscribe from core function
+ *
+ * @param id The component ID provided by component manager
+ *
+ * @return ASC_RESULT_OK on success, ASC_RESULT_MEMORY_EXCEPTION otherwise
+ */
+asc_result_t collector_default_unsubscribe(component_id_t id);
+
+/**
+ * @brief Default collector deinit function
+ *
+ * @param id The component ID provided by component manager
+ *
+ * @return ASC_RESULT_OK on success, ASC_RESULT_MEMORY_EXCEPTION otherwise
+ */
+asc_result_t collector_default_deinit(component_id_t id);
+
+/**
+ * @brief Default collector start function
+ *
+ * @param id The component ID provided by component manager
+ *
+ * @return ASC_RESULT_OK
+ */
+asc_result_t collector_default_start(component_id_t id);
+/**
+ * @brief Default collector stop function
+ *
+ * @param id The component ID provided by component manager
+ *
+ * @return ASC_RESULT_OK
+ */
+asc_result_t collector_default_stop(component_id_t id);
+
+#define COLLECTOR_OPS_DEFINITIONS(__ops, __init, __deinit, __subscribe, __unsubscribe, __start, __stop) \
+static component_ops_t _ops##__ops = { \
+ .init = __init, \
+ .deinit = __deinit, \
+ .subscribe = __subscribe, \
+ .unsubscribe = __unsubscribe, \
+ .start = __start, \
+ .stop = __stop, \
+}
#endif /* COLLECTOR_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collector_collection.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collector_collection.h
index f60ca828..a2683b4f 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collector_collection.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collector_collection.h
@@ -1,21 +1,24 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef IOTSECURITY_COLLECTOR_COLLECTION_H
#define IOTSECURITY_COLLECTOR_COLLECTION_H
#include
+
+#include
+
#include "asc_security_core/asc_result.h"
#include "asc_security_core/collector.h"
-#include "asc_security_core/utils/collection/linked_list.h"
+#include "asc_security_core/utils/collection/list.h"
typedef struct priority_collectors priority_collectors_t;
typedef struct collector_collection collector_collection_t;
@@ -26,7 +29,7 @@ typedef struct collector_collection collector_collection_t;
*
* @return A @c collector_collection_t* representing the newly created collector collection.
*/
-collector_collection_t *collector_collection_init();
+collector_collection_t *collector_collection_init(void);
/**
@@ -36,6 +39,24 @@ collector_collection_t *collector_collection_init();
*/
void collector_collection_deinit(collector_collection_t *collector_collection_ptr);
+/**
+ * @brief Register collector to collector_collection
+ *
+ * @param collector_collection_ptr the collector colleciton
+ * @param collector_ptr a @c collector_t* collector handle
+ * @param random_collect_offset a random start collection offset
+ *
+ * @return ASC_RESULT_OK on success, corresponding error code otherwise.
+ */
+asc_result_t collector_collection_register(collector_collection_t *collector_collection_ptr, collector_t *collector_ptr, unsigned long collect_offset);
+
+/**
+ * @brief Unregister collector from collector_collection
+ *
+ * @param collector_collection_ptr the collector colleciton
+ * @param collector_ptr a @c collector_t* collector handle
+ */
+void collector_collection_unregister(collector_collection_t *collector_collection_ptr, collector_t *collector_ptr);
/**
* @brief Return CollectorCollection specific priority collection
@@ -76,7 +97,7 @@ priority_collectors_t *collector_collection_get_next_priority(collector_collecti
*
* @return A @c collector_t* collector handle with the same type
*/
-collector_t *collector_collection_get_collector_by_priority(collector_collection_t *collector_collection_ptr, collector_type_t type);
+collector_t *collector_collection_get_collector_by_priority(collector_collection_t *collector_collection_ptr, collector_enum_t type);
/**
@@ -85,38 +106,16 @@ collector_t *collector_collection_get_collector_by_priority(collector_collection
* @param action_function a predicate to call to for each collector
* @param context caller context
*/
-void collector_collection_foreach(collector_collection_t *collector_collection_ptr, linked_list_collector_t_action action_function, void *context);
-
-
-/**
- * @brief returns the interval in seconds of the priority collection
- *
- * @param priority_collectors_ptr the priority collection
- *
- * @return A @c uint32_t which stands for the interval in seconds of the priority collection
- */
-uint32_t priority_collectors_get_interval(priority_collectors_t *priority_collectors_ptr);
-
-
-/**
- * @brief priority collectors interval setter
- *
- * @param priority_collectors_ptr priority collectors ptr
- * @param interval interval in seconds
- *
- * @return asc_result_t
- */
-asc_result_t priority_collectors_set_interval(priority_collectors_t *priority_collectors_ptr, uint32_t interval);
-
+void collector_collection_foreach(collector_collection_t *collector_collection_ptr, void(*action_function)(collector_t *collector, void *context), void *context);
/**
* @brief returns the list of collectors of the priority collection
*
* @param priority_collectors_ptr the priority collection
*
- * @return A @c linked_list_collector_t which stands for the list of collectors of the priority collection
+ * @return A @c linked_list_t which stands for the list of collectors of the priority collection
*/
-linked_list_collector_t_handle priority_collectors_get_list(priority_collectors_t *priority_collectors_ptr);
+linked_list_t *priority_collectors_get_list(priority_collectors_t *priority_collectors_ptr);
/**
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collector_collection_factory.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collector_collection_factory.h
deleted file mode 100644
index c476fb24..00000000
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collector_collection_factory.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
-
-#ifndef IOTSECURITY_COLLECTOR_COLLECTION_FACTORY_H
-#define IOTSECURITY_COLLECTOR_COLLECTION_FACTORY_H
-
-
-#include
-#include "asc_security_core/collector_collection.h"
-#include "asc_security_core/asc_result.h"
-
-/**
- * @brief Initialize an collector_init_function_t array with init functions of enabled collectors
- *
- * @param init_array out param -given array to populate
- * @param init_array_size array size
- *
- * @return An @c asc_result_t indicating the status of the call.
- */
-asc_result_t collector_collection_factory_get_initialization_array(collector_init_function_t **init_array, uint32_t *init_array_size);
-
-#endif /* IOTSECURITY_COLLECTOR_COLLECTION_FACTORY_H */
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collector_collection_internal.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collector_collection_internal.h
deleted file mode 100644
index 7d38a301..00000000
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collector_collection_internal.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
-
-#ifndef IOTSECURITY_COLLECTOR_COLLECTION_INTERNAL_H
-#define IOTSECURITY_COLLECTOR_COLLECTION_INTERNAL_H
-
-#include
-#include "asc_security_core/collector_collection.h"
-#include "asc_security_core/asc_result.h"
-
-/**
- * @brief Initialize startup time for each collector in the collection
- *
- * @param collector_collection collector collection
- *
- * @return An @c asc_result_t indicating the status of the call.
- */
-asc_result_t collector_collection_internal_init_startup_time(collector_collection_t *collector_collection_ptr);
-
-#endif /* IOTSECURITY_COLLECTOR_COLLECTION_INTERNAL_H */
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collector_enums.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collector_enums.h
deleted file mode 100644
index ed6fe513..00000000
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collector_enums.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
-
-#ifndef _COLLECTOR_ENUMS_H_
-#define _COLLECTOR_ENUMS_H_
-
-#include
-
-#include "asc_security_core/configuration.h"
-
-#define COLLECTOR_NAME_SYSTEM_INFORMATION "SystemInformation"
-#define COLLECTOR_NAME_NETWORK_ACTIVITY "NetworkActivity"
-#define COLLECTOR_NAME_LISTENING_PORTS "ListeningPorts"
-#define COLLECTOR_NAME_HEARTBEAT "Heartbeat"
-#define COLLECTOR_NAME_BASELINE "Baseline"
-
-typedef enum {
-#ifdef COLLECTOR_SYSTEM_INFORMATION_ENABLED
- COLLECTOR_TYPE_SYSTEM_INFORMATION,
-#endif
-#ifdef COLLECTOR_NETWORK_ACTIVITY_ENABLED
- COLLECTOR_TYPE_NETWORK_ACTIVITY,
-#endif
-#ifdef COLLECTOR_LISTENING_PORTS_ENABLED
- COLLECTOR_TYPE_LISTENING_PORTS,
-#endif
-#ifdef COLLECTOR_HEARTBEAT_ENABLED
- COLLECTOR_TYPE_HEARTBEAT,
-#endif
-#ifdef COLLECTOR_BASELINE_ENABLED
- COLLECTOR_TYPE_BASELINE,
-#endif
- COLLECTOR_TYPE_COUNT
-} collector_type_t;
-
-extern const char *g_collector_names[COLLECTOR_TYPE_COUNT];
-
-typedef enum {
- COLLECTOR_PRIORITY_HIGH = 0,
- COLLECTOR_PRIORITY_MEDIUM = 1,
- COLLECTOR_PRIORITY_LOW = 2,
- COLLECTOR_PRIORITY_COUNT = 3
-} collector_priority_t;
-
-extern const uint32_t g_collector_collections_intervals[COLLECTOR_PRIORITY_COUNT];
-
-#endif /* _COLLECTOR_ENUMS_H_ */
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collectors/heartbeat.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collectors/heartbeat.h
deleted file mode 100644
index a5a9e076..00000000
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collectors/heartbeat.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
-
-#ifndef _HEARTBEAT_INFORMATION_H
-#define _HEARTBEAT_INFORMATION_H
-
-#include "asc_security_core/collector.h"
-
-/**
- * @brief Initialize Heartbeat Collector
- *
- * @param collector_internal_ptr A handle to the collector internal to initialize.
- *
- * @return ASC_RESULT_OK on success
- */
-asc_result_t collector_heartbeat_init(collector_internal_t *collector_internal_ptr);
-
-#endif /* _HEARTBEAT_INFORMATION_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collectors/network_activity.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collectors/network_activity.h
deleted file mode 100644
index 8be732be..00000000
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collectors/network_activity.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
-
-#ifndef _COLLECTOR_NETWORK_ACTIVITY_H
-#define _COLLECTOR_NETWORK_ACTIVITY_H
-
-#include "asc_security_core/collector.h"
-
-/**
- * @brief Initialize NetworkActivity Collector
- *
- * @param collector_internal_ptr A handle to the collector internal to initialize.
- *
- * @return ASC_RESULT_OK on success
- */
-asc_result_t collector_network_activity_init(collector_internal_t *collector_internal_ptr);
-
-#endif /* _COLLECTOR_NETWORK_ACTIVITY_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collectors/system_information.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collectors/system_information.h
deleted file mode 100644
index 6eb0f888..00000000
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collectors/system_information.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
-
-#ifndef _COLLECTOR_SYSTEM_INFORMATION_H
-#define _COLLECTOR_SYSTEM_INFORMATION_H
-
-#include "asc_security_core/collector.h"
-
-/**
- * @brief Initialize SystemInformation Collector
- *
- * @param collector_internal_ptr A handle to the collector internal to initialize.
- *
- * @return ASC_RESULT_OK on success
- */
-asc_result_t collector_system_information_init(collector_internal_t *collector_internal_ptr);
-
-#endif /* _COLLECTOR_SYSTEM_INFORMATION_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collectors_headers.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collectors_headers.h
deleted file mode 100644
index 5906076d..00000000
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collectors_headers.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
-
-#ifndef _COLLECTORS_HEADERS_H
-#define _COLLECTORS_HEADERS_H
-
-#include "asc_security_core/configuration.h"
-
-#ifdef COLLECTOR_SYSTEM_INFORMATION_ENABLED
-#include "asc_security_core/collectors/system_information.h"
-#endif
-
-#ifdef COLLECTOR_LISTENING_PORTS_ENABLED
-#include "asc_security_core/collectors/listening_ports.h"
-#endif
-
-#ifdef COLLECTOR_NETWORK_ACTIVITY_ENABLED
-#include "asc_security_core/collectors/network_activity.h"
-#endif
-
-#ifdef COLLECTOR_HEARTBEAT_ENABLED
-#include "asc_security_core/collectors/heartbeat.h"
-#endif
-
-#ifdef COLLECTOR_BASELINE_ENABLED
-#include "asc_security_core/collectors/baseline.h"
-#endif
-
-#endif /* _COLLECTORS_HEADERS_H */
-
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collectors_info.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collectors_info.h
index e84d4ba6..f1e400ce 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collectors_info.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/collectors_info.h
@@ -1,26 +1,25 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef _COLLECTORS_INFO_H_
#define _COLLECTORS_INFO_H_
#include
-#ifndef EXTRA_COLLECTORS_OBJECT_POOL_COUNT
-#define COLLECTORS_INFO_SIZE COLLECTOR_TYPE_COUNT
-#else
-#define COLLECTORS_INFO_SIZE (COLLECTOR_TYPE_COUNT + EXTRA_COLLECTORS_OBJECT_POOL_COUNT)
-#endif
+#include
+
+#define COLLECTORS_INFO_SIZE COLLECTORS_COUNT
+
typedef struct {
- uint32_t interval;
+ unsigned long interval;
} collector_info_t;
typedef intptr_t collectors_info_t;
@@ -29,7 +28,7 @@ typedef intptr_t collectors_info_t;
*
* @return Collectors info data struct handler
*/
-collectors_info_t *collectors_info_init();
+collectors_info_t *collectors_info_init(void);
/**
* @brief Deinitialize collectors info module
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/component_id.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/component_id.h
new file mode 100644
index 00000000..cc123560
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/component_id.h
@@ -0,0 +1,50 @@
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
+
+#ifndef __COMPONENT_ID_H__
+#define __COMPONENT_ID_H__
+#include
+
+#include "asc_security_core/components_factory_type.h"
+
+static component_id_t __auto_generated_self_id = 0;
+
+/**
+ * @brief Get self ID of specific component.
+ * Can be called after COMPONENTS_FACTORY_DEFINITION() only.
+ *
+ * @return A @c component_id_t component ID.
+ */
+static inline component_id_t components_manager_get_self_id()
+{
+ return __auto_generated_self_id;
+}
+
+/**
+ * @brief Set self ID of specific component.
+ * Can be called instead COMPONENTS_FACTORY_DEFINITION().
+ *
+ * @param component Component enumerator
+ *
+ */
+static inline void components_manager_set_self_id(int component)
+{
+ __auto_generated_self_id = g_component_factory[component].component.info.id;
+}
+
+/**
+ * @brief Reset static self ID in specific file.
+ */
+static inline void components_manager_reset_self_id()
+{
+ __auto_generated_self_id = 0;
+}
+#endif
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/component_info.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/component_info.h
new file mode 100644
index 00000000..1218e9c2
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/component_info.h
@@ -0,0 +1,123 @@
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
+
+#ifndef __COMPONENT_INFO_H__
+#define __COMPONENT_INFO_H__
+
+#include
+
+#include
+
+#include "asc_security_core/asc_result.h"
+
+#include "asc_security_core/components_factory_enum.h"
+#include "asc_security_core/utils/collection/bit_vector.h"
+
+BIT_VECTOR_DECLARATIONS(component_owners_t, COMPONENTS_COUNT)
+
+/**
+ * @brief Type definition of component ID.
+ */
+typedef uintptr_t component_id_t;
+
+/**
+ * @brief Type definition of life cycle management functions: init(), deinit(), start(), stop().
+ */
+typedef asc_result_t (*lcm_func_t)(component_id_t id);
+
+/**
+ * @brief State enumerator of built-in component.
+ */
+typedef enum {
+ COMPONENT_UNLOADED = 0,
+ COMPONENT_LOADED,
+ COMPONENT_FAIL,
+ COMPONENT_INITIALIZED,
+ COMPONENT_RUNNING,
+ COMPONENT_STOPED,
+ COMPONENT_SUBSCRIBED,
+ COMPONENT_UNSUBSCRIBED,
+ COMPONENT_UNDEFINED
+} component_state_enum_t;
+
+/**
+ * @brief Struct of component internal info.
+ */
+typedef struct {
+/* The current component's state from component_state_enum_t */
+ component_state_enum_t state;
+
+/* The last component's result (like erno but for each component) */
+ asc_result_t last_result;
+
+/* The component's ID */
+ component_id_t id;
+
+/* The component's name */
+ const char *name;
+
+/* The component's enumerator */
+ int enumerator;
+
+/* The component's internal context */
+ void *ctx;
+
+/* The component's external context */
+ uintptr_t ext_ctx;
+
+/* Disable auto start configuration */
+ bool auto_start_disable;
+
+/* The bit vector of component's owners - who started and stopped it */
+ bit_vector_component_owners_t owners;
+
+/* The log level */
+ unsigned int log_level;
+
+} component_info_t;
+
+/**
+ * @brief Struct of component's operations.
+ */
+typedef struct {
+/* The 'init()' function is for internal allocations and subscriptions. Don't use here API from another components,
+ * don't set timers, don't send notifications etc.
+ */
+ lcm_func_t init;
+
+/* The 'subscribe()' is place to registrate and subscribe to APIs from another components. */
+ lcm_func_t subscribe;
+
+/* The 'start()' is place to set timers, send notifications and start the component's logic. */
+ lcm_func_t start;
+
+/* The 'deinit()' function is for free internal memory. Don't use here API from another components,
+ * don't set/delete timers, don't send notifications etc.
+ */
+ lcm_func_t deinit;
+
+/* The 'unsubscribe()' is place to unregistrate and unsubscribe from APIs from another components. */
+ lcm_func_t unsubscribe;
+
+/* The 'stop()' is place to delete timers, send notifications and finalize all running sequence of component. */
+ lcm_func_t stop;
+
+} component_ops_t;
+
+/**
+ * @brief Struct of component's.
+ */
+typedef struct {
+ component_info_t info;
+ component_ops_t *ops;
+} component_t;
+
+#endif
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/components_factory.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/components_factory.h
new file mode 100644
index 00000000..a9757951
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/components_factory.h
@@ -0,0 +1,46 @@
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
+
+#ifndef __COMPONENTS_FACTORY_H__
+#define __COMPONENTS_FACTORY_H__
+
+#include
+#include
+
+#include
+
+#include "asc_security_core/logger.h"
+#include "asc_security_core/utils/string_utils.h"
+#include "asc_security_core/components_factory_type.h"
+#include "asc_security_core/component_id.h"
+
+/**
+ * @brief Macros for generating load and get_id functions for built-in components.
+ *
+ * @param _component Component generated name from @c component_enum_t and @c collector_enum_t
+ */
+/* Add this declaration in inc/asc_security_core/components_factory_enum.h. */
+#define COMPONENTS_FACTORY_DECLARATION(_component) \
+extern component_load_function_t components_factory_##_component##_load_ptr;
+
+#define COMPONENTS_FACTORY_DEFINITION(_component, _ops) \
+asc_result_t components_factory_##_component##_load(void);\
+asc_result_t components_factory_##_component##_load(void) { \
+ asc_result_t result = components_factory_set(#_component, _component, _ops, false); \
+ __auto_generated_self_id = g_component_factory[_component].component.info.id; \
+ return result; \
+} \
+component_load_function_t components_factory_##_component##_load_ptr = components_factory_##_component##_load;
+
+/* Add this macro in src/components_factory.c */
+#define COMPONENTS_FACTORY_LOAD(_component) &components_factory_##_component##_load_ptr
+
+#endif // __COMPONENTS_FACTORY_H__
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/components_factory_declarations.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/components_factory_declarations.h
new file mode 100644
index 00000000..e7abe905
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/components_factory_declarations.h
@@ -0,0 +1,64 @@
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
+
+#ifndef __COMPONENTS_FACTORY_DECLARATIONS_H__
+#define __COMPONENTS_FACTORY_DECLARATIONS_H__
+#include
+
+#include "asc_security_core/components_factory.h"
+
+COMPONENTS_FACTORY_DECLARATION(ManagerCore)
+#ifdef ASC_COMPONENT_SECURITY_MODULE
+ COMPONENTS_FACTORY_DECLARATION(SecurityModule)
+#endif
+COMPONENTS_FACTORY_DECLARATION(CollectorsCore)
+COMPONENTS_FACTORY_DECLARATION(Logger)
+#ifdef ASC_COMPONENT_CONFIGURATION
+ COMPONENTS_FACTORY_DECLARATION(Configuration)
+#endif
+#ifdef ASC_COMPONENT_CONFIGURATION_PLAT
+ COMPONENTS_FACTORY_DECLARATION(ConfigurationPlatform)
+#endif
+#ifdef ASC_COMPONENT_COMMAND_EXECUTOR_PLAT
+ COMPONENTS_FACTORY_DECLARATION(CommandExecutorPlatform)
+#endif
+#ifdef ASC_COLLECTOR_HEARTBEAT_ENABLED
+ COMPONENTS_FACTORY_DECLARATION(Heartbeat)
+#endif
+#ifdef ASC_COLLECTOR_BASELINE_ENABLED
+ COMPONENTS_FACTORY_DECLARATION(Baseline)
+#endif
+#ifdef ASC_COMPONENT_BASELINE_PLAT
+ COMPONENTS_FACTORY_DECLARATION(BaselinePlatform)
+#endif
+#ifdef ASC_COMPONENT_IPC_PLAT
+ COMPONENTS_FACTORY_DECLARATION(IpcPlatform)
+#endif
+#ifdef ASC_COMPONENT_CLI_PLAT
+ #ifdef ASC_COMPONENT_DEMO_CLI_PLAT
+ COMPONENTS_FACTORY_DECLARATION(CliDemoPlatform)
+ #endif
+ COMPONENTS_FACTORY_DECLARATION(CliPlatform)
+#endif
+#ifdef ASC_COLLECTOR_SYSTEM_INFORMATION_ENABLED
+ COMPONENTS_FACTORY_DECLARATION(SystemInformation)
+#endif
+#ifdef ASC_COLLECTOR_NETWORK_ACTIVITY_ENABLED
+ COMPONENTS_FACTORY_DECLARATION(NetworkActivity)
+#endif
+#ifdef ASC_COLLECTOR_LISTENING_PORTS_ENABLED
+ COMPONENTS_FACTORY_DECLARATION(ListeningPorts)
+#endif
+#ifdef ASC_COLLECTOR_PROCESS_ENABLED
+ COMPONENTS_FACTORY_DECLARATION(Process)
+#endif
+
+#endif // __COMPONENTS_FACTORY_DECLARATIONS_H__
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/components_factory_enum.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/components_factory_enum.h
new file mode 100644
index 00000000..04976b26
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/components_factory_enum.h
@@ -0,0 +1,125 @@
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
+
+#ifndef __COMPONENTS_FACTORY_ENUM_H__
+#define __COMPONENTS_FACTORY_ENUM_H__
+#include
+
+typedef enum {
+#ifdef ASC_COLLECTOR_SYSTEM_INFORMATION_ENABLED
+ SystemInformation,
+#endif
+#ifdef ASC_COLLECTOR_NETWORK_ACTIVITY_ENABLED
+ NetworkActivity,
+#endif
+#ifdef ASC_COLLECTOR_LISTENING_PORTS_ENABLED
+ ListeningPorts,
+#endif
+#ifdef ASC_COLLECTOR_HEARTBEAT_ENABLED
+ Heartbeat,
+#endif
+#ifdef ASC_COLLECTOR_BASELINE_ENABLED
+ Baseline,
+#endif
+#ifdef ASC_COLLECTOR_PROCESS_ENABLED
+ Process,
+#endif
+ __COLLECTOR_COUNT // Must be last
+} collector_enum_t;
+
+#define COLLECTORS_COUNT (__COLLECTOR_COUNT + ASC_EXTRA_COLLECTORS_COUNT + ASC_DYNAMIC_COLLECTORS_MAX)
+
+/**
+ * @brief Factory enumerator of all built-in component.
+ * Components factory has following struct:
+ * FACTORY_ARRAY[__COLLECTOR_COUNT, ASC_EXTRA_COLLECTORS_COUNT, ASC_DYNAMIC_COLLECTORS_MAX, __COMPONENT_COUNT, ASC_EXTRA_COMPONENTS_COUNT, ASC_DYNAMIC_COMPONENTS_MAX]
+ * COLLECTORS_COUNT
+ * |________________________________________________________________________|
+ * COMPONENTS_COUNT
+ * |___________________________________________________________________________________________________________________________________________________|
+ */
+/**
+ * @brief Factory enumerator of collectors. This enumerator comes first in component enum.
+ *
+ * :
+ * : 0
+ * CollectorN1
+ * CollectorNx
+ * : __COLLECTOR_COUNT
+ * :
+ * : __COLLECTOR_COUNT
+ * CollectorExtraN1
+ * CollectorExtraNx
+ * : __COLLECTOR_COUNT + ASC_EXTRA_COLLECTORS_COUNT
+ * :
+ * : __COLLECTOR_COUNT + ASC_DYNAMIC_COLLECTORS_MAX
+ * CollectorDynamicN1
+ * CollectorDynamicNx
+ * : COLLECTORS_COUNT = __COLLECTOR_COUNT + ASC_DYNAMIC_COLLECTORS_MAX + ASC_DYNAMIC_COLLECTORS_MAX
+ * :
+ * : COLLECTORS_COUNT
+ * ComponentN1
+ * ComponentNx
+ * : __COMPONENT_COUNT
+ * :
+ * : __COMPONENT_COUNT
+ * ComponentExtraN1
+ * ComponentExtraNx
+ * :
+ * : __COMPONENT_COUNT + ASC_EXTRA_COMPONENTS_COUNT
+ * ComponentDynamicN1
+ * ComponentDynamicNx
+ * : COMPONENTS_COUNT = __COMPONENT_COUNT + ASC_EXTRA_COMPONENTS_COUNT + ASC_DYNAMIC_COMPONENTS_MAX
+ *
+ * Each component should be defined in 5 places:
+ * in @c component_enum_t or @c collector_enum_t enum: ComponentName or CollectorName
+ * The enum must contain the following characters only: [a-zA-Z0-9]*
+ * in inc/asc_security_core/components_factory_declarations.h: @c COMPONENTS_FACTORY_DECLARATION(ComponentName)
+ * in src/component_factory.c:component_load_function_array[]: @c COMPONENTS_FACTORY_LOAD(ComponentName);
+ * in component's code: @c COMPONENTS_FACTORY_DEFINITION(ComponentName, &ops)
+ * in compilation enviroments: @c -DComponentName
+ *
+ * @param _component Component generated name from @c component_enum_t
+ */
+typedef enum {
+ ManagerCore = COLLECTORS_COUNT, //first and always exists
+#ifdef ASC_COMPONENT_SECURITY_MODULE
+ SecurityModule,
+#endif
+ CollectorsCore,
+#ifdef ASC_COMPONENT_CONFIGURATION
+ Configuration,
+#endif
+#ifdef ASC_COMPONENT_CONFIGURATION_PLAT
+ ConfigurationPlatform,
+#endif
+#ifdef ASC_COMPONENT_COMMAND_EXECUTOR_PLAT
+ CommandExecutorPlatform,
+#endif
+#ifdef ASC_COMPONENT_BASELINE_PLAT
+ BaselinePlatform,
+#endif
+#ifdef ASC_COMPONENT_IPC_PLAT
+ IpcPlatform,
+#endif
+#ifdef ASC_COMPONENT_CLI_PLAT
+ CliPlatform,
+ #ifdef ASC_COMPONENT_DEMO_CLI_PLAT
+ CliDemoPlatform,
+ #endif
+#endif
+ Logger,
+ __COMPONENT_COUNT // Must be last
+} component_enum_t;
+
+#define COMPONENTS_COUNT (__COMPONENT_COUNT + ASC_EXTRA_COMPONENTS_COUNT + ASC_DYNAMIC_COMPONENTS_MAX)
+
+#endif // __COMPONENTS_FACTORY_ENUM_H__
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/components_factory_type.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/components_factory_type.h
new file mode 100644
index 00000000..3328cdc2
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/components_factory_type.h
@@ -0,0 +1,140 @@
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
+
+#ifndef __COMPONENTS_FACTORY__TYPE_H__
+#define __COMPONENTS_FACTORY__TYPE_H__
+
+#include
+
+#include
+
+#include "asc_security_core/asc_result.h"
+#include "asc_security_core/component_info.h"
+
+/**
+ * @brief Factory load the component function prototype.
+ */
+typedef asc_result_t (*component_load_function_t)(void);
+
+/**
+ * @brief Struct of factory entry.
+ */
+typedef struct {
+ component_t component;
+} components_factory_t;
+
+/**
+ * @brief Factory global array.
+ */
+extern components_factory_t g_component_factory[];
+
+/**
+ * @brief Get array of component load functions.
+ *
+ * @return An @c component_load_function_t array of component load functions.
+ */
+component_load_function_t **components_factory_get_load_array(void);
+
+/**
+ * @brief Factory unload - clean built-in components data from @c g_component_factory .
+ *
+ * @return none.
+ */
+void components_factory_unload(void);
+
+/**
+ * @brief Factory unload - clean built-in component with specified index from @c g_component_factory .
+ *
+ * @param index A component's index.
+ *
+ * @return none.
+ */
+void component_factory_unload(int index);
+
+/**
+ * @brief Generate ID for component with specified index.
+ *
+ * @param index A component's index.
+ *
+ * @return A component's ID.
+ */
+component_id_t components_factory_create_id(int index);
+
+/**
+ * @brief Insert component with specified index to @c g_component_factory .
+ *
+ * @param name A component's name.
+ * @param index A component's index.
+ * @param ops A component's LCM ops.
+ * @param auto_disable Is componet auto disable to run.
+ *
+ * @return ASC_RESULT_OK on success, corresponding error code otherwise.
+ */
+asc_result_t components_factory_set(const char *name, int index, component_ops_t *ops, bool auto_disable);
+
+/**
+ * @brief Dynamic loading API .
+ */
+#ifdef ASC_DYNAMIC_FACTORY_ENABLED
+/**
+ * @brief Insert dynamic loaded collector with specified index to @c g_component_factory .
+ *
+ * @param name A collector's name.
+ * @param index A collector's index.
+ * @param ops A collector's LCM ops.
+ * @param auto_disable Is collector auto disable to run.
+ *
+ * @return ASC_RESULT_OK on success, corresponding error code otherwise.
+ */
+asc_result_t components_factory_set_dynamic_collector(const char *name, int index, component_ops_t *ops, bool auto_disable);
+
+/**
+ * @brief Insert dynamic loaded component with specified index to @c g_component_factory .
+ *
+ * @param name A component's name.
+ * @param index A component's index.
+ * @param ops A component's LCM ops.
+ * @param auto_disable Is componet auto disable to run.
+ *
+ * @return ASC_RESULT_OK on success, corresponding error code otherwise.
+ */
+asc_result_t components_factory_set_dynamic_component(const char *name, int index, component_ops_t *ops, bool auto_disable);
+
+/**
+ * @brief Dynamic loading of all existing collectors and componets to @c g_component_factory .
+ *
+ * @param __path A directory of dynamic stuff - if NULL taken from components_factory_dynamic_path_set() and ASC_DYNAMIC_FACTORY_PATH.
+ *
+ * @return ASC_RESULT_OK on success, corresponding error code otherwise.
+ */
+asc_result_t components_factory_load_dynamic(const char *__path);
+
+/**
+ * @brief Unload all dynamic loaded entries from @c g_component_factory .
+ *
+ * @return none.
+ */
+void components_factory_unload_dynamic(void);
+
+
+#ifdef ASC_DYNAMIC_FACTORY_PATH_RUNTIME_SET
+/**
+ * @brief Overwrite default path to dynamic stuff.
+ *
+ * @param __path A directory of dynamic stuff.
+ *
+ * @return none.
+ */
+void components_factory_dynamic_path_set(const char *__path);
+#endif
+#endif // ASC_DYNAMIC_FACTORY_ENABLED
+
+#endif // __COMPONENTS_FACTORY__TYPE_H__
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/components_manager.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/components_manager.h
new file mode 100644
index 00000000..ad903928
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/components_manager.h
@@ -0,0 +1,176 @@
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
+
+#ifndef __COMPONENTS_MANAGER_H__
+#define __COMPONENTS_MANAGER_H__
+#include
+
+#include "asc_security_core/asc_result.h"
+#include "asc_security_core/components_factory.h"
+
+/**
+ * @brief Call init and start function of all declarated built-in components.
+ *
+ * @return A @c asc_result_t result.
+ */
+asc_result_t components_manager_init(void);
+
+/**
+ * @brief Set global context.
+ *
+ * @param ctx Global Context
+ *
+ * @return none.
+ */
+void components_manager_global_context_set(uintptr_t ctx);
+
+/**
+ * @brief Get global context.
+ *
+ * @return The global context.
+ */
+uintptr_t components_manager_global_context_get(void);
+
+/**
+ * @brief Call stop and deinit function of all declarated built-in components.
+ *
+ * @return A @c asc_result_t result.
+ */
+asc_result_t components_manager_deinit(void);
+
+/**
+ * @brief Get internal component struct by it's ID.
+ *
+ * @param id Component ID provided by component manager on init function
+ *
+ * @return A @c component_t* representing component.
+ */
+component_t *components_manager_get_component(component_id_t id);
+
+/**
+ * @brief Get internal info of specific component by it's ID.
+ *
+ * @param id Component ID provided by component manager on init function
+ *
+ * @return A @c component_info_t* representing internal component info.
+ */
+component_info_t *components_manager_get_info(component_id_t id);
+
+/**
+ * @brief Get user component context by it's ID. Avoid using __components_manager_get_ctx() - use private components_manager_get_self_ctx() macro
+ *
+ * @param id Component ID provided by component manager on init function
+ *
+ * @return A @c void* user context.
+ */
+void *__components_manager_get_ctx(component_id_t id);
+#define components_manager_get_self_ctx() __components_manager_get_ctx(components_manager_get_self_id())
+
+/**
+ * @brief Set user component context by it's ID. Avoid using __components_manager_set_ctx() - use private components_manager_set_self_ctx() macro
+ *
+ * @param id Component ID provided by component manager on init function
+ *
+ * @param ctx User context to store
+ *
+ * @return none.
+ */
+void __components_manager_set_ctx(component_id_t id, void *ctx);
+#define components_manager_set_self_ctx(_ctx) __components_manager_set_ctx(components_manager_get_self_id(), _ctx)
+
+/**
+ * @brief Get last result of component.
+ *
+ * @param id Component ID provided by component manager on init function
+ *
+ * @return A @c asc_result_t result.
+ */
+asc_result_t components_manager_get_last_result(component_id_t id);
+
+/**
+ * @brief Get name of component.
+ *
+ * @param id Component ID provided by component manager on init function
+ *
+ * @return A component name.
+ */
+const char *components_manager_get_name(component_id_t id);
+
+/**
+ * @brief Set log level to specified component.
+ *
+ * @param id Component ID provided by component manager on init function
+ * @param set Requested log level, if (-1) - reset to default 'ASC_LOG_LEVEL'
+ *
+ * @return true on seccess, otherwise false..
+ */
+bool components_manager_set_log_level(component_id_t id, int set);
+
+/**
+ * @brief Get log level to specified component.
+ *
+ * @param id Component ID provided by component manager on init function
+ *
+ * @return log level.
+ */
+unsigned int components_manager_get_log_level(component_id_t id);
+
+/**
+ * @brief Set log level to all components.
+ *
+ * @param set Requested log level, if (-1) - reset to default 'ASC_LOG_LEVEL'
+ *
+ * @return true on seccess, otherwise false..
+ */
+bool components_manager_set_log_level_all(int set);
+
+/**
+ * @brief Get ID of specific component by it's generated name.
+ *
+ * @param name Component name in string format
+ * @paran len The length of the name
+ *
+ * @return A @c component_id_t component ID.
+ */
+component_id_t components_manager_get_id_by_name(const char *name, size_t len);
+
+/**
+ * @brief Get ID of specific component by it's generated name.
+ *
+ * @param _component Component generated name from @c component_enum_t or @c collector_enum_t
+ *
+ * @return A @c component_id_t component ID.
+ */
+#define components_manager_get_id(_component) (g_component_factory[_component].component.info.id)
+
+/**
+ * @brief Start component.
+ *
+ * @param id Component ID provided by component manager on init function
+ * @param owner_id Component ID that asked the action
+ *
+ * @return A @c asc_result_t result.
+ */
+asc_result_t components_manager_start(component_id_t id, component_id_t owner_id);
+
+/**
+ * @brief Stop component.
+ *
+ * @param id Component ID provided by component manager on init function
+ * @param owner_id Component ID that asked the action
+ * @param ignore_self_owner If component has only self owner stop it
+ * @param force Force stop and clean owners
+ *
+ * @return A @c asc_result_t result.
+ */
+asc_result_t components_manager_stop(component_id_t id, component_id_t owner_id, bool ignore_self_owner, bool force);
+
+#endif //__COMPONENTS_MANAGER_H__
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/configuration.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/configuration.h
deleted file mode 100644
index 45f6903d..00000000
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/configuration.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
-
-#ifndef CONFIGURATION_H
-#define CONFIGURATION_H
-
-#include "asc_security_core/version.h"
-
-#ifndef DISABLE_ASC_PORT
-#include "asc_port.h"
-#else
-#include "asc_security_core/no_platform/asc_port.h"
-#endif /* DISABLE_ASC_PORT */
-
-// Security Module ID - A unique identifier of the device
-#ifndef ASC_SECURITY_MODULE_ID
-#define ASC_SECURITY_MODULE_ID "iot_security_module"
-#endif
-
-// First collection interval in seconds
-#ifndef ASC_FIRST_COLLECTION_INTERVAL
-#define ASC_FIRST_COLLECTION_INTERVAL 10
-#endif
-
-// Collection interval for high priority events, in seconds
-#ifndef ASC_HIGH_PRIORITY_INTERVAL
-#define ASC_HIGH_PRIORITY_INTERVAL 10
-#endif
-
-// Collection interval for medium priority events, in seconds
-#ifndef ASC_MEDIUM_PRIORITY_INTERVAL
-#define ASC_MEDIUM_PRIORITY_INTERVAL 30
-#endif
-
-// Collection interval for low priority events, in seconds
-#ifndef ASC_LOW_PRIORITY_INTERVAL
-#define ASC_LOW_PRIORITY_INTERVAL 60
-#endif
-
-// The maximum number of IPv4 network events to store in memory
-#ifndef ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV4_OBJECTS_IN_CACHE
-#define ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV4_OBJECTS_IN_CACHE 64
-#endif
-
-// The maximum number of IPv6 network events to store in memory
-#ifndef ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE
-#define ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE 64
-#endif
-
-// Send empty Network Activity events
-// #define ASC_COLLECTOR_NETWORK_ACTIVITY_SEND_EMPTY_EVENTS
-
-// The size of flatcc emitter page cache, when using custom allocator
-#ifndef EMITTER_PAGE_CACHE_SIZE
-#define EMITTER_PAGE_CACHE_SIZE 1
-#endif
-
-#endif /* CONFIGURATION_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/core.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/core.h
index 9a2921ab..96b8d97b 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/core.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/core.h
@@ -1,91 +1,86 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef CORE_H
#define CORE_H
+#include
+#include
+
+#include
+
#include "asc_security_core/asc_result.h"
#include "asc_security_core/collector_collection.h"
#include "asc_security_core/model/security_message.h"
-
+#define CORE_NEAREST_TIMER_UNSET_VAL LONG_MAX
/**
- * @struct core_t
+ * @brief Get a security message from the core.
*
+ * @param core_ptr The core ptr
+ * @param security_message_ptr The message buffer to write into
+ *
+ * @return ASC_RESULT_OK on success,
+ * ASC_RESULT_EMPTY when there are no events to send, in that case message_ptr remains unchanged,
+ * ASC_RESULT_EXCEPTION otherwise.
*/
-typedef struct core {
- COLLECTION_INTERFACE(struct core);
-
- const char *security_module_id;
- uint32_t security_module_version;
- collector_collection_t *collector_collection_ptr;
-
- uint8_t *message_buffer;
- size_t message_buffer_size;
-#ifdef DYNAMIC_MEMORY_ENABLED
- bool message_allocated;
-#endif
- bool message_empty;
-
- serializer_t *serializer;
-} core_t;
-
+asc_result_t core_message_get(security_message_t* security_message_ptr);
/**
- * @brief Initialize a new core
+ * @brief Deinit the last security message.
*
- * @return A new core
+ * @return ASC_RESULT_OK on success,
+ * ASC_RESULT_EXCEPTION otherwise.
*/
-core_t *core_init();
+asc_result_t core_message_deinit(void);
/**
- * @brief Deinitialize a core
+ * @brief Register collector to core
*
- * @param core_ptr The core to deinit
+ * @param collector_ptr A @c collector_t* collector handle
+ *
+ * @return ASC_RESULT_OK on success, corresponding error code otherwise.
*/
-void core_deinit(core_t *core_ptr);
+asc_result_t core_collector_register(collector_t *collector_ptr);
/**
- * @brief Collect events from all of the registered collectors.
+ * @brief Unregister collector from collector_collection
*
- * @param core_ptr the core ptr
- *
- * @return ASC_RESULT_OK on success,
- * ASC_RESULT_EMPTY when there are no events to send,
- * ASC_RESULT_EXCEPTION otherwise.
+ * @param collector_ptr A @c collector_t* collector handle
+ *
+ * @return ASC_RESULT_OK on success, corresponding error code otherwise.
*/
-asc_result_t core_collect(core_t *core_ptr);
+asc_result_t core_collector_unregister(collector_t *collector_ptr);
/**
- * @brief Get a security message from the core.
+ * @brief Get random generated collection start time, what is generating on startup of system to avoid sending message
+ * from many devices simultaneously.
*
- * @param core_ptr The core ptr
- * @param security_message_ptr The message buffer to write into
- *
- * @return ASC_RESULT_OK on success,
- * ASC_RESULT_EMPTY when there are no events to send, in that case message_ptr remains unchanged,
- * ASC_RESULT_EXCEPTION otherwise.
+ * @return init_random_collect_offset value.
*/
-asc_result_t core_message_get(core_t* core_ptr, security_message_t* security_message_ptr);
-
+unsigned long core_get_init_random_collect_offset(void);
/**
- * @brief Deinit the last security message.
+ * @brief Get current (last set) collect time.
*
- * @param core_ptr the core ptr
+ * @return nearest_collect_time value. In case of unset timer the CORE_NEAREST_TIMER_UNSET_VAL=LONG_MAX will be returned.
+ */
+unsigned long core_get_nearest_collect_time(void);
+
+/**
+ * @brief Get collectors collections that registered to core
*
- * @return ASC_RESULT_OK on success,
- * ASC_RESULT_EXCEPTION otherwise.
+ * @return Pointer to collector collection @c collector_collection_t .
*/
-asc_result_t core_message_deinit(core_t *core_ptr);
+collector_collection_t *core_get_collector_collection(void);
#endif /* CORE_H */
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/logger.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/logger.h
index 2f79b441..ac0ea9c0 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/logger.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/logger.h
@@ -1,73 +1,88 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef LOGGER_H
#define LOGGER_H
-#include "asc_security_core/utils/macros.h"
+#include
+#include
+#include
+#include
-#define LOG_LEVEL_NOTSET 0
-#define LOG_LEVEL_DEBUG 1
-#define LOG_LEVEL_INFO 2
-#define LOG_LEVEL_WARN 3
-#define LOG_LEVEL_ERROR 4
-#define LOG_LEVEL_FATAL 5
+#include
+#define LOG_LEVEL_NOTSET 0
+#define LOG_LEVEL_FATAL 1
+#define LOG_LEVEL_ERROR 2
+#define LOG_LEVEL_WARN 3
+#define LOG_LEVEL_INFO 4
+#define LOG_LEVEL_DEBUG 5
-#if LOG_LEVEL == LOG_LEVEL_NOTSET
+#ifndef ASC_LOG_LEVEL
+#define ASC_LOG_LEVEL LOG_LEVEL_NOTSET
+#endif
+
+#if ASC_LOG_LEVEL == LOG_LEVEL_NOTSET
#define log_debug(...)
#define log_info(...)
#define log_warn(...)
#define log_error(...)
#define log_fatal(...)
+ #define logger_set_system_log_level(_l)
+ #define logger_set_timestamp(_s)
+ #define logger_get_system_log_level() (LOG_LEVEL_NOTSET)
#else
- #include
- #include
- #include
- #include
+ #include "asc_security_core/utils/macros.h"
+ #include "asc_security_core/component_id.h"
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
- #define MDC_FORMAT "%s [%s/%s:%d] "
- bool logger_init();
- void logger_deinit();
- void logger_log(const char *level, const char *filename, const char *func, int line, const char *fmt, ...) ATTRIBUTE_FORMAT(5, 6);
+ bool logger_log(component_id_t id, unsigned int level, const char *filename, const char *func, int line, const char *fmt, ...) ATTRIBUTE_FORMAT(6, 7);
+/**
+ * @brief Set system log level - highest priority.
+ *
+ * @param set Requested log level, if (-1) - reset to default 'ASC_LOG_LEVEL'
+ *
+ * @return true on seccess, otherwise false.
+ */
+ bool logger_set_system_log_level(int set);
+ void logger_set_timestamp(bool set);
+ int logger_get_system_log_level(void);
- // define log by severity according to LOG_LEVEL
- #if LOG_LEVEL > LOG_LEVEL_DEBUG
+ // define log by severity according to ASC_LOG_LEVEL
+ #if ASC_LOG_LEVEL < LOG_LEVEL_DEBUG
#define log_debug(...)
#else
- #define log_debug(...) logger_log("DEBUG", __FILENAME__, __func__, __LINE__, ##__VA_ARGS__)
+ #define log_debug(...) logger_log(components_manager_get_self_id(), LOG_LEVEL_DEBUG, __FILENAME__, __func__, __LINE__, ##__VA_ARGS__)
#endif
- #if LOG_LEVEL > LOG_LEVEL_INFO
+ #if ASC_LOG_LEVEL < LOG_LEVEL_INFO
#define log_info(...)
#else
- #define log_info(...) logger_log("INFO", __FILENAME__, __func__, __LINE__, ##__VA_ARGS__)
+ #define log_info(...) logger_log(components_manager_get_self_id(), LOG_LEVEL_INFO, __FILENAME__, __func__, __LINE__, ##__VA_ARGS__)
#endif
- #if LOG_LEVEL > LOG_LEVEL_WARN
+ #if ASC_LOG_LEVEL < LOG_LEVEL_WARN
#define log_warn(...)
#else
- #define log_warn(...) logger_log("WARN", __FILENAME__, __func__, __LINE__, ##__VA_ARGS__)
+ #define log_warn(...) logger_log(components_manager_get_self_id(), LOG_LEVEL_WARN, __FILENAME__, __func__, __LINE__, ##__VA_ARGS__)
#endif
- #if LOG_LEVEL > LOG_LEVEL_ERROR
+ #if ASC_LOG_LEVEL < LOG_LEVEL_ERROR
#define log_error(...)
#else
- #define log_error(...) logger_log("ERROR", __FILENAME__, __func__, __LINE__, ##__VA_ARGS__)
+ #define log_error(...) logger_log(components_manager_get_self_id(), LOG_LEVEL_ERROR, __FILENAME__, __func__, __LINE__, ##__VA_ARGS__)
#endif
- #if LOG_LEVEL > LOG_LEVEL_FATAL
+ #if ASC_LOG_LEVEL < LOG_LEVEL_FATAL
#define log_fatal(...)
#else
- #define log_fatal(...) logger_log("FATAL", __FILENAME__, __func__, __LINE__, ##__VA_ARGS__)
+ #define log_fatal(...) logger_log(components_manager_get_self_id(), LOG_LEVEL_FATAL, __FILENAME__, __func__, __LINE__, ##__VA_ARGS__)
#endif
#endif
-
-#endif //LOGGER_H
\ No newline at end of file
+#endif //LOGGER_H
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/mti.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/mti.h
index e076d446..3c497a63 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/mti.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/mti.h
@@ -1,17 +1,17 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef _MTI_H_
#define _MTI_H_
-
+#include
/**
* @brief Create Message Type Indicator in format "X.Y-E-S-T",
* where "Major.Minor-Encoding-Source-Type". All fields are numeric
@@ -19,7 +19,7 @@
#define MTI_NAME "mti"
#define SCHEMA_MAJOR_VER "2"
-#define SCHEMA_MINOR_VER "0"
+#define SCHEMA_MINOR_VER "3"
#define JSON_ENCODING "0"
#define FLAT_BUFFERS "1"
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/objects/network_activity.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/objects/network_activity.h
index 196b3d1d..99602774 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/objects/network_activity.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/objects/network_activity.h
@@ -1,19 +1,21 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef OBJECT_NETWORK_ACTIVITY_H
#define OBJECT_NETWORK_ACTIVITY_H
#include
+#include
+
#include "asc_security_core/model/objects/transport_protocol.h"
#include "asc_security_core/utils/collection/collection.h"
@@ -27,16 +29,18 @@ typedef struct {
typedef struct network_activity_ipv4_t {
- network_activity_common_t common;
+ /* This macro must be first in object */
COLLECTION_INTERFACE(struct network_activity_ipv4_t);
+ network_activity_common_t common;
uint32_t local_address;
uint32_t remote_address;
} network_activity_ipv4_t;
typedef struct network_activity_ipv6_t {
- network_activity_common_t common;
+ /* This macro must be first in object */
COLLECTION_INTERFACE(struct network_activity_ipv6_t);
+ network_activity_common_t common;
uint32_t local_address[4];
uint32_t remote_address[4];
} network_activity_ipv6_t;
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/objects/objects.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/objects/objects.h
index 53b7e278..b24eec48 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/objects/objects.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/objects/objects.h
@@ -1,34 +1,41 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef OBJECTS_H
#define OBJECTS_H
+#include
-#include "asc_security_core/configuration.h"
+#ifdef ASC_COLLECTOR_LOG_ENABLED
+#include "asc_security_core/model/objects/log.h"
+#endif
-#ifdef COLLECTOR_SYSTEM_INFORMATION_ENABLED
+#ifdef ASC_COLLECTOR_SYSTEM_INFORMATION_ENABLED
#include "asc_security_core/model/objects/system_information.h"
#endif
-#ifdef COLLECTOR_LISTENING_PORTS_ENABLED
+#ifdef ASC_COLLECTOR_LISTENING_PORTS_ENABLED
#include "asc_security_core/model/objects/listening_ports.h"
#endif
-#ifdef COLLECTOR_NETWORK_ACTIVITY_ENABLED
+#ifdef ASC_COLLECTOR_NETWORK_ACTIVITY_ENABLED
#include "asc_security_core/model/objects/network_activity.h"
#endif
-#ifdef COLLECTOR_BASELINE_ENABLED
+#ifdef ASC_COLLECTOR_BASELINE_ENABLED
#include "asc_security_core/model/objects/baseline.h"
#include "asc_security_core/model/objects/object_baseline_ext.h"
#endif
+#ifdef ASC_COLLECTOR_PROCESS_ENABLED
+#include "asc_security_core/model/objects/process.h"
+#endif
+
#endif /* OBJECTS_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/objects/system_information.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/objects/system_information.h
index 536bcaff..4ac54bf3 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/objects/system_information.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/objects/system_information.h
@@ -1,22 +1,25 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef OBJECT_SYSTEM_INFORMATION_H
#define OBJECT_SYSTEM_INFORMATION_H
#include
+#include
+
#include "asc_security_core/utils/collection/collection.h"
typedef struct system_information_t {
+ /* This macro must be first in object */
COLLECTION_INTERFACE(struct system_information_t);
char* os_info;
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/objects/transport_protocol.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/objects/transport_protocol.h
index 8f816e7a..d7a542df 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/objects/transport_protocol.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/objects/transport_protocol.h
@@ -1,16 +1,17 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef TRANSPORT_PROTOCOL_H
#define TRANSPORT_PROTOCOL_H
+#include
typedef enum {
TRANSPORT_PROTOCOL_TCP,
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/baseline_json_parser.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/baseline_json_parser.h
new file mode 100644
index 00000000..c7a49d58
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/baseline_json_parser.h
@@ -0,0 +1,424 @@
+#ifndef BASELINE_JSON_PARSER_H
+#define BASELINE_JSON_PARSER_H
+
+/* Generated by flatcc 0.6.1-dev FlatBuffers schema compiler for C by dvide.com */
+
+#include "flatcc/flatcc_json_parser.h"
+#include "flatcc/flatcc_prologue.h"
+
+static const char *AzureIoTSecurity_Result_parse_json_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_type, uint64_t *value, int *aggregate);
+static const char *AzureIoTSecurity_Severity_parse_json_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_type, uint64_t *value, int *aggregate);
+static const char *AzureIoTSecurity_BaselineCheck_parse_json_table(flatcc_json_parser_t *ctx, const char *buf, const char *end, flatcc_builder_ref_t *result);
+static const char *AzureIoTSecurity_Baseline_parse_json_table(flatcc_json_parser_t *ctx, const char *buf, const char *end, flatcc_builder_ref_t *result);
+static const char *baseline_local_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+int *value_type, uint64_t *value, int *aggregate);
+static const char *baseline_local_AzureIoTSecurity_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+int *value_type, uint64_t *value, int *aggregate);
+static const char *baseline_global_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_type, uint64_t *value, int *aggregate);
+
+static const char *AzureIoTSecurity_Result_parse_json_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_sign, uint64_t *value, int *aggregate)
+{
+ const char *unmatched = buf;
+ const char *mark;
+ uint64_t w;
+
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w < 0x4641494c00000000) { /* branch "FAIL" */
+ if ((w & 0xffffffffff000000) == 0x4552524f52000000) { /* "ERROR" */
+ buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 5, aggregate);
+ if (buf != mark) {
+ *value = UINT64_C(2), *value_sign = 0;
+ } else {
+ return unmatched;
+ }
+ } else { /* "ERROR" */
+ return unmatched;
+ } /* "ERROR" */
+ } else { /* branch "FAIL" */
+ if ((w & 0xffffffff00000000) == 0x5041535300000000) { /* "PASS" */
+ buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 4, aggregate);
+ if (buf != mark) {
+ *value = UINT64_C(0), *value_sign = 0;
+ } else {
+ return unmatched;
+ }
+ } else { /* "PASS" */
+ if ((w & 0xffffffff00000000) == 0x4641494c00000000) { /* "FAIL" */
+ buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 4, aggregate);
+ if (buf != mark) {
+ *value = UINT64_C(1), *value_sign = 0;
+ } else {
+ return unmatched;
+ }
+ } else { /* "FAIL" */
+ return unmatched;
+ } /* "FAIL" */
+ } /* "PASS" */
+ } /* branch "FAIL" */
+ return buf;
+}
+
+static const char *AzureIoTSecurity_Severity_parse_json_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_sign, uint64_t *value, int *aggregate)
+{
+ const char *unmatched = buf;
+ const char *mark;
+ uint64_t w;
+
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w < 0x494d504f5254414e) { /* branch "IMPORTAN" */
+ if (w == 0x435249544943414c) { /* "CRITICAL" */
+ buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 8, aggregate);
+ if (buf != mark) {
+ *value = UINT64_C(0), *value_sign = 0;
+ } else {
+ return unmatched;
+ }
+ } else { /* "CRITICAL" */
+ return unmatched;
+ } /* "CRITICAL" */
+ } else { /* branch "IMPORTAN" */
+ if (w < 0x494e464f524d4154) { /* branch "INFORMAT" */
+ if (w == 0x494d504f5254414e) { /* descend "IMPORTAN" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xff00000000000000) == 0x5400000000000000) { /* "T" */
+ buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 1, aggregate);
+ if (buf != mark) {
+ *value = UINT64_C(1), *value_sign = 0;
+ } else {
+ return unmatched;
+ }
+ } else { /* "T" */
+ return unmatched;
+ } /* "T" */
+ } else { /* descend "IMPORTAN" */
+ return unmatched;
+ } /* descend "IMPORTAN" */
+ } else { /* branch "INFORMAT" */
+ if (w == 0x494e464f524d4154) { /* descend "INFORMAT" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xffffffffff000000) == 0x494f4e414c000000) { /* "IONAL" */
+ buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 5, aggregate);
+ if (buf != mark) {
+ *value = UINT64_C(3), *value_sign = 0;
+ } else {
+ return unmatched;
+ }
+ } else { /* "IONAL" */
+ return unmatched;
+ } /* "IONAL" */
+ } else { /* descend "INFORMAT" */
+ if ((w & 0xffffffffffffff00) == 0x5741524e494e4700) { /* "WARNING" */
+ buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 7, aggregate);
+ if (buf != mark) {
+ *value = UINT64_C(2), *value_sign = 0;
+ } else {
+ return unmatched;
+ }
+ } else { /* "WARNING" */
+ return unmatched;
+ } /* "WARNING" */
+ } /* descend "INFORMAT" */
+ } /* branch "INFORMAT" */
+ } /* branch "IMPORTAN" */
+ return buf;
+}
+
+static const char *AzureIoTSecurity_BaselineCheck_parse_json_table(flatcc_json_parser_t *ctx, const char *buf, const char *end, flatcc_builder_ref_t *result)
+{
+ int more;
+ void *pval;
+ flatcc_builder_ref_t ref, *pref;
+ const char *mark;
+ uint64_t w;
+
+ *result = 0;
+ if (flatcc_builder_start_table(ctx->ctx, 6)) goto failed;
+ buf = flatcc_json_parser_object_start(ctx, buf, end, &more);
+ while (more) {
+ buf = flatcc_json_parser_symbol_start(ctx, buf, end);
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w < 0x6964000000000000) { /* branch "id" */
+ if (w == 0x6465736372697074) { /* descend "descript" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xffffff0000000000) == 0x696f6e0000000000) { /* "ion" */
+ buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 3);
+ if (mark != buf) {
+ buf = flatcc_json_parser_build_string(ctx, buf, end, &ref);
+ if (!ref || !(pref = flatcc_builder_table_add_offset(ctx->ctx, 3))) goto failed;
+ *pref = ref;
+ } else {
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ }
+ } else { /* "ion" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* "ion" */
+ } else { /* descend "descript" */
+ if ((w & 0xffffffffff000000) == 0x6572726f72000000) { /* "error" */
+ buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 5);
+ if (mark != buf) {
+ buf = flatcc_json_parser_build_string(ctx, buf, end, &ref);
+ if (!ref || !(pref = flatcc_builder_table_add_offset(ctx->ctx, 2))) goto failed;
+ *pref = ref;
+ } else {
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ }
+ } else { /* "error" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* "error" */
+ } /* descend "descript" */
+ } else { /* branch "id" */
+ if (w < 0x72656d6564696174) { /* branch "remediat" */
+ if ((w & 0xffff000000000000) == 0x6964000000000000) { /* "id" */
+ buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 2);
+ if (mark != buf) {
+ buf = flatcc_json_parser_build_string(ctx, buf, end, &ref);
+ if (!ref || !(pref = flatcc_builder_table_add_offset(ctx->ctx, 0))) goto failed;
+ *pref = ref;
+ } else {
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ }
+ } else { /* "id" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* "id" */
+ } else { /* branch "remediat" */
+ if (w < 0x726573756c740000) { /* branch "result" */
+ if (w == 0x72656d6564696174) { /* descend "remediat" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xffffff0000000000) == 0x696f6e0000000000) { /* "ion" */
+ buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 3);
+ if (mark != buf) {
+ buf = flatcc_json_parser_build_string(ctx, buf, end, &ref);
+ if (!ref || !(pref = flatcc_builder_table_add_offset(ctx->ctx, 5))) goto failed;
+ *pref = ref;
+ } else {
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ }
+ } else { /* "ion" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* "ion" */
+ } else { /* descend "remediat" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* descend "remediat" */
+ } else { /* branch "result" */
+ if (w == 0x7365766572697479) { /* "severity" */
+ buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 8);
+ if (mark != buf) {
+ int8_t val = 0;
+ static flatcc_json_parser_integral_symbol_f *symbolic_parsers[] = {
+ AzureIoTSecurity_Severity_parse_json_enum,
+ baseline_local_AzureIoTSecurity_json_parser_enum,
+ baseline_global_json_parser_enum, 0 };
+ buf = flatcc_json_parser_int8(ctx, (mark = buf), end, &val);
+ if (mark == buf) {
+ buf = flatcc_json_parser_symbolic_int8(ctx, (mark = buf), end, symbolic_parsers, &val);
+ if (buf == mark || buf == end) goto failed;
+ }
+ if (val != 0 || (ctx->flags & flatcc_json_parser_f_force_add)) {
+ if (!(pval = flatcc_builder_table_add(ctx->ctx, 4, 1, 1))) goto failed;
+ flatbuffers_int8_write_to_pe(pval, val);
+ }
+ } else {
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ }
+ } else { /* "severity" */
+ if ((w & 0xffffffffffff0000) == 0x726573756c740000) { /* "result" */
+ buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 6);
+ if (mark != buf) {
+ int8_t val = 0;
+ static flatcc_json_parser_integral_symbol_f *symbolic_parsers[] = {
+ AzureIoTSecurity_Result_parse_json_enum,
+ baseline_local_AzureIoTSecurity_json_parser_enum,
+ baseline_global_json_parser_enum, 0 };
+ buf = flatcc_json_parser_int8(ctx, (mark = buf), end, &val);
+ if (mark == buf) {
+ buf = flatcc_json_parser_symbolic_int8(ctx, (mark = buf), end, symbolic_parsers, &val);
+ if (buf == mark || buf == end) goto failed;
+ }
+ if (val != 0 || (ctx->flags & flatcc_json_parser_f_force_add)) {
+ if (!(pval = flatcc_builder_table_add(ctx->ctx, 1, 1, 1))) goto failed;
+ flatbuffers_int8_write_to_pe(pval, val);
+ }
+ } else {
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ }
+ } else { /* "result" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* "result" */
+ } /* "severity" */
+ } /* branch "result" */
+ } /* branch "remediat" */
+ } /* branch "id" */
+ buf = flatcc_json_parser_object_end(ctx, buf, end, &more);
+ }
+ if (ctx->error) goto failed;
+ if (!flatcc_builder_check_required_field(ctx->ctx, 0)
+ ) {
+ buf = flatcc_json_parser_set_error(ctx, buf, end, flatcc_json_parser_error_required);
+ goto failed;
+ }
+ if (!(*result = flatcc_builder_end_table(ctx->ctx))) goto failed;
+ return buf;
+failed:
+ return flatcc_json_parser_set_error(ctx, buf, end, flatcc_json_parser_error_runtime);
+}
+
+static inline int AzureIoTSecurity_BaselineCheck_parse_json_as_root(flatcc_builder_t *B, flatcc_json_parser_t *ctx, const char *buf, size_t bufsiz, int flags, const char *fid)
+{
+ return flatcc_json_parser_table_as_root(B, ctx, buf, bufsiz, flags, fid, AzureIoTSecurity_BaselineCheck_parse_json_table);
+}
+
+static const char *AzureIoTSecurity_Baseline_parse_json_table(flatcc_json_parser_t *ctx, const char *buf, const char *end, flatcc_builder_ref_t *result)
+{
+ int more;
+ void *pval;
+ flatcc_builder_ref_t ref, *pref;
+ const char *mark;
+ uint64_t w;
+
+ *result = 0;
+ if (flatcc_builder_start_table(ctx->ctx, 1)) goto failed;
+ buf = flatcc_json_parser_object_start(ctx, buf, end, &more);
+ while (more) {
+ buf = flatcc_json_parser_symbol_start(ctx, buf, end);
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x626173656c696e65) { /* descend "baseline" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xffffffffffffff00) == 0x5f636865636b7300) { /* "_checks" */
+ buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 7);
+ if (mark != buf) {
+ if (flatcc_builder_start_offset_vector(ctx->ctx)) goto failed;
+ buf = flatcc_json_parser_array_start(ctx, buf, end, &more);
+ while (more) {
+ buf = AzureIoTSecurity_BaselineCheck_parse_json_table(ctx, buf, end, &ref);
+ if (!ref || !(pref = flatcc_builder_extend_offset_vector(ctx->ctx, 1))) goto failed;
+ *pref = ref;
+ buf = flatcc_json_parser_array_end(ctx, buf, end, &more);
+ }
+ ref = flatcc_builder_end_offset_vector(ctx->ctx);
+ if (!ref || !(pref = flatcc_builder_table_add_offset(ctx->ctx, 0))) goto failed;
+ *pref = ref;
+ } else {
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ }
+ } else { /* "_checks" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* "_checks" */
+ } else { /* descend "baseline" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* descend "baseline" */
+ buf = flatcc_json_parser_object_end(ctx, buf, end, &more);
+ }
+ if (ctx->error) goto failed;
+ if (!(*result = flatcc_builder_end_table(ctx->ctx))) goto failed;
+ return buf;
+failed:
+ return flatcc_json_parser_set_error(ctx, buf, end, flatcc_json_parser_error_runtime);
+}
+
+static inline int AzureIoTSecurity_Baseline_parse_json_as_root(flatcc_builder_t *B, flatcc_json_parser_t *ctx, const char *buf, size_t bufsiz, int flags, const char *fid)
+{
+ return flatcc_json_parser_table_as_root(B, ctx, buf, bufsiz, flags, fid, AzureIoTSecurity_Baseline_parse_json_table);
+}
+
+static const char *baseline_local_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_type, uint64_t *value, int *aggregate)
+{
+ /* Scope has no enum / union types to look up. */
+ return buf; /* unmatched; */
+}
+
+static const char *baseline_local_AzureIoTSecurity_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_type, uint64_t *value, int *aggregate)
+{
+ const char *unmatched = buf;
+ const char *mark;
+ uint64_t w;
+
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x5365766572697479) { /* "Severity" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 8);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_Severity_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* "Severity" */
+ if ((w & 0xffffffffffff0000) == 0x526573756c740000) { /* "Result" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 6);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_Result_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* "Result" */
+ return unmatched;
+ } /* "Result" */
+ } /* "Severity" */
+ return buf;
+}
+
+static const char *baseline_global_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_type, uint64_t *value, int *aggregate)
+{
+ const char *unmatched = buf;
+ const char *mark;
+ uint64_t w;
+
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x417a757265496f54) { /* descend "AzureIoT" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x5365637572697479) { /* descend "Security" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xffffffffffffff00) == 0x2e526573756c7400) { /* ".Result" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 7);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_Result_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ goto pfguard1;
+ }
+ } else { /* ".Result" */
+ goto pfguard1;
+ } /* ".Result" */
+ goto endpfguard1;
+pfguard1:
+ if (w == 0x2e53657665726974) { /* descend ".Severit" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xff00000000000000) == 0x7900000000000000) { /* "y" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 1);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_Severity_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* "y" */
+ return unmatched;
+ } /* "y" */
+ } else { /* descend ".Severit" */
+ return unmatched;
+ } /* descend ".Severit" */
+endpfguard1:
+ (void)0;
+ } else { /* descend "Security" */
+ return unmatched;
+ } /* descend "Security" */
+ } else { /* descend "AzureIoT" */
+ return unmatched;
+ } /* descend "AzureIoT" */
+ return buf;
+}
+
+#include "flatcc/flatcc_epilogue.h"
+#endif /* BASELINE_JSON_PARSER_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/baseline_json_printer.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/baseline_json_printer.h
new file mode 100644
index 00000000..76ec854c
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/baseline_json_printer.h
@@ -0,0 +1,61 @@
+#ifndef BASELINE_JSON_PRINTER_H
+#define BASELINE_JSON_PRINTER_H
+
+/* Generated by flatcc 0.6.1-dev FlatBuffers schema compiler for C by dvide.com */
+
+#include "flatcc/flatcc_json_printer.h"
+#include "flatcc/flatcc_prologue.h"
+
+static void AzureIoTSecurity_BaselineCheck_print_json_table(flatcc_json_printer_t *ctx, flatcc_json_printer_table_descriptor_t *td);
+static void AzureIoTSecurity_Baseline_print_json_table(flatcc_json_printer_t *ctx, flatcc_json_printer_table_descriptor_t *td);
+
+static void AzureIoTSecurity_Result_print_json_enum(flatcc_json_printer_t *ctx, int8_t v)
+{
+
+ switch (v) {
+ case 0: flatcc_json_printer_enum(ctx, "PASS", 4); break;
+ case 1: flatcc_json_printer_enum(ctx, "FAIL", 4); break;
+ case 2: flatcc_json_printer_enum(ctx, "ERROR", 5); break;
+ default: flatcc_json_printer_int8(ctx, v); break;
+ }
+}
+
+static void AzureIoTSecurity_Severity_print_json_enum(flatcc_json_printer_t *ctx, int8_t v)
+{
+
+ switch (v) {
+ case 0: flatcc_json_printer_enum(ctx, "CRITICAL", 8); break;
+ case 1: flatcc_json_printer_enum(ctx, "IMPORTANT", 9); break;
+ case 2: flatcc_json_printer_enum(ctx, "WARNING", 7); break;
+ case 3: flatcc_json_printer_enum(ctx, "INFORMATIONAL", 13); break;
+ default: flatcc_json_printer_int8(ctx, v); break;
+ }
+}
+
+static void AzureIoTSecurity_BaselineCheck_print_json_table(flatcc_json_printer_t *ctx, flatcc_json_printer_table_descriptor_t *td)
+{
+ flatcc_json_printer_string_field(ctx, td, 0, "id", 2);
+ flatcc_json_printer_int8_enum_field(ctx, td, 1, "result", 6, 0, AzureIoTSecurity_Result_print_json_enum);
+ flatcc_json_printer_string_field(ctx, td, 2, "error", 5);
+ flatcc_json_printer_string_field(ctx, td, 3, "description", 11);
+ flatcc_json_printer_int8_enum_field(ctx, td, 4, "severity", 8, 0, AzureIoTSecurity_Severity_print_json_enum);
+ flatcc_json_printer_string_field(ctx, td, 5, "remediation", 11);
+}
+
+static inline int AzureIoTSecurity_BaselineCheck_print_json_as_root(flatcc_json_printer_t *ctx, const void *buf, size_t bufsiz, const char *fid)
+{
+ return flatcc_json_printer_table_as_root(ctx, buf, bufsiz, fid, AzureIoTSecurity_BaselineCheck_print_json_table);
+}
+
+static void AzureIoTSecurity_Baseline_print_json_table(flatcc_json_printer_t *ctx, flatcc_json_printer_table_descriptor_t *td)
+{
+ flatcc_json_printer_table_vector_field(ctx, td, 0, "baseline_checks", 15, AzureIoTSecurity_BaselineCheck_print_json_table);
+}
+
+static inline int AzureIoTSecurity_Baseline_print_json_as_root(flatcc_json_printer_t *ctx, const void *buf, size_t bufsiz, const char *fid)
+{
+ return flatcc_json_printer_table_as_root(ctx, buf, bufsiz, fid, AzureIoTSecurity_Baseline_print_json_table);
+}
+
+#include "flatcc/flatcc_epilogue.h"
+#endif /* BASELINE_JSON_PRINTER_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/event_builder.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/event_builder.h
index 776f7e13..a947d0a0 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/event_builder.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/event_builder.h
@@ -42,6 +42,8 @@ __flatbuffers_build_union_table_value_field(flatbuffers_, AzureIoTSecurity_Event
__flatbuffers_build_union_table_value_field(flatbuffers_, AzureIoTSecurity_Event_payload, AzureIoTSecurity_Payload, ListeningPorts, AzureIoTSecurity_ListeningPorts)
__flatbuffers_build_union_table_value_field(flatbuffers_, AzureIoTSecurity_Event_payload, AzureIoTSecurity_Payload, Heartbeat, AzureIoTSecurity_Heartbeat)
__flatbuffers_build_union_table_value_field(flatbuffers_, AzureIoTSecurity_Event_payload, AzureIoTSecurity_Payload, Baseline, AzureIoTSecurity_Baseline)
+__flatbuffers_build_union_table_value_field(flatbuffers_, AzureIoTSecurity_Event_payload, AzureIoTSecurity_Payload, Process, AzureIoTSecurity_Process)
+__flatbuffers_build_union_table_value_field(flatbuffers_, AzureIoTSecurity_Event_payload, AzureIoTSecurity_Payload, Log, AzureIoTSecurity_Log)
static inline AzureIoTSecurity_Event_ref_t AzureIoTSecurity_Event_create(flatbuffers_builder_t *B __AzureIoTSecurity_Event_formal_args)
{
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/event_json_parser.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/event_json_parser.h
index 85ad1f60..07271041 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/event_json_parser.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/event_json_parser.h
@@ -175,7 +175,7 @@ static const char *event_local_AzureIoTSecurity_json_parser_enum(flatcc_json_par
uint64_t w;
w = flatcc_json_parser_symbol_part(buf, end);
- if (w < 0x50726f746f636f6c) { /* branch "Protocol" */
+ if (w < 0x50726f6365737345) { /* branch "ProcessE" */
if ((w & 0xffffffffffffff00) == 0x5061796c6f616400) { /* "Payload" */
buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 7);
if (buf != mark) {
@@ -184,42 +184,70 @@ static const char *event_local_AzureIoTSecurity_json_parser_enum(flatcc_json_par
return unmatched;
}
} else { /* "Payload" */
- return unmatched;
- } /* "Payload" */
- } else { /* branch "Protocol" */
- if (w < 0x526573756c740000) { /* branch "Result" */
- if (w == 0x50726f746f636f6c) { /* "Protocol" */
- buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 8);
+ if ((w & 0xffffffffff000000) == 0x4c6576656c000000) { /* "Level" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 5);
if (buf != mark) {
- buf = AzureIoTSecurity_Protocol_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ buf = AzureIoTSecurity_Level_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
} else {
return unmatched;
}
- } else { /* "Protocol" */
+ } else { /* "Level" */
return unmatched;
- } /* "Protocol" */
- } else { /* branch "Result" */
- if (w == 0x5365766572697479) { /* "Severity" */
- buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 8);
- if (buf != mark) {
- buf = AzureIoTSecurity_Severity_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
- } else {
+ } /* "Level" */
+ } /* "Payload" */
+ } else { /* branch "ProcessE" */
+ if (w < 0x50726f746f636f6c) { /* branch "Protocol" */
+ if (w == 0x50726f6365737345) { /* descend "ProcessE" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x76656e7454797065) { /* "ventType" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 8);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_ProcessEventType_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* "ventType" */
return unmatched;
- }
- } else { /* "Severity" */
- if ((w & 0xffffffffffff0000) == 0x526573756c740000) { /* "Result" */
- buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 6);
+ } /* "ventType" */
+ } else { /* descend "ProcessE" */
+ return unmatched;
+ } /* descend "ProcessE" */
+ } else { /* branch "Protocol" */
+ if (w < 0x526573756c740000) { /* branch "Result" */
+ if (w == 0x50726f746f636f6c) { /* "Protocol" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 8);
if (buf != mark) {
- buf = AzureIoTSecurity_Result_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ buf = AzureIoTSecurity_Protocol_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
} else {
return unmatched;
}
- } else { /* "Result" */
+ } else { /* "Protocol" */
return unmatched;
- } /* "Result" */
- } /* "Severity" */
- } /* branch "Result" */
- } /* branch "Protocol" */
+ } /* "Protocol" */
+ } else { /* branch "Result" */
+ if (w == 0x5365766572697479) { /* "Severity" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 8);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_Severity_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* "Severity" */
+ if ((w & 0xffffffffffff0000) == 0x526573756c740000) { /* "Result" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 6);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_Result_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* "Result" */
+ return unmatched;
+ } /* "Result" */
+ } /* "Severity" */
+ } /* branch "Result" */
+ } /* branch "Protocol" */
+ } /* branch "ProcessE" */
return buf;
}
@@ -237,7 +265,7 @@ static const char *event_global_json_parser_enum(flatcc_json_parser_t *ctx, cons
if (w == 0x5365637572697479) { /* descend "Security" */
buf += 8;
w = flatcc_json_parser_symbol_part(buf, end);
- if (w < 0x2e50726f746f636f) { /* branch ".Protoco" */
+ if (w < 0x2e50726f63657373) { /* branch ".Process" */
if (w == 0x2e5061796c6f6164) { /* ".Payload" */
buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 8);
if (buf != mark) {
@@ -246,59 +274,93 @@ static const char *event_global_json_parser_enum(flatcc_json_parser_t *ctx, cons
return unmatched;
}
} else { /* ".Payload" */
- return unmatched;
+ if ((w & 0xffffffffffff0000) == 0x2e4c6576656c0000) { /* ".Level" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 6);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_Level_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* ".Level" */
+ return unmatched;
+ } /* ".Level" */
} /* ".Payload" */
- } else { /* branch ".Protoco" */
- if (w < 0x2e526573756c7400) { /* branch ".Result" */
- if (w == 0x2e50726f746f636f) { /* descend ".Protoco" */
+ } else { /* branch ".Process" */
+ if (w < 0x2e50726f746f636f) { /* branch ".Protoco" */
+ if (w == 0x2e50726f63657373) { /* descend ".Process" */
buf += 8;
w = flatcc_json_parser_symbol_part(buf, end);
- if ((w & 0xff00000000000000) == 0x6c00000000000000) { /* "l" */
- buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 1);
- if (buf != mark) {
- buf = AzureIoTSecurity_Protocol_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
- } else {
+ if (w == 0x4576656e74547970) { /* descend "EventTyp" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xff00000000000000) == 0x6500000000000000) { /* "e" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 1);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_ProcessEventType_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* "e" */
return unmatched;
- }
- } else { /* "l" */
+ } /* "e" */
+ } else { /* descend "EventTyp" */
return unmatched;
- } /* "l" */
- } else { /* descend ".Protoco" */
+ } /* descend "EventTyp" */
+ } else { /* descend ".Process" */
return unmatched;
- } /* descend ".Protoco" */
- } else { /* branch ".Result" */
- if ((w & 0xffffffffffffff00) == 0x2e526573756c7400) { /* ".Result" */
- buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 7);
- if (buf != mark) {
- buf = AzureIoTSecurity_Result_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
- } else {
- goto pfguard1;
- }
- } else { /* ".Result" */
- goto pfguard1;
- } /* ".Result" */
- goto endpfguard1;
-pfguard1:
- if (w == 0x2e53657665726974) { /* descend ".Severit" */
- buf += 8;
- w = flatcc_json_parser_symbol_part(buf, end);
- if ((w & 0xff00000000000000) == 0x7900000000000000) { /* "y" */
- buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 1);
+ } /* descend ".Process" */
+ } else { /* branch ".Protoco" */
+ if (w < 0x2e526573756c7400) { /* branch ".Result" */
+ if (w == 0x2e50726f746f636f) { /* descend ".Protoco" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xff00000000000000) == 0x6c00000000000000) { /* "l" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 1);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_Protocol_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* "l" */
+ return unmatched;
+ } /* "l" */
+ } else { /* descend ".Protoco" */
+ return unmatched;
+ } /* descend ".Protoco" */
+ } else { /* branch ".Result" */
+ if ((w & 0xffffffffffffff00) == 0x2e526573756c7400) { /* ".Result" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 7);
if (buf != mark) {
- buf = AzureIoTSecurity_Severity_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ buf = AzureIoTSecurity_Result_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
} else {
- return unmatched;
+ goto pfguard1;
}
- } else { /* "y" */
+ } else { /* ".Result" */
+ goto pfguard1;
+ } /* ".Result" */
+ goto endpfguard1;
+pfguard1:
+ if (w == 0x2e53657665726974) { /* descend ".Severit" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xff00000000000000) == 0x7900000000000000) { /* "y" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 1);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_Severity_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* "y" */
+ return unmatched;
+ } /* "y" */
+ } else { /* descend ".Severit" */
return unmatched;
- } /* "y" */
- } else { /* descend ".Severit" */
- return unmatched;
- } /* descend ".Severit" */
+ } /* descend ".Severit" */
endpfguard1:
- (void)0;
- } /* branch ".Result" */
- } /* branch ".Protoco" */
+ (void)0;
+ } /* branch ".Result" */
+ } /* branch ".Protoco" */
+ } /* branch ".Process" */
} else { /* descend "Security" */
return unmatched;
} /* descend "Security" */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/flatbuffers_common_reader.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/flatbuffers_common_reader.h
index 2f4b5784..5f6f64df 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/flatbuffers_common_reader.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/flatbuffers_common_reader.h
@@ -3,11 +3,8 @@
/* Generated by flatcc 0.6.1-dev FlatBuffers schema compiler for C by dvide.com */
-#ifndef FLATCC_NO_ASSERT
-#define FLATCC_NO_ASSERT
-#endif
-
/* Common FlatBuffers read functionality for C. */
+
#include "flatcc/flatcc_prologue.h"
#include "flatcc/flatcc_flatbuffers.h"
@@ -17,7 +14,7 @@
#define __flatbuffers_read_vt(ID, offset, t)\
flatbuffers_voffset_t offset = 0;\
{ flatbuffers_voffset_t id__tmp, *vt__tmp;\
- FLATCC_ASSERT(t != 0 && "null pointer table access");\
+ FLATCC_ASSERT((0 != (__ASSERT_VAL__ = (t != 0))) && (NULL != (__ASSERT_REASON__ = "null pointer table access")));\
id__tmp = ID;\
vt__tmp = (flatbuffers_voffset_t *)((uint8_t *)(t) -\
__flatbuffers_soffset_read_from_pe(t));\
@@ -54,7 +51,7 @@ __flatbuffers_define_scan_by_scalar_field(N, NK, T)
if (offset__tmp) {\
return (T)((uint8_t *)(t) + offset__tmp);\
}\
- FLATCC_ASSERT(!(r) && "required field missing");\
+ FLATCC_ASSERT((0 != (__ASSERT_VAL__ = !(r))) && (NULL != (__ASSERT_REASON__ = "required field missing")));\
return 0;\
}
#define __flatbuffers_offset_field(T, ID, t, r, adjust)\
@@ -67,7 +64,7 @@ __flatbuffers_define_scan_by_scalar_field(N, NK, T)
return (T)((uint8_t *)(elem__tmp) + adjust +\
__flatbuffers_uoffset_read_from_pe(elem__tmp));\
}\
- FLATCC_ASSERT(!(r) && "required field missing");\
+ FLATCC_ASSERT((0 != (__ASSERT_VAL__ = !(r))) && (NULL != (__ASSERT_REASON__ = "required field missing")));\
return 0;\
}
#define __flatbuffers_vector_field(T, ID, t, r) __flatbuffers_offset_field(T, ID, t, r, sizeof(flatbuffers_uoffset_t))
@@ -107,14 +104,14 @@ __flatbuffers_define_scan_by_string_field(N, NK)
static inline size_t flatbuffers_vec_len(const void *vec)
__flatbuffers_vec_len(vec)
#define __flatbuffers_scalar_vec_at(N, vec, i)\
-{ FLATCC_ASSERT(flatbuffers_vec_len(vec) > (i) && "index out of range");\
+{ FLATCC_ASSERT(flatbuffers_vec_len(vec) > (i) && (NULL != (__ASSERT_REASON__ = "index out of range")));\
return __flatbuffers_read_scalar(N, &(vec)[i]); }
#define __flatbuffers_struct_vec_at(vec, i)\
-{ FLATCC_ASSERT(flatbuffers_vec_len(vec) > (i) && "index out of range"); return (vec) + (i); }
+{ FLATCC_ASSERT(flatbuffers_vec_len(vec) > (i) && (NULL != (__ASSERT_REASON__ = "index out of range"))); return (vec) + (i); }
/* `adjust` skips past the header for string vectors. */
#define __flatbuffers_offset_vec_at(T, vec, i, adjust)\
{ const flatbuffers_uoffset_t *elem__tmp = (vec) + (i);\
- FLATCC_ASSERT(flatbuffers_vec_len(vec) > (i) && "index out of range");\
+ FLATCC_ASSERT(flatbuffers_vec_len(vec) > (i) && (NULL != (__ASSERT_REASON__ = "index out of range")));\
return (T)((uint8_t *)(elem__tmp) + (size_t)__flatbuffers_uoffset_read_from_pe(elem__tmp) + (adjust)); }
#define __flatbuffers_define_scalar_vec_len(N)\
static inline size_t N ## _vec_len(N ##_vec_t vec__tmp)\
@@ -194,7 +191,7 @@ static inline size_t T ## _union_vec_len(T ## _union_vec_t uv__tmp)\
{ return NS ## vec_len(uv__tmp.type); }\
static inline T ## _union_t T ## _union_vec_at(T ## _union_vec_t uv__tmp, size_t i__tmp)\
{ T ## _union_t u__tmp = { 0, 0 }; size_t n__tmp = NS ## vec_len(uv__tmp.type);\
- FLATCC_ASSERT(n__tmp > (i__tmp) && "index out of range"); u__tmp.type = uv__tmp.type[i__tmp];\
+ FLATCC_ASSERT(n__tmp > (i__tmp) && (NULL != (__ASSERT_REASON__ = "index out of range"))); u__tmp.type = uv__tmp.type[i__tmp];\
/* Unknown type is treated as NONE for schema evolution. */\
if (u__tmp.type == 0) return u__tmp;\
u__tmp.value = NS ## generic_vec_at(uv__tmp.value, i__tmp); return u__tmp; }\
@@ -220,7 +217,7 @@ static inline T ## _union_vec_t N ## _ ## NK ## _union(N ## _table_t t__tmp)\
{ T ## _union_vec_t uv__tmp; uv__tmp.type = N ## _ ## NK ## _type_get(t__tmp);\
uv__tmp.value = N ## _ ## NK(t__tmp);\
FLATCC_ASSERT(NS ## vec_len(uv__tmp.type) == NS ## vec_len(uv__tmp.value)\
- && "union vector type length mismatch"); return uv__tmp; }
+ && (NULL != (__ASSERT_REASON__ = "union vector type length mismatch"))); return uv__tmp; }
#include
static const size_t flatbuffers_not_found = (size_t)-1;
static const size_t flatbuffers_end = (size_t)-1;
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/listening_ports_json_parser.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/listening_ports_json_parser.h
new file mode 100644
index 00000000..7204f173
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/listening_ports_json_parser.h
@@ -0,0 +1,427 @@
+#ifndef LISTENING_PORTS_JSON_PARSER_H
+#define LISTENING_PORTS_JSON_PARSER_H
+
+/* Generated by flatcc 0.6.1-dev FlatBuffers schema compiler for C by dvide.com */
+
+#include "flatcc/flatcc_json_parser.h"
+#ifndef PROTOCOL_JSON_PARSER_H
+#include "protocol_json_parser.h"
+#endif
+#include "flatcc/flatcc_prologue.h"
+
+static const char *AzureIoTSecurity_ListeningPortsCommon_parse_json_struct_inline(flatcc_json_parser_t *ctx, const char *buf, const char *end, void *struct_base);
+static const char *AzureIoTSecurity_ListeningPortsCommon_parse_json_struct(flatcc_json_parser_t *ctx, const char *buf, const char *end, flatcc_builder_ref_t *result);
+static const char *AzureIoTSecurity_ListeningPortsV4_parse_json_struct_inline(flatcc_json_parser_t *ctx, const char *buf, const char *end, void *struct_base);
+static const char *AzureIoTSecurity_ListeningPortsV4_parse_json_struct(flatcc_json_parser_t *ctx, const char *buf, const char *end, flatcc_builder_ref_t *result);
+static const char *AzureIoTSecurity_ListeningPortsV6_parse_json_struct_inline(flatcc_json_parser_t *ctx, const char *buf, const char *end, void *struct_base);
+static const char *AzureIoTSecurity_ListeningPortsV6_parse_json_struct(flatcc_json_parser_t *ctx, const char *buf, const char *end, flatcc_builder_ref_t *result);
+static const char *AzureIoTSecurity_ListeningPorts_parse_json_table(flatcc_json_parser_t *ctx, const char *buf, const char *end, flatcc_builder_ref_t *result);
+static const char *listening_ports_local_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+int *value_type, uint64_t *value, int *aggregate);
+static const char *listening_ports_local_AzureIoTSecurity_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+int *value_type, uint64_t *value, int *aggregate);
+static const char *listening_ports_global_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_type, uint64_t *value, int *aggregate);
+
+static const char *AzureIoTSecurity_ListeningPortsCommon_parse_json_struct_inline(flatcc_json_parser_t *ctx, const char *buf, const char *end, void *struct_base)
+{
+ int more;
+ flatcc_builder_ref_t ref;
+ void *pval;
+ const char *mark;
+ uint64_t w;
+
+ buf = flatcc_json_parser_object_start(ctx, buf, end, &more);
+ while (more) {
+ buf = flatcc_json_parser_symbol_start(ctx, buf, end);
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x6c6f63616c5f706f) { /* descend "local_po" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xffff000000000000) == 0x7274000000000000) { /* "rt" */
+ buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 2);
+ if (mark != buf) {
+ uint16_t val = 0;
+ static flatcc_json_parser_integral_symbol_f *symbolic_parsers[] = {
+ listening_ports_local_AzureIoTSecurity_json_parser_enum,
+ listening_ports_global_json_parser_enum, 0 };
+ pval = (void *)((size_t)struct_base + 0);
+ buf = flatcc_json_parser_uint16(ctx, (mark = buf), end, &val);
+ if (mark == buf) {
+ buf = flatcc_json_parser_symbolic_uint16(ctx, (mark = buf), end, symbolic_parsers, &val);
+ if (buf == mark || buf == end) goto failed;
+ }
+ flatbuffers_uint16_write_to_pe(pval, val);
+ } else {
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ }
+ } else { /* "rt" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* "rt" */
+ } else { /* descend "local_po" */
+ if (w == 0x70726f746f636f6c) { /* "protocol" */
+ buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 8);
+ if (mark != buf) {
+ int8_t val = 0;
+ static flatcc_json_parser_integral_symbol_f *symbolic_parsers[] = {
+ AzureIoTSecurity_Protocol_parse_json_enum,
+ listening_ports_local_AzureIoTSecurity_json_parser_enum,
+ listening_ports_global_json_parser_enum, 0 };
+ pval = (void *)((size_t)struct_base + 2);
+ buf = flatcc_json_parser_int8(ctx, (mark = buf), end, &val);
+ if (mark == buf) {
+ buf = flatcc_json_parser_symbolic_int8(ctx, (mark = buf), end, symbolic_parsers, &val);
+ if (buf == mark || buf == end) goto failed;
+ }
+ flatbuffers_int8_write_to_pe(pval, val);
+ } else {
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ }
+ } else { /* "protocol" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* "protocol" */
+ } /* descend "local_po" */
+ buf = flatcc_json_parser_object_end(ctx, buf, end , &more);
+ }
+ return buf;
+failed:
+ return flatcc_json_parser_set_error(ctx, buf, end, flatcc_json_parser_error_runtime);
+}
+
+static const char *AzureIoTSecurity_ListeningPortsCommon_parse_json_struct(flatcc_json_parser_t *ctx, const char *buf, const char *end, flatcc_builder_ref_t *result)
+{
+ void *pval;
+
+ *result = 0;
+ if (!(pval = flatcc_builder_start_struct(ctx->ctx, 4, 2))) goto failed;
+ buf = AzureIoTSecurity_ListeningPortsCommon_parse_json_struct_inline(ctx, buf, end, pval);
+ if (buf == end || !(*result = flatcc_builder_end_struct(ctx->ctx))) goto failed;
+ return buf;
+failed:
+ return flatcc_json_parser_set_error(ctx, buf, end, flatcc_json_parser_error_runtime);
+}
+
+static inline int AzureIoTSecurity_ListeningPortsCommon_parse_json_as_root(flatcc_builder_t *B, flatcc_json_parser_t *ctx, const char *buf, size_t bufsiz, int flags, const char *fid)
+{
+ return flatcc_json_parser_struct_as_root(B, ctx, buf, bufsiz, flags, fid, AzureIoTSecurity_ListeningPortsCommon_parse_json_struct);
+}
+
+static const char *AzureIoTSecurity_ListeningPortsV4_parse_json_struct_inline(flatcc_json_parser_t *ctx, const char *buf, const char *end, void *struct_base)
+{
+ int more;
+ flatcc_builder_ref_t ref;
+ void *pval;
+ const char *mark;
+ uint64_t w;
+
+ buf = flatcc_json_parser_object_start(ctx, buf, end, &more);
+ while (more) {
+ buf = flatcc_json_parser_symbol_start(ctx, buf, end);
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xffffffffffff0000) == 0x636f6d6d6f6e0000) { /* "common" */
+ buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 6);
+ if (mark != buf) {
+ pval = (void *)((size_t)struct_base + 4);
+ buf = AzureIoTSecurity_ListeningPortsCommon_parse_json_struct_inline(ctx, buf, end, pval);
+ } else {
+ goto pfguard1;
+ }
+ } else { /* "common" */
+ goto pfguard1;
+ } /* "common" */
+ goto endpfguard1;
+pfguard1:
+ if (w == 0x6c6f63616c5f6164) { /* descend "local_ad" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xffffffffff000000) == 0x6472657373000000) { /* "dress" */
+ buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 5);
+ if (mark != buf) {
+ uint32_t val = 0;
+ static flatcc_json_parser_integral_symbol_f *symbolic_parsers[] = {
+ listening_ports_local_AzureIoTSecurity_json_parser_enum,
+ listening_ports_global_json_parser_enum, 0 };
+ pval = (void *)((size_t)struct_base + 0);
+ buf = flatcc_json_parser_uint32(ctx, (mark = buf), end, &val);
+ if (mark == buf) {
+ buf = flatcc_json_parser_symbolic_uint32(ctx, (mark = buf), end, symbolic_parsers, &val);
+ if (buf == mark || buf == end) goto failed;
+ }
+ flatbuffers_uint32_write_to_pe(pval, val);
+ } else {
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ }
+ } else { /* "dress" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* "dress" */
+ } else { /* descend "local_ad" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* descend "local_ad" */
+endpfguard1:
+ (void)0;
+ buf = flatcc_json_parser_object_end(ctx, buf, end , &more);
+ }
+ return buf;
+failed:
+ return flatcc_json_parser_set_error(ctx, buf, end, flatcc_json_parser_error_runtime);
+}
+
+static const char *AzureIoTSecurity_ListeningPortsV4_parse_json_struct(flatcc_json_parser_t *ctx, const char *buf, const char *end, flatcc_builder_ref_t *result)
+{
+ void *pval;
+
+ *result = 0;
+ if (!(pval = flatcc_builder_start_struct(ctx->ctx, 8, 4))) goto failed;
+ buf = AzureIoTSecurity_ListeningPortsV4_parse_json_struct_inline(ctx, buf, end, pval);
+ if (buf == end || !(*result = flatcc_builder_end_struct(ctx->ctx))) goto failed;
+ return buf;
+failed:
+ return flatcc_json_parser_set_error(ctx, buf, end, flatcc_json_parser_error_runtime);
+}
+
+static inline int AzureIoTSecurity_ListeningPortsV4_parse_json_as_root(flatcc_builder_t *B, flatcc_json_parser_t *ctx, const char *buf, size_t bufsiz, int flags, const char *fid)
+{
+ return flatcc_json_parser_struct_as_root(B, ctx, buf, bufsiz, flags, fid, AzureIoTSecurity_ListeningPortsV4_parse_json_struct);
+}
+
+static const char *AzureIoTSecurity_ListeningPortsV6_parse_json_struct_inline(flatcc_json_parser_t *ctx, const char *buf, const char *end, void *struct_base)
+{
+ int more;
+ flatcc_builder_ref_t ref;
+ void *pval;
+ const char *mark;
+ uint64_t w;
+
+ buf = flatcc_json_parser_object_start(ctx, buf, end, &more);
+ while (more) {
+ buf = flatcc_json_parser_symbol_start(ctx, buf, end);
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xffffffffffff0000) == 0x636f6d6d6f6e0000) { /* "common" */
+ buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 6);
+ if (mark != buf) {
+ pval = (void *)((size_t)struct_base + 16);
+ buf = AzureIoTSecurity_ListeningPortsCommon_parse_json_struct_inline(ctx, buf, end, pval);
+ } else {
+ goto pfguard1;
+ }
+ } else { /* "common" */
+ goto pfguard1;
+ } /* "common" */
+ goto endpfguard1;
+pfguard1:
+ if (w == 0x6c6f63616c5f6164) { /* descend "local_ad" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xffffffffff000000) == 0x6472657373000000) { /* "dress" */
+ buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 5);
+ if (mark != buf) {
+ size_t count = 4;
+ uint32_t *base = (uint32_t *)((size_t)struct_base + 0);
+ buf = flatcc_json_parser_array_start(ctx, buf, end, &more);
+ while (more) {
+ uint32_t val = 0;
+ static flatcc_json_parser_integral_symbol_f *symbolic_parsers[] = {
+ listening_ports_local_AzureIoTSecurity_json_parser_enum,
+ listening_ports_global_json_parser_enum, 0 };
+ buf = flatcc_json_parser_uint32(ctx, (mark = buf), end, &val);
+ if (mark == buf) {
+ buf = flatcc_json_parser_symbolic_uint32(ctx, (mark = buf), end, symbolic_parsers, &val);
+ if (buf == mark || buf == end) goto failed;
+ }
+ if (count) {
+ flatbuffers_uint32_write_to_pe(base, val);
+ --count;
+ ++base;
+ } else if (!(ctx->flags & flatcc_json_parser_f_skip_array_overflow)) {
+ return flatcc_json_parser_set_error(ctx, buf, end, flatcc_json_parser_error_array_overflow);
+ }
+ buf = flatcc_json_parser_array_end(ctx, buf, end, &more);
+ }
+ if (count) {
+ if (ctx->flags & flatcc_json_parser_f_reject_array_underflow) {
+ return flatcc_json_parser_set_error(ctx, buf, end, flatcc_json_parser_error_array_underflow);
+ }
+ memset(base, 0, count * sizeof(*base));
+ }
+ } else {
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ }
+ } else { /* "dress" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* "dress" */
+ } else { /* descend "local_ad" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* descend "local_ad" */
+endpfguard1:
+ (void)0;
+ buf = flatcc_json_parser_object_end(ctx, buf, end , &more);
+ }
+ return buf;
+failed:
+ return flatcc_json_parser_set_error(ctx, buf, end, flatcc_json_parser_error_runtime);
+}
+
+static const char *AzureIoTSecurity_ListeningPortsV6_parse_json_struct(flatcc_json_parser_t *ctx, const char *buf, const char *end, flatcc_builder_ref_t *result)
+{
+ void *pval;
+
+ *result = 0;
+ if (!(pval = flatcc_builder_start_struct(ctx->ctx, 20, 4))) goto failed;
+ buf = AzureIoTSecurity_ListeningPortsV6_parse_json_struct_inline(ctx, buf, end, pval);
+ if (buf == end || !(*result = flatcc_builder_end_struct(ctx->ctx))) goto failed;
+ return buf;
+failed:
+ return flatcc_json_parser_set_error(ctx, buf, end, flatcc_json_parser_error_runtime);
+}
+
+static inline int AzureIoTSecurity_ListeningPortsV6_parse_json_as_root(flatcc_builder_t *B, flatcc_json_parser_t *ctx, const char *buf, size_t bufsiz, int flags, const char *fid)
+{
+ return flatcc_json_parser_struct_as_root(B, ctx, buf, bufsiz, flags, fid, AzureIoTSecurity_ListeningPortsV6_parse_json_struct);
+}
+
+static const char *AzureIoTSecurity_ListeningPorts_parse_json_table(flatcc_json_parser_t *ctx, const char *buf, const char *end, flatcc_builder_ref_t *result)
+{
+ int more;
+ void *pval;
+ flatcc_builder_ref_t ref, *pref;
+ const char *mark;
+ uint64_t w;
+
+ *result = 0;
+ if (flatcc_builder_start_table(ctx->ctx, 2)) goto failed;
+ buf = flatcc_json_parser_object_start(ctx, buf, end, &more);
+ while (more) {
+ buf = flatcc_json_parser_symbol_start(ctx, buf, end);
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x697076345f706f72) { /* descend "ipv4_por" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xffff000000000000) == 0x7473000000000000) { /* "ts" */
+ buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 2);
+ if (mark != buf) {
+ if (flatcc_builder_start_vector(ctx->ctx, 8, 4, UINT64_C(536870911))) goto failed;
+ buf = flatcc_json_parser_array_start(ctx, buf, end, &more);
+ while (more) {
+ if (!(pval = flatcc_builder_extend_vector(ctx->ctx, 1))) goto failed;
+ buf = AzureIoTSecurity_ListeningPortsV4_parse_json_struct_inline(ctx, buf, end, pval);
+ buf = flatcc_json_parser_array_end(ctx, buf, end, &more);
+ }
+ ref = flatcc_builder_end_vector(ctx->ctx);
+ if (!ref || !(pref = flatcc_builder_table_add_offset(ctx->ctx, 0))) goto failed;
+ *pref = ref;
+ } else {
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ }
+ } else { /* "ts" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* "ts" */
+ } else { /* descend "ipv4_por" */
+ if (w == 0x697076365f706f72) { /* descend "ipv6_por" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xffff000000000000) == 0x7473000000000000) { /* "ts" */
+ buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 2);
+ if (mark != buf) {
+ if (flatcc_builder_start_vector(ctx->ctx, 20, 4, UINT64_C(214748364))) goto failed;
+ buf = flatcc_json_parser_array_start(ctx, buf, end, &more);
+ while (more) {
+ if (!(pval = flatcc_builder_extend_vector(ctx->ctx, 1))) goto failed;
+ buf = AzureIoTSecurity_ListeningPortsV6_parse_json_struct_inline(ctx, buf, end, pval);
+ buf = flatcc_json_parser_array_end(ctx, buf, end, &more);
+ }
+ ref = flatcc_builder_end_vector(ctx->ctx);
+ if (!ref || !(pref = flatcc_builder_table_add_offset(ctx->ctx, 1))) goto failed;
+ *pref = ref;
+ } else {
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ }
+ } else { /* "ts" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* "ts" */
+ } else { /* descend "ipv6_por" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* descend "ipv6_por" */
+ } /* descend "ipv4_por" */
+ buf = flatcc_json_parser_object_end(ctx, buf, end, &more);
+ }
+ if (ctx->error) goto failed;
+ if (!(*result = flatcc_builder_end_table(ctx->ctx))) goto failed;
+ return buf;
+failed:
+ return flatcc_json_parser_set_error(ctx, buf, end, flatcc_json_parser_error_runtime);
+}
+
+static inline int AzureIoTSecurity_ListeningPorts_parse_json_as_root(flatcc_builder_t *B, flatcc_json_parser_t *ctx, const char *buf, size_t bufsiz, int flags, const char *fid)
+{
+ return flatcc_json_parser_table_as_root(B, ctx, buf, bufsiz, flags, fid, AzureIoTSecurity_ListeningPorts_parse_json_table);
+}
+
+static const char *listening_ports_local_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_type, uint64_t *value, int *aggregate)
+{
+ /* Scope has no enum / union types to look up. */
+ return buf; /* unmatched; */
+}
+
+static const char *listening_ports_local_AzureIoTSecurity_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_type, uint64_t *value, int *aggregate)
+{
+ const char *unmatched = buf;
+ const char *mark;
+ uint64_t w;
+
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x50726f746f636f6c) { /* "Protocol" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 8);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_Protocol_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* "Protocol" */
+ return unmatched;
+ } /* "Protocol" */
+ return buf;
+}
+
+static const char *listening_ports_global_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_type, uint64_t *value, int *aggregate)
+{
+ const char *unmatched = buf;
+ const char *mark;
+ uint64_t w;
+
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x417a757265496f54) { /* descend "AzureIoT" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x5365637572697479) { /* descend "Security" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x2e50726f746f636f) { /* descend ".Protoco" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xff00000000000000) == 0x6c00000000000000) { /* "l" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 1);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_Protocol_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* "l" */
+ return unmatched;
+ } /* "l" */
+ } else { /* descend ".Protoco" */
+ return unmatched;
+ } /* descend ".Protoco" */
+ } else { /* descend "Security" */
+ return unmatched;
+ } /* descend "Security" */
+ } else { /* descend "AzureIoT" */
+ return unmatched;
+ } /* descend "AzureIoT" */
+ return buf;
+}
+
+#include "flatcc/flatcc_epilogue.h"
+#endif /* LISTENING_PORTS_JSON_PARSER_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/listening_ports_json_printer.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/listening_ports_json_printer.h
new file mode 100644
index 00000000..83556521
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/listening_ports_json_printer.h
@@ -0,0 +1,62 @@
+#ifndef LISTENING_PORTS_JSON_PRINTER_H
+#define LISTENING_PORTS_JSON_PRINTER_H
+
+/* Generated by flatcc 0.6.1-dev FlatBuffers schema compiler for C by dvide.com */
+
+#include "flatcc/flatcc_json_printer.h"
+#ifndef PROTOCOL_JSON_PRINTER_H
+#include "protocol_json_printer.h"
+#endif
+#include "flatcc/flatcc_prologue.h"
+
+static void AzureIoTSecurity_ListeningPortsCommon_print_json_struct(flatcc_json_printer_t *ctx, const void *p);
+static void AzureIoTSecurity_ListeningPortsV4_print_json_struct(flatcc_json_printer_t *ctx, const void *p);
+static void AzureIoTSecurity_ListeningPortsV6_print_json_struct(flatcc_json_printer_t *ctx, const void *p);
+static void AzureIoTSecurity_ListeningPorts_print_json_table(flatcc_json_printer_t *ctx, flatcc_json_printer_table_descriptor_t *td);
+
+static void AzureIoTSecurity_ListeningPortsCommon_print_json_struct(flatcc_json_printer_t *ctx, const void *p)
+{
+ flatcc_json_printer_uint16_struct_field(ctx, 0, p, 0, "local_port", 10);
+ flatcc_json_printer_int8_enum_struct_field(ctx, 1, p, 2, "protocol", 8, AzureIoTSecurity_Protocol_print_json_enum);
+}
+
+static inline int AzureIoTSecurity_ListeningPortsCommon_print_json_as_root(flatcc_json_printer_t *ctx, const void *buf, size_t bufsiz, const char *fid)
+{
+ return flatcc_json_printer_struct_as_root(ctx, buf, bufsiz, fid, AzureIoTSecurity_ListeningPortsCommon_print_json_struct);
+}
+
+static void AzureIoTSecurity_ListeningPortsV4_print_json_struct(flatcc_json_printer_t *ctx, const void *p)
+{
+ flatcc_json_printer_uint32_struct_field(ctx, 0, p, 0, "local_address", 13);
+ flatcc_json_printer_embedded_struct_field(ctx, 1, p, 4, "common", 6, AzureIoTSecurity_ListeningPortsCommon_print_json_struct);
+}
+
+static inline int AzureIoTSecurity_ListeningPortsV4_print_json_as_root(flatcc_json_printer_t *ctx, const void *buf, size_t bufsiz, const char *fid)
+{
+ return flatcc_json_printer_struct_as_root(ctx, buf, bufsiz, fid, AzureIoTSecurity_ListeningPortsV4_print_json_struct);
+}
+
+static void AzureIoTSecurity_ListeningPortsV6_print_json_struct(flatcc_json_printer_t *ctx, const void *p)
+{
+ flatcc_json_printer_uint32_array_struct_field(ctx, 0, p, 0, "local_address", 13, 4);
+ flatcc_json_printer_embedded_struct_field(ctx, 1, p, 16, "common", 6, AzureIoTSecurity_ListeningPortsCommon_print_json_struct);
+}
+
+static inline int AzureIoTSecurity_ListeningPortsV6_print_json_as_root(flatcc_json_printer_t *ctx, const void *buf, size_t bufsiz, const char *fid)
+{
+ return flatcc_json_printer_struct_as_root(ctx, buf, bufsiz, fid, AzureIoTSecurity_ListeningPortsV6_print_json_struct);
+}
+
+static void AzureIoTSecurity_ListeningPorts_print_json_table(flatcc_json_printer_t *ctx, flatcc_json_printer_table_descriptor_t *td)
+{
+ flatcc_json_printer_struct_vector_field(ctx, td, 0, "ipv4_ports", 10, 8, AzureIoTSecurity_ListeningPortsV4_print_json_struct);
+ flatcc_json_printer_struct_vector_field(ctx, td, 1, "ipv6_ports", 10, 20, AzureIoTSecurity_ListeningPortsV6_print_json_struct);
+}
+
+static inline int AzureIoTSecurity_ListeningPorts_print_json_as_root(flatcc_json_printer_t *ctx, const void *buf, size_t bufsiz, const char *fid)
+{
+ return flatcc_json_printer_table_as_root(ctx, buf, bufsiz, fid, AzureIoTSecurity_ListeningPorts_print_json_table);
+}
+
+#include "flatcc/flatcc_epilogue.h"
+#endif /* LISTENING_PORTS_JSON_PRINTER_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/log_builder.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/log_builder.h
new file mode 100644
index 00000000..9043392f
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/log_builder.h
@@ -0,0 +1,101 @@
+#ifndef LOG_BUILDER_H
+#define LOG_BUILDER_H
+
+/* Generated by flatcc 0.6.1-dev FlatBuffers schema compiler for C by dvide.com */
+
+#ifndef LOG_READER_H
+#include "log_reader.h"
+#endif
+#ifndef FLATBUFFERS_COMMON_BUILDER_H
+#include "flatbuffers_common_builder.h"
+#endif
+#include "flatcc/flatcc_prologue.h"
+#ifndef flatbuffers_identifier
+#define flatbuffers_identifier 0
+#endif
+#ifndef flatbuffers_extension
+#define flatbuffers_extension ".bin"
+#endif
+
+#define __AzureIoTSecurity_Level_formal_args , AzureIoTSecurity_Level_enum_t v0
+#define __AzureIoTSecurity_Level_call_args , v0
+__flatbuffers_build_scalar(flatbuffers_, AzureIoTSecurity_Level, AzureIoTSecurity_Level_enum_t)
+
+static const flatbuffers_voffset_t __AzureIoTSecurity_Record_required[] = { 0, 4, 0 };
+typedef flatbuffers_ref_t AzureIoTSecurity_Record_ref_t;
+static AzureIoTSecurity_Record_ref_t AzureIoTSecurity_Record_clone(flatbuffers_builder_t *B, AzureIoTSecurity_Record_table_t t);
+__flatbuffers_build_table(flatbuffers_, AzureIoTSecurity_Record, 5)
+
+static const flatbuffers_voffset_t __AzureIoTSecurity_Log_required[] = { 0 };
+typedef flatbuffers_ref_t AzureIoTSecurity_Log_ref_t;
+static AzureIoTSecurity_Log_ref_t AzureIoTSecurity_Log_clone(flatbuffers_builder_t *B, AzureIoTSecurity_Log_table_t t);
+__flatbuffers_build_table(flatbuffers_, AzureIoTSecurity_Log, 1)
+
+#define __AzureIoTSecurity_Record_formal_args ,\
+ flatbuffers_string_ref_t v0, AzureIoTSecurity_Level_enum_t v1, uint64_t v2, uint32_t v3, flatbuffers_string_ref_t v4
+#define __AzureIoTSecurity_Record_call_args ,\
+ v0, v1, v2, v3, v4
+static inline AzureIoTSecurity_Record_ref_t AzureIoTSecurity_Record_create(flatbuffers_builder_t *B __AzureIoTSecurity_Record_formal_args);
+__flatbuffers_build_table_prolog(flatbuffers_, AzureIoTSecurity_Record, AzureIoTSecurity_Record_file_identifier, AzureIoTSecurity_Record_type_identifier)
+
+#define __AzureIoTSecurity_Log_formal_args , AzureIoTSecurity_Record_vec_ref_t v0
+#define __AzureIoTSecurity_Log_call_args , v0
+static inline AzureIoTSecurity_Log_ref_t AzureIoTSecurity_Log_create(flatbuffers_builder_t *B __AzureIoTSecurity_Log_formal_args);
+__flatbuffers_build_table_prolog(flatbuffers_, AzureIoTSecurity_Log, AzureIoTSecurity_Log_file_identifier, AzureIoTSecurity_Log_type_identifier)
+
+__flatbuffers_build_string_field(0, flatbuffers_, AzureIoTSecurity_Record_message, AzureIoTSecurity_Record)
+__flatbuffers_build_scalar_field(1, flatbuffers_, AzureIoTSecurity_Record_level, AzureIoTSecurity_Level, AzureIoTSecurity_Level_enum_t, 1, 1, INT8_C(0), AzureIoTSecurity_Record)
+__flatbuffers_build_scalar_field(2, flatbuffers_, AzureIoTSecurity_Record_timestamp, flatbuffers_uint64, uint64_t, 8, 8, UINT64_C(0), AzureIoTSecurity_Record)
+__flatbuffers_build_scalar_field(3, flatbuffers_, AzureIoTSecurity_Record_line, flatbuffers_uint32, uint32_t, 4, 4, UINT32_C(0), AzureIoTSecurity_Record)
+__flatbuffers_build_string_field(4, flatbuffers_, AzureIoTSecurity_Record_filename, AzureIoTSecurity_Record)
+
+static inline AzureIoTSecurity_Record_ref_t AzureIoTSecurity_Record_create(flatbuffers_builder_t *B __AzureIoTSecurity_Record_formal_args)
+{
+ if (AzureIoTSecurity_Record_start(B)
+ || AzureIoTSecurity_Record_timestamp_add(B, v2)
+ || AzureIoTSecurity_Record_message_add(B, v0)
+ || AzureIoTSecurity_Record_line_add(B, v3)
+ || AzureIoTSecurity_Record_filename_add(B, v4)
+ || AzureIoTSecurity_Record_level_add(B, v1)) {
+ return 0;
+ }
+ return AzureIoTSecurity_Record_end(B);
+}
+
+static AzureIoTSecurity_Record_ref_t AzureIoTSecurity_Record_clone(flatbuffers_builder_t *B, AzureIoTSecurity_Record_table_t t)
+{
+ __flatbuffers_memoize_begin(B, t);
+ if (AzureIoTSecurity_Record_start(B)
+ || AzureIoTSecurity_Record_timestamp_pick(B, t)
+ || AzureIoTSecurity_Record_message_pick(B, t)
+ || AzureIoTSecurity_Record_line_pick(B, t)
+ || AzureIoTSecurity_Record_filename_pick(B, t)
+ || AzureIoTSecurity_Record_level_pick(B, t)) {
+ return 0;
+ }
+ __flatbuffers_memoize_end(B, t, AzureIoTSecurity_Record_end(B));
+}
+
+__flatbuffers_build_table_vector_field(0, flatbuffers_, AzureIoTSecurity_Log_logs, AzureIoTSecurity_Record, AzureIoTSecurity_Log)
+
+static inline AzureIoTSecurity_Log_ref_t AzureIoTSecurity_Log_create(flatbuffers_builder_t *B __AzureIoTSecurity_Log_formal_args)
+{
+ if (AzureIoTSecurity_Log_start(B)
+ || AzureIoTSecurity_Log_logs_add(B, v0)) {
+ return 0;
+ }
+ return AzureIoTSecurity_Log_end(B);
+}
+
+static AzureIoTSecurity_Log_ref_t AzureIoTSecurity_Log_clone(flatbuffers_builder_t *B, AzureIoTSecurity_Log_table_t t)
+{
+ __flatbuffers_memoize_begin(B, t);
+ if (AzureIoTSecurity_Log_start(B)
+ || AzureIoTSecurity_Log_logs_pick(B, t)) {
+ return 0;
+ }
+ __flatbuffers_memoize_end(B, t, AzureIoTSecurity_Log_end(B));
+}
+
+#include "flatcc/flatcc_epilogue.h"
+#endif /* LOG_BUILDER_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/log_json_parser.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/log_json_parser.h
new file mode 100644
index 00000000..b52ba74e
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/log_json_parser.h
@@ -0,0 +1,348 @@
+#ifndef LOG_JSON_PARSER_H
+#define LOG_JSON_PARSER_H
+
+/* Generated by flatcc 0.6.1-dev FlatBuffers schema compiler for C by dvide.com */
+
+#include "flatcc/flatcc_json_parser.h"
+#include "flatcc/flatcc_prologue.h"
+
+static const char *AzureIoTSecurity_Level_parse_json_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_type, uint64_t *value, int *aggregate);
+static const char *AzureIoTSecurity_Record_parse_json_table(flatcc_json_parser_t *ctx, const char *buf, const char *end, flatcc_builder_ref_t *result);
+static const char *AzureIoTSecurity_Log_parse_json_table(flatcc_json_parser_t *ctx, const char *buf, const char *end, flatcc_builder_ref_t *result);
+static const char *log_local_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+int *value_type, uint64_t *value, int *aggregate);
+static const char *log_local_AzureIoTSecurity_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+int *value_type, uint64_t *value, int *aggregate);
+static const char *log_global_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_type, uint64_t *value, int *aggregate);
+
+static const char *AzureIoTSecurity_Level_parse_json_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_sign, uint64_t *value, int *aggregate)
+{
+ const char *unmatched = buf;
+ const char *mark;
+ uint64_t w;
+
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w < 0x464154414c000000) { /* branch "FATAL" */
+ if ((w & 0xffffffffff000000) == 0x4552524f52000000) { /* "ERROR" */
+ buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 5, aggregate);
+ if (buf != mark) {
+ *value = UINT64_C(2), *value_sign = 0;
+ } else {
+ return unmatched;
+ }
+ } else { /* "ERROR" */
+ if ((w & 0xffffffffff000000) == 0x4445425547000000) { /* "DEBUG" */
+ buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 5, aggregate);
+ if (buf != mark) {
+ *value = UINT64_C(5), *value_sign = 0;
+ } else {
+ return unmatched;
+ }
+ } else { /* "DEBUG" */
+ return unmatched;
+ } /* "DEBUG" */
+ } /* "ERROR" */
+ } else { /* branch "FATAL" */
+ if (w < 0x494e464f00000000) { /* branch "INFO" */
+ if ((w & 0xffffffffff000000) == 0x464154414c000000) { /* "FATAL" */
+ buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 5, aggregate);
+ if (buf != mark) {
+ *value = UINT64_C(1), *value_sign = 0;
+ } else {
+ return unmatched;
+ }
+ } else { /* "FATAL" */
+ return unmatched;
+ } /* "FATAL" */
+ } else { /* branch "INFO" */
+ if (w < 0x4e4f545345540000) { /* branch "NOTSET" */
+ if ((w & 0xffffffff00000000) == 0x494e464f00000000) { /* "INFO" */
+ buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 4, aggregate);
+ if (buf != mark) {
+ *value = UINT64_C(4), *value_sign = 0;
+ } else {
+ return unmatched;
+ }
+ } else { /* "INFO" */
+ return unmatched;
+ } /* "INFO" */
+ } else { /* branch "NOTSET" */
+ if ((w & 0xffffffff00000000) == 0x5741524e00000000) { /* "WARN" */
+ buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 4, aggregate);
+ if (buf != mark) {
+ *value = UINT64_C(3), *value_sign = 0;
+ } else {
+ return unmatched;
+ }
+ } else { /* "WARN" */
+ if ((w & 0xffffffffffff0000) == 0x4e4f545345540000) { /* "NOTSET" */
+ buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 6, aggregate);
+ if (buf != mark) {
+ *value = UINT64_C(0), *value_sign = 0;
+ } else {
+ return unmatched;
+ }
+ } else { /* "NOTSET" */
+ return unmatched;
+ } /* "NOTSET" */
+ } /* "WARN" */
+ } /* branch "NOTSET" */
+ } /* branch "INFO" */
+ } /* branch "FATAL" */
+ return buf;
+}
+
+static const char *AzureIoTSecurity_Record_parse_json_table(flatcc_json_parser_t *ctx, const char *buf, const char *end, flatcc_builder_ref_t *result)
+{
+ int more;
+ void *pval;
+ flatcc_builder_ref_t ref, *pref;
+ const char *mark;
+ uint64_t w;
+
+ *result = 0;
+ if (flatcc_builder_start_table(ctx->ctx, 5)) goto failed;
+ buf = flatcc_json_parser_object_start(ctx, buf, end, &more);
+ while (more) {
+ buf = flatcc_json_parser_symbol_start(ctx, buf, end);
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w < 0x6c696e6500000000) { /* branch "line" */
+ if ((w & 0xffffffffff000000) == 0x6c6576656c000000) { /* "level" */
+ buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 5);
+ if (mark != buf) {
+ int8_t val = 0;
+ static flatcc_json_parser_integral_symbol_f *symbolic_parsers[] = {
+ AzureIoTSecurity_Level_parse_json_enum,
+ log_local_AzureIoTSecurity_json_parser_enum,
+ log_global_json_parser_enum, 0 };
+ buf = flatcc_json_parser_int8(ctx, (mark = buf), end, &val);
+ if (mark == buf) {
+ buf = flatcc_json_parser_symbolic_int8(ctx, (mark = buf), end, symbolic_parsers, &val);
+ if (buf == mark || buf == end) goto failed;
+ }
+ if (val != 0 || (ctx->flags & flatcc_json_parser_f_force_add)) {
+ if (!(pval = flatcc_builder_table_add(ctx->ctx, 1, 1, 1))) goto failed;
+ flatbuffers_int8_write_to_pe(pval, val);
+ }
+ } else {
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ }
+ } else { /* "level" */
+ if (w == 0x66696c656e616d65) { /* "filename" */
+ buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 8);
+ if (mark != buf) {
+ buf = flatcc_json_parser_build_string(ctx, buf, end, &ref);
+ if (!ref || !(pref = flatcc_builder_table_add_offset(ctx->ctx, 4))) goto failed;
+ *pref = ref;
+ } else {
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ }
+ } else { /* "filename" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* "filename" */
+ } /* "level" */
+ } else { /* branch "line" */
+ if (w < 0x6d65737361676500) { /* branch "message" */
+ if ((w & 0xffffffff00000000) == 0x6c696e6500000000) { /* "line" */
+ buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 4);
+ if (mark != buf) {
+ uint32_t val = 0;
+ static flatcc_json_parser_integral_symbol_f *symbolic_parsers[] = {
+ log_local_AzureIoTSecurity_json_parser_enum,
+ log_global_json_parser_enum, 0 };
+ buf = flatcc_json_parser_uint32(ctx, (mark = buf), end, &val);
+ if (mark == buf) {
+ buf = flatcc_json_parser_symbolic_uint32(ctx, (mark = buf), end, symbolic_parsers, &val);
+ if (buf == mark || buf == end) goto failed;
+ }
+ if (val != 0 || (ctx->flags & flatcc_json_parser_f_force_add)) {
+ if (!(pval = flatcc_builder_table_add(ctx->ctx, 3, 4, 4))) goto failed;
+ flatbuffers_uint32_write_to_pe(pval, val);
+ }
+ } else {
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ }
+ } else { /* "line" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* "line" */
+ } else { /* branch "message" */
+ if ((w & 0xffffffffffffff00) == 0x6d65737361676500) { /* "message" */
+ buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 7);
+ if (mark != buf) {
+ buf = flatcc_json_parser_build_string(ctx, buf, end, &ref);
+ if (!ref || !(pref = flatcc_builder_table_add_offset(ctx->ctx, 0))) goto failed;
+ *pref = ref;
+ } else {
+ goto pfguard1;
+ }
+ } else { /* "message" */
+ goto pfguard1;
+ } /* "message" */
+ goto endpfguard1;
+pfguard1:
+ if (w == 0x74696d657374616d) { /* descend "timestam" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xff00000000000000) == 0x7000000000000000) { /* "p" */
+ buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 1);
+ if (mark != buf) {
+ uint64_t val = 0;
+ static flatcc_json_parser_integral_symbol_f *symbolic_parsers[] = {
+ log_local_AzureIoTSecurity_json_parser_enum,
+ log_global_json_parser_enum, 0 };
+ buf = flatcc_json_parser_uint64(ctx, (mark = buf), end, &val);
+ if (mark == buf) {
+ buf = flatcc_json_parser_symbolic_uint64(ctx, (mark = buf), end, symbolic_parsers, &val);
+ if (buf == mark || buf == end) goto failed;
+ }
+ if (val != 0 || (ctx->flags & flatcc_json_parser_f_force_add)) {
+ if (!(pval = flatcc_builder_table_add(ctx->ctx, 2, 8, 8))) goto failed;
+ flatbuffers_uint64_write_to_pe(pval, val);
+ }
+ } else {
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ }
+ } else { /* "p" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* "p" */
+ } else { /* descend "timestam" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* descend "timestam" */
+endpfguard1:
+ (void)0;
+ } /* branch "message" */
+ } /* branch "line" */
+ buf = flatcc_json_parser_object_end(ctx, buf, end, &more);
+ }
+ if (ctx->error) goto failed;
+ if (!flatcc_builder_check_required_field(ctx->ctx, 4)
+ || !flatcc_builder_check_required_field(ctx->ctx, 0)
+ ) {
+ buf = flatcc_json_parser_set_error(ctx, buf, end, flatcc_json_parser_error_required);
+ goto failed;
+ }
+ if (!(*result = flatcc_builder_end_table(ctx->ctx))) goto failed;
+ return buf;
+failed:
+ return flatcc_json_parser_set_error(ctx, buf, end, flatcc_json_parser_error_runtime);
+}
+
+static inline int AzureIoTSecurity_Record_parse_json_as_root(flatcc_builder_t *B, flatcc_json_parser_t *ctx, const char *buf, size_t bufsiz, int flags, const char *fid)
+{
+ return flatcc_json_parser_table_as_root(B, ctx, buf, bufsiz, flags, fid, AzureIoTSecurity_Record_parse_json_table);
+}
+
+static const char *AzureIoTSecurity_Log_parse_json_table(flatcc_json_parser_t *ctx, const char *buf, const char *end, flatcc_builder_ref_t *result)
+{
+ int more;
+ void *pval;
+ flatcc_builder_ref_t ref, *pref;
+ const char *mark;
+ uint64_t w;
+
+ *result = 0;
+ if (flatcc_builder_start_table(ctx->ctx, 1)) goto failed;
+ buf = flatcc_json_parser_object_start(ctx, buf, end, &more);
+ while (more) {
+ buf = flatcc_json_parser_symbol_start(ctx, buf, end);
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xffffffff00000000) == 0x6c6f677300000000) { /* "logs" */
+ buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 4);
+ if (mark != buf) {
+ if (flatcc_builder_start_offset_vector(ctx->ctx)) goto failed;
+ buf = flatcc_json_parser_array_start(ctx, buf, end, &more);
+ while (more) {
+ buf = AzureIoTSecurity_Record_parse_json_table(ctx, buf, end, &ref);
+ if (!ref || !(pref = flatcc_builder_extend_offset_vector(ctx->ctx, 1))) goto failed;
+ *pref = ref;
+ buf = flatcc_json_parser_array_end(ctx, buf, end, &more);
+ }
+ ref = flatcc_builder_end_offset_vector(ctx->ctx);
+ if (!ref || !(pref = flatcc_builder_table_add_offset(ctx->ctx, 0))) goto failed;
+ *pref = ref;
+ } else {
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ }
+ } else { /* "logs" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* "logs" */
+ buf = flatcc_json_parser_object_end(ctx, buf, end, &more);
+ }
+ if (ctx->error) goto failed;
+ if (!(*result = flatcc_builder_end_table(ctx->ctx))) goto failed;
+ return buf;
+failed:
+ return flatcc_json_parser_set_error(ctx, buf, end, flatcc_json_parser_error_runtime);
+}
+
+static inline int AzureIoTSecurity_Log_parse_json_as_root(flatcc_builder_t *B, flatcc_json_parser_t *ctx, const char *buf, size_t bufsiz, int flags, const char *fid)
+{
+ return flatcc_json_parser_table_as_root(B, ctx, buf, bufsiz, flags, fid, AzureIoTSecurity_Log_parse_json_table);
+}
+
+static const char *log_local_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_type, uint64_t *value, int *aggregate)
+{
+ /* Scope has no enum / union types to look up. */
+ return buf; /* unmatched; */
+}
+
+static const char *log_local_AzureIoTSecurity_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_type, uint64_t *value, int *aggregate)
+{
+ const char *unmatched = buf;
+ const char *mark;
+ uint64_t w;
+
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xffffffffff000000) == 0x4c6576656c000000) { /* "Level" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 5);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_Level_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* "Level" */
+ return unmatched;
+ } /* "Level" */
+ return buf;
+}
+
+static const char *log_global_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_type, uint64_t *value, int *aggregate)
+{
+ const char *unmatched = buf;
+ const char *mark;
+ uint64_t w;
+
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x417a757265496f54) { /* descend "AzureIoT" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x5365637572697479) { /* descend "Security" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xffffffffffff0000) == 0x2e4c6576656c0000) { /* ".Level" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 6);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_Level_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* ".Level" */
+ return unmatched;
+ } /* ".Level" */
+ } else { /* descend "Security" */
+ return unmatched;
+ } /* descend "Security" */
+ } else { /* descend "AzureIoT" */
+ return unmatched;
+ } /* descend "AzureIoT" */
+ return buf;
+}
+
+#include "flatcc/flatcc_epilogue.h"
+#endif /* LOG_JSON_PARSER_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/log_json_printer.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/log_json_printer.h
new file mode 100644
index 00000000..0c0eacba
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/log_json_printer.h
@@ -0,0 +1,51 @@
+#ifndef LOG_JSON_PRINTER_H
+#define LOG_JSON_PRINTER_H
+
+/* Generated by flatcc 0.6.1-dev FlatBuffers schema compiler for C by dvide.com */
+
+#include "flatcc/flatcc_json_printer.h"
+#include "flatcc/flatcc_prologue.h"
+
+static void AzureIoTSecurity_Record_print_json_table(flatcc_json_printer_t *ctx, flatcc_json_printer_table_descriptor_t *td);
+static void AzureIoTSecurity_Log_print_json_table(flatcc_json_printer_t *ctx, flatcc_json_printer_table_descriptor_t *td);
+
+static void AzureIoTSecurity_Level_print_json_enum(flatcc_json_printer_t *ctx, int8_t v)
+{
+
+ switch (v) {
+ case 0: flatcc_json_printer_enum(ctx, "NOTSET", 6); break;
+ case 1: flatcc_json_printer_enum(ctx, "FATAL", 5); break;
+ case 2: flatcc_json_printer_enum(ctx, "ERROR", 5); break;
+ case 3: flatcc_json_printer_enum(ctx, "WARN", 4); break;
+ case 4: flatcc_json_printer_enum(ctx, "INFO", 4); break;
+ case 5: flatcc_json_printer_enum(ctx, "DEBUG", 5); break;
+ default: flatcc_json_printer_int8(ctx, v); break;
+ }
+}
+
+static void AzureIoTSecurity_Record_print_json_table(flatcc_json_printer_t *ctx, flatcc_json_printer_table_descriptor_t *td)
+{
+ flatcc_json_printer_string_field(ctx, td, 0, "message", 7);
+ flatcc_json_printer_int8_enum_field(ctx, td, 1, "level", 5, 0, AzureIoTSecurity_Level_print_json_enum);
+ flatcc_json_printer_uint64_field(ctx, td, 2, "timestamp", 9, 0);
+ flatcc_json_printer_uint32_field(ctx, td, 3, "line", 4, 0);
+ flatcc_json_printer_string_field(ctx, td, 4, "filename", 8);
+}
+
+static inline int AzureIoTSecurity_Record_print_json_as_root(flatcc_json_printer_t *ctx, const void *buf, size_t bufsiz, const char *fid)
+{
+ return flatcc_json_printer_table_as_root(ctx, buf, bufsiz, fid, AzureIoTSecurity_Record_print_json_table);
+}
+
+static void AzureIoTSecurity_Log_print_json_table(flatcc_json_printer_t *ctx, flatcc_json_printer_table_descriptor_t *td)
+{
+ flatcc_json_printer_table_vector_field(ctx, td, 0, "logs", 4, AzureIoTSecurity_Record_print_json_table);
+}
+
+static inline int AzureIoTSecurity_Log_print_json_as_root(flatcc_json_printer_t *ctx, const void *buf, size_t bufsiz, const char *fid)
+{
+ return flatcc_json_printer_table_as_root(ctx, buf, bufsiz, fid, AzureIoTSecurity_Log_print_json_table);
+}
+
+#include "flatcc/flatcc_epilogue.h"
+#endif /* LOG_JSON_PRINTER_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/log_reader.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/log_reader.h
new file mode 100644
index 00000000..045c7ce5
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/log_reader.h
@@ -0,0 +1,116 @@
+#ifndef LOG_READER_H
+#define LOG_READER_H
+
+/* Generated by flatcc 0.6.1-dev FlatBuffers schema compiler for C by dvide.com */
+
+#ifndef FLATBUFFERS_COMMON_READER_H
+#include "flatbuffers_common_reader.h"
+#endif
+#include "flatcc/flatcc_flatbuffers.h"
+#ifndef __alignas_is_defined
+#include
+#endif
+#include "flatcc/flatcc_prologue.h"
+#ifndef flatbuffers_identifier
+#define flatbuffers_identifier 0
+#endif
+#ifndef flatbuffers_extension
+#define flatbuffers_extension ".bin"
+#endif
+
+
+typedef const struct AzureIoTSecurity_Record_table *AzureIoTSecurity_Record_table_t;
+typedef struct AzureIoTSecurity_Record_table *AzureIoTSecurity_Record_mutable_table_t;
+typedef const flatbuffers_uoffset_t *AzureIoTSecurity_Record_vec_t;
+typedef flatbuffers_uoffset_t *AzureIoTSecurity_Record_mutable_vec_t;
+typedef const struct AzureIoTSecurity_Log_table *AzureIoTSecurity_Log_table_t;
+typedef struct AzureIoTSecurity_Log_table *AzureIoTSecurity_Log_mutable_table_t;
+typedef const flatbuffers_uoffset_t *AzureIoTSecurity_Log_vec_t;
+typedef flatbuffers_uoffset_t *AzureIoTSecurity_Log_mutable_vec_t;
+#ifndef AzureIoTSecurity_Record_file_identifier
+#define AzureIoTSecurity_Record_file_identifier flatbuffers_identifier
+#endif
+/* deprecated, use AzureIoTSecurity_Record_file_identifier */
+#ifndef AzureIoTSecurity_Record_identifier
+#define AzureIoTSecurity_Record_identifier flatbuffers_identifier
+#endif
+#define AzureIoTSecurity_Record_type_hash ((flatbuffers_thash_t)0xb5e0a8b5)
+#define AzureIoTSecurity_Record_type_identifier "\xb5\xa8\xe0\xb5"
+#ifndef AzureIoTSecurity_Log_file_identifier
+#define AzureIoTSecurity_Log_file_identifier flatbuffers_identifier
+#endif
+/* deprecated, use AzureIoTSecurity_Log_file_identifier */
+#ifndef AzureIoTSecurity_Log_identifier
+#define AzureIoTSecurity_Log_identifier flatbuffers_identifier
+#endif
+#define AzureIoTSecurity_Log_type_hash ((flatbuffers_thash_t)0x4ee428f2)
+#define AzureIoTSecurity_Log_type_identifier "\xf2\x28\xe4\x4e"
+
+typedef int8_t AzureIoTSecurity_Level_enum_t;
+__flatbuffers_define_integer_type(AzureIoTSecurity_Level, AzureIoTSecurity_Level_enum_t, 8)
+#define AzureIoTSecurity_Level_NOTSET ((AzureIoTSecurity_Level_enum_t)INT8_C(0))
+#define AzureIoTSecurity_Level_FATAL ((AzureIoTSecurity_Level_enum_t)INT8_C(1))
+#define AzureIoTSecurity_Level_ERROR ((AzureIoTSecurity_Level_enum_t)INT8_C(2))
+#define AzureIoTSecurity_Level_WARN ((AzureIoTSecurity_Level_enum_t)INT8_C(3))
+#define AzureIoTSecurity_Level_INFO ((AzureIoTSecurity_Level_enum_t)INT8_C(4))
+#define AzureIoTSecurity_Level_DEBUG ((AzureIoTSecurity_Level_enum_t)INT8_C(5))
+
+static inline const char *AzureIoTSecurity_Level_name(AzureIoTSecurity_Level_enum_t value)
+{
+ switch (value) {
+ case AzureIoTSecurity_Level_NOTSET: return "NOTSET";
+ case AzureIoTSecurity_Level_FATAL: return "FATAL";
+ case AzureIoTSecurity_Level_ERROR: return "ERROR";
+ case AzureIoTSecurity_Level_WARN: return "WARN";
+ case AzureIoTSecurity_Level_INFO: return "INFO";
+ case AzureIoTSecurity_Level_DEBUG: return "DEBUG";
+ default: return "";
+ }
+}
+
+static inline int AzureIoTSecurity_Level_is_known_value(AzureIoTSecurity_Level_enum_t value)
+{
+ switch (value) {
+ case AzureIoTSecurity_Level_NOTSET: return 1;
+ case AzureIoTSecurity_Level_FATAL: return 1;
+ case AzureIoTSecurity_Level_ERROR: return 1;
+ case AzureIoTSecurity_Level_WARN: return 1;
+ case AzureIoTSecurity_Level_INFO: return 1;
+ case AzureIoTSecurity_Level_DEBUG: return 1;
+ default: return 0;
+ }
+}
+
+
+
+struct AzureIoTSecurity_Record_table { uint8_t unused__; };
+
+static inline size_t AzureIoTSecurity_Record_vec_len(AzureIoTSecurity_Record_vec_t vec)
+__flatbuffers_vec_len(vec)
+static inline AzureIoTSecurity_Record_table_t AzureIoTSecurity_Record_vec_at(AzureIoTSecurity_Record_vec_t vec, size_t i)
+__flatbuffers_offset_vec_at(AzureIoTSecurity_Record_table_t, vec, i, 0)
+__flatbuffers_table_as_root(AzureIoTSecurity_Record)
+
+/** The formatted log message */
+__flatbuffers_define_string_field(0, AzureIoTSecurity_Record, message, 1)
+/** The level of the record defined in Level enum */
+__flatbuffers_define_scalar_field(1, AzureIoTSecurity_Record, level, AzureIoTSecurity_Level, AzureIoTSecurity_Level_enum_t, INT8_C(0))
+__flatbuffers_define_scalar_field(2, AzureIoTSecurity_Record, timestamp, flatbuffers_uint64, uint64_t, UINT64_C(0))
+/** The line number from which this record was written */
+__flatbuffers_define_scalar_field(3, AzureIoTSecurity_Record, line, flatbuffers_uint32, uint32_t, UINT32_C(0))
+/** The file name from which this record was written */
+__flatbuffers_define_string_field(4, AzureIoTSecurity_Record, filename, 1)
+
+struct AzureIoTSecurity_Log_table { uint8_t unused__; };
+
+static inline size_t AzureIoTSecurity_Log_vec_len(AzureIoTSecurity_Log_vec_t vec)
+__flatbuffers_vec_len(vec)
+static inline AzureIoTSecurity_Log_table_t AzureIoTSecurity_Log_vec_at(AzureIoTSecurity_Log_vec_t vec, size_t i)
+__flatbuffers_offset_vec_at(AzureIoTSecurity_Log_table_t, vec, i, 0)
+__flatbuffers_table_as_root(AzureIoTSecurity_Log)
+
+__flatbuffers_define_vector_field(0, AzureIoTSecurity_Log, logs, AzureIoTSecurity_Record_vec_t, 0)
+
+
+#include "flatcc/flatcc_epilogue.h"
+#endif /* LOG_READER_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/message_json_parser.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/message_json_parser.h
index e8985527..dd118fa9 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/message_json_parser.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/message_json_parser.h
@@ -167,7 +167,7 @@ static const char *message_local_AzureIoTSecurity_json_parser_enum(flatcc_json_p
uint64_t w;
w = flatcc_json_parser_symbol_part(buf, end);
- if (w < 0x50726f746f636f6c) { /* branch "Protocol" */
+ if (w < 0x50726f6365737345) { /* branch "ProcessE" */
if ((w & 0xffffffffffffff00) == 0x5061796c6f616400) { /* "Payload" */
buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 7);
if (buf != mark) {
@@ -176,42 +176,70 @@ static const char *message_local_AzureIoTSecurity_json_parser_enum(flatcc_json_p
return unmatched;
}
} else { /* "Payload" */
- return unmatched;
- } /* "Payload" */
- } else { /* branch "Protocol" */
- if (w < 0x526573756c740000) { /* branch "Result" */
- if (w == 0x50726f746f636f6c) { /* "Protocol" */
- buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 8);
+ if ((w & 0xffffffffff000000) == 0x4c6576656c000000) { /* "Level" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 5);
if (buf != mark) {
- buf = AzureIoTSecurity_Protocol_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ buf = AzureIoTSecurity_Level_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
} else {
return unmatched;
}
- } else { /* "Protocol" */
+ } else { /* "Level" */
return unmatched;
- } /* "Protocol" */
- } else { /* branch "Result" */
- if (w == 0x5365766572697479) { /* "Severity" */
- buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 8);
- if (buf != mark) {
- buf = AzureIoTSecurity_Severity_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
- } else {
+ } /* "Level" */
+ } /* "Payload" */
+ } else { /* branch "ProcessE" */
+ if (w < 0x50726f746f636f6c) { /* branch "Protocol" */
+ if (w == 0x50726f6365737345) { /* descend "ProcessE" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x76656e7454797065) { /* "ventType" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 8);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_ProcessEventType_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* "ventType" */
return unmatched;
- }
- } else { /* "Severity" */
- if ((w & 0xffffffffffff0000) == 0x526573756c740000) { /* "Result" */
- buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 6);
+ } /* "ventType" */
+ } else { /* descend "ProcessE" */
+ return unmatched;
+ } /* descend "ProcessE" */
+ } else { /* branch "Protocol" */
+ if (w < 0x526573756c740000) { /* branch "Result" */
+ if (w == 0x50726f746f636f6c) { /* "Protocol" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 8);
if (buf != mark) {
- buf = AzureIoTSecurity_Result_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ buf = AzureIoTSecurity_Protocol_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
} else {
return unmatched;
}
- } else { /* "Result" */
+ } else { /* "Protocol" */
return unmatched;
- } /* "Result" */
- } /* "Severity" */
- } /* branch "Result" */
- } /* branch "Protocol" */
+ } /* "Protocol" */
+ } else { /* branch "Result" */
+ if (w == 0x5365766572697479) { /* "Severity" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 8);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_Severity_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* "Severity" */
+ if ((w & 0xffffffffffff0000) == 0x526573756c740000) { /* "Result" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 6);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_Result_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* "Result" */
+ return unmatched;
+ } /* "Result" */
+ } /* "Severity" */
+ } /* branch "Result" */
+ } /* branch "Protocol" */
+ } /* branch "ProcessE" */
return buf;
}
@@ -229,7 +257,7 @@ static const char *message_global_json_parser_enum(flatcc_json_parser_t *ctx, co
if (w == 0x5365637572697479) { /* descend "Security" */
buf += 8;
w = flatcc_json_parser_symbol_part(buf, end);
- if (w < 0x2e50726f746f636f) { /* branch ".Protoco" */
+ if (w < 0x2e50726f63657373) { /* branch ".Process" */
if (w == 0x2e5061796c6f6164) { /* ".Payload" */
buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 8);
if (buf != mark) {
@@ -238,59 +266,93 @@ static const char *message_global_json_parser_enum(flatcc_json_parser_t *ctx, co
return unmatched;
}
} else { /* ".Payload" */
- return unmatched;
+ if ((w & 0xffffffffffff0000) == 0x2e4c6576656c0000) { /* ".Level" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 6);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_Level_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* ".Level" */
+ return unmatched;
+ } /* ".Level" */
} /* ".Payload" */
- } else { /* branch ".Protoco" */
- if (w < 0x2e526573756c7400) { /* branch ".Result" */
- if (w == 0x2e50726f746f636f) { /* descend ".Protoco" */
+ } else { /* branch ".Process" */
+ if (w < 0x2e50726f746f636f) { /* branch ".Protoco" */
+ if (w == 0x2e50726f63657373) { /* descend ".Process" */
buf += 8;
w = flatcc_json_parser_symbol_part(buf, end);
- if ((w & 0xff00000000000000) == 0x6c00000000000000) { /* "l" */
- buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 1);
- if (buf != mark) {
- buf = AzureIoTSecurity_Protocol_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
- } else {
+ if (w == 0x4576656e74547970) { /* descend "EventTyp" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xff00000000000000) == 0x6500000000000000) { /* "e" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 1);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_ProcessEventType_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* "e" */
return unmatched;
- }
- } else { /* "l" */
+ } /* "e" */
+ } else { /* descend "EventTyp" */
return unmatched;
- } /* "l" */
- } else { /* descend ".Protoco" */
+ } /* descend "EventTyp" */
+ } else { /* descend ".Process" */
return unmatched;
- } /* descend ".Protoco" */
- } else { /* branch ".Result" */
- if ((w & 0xffffffffffffff00) == 0x2e526573756c7400) { /* ".Result" */
- buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 7);
- if (buf != mark) {
- buf = AzureIoTSecurity_Result_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
- } else {
- goto pfguard1;
- }
- } else { /* ".Result" */
- goto pfguard1;
- } /* ".Result" */
- goto endpfguard1;
-pfguard1:
- if (w == 0x2e53657665726974) { /* descend ".Severit" */
- buf += 8;
- w = flatcc_json_parser_symbol_part(buf, end);
- if ((w & 0xff00000000000000) == 0x7900000000000000) { /* "y" */
- buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 1);
+ } /* descend ".Process" */
+ } else { /* branch ".Protoco" */
+ if (w < 0x2e526573756c7400) { /* branch ".Result" */
+ if (w == 0x2e50726f746f636f) { /* descend ".Protoco" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xff00000000000000) == 0x6c00000000000000) { /* "l" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 1);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_Protocol_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* "l" */
+ return unmatched;
+ } /* "l" */
+ } else { /* descend ".Protoco" */
+ return unmatched;
+ } /* descend ".Protoco" */
+ } else { /* branch ".Result" */
+ if ((w & 0xffffffffffffff00) == 0x2e526573756c7400) { /* ".Result" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 7);
if (buf != mark) {
- buf = AzureIoTSecurity_Severity_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ buf = AzureIoTSecurity_Result_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
} else {
- return unmatched;
+ goto pfguard1;
}
- } else { /* "y" */
+ } else { /* ".Result" */
+ goto pfguard1;
+ } /* ".Result" */
+ goto endpfguard1;
+pfguard1:
+ if (w == 0x2e53657665726974) { /* descend ".Severit" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xff00000000000000) == 0x7900000000000000) { /* "y" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 1);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_Severity_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* "y" */
+ return unmatched;
+ } /* "y" */
+ } else { /* descend ".Severit" */
return unmatched;
- } /* "y" */
- } else { /* descend ".Severit" */
- return unmatched;
- } /* descend ".Severit" */
+ } /* descend ".Severit" */
endpfguard1:
- (void)0;
- } /* branch ".Result" */
- } /* branch ".Protoco" */
+ (void)0;
+ } /* branch ".Result" */
+ } /* branch ".Protoco" */
+ } /* branch ".Process" */
} else { /* descend "Security" */
return unmatched;
} /* descend "Security" */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/payload_builder.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/payload_builder.h
index eb55fca3..de956439 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/payload_builder.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/payload_builder.h
@@ -9,6 +9,12 @@
#ifndef FLATBUFFERS_COMMON_BUILDER_H
#include "flatbuffers_common_builder.h"
#endif
+#ifndef LOG_BUILDER_H
+#include "log_builder.h"
+#endif
+#ifndef PROCESS_BUILDER_H
+#include "process_builder.h"
+#endif
#ifndef BASELINE_BUILDER_H
#include "baseline_builder.h"
#endif
@@ -48,6 +54,10 @@ static inline AzureIoTSecurity_Payload_union_ref_t AzureIoTSecurity_Payload_as_H
{ AzureIoTSecurity_Payload_union_ref_t uref; uref.type = AzureIoTSecurity_Payload_Heartbeat; uref.value = ref; return uref; }
static inline AzureIoTSecurity_Payload_union_ref_t AzureIoTSecurity_Payload_as_Baseline(AzureIoTSecurity_Baseline_ref_t ref)
{ AzureIoTSecurity_Payload_union_ref_t uref; uref.type = AzureIoTSecurity_Payload_Baseline; uref.value = ref; return uref; }
+static inline AzureIoTSecurity_Payload_union_ref_t AzureIoTSecurity_Payload_as_Process(AzureIoTSecurity_Process_ref_t ref)
+{ AzureIoTSecurity_Payload_union_ref_t uref; uref.type = AzureIoTSecurity_Payload_Process; uref.value = ref; return uref; }
+static inline AzureIoTSecurity_Payload_union_ref_t AzureIoTSecurity_Payload_as_Log(AzureIoTSecurity_Log_ref_t ref)
+{ AzureIoTSecurity_Payload_union_ref_t uref; uref.type = AzureIoTSecurity_Payload_Log; uref.value = ref; return uref; }
__flatbuffers_build_union_vector(flatbuffers_, AzureIoTSecurity_Payload)
static AzureIoTSecurity_Payload_union_ref_t AzureIoTSecurity_Payload_clone(flatbuffers_builder_t *B, AzureIoTSecurity_Payload_union_t u)
@@ -58,6 +68,8 @@ static AzureIoTSecurity_Payload_union_ref_t AzureIoTSecurity_Payload_clone(flatb
case 3: return AzureIoTSecurity_Payload_as_ListeningPorts(AzureIoTSecurity_ListeningPorts_clone(B, (AzureIoTSecurity_ListeningPorts_table_t)u.value));
case 4: return AzureIoTSecurity_Payload_as_Heartbeat(AzureIoTSecurity_Heartbeat_clone(B, (AzureIoTSecurity_Heartbeat_table_t)u.value));
case 5: return AzureIoTSecurity_Payload_as_Baseline(AzureIoTSecurity_Baseline_clone(B, (AzureIoTSecurity_Baseline_table_t)u.value));
+ case 6: return AzureIoTSecurity_Payload_as_Process(AzureIoTSecurity_Process_clone(B, (AzureIoTSecurity_Process_table_t)u.value));
+ case 7: return AzureIoTSecurity_Payload_as_Log(AzureIoTSecurity_Log_clone(B, (AzureIoTSecurity_Log_table_t)u.value));
default: return AzureIoTSecurity_Payload_as_NONE();
}
}
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/payload_json_parser.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/payload_json_parser.h
index a61c12ba..ecaa0bf6 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/payload_json_parser.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/payload_json_parser.h
@@ -4,6 +4,12 @@
/* Generated by flatcc 0.6.1-dev FlatBuffers schema compiler for C by dvide.com */
#include "flatcc/flatcc_json_parser.h"
+#ifndef LOG_JSON_PARSER_H
+#include "log_json_parser.h"
+#endif
+#ifndef PROCESS_JSON_PARSER_H
+#include "process_json_parser.h"
+#endif
#ifndef BASELINE_JSON_PARSER_H
#include "baseline_json_parser.h"
#endif
@@ -54,6 +60,12 @@ static const char *AzureIoTSecurity_Payload_parse_json_union(flatcc_json_parser_
case 5: /* Baseline */
buf = AzureIoTSecurity_Baseline_parse_json_table(ctx, buf, end, result);
break;
+ case 6: /* Process */
+ buf = AzureIoTSecurity_Process_parse_json_table(ctx, buf, end, result);
+ break;
+ case 7: /* Log */
+ buf = AzureIoTSecurity_Log_parse_json_table(ctx, buf, end, result);
+ break;
default:
if (!(ctx->flags & flatcc_json_parser_f_skip_unknown)) {
return flatcc_json_parser_set_error(ctx, buf, end, flatcc_json_parser_error_unknown_union);
@@ -77,6 +89,8 @@ static int AzureIoTSecurity_Payload_json_union_accept_type(uint8_t type)
case 3: return 1; /* ListeningPorts */
case 4: return 1; /* Heartbeat */
case 5: return 1; /* Baseline */
+ case 6: return 1; /* Process */
+ case 7: return 1; /* Log */
default: return 0;
}
}
@@ -89,68 +103,74 @@ static const char *AzureIoTSecurity_Payload_parse_json_enum(flatcc_json_parser_t
uint64_t w;
w = flatcc_json_parser_symbol_part(buf, end);
- if (w < 0x4c697374656e696e) { /* branch "Listenin" */
- if (w == 0x426173656c696e65) { /* "Baseline" */
- buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 8, aggregate);
- if (buf != mark) {
- *value = UINT64_C(5), *value_sign = 0;
- } else {
- goto pfguard1;
- }
- } else { /* "Baseline" */
- goto pfguard1;
- } /* "Baseline" */
- goto endpfguard1;
-pfguard1:
- if (w == 0x4865617274626561) { /* descend "Heartbea" */
- buf += 8;
- w = flatcc_json_parser_symbol_part(buf, end);
- if ((w & 0xff00000000000000) == 0x7400000000000000) { /* "t" */
- buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 1, aggregate);
+ if (w < 0x4c6f670000000000) { /* branch "Log" */
+ if (w < 0x4865617274626561) { /* branch "Heartbea" */
+ if (w == 0x426173656c696e65) { /* "Baseline" */
+ buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 8, aggregate);
if (buf != mark) {
- *value = UINT64_C(4), *value_sign = 0;
+ *value = UINT64_C(5), *value_sign = 0;
} else {
return unmatched;
}
- } else { /* "t" */
+ } else { /* "Baseline" */
return unmatched;
- } /* "t" */
- } else { /* descend "Heartbea" */
- return unmatched;
- } /* descend "Heartbea" */
-endpfguard1:
- (void)0;
- } else { /* branch "Listenin" */
- if (w < 0x4e4f4e4500000000) { /* branch "NONE" */
- if (w == 0x4c697374656e696e) { /* descend "Listenin" */
+ } /* "Baseline" */
+ } else { /* branch "Heartbea" */
+ if (w == 0x4865617274626561) { /* descend "Heartbea" */
buf += 8;
w = flatcc_json_parser_symbol_part(buf, end);
- if ((w & 0xffffffffffff0000) == 0x67506f7274730000) { /* "gPorts" */
- buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 6, aggregate);
+ if ((w & 0xff00000000000000) == 0x7400000000000000) { /* "t" */
+ buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 1, aggregate);
if (buf != mark) {
- *value = UINT64_C(3), *value_sign = 0;
+ *value = UINT64_C(4), *value_sign = 0;
} else {
return unmatched;
}
- } else { /* "gPorts" */
+ } else { /* "t" */
return unmatched;
- } /* "gPorts" */
- } else { /* descend "Listenin" */
- return unmatched;
- } /* descend "Listenin" */
- } else { /* branch "NONE" */
- if (w < 0x4e6574776f726b41) { /* branch "NetworkA" */
- if ((w & 0xffffffff00000000) == 0x4e4f4e4500000000) { /* "NONE" */
- buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 4, aggregate);
+ } /* "t" */
+ } else { /* descend "Heartbea" */
+ if (w == 0x4c697374656e696e) { /* descend "Listenin" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xffffffffffff0000) == 0x67506f7274730000) { /* "gPorts" */
+ buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 6, aggregate);
+ if (buf != mark) {
+ *value = UINT64_C(3), *value_sign = 0;
+ } else {
+ return unmatched;
+ }
+ } else { /* "gPorts" */
+ return unmatched;
+ } /* "gPorts" */
+ } else { /* descend "Listenin" */
+ return unmatched;
+ } /* descend "Listenin" */
+ } /* descend "Heartbea" */
+ } /* branch "Heartbea" */
+ } else { /* branch "Log" */
+ if (w < 0x4e6574776f726b41) { /* branch "NetworkA" */
+ if ((w & 0xffffffff00000000) == 0x4e4f4e4500000000) { /* "NONE" */
+ buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 4, aggregate);
+ if (buf != mark) {
+ *value = UINT64_C(0), *value_sign = 0;
+ } else {
+ return unmatched;
+ }
+ } else { /* "NONE" */
+ if ((w & 0xffffff0000000000) == 0x4c6f670000000000) { /* "Log" */
+ buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 3, aggregate);
if (buf != mark) {
- *value = UINT64_C(0), *value_sign = 0;
+ *value = UINT64_C(7), *value_sign = 0;
} else {
return unmatched;
}
- } else { /* "NONE" */
+ } else { /* "Log" */
return unmatched;
- } /* "NONE" */
- } else { /* branch "NetworkA" */
+ } /* "Log" */
+ } /* "NONE" */
+ } else { /* branch "NetworkA" */
+ if (w < 0x50726f6365737300) { /* branch "Process" */
if (w == 0x4e6574776f726b41) { /* descend "NetworkA" */
buf += 8;
w = flatcc_json_parser_symbol_part(buf, end);
@@ -165,32 +185,48 @@ static const char *AzureIoTSecurity_Payload_parse_json_enum(flatcc_json_parser_t
return unmatched;
} /* "ctivity" */
} else { /* descend "NetworkA" */
- if (w == 0x53797374656d496e) { /* descend "SystemIn" */
+ return unmatched;
+ } /* descend "NetworkA" */
+ } else { /* branch "Process" */
+ if ((w & 0xffffffffffffff00) == 0x50726f6365737300) { /* "Process" */
+ buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 7, aggregate);
+ if (buf != mark) {
+ *value = UINT64_C(6), *value_sign = 0;
+ } else {
+ goto pfguard1;
+ }
+ } else { /* "Process" */
+ goto pfguard1;
+ } /* "Process" */
+ goto endpfguard1;
+pfguard1:
+ if (w == 0x53797374656d496e) { /* descend "SystemIn" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x666f726d6174696f) { /* descend "formatio" */
buf += 8;
w = flatcc_json_parser_symbol_part(buf, end);
- if (w == 0x666f726d6174696f) { /* descend "formatio" */
- buf += 8;
- w = flatcc_json_parser_symbol_part(buf, end);
- if ((w & 0xff00000000000000) == 0x6e00000000000000) { /* "n" */
- buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 1, aggregate);
- if (buf != mark) {
- *value = UINT64_C(2), *value_sign = 0;
- } else {
- return unmatched;
- }
- } else { /* "n" */
+ if ((w & 0xff00000000000000) == 0x6e00000000000000) { /* "n" */
+ buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 1, aggregate);
+ if (buf != mark) {
+ *value = UINT64_C(2), *value_sign = 0;
+ } else {
return unmatched;
- } /* "n" */
- } else { /* descend "formatio" */
+ }
+ } else { /* "n" */
return unmatched;
- } /* descend "formatio" */
- } else { /* descend "SystemIn" */
+ } /* "n" */
+ } else { /* descend "formatio" */
return unmatched;
- } /* descend "SystemIn" */
- } /* descend "NetworkA" */
- } /* branch "NetworkA" */
- } /* branch "NONE" */
- } /* branch "Listenin" */
+ } /* descend "formatio" */
+ } else { /* descend "SystemIn" */
+ return unmatched;
+ } /* descend "SystemIn" */
+endpfguard1:
+ (void)0;
+ } /* branch "Process" */
+ } /* branch "NetworkA" */
+ } /* branch "Log" */
return buf;
}
@@ -209,7 +245,7 @@ static const char *payload_local_AzureIoTSecurity_json_parser_enum(flatcc_json_p
uint64_t w;
w = flatcc_json_parser_symbol_part(buf, end);
- if (w < 0x50726f746f636f6c) { /* branch "Protocol" */
+ if (w < 0x50726f6365737345) { /* branch "ProcessE" */
if ((w & 0xffffffffffffff00) == 0x5061796c6f616400) { /* "Payload" */
buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 7);
if (buf != mark) {
@@ -218,42 +254,70 @@ static const char *payload_local_AzureIoTSecurity_json_parser_enum(flatcc_json_p
return unmatched;
}
} else { /* "Payload" */
- return unmatched;
- } /* "Payload" */
- } else { /* branch "Protocol" */
- if (w < 0x526573756c740000) { /* branch "Result" */
- if (w == 0x50726f746f636f6c) { /* "Protocol" */
- buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 8);
+ if ((w & 0xffffffffff000000) == 0x4c6576656c000000) { /* "Level" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 5);
if (buf != mark) {
- buf = AzureIoTSecurity_Protocol_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ buf = AzureIoTSecurity_Level_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
} else {
return unmatched;
}
- } else { /* "Protocol" */
+ } else { /* "Level" */
return unmatched;
- } /* "Protocol" */
- } else { /* branch "Result" */
- if (w == 0x5365766572697479) { /* "Severity" */
- buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 8);
- if (buf != mark) {
- buf = AzureIoTSecurity_Severity_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
- } else {
+ } /* "Level" */
+ } /* "Payload" */
+ } else { /* branch "ProcessE" */
+ if (w < 0x50726f746f636f6c) { /* branch "Protocol" */
+ if (w == 0x50726f6365737345) { /* descend "ProcessE" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x76656e7454797065) { /* "ventType" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 8);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_ProcessEventType_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* "ventType" */
return unmatched;
- }
- } else { /* "Severity" */
- if ((w & 0xffffffffffff0000) == 0x526573756c740000) { /* "Result" */
- buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 6);
+ } /* "ventType" */
+ } else { /* descend "ProcessE" */
+ return unmatched;
+ } /* descend "ProcessE" */
+ } else { /* branch "Protocol" */
+ if (w < 0x526573756c740000) { /* branch "Result" */
+ if (w == 0x50726f746f636f6c) { /* "Protocol" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 8);
if (buf != mark) {
- buf = AzureIoTSecurity_Result_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ buf = AzureIoTSecurity_Protocol_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
} else {
return unmatched;
}
- } else { /* "Result" */
+ } else { /* "Protocol" */
return unmatched;
- } /* "Result" */
- } /* "Severity" */
- } /* branch "Result" */
- } /* branch "Protocol" */
+ } /* "Protocol" */
+ } else { /* branch "Result" */
+ if (w == 0x5365766572697479) { /* "Severity" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 8);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_Severity_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* "Severity" */
+ if ((w & 0xffffffffffff0000) == 0x526573756c740000) { /* "Result" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 6);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_Result_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* "Result" */
+ return unmatched;
+ } /* "Result" */
+ } /* "Severity" */
+ } /* branch "Result" */
+ } /* branch "Protocol" */
+ } /* branch "ProcessE" */
return buf;
}
@@ -271,7 +335,7 @@ static const char *payload_global_json_parser_enum(flatcc_json_parser_t *ctx, co
if (w == 0x5365637572697479) { /* descend "Security" */
buf += 8;
w = flatcc_json_parser_symbol_part(buf, end);
- if (w < 0x2e50726f746f636f) { /* branch ".Protoco" */
+ if (w < 0x2e50726f63657373) { /* branch ".Process" */
if (w == 0x2e5061796c6f6164) { /* ".Payload" */
buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 8);
if (buf != mark) {
@@ -280,59 +344,93 @@ static const char *payload_global_json_parser_enum(flatcc_json_parser_t *ctx, co
return unmatched;
}
} else { /* ".Payload" */
- return unmatched;
+ if ((w & 0xffffffffffff0000) == 0x2e4c6576656c0000) { /* ".Level" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 6);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_Level_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* ".Level" */
+ return unmatched;
+ } /* ".Level" */
} /* ".Payload" */
- } else { /* branch ".Protoco" */
- if (w < 0x2e526573756c7400) { /* branch ".Result" */
- if (w == 0x2e50726f746f636f) { /* descend ".Protoco" */
+ } else { /* branch ".Process" */
+ if (w < 0x2e50726f746f636f) { /* branch ".Protoco" */
+ if (w == 0x2e50726f63657373) { /* descend ".Process" */
buf += 8;
w = flatcc_json_parser_symbol_part(buf, end);
- if ((w & 0xff00000000000000) == 0x6c00000000000000) { /* "l" */
- buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 1);
- if (buf != mark) {
- buf = AzureIoTSecurity_Protocol_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
- } else {
+ if (w == 0x4576656e74547970) { /* descend "EventTyp" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xff00000000000000) == 0x6500000000000000) { /* "e" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 1);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_ProcessEventType_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* "e" */
return unmatched;
- }
- } else { /* "l" */
+ } /* "e" */
+ } else { /* descend "EventTyp" */
return unmatched;
- } /* "l" */
- } else { /* descend ".Protoco" */
+ } /* descend "EventTyp" */
+ } else { /* descend ".Process" */
return unmatched;
- } /* descend ".Protoco" */
- } else { /* branch ".Result" */
- if ((w & 0xffffffffffffff00) == 0x2e526573756c7400) { /* ".Result" */
- buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 7);
- if (buf != mark) {
- buf = AzureIoTSecurity_Result_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
- } else {
- goto pfguard1;
- }
- } else { /* ".Result" */
- goto pfguard1;
- } /* ".Result" */
- goto endpfguard1;
-pfguard1:
- if (w == 0x2e53657665726974) { /* descend ".Severit" */
- buf += 8;
- w = flatcc_json_parser_symbol_part(buf, end);
- if ((w & 0xff00000000000000) == 0x7900000000000000) { /* "y" */
- buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 1);
+ } /* descend ".Process" */
+ } else { /* branch ".Protoco" */
+ if (w < 0x2e526573756c7400) { /* branch ".Result" */
+ if (w == 0x2e50726f746f636f) { /* descend ".Protoco" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xff00000000000000) == 0x6c00000000000000) { /* "l" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 1);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_Protocol_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* "l" */
+ return unmatched;
+ } /* "l" */
+ } else { /* descend ".Protoco" */
+ return unmatched;
+ } /* descend ".Protoco" */
+ } else { /* branch ".Result" */
+ if ((w & 0xffffffffffffff00) == 0x2e526573756c7400) { /* ".Result" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 7);
if (buf != mark) {
- buf = AzureIoTSecurity_Severity_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ buf = AzureIoTSecurity_Result_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
} else {
- return unmatched;
+ goto pfguard1;
}
- } else { /* "y" */
+ } else { /* ".Result" */
+ goto pfguard1;
+ } /* ".Result" */
+ goto endpfguard1;
+pfguard1:
+ if (w == 0x2e53657665726974) { /* descend ".Severit" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xff00000000000000) == 0x7900000000000000) { /* "y" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 1);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_Severity_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* "y" */
+ return unmatched;
+ } /* "y" */
+ } else { /* descend ".Severit" */
return unmatched;
- } /* "y" */
- } else { /* descend ".Severit" */
- return unmatched;
- } /* descend ".Severit" */
+ } /* descend ".Severit" */
endpfguard1:
- (void)0;
- } /* branch ".Result" */
- } /* branch ".Protoco" */
+ (void)0;
+ } /* branch ".Result" */
+ } /* branch ".Protoco" */
+ } /* branch ".Process" */
} else { /* descend "Security" */
return unmatched;
} /* descend "Security" */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/payload_json_printer.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/payload_json_printer.h
index f366f589..9ca6c3fa 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/payload_json_printer.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/payload_json_printer.h
@@ -4,6 +4,12 @@
/* Generated by flatcc 0.6.1-dev FlatBuffers schema compiler for C by dvide.com */
#include "flatcc/flatcc_json_printer.h"
+#ifndef LOG_JSON_PRINTER_H
+#include "log_json_printer.h"
+#endif
+#ifndef PROCESS_JSON_PRINTER_H
+#include "process_json_printer.h"
+#endif
#ifndef BASELINE_JSON_PRINTER_H
#include "baseline_json_printer.h"
#endif
@@ -42,6 +48,12 @@ static void AzureIoTSecurity_Payload_print_json_union_type(flatcc_json_printer_t
case 5:
flatcc_json_printer_enum(ctx, "Baseline", 8);
break;
+ case 6:
+ flatcc_json_printer_enum(ctx, "Process", 7);
+ break;
+ case 7:
+ flatcc_json_printer_enum(ctx, "Log", 3);
+ break;
default:
flatcc_json_printer_enum(ctx, "NONE", 4);
break;
@@ -66,6 +78,12 @@ static void AzureIoTSecurity_Payload_print_json_union(flatcc_json_printer_t *ctx
case 5:
flatcc_json_printer_union_table(ctx, ud, AzureIoTSecurity_Baseline_print_json_table);
break;
+ case 6:
+ flatcc_json_printer_union_table(ctx, ud, AzureIoTSecurity_Process_print_json_table);
+ break;
+ case 7:
+ flatcc_json_printer_union_table(ctx, ud, AzureIoTSecurity_Log_print_json_table);
+ break;
default:
break;
}
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/payload_reader.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/payload_reader.h
index b74c248b..7d4ac8c0 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/payload_reader.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/payload_reader.h
@@ -6,6 +6,12 @@
#ifndef FLATBUFFERS_COMMON_READER_H
#include "flatbuffers_common_reader.h"
#endif
+#ifndef LOG_READER_H
+#include "log_reader.h"
+#endif
+#ifndef PROCESS_READER_H
+#include "process_reader.h"
+#endif
#ifndef BASELINE_READER_H
#include "baseline_reader.h"
#endif
@@ -45,6 +51,8 @@ __flatbuffers_define_union(flatbuffers_, AzureIoTSecurity_Payload)
#define AzureIoTSecurity_Payload_ListeningPorts ((AzureIoTSecurity_Payload_union_type_t)UINT8_C(3))
#define AzureIoTSecurity_Payload_Heartbeat ((AzureIoTSecurity_Payload_union_type_t)UINT8_C(4))
#define AzureIoTSecurity_Payload_Baseline ((AzureIoTSecurity_Payload_union_type_t)UINT8_C(5))
+#define AzureIoTSecurity_Payload_Process ((AzureIoTSecurity_Payload_union_type_t)UINT8_C(6))
+#define AzureIoTSecurity_Payload_Log ((AzureIoTSecurity_Payload_union_type_t)UINT8_C(7))
static inline const char *AzureIoTSecurity_Payload_type_name(AzureIoTSecurity_Payload_union_type_t type)
{
@@ -55,6 +63,8 @@ static inline const char *AzureIoTSecurity_Payload_type_name(AzureIoTSecurity_Pa
case AzureIoTSecurity_Payload_ListeningPorts: return "ListeningPorts";
case AzureIoTSecurity_Payload_Heartbeat: return "Heartbeat";
case AzureIoTSecurity_Payload_Baseline: return "Baseline";
+ case AzureIoTSecurity_Payload_Process: return "Process";
+ case AzureIoTSecurity_Payload_Log: return "Log";
default: return "";
}
}
@@ -68,6 +78,8 @@ static inline int AzureIoTSecurity_Payload_is_known_type(AzureIoTSecurity_Payloa
case AzureIoTSecurity_Payload_ListeningPorts: return 1;
case AzureIoTSecurity_Payload_Heartbeat: return 1;
case AzureIoTSecurity_Payload_Baseline: return 1;
+ case AzureIoTSecurity_Payload_Process: return 1;
+ case AzureIoTSecurity_Payload_Log: return 1;
default: return 0;
}
}
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_builder.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_builder.h
new file mode 100644
index 00000000..2d2d4f0d
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_builder.h
@@ -0,0 +1,80 @@
+#ifndef PROCESS_BUILDER_H
+#define PROCESS_BUILDER_H
+
+/* Generated by flatcc 0.6.1-dev FlatBuffers schema compiler for C by dvide.com */
+
+#ifndef PROCESS_READER_H
+#include "process_reader.h"
+#endif
+#ifndef FLATBUFFERS_COMMON_BUILDER_H
+#include "flatbuffers_common_builder.h"
+#endif
+#ifndef PROCESS_EVENT_TYPE_BUILDER_H
+#include "process_event_type_builder.h"
+#endif
+#include "flatcc/flatcc_prologue.h"
+#ifndef flatbuffers_identifier
+#define flatbuffers_identifier 0
+#endif
+#ifndef flatbuffers_extension
+#define flatbuffers_extension ".bin"
+#endif
+
+static const flatbuffers_voffset_t __AzureIoTSecurity_Process_required[] = { 0 };
+typedef flatbuffers_ref_t AzureIoTSecurity_Process_ref_t;
+static AzureIoTSecurity_Process_ref_t AzureIoTSecurity_Process_clone(flatbuffers_builder_t *B, AzureIoTSecurity_Process_table_t t);
+__flatbuffers_build_table(flatbuffers_, AzureIoTSecurity_Process, 8)
+
+#define __AzureIoTSecurity_Process_formal_args ,\
+ flatbuffers_string_ref_t v0, uint32_t v1, uint32_t v2, uint32_t v3,\
+ flatbuffers_string_ref_t v4, flatbuffers_string_ref_t v5, AzureIoTSecurity_ProcessEventType_enum_t v6, uint32_t v7
+#define __AzureIoTSecurity_Process_call_args ,\
+ v0, v1, v2, v3,\
+ v4, v5, v6, v7
+static inline AzureIoTSecurity_Process_ref_t AzureIoTSecurity_Process_create(flatbuffers_builder_t *B __AzureIoTSecurity_Process_formal_args);
+__flatbuffers_build_table_prolog(flatbuffers_, AzureIoTSecurity_Process, AzureIoTSecurity_Process_file_identifier, AzureIoTSecurity_Process_type_identifier)
+
+__flatbuffers_build_string_field(0, flatbuffers_, AzureIoTSecurity_Process_executable, AzureIoTSecurity_Process)
+__flatbuffers_build_scalar_field(1, flatbuffers_, AzureIoTSecurity_Process_process_id, flatbuffers_uint32, uint32_t, 4, 4, UINT32_C(0), AzureIoTSecurity_Process)
+__flatbuffers_build_scalar_field(2, flatbuffers_, AzureIoTSecurity_Process_parent_process_id, flatbuffers_uint32, uint32_t, 4, 4, UINT32_C(0), AzureIoTSecurity_Process)
+__flatbuffers_build_scalar_field(3, flatbuffers_, AzureIoTSecurity_Process_user_id, flatbuffers_uint32, uint32_t, 4, 4, UINT32_C(0), AzureIoTSecurity_Process)
+__flatbuffers_build_string_field(4, flatbuffers_, AzureIoTSecurity_Process_user_name, AzureIoTSecurity_Process)
+__flatbuffers_build_string_field(5, flatbuffers_, AzureIoTSecurity_Process_commandline, AzureIoTSecurity_Process)
+__flatbuffers_build_scalar_field(6, flatbuffers_, AzureIoTSecurity_Process_event_type, AzureIoTSecurity_ProcessEventType, AzureIoTSecurity_ProcessEventType_enum_t, 1, 1, INT8_C(0), AzureIoTSecurity_Process)
+__flatbuffers_build_scalar_field(7, flatbuffers_, AzureIoTSecurity_Process_hit_count, flatbuffers_uint32, uint32_t, 4, 4, UINT32_C(1), AzureIoTSecurity_Process)
+
+static inline AzureIoTSecurity_Process_ref_t AzureIoTSecurity_Process_create(flatbuffers_builder_t *B __AzureIoTSecurity_Process_formal_args)
+{
+ if (AzureIoTSecurity_Process_start(B)
+ || AzureIoTSecurity_Process_executable_add(B, v0)
+ || AzureIoTSecurity_Process_process_id_add(B, v1)
+ || AzureIoTSecurity_Process_parent_process_id_add(B, v2)
+ || AzureIoTSecurity_Process_user_id_add(B, v3)
+ || AzureIoTSecurity_Process_user_name_add(B, v4)
+ || AzureIoTSecurity_Process_commandline_add(B, v5)
+ || AzureIoTSecurity_Process_hit_count_add(B, v7)
+ || AzureIoTSecurity_Process_event_type_add(B, v6)) {
+ return 0;
+ }
+ return AzureIoTSecurity_Process_end(B);
+}
+
+static AzureIoTSecurity_Process_ref_t AzureIoTSecurity_Process_clone(flatbuffers_builder_t *B, AzureIoTSecurity_Process_table_t t)
+{
+ __flatbuffers_memoize_begin(B, t);
+ if (AzureIoTSecurity_Process_start(B)
+ || AzureIoTSecurity_Process_executable_pick(B, t)
+ || AzureIoTSecurity_Process_process_id_pick(B, t)
+ || AzureIoTSecurity_Process_parent_process_id_pick(B, t)
+ || AzureIoTSecurity_Process_user_id_pick(B, t)
+ || AzureIoTSecurity_Process_user_name_pick(B, t)
+ || AzureIoTSecurity_Process_commandline_pick(B, t)
+ || AzureIoTSecurity_Process_hit_count_pick(B, t)
+ || AzureIoTSecurity_Process_event_type_pick(B, t)) {
+ return 0;
+ }
+ __flatbuffers_memoize_end(B, t, AzureIoTSecurity_Process_end(B));
+}
+
+#include "flatcc/flatcc_epilogue.h"
+#endif /* PROCESS_BUILDER_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_event_builder.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_event_builder.h
new file mode 100644
index 00000000..05847074
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_event_builder.h
@@ -0,0 +1,25 @@
+#ifndef PROCESS_EVENT_BUILDER_H
+#define PROCESS_EVENT_BUILDER_H
+
+/* Generated by flatcc 0.6.1-dev FlatBuffers schema compiler for C by dvide.com */
+
+#ifndef PROCESS_EVENT_READER_H
+#include "process_event_reader.h"
+#endif
+#ifndef FLATBUFFERS_COMMON_BUILDER_H
+#include "flatbuffers_common_builder.h"
+#endif
+#include "flatcc/flatcc_prologue.h"
+#ifndef flatbuffers_identifier
+#define flatbuffers_identifier 0
+#endif
+#ifndef flatbuffers_extension
+#define flatbuffers_extension ".bin"
+#endif
+
+#define __AzureIoTSecurity_ProcessEvent_formal_args , AzureIoTSecurity_ProcessEvent_enum_t v0
+#define __AzureIoTSecurity_ProcessEvent_call_args , v0
+__flatbuffers_build_scalar(flatbuffers_, AzureIoTSecurity_ProcessEvent, AzureIoTSecurity_ProcessEvent_enum_t)
+
+#include "flatcc/flatcc_epilogue.h"
+#endif /* PROCESS_EVENT_BUILDER_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_event_json_parser.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_event_json_parser.h
new file mode 100644
index 00000000..df237d59
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_event_json_parser.h
@@ -0,0 +1,135 @@
+#ifndef PROCESS_EVENT_JSON_PARSER_H
+#define PROCESS_EVENT_JSON_PARSER_H
+
+/* Generated by flatcc 0.6.1-dev FlatBuffers schema compiler for C by dvide.com */
+
+#include "flatcc/flatcc_json_parser.h"
+#include "flatcc/flatcc_prologue.h"
+
+static const char *AzureIoTSecurity_ProcessEvent_parse_json_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_type, uint64_t *value, int *aggregate);
+static const char *process_event_local_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+int *value_type, uint64_t *value, int *aggregate);
+static const char *process_event_local_AzureIoTSecurity_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+int *value_type, uint64_t *value, int *aggregate);
+static const char *process_event_global_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_type, uint64_t *value, int *aggregate);
+
+static const char *AzureIoTSecurity_ProcessEvent_parse_json_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_sign, uint64_t *value, int *aggregate)
+{
+ const char *unmatched = buf;
+ const char *mark;
+ uint64_t w;
+
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w < 0x4558495400000000) { /* branch "EXIT" */
+ if ((w & 0xffffffff00000000) == 0x4558454300000000) { /* "EXEC" */
+ buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 4, aggregate);
+ if (buf != mark) {
+ *value = UINT64_C(1), *value_sign = 0;
+ } else {
+ return unmatched;
+ }
+ } else { /* "EXEC" */
+ return unmatched;
+ } /* "EXEC" */
+ } else { /* branch "EXIT" */
+ if ((w & 0xffffffff00000000) == 0x464f524b00000000) { /* "FORK" */
+ buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 4, aggregate);
+ if (buf != mark) {
+ *value = UINT64_C(0), *value_sign = 0;
+ } else {
+ return unmatched;
+ }
+ } else { /* "FORK" */
+ if ((w & 0xffffffff00000000) == 0x4558495400000000) { /* "EXIT" */
+ buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 4, aggregate);
+ if (buf != mark) {
+ *value = UINT64_C(2), *value_sign = 0;
+ } else {
+ return unmatched;
+ }
+ } else { /* "EXIT" */
+ return unmatched;
+ } /* "EXIT" */
+ } /* "FORK" */
+ } /* branch "EXIT" */
+ return buf;
+}
+
+static const char *process_event_local_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_type, uint64_t *value, int *aggregate)
+{
+ /* Scope has no enum / union types to look up. */
+ return buf; /* unmatched; */
+}
+
+static const char *process_event_local_AzureIoTSecurity_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_type, uint64_t *value, int *aggregate)
+{
+ const char *unmatched = buf;
+ const char *mark;
+ uint64_t w;
+
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x50726f6365737345) { /* descend "ProcessE" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xffffffff00000000) == 0x76656e7400000000) { /* "vent" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 4);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_ProcessEvent_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* "vent" */
+ return unmatched;
+ } /* "vent" */
+ } else { /* descend "ProcessE" */
+ return unmatched;
+ } /* descend "ProcessE" */
+ return buf;
+}
+
+static const char *process_event_global_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_type, uint64_t *value, int *aggregate)
+{
+ const char *unmatched = buf;
+ const char *mark;
+ uint64_t w;
+
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x417a757265496f54) { /* descend "AzureIoT" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x5365637572697479) { /* descend "Security" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x2e50726f63657373) { /* descend ".Process" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xffffffffff000000) == 0x4576656e74000000) { /* "Event" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 5);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_ProcessEvent_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* "Event" */
+ return unmatched;
+ } /* "Event" */
+ } else { /* descend ".Process" */
+ return unmatched;
+ } /* descend ".Process" */
+ } else { /* descend "Security" */
+ return unmatched;
+ } /* descend "Security" */
+ } else { /* descend "AzureIoT" */
+ return unmatched;
+ } /* descend "AzureIoT" */
+ return buf;
+}
+
+#include "flatcc/flatcc_epilogue.h"
+#endif /* PROCESS_EVENT_JSON_PARSER_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_event_json_printer.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_event_json_printer.h
new file mode 100644
index 00000000..a2029994
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_event_json_printer.h
@@ -0,0 +1,22 @@
+#ifndef PROCESS_EVENT_JSON_PRINTER_H
+#define PROCESS_EVENT_JSON_PRINTER_H
+
+/* Generated by flatcc 0.6.1-dev FlatBuffers schema compiler for C by dvide.com */
+
+#include "flatcc/flatcc_json_printer.h"
+#include "flatcc/flatcc_prologue.h"
+
+
+static void AzureIoTSecurity_ProcessEvent_print_json_enum(flatcc_json_printer_t *ctx, int8_t v)
+{
+
+ switch (v) {
+ case 0: flatcc_json_printer_enum(ctx, "FORK", 4); break;
+ case 1: flatcc_json_printer_enum(ctx, "EXEC", 4); break;
+ case 2: flatcc_json_printer_enum(ctx, "EXIT", 4); break;
+ default: flatcc_json_printer_int8(ctx, v); break;
+ }
+}
+
+#include "flatcc/flatcc_epilogue.h"
+#endif /* PROCESS_EVENT_JSON_PRINTER_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_event_reader.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_event_reader.h
new file mode 100644
index 00000000..fffbbb50
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_event_reader.h
@@ -0,0 +1,53 @@
+#ifndef PROCESS_EVENT_READER_H
+#define PROCESS_EVENT_READER_H
+
+/* Generated by flatcc 0.6.1-dev FlatBuffers schema compiler for C by dvide.com */
+
+#ifndef FLATBUFFERS_COMMON_READER_H
+#include "flatbuffers_common_reader.h"
+#endif
+#include "flatcc/flatcc_flatbuffers.h"
+#ifndef __alignas_is_defined
+#include
+#endif
+#include "flatcc/flatcc_prologue.h"
+#ifndef flatbuffers_identifier
+#define flatbuffers_identifier 0
+#endif
+#ifndef flatbuffers_extension
+#define flatbuffers_extension ".bin"
+#endif
+
+
+
+typedef int8_t AzureIoTSecurity_ProcessEvent_enum_t;
+__flatbuffers_define_integer_type(AzureIoTSecurity_ProcessEvent, AzureIoTSecurity_ProcessEvent_enum_t, 8)
+#define AzureIoTSecurity_ProcessEvent_FORK ((AzureIoTSecurity_ProcessEvent_enum_t)INT8_C(0))
+#define AzureIoTSecurity_ProcessEvent_EXEC ((AzureIoTSecurity_ProcessEvent_enum_t)INT8_C(1))
+#define AzureIoTSecurity_ProcessEvent_EXIT ((AzureIoTSecurity_ProcessEvent_enum_t)INT8_C(2))
+
+static inline const char *AzureIoTSecurity_ProcessEvent_name(AzureIoTSecurity_ProcessEvent_enum_t value)
+{
+ switch (value) {
+ case AzureIoTSecurity_ProcessEvent_FORK: return "FORK";
+ case AzureIoTSecurity_ProcessEvent_EXEC: return "EXEC";
+ case AzureIoTSecurity_ProcessEvent_EXIT: return "EXIT";
+ default: return "";
+ }
+}
+
+static inline int AzureIoTSecurity_ProcessEvent_is_known_value(AzureIoTSecurity_ProcessEvent_enum_t value)
+{
+ switch (value) {
+ case AzureIoTSecurity_ProcessEvent_FORK: return 1;
+ case AzureIoTSecurity_ProcessEvent_EXEC: return 1;
+ case AzureIoTSecurity_ProcessEvent_EXIT: return 1;
+ default: return 0;
+ }
+}
+
+
+
+
+#include "flatcc/flatcc_epilogue.h"
+#endif /* PROCESS_EVENT_READER_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_event_type_builder.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_event_type_builder.h
new file mode 100644
index 00000000..9372e890
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_event_type_builder.h
@@ -0,0 +1,25 @@
+#ifndef PROCESS_EVENT_TYPE_BUILDER_H
+#define PROCESS_EVENT_TYPE_BUILDER_H
+
+/* Generated by flatcc 0.6.1-dev FlatBuffers schema compiler for C by dvide.com */
+
+#ifndef PROCESS_EVENT_TYPE_READER_H
+#include "process_event_type_reader.h"
+#endif
+#ifndef FLATBUFFERS_COMMON_BUILDER_H
+#include "flatbuffers_common_builder.h"
+#endif
+#include "flatcc/flatcc_prologue.h"
+#ifndef flatbuffers_identifier
+#define flatbuffers_identifier 0
+#endif
+#ifndef flatbuffers_extension
+#define flatbuffers_extension ".bin"
+#endif
+
+#define __AzureIoTSecurity_ProcessEventType_formal_args , AzureIoTSecurity_ProcessEventType_enum_t v0
+#define __AzureIoTSecurity_ProcessEventType_call_args , v0
+__flatbuffers_build_scalar(flatbuffers_, AzureIoTSecurity_ProcessEventType, AzureIoTSecurity_ProcessEventType_enum_t)
+
+#include "flatcc/flatcc_epilogue.h"
+#endif /* PROCESS_EVENT_TYPE_BUILDER_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_event_type_json_parser.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_event_type_json_parser.h
new file mode 100644
index 00000000..04610574
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_event_type_json_parser.h
@@ -0,0 +1,141 @@
+#ifndef PROCESS_EVENT_TYPE_JSON_PARSER_H
+#define PROCESS_EVENT_TYPE_JSON_PARSER_H
+
+/* Generated by flatcc 0.6.1-dev FlatBuffers schema compiler for C by dvide.com */
+
+#include "flatcc/flatcc_json_parser.h"
+#include "flatcc/flatcc_prologue.h"
+
+static const char *AzureIoTSecurity_ProcessEventType_parse_json_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_type, uint64_t *value, int *aggregate);
+static const char *process_event_type_local_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+int *value_type, uint64_t *value, int *aggregate);
+static const char *process_event_type_local_AzureIoTSecurity_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+int *value_type, uint64_t *value, int *aggregate);
+static const char *process_event_type_global_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_type, uint64_t *value, int *aggregate);
+
+static const char *AzureIoTSecurity_ProcessEventType_parse_json_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_sign, uint64_t *value, int *aggregate)
+{
+ const char *unmatched = buf;
+ const char *mark;
+ uint64_t w;
+
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w < 0x4558495400000000) { /* branch "EXIT" */
+ if ((w & 0xffffffff00000000) == 0x4558454300000000) { /* "EXEC" */
+ buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 4, aggregate);
+ if (buf != mark) {
+ *value = UINT64_C(1), *value_sign = 0;
+ } else {
+ return unmatched;
+ }
+ } else { /* "EXEC" */
+ return unmatched;
+ } /* "EXEC" */
+ } else { /* branch "EXIT" */
+ if ((w & 0xffffffff00000000) == 0x464f524b00000000) { /* "FORK" */
+ buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 4, aggregate);
+ if (buf != mark) {
+ *value = UINT64_C(0), *value_sign = 0;
+ } else {
+ return unmatched;
+ }
+ } else { /* "FORK" */
+ if ((w & 0xffffffff00000000) == 0x4558495400000000) { /* "EXIT" */
+ buf = flatcc_json_parser_match_constant(ctx, (mark = buf), end, 4, aggregate);
+ if (buf != mark) {
+ *value = UINT64_C(2), *value_sign = 0;
+ } else {
+ return unmatched;
+ }
+ } else { /* "EXIT" */
+ return unmatched;
+ } /* "EXIT" */
+ } /* "FORK" */
+ } /* branch "EXIT" */
+ return buf;
+}
+
+static const char *process_event_type_local_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_type, uint64_t *value, int *aggregate)
+{
+ /* Scope has no enum / union types to look up. */
+ return buf; /* unmatched; */
+}
+
+static const char *process_event_type_local_AzureIoTSecurity_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_type, uint64_t *value, int *aggregate)
+{
+ const char *unmatched = buf;
+ const char *mark;
+ uint64_t w;
+
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x50726f6365737345) { /* descend "ProcessE" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x76656e7454797065) { /* "ventType" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 8);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_ProcessEventType_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* "ventType" */
+ return unmatched;
+ } /* "ventType" */
+ } else { /* descend "ProcessE" */
+ return unmatched;
+ } /* descend "ProcessE" */
+ return buf;
+}
+
+static const char *process_event_type_global_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_type, uint64_t *value, int *aggregate)
+{
+ const char *unmatched = buf;
+ const char *mark;
+ uint64_t w;
+
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x417a757265496f54) { /* descend "AzureIoT" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x5365637572697479) { /* descend "Security" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x2e50726f63657373) { /* descend ".Process" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x4576656e74547970) { /* descend "EventTyp" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xff00000000000000) == 0x6500000000000000) { /* "e" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 1);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_ProcessEventType_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* "e" */
+ return unmatched;
+ } /* "e" */
+ } else { /* descend "EventTyp" */
+ return unmatched;
+ } /* descend "EventTyp" */
+ } else { /* descend ".Process" */
+ return unmatched;
+ } /* descend ".Process" */
+ } else { /* descend "Security" */
+ return unmatched;
+ } /* descend "Security" */
+ } else { /* descend "AzureIoT" */
+ return unmatched;
+ } /* descend "AzureIoT" */
+ return buf;
+}
+
+#include "flatcc/flatcc_epilogue.h"
+#endif /* PROCESS_EVENT_TYPE_JSON_PARSER_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_event_type_json_printer.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_event_type_json_printer.h
new file mode 100644
index 00000000..b4392840
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_event_type_json_printer.h
@@ -0,0 +1,22 @@
+#ifndef PROCESS_EVENT_TYPE_JSON_PRINTER_H
+#define PROCESS_EVENT_TYPE_JSON_PRINTER_H
+
+/* Generated by flatcc 0.6.1-dev FlatBuffers schema compiler for C by dvide.com */
+
+#include "flatcc/flatcc_json_printer.h"
+#include "flatcc/flatcc_prologue.h"
+
+
+static void AzureIoTSecurity_ProcessEventType_print_json_enum(flatcc_json_printer_t *ctx, int8_t v)
+{
+
+ switch (v) {
+ case 0: flatcc_json_printer_enum(ctx, "FORK", 4); break;
+ case 1: flatcc_json_printer_enum(ctx, "EXEC", 4); break;
+ case 2: flatcc_json_printer_enum(ctx, "EXIT", 4); break;
+ default: flatcc_json_printer_int8(ctx, v); break;
+ }
+}
+
+#include "flatcc/flatcc_epilogue.h"
+#endif /* PROCESS_EVENT_TYPE_JSON_PRINTER_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_event_type_reader.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_event_type_reader.h
new file mode 100644
index 00000000..515bfc98
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_event_type_reader.h
@@ -0,0 +1,53 @@
+#ifndef PROCESS_EVENT_TYPE_READER_H
+#define PROCESS_EVENT_TYPE_READER_H
+
+/* Generated by flatcc 0.6.1-dev FlatBuffers schema compiler for C by dvide.com */
+
+#ifndef FLATBUFFERS_COMMON_READER_H
+#include "flatbuffers_common_reader.h"
+#endif
+#include "flatcc/flatcc_flatbuffers.h"
+#ifndef __alignas_is_defined
+#include
+#endif
+#include "flatcc/flatcc_prologue.h"
+#ifndef flatbuffers_identifier
+#define flatbuffers_identifier 0
+#endif
+#ifndef flatbuffers_extension
+#define flatbuffers_extension ".bin"
+#endif
+
+
+
+typedef int8_t AzureIoTSecurity_ProcessEventType_enum_t;
+__flatbuffers_define_integer_type(AzureIoTSecurity_ProcessEventType, AzureIoTSecurity_ProcessEventType_enum_t, 8)
+#define AzureIoTSecurity_ProcessEventType_FORK ((AzureIoTSecurity_ProcessEventType_enum_t)INT8_C(0))
+#define AzureIoTSecurity_ProcessEventType_EXEC ((AzureIoTSecurity_ProcessEventType_enum_t)INT8_C(1))
+#define AzureIoTSecurity_ProcessEventType_EXIT ((AzureIoTSecurity_ProcessEventType_enum_t)INT8_C(2))
+
+static inline const char *AzureIoTSecurity_ProcessEventType_name(AzureIoTSecurity_ProcessEventType_enum_t value)
+{
+ switch (value) {
+ case AzureIoTSecurity_ProcessEventType_FORK: return "FORK";
+ case AzureIoTSecurity_ProcessEventType_EXEC: return "EXEC";
+ case AzureIoTSecurity_ProcessEventType_EXIT: return "EXIT";
+ default: return "";
+ }
+}
+
+static inline int AzureIoTSecurity_ProcessEventType_is_known_value(AzureIoTSecurity_ProcessEventType_enum_t value)
+{
+ switch (value) {
+ case AzureIoTSecurity_ProcessEventType_FORK: return 1;
+ case AzureIoTSecurity_ProcessEventType_EXEC: return 1;
+ case AzureIoTSecurity_ProcessEventType_EXIT: return 1;
+ default: return 0;
+ }
+}
+
+
+
+
+#include "flatcc/flatcc_epilogue.h"
+#endif /* PROCESS_EVENT_TYPE_READER_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_json_parser.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_json_parser.h
new file mode 100644
index 00000000..8ab1e1f5
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_json_parser.h
@@ -0,0 +1,337 @@
+#ifndef PROCESS_JSON_PARSER_H
+#define PROCESS_JSON_PARSER_H
+
+/* Generated by flatcc 0.6.1-dev FlatBuffers schema compiler for C by dvide.com */
+
+#include "flatcc/flatcc_json_parser.h"
+#ifndef PROCESS_EVENT_TYPE_JSON_PARSER_H
+#include "process_event_type_json_parser.h"
+#endif
+#include "flatcc/flatcc_prologue.h"
+
+static const char *AzureIoTSecurity_Process_parse_json_table(flatcc_json_parser_t *ctx, const char *buf, const char *end, flatcc_builder_ref_t *result);
+static const char *process_local_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+int *value_type, uint64_t *value, int *aggregate);
+static const char *process_local_AzureIoTSecurity_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+int *value_type, uint64_t *value, int *aggregate);
+static const char *process_global_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_type, uint64_t *value, int *aggregate);
+
+static const char *AzureIoTSecurity_Process_parse_json_table(flatcc_json_parser_t *ctx, const char *buf, const char *end, flatcc_builder_ref_t *result)
+{
+ int more;
+ void *pval;
+ flatcc_builder_ref_t ref, *pref;
+ const char *mark;
+ uint64_t w;
+
+ *result = 0;
+ if (flatcc_builder_start_table(ctx->ctx, 8)) goto failed;
+ buf = flatcc_json_parser_object_start(ctx, buf, end, &more);
+ while (more) {
+ buf = flatcc_json_parser_symbol_start(ctx, buf, end);
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w < 0x6869745f636f756e) { /* branch "hit_coun" */
+ if (w < 0x6576656e745f7479) { /* branch "event_ty" */
+ if (w == 0x636f6d6d616e646c) { /* descend "commandl" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xffffff0000000000) == 0x696e650000000000) { /* "ine" */
+ buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 3);
+ if (mark != buf) {
+ buf = flatcc_json_parser_build_string(ctx, buf, end, &ref);
+ if (!ref || !(pref = flatcc_builder_table_add_offset(ctx->ctx, 5))) goto failed;
+ *pref = ref;
+ } else {
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ }
+ } else { /* "ine" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* "ine" */
+ } else { /* descend "commandl" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* descend "commandl" */
+ } else { /* branch "event_ty" */
+ if (w == 0x6576656e745f7479) { /* descend "event_ty" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xffff000000000000) == 0x7065000000000000) { /* "pe" */
+ buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 2);
+ if (mark != buf) {
+ int8_t val = 0;
+ static flatcc_json_parser_integral_symbol_f *symbolic_parsers[] = {
+ AzureIoTSecurity_ProcessEventType_parse_json_enum,
+ process_local_AzureIoTSecurity_json_parser_enum,
+ process_global_json_parser_enum, 0 };
+ buf = flatcc_json_parser_int8(ctx, (mark = buf), end, &val);
+ if (mark == buf) {
+ buf = flatcc_json_parser_symbolic_int8(ctx, (mark = buf), end, symbolic_parsers, &val);
+ if (buf == mark || buf == end) goto failed;
+ }
+ if (val != 0 || (ctx->flags & flatcc_json_parser_f_force_add)) {
+ if (!(pval = flatcc_builder_table_add(ctx->ctx, 6, 1, 1))) goto failed;
+ flatbuffers_int8_write_to_pe(pval, val);
+ }
+ } else {
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ }
+ } else { /* "pe" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* "pe" */
+ } else { /* descend "event_ty" */
+ if (w == 0x6578656375746162) { /* descend "executab" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xffff000000000000) == 0x6c65000000000000) { /* "le" */
+ buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 2);
+ if (mark != buf) {
+ buf = flatcc_json_parser_build_string(ctx, buf, end, &ref);
+ if (!ref || !(pref = flatcc_builder_table_add_offset(ctx->ctx, 0))) goto failed;
+ *pref = ref;
+ } else {
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ }
+ } else { /* "le" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* "le" */
+ } else { /* descend "executab" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* descend "executab" */
+ } /* descend "event_ty" */
+ } /* branch "event_ty" */
+ } else { /* branch "hit_coun" */
+ if (w < 0x70726f636573735f) { /* branch "process_" */
+ if (w == 0x6869745f636f756e) { /* descend "hit_coun" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xff00000000000000) == 0x7400000000000000) { /* "t" */
+ buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 1);
+ if (mark != buf) {
+ uint32_t val = 0;
+ static flatcc_json_parser_integral_symbol_f *symbolic_parsers[] = {
+ process_local_AzureIoTSecurity_json_parser_enum,
+ process_global_json_parser_enum, 0 };
+ buf = flatcc_json_parser_uint32(ctx, (mark = buf), end, &val);
+ if (mark == buf) {
+ buf = flatcc_json_parser_symbolic_uint32(ctx, (mark = buf), end, symbolic_parsers, &val);
+ if (buf == mark || buf == end) goto failed;
+ }
+ if (val != 1 || (ctx->flags & flatcc_json_parser_f_force_add)) {
+ if (!(pval = flatcc_builder_table_add(ctx->ctx, 7, 4, 4))) goto failed;
+ flatbuffers_uint32_write_to_pe(pval, val);
+ }
+ } else {
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ }
+ } else { /* "t" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* "t" */
+ } else { /* descend "hit_coun" */
+ if (w == 0x706172656e745f70) { /* descend "parent_p" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x726f636573735f69) { /* descend "rocess_i" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xff00000000000000) == 0x6400000000000000) { /* "d" */
+ buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 1);
+ if (mark != buf) {
+ uint32_t val = 0;
+ static flatcc_json_parser_integral_symbol_f *symbolic_parsers[] = {
+ process_local_AzureIoTSecurity_json_parser_enum,
+ process_global_json_parser_enum, 0 };
+ buf = flatcc_json_parser_uint32(ctx, (mark = buf), end, &val);
+ if (mark == buf) {
+ buf = flatcc_json_parser_symbolic_uint32(ctx, (mark = buf), end, symbolic_parsers, &val);
+ if (buf == mark || buf == end) goto failed;
+ }
+ if (val != 0 || (ctx->flags & flatcc_json_parser_f_force_add)) {
+ if (!(pval = flatcc_builder_table_add(ctx->ctx, 2, 4, 4))) goto failed;
+ flatbuffers_uint32_write_to_pe(pval, val);
+ }
+ } else {
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ }
+ } else { /* "d" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* "d" */
+ } else { /* descend "rocess_i" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* descend "rocess_i" */
+ } else { /* descend "parent_p" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* descend "parent_p" */
+ } /* descend "hit_coun" */
+ } else { /* branch "process_" */
+ if (w < 0x757365725f696400) { /* branch "user_id" */
+ if (w == 0x70726f636573735f) { /* descend "process_" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xffff000000000000) == 0x6964000000000000) { /* "id" */
+ buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 2);
+ if (mark != buf) {
+ uint32_t val = 0;
+ static flatcc_json_parser_integral_symbol_f *symbolic_parsers[] = {
+ process_local_AzureIoTSecurity_json_parser_enum,
+ process_global_json_parser_enum, 0 };
+ buf = flatcc_json_parser_uint32(ctx, (mark = buf), end, &val);
+ if (mark == buf) {
+ buf = flatcc_json_parser_symbolic_uint32(ctx, (mark = buf), end, symbolic_parsers, &val);
+ if (buf == mark || buf == end) goto failed;
+ }
+ if (val != 0 || (ctx->flags & flatcc_json_parser_f_force_add)) {
+ if (!(pval = flatcc_builder_table_add(ctx->ctx, 1, 4, 4))) goto failed;
+ flatbuffers_uint32_write_to_pe(pval, val);
+ }
+ } else {
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ }
+ } else { /* "id" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* "id" */
+ } else { /* descend "process_" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* descend "process_" */
+ } else { /* branch "user_id" */
+ if ((w & 0xffffffffffffff00) == 0x757365725f696400) { /* "user_id" */
+ buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 7);
+ if (mark != buf) {
+ uint32_t val = 0;
+ static flatcc_json_parser_integral_symbol_f *symbolic_parsers[] = {
+ process_local_AzureIoTSecurity_json_parser_enum,
+ process_global_json_parser_enum, 0 };
+ buf = flatcc_json_parser_uint32(ctx, (mark = buf), end, &val);
+ if (mark == buf) {
+ buf = flatcc_json_parser_symbolic_uint32(ctx, (mark = buf), end, symbolic_parsers, &val);
+ if (buf == mark || buf == end) goto failed;
+ }
+ if (val != 0 || (ctx->flags & flatcc_json_parser_f_force_add)) {
+ if (!(pval = flatcc_builder_table_add(ctx->ctx, 3, 4, 4))) goto failed;
+ flatbuffers_uint32_write_to_pe(pval, val);
+ }
+ } else {
+ goto pfguard1;
+ }
+ } else { /* "user_id" */
+ goto pfguard1;
+ } /* "user_id" */
+ goto endpfguard1;
+pfguard1:
+ if (w == 0x757365725f6e616d) { /* descend "user_nam" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xff00000000000000) == 0x6500000000000000) { /* "e" */
+ buf = flatcc_json_parser_match_symbol(ctx, (mark = buf), end, 1);
+ if (mark != buf) {
+ buf = flatcc_json_parser_build_string(ctx, buf, end, &ref);
+ if (!ref || !(pref = flatcc_builder_table_add_offset(ctx->ctx, 4))) goto failed;
+ *pref = ref;
+ } else {
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ }
+ } else { /* "e" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* "e" */
+ } else { /* descend "user_nam" */
+ buf = flatcc_json_parser_unmatched_symbol(ctx, buf, end);
+ } /* descend "user_nam" */
+endpfguard1:
+ (void)0;
+ } /* branch "user_id" */
+ } /* branch "process_" */
+ } /* branch "hit_coun" */
+ buf = flatcc_json_parser_object_end(ctx, buf, end, &more);
+ }
+ if (ctx->error) goto failed;
+ if (!(*result = flatcc_builder_end_table(ctx->ctx))) goto failed;
+ return buf;
+failed:
+ return flatcc_json_parser_set_error(ctx, buf, end, flatcc_json_parser_error_runtime);
+}
+
+static inline int AzureIoTSecurity_Process_parse_json_as_root(flatcc_builder_t *B, flatcc_json_parser_t *ctx, const char *buf, size_t bufsiz, int flags, const char *fid)
+{
+ return flatcc_json_parser_table_as_root(B, ctx, buf, bufsiz, flags, fid, AzureIoTSecurity_Process_parse_json_table);
+}
+
+static const char *process_local_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_type, uint64_t *value, int *aggregate)
+{
+ /* Scope has no enum / union types to look up. */
+ return buf; /* unmatched; */
+}
+
+static const char *process_local_AzureIoTSecurity_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_type, uint64_t *value, int *aggregate)
+{
+ const char *unmatched = buf;
+ const char *mark;
+ uint64_t w;
+
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x50726f6365737345) { /* descend "ProcessE" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x76656e7454797065) { /* "ventType" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 8);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_ProcessEventType_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* "ventType" */
+ return unmatched;
+ } /* "ventType" */
+ } else { /* descend "ProcessE" */
+ return unmatched;
+ } /* descend "ProcessE" */
+ return buf;
+}
+
+static const char *process_global_json_parser_enum(flatcc_json_parser_t *ctx, const char *buf, const char *end,
+ int *value_type, uint64_t *value, int *aggregate)
+{
+ const char *unmatched = buf;
+ const char *mark;
+ uint64_t w;
+
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x417a757265496f54) { /* descend "AzureIoT" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x5365637572697479) { /* descend "Security" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x2e50726f63657373) { /* descend ".Process" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if (w == 0x4576656e74547970) { /* descend "EventTyp" */
+ buf += 8;
+ w = flatcc_json_parser_symbol_part(buf, end);
+ if ((w & 0xff00000000000000) == 0x6500000000000000) { /* "e" */
+ buf = flatcc_json_parser_match_scope(ctx, (mark = buf), end, 1);
+ if (buf != mark) {
+ buf = AzureIoTSecurity_ProcessEventType_parse_json_enum(ctx, buf, end, value_type, value, aggregate);
+ } else {
+ return unmatched;
+ }
+ } else { /* "e" */
+ return unmatched;
+ } /* "e" */
+ } else { /* descend "EventTyp" */
+ return unmatched;
+ } /* descend "EventTyp" */
+ } else { /* descend ".Process" */
+ return unmatched;
+ } /* descend ".Process" */
+ } else { /* descend "Security" */
+ return unmatched;
+ } /* descend "Security" */
+ } else { /* descend "AzureIoT" */
+ return unmatched;
+ } /* descend "AzureIoT" */
+ return buf;
+}
+
+#include "flatcc/flatcc_epilogue.h"
+#endif /* PROCESS_JSON_PARSER_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_json_printer.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_json_printer.h
new file mode 100644
index 00000000..ae647275
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_json_printer.h
@@ -0,0 +1,32 @@
+#ifndef PROCESS_JSON_PRINTER_H
+#define PROCESS_JSON_PRINTER_H
+
+/* Generated by flatcc 0.6.1-dev FlatBuffers schema compiler for C by dvide.com */
+
+#include "flatcc/flatcc_json_printer.h"
+#ifndef PROCESS_EVENT_TYPE_JSON_PRINTER_H
+#include "process_event_type_json_printer.h"
+#endif
+#include "flatcc/flatcc_prologue.h"
+
+static void AzureIoTSecurity_Process_print_json_table(flatcc_json_printer_t *ctx, flatcc_json_printer_table_descriptor_t *td);
+
+static void AzureIoTSecurity_Process_print_json_table(flatcc_json_printer_t *ctx, flatcc_json_printer_table_descriptor_t *td)
+{
+ flatcc_json_printer_string_field(ctx, td, 0, "executable", 10);
+ flatcc_json_printer_uint32_field(ctx, td, 1, "process_id", 10, 0);
+ flatcc_json_printer_uint32_field(ctx, td, 2, "parent_process_id", 17, 0);
+ flatcc_json_printer_uint32_field(ctx, td, 3, "user_id", 7, 0);
+ flatcc_json_printer_string_field(ctx, td, 4, "user_name", 9);
+ flatcc_json_printer_string_field(ctx, td, 5, "commandline", 11);
+ flatcc_json_printer_int8_enum_field(ctx, td, 6, "event_type", 10, 0, AzureIoTSecurity_ProcessEventType_print_json_enum);
+ flatcc_json_printer_uint32_field(ctx, td, 7, "hit_count", 9, 1);
+}
+
+static inline int AzureIoTSecurity_Process_print_json_as_root(flatcc_json_printer_t *ctx, const void *buf, size_t bufsiz, const char *fid)
+{
+ return flatcc_json_printer_table_as_root(ctx, buf, bufsiz, fid, AzureIoTSecurity_Process_print_json_table);
+}
+
+#include "flatcc/flatcc_epilogue.h"
+#endif /* PROCESS_JSON_PRINTER_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_reader.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_reader.h
new file mode 100644
index 00000000..9d6e7beb
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/process_reader.h
@@ -0,0 +1,60 @@
+#ifndef PROCESS_READER_H
+#define PROCESS_READER_H
+
+/* Generated by flatcc 0.6.1-dev FlatBuffers schema compiler for C by dvide.com */
+
+#ifndef FLATBUFFERS_COMMON_READER_H
+#include "flatbuffers_common_reader.h"
+#endif
+#ifndef PROCESS_EVENT_TYPE_READER_H
+#include "process_event_type_reader.h"
+#endif
+#include "flatcc/flatcc_flatbuffers.h"
+#ifndef __alignas_is_defined
+#include
+#endif
+#include "flatcc/flatcc_prologue.h"
+#ifndef flatbuffers_identifier
+#define flatbuffers_identifier 0
+#endif
+#ifndef flatbuffers_extension
+#define flatbuffers_extension ".bin"
+#endif
+
+
+typedef const struct AzureIoTSecurity_Process_table *AzureIoTSecurity_Process_table_t;
+typedef struct AzureIoTSecurity_Process_table *AzureIoTSecurity_Process_mutable_table_t;
+typedef const flatbuffers_uoffset_t *AzureIoTSecurity_Process_vec_t;
+typedef flatbuffers_uoffset_t *AzureIoTSecurity_Process_mutable_vec_t;
+#ifndef AzureIoTSecurity_Process_file_identifier
+#define AzureIoTSecurity_Process_file_identifier flatbuffers_identifier
+#endif
+/* deprecated, use AzureIoTSecurity_Process_file_identifier */
+#ifndef AzureIoTSecurity_Process_identifier
+#define AzureIoTSecurity_Process_identifier flatbuffers_identifier
+#endif
+#define AzureIoTSecurity_Process_type_hash ((flatbuffers_thash_t)0x9577302d)
+#define AzureIoTSecurity_Process_type_identifier "\x2d\x30\x77\x95"
+
+
+
+struct AzureIoTSecurity_Process_table { uint8_t unused__; };
+
+static inline size_t AzureIoTSecurity_Process_vec_len(AzureIoTSecurity_Process_vec_t vec)
+__flatbuffers_vec_len(vec)
+static inline AzureIoTSecurity_Process_table_t AzureIoTSecurity_Process_vec_at(AzureIoTSecurity_Process_vec_t vec, size_t i)
+__flatbuffers_offset_vec_at(AzureIoTSecurity_Process_table_t, vec, i, 0)
+__flatbuffers_table_as_root(AzureIoTSecurity_Process)
+
+__flatbuffers_define_string_field(0, AzureIoTSecurity_Process, executable, 0)
+__flatbuffers_define_scalar_field(1, AzureIoTSecurity_Process, process_id, flatbuffers_uint32, uint32_t, UINT32_C(0))
+__flatbuffers_define_scalar_field(2, AzureIoTSecurity_Process, parent_process_id, flatbuffers_uint32, uint32_t, UINT32_C(0))
+__flatbuffers_define_scalar_field(3, AzureIoTSecurity_Process, user_id, flatbuffers_uint32, uint32_t, UINT32_C(0))
+__flatbuffers_define_string_field(4, AzureIoTSecurity_Process, user_name, 0)
+__flatbuffers_define_string_field(5, AzureIoTSecurity_Process, commandline, 0)
+__flatbuffers_define_scalar_field(6, AzureIoTSecurity_Process, event_type, AzureIoTSecurity_ProcessEventType, AzureIoTSecurity_ProcessEventType_enum_t, INT8_C(0))
+__flatbuffers_define_scalar_field(7, AzureIoTSecurity_Process, hit_count, flatbuffers_uint32, uint32_t, UINT32_C(1))
+
+
+#include "flatcc/flatcc_epilogue.h"
+#endif /* PROCESS_READER_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/version.txt b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/version.txt
new file mode 100644
index 00000000..bb576dbd
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/schema/version.txt
@@ -0,0 +1 @@
+2.3
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/security_message.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/security_message.h
index 6b535ce3..fb340441 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/security_message.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/model/security_message.h
@@ -1,9 +1,22 @@
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
+
#ifndef SECURITY_MESSAGE_H
#define SECURITY_MESSAGE_H
#include
#include
+#include
+
#include "asc_security_core/asc_result.h"
typedef struct {
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/object_pool.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/object_pool.h
index db8edac9..f42fa2e2 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/object_pool.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/object_pool.h
@@ -1,28 +1,25 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef OBJECT_POOL_H
#define OBJECT_POOL_H
+#include
#include "asc_security_core/utils/collection/collection.h"
#include "asc_security_core/utils/collection/stack.h"
-#include "asc_security_core/configuration.h"
-#ifdef DYNAMIC_MEMORY_ENABLED
+#ifdef ASC_DYNAMIC_MEMORY_ENABLED
#include "asc_security_core/object_pool_dynamic.h"
#else
#include "asc_security_core/object_pool_static.h"
#endif
-#define object_pool_get(type) object_pool_##type##_get()
-#define object_pool_free(type,object) object_pool_##type##_free(object)
-
#endif /* OBJECT_POOL_H */
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/object_pool_def.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/object_pool_def.h
new file mode 100644
index 00000000..0cbbfa29
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/object_pool_def.h
@@ -0,0 +1,30 @@
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
+
+#ifndef OBJECT_POOL_DEF_H
+#define OBJECT_POOL_DEF_H
+
+#include
+
+#include
+
+#include "asc_security_core/utils/collection/stack.h"
+
+typedef struct {
+ bool initialized;
+ stack_collection_t stack;
+ size_t item_size;
+ size_t size;
+ size_t current_size;
+ size_t failures;
+} object_pool_t;
+
+#endif /* OBJECT_POOL_DEF_H */
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/object_pool_dynamic.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/object_pool_dynamic.h
index 29856977..40fbf1ff 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/object_pool_dynamic.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/object_pool_dynamic.h
@@ -1,49 +1,56 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef OBJECT_POOL_DYNAMIC_H
#define OBJECT_POOL_DYNAMIC_H
-#include
-#include
#include
-#include "asc_security_core/logger.h"
+#include
+#include "asc_security_core/object_pool_def.h"
+
+/* Pay your attention, that this implementation is not thread safe. */
+
+/* The "type" in OBJECT_POOL_DECLARATIONS(type) OBJECT_POOL_DEFINITIONS(type) macros MUST be from following type:
+typedef struct NAME_OF_DATA_FOR_LINKED_LIST_t {
+ // This macro must be first in object
+ COLLECTION_INTERFACE(struct NAME_OF_DATA_FOR_LINKED_LIST_t);
+ < Any data >
+} NAME_OF_DATA_FOR_LINKED_LIST_t;
+*/
#define OBJECT_POOL_DECLARATIONS(type)\
-type *object_pool_##type##_get();\
-void object_pool_##type##_free(type *object);\
+extern type _##type##_pool_test;\
+extern object_pool_t _##type##_pool_obj;
#define OBJECT_POOL_DEFINITIONS(type, pool_size)\
-static uint32_t _##type##_pool_size = pool_size;\
-static uint32_t _##type##_current_pool_size = 0;\
-type *object_pool_##type##_get() \
-{\
- if ((_##type##_current_pool_size) >= (_##type##_pool_size)) {\
- log_debug("Pool exceeded objects count %d size %d", _##type##_current_pool_size, _##type##_pool_size); \
- return NULL;\
- }\
- (_##type##_current_pool_size)++;\
- return (type*)malloc(sizeof(type));\
-}\
-void object_pool_##type##_free(type *obj) \
-{\
- if (obj) { \
- if (_##type##_current_pool_size == 0) { \
- log_fatal("Invalid memory free"); \
- } else { \
- free(obj);\
- (_##type##_current_pool_size)--; \
- } \
- } \
-}\
+type _##type##_pool_test;\
+object_pool_t _##type##_pool_obj = {.item_size = sizeof(type), .size = pool_size, .initialized = false, .stack = {0}, .current_size = 0, .failures = 0};
+
+void *__object_pool_get(object_pool_t *pool, uintptr_t offset1, uintptr_t offset2);
+void __object_pool_free(object_pool_t *pool, void *obj);
+size_t __object_pool_get_available_size(object_pool_t *pool);
+
+#define object_pool_init(type) _##type##_pool_obj.initialized = true
+
+#define object_pool_get(type)\
+(type *)__object_pool_get((object_pool_t *)&_##type##_pool_obj, (uintptr_t)(&_##type##_pool_test), (uintptr_t)(&(_##type##_pool_test.previous)))
+
+#define object_pool_free(type, obj)\
+__object_pool_free((object_pool_t *)&_##type##_pool_obj, (void *)obj)
+
+/* Returns number of available objects of specific type.
+ * If the definition of pool (OBJECT_POOL_DEFINITIONS(type_t, 0)) was done with zero size - always returns SIZE_MAX.
+ */
+#define object_pool_get_available_size(type) \
+__object_pool_get_available_size((object_pool_t *)&_##type##_pool_obj)
#endif /* OBJECT_POOL_DYNAMIC_H */
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/object_pool_static.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/object_pool_static.h
index ee0165c5..9b1c8922 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/object_pool_static.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/object_pool_static.h
@@ -1,77 +1,53 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef OBJECT_POOL_STATIC_H
#define OBJECT_POOL_STATIC_H
-#include
-#include
#include
-#include "asc_security_core/logger.h"
+#include
-#define OBJECT_POOL_DEFINITIONS(type, pool_size)\
-STACK_DEFINITIONS(type)\
-static bool _##type##_is_pool_initialized = false;\
-static type _##type##_pool[pool_size];\
-static stack_##type _stack_##type = {0};\
-static stack_##type##_handle _stack_##type##_handle;\
-static uint32_t _##type##_pool_size = pool_size;\
-static uint32_t _##type##_current_pool_size = 0;\
-static uint32_t _##type##_failures = 0;\
-void object_pool_##type##_init() \
-{\
- if (_##type##_is_pool_initialized) {\
- return;\
- }\
-\
- _stack_##type##_handle = &(_stack_##type);\
- stack_##type##_init(_stack_##type##_handle);\
- for (uint32_t i=0; i= (_##type##_pool_size)) {\
- (_##type##_failures)++;\
- if ((_##type##_failures) % (_##type##_pool_size) == 0) {\
- log_debug("Pool exceeded objects [%d/%d] failures=[%d]", _##type##_current_pool_size, _##type##_pool_size, _##type##_failures); \
- }\
- return NULL;\
- }\
- (_##type##_current_pool_size)++;\
- return stack_##type##_pop(_stack_##type##_handle);\
-}\
-void object_pool_##type##_free(type *obj) \
-{\
- if (obj) { \
- if (_##type##_current_pool_size == 0) { \
- log_fatal("Invalid memory free"); \
- } else { \
- (_##type##_current_pool_size)--; \
- stack_##type##_push(_stack_##type##_handle, obj);\
- } \
- } \
-}\
+#include "asc_security_core/object_pool_def.h"
+
+/* Pay your attention, that this implementation is not thread safe. */
+/* The "type" in OBJECT_POOL_DECLARATIONS(type) OBJECT_POOL_DEFINITIONS(type) macros MUST be from following type:
+typedef struct NAME_OF_DATA_FOR_LINKED_LIST_t {
+ // This macro must be first in object
+ COLLECTION_INTERFACE(struct NAME_OF_DATA_FOR_LINKED_LIST_t);
+ < Any data >
+} NAME_OF_DATA_FOR_LINKED_LIST_t;
+*/
#define OBJECT_POOL_DECLARATIONS(type)\
-STACK_DECLARATIONS(type)\
-void object_pool_##type##_init();\
-type *object_pool_##type##_get();\
-void object_pool_##type##_free(type *obj);\
+extern type _##type##_pool[];\
+extern object_pool_t _##type##_pool_obj;
+
+#define OBJECT_POOL_DEFINITIONS(type, pool_size)\
+type _##type##_pool[pool_size];\
+object_pool_t _##type##_pool_obj = {.item_size = sizeof(type), .size = pool_size, .initialized = false, .stack = {0}, .current_size = 0, .failures = 0};
+
+void *__object_pool_get(object_pool_t *pool, uintptr_t offset1, uintptr_t offset2, uintptr_t objs);
+void __object_pool_free(object_pool_t *pool, void *obj);
+size_t __object_pool_get_available_size(object_pool_t *pool);
+
+#define object_pool_get(type) \
+(type *)__object_pool_get((object_pool_t *)&_##type##_pool_obj, (uintptr_t)(&_##type##_pool[0]), (uintptr_t)(&(_##type##_pool[0].previous)), (uintptr_t)_##type##_pool)
+
+#define object_pool_free(type, obj) \
+__object_pool_free((object_pool_t *)&_##type##_pool_obj, (void *)obj)
+
+/* Returns number of available objects of specific type. */
+#define object_pool_get_available_size(type) \
+__object_pool_get_available_size((object_pool_t *)&_##type##_pool_obj)
#endif /* OBJECT_POOL_STATIC_H */
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/serializer.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/serializer.h
index 2e0c7cc4..e5b7539b 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/serializer.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/serializer.h
@@ -1,13 +1,13 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef SERIALIZER_H
#define SERIALIZER_H
@@ -15,7 +15,8 @@
#include
#include
-#include "asc_security_core/configuration.h"
+#include
+
#include "asc_security_core/asc_result.h"
#include "asc_security_core/model/objects/objects.h"
@@ -117,7 +118,7 @@ typedef struct serializer serializer_t;
* On success sets state to: SERIALIZER_STATE_INITIALIZED
* @return A new serializer
*/
-serializer_t *serializer_init();
+serializer_t *serializer_init(void);
/**
* @brief Deinitialize a serializer
@@ -163,7 +164,25 @@ asc_result_t serializer_message_begin(serializer_t *serializer, const char *secu
*/
asc_result_t serializer_message_end(serializer_t *serializer);
-#ifdef COLLECTOR_NETWORK_ACTIVITY_ENABLED
+#ifdef ASC_COLLECTOR_LOG_ENABLED
+/**
+ * @brief Adds a Log event to current message.
+ * Callable from states: SERIALIZER_STATE_INITIALIZED, SERIALIZER_STATE_MESSAGE_PROCESSING
+ * On success sets state to: SERIALIZER_STATE_MESSAGE_PROCESSING
+ *
+ * @param serializer The serializer
+ * @param timestamp The event timestamp
+ * @param collection_interval The collection interval
+ * @param report_list_iter The log report list iterator
+ *
+ * @return ASC_RESULT_OK on success,
+ * ASC_RESULT_BAD_ARGUMENT if @a serializer is NULL
+ * ASC_RESULT_EXCEPTION otherwise
+ */
+asc_result_t serializer_event_add_log(serializer_t *serializer, unsigned long timestamp, unsigned long collection_interval, log_fetcher_t *fetcher);
+#endif
+
+#ifdef ASC_COLLECTOR_NETWORK_ACTIVITY_ENABLED
/**
* @brief Adds a network activity event to current message.
* Callable from states: SERIALIZER_STATE_INITIALIZED, SERIALIZER_STATE_MESSAGE_PROCESSING
@@ -179,12 +198,29 @@ asc_result_t serializer_message_end(serializer_t *serializer);
* ASC_RESULT_BAD_ARGUMENT if @a serializer is NULL
* ASC_RESULT_EXCEPTION otherwise
*/
-asc_result_t serializer_event_add_network_activity(serializer_t *serializer, uint32_t timestamp, uint32_t collection_interval,
+asc_result_t serializer_event_add_network_activity(serializer_t *serializer, unsigned long timestamp, unsigned long collection_interval,
network_activity_ipv4_t *ipv4_payload, network_activity_ipv6_t *ipv6_payload);
#endif
+#ifdef ASC_COLLECTOR_PROCESS_ENABLED
+/**
+ * @brief Adds a process event to the current message.
+ * Callable from states: SERIALIZER_STATE_INITIALIZED, SERIALIZER_STATE_MESSAGE_PROCESSING
+ * On success sets state to: SERIALIZER_STATE_MESSAGE_PROCESSING
+ *
+ * @param serializer The serializer
+ * @param timestamp The event timestamp
+ * @param collection_interval The collection interval
+ * @param payload The process payload object
+ *
+ * @return ASC_RESULT_OK on success,
+ * ASC_RESULT_BAD_ARGUMENT if @a serializer is NULL
+ * ASC_RESULT_EXCEPTION otherwise
+ */
+asc_result_t serializer_event_add_process(serializer_t *serializer, unsigned long timestamp, unsigned long collection_interval, process_t *payload);
+#endif
-#ifdef COLLECTOR_SYSTEM_INFORMATION_ENABLED
+#ifdef ASC_COLLECTOR_SYSTEM_INFORMATION_ENABLED
/**
* @brief Adds a system information event to current message.
* Callable from states: SERIALIZER_STATE_INITIALIZED, SERIALIZER_STATE_MESSAGE_PROCESSING
@@ -199,12 +235,12 @@ asc_result_t serializer_event_add_network_activity(serializer_t *serializer, uin
* ASC_RESULT_BAD_ARGUMENT if @a serializer is NULL
* ASC_RESULT_EXCEPTION otherwise
*/
-asc_result_t serializer_event_add_system_information(serializer_t *serializer, uint32_t timestamp, uint32_t collection_interval,
+asc_result_t serializer_event_add_system_information(serializer_t *serializer, unsigned long timestamp, unsigned long collection_interval,
system_information_t *payload);
#endif
-#ifdef COLLECTOR_HEARTBEAT_ENABLED
+#ifdef ASC_COLLECTOR_HEARTBEAT_ENABLED
/**
* @brief Adds a heartbeat event to current message.
* Callable from states: SERIALIZER_STATE_MESSAGE_READY
@@ -217,11 +253,11 @@ asc_result_t serializer_event_add_system_information(serializer_t *serializer, u
* ASC_RESULT_BAD_ARGUMENT if @a serializer is NULL
* ASC_RESULT_EXCEPTION otherwise
*/
-asc_result_t serializer_event_add_heartbeat(serializer_t *serializer, uint32_t timestamp, uint32_t collection_interval);
+asc_result_t serializer_event_add_heartbeat(serializer_t *serializer, unsigned long timestamp, unsigned long collection_interval);
#endif
-#ifdef COLLECTOR_LISTENING_PORTS_ENABLED
+#ifdef ASC_COLLECTOR_LISTENING_PORTS_ENABLED
/**
* @brief Adds a listening ports event to current message.
* Callable from states: SERIALIZER_STATE_INITIALIZED, SERIALIZER_STATE_MESSAGE_PROCESSING
@@ -237,11 +273,11 @@ asc_result_t serializer_event_add_heartbeat(serializer_t *serializer, uint32_t t
* ASC_RESULT_BAD_ARGUMENT if @a serializer is NULL
* ASC_RESULT_EXCEPTION otherwise
*/
-asc_result_t serializer_event_add_listening_ports(serializer_t *serializer, uint32_t timestamp, uint32_t collection_interval,
+asc_result_t serializer_event_add_listening_ports(serializer_t *serializer, unsigned long timestamp, unsigned long collection_interval,
listening_ports_ipv4_t *ipv4_payload, listening_ports_ipv6_t *ipv6_payload);
#endif
-#ifdef COLLECTOR_BASELINE_ENABLED
+#ifdef ASC_COLLECTOR_BASELINE_ENABLED
/**
* @brief Adds a Baseline event to current message.
* Callable from states: SERIALIZER_STATE_INITIALIZED, SERIALIZER_STATE_MESSAGE_PROCESSING
@@ -256,7 +292,7 @@ asc_result_t serializer_event_add_listening_ports(serializer_t *serializer, uint
* ASC_RESULT_BAD_ARGUMENT if @a serializer is NULL
* ASC_RESULT_EXCEPTION otherwise
*/
-asc_result_t serializer_event_add_baseline(serializer_t *serializer, uint32_t timestamp, uint32_t collection_interval, linked_list_iterator_baseline_report_t *report_list_iter);
+asc_result_t serializer_event_add_baseline(serializer_t *serializer, unsigned long timestamp, unsigned long collection_interval, linked_list_t *report_list);
#endif
/**
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/serializer/custom_builder_allocator.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/serializer/custom_builder_allocator.h
new file mode 100644
index 00000000..28e6cc6c
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/serializer/custom_builder_allocator.h
@@ -0,0 +1,22 @@
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
+#include
+
+#ifndef CUSTOM_BUILDER_ALLOCATOR_H
+#define CUSTOM_BUILDER_ALLOCATOR_H
+
+#include "flatcc/flatcc_builder.h"
+
+int serializer_custom_allocator(void *alloc_context, flatcc_iovec_t *b, size_t request, int zero_fill, int alloc_type);
+
+void serializer_custom_allocator_reset(void);
+
+#endif /* CUSTOM_BUILDER_ALLOCATOR_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/serializer/page_allocator.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/serializer/page_allocator.h
new file mode 100644
index 00000000..2d1255be
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/serializer/page_allocator.h
@@ -0,0 +1,38 @@
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
+
+#ifndef PAGE_ALLOCATOR_H
+#define PAGE_ALLOCATOR_H
+
+#include
+
+#include
+
+#ifdef ASC_COLLECTOR_PROCESS_ENABLED
+#include "asc_security_core/model/objects/process.h"
+#define COLLECTOR_PROCESS_SIZE (ASC_COLLECTOR_PROCESS_IN_CACHE * sizeof(process_t))
+#else
+#define COLLECTOR_PROCESS_SIZE 0
+#endif
+
+#define COLLECTOR_NETWORK_ACTIVITY_SIZE (ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV4_OBJECTS_IN_CACHE * 36 + \
+ ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE * 60)
+
+#define MAX_MESSAGE_SIZE (500 + COLLECTOR_NETWORK_ACTIVITY_SIZE + COLLECTOR_PROCESS_SIZE)
+
+#define MIN_PAGE_SIZE (MAX_MESSAGE_SIZE * 2)
+#define PAGE_MULTIPLE ((uint32_t)64)
+#define FLATCC_EMITTER_PAGE_SIZE ((MIN_PAGE_SIZE + (PAGE_MULTIPLE) - 1) & ~(2 * (PAGE_MULTIPLE) - 1))
+
+void *serializer_page_alloc(size_t size);
+void serializer_page_free(void *page);
+
+#endif /* PAGE_ALLOCATOR_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/async.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/async.h
deleted file mode 100644
index 7dd2baca..00000000
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/async.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
-
-#ifndef _ASYNC_H_
-#define _ASYNC_H_
-
-#include
-
-#include "asc_security_core/utils/collection/collection.h"
-#include "asc_security_core/utils/ievent_loop.h"
-
-#define ASYNC_ERROR_LEN 50
-
-typedef enum {
- // must be first
- ASYNC_PENDING = 0,
- ASYNC_IN_PROGRESS,
- ASYNC_FAIL
-} async_status_t;
-
-/** @brief A callback function called when asynchronous operation is done */
-typedef void (*event_loop_done_cb_t)(void *ctx);
-
-typedef struct async_t{
- COLLECTION_INTERFACE(struct async_t);
-
- event_loop_timer_cb_t func;
- event_loop_timer_handler timer;
- event_loop_done_cb_t done_callback;
- uint8_t retry;
- async_status_t status;
- char err[ASYNC_ERROR_LEN];
-
- void *ctx;
-} async_t;
-
-#endif /* _ASYNC_H_ */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/collection/bit_vector.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/collection/bit_vector.h
new file mode 100644
index 00000000..f9dc46c9
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/collection/bit_vector.h
@@ -0,0 +1,92 @@
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
+
+#ifndef __BIT_VECTOR_H__
+#define __BIT_VECTOR_H__
+
+#include
+
+#include
+
+#define __BV_VEC_IND(index) (index>>3)
+#define __BV_VEC_SHIFT(index) (index & 0x07)
+#define __BV_CEIL_DIV8(x) ((x>>3)+(!!(x & 0x07)))
+
+#define BIT_VECTOR_DECLARATIONS(type, size) \
+typedef struct {\
+ char data[__BV_CEIL_DIV8(size)]; \
+} bit_vector_##type;
+
+/**
+ * @brief Set/Clear bit at index place.
+ *
+ * @param bit_vector The pointer on @c bit_vector_##type object.
+ * @param index The bit index.
+ * @param bit Value to set: true/false.
+ * @param size Bit vector size.
+ *
+ * @return false on overflow, otherwise true.
+ */
+bool __bit_vector_set(char bit_vector[], int index, bool bit, int size);
+
+/**
+ * @brief Get bit at index place.
+ *
+ * @param bit_vector The pointer on @c bit_vector_##type object.
+ * @param index The bit index.
+ * @param size Bit vector size.
+ *
+ * @return false on overflow, otherwise the actual value.
+ */
+bool __bit_vector_get(char bit_vector[], int index, int size);
+
+/**
+ * @brief Check if the vector is zero.
+ *
+ * @param bit_vector The pointer on @c bit_vector_##type object.
+ * @param size Bit vector size.
+ *
+ * @return true if all bits in vector are zero, otherwise false.
+ */
+bool __is_bit_vector_zero(char bit_vector[], int size);
+
+/**
+ * @brief Set the vector to zero.
+ *
+ * @param bit_vector The pointer on @c bit_vector_##type object.
+ * @param size Bit vector size.
+ *
+ * @return none.
+ */
+void __bit_vector_clean(char bit_vector[], int size);
+
+/**
+ * @brief Takes vector size in bits by type.
+ *
+ * @param bit_vector type
+ *
+ * @return vector size in bits.
+ */
+#define bit_vector_size(type) ((int)(sizeof(bit_vector_##type)<<3))
+
+#define bit_vector_set(type, bit_vector_ptr, index, bit) \
+__bit_vector_set((bit_vector_ptr)->data, index, bit, bit_vector_size(type))
+
+#define bit_vector_get(type, bit_vector_ptr, index) \
+__bit_vector_get((bit_vector_ptr)->data, index, bit_vector_size(type))
+
+#define is_bit_vector_zero(type, bit_vector_ptr) \
+__is_bit_vector_zero((bit_vector_ptr)->data, bit_vector_size(type))
+
+#define bit_vector_clean(type, bit_vector_ptr) \
+__bit_vector_clean((bit_vector_ptr)->data, bit_vector_size(type))
+
+#endif /* __BIT_VECTOR_H__ */
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/collection/collection.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/collection/collection.h
index 9bdcbe20..ec76b2cc 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/collection/collection.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/collection/collection.h
@@ -1,19 +1,27 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef COLLECTION_H
#define COLLECTION_H
+#include
+/* Pay your attention, that this implementation is not thread safe. */
+/* This macro must be first in object */
#define COLLECTION_INTERFACE(type)\
type *previous;\
type *next
+typedef struct {
+ /* This macro must be first in object */
+ COLLECTION_INTERFACE(void);
+} collection_item_t;
+
#endif /* COLLECTION_H */
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/collection/hashset.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/collection/hashset.h
index ae9f7b4c..76cca0ad 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/collection/hashset.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/collection/hashset.h
@@ -1,19 +1,21 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef HASHSET_H
#define HASHSET_H
#include
+#include
+
#include "asc_security_core/utils/collection/collection.h"
/**
@@ -28,7 +30,7 @@
* - hashset_##type##_update
*
* Additional Notes:
- * - Make sure the struct-type uses COLLECTION_INTERFACE (see collection.h)
+ * - Make sure the struct-type uses COLLECTION_INTERFACE (see collection.h) This macro must be first in object.
* - The Hashset does NOT allocate any memory
* - The size defined in HASHSET_DEFINITION is the expected size for any hashset instance
* - When implementing hashset_##type##_hash and hashset_##type##_equals, make sure that
@@ -129,7 +131,26 @@ extern int hashset_##type##_equals(type *a, type *b);
* \
* @return void \
*/ \
-extern void hashset_##type##_update(type *old_element, type *new_element);
+extern void hashset_##type##_update(type *old_element, type *new_element); \
+ \
+/** \
+ * @brief Get depth of hash to exam the hash function! \
+ * \
+ * @param table An initialized hashset \
+ * @param count Count of non null or one element linked lists (out parameter) \
+ * \
+ * @return zero if all hash elements have list with 0 or 1 length - otherwise the longest list length \
+ */ \
+unsigned int hashset_##type##_get_depth(type *table[], unsigned int *count); \
+ \
+/** \
+ * @brief Check if hash table is empty \
+ * \
+ * @param table An initialized hashset \
+ * \
+ * @return true if hash table is empty - otherwise false \
+ */ \
+ bool hashset_##type##_is_empty(type *table[]);
#define HASHSET_DEFINITIONS(type, size) \
void hashset_##type##_init(type *table[]) \
@@ -189,12 +210,13 @@ extern void hashset_##type##_add_or_update(type *table[], type *element)
void hashset_##type##_for_each(type *table[], hashset_##type##_for_each_function for_each_funcion, void *context) \
{ \
if (table == NULL || for_each_funcion == NULL) return; \
- type *current_element = NULL; \
+ type *current_element = NULL, *tmp = NULL; \
for (unsigned int i = 0; i < size; ++i) { \
current_element = table[i]; \
while (current_element != NULL) { \
+ tmp = current_element->next; \
for_each_funcion(current_element, context); \
- current_element = current_element->next; \
+ current_element = tmp; \
} \
} \
} \
@@ -218,6 +240,47 @@ void hashset_##type##_clear(type *table[], hashset_##type##_for_each_function fo
current_element = table[i]; \
} \
} \
+} \
+ \
+unsigned int hashset_##type##_get_depth(type *table[], unsigned int *count) \
+{ \
+ unsigned int max = 0; \
+ *count = 0; \
+ if (table == NULL) return max; \
+ type *current_element = NULL; \
+ for (unsigned int i = 0; i < size; ++i) { \
+ unsigned int cnt = 0; \
+ current_element = table[i]; \
+ while (current_element != NULL) { \
+ cnt++; \
+ current_element = current_element->next; \
+ } \
+ if (cnt > 1) { \
+ if (cnt > max) max = cnt; \
+ (*count)++; \
+ } \
+ } \
+ return max; \
+} \
+ \
+bool hashset_##type##_is_empty(type *table[]) \
+{ \
+ if (table == NULL) return true; \
+ for (unsigned int i = 0; i < size; ++i) { \
+ if (table[i]) return false; \
+ } \
+ return true; \
+}
+
+static inline unsigned int hashset_buffer2hash(const char *str, size_t len)
+{
+ unsigned int hash = 5381;
+
+ for (size_t i = 0 ; i < len; i++) {
+ hash = ((hash << 5) + hash) + (unsigned int)str[i];
+ }
+
+ return hash;
}
#endif /* HASHSET_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/collection/hashtable.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/collection/hashtable.h
new file mode 100644
index 00000000..665f9c5f
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/collection/hashtable.h
@@ -0,0 +1,204 @@
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
+
+#ifndef __HASHTABLE_H__
+#define __HASHTABLE_H__
+
+#include
+#include
+#include
+
+#include
+
+#include "asc_security_core/utils/collection/collection.h"
+
+/* Pay your attention, that this implementation is not thread safe. */
+
+#define HASH_KEY(_key) ((const void *)((uintptr_t)(_key)))
+
+/**
+ * @brief Typedef of hash function
+ *
+ * @param key Hash key
+ *
+ * @return hash value none normilized to size.
+ */
+typedef unsigned int (*hash_func_t)(const void *key);
+
+/**
+ * @brief Typedef of comparing function
+ *
+ * @param key Hash key calculated by @c hash_func_t provided to @c hashtable_init(...)
+ * @param item The item to compare
+ *
+ * @return true on equal, otherwise false
+ */
+typedef bool (*hash_equal_func_t)(const void *key, void *item);
+
+/**
+ * @brief Typedef of updating function
+ *
+ * @param a The old item
+ * @param b The new item
+ *
+ * @return none
+ */
+typedef void (*hash_update_func_t)(void *a, void *b);
+
+/**
+ * @brief Typedef of free function
+ *
+ * @param item The item to free
+ *
+ * @return none
+ */
+typedef void (*hash_free_func_t)(void *item);
+
+/**
+ * @brief Typedef of action function
+ *
+ * @param item The item for action
+ * @param ctx User context
+ *
+ * @return none
+ */
+typedef void (*hash_action_func_t)(void *item, void *ctx);
+
+typedef struct {
+ bool initialized; // single tone initializin flag
+ size_t size; /* Actual size of hashtable. MUST be between 1 and given in HASHTABLE_DECLARATIONS() macro.
+ * Warning: there is no size checking - so passing , that above will lead to crash */
+ hash_func_t hash_func;
+ hash_equal_func_t hash_equal_func;
+ hash_update_func_t hash_update_func;
+} hashtable_ctrl_t;
+
+#define HASHTABLE_DECLARATIONS(type, max_hash_size) \
+typedef struct { \
+ hashtable_ctrl_t ctrl; \
+ type *table[(max_hash_size)]; \
+} hashtable_##type;
+
+typedef struct {
+ hashtable_ctrl_t ctrl;
+ void *table[1];
+} hashtable_t;
+
+// API functions
+/**
+ * @brief Run time initialization of hashtable object
+ *
+ * @param hashtable Pointer on hashtable for initialization
+ * @param size Actual size of hashtable. MUST be between 1 and given in HASHTABLE_DECLARATIONS() macro.
+ * Warning: there is no size checking - so passing size, that above number
+ * that given in HASHTABLE_DECLARATIONS() will lead to crash
+ * @param hash_func Hash function. @c hash_func_t If NULL was passed the hashtable will use simple hashing formula (key%size)
+ * @param hash_equal_func Hash object comparing function. @c hash_equal_func_t If NULL was passed the hashtable will use default comparing (key == item)
+ * @param hash_update_func Hash object updating function. @c hash_update_func_t If NULL was passed the hashtable will use @c hashtable_update_none_func(...)
+ *
+ * @return true on success, otherwise false
+ */
+bool hashtable_init(hashtable_t *hashtable, size_t size, hash_func_t hash_func,
+ hash_equal_func_t hash_equal_func, hash_update_func_t hash_update_func);
+
+/**
+ * @brief Insert new hashtable item by key. If equal item was found by @c hash_equal_func_t the @c hash_update_func_t will performed
+ *
+ * @param hashtable A pointer on initialized hashtable
+ * @param key Hash key calculated by @c hash_func_t provided to @c hashtable_init(...)
+ * @param item Item to be inserted
+ *
+ * @return the pointer on inserted item on success, otherwise NULL.
+ */
+void *hashtable_insert(hashtable_t *hashtable, const void *key, void *item);
+
+/**
+ * @brief Remove hashtable item by key.
+ *
+ * @param hashtable A pointer on initialized hashtable
+ * @param key Hash key calculated by @c hash_func_t provided to @c hashtable_init(...)
+ * @param hash_free_func Free data function
+ *
+ * @return the pointer on removed item on success and if the hash_free_func == NULL, otherwise NULL.
+ */
+void *hashtable_remove(hashtable_t *hashtable, const void *key, hash_free_func_t hash_free_func);
+
+/**
+ * @brief Find hashtable item by key.
+ *
+ * @param hashtable A pointer on initialized hashtable
+ * @param key Hash key calculated by @c hash_func_t provided to @c hashtable_init(...)
+ *
+ * @return the pointer on found item on success, otherwise NULL.
+ */
+void *hashtable_find(hashtable_t *hashtable, const void *key);
+
+/**
+ * @brief Cleanup the hashtable.
+ *
+ * @param hashtable A pointer on initialized hashtable
+ * @param hash_free_func Free data function
+ *
+ * @return none
+ */
+void hashtable_flush(hashtable_t *hashtable, hash_free_func_t hash_free_func);
+
+/**
+ * @brief Runn over all hashtable items.
+ *
+ * @param hashtable A pointer on initialized hashtable
+ * @param hash_action_func Action callback to be called for each item
+ * @param ctx User contex to be passed to @c hash_action_func(...)
+ *
+ * @return none
+ */
+void hashtable_foreach(hashtable_t *hashtable, hash_action_func_t hash_action_func, void *ctx);
+
+/**
+ * @brief Get depth of hash to exam the hash function.
+ *
+ * @param hashtable A pointer on initialized hashtable
+ * @param count Count of non null or one element linked lists (out parameter)
+ *
+ * @return zero if all hash elements have list with 0 or 1 length - otherwise the longest list length
+ */
+size_t hashtable_get_depth(hashtable_t *hashtable, size_t *count);
+
+/**
+ * @brief Check if hash table is empty
+ *
+ * @param table A pointer on initialized hashset
+ *
+ * @return true if hash table is empty - otherwise false
+ */
+ bool hashtable_is_empty(hashtable_t *hashtable);
+
+/** @brief Run over specified column of hashtable **/
+#define hashtable_column_foreach(hashtable, iter, column) for (iter = (hashtable)->table[(column)]; (iter); iter = (iter)->next)
+
+/** @brief Init hashtable with default callbacks **/
+#define hashtable_init_simple(hashtable, size) hashtable_init(hashtable, size, NULL, NULL, NULL)
+
+// Service callbacks
+/** @brief The default @c hash_equal_func_t equal function returns true is if key equals to object pointer **/
+bool hashtable_equal_default_func(const void *key, void *item);
+
+/** @brief The 'key is NULL terminated string' @c hash_func_t hash generic function **/
+unsigned int hashtable_hash_str_default(const void *key);
+
+/** @brief The default @c hash_update_func_t hash update doing nothing function **/
+void hashtable_update_none_func(void *a, void *b);
+
+// Service functions
+/** @brief The default hash calculating function on char buffer **/
+unsigned int hashtable_buffer2hash(const char *buffer, size_t len);
+
+#endif // __HASHTABLE_H__
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/collection/linked_list.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/collection/linked_list.h
index df41f7d9..8e65b23c 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/collection/linked_list.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/collection/linked_list.h
@@ -1,22 +1,25 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef LINKED_LIST_H
#define LINKED_LIST_H
-#include "asc_security_core/utils/collection/collection.h"
#include
#include
#include
+#include
+
+#include "asc_security_core/utils/collection/collection.h"
+
#define LINKED_LIST_DECLARATIONS(type) \
typedef void (*linked_list_##type##_deinit_function)(type *item);\
typedef void (*linked_list_##type##_action)(type *item, void *context);\
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/collection/list.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/collection/list.h
new file mode 100644
index 00000000..fd850258
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/collection/list.h
@@ -0,0 +1,106 @@
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
+
+#ifndef __LIST_H__
+#define __LIST_H__
+
+#include
+#include
+
+#include
+
+#include "asc_security_core/utils/collection/collection.h"
+
+/* Pay your attention, that this implementation is not thread safe. */
+
+/**
+ * @brief Typedef of free function
+ *
+ * @param item The item to free
+ *
+ * @return none
+ */
+typedef void (*linked_list_free_cb)(void *item);
+
+/**
+ * @brief Typedef of condition function
+ *
+ * @param item The item to perform the condition
+ * @param condition_input The condition input
+ *
+ * @return true on confition is true, otherwise false
+ */
+typedef bool (*linked_list_condition_cb)(void *item, void *condition_input);
+
+/**
+ * @brief Typedef of updating function
+ *
+ * @param a The old item
+ * @param b The new item
+ *
+ * @return none
+ */
+typedef void (*linked_list_update_cb)(void *a, void *b);
+
+typedef struct linked_list_t {
+ collection_item_t *head;
+ collection_item_t *tail;
+ size_t size;
+ bool initialized;
+} linked_list_t;
+
+/* APIs */
+/* The void *data parameter for this implementation of linked list MUST be from following type:
+typedef struct NAME_OF_DATA_FOR_LINKED_LIST_t {
+ // This macro must be first in object
+ COLLECTION_INTERFACE(struct NAME_OF_DATA_FOR_LINKED_LIST_t);
+ < Any data >
+} NAME_OF_DATA_FOR_LINKED_LIST_t;
+*/
+
+/** @brief Add item to tail of linked list **/
+void *linked_list_add_last(linked_list_t *list, void *data);
+
+/** @brief Add item to head of linked list **/
+void *linked_list_add_first(linked_list_t *list, void *data);
+
+/** @brief Insert item before specified item of linked list. If 'before' item does not exist or NULL - add to tail **/
+void *linked_list_insert_before(linked_list_t *list, void *before, void *data);
+
+/** @brief Remove item from linked list. Returns the pointer on removed item on success and if the free_function == NULL, otherwise NULL **/
+void *linked_list_remove(linked_list_t *list, void *data, linked_list_free_cb free_function);
+
+/** @brief Add item to tail if not exists. If equal item was found by @c linked_list_condition_cb the @c linked_list_update_cb will performed **/
+void *linked_list_add_or_update(linked_list_t *list, linked_list_condition_cb condition_function,
+ linked_list_update_cb update_func, void *data);
+
+/** @brief Init linked list object **/
+void linked_list_init(linked_list_t *list);
+
+/** @brief Find linked list item that meets the conditions of @c linked_list_condition_cb and condition_input. Returns NULL on fail. **/
+void *linked_list_find(linked_list_t *list, linked_list_condition_cb condition_function, void *condition_input);
+
+/** @brief Get head item of linked list **/
+void *linked_list_get_first(linked_list_t *list);
+
+/** @brief Flush the linked list **/
+void linked_list_flush(linked_list_t *list, linked_list_free_cb free_function);
+
+/** @brief Get current size of linked list **/
+size_t linked_list_get_size(linked_list_t *list);
+
+/** @brief The default @c linked_list_condition_cb condition function returns true is if condition_input equals to item object pointer **/
+bool linked_list_condition_default(void *item, void *condition_input);
+
+/** @brief Run over linked list object **/
+#define linked_list_foreach(list, iter) for (iter = (void *)((list)->head); (iter); iter = (iter)->next)
+
+#endif /* __LIST_H__ */
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/collection/stack.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/collection/stack.h
index c76476cd..116093e9 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/collection/stack.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/collection/stack.h
@@ -1,73 +1,33 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef STACK_H
#define STACK_H
+#include
+#include
+
+#include
+
#include "asc_security_core/utils/collection/collection.h"
-#define STACK_DECLARATIONS(type) \
-typedef struct {\
- type *head;\
- size_t size;\
-} stack_##type;\
-typedef stack_##type *stack_##type##_handle;\
-extern void stack_##type##_init(stack_##type##_handle stack);\
-extern void stack_##type##_push(stack_##type##_handle stack, type *item);\
-extern type *stack_##type##_pop(stack_##type##_handle stack);\
-extern type *stack_##type##_peek(stack_##type##_handle stack);\
+/* Pay your attention, that this implementation is not thread safe. */
+
+typedef struct {
+ collection_item_t *head;
+ size_t size;
+} stack_collection_t;
-#define STACK_DEFINITIONS(type) \
-extern void stack_##type##_init(stack_##type##_handle stack) \
-{\
- if ((stack) == NULL) {\
- return;\
- }\
- (stack)->head = NULL;\
- (stack)->size = 0;\
-}\
-void stack_##type##_push(stack_##type##_handle stack, type *item) \
-{\
- type *current_head = (stack)->head;\
- if ((current_head) == NULL) {\
- (stack)->head = item;\
- (item)->next = NULL;\
- (item)->previous = NULL;\
- (stack)->size++;\
- return;\
- }\
- (item)->next = current_head;\
- (item)->previous = NULL;\
- (current_head)->previous = item;\
- (stack)->head = item;\
- (stack)->size++;\
- return;\
-}\
-type *stack_##type##_pop(stack_##type##_handle stack) \
-{\
- type *current_head = (stack)->head;\
- if ((current_head) == NULL) {\
- return NULL;\
- }\
- type *new_head = (current_head)->next;\
- (current_head)->previous = (current_head)->next = NULL;\
- if ((new_head) != NULL) {\
- (new_head)->previous = NULL;\
- }\
- (stack)->head = new_head;\
- return current_head;\
-}\
-type *stack_##type##_peek(stack_##type##_handle stack) \
-{\
- return (stack)->head;\
-}\
+void stack_push(stack_collection_t *stack, collection_item_t *item);
+collection_item_t * stack_pop(stack_collection_t *stack);
+collection_item_t * stack_peek(stack_collection_t *stack);
#endif /* STACK_H */
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/containerof.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/containerof.h
index 94ab3640..5f48ee4d 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/containerof.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/containerof.h
@@ -1,16 +1,17 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef __CONTAINER_OF_H__
#define __CONTAINER_OF_H__
+#include
#undef offsetof
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/event_loop_be.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/event_loop_be.h
index 97627cae..2e4a4465 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/event_loop_be.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/event_loop_be.h
@@ -1,24 +1,34 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef _EVENT_BE_H_
#define _EVENT_BE_H_
+#include
+
+#include "asc_security_core/components_factory_enum.h"
#include "asc_security_core/utils/ievent_loop.h"
-#include "asc_security_core/collector_enums.h"
-#ifndef EXTRA_BE_TIMERS_OBJECT_POOL_ENTRIES
-#define OBJECT_POOL_BE_EVENT_LOOP_TIMERS_COUNT (COLLECTOR_TYPE_COUNT + 1)
+#ifndef ASC_EXTRA_BE_TIMERS_OBJECT_POOL_ENTRIES
+#ifndef ASC_BE_TIMERS_OBJECT_POOL_ENTRIES
+#define OBJECT_POOL_BE_EVENT_LOOP_TIMERS_COUNT (COMPONENTS_COUNT + 1)
+#else
+#define OBJECT_POOL_BE_EVENT_LOOP_TIMERS_COUNT (ASC_BE_TIMERS_OBJECT_POOL_ENTRIES)
+#endif
#else
-#define OBJECT_POOL_BE_EVENT_LOOP_TIMERS_COUNT ((COLLECTOR_TYPE_COUNT + 1) + EXTRA_BE_TIMERS_OBJECT_POOL_ENTRIES)
+#ifndef ASC_BE_TIMERS_OBJECT_POOL_ENTRIES
+#define OBJECT_POOL_BE_EVENT_LOOP_TIMERS_COUNT ((COMPONENTS_COUNT + 1) + ASC_EXTRA_BE_TIMERS_OBJECT_POOL_ENTRIES)
+#else
+#define OBJECT_POOL_BE_EVENT_LOOP_TIMERS_COUNT ((ASC_BE_TIMERS_OBJECT_POOL_ENTRIES) + ASC_EXTRA_BE_TIMERS_OBJECT_POOL_ENTRIES)
+#endif
#endif
@@ -27,6 +37,6 @@
*
* @return @c ievent_loop_t structure represents event loop based on base effort
*/
-ievent_loop_t *event_loop_be_instance_attach();
+ievent_loop_t *event_loop_be_instance_attach(void);
#endif //_EVENT_BE_H_
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/iconv.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/iconv.h
new file mode 100644
index 00000000..c3473e90
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/iconv.h
@@ -0,0 +1,45 @@
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
+
+#ifndef ICONV_H
+#define ICONV_H
+
+#include
+
+#include
+
+typedef struct {
+ int code;
+ char *string;
+} code2string_t;
+
+/**
+ * @brief Return the first string from the list which matches code
+ *
+ * @param list List of strings and their matching code
+ * @param code The code that that should be located
+ *
+ * @return The string that matches the code or NULL in case of failure.
+ */
+char *code2string(code2string_t *list, int code);
+
+/**
+ * @brief Return the first code from the list which matches the string
+ *
+ * @param list List of strings and their matching code
+ * @param string The string that should be located
+ * @parma len The length of the string
+ *
+ * @return The code that matches the string or -1 in case of failure.
+ */
+int string2code(code2string_t *list, char *string, uint32_t len);
+
+#endif /* ICONV_H */
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/ievent_loop.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/ievent_loop.h
index d636c67d..fb09d95a 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/ievent_loop.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/ievent_loop.h
@@ -1,17 +1,23 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef _IEVENT_LOOP_H_
#define _IEVENT_LOOP_H_
+#include
+
+#include
+
+#define EVENT_LOOP_DEFAULT_MAX_COUNT_RUN_UNTIL 100
+
/**
* @file ievent_loop.h
* @brief Event loop API.
@@ -34,11 +40,17 @@ typedef uintptr_t event_loop_signal_handler;
typedef void (*event_loop_signal_cb_t)(event_loop_signal_handler h, int signal_num, void *ctx);
typedef struct {
-/** @brief Initialize the event loop. */
- int (*init)(void);
+/** @brief Initialize the event loop. Returns true on success, otherwise false */
+ bool (*init)(void);
-/** @brief Unitialize the event loop. */
- int (*deinit)(void);
+/**
+ * @brief Unitialize the event loop.
+ * @param flush perform run_until loop on deinit
+ *
+ * Returns false if there are unhandled event callbacks still exists, otherwise true.
+ * If parameter (flush == false) always returns true.
+ */
+ bool (*deinit)(bool flush);
/**
* @brief Handle all events registered on the loop.
@@ -50,6 +62,13 @@ typedef struct {
/** @brief Run only a single iteration of the loop. */
bool (*run_once)(void);
+/**
+ * @brief Run until there are no more active and referenced handles or requests.
+ * @param max_count maximum count of iterations
+ * @return true if there are no more active and referenced handles or requests.
+*/
+ bool (*run_until)(int max_count);
+
/** @brief Stop the even loop and return from @ref event_loop_run. */
void (*stop)(void);
@@ -68,8 +87,8 @@ typedef struct {
*
* @return An object representing the timer. Used later for destroying it
*/
- event_loop_timer_handler (*timer_create)(event_loop_timer_cb_t cb, void *ctx, uint64_t delay,
- uint64_t repeat, event_loop_timer_handler *self);
+ event_loop_timer_handler (*timer_create)(event_loop_timer_cb_t cb, void *ctx, unsigned long delay,
+ unsigned long repeat, event_loop_timer_handler *self);
/**
* @brief Delete a timer.
@@ -113,6 +132,6 @@ typedef struct {
*
* @return Global event loop object
*/
-extern ievent_loop_t *ievent_loop_get_instance();
+extern ievent_loop_t *ievent_loop_get_instance(void);
#endif //_IEVENT_LOOP_H_
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/ifile.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/ifile.h
index 3d9232b3..cf277f4b 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/ifile.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/ifile.h
@@ -1,13 +1,13 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef __IFILE_H__
#define __IFILE_H__
@@ -16,6 +16,8 @@
#include
#include
+#include
+
#include "asc_security_core/asc_result.h"
#include "asc_security_core/utils/istream.h"
@@ -32,6 +34,17 @@
*/
size_t ifile_read(const char *path, const char *mode, char *buf, size_t size);
+/**
+ * @brief Read a file data with allocating buffer.
+ *
+ * @param path The path of the file.
+ * @param mode The mode of the file.
+ * @param size The number of bytes read.
+ *
+ * @return char* The allocated buffer or NULL in case of an error.
+ */
+char *ifile_alloc_read(const char *path, const char *mode, size_t *size);
+
/**
* @brief Write a buffer into a file.
*
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/irand.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/irand.h
index bac69f4b..62d9beab 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/irand.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/irand.h
@@ -1,19 +1,21 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef IRAND_H
#define IRAND_H
#include
+#include
+
/**
* @brief Initialize the seed for rand generator.
*/
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/istream.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/istream.h
new file mode 100644
index 00000000..480bcb2f
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/istream.h
@@ -0,0 +1,112 @@
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
+
+#ifndef __ISTREAM_H__
+#define __ISTREAM_H__
+
+#include
+#include
+#include
+
+#include
+
+#include "asc_security_core/asc_result.h"
+
+/**
+ * @brief Enum to define the data source.
+*/
+typedef enum {
+ ISTREAM_DATA_SRC_FILE = 0,
+ ISTREAM_DATA_SRC_CMD_OUTPUT,
+ ISTREAM_DATA_SRC_CMD_OUTPUT_TO_TMP,
+ ISTREAM_DATA_SRC_BASH_CMD_OUTPUT
+} istream_data_src_t;
+
+typedef struct {
+ istream_data_src_t data_src; // Data source
+ bool full; // Search on full buffer (true) or line by line (false - default)
+ bool negative; // Make logic to be opposite, if not match - pass
+ bool data_not_exist_pass; // Add logic if src not exist - pass
+ bool data_empty_pass; // Add logic if stream is empty - pass
+ bool scandir_match_or; // Add logic if one of the files match the condition in scandir (asterisk) - result is pass
+ bool case_ignore; // Is case sensitive
+ bool each_line; // Matching on each line
+ int sub_group_or; // Add logic of sub group 'or' if one of the tests in this sub group passed - result of this sub group is pass - max 10
+ int sub_group_and; // Add logic of sub group 'and' if all tests in sub this group passed - result of this sub group is pass - max 10
+ const char *path; // Pointer on previous allocated stream path
+ const char *regex; // Pointer on previous allocated matching string
+ const char *base_dir; // Base dir for 'path' parameter
+ const char *hash; // Pointer on previous allocated hash
+ bool suppress_err_log; // Flag for error log suppress on low layer
+} istream_match_t;
+
+/**
+ * @brief Check if there is a stream contains the specified string.
+ *
+ * @param path The stream path
+ * @param s The string
+ * @param params The parameters defined in @c istream_match_t struct
+ * @param buf The target buffer that is used to read result or error
+ * @param size The size of the buffer in bytes.
+ *
+ * @return ASC_RESULT_OK on contains, ASC_RESULT_EMPTY on not contains, otherwise ASC_RESULT_error_code.
+ */
+asc_result_t istream_contains_string(const char *path, const char *s, istream_match_t *params, char **buf, size_t *size);
+
+/**
+ * @brief Check if the content of the whole stream (without newline or return) given by path, is equal specified buffer.
+ *
+ * @param path The stream path
+ * @param s Compare the content of the stream with this string
+ * @param params The parameters defined in @c istream_match_t struct
+ * @param buf The target buffer that is used to read result or error
+ * @param size The size of the buffer in bytes.
+ *
+ * @return ASC_RESULT_OK on equals, ASC_RESULT_EMPTY on not equal, otherwise ASC_RESULT_error_code.
+ */
+asc_result_t istream_trimmed_equals_to_buffer(const char *path, const char *s, istream_match_t *params, char **buf, size_t *size);
+
+typedef struct {
+ int deep_of_substrings; // Max deep of regular expression substrings
+ int start_index_substring; // Start substring index to be stored
+ int end_index_substring; // End substring index to be stored
+ const char *var_delim; // Delimiter between values in output format
+ int regcomp_flags; // Regular expression compilation flags (see )
+ istream_match_t istream_match; // The istream_match_t struct
+} istream_regex_extract_t;
+
+/**
+ * @brief Fill given buffer by blocks from stream based on regular expression.
+ *
+ * @param path The stream path
+ * @param regex The regular expression to be extracted
+ * @param params The parameters defined in @c istream_get_regex_t struct
+ * @param buf The target buffer that is used to read result or error
+ * @param size The size of the buffer in bytes.
+ *
+ * @return ASC_RESULT_OK on success
+ */
+asc_result_t istream_regex_extract(const char *path, const char *regex, istream_regex_extract_t *params, char **buf, size_t *size);
+
+/**
+ * @brief Check if there is a line in the stream that contains the specified regular expression.
+ *
+ * @param path The stream path
+ * @param regex The regular expression to be matched
+ * @param params The parameters defined in @c istream_match_t struct
+ * @param buf The target buffer that is used to read result or error
+ * @param size The size of the buffer in bytes.
+ *
+ * @return ASC_RESULT_OK on contains, ASC_RESULT_EMPTY on not contains, otherwise ASC_RESULT_error_code.
+ */
+asc_result_t istream_regex_match(const char *path, const char *regex, istream_match_t *params, char **buf, size_t *size);
+
+#endif /* __ISTREAM_H__ */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/itime.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/itime.h
index 67088944..87cbc2f5 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/itime.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/itime.h
@@ -1,25 +1,28 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef ITIME_H
#define ITIME_H
#include
-#include
+
+#include
#define SEC_MIN (60)
#define SEC_HOUR (SEC_MIN * 60)
#define SEC_DAY (SEC_HOUR * 24)
-typedef uint32_t (*unix_time_callback_t)(uint32_t *unix_time);
+#define ITIME_FAILED ((unsigned long)(-1))
+
+typedef unsigned long (*unix_time_callback_t)(unsigned long *unix_time);
void itime_init(unix_time_callback_t time_callback);
@@ -29,7 +32,7 @@ void itime_init(unix_time_callback_t time_callback);
* @details This function provides the same functionality as the
* standard C @c time() function.
*/
-uint32_t itime_time(uint32_t *timer);
+unsigned long itime_time(unsigned long *timer);
#endif /* ITIME_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/macros.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/macros.h
index a668a22b..e4a28b95 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/macros.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/macros.h
@@ -1,16 +1,25 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef __MACROS_H__
#define __MACROS_H__
+#include
+
+#ifndef MIN
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#endif
+
+#ifndef MAX
+#define MAX(a, b) ((a) >= (b) ? (a) : (b))
+#endif
#ifdef __clang__
#define ATTRIBUTE_FORMAT(fmt_index, args_index) __attribute__((__format__ (__printf__, fmt_index, args_index)))
@@ -20,4 +29,12 @@
#define ATTRIBUTE_FORMAT(fmt_index, args_index)
#endif
+#ifdef __clang__
+#define ATTRIBUTE_NONNUL(_index, ...) __attribute__((nonnull (_index, ##__VA_ARGS__)))
+#elif __GNUC__
+#define ATTRIBUTE_NONNUL(_index, ...) __attribute__((nonnull(_index, ##__VA_ARGS__)))
+#else
+#define ATTRIBUTE_NONNUL(_index, ...)
+#endif
+
#endif /* __MACROS_H__ */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/notifier.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/notifier.h
index d9cbf6ec..73d7c04e 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/notifier.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/notifier.h
@@ -1,25 +1,33 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef __NOTIFIER_H__
#define __NOTIFIER_H__
+#include
#include "asc_security_core/asc_result.h"
-#include "asc_security_core/configuration.h"
#include "asc_security_core/utils/notifier_topics.h"
+#include "asc_security_core/components_factory_enum.h"
-#ifndef EXTRA_NOTIFIERS_OBJECT_POOL_ENTRIES
-#define NOTIFIERS_POOL_ENTRIES 1
+#ifndef ASC_DYNAMIC_MEMORY_ENABLED
+#ifndef ASC_NOTIFIERS_OBJECT_POOL_ENTRIES /* if ASC_NOTIFIERS_OBJECT_POOL_ENTRIES not defined set default */
+#define ASC_NOTIFIERS_OBJECT_POOL_ENTRIES (NOTIFY_TOPICS_NUMBER * (COMPONENTS_COUNT+1))
+#endif
+#ifndef ASC_EXTRA_NOTIFIERS_OBJECT_POOL_ENTRIES /* Add ASC_EXTRA_NOTIFIERS_OBJECT_POOL_ENTRIES */
+#define NOTIFIERS_POOL_ENTRIES ASC_NOTIFIERS_OBJECT_POOL_ENTRIES
#else
-#define NOTIFIERS_POOL_ENTRIES (1 + EXTRA_NOTIFIERS_OBJECT_POOL_ENTRIES)
+#define NOTIFIERS_POOL_ENTRIES (ASC_NOTIFIERS_OBJECT_POOL_ENTRIES + ASC_EXTRA_NOTIFIERS_OBJECT_POOL_ENTRIES)
+#endif
+#else /* Set unlimited in case of ASC_DYNAMIC_MEMORY_ENABLED */
+#define NOTIFIERS_POOL_ENTRIES 0
#endif
typedef struct notifier_t notifier_t;
@@ -58,5 +66,6 @@ asc_result_t notifier_unsubscribe(notify_topic_t topic, notifier_t *notifier);
*
* @param topic Topic enumerator
* @return ASC_RESULT_OK on success, ASC_RESULT_EXCEPTION otherwise.
- */asc_result_t notifier_deinit(notify_topic_t topic);
+ */
+asc_result_t notifier_deinit(notify_topic_t topic);
#endif
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/notifier_topics.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/notifier_topics.h
index 903069cc..9d6e16d4 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/notifier_topics.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/notifier_topics.h
@@ -1,24 +1,38 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef __NOTIFIER_GROUPS_H__
#define __NOTIFIER_GROUPS_H__
+#include
typedef enum {
NOTIFY_TOPIC_SYSTEM,
+ NOTIFY_TOPIC_COLLECT,
+ NOTIFY_TOPIC_SECURITY_MODULE_STATE,
NOTIFY_TOPICS_NUMBER
} notify_topic_t;
enum {
- NOTIFY_MESSAGE_SYSTEM_CONFIGURATION = 0
+#ifdef ASC_COLLECTORS_INFO_SUPPORT
+ NOTIFY_SYSTEM_CONFIGURATION,
+#endif
+
+ NOTIFY_MESSAGE_READY,
+
+ NOTIFY_SECURITY_MODULE_CONNECTED,
+ NOTIFY_SECURITY_MODULE_PENDING,
+ NOTIFY_SECURITY_MODULE_SUSPENDED,
+#ifdef ASC_COMPONENT_CORE_SUPPORTS_RESTART
+ NOTIFY_SECURITY_MODULE_RESTART
+#endif
};
#endif
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/num2str.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/num2str.h
new file mode 100644
index 00000000..b6722c4e
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/num2str.h
@@ -0,0 +1,38 @@
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
+
+#ifndef _NUM2STR_H_
+#define _NUM2STR_H_
+#include
+
+#define __STR_AUX(x) #x
+#define NUM_2_STR(x) __STR_AUX(x)
+#define NUM_2_STR_SIZE(x) (sizeof(NUM_2_STR(x)))
+
+#define ULLONG64_MAX_STR NUM_2_STR(18446744073709551615)
+#define ULLONG64_MAX_STR_SIZE (sizeof(ULLONG64_MAX_STR))
+
+#define LLONG64_MAX_STR NUM_2_STR(9223372036854775807)
+#define LLONG64_MAX_STR_SIZE (sizeof(LLONG64_MAX_STR))
+
+#define ULONG32_MAX_STR NUM_2_STR(4294967295)
+#define ULONG32_MAX_STR_SIZE (sizeof(ULONG32_MAX_STR))
+
+#define LONG32_MAX_STR NUM_2_STR(2147483647)
+#define LONG32_MAX_STR_SIZE (sizeof(LONG32_MAX_STR))
+
+#define UINT16_MAX_STR NUM_2_STR(65535)
+#define UINT16_MAX_STR_SIZE (sizeof(UINT16_MAX_STR))
+
+#define INT16_MAX_STR NUM_2_STR(32767)
+#define INT16_MAX_STR_SIZE (sizeof(INT16_MAX_STR))
+
+#endif /* _NUM2STR_H_ */
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/os_utils.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/os_utils.h
index 8afcda04..bc1bd992 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/os_utils.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/os_utils.h
@@ -1,22 +1,23 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef OS_UTILS_H
#define OS_UTILS_H
+#include
/**
* @brief Unique hardware identifier for security module
*
* @return security module id
*/
-const char *os_utils_get_security_module_id();
+const char *os_utils_get_security_module_id(void);
#endif /* OS_UTILS_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/string_utils.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/string_utils.h
index 06a81ecb..7a61b3d5 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/string_utils.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/string_utils.h
@@ -1,13 +1,13 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef STRING_UTILS_H
#define STRING_UTILS_H
@@ -15,6 +15,64 @@
#include
#include
+#include
+
+#include "asc_security_core/asc_result.h"
+
+/**
+ * @brief safe strstr.
+ *
+ * @param s the buffer
+ *
+ * @return buffer size
+ */
+char *str_str(const char *s1, const char *s2);
+
+/**
+ * @brief Replace last newline by NULL - no reallocation memory.
+ *
+ * @param s the buffer
+ *
+ * @return non
+ */
+void str_trim_last_newline(char *s);
+
+/**
+ * @brief Trim whitespaces. This function returns a pointer to a substring of the original string.
+ *
+ * @param s the original string
+ *
+ * @return a pointer to a substring of the original string
+ */
+char *str_trim(char *s);
+
+/**
+ * @brief safe strlen.
+ *
+ * @param s the buffer
+ *
+ * @return buffer size
+ */
+size_t str_len(const char *s);
+
+/**
+ * @brief safe strcmp.
+ *
+ * @param s the buffer
+ *
+ * @return comparison result
+ */
+int str_cmp(const char *s1, const char *s2);
+
+/**
+ * @brief check if string is NULL or empty.
+ *
+ * @param s the string for check
+ *
+ * @return true if empty, otherwise false.
+ */
+bool str_isempty(const char *s);
+
/**
* @brief char* value getter
*
@@ -22,8 +80,7 @@
*
* @return char* value if is not NULL, empty otherwise
*/
-const char *string_utils_value_or_empty(const char *s);
-
+const char *str_value_or_empty(const char *s);
/**
* @brief Check if string is blank
@@ -32,7 +89,54 @@ const char *string_utils_value_or_empty(const char *s);
*
* @return true iff string is blank
*/
-bool string_utils_is_blank(const char *s);
+bool str_is_blank(const char *s);
+/**
+ * @brief Split a string to two parts by a delimiter
+ *
+ * @param s string
+ * @param token A pointer to a variable to receive the token
+ * @param token_len A pointer to a variable to receive the length of 'token'
+ * @param rest A pointer to a variable to receive the rest of the string
+ * @param rest_len A pointer to a variable to receive the length of 'rest'
+ * @param delimiter The delimiter to 'split' the string
+ *
+ * @return ASC_RESULT_OK on success.
+ */
+asc_result_t str_split(char *s, char **token, size_t *token_len, char **rest, size_t *rest_len, char *delimiter);
+
+/**
+ * @brief Compare two strings
+ *
+ * @param s1 The first string
+ * @param s1_len The length of s1
+ * @param s2 The second string
+ * @param s2_len The length of s2
+ *
+ * @return comparison result
+ */
+int str_ncmp(const char *s1, size_t s1_len, const char *s2, size_t s2_len);
+
+/**
+ * @brief Check if one string is a prefix of the other string
+ *
+ * @param s1 The first string
+ * @param s2 The second string
+ *
+ * @return true if s2 is a prefix of s1
+ */
+bool str_starts_from(const char *s1, const char *s2);
+
+/**
+ * @brief replace all instances of a char in a char array with a different char
+ *
+ * @param char_array The character array
+ * @param len The length to look at
+ * @param replace_from The character to be replaced
+ * @param replace_to The character to replace with
+ *
+ * @return a reference to the char array
+ */
+char *replace_chars(char *char_array, size_t len, char replace_from, char replace_to);
#endif /* STRING_UTILS_H */
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/uuid.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/uuid.h
new file mode 100644
index 00000000..ab6d7803
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/utils/uuid.h
@@ -0,0 +1,30 @@
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
+
+#ifndef IUUID_H
+#define IUUID_H
+
+#include
+
+#include
+
+/**
+ * @brief Generate a binary uuid
+ * @note: not thread-safe.
+ *
+ * @param buf - The buffer to write the UUID to. Size should be at least 16 bytes.
+ *
+ * @return 0 on sucess, -1 otherwise
+ */
+int uuid_generate(uint8_t *buf);
+
+
+#endif /* IUUID_H */
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/version.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/version.h
index aae9b8c3..5dcfc23c 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/version.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/inc/asc_security_core/version.h
@@ -1,34 +1,20 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef VERSION_H
#define VERSION_H
-
-#ifndef DISABLE_ASC_PORT
-#include "asc_version.h"
-#else
-#ifndef SECURITY_MODULE_VERSION_MAJOR
-#define SECURITY_MODULE_VERSION_MAJOR 0
-#endif
-#ifndef SECURITY_MODULE_VERSION_MINOR
-#define SECURITY_MODULE_VERSION_MINOR 0
-#endif
-#ifndef SECURITY_MODULE_VERSION_PATCH
-#define SECURITY_MODULE_VERSION_PATCH 0
-#endif
-#endif /* DISABLE_ASC_PORT */
-
+#include
#define SECURITY_MODULE_VERSION ((SECURITY_MODULE_VERSION_MAJOR << 24) |\
- (SECURITY_MODULE_VERSION_MINOR << 16) |\
- SECURITY_MODULE_VERSION_PATCH)
+ (SECURITY_MODULE_VERSION_MINOR << 16) |\
+ SECURITY_MODULE_VERSION_PATCH)
#endif /* VERSION_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/collector_collection.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/collector_collection.c
index 3f4aa8a5..9c927764 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/collector_collection.c
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/collector_collection.c
@@ -1,35 +1,35 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#include
#include
+#include
+
#include "asc_security_core/logger.h"
-#include "asc_security_core/collector_collection.h"
#include "asc_security_core/object_pool.h"
-#include "asc_security_core/collector_collection_internal.h"
-#include "asc_security_core/collector_collection_factory.h"
-#include "asc_security_core/collectors_headers.h"
+
+#include "asc_security_core/collector_collection.h"
#define COLLECTOR_COLLECTION_OBJECT_POOL_COUNT 1
struct priority_collectors {
- uint32_t interval;
collector_priority_t priority;
collector_t *current_collector_ptr;
- linked_list_collector_t collector_list;
+ linked_list_t collector_list;
};
struct collector_collection {
+ /* This macro must be first in object */
COLLECTION_INTERFACE(struct collector_collection);
priority_collectors_t collector_array[COLLECTOR_PRIORITY_COUNT];
@@ -38,18 +38,16 @@ struct collector_collection {
OBJECT_POOL_DECLARATIONS(collector_collection_t)
OBJECT_POOL_DEFINITIONS(collector_collection_t, COLLECTOR_COLLECTION_OBJECT_POOL_COUNT)
-static asc_result_t _collector_collection_init_collector_lists(collector_collection_t *collector_collection_ptr, collector_init_function_t *collector_init_array, uint32_t array_size);
-static void _collector_collection_deinit_collector_lists(linked_list_collector_t_handle collector_list_ptr);
-static bool _collector_collection_type_match_function(collector_t *collector_ptr, void *match_context);
+static void _collector_collection_init_collector_lists(collector_collection_t *collector_collection_ptr);
+static void _collector_collection_deinit_collector_lists(linked_list_t *collector_list_ptr);
+static bool _collector_collection_type_match_function(void *item, void *match_context);
-collector_collection_t *collector_collection_init()
+collector_collection_t *collector_collection_init(void)
{
log_debug("Init collector collection");
asc_result_t result = ASC_RESULT_OK;
collector_collection_t *collector_collection_ptr = NULL;
- collector_init_function_t *collector_init_array = NULL;
- uint32_t collector_init_array_size = 0;
collector_collection_ptr = object_pool_get(collector_collection_t);
if (collector_collection_ptr == NULL) {
@@ -60,25 +58,8 @@ collector_collection_t *collector_collection_init()
memset(collector_collection_ptr, 0, sizeof(collector_collection_t));
- result = collector_collection_factory_get_initialization_array(&collector_init_array, &collector_init_array_size);
- if (result != ASC_RESULT_OK) {
- log_error("Collector collection array is not being initialized properly");
- goto cleanup;
- }
-
- result = _collector_collection_init_collector_lists(collector_collection_ptr, collector_init_array, collector_init_array_size);
- if (result != ASC_RESULT_OK) {
- log_error("Collector collection failed to initialize collector lists, result=[%d]", result);
- goto cleanup;
- }
-
- result = collector_collection_internal_init_startup_time(collector_collection_ptr);
- if (result != ASC_RESULT_OK) {
- log_error("Collector collection failed to init collectors startup time, result=[%d]", result);
- goto cleanup;
- }
-
-
+ _collector_collection_init_collector_lists(collector_collection_ptr);
+
cleanup:
if (result != ASC_RESULT_OK) {
log_error("Failed to initialize collector collection, result=[%d]", result);
@@ -132,21 +113,27 @@ priority_collectors_t *collector_collection_get_by_priority(collector_collection
}
-static bool _collector_collection_type_match_function(collector_t *collector_ptr, void *match_context)
+static bool _collector_collection_type_match_function(void *item, void *match_context)
{
- return collector_ptr == NULL ? false : collector_ptr->internal.type == *((collector_type_t *)match_context);
+ collector_t *collector_ptr = item;
+ return collector_ptr == NULL ? false : collector_ptr->internal.type == *((collector_enum_t *)match_context);
}
-collector_t *collector_collection_get_collector_by_priority(collector_collection_t *collector_collection_ptr, collector_type_t type)
+collector_t *collector_collection_get_collector_by_priority(collector_collection_t *collector_collection_ptr, collector_enum_t type)
{
collector_t *collector_ptr = NULL;
- priority_collectors_t *priority_collector_ptr = collector_collection_get_head_priority(collector_collection_ptr);
+ priority_collectors_t *priority_collector_ptr = NULL;
+
+ if (collector_collection_ptr == NULL) {
+ goto cleanup;
+ }
+ priority_collector_ptr = collector_collection_get_head_priority(collector_collection_ptr);
while (priority_collector_ptr != NULL) {
- linked_list_collector_t_handle collector_list = priority_collectors_get_list(priority_collector_ptr);
+ linked_list_t *collector_list = priority_collectors_get_list(priority_collector_ptr);
- collector_ptr = linked_list_collector_t_find(collector_list, _collector_collection_type_match_function, &type);
+ collector_ptr = linked_list_find(collector_list, _collector_collection_type_match_function, &type);
if (collector_ptr != NULL) {
goto cleanup;
}
@@ -159,84 +146,39 @@ collector_t *collector_collection_get_collector_by_priority(collector_collection
}
-void collector_collection_foreach(collector_collection_t *collector_collection_ptr, linked_list_collector_t_action action_function, void *context)
+void collector_collection_foreach(collector_collection_t *collector_collection_ptr, void(*action_function)(collector_t *collector, void *context), void *context)
{
- for (priority_collectors_t *prioritized_collectors = collector_collection_get_head_priority(collector_collection_ptr) ; prioritized_collectors != NULL; prioritized_collectors = collector_collection_get_next_priority(collector_collection_ptr, prioritized_collectors)) {
- linked_list_collector_t_foreach(priority_collectors_get_list(prioritized_collectors), action_function, context);
- }
-}
-
-
-uint32_t priority_collectors_get_interval(priority_collectors_t *priority_collectors_ptr)
-{
- return priority_collectors_ptr->interval;
-}
-
-
-asc_result_t priority_collectors_set_interval(priority_collectors_t *priority_collectors_ptr, uint32_t interval)
-{
- asc_result_t result = ASC_RESULT_OK;
-
- if (priority_collectors_ptr == NULL)
- {
- result = ASC_RESULT_BAD_ARGUMENT;
+ if (action_function == NULL) {
+ return;
}
- else
- {
- priority_collectors_ptr->interval = interval;
+ for (priority_collectors_t *prioritized_collectors = collector_collection_get_head_priority(collector_collection_ptr) ; prioritized_collectors != NULL; prioritized_collectors = collector_collection_get_next_priority(collector_collection_ptr, prioritized_collectors)) {
+ linked_list_t *linked_list_handle = priority_collectors_get_list(prioritized_collectors);
+ collector_t *curr = NULL;
+ linked_list_foreach(linked_list_handle, curr) {
+ action_function(curr, context);
+ }
}
-
- return result;
}
-
collector_priority_t priority_collectors_get_priority(priority_collectors_t *priority_collectors_ptr)
{
return priority_collectors_ptr->priority;
}
-linked_list_collector_t_handle priority_collectors_get_list(priority_collectors_t *priority_collectors_ptr)
+linked_list_t *priority_collectors_get_list(priority_collectors_t *priority_collectors_ptr)
{
return &(priority_collectors_ptr->collector_list);
}
-asc_result_t _collector_collection_init_collector_lists(collector_collection_t *collector_collection_ptr, collector_init_function_t *collector_init_array, uint32_t collector_init_array_size)
+static void _collector_collection_init_collector_lists(collector_collection_t *collector_collection_ptr)
{
- asc_result_t result = ASC_RESULT_OK;
-
for (unsigned int priority=0; priority < COLLECTOR_PRIORITY_COUNT; priority++) {
- linked_list_collector_t_init(&(collector_collection_ptr->collector_array[priority].collector_list), NULL);
- collector_collection_ptr->collector_array[priority].interval = g_collector_collections_intervals[priority];
+ linked_list_init(&(collector_collection_ptr->collector_array[priority].collector_list));
collector_collection_ptr->collector_array[priority].current_collector_ptr = NULL;
collector_collection_ptr->collector_array[priority].priority = (collector_priority_t)priority;
}
-
- uint32_t collector_count = collector_init_array_size;
- for (unsigned int i=0; i < collector_count; i++){
- collector_t *collector_ptr = collector_init(collector_init_array[i]);
-
- if (collector_ptr == NULL) {
- result = ASC_RESULT_MEMORY_EXCEPTION;
- goto cleanup;
- }
-
- collector_priority_t priority = collector_get_priority(collector_ptr);
-
- linked_list_collector_t_handle current_collector_list_handle = &(collector_collection_ptr->collector_array[priority].collector_list);
-
- if (linked_list_collector_t_add_last(current_collector_list_handle, collector_ptr) == NULL){
- log_error("Could not append collector type=[%d] to collector list", collector_ptr->internal.type);
- result = ASC_RESULT_EXCEPTION;
- goto cleanup;
- }
- collector_collection_ptr->collector_array[priority].current_collector_ptr = linked_list_collector_t_get_first(current_collector_list_handle);
- }
-
-cleanup:
-
- return result;
}
@@ -261,7 +203,7 @@ collector_t *priority_collectors_get_next_cyclic_collector(priority_collectors_t
}
if (current_item->next == NULL) {
- current_item = linked_list_collector_t_get_first(&(priority_collectors_ptr->collector_list));
+ current_item = linked_list_get_first(&priority_collectors_ptr->collector_list);
} else {
current_item = current_item->next;
}
@@ -270,17 +212,42 @@ collector_t *priority_collectors_get_next_cyclic_collector(priority_collectors_t
}
-static void _collector_collection_deinit_collector_lists(linked_list_collector_t_handle collector_list_ptr)
+asc_result_t collector_collection_register(collector_collection_t *collector_collection_ptr, collector_t *collector_ptr, unsigned long collect_offset)
{
- collector_t *collector_ptr = linked_list_collector_t_get_first(collector_list_ptr);
- while (collector_ptr != NULL) {
- linked_list_collector_t_remove(collector_list_ptr, collector_ptr);
+ asc_result_t result = ASC_RESULT_OK;
+ collector_priority_t priority = collector_get_priority(collector_ptr);
- if (collector_ptr != NULL) {
- collector_deinit(collector_ptr);
- }
+ linked_list_t *current_collector_list_handle = &(collector_collection_ptr->collector_array[priority].collector_list);
- collector_ptr = linked_list_collector_t_get_first(collector_list_ptr);
+ if (linked_list_add_last(current_collector_list_handle, collector_ptr) == NULL){
+ log_error("Could not append collector type=[%d] to collector list", collector_ptr->internal.type);
+ result = ASC_RESULT_EXCEPTION;
+ goto cleanup;
}
+ collector_collection_ptr->collector_array[priority].current_collector_ptr = linked_list_get_first(current_collector_list_handle);
+ collector_set_last_collected_timestamp(collector_ptr, collect_offset);
+cleanup:
+ return result;
+}
+
+
+void collector_collection_unregister(collector_collection_t *collector_collection_ptr, collector_t *collector_ptr)
+{
+ collector_priority_t priority = collector_get_priority(collector_ptr);
+
+ linked_list_t *current_collector_list_handle = &(collector_collection_ptr->collector_array[priority].collector_list);
+
+ linked_list_remove(current_collector_list_handle, collector_ptr, NULL);
+ collector_collection_ptr->collector_array[priority].current_collector_ptr = linked_list_get_first(current_collector_list_handle);
+}
+
+
+static void _collector_collection_deinit_collector_lists(linked_list_t *collector_list_ptr)
+{
+ collector_t *collector_ptr = linked_list_get_first(collector_list_ptr);
+ while (collector_ptr != NULL) {
+ linked_list_remove(collector_list_ptr, collector_ptr, NULL);
+ collector_ptr = linked_list_get_first(collector_list_ptr);
+ }
}
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/collector_collection_factory.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/collector_collection_factory.c
deleted file mode 100644
index 3bcd2308..00000000
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/collector_collection_factory.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
-
-#include
-#include "asc_security_core/utils/itime.h"
-#include "asc_security_core/logger.h"
-
-#include "asc_security_core/collector_collection_factory.h"
-#include "asc_security_core/collectors_headers.h"
-
-static collector_init_function_t collector_init_array[] = {
-#ifdef COLLECTOR_SYSTEM_INFORMATION_ENABLED
- collector_system_information_init,
-#endif
-#ifdef COLLECTOR_LISTENING_PORTS_ENABLED
- collector_listening_ports_init,
-#endif
-#ifdef COLLECTOR_NETWORK_ACTIVITY_ENABLED
- collector_network_activity_init,
-#endif
-#ifdef COLLECTOR_HEARTBEAT_ENABLED
- collector_heartbeat_init,
-#endif
-#ifdef COLLECTOR_BASELINE_ENABLED
- collector_baseline_init,
-#endif
-};
-
-
-asc_result_t collector_collection_factory_get_initialization_array(collector_init_function_t **init_array, uint32_t *init_array_size)
-{
- asc_result_t result = ASC_RESULT_OK;
-
- if (init_array == NULL) {
- log_error("Collector collection array cannot be initialize due to bad arguments");
- result = ASC_RESULT_BAD_ARGUMENT;
- goto cleanup;
- }
-
- if (collector_init_array == NULL) {
- log_error("Collector collection array cannot be initialize due to collector_init_array=[NULL]");
- result = ASC_RESULT_UNINITIALIZED;
- goto cleanup;
- }
-
- *init_array = collector_init_array;
- *init_array_size = sizeof(collector_init_array) / sizeof(collector_init_function_t);
-
-cleanup:
- if (result != ASC_RESULT_OK) {
- log_error("Failed to retrieve collector collection initialization array");
- }
-
- return result;
-}
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/collector_collection_internal.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/collector_collection_internal.c
deleted file mode 100644
index 1c46b388..00000000
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/collector_collection_internal.c
+++ /dev/null
@@ -1,93 +0,0 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
-
-#include "asc_security_core/collector_collection.h"
-#include "asc_security_core/collector_collection_internal.h"
-#include "asc_security_core/collectors_headers.h"
-#include "asc_security_core/logger.h"
-#include "asc_security_core/utils/collection/linked_list.h"
-#include "asc_security_core/utils/irand.h"
-#include "asc_security_core/utils/itime.h"
-
-const char *g_collector_names[COLLECTOR_TYPE_COUNT] = {
-#ifdef COLLECTOR_SYSTEM_INFORMATION_ENABLED
- COLLECTOR_NAME_SYSTEM_INFORMATION,
-#endif
-#ifdef COLLECTOR_NETWORK_ACTIVITY_ENABLED
- COLLECTOR_NAME_NETWORK_ACTIVITY,
-#endif
-#ifdef COLLECTOR_LISTENING_PORTS_ENABLED
- COLLECTOR_NAME_LISTENING_PORTS,
-#endif
-#ifdef COLLECTOR_HEARTBEAT_ENABLED
- COLLECTOR_NAME_HEARTBEAT,
-#endif
-#ifdef COLLECTOR_BASELINE_ENABLED
- COLLECTOR_NAME_BASELINE,
-#endif
-};
-
-const uint32_t g_collector_collections_intervals[COLLECTOR_PRIORITY_COUNT] = {
- ASC_HIGH_PRIORITY_INTERVAL,
- ASC_MEDIUM_PRIORITY_INTERVAL,
- ASC_LOW_PRIORITY_INTERVAL
-};
-
-static asc_result_t collector_collection_internal_set_random_collected_time(priority_collectors_t *priority_collector_ptr);
-
-asc_result_t collector_collection_internal_init_startup_time(collector_collection_t *collector_collection_ptr)
-{
- asc_result_t result = ASC_RESULT_OK;
-
- priority_collectors_t *priority_collector_ptr = collector_collection_get_head_priority(collector_collection_ptr);
-
- while (priority_collector_ptr != NULL) {
- result = collector_collection_internal_set_random_collected_time(priority_collector_ptr);
- if (result != ASC_RESULT_OK) {
- log_error("Failed to set random collected time to collectors, collector_priority=[%d], result=[%d]", priority_collectors_get_priority(priority_collector_ptr), result);
- goto cleanup;
- }
-
- priority_collector_ptr = collector_collection_get_next_priority(collector_collection_ptr, priority_collector_ptr);
- }
-
-cleanup:
- if (result != ASC_RESULT_OK) {
- log_error("Failed to init collector collection init startup time, result=[%d]", result);
- }
-
- return result;
-}
-
-static asc_result_t collector_collection_internal_set_random_collected_time(priority_collectors_t *priority_collector_ptr)
-{
- linked_list_collector_t_handle priority_collector_list = priority_collectors_get_list(priority_collector_ptr);
- uint32_t collector_interval = priority_collectors_get_interval(priority_collector_ptr);
- collector_t *collector_ptr = linked_list_collector_t_get_first(priority_collector_list);
- uint32_t current_time = itime_time(NULL);
- uint32_t last_collected_timestamp;
-
-#ifdef ASC_FIRST_FORCE_COLLECTION_INTERVAL
- last_collected_timestamp = current_time - collector_interval + ASC_FIRST_FORCE_COLLECTION_INTERVAL;
-#else
- collector_priority_t priority = priority_collectors_get_priority(priority_collector_ptr);
- uint32_t interval = (uint32_t)((priority+1) * ASC_FIRST_COLLECTION_INTERVAL);
- uint32_t delta = (uint32_t)(irand_int() % (2 * interval) + interval);
- last_collected_timestamp = current_time - collector_interval + delta;
-#endif
-
- while (collector_ptr != NULL) {
- collector_set_last_collected_timestamp(collector_ptr, last_collected_timestamp);
- collector_ptr = collector_ptr->next;
- }
-
- return ASC_RESULT_OK;
-}
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/collectors/collector_heartbeat.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/collectors/collector_heartbeat.c
index 1b0f96dd..bbbd64c9 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/collectors/collector_heartbeat.c
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/collectors/collector_heartbeat.c
@@ -1,51 +1,39 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
-
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#include
-#include "asc_security_core/collectors/heartbeat.h"
+#include
+
#include "asc_security_core/logger.h"
-#include "asc_security_core/collector_enums.h"
+#include "asc_security_core/components_manager.h"
+#include "asc_security_core/core.h"
#include "asc_security_core/object_pool.h"
#include "asc_security_core/utils/itime.h"
-#include "asc_security_core/utils/notifier.h"
-static void _collector_heartbeat_deinit(collector_internal_t *collector_internal_ptr);
static asc_result_t _collector_heartbeat_get_events(collector_internal_t *collector_internal_ptr, serializer_t *serializer);
-asc_result_t collector_heartbeat_init(collector_internal_t *collector_internal_ptr)
-{
- if (collector_internal_ptr == NULL) {
- log_error("Could not initialize collector_heartbeat, bad argument");
- return ASC_RESULT_BAD_ARGUMENT;
- }
+static asc_result_t _collector_heartbeat_init(component_id_t id);
- memset(collector_internal_ptr, 0, sizeof(*collector_internal_ptr));
+COLLECTOR_OPS_DEFINITIONS(, _collector_heartbeat_init, collector_default_deinit,
+ collector_default_subscribe, collector_default_unsubscribe, collector_default_start, collector_default_stop);
- collector_internal_ptr->type = COLLECTOR_TYPE_HEARTBEAT;
- collector_internal_ptr->priority = COLLECTOR_PRIORITY_LOW;
- collector_internal_ptr->collect_function = _collector_heartbeat_get_events;
- collector_internal_ptr->deinit_function = _collector_heartbeat_deinit;
- notifier_notify(NOTIFY_TOPIC_SYSTEM, NOTIFY_MESSAGE_SYSTEM_CONFIGURATION, collector_internal_ptr);
-
- return ASC_RESULT_OK;
-}
+COMPONENTS_FACTORY_DEFINITION(Heartbeat, &_ops)
-static void _collector_heartbeat_deinit(collector_internal_t *collector_internal_ptr)
+static asc_result_t _collector_heartbeat_init(component_id_t id)
{
- memset(collector_internal_ptr, 0, sizeof(*collector_internal_ptr));
+ return collector_default_create(id, Heartbeat, COLLECTOR_PRIORITY_LOW, _collector_heartbeat_get_events, ASC_LOW_PRIORITY_INTERVAL, NULL);
}
static asc_result_t _collector_heartbeat_get_events(collector_internal_t *collector_internal_ptr, serializer_t *serializer)
{
- uint32_t timestamp = itime_time(NULL);
- return serializer_event_add_heartbeat(serializer, timestamp, g_collector_collections_intervals[collector_internal_ptr->priority]);
+ unsigned long timestamp = itime_time(NULL);
+ return serializer_event_add_heartbeat(serializer, timestamp, collector_internal_ptr->interval);
}
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/collectors_info.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/collectors_info.c
index 0617de11..35192f9a 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/collectors_info.c
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/collectors_info.c
@@ -1,26 +1,28 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
-
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#include
#include
+#include
+
#include "asc_security_core/logger.h"
#include "asc_security_core/object_pool.h"
#include "asc_security_core/collectors_info.h"
-#include "asc_security_core/collector_enums.h"
#include "asc_security_core/collector.h"
+#include "asc_security_core/components_factory.h"
#include "asc_security_core/utils/containerof.h"
#include "asc_security_core/utils/notifier.h"
typedef struct notifier_container_t {
+ /* This macro must be first in object */
COLLECTION_INTERFACE(struct notifier_container_t);
notifier_t notifier;
@@ -41,18 +43,17 @@ static void _collector_info_cb(notifier_t *notifier, int message_num, void *payl
return;
}
- if (collector_internal_ptr->type >= COLLECTORS_INFO_SIZE ||
- collector_internal_ptr->priority >= COLLECTOR_PRIORITY_COUNT) {
- log_error("Wrong collector type=[%d] or priority=[%d]", collector_internal_ptr->type, collector_internal_ptr->priority);
+ if (collector_internal_ptr->type >= COLLECTORS_INFO_SIZE) {
+ log_error("Wrong collector type=[%d]", collector_internal_ptr->type);
} else {
- info[collector_internal_ptr->type].interval = g_collector_collections_intervals[collector_internal_ptr->priority];
- log_debug("Updated configuration for collector=[%s] with interval=[%u]\n",
- g_collector_names[collector_internal_ptr->type],
+ info[collector_internal_ptr->type].interval = collector_internal_ptr->interval;
+ log_debug("Updated configuration for collector=[%d] with interval=[%lu]\n",
+ collector_internal_ptr->type,
info[collector_internal_ptr->type].interval);
}
}
-collectors_info_t *collectors_info_init()
+collectors_info_t *collectors_info_init(void)
{
notifier_container_t *container = object_pool_get(notifier_container_t);
@@ -62,7 +63,11 @@ collectors_info_t *collectors_info_init()
}
memset(container, 0, sizeof(notifier_container_t));
container->notifier.notify = _collector_info_cb;
- notifier_subscribe(NOTIFY_TOPIC_SYSTEM, &container->notifier);
+ if (notifier_subscribe(NOTIFY_TOPIC_SYSTEM, &container->notifier) != ASC_RESULT_OK) {
+ collectors_info_deinit((collectors_info_t *)container);
+ return NULL;
+ }
+
return (collectors_info_t *)container;
}
@@ -86,6 +91,8 @@ collector_info_t *collectors_info_get(collectors_info_t *collectors_info, uint32
log_error("collectors_info_t *is NULL");
return NULL;
}
- *size = COLLECTORS_INFO_SIZE;
+ if (size) {
+ *size = COLLECTORS_INFO_SIZE;
+ }
return container->info;
}
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/components_factory.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/components_factory.c
new file mode 100644
index 00000000..8371594b
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/components_factory.c
@@ -0,0 +1,141 @@
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
+
+#include
+
+#include
+
+#include "asc_security_core/components_factory_declarations.h"
+#include "asc_security_core/components_manager.h"
+
+components_factory_t g_component_factory[COMPONENTS_COUNT];
+
+static component_load_function_t *component_load_function_array[] = {
+ COMPONENTS_FACTORY_LOAD(ManagerCore),
+ COMPONENTS_FACTORY_LOAD(Logger),
+#ifdef ASC_COMPONENT_SECURITY_MODULE
+ COMPONENTS_FACTORY_LOAD(SecurityModule),
+#endif
+ COMPONENTS_FACTORY_LOAD(CollectorsCore),
+#ifdef ASC_COMPONENT_CONFIGURATION
+ COMPONENTS_FACTORY_LOAD(Configuration),
+#endif
+#ifdef ASC_COMPONENT_CONFIGURATION_PLAT
+ COMPONENTS_FACTORY_LOAD(ConfigurationPlatform),
+#endif
+#ifdef ASC_COMPONENT_COMMAND_EXECUTOR_PLAT
+ COMPONENTS_FACTORY_LOAD(CommandExecutorPlatform),
+#endif
+#ifdef ASC_COLLECTOR_HEARTBEAT_ENABLED
+ COMPONENTS_FACTORY_LOAD(Heartbeat),
+#endif
+#ifdef ASC_COLLECTOR_BASELINE_ENABLED
+ COMPONENTS_FACTORY_LOAD(Baseline),
+#endif
+#ifdef ASC_COMPONENT_BASELINE_PLAT
+ COMPONENTS_FACTORY_LOAD(BaselinePlatform),
+#endif
+#ifdef ASC_COMPONENT_IPC_PLAT
+ COMPONENTS_FACTORY_LOAD(IpcPlatform),
+#endif
+#ifdef ASC_COMPONENT_CLI_PLAT
+ #ifdef ASC_COMPONENT_DEMO_CLI_PLAT
+ COMPONENTS_FACTORY_LOAD(CliDemoPlatform),
+ #endif
+ COMPONENTS_FACTORY_LOAD(CliPlatform),
+#endif
+#ifdef ASC_COLLECTOR_SYSTEM_INFORMATION_ENABLED
+ COMPONENTS_FACTORY_LOAD(SystemInformation),
+#endif
+#ifdef ASC_COLLECTOR_NETWORK_ACTIVITY_ENABLED
+ COMPONENTS_FACTORY_LOAD(NetworkActivity),
+#endif
+#ifdef ASC_COLLECTOR_LISTENING_PORTS_ENABLED
+ COMPONENTS_FACTORY_LOAD(ListeningPorts),
+#endif
+#ifdef ASC_COLLECTOR_PROCESS_ENABLED
+ COMPONENTS_FACTORY_LOAD(Process),
+#endif
+ NULL
+};
+
+component_load_function_t **components_factory_get_load_array(void)
+{
+ return component_load_function_array;
+}
+
+component_id_t components_factory_create_id(int index)
+{
+ return (component_id_t)(&g_component_factory[index].component);
+}
+
+asc_result_t components_factory_set(const char *name, int index, component_ops_t *ops, bool auto_disable)
+{
+ if (name == NULL || str_str(name, "_")) {
+ log_fatal("Component name=[%s] is wrong (NULL or has '_')", name ? name : "NULL");
+ return ASC_RESULT_BAD_ARGUMENT;
+ }
+ if (components_manager_get_id_by_name(name, str_len(name))) {
+ log_fatal("Component name=[%s] already exists", name);
+ return ASC_RESULT_BAD_ARGUMENT;
+ }
+ g_component_factory[index].component.info.state = COMPONENT_LOADED;
+ g_component_factory[index].component.info.last_result = ASC_RESULT_OK;
+ g_component_factory[index].component.info.log_level = ASC_LOG_LEVEL;
+ g_component_factory[index].component.ops = ops;
+ g_component_factory[index].component.info.id = components_factory_create_id(index);
+ g_component_factory[index].component.info.name = name;
+ g_component_factory[index].component.info.enumerator = index;
+ g_component_factory[index].component.info.auto_start_disable = auto_disable;
+ bit_vector_clean(component_owners_t, &g_component_factory[index].component.info.owners);
+ //__auto_generated_self_id = g_component_factory[_component].component.info.id;
+ return ASC_RESULT_OK;
+}
+
+#ifdef ASC_DYNAMIC_FACTORY_ENABLED
+asc_result_t components_factory_set_dynamic_collector(const char *name, int index, component_ops_t *ops, bool auto_disable)
+{
+ if (index < (__COLLECTOR_COUNT + ASC_EXTRA_COLLECTORS_COUNT) || index >= COLLECTORS_COUNT) {
+ log_fatal("Index=[%d] is out of dynamic collectors area", index);
+ return ASC_RESULT_MEMORY_EXCEPTION;
+ }
+ return components_factory_set(name, index, ops, auto_disable);
+}
+
+asc_result_t components_factory_set_dynamic_component(const char *name, int index, component_ops_t *ops, bool auto_disable)
+{
+ if (index < (__COMPONENT_COUNT + ASC_EXTRA_COMPONENTS_COUNT) || index >= COMPONENTS_COUNT) {
+ log_fatal("Index=[%d] is out of dynamic components area", index);
+ return ASC_RESULT_MEMORY_EXCEPTION;
+ }
+ return components_factory_set(name, index, ops, auto_disable);
+}
+#endif
+
+void component_factory_unload(int index)
+{
+ g_component_factory[index].component.ops = NULL;
+ g_component_factory[index].component.info.state = COMPONENT_UNLOADED;
+ g_component_factory[index].component.info.id = 0;
+ g_component_factory[index].component.info.name = NULL;
+ g_component_factory[index].component.info.enumerator = COMPONENTS_COUNT;
+ g_component_factory[index].component.info.log_level = ASC_LOG_LEVEL;
+ bit_vector_clean(component_owners_t, &g_component_factory[index].component.info.owners);
+}
+
+void components_factory_unload(void)
+{
+ int index;
+
+ for (index = 0; index < COMPONENTS_COUNT; index++) {
+ component_factory_unload(index);
+ }
+}
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/components_manager.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/components_manager.c
new file mode 100644
index 00000000..c2900b3c
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/components_manager.c
@@ -0,0 +1,458 @@
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
+#include
+#include
+#include
+
+#include
+
+#include "asc_security_core/logger.h"
+#include "asc_security_core/utils/string_utils.h"
+
+#include "asc_security_core/components_factory_declarations.h"
+#include "asc_security_core/components_manager.h"
+
+static bool _components_manager_initialized = false;
+static uintptr_t _components_manager_global_context;
+
+static void components_manager_do_lcm_action(component_state_enum_t to_state, component_state_enum_t from_state);
+static int _get_owner_enumerator(component_id_t owner_id);
+
+asc_result_t components_manager_init(void)
+{
+ asc_result_t result = ASC_RESULT_OK;
+
+ if (_components_manager_initialized) {
+ log_debug("Aleady initialized");
+ return ASC_RESULT_INITIALIZED;
+ }
+
+ log_debug("Init");
+ int index = 0;
+ component_load_function_t *func_ptr = NULL;
+ component_load_function_t **init_array = components_factory_get_load_array();
+
+ if (init_array == NULL) {
+ log_fatal("Unable to get components init array");
+ return ASC_RESULT_EXCEPTION;
+ }
+ _components_manager_initialized = true;
+
+ while ((func_ptr = init_array[index++])) {
+ component_load_function_t func = *func_ptr;
+
+ if (func) {
+ asc_result_t ret = func();
+ if (ret != ASC_RESULT_OK) {
+ result = ret;
+ log_fatal("Unable to load component with index=[%d]", index-1);
+ }
+ }
+ }
+
+#ifdef ASC_DYNAMIC_FACTORY_ENABLED
+ asc_result_t result_dyn = components_factory_load_dynamic(NULL);
+ if (result_dyn != ASC_RESULT_OK && result_dyn != ASC_RESULT_EMPTY) {
+ result = result_dyn;
+ }
+#endif
+
+ components_manager_do_lcm_action(COMPONENT_INITIALIZED, COMPONENT_LOADED);
+ components_manager_do_lcm_action(COMPONENT_SUBSCRIBED, COMPONENT_INITIALIZED);
+ components_manager_do_lcm_action(COMPONENT_RUNNING, COMPONENT_SUBSCRIBED);
+
+ return result;
+}
+
+asc_result_t components_manager_deinit(void)
+{
+ if (!_components_manager_initialized) {
+ log_debug("Unintialized");
+ return ASC_RESULT_IMPOSSIBLE;
+ }
+ _components_manager_initialized = false;
+ log_debug("Deinit");
+ components_manager_do_lcm_action(COMPONENT_STOPED, COMPONENT_RUNNING);
+ components_manager_do_lcm_action(COMPONENT_UNSUBSCRIBED, COMPONENT_UNDEFINED);
+ components_manager_do_lcm_action(COMPONENT_LOADED, COMPONENT_UNDEFINED);
+
+#ifdef ASC_DYNAMIC_FACTORY_ENABLED
+ components_factory_unload_dynamic(); // must be before components_factory_unload();
+#endif
+ components_factory_unload();
+ _components_manager_global_context = 0;
+ return ASC_RESULT_OK;
+}
+
+void components_manager_global_context_set(uintptr_t ctx)
+{
+ _components_manager_global_context = ctx;
+}
+
+uintptr_t components_manager_global_context_get(void)
+{
+ return _components_manager_global_context;
+}
+
+#ifdef ASC_COMPONENT_CONFIGURATION
+bool components_manager_set_log_level(component_id_t id, int set)
+{
+ unsigned int level = (set < 0) ? ASC_LOG_LEVEL : (unsigned int)set;
+
+ if (level > ASC_LOG_LEVEL) {
+ log_error("Requested log level=[%u] is above than compiled=[%u]", level, ASC_LOG_LEVEL);
+ return false;
+ }
+ if (!id) {
+ id = components_manager_get_id(ManagerCore);
+ }
+ component_info_t *info = components_manager_get_info(id);
+
+ if (info) {
+ info->log_level = level;
+ return true;
+ }
+ return false;
+}
+
+unsigned int components_manager_get_log_level(component_id_t id)
+{
+ if (!id) {
+ id = components_manager_get_id(ManagerCore);
+ }
+ component_info_t *info = components_manager_get_info(id);
+
+ // return debug if no info or not initialized yet to not lost the log print
+ if (!info || info->state == COMPONENT_UNLOADED) {
+ return LOG_LEVEL_DEBUG;
+ }
+
+ return info->log_level;
+}
+
+bool components_manager_set_log_level_all(int set)
+{
+ unsigned int level = (set < 0) ? ASC_LOG_LEVEL : (unsigned int)set;
+
+ if (level > ASC_LOG_LEVEL) {
+ log_error("Requested log level=[%u] is above than compiled=[%u]", level, ASC_LOG_LEVEL);
+ return false;
+ }
+ for (int index = 0; index < COMPONENTS_COUNT; index++) {
+ g_component_factory[index].component.info.log_level = level;
+ }
+ return true;
+}
+#endif
+
+component_t *components_manager_get_component(component_id_t id)
+{
+ for (int index = 0; index < COMPONENTS_COUNT; index++) {
+ if (g_component_factory[index].component.info.id == id) {
+ return &g_component_factory[index].component;
+ }
+ }
+ return NULL;
+}
+
+component_id_t components_manager_get_id_by_name(const char *name, size_t len)
+{
+ if (str_isempty(name)) {
+ return 0;
+ }
+
+ for (int index = 0; index < COMPONENTS_COUNT; index++) {
+
+ if (!str_ncmp(g_component_factory[index].component.info.name,
+ str_len(g_component_factory[index].component.info.name), name, len)) {
+ return g_component_factory[index].component.info.id;
+ }
+ }
+ return 0;
+}
+
+component_info_t *components_manager_get_info(component_id_t id)
+{
+ component_t *component = components_manager_get_component(id);
+
+ return component ? &component->info : NULL;
+}
+
+void *__components_manager_get_ctx(component_id_t id)
+{
+ component_t *component = components_manager_get_component(id);
+
+ return component ? component->info.ctx : NULL;
+}
+
+void __components_manager_set_ctx(component_id_t id, void *ctx)
+{
+ component_t *component = components_manager_get_component(id);
+
+ if (component) {
+ component->info.ctx = ctx;
+ }
+}
+
+asc_result_t components_manager_get_last_result(component_id_t id)
+{
+ component_t *component = components_manager_get_component(id);
+
+ return component ? component->info.last_result : ASC_RESULT_UNINITIALIZED;
+}
+
+const char *components_manager_get_name(component_id_t id)
+{
+ component_t *component = components_manager_get_component(id);
+
+ return component ? component->info.name : "";
+}
+
+asc_result_t components_manager_start(component_id_t id, component_id_t owner_id)
+{
+ asc_result_t result = ASC_RESULT_OK;
+ component_t *component = components_manager_get_component(id);
+ int owner_enumerator = -1;
+ component_state_enum_t cur_state = COMPONENT_UNLOADED;
+ component_ops_t *ops = NULL;
+ lcm_func_t func = NULL;
+
+ if (!component) {
+ return ASC_RESULT_BAD_ARGUMENT;
+ }
+
+ owner_enumerator = _get_owner_enumerator(owner_id);
+ if (owner_enumerator < 0) {
+ return ASC_RESULT_BAD_ARGUMENT;
+ }
+
+ cur_state = component->info.state;
+ if (cur_state != COMPONENT_SUBSCRIBED && cur_state != COMPONENT_STOPED && cur_state != COMPONENT_RUNNING) {
+ result = ASC_RESULT_IMPOSSIBLE;
+ goto cleanup;
+ }
+
+ /* Handle case already in running state */
+ if (cur_state == COMPONENT_RUNNING) {
+ bit_vector_set(component_owners_t, &component->info.owners, owner_enumerator, true);
+ goto cleanup;
+ }
+
+ ops = component->ops;
+ func = ops ? ops->start : NULL;
+
+ result = func ? func(id) : ASC_RESULT_OK;
+ if (result == ASC_RESULT_OK) {
+ bit_vector_set(component_owners_t, &component->info.owners, owner_enumerator, true);
+ component->info.state = COMPONENT_RUNNING;
+ }
+ goto cleanup;
+
+cleanup:
+ if (result != ASC_RESULT_OK) {
+ component->info.state = COMPONENT_FAIL;
+ log_error("failed to start component=[%s]", component->info.name);
+ }
+ return result;
+}
+
+asc_result_t components_manager_stop(component_id_t id, component_id_t owner_id, bool ignore_self_owner, bool force)
+{
+ asc_result_t result = ASC_RESULT_OK;
+ component_t *component = components_manager_get_component(id);
+ int owner_enumerator = -1;
+ bool owner = false;
+ bool self_owner = false;
+
+ if (!component) {
+ return ASC_RESULT_BAD_ARGUMENT;
+ }
+
+ owner_enumerator = _get_owner_enumerator(owner_id);
+ if (owner_enumerator < 0) {
+ return ASC_RESULT_BAD_ARGUMENT;
+ }
+
+ if (component->info.state == COMPONENT_FAIL) {
+ result = ASC_RESULT_IMPOSSIBLE;
+ goto cleanup;
+ }
+
+ /* Handle case already in stopped state */
+ if (component->info.state != COMPONENT_RUNNING) {
+ if (force) {
+ bit_vector_clean(component_owners_t, &component->info.owners);
+ } else {
+ if (ignore_self_owner) {
+ bit_vector_set(component_owners_t, &component->info.owners, component->info.enumerator, false);
+ }
+ bit_vector_set(component_owners_t, &component->info.owners, owner_enumerator, false);
+ }
+ goto cleanup;
+ }
+
+ /* Prepare vector */
+ if (force) {
+ bit_vector_clean(component_owners_t, &component->info.owners);
+ } else {
+ owner = bit_vector_get(component_owners_t, &component->info.owners, owner_enumerator);
+ self_owner = bit_vector_get(component_owners_t, &component->info.owners, component->info.enumerator);
+ if (ignore_self_owner) {
+ bit_vector_set(component_owners_t, &component->info.owners, component->info.enumerator, false);
+ }
+ bit_vector_set(component_owners_t, &component->info.owners, owner_enumerator, false);
+ }
+
+ /* Performe stop */
+ if (is_bit_vector_zero(component_owners_t, &component->info.owners)) {
+ component_ops_t *ops = component->ops;
+ lcm_func_t func = ops ? ops->stop : NULL;
+
+ result = func ? func(id) : ASC_RESULT_OK;
+ if (result == ASC_RESULT_OK) {
+ component->info.state = COMPONENT_STOPED;
+ } else {
+ /* Restore status of owners */
+ bit_vector_set(component_owners_t, &component->info.owners, owner_enumerator, owner);
+ bit_vector_set(component_owners_t, &component->info.owners, component->info.enumerator, self_owner);
+ }
+ } else {
+ /* Restore status of self owner */
+ bit_vector_set(component_owners_t, &component->info.owners, component->info.enumerator, self_owner);
+ }
+
+cleanup:
+ if (result != ASC_RESULT_OK) {
+ component->info.state = COMPONENT_FAIL;
+ log_error("failed to stop component=[%s]", component->info.name);
+ }
+ return result;
+}
+
+static lcm_func_t _load_lcm_function(int index, component_state_enum_t to_state, component_state_enum_t from_state)
+{
+ lcm_func_t func = NULL;
+ component_ops_t *ops = g_component_factory[index].component.ops;
+
+ if (ops) {
+ switch (to_state) {
+ case COMPONENT_INITIALIZED:
+ func = ops->init;
+ break;
+ case COMPONENT_SUBSCRIBED:
+ func = ops->subscribe;
+ break;
+ case COMPONENT_RUNNING:
+ func = ops->start;
+ break;
+ case COMPONENT_STOPED:
+ func = ops->stop;
+ break;
+ case COMPONENT_UNSUBSCRIBED:
+ func = ops->unsubscribe;
+ break;
+ case COMPONENT_LOADED:
+ func = ops->deinit;
+ break;
+ default:
+ g_component_factory[index].component.info.last_result = ASC_RESULT_NOT_SUPPORTED_EXCEPTION;
+ log_fatal("Unsupported LCM state=[%d]", to_state);
+ return NULL;
+ }
+ }
+
+ log_debug("lcm function component=[%s] ops=[%p] is defined=[%d] to=[%d] from=[%d] current=[%d]",
+ g_component_factory[index].component.info.name,
+ (void *)ops, func ? 1 : 0, to_state, from_state,
+ g_component_factory[index].component.info.state);
+
+ return func;
+}
+
+static void _perform_lcm_action(lcm_func_t func, int index, component_state_enum_t to_state)
+{
+ switch (to_state)
+ {
+ case COMPONENT_RUNNING:
+ if (!g_component_factory[index].component.info.auto_start_disable) {
+ g_component_factory[index].component.info.last_result =
+ components_manager_start(g_component_factory[index].component.info.id, g_component_factory[index].component.info.id);
+ } else {
+ log_debug("%d function is disabled by auto_start_disable==true in component=[%s]", to_state, g_component_factory[index].component.info.name);
+ }
+
+ break;
+ case COMPONENT_STOPED:
+ g_component_factory[index].component.info.last_result =
+ components_manager_stop(g_component_factory[index].component.info.id, g_component_factory[index].component.info.id, false, true);
+ break;
+ default:
+ if (func == NULL) {
+ if (g_component_factory[index].component.info.state != COMPONENT_FAIL) {
+ g_component_factory[index].component.info.state = to_state;
+ }
+ log_debug("%d function function in component=[%s] is not armed", to_state, g_component_factory[index].component.info.name);
+ return;
+ }
+ g_component_factory[index].component.info.last_result = func(g_component_factory[index].component.info.id);
+
+ if (g_component_factory[index].component.info.last_result != ASC_RESULT_OK) {
+ g_component_factory[index].component.info.state = COMPONENT_FAIL;
+ log_error("failed to %d function component=[%s]", to_state, g_component_factory[index].component.info.name);
+ } else {
+ g_component_factory[index].component.info.state = to_state;
+ log_debug("%d function component=[%s] done", to_state, g_component_factory[index].component.info.name);
+ }
+ break;
+ }
+}
+
+static void components_manager_do_lcm_action(component_state_enum_t to_state, component_state_enum_t from_state)
+{
+ for (int index = 0; index < COMPONENTS_COUNT; index++) {
+ if (g_component_factory[index].component.info.state == COMPONENT_UNLOADED) {
+ continue;
+ }
+ g_component_factory[index].component.info.last_result = ASC_RESULT_OK;
+
+ lcm_func_t func = _load_lcm_function(index, to_state, from_state);
+
+ if (g_component_factory[index].component.info.last_result == ASC_RESULT_NOT_SUPPORTED_EXCEPTION) {
+ return;
+ }
+
+ bool is_stop_start_same_state = false;
+
+ if (g_component_factory[index].component.info.state == to_state && (to_state == COMPONENT_RUNNING || to_state == COMPONENT_STOPED)) {
+ is_stop_start_same_state = true;
+ }
+
+ if (func && !is_stop_start_same_state && from_state != COMPONENT_UNDEFINED && g_component_factory[index].component.info.state != from_state) {
+ log_error("Expected=[%d] state is not match current=[%d] component=[%s]", from_state, g_component_factory[index].component.info.state, g_component_factory[index].component.info.name);
+ g_component_factory[index].component.info.last_result = ASC_RESULT_PARSE_EXCEPTION;
+ continue;
+ }
+ _perform_lcm_action(func, index, to_state);
+ }
+}
+
+static int _get_owner_enumerator(component_id_t owner_id)
+{
+ component_t *owner = components_manager_get_component(owner_id);
+
+ if (owner == NULL) {
+ return -1;
+ }
+ return owner->info.enumerator;
+}
+
+/* Component manager is component itself */
+COMPONENTS_FACTORY_DEFINITION(ManagerCore, NULL)
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/core.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/core.c
index b148e535..5a6be1cb 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/core.c
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/core.c
@@ -1,35 +1,130 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
-
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#include
#include
#include
-#include "asc_security_core/collector_collection.h"
-#include "asc_security_core/configuration.h"
+#include
+
+#include "asc_security_core/components_manager.h"
#include "asc_security_core/logger.h"
-#include "asc_security_core/collector.h"
#include "asc_security_core/object_pool.h"
#include "asc_security_core/serializer.h"
+#include "asc_security_core/utils/ievent_loop.h"
#include "asc_security_core/utils/itime.h"
+#include "asc_security_core/utils/irand.h"
+#include "asc_security_core/utils/notifier.h"
#include "asc_security_core/utils/os_utils.h"
#include "asc_security_core/core.h"
+#include "asc_security_core/version.h"
#define CORE_OBJECT_POOL_COUNT 1
+#define CORE_RESTART_SLEEP 1
+
+typedef struct core {
+ /* This macro must be first in object */
+ COLLECTION_INTERFACE(struct core);
+
+ const char *security_module_id;
+ uint32_t security_module_version;
+ collector_collection_t *collector_collection_ptr;
+
+ uint8_t *message_buffer;
+ size_t message_buffer_size;
+#ifdef ASC_DYNAMIC_MEMORY_ENABLED
+ bool message_allocated;
+#endif
+ bool message_empty;
+
+ serializer_t *serializer;
+ unsigned long init_random_collect_offset;
+ unsigned long nearest_collect_time;
+ event_loop_timer_handler h_collect;
+ event_loop_timer_handler h_start;
+ notifier_t security_module_state_notifier;
+} core_t;
OBJECT_POOL_DECLARATIONS(core_t)
OBJECT_POOL_DEFINITIONS(core_t, CORE_OBJECT_POOL_COUNT)
-core_t *core_init()
+typedef struct {
+ unsigned long minimum;
+ unsigned long curr_time;
+ bool is_in_start;
+} calc_nearest_collect_t;
+
+static asc_result_t _cm_init(component_id_t id);
+static asc_result_t _cm_deinit(component_id_t id);
+static asc_result_t _cm_start(component_id_t id);
+static asc_result_t _cm_stop(component_id_t id);
+static component_ops_t _ops = {
+ .init = _cm_init,
+ .deinit = _cm_deinit,
+ .start = _cm_start,
+ .stop = _cm_stop,
+};
+
+COMPONENTS_FACTORY_DEFINITION(CollectorsCore, &_ops)
+
+static void _core_deinit(core_t *core_ptr, component_id_t id);
+static asc_result_t _set_next_collect_timer(core_t *core_ptr, unsigned long curr_time, bool is_in_start);
+static void _security_module_state_cb(notifier_t *notifier, int message_num, void *payload);
+
+static void _init_random_collect_offset(core_t *core_ptr)
+{
+ unsigned long now = itime_time(NULL);
+ if (now == ITIME_FAILED) {
+ log_error("Error get current time");
+ now = 0;
+ }
+#ifdef ASC_FIRST_FORCE_COLLECTION_INTERVAL
+ #if ASC_FIRST_FORCE_COLLECTION_INTERVAL < 0
+ core_ptr->init_random_collect_offset = now;
+ #else
+ core_ptr->init_random_collect_offset = now + ASC_FIRST_FORCE_COLLECTION_INTERVAL;
+ #endif
+#else
+ core_ptr->init_random_collect_offset = now + (unsigned long)(irand_int() % (2 * ASC_FIRST_COLLECTION_INTERVAL) + ASC_FIRST_COLLECTION_INTERVAL);
+#endif
+}
+
+static unsigned long _calculate_collector_time_offset(core_t *core_ptr, collector_t *collector_ptr, component_state_enum_t state)
+{
+ unsigned long offset, base_collecting_time = core_ptr->init_random_collect_offset;
+
+ // TODO it breaks sequence of collections and cause to increasing of security messages - need to sync on init_random_collect_offset
+ if (state == COMPONENT_RUNNING) {
+ unsigned long now = itime_time(NULL);
+ if (now == ITIME_FAILED) {
+ log_error("Error get current time");
+ now = 0;
+ }
+ base_collecting_time = now + ASC_FIRST_COLLECTION_INTERVAL;
+ }
+ if (collector_ptr->internal.interval > core_ptr->init_random_collect_offset) {
+ // should never happens
+ offset = base_collecting_time;
+ } else {
+ if (base_collecting_time >= collector_ptr->internal.interval) {
+ offset = base_collecting_time - collector_ptr->internal.interval;
+ } else {
+ // should never happens
+ offset = base_collecting_time;
+ }
+ }
+ return offset;
+}
+
+static core_t *core_init(component_id_t id)
{
asc_result_t result = ASC_RESULT_OK;
core_t *core_ptr = NULL;
@@ -41,6 +136,7 @@ core_t *core_init()
goto cleanup;
}
memset(core_ptr, 0, sizeof(core_t));
+ core_ptr->nearest_collect_time = CORE_NEAREST_TIMER_UNSET_VAL;
core_ptr->security_module_id = os_utils_get_security_module_id();
if (core_ptr->security_module_id == NULL) {
@@ -67,29 +163,34 @@ core_t *core_init()
result = serializer_message_begin(core_ptr->serializer, core_ptr->security_module_id, core_ptr->security_module_version);
-#ifdef DYNAMIC_MEMORY_ENABLED
+#ifdef ASC_DYNAMIC_MEMORY_ENABLED
core_ptr->message_allocated = false;
#endif
core_ptr->message_empty = true;
+ _init_random_collect_offset(core_ptr);
+
+ core_ptr->security_module_state_notifier.notify = _security_module_state_cb;
+ result = notifier_subscribe(NOTIFY_TOPIC_SECURITY_MODULE_STATE, &core_ptr->security_module_state_notifier);
cleanup:
if (result != ASC_RESULT_OK) {
log_error("Failed to init client core_t");
- core_deinit(core_ptr);
+ _core_deinit(core_ptr, id);
core_ptr = NULL;
}
return core_ptr;
}
-void core_deinit(core_t *core_ptr)
+static void _core_deinit(core_t *core_ptr, component_id_t id)
{
if (core_ptr != NULL) {
+ notifier_unsubscribe(NOTIFY_TOPIC_SECURITY_MODULE_STATE, &core_ptr->security_module_state_notifier);
if (core_ptr->collector_collection_ptr != NULL) {
collector_collection_deinit(core_ptr->collector_collection_ptr);
}
-#ifdef DYNAMIC_MEMORY_ENABLED
+#ifdef ASC_DYNAMIC_MEMORY_ENABLED
if (core_ptr->message_allocated) {
free(core_ptr->message_buffer);
core_ptr->message_buffer = NULL;
@@ -103,31 +204,154 @@ void core_deinit(core_t *core_ptr)
object_pool_free(core_t, core_ptr);
core_ptr = NULL;
}
+ components_manager_set_self_ctx(NULL);
+}
+
+static void _start_stop_all_collectors(collector_t *collector_ptr, void *context)
+{
+ bool do_start = *(bool*)context;
+
+ component_id_t collector_id = components_manager_get_id(collector_ptr->internal.type);
+ component_id_t core_id = components_manager_get_self_id();
+
+ if (do_start) {
+ components_manager_start(collector_id, core_id);
+ } else {
+ components_manager_stop(collector_id, core_id, true, false);
+ }
+}
+
+#ifdef ASC_COMPONENT_CORE_SUPPORTS_RESTART
+static void _reset_last_collected_timestamp(collector_t *collector_ptr, void *context)
+{
+ core_t *core_ptr = context;
+
+ unsigned long offset = _calculate_collector_time_offset(core_ptr, collector_ptr, COMPONENT_STOPED);
+
+ collector_set_last_collected_timestamp(collector_ptr, offset);
+}
+
+static void cb_do_start(event_loop_timer_handler h, void *ctx)
+{
+ core_t *core_ptr = ctx;
+ ievent_loop_t *el = ievent_loop_get_instance();
+
+ el->timer_delete(h);
+
+ if (core_ptr == NULL) {
+ log_error("core uninitialized");
+ return;
+ }
+ bool do_start = true;
+ component_id_t core_id = components_manager_get_self_id();
+ _init_random_collect_offset(core_ptr);
+ collector_collection_foreach(core_ptr->collector_collection_ptr, _reset_last_collected_timestamp, core_ptr);
+ collector_collection_foreach(core_ptr->collector_collection_ptr, _start_stop_all_collectors, &do_start);
+ components_manager_start(core_id, core_id);
+}
+#endif
+
+static void _start_stop_collection(bool do_start, bool restart)
+{
+ core_t *core_ptr = components_manager_get_self_ctx();
+
+ if (core_ptr == NULL) {
+ log_error("core uninitialized");
+ return;
+ }
+ component_id_t core_id = components_manager_get_self_id();
+
+#ifdef ASC_COMPONENT_CORE_SUPPORTS_RESTART
+ if (restart) {
+ bool restart_do_start = false;
+ collector_collection_foreach(core_ptr->collector_collection_ptr, _start_stop_all_collectors, &restart_do_start);
+ components_manager_stop(core_id, core_id, false, false);
+ core_message_deinit();
+ ievent_loop_t *el = ievent_loop_get_instance();
+ el->timer_delete(core_ptr->h_start);
+ core_ptr->h_start = el->timer_create(cb_do_start, core_ptr, CORE_RESTART_SLEEP, 0, &core_ptr->h_start);
+ } else
+#endif
+ {
+ collector_collection_foreach(core_ptr->collector_collection_ptr, _start_stop_all_collectors, &do_start);
+
+ if (do_start) {
+ components_manager_start(core_id, core_id);
+ } else {
+ components_manager_stop(core_id, core_id, false, false);
+ }
+ }
}
-asc_result_t core_collect(core_t *core_ptr)
+static void _security_module_state_cb(notifier_t *notifier, int message_num, void *payload)
+{
+ switch (message_num)
+ {
+ case NOTIFY_SECURITY_MODULE_CONNECTED:
+ _start_stop_collection(true, false);
+ log_info("Security Module inserted to 'Connected' state");
+ break;
+#ifdef ASC_COMPONENT_CORE_SUPPORTS_RESTART
+ case NOTIFY_SECURITY_MODULE_RESTART:
+ _start_stop_collection(true, true);
+ log_info("Security Module inserted to 'Connected' state with restart");
+ break;
+#endif
+ case NOTIFY_SECURITY_MODULE_PENDING:
+ _start_stop_collection(true, false);
+ log_info("Security Module inserted to 'Pending' state");
+ break;
+ case NOTIFY_SECURITY_MODULE_SUSPENDED:
+ _start_stop_collection(false, false);
+ log_info("Security Module inserted to 'Suspended' state");
+ break;
+ default:
+ log_error("Unsupported Security Module state");
+ break;
+ }
+}
+
+static asc_result_t core_collect(core_t *core_ptr, unsigned long now)
{
asc_result_t result = ASC_RESULT_OK;
- uint32_t current_snapshot = itime_time(NULL);
bool at_least_one_success = false;
bool time_passed = false;
+ if (now == ITIME_FAILED) {
+ log_error("Error get current time");
+ return ASC_RESULT_IMPOSSIBLE;
+ }
+
+ core_message_deinit();
+
for (priority_collectors_t *prioritized_collectors = collector_collection_get_head_priority(core_ptr->collector_collection_ptr);
prioritized_collectors != NULL;
prioritized_collectors = collector_collection_get_next_priority(core_ptr->collector_collection_ptr, prioritized_collectors)
) {
- linked_list_collector_t_handle collector_list = priority_collectors_get_list(prioritized_collectors);
+ linked_list_t *collector_list = priority_collectors_get_list(prioritized_collectors);
+ collector_t *current_collector = NULL;
+ linked_list_foreach(collector_list, current_collector)
+ {
+ component_info_t *info = components_manager_get_info(components_manager_get_id(current_collector->internal.type));
+ if (!info || info->state != COMPONENT_RUNNING) {
+ continue;
+ }
- for (collector_t *current_collector=linked_list_collector_t_get_first(collector_list);
- current_collector!=NULL;
- current_collector=current_collector->next
- ) {
- uint32_t last_collected = collector_get_last_collected_timestamp(current_collector);
- double interval = priority_collectors_get_interval(prioritized_collectors);
+ unsigned long last_collected = collector_get_last_collected_timestamp(current_collector);
+ unsigned long interval = current_collector->internal.interval;
+ unsigned long delta;
+ if (now > last_collected) {
+ delta = now - last_collected;
+ } else {
+ log_error("Current time is less than last collected interval");
+ delta = interval;
+ }
- if (current_snapshot - last_collected >= interval) {
+ if (delta >= interval) {
time_passed = true;
result = collector_serialize_events(current_collector, core_ptr->serializer);
+ // overwrite last collected time with common start value to store sequence of collections
+ collector_set_last_collected_timestamp(current_collector, now);
if (result == ASC_RESULT_EMPTY) {
log_debug("empty, collector type=[%d]", current_collector->internal.type);
continue;
@@ -145,18 +369,114 @@ asc_result_t core_collect(core_t *core_ptr)
error:
// In case of serializer failure, it is unsafe to keep building the message
- core_message_deinit(core_ptr);
+ core_message_deinit();
return ASC_RESULT_EXCEPTION;
}
+static void _collector_collection_calc_nearest_collect(collector_t *collector_ptr, void *context)
+{
+ calc_nearest_collect_t *ctx = (calc_nearest_collect_t *)context;
+ component_info_t *info = components_manager_get_info(components_manager_get_id(collector_ptr->internal.type));
+
+ /* Exclude failed collectors from nearest collect time calculation */
+ if (!info) {
+ return;
+ }
+ if (!ctx->is_in_start) {
+ if (info->state != COMPONENT_RUNNING) {
+ return;
+ }
+ } else { /* If we are in core start function take in account also subscribed collectors */
+ if (info->state != COMPONENT_RUNNING && info->state != COMPONENT_SUBSCRIBED) {
+ return;
+ }
+ }
+
+ unsigned long curr_time = ctx->curr_time;
+ unsigned long last_collected = collector_get_last_collected_timestamp(collector_ptr);
+ unsigned long interval = collector_ptr->internal.interval;
+ unsigned long next_time;
+
+ if (last_collected > curr_time) {
+ next_time = last_collected - curr_time + interval;
+ } else {
+ unsigned long delta = curr_time - last_collected;
+ if (interval <= delta) {
+ next_time = 0;
+ } else {
+ next_time = interval - delta;
+ }
+ }
+
+ if (next_time < ctx->minimum) {
+ ctx->minimum = next_time;
+ }
+}
+
+static void cb_collect(event_loop_timer_handler h, void *ctx)
+{
+ core_t *core_ptr = ctx;
+ ievent_loop_t *el = ievent_loop_get_instance();
+
+ el->timer_delete(h);
+
+ if (core_ptr == NULL) {
+ log_error("core uninitialized");
+ return;
+ }
+ unsigned long curr_time = itime_time(NULL);
+
+ if (core_collect(core_ptr, curr_time) == ASC_RESULT_OK) {
+ notifier_notify(NOTIFY_TOPIC_COLLECT, NOTIFY_MESSAGE_READY, NULL);
+ }
+ _set_next_collect_timer(core_ptr, curr_time, false);
+}
+
+static asc_result_t _set_next_collect_timer(core_t *core_ptr, unsigned long now, bool is_in_start)
+{
+ ievent_loop_t *el = ievent_loop_get_instance();
+ calc_nearest_collect_t ctx;
+
+ // stop existing timer
+ el->timer_delete(core_ptr->h_collect);
-asc_result_t core_message_get(core_t* core_ptr, security_message_t* security_message_ptr) {
+ if (now == ITIME_FAILED) {
+ log_error("Error get current time");
+ core_ptr->h_collect = el->timer_create(cb_collect, core_ptr, ASC_HIGH_PRIORITY_INTERVAL, 0, &core_ptr->h_collect);
+ core_ptr->nearest_collect_time = ASC_HIGH_PRIORITY_INTERVAL;
+ return ASC_RESULT_OK;
+ }
+
+ ctx.minimum = CORE_NEAREST_TIMER_UNSET_VAL;
+ ctx.curr_time = now;
+ ctx.is_in_start = is_in_start;
+
+ collector_collection_foreach(core_ptr->collector_collection_ptr, _collector_collection_calc_nearest_collect, &ctx);
+
+ if (ctx.minimum == CORE_NEAREST_TIMER_UNSET_VAL) {
+ log_info("the list of collectors is empty");
+ ctx.minimum = ASC_HIGH_PRIORITY_INTERVAL;
+ core_ptr->h_collect = el->timer_create(cb_collect, core_ptr, ctx.minimum, 0, &core_ptr->h_collect);
+ } else {
+ log_debug("the nearest collection interval=[%lu]", ctx.minimum);
+ core_ptr->h_collect = el->timer_create(cb_collect, core_ptr, ctx.minimum, 0, &core_ptr->h_collect);
+ }
+
+ core_ptr->nearest_collect_time = ctx.minimum;
+
+ return ASC_RESULT_OK;
+}
+
+/* API Functions */
+asc_result_t core_message_get(security_message_t* security_message_ptr)
+{
asc_result_t result = ASC_RESULT_OK;
+ core_t *core_ptr = components_manager_get_self_ctx();
if (core_ptr == NULL || security_message_ptr == NULL) {
- result = ASC_RESULT_BAD_ARGUMENT;
- log_error("bad argument");
+ result = ASC_RESULT_MEMORY_EXCEPTION;
+ log_error("core uninitialized");
goto cleanup;
}
@@ -181,11 +501,11 @@ asc_result_t core_message_get(core_t* core_ptr, security_message_t* security_mes
}
if (result == ASC_RESULT_IMPOSSIBLE) {
-#ifndef DYNAMIC_MEMORY_ENABLED
+#ifndef ASC_DYNAMIC_MEMORY_ENABLED
log_error("failed in serializer_buffer_get, message too big");
result = ASC_RESULT_EXCEPTION;
goto cleanup;
-#else /* DYNAMIC_MEMORY_ENABLED */
+#else /* ASC_DYNAMIC_MEMORY_ENABLED */
result = ASC_RESULT_OK;
log_debug("failed in serializer_buffer_get on first attempt, re-allocating buffer...");
if (serializer_buffer_get_size(core_ptr->serializer, &core_ptr->message_buffer_size) != ASC_RESULT_OK) {
@@ -209,7 +529,7 @@ asc_result_t core_message_get(core_t* core_ptr, security_message_t* security_mes
goto cleanup;
}
log_debug("re-allocating buffer done successfully");
-#endif /* DYNAMIC_MEMORY_ENABLED */
+#endif /* ASC_DYNAMIC_MEMORY_ENABLED */
}
}
@@ -219,20 +539,60 @@ asc_result_t core_message_get(core_t* core_ptr, security_message_t* security_mes
cleanup:
if (result == ASC_RESULT_EXCEPTION || result == ASC_RESULT_MEMORY_EXCEPTION) {
- core_message_deinit(core_ptr);
+ core_message_deinit();
}
return result;
}
-asc_result_t core_message_deinit(core_t *core_ptr)
+asc_result_t core_collector_register(collector_t *collector_ptr)
{
+ core_t *core_ptr = components_manager_get_self_ctx();
+
if (core_ptr == NULL) {
- log_error("bad argument");
- return ASC_RESULT_BAD_ARGUMENT;
+ log_error("core uninitialized");
+ return ASC_RESULT_MEMORY_EXCEPTION;
+ }
+ component_state_enum_t state = components_manager_get_info(components_manager_get_self_id())->state;
+ unsigned long offset = _calculate_collector_time_offset(core_ptr, collector_ptr, state);
+
+ asc_result_t result = collector_collection_register(core_ptr->collector_collection_ptr, collector_ptr, offset);
+
+ if (state == COMPONENT_RUNNING) {
+ _set_next_collect_timer(core_ptr, itime_time(NULL), false);
}
+ return result;
+}
-#ifdef DYNAMIC_MEMORY_ENABLED
+asc_result_t core_collector_unregister(collector_t *collector_ptr)
+{
+ core_t *core_ptr = components_manager_get_self_ctx();
+
+ if (core_ptr == NULL) {
+ log_error("core uninitialized");
+ return ASC_RESULT_MEMORY_EXCEPTION;
+ }
+
+ collector_collection_unregister(core_ptr->collector_collection_ptr, collector_ptr);
+
+ component_state_enum_t state = components_manager_get_info(components_manager_get_self_id())->state;
+
+ if (state == COMPONENT_RUNNING) {
+ _set_next_collect_timer(core_ptr, itime_time(NULL), false);
+ }
+ return ASC_RESULT_OK;
+}
+
+asc_result_t core_message_deinit(void)
+{
+ core_t *core_ptr = components_manager_get_self_ctx();
+
+ if (core_ptr == NULL) {
+ log_error("core uninitialized");
+ return ASC_RESULT_MEMORY_EXCEPTION;
+ }
+
+#ifdef ASC_DYNAMIC_MEMORY_ENABLED
if (core_ptr->message_allocated) {
free(core_ptr->message_buffer);
core_ptr->message_allocated = false;
@@ -255,3 +615,93 @@ asc_result_t core_message_deinit(core_t *core_ptr)
return ASC_RESULT_OK;
}
+
+unsigned long core_get_init_random_collect_offset(void)
+{
+ core_t *core_ptr = components_manager_get_self_ctx();
+
+ if (core_ptr == NULL) {
+ log_error("core uninitialized");
+ return 0;
+ }
+ return core_ptr->init_random_collect_offset;
+}
+
+unsigned long core_get_nearest_collect_time(void)
+{
+ core_t *core_ptr = components_manager_get_self_ctx();
+
+ if (core_ptr == NULL) {
+ log_error("core uninitialized");
+ return 0;
+ }
+ return core_ptr->nearest_collect_time;
+}
+
+collector_collection_t *core_get_collector_collection(void)
+{
+ core_t *core_ptr = components_manager_get_self_ctx();
+
+ if (core_ptr == NULL) {
+ log_error("core uninitialized");
+ return NULL;
+ }
+ return core_ptr->collector_collection_ptr;
+}
+
+/* OPS Functions */
+static asc_result_t _cm_init(component_id_t id)
+{
+ core_t *ptr = core_init(id);
+
+ if (ptr == NULL) {
+ components_manager_set_self_ctx(NULL);
+ return ASC_RESULT_EXCEPTION;
+ }
+ components_manager_set_self_ctx(ptr);
+
+ return ASC_RESULT_OK;
+}
+
+static asc_result_t _cm_deinit(component_id_t id)
+{
+ core_t *core_ptr = components_manager_get_self_ctx();
+
+ if (core_ptr == NULL) {
+ log_error("core uninitialized");
+ return ASC_RESULT_MEMORY_EXCEPTION;
+ }
+
+ _core_deinit(core_ptr, id);
+ return ASC_RESULT_OK;
+}
+
+asc_result_t _cm_stop(component_id_t id)
+{
+ core_t *core_ptr = components_manager_get_self_ctx();
+
+ if (core_ptr == NULL) {
+ log_error("core uninitialized");
+ return ASC_RESULT_MEMORY_EXCEPTION;
+ }
+ ievent_loop_t *el = ievent_loop_get_instance();
+ el->timer_delete(core_ptr->h_start);
+ el->timer_delete(core_ptr->h_collect);
+ core_ptr->nearest_collect_time = CORE_NEAREST_TIMER_UNSET_VAL;
+
+ return ASC_RESULT_OK;
+}
+
+static asc_result_t _cm_start(component_id_t id)
+{
+ core_t *core_ptr = components_manager_get_self_ctx();
+
+ if (core_ptr == NULL) {
+ log_error("core uninitialized");
+ return ASC_RESULT_MEMORY_EXCEPTION;
+ }
+ ievent_loop_t *el = ievent_loop_get_instance();
+ el->timer_delete(core_ptr->h_start);
+ /* Last parameter is 'true' because we do not want to base on sequence so we taking in account all registered collectors here */
+ return _set_next_collect_timer(core_ptr, itime_time(NULL), true);
+}
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/logger.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/logger.c
index 1f56716e..a9a99b33 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/logger.c
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/logger.c
@@ -1,33 +1,260 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
-
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#include
#include
#include
+
+#include
+#include "asc_security_core/components_manager.h"
+// #define ASC_TIME_H_SUPPORT
+
+#if ASC_LOG_LEVEL != LOG_LEVEL_NOTSET
+
+#ifdef ASC_TIME_H_SUPPORT
+#include
+#endif
+
+#include "asc_security_core/logger.h"
+#include "asc_security_core/utils/itime.h"
+#include "asc_security_core/utils/string_utils.h"
+#ifdef ASC_COMPONENT_CONFIGURATION
+#include "asc_security_core/configuration.h"
+#endif
+#include "asc_security_core/utils/iconv.h"
+#include "asc_security_core/utils/string_utils.h"
#include "asc_security_core/logger.h"
-#if LOG_LEVEL != LOG_LEVEL_NOTSET
-bool logger_init()
+static unsigned int _system_level = ASC_LOG_LEVEL;
+#ifdef ASC_LOG_TIMESTAMP_DEFAULT
+static bool _timestamp = true;
+#else
+static bool _timestamp = false;
+#endif
+
+static code2string_t _log_levels[] = {
+ {LOG_LEVEL_NOTSET, "NOSET"},
+ {LOG_LEVEL_FATAL, "FATAL"},
+ {LOG_LEVEL_ERROR, "ERROR"},
+ {LOG_LEVEL_WARN, "WARN"},
+ {LOG_LEVEL_INFO, "INFO"},
+ {LOG_LEVEL_DEBUG, "DEBUG"},
+ {-1, NULL}
+};
+
+static asc_result_t _cm_init(component_id_t id)
+{
+ return ASC_RESULT_OK;
+}
+
+#ifdef ASC_COMPONENT_CONFIGURATION
+static bool _conf_validate_level(conf_t *conf)
{
+ if (conf->value.type != CONF_TYPE_STRING) {
+ log_error("Invalid configuration for component=[%.*s]: invalid type for key=[%.*s]",
+ conf->component.length, conf->component.string, conf->key.length, conf->key.string);
+ return false;
+ }
+
+ if (string2code(_log_levels, conf->value.value.string.string, conf->value.value.string.length) == -1) {
+ log_error("Invalid configuration for component=[%.*s]: invalid type for key=[%.*s]",
+ conf->component.length, conf->component.string, conf->key.length, conf->key.string);
+ return false;
+ }
+
return true;
}
-void logger_deinit()
+static asc_result_t _conf_validate_or_apply(linked_list_t *conf_list, conf_origin_t origin, bool validate_only)
{
+ conf_t *conf;
+ bool all_pass = true;
+
+ linked_list_foreach(conf_list, conf)
+ {
+ char *token = NULL, *rest = NULL;
+ size_t token_len = 0, rest_len = 0;
+ component_id_t id;
+ int code;
+ log_debug("Validating [%.*s]: key=[%.*s]",
+ conf->component.length, conf->component.string, conf->key.length, conf->key.string);
+
+ if (!str_ncmp(conf->key.string, conf->key.length, "Level", str_len("Level"))) {
+ if (!_conf_validate_level(conf)) {
+ all_pass = false;
+ continue;
+ }
+
+ if (validate_only) {
+ continue;
+ }
+
+ code = string2code(_log_levels, conf->value.value.string.string, conf->value.value.string.length);
+ logger_set_system_log_level(code);
+ continue;
+ }
+
+ if (origin == CONF_ORIGIN_TWIN) {
+ all_pass = false;
+ log_error("Component=[%.*s] key=[%.*s] can't be configured via device twin",
+ conf->component.length, conf->component.string, conf->key.length, conf->key.string);
+ continue;
+ }
+
+ /* Validate key in format: _Level */
+ if (str_split(conf->key.string, &token, &token_len, &rest, &rest_len, "_") != ASC_RESULT_OK) {
+ log_error("Invalid configuration for component=[%.*s]: key=[%.*s]",
+ conf->component.length, conf->component.string, conf->key.length, conf->key.string);
+ all_pass = false;
+ continue;
+ }
+
+ id = components_manager_get_id_by_name(token, token_len);
+ if (id == 0) {
+ log_error("Invalid component=[%.*s]", (uint32_t)token_len, token);
+ all_pass = false;
+ continue;
+ }
+
+ if (str_ncmp("Level", str_len("Level"), rest, rest_len)) {
+ log_error("Invalid key=[%.*s]", (uint32_t)rest_len, rest);
+ all_pass = false;
+ continue;
+ }
+
+ if (!_conf_validate_level(conf)) {
+ all_pass = false;
+ continue;
+ }
+
+ if (validate_only) {
+ continue;
+ }
+
+ if (!all_pass) {
+ /* Shouldn't happen (it should fail on validation step) */
+ log_error("Can't apply new log configuration - validation failed");
+ continue;
+ }
+
+ code = string2code(_log_levels, conf->value.value.string.string, conf->value.value.string.length);
+ components_manager_set_log_level(id, code);
+ }
+
+ return all_pass ? ASC_RESULT_OK : ASC_RESULT_BAD_ARGUMENT;
+}
+
+static asc_result_t _conf_validate(linked_list_t *conf_list, conf_origin_t origin)
+{
+ return _conf_validate_or_apply(conf_list, origin, true);
}
-void logger_log(const char *level, const char *filename, const char *func, int line, const char *fmt, ...)
+static asc_result_t _conf_apply(linked_list_t *conf_list, conf_origin_t origin)
{
- printf(MDC_FORMAT , level, filename, func, line);
+ return _conf_validate_or_apply(conf_list, origin, false);
+}
+#endif
+
+static asc_result_t _cm_deinit(component_id_t id)
+{
+ return ASC_RESULT_OK;
+}
+
+static asc_result_t _cm_subscribe(component_id_t id)
+{
+#ifdef ASC_COMPONENT_CONFIGURATION
+ return configuration_component_register(components_manager_get_name(id), _conf_validate, _conf_apply);
+#else
+ return ASC_RESULT_OK;
+#endif
+}
+
+static asc_result_t _cm_unsubscribe(component_id_t id)
+{
+#ifdef ASC_COMPONENT_CONFIGURATION
+ return configuration_component_unregister(components_manager_get_name(id));
+#else
+ return ASC_RESULT_OK;
+#endif
+}
+
+static component_ops_t _ops = {
+ .init = _cm_init,
+ .deinit = _cm_deinit,
+ .subscribe = _cm_subscribe,
+ .unsubscribe = _cm_unsubscribe,
+};
+
+COMPONENTS_FACTORY_DEFINITION(Logger, &_ops)
+
+bool logger_set_system_log_level(int set)
+{
+ unsigned int level = (set < 0) ? ASC_LOG_LEVEL : (unsigned int)set;
+
+ if (level > ASC_LOG_LEVEL) {
+ log_error("Requested log level=[%u] is above than compiled=[%u]", level, ASC_LOG_LEVEL);
+ return false;
+ }
+ _system_level = level;
+ return true;
+}
+
+int logger_get_system_log_level(void)
+{
+ return (int)_system_level;
+}
+
+void logger_set_timestamp(bool set)
+{
+ _timestamp = set;
+}
+
+bool logger_log(component_id_t id, unsigned int level, const char *filename, const char *func, int line, const char *fmt, ...)
+{
+#define MDC_FORMAT "%s [%s/%s:%d] "
+#define MDC_TS_FORMAT "%s %lu - [%s/%s:%d] "
+#ifdef ASC_TIME_H_SUPPORT
+ #define MDC_TS_TIME_H_FORMAT "%s %02d:%02d:%02d [%s/%s:%d] "
+#endif
+ const char *level_str = NULL;
+
+ if (_system_level < level
+#ifdef ASC_COMPONENT_CONFIGURATION
+ || components_manager_get_log_level(id) < level
+#endif
+ )
+ {
+ return false;
+ }
+
+ level_str = code2string(_log_levels, (int)level);
+ if (level_str == NULL) {
+ level_str = "UNDEF";
+ }
+
+ if (_timestamp) {
+ unsigned long rawtime = itime_time(NULL);
+#ifdef ASC_TIME_H_SUPPORT
+ struct tm *ptm = localtime((time_t *)&rawtime);
+ if (ptm == NULL) {
+ printf(MDC_TS_FORMAT, level_str, rawtime, filename, func, line);
+ } else {
+ printf(MDC_TS_TIME_H_FORMAT, level_str, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, filename, func, line);
+ }
+#else
+ printf(MDC_TS_FORMAT, level_str, rawtime, filename, func, line);
+#endif
+ } else {
+ printf(MDC_FORMAT, level_str, filename, func, line);
+ }
va_list args;
va_start(args, fmt);
@@ -35,5 +262,8 @@ void logger_log(const char *level, const char *filename, const char *func, int l
va_end(args);
printf("\n");
+ return true;
}
+#else
+COMPONENTS_FACTORY_DEFINITION(Logger, NULL)
#endif
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/model/collector.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/model/collector.c
index 328b1628..29cc2646 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/model/collector.c
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/model/collector.c
@@ -1,86 +1,132 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
-
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#include
#include
+#include
+
+#include "asc_security_core/utils/itime.h"
#include "asc_security_core/logger.h"
+#include "asc_security_core/components_manager.h"
+#include "asc_security_core/core.h"
+#include "asc_security_core/utils/notifier.h"
+
#include "asc_security_core/collector.h"
OBJECT_POOL_DEFINITIONS(collector_t, COLLECTOR_OBJECT_POOL_COUNT)
-LINKED_LIST_DEFINITIONS(collector_t)
-collector_t *collector_init(collector_init_function_t collector_internal_init_function)
+static collector_t *collector_alloc(component_id_t id)
{
- asc_result_t result = ASC_RESULT_OK;
- collector_t *collector_ptr = NULL;
+ collector_t *collector_ptr = object_pool_get(collector_t);
- if (collector_internal_init_function == NULL) {
- log_error("Failed to initialize collector due to bad argument");
- result = ASC_RESULT_BAD_ARGUMENT;
+ __components_manager_set_ctx(id, collector_ptr);
+ if (collector_ptr == NULL) {
+ log_error("Failed to allocate collector=[%s]", components_manager_get_name(id));
goto cleanup;
}
+ memset(collector_ptr, 0, sizeof(collector_t));
+
+cleanup:
+ return collector_ptr;
+}
+
+static asc_result_t collector_init_with_params(collector_internal_t *collector_internal_ptr, collector_enum_t type, collector_priority_t priority, collector_serialize_function_t collect_function, unsigned long interval, void *state)
+{
+ if (collector_internal_ptr == NULL) {
+ return ASC_RESULT_BAD_ARGUMENT;
+ }
+
+ memset(collector_internal_ptr, 0, sizeof(*collector_internal_ptr));
+
+ collector_internal_ptr->type = type;
+ collector_internal_ptr->priority = priority;
+ collector_internal_ptr->interval = interval;
+ collector_internal_ptr->collect_function = collect_function;
+ collector_internal_ptr->state = state;
+
+ return ASC_RESULT_OK;
+}
+
+asc_result_t collector_default_create(component_id_t id, collector_enum_t type, collector_priority_t priority, collector_serialize_function_t collect_function, unsigned long interval, void *state)
+{
+ asc_result_t result = ASC_RESULT_OK;
+ collector_t *collector_ptr = collector_alloc(id);
- collector_ptr = object_pool_get(collector_t);
if (collector_ptr == NULL) {
- log_error("Failed to allocate collector");
+ log_error("Failed to init collector type=[%d] name=[%s]", type, components_manager_get_name(id));
result = ASC_RESULT_MEMORY_EXCEPTION;
goto cleanup;
}
-
- memset(collector_ptr, 0, sizeof(collector_t));
-
- result = collector_internal_init_function(&collector_ptr->internal);
+ result = collector_init_with_params(&collector_ptr->internal, type, priority, collect_function, interval, state);
if (result != ASC_RESULT_OK) {
- log_error("Failed to initialize collector internal, result=[%d]", result);
+ log_error("Failed to init internal collector parameters type=[%d] name=[%s]", type, components_manager_get_name(id));
goto cleanup;
}
+#ifdef ASC_COLLECTORS_INFO_SUPPORT
+ notifier_notify(NOTIFY_TOPIC_SYSTEM, NOTIFY_SYSTEM_CONFIGURATION, &collector_ptr->internal);
+#endif
- log_debug("Initialize collector, type=[%d], priority=[%d]", collector_ptr->internal.type, collector_ptr->internal.priority);
+cleanup:
+ return result;
+}
- // default parameters
- collector_ptr->enabled = true;
- collector_ptr->status = COLLECTOR_STATUS_OK;
- collector_ptr->failure_count = 0;
- collector_ptr->last_collected_timestamp = 0;
- collector_ptr->last_sent_timestamp = 0;
+asc_result_t collector_default_deinit(component_id_t id)
+{
+ collector_t *collector_ptr = __components_manager_get_ctx(id);
-cleanup:
- if (result != ASC_RESULT_OK) {
- log_error("Failed to initialize collector, result=[%d]", result);
- collector_deinit(collector_ptr);
- collector_ptr = NULL;
+ if (collector_ptr == NULL) {
+ log_error("collector uninitialized name=[%s]", components_manager_get_name(id));
+ return ASC_RESULT_MEMORY_EXCEPTION;
}
-
- return collector_ptr;
+ memset(collector_ptr, 0, sizeof(collector_t));
+ object_pool_free(collector_t, collector_ptr);
+ __components_manager_set_ctx(id, NULL);
+ return ASC_RESULT_OK;
}
-void collector_deinit(collector_t *collector_ptr)
+asc_result_t collector_default_subscribe(component_id_t id)
{
+ collector_t *collector_ptr = __components_manager_get_ctx(id);
+
if (collector_ptr == NULL) {
- return;
+ log_error("collector uninitialized name=[%s]", components_manager_get_name(id));
+ return ASC_RESULT_MEMORY_EXCEPTION;
}
- log_debug("Deinitialize collector, type=[%d], priority=[%d]", collector_ptr->internal.type, collector_ptr->internal.priority);
+ return core_collector_register(collector_ptr);
+}
- if (collector_ptr->internal.deinit_function != NULL) {
- collector_ptr->internal.deinit_function(&collector_ptr->internal);
+asc_result_t collector_default_unsubscribe(component_id_t id)
+{
+ collector_t *collector_ptr = __components_manager_get_ctx(id);
+
+ if (collector_ptr == NULL) {
+ log_error("collector uninitialized name=[%s]", components_manager_get_name(id));
+ return ASC_RESULT_MEMORY_EXCEPTION;
}
+ return core_collector_unregister(collector_ptr);
+}
- object_pool_free(collector_t, collector_ptr);
- collector_ptr = NULL;
+asc_result_t collector_default_start(component_id_t id)
+{
+ return ASC_RESULT_OK;
+}
+
+asc_result_t collector_default_stop(component_id_t id)
+{
+ return ASC_RESULT_OK;
}
collector_priority_t collector_get_priority(collector_t *collector_ptr)
{
- collector_priority_t priority = COLLECTOR_PRIORITY_HIGH;
+ collector_priority_t priority = COLLECTOR_PRIORITY_COUNT;
if (collector_ptr == NULL) {
log_error("Failed to retrieve collector priority, bad argument");
@@ -91,9 +137,9 @@ collector_priority_t collector_get_priority(collector_t *collector_ptr)
return priority;
}
-uint32_t collector_get_last_collected_timestamp(collector_t *collector_ptr)
+unsigned long collector_get_last_collected_timestamp(collector_t *collector_ptr)
{
- uint32_t last_collected_timestamp = 0;
+ unsigned long last_collected_timestamp = 0;
if (collector_ptr == NULL) {
log_error("Failed to retrieve collector last collected timestamp, bad argument");
@@ -104,7 +150,7 @@ uint32_t collector_get_last_collected_timestamp(collector_t *collector_ptr)
return last_collected_timestamp;
}
-asc_result_t collector_set_last_collected_timestamp(collector_t *collector_ptr, uint32_t last_collected_timestamp)
+asc_result_t collector_set_last_collected_timestamp(collector_t *collector_ptr, unsigned long last_collected_timestamp)
{
if (collector_ptr == NULL) {
log_error("Failed to set collector last collected timestamp, bad argument");
@@ -122,8 +168,13 @@ asc_result_t collector_serialize_events(collector_t *collector_ptr, serializer_t
log_error("Collector failed to serialize events, bad argument");
return ASC_RESULT_BAD_ARGUMENT;
}
+ unsigned long now = itime_time(NULL);
+ if (now == ITIME_FAILED) {
+ log_error("Error get current time");
+ now = 0;
+ }
- collector_ptr->last_collected_timestamp = itime_time(NULL);
+ collector_ptr->last_collected_timestamp = now;
if (collector_ptr->internal.collect_function == NULL) {
log_error("Collector failed to serialize events, internal collect function is NULL");
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/model/security_message.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/model/security_message.c
index a1c086f6..880bf5d4 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/model/security_message.c
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/model/security_message.c
@@ -1,7 +1,19 @@
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#include
#include
#include
+#include
+
#include "asc_security_core/model/security_message.h"
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/object_pool_static.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/object_pool_static.c
new file mode 100644
index 00000000..6f886aac
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/object_pool_static.c
@@ -0,0 +1,71 @@
+
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
+#include
+#include
+
+#include
+
+#include "asc_security_core/logger.h"
+#include "asc_security_core/object_pool_static.h"
+
+static bool _object_pool_init(object_pool_t *pool, uintptr_t offset1, uintptr_t offset2, uintptr_t objs)
+{
+ if (!pool || pool->size == 0) {
+ log_fatal("Wrong definition pool=[%p] size=[%zu]", (void *)pool, pool ? pool->size : 0);
+ return false;
+ }
+ if (!pool->initialized) {
+ if (offset1 != offset2) {
+ log_fatal("Wrong offset of pool typedef, COLLECTION_INTERFACE(...) is not on top.");
+ return false;
+ }
+ for (size_t i=0; isize; i++) {
+ uintptr_t obj = objs + (i * pool->item_size);
+ stack_push(&pool->stack, (collection_item_t *)obj);
+ }
+ pool->initialized = true;
+ }
+ return true;
+}
+
+void *__object_pool_get(object_pool_t *pool, uintptr_t offset1, uintptr_t offset2, uintptr_t objs)
+{
+ if (!_object_pool_init(pool, offset1, offset2, objs)) {
+ return NULL;
+ }
+ if (pool->current_size >= pool->size) {
+ if (++pool->failures % pool->size == 0) {
+ log_debug("Pool exceeded objects [%zu/%zu] failures=[%zu]", pool->current_size, pool->size, pool->failures);
+ }
+ return NULL;
+ }
+ pool->current_size++;
+ return (void *)stack_pop(&pool->stack);
+}
+
+void __object_pool_free(object_pool_t *pool, void *obj)
+{
+ if (!pool || !obj || !pool->initialized) {
+ return;
+ }
+ if (pool->current_size == 0) {
+ log_fatal("Invalid memory free");
+ } else {
+ pool->current_size--;
+ stack_push(&pool->stack, (collection_item_t *)obj);
+ }
+}
+
+size_t __object_pool_get_available_size(object_pool_t *pool)
+{
+ return (pool->size - pool->current_size);
+}
\ No newline at end of file
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/extensions/custom_builder_allocator.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/extensions/custom_builder_allocator.c
index 239629cc..a5f8c83f 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/extensions/custom_builder_allocator.c
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/extensions/custom_builder_allocator.c
@@ -1,19 +1,20 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
-
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#include
+#include
+
#include "asc_security_core/logger.h"
-#include "custom_builder_allocator.h"
+#include "asc_security_core/serializer/custom_builder_allocator.h"
#define VS_SIZE 64
#define DS_SIZE 512
@@ -67,7 +68,7 @@ int serializer_custom_allocator(void *alloc_context, flatcc_iovec_t *b, size_t r
return 0;
}
-void serializer_custom_allocator_reset()
+void serializer_custom_allocator_reset(void)
{
for (int i = 0; i < FLATCC_BUILDER_ALLOC_BUFFER_COUNT; ++i) {
if (buffers[i].iov_base != NULL) {
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/extensions/page_allocator.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/extensions/page_allocator.c
index 71bc2f3f..08676034 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/extensions/page_allocator.c
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/extensions/page_allocator.c
@@ -1,17 +1,17 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
-
-#include "page_allocator.h"
-
-#include "asc_security_core/configuration.h"
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
+#include
+
+#include "asc_security_core/serializer/page_allocator.h"
+
#include "asc_security_core/logger.h"
#include "asc_security_core/object_pool.h"
#include "asc_security_core/utils/collection/collection.h"
@@ -21,12 +21,13 @@
typedef struct emitter_page emitter_page_t;
struct emitter_page {
+ /* This macro must be first in object */
COLLECTION_INTERFACE(emitter_page_t);
flatcc_emitter_page_t page;
};
OBJECT_POOL_DECLARATIONS(emitter_page_t)
-OBJECT_POOL_DEFINITIONS(emitter_page_t, EMITTER_PAGE_CACHE_SIZE)
+OBJECT_POOL_DEFINITIONS(emitter_page_t, ASC_EMITTER_PAGE_CACHE_SIZE)
void *serializer_page_alloc(size_t size)
{
@@ -35,7 +36,7 @@ void *serializer_page_alloc(size_t size)
return NULL;
}
- emitter_page_t *page = object_pool_emitter_page_t_get();
+ emitter_page_t *page = object_pool_get(emitter_page_t);
if (page != NULL) {
static flatcc_emitter_page_t *temp;
temp = &(page->page);
@@ -55,5 +56,5 @@ void serializer_page_free(void *page)
}
emitter_page_t *page_ptr = containerof(page, emitter_page_t, page);
- object_pool_emitter_page_t_free(page_ptr);
+ object_pool_free(emitter_page_t, page_ptr);
}
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/extensions/page_allocator.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/extensions/page_allocator.h
deleted file mode 100644
index 63bdc189..00000000
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/extensions/page_allocator.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
-
-#ifndef PAGE_ALLOCATOR_H
-#define PAGE_ALLOCATOR_H
-
-#include
-
-#include "asc_security_core/configuration.h"
-
-#define MAX_MESSAGE_SIZE (500 + \
- ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV4_OBJECTS_IN_CACHE * 36 + \
- ASC_COLLECTOR_NETWORK_ACTIVITY_MAX_IPV6_OBJECTS_IN_CACHE * 60)
-
-#define MIN_PAGE_SIZE (MAX_MESSAGE_SIZE * 2)
-#define PAGE_MULTIPLE 64
-#define FLATCC_EMITTER_PAGE_SIZE ((MIN_PAGE_SIZE + (PAGE_MULTIPLE) - 1) & ~(2 * (PAGE_MULTIPLE) - 1))
-
-void *serializer_page_alloc(size_t size);
-void serializer_page_free(void *page);
-
-#endif /* PAGE_ALLOCATOR_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/heartbeat.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/heartbeat.c
index 0c7070b1..c11c99d9 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/heartbeat.c
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/heartbeat.c
@@ -1,13 +1,14 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
+#include
#include "asc_security_core/logger.h"
#include "asc_security_core/model/schema/message_builder.h"
@@ -15,9 +16,9 @@
#include "asc_security_core/serializer.h"
#include "serializer_private.h"
-asc_result_t serializer_event_add_heartbeat(serializer_t *serializer, uint32_t timestamp, uint32_t collection_interval)
+asc_result_t serializer_event_add_heartbeat(serializer_t *serializer, unsigned long timestamp, unsigned long collection_interval)
{
- log_debug("serializer_event_add_heartbeat, serializer=[%p], timestamp=[%u], collection_interval=[%u]",
+ log_debug("serializer_event_add_heartbeat, serializer=[%p], timestamp=[%lu], collection_interval=[%lu]",
(void*)serializer, timestamp, collection_interval);
if (serializer == NULL) {
@@ -40,7 +41,7 @@ asc_result_t serializer_event_add_heartbeat(serializer_t *serializer, uint32_t t
return ASC_RESULT_EXCEPTION;
}
- if (AzureIoTSecurity_Message_events_push_end(&serializer->builder) == NULL) {
+ if (AzureIoTSecurity_Event_vec_push_end(&serializer->builder) == NULL) {
log_error("failed in AzureIoTSecurity_Event_vec_push_end");
serializer->state = SERIALIZER_STATE_EXCEPTION;
return ASC_RESULT_EXCEPTION;
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/network_activity.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/network_activity.c
index f249585c..33252780 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/network_activity.c
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/network_activity.c
@@ -1,15 +1,15 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
-
-#include "asc_security_core/configuration.h"
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
+#include
+
#include "asc_security_core/logger.h"
#include "asc_security_core/model/schema/event_builder.h"
#include "asc_security_core/serializer.h"
@@ -24,10 +24,10 @@ static asc_result_t _serializer_network_activity_add_ipv4_activity(serializer_t
static asc_result_t _serializer_network_activity_add_ipv6_activity(serializer_t *serializer, network_activity_ipv6_t *ipv6_payload);
static asc_result_t _serializer_network_activity_add_common(serializer_t *serializer, network_activity_common_t *common);
-asc_result_t serializer_event_add_network_activity(serializer_t *serializer, uint32_t timestamp, uint32_t collection_interval,
+asc_result_t serializer_event_add_network_activity(serializer_t *serializer, unsigned long timestamp, unsigned long collection_interval,
network_activity_ipv4_t *ipv4_payload, network_activity_ipv6_t *ipv6_payload)
{
- log_debug("serializer_event_add_network_activity, serializer=[%p], timestamp=[%u], collection_interval=[%u], ipv4_payload=[%p], ipv6_payload=[%p]",
+ log_debug("serializer_event_add_network_activity, serializer=[%p], timestamp=[%lu], collection_interval=[%lu], ipv4_payload=[%p], ipv6_payload=[%p]",
(void*)serializer, timestamp, collection_interval, (void*)ipv4_payload, (void*)ipv6_payload);
#ifndef ASC_COLLECTOR_NETWORK_ACTIVITY_SEND_EMPTY_EVENTS
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/protocol_serialize_enum.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/protocol_serialize_enum.h
index 069491e0..bedf4486 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/protocol_serialize_enum.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/protocol_serialize_enum.h
@@ -1,16 +1,17 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef PROTOCOL_PRIVATE_H
#define PROTOCOL_PRIVATE_H
+#include
#include "asc_security_core/model/objects/transport_protocol.h"
#include "asc_security_core/model/schema/protocol_builder.h"
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/serializer.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/serializer.c
index bfca583a..9b664d2d 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/serializer.c
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/serializer.c
@@ -1,19 +1,19 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
-
-#include "asc_security_core/configuration.h"
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
+#include
+
#include "asc_security_core/logger.h"
#include "asc_security_core/model/schema/message_builder.h"
#include "asc_security_core/object_pool.h"
-#include "asc_security_core/utils/iuuid.h"
+#include "asc_security_core/utils/uuid.h"
#include "asc_security_core/serializer.h"
#include "serializer_private.h"
@@ -22,13 +22,13 @@ OBJECT_POOL_DECLARATIONS(serializer_t)
OBJECT_POOL_DEFINITIONS(serializer_t, 1)
#ifdef ASC_SERIALIZER_USE_CUSTOM_ALLOCATOR
-#include "extensions/custom_builder_allocator.h"
+#include "asc_security_core/serializer/custom_builder_allocator.h"
#define ASC_SERIALIZER_CUSTOM_ALLOCATOR serializer_custom_allocator
#else
#define ASC_SERIALIZER_CUSTOM_ALLOCATOR NULL
#endif
-serializer_t *serializer_init()
+serializer_t *serializer_init(void)
{
log_debug("serializer_init");
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/serializer_private.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/serializer_private.c
index fa80eb96..3d5ee06a 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/serializer_private.c
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/serializer_private.c
@@ -1,23 +1,24 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
-
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#include
+#include
+
#include "asc_security_core/logger.h"
#include "asc_security_core/model/schema/message_builder.h"
-#include "asc_security_core/utils/iuuid.h"
+#include "asc_security_core/utils/uuid.h"
#include "serializer_private.h"
-asc_result_t serializer_event_start(serializer_t *serializer, uint32_t timestamp, uint32_t collection_interval)
+asc_result_t serializer_event_start(serializer_t *serializer, unsigned long timestamp, unsigned long collection_interval)
{
if (serializer->state == SERIALIZER_STATE_MESSAGE_EMPTY && flatbuffers_failed(AzureIoTSecurity_Message_events_start(&serializer->builder))) {
log_error("failed in AzureIoTSecurity_Message_events_start");
@@ -32,8 +33,8 @@ asc_result_t serializer_event_start(serializer_t *serializer, uint32_t timestamp
}
uint8_t uuid[16] = { 0 };
- if (iuuid_generate(uuid) < 0) {
- log_error("failed in iuuid_generate");
+ if (uuid_generate(uuid) < 0) {
+ log_error("failed in uuid_generate");
serializer->state = SERIALIZER_STATE_EXCEPTION;
return ASC_RESULT_EXCEPTION;
}
@@ -45,13 +46,13 @@ asc_result_t serializer_event_start(serializer_t *serializer, uint32_t timestamp
}
- if (flatbuffers_failed(AzureIoTSecurity_Event_time_add(&serializer->builder, timestamp))) {
+ if (flatbuffers_failed(AzureIoTSecurity_Event_time_add(&serializer->builder, (uint32_t)timestamp))) {
log_error("failed in AzureIoTSecurity_Event_time_add");
serializer->state = SERIALIZER_STATE_EXCEPTION;
return ASC_RESULT_EXCEPTION;
}
- if (flatbuffers_failed(AzureIoTSecurity_Event_collection_interval_add(&serializer->builder, collection_interval))) {
+ if (flatbuffers_failed(AzureIoTSecurity_Event_collection_interval_add(&serializer->builder, (uint32_t)collection_interval))) {
log_error("failed in AzureIoTSecurity_Event_collection_interval_add");
serializer->state = SERIALIZER_STATE_EXCEPTION;
return ASC_RESULT_EXCEPTION;
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/serializer_private.h b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/serializer_private.h
index ed734aa6..2915c008 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/serializer_private.h
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/serializer_private.h
@@ -1,13 +1,13 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
#ifndef SERIALIZER_PRIVATE_H
#define SERIALIZER_PRIVATE_H
@@ -15,12 +15,15 @@
#include
#include
+#include
+
#include "flatcc/flatcc_builder.h"
#include "asc_security_core/utils/collection/collection.h"
#include "asc_security_core/serializer.h"
struct serializer {
+ /* This macro must be first in object */
COLLECTION_INTERFACE(serializer_t);
flatcc_builder_t builder;
@@ -40,6 +43,6 @@ struct serializer {
* @return ASC_RESULT_OK on success,
* ASC_RESULT_EXCEPTION otherwise
*/
-asc_result_t serializer_event_start(serializer_t *serializer, uint32_t timestamp, uint32_t collection_interval);
+asc_result_t serializer_event_start(serializer_t *serializer, unsigned long timestamp, unsigned long collection_interval);
#endif /* SERIALIZER_PRIVATE_H */
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/system_information.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/system_information.c
index 40d2c750..5fa324ab 100644
--- a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/system_information.c
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/serializer/system_information.c
@@ -1,13 +1,14 @@
-/**************************************************************************/
-/* */
-/* Copyright (c) Microsoft Corporation. All rights reserved. */
-/* */
-/* This software is licensed under the Microsoft Software License */
-/* Terms for Microsoft Azure RTOS. Full text of the license can be */
-/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
-/* and in the root directory of this software. */
-/* */
-/**************************************************************************/
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
+#include
#include "asc_security_core/logger.h"
#include "asc_security_core/model/schema/event_builder.h"
@@ -15,10 +16,10 @@
#include "asc_security_core/serializer.h"
#include "serializer_private.h"
-asc_result_t serializer_event_add_system_information(serializer_t *serializer, uint32_t timestamp, uint32_t collection_interval,
+asc_result_t serializer_event_add_system_information(serializer_t *serializer, unsigned long timestamp, unsigned long collection_interval,
system_information_t *payload)
{
- log_debug("serializer_event_add_system_information, serializer=[%p], timestamp=[%u], collection_interval=[%u], payload=[%p]",
+ log_debug("serializer_event_add_system_information, serializer=[%p], timestamp=[%lu], collection_interval=[%lu], payload=[%p]",
(void*)serializer, timestamp, collection_interval, (void*)payload);
if (serializer == NULL) {
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/utils/collection/bit_vector.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/utils/collection/bit_vector.c
new file mode 100644
index 00000000..ed9cbdcb
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/utils/collection/bit_vector.c
@@ -0,0 +1,54 @@
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
+#include
+#include
+
+#include
+
+#include "asc_security_core/utils/collection/bit_vector.h"
+
+bool __bit_vector_set(char bit_vector[], int index, bool bit, int size)
+{
+ if (index >= 0 && index < size) {
+ if (bit) {
+ bit_vector[__BV_VEC_IND(index)] |= (char)(0x01 << __BV_VEC_SHIFT(index));
+ } else {
+ bit_vector[__BV_VEC_IND(index)] &= (char)~(0x01 << __BV_VEC_SHIFT(index));
+ }
+ return true;
+ }
+ return false;
+}
+
+bool __bit_vector_get(char bit_vector[], int index, int size)
+{
+ if (index >= 0 && index < size) {
+ return (!!(bit_vector[__BV_VEC_IND(index)] & (0x01 << __BV_VEC_SHIFT(index))));
+ }
+ return false;
+}
+
+bool __is_bit_vector_zero(char bit_vector[], int size)
+{
+ int vector_size_in_bytes = size>>3;
+
+ for(int i = 0; i < vector_size_in_bytes; i++) {
+ if (bit_vector[i] != 0x00) {
+ return false;
+ }
+ }
+ return true;
+}
+
+void __bit_vector_clean(char bit_vector[], int size)
+{
+ memset(bit_vector, 0, (size_t)size>>3);
+}
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/utils/collection/hashtable.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/utils/collection/hashtable.c
new file mode 100644
index 00000000..2bf330b8
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/utils/collection/hashtable.c
@@ -0,0 +1,229 @@
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
+#include
+
+#include
+
+#include
+#include
+#include
+
+static unsigned int _hash_calc(hashtable_t *hashtable, const void *key);
+static void *_hashtable_find(hashtable_t *hashtable, const void *key, unsigned int *index);
+
+// API functions
+bool hashtable_init(hashtable_t *hashtable, size_t size, hash_func_t hash_func,
+ hash_equal_func_t hash_equal_func, hash_update_func_t hash_update_func)
+{
+ if (!hashtable || !size) {
+ log_error("Wrong hashtable init parametrs");
+ return false;
+ }
+ hashtable->ctrl.size = size;
+ hashtable->ctrl.hash_func = hash_func;
+ hashtable->ctrl.hash_equal_func = hash_equal_func ? hash_equal_func : hashtable_equal_default_func;
+ hashtable->ctrl.hash_update_func = hash_update_func ? hash_update_func : hashtable_update_none_func;
+ memset(hashtable->table, 0, size * sizeof(void *));
+ hashtable->ctrl.initialized = true;
+ return true;
+}
+
+void *hashtable_insert(hashtable_t *hashtable, const void *key, void *item)
+{
+ if (!hashtable || !hashtable->ctrl.initialized || !key || !item) {
+ log_error("Wrong parametrs");
+ return NULL;
+ }
+ collection_item_t *element = item;
+ unsigned int index = 0;
+ collection_item_t *existing_element = _hashtable_find(hashtable, key, &index);
+
+ if (existing_element == NULL) {
+ collection_item_t *column = hashtable->table[index];
+ element->previous = NULL;
+ element->next = column;
+ if (column != NULL) {
+ column->previous = element;
+ }
+ hashtable->table[index] = element;
+ } else {
+ hashtable->ctrl.hash_update_func(existing_element, element);
+ }
+ return item;
+}
+
+void *hashtable_remove(hashtable_t *hashtable, const void *key, hash_free_func_t hash_free_func)
+{
+ if (!hashtable || !hashtable->ctrl.initialized || !key) {
+ log_error("Wrong parametrs");
+ return NULL;
+ }
+ unsigned int index = 0;
+ collection_item_t *existing_element = _hashtable_find(hashtable, key, &index);
+
+ if (existing_element == NULL) {
+ return NULL;
+ }
+ collection_item_t *previous_element = existing_element->previous;
+ collection_item_t *next_element = existing_element->next;
+
+ if (next_element != NULL) {
+ next_element->previous = previous_element;
+ }
+ if (previous_element == NULL) {
+ hashtable->table[index] = next_element;
+ } else {
+ previous_element->next = next_element;
+ }
+ if (hash_free_func) {
+ hash_free_func(existing_element);
+ return NULL;
+ }
+ return existing_element;
+}
+
+void *hashtable_find(hashtable_t *hashtable, const void *key)
+{
+ if (!hashtable || !hashtable->ctrl.initialized || !key) {
+ log_error("Wrong parametrs");
+ return NULL;
+ }
+ unsigned int index;
+ return _hashtable_find(hashtable, key, &index);
+}
+
+size_t hashtable_get_depth(hashtable_t *hashtable, size_t *count)
+{
+ size_t max = 0;
+ if (count) {
+ *count = 0;
+ }
+ if (!hashtable || !hashtable->ctrl.initialized) {
+ return 0;
+ }
+ for (size_t i = 0; i < hashtable->ctrl.size; i++) {
+ collection_item_t *current_element = NULL;
+ size_t cnt = 0;
+ hashtable_column_foreach(hashtable, current_element, i) {
+ cnt++;
+ }
+ if (cnt > 1) {
+ if (cnt > max) {
+ max = cnt;
+ }
+ if (count) {
+ (*count)++;
+ }
+ }
+ }
+ return max;
+}
+
+void hashtable_foreach(hashtable_t *hashtable, hash_action_func_t hash_action_func, void *ctx)
+{
+ if (!hashtable || !hashtable->ctrl.initialized || !hash_action_func) {
+ return;
+ }
+ for (unsigned int i = 0; i < hashtable->ctrl.size; i++) {
+ // not using hashtable_column_foreach() because of 'tmp = current_element->next for safe action'
+ collection_item_t *current_element = hashtable->table[i]; // get column head
+ while (current_element != NULL) {
+ collection_item_t *tmp = current_element->next;
+ hash_action_func(current_element, ctx);
+ current_element = tmp;
+ }
+ }
+}
+
+void hashtable_flush(hashtable_t *hashtable, hash_free_func_t hash_free_func)
+{
+ if (!hashtable || !hashtable->ctrl.initialized) {
+ return;
+ }
+ if (!hash_free_func) {
+ goto cleanup;
+ }
+ for (size_t i = 0; i < hashtable->ctrl.size; i++) {
+ // not using hashtable_column_foreach() because of 'tmp = current_element->next for safe free'
+ collection_item_t *current_element = hashtable->table[i]; // get column head
+ while (current_element != NULL) {
+ collection_item_t *tmp = current_element->next;
+ hash_free_func(current_element);
+ current_element = tmp;
+ }
+ }
+cleanup:
+ memset(hashtable->table, 0, hashtable->ctrl.size * sizeof(void *));
+}
+
+bool hashtable_is_empty(hashtable_t *hashtable)
+{
+ if (!hashtable || !hashtable->ctrl.initialized) {
+ return true;
+ }
+ for (size_t i = 0; i < hashtable->ctrl.size; i++) {
+ collection_item_t *column = hashtable->table[i];
+ if (column) {
+ return false;
+ }
+ }
+ return true;
+}
+
+// Service callbacks and functions
+void hashtable_update_none_func(void *a, void *b)
+{
+ log_error("Should never happens");
+}
+
+bool hashtable_equal_default_func(const void *key, void *item)
+{
+ return (key == item);
+}
+
+unsigned int hashtable_hash_str_default(const void *key)
+{
+ const char *buffer = key;
+ return hashtable_buffer2hash(buffer, str_len(buffer));
+}
+
+unsigned int hashtable_buffer2hash(const char *buffer, size_t len)
+{
+ unsigned int hash = 5381;
+
+ for (size_t i = 0 ; i < len; i++) {
+ hash = ((hash << 5) + hash) + (unsigned int)buffer[i];
+ }
+
+ return hash;
+}
+
+// Internal functions
+static unsigned int _hash_calc(hashtable_t *hashtable, const void *key)
+{
+ return hashtable->ctrl.hash_func ? (unsigned int)(hashtable->ctrl.hash_func(key) % hashtable->ctrl.size) :
+ (unsigned int)((uintptr_t)key % hashtable->ctrl.size);
+}
+
+static void *_hashtable_find(hashtable_t *hashtable, const void *key, unsigned int *index)
+{
+ *index = _hash_calc(hashtable, key);
+ collection_item_t *current_element = NULL;
+
+ hashtable_column_foreach(hashtable, current_element, *index) {
+ if (hashtable->ctrl.hash_equal_func(key, current_element) != 0) {
+ break;
+ }
+ }
+
+ return current_element;
+}
+
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/utils/collection/list.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/utils/collection/list.c
new file mode 100644
index 00000000..0db4711c
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/utils/collection/list.c
@@ -0,0 +1,183 @@
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
+
+#include
+
+#include "asc_security_core/utils/collection/list.h"
+
+void linked_list_init(linked_list_t *list)
+{
+ if (list == NULL) {
+ return;
+ }
+ list->head = NULL;
+ list->tail = NULL;
+ list->size = 0;
+ list->initialized = true;
+}
+
+void *linked_list_get_first(linked_list_t *list)
+{
+ if (list == NULL) {
+ return NULL;
+ }
+ return list->head;
+}
+
+void *linked_list_find(linked_list_t *list, linked_list_condition_cb condition_function, void *condition_input)
+{
+ if (list == NULL || (condition_function) == NULL) {
+ return NULL;
+ }
+ collection_item_t *curr = NULL;
+ linked_list_foreach(list, curr) {
+ if (condition_function(curr, condition_input) == true) {
+ break;
+ }
+ }
+ return curr;
+}
+
+void *linked_list_add_or_update(linked_list_t *list, linked_list_condition_cb condition_function,
+ linked_list_update_cb update_func, void *data)
+{
+ if (list == NULL || (condition_function) == NULL || update_func == NULL) {
+ return NULL;
+ }
+ collection_item_t *curr = NULL;
+ linked_list_foreach(list, curr) {
+ if (condition_function(curr, data) == true) {
+ update_func(curr, data);
+ return curr;
+ }
+ }
+ return linked_list_add_last(list, data);
+}
+
+void *linked_list_add_last(linked_list_t *list, void *data)
+{
+ collection_item_t *item = data;
+ if (list == NULL || item == NULL) {
+ return NULL;
+ }
+ item->next = NULL;
+ if (list->head == NULL) {
+ item->previous = NULL;
+ list->head = item;
+ list->tail = item;
+ } else {
+ item->previous = list->tail;
+ list->tail->next = item;
+ list->tail = item;
+ }
+
+ list->size += 1;
+ return data;
+}
+
+void *linked_list_add_first(linked_list_t *list, void *data)
+{
+ collection_item_t *item = data;
+ if (list == NULL || item == NULL) {
+ return NULL;
+ }
+ item->previous = NULL;
+ item->next = NULL;
+ if (list->head == NULL) {
+ list->head = item;
+ list->tail = item;
+ } else {
+ list->head->previous = item;
+ item->next = list->head;
+ list->head = item;
+ }
+ list->size += 1;
+ return item;
+}
+
+void *linked_list_insert_before(linked_list_t *list, void *before, void *data)
+{
+ collection_item_t *item = data;
+ if (list == NULL || item == NULL) {
+ return NULL;
+ }
+ if (before == NULL) {
+ return linked_list_add_last(list, item);
+ }
+ collection_item_t *before_item = linked_list_find(list, linked_list_condition_default, before);
+ if (before_item == NULL) {
+ return linked_list_add_last(list, item);
+ }
+ collection_item_t *previous_item = before_item->previous;
+ if (previous_item == NULL) {
+ return linked_list_add_first(list, item);
+ }
+ item->next = before_item;
+ item->previous = previous_item;
+ previous_item->next = item;
+ before_item->previous = item;
+ list->size += 1;
+ return item;
+}
+
+void *linked_list_remove(linked_list_t *list, void *data, linked_list_free_cb free_function)
+{
+ collection_item_t *item = data;
+ if (list == NULL || item == NULL) {
+ return NULL;
+ }
+ if (linked_list_find(list, linked_list_condition_default, item) == NULL) {
+ return NULL;
+ }
+ collection_item_t *previous_item = item->previous;
+ collection_item_t *next_item = item->next;
+ if (next_item != NULL) {
+ next_item->previous = previous_item;
+ }
+ if (previous_item == NULL) {
+ list->head = next_item;
+ } else {
+ previous_item->next = next_item;
+ }
+ if (item == list->tail) {
+ list->tail = previous_item;
+ }
+ list->size -= 1;
+ if (free_function != NULL) {
+ free_function(item);
+ return NULL;
+ }
+ return item;
+}
+
+void linked_list_flush(linked_list_t *list, linked_list_free_cb free_function)
+{
+ if (list == NULL) {
+ return;
+ }
+ while (list->head != NULL) {
+ linked_list_remove(list, list->head, free_function);
+ }
+ linked_list_init(list);
+}
+
+size_t linked_list_get_size(linked_list_t *list)
+{
+ if (list == NULL) {
+ return 0;
+ }
+ return list->size;
+}
+
+bool linked_list_condition_default(void *item, void *condition_input)
+{
+ return (item==condition_input);
+}
diff --git a/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/utils/collection/stack.c b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/utils/collection/stack.c
new file mode 100644
index 00000000..d7b94015
--- /dev/null
+++ b/addons/azure_iot/azure_iot_security_module/iot-security-module-core/src/utils/collection/stack.c
@@ -0,0 +1,62 @@
+/*******************************************************************************/
+/* */
+/* Copyright (c) Microsoft Corporation. All rights reserved. */
+/* */
+/* This software is licensed under the Microsoft Software License */
+/* Terms for Microsoft Azure Defender for IoT. Full text of the license can be */
+/* found in the LICENSE file at https://aka.ms/AzureDefenderForIoT_EULA */
+/* and in the root directory of this software. */
+/* */
+/*******************************************************************************/
+#include
+#include