Skip to content

Commit 955c19a

Browse files
committed
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)
1 parent cc5fc18 commit 955c19a

File tree

8 files changed

+32
-67
lines changed

8 files changed

+32
-67
lines changed

cores/esp8266/LwipDhcpServer-NonOS.h

Lines changed: 0 additions & 28 deletions
This file was deleted.

libraries/ESP8266WiFi/examples/RangeExtender-NAPT/RangeExtender-NAPT.ino

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <ESP8266WiFi.h>
1414
#include <lwip/napt.h>
1515
#include <lwip/dns.h>
16-
#include <LwipDhcpServer.h>
1716

1817
#define NAPT 1000
1918
#define NAPT_PORT 10
@@ -54,7 +53,7 @@ void setup() {
5453
Serial.printf("\nSTA: %s (dns: %s / %s)\n", WiFi.localIP().toString().c_str(), WiFi.dnsIP(0).toString().c_str(), WiFi.dnsIP(1).toString().c_str());
5554

5655
// give DNS servers to AP side
57-
auto& server = dhcpSoftAP();
56+
auto& server = WiFi.softAPDhcpServer();
5857
server.dhcps_set_dns(0, WiFi.dnsIP(0));
5958
server.dhcps_set_dns(1, WiFi.dnsIP(1));
6059

libraries/ESP8266WiFi/examples/StaticLease/StaticLease.ino

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <ESP8266WiFi.h>
55
#include <WiFiClient.h>
66
#include <ESP8266WebServer.h>
7-
#include <LwipDhcpServer.h>
87

98
/* Set these to your desired credentials. */
109
const char *ssid = "ESPap";
@@ -76,7 +75,7 @@ void setup() {
7675
...
7776
any client not listed will use next IP address available from the range (here 192.168.0.102 and more)
7877
*/
79-
auto &dhcpServer = dhcpSoftAP();
78+
auto &dhcpServer = WiFi.softAPDhcpServer();
8079
dhcpServer.add_dhcps_lease(mac_CAM); // always 192.168.0.100
8180
dhcpServer.add_dhcps_lease(mac_PC); // always 192.168.0.101
8281
/* Start Access Point. You can remove the password parameter if you want the AP to be open. */
Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,58 @@
11
/*
2-
lwIPDhcpServer-NonOS - DHCP server wrapper
2+
NonOS DHCP server helpers
33
4-
Copyright (c) 2020 esp8266 arduino. All rights reserved.
4+
Copyright (c) 2020-2022 esp8266 arduino. All rights reserved.
55
This file is part of the esp8266 core for Arduino environment.
6-
76
This library is free software; you can redistribute it and/or
87
modify it under the terms of the GNU Lesser General Public
98
License as published by the Free Software Foundation; either
109
version 2.1 of the License, or (at your option) any later version.
11-
1210
This library is distributed in the hope that it will be useful,
1311
but WITHOUT ANY WARRANTY; without even the implied warranty of
1412
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1513
Lesser General Public License for more details.
16-
1714
You should have received a copy of the GNU Lesser General Public
1815
License along with this library; if not, write to the Free Software
1916
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2017
*/
2118

22-
// STARTS/STOPS DHCP SERVER ON WIFI AP INTERFACE
23-
// these functions must exists as-is with "C" interface,
24-
// nonos-sdk calls them at boot time and later
25-
26-
#include "LwipDhcpServer-NonOS.h"
19+
#include "ESP8266WiFi.h"
20+
#include "ESP8266WiFiAP.h"
2721

22+
#include <lwip/init.h>
2823
#include <lwip/netif.h>
2924

3025
// Global static DHCP instance for softAP interface
3126
// (since the netif object never goes away, even when AP is disabled)
3227
// Initial version fully emulates nonos-sdk api in DhcpServer class,
3328
// before trying to further change it and possibly break legacy behaviour
34-
DhcpServer& dhcpSoftAP()
29+
static DhcpServer& getNonOSDhcpServer()
3530
{
3631
extern netif netif_git[2];
3732
static DhcpServer server(&netif_git[SOFTAP_IF]);
3833
return server;
3934
}
4035

36+
DhcpServer& ESP8266WiFiAPClass::softAPDhcpServer()
37+
{
38+
return getNonOSDhcpServer();
39+
}
40+
4141
extern "C"
4242
{
4343
// `ip_info` is useless, since we get the information from the netif directly
4444
// `netif` would be netif_git[SOFTAP_IF], which we get from the lwip2 glue
4545
void dhcps_start(ip_info*, netif*)
4646
{
47-
auto& server = dhcpSoftAP();
47+
auto& server = getNonOSDhcpServer();
4848
if (!server.isRunning())
4949
{
5050
server.begin();
5151
}
5252
}
5353

54-
void dhcps_stop()
55-
{
56-
auto& server = dhcpSoftAP();
54+
void dhcps_stop() {
55+
auto& server = getNonOSDhcpServer();
5756
if (server.isRunning())
5857
{
5958
server.end();
@@ -64,38 +63,40 @@ extern "C"
6463

6564
bool wifi_softap_set_dhcps_lease(dhcps_lease* please)
6665
{
67-
auto& server = dhcpSoftAP();
66+
auto& server = getNonOSDhcpServer();
6867
return server.set_dhcps_lease(please);
6968
}
7069

7170
bool wifi_softap_get_dhcps_lease(dhcps_lease* please)
7271
{
73-
auto& server = dhcpSoftAP();
72+
auto& server = getNonOSDhcpServer();
7473
return server.get_dhcps_lease(please);
7574
}
7675

7776
uint32 wifi_softap_get_dhcps_lease_time()
7877
{
79-
auto& server = dhcpSoftAP();
78+
auto& server = getNonOSDhcpServer();
8079
return server.get_dhcps_lease_time();
8180
}
8281

8382
bool wifi_softap_set_dhcps_lease_time(uint32 minutes)
8483
{
85-
auto& server = dhcpSoftAP();
84+
auto& server = getNonOSDhcpServer();
8685
return server.set_dhcps_lease_time(minutes);
8786
}
8887

8988
bool wifi_softap_reset_dhcps_lease_time()
9089
{
91-
auto& server = dhcpSoftAP();
90+
auto& server = getNonOSDhcpServer();
9291
return server.reset_dhcps_lease_time();
9392
}
9493

9594
bool wifi_softap_add_dhcps_lease(uint8* macaddr)
9695
{
97-
auto& server = dhcpSoftAP();
96+
auto& server = getNonOSDhcpServer();
9897
return server.add_dhcps_lease(macaddr);
9998
}
10099

101100
} // extern "C"
101+
102+

libraries/ESP8266WiFi/src/ESP8266WiFiAP.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ extern "C" {
3838

3939
#include "debug.h"
4040

41-
#include <LwipDhcpServer.h>
42-
4341
// -----------------------------------------------------------------------------------------------------------------------
4442
// ---------------------------------------------------- Private functions ------------------------------------------------
4543
// -----------------------------------------------------------------------------------------------------------------------
@@ -167,7 +165,7 @@ bool ESP8266WiFiAPClass::softAP(const char* ssid, const char* psk, int channel,
167165
DEBUG_WIFI("[AP] softap config unchanged\n");
168166
}
169167

170-
auto& server = dhcpSoftAP();
168+
auto& server = softAPDhcpServer();
171169
server.end();
172170

173171
// check IP config
@@ -247,7 +245,7 @@ bool ESP8266WiFiAPClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPA
247245
dhcp_lease.end_ip.addr = ip.v4();
248246
DEBUG_WIFI("[APConfig] DHCP IP end: %s\n", ip.toString().c_str());
249247

250-
auto& server = dhcpSoftAP();
248+
auto& server = softAPDhcpServer();
251249
if(!server.set_dhcps_lease(&dhcp_lease))
252250
{
253251
DEBUG_WIFI("[APConfig] wifi_set_ip_info failed!\n");

libraries/ESP8266WiFi/src/ESP8266WiFiAP.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include "ESP8266WiFiType.h"
2828
#include "ESP8266WiFiGeneric.h"
2929

30-
#include <LwipDhcpServer-NonOS.h>
30+
#include <LwipDhcpServer.h>
3131

3232
class ESP8266WiFiAPClass {
3333

@@ -49,8 +49,10 @@ class ESP8266WiFiAPClass {
4949
uint8_t* softAPmacAddress(uint8_t* mac);
5050
String softAPmacAddress(void);
5151

52-
String softAPSSID() const;
53-
String softAPPSK() const;
52+
String softAPSSID() const;
53+
String softAPPSK() const;
54+
55+
static DhcpServer& softAPDhcpServer();
5456

5557
protected:
5658

tests/host/common/user_interface.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,6 @@ DhcpServer::~DhcpServer()
7676
end();
7777
}
7878

79-
DhcpServer& dhcpSoftAP()
80-
{
81-
static DhcpServer server(nullptr);
82-
return server;
83-
}
84-
8579
extern "C"
8680
{
8781
#include <user_interface.h>

tools/sdk/include/user_interface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ bool wifi_softap_dhcps_stop(void);
385385
// esp8266/Arduino notice:
386386
// these dhcp functions are no longer provided by the lwip lib
387387
// only way to include them is to build our NonOS LwipDhcpServer helpers
388-
// (ref. cores/esp8266/LwipDhcpServer-NonOS.cpp)
388+
// (ref. libraries/ESP8266WiFi/src/ESP8266WiFiAP-DhcpServer.cpp)
389389

390390
bool wifi_softap_set_dhcps_lease(struct dhcps_lease *please);
391391
bool wifi_softap_get_dhcps_lease(struct dhcps_lease *please);

0 commit comments

Comments
 (0)