diff --git a/cores/esp8266/LwipDhcpServer-NonOS.cpp b/cores/esp8266/LwipDhcpServer-NonOS.cpp index aee22b6d5c..0a4d1298cd 100644 --- a/cores/esp8266/LwipDhcpServer-NonOS.cpp +++ b/cores/esp8266/LwipDhcpServer-NonOS.cpp @@ -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_VERSION +#include "LwipDhcpServer-NonOS.h" +#include #include -#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" diff --git a/cores/esp8266/LwipDhcpServer-NonOS.h b/cores/esp8266/LwipDhcpServer-NonOS.h new file mode 100644 index 0000000000..4da4eca1b3 --- /dev/null +++ b/cores/esp8266/LwipDhcpServer-NonOS.h @@ -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(); diff --git a/cores/esp8266/LwipDhcpServer.cpp b/cores/esp8266/LwipDhcpServer.cpp index 07270bb6c2..f5a85f24f7 100644 --- a/cores/esp8266/LwipDhcpServer.cpp +++ b/cores/esp8266/LwipDhcpServer.cpp @@ -36,8 +36,6 @@ #include // LWIP_VERSION -#define DHCPS_LEASE_TIME_DEF (120) - #define USE_DNS #include "lwip/inet.h" @@ -166,7 +164,7 @@ const char mem_debug_file[] ICACHE_RODATA_ATTR = __FILE__; int ret = 1, errval = (err); \ if (errval != ERR_OK) \ { \ - os_printf("DHCPS ERROR: %s (lwip:%d)\n", what, errval); \ + os_printf("DHCPS ERROR: %s (lwip:%s(%d))\n", what, lwip_strerr(errval), errval); \ ret = 0; \ } \ ret; \ @@ -175,36 +173,9 @@ const char mem_debug_file[] ICACHE_RODATA_ATTR = __FILE__; #define LWIP_IS_OK(what, err) ((err) == ERR_OK) #endif -const uint32 DhcpServer::magic_cookie = 0x63538263; // https://tools.ietf.org/html/rfc1497 - -int fw_has_started_softap_dhcps = 0; - //////////////////////////////////////////////////////////////////////////////////// -DhcpServer::DhcpServer(netif* netif) : _netif(netif) -{ - pcb_dhcps = nullptr; - dns_address.addr = 0; - plist = nullptr; - offer = 0xFF; - renew = false; - dhcps_lease_time = DHCPS_LEASE_TIME_DEF; // minute - - if (netif->num == SOFTAP_IF && fw_has_started_softap_dhcps == 1) - { - // When nonos-sdk starts DHCPS at boot: - // 1. `fw_has_started_softap_dhcps` is already initialized to 1 - // 2. global ctor DhcpServer's `dhcpSoftAP(&netif_git[SOFTAP_IF])` is called - // 3. (that's here) => begin(legacy-values) is called - ip_info ip = { - { 0x0104a8c0 }, // IP 192.168.4.1 - { 0x00ffffff }, // netmask 255.255.255.0 - { 0 } // gateway 0.0.0.0 - }; - begin(&ip); - fw_has_started_softap_dhcps = 2; // not 1, ending initial boot sequence - } -}; +DhcpServer::DhcpServer(netif* netif) : _netif(netif) { } // wifi_softap_set_station_info is missing in user_interface.h: extern "C" void wifi_softap_set_station_info(uint8_t* mac, struct ipv4_addr*); @@ -516,7 +487,7 @@ void DhcpServer::create_msg(struct dhcps_msg* m) memset((char*)m->sname, 0, sizeof(m->sname)); memset((char*)m->file, 0, sizeof(m->file)); memset((char*)m->options, 0, sizeof(m->options)); - memcpy((char*)m->options, &magic_cookie, sizeof(magic_cookie)); + memcpy((char*)m->options, &MagicCookie, sizeof(MagicCookie)); } /////////////////////////////////////////////////////////////////////////////////// /* @@ -821,7 +792,7 @@ uint8_t DhcpServer::parse_options(uint8_t* optptr, sint16_t len) /////////////////////////////////////////////////////////////////////////////////// sint16_t DhcpServer::parse_msg(struct dhcps_msg* m, u16_t len) { - if (memcmp((char*)m->options, &magic_cookie, sizeof(magic_cookie)) == 0) + if (memcmp((char*)m->options, &MagicCookie, sizeof(MagicCookie)) == 0) { struct ipv4_addr ip; memcpy(&ip.addr, m->ciaddr, sizeof(ip.addr)); @@ -1008,7 +979,7 @@ void DhcpServer::init_dhcps_lease(uint32 ip) } /////////////////////////////////////////////////////////////////////////////////// -bool DhcpServer::begin(struct ip_info* info) +bool DhcpServer::begin() { if (pcb_dhcps != nullptr) { @@ -1016,9 +987,11 @@ bool DhcpServer::begin(struct ip_info* info) } pcb_dhcps = udp_new(); - if (pcb_dhcps == nullptr || info == nullptr) + if (pcb_dhcps == nullptr) { +#if DHCPS_DEBUG os_printf("dhcps_start(): could not obtain pcb\n"); +#endif return false; } @@ -1030,7 +1003,7 @@ bool DhcpServer::begin(struct ip_info* info) ip_2_ip4(&broadcast_dhcps)->addr |= ~ip_2_ip4(&_netif->netmask)->addr; // XXXFIXMEIPV6 broadcast address? - server_address = info->ip; + server_address = *ip_2_ip4(&_netif->ip_addr); init_dhcps_lease(server_address.addr); udp_bind(pcb_dhcps, IP_ADDR_ANY, DHCPS_SERVER_PORT); @@ -1040,12 +1013,6 @@ bool DhcpServer::begin(struct ip_info* info) "pcb_dhcps\n"); #endif - if (_netif->num == SOFTAP_IF) - { - wifi_set_ip_info(SOFTAP_IF, info); // added for lwip-git, not sure whether useful - } - _netif->flags |= NETIF_FLAG_UP | NETIF_FLAG_LINK_UP; // added for lwip-git - return true; } @@ -1091,9 +1058,9 @@ void DhcpServer::end() } } -bool DhcpServer::isRunning() +bool DhcpServer::isRunning() const { - return !!_netif->state; + return pcb_dhcps != nullptr; } /****************************************************************************** @@ -1342,7 +1309,7 @@ bool DhcpServer::reset_dhcps_lease_time(void) { return false; } - dhcps_lease_time = DHCPS_LEASE_TIME_DEF; + dhcps_lease_time = DefaultLeaseTime; return true; } diff --git a/cores/esp8266/LwipDhcpServer.h b/cores/esp8266/LwipDhcpServer.h index d5eb6410ef..3ec9263342 100644 --- a/cores/esp8266/LwipDhcpServer.h +++ b/cores/esp8266/LwipDhcpServer.h @@ -28,22 +28,24 @@ // nearly as-is. This is an initial version to guaranty legacy behavior // with same default values. -#ifndef __DHCPS_H__ -#define __DHCPS_H__ +#pragma once #include // LWIP_VERSION class DhcpServer { public: - DhcpServer(netif* netif); + static constexpr int DefaultLeaseTime = 720; // minutes + static constexpr uint32 MagicCookie = 0x63538263; // https://tools.ietf.org/html/rfc1497 + + DhcpServer(netif*); ~DhcpServer(); void setDns(int num, const ipv4_addr_t* dns); - bool begin(ip_info* info); + bool begin(); void end(); - bool isRunning(); + bool isRunning() const; // this is the C interface encapsulated in a class // (originally dhcpserver.c in lwIP-v1.4 in NonOS-SDK) @@ -91,25 +93,17 @@ class DhcpServer void dhcps_client_leave(u8* bssid, struct ipv4_addr* ip, bool force); uint32 dhcps_client_update(u8* bssid, struct ipv4_addr* ip); - netif* _netif; + netif* _netif = nullptr; - struct udp_pcb* pcb_dhcps; - ip_addr_t broadcast_dhcps; - struct ipv4_addr server_address; - struct ipv4_addr client_address; - struct ipv4_addr dns_address; - uint32 dhcps_lease_time; + udp_pcb* pcb_dhcps = nullptr; + ip_addr_t broadcast_dhcps {}; + ipv4_addr server_address {}; + ipv4_addr client_address {}; + ipv4_addr dns_address {}; + uint32 dhcps_lease_time = DefaultLeaseTime; struct dhcps_lease dhcps_lease; list_node* plist; uint8 offer; bool renew; - - static const uint32 magic_cookie; }; - -// SoftAP DHCP server always exists and is started on boot -extern DhcpServer dhcpSoftAP; -extern "C" int fw_has_started_softap_dhcps; - -#endif // __DHCPS_H__ diff --git a/libraries/DNSServer/examples/NAPTCaptivePortal/NAPTCaptivePortal.ino b/libraries/DNSServer/examples/NAPTCaptivePortal/NAPTCaptivePortal.ino index cb65f518ef..1fa46291bb 100644 --- a/libraries/DNSServer/examples/NAPTCaptivePortal/NAPTCaptivePortal.ino +++ b/libraries/DNSServer/examples/NAPTCaptivePortal/NAPTCaptivePortal.ino @@ -74,7 +74,6 @@ #include #include #include -#include #include #include #include diff --git a/libraries/ESP8266WiFi/examples/RangeExtender-NAPT/RangeExtender-NAPT.ino b/libraries/ESP8266WiFi/examples/RangeExtender-NAPT/RangeExtender-NAPT.ino index 2c62ded038..3c9caee2fc 100644 --- a/libraries/ESP8266WiFi/examples/RangeExtender-NAPT/RangeExtender-NAPT.ino +++ b/libraries/ESP8266WiFi/examples/RangeExtender-NAPT/RangeExtender-NAPT.ino @@ -13,7 +13,6 @@ #include #include #include -#include #define NAPT 1000 #define NAPT_PORT 10 @@ -54,8 +53,9 @@ void setup() { 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()); // give DNS servers to AP side - dhcpSoftAP.dhcps_set_dns(0, WiFi.dnsIP(0)); - dhcpSoftAP.dhcps_set_dns(1, WiFi.dnsIP(1)); + auto& server = WiFi.softAPDhcpServer(); + server.dhcps_set_dns(0, WiFi.dnsIP(0)); + server.dhcps_set_dns(1, WiFi.dnsIP(1)); WiFi.softAPConfig( // enable AP, with android-compatible google domain IPAddress(172, 217, 28, 254), IPAddress(172, 217, 28, 254), IPAddress(255, 255, 255, 0)); diff --git a/libraries/ESP8266WiFi/examples/StaticLease/StaticLease.ino b/libraries/ESP8266WiFi/examples/StaticLease/StaticLease.ino index e4520c4720..d4ed0cd375 100644 --- a/libraries/ESP8266WiFi/examples/StaticLease/StaticLease.ino +++ b/libraries/ESP8266WiFi/examples/StaticLease/StaticLease.ino @@ -4,7 +4,6 @@ #include #include #include -#include /* Set these to your desired credentials. */ const char *ssid = "ESPap"; @@ -76,8 +75,9 @@ void setup() { ... any client not listed will use next IP address available from the range (here 192.168.0.102 and more) */ - dhcpSoftAP.add_dhcps_lease(mac_CAM); // always 192.168.0.100 - dhcpSoftAP.add_dhcps_lease(mac_PC); // always 192.168.0.101 + auto &dhcpServer = WiFi.softAPDhcpServer(); + dhcpServer.add_dhcps_lease(mac_CAM); // always 192.168.0.100 + dhcpServer.add_dhcps_lease(mac_PC); // always 192.168.0.101 /* Start Access Point. You can remove the password parameter if you want the AP to be open. */ WiFi.softAP(ssid, password); Serial.print("AP IP address: "); diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiAP.cpp b/libraries/ESP8266WiFi/src/ESP8266WiFiAP.cpp index b0a0084853..ffd536a0ba 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiAP.cpp +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiAP.cpp @@ -26,6 +26,8 @@ #include "ESP8266WiFiGeneric.h" #include "ESP8266WiFiAP.h" +#include + extern "C" { #include "c_types.h" #include "ets_sys.h" @@ -37,7 +39,6 @@ extern "C" { } #include "debug.h" -#include "LwipDhcpServer.h" // ----------------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------- Private functions ------------------------------------------------ @@ -166,16 +167,18 @@ bool ESP8266WiFiAPClass::softAP(const char* ssid, const char* psk, int channel, DEBUG_WIFI("[AP] softap config unchanged\n"); } - dhcpSoftAP.end(); + auto& server = softAPDhcpServer(); + server.end(); // check IP config struct ip_info ip; if(wifi_get_ip_info(SOFTAP_IF, &ip)) { if(ip.ip.addr == 0x00000000) { - // Invalid config DEBUG_WIFI("[AP] IP config Invalid resetting...\n"); - //192.168.4.1 , 192.168.4.1 , 255.255.255.0 - ret = softAPConfig(0x0104A8C0, 0x0104A8C0, 0x00FFFFFF); + ret = softAPConfig( + 0x0104A8C0 /* 192.168.4.1 */, + 0x0104A8C0 /* 192.168.4.1 */, + 0x00FFFFFF /* 255.255.255.0 */); if(!ret) { DEBUG_WIFI("[AP] softAPConfig failed!\n"); ret = false; @@ -186,7 +189,7 @@ bool ESP8266WiFiAPClass::softAP(const char* ssid, const char* psk, int channel, ret = false; } - dhcpSoftAP.begin(&ip); + server.begin(); return ret; } @@ -244,21 +247,15 @@ bool ESP8266WiFiAPClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPA dhcp_lease.end_ip.addr = ip.v4(); DEBUG_WIFI("[APConfig] DHCP IP end: %s\n", ip.toString().c_str()); - if(!dhcpSoftAP.set_dhcps_lease(&dhcp_lease)) + auto& server = softAPDhcpServer(); + if(!server.set_dhcps_lease(&dhcp_lease)) { DEBUG_WIFI("[APConfig] wifi_set_ip_info failed!\n"); ret = false; } - // set lease time to 720min --> 12h - if(!dhcpSoftAP.set_dhcps_lease_time(720)) - { - DEBUG_WIFI("[APConfig] wifi_softap_set_dhcps_lease_time failed!\n"); - ret = false; - } - uint8 mode = info.gw.addr ? 1 : 0; - if(!dhcpSoftAP.set_dhcps_offer_option(OFFER_ROUTER, &mode)) + if(!server.set_dhcps_offer_option(OFFER_ROUTER, &mode)) { DEBUG_WIFI("[APConfig] wifi_softap_set_dhcps_offer_option failed!\n"); ret = false; @@ -389,3 +386,11 @@ String ESP8266WiFiAPClass::softAPPSK() const { return psk; } + +/** + * Get the static DHCP server instance attached to the softAP interface + * @return DhcpServer instance. + */ +DhcpServer& ESP8266WiFiAPClass::softAPDhcpServer() { + return getNonOSDhcpServer(); +} diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiAP.h b/libraries/ESP8266WiFi/src/ESP8266WiFiAP.h index b8b3b8fb12..73b3218c32 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiAP.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiAP.h @@ -27,6 +27,7 @@ #include "ESP8266WiFiType.h" #include "ESP8266WiFiGeneric.h" +#include class ESP8266WiFiAPClass { @@ -48,8 +49,10 @@ class ESP8266WiFiAPClass { uint8_t* softAPmacAddress(uint8_t* mac); String softAPmacAddress(void); - String softAPSSID() const; - String softAPPSK() const; + String softAPSSID() const; + String softAPPSK() const; + + static DhcpServer& softAPDhcpServer(); protected: diff --git a/libraries/lwIP_PPP/examples/PPPServer/PPPServer.ino b/libraries/lwIP_PPP/examples/PPPServer/PPPServer.ino index f5e93eeb4b..baa499721e 100644 --- a/libraries/lwIP_PPP/examples/PPPServer/PPPServer.ino +++ b/libraries/lwIP_PPP/examples/PPPServer/PPPServer.ino @@ -19,7 +19,6 @@ #include #include #include -#include #include #include diff --git a/tests/host/Makefile b/tests/host/Makefile index 82222ad299..f819047891 100644 --- a/tests/host/Makefile +++ b/tests/host/Makefile @@ -143,6 +143,7 @@ MOCK_CPP_FILES_EMU := $(MOCK_CPP_FILES_COMMON) \ ArduinoMainUdp.cpp \ ArduinoMainSpiffs.cpp \ ArduinoMainLittlefs.cpp \ + DhcpServer.cpp \ user_interface.cpp \ ) diff --git a/tests/host/common/DhcpServer.cpp b/tests/host/common/DhcpServer.cpp new file mode 100644 index 0000000000..7e88ea88c4 --- /dev/null +++ b/tests/host/common/DhcpServer.cpp @@ -0,0 +1,80 @@ +#include +#include + +DhcpServer& getNonOSDhcpServer() +{ + static DhcpServer instance(nullptr); + return instance; +} + +bool DhcpServer::set_dhcps_lease(struct dhcps_lease* please) +{ + (void)please; + return false; +} + +bool DhcpServer::set_dhcps_lease_time(uint32 minute) +{ + (void)minute; + return false; +} + +bool DhcpServer::set_dhcps_offer_option(uint8 level, void* optarg) +{ + (void)level; + (void)optarg; + return false; +} + +void DhcpServer::end() { } + +bool DhcpServer::begin() +{ + return false; +} + +DhcpServer::DhcpServer(netif*) { } + +DhcpServer::~DhcpServer() +{ + end(); +} + +extern "C" +{ +#include + + bool wifi_softap_dhcps_start(void) + { + return true; + } + + enum dhcp_status wifi_softap_dhcps_status(void) + { + return DHCP_STARTED; + } + + bool wifi_softap_dhcps_stop(void) + { + return true; + } + + bool wifi_softap_set_dhcps_lease(struct dhcps_lease* please) + { + (void)please; + return true; + } + + bool wifi_softap_set_dhcps_lease_time(uint32 minute) + { + (void)minute; + return true; + } + + bool wifi_softap_set_dhcps_offer_option(uint8 level, void* optarg) + { + (void)level; + (void)optarg; + return true; + } +} diff --git a/tests/host/common/user_interface.cpp b/tests/host/common/user_interface.cpp index afb8ed3740..c35a7cc236 100644 --- a/tests/host/common/user_interface.cpp +++ b/tests/host/common/user_interface.cpp @@ -41,47 +41,6 @@ #include "MocklwIP.h" -#include - -bool DhcpServer::set_dhcps_lease(struct dhcps_lease* please) -{ - (void)please; - return false; -} - -bool DhcpServer::set_dhcps_lease_time(uint32 minute) -{ - (void)minute; - return false; -} - -bool DhcpServer::set_dhcps_offer_option(uint8 level, void* optarg) -{ - (void)level; - (void)optarg; - return false; -} - -void DhcpServer::end() { } - -bool DhcpServer::begin(struct ip_info* info) -{ - (void)info; - return false; -} - -DhcpServer::DhcpServer(netif* netif) -{ - (void)netif; -} - -DhcpServer::~DhcpServer() -{ - end(); -} - -DhcpServer dhcpSoftAP(nullptr); - extern "C" { #include @@ -400,21 +359,6 @@ extern "C" (void)max_tpw; } - bool wifi_softap_dhcps_start(void) - { - return true; - } - - enum dhcp_status wifi_softap_dhcps_status(void) - { - return DHCP_STARTED; - } - - bool wifi_softap_dhcps_stop(void) - { - return true; - } - bool wifi_softap_get_config(struct softap_config* config) { strcpy((char*)config->ssid, "apssid"); @@ -450,25 +394,6 @@ extern "C" return true; } - bool wifi_softap_set_dhcps_lease(struct dhcps_lease* please) - { - (void)please; - return true; - } - - bool wifi_softap_set_dhcps_lease_time(uint32 minute) - { - (void)minute; - return true; - } - - bool wifi_softap_set_dhcps_offer_option(uint8 level, void* optarg) - { - (void)level; - (void)optarg; - return true; - } - bool wifi_station_scan(struct scan_config* config, scan_done_cb_t cb) { (void)config; diff --git a/tools/sdk/include/user_interface.h b/tools/sdk/include/user_interface.h index e69821b372..696583d2ba 100644 --- a/tools/sdk/include/user_interface.h +++ b/tools/sdk/include/user_interface.h @@ -382,17 +382,17 @@ void wifi_softap_free_station_info(void); bool wifi_softap_dhcps_start(void); bool wifi_softap_dhcps_stop(void); -#if 1 // dhcp server -// these functions are open-source, in dhcp server, -// which is now moved to lwIPDhcpServer.cpp (lwip2) -// (but still there with lwip1) +// esp8266/Arduino notice: +// these dhcp functions are no longer provided by the lwip lib +// only way to include them is to build our NonOS LwipDhcpServer helpers +// (ref. libraries/ESP8266WiFi/src/ESP8266WiFiAP-DhcpServer.cpp) + bool wifi_softap_set_dhcps_lease(struct dhcps_lease *please); bool wifi_softap_get_dhcps_lease(struct dhcps_lease *please); uint32 wifi_softap_get_dhcps_lease_time(void); bool wifi_softap_set_dhcps_lease_time(uint32 minute); bool wifi_softap_reset_dhcps_lease_time(void); bool wifi_softap_add_dhcps_lease(uint8 *macaddr); // add static lease on the list, this will be the next available @ -#endif // dhcp server enum dhcp_status wifi_softap_dhcps_status(void); bool wifi_softap_set_dhcps_offer_option(uint8 level, void* optarg); diff --git a/tools/sdk/lwip2/include/dhcpserver.h b/tools/sdk/lwip2/include/dhcpserver.h deleted file mode 100644 index 4ec907126f..0000000000 --- a/tools/sdk/lwip2/include/dhcpserver.h +++ /dev/null @@ -1,130 +0,0 @@ - -// adapted from dhcpserver.c distributed in esp8266 sdk 2.0.0 -// same license may apply - -#ifndef __DHCPS_H__ -#define __DHCPS_H__ - -#include "glue.h" // for UDEBUG - -#define USE_DNS - -typedef struct dhcps_state{ - sint16_t state; -} dhcps_state; - -typedef struct dhcps_msg { - uint8_t op, htype, hlen, hops; - uint8_t xid[4]; - uint16_t secs, flags; - uint8_t ciaddr[4]; - uint8_t yiaddr[4]; - uint8_t siaddr[4]; - uint8_t giaddr[4]; - uint8_t chaddr[16]; - uint8_t sname[64]; - uint8_t file[128]; - uint8_t options[312]; -}dhcps_msg; - -#ifndef LWIP_OPEN_SRC -struct dhcps_lease { - bool enable; - struct ipv4_addr start_ip; - struct ipv4_addr end_ip; -}; - -enum dhcps_offer_option{ - OFFER_START = 0x00, - OFFER_ROUTER = 0x01, - OFFER_END -}; -#endif - -typedef enum { - DHCPS_TYPE_DYNAMIC, - DHCPS_TYPE_STATIC -} dhcps_type_t; - -typedef enum { - DHCPS_STATE_ONLINE, - DHCPS_STATE_OFFLINE -} dhcps_state_t; - -struct dhcps_pool{ - struct ipv4_addr ip; - uint8 mac[6]; - uint32 lease_timer; - dhcps_type_t type; - dhcps_state_t state; - -}; - -typedef struct _list_node{ - void *pnode; - struct _list_node *pnext; -}list_node; - -extern uint32 dhcps_lease_time; -#define DHCPS_LEASE_TIMER dhcps_lease_time //0x05A0 -#define DHCPS_MAX_LEASE 0x64 -#define BOOTP_BROADCAST 0x8000 - -#define DHCP_REQUEST 1 -#define DHCP_REPLY 2 -#define DHCP_HTYPE_ETHERNET 1 -#define DHCP_HLEN_ETHERNET 6 -#define DHCP_MSG_LEN 236 - -#define DHCPS_SERVER_PORT 67 -#define DHCPS_CLIENT_PORT 68 - -#define DHCPDISCOVER 1 -#define DHCPOFFER 2 -#define DHCPREQUEST 3 -#define DHCPDECLINE 4 -#define DHCPACK 5 -#define DHCPNAK 6 -#define DHCPRELEASE 7 - -#define DHCP_OPTION_SUBNET_MASK 1 -#define DHCP_OPTION_ROUTER 3 -#define DHCP_OPTION_DNS_SERVER 6 -#define DHCP_OPTION_REQ_IPADDR 50 -#define DHCP_OPTION_LEASE_TIME 51 -#define DHCP_OPTION_MSG_TYPE 53 -#define DHCP_OPTION_SERVER_ID 54 -#define DHCP_OPTION_INTERFACE_MTU 26 -#define DHCP_OPTION_PERFORM_ROUTER_DISCOVERY 31 -#define DHCP_OPTION_BROADCAST_ADDRESS 28 -#define DHCP_OPTION_REQ_LIST 55 -#define DHCP_OPTION_END 255 - -//#define USE_CLASS_B_NET 1 -#define DHCPS_DEBUG UDEBUG -#define MAX_STATION_NUM 8 - -#define DHCPS_STATE_OFFER 1 -#define DHCPS_STATE_DECLINE 2 -#define DHCPS_STATE_ACK 3 -#define DHCPS_STATE_NAK 4 -#define DHCPS_STATE_IDLE 5 -#define DHCPS_STATE_RELEASE 6 - -#define dhcps_router_enabled(offer) ((offer & OFFER_ROUTER) != 0) - -#ifdef __cplusplus -extern "C" -{ -#endif - -void dhcps_set_dns (int num, const ipv4_addr_t* dns); - -void dhcps_start(struct ip_info *info); -void dhcps_stop(void); - -#ifdef __cplusplus -} -#endif - -#endif 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