Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions crates/owly-awdl/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,26 @@ impl<A: Air, N: Netif> Driver<A, N> {
}

fn transmit(&mut self, at: Time, frame: Frame) {
let cfg = self.node.config();
if cfg.unicast_groups && frame.to.is_multicast() {
let no_ack = cfg.no_ack;
// A peer address comes from the air. A group address would
// recurse into this branch and could never be a unicast copy.
let peers: Vec<MacAddr> = self
.node
.peers()
.map(|p| p.mac)
.filter(|mac| !mac.is_multicast())
.collect();
for mac in peers {
let mut copy = frame.clone();
copy.bytes[4..10].copy_from_slice(&mac.0);
copy.to = mac;
copy.no_ack = no_ack;
self.transmit(at, copy);
}
return;
}
if frame.is_action() {
// Built for this moment, its sync TLVs and timestamp with it: by
// the next try it would be stale, and the next PSF or MIF is
Expand Down
5 changes: 5 additions & 0 deletions crates/owly-awdl/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ pub struct Config {
pub neighbour_echo: bool,
/// Most peers tracked: [`MAX_PEERS`] by default.
pub max_peers: usize,
/// Send each broadcast or multicast frame as one unicast copy per peer,
/// for radios whose firmware never sends group frames from an ad-hoc
/// cell and resets when its queue stalls (Intel 8265).
pub unicast_groups: bool,
}

impl Config {
Expand All @@ -138,6 +142,7 @@ impl Config {
rssi_threshold: Some(-65),
neighbour_echo: true,
max_peers: MAX_PEERS,
unicast_groups: false,
}
}
}
Expand Down
74 changes: 73 additions & 1 deletion crates/owly-awdl/tests/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ fn config(n: u8) -> Config {
}

fn host(n: u8, tx: mpsc::UnboundedSender<Received>, rx: mpsc::UnboundedReceiver<Received>) -> Host {
host_with(config(n), tx, rx)
}

fn host_with(
cfg: Config,
tx: mpsc::UnboundedSender<Received>,
rx: mpsc::UnboundedReceiver<Received>,
) -> Host {
let (peers_tx, peers) = watch::channel(Vec::new());
let (send, outbound) = mpsc::unbounded_channel();
let (delivered_tx, delivered) = mpsc::unbounded_channel();
Expand All @@ -114,7 +122,7 @@ fn host(n: u8, tx: mpsc::UnboundedSender<Received>, rx: mpsc::UnboundedReceiver<
};
let netif_read = read.clone();
let running = driver::spawn(
config(n),
cfg,
move || {
let netif = MemNetif {
outbound,
Expand Down Expand Up @@ -202,6 +210,70 @@ async fn two_nodes_on_an_in_memory_air_meet_and_pass_ipv6() {
b.running.stop();
}

#[tokio::test(flavor = "multi_thread")]
async fn unicast_groups_sends_group_frames_to_each_peer_instead() {
let (a_tx, mut from_a) = mpsc::unbounded_channel::<Received>();
let (to_b, b_rx) = mpsc::unbounded_channel();
let (b_tx, a_rx) = mpsc::unbounded_channel();
let mut cfg = config(1);
cfg.unicast_groups = true;
let a = host_with(cfg, a_tx, a_rx);
let mut b = host(2, b_tx, b_rx);
let receivers = Arc::new(std::sync::Mutex::new(Vec::new()));
let tap = receivers.clone();
tokio::spawn(async move {
while let Some(frame) = from_a.recv().await {
tap.lock().unwrap().push(frame.bytes[4..10].to_vec());
let _ = to_b.send(frame);
}
});
let met =
tokio::time::timeout(Duration::from_secs(5), b.peers.wait_for(|p| p.len() == 1)).await;
assert!(met.is_ok(), "b never heard a");

let receivers = receivers.lock().unwrap();
assert!(!receivers.is_empty());
assert!(
receivers.iter().all(|r| r[..] == mac(2).0),
"a sent to {receivers:02x?}"
);
drop(receivers);
a.running.stop();
b.running.stop();
}

#[tokio::test(flavor = "multi_thread")]
async fn unicast_groups_never_recurses_on_a_spoofed_multicast_peer() {
let (a_tx, mut from_a) = mpsc::unbounded_channel::<Received>();
let (to_a, a_rx) = mpsc::unbounded_channel();
let mut cfg = config(1);
cfg.unicast_groups = true;
let mut a = host_with(cfg, a_tx, a_rx);

// A valid advertisement with an invalid transmitter address can still
// reach the peer table. It must never become another group transmission.
let mut spoofed = config(2);
spoofed.addr = MacAddr::BROADCAST;
let mut sender = owly_awdl::Node::new(spoofed, owly_awdl::Time(1));
for action in sender.handle(owly_awdl::Input::Timer(owly_awdl::Time(1))) {
if let owly_awdl::Action::Transmit { frame, .. } = action {
to_a.send(Received {
bytes: frame.bytes,
rssi: Some(-40),
})
.unwrap();
}
}
tokio::time::timeout(Duration::from_secs(2), a.peers.wait_for(|p| !p.is_empty()))
.await
.expect("the spoofed peer was never processed")
.unwrap();
tokio::time::sleep(Duration::from_millis(300)).await;
assert!(from_a.try_recv().is_err(), "sent to a group address");
assert!(a.running.failed().borrow().is_none());
a.running.stop();
}

#[test]
fn a_transport_that_cant_open_fails_the_spawn() {
let (peers, _) = watch::channel(Vec::new());
Expand Down
8 changes: 5 additions & 3 deletions crates/owly-radio/drivers.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,15 @@ issues = [
notes = "Intel Wireless-AC 8260 (NUC6i7KYK, 8086:24f3, kernel 6.12)."

[devices."8086:24fd"]
status = "broken"
status = "untested"
mode = "exclusive"
channels = [6]
unicast_groups = true
ibss_rejoin_secs = 9
issues = [
"This Intel Wireless-AC 8265's firmware (8265-36) stalls a transmit queue and resets about 10 s after the ad-hoc cell starts on channel 6.",
"This Intel Wireless-AC 8265's firmware (8265-36) never sends the ad-hoc cell's group frames, and stops sending to its stations at the cell's first beacon. Owly sends group frames to each peer instead and rejoins the cell every 9 s, which restarts the firmware: a transfer pauses for about 1 s every 10 s.",
]
notes = "Intel Dual Band Wireless-AC 8265 (EliteBook x360 1030 G3, 8086:24fd, kernel 6.12). The reset repeats until the driver is reloaded. With a hidden AP forced in the cell's place, it runs without resetting but hears no AWDL action frames from the phone."
notes = "Intel Dual Band Wireless-AC 8265 (EliteBook x360 1030 G3, 8086:24fd, kernel 6.12; ASUS X580VD, kernel 7.0.14). Without the quirks the group queue stalls and the firmware resets every ~21 s, until the driver is reloaded. With a hidden AP forced in the cell's place, it runs without resetting but hears no AWDL action frames from the phone. With them, on the X580VD: four photos from an iPhone (10.3 MB) and one to it (1.1 MB in 12 s) in one session. Leaving the cell asserts the firmware (ADVANCED_SYSASSERT 0x3437); owlymon0 and awdl0 survive the restart. Firmware 8265-34 stalls the same way."

[drivers.rtw88_8822be]
status = "tested"
Expand Down
24 changes: 24 additions & 0 deletions crates/owly-radio/src/injection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ impl Injection {
let supervisor = tokio::spawn(supervise(
ops.clone(),
prepared.hostapd,
prepared.rejoin,
node.failed(),
stopped,
state_tx,
Expand Down Expand Up @@ -343,11 +344,17 @@ impl Backend for Injection {
async fn supervise(
ops: Arc<dyn Ops>,
mut hostapd: Option<Child>,
rejoin: Option<(String, u32, Duration)>,
mut failed: watch::Receiver<Option<String>>,
mut stopped: watch::Receiver<bool>,
state: watch::Sender<LinkState>,
) -> Option<Child> {
let mut check = tokio::time::interval(Duration::from_secs(1));
let mut rejoin_tick = rejoin.as_ref().map(|(_, _, every)| {
let mut t = tokio::time::interval_at(tokio::time::Instant::now() + *every, *every);
t.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Delay);
t
});
let lost = |why: String| {
tracing::warn!("link lost: {why}");
state.send_if_modified(|s| {
Expand All @@ -366,6 +373,23 @@ async fn supervise(
lost(why);
}
}
_ = async {
match rejoin_tick.as_mut() {
Some(t) => drop(t.tick().await),
None => std::future::pending().await,
}
} => {
let Some((cell, freq, _)) = rejoin.clone() else { continue };
let ops = ops.clone();
let joined = tokio::task::spawn_blocking(move || {
let _ = ops.leave_ibss(&cell);
ops.join_ibss(&cell, freq)
})
.await;
if let Ok(Err(e)) = joined {
tracing::warn!("rejoining the ad-hoc cell: {e}");
}
}
_ = check.tick() => {
// A driver that reloads (iwlwifi after a firmware crash)
// takes the monitor interface with it (legacy #23).
Expand Down
22 changes: 18 additions & 4 deletions crates/owly-radio/src/injection/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ pub(crate) struct Prepared {
pub announce: Announce,
/// The hidden AP's hostapd, when the mode runs one.
pub hostapd: Option<Child>,
/// The ad-hoc cell, its frequency and how often to rejoin it, when the
/// driver's `ibss_rejoin_secs` asks for that.
pub rejoin: Option<(String, u32, Duration)>,
}

/// Sets the radio up in the station's mode. Undoes what it did if a step
Expand Down Expand Up @@ -171,11 +174,18 @@ impl Setup<'_> {
}

let mut hostapd = None;
let mut rejoin = None;
let freq = if mode == Mode::ActiveMonitor {
self.active_monitor(sta_mac, &freqs)?
} else {
let freq = if self.station.has(IfType::Adhoc) {
self.ibss_cell(sta_mac, &freqs)?
let (cell, freq) = self.ibss_cell(sta_mac, &freqs)?;
rejoin = self
.station
.quirk
.ibss_rejoin_secs
.map(|s| (cell, freq, Duration::from_secs(s)));
freq
} else {
let (freq, child) = self.ap_cell(sta_mac, &freqs)?;
hostapd = Some(child);
Expand All @@ -196,7 +206,9 @@ impl Setup<'_> {
channel: Channel(channel),
presence: Presence::Fixed,
};
Ok(self.finish(mode, radio, sta_mac, Announce::FIXED, hostapd))
let mut prepared = self.finish(mode, radio, sta_mac, Announce::FIXED, hostapd);
prepared.rejoin = rejoin;
Ok(prepared)
}

/// AWDL on `radio`, on the station's MAC (AWDL-2), named after the
Expand Down Expand Up @@ -230,11 +242,13 @@ impl Setup<'_> {
awdl.no_ack = no_ack;
}
awdl.amsdu = self.settings.tx_amsdu;
awdl.unicast_groups = self.station.quirk.unicast_groups;
Prepared {
mode,
awdl,
announce,
hostapd,
rejoin: None,
}
}

Expand Down Expand Up @@ -332,7 +346,7 @@ impl Setup<'_> {
/// Cards that refuse an ad-hoc interface beside the station, even down
/// (some AX211s), get the station itself made the cell. Returns the
/// frequency it started on.
fn ibss_cell(&mut self, mac: MacAddr, freqs: &[u32]) -> Result<u32, Error> {
fn ibss_cell(&mut self, mac: MacAddr, freqs: &[u32]) -> Result<(String, u32), Error> {
let ops = self.ops;
let name = self.station.name.clone();
if ops.exists(IBSS) {
Expand Down Expand Up @@ -379,7 +393,7 @@ impl Setup<'_> {
}
// mac80211 scans the channel once before it starts the cell.
if self.wait(Duration::from_secs(10), || ops.link_freq(&cell) == Some(f)) {
return Ok(f);
return Ok((cell, f));
}
tracing::info!("the ad-hoc cell on {f} MHz didn't start");
let _ = ops.leave_ibss(&cell);
Expand Down
42 changes: 42 additions & 0 deletions crates/owly-radio/src/quirks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ pub struct Quirk {
/// selection, which doesn't use it yet.
#[serde(default)]
pub supports_tx_ldpc: bool,
/// Send broadcast and multicast as unicast to each peer: the firmware
/// never sends group frames from the ad-hoc cell.
#[serde(default)]
pub unicast_groups: bool,
/// Leave and rejoin the ad-hoc cell this often, in seconds: the
/// firmware stops sending to its stations from the cell's first beacon.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub ibss_rejoin_secs: Option<u64>,
/// Known problems on this hardware, one sentence each, for the person
/// at the computer. The probe reports them.
#[serde(default)]
Expand Down Expand Up @@ -156,6 +164,9 @@ impl Quirk {
if self.channels.is_empty() {
return Err("channels is empty".into());
}
if self.ibss_rejoin_secs == Some(0) {
return Err("ibss_rejoin_secs must be greater than zero".into());
}
Ok(())
}
}
Expand Down Expand Up @@ -239,6 +250,37 @@ mod tests {
assert_eq!(q.notes, "");
}

#[test]
fn intel_8265_workarounds_are_opt_in_and_device_specific() {
let quirks = packaged();
let (q, source) = quirks.get("iwlwifi", Some("8086:24fd"));
assert_eq!(source, Source::Device);
assert_eq!(q.status, Status::Untested);
assert_eq!(q.mode, Mode::Exclusive);
assert_eq!(q.channels, [6]);
assert!(q.unicast_groups);
assert_eq!(q.ibss_rejoin_secs, Some(9));

for id in ["8086:51f0", "8086:24f3", "8086:095a"] {
let (q, _) = quirks.get("iwlwifi", Some(id));
assert!(!q.unicast_groups, "unexpected workaround for {id}");
assert_eq!(q.ibss_rejoin_secs, None);
}
}

#[test]
fn a_zero_ibss_rejoin_interval_is_rejected_before_starting_the_radio() {
let result = Quirks::parse(
r#"
[drivers.iwlwifi]
status = "untested"
mode = "exclusive"
ibss_rejoin_secs = 0
"#,
);
assert!(result.is_err(), "a zero interval panics the supervisor");
}

#[test]
fn mistakes_are_refused() {
let text = r#"
Expand Down
Loading