Skip to content

WiFi: ARP gratuitous API for wifi station mode #6889

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

Merged
merged 20 commits into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
update API
  • Loading branch information
d-a-v committed Dec 8, 2019
commit 8d433ca6d5c51df17d2c315feeaf43c43755692b
2 changes: 1 addition & 1 deletion libraries/ESP8266WiFi/keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ BSSIDstr KEYWORD2
RSSI KEYWORD2
stationKeepAliveSetIntervalMs KEYWORD2
stationKeepAliveStop KEYWORD2
stationKeepAliveEnabled KEYWORD2
stationKeepAliveNow KEYWORD2
enableInsecureWEP KEYWORD2
getListenInterval KEYWORD2
isSleepLevelMax KEYWORD2
Expand Down
77 changes: 44 additions & 33 deletions libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,48 +713,59 @@ int32_t ESP8266WiFiSTAClass::RSSI(void) {

void ESP8266WiFiSTAClass::stationKeepAliveNow ()
{
if (_keepStationAliveUs > 0)
{
for (netif* interface = netif_list; interface != nullptr; interface = interface->next)
if (
(interface->flags & NETIF_FLAG_LINK_UP)
&& (interface->flags & NETIF_FLAG_UP)
for (netif* interface = netif_list; interface != nullptr; interface = interface->next)
if (
(interface->flags & NETIF_FLAG_LINK_UP)
&& (interface->flags & NETIF_FLAG_UP)
#if LWIP_VERSION_MAJOR == 1
&& interface == eagle_lwip_getif(STATION_IF) /* lwip1 does not set num properly */
&& (!ip_addr_isany(&interface->ip_addr))
&& interface == eagle_lwip_getif(STATION_IF) /* lwip1 does not set if->num properly */
&& (!ip_addr_isany(&interface->ip_addr))
#else
&& interface->num == STATION_IF
&& (!ip4_addr_isany_val(*netif_ip4_addr(interface)))
&& interface->num == STATION_IF
&& (!ip4_addr_isany_val(*netif_ip4_addr(interface)))
#endif
)
{
etharp_gratuitous(interface);
break;
}

// re/schedule with a possibly updated interval
schedule_recurrent_function_us([&]()
{
stationKeepAliveNow();
return false;
}, _keepStationAliveUs);
}
else
// mark disabled (0) if user cancelled it (<0)
_keepStationAliveUs = 0;
)
{
etharp_gratuitous(interface);
break;
}
}

void ESP8266WiFiSTAClass::stationKeepAliveSetIntervalMs (int ms)
{
bool wasEnabled = (_keepStationAliveUs > 0);
int us = ms * 1000;
if (wasEnabled)
_keepStationAliveUs = ms <= 0? /*disable*/-1: /*update*/us;
else if (ms > 0)
int us;
if (ms > std::numeric_limits<int>::max() / 1000)
// for sanity only, 24 days is not really meaningful
us = std::numeric_limits<int>::max();
else
us = ms * 1000;

// cancel possibly already scheduled future events
_keepStationState++;

if (us)
{
_keepStationAliveUs = us;
// start
// send one now
stationKeepAliveNow();

// schedule next ones
int checkState = _keepStationState;
schedule_recurrent_function_us([&, checkState]()
{
Serial.printf("--- %d %d\n", checkState, this->_keepStationState);
// this recurring scheduled function will be cancelled
// when this->_keepStationState != checkState
if (checkState != this->_keepStationState)
// cancel this recurring event
return false;

Serial.printf("--- SEND\n");
// send gratuitous ARP
this->stationKeepAliveNow();

// keep on with next event
return true;
}, us);
}
}

Expand Down
17 changes: 8 additions & 9 deletions libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class ESP8266WiFiSTAClass {
wl_status_t begin(const String& ssid, const String& passphrase = emptyString, int32_t channel = 0, const uint8_t* bssid = NULL, bool connect = true);
wl_status_t begin();

//The argument order for ESP is not the same as for Arduino. However, there is compatibility code under the hood
//to detect Arduino arg order, and handle it correctly. Be aware that the Arduino default value handling doesn't
//The argument order for ESP is not the same as for Arduino. However, there is compatibility code under the hood
//to detect Arduino arg order, and handle it correctly. Be aware that the Arduino default value handling doesn't
//work here (see Arduino docs for gway/subnet defaults). In other words: at least 3 args must always be given.
bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000);

Expand Down Expand Up @@ -83,26 +83,25 @@ class ESP8266WiFiSTAClass {

int32_t RSSI();

// enable or update automatic sending of Gratuitous ARP packets
// based on a time interval in milliseconds
// disable(0) or enable/update automatic sending of Gratuitous ARP packets
// a gratuitous ARP packet is sent at start, then
// based on a time interval in milliseconds, default 1s
void stationKeepAliveSetIntervalMs (int ms = 1000);

// request for stopping arp gratuitous packets
void stationKeepAliveStop () { stationKeepAliveSetIntervalMs(0); }

// allows to check whether the gratuitous ARP service is still running
bool stationKeepAliveEnabled () const { return _keepStationAliveUs != 0; }

// immediately send one gratuitous ARP from STA
static void stationKeepAliveNow ();

static void enableInsecureWEP (bool enable = true) { _useInsecureWEP = enable; }

protected:

int _keepStationAliveUs = 0;
static bool _useStaticIp;
static bool _useInsecureWEP;

void stationKeepAliveNow ();
int _keepStationState = 0;

// ----------------------------------------------------------------------------------------------
// ------------------------------------ STA remote configure -----------------------------------
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy