12#if DETWS_ENABLE_PROMISC
16bool wifi_frame_parse(
const uint8_t *frame, uint16_t len, WifiFrameInfo *out)
18 if (!frame || !out || len < 10)
20 memset(out, 0,
sizeof(*out));
22 const uint8_t fc0 = frame[0];
23 const uint8_t fc1 = frame[1];
24 out->type = (WifiFrameType)((fc0 >> 2) & 0x3);
25 out->subtype = (uint8_t)((fc0 >> 4) & 0xF);
26 out->to_ds = (fc1 & 0x01) != 0;
27 out->from_ds = (fc1 & 0x02) != 0;
28 out->protected_frame = (fc1 & 0x40) != 0;
30 if (out->type == WifiFrameType::WIFI_FT_CTRL)
41 out->seq = (uint16_t)(((uint16_t)frame[22] | ((uint16_t)frame[23] << 8)) >> 4);
42 out->is_qos = (out->type == WifiFrameType::WIFI_FT_DATA) && (out->subtype & 0x08) != 0;
44 const bool has_addr4 = out->to_ds && out->from_ds;
50 if (out->is_qos && (fc1 & 0x80))
56 const uint8_t *a1 = frame + 4;
57 const uint8_t *a2 = frame + 10;
58 const uint8_t *a3 = frame + 16;
59 if (!out->to_ds && !out->from_ds)
65 else if (!out->to_ds && out->from_ds)
71 else if (out->to_ds && !out->from_ds)
80 out->src = frame + 24;
100 promisc_sink_fn sink =
nullptr;
104void promisc_rx(
void *buf, wifi_promiscuous_pkt_type_t)
106 if (!s_promisc.sink || !buf)
108 const wifi_promiscuous_pkt_t *pkt = (
const wifi_promiscuous_pkt_t *)buf;
109 uint16_t len = (uint16_t)pkt->rx_ctrl.sig_len;
112 s_promisc.sink(pkt->payload, (uint16_t)(len - 4), (int8_t)pkt->rx_ctrl.rssi, (uint8_t)pkt->rx_ctrl.channel);
116bool promisc_begin(uint8_t channel, promisc_sink_fn sink)
120 s_promisc.sink = sink;
121 esp_wifi_set_promiscuous(
true);
122 esp_wifi_set_promiscuous_rx_cb(&promisc_rx);
123 esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE);
127void promisc_set_channel(uint8_t channel)
129 esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE);
132void promisc_end(
void)
134 esp_wifi_set_promiscuous(
false);
135 s_promisc.sink =
nullptr;
140bool promisc_begin(uint8_t, promisc_sink_fn)
144void promisc_set_channel(uint8_t)
148void promisc_end(
void)
Wi-Fi promiscuous (monitor) capture (DETWS_ENABLE_PROMISC) - passive 802.11 sniffing.