# ESP32-C5 WiFi Monitor GDB Configuration # Auto-loaded for WiFi frame analysis with PHY rate and duration # ============================================================ # THRESHOLD TUNING COMMANDS # ============================================================ define show_thresholds printf "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n" printf "WiFi Monitor Thresholds (GDB-tunable)\n" printf "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n" printf "High NAV threshold: %u us\n", threshold_high_nav_us printf "Duration mismatch log: %u us\n", threshold_duration_mismatch_us printf "PHY rate fallback: %u Mbps\n", threshold_phy_rate_fallback_mbps printf "Duration multiplier: %ux expected\n", threshold_duration_multiplier printf "\n" printf "Collapse Detection:\n" printf " Retry rate threshold: %.1f%%\n", threshold_retry_rate_percent printf " Avg NAV collapse: %u us\n", threshold_avg_nav_collapse_us printf " Collision percentage: %.1f%%\n", threshold_collision_percent printf " Mismatch percentage: %.1f%%\n", threshold_mismatch_percent printf "\n" printf "Logging Control:\n" printf " Log every N mismatches: %u (1=all, 10=every 10th)\n", log_every_n_mismatches printf "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n" end define set_high_nav if $argc != 1 printf "Usage: set_high_nav \n" printf "Example: set_high_nav 8000 (set to 8ms)\n" else set threshold_high_nav_us = $arg0 printf "High NAV threshold set to %u us\n", threshold_high_nav_us end end define set_mismatch_log if $argc != 1 printf "Usage: set_mismatch_log \n" printf "Example: set_mismatch_log 15000 (log when NAV > 15ms)\n" else set threshold_duration_mismatch_us = $arg0 printf "Duration mismatch logging threshold set to %u us\n", threshold_duration_mismatch_us end end define set_rate_fallback if $argc != 1 printf "Usage: set_rate_fallback \n" printf "Example: set_rate_fallback 50 (fallback if < 50 Mbps)\n" else set threshold_phy_rate_fallback_mbps = $arg0 printf "PHY rate fallback threshold set to %u Mbps\n", threshold_phy_rate_fallback_mbps end end define set_multiplier if $argc != 1 printf "Usage: set_multiplier \n" printf "Example: set_multiplier 3 (NAV > 3x expected = mismatch)\n" else set threshold_duration_multiplier = $arg0 printf "Duration multiplier set to %ux expected\n", threshold_duration_multiplier end end define set_log_rate if $argc != 1 printf "Usage: set_log_rate \n" printf "Example: set_log_rate 10 (log every 10th mismatch)\n" printf " set_log_rate 1 (log all mismatches)\n" else set log_every_n_mismatches = $arg0 printf "Logging every %u mismatch(es)\n", log_every_n_mismatches end end define tune_sensitive set threshold_high_nav_us = 3000 set threshold_duration_mismatch_us = 5000 set threshold_phy_rate_fallback_mbps = 150 set threshold_duration_multiplier = 1.5 set threshold_retry_rate_percent = 15.0 set threshold_avg_nav_collapse_us = 5000 set threshold_collision_percent = 5.0 set threshold_mismatch_percent = 3.0 printf "Thresholds set to SENSITIVE (catch more issues)\n" show_thresholds end define tune_normal set threshold_high_nav_us = 5000 set threshold_duration_mismatch_us = 10000 set threshold_phy_rate_fallback_mbps = 100 set threshold_duration_multiplier = 2 set threshold_retry_rate_percent = 20.0 set threshold_avg_nav_collapse_us = 10000 set threshold_collision_percent = 10.0 set threshold_mismatch_percent = 5.0 printf "Thresholds set to NORMAL (default)\n" show_thresholds end define tune_relaxed set threshold_high_nav_us = 10000 set threshold_duration_mismatch_us = 20000 set threshold_phy_rate_fallback_mbps = 50 set threshold_duration_multiplier = 3 set threshold_retry_rate_percent = 30.0 set threshold_avg_nav_collapse_us = 15000 set threshold_collision_percent = 15.0 set threshold_mismatch_percent = 10.0 printf "Thresholds set to RELAXED (fewer false positives)\n" show_thresholds end # ============================================================ # FRAME ANALYSIS COMMANDS # ============================================================ define show_frame_full printf "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n" printf "Frame: %s\n", wifi_frame_type_str(frame->type, frame->subtype) printf "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n" printf "RSSI: %d dBm\n", frame->rssi printf "Channel: %d\n", frame->channel printf "Retry: %s\n", frame->retry ? "YES" : "no" printf "\n" set $bw_str = "20MHz" if frame->bandwidth == 1 set $bw_str = "40MHz" end if frame->bandwidth == 2 set $bw_str = "80MHz" end printf "PHY Rate: %u Kbps (%.1f Mbps)\n", frame->phy_rate_kbps, frame->phy_rate_kbps / 1000.0 printf "Mode: MCS %d, BW %s, SGI %s\n", frame->mcs, $bw_str, frame->sgi ? "Yes" : "No" printf "\n" printf "Byte Count: %u bytes\n", frame->frame_len if frame->phy_rate_kbps > 0 set $tx_us = (frame->frame_len * 8000) / frame->phy_rate_kbps set $overhead = 44 set $expected = $tx_us + $overhead printf "Expected Duration: %u us (%u tx + %u overhead)\n", $expected, $tx_us, $overhead printf "Actual Duration (NAV): %u us\n", frame->duration_id set $diff = frame->duration_id - $expected if $diff > 0 printf "Difference: +%d us LONGER than expected", $diff if $diff > 5000 printf " ⚠⚠⚠ HIGH!\n" else printf "\n" end else set $diff = -$diff printf "Difference: -%d us shorter\n", $diff end else printf "Actual Duration (NAV): %u us\n", frame->duration_id end printf "\n" printf "Dest: %02x:%02x:%02x:%02x:%02x:%02x\n", frame->addr1[0], frame->addr1[1], frame->addr1[2], frame->addr1[3], frame->addr1[4], frame->addr1[5] printf "Source: %02x:%02x:%02x:%02x:%02x:%02x\n", frame->addr2[0], frame->addr2[1], frame->addr2[2], frame->addr2[3], frame->addr2[4], frame->addr2[5] printf "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n" end define show_duration set $tx_us = 0 if frame->phy_rate_kbps > 0 set $tx_us = (frame->frame_len * 8000) / frame->phy_rate_kbps set $expected = $tx_us + 44 printf "%s: %u bytes @ %.1f Mbps → Expected %u us, NAV %u us", wifi_frame_type_str(frame->type, frame->subtype), frame->frame_len, frame->phy_rate_kbps/1000.0, $expected, frame->duration_id set $diff = frame->duration_id - $expected if $diff > 0 printf " (+%d)\n", $diff else set $diff = -$diff printf " (-%d)\n", $diff end else printf "%s: %u bytes, NAV %u us\n", wifi_frame_type_str(frame->type, frame->subtype), frame->frame_len, frame->duration_id end end define find_high_nav break monitor_frame_callback if frame->duration_id > 10000 commands silent printf "⚠ HIGH NAV: " show_duration continue end printf "Watching for NAV > 10000 us\n" continue end define find_mismatch break monitor_frame_callback if frame->phy_rate_kbps > 0 && frame->duration_id > ((frame->frame_len * 8000) / frame->phy_rate_kbps + 44) * 2 printf "Watching for NAV 2x+ expected duration\n" continue end define watch_data break monitor_frame_callback if frame->type == 2 commands silent show_duration continue end printf "Watching DATA frames\n" continue end printf "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n" printf "WiFi Monitor GDB Commands Loaded\n" printf "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n" printf "Frame Analysis:\n" printf " show_frame_full - Complete frame analysis\n" printf " show_duration - Quick duration comparison\n" printf " find_high_nav - Auto-break on high NAV\n" printf " find_mismatch - Auto-break on NAV mismatch\n" printf " watch_data - Monitor DATA frames\n" printf "\n" printf "Threshold Tuning:\n" printf " show_thresholds - Display current thresholds\n" printf " set_high_nav - Set high NAV threshold\n" printf " set_mismatch_log - Set mismatch log threshold\n" printf " set_rate_fallback - Set rate fallback threshold\n" printf " set_multiplier - Set duration multiplier\n" printf " set_log_rate - Log every Nth mismatch\n" printf "\n" printf "Preset Profiles:\n" printf " tune_sensitive - Catch more issues (stricter)\n" printf " tune_normal - Default settings (balanced)\n" printf " tune_relaxed - Fewer false positives (lenient)\n" printf "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n" printf "Type 'show_thresholds' to see current settings\n" printf "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n"