Skip to content

Instantly share code, notes, and snippets.

@Staubgeborener
Last active July 17, 2021 18:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Staubgeborener/6977a6851510a296eabde0b9148f4658 to your computer and use it in GitHub Desktop.
Save Staubgeborener/6977a6851510a296eabde0b9148f4658 to your computer and use it in GitHub Desktop.
#include "freertos/FreeRTOS.h"
#include "nvs_flash.h"
#include "lwip/err.h"
#include "esp_wifi.h"
#include "esp_wifi_internal.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_event_loop.h"
uint16_t offset = 0;
esp_err_t event_handler(void* ctx, system_event_t* event)
{
return ESP_OK;
}
void promiscuousmode(void* buffer, wifi_promiscuous_pkt_type_t type)
{
wifi_promiscuous_pkt_t* p = (wifi_promiscuous_pkt_t*)buffer;
//remove last 4 bytes of mgmt packets
//if (type == WIFI_PKT_MGMT) (packet->rx_ctrl.sig_len) -= 4;
for (int i = 0; i < p->rx_ctrl.sig_len; i++) {
if (i % 8 == 0) {
printf("%06X ", offset);
offset += 8;
}
printf("%02X ", p->payload[i]);
if (i % 8 == 7) {
printf("\n");
}
else if ((i + 1) == p->rx_ctrl.sig_len) {
printf("\n");
}
}
offset = 0;
}
void app_main(void)
{
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
esp_interface_t wifi_if;
nvs_flash_init();
tcpip_adapter_init();
ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
ESP_ERROR_CHECK(esp_wifi_start());
esp_wifi_set_promiscuous(true);
esp_wifi_set_promiscuous_rx_cb(&promiscuousmode);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment