Skip to content
Merged
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
2 changes: 1 addition & 1 deletion uefi-test-runner/src/proto/network/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub fn test() {

info!("Bring up interface (ip4 config2 protocol)");
let mut ip4 = Ip4Config2::new(*h).expect("open ip4 config2 protocol");
ip4.ifup(true).expect("acquire ipv4 address");
ip4.ifup().expect("acquire ipv4 address");

// hard to find web sites which still allow plain http these days ...
info!("Testing HTTP");
Expand Down
39 changes: 16 additions & 23 deletions uefi/src/proto/network/ip4config2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ use alloc::vec::Vec;
use core::ffi::c_void;
use core::net::Ipv4Addr;
use core::time::Duration;

use log::{debug, trace};
use uefi::boot::ScopedProtocol;
use uefi::prelude::*;
use uefi::proto::unsafe_protocol;
use uefi::{print, println};
use uefi_raw::protocol::network::ip4_config2::{
Ip4Config2DataType, Ip4Config2InterfaceInfo, Ip4Config2Policy, Ip4Config2Protocol,
};
Expand Down Expand Up @@ -102,39 +101,33 @@ impl Ip4Config2 {
})
}

/// Bring up network interface. Does nothing in case the network
/// is already set up. Otherwise turns on DHCP and waits until an
/// IPv4 address has been assigned. Reports progress on the
/// console if verbose is set to true. Returns TIMEOUT error in
/// case DHCP configuration does not finish within 30 seconds.
pub fn ifup(&mut self, verbose: bool) -> uefi::Result<()> {
/// Bring up network interface.
///
/// Does nothing in case the network is already set up. Otherwise turns on
/// DHCP and waits until an IPv4 address has been assigned.
///
/// Returns TIMEOUT error in case DHCP configuration does not finish within
/// 30 seconds.
pub fn ifup(&mut self) -> uefi::Result<()> {
const TIMEOUT_SECS: u64 = 30;

let no_address = Ipv4Addr::from_bits(0);

let info = self.get_interface_info()?;
if info.station_addr != no_address.into() {
if verbose {
print!("Network is already up: ");
println!("addr v4: {}", info.station_addr);
}
debug!("Network is already up: addr v4: {}", info.station_addr);
return Ok(());
}

if verbose {
print!("DHCP ");
}
debug!("DHCP ");
self.set_policy(Ip4Config2Policy::DHCP)?;

for _ in 0..30 {
if verbose {
print!(".");
}
for _ in 0..TIMEOUT_SECS {
boot::stall(Duration::from_secs(1));
trace!(".\r");
let info = self.get_interface_info()?;
if info.station_addr != no_address.into() {
if verbose {
print!(" OK: ");
println!("addr v4: {}", info.station_addr);
}
debug!("OK: addr v4: {}", info.station_addr);
return Ok(());
}
}
Expand Down