Skip to content

unisocwifi: reconcile connect and roam state - #17

Open
YipKo wants to merge 4 commits into
armbian:masterfrom
YipKo:fix/connect-roam-state
Open

unisocwifi: reconcile connect and roam state#17
YipKo wants to merge 4 commits into
armbian:masterfrom
YipKo:fix/connect-roam-state

Conversation

@YipKo

@YipKo YipKo commented Aug 21, 2026

Copy link
Copy Markdown

Related to orangepi-xunlong/linux-orangepi#98

When an AP sends an 802.11v BSS Transition Management request, the firmware may report SPRDWL_ROAM_SUCCESS while the host is still in SPRDWL_CONNECTING.

The existing handler only accepts SPRDWL_CONNECT_SUCCESS in that state. It therefore enters the error path and may leave sm_state stuck in SPRDWL_CONNECTING. Subsequent association attempts then fail until sprdwl_ng is reloaded.

A later test also triggered WARN_ON(bss_not_found) in net/wireless/sme.c. cfg80211 processes connection notifications asynchronously, and the BSS may no longer be present in the scan cache by the time the event is handled.

This change selects the cfg80211 notification from the saved host state:

  • Treat SPRDWL_ROAM_SUCCESS as connect success while an initial connection is pending.
  • Report a roam only when already connected.
  • Reset a failed initial connection to SPRDWL_DISCONNECTED.
  • Preserve the existing association when a roam fails.

For successful connect and roam events, the driver now resolves and holds the target cfg80211_bss instead of leaving cfg80211 to look it up later. If the beacon data or firmware-provided channel cannot be used, it falls back to an SSID/BSSID lookup.

The patch also publishes the pending SSID and BSSID before sending the firmware command, validates firmware event lengths before parsing them, fixes several key-validation checks, and removes a debug message that printed key material.

The driver builds successfully for ARM64 against Armbian Linux 6.12.23 and has been tested on an Orange Pi Zero 3 without any Wi-Fi disconnects.

Firmware may report SPRDWL_ROAM_SUCCESS while the host is still waiting for an initial connection. The old handler treats this as an error and can leave sm_state stuck in SPRDWL_CONNECTING, after which reconnect attempts fail until the module is reloaded.

Choose the cfg80211 notification from the saved host state, restore DISCONNECTED after a failed initial connection, preserve a live association after a failed roam, and balance cfg80211 BSS references.

Signed-off-by: YipKo <17290550+YipKo@users.noreply.github.com>
YipKo added 3 commits August 22, 2026 04:46
Connection and roam notifications are asynchronous, so cfg80211 may no
longer be able to resolve the target BSS by the time the event is
processed. Validate and hold the exact BSS for both initial connection
and roaming, falling back to an SSID/BSSID cache lookup without trusting
the firmware channel. This avoids cfg80211 warnings and keeps driver and
kernel connection state aligned.

Signed-off-by: YipKo <17290550+YipKo@users.noreply.github.com>
Validate firmware response and event header lengths before using them.
Decode little-endian IE lengths explicitly and reject truncated connect
or disconnect events before their payload reaches cfg80211. Also reject
malformed beacon frames before calculating IE offsets.

Signed-off-by: YipKo <17290550+YipKo@users.noreply.github.com>
Firmware events may run before the thread waiting for a connect command
response resumes. Publish SSID, BSSID, and connection state before sending
the command, and restore the previous metadata only if the attempt is still
pending when the command fails.

Treat association and beacon IEs as optional, falling back to the BSS cache
when beacon data cannot be used. Validate key bounds before copying, handle
missing pairwise ciphers safely, and never print key material to the log.

Signed-off-by: YipKo <17290550+YipKo@users.noreply.github.com>
@ValdikSS

Copy link
Copy Markdown

This fixes roaming without issues so far, thanks!

See orangepi-xunlong/linux-orangepi#98 (comment)

@YipKo
YipKo marked this pull request as ready for review August 24, 2026 06:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants