8000 DHCP custom option by mcspr · Pull Request #8582 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content

DHCP custom option #8582

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'origin/master' into dhcps-opts
  • Loading branch information
mcspr committed Jun 2, 2022
commit 38c30cf7dbb6d2c4d9c5584b043272e2dc6dc337
20 changes: 2 additions & 18 deletions cores/esp8266/LwipDhcpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,23 +193,7 @@ DhcpServer::OptionsBuffer& DhcpServer::OptionsBuffer::add(uint8_t code, const ui

////////////////////////////////////////////////////////////////////////////////////

DhcpServer::DhcpServer(netif* netif) : _netif(netif)
{
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*);
Expand Down Expand Up @@ -417,7 +401,7 @@ DhcpServer::OptionsBuffer 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));

return { &m->options[sizeof(magic_cookie)], std::end(m->options) };
}
Expand Down
6 changes: 4 additions & 2 deletions cores/esp8266/LwipDhcpServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
class DhcpServer
{
public:
static constexpr int DefaultLeaseTime = 720; // minutes
static constexpr uint32 MagicCookie = 0x63538263; // https://tools.ietf.org/html/rfc1497
//
struct OptionsBuffer
{
OptionsBuffer(uint8_t* begin, uint8_t* end) : _it(begin), _begin(begin), _end(end) { }
Expand Down Expand Up @@ -217,8 +220,7 @@ class DhcpServer
ip4_addr_t server_address {};
ip4_addr_t client_address {};

static constexpr uint32_t DefaultLeaseTime { 720 }; // minutes
uint32_t lease_time = DefaultLeaseTime;
uint32_t lease_time = DefaultLeaseTime;

bool offer_router = true;
ip4_addr_t dns_address {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ void setup() {
// Notice that:
// - DhcpServer class only supports IPv4
// - Only a single IP can be set
dhcpSoftAP.setDns(WiFi.dnsIP(0));
auto& server = WiFi.softAPDhcpServer();
server.setDns(WiFi.dnsIP(0));

WiFi.softAPConfig( // enable AP, with android-compatible google domain
IPAddress(172, 217, 28, 254), IPAddress(172, 217, 28, 254), IPAddress(255, 255, 255, 0));
Expand Down
7 changes: 3 additions & 4 deletions libraries/ESP8266WiFi/src/ESP8266WiFiAP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ bool ESP8266WiFiAPClass::softAP(const char* ssid, const char* psk, int channel,
if(ip.ip.addr == 0x00000000) {
DEBUG_WIFI("[AP] IP config Invalid resetting...\n");
ret = softAPConfig(
0x0104A8C0 /* 192.168.4.1 */,
0x0104A8C0 /* 192.168.4.1 */,
0x00FFFFFF /* 255.255.255.0 */);
IPAddress(192, 168, 4, 1),
IPAddress(192, 168, 4, 1),
IPAddress(255, 255, 255, 0));
if(!ret) {
DEBUG_WIFI("[AP] softAPConfig failed!\n");
ret = false;
Expand Down Expand Up @@ -254,7 +254,6 @@ bool ESP8266WiFiAPClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPA
ret = false;
}

dhcpSoftAP.setLeaseTime(720); // 720 minutes == 12 h
dhcpSoftAP.setRouter(true); // send ROUTER option with netif's gateway IP

if(!wifi_softap_dhcps_start()) {
Expand Down
28 changes: 0 additions & 28 deletions tests/host/common/user_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,6 @@

#include "MocklwIP.h"

#include <LwipDhcpServer.h>

bool DhcpServer::set_dhcps_lease(struct dhcps_lease* please)
{
(void)please;
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 <user_interface.h>
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.
0