Look at every packet with promiscuous mode
This commit is contained in:
parent
8984dcb4c5
commit
1c636e0749
1 changed files with 59 additions and 0 deletions
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
#include "WiFi.h"
|
#include "WiFi.h"
|
||||||
|
#include "esp_wifi.h"
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
#include "ESP8266WiFi.h"
|
#include "ESP8266WiFi.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -15,6 +16,23 @@ fw::API *firewallApi;
|
||||||
|
|
||||||
WiFiServer wifiServer(80);
|
WiFiServer wifiServer(80);
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
unsigned frame_ctrl : 16;
|
||||||
|
unsigned duration_id : 16;
|
||||||
|
uint8_t addr1[6]; /* receiver address */
|
||||||
|
uint8_t addr2[6]; /* sender address */
|
||||||
|
uint8_t addr3[6]; /* filtering address */
|
||||||
|
unsigned sequence_ctrl : 16;
|
||||||
|
uint8_t addr4[6]; /* optional */
|
||||||
|
} wifi_ieee80211_mac_hdr_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
wifi_ieee80211_mac_hdr_t hdr;
|
||||||
|
uint8_t payload[0]; /* network data ended with 4 bytes csum (CRC32) */
|
||||||
|
} wifi_ieee80211_packet_t;
|
||||||
|
|
||||||
void connectToWifi()
|
void connectToWifi()
|
||||||
{
|
{
|
||||||
WiFi.begin(ssid, psk);
|
WiFi.begin(ssid, psk);
|
||||||
|
@ -47,11 +65,52 @@ void handle_wifi_events(WiFiEvent_t event, WiFiEventInfo_t info)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *wifi_sniffer_packet_type2str(wifi_promiscuous_pkt_type_t type)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case WIFI_PKT_DATA:
|
||||||
|
return "DATA";
|
||||||
|
default:
|
||||||
|
case WIFI_PKT_MISC:
|
||||||
|
return "MISC";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wifi_sniffer_packet_handler(void *buff, wifi_promiscuous_pkt_type_t type)
|
||||||
|
{
|
||||||
|
if (type != WIFI_PKT_MGMT)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const wifi_promiscuous_pkt_t *ppkt = (wifi_promiscuous_pkt_t *)buff;
|
||||||
|
const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)ppkt->payload;
|
||||||
|
const wifi_ieee80211_mac_hdr_t *hdr = &ipkt->hdr;
|
||||||
|
|
||||||
|
printf("PACKET TYPE=%s, CHAN=%02d, RSSI=%02d,"
|
||||||
|
" ADDR1=%02x:%02x:%02x:%02x:%02x:%02x,"
|
||||||
|
" ADDR2=%02x:%02x:%02x:%02x:%02x:%02x,"
|
||||||
|
" ADDR3=%02x:%02x:%02x:%02x:%02x:%02x\n",
|
||||||
|
wifi_sniffer_packet_type2str(type),
|
||||||
|
ppkt->rx_ctrl.channel,
|
||||||
|
ppkt->rx_ctrl.rssi,
|
||||||
|
/* ADDR1 */
|
||||||
|
hdr->addr1[0], hdr->addr1[1], hdr->addr1[2],
|
||||||
|
hdr->addr1[3], hdr->addr1[4], hdr->addr1[5],
|
||||||
|
/* ADDR2 */
|
||||||
|
hdr->addr2[0], hdr->addr2[1], hdr->addr2[2],
|
||||||
|
hdr->addr2[3], hdr->addr2[4], hdr->addr2[5],
|
||||||
|
/* ADDR3 */
|
||||||
|
hdr->addr3[0], hdr->addr3[1], hdr->addr3[2],
|
||||||
|
hdr->addr3[3], hdr->addr3[4], hdr->addr3[5]);
|
||||||
|
}
|
||||||
|
|
||||||
void setup_wifi()
|
void setup_wifi()
|
||||||
{
|
{
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.onEvent(handle_wifi_events, ARDUINO_EVENT_MAX);
|
WiFi.onEvent(handle_wifi_events, ARDUINO_EVENT_MAX);
|
||||||
connectToWifi();
|
connectToWifi();
|
||||||
|
esp_wifi_set_promiscuous(true);
|
||||||
|
esp_wifi_set_promiscuous_rx_cb(&wifi_sniffer_packet_handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
|
|
Reference in a new issue