RF Sentinel (RFSentinel): free, open-source police detector app for Android. Spots police body cams, Flock ALPR cameras, AirTag trackers, Remote ID drones, smart glasses and fake cell towers from Bluetooth LE and WiFi. No root.
Kotlin airtagalprandroidandroid-autoanti-surveillancebluetooth-low-energybody-cameracounter-surveillancedrone-detectionflock-safetyimsi-catcher-detectorpolice-detectorpolice-scannerprivacyremote-idrtl-sdrsdrsurveillance-detectiontracker-detectionwifi
MT7921AU: visit a rotating third of the 6 GHz channels each round (every channel within 3 rounds), and every round any 6 GHz channel that carried a frame in the last 90 s
CIS-C05d9517ede66a
diff --git a/app/src/main/java/com/rfsentinel/app/usb/Mt7921uMonitor.kt b/app/src/main/java/com/rfsentinel/app/usb/Mt7921uMonitor.ktindex d018504..a6d1ba5 100644--- a/app/src/main/java/com/rfsentinel/app/usb/Mt7921uMonitor.kt+++ b/app/src/main/java/com/rfsentinel/app/usb/Mt7921uMonitor.kt@@ -41,6 +41,22 @@ object Mt7921uMonitor {149, 153, 157, 161, 165).map { 1 to it } +listOf(5, 21, 37, 53, 69, 85, 101, 117, 133, 149, 165, 181, 197, 213, 229).map { 2 to it }private const val DWELL_MS = 150L+ /** Each 6 GHz channel is visited every this many rounds, unless something was heard on it lately. */+ private const val SIX_GHZ_EVERY = 3+ /** A 6 GHz channel that carried a frame this recently is visited every round. */+ private const val SIX_GHZ_ACTIVE_MS = 90_000L++ /**+ * The channels of hop round [round]: all of 2.4 and 5 GHz, and a rotating third of the 6 GHz+ * channels plus any 6 GHz channel in [active6]. 6 GHz switches are the slowest (often the full+ * timeout) and most places have little there yet, so a full 6 GHz pass every round would+ * stretch the loop by about half for nothing; every channel is still visited every 3 rounds.+ */+ internal fun roundPlan(round: Int, active6: Set<Int>): List<Pair<Int, Int>> {+ val six = HOP.filter { it.first == 2 }+ return HOP.filter { it.first != 2 } ++ six.filterIndexed { i, (_, ch) -> i % SIX_GHZ_EVERY == round % SIX_GHZ_EVERY || ch in active6 }+ }private const val RX_ANTENNAS = 0x3private const val SWITCH_TIMEOUT_MS = 500L/** A full round, allowing ~150 ms per channel switch on top of the dwell. */@@ -565,6 +581,10 @@ object Mt7921uMonitor {private class RxState {var hopAt = 0L; var lastEmit = 0L; var lastRxAt = 0L; var lastCheck = 0L; var hopIdx = 0+ var round = 0; var plan: List<Pair<Int, Int>> = HOP+ /** 6 GHz channel number -> when a frame was last heard on it. */+ val heard6 = HashMap<Int, Long>()+ val current get() = plan[hopIdx]/** Sequence number of the hop's last command until the firmware confirms it (-1: confirmed). */var pendingSeq = -1; var sentAt = 0Lvar switches = 0; var switchMsTotal = 0L; var switchMsMax = 0L; var unconfirmed = 0@@ -595,7 +615,8 @@ object Mt7921uMonitor {return@onData}val f = parseRx(b, n, onBad = { crc -> if (crc) stats.badChecksum++ else stats.malformed++ }) ?: return@onData- val (hopBand, hopCh) = HOP[st.hopIdx]+ val (hopBand, hopCh) = st.current+ if (f.band == 2 && f.channel > 0) st.heard6[f.channel] = System.currentTimeMillis()// The descriptor's channel, else the one tuned to.val ch = if (f.channel > 0) monitorChannel(f.band, f.channel) else monitorChannel(hopBand, hopCh)stats.frame(f.rssi)@@ -603,7 +624,7 @@ object Mt7921uMonitor {}) { now ->stats.maybeLog(now) {val (aps, clients) = frames.live(now, REPORT_MS)- val (band, ch) = HOP[st.hopIdx]+ val (band, ch) = st.current"${listOf("2.4", "5", "6")[band]} GHz ch $ch, $aps access points, $clients devices, " +"firmware answered $cmdsAnswered of $cmdsSent commands, ${st.switchSummary()}, USB errors $ctlErrors"}@@ -621,8 +642,13 @@ object Mt7921uMonitor {// dwell is counted from that answer, so slow switches don't eat the listening time.if (st.pendingSeq >= 0 && now - st.sentAt > SWITCH_TIMEOUT_MS) { st.unconfirmed++; st.pendingSeq = -1; st.hopAt = now }if (st.pendingSeq < 0 && now - st.hopAt > DWELL_MS) {- st.hopIdx = (st.hopIdx + 1) % HOP.size- val (band, ch) = HOP[st.hopIdx]+ st.hopIdx+++ if (st.hopIdx >= st.plan.size) {+ st.round+++ st.plan = roundPlan(st.round, st.heard6.filterValues { now - it < SIX_GHZ_ACTIVE_MS }.keys)+ st.hopIdx = 0+ }+ val (band, ch) = st.currentrunCatching { tune(band, ch, wait = false) }st.pendingSeq = seq; st.sentAt = nowval (aps, clients) = frames.live(now, REPORT_MS)diff --git a/app/src/test/java/com/rfsentinel/app/usb/Mt7921uDriverTest.kt b/app/src/test/java/com/rfsentinel/app/usb/Mt7921uDriverTest.ktindex c3edf12..8c7a587 100644--- a/app/src/test/java/com/rfsentinel/app/usb/Mt7921uDriverTest.kt+++ b/app/src/test/java/com/rfsentinel/app/usb/Mt7921uDriverTest.kt@@ -159,6 +159,19 @@ class Mt7921uDriverTest {assertEquals("6 GHz: the preferred scanning channels", (0 until 15).map { 5 + 16 * it }, m.HOP.filter { it.first == 2 }.map { it.second })}+ @Test+ fun sixGhzRotatesUnlessSomethingWasHeardThere() {+ val rounds = (0 until 3).map { r -> m.roundPlan(r, emptySet()) }+ for (plan in rounds) {+ assertEquals("all of 2.4 and 5 GHz every round", 13 + 25, plan.count { it.first != 2 })+ assertEquals("a third of 6 GHz per round", 5, plan.count { it.first == 2 })+ }+ assertEquals("every 6 GHz channel within 3 rounds", m.HOP.filter { it.first == 2 }.toSet(),+ rounds.flatten().filter { it.first == 2 }.toSet())+ // ch 37 had traffic: it's in every round+ for (r in 0 until 3) assertTrue(2 to 37 in m.roundPlan(r, setOf(37)))+ }+// --- firmware: the official linux-firmware images, unmodified ---private val dir = "src/main/assets/usbwifi"