/* * rt_attack.c * Mutual exclusion for offensive operations. * * Ensures only one attack runs at a time (deauth, beacon, karma, capture). */ #include "sdkconfig.h" #ifdef CONFIG_MODULE_REDTEAM #include "freertos/FreeRTOS.h" #include "freertos/semphr.h" #include "esp_log.h" #include "rt_attack.h" #define TAG "RT_ATTACK" static SemaphoreHandle_t s_mutex = NULL; static rt_attack_type_t s_current = RT_ATTACK_NONE; static bool s_inited = false; static const char *s_names[] = { [RT_ATTACK_NONE] = "none", [RT_ATTACK_DEAUTH] = "deauth", [RT_ATTACK_BEACON] = "beacon", [RT_ATTACK_KARMA] = "karma", [RT_ATTACK_CAPTURE] = "capture", }; void rt_attack_init(void) { if (s_inited) return; s_mutex = xSemaphoreCreateMutex(); configASSERT(s_mutex); s_current = RT_ATTACK_NONE; s_inited = true; } esp_err_t rt_attack_start(rt_attack_type_t type) { if (!s_inited) rt_attack_init(); xSemaphoreTake(s_mutex, portMAX_DELAY); if (s_current != RT_ATTACK_NONE) { ESP_LOGW(TAG, "Cannot start %s: %s already running", s_names[type], s_names[s_current]); xSemaphoreGive(s_mutex); return ESP_ERR_INVALID_STATE; } s_current = type; ESP_LOGI(TAG, "Attack started: %s", s_names[type]); xSemaphoreGive(s_mutex); return ESP_OK; } void rt_attack_stop(void) { if (!s_inited) return; xSemaphoreTake(s_mutex, portMAX_DELAY); if (s_current != RT_ATTACK_NONE) { ESP_LOGI(TAG, "Attack stopped: %s", s_names[s_current]); } s_current = RT_ATTACK_NONE; xSemaphoreGive(s_mutex); } rt_attack_type_t rt_attack_current(void) { if (!s_inited) return RT_ATTACK_NONE; xSemaphoreTake(s_mutex, portMAX_DELAY); rt_attack_type_t t = s_current; xSemaphoreGive(s_mutex); return t; } const char *rt_attack_name(void) { return s_names[rt_attack_current()]; } bool rt_attack_is_active(void) { return rt_attack_current() != RT_ATTACK_NONE; } #endif /* CONFIG_MODULE_REDTEAM */