Skip to content

Commit 0491b4a

Browse files
Merge pull request #1093 from justcallmekoko/develop
Reduce frame buffer size for non-PSRAM
2 parents ef6aec0 + 29b6783 commit 0491b4a

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

esp32_marauder/WiFiScan.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
static const uint8_t *g_filter_bssid = nullptr;
1010
uint8_t *current_act = nullptr;
1111

12-
MacEntry WiFiScan::mac_entries[mac_history_len];
13-
uint8_t WiFiScan::mac_entry_state[mac_history_len];
12+
MacEntry WiFiScan::mac_entries[mac_history_len_half];
13+
uint8_t WiFiScan::mac_entry_state[mac_history_len_half];
1414

1515
int num_beacon = 0;
1616
int num_deauth = 0;
@@ -1721,7 +1721,7 @@ void WiFiScan::RunSetup() {
17211721
mac_history = (struct mac_addr*) ps_malloc(mac_history_len * sizeof(struct mac_addr));
17221722
#endif
17231723

1724-
for (int i = 0; i < mac_history_len; i++)
1724+
for (int i = 0; i < mac_history_len_half; i++)
17251725
mac_entry_state[i] = 0;
17261726

17271727
#ifdef HAS_BT
@@ -2637,7 +2637,7 @@ int16_t WiFiScan::seen_mac_int(unsigned char* mac, bool simple) {
26372637
tmp[x] = mac[x];
26382638
}
26392639

2640-
for (int x = 0; x < mac_history_len; x++) {
2640+
for (int x = 0; x < mac_history_len_half; x++) {
26412641
if (this->mac_cmp(tmp, mac_entries[x].mac)) {
26422642
return x;
26432643
}
@@ -2658,12 +2658,12 @@ inline uint32_t WiFiScan::hash_mac(const uint8_t mac[6]) {
26582658

26592659
int WiFiScan::update_mac_entry(const uint8_t mac[6], int8_t rssi, bool bt) {
26602660
const uint32_t now_ms = millis();
2661-
const uint32_t start_idx = hash_mac(mac) & (mac_history_len - 1);
2661+
const uint32_t start_idx = hash_mac(mac) & (mac_history_len_half - 1);
26622662

26632663
int32_t first_tombstone = -1;
26642664

2665-
for (uint32_t probe = 0; probe < mac_history_len; probe++) {
2666-
const uint32_t idx = (start_idx + probe) & (mac_history_len - 1);
2665+
for (uint32_t probe = 0; probe < mac_history_len_half; probe++) {
2666+
const uint32_t idx = (start_idx + probe) & (mac_history_len_half - 1);
26672667

26682668
switch (mac_entry_state[idx]) {
26692669

@@ -2699,7 +2699,7 @@ int WiFiScan::update_mac_entry(const uint8_t mac[6], int8_t rssi, bool bt) {
26992699

27002700
mac_entries[idx].rssi = rssi;
27012701

2702-
return idx + mac_history_len;
2702+
return idx + mac_history_len_half;
27032703
}
27042704
break;
27052705
}
@@ -2737,7 +2737,7 @@ void WiFiScan::evict_and_insert(const uint8_t mac[6], uint32_t now_ms) {
27372737
const uint32_t EVICT_AGE_MS = TRACK_EVICT_SEC * 1000UL;
27382738

27392739
// 1) Prefer reusing a tombstone if any exist.
2740-
for (uint32_t i = 0; i < mac_history_len; i++) {
2740+
for (uint32_t i = 0; i < mac_history_len_half; i++) {
27412741
if (mac_entry_state[i] == TOMBSTONE_ENTRY) {
27422742
insert_mac_entry(i, mac, now_ms);
27432743
return;
@@ -2754,7 +2754,7 @@ void WiFiScan::evict_and_insert(const uint8_t mac[6], uint32_t now_ms) {
27542754
uint16_t victim_any_frames = 0xFFFF;
27552755
uint32_t victim_any_age = 0;
27562756

2757-
for (uint32_t i = 0; i < mac_history_len; i++) {
2757+
for (uint32_t i = 0; i < mac_history_len_half; i++) {
27582758
if (mac_entry_state[i] != VALID_ENTRY) continue;
27592759

27602760
const uint32_t age = (uint32_t)(now_ms - mac_entries[i].last_seen_ms);
@@ -2890,7 +2890,7 @@ uint8_t WiFiScan::build_top10_for_ui(MacEntry* out_top10, MacSortMode mode) {
28902890
}
28912891
};
28922892

2893-
for (uint32_t i = 0; i < mac_history_len; i++) {
2893+
for (uint32_t i = 0; i < mac_history_len_half; i++) {
28942894
if (mac_entry_state[i] != VALID_ENTRY)
28952895
continue;
28962896

@@ -8085,12 +8085,12 @@ void WiFiScan::beaconSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type
80858085
else if (wifi_scan_obj.currentScanMode == WIFI_SCAN_DETECT_FOLLOW) {
80868086
int frame_check = wifi_scan_obj.update_mac_entry(src_addr, snifferPacket->rx_ctrl.rssi);
80878087

8088-
if (frame_check >= mac_history_len) {
8088+
if (frame_check >= mac_history_len_half) {
80898089
int32_t dloc = 0;
8090-
bool is_following = is_following_candidate_light(wifi_scan_obj.mac_entries[frame_check - mac_history_len], millis(), &dloc);
8090+
bool is_following = is_following_candidate_light(wifi_scan_obj.mac_entries[frame_check - mac_history_len_half], millis(), &dloc);
80918091
if (is_following) {
8092-
wifi_scan_obj.mac_entries[frame_check - mac_history_len].dloc = dloc;
8093-
wifi_scan_obj.mac_entries[frame_check - mac_history_len].following = is_following;
8092+
wifi_scan_obj.mac_entries[frame_check - mac_history_len_half].dloc = dloc;
8093+
wifi_scan_obj.mac_entries[frame_check - mac_history_len_half].following = is_following;
80948094
buffer_obj.append(snifferPacket, len);
80958095
}
80968096
}

esp32_marauder/WiFiScan.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,8 +662,8 @@ class WiFiScan
662662
volatile bool bt_pending_clear = false;
663663

664664

665-
static MacEntry mac_entries[mac_history_len];
666-
static uint8_t mac_entry_state[mac_history_len];
665+
static MacEntry mac_entries[mac_history_len_half];
666+
static uint8_t mac_entry_state[mac_history_len_half];
667667

668668
// Stuff for RAW stats
669669
uint32_t mgmt_frames = 0;

esp32_marauder/configs.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
#define HAS_BT
156156
#define HAS_BT_REMOTE
157157
#define HAS_BUTTONS
158-
#define HAS_NEOPIXEL_LED
158+
//#define HAS_NEOPIXEL_LED
159159
//#define HAS_PWR_MGMT
160160
#define HAS_SCREEN
161161
#define HAS_FULL_SCREEN
@@ -2334,6 +2334,8 @@
23342334
#define mac_history_len 100
23352335
#endif
23362336

2337+
#define mac_history_len_half (mac_history_len / 2)
2338+
23372339
#if defined(MARAUDER_V6) || defined(MARAUDER_V6_1)
23382340
#define GPS_SERIAL_INDEX 2
23392341
#define GPS_TX 4
@@ -2409,6 +2411,7 @@
24092411
#endif
24102412
#else
24112413
#define mac_history_len 100
2414+
#define mac_history_len_half (mac_history_len / 2)
24122415
#endif
24132416
//// END GPS STUFF
24142417

@@ -2519,9 +2522,9 @@
25192522
#ifdef HAS_PSRAM
25202523
#define BUF_SIZE 8 * 1024 // Had to reduce buffer size to save RAM. GG @spacehuhn
25212524
#define SNAP_LEN 1 * 4096 // max len of each recieved packet
2522-
#elif !defined(HAS_ILI9341)
2523-
#define BUF_SIZE 8 * 1024 // Had to reduce buffer size to save RAM. GG @spacehuhn
2524-
#define SNAP_LEN 4096 // max len of each recieved packet
2525+
//#elif !defined(HAS_ILI9341)
2526+
// #define BUF_SIZE 8 * 1024 // Had to reduce buffer size to save RAM. GG @spacehuhn
2527+
// #define SNAP_LEN 4096 // max len of each recieved packet
25252528
#else
25262529
#define BUF_SIZE 3 * 1024 // Had to reduce buffer size to save RAM. GG @spacehuhn
25272530
#define SNAP_LEN 2324 // max len of each recieved packet

0 commit comments

Comments
 (0)