chore: import local project into Gitea
This commit is contained in:
37
include/README
Normal file
37
include/README
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
This directory is intended for project header files.
|
||||
|
||||
A header file is a file containing C declarations and macro definitions
|
||||
to be shared between several project source files. You request the use of a
|
||||
header file in your project source file (C, C++, etc) located in `src` folder
|
||||
by including it, with the C preprocessing directive `#include'.
|
||||
|
||||
```src/main.c
|
||||
|
||||
#include "header.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
Including a header file produces the same results as copying the header file
|
||||
into each source file that needs it. Such copying would be time-consuming
|
||||
and error-prone. With a header file, the related declarations appear
|
||||
in only one place. If they need to be changed, they can be changed in one
|
||||
place, and programs that include the header file will automatically use the
|
||||
new version when next recompiled. The header file eliminates the labor of
|
||||
finding and changing all the copies as well as the risk that a failure to
|
||||
find one copy will result in inconsistencies within a program.
|
||||
|
||||
In C, the convention is to give header files names that end with `.h'.
|
||||
|
||||
Read more about using header files in official GCC documentation:
|
||||
|
||||
* Include Syntax
|
||||
* Include Operation
|
||||
* Once-Only Headers
|
||||
* Computed Includes
|
||||
|
||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||
80
include/config_manager.h
Normal file
80
include/config_manager.h
Normal file
@@ -0,0 +1,80 @@
|
||||
#ifndef CONFIG_MANAGER_H
|
||||
#define CONFIG_MANAGER_H
|
||||
|
||||
#include "esp_err.h"
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// WiFi AP Configuration
|
||||
typedef struct {
|
||||
char ssid[32];
|
||||
char password[64];
|
||||
uint8_t channel;
|
||||
uint8_t max_connections;
|
||||
char ip[16];
|
||||
char gateway[16];
|
||||
char netmask[16];
|
||||
} custom_wifi_ap_config_t;
|
||||
|
||||
// Ethernet Configuration
|
||||
typedef struct {
|
||||
bool dhcp_enabled;
|
||||
char static_ip[16];
|
||||
char gateway[16];
|
||||
char netmask[16];
|
||||
char dns[16];
|
||||
} ethernet_config_t;
|
||||
|
||||
// Web Server Configuration
|
||||
typedef struct {
|
||||
uint16_t port;
|
||||
bool auth_enabled;
|
||||
char username[32];
|
||||
char password[64];
|
||||
} web_server_config_t;
|
||||
|
||||
// Scanner Configuration
|
||||
typedef struct {
|
||||
uint32_t arp_timeout_ms;
|
||||
uint32_t ping_timeout_ms;
|
||||
uint32_t port_scan_timeout_ms;
|
||||
uint16_t max_ports_per_scan;
|
||||
uint32_t scan_interval_ms;
|
||||
} scanner_config_t;
|
||||
|
||||
// Main Configuration Structure
|
||||
typedef struct {
|
||||
custom_wifi_ap_config_t wifi_ap;
|
||||
ethernet_config_t ethernet;
|
||||
web_server_config_t web_server;
|
||||
scanner_config_t scanner;
|
||||
} config_t;
|
||||
|
||||
// Function prototypes
|
||||
esp_err_t config_manager_init(void);
|
||||
esp_err_t config_manager_load(void);
|
||||
esp_err_t config_manager_save(void);
|
||||
const config_t* config_manager_get_config(void);
|
||||
|
||||
esp_err_t config_manager_update_wifi_ap(const custom_wifi_ap_config_t *config);
|
||||
esp_err_t config_manager_update_ethernet(const ethernet_config_t *config);
|
||||
esp_err_t config_manager_update_web_server(const web_server_config_t *config);
|
||||
esp_err_t config_manager_update_scanner(const scanner_config_t *config);
|
||||
|
||||
esp_err_t config_manager_reset_to_defaults(void);
|
||||
|
||||
// Password management functions
|
||||
esp_err_t config_manager_is_first_boot(bool* is_first_boot);
|
||||
esp_err_t config_manager_change_password(const char* username, const char* old_password,
|
||||
const char* new_password, bool* success);
|
||||
esp_err_t config_manager_change_wifi_password(const char* new_password, bool* success);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // CONFIG_MANAGER_H
|
||||
72
include/led_manager.h
Normal file
72
include/led_manager.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* LED Manager - Status Indicators
|
||||
* Provides visual feedback for system status and operations
|
||||
*/
|
||||
|
||||
#ifndef LED_MANAGER_H
|
||||
#define LED_MANAGER_H
|
||||
|
||||
#include <esp_err.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// LED GPIO Pins for ESP32-P4-NANO
|
||||
#define LED_STATUS_GPIO 8 // Blue LED
|
||||
#define LED_ERROR_GPIO 15 // Red LED
|
||||
|
||||
// Additional indicator LEDs (optional, map to unused GPIOs if not present)
|
||||
#define LED_ETHERNET_GPIO 9 // Ethernet activity LED (optional)
|
||||
#define LED_WIFI_GPIO 10 // Wi-Fi activity LED (optional)
|
||||
#define LED_SCAN_GPIO 11 // Scan activity LED (optional)
|
||||
|
||||
// LED basic states for blinking patterns
|
||||
typedef enum {
|
||||
LED_STATE_OFF = 0,
|
||||
LED_STATE_ON,
|
||||
LED_STATE_BLINK_SLOW,
|
||||
LED_STATE_BLINK_FAST,
|
||||
LED_STATE_PULSE
|
||||
} led_state_t;
|
||||
|
||||
// Extended system status indicators (kept for backward compatibility)
|
||||
typedef enum {
|
||||
LED_STATUS_SYSTEM_READY = 0,
|
||||
LED_STATUS_SYSTEM_ERROR,
|
||||
LED_STATUS_ETHERNET_CONNECTED,
|
||||
LED_STATUS_ETHERNET_DISCONNECTED,
|
||||
LED_STATUS_WIFI_AP_ACTIVE,
|
||||
LED_STATUS_WIFI_CLIENT_CONNECTED,
|
||||
LED_STATUS_SCAN_ACTIVE,
|
||||
LED_STATUS_SCAN_COMPLETE,
|
||||
LED_STATUS_SD_CARD_ACCESS,
|
||||
LED_STATUS_OTA_UPDATE
|
||||
} led_status_t;
|
||||
|
||||
/**
|
||||
* Initialize LED manager
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t led_manager_init(void);
|
||||
|
||||
/**
|
||||
* Set LED status
|
||||
* @param status LED status to set
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t led_manager_set_status(led_status_t status);
|
||||
|
||||
// Forward-compatibility: keep previous prototypes so existing source builds
|
||||
esp_err_t led_manager_set_state(int gpio_num, led_state_t state);
|
||||
void led_manager_update(void);
|
||||
void led_manager_set_ethernet_activity(bool active);
|
||||
void led_manager_set_wifi_activity(bool active);
|
||||
void led_manager_set_scan_activity(bool active);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // LED_MANAGER_H
|
||||
46
include/log_manager.h
Normal file
46
include/log_manager.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef LOG_MANAGER_H
|
||||
#define LOG_MANAGER_H
|
||||
|
||||
#include "esp_err.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Log levels
|
||||
typedef enum {
|
||||
LOG_LEVEL_DEBUG = 0,
|
||||
LOG_LEVEL_INFO,
|
||||
LOG_LEVEL_WARN,
|
||||
LOG_LEVEL_ERROR,
|
||||
LOG_LEVEL_CRITICAL
|
||||
} log_level_t;
|
||||
|
||||
// Function prototypes
|
||||
esp_err_t log_manager_init(void);
|
||||
esp_err_t log_manager_deinit(void);
|
||||
|
||||
// Main logging function
|
||||
esp_err_t log_manager_log(log_level_t level, const char* tag, const char* format, ...);
|
||||
|
||||
// Convenience logging functions
|
||||
esp_err_t log_manager_log_debug(const char* tag, const char* format, ...);
|
||||
esp_err_t log_manager_log_info(const char* tag, const char* format, ...);
|
||||
esp_err_t log_manager_log_warn(const char* tag, const char* format, ...);
|
||||
esp_err_t log_manager_log_error(const char* tag, const char* format, ...);
|
||||
esp_err_t log_manager_log_critical(const char* tag, const char* format, ...);
|
||||
|
||||
// Log management functions
|
||||
esp_err_t log_manager_rotate_logs(void);
|
||||
esp_err_t log_manager_cleanup_old_logs(void);
|
||||
esp_err_t log_manager_get_logs(char** logs, size_t* logs_size);
|
||||
esp_err_t log_manager_clear_logs(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // LOG_MANAGER_H
|
||||
123
include/network_manager.h
Normal file
123
include/network_manager.h
Normal file
@@ -0,0 +1,123 @@
|
||||
/**
|
||||
* Network Manager Header
|
||||
* Handles dual interface management for ESP32-P4-NANO:
|
||||
* - ESP32-P4: Ethernet interface (LAN8720 RMII PHY)
|
||||
* - ESP32-C6: Wi-Fi Access Point
|
||||
*
|
||||
* Enhanced with comprehensive debugging and error handling
|
||||
*/
|
||||
|
||||
#ifndef NETWORK_MANAGER_H
|
||||
#define NETWORK_MANAGER_H
|
||||
|
||||
#include <esp_err.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "esp_netif.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Network interface types
|
||||
typedef enum {
|
||||
NETIF_TYPE_ETHERNET,
|
||||
NETIF_TYPE_WIFI_AP
|
||||
} network_interface_type_t;
|
||||
|
||||
// Network statistics structure
|
||||
typedef struct {
|
||||
bool link_up;
|
||||
uint32_t rx_packets;
|
||||
uint32_t tx_packets;
|
||||
uint32_t rx_bytes;
|
||||
uint32_t tx_bytes;
|
||||
uint32_t rx_errors;
|
||||
uint32_t tx_errors;
|
||||
} network_stats_t;
|
||||
|
||||
// GPIO Configuration for ESP32-P4-NANO with IP101GRI PHY
|
||||
#define ETH_MDC_GPIO 31
|
||||
#define ETH_MDIO_GPIO 52
|
||||
#define ETH_PHY_RST_GPIO 51
|
||||
#define ETH_PHY_ADDR 0
|
||||
#define ETH_REF_CLK_GPIO 50
|
||||
#define ETH_TX_EN_GPIO 49
|
||||
#define ETH_TXD0_GPIO 34
|
||||
#define ETH_TXD1_GPIO 35
|
||||
#define ETH_RXD0_GPIO 30
|
||||
#define ETH_RXD1_GPIO 29
|
||||
#define ETH_CRS_DV_GPIO 28
|
||||
|
||||
// Function declarations
|
||||
|
||||
/**
|
||||
* Enable/disable debug output
|
||||
*/
|
||||
esp_err_t network_manager_set_debug(bool enable);
|
||||
|
||||
/**
|
||||
* Enable/disable matrix debug output
|
||||
*/
|
||||
esp_err_t network_manager_set_matrix_debug(bool enable);
|
||||
|
||||
/**
|
||||
* Initialize Ethernet interface (LAN8720 RMII PHY)
|
||||
*/
|
||||
esp_err_t network_manager_init_ethernet(void);
|
||||
|
||||
/**
|
||||
* Initialize Wi-Fi Access Point using ESP-Hosted-FG
|
||||
*/
|
||||
esp_err_t network_manager_init_wifi_ap(void);
|
||||
|
||||
/**
|
||||
* Monitor Ethernet interface status with enhanced debugging
|
||||
*/
|
||||
void network_manager_monitor_ethernet(void);
|
||||
|
||||
/**
|
||||
* Monitor Wi-Fi AP status with enhanced debugging
|
||||
*/
|
||||
void network_manager_monitor_wifi(void);
|
||||
|
||||
/**
|
||||
* Update network statistics with debugging
|
||||
*/
|
||||
void network_manager_update_stats(void);
|
||||
|
||||
/**
|
||||
* Get network statistics for specified interface
|
||||
*/
|
||||
esp_err_t network_manager_get_stats(network_interface_type_t type, network_stats_t *stats);
|
||||
|
||||
/**
|
||||
* Get Ethernet interface handle
|
||||
*/
|
||||
esp_netif_t* network_manager_get_ethernet_netif(void);
|
||||
|
||||
/**
|
||||
* Get Wi-Fi AP interface handle
|
||||
*/
|
||||
esp_netif_t* network_manager_get_wifi_ap_netif(void);
|
||||
|
||||
/**
|
||||
* Check if Ethernet link is up
|
||||
*/
|
||||
bool network_manager_ethernet_link_up(void);
|
||||
|
||||
/**
|
||||
* Get Ethernet MAC address
|
||||
*/
|
||||
esp_err_t network_manager_get_ethernet_mac(uint8_t *mac);
|
||||
|
||||
/**
|
||||
* Get Wi-Fi AP MAC address
|
||||
*/
|
||||
esp_err_t network_manager_get_wifi_mac(uint8_t *mac);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NETWORK_MANAGER_H
|
||||
65
include/ota_manager.h
Normal file
65
include/ota_manager.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* OTA Manager - Firmware Update Management
|
||||
* Handles Over-The-Air firmware updates via Wi-Fi
|
||||
*/
|
||||
|
||||
#ifndef OTA_MANAGER_H
|
||||
#define OTA_MANAGER_H
|
||||
|
||||
#include "esp_err.h"
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/semphr.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// OTA states
|
||||
typedef enum {
|
||||
OTA_STATE_IDLE = 0,
|
||||
OTA_STATE_CHECKING,
|
||||
OTA_STATE_DOWNLOADING,
|
||||
OTA_STATE_VERIFYING,
|
||||
OTA_STATE_READY_TO_UPDATE,
|
||||
OTA_STATE_UPDATING,
|
||||
OTA_STATE_COMPLETE,
|
||||
OTA_STATE_ERROR
|
||||
} ota_state_t;
|
||||
|
||||
// OTA progress structure
|
||||
typedef struct {
|
||||
ota_state_t state;
|
||||
int progress_percent;
|
||||
char status_message[128];
|
||||
char error_message[128];
|
||||
uint32_t bytes_downloaded;
|
||||
uint32_t total_bytes;
|
||||
bool update_available;
|
||||
char new_version[32];
|
||||
char current_version[32];
|
||||
} ota_progress_t;
|
||||
|
||||
// Function prototypes
|
||||
esp_err_t ota_manager_init(void);
|
||||
esp_err_t ota_manager_deinit(void);
|
||||
|
||||
// Server configuration
|
||||
esp_err_t ota_manager_set_server_url(const char* server_url);
|
||||
|
||||
// Update management
|
||||
esp_err_t ota_manager_check_for_updates(void);
|
||||
esp_err_t ota_manager_start_update(const char* url);
|
||||
esp_err_t ota_manager_install_update(void);
|
||||
esp_err_t ota_manager_cancel_update(void);
|
||||
esp_err_t ota_manager_get_current_version(char* version);
|
||||
|
||||
// Progress monitoring
|
||||
esp_err_t ota_manager_get_progress(ota_progress_t* progress);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // OTA_MANAGER_H
|
||||
338
include/scanner_engine.h
Normal file
338
include/scanner_engine.h
Normal file
@@ -0,0 +1,338 @@
|
||||
/**
|
||||
* Scanner Engine - Network Reconnaissance and Analysis
|
||||
* Provides ARP, port scanning, DNS monitoring, and packet analysis
|
||||
*/
|
||||
|
||||
#ifndef SCANNER_ENGINE_H
|
||||
#define SCANNER_ENGINE_H
|
||||
|
||||
#include <esp_err.h>
|
||||
#include <esp_system.h>
|
||||
#include <lwip/ip_addr.h>
|
||||
#include <lwip/ip4_addr.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/queue.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
// Constants
|
||||
#define MAX_DEVICES 100
|
||||
#define MAX_MAC_VENDORS 1000
|
||||
#define DNS_MAX_NAME_LEN 256
|
||||
|
||||
// MAC vendor database entry
|
||||
typedef struct {
|
||||
uint8_t prefix[3];
|
||||
char vendor[64];
|
||||
} mac_vendor_entry_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Scan types
|
||||
typedef enum {
|
||||
SCAN_TYPE_ARP = 0,
|
||||
SCAN_TYPE_PORT_TCP,
|
||||
SCAN_TYPE_PORT_SYN,
|
||||
SCAN_TYPE_ICMP_PING,
|
||||
SCAN_TYPE_DNS_MONITOR,
|
||||
SCAN_TYPE_DHCP_MONITOR,
|
||||
SCAN_TYPE_PASSIVE_SNIFF,
|
||||
SCAN_TYPE_MAX
|
||||
} scan_type_t;
|
||||
|
||||
// Scan status
|
||||
typedef enum {
|
||||
SCAN_STATUS_IDLE = 0,
|
||||
SCAN_STATUS_RUNNING,
|
||||
SCAN_STATUS_COMPLETED,
|
||||
SCAN_STATUS_ERROR,
|
||||
SCAN_STATUS_CANCELLED
|
||||
} scan_status_t;
|
||||
|
||||
// Port scan methods
|
||||
typedef enum {
|
||||
PORT_SCAN_TCP_CONNECT = 0,
|
||||
PORT_SCAN_TCP_SYN,
|
||||
PORT_SCAN_UDP
|
||||
} port_scan_method_t;
|
||||
|
||||
// Discovered device structure
|
||||
typedef struct {
|
||||
ip4_addr_t ip_addr;
|
||||
uint8_t mac_addr[6];
|
||||
char hostname[64];
|
||||
char vendor[32];
|
||||
uint32_t response_time;
|
||||
uint16_t open_ports[256];
|
||||
uint8_t open_port_count;
|
||||
uint32_t last_seen;
|
||||
bool is_active;
|
||||
} discovered_device_t;
|
||||
|
||||
// Scan configuration
|
||||
typedef struct {
|
||||
scan_type_t type;
|
||||
ip4_addr_t start_ip;
|
||||
ip4_addr_t end_ip;
|
||||
uint16_t port_start;
|
||||
uint16_t port_end;
|
||||
port_scan_method_t method;
|
||||
uint32_t timeout_ms;
|
||||
uint32_t delay_ms;
|
||||
bool aggressive_mode;
|
||||
char output_file[128];
|
||||
} scan_config_t;
|
||||
|
||||
// Scan request structure
|
||||
typedef struct {
|
||||
uint32_t scan_id;
|
||||
scan_config_t config;
|
||||
scan_status_t status;
|
||||
uint32_t progress_percent;
|
||||
uint32_t devices_found;
|
||||
uint32_t start_time;
|
||||
uint32_t end_time;
|
||||
char error_message[256];
|
||||
} scan_request_t;
|
||||
|
||||
// Scanner statistics
|
||||
typedef struct {
|
||||
uint32_t total_scans;
|
||||
uint32_t successful_scans;
|
||||
uint32_t failed_scans;
|
||||
uint32_t devices_discovered;
|
||||
uint32_t ports_scanned;
|
||||
uint32_t packets_sent;
|
||||
uint32_t packets_received;
|
||||
uint32_t scan_time_ms;
|
||||
} scanner_stats_t;
|
||||
|
||||
// DNS monitoring structures
|
||||
typedef struct {
|
||||
char domain[256];
|
||||
char query_type[8];
|
||||
char source_ip[16];
|
||||
uint32_t timestamp;
|
||||
} dns_query_t;
|
||||
|
||||
// DHCP monitoring structures
|
||||
typedef struct {
|
||||
uint8_t mac_addr[6];
|
||||
ip4_addr_t ip_addr;
|
||||
uint32_t lease_time;
|
||||
uint32_t timestamp;
|
||||
char hostname[64];
|
||||
char message_type[16];
|
||||
} dhcp_lease_t;
|
||||
|
||||
// Packet capture configuration
|
||||
typedef struct {
|
||||
int interface_index;
|
||||
bool promiscuous;
|
||||
bool save_pcap;
|
||||
const char *filter;
|
||||
} capture_config_t;
|
||||
|
||||
// Packet information
|
||||
typedef struct {
|
||||
uint32_t timestamp;
|
||||
uint16_t protocol;
|
||||
char source[32];
|
||||
char destination[32];
|
||||
uint16_t source_port;
|
||||
uint16_t destination_port;
|
||||
uint32_t length;
|
||||
char info[256];
|
||||
uint8_t *payload;
|
||||
uint32_t payload_length;
|
||||
} packet_info_t;
|
||||
|
||||
#define MAX_CONCURRENT_SCANS 3
|
||||
#define MAX_DISCOVERED_DEVICES 1000
|
||||
#define SCAN_QUEUE_SIZE 10
|
||||
#define DEFAULT_PORT_TIMEOUT 1000 // 1 second
|
||||
#define DEFAULT_SCAN_DELAY 10 // 10ms between requests
|
||||
|
||||
/**
|
||||
* Initialize scanner engine
|
||||
* @return ESP_OK on success, error code otherwise
|
||||
*/
|
||||
esp_err_t scanner_engine_init(void);
|
||||
|
||||
/**
|
||||
* Deinitialize scanner engine
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t scanner_engine_deinit(void);
|
||||
|
||||
/**
|
||||
* Start network scan
|
||||
* @param config Scan configuration
|
||||
* @param scan_id Pointer to store scan ID
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t scanner_engine_start_scan(const scan_config_t *config, uint32_t *scan_id);
|
||||
|
||||
/**
|
||||
* Stop active scan
|
||||
* @param scan_id Scan ID to stop
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t scanner_engine_stop_scan(uint32_t scan_id);
|
||||
|
||||
/**
|
||||
* Get scan results
|
||||
* @param devices Buffer to store discovered devices
|
||||
* @param count On input: buffer size, on output: actual device count
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t scanner_engine_get_results(discovered_device_t *devices, size_t *count);
|
||||
|
||||
/**
|
||||
* Get scan status
|
||||
* @param scan_id Scan ID
|
||||
* @param status Buffer to store scan status
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t scanner_engine_get_scan_status(uint32_t scan_id, scan_request_t *status);
|
||||
|
||||
/**
|
||||
* Process scan queue (legacy function for compatibility)
|
||||
*/
|
||||
void scanner_engine_process_queue(void);
|
||||
|
||||
/**
|
||||
* Get discovered devices
|
||||
* @param devices Array to store devices
|
||||
* @param max_devices Maximum number of devices to return
|
||||
* @param device_count Pointer to store actual device count
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t scanner_engine_get_devices(discovered_device_t *devices, size_t max_devices, size_t *device_count);
|
||||
|
||||
/**
|
||||
* Clear discovered devices list
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t scanner_engine_clear_devices(void);
|
||||
|
||||
/**
|
||||
* Get scanner statistics
|
||||
* @param stats Pointer to store statistics
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t scanner_engine_get_stats(scanner_stats_t *stats);
|
||||
|
||||
/**
|
||||
* Reset scanner statistics
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t scanner_engine_reset_stats(void);
|
||||
|
||||
/**
|
||||
* Export scan results to file
|
||||
* @param scan_id Scan ID
|
||||
* @param format Export format ("json", "csv", "xml")
|
||||
* @param filepath Output file path
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t scanner_engine_export_results(uint32_t scan_id, const char *format, const char *filepath);
|
||||
|
||||
// Specific scan functions
|
||||
/**
|
||||
* Perform ARP scan
|
||||
* @param config Scan configuration
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t scanner_arp_scan(const scan_config_t *config);
|
||||
|
||||
/**
|
||||
* Perform TCP port scan
|
||||
* @param config Scan configuration
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t scanner_tcp_port_scan(const scan_config_t *config);
|
||||
|
||||
/**
|
||||
* Perform ICMP ping sweep
|
||||
* @param config Scan configuration
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t scanner_icmp_ping_sweep(const scan_config_t *config);
|
||||
|
||||
/**
|
||||
* Start DNS monitoring
|
||||
* @param duration_seconds Duration to monitor (0 = continuous)
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t scanner_start_dns_monitor(uint32_t duration_seconds);
|
||||
|
||||
/**
|
||||
* Stop DNS monitoring
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t scanner_stop_dns_monitor(void);
|
||||
|
||||
/**
|
||||
* Get DNS queries from monitor
|
||||
* @param queries Array to store queries
|
||||
* @param max_queries Maximum number of queries to retrieve
|
||||
* @param query_count Actual number of queries retrieved
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t scanner_get_dns_queries(dns_query_t *queries, size_t max_queries, size_t *query_count);
|
||||
|
||||
/**
|
||||
* Start DHCP monitoring
|
||||
* @param duration_seconds Duration to monitor (0 = continuous)
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t scanner_start_dhcp_monitor(uint32_t duration_seconds);
|
||||
|
||||
/**
|
||||
* Stop DHCP monitoring
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t scanner_stop_dhcp_monitor(void);
|
||||
|
||||
/**
|
||||
* Get DHCP leases from monitor
|
||||
* @param leases Array to store leases
|
||||
* @param max_leases Maximum number of leases to retrieve
|
||||
* @param lease_count Actual number of leases retrieved
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t scanner_get_dhcp_leases(dhcp_lease_t *leases, size_t max_leases, size_t *lease_count);
|
||||
|
||||
/**
|
||||
* Start passive network sniffing
|
||||
* @param duration_seconds Duration to sniff (0 = continuous)
|
||||
* @param pcap_file PCAP file to save packets (optional)
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t scanner_start_passive_sniff(uint32_t duration_seconds, const char *pcap_file);
|
||||
|
||||
/**
|
||||
* Stop passive packet sniffing
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t scanner_stop_passive_sniff(void);
|
||||
|
||||
/**
|
||||
* Get current PCAP file path
|
||||
* @param filename Buffer to store filename
|
||||
* @param size Buffer size
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t scanner_get_pcap_file(char *filename, size_t size);
|
||||
|
||||
// MAC vendor database functions
|
||||
esp_err_t load_mac_vendor_database(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SCANNER_ENGINE_H
|
||||
177
include/sd_manager.h
Normal file
177
include/sd_manager.h
Normal file
@@ -0,0 +1,177 @@
|
||||
/**
|
||||
* SD Card Manager - File System Operations
|
||||
* Manages FAT32 SD card for web assets, logs, and configuration
|
||||
*/
|
||||
|
||||
#ifndef SD_MANAGER_H
|
||||
#define SD_MANAGER_H
|
||||
|
||||
#include <esp_err.h>
|
||||
#include <esp_vfs_fat.h>
|
||||
#include <sdmmc_cmd.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// SD card configuration
|
||||
#define SD_MOUNT_POINT "/sdcard"
|
||||
#define SD_MAX_FILES 10
|
||||
#define SD_FORMAT_IF_MOUNT_FAIL true
|
||||
#define SD_ALLOC_UNIT_SIZE 16 * 1024
|
||||
|
||||
// Directory structure
|
||||
#define SD_WWW_DIR SD_MOUNT_POINT "/www"
|
||||
#define SD_LOGS_DIR SD_MOUNT_POINT "/logs"
|
||||
#define SD_CONFIG_DIR SD_MOUNT_POINT "/config"
|
||||
#define SD_SCRIPTS_DIR SD_MOUNT_POINT "/scripts"
|
||||
|
||||
// File paths
|
||||
#define SD_CONFIG_FILE SD_CONFIG_DIR "/config.json"
|
||||
#define SD_WIFI_CONFIG_FILE SD_CONFIG_DIR "/wifi.json"
|
||||
#define SD_SCAN_CONFIG_FILE SD_CONFIG_DIR "/scan.json"
|
||||
#define SD_INDEX_HTML SD_WWW_DIR "/index.html"
|
||||
|
||||
// Log file naming
|
||||
#define LOG_FILE_PREFIX "audit_"
|
||||
#define LOG_FILE_EXTENSION ".log"
|
||||
#define LOG_MAX_SIZE (1024 * 1024) // 1MB per log file
|
||||
#define LOG_MAX_FILES 100
|
||||
|
||||
/**
|
||||
* Initialize SD card and mount file system
|
||||
* @return ESP_OK on success, error code otherwise
|
||||
*/
|
||||
esp_err_t sd_manager_init(void);
|
||||
|
||||
/**
|
||||
* Deinitialize SD card
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t sd_manager_deinit(void);
|
||||
|
||||
/**
|
||||
* Check if SD card is mounted and accessible
|
||||
* @return true if available, false otherwise
|
||||
*/
|
||||
bool sd_manager_is_available(void);
|
||||
|
||||
/**
|
||||
* Create directory structure on SD card
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t sd_manager_create_directories(void);
|
||||
|
||||
/**
|
||||
* Write data to file
|
||||
* @param filepath Full path to file
|
||||
* @param data Data to write
|
||||
* @param size Size of data
|
||||
* @param append Whether to append or overwrite
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t sd_manager_write_file(const char *filepath, const void *data, size_t size, bool append);
|
||||
|
||||
/**
|
||||
* Read data from file
|
||||
* @param filepath Full path to file
|
||||
* @param buffer Buffer to read into
|
||||
* @param size Size of buffer
|
||||
* @param bytes_read Pointer to store actual bytes read
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t sd_manager_read_file(const char *filepath, void *buffer, size_t size, size_t *bytes_read);
|
||||
|
||||
/**
|
||||
* Delete file
|
||||
* @param filepath Full path to file
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t sd_manager_delete_file(const char *filepath);
|
||||
|
||||
/**
|
||||
* Check if file exists
|
||||
* @param filepath Full path to file
|
||||
* @return true if file exists, false otherwise
|
||||
*/
|
||||
bool sd_manager_file_exists(const char *filepath);
|
||||
|
||||
/**
|
||||
* Get file size
|
||||
* @param filepath Full path to file
|
||||
* @param size Pointer to store file size
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t sd_manager_get_file_size(const char *filepath, size_t *size);
|
||||
|
||||
/**
|
||||
* List files in directory
|
||||
* @param dir_path Directory path
|
||||
* @param file_list Buffer to store file list (JSON format)
|
||||
* @param buffer_size Size of buffer
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t sd_manager_list_files(const char *dir_path, char *file_list, size_t buffer_size);
|
||||
|
||||
/**
|
||||
* Create new log file with timestamp
|
||||
* @param log_type Type of log (e.g., "scan", "system", "error")
|
||||
* @param filepath Buffer to store created filepath
|
||||
* @param filepath_size Size of filepath buffer
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t sd_manager_create_log_file(const char *log_type, char *filepath, size_t filepath_size);
|
||||
|
||||
/**
|
||||
* Write log entry with timestamp
|
||||
* @param filepath Log file path
|
||||
* @param level Log level (INFO, WARN, ERROR)
|
||||
* @param message Log message
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t sd_manager_write_log(const char *filepath, const char *level, const char *message);
|
||||
|
||||
/**
|
||||
* Get SD card information
|
||||
* @param info Pointer to sdmmc_card_t structure
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t sd_manager_get_card_info(sdmmc_card_t **info);
|
||||
|
||||
/**
|
||||
* Get free space on SD card
|
||||
* @param free_bytes Pointer to store free bytes
|
||||
* @param total_bytes Pointer to store total bytes
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t sd_manager_get_space_info(uint64_t *free_bytes, uint64_t *total_bytes);
|
||||
|
||||
/**
|
||||
* Create directory
|
||||
* @param path Directory path to create
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t sd_manager_mkdir(const char *path);
|
||||
|
||||
/**
|
||||
* Append data to file
|
||||
* @param filepath Full path to file
|
||||
* @param data Data to append
|
||||
* @param size Size of data
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t sd_manager_append_file(const char *filepath, const void *data, size_t size);
|
||||
|
||||
/**
|
||||
* Rename file
|
||||
* @param old_path Current file path
|
||||
* @param new_path New file path
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t sd_manager_rename_file(const char *old_path, const char *new_path);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SD_MANAGER_H
|
||||
45
include/security_manager.h
Normal file
45
include/security_manager.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Security Manager - Authentication and Access Control
|
||||
* Handles Wi-Fi security, web authentication, and system security
|
||||
*/
|
||||
|
||||
#ifndef SECURITY_MANAGER_H
|
||||
#define SECURITY_MANAGER_H
|
||||
|
||||
#include "esp_err.h"
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/semphr.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Function prototypes
|
||||
esp_err_t security_manager_init(void);
|
||||
esp_err_t security_manager_deinit(void);
|
||||
|
||||
// Authentication functions
|
||||
esp_err_t security_manager_authenticate(const char* username, const char* password,
|
||||
const char* ip_address, char* session_id, size_t session_id_size);
|
||||
|
||||
// Password hashing functions
|
||||
esp_err_t security_manager_hash_password(const char* password, char* salt, size_t salt_size,
|
||||
char* hash, size_t hash_size);
|
||||
bool verify_password_hash(const char* password, const char* stored_hash);
|
||||
|
||||
// Session management
|
||||
esp_err_t security_manager_validate_session(const char* session_id, char* username, size_t username_size);
|
||||
esp_err_t security_manager_logout(const char* session_id);
|
||||
esp_err_t security_manager_cleanup_expired_sessions(void);
|
||||
esp_err_t security_manager_get_active_sessions(int* count);
|
||||
|
||||
// Configuration
|
||||
esp_err_t security_manager_is_authentication_required(bool* required);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SECURITY_MANAGER_H
|
||||
117
include/web_server.h
Normal file
117
include/web_server.h
Normal file
@@ -0,0 +1,117 @@
|
||||
/**
|
||||
* Web Server - HTTP Server and File Management
|
||||
* Serves web interface from SD card and provides REST API
|
||||
*/
|
||||
|
||||
#ifndef WEB_SERVER_H
|
||||
#define WEB_SERVER_H
|
||||
|
||||
#include <esp_err.h>
|
||||
#include <esp_http_server.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Web server configuration
|
||||
#define WEB_SERVER_PORT 80
|
||||
#define WEB_SERVER_MAX_URI_LEN 512
|
||||
#define WEB_SERVER_MAX_HDR_LEN 1024
|
||||
#define WEB_SERVER_STACK_SIZE 8192
|
||||
|
||||
// Authentication configuration
|
||||
#define WEB_AUTH_ENABLED true
|
||||
#define WEB_AUTH_USERNAME "admin"
|
||||
#define WEB_AUTH_PASSWORD "audit123"
|
||||
#define WEB_SESSION_TIMEOUT 3600 // 1 hour in seconds
|
||||
|
||||
// Wi-Fi AP configuration
|
||||
#define WIFI_AP_SSID "ESP32-P4-Bridge"
|
||||
#define WIFI_AP_IP "192.168.4.1"
|
||||
#define WIFI_AP_CHANNEL 1
|
||||
|
||||
// File upload limits
|
||||
#define MAX_FILE_SIZE (1024 * 1024) // 1MB
|
||||
#define MAX_FILENAME_LEN 64
|
||||
|
||||
/**
|
||||
* Initialize HTTP web server
|
||||
* @return ESP_OK on success, error code otherwise
|
||||
*/
|
||||
esp_err_t web_server_init(void);
|
||||
|
||||
/**
|
||||
* Stop HTTP web server
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t web_server_stop(void);
|
||||
|
||||
/**
|
||||
* Update system status for web interface
|
||||
*/
|
||||
void web_server_update_status(void);
|
||||
|
||||
/**
|
||||
* Register custom URI handlers
|
||||
* @param server HTTP server handle
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t web_server_register_handlers(httpd_handle_t server);
|
||||
|
||||
/**
|
||||
* Authenticate HTTP request
|
||||
* @param req HTTP request handle
|
||||
* @return true if authenticated, false otherwise
|
||||
*/
|
||||
bool web_server_authenticate(httpd_req_t *req);
|
||||
|
||||
/**
|
||||
* Send JSON response
|
||||
* @param req HTTP request handle
|
||||
* @param json_string JSON string to send
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t web_server_send_json(httpd_req_t *req, const char *json_string);
|
||||
|
||||
/**
|
||||
* Send file from SD card
|
||||
* @param req HTTP request handle
|
||||
* @param filepath Path to file on SD card
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t web_server_send_file(httpd_req_t *req, const char *filepath);
|
||||
|
||||
/**
|
||||
* Handle file upload
|
||||
* @param req HTTP request handle
|
||||
* @param destination Destination path on SD card
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t web_server_handle_upload(httpd_req_t *req, const char *destination);
|
||||
|
||||
/**
|
||||
* Get MIME type from file extension
|
||||
* @param filename File name
|
||||
* @return MIME type string
|
||||
*/
|
||||
const char* web_server_get_mime_type(const char *filename);
|
||||
|
||||
// REST API endpoints
|
||||
#define API_PREFIX "/api"
|
||||
#define API_SCAN_START API_PREFIX "/scan/start"
|
||||
#define API_SCAN_STOP API_PREFIX "/scan/stop"
|
||||
#define API_SCAN_STATUS API_PREFIX "/scan/status"
|
||||
#define API_SCAN_RESULTS API_PREFIX "/scan/results"
|
||||
#define API_SYSTEM_STATUS API_PREFIX "/system/status"
|
||||
#define API_SYSTEM_REBOOT API_PREFIX "/system/reboot"
|
||||
#define API_LOGS_LIST API_PREFIX "/logs/list"
|
||||
#define API_LOGS_DOWNLOAD API_PREFIX "/logs/download"
|
||||
#define API_CONFIG_GET API_PREFIX "/config/get"
|
||||
#define API_CONFIG_SET API_PREFIX "/config/set"
|
||||
#define API_UPLOAD_FILE API_PREFIX "/upload"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // WEB_SERVER_H
|
||||
Reference in New Issue
Block a user