Skip to content

Commit

Permalink
Reset DHCP socket when the link up is detected (esp-rs#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoernQ committed May 23, 2024
1 parent 5415124 commit f5b62e4
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions esp-wifi/src/wifi_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pub struct WifiStack<'a, MODE: WifiDeviceMode> {
pub(crate) ip_info: RefCell<Option<ipv4::IpInfo>>,
#[cfg(feature = "dhcpv4")]
pub(crate) dhcp_socket_handle: RefCell<Option<SocketHandle>>,
#[cfg(feature = "dhcpv4")]
pub(crate) old_connected: RefCell<bool>,
#[cfg(feature = "dns")]
dns_socket_handle: RefCell<Option<SocketHandle>>,
}
Expand Down Expand Up @@ -78,6 +80,8 @@ impl<'a, MODE: WifiDeviceMode> WifiStack<'a, MODE> {
ip_info: RefCell::new(None),
#[cfg(feature = "dhcpv4")]
dhcp_socket_handle: RefCell::new(dhcp_socket_handle),
#[cfg(feature = "dhcpv4")]
old_connected: RefCell::new(false),
sockets: RefCell::new(sockets),
current_millis_fn,
#[cfg(feature = "tcp")]
Expand Down Expand Up @@ -215,6 +219,18 @@ impl<'a, MODE: WifiDeviceMode> WifiStack<'a, MODE> {
let dhcp_socket_handle_ref = self.dhcp_socket_handle.borrow_mut();
if let Some(dhcp_handle) = *dhcp_socket_handle_ref {
let dhcp_socket = sockets.get_mut::<Dhcpv4Socket>(dhcp_handle);

let connected = match crate::wifi::get_sta_state() {
crate::wifi::WifiState::StaConnected => true,
_ => false,
};

if connected && !*self.old_connected.borrow() {
dhcp_socket.reset();
}

*self.old_connected.borrow_mut() = connected;

let event = dhcp_socket.poll();
if let Some(event) = event {
match event {
Expand Down

0 comments on commit f5b62e4

Please sign in to comment.