Skip to content

Commit eb891cd

Browse files
committed
Revert "Added support for user-supplied DHCP range, with basic sanity checks (#3562)"
This reverts commit bdf2296.
1 parent 35d5fab commit eb891cd

File tree

2 files changed

+23
-62
lines changed

2 files changed

+23
-62
lines changed

libraries/ESP8266WiFi/src/ESP8266WiFiAP.cpp

+23-61
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,8 @@ bool ESP8266WiFiAPClass::softAP(const char* ssid, const char* passphrase, int ch
179179
* @param local_ip access point IP
180180
* @param gateway gateway IP
181181
* @param subnet subnet mask
182-
* @param dhcp_start first IP assigned by DHCP
183-
* @param dhcp_end last IP assigned by DHCP
184182
*/
185-
bool ESP8266WiFiAPClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dhcp_start, IPAddress dhcp_end) {
183+
bool ESP8266WiFiAPClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet) {
186184
DEBUG_WIFI("[APConfig] local_ip: %s gateway: %s subnet: %s\n", local_ip.toString().c_str(), gateway.toString().c_str(), subnet.toString().c_str());
187185
if(!WiFi.enableAP(true)) {
188186
// enable AP failed
@@ -206,52 +204,35 @@ bool ESP8266WiFiAPClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPA
206204
}
207205

208206
struct dhcps_lease dhcp_lease;
207+
IPAddress ip = local_ip;
208+
ip[3] += 99;
209+
dhcp_lease.start_ip.addr = static_cast<uint32_t>(ip);
210+
DEBUG_WIFI("[APConfig] DHCP IP start: %s\n", ip.toString().c_str());
209211

210-
uint32_t net_addr = info.ip.addr & info.netmask.addr;
211-
uint32_t bcast_addr = net_addr | !info.netmask.addr;
212-
213-
// Assign user-supplied range, checking its validity
214-
IPAddress ip = (static_cast<uint32_t>(dhcp_start) & !info.netmask.addr) | net_addr;
212+
ip[3] += 100;
213+
dhcp_lease.end_ip.addr = static_cast<uint32_t>(ip);
214+
DEBUG_WIFI("[APConfig] DHCP IP end: %s\n", ip.toString().c_str());
215215

216-
dhcp_lease.start_ip.addr = ip;
217-
if(ip != net_addr && ip != bcast_addr && ip != info.ip.addr && ip != info.gw.addr) {
218-
DEBUG_WIFI("[APConfig] DHCP IP start: %s\n", ip.toString().c_str());
219-
} else {
220-
dhcp_lease.start_ip.addr=0;
216+
if(!wifi_softap_set_dhcps_lease(&dhcp_lease)) {
217+
DEBUG_WIFI("[APConfig] wifi_set_ip_info failed!\n");
218+
ret = false;
221219
}
222220

223-
ip = (static_cast<uint32_t>(dhcp_end) & !info.netmask.addr) | net_addr;
224-
dhcp_lease.end_ip.addr = static_cast<uint32_t>(ip);
225-
if(ip != net_addr && ip != bcast_addr && ip != info.ip.addr && ip != info.gw.addr) {
226-
DEBUG_WIFI("[APConfig] DHCP IP end: %s\n", ip.toString().c_str());
227-
} else {
228-
dhcp_lease.end_ip.addr=0;
221+
// set lease time to 720min --> 12h
222+
if(!wifi_softap_set_dhcps_lease_time(720)) {
223+
DEBUG_WIFI("[APConfig] wifi_softap_set_dhcps_lease_time failed!\n");
224+
ret = false;
229225
}
230226

231-
if(dhcp_lease.start_ip.addr && dhcp_lease.end_ip.addr) {
232-
if(!wifi_softap_set_dhcps_lease(&dhcp_lease)) {
233-
DEBUG_WIFI("[APConfig] wifi_set_ip_info failed!\n");
234-
ret = false;
235-
}
236-
237-
// set lease time to 720min --> 12h
238-
if(!wifi_softap_set_dhcps_lease_time(720)) {
239-
DEBUG_WIFI("[APConfig] wifi_softap_set_dhcps_lease_time failed!\n");
240-
ret = false;
241-
}
242-
243-
uint8 mode = 1;
244-
if(!wifi_softap_set_dhcps_offer_option(OFFER_ROUTER, &mode)) {
245-
DEBUG_WIFI("[APConfig] wifi_softap_set_dhcps_offer_option failed!\n");
246-
ret = false;
247-
}
227+
uint8 mode = 1;
228+
if(!wifi_softap_set_dhcps_offer_option(OFFER_ROUTER, &mode)) {
229+
DEBUG_WIFI("[APConfig] wifi_softap_set_dhcps_offer_option failed!\n");
230+
ret = false;
231+
}
248232

249-
if(!wifi_softap_dhcps_start()) {
250-
DEBUG_WIFI("[APConfig] wifi_softap_dhcps_start failed!\n");
251-
ret = false;
252-
}
253-
} else {
254-
DEBUG_WIFI("[APConfig] DHCP daemon not started (range error or user request)\n");
233+
if(!wifi_softap_dhcps_start()) {
234+
DEBUG_WIFI("[APConfig] wifi_softap_dhcps_start failed!\n");
235+
ret = false;
255236
}
256237

257238
// check config
@@ -273,25 +254,6 @@ bool ESP8266WiFiAPClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPA
273254
}
274255

275256

276-
/**
277-
* Configure access point
278-
* @param local_ip access point IP
279-
* @param gateway gateway IP
280-
* @param subnet subnet mask
281-
*/
282-
bool ESP8266WiFiAPClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet) {
283-
IPAddress dhcp_start;
284-
IPAddress dhcp_end;
285-
286-
// calculate dhcp_start and DHCP_end as done in the old code
287-
dhcp_start = local_ip;
288-
dhcp_start[3] += 99;
289-
dhcp_end = dhcp_start;
290-
dhcp_end[3] += 100;
291-
292-
softAPConfig(local_ip, gateway, subnet, dhcp_start, dhcp_end);
293-
}
294-
295257

296258
/**
297259
* Disconnect from the network (close AP)

libraries/ESP8266WiFi/src/ESP8266WiFiAP.h

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ class ESP8266WiFiAPClass {
3737
public:
3838

3939
bool softAP(const char* ssid, const char* passphrase = NULL, int channel = 1, int ssid_hidden = 0, int max_connection = 4);
40-
bool softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dhcp_start, IPAddress dhcp_end);
4140
bool softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet);
4241
bool softAPdisconnect(bool wifioff = false);
4342

0 commit comments

Comments
 (0)