-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initialize SoftAP DhcpServer object on demand (#8546)
* Initialize SoftAP DhcpServer object on demand Remove dependency on global ctor, and just construct the object when someone asks us to do it. Only dependency right now is netif_git, which is expected to be initialized by the lwip code some time before dhcps_start happens. Removing ip_info from begin(), since we never reference later on. Also removing the specific check for netif id and simplify the ctors. Update tests and recover old nonos-sdk dhcps functions that were not implemented. * nonos helpers have a separate header * wifi ap needs this anyway, simplify sketch includes * missing example * existing name :/ * trying to fix header dependency * restyle * not a c header * no need to init * move dhcp server getter to WiFi more... arduino'ish? we ahve object as namespace, plus everything else related to softAP is there redundant includes, redundant mock impl (out-of-scope here to fix) * ...move things back, still expose as WiFi method * review fix * include -nonos header in wifi lib though * no more lwip include * style * need mock dhcpserver instance
- Loading branch information
Showing
15 changed files
with
233 additions
and
334 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,95 @@ | ||
/* | ||
lwIPDhcpServer-NonOS.cpp - DHCP server wrapper | ||
NonOS DHCP server helpers | ||
Copyright (c) 2020 esp8266 arduino. All rights reserved. | ||
Copyright (c) 2020-2022 esp8266 arduino. All rights reserved. | ||
This file is part of the esp8266 core for Arduino environment. | ||
This library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2.1 of the License, or (at your option) any later version. | ||
This library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with this library; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
// STARTS/STOPS DHCP SERVER ON WIFI AP INTERFACE | ||
// these functions must exists as-is with "C" interface, | ||
// nonos-sdk calls them at boot time and later | ||
|
||
#include <lwip/init.h> // LWIP_VERSION | ||
#include "LwipDhcpServer-NonOS.h" | ||
|
||
#include <lwip/init.h> | ||
#include <lwip/netif.h> | ||
#include "LwipDhcpServer.h" | ||
|
||
extern netif netif_git[2]; | ||
|
||
// global DHCP instance for softAP interface | ||
DhcpServer dhcpSoftAP(&netif_git[SOFTAP_IF]); | ||
// Global static DHCP instance for softAP interface | ||
// (since the netif object never goes away, even when AP is disabled) | ||
// Initial version fully emulates nonos-sdk api in DhcpServer class, | ||
// before trying to further change it and possibly break legacy behaviour | ||
DhcpServer& getNonOSDhcpServer() | ||
{ | ||
extern netif netif_git[2]; | ||
static DhcpServer server(&netif_git[SOFTAP_IF]); | ||
return server; | ||
} | ||
|
||
extern "C" | ||
{ | ||
void dhcps_start(struct ip_info* info, netif* apnetif) | ||
{ | ||
// apnetif is esp interface, replaced by lwip2's | ||
// netif_git[SOFTAP_IF] interface in constructor | ||
(void)apnetif; | ||
|
||
#if 0 | ||
// can't use C++ now, global ctors are not initialized yet | ||
dhcpSoftAP.begin(info); | ||
#else | ||
(void)info; | ||
// initial version: emulate nonos-sdk in DhcpServer class before | ||
// trying to change legacy behavor | ||
// `fw_has_started_softap_dhcps` will be read in DhcpServer::DhcpServer | ||
// which is called when c++ ctors are initialized, specifically | ||
// dhcpSoftAP initialized with AP interface number above. | ||
fw_has_started_softap_dhcps = 1; | ||
#endif | ||
// `ip_info` is useless, since we get the information from the netif directly | ||
// `netif` would be netif_git[SOFTAP_IF], which we get from the lwip2 glue | ||
void dhcps_start(ip_info*, netif*) | ||
{ | ||
auto& server = getNonOSDhcpServer(); | ||
if (!server.isRunning()) | ||
{ | ||
server.begin(); | ||
} | ||
} | ||
|
||
void dhcps_stop() | ||
{ | ||
dhcpSoftAP.end(); | ||
auto& server = getNonOSDhcpServer(); | ||
if (server.isRunning()) | ||
{ | ||
server.end(); | ||
} | ||
} | ||
|
||
// providing the rest of the nonos-sdk API, which was originally removed in 3.0.0 | ||
|
||
bool wifi_softap_set_dhcps_lease(dhcps_lease* please) | ||
{ | ||
auto& server = getNonOSDhcpServer(); | ||
return server.set_dhcps_lease(please); | ||
} | ||
|
||
bool wifi_softap_get_dhcps_lease(dhcps_lease* please) | ||
{ | ||
auto& server = getNonOSDhcpServer(); | ||
return server.get_dhcps_lease(please); | ||
} | ||
|
||
uint32 wifi_softap_get_dhcps_lease_time() | ||
{ | ||
auto& server = getNonOSDhcpServer(); | ||
return server.get_dhcps_lease_time(); | ||
} | ||
|
||
bool wifi_softap_set_dhcps_lease_time(uint32 minutes) | ||
{ | ||
auto& server = getNonOSDhcpServer(); | ||
return server.set_dhcps_lease_time(minutes); | ||
} | ||
|
||
bool wifi_softap_reset_dhcps_lease_time() | ||
{ | ||
auto& server = getNonOSDhcpServer(); | ||
return server.reset_dhcps_lease_time(); | ||
} | ||
|
||
bool wifi_softap_add_dhcps_lease(uint8* macaddr) | ||
{ | ||
auto& server = getNonOSDhcpServer(); | ||
return server.add_dhcps_lease(macaddr); | ||
} | ||
|
||
} // extern "C" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
NonOS DHCP server helpers | ||
Copyright (c) 2020-2022 esp8266 arduino. All rights reserved. | ||
This file is part of the esp8266 core for Arduino environment. | ||
This library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2.1 of the License, or (at your option) any later version. | ||
This library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with this library; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "LwipDhcpServer.h" | ||
|
||
// Global static DHCP instance for softAP interface | ||
DhcpServer& getNonOSDhcpServer(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.