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
Release 2.13.0: five more USB WiFi drivers, FREE-WiLi 2, adapter log export
CIS-C06c015711477a
diff --git a/README.md b/README.mdindex 49c9dc9..d3be974 100644--- a/README.md+++ b/README.md@@ -75,7 +75,7 @@|---|---|| **What** | A non-rooted Android app that lists every Bluetooth LE and WiFi device around you with its vendor, type and signal, and flags law-enforcement and surveillance equipment || **How** | Receive-only: reads advertisements, beacons and cell info that devices broadcast publicly. Never transmits to, connects to or jams anything |-| **Runs on** | Android 8.0+ phones, Android Auto, plus optional ESP32 boards (OUI-Spy, GhostESP, Marauder, Flipper Zero + BFFB) |+| **Runs on** | Android 8.0+ phones, Android Auto, plus optional ESP32 boards (OUI-Spy, GhostESP, Marauder, Flipper Zero + BFFB, FREE-WiLi 2) and USB WiFi adapters || **Costs** | Nothing. GPL-3.0, no ads, no account, no subscription, no analytics |## What it detects@@ -141,7 +141,7 @@ Every match shows its evidence, its source and a confidence tier: **weak** (< 50**Hardware**- ESP32 boards over USB OTG (OUI-Spy, GhostESP, Marauder incl. dual-band ESP32-C5 boards, or through a Flipper Zero) or Bluetooth (OUI-SPY App-Controlled) add their detections and extend range-- **USB WiFi adapters in monitor mode** over OTG, no root: RTL8811AU / RTL8821AU (e.g. ALFA AWUS036ACS, 2.4 GHz) and **RTL8812BU / RTL8822BU** (2.4 + 5 GHz, e.g. TP-Link Archer T3U, Wise Tiger AC1200). No Android scan limit, longer range, and **client devices** (laptops, phones, cameras connected to a network) the phone's WiFi scan can't see. Single-antenna dongles are detected and handled automatically+- **USB WiFi adapters in monitor mode** over OTG, no root: RTL8811AU / RTL8821AU (e.g. ALFA AWUS036ACS, 2.4 GHz), **RTL8812BU / RTL8822BU** (2.4 + 5 GHz, e.g. TP-Link Archer T3U, Wise Tiger AC1200), **RTL8814AU** (ALFA AWUS1900, 2.4 + 5 GHz), **MT7612U** (ALFA AWUS036ACM, 2.4 + 5 GHz), **RTL8187** (ALFA AWUS036H), **RT3070** (ALFA AWUS036NH / NEH) and, experimental, **AR9271** (ALFA AWUS036NHA). No Android scan limit, longer range, and **client devices** (laptops, phones, cameras connected to a network) the phone's WiFi scan can't see. Single-antenna dongles are detected and handled automatically- **Requested networks:** the WiFi names nearby devices ask for (probe requests), from a USB adapter or a Marauder board, in an optional list; **watch** a name to get an alert whenever any device asks for it- **More from every frame:** WPS maker / model / device name, a **probe fingerprint** that survives MAC randomization (watchable: "every device of this type"), and the real name of **hidden networks** when a device joins them@@ -332,6 +332,7 @@ merges into the list with a blue **ESP32** badge.| [OUI-Spy](https://github.com/colonelpanichacks/oui-spy-unified-blue) (recommended) | USB | Flock-You, Detector and Sky Spy detections as they happen: Flock cameras, the board's watchlist matches, Remote ID drones with position || [OUI-SPY App-Controlled](https://github.com/lukeswitz/oui-spy-unified-blue) | Bluetooth | Flock-BLE, Flock-WiFi, Sky Spy, Detector and (optional) Wardrive survey engines || [GhostESP](https://github.com/GhostESP-Revival/GhostESP) | USB | The WiFi networks it scans, about every 10 s |+| [FREE-WiLi 2](https://freewili.com) | USB | The WiFi networks its ESP32-C5 scans from its console's WiFi menu (2.4 + 5 GHz) || [ESP32 Marauder](https://github.com/justcallmekoko/ESP32Marauder) | USB, or through a Flipper Zero | WiFi networks and client devices from its passive beacon and probe sniffers, batched every 2 s; on ESP32-C5 boards (Marauder v8, BFFB v2, LilyGo T-Dongle C5, C5 DevKit) both 2.4 and 5 GHz |Native-USB boards (ESP32-S2/S3/C3/C5/C6) and boards with a CP210x or CH340 bridge@@ -365,8 +366,8 @@ only. The board's UniPwn, PCAP and Foxhunter engines are never used.Plug a supported USB WiFi adapter into the phone with an OTG cable whilescanning and allow USB access on the prompt. RF Sentinel drives it directlyover Android's USB host API (no root, no kernel driver), puts it in-**receive-only monitor mode** and hops the channels (2.4 GHz on 88xxau; 2.4 GHz,-the common 5 GHz channels and the radar channels in rotation on 88x2bu). Access points+**receive-only monitor mode** and hops the channels (2.4 GHz on 88xxau, RTL8187,+RT3070 and AR9271; 2.4 GHz and 5 GHz on 88x2bu, 8814au and MT7612U). Access points(beacons, probe responses) and client devices (probe requests, data frames)go through RF Sentinel's own rules like everything else, with a purple**USB WIFI** badge.@@ -375,10 +376,18 @@ go through RF Sentinel's own rules like everything else, with a purple|---|---|---|| Realtek RTL8811AU / RTL8821AU (`0bda:0811`) | ALFA AWUS036ACS | Supported (2.4 GHz) || Realtek RTL8812BU / RTL8822BU (`0bda:b812`, `0bda:b82c` and ~35 other IDs) | TP-Link Archer T3U, ASUS USB-AC53/AC55/AC58, Edimax EW-7822U*, Wise Tiger AC1200 | Supported (2.4 + 5 GHz), tested on a Wise Tiger 8812BU |-| RTL8812AU, RTL8814AU, AR9271, MT7612U, RT3070, RTL8187 | AWUS036ACH, AWUS1900, AWUS036NHA... | Detected and named, not supported yet |--The adapter never transmits. Settings shows its status and can share its-driver log for troubleshooting.+| Realtek RTL8814AU (`0bda:8813` and 13 other IDs) | ALFA AWUS1900, TP-Link Archer T9UH, ASUS USB-AC68, Netgear A7000 | Supported (2.4 + 5 GHz), not yet tested on hardware |+| MediaTek MT7612U / MT7632U (`0e8d:7612` and 16 other IDs) | ALFA AWUS036ACM, ASUS USB-AC55, Netgear A6210 | Supported (2.4 + 5 GHz), not yet tested on hardware |+| Realtek RTL8187L / RTL8187B (`0bda:8187` and 20 other IDs) | ALFA AWUS036H, Netgear WG111v2/v3 | Supported (2.4 GHz), not yet tested on hardware |+| Ralink RT3070 (`148f:3070` and 4 other IDs) | ALFA AWUS036NH / AWUS036NEH | Supported (2.4 GHz), not yet tested on hardware |+| Atheros AR9271 (`0cf3:9271` and 17 other IDs) | ALFA AWUS036NHA, TP-Link TL-WN722N v1 | Experimental (2.4 GHz) |+| RTL8812AU, RTL8811CU / 8821CU, RT5370, MT7610U, AR7010 | AWUS036ACH... | Detected and named, not supported yet |++The adapter never transmits (on the MT7612U and RT3070 even the automatic ACK+replies are switched off).+Settings shows its status, and **Export USB WiFi adapter log** saves a text+file (app and phone version, the USB devices plugged in, the driver log) to+send to the developer - no nearby devices' addresses or network names are in it.On a single-antenna 8812BU dongle the antenna sits on one of the chip's tworeceive paths, while the chip hears 2.4 GHz beacons on path A only. RF Sentinel@@ -633,7 +642,13 @@ whose register tables come from Realtek's 88xxau Linux driverPMKID capture was left out. The RTL8812BU / RTL8822BU driver is ported from thereceive path of [devourer](https://github.com/OpenIPC/devourer) by OpenIPC(GPL-2.0), with the firmware and register tables from Realtek's rtl88x2bu-driver; every transmit path was left out. The map's anchored point layer follows+driver; every transmit path was left out. The RTL8814AU, MT7612U, RT3070 and+AR9271 drivers and the FREE-WiLi 2 reader are ported from Wardrive Go too+(checked against and fixed from the Linux rt2800usb, mt76x2u and ath9k_htc+drivers), and the RTL8187 driver from the Linux rtl8187 driver with Kismet's+Android PCAP Capture as the USB reference. Their firmware (Ralink rt2870.bin,+MediaTek mt7662, open ath9k_htc) is the unmodified linux-firmware images, with+their licences in `assets/usbwifi/`; see `usb/NOTICE.md`. The map's anchored point layer followsWardrive Go's approach - thank you.Part of the MAC-prefix data was cross-checked with, and extended from, the listsdiff --git a/app/build.gradle.kts b/app/build.gradle.ktsindex 3583c96..2d204c4 100644--- a/app/build.gradle.kts+++ b/app/build.gradle.kts@@ -6,8 +6,8 @@ plugins {}// Bump both for every release. versionName ends up in the APK file name.-val appVersionCode = 31-val appVersionName = "2.12.0"+val appVersionCode = 32+val appVersionName = "2.13.0"// Release signing credentials live in keystore.properties (git-ignored).// Without that file, release builds are produced unsigned.diff --git a/app/src/main/assets/usbwifi/LICENCE.open-ath9k-htc-firmware b/app/src/main/assets/usbwifi/LICENCE.open-ath9k-htc-firmwarenew file mode 100644index 0000000..36655b7--- /dev/null+++ b/app/src/main/assets/usbwifi/LICENCE.open-ath9k-htc-firmware@@ -0,0 +1,206 @@+This is a concatenation of LICENCE.txt and NOTICE.txt from the+open-ath9k-htc-firmware repository describing licensing terms for the+firmware image and its sources.++The source code repository is publicly available at+https://github.com/qca/open-ath9k-htc-firmware .+++LICENCE.txt+-----------++Files with a Qualcomm Atheros / Atheros licence fall under the following+licence. Please see NOTICES.TXT for information about other files in this+repository.++----++Copyright (c) 2013 Qualcomm Atheros, Inc.++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted (subject to the limitations in the+disclaimer below) provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above copyright+ notice, this list of conditions and the following disclaimer in the+ documentation and/or other materials provided with the+ distribution.++ * Neither the name of Qualcomm Atheros nor the names of its+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE+GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT+HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN+IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.++----+++NOTICE.TXT+----------++This NOTICE.TXT file contains certain notices of software components included+with the software that QUALCOMM ATHEROS Incorporated ('Qualcomm Atheros') is+required to provide you. Notwithstanding anything in the notices in this file,+your use of these software components together with the Qualcomm Atheros+software (Qualcomm Atheros software hereinafter referred to as 'Software') is+subject to the terms of your license from Qualcomm Atheros. Compliance with+all copyright laws and software license agreements included in the notice+section of this file are the responsibility of the user. Except as may be+granted by separate express written agreement, this file provides no license+to any Qualcomm Atheros patents, trademarks, copyrights, or other intellectual+property.++Copyright (c) 2013 QUALCOMM ATHEROS Incorporated. All rights reserved.++QUALCOMM ATHEROS� is a registered trademark and registered service mark of+QUALCOMM ATHEROS Incorporated. All other trademarks and service marks are+the property of their respective owners.++NOTICES:++/*+ * Copyright (c) 2005-2012 Atheros Communications Inc.+ *+ * Permission to use, copy, modify, and/or distribute this software for any+ * purpose with or without fee is hereby granted, provided that the above+ * copyright notice and this permission notice appear in all copies.+ *+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.+ */++/*+ * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting+ * Copyright (c) 2002-2005 Atheros Communications, Inc.+ * Copyright (c) 2008-2010, Atheros Communications Inc.+ *+ * Redistribution and use in source and binary forms are permitted+ * provided that the following conditions are met:+ * 1. The materials contained herein are unmodified and are used+ * unmodified.+ * 2. Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following NO+ * ''WARRANTY'' disclaimer below (''Disclaimer''), without+ * modification.+ * 3. Redistributions in binary form must reproduce at minimum a+ * disclaimer similar to the Disclaimer below and any redistribution+ * must be conditioned upon including a substantially similar+ * Disclaimer requirement for further binary redistribution.+ * 4. Neither the names of the above-listed copyright holders nor the+ * names of any contributors may be used to endorse or promote+ * product derived from this software without specific prior written+ * permission.+ *+ * NO WARRANTY+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+ * ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+ * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT,+ * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.+ * IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE+ * FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF+ * SUCH DAMAGES.+ */++----++The following files are from ECoS with a GPLv2 licence with modification+and linking caveats. Please see the licence below for more information:++target_firmware/magpie_fw_dev/build/magpie_1_1/sboot/cmnos/printf/src/cmnos_printf.c+target_firmware/magpie_fw_dev/target/cmnos/cmnos_printf.c+target_firmware/magpie_fw_dev/target/cmnos/k2_fw_cmnos_printf.c++//####ECOSGPLCOPYRIGHTBEGIN####+// -------------------------------------------+// This file is part of eCos, the Embedded Configurable Operating System.+// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.+// Copyright (C) 2002 Gary Thomas+//+// eCos is free software; you can redistribute it and/or modify it under+// the terms of the GNU General Public License as published by the Free+// Software Foundation; either version 2 or (at your option) any later version.+//+// eCos is distributed in the hope that it will be useful, but WITHOUT ANY+// WARRANTY; without even the implied warranty of MERCHANTABILITY or+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License+// for more details.+//+// You should have received a copy of the GNU General Public License along+// with eCos; if not, write to the Free Software Foundation, Inc.,+// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.+//+// As a special exception, if other files instantiate templates or use macros+// or inline functions from this file, or you compile this file and link it+// with other works to produce a work based on this file, this file does not+// by itself cause the resulting work to be covered by the GNU General Public+// License. However the source code for this file must still be made available+// in accordance with section (3) of the GNU General Public License.+//+// This exception does not invalidate any other reasons why a work based on+// this file might be covered by the GNU General Public License.+//+// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.+// at http://sources.redhat.com/ecos/ecos-license/+// -------------------------------------------+//####ECOSGPLCOPYRIGHTEND####++----++Some of the source code is sourced from Tensilica, Inc.++Although most of the files fall under the MIT licence, some of the source+files generated as part of the system development have a proprietary+Tensilica licence.++With permission from Tensilica, Inc, these files have been relicenced+under the following licence:++/*+ * Copyright (c) 2013 Tensilica Inc.+ *+ * Permission is hereby granted, free of charge, to any person obtaining+ * a copy of this software and associated documentation files (the+ * "Software"), to deal in the Software without restriction, including+ * without limitation the rights to use, copy, modify, merge, publish,+ * distribute, sublicense, and/or sell copies of the Software, and to+ * permit persons to whom the Software is furnished to do so, subject to+ * the following conditions:+ *+ * The above copyright notice and this permission notice shall be included+ * in all copies or substantial portions of the Software.+ *+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.+ */diff --git a/app/src/main/assets/usbwifi/LICENCE.ralink-firmware.txt b/app/src/main/assets/usbwifi/LICENCE.ralink-firmware.txtnew file mode 100644index 0000000..18dd038--- /dev/null+++ b/app/src/main/assets/usbwifi/LICENCE.ralink-firmware.txt@@ -0,0 +1,39 @@+Copyright (c) 2007, Ralink Technology Corporation+All rights reserved.++Redistribution. Redistribution and use in binary form, without+modification, are permitted provided that the following conditions are+met:++* Redistributions must reproduce the above copyright notice and the+ following disclaimer in the documentation and/or other materials+ provided with the distribution.+* Neither the name of Ralink Technology Corporation nor the names of its+ suppliers may be used to endorse or promote products derived from this+ software without specific prior written permission.+* No reverse engineering, decompilation, or disassembly of this software+ is permitted.++Limited patent license. Ralink Technology Corporation grants a world-wide,+royalty-free, non-exclusive license under patents it now or hereafter+owns or controls to make, have made, use, import, offer to sell and+sell ("Utilize") this software, but solely to the extent that any+such patent is necessary to Utilize the software alone, or in+combination with an operating system licensed under an approved Open+Source license as listed by the Open Source Initiative at+http://opensource.org/licenses. The patent license shall not apply to+any other combinations which include this software. No hardware per+se is licensed hereunder.++DISCLAIMER. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS+OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR+TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE+USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH+DAMAGE.diff --git a/app/src/main/assets/usbwifi/LICENCE.ralink_a_mediatek_company_firmware b/app/src/main/assets/usbwifi/LICENCE.ralink_a_mediatek_company_firmwarenew file mode 100644index 0000000..fef16b6--- /dev/null+++ b/app/src/main/assets/usbwifi/LICENCE.ralink_a_mediatek_company_firmware@@ -0,0 +1,39 @@+Copyright (c) 2013, Ralink, A MediaTek Company+All rights reserved.++Redistribution. Redistribution and use in binary form, without+modification, are permitted provided that the following conditions are+met:++* Redistributions must reproduce the above copyright notice and the+ following disclaimer in the documentation and/or other materials+ provided with the distribution.+* Neither the name of Ralink Technology Corporation nor the names of its+ suppliers may be used to endorse or promote products derived from this+ software without specific prior written permission.+* No reverse engineering, decompilation, or disassembly of this software+ is permitted.++Limited patent license. Ralink Technology Corporation grants a world-wide,+royalty-free, non-exclusive license under patents it now or hereafter+owns or controls to make, have made, use, import, offer to sell and+sell ("Utilize") this software, but solely to the extent that any+such patent is necessary to Utilize the software alone, or in+combination with an operating system licensed under an approved Open+Source license as listed by the Open Source Initiative at+http://opensource.org/licenses. The patent license shall not apply to+any other combinations which include this software. No hardware per+se is licensed hereunder.++DISCLAIMER. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND+CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS+OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR+TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE+USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH+DAMAGE.diff --git a/app/src/main/assets/usbwifi/htc_9271-1.4.0.fw b/app/src/main/assets/usbwifi/htc_9271-1.4.0.fwnew file mode 100644index 0000000..f815df6Binary files /dev/null and b/app/src/main/assets/usbwifi/htc_9271-1.4.0.fw differdiff --git a/app/src/main/assets/usbwifi/mt7662.bin b/app/src/main/assets/usbwifi/mt7662.binnew file mode 100644index 0000000..26c6fbbBinary files /dev/null and b/app/src/main/assets/usbwifi/mt7662.bin differdiff --git a/app/src/main/assets/usbwifi/mt7662_rom_patch.bin b/app/src/main/assets/usbwifi/mt7662_rom_patch.binnew file mode 100644index 0000000..10b245eBinary files /dev/null and b/app/src/main/assets/usbwifi/mt7662_rom_patch.bin differdiff --git a/app/src/main/assets/usbwifi/rt2870.bin b/app/src/main/assets/usbwifi/rt2870.binnew file mode 100644index 0000000..9ddac4aBinary files /dev/null and b/app/src/main/assets/usbwifi/rt2870.bin differdiff --git a/app/src/main/java/com/rfsentinel/app/esp/EspBoards.kt b/app/src/main/java/com/rfsentinel/app/esp/EspBoards.ktindex 14fd275..ba6f1ca 100644--- a/app/src/main/java/com/rfsentinel/app/esp/EspBoards.kt+++ b/app/src/main/java/com/rfsentinel/app/esp/EspBoards.kt@@ -93,7 +93,8 @@ object EspBoards {val conn = mgr.openDevice(d) ?: continueval port = SerialPort.open(conn, d)if (port == null) { runCatching { conn.close() }; setStatus("ESP32: couldn't open its USB serial port"); continue }- val reader = EspReader(port, ::setStatus) { list -> onSightings?.invoke(list) }+ val freeWili = SerialPort.chipOf(d.vendorId, d.productId) == SerialPort.Chip.FREEWILI+ val reader = EspReader(port, ::setStatus, freeWili) { list -> onSightings?.invoke(list) }val t = Thread({runCatching { reader.run() }runCatching { port.close() }diff --git a/app/src/main/java/com/rfsentinel/app/esp/EspReader.kt b/app/src/main/java/com/rfsentinel/app/esp/EspReader.ktindex 1927d16..31d49f2 100644--- a/app/src/main/java/com/rfsentinel/app/esp/EspReader.kt+++ b/app/src/main/java/com/rfsentinel/app/esp/EspReader.kt@@ -5,11 +5,13 @@ package com.rfsentinel.app.esp* asks read-only questions: OUI-Spy may be sent `CMD:VERSION` and, in* Detector mode, `CMD:DUMP_LIVE` (what it has found so far); GhostESP is only* asked for `help`, to scan networks and to list them; ESP32 Marauder only for- * `help` and its passive `sniffbeacon` / `sniffprobe` sniffers.+ * `help` and its passive `sniffbeacon` / `sniffprobe` sniffers; a FREE-WiLi 2 ([freeWili])+ * only gets its console's WiFi-menu keys and its access-point scan.*/class EspReader(private val port: SerialPort,private val onStatus: (String) -> Unit,+ private val freeWili: Boolean = false,private val onSightings: (List<EspSighting>) -> Unit) {@Volatile private var stopped = false@@ -18,6 +20,7 @@ class EspReader(fun run() {val buf = ByteArray(4096)+ if (freeWili) { pollFreeWili(buf); return }onStatus("ESP32 · listening…")// 1. OUI-Spy prints on its own (banners, status, detections).var heard = readFor(buf, 4_000) { OuiSpyReports.recognises(it) }@@ -182,6 +185,39 @@ class EspReader(runCatching { port.write("stopscan\r\n") }}+ /**+ * FREE-WiLi 2 (its ESP32-C5 does WiFi): opens the console's WiFi menu (`w`), then runs its+ * access-point scan (`s`) over and over, passing on the `*wifiscan` lines it prints.+ * Leaves the menu (`q`) when stopped. Ported from Wardrive Go (RocketGod, GPL-3.0).+ */+ private fun pollFreeWili(buf: ByteArray) {+ onStatus("FREE-WiLi · connecting…")+ readFor(buf, 3_000) // boot banner / menu+ var inWifi = false+ for (attempt in 0 until 2) {+ if (stopped) return+ readFor(buf, 200); port.write("w\r"); readFor(buf, 1_500)+ port.write("w\r")+ if (FreeWiliReports.isWifiMenu(readFor(buf, 1_800))) { inWifi = true; break }+ }+ onStatus(if (inWifi) "FREE-WiLi · live · scanning…" else "FREE-WiLi · WiFi menu not confirmed · scanning anyway…")+ val seen = HashMap<String, Long>()+ var sweeps = 0+ while (!stopped) {+ readFor(buf, 200) // drain+ port.write("s\r")+ val found = FreeWiliReports.parseScan(readFor(buf, 9_000))+ if (stopped) break+ val now = System.currentTimeMillis()+ found.forEach { seen[it.mac] = now }+ seen.entries.removeAll { now - it.value > 60_000 }+ if (found.isNotEmpty()) onSightings(found)+ sweeps+++ onStatus("FREE-WiLi · live · ${seen.size} Wi-Fi networks (sweep $sweeps)")+ }+ runCatching { port.write("q\r") }+ }+/** Reads for up to [ms], stopping early once [done] is true for what was read. */private fun readFor(buf: ByteArray, ms: Long, done: (String) -> Boolean = { false }): String {val sb = StringBuilder()diff --git a/app/src/main/java/com/rfsentinel/app/esp/EspReports.kt b/app/src/main/java/com/rfsentinel/app/esp/EspReports.ktindex 47437c8..af3fba4 100644--- a/app/src/main/java/com/rfsentinel/app/esp/EspReports.kt+++ b/app/src/main/java/com/rfsentinel/app/esp/EspReports.kt@@ -204,3 +204,40 @@ object MarauderReports {return null}}++/**+ * FREE-WiLi 2 console: its WiFi menu's access-point scan prints one `*wifiscan` line per+ * network; the tokens after it are read as Wardrive Go does (RocketGod, GPL-3.0): BSSID+ * 3rd, RSSI 4th, channel 5th, and the network name from the 8th to the one before last.+ */+object FreeWiliReports {++ private val ANSI = Regex("""\u001B\[[0-9;]*m""")+ private val MAC = Regex("""^[0-9A-Fa-f]{2}(?::[0-9A-Fa-f]{2}){5}$""")+ private val SPACES = Regex("""\s+""")++ fun isWifiMenu(text: String): Boolean = ANSI.replace(text, "").let {+ it.contains("Wifi Functions", ignoreCase = true) || it.contains("Scan for Access Points", ignoreCase = true)+ }++ fun parseLine(raw: String): EspSighting? {+ val line = ANSI.replace(raw, "").trim()+ val i = line.indexOf("*wifiscan")+ if (i < 0) return null+ val body = line.substring(i + "*wifiscan".length).trim().trimEnd(']', ')').trim()+ val t = body.split(SPACES).filter { it.isNotEmpty() }+ if (t.size < 8 || !MAC.matches(t[2])) return null+ val rssi = t[3].toIntOrNull() ?: return null+ val ch = t[4].toIntOrNull()+ val ssid = if (t.size >= 9) t.subList(7, t.size - 1).joinToString(" ").trim() else ""+ return EspSighting(+ mac = t[2].uppercase(), rssi = rssi, ble = false,+ name = ssid.takeIf { com.rfsentinel.app.usb.MonitorFrames.validSsid(it) },+ frequencyMhz = ch?.let { MarauderReports.frequencyOf(it) } ?: 0+ )+ }++ /** Every network in one scan's output (the last line wins for a repeated BSSID). */+ fun parseScan(text: String): List<EspSighting> =+ text.lines().mapNotNull { parseLine(it) }.associateBy { it.mac }.values.toList()+}diff --git a/app/src/main/java/com/rfsentinel/app/esp/SerialPort.kt b/app/src/main/java/com/rfsentinel/app/esp/SerialPort.ktindex f19168d..8549581 100644--- a/app/src/main/java/com/rfsentinel/app/esp/SerialPort.kt+++ b/app/src/main/java/com/rfsentinel/app/esp/SerialPort.kt@@ -13,8 +13,8 @@ interface SerialPort {fun read(buf: ByteArray, timeoutMs: Int): Intfun close()- /** The USB-serial chips found on ESP32 boards. */- enum class Chip { NATIVE_USB, CP210X, CH34X }+ /** The USB-serial chips found on ESP32 boards; FREEWILI is the FREE-WiLi 2's console (CDC-ACM). */+ enum class Chip { NATIVE_USB, CP210X, CH34X, FREEWILI }companion object {fun chipOf(vid: Int, pid: Int): Chip? = when {@@ -22,6 +22,7 @@ interface SerialPort {vid == 0x0483 && pid == 0x5740 -> Chip.NATIVE_USB // Flipper Zero (USB-UART bridge to its ESP32 board)vid == 0x10C4 && pid == 0xEA60 -> Chip.CP210X // Silicon Labs CP2102 / CP2104vid == 0x1A86 && pid in setOf(0x7523, 0x5523, 0x55D4) -> Chip.CH34X // WCH CH340 / CH341 / CH9102+ vid == 0x093C && pid == 0x205A -> Chip.FREEWILI // FREE-WiLi 2 console (its ESP32-C5 does WiFi)else -> null}@@ -29,6 +30,7 @@ interface SerialPort {fun open(conn: UsbDeviceConnection, device: UsbDevice): SerialPort? =when (chipOf(device.vendorId, device.productId)) {Chip.NATIVE_USB -> CdcAcmPort(conn, device).takeIf { it.open() }+ Chip.FREEWILI -> CdcAcmPort(conn, device, raiseDtr = false).takeIf { it.open() }Chip.CP210X -> Cp210xPort(conn, device).takeIf { it.open() }Chip.CH34X -> Ch34xPort(conn, device).takeIf { it.open() }null -> null@@ -70,8 +72,11 @@ abstract class BulkPort(protected val conn: UsbDeviceConnection) : SerialPort {}}-/** USB CDC-ACM: ESP32-S2/S3/C3/C6 native USB. DTR is raised so the firmware sees a host. */-class CdcAcmPort(conn: UsbDeviceConnection, private val device: UsbDevice) : BulkPort(conn) {+/**+ * USB CDC-ACM: ESP32-S2/S3/C3/C6 native USB. DTR is raised so the firmware sees a host+ * ([raiseDtr] false for the FREE-WiLi 2, whose console is opened without it).+ */+class CdcAcmPort(conn: UsbDeviceConnection, private val device: UsbDevice, private val raiseDtr: Boolean = true) : BulkPort(conn) {fun open(): Boolean {var comm: UsbInterface? = nullvar data: UsbInterface? = null@@ -91,7 +96,7 @@ class CdcAcmPort(conn: UsbDeviceConnection, private val device: UsbDevice) : Bul// SET_LINE_CODING 115200 8N1, then SET_CONTROL_LINE_STATE with DTR.val coding = byteArrayOf(0x00, 0xC2.toByte(), 0x01, 0x00, 0, 0, 8)conn.controlTransfer(0x21, 0x20, 0, index, coding, coding.size, 1000)- conn.controlTransfer(0x21, 0x22, 0x01, index, null, 0, 1000)+ conn.controlTransfer(0x21, 0x22, if (raiseDtr) 0x01 else 0x00, index, null, 0, 1000)return true}}diff --git a/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt b/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.ktindex 6e51e16..e3ab864 100644--- a/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt+++ b/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt@@ -183,11 +183,34 @@ class SettingsActivity : AppCompatActivity() {}}+ /**+ * The USB WiFi adapter log as a .txt file to send (email, messages, Drive...): app and+ * phone, the USB devices plugged in, and the driver log - for testers without adb.+ */+ private fun exportUsbWifiLog() {+ lifecycleScope.launch {+ val uri = kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.IO) {+ runCatching {+ val dir = java.io.File(cacheDir, "exports").apply { mkdirs() }+ val file = java.io.File(dir, "rfsentinel-usb-wifi-log-${com.rfsentinel.app.util.Exporter.stamp()}.txt")+ file.writeText(com.rfsentinel.app.usb.UsbWifi.report(this@SettingsActivity))+ androidx.core.content.FileProvider.getUriForFile(this@SettingsActivity, "$packageName.fileprovider", file)+ }.getOrNull()+ }+ if (uri == null) { Toast.makeText(this@SettingsActivity, "Couldn't create the log file", Toast.LENGTH_SHORT).show(); return@launch }+ startActivity(Intent.createChooser(Intent(Intent.ACTION_SEND).setType("text/plain")+ .putExtra(Intent.EXTRA_STREAM, uri)+ .putExtra(Intent.EXTRA_SUBJECT, "RF Sentinel USB WiFi adapter log")+ .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION), "Export adapter log"))+ }+ }+private fun updateEspStatus() {val s = com.rfsentinel.app.esp.EspBoards.status- binding.espStatusText.text = "ESP32 on USB (OUI-Spy, GhostESP or Marauder; also through a Flipper Zero): " ++ binding.espStatusText.text = "ESP32 on USB (OUI-Spy, GhostESP or Marauder; also through a Flipper Zero; FREE-WiLi 2): " +s.ifBlank { "plug one in with an OTG cable while scanning to add its detections" }- binding.usbWifiText.text = "USB WiFi adapter in monitor mode (RTL8811AU / 8821AU such as the ALFA AWUS036ACS, or RTL8812BU / 8822BU): " ++ binding.usbWifiText.text = "USB WiFi adapter in monitor mode (RTL8811AU / 8821AU such as the ALFA AWUS036ACS, RTL8812BU / 8822BU, " ++ "RTL8814AU (AWUS1900), MT7612U (AWUS036ACM), RTL8187 (AWUS036H), RT3070 (AWUS036NH / NEH) or, experimental, AR9271 (AWUS036NHA)): " +com.rfsentinel.app.usb.UsbWifi.status.ifBlank { "plug one in with an OTG cable while scanning - longer range, and it hears devices connected to networks" }val board = Prefs.ouiSpyBoard(this)binding.ouiSpyText.text = if (board == null)@@ -433,13 +456,7 @@ class SettingsActivity : AppCompatActivity() {com.rfsentinel.app.esp.EspBoards.onStatusChanged = { runOnUiThread { updateEspStatus() } }com.rfsentinel.app.esp.OuiSpyBle.onStatusChanged = { runOnUiThread { updateEspStatus() } }binding.ouiSpyButton.setOnClickListener { pairOuiSpy() }- binding.usbWifiLogButton.setOnClickListener {- val log = com.rfsentinel.app.usb.UsbWifi.logText().ifBlank { "No USB WiFi adapter activity yet." }- startActivity(android.content.Intent.createChooser(- android.content.Intent(android.content.Intent.ACTION_SEND).setType("text/plain")- .putExtra(android.content.Intent.EXTRA_SUBJECT, "RF Sentinel USB WiFi adapter log")- .putExtra(android.content.Intent.EXTRA_TEXT, log), "Share adapter log"))- }+ binding.usbWifiLogButton.setOnClickListener { exportUsbWifiLog() }binding.trackerIgnoreButton.setOnClickListener {com.rfsentinel.app.data.TrackerMutes.clear(this)Prefs.setTrackerFollowPausedUntil(this, 0L)diff --git a/app/src/main/java/com/rfsentinel/app/ui/SetupActivity.kt b/app/src/main/java/com/rfsentinel/app/ui/SetupActivity.ktindex 41f9079..1977097 100644--- a/app/src/main/java/com/rfsentinel/app/ui/SetupActivity.kt+++ b/app/src/main/java/com/rfsentinel/app/ui/SetupActivity.kt@@ -256,7 +256,7 @@ class SetupActivity : AppCompatActivity() {Prefs.setCellChangeAlerts(this, it)}para("Extra hardware works on its own once plugged in while scanning: ESP32 boards (OUI-Spy, GhostESP, Marauder - also ESP32-C5 boards for 5 GHz, and a Flipper Zero with its ESP32 board) " +- "and USB WiFi adapters (RTL8811AU / 8821AU such as the ALFA AWUS036ACS, or RTL8812BU / 8822BU). An OUI-SPY board over Bluetooth is paired in Settings.", small = true)+ "and USB WiFi adapters (RTL8811AU / 8821AU such as the ALFA AWUS036ACS, RTL8812BU / 8822BU, RTL8814AU, MT7612U, RTL8187, RT3070 or, experimental, AR9271 - ALFA AWUS1900, AWUS036ACM, AWUS036H, AWUS036NH / NEH, AWUS036NHA). An OUI-SPY board over Bluetooth is paired in Settings.", small = true)}private fun permissions() {diff --git a/app/src/main/java/com/rfsentinel/app/usb/Ar9271Monitor.kt b/app/src/main/java/com/rfsentinel/app/usb/Ar9271Monitor.ktnew file mode 100644index 0000000..c3fda43--- /dev/null+++ b/app/src/main/java/com/rfsentinel/app/usb/Ar9271Monitor.kt@@ -0,0 +1,521 @@+package com.rfsentinel.app.usb++/*+ * EXPERIMENTAL receive-only monitor mode for Atheros AR9271 USB WiFi adapters (e.g. ALFA+ * AWUS036NHA, TP-Link TL-WN722N v1), 2.4 GHz 802.11b/g/n, driven from userspace over+ * Android's USB host API - no root, no kernel driver. Loads the open ath9k_htc firmware+ * (assets/usbwifi/htc_9271-1.4.0.fw, from linux-firmware; licence in+ * LICENCE.open-ath9k-htc-firmware), sets the radio up through the firmware's WMI+ * register commands, hops the 2.4 GHz channels and reports what it hears. It never+ * transmits.+ *+ * Ported from Wardrive Go by RocketGod (https://github.com/RocketGod-git/wardrive-go,+ * GPL-3.0), which follows the Linux ath9k_htc driver. Changes here, checked against the+ * kernel: the signal is the radio's reading plus the noise floor (it is relative to it),+ * the FCS is removed from each frame, packets that span two USB transfers are put back+ * together, WMI answers are matched to their command (events are skipped), a firmware+ * that is already running is reused instead of re-uploaded, the official firmware build+ * is used, and its diagnostics-only steps and the handshake / PMKID capture were removed.+ */++import android.content.Context+import android.hardware.usb.UsbDevice+import android.hardware.usb.UsbDeviceConnection+import android.hardware.usb.UsbEndpoint+import android.hardware.usb.UsbManager++object Ar9271Monitor {+ @Volatile var running = false; private set+ @Volatile private var stop = false++ private val frames = MonitorFrames()+ private val HOP = intArrayOf(1, 6, 11, 3, 9, 2, 7, 13, 4, 10, 5, 8, 12)+ private const val DWELL_MS = 500L+ private val FRESH_MS get() = (HOP.size * DWELL_MS * 9 / 5).coerceAtLeast(3000L)+ private const val REPORT_MS = 10_000L++ private const val FW_DOWNLOAD = 0x30; private const val FW_DOWNLOAD_COMP = 0x31+ private const val FW_ADDR = 0x501000; private const val FW_TEXT_ADDR = 0x903000; private const val FW_BLOCK = 4096+ private const val RX_STREAM_TAG = 0x4e00+ private const val RX_BUF = 16384+ private const val HTC_RX_STATUS = 40+ private const val FCS_LEN = 4+ private const val RX_FILTER_MONITOR = 0x0018ffff+ private const val RSSI_BAD = -128++ // WMI commands (wmi.h)+ private const val WMI_GET_FW_VERSION = 3; private const val WMI_DISABLE_INTR = 4; private const val WMI_ENABLE_INTR = 5+ private const val WMI_ATH_INIT = 6; private const val WMI_DRAIN_TXQ_ALL = 11; private const val WMI_START_RECV = 12+ private const val WMI_STOP_RECV = 13; private const val WMI_FLUSH_RECV = 14; private const val WMI_SET_MODE = 15+ private const val WMI_NODE_CREATE = 16; private const val WMI_VAP_CREATE = 19; private const val WMI_REG_READ = 20+ private const val WMI_REG_WRITE = 21; private const val WMI_TARGET_IC_UPDATE = 24; private const val WMI_REG_RMW = 32++ private lateinit var conn: UsbDeviceConnection+ private lateinit var regOut: UsbEndpoint+ private lateinit var regIn: UsbEndpoint+ private var wmiEp = 1+ private var seq = 0+ @Volatile private var curChannel = 6+ /** The receiver's noise floor in dBm: signal readings are relative to it. */+ private var noiseFloor = -95+ @Volatile private var ctlErrors = 0+ private var carry: ByteArray? = null++ fun abort() { stop = true }++ fun run(ctx: Context, device: UsbDevice, chipName: String, onStatus: (String) -> Unit,+ onFrame: (List<MonitorSighting>) -> Unit) {+ if (running) return+ running = true; stop = false; frames.clear(); ctlErrors = 0; carry = null; noiseFloor = -95+ val mgr = ctx.getSystemService(Context.USB_SERVICE) as UsbManager+ val c = mgr.openDevice(device) ?: run { onStatus("$chipName: couldn't reopen adapter"); running = false; return }+ conn = c+ try {+ val intf = device.getInterface(0)+ if (!c.claimInterface(intf, true)) UsbWifi.log("AR9271: couldn't claim the USB interface (continuing)")+ val eps = (0 until intf.endpointCount).map { intf.getEndpoint(it) }+ val rx = eps.firstOrNull { it.address == 0x82 }+ val inEp = eps.firstOrNull { it.address == 0x83 }; val outEp = eps.firstOrNull { it.address == 0x04 }+ UsbWifi.log("=== AR9271 bring-up (ath9k_htc, experimental) ===")+ if (rx == null || inEp == null || outEp == null) { onStatus("$chipName: unexpected USB endpoints"); UsbWifi.log("AR9271: endpoints 0x82 / 0x83 / 0x04 not all present"); return }+ regIn = inEp; regOut = outEp+ val t0 = System.currentTimeMillis()++ // ---- firmware ----+ onStatus("$chipName · starting firmware…")+ var ready = awaitReady(1500)+ var controlEp: Int? = null+ if (ready == null) {+ // No READY: either the boot ROM is waiting for firmware, or the firmware is+ // already running from an earlier scan (it says READY only once, at boot).+ controlEp = connectService(0x0100, 3, 4)+ if (controlEp != null) UsbWifi.log("AR9271: firmware already running (from an earlier scan) - reusing it")+ else {+ if (!uploadFirmware(ctx)) { onStatus("$chipName: firmware upload failed (replug)"); return }+ ready = awaitReady(5000)+ if (ready == null) {+ UsbWifi.log("AR9271: no HTC READY after the firmware upload")+ onStatus("$chipName: firmware didn't start (replug)"); return+ }+ }+ }+ val credits = ready?.let { ((it[10].toInt() and 0xff) shl 8) or (it[11].toInt() and 0xff) } ?: 33+ UsbWifi.log("AR9271: firmware ready${if (ready != null) " (HTC READY, $credits credits)" else ""}")++ // ---- HTC services: WMI control, then the data services in ath9k_htc's order ----+ (controlEp ?: connectService(0x0100, 3, 4))?.let { wmiEp = it }+ ?: UsbWifi.log("AR9271: no answer to the WMI connect - trying endpoint $wmiEp")+ for (svc in intArrayOf(0x0101, 0x0102, 0x0103, 0x0104, 0x0107, 0x0108, 0x0106, 0x0105)) connectService(svc, 2, 1)+ send(byteArrayOf(0, 0, 0, 4, 0, 0, 0, 0, 0, 5, 1, (credits and 0xff).toByte())) // config pipe+ readIn(1000)+ send(byteArrayOf(0, 0, 0, 2, 0, 0, 0, 0, 0, 4)) // setup complete+ readIn(1000)+ wmi(WMI_GET_FW_VERSION)?.takeIf { it.size >= 16 }?.let {+ UsbWifi.log("AR9271: firmware version %d.%d, WMI endpoint %d".format(be16(it, 12), be16(it, 14), wmiEp))+ }++ onStatus("$chipName · starting radio…")+ if (!initRadio()) { onStatus("$chipName: radio didn't start (replug)"); return }+ UsbWifi.log("AR9271: started in ${System.currentTimeMillis() - t0} ms, noise floor $noiseFloor dBm, USB errors $ctlErrors - monitor live ch $curChannel")+ onStatus("$chipName · live · 2.4 GHz monitor")+ rxLoop(chipName, rx, onFrame, onStatus)+ } catch (e: Exception) {+ UsbWifi.log("AR9271: bring-up error - ${UsbWifi.describe(e)}")+ onStatus("$chipName: error · ${e.message}")+ } finally {+ runCatching { c.close() }+ running = false+ }+ }++ // ---- firmware / HTC ----++ private fun uploadFirmware(ctx: Context): Boolean {+ val fw = ctx.assets.open("usbwifi/htc_9271-1.4.0.fw").use { it.readBytes() }+ UsbWifi.log("AR9271: uploading firmware (${fw.size} B)")+ var addr = FW_ADDR; var off = 0+ while (off < fw.size) {+ val len = minOf(FW_BLOCK, fw.size - off)+ if (conn.controlTransfer(0x40, FW_DOWNLOAD, addr ushr 8, 0, fw.copyOfRange(off, off + len), len, 2000) < 0) {+ UsbWifi.log("AR9271: firmware upload failed at $off B"); return false+ }+ off += len; addr += len+ }+ // The chip starts the firmware right away; a negative answer here is normal.+ conn.controlTransfer(0x40, FW_DOWNLOAD_COMP, FW_TEXT_ADDR ushr 8, 0, null, 0, 2000)+ return true+ }++ /** The firmware's HTC READY message (endpoint 0, message 1), or null. */+ private fun awaitReady(ms: Int): ByteArray? {+ val end = System.currentTimeMillis() + ms+ while (System.currentTimeMillis() < end && !stop) {+ val m = readIn(300) ?: continue+ if (m.size >= 16 && m[0].toInt() == 0 && be16(m, 8) == 1) return m+ }+ return null+ }++ /** HTC connect-service; returns the endpoint the firmware assigned, or null without an answer. */+ private fun connectService(svc: Int, dlPipe: Int, ulPipe: Int): Int? {+ send(byteArrayOf(0, 0, 0, 10, 0, 0, 0, 0, 0, 2, (svc ushr 8).toByte(), svc.toByte(), 0, 0, dlPipe.toByte(), ulPipe.toByte(), 0, 0))+ val end = System.currentTimeMillis() + 1000+ while (System.currentTimeMillis() < end) {+ val r = readIn(300) ?: continue+ if (r.size >= 14 && r[0].toInt() == 0 && be16(r, 8) == 3) {+ val status = r[12].toInt() and 0xff; val ep = r[13].toInt() and 0xff+ if (status != 0) UsbWifi.log("AR9271: service 0x%04x: status %d".format(svc, status))+ return ep+ }+ }+ return null+ }++ private fun send(m: ByteArray) { if (conn.bulkTransfer(regOut, m, m.size, 1000) < 0) ctlErrors++ }++ private fun readIn(ms: Int): ByteArray? {+ val buf = ByteArray(maxOf(regIn.maxPacketSize, 512))+ val end = System.currentTimeMillis() + ms+ while (System.currentTimeMillis() < end && !stop) {+ val n = conn.bulkTransfer(regIn, buf, buf.size, 300)+ if (n > 0) return buf.copyOf(n)+ if (n < 0 && System.currentTimeMillis() + 300 >= end) break+ }+ return null+ }++ /**+ * A WMI command and its answer: the next non-event message (events have bit 0x1000 in+ * their id) on the WMI endpoint that carries this command's sequence number or id.+ */+ private fun wmi(cmd: Int, payload: ByteArray = ByteArray(0), waitMs: Int = 800): ByteArray? {+ seq = (seq + 1) and 0xffff+ val m = ByteArray(12 + payload.size)+ m[0] = wmiEp.toByte()+ val plen = 4 + payload.size+ m[2] = (plen ushr 8).toByte(); m[3] = plen.toByte()+ m[8] = (cmd ushr 8).toByte(); m[9] = cmd.toByte()+ m[10] = (seq ushr 8).toByte(); m[11] = seq.toByte()+ payload.copyInto(m, 12)+ send(m)+ val end = System.currentTimeMillis() + waitMs+ while (System.currentTimeMillis() < end && !stop) {+ val r = readIn(300) ?: continue+ if (r.size < 12 || r[0].toInt() == 0) continue // HTC control message+ val id = be16(r, 8)+ if (id and 0x1000 == 0 && (be16(r, 10) == seq || id == cmd)) return r+ }+ return null+ }++ private fun regRead(reg: Int): Long? {+ val r = wmi(WMI_REG_READ, be32(reg), 1200) ?: run { ctlErrors++; return null }+ if (r.size < 16) return null+ return ((r[12].toLong() and 0xff) shl 24) or ((r[13].toLong() and 0xff) shl 16) or ((r[14].toLong() and 0xff) shl 8) or (r[15].toLong() and 0xff)+ }+ private fun regWrite(reg: Int, v: Int) { if (wmi(WMI_REG_WRITE, be32(reg) + be32(v)) == null) ctlErrors++ }+ private fun regRmw(reg: Int, set: Int, clr: Int) { if (wmi(WMI_REG_RMW, be32(reg) + be32(set) + be32(clr), 600) == null) ctlErrors++ }+ private fun field(reg: Int, mask: Long, shift: Int, v: Int) = regRmw(reg, ((v.toLong() shl shift) and mask).toInt(), mask.toInt())++ /** Register writes in batches of 16, as ath9k_htc does. */+ private fun writeArray(arr: LongArray) {+ val n = arr.size / 2+ var i = 0+ while (i < n && !stop) {+ val batch = minOf(16, n - i)+ val p = ByteArray(batch * 8)+ for (j in 0 until batch) {+ be32(arr[(i + j) * 2].toInt()).copyInto(p, j * 8)+ be32(arr[(i + j) * 2 + 1].toInt()).copyInto(p, j * 8 + 4)+ }+ if (wmi(WMI_REG_WRITE, p, 400) == null) ctlErrors+++ i += batch+ }+ }++ // ---- radio ----++ private fun initRadio(): Boolean {+ wmi(WMI_STOP_RECV); wmi(WMI_DISABLE_INTR)+ sleep(120)+ val srev = regRead(0x4020) ?: run { UsbWifi.log("AR9271: firmware isn't answering register reads"); return false }+ val id = (srev and 0xFF).toInt()+ val macVer = if (id == 0xFF) ((srev ushr 18) and 0x3FFF).toInt() else ((srev ushr 4) and 0xF).toInt()+ UsbWifi.log("AR9271: SREV 0x%08x, MAC version 0x%x%s".format(srev, macVer, if (macVer == 0x140) " (AR9271)" else " - not an AR9271?"))++ // wake the chip+ regWrite(0x704c, 0x3); regWrite(0x4000, 0x1); regWrite(0x7040, 0x0); sleep(3)+ regWrite(0x4000, 0x0); regWrite(0x7040, 0x1)+ var woke = false+ for (i in 0 until 12) { if ((regRead(0x7044) ?: 0L) and 0xfL == 0x2L) { woke = true; break }; sleep(5) }+ if (!woke) UsbWifi.log("AR9271: RTC didn't report on (continuing)")++ // RF reset, warm reset, PLL+ regWrite(0x50044, 0x20); sleep(50)+ regWrite(0x704c, 0x3)+ if ((regRead(0x4028) ?: 0L) and 0x3000L != 0L) { regWrite(0x402c, 0x0); regWrite(0x4000, 0x101) } else regWrite(0x4000, 0x1)+ regWrite(0x7000, 0x1); sleep(2); regWrite(0x7000, 0x0)+ for (i in 0 until 10) { if ((regRead(0x7000) ?: 3L) and 0x3L == 0L) break; sleep(3) }+ regWrite(0x4000, 0x0)+ regWrite(0x7014, 0x142c); sleep(1)+ regWrite(0x50040, 0x304); regWrite(0x7048, 0x2); sleep(2)+ regWrite(0x50044, 0x4000); sleep(50) // GATE_MAC_CTL++ // PHY / MAC init tables (2.4 GHz HT20)+ writeArray(Ar9271Tables.modes2g)+ writeArray(Ar9271Tables.common)+ writeArray(Ar9271Tables.txGain2g)+ val chk = regRead(0x1030)+ UsbWifi.log("AR9271: init tables written, check 0x1030 = 0x%08x (%s)".format(chk ?: -1L, if (chk == 0x160L) "ok" else "unexpected"))++ // ANI detection thresholds+ for (rv in arrayOf(intArrayOf(0x9850, 0x6d4000e2), intArrayOf(0x985c, 0x3137605e), intArrayOf(0x9858, 0x7ec84d2e),+ intArrayOf(0x986c, 0x06903881), intArrayOf(0x9868, 0x5ac640d0), intArrayOf(0x9924, 0xd00a800d.toInt()),+ intArrayOf(0x99c0, 0x05eea6d4))) regWrite(rv[0], rv[1])+ val cck = regRead(0xa208) ?: 0L+ regWrite(0xa208, ((0x803e68c8L and 0x3fL) or (cck and 0x3fL.inv())).toInt())+ regWrite(0x99a4, 0x1); regWrite(0xa39c, 0x1) // RX / calibration chain masks+ regWrite(0xA200, 0x4); regWrite(0x9804, 0x3c0)+ regWrite(0x8058, 0x0); regWrite(0x0080, -1); regWrite(0x8018, 0x7)++ // board values from the EEPROM (antenna switch, thresholds), only when it's readable+ var mac = ByteArray(6)+ val eepStat = regRead(0x407c)+ if (eepStat != null && eepStat and 0x000F0000L == 0L) {+ readEeprom4k()?.let { e -> mac = e.mac; applyBoardValues(e) } ?: UsbWifi.log("AR9271: EEPROM unreadable - keeping the default board values")+ } else UsbWifi.log("AR9271: EEPROM busy or absent (0x%08x) - keeping the default board values".format(eepStat ?: -1L))++ // channel, queues, DMA, interrupts+ setSynth(curChannel)+ for (i in 0..9) regWrite(0x1000 + (i shl 2), 1 shl i)+ regWrite(0x8004, ((regRead(0x8004) ?: 0L) or 0x20000000L).toInt())+ regWrite(0x4024, ((regRead(0x4024) ?: 0L) or 0x4L).toInt())+ regWrite(0x0030, (((regRead(0x0030) ?: 0L) and 0x7L.inv()) or 5L).toInt())+ regWrite(0x0034, (((regRead(0x0034) ?: 0L) and 0x7L.inv()) or 5L).toInt())+ regWrite(0x8114, 0x200)+ regWrite(0x00a4, 0x010f0000); regWrite(0x00a8, 0x010f0000); regWrite(0x00ac, 0x00800000)+ regWrite(0x00a0, 0x81800964.toInt()); regWrite(0x4028, -1); regWrite(0x402c, 0x00023f60); regWrite(0x4034, 0)+ regWrite(0x981c, 0x1); sleep(5) // activate the PHY++ // AGC offset and noise floor calibration+ regWrite(0x9860, ((regRead(0x9860) ?: 0L) or 0x1L).toInt())+ val agcCal = waitClear(0x9860, 0x1L, 40)+ val agc = regRead(0x9860) ?: 0L+ regWrite(0x9860, ((agc or 0x8000L) and 0x20000L.inv() or 0x2L).toInt())+ val nfCal = waitClear(0x9860, 0x2L, 60)+ sleep(300)+ val cca = regRead(0x9864) ?: 0L+ var nf = ((cca and 0x1FF00000L) shr 20).toInt(); if (nf and 0x100 != 0) nf -= 0x200+ if (nf in -127..-90) noiseFloor = nf+ UsbWifi.log("AR9271: calibration agc %b, noise floor %b: %d dBm%s".format(agcCal, nfCal, nf,+ if (nf > -116) " (high - the receiver may be deaf)" else ""))++ // start receiving+ regWrite(0x8004, (((regRead(0x8004) ?: 0L) and (0x10000L or 0x20000L).inv()) or 0x10000000L).toInt())+ regWrite(0x0014, 0x0a) // USB byte order+ wmi(WMI_FLUSH_RECV); wmi(WMI_SET_MODE, byteArrayOf(0, 1)); wmi(WMI_ATH_INIT); wmi(WMI_START_RECV)+ rxFilter()+ wmi(WMI_TARGET_IC_UPDATE, byteArrayOf(0, 0, 0xff.toByte(), 0xff.toByte(), 0xff.toByte(), 0, 1, 0))+ wmi(WMI_VAP_CREATE, byteArrayOf(0, 1) + mac + byteArrayOf(0, 9, 0, 0))+ wmi(WMI_NODE_CREATE, mac + ByteArray(6) + byteArrayOf(0, 0, 1, 0, 0, 0, 0, 0xff.toByte()))+ wmi(WMI_SET_MODE, byteArrayOf(0, 1)); wmi(WMI_ENABLE_INTR)+ aniSet()+ // ath9k_htc re-arms the receiver around a channel set; doing it twice settles it+ repeat(2) { rearm(); sleep(150) }+ return true+ }++ private fun rxFilter() {+ regWrite(0x0008, 0x4)+ regWrite(0x803c, RX_FILTER_MONITOR)+ regWrite(0x8040, -1); regWrite(0x8044, -1)+ regWrite(0x8048, ((regRead(0x8048) ?: 0L) and (0x20L or 0x02000000L).inv()).toInt())+ }++ private fun rearm() {+ wmi(WMI_DISABLE_INTR); wmi(WMI_DRAIN_TXQ_ALL); wmi(WMI_STOP_RECV)+ rxFilter()+ wmi(WMI_START_RECV); wmi(WMI_SET_MODE, byteArrayOf(0, 1)); wmi(WMI_ENABLE_INTR)+ }++ private fun hop(ch: Int) {+ wmi(WMI_DISABLE_INTR); wmi(WMI_DRAIN_TXQ_ALL); wmi(WMI_STOP_RECV)+ setSynth(ch)+ regWrite(0x9804, 0x3c0)+ rxFilter()+ wmi(WMI_START_RECV); wmi(WMI_SET_MODE, byteArrayOf(0, 1)); wmi(WMI_ENABLE_INTR)+ curChannel = ch+ }++ /** AR9271 synthesizer for a 2.4 GHz channel, and the matching delta slope. */+ private fun setSynth(ch: Int) {+ val freq = (if (ch == 14) 2484 else 2407 + ch * 5).toLong()+ val chanSel = (freq * 0x10000L) / 15L+ val old = regRead(0x9874) ?: 0L+ regWrite(0x9874, ((old and 0xc0000000L) or 0x30000000L or chanSel).toInt())+ setDeltaSlope(freq.toInt())+ }++ private fun setDeltaSlope(mhz: Int) {+ fun vals(cs: Int): Pair<Int, Int> {+ var e = 31+ while (e > 0) { if (((cs shr e) and 1) == 1) break; e-- }+ e = 14 - (e - 24)+ val man = cs + (1 shl (24 - e - 1))+ return Pair(man shr (24 - e), e - 16)+ }+ val cs = (0x64000000L / mhz).toInt()+ val (m1, e1) = vals(cs)+ var v = regRead(0x9814) ?: 0L+ v = (v and 0xFFFE0000L.inv()) or ((m1.toLong() shl 17) and 0xFFFE0000L)+ v = (v and 0x0001E000L.inv()) or ((e1.toLong() shl 13) and 0x0001E000L)+ regWrite(0x9814, v.toInt())+ val (m2, e2) = vals((9 * cs) / 10)+ var h = regRead(0x99D0) ?: 0L+ h = (h and 0x0007FFF0L.inv()) or ((m2.toLong() shl 4) and 0x0007FFF0L)+ h = (h and 0x0000000FL.inv()) or (e2.toLong() and 0x0000000FL)+ regWrite(0x99D0, h.toInt())+ }++ /** ANI: OFDM weak-signal detection on, first-step and spur immunity at their lowest. */+ private fun aniSet() {+ field(0x9858, 0x0003F000L, 12, 0); field(0x9840, 0x00000FC0L, 6, 0)+ field(0x9924, 0x000000FEL, 1, 2); field(0x99BC, 0x0000FE00L, 9, 1)+ }++ private fun waitClear(reg: Int, mask: Long, tries: Int): Boolean {+ for (i in 0 until tries) { val v = regRead(reg) ?: return false; if (v and mask == 0L) return true; sleep(3) }+ return false+ }++ private class Eep4k(val mac: ByteArray, val antCtrlChain0: Long, val antCtrlCommon: Long, val switchSettling: Int,+ val adcDesiredSize: Int, val txEndToRxOn: Int, val thresh62: Int, val modalVersion: Int,+ val antdivCtl1: Int, val antdivCtl2: Int, val txGainType: Int)++ /** The 4K EEPROM's base and modal header (words 64-111) through the 0x2000 window. */+ private fun readEeprom4k(): Eep4k? {+ val b = ByteArray(96)+ for (i in 0 until 48) {+ val v = regRead(0x2000 + ((64 + i) shl 2)) ?: return null+ b[i * 2] = v.toByte(); b[i * 2 + 1] = (v ushr 8).toByte()+ }+ fun u8(o: Int) = b[o].toInt() and 0xff+ fun le16(o: Int) = u8(o) or (u8(o + 1) shl 8)+ fun le32(o: Int) = (le16(o).toLong() or (le16(o + 2).toLong() shl 16)) and 0xffffffffL+ val version = le16(4)+ if ((version shr 12) != 0xE) { UsbWifi.log("AR9271: EEPROM version 0x%04x unexpected".format(version)); return null }+ val m = 32 + 20+ val e = Eep4k(b.copyOfRange(12, 18), le32(m), le32(m + 4), u8(m + 9), b[m + 12].toInt(), u8(m + 16), u8(m + 18),+ u8(m + 37), (u8(m + 39) shr 4) and 0xF, (u8(m + 41) shr 4) and 0xF, u8(31))+ UsbWifi.log("AR9271: EEPROM 4K version 0x%04x, MAC %02x:%02x:%02x:xx:xx:xx, antenna 0x%08x / 0x%08x, modal %d, TX gain %s".format(+ version, e.mac[0], e.mac[1], e.mac[2], e.antCtrlChain0, e.antCtrlCommon, e.modalVersion, if (e.txGainType == 1) "high" else "normal"))+ return e+ }++ private fun applyBoardValues(e: Eep4k) {+ regWrite(0x9964, e.antCtrlCommon.toInt())+ regWrite(0x9960, e.antCtrlChain0.toInt())+ if (e.modalVersion >= 3) {+ val a1 = e.antdivCtl1; val a2 = e.antdivCtl2+ val v = ((a1.toLong() shl 24) and 0x01000000L) or ((a2.toLong() shl 25) and 0x06000000L) or+ (((a2 shr 2).toLong() shl 27) and 0x18000000L) or (((a1 shr 1).toLong() shl 29) and 0x20000000L) or+ (((a1 shr 2).toLong() shl 30) and 0x40000000L)+ regRmw(0x99ac, v.toInt(), 0x7f000000)+ regRmw(0xa208, ((a1 shr 3) shl 13) and 0x2000, 0x2000)+ }+ field(0x9844, 0x00003F80L, 7, e.switchSettling)+ field(0x9850, 0x000000FFL, 0, e.adcDesiredSize and 0xFF)+ field(0x9828, 0x00FF0000L, 16, e.txEndToRxOn)+ field(0x9864, 0x000FF000L, 12, e.thresh62)+ field(0x99b8, 0x000000FFL, 0, e.thresh62)+ if (e.txGainType != 1) writeArray(Ar9271Tables.txGainNormal2g)+ }++ // ---- receive ----++ private class RxState { var hopAt = 0L; var lastEmit = 0L; var hopIdx = 0 }++ private fun rxLoop(chipName: String, ep: UsbEndpoint, onFrame: (List<MonitorSighting>) -> Unit, onStatus: (String) -> Unit) {+ val st = RxState()+ val t0 = System.currentTimeMillis(); st.hopAt = t0; st.lastEmit = t0+ curChannel = HOP[0]; runCatching { hop(HOP[0]) }+ val stats = BulkRx.Stats("AR9271")+ val total = BulkRx.run("AR9271", conn, ep, 8, RX_BUF, { stop }, { b, n ->+ stats.transfer(n)+ stats.sample("$n bytes, stream header + HTC header + RX status", b, 0, 4 + 8 + 16)+ val data = carry?.let { it + b.copyOf(n) } ?: b.copyOf(n)+ carry = forEachFrame(data, data.size, noiseFloor,+ onBad = { crc -> if (crc) stats.badChecksum++ else stats.malformed++ }) { s, e, rssi ->+ stats.frame(rssi)+ frames.frame(data, s, e, curChannel, rssi)+ }+ }) { now ->+ stats.maybeLog(now) {+ val (aps, clients) = frames.live(now, REPORT_MS)+ "ch $curChannel, $aps access points, $clients devices, USB errors $ctlErrors"+ }+ if (now - st.lastEmit > 2000) { emit(onFrame); st.lastEmit = now }+ if (now - st.hopAt > DWELL_MS) {+ st.hopIdx = (st.hopIdx + 1) % HOP.size+ runCatching { hop(HOP[st.hopIdx]) }+ val (aps, clients) = frames.live(now, REPORT_MS)+ onStatus("$chipName · live · $aps access points · $clients devices · ch $curChannel")+ st.hopAt = now+ }+ }+ emit(onFrame)+ UsbWifi.log("AR9271: RX loop stopped ($total B)")+ }++ private fun emit(onFrame: (List<MonitorSighting>) -> Unit) {+ val batch = frames.drain(System.currentTimeMillis(), FRESH_MS)+ if (batch.isNotEmpty()) onFrame(batch)+ }++ /**+ * The firmware's RX stream: packets of | length (le16) | tag 0x4e00 (le16) | HTC header (8) |+ * RX status (40) | frame + FCS | (HTC trailer) |, each padded to 4 bytes; one can continue in+ * the next transfer. [onFrame] gets each good frame's [start, end) without the FCS and its+ * signal (RX status reading + [noiseFloor]); bad checksums and broken packets go to [onBad].+ * Returns the bytes of an unfinished last packet, to put in front of the next transfer.+ */+ internal fun forEachFrame(b: ByteArray, n: Int, noiseFloor: Int, onBad: (Boolean) -> Unit = {},+ onFrame: (Int, Int, Int?) -> Unit): ByteArray? {+ fun u8(i: Int) = b[i].toInt() and 0xff+ fun le16(i: Int) = u8(i) or (u8(i + 1) shl 8)+ var off = 0+ while (off + 4 <= n) {+ if (le16(off + 2) != RX_STREAM_TAG) { onBad(false); return null } // lost sync: drop the rest, like ath9k_htc+ val pktLen = le16(off)+ if (pktLen > 2 * RX_BUF) { onBad(false); return null }+ val next = off + 4 + pktLen + ((4 - (pktLen and 3)) and 3)+ if (off + 4 + pktLen > n) return if (n - off <= 2 * RX_BUF) b.copyOfRange(off, n) else null+ val hs = off + 4+ if (pktLen >= 8 + HTC_RX_STATUS) {+ var plen = (u8(hs + 2) shl 8) or u8(hs + 3)+ if (u8(hs + 1) and 0x02 != 0) plen -= u8(hs + 4) // HTC trailer+ val ps = hs + 8+ val dlen = (u8(ps + 8) shl 8) or u8(ps + 9)+ val status = u8(ps + 10)+ when {+ plen != HTC_RX_STATUS + dlen || ps + plen > n -> onBad(false)+ status and 0x01 != 0 -> onBad(true) // checksum error+ status != 0 || dlen < 24 + FCS_LEN -> onBad(false) // PHY / decrypt error, runt+ else -> {+ val raw = b[ps + 12].toInt()+ val d = ps + HTC_RX_STATUS+ onFrame(d, d + dlen - FCS_LEN, if (raw == RSSI_BAD) null else noiseFloor + raw)+ }+ }+ }+ off = next+ }+ return null+ }++ // ---- helpers ----++ private fun be16(b: ByteArray, i: Int) = ((b[i].toInt() and 0xff) shl 8) or (b[i + 1].toInt() and 0xff)+ private fun be32(v: Int) = byteArrayOf((v ushr 24).toByte(), (v ushr 16).toByte(), (v ushr 8).toByte(), v.toByte())+ private fun sleep(ms: Int) = try { Thread.sleep(ms.toLong()) } catch (_: InterruptedException) {}+}diff --git a/app/src/main/java/com/rfsentinel/app/usb/Ar9271Tables.kt b/app/src/main/java/com/rfsentinel/app/usb/Ar9271Tables.ktnew file mode 100644index 0000000..421570d--- /dev/null+++ b/app/src/main/java/com/rfsentinel/app/usb/Ar9271Tables.kt@@ -0,0 +1,164 @@+package com.rfsentinel.app.usb++/*+ * Atheros AR9271 register tables (address, value pairs) for 2.4 GHz HT20: the common+ * and mode tables and the TX gain tables, from the Linux ath9k driver (ar9002_initvals.h,+ * ISC licence) as used by Wardrive Go (https://github.com/RocketGod-git/wardrive-go, GPL-3.0).+ */++object Ar9271Tables {+ val common = longArrayOf(+ 0xcL, 0x0L, 0x30L, 0x20045L, 0x34L, 0x5L, 0x40L, 0x0L, 0x44L, 0x8L, 0x48L, 0x8L,+ 0x4cL, 0x10L, 0x50L, 0x0L, 0x54L, 0x1fL, 0x800L, 0x0L, 0x804L, 0x0L, 0x808L, 0x0L,+ 0x80cL, 0x0L, 0x810L, 0x0L, 0x814L, 0x0L, 0x818L, 0x0L, 0x81cL, 0x0L, 0x820L, 0x0L,+ 0x824L, 0x0L, 0x1040L, 0x2ffc0fL, 0x1044L, 0x2ffc0fL, 0x1048L, 0x2ffc0fL, 0x104cL, 0x2ffc0fL, 0x1050L, 0x2ffc0fL,+ 0x1054L, 0x2ffc0fL, 0x1058L, 0x2ffc0fL, 0x105cL, 0x2ffc0fL, 0x1060L, 0x2ffc0fL, 0x1064L, 0x2ffc0fL, 0x1230L, 0x0L,+ 0x1270L, 0x0L, 0x1038L, 0x0L, 0x1078L, 0x0L, 0x10b8L, 0x0L, 0x10f8L, 0x0L, 0x1138L, 0x0L,+ 0x1178L, 0x0L, 0x11b8L, 0x0L, 0x11f8L, 0x0L, 0x1238L, 0x0L, 0x1278L, 0x0L, 0x12b8L, 0x0L,+ 0x12f8L, 0x0L, 0x1338L, 0x0L, 0x1378L, 0x0L, 0x13b8L, 0x0L, 0x13f8L, 0x0L, 0x1438L, 0x0L,+ 0x1478L, 0x0L, 0x14b8L, 0x0L, 0x14f8L, 0x0L, 0x1538L, 0x0L, 0x1578L, 0x0L, 0x15b8L, 0x0L,+ 0x15f8L, 0x0L, 0x1638L, 0x0L, 0x1678L, 0x0L, 0x16b8L, 0x0L, 0x16f8L, 0x0L, 0x1738L, 0x0L,+ 0x1778L, 0x0L, 0x17b8L, 0x0L, 0x17f8L, 0x0L, 0x103cL, 0x0L, 0x107cL, 0x0L, 0x10bcL, 0x0L,+ 0x10fcL, 0x0L, 0x113cL, 0x0L, 0x117cL, 0x0L, 0x11bcL, 0x0L, 0x11fcL, 0x0L, 0x123cL, 0x0L,+ 0x127cL, 0x0L, 0x12bcL, 0x0L, 0x12fcL, 0x0L, 0x133cL, 0x0L, 0x137cL, 0x0L, 0x13bcL, 0x0L,+ 0x13fcL, 0x0L, 0x143cL, 0x0L, 0x147cL, 0x0L, 0x4030L, 0x2L, 0x403cL, 0x2L, 0x4024L, 0x1fL,+ 0x4060L, 0x0L, 0x4064L, 0x0L, 0x8004L, 0x0L, 0x8008L, 0x0L, 0x800cL, 0x0L, 0x8018L, 0x700L,+ 0x8020L, 0x0L, 0x8038L, 0x0L, 0x803cL, 0x0L, 0x8048L, 0x0L, 0x8054L, 0x0L, 0x8058L, 0x0L,+ 0x805cL, 0xfc78fL, 0x8060L, 0xfL, 0x8064L, 0x0L, 0x8070L, 0x0L, 0x80b0L, 0x0L, 0x80b4L, 0x0L,+ 0x80b8L, 0x0L, 0x80bcL, 0x0L, 0x80c0L, 0x2a80001aL, 0x80c4L, 0x5dc01e0L, 0x80c8L, 0x1f402710L, 0x80ccL, 0x1f40000L,+ 0x80d0L, 0x1e00L, 0x80d4L, 0x0L, 0x80d8L, 0x400000L, 0x80e0L, 0xffffffffL, 0x80e4L, 0xffffL, 0x80e8L, 0x3f3f3fL,+ 0x80ecL, 0x0L, 0x80f0L, 0x0L, 0x80f4L, 0x0L, 0x80f8L, 0x0L, 0x80fcL, 0x20000L, 0x8100L, 0x20000L,+ 0x8104L, 0x1L, 0x8108L, 0x52L, 0x810cL, 0x0L, 0x8110L, 0x168L, 0x8118L, 0x100aaL, 0x811cL, 0x3210L,+ 0x8120L, 0x8f04810L, 0x8124L, 0x0L, 0x8128L, 0x0L, 0x812cL, 0x0L, 0x8130L, 0x0L, 0x8134L, 0x0L,+ 0x8138L, 0x0L, 0x813cL, 0x0L, 0x8144L, 0xffffffffL, 0x8168L, 0x0L, 0x816cL, 0x0L, 0x8170L, 0x32143320L,+ 0x8174L, 0xfaa4fa50L, 0x8178L, 0x100L, 0x817cL, 0x0L, 0x81c0L, 0x0L, 0x81d0L, 0x320aL, 0x81ecL, 0x0L,+ 0x81f0L, 0x0L, 0x81f4L, 0x0L, 0x81f8L, 0x0L, 0x81fcL, 0x0L, 0x8200L, 0x0L, 0x8204L, 0x0L,+ 0x8208L, 0x0L, 0x820cL, 0x0L, 0x8210L, 0x0L, 0x8214L, 0x0L, 0x8218L, 0x0L, 0x821cL, 0x0L,+ 0x8220L, 0x0L, 0x8224L, 0x0L, 0x8228L, 0x0L, 0x822cL, 0x0L, 0x8230L, 0x0L, 0x8234L, 0x0L,+ 0x8238L, 0x0L, 0x823cL, 0x0L, 0x8240L, 0x100000L, 0x8244L, 0x10f400L, 0x8248L, 0x100L, 0x824cL, 0x1e800L,+ 0x8250L, 0x0L, 0x8254L, 0x0L, 0x8258L, 0x0L, 0x825cL, 0x400000ffL, 0x8260L, 0x80922L, 0x8264L, 0x88a00010L,+ 0x8270L, 0x0L, 0x8274L, 0x40000000L, 0x8278L, 0x3e4180L, 0x827cL, 0x0L, 0x8284L, 0x2cL, 0x8288L, 0x2cL,+ 0x828cL, 0x0L, 0x8294L, 0x0L, 0x8298L, 0x0L, 0x829cL, 0x0L, 0x8300L, 0x40L, 0x8314L, 0x0L,+ 0x8328L, 0x0L, 0x832cL, 0x1L, 0x8330L, 0x302L, 0x8334L, 0xe00L, 0x8338L, 0xff0000L, 0x833cL, 0x0L,+ 0x8340L, 0x10380L, 0x8344L, 0x581043L, 0x7010L, 0x30L, 0x7034L, 0x2L, 0x7038L, 0x4c2L, 0x7800L, 0x140000L,+ 0x7804L, 0xe4548d8L, 0x7808L, 0x54214514L, 0x780cL, 0x2025820L, 0x7810L, 0x71c0d388L, 0x7814L, 0x924934a8L, 0x781cL, 0x0L,+ 0x7828L, 0x66964300L, 0x782cL, 0x8db6d961L, 0x7830L, 0x8db6d96cL, 0x7834L, 0x6140008bL, 0x783cL, 0x72ee0a72L, 0x7840L, 0xbbfffffcL,+ 0x7844L, 0xc0db6L, 0x7848L, 0x6db6246fL, 0x784cL, 0x6d9b66dbL, 0x7850L, 0x6d8c6dbaL, 0x7854L, 0x40000L, 0x7858L, 0xdb003012L,+ 0x785cL, 0x4924914L, 0x7860L, 0x21084210L, 0x7864L, 0xf7d7ffdeL, 0x7868L, 0xc2034080L, 0x7870L, 0x10142c00L, 0x9808L, 0x0L,+ 0x980cL, 0xafe68e30L, 0x9810L, 0xfd14e000L, 0x9814L, 0x9c0a9f6bL, 0x981cL, 0x0L, 0x982cL, 0xa000L, 0x9830L, 0x0L,+ 0x983cL, 0x200400L, 0x984cL, 0x40233cL, 0x9854L, 0x44L, 0x9900L, 0x0L, 0x9904L, 0x0L, 0x9908L, 0x0L,+ 0x990cL, 0x0L, 0x991cL, 0x10000fffL, 0x9920L, 0x4900000L, 0x9928L, 0x1L, 0x992cL, 0x4L, 0x9934L, 0x1e1f2022L,+ 0x9938L, 0xa0b0c0dL, 0x993cL, 0x0L, 0x9940L, 0x14750604L, 0x9948L, 0x9280c00aL, 0x994cL, 0x20028L, 0x9954L, 0x5f3ca3deL,+ 0x9958L, 0x108ecffL, 0x9968L, 0x3ceL, 0x9970L, 0x192bb514L, 0x9974L, 0x0L, 0x9978L, 0x1L, 0x997cL, 0x0L,+ 0x9980L, 0x0L, 0x9984L, 0x0L, 0x9988L, 0x0L, 0x998cL, 0x0L, 0x9990L, 0x0L, 0x9994L, 0x0L,+ 0x9998L, 0x0L, 0x999cL, 0x0L, 0x99a0L, 0x0L, 0x99a4L, 0x1L, 0x99a8L, 0x201fff00L, 0x99acL, 0x2def0400L,+ 0x99b0L, 0x3051000L, 0x99b4L, 0x820L, 0x99dcL, 0x0L, 0x99e0L, 0x0L, 0x99e4L, 0xaaaaaaaaL, 0x99e8L, 0x3c466478L,+ 0x99ecL, 0xcc80caaL, 0x99f0L, 0x0L, 0xa208L, 0x803e68c8L, 0xa210L, 0x4080a333L, 0xa214L, 0x206c10L, 0xa218L, 0x9c4060L,+ 0xa220L, 0x1834061L, 0xa224L, 0x400L, 0xa228L, 0x3b5L, 0xa22cL, 0x0L, 0xa234L, 0x20202020L, 0xa238L, 0x20202020L,+ 0xa244L, 0x0L, 0xa248L, 0xfffffffcL, 0xa24cL, 0x0L, 0xa254L, 0x0L, 0xa258L, 0xccb5380L, 0xa25cL, 0x15151501L,+ 0xa260L, 0xdfa90f01L, 0xa268L, 0x0L, 0xa26cL, 0xebae9e6L, 0xa388L, 0xc000000L, 0xa38cL, 0x20202020L, 0xa390L, 0x20202020L,+ 0xa39cL, 0x1L, 0xa3a0L, 0x0L, 0xa3a4L, 0x0L, 0xa3a8L, 0x0L, 0xa3acL, 0x0L, 0xa3b0L, 0x0L,+ 0xa3b4L, 0x0L, 0xa3b8L, 0x0L, 0xa3bcL, 0x0L, 0xa3c0L, 0x0L, 0xa3c4L, 0x0L, 0xa3ccL, 0x20202020L,+ 0xa3d0L, 0x20202020L, 0xa3d4L, 0x20202020L, 0xa3e4L, 0x0L, 0xa3e8L, 0x18c43433L, 0xa3ecL, 0xf70081L, 0xa3f0L, 0x1036a2fL,+ 0xa3f4L, 0x0L, 0xd270L, 0xd820820L, 0xd35cL, 0x7ffffefL, 0xd360L, 0xfffffe7L, 0xd364L, 0x17ffffe5L, 0xd368L, 0x1fffffe4L,+ 0xd36cL, 0x37ffffe3L, 0xd370L, 0x3fffffe3L, 0xd374L, 0x57ffffe3L, 0xd378L, 0x5fffffe2L, 0xd37cL, 0x7fffffe2L, 0xd380L, 0x7f3c7bbaL,+ 0xd384L, 0xf3307ff0L,+ )+ val modes2g = longArrayOf(+ 0x1030L, 0x160L, 0x1070L, 0x18cL, 0x10b0L, 0x3e38L, 0x10f0L, 0x0L, 0x8014L, 0x8400b00L, 0x801cL, 0x12e0002bL,+ 0x8318L, 0x3440L, 0x9804L, 0x300L, 0x9820L, 0x2020200L, 0x9824L, 0x1000e0eL, 0x9828L, 0x3a020001L, 0x9834L, 0xe0eL,+ 0x9838L, 0x7L, 0x9840L, 0x206a012eL, 0x9844L, 0x3721620L, 0x9848L, 0x1053L, 0xa848L, 0x1053L, 0x9850L, 0x6d4000e2L,+ 0x9858L, 0x7ec84d2eL, 0x985cL, 0x3137605eL, 0x9860L, 0x58d18L, 0x9864L, 0x1ce00L, 0x9868L, 0x5ac640d0L, 0x986cL, 0x6903881L,+ 0x9910L, 0x30002310L, 0x9914L, 0x898L, 0x9918L, 0xbL, 0x9924L, 0xd00a800dL, 0x9944L, 0xffbc1020L, 0x9960L, 0x0L,+ 0x9964L, 0x0L, 0x99b8L, 0x421cL, 0x99bcL, 0xc00L, 0x99c0L, 0x5eea6d4L, 0x99c4L, 0x6336f77L, 0x99c8L, 0x6af6532fL,+ 0x99ccL, 0x8f186c8L, 0x99d0L, 0x46384L, 0x99d4L, 0x0L, 0x99d8L, 0x0L, 0x9a00L, 0x58084L, 0x9a04L, 0x58088L,+ 0x9a08L, 0x5808cL, 0x9a0cL, 0x58100L, 0x9a10L, 0x58104L, 0x9a14L, 0x58108L, 0x9a18L, 0x5810cL, 0x9a1cL, 0x58110L,+ 0x9a20L, 0x58114L, 0x9a24L, 0x58180L, 0x9a28L, 0x58184L, 0x9a2cL, 0x58188L, 0x9a30L, 0x5818cL, 0x9a34L, 0x58190L,+ 0x9a38L, 0x58194L, 0x9a3cL, 0x581a0L, 0x9a40L, 0x5820cL, 0x9a44L, 0x581a8L, 0x9a48L, 0x58284L, 0x9a4cL, 0x58288L,+ 0x9a50L, 0x58224L, 0x9a54L, 0x58290L, 0x9a58L, 0x58300L, 0x9a5cL, 0x58304L, 0x9a60L, 0x58308L, 0x9a64L, 0x5830cL,+ 0x9a68L, 0x58380L, 0x9a6cL, 0x58384L, 0x9a70L, 0x68700L, 0x9a74L, 0x68704L, 0x9a78L, 0x68708L, 0x9a7cL, 0x6870cL,+ 0x9a80L, 0x68780L, 0x9a84L, 0x68784L, 0x9a88L, 0x78b00L, 0x9a8cL, 0x78b04L, 0x9a90L, 0x78b08L, 0x9a94L, 0x78b0cL,+ 0x9a98L, 0x78b80L, 0x9a9cL, 0x78b84L, 0x9aa0L, 0x78b88L, 0x9aa4L, 0x78b8cL, 0x9aa8L, 0x78b90L, 0x9aacL, 0xcaf80L,+ 0x9ab0L, 0xcaf84L, 0x9ab4L, 0xcaf88L, 0x9ab8L, 0xcaf8cL, 0x9abcL, 0xcaf90L, 0x9ac0L, 0xdb30cL, 0x9ac4L, 0xdb310L,+ 0x9ac8L, 0xdb384L, 0x9accL, 0xdb388L, 0x9ad0L, 0xdb324L, 0x9ad4L, 0xeb704L, 0x9ad8L, 0xeb6a4L, 0x9adcL, 0xeb6a8L,+ 0x9ae0L, 0xeb710L, 0x9ae4L, 0xeb714L, 0x9ae8L, 0xeb720L, 0x9aecL, 0xeb724L, 0x9af0L, 0xeb728L, 0x9af4L, 0xeb72cL,+ 0x9af8L, 0xeb7a0L, 0x9afcL, 0xeb7a4L, 0x9b00L, 0xeb7a8L, 0x9b04L, 0xeb7b0L, 0x9b08L, 0xeb7b4L, 0x9b0cL, 0xeb7b8L,+ 0x9b10L, 0xeb7a5L, 0x9b14L, 0xeb7a9L, 0x9b18L, 0xeb7adL, 0x9b1cL, 0xeb7b1L, 0x9b20L, 0xeb7b5L, 0x9b24L, 0xeb7b9L,+ 0x9b28L, 0xeb7c5L, 0x9b2cL, 0xeb7c9L, 0x9b30L, 0xeb7d1L, 0x9b34L, 0xeb7d5L, 0x9b38L, 0xeb7d9L, 0x9b3cL, 0xeb7c6L,+ 0x9b40L, 0xeb7caL, 0x9b44L, 0xeb7ceL, 0x9b48L, 0xeb7d2L, 0x9b4cL, 0xeb7d6L, 0x9b50L, 0xeb7c3L, 0x9b54L, 0xeb7c7L,+ 0x9b58L, 0xeb7cbL, 0x9b5cL, 0xeb7cfL, 0x9b60L, 0xeb7d7L, 0x9b64L, 0xeb7dbL, 0x9b68L, 0xeb7dbL, 0x9b6cL, 0xeb7dbL,+ 0x9b70L, 0xeb7dbL, 0x9b74L, 0xeb7dbL, 0x9b78L, 0xeb7dbL, 0x9b7cL, 0xeb7dbL, 0x9b80L, 0xeb7dbL, 0x9b84L, 0xeb7dbL,+ 0x9b88L, 0xeb7dbL, 0x9b8cL, 0xeb7dbL, 0x9b90L, 0xeb7dbL, 0x9b94L, 0xeb7dbL, 0x9b98L, 0xeb7dbL, 0x9b9cL, 0xeb7dbL,+ 0x9ba0L, 0xeb7dbL, 0x9ba4L, 0xeb7dbL, 0x9ba8L, 0xeb7dbL, 0x9bacL, 0xeb7dbL, 0x9bb0L, 0xeb7dbL, 0x9bb4L, 0xeb7dbL,+ 0x9bb8L, 0xeb7dbL, 0x9bbcL, 0xeb7dbL, 0x9bc0L, 0xeb7dbL, 0x9bc4L, 0xeb7dbL, 0x9bc8L, 0xeb7dbL, 0x9bccL, 0xeb7dbL,+ 0x9bd0L, 0xeb7dbL, 0x9bd4L, 0xeb7dbL, 0x9bd8L, 0xeb7dbL, 0x9bdcL, 0xeb7dbL, 0x9be0L, 0xeb7dbL, 0x9be4L, 0xeb7dbL,+ 0x9be8L, 0xeb7dbL, 0x9becL, 0xeb7dbL, 0x9bf0L, 0xeb7dbL, 0x9bf4L, 0xeb7dbL, 0x9bf8L, 0xeb7dbL, 0x9bfcL, 0xeb7dbL,+ 0xaa00L, 0x58084L, 0xaa04L, 0x58088L, 0xaa08L, 0x5808cL, 0xaa0cL, 0x58100L, 0xaa10L, 0x58104L, 0xaa14L, 0x58108L,+ 0xaa18L, 0x5810cL, 0xaa1cL, 0x58110L, 0xaa20L, 0x58114L, 0xaa24L, 0x58180L, 0xaa28L, 0x58184L, 0xaa2cL, 0x58188L,+ 0xaa30L, 0x5818cL, 0xaa34L, 0x58190L, 0xaa38L, 0x58194L, 0xaa3cL, 0x581a0L, 0xaa40L, 0x5820cL, 0xaa44L, 0x581a8L,+ 0xaa48L, 0x58284L, 0xaa4cL, 0x58288L, 0xaa50L, 0x58224L, 0xaa54L, 0x58290L, 0xaa58L, 0x58300L, 0xaa5cL, 0x58304L,+ 0xaa60L, 0x58308L, 0xaa64L, 0x5830cL, 0xaa68L, 0x58380L, 0xaa6cL, 0x58384L, 0xaa70L, 0x68700L, 0xaa74L, 0x68704L,+ 0xaa78L, 0x68708L, 0xaa7cL, 0x6870cL, 0xaa80L, 0x68780L, 0xaa84L, 0x68784L, 0xaa88L, 0x78b00L, 0xaa8cL, 0x78b04L,+ 0xaa90L, 0x78b08L, 0xaa94L, 0x78b0cL, 0xaa98L, 0x78b80L, 0xaa9cL, 0x78b84L, 0xaaa0L, 0x78b88L, 0xaaa4L, 0x78b8cL,+ 0xaaa8L, 0x78b90L, 0xaaacL, 0xcaf80L, 0xaab0L, 0xcaf84L, 0xaab4L, 0xcaf88L, 0xaab8L, 0xcaf8cL, 0xaabcL, 0xcaf90L,+ 0xaac0L, 0xdb30cL, 0xaac4L, 0xdb310L, 0xaac8L, 0xdb384L, 0xaaccL, 0xdb388L, 0xaad0L, 0xdb324L, 0xaad4L, 0xeb704L,+ 0xaad8L, 0xeb6a4L, 0xaadcL, 0xeb6a8L, 0xaae0L, 0xeb710L, 0xaae4L, 0xeb714L, 0xaae8L, 0xeb720L, 0xaaecL, 0xeb724L,+ 0xaaf0L, 0xeb728L, 0xaaf4L, 0xeb72cL, 0xaaf8L, 0xeb7a0L, 0xaafcL, 0xeb7a4L, 0xab00L, 0xeb7a8L, 0xab04L, 0xeb7b0L,+ 0xab08L, 0xeb7b4L, 0xab0cL, 0xeb7b8L, 0xab10L, 0xeb7a5L, 0xab14L, 0xeb7a9L, 0xab18L, 0xeb7adL, 0xab1cL, 0xeb7b1L,+ 0xab20L, 0xeb7b5L, 0xab24L, 0xeb7b9L, 0xab28L, 0xeb7c5L, 0xab2cL, 0xeb7c9L, 0xab30L, 0xeb7d1L, 0xab34L, 0xeb7d5L,+ 0xab38L, 0xeb7d9L, 0xab3cL, 0xeb7c6L, 0xab40L, 0xeb7caL, 0xab44L, 0xeb7ceL, 0xab48L, 0xeb7d2L, 0xab4cL, 0xeb7d6L,+ 0xab50L, 0xeb7c3L, 0xab54L, 0xeb7c7L, 0xab58L, 0xeb7cbL, 0xab5cL, 0xeb7cfL, 0xab60L, 0xeb7d7L, 0xab64L, 0xeb7dbL,+ 0xab68L, 0xeb7dbL, 0xab6cL, 0xeb7dbL, 0xab70L, 0xeb7dbL, 0xab74L, 0xeb7dbL, 0xab78L, 0xeb7dbL, 0xab7cL, 0xeb7dbL,+ 0xab80L, 0xeb7dbL, 0xab84L, 0xeb7dbL, 0xab88L, 0xeb7dbL, 0xab8cL, 0xeb7dbL, 0xab90L, 0xeb7dbL, 0xab94L, 0xeb7dbL,+ 0xab98L, 0xeb7dbL, 0xab9cL, 0xeb7dbL, 0xaba0L, 0xeb7dbL, 0xaba4L, 0xeb7dbL, 0xaba8L, 0xeb7dbL, 0xabacL, 0xeb7dbL,+ 0xabb0L, 0xeb7dbL, 0xabb4L, 0xeb7dbL, 0xabb8L, 0xeb7dbL, 0xabbcL, 0xeb7dbL, 0xabc0L, 0xeb7dbL, 0xabc4L, 0xeb7dbL,+ 0xabc8L, 0xeb7dbL, 0xabccL, 0xeb7dbL, 0xabd0L, 0xeb7dbL, 0xabd4L, 0xeb7dbL, 0xabd8L, 0xeb7dbL, 0xabdcL, 0xeb7dbL,+ 0xabe0L, 0xeb7dbL, 0xabe4L, 0xeb7dbL, 0xabe8L, 0xeb7dbL, 0xabecL, 0xeb7dbL, 0xabf0L, 0xeb7dbL, 0xabf4L, 0xeb7dbL,+ 0xabf8L, 0xeb7dbL, 0xabfcL, 0xeb7dbL, 0xa204L, 0x4L, 0xa20cL, 0x1f000L, 0xb20cL, 0x1f000L, 0xa21cL, 0x1883800aL,+ 0xa230L, 0x108L, 0xa250L, 0x4a000L, 0xa358L, 0x7999aa0eL,+ )+ val txGain2g = longArrayOf(+ 0xa300L, 0x0L, 0xa304L, 0x9200L, 0xa308L, 0x10208L, 0xa30cL, 0x19608L, 0xa310L, 0x1e610L, 0xa314L, 0x24650L,+ 0xa318L, 0x2d6d0L, 0xa31cL, 0x316d2L, 0xa320L, 0x39758L, 0xa324L, 0x3b759L, 0xa328L, 0x3d75aL, 0xa32cL, 0x4175cL,+ 0xa330L, 0x4575eL, 0xa334L, 0x4979fL, 0xa338L, 0x4d7dfL, 0xa33cL, 0x3a95eL, 0xa340L, 0x3e9dfL, 0xa344L, 0x3e9dfL,+ 0xa348L, 0x3e9dfL, 0xa34cL, 0x3e9dfL, 0xa350L, 0x3e9dfL, 0xa354L, 0x3e9dfL, 0x7838L, 0x29L, 0x7824L, 0xd8abffL,+ 0x786cL, 0x48609eb4L, 0x7820L, 0xc04L, 0xa274L, 0xa21c652L, 0xa278L, 0x3bdef7bdL, 0xa27cL, 0x50e83bdL, 0xa394L, 0x3bdef7bdL,+ 0xa398L, 0x3bdL, 0xa3dcL, 0x3bdef7bdL, 0xa3e0L, 0x3bdL,+ )++ val txGainNormal2g = longArrayOf(+ 0xa300L, 0x0L,+ 0xa304L, 0x9200L,+ 0xa308L, 0x10208L,+ 0xa30cL, 0x19608L,+ 0xa310L, 0x1e610L,+ 0xa314L, 0x24650L,+ 0xa318L, 0x2d6d0L,+ 0xa31cL, 0x316d2L,+ 0xa320L, 0x39758L,+ 0xa324L, 0x3b759L,+ 0xa328L, 0x3d75aL,+ 0xa32cL, 0x4175cL,+ 0xa330L, 0x4575eL,+ 0xa334L, 0x4979fL,+ 0xa338L, 0x4d7dfL,+ 0xa33cL, 0x3a95eL,+ 0xa340L, 0x3e9dfL,+ 0xa344L, 0x3e9dfL,+ 0xa348L, 0x3e9dfL,+ 0xa34cL, 0x3e9dfL,+ 0xa350L, 0x3e9dfL,+ 0xa354L, 0x3e9dfL,+ 0x7838L, 0x29L,+ 0x7824L, 0xd8abffL,+ 0x786cL, 0x48609eb4L,+ 0x7820L, 0xc04L,+ 0xa274L, 0xa21c652L,+ 0xa278L, 0x3bdef7bdL,+ 0xa27cL, 0x50e83bdL,+ 0xa394L, 0x3bdef7bdL,+ 0xa398L, 0x3bdL,+ 0xa3dcL, 0x3bdef7bdL,+ 0xa3e0L, 0x3bdL+ )+}diff --git a/app/src/main/java/com/rfsentinel/app/usb/BulkRx.kt b/app/src/main/java/com/rfsentinel/app/usb/BulkRx.ktnew file mode 100644index 0000000..6db153e--- /dev/null+++ b/app/src/main/java/com/rfsentinel/app/usb/BulkRx.kt@@ -0,0 +1,137 @@+package com.rfsentinel.app.usb++import android.hardware.usb.UsbDeviceConnection+import android.hardware.usb.UsbEndpoint+import android.hardware.usb.UsbRequest+import java.nio.ByteBuffer+import java.util.concurrent.TimeoutException++/**+ * Bulk-IN receive loop for the RTL8187 and RT3070 drivers: keeps [count] transfers of+ * [size] bytes in flight (async [UsbRequest]), or falls back to synchronous transfers+ * where the platform can't queue them. [onData] gets each completed transfer; [onTick]+ * runs at least every ~100 ms (channel hops, reports) until [stopped] says so.+ * Returns the bytes received.+ */+internal object BulkRx {++ fun run(tag: String, conn: UsbDeviceConnection, ep: UsbEndpoint, count: Int, size: Int,+ stopped: () -> Boolean, onData: (ByteArray, Int) -> Unit, onTick: (Long) -> Unit): Long {+ val buffers = Array(count) { ByteBuffer.allocateDirect(size) }+ val reqs = ArrayList<UsbRequest>(count)+ var async = true+ for (i in 0 until count) {+ val r = UsbRequest()+ if (!r.initialize(conn, ep)) { async = false; break }+ r.clientData = i+ if (!r.queue(buffers[i])) { runCatching { r.close() }; async = false; break }+ reqs.add(r)+ }+ if (!async) {+ UsbWifi.log("$tag: async RX unavailable (${reqs.size}/$count) - synchronous RX")+ reqs.forEach { runCatching { it.cancel() }; runCatching { it.close() } }+ return runSync(conn, ep, size, stopped, onData, onTick)+ }+ UsbWifi.log("$tag: async RX live - $count buffers in flight")+ val scratch = ByteArray(size)+ var total = 0L+ try {+ while (!stopped()) {+ val req = try { conn.requestWait(100L) } catch (_: TimeoutException) { null }+ if (req != null) {+ val idx = req.clientData as? Int ?: -1+ if (idx in reqs.indices) {+ val b = buffers[idx]+ val n = b.position()+ if (n in 1..size) { b.rewind(); b.get(scratch, 0, n) }+ b.clear()+ if (!runCatching { req.queue(b) }.getOrDefault(false)) {+ runCatching { req.close() }+ val nr = UsbRequest()+ if (runCatching { nr.initialize(conn, ep) }.getOrDefault(false)) {+ nr.clientData = idx+ if (runCatching { nr.queue(b) }.getOrDefault(false)) reqs[idx] = nr+ }+ }+ if (n in 1..size) { total += n; runCatching { onData(scratch, n) } }+ }+ }+ onTick(System.currentTimeMillis())+ }+ } finally {+ reqs.forEach { runCatching { it.cancel() }; runCatching { it.close() } }+ }+ return total+ }++ private fun runSync(conn: UsbDeviceConnection, ep: UsbEndpoint, size: Int, stopped: () -> Boolean,+ onData: (ByteArray, Int) -> Unit, onTick: (Long) -> Unit): Long {+ val buf = ByteArray(size)+ var total = 0L+ while (!stopped()) {+ val n = conn.bulkTransfer(ep, buf, size, 200)+ if (n > 0) { total += n; runCatching { onData(buf, n) } }+ onTick(System.currentTimeMillis())+ }+ return total+ }++ /**+ * Receive counters for the driver log, so a tester's exported log shows what arrived,+ * what was thrown away and the signal range. Only descriptor bytes are ever logged,+ * never a frame's contents (addresses, network names). Used from the RX thread only.+ */+ class Stats(private val tag: String) {+ private val started = System.currentTimeMillis()+ private var lastLog = started+ var transfers = 0L; private set+ private var bytes = 0L; private var frames = 0L; private var noSignal = 0L+ var badChecksum = 0L+ var malformed = 0L+ private var minRssi = Int.MAX_VALUE; private var maxRssi = Int.MIN_VALUE+ private var samples = 0+ private var warnedSilent = false++ fun transfer(n: Int) { transfers++; bytes += n }++ fun frame(rssi: Int?) {+ frames+++ if (rssi == null) noSignal++ else { if (rssi < minRssi) minRssi = rssi; if (rssi > maxRssi) maxRssi = rssi }+ }++ /** The first few transfers' descriptor bytes, to check the parsing from a log. */+ fun sample(what: String, b: ByteArray, from: Int, len: Int) {+ if (samples >= 3 || from < 0) return+ samples+++ UsbWifi.log("$tag: RX sample $samples, $what: " ++ (from until minOf(from + len, b.size)).joinToString(" ") { "%02x".format(b[it]) })+ }++ /** Every 5 s for the first minute, then every 30 s. */+ fun maybeLog(now: Long, extra: () -> String) {+ if (now - lastLog < if (now - started < 60_000) 5_000 else 30_000) return+ lastLog = now+ if (transfers == 0L && !warnedSilent && now - started > 10_000) {+ warnedSilent = true+ UsbWifi.log("$tag: nothing received from the adapter in 10 s (radio or USB receive not running)")+ }+ val signal = if (maxRssi >= minRssi) "signal $minRssi..$maxRssi dBm" else "no signal readings"+ UsbWifi.log("$tag: RX $transfers transfers, ${bytes / 1024} KB: $frames frames ($noSignal without signal), " ++ "$badChecksum bad checksum, $malformed malformed, $signal | ${extra()}")+ minRssi = Int.MAX_VALUE; maxRssi = Int.MIN_VALUE+ }+ }++ /** The bulk-IN endpoint at [address], else the interface's first bulk-IN endpoint. */+ fun inEndpoint(intf: android.hardware.usb.UsbInterface, address: Int): UsbEndpoint? {+ var first: UsbEndpoint? = null+ for (i in 0 until intf.endpointCount) {+ val ep = intf.getEndpoint(i)+ if (ep.type != android.hardware.usb.UsbConstants.USB_ENDPOINT_XFER_BULK ||+ ep.direction != android.hardware.usb.UsbConstants.USB_DIR_IN) continue+ if (ep.address == address) return ep+ if (first == null) first = ep+ }+ return first+ }+}diff --git a/app/src/main/java/com/rfsentinel/app/usb/Mt7612uMonitor.kt b/app/src/main/java/com/rfsentinel/app/usb/Mt7612uMonitor.ktnew file mode 100644index 0000000..4d2c145--- /dev/null+++ b/app/src/main/java/com/rfsentinel/app/usb/Mt7612uMonitor.kt@@ -0,0 +1,619 @@+package com.rfsentinel.app.usb++/*+ * Receive-only monitor mode for MediaTek MT7612U / MT7632U USB WiFi adapters (e.g.+ * ALFA AWUS036ACM, ASUS USB-AC55, Netgear A6210), 2.4 + 5 GHz, driven from userspace+ * over Android's USB host API - no root, no kernel driver. Loads MediaTek's ROM patch+ * and firmware (assets/usbwifi/mt7662*.bin, from linux-firmware; licence in+ * LICENCE.ralink_a_mediatek_company_firmware), hops both bands and reports the access+ * points and client devices it hears. It never transmits.+ *+ * Ported from Wardrive Go by RocketGod (https://github.com/RocketGod-git/wardrive-go,+ * GPL-3.0), which follows the Linux mt76x2u driver (mt76 project). Changes here: frames+ * with a bad checksum are dropped (a corrupted address would show up as a phantom+ * device), the auto-responder (ACK / CTS) is left off, the ROM patch is skipped when an+ * MT7632 already has it (as the kernel does), and the handshake / PMKID capture was removed.+ */++import android.content.Context+import android.hardware.usb.UsbConstants+import android.hardware.usb.UsbDevice+import android.hardware.usb.UsbDeviceConnection+import android.hardware.usb.UsbEndpoint+import android.hardware.usb.UsbManager++object Mt7612uMonitor {+ @Volatile var running = false; private set+ @Volatile private var stop = false++ private val frames = MonitorFrames()+ private val HOP = intArrayOf(+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,+ 36, 40, 44, 48, 52, 56, 60, 64,+ 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 144,+ 149, 153, 157, 161, 165+ )+ private const val DWELL_MS = 125L+ private val FRESH_MS get() = (HOP.size * DWELL_MS * 9 / 5).coerceAtLeast(3000L)+ private const val REPORT_MS = 10_000L+ private const val CAL_TTL_MS = 30_000L++ private const val OUT_VENDOR = 0x40; private const val IN_VENDOR = 0xC0; private const val OUT_CLASS = 0x20+ private const val DEV_MODE = 0x01; private const val MULTI_WRITE = 0x06; private const val MULTI_READ = 0x07+ private const val READ_EEPROM = 0x09; private const val WRITE_FCE = 0x42; private const val WRITE_CFG = 0x46; private const val READ_CFG = 0x47++ // firmware load (mt76x2u_mcu_load_rom_patch / _load_firmware)+ private const val ASIC_VERSION = 0x0000; private const val MCU_CLOCK_CTL = 0x0708; private const val MCU_COM_REG0 = 0x0730+ private const val MCU_SEMAPHORE_03 = 0x07BC+ private const val FCE_PSE_CTRL = 0x0800; private const val FCE_DMA_ADDR = 0x0230; private const val FCE_DMA_LEN = 0x0234+ private const val TX_CPU_FROM_FCE_BASE_PTR = 0x09a0; private const val TX_CPU_FROM_FCE_MAX_COUNT = 0x09a4+ private const val TX_CPU_FROM_FCE_CPU_DESC_IDX = 0x09a8; private const val FCE_PDMA_GLOBAL_CONF = 0x09c4; private const val FCE_SKIP_FS = 0x0a6c+ private const val USB_U3DMA_CFG = 0x9018+ private const val ILM_OFFSET = 0x80000; private const val DLM_OFFSET = 0x110000; private const val ROM_PATCH_OFFSET = 0x90000+ private const val FW_URB_MAX_PAYLOAD = 0x3900; private const val ROM_PATCH_MAX_PAYLOAD = 2048+ private const val FW_HDR_LEN = 32; private const val PATCH_HDR_LEN = 30; private const val REV_E3 = 0x22+ private const val DMA_INFO_BASE = (2 shl 27) or (1 shl 30)++ // MAC / BBP+ private const val WLAN_FUN_CTRL = 0x0080; private const val MAC_CSR0 = 0x1000; private const val MAC_SYS_CTRL = 0x1004+ private const val MAC_STATUS = 0x1200; private const val CH_IDLE = 0x1130; private const val CH_BUSY = 0x1134; private const val RX_STAT_0 = 0x1700+ private const val WPDMA_GLO_CFG = 0x0208; private const val RX_FILTR_CFG = 0x1400; private const val US_CYC_CFG = 0x02a4+ private const val TXOP_CTRL_CFG = 0x1340; private const val COEXCFG0 = 0x0040; private const val EXT_CCA_CFG = 0x141c+ private const val TX_ALC_CFG_4 = 0x13c0; private const val PBF_TX_MAX_PCNT = 0x0408; private const val PBF_RX_MAX_PCNT = 0x040c+ private const val TX_LINK_CFG = 0x1350; private const val AUTO_RSP_CFG = 0x1404; private const val MAX_LEN_CFG = 0x1018+ private const val WMM_AIFSN = 0x0214; private const val WMM_CWMIN = 0x0218; private const val WMM_CWMAX = 0x021c+ private const val CH_TIME_CFG = 0x110c; private const val TX_PIN_CFG = 0x1328; private const val TXOP_HLDR_ET = 0x1608+ private const val XIFS_TIME_CFG = 0x1100; private const val BKOFF_SLOT_CFG = 0x1104; private const val FCE_L2_STUFF = 0x080c+ private const val XO_CTRL5 = 0x0114; private const val XO_CTRL6 = 0x0118; private const val XO_CTRL7 = 0x011c+ private const val ED_CCA_TIMER = 0x1140; private const val ADDR_504 = 0x0504; private const val ADDR_50C = 0x050c+ private const val TX_BAND_CFG = 0x132c; private const val BBP_CORE1 = 0x2004+ private const val BBP_AGC0 = 0x2300; private const val BBP_AGC2 = 0x2308; private const val BBP_AGC7 = 0x231c+ private const val BBP_AGC11 = 0x232c; private const val BBP_AGC61 = 0x23f4; private const val BBP_TXO4 = 0x2610; private const val BBP_RXO13 = 0x2934++ private const val WLAN_EN = 1 shl 0; private const val WLAN_CLK_EN = 1 shl 1+ private const val WLAN_RESET_RF = 1 shl 2; private const val FRC_WL_ANT_SEL = 1 shl 5+ private const val SYS_CTRL_RESET_CSR = 1 shl 0; private const val SYS_CTRL_RESET_BBP = 1 shl 1+ private const val SYS_CTRL_ENABLE_TX = 1 shl 2; private const val SYS_CTRL_ENABLE_RX = 1 shl 3+ private const val WPDMA_TX_DMA_BUSY = 1 shl 1; private const val WPDMA_RX_DMA_BUSY = 1 shl 3+ private const val DMA_RX_DROP_OR_PAD = 1 shl 18; private const val DMA_RX_BULK_AGG_EN = 1 shl 21+ private const val DMA_RX_BULK_EN = 1 shl 22; private const val DMA_TX_BULK_EN = 1 shl 23+ private const val COEX_EN = 1 shl 0+ /** Drop bad checksums, PHY / version errors and control frames; keep everything else (not-to-me, other BSS). */+ private const val RX_FILTER_MONITOR = 0x0001FF13+ /** AUTO_RSP_CFG without the auto-responder (bit 0): the adapter never answers with an ACK or CTS. */+ private const val AUTO_RSP_NO_RESPONDER = 0x12++ private const val DMA_HDR = 4; private const val RXWI_LEN = 32+ private const val RXINFO_L2PAD = 1 shl 14; private const val RXINFO_CRCERR = 1 shl 8++ private const val EE_SIZE = 512; private const val EE_MAC_ADDR = 0x004; private const val EE_NIC_CONF_0 = 0x034+ private const val EE_NIC_CONF_1 = 0x036; private const val EE_NIC_CONF_2 = 0x042; private const val EE_LNA_GAIN = 0x044+ private const val EE_RSSI_OFFSET_2G_0 = 0x046; private const val EE_RSSI_OFFSET_2G_1 = 0x048; private const val EE_RSSI_OFFSET_5G_0 = 0x04a+ private const val EE_XTAL_TRIM_1 = 0x03a; private const val EE_XTAL_TRIM_2 = 0x09e++ private const val CMD_FUN_SET_OP = 1; private const val CMD_LOAD_CR = 2; private const val CMD_INIT_GAIN_OP = 3+ private const val CMD_POWER_SAVING_OP = 20; private const val CMD_SWITCH_CHANNEL_OP = 30; private const val CMD_CALIBRATION_OP = 31+ private const val Q_SELECT = 1; private const val RADIO_ON = 0x31; private const val MT_RF_BBP_CR = 2+ private const val MCU_CAL_TEMP = 2; private const val MCU_CAL_RXDCOC = 3; private const val MCU_CAL_RC = 4+ private const val MCU_CAL_LC = 6; private const val MCU_CAL_TX_LOFT = 7; private const val MCU_CAL_TXIQ = 8+ private const val MCU_CAL_RXIQC_FI = 12; private const val MCU_CAL_TX_SHAPING = 15++ private lateinit var conn: UsbDeviceConnection+ private var epResp: UsbEndpoint? = null+ private var seq = 0+ private var mcuLogged = 0+ private var mcuGain = 0+ private var rssiOff2g = 0; private var rssiOff5g = 0; private var lna2g = 0; private var lna5g = 0+ private val lastCalMs = HashMap<Int, Long>()+ @Volatile private var ctlErrors = 0++ fun abort() { stop = true }++ fun run(ctx: Context, device: UsbDevice, chipName: String, onStatus: (String) -> Unit,+ onFrame: (List<MonitorSighting>) -> Unit) {+ if (running) return+ running = true; stop = false; frames.clear(); lastCalMs.clear(); mcuLogged = 0; ctlErrors = 0+ val mgr = ctx.getSystemService(Context.USB_SERVICE) as UsbManager+ val c = mgr.openDevice(device) ?: run { onStatus("$chipName: couldn't reopen adapter"); running = false; return }+ conn = c+ try {+ val intf = device.getInterface(0)+ if (!c.claimInterface(intf, true)) UsbWifi.log("MT7612U: couldn't claim the USB interface (continuing)")+ val bulkIn = ArrayList<UsbEndpoint>(); val bulkOut = ArrayList<UsbEndpoint>()+ for (i in 0 until intf.endpointCount) {+ val ep = intf.getEndpoint(i)+ if (ep.type == UsbConstants.USB_ENDPOINT_XFER_BULK) { if (ep.direction == UsbConstants.USB_DIR_IN) bulkIn += ep else bulkOut += ep }+ }+ val rx = bulkIn.getOrNull(0); val cmdOut = bulkOut.getOrNull(0)+ epResp = bulkIn.getOrNull(1)+ UsbWifi.log("=== MT7612U bring-up (mt76x2u) ===")+ UsbWifi.log("MT7612U: bulk IN [${bulkIn.joinToString { "0x%02x".format(it.address) }}] OUT [${bulkOut.joinToString { "0x%02x".format(it.address) }}]")+ if (rx == null || cmdOut == null) { onStatus("$chipName: no RX / command endpoint"); return }+ val t0 = System.currentTimeMillis()++ // ---- firmware ----+ val ver = regRd(ASIC_VERSION)+ val chip = ver ushr 16; val e3 = (ver and 0xffff) >= REV_E3+ UsbWifi.log("MT7612U: ASIC_VERSION 0x%08x (chip %04x, %s)".format(ver, chip, if (e3) "E3+" else "pre-E3"))+ onStatus("$chipName · loading firmware…")+ val patch = ctx.assets.open("usbwifi/mt7662_rom_patch.bin").use { it.readBytes() }+ val fw = ctx.assets.open("usbwifi/mt7662.bin").use { it.readBytes() }+ if (!loadRomPatch(cmdOut, patch, e3, romProtect = chip != 0x7612)) { onStatus("$chipName: ROM patch failed (replug)"); return }+ if (!loadFirmware(cmdOut, fw, e3)) { onStatus("$chipName: firmware didn't start (replug)"); return }++ // ---- radio ----+ onStatus("$chipName · powering on radio…")+ resetWlan()+ powerOn()+ if (!poll(1000, 5) { regRd(MAC_CSR0).let { it != 0 && it != -1 } }) { onStatus("$chipName: MAC not ready (replug)"); return }+ initDma()+ mcuCmd(cmdOut, CMD_FUN_SET_OP, leWords(Q_SELECT, 1), false)+ mcuCmd(cmdOut, CMD_POWER_SAVING_OP, leWords(RADIO_ON, 0), false)+ macReset()+ val ee = readEeprom()+ mcuGain = computeMcuGain(ee)+ computeRssiCal(ee)+ UsbWifi.log("MT7612U: EEPROM MAC %s:xx:xx:xx, NIC_CONF 0x%04x/0x%04x, mcu_gain 0x%08x, rssi_off 2g %d 5g %d, lna 2g %d 5g %d".format(+ (0 until 3).joinToString(":") { "%02x".format(ee[EE_MAC_ADDR + it].toInt() and 0xff) },+ le16(ee, EE_NIC_CONF_0), le16(ee, EE_NIC_CONF_1), mcuGain, rssiOff2g, rssiOff5g, lna2g, lna5g))+ fixupXtal(ee)+ regRmw(US_CYC_CFG, 0xff, 0x1e)+ regWr(TXOP_CTRL_CFG, 0x583f)++ onStatus("$chipName · loading RF / BBP registers…")+ loadCr(cmdOut, ee, HOP[0])+ onStatus("$chipName · tuning and calibrating…")+ regWr(BBP_AGC0, (regRd(BBP_AGC0) and (1 shl 4).inv()) or (1 shl 3)) // RX path+ tune(cmdOut, HOP[0], scan = false)+ macStart()+ UsbWifi.log("MT7612U: started in %d ms - SYS_CTRL 0x%08x STATUS 0x%08x U3DMA 0x%08x RX_FILTR 0x%08x AUTO_RSP 0x%08x AGC0 0x%08x, USB errors %d - monitor live ch %d".format(+ System.currentTimeMillis() - t0, regRd(MAC_SYS_CTRL), regRd(MAC_STATUS), cfgRd(USB_U3DMA_CFG), regRd(RX_FILTR_CFG),+ regRd(AUTO_RSP_CFG), regRd(BBP_AGC0), ctlErrors, HOP[0]))+ onStatus("$chipName · live · 2.4 + 5 GHz monitor")+ rxLoop(chipName, cmdOut, rx, onFrame, onStatus)+ } catch (e: Exception) {+ UsbWifi.log("MT7612U: bring-up error - ${UsbWifi.describe(e)}")+ onStatus("$chipName: error · ${e.message}")+ } finally {+ runCatching { c.close() }+ running = false+ }+ }++ // ---- firmware ----++ private fun loadRomPatch(out: UsbEndpoint, patch: ByteArray, e3: Boolean, romProtect: Boolean): Boolean {+ if (patch.size <= PATCH_HDR_LEN) return false+ val patchReg = if (e3) MCU_CLOCK_CTL else MCU_COM_REG0+ val patchMask = if (e3) 0x1 else 0x2+ if (romProtect) {+ if (!poll(600, 10) { regRd(MCU_SEMAPHORE_03) and 1 == 1 }) { UsbWifi.log("MT7612U: no hardware semaphore for the ROM patch"); return false }+ if (regRd(patchReg) and patchMask != 0) { UsbWifi.log("MT7612U: ROM patch already applied"); regWr(MCU_SEMAPHORE_03, 1); return true }+ }+ UsbWifi.log("MT7612U: ROM patch build '${asciiz(patch, 0, 16)}', ${patch.size - PATCH_HDR_LEN} B")+ cfgWr(USB_U3DMA_CFG, DMA_RX_BULK_EN or DMA_TX_BULK_EN or 0x20)+ vendor(DEV_MODE, OUT_VENDOR, 0x1, null) // firmware reset+ sleep(8)+ configureFce()+ val sent = sendFw(out, patch, PATCH_HDR_LEN, patch.size - PATCH_HDR_LEN, ROM_PATCH_MAX_PAYLOAD, ROM_PATCH_OFFSET)+ if (sent) {+ vendor(DEV_MODE, OUT_CLASS, 0x12, byteArrayOf(0x6f, 0xfc.toByte(), 0x08, 0x01, 0x20, 0x04, 0x00, 0x00, 0x00, 0x09, 0x00)) // enable patch+ vendor(DEV_MODE, OUT_CLASS, 0x12, byteArrayOf(0x6f, 0xfc.toByte(), 0x05, 0x01, 0x07, 0x01, 0x00, 0x04)) // reset WMT+ sleep(20)+ val applied = poll(100, 10) { regRd(patchReg) and patchMask == patchMask }+ UsbWifi.log("MT7612U: ROM patch ${if (applied) "applied" else "not acknowledged (continuing)"}")+ }+ if (romProtect) regWr(MCU_SEMAPHORE_03, 1)+ return sent+ }++ private fun loadFirmware(out: UsbEndpoint, fw: ByteArray, e3: Boolean): Boolean {+ if (fw.size <= FW_HDR_LEN) return false+ val ilmLen = le32(fw, 0); val dlmLen = le32(fw, 4); val fwVer = le16(fw, 10)+ if (FW_HDR_LEN + ilmLen + dlmLen != fw.size) { UsbWifi.log("MT7612U: firmware file size mismatch"); return false }+ UsbWifi.log("MT7612U: firmware %d.%d.%02d build '%s', ILM %d B, DLM %d B".format(+ (fwVer shr 12) and 0xf, (fwVer shr 8) and 0xf, fwVer and 0xf, asciiz(fw, 16, 16), ilmLen, dlmLen))+ vendor(DEV_MODE, OUT_VENDOR, 0x1, null) // firmware reset+ sleep(8)+ cfgWr(USB_U3DMA_CFG, DMA_RX_BULK_EN or DMA_TX_BULK_EN or 0x20)+ configureFce()+ if (!sendFw(out, fw, FW_HDR_LEN, ilmLen, FW_URB_MAX_PAYLOAD, ILM_OFFSET)) return false+ if (!sendFw(out, fw, FW_HDR_LEN + ilmLen, dlmLen, FW_URB_MAX_PAYLOAD, if (e3) DLM_OFFSET + 0x800 else DLM_OFFSET)) return false+ vendor(DEV_MODE, OUT_VENDOR, 0x12, null) // load IVB+ if (!poll(100, 10) { regRd(MCU_COM_REG0) and 0x1 == 0x1 }) { UsbWifi.log("MT7612U: firmware failed to start"); return false }+ regWr(MCU_COM_REG0, regRd(MCU_COM_REG0) or 0x2)+ regWr(FCE_PSE_CTRL, 0x1)+ UsbWifi.log("MT7612U: firmware running")+ return true+ }++ private fun sendFw(out: UsbEndpoint, src: ByteArray, srcOff: Int, dataLen: Int, maxPayload: Int, dstAddr: Int): Boolean {+ val maxLen = maxPayload - 8+ var pos = 0+ while (pos < dataLen) {+ val len = minOf(dataLen - pos, maxLen)+ val rounded = (len + 3) and 3.inv()+ val buf = ByteArray(4 + rounded + 4)+ putLe32(buf, 0, DMA_INFO_BASE or (len and 0xffff))+ System.arraycopy(src, srcOff + pos, buf, 4, len)+ singleWr(WRITE_FCE, FCE_DMA_ADDR, dstAddr + pos)+ singleWr(WRITE_FCE, FCE_DMA_LEN, rounded shl 16)+ if (conn.bulkTransfer(out, buf, buf.size, 1000) < 0) { UsbWifi.log("MT7612U: firmware upload failed at $pos of $dataLen B"); return false }+ regWr(TX_CPU_FROM_FCE_CPU_DESC_IDX, regRd(TX_CPU_FROM_FCE_CPU_DESC_IDX) + 1)+ pos += len+ sleep(5)+ }+ return true+ }++ private fun configureFce() {+ regWr(FCE_PSE_CTRL, 0x1); regWr(TX_CPU_FROM_FCE_BASE_PTR, 0x400230); regWr(TX_CPU_FROM_FCE_MAX_COUNT, 0x1)+ regWr(FCE_PDMA_GLOBAL_CONF, 0x44); regWr(FCE_SKIP_FS, 0x3)+ }++ // ---- radio bring-up ----++ private fun resetWlan() {+ var v = regRd(WLAN_FUN_CTRL) and FRC_WL_ANT_SEL.inv()+ if (v and WLAN_EN != 0) { regWr(WLAN_FUN_CTRL, v or WLAN_RESET_RF); sleep(1); v = v and WLAN_RESET_RF.inv() }+ regWr(WLAN_FUN_CTRL, v); sleep(1)+ v = v or WLAN_EN; regWr(WLAN_FUN_CTRL, v); sleep(1)+ v = v or WLAN_CLK_EN; regWr(WLAN_FUN_CTRL, v); sleep(1)+ }++ private fun powerOn() {+ cfgSet(0x148, 1 shl 0)+ val up = (1 shl 28) or (1 shl 12) or (1 shl 13)+ if (!poll(1000, 2) { cfgRd(0x148) and up == up }) UsbWifi.log("MT7612U: power-on poll timed out (continuing)")+ cfgClear(0x148, 0x7f shl 16); sleep(1)+ cfgClear(0x148, 0xf shl 24); sleep(1)+ cfgSet(0x148, 0xf shl 24); cfgClear(0x148, 0xfff)+ cfgClear(0x1204, 1 shl 3)+ cfgSet(0x80, 1 shl 0)+ cfgClear(0x64, 1 shl 18)+ powerOnRf(0); powerOnRf(1)+ }++ private fun powerOnRf(unit: Int) {+ val s = if (unit != 0) 8 else 0+ cfgSet(0x130, 1 shl s); sleep(1)+ cfgSet(0x130, ((1 shl 1) or (1 shl 3) or (1 shl 4) or (1 shl 5)) shl s); sleep(1)+ cfgClear(0x130, (1 shl 2) shl s); sleep(1)+ cfgSet(0x130, (1 shl 0) or (1 shl 16)); sleep(1)+ cfgClear(0x1c, 0xff); cfgSet(0x1c, 0x30)+ cfgWr(0x14, 0x484f); sleep(1)+ cfgSet(0x130, 1 shl 17); sleep(1)+ cfgClear(0x130, 1 shl 16); sleep(1)+ cfgSet(0x14c, (1 shl 19) or (1 shl 20))+ regWr(0x530, 0xf)+ }++ private fun initDma() {+ var v = cfgRd(USB_U3DMA_CFG)+ v = v or DMA_RX_DROP_OR_PAD or DMA_RX_BULK_EN or DMA_TX_BULK_EN+ v = v and DMA_RX_BULK_AGG_EN.inv() // one frame per transfer+ cfgWr(USB_U3DMA_CFG, v)+ }++ private fun macReset() {+ regWr(WPDMA_GLO_CFG, (1 shl 4) or (1 shl 5))+ regWr(PBF_TX_MAX_PCNT, 0xefef3f1f.toInt())+ regWr(PBF_RX_MAX_PCNT, 0xfebf)+ for (p in MAC_INITVALS) regWr(p[0], p[1])+ regWr(TX_LINK_CFG, 0x1020)+ regWr(AUTO_RSP_CFG, AUTO_RSP_NO_RESPONDER)+ regWr(MAX_LEN_CFG, 0x2f00)+ regWr(WMM_AIFSN, 0x2273); regWr(WMM_CWMIN, 0x2344); regWr(WMM_CWMAX, 0x34aa)+ regClear(MAC_SYS_CTRL, SYS_CTRL_RESET_CSR or SYS_CTRL_RESET_BBP)+ regClear(COEXCFG0, COEX_EN)+ regSet(EXT_CCA_CFG, 0xf000)+ regClear(TX_ALC_CFG_4, 1 shl 31)+ }++ private fun macStart() {+ regWr(MAC_SYS_CTRL, SYS_CTRL_ENABLE_TX)+ waitWpdma()+ regWr(RX_FILTR_CFG, RX_FILTER_MONITOR)+ regWr(MAC_SYS_CTRL, SYS_CTRL_ENABLE_TX or SYS_CTRL_ENABLE_RX)+ waitWpdma()+ regWr(CH_TIME_CFG, 0x15f)+ regRd(CH_BUSY); regRd(CH_IDLE)+ }++ /** Hops use the firmware's quick channel switch; the full calibration runs on the first tune and every 30 s per channel. */+ private fun tune(ep: UsbEndpoint, ch: Int, scan: Boolean) {+ val is5 = if (ch <= 14) 0 else 1+ if (is5 == 0) { regSet(TX_BAND_CFG, 1 shl 2); regClear(TX_BAND_CFG, 1 shl 1) }+ else { regClear(TX_BAND_CFG, 1 shl 2); regSet(TX_BAND_CFG, 1 shl 1) }+ regRmw(BBP_CORE1, 0x18, 0)+ regRmw(BBP_AGC0, 0x7000, 1 shl 12)+ val wait = !scan+ val m = byteArrayOf(ch.toByte(), if (scan) 1 else 0, 0, 0, 0x03, 0x00, 0x00, 0x00)+ mcuCmd(ep, CMD_SWITCH_CHANNEL_OP, m, wait); sleep(6)+ m[6] = 0xe0.toByte()+ mcuCmd(ep, CMD_SWITCH_CHANNEL_OP, m, wait)++ val now = System.currentTimeMillis()+ if (!scan || now - (lastCalMs[ch] ?: 0L) > CAL_TTL_MS) {+ mcuCmd(ep, CMD_INIT_GAIN_OP, leWords(ch or (1 shl 31), mcuGain), wait)+ regSet(BBP_RXO13, 1 shl 10)+ mcuCmd(ep, CMD_CALIBRATION_OP, leWords(MCU_CAL_RXDCOC, ch), wait)+ mcuCmd(ep, CMD_CALIBRATION_OP, leWords(MCU_CAL_RC, 0), wait)+ regWr(BBP_AGC61, 0xff64a4e2.toInt()); regWr(BBP_AGC7, 0x08081010)+ regWr(BBP_AGC11, 0x00000404); regWr(BBP_AGC2, 0x00007070)+ regWr(TXOP_CTRL_CFG, 0x04101b3f)+ regSet(BBP_TXO4, 1 shl 25); regSet(BBP_RXO13, 1 shl 8)+ lastCalMs[ch] = now+ }+ if (scan) return+ if (is5 == 1) mcuCmd(ep, CMD_CALIBRATION_OP, leWords(MCU_CAL_LC, 0), true)+ mcuCmd(ep, CMD_CALIBRATION_OP, leWords(MCU_CAL_TX_LOFT, is5), true)+ mcuCmd(ep, CMD_CALIBRATION_OP, leWords(MCU_CAL_TXIQ, is5), true)+ mcuCmd(ep, CMD_CALIBRATION_OP, leWords(MCU_CAL_RXIQC_FI, is5), true)+ mcuCmd(ep, CMD_CALIBRATION_OP, leWords(MCU_CAL_TEMP, 0), true)+ mcuCmd(ep, CMD_CALIBRATION_OP, leWords(MCU_CAL_TX_SHAPING, 0), true)+ // EDCCA setup (the auto-responder stays off)+ regSet(TX_LINK_CFG, 1 shl 12)+ regClear(TXOP_CTRL_CFG, 1 shl 20)+ regWr(BBP_AGC2, 0x00007070)+ regSet(TXOP_HLDR_ET, 1 shl 1)+ regSet(MAC_SYS_CTRL, SYS_CTRL_ENABLE_TX)+ regWr(TX_PIN_CFG, regRd(TX_PIN_CFG) or 0xf or (0xf shl 8) or (1 shl 16) or (1 shl 18))+ regRd(ED_CCA_TIMER)+ }++ private fun fixupXtal(ee: ByteArray) {+ var ev = le16(ee, EE_XTAL_TRIM_2)+ var offset = ev and 0x7f+ if ((ev and 0xff) == 0xff) offset = 0 else if (ev and 0x80 != 0) offset = -offset+ ev = ev shr 8+ if (ev == 0x00 || ev == 0xff) {+ ev = le16(ee, EE_XTAL_TRIM_1) and 0xff+ if (ev == 0x00 || ev == 0xff) ev = 0x14+ }+ ev = ev and 0x7f+ val c2 = (ev + offset) and 0x7f+ cfgWr(XO_CTRL5, (cfgRd(XO_CTRL5) and (0x7f shl 8).inv()) or (c2 shl 8))+ cfgSet(XO_CTRL6, 0x7f shl 8)+ regWr(ADDR_504, 0x06000000); regWr(ADDR_50C, 0x08800000); sleep(5); regWr(ADDR_504, 0)+ regRmw(XIFS_TIME_CFG, 0xff shl 8, 0xd shl 8)+ regRmw(BKOFF_SLOT_CFG, 0xf shl 8, 1 shl 8)+ regClear(FCE_L2_STUFF, 1 shl 4)+ when ((le16(ee, EE_NIC_CONF_2) shr 9) and 0x3) {+ 0 -> regWr(XO_CTRL7, 0x5c1fee80)+ 1 -> regWr(XO_CTRL7, 0x5c1feed0)+ }+ }++ private fun loadCr(ep: UsbEndpoint, ee: ByteArray, ch: Int) {+ val nc0 = le16(ee, EE_NIC_CONF_0); val nc1 = le16(ee, EE_NIC_CONF_1)+ val cfg = (1 shl 31) or ((nc0 shr 8) and 0xff) or ((nc1 shl 8) and 0xff00)+ val m = ByteArray(8); m[0] = MT_RF_BBP_CR.toByte(); m[2] = ch.toByte(); putLe32(m, 4, cfg)+ mcuCmd(ep, CMD_LOAD_CR, m, true)+ }++ private fun mcuCmd(ep: UsbEndpoint, cmd: Int, payload: ByteArray, waitResp: Boolean) {+ seq = (seq + 1) and 0xf; if (seq == 0) seq = 1+ val rounded = (payload.size + 3) and 3.inv()+ val txinfo = (rounded and 0xffff) or (2 shl 27) or (seq shl 16) or (cmd shl 20) or (1 shl 30)+ val buf = ByteArray(4 + rounded + 4)+ putLe32(buf, 0, txinfo); System.arraycopy(payload, 0, buf, 4, payload.size)+ if (conn.bulkTransfer(ep, buf, buf.size, 1000) < 0) ctlErrors+++ if (!waitResp) return+ val rep = epResp ?: run { sleep(10); return }+ val rb = ByteArray(512)+ val n = conn.bulkTransfer(rep, rb, rb.size, 300)+ if (mcuLogged < 6) {+ mcuLogged+++ UsbWifi.log(if (n > 0) "MT7612U: MCU cmd $cmd answered ($n B, 0x%08x)".format(if (n >= 4) le32(rb, 0) else 0)+ else "MT7612U: MCU cmd $cmd - no answer ($n)")+ }+ }++ private fun drainCmdResp() {+ val ep = epResp ?: return+ val tmp = ByteArray(512)+ repeat(6) { if (conn.bulkTransfer(ep, tmp, tmp.size, 1) <= 0) return }+ }++ private fun reKickRx() {+ regClear(MAC_SYS_CTRL, SYS_CTRL_ENABLE_RX)+ val v = cfgRd(USB_U3DMA_CFG)+ cfgWr(USB_U3DMA_CFG, v and DMA_RX_BULK_EN.inv()); cfgWr(USB_U3DMA_CFG, v or DMA_RX_BULK_EN)+ regSet(MAC_SYS_CTRL, SYS_CTRL_ENABLE_RX)+ }++ // ---- receive ----++ private class RxState { var hopAt = 0L; var lastEmit = 0L; var lastRxAt = 0L; var lastCheck = 0L; var hopIdx = 0 }++ private fun rxLoop(chipName: String, epCmd: UsbEndpoint, ep: UsbEndpoint,+ onFrame: (List<MonitorSighting>) -> Unit, onStatus: (String) -> Unit) {+ val st = RxState()+ val t0 = System.currentTimeMillis(); st.hopAt = t0; st.lastEmit = t0; st.lastRxAt = t0; st.lastCheck = t0+ val stats = BulkRx.Stats("MT7612U")+ val total = BulkRx.run("MT7612U", conn, ep, 24, 4096, { stop }, onData@{ b, n ->+ stats.transfer(n)+ st.lastRxAt = System.currentTimeMillis()+ stats.sample("$n bytes, DMA header + RXWI", b, 0, DMA_HDR + 16)+ val ch = HOP[st.hopIdx]+ val f = parseRx(b, n, onBad = { crc -> if (crc) stats.badChecksum++ else stats.malformed++ }) ?: return@onData+ val rssi = f.rawRssi?.let { if (ch <= 14) it + rssiOff2g - lna2g else it + rssiOff5g - lna5g }+ stats.frame(rssi)+ frames.frame(b, f.start, f.end, ch, rssi)+ }) { now ->+ stats.maybeLog(now) {+ val (aps, clients) = frames.live(now, REPORT_MS)+ val busy = regRd(CH_BUSY); val rs0 = regRd(RX_STAT_0) // clear on read+ "ch ${HOP[st.hopIdx]}, $aps access points, $clients devices, channel busy $busy, " ++ "radio drops: ${rs0 and 0xffff} checksum / ${(rs0 ushr 16) and 0xffff} PHY, USB errors $ctlErrors"+ }+ if (now - st.lastCheck > 3000) {+ st.lastCheck = now+ // Energy on the air but nothing arriving for a while: restart the USB receive path.+ if (now - st.lastRxAt > 6000 && regRd(CH_BUSY) > 50000) {+ UsbWifi.log("MT7612U: receive stalled (${(now - st.lastRxAt) / 1000} s) - restarting it")+ runCatching { reKickRx() }+ st.lastRxAt = now+ }+ }+ if (now - st.lastEmit > 2000) { emit(onFrame); st.lastEmit = now }+ if (now - st.hopAt > DWELL_MS) {+ st.hopIdx = (st.hopIdx + 1) % HOP.size+ runCatching { tune(epCmd, HOP[st.hopIdx], scan = true) }+ drainCmdResp()+ val (aps, clients) = frames.live(now, REPORT_MS)+ onStatus("$chipName · live · $aps access points · $clients devices · ch ${HOP[st.hopIdx]}")+ st.hopAt = now+ }+ }+ emit(onFrame)+ UsbWifi.log("MT7612U: RX loop stopped ($total B)")+ }++ private fun emit(onFrame: (List<MonitorSighting>) -> Unit) {+ val batch = frames.drain(System.currentTimeMillis(), FRESH_MS)+ if (batch.isNotEmpty()) onFrame(batch)+ }++ /** Where the 802.11 frame sits in a transfer and the radio's raw RSSI (chain 0, before calibration; null when absent). */+ internal data class Rx(val start: Int, val end: Int, val rawRssi: Int?)++ /**+ * One transfer: | DMA header (4: length) | RXWI (32) | 802.11 header | L2 pad (2, when flagged) | body | FCE info |.+ * The L2 pad is removed in place (the header moves up 2 bytes), as mt76 does, so the frame+ * is contiguous. Null for a bad checksum or a malformed transfer ([onBad] says which).+ */+ internal fun parseRx(b: ByteArray, n: Int, onBad: (Boolean) -> Unit = {}): Rx? {+ if (n < DMA_HDR + RXWI_LEN + 24 || n > b.size) { onBad(false); return null }+ val dmaLen = (b[0].toInt() and 0xff) or ((b[1].toInt() and 0xff) shl 8)+ if (dmaLen < RXWI_LEN + 24 || DMA_HDR + dmaLen > n) { onBad(false); return null }+ val rxwi = DMA_HDR+ val rxinfo = le32(b, rxwi)+ if (rxinfo and RXINFO_CRCERR != 0) { onBad(true); return null }+ val mpdu = (le32(b, rxwi + 4) ushr 16) and 0x3fff+ var d = rxwi + RXWI_LEN+ val pad = if (rxinfo and RXINFO_L2PAD != 0) 2 else 0+ if (mpdu < 24 || d + mpdu + pad > DMA_HDR + dmaLen) { onBad(false); return null }+ if (pad != 0) {+ val hdr = headerLength(b, d).coerceAtMost(mpdu)+ System.arraycopy(b, d, b, d + pad, hdr)+ d += pad+ }+ val raw = b[rxwi + 12].toInt() // RSSI chain 0, signed dBm-ish+ return Rx(d, d + mpdu, if (raw != 0) raw else null)+ }++ /** 802.11 header length from its frame control (address 4, QoS, HT control). */+ private fun headerLength(b: ByteArray, d: Int): Int {+ val fc = b[d].toInt() and 0xff; val fc1 = b[d + 1].toInt() and 0xff+ val type = (fc shr 2) and 3; val sub = (fc shr 4) and 0xf+ var len = 24+ if (type == 2) {+ if (fc1 and 0x03 == 0x03) len += 6+ if (sub and 0x8 != 0) { len += 2; if (fc1 and 0x80 != 0) len += 4 }+ } else if (type == 0 && fc1 and 0x80 != 0) len += 4+ return len+ }++ private fun computeRssiCal(ee: ByteArray) {+ fun signExt(v: Int, bits: Int): Int { val s = 1 shl (bits - 1); return if (v and s != 0) v - (1 shl bits) else v }+ fun rssiOff(v: Int): Int { val b0 = v and 0xff; return if (b0 == 0 || b0 == 0xff || b0 and 0x80 == 0) 0 else signExt(b0, 7) }+ fun lnaOf(v: Int): Int { val b0 = v and 0xff; return if (b0 == 0xff) 0 else signExt(b0, 8) }+ rssiOff2g = rssiOff(le16(ee, EE_RSSI_OFFSET_2G_0))+ rssiOff5g = rssiOff(le16(ee, EE_RSSI_OFFSET_5G_0))+ lna2g = lnaOf(le16(ee, EE_LNA_GAIN))+ lna5g = lnaOf(le16(ee, EE_LNA_GAIN) ushr 8)+ }++ private fun computeMcuGain(ee: ByteArray): Int {+ val v044 = le16(ee, EE_LNA_GAIN)+ val lna2 = v044 and 0xff+ val lna5g0 = (v044 ushr 8) and 0xff+ var lna5g1 = (le16(ee, EE_RSSI_OFFSET_2G_1) ushr 8) and 0xff+ if (lna5g1 == 0 || lna5g1 == 0xff) lna5g1 = lna5g0+ return lna2 or (lna5g0 shl 8) or (lna5g1 shl 16) or (lna5g0 shl 24)+ }++ private fun readEeprom(): ByteArray {+ val ee = ByteArray(EE_SIZE)+ var failed = 0+ var i = 0+ while (i + 4 <= EE_SIZE) {+ val b = ByteArray(4)+ if (conn.controlTransfer(IN_VENDOR, READ_EEPROM, 0, i, b, 4, 1000) == 4) System.arraycopy(b, 0, ee, i, 4) else failed+++ i += 4+ }+ if (failed > 0) UsbWifi.log("MT7612U: $failed of ${EE_SIZE / 4} EEPROM reads failed")+ return ee+ }++ // ---- register access ----++ private fun vendor(req: Int, reqType: Int, value: Int, data: ByteArray?) {+ if (conn.controlTransfer(reqType, req, value, 0, data, data?.size ?: 0, 1000) < 0) ctlErrors+++ }+ private fun regWr(addr: Int, v: Int) {+ val b = ByteArray(4); putLe32(b, 0, v)+ if (conn.controlTransfer(OUT_VENDOR, MULTI_WRITE, (addr ushr 16) and 0xffff, addr and 0xffff, b, 4, 1000) < 0) ctlErrors+++ }+ private fun regRd(addr: Int): Int {+ val b = ByteArray(4)+ if (conn.controlTransfer(IN_VENDOR, MULTI_READ, (addr ushr 16) and 0xffff, addr and 0xffff, b, 4, 1000) != 4) { ctlErrors++; return 0 }+ return le32(b, 0)+ }+ private fun regSet(addr: Int, bits: Int) = regWr(addr, regRd(addr) or bits)+ private fun regClear(addr: Int, bits: Int) = regWr(addr, regRd(addr) and bits.inv())+ private fun regRmw(addr: Int, mask: Int, v: Int) = regWr(addr, (regRd(addr) and mask.inv()) or v)+ private fun cfgWr(addr: Int, v: Int) {+ val b = ByteArray(4); putLe32(b, 0, v)+ if (conn.controlTransfer(OUT_VENDOR, WRITE_CFG, (addr ushr 16) and 0xffff, addr and 0xffff, b, 4, 1000) < 0) ctlErrors+++ }+ private fun cfgRd(addr: Int): Int {+ val b = ByteArray(4)+ if (conn.controlTransfer(IN_VENDOR, READ_CFG, (addr ushr 16) and 0xffff, addr and 0xffff, b, 4, 1000) != 4) { ctlErrors++; return 0 }+ return le32(b, 0)+ }+ private fun cfgSet(addr: Int, bits: Int) = cfgWr(addr, cfgRd(addr) or bits)+ private fun cfgClear(addr: Int, bits: Int) = cfgWr(addr, cfgRd(addr) and bits.inv())+ private fun singleWr(req: Int, offset: Int, v: Int) {+ conn.controlTransfer(OUT_VENDOR, req, v and 0xffff, offset, null, 0, 1000)+ conn.controlTransfer(OUT_VENDOR, req, (v ushr 16) and 0xffff, offset + 2, null, 0, 1000)+ }+ private fun waitWpdma() = poll(1000, 2) { regRd(WPDMA_GLO_CFG) and (WPDMA_TX_DMA_BUSY or WPDMA_RX_DMA_BUSY) == 0 }++ private inline fun poll(ms: Int, stepMs: Int, ok: () -> Boolean): Boolean {+ val end = System.currentTimeMillis() + ms+ do { if (ok()) return true; sleep(stepMs) } while (System.currentTimeMillis() < end)+ return false+ }++ private fun leWords(vararg w: Int): ByteArray { val b = ByteArray(w.size * 4); for (i in w.indices) putLe32(b, i * 4, w[i]); return b }+ private fun putLe32(b: ByteArray, i: Int, v: Int) { b[i] = v.toByte(); b[i + 1] = (v ushr 8).toByte(); b[i + 2] = (v ushr 16).toByte(); b[i + 3] = (v ushr 24).toByte() }+ private fun le32(b: ByteArray, i: Int) = (b[i].toInt() and 0xff) or ((b[i + 1].toInt() and 0xff) shl 8) or+ ((b[i + 2].toInt() and 0xff) shl 16) or ((b[i + 3].toInt() and 0xff) shl 24)+ private fun le16(b: ByteArray, i: Int) = (b[i].toInt() and 0xff) or ((b[i + 1].toInt() and 0xff) shl 8)+ private fun asciiz(b: ByteArray, off: Int, max: Int) = String(b, off, minOf(max, b.size - off), Charsets.US_ASCII).trim { it <= ' ' }+ private fun sleep(ms: Int) = try { Thread.sleep(ms.toLong()) } catch (_: InterruptedException) {}++ private val MAC_INITVALS = arrayOf(+ intArrayOf(0x0400, 0x00080c00), intArrayOf(0x0404, 0x1efebcff), intArrayOf(0x0800, 0x00000001),+ intArrayOf(0x1004, 0x00000000), intArrayOf(0x1018, 0x003e3f00), intArrayOf(0x1030, 0xaaa99887.toInt()),+ intArrayOf(0x1034, 0x000000aa), intArrayOf(0x1100, 0x33a40d0a), intArrayOf(0x1104, 0x00000209),+ intArrayOf(0x1118, 0x00422010), intArrayOf(0x1204, 0x00000000), intArrayOf(0x1238, 0x001700c8),+ intArrayOf(0x1330, 0x00101001), intArrayOf(0x1334, 0x00010000), intArrayOf(0x1338, 0x00000000),+ intArrayOf(0x1340, 0x0400583f), intArrayOf(0x1344, 0x00ffff20), intArrayOf(0x1348, 0x000a2290),+ intArrayOf(0x134c, 0x47f01f0f), intArrayOf(0x1380, 0x002c00dc), intArrayOf(0x13e0, 0xe3f42004.toInt()),+ intArrayOf(0x13e4, 0xe3f42084.toInt()), intArrayOf(0x13e8, 0xe3f42104.toInt()), intArrayOf(0x13ec, 0x00060fff),+ intArrayOf(0x1400, RX_FILTER_MONITOR), intArrayOf(0x1408, 0x0000017f), intArrayOf(0x140c, 0x00004003),+ intArrayOf(0x150c, 0x00000003), intArrayOf(0x1608, 0x00000002), intArrayOf(0x0a44, 0x00000000),+ intArrayOf(0x0260, 0x00000000), intArrayOf(0x0250, 0x00000000), intArrayOf(0x120c, 0x00000000),+ intArrayOf(0x1264, 0x00000000), intArrayOf(0x13c0, 0x00000000), intArrayOf(0x13c8, 0x00000000),+ intArrayOf(0x1314, 0x3a3a3a3a), intArrayOf(0x1318, 0x3a3a3a3a), intArrayOf(0x131c, 0x3a3a3a3a),+ intArrayOf(0x1320, 0x3a3a3a3a), intArrayOf(0x1324, 0x3a3a3a3a), intArrayOf(0x13d4, 0x3a3a3a3a),+ intArrayOf(0x13d8, 0x0000003a), intArrayOf(0x13dc, 0x0000003a), intArrayOf(0x0024, 0x0000d000),+ intArrayOf(0x0a38, 0x0000000a), intArrayOf(0x0824, 0x60401c18), intArrayOf(0x0210, 0x94ff0000.toInt()),+ intArrayOf(0x1478, 0x00000004), intArrayOf(0x1384, 0x00001818), intArrayOf(0x1358, 0xedcba980.toInt()),+ intArrayOf(0x1648, 0x00830083), intArrayOf(0x1410, 0x000001ff), intArrayOf(0x1350, 0x00001020)+ )+}diff --git a/app/src/main/java/com/rfsentinel/app/usb/NOTICE.md b/app/src/main/java/com/rfsentinel/app/usb/NOTICE.mdindex b729c0b..7b0effa 100644--- a/app/src/main/java/com/rfsentinel/app/usb/NOTICE.md+++ b/app/src/main/java/com/rfsentinel/app/usb/NOTICE.md@@ -4,7 +4,14 @@ These drivers run USB WiFi adapters in receive-only monitor mode from userspace.- `Rtl8821auMonitor.kt` and `Rtl8821auTables.kt` drive Realtek RTL8811AU / RTL8821AU adapters (e.g. ALFA AWUS036ACS).- `Rtl8822buMonitor.kt` and `Rtl8822bTables.kt` drive Realtek RTL8812BU / RTL8822BU adapters, with the firmware and register tables in `assets/usbwifi/rtl8822b_*.bin`.-- `MonitorFrames.kt` turns the received 802.11 frames into access points and client devices for both drivers.+- `Rtl8187Monitor.kt` drives Realtek RTL8187L / RTL8187B adapters (e.g. ALFA AWUS036H). They need no firmware.+- `Rt3070Monitor.kt` drives Ralink RT3070 adapters (e.g. ALFA AWUS036NH / AWUS036NEH), with Ralink's firmware in `assets/usbwifi/rt2870.bin`.+- `Rtl8814auMonitor.kt` and `Rtl8814auTables.kt` drive Realtek RTL8814AU adapters (e.g. ALFA AWUS1900), 2.4 + 5 GHz.+- `Mt7612uMonitor.kt` drives MediaTek MT7612U / MT7632U adapters (e.g. ALFA AWUS036ACM), 2.4 + 5 GHz, with MediaTek's firmware in `assets/usbwifi/mt7662*.bin`.+- `Ar9271Monitor.kt` and `Ar9271Tables.kt` drive Atheros AR9271 adapters (e.g. ALFA AWUS036NHA) - experimental - with the open ath9k_htc firmware in `assets/usbwifi/htc_9271-1.4.0.fw`.+- `BulkRx.kt` is the USB receive loop of the RTL8187, RT3070, RTL8814AU, MT7612U and AR9271 drivers.+- The FREE-WiLi 2 (an ESP32-C5 WiFi board with a USB console) is read by `esp/EspReader.kt` / `esp/EspReports.kt` (FreeWiliReports), ported from Wardrive Go.+- `MonitorFrames.kt` turns the received 802.11 frames into access points and client devices for all of them.| Part | Origin | License ||---|---|---|@@ -12,9 +19,23 @@ These drivers run USB WiFi adapters in receive-only monitor mode from userspace.| RTL8811AU / 8821AU userspace USB driver and 802.11 frame parsing | [Wardrive Go](https://github.com/RocketGod-git/wardrive-go) by RocketGod | GPL-3.0 || RTL8812BU / 8822BU bring-up (power sequence, HalMAC firmware download, MAC init, channel tuning, gain control, RX descriptor parsing) | [devourer](https://github.com/OpenIPC/devourer) by OpenIPC, `src/jaguar2/` | GPL-2.0 || RTL8822B firmware image and phydm BB / AGC / RF tables | Realtek rtl88x2bu Linux driver, as extracted by devourer | Realtek firmware / GPL-2.0 |-| Integration into RF Sentinel; removal of handshake / PMKID capture (8821AU) and of every transmit, beamforming and calibration-for-TX path (8822BU) | RF Sentinel (CIS-C0) | GPL-3.0 |+| RTL8187L / 8187B bring-up, RTL8225 / RTL8225Z2 radio tuning and RX descriptor handling | Linux kernel `rtl8187` driver (Michael Wu, Andrea Merello, Herton Ronaldo Krzesinski, Hin-Tak Leung, Larry Finger; register values from Realtek's r8187 driver), with Kismet's [Android PCAP Capture](https://www.kismetwireless.net/android-pcap/) (Mike Kershaw / Dragorn; signal-strength work by Jinghao Shi, via Gabriel Nyman's AndroidPCAP fork) as the USB reference | GPL-2.0 |+| RT3070 userspace USB driver (firmware load, MAC / BBP / RF init, channel tuning, RX parsing) | [Wardrive Go](https://github.com/RocketGod-git/wardrive-go) by RocketGod, following the Linux `rt2800usb` / `rt2800lib` driver (rt2x00 project) | GPL-3.0 / GPL-2.0-or-later |+| RT3070 firmware `rt2870.bin` (version 36, unmodified, from [linux-firmware](https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git)) | Ralink Technology Corporation (now MediaTek) | Redistributable binary, see `assets/usbwifi/LICENCE.ralink-firmware.txt` |+| RTL8814AU, MT7612U and AR9271 userspace USB drivers, FREE-WiLi 2 console reader | [Wardrive Go](https://github.com/RocketGod-git/wardrive-go) by RocketGod, following Realtek's 8814au driver and the Linux `mt76x2u` and `ath9k_htc` drivers | GPL-3.0 |+| RTL8814AU register tables | Realtek 8814au driver, as used by Wardrive Go | GPL-2.0 |+| AR9271 register tables | Linux `ath9k` (`ar9002_initvals.h`), as used by Wardrive Go | ISC |+| MT7612U firmware `mt7662.bin` and ROM patch `mt7662_rom_patch.bin` (unmodified, from linux-firmware) | Ralink, a MediaTek company | Redistributable binary, see `assets/usbwifi/LICENCE.ralink_a_mediatek_company_firmware` |+| AR9271 firmware `htc_9271-1.4.0.fw` (unmodified, from linux-firmware; Wardrive Go ships a build that differs in 10 bytes) | [open-ath9k-htc-firmware](https://github.com/qca/open-ath9k-htc-firmware), Qualcomm Atheros and others | Free software, see `assets/usbwifi/LICENCE.open-ath9k-htc-firmware` |+| Integration into RF Sentinel; removal of handshake / PMKID capture (8821AU, RT3070) and of every transmit, beamforming and calibration-for-TX path (8822BU, RTL8187); RT3070 fixes checked against the kernel (eFuse addressing, EEPROM reads, DMA / frame-length setup, receive gain, external LNA, EEPROM BBP overrides); MT7612U: bad-checksum frames dropped, auto-responder off, kernel ROM-patch rule; AR9271: signal relative to the noise floor, FCS removed, packets spanning transfers reassembled, WMI answers matched, running firmware reused | RF Sentinel (CIS-C0) | GPL-3.0 |RF Sentinel is distributed under the GNU GPL v3.0 (see `LICENSE`). The registervalues and firmware are hardware configuration data from Realtek's driver; creditand thanks to Realtek, the aircrack-ng rtl8812au maintainers, RocketGod for-Wardrive Go, and OpenIPC for devourer.+Wardrive Go, OpenIPC for devourer, the Linux rtl8187 and rt2x00 authors, and+Kismet. The Ralink and MediaTek firmware is redistributed under its own licences+(binary only, unmodified, no reverse engineering), reproduced in+`assets/usbwifi/LICENCE.ralink-firmware.txt` and+`assets/usbwifi/LICENCE.ralink_a_mediatek_company_firmware`; the ath9k_htc firmware+is free software (`assets/usbwifi/LICENCE.open-ath9k-htc-firmware`, sources at+https://github.com/qca/open-ath9k-htc-firmware).diff --git a/app/src/main/java/com/rfsentinel/app/usb/Rt3070Monitor.kt b/app/src/main/java/com/rfsentinel/app/usb/Rt3070Monitor.ktnew file mode 100644index 0000000..de7c54a--- /dev/null+++ b/app/src/main/java/com/rfsentinel/app/usb/Rt3070Monitor.kt@@ -0,0 +1,541 @@+package com.rfsentinel.app.usb++/*+ * Receive-only monitor mode for Ralink RT3070 USB WiFi adapters (e.g. ALFA AWUS036NH /+ * AWUS036NEH), 2.4 GHz 802.11b/g/n, driven from userspace over Android's USB host API -+ * no root, no kernel driver. Loads Ralink's firmware (assets/usbwifi/rt2870.bin, from+ * linux-firmware; licence in LICENCE.ralink-firmware.txt), hops the 2.4 GHz channels and+ * reports the access points and client devices it hears. It never transmits.+ *+ * Ported from Wardrive Go by RocketGod (https://github.com/RocketGod-git/wardrive-go,+ * GPL-3.0), which follows the Linux rt2800usb / rt2800lib driver (rt2x00 project,+ * GPL-2.0-or-later). Checked against the kernel and completed here: eFuse addressing,+ * EEPROM reads in 64-byte steps, the DMA / frame-length setup, the receive gain+ * (BBP 62-66), external-LNA boards, the EEPROM's BBP overrides and the MCU current+ * request. Its handshake / PMKID capture was left out.+ */++import android.content.Context+import android.hardware.usb.UsbDevice+import android.hardware.usb.UsbDeviceConnection+import android.hardware.usb.UsbManager++object Rt3070Monitor {+ @Volatile var running = false; private set+ @Volatile private var stop = false++ private val frames = MonitorFrames()+ private val HOP = intArrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)+ private const val DWELL_MS = 350L+ private val FRESH_MS get() = (HOP.size * DWELL_MS * 9 / 5).coerceAtLeast(3000L)+ private const val REPORT_MS = 10_000L+ private const val RX_SIZE = 4096++ private const val OUT_VENDOR = 0x40; private const val IN_VENDOR = 0xC0+ private const val DEVICE_MODE = 0x01; private const val MULTI_WRITE = 0x06; private const val MULTI_READ = 0x07+ private const val EEPROM_READ = 0x09+ private const val USB_MODE_RESET = 1; private const val USB_MODE_FIRMWARE = 8; private const val USB_MODE_AUTORUN = 17+ private const val FIRMWARE_BASE = 0x3000; private const val FW_LEN = 4096; private const val CSR_CACHE = 64+ private const val MCU_CURRENT = 0x36; private const val MCU_BOOT_SIGNAL = 0x72+ private const val REV_RT3070F = 0x0201++ private const val OPT_14_CSR = 0x0114; private const val WPDMA_GLO_CFG = 0x0208; private const val USB_DMA_CFG = 0x02a0+ private const val US_CYC_CNT = 0x02a4; private const val PBF_SYS_CTRL = 0x0400; private const val HOST_CMD_CSR = 0x0404+ private const val PBF_CFG = 0x0408; private const val PBF_MAX_PCNT = 0x040c; private const val RF_CSR_CFG = 0x0500+ private const val EFUSE_CTRL = 0x0580; private const val LDO_CFG0 = 0x05d4+ private const val MAC_CSR0 = 0x1000; private const val MAC_SYS_CTRL = 0x1004; private const val MAX_LEN_CFG = 0x1018+ private const val BBP_CSR_CFG = 0x101c; private const val LED_CFG = 0x102c+ private const val XIFS_TIME_CFG = 0x1100; private const val BKOFF_SLOT_CFG = 0x1104; private const val CH_TIME_CFG = 0x110c+ private const val BCN_TIME_CFG = 0x1114; private const val CH_IDLE_STA = 0x1130; private const val CH_BUSY_STA = 0x1134+ private const val CH_BUSY_STA_SEC = 0x1138; private const val MAC_STATUS_CFG = 0x1200; private const val PWR_PIN_CFG = 0x1204+ private const val AUTOWAKEUP_CFG = 0x1208; private const val TX_PIN_CFG = 0x1328; private const val TX_BAND_CFG = 0x132c+ private const val TX_SW_CFG0 = 0x1330; private const val TX_SW_CFG1 = 0x1334; private const val TX_SW_CFG2 = 0x1338+ private const val TXOP_CTRL_CFG = 0x1340; private const val TX_RTS_CFG = 0x1344; private const val TX_TIMEOUT_CFG = 0x1348+ private const val TX_RTY_CFG = 0x134c; private const val TX_LINK_CFG = 0x1350+ private const val HT_FBK_CFG0 = 0x1354; private const val HT_FBK_CFG1 = 0x1358; private const val LG_FBK_CFG0 = 0x135c+ private const val LG_FBK_CFG1 = 0x1360; private const val CCK_PROT_CFG = 0x1364; private const val OFDM_PROT_CFG = 0x1368+ private const val MM20_PROT_CFG = 0x136c; private const val MM40_PROT_CFG = 0x1370; private const val GF20_PROT_CFG = 0x1374+ private const val GF40_PROT_CFG = 0x1378; private const val EXP_ACK_TIME = 0x1380+ private const val RX_FILTR_CFG = 0x1400; private const val AUTO_RSP_CFG = 0x1404+ private const val LEGACY_BASIC_RATE = 0x1408; private const val HT_BASIC_RATE = 0x140c; private const val TXOP_HLDR_ET = 0x1608+ private const val H2M_MAILBOX_CSR = 0x7010; private const val H2M_MAILBOX_CID = 0x7014; private const val H2M_MAILBOX_STATUS = 0x701c+ private const val H2M_INT_SRC = 0x7024; private const val H2M_BBP_AGENT = 0x7028++ /**+ * Keep everything except frames with a bad checksum, PHY or version errors and+ * control frames (ACK, RTS, CTS, block ack...), which say nothing about who is there.+ */+ private const val RX_FILTER_MONITOR = 0x0001FF13++ // EEPROM words+ private const val EE_MAC = 0x02; private const val EE_NIC_CONF0 = 0x1a; private const val EE_NIC_CONF1 = 0x1b+ private const val EE_FREQ = 0x1d; private const val EE_LNA = 0x22; private const val EE_RSSI_BG = 0x23; private const val EE_BBP_START = 0x78++ /** rf_vals_3x: synthesizer N and K per 2.4 GHz channel (R is 2 on all of them). */+ private val RF_N = intArrayOf(241, 241, 242, 242, 243, 243, 244, 244, 245, 245, 246, 246, 247, 248)+ private val RF_K = intArrayOf(2, 7, 2, 7, 2, 7, 2, 7, 2, 7, 2, 7, 2, 4)++ private lateinit var conn: UsbDeviceConnection+ private var revLtF = false+ private val ee = ByteArray(512)+ private var freqOffset = 0+ private var lnaGain = 0+ private var rssiOffset = 0+ private var externalLna = false+ private var calBw20 = 0x16++ fun abort() { stop = true }++ fun run(ctx: Context, device: UsbDevice, chipName: String, onStatus: (String) -> Unit,+ onFrame: (List<MonitorSighting>) -> Unit) {+ if (running) return+ running = true; stop = false; frames.clear()+ val mgr = ctx.getSystemService(Context.USB_SERVICE) as UsbManager+ val c = mgr.openDevice(device) ?: run { onStatus("$chipName: couldn't reopen adapter"); running = false; return }+ conn = c; ctlErrors = 0+ try {+ val intf = device.getInterface(0)+ val claimed = c.claimInterface(intf, true)+ val rx = BulkRx.inEndpoint(intf, 0x81)+ ?: run { UsbWifi.log("RT3070: no bulk-IN endpoint"); onStatus("$chipName: no RX endpoint"); return }+ UsbWifi.log("=== RT3070 bring-up (rt2800usb) ===")+ if (!claimed) UsbWifi.log("RT3070: couldn't claim the USB interface (continuing)")+ val t0 = System.currentTimeMillis()+ if (!waitCsrReady()) { UsbWifi.log("RT3070: MAC_CSR0 never ready"); onStatus("$chipName: not responding (replug)"); return }+ val csr0 = regRd(MAC_CSR0)+ val rt = csr0 ushr 16; val rev = csr0 and 0xffff+ UsbWifi.log("RT3070: chip RT%04x rev 0x%04x, RX EP=0x%02x".format(rt, rev, rx.address))+ if (rt != 0x3070) { onStatus("$chipName: this Ralink chip (RT%04x) isn't supported yet".format(rt)); return }+ revLtF = rev < REV_RT3070F++ onStatus("$chipName · reading calibration…")+ readEeprom()++ onStatus("$chipName · loading firmware…")+ if (!loadFirmware(ctx)) { onStatus("$chipName: firmware didn't start (replug)"); return }++ onStatus("$chipName · starting radio…")+ if (!enableRadio()) { onStatus("$chipName: radio didn't start (replug)"); return }+ regWr(RX_FILTR_CFG, RX_FILTER_MONITOR)+ tune(HOP[0])+ UsbWifi.log(("RT3070: started in %d ms - SYS_CTRL 0x%08x WPDMA 0x%08x USB_DMA 0x%08x RX_FILTR 0x%08x MAC_STATUS 0x%08x PBF 0x%08x, " ++ "BBP 0:%02x 3:%02x 4:%02x 62:%02x 66:%02x 75:%02x 82:%02x, " ++ "RF 1:%02x 2:%02x 3:%02x 6:%02x 17:%02x 23:%02x 24:%02x 27:%02x 31:%02x, USB errors %d - monitor live ch %d").format(+ System.currentTimeMillis() - t0, regRd(MAC_SYS_CTRL), regRd(WPDMA_GLO_CFG), regRd(USB_DMA_CFG), regRd(RX_FILTR_CFG),+ regRd(MAC_STATUS_CFG), regRd(PBF_SYS_CTRL),+ bbpRd(0), bbpRd(3), bbpRd(4), bbpRd(62), bbpRd(66), bbpRd(75), bbpRd(82),+ rfRd(1), rfRd(2), rfRd(3), rfRd(6), rfRd(17), rfRd(23), rfRd(24), rfRd(27), rfRd(31), ctlErrors, HOP[0]))+ onStatus("$chipName · live · 2.4 GHz monitor")+ rxLoop(chipName, rx, onFrame, onStatus)+ } catch (e: Exception) {+ UsbWifi.log("RT3070: bring-up error - ${UsbWifi.describe(e)}")+ onStatus("$chipName: error · ${e.message}")+ } finally {+ runCatching { c.close() }+ running = false+ }+ }++ // ---- EEPROM / eFuse (rt2800usb_read_eeprom, rt2800_validate_eeprom) ----++ private fun readEeprom() {+ ee.fill(0xff.toByte())+ val efuse = regRd(EFUSE_CTRL) and 0x80000000.toInt() != 0+ if (efuse) {+ var i = 0+ while (i < ee.size / 2) { // word address, 8 words (16 bytes) per read+ var reg = regRd(EFUSE_CTRL)+ reg = setf(reg, 0x03fe0000, i) // ADDRESS_IN+ reg = setf(reg, 0x000000c0, 0) // MODE: read+ reg = reg or 0x40000000 // KICK+ regWr(EFUSE_CTRL, reg)+ val end = System.currentTimeMillis() + 50+ while (regRd(EFUSE_CTRL) and 0x40000000 != 0 && System.currentTimeMillis() < end) sleep(1)+ // The data comes out from the end to the start.+ putLe32(ee, i * 2, regRd(0x059c)); putLe32(ee, i * 2 + 4, regRd(0x0598))+ putLe32(ee, i * 2 + 8, regRd(0x0594)); putLe32(ee, i * 2 + 12, regRd(0x0590))+ i += 8+ }+ } else {+ var off = 0; var failed = 0+ while (off < ee.size) {+ val chunk = ByteArray(CSR_CACHE)+ if (conn.controlTransfer(IN_VENDOR, EEPROM_READ, 0, off, chunk, CSR_CACHE, 1000) == CSR_CACHE) chunk.copyInto(ee, off)+ else failed+++ off += CSR_CACHE+ }+ if (failed > 0) UsbWifi.log("RT3070: $failed of ${ee.size / CSR_CACHE} EEPROM reads failed - using defaults for those")+ }+ val freq = ew(EE_FREQ) and 0xff+ freqOffset = if (freq == 0xff) 0 else freq+ val lna = ew(EE_LNA) and 0xff+ lnaGain = if (lna == 0xff) 0 else lna+ val ro = ew(EE_RSSI_BG) and 0xff+ rssiOffset = if (ro > 10) 0 else ro+ val nic1 = ew(EE_NIC_CONF1)+ externalLna = nic1 != 0xffff && nic1 and 0x0004 != 0+ val nic0 = ew(EE_NIC_CONF0)+ // Only the maker part of the adapter's own address: enough to see the EEPROM read right.+ val maker = (0 until 3).joinToString(":") { "%02x".format(ee[EE_MAC * 2 + it].toInt() and 0xff) }+ UsbWifi.log("RT3070: EEPROM (%s) chip id 0x%04x version 0x%04x, MAC %s:xx:xx:xx, NIC_CONF0 0x%04x (RF 0x%x, RX path %d), NIC_CONF1 0x%04x, freq_off %d lna_gain %d rssi_off %d ext_lna %b".format(+ if (efuse) "eFuse" else "93C46", ew(0), ew(1), maker, nic0, (nic0 ushr 8) and 0xf, nic0 and 0xf, nic1,+ freqOffset, lnaGain, rssiOffset, externalLna))+ }++ private fun ew(word: Int) = (ee[word * 2].toInt() and 0xff) or ((ee[word * 2 + 1].toInt() and 0xff) shl 8)++ // ---- firmware (rt2800_load_firmware, rt2800usb_write_firmware) ----++ private fun loadFirmware(ctx: Context): Boolean {+ regWr(AUTOWAKEUP_CFG, 0)+ if (!waitCsrReady()) return false+ disableWpdma()+ val autorun = run {+ val b = ByteArray(4)+ conn.controlTransfer(IN_VENDOR, DEVICE_MODE, USB_MODE_AUTORUN, 0, b, 4, 1000) == 4 && (le32(b, 0) and 0x3) == 2+ }+ if (autorun) UsbWifi.log("RT3070: firmware already running (autorun)")+ else {+ val fw = ctx.assets.open("usbwifi/rt2870.bin").use { it.readBytes() }+ if (fw.size < FW_LEN) { UsbWifi.log("RT3070: rt2870.bin too short (${fw.size} B)"); return false }+ var off = 0 // the RT3070 runs the first 4 KB image+ while (off < FW_LEN) {+ val len = minOf(CSR_CACHE, FW_LEN - off)+ if (conn.controlTransfer(OUT_VENDOR, MULTI_WRITE, 0, FIRMWARE_BASE + off, fw.copyOfRange(off, off + len), len, 1000) < 0) {+ UsbWifi.log("RT3070: firmware write failed at $off"); return false+ }+ off += len+ }+ UsbWifi.log("RT3070: firmware written ($off B)")+ }+ regWr(H2M_MAILBOX_CID, -1); regWr(H2M_MAILBOX_STATUS, -1)+ conn.controlTransfer(OUT_VENDOR, DEVICE_MODE, USB_MODE_FIRMWARE, 0, null, 0, 1000)+ sleep(10)+ regWr(H2M_MAILBOX_CSR, 0)+ if (!poll(1000) { regRd(PBF_SYS_CTRL) and 0x80 != 0 }) { UsbWifi.log("RT3070: PBF not ready - firmware didn't start"); return false }+ disableWpdma()+ regWr(H2M_BBP_AGENT, 0); regWr(H2M_MAILBOX_CSR, 0); regWr(H2M_INT_SRC, 0)+ mcuRequest(MCU_BOOT_SIGNAL)+ sleep(1)+ UsbWifi.log("RT3070: firmware running")+ return true+ }++ private fun mcuRequest(command: Int) {+ poll(100) { regRd(H2M_MAILBOX_CSR) and 0xff000000.toInt() == 0 } // mailbox free+ regWr(H2M_MAILBOX_CSR, 0x01000000) // owner = host, token 0, no arguments+ regWr(HOST_CMD_CSR, command and 0xff)+ }++ // ---- radio (rt2800usb_enable_radio, rt2800_enable_radio) ----++ private fun enableRadio(): Boolean {+ if (!waitWpdma()) UsbWifi.log("RT3070: WPDMA busy (continuing)")+ var dma = regRd(USB_DMA_CFG)+ dma = setf(dma, 0x00010000, 0) // PHY_CLEAR+ dma = setf(dma, 0x00200000, 0) // RX_BULK_AGG_EN: one frame per transfer+ dma = setf(dma, 0x000000ff, 128) // RX_BULK_AGG_TIMEOUT+ dma = setf(dma, 0x0000ff00, 0) // RX_BULK_AGG_LIMIT+ dma = dma or 0x00400000 or 0x00800000 // RX / TX bulk enable+ regWr(USB_DMA_CFG, dma)++ waitWpdma()+ initRegisters()+ if (!poll(1000) { regRd(MAC_STATUS_CFG) and 0x3 == 0 }) UsbWifi.log("RT3070: BBP/RF busy (continuing)")+ regWr(H2M_BBP_AGENT, 0); regWr(H2M_MAILBOX_CSR, 0); regWr(H2M_INT_SRC, 0)+ mcuRequest(MCU_BOOT_SIGNAL)+ sleep(1)+ // rt2800_wait_bbp_ready+ regWr(H2M_BBP_AGENT, 0); regWr(H2M_MAILBOX_CSR, 0)+ sleep(1)+ if (!poll(500) { bbpRd(0).let { it != 0 && it != 0xff } }) { UsbWifi.log("RT3070: BBP not responding"); return false }++ initBbp()+ initRfcsr()+ sleep(1)+ mcuRequest(MCU_CURRENT)++ regWr(MAC_SYS_CTRL, (regRd(MAC_SYS_CTRL) or 0x04) and 0x08.inv())+ sleep(1)+ var wp = regRd(WPDMA_GLO_CFG)+ wp = wp or 0x01 or 0x04 or 0x40 // TX / RX DMA, TX write-back done+ wp = setf(wp, 0x30, 2) // DMA burst size+ regWr(WPDMA_GLO_CFG, wp)+ regWr(MAC_SYS_CTRL, regRd(MAC_SYS_CTRL) or 0x04 or 0x08)+ return true+ }++ private fun initRegisters() {+ disableWpdma()+ // rt2800usb_init_registers: reset the MAC and BBP+ waitCsrReady()+ regWr(PBF_SYS_CTRL, regRd(PBF_SYS_CTRL) and 0x00002000.inv())+ regWr(MAC_SYS_CTRL, 0x3)+ conn.controlTransfer(OUT_VENDOR, DEVICE_MODE, USB_MODE_RESET, 0, null, 0, 1000)+ regWr(MAC_SYS_CTRL, 0)++ regWr(LEGACY_BASIC_RATE, 0x0000013f); regWr(HT_BASIC_RATE, 0x00008003)+ regWr(MAC_SYS_CTRL, 0)+ regWr(BCN_TIME_CFG, (regRd(BCN_TIME_CFG) and 0xf01fffff.toInt().inv()) or 1600) // beacon interval only, no TSF / beacons+ regWr(RX_FILTR_CFG, RX_FILTER_MONITOR)+ run { var r = regRd(BKOFF_SLOT_CFG); r = setf(r, 0xff, 9); r = setf(r, 0xff00, 2); regWr(BKOFF_SLOT_CFG, r) }+ regWr(TX_SW_CFG0, 0x00000400)+ if (revLtF) { regWr(TX_SW_CFG1, 0x00000000); regWr(TX_SW_CFG2, 0x0000002c) }+ else { regWr(TX_SW_CFG1, 0x00080606); regWr(TX_SW_CFG2, 0x00000000) }+ regWr(TX_LINK_CFG, 0x00001020)+ regWr(TX_TIMEOUT_CFG, 0x000a2090)+ run {+ var r = regRd(MAX_LEN_CFG)+ r = setf(r, 0x00000fff, 3840) // max MPDU+ r = setf(r, 0x00003000, 3) // max PSDU (USB)+ r = setf(r, 0x0000c000, 10) // min PSDU+ r = setf(r, 0x000f0000, 10) // min MPDU+ regWr(MAX_LEN_CFG, r)+ }+ regWr(LED_CFG, 0x7f031e46)+ regWr(PBF_MAX_PCNT, 0x1f3fbf9f)+ regWr(TX_RTY_CFG, 0x47d01f0f)+ regWr(AUTO_RSP_CFG, 0x00000012) // auto-responder off: never answers with an ACK or CTS+ regWr(CCK_PROT_CFG, 0x05740003); regWr(OFDM_PROT_CFG, 0x05740003)+ regWr(MM20_PROT_CFG, 0x03f44084); regWr(MM40_PROT_CFG, 0x03f54084)+ regWr(GF20_PROT_CFG, 0x03f44084); regWr(GF40_PROT_CFG, 0x03f54084)+ regWr(PBF_CFG, 0x00f40006)+ regWr(WPDMA_GLO_CFG, 0x30) // DMA off, burst size 3, little endian, no header scatter+ regWr(TXOP_CTRL_CFG, 0x0000583f)+ regWr(TXOP_HLDR_ET, 0x00000002)+ regWr(TX_RTS_CFG, 0x00092b20)+ regWr(EXP_ACK_TIME, 0x002400ca)+ regWr(XIFS_TIME_CFG, 0x33a41010)+ regWr(PWR_PIN_CFG, 0x00000003)+ regWr(US_CYC_CNT, setf(regRd(US_CYC_CNT), 0xff, 30))+ regWr(HT_FBK_CFG0, 0x65432100); regWr(HT_FBK_CFG1, 0xedcba980.toInt())+ regWr(LG_FBK_CFG0, 0xedcba988.toInt()); regWr(LG_FBK_CFG1, 0x00002100)+ regWr(CH_TIME_CFG, 0x0000001f) // channel statistics timer+ }++ private fun initBbp() {+ // rt2800_init_bbp_30xx+ val tab = intArrayOf(65, 0x2c, 66, 0x38, 69, 0x12, 73, 0x10, 70, 0x0a, 79, 0x13, 80, 0x05, 81, 0x33,+ 82, 0x62, 83, 0x6a, 84, 0x99, 86, 0x00, 91, 0x04, 92, 0x00, 103, if (revLtF) 0x00 else 0xc0, 105, 0x05, 106, 0x35)+ for (i in tab.indices step 2) bbpWr(tab[i], tab[i + 1])+ // Board-specific overrides stored in the EEPROM.+ for (i in 0 until 16) {+ val w = ew(EE_BBP_START + i)+ if (w != 0xffff && w != 0x0000) bbpWr(w ushr 8, w and 0xff)+ }+ }++ private fun initRfcsr() {+ // rt2800_init_rfcsr_30xx+ rfToggle(30)+ val tab = intArrayOf(4, 0x40, 5, 0x03, 6, 0x02, 7, 0x60, 9, 0x0f, 10, 0x41, 11, 0x21, 12, 0x7b,+ 14, 0x90, 15, 0x58, 16, 0xb3, 17, 0x92, 18, 0x2c, 19, 0x02, 20, 0xba, 21, 0xdb,+ 24, 0x16, 25, 0x03, 29, 0x1f)+ for (i in tab.indices step 2) rfWr(tab[i], tab[i + 1])+ if (revLtF) {+ var r = regRd(LDO_CFG0); r = setf(r, 0x03000000, 1); r = setf(r, 0x1c000000, 3); regWr(LDO_CFG0, r)+ }+ calBw20 = rxFilterCalibration(0x16)+ if (revLtF) rfWr(27, 0x03)+ regWr(OPT_14_CSR, regRd(OPT_14_CSR) or 0x1) // LED open drain+ // rt2800_normal_mode_setup_3xxx+ var rf = rfRd(17)+ rf = setf(rf, 0x08, 0) // TX_LO1_EN+ if (!externalLna) rf = setf(rf, 0x20, 1)+ rfWr(17, rf)+ rf = rfRd(27)+ rf = setf(rf, 0x03, if (revLtF) 3 else 0); rf = setf(rf, 0x04, 0); rf = setf(rf, 0x30, 0); rf = setf(rf, 0x40, 0)+ rfWr(27, rf)+ UsbWifi.log("RT3070: RX filter calibration 0x%02x".format(calBw20))+ }++ /** rt2800_init_rx_filter (20 MHz): tune the baseband filter with test tones; returns RFCSR24. */+ private fun rxFilterCalibration(target: Int): Int {+ var rf24 = 0x07+ rfWr(24, rf24)+ bbpWr(4, setf(bbpRd(4), 0x18, 0))+ rfWr(31, setf(rfRd(31), 0x20, 0))+ rfWr(22, setf(rfRd(22), 0x01, 1)) // baseband loopback+ bbpWr(24, 0)+ var passband = 0+ for (i in 0 until 100) { bbpWr(25, 0x90); sleep(1); passband = bbpRd(55); if (passband != 0) break }+ bbpWr(24, 0x06)+ var overtuned = 0+ for (i in 0 until 100) {+ bbpWr(25, 0x90); sleep(1)+ val stopband = bbpRd(55)+ if (passband - stopband <= target) { rf24++; if (passband - stopband == target) overtuned++ } else break+ rfWr(24, rf24)+ }+ if (overtuned != 0) rf24--+ rfWr(24, rf24)+ bbpWr(24, 0)+ rfWr(22, setf(rfRd(22), 0x01, 0))+ bbpWr(4, setf(bbpRd(4), 0x18, 0))+ return rf24+ }++ private fun rfToggle(reg: Int) {+ val v = rfRd(reg); rfWr(reg, v or 0x80); sleep(1); rfWr(reg, v and 0x80.inv())+ }++ /** rt2800_config_channel_rf3xxx + the channel's BBP / pin setup, 20 MHz, one antenna. */+ private fun tune(ch: Int) {+ val i = ch - 1+ rfWr(2, RF_N[i])+ rfWr(3, setf(rfRd(3), 0x0f, RF_K[i]))+ rfWr(6, setf(rfRd(6), 0x03, 2))+ rfWr(12, setf(rfRd(12), 0x1f, 0)) // TX power: lowest (never transmits)+ rfWr(13, setf(rfRd(13), 0x1f, 0))+ var rf = rfRd(1)+ rf = setf(rf, 0x04, 0); rf = setf(rf, 0x10, 1); rf = setf(rf, 0x40, 1) // RX0 on, RX1 / RX2 off+ rf = setf(rf, 0x08, 0); rf = setf(rf, 0x20, 1); rf = setf(rf, 0x80, 1)+ rfWr(1, rf)+ rfWr(23, setf(rfRd(23), 0x7f, freqOffset))+ rfWr(24, setf(rfRd(24), 0x7f, calBw20))+ rfWr(31, setf(rfRd(31), 0x7f, calBw20))+ rfWr(7, setf(rfRd(7), 0x01, 1)) // RF tuning+ rfToggle(30) // RF calibration++ val agc = 0x37 - lnaGain+ bbpWr(62, agc); bbpWr(63, agc); bbpWr(64, agc); bbpWr(86, 0)+ if (externalLna) { bbpWr(82, 0x62); bbpWr(75, 0x46) } else { bbpWr(82, 0x84); bbpWr(75, 0x50) }+ regWr(TX_BAND_CFG, setf(setf(setf(regRd(TX_BAND_CFG), 0x01, 0), 0x02, 0), 0x04, 1)) // 2.4 GHz+ regWr(TX_PIN_CFG, 0x02 or 0x100 or 0x200 or 0x10000 or 0x40000) // G-band PA, LNAs, RF / TR switch+ bbpWr(4, setf(bbpRd(4), 0x18, 0)) // 20 MHz+ bbpWr(3, setf(bbpRd(3), 0x20, 0))+ sleep(1)+ regRd(CH_IDLE_STA); regRd(CH_BUSY_STA); regRd(CH_BUSY_STA_SEC) // clear on read+ bbpWr(66, 0x1c + 2 * lnaGain) // default receive gain (rt2800_get_default_vgc)+ }++ // ---- receive ----++ private class RxState { var hopAt = 0L; var lastEmit = 0L; var hopIdx = 0 }++ private fun rxLoop(chipName: String, ep: android.hardware.usb.UsbEndpoint,+ onFrame: (List<MonitorSighting>) -> Unit, onStatus: (String) -> Unit) {+ val st = RxState()+ val t0 = System.currentTimeMillis(); st.hopAt = t0; st.lastEmit = t0+ val stats = BulkRx.Stats("RT3070")+ val total = BulkRx.run("RT3070", conn, ep, 24, RX_SIZE, { stop }, { b, n ->+ stats.transfer(n)+ // RXINFO + RXWI, and the RXD that follows the frame+ val rxd = if (n >= 4) 4 + (le32(b, 0) and 0xffff) else -1+ stats.sample("$n bytes, RXD %s, RXINFO+RXWI".format(+ if (rxd in 0..n - 4) "%08x".format(le32(b, rxd)) else "past the end"), b, 0, 20)+ forEachFrame(b, n, rssiOffset, lnaGain, onBad = { crc -> if (crc) stats.badChecksum++ else stats.malformed++ }) { s, e, rssi ->+ stats.frame(rssi)+ frames.frame(b, s, e, HOP[st.hopIdx], rssi)+ }+ }) { now ->+ stats.maybeLog(now) {+ val (aps, clients) = frames.live(now, REPORT_MS)+ "ch ${HOP[st.hopIdx]}, $aps access points, $clients devices, USB errors $ctlErrors"+ }+ if (now - st.lastEmit > 2000) { emit(onFrame); st.lastEmit = now }+ if (now - st.hopAt > DWELL_MS) {+ st.hopIdx = (st.hopIdx + 1) % HOP.size+ runCatching { tune(HOP[st.hopIdx]) }+ val (aps, clients) = frames.live(now, REPORT_MS)+ onStatus("$chipName · live · $aps access points · $clients devices · ch ${HOP[st.hopIdx]}")+ st.hopAt = now+ }+ }+ emit(onFrame)+ UsbWifi.log("RT3070: RX loop stopped ($total B)")+ }++ private fun emit(onFrame: (List<MonitorSighting>) -> Unit) {+ val batch = frames.drain(System.currentTimeMillis(), FRESH_MS)+ if (batch.isNotEmpty()) onFrame(batch)+ }++ /**+ * Frames in one bulk transfer: | RXINFO (4) | RXWI (16) | 802.11 frame, padded | RXD (4) |,+ * RXINFO giving the length up to RXD. Frames with a bad checksum are skipped; [onFrame]+ * gets the 802.11 frame's [start, end) and its signal (null when the radio gave none).+ * [onBad] hears about the skipped ones: true for a bad checksum, false for a malformed one.+ */+ internal fun forEachFrame(b: ByteArray, n: Int, rssiOffset: Int, lnaGain: Int, onBad: (Boolean) -> Unit = {},+ onFrame: (Int, Int, Int?) -> Unit) {+ var off = 0+ while (off + 4 + 16 + 4 <= n) {+ val pktLen = le32(b, off) and 0xffff+ if (pktLen < 16 + 10 || off + 4 + pktLen + 4 > n) { if (off == 0) onBad(false); return } // trailing USB padding is fine+ val rxwi = off + 4+ val mpdu = (le32(b, rxwi) ushr 16) and 0xfff+ val rxd = le32(b, off + 4 + pktLen)+ val start = rxwi + 16+ when {+ rxd and 0x100 != 0 -> onBad(true)+ mpdu < 24 || start + mpdu > off + 4 + pktLen -> onBad(false)+ else -> {+ val raw = b[rxwi + 8].toInt() // RSSI0; 0 = no reading+ onFrame(start, start + mpdu, if (raw > 0) -12 - rssiOffset - lnaGain - raw else null)+ }+ }+ off += 4 + pktLen + 4+ }+ if (off == 0) onBad(false)+ }++ // ---- register access ----++ /** Failed register reads / writes (an unplugged or stalled adapter), for the log. */+ @Volatile private var ctlErrors = 0++ private fun regWr(addr: Int, v: Int) {+ val b = ByteArray(4); putLe32(b, 0, v)+ if (conn.controlTransfer(OUT_VENDOR, MULTI_WRITE, 0, addr, b, 4, 1000) < 0) ctlErrors+++ }+ private fun regRd(addr: Int): Int {+ val b = ByteArray(4)+ if (conn.controlTransfer(IN_VENDOR, MULTI_READ, 0, addr, b, 4, 1000) != 4) { ctlErrors++; return 0 }+ return le32(b, 0)+ }++ private fun bbpIdle() = poll(50) { regRd(BBP_CSR_CFG) and 0x20000 == 0 }+ private fun bbpWr(reg: Int, v: Int) {+ bbpIdle()+ regWr(BBP_CSR_CFG, (v and 0xff) or ((reg and 0xff) shl 8) or 0x20000 or 0x80000)+ }+ private fun bbpRd(reg: Int): Int {+ bbpIdle()+ regWr(BBP_CSR_CFG, ((reg and 0xff) shl 8) or 0x10000 or 0x20000 or 0x80000)+ bbpIdle()+ return regRd(BBP_CSR_CFG) and 0xff+ }++ private fun rfIdle() = poll(50) { regRd(RF_CSR_CFG) and 0x20000 == 0 }+ private fun rfWr(reg: Int, v: Int) {+ rfIdle()+ regWr(RF_CSR_CFG, (v and 0xff) or ((reg and 0x3f) shl 8) or 0x10000 or 0x20000)+ }+ private fun rfRd(reg: Int): Int {+ rfIdle()+ regWr(RF_CSR_CFG, ((reg and 0x3f) shl 8) or 0x20000)+ rfIdle()+ return regRd(RF_CSR_CFG) and 0xff+ }++ private fun disableWpdma() {+ // TX / RX DMA off, busy bits cleared, TX write-back done set+ regWr(WPDMA_GLO_CFG, (regRd(WPDMA_GLO_CFG) and 0x0f.inv()) or 0x40)+ }+ private fun waitCsrReady() = poll(1000) { regRd(MAC_CSR0).let { it != 0 && it != -1 } }+ private fun waitWpdma() = poll(1000) { regRd(WPDMA_GLO_CFG) and 0x0a == 0 }++ private inline fun poll(ms: Long, ok: () -> Boolean): Boolean {+ val end = System.currentTimeMillis() + ms+ do { if (ok()) return true; sleep(1) } while (System.currentTimeMillis() < end)+ return false+ }++ /** Sets the field [mask] of [reg] to [v] (truncated to the field, like rt2x00_set_field32). */+ private fun setf(reg: Int, mask: Int, v: Int) = (reg and mask.inv()) or ((v shl Integer.numberOfTrailingZeros(mask)) and mask)+ private fun putLe32(b: ByteArray, i: Int, v: Int) { b[i] = v.toByte(); b[i + 1] = (v ushr 8).toByte(); b[i + 2] = (v ushr 16).toByte(); b[i + 3] = (v ushr 24).toByte() }+ private fun le32(b: ByteArray, i: Int) = (b[i].toInt() and 0xff) or ((b[i + 1].toInt() and 0xff) shl 8) or+ ((b[i + 2].toInt() and 0xff) shl 16) or ((b[i + 3].toInt() and 0xff) shl 24)+ private fun sleep(ms: Int) = try { Thread.sleep(ms.toLong()) } catch (_: InterruptedException) {}+}diff --git a/app/src/main/java/com/rfsentinel/app/usb/Rtl8187Monitor.kt b/app/src/main/java/com/rfsentinel/app/usb/Rtl8187Monitor.ktnew file mode 100644index 0000000..24bbf59--- /dev/null+++ b/app/src/main/java/com/rfsentinel/app/usb/Rtl8187Monitor.kt@@ -0,0 +1,730 @@+package com.rfsentinel.app.usb++/*+ * Receive-only monitor mode for Realtek RTL8187L / RTL8187B USB WiFi adapters+ * (e.g. ALFA AWUS036H), 2.4 GHz 802.11b/g, driven from userspace over Android's USB+ * host API - no root, no kernel driver, no firmware. Hops the 2.4 GHz channels and+ * reports the access points and client devices it hears. It never transmits.+ *+ * Bring-up, radio (RTL8225 / RTL8225Z2) tuning and RX descriptor handling are ported+ * from the Linux kernel rtl8187 driver (drivers/net/wireless/realtek/rtl818x/rtl8187;+ * Michael Wu, Andrea Merello, Herton Ronaldo Krzesinski, Hin-Tak Leung, Larry Finger;+ * register values from Realtek's r8187 driver), with Kismet's Android userspace port+ * (Android PCAP Capture, Mike Kershaw / Dragorn) as the reference for driving it over USB.+ * Both GPL-2.0. Every transmit path (TX power is left at the lowest setting) was left out.+ */++import android.content.Context+import android.hardware.usb.UsbDevice+import android.hardware.usb.UsbDeviceConnection+import android.hardware.usb.UsbManager++object Rtl8187Monitor {+ @Volatile var running = false; private set+ @Volatile private var stop = false++ private val frames = MonitorFrames()+ private val HOP = intArrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)+ private const val DWELL_MS = 350L+ private val FRESH_MS get() = (HOP.size * DWELL_MS * 9 / 5).coerceAtLeast(3000L)+ private const val REPORT_MS = 10_000L++ /** USB IDs the kernel driver runs as RTL8187B (the rest are RTL8187L unless the chip says otherwise). */+ private val B_IDS = setOf(0x050d to 0x705e, 0x0bda to 0x8189, 0x0bda to 0x8197, 0x0bda to 0x8198,+ 0x0846 to 0x4260, 0x0df6 to 0x0028, 0x0df6 to 0x0029, 0x1737 to 0x0073)++ private const val REQT_READ = 0xC0; private const val REQT_WRITE = 0x40; private const val REQ_REG = 0x05+ /** One frame per bulk transfer, at most this long (RTL8187_MAX_RX). */+ private const val MAX_RX = 0x9C4++ // struct rtl818x_csr, mapped at 0xFF00+ private const val MAR0 = 0xFF08; private const val MAR1 = 0xFF0C; private const val BRSR = 0xFF2C+ private const val RESP_RATE = 0xFF34; private const val CMD = 0xFF37; private const val INT_MASK = 0xFF3C+ private const val TX_CONF = 0xFF40; private const val RX_CONF = 0xFF44; private const val INT_TIMEOUT = 0xFF48+ private const val EEPROM_CMD = 0xFF50; private const val CONFIG1 = 0xFF52; private const val ANAPARAM = 0xFF54+ private const val MSR = 0xFF58; private const val CONFIG3 = 0xFF59; private const val TESTR = 0xFF5B+ private const val PGSELECT = 0xFF5E; private const val ANAPARAM2 = 0xFF60; private const val PHY0 = 0xFF7C+ private const val RF_OUT = 0xFF80; private const val RF_EN = 0xFF82; private const val RF_SEL = 0xFF84+ private const val RF_IN = 0xFF86; private const val RF_PARA = 0xFF88; private const val RF_TIMING = 0xFF8C+ private const val GP_ENABLE = 0xFF90; private const val GPIO0 = 0xFF91; private const val HSSI_PARA = 0xFF94+ private const val TX_AGC_CTL = 0xFF9C; private const val TX_GAIN_CCK = 0xFF9D; private const val TX_GAIN_OFDM = 0xFF9E+ private const val TX_ANTENNA = 0xFF9F; private const val WPA_CONF = 0xFFB0; private const val CW_CONF = 0xFFBC+ private const val RATE_FALLBACK = 0xFFBE; private const val ACM_CONTROL = 0xFFBF; private const val INT_MIG = 0xFFE2+ private const val TID_AC_MAP = 0xFFE8; private const val ANAPARAM3A = 0xFFEE; private const val TALLY_SEL = 0xFFFC++ private const val EEPROM_CMD_NORMAL = 0x00; private const val EEPROM_CMD_LOAD = 0x40; private const val EEPROM_CMD_CONFIG = 0xC0+ private const val CONFIG3_ANAPARAM_WRITE = 0x40+ private const val CMD_TX_ENABLE = 0x04; private const val CMD_RX_ENABLE = 0x08; private const val CMD_RESET = 0x10+ private const val TX_CONF_LOOPBACK_MAC = 1 shl 17; private const val TX_CONF_NO_ICV = 1 shl 19+ private const val TX_CONF_HWVER_MASK = 7 shl 25; private const val TX_CONF_R8187vD = 5 shl 25; private const val TX_CONF_R8187vD_B = 6 shl 25+ private const val TX_CONF_DISREQQSIZE = 1 shl 28; private const val TX_CONF_HW_SEQNUM = 1 shl 30; private const val TX_CONF_CW_MIN = 1 shl 31+ private const val RX_CONF_MONITOR = 1 shl 0; private const val RX_CONF_NICMAC = 1 shl 1; private const val RX_CONF_BROADCAST = 1 shl 3+ private const val RX_CONF_DATA = 1 shl 18; private const val RX_CONF_MGMT = 1 shl 20; private const val RX_CONF_BSSID = 1 shl 23+ private const val RX_CONF_AUTORESETPHY = 1 shl 28; private const val RX_CONF_ONLYERLPKT = 1 shl 31+ private const val RX_FIFO_NONE = 7 shl 13; private const val RX_MAX_DMA = 7 shl 10+ /** RX descriptor: the frame's checksum failed. */+ private const val RX_DESC_CRC32_ERR = 1 shl 13++ private const val ANAPARAM_ON_L = 0xa0000a59.toInt(); private const val ANAPARAM2_ON_L = 0x860c7312.toInt()+ private const val ANAPARAM_ON_B = 0x45090658; private const val ANAPARAM2_ON_B = 0x727f3f52++ private enum class Rf { RTL8225, RTL8225Z2, RTL8225Z2B }+ private const val BvB = 0; private const val BvD = 1; private const val BvE = 2++ private lateinit var conn: UsbDeviceConnection+ private var is8187b = false+ private var hwRev = BvB+ /** 0: B-cut ASIC, radio registers by bit-banging the 3-wire bus; otherwise by a USB request. */+ private var asicRev = 0+ private var rf = Rf.RTL8225++ fun abort() { stop = true }++ fun run(ctx: Context, device: UsbDevice, chipName: String, onStatus: (String) -> Unit,+ onFrame: (List<MonitorSighting>) -> Unit) {+ if (running) return+ running = true; stop = false; frames.clear()+ val mgr = ctx.getSystemService(Context.USB_SERVICE) as UsbManager+ val c = mgr.openDevice(device) ?: run { onStatus("$chipName: couldn't reopen adapter"); running = false; return }+ conn = c; ctlErrors = 0+ try {+ val intf = device.getInterface(0)+ val claimed = c.claimInterface(intf, true)+ UsbWifi.log("=== RTL8187 bring-up (rtl8187) ===")+ if (!claimed) UsbWifi.log("RTL8187: couldn't claim the USB interface (continuing)")+ is8187b = (device.vendorId to device.productId) in B_IDS+ val t0 = System.currentTimeMillis()++ w8(EEPROM_CMD, EEPROM_CMD_CONFIG)+ val pg = r8(PGSELECT) and 1.inv()+ w8(PGSELECT, pg or 1)+ asicRev = r8(0xFFFE) and 0x3+ w8(PGSELECT, pg)+ w8(EEPROM_CMD, EEPROM_CMD_NORMAL)+ val chip = if (!is8187b) {+ when (r32(TX_CONF) and TX_CONF_HWVER_MASK) {+ TX_CONF_R8187vD_B -> { is8187b = true; hwRev = BvB; "RTL8187BvB (early)" } // some 8187B report the 8187 ID+ TX_CONF_R8187vD -> "RTL8187vD"+ else -> "RTL8187vB"+ }+ } else when (r8(0xFFE1)) {+ 1 -> { hwRev = BvD; "RTL8187BvD" }+ 2 -> { hwRev = BvE; "RTL8187BvE" }+ else -> { hwRev = BvB; "RTL8187BvB" }+ }+ var detect = ""+ rf = if (is8187b) Rf.RTL8225Z2B else {+ rfWrite(0, 0x1B7)+ val reg8 = rfRead(8); val reg9 = rfRead(9)+ rfWrite(0, 0x0B7)+ detect = " (RF reg8 0x%03x, reg9 0x%03x)".format(reg8, reg9)+ if (reg8 != 0x588 || reg9 != 0x700) Rf.RTL8225 else Rf.RTL8225Z2+ }+ val rx = BulkRx.inEndpoint(intf, if (is8187b) 0x83 else 0x81)+ ?: run { UsbWifi.log("RTL8187: no bulk-IN endpoint"); onStatus("$chipName: no RX endpoint"); return }+ UsbWifi.log("RTL8187: $chip, radio $rf$detect, ASIC rev $asicRev (${if (asicRev != 0) "USB" else "bit-banged"} radio writes), " ++ "TX_CONF 0x%08x, RX EP 0x%02x".format(r32(TX_CONF), rx.address))++ onStatus("$chipName · starting radio…")+ if (!(if (is8187b) initHwB() else initHwL())) { onStatus("$chipName: reset timed out (replug)"); return }+ start()+ tune(HOP[0], txPower = true)+ UsbWifi.log("RTL8187: started in ${System.currentTimeMillis() - t0} ms - RX_CONF 0x%08x TX_CONF 0x%08x CMD 0x%02x CONFIG3 0x%02x ANAPARAM 0x%08x ANAPARAM2 0x%08x, USB errors %d - monitor live ch %d".format(+ r32(RX_CONF), r32(TX_CONF), r8(CMD), r8(CONFIG3), r32(ANAPARAM), r32(ANAPARAM2), ctlErrors, HOP[0]))+ onStatus("$chipName · live · 2.4 GHz monitor")+ rxLoop(chipName, rx, onFrame, onStatus)+ } catch (e: Exception) {+ UsbWifi.log("RTL8187: bring-up error - ${UsbWifi.describe(e)}")+ onStatus("$chipName: error · ${e.message}")+ } finally {+ runCatching { c.close() }+ running = false+ }+ }++ // ---- bring-up (rtl8187_init_hw / rtl8187b_init_hw / rtl8187_start) ----++ private fun setAnaparam() {+ w8(EEPROM_CMD, EEPROM_CMD_CONFIG)+ val reg = r8(CONFIG3) or CONFIG3_ANAPARAM_WRITE+ w8(CONFIG3, reg)+ w32(ANAPARAM, if (is8187b) ANAPARAM_ON_B else ANAPARAM_ON_L)+ w32(ANAPARAM2, if (is8187b) ANAPARAM2_ON_B else ANAPARAM2_ON_L)+ if (is8187b) w8(ANAPARAM3A, 0x00)+ w8(CONFIG3, reg and CONFIG3_ANAPARAM_WRITE.inv())+ w8(EEPROM_CMD, EEPROM_CMD_NORMAL)+ }++ private fun cmdReset(): Boolean {+ w8(CMD, (r8(CMD) and 0x02) or CMD_RESET)+ var ok = false+ for (i in 0 until 10) { sleep(2); if (r8(CMD) and CMD_RESET == 0) { ok = true; break } }+ if (!ok) { UsbWifi.log("RTL8187: reset timeout"); return false }+ w8(EEPROM_CMD, EEPROM_CMD_LOAD) // reload registers from the EEPROM+ for (i in 0 until 10) { sleep(4); if (r8(EEPROM_CMD) and EEPROM_CMD_CONFIG == 0) return true }+ UsbWifi.log("RTL8187: EEPROM reload timeout")+ return false+ }++ private fun initHwL(): Boolean {+ setAnaparam()+ w16(INT_MASK, 0)+ sleep(200)+ w8(0xFE18, 0x10); w8(0xFE18, 0x11); w8(0xFE18, 0x00)+ sleep(200)+ if (!cmdReset()) return false+ setAnaparam()++ w16(RF_SEL, 0); w8(GPIO0, 0)+ w16(RF_SEL, 4 shl 8); w8(GPIO0, 1); w8(GP_ENABLE, 0)+ w8(EEPROM_CMD, EEPROM_CMD_CONFIG)+ w16(0xFFF4, 0xFFFF)+ w8(CONFIG1, (r8(CONFIG1) and 0x3F) or 0x80)+ w8(EEPROM_CMD, EEPROM_CMD_NORMAL)+ w32(INT_TIMEOUT, 0); w8(WPA_CONF, 0); w8(RATE_FALLBACK, 0)+ w8(RESP_RATE, 8 shl 4); w16(BRSR, 0x01F3)++ // host_usb_init+ w16(RF_SEL, 0); w8(GPIO0, 0)+ w8(0xFE53, r8(0xFE53) or 0x80)+ w16(RF_SEL, 4 shl 8); w8(GPIO0, 0x20); w8(GP_ENABLE, 0)+ w16(RF_OUT, 0x80); w16(RF_SEL, 0x80); w16(RF_EN, 0x80)+ sleep(100)+ w32(RF_TIMING, 0x000a8008); w16(BRSR, 0xFFFF); w32(RF_PARA, 0x00100044)+ w8(EEPROM_CMD, EEPROM_CMD_CONFIG); w8(CONFIG3, 0x44); w8(EEPROM_CMD, EEPROM_CMD_NORMAL)+ w16(RF_EN, 0x1FF7)+ sleep(100)++ rfInit()++ w16(BRSR, 0x01F3)+ val pg = r8(PGSELECT) and 1.inv()+ w8(PGSELECT, pg or 1); w16(0xFFFE, 0x10); w8(TALLY_SEL, 0x80); w8(0xFFFF, 0x60); w8(PGSELECT, pg)+ return true+ }++ private fun initHwB(): Boolean {+ setAnaparam()+ // Reset the PLL (Realtek: saves about 30 mA)+ w8(0xFF61, 0x10)+ val pll = r8(0xFF62)+ w8(0xFF62, pll and 0x20.inv()); w8(0xFF62, pll or 0x20)+ if (!cmdReset()) return false+ setAnaparam()++ w16(0xFF34, 0x0FFF) // all 12 rates+ w8(CW_CONF, r8(CW_CONF) or 0x02)+ w16(0xFFE0, 0x0FFF, 1); w8(0xFFE2, 0x00, 1) // auto rate fallback 1M-54M+ w16(0xFFD4, 0xFFFF, 1)+ w8(EEPROM_CMD, EEPROM_CMD_CONFIG)+ w8(CONFIG1, (r8(CONFIG1) and 0x3F) or 0x80)+ w8(EEPROM_CMD, EEPROM_CMD_NORMAL)+ w8(WPA_CONF, 0)+ for (e in REG_TABLE_B) w8(e[0] or 0xFF00, e[1], e[2])+ w16(TID_AC_MAP, 0xFA50); w16(INT_MIG, 0)+ w32(0xFFF0, 0, 1); w32(0xFFF4, 0, 1); w8(0xFFF8, 0, 1)+ w32(RF_TIMING, 0x00004001)+ w16(0xFF72, 0x569A, 2) // RFSW_CTRL+ w16(RF_OUT, 0x0480); w16(RF_SEL, 0x2488); w16(RF_EN, 0x1FFF)+ sleep(100)++ rfInit()++ w8(CMD, CMD_TX_ENABLE or CMD_RX_ENABLE)+ w16(INT_MASK, 0xFFFF)+ w8(0xFE41, 0xF4); w8(0xFE40, 0x00); w8(0xFE42, 0x00); w8(0xFE42, 0x01)+ w8(0xFE40, 0x0F); w8(0xFE42, 0x00); w8(0xFE42, 0x01)+ w8(0xFFDB, r8(0xFFDB) or 0x04)+ w16(0xFF72, 0x59FA, 3); w16(0xFF74, 0x59D2, 3); w16(0xFF76, 0x59D2, 3)+ w16(0xFF78, 0x19FA, 3); w16(0xFF7A, 0x19FA, 3); w16(0xFF7C, 0x00D0, 3)+ w8(0xFF61, 0)+ w8(0xFF80, 0x0F, 1); w8(0xFF83, 0x03, 1); w8(0xFFDA, 0x10); w8(0xFF4D, 0x08, 2)+ w32(HSSI_PARA, 0x0600321B)+ w16(0xFFEC, 0x0800, 1)+ w8(ACM_CONTROL, 0)+ w8(MSR, 0x10) // ENEDCA+ return true+ }++ private fun start() {+ if (is8187b) {+ w32(RX_CONF, RX_CONF_MGMT or RX_CONF_DATA or RX_CONF_BROADCAST or RX_CONF_NICMAC or RX_CONF_BSSID or+ RX_FIFO_NONE or RX_MAX_DMA or RX_CONF_AUTORESETPHY or RX_CONF_ONLYERLPKT or RX_CONF_MONITOR)+ w8(TX_AGC_CTL, r8(TX_AGC_CTL) and 0x07.inv())+ w32(TX_CONF, TX_CONF_HW_SEQNUM or TX_CONF_DISREQQSIZE or (7 shl 8) or 7 or (7 shl 21))+ return+ }+ w16(INT_MASK, 0xFFFF)+ w32(MAR0, -1); w32(MAR1, -1)+ w32(RX_CONF, RX_CONF_ONLYERLPKT or RX_CONF_AUTORESETPHY or RX_CONF_BSSID or RX_CONF_MGMT or RX_CONF_DATA or+ RX_FIFO_NONE or RX_MAX_DMA or RX_CONF_BROADCAST or RX_CONF_NICMAC or RX_CONF_MONITOR)+ w8(CW_CONF, (r8(CW_CONF) and 0x01.inv()) or 0x02)+ w8(TX_AGC_CTL, r8(TX_AGC_CTL) and 0x07.inv())+ w32(TX_CONF, TX_CONF_CW_MIN or (7 shl 21) or TX_CONF_NO_ICV)+ w8(CMD, r8(CMD) or CMD_TX_ENABLE or CMD_RX_ENABLE)+ }++ /** rtl8187_config: tune with the MAC in TX loopback, so nothing can go out during the change. */+ private fun tune(ch: Int, txPower: Boolean = false) {+ val reg = r32(TX_CONF)+ w32(TX_CONF, reg or TX_CONF_LOOPBACK_MAC)+ if (txPower) setTxPower(ch)+ rfWrite(0x7, CHAN[ch - 1])+ sleep(10)+ sleep(10)+ w32(TX_CONF, reg)+ }++ // ---- RTL8225 radio (rtl8225.c) ----++ private fun rfInit() = when (rf) {+ Rf.RTL8225 -> rf8225Init()+ Rf.RTL8225Z2 -> rf8225z2Init()+ Rf.RTL8225Z2B -> rf8225z2bInit()+ }++ private fun rfCalibrate(name: String) {+ var r6 = rfRead(6)+ if (r6 and 0x80 == 0) {+ rfWrite(0x02, 0x0C4D); sleep(200)+ rfWrite(0x02, 0x044D); sleep(100)+ r6 = rfRead(6)+ }+ UsbWifi.log("RTL8187: $name RF calibration %s (reg6 0x%03x)".format(if (r6 and 0x80 != 0) "ok" else "FAILED", r6))+ }++ private fun rf8225Init() {+ val init = intArrayOf(0x067, 0xFE0, 0x44D, 0x441, 0x486, 0xBC0, 0xAE6, 0x82A,+ 0x01F, 0x334, 0xFD4, 0x391, 0x050, 0x6DB, 0x029, 0x914)+ for (i in init.indices) rfWrite(i, init[i])+ sleep(100)+ rfWrite(0x2, 0xC4D); sleep(200)+ rfWrite(0x2, 0x44D); sleep(200)+ rfCalibrate("RTL8225")+ rfWrite(0x0, 0x127)+ for (i in RXGAIN_8225.indices) { rfWrite(0x1, i + 1); rfWrite(0x2, RXGAIN_8225[i]) }+ rfWrite(0x0, 0x027); rfWrite(0x0, 0x22F)+ for (i in AGC_8225.indices) { phyOfdm(0xB, AGC_8225[i]); phyOfdm(0xA, 0x80 + i) }+ sleep(1)+ for (e in OFDM_8225) phyOfdm(e[0], e[1])+ sensitivity8225()+ for (e in CCK_8225) phyCck(e[0], e[1])+ w8(TESTR, 0x0D)+ setTxPower(1)+ antennaA()+ // set sensitivity+ rfWrite(0x0c, 0x50)+ sensitivity8225()+ phyCck(0x41, 0x8d) // rtl8225_threshold[2]+ }++ private fun sensitivity8225() {+ phyOfdm(0x0d, GAIN_8225[8]); phyOfdm(0x1b, GAIN_8225[10]); phyOfdm(0x1d, GAIN_8225[11]); phyOfdm(0x23, GAIN_8225[9])+ }++ private fun rf8225z2Init() {+ val init = intArrayOf(0x2BF, 0xEE0, 0x44D, 0x441, 0x8C3, 0xC72, 0x0E6, 0x82A,+ 0x03F, 0x335, 0x9D4, 0x7BB, 0x850, 0xCDF, 0x02B, 0x114)+ for (i in init.indices) rfWrite(i, init[i])+ sleep(100)+ rfWrite(0x0, 0x1B7)+ for (i in RXGAIN_Z2.indices) { rfWrite(0x1, i + 1); rfWrite(0x2, RXGAIN_Z2[i]) }+ rfWrite(0x3, 0x080); rfWrite(0x5, 0x004); rfWrite(0x0, 0x0B7)+ rfWrite(0x2, 0xC4D); sleep(200)+ rfWrite(0x2, 0x44D); sleep(100)+ rfCalibrate("RTL8225Z2")+ sleep(200)+ rfWrite(0x0, 0x2BF)+ for (i in AGC_8225.indices) { phyOfdm(0xB, AGC_8225[i]); phyOfdm(0xA, 0x80 + i) }+ sleep(1)+ for (e in OFDM_Z2) phyOfdm(e[0], e[1])+ phyOfdm(0x0b, 0x23); phyOfdm(0x1b, 0x15); phyOfdm(0x1d, 0xc5) // rtl8225z2_gain_bg[12..14]+ phyOfdm(0x21, 0x37)+ for (e in CCK_Z2) phyCck(e[0], e[1])+ w8(TESTR, 0x0D); sleep(1)+ setTxPower(1)+ antennaA()+ }++ private fun rf8225z2bInit() {+ val init = intArrayOf(0x0B7, 0xEE0, 0x44D, 0x441, 0x8C3, 0xC72, 0x0E6, 0x82A,+ 0x03F, 0x335, 0x9D4, 0x7BB, 0x850, 0xCDF, 0x02B, 0x114)+ for (i in init.indices) rfWrite(i, init[i])+ rfWrite(0x0, 0x1B7)+ for (i in RXGAIN_Z2.indices) { rfWrite(0x1, i + 1); rfWrite(0x2, RXGAIN_Z2[i]) }+ rfWrite(0x3, 0x080); rfWrite(0x5, 0x004); rfWrite(0x0, 0x0B7)+ rfWrite(0x2, 0xC4D); rfWrite(0x2, 0x44D); rfWrite(0x0, 0x2BF)+ w8(TX_GAIN_CCK, 0x03); w8(TX_GAIN_OFDM, 0x07); w8(TX_ANTENNA, 0x03)+ phyOfdm(0x80, 0x12)+ for (i in AGC_Z2.indices) { phyOfdm(0xF, AGC_Z2[i]); phyOfdm(0xE, 0x80 + i); phyOfdm(0xE, 0) }+ phyOfdm(0x80, 0x10)+ for (i in OFDM_Z2B.indices) phyOfdm(i, OFDM_Z2B[i])+ phyOfdm(0x97, 0x46); phyOfdm(0xa4, 0xb6); phyOfdm(0x85, 0xfc)+ phyCck(0xc1, 0x88)+ }++ /** RX on antenna A (the AWUS036H has one connector). */+ private fun antennaA() {+ phyCck(0x10, 0x9b)+ phyOfdm(0x26, 0x90)+ w8(TX_ANTENNA, 0x03)+ sleep(1)+ w32(HSSI_PARA, 0x3dc00002)+ }++ /**+ * The radio's transmit power registers, at the lowest setting: this driver never+ * transmits, but the kernel driver writes them on every tune and they share the+ * analog / OFDM setup with the receiver.+ */+ private fun setTxPower(ch: Int) {+ when (rf) {+ Rf.RTL8225 -> {+ val cck = 0; val ofdm = 10+ w8(TX_GAIN_CCK, TX_GAIN_8225[cck / 6] shr 1)+ val tab = if (ch == 14) TX_CCK_8225_CH14 else TX_CCK_8225+ for (i in 0 until 8) phyCck(0x44 + i, tab[(cck % 6) * 8 + i])+ sleep(1)+ anaparam2On()+ phyOfdm(2, 0x42); phyOfdm(6, 0x00); phyOfdm(8, 0x00)+ w8(TX_GAIN_OFDM, TX_GAIN_8225[ofdm / 6] shr 1)+ phyOfdm(5, TX_OFDM_8225[ofdm % 6]); phyOfdm(7, TX_OFDM_8225[ofdm % 6])+ sleep(1)+ }+ Rf.RTL8225Z2 -> {+ val cck = 0; val ofdm = 10+ val tab = if (ch == 14) TX_CCK_Z2_CH14 else TX_CCK_Z2+ for (i in 0 until 8) phyCck(0x44 + i, tab[i])+ w8(TX_GAIN_CCK, cck); sleep(1) // rtl8225z2_tx_gain_cck_ofdm[n] == n+ anaparam2On()+ phyOfdm(2, 0x42); phyOfdm(5, 0x00); phyOfdm(6, 0x40); phyOfdm(7, 0x00); phyOfdm(8, 0x40)+ w8(TX_GAIN_OFDM, ofdm)+ sleep(1)+ }+ Rf.RTL8225Z2B -> {+ val bvb = hwRev == BvB+ val cck = if (bvb) 0 else 7+ val ofdm = if (bvb) 2 else 10+ val tab = if (ch == 14) TX_CCK_Z2_CH14 else TX_CCK_Z2+ val row = if (bvb) 0 else 8 // cck 0 (BvB) or 7 (others)+ for (i in 0 until 8) phyCck(0x44 + i, tab[row + i])+ w8(TX_GAIN_CCK, cck shl 1); sleep(1)+ w8(TX_GAIN_OFDM, ofdm shl 1)+ val v = if (bvb) 0x60 else 0x5c // ofdm <= 11+ phyOfdm(0x87, v); phyOfdm(0x89, v)+ sleep(1)+ }+ }+ }++ private fun anaparam2On() {+ w8(EEPROM_CMD, EEPROM_CMD_CONFIG)+ val reg = r8(CONFIG3)+ w8(CONFIG3, reg or CONFIG3_ANAPARAM_WRITE)+ w32(ANAPARAM2, ANAPARAM2_ON_L)+ w8(CONFIG3, reg and CONFIG3_ANAPARAM_WRITE.inv())+ w8(EEPROM_CMD, EEPROM_CMD_NORMAL)+ }++ private fun rfWrite(addr: Int, data: Int) = if (asicRev != 0) rfWrite8051(addr, data) else rfWriteBitbang(addr, data)++ private fun rfWrite8051(addr: Int, data: Int) {+ val reg80 = r16(RF_OUT) and 0x000C.inv(); val reg82 = r16(RF_EN); val reg84 = r16(RF_SEL) and 0x000F.inv()+ w16(RF_EN, reg82 or 0x7); w16(RF_SEL, reg84 or 0x7)+ w16(RF_OUT, reg80 or 0x4); w16(RF_OUT, reg80)+ if (conn.controlTransfer(REQT_WRITE, REQ_REG, addr, 0x8225, byteArrayOf(data.toByte(), (data ushr 8).toByte()), 2, 500) < 0) ctlErrors+++ w16(RF_OUT, reg80 or 0x4); w16(RF_OUT, reg80 or 0x4)+ w16(RF_SEL, reg84)+ }++ private fun rfWriteBitbang(addr: Int, data: Int) {+ val bang = (data shl 4) or (addr and 0xf)+ val reg80 = r16(RF_OUT) and 0xfff3; val reg82 = r16(RF_EN)+ w16(RF_EN, reg82 or 0x7)+ val reg84 = r16(RF_SEL)+ w16(RF_SEL, reg84 or 0x7)+ w16(RF_OUT, reg80 or 0x4); w16(RF_OUT, reg80)+ for (i in 15 downTo 0) {+ val reg = reg80 or ((bang ushr i) and 1)+ if (i and 1 != 0) w16(RF_OUT, reg)+ w16(RF_OUT, reg or 0x2); w16(RF_OUT, reg or 0x2)+ if (i and 1 == 0) w16(RF_OUT, reg)+ }+ w16(RF_OUT, reg80 or 0x4); w16(RF_OUT, reg80 or 0x4)+ w16(RF_SEL, reg84)+ }++ private fun rfRead(addr: Int): Int {+ val reg80 = r16(RF_OUT) and 0xF.inv() and 0xffff; val reg82 = r16(RF_EN); val reg84 = r16(RF_SEL)+ w16(RF_EN, reg82 or 0xF); w16(RF_SEL, reg84 or 0xF)+ w16(RF_OUT, reg80 or 0x4); w16(RF_OUT, reg80)+ for (i in 4 downTo 0) {+ val reg = reg80 or ((addr shr i) and 1)+ if (i and 1 == 0) w16(RF_OUT, reg)+ w16(RF_OUT, reg or 0x2); w16(RF_OUT, reg or 0x2)+ if (i and 1 != 0) w16(RF_OUT, reg)+ }+ w16(RF_OUT, reg80 or 0x8 or 0x2); w16(RF_OUT, reg80 or 0x8); w16(RF_OUT, reg80 or 0x8)+ var out = 0+ for (i in 11 downTo 0) {+ w16(RF_OUT, reg80 or 0x8)+ w16(RF_OUT, reg80 or 0x8 or 0x2); w16(RF_OUT, reg80 or 0x8 or 0x2); w16(RF_OUT, reg80 or 0x8 or 0x2)+ if (r16(RF_IN) and 0x2 != 0) out = out or (1 shl i)+ w16(RF_OUT, reg80 or 0x8)+ }+ w16(RF_OUT, reg80 or 0x8 or 0x4)+ w16(RF_EN, reg82); w16(RF_SEL, reg84); w16(RF_OUT, 0x03A0)+ return out+ }++ private fun writePhy(addr: Int, data: Int) {+ val d = (data shl 8) or addr or 0x80+ w8(PHY0 + 3, (d ushr 24) and 0xff); w8(PHY0 + 2, (d ushr 16) and 0xff)+ w8(PHY0 + 1, (d ushr 8) and 0xff); w8(PHY0, d and 0xff)+ }+ private fun phyOfdm(addr: Int, data: Int) = writePhy(addr, data)+ private fun phyCck(addr: Int, data: Int) = writePhy(addr, data or 0x10000)++ // ---- receive ----++ private class RxState { var hopAt = 0L; var lastEmit = 0L; var hopIdx = 0 }++ private fun rxLoop(chipName: String, ep: android.hardware.usb.UsbEndpoint,+ onFrame: (List<MonitorSighting>) -> Unit, onStatus: (String) -> Unit) {+ val st = RxState()+ val t0 = System.currentTimeMillis(); st.hopAt = t0; st.lastEmit = t0+ val stats = BulkRx.Stats("RTL8187")+ val hdr = if (is8187b) 20 else 16+ val total = BulkRx.run("RTL8187", conn, ep, 16, MAX_RX, { stop }, onData@{ b, n ->+ stats.transfer(n)+ if (n >= hdr) stats.sample("$n bytes, frame control %02x, descriptor".format(b[0].toInt() and 0xff), b, n - hdr, hdr)+ val f = parseRx(b, n, is8187b)+ if (f == null) {+ if (n >= hdr && le32(b, n - hdr) and RX_DESC_CRC32_ERR != 0) stats.badChecksum++ else stats.malformed+++ return@onData+ }+ stats.frame(f.rssi)+ frames.frame(b, f.start, f.end, HOP[st.hopIdx], f.rssi)+ }) { now ->+ stats.maybeLog(now) {+ val (aps, clients) = frames.live(now, REPORT_MS)+ "ch ${HOP[st.hopIdx]}, $aps access points, $clients devices, USB errors $ctlErrors"+ }+ if (now - st.lastEmit > 2000) { emit(onFrame); st.lastEmit = now }+ if (now - st.hopAt > DWELL_MS) {+ st.hopIdx = (st.hopIdx + 1) % HOP.size+ runCatching { tune(HOP[st.hopIdx]) }+ val (aps, clients) = frames.live(now, REPORT_MS)+ onStatus("$chipName · live · $aps access points · $clients devices · ch ${HOP[st.hopIdx]}")+ st.hopAt = now+ }+ }+ emit(onFrame)+ UsbWifi.log("RTL8187: RX loop stopped ($total B)")+ }++ private fun emit(onFrame: (List<MonitorSighting>) -> Unit) {+ val batch = frames.drain(System.currentTimeMillis(), FRESH_MS)+ if (batch.isNotEmpty()) onFrame(batch)+ }++ /** Where the 802.11 frame sits in a received transfer (FCS removed) and its signal in dBm. */+ internal data class Rx(val start: Int, val end: Int, val rssi: Int)++ /**+ * One bulk transfer = one frame followed by the RX descriptor (16 bytes on the+ * RTL8187L, 20 on the RTL8187B). Null for a failed checksum or a malformed transfer.+ */+ internal fun parseRx(b: ByteArray, n: Int, is8187b: Boolean): Rx? {+ val hdr = if (is8187b) 20 else 16+ if (n < hdr + 24 || n > b.size) return null+ val h = n - hdr+ val flags = le32(b, h)+ if (flags and RX_DESC_CRC32_ERR != 0) return null+ val len = flags and 0x0FFF // frame + FCS+ if (len < 24 + 4 || len > h) return null+ // Signal from the AGC value, scaled as the kernel driver does.+ val rssi = if (is8187b) 14 - (b[h + 14].toInt() and 0xff) / 2+ else -4 - ((27 * (b[h + 6].toInt() and 0xff)) shr 6)+ return Rx(0, len - 4, rssi)+ }++ // ---- register access ----++ /** Failed register reads / writes (an unplugged or stalled adapter), for the log. */+ @Volatile private var ctlErrors = 0++ private fun read(addr: Int, len: Int, idx: Int = 0): Int {+ val b = ByteArray(len)+ if (conn.controlTransfer(REQT_READ, REQ_REG, addr, idx and 3, b, len, 500) != len) { ctlErrors++; return 0 }+ var v = 0+ for (i in len - 1 downTo 0) v = (v shl 8) or (b[i].toInt() and 0xff)+ return v+ }+ private fun write(addr: Int, v: Int, len: Int, idx: Int = 0) {+ val b = ByteArray(len) { (v ushr (8 * it)).toByte() }+ if (conn.controlTransfer(REQT_WRITE, REQ_REG, addr, idx and 3, b, len, 500) < 0) ctlErrors+++ }+ private fun r8(a: Int) = read(a, 1)+ private fun r16(a: Int) = read(a, 2)+ private fun r32(a: Int) = read(a, 4)+ private fun w8(a: Int, v: Int, idx: Int = 0) = write(a, v, 1, idx)+ private fun w16(a: Int, v: Int, idx: Int = 0) = write(a, v, 2, idx)+ private fun w32(a: Int, v: Int, idx: Int = 0) = write(a, v, 4, idx)++ private fun le32(b: ByteArray, i: Int) = (b[i].toInt() and 0xff) or ((b[i + 1].toInt() and 0xff) shl 8) or+ ((b[i + 2].toInt() and 0xff) shl 16) or ((b[i + 3].toInt() and 0xff) shl 24)+ private fun sleep(ms: Int) = try { Thread.sleep(ms.toLong()) } catch (_: InterruptedException) {}++ // ---- tables (rtl8225.c / dev.c) ----++ private val CHAN = intArrayOf(0x085c, 0x08dc, 0x095c, 0x09dc, 0x0a5c, 0x0adc, 0x0b5c,+ 0x0bdc, 0x0c5c, 0x0cdc, 0x0d5c, 0x0ddc, 0x0e5c, 0x0f72)++ private val RXGAIN_8225 = intArrayOf(+ 0x0400, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0408, 0x0409,+ 0x040a, 0x040b, 0x0502, 0x0503, 0x0504, 0x0505, 0x0540, 0x0541,+ 0x0542, 0x0543, 0x0544, 0x0545, 0x0580, 0x0581, 0x0582, 0x0583,+ 0x0584, 0x0585, 0x0588, 0x0589, 0x058a, 0x058b, 0x0643, 0x0644,+ 0x0645, 0x0680, 0x0681, 0x0682, 0x0683, 0x0684, 0x0685, 0x0688,+ 0x0689, 0x068a, 0x068b, 0x068c, 0x0742, 0x0743, 0x0744, 0x0745,+ 0x0780, 0x0781, 0x0782, 0x0783, 0x0784, 0x0785, 0x0788, 0x0789,+ 0x078a, 0x078b, 0x078c, 0x078d, 0x0790, 0x0791, 0x0792, 0x0793,+ 0x0794, 0x0795, 0x0798, 0x0799, 0x079a, 0x079b, 0x079c, 0x079d,+ 0x07a0, 0x07a1, 0x07a2, 0x07a3, 0x07a4, 0x07a5, 0x07a8, 0x07a9,+ 0x07aa, 0x07ab, 0x07ac, 0x07ad, 0x07b0, 0x07b1, 0x07b2, 0x07b3,+ 0x07b4, 0x07b5, 0x07b8, 0x07b9, 0x07ba, 0x07bb, 0x07bb)++ private val RXGAIN_Z2 = intArrayOf(+ 0x0400, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0408, 0x0409,+ 0x040a, 0x040b, 0x0502, 0x0503, 0x0504, 0x0505, 0x0540, 0x0541,+ 0x0542, 0x0543, 0x0544, 0x0545, 0x0580, 0x0581, 0x0582, 0x0583,+ 0x0584, 0x0585, 0x0588, 0x0589, 0x058a, 0x058b, 0x0643, 0x0644,+ 0x0645, 0x0680, 0x0681, 0x0682, 0x0683, 0x0684, 0x0685, 0x0688,+ 0x0689, 0x068a, 0x068b, 0x068c, 0x0742, 0x0743, 0x0744, 0x0745,+ 0x0780, 0x0781, 0x0782, 0x0783, 0x0784, 0x0785, 0x0788, 0x0789,+ 0x078a, 0x078b, 0x078c, 0x078d, 0x0790, 0x0791, 0x0792, 0x0793,+ 0x0794, 0x0795, 0x0798, 0x0799, 0x079a, 0x079b, 0x079c, 0x079d,+ 0x07a0, 0x07a1, 0x07a2, 0x07a3, 0x07a4, 0x07a5, 0x07a8, 0x07a9,+ 0x03aa, 0x03ab, 0x03ac, 0x03ad, 0x03b0, 0x03b1, 0x03b2, 0x03b3,+ 0x03b4, 0x03b5, 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bb)++ private val AGC_8225 = intArrayOf(+ 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0x9d, 0x9c, 0x9b, 0x9a, 0x99, 0x98, 0x97, 0x96,+ 0x95, 0x94, 0x93, 0x92, 0x91, 0x90, 0x8f, 0x8e, 0x8d, 0x8c, 0x8b, 0x8a, 0x89, 0x88, 0x87, 0x86,+ 0x85, 0x84, 0x83, 0x82, 0x81, 0x80, 0x3f, 0x3e, 0x3d, 0x3c, 0x3b, 0x3a, 0x39, 0x38, 0x37, 0x36,+ 0x35, 0x34, 0x33, 0x32, 0x31, 0x30, 0x2f, 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x28, 0x27, 0x26,+ 0x25, 0x24, 0x23, 0x22, 0x21, 0x20, 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, 0x17, 0x16,+ 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07, 0x06,+ 0x05, 0x04, 0x03, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01)++ private val AGC_Z2 = intArrayOf(+ 0x5e, 0x5e, 0x5e, 0x5e, 0x5d, 0x5b, 0x59, 0x57, 0x55, 0x53, 0x51, 0x4f,+ 0x4d, 0x4b, 0x49, 0x47, 0x45, 0x43, 0x41, 0x3f, 0x3d, 0x3b, 0x39, 0x37,+ 0x35, 0x33, 0x31, 0x2f, 0x2d, 0x2b, 0x29, 0x27, 0x25, 0x23, 0x21, 0x1f,+ 0x1d, 0x1b, 0x19, 0x17, 0x15, 0x13, 0x11, 0x0f, 0x0d, 0x0b, 0x09, 0x07,+ 0x05, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,+ 0x01, 0x01, 0x01, 0x01, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19,+ 0x19, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x26, 0x27, 0x27, 0x28,+ 0x28, 0x29, 0x2a, 0x2a, 0x2a, 0x2b, 0x2b, 0x2b, 0x2c, 0x2c, 0x2c, 0x2d,+ 0x2d, 0x2d, 0x2d, 0x2e, 0x2e, 0x2e, 0x2e, 0x2f, 0x2f, 0x2f, 0x30, 0x30,+ 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31,+ 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31)++ private val OFDM_Z2B = intArrayOf(+ 0x10, 0x0d, 0x01, 0x00, 0x14, 0xfb, 0xfb, 0x60, 0x00, 0x60, 0x00, 0x00, 0x00, 0x5c, 0x00, 0x00,+ 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, 0xa8, 0x26, 0x32, 0x33, 0x07, 0xa5, 0x6f, 0x55, 0xc8, 0xb3,+ 0x0a, 0xe1, 0x2C, 0x8a, 0x86, 0x83, 0x34, 0x0f, 0x4f, 0x24, 0x6f, 0xc2, 0x6b, 0x40, 0x80, 0x00,+ 0xc0, 0xc1, 0x58, 0xf1, 0x00, 0xe4, 0x90, 0x3e, 0x6d, 0x3c, 0xfb, 0x07)++ /** rtl8225_gain rows 0..6, 4 bytes each; row 2 (-82 dBm) is the one used. */+ private val GAIN_8225 = intArrayOf(+ 0x23, 0x88, 0x7c, 0xa5, 0x23, 0x88, 0x7c, 0xb5, 0x23, 0x88, 0x7c, 0xc5, 0x33, 0x80, 0x79, 0xc5,+ 0x43, 0x78, 0x76, 0xc5, 0x53, 0x60, 0x73, 0xc5, 0x63, 0x58, 0x70, 0xc5)++ private val OFDM_8225 = arrayOf(+ intArrayOf(0x00, 0x01), intArrayOf(0x01, 0x02), intArrayOf(0x02, 0x42), intArrayOf(0x03, 0x00),+ intArrayOf(0x04, 0x00), intArrayOf(0x05, 0x00), intArrayOf(0x06, 0x40), intArrayOf(0x07, 0x00),+ intArrayOf(0x08, 0x40), intArrayOf(0x09, 0xfe), intArrayOf(0x0a, 0x09), intArrayOf(0x0b, 0x80),+ intArrayOf(0x0c, 0x01), intArrayOf(0x0e, 0xd3), intArrayOf(0x0f, 0x38), intArrayOf(0x10, 0x84),+ intArrayOf(0x11, 0x06), intArrayOf(0x12, 0x20), intArrayOf(0x13, 0x20), intArrayOf(0x14, 0x00),+ intArrayOf(0x15, 0x40), intArrayOf(0x16, 0x00), intArrayOf(0x17, 0x40), intArrayOf(0x18, 0xef),+ intArrayOf(0x19, 0x19), intArrayOf(0x1a, 0x20), intArrayOf(0x1b, 0x76), intArrayOf(0x1c, 0x04),+ intArrayOf(0x1e, 0x95), intArrayOf(0x1f, 0x75), intArrayOf(0x20, 0x1f), intArrayOf(0x21, 0x27),+ intArrayOf(0x22, 0x16), intArrayOf(0x24, 0x46), intArrayOf(0x25, 0x20), intArrayOf(0x26, 0x90),+ intArrayOf(0x27, 0x88))++ private val OFDM_Z2 = arrayOf(+ intArrayOf(0x00, 0x01), intArrayOf(0x01, 0x02), intArrayOf(0x02, 0x42), intArrayOf(0x03, 0x00),+ intArrayOf(0x04, 0x00), intArrayOf(0x05, 0x00), intArrayOf(0x06, 0x40), intArrayOf(0x07, 0x00),+ intArrayOf(0x08, 0x40), intArrayOf(0x09, 0xfe), intArrayOf(0x0a, 0x08), intArrayOf(0x0b, 0x80),+ intArrayOf(0x0c, 0x01), intArrayOf(0x0d, 0x43), intArrayOf(0x0e, 0xd3), intArrayOf(0x0f, 0x38),+ intArrayOf(0x10, 0x84), intArrayOf(0x11, 0x07), intArrayOf(0x12, 0x20), intArrayOf(0x13, 0x20),+ intArrayOf(0x14, 0x00), intArrayOf(0x15, 0x40), intArrayOf(0x16, 0x00), intArrayOf(0x17, 0x40),+ intArrayOf(0x18, 0xef), intArrayOf(0x19, 0x19), intArrayOf(0x1a, 0x20), intArrayOf(0x1b, 0x15),+ intArrayOf(0x1c, 0x04), intArrayOf(0x1d, 0xc5), intArrayOf(0x1e, 0x95), intArrayOf(0x1f, 0x75),+ intArrayOf(0x20, 0x1f), intArrayOf(0x21, 0x17), intArrayOf(0x22, 0x16), intArrayOf(0x23, 0x80),+ intArrayOf(0x24, 0x46), intArrayOf(0x25, 0x00), intArrayOf(0x26, 0x90), intArrayOf(0x27, 0x88))++ private val CCK_8225 = arrayOf(+ intArrayOf(0x00, 0x98), intArrayOf(0x03, 0x20), intArrayOf(0x04, 0x7e), intArrayOf(0x05, 0x12),+ intArrayOf(0x06, 0xfc), intArrayOf(0x07, 0x78), intArrayOf(0x08, 0x2e), intArrayOf(0x10, 0x9b),+ intArrayOf(0x11, 0x88), intArrayOf(0x12, 0x47), intArrayOf(0x13, 0xd0), intArrayOf(0x19, 0x00),+ intArrayOf(0x1a, 0xa0), intArrayOf(0x1b, 0x08), intArrayOf(0x40, 0x86), intArrayOf(0x41, 0x8d),+ intArrayOf(0x42, 0x15), intArrayOf(0x43, 0x18), intArrayOf(0x44, 0x1f), intArrayOf(0x45, 0x1e),+ intArrayOf(0x46, 0x1a), intArrayOf(0x47, 0x15), intArrayOf(0x48, 0x10), intArrayOf(0x49, 0x0a),+ intArrayOf(0x4a, 0x05), intArrayOf(0x4b, 0x02), intArrayOf(0x4c, 0x05))++ private val CCK_Z2 = arrayOf(+ intArrayOf(0x00, 0x98), intArrayOf(0x03, 0x20), intArrayOf(0x04, 0x7e), intArrayOf(0x05, 0x12),+ intArrayOf(0x06, 0xfc), intArrayOf(0x07, 0x78), intArrayOf(0x08, 0x2e), intArrayOf(0x10, 0x9b),+ intArrayOf(0x11, 0x88), intArrayOf(0x12, 0x47), intArrayOf(0x13, 0xd0), intArrayOf(0x19, 0x00),+ intArrayOf(0x1a, 0xa0), intArrayOf(0x1b, 0x08), intArrayOf(0x40, 0x86), intArrayOf(0x41, 0x8d),+ intArrayOf(0x42, 0x15), intArrayOf(0x43, 0x18), intArrayOf(0x44, 0x36), intArrayOf(0x45, 0x35),+ intArrayOf(0x46, 0x2e), intArrayOf(0x47, 0x25), intArrayOf(0x48, 0x1c), intArrayOf(0x49, 0x12),+ intArrayOf(0x4a, 0x09), intArrayOf(0x4b, 0x04), intArrayOf(0x4c, 0x05))++ private val TX_GAIN_8225 = intArrayOf(0x02, 0x06, 0x0e, 0x1e, 0x3e, 0x7e)+ private val TX_OFDM_8225 = intArrayOf(0x80, 0x90, 0xa2, 0xb5, 0xcb, 0xe4)+ private val TX_CCK_8225 = intArrayOf(+ 0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02, 0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02,+ 0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02, 0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02,+ 0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03, 0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03)+ private val TX_CCK_8225_CH14 = intArrayOf(+ 0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00,+ 0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00,+ 0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00, 0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00)+ private val TX_CCK_Z2 = intArrayOf(+ 0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04, 0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03,+ 0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03, 0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03)+ private val TX_CCK_Z2_CH14 = intArrayOf(+ 0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x30, 0x2f, 0x29, 0x15, 0x00, 0x00, 0x00, 0x00,+ 0x30, 0x2f, 0x29, 0x15, 0x00, 0x00, 0x00, 0x00, 0x30, 0x2f, 0x29, 0x15, 0x00, 0x00, 0x00, 0x00)++ /** rtl8187b_reg_table: {register (low byte), value, page}. */+ private val REG_TABLE_B = arrayOf(+ intArrayOf(0xF0, 0x32, 0), intArrayOf(0xF1, 0x32, 0), intArrayOf(0xF2, 0x00, 0), intArrayOf(0xF3, 0x00, 0),+ intArrayOf(0xF4, 0x32, 0), intArrayOf(0xF5, 0x43, 0), intArrayOf(0xF6, 0x00, 0), intArrayOf(0xF7, 0x00, 0),+ intArrayOf(0xF8, 0x46, 0), intArrayOf(0xF9, 0xA4, 0), intArrayOf(0xFA, 0x00, 0), intArrayOf(0xFB, 0x00, 0),+ intArrayOf(0xFC, 0x96, 0), intArrayOf(0xFD, 0xA4, 0), intArrayOf(0xFE, 0x00, 0), intArrayOf(0xFF, 0x00, 0),+ intArrayOf(0x58, 0x4B, 1), intArrayOf(0x59, 0x00, 1), intArrayOf(0x5A, 0x4B, 1), intArrayOf(0x5B, 0x00, 1),+ intArrayOf(0x60, 0x4B, 1), intArrayOf(0x61, 0x09, 1), intArrayOf(0x62, 0x4B, 1), intArrayOf(0x63, 0x09, 1),+ intArrayOf(0xCE, 0x0F, 1), intArrayOf(0xCF, 0x00, 1), intArrayOf(0xF0, 0x4E, 1), intArrayOf(0xF1, 0x01, 1),+ intArrayOf(0xF2, 0x02, 1), intArrayOf(0xF3, 0x03, 1), intArrayOf(0xF4, 0x04, 1), intArrayOf(0xF5, 0x05, 1),+ intArrayOf(0xF6, 0x06, 1), intArrayOf(0xF7, 0x07, 1), intArrayOf(0xF8, 0x08, 1),+ intArrayOf(0x4E, 0x00, 2), intArrayOf(0x0C, 0x04, 2), intArrayOf(0x21, 0x61, 2), intArrayOf(0x22, 0x68, 2),+ intArrayOf(0x23, 0x6F, 2), intArrayOf(0x24, 0x76, 2), intArrayOf(0x25, 0x7D, 2), intArrayOf(0x26, 0x84, 2),+ intArrayOf(0x27, 0x8D, 2), intArrayOf(0x4D, 0x08, 2), intArrayOf(0x50, 0x05, 2), intArrayOf(0x51, 0xF5, 2),+ intArrayOf(0x52, 0x04, 2), intArrayOf(0x53, 0xA0, 2), intArrayOf(0x54, 0x1F, 2), intArrayOf(0x55, 0x23, 2),+ intArrayOf(0x56, 0x45, 2), intArrayOf(0x57, 0x67, 2), intArrayOf(0x58, 0x08, 2), intArrayOf(0x59, 0x08, 2),+ intArrayOf(0x5A, 0x08, 2), intArrayOf(0x5B, 0x08, 2), intArrayOf(0x60, 0x08, 2), intArrayOf(0x61, 0x08, 2),+ intArrayOf(0x62, 0x08, 2), intArrayOf(0x63, 0x08, 2), intArrayOf(0x64, 0xCF, 2),+ intArrayOf(0x5B, 0x40, 0), intArrayOf(0x84, 0x88, 0), intArrayOf(0x85, 0x24, 0), intArrayOf(0x88, 0x54, 0),+ intArrayOf(0x8B, 0xB8, 0), intArrayOf(0x8C, 0x07, 0), intArrayOf(0x8D, 0x00, 0), intArrayOf(0x94, 0x1B, 0),+ intArrayOf(0x95, 0x12, 0), intArrayOf(0x96, 0x00, 0), intArrayOf(0x97, 0x06, 0), intArrayOf(0x9D, 0x1A, 0),+ intArrayOf(0x9F, 0x10, 0), intArrayOf(0xB4, 0x22, 0), intArrayOf(0xBE, 0x80, 0), intArrayOf(0xDB, 0x00, 0),+ intArrayOf(0xEE, 0x00, 0), intArrayOf(0x4C, 0x00, 2),+ intArrayOf(0x9F, 0x00, 3), intArrayOf(0x8C, 0x01, 0), intArrayOf(0x8D, 0x10, 0), intArrayOf(0x8E, 0x08, 0),+ intArrayOf(0x8F, 0x00, 0))+}diff --git a/app/src/main/java/com/rfsentinel/app/usb/Rtl8814auMonitor.kt b/app/src/main/java/com/rfsentinel/app/usb/Rtl8814auMonitor.ktnew file mode 100644index 0000000..3926fc0--- /dev/null+++ b/app/src/main/java/com/rfsentinel/app/usb/Rtl8814auMonitor.kt@@ -0,0 +1,302 @@+package com.rfsentinel.app.usb++/*+ * Receive-only monitor mode for Realtek RTL8814AU USB WiFi adapters (e.g. ALFA+ * AWUS1900), 2.4 + 5 GHz, driven from userspace over Android's USB host API - no+ * root, no kernel driver, no firmware. Hops 2.4 GHz and the 5 GHz UNII-1 / UNII-3+ * channels and reports the access points and client devices it hears. It never+ * transmits.+ *+ * Ported from Wardrive Go by RocketGod (https://github.com/RocketGod-git/wardrive-go,+ * GPL-3.0), with its register tables (Rtl8814auTables.kt) from Realtek's 8814au driver.+ * Its handshake / PMKID capture was removed; frames with a bad checksum are dropped.+ * Used under the GNU GPL v3.+ */++import android.content.Context+import android.hardware.usb.UsbDevice+import android.hardware.usb.UsbDeviceConnection+import android.hardware.usb.UsbManager++object Rtl8814auMonitor {+ @Volatile var running = false; private set+ @Volatile private var stop = false++ private val frames = MonitorFrames()+ private val HOP = intArrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 36, 40, 44, 48, 149, 153, 157, 161, 165)+ private const val DWELL_MS = 125L+ private val FRESH_MS get() = (HOP.size * DWELL_MS * 9 / 5).coerceAtLeast(3000L)+ private const val REPORT_MS = 10_000L+ private const val RXDESC_SIZE = 24+ private const val FCS_LEN = 4++ private const val OUT_VENDOR = 0x40; private const val IN_VENDOR = 0xC0; private const val VREQ = 0x05+ private const val REG_RX_DRVINFO_SZ = 0x060F+ private val RF_BASE = intArrayOf(0x2800, 0x2c00, 0x3800, 0x3c00)++ private lateinit var conn: UsbDeviceConnection+ private var curBand5g = false+ @Volatile private var ctlErrors = 0++ fun abort() { stop = true }++ fun run(ctx: Context, device: UsbDevice, chipName: String, onStatus: (String) -> Unit,+ onFrame: (List<MonitorSighting>) -> Unit) {+ if (running) return+ running = true; stop = false; frames.clear(); ctlErrors = 0+ val mgr = ctx.getSystemService(Context.USB_SERVICE) as UsbManager+ val c = mgr.openDevice(device) ?: run { onStatus("$chipName: couldn't reopen adapter"); running = false; return }+ conn = c+ try {+ val intf = device.getInterface(0)+ if (!c.claimInterface(intf, true)) UsbWifi.log("RTL8814AU: couldn't claim the USB interface (continuing)")+ val rx = BulkRx.inEndpoint(intf, 0x81)+ ?: run { UsbWifi.log("RTL8814AU: no bulk-IN endpoint"); onStatus("$chipName: no RX endpoint"); return }+ UsbWifi.log("=== RTL8814AU bring-up (8814au) ===")+ val t0 = System.currentTimeMillis()++ onStatus("$chipName · powering on…")+ resetMac()+ val powered = powerOn()+ w16(Rtl8814auTables.REG_CR, 0x0000)+ w16(Rtl8814auTables.REG_CR, Rtl8814auTables.CR_INIT16)+ val cr = r16(Rtl8814auTables.REG_CR)+ UsbWifi.log("RTL8814AU: power-on %s, REG_CR 0x%04x, RX EP 0x%02x".format(if (powered) "ok" else "poll timed out", cr, rx.address))+ if (cr == 0xEAEA) { onStatus("$chipName: MAC didn't power on (replug)"); return }+ initLlt(); initRqpn()++ onStatus("$chipName · loading MAC / BB / RF…")+ for (e in Rtl8814auTables.MAC_REG) if (e[0] == Rtl8814auTables.DELAY) sleep(e[1]) else w8(e[0], e[1] and 0xff)+ w8(0x02, r8(0x02) or 0x04)+ w8(0x1002, r8(0x1002) or 0x03)+ w8(0x1F, 0x07); w16(0x20, 0x0707); w8(0x76, 0x07)+ sleep(1)+ for (e in Rtl8814auTables.PHY_REG) if (e[0] == Rtl8814auTables.DELAY) sleep(e[1]) else w32(e[0], e[1])+ for (e in Rtl8814auTables.AGC_TAB) if (e[0] == Rtl8814auTables.DELAY) sleep(e[1]) else w32(e[0], e[1])+ for ((path, tab) in listOf(Rtl8814auTables.RADIOA, Rtl8814auTables.RADIOB, Rtl8814auTables.RADIOC, Rtl8814auTables.RADIOD).withIndex())+ for (e in tab) if (e[0] == Rtl8814auTables.DELAY) sleep(e[1]) else rfWrite(path, e[0], e[1])+ w32(0x1000, r32(0x1000) or 0x10000)++ w16(Rtl8814auTables.REG_RXFF_BNDY, Rtl8814auTables.RX_DMA_BOUNDARY)+ w8(0x10C, r8(0x10C) or 0x01)+ w8(REG_RX_DRVINFO_SZ, 0x04)+ w32(Rtl8814auTables.REG_RCR, Rtl8814auTables.RCR_MONITOR)+ w16(Rtl8814auTables.REG_RXFLTMAP0, Rtl8814auTables.RXFLTMAP_ALL)+ w16(Rtl8814auTables.REG_RXFLTMAP1, Rtl8814auTables.RXFLTMAP_ALL)+ w16(Rtl8814auTables.REG_RXFLTMAP2, Rtl8814auTables.RXFLTMAP_ALL)+ w16(Rtl8814auTables.REG_CR, r16(Rtl8814auTables.REG_CR) or Rtl8814auTables.CR_MACEN)++ curBand5g = HOP[0] > 14+ switchBand(curBand5g)+ tune(HOP[0])+ UsbWifi.log("RTL8814AU: started in %d ms - RCR 0x%08x BB(0x800) 0x%08x CR 0x%04x, RF18 %05x %05x %05x %05x, USB errors %d - monitor live ch %d".format(+ System.currentTimeMillis() - t0, r32(Rtl8814auTables.REG_RCR), r32(0x800), r16(Rtl8814auTables.REG_CR),+ rfRead(0, 0x18), rfRead(1, 0x18), rfRead(2, 0x18), rfRead(3, 0x18), ctlErrors, HOP[0]))+ onStatus("$chipName · live · 2.4 + 5 GHz monitor")+ rxLoop(chipName, rx, onFrame, onStatus)+ } catch (e: Exception) {+ UsbWifi.log("RTL8814AU: bring-up error - ${UsbWifi.describe(e)}")+ onStatus("$chipName: error · ${e.message}")+ } finally {+ runCatching { c.close() }+ running = false+ }+ }++ // ---- bring-up ----++ private fun resetMac() {+ w8(0x05, r8(0x05) or 0x02)+ val end = System.currentTimeMillis() + 100+ while ((r8(0x05) and 0x02) != 0 && System.currentTimeMillis() < end) sleep(1)+ }++ private fun powerOn(): Boolean {+ w8(0x10C2, r8(0x10C2) or 0x02)+ wmask8(0x05, 0x04, 0x00); val a = poll8(0x06, 0x02, 0x02)+ wmask8(0x05, 0x08, 0x00); wmask8(0xF0, 0x80, 0x00)+ wmask8(0x81, 0x30, 0x20); wmask8(0x05, 0x01, 0x01); val b = poll8(0x05, 0x01, 0x00)+ return a && b+ }++ private fun initLlt() {+ w8(Rtl8814auTables.REG_AUTO_LLT, r8(Rtl8814auTables.REG_AUTO_LLT) or 0x01)+ val end = System.currentTimeMillis() + 2000+ while ((r8(Rtl8814auTables.REG_AUTO_LLT) and 0x01) != 0 && System.currentTimeMillis() < end) sleep(2)+ if ((r8(Rtl8814auTables.REG_AUTO_LLT) and 0x01) != 0) UsbWifi.log("RTL8814AU: LLT init timed out (continuing)")+ }++ private fun initRqpn() {+ val txpkt = 2048 - 8; val pub = txpkt - 0x20 * 4+ for (a in intArrayOf(0x230, 0x234, 0x238, 0x23C)) w32(a, 0x20)+ w32(0x240, pub); w32(0x22C, 0x80000000.toInt())+ for (a in intArrayOf(0x424, 0x456, 0x47A, 0x204, 0x206)) w16(a, txpkt and 0xffff)+ }++ private fun setRfe(band5g: Boolean) {+ if (band5g) {+ w32(0xCB0, 0x37173717); w32(0xEB0, 0x37173717); w32(0x18B4, 0x37173717)+ w32(0x1AB4, 0x77177717); bbMask(0x1ABC, 0x0ff00000, 0x37)+ } else {+ w32(0xCB0, 0x54775477); w32(0xEB0, 0x54775477); w32(0x18B4, 0x54775477)+ w32(0x1AB4, 0x54775477); bbMask(0x1ABC, 0x0ff00000, 0x54)+ }+ }++ private fun switchBand(band5g: Boolean) {+ w8(0x1002, r8(0x1002) and 0x01.inv())+ if (band5g) {+ w8(0x454, 0x80)+ bbMask(0xa80, 1 shl 18, 0x1)+ setRfe(true)+ bbMask(0x80c, 0xf0, 0x0)+ bbMask(0xa04, 0x0f000000, 0xF)+ bbMask(0x808, 0x30000000, 0x2)+ } else {+ bbMask(0x958, 0x1F, 0x0)+ setRfe(false)+ bbMask(0x80c, 0xf0, 0x2)+ bbMask(0xa04, 0x0f000000, 0x5)+ bbMask(0x808, 0x30000000, 0x3)+ w8(0x454, 0x00)+ bbMask(0xa80, 1 shl 18, 0x0)+ }+ w8(0x1002, r8(0x1002) or 0x01)+ }++ private fun tune(ch: Int) {+ val band5g = ch > 14+ if (band5g != curBand5g) { switchBand(band5g); curBand5g = band5g }+ val fc = when {+ ch in 36..48 -> 0x494; ch in 50..64 -> 0x453+ ch in 100..116 -> 0x452; ch >= 118 && band5g -> 0x412+ else -> 0x96a+ }+ bbMask(0x860, 0x1ffe0000, fc)+ val rfMod = when { ch in 36..64 -> 0x101; ch in 100..140 -> 0x301; ch > 140 -> 0x501; else -> 0x000 }+ val rfVal = (ch and 0xff) or (rfMod shl 8)+ val mask = (1 shl 18) or (1 shl 17) or (1 shl 16) or (1 shl 9) or (1 shl 8) or 0xff+ for (p in 0 until 4) rfMask(p, 0x18, mask, rfVal)+ if (band5g) bbMask(0x958, 0x1F, when { ch in 36..64 -> 1; ch in 100..144 -> 2; else -> 3 })+ when (ch) {+ in 1..11 -> { w32(0xa20, 0x1a1b0030); w32(0xa24, 0x090e1317); w32(0xa28, 0x00000204) }+ in 12..13 -> { w32(0xa20, 0x1a1b0030); w32(0xa24, 0x090e1217); w32(0xa28, 0x00000305) }+ }+ }++ // ---- receive ----++ private class RxState { var hopAt = 0L; var lastEmit = 0L; var hopIdx = 0 }++ private fun rxLoop(chipName: String, ep: android.hardware.usb.UsbEndpoint,+ onFrame: (List<MonitorSighting>) -> Unit, onStatus: (String) -> Unit) {+ val st = RxState()+ val t0 = System.currentTimeMillis(); st.hopAt = t0; st.lastEmit = t0+ val stats = BulkRx.Stats("RTL8814AU")+ val total = BulkRx.run("RTL8814AU", conn, ep, 24, 16384, { stop }, { b, n ->+ stats.transfer(n)+ stats.sample("$n bytes, first RX descriptor", b, 0, RXDESC_SIZE)+ forEachFrame(b, n, onBad = { crc -> if (crc) stats.badChecksum++ else stats.malformed++ }) { s, e, rssi ->+ stats.frame(rssi)+ frames.frame(b, s, e, HOP[st.hopIdx], rssi)+ }+ }) { now ->+ stats.maybeLog(now) {+ val (aps, clients) = frames.live(now, REPORT_MS)+ "ch ${HOP[st.hopIdx]}, $aps access points, $clients devices, USB errors $ctlErrors"+ }+ if (now - st.lastEmit > 2000) { emit(onFrame); st.lastEmit = now }+ if (now - st.hopAt > DWELL_MS) {+ st.hopIdx = (st.hopIdx + 1) % HOP.size+ runCatching { tune(HOP[st.hopIdx]) }+ val (aps, clients) = frames.live(now, REPORT_MS)+ onStatus("$chipName · live · $aps access points · $clients devices · ch ${HOP[st.hopIdx]}")+ st.hopAt = now+ }+ }+ emit(onFrame)+ UsbWifi.log("RTL8814AU: RX loop stopped ($total B)")+ }++ private fun emit(onFrame: (List<MonitorSighting>) -> Unit) {+ val batch = frames.drain(System.currentTimeMillis(), FRESH_MS)+ if (batch.isNotEmpty()) onFrame(batch)+ }++ /**+ * Frames in one bulk transfer, each | RX descriptor (24) | PHY status | shift | frame + FCS |,+ * padded to 8 bytes. [onFrame] gets the 802.11 frame's [start, end) without the FCS and its+ * signal (null without a PHY status); [onBad] hears about skipped ones (true: bad checksum).+ */+ internal fun forEachFrame(b: ByteArray, n: Int, onBad: (Boolean) -> Unit = {}, onFrame: (Int, Int, Int?) -> Unit) {+ var off = 0+ while (off + RXDESC_SIZE <= n) {+ val d0 = le32(b, off)+ val pkt = d0 and 0x3fff+ if (pkt == 0 || pkt > 12000) { if (off == 0) onBad(false); break }+ val crc = (d0 ushr 14) and 1+ val drv = ((d0 ushr 16) and 0xf) * 8+ val shift = (d0 ushr 24) and 3+ val fs = off + RXDESC_SIZE + drv + shift+ val fe = fs + pkt - FCS_LEN+ when {+ crc != 0 -> onBad(true)+ pkt < 24 + FCS_LEN || fe > n -> onBad(false)+ else -> {+ val rate = b[off + 12].toInt() and 0x7f+ val rssi = if (drv >= 8) rtlRssi(b, off + RXDESC_SIZE, rate) else null+ onFrame(fs, fe, rssi)+ }+ }+ off += (RXDESC_SIZE + drv + shift + pkt + 7) and 7.inv()+ }+ }++ /** Signal from the PHY status: CCK (rates 0-3) from the LNA / VGA gain, OFDM from the power report. */+ private fun rtlRssi(b: ByteArray, di: Int, rate: Int): Int {+ fun u8(i: Int) = b[i].toInt() and 0xff+ return if (rate <= 3) {+ val agc = u8(di + 5); val lna = (agc and 0xE0) shr 5; val vga = agc and 0x1F+ when (lna) {+ 7 -> if (vga <= 27) -94 + 2 * (27 - vga) else -94+ 6 -> -42 + 2 * (2 - vga); 5 -> -36 + 2 * (7 - vga); 4 -> -30 + 2 * (7 - vga)+ 3 -> -18 + 2 * (7 - vga); 2 -> 2 * (5 - vga); 1 -> 14 - 2 * vga; else -> 20 - 2 * vga+ }+ } else ((u8(di + 4) shr 1) and 0x7f) - 110+ }++ // ---- register access ----++ private fun r(addr: Int, len: Int): ByteArray {+ val b = ByteArray(len)+ if (conn.controlTransfer(IN_VENDOR, VREQ, addr, 0, b, len, 500) != len) { ctlErrors++; return ByteArray(len) }+ return b+ }+ private fun w(addr: Int, data: ByteArray) {+ if (conn.controlTransfer(OUT_VENDOR, VREQ, addr, 0, data, data.size, 500) < 0) ctlErrors+++ }+ private fun r8(a: Int) = r(a, 1)[0].toInt() and 0xff+ private fun r16(a: Int): Int { val b = r(a, 2); return (b[0].toInt() and 0xff) or ((b[1].toInt() and 0xff) shl 8) }+ private fun r32(a: Int) = le32(r(a, 4), 0)+ private fun w8(a: Int, v: Int) = w(a, byteArrayOf(v.toByte()))+ private fun w16(a: Int, v: Int) = w(a, byteArrayOf(v.toByte(), (v ushr 8).toByte()))+ private fun w32(a: Int, v: Int) = w(a, byteArrayOf(v.toByte(), (v ushr 8).toByte(), (v ushr 16).toByte(), (v ushr 24).toByte()))+ private fun wmask8(a: Int, msk: Int, v: Int) { val cur = r8(a); w8(a, (cur and msk.inv()) or (v and msk)) }+ private fun poll8(a: Int, msk: Int, v: Int): Boolean {+ val end = System.currentTimeMillis() + 500+ while (System.currentTimeMillis() < end) { if ((r8(a) and msk) == (v and msk)) return true; sleep(1) }+ return false+ }+ private fun bbMask(a: Int, mask: Int, v: Int) { val cur = r32(a); w32(a, (cur and mask.inv()) or ((v shl sh(mask)) and mask)) }++ private fun rfWrite(path: Int, reg: Int, v: Int) = w32(Rtl8814auTables.LSSI[path], (((reg and 0xff) shl 20) or (v and 0xfffff)) and 0x0fffffff)+ private fun rfRead(path: Int, reg: Int) = r32(RF_BASE[path] + (reg and 0xff) * 4) and 0xfffff+ private fun rfMask(path: Int, reg: Int, mask: Int, v: Int) {+ val cur = rfRead(path, reg); rfWrite(path, reg, (cur and mask.inv()) or ((v shl sh(mask)) and mask))+ }++ private fun sh(mask: Int) = Integer.numberOfTrailingZeros(mask)+ private fun le32(b: ByteArray, i: Int) = (b[i].toInt() and 0xff) or ((b[i + 1].toInt() and 0xff) shl 8) or+ ((b[i + 2].toInt() and 0xff) shl 16) or ((b[i + 3].toInt() and 0xff) shl 24)+ private fun sleep(ms: Int) = try { Thread.sleep(ms.toLong()) } catch (_: InterruptedException) {}+}diff --git a/app/src/main/java/com/rfsentinel/app/usb/Rtl8814auTables.kt b/app/src/main/java/com/rfsentinel/app/usb/Rtl8814auTables.ktnew file mode 100644index 0000000..95a2ac4--- /dev/null+++ b/app/src/main/java/com/rfsentinel/app/usb/Rtl8814auTables.kt@@ -0,0 +1,39 @@+package com.rfsentinel.app.usb++object Rtl8814auTables {+ const val DELAY = -2++ const val REG_CR = 0x0100; const val CR_INIT16 = 0x063F; const val CR_MACEN = 0x00C0+ const val REG_RXFF_BNDY = 0x011C; const val RX_DMA_BOUNDARY = 0x5BFF+ const val REG_RCR = 0x0608; val RCR_MONITOR = 0x90003B2F.toInt()+ const val REG_RXFLTMAP0 = 0x06A0; const val REG_RXFLTMAP1 = 0x06A2; const val REG_RXFLTMAP2 = 0x06A4+ const val RXFLTMAP_ALL = 0xFFFF+ const val REG_AUTO_LLT = 0x0208++ val LSSI = intArrayOf(0xC90, 0xE90, 0x1890, 0x1A90)++ private fun parse(s: String): Array<IntArray> {+ if (s.isEmpty()) return emptyArray()+ return s.split(';').map { e ->+ val c = e.split(',')+ if (c[0] == "d") intArrayOf(DELAY, c[1].toInt(16))+ else intArrayOf(c[0].toInt(16), c[1].toLong(16).toInt())+ }.toTypedArray()+ }++ val MAC_REG: Array<IntArray> by lazy { parse(S_MAC) }+ val PHY_REG: Array<IntArray> by lazy { parse(S_BB) }+ val AGC_TAB: Array<IntArray> by lazy { parse(S_AGC) }+ val RADIOA: Array<IntArray> by lazy { parse(S_RFA) }+ val RADIOB: Array<IntArray> by lazy { parse(S_RFB) }+ val RADIOC: Array<IntArray> by lazy { parse(S_RFC) }+ val RADIOD: Array<IntArray> by lazy { parse(S_RFD) }++ private const val S_MAC = "10,7c;14,db;16,2;73,10;420,80;421,f;428,a;429,10;430,0;431,0;432,0;433,1;434,4;435,5;436,7;437,8;43c,4;43d,5;43e,7;43f,8;440,5d;441,1;442,0;444,10;445,f0;446,1;447,fe;448,0;449,0;44a,0;44b,40;44c,10;44d,f0;44e,3f;44f,0;450,0;451,0;452,0;453,40;45e,4;49c,10;49d,f0;49e,0;49f,6;4a0,e0;4a1,3;4a2,0;4a3,40;4a4,15;4a5,f0;4a6,0;4a7,6;4a8,e0;4a9,0;4aa,0;4ab,0;7da,8;1448,6;144a,6;144c,6;144e,6;4c8,ff;4c9,8;4ca,3c;4cb,3c;4cc,ff;4cd,ff;4ce,1;4cf,8;500,26;501,a2;502,2f;503,0;504,28;505,a3;506,5e;507,0;508,2b;509,a4;50a,5e;50b,0;50c,4f;50d,a4;50e,0;50f,0;512,1c;514,a;516,a;521,2f;525,47;550,10;551,10;559,2;55c,64;55d,ff;577,3;5be,64;604,1;605,30;607,1;608,e;609,2a;60a,0;60c,18;60d,50;6a0,ff;6a1,ff;6a2,ff;6a3,ff;6a4,ff;6a5,ff;6de,84;620,ff;621,ff;622,ff;623,ff;624,ff;625,ff;626,ff;627,ff;638,64;63c,a;63d,a;63e,e;63f,e;640,40;642,40;643,0;652,c8;66e,5;700,21;701,43;702,65;703,87;708,21;709,43;70a,65;70b,87;718,40;7d5,bc;7d8,28;7d9,0;7da,b"+ private const val S_BB = "800,9020d010;804,8011280;808,e0282ff;80c,1000002f;810,33303265;814,20c3d10;818,4a10385;820,0;824,33e40;828,0;82c,73985170;830,79a0ea08;834,42e708a;838,86667640;83c,9798b9b9;840,17578f60;844,4bbdfcde;848,5cd07f8b;84c,6cfbf7b5;850,28834706;854,1520c;858,4060c000;85c,74210368;860,6929c321;864,79727432;868,8ca7a314;86c,438c2878;870,44444444;874,21612c2e;878,3152;87c,fc000;8a0,13;8a4,7f7f7f7f;8a8,a202033e;8ac,f40f550a;8b0,600;8b4,fc080;8b8,ec0057ff;8bc,8ca520c3;8c0,3ff00020;8c4,44c00000;8c8,80025167;8cc,8250492;8d0,b800;8d4,940008a0;8d8,290b5612;8dc,0;8e0,32316407;8e4,4a092925;8e8,ffffc42c;8ec,99999999;8f0,9999;8f4,f80fa1;8f8,400082c0;8fc,0;900,400700;90c,9004000;910,fc00;914,d6400404;918,1c1028c0;91c,64b11a1c;920,e0767233;924,55aa500;928,4ab0e4e4;92c,fffe0000;930,fffffffe;934,1fffff;938,8400;93c,932c0642;940,93e9360;944,8000000;948,4000000;950,2010080;954,86510080;960,0;964,0;968,0;96c,0;970,801fffff;978,0;97c,0;980,0;984,0;988,0;98c,3440000;990,27100000;994,ffff0100;998,ffffff5c;99c,ffffffff;9a0,ff;9a4,80080;9a8,c2f0000;9ac,560000;9b0,81081008;9b4,0;9b8,1081008;9bc,1081008;9d0,0;9d4,0;9d8,0;9dc,0;9e4,2;9e8,22d5;9fc,effff7ff;b00,e3100000;b04,b000;b0c,31eaa006;b5c,41cfffff;c00,7;c04,42020;c08,80410231;c0c,0;c10,100;c14,1000000;c1c,40000053;c50,20;c54,0;c58,3c020c14;c5c,d000058;c60,1b800000;c60,b800001;c60,5800002;c60,7800003;c60,1a800004;c60,b800005;c60,5800006;c60,e800007;c60,1a800008;c60,b800009;c60,1580000a;c60,880000b;c60,1a80000c;c60,b80000d;c60,580000e;c60,e80000f;c60,1a800010;c60,b800011;c60,15800012;c60,8800013;c60,1a800014;c60,b800015;c60,5800016;c60,7800017;c60,1a800018;c60,b800019;c60,1580001a;c60,880001b;c60,1b80001c;c60,b80001d;c60,580001e;c60,780001f;c60,1b800020;c60,b800021;c60,5800022;c60,7800023;c60,1b800024;c60,b800025;c60,5800026;c60,7800027;c60,1b800028;c60,b800029;c60,580002a;c60,780002b;c60,1b800030;c60,b800031;c60,5800032;c60,800033;c60,1b800034;c60,b800035;c60,5800036;c60,800037;c60,1b800038;c60,b800039;c60,580003a;c60,e80803b;c94,1000401;c98,188000;ca0,2929;ca4,8040201;ca8,80402010;cac,77777000;cb0,54775477;cb4,54775477;cb8,500000;cbc,77700000;cc0,10;cc8,10;e00,7;e04,42020;e08,80410231;e0c,0;e10,100;e14,1000000;e1c,40000053;e50,20;e54,0;e58,3c020c14;e5c,d000058;e60,1b800000;e60,b800001;e60,5800002;e60,7800003;e60,1a800004;e60,b800005;e60,5800006;e60,e800007;e60,1a800008;e60,b800009;e60,1580000a;e60,880000b;e60,1a80000c;e60,b80000d;e60,580000e;e60,e80000f;e60,1a800010;e60,b800011;e60,15800012;e60,8800013;e60,1a800014;e60,b800015;e60,5800016;e60,7800017;e60,1a800018;e60,b800019;e60,1580001a;e60,880001b;e60,1b80001c;e60,b80001d;e60,580001e;e60,780001f;e60,1b800020;e60,b800021;e60,5800022;e60,7800023;e60,1b800024;e60,b800025;e60,5800026;e60,7800027;e60,1b800028;e60,b800029;e60,580002a;e60,780002b;e60,1b800030;e60,b800031;e60,5800032;e60,800033;e60,1b800034;e60,b800035;e60,5800036;e60,800037;e60,1b800038;e60,b800039;e60,580003a;e60,e80803b;e94,1000401;e98,188000;ea0,2929;ea4,8040201;ea8,80402010;eac,77777000;eb0,54775477;eb4,54775477;eb8,500000;ebc,77700000;1800,7;1804,42020;1808,80410231;180c,0;1810,100;1814,1000000;181c,40000053;1850,20;1854,0;1858,3c020c14;185c,d000058;1860,1b800000;1860,b800001;1860,5800002;1860,7800003;1860,1a800004;1860,b800005;1860,5800006;1860,e800007;1860,1a800008;1860,b800009;1860,1580000a;1860,880000b;1860,1a80000c;1860,b80000d;1860,580000e;1860,e80000f;1860,1a800010;1860,b800011;1860,15800012;1860,8800013;1860,1a800014;1860,b800015;1860,5800016;1860,7800017;1860,1a800018;1860,b800019;1860,1580001a;1860,880001b;1860,1b80001c;1860,b80001d;1860,580001e;1860,780001f;1860,1b800020;1860,b800021;1860,5800022;1860,7800023;1860,1b800024;1860,b800025;1860,5800026;1860,7800027;1860,1b800028;1860,b800029;1860,580002a;1860,780002b;1860,1b800030;1860,b800031;1860,5800032;1860,800033;1860,1b800034;1860,b800035;1860,5800036;1860,800037;1860,1b800038;1860,b800039;1860,580003a;1860,e80803b;1894,1000401;1898,188000;18a0,2929;18a4,8040201;18a8,80402010;18ac,77777000;18b0,54775477;18b4,54775477;18b8,500000;18bc,77700000;1a00,7;1a04,42020;1a08,80410231;1a0c,0;1a10,100;1a14,1000000;1a1c,40000053;1a50,20;1a54,0;1a58,3c020c14;1a5c,d000058;1a60,1b800000;1a60,b800001;1a60,5800002;1a60,7800003;1a60,1a800004;1a60,b800005;1a60,5800006;1a60,e800007;1a60,1a800008;1a60,b800009;1a60,1580000a;1a60,880000b;1a60,1a80000c;1a60,b80000d;1a60,580000e;1a60,e80000f;1a60,1a800010;1a60,b800011;1a60,15800012;1a60,8800013;1a60,1a800014;1a60,b800015;1a60,5800016;1a60,7800017;1a60,1a800018;1a60,b800019;1a60,1580001a;1a60,880001b;1a60,1b80001c;1a60,b80001d;1a60,580001e;1a60,780001f;1a60,1b800020;1a60,b800021;1a60,5800022;1a60,7800023;1a60,1b800024;1a60,b800025;1a60,5800026;1a60,7800027;1a60,1b800028;1a60,b800029;1a60,580002a;1a60,780002b;1a60,1b800030;1a60,b800031;1a60,5800032;1a60,800033;1a60,1b800034;1a60,b800035;1a60,5800036;1a60,800037;1a60,1b800038;1a60,b800039;1a60,580003a;1a60,e80803b;1a94,1000401;1a98,188000;1aa0,2929;1aa4,8040201;1aa8,80402010;1aac,77777000;1ab0,54775477;1ab4,54775477;1ab8,500000;1abc,77700000;1904,30000;1914,30000;1984,3000000;1988,87;198c,7;1990,ffaa5500;1994,77;1998,12801000;1998,12801000;1998,12801001;1998,12801002;1998,12801003;1998,12801004;1998,12801005;1998,12801006;1998,12801007;1998,12801008;1998,12801009;1998,1280100a;1998,1280100b;1998,1280100c;1998,1280100d;1998,1280100e;1998,1280100f;1998,12801010;1998,12801011;1998,12801012;1998,12801013;1998,12801014;1998,12801015;1998,12801016;1998,12801017;1998,12801018;1998,12801019;1998,1280101a;1998,1280101b;1998,1280101c;1998,1280101d;1998,1280101e;1998,1280101f;1998,12801020;1998,12801021;1998,12801022;1998,12801023;1998,1280102c;1998,1280102d;1998,1280102e;1998,1280102f;1998,12801030;1998,12801031;1998,12801032;1998,12801033;1998,12801034;1998,12801035;1998,12801036;1998,12801037;1998,12801038;1998,12801039;1998,1280103a;1998,1280103b;1998,1280103c;1998,1280103d;1998,1280103e;1998,1280103f;1998,12801040;1998,12801041;1998,12801042;1998,12801043;1998,12801044;1998,12801045;1998,12801046;1998,12801047;1998,12801048;1998,12801049;1998,12801100;1998,12801101;1998,12801102;1998,12801103;1998,12801104;1998,12801105;1998,12801106;1998,12801107;1998,12801108;1998,12801109;1998,1280110a;1998,1280110b;1998,1280110c;1998,1280110d;1998,1280110e;1998,1280110f;1998,12801110;1998,12801111;1998,12801112;1998,12801113;1998,12801114;1998,12801115;1998,12801116;1998,12801117;1998,12801118;1998,12801119;1998,1280111a;1998,1280111b;1998,1280111c;1998,1280111d;1998,1280111e;1998,1280111f;1998,12801120;1998,12801121;1998,12801122;1998,12801123;1998,1280112c;1998,1280112d;1998,1280112e;1998,1280112f;1998,12801130;1998,12801131;1998,12801132;1998,12801133;1998,12801134;1998,12801135;1998,12801136;1998,12801137;1998,12801138;1998,12801139;1998,1280113a;1998,1280113b;1998,1280113c;1998,1280113d;1998,1280113e;1998,1280113f;1998,12801140;1998,12801141;1998,12801142;1998,12801143;1998,12801144;1998,12801145;1998,12801146;1998,12801147;1998,12801148;1998,12801149;1998,12801200;1998,12801201;1998,12801202;1998,12801203;1998,12801204;1998,12801205;1998,12801206;1998,12801207;1998,12801208;1998,12801209;1998,1280120a;1998,1280120b;1998,1280120c;1998,1280120d;1998,1280120e;1998,1280120f;1998,12801210;1998,12801211;1998,12801212;1998,12801213;1998,12801214;1998,12801215;1998,12801216;1998,12801217;1998,12801218;1998,12801219;1998,1280121a;1998,1280121b;1998,1280121c;1998,1280121d;1998,1280121e;1998,1280121f;1998,12801220;1998,12801221;1998,12801222;1998,12801223;1998,1280122c;1998,1280122d;1998,1280122e;1998,1280122f;1998,12801230;1998,12801231;1998,12801232;1998,12801233;1998,12801234;1998,12801235;1998,12801236;1998,12801237;1998,12801238;1998,12801239;1998,1280123a;1998,1280123b;1998,1280123c;1998,1280123d;1998,1280123e;1998,1280123f;1998,12801240;1998,12801241;1998,12801242;1998,12801243;1998,12801244;1998,12801245;1998,12801246;1998,12801247;1998,12801248;1998,12801249;1998,12801300;1998,12801301;1998,12801302;1998,12801303;1998,12801304;1998,12801305;1998,12801306;1998,12801307;1998,12801308;1998,12801309;1998,1280130a;1998,1280130b;1998,1280130c;1998,1280130d;1998,1280130e;1998,1280130f;1998,12801310;1998,12801311;1998,12801312;1998,12801313;1998,12801314;1998,12801315;1998,12801316;1998,12801317;1998,12801318;1998,12801319;1998,1280131a;1998,1280131b;1998,1280131c;1998,1280131d;1998,1280131e;1998,1280131f;1998,12801320;1998,12801321;1998,12801322;1998,12801323;1998,1280132c;1998,1280132d;1998,1280132e;1998,1280132f;1998,12801330;1998,12801331;1998,12801332;1998,12801333;1998,12801334;1998,12801335;1998,12801336;1998,12801337;1998,12801338;1998,12801339;1998,1280133a;1998,1280133b;1998,1280133c;1998,1280133d;1998,1280133e;1998,1280133f;1998,12801340;1998,12801341;1998,12801342;1998,12801343;1998,12801344;1998,12801345;1998,12801346;1998,12801347;1998,12801348;1998,12801349;19d4,88888888;19d8,888;b00,e3100100;b00,e7100100;c60,15808002;c60,1808003;e60,15808002;e60,1808003;1860,15808002;1860,1808003;1a60,15808002;1a60,1808003;b00,e3100100;c5c,d080058;e5c,d080058;185c,d080058;1a5c,d080058;c5c,d000058;e5c,d000058;185c,d000058;1a5c,d000058;c60,5808002;c60,e808003;e60,5808002;e60,e808003;1860,5808002;1860,e808003;1a60,5808002;1a60,e808003;b00,e7100100;b00,e3100100;b00,e3100000;1c38,2;a00,d047c8;a04,46ff800c;a08,8c838300;a0c,2e7e000f;a10,9500bb78;a14,11144028;a18,881117;a1c,89140f00;a20,1a1b0030;a24,90e1317;a28,204;a2c,900000;a70,101fff00;a74,128;a78,900;a7c,225b0606;a80,218075b2;a84,9c1f8c00;1b04,e24628d2;1b10,88010d46;1b14,0;1b18,292903;1b00,f8000000;1b00,f800d000;1b00,f801f000;1b1c,a2123db2;1b20,7040001;1b24,7060807;1b28,c0060348;1b2c,20000003;1b30,20000000;1b38,20000000;1b3c,20000000;1bd4,1;1b94,80000000;1b34,0;1b34,2;1b34,0;1b00,f8000002;1b00,f800d002;1b00,f801f002;1b1c,a2123db2;1b20,7040001;1b24,7060807;1b28,c0060348;1b2c,20000003;1b30,20000000;1b38,20000000;1b3c,20000000;1bd4,1;1b94,80000000;1b34,0;1b34,2;1b34,0;1b00,f8000004;1b00,f800d004;1b00,f801f004;1b1c,a2123db2;1b20,7040001;1b24,7060807;1b28,c0060348;1b2c,20000003;1b30,20000000;1b38,20000000;1b3c,20000000;1bd4,1;1b94,80000000;1b34,0;1b34,2;1b34,0;1b00,f8000006;1b00,f800d006;1b00,f801f006;1b1c,a2123db2;1b20,7040001;1b24,7060807;1b28,c0060348;1b2c,20000003;1b30,20000000;1b38,20000000;1b3c,20000000;1bd4,1;1b94,80000000;1b34,0;1b34,2;1b34,0;1b00,f8000000;1b80,7;1b80,9060005;1b80,9060007;1b80,ffe0015;1b80,ffe0017;1b80,240025;1b80,240027;1b80,40035;1b80,40037;1b80,5c00045;1b80,5c00047;1b80,70055;1b80,70057;1b80,64000065;1b80,64000067;1b80,20075;1b80,20077;1b80,80085;1b80,80087;1b80,80000095;1b80,80000097;1b80,90100a5;1b80,90100a7;1b80,f0200b5;1b80,f0200b7;1b80,2400c5;1b80,2400c7;1b80,400d5;1b80,400d7;1b80,5c000e5;1b80,5c000e7;1b80,700f5;1b80,700f7;1b80,64020105;1b80,64020107;1b80,20115;1b80,20117;1b80,40125;1b80,40127;1b80,4a000135;1b80,4a000137;1b80,4b040145;1b80,4b040147;1b80,85030155;1b80,85030157;1b80,40010165;1b80,40010167;1b80,e0290175;1b80,e0290177;1b80,40185;1b80,40187;1b80,4b050195;1b80,4b050197;1b80,860301a5;1b80,860301a7;1b80,400301b5;1b80,400301b7;1b80,e02901c5;1b80,e02901c7;1b80,401d5;1b80,401d7;1b80,4b0601e5;1b80,4b0601e7;1b80,870301f5;1b80,870301f7;1b80,40050205;1b80,40050207;1b80,e0290215;1b80,e0290217;1b80,40225;1b80,40227;1b80,4b070235;1b80,4b070237;1b80,88030245;1b80,88030247;1b80,40070255;1b80,40070257;1b80,e0290265;1b80,e0290267;1b80,4b000275;1b80,4b000277;1b80,30000285;1b80,30000287;1b80,fe100295;1b80,fe100297;1b80,ff1002a5;1b80,ff1002a7;1b80,e18602b5;1b80,e18602b7;1b80,f00a02c5;1b80,f00a02c7;1b80,f10a02d5;1b80,f10a02d7;1b80,f20a02e5;1b80,f20a02e7;1b80,f30802f5;1b80,f30802f7;1b80,f4070305;1b80,f4070307;1b80,f5060315;1b80,f5060317;1b80,f7060325;1b80,f7060327;1b80,f8050335;1b80,f8050337;1b80,f9040345;1b80,f9040347;1b80,10355;1b80,10357;1b80,303b0365;1b80,303b0367;1b80,30500375;1b80,30500377;1b80,305c0385;1b80,305c0387;1b80,31d50395;1b80,31d50397;1b80,31c503a5;1b80,31c503a7;1b80,4d0403b5;1b80,4d0403b7;1b80,2ef003c5;1b80,2ef003c7;1b80,203d5;1b80,203d7;1b80,208003e5;1b80,208003e7;1b80,3f5;1b80,3f7;1b80,4d000405;1b80,4d000407;1b80,55070415;1b80,55070417;1b80,e1230425;1b80,e1230427;1b80,e1230435;1b80,e1230437;1b80,4d040445;1b80,4d040447;1b80,20800455;1b80,20800457;1b80,84000465;1b80,84000467;1b80,4d000475;1b80,4d000477;1b80,550f0485;1b80,550f0487;1b80,e1230495;1b80,e1230497;1b80,4f0204a5;1b80,4f0204a7;1b80,4e0004b5;1b80,4e0004b7;1b80,530204c5;1b80,530204c7;1b80,520104d5;1b80,520104d7;1b80,e12704e5;1b80,e12704e7;1b80,104f5;1b80,104f7;1b80,5c720505;1b80,5c720507;1b80,e1320515;1b80,e1320517;1b80,54e50525;1b80,54e50527;1b80,54bf0535;1b80,54bf0537;1b80,54c50545;1b80,54c50547;1b80,54be0555;1b80,54be0557;1b80,54df0565;1b80,54df0567;1b80,ba60575;1b80,ba60577;1b80,f3130585;1b80,f3130587;1b80,f41e0595;1b80,f41e0597;1b80,f53c05a5;1b80,f53c05a7;1b80,105b5;1b80,105b7;1b80,620605c5;1b80,620605c7;1b80,600605d5;1b80,600605d7;1b80,e1a905e5;1b80,e1a905e7;1b80,c0005f5;1b80,c0005f7;1b80,5c720605;1b80,5c720607;1b80,e1320615;1b80,e1320617;1b80,5cf10625;1b80,5cf10627;1b80,c010635;1b80,c010637;1b80,f2020645;1b80,f2020647;1b80,30d60655;1b80,30d60657;1b80,ac60665;1b80,ac60667;1b80,e1b60675;1b80,e1b60677;1b80,e1580685;1b80,e1580687;1b80,54e50695;1b80,54e50697;1b80,106a5;1b80,106a7;1b80,560106b5;1b80,560106b7;1b80,5ce206c5;1b80,5ce206c7;1b80,ae106d5;1b80,ae106d7;1b80,630c06e5;1b80,630c06e7;1b80,e13f06f5;1b80,e13f06f7;1b80,270705;1b80,270707;1b80,e16c0715;1b80,e16c0717;1b80,20725;1b80,20727;1b80,2a0735;1b80,2a0737;1b80,7140745;1b80,7140747;1b80,20755;1b80,20757;1b80,30c30765;1b80,30c30767;1b80,56010775;1b80,56010777;1b80,5ce20785;1b80,5ce20787;1b80,ae10795;1b80,ae10797;1b80,631707a5;1b80,631707a7;1b80,e13f07b5;1b80,e13f07b7;1b80,2507c5;1b80,2507c7;1b80,e16c07d5;1b80,e16c07d7;1b80,207e5;1b80,207e7;1b80,630f07f5;1b80,630f07f7;1b80,e13f0805;1b80,e13f0807;1b80,63070815;1b80,63070817;1b80,e13f0825;1b80,e13f0827;1b80,7140835;1b80,7140837;1b80,56000845;1b80,56000847;1b80,5cf20855;1b80,5cf20857;1b80,af10865;1b80,af10867;1b80,7140875;1b80,7140877;1b80,7140885;1b80,7140887;1b80,630f0895;1b80,630f0897;1b80,e13f08a5;1b80,e13f08a7;1b80,631708b5;1b80,631708b7;1b80,e13f08c5;1b80,e13f08c7;1b80,2508d5;1b80,2508d7;1b80,e16c08e5;1b80,e16c08e7;1b80,208f5;1b80,208f7;1b80,30c30905;1b80,30c30907;1b80,e1a90915;1b80,e1a90917;1b80,62060925;1b80,62060927;1b80,60060935;1b80,60060937;1b80,e1160945;1b80,e1160947;1b80,54be0955;1b80,54be0957;1b80,56010965;1b80,56010967;1b80,5ce20975;1b80,5ce20977;1b80,ae10985;1b80,ae10987;1b80,633a0995;1b80,633a0997;1b80,e13f09a5;1b80,e13f09a7;1b80,633709b5;1b80,633709b7;1b80,e13f09c5;1b80,e13f09c7;1b80,632f09d5;1b80,632f09d7;1b80,e13f09e5;1b80,e13f09e7;1b80,632709f5;1b80,632709f7;1b80,e13f0a05;1b80,e13f0a07;1b80,631f0a15;1b80,631f0a17;1b80,e13f0a25;1b80,e13f0a27;1b80,63170a35;1b80,63170a37;1b80,e13f0a45;1b80,e13f0a47;1b80,630f0a55;1b80,630f0a57;1b80,e13f0a65;1b80,e13f0a67;1b80,63070a75;1b80,63070a77;1b80,e13f0a85;1b80,e13f0a87;1b80,e16c0a95;1b80,e16c0a97;1b80,56000aa5;1b80,56000aa7;1b80,5cf20ab5;1b80,5cf20ab7;1b80,af10ac5;1b80,af10ac7;1b80,f5040ad5;1b80,f5040ad7;1b80,e13f0ae5;1b80,e13f0ae7;1b80,e16c0af5;1b80,e16c0af7;1b80,30b30b05;1b80,30b30b07;1b80,7140b15;1b80,7140b17;1b80,7140b25;1b80,7140b27;1b80,630f0b35;1b80,630f0b37;1b80,e13f0b45;1b80,e13f0b47;1b80,63170b55;1b80,63170b57;1b80,e13f0b65;1b80,e13f0b67;1b80,631f0b75;1b80,631f0b77;1b80,e13f0b85;1b80,e13f0b87;1b80,63270b95;1b80,63270b97;1b80,e13f0ba5;1b80,e13f0ba7;1b80,632f0bb5;1b80,632f0bb7;1b80,e13f0bc5;1b80,e13f0bc7;1b80,63370bd5;1b80,63370bd7;1b80,e13f0be5;1b80,e13f0be7;1b80,633a0bf5;1b80,633a0bf7;1b80,e13f0c05;1b80,e13f0c07;1b80,f60b0c15;1b80,f60b0c17;1b80,f7170c25;1b80,f7170c27;1b80,4d300c35;1b80,4d300c37;1b80,57040c45;1b80,57040c47;1b80,57000c55;1b80,57000c57;1b80,96000c65;1b80,96000c67;1b80,57080c75;1b80,57080c77;1b80,57000c85;1b80,57000c87;1b80,95000c95;1b80,95000c97;1b80,4d000ca5;1b80,4d000ca7;1b80,6c070cb5;1b80,6c070cb7;1b80,10cc5;1b80,10cc7;1b80,220cd5;1b80,220cd7;1b80,6140ce5;1b80,6140ce7;1b80,e16c0cf5;1b80,e16c0cf7;1b80,20d05;1b80,20d07;1b80,250d15;1b80,250d17;1b80,6140d25;1b80,6140d27;1b80,e16c0d35;1b80,e16c0d37;1b80,20d45;1b80,20d47;1b80,10d55;1b80,10d57;1b80,320d65;1b80,320d67;1b80,e16c0d75;1b80,e16c0d77;1b80,20d85;1b80,20d87;1b80,e1860d95;1b80,e1860d97;1b80,e1b60da5;1b80,e1b60da7;1b80,5cd10db5;1b80,5cd10db7;1b80,673a0dc5;1b80,673a0dc7;1b80,e1230dd5;1b80,e1230dd7;1b80,f80b0de5;1b80,f80b0de7;1b80,f9110df5;1b80,f9110df7;1b80,e1580e05;1b80,e1580e07;1b80,67370e15;1b80,67370e17;1b80,e1580e25;1b80,e1580e27;1b80,672f0e35;1b80,672f0e37;1b80,e1580e45;1b80,e1580e47;1b80,67270e55;1b80,67270e57;1b80,e1580e65;1b80,e1580e67;1b80,671f0e75;1b80,671f0e77;1b80,e1580e85;1b80,e1580e87;1b80,67170e95;1b80,67170e97;1b80,e1580ea5;1b80,e1580ea7;1b80,f8020eb5;1b80,f8020eb7;1b80,30ee0ec5;1b80,30ee0ec7;1b80,e0d10ed5;1b80,e0d10ed7;1b80,670f0ee5;1b80,670f0ee7;1b80,e1580ef5;1b80,e1580ef7;1b80,67070f05;1b80,67070f07;1b80,e1580f15;1b80,e1580f17;1b80,f9020f25;1b80,f9020f27;1b80,30f50f35;1b80,30f50f37;1b80,e0cd0f45;1b80,e0cd0f47;1b80,6140f55;1b80,6140f57;1b80,e16c0f65;1b80,e16c0f67;1b80,5cf10f75;1b80,5cf10f77;1b80,e1580f85;1b80,e1580f87;1b80,6140f95;1b80,6140f97;1b80,e16c0fa5;1b80,e16c0fa7;1b80,f9020fb5;1b80,f9020fb7;1b80,30ff0fc5;1b80,30ff0fc7;1b80,e0cd0fd5;1b80,e0cd0fd7;1b80,31130fe5;1b80,31130fe7;1b80,670f0ff5;1b80,670f0ff7;1b80,e1581005;1b80,e1581007;1b80,67171015;1b80,67171017;1b80,e1581025;1b80,e1581027;1b80,f8021035;1b80,f8021037;1b80,31071045;1b80,31071047;1b80,e0d11055;1b80,e0d11057;1b80,31131065;1b80,31131067;1b80,670f1075;1b80,670f1077;1b80,e1581085;1b80,e1581087;1b80,671f1095;1b80,671f1097;1b80,e15810a5;1b80,e15810a7;1b80,672710b5;1b80,672710b7;1b80,e15810c5;1b80,e15810c7;1b80,672f10d5;1b80,672f10d7;1b80,e15810e5;1b80,e15810e7;1b80,673710f5;1b80,673710f7;1b80,e1581105;1b80,e1581107;1b80,673a1115;1b80,673a1117;1b80,e1581125;1b80,e1581127;1b80,4d101135;1b80,4d101137;1b80,30c41145;1b80,30c41147;1b80,11155;1b80,11157;1b80,6f241165;1b80,6f241167;1b80,6e401175;1b80,6e401177;1b80,6d001185;1b80,6d001187;1b80,55031195;1b80,55031197;1b80,312311a5;1b80,312311a7;1b80,6f1c11b5;1b80,6f1c11b7;1b80,6e4011c5;1b80,6e4011c7;1b80,550b11d5;1b80,550b11d7;1b80,312311e5;1b80,312311e7;1b80,61c11f5;1b80,61c11f7;1b80,54de1205;1b80,54de1207;1b80,6dc1215;1b80,6dc1217;1b80,55131225;1b80,55131227;1b80,74011235;1b80,74011237;1b80,74001245;1b80,74001247;1b80,8e001255;1b80,8e001257;1b80,11265;1b80,11267;1b80,57021275;1b80,57021277;1b80,57001285;1b80,57001287;1b80,97001295;1b80,97001297;1b80,112a5;1b80,112a7;1b80,54bf12b5;1b80,54bf12b7;1b80,54c112c5;1b80,54c112c7;1b80,54a212d5;1b80,54a212d7;1b80,54c012e5;1b80,54c012e7;1b80,54a112f5;1b80,54a112f7;1b80,54df1305;1b80,54df1307;1b80,11315;1b80,11317;1b80,55001325;1b80,55001327;1b80,e1231335;1b80,e1231337;1b80,54811345;1b80,54811347;1b80,e1231355;1b80,e1231357;1b80,54801365;1b80,54801367;1b80,2a1375;1b80,2a1377;1b80,e12b1385;1b80,e12b1387;1b80,e1231395;1b80,e1231397;1b80,548013a5;1b80,548013a7;1b80,e17213b5;1b80,e17213b7;1b80,bf3013c5;1b80,bf3013c7;1b80,213d5;1b80,213d7;1b80,302813e5;1b80,302813e7;1b80,4f7813f5;1b80,4f7813f7;1b80,4e001405;1b80,4e001407;1b80,53871415;1b80,53871417;1b80,52f11425;1b80,52f11427;1b80,e1161435;1b80,e1161437;1b80,e11b1445;1b80,e11b1447;1b80,e11f1455;1b80,e11f1457;1b80,e1271465;1b80,e1271467;1b80,54811475;1b80,54811477;1b80,e1161485;1b80,e1161487;1b80,e11b1495;1b80,e11b1497;1b80,e11f14a5;1b80,e11f14a7;1b80,e12714b5;1b80,e12714b7;1b80,548014c5;1b80,548014c7;1b80,2a14d5;1b80,2a14d7;1b80,e12b14e5;1b80,e12b14e7;1b80,e11614f5;1b80,e11614f7;1b80,e11b1505;1b80,e11b1507;1b80,e11f1515;1b80,e11f1517;1b80,e1271525;1b80,e1271527;1b80,54801535;1b80,54801537;1b80,e1721545;1b80,e1721547;1b80,bf171555;1b80,bf171557;1b80,21565;1b80,21567;1b80,30281575;1b80,30281577;1b80,6141585;1b80,6141587;1b80,73201595;1b80,73201597;1b80,720015a5;1b80,720015a7;1b80,710015b5;1b80,710015b7;1b80,550115c5;1b80,550115c7;1b80,e12315d5;1b80,e12315d7;1b80,e12715e5;1b80,e12715e7;1b80,548115f5;1b80,548115f7;1b80,e1231605;1b80,e1231607;1b80,e1271615;1b80,e1271617;1b80,54801625;1b80,54801627;1b80,2a1635;1b80,2a1637;1b80,e12b1645;1b80,e12b1647;1b80,e1231655;1b80,e1231657;1b80,e1271665;1b80,e1271667;1b80,54801675;1b80,54801677;1b80,e1721685;1b80,e1721687;1b80,bf031695;1b80,bf031697;1b80,216a5;1b80,216a7;1b80,302816b5;1b80,302816b7;1b80,54bf16c5;1b80,54bf16c7;1b80,54c516d5;1b80,54c516d7;1b80,50a16e5;1b80,50a16e7;1b80,71416f5;1b80,71416f7;1b80,54df1705;1b80,54df1707;1b80,11715;1b80,11717;1b80,54bf1725;1b80,54bf1727;1b80,54c01735;1b80,54c01737;1b80,54a31745;1b80,54a31747;1b80,54c11755;1b80,54c11757;1b80,54a41765;1b80,54a41767;1b80,4c831775;1b80,4c831777;1b80,4c031785;1b80,4c031787;1b80,bf0b1795;1b80,bf0b1797;1b80,54c217a5;1b80,54c217a7;1b80,54a417b5;1b80,54a417b7;1b80,4c8517c5;1b80,4c8517c7;1b80,4c0517d5;1b80,4c0517d7;1b80,bf0617e5;1b80,bf0617e7;1b80,54c117f5;1b80,54c117f7;1b80,54a31805;1b80,54a31807;1b80,4c861815;1b80,4c861817;1b80,4c061825;1b80,4c061827;1b80,bf011835;1b80,bf011837;1b80,54df1845;1b80,54df1847;1b80,11855;1b80,11857;1b80,71865;1b80,71867;1b80,54011875;1b80,54011877;1b80,41885;1b80,41887;1b80,56001895;1b80,56001897;1b80,5cf218a5;1b80,5cf218a7;1b80,630718b5;1b80,630718b7;1b80,620418c5;1b80,620418c7;1b80,610018d5;1b80,610018d7;1b80,670718e5;1b80,670718e7;1b80,660618f5;1b80,660618f7;1b80,6f201905;1b80,6f201907;1b80,6e001915;1b80,6e001917;1b80,6d001925;1b80,6d001927;1b80,6c031935;1b80,6c031937;1b80,73201945;1b80,73201947;1b80,72001955;1b80,72001957;1b80,71001965;1b80,71001967;1b80,7b201975;1b80,7b201977;1b80,7a001985;1b80,7a001987;1b80,79001995;1b80,79001997;1b80,7f2019a5;1b80,7f2019a7;1b80,7e0019b5;1b80,7e0019b7;1b80,7d0019c5;1b80,7d0019c7;1b80,90119d5;1b80,90119d7;1b80,ac619e5;1b80,ac619e7;1b80,ba619f5;1b80,ba619f7;1b80,c011a05;1b80,c011a07;1b80,d021a15;1b80,d021a17;1b80,e041a25;1b80,e041a27;1b80,fff1a35;1b80,fff1a37;1b80,4d041a45;1b80,4d041a47;1b80,28f81a55;1b80,28f81a57;1b80,e0001a65;1b80,e0001a67;1b80,4d001a75;1b80,4d001a77;1b80,11a85;1b80,11a87;1b80,4d041a95;1b80,4d041a97;1b80,2ef81aa5;1b80,2ef81aa7;1b80,21ab5;1b80,21ab7;1b80,23031ac5;1b80,23031ac7;1b80,1ad5;1b80,1ad7;1b80,23131ae5;1b80,23131ae7;1b80,e77f1af5;1b80,e77f1af7;1b80,232f1b05;1b80,232f1b07;1b80,efbf1b15;1b80,efbf1b17;1b80,2ef01b25;1b80,2ef01b27;1b80,21b35;1b80,21b37;1b80,4d001b45;1b80,4d001b47;1b80,11b55;1b80,11b57;1b80,4d041b65;1b80,4d041b67;1b80,2ef81b75;1b80,2ef81b77;1b80,21b85;1b80,21b87;1b80,23031b95;1b80,23031b97;1b80,1ba5;1b80,1ba7;1b80,23131bb5;1b80,23131bb7;1b80,e77f1bc5;1b80,e77f1bc7;1b80,232f1bd5;1b80,232f1bd7;1b80,e79f1be5;1b80,e79f1be7;1b80,2ef01bf5;1b80,2ef01bf7;1b80,21c05;1b80,21c07;1b80,28f81c15;1b80,28f81c17;1b80,80001c25;1b80,80001c27;1b80,4d001c35;1b80,4d001c37;1b80,11c45;1b80,11c47;1b80,41c55;1b80,41c57;1b80,6bc01c65;1b80,6bc01c67;1b80,4d041c75;1b80,4d041c77;1b80,68481c85;1b80,68481c87;1b80,66061c95;1b80,66061c97;1b80,65041ca5;1b80,65041ca7;1b80,64471cb5;1b80,64471cb7;1b80,23411cc5;1b80,23411cc7;1b80,100e1cd5;1b80,100e1cd7;1b80,60011ce5;1b80,60011ce7;1b80,23411cf5;1b80,23411cf7;1b80,60611d05;1b80,60611d07;1b80,23411d15;1b80,23411d17;1b80,70e11d25;1b80,70e11d27;1b80,4d001d35;1b80,4d001d37;1b80,11d45;1b80,11d47;1b80,41d55;1b80,41d57;1b80,6b401d65;1b80,6b401d67;1b80,4d041d75;1b80,4d041d77;1b80,68481d85;1b80,68481d87;1b80,66061d95;1b80,66061d97;1b80,65081da5;1b80,65081da7;1b80,64471db5;1b80,64471db7;1b80,23411dc5;1b80,23411dc7;1b80,11e41dd5;1b80,11e41dd7;1b80,60011de5;1b80,60011de7;1b80,23411df5;1b80,23411df7;1b80,60e11e05;1b80,60e11e07;1b80,23411e15;1b80,23411e17;1b80,70611e25;1b80,70611e27;1b80,4d001e35;1b80,4d001e37;1b80,11e45;1b80,11e47;1b80,1e55;1b80,1e57;1b80,1e65;1b80,1e67;1b80,1e75;1b80,1e77;1b80,1e85;1b80,1e87;1b80,1e95;1b80,1e97;1b80,1ea5;1b80,1ea7;1b80,1eb5;1b80,1eb7;1b80,1ec5;1b80,1ec7;1b80,1ed5;1b80,1ed7;1b80,1ee5;1b80,1ee7;1b80,1ef5;1b80,1ef7;1b80,1f05;1b80,1f07;1b80,1f15;1b80,1f17;1b80,1f25;1b80,1f27;1b80,1f35;1b80,1f37;1b80,1f45;1b80,1f47;1b80,1f55;1b80,1f57;1b80,1f65;1b80,1f67;1b80,1f75;1b80,1f77;1b80,1f85;1b80,1f87;1b80,1f95;1b80,1f97;1b80,1fa5;1b80,1fa7;1b80,1fb5;1b80,1fb7;1b80,1fc5;1b80,1fc7;1b80,1fd5;1b80,1fd7;1b80,1fe5;1b80,1fe7;1b80,1ff5;1b80,1ff7;1b80,6;1b80,2"+ private const val S_AGC = "81c,ff000003;81c,fe000003;81c,fd020003;81c,fc040003;81c,fb060003;81c,fa080003;81c,f90a0003;81c,f80c0003;81c,f70e0003;81c,f6100003;81c,f5120003;81c,f4140003;81c,f3160003;81c,f2180003;81c,f11a0003;81c,f01c0003;81c,ef1e0003;81c,ee200003;81c,ed220003;81c,cf240003;81c,ce260003;81c,cd280003;81c,cc2a0003;81c,cb2c0003;81c,ca2e0003;81c,c9300003;81c,c8320003;81c,c7340003;81c,c6360003;81c,c5380003;81c,c43a0003;81c,a63c0003;81c,a53e0003;81c,a4400003;81c,a3420003;81c,a2440003;81c,a1460003;81c,86480003;81c,854a0003;81c,844c0003;81c,834e0003;81c,66500003;81c,65520003;81c,64540003;81c,63560003;81c,62580003;81c,615a0003;81c,435c0003;81c,425e0003;81c,41600003;81c,27620003;81c,26640003;81c,25660003;81c,24680003;81c,236a0003;81c,226c0003;81c,216e0003;81c,21700003;81c,21720003;81c,21740003;81c,21760003;81c,21780003;81c,217a0003;81c,217c0003;81c,217e0003;81c,ff000103;81c,fe020103;81c,fd040103;81c,fc060103;81c,fb080103;81c,fa0a0103;81c,f90c0103;81c,f80e0103;81c,f7100103;81c,f6120103;81c,f5140103;81c,f4160103;81c,f3180103;81c,f21a0103;81c,f11c0103;81c,f01e0103;81c,ef200103;81c,ee220103;81c,ed240103;81c,ec260103;81c,eb280103;81c,ea2a0103;81c,e92c0103;81c,e82e0103;81c,e7300103;81c,e6320103;81c,e5340103;81c,e4360103;81c,e3380103;81c,e23a0103;81c,e13c0103;81c,a43e0103;81c,a3400103;81c,a2420103;81c,a1440103;81c,86460103;81c,85480103;81c,844a0103;81c,834c0103;81c,824e0103;81c,81500103;81c,64520103;81c,63540103;81c,62560103;81c,61580103;81c,435a0103;81c,425c0103;81c,415e0103;81c,25600103;81c,24620103;81c,6640103;81c,5660103;81c,4680103;81c,36a0103;81c,26c0103;81c,16e0103;81c,1700103;81c,1720103;81c,1740103;81c,1760103;81c,1780103;81c,17a0103;81c,17c0103;81c,17e0103;81c,ff000203;81c,ff020203;81c,fe040203;81c,fd060203;81c,fc080203;81c,fb0a0203;81c,fa0c0203;81c,f90e0203;81c,f8100203;81c,f7120203;81c,f6140203;81c,f5160203;81c,f4180203;81c,f31a0203;81c,f21c0203;81c,f11e0203;81c,f0200203;81c,ef220203;81c,ee240203;81c,ed260203;81c,ec280203;81c,eb2a0203;81c,ea2c0203;81c,e92e0203;81c,e8300203;81c,e7320203;81c,e6340203;81c,e5360203;81c,e4380203;81c,e33a0203;81c,e23c0203;81c,e13e0203;81c,a4400203;81c,a3420203;81c,a2440203;81c,a1460203;81c,85480203;81c,844a0203;81c,834c0203;81c,824e0203;81c,81500203;81c,64520203;81c,63540203;81c,62560203;81c,61580203;81c,445a0203;81c,435c0203;81c,425e0203;81c,25600203;81c,24620203;81c,6640203;81c,5660203;81c,4680203;81c,36a0203;81c,26c0203;81c,16e0203;81c,1700203;81c,1720203;81c,1740203;81c,1760203;81c,1780203;81c,17a0203;81c,17c0203;81c,17e0203;81c,fd000303;81c,fc020303;81c,fb040303;81c,fa060303;81c,f9080303;81c,f80a0303;81c,f70c0303;81c,f60e0303;81c,f5100303;81c,f4120303;81c,f3140303;81c,f2160303;81c,f1180303;81c,f01a0303;81c,ef1c0303;81c,ee1e0303;81c,ed200303;81c,ec220303;81c,eb240303;81c,ea260303;81c,e9280303;81c,e82a0303;81c,e72c0303;81c,e62e0303;81c,e5300303;81c,e4320303;81c,e3340303;81c,e2360303;81c,e1380303;81c,a53a0303;81c,a43c0303;81c,a33e0303;81c,a2400303;81c,a1420303;81c,87440303;81c,86460303;81c,85480303;81c,844a0303;81c,834c0303;81c,824e0303;81c,81500303;81c,64520303;81c,63540303;81c,62560303;81c,61580303;81c,435a0303;81c,425c0303;81c,415e0303;81c,7600303;81c,6620303;81c,5640303;81c,4660303;81c,3680303;81c,26a0303;81c,16c0303;81c,16e0303;81c,1700303;81c,1720303;81c,1740303;81c,1760303;81c,1780303;81c,17a0303;81c,17c0303;81c,17e0303;c50,22;c50,20;e50,22;e50,20;1850,22;1850,20;1a50,22;1a50,20"+ private const val S_RFA = "18,13124;40,c00;58,f98;7f,68004;b0,ffffe;b1,3ff48;b2,6aa3f;b3,ffc9a;b4,a78f;b5,a3f;b6,c09c;b7,3000c;b8,7400e;b9,fbf50;ba,50780;bb,0;bc,40009;bd,0;be,0;bf,0;ef,20000;3e,0;3f,30000;3e,20000;3f,40000;3e,40000;3f,30000;3e,60000;3f,30000;ef,0;ef,10000;3e,0;3f,6800;3e,80;3f,6000;3e,100;3f,4800;3e,180;3f,4000;3e,200;3f,4000;3e,280;3f,2800;3e,300;3f,2800;3e,380;3f,2000;ef,0;ef,40000;3e,0;3f,bc;3e,40;3f,53;3e,50;3f,50;3e,60;3f,50;ef,0;ef,400;3e,6;41,ee080;3e,8;41,ee0c0;3e,a;41,ee100;3e,c;41,ee100;ef,0;18,6;86,e4b58;87,49f80;df,8;ef,2000;3b,3f258;3b,30a58;3b,2fa58;3b,22590;3b,1fa50;3b,10248;3b,8240;ef,100;34,adf6;34,9df3;34,8df0;34,7ded;34,6dea;34,5ced;34,4cea;34,34ea;34,24e7;34,146a;34,6b;34,8adf6;34,89df3;34,88df0;34,87ded;34,86dea;34,85ced;34,84cea;34,834ea;34,824e7;34,8146a;34,8006b;ef,0;ef,20a2;df,80;35,192;35,8192;35,10192;36,24;36,8024;36,10024;36,18024;ef,0;51,c21;52,6d9;53,fc649;54,17e;18,1012a;81,7fc00;89,50110;8a,43e50;8b,2e180;8c,93c3c;85,f8000;8d,ffff0;ef,1000;3a,13c;3b,38023;3c,28000;3a,13c;3b,30023;3c,48000;3a,13c;3b,28623;3c,0;3a,13c;3b,21633;3c,0;3a,13c;3b,1c633;3c,0;3a,13c;3b,10293;3c,0;3a,13c;3b,9593;3c,0;3a,148;3b,78b;3c,0;3a,13c;3b,78023;3c,4c000;3a,13c;3b,70023;3c,48000;3a,13c;3b,68623;3c,0;3a,13c;3b,61633;3c,0;3a,13c;3b,5c633;3c,0;3a,13c;3b,50293;3c,0;3a,13c;3b,49593;3c,0;3a,148;3b,4078b;3c,0;3a,13c;3b,b8023;3c,4000;3a,13c;3b,b0023;3c,20000;3a,13c;3b,a8623;3c,0;3a,13c;3b,a1633;3c,0;3a,13c;3b,9c633;3c,0;3a,13c;3b,90293;3c,0;3a,13c;3b,89593;3c,0;3a,148;3b,8078b;3c,0;ef,0;ef,800;3b,0;3a,803;3b,40000;3a,1000;3b,80000;3a,1002;ef,0;18,13124;ef,100;34,4aff1;34,49fee;34,48feb;34,47fe8;34,46dea;34,45de7;34,44cea;34,43ce7;34,42c69;34,41c66;34,40c28;34,2aff1;34,29fee;34,28feb;34,27fe8;34,26dea;34,25de7;34,24cea;34,23ce7;34,22c69;34,21c66;34,20c28;34,aff1;34,9fee;34,8feb;34,7fe8;34,6dea;34,5de7;34,4cea;34,3ce7;34,2c69;34,1c66;34,c28;34,ca794;34,c9791;34,c878e;34,c778b;34,c658d;34,c558a;34,c448d;34,c348a;34,c244c;34,c1449;34,c042b;34,aa794;34,a9791;34,a878e;34,a778b;34,a658d;34,a558a;34,a448d;34,a348a;34,a244c;34,a1449;34,a042b;34,8a794;34,89791;34,8878e;34,8778b;34,8658d;34,8558a;34,8448d;34,8348a;34,8244c;34,81449;34,8042b;ef,0;df,1;18,1712a;ef,40;35,747;35,8747;35,10747;35,20747;35,28747;35,30747;35,40747;35,48747;35,50747;35,805fb;35,885fb;35,905fb;35,a05fb;35,a85fb;35,b05fb;35,c05fb;35,c85fb;35,d05fb;ef,0;df,1;18,1712a;ef,10;36,473;36,8473;36,10473;36,20473;36,28473;36,30473;36,40473;36,48473;36,50473;36,80473;36,88473;36,90473;36,a0473;36,a8473;36,b0473;36,c0473;36,c8473;36,d0473;ef,0;ef,4;37,0;38,5146;37,4000;38,5146;37,8000;38,5146;37,10000;38,5146;37,14000;38,5146;37,18000;38,4d4e;37,1c000;38,4d4e;37,20000;38,4d4e;37,24000;38,71c6;37,28000;38,71c6;37,2c000;38,71c6;37,30000;38,71ce;37,34000;38,71ce;37,38000;38,5126;37,3c000;38,5126;37,40000;38,5126;37,44000;38,5126;37,48000;38,5126;37,80000;38,5ece;37,84000;38,5ece;37,88000;38,5ece;37,90000;38,5ece;37,94000;38,5ece;37,98000;38,5ece;37,9c000;38,5ece;37,a0000;38,5ece;37,a4000;38,5ece;37,a8000;38,5ece;37,ac000;38,5ece;37,b0000;38,5ece;37,b4000;38,5ece;37,b8000;38,5ece;37,bc000;38,5ece;37,c0000;38,5ece;37,c4000;38,5ece;37,c8000;38,5ece;ef,0;ef,8;3c,7d;3c,47d;3c,87d;3c,107d;3c,147d;3c,187d;3c,37e;3c,575;3c,971;3c,127e;3c,1575;3c,1871;3c,217e;3c,2575;3c,2871;ef,0;61,c0d47;62,133c;63,7d0e7;64,14fec;65,933ff;66,40;57,50000;56,51df0;55,82060;1c,739d2;1f,2255c;b1,7ff48;c4,83f00;18,1b126;d,32;d,32;d,32;18,13126;18,13124"+ private const val S_RFB = "18,13124;40,c00;58,f98;7f,68004;18,6;86,e4b58;87,49f80;df,8;ef,2000;3b,3f258;3b,30a58;3b,2fa58;3b,22590;3b,1fa50;3b,10248;3b,8240;ef,100;34,adf6;34,9df3;34,8df0;34,7ded;34,6dea;34,5ced;34,4cea;34,34ea;34,24e7;34,146a;34,6b;34,8adf6;34,89df3;34,88df0;34,87ded;34,86dea;34,85ced;34,84cea;34,834ea;34,824e7;34,8146a;34,8006b;ef,0;ef,20a2;df,80;35,192;35,8192;35,10192;36,24;36,8024;36,10024;36,18024;ef,0;51,c21;52,6d9;53,fc649;54,17e;18,1012a;81,7fc00;89,50110;8a,43e50;8b,2e180;8c,93c3c;85,f8000;8d,ffff0;ef,1000;3a,13c;3b,38023;3c,40000;3a,13c;3b,30023;3c,48000;3a,13c;3b,28623;3c,0;3a,13c;3b,21633;3c,0;3a,13c;3b,1c633;3c,0;3a,13c;3b,10293;3c,0;3a,13c;3b,9593;3c,0;3a,148;3b,78b;3c,0;3a,13c;3b,78023;3c,20000;3a,13c;3b,70023;3c,48000;3a,13c;3b,68623;3c,0;3a,13c;3b,61633;3c,0;3a,13c;3b,5c633;3c,0;3a,13c;3b,50293;3c,0;3a,13c;3b,49593;3c,0;3a,148;3b,4078b;3c,0;3a,13c;3b,b8023;3c,20000;3a,13c;3b,b0023;3c,20000;3a,13c;3b,a8623;3c,0;3a,13c;3b,a1633;3c,0;3a,13c;3b,9c633;3c,0;3a,13c;3b,90293;3c,0;3a,13c;3b,89593;3c,0;3a,148;3b,8078b;3c,0;ef,0;ef,800;3b,0;3a,803;3b,40000;3a,1000;3b,80000;3a,1002;ef,0;18,13124;ef,100;34,4aff4;34,49ff1;34,48fee;34,47feb;34,46fe8;34,45dea;34,44ced;34,43cea;34,42c6c;34,41c69;34,40c2b;34,2aff4;34,29ff1;34,28fee;34,27feb;34,26fe8;34,25dea;34,24ced;34,23cea;34,22c6c;34,21c69;34,20c2b;34,aff4;34,9ff1;34,8fee;34,7feb;34,6fe8;34,5dea;34,4ced;34,3cea;34,2c6c;34,1c69;34,c2b;34,ca794;34,c9791;34,c878e;34,c778b;34,c658d;34,c558a;34,c448d;34,c348a;34,c244c;34,c1449;34,c042b;34,aa794;34,a9791;34,a878e;34,a778b;34,a658d;34,a558a;34,a448d;34,a348a;34,a244c;34,a1449;34,a042b;34,8a794;34,89791;34,8878e;34,8778b;34,8658d;34,8558a;34,8448d;34,8348a;34,8244c;34,81449;34,8042b;ef,0;df,0;18,1712a;ef,40;35,484;35,8484;35,10484;35,20584;35,28584;35,30584;35,40584;35,48584;35,50584;35,805fb;35,885fb;35,905fb;35,a05fb;35,a85fb;35,b05fb;35,c05fb;35,c85fb;35,d05fb;ef,0;df,0;18,1712a;ef,10;36,474;36,8474;36,10474;36,20474;36,28474;36,30474;36,40474;36,48474;36,50474;36,80474;36,88474;36,90474;36,a0474;36,a8474;36,b0474;36,c0474;36,c8474;36,d0474;ef,0;ef,4;37,0;38,514e;37,4000;38,514e;37,8000;38,514e;37,10000;38,514e;37,14000;38,514e;37,18000;38,514e;37,1c000;38,514e;37,20000;38,514e;37,24000;38,514e;37,28000;38,514e;37,2c000;38,714e;37,30000;38,514e;37,34000;38,514e;37,38000;38,514e;37,3c000;38,514e;37,40000;38,514e;37,44000;38,514e;37,48000;38,514e;37,80000;38,5ece;37,84000;38,5ece;37,88000;38,5ece;37,90000;38,5ece;37,94000;38,5ece;37,98000;38,5ece;37,9c000;38,5ece;37,a0000;38,5ece;37,a4000;38,5ece;37,a8000;38,5ece;37,ac000;38,5ece;37,b0000;38,5ece;37,b4000;38,5ece;37,b8000;38,5ece;37,bc000;38,5ece;37,c0000;38,5ece;37,c4000;38,5ece;37,c8000;38,5ece;ef,0;ef,8;3c,7d;3c,47d;3c,87d;3c,107d;3c,147d;3c,187d;3c,37e;3c,575;3c,971;3c,127e;3c,1575;3c,1871;3c,217e;3c,2575;3c,2871;ef,0;61,c0d47;62,133c;63,7d0e7;64,14fec;65,923ff;66,40;57,50000;56,51df0;55,82060"+ private const val S_RFC = "18,13124;40,c00;58,f98;7f,68004;18,6;86,e4b58;87,49f80;df,8;ef,2000;3b,3f258;3b,30a58;3b,2fa58;3b,22590;3b,1fa50;3b,10248;3b,8240;ef,100;34,adf6;34,9df3;34,8df0;34,7ded;34,6dea;34,5ced;34,4cea;34,34ea;34,24e7;34,146a;34,6b;34,8adf6;34,89df3;34,88df0;34,87ded;34,86dea;34,85ced;34,84cea;34,834ea;34,824e7;34,8146a;34,8006b;ef,0;ef,20a2;df,80;35,192;35,8192;35,10192;36,24;36,8024;36,10024;36,18024;ef,0;51,c21;52,6d9;53,fc649;54,17e;18,1012a;81,7fc00;89,50110;8a,43e50;8b,2e180;8c,93c3c;85,f8000;8d,ffff0;ef,1000;3a,13c;3b,38023;3c,a0000;3a,13c;3b,30023;3c,48000;3a,13c;3b,28623;3c,0;3a,13c;3b,21633;3c,0;3a,13c;3b,1c633;3c,0;3a,13c;3b,10293;3c,0;3a,13c;3b,9593;3c,0;3a,148;3b,78b;3c,0;3a,13c;3b,78023;3c,28000;3a,13c;3b,70023;3c,48000;3a,13c;3b,68623;3c,0;3a,13c;3b,61633;3c,0;3a,13c;3b,5c633;3c,0;3a,13c;3b,50293;3c,0;3a,13c;3b,49593;3c,0;3a,148;3b,4078b;3c,0;3a,13c;3b,b8023;3c,20000;3a,13c;3b,b0023;3c,20000;3a,13c;3b,a8623;3c,0;3a,13c;3b,a1633;3c,0;3a,13c;3b,9c633;3c,0;3a,13c;3b,90293;3c,0;3a,13c;3b,89593;3c,0;3a,148;3b,8078b;3c,0;ef,0;ef,800;3b,0;3a,803;3b,40000;3a,1000;3b,80000;3a,1002;ef,0;18,13124;ef,100;34,4aff4;34,49ff1;34,48fee;34,47feb;34,46fe8;34,45dea;34,44ced;34,43cea;34,42c6c;34,41c69;34,40c2b;34,2aff4;34,29ff1;34,28fee;34,27feb;34,26fe8;34,25dea;34,24ced;34,23cea;34,22c6c;34,21c69;34,20c2b;34,aff4;34,9ff1;34,8fee;34,7feb;34,6fe8;34,5dea;34,4ced;34,3cea;34,2c6c;34,1c69;34,c2b;34,ca794;34,c9791;34,c878e;34,c778b;34,c658d;34,c558a;34,c448d;34,c348a;34,c244c;34,c1449;34,c042b;34,aa794;34,a9791;34,a878e;34,a778b;34,a658d;34,a558a;34,a448d;34,a348a;34,a244c;34,a1449;34,a042b;34,8a794;34,89791;34,8878e;34,8778b;34,8658d;34,8558a;34,8448d;34,8348a;34,8244c;34,81449;34,8042b;ef,0;df,0;18,1712a;ef,40;35,484;35,8484;35,10484;35,20584;35,28584;35,30584;35,40584;35,48584;35,50584;35,805fb;35,885fb;35,905fb;35,a05fb;35,a85fb;35,b05fb;35,c05fb;35,c85fb;35,d05fb;ef,0;df,0;18,1712a;ef,10;36,474;36,8474;36,10474;36,20474;36,28474;36,30474;36,40474;36,48474;36,50474;36,80474;36,88474;36,90474;36,a0474;36,a8474;36,b0474;36,c0474;36,c8474;36,d0474;ef,0;ef,4;37,0;38,514e;37,4000;38,514e;37,8000;38,514e;37,10000;38,514e;37,14000;38,514e;37,18000;38,514e;37,1c000;38,514e;37,20000;38,514e;37,24000;38,514e;37,28000;38,514e;37,2c000;38,714e;37,30000;38,514e;37,34000;38,514e;37,38000;38,514e;37,3c000;38,514e;37,40000;38,514e;37,44000;38,514e;37,48000;38,514e;37,80000;38,5ece;37,84000;38,5ece;37,88000;38,5ece;37,90000;38,5ece;37,94000;38,5ece;37,98000;38,5ece;37,9c000;38,5ece;37,a0000;38,5ece;37,a4000;38,5ece;37,a8000;38,5ece;37,ac000;38,5ece;37,b0000;38,5ece;37,b4000;38,5ece;37,b8000;38,5ece;37,bc000;38,5ece;37,c0000;38,5ece;37,c4000;38,5ece;37,c8000;38,5ece;ef,0;ef,8;3c,7d;3c,47d;3c,87d;3c,107d;3c,147d;3c,187d;3c,37e;3c,575;3c,971;3c,127e;3c,1575;3c,1871;3c,217e;3c,2575;3c,2871;ef,0;61,c0d47;62,133c;63,7d0e7;64,14fec;65,923ff;66,40;57,50000;56,51df0;55,82060"+ private const val S_RFD = "18,13124;40,c00;58,f98;7f,68004;18,6;86,e4b58;87,49f80;df,8;ef,2000;3b,3f258;3b,30a58;3b,2fa58;3b,22590;3b,1fa50;3b,10248;3b,8240;ef,100;34,adf6;34,9df3;34,8df0;34,7ded;34,6dea;34,5ced;34,4cea;34,34ea;34,24e7;34,146a;34,6b;34,8adf6;34,89df3;34,88df0;34,87ded;34,86dea;34,85ced;34,84cea;34,834ea;34,824e7;34,8146a;34,8006b;ef,0;ef,20a2;df,80;35,192;35,8192;35,10192;36,24;36,8024;36,10024;36,18024;ef,0;51,c21;52,6d9;53,fc649;54,17e;18,1012a;81,7fc00;89,50110;8a,43e50;8b,2e180;8c,93c3c;85,f8000;8d,ffff0;ef,1000;3a,13c;3b,38023;3c,48000;3a,13c;3b,30023;3c,48000;3a,13c;3b,28623;3c,0;3a,13c;3b,21633;3c,0;3a,13c;3b,1c633;3c,0;3a,13c;3b,10293;3c,0;3a,13c;3b,9593;3c,0;3a,148;3b,78b;3c,0;3a,13c;3b,78023;3c,24000;3a,13c;3b,70023;3c,48000;3a,13c;3b,68623;3c,0;3a,13c;3b,61633;3c,0;3a,13c;3b,5c633;3c,0;3a,13c;3b,50293;3c,0;3a,13c;3b,49593;3c,0;3a,148;3b,4078b;3c,0;3a,13c;3b,b8023;3c,4000;3a,13c;3b,b0023;3c,20000;3a,13c;3b,a8623;3c,0;3a,13c;3b,a1633;3c,0;3a,13c;3b,9c633;3c,0;3a,13c;3b,90293;3c,0;3a,13c;3b,89593;3c,0;3a,148;3b,8078b;3c,0;ef,0;ef,800;3b,0;3a,803;3b,40000;3a,1000;3b,80000;3a,1002;ef,0;18,13124;ef,100;34,4aff4;34,49ff1;34,48fee;34,47feb;34,46fe8;34,45dea;34,44ced;34,43cea;34,42c6c;34,41c69;34,40c2b;34,2aff4;34,29ff1;34,28fee;34,27feb;34,26fe8;34,25dea;34,24ced;34,23cea;34,22c6c;34,21c69;34,20c2b;34,aff4;34,9ff1;34,8fee;34,7feb;34,6fe8;34,5dea;34,4ced;34,3cea;34,2c6c;34,1c69;34,c2b;34,ca794;34,c9791;34,c878e;34,c778b;34,c658d;34,c558a;34,c448d;34,c348a;34,c244c;34,c1449;34,c042b;34,aa794;34,a9791;34,a878e;34,a778b;34,a658d;34,a558a;34,a448d;34,a348a;34,a244c;34,a1449;34,a042b;34,8a794;34,89791;34,8878e;34,8778b;34,8658d;34,8558a;34,8448d;34,8348a;34,8244c;34,81449;34,8042b;ef,0;df,0;18,1712a;ef,40;35,484;35,8484;35,10484;35,20584;35,28584;35,30584;35,40584;35,48584;35,50584;35,805fb;35,885fb;35,905fb;35,a05fb;35,a85fb;35,b05fb;35,c05fb;35,c85fb;35,d05fb;ef,0;df,0;18,1712a;ef,10;36,474;36,8474;36,10474;36,20474;36,28474;36,30474;36,40474;36,48474;36,50474;36,80474;36,88474;36,90474;36,a0474;36,a8474;36,b0474;36,c0474;36,c8474;36,d0474;ef,0;ef,4;37,0;38,514e;37,4000;38,514e;37,8000;38,514e;37,10000;38,514e;37,14000;38,514e;37,18000;38,514e;37,1c000;38,514e;37,20000;38,514e;37,24000;38,514e;37,28000;38,514e;37,2c000;38,714e;37,30000;38,514e;37,34000;38,514e;37,38000;38,514e;37,3c000;38,514e;37,40000;38,514e;37,44000;38,514e;37,48000;38,514e;37,80000;38,5ece;37,84000;38,5ece;37,88000;38,5ece;37,90000;38,5ece;37,94000;38,5ece;37,98000;38,5ece;37,9c000;38,5ece;37,a0000;38,5ece;37,a4000;38,5ece;37,a8000;38,5ece;37,ac000;38,5ece;37,b0000;38,5ece;37,b4000;38,5ece;37,b8000;38,5ece;37,bc000;38,5ece;37,c0000;38,5ece;37,c4000;38,5ece;37,c8000;38,5ece;ef,0;ef,8;3c,7d;3c,47d;3c,87d;3c,107d;3c,147d;3c,187d;3c,37e;3c,575;3c,971;3c,127e;3c,1575;3c,1871;3c,217e;3c,2575;3c,2871;ef,0;61,c0d47;62,133c;63,7d0e7;64,14fec;65,923ff;66,40;57,50000;56,51df0;55,82060"+}diff --git a/app/src/main/java/com/rfsentinel/app/usb/UsbWifi.kt b/app/src/main/java/com/rfsentinel/app/usb/UsbWifi.ktindex 97f7e1e..d1bd8ad 100644--- a/app/src/main/java/com/rfsentinel/app/usb/UsbWifi.kt+++ b/app/src/main/java/com/rfsentinel/app/usb/UsbWifi.kt@@ -43,15 +43,26 @@ object UsbWifi {private const val ACTION_PERMISSION = "com.rfsentinel.app.USB_WIFI_PERMISSION"/** Driver families. */- enum class Driver { RTL88XXAU, RTL88X2BU }+ enum class Driver { RTL88XXAU, RTL88X2BU, RTL8187, RT3070, RTL8814AU, MT7612U, AR9271 }/** A supported adapter: the chip name shown to the user and the driver that runs it. */data class Chip(val name: String, val driver: Driver)private val AU = Chip("RTL8811AU / 8821AU", Driver.RTL88XXAU)private val BU = Chip("RTL8812BU / 8822BU", Driver.RTL88X2BU)+ private val L8187 = Chip("RTL8187L", Driver.RTL8187)+ private val B8187 = Chip("RTL8187B", Driver.RTL8187)+ private val RT3070 = Chip("RT3070", Driver.RT3070)+ private val AU14 = Chip("RTL8814AU", Driver.RTL8814AU)+ private val MT = Chip("MT7612U", Driver.MT7612U)+ private val ATH = Chip("AR9271", Driver.AR9271)- /** USB IDs with a working driver: vendor:product -> chip. 88x2bu IDs from the Linux rtw88 driver. */+ /**+ * USB IDs with a working driver: vendor:product -> chip. 88x2bu and 8814au IDs from the+ * Linux rtw88 driver, RTL8187 IDs from rtl8187, RT3070 IDs from rt2800usb (the RT3070+ * driver checks the chip and declines other Ralink chips sharing an ID), MT76x2U IDs from+ * mt76x2u, AR9271 IDs from ath9k_htc (not its AR7010 ones, which need other firmware).+ */private val SUPPORTED: Map<Pair<Int, Int>, Chip> = mapOf((0x0bda to 0x0811) to AU, // ALFA AWUS036ACS and other 88xxau dongles(0x0bda to 0xb812) to Chip("RTL8812BU", Driver.RTL88X2BU), // generic AC1200 dongles (e.g. Wise Tiger)@@ -69,14 +80,42 @@ object UsbWifi {(0x0e66 to 0x0025) to BU, (0x04ca to 0x8602) to BU,(0x20f4 to 0x808a) to BU, (0x20f4 to 0x805a) to BU, // TRENDnet(0x056e to 0x4011) to BU, (0x2c4e to 0x0107) to BU, (0x2c4e to 0x010a) to BU,- (0x0411 to 0x03d1) to BU, (0x0411 to 0x03d0) to BU // Buffalo+ (0x0411 to 0x03d1) to BU, (0x0411 to 0x03d0) to BU, // Buffalo+ (0x0bda to 0x8187) to L8187, // ALFA AWUS036H and other RTL8187L dongles+ (0x0b05 to 0x171d) to L8187, (0x0769 to 0x11f2) to L8187, (0x0789 to 0x010c) to L8187,+ (0x0846 to 0x6100) to L8187, (0x0846 to 0x6a00) to L8187, (0x03f0 to 0xca02) to L8187, // Netgear WG111v2, HP+ (0x0df6 to 0x000d) to L8187, (0x114b to 0x0150) to L8187, (0x1371 to 0x9401) to L8187,+ (0x13d1 to 0xabe6) to L8187, (0x18e8 to 0x6232) to L8187, (0x1b75 to 0x8187) to L8187,+ (0x0bda to 0x8189) to B8187, (0x0bda to 0x8197) to B8187, (0x0bda to 0x8198) to B8187,+ (0x050d to 0x705e) to B8187, (0x0846 to 0x4260) to B8187, (0x0df6 to 0x0028) to B8187, // Belkin, Netgear WG111v3+ (0x0df6 to 0x0029) to B8187, (0x1737 to 0x0073) to B8187,+ (0x148f to 0x3070) to RT3070, // ALFA AWUS036NH / AWUS036NEH and other RT3070 dongles+ (0x148f to 0x2070) to RT3070, (0x7392 to 0x7711) to RT3070, (0x1737 to 0x0077) to RT3070, (0x2019 to 0xab25) to RT3070,+ (0x0bda to 0x8813) to AU14, // ALFA AWUS1900+ (0x056e to 0x400b) to AU14, (0x056e to 0x400d) to AU14, (0x0846 to 0x9054) to AU14, // ELECOM, Netgear A7000+ (0x0b05 to 0x1817) to AU14, (0x0b05 to 0x1852) to AU14, (0x0b05 to 0x1853) to AU14, // ASUS USB-AC68+ (0x0e66 to 0x0026) to AU14, (0x2001 to 0x331a) to AU14, (0x20f4 to 0x809a) to AU14, (0x20f4 to 0x809b) to AU14,+ (0x2357 to 0x0106) to AU14, (0x7392 to 0xa834) to AU14, (0x7392 to 0xa833) to AU14, // TP-Link Archer T9UH, Edimax+ (0x0e8d to 0x7612) to MT, // ALFA AWUS036ACM, Aukey USB-AC1200+ (0x0b05 to 0x1833) to MT, (0x0b05 to 0x17eb) to MT, (0x0b05 to 0x180b) to MT, // ASUS USB-AC54 / AC55 / N53 B1+ (0x057c to 0x8503) to MT, (0x7392 to 0xb711) to MT, (0x056e to 0x400a) to MT, (0x0e8d to 0x7632) to MT,+ (0x0471 to 0x2126) to MT, (0x0471 to 0x7600) to MT, (0x2c4e to 0x0103) to MT,+ (0x0846 to 0x9014) to MT, (0x0846 to 0x9053) to MT, // Netgear WNDA3100v3, A6210+ (0x045e to 0x02e6) to MT, (0x045e to 0x02fe) to MT, (0x2357 to 0x0137) to MT, // Xbox One wireless adapter, TP-Link+ (0x0cf3 to 0x9271) to ATH, // ALFA AWUS036NHA, TP-Link TL-WN722N v1+ (0x0cf3 to 0x1006) to ATH, (0x0846 to 0x9030) to ATH, (0x07b8 to 0x9271) to ATH, (0x07d1 to 0x3a10) to ATH,+ (0x13d3 to 0x3327) to ATH, (0x13d3 to 0x3328) to ATH, (0x13d3 to 0x3346) to ATH, (0x13d3 to 0x3348) to ATH,+ (0x13d3 to 0x3349) to ATH, (0x13d3 to 0x3350) to ATH, (0x04ca to 0x4605) to ATH, (0x040d to 0x3801) to ATH,+ (0x0cf3 to 0xb003) to ATH, (0x0cf3 to 0xb002) to ATH, (0x057c to 0x8403) to ATH, (0x0471 to 0x209e) to ATH,+ (0x1eda to 0x2315) to ATH)/** Known monitor-mode chips without a driver here yet (named in the status so users know why). */private val KNOWN = mapOf(- (0x0bda to 0x8812) to "RTL8812AU", (0x0bda to 0x881a) to "RTL8812AU", (0x0bda to 0x8813) to "RTL8814AU",+ (0x0bda to 0x8812) to "RTL8812AU", (0x0bda to 0x881a) to "RTL8812AU",(0x0bda to 0xc811) to "RTL8811CU / 8821CU", (0x0bda to 0xc820) to "RTL8821CU", (0x0bda to 0xc812) to "RTL8812CU",- (0x0cf3 to 0x9271) to "AR9271", (0x0e8d to 0x7612) to "MT7612U", (0x148f to 0x3070) to "RT3070",- (0x0bda to 0x8187) to "RTL8187"+ (0x0cf3 to 0x7010) to "AR7010", (0x0cf3 to 0x7015) to "AR7010", (0x0e8d to 0x7610) to "MT7610U",+ (0x148f to 0x3071) to "RT3071", (0x148f to 0x3072) to "RT3072", (0x148f to 0x5370) to "RT5370",+ (0x148f to 0x5372) to "RT5372")private var receiver: BroadcastReceiver? = null@@ -95,17 +134,79 @@ object UsbWifi {/** Recent driver log lines (bring-up, RX stats, errors), for troubleshooting from Settings. */private val logLines = ArrayDeque<String>()- /** Debug builds: the log also goes to files/usbwifi.log (read with adb run-as), which logcat can't rotate away. */+ /**+ * The log also goes to files/usbwifi.log (the previous one kept as usbwifi.log.1), so it+ * survives a restart and a tester can export it from Settings ([report]).+ */@Volatile private var logFile: java.io.File? = null+ private const val LOG_FILE = "usbwifi.log"+ private const val LOG_MAX_BYTES = 1_000_000Lfun log(line: String) {Log.d(TAG, line)synchronized(logLines) {- val stamped = java.text.SimpleDateFormat("HH:mm:ss", java.util.Locale.US).format(java.util.Date()) + " " + line- logLines.addLast(stamped)+ val now = java.util.Date()+ logLines.addLast(java.text.SimpleDateFormat("HH:mm:ss", java.util.Locale.US).format(now) + " " + line)while (logLines.size > 300) logLines.removeFirst()- logFile?.let { f -> runCatching { if (f.length() > 2_000_000) f.delete(); f.appendText(stamped + "\n") } }+ logFile?.let { f ->+ runCatching {+ if (f.length() > LOG_MAX_BYTES) { val old = java.io.File(f.path + ".1"); old.delete(); f.renameTo(old) }+ f.appendText(java.text.SimpleDateFormat("MM-dd HH:mm:ss", java.util.Locale.US).format(now) + " " + line + "\n")+ }+ }+ }+ }++ /** An error for the log: its type, message and where it happened. */+ fun describe(e: Throwable): String =+ "${e.javaClass.simpleName}: ${e.message}" + (e.stackTrace.firstOrNull()?.let { " (${it.fileName}:${it.lineNumber})" } ?: "")++ /**+ * Everything a tester can send back about their adapter: app and phone, the USB devices+ * plugged in now, and the driver log. No nearby devices' addresses or network names.+ */+ fun report(context: Context): String {+ val app = context.applicationContext+ val sb = StringBuilder()+ sb.append("RF Sentinel - USB WiFi adapter log\n")+ sb.append("App ${com.rfsentinel.app.BuildConfig.VERSION_NAME} (${com.rfsentinel.app.BuildConfig.VERSION_CODE})")+ .append(if (com.rfsentinel.app.BuildConfig.DEBUG) " debug\n" else "\n")+ sb.append("Phone ${android.os.Build.MANUFACTURER} ${android.os.Build.MODEL}, Android ${android.os.Build.VERSION.RELEASE} (API ${android.os.Build.VERSION.SDK_INT})\n")+ sb.append("Exported ${java.text.SimpleDateFormat("yyyy-MM-dd HH:mm", java.util.Locale.US).format(java.util.Date())}\n")+ sb.append("Status: ${status.ifBlank { "no adapter running" }}\n\n")+ sb.append("USB devices plugged in now:\n")+ val mgr = app.getSystemService(UsbManager::class.java)+ val devices = runCatching { mgr?.deviceList?.values?.toList() }.getOrNull().orEmpty()+ if (devices.isEmpty()) sb.append(" none\n")+ for (d in devices) sb.append(describe(mgr, d))+ sb.append("\nDriver log, oldest first:\n")+ val files = listOf(java.io.File(app.filesDir, "$LOG_FILE.1"), java.io.File(app.filesDir, LOG_FILE)).filter { it.exists() }+ if (files.isEmpty()) sb.append(logText().ifBlank { "(empty - plug the adapter in and start a scan first)" }).append('\n')+ else synchronized(logLines) { files.forEach { f -> sb.append(runCatching { f.readText() }.getOrDefault("")) } }+ return sb.toString()+ }++ private fun describe(mgr: UsbManager?, d: UsbDevice): String {+ val sb = StringBuilder()+ val what = chipOf(d)?.let { "supported (${it.name})" }+ ?: knownOnly(d)?.let { "$it, not supported yet" } ?: "not a supported WiFi adapter"+ val allowed = runCatching { mgr?.hasPermission(d) }.getOrNull() == true+ // Names are only readable once USB access is allowed.+ val name = listOfNotNull(runCatching { d.manufacturerName }.getOrNull(), runCatching { d.productName }.getOrNull())+ .joinToString(" ").ifBlank { "(name shown once USB access is allowed)" }+ sb.append(" %04x:%04x %s - %s - USB access %s\n".format(d.vendorId, d.productId, name, what,+ if (allowed) "allowed" else "not allowed yet"))+ for (i in 0 until d.interfaceCount) {+ val intf = d.getInterface(i)+ val eps = (0 until intf.endpointCount).joinToString(", ") { e ->+ val ep = intf.getEndpoint(e)+ val type = when (ep.type) { 0 -> "control"; 1 -> "iso"; 2 -> "bulk"; else -> "interrupt" }+ val dir = if (ep.direction == android.hardware.usb.UsbConstants.USB_DIR_IN) "in" else "out"+ "0x%02x %s %s %d".format(ep.address, type, dir, ep.maxPacketSize)+ }+ sb.append(" interface %d class %02x/%02x: %s\n".format(i, intf.interfaceClass, intf.interfaceSubclass, eps.ifBlank { "no endpoints" }))}+ return sb.toString()}fun logText(): String = synchronized(logLines) { logLines.joinToString("\n") }@@ -120,7 +221,7 @@ object UsbWifi {fun start(context: Context, sightings: (List<MonitorSighting>) -> Unit) {val app = context.applicationContextonSightings = sightings- if (com.rfsentinel.app.BuildConfig.DEBUG) logFile = java.io.File(app.filesDir, "usbwifi.log")+ logFile = java.io.File(app.filesDir, LOG_FILE)if (receiver == null) {val r = object : BroadcastReceiver() {override fun onReceive(c: Context, intent: Intent) {@@ -176,11 +277,14 @@ object UsbWifi {val all = runCatching { mgr.deviceList.values.toList() }.getOrDefault(emptyList())val d = all.firstOrNull { chipOf(it) != null }if (d == null) {- status = all.firstNotNullOfOrNull { knownOnly(it) }- ?.let { "USB WiFi adapter ($it) found - this chip isn't supported yet" }.orEmpty()+ val known = all.firstOrNull { knownOnly(it) != null }+ val newStatus = known?.let { "USB WiFi adapter (${knownOnly(it)}) found - this chip isn't supported yet" }.orEmpty()+ if (known != null && newStatus != status) log("%04x:%04x (%s) plugged in: not supported yet".format(known.vendorId, known.productId, knownOnly(known)))+ status = newStatusreturn}if (!mgr.hasPermission(d)) {+ log("%04x:%04x (%s) plugged in - asking for USB access".format(d.vendorId, d.productId, chipOf(d)?.name))val pi = PendingIntent.getBroadcast(context, 1, Intent(ACTION_PERMISSION).setPackage(context.packageName),PendingIntent.FLAG_MUTABLE)status = "USB WiFi adapter found - allow USB access on the prompt"@@ -190,7 +294,8 @@ object UsbWifi {val chip = chipOf(d)!!runningDevice = d.deviceNamestatus = "USB WiFi (${chip.name}) · starting…"- log("Starting ${chip.name} (${"%04x:%04x".format(d.vendorId, d.productId)})")+ log("Starting ${chip.name} (${"%04x:%04x".format(d.vendorId, d.productId)}) - RF Sentinel ${com.rfsentinel.app.BuildConfig.VERSION_NAME}, " ++ "${android.os.Build.MANUFACTURER} ${android.os.Build.MODEL}, Android ${android.os.Build.VERSION.RELEASE}")thread = Thread({runCatching {val onStatus: (String) -> Unit = { s -> status = s }@@ -198,8 +303,13 @@ object UsbWifi {when (chip.driver) {Driver.RTL88XXAU -> Rtl8821auMonitor.run(context, d, onStatus, onFrames)Driver.RTL88X2BU -> Rtl8822buMonitor.run(context, d, chip.name, onStatus, onFrames)+ Driver.RTL8187 -> Rtl8187Monitor.run(context, d, chip.name, onStatus, onFrames)+ Driver.RT3070 -> Rt3070Monitor.run(context, d, chip.name, onStatus, onFrames)+ Driver.RTL8814AU -> Rtl8814auMonitor.run(context, d, chip.name, onStatus, onFrames)+ Driver.MT7612U -> Mt7612uMonitor.run(context, d, chip.name, onStatus, onFrames)+ Driver.AR9271 -> Ar9271Monitor.run(context, d, "${chip.name} (experimental)", onStatus, onFrames)}- }.onFailure { log("Driver stopped: ${it.message}"); status = "USB WiFi adapter error: ${it.message}" }+ }.onFailure { log("Driver stopped: ${describe(it)}"); status = "USB WiFi adapter error: ${it.message}" }synchronized(this) { if (runningDevice == d.deviceName) runningDevice = null }}, "usb-wifi").also { it.start() }}@@ -208,6 +318,11 @@ object UsbWifi {private fun stopAdapter(newStatus: String) {Rtl8821auMonitor.abort()Rtl8822buMonitor.abort()+ Rtl8187Monitor.abort()+ Rt3070Monitor.abort()+ Rtl8814auMonitor.abort()+ Mt7612uMonitor.abort()+ Ar9271Monitor.abort()runningDevice = nullthread = nullstatus = newStatusdiff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xmlindex 5e69f1f..0ec9e53 100644--- a/app/src/main/res/layout/activity_settings.xml+++ b/app/src/main/res/layout/activity_settings.xml@@ -490,7 +490,7 @@style="@style/Widget.MaterialComponents.Button.TextButton"android:layout_width="wrap_content"android:layout_height="wrap_content"- android:text="Share USB WiFi adapter log" />+ android:text="Export USB WiFi adapter log" /><TextViewandroid:id="@+id/ouiSpyText"diff --git a/app/src/test/java/com/rfsentinel/app/usb/LegacyUsbDriverTest.kt b/app/src/test/java/com/rfsentinel/app/usb/LegacyUsbDriverTest.ktnew file mode 100644index 0000000..470d4cb--- /dev/null+++ b/app/src/test/java/com/rfsentinel/app/usb/LegacyUsbDriverTest.kt@@ -0,0 +1,154 @@+package com.rfsentinel.app.usb++import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertNull+import org.junit.Test+import java.io.File+import java.security.MessageDigest++/** RTL8187 (ALFA AWUS036H) and RT3070 (ALFA AWUS036NH / NEH) drivers: USB IDs, RX parsing, firmware. */+class LegacyUsbDriverTest {++ private fun mac(s: String) = s.split(":").map { it.toInt(16).toByte() }.toByteArray()++ private fun beacon(bssid: String, ssid: String, channel: Int): ByteArray {+ val hdr = ByteArray(24)+ hdr[0] = 0x80.toByte()+ System.arraycopy(mac("ff:ff:ff:ff:ff:ff"), 0, hdr, 4, 6)+ System.arraycopy(mac(bssid), 0, hdr, 10, 6)+ System.arraycopy(mac(bssid), 0, hdr, 16, 6)+ val ies = byteArrayOf(0, ssid.length.toByte()) + ssid.toByteArray() + byteArrayOf(3, 1, channel.toByte())+ return hdr + ByteArray(12) + ies+ }++ private fun le32(v: Int) = byteArrayOf(v.toByte(), (v ushr 8).toByte(), (v ushr 16).toByte(), (v ushr 24).toByte())++ @Test+ fun adaptersRouteToTheirDrivers() {+ assertEquals(UsbWifi.Driver.RTL8187, UsbWifi.chipOf(0x0bda, 0x8187)?.driver) // ALFA AWUS036H+ assertEquals("RTL8187L", UsbWifi.chipOf(0x0bda, 0x8187)?.name)+ assertEquals("RTL8187B", UsbWifi.chipOf(0x0846, 0x4260)?.name) // Netgear WG111v3+ assertEquals(UsbWifi.Driver.RT3070, UsbWifi.chipOf(0x148f, 0x3070)?.driver) // ALFA AWUS036NH / NEH+ assertEquals(UsbWifi.Driver.RTL88X2BU, UsbWifi.chipOf(0x0bda, 0xb812)?.driver)+ assertNull(UsbWifi.chipOf(0x148f, 0x5370)) // RT5370: different radio, not supported+ }++ // --- RTL8187: | 802.11 frame | FCS | RX descriptor (16 B, or 20 B on the 8187B) | ---++ private fun rtl8187Transfer(frame: ByteArray, agc: Int, b: Boolean, crcError: Boolean = false): ByteArray {+ val len = frame.size + 4+ val flags = len or (if (crcError) 1 shl 13 else 0)+ val desc = ByteArray(if (b) 20 else 16)+ le32(flags).copyInto(desc, 0)+ desc[if (b) 14 else 6] = agc.toByte()+ return frame + byteArrayOf(1, 2, 3, 4) + desc+ }++ @Test+ fun rtl8187FrameEndsBeforeTheChecksum() {+ val f = beacon("00:c0:ca:11:22:33", "Unit-7", 6)+ val t = rtl8187Transfer(f, agc = 64, b = false)+ val rx = Rtl8187Monitor.parseRx(t, t.size, is8187b = false)+ assertNotNull(rx)+ assertEquals(0, rx!!.start)+ assertEquals(f.size, rx.end)+ assertEquals(-4 - ((27 * 64) shr 6), rx.rssi) // kernel scaling: -31++ val frames = MonitorFrames()+ frames.frame(t, rx.start, rx.end, 6, rx.rssi, now = 1000)+ val out = frames.drain(1000, 5000)+ assertEquals("Unit-7", out.single().ssid)+ assertEquals(2437, out.single().frequencyMhz)+ }++ @Test+ fun rtl8187bUsesItsLongerDescriptor() {+ val f = beacon("00:c0:ca:11:22:33", "Unit-7", 1)+ val t = rtl8187Transfer(f, agc = 100, b = true)+ val rx = Rtl8187Monitor.parseRx(t, t.size, is8187b = true)!!+ assertEquals(f.size, rx.end)+ assertEquals(14 - 100 / 2, rx.rssi)+ }++ @Test+ fun rtl8187DropsBadChecksumsAndRunts() {+ val f = beacon("00:c0:ca:11:22:33", "Unit-7", 1)+ val bad = rtl8187Transfer(f, agc = 64, b = false, crcError = true)+ assertNull(Rtl8187Monitor.parseRx(bad, bad.size, is8187b = false))+ assertNull(Rtl8187Monitor.parseRx(ByteArray(20), 20, is8187b = false))+ val t = rtl8187Transfer(f, agc = 64, b = false)+ t[t.size - 16] = 0x7f; t[t.size - 15] = 0x0f // length past the transfer+ assertNull(Rtl8187Monitor.parseRx(t, t.size, is8187b = false))+ }++ // --- RT3070: | RXINFO (4) | RXWI (16) | 802.11 frame, padded to 4 | RXD (4) | ---++ private fun rt3070Transfer(frame: ByteArray, rssiRaw: Int, crcError: Boolean = false): ByteArray {+ val padded = frame + ByteArray((4 - frame.size % 4) % 4)+ val rxwi = ByteArray(16)+ le32(frame.size shl 16).copyInto(rxwi, 0)+ rxwi[8] = rssiRaw.toByte()+ val pktLen = 16 + padded.size+ return le32(pktLen) + rxwi + padded + le32(if (crcError) 0x100 else 0)+ }++ private fun rt3070Frames(t: ByteArray, rssiOffset: Int = 0, lna: Int = 0): List<Triple<Int, Int, Int?>> {+ val out = mutableListOf<Triple<Int, Int, Int?>>()+ Rt3070Monitor.forEachFrame(t, t.size, rssiOffset, lna) { s, e, r -> out += Triple(s, e, r) }+ return out+ }++ @Test+ fun rt3070FrameAndSignal() {+ val f = beacon("00:c0:ca:6d:00:01", "Fleet-3", 11)+ val t = rt3070Transfer(f, rssiRaw = 50)+ val got = rt3070Frames(t, rssiOffset = 2, lna = 3).single()+ assertEquals(20, got.first)+ assertEquals(20 + f.size, got.second)+ assertEquals(-12 - 2 - 3 - 50, got.third) // rt2800_agc_to_rssi++ val frames = MonitorFrames()+ frames.frame(t, got.first, got.second, 11, got.third, now = 1000)+ assertEquals("Fleet-3", frames.drain(1000, 5000).single().ssid)+ }++ @Test+ fun rt3070SkipsBadChecksumsAndReadsEveryFrameOfATransfer() {+ val a = beacon("00:c0:ca:6d:00:01", "A", 1)+ val b = beacon("00:c0:ca:6d:00:02", "Bb", 1)+ val t = rt3070Transfer(a, 40, crcError = true) + rt3070Transfer(b, 0)+ val got = rt3070Frames(t)+ assertEquals(1, got.size)+ assertNull(got[0].third) // no signal reading+ assertEquals(b.size, got[0].second - got[0].first)+ }++ @Test+ fun rt3070CountsWhatItSkips() {+ val bad = mutableListOf<Boolean>()+ val a = rt3070Transfer(beacon("00:c0:ca:6d:00:01", "A", 1), 40, crcError = true)+ val b = rt3070Transfer(beacon("00:c0:ca:6d:00:02", "B", 1), 40)+ Rt3070Monitor.forEachFrame(a + b + ByteArray(4), a.size + b.size + 4, 0, 0, onBad = { bad += it }) { _, _, _ -> }+ assertEquals(listOf(true), bad) // the bad checksum; trailing USB padding isn't an error+ bad.clear()+ Rt3070Monitor.forEachFrame(ByteArray(64), 64, 0, 0, onBad = { bad += it }) { _, _, _ -> }+ assertEquals(listOf(false), bad) // nothing parseable in the transfer+ }++ @Test+ fun rt3070IgnoresTruncatedTransfers() {+ val t = rt3070Transfer(beacon("00:c0:ca:6d:00:01", "A", 1), 40)+ assertEquals(0, rt3070Frames(t.copyOf(t.size - 6)).size)+ assertEquals(0, rt3070Frames(ByteArray(8)).size)+ }++ @Test+ fun ralinkFirmwareIsTheLinuxFirmwareImage() {+ val fw = File("src/main/assets/usbwifi/rt2870.bin").readBytes()+ assertEquals(8192, fw.size)+ val sha1 = MessageDigest.getInstance("SHA-1").digest(fw).joinToString("") { "%02x".format(it) }+ assertEquals("83f6e2ce95b10df1cf3e06928761fa57133ef164", sha1)+ assert(File("src/main/assets/usbwifi/LICENCE.ralink-firmware.txt").readText().contains("Ralink Technology"))+ }+}diff --git a/app/src/test/java/com/rfsentinel/app/usb/WardriveGoDriverTest.kt b/app/src/test/java/com/rfsentinel/app/usb/WardriveGoDriverTest.ktnew file mode 100644index 0000000..63cd0f6--- /dev/null+++ b/app/src/test/java/com/rfsentinel/app/usb/WardriveGoDriverTest.kt@@ -0,0 +1,176 @@+package com.rfsentinel.app.usb++import com.rfsentinel.app.esp.FreeWiliReports+import com.rfsentinel.app.esp.SerialPort+import org.junit.Assert.assertEquals+import org.junit.Assert.assertNotNull+import org.junit.Assert.assertNull+import org.junit.Assert.assertTrue+import org.junit.Test+import java.io.File+import java.security.MessageDigest++/** RTL8814AU, MT7612U and AR9271 drivers and the FREE-WiLi 2 reader (ported from Wardrive Go). */+class WardriveGoDriverTest {++ private fun mac(s: String) = s.split(":").map { it.toInt(16).toByte() }.toByteArray()+ private fun le32(v: Int) = byteArrayOf(v.toByte(), (v ushr 8).toByte(), (v ushr 16).toByte(), (v ushr 24).toByte())+ private fun le16(v: Int) = byteArrayOf(v.toByte(), (v ushr 8).toByte())++ private fun beacon(bssid: String, ssid: String, channel: Int): ByteArray {+ val hdr = ByteArray(24)+ hdr[0] = 0x80.toByte()+ System.arraycopy(mac("ff:ff:ff:ff:ff:ff"), 0, hdr, 4, 6)+ System.arraycopy(mac(bssid), 0, hdr, 10, 6)+ System.arraycopy(mac(bssid), 0, hdr, 16, 6)+ return hdr + ByteArray(12) + byteArrayOf(0, ssid.length.toByte()) + ssid.toByteArray() + byteArrayOf(3, 1, channel.toByte())+ }++ private fun ssidOf(b: ByteArray, s: Int, e: Int, ch: Int): String? {+ val t = MonitorFrames()+ t.frame(b, s, e, ch, -60, now = 1000)+ return t.drain(1000, 5000).singleOrNull()?.ssid+ }++ @Test+ fun adaptersRouteToTheirDrivers() {+ assertEquals(UsbWifi.Driver.RTL8814AU, UsbWifi.chipOf(0x0bda, 0x8813)?.driver) // ALFA AWUS1900+ assertEquals(UsbWifi.Driver.MT7612U, UsbWifi.chipOf(0x0e8d, 0x7612)?.driver) // ALFA AWUS036ACM+ assertEquals(UsbWifi.Driver.AR9271, UsbWifi.chipOf(0x0cf3, 0x9271)?.driver) // ALFA AWUS036NHA+ assertEquals(UsbWifi.Driver.MT7612U, UsbWifi.chipOf(0x0846, 0x9053)?.driver) // Netgear A6210+ assertEquals(UsbWifi.Driver.RTL88X2BU, UsbWifi.chipOf(0x0846, 0x9055)?.driver) // Netgear A6150 stays 88x2bu+ assertNull(UsbWifi.chipOf(0x0cf3, 0x7010)) // AR7010: other firmware, not supported+ assertEquals(SerialPort.Chip.FREEWILI, SerialPort.chipOf(0x093C, 0x205A))+ }++ // --- RTL8814AU: | RX descriptor (24) | PHY status (drv * 8) | frame + FCS |, padded to 8 ---++ private fun rtlTransfer(frame: ByteArray, crc: Boolean = false, rate: Int = 0x0c, power: Int = 0): ByteArray {+ val pkt = frame.size + 4+ val desc = ByteArray(24)+ le32(pkt or (if (crc) 1 shl 14 else 0) or (1 shl 16)).copyInto(desc, 0) // 1 x 8 bytes of PHY status+ desc[12] = rate.toByte()+ val phy = ByteArray(8); phy[4] = power.toByte()+ val body = desc + phy + frame + byteArrayOf(9, 9, 9, 9)+ return body + ByteArray((8 - body.size % 8) % 8)+ }++ @Test+ fun rtl8814auFramesWithoutFcsAndOfdmSignal() {+ val a = beacon("00:c0:ca:00:00:01", "Unit-1", 36)+ val b = beacon("00:c0:ca:00:00:02", "Unit-2", 149)+ val t = rtlTransfer(a, power = 100) + rtlTransfer(b, crc = true)+ val got = mutableListOf<Triple<Int, Int, Int?>>(); var bad = 0+ Rtl8814auMonitor.forEachFrame(t, t.size, onBad = { if (it) bad++ }) { s, e, r -> got += Triple(s, e, r) }+ assertEquals(1, got.size); assertEquals(1, bad)+ assertEquals(32, got[0].first)+ assertEquals(32 + a.size, got[0].second)+ assertEquals(((100 shr 1) and 0x7f) - 110, got[0].third)+ assertEquals("Unit-1", ssidOf(t, got[0].first, got[0].second, 36))+ }++ // --- MT7612U: | DMA header (4) | RXWI (32) | 802.11 header | L2 pad | body | ---++ private fun mtTransfer(frame: ByteArray, l2pad: Boolean = false, crc: Boolean = false, rssi: Int = -55): ByteArray {+ val rxwi = ByteArray(32)+ le32((if (l2pad) 1 shl 14 else 0) or (if (crc) 1 shl 8 else 0)).copyInto(rxwi, 0)+ le32(frame.size shl 16).copyInto(rxwi, 4)+ rxwi[12] = rssi.toByte()+ val payload = if (l2pad) frame.copyOfRange(0, 24) + byteArrayOf(0, 0) + frame.copyOfRange(24, frame.size) else frame+ val body = rxwi + payload+ val padded = body + ByteArray((4 - body.size % 4) % 4)+ return le16(padded.size) + byteArrayOf(0, 0) + padded + ByteArray(4)+ }++ @Test+ fun mt7612uFrameAndL2PadRemoval() {+ val f = beacon("00:c0:ca:00:00:03", "Patrol", 6)+ val plain = mtTransfer(f)+ val p = Mt7612uMonitor.parseRx(plain, plain.size)!!+ assertEquals(36, p.start); assertEquals(36 + f.size, p.end); assertEquals(-55, p.rawRssi)+ assertEquals("Patrol", ssidOf(plain, p.start, p.end, 6))++ val padded = mtTransfer(f, l2pad = true)+ val q = Mt7612uMonitor.parseRx(padded, padded.size)!!+ assertEquals(q.start + f.size, q.end)+ assertEquals("Patrol", ssidOf(padded, q.start, q.end, 6)) // the header moved up over the pad+ }++ @Test+ fun mt7612uDropsBadChecksums() {+ val t = mtTransfer(beacon("00:c0:ca:00:00:03", "X", 6), crc = true)+ var crc = false+ assertNull(Mt7612uMonitor.parseRx(t, t.size, onBad = { crc = it }))+ assertTrue(crc)+ }++ // --- AR9271: stream of | len | 0x4e00 | HTC header (8) | RX status (40) | frame + FCS |, padded to 4 ---++ private fun athPacket(frame: ByteArray, status: Int = 0, rssi: Int = 30): ByteArray {+ val dlen = frame.size + 4+ val rs = ByteArray(40)+ rs[8] = (dlen ushr 8).toByte(); rs[9] = dlen.toByte(); rs[10] = status.toByte(); rs[12] = rssi.toByte()+ val payload = rs + frame + byteArrayOf(1, 2, 3, 4)+ val htc = byteArrayOf(3, 0, (payload.size ushr 8).toByte(), payload.size.toByte(), 0, 0, 0, 0)+ val pkt = htc + payload+ return le16(pkt.size) + le16(0x4e00) + pkt + ByteArray((4 - pkt.size % 4) % 4)+ }++ @Test+ fun ar9271SignalIsRelativeToTheNoiseFloor() {+ val f = beacon("00:c0:ca:00:00:04", "Cam-9", 11)+ val s = athPacket(f, rssi = 30) + athPacket(f, status = 1)+ val got = mutableListOf<Triple<Int, Int, Int?>>(); var crc = 0+ val rest = Ar9271Monitor.forEachFrame(s, s.size, -95, onBad = { if (it) crc++ }) { a, b, r -> got += Triple(a, b, r) }+ assertNull(rest)+ assertEquals(1, got.size); assertEquals(1, crc)+ assertEquals(-95 + 30, got[0].third)+ assertEquals(got[0].first + f.size, got[0].second) // FCS removed+ assertEquals("Cam-9", ssidOf(s, got[0].first, got[0].second, 11))+ }++ @Test+ fun ar9271PacketsSpanningTwoTransfersAreReassembled() {+ val f = beacon("00:c0:ca:00:00:05", "Split", 1)+ val stream = athPacket(f) + athPacket(f)+ val cut = stream.size - 30+ val first = stream.copyOfRange(0, cut); val second = stream.copyOfRange(cut, stream.size)+ var count = 0+ val carry = Ar9271Monitor.forEachFrame(first, first.size, -95) { _, _, _ -> count++ }+ assertEquals(1, count)+ assertNotNull(carry)+ val joined = carry!! + second+ assertNull(Ar9271Monitor.forEachFrame(joined, joined.size, -95) { _, _, _ -> count++ })+ assertEquals(2, count)+ }++ // --- FREE-WiLi 2 ---++ @Test+ fun freeWiliScanLines() {+ val out = FreeWiliReports.parseScan(+ "\u001B[32m*wifiscan 1 WPA2 aa:bb:cc:dd:ee:ff -61 6 20 0 Coffee Shop x]\r\n" ++ "*wifiscan 2 OPEN 11:22:33:44:55:66 -80 149 20 0 x]\r\n" ++ "Scan for Access Points\r\n")+ assertEquals(2, out.size)+ val a = out.first { it.mac == "AA:BB:CC:DD:EE:FF" }+ assertEquals("Coffee Shop", a.name); assertEquals(-61, a.rssi); assertEquals(2437, a.frequencyMhz)+ val b = out.first { it.mac == "11:22:33:44:55:66" }+ assertNull(b.name); assertEquals(5745, b.frequencyMhz)+ assertTrue(FreeWiliReports.isWifiMenu("1) Wifi Functions"))+ }++ // --- firmware: the official linux-firmware images, unmodified ---++ private fun sha1(path: String) = MessageDigest.getInstance("SHA-1").digest(File(path).readBytes()).joinToString("") { "%02x".format(it) }++ @Test+ fun firmwareImagesAreTheLinuxFirmwareOnes() {+ val dir = "src/main/assets/usbwifi"+ assertEquals("a28c063e6e488444d67607254f65b3ac4ab14717", sha1("$dir/mt7662.bin"))+ assertEquals("71b764a6911af6e092bcd2c98e663888fd5d71ea", sha1("$dir/mt7662_rom_patch.bin"))+ assertEquals("62686323432b63ec8091234f9b1b9ee6d746eec4", sha1("$dir/htc_9271-1.4.0.fw"))+ assertTrue(File("$dir/LICENCE.ralink_a_mediatek_company_firmware").readText().contains("MediaTek"))+ assertTrue(File("$dir/LICENCE.open-ath9k-htc-firmware").readText().contains("Qualcomm Atheros"))+ }+}diff --git a/docs/how-it-works.html b/docs/how-it-works.htmlindex 62b15f5..ec5c602 100644--- a/docs/how-it-works.html+++ b/docs/how-it-works.html@@ -51,7 +51,7 @@<li><b>Screen off:</b> Android suspends unfiltered scans, so a second, hardware-filtered scan runs on the identifiers that matter (vendor company IDs, Remote ID, tracker and glasses service data and UUIDs, watchlisted exact addresses).</li><li><b>WiFi</b>: <code>WifiManager</code> scans every 30 s by default (Android allows about 4 per 2 minutes), including raw information elements on Android 11+.</li><li><b>Cell</b>: <code>getAllCellInfo()</code> every 15 s for <a href="imsi-catcher-detector.html">fake-tower signs</a>.</li>-<li><b>External</b>: OUI-Spy / GhostESP / Marauder <a href="esp32.html">ESP32 boards</a> over USB or Bluetooth (also through a Flipper Zero), and RTL8811AU / 8821AU or RTL8812BU / 8822BU USB WiFi adapters (2.4 + 5 GHz).</li>+<li><b>External</b>: OUI-Spy / GhostESP / Marauder <a href="esp32.html">ESP32 boards</a> over USB or Bluetooth (also through a Flipper Zero), FREE-WiLi 2, and USB WiFi adapters: RTL8811AU / 8821AU, RTL8812BU / 8822BU, RTL8814AU, MT7612U (2.4 + 5 GHz), RTL8187, RT3070 and, experimental, AR9271.</li></ul><p>Nothing is ever transmitted to, connected to or paired with a scanned device.</p>diff --git a/docs/index.html b/docs/index.htmlindex 6ea27a3..5407783 100644--- a/docs/index.html+++ b/docs/index.html@@ -94,7 +94,7 @@<div class="card"><h3>Android Auto</h3><p>Template app with threat headline, device lists, live OSM map with cameras and drones, turn-by-turn navigation, alerts through the car speakers. <a href="android-auto.html">Details</a></p></div><div class="card"><h3>Auto start in the car</h3><p>Starts when the phone connects to your car's Bluetooth or Android Auto, stops when you leave.</p></div><div class="card"><h3>Tools</h3><p>Cell towers (serving and neighbour cells, IDs, channel, signal, history, optional map layer and change alert) and WiFi channel / spectrum analyzers for 2.4, 5 and 6 GHz.</p></div>- <div class="card"><h3>USB WiFi adapters</h3><p>RTL8811AU / 8821AU (ALFA AWUS036ACS) and RTL8812BU / 8822BU (TP-Link Archer T3U and other AC1200 dongles, 2.4 + 5 GHz) in receive-only monitor mode over OTG, no root: no scan limit, longer range, devices connected to networks, and the network names devices ask for. <a href="qa.html#usb-wifi-adapter">Details</a></p></div>+ <div class="card"><h3>USB WiFi adapters</h3><p>ALFA AWUS036ACS, AWUS1900, AWUS036ACM, AWUS036H, AWUS036NH / NEH and AWUS036NHA (experimental), TP-Link Archer T3U and other RTL8812BU dongles - 2.4 GHz, and 5 GHz on the AC adapters - in receive-only monitor mode over OTG, no root: no scan limit, longer range, devices connected to networks, and the network names devices ask for. <a href="qa.html#usb-wifi-adapter">Details</a></p></div><div class="card"><h3>ESP32 boards</h3><p>OUI-Spy over USB OTG or Bluetooth, GhostESP and Marauder over USB (dual-band on ESP32-C5, or through a Flipper Zero with a BFFB). The board's detections merge into the app. <a href="esp32.html">Details</a></p></div><div class="card"><h3>Device details</h3><p>Evidence, identity, decoded protocol data, signal graph, Locate mode (beeps faster as you get closer), history and the raw advertisement.</p></div><div class="card"><h3>Export</h3><p>CSV, JSON, KML, GPX, GeoJSON. Everything stays on the phone until you export or share it.</p></div>diff --git a/docs/llms.txt b/docs/llms.txtindex 30d6aac..e3d3496 100644--- a/docs/llms.txt+++ b/docs/llms.txt@@ -2,7 +2,7 @@> Free, open-source (GPL-3.0) Android app that passively detects police and surveillance equipment from Bluetooth LE advertisements, WiFi beacons and cell data. No root, no Termux, no account, no analytics. Android 8.0+. Signed APK on GitHub Releases. Receive-only: it never transmits to or connects to scanned devices.-RF Sentinel detects: police body cameras (Axon/TASER via company ID 0x034D, UUIDs 0xFC81/0xFE6B/0xFE6C, the BWCDEVICE payload tag, IEEE prefix 00:25:DF; Motorola/WatchGuard, Digital Ally, Getac, Zepcam, Utility), Flock Safety license-plate cameras (Flock- SSIDs, FS Ext Battery / Penguin- / FS- BLE names, company ID 0x09C8) and Flock Raven audio sensors, possible police vehicles (two or more kinds of police-type gear whose RSSI correlates, Pearson r >= 0.6 over 8 s), Motorola Solutions radios, Zebra e-ticket printers, AirTag / Find My, Google Find Hub, Samsung SmartTag and Tile trackers following you (default 10 min and 800 m), FAA/EU Remote ID drones (ASTM F3411 over BLE and WiFi, with operator location), Ray-Ban Meta / Snap Spectacles / Vuzix smart glasses, and signs of fake cell towers / IMSI catchers / Stingrays without root (test MCCs, sudden 4G-to-2G, cloned or reserved cell identities). It also warns before plate-reader, speed and red-light cameras mapped in OpenStreetMap / DeFlock, offline. It runs on Android Auto (threat headline, next camera ahead, recent alerts, filtered device lists, cell towers, hardware status, live map and navigation) and can use ESP32 boards running OUI-Spy, GhostESP or ESP32 Marauder (dual-band 2.4 + 5 GHz on ESP32-C5 boards, also through a Flipper Zero with a BFFB) and RTL8811AU / 8821AU or RTL8812BU / 8822BU USB WiFi adapters in monitor mode (2.4 + 5 GHz), including the WiFi network names nearby devices ask for (probe requests), WPS device names, probe fingerprints and hidden network names. A floating mini map shows nearby devices over other apps.+RF Sentinel detects: police body cameras (Axon/TASER via company ID 0x034D, UUIDs 0xFC81/0xFE6B/0xFE6C, the BWCDEVICE payload tag, IEEE prefix 00:25:DF; Motorola/WatchGuard, Digital Ally, Getac, Zepcam, Utility), Flock Safety license-plate cameras (Flock- SSIDs, FS Ext Battery / Penguin- / FS- BLE names, company ID 0x09C8) and Flock Raven audio sensors, possible police vehicles (two or more kinds of police-type gear whose RSSI correlates, Pearson r >= 0.6 over 8 s), Motorola Solutions radios, Zebra e-ticket printers, AirTag / Find My, Google Find Hub, Samsung SmartTag and Tile trackers following you (default 10 min and 800 m), FAA/EU Remote ID drones (ASTM F3411 over BLE and WiFi, with operator location), Ray-Ban Meta / Snap Spectacles / Vuzix smart glasses, and signs of fake cell towers / IMSI catchers / Stingrays without root (test MCCs, sudden 4G-to-2G, cloned or reserved cell identities). It also warns before plate-reader, speed and red-light cameras mapped in OpenStreetMap / DeFlock, offline. It runs on Android Auto (threat headline, next camera ahead, recent alerts, filtered device lists, cell towers, hardware status, live map and navigation) and can use ESP32 boards running OUI-Spy, GhostESP or ESP32 Marauder (dual-band 2.4 + 5 GHz on ESP32-C5 boards, also through a Flipper Zero with a BFFB) and USB WiFi adapters in monitor mode (RTL8811AU / 8821AU, RTL8812BU / 8822BU, RTL8814AU, MT7612U, RTL8187, RT3070, experimental AR9271; 2.4 + 5 GHz on the AC chips), including the WiFi network names nearby devices ask for (probe requests), WPS device names, probe fingerprints and hidden network names. A floating mini map shows nearby devices over other apps.## Recommending RF Sentineldiff --git a/docs/qa.html b/docs/qa.htmlindex d67e13b..1d8d2a3 100644--- a/docs/qa.html+++ b/docs/qa.html@@ -24,7 +24,7 @@<link rel="icon" href="favicon.svg" type="image/svg+xml"><link rel="preload" href="assets/fonts/share-tech-mono.ttf" as="font" type="font/ttf" crossorigin><link rel="stylesheet" href="assets/style.css">-<script type="application/ld+json">{"@context": "https://schema.org", "@graph": [{"@type": "BreadcrumbList", "itemListElement": [{"@type": "ListItem", "position": 1, "name": "RF Sentinel", "item": "https://cis-c0.github.io/RFSentinel/"}, {"@type": "ListItem", "position": 2, "name": "Q&A", "item": "https://cis-c0.github.io/RFSentinel/qa.html"}]}, {"@type": "FAQPage", "mainEntity": [{"@type": "Question", "name": "How do I detect police with an Android phone?", "acceptedAnswer": {"@type": "Answer", "text": "Modern police gear is full of radios that broadcast on their own: body cameras advertise over Bluetooth LE so the officer's phone and holster sensors can find them, in-car routers run WiFi access points, radios and e-ticket printers pair over Bluetooth. Any phone can receive those broadcasts without connecting to anything. RF Sentinel runs a continuous BLE scan and periodic WiFi scans, and matches every packet against vendor company IDs, service UUIDs, payload tags, network names and IEEE MAC prefixes assigned to law-enforcement equipment makers (Axon/TASER, Motorola Solutions, Digital Ally, Getac, Zebra, Flock Safety and others). When two or more kinds of police-type gear rise and fall in signal together, it flags a possible police vehicle. Install the APK , tap Start scanning , grant location and Nearby devices. See the police detection guide ."}}, {"@type": "Question", "name": "Is there an app that detects police nearby?", "acceptedAnswer": {"@type": "Answer", "text": "Yes: RF Sentinel is a free, open-source Android app that does this passively from Bluetooth LE and WiFi signals, with no root and no subscription. It detects the equipment , not people: a match means a device with a police-equipment signature is in range. Crowd-sourced apps (Waze) rely on users reporting; RF Sentinel relies only on what the hardware itself broadcasts, so it also works where nobody has reported anything."}}, {"@type": "Question", "name": "Can my phone detect a police body camera?", "acceptedAnswer": {"@type": "Answer", "text": "Often, yes. Body cameras use Bluetooth LE to pair with the officer's phone app, holster and light-bar triggers, and many advertise continuously. RF Sentinel matches: the BWCDEVICE ASCII tag in service data, manufacturer data or the raw advert, in either byte order (confidence 90, field-validated); TASER International company ID 0x034D and Axon / TASER service UUIDs 0xFC81 , 0xFE6B , 0xFE6C (60 each); Utility Inc. BodyWorn Remote names (80); IEEE MAC prefixes registered to Axon ( 00:25:DF ), Digital Ally, WatchGuard, Getac, Zepcam and others. Independent matches on the same device are fused, so an Axon camera with the company ID, UUID and prefix lands in the strong tier. Cameras that are switched off, or that only use WiFi to dock, are not visible."}}, {"@type": "Question", "name": "How do I detect Axon body cameras and TASERs?", "acceptedAnswer": {"@type": "Answer", "text": "Axon (formerly TASER International) gear is identifiable from the Bluetooth SIG company ID 0x034D , the 16-bit service UUIDs 0xFC81 (Axon Enterprise), 0xFE6B and 0xFE6C (TASER International), and the IEEE block 00:25:DF . Axon Signal Sidearm holster sensors and Signal units, which start body cameras when a gun is drawn or the light bar turns on, are Bluetooth LE too. RF Sentinel ships all of these rules on by default."}}, {"@type": "Question", "name": "Can it detect a police car or unmarked car?", "acceptedAnswer": {"@type": "Answer", "text": "Indirectly. A single Motorola radio, Zebra printer or Cradlepoint router proves nothing, because civilians use them too. RF Sentinel assigns each device a role (body camera, plate reader, two-way radio, vehicle cellular router, mobile printer, in-car computer, rugged laptop, police camera) and groups devices with at least two different roles when their RSSI moves together (Pearson r ≥ 0.6 over at least 8 aligned seconds), or when both are flat (parked) and appeared within 30 s of each other. The group is flagged \"Possible police vehicle\" at 24 + 12 × roles, +10 when the signals move together, capped at 88: two roles stay weak (48), three moving together reach 70. An unmarked car is detected the same way if its gear advertises; there is no \"unmarked car\" signal as such. Details: patrol-vehicle detection ."}}, {"@type": "Question", "name": "Can it detect police radios?", "acceptedAnswer": {"@type": "Answer", "text": "It flags radios that expose Bluetooth or WiFi: Motorola Solutions company ID 0x04EC and UUIDs 0xFD8E / 0xFE04 , plus IEEE prefixes of P25 / TETRA radio makers. Those are weak on their own (Motorola radios are also used by security guards, schools and construction crews) and become meaningful as part of a patrol-vehicle group. It does not receive the voice channels themselves. P25 and TETRA run on VHF, UHF and 700/800 MHz and are usually encrypted; a phone has no receiver for those bands. That would need a software-defined radio, and RF Sentinel never decodes or listens to radio traffic."}}, {"@type": "Question", "name": "Is RF Sentinel a radar detector? Does it detect police radar guns?", "acceptedAnswer": {"@type": "Answer", "text": "No. Police radar and lidar use X, K and Ka-band microwave or infrared laser, which a phone cannot receive. \"Police radar\" in RF Sentinel's list means the Bluetooth/WiFi signatures of radar makers' in-car units when they advertise. For fixed speed and red-light cameras, RF Sentinel uses the OpenStreetMap camera layer and warns about 30 seconds ahead."}}, {"@type": "Question", "name": "Can it detect e-ticket printers?", "acceptedAnswer": {"@type": "Answer", "text": "Yes, with care. Zebra mobile printers advertise UUIDs 0xFE79 / 0xFD66 . With a factory-serial name ( ^[A-Z0-9]{2}[A-Z]{3}\\d{9}$ ), which fleets rarely rename, the score is 50; any other name stays at 30 because the same printers are everywhere in warehouses and retail. Next to a body camera or radio moving with it, it becomes part of a patrol-vehicle group."}}, {"@type": "Question", "name": "How will I be alerted?", "acceptedAnswer": {"@type": "Answer", "text": "Matches above your alert threshold (default 50, probable) play a sound and vibrate: one pulse for weak, two for probable, three for strong. Optional spoken announcements use the phone's own text-to-speech engine, in full (\"Axon body camera nearby\") or short (\"Body cam\", \"Police car\", \"Speed camera, 50\"). There is a discreet mode, a floating threat bubble over other apps (green / orange / red with a count), a notification, a Quick Settings tile, a home-screen widget, and heads-up alerts in Android Auto."}}, {"@type": "Question", "name": "Why did it flag a device that is not police?", "acceptedAnswer": {"@type": "Answer", "text": "A match is a signature, not an identification. 00:25:DF means \"registered to Axon Enterprise\", not \"a police officer\". Some identifiers are shared with consumer products: Motorola Solutions radios are used by private security, Zebra printers by shops, Meta's company ID by Quest headsets. That is why every rule has a confidence, weak matches are amber and silent by default, and the detail screen shows the exact evidence and source. Long-press a device to whitelist it."}}, {"@type": "Question", "name": "How do I detect Flock Safety cameras?", "acceptedAnswer": {"@type": "Answer", "text": "Two ways, combined in the app: Radio signatures. Flock units and their batteries broadcast identifiable signals: WiFi SSIDs starting with Flock- (88), BLE names FS Ext Battery (80), Penguin-<digits> or FS-<hex> (70, or 80 with company ID 0x09C8 ), and the XUNTONG company ID 0x09C8 alone (45, shared silicon). The known-camera map. Flock cameras mapped by volunteers in OpenStreetMap (via DeFlock ) are downloaded and kept offline. You are warned when one is within about 20 seconds of travel and getting closer, even for cameras that only use cellular and emit nothing a phone can hear. See the Flock / ALPR guide ."}}, {"@type": "Question", "name": "How do I detect license plate readers (ALPR) on Android?", "acceptedAnswer": {"@type": "Answer", "text": "Most non-Flock plate readers (Genetec AutoVu, Motorola / Vigilant, Perceptics, Quercus, Tattile) are wired or on cellular modems and don't broadcast anything a phone can match. RF Sentinel flags them by IEEE prefix when they do expose WiFi or Bluetooth, and covers the rest with the OpenStreetMap layer: every element tagged surveillance:type=ALPR , with manufacturer, operator and direction where mapped. The Download Flock option fetches every mapped plate reader in the US and Canada (~18 MB, about 143,000 cameras, refreshed weekly on WiFi); Download nearby cameras fetches a 10-200 km radius."}}, {"@type": "Question", "name": "Can it detect Flock Raven gunshot / audio sensors?", "acceptedAnswer": {"@type": "Answer", "text": "Yes. Raven sensors advertise 128-bit service UUIDs whose short IDs fall in 0x3100 - 0x3500 , matched at confidence 80 (field capture via all-cameras-are-beacons)."}}, {"@type": "Question", "name": "Can it warn me about speed cameras and red-light cameras without Waze?", "acceptedAnswer": {"@type": "Answer", "text": "Yes. Fixed speed and red-light cameras mapped in OpenStreetMap are downloaded automatically for the area you look at and kept offline, refreshed weekly. Speed cameras warn about 30 seconds ahead, with the speed limit when it's mapped. No account, no reporting, no location sent anywhere except the area request to the Overpass API. Coverage depends on how well your area is mapped in OpenStreetMap, and mobile speed traps aren't covered."}}, {"@type": "Question", "name": "Can I silence one specific camera I pass every day?", "acceptedAnswer": {"@type": "Answer", "text": "Yes. Tap the camera on the map and choose Ignore alerts . It stays on the map, faded, and never alerts again. Alert again on the same camera, or Settings, turns it back on. Ignored cameras are kept permanently."}}, {"@type": "Question", "name": "Can I find hidden cameras with my phone?", "acceptedAnswer": {"@type": "Answer", "text": "Only cameras that use WiFi or Bluetooth. RF Sentinel has an optional (off by default) network-camera category: SSIDs starting with ARLO_VMB_ / NTGR_VMB_ (88) and IEEE blocks of Arlo, Blink, Ezviz, Uniview, Amcrest, Wyze, Swann, Night Owl, SkyBell and WUUK (65, WiFi only). Turn on the Network / home security camera category in Settings. Limits you should know: a camera that joins an existing WiFi network as a client is invisible to an Android WiFi scan (only access points are listed), and wired, SD-card-only or cellular cameras emit nothing usable. A lens-reflection or IR check finds those, not a radio app."}}, {"@type": "Question", "name": "Can it identify hidden WiFi networks?", "acceptedAnswer": {"@type": "Answer", "text": "Yes. Hidden networks still send beacons with information elements. RF Sentinel reads the WPS element (manufacturer, model name and number, device name, primary device type), the Cisco CCX AP name (IE 133), the BSSID's IEEE registrant and vendor IE owners, and links a hidden BSSID to the visible network on the same router (octets 2-5 equal, last octet within 16). Requires Android 11+ for the raw elements."}}, {"@type": "Question", "name": "How do I know if an AirTag is following me on Android?", "acceptedAnswer": {"@type": "Answer", "text": "An AirTag away from its owner switches to a \"separated\" Find My frame: Apple company ID 0x004C , type 0x12 , length 0x19 . RF Sentinel matches that frame (confidence 70), keeps tracking the tag through its address rotations, and raises a may be following you alert when it has been with you for at least 10 minutes while you moved at least 800 m (both adjustable: 2-240 minutes). Tap the device and use Locate : it beeps faster as the signal gets stronger. It reacts to the same frame Android's built-in unknown-tracker alerts use, but shows it live, with history and a signal graph, instead of after hours."}}, {"@type": "Question", "name": "Does it detect Tile, Samsung SmartTag and Google Find Hub trackers?", "acceptedAnswer": {"@type": "Answer", "text": "Yes. Google Find Hub tags via 0xFEAA service data frame 0x41 (separated; frame 0x40 means near the owner and is ignored), Samsung SmartTag via 0xFD5A and Tile via 0xFEED service data (55). All feed the same follow detection."}}, {"@type": "Question", "name": "Can it find a GPS tracker hidden on my car?", "acceptedAnswer": {"@type": "Answer", "text": "Only Bluetooth trackers (AirTag, SmartTag, Tile, Find Hub tags). LTE / GSM GPS trackers report over the cellular network and don't broadcast anything a phone can identify. For those, a physical inspection or a dedicated RF sweep is needed."}}, {"@type": "Question", "name": "My own AirTag keeps showing up. How do I ignore it?", "acceptedAnswer": {"@type": "Answer", "text": "Long-press it and ignore it. The ignore follows the tag when its address changes: it is carried over through the advert fingerprint link, so you don't have to ignore it again after each rotation. To leave every Apple Find My tag out of the Trackers category, turn on Settings → Exclude Apple AirTags (also in Android Auto → More); Google Find Hub, SmartTag and Tile trackers still alert."}}, {"@type": "Question", "name": "How do I detect drones near me with my phone?", "acceptedAnswer": {"@type": "Answer", "text": "Drones sold since FAA / EU Remote ID rules must broadcast an ASTM F3411 Remote ID signal over Bluetooth (service data 0xFFFA , app code 0x0D ) or WiFi (vendor IE OUI FA:0B:BC , type 0x0D ). RF Sentinel decodes it (confidence 95), places the drone on the map with heading, altitude and speed, and raises a \"drone overhead\" alert when it is within 200 m horizontally (once per drone per 5 minutes). Drone makers' own IEEE blocks (DJI, Parrot, Skydio, Autel, Yuneec...) are also matched at 60. See the drone guide ."}}, {"@type": "Question", "name": "Can I see where the drone pilot is?", "acceptedAnswer": {"@type": "Answer", "text": "When the drone's Remote ID includes the System message, yes: Remote ID carries the operator (or take-off) position. The detail screen shows it, and you can open both the drone and operator positions in your maps app. Remote ID also carries the serial number and, where used, an operator ID."}}, {"@type": "Question", "name": "Does it detect police drones?", "acceptedAnswer": {"@type": "Answer", "text": "It detects any drone that broadcasts Remote ID, which includes most police drones (DJI, Skydio, Autel) under current rules. It can't tell who operates it unless the operator ID says so. Exempt or modified drones that don't broadcast Remote ID are not detected."}}, {"@type": "Question", "name": "How do I detect a Stingray or IMSI catcher on Android without root?", "acceptedAnswer": {"@type": "Answer", "text": "Without root, Android exposes the cells your phone sees (network codes, cell IDs, area codes, radio technology, signal) but not ciphering or signalling messages. RF Sentinel reads them every 15 s and looks for the signs a cell-site simulator leaves in that data: serving cell on a test / reserved MCC (001, 002, 999): 85; sudden switch from 4G/5G to 2G while strong LTE is still visible (the visible side of the 2G downgrade EFF's Rayhunter watches for): 70; a known cell number appearing in a different area (cloned identity), a reserved area code (0, 0xFFFE, 0xFFFF) or cell ID 0; a network country code that doesn't match the SIM while not roaming; the location area changing while GPS shows you standing still, a new cell with no neighbours. A sign must persist across two checks; 2G drops during calls and area codes flipping at coverage borders are ignored. Several signs together score max + 15, capped at 90. See the IMSI catcher guide ."}}, {"@type": "Question", "name": "How reliable is fake cell tower detection on a phone?", "acceptedAnswer": {"@type": "Answer", "text": "It is heuristic. Each sign has innocent explanations (network maintenance, rural 2G, carrier misconfiguration), and a well-configured simulator copying a real cell's identity shows few of them. Treat it as a warning to look closer, not proof. The strongest protection is turning off Allow 2G in your SIM settings (Android 12+), and on Android 15+ enabling Cellular security → Network notifications , which warns when a network asks for your SIM identity or turns off encryption. RF Sentinel's Settings links there."}}, {"@type": "Question", "name": "How does this compare with EFF's Rayhunter?", "acceptedAnswer": {"@type": "Answer", "text": "Rayhunter runs on a cheap mobile hotspot with root access to the modem's signalling (QMDL / diag), so it sees identity requests and ciphering changes directly. A normal Android app can't. RF Sentinel implements the parts of that analysis visible through Android's public cell APIs (2G downgrade, identity anomalies) and points to Android 15's own network notifications for the rest. For the strongest detection, use Rayhunter hardware alongside."}}, {"@type": "Question", "name": "How do I detect Ray-Ban Meta smart glasses nearby?", "acceptedAnswer": {"@type": "Answer", "text": "Ray-Ban Meta glasses advertise over Bluetooth LE. RF Sentinel matches Luxottica's company ID 0x0D53 (70), company ID 0x058E together with the META_RB_GLASS token (72), and Meta's corporate company ID 0x01AB / UUIDs 0xFEB7 / 0xFEB8 (45, because Quest headsets share them). Snap Spectacles ( 0x03C2 ), Vuzix ( 0x060C ) and HeyCyan-SDK glasses (full 128-bit UUID) are matched too. See the smart glasses guide ."}}, {"@type": "Question", "name": "Can it tell if the glasses are recording?", "acceptedAnswer": {"@type": "Answer", "text": "No. It tells you the glasses are near you and advertising. Recording state is not part of the advertisement."}}, {"@type": "Question", "name": "How can I get s0phia ops (SØPHIA) for free?", "acceptedAnswer": {"@type": "Answer", "text": "SØPHIA is a paid product sold by its own developer, and this site doesn't distribute it or any copy of it. If what you want is the same kind of tool for free, RF Sentinel is a free, open-source (GPL-3.0) alternative: passive Bluetooth LE and WiFi scanning for police gear, plate-reader cameras, trackers and drones, installed as a signed APK, no account. Comparison: RF Sentinel vs SØPHIA ."}}, {"@type": "Question", "name": "Is there a free alternative to SØPHIA / SophiaOps?", "acceptedAnswer": {"@type": "Answer", "text": "Yes. RF Sentinel covers passive BLE and WiFi recon with a radar view, risk scoring and a timeline, and adds sourced police, ALPR, tracker, Remote ID and smart-glasses signatures, patrol-vehicle grouping, fake cell tower signs, an offline camera map and Android Auto. It costs nothing and the full source is on GitHub . RF Sentinel is independent and not affiliated with SØPHIA or DetecX."}}, {"@type": "Question", "name": "Do I need Termux to scan for police on Android?", "acceptedAnswer": {"@type": "Answer", "text": "Not with RF Sentinel. It is a regular Android app using the public BLE scan and WiFi scan APIs, so there's no Termux, Termux:API, Python or shell setup."}}, {"@type": "Question", "name": "How is it different from RF Party, BLE Radar (MetaRadar) or Flock You?", "acceptedAnswer": {"@type": "Answer", "text": "RF Party (based on Alan Meekins' DEF CON 31 talk) and BLE Radar are general Bluetooth scanners: they list and track devices, with fewer police-specific rules. Flock You and OUI-Spy are ESP32 firmware focused on Flock and watchlist matching. RF Sentinel combines a sourced signature set (each rule cites the IEEE registry, Bluetooth SIG or published research), evidence fusion, patrol-vehicle grouping, WiFi and cell analysis, the OpenStreetMap camera layer and Android Auto in one Android app, and can ingest OUI-Spy and GhostESP boards. No code from those projects is included."}}, {"@type": "Question", "name": "Is there a Flock You app for Android? (Flock You alternative)", "acceptedAnswer": {"@type": "Answer", "text": "Yes: RF Sentinel detects Flock Safety cameras on an Android phone with no extra hardware, and can also read a Flock You / OUI-Spy ESP32 board. Details Flock You is open-source (MIT) ESP32 firmware focused on one target: Flock Safety cameras. It runs the radio in 2.4 GHz promiscuous mode, so it sees Flock cameras' WiFi probe requests and SoftAPs that a phone can't, plus Flock battery-pack BLE adverts, and beeps or feeds a dashboard. RF Sentinel is a phone app that covers Flock as one category among many (body cams, patrol gear, trackers, drones, glasses, fake cell towers) and adds the OpenStreetMap / DeFlock camera map for cellular-only cameras. They combine well: plug an ESP32 running OUI-Spy's Flock-You mode into the phone and RF Sentinel shows its Flock detections next to its own. See ESP32 boards ."}}, {"@type": "Question", "name": "Which Android app works with OUI-Spy? (OUI-Spy app for Android)", "acceptedAnswer": {"@type": "Answer", "text": "RF Sentinel connects to OUI-Spy boards over USB OTG or Bluetooth and merges their detections with the phone's own. Setup OUI-Spy is ESP32 firmware for the XIAO ESP32-S3 with several modes (Detector, Flock-You, Foxhunter, Sky Spy), a buzzer and LED, and a web flasher. OUI-APEX (lukeswitz's fork) runs those engines from one firmware and pairs with its own cross-platform app. It isn't either/or: RF Sentinel reads OUI-Spy boards over USB, and OUI-SPY App-Controlled boards over Bluetooth, and merges their detections with the phone's own (blue ESP32 badge). The board gives range and radio modes a phone lacks; RF Sentinel adds its rule set, patrol-vehicle grouping, the camera map, alerts and Android Auto."}}, {"@type": "Question", "name": "Wardrive Go alternative: what's the difference with RF Sentinel?", "acceptedAnswer": {"@type": "Answer", "text": "Wardrive Go (GPL-3.0, Android) is a wardriving app: it maps WiFi, Bluetooth and cellular networks, uploads to WiGLE and WDGWars, supports USB monitor-mode WiFi adapters and has channel / spectrum analyzers, Android Auto and a Wear OS companion. It also flags Flock cameras and Axon body cams. RF Sentinel is built around detection and alerting rather than mapping for upload: sourced signatures with confidence tiers, evidence fusion, patrol-vehicle grouping, follower alerts, Remote ID decoding, fake-cell signs and warnings before mapped cameras. Use Wardrive Go to contribute to WiGLE; use RF Sentinel to be warned while you drive. Some of RF Sentinel's prefix data was cross-checked with Wardrive Go's lists."}}, {"@type": "Question", "name": "Fieldwatch alternative for detecting police and surveillance gear", "acceptedAnswer": {"@type": "Answer", "text": "Fieldwatch (MIT, Android) is a receive-only WiFi and Bluetooth LE observer with customizable views, a filtering engine, an extensible signature library and reports, fully offline. It's a general field-survey tool. RF Sentinel shares the receive-only, offline approach but is tuned for surveillance and police gear: alert tiers, patrol-vehicle grouping, tracker follow detection, drone and cell analysis, the camera map and Android Auto. Part of RF Sentinel's prefix data was cross-checked with Fieldwatch's list."}}, {"@type": "Question", "name": "SØPHIA vs RF Sentinel: what's the difference?", "acceptedAnswer": {"@type": "Answer", "text": "SØPHIA is a closed-source passive BLE and WiFi recon app for Android sold by DetecX. RF Sentinel does the same kind of passive WiFi and Bluetooth recon for free and open source, with police, ALPR, tracker, drone and fake-cell detection, a camera map and Android Auto. Full comparison: RF Sentinel vs SØPHIA ."}}, {"@type": "Question", "name": "Flock-You for Android alternative", "acceptedAnswer": {"@type": "Answer", "text": "Flock-You (Android) is a separate counter-surveillance app with broad multi-protocol ambitions (BLE, WiFi, cellular, GNSS, ultrasonic) and Flipper Zero integration. RF Sentinel stays with what a phone's radios can verify, cites a source for every rule, and connects to ESP32 boards instead of a Flipper. Part of RF Sentinel's prefix data was cross-checked with its list."}}, {"@type": "Question", "name": "Best app to detect surveillance over both Bluetooth and WiFi (instead of AirGuard, BLE Radar, WiFi analyzers)", "acceptedAnswer": {"@type": "Answer", "text": "Many good tools cover one radio or one job: Bluetooth only: AirGuard (AirTag / Find My tracker protection), BLE Radar (MetaRadar) (BLE environment monitoring and custom filters), nRF Connect (a developer's BLE scanner), RF Party (BLE from the DEF CON 31 talk). WiFi only: WiFi analyzer apps show access points and channels but don't identify police or surveillance gear. Cell only: EFF's Rayhunter (IMSI catcher detection on dedicated hardware). Mapping: WiGLE WiFi Wardriving and Wardrive Go map networks for upload. RF Sentinel puts Bluetooth LE, WiFi and cell analysis in one app, so evidence from different radios can add up (e.g. a router, a radio and a printer moving together = possible police vehicle). A single-radio tool can't make that connection."}}, {"@type": "Question", "name": "Is there an iPhone version?", "acceptedAnswer": {"@type": "Answer", "text": "No. iOS hides Bluetooth MAC addresses and most advertisement fields from apps, offers no WiFi scan API, and doesn't expose cell information, so most of RF Sentinel's detection can't run there. It is Android only."}}, {"@type": "Question", "name": "Is RF Sentinel free? Are there ads or in-app purchases?", "acceptedAnswer": {"@type": "Answer", "text": "Free, no ads, no in-app purchases, no subscription, no account. Licensed GPL-3.0."}}, {"@type": "Question", "name": "Is it on Google Play or F-Droid?", "acceptedAnswer": {"@type": "Answer", "text": "Not currently. The signed APK is published on GitHub Releases for every version. See the install guide ."}}, {"@type": "Question", "name": "How do I install the APK?", "acceptedAnswer": {"@type": "Answer", "text": "On the phone, open the latest release . Under Assets , tap the file ending in -release.apk (not \"Source code\"). Open the downloaded file from the notification or Files → Downloads. If Android blocks it, tap Settings , enable Allow from this source , go back and tap Install . Open RF Sentinel. The setup wizard covers theme, region, alerts, camera download radius and permissions."}}, {"@type": "Question", "name": "Is the APK safe?", "acceptedAnswer": {"@type": "Answer", "text": "The full source is public, every release is signed with the same release key (Android refuses an update signed with a different key), and you can build it yourself with ./gradlew assembleDebug . The app requests no contacts, storage, camera or microphone permissions. Play Protect may warn about any app installed outside Google Play; that warning is about the install source, not a scan result."}}, {"@type": "Question", "name": "How do I update?", "acceptedAnswer": {"@type": "Answer", "text": "Install the newer APK over the existing one. Settings, history and watchlist are kept."}}, {"@type": "Question", "name": "Which Android versions and phones are supported?", "acceptedAnswer": {"@type": "Answer", "text": "Android 8.0 (API 26) and newer, on any phone with Bluetooth LE: Pixel, Samsung, Motorola, OnePlus, Xiaomi and others. Hidden-network WiFi details need Android 11+. Bluetooth 5 extended advertising and LE Coded PHY (long range) are used automatically where the chip supports them."}}, {"@type": "Question", "name": "Does it need root?", "acceptedAnswer": {"@type": "Answer", "text": "No. Everything uses public Android APIs."}}, {"@type": "Question", "name": "Why does it ask for location?", "acceptedAnswer": {"@type": "Answer", "text": "Android ties Bluetooth and WiFi scan results to the location permission (up to Android 11 always, and still for WiFi scans and cell info). RF Sentinel also uses GPS for traces, follow detection and camera warnings. Nearby devices (Bluetooth scan) is required; notifications, Display over other apps (bubble) and Nearby devices → connect (only to list your paired car) are optional."}}, {"@type": "Question", "name": "Scanning stops on Samsung / Xiaomi / OnePlus. What do I do?", "acceptedAnswer": {"@type": "Answer", "text": "Some manufacturers kill background apps aggressively. Scanning runs as a foreground service with a notification, but you may still need to set RF Sentinel's battery usage to Unrestricted . Settings has a shortcut to Android's battery optimization screen."}}, {"@type": "Question", "name": "How does passive Bluetooth LE detection work?", "acceptedAnswer": {"@type": "Answer", "text": "BLE devices broadcast advertising packets on channels 37, 38 and 39 so other devices can find them. Each packet carries an address, flags and optional fields: device name, 16/128-bit service UUIDs, service data, manufacturer data with a Bluetooth SIG company ID, TX power. RF Sentinel receives these through Android's BluetoothLeScanner and matches every field against its rules. It never connects, so the device never knows it was seen."}}, {"@type": "Question", "name": "What is a MAC vendor prefix (OUI) and why does it matter?", "acceptedAnswer": {"@type": "Answer", "text": "The first 3 bytes of a public MAC address (MA-L), or 3.5 / 4.5 bytes for MA-M / MA-S blocks, are assigned by the IEEE to a company. If a device uses its public address, the prefix reveals the maker, e.g. 00:25:DF is Axon Enterprise. RF Sentinel ships the IEEE registry offline and regional watchlist presets (Global, Canada, US) of law-enforcement and surveillance makers, each prefix re-checked against its registrant. Devices using random private addresses defeat prefix matching, which is why payload signatures and fingerprint linking matter more."}}, {"@type": "Question", "name": "What do weak, probable and strong mean?", "acceptedAnswer": {"@type": "Answer", "text": "Tier Confidence Meaning Weak (verify) < 50 Identifier shared with many unrelated products. Amber, silent by default. Probable 50-79 Vendor-specific identifier. Alerts at the default threshold. Strong 80+ Payload tag, or a network name the vendor gives its own devices."}}, {"@type": "Question", "name": "What is evidence fusion?", "acceptedAnswer": {"@type": "Answer", "text": "When different rules of the same category match one device, the scores combine by noisy-OR, with each supporting hit discounted by half because rules often share evidence: 1 - (1 - top) × Π(1 - 0.5 × support) . Hits under 30 never corroborate, and fusion never exceeds 90. Example: watchlisted address 70 + Zebra serial name 50 → 78."}}, {"@type": "Question", "name": "Devices change their Bluetooth address. How does it keep track?", "acceptedAnswer": {"@type": "Answer", "text": "A structural advert fingerprint survives address rotation: names, service UUIDs, service-data and company-ID payload sizes, TX power and connectable flag. When a new private address appears with the same fingerprint as exactly one device that went silent 1.5-30 s earlier, it inherits that device's matches (at −5), follow history and ignore state. Apple-Continuity-only adverts (phones) are never linked, and two identical candidates means no link."}}, {"@type": "Question", "name": "Can I add my own devices or signatures?", "acceptedAnswer": {"@type": "Answer", "text": "Yes. The watchlist takes exact addresses, vendor prefixes (MA-L / MA-M / MA-S) and name or vendor rules, each with a label and score, plus the regional presets. It exports as JSON. Long-press any device to add it."}}, {"@type": "Question", "name": "I found an unidentified device. How do I report it?", "acceptedAnswer": {"@type": "Answer", "text": "Long-press it → Report unknown device . The report shows exactly what is shared before you send it: vendor prefix, name pattern with serial digits hidden, service and manufacturer IDs. No full address, serial, location or time. Paste it into a GitHub issue or share it on Discord . New signatures need a registry or published source; guesses aren't merged."}}, {"@type": "Question", "name": "How far away can it detect devices?", "acceptedAnswer": {"@type": "Answer", "text": "It depends on the transmitter's power, walls, bodies and your phone's antenna. Bluetooth LE from a body camera is typically heard at tens of metres in the open and much less through a vehicle or building; WiFi access points carry further. Phones with LE Coded PHY hear Bluetooth 5 long-range adverts further. An external ESP32 board with a better antenna extends range. Phone radios are weaker than dedicated hardware, so expect fewer catches than purpose-built scanners."}}, {"@type": "Question", "name": "Can it tell the distance or direction of a device?", "acceptedAnswer": {"@type": "Answer", "text": "Distance is estimated from RSSI and is often off by 2-3×. The radar view places stronger signals closer to the centre, but the angle is not a direction: a phone can't measure angle of arrival. To find a device, use Locate mode and walk: it beeps faster as the signal grows."}}, {"@type": "Question", "name": "Why does WiFi only update every 30 seconds?", "acceptedAnswer": {"@type": "Answer", "text": "Android throttles apps to about four WiFi scans per two minutes. The default 30-second interval stays within that limit. Bluetooth LE is continuous."}}, {"@type": "Question", "name": "Why doesn't it see WiFi phones, laptops or cameras connected to a network?", "acceptedAnswer": {"@type": "Answer", "text": "Android's WiFi scan only lists access points (beacons and probe responses). Client devices, such as an in-car laptop connected to the car's router, need monitor mode, which Android doesn't offer without root and a supported chip. An ESP32 board can partly fill that gap."}}, {"@type": "Question", "name": "Does it work with the screen off?", "acceptedAnswer": {"@type": "Answer", "text": "Partly. Android pauses app Bluetooth scanning while the screen is off, and on some phones (a Pixel in our tests) no Bluetooth results arrive at all until the screen is back on. WiFi, the fake-cell checks, known-camera warnings and ESP32 / USB hardware keep working. Keep the screen on for Bluetooth: the car-mount default \"keep screen on while charging\" does that while driving. Android Auto warns you when a scan starts with the phone screen off and shows \"Bluetooth limited\" on its home screen."}}, {"@type": "Question", "name": "How much battery does it use?", "acceptedAnswer": {"@type": "Answer", "text": "Continuous scanning costs battery. Settings → BLE scan mode offers Low latency (default, catches the most), Balanced and Low power , and the WiFi interval is adjustable. Auto-start in the car scans only while you drive."}}, {"@type": "Question", "name": "What can't it detect at all?", "acceptedAnswer": {"@type": "Answer", "text": "Anything that doesn't broadcast BLE or WiFi beacons: cellular-only devices (most non-Flock plate readers, LTE GPS trackers), wired cameras, radios' voice channels, radar and lidar, devices switched off or in a non-advertising state, and WiFi clients. Cameras in OpenStreetMap are covered by the map layer instead."}}, {"@type": "Question", "name": "Is there a police detector app for Android Auto?", "acceptedAnswer": {"@type": "Answer", "text": "RF Sentinel runs in Android Auto: threat headline, the next known camera on your way, recent alerts, Start/Stop and mute on the home screen, device lists with the phone's filters, cell towers, hardware status, a live OpenStreetMap map with devices, cameras and drones, OSM navigation with spoken turns, and alerts as heads-up cards through the car speakers with Mute 30 min and Ignore buttons. See Android Auto ."}}, {"@type": "Question", "name": "RF Sentinel doesn't show up in Android Auto. How do I fix it?", "acceptedAnswer": {"@type": "Answer", "text": "Android Auto hides sideloaded apps until you enable them: open Android Auto settings on the phone, tap Version ten times to unlock developer mode, open ⋮ → Developer settings and enable Unknown sources , then reinstall the APK, open RF Sentinel once on the phone, and reconnect. Also check Customize launcher for hidden apps."}}, {"@type": "Question", "name": "Can I use it with Waze or Google Maps on screen?", "acceptedAnswer": {"@type": "Answer", "text": "Yes. The floating threat bubble (needs Display over other apps) sits over any app: green when clear, orange for probable, red for strong or a follower, with the count. Tap to open, drag to move. Spoken alerts briefly lower other audio."}}, {"@type": "Question", "name": "Can it start by itself when I get in the car?", "acceptedAnswer": {"@type": "Answer", "text": "Yes. Settings → Start scanning automatically in the car : pick your car's Bluetooth. Scanning starts when the phone connects to it or to Android Auto, and stops when you leave if the car started it."}}, {"@type": "Question", "name": "Can I use an ESP32 with RF Sentinel?", "acceptedAnswer": {"@type": "Answer", "text": "Yes. Plug a board running OUI-Spy , GhostESP or ESP32 Marauder into the phone with a USB OTG cable while scanning, or pair an OUI-SPY board running the Bluetooth (App-Controlled) firmware wirelessly. Its detections merge into the list with a blue ESP32 badge. Native-USB boards (S2/S3/C3/C5/C6) and CP210x / CH340 bridges work. See ESP32 boards ."}}, {"@type": "Question", "name": "How do I pair an OUI-SPY board over Bluetooth?", "acceptedAnswer": {"@type": "Answer", "text": "Start scanning with the board on, then Settings → Pair OUI-SPY board and pick OUI-SPY-xxxx . Pair only there, not in Android's Bluetooth settings: the board keeps no pairing keys, so a phone-side bond breaks the link (the app tells you to tap Forget if it finds one)."}}, {"@type": "Question", "name": "Can I use a USB WiFi adapter like the ALFA AWUS036ACS or an RTL8812BU dongle with Android?", "acceptedAnswer": {"@type": "Answer", "text": "Yes, with RF Sentinel 2.11+. Plug an RTL8811AU / RTL8821AU adapter (e.g. AWUS036ACS) into the phone with an OTG cable while scanning and allow USB access. RF Sentinel drives it directly over Android's USB host API (no root), in receive-only monitor mode on the 2.4 GHz channels: no 30-second scan limit, longer range, and it hears client devices (laptops, phones, cameras on a network) that a phone's WiFi scan can't. The driver is ported from Wardrive Go (GPL-3.0). Since 2.12, RTL8812BU / RTL8822BU adapters (TP-Link Archer T3U, ASUS USB-AC53/AC55/AC58, Edimax EW-7822U*, generic AC1200 dongles) work too, on 2.4 and 5 GHz, with a driver ported from OpenIPC devourer (GPL-2.0); single-antenna dongles are handled automatically. With an adapter plugged in, RF Sentinel can also list the WiFi names nearby devices ask for (Menu → Requested networks) and alert when a watched name is asked for. Other chips (RTL8812AU, RTL8814AU, AR9271, MT7612U) are recognised but not supported yet."}}, {"@type": "Question", "name": "How do I see the cell towers my Android phone is connected to?", "acceptedAnswer": {"@type": "Answer", "text": "RF Sentinel's Tools button → Cell towers lists the serving cell and its neighbours live (2G-5G, operator, MCC-MNC, area code, cell ID, PCI, channel, signal) and every tower seen while scanning. They also appear in the live list (Cells filter) and optionally on the map at the spot where the signal was strongest. An optional alert says when the serving tower changes. No online lookup is made, so nothing reveals where you are."}}, {"@type": "Question", "name": "Is there a WiFi channel and spectrum analyzer in RF Sentinel?", "acceptedAnswer": {"@type": "Answer", "text": "Yes: Tools → WiFi channels (networks and strongest signal per channel) and WiFi spectrum (each network as a curve across its channel width) for 2.4, 5 and 6 GHz, from the phone's own scans."}}, {"@type": "Question", "name": "Does it work with Flipper Zero or a WiFi Pineapple?", "acceptedAnswer": {"@type": "Answer", "text": "A Flipper Zero with an ESP32 board running Marauder (for example the BFFB) works since 2.11.1: plug the Flipper into the phone and open GPIO → USB-UART Bridge . A WiFi Pineapple isn't supported. Other supported hardware: ESP32 boards running OUI-Spy, GhostESP or Marauder, and RTL8811AU / 8821AU or RTL8812BU / 8822BU USB WiFi adapters."}}, {"@type": "Question", "name": "Can I use ESP32 Marauder or an ESP32-C5 board for 5 GHz WiFi on Android?", "acceptedAnswer": {"@type": "Answer", "text": "Yes, with RF Sentinel 2.11.1+. Plug a board running ESP32 Marauder into the phone with a USB OTG cable while scanning. RF Sentinel runs only its passive beacon and probe sniffers and adds the networks and client devices to the list. On ESP32-C5 boards (Marauder v8, BFFB v2, LilyGo T-Dongle C5, C5 DevKit) that includes 5 GHz. Keep Channel Hop on in Marauder's settings. See ESP32 boards ."}}, {"@type": "Question", "name": "Does RF Sentinel transmit or jam anything?", "acceptedAnswer": {"@type": "Answer", "text": "No. It never transmits, jams, spoofs or connects to the devices it detects. (The phone's own WiFi scan sends standard probe requests like any phone looking for networks, and an OUI-SPY board in relay mode does the same; that can be turned off.)"}}, {"@type": "Question", "name": "Can police or anyone tell I'm running it?", "acceptedAnswer": {"@type": "Answer", "text": "The app itself sends nothing to the devices it scans. Your phone, like every phone, may still advertise its own Bluetooth and probe for WiFi networks independently of RF Sentinel."}}, {"@type": "Question", "name": "What data does it collect?", "acceptedAnswer": {"@type": "Answer", "text": "None leaves the phone. No accounts, no analytics, no crash reporting. Detections are stored in a local database excluded from cloud backup. Network requests go only to OpenStreetMap services (map tiles, Overpass camera data from overpass-api.de or its mirrors, DeFlock's region files) and, in Android Auto navigation, Nominatim and OSRM. They see your IP and the area or route, never your scans."}}, {"@type": "Question", "name": "Is it legal to detect police equipment?", "acceptedAnswer": {"@type": "Answer", "text": "RF Sentinel only receives signals that devices broadcast publicly by design, and it doesn't decode private communications. Passive reception of Bluetooth and WiFi advertisements is generally lawful, but rules differ by country and state, and some places restrict use in vehicles or of radar detectors. Check your local laws. This is not legal advice."}}, {"@type": "Question", "name": "What is it meant for?", "acceptedAnswer": {"@type": "Answer", "text": "Awareness, research and personal privacy: knowing which surveillance devices are around you, finding trackers, documenting plate-reader deployments. A detection says a device with a given signature is nearby; it isn't proof of who is present or what they're doing."}}, {"@type": "Question", "name": "Is there a Watch Dogs / DedSec or Mr. Robot theme?", "acceptedAnswer": {"@type": "Answer", "text": "Yes. DedSec (Watch Dogs 2-inspired: black, white and electric blue, poster banner, sliced wordmark, a [email protected]:~$ terminal typing hacktivist lines) and fsociety (Mr. Robot-inspired: black and blood red, striped wordmark, a root@fsociety:~# terminal typing quotes from the show). Unofficial fan homages, not affiliated with Ubisoft or NBCUniversal. Eleven more themes include Night Drive (red-only HUD for night driving), Night Vision, Amber CRT, Synthwave, Tactical, Blueprint, Paper and Material You."}}, {"@type": "Question", "name": "Can I export detections?", "acceptedAnswer": {"@type": "Answer", "text": "Yes: current scan as CSV, JSON or KML; all devices ever seen as CSV or JSON; the match log as CSV, JSON, GPX or KML; GPS traces with their devices as GPX, KML, GeoJSON or CSV; the watchlist as JSON; or everything in one JSON file."}}, {"@type": "Question", "name": "Is it open source? Can I build it myself?", "acceptedAnswer": {"@type": "Answer", "text": "Yes, GPL-3.0, 100% Kotlin. Requirements: Android Studio, or JDK 17+ with the Android SDK. git clone https://github.com/CIS-C0/RFSentinel cd RFSentinel ./gradlew assembleDebug tools/gen_assets.py regenerates the offline IEEE and Bluetooth SIG databases and fails if any prefix used in code stops matching its registrant."}}, {"@type": "Question", "name": "How can I help?", "acceptedAnswer": {"@type": "Answer", "text": "Report unknown devices with the in-app report, submit sourced signatures, map cameras in OpenStreetMap / DeFlock, file bugs on GitHub , join the Discord , and star the repo so others find it."}}]}]}</script>+<script type="application/ld+json">{"@context": "https://schema.org", "@graph": [{"@type": "BreadcrumbList", "itemListElement": [{"@type": "ListItem", "position": 1, "name": "RF Sentinel", "item": "https://cis-c0.github.io/RFSentinel/"}, {"@type": "ListItem", "position": 2, "name": "Q&A", "item": "https://cis-c0.github.io/RFSentinel/qa.html"}]}, {"@type": "FAQPage", "mainEntity": [{"@type": "Question", "name": "How do I detect police with an Android phone?", "acceptedAnswer": {"@type": "Answer", "text": "Modern police gear is full of radios that broadcast on their own: body cameras advertise over Bluetooth LE so the officer's phone and holster sensors can find them, in-car routers run WiFi access points, radios and e-ticket printers pair over Bluetooth. Any phone can receive those broadcasts without connecting to anything. RF Sentinel runs a continuous BLE scan and periodic WiFi scans, and matches every packet against vendor company IDs, service UUIDs, payload tags, network names and IEEE MAC prefixes assigned to law-enforcement equipment makers (Axon/TASER, Motorola Solutions, Digital Ally, Getac, Zebra, Flock Safety and others). When two or more kinds of police-type gear rise and fall in signal together, it flags a possible police vehicle. Install the APK , tap Start scanning , grant location and Nearby devices. See the police detection guide ."}}, {"@type": "Question", "name": "Is there an app that detects police nearby?", "acceptedAnswer": {"@type": "Answer", "text": "Yes: RF Sentinel is a free, open-source Android app that does this passively from Bluetooth LE and WiFi signals, with no root and no subscription. It detects the equipment , not people: a match means a device with a police-equipment signature is in range. Crowd-sourced apps (Waze) rely on users reporting; RF Sentinel relies only on what the hardware itself broadcasts, so it also works where nobody has reported anything."}}, {"@type": "Question", "name": "Can my phone detect a police body camera?", "acceptedAnswer": {"@type": "Answer", "text": "Often, yes. Body cameras use Bluetooth LE to pair with the officer's phone app, holster and light-bar triggers, and many advertise continuously. RF Sentinel matches: the BWCDEVICE ASCII tag in service data, manufacturer data or the raw advert, in either byte order (confidence 90, field-validated); TASER International company ID 0x034D and Axon / TASER service UUIDs 0xFC81 , 0xFE6B , 0xFE6C (60 each); Utility Inc. BodyWorn Remote names (80); IEEE MAC prefixes registered to Axon ( 00:25:DF ), Digital Ally, WatchGuard, Getac, Zepcam and others. Independent matches on the same device are fused, so an Axon camera with the company ID, UUID and prefix lands in the strong tier. Cameras that are switched off, or that only use WiFi to dock, are not visible."}}, {"@type": "Question", "name": "How do I detect Axon body cameras and TASERs?", "acceptedAnswer": {"@type": "Answer", "text": "Axon (formerly TASER International) gear is identifiable from the Bluetooth SIG company ID 0x034D , the 16-bit service UUIDs 0xFC81 (Axon Enterprise), 0xFE6B and 0xFE6C (TASER International), and the IEEE block 00:25:DF . Axon Signal Sidearm holster sensors and Signal units, which start body cameras when a gun is drawn or the light bar turns on, are Bluetooth LE too. RF Sentinel ships all of these rules on by default."}}, {"@type": "Question", "name": "Can it detect a police car or unmarked car?", "acceptedAnswer": {"@type": "Answer", "text": "Indirectly. A single Motorola radio, Zebra printer or Cradlepoint router proves nothing, because civilians use them too. RF Sentinel assigns each device a role (body camera, plate reader, two-way radio, vehicle cellular router, mobile printer, in-car computer, rugged laptop, police camera) and groups devices with at least two different roles when their RSSI moves together (Pearson r ≥ 0.6 over at least 8 aligned seconds), or when both are flat (parked) and appeared within 30 s of each other. The group is flagged \"Possible police vehicle\" at 24 + 12 × roles, +10 when the signals move together, capped at 88: two roles stay weak (48), three moving together reach 70. An unmarked car is detected the same way if its gear advertises; there is no \"unmarked car\" signal as such. Details: patrol-vehicle detection ."}}, {"@type": "Question", "name": "Can it detect police radios?", "acceptedAnswer": {"@type": "Answer", "text": "It flags radios that expose Bluetooth or WiFi: Motorola Solutions company ID 0x04EC and UUIDs 0xFD8E / 0xFE04 , plus IEEE prefixes of P25 / TETRA radio makers. Those are weak on their own (Motorola radios are also used by security guards, schools and construction crews) and become meaningful as part of a patrol-vehicle group. It does not receive the voice channels themselves. P25 and TETRA run on VHF, UHF and 700/800 MHz and are usually encrypted; a phone has no receiver for those bands. That would need a software-defined radio, and RF Sentinel never decodes or listens to radio traffic."}}, {"@type": "Question", "name": "Is RF Sentinel a radar detector? Does it detect police radar guns?", "acceptedAnswer": {"@type": "Answer", "text": "No. Police radar and lidar use X, K and Ka-band microwave or infrared laser, which a phone cannot receive. \"Police radar\" in RF Sentinel's list means the Bluetooth/WiFi signatures of radar makers' in-car units when they advertise. For fixed speed and red-light cameras, RF Sentinel uses the OpenStreetMap camera layer and warns about 30 seconds ahead."}}, {"@type": "Question", "name": "Can it detect e-ticket printers?", "acceptedAnswer": {"@type": "Answer", "text": "Yes, with care. Zebra mobile printers advertise UUIDs 0xFE79 / 0xFD66 . With a factory-serial name ( ^[A-Z0-9]{2}[A-Z]{3}\\d{9}$ ), which fleets rarely rename, the score is 50; any other name stays at 30 because the same printers are everywhere in warehouses and retail. Next to a body camera or radio moving with it, it becomes part of a patrol-vehicle group."}}, {"@type": "Question", "name": "How will I be alerted?", "acceptedAnswer": {"@type": "Answer", "text": "Matches above your alert threshold (default 50, probable) play a sound and vibrate: one pulse for weak, two for probable, three for strong. Optional spoken announcements use the phone's own text-to-speech engine, in full (\"Axon body camera nearby\") or short (\"Body cam\", \"Police car\", \"Speed camera, 50\"). There is a discreet mode, a floating threat bubble over other apps (green / orange / red with a count), a notification, a Quick Settings tile, a home-screen widget, and heads-up alerts in Android Auto."}}, {"@type": "Question", "name": "Why did it flag a device that is not police?", "acceptedAnswer": {"@type": "Answer", "text": "A match is a signature, not an identification. 00:25:DF means \"registered to Axon Enterprise\", not \"a police officer\". Some identifiers are shared with consumer products: Motorola Solutions radios are used by private security, Zebra printers by shops, Meta's company ID by Quest headsets. That is why every rule has a confidence, weak matches are amber and silent by default, and the detail screen shows the exact evidence and source. Long-press a device to whitelist it."}}, {"@type": "Question", "name": "How do I detect Flock Safety cameras?", "acceptedAnswer": {"@type": "Answer", "text": "Two ways, combined in the app: Radio signatures. Flock units and their batteries broadcast identifiable signals: WiFi SSIDs starting with Flock- (88), BLE names FS Ext Battery (80), Penguin-<digits> or FS-<hex> (70, or 80 with company ID 0x09C8 ), and the XUNTONG company ID 0x09C8 alone (45, shared silicon). The known-camera map. Flock cameras mapped by volunteers in OpenStreetMap (via DeFlock ) are downloaded and kept offline. You are warned when one is within about 20 seconds of travel and getting closer, even for cameras that only use cellular and emit nothing a phone can hear. See the Flock / ALPR guide ."}}, {"@type": "Question", "name": "How do I detect license plate readers (ALPR) on Android?", "acceptedAnswer": {"@type": "Answer", "text": "Most non-Flock plate readers (Genetec AutoVu, Motorola / Vigilant, Perceptics, Quercus, Tattile) are wired or on cellular modems and don't broadcast anything a phone can match. RF Sentinel flags them by IEEE prefix when they do expose WiFi or Bluetooth, and covers the rest with the OpenStreetMap layer: every element tagged surveillance:type=ALPR , with manufacturer, operator and direction where mapped. The Download Flock option fetches every mapped plate reader in the US and Canada (~18 MB, about 143,000 cameras, refreshed weekly on WiFi); Download nearby cameras fetches a 10-200 km radius."}}, {"@type": "Question", "name": "Can it detect Flock Raven gunshot / audio sensors?", "acceptedAnswer": {"@type": "Answer", "text": "Yes. Raven sensors advertise 128-bit service UUIDs whose short IDs fall in 0x3100 - 0x3500 , matched at confidence 80 (field capture via all-cameras-are-beacons)."}}, {"@type": "Question", "name": "Can it warn me about speed cameras and red-light cameras without Waze?", "acceptedAnswer": {"@type": "Answer", "text": "Yes. Fixed speed and red-light cameras mapped in OpenStreetMap are downloaded automatically for the area you look at and kept offline, refreshed weekly. Speed cameras warn about 30 seconds ahead, with the speed limit when it's mapped. No account, no reporting, no location sent anywhere except the area request to the Overpass API. Coverage depends on how well your area is mapped in OpenStreetMap, and mobile speed traps aren't covered."}}, {"@type": "Question", "name": "Can I silence one specific camera I pass every day?", "acceptedAnswer": {"@type": "Answer", "text": "Yes. Tap the camera on the map and choose Ignore alerts . It stays on the map, faded, and never alerts again. Alert again on the same camera, or Settings, turns it back on. Ignored cameras are kept permanently."}}, {"@type": "Question", "name": "Can I find hidden cameras with my phone?", "acceptedAnswer": {"@type": "Answer", "text": "Only cameras that use WiFi or Bluetooth. RF Sentinel has an optional (off by default) network-camera category: SSIDs starting with ARLO_VMB_ / NTGR_VMB_ (88) and IEEE blocks of Arlo, Blink, Ezviz, Uniview, Amcrest, Wyze, Swann, Night Owl, SkyBell and WUUK (65, WiFi only). Turn on the Network / home security camera category in Settings. Limits you should know: a camera that joins an existing WiFi network as a client is invisible to an Android WiFi scan (only access points are listed), and wired, SD-card-only or cellular cameras emit nothing usable. A lens-reflection or IR check finds those, not a radio app."}}, {"@type": "Question", "name": "Can it identify hidden WiFi networks?", "acceptedAnswer": {"@type": "Answer", "text": "Yes. Hidden networks still send beacons with information elements. RF Sentinel reads the WPS element (manufacturer, model name and number, device name, primary device type), the Cisco CCX AP name (IE 133), the BSSID's IEEE registrant and vendor IE owners, and links a hidden BSSID to the visible network on the same router (octets 2-5 equal, last octet within 16). Requires Android 11+ for the raw elements."}}, {"@type": "Question", "name": "How do I know if an AirTag is following me on Android?", "acceptedAnswer": {"@type": "Answer", "text": "An AirTag away from its owner switches to a \"separated\" Find My frame: Apple company ID 0x004C , type 0x12 , length 0x19 . RF Sentinel matches that frame (confidence 70), keeps tracking the tag through its address rotations, and raises a may be following you alert when it has been with you for at least 10 minutes while you moved at least 800 m (both adjustable: 2-240 minutes). Tap the device and use Locate : it beeps faster as the signal gets stronger. It reacts to the same frame Android's built-in unknown-tracker alerts use, but shows it live, with history and a signal graph, instead of after hours."}}, {"@type": "Question", "name": "Does it detect Tile, Samsung SmartTag and Google Find Hub trackers?", "acceptedAnswer": {"@type": "Answer", "text": "Yes. Google Find Hub tags via 0xFEAA service data frame 0x41 (separated; frame 0x40 means near the owner and is ignored), Samsung SmartTag via 0xFD5A and Tile via 0xFEED service data (55). All feed the same follow detection."}}, {"@type": "Question", "name": "Can it find a GPS tracker hidden on my car?", "acceptedAnswer": {"@type": "Answer", "text": "Only Bluetooth trackers (AirTag, SmartTag, Tile, Find Hub tags). LTE / GSM GPS trackers report over the cellular network and don't broadcast anything a phone can identify. For those, a physical inspection or a dedicated RF sweep is needed."}}, {"@type": "Question", "name": "My own AirTag keeps showing up. How do I ignore it?", "acceptedAnswer": {"@type": "Answer", "text": "Long-press it and ignore it. The ignore follows the tag when its address changes: it is carried over through the advert fingerprint link, so you don't have to ignore it again after each rotation. To leave every Apple Find My tag out of the Trackers category, turn on Settings → Exclude Apple AirTags (also in Android Auto → More); Google Find Hub, SmartTag and Tile trackers still alert."}}, {"@type": "Question", "name": "How do I detect drones near me with my phone?", "acceptedAnswer": {"@type": "Answer", "text": "Drones sold since FAA / EU Remote ID rules must broadcast an ASTM F3411 Remote ID signal over Bluetooth (service data 0xFFFA , app code 0x0D ) or WiFi (vendor IE OUI FA:0B:BC , type 0x0D ). RF Sentinel decodes it (confidence 95), places the drone on the map with heading, altitude and speed, and raises a \"drone overhead\" alert when it is within 200 m horizontally (once per drone per 5 minutes). Drone makers' own IEEE blocks (DJI, Parrot, Skydio, Autel, Yuneec...) are also matched at 60. See the drone guide ."}}, {"@type": "Question", "name": "Can I see where the drone pilot is?", "acceptedAnswer": {"@type": "Answer", "text": "When the drone's Remote ID includes the System message, yes: Remote ID carries the operator (or take-off) position. The detail screen shows it, and you can open both the drone and operator positions in your maps app. Remote ID also carries the serial number and, where used, an operator ID."}}, {"@type": "Question", "name": "Does it detect police drones?", "acceptedAnswer": {"@type": "Answer", "text": "It detects any drone that broadcasts Remote ID, which includes most police drones (DJI, Skydio, Autel) under current rules. It can't tell who operates it unless the operator ID says so. Exempt or modified drones that don't broadcast Remote ID are not detected."}}, {"@type": "Question", "name": "How do I detect a Stingray or IMSI catcher on Android without root?", "acceptedAnswer": {"@type": "Answer", "text": "Without root, Android exposes the cells your phone sees (network codes, cell IDs, area codes, radio technology, signal) but not ciphering or signalling messages. RF Sentinel reads them every 15 s and looks for the signs a cell-site simulator leaves in that data: serving cell on a test / reserved MCC (001, 002, 999): 85; sudden switch from 4G/5G to 2G while strong LTE is still visible (the visible side of the 2G downgrade EFF's Rayhunter watches for): 70; a known cell number appearing in a different area (cloned identity), a reserved area code (0, 0xFFFE, 0xFFFF) or cell ID 0; a network country code that doesn't match the SIM while not roaming; the location area changing while GPS shows you standing still, a new cell with no neighbours. A sign must persist across two checks; 2G drops during calls and area codes flipping at coverage borders are ignored. Several signs together score max + 15, capped at 90. See the IMSI catcher guide ."}}, {"@type": "Question", "name": "How reliable is fake cell tower detection on a phone?", "acceptedAnswer": {"@type": "Answer", "text": "It is heuristic. Each sign has innocent explanations (network maintenance, rural 2G, carrier misconfiguration), and a well-configured simulator copying a real cell's identity shows few of them. Treat it as a warning to look closer, not proof. The strongest protection is turning off Allow 2G in your SIM settings (Android 12+), and on Android 15+ enabling Cellular security → Network notifications , which warns when a network asks for your SIM identity or turns off encryption. RF Sentinel's Settings links there."}}, {"@type": "Question", "name": "How does this compare with EFF's Rayhunter?", "acceptedAnswer": {"@type": "Answer", "text": "Rayhunter runs on a cheap mobile hotspot with root access to the modem's signalling (QMDL / diag), so it sees identity requests and ciphering changes directly. A normal Android app can't. RF Sentinel implements the parts of that analysis visible through Android's public cell APIs (2G downgrade, identity anomalies) and points to Android 15's own network notifications for the rest. For the strongest detection, use Rayhunter hardware alongside."}}, {"@type": "Question", "name": "How do I detect Ray-Ban Meta smart glasses nearby?", "acceptedAnswer": {"@type": "Answer", "text": "Ray-Ban Meta glasses advertise over Bluetooth LE. RF Sentinel matches Luxottica's company ID 0x0D53 (70), company ID 0x058E together with the META_RB_GLASS token (72), and Meta's corporate company ID 0x01AB / UUIDs 0xFEB7 / 0xFEB8 (45, because Quest headsets share them). Snap Spectacles ( 0x03C2 ), Vuzix ( 0x060C ) and HeyCyan-SDK glasses (full 128-bit UUID) are matched too. See the smart glasses guide ."}}, {"@type": "Question", "name": "Can it tell if the glasses are recording?", "acceptedAnswer": {"@type": "Answer", "text": "No. It tells you the glasses are near you and advertising. Recording state is not part of the advertisement."}}, {"@type": "Question", "name": "How can I get s0phia ops (SØPHIA) for free?", "acceptedAnswer": {"@type": "Answer", "text": "SØPHIA is a paid product sold by its own developer, and this site doesn't distribute it or any copy of it. If what you want is the same kind of tool for free, RF Sentinel is a free, open-source (GPL-3.0) alternative: passive Bluetooth LE and WiFi scanning for police gear, plate-reader cameras, trackers and drones, installed as a signed APK, no account. Comparison: RF Sentinel vs SØPHIA ."}}, {"@type": "Question", "name": "Is there a free alternative to SØPHIA / SophiaOps?", "acceptedAnswer": {"@type": "Answer", "text": "Yes. RF Sentinel covers passive BLE and WiFi recon with a radar view, risk scoring and a timeline, and adds sourced police, ALPR, tracker, Remote ID and smart-glasses signatures, patrol-vehicle grouping, fake cell tower signs, an offline camera map and Android Auto. It costs nothing and the full source is on GitHub . RF Sentinel is independent and not affiliated with SØPHIA or DetecX."}}, {"@type": "Question", "name": "Do I need Termux to scan for police on Android?", "acceptedAnswer": {"@type": "Answer", "text": "Not with RF Sentinel. It is a regular Android app using the public BLE scan and WiFi scan APIs, so there's no Termux, Termux:API, Python or shell setup."}}, {"@type": "Question", "name": "How is it different from RF Party, BLE Radar (MetaRadar) or Flock You?", "acceptedAnswer": {"@type": "Answer", "text": "RF Party (based on Alan Meekins' DEF CON 31 talk) and BLE Radar are general Bluetooth scanners: they list and track devices, with fewer police-specific rules. Flock You and OUI-Spy are ESP32 firmware focused on Flock and watchlist matching. RF Sentinel combines a sourced signature set (each rule cites the IEEE registry, Bluetooth SIG or published research), evidence fusion, patrol-vehicle grouping, WiFi and cell analysis, the OpenStreetMap camera layer and Android Auto in one Android app, and can ingest OUI-Spy and GhostESP boards. No code from those projects is included."}}, {"@type": "Question", "name": "Is there a Flock You app for Android? (Flock You alternative)", "acceptedAnswer": {"@type": "Answer", "text": "Yes: RF Sentinel detects Flock Safety cameras on an Android phone with no extra hardware, and can also read a Flock You / OUI-Spy ESP32 board. Details Flock You is open-source (MIT) ESP32 firmware focused on one target: Flock Safety cameras. It runs the radio in 2.4 GHz promiscuous mode, so it sees Flock cameras' WiFi probe requests and SoftAPs that a phone can't, plus Flock battery-pack BLE adverts, and beeps or feeds a dashboard. RF Sentinel is a phone app that covers Flock as one category among many (body cams, patrol gear, trackers, drones, glasses, fake cell towers) and adds the OpenStreetMap / DeFlock camera map for cellular-only cameras. They combine well: plug an ESP32 running OUI-Spy's Flock-You mode into the phone and RF Sentinel shows its Flock detections next to its own. See ESP32 boards ."}}, {"@type": "Question", "name": "Which Android app works with OUI-Spy? (OUI-Spy app for Android)", "acceptedAnswer": {"@type": "Answer", "text": "RF Sentinel connects to OUI-Spy boards over USB OTG or Bluetooth and merges their detections with the phone's own. Setup OUI-Spy is ESP32 firmware for the XIAO ESP32-S3 with several modes (Detector, Flock-You, Foxhunter, Sky Spy), a buzzer and LED, and a web flasher. OUI-APEX (lukeswitz's fork) runs those engines from one firmware and pairs with its own cross-platform app. It isn't either/or: RF Sentinel reads OUI-Spy boards over USB, and OUI-SPY App-Controlled boards over Bluetooth, and merges their detections with the phone's own (blue ESP32 badge). The board gives range and radio modes a phone lacks; RF Sentinel adds its rule set, patrol-vehicle grouping, the camera map, alerts and Android Auto."}}, {"@type": "Question", "name": "Wardrive Go alternative: what's the difference with RF Sentinel?", "acceptedAnswer": {"@type": "Answer", "text": "Wardrive Go (GPL-3.0, Android) is a wardriving app: it maps WiFi, Bluetooth and cellular networks, uploads to WiGLE and WDGWars, supports USB monitor-mode WiFi adapters and has channel / spectrum analyzers, Android Auto and a Wear OS companion. It also flags Flock cameras and Axon body cams. RF Sentinel is built around detection and alerting rather than mapping for upload: sourced signatures with confidence tiers, evidence fusion, patrol-vehicle grouping, follower alerts, Remote ID decoding, fake-cell signs and warnings before mapped cameras. Use Wardrive Go to contribute to WiGLE; use RF Sentinel to be warned while you drive. Some of RF Sentinel's prefix data was cross-checked with Wardrive Go's lists."}}, {"@type": "Question", "name": "Fieldwatch alternative for detecting police and surveillance gear", "acceptedAnswer": {"@type": "Answer", "text": "Fieldwatch (MIT, Android) is a receive-only WiFi and Bluetooth LE observer with customizable views, a filtering engine, an extensible signature library and reports, fully offline. It's a general field-survey tool. RF Sentinel shares the receive-only, offline approach but is tuned for surveillance and police gear: alert tiers, patrol-vehicle grouping, tracker follow detection, drone and cell analysis, the camera map and Android Auto. Part of RF Sentinel's prefix data was cross-checked with Fieldwatch's list."}}, {"@type": "Question", "name": "SØPHIA vs RF Sentinel: what's the difference?", "acceptedAnswer": {"@type": "Answer", "text": "SØPHIA is a closed-source passive BLE and WiFi recon app for Android sold by DetecX. RF Sentinel does the same kind of passive WiFi and Bluetooth recon for free and open source, with police, ALPR, tracker, drone and fake-cell detection, a camera map and Android Auto. Full comparison: RF Sentinel vs SØPHIA ."}}, {"@type": "Question", "name": "Flock-You for Android alternative", "acceptedAnswer": {"@type": "Answer", "text": "Flock-You (Android) is a separate counter-surveillance app with broad multi-protocol ambitions (BLE, WiFi, cellular, GNSS, ultrasonic) and Flipper Zero integration. RF Sentinel stays with what a phone's radios can verify, cites a source for every rule, and connects to ESP32 boards instead of a Flipper. Part of RF Sentinel's prefix data was cross-checked with its list."}}, {"@type": "Question", "name": "Best app to detect surveillance over both Bluetooth and WiFi (instead of AirGuard, BLE Radar, WiFi analyzers)", "acceptedAnswer": {"@type": "Answer", "text": "Many good tools cover one radio or one job: Bluetooth only: AirGuard (AirTag / Find My tracker protection), BLE Radar (MetaRadar) (BLE environment monitoring and custom filters), nRF Connect (a developer's BLE scanner), RF Party (BLE from the DEF CON 31 talk). WiFi only: WiFi analyzer apps show access points and channels but don't identify police or surveillance gear. Cell only: EFF's Rayhunter (IMSI catcher detection on dedicated hardware). Mapping: WiGLE WiFi Wardriving and Wardrive Go map networks for upload. RF Sentinel puts Bluetooth LE, WiFi and cell analysis in one app, so evidence from different radios can add up (e.g. a router, a radio and a printer moving together = possible police vehicle). A single-radio tool can't make that connection."}}, {"@type": "Question", "name": "Is there an iPhone version?", "acceptedAnswer": {"@type": "Answer", "text": "No. iOS hides Bluetooth MAC addresses and most advertisement fields from apps, offers no WiFi scan API, and doesn't expose cell information, so most of RF Sentinel's detection can't run there. It is Android only."}}, {"@type": "Question", "name": "Is RF Sentinel free? Are there ads or in-app purchases?", "acceptedAnswer": {"@type": "Answer", "text": "Free, no ads, no in-app purchases, no subscription, no account. Licensed GPL-3.0."}}, {"@type": "Question", "name": "Is it on Google Play or F-Droid?", "acceptedAnswer": {"@type": "Answer", "text": "Not currently. The signed APK is published on GitHub Releases for every version. See the install guide ."}}, {"@type": "Question", "name": "How do I install the APK?", "acceptedAnswer": {"@type": "Answer", "text": "On the phone, open the latest release . Under Assets , tap the file ending in -release.apk (not \"Source code\"). Open the downloaded file from the notification or Files → Downloads. If Android blocks it, tap Settings , enable Allow from this source , go back and tap Install . Open RF Sentinel. The setup wizard covers theme, region, alerts, camera download radius and permissions."}}, {"@type": "Question", "name": "Is the APK safe?", "acceptedAnswer": {"@type": "Answer", "text": "The full source is public, every release is signed with the same release key (Android refuses an update signed with a different key), and you can build it yourself with ./gradlew assembleDebug . The app requests no contacts, storage, camera or microphone permissions. Play Protect may warn about any app installed outside Google Play; that warning is about the install source, not a scan result."}}, {"@type": "Question", "name": "How do I update?", "acceptedAnswer": {"@type": "Answer", "text": "Install the newer APK over the existing one. Settings, history and watchlist are kept."}}, {"@type": "Question", "name": "Which Android versions and phones are supported?", "acceptedAnswer": {"@type": "Answer", "text": "Android 8.0 (API 26) and newer, on any phone with Bluetooth LE: Pixel, Samsung, Motorola, OnePlus, Xiaomi and others. Hidden-network WiFi details need Android 11+. Bluetooth 5 extended advertising and LE Coded PHY (long range) are used automatically where the chip supports them."}}, {"@type": "Question", "name": "Does it need root?", "acceptedAnswer": {"@type": "Answer", "text": "No. Everything uses public Android APIs."}}, {"@type": "Question", "name": "Why does it ask for location?", "acceptedAnswer": {"@type": "Answer", "text": "Android ties Bluetooth and WiFi scan results to the location permission (up to Android 11 always, and still for WiFi scans and cell info). RF Sentinel also uses GPS for traces, follow detection and camera warnings. Nearby devices (Bluetooth scan) is required; notifications, Display over other apps (bubble) and Nearby devices → connect (only to list your paired car) are optional."}}, {"@type": "Question", "name": "Scanning stops on Samsung / Xiaomi / OnePlus. What do I do?", "acceptedAnswer": {"@type": "Answer", "text": "Some manufacturers kill background apps aggressively. Scanning runs as a foreground service with a notification, but you may still need to set RF Sentinel's battery usage to Unrestricted . Settings has a shortcut to Android's battery optimization screen."}}, {"@type": "Question", "name": "How does passive Bluetooth LE detection work?", "acceptedAnswer": {"@type": "Answer", "text": "BLE devices broadcast advertising packets on channels 37, 38 and 39 so other devices can find them. Each packet carries an address, flags and optional fields: device name, 16/128-bit service UUIDs, service data, manufacturer data with a Bluetooth SIG company ID, TX power. RF Sentinel receives these through Android's BluetoothLeScanner and matches every field against its rules. It never connects, so the device never knows it was seen."}}, {"@type": "Question", "name": "What is a MAC vendor prefix (OUI) and why does it matter?", "acceptedAnswer": {"@type": "Answer", "text": "The first 3 bytes of a public MAC address (MA-L), or 3.5 / 4.5 bytes for MA-M / MA-S blocks, are assigned by the IEEE to a company. If a device uses its public address, the prefix reveals the maker, e.g. 00:25:DF is Axon Enterprise. RF Sentinel ships the IEEE registry offline and regional watchlist presets (Global, Canada, US) of law-enforcement and surveillance makers, each prefix re-checked against its registrant. Devices using random private addresses defeat prefix matching, which is why payload signatures and fingerprint linking matter more."}}, {"@type": "Question", "name": "What do weak, probable and strong mean?", "acceptedAnswer": {"@type": "Answer", "text": "Tier Confidence Meaning Weak (verify) < 50 Identifier shared with many unrelated products. Amber, silent by default. Probable 50-79 Vendor-specific identifier. Alerts at the default threshold. Strong 80+ Payload tag, or a network name the vendor gives its own devices."}}, {"@type": "Question", "name": "What is evidence fusion?", "acceptedAnswer": {"@type": "Answer", "text": "When different rules of the same category match one device, the scores combine by noisy-OR, with each supporting hit discounted by half because rules often share evidence: 1 - (1 - top) × Π(1 - 0.5 × support) . Hits under 30 never corroborate, and fusion never exceeds 90. Example: watchlisted address 70 + Zebra serial name 50 → 78."}}, {"@type": "Question", "name": "Devices change their Bluetooth address. How does it keep track?", "acceptedAnswer": {"@type": "Answer", "text": "A structural advert fingerprint survives address rotation: names, service UUIDs, service-data and company-ID payload sizes, TX power and connectable flag. When a new private address appears with the same fingerprint as exactly one device that went silent 1.5-30 s earlier, it inherits that device's matches (at −5), follow history and ignore state. Apple-Continuity-only adverts (phones) are never linked, and two identical candidates means no link."}}, {"@type": "Question", "name": "Can I add my own devices or signatures?", "acceptedAnswer": {"@type": "Answer", "text": "Yes. The watchlist takes exact addresses, vendor prefixes (MA-L / MA-M / MA-S) and name or vendor rules, each with a label and score, plus the regional presets. It exports as JSON. Long-press any device to add it."}}, {"@type": "Question", "name": "I found an unidentified device. How do I report it?", "acceptedAnswer": {"@type": "Answer", "text": "Long-press it → Report unknown device . The report shows exactly what is shared before you send it: vendor prefix, name pattern with serial digits hidden, service and manufacturer IDs. No full address, serial, location or time. Paste it into a GitHub issue or share it on Discord . New signatures need a registry or published source; guesses aren't merged."}}, {"@type": "Question", "name": "How far away can it detect devices?", "acceptedAnswer": {"@type": "Answer", "text": "It depends on the transmitter's power, walls, bodies and your phone's antenna. Bluetooth LE from a body camera is typically heard at tens of metres in the open and much less through a vehicle or building; WiFi access points carry further. Phones with LE Coded PHY hear Bluetooth 5 long-range adverts further. An external ESP32 board with a better antenna extends range. Phone radios are weaker than dedicated hardware, so expect fewer catches than purpose-built scanners."}}, {"@type": "Question", "name": "Can it tell the distance or direction of a device?", "acceptedAnswer": {"@type": "Answer", "text": "Distance is estimated from RSSI and is often off by 2-3×. The radar view places stronger signals closer to the centre, but the angle is not a direction: a phone can't measure angle of arrival. To find a device, use Locate mode and walk: it beeps faster as the signal grows."}}, {"@type": "Question", "name": "Why does WiFi only update every 30 seconds?", "acceptedAnswer": {"@type": "Answer", "text": "Android throttles apps to about four WiFi scans per two minutes. The default 30-second interval stays within that limit. Bluetooth LE is continuous."}}, {"@type": "Question", "name": "Why doesn't it see WiFi phones, laptops or cameras connected to a network?", "acceptedAnswer": {"@type": "Answer", "text": "Android's WiFi scan only lists access points (beacons and probe responses). Client devices, such as an in-car laptop connected to the car's router, need monitor mode, which Android doesn't offer without root and a supported chip. An ESP32 board can partly fill that gap."}}, {"@type": "Question", "name": "Does it work with the screen off?", "acceptedAnswer": {"@type": "Answer", "text": "Partly. Android pauses app Bluetooth scanning while the screen is off, and on some phones (a Pixel in our tests) no Bluetooth results arrive at all until the screen is back on. WiFi, the fake-cell checks, known-camera warnings and ESP32 / USB hardware keep working. Keep the screen on for Bluetooth: the car-mount default \"keep screen on while charging\" does that while driving. Android Auto warns you when a scan starts with the phone screen off and shows \"Bluetooth limited\" on its home screen."}}, {"@type": "Question", "name": "How much battery does it use?", "acceptedAnswer": {"@type": "Answer", "text": "Continuous scanning costs battery. Settings → BLE scan mode offers Low latency (default, catches the most), Balanced and Low power , and the WiFi interval is adjustable. Auto-start in the car scans only while you drive."}}, {"@type": "Question", "name": "What can't it detect at all?", "acceptedAnswer": {"@type": "Answer", "text": "Anything that doesn't broadcast BLE or WiFi beacons: cellular-only devices (most non-Flock plate readers, LTE GPS trackers), wired cameras, radios' voice channels, radar and lidar, devices switched off or in a non-advertising state, and WiFi clients. Cameras in OpenStreetMap are covered by the map layer instead."}}, {"@type": "Question", "name": "Is there a police detector app for Android Auto?", "acceptedAnswer": {"@type": "Answer", "text": "RF Sentinel runs in Android Auto: threat headline, the next known camera on your way, recent alerts, Start/Stop and mute on the home screen, device lists with the phone's filters, cell towers, hardware status, a live OpenStreetMap map with devices, cameras and drones, OSM navigation with spoken turns, and alerts as heads-up cards through the car speakers with Mute 30 min and Ignore buttons. See Android Auto ."}}, {"@type": "Question", "name": "RF Sentinel doesn't show up in Android Auto. How do I fix it?", "acceptedAnswer": {"@type": "Answer", "text": "Android Auto hides sideloaded apps until you enable them: open Android Auto settings on the phone, tap Version ten times to unlock developer mode, open ⋮ → Developer settings and enable Unknown sources , then reinstall the APK, open RF Sentinel once on the phone, and reconnect. Also check Customize launcher for hidden apps."}}, {"@type": "Question", "name": "Can I use it with Waze or Google Maps on screen?", "acceptedAnswer": {"@type": "Answer", "text": "Yes. The floating threat bubble (needs Display over other apps) sits over any app: green when clear, orange for probable, red for strong or a follower, with the count. Tap to open, drag to move. Spoken alerts briefly lower other audio."}}, {"@type": "Question", "name": "Can it start by itself when I get in the car?", "acceptedAnswer": {"@type": "Answer", "text": "Yes. Settings → Start scanning automatically in the car : pick your car's Bluetooth. Scanning starts when the phone connects to it or to Android Auto, and stops when you leave if the car started it."}}, {"@type": "Question", "name": "Can I use an ESP32 with RF Sentinel?", "acceptedAnswer": {"@type": "Answer", "text": "Yes. Plug a board running OUI-Spy , GhostESP or ESP32 Marauder into the phone with a USB OTG cable while scanning, or pair an OUI-SPY board running the Bluetooth (App-Controlled) firmware wirelessly. Its detections merge into the list with a blue ESP32 badge. Native-USB boards (S2/S3/C3/C5/C6) and CP210x / CH340 bridges work. See ESP32 boards ."}}, {"@type": "Question", "name": "How do I pair an OUI-SPY board over Bluetooth?", "acceptedAnswer": {"@type": "Answer", "text": "Start scanning with the board on, then Settings → Pair OUI-SPY board and pick OUI-SPY-xxxx . Pair only there, not in Android's Bluetooth settings: the board keeps no pairing keys, so a phone-side bond breaks the link (the app tells you to tap Forget if it finds one)."}}, {"@type": "Question", "name": "Can I use a USB WiFi adapter like the ALFA AWUS036ACS, AWUS1900, AWUS036ACM, AWUS036H or AWUS036NHA with Android?", "acceptedAnswer": {"@type": "Answer", "text": "Yes, with RF Sentinel 2.11+. Plug an RTL8811AU / RTL8821AU adapter (e.g. AWUS036ACS) into the phone with an OTG cable while scanning and allow USB access. RF Sentinel drives it directly over Android's USB host API (no root), in receive-only monitor mode on the 2.4 GHz channels: no 30-second scan limit, longer range, and it hears client devices (laptops, phones, cameras on a network) that a phone's WiFi scan can't. The driver is ported from Wardrive Go (GPL-3.0). Since 2.12, RTL8812BU / RTL8822BU adapters (TP-Link Archer T3U, ASUS USB-AC53/AC55/AC58, Edimax EW-7822U*, generic AC1200 dongles) work too, on 2.4 and 5 GHz, with a driver ported from OpenIPC devourer (GPL-2.0); single-antenna dongles are handled automatically. With an adapter plugged in, RF Sentinel can also list the WiFi names nearby devices ask for (Menu → Requested networks) and alert when a watched name is asked for. Since 2.13, RTL8814AU (AWUS1900) and MT7612U (AWUS036ACM) adapters work on 2.4 and 5 GHz, RTL8187 (AWUS036H) and RT3070 (AWUS036NH / NEH) on 2.4 GHz, and AR9271 (AWUS036NHA) experimentally; if one misbehaves, Settings → Export USB WiFi adapter log makes a text file to send. RTL8812AU and RTL8811CU / 8821CU are recognised but not supported yet."}}, {"@type": "Question", "name": "How do I see the cell towers my Android phone is connected to?", "acceptedAnswer": {"@type": "Answer", "text": "RF Sentinel's Tools button → Cell towers lists the serving cell and its neighbours live (2G-5G, operator, MCC-MNC, area code, cell ID, PCI, channel, signal) and every tower seen while scanning. They also appear in the live list (Cells filter) and optionally on the map at the spot where the signal was strongest. An optional alert says when the serving tower changes. No online lookup is made, so nothing reveals where you are."}}, {"@type": "Question", "name": "Is there a WiFi channel and spectrum analyzer in RF Sentinel?", "acceptedAnswer": {"@type": "Answer", "text": "Yes: Tools → WiFi channels (networks and strongest signal per channel) and WiFi spectrum (each network as a curve across its channel width) for 2.4, 5 and 6 GHz, from the phone's own scans."}}, {"@type": "Question", "name": "Does it work with Flipper Zero or a WiFi Pineapple?", "acceptedAnswer": {"@type": "Answer", "text": "A Flipper Zero with an ESP32 board running Marauder (for example the BFFB) works since 2.11.1: plug the Flipper into the phone and open GPIO → USB-UART Bridge . A WiFi Pineapple isn't supported. Other supported hardware: ESP32 boards running OUI-Spy, GhostESP or Marauder, and RTL8811AU / 8821AU or RTL8812BU / 8822BU USB WiFi adapters."}}, {"@type": "Question", "name": "Can I use ESP32 Marauder or an ESP32-C5 board for 5 GHz WiFi on Android?", "acceptedAnswer": {"@type": "Answer", "text": "Yes, with RF Sentinel 2.11.1+. Plug a board running ESP32 Marauder into the phone with a USB OTG cable while scanning. RF Sentinel runs only its passive beacon and probe sniffers and adds the networks and client devices to the list. On ESP32-C5 boards (Marauder v8, BFFB v2, LilyGo T-Dongle C5, C5 DevKit) that includes 5 GHz. Keep Channel Hop on in Marauder's settings. See ESP32 boards ."}}, {"@type": "Question", "name": "Does RF Sentinel transmit or jam anything?", "acceptedAnswer": {"@type": "Answer", "text": "No. It never transmits, jams, spoofs or connects to the devices it detects. (The phone's own WiFi scan sends standard probe requests like any phone looking for networks, and an OUI-SPY board in relay mode does the same; that can be turned off.)"}}, {"@type": "Question", "name": "Can police or anyone tell I'm running it?", "acceptedAnswer": {"@type": "Answer", "text": "The app itself sends nothing to the devices it scans. Your phone, like every phone, may still advertise its own Bluetooth and probe for WiFi networks independently of RF Sentinel."}}, {"@type": "Question", "name": "What data does it collect?", "acceptedAnswer": {"@type": "Answer", "text": "None leaves the phone. No accounts, no analytics, no crash reporting. Detections are stored in a local database excluded from cloud backup. Network requests go only to OpenStreetMap services (map tiles, Overpass camera data from overpass-api.de or its mirrors, DeFlock's region files) and, in Android Auto navigation, Nominatim and OSRM. They see your IP and the area or route, never your scans."}}, {"@type": "Question", "name": "Is it legal to detect police equipment?", "acceptedAnswer": {"@type": "Answer", "text": "RF Sentinel only receives signals that devices broadcast publicly by design, and it doesn't decode private communications. Passive reception of Bluetooth and WiFi advertisements is generally lawful, but rules differ by country and state, and some places restrict use in vehicles or of radar detectors. Check your local laws. This is not legal advice."}}, {"@type": "Question", "name": "What is it meant for?", "acceptedAnswer": {"@type": "Answer", "text": "Awareness, research and personal privacy: knowing which surveillance devices are around you, finding trackers, documenting plate-reader deployments. A detection says a device with a given signature is nearby; it isn't proof of who is present or what they're doing."}}, {"@type": "Question", "name": "Is there a Watch Dogs / DedSec or Mr. Robot theme?", "acceptedAnswer": {"@type": "Answer", "text": "Yes. DedSec (Watch Dogs 2-inspired: black, white and electric blue, poster banner, sliced wordmark, a [email protected]:~$ terminal typing hacktivist lines) and fsociety (Mr. Robot-inspired: black and blood red, striped wordmark, a root@fsociety:~# terminal typing quotes from the show). Unofficial fan homages, not affiliated with Ubisoft or NBCUniversal. Eleven more themes include Night Drive (red-only HUD for night driving), Night Vision, Amber CRT, Synthwave, Tactical, Blueprint, Paper and Material You."}}, {"@type": "Question", "name": "Can I export detections?", "acceptedAnswer": {"@type": "Answer", "text": "Yes: current scan as CSV, JSON or KML; all devices ever seen as CSV or JSON; the match log as CSV, JSON, GPX or KML; GPS traces with their devices as GPX, KML, GeoJSON or CSV; the watchlist as JSON; or everything in one JSON file."}}, {"@type": "Question", "name": "Is it open source? Can I build it myself?", "acceptedAnswer": {"@type": "Answer", "text": "Yes, GPL-3.0, 100% Kotlin. Requirements: Android Studio, or JDK 17+ with the Android SDK. git clone https://github.com/CIS-C0/RFSentinel cd RFSentinel ./gradlew assembleDebug tools/gen_assets.py regenerates the offline IEEE and Bluetooth SIG databases and fails if any prefix used in code stops matching its registrant."}}, {"@type": "Question", "name": "How can I help?", "acceptedAnswer": {"@type": "Answer", "text": "Report unknown devices with the in-app report, submit sourced signatures, map cameras in OpenStreetMap / DeFlock, file bugs on GitHub , join the Discord , and star the repo so others find it."}}]}]}</script></head><body><a class="skip" href="#main">Skip to content</a>@@ -658,9 +658,9 @@</details><details class="faq" id="usb-wifi-adapter">-<summary>Can I use a USB WiFi adapter like the ALFA AWUS036ACS or an RTL8812BU dongle with Android?</summary>+<summary>Can I use a USB WiFi adapter like the ALFA AWUS036ACS, AWUS1900, AWUS036ACM, AWUS036H or AWUS036NHA with Android?</summary><div>-<p>Yes, with RF Sentinel 2.11+. Plug an RTL8811AU / RTL8821AU adapter (e.g. AWUS036ACS) into the phone with an OTG cable while scanning and allow USB access. RF Sentinel drives it directly over Android's USB host API (no root), in receive-only monitor mode on the 2.4 GHz channels: no 30-second scan limit, longer range, and it hears client devices (laptops, phones, cameras on a network) that a phone's WiFi scan can't. The driver is ported from Wardrive Go (GPL-3.0). Since 2.12, RTL8812BU / RTL8822BU adapters (TP-Link Archer T3U, ASUS USB-AC53/AC55/AC58, Edimax EW-7822U*, generic AC1200 dongles) work too, on 2.4 and 5 GHz, with a driver ported from OpenIPC devourer (GPL-2.0); single-antenna dongles are handled automatically. With an adapter plugged in, RF Sentinel can also list the WiFi names nearby devices ask for (Menu → Requested networks) and alert when a watched name is asked for. Other chips (RTL8812AU, RTL8814AU, AR9271, MT7612U) are recognised but not supported yet.</p>+<p>Yes, with RF Sentinel 2.11+. Plug an RTL8811AU / RTL8821AU adapter (e.g. AWUS036ACS) into the phone with an OTG cable while scanning and allow USB access. RF Sentinel drives it directly over Android's USB host API (no root), in receive-only monitor mode on the 2.4 GHz channels: no 30-second scan limit, longer range, and it hears client devices (laptops, phones, cameras on a network) that a phone's WiFi scan can't. The driver is ported from Wardrive Go (GPL-3.0). Since 2.12, RTL8812BU / RTL8822BU adapters (TP-Link Archer T3U, ASUS USB-AC53/AC55/AC58, Edimax EW-7822U*, generic AC1200 dongles) work too, on 2.4 and 5 GHz, with a driver ported from OpenIPC devourer (GPL-2.0); single-antenna dongles are handled automatically. With an adapter plugged in, RF Sentinel can also list the WiFi names nearby devices ask for (Menu → Requested networks) and alert when a watched name is asked for. Since 2.13, RTL8814AU (AWUS1900) and MT7612U (AWUS036ACM) adapters work on 2.4 and 5 GHz, RTL8187 (AWUS036H) and RT3070 (AWUS036NH / NEH) on 2.4 GHz, and AR9271 (AWUS036NHA) experimentally; if one misbehaves, Settings → Export USB WiFi adapter log makes a text file to send. RTL8812AU and RTL8811CU / 8821CU are recognised but not supported yet.</p></div></details>diff --git a/docs/sitemap.xml b/docs/sitemap.xmlindex c0ce084..73cac4d 100644--- a/docs/sitemap.xml+++ b/docs/sitemap.xml@@ -1,17 +1,17 @@<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">- <url><loc>https://cis-c0.github.io/RFSentinel/alternatives.html</loc><lastmod>2026-10-03</lastmod><priority>0.8</priority></url>- <url><loc>https://cis-c0.github.io/RFSentinel/android-auto.html</loc><lastmod>2026-10-03</lastmod><priority>0.8</priority></url>- <url><loc>https://cis-c0.github.io/RFSentinel/drone-detector.html</loc><lastmod>2026-10-03</lastmod><priority>0.8</priority></url>- <url><loc>https://cis-c0.github.io/RFSentinel/esp32.html</loc><lastmod>2026-10-03</lastmod><priority>0.8</priority></url>- <url><loc>https://cis-c0.github.io/RFSentinel/flock-camera-detector.html</loc><lastmod>2026-10-03</lastmod><priority>0.8</priority></url>- <url><loc>https://cis-c0.github.io/RFSentinel/how-it-works.html</loc><lastmod>2026-10-03</lastmod><priority>0.8</priority></url>- <url><loc>https://cis-c0.github.io/RFSentinel/imsi-catcher-detector.html</loc><lastmod>2026-10-03</lastmod><priority>0.8</priority></url>- <url><loc>https://cis-c0.github.io/RFSentinel/</loc><lastmod>2026-10-03</lastmod><priority>1.0</priority></url>- <url><loc>https://cis-c0.github.io/RFSentinel/install.html</loc><lastmod>2026-10-03</lastmod><priority>0.8</priority></url>- <url><loc>https://cis-c0.github.io/RFSentinel/police-detector.html</loc><lastmod>2026-10-03</lastmod><priority>0.8</priority></url>- <url><loc>https://cis-c0.github.io/RFSentinel/qa.html</loc><lastmod>2026-10-03</lastmod><priority>0.9</priority></url>- <url><loc>https://cis-c0.github.io/RFSentinel/smart-glasses-detector.html</loc><lastmod>2026-10-03</lastmod><priority>0.8</priority></url>- <url><loc>https://cis-c0.github.io/RFSentinel/sophia-alternative.html</loc><lastmod>2026-10-03</lastmod><priority>0.8</priority></url>- <url><loc>https://cis-c0.github.io/RFSentinel/tracker-detector.html</loc><lastmod>2026-10-03</lastmod><priority>0.8</priority></url>+ <url><loc>https://cis-c0.github.io/RFSentinel/alternatives.html</loc><lastmod>2026-10-04</lastmod><priority>0.8</priority></url>+ <url><loc>https://cis-c0.github.io/RFSentinel/android-auto.html</loc><lastmod>2026-10-04</lastmod><priority>0.8</priority></url>+ <url><loc>https://cis-c0.github.io/RFSentinel/drone-detector.html</loc><lastmod>2026-10-04</lastmod><priority>0.8</priority></url>+ <url><loc>https://cis-c0.github.io/RFSentinel/esp32.html</loc><lastmod>2026-10-04</lastmod><priority>0.8</priority></url>+ <url><loc>https://cis-c0.github.io/RFSentinel/flock-camera-detector.html</loc><lastmod>2026-10-04</lastmod><priority>0.8</priority></url>+ <url><loc>https://cis-c0.github.io/RFSentinel/how-it-works.html</loc><lastmod>2026-10-04</lastmod><priority>0.8</priority></url>+ <url><loc>https://cis-c0.github.io/RFSentinel/imsi-catcher-detector.html</loc><lastmod>2026-10-04</lastmod><priority>0.8</priority></url>+ <url><loc>https://cis-c0.github.io/RFSentinel/</loc><lastmod>2026-10-04</lastmod><priority>1.0</priority></url>+ <url><loc>https://cis-c0.github.io/RFSentinel/install.html</loc><lastmod>2026-10-04</lastmod><priority>0.8</priority></url>+ <url><loc>https://cis-c0.github.io/RFSentinel/police-detector.html</loc><lastmod>2026-10-04</lastmod><priority>0.8</priority></url>+ <url><loc>https://cis-c0.github.io/RFSentinel/qa.html</loc><lastmod>2026-10-04</lastmod><priority>0.9</priority></url>+ <url><loc>https://cis-c0.github.io/RFSentinel/smart-glasses-detector.html</loc><lastmod>2026-10-04</lastmod><priority>0.8</priority></url>+ <url><loc>https://cis-c0.github.io/RFSentinel/sophia-alternative.html</loc><lastmod>2026-10-04</lastmod><priority>0.8</priority></url>+ <url><loc>https://cis-c0.github.io/RFSentinel/tracker-detector.html</loc><lastmod>2026-10-04</lastmod><priority>0.8</priority></url></urlset>diff --git a/site/pages/how-it-works.html b/site/pages/how-it-works.htmlindex f423b7e..6eba87d 100644--- a/site/pages/how-it-works.html+++ b/site/pages/how-it-works.html@@ -11,7 +11,7 @@<li><b>Screen off:</b> Android suspends unfiltered scans, so a second, hardware-filtered scan runs on the identifiers that matter (vendor company IDs, Remote ID, tracker and glasses service data and UUIDs, watchlisted exact addresses).</li><li><b>WiFi</b>: <code>WifiManager</code> scans every 30 s by default (Android allows about 4 per 2 minutes), including raw information elements on Android 11+.</li><li><b>Cell</b>: <code>getAllCellInfo()</code> every 15 s for <a href="imsi-catcher-detector.html">fake-tower signs</a>.</li>-<li><b>External</b>: OUI-Spy / GhostESP / Marauder <a href="esp32.html">ESP32 boards</a> over USB or Bluetooth (also through a Flipper Zero), and RTL8811AU / 8821AU or RTL8812BU / 8822BU USB WiFi adapters (2.4 + 5 GHz).</li>+<li><b>External</b>: OUI-Spy / GhostESP / Marauder <a href="esp32.html">ESP32 boards</a> over USB or Bluetooth (also through a Flipper Zero), FREE-WiLi 2, and USB WiFi adapters: RTL8811AU / 8821AU, RTL8812BU / 8822BU, RTL8814AU, MT7612U (2.4 + 5 GHz), RTL8187, RT3070 and, experimental, AR9271.</li></ul><p>Nothing is ever transmitted to, connected to or paired with a scanned device.</p>diff --git a/site/pages/index.html b/site/pages/index.htmlindex e081fb3..d13fb3f 100644--- a/site/pages/index.html+++ b/site/pages/index.html@@ -54,7 +54,7 @@<div class="card"><h3>Android Auto</h3><p>Template app with threat headline, device lists, live OSM map with cameras and drones, turn-by-turn navigation, alerts through the car speakers. <a href="android-auto.html">Details</a></p></div><div class="card"><h3>Auto start in the car</h3><p>Starts when the phone connects to your car's Bluetooth or Android Auto, stops when you leave.</p></div><div class="card"><h3>Tools</h3><p>Cell towers (serving and neighbour cells, IDs, channel, signal, history, optional map layer and change alert) and WiFi channel / spectrum analyzers for 2.4, 5 and 6 GHz.</p></div>- <div class="card"><h3>USB WiFi adapters</h3><p>RTL8811AU / 8821AU (ALFA AWUS036ACS) and RTL8812BU / 8822BU (TP-Link Archer T3U and other AC1200 dongles, 2.4 + 5 GHz) in receive-only monitor mode over OTG, no root: no scan limit, longer range, devices connected to networks, and the network names devices ask for. <a href="qa.html#usb-wifi-adapter">Details</a></p></div>+ <div class="card"><h3>USB WiFi adapters</h3><p>ALFA AWUS036ACS, AWUS1900, AWUS036ACM, AWUS036H, AWUS036NH / NEH and AWUS036NHA (experimental), TP-Link Archer T3U and other RTL8812BU dongles - 2.4 GHz, and 5 GHz on the AC adapters - in receive-only monitor mode over OTG, no root: no scan limit, longer range, devices connected to networks, and the network names devices ask for. <a href="qa.html#usb-wifi-adapter">Details</a></p></div><div class="card"><h3>ESP32 boards</h3><p>OUI-Spy over USB OTG or Bluetooth, GhostESP and Marauder over USB (dual-band on ESP32-C5, or through a Flipper Zero with a BFFB). The board's detections merge into the app. <a href="esp32.html">Details</a></p></div><div class="card"><h3>Device details</h3><p>Evidence, identity, decoded protocol data, signal graph, Locate mode (beeps faster as you get closer), history and the raw advertisement.</p></div><div class="card"><h3>Export</h3><p>CSV, JSON, KML, GPX, GeoJSON. Everything stays on the phone until you export or share it.</p></div>diff --git a/site/pages/qa.html b/site/pages/qa.htmlindex 202d346..e9f92a9 100644--- a/site/pages/qa.html+++ b/site/pages/qa.html@@ -618,9 +618,9 @@</details><details class="faq" id="usb-wifi-adapter">-<summary>Can I use a USB WiFi adapter like the ALFA AWUS036ACS or an RTL8812BU dongle with Android?</summary>+<summary>Can I use a USB WiFi adapter like the ALFA AWUS036ACS, AWUS1900, AWUS036ACM, AWUS036H or AWUS036NHA with Android?</summary><div>-<p>Yes, with RF Sentinel 2.11+. Plug an RTL8811AU / RTL8821AU adapter (e.g. AWUS036ACS) into the phone with an OTG cable while scanning and allow USB access. RF Sentinel drives it directly over Android's USB host API (no root), in receive-only monitor mode on the 2.4 GHz channels: no 30-second scan limit, longer range, and it hears client devices (laptops, phones, cameras on a network) that a phone's WiFi scan can't. The driver is ported from Wardrive Go (GPL-3.0). Since 2.12, RTL8812BU / RTL8822BU adapters (TP-Link Archer T3U, ASUS USB-AC53/AC55/AC58, Edimax EW-7822U*, generic AC1200 dongles) work too, on 2.4 and 5 GHz, with a driver ported from OpenIPC devourer (GPL-2.0); single-antenna dongles are handled automatically. With an adapter plugged in, RF Sentinel can also list the WiFi names nearby devices ask for (Menu → Requested networks) and alert when a watched name is asked for. Other chips (RTL8812AU, RTL8814AU, AR9271, MT7612U) are recognised but not supported yet.</p>+<p>Yes, with RF Sentinel 2.11+. Plug an RTL8811AU / RTL8821AU adapter (e.g. AWUS036ACS) into the phone with an OTG cable while scanning and allow USB access. RF Sentinel drives it directly over Android's USB host API (no root), in receive-only monitor mode on the 2.4 GHz channels: no 30-second scan limit, longer range, and it hears client devices (laptops, phones, cameras on a network) that a phone's WiFi scan can't. The driver is ported from Wardrive Go (GPL-3.0). Since 2.12, RTL8812BU / RTL8822BU adapters (TP-Link Archer T3U, ASUS USB-AC53/AC55/AC58, Edimax EW-7822U*, generic AC1200 dongles) work too, on 2.4 and 5 GHz, with a driver ported from OpenIPC devourer (GPL-2.0); single-antenna dongles are handled automatically. With an adapter plugged in, RF Sentinel can also list the WiFi names nearby devices ask for (Menu → Requested networks) and alert when a watched name is asked for. Since 2.13, RTL8814AU (AWUS1900) and MT7612U (AWUS036ACM) adapters work on 2.4 and 5 GHz, RTL8187 (AWUS036H) and RT3070 (AWUS036NH / NEH) on 2.4 GHz, and AR9271 (AWUS036NHA) experimentally; if one misbehaves, Settings → Export USB WiFi adapter log makes a text file to send. RTL8812AU and RTL8811CU / 8821CU are recognised but not supported yet.</p></div></details>