Skip to content

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.

OUI-SPY: relay every network and Bluetooth device the board hears (survey engine), checked by RF Sentinel's own lists

CIS-C0fb06115acf52
diff --git a/app/src/main/OuiSpyBle.kt b/app/src/main/OuiSpyBle.kt
new file mode 100644
index 0000000..e69de29
diff --git a/app/src/main/java/com/rfsentinel/app/esp/EspReports.kt b/app/src/main/java/com/rfsentinel/app/esp/EspReports.kt
index 2806f7c..d05f0aa 100644
--- a/app/src/main/java/com/rfsentinel/app/esp/EspReports.kt
+++ b/app/src/main/java/com/rfsentinel/app/esp/EspReports.kt
@@ -17,6 +17,8 @@ data class EspSighting(
/** Wi-Fi network name (access points) or Bluetooth device name. */
val name: String? = null,
val frequencyMhz: Int = 0,
+ /** Wi-Fi security in Android's ScanResult style ("[WPA2-PSK]"), when known. */
+ val capabilities: String = "",
val companyId: Int? = null,
val serviceUuid16: Int? = null,
/** Drone position (OUI-Spy Sky Spy mode). */
diff --git a/app/src/main/java/com/rfsentinel/app/esp/OuiSpyBle.kt b/app/src/main/java/com/rfsentinel/app/esp/OuiSpyBle.kt
index eea694b..0b2918a 100644
--- a/app/src/main/java/com/rfsentinel/app/esp/OuiSpyBle.kt
+++ b/app/src/main/java/com/rfsentinel/app/esp/OuiSpyBle.kt
@@ -18,7 +18,8 @@ import com.rfsentinel.app.util.Permissions
/**
* Connects to an OUI-SPY board running the "App-Controlled" (Bluetooth)
* firmware, like its companion app does, but only for detection: it switches
- * on the Flock-BLE, Flock-WiFi, Sky Spy and Detector engines, listens to
+ * on the Flock-BLE, Flock-WiFi, Sky Spy and Detector engines (plus, by default,
+ * the survey engine that relays every network and device it hears), listens to
* Detection Events, and switches them off again when scanning stops. No cable
* needed; the board just needs power. Reconnects when the board comes back.
*/
@@ -32,6 +33,7 @@ object OuiSpyBle {
private var gatt: BluetoothGatt? = null
private var appContext: Context? = null
private var address: String? = null
+ private var relayAll = true
private var onSightings: ((List<EspSighting>) -> Unit)? = null
@Volatile private var active = false
private var inSpool = false
@@ -49,12 +51,13 @@ object OuiSpyBle {
Permissions.granted(context, android.Manifest.permission.BLUETOOTH_CONNECT)
/** Starts (or keeps) the link to the board at [boardAddress] while scanning. */
- fun start(context: Context, boardAddress: String, sightings: (List<EspSighting>) -> Unit) = main.post {
+ fun start(context: Context, boardAddress: String, relayEverything: Boolean, sightings: (List<EspSighting>) -> Unit) = main.post {
onSightings = sightings
- if (active && address == boardAddress) return@post
+ if (active && address == boardAddress && relayAll == relayEverything) return@post
stopNow()
appContext = context.applicationContext
address = boardAddress
+ relayAll = relayEverything
active = true
connect()
}
@@ -116,7 +119,8 @@ object OuiSpyBle {
@SuppressLint("MissingPermission")
private fun writeNext(g: BluetoothGatt) {
val next = pending.removeFirstOrNull() ?: run {
- setStatus("OUI-SPY · live · Flock, Sky Spy and Detector engines on")
+ setStatus(if (relayAll) "OUI-SPY · live · relaying everything it hears"
+ else "OUI-SPY · live · Flock, Sky Spy and Detector engines on")
return
}
val ctl = g.getService(OuiSpyBleProtocol.SERVICE)?.getCharacteristic(OuiSpyBleProtocol.ENGINE_CONTROL) ?: return
@@ -132,7 +136,7 @@ object OuiSpyBle {
val s = OuiSpyBleProtocol.decode(value) ?: return
detections++
onSightings?.invoke(listOf(s))
- setStatus("OUI-SPY · live · $detections detection${if (detections == 1) "" else "s"}")
+ setStatus("OUI-SPY · live · $detections report${if (detections == 1) "" else "s"}")
}
private val callback = object : BluetoothGattCallback() {
@@ -185,7 +189,7 @@ object OuiSpyBle {
if (g !== gatt) return@post
inSpool = false
pending.clear()
- OuiSpyBleProtocol.ENGINES.forEach { pending.addLast(OuiSpyBleProtocol.enable(it)) }
+ OuiSpyBleProtocol.engines(relayAll).forEach { pending.addLast(OuiSpyBleProtocol.enable(it)) }
writeNext(g)
}
}
diff --git a/app/src/main/java/com/rfsentinel/app/esp/OuiSpyBleProtocol.kt b/app/src/main/java/com/rfsentinel/app/esp/OuiSpyBleProtocol.kt
index 80a813b..84f500e 100644
--- a/app/src/main/java/com/rfsentinel/app/esp/OuiSpyBleProtocol.kt
+++ b/app/src/main/java/com/rfsentinel/app/esp/OuiSpyBleProtocol.kt
@@ -31,10 +31,15 @@ object OuiSpyBleProtocol {
const val ENGINE_FLOCK_BLE = 1
const val ENGINE_FLOCK_WIFI = 2
const val ENGINE_SKYSPY = 4
+ /** Survey mode: reports every Wi-Fi network and Bluetooth device the board hears. */
+ const val ENGINE_WARDRIVE = 6
- /** Only passive detection engines; RF Sentinel never touches the others. */
+ /** Detection engines; RF Sentinel never touches the others (UniPwn, PCAP, Foxhunter). */
val ENGINES = listOf(ENGINE_FLOCK_BLE, ENGINE_FLOCK_WIFI, ENGINE_SKYSPY, ENGINE_DETECTOR)
+ /** Engines to switch on; [relayAll] adds the survey engine so RF Sentinel's own rules see everything. */
+ fun engines(relayAll: Boolean) = if (relayAll) ENGINES + ENGINE_WARDRIVE else ENGINES
+
fun enable(engine: Int): ByteArray = byteArrayOf(0x01, engine.toByte())
fun disable(engine: Int): ByteArray = byteArrayOf(0x00, engine.toByte())
/** DISABLE_ALL (0x0F): the board goes quiet when RF Sentinel stops scanning. */
@@ -61,6 +66,22 @@ object OuiSpyBleProtocol {
ENGINE_FLOCK_BLE, ENGINE_FLOCK_WIFI -> flock(engine, d, mac, rssi, channel, method)
ENGINE_SKYSPY -> if (d.size >= 155) drone(d, b, mac, rssi, method) else null
ENGINE_DETECTOR -> detector(d, mac, rssi, channel, method)
+ ENGINE_WARDRIVE -> survey(d, mac, rssi, channel, method)
+ else -> null
+ }
+ }
+
+ // auth_mode: 0 open, 1 WEP, 2 WPA, 3 WPA2, 4 WPA/WPA2, 5 WPA2-Enterprise, 6 WPA3.
+ private val AUTH = listOf("[ESS]", "[WEP][ESS]", "[WPA-PSK][ESS]", "[WPA2-PSK][ESS]",
+ "[WPA-PSK][WPA2-PSK][ESS]", "[WPA2-EAP][ESS]", "[RSN-SAE][ESS]")
+
+ /** A plain sighting with no verdict: RF Sentinel's own watchlist and rules judge it. */
+ private fun survey(d: ByteArray, mac: String, rssi: Int, channel: Int, method: Int): EspSighting? {
+ if (d.size < 74) return null
+ return when (method) {
+ 0 -> EspSighting(mac = mac, rssi = rssi, ble = false, name = text(d, 19, 33),
+ frequencyMhz = freq(channel), capabilities = AUTH.getOrElse(d[52].toInt() and 0xFF) { "" })
+ 1 -> EspSighting(mac = mac, rssi = rssi, ble = true, name = text(d, 53, 21))
else -> null
}
}
diff --git a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
index cc2e8ce..58363ca 100644
--- a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
+++ b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt
@@ -243,7 +243,7 @@ class ScanForegroundService : Service() {
com.rfsentinel.app.esp.EspBoards.start(this) { list -> pipeline.post { list.forEach(::processEsp) } }
// An OUI-SPY board paired over Bluetooth (App-Controlled firmware).
Prefs.ouiSpyBoard(this)?.let { addr ->
- com.rfsentinel.app.esp.OuiSpyBle.start(this, addr) { list -> pipeline.post { list.forEach(::processEsp) } }
+ com.rfsentinel.app.esp.OuiSpyBle.start(this, addr, Prefs.ouiSpyRelayAll(this)) { list -> pipeline.post { list.forEach(::processEsp) } }
} ?: com.rfsentinel.app.esp.OuiSpyBle.stop()
updateLocationUpdates()
startHousekeeping()
@@ -462,7 +462,7 @@ class ScanForegroundService : Service() {
timestamp = now
) else Advert(
mac = e.mac, source = Advert.Source.WIFI, rssi = e.rssi, name = e.name,
- wifi = Advert.WifiInfo(e.frequencyMhz, "", null, emptyList()), timestamp = now
+ wifi = Advert.WifiInfo(e.frequencyMhz, e.capabilities, null, emptyList()), timestamp = now
)
process(advert, e.remoteId)
}
diff --git a/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt b/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt
index dc5ef00..39b26ad 100644
--- a/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt
@@ -318,6 +318,7 @@ class SettingsActivity : AppCompatActivity() {
binding.followMetersInput.setText(Prefs.followMinMeters(this).toString())
binding.gpsSwitch.isChecked = Prefs.gpsTaggingEnabled(this)
binding.autoRecordSwitch.isChecked = Prefs.autoRecordTrace(this)
+ binding.ouiSpyRelaySwitch.isChecked = Prefs.ouiSpyRelayAll(this)
binding.knownAlprSwitch.isChecked = Prefs.knownAlprAlerts(this)
binding.speedCameraSwitch.isChecked = Prefs.speedCameraAlerts(this)
binding.autoCamerasSwitch.isChecked = Prefs.autoCameras(this)
@@ -457,6 +458,7 @@ class SettingsActivity : AppCompatActivity() {
Prefs.setFollowMinMeters(this, (binding.followMetersInput.text.toString().toIntOrNull() ?: 800).coerceIn(100, 50_000))
Prefs.setGpsTaggingEnabled(this, binding.gpsSwitch.isChecked)
Prefs.setAutoRecordTrace(this, binding.autoRecordSwitch.isChecked)
+ Prefs.setOuiSpyRelayAll(this, binding.ouiSpyRelaySwitch.isChecked)
Prefs.setKnownAlprAlerts(this, binding.knownAlprSwitch.isChecked)
Prefs.setSpeedCameraAlerts(this, binding.speedCameraSwitch.isChecked)
Prefs.setAutoCameras(this, binding.autoCamerasSwitch.isChecked)
diff --git a/app/src/main/java/com/rfsentinel/app/util/Prefs.kt b/app/src/main/java/com/rfsentinel/app/util/Prefs.kt
index 398c1ea..260b0b6 100644
--- a/app/src/main/java/com/rfsentinel/app/util/Prefs.kt
+++ b/app/src/main/java/com/rfsentinel/app/util/Prefs.kt
@@ -119,6 +119,9 @@ object Prefs {
fun setOuiSpyBoard(context: Context, address: String?) = sp(context).edit {
if (address == null) remove("ouispy_board") else putString("ouispy_board", address)
}
+ /** Have the OUI-SPY board relay every network and Bluetooth device it hears (its Wardrive engine). */
+ fun ouiSpyRelayAll(context: Context): Boolean = bool(context, "ouispy_relay_all", true)
+ fun setOuiSpyRelayAll(context: Context, value: Boolean) = setBool(context, "ouispy_relay_all", value)
fun showKnownAlpr(context: Context): Boolean = bool(context, "show_known_alpr", true)
fun setShowKnownAlpr(context: Context, value: Boolean) = setBool(context, "show_known_alpr", value)
diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml
index e66b62f..eb43a16 100644
--- a/app/src/main/res/layout/activity_settings.xml
+++ b/app/src/main/res/layout/activity_settings.xml
@@ -366,6 +366,12 @@
android:layout_height="wrap_content"
android:text="Pair OUI-SPY board (Bluetooth)" />
+ <com.google.android.material.switchmaterial.SwitchMaterial
+ android:id="@+id/ouiSpyRelaySwitch"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="OUI-SPY: relay every network and Bluetooth device it hears, so RF Sentinel's own lists check them (the board also sends standard Wi-Fi scan probes)" />
+
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/autoRecordSwitch"
android:layout_width="match_parent"
diff --git a/app/src/test/java/com/rfsentinel/app/esp/OuiSpyBleProtocolTest.kt b/app/src/test/java/com/rfsentinel/app/esp/OuiSpyBleProtocolTest.kt
index 84a1b77..86cf05f 100644
--- a/app/src/test/java/com/rfsentinel/app/esp/OuiSpyBleProtocolTest.kt
+++ b/app/src/test/java/com/rfsentinel/app/esp/OuiSpyBleProtocolTest.kt
@@ -84,16 +84,37 @@ class OuiSpyBleProtocolTest {
fun skipsOldUnusedAndShortFrames() {
// Detected while no phone was connected (DET_FLAG_AWAY).
assertNull(OuiSpyBleProtocol.decode(header(70, 0x80 or OuiSpyBleProtocol.ENGINE_FLOCK_WIFI, mac, -70, 6, 4).array()))
- // Engines RF Sentinel doesn't use (5 = UniPwn, 6 = Wardrive, 7 = PCAP).
- for (e in 5..7) assertNull(OuiSpyBleProtocol.decode(header(74, e, mac, -70, 6, 0).array()))
+ // Engines RF Sentinel doesn't use (3 = Foxhunter, 5 = UniPwn, 7 = PCAP).
+ for (e in listOf(3, 5, 7)) assertNull(OuiSpyBleProtocol.decode(header(74, e, mac, -70, 6, 0).array()))
assertNull(OuiSpyBleProtocol.decode(ByteArray(10)))
assertTrue(OuiSpyBleProtocol.isSpoolHeader(byteArrayOf(0xFF.toByte(), 2, 0, 0, 0, 1, 2, 3, 4)))
assertTrue(OuiSpyBleProtocol.isSpoolEnd(byteArrayOf(0xFE.toByte())))
}
+ @Test
+ fun surveyRelaysPlainNetworksAndDevices() {
+ val ap = header(74, OuiSpyBleProtocol.ENGINE_WARDRIVE, mac, -67, 11, 0)
+ str(ap, 19, "Cafe Guest"); ap.put(52, 3)
+ val a = OuiSpyBleProtocol.decode(ap.array())!!
+ assertFalse(a.ble)
+ assertEquals("Cafe Guest", a.name)
+ assertEquals(2462, a.frequencyMhz)
+ assertEquals("[WPA2-PSK][ESS]", a.capabilities)
+ assertTrue(a.hits.isEmpty()) // RF Sentinel's own lists decide
+
+ val dev = header(74, OuiSpyBleProtocol.ENGINE_WARDRIVE, mac, -58, 0, 1)
+ str(dev, 53, "Speaker")
+ val b = OuiSpyBleProtocol.decode(dev.array())!!
+ assertTrue(b.ble)
+ assertEquals("Speaker", b.name)
+ assertTrue(b.hits.isEmpty())
+ }
+
@Test
fun onlyDetectionEnginesAreEverEnabled() {
assertEquals(listOf(1, 2, 4, 0), OuiSpyBleProtocol.ENGINES)
+ assertEquals(listOf(1, 2, 4, 0, 6), OuiSpyBleProtocol.engines(relayAll = true))
+ assertEquals(listOf(1, 2, 4, 0), OuiSpyBleProtocol.engines(relayAll = false))
assertArrayEquals(byteArrayOf(0x01, 0x02), OuiSpyBleProtocol.enable(2))
assertArrayEquals(byteArrayOf(0x0F, 0x00), OuiSpyBleProtocol.disableAll())
}