Skip to content

backend: borrow an existing idle AP interface - #20

Open
professorpip wants to merge 1 commit into
ravindu644:mainfrom
professorpip:backend/borrow-idle-ap0
Open

professorpip wants to merge 1 commit into
ravindu644:mainfrom
professorpip:backend/borrow-idle-ap0

Conversation

@professorpip

Copy link
Copy Markdown

Problem

Some Android Wi-Fi frameworks leave a valid, idle ap0 in place, while their vendor driver refuses to create an equivalent replacement.

On the tested MediaTek device:

  • with Android Wi-Fi off and no ap0, direct nl80211 creation failed with -EFAULT;
  • with Android Wi-Fi on, the framework created an idle AP-type ap0;
  • VirtualAP deleted that interface, then replacement creation failed with -ENOMEM.

The errno values are the vendor driver's interface-operation response, not evidence of host memory exhaustion.

Change

When ap0 already exists, the backend now borrows it only when both runtime checks pass:

  1. nl80211 reports NL80211_IFTYPE_AP;
  2. the interface is administratively down.

An active interface, a different interface type or an inspection failure is refused rather than replaced. A durable marker records that Android owns the interface. Stop then detaches it from the bridge, flushes VirtualAP addresses and brings it down, but does not delete it.

When ap0 does not exist, the existing create/delete behaviour is unchanged.

Working output

Creating virtual AP interface 'ap0' on wlan0...
Using existing idle AP interface 'ap0'.
Starting hostapd (2GHz ch 6, 20MHz)...
hostapd running
ap0 bridged into vap-br0 - clients now live on the container's LAN.
VirtualAP is ACTIVE

The same interface index was present before start, during the managed router run and after repeated Stop calls.

Tested environment

  • Device: Planet Computers Astro Slide 5G
  • Android: 11 / V07b
  • Root: Magisk
  • SoC: MediaTek MT6873
  • Wi-Fi driver: MediaTek vendor WLAN (mtk_cfg80211_* path observed)
  • Radio: 2.4 GHz, channel 6, 20 MHz, WPA2
  • Upstream: mobile data on ccmni0
  • Mode: managed Droidspaces/OpenWrt bridge mode
  • Client: iPhone, with DHCP lease, LTE internet and LuCI access confirmed

Two complete saved-profile start/stop cycles passed, including an extra idempotent Stop in each cycle. Android Wi-Fi remained healthy and the framework-owned interface retained the same index.

Validation

  • Added wrong-type and active-interface predicate coverage.
  • Added atomic ownership-marker coverage.
  • Added borrowed-interface release coverage proving the link remains present, down and detached.
  • Full Linux make check suite passed on the host validation runner.
  • Warning-clean static arm64 build passed.
  • Live managed-mode client test and repeated cleanup cycles passed.

The macOS checkout cannot run make check directly because the suite requires Linux kernel headers and Linux-only APIs. The pushed branch is left for the repository's Linux CI to re-run those checks.

Signed-off-by: Philip White <60242898+professorpip@users.noreply.github.com>
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.

1 participant