wifi: defer LAR country-update notifications during Intel scan and PHY setup (PR #48)

This commit is contained in:
rqffael authored and Garvit Surana committed 2026-11-30 15:46:26 +00:00
1 parent f2de37cb77
commit 92cf419fc7
5 files changed
+96 -7

No files matched your search

@@ -169,6 +169,7 @@ pub struct Ax200Scan<'a, Q: BootIo, B: BiosIo, O: CountryIo + OsPolicy> {
/// `last_start_time_jiffies` and `last_6ghz_passive_jiffies`.
started_us: u64,
last_passive_six_ghz: Option<u64>,
pub(super) defer_country_updates: bool,
}
impl<'a, Q: BootIo, B: BiosIo, O: CountryIo + OsPolicy> Ax200Mac<'a, Q, B, O> {
/// Attach the same live OS regulatory source to the original unbound MAC.
@@ -237,10 +238,14 @@ impl<'a, Q: BootIo, B: BiosIo, O: CountryIo + OsPolicy> Ax200Mac<'a, Q, B, O> {
ebs_failed: false,
started_us,
last_passive_six_ghz: None,
defer_country_updates: false,
})
}
}
impl<Q: BootIo, B: BiosIo, O: CountryIo + OsPolicy> Ax200Scan<'_, Q, B, O> {
pub fn defer_country_updates(&mut self) {
self.defer_country_updates = true;
}
pub fn phase(&self) -> Ax200ScanPhase {
self.phase
}
@@ -657,6 +662,9 @@ impl<Q: BootIo, B: BiosIo, O: CountryIo + OsPolicy> Ax200Scan<'_, Q, B, O> {
notifications: boot.hcmd.notification_count(),
});
}
if self.defer_country_updates {
while boot.take_country_update().is_some() {}
}
if boot.hcmd.has_matching(0xc1, 0) {
return Err(Ax200ScanError::PreScanReceiveRequired);
}
@@ -991,7 +999,7 @@ impl<Q: BootIo, B: BiosIo, O: CountryIo + OsPolicy> Ax200Scan<'_, Q, B, O> {
.get_or_insert(Ax200ScanError::Country(error));
self.cancel()?;
}
if self
let boot = &mut self
.mac
.country
.board
@@ -1001,10 +1009,10 @@ impl<Q: BootIo, B: BiosIo, O: CountryIo + OsPolicy> Ax200Scan<'_, Q, B, O> {
.lari
.radio
.initialized
.boot
.hcmd
.has_matching(0xc9, 0)
{
.boot;
if self.defer_country_updates {
while boot.take_country_update().is_some() {}
} else if boot.hcmd.has_matching(0xc9, 0) {
self.first_error
.get_or_insert(Ax200ScanError::StaleNotification);
self.cancel()?;
@@ -347,6 +347,7 @@ impl<'a, Q: BootIo, B: BiosIo, O: CountryIo + OsPolicy> Ax200Phy<'a, Q, B, O> {
Ok(self.scan)
}
fn capture_idle_receive(&mut self) -> Result<(), Ax200PhyError> {
let defer_country_updates = self.scan.defer_country_updates;
let boot = self.boot();
let mut quiet = false;
for _ in 0..=boot.entries {
@@ -367,6 +368,9 @@ impl<'a, Q: BootIo, B: BiosIo, O: CountryIo + OsPolicy> Ax200Phy<'a, Q, B, O> {
notifications: boot.hcmd.notification_count(),
}));
}
if defer_country_updates {
while boot.take_country_update().is_some() {}
}
if boot
.hcmd
.has_matching(wire::COMPLETE_OPCODE, wire::COMPLETE_GROUP)
@@ -173,6 +173,9 @@ impl<Q: BootIo, B: BiosIo, O: CountryIo + OsPolicy> Ax200Scan<'_, Q, B, O> {
notifications: boot.hcmd.notification_count(),
});
}
if self.defer_country_updates {
while boot.take_country_update().is_some() {}
}
if boot
.hcmd
.has_matching(wire::COMPLETE_OPCODE, wire::COMPLETE_GROUP)
@@ -98,6 +98,8 @@ struct Device<'n> {
other: Option<(Vec<u8>, Vec<u8>)>,
/// A scan of an association's links runs until it is told to stop.
holds_link_scan: bool,
/// Inject a `0xc9` country update notification while a scan runs.
notify_country_on_scan: bool,
}
impl Device<'_> {
@@ -237,6 +239,14 @@ impl Device<'_> {
self.inject(rom, &frame);
}
}
if self.notify_country_on_scan {
let update = Id {
group: 0,
opcode: 0xc9,
version: 0,
};
self.inject(rom, &command_packet(update, 0x8000, &[b'D', b'E', 5, 0]));
}
if !(beside && self.holds_link_scan) {
self.finish_scan(rom, 1);
}
@@ -653,7 +663,7 @@ fn raise_split<'n>(
/// [`raise_split`], with [`Device::rsn`], a radio standing in for `eht` and
/// whether the AP MLD has [`Device::other`].
#[expect(clippy::too_many_arguments, reason = "each is a fixture's own knob")]
fn raise_as<'n>(
fn setup_station<'n>(
native: &'n Native,
country: Option<[u8; 2]>,
beacons: Vec<&'static [u8]>,
@@ -666,7 +676,7 @@ fn raise_as<'n>(
eht: Option<EhtLimits>,
secret: Secret,
other: bool,
) -> (Station<Model, ClockBios>, Phase, Device<'n>) {
) -> (Station<Model, ClockBios>, Device<'n>) {
let image = native.firmware.clone().unwrap_or_else(|| coex_image(2));
let catalog: &'static resources::Catalog = Box::leak(Box::new(catalog_for(
&profile(),
@@ -725,6 +735,7 @@ fn raise_as<'n>(
confirm: None,
other: other.then(|| (other_beacon([60, 70]), other_response())),
holds_link_scan: false,
notify_country_on_scan: false,
};
device.inject(&boot, &alive);
let inputs = Inputs {
@@ -756,6 +767,28 @@ fn raise_as<'n>(
// SAFETY: the model owns its pages and nothing else reaches the function.
let mut wifi = unsafe { crate::wifi::intel::link::Wifi::new(boot, inputs) };
wifi.radio_mut().assumed_eht = eht;
(wifi, device)
}
#[expect(clippy::too_many_arguments, reason = "each is a fixture's own knob")]
fn raise_as<'n>(
native: &'n Native,
country: Option<[u8; 2]>,
beacons: Vec<&'static [u8]>,
flags: u8,
channel: u32,
quality: bool,
elements: &'static [u8],
second: Option<u32>,
rsn: &'static [u8],
eht: Option<EhtLimits>,
secret: Secret,
other: bool,
) -> (Station<Model, ClockBios>, Phase, Device<'n>) {
let (mut wifi, mut device) = setup_station(
native, country, beacons, flags, channel, quality, elements, second, rsn, eht, secret,
other,
);
let mut phase = Phase::Booting;
for _ in 0..600 {
wifi.carrier();
@@ -960,6 +993,46 @@ fn bring_up_scans_for_the_network_and_readies_its_station() {
assert_ne!(wifi.address(), Mac::default());
}
#[test]
fn a_country_update_notification_during_scan_does_not_abort_bring_up() {
if crate::test_process::isolate_model() {
return;
}
let native = Native::default();
let secret = Secret::Psk(Zeroizing::new([0; 32]));
let (mut wifi, mut device) = setup_station(
&native,
Some(*b"US"),
vec![b"test"],
0,
OPEN,
false,
&[],
None,
&RSN,
None,
secret,
false,
);
device.notify_country_on_scan = true;
let mut phase = Phase::Booting;
for _ in 0..600 {
wifi.carrier();
phase = wifi.radio().phase();
if matches!(phase, Phase::AuthenticationRequired | Phase::Failed) {
break;
}
device.respond(wifi.radio().rom().unwrap());
}
let wifi = wifi.radio();
assert_eq!(wifi.error(), None);
assert_eq!(phase, Phase::AuthenticationRequired);
assert_eq!(
wifi.selected().unwrap().bss.ssid.as_deref(),
Some(b"test".as_slice())
);
}
#[test]
fn without_a_country_world_rules_apply_and_only_the_networks_bss_is_joined() {
if crate::test_process::isolate_model() {
@@ -852,6 +852,7 @@ impl<Q: BootIo, B: BiosIo> Wifi<Q, B> {
// the lease, and no other path publishes to this function.
match unsafe { mac.begin_scan() } {
Ok(mut scan) => {
scan.defer_country_updates();
self.client.channels = scan.regulated_channels();
self.chains = scan.chains();
self.eht = scan.eht_limits();