DHCPOFFER works
This commit is contained in:
parent
a6ef2702a3
commit
6f5ebbd752
40
src/main.rs
40
src/main.rs
@ -7,7 +7,7 @@
|
||||
use core::net::Ipv4Addr;
|
||||
use core::slice;
|
||||
use cyw43_pio::{DEFAULT_CLOCK_DIVIDER, PioSpi};
|
||||
use dhcparse::dhcpv4::{DhcpOption, Encode as _, MessageType, OpCode};
|
||||
use dhcparse::dhcpv4::{DhcpOption, Encode as _};
|
||||
use dhcparse::{dhcpv4, v4_options};
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_net::udp::{PacketMetadata, UdpMetadata, UdpSocket};
|
||||
@ -241,36 +241,36 @@ async fn main(spawner: Spawner) {
|
||||
info!("{}", res_buf.len());
|
||||
Timer::after_secs(0).await;
|
||||
|
||||
let mut res_opts = Vec::<DhcpOption, 255>::new();
|
||||
// let mut res_opts = Vec::<DhcpOption, 255>::new();
|
||||
for o in unwrap(v4_options!(msg; ParameterRequestList))
|
||||
.await
|
||||
.unwrap_or(&[])
|
||||
{
|
||||
let opt = match o {
|
||||
1 => DhcpOption::SubnetMask(&dhcpv4::Addr([255, 255, 255, 0])),
|
||||
2 => DhcpOption::TimeOffset(3600),
|
||||
3 => DhcpOption::Router(&[dhcpv4::Addr([192, 254, 0, 2])]),
|
||||
6 => DhcpOption::DomainNameServer(&[dhcpv4::Addr([0, 0, 0, 0])]),
|
||||
12 => DhcpOption::HostName(b"blue"),
|
||||
15 => DhcpOption::DomainName(b"LocalDomain"),
|
||||
26 => DhcpOption::Unknown(26, &[0x5, 0xEA]), // mtu
|
||||
28 => DhcpOption::Unknown(28, &[192, 254, 0, 255]), // broadcast
|
||||
51 => DhcpOption::AddressLeaseTime(700),
|
||||
54 => DhcpOption::ServerIdentifier(&dhcpv4::Addr([192, 254, 0, 2])),
|
||||
58 => DhcpOption::Unknown(58, &[0, 0, 0x1, 0xF4]), // renewal time = 500s
|
||||
59 => DhcpOption::Unknown(59, &[0, 0, 0x2, 0x58]), // rebinding time = 600s
|
||||
let (opt_len, opt): (u8, &[u8]) = match o {
|
||||
1 => (4, &[255, 255, 255, 0]), // DhcpOption::SubnetMask(&dhcpv4::Addr([255, 255, 255, 0])),
|
||||
2 => (4, &3600_i32.to_be_bytes()), // DhcpOption::TimeOffset(3600),
|
||||
3 => (4, &[192, 254, 0, 2]), // DhcpOption::Router(&[dhcpv4::Addr([192, 254, 0, 2])]),
|
||||
6 => (4, &[0, 0, 0, 0]), // DhcpOption::DomainNameServer(&[dhcpv4::Addr([0, 0, 0, 0])]),
|
||||
12 => (4, b"blue"), // DhcpOption::HostName(b"blue"),
|
||||
15 => (11, b"LocalDomain"), // DhcpOption::DomainName(b"LocalDomain"),
|
||||
26 => (2, &1514_u16.to_be_bytes()), // DhcpOption::Unknown(26, &[0x5, 0xEA]), // mtu
|
||||
28 => (4, &[192, 254, 0, 255]), // DhcpOption::Unknown(28, &[192, 254, 0, 255]), // broadcast
|
||||
51 => (4, &700_u32.to_be_bytes()), // DhcpOption::AddressLeaseTime(700),
|
||||
54 => (4, &[192, 254, 0, 2]), // DhcpOption::ServerIdentifier(&dhcpv4::Addr([192, 254, 0, 2])),
|
||||
58 => (4, &500_u32.to_be_bytes()), // DhcpOption::Unknown(58, &[0, 0, 0x1, 0xF4]), // renewal time = 500s
|
||||
59 => (4, &600_u32.to_be_bytes()), // DhcpOption::Unknown(59, &[0, 0, 0x2, 0x58]), // rebinding time = 600s
|
||||
_ => {
|
||||
info!("Unhandled requested option : {}", o);
|
||||
Timer::after_secs(0).await;
|
||||
continue;
|
||||
}
|
||||
};
|
||||
res_buf.push(o).unwrap();
|
||||
match opt {
|
||||
|
||||
}
|
||||
res_buf.push(*o).unwrap();
|
||||
res_buf.push(opt_len).unwrap();
|
||||
res_buf.extend_from_slice(opt).unwrap();
|
||||
}
|
||||
unwrap(res_opts.push(DhcpOption::End)).await;
|
||||
res_buf.push(255).unwrap(); // end option
|
||||
// unwrap(res_opts.push(DhcpOption::End)).await;
|
||||
|
||||
// res_buf.clear();
|
||||
// unwrap(
|
||||
|
Loading…
Reference in New Issue
Block a user