espilon-source/espilon_bot/components/mod_system/cmd_system.c
Eun0us 6d45770d98 epsilon: merge command system into core + add 5 new modules
Move command registry from components/command/ into components/core/.
New modules: mod_canbus, mod_honeypot, mod_fallback, mod_redteam, mod_ota.
Replace mod_proxy with tun_core (multiplexed SOCKS5 tunnel).
Kconfig extended with per-module settings and async worker config.
2026-02-28 20:07:59 +01:00

198 lines
5.1 KiB
C

/*
* cmd_system.c
* Refactored for new command system (flat commands)
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include "esp_log.h"
#include "esp_system.h"
#include "esp_timer.h"
#include "esp_chip_info.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "utils.h"
#define TAG "SYSTEM"
/* ============================================================
* COMMAND: system_reboot
* ============================================================ */
static int cmd_system_reboot(
int argc,
char **argv,
const char *req,
void *ctx
) {
(void)argc;
(void)argv;
(void)ctx;
msg_info(TAG, "Rebooting device", req);
vTaskDelay(pdMS_TO_TICKS(250));
esp_restart();
return 0;
}
/* ============================================================
* COMMAND: system_mem
* ============================================================ */
static int cmd_system_mem(
int argc,
char **argv,
const char *req,
void *ctx
) {
(void)argc;
(void)argv;
(void)ctx;
uint32_t heap_free = esp_get_free_heap_size();
uint32_t heap_min = esp_get_minimum_free_heap_size();
size_t internal_free = heap_caps_get_free_size(MALLOC_CAP_INTERNAL);
char buf[256];
snprintf(buf, sizeof(buf),
"heap_free=%" PRIu32 " heap_min=%" PRIu32 " internal_free=%u",
heap_free,
heap_min,
(unsigned)internal_free
);
msg_info(TAG, buf, req);
return 0;
}
/* ============================================================
* COMMAND: system_uptime
* ============================================================ */
static int cmd_system_uptime(
int argc,
char **argv,
const char *req,
void *ctx
) {
(void)argc;
(void)argv;
(void)ctx;
uint64_t sec = esp_timer_get_time() / 1000000ULL;
char buf[128];
snprintf(buf, sizeof(buf),
"uptime=%llu days=%llu h=%02llu m=%02llu s=%02llu",
(unsigned long long)sec,
(unsigned long long)(sec / 86400),
(unsigned long long)((sec / 3600) % 24),
(unsigned long long)((sec / 60) % 60),
(unsigned long long)(sec % 60)
);
msg_info(TAG, buf, req);
return 0;
}
/* ============================================================
* COMMAND: system_info
* ============================================================ */
static int cmd_system_info(
int argc,
char **argv,
const char *req,
void *ctx
) {
(void)argc;
(void)argv;
(void)ctx;
esp_chip_info_t chip_info;
esp_chip_info(&chip_info);
uint32_t heap_free = esp_get_free_heap_size();
uint64_t uptime_sec = esp_timer_get_time() / 1000000ULL;
char buf[512];
int len = 0;
len += snprintf(buf + len, sizeof(buf) - len,
"chip=%s cores=%d flash=%s heap=%"PRIu32" uptime=%llus modules=",
CONFIG_IDF_TARGET,
chip_info.cores,
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external",
heap_free,
(unsigned long long)uptime_sec
);
// List loaded modules
int first = 1;
#ifdef CONFIG_MODULE_NETWORK
len += snprintf(buf + len, sizeof(buf) - len, "%snetwork", first ? "" : ",");
first = 0;
#endif
#ifdef CONFIG_MODULE_FAKEAP
len += snprintf(buf + len, sizeof(buf) - len, "%sfakeap", first ? "" : ",");
first = 0;
#endif
#ifdef CONFIG_MODULE_RECON
#ifdef CONFIG_RECON_MODE_CAMERA
len += snprintf(buf + len, sizeof(buf) - len, "%scamera", first ? "" : ",");
first = 0;
#endif
#ifdef CONFIG_RECON_MODE_MLAT
len += snprintf(buf + len, sizeof(buf) - len, "%smlat", first ? "" : ",");
first = 0;
#endif
#endif
#ifdef CONFIG_MODULE_HONEYPOT
len += snprintf(buf + len, sizeof(buf) - len, "%shoneypot", first ? "" : ",");
first = 0;
#endif
#ifdef CONFIG_MODULE_CANBUS
len += snprintf(buf + len, sizeof(buf) - len, "%scanbus", first ? "" : ",");
first = 0;
#endif
#ifdef CONFIG_MODULE_FALLBACK
len += snprintf(buf + len, sizeof(buf) - len, "%sfallback", first ? "" : ",");
first = 0;
#endif
#ifdef CONFIG_MODULE_REDTEAM
len += snprintf(buf + len, sizeof(buf) - len, "%sredteam", first ? "" : ",");
first = 0;
#endif
#ifdef CONFIG_ESPILON_OTA_ENABLED
len += snprintf(buf + len, sizeof(buf) - len, "%sota", first ? "" : ",");
first = 0;
#endif
if (first) {
len += snprintf(buf + len, sizeof(buf) - len, "none");
}
msg_info(TAG, buf, req);
return 0;
}
/* ============================================================
* COMMAND REGISTRATION
* ============================================================ */
static const command_t system_cmds[] = {
{ "system_reboot", NULL, NULL, 0, 0, cmd_system_reboot, NULL, false },
{ "system_mem", NULL, NULL, 0, 0, cmd_system_mem, NULL, false },
{ "system_uptime", NULL, NULL, 0, 0, cmd_system_uptime, NULL, false },
{ "system_info", NULL, NULL, 0, 0, cmd_system_info, NULL, false }
};
void mod_system_register_commands(void)
{
ESPILON_LOGI_PURPLE(TAG, "Registering system commands");
for (size_t i = 0; i < sizeof(system_cmds)/sizeof(system_cmds[0]); i++) {
command_register(&system_cmds[i]);
}
}