This commit is contained in:
2025-05-01 23:57:01 +02:00
parent 9229711870
commit 6123cd0fe3
2 changed files with 80 additions and 6 deletions

12
.vscode/settings.json vendored
View File

@@ -1,11 +1,11 @@
{ {
"C_Cpp.intelliSenseEngine": "default", "C_Cpp.intelliSenseEngine": "default",
"idf.espIdfPath": "/home/bruno/esp/v5.4.1/esp-idf", "idf.espIdfPath": "/home/bruno/esp/master/esp-idf",
"idf.pythonInstallPath": "/usr/bin/python", "idf.pythonInstallPath": "/usr/bin/python",
"idf.openOcdConfigs": [ "idf.openOcdConfigs": [
"board/esp32s3-builtin.cfg" "board/esp32s3-builtin.cfg"
], ],
"idf.port": "/dev/ttyUSB0", "idf.port": "/dev/ttyUSB1",
"idf.toolsPath": "/home/bruno/.espressif", "idf.toolsPath": "/home/bruno/.espressif",
"idf.customExtraVars": { "idf.customExtraVars": {
"OPENOCD_SCRIPTS": "/home/bruno/.espressif/tools/openocd-esp32/v0.12.0-esp32-20240821/openocd-esp32/share/openocd/scripts", "OPENOCD_SCRIPTS": "/home/bruno/.espressif/tools/openocd-esp32/v0.12.0-esp32-20240821/openocd-esp32/share/openocd/scripts",
@@ -19,6 +19,10 @@
"array": "c", "array": "c",
"string": "c", "string": "c",
"string_view": "c", "string_view": "c",
"span": "c" "span": "c",
} "esp_timer.h": "c",
"sx1262.h": "c"
},
"idf.flashBaudRate": "921600",
"idf.monitorBaudRate": "921600",
} }

View File

@@ -2,21 +2,91 @@
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "driver/gpio.h" #include "driver/gpio.h"
#include "esp_log.h"
#include "sdkconfig.h" #include "sdkconfig.h"
#include "esp_mac.h"
#include <string.h> #include <string.h>
#include "radio.h" #include "radio.h"
#include "buscfg.h" #include "buscfg.h"
#include "driver/spi_master.h" #include "driver/spi_master.h"
#include "esp_event.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_timer.h"
#include "esp_wifi.h"
#include "esp_log.h"
#include "esp_mac.h"
#include "nvs_flash.h"
#include "string.h"
#include "mbedtls/base64.h"
#include "driver/uart.h"
#define TAG "canZem" #define TAG "canZem"
void wifi_sniffer_packet_handler(void *buf, wifi_promiscuous_pkt_type_t type)
{
if (type != WIFI_PKT_MGMT && type != WIFI_PKT_DATA)
return;
const wifi_promiscuous_pkt_t *ppkt = (wifi_promiscuous_pkt_t *)buf;
const uint8_t *payload = ppkt->payload;
uint32_t len = ppkt->rx_ctrl.sig_len + 44;
// Simple PlecyC header check
if (len > 24 + 11 &&
payload[29] == 'P' &&
payload[30] == 'l' &&
payload[31] == 'e' &&
payload[32] == 'c' &&
payload[33] == 'y' &&
payload[34] == 'C')
{
unsigned char outBuf[3136];
size_t output_len = 0; // will store the real output size
mbedtls_base64_encode(outBuf, sizeof(outBuf), &output_len, buf, len);
printf("\n the frame is %ld bytes long\n", len);
printf("\nGot 2400mhZ frame: %s\n", outBuf);
// // Parse further as needed
// ESP_LOGI(TAG, "HEXko\n");
// ESP_LOG_BUFFER_HEXDUMP(TAG, buf, len, ESP_LOG_INFO);
}
}
void start_sniffer()
{
nvs_flash_init();
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
cfg.static_rx_buf_num = 32;
cfg.dynamic_rx_buf_num = 32;
cfg.ampdu_tx_enable = 1;
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
// Set mode to NULL (or STA)
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL));
ESP_ERROR_CHECK(esp_wifi_start());
// Set channel 10 explicitly
ESP_ERROR_CHECK(esp_wifi_set_channel(10, WIFI_SECOND_CHAN_NONE));
// Enable promiscuous mode and set callback
ESP_ERROR_CHECK(esp_wifi_set_promiscuous_rx_cb(&wifi_sniffer_packet_handler));
ESP_ERROR_CHECK(esp_wifi_set_promiscuous(true));
// Optional: Disable power saving
ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE));
}
void app_main(void) void app_main(void)
{ {
uart_set_baudrate(UART_NUM_0, 921600);
ESP_LOGI("BOOT", "BRN Systems incorporated CanSat flight firmware build: %s %s", __DATE__, __TIME__); ESP_LOGI("BOOT", "BRN Systems incorporated CanSat flight firmware build: %s %s", __DATE__, __TIME__);
start_sniffer();
spi_bus_config_t HighSpeedBusCfg = { spi_bus_config_t HighSpeedBusCfg = {
// CONNECTED to LoRa and SD card // CONNECTED to LoRa and SD card
.mosi_io_num = HSPI_MOSI_GPIO, .mosi_io_num = HSPI_MOSI_GPIO,