Skip to content

RF Sentinel (RFSentinel): free, open-source police detector app for Android. Spots police body cams, Flock ALPR cameras, AirTag trackers, Remote ID drones, smart glasses and fake cell towers from Bluetooth LE and WiFi. No root.

MT7610U USB WiFi adapters: 2.4 + 5 GHz monitor on the MT7612U transport, with bring-up, tuning and tables from the Linux mt76x0u driver (experimental, untested on hardware)

CIS-C03ec01dd78fe0
diff --git a/README.md b/README.md
index c1aa38b..7498585 100644
--- a/README.md
+++ b/README.md
@@ -268,7 +268,7 @@ Everything the app does, grouped by area.
<summary><b>Hardware</b></summary>
- 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; 5 GHz experimental, Settings → External hardware), **RTL8812AU** (e.g. ALFA AWUS036ACH, 2.4 + 5 GHz, experimental), **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), **MT7921AU** (ALFA AWUS036AXML / AXM, WiFi 6E: 2.4 + 5 + **6 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
+- **USB WiFi adapters in monitor mode** over OTG, no root: RTL8811AU / RTL8821AU (e.g. ALFA AWUS036ACS, 2.4 GHz; 5 GHz experimental, Settings → External hardware), **RTL8812AU** (e.g. ALFA AWUS036ACH, 2.4 + 5 GHz, experimental), **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), **MT7921AU** (ALFA AWUS036AXML / AXM, WiFi 6E: 2.4 + 5 + **6 GHz**), **RTL8187** (ALFA AWUS036H), **RT3070** (ALFA AWUS036NH / NEH) and, experimental, **AR9271** (ALFA AWUS036NHA), **RT5370 / RT5372** and **MT7610U** (2.4 + 5 GHz). 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
- **USB Bluetooth adapters** as a second Bluetooth LE scanner, no root: the Bluetooth part of an MT7921AU, RTL8821AU or RTL8822BU combo adapter, or a USB Bluetooth dongle (standard controllers, Realtek RTL8761B / 8761C and others), listening only, with LE Coded long range where the chip has it; devices it hears get a **USB BT** badge (Settings → External hardware)
- **Record frames to .pcap** for Wireshark (Settings → External hardware): every frame a USB WiFi adapter or V2X board hears, with its channel and signal
@@ -689,7 +689,7 @@ Plug a supported USB WiFi adapter into the phone with an OTG cable while
scanning and allow USB access on the prompt. RF Sentinel drives it directly
over 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, RTL8187,
-RT3070 and AR9271; 2.4 GHz and 5 GHz on 88x2bu, 8814au and MT7612U; 2.4, 5 and 6 GHz on the
+RT3070 and AR9271; 2.4 GHz and 5 GHz on 88x2bu, 8814au, MT7612U and MT7610U; 2.4, 5 and 6 GHz on the
MT7921AU, 6 GHz on its 15 preferred scanning channels, where access points beacon). 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
@@ -722,14 +722,15 @@ Realtek RTL8822CU / 8852 and Intel dongles aren't supported yet.
| RTL8187 | 2.4 GHz | - | ALFA AWUS036H, Netgear WG111v2 |
| RT3070 | 2.4 GHz | - | ALFA AWUS036NH / NEH |
| RT5370 / RT5372 | 2.4 GHz, experimental | - | Generic Ralink dongles |
+| MT7610U | 2.4 + 5 GHz, experimental | - | TP-Link Archer T2UHP / T1U, Linksys AE6000, ASUS USB-AC51 |
| AR9271 | 2.4 GHz, experimental | - | ALFA AWUS036NHA, TP-Link TL-WN722N v1 |
-Recognised but not supported yet: RTL8811CU / 8821CU / 8812CU, MT7610U, AR7010.
+Recognised but not supported yet: RTL8811CU / 8821CU / 8812CU, AR7010.
<details>
<summary><b>Receive-only, the adapter log and single-antenna dongles</b></summary>
-The adapter never transmits (on the MT7612U and RT3070 even the automatic ACK
+The adapter never transmits (on the MT7612U, MT7610U and RT3070 even the automatic ACK
replies are switched off).
Settings → External hardware shows its status, and **Export USB adapter log** saves a text
file (app and phone version, the USB devices plugged in, the driver log) to
@@ -1139,7 +1140,7 @@ always OpenFreeMap. **full** adds the optional Mapbox map (`./gradlew assembleFu
Both have the same app ID, so either one replaces the other.
A build of only foss tasks (or `-Prfs.foss=true`) leaves the full flavor out and never
declares or contacts Mapbox's Maven server. The foss flavor also leaves out the non-free
-firmware of the RT3070, MT7612U, MT7921AU and RTL8812BU / 8822BU adapters: when one is
+firmware of the RT3070, MT7612U, MT7610U, MT7921AU and RTL8812BU / 8822BU adapters: when one is
plugged in, the app asks before downloading those exact files once from
[linux-firmware](https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git)
(pinned commit, checked against their SHA-256; see `usb/Firmware.kt`).
@@ -1263,11 +1264,11 @@ 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. The MT7921AU (WiFi 6E) driver is ported from
+Android PCAP Capture as the USB reference. The MT7610U path follows the Linux mt76x0u driver. The MT7921AU (WiFi 6E) driver is ported from
[mt76-usb-macos](https://github.com/Network-Weather/mt76-usb-macos) by Network Weather
(BSD-3-Clause-Clear), a transcription of the MT7921 path of the Linux mt76 driver
(openwrt/mt76, MediaTek and the mt76 authors, BSD-3-Clause-Clear); its transmit path was left out. Their firmware (Ralink rt2870.bin,
-MediaTek mt7662 and MT7961, open ath9k_htc) is the unmodified linux-firmware images, with
+MediaTek mt7662, mt7610u and MT7961, 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 follows
Wardrive Go's approach - thank you.
diff --git a/app/src/full/assets/usbwifi/mt7610u.bin b/app/src/full/assets/usbwifi/mt7610u.bin
new file mode 100644
index 0000000..c6c863e
Binary files /dev/null and b/app/src/full/assets/usbwifi/mt7610u.bin differ
diff --git a/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt b/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt
index 49df330..f1df60a 100644
--- a/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/settings/SettingsActivity.kt
@@ -788,7 +788,7 @@ class SettingsActivity : AppCompatActivity() {
"• USB WiFi adapters in monitor mode: longer range, and they hear devices connected to networks. " +
"RTL8811AU / 8821AU (ALFA AWUS036ACS), RTL8812BU / 8822BU, RTL8814AU (AWUS1900), MT7612U (AWUS036ACM), " +
"MT7921AU (AWUS036AXML, WiFi 6E: 2.4, 5 and 6 GHz, experimental), " +
- "RTL8187 (AWUS036H), RT3070 (AWUS036NH / NEH), RT5370 / RT5372 (experimental), AR9271 (AWUS036NHA, experimental).\n\n" +
+ "RTL8187 (AWUS036H), RT3070 (AWUS036NH / NEH), RT5370 / RT5372 (experimental), MT7610U (experimental), AR9271 (AWUS036NHA, experimental).\n\n" +
"AWUS036ACS 5 GHz (experimental, off by default): the RTL8811AU / 8821AU also hops 5 GHz channels 36-48 and " +
"149-165. Untested on every unit: if it misbehaves, turn it off and send the adapter log. Applies when the adapter is plugged in.\n\n" +
"Adapter light: the AWUS036ACS blinks with received traffic; switch it off to keep it dark (for example in a car at night). " +
diff --git a/app/src/main/java/com/rfsentinel/app/ui/SetupActivity.kt b/app/src/main/java/com/rfsentinel/app/ui/SetupActivity.kt
index 474fe9a..8d4fc3f 100644
--- a/app/src/main/java/com/rfsentinel/app/ui/SetupActivity.kt
+++ b/app/src/main/java/com/rfsentinel/app/ui/SetupActivity.kt
@@ -299,7 +299,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, RTL8812BU / 8822BU, RTL8814AU, MT7612U, RTL8187, RT3070 or, experimental, RT5370, AR9271 and the WiFi 6E MT7921AU - ALFA AWUS1900, AWUS036ACM, AWUS036H, AWUS036NH / NEH, AWUS036NHA, AWUS036AXML), and an RTL-SDR dongle to hear two-way radios transmitting nearby (signal strength only, nothing decoded). 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, RT5370, MT7610U, AR9271 and the WiFi 6E MT7921AU - ALFA AWUS1900, AWUS036ACM, AWUS036H, AWUS036NH / NEH, AWUS036NHA, AWUS036AXML), and an RTL-SDR dongle to hear two-way radios transmitting nearby (signal strength only, nothing decoded). 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/Firmware.kt b/app/src/main/java/com/rfsentinel/app/usb/Firmware.kt
index 0b0d83f..5300315 100644
--- a/app/src/main/java/com/rfsentinel/app/usb/Firmware.kt
+++ b/app/src/main/java/com/rfsentinel/app/usb/Firmware.kt
@@ -28,6 +28,8 @@ object Firmware {
"6f0e871268f6e4d99196d90d89bcc09fe493d010366260a2cfcaa5dd66095f8c", 26350, "LICENCE.ralink_a_mediatek_company_firmware")
private val MT7662 = Blob("mt7662.bin", "mediatek/mt7662.bin",
"f7e52492f58088cae50e51a54cca68e4abc5b74f7d0b6b731dbb4c04465a94b6", 81908, "LICENCE.ralink_a_mediatek_company_firmware")
+ private val MT7610U = Blob("mt7610u.bin", "mediatek/mt7610u.bin",
+ "5a4268e9021bb587426ba624b425f1e660bfc82cd63b36ad3ce6fb9ce6751760", 80288, "LICENCE.ralink_a_mediatek_company_firmware")
private val MT7961_PATCH = Blob("WIFI_MT7961_patch_mcu_1_2_hdr.bin", "mediatek/WIFI_MT7961_patch_mcu_1_2_hdr.bin",
"a276c06c2b772adb50b86639d33c82824ff4c21d617feb78caea74c040b873f6", 92192, "LICENCE.mediatek")
private val MT7961_RAM = Blob("WIFI_RAM_CODE_MT7961_1.bin", "mediatek/WIFI_RAM_CODE_MT7961_1.bin",
@@ -64,12 +66,13 @@ object Firmware {
)
/** Every file the FOSS build may download. */
- val ALL = listOf(RT2870, MT7662_PATCH, MT7662, MT7961_PATCH, MT7961_RAM, RTL8822B) + BLUETOOTH
+ val ALL = listOf(RT2870, MT7662_PATCH, MT7662, MT7610U, MT7961_PATCH, MT7961_RAM, RTL8822B) + BLUETOOTH
/** The non-free files a driver needs (none for the drivers that load no firmware or only free files). */
fun needed(driver: UsbWifi.Driver): List<Blob> = when (driver) {
UsbWifi.Driver.RT3070 -> listOf(RT2870)
UsbWifi.Driver.MT7612U -> listOf(MT7662_PATCH, MT7662)
+ UsbWifi.Driver.MT7610U -> listOf(MT7610U)
UsbWifi.Driver.MT7921U -> listOf(MT7961_PATCH, MT7961_RAM)
UsbWifi.Driver.RTL88X2BU -> listOf(RTL8822B)
else -> emptyList()
diff --git a/app/src/main/java/com/rfsentinel/app/usb/Mt7610uTables.kt b/app/src/main/java/com/rfsentinel/app/usb/Mt7610uTables.kt
new file mode 100644
index 0000000..300c7d9
--- /dev/null
+++ b/app/src/main/java/com/rfsentinel/app/usb/Mt7610uTables.kt
@@ -0,0 +1,231 @@
+package com.rfsentinel.app.usb
+
+/**
+ * MT7610U register tables from the Linux mt76x0 driver (initvals.h, initvals_init.h, initvals_phy.h; GPL-2.0-only,
+ * (c) Ralink Technology, Felix Fietkau, Jakub Kicinski, Stanislaw Gruszka, Lorenzo Bianconi), for the 20 MHz
+ * channels this monitor tunes. Generated from those headers; changed from them only where marked.
+ * Flat arrays: register, value pairs, or register, band mask, value triples.
+ */
+internal object Mt7610uTables {
+ /** common_mac_reg_table, then mt76x0_mac_reg_table. AUTO_RSP_CFG loses bit 0: the auto-responder stays off, so the adapter never answers. */
+ val MAC = intArrayOf(
+ 0x41c, 0xf8f0e8e0.toInt(), 0x420, 0x6f77d0c8, 0x1408, 0x13f, 0x140c, 0x8003,
+ 0x1004, 0x0, 0x1400, 0x17f97, 0x1104, 0x209, 0x1330, 0x0,
+ 0x1334, 0x80606, 0x1350, 0x1020, 0x1348, 0xa2090, 0x1018, 0xa1fff,
+ 0x102c, 0x7f031e46, 0x408, 0x1fbf1f1f, 0x40c, 0xfe9f, 0x134c, 0x47d01f0f,
+ 0x1404, 0x12, 0x1364, 0x7f40003, 0x1368, 0x7f42004, 0x404, 0xf40006,
+ 0x208, 0x30, 0x1374, 0x1742004, 0x1378, 0x3f42084, 0x136c, 0x1742004,
+ 0x1370, 0x3f42084, 0x1340, 0x583f, 0x1344, 0xffff20, 0x1380, 0x2400ca,
+ 0x1608, 0x2, 0x1100, 0x33a41010, 0x1204, 0x0, 0x124, 0xa0040080.toInt(),
+ 0x400, 0x80c00, 0x404, 0x77723c1f, 0x800, 0x1, 0x1030, 0xaaa99887.toInt(),
+ 0x1330, 0x601, 0x1334, 0x40000, 0x1338, 0x0, 0xa44, 0x0,
+ 0x260, 0x0, 0x250, 0x0, 0x1218, 0x500055, 0x1220, 0x500055,
+ 0x13b0, 0x2f2f000c, 0x13c0, 0x0, 0x1314, 0x3a3a3a3a, 0x1318, 0x3a3a3a3a,
+ 0x131c, 0x3a3a3a3a, 0x1320, 0x3a3a3a3a, 0x1324, 0x3a3a3a3a, 0x13d4, 0x3a3a3a3a,
+ 0x13d8, 0x3a, 0x13dc, 0x3a, 0x150c, 0x2, 0x1238, 0x1700c8,
+ 0x6c, 0xa647b6, 0x70, 0x6b006464, 0x140c, 0x4003, 0x1410, 0x1ff,
+ 0x1608, 0x0, 0x150c, 0x3, 0x13e0, 0xe3f42004.toInt(), 0x13e4, 0xe3f42084.toInt(),
+ 0x13e8, 0xe3f42104.toInt(), 0x1358, 0xedcba980.toInt()
+ )
+ /** mt76x0_bbp_init_tab. */
+ val BBP_INIT = intArrayOf(
+ 0x2004, 0x2, 0x2010, 0x0, 0x2060, 0x0, 0x2080, 0x4003000a,
+ 0x20a8, 0x0, 0x20b0, 0x0, 0x212c, 0xfde8081, 0x2300, 0x21400,
+ 0x2304, 0x3, 0x2308, 0x3a6464, 0x233c, 0x88a28cb8.toInt(), 0x2358, 0x1e21,
+ 0x235c, 0x272c, 0x2360, 0x2f3a, 0x2364, 0x8000005a.toInt(), 0x2368, 0x7c2005,
+ 0x2384, 0x3238, 0x2388, 0xa0c0c, 0x2394, 0x2121262c, 0x23a4, 0x38383e45,
+ 0x23e4, 0x1010, 0x23ec, 0xbaa20e96.toInt(), 0x23fc, 0x1, 0x2400, 0x280403,
+ 0x2404, 0x0, 0x2504, 0x12, 0x2508, 0x11, 0x250c, 0x5,
+ 0x2510, 0x0, 0x2514, 0xf977c4ec.toInt(), 0x251c, 0x90, 0x2620, 0x0,
+ 0x2700, 0x0, 0x2710, 0x4, 0x2718, 0x0, 0x2720, 0x14,
+ 0x2724, 0x20000000, 0x2728, 0x0, 0x2730, 0x0, 0x2734, 0x0,
+ 0x2738, 0x0, 0x273c, 0x0, 0x2740, 0x0, 0x2744, 0x0,
+ 0x2804, 0x8800, 0x280c, 0x0, 0x2810, 0x0, 0x2934, 0x192,
+ 0x2938, 0x60612, 0x293c, 0xc8321b18.toInt(), 0x2940, 0x1e, 0x2944, 0x0,
+ 0x2948, 0xcc00a993.toInt(), 0x294c, 0xb9cb9cb9.toInt(), 0x2950, 0x26c00057, 0x2954, 0x1,
+ 0x2960, 0x6, 0x2970, 0x3f
+ )
+ /** mt76x0_dcoc_tab. */
+ val BBP_DCOC = intArrayOf(
+ 0x2cbc, 0x10f0, 0x2cc0, 0x8080, 0x2cc4, 0xf07, 0x2cc8, 0x40,
+ 0x2ccc, 0x404, 0x2cd0, 0x80803, 0x2cd4, 0x704, 0x2cd8, 0x2828,
+ 0x2cdc, 0x5050
+ )
+ /** mt76x0_bbp_switch_tab, the 2.4 GHz 20 MHz rows. */
+ val BBP_2G = intArrayOf(
+ 0x2310, 0x1feda049, 0x2318, 0x45, 0x2320, 0x16344ef0, 0x2330, 0x5052879,
+ 0x2334, 0x35050004, 0x2338, 0x310f2e3c, 0x2368, 0x7c2005, 0x236c, 0xe1,
+ 0x2370, 0x60806, 0x237c, 0xe23, 0x2380, 0x3218, 0x2384, 0x3240,
+ 0x238c, 0x11111616, 0x239c, 0x2a2a3036, 0x23ac, 0x27273438, 0x23cc, 0x17171c1c,
+ 0x23d4, 0x26262a2f, 0x23dc, 0x40404040, 0x23e8, 0x1010, 0x2800, 0x3d5000e0
+ )
+ /** mt76x0_bbp_switch_tab, the 5 GHz 20 MHz rows. */
+ val BBP_5G = intArrayOf(
+ 0x2310, 0x1feca054, 0x2318, 0xa, 0x2320, 0x122c54f2, 0x2330, 0x50528f9,
+ 0x2334, 0x2c3a0406, 0x2338, 0x310f2a3f, 0x2368, 0x7c2005, 0x236c, 0xec,
+ 0x2370, 0x60806, 0x2970, 0x8a, 0x237c, 0xe13, 0x2380, 0x181c,
+ 0x2384, 0x3218, 0x238c, 0x11111111, 0x239c, 0x2a2a2a2a, 0x23ac, 0x27271a1a,
+ 0x23cc, 0xffffffff.toInt(), 0x23d4, 0xffffffff.toInt(), 0x23dc, 0xffffffff.toInt(), 0x23e8, 0x0,
+ 0x2800, 0x895000e0.toInt()
+ )
+ /** mt76x0_rf_central_tab. */
+ val RF_CENTRAL = intArrayOf(
+ 0x1, 0x1, 0x2, 0x11, 0x3, 0x73, 0x4, 0x30,
+ 0x5, 0x0, 0x6, 0x41, 0x7, 0x0, 0x8, 0x0,
+ 0x9, 0x0, 0xa, 0xc, 0xb, 0x0, 0xc, 0x0,
+ 0xd, 0x0, 0xe, 0x0, 0xf, 0x0, 0x13, 0x20,
+ 0x14, 0x22, 0x15, 0x12, 0x17, 0x0, 0x18, 0x33,
+ 0x19, 0x0, 0x1a, 0x0, 0x1b, 0x0, 0x1c, 0x0,
+ 0x1d, 0x0, 0x1e, 0x0, 0x1f, 0x0, 0x20, 0x0,
+ 0x21, 0x0, 0x22, 0x0, 0x23, 0x0, 0x24, 0x0,
+ 0x25, 0x0, 0x26, 0x2f, 0x40, 0x0, 0x41, 0x80,
+ 0x42, 0x1, 0x43, 0x4, 0x44, 0x0, 0x45, 0x8,
+ 0x46, 0x8, 0x47, 0x40, 0x48, 0xd0, 0x49, 0x93
+ )
+ /** mt76x0_rf_2g_channel_0_tab. */
+ val RF_2G = intArrayOf(
+ 0x50002, 0xc, 0x50003, 0x0, 0x50004, 0x0, 0x50005, 0x84,
+ 0x50006, 0x2, 0x50007, 0x0, 0x50008, 0x0, 0x50009, 0x0,
+ 0x5000a, 0x51, 0x5000b, 0x22, 0x5000c, 0x22, 0x5000d, 0xf,
+ 0x5000e, 0x47, 0x5000f, 0x25, 0x50010, 0xc7, 0x50011, 0x0,
+ 0x50012, 0x0, 0x50013, 0x30, 0x50014, 0x33, 0x50015, 0x2,
+ 0x50016, 0x32, 0x50017, 0x0, 0x50018, 0x25, 0x5001a, 0x0,
+ 0x5001b, 0x12, 0x5001c, 0xf, 0x5001d, 0x0, 0x5001e, 0x51,
+ 0x5001f, 0x35, 0x50020, 0x31, 0x50021, 0x31, 0x50022, 0x34,
+ 0x50023, 0x3, 0x50024, 0x0, 0x50025, 0xdd, 0x50026, 0xb3,
+ 0x50027, 0x33, 0x50028, 0xb1, 0x50029, 0x71, 0x5002a, 0xf2,
+ 0x5002b, 0x47, 0x5002c, 0x77, 0x5002d, 0xe, 0x5002e, 0x10,
+ 0x5002f, 0x0, 0x50030, 0x53, 0x50031, 0x3, 0x50032, 0xef,
+ 0x50033, 0xc7, 0x50034, 0x62, 0x50035, 0x62, 0x50036, 0x0,
+ 0x50037, 0x0, 0x50038, 0xf, 0x50039, 0xf, 0x5003a, 0x16,
+ 0x5003b, 0x16, 0x5003c, 0x10, 0x5003d, 0x10, 0x5003e, 0xd0,
+ 0x5003f, 0x6c, 0x50040, 0x58, 0x50041, 0x58, 0x50042, 0xf2,
+ 0x50043, 0xe8, 0x50044, 0xf0, 0x50045, 0xf0, 0x5007f, 0x4
+ )
+ /** mt76x0_rf_5g_channel_0_tab. */
+ val RF_5G = intArrayOf(
+ 0x60002, 0xc, 0x60003, 0x0, 0x60004, 0x0, 0x60005, 0x84,
+ 0x60006, 0x2, 0x60007, 0x0, 0x60008, 0x0, 0x60009, 0x0,
+ 0x6000a, 0x0, 0x6000b, 0x1, 0x6000d, 0x23, 0x6000e, 0x0,
+ 0x6000f, 0x4, 0x60010, 0x22, 0x60012, 0x8, 0x60013, 0x0,
+ 0x60014, 0x0, 0x60015, 0x0, 0x60016, 0xfb, 0x60019, 0x76,
+ 0x6001a, 0x24, 0x6001b, 0x4, 0x6001c, 0x0, 0x6001d, 0x0,
+ 0x60025, 0xbb, 0x60026, 0xb3, 0x60028, 0x33, 0x60029, 0x33,
+ 0x6002b, 0x3, 0x6002c, 0xb3, 0x6002e, 0x17, 0x6002f, 0xe,
+ 0x60030, 0x10, 0x60031, 0x7, 0x6003e, 0x0, 0x6003f, 0x0,
+ 0x60040, 0xf1, 0x60041, 0xf
+ )
+ /** mt76x0_rf_vga_channel_0_tab. */
+ val RF_VGA = intArrayOf(
+ 0x70000, 0x47, 0x70001, 0x0, 0x70002, 0x0, 0x70003, 0x0,
+ 0x70004, 0x0, 0x7000a, 0x13, 0x7000b, 0xf, 0x7000c, 0x13,
+ 0x7000d, 0x13, 0x7000e, 0x13, 0x7000f, 0x20, 0x70010, 0x22,
+ 0x70011, 0x7c, 0x70012, 0x0, 0x70013, 0x0, 0x70014, 0x0,
+ 0x70015, 0xf1, 0x70016, 0x11, 0x70017, 0xc2, 0x70018, 0x41,
+ 0x70019, 0x20, 0x7001a, 0x40, 0x7001b, 0xd7, 0x7001c, 0xa2,
+ 0x7001d, 0x60, 0x7001e, 0x49, 0x7001f, 0x20, 0x70020, 0x44,
+ 0x70021, 0xc1, 0x70022, 0x60, 0x70023, 0xc0, 0x7003d, 0x1,
+ 0x70048, 0x3c, 0x70049, 0x34, 0x7004a, 0x0
+ )
+ /** mt76x0_rf_bw_switch_tab, the rows mt76x0_phy_rf_init writes. */
+ val RF_BW_INIT = intArrayOf(
+ 0x11, 0x0, 0x70006, 0x40, 0x70007, 0x40, 0x70008, 0x3,
+ 0x7003a, 0x40, 0x7003b, 0x40, 0x7003c, 0xaa, 0x7004c, 0x40,
+ 0x7004d, 0x40
+ )
+ /** mt76x0_rf_bw_switch_tab, the 20 MHz rows a channel change writes: register, band mask (0 = any), value. */
+ val RF_BW = intArrayOf(
+ 0x11, 0x100, 0x0, 0x11, 0x200, 0x0, 0x70006, 0x100,
+ 0x40, 0x70006, 0x200, 0x40, 0x70007, 0x100, 0x40, 0x70007,
+ 0x200, 0x40, 0x70008, 0x100, 0x3, 0x70008, 0x200, 0x3,
+ 0x7003a, 0x100, 0x40, 0x7003a, 0x200, 0x40, 0x7003b, 0x100,
+ 0x40, 0x7003b, 0x200, 0x40, 0x7003c, 0x100, 0xaa, 0x7003c,
+ 0x200, 0xaa, 0x7004c, 0x0, 0x40, 0x7004d, 0x0, 0x40
+ )
+ /** mt76x0_rf_band_switch_tab: register, band mask, value. */
+ val RF_BAND = intArrayOf(
+ 0x10, 0x100, 0x20, 0x10, 0x200, 0x20, 0x12, 0x100,
+ 0x0, 0x12, 0x200, 0x0, 0x27, 0x100, 0x36, 0x27,
+ 0x400, 0x34, 0x27, 0x800, 0x33, 0x27, 0x1000, 0x31,
+ 0x27, 0x2000, 0x36, 0x6000c, 0x400, 0x44, 0x6000c, 0x800,
+ 0x44, 0x6000c, 0x1000, 0x55, 0x6000c, 0x2000, 0x44, 0x60011,
+ 0x400, 0x2, 0x60011, 0x800, 0x0, 0x60011, 0x1000, 0x0,
+ 0x60011, 0x2000, 0x5, 0x60018, 0x400, 0xa1, 0x60018, 0x800,
+ 0x41, 0x60018, 0x1000, 0x21, 0x60018, 0x2000, 0xe1, 0x60027,
+ 0x400, 0x36, 0x60027, 0x800, 0x34, 0x60027, 0x1000, 0x32,
+ 0x60027, 0x2000, 0x37, 0x6002a, 0x400, 0xfb, 0x6002a, 0x800,
+ 0xf3, 0x6002a, 0x1000, 0xeb, 0x6002a, 0x2000, 0xeb, 0x6007f,
+ 0x100, 0x84, 0x6007f, 0x200, 0x4, 0x70005, 0x100, 0x40,
+ 0x70005, 0x200, 0x0, 0x70009, 0x100, 0x0, 0x70009, 0x200,
+ 0x0, 0x70046, 0x100, 0x0, 0x70046, 0x200, 0x6d, 0x70047,
+ 0x100, 0x0, 0x70047, 0x200, 0xb0, 0x7004e, 0x100, 0x0,
+ 0x7004e, 0x200, 0x55, 0x7004f, 0x100, 0x0, 0x7004f, 0x200,
+ 0x55
+ )
+ /** mt76x0_rf_ext_pa_tab: register, band mask, value. */
+ val RF_EXT_PA = intArrayOf(
+ 0x6002d, 0x400, 0x63, 0x6002d, 0x800, 0x43, 0x6002d, 0x1000,
+ 0x33, 0x6002d, 0x2000, 0x73, 0x60032, 0x400, 0x2, 0x60032,
+ 0x800, 0x2, 0x60032, 0x1000, 0x2, 0x60032, 0x2000, 0x2,
+ 0x60033, 0x400, 0x2, 0x60033, 0x800, 0x2, 0x60033, 0x1000,
+ 0x2, 0x60033, 0x2000, 0x2, 0x60034, 0x400, 0x8, 0x60034,
+ 0x800, 0x8, 0x60034, 0x1000, 0x8, 0x60034, 0x2000, 0x8,
+ 0x60035, 0x400, 0x8, 0x60035, 0x800, 0x8, 0x60035, 0x1000,
+ 0x8, 0x60035, 0x2000, 0x8, 0x60036, 0x400, 0xa, 0x60036,
+ 0x800, 0xa, 0x60036, 0x1000, 0xa, 0x60036, 0x2000, 0xa,
+ 0x60037, 0x400, 0xa, 0x60037, 0x800, 0xa, 0x60037, 0x1000,
+ 0xa, 0x60037, 0x2000, 0xa, 0x60038, 0x400, 0x5, 0x60038,
+ 0x800, 0x5, 0x60038, 0x1000, 0x5, 0x60038, 0x2000, 0x5,
+ 0x60039, 0x400, 0x5, 0x60039, 0x800, 0x5, 0x60039, 0x1000,
+ 0x5, 0x60039, 0x2000, 0x5, 0x6003a, 0x400, 0x5, 0x6003a,
+ 0x800, 0x3, 0x6003a, 0x1000, 0x2, 0x6003a, 0x2000, 0x7,
+ 0x6003b, 0x400, 0x5, 0x6003b, 0x800, 0x3, 0x6003b, 0x1000,
+ 0x2, 0x6003b, 0x2000, 0x7
+ )
+ /**
+ * mt76x0_frequency_plan, or mt76x0_sdm_frequency_plan for the channels in mt76x0_sdm_channel: channel, band mask,
+ * R37, R36, R35, R34, R33, R32 b7-5, R32 b4-0, R31 b7-5, R31 b4-0, R30 b7, R30 b6-2, R30 b1, pll_n, R28 b7-6,
+ * R28 b5-4, R28 b3-2, sdm_k, R24 b1-0, 1 when it's an SDM channel.
+ */
+ val CHANNELS = arrayOf(
+ intArrayOf(1, 0x100, 0x2, 0x3f, 0x28, 0xdd, 0xe2, 0x40, 0x2, 0x40, 0x2, 0x0, 0x0, 0x1, 0x28, 0x0, 0x30, 0x0, 0x0, 0x3, 0x0),
+ intArrayOf(2, 0x100, 0x2, 0x3f, 0x3c, 0xdd, 0xe4, 0x40, 0x7, 0x40, 0x2, 0x0, 0x0, 0x1, 0xa1, 0x0, 0x30, 0x0, 0x0, 0x1, 0x0),
+ intArrayOf(3, 0x100, 0x2, 0x3f, 0x3c, 0xdd, 0xe2, 0x40, 0x7, 0x40, 0xb, 0x0, 0x0, 0x1, 0x50, 0x0, 0x30, 0x0, 0x0, 0x0, 0x0),
+ intArrayOf(4, 0x100, 0x2, 0x3f, 0x28, 0xdd, 0xd4, 0x40, 0x2, 0x40, 0x9, 0x0, 0x0, 0x1, 0x50, 0x0, 0x30, 0x0, 0x0, 0x0, 0x0),
+ intArrayOf(5, 0x100, 0x2, 0x3f, 0x3c, 0xdd, 0xd4, 0x40, 0x7, 0x40, 0x2, 0x0, 0x0, 0x1, 0xa2, 0x0, 0x30, 0x0, 0x0, 0x1, 0x0),
+ intArrayOf(6, 0x100, 0x2, 0x3f, 0x3c, 0xdd, 0xd4, 0x40, 0x7, 0x40, 0x7, 0x0, 0x0, 0x1, 0xa2, 0x0, 0x30, 0x0, 0x0, 0x1, 0x0),
+ intArrayOf(7, 0x100, 0x2, 0x3f, 0x28, 0xdd, 0xe2, 0x40, 0x2, 0x40, 0x7, 0x0, 0x0, 0x1, 0x28, 0x0, 0x30, 0x0, 0x0, 0x3, 0x0),
+ intArrayOf(8, 0x100, 0x2, 0x3f, 0x3c, 0xdd, 0xd4, 0x40, 0x7, 0x40, 0x2, 0x0, 0x0, 0x1, 0xa3, 0x0, 0x30, 0x0, 0x0, 0x1, 0x0),
+ intArrayOf(9, 0x100, 0x2, 0x3f, 0x3c, 0xdd, 0xf2, 0x40, 0x7, 0x40, 0xd, 0x0, 0x0, 0x1, 0x28, 0x0, 0x30, 0x0, 0x0, 0x3, 0x0),
+ intArrayOf(10, 0x100, 0x2, 0x3f, 0x28, 0xdd, 0xd4, 0x40, 0x2, 0x40, 0x9, 0x0, 0x0, 0x1, 0x51, 0x0, 0x30, 0x0, 0x0, 0x0, 0x0),
+ intArrayOf(11, 0x100, 0x2, 0x3f, 0x3c, 0xdd, 0xd4, 0x40, 0x7, 0x40, 0x2, 0x0, 0x0, 0x1, 0xa4, 0x0, 0x30, 0x0, 0x0, 0x1, 0x0),
+ intArrayOf(12, 0x100, 0x2, 0x3f, 0x3c, 0xdd, 0xd4, 0x40, 0x7, 0x40, 0x7, 0x0, 0x0, 0x1, 0xa4, 0x0, 0x30, 0x0, 0x0, 0x1, 0x0),
+ intArrayOf(13, 0x100, 0x2, 0x3f, 0x28, 0xdd, 0xf2, 0x40, 0x2, 0x40, 0x2, 0x0, 0x0, 0x1, 0x29, 0x0, 0x30, 0x0, 0x0, 0x3, 0x0),
+ intArrayOf(14, 0x100, 0x2, 0x3f, 0x28, 0xdd, 0xf2, 0x40, 0x2, 0x40, 0x4, 0x0, 0x0, 0x1, 0x29, 0x0, 0x30, 0x0, 0x0, 0x3, 0x0),
+ intArrayOf(36, 0x600, 0x2, 0x3f, 0x30, 0x97, 0xd2, 0x40, 0x4, 0x40, 0x2, 0x0, 0x0, 0x1, 0x2b, 0x0, 0x30, 0x0, 0x0, 0x3, 0x0),
+ intArrayOf(40, 0x600, 0x2, 0x3f, 0x30, 0x97, 0xd2, 0x40, 0x4, 0x40, 0x4, 0x0, 0x0, 0x1, 0x2b, 0x0, 0x30, 0x0, 0x0, 0x3, 0x0),
+ intArrayOf(44, 0x600, 0x2, 0x3f, 0x30, 0x97, 0xd2, 0x40, 0x4, 0x40, 0x6, 0x0, 0x0, 0x1, 0x2b, 0x0, 0x30, 0x0, 0x0, 0x3, 0x0),
+ intArrayOf(48, 0x600, 0x2, 0x3f, 0x30, 0x97, 0xd2, 0x40, 0x4, 0x40, 0x8, 0x0, 0x0, 0x1, 0x2b, 0x0, 0x30, 0x0, 0x0, 0x3, 0x0),
+ intArrayOf(52, 0x600, 0x2, 0x3f, 0x30, 0x97, 0xd2, 0x40, 0x4, 0x40, 0xa, 0x0, 0x0, 0x1, 0x2b, 0x0, 0x30, 0x0, 0x0, 0x3, 0x0),
+ intArrayOf(56, 0x600, 0x2, 0x3f, 0x30, 0x97, 0xd2, 0x40, 0x4, 0x40, 0x0, 0x0, 0x0, 0x1, 0x2c, 0x0, 0x30, 0x0, 0x0, 0x3, 0x0),
+ intArrayOf(60, 0x600, 0x2, 0x3f, 0x30, 0x97, 0xd2, 0x40, 0x4, 0x40, 0x2, 0x0, 0x0, 0x1, 0x2c, 0x0, 0x30, 0x0, 0x0, 0x3, 0x0),
+ intArrayOf(64, 0x600, 0x2, 0x3f, 0x30, 0x97, 0xd2, 0x40, 0x4, 0x40, 0x4, 0x0, 0x0, 0x1, 0x2c, 0x0, 0x30, 0x0, 0x0, 0x3, 0x0),
+ intArrayOf(100, 0xa00, 0x2, 0x3f, 0x30, 0x97, 0xd2, 0x40, 0x4, 0x40, 0xa, 0x0, 0x0, 0x1, 0x2d, 0x0, 0x30, 0x0, 0x0, 0x3, 0x0),
+ intArrayOf(104, 0xa00, 0x2, 0x3f, 0x30, 0x97, 0xd2, 0x40, 0x4, 0x40, 0x0, 0x0, 0x0, 0x1, 0x2e, 0x0, 0x30, 0x0, 0x0, 0x3, 0x0),
+ intArrayOf(108, 0xa00, 0x2, 0x3f, 0x30, 0x97, 0xd2, 0x40, 0x4, 0x40, 0x2, 0x0, 0x0, 0x1, 0x2e, 0x0, 0x30, 0x0, 0x0, 0x3, 0x0),
+ intArrayOf(112, 0xa00, 0x2, 0x3f, 0x30, 0x97, 0xd2, 0x40, 0x4, 0x40, 0x4, 0x0, 0x0, 0x1, 0x2e, 0x0, 0x30, 0x0, 0x0, 0x3, 0x0),
+ intArrayOf(116, 0xa00, 0x2, 0x3f, 0x30, 0x97, 0xd2, 0x40, 0x4, 0x40, 0x6, 0x0, 0x0, 0x1, 0x2e, 0x0, 0x30, 0x0, 0x0, 0x3, 0x0),
+ intArrayOf(120, 0xa00, 0x2, 0x3f, 0x30, 0x97, 0xd2, 0x40, 0x4, 0x40, 0x8, 0x0, 0x0, 0x1, 0x2e, 0x0, 0x30, 0x0, 0x0, 0x3, 0x0),
+ intArrayOf(124, 0xa00, 0x2, 0x3f, 0x30, 0x97, 0xd2, 0x40, 0x4, 0x40, 0xa, 0x0, 0x0, 0x1, 0x2e, 0x0, 0x30, 0x0, 0x0, 0x3, 0x0),
+ intArrayOf(128, 0xa00, 0x2, 0x3f, 0x30, 0x97, 0xd2, 0x40, 0x4, 0x40, 0x0, 0x0, 0x0, 0x1, 0x2f, 0x0, 0x30, 0x0, 0x0, 0x3, 0x0),
+ intArrayOf(132, 0xa00, 0x2, 0x3f, 0x30, 0x97, 0xd2, 0x40, 0x4, 0x40, 0x2, 0x0, 0x0, 0x1, 0x2f, 0x0, 0x30, 0x0, 0x0, 0x3, 0x0),
+ intArrayOf(136, 0xa00, 0x2, 0x3f, 0x30, 0x97, 0xd2, 0x40, 0x4, 0x40, 0x4, 0x0, 0x0, 0x1, 0x2f, 0x0, 0x30, 0x0, 0x0, 0x3, 0x0),
+ intArrayOf(140, 0x1200, 0x2, 0x3f, 0x30, 0x97, 0xd2, 0x40, 0x4, 0x40, 0x6, 0x0, 0x0, 0x1, 0x2f, 0x0, 0x30, 0x0, 0x0, 0x3, 0x0),
+ intArrayOf(144, 0x1200, 0x2, 0x3f, 0x30, 0x97, 0xd2, 0x40, 0x4, 0x40, 0x8, 0x0, 0x0, 0x1, 0x2f, 0x0, 0x30, 0x0, 0x0, 0x3, 0x0),
+ intArrayOf(149, 0x1200, 0x2, 0x3f, 0x68, 0xdd, 0xd2, 0x40, 0x10, 0x40, 0x15, 0x0, 0x0, 0x1, 0x2f, 0x0, 0x30, 0x0, 0x0, 0x3, 0x0),
+ intArrayOf(153, 0x1200, 0x2, 0x3f, 0x7f, 0xdd, 0xc3, 0x40, 0x0, 0x80, 0x0, 0x0, 0x0, 0x0, 0x30, 0x0, 0x0, 0x8, 0x2aaa, 0x3, 0x1),
+ intArrayOf(157, 0x1200, 0x2, 0x3f, 0x68, 0xdd, 0xd2, 0x40, 0x10, 0x40, 0x5, 0x0, 0x0, 0x1, 0x30, 0x0, 0x30, 0x0, 0x0, 0x3, 0x0),
+ intArrayOf(161, 0x1200, 0x2, 0x3f, 0x68, 0xdd, 0xd2, 0x40, 0x10, 0x40, 0x9, 0x0, 0x0, 0x1, 0x30, 0x0, 0x30, 0x0, 0x0, 0x3, 0x0),
+ intArrayOf(165, 0x1200, 0x2, 0x3f, 0x7f, 0xdd, 0xc3, 0x40, 0x0, 0x80, 0x0, 0x0, 0x0, 0x0, 0x30, 0x0, 0x0, 0x8, 0x22aaa, 0x3, 0x1)
+ )
+}
diff --git a/app/src/main/java/com/rfsentinel/app/usb/Mt7612uMonitor.kt b/app/src/main/java/com/rfsentinel/app/usb/Mt7612uMonitor.kt
index fbc3dcc..d8768e3 100644
--- a/app/src/main/java/com/rfsentinel/app/usb/Mt7612uMonitor.kt
+++ b/app/src/main/java/com/rfsentinel/app/usb/Mt7612uMonitor.kt
@@ -13,6 +13,11 @@ package com.rfsentinel.app.usb
* 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.
+ *
+ * MT7610U adapters (one chain, 2.4 + 5 GHz) run here too: same USB transport, firmware upload,
+ * MCU protocol and RX format, with the bring-up and tuning of the Linux mt76x0u driver (run with
+ * [x0], tables in [Mt7610uTables]). There the host programs the radio through the MCU. Left out
+ * of that path: everything for transmitting (TSSI, TX power, beacons) and the auto-responder.
*/
import android.content.Context
@@ -84,6 +89,22 @@ object Mt7612uMonitor {
/** 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
+ // MT7610U (mt76x0u)
+ private const val USB_DMA_CFG = 0x0238; private const val DMA_TX_WL_DROP = 1 shl 16
+ private const val EFUSE_CTRL = 0x0024; private const val EFUSE_DATA = 0x0028
+ private const val CMB_CTRL = 0x0020; private const val COEXCFG3 = 0x004c; private const val CSR_EE_CFG1 = 0x0104
+ private const val WMM_CTRL = 0x0230; private const val RF_MISC = 0x0518
+ private const val TX0_RF_GAIN_CORR = 0x13a0; private const val TX0_RF_GAIN_ATTEN = 0x13a8
+ private const val TX_ALC_CFG_0 = 0x13b0; private const val TX_ALC_CFG_1 = 0x13b4; private const val TX_ALC_VGA3 = 0x13c8
+ private const val BBP_CORE0 = 0x2000; private const val BBP_IBI9 = 0x2124; private const val BBP_AGC8 = 0x2320
+ private const val BBP_TXBE0 = 0x2700; private const val BBP_TXBE5 = 0x2714
+ private const val IVB_SIZE = 0x40; private const val DLM_X0 = 0x80000; private const val FW_URB_X0 = 0x38f8
+ private const val CMD_RANDOM_READ = 10; private const val CMD_RANDOM_WRITE = 12; private const val BW_SETTING = 2
+ private const val RF_MEMMAP = 0x80000000.toInt(); private const val RF_PAIRS_PER_CMD = 24 // MT_INBAND_PACKET_MAX_LEN / 8
+ private const val X0_CAL_R = 1; private const val X0_CAL_RXDCOC = 2; private const val X0_CAL_LC = 3
+ private const val X0_CAL_VCO = 12; private const val X0_CAL_FULL = 0xff
+ private const val RF_G_BAND = 0x100; private const val RF_A_BAND = 0x200
+
private const val MIN_FRAME = 10; private const val MAX_BAD_LOGS = 12; private const val DEAF_MS = 15_000L
private const val UNCALIBRATED = " · not calibrated: unplug the adapter and plug it back in"
private const val FW_ATTEMPTS = 3; private const val CLAIM_WAITS = 10
@@ -96,6 +117,7 @@ object Mt7612uMonitor {
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 EE_ANTENNA = 0x022; private const val EE_CFG1_INIT = 0x024; private const val EE_RSSI_OFFSET_5G_1 = 0x04c; private const val EE_TSSI_BOUND4 = 0x0da
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
@@ -118,6 +140,14 @@ object Mt7612uMonitor {
@Volatile private var uncalibrated = false
private var mcuGain = 0
private var rssiOff2g = 0; private var rssiOff5g = 0; private var lna2g = 0; private var lna5g = 0
+ /** Running an MT7610U ([run]'s x0): its 5 GHz LNA gain per sub-band, EEPROM words, and crystal trim. */
+ private var x0 = false
+ private var tag = "MT7612U"
+ private val lnaX0 = IntArray(3)
+ private var conf0X0 = 0
+ private var freqOffsetX0 = 0
+ private var antCfgX0 = 0 to 0
+ private var antConf2X0 = 0
/** Chain 1's RSSI offsets (the EEPROM words' high bytes, as mt76x2_read_rx_gain reads them). */
private var rssiOff2g1 = 0; private var rssiOff5g1 = 0
private val lastCalMs = HashMap<Int, Long>()
@@ -126,8 +156,9 @@ object Mt7612uMonitor {
fun abort() { stop = true }
fun run(ctx: Context, device: UsbDevice, chipName: String, onStatus: (String) -> Unit,
- onFrame: (List<MonitorSighting>) -> Unit) {
+ onFrame: (List<MonitorSighting>) -> Unit, x0: Boolean = false) {
if (running) return
+ this.x0 = x0; tag = if (x0) "MT7610U" else "MT7612U"
HOP = UsbWifi.hops(ALL_HOP)
running = true; stop = false; frames.clear(); lastCalMs.clear(); mcuLogged = 0; ctlErrors = 0; mcuAsked = 0; mcuAnswered = 0; uncalibrated = false
val mgr = ctx.getSystemService(Context.USB_SERVICE) as UsbManager
@@ -140,8 +171,8 @@ object Mt7612uMonitor {
var claimed = c.claimInterface(intf, true)
var waits = 0
while (!claimed && waits < CLAIM_WAITS && !stop) { sleep(300); waits++; claimed = c.claimInterface(intf, true) }
- if (!claimed) UsbWifi.log("MT7612U: couldn't claim the USB interface after ${waits * 300} ms (continuing)")
- else if (waits > 0) UsbWifi.log("MT7612U: USB interface claimed after ${waits * 300} ms")
+ if (!claimed) UsbWifi.log("$tag: couldn't claim the USB interface after ${waits * 300} ms (continuing)")
+ else if (waits > 0) UsbWifi.log("$tag: USB interface claimed after ${waits * 300} ms")
val bulkIn = ArrayList<UsbEndpoint>(); val bulkOut = ArrayList<UsbEndpoint>()
for (i in 0 until intf.endpointCount) {
val ep = intf.getEndpoint(i)
@@ -149,10 +180,11 @@ object Mt7612uMonitor {
}
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) }}]")
+ UsbWifi.log("=== $tag bring-up (${if (x0) "mt76x0u" else "mt76x2u"}) ===")
+ UsbWifi.log("$tag: 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()
+ if (x0) { runX0(ctx, device, chipName, cmdOut, rx, bulkOut + bulkIn, t0, onFrame, onStatus); return }
// ---- firmware ----
val ver = regRd(ASIC_VERSION)
@@ -219,7 +251,7 @@ object Mt7612uMonitor {
onStatus("$chipName · live · 2.4 + 5 GHz monitor" + UNCALIBRATED.takeIf { uncalibrated }.orEmpty())
rxLoop(chipName, cmdOut, rx, onFrame, onStatus)
} catch (e: Exception) {
- UsbWifi.log("MT7612U: bring-up error - ${UsbWifi.describe(e)}")
+ UsbWifi.log("$tag: bring-up error - ${UsbWifi.describe(e)}")
onStatus("$chipName: error · ${e.message}")
} finally {
runCatching { c.close() }
@@ -288,8 +320,8 @@ object Mt7612uMonitor {
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) break
- if (++tries >= 3) { UsbWifi.log("MT7612U: firmware upload failed at $pos of $dataLen B"); return false }
- UsbWifi.log("MT7612U: firmware chunk at $pos of $dataLen B not taken - resending")
+ if (++tries >= 3) { UsbWifi.log("$tag: firmware upload failed at $pos of $dataLen B"); return false }
+ UsbWifi.log("$tag: firmware chunk at $pos of $dataLen B not taken - resending")
sleep(20)
}
regWr(TX_CPU_FROM_FCE_CPU_DESC_IDX, regRd(TX_CPU_FROM_FCE_CPU_DESC_IDX) + 1)
@@ -375,6 +407,7 @@ object Mt7612uMonitor {
/** 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) {
+ if (x0) { tuneX0(ep, ch, scan); return }
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) }
@@ -472,8 +505,13 @@ object Mt7612uMonitor {
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)
+ if (x0) {
+ val v = regRd(USB_DMA_CFG)
+ regWr(USB_DMA_CFG, v and DMA_RX_BULK_EN.inv()); regWr(USB_DMA_CFG, v or DMA_RX_BULK_EN)
+ } else {
+ 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)
}
@@ -488,16 +526,16 @@ object Mt7612uMonitor {
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, RX_BUF, { stop }, onData@{ b, n ->
+ val stats = BulkRx.Stats(tag)
+ val total = BulkRx.run(tag, conn, ep, 24, RX_BUF, { 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++ },
- why = { if (st.badLogged < MAX_BAD_LOGS) { st.badLogged++; UsbWifi.log("MT7612U: transfer dropped - $it") } }) ?: return@onData
+ why = { if (st.badLogged < MAX_BAD_LOGS) { st.badLogged++; UsbWifi.log("$tag: transfer dropped - $it") } }) ?: return@onData
val rssi = f.rawRssi?.let { if (ch <= 14) it + rssiOff2g - lna2g else it + rssiOff5g - lna5g }
- val rssi1 = f.rawRssi1?.let { if (ch <= 14) it + rssiOff2g1 - lna2g else it + rssiOff5g1 - lna5g }
+ val rssi1 = f.rawRssi1?.takeUnless { x0 }?.let { if (ch <= 14) it + rssiOff2g1 - lna2g else it + rssiOff5g1 - lna5g } // MT7610U: one chain
stats.frame(rssi)
frames.frame(b, f.start, f.end, ch, rssi, pathA = rssi, pathB = rssi1)
}) { now ->
@@ -511,7 +549,7 @@ object Mt7612uMonitor {
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")
+ UsbWifi.log("$tag: receive stalled (${(now - st.lastRxAt) / 1000} s) - restarting it")
runCatching { reKickRx() }
st.lastRxAt = now
} else if (now - st.lastRxAt > DEAF_MS) {
@@ -519,7 +557,7 @@ object Mt7612uMonitor {
// lost its calibration (seen after a quick restart without a replug). Switch it
// back on and fully retune.
val sys = regRd(MAC_SYS_CTRL)
- if (st.revivals < 5) UsbWifi.log("MT7612U: nothing received for ${(now - st.lastRxAt) / 1000} s (SYS_CTRL 0x%08x) - re-enabling the receiver".format(sys))
+ if (st.revivals < 5) UsbWifi.log("$tag: nothing received for ${(now - st.lastRxAt) / 1000} s (SYS_CTRL 0x%08x) - re-enabling the receiver".format(sys))
st.revivals++
runCatching {
if (sys and SYS_CTRL_ENABLE_RX == 0) macStart() else reKickRx()
@@ -543,7 +581,7 @@ object Mt7612uMonitor {
}
}
frames.emit(FRESH_MS, onFrame)
- UsbWifi.log("MT7612U: RX loop stopped ($total B)")
+ UsbWifi.log("$tag: RX loop stopped ($total B)")
}
/** Where the 802.11 frame sits in a transfer and the radio's raw RSSI per chain (0 and 1, before calibration; null when absent). */
@@ -631,6 +669,332 @@ object Mt7612uMonitor {
return ee
}
+ // ---- MT7610U (mt76x0u): bring-up, in the order of mt76x0u_probe / _init_hardware / _start ----
+
+ private fun runX0(ctx: Context, device: UsbDevice, chipName: String, cmdOut: UsbEndpoint, rx: UsbEndpoint, endpoints: List<UsbEndpoint>,
+ t0: Long, onFrame: (List<MonitorSighting>) -> Unit, onStatus: (String) -> Unit) {
+ onStatus("$chipName · powering on…")
+ chipOnOffX0(enable = false, reset = false) // otherwise the MCU fails to start on a warm adapter
+ if (!macReadyX0()) { onStatus("$chipName: MAC not ready - unplug the adapter and plug it back in"); return }
+ val ver = regRd(ASIC_VERSION)
+ UsbWifi.log("MT7610U: ASIC_VERSION 0x%08x".format(ver))
+ if (ver ushr 16 != 0x7610) { onStatus("$chipName: this MediaTek chip (%04x) isn't supported yet".format(ver ushr 16)); return }
+ chipOnOffX0(enable = true, reset = true)
+ if (!macReadyX0()) { onStatus("$chipName: MAC not ready - unplug the adapter and plug it back in"); return }
+
+ onStatus("$chipName · loading firmware…")
+ val fw = Firmware.read(ctx, "mt7610u.bin")
+ var loaded = false
+ for (attempt in 1..FW_ATTEMPTS) {
+ if (attempt > 1) {
+ UsbWifi.log("MT7610U: retrying the firmware load (attempt $attempt of $FW_ATTEMPTS)")
+ sleep(1000)
+ chipOnOffX0(enable = true, reset = true)
+ }
+ for (ep in endpoints) clearHalt(ep)
+ if (loadFirmwareX0(cmdOut, fw)) { loaded = true; break }
+ }
+ if (!loaded) { onStatus("$chipName: firmware didn't load - unplug the adapter and plug it back in"); return }
+
+ onStatus("$chipName · starting the radio…")
+ initDmaX0()
+ if (!initHardwareX0(cmdOut)) { onStatus("$chipName: radio didn't start - unplug the adapter and plug it back in"); return }
+ val board = (conf0X0 ushr 12) and 3 // BOARD_TYPE: 1 = 2.4 GHz only, 2 = 5 GHz only
+ val has2 = board != 2 && !(device.vendorId == 0x2357 && device.productId == 0x0105) // Archer T1U: 5 GHz only
+ val has5 = board != 1
+ antSelectX0(has2, has5)
+ rfInitX0(cmdOut)
+ regClear(BBP_AGC0, (1 shl 4) or (1 shl 3)) // RX path: the one chain
+ regClear(BBP_TXBE5, 0x3)
+ regRmw(US_CYC_CFG, 0xff, 0x1e)
+ regWr(TXOP_CTRL_CFG, 0x583f)
+ HOP = HOP.filter { if (it <= 14) has2 else has5 }.toIntArray()
+ if (HOP.isEmpty()) { onStatus("$chipName: this adapter's band is turned off in Settings"); return }
+
+ onStatus("$chipName · tuning and calibrating…")
+ macStart()
+ calibrateX0(cmdOut, HOP[0], powerOn = true)
+ tune(cmdOut, HOP[0], scan = false)
+ UsbWifi.log("MT7610U: started in %d ms - SYS_CTRL 0x%08x STATUS 0x%08x USB_DMA 0x%08x RX_FILTR 0x%08x AUTO_RSP 0x%08x, USB errors %d - monitor live ch %d".format(
+ System.currentTimeMillis() - t0, regRd(MAC_SYS_CTRL), regRd(MAC_STATUS), regRd(USB_DMA_CFG), regRd(RX_FILTR_CFG),
+ regRd(AUTO_RSP_CFG), ctlErrors, HOP[0]))
+ uncalibrated = mcuAsked >= 3 && mcuAnswered == 0
+ onStatus("$chipName · live · monitor" + UNCALIBRATED.takeIf { uncalibrated }.orEmpty())
+ rxLoop(chipName, cmdOut, rx, onFrame, onStatus)
+ }
+
+ private fun macReadyX0() = poll(2500, 5) { regRd(MAC_CSR0).let { it != 0 && it != -1 } }
+
+ /** mt76x0_chip_onoff. */
+ private fun chipOnOffX0(enable: Boolean, reset: Boolean) {
+ var v = regRd(WLAN_FUN_CTRL)
+ if (reset) {
+ v = (v or (0xff shl 24)) and FRC_WL_ANT_SEL.inv() // GPIO_OUT_EN
+ if (v and WLAN_EN != 0) {
+ val resets = (1 shl 3) or WLAN_RESET_RF
+ regWr(WLAN_FUN_CTRL, v or resets); sleep(1)
+ v = v and resets.inv()
+ }
+ }
+ regWr(WLAN_FUN_CTRL, v); sleep(1)
+ v = if (enable) v or WLAN_EN or WLAN_CLK_EN else v and WLAN_EN.inv()
+ regWr(WLAN_FUN_CTRL, v); sleep(1)
+ val locked = (1 shl 22) or (1 shl 23) // XTAL_RDY, PLL_LD
+ if (enable && !poll(2000, 2) { regRd(CMB_CTRL) and locked == locked }) UsbWifi.log("MT7610U: PLL and crystal check failed (continuing)")
+ }
+
+ /** mt76x0u_load_firmware. */
+ private fun loadFirmwareX0(out: UsbEndpoint, fw: ByteArray): Boolean {
+ regWr(USB_DMA_CFG, DMA_RX_BULK_EN or DMA_TX_BULK_EN)
+ if (regRd(MCU_COM_REG0) == 1) { UsbWifi.log("MT7610U: firmware already running"); return true }
+ if (fw.size <= FW_HDR_LEN) return false
+ val ilmLen = le32(fw, 0); val dlmLen = le32(fw, 4)
+ if (ilmLen <= IVB_SIZE || FW_HDR_LEN + ilmLen + dlmLen != fw.size) { UsbWifi.log("MT7610U: firmware file size mismatch"); return false }
+ UsbWifi.log("MT7610U: firmware build '${asciiz(fw, 16, 16)}', ILM $ilmLen B, DLM $dlmLen B")
+ regWr(MAC_SYS_CTRL, 0x2c)
+ regSet(USB_DMA_CFG, DMA_RX_BULK_EN or DMA_TX_BULK_EN or 0x20)
+ vendor(DEV_MODE, OUT_VENDOR, 0x1, null) // firmware reset
+ sleep(6)
+ configureFce()
+ regSet(USB_DMA_CFG, DMA_TX_WL_DROP); regClear(USB_DMA_CFG, DMA_TX_WL_DROP)
+ if (!sendFw(out, fw, FW_HDR_LEN + IVB_SIZE, ilmLen - IVB_SIZE, FW_URB_X0, IVB_SIZE)) return false
+ if (!sendFw(out, fw, FW_HDR_LEN + ilmLen, dlmLen, FW_URB_X0, DLM_X0)) return false
+ vendor(DEV_MODE, OUT_VENDOR, 0x12, fw.copyOfRange(FW_HDR_LEN, FW_HDR_LEN + IVB_SIZE)) // start from the IVB
+ if (!poll(1000, 10) { regRd(MCU_COM_REG0) and 0x1 == 0x1 }) { UsbWifi.log("MT7610U: firmware failed to start"); return false }
+ regWr(FCE_PSE_CTRL, 0x1)
+ UsbWifi.log("MT7610U: firmware running")
+ return true
+ }
+
+ /** mt76x0_init_usb_dma. */
+ private fun initDmaX0() {
+ val v = (regRd(USB_DMA_CFG) or DMA_RX_BULK_EN or DMA_TX_BULK_EN) and DMA_RX_BULK_AGG_EN.inv() // one frame per transfer
+ regWr(USB_DMA_CFG, v)
+ regWr(USB_DMA_CFG, v or DMA_RX_DROP_OR_PAD)
+ regWr(USB_DMA_CFG, v and DMA_RX_DROP_OR_PAD.inv())
+ }
+
+ /** mt76x0_init_hardware up to the EEPROM; its shared key and WCID clearing only matters to a client. */
+ private fun initHardwareX0(ep: UsbEndpoint): Boolean {
+ if (!waitWpdma()) UsbWifi.log("MT7610U: DMA still busy after the firmware (continuing)")
+ if (!macReadyX0()) return false
+ regWr(MAC_SYS_CTRL, SYS_CTRL_RESET_CSR or SYS_CTRL_RESET_BBP); sleep(200)
+ regClear(MAC_SYS_CTRL, SYS_CTRL_RESET_CSR or SYS_CTRL_RESET_BBP)
+ mcuX0(ep, CMD_FUN_SET_OP, leWords(Q_SELECT, 1), false)
+ writeAll(Mt7610uTables.MAC)
+ regClear(MAC_SYS_CTRL, SYS_CTRL_RESET_CSR or SYS_CTRL_RESET_BBP)
+ regSet(EXT_CCA_CFG, 0xf000)
+ regClear(FCE_L2_STUFF, 1 shl 4)
+ regRmw(WMM_CTRL, 0x3ff, 0x201)
+ if (!poll(100, 2) { regRd(MAC_STATUS) and 3 == 0 }) { UsbWifi.log("MT7610U: MAC not idle"); return false }
+ if ((1..20).none { regRd(BBP_CORE0).let { v -> v != 0 && v != -1 } }) { UsbWifi.log("MT7610U: BBP not ready"); return false }
+ writeAll(Mt7610uTables.BBP_INIT); writeAll(Mt7610uTables.BBP_2G); writeAll(Mt7610uTables.BBP_DCOC)
+ val ee = readEfuse()
+ conf0X0 = le16(ee, EE_NIC_CONF_0)
+ calFromEfuse(ee)
+ UsbWifi.log("MT7610U: EFUSE MAC %s:xx:xx:xx, NIC_CONF 0x%04x, rssi_off 2g %d 5g %d, lna 2g %d 5g %s, freq offset %d".format(
+ (0 until 3).joinToString(":") { "%02x".format(ee[EE_MAC_ADDR + it].toInt() and 0xff) },
+ conf0X0, rssiOff2g, rssiOff5g, lna2g, lnaX0.joinToString("/"), freqOffsetX0))
+ antCfgX0 = le16(ee, EE_ANTENNA) to le16(ee, EE_CFG1_INIT)
+ antConf2X0 = le16(ee, EE_NIC_CONF_2)
+ return true
+ }
+
+ private fun writeAll(tab: IntArray) { for (i in tab.indices step 2) regWr(tab[i], tab[i + 1]) }
+
+ /** mt76x02_efuse_read over the 512 B map, 16 B per read: unwritten blocks read as 0xff. */
+ private fun readEfuse(): ByteArray {
+ val ee = ByteArray(EE_SIZE)
+ for (addr in 0 until EE_SIZE step 16) {
+ regWr(EFUSE_CTRL, (regRd(EFUSE_CTRL) and (0x03ff0000 or 0xc0).inv()) or (addr shl 16) or (1 shl 30))
+ if (!poll(1000, 1) { regRd(EFUSE_CTRL) and (1 shl 30) == 0 }) UsbWifi.log("MT7610U: EFUSE read timed out at $addr")
+ if (regRd(EFUSE_CTRL) and 0x3f == 0x3f) ee.fill(0xff.toByte(), addr, addr + 16)
+ else for (i in 0 until 4) putLe32(ee, addr + i * 4, regRd(EFUSE_DATA + i * 4))
+ }
+ return ee
+ }
+
+ /** mt76x0_set_freq_offset and mt76x0_read_rx_gain. */
+ internal fun x0FreqOffset(trim: Int, compensation: Int): Int {
+ val valid = { v: Int -> v != 0 && v != 0xff }
+ val base = if (valid(trim)) trim else 0
+ val c = if (valid(compensation)) compensation else 0
+ val delta = if (c and 0x80 != 0) c and 0x7f else -(c and 0x7f) // mt76x02_sign_extend: the top bit set means positive
+ return (base - delta) and 0xff
+ }
+
+ private fun calFromEfuse(ee: ByteArray) {
+ fun u8(i: Int) = ee[i].toInt() and 0xff
+ fun offset(i: Int) = ee[i].toInt().takeIf { it in -10..10 } ?: 0
+ fun lna(v: Int) = if (v == 0xff) 0 else v.toByte().toInt()
+ freqOffsetX0 = x0FreqOffset(u8(EE_XTAL_TRIM_1), u8(EE_TSSI_BOUND4 + 1))
+ rssiOff2g = offset(EE_RSSI_OFFSET_2G_0); rssiOff5g = offset(EE_RSSI_OFFSET_5G_0)
+ lna2g = lna(u8(EE_LNA_GAIN))
+ val l0 = u8(EE_LNA_GAIN + 1)
+ fun orFirst(v: Int) = if (v != 0 && v != 0xff) v else l0
+ lnaX0[0] = lna(l0); lnaX0[1] = lna(orFirst(u8(EE_RSSI_OFFSET_2G_1 + 1))); lnaX0[2] = lna(orFirst(u8(EE_RSSI_OFFSET_5G_1 + 1)))
+ lna5g = lnaX0[0]
+ }
+
+ /** mt76x0_phy_ant_select. */
+ private fun antSelectX0(has2: Boolean, has5: Boolean) {
+ var ant = antCfgX0.first and ((1 shl 14) or (1 shl 12)).inv()
+ var wlan = regRd(WLAN_FUN_CTRL) and ((1 shl 6) or (1 shl 5)).inv()
+ var coex3 = regRd(COEXCFG3) and (0xf shl 2).inv()
+ if (ant and (1 shl 15) != 0) { // dual antenna
+ val diversity = antConf2X0 and (1 shl 3) == 0 && antConf2X0 and (1 shl 4) != 0
+ if (diversity) ant = ant or (1 shl 12) else coex3 = coex3 or (1 shl 4)
+ coex3 = coex3 or (1 shl 3)
+ if (has2) wlan = wlan or (1 shl 6)
+ } else if (has5) coex3 = coex3 or (1 shl 3) or (1 shl 4)
+ else { wlan = wlan or (1 shl 6); coex3 = coex3 or (1 shl 1) }
+ regWr(WLAN_FUN_CTRL, wlan)
+ regRmw(CMB_CTRL, 0xffff, ant)
+ regRmw(CSR_EE_CFG1, 0xffff, antCfgX0.second)
+ regClear(COEXCFG0, 1 shl 2)
+ regWr(COEXCFG3, coex3)
+ }
+
+ /** mt76x0_phy_rf_init. */
+ private fun rfInitX0(ep: UsbEndpoint) {
+ rfWrAll(ep, Mt7610uTables.RF_CENTRAL); rfWrAll(ep, Mt7610uTables.RF_2G)
+ rfWrAll(ep, Mt7610uTables.RF_5G); rfWrAll(ep, Mt7610uTables.RF_VGA)
+ rfWrAll(ep, Mt7610uTables.RF_BW_INIT)
+ rfWrAll(ep, rfRows(Mt7610uTables.RF_BAND, RF_G_BAND))
+ rfWr(ep, rf(0, 22), minOf(freqOffsetX0, 0xbf))
+ rfRd(ep, rf(0, 22))
+ rfRmw(ep, rf(0, 73), 0, 0x80); rfRmw(ep, rf(0, 73), 0x80, 0); rfRmw(ep, rf(0, 73), 0, 0x80) // DAC reset
+ rfRmw(ep, rf(0, 4), 0, 0x80) // VCO calibration
+ }
+
+ /** mt76x0_phy_set_channel at 20 MHz, without the transmit power. */
+ private fun tuneX0(ep: UsbEndpoint, ch: Int, scan: Boolean) {
+ val f = Mt7610uTables.CHANNELS.firstOrNull { it[0] == ch } ?: return
+ val is5 = ch > 14
+ mcuX0(ep, CMD_FUN_SET_OP, leWords(BW_SETTING, 0), true)
+ regRmw(BBP_CORE1, 0x18, 0)
+ regRmw(BBP_AGC0, 0x7000 or 0x300, 1 shl 12)
+ regRmw(BBP_TXBE0, 0x3, 0)
+ regRmw(TX_BAND_CFG, 0x7, if (is5) 1 shl 1 else 1 shl 2)
+ regRmw(EXT_CCA_CFG, 0xfff, (1 shl 2) or (2 shl 4) or (3 shl 6) or (1 shl 8))
+ // mt76x0_phy_set_band
+ rfWrAll(ep, if (is5) Mt7610uTables.RF_5G else Mt7610uTables.RF_2G)
+ rfWr(ep, rf(5, 0), if (is5) 0x44 else 0x45)
+ rfWr(ep, rf(6, 0), if (is5) 0x45 else 0x44)
+ regWr(TX_ALC_VGA3, if (is5) 0x00000005 else 0x00050007)
+ regWr(TX0_RF_GAIN_CORR, if (is5) 0x01010102 else 0x003E0002)
+ setChanRfX0(ep, f)
+ if (ch == 14) regSet(BBP_CORE1, 0x20) else regClear(BBP_CORE1, 0x20)
+ // mt76x0_read_rx_gain, then mt76x0_phy_set_chan_bbp_params
+ if (is5) lna5g = lnaX0[if (ch <= 64) 0 else if (ch <= 128) 1 else 2]
+ val tab = if (is5) Mt7610uTables.BBP_5G else Mt7610uTables.BBP_2G
+ for (i in tab.indices step 2) regWr(tab[i], if (tab[i] == BBP_AGC8) x0AgcGain(tab[i + 1], if (is5) lna5g else lna2g) else tab[i + 1])
+ rfRmw(ep, rf(0, 4), 0, 0x80) // VCO on
+ // Linux skips calibration only while scanning; a monitor is always hopping, so as on the MT7612U each channel gets it every 30 s.
+ val now = System.currentTimeMillis()
+ if (!scan || now - (lastCalMs[ch] ?: 0L) > CAL_TTL_MS) { calibrateX0(ep, ch, powerOn = false); lastCalMs[ch] = now }
+ }
+
+ /** The AGC value with its gain field (bits 14:8) lowered by twice the LNA gain. */
+ internal fun x0AgcGain(v: Int, lna: Int) = (v and (0x7f shl 8).inv()) or (((((v ushr 8) and 0x7f) - lna * 2) and 0x7f) shl 8)
+
+ /** mt76x0_phy_set_chan_rf_params; [f] is a row of [Mt7610uTables.CHANNELS]. */
+ private fun setChanRfX0(ep: UsbEndpoint, f: IntArray) {
+ val band = f[1]; val sdm = f[20] == 1
+ rfWr(ep, rf(0, 37), f[2]); rfWr(ep, rf(0, 36), f[3]); rfWr(ep, rf(0, 35), f[4])
+ rfWr(ep, rf(0, 34), f[5]); rfWr(ep, rf(0, 33), f[6])
+ rfRmw(ep, rf(0, 32), 0xe0, f[7]); rfRmw(ep, rf(0, 32), 0x1f, f[8])
+ rfRmw(ep, rf(0, 31), 0xe0, f[9]); rfRmw(ep, rf(0, 31), 0x1f, f[10])
+ if (sdm) { rfRmw(ep, rf(0, 30), 0x80, 0); rfRmw(ep, rf(0, 30), 0, 0x80) } else rfRmw(ep, rf(0, 30), 0x80, f[11])
+ rfRmw(ep, rf(0, 30), 0x7c, f[12])
+ rfRmw(ep, rf(0, 30), 0x02, f[13] shl 1)
+ rfWr(ep, rf(0, 29), f[14] and 0xff)
+ rfRmw(ep, rf(0, 30), 0x01, (f[14] ushr 8) and 0x1)
+ rfRmw(ep, rf(0, 28), 0xc0, f[15]); rfRmw(ep, rf(0, 28), 0x30, f[16]); rfRmw(ep, rf(0, 28), 0x0c, f[17])
+ rfWr(ep, rf(0, 26), f[18] and 0xff); rfWr(ep, rf(0, 27), (f[18] ushr 8) and 0xff)
+ rfRmw(ep, rf(0, 28), 0x03, (f[18] ushr 16) and 0x3)
+ rfRmw(ep, rf(0, 24), 0x03, f[19])
+ rfWrAll(ep, rfRows(Mt7610uTables.RF_BW, band, anyBand = true))
+ rfWrAll(ep, rfRows(Mt7610uTables.RF_BAND, band))
+ regClear(RF_MISC, 0xc)
+ val is2 = band and RF_G_BAND != 0
+ if (conf0X0 and (if (is2) 1 shl 8 else 1 shl 9) == 0) { // external PA
+ regSet(RF_MISC, if (is2) 1 shl 3 else 1 shl 2)
+ rfWrAll(ep, rfRows(Mt7610uTables.RF_EXT_PA, band))
+ }
+ regWr(TX0_RF_GAIN_ATTEN, if (is2) 0x63707400 else 0x686A7800)
+ regWr(TX_ALC_CFG_1, regRd(TX_ALC_CFG_1) and (if (is2) 0x896400FF else 0x890400FF).toInt())
+ }
+
+ /** mt76x0_phy_calibrate, without the TSSI step: that one drives the transmit path. */
+ private fun calibrateX0(ep: UsbEndpoint, ch: Int, powerOn: Boolean) {
+ fun cal(id: Int, v: Int) { mcuX0(ep, CMD_CALIBRATION_OP, leWords(id, v), true) }
+ if (powerOn) { cal(X0_CAL_R, 0); cal(X0_CAL_VCO, ch) }
+ val txAlc = regRd(TX_ALC_CFG_0)
+ regWr(TX_ALC_CFG_0, 0); sleep(1)
+ val ibi9 = regRd(BBP_IBI9)
+ regWr(BBP_IBI9, 0xffffff7e.toInt())
+ val is5 = ch > 14
+ cal(X0_CAL_FULL, if (!is5) 0x600 else if (ch < 100) 0x701 else if (ch < 140) 0x801 else 0x901)
+ cal(X0_CAL_LC, if (is5) 1 else 0)
+ sleep(16)
+ regWr(BBP_IBI9, ibi9)
+ regWr(TX_ALC_CFG_0, txAlc)
+ cal(X0_CAL_RXDCOC, 1)
+ }
+
+ private fun rf(bank: Int, reg: Int) = (bank shl 16) or reg
+
+ /** The register, value pairs of a register, band mask, value table that apply to [band]. */
+ private fun rfRows(tab: IntArray, band: Int, anyBand: Boolean = false): IntArray {
+ val out = ArrayList<Int>()
+ for (i in tab.indices step 3) if (tab[i + 1] and band != 0 || anyBand && tab[i + 1] == 0) { out += tab[i]; out += tab[i + 2] }
+ return out.toIntArray()
+ }
+
+ /** mt76x02u_mcu_wr_rp: USB reaches the radio's registers only through the MCU; only the last command waits. */
+ private fun rfWrAll(ep: UsbEndpoint, pairs: IntArray) {
+ var i = 0
+ while (i < pairs.size) {
+ val end = minOf(i + RF_PAIRS_PER_CMD * 2, pairs.size)
+ val m = IntArray(end - i) { k -> if (k % 2 == 0) RF_MEMMAP + pairs[i + k] else pairs[i + k] }
+ mcuX0(ep, CMD_RANDOM_WRITE, leWords(*m), end == pairs.size)
+ i = end
+ }
+ }
+ private fun rfWr(ep: UsbEndpoint, reg: Int, v: Int) = rfWrAll(ep, intArrayOf(reg, v))
+
+ /** The register's value, or -1 when the MCU didn't answer. */
+ private fun rfRd(ep: UsbEndpoint, reg: Int): Int {
+ val r = mcuX0(ep, CMD_RANDOM_READ, leWords(RF_MEMMAP + reg, 0), true) ?: return -1
+ return le32(r, 8) and 0xff // | FCE info | register | value |
+ }
+ private fun rfRmw(ep: UsbEndpoint, reg: Int, mask: Int, v: Int) {
+ val cur = rfRd(ep, reg)
+ if (cur >= 0) rfWr(ep, reg, v or (cur and mask.inv()))
+ }
+
+ /** __mt76x02u_mcu_send_msg: sequence 0 asks for no answer. The answer, or null. */
+ private fun mcuX0(ep: UsbEndpoint, cmd: Int, payload: ByteArray, wait: Boolean): ByteArray? {
+ var s = 0
+ if (wait) { seq = (seq + 1) and 0xf; if (seq == 0) seq = 1; s = seq }
+ val rounded = (payload.size + 3) and 3.inv()
+ val buf = ByteArray(4 + rounded + 4)
+ putLe32(buf, 0, (rounded and 0xffff) or (2 shl 27) or (s shl 16) or (cmd shl 20) or (1 shl 30))
+ System.arraycopy(payload, 0, buf, 4, payload.size)
+ if (conn.bulkTransfer(ep, buf, buf.size, 500) < 0) ctlErrors++
+ if (!wait) return null
+ mcuAsked++
+ val rep = epResp ?: run { sleep(10); return null }
+ val rb = ByteArray(1024)
+ repeat(5) {
+ val n = conn.bulkTransfer(rep, rb, rb.size, 300)
+ if (n >= 4 && (le32(rb, 0) ushr 16) and 0xf == s) { mcuAnswered++; return rb }
+ }
+ if (mcuLogged < 6) { mcuLogged++; UsbWifi.log("MT7610U: MCU cmd $cmd - no answer") }
+ return null
+ }
+
// ---- register access ----
/** Standard CLEAR_FEATURE(ENDPOINT_HALT) on [ep]. */
diff --git a/app/src/main/java/com/rfsentinel/app/usb/NOTICE.md b/app/src/main/java/com/rfsentinel/app/usb/NOTICE.md
index d309d61..765ec99 100644
--- a/app/src/main/java/com/rfsentinel/app/usb/NOTICE.md
+++ b/app/src/main/java/com/rfsentinel/app/usb/NOTICE.md
@@ -8,7 +8,7 @@ These drivers run USB WiFi adapters in receive-only monitor mode from userspace.
- `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) and RT5370 / RT5372 ones, 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`.
+- `Mt7612uMonitor.kt` drives MediaTek MT7612U / MT7632U adapters (e.g. ALFA AWUS036ACM), 2.4 + 5 GHz, with MediaTek's firmware in `assets/usbwifi/mt7662*.bin`. It also drives MT7610U adapters (e.g. TP-Link Archer T2UHP), 2.4 + 5 GHz - experimental - with the tables in `Mt7610uTables.kt` and MediaTek's firmware in `assets/usbwifi/mt7610u.bin`.
- `Mt7921uMonitor.kt` drives MediaTek MT7921AU WiFi 6E adapters (e.g. ALFA AWUS036AXML), 2.4 + 5 + 6 GHz - experimental - with MediaTek's ROM patch and firmware in `assets/usbwifi/WIFI_*MT7961*.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.
@@ -30,6 +30,8 @@ These drivers run USB WiFi adapters in receive-only monitor mode from userspace.
| 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 |
+| MT7610U bring-up, channel tuning and calibration; register tables in `Mt7610uTables.kt` | Linux `mt76x0` (`initvals.h`, `initvals_init.h`, `initvals_phy.h`, `phy.c`, `init.c`, `usb.c`, `usb_mcu.c`; Ralink Technology, Felix Fietkau, Jakub Kicinski, Stanislaw Gruszka, Lorenzo Bianconi) | GPL-2.0 |
+| MT7610U firmware `mt7610u.bin` (unmodified, from linux-firmware) | Ralink, a MediaTek company | Redistributable binary, see `assets/usbwifi/LICENCE.ralink_a_mediatek_company_firmware` |
| 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` |
| MT7921AU userspace USB driver (WFSYS reset, USB / WFDMA setup, ROM patch and firmware download, MCU command framing, efuse calibration push, monitor filters and sniffer mode, channel switching, RX descriptor parsing) | [mt76-usb-macos](https://github.com/Network-Weather/mt76-usb-macos) by Network Weather (Copyright (c) 2026 Primatech Paper Co LLC d/b/a Network Weather), a transcription of the MT7921 path of the Linux mt76 driver ([openwrt/mt76](https://github.com/openwrt/mt76): Copyright (C) 2020-2023 MediaTek Inc., (C) 2018 Lorenzo Bianconi, (C) 2016 Felix Fietkau) | BSD-3-Clause-Clear |
| MT7921AU ROM patch `WIFI_MT7961_patch_mcu_1_2_hdr.bin` and firmware `WIFI_RAM_CODE_MT7961_1.bin` (unmodified, from linux-firmware commit e981caea6ed3) | MediaTek Inc. | Redistributable binary, see `assets/usbwifi/LICENCE.mediatek` |
@@ -40,7 +42,7 @@ These drivers run USB WiFi adapters in receive-only monitor mode from userspace.
| MT7921AU Bluetooth firmware `BT_RAM_CODE_MT7961_1_2_hdr.bin` (unmodified, from linux-firmware) | MediaTek Inc. | Redistributable binary, see `assets/usbwifi/LICENCE.mediatek` |
| Realtek Bluetooth firmware and config files `bt_rtl*.bin` (unmodified, from linux-firmware `rtl_bt/`) | Realtek Semiconductor Corp. | Redistributable binary, see `assets/usbwifi/LICENCE.rtlwifi_firmware.txt` |
| RTL-SDR driver (`sdr/RtlSdr.kt`: RTL2832U baseband, R820T / R828D tuner, RTL-SDR Blog V4 and V4L band switching) | [librtlsdr](https://github.com/osmocom/rtl-sdr) (osmocom: Steve Markgraf, Dimitri Stolnikov and others; R82xx code by Mauro Carvalho Chehab and Steve Markgraf; Blog V4 support by RTL-SDR Blog) | GPL-2.0-or-later |
-| 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; MT7921AU: Android USB host API instead of IOKit, no port reset, commands while receiving answered on the shared endpoint without blocking, bad-checksum frames dropped, failed register reads never written back, every transmit path (injection, TX descriptors) left out | RF Sentinel (CIS-C0) | GPL-3.0 |
+| 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; MT7610U: auto-responder off, TSSI, TX power and beacon setup left out, channels recalibrated on a timer while hopping; AR9271: signal relative to the noise floor, FCS removed, packets spanning transfers reassembled, WMI answers matched, running firmware reused; MT7921AU: Android USB host API instead of IOKit, no port reset, commands while receiving answered on the shared endpoint without blocking, bad-checksum frames dropped, failed register reads never written back, every transmit path (injection, TX descriptors) left out | RF Sentinel (CIS-C0) | GPL-3.0 |
The non-free firmware files (Ralink, MediaTek, Realtek) ship in the full build only
(`app/src/full/assets/usbwifi`). The FOSS build asks before downloading those same
diff --git a/app/src/main/java/com/rfsentinel/app/usb/UsbWifi.kt b/app/src/main/java/com/rfsentinel/app/usb/UsbWifi.kt
index 0410bc6..c497898 100644
--- a/app/src/main/java/com/rfsentinel/app/usb/UsbWifi.kt
+++ b/app/src/main/java/com/rfsentinel/app/usb/UsbWifi.kt
@@ -61,7 +61,7 @@ object UsbWifi {
internal const val ACTION_PERMISSION = "com.rfsentinel.app.USB_WIFI_PERMISSION"
/** Driver families. */
- enum class Driver { RTL88XXAU, RTL8812AU, RTL88X2BU, RTL8187, RT3070, RTL8814AU, MT7612U, MT7921U, AR9271 }
+ enum class Driver { RTL88XXAU, RTL8812AU, RTL88X2BU, RTL8187, RT3070, RTL8814AU, MT7612U, MT7610U, MT7921U, 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)
@@ -75,6 +75,7 @@ object UsbWifi {
private val RT53 = Chip("RT5370", Driver.RT3070)
private val AU14 = Chip("RTL8814AU", Driver.RTL8814AU)
private val MT = Chip("MT7612U", Driver.MT7612U)
+ private val MT10 = Chip("MT7610U", Driver.MT7610U)
private val ATH = Chip("AR9271", Driver.AR9271)
private val MT21 = Chip("MT7921AU", Driver.MT7921U)
@@ -131,6 +132,12 @@ object UsbWifi {
(0x043e to 0x7a22) to RT53, (0x043e to 0x7a42) to RT53, (0x04da to 0x1801) to RT53, (0x04da to 0x1800) to RT53,
(0x04da to 0x23f6) to RT53, (0x0471 to 0x2104) to RT53, (0x0471 to 0x2180) to RT53, (0x0471 to 0x2181) to RT53,
(0x0471 to 0x2182) to RT53,
+ (0x148f to 0x7610) to MT10, (0x13b1 to 0x003e) to MT10, (0x0e8d to 0x7610) to MT10, (0x7392 to 0xa711) to MT10,
+ (0x148f to 0x761a) to MT10, (0x148f to 0x760a) to MT10, (0x0b05 to 0x17d1) to MT10, (0x0b05 to 0x17db) to MT10,
+ (0x0df6 to 0x0075) to MT10, (0x2019 to 0xab31) to MT10, (0x2001 to 0x3d02) to MT10, (0x0586 to 0x3425) to MT10,
+ (0x07b8 to 0x7610) to MT10, (0x04bb to 0x0951) to MT10, (0x057c to 0x8502) to MT10, (0x293c to 0x5702) to MT10,
+ (0x20f4 to 0x806b) to MT10, (0x7392 to 0xc711) to MT10, (0x0df6 to 0x0079) to MT10, (0x2357 to 0x0123) to MT10,
+ (0x2357 to 0x010b) to MT10, (0x2357 to 0x0105) to MT10,
(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
@@ -155,7 +162,7 @@ object UsbWifi {
/** Known monitor-mode chips without a driver here yet (named in the status so users know why). */
private val KNOWN = mapOf(
(0x0bda to 0xc811) to "RTL8811CU / 8821CU", (0x0bda to 0xc820) to "RTL8821CU", (0x0bda to 0xc812) to "RTL8812CU",
- (0x0cf3 to 0x7010) to "AR7010", (0x0cf3 to 0x7015) to "AR7010", (0x0e8d to 0x7610) to "MT7610U",
+ (0x0cf3 to 0x7010) to "AR7010", (0x0cf3 to 0x7015) to "AR7010",
(0x148f to 0x3071) to "RT3071", (0x148f to 0x3072) to "RT3072"
)
@@ -404,6 +411,7 @@ object UsbWifi {
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.MT7610U -> Mt7612uMonitor.run(context, d, chip.name, onStatus, onFrames, x0 = true)
Driver.MT7921U -> Mt7921uMonitor.run(context, d, chip.name, onStatus, onFrames)
Driver.AR9271 -> Ar9271Monitor.run(context, d, "${chip.name} (experimental)", onStatus, onFrames)
}
diff --git a/app/src/main/res/xml/usb_device_filter.xml b/app/src/main/res/xml/usb_device_filter.xml
index 7777ba7..c5d5a66 100644
--- a/app/src/main/res/xml/usb_device_filter.xml
+++ b/app/src/main/res/xml/usb_device_filter.xml
@@ -58,6 +58,28 @@
<usb-device vendor-id="8193" product-id="13090" />
<usb-device vendor-id="5041" product-id="67" />
<usb-device vendor-id="5041" product-id="69" />
+ <usb-device vendor-id="5263" product-id="30224" />
+ <usb-device vendor-id="5041" product-id="62" />
+ <usb-device vendor-id="3725" product-id="30224" />
+ <usb-device vendor-id="29586" product-id="42769" />
+ <usb-device vendor-id="5263" product-id="30234" />
+ <usb-device vendor-id="5263" product-id="30218" />
+ <usb-device vendor-id="2821" product-id="6097" />
+ <usb-device vendor-id="2821" product-id="6107" />
+ <usb-device vendor-id="3574" product-id="117" />
+ <usb-device vendor-id="8217" product-id="43825" />
+ <usb-device vendor-id="8193" product-id="15618" />
+ <usb-device vendor-id="1414" product-id="13349" />
+ <usb-device vendor-id="1976" product-id="30224" />
+ <usb-device vendor-id="1211" product-id="2385" />
+ <usb-device vendor-id="1404" product-id="34050" />
+ <usb-device vendor-id="10556" product-id="22274" />
+ <usb-device vendor-id="8436" product-id="32875" />
+ <usb-device vendor-id="29586" product-id="50961" />
+ <usb-device vendor-id="3574" product-id="121" />
+ <usb-device vendor-id="9047" product-id="291" />
+ <usb-device vendor-id="9047" product-id="267" />
+ <usb-device vendor-id="9047" product-id="261" />
<usb-device vendor-id="1086" product-id="31250" />
<usb-device vendor-id="2821" product-id="6120" />
<usb-device vendor-id="5075" product-id="13097" />
diff --git a/app/src/test/java/com/rfsentinel/app/usb/Mt7610uDriverTest.kt b/app/src/test/java/com/rfsentinel/app/usb/Mt7610uDriverTest.kt
new file mode 100644
index 0000000..32eec1d
--- /dev/null
+++ b/app/src/test/java/com/rfsentinel/app/usb/Mt7610uDriverTest.kt
@@ -0,0 +1,45 @@
+package com.rfsentinel.app.usb
+
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertTrue
+import org.junit.Test
+
+/** MT7610U: USB IDs, the tables taken from the Linux driver, and the EEPROM maths. */
+class Mt7610uDriverTest {
+
+ @Test
+ fun usbIds() {
+ assertEquals(UsbWifi.Driver.MT7610U, UsbWifi.chipOf(0x0e8d, 0x7610)?.driver)
+ assertEquals(UsbWifi.Driver.MT7610U, UsbWifi.chipOf(0x2357, 0x0105)?.driver) // Archer T1U
+ assertEquals("Linux lists it for both chips; it stays on the MT7612U", UsbWifi.Driver.MT7612U, UsbWifi.chipOf(0x7392, 0xb711)?.driver)
+ assertEquals("mt7610u.bin", Firmware.needed(UsbWifi.Driver.MT7610U).single().name)
+ }
+
+ @Test
+ fun autoResponderStaysOff() {
+ val mac = Mt7610uTables.MAC
+ val i = (mac.indices step 2).single { mac[it] == 0x1404 }
+ assertEquals(0, mac[i + 1] and 1)
+ }
+
+ @Test
+ fun everyHopChannelHasARow() {
+ val have = Mt7610uTables.CHANNELS.associateBy { it[0] }
+ val hop = (1..14) + listOf(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)
+ for (ch in hop) assertEquals("channel $ch", 21, have[ch]?.size)
+ assertTrue(have.values.all { it[1] and (if (it[0] <= 14) 0x100 else 0x200) != 0 })
+ }
+
+ @Test
+ fun freqOffset() {
+ assertEquals(0x1b, Mt7612uMonitor.x0FreqOffset(0x20, 0x85)) // top bit set: positive, subtracted
+ assertEquals(0x25, Mt7612uMonitor.x0FreqOffset(0x20, 0x05))
+ assertEquals(0, Mt7612uMonitor.x0FreqOffset(0xff, 0xff)) // unwritten
+ }
+
+ @Test
+ fun agcGainLoweredByTwiceTheLna() {
+ assertEquals(0x12341a78, Mt7612uMonitor.x0AgcGain(0x12341e78, 2))
+ assertEquals(0x12347f78, Mt7612uMonitor.x0AgcGain(0x12340178, 1)) // wraps within the 7-bit field, as Linux does
+ }
+}