sv6160: wire-diff the connect against the vendor; send vif_addr in VIF_CFG

Instrument both drivers to dump every control command in one format
(WIRECMD id=<n> len=<n> plus WIRE hex), capture a connect from each, and
diff them command for command.  tools/rk915-wiredump.patch is the vendor
side; wiredump=1 is ours.  Two things about the capture are worth writing
down: the vendor's scans are invisible at its default debug_mask of 0
(debug_mask=2 is RK915_DBG_SCAN), and the kernel ring buffer wraps well
inside a single connect, so dmesg has to be drained continuously or the
window silently disappears.

The vendor's window, from Scan Complete to associated:

  CHANNEL(48) VIF_CFG(88) VIF_CFG(88) [auth TX 581] VIF_CFG(88)
  MCST_ADDR_CFG(38) x6  MCST_FLTR_CTRL(32)  -> authenticated

Ours, same window:

  CHANNEL(48) VIF_CFG(88) VIF_CFG(88) VIF_CFG(88) [auth TX]
  MCST_ADDR_CFG(38) x6                          -> nothing

and the VIF_CFG payloads differ in a way that is hard to argue with.  The
vendor's carry its own MAC at vif_addr; ours carry 00:00:00:00:00:00,
because sv6160_rpu_vif_cfg() has never populated that field -- the struct
has it, the memset zeroes it, nothing ever writes it.  RPU_CMD_VIF_CTRL
also carries vif_addr, but FW_PRIV_INIT only ever carries the FIRST OCTET
of the MAC, so VIF_CFG/VIF_CTRL are the only places the firmware can learn
the whole address.  Without it the LMAC cannot address-match a unicast
frame to us, which is exactly the asymmetry we have been chasing:
broadcast beacons arrive, our unicast auth response never does.

Fill it in, from wiphy->perm_addr rather than sc->vif->addr -- this command
is also sent from paths that run while the VIF is being torn down, and
dereferencing sc->vif there rebooted the board twice.

NOT YET VALIDATED on hardware.  The runs after this change hit a corrupt
scp of the module (Invalid ELF section header overflow -- md5 the .ko after
copying, the link is not reliable), three reboots, and NetworkManager
refusing to activate the profile on the freshly created device.  The change
is a demonstrable correctness fix regardless of whether it is THE blocker.

Two smaller differences the diff turned up, not addressed here: we send
basic_rate_set 0x153 where the vendor sends its bss_conf->basic_rates (15
for this AP), and we send the beacon-interval VIF_CFG (bitmap 0x800) before
the auth frame where the vendor sends it after.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Moos7zcsHdpW8DKMq2KM3G
This commit is contained in:
Paul KilarandClaude Opus 5 committed 2026-09-10 22:31:44 -04:00
1 parent 224152f3c8
commit 4894a64ac3
3 files changed
+88

No files matched your search

@@ -289,6 +289,10 @@ static int mod_rf_keep;
module_param_named(rf_keep, mod_rf_keep, int, 0644);
MODULE_PARM_DESC(rf_keep, "Re-assert the firmware's RF enable after each channel program: 0=off (default; measured to make no difference), 1=on");
static int mod_wiredump;
module_param_named(wiredump, mod_wiredump, int, 0644);
MODULE_PARM_DESC(wiredump, "hex-dump every control command payload in the vendor's WIRECMD/WIRE format (0=off)");
/* Poke firmware memory directly. DUMP_REG_INFO carries an rw field and the
* vendor drives its debugfs "write_fw_reg=addr,val" through exactly this path,
* so the firmware will take a write from us as readily as a read.
@@ -700,6 +704,17 @@ static int __sv6160_rpu_write_cmd(struct sv6160_softc *sc, void *cmd,
sc->recv_len_failed = false;
/* Byte-level dump of every control command, in the same format the
* vendor driver was instrumented to produce (WIRECMD/WIRE), so the two
* connect sequences can be diffed command for command. */
if (mod_wiredump) {
struct rpu_msg_hdr *h = cmd;
pr_info("WIRECMD id=%u len=%zu\n", le32_to_cpu(h->id), len);
print_hex_dump(KERN_INFO, "WIRE ", DUMP_PREFIX_NONE, 32, 1,
cmd, len > 256 ? 256 : len, false);
}
return sv6160_sdio_write_data(sc, SDIO_DATA_ADDR, cmd, len);
}
@@ -1310,6 +1325,25 @@ int sv6160_rpu_vif_cfg(struct sv6160_softc *sc, const u8 *bssid,
cmd.if_index = cpu_to_le32(sc->vif_index);
cmd.changed_bitmap = cpu_to_le32(changed);
/* Our own MAC, in EVERY VIF_CFG -- found by byte-diffing this command
* against the vendor's on the wire. The vendor fills vif_addr in on
* all three of its pre/post-auth VIF_CFGs (rk915 vif.c passes
* uvif->vif->addr to every rpu_prog_vif_* helper); we left the field
* zeroed since the struct was written, so the firmware was told our
* address was 00:00:00:00:00:00. RPU_CMD_VIF_CTRL carries vif_addr
* too, but FW_PRIV_INIT only ever carries the FIRST OCTET of the MAC,
* so VIF_CFG/VIF_CTRL are the only places the firmware can learn the
* whole thing -- and without it the LMAC cannot address-match a
* unicast frame to us. Broadcast beacons still arrive, which is
* exactly the asymmetry we have been chasing.
*
* Taken from wiphy->perm_addr rather than sc->vif->addr: this command is
* also sent from paths that run while the VIF is being torn down, and
* dereferencing sc->vif there rebooted the board twice. For our single
* STA interface the two are the same address -- mac80211 logs it as the
* local address on every auth attempt. */
memcpy(cmd.vif_addr, sc->hw->wiphy->perm_addr, 6);
if (changed & VIF_CFG_BSSID_CHANGED)
memcpy(cmd.bssid, bssid, 6);
+28
View File
@@ -0,0 +1,28 @@
# tools
## `rk915-wiredump.patch`
Instruments the vendor rk915 driver to hex-dump every control command it sends,
in the same `WIRECMD id=<n> len=<n>` + `WIRE <hex>` format the sv6160 driver
emits under `wiredump=1`. That makes the two connect sequences directly
diffable, command for command and byte for byte.
Apply it to a copy of the vendor source (do not edit the ROCKNIX build tree in
place), build against the same kernel, and load with `wiredump=1`:
```sh
cp -a .../build/rk915-<hash> /tmp/rk915v
patch -d /tmp/rk915v -p0 < tools/rk915-wiredump.patch
make -C <kernel-build-tree> M=/tmp/rk915v ARCH=arm64 \
CROSS_COMPILE=aarch64-rocknix-linux-gnu- CONFIG_RK915=m modules
# on the device
rmmod rk915 && insmod rk915.ko wiredump=1 debug_mask=2
```
`debug_mask=2` is `RK915_DBG_SCAN`, which makes the vendor log its scans — they
are invisible at the default mask of 0, and their absence from a capture is
easy to misread as "the vendor does not scan before authenticating". It does.
Drain dmesg continuously while capturing (`while true; do dmesg -c >> log;
sleep 0.2; done &`); the ring buffer wraps well inside a single connect and
will silently eat the window you care about.
+26
View File
@@ -0,0 +1,26 @@
--- /home/pkilar/Devel/rocknix/build.ROCKNIX-RK3326.aarch64/build/rk915-86f0d0e07afe156651ce5eec3e315f66ef79a59f/src/hal.c 2026-08-08 03:02:20.000000000 -0400
+++ /tmp/claude-1000/-home-pkilar-Devel-gusgu/c1ac0c7f-cdf3-4195-92c5-42ffe8e5463e/scratchpad/rk915v/src/hal.c 2026-09-10 21:47:17.950825261 -0400
@@ -303,9 +303,23 @@
}
}
+/* Byte-level wire dump of every control command, for diffing this driver's
+ * connect sequence against a clean-room reimplementation. Off by default. */
+unsigned int rk915_wiredump;
+module_param_named(wiredump, rk915_wiredump, uint, 0644);
+MODULE_PARM_DESC(wiredump, "hex-dump every control command payload (0=off)");
+
static void _hal_send(struct hal_priv *priv,
struct sk_buff *skb)
{
+ if (rk915_wiredump && skb->len >= sizeof(struct host_rpu_msg_hdr)) {
+ struct host_rpu_msg_hdr *h = (struct host_rpu_msg_hdr *)skb->data;
+
+ pr_info("WIRECMD id=%u len=%u\n", h->id, skb->len);
+ print_hex_dump(KERN_INFO, "WIRE ", DUMP_PREFIX_NONE, 32, 1,
+ skb->data,
+ skb->len > 256 ? 256 : skb->len, false);
+ }
skb_queue_tail(&priv->txq, skb);
//tasklet_schedule(&priv->tx_tasklet);
hal_tx_queue_work(priv);