fix(network): give macOS's network only a host adapter with a usable station address, driving a Wi-Fi chip up to 10 s for its own, count a saved Wi-Fi network as configured when choosing it, and place no USB Ethernet adapter for an address that is not unicast, where a laptop with no cable and an Intel AX200 stopped at "Setting up the Mac's hardware" with "the USB Ethernet address must be a unicast address"

The guest network chose the AX200 because a Wi-Fi network was set, before
its firmware had read the address from its NVM, so the guest's USB Ethernet
adapter got all zeros and placing the board failed. The chosen Wi-Fi chip's
link is now polled until it names its address; an adapter that has none
then is put back and the next one is chosen, and with none left macOS
starts without a network. The board also places no USB Ethernet adapter
for an address that is not a usable unicast one instead of stopping.

With saved networks and no --wifi, the guest took the first adapter, an
Ethernet port with no cable, and macOS had no network although the boot
menu had joined Wi-Fi; a saved network now counts as configured.
This commit is contained in:
Garvit Surana committed 2026-11-25 17:29:59 +00:00
1 parent 9a0bc0b532
commit 3ff9b16d94
6 files changed
+176 -9

No files matched your search

@@ -44,6 +44,32 @@ pub fn guest_adapter(carriers: &[bool], wireless: &[bool], wifi_configured: bool
.unwrap_or(0)
}
/// [`guest_adapter`] among the adapters whose station address is `usable`,
/// in the same order; none when no adapter has one. The guest's USB
/// Ethernet adapter takes its host adapter's address, so an Intel Wi-Fi
/// chip whose firmware had not read its address yet gave macOS all zeros
/// and 0.6.1 stopped the boot ("the USB Ethernet address must be a unicast
/// address") on a laptop with no cable and a Wi-Fi network configured.
pub fn usable_guest_adapter(
carriers: &[bool],
wireless: &[bool],
usable: &[bool],
wifi_configured: bool,
) -> Option<usize> {
let kept: alloc::vec::Vec<usize> = (0..carriers.len())
.filter(|&index| usable.get(index).copied().unwrap_or(false))
.collect();
if kept.is_empty() {
return None;
}
let pick = |of: &[bool]| -> alloc::vec::Vec<bool> {
kept.iter()
.map(|&index| of.get(index).copied().unwrap_or(false))
.collect()
};
Some(kept[guest_adapter(&pick(carriers), &pick(wireless), wifi_configured)])
}
/// `text` with the network's name `ssid` written `<ssid>` wherever it
/// occurs, byte for byte, as `String::from_utf8_lossy` writes it (the
/// connection keeper's failures name the network so): occurrences that
@@ -257,3 +257,51 @@ fn the_guest_takes_the_configured_wifi_over_an_empty_ethernet_port() {
// Wi-Fi alone: itself.
assert_eq!(guest_adapter(&[false], &[true], true), 0);
}
/// An adapter without a usable station address is passed over, keeping the
/// order the guest's choice follows; none at all when no adapter has one.
#[test]
fn the_guest_adapter_is_one_with_a_usable_station_address() {
// A laptop's I219 with no cable and an AX200 whose firmware has not
// named its address: the I219, where 0.6.1 took the AX200 and stopped.
let (carriers, wireless) = ([false, false], [false, true]);
assert_eq!(guest_adapter(&carriers, &wireless, true), 1);
assert_eq!(
usable_guest_adapter(&carriers, &wireless, &[true, false], true),
Some(0)
);
// With its address the Wi-Fi chip is taken, as before.
assert_eq!(
usable_guest_adapter(&carriers, &wireless, &[true, true], true),
Some(1)
);
assert_eq!(
usable_guest_adapter(&carriers, &wireless, &[true, true], false),
Some(0)
);
// A carrier still comes first among the usable, and the indices are
// the adapters' own.
assert_eq!(
usable_guest_adapter(
&[true, false, true],
&[false; 3],
&[false, true, true],
false
),
Some(2)
);
assert_eq!(
usable_guest_adapter(
&[false, false, false],
&[false, true, true],
&[true, false, true],
true
),
Some(2)
);
assert_eq!(
usable_guest_adapter(&carriers, &wireless, &[false, false], true),
None
);
assert_eq!(usable_guest_adapter(&[], &[], &[], true), None);
}
+73 -8
View File
@@ -972,10 +972,49 @@ pub(super) fn set_receive_core(apic: u64) {
/// the devices' lock: the rest wait in the adapter's ring.
const RECEIVE_BURST: usize = 256;
/// How long a Wi-Fi chip chosen for the guest network may take to name its
/// station address: Intel's reads it from its NVM once its firmware is
/// alive (2 s at most), which polling its link drives.
const STATION_WAIT_MILLIS: u64 = 10_000;
/// Whether `link` has a usable unicast station address for the guest's USB
/// Ethernet adapter, a Wi-Fi chip's link being driven up to
/// [`STATION_WAIT_MILLIS`] for one. On a laptop with no cable and a Wi-Fi
/// network configured, 0.6.1 gave macOS an Intel AX200's all-zero address,
/// read before its firmware ran, and stopped at "Setting up the Mac's
/// hardware" ("the USB Ethernet address must be a unicast address").
fn station_address(link: &mut RootLink) -> bool {
if link.mac().is_valid() {
return true;
}
let start = output::now();
if link.device.wireless() {
while output::millis_since(start) < STATION_WAIT_MILLIS {
let _ = link.carrier_now();
if link.mac().is_valid() {
output::arguments(format_args!(
"GUEST NETWORK adapter {} named its station address after {} ms\n",
link.device.location(),
output::millis_since(start)
));
return true;
}
core::hint::spin_loop();
}
}
output::arguments(format_args!(
"GUEST NETWORK adapter {} has no usable station address after {} ms: not given to macOS\n",
link.device.location(),
output::millis_since(start)
));
false
}
impl GuestNetwork {
/// The first adapter left in `links` with carrier now; else, with a
/// Wi-Fi network configured, the first Wi-Fi adapter; else the first one
/// left (`network_link::guest_adapter`). The mount's own client, when it
/// Wi-Fi network configured or saved, the first Wi-Fi adapter; else the
/// first one left (`network_link::usable_guest_adapter`), among those
/// with a usable station address ([`station_address`]). The mount's own client, when it
/// runs, has taken its adapter first ([`HostNetwork::open`]), so the
/// guest never takes the only adapter with a cable from an install.
/// `ssid` is the configured Wi-Fi network's name, hidden in what a Wi-Fi
@@ -992,19 +1031,45 @@ impl GuestNetwork {
.iter()
.map(|device| device.wireless())
.collect();
let index = network_link::guest_adapter(&carriers, &wireless, ssid.is_some());
let device = links.devices.remove(index);
// A saved network counts as configured too: with no cable, macOS's
// network goes to the Wi-Fi chip that joins it, where 0.6.1 gave it
// the first adapter, an Ethernet port with no link.
let wifi_configured = ssid.is_some()
|| NETWORKS
.0
.try_borrow()
.is_ok_and(|networks| !networks.is_empty());
// The guest's USB Ethernet adapter takes the host adapter's station
// address, so an adapter without a usable one is put back and the
// next is chosen; with none left, macOS starts without a network.
let mut usable = alloc::vec![true; links.devices.len()];
let link = loop {
let Some(index) =
network_link::usable_guest_adapter(&carriers, &wireless, &usable, wifi_configured)
else {
return Err(refuse!(
"the guest network needs a host network adapter with a station address; \
none left has one"
));
};
let mut link = RootLink::new(links.devices.remove(index), links.root, ssid);
if station_address(&mut link) {
break link;
}
links.devices.insert(index, link.into_device());
usable[index] = false;
};
output::arguments(format_args!(
"GUEST NETWORK adapter {} mac={}\n",
device.location(),
stela_contracts::masked::Mac(&device.mac().0)
link.device.location(),
stela_contracts::masked::Mac(&link.mac().0)
));
super::ident::set(
super::ident::Kind::Network,
format_args!("{}", device.location()),
format_args!("{}", link.device.location()),
);
Ok(Self {
link: RootLink::new(device, links.root, ssid),
link,
up: None,
counters: Default::default(),
refused: false,
+2 -1
View File
@@ -392,7 +392,8 @@ pub struct UsbCables {
/// Host disks, each a USB mass storage device (at most five with a
/// network adapter, six without).
pub disks: Vec<Box<dyn BlockDevice>>,
/// A USB Ethernet adapter with this station address.
/// A USB Ethernet adapter with this station address, when it is a
/// usable unicast one ([`Mac::is_valid`]); none otherwise.
pub network: Option<Mac>,
/// A USB Bluetooth controller.
pub bluetooth: Option<UsbBluetooth>,
@@ -144,6 +144,27 @@ fn report(t: &mut Trackpad) -> Option<Vec<u8>> {
}
}
/// A guest network whose host adapter has no usable station address yet
/// (an Intel Wi-Fi chip before its firmware read it, all zeros) places no
/// USB Ethernet adapter and the board is still placed, where 0.6.1 stopped
/// the boot; a usable address places one.
#[test]
fn a_network_address_that_is_not_unicast_places_no_usb_ethernet() {
for unusable in [Mac([0; 6]), Mac([1, 0, 0x5e, 0, 0, 1])] {
let mut d = cabled(UsbCables {
network: Some(unusable),
..UsbCables::default()
});
assert!(d.usb_network().is_err());
assert!(d.network_deliver(&[0; 60]).is_err());
}
let mut d = cabled(UsbCables {
network: Some(Mac([2, 0, 0, 0, 0, 1])),
..UsbCables::default()
});
assert!(d.usb_network().is_ok());
}
#[test]
fn touch_routes_to_trackpad() {
let mut d = cabled(UsbCables {
+6
View File
@@ -175,6 +175,12 @@ impl AppleDevices {
system_control,
trackpad,
} = cables;
// An address that is not a usable unicast one, as a Wi-Fi chip
// whose firmware has not named its own yet has, places no USB
// Ethernet adapter: macOS starts without the network, where 0.6.1
// stopped the boot ("the USB Ethernet address must be a unicast
// address").
let network = network.filter(Mac::is_valid);
#[cfg(not(any(feature = "trackpad", test)))]
if trackpad.is_some() {
return Err(refuse!(