Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,43 @@
.venv
.cache

# CMake build files
build*/
CMakeCache.txt
CMakeFiles/
Makefile
cmake_install.cmake
install_manifest.txt
CTestTestfile.cmake
Testing/

# Coverage files
*.gcda
*.gcno
*.gcov
*.info
coverage_html/
coverage_report.md
coverage_summary.txt

# Generated files
*.a
*.so
*.dll
*.exe

# IDE files
.vscode/
.idea/
*.swp
*.swo
*~

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
84 changes: 84 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
cmake_minimum_required(VERSION 3.16)

project(EmbedIDS
VERSION 0.1.0
DESCRIPTION "Lightweight Runtime Intrusion Detection SDK for embedded IoT devices"
LANGUAGES C CXX
)

# Standards
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Options
option(BUILD_TESTS "Build unit tests" OFF)
option(BUILD_EXAMPLES "Build examples" OFF)
option(ENABLE_COVERAGE "Enable code coverage" OFF)

# Compiler flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Os -ffunction-sections -fdata-sections")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Os -ffunction-sections -fdata-sections")

# Coverage configuration
if(ENABLE_COVERAGE AND CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
include(CTest)
message(STATUS "Enabling code coverage with ${CMAKE_C_COMPILER_ID}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g --coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g --coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
elseif(ENABLE_COVERAGE)
message(WARNING "Coverage only supported with GCC or Clang")
endif()

# Configure main header with version info
configure_file(include/embedids.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/embedids.h @ONLY)

# Include directories
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)

# Build targets
add_subdirectory(src)
add_library(EmbedIDS::embedids ALIAS embedids)

if(BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()

if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

# Installation
install(TARGETS embedids
ARCHIVE DESTINATION lib
PUBLIC_HEADER DESTINATION include
)

install(FILES
${CMAKE_CURRENT_BINARY_DIR}/include/embedids.h
DESTINATION include
)

# Package configuration
include(CMakePackageConfigHelpers)
write_basic_package_version_file("EmbedIDSConfigVersion.cmake"
VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion)
configure_package_config_file("cmake/EmbedIDSConfig.cmake.in" "EmbedIDSConfig.cmake"
INSTALL_DESTINATION lib/cmake/EmbedIDS)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/EmbedIDSConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/EmbedIDSConfigVersion.cmake"
DESTINATION lib/cmake/EmbedIDS)

# Coverage targets
if(ENABLE_COVERAGE AND BUILD_TESTS)
add_custom_target(coverage
COMMAND ${CMAKE_CTEST_COMMAND} -T Test -T Coverage --output-on-failure
DEPENDS embedids_tests
COMMENT "Running tests and generating coverage report"
)
message(STATUS "Coverage target added: make coverage")
endif()
166 changes: 165 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,166 @@
# EmbedIDS
Modern Intrusion Detection Systems (IDS) for Embedded Systems

> **Modern Intrusion Detection System for Embedded Devices & IoT**

EmbedIDS is a lightweight, extensible intrusion detection library designed for embedded systems and IoT devices. It features user-managed memory, custom metrics, and pluggable detection algorithms with zero runtime overhead when disabled.

## Quick Start

```c
#include <embedids.h>

// Allocate history buffer (user-managed memory)
static embedids_metric_datapoint_t cpu_history[50];

// Configure CPU monitoring with 80% threshold
embedids_metric_config_t cpu_config = {
.metric = {
.name = "cpu_usage",
.type = EMBEDIDS_METRIC_TYPE_PERCENTAGE,
.history = cpu_history,
.max_history_size = 50,
.enabled = true
},
.algorithms = {{
.type = EMBEDIDS_ALGORITHM_THRESHOLD,
.enabled = true,
.config.threshold = {
.max_threshold.f32 = 80.0f,
.check_max = true
}
}},
.num_algorithms = 1
};

// Initialize context and system
embedids_context_t context;
memset(&context, 0, sizeof(context));

embedids_system_config_t system = {
.metrics = &cpu_config,
.max_metrics = 1,
.num_active_metrics = 1
};

embedids_init(&context, &system);

// Monitor in real-time
embedids_metric_value_t value = {.f32 = get_cpu_usage()};
embedids_add_datapoint(&context, "cpu_usage", value, timestamp_ms);

if (embedids_analyze_metric(&context, "cpu_usage") != EMBEDIDS_OK) {
handle_intrusion_detected();
}
```

## Architecture & Features

### **Extensible Design**
- **User-Managed Memory**: No malloc/free - perfect for embedded systems
- **Custom Metrics**: Support for float, int, percentage, boolean, enum types
- **Pluggable Algorithms**: Threshold, trend analysis, statistical, and custom detection
- **Multiple Algorithms per Metric**: Run several detection methods simultaneously
- **Real-time Analysis**: Low-latency threat detection with configurable history

### **Detection Algorithms**
| Algorithm | Description | Use Case |
|-----------|-------------|----------|
| **Threshold** | Min/max boundary checking | CPU usage, memory limits |
| **Trend** | Slope-based anomaly detection | Memory leaks, performance degradation |
| **Statistical** | Advanced statistical analysis | Complex pattern detection |
| **Custom** | User-defined detection functions | Domain-specific threats |

### **Metric Types**
- `EMBEDIDS_METRIC_TYPE_PERCENTAGE` - CPU usage, memory utilization (0-100%)
- `EMBEDIDS_METRIC_TYPE_FLOAT` - Sensor readings, network traffic
- `EMBEDIDS_METRIC_TYPE_UINT32/64` - Packet counts, process counts
- `EMBEDIDS_METRIC_TYPE_BOOL` - System states, security flags
- `EMBEDIDS_METRIC_TYPE_ENUM` - Custom enumerated values

## Installation

### **CMake (Recommended)**
```bash
mkdir build && cd build
cmake .. -DBUILD_EXAMPLES=ON -DBUILD_TESTS=ON
make -j$(nproc)
sudo make install
```

### **Integration Options**
```cmake
# Option 1: Installed package
find_package(EmbedIDS REQUIRED)
target_link_libraries(your_app EmbedIDS::embedids)

# Option 2: FetchContent (Git repository)
include(FetchContent)
FetchContent_Declare(
EmbedIDS
GIT_REPOSITORY https://github.com/samiralavi/EmbedIDS.git
GIT_BRANCH main # Fetch the main branch
)
FetchContent_MakeAvailable(EmbedIDS)
target_link_libraries(your_app embedids)
```

### Build Options

- `BUILD_TESTS=ON/OFF` - Unit tests with GoogleTest (default: ON)
- `BUILD_EXAMPLES=ON/OFF` - Example applications (default: ON)
- `ENABLE_COVERAGE=ON/OFF` - Code coverage reporting (default: OFF)

## Testing & Coverage

### Running Unit Tests

There are multiple ways to run the test suites

#### Method 1: Using CTest (Recommended)
```bash
# Build the project first
mkdir build && cd build
cmake .. -DBUILD_TESTS=ON
make -j$(nproc)

# Run all tests
ctest

# Run tests with detailed output
ctest --verbose

# List available tests
ctest --list-tests
```

#### Method 2: Direct Test Execution
```bash
# After building, run tests directly
./tests/embedids_tests

# Run specific test patterns (GoogleTest)
./tests/embedids_tests --gtest_filter="*Threshold*"
```

#### Method 3: Using make (if available)
```bash
make test # May not be available in all configurations
```

### Code Coverage Analysis

Generate detailed coverage reports to see test effectiveness:

```bash
# Configure with coverage enabled
mkdir build && cd build
cmake .. -DBUILD_TESTS=ON -DENABLE_COVERAGE=ON
make -j$(nproc)

# Generate coverage report
make coverage
```

## License

Licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) file for details.
5 changes: 5 additions & 0 deletions cmake/EmbedIDSConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/EmbedIDSTargets.cmake")

check_required_components(EmbedIDS)
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
2 changes: 0 additions & 2 deletions docs/blogs/index.md

This file was deleted.

10 changes: 9 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ description: EmbedIDS is a lightweight Runtime Intrusion Detection SDK specifica
hide:
- toc
---

# EmbedIDS: Open Source Intrusion Detection System (IDS) for Embedded Systems

![EmbedIDS Logo](images/embedIDS_logo_text.png)
![EmbedIDS Logo](assets/images/embedIDS_logo_text.png)

**🚀 New to EmbedIDS?**
- **[Quick Start Guide](quickstart.md)** - Get running in 5 minutes
- **[Complete Tutorial](tutorial.md)** - Comprehensive learning guide
- **[Examples](https://github.com/samiralavi/EmbedIDS/tree/main/examples)** - Ready-to-run code samples

---

EmbedIDS is a lightweight Runtime Intrusion Detection SDK specifically designed for low-power embedded Internet of Things (IoT) devices. Our open-source SDK provides AI-driven protection to address the critical security gap in constrained IoT environments.

Expand Down
Loading