fix(wifi): keep what an Intel scan heard through its later parts

This commit is contained in:
Tyler Smith committed 2026-10-31 01:50:19 +00:00
1 parent 082cc0fa07
commit 0fe964fbb4
3 files changed
+68 -11

No files matched your search

@@ -70,6 +70,9 @@ struct Device<'n> {
block_acks: Vec<Vec<u8>>,
/// Each scan request.
scans: Vec<Vec<u8>>,
/// The second channel's rules, when they differ from the first's, and the
/// AP then only heard from the first scan.
second: Option<u32>,
/// Whether frames are acknowledged in Block Ack notifications alone, as
/// the firmware reports those it aggregated.
aggregating: bool,
@@ -134,7 +137,8 @@ impl Device<'_> {
};
let mut payload = mcc_payload(country, request[2], 51);
payload[20..24].copy_from_slice(&self.channel.to_le_bytes());
payload[24..28].copy_from_slice(&self.channel.to_le_bytes());
let second = self.second.unwrap_or(self.channel);
payload[24..28].copy_from_slice(&second.to_le_bytes());
payload
}
(1 | 5, 0x08) => vec![0x9b],
@@ -172,8 +176,10 @@ impl Device<'_> {
}
if (id.group, id.opcode) == (1, 0x0d) {
self.scans.push(request.to_vec());
for ssid in self.beacons.clone() {
self.inject(rom, &beacon(ssid, self.quality, self.elements));
if self.second.is_none() || self.scans.len() == 1 {
for ssid in self.beacons.clone() {
self.inject(rom, &beacon(ssid, self.quality, self.elements));
}
}
let mut body = [0; 16];
body[6] = 1;
@@ -376,6 +382,23 @@ fn raise_beside<'n>(
channel: u32,
quality: bool,
elements: &'static [u8],
) -> (Station<Model, ClockBios>, Phase, Device<'n>) {
raise_split(
native, country, beacons, flags, channel, quality, elements, None,
)
}
/// [`raise_beside`], with [`Device::second`].
#[expect(clippy::too_many_arguments, reason = "each is a fixture's own knob")]
fn raise_split<'n>(
native: &'n Native,
country: Option<[u8; 2]>,
beacons: Vec<&'static [u8]>,
flags: u8,
channel: u32,
quality: bool,
elements: &'static [u8],
second: Option<u32>,
) -> (Station<Model, ClockBios>, Phase, Device<'n>) {
let catalog: &'static resources::Catalog = Box::leak(Box::new(catalog_for(
&profile(),
@@ -415,6 +438,7 @@ fn raise_beside<'n>(
configuration: Vec::new(),
block_acks: Vec::new(),
scans: Vec::new(),
second,
aggregating: false,
};
device.inject(&boot, &alive);
@@ -1058,6 +1082,23 @@ fn a_scan_probes_where_a_frame_may_start_and_listens_elsewhere() {
assert_eq!(scan[48], 0);
}
#[test]
fn a_network_one_scan_part_heard_outlives_the_parts_after_it() {
let native = Native::default();
let (_, phase, device) = raise_split(
&native,
Some(*b"US"),
vec![b"test"],
0,
OPEN,
true,
&[],
Some(OPEN & !8),
);
assert_eq!(device.scans.len(), 2);
assert_eq!(phase, Phase::AuthenticationRequired);
}
/// An AP's HE capabilities, one stream with its ACK and HTC bits, then its
/// operation: 3 us packet extension, RTS threshold 5, color 9. Random access
/// and MU EDCA parameters follow it.
@@ -740,15 +740,18 @@ impl<Q: BootIo, B: BiosIo> Wifi<Q, B> {
{
beacons.heard(bss.channel);
}
let observed = Arc::new(association::NativeBssObservation { bss: bss.clone() });
let heard = station::Heard {
observation: Arc::new(association::NativeBssObservation { bss: bss.clone() }),
at: self.clock.now_us(),
};
match self
.client
.observed
.iter_mut()
.find(|known| known.bss().bssid == bss.bssid)
.find(|known| known.observation.bss().bssid == bss.bssid)
{
Some(known) => *known = observed,
None => self.client.observed.push(observed),
Some(known) => *known = heard,
None => self.client.observed.push(heard),
}
}
}
@@ -188,10 +188,19 @@ pub struct ManagementKey {
}
/// The association's state beside the kept chain.
/// `IEEE80211_SCAN_RESULT_EXPIRE`.
const BSS_EXPIRY_US: u64 = 30_000_000;
/// A BSS and when it was last heard, a `cfg80211_internal_bss`.
pub(super) struct Heard {
pub(super) observation: Arc<NativeBssObservation>,
pub(super) at: u64,
}
pub(super) struct Client {
station: Station,
pub(super) plan: Option<Plan>,
pub(super) observed: Vec<Arc<NativeBssObservation>>,
pub(super) observed: Vec<Heard>,
pub(super) channels: Vec<(Channel, u32)>,
pub(super) regulatory: Option<database::Country>,
steps: VecDeque<Step>,
@@ -1352,7 +1361,7 @@ impl<Q: BootIo, B: BiosIo> Wifi<Q, B> {
self.client
.observed
.get(handle)
.cloned()
.map(|heard| heard.observation.clone())
.ok_or(Error::Refused("BSS"))
}
}
@@ -1683,7 +1692,11 @@ impl<Q: BootIo, B: BiosIo> Radio for Wifi<Q, B> {
owner.poll_pre_scan_receive().map_err(Error::Scan)?,
MpduProgress::Pending | MpduProgress::Backpressure { .. }
) {}
self.client.observed.clear();
// A scan runs in parts, whose results `choose` takes together.
let now = self.clock.now_us();
self.client
.observed
.retain(|heard| now.saturating_sub(heard.at) < BSS_EXPIRY_US);
let started = match probe {
// SAFETY: `new`'s contract covers the scan's pages.
Some(probe) => unsafe { owner.start_probing(request, &probe, budget_us, pages) },
@@ -1720,7 +1733,7 @@ impl<Q: BootIo, B: BiosIo> Radio for Wifi<Q, B> {
.observed
.iter()
.enumerate()
.map(|(handle, observed)| (handle, observed.bss()))
.map(|(handle, heard)| (handle, heard.observation.bss()))
.collect()
}