Skip to content

LEAmDNS #5370

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

Closed
wants to merge 6 commits into from
Closed

LEAmDNS #5370

Show file tree
Hide file tree
Changes from all commits
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
42 changes: 39 additions & 3 deletions cores/esp8266/Esp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "flash_utils.h"
#include "eboot_command.h"
#include <memory>
#include <interrupts.h>
#include "interrupts.h"
#include "MD5Builder.h"
#include "umm_malloc/umm_malloc.h"
#include "cont.h"
Expand Down Expand Up @@ -132,9 +132,43 @@ uint64_t EspClass::deepSleepMax()

}

/*
Layout of RTC Memory is as follows:
Ref: Espressif doc 2C-ESP8266_Non_OS_SDK_API_Reference, section 3.3.23 (system_rtc_mem_write)

|<------system data (256 bytes)------->|<-----------------user data (512 bytes)--------------->|

SDK function signature:
bool system_rtc_mem_read (
uint32 des_addr,
void * src_addr,
uint32 save_size
)

The system data section can't be used by the user, so:
des_addr must be >=64 (i.e.: 256/4) and <192 (i.e.: 768/4)
src_addr is a pointer to data
save_size is the number of bytes to write

For the method interface:
offset is the user block number (block size is 4 bytes) must be >= 0 and <128
data is a pointer to data, 4-byte aligned
size is number of bytes in the block pointed to by data

Same for write

Note: If the Updater class is in play, e.g.: the application uses OTA, the eboot
command will be stored into the first 128 bytes of user data, then it will be
retrieved by eboot on boot. That means that user data present there will be lost.
Ref:
- discussion in PR #5330.
- https://github.com/esp8266/esp8266-wiki/wiki/Memory-Map#memmory-mapped-io-registers
- Arduino/bootloaders/eboot/eboot_command.h RTC_MEM definition
*/

bool EspClass::rtcUserMemoryRead(uint32_t offset, uint32_t *data, size_t size)
{
if (size + offset > 512) {
if (offset * 4 + size > 512 || size == 0) {
return false;
} else {
return system_rtc_mem_read(64 + offset, data, size);
Expand All @@ -143,13 +177,15 @@ bool EspClass::rtcUserMemoryRead(uint32_t offset, uint32_t *data, size_t size)

bool EspClass::rtcUserMemoryWrite(uint32_t offset, uint32_t *data, size_t size)
{
if (size + offset > 512) {
if (offset * 4 + size > 512 || size == 0) {
return false;
} else {
return system_rtc_mem_write(64 + offset, data, size);
}
}



extern "C" void __real_system_restart_local();
void EspClass::reset(void)
{
Expand Down
4 changes: 2 additions & 2 deletions cores/esp8266/MD5Builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ class MD5Builder {
void add(const uint8_t * data, const uint16_t len);
void add(const char * data){ add((const uint8_t*)data, strlen(data)); }
void add(char * data){ add((const char*)data); }
void add(const String data){ add(data.c_str()); }
void add(const String& data){ add(data.c_str()); }
void addHexString(const char * data);
void addHexString(char * data){ addHexString((const char*)data); }
void addHexString(const String data){ addHexString(data.c_str()); }
void addHexString(const String& data){ addHexString(data.c_str()); }
bool addStream(Stream & stream, const size_t maxLen);
void calculate(void);
void getBytes(uint8_t * output);
Expand Down
126 changes: 126 additions & 0 deletions cores/esp8266/PolledTimeout.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#ifndef __POLLEDTIMING_H__
#define __POLLEDTIMING_H__


/*
PolledTimeout.h - Encapsulation of a polled Timeout

Copyright (c) 2018 Daniel Salazar. 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
*/



namespace esp8266
{


namespace polledTimeout
{

namespace YieldPolicy
{

struct DoNothing
{
static void execute() {}
};

struct YieldOrSkip
{
static void execute() {delay(0);}
};

} //YieldPolicy


template <bool PeriodicT, typename YieldPolicyT = YieldPolicy::DoNothing>
class timeoutTemplate
{
public:
using timeType = decltype(millis());

timeoutTemplate(timeType timeout)
: _timeout(timeout), _start(millis())
{}

bool expired()
{
YieldPolicyT::execute(); //in case of DoNothing: gets optimized away
if(PeriodicT) //in case of false: gets optimized away
return expiredRetrigger();
return expiredOneShot();
}

operator bool()
{
return expired();
}

void reset(timeType newTimeout)
{
_timeout = newTimeout;
reset();
}

void reset()
{
_start = millis();
}

protected:
bool checkExpired(timeType t) const
{
return (t - _start) >= _timeout;
}

bool expiredRetrigger()
{
timeType current = millis();
if(checkExpired(current))
{
unsigned long n = (current - _start) / _timeout; //how many _timeouts periods have elapsed, will usually be 1 (current - _start >= _timeout)
_start += n * _timeout;
return true;
}
return false;
}

bool expiredOneShot() const
{
return checkExpired(millis());
}

timeType _timeout;
timeType _start;
};

using oneShot = polledTimeout::timeoutTemplate<false>;
using periodic = polledTimeout::timeoutTemplate<true>;

} //polledTimeout


/* A 1-shot timeout that auto-yields when in CONT can be built as follows:
* using oneShotYield = esp8266::polledTimeout::timeoutTemplate<false, esp8266::polledTimeout::YieldPolicy::YieldOrSkip>;
*
* Other policies can be implemented by the user, e.g.: simple yield that panics in SYS, and the polledTimeout types built as needed as shown above, without modifying this file.
*/

}//esp8266

#endif
2 changes: 1 addition & 1 deletion libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ bool ESP8266WiFiSTAClass::hostname(const char* aHostname) {
* @param aHostname max length:32
* @return ok
*/
bool ESP8266WiFiSTAClass::hostname(String aHostname) {
bool ESP8266WiFiSTAClass::hostname(const String& aHostname) {
return hostname((char*) aHostname.c_str());
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/ESP8266WiFi/src/ESP8266WiFiSTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ESP8266WiFiSTAClass {
String hostname();
bool hostname(char* aHostname);
bool hostname(const char* aHostname);
bool hostname(String aHostname);
bool hostname(const String& aHostname);

// STA WiFi info
wl_status_t status();
Expand Down
2 changes: 1 addition & 1 deletion libraries/ESP8266WiFi/src/WiFiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ int WiFiClient::connect(const char* host, uint16_t port)
return 0;
}

int WiFiClient::connect(const String host, uint16_t port)
int WiFiClient::connect(const String& host, uint16_t port)
{
return connect(host.c_str(), port);
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/ESP8266WiFi/src/WiFiClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class WiFiClient : public Client, public SList<WiFiClient> {
uint8_t status();
virtual int connect(IPAddress ip, uint16_t port);
virtual int connect(const char *host, uint16_t port);
virtual int connect(const String host, uint16_t port);
virtual int connect(const String& host, uint16_t port);
virtual size_t write(uint8_t);
virtual size_t write(const uint8_t *buf, size_t size);
virtual size_t write_P(PGM_P buf, size_t size);
Expand Down
2 changes: 1 addition & 1 deletion libraries/ESP8266WiFi/src/WiFiClientSecureAxTLS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ int WiFiClientSecure::connect(const char* name, uint16_t port)
return _connectSSL(name);
}

int WiFiClientSecure::connect(const String host, uint16_t port)
int WiFiClientSecure::connect(const String& host, uint16_t port)
{
return connect(host.c_str(), port);
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/ESP8266WiFi/src/WiFiClientSecureAxTLS.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class WiFiClientSecure : public WiFiClient {
~WiFiClientSecure() override;

int connect(IPAddress ip, uint16_t port) override;
int connect(const String host, uint16_t port) override;
int connect(const String& host, uint16_t port) override;
int connect(const char* name, uint16_t port) override;

bool verify(const char* fingerprint, const char* domain_name);
Expand Down
4 changes: 2 additions & 2 deletions libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ int WiFiClientSecure::connect(const char* name, uint16_t port) {
return _connectSSL(name);
}

int WiFiClientSecure::connect(const String host, uint16_t port) {
int WiFiClientSecure::connect(const String& host, uint16_t port) {
return connect(host.c_str(), port);
}

Expand Down Expand Up @@ -1108,7 +1108,7 @@ bool WiFiClientSecure::probeMaxFragmentLength(const char* name, uint16_t port, u
return WiFiClientSecure::probeMaxFragmentLength(remote_addr, port, len);
}

bool WiFiClientSecure::probeMaxFragmentLength(const String host, uint16_t port, uint16_t len) {
bool WiFiClientSecure::probeMaxFragmentLength(const String& host, uint16_t port, uint16_t len) {
return WiFiClientSecure::probeMaxFragmentLength(host.c_str(), port, len);
}

Expand Down
4 changes: 2 additions & 2 deletions libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class WiFiClientSecure : public WiFiClient {
~WiFiClientSecure() override;

int connect(IPAddress ip, uint16_t port) override;
int connect(const String host, uint16_t port) override;
int connect(const String& host, uint16_t port) override;
int connect(const char* name, uint16_t port) override;

uint8_t connected() override;
Expand Down Expand Up @@ -119,7 +119,7 @@ class WiFiClientSecure : public WiFiClient {
// Check for Maximum Fragment Length support for given len
static bool probeMaxFragmentLength(IPAddress ip, uint16_t port, uint16_t len);
static bool probeMaxFragmentLength(const char *hostname, uint16_t port, uint16_t len);
static bool probeMaxFragmentLength(const String host, uint16_t port, uint16_t len);
static bool probeMaxFragmentLength(const String& host, uint16_t port, uint16_t len);

// AXTLS compatible wrappers
// Cannot implement this mode, we need FP before we can connect: bool verify(const char* fingerprint, const char* domain_name)
Expand Down
Loading