diff --git a/crates/owly-awdl/src/driver.rs b/crates/owly-awdl/src/driver.rs index e4639ac..a8867fe 100644 --- a/crates/owly-awdl/src/driver.rs +++ b/crates/owly-awdl/src/driver.rs @@ -271,6 +271,26 @@ impl Driver { } 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 = 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 diff --git a/crates/owly-awdl/src/node.rs b/crates/owly-awdl/src/node.rs index 7af678e..48050e2 100644 --- a/crates/owly-awdl/src/node.rs +++ b/crates/owly-awdl/src/node.rs @@ -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 { @@ -138,6 +142,7 @@ impl Config { rssi_threshold: Some(-65), neighbour_echo: true, max_peers: MAX_PEERS, + unicast_groups: false, } } } diff --git a/crates/owly-awdl/tests/driver.rs b/crates/owly-awdl/tests/driver.rs index 62304ca..a9ca201 100644 --- a/crates/owly-awdl/tests/driver.rs +++ b/crates/owly-awdl/tests/driver.rs @@ -99,6 +99,14 @@ fn config(n: u8) -> Config { } fn host(n: u8, tx: mpsc::UnboundedSender, rx: mpsc::UnboundedReceiver) -> Host { + host_with(config(n), tx, rx) +} + +fn host_with( + cfg: Config, + tx: mpsc::UnboundedSender, + rx: mpsc::UnboundedReceiver, +) -> Host { let (peers_tx, peers) = watch::channel(Vec::new()); let (send, outbound) = mpsc::unbounded_channel(); let (delivered_tx, delivered) = mpsc::unbounded_channel(); @@ -114,7 +122,7 @@ fn host(n: u8, tx: mpsc::UnboundedSender, rx: mpsc::UnboundedReceiver< }; let netif_read = read.clone(); let running = driver::spawn( - config(n), + cfg, move || { let netif = MemNetif { outbound, @@ -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::(); + 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::(); + 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()); diff --git a/crates/owly-radio/drivers.toml b/crates/owly-radio/drivers.toml index ad89ba7..81e7a81 100644 --- a/crates/owly-radio/drivers.toml +++ b/crates/owly-radio/drivers.toml @@ -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" diff --git a/crates/owly-radio/src/injection/mod.rs b/crates/owly-radio/src/injection/mod.rs index f70494c..ecd59b9 100644 --- a/crates/owly-radio/src/injection/mod.rs +++ b/crates/owly-radio/src/injection/mod.rs @@ -254,6 +254,7 @@ impl Injection { let supervisor = tokio::spawn(supervise( ops.clone(), prepared.hostapd, + prepared.rejoin, node.failed(), stopped, state_tx, @@ -343,11 +344,17 @@ impl Backend for Injection { async fn supervise( ops: Arc, mut hostapd: Option, + rejoin: Option<(String, u32, Duration)>, mut failed: watch::Receiver>, mut stopped: watch::Receiver, state: watch::Sender, ) -> Option { 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| { @@ -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). diff --git a/crates/owly-radio/src/injection/setup.rs b/crates/owly-radio/src/injection/setup.rs index fab1693..2a650a6 100644 --- a/crates/owly-radio/src/injection/setup.rs +++ b/crates/owly-radio/src/injection/setup.rs @@ -28,6 +28,9 @@ pub(crate) struct Prepared { pub announce: Announce, /// The hidden AP's hostapd, when the mode runs one. pub hostapd: Option, + /// 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 @@ -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); @@ -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 @@ -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, } } @@ -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 { + 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) { @@ -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); diff --git a/crates/owly-radio/src/quirks.rs b/crates/owly-radio/src/quirks.rs index 6153beb..a27e705 100644 --- a/crates/owly-radio/src/quirks.rs +++ b/crates/owly-radio/src/quirks.rs @@ -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, /// Known problems on this hardware, one sentence each, for the person /// at the computer. The probe reports them. #[serde(default)] @@ -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(()) } } @@ -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#" diff --git a/crates/owly-radio/tests/injection.rs b/crates/owly-radio/tests/injection.rs index 4b176fa..8b5fb18 100644 --- a/crates/owly-radio/tests/injection.rs +++ b/crates/owly-radio/tests/injection.rs @@ -817,6 +817,57 @@ async fn exclusive_mode_runs_an_ad_hoc_cell() { backend.down().await.unwrap(); } +#[tokio::test(flavor = "multi_thread")] +async fn intel_8265_rejoins_the_cell_without_restarting_awdl_and_stops_cleanly() { + let fx = Fx::with(|o| { + intel(o); + o.device = Some("8086:24fd".into()); + }); + // Keep the real device's configuration, shortening only the timer. + let overrides = fx.dir.path().join("drivers.toml"); + std::fs::write( + &overrides, + owly_radio::quirks::PACKAGED.replace("ibss_rejoin_secs = 9", "ibss_rejoin_secs = 1"), + ) + .unwrap(); + let mut settings = fx.settings(); + settings.allow_untested = true; + settings.quirks = Quirks::load(&overrides).unwrap(); + let mut backend = fx.backend_with(settings); + let link = backend.up().await.unwrap(); + assert!(fx.awdl().unicast_groups); + let initial_calls = fx.ops.calls().len(); + tokio::time::timeout(Duration::from_secs(3), async { + loop { + if fx + .since(initial_calls) + .contains(&format!("join {IBSS} 2437")) + { + break; + } + tokio::time::sleep(Duration::from_millis(20)).await; + } + }) + .await + .expect("the 8265's cell was never rejoined"); + assert_eq!( + fx.since(initial_calls), + [format!("leave {IBSS}"), format!("join {IBSS} 2437")] + ); + assert!(fx.awdl_running()); + assert!(fx.ops.awdl()); + assert_eq!(*link.state.borrow(), LinkState::Up); + + backend.down().await.unwrap(); + let after_stop = fx.ops.calls(); + tokio::time::sleep(Duration::from_millis(1100)).await; + assert_eq!(fx.ops.calls(), after_stop, "rejoining continued after stop"); + assert!(!fx.awdl_running()); + assert!(!fx.ops.awdl()); + assert_eq!(fx.journal(), None); + assert_eq!(fx.ops.kind(STATION).as_deref(), Some("managed")); +} + #[tokio::test(flavor = "multi_thread")] async fn exclusive_mode_tries_each_channel_in_order() { // An RTL8822BE starts no cell on 5 GHz: 44 and 149 fail, 6 works. diff --git a/local/intel8265/README.md b/local/intel8265/README.md new file mode 100644 index 0000000..a262297 --- /dev/null +++ b/local/intel8265/README.md @@ -0,0 +1,95 @@ +# Local Intel Wireless-AC 8265 workaround + +This branch backports [Owly PR #117](https://github.com/t4t5/owly/pull/117) +(commit `cfb06ec73e22f24bf47468d259f18c835bc5470d`) onto Owly 0.4.3. +The original findings and iPhone transfer results are in +[issue #116](https://github.com/t4t5/owly/issues/116). + +The workaround sends broadcast/multicast frames as individual unicast copies +to known peers and rejoins the ad-hoc cell every nine seconds. Both behaviors +apply only to PCI device `8086:24fd`. Other cards retain their defaults. The +card remains marked experimental and requires `allow_untested = true`. +Local additions validate the rejoin interval, reject group addresses when +choosing unicast recipients, and test device selection, periodic rejoining, +preservation of the AWDL interface, spoofed peers, and shutdown recovery. + +## Install + +From this checkout: + +```sh +cargo build --release --locked -p owlyd -p owly-cli +sh local/intel8265/install.sh --check +sudo sh local/intel8265/install.sh +``` + +The installer keeps the packaged `/usr/lib/owly/owlyd` and `/usr/bin/owly`. +It installs the patched daemon at `/usr/local/lib/owly-8265/owlyd` and uses +`/etc/systemd/system/owlyd.service.d/8265-workaround.conf` to select it. +Any existing local daemon, drop-in, or configuration is copied to a new +directory under `/var/backups/owly-8265-*` before installation. An existing +radio configuration must already contain `allow_untested = true`; the script +will stop instead of replacing other settings. + +This machine also has a VPN rule at IPv6 priority 9000 that rejects traffic +before the main routing table. Packet capture showed the Mac's TCP SYNs +arriving on port 8771 without a reply. A rule at priority 8990 now selects +the main table only for `fe80::/64` traffic explicitly scoped to `awdl0`. +The service's `ExecStartPre` helper ensures this rule exists after a reboot. +It preserves other rules and refuses to use an occupied priority. The rule +stays detached while `awdl0` is absent, and affects neither global IPv6 +destinations nor other output interfaces. + +To select the packaged daemon again, edit the drop-in so its last line reads +`ExecStart=/usr/lib/owly/owlyd`, then run `sudo systemctl daemon-reload` and +`sudo systemctl restart owlyd`. Omit the local `ExecStartPre` line to stop +recreating the scoped routing exception at service startup. To restore experimental hardware blocking, +set `allow_untested = false` in `/etc/owly/radio.toml`. + +## Receive from a Mac + +Keep this running in one terminal: + +```sh +owly radio up +``` + +In a second terminal: + +```sh +owly receive --name "Moein Linux" --dir ~/Downloads +``` + +On the Mac, turn on Wi-Fi and Bluetooth, then select a small test file in +Finder and use Share > AirDrop. Select Moein Linux if it appears, then accept +the request in the receiving terminal. Stop both commands with Ctrl+C. + +The laptop's normal Wi-Fi disconnects while the radio is running. The firmware +restart causes approximately one second of interruption every ten seconds; +large transfers can need a retry. A passing simulation is not proof of a +successful transfer on this card. The published hardware results use an iPhone. +On this machine, a MacBook Pro running macOS 27.0.1 successfully completed +discovery and offered CHANGELOG.md after the routing exception was added. +Completed file reception still needs confirmation. + +For a bounded test in a local terminal (including an interactive acceptance +prompt), run `bash local/intel8265/receive-test.sh`. It waits for the radio's +D-Bus session before starting discovery and keeps `timeout` in the foreground +so terminal input can reach the receiver. + +## Validation on this machine + +- The group-to-unicast regression failed before the backport and passed after it. +- The spoofed-peer regression aborted the unguarded driver and passed with the guard. +- `cargo test --locked -p owly-awdl --features driver`: 63 passed. +- `cargo test --locked -p owly-radio --lib --test injection`: 55 passed. +- `cargo test --locked -p owlyd --test service`: 11 passed. +- Workspace library/binary tests, formatting, Clippy, hardware table consistency, + and protocol coverage checks passed. The release binaries built successfully. +- The native kernel integration test cannot run under this machine's current + user-namespace restrictions (`unshare: ... uid_map: Operation not permitted`). + The host security policy was left unchanged. +- `local/intel8265/test-routing.sh` passed in isolated network namespaces: + the exception allows scoped AirDrop replies, preserves blocking for global + IPv6 and other interfaces, is idempotent, and refuses an occupied priority + without changing existing rules. diff --git a/local/intel8265/capture-discovery.sh b/local/intel8265/capture-discovery.sh new file mode 100644 index 0000000..1927df8 --- /dev/null +++ b/local/intel8265/capture-discovery.sh @@ -0,0 +1,21 @@ +#!/bin/sh +# Capture only this test's AWDL discovery traffic. Run through pkexec. +set -eu +TASK_ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/../.." && pwd) +TASK_CAPTURE="$TASK_ROOT/target/intel8265-discovery-$(date -u +%Y%m%dT%H%M%SZ).pcap" +echo "Waiting for awdl0; capture: $TASK_CAPTURE" +TASK_ATTEMPTS=0 +while [ ! -e /sys/class/net/awdl0 ]; do + TASK_ATTEMPTS=$((TASK_ATTEMPTS + 1)) + [ "$TASK_ATTEMPTS" -lt 120 ] || { echo 'No AirDrop interface appeared.' >&2; exit 1; } + sleep 0.25 +done +TASK_STATUS=0 +timeout --signal=INT 100 /usr/bin/tcpdump -i awdl0 -nn -U -s 0 \ + -w "$TASK_CAPTURE" 'ip6 and (udp port 5353 or tcp)' || TASK_STATUS=$? +chmod 0644 "$TASK_CAPTURE" +if [ "$TASK_STATUS" -eq 1 ] && [ ! -e /sys/class/net/awdl0 ] && [ -s "$TASK_CAPTURE" ]; then + # The receiver's bounded test normally removes this interface first. + exit 0 +fi +case "$TASK_STATUS" in 0|124) exit 0 ;; *) exit "$TASK_STATUS" ;; esac diff --git a/local/intel8265/ensure-link-local-route.py b/local/intel8265/ensure-link-local-route.py new file mode 100644 index 0000000..8d96d5c --- /dev/null +++ b/local/intel8265/ensure-link-local-route.py @@ -0,0 +1,27 @@ +#!/usr/bin/python3 +"""Keep AirDrop's scoped local IPv6 replies ahead of the VPN reject rule.""" + +import json +import subprocess +import sys + +IP = "/usr/sbin/ip" +PRIORITY = 8990 +rules = json.loads(subprocess.check_output([IP, "-6", "-j", "rule", "show"])) +expected = { + "priority": PRIORITY, + "src": "all", + "dst": "fe80::", + "dstlen": 64, + "oif": "awdl0", + "table": "main", +} +if any(all(rule.get(key) == value for key, value in expected.items()) for rule in rules): + sys.exit(0) +if any(rule.get("priority") == PRIORITY for rule in rules): + sys.exit(f"IPv6 rule priority {PRIORITY} is already in use; existing rules were preserved.") +subprocess.run( + [IP, "-6", "rule", "add", "priority", str(PRIORITY), + "to", "fe80::/64", "oif", "awdl0", "lookup", "main"], + check=True, +) diff --git a/local/intel8265/install.sh b/local/intel8265/install.sh new file mode 100644 index 0000000..a4ca975 --- /dev/null +++ b/local/intel8265/install.sh @@ -0,0 +1,61 @@ +#!/bin/sh +# Install the local daemon alongside the distribution package, preserving it. +set -eu + +TASK_ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/../.." && pwd) +TASK_DAEMON="$TASK_ROOT/target/release/owlyd" +TASK_CONFIG=/etc/owly/radio.toml +TASK_DROPIN=/etc/systemd/system/owlyd.service.d/8265-workaround.conf +TASK_DEST=/usr/local/lib/owly-8265/owlyd +TASK_ROUTE_HELPER=/usr/local/lib/owly-8265/ensure-link-local-route.py + +case "${1:-}" in + ''|--check) ;; + *) echo "usage: $0 [--check]" >&2; exit 2 ;; +esac +[ -x "$TASK_DAEMON" ] || { echo "Build owlyd in release mode first." >&2; exit 1; } + +# Do not replace a machine's existing radio settings. The current machine +# has no settings file; an existing one must already opt into this experiment. +python3 - "$TASK_CONFIG" <<'PY' +import pathlib, sys, tomllib +path = pathlib.Path(sys.argv[1]) +if path.exists(): + with path.open('rb') as stream: + config = tomllib.load(stream) + if config.get('allow_untested') is not True: + sys.exit(f'Set allow_untested = true in {path}, preserving its other settings, then retry.') +PY + +if [ "${1:-}" = --check ]; then + echo "Ready: install the patched daemon at $TASK_DEST" + echo "Set owlyd's ExecStart through $TASK_DROPIN" + echo "Keep AirDrop's scoped local IPv6 route ahead of the VPN reject rule." + echo "Enable experimental hardware in $TASK_CONFIG and restart owlyd." + exit 0 +fi +[ "$(id -u)" -eq 0 ] || { echo "Run: sudo sh $0" >&2; exit 1; } + +TASK_BACKUP="/var/backups/owly-8265-$(date -u +%Y%m%dT%H%M%SZ)-$$" +install -d -m 0755 "$TASK_BACKUP" +for TASK_EXISTING in "$TASK_CONFIG" "$TASK_DROPIN" "$TASK_DEST" "$TASK_ROUTE_HELPER"; do + if [ -f "$TASK_EXISTING" ]; then + cp -p -- "$TASK_EXISTING" "$TASK_BACKUP/$(basename -- "$TASK_EXISTING")" + fi +done +install -D -m 0755 "$TASK_DAEMON" "$TASK_DEST" +install -D -m 0755 "$TASK_ROOT/local/intel8265/ensure-link-local-route.py" "$TASK_ROUTE_HELPER" +if [ ! -e "$TASK_CONFIG" ]; then + install -d -m 0755 /etc/owly + printf '%s\n' '# Local Intel 8265 firmware workaround (PR #117).' 'allow_untested = true' > "$TASK_CONFIG" + chmod 0644 "$TASK_CONFIG" +fi +install -d -m 0755 /etc/systemd/system/owlyd.service.d +printf '%s\n' '[Service]' "ExecStartPre=/usr/bin/python3 $TASK_ROUTE_HELPER" \ + 'ExecStart=' "ExecStart=$TASK_DEST" > "$TASK_DROPIN" +chmod 0644 "$TASK_DROPIN" +systemctl daemon-reload +systemctl restart owlyd +systemctl is-active --quiet owlyd +echo "Patched service running. Previous local files saved in $TASK_BACKUP" +/usr/bin/owly doctor diff --git a/local/intel8265/receive-test.sh b/local/intel8265/receive-test.sh new file mode 100644 index 0000000..ffb345e --- /dev/null +++ b/local/intel8265/receive-test.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# Run from a local terminal: normal Wi-Fi is unavailable during this test. +set -u +TASK_ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/../.." && pwd) +TASK_RADIO_LOG="$TASK_ROOT/target/intel8265-visible-radio.log" +TASK_RADIO_PID= + +cleanup() { + if [ -n "$TASK_RADIO_PID" ]; then + kill -INT "$TASK_RADIO_PID" 2>/dev/null || true + wait "$TASK_RADIO_PID" 2>/dev/null || true + TASK_RADIO_PID= + fi +} +trap cleanup EXIT + +echo 'Owly: receive a test file from your Mac' +echo 'Normal Wi-Fi will disconnect during this 90-second test.' +echo 'On the Mac: select a small file, then Share > AirDrop > Moein Linux.' +echo 'When this terminal asks "accept? [y/N]", type y and press Enter.' +echo 'Press Ctrl+C to stop the receiver early.' +echo +/usr/bin/owly radio up --for 110 > "$TASK_RADIO_LOG" 2>&1 & +TASK_RADIO_PID=$! +TASK_ATTEMPTS=0 +# The interface appears before the D-Bus lease becomes ready. Starting the +# receiver in that gap loses the radio's discovery announcement bursts. +while [ ! -e /sys/class/net/awdl0 ] || ! /usr/bin/owly radio peers >/dev/null 2>&1; do + TASK_ATTEMPTS=$((TASK_ATTEMPTS + 1)) + if ! kill -0 "$TASK_RADIO_PID" 2>/dev/null || [ "$TASK_ATTEMPTS" -ge 60 ]; then + cat "$TASK_RADIO_LOG" + exit 1 + fi + sleep 0.25 +done +RUST_LOG=debug timeout --foreground --signal=INT 90 /usr/bin/owly receive \ + --name 'Moein Linux' --dir /home/moein/Downloads +cleanup +echo +echo 'Test ended. Normal Wi-Fi is reconnecting.' +read -r -p 'Press Enter to close this window.' diff --git a/local/intel8265/test-routing.sh b/local/intel8265/test-routing.sh new file mode 100644 index 0000000..d855462 --- /dev/null +++ b/local/intel8265/test-routing.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# Run as root. All network changes stay in temporary network namespaces. +set -eu +TASK_ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/../.." && pwd) +TASK_HELPER="$TASK_ROOT/local/intel8265/ensure-link-local-route.py" + +unshare --net /bin/sh -eu -c ' + ip -6 rule add priority 9000 unreachable + python3 "$1" + TASK_FIRST=$(ip -6 -j rule show) + python3 "$1" + [ "$TASK_FIRST" = "$(ip -6 -j rule show)" ] + ip link add awdl0 type dummy + ip link set awdl0 up + ip -6 addr add fe80::1/64 dev awdl0 nodad + ip link add other0 type dummy + ip link set other0 up + ip -6 addr add fe80::2/64 dev other0 nodad + ip -6 route get fe80::abcd oif awdl0 + if ip -6 route get fe80::abcd oif other0 2>/dev/null; then exit 1; fi + if ip -6 route get 2001:db8::1 oif awdl0 2>/dev/null; then exit 1; fi + echo "PASS: local AirDrop traffic works; other interfaces and global IPv6 stay blocked; installation is idempotent." +' test-routing "$TASK_HELPER" + +unshare --net /bin/sh -eu -c ' + ip -6 rule add priority 8990 unreachable + TASK_BEFORE=$(ip -6 -j rule show) + if python3 "$1"; then exit 1; fi + [ "$TASK_BEFORE" = "$(ip -6 -j rule show)" ] + echo "PASS: an occupied priority is refused without changing existing rules." +' test-routing "$TASK_HELPER"