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
OUI-SPY over Bluetooth (App-Controlled firmware)
CIS-C0b199b183492f
diff --git a/README.md b/README.mdindex dfbcb79..05c21c4 100644--- a/README.md+++ b/README.md@@ -267,6 +267,18 @@ USB chip work. RF Sentinel only listens: it never sends OUI-Spy anything, andonly asks GhostESP to scan and list networks. Settings shows the board'sstatus.+### OUI-SPY over Bluetooth (no cable)++Boards running the Bluetooth ("App-Controlled") OUI-SPY firmware+([lukeswitz/oui-spy-unified-blue](https://github.com/lukeswitz/oui-spy-unified-blue))+connect wirelessly: start scanning with the board powered on, then+**Settings -> Pair OUI-SPY board** and pick its `OUI-SPY-xxxx` entry. While+scanning, RF Sentinel switches on the board's Flock-BLE, Flock-WiFi, Sky Spy and+Detector engines, adds what they find (Flock cameras and Raven sensors, Remote+ID drones with position, trackers, Axon and smart-glasses signatures, the+board's own watchlist), and switches them off again when scanning stops. It+never uses the board's other engines.+## ThemesPick a theme in the setup wizard or under **Settings → Appearance**.diff --git a/app/src/main/java/com/rfsentinel/app/esp/OuiSpyBle.kt b/app/src/main/java/com/rfsentinel/app/esp/OuiSpyBle.ktnew file mode 100644index 0000000..b5d81ef--- /dev/null+++ b/app/src/main/java/com/rfsentinel/app/esp/OuiSpyBle.kt@@ -0,0 +1,204 @@+package com.rfsentinel.app.esp++import android.annotation.SuppressLint+import android.bluetooth.BluetoothDevice+import android.bluetooth.BluetoothGatt+import android.bluetooth.BluetoothGattCallback+import android.bluetooth.BluetoothGattCharacteristic+import android.bluetooth.BluetoothGattDescriptor+import android.bluetooth.BluetoothManager+import android.bluetooth.BluetoothProfile+import android.content.Context+import android.os.Build+import android.os.Handler+import android.os.Looper+import android.util.Log+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+ * Detection Events, and switches them off again when scanning stops. No cable+ * needed; the board just needs power. Reconnects when the board comes back.+ */+object OuiSpyBle {++ private const val TAG = "OuiSpyBle"+ private const val MTU = 247 // detections are up to 155 bytes+ private const val RECONNECT_MS = 8_000L++ private val main = Handler(Looper.getMainLooper())+ private var gatt: BluetoothGatt? = null+ private var appContext: Context? = null+ private var address: String? = null+ private var onSightings: ((List<EspSighting>) -> Unit)? = null+ @Volatile private var active = false+ private var inSpool = false+ private var detections = 0+ /** GATT writes must be sent one at a time. */+ private val pending = ArrayDeque<ByteArray>()++ @Volatile var status: String = ""+ private set+ var onStatusChanged: (() -> Unit)? = null++ private fun setStatus(s: String) { status = s; onStatusChanged?.invoke() }++ fun canConnect(context: Context) = Build.VERSION.SDK_INT < 31 ||+ 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 {+ onSightings = sightings+ if (active && address == boardAddress) return@post+ stopNow()+ appContext = context.applicationContext+ address = boardAddress+ active = true+ connect()+ }++ fun stop() = main.post { stopNow() }++ @SuppressLint("MissingPermission") // checked by canConnect()+ private fun stopNow() {+ active = false+ main.removeCallbacksAndMessages(null)+ val g = gatt ?: return+ // Switch our engines off so the board goes quiet, then let go.+ val ctl = g.getService(OuiSpyBleProtocol.SERVICE)?.getCharacteristic(OuiSpyBleProtocol.ENGINE_CONTROL)+ if (ctl != null) runCatching { write(g, ctl, OuiSpyBleProtocol.disableAll()) }+ main.postDelayed({ runCatching { g.disconnect(); g.close() } }, 300)+ gatt = null+ setStatus("")+ }++ @SuppressLint("MissingPermission")+ private fun connect() {+ val ctx = appContext ?: return+ val addr = address ?: return+ if (!active) return+ if (!canConnect(ctx)) { setStatus("OUI-SPY: allow \"Nearby devices\" to connect to the board"); return }+ val adapter = ctx.getSystemService(BluetoothManager::class.java)?.adapter ?: return+ if (!adapter.isEnabled) { setStatus("OUI-SPY: Bluetooth is off"); retry(); return }+ val device = runCatching { adapter.getRemoteDevice(addr) }.getOrNull() ?: return+ setStatus("OUI-SPY: connecting…")+ gatt = device.connectGatt(ctx, false, callback, BluetoothDevice.TRANSPORT_LE)+ }++ private fun retry() {+ if (!active) return+ main.removeCallbacksAndMessages(null)+ main.postDelayed({ connect() }, RECONNECT_MS)+ }++ @SuppressLint("MissingPermission")+ private fun write(g: BluetoothGatt, c: BluetoothGattCharacteristic, value: ByteArray) {+ if (Build.VERSION.SDK_INT >= 33) {+ g.writeCharacteristic(c, value, BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT)+ } else {+ @Suppress("DEPRECATION")+ c.value = value+ @Suppress("DEPRECATION")+ g.writeCharacteristic(c)+ }+ }++ @SuppressLint("MissingPermission")+ private fun writeNext(g: BluetoothGatt) {+ val next = pending.removeFirstOrNull() ?: run {+ setStatus("OUI-SPY · live · Flock, Sky Spy and Detector engines on")+ return+ }+ val ctl = g.getService(OuiSpyBleProtocol.SERVICE)?.getCharacteristic(OuiSpyBleProtocol.ENGINE_CONTROL) ?: return+ write(g, ctl, next)+ }++ private fun handle(value: ByteArray) {+ when {+ OuiSpyBleProtocol.isSpoolHeader(value) -> { inSpool = true; return }+ OuiSpyBleProtocol.isSpoolEnd(value) -> { inSpool = false; return }+ inSpool -> return // stored while no phone was connected: old, no location+ }+ val s = OuiSpyBleProtocol.decode(value) ?: return+ detections+++ onSightings?.invoke(listOf(s))+ setStatus("OUI-SPY · live · $detections detection${if (detections == 1) "" else "s"}")+ }++ private val callback = object : BluetoothGattCallback() {+ @SuppressLint("MissingPermission")+ override fun onConnectionStateChange(g: BluetoothGatt, st: Int, newState: Int) {+ main.post {+ if (g !== gatt) return@post+ if (newState == BluetoothProfile.STATE_CONNECTED) {+ setStatus("OUI-SPY: connected, setting up…")+ if (!g.requestMtu(MTU)) g.discoverServices()+ } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {+ runCatching { g.close() }+ gatt = null+ if (active) { setStatus("OUI-SPY: out of reach - reconnecting…"); retry() }+ }+ }+ }++ @SuppressLint("MissingPermission")+ override fun onMtuChanged(g: BluetoothGatt, mtu: Int, st: Int) {+ main.post { if (g === gatt) g.discoverServices() }+ }++ @SuppressLint("MissingPermission")+ override fun onServicesDiscovered(g: BluetoothGatt, st: Int) {+ main.post {+ if (g !== gatt) return@post+ val svc = g.getService(OuiSpyBleProtocol.SERVICE)+ val det = svc?.getCharacteristic(OuiSpyBleProtocol.DETECTION_EVENTS)+ if (det == null) {+ setStatus("OUI-SPY: this board's firmware isn't the Bluetooth (App-Controlled) version")+ return@post+ }+ g.setCharacteristicNotification(det, true)+ val cccd = det.getDescriptor(OuiSpyBleProtocol.CCCD) ?: return@post+ if (Build.VERSION.SDK_INT >= 33) {+ g.writeDescriptor(cccd, BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE)+ } else {+ @Suppress("DEPRECATION")+ cccd.value = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE+ @Suppress("DEPRECATION")+ g.writeDescriptor(cccd)+ }+ }+ }++ override fun onDescriptorWrite(g: BluetoothGatt, d: BluetoothGattDescriptor, st: Int) {+ main.post {+ if (g !== gatt) return@post+ inSpool = false+ pending.clear()+ OuiSpyBleProtocol.ENGINES.forEach { pending.addLast(OuiSpyBleProtocol.enable(it)) }+ writeNext(g)+ }+ }++ override fun onCharacteristicWrite(g: BluetoothGatt, c: BluetoothGattCharacteristic, st: Int) {+ main.post {+ if (g !== gatt) return@post+ if (st != BluetoothGatt.GATT_SUCCESS) Log.w(TAG, "engine write failed: $st")+ writeNext(g)+ }+ }++ override fun onCharacteristicChanged(g: BluetoothGatt, c: BluetoothGattCharacteristic, value: ByteArray) {+ if (c.uuid == OuiSpyBleProtocol.DETECTION_EVENTS) main.post { handle(value) }+ }++ @Deprecated("Android 12 and older")+ @Suppress("DEPRECATION")+ override fun onCharacteristicChanged(g: BluetoothGatt, c: BluetoothGattCharacteristic) {+ if (Build.VERSION.SDK_INT >= 33) return+ val v = c.value ?: return+ if (c.uuid == OuiSpyBleProtocol.DETECTION_EVENTS) main.post { handle(v) }+ }+ }+}diff --git a/app/src/main/java/com/rfsentinel/app/esp/OuiSpyBleProtocol.kt b/app/src/main/java/com/rfsentinel/app/esp/OuiSpyBleProtocol.ktnew file mode 100644index 0000000..80a813b--- /dev/null+++ b/app/src/main/java/com/rfsentinel/app/esp/OuiSpyBleProtocol.kt@@ -0,0 +1,138 @@+package com.rfsentinel.app.esp++import com.rfsentinel.app.detect.Category+import com.rfsentinel.app.detect.Hit+import com.rfsentinel.app.detect.RemoteId+import java.nio.ByteBuffer+import java.nio.ByteOrder+import java.util.UUID++/**+ * The Bluetooth protocol of OUI-SPY "App-Controlled" firmware+ * (lukeswitz/oui-spy-unified-blue, src/protocol.h + ble_gatt.cpp), as far as+ * RF Sentinel uses it: switching detection engines on/off and decoding the+ * detection notifications. Pure Kotlin; unit-tested with packets laid out like+ * the firmware's packDetection().+ */+object OuiSpyBleProtocol {++ private const val BASE = "-0a15-4b70-ba00-c010ae1ba01c"+ val SERVICE: UUID = UUID.fromString("00000001$BASE")+ val DEVICE_INFO: UUID = UUID.fromString("00000001$BASE")+ val ENGINE_CONTROL: UUID = UUID.fromString("00000002$BASE")+ val DETECTION_EVENTS: UUID = UUID.fromString("00000010$BASE")+ val CCCD: UUID = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb")++ /** Name prefix the boards advertise ("OUI-SPY-xxxx", "OUI-SPY-MGR-...") */+ const val NAME_PREFIX = "OUI-SPY"++ // Engine IDs (protocol.h EngineId).+ const val ENGINE_DETECTOR = 0+ const val ENGINE_FLOCK_BLE = 1+ const val ENGINE_FLOCK_WIFI = 2+ const val ENGINE_SKYSPY = 4++ /** Only passive detection engines; RF Sentinel never touches the others. */+ val ENGINES = listOf(ENGINE_FLOCK_BLE, ENGINE_FLOCK_WIFI, ENGINE_SKYSPY, ENGINE_DETECTOR)++ 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. */+ fun disableAll(): ByteArray = byteArrayOf(0x0F, 0x00)++ const val SOURCE = "OUI-SPY board over Bluetooth"++ /** Offline-spool frames: a 9-byte header starting 0xFF and a 1-byte 0xFE end marker. */+ fun isSpoolHeader(d: ByteArray) = d.size == 9 && d[0] == 0xFF.toByte()+ fun isSpoolEnd(d: ByteArray) = d.size == 1 && d[0] == 0xFE.toByte()++ /** Decodes one Detection Events notification, or null for frames RF Sentinel doesn't use. */+ fun decode(d: ByteArray): EspSighting? {+ if (d.size < 19) return null+ val raw = d[0].toInt() and 0xFF+ if (raw and 0x80 != 0) return null // detected while no phone was connected (old)+ val engine = raw and 0x7F+ val mac = (1..6).joinToString(":") { "%02X".format(d[it].toInt() and 0xFF) }+ val rssi = d[7].toInt()+ val channel = d[8].toInt() and 0xFF+ val method = d[13].toInt() and 0xFF+ val b = ByteBuffer.wrap(d).order(ByteOrder.LITTLE_ENDIAN)+ return when (engine) {+ 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)+ else -> null+ }+ }++ private fun text(d: ByteArray, from: Int, len: Int): String? {+ if (d.size < from + len) return null+ val end = (from until from + len).firstOrNull { d[it] == 0.toByte() } ?: (from + len)+ return String(d, from, end - from, Charsets.UTF_8).trim().takeIf { it.isNotEmpty() }+ }++ private fun freq(channel: Int) = when (channel) {+ 0 -> 0+ 14 -> 2484+ in 1..13 -> 2407 + channel * 5+ else -> 5000 + channel * 5+ }++ private fun flock(engine: Int, d: ByteArray, mac: String, rssi: Int, channel: Int, method: Int): EspSighting {+ val wifi = engine == ENGINE_FLOCK_WIFI+ val isRaven = d.size > 19 && d[19] != 0.toByte()+ val name = text(d, 37, 32)+ val hit = when {+ isRaven -> Hit(Category.AUDIO_SENSOR, "Raven gunshot sensor (Flock)", 85,+ "Reported by OUI-SPY: Raven service" + (text(d, 20, 16)?.let { ", firmware $it" } ?: ""), SOURCE)+ wifi && method >= 4 -> Hit(Category.ALPR, "Flock camera (wildcard probe)", 80,+ "Reported by OUI-SPY: Flock-style network probe", SOURCE)+ wifi && method == 3 -> Hit(Category.ALPR, "Flock camera (Wi-Fi name)", 80,+ "Reported by OUI-SPY: Flock network name" + (name?.let { " \"$it\"" } ?: ""), SOURCE)+ wifi -> Hit(Category.ALPR, "Possible Flock equipment", 45,+ "Reported by OUI-SPY: Flock radio-module address (common chip, weak)", SOURCE)+ method == 1 -> Hit(Category.ALPR, "Flock equipment (Bluetooth name)", 80,+ "Reported by OUI-SPY: Flock / Penguin device name" + (name?.let { " \"$it\"" } ?: ""), SOURCE)+ else -> Hit(Category.ALPR, "Flock equipment (Bluetooth)", 70,+ "Reported by OUI-SPY Flock-BLE (method $method)", SOURCE)+ }+ return EspSighting(+ mac = mac, rssi = rssi, ble = !wifi, name = if (wifi) null else name,+ frequencyMhz = if (wifi) freq(channel) else 0, hits = listOf(hit)+ )+ }++ private fun drone(d: ByteArray, b: ByteBuffer, mac: String, rssi: Int, method: Int): EspSighting {+ fun coord(at: Int) = b.getDouble(at).takeIf { it != 0.0 && it.isFinite() }+ val info = RemoteId.Info(+ uasId = text(d, 19, 21),+ latitude = coord(61), longitude = coord(69),+ altitudeGeoM = b.getShort(77).toDouble(),+ heightM = b.getShort(79).toDouble(),+ operatorLatitude = coord(85), operatorLongitude = coord(93),+ selfIdDescription = text(d, 101, 24)+ )+ val via = when (method) { 0 -> "Bluetooth"; 1 -> "Wi-Fi NAN"; else -> "Wi-Fi beacon" }+ return EspSighting(+ mac = mac, rssi = rssi, ble = method == 0, remoteId = info,+ hits = listOf(Hit(Category.DRONE, "Drone broadcasting Remote ID", 95,+ "Reported by OUI-SPY Sky Spy ($via)" + (info.uasId?.let { ", ID $it" } ?: ""), SOURCE))+ )+ }++ private fun detector(d: ByteArray, mac: String, rssi: Int, channel: Int, method: Int): EspSighting {+ val desc = text(d, 20, 32)+ val hit = when (method) {+ 2 -> Hit(Category.TRACKER, "Tracker following you (OUI-SPY)", 75,+ "Reported by OUI-SPY Detector" + (desc?.let { ": $it" } ?: ""), SOURCE)+ 7 -> Hit(Category.GLASSES, "Smart glasses", 70, "Reported by OUI-SPY Detector (glasses signature)", SOURCE)+ 8 -> Hit(Category.BODY_CAM, "Axon equipment", 75, "Reported by OUI-SPY Detector (Axon signature)", SOURCE)+ 0, 1 -> Hit(Category.CUSTOM, "OUI-SPY target" + (desc?.let { ": $it" } ?: ""), 70,+ "Matched the watchlist set on the OUI-SPY board", SOURCE)+ else -> null // Flipper, Pwnagotchi, deauth / probe floods: outside RF Sentinel's scope+ }+ val wifi = method == 1 || method == 4 || method == 5+ return EspSighting(mac = mac, rssi = rssi, ble = !wifi,+ frequencyMhz = if (wifi) freq(channel) else 0, hits = listOfNotNull(hit))+ }+}diff --git a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.ktindex ce6e7e5..7fae64c 100644--- a/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt+++ b/app/src/main/java/com/rfsentinel/app/service/ScanForegroundService.kt@@ -241,6 +241,10 @@ class ScanForegroundService : Service() {if (Prefs.wifiEnabled(this)) startWifiPolling() else stopWifiPolling()// ESP32 boards on USB (OUI-Spy / GhostESP): their reports join the same pipeline.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.stop()updateLocationUpdates()startHousekeeping()startCellChecks()@@ -730,6 +734,7 @@ class ScanForegroundService : Service() {override fun onDestroy() {com.rfsentinel.app.esp.EspBoards.stop(this)+ com.rfsentinel.app.esp.OuiSpyBle.stop()bleEngine.stop()wifiEngine.stop()if (btStateReceiverRegistered) {diff --git a/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt b/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.ktindex daa980b..dc5ef00 100644--- a/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt+++ b/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt@@ -112,11 +112,63 @@ class SettingsActivity : AppCompatActivity() {binding.trackerIgnoreButton.visibility = if (n > 0 || paused) android.view.View.VISIBLE else android.view.View.GONE}- /** ESP32 boards on USB (OUI-Spy / GhostESP) are picked up while scanning. */+ /** ESP32 boards on USB (OUI-Spy / GhostESP) and an OUI-SPY board over Bluetooth. */private fun updateEspStatus() {val s = com.rfsentinel.app.esp.EspBoards.statusbinding.espStatusText.text = "ESP32 on USB (OUI-Spy or GhostESP): " +s.ifBlank { "plug one in with an OTG cable while scanning to add its detections" }+ val board = Prefs.ouiSpyBoard(this)+ binding.ouiSpyText.text = if (board == null)+ "OUI-SPY over Bluetooth (App-Controlled firmware): not paired"+ else "OUI-SPY board $board: " + com.rfsentinel.app.esp.OuiSpyBle.status.ifBlank { "connects while scanning" }+ binding.ouiSpyButton.text = if (board == null) "Pair OUI-SPY board (Bluetooth)" else "Change or forget OUI-SPY board"+ }++ private val ouiSpyConnectPermission = registerForActivityResult(+ androidx.activity.result.contract.ActivityResultContracts.RequestPermission()+ ) { granted -> if (granted) pairOuiSpy() }++ /**+ * Picks the OUI-SPY board among nearby devices RF Sentinel hears (they+ * advertise as "OUI-SPY-xxxx"); scanning must be running to see it.+ */+ private fun pairOuiSpy() {+ if (!com.rfsentinel.app.esp.OuiSpyBle.canConnect(this)) {+ ouiSpyConnectPermission.launch(android.Manifest.permission.BLUETOOTH_CONNECT); return+ }+ val boards = com.rfsentinel.app.service.DeviceRegistry.snapshot()+ .filter { it.name?.startsWith(com.rfsentinel.app.esp.OuiSpyBleProtocol.NAME_PREFIX) == true }+ .sortedByDescending { it.rssi }+ val current = Prefs.ouiSpyBoard(this)+ val labels = boards.map { "${it.name} (${it.mac}, ${it.rssi} dBm)" }.toMutableList()+ if (current != null) labels += "Forget the paired board"+ if (labels.isEmpty()) {+ AlertDialog.Builder(this)+ .setTitle("No OUI-SPY board heard")+ .setMessage("Power the board (Bluetooth / App-Controlled firmware) and start scanning, " ++ "then come back here: it shows up as \"OUI-SPY-xxxx\".")+ .setPositiveButton("OK", null)+ .show()+ return+ }+ AlertDialog.Builder(this)+ .setTitle("Which OUI-SPY board?")+ .setItems(labels.toTypedArray()) { _, i ->+ if (i < boards.size) {+ Prefs.setOuiSpyBoard(this, boards[i].mac)+ Toast.makeText(this, "Paired - RF Sentinel connects to it while scanning", Toast.LENGTH_LONG).show()+ } else {+ Prefs.setOuiSpyBoard(this, null)+ com.rfsentinel.app.esp.OuiSpyBle.stop()+ }+ updateEspStatus()+ // Apply to a running scan right away.+ if (com.rfsentinel.app.service.ScanForegroundService.isRunning) {+ com.rfsentinel.app.service.ScanForegroundService.start(this)+ }+ }+ .setNegativeButton("Cancel", null)+ .show()}private fun updateBannerButtons() {@@ -125,6 +177,7 @@ class SettingsActivity : AppCompatActivity() {override fun onDestroy() {com.rfsentinel.app.esp.EspBoards.onStatusChanged = null+ com.rfsentinel.app.esp.OuiSpyBle.onStatusChanged = nullstopObservingPrefetch?.invoke()super.onDestroy()}@@ -253,6 +306,8 @@ class SettingsActivity : AppCompatActivity() {updateTrackerIgnoreText()updateEspStatus()com.rfsentinel.app.esp.EspBoards.onStatusChanged = { runOnUiThread { updateEspStatus() } }+ com.rfsentinel.app.esp.OuiSpyBle.onStatusChanged = { runOnUiThread { updateEspStatus() } }+ binding.ouiSpyButton.setOnClickListener { pairOuiSpy() }binding.trackerIgnoreButton.setOnClickListener {com.rfsentinel.app.data.TrackerMutes.clear(this)Prefs.setTrackerFollowPausedUntil(this, 0L)diff --git a/app/src/main/java/com/rfsentinel/app/util/Prefs.kt b/app/src/main/java/com/rfsentinel/app/util/Prefs.ktindex 46b9909..398c1ea 100644--- a/app/src/main/java/com/rfsentinel/app/util/Prefs.kt+++ b/app/src/main/java/com/rfsentinel/app/util/Prefs.kt@@ -114,6 +114,11 @@ object Prefs {/** Tracker "following you" warnings paused until this time (epoch ms). */fun trackerFollowPausedUntil(context: Context): Long = sp(context).getLong("tracker_follow_paused_until", 0L)fun setTrackerFollowPausedUntil(context: Context, value: Long) = sp(context).edit { putLong("tracker_follow_paused_until", value) }+ /** Bluetooth address of the OUI-SPY board to connect to while scanning (null = none). */+ fun ouiSpyBoard(context: Context): String? = sp(context).getString("ouispy_board", null)+ fun setOuiSpyBoard(context: Context, address: String?) = sp(context).edit {+ if (address == null) remove("ouispy_board") else putString("ouispy_board", address)+ }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.xmlindex 86f0483..e66b62f 100644--- a/app/src/main/res/layout/activity_settings.xml+++ b/app/src/main/res/layout/activity_settings.xml@@ -353,6 +353,19 @@android:paddingTop="6dp"android:textSize="12sp" />+ <TextView+ android:id="@+id/ouiSpyText"+ style="@style/SettingsLabel"+ android:paddingTop="6dp"+ android:textSize="12sp" />++ <Button+ android:id="@+id/ouiSpyButton"+ style="@style/Widget.MaterialComponents.Button.TextButton"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:text="Pair OUI-SPY board (Bluetooth)" />+<com.google.android.material.switchmaterial.SwitchMaterialandroid: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.ktnew file mode 100644index 0000000..84a1b77--- /dev/null+++ b/app/src/test/java/com/rfsentinel/app/esp/OuiSpyBleProtocolTest.kt@@ -0,0 +1,100 @@+package com.rfsentinel.app.esp++import com.rfsentinel.app.detect.Category+import org.junit.Assert.assertArrayEquals+import org.junit.Assert.assertEquals+import org.junit.Assert.assertFalse+import org.junit.Assert.assertNull+import org.junit.Assert.assertTrue+import org.junit.Test+import java.nio.ByteBuffer+import java.nio.ByteOrder++/** Packets laid out like packDetection() in the OUI-SPY firmware (made-up values). */+class OuiSpyBleProtocolTest {++ private fun header(size: Int, engine: Int, mac: IntArray, rssi: Int, ch: Int, method: Int): ByteBuffer {+ val b = ByteBuffer.allocate(size).order(ByteOrder.LITTLE_ENDIAN)+ b.put(0, engine.toByte())+ mac.forEachIndexed { i, v -> b.put(1 + i, v.toByte()) }+ b.put(7, rssi.toByte()); b.put(8, ch.toByte())+ b.putInt(9, 123456); b.put(13, method.toByte())+ return b+ }++ private fun str(b: ByteBuffer, at: Int, s: String) = s.toByteArray().forEachIndexed { i, v -> b.put(at + i, v) }++ private val mac = intArrayOf(0x70, 0xC9, 0x4E, 0x11, 0x22, 0x33)++ @Test+ fun flockWifiWildcardProbe() {+ val b = header(70, OuiSpyBleProtocol.ENGINE_FLOCK_WIFI, mac, -70, 6, 4)+ val s = OuiSpyBleProtocol.decode(b.array())!!+ assertEquals("70:C9:4E:11:22:33", s.mac)+ assertFalse(s.ble)+ assertEquals(2437, s.frequencyMhz)+ assertEquals(Category.ALPR, s.hits.single().category)+ assertEquals(80, s.hits.single().confidence)+ }++ @Test+ fun flockBleNameAndRaven() {+ val b = header(70, OuiSpyBleProtocol.ENGINE_FLOCK_BLE, mac, -60, 0, 1)+ str(b, 37, "Penguin-1234567890")+ val s = OuiSpyBleProtocol.decode(b.array())!!+ assertTrue(s.ble)+ assertEquals("Penguin-1234567890", s.name)+ assertEquals(Category.ALPR, s.hits.single().category)++ val r = header(70, OuiSpyBleProtocol.ENGINE_FLOCK_BLE, mac, -60, 0, 3)+ r.put(19, 1); str(r, 20, "1.3.1")+ assertEquals(Category.AUDIO_SENSOR, OuiSpyBleProtocol.decode(r.array())!!.hits.single().category)+ }++ @Test+ fun skySpyDroneWithPositions() {+ val b = header(155, OuiSpyBleProtocol.ENGINE_SKYSPY, intArrayOf(0x60, 0x60, 0x1F, 1, 2, 3), -80, 0, 0)+ str(b, 19, "1581F5FJD123")+ b.putDouble(61, 10.5010); b.putDouble(69, -20.5020)+ b.putShort(77, 130); b.putShort(79, 60)+ b.putDouble(85, 10.5000); b.putDouble(93, -20.5000)+ val s = OuiSpyBleProtocol.decode(b.array())!!+ val rid = s.remoteId!!+ assertEquals("1581F5FJD123", rid.uasId)+ assertEquals(10.501, rid.latitude!!, 1e-9)+ assertEquals(-20.5, rid.operatorLongitude!!, 1e-9)+ assertEquals(60.0, rid.heightM!!, 0.0)+ assertEquals(Category.DRONE, s.hits.single().category)+ }++ @Test+ fun detectorSignaturesAndWatchlist() {+ val axon = header(52, OuiSpyBleProtocol.ENGINE_DETECTOR, intArrayOf(0x00, 0x25, 0xDF, 1, 2, 3), -55, 0, 8)+ assertEquals(Category.BODY_CAM, OuiSpyBleProtocol.decode(axon.array())!!.hits.single().category)++ val watch = header(52, OuiSpyBleProtocol.ENGINE_DETECTOR, mac, -55, 0, 0)+ str(watch, 20, "Patrol car radio")+ assertEquals("OUI-SPY target: Patrol car radio", OuiSpyBleProtocol.decode(watch.array())!!.hits.single().label)++ val flipper = header(52, OuiSpyBleProtocol.ENGINE_DETECTOR, mac, -55, 0, 3)+ assertTrue(OuiSpyBleProtocol.decode(flipper.array())!!.hits.isEmpty()) // outside RF Sentinel's scope+ }++ @Test+ 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()))+ 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 onlyDetectionEnginesAreEverEnabled() {+ assertEquals(listOf(1, 2, 4, 0), OuiSpyBleProtocol.ENGINES)+ assertArrayEquals(byteArrayOf(0x01, 0x02), OuiSpyBleProtocol.enable(2))+ assertArrayEquals(byteArrayOf(0x0F, 0x00), OuiSpyBleProtocol.disableAll())+ }+}