Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LwipIntfDev - method end() to enable repeated begin #9023

Merged
merged 3 commits into from
Nov 12, 2023
Merged
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
37 changes: 30 additions & 7 deletions cores/esp8266/LwipIntfDev.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class LwipIntfDev: public LwipIntf, public RawDev

// default mac-address is inferred from esp8266's STA interface
boolean begin(const uint8_t* macAddress = nullptr, const uint16_t mtu = DEFAULT_MTU);
void end();

const netif* getNetIf() const
{
Expand Down Expand Up @@ -170,6 +171,7 @@ class LwipIntfDev: public LwipIntf, public RawDev
int8_t _intrPin;
uint8_t _macAddress[6];
bool _started;
bool _scheduled;
bool _default;
};

Expand Down Expand Up @@ -261,6 +263,7 @@ boolean LwipIntfDev<RawDev>::begin(const uint8_t* macAddress, const uint16_t mtu
if (!netif_add(&_netif, ip_2_ip4(&ip_addr), ip_2_ip4(&netmask), ip_2_ip4(&gw), this,
netif_init_s, ethernet_input))
{
RawDev::end();
return false;
}

Expand All @@ -274,10 +277,11 @@ boolean LwipIntfDev<RawDev>::begin(const uint8_t* macAddress, const uint16_t mtu
break;

case ERR_IF:
RawDev::end();
return false;

default:
netif_remove(&_netif);
end();
return false;
}
}
Expand All @@ -304,22 +308,41 @@ boolean LwipIntfDev<RawDev>::begin(const uint8_t* macAddress, const uint16_t mtu
}
}

if (_intrPin < 0
&& !schedule_recurrent_function_us(
if (_intrPin < 0 && !_scheduled)
{
_scheduled = schedule_recurrent_function_us(
[&]()
{
if (!_started)
{
JAndrassy marked this conversation as resolved.
Show resolved Hide resolved
_scheduled = false;
return false;
}
this->handlePackets();
return true;
},
100))
{
netif_remove(&_netif);
return false;
100);
if (!_scheduled)
{
end();
return false;
}
}

return true;
}

template<class RawDev>
void LwipIntfDev<RawDev>::end()
{
netif_remove(&_netif);
ip_addr_copy(_netif.ip_addr, ip_addr_any); // to allow DHCP at next begin
ip_addr_copy(_netif.netmask, ip_addr_any);
ip_addr_copy(_netif.gw, ip_addr_any);
_started = false;
RawDev::end();
}

template<class RawDev>
wl_status_t LwipIntfDev<RawDev>::status()
{
Expand Down