|
| 1 | +/* |
| 2 | + lwIPDhcpServer-NonOS.cpp - DHCP server wrapper |
| 3 | +
|
| 4 | + Copyright (c) 2020 esp8266 arduino. All rights reserved. |
| 5 | + This file is part of the esp8266 core for Arduino environment. |
| 6 | +
|
| 7 | + This library is free software; you can redistribute it and/or |
| 8 | + modify it under the terms of the GNU Lesser General Public |
| 9 | + License as published by the Free Software Foundation; either |
| 10 | + version 2.1 of the License, or (at your option) any later version. |
| 11 | +
|
| 12 | + This library is distributed in the hope that it will be useful, |
| 13 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | + Lesser General Public License for more details. |
| 16 | +
|
| 17 | + You should have received a copy of the GNU Lesser General Public |
| 18 | + License along with this library; if not, write to the Free Software |
| 19 | + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | +*/ |
| 21 | + |
| 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 <lwip/init.h> // LWIP_VERSION |
| 27 | + |
| 28 | +#include <lwip/netif.h> |
| 29 | +#include "LwipDhcpServer.h" |
| 30 | + |
| 31 | +extern netif netif_git[2]; |
| 32 | + |
| 33 | +// global DHCP instance for softAP interface |
| 34 | +DhcpServer dhcpSoftAP(&netif_git[SOFTAP_IF]); |
| 35 | + |
| 36 | +extern "C" |
| 37 | +{ |
| 38 | + |
| 39 | + void dhcps_start(struct ip_info *info, netif* apnetif) |
| 40 | + { |
| 41 | + // apnetif is esp interface, replaced by lwip2's |
| 42 | + // netif_git[SOFTAP_IF] interface in constructor |
| 43 | + (void)apnetif; |
| 44 | + |
| 45 | +#if 0 |
| 46 | + // can't use C++ now, global ctors are not initialized yet |
| 47 | + dhcpSoftAP.begin(info); |
| 48 | +#else |
| 49 | + (void)info; |
| 50 | + // initial version: emulate nonos-sdk in DhcpServer class before |
| 51 | + // trying to change legacy behavor |
| 52 | + // `fw_has_started_softap_dhcps` will be read in DhcpServer::DhcpServer |
| 53 | + // which is called when c++ ctors are initialized, specifically |
| 54 | + // dhcpSoftAP intialized with AP interface number above. |
| 55 | + fw_has_started_softap_dhcps = 1; |
| 56 | +#endif |
| 57 | + } |
| 58 | + |
| 59 | + void dhcps_stop() |
| 60 | + { |
| 61 | + dhcpSoftAP.end(); |
| 62 | + } |
| 63 | + |
| 64 | +} // extern "C" |
0 commit comments