11#if DETWS_ENABLE_WIFI_SNIFFER
15bool detws_wifi_parse(
const uint8_t *frame,
size_t len, WifiFrame *out)
17 if (!frame || !out || len < 10)
20 memset(out, 0,
sizeof(*out));
22 uint8_t fc0 = frame[0];
23 uint8_t fc1 = frame[1];
24 out->version = fc0 & 0x03;
25 out->type = (fc0 >> 2) & 0x03;
26 out->subtype = (fc0 >> 4) & 0x0F;
27 out->to_ds = (fc1 & 0x01) != 0;
28 out->from_ds = (fc1 & 0x02) != 0;
29 out->retry = (fc1 & 0x08) != 0;
30 out->protected_frame = (fc1 & 0x40) != 0;
33 memcpy(out->addr1, frame + 4, 6);
37 memcpy(out->addr2, frame + 10, 6);
42 memcpy(out->addr3, frame + 16, 6);
48void detws_wifi_stats_reset(WifiStats *s)
51 memset(s, 0,
sizeof(*s));
54void detws_wifi_stats_add(WifiStats *s,
const WifiFrame *f)
60 case WifiType::WIFI_TYPE_MGMT:
63 case WifiType::WIFI_TYPE_CTRL:
66 case WifiType::WIFI_TYPE_DATA:
76bool detws_wifi_should_roam(int8_t cur_rssi, int8_t cand_rssi, uint8_t hysteresis_db)
80 int32_t margin = (int32_t)cand_rssi - (int32_t)cur_rssi;
81 return margin > (int32_t)hysteresis_db;
802.11 frame decode + traffic tally + RSSI roaming decision (DETWS_ENABLE_WIFI_SNIFFER).