Commit 507b0af3 authored by MLA98's avatar MLA98

Update device.rs

parent 850d5d22
......@@ -8,6 +8,15 @@ use syscall::io::{Dma, Mmio, Io, ReadOnly};
use syscall::scheme::SchemeMut;
#[repr(packed)]
pub fn setnetcfg(key: &str, value: &str) -> Result<()> {
let mut file = File::create(&format!("/etc/net/eth0/{}", key))?;
file.write(value.as_bytes())?;
file.set_len(value.len() as u64)?;
file.sync_all()?;
Ok(())
}
struct Regs {
mac: [Mmio<u32>; 2],
_mar: [Mmio<u32>; 2],
......@@ -281,7 +290,7 @@ impl Rtl8168 {
mac_high as u8,
(mac_high >> 8) as u8];
print!("{}", format!(" - MAC: {:>02X}:{:>02X}:{:>02X}:{:>02X}:{:>02X}:{:>02X}\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]));
let _ = setcfg("mac", &format!("{:>02X}-{:>02X}-{:>02X}-{:>02X}-{:>02X}-{:>02X}\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]));
let _ = setnetcfg("mac", &format!("{:>02X}-{:>02X}-{:>02X}-{:>02X}-{:>02X}-{:>02X}\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]));
// Reset - this will disable tx and rx, reinitialize FIFOs, and set the system buffer pointer to the initial value
self.regs.cmd.writef(1 << 4, true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment