forked from esp8266/Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLwipDhcpServer-NonOS.cpp
97 lines (83 loc) · 2.91 KB
/
LwipDhcpServer-NonOS.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
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
*/
#include "LwipDhcpServer-NonOS.h"
#include <lwip/init.h>
#include <lwip/netif.h>
// 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"
{
// `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()
{
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.getLeaseTime();
}
bool wifi_softap_set_dhcps_lease_time(uint32 minutes)
{
auto& server = getNonOSDhcpServer();
server.setLeaseTime(minutes);
return true;
}
bool wifi_softap_reset_dhcps_lease_time()
{
auto& server = getNonOSDhcpServer();
server.resetLeaseTime();
return true;
}
bool wifi_softap_add_dhcps_lease(uint8* macaddr)
{
auto& server = getNonOSDhcpServer();
return server.add_dhcps_lease(macaddr);
}
} // extern "C"