|
|
@ -1,4 +1,9 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
|
|
|
|
* V6.2 - 12.12.2018- Nastaveni jmena zarizeni nadale NENI soucasti WiFiConfig a je treba ho pridat jako uzivatelsky parametr. Je to proto, protoze
|
|
|
|
|
|
|
|
* se ukazalo, ze neni dobre z externiho kodu sahat do vnitrni struktury WiFiConfig (napr. pri ukladani noveho jmena).
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* V6.1 - 11.12.2018- Sifrovani retezcu vytazeno mimo WiFiConfig do knihovny encipheredEEPROMStrings (dostupna na gitu) kvuli pristupu i jinych modulu
|
|
|
|
|
|
|
|
*
|
|
|
|
* V6.0 - 20.11.2018- Verze i pro ESP32
|
|
|
|
* V6.0 - 20.11.2018- Verze i pro ESP32
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* V5.9 - 18.7.2018 - Retezce, ukladane do EEPROM jsou primitivnim zpusobem sifrovany pro ztizeni odhaleni SSID a hesla pri dumpu pameti
|
|
|
|
* V5.9 - 18.7.2018 - Retezce, ukladane do EEPROM jsou primitivnim zpusobem sifrovany pro ztizeni odhaleni SSID a hesla pri dumpu pameti
|
|
|
@ -78,6 +83,7 @@
|
|
|
|
#include "WiFiConfig.h"
|
|
|
|
#include "WiFiConfig.h"
|
|
|
|
#include <EEPROM.h>
|
|
|
|
#include <EEPROM.h>
|
|
|
|
#include <Ticker.h>
|
|
|
|
#include <Ticker.h>
|
|
|
|
|
|
|
|
#include <encipheredEEPROMStrings.h>
|
|
|
|
#include "embHTML.h"
|
|
|
|
#include "embHTML.h"
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG_ESP_PORT
|
|
|
|
#ifdef DEBUG_ESP_PORT
|
|
|
@ -98,7 +104,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
#define DNS_PORT 53
|
|
|
|
#define DNS_PORT 53
|
|
|
|
|
|
|
|
|
|
|
|
char WiFiDeviceName[elementSize(wificonfigarea_t, devname)]; // misto pro jmeno zarizeni (dodane do DNS, DHCP NBNS apod...)
|
|
|
|
extern char WiFiDeviceName[];
|
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -117,9 +123,9 @@ static int configBase; // musi byt trvale ulozene, aby fungovaly metody pro zisk
|
|
|
|
|
|
|
|
|
|
|
|
static std::unique_ptr<DNSServer> dnsServer;
|
|
|
|
static std::unique_ptr<DNSServer> dnsServer;
|
|
|
|
#if defined(ESP8266)
|
|
|
|
#if defined(ESP8266)
|
|
|
|
static std::unique_ptr<ESP8266WebServer> server;
|
|
|
|
static std::unique_ptr<ESP8266WebServer> server;
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
static std::unique_ptr<WebServer> server;
|
|
|
|
static std::unique_ptr<WebServer> server;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
static std::unique_ptr<Ticker> rsttick;
|
|
|
|
static std::unique_ptr<Ticker> rsttick;
|
|
|
|
|
|
|
|
|
|
|
@ -142,7 +148,7 @@ IPAddress getOurIP(void)
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
ipa = IPAddress(0,0,0,0); // nelze urcit ip adresu (bud je AP + STA aktivni, nebo je vypnute WiFi)
|
|
|
|
ipa = IPAddress(0, 0, 0, 0); // nelze urcit ip adresu (bud je AP + STA aktivni, nebo je vypnute WiFi)
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ipa;
|
|
|
|
return ipa;
|
|
|
@ -161,7 +167,7 @@ uint32_t getEEPROMuint32(unsigned int start)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint32_t result = 0;
|
|
|
|
uint32_t result = 0;
|
|
|
|
|
|
|
|
|
|
|
|
for (uint32_t i=0; i<4; ++i)
|
|
|
|
for (uint32_t i = 0; i < 4; ++i)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
result <<= 8;
|
|
|
|
result <<= 8;
|
|
|
|
result += EEPROM.read(start);
|
|
|
|
result += EEPROM.read(start);
|
|
|
@ -173,7 +179,7 @@ uint32_t getEEPROMuint32(unsigned int start)
|
|
|
|
void setEEPROMuint32(unsigned int start, uint32_t val)
|
|
|
|
void setEEPROMuint32(unsigned int start, uint32_t val)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
for (unsigned int i=0; i<4; ++i)
|
|
|
|
for (unsigned int i = 0; i < 4; ++i)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
EEPROM.write(start + 3 - i, (uint8_t)val);
|
|
|
|
EEPROM.write(start + 3 - i, (uint8_t)val);
|
|
|
|
val >>= 8;
|
|
|
|
val >>= 8;
|
|
|
@ -382,11 +388,6 @@ void WiFiConfig::_handleInfo(void)
|
|
|
|
reply.concat(buff);
|
|
|
|
reply.concat(buff);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
reply.concat(F("<TR><TD>Timeout:<TD>"));
|
|
|
|
|
|
|
|
reply.concat(_timeout);
|
|
|
|
|
|
|
|
reply.concat(F("/"));
|
|
|
|
|
|
|
|
reply.concat(_time);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(ESP8266)
|
|
|
|
#if defined(ESP8266)
|
|
|
|
uint8_t stations = wifi_softap_get_station_num();
|
|
|
|
uint8_t stations = wifi_softap_get_station_num();
|
|
|
|
|
|
|
|
|
|
|
@ -493,21 +494,16 @@ void WiFiConfig::_handleDisplayAP(void)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s = FPSTR(PAGE_INDEX2);
|
|
|
|
s = FPSTR(PAGE_INDEX2);
|
|
|
|
v = _readString(configBase + offsetof(wificonfigarea_t, ssid), elementSize(wificonfigarea_t, ssid));
|
|
|
|
v = EES_readString(configBase + offsetof(wificonfigarea_t, ssid), elementSize(wificonfigarea_t, ssid));
|
|
|
|
if (v.length())
|
|
|
|
if (v.length())
|
|
|
|
s.replace(F("{s}"), String(FPSTR(VALUE)) + v + F("'"));
|
|
|
|
s.replace(F("{s}"), String(FPSTR(VALUE)) + v + F("'"));
|
|
|
|
else
|
|
|
|
else
|
|
|
|
s.replace(F("{s}"), F("placeholder='SSID'"));
|
|
|
|
s.replace(F("{s}"), F(""));
|
|
|
|
v = _readString(configBase + offsetof(wificonfigarea_t, pass), elementSize(wificonfigarea_t, pass));
|
|
|
|
v = EES_readString(configBase + offsetof(wificonfigarea_t, pass), elementSize(wificonfigarea_t, pass));
|
|
|
|
if (v.length())
|
|
|
|
if (v.length())
|
|
|
|
s.replace(F("{p}"), String(FPSTR(VALUE)) + v + F("'"));
|
|
|
|
s.replace(F("{p}"), String(FPSTR(VALUE)) + v + F("'"));
|
|
|
|
else
|
|
|
|
else
|
|
|
|
s.replace(F("{p}"), F("placeholder='password'"));
|
|
|
|
s.replace(F("{p}"), F(""));
|
|
|
|
v = _readString(configBase + offsetof(wificonfigarea_t, devname), elementSize(wificonfigarea_t, devname));
|
|
|
|
|
|
|
|
if (v.length())
|
|
|
|
|
|
|
|
s.replace(F("{n}"), String(FPSTR(VALUE)) + v + F("'"));
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
s.replace(F("{n}"), F("placeholder='name'"));
|
|
|
|
|
|
|
|
if (EEPROM.read(configBase + offsetof(wificonfigarea_t, mode)) == WIFIMODE_AP)
|
|
|
|
if (EEPROM.read(configBase + offsetof(wificonfigarea_t, mode)) == WIFIMODE_AP)
|
|
|
|
s.replace(F("{a}"), FPSTR(CHECKED));
|
|
|
|
s.replace(F("{a}"), FPSTR(CHECKED));
|
|
|
|
else
|
|
|
|
else
|
|
|
@ -560,13 +556,10 @@ void WiFiConfig::_handleSetAP(void)
|
|
|
|
str = server->arg(F("_s"));
|
|
|
|
str = server->arg(F("_s"));
|
|
|
|
if (str.length() > 0)
|
|
|
|
if (str.length() > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_storeString(configBase + offsetof(wificonfigarea_t, ssid), elementSize(wificonfigarea_t, ssid), str);
|
|
|
|
EES_storeString(configBase + offsetof(wificonfigarea_t, ssid), elementSize(wificonfigarea_t, ssid), str);
|
|
|
|
|
|
|
|
|
|
|
|
str = server->arg(F("_p"));
|
|
|
|
str = server->arg(F("_p"));
|
|
|
|
_storeString(configBase + offsetof(wificonfigarea_t, pass), elementSize(wificonfigarea_t, pass), str);
|
|
|
|
EES_storeString(configBase + offsetof(wificonfigarea_t, pass), elementSize(wificonfigarea_t, pass), str);
|
|
|
|
|
|
|
|
|
|
|
|
str = server->arg(F("_n"));
|
|
|
|
|
|
|
|
_storeString(configBase + offsetof(wificonfigarea_t, devname), elementSize(wificonfigarea_t, devname), str);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
str = server->arg(F("_a"));
|
|
|
|
str = server->arg(F("_a"));
|
|
|
|
if (str.length() > 0)
|
|
|
|
if (str.length() > 0)
|
|
|
@ -622,10 +615,8 @@ void WiFiConfig::_handleSetAP(void)
|
|
|
|
WiFi.disconnect(); // vsechno odpojime
|
|
|
|
WiFi.disconnect(); // vsechno odpojime
|
|
|
|
WiFi.persistent(true); // chceme, aby si modul zapamatoval konfiguraci
|
|
|
|
WiFi.persistent(true); // chceme, aby si modul zapamatoval konfiguraci
|
|
|
|
|
|
|
|
|
|
|
|
String s = _readString(configBase + offsetof(wificonfigarea_t, devname), elementSize(wificonfigarea_t, devname));
|
|
|
|
String s = EES_readString(configBase + offsetof(wificonfigarea_t, ssid), elementSize(wificonfigarea_t, ssid));
|
|
|
|
strcpy(WiFiDeviceName, s.c_str());
|
|
|
|
String pass = EES_readString(configBase + offsetof(wificonfigarea_t, pass), elementSize(wificonfigarea_t, pass));
|
|
|
|
s = _readString(configBase + offsetof(wificonfigarea_t, ssid), elementSize(wificonfigarea_t, ssid));
|
|
|
|
|
|
|
|
String pass = _readString(configBase + offsetof(wificonfigarea_t, pass), elementSize(wificonfigarea_t, pass));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (EEPROM.read(configBase + offsetof(wificonfigarea_t, mode)))
|
|
|
|
switch (EEPROM.read(configBase + offsetof(wificonfigarea_t, mode)))
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -715,12 +706,8 @@ wificonfigresult_t WiFiConfig::_setupAP(wificonfig_cb cb)
|
|
|
|
WiFi.softAPConfig(apIP, apIP, netMsk);
|
|
|
|
WiFi.softAPConfig(apIP, apIP, netMsk);
|
|
|
|
if (ssid.endsWith(F("?")))
|
|
|
|
if (ssid.endsWith(F("?")))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//uint8_t amac[6];
|
|
|
|
|
|
|
|
char lmac[16];
|
|
|
|
char lmac[16];
|
|
|
|
|
|
|
|
|
|
|
|
//WiFi.softAPmacAddress(amac);
|
|
|
|
|
|
|
|
//sprintf_P(lmac, PSTR("%02X%02X%02X"), amac[3], amac[4], amac[5]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sprintf_P(lmac, PSTR("%06X"), ESP_getChipId());
|
|
|
|
sprintf_P(lmac, PSTR("%06X"), ESP_getChipId());
|
|
|
|
ssid.replace(F("?"), String(lmac));
|
|
|
|
ssid.replace(F("?"), String(lmac));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -763,80 +750,6 @@ wificonfigresult_t WiFiConfig::_setupAP(wificonfig_cb cb)
|
|
|
|
return WCR_TIMEOUT; // nepripojeno, vyprsel timeout konfiguracniho AP
|
|
|
|
return WCR_TIMEOUT; // nepripojeno, vyprsel timeout konfiguracniho AP
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String WiFiConfig::_readString(unsigned int start, size_t maxlen)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
uint8_t key[4];
|
|
|
|
|
|
|
|
unsigned int enciphidx = 0;
|
|
|
|
|
|
|
|
String result;
|
|
|
|
|
|
|
|
unsigned int top = EEPROM.read(start);
|
|
|
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result.reserve(maxlen);
|
|
|
|
|
|
|
|
uint32_t cid = ESP_getChipId();
|
|
|
|
|
|
|
|
uint32_t *pkey = (uint32_t *)&key[0];
|
|
|
|
|
|
|
|
*pkey = cid;
|
|
|
|
|
|
|
|
DEBUG_MSG("Key = %02X:%02X:%02X:%02X\r\n", key[0], key[1], key[2], key[3]);
|
|
|
|
|
|
|
|
if ((top > 0) && (top < (maxlen - 2)))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
uint8_t b;
|
|
|
|
|
|
|
|
for (i = start + 1; i < + start + top + 1; ++i)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
b = EEPROM.read(i);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
b ^= key[enciphidx];
|
|
|
|
|
|
|
|
++enciphidx;
|
|
|
|
|
|
|
|
enciphidx %= sizeof(key);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result.concat(char(b));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
b = EEPROM.read(i) ^ key[enciphidx];
|
|
|
|
|
|
|
|
if (b != 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
DEBUG_MSG("_readString error! (%s)\r\n", result.c_str());
|
|
|
|
|
|
|
|
result = F(""); // spatna ukoncovaci nula - neplatny retezec
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool WiFiConfig::_storeString(unsigned int start, size_t maxlen, String &string)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
uint8_t key[4];
|
|
|
|
|
|
|
|
unsigned int enciphidx = 0;
|
|
|
|
|
|
|
|
unsigned int si = 0;
|
|
|
|
|
|
|
|
unsigned int top;
|
|
|
|
|
|
|
|
char c;
|
|
|
|
|
|
|
|
bool result = false; // retezec nebyl ulozeny cely (nevesel s do bufferu)
|
|
|
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (string.length() > maxlen - 2)
|
|
|
|
|
|
|
|
top = maxlen - 2;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
result = true; // retezec se do urceneho mista vejde
|
|
|
|
|
|
|
|
top = string.length();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t cid = ESP_getChipId();
|
|
|
|
|
|
|
|
uint32_t *pkey = (uint32_t *)&key[0];
|
|
|
|
|
|
|
|
*pkey = cid;
|
|
|
|
|
|
|
|
DEBUG_MSG("Key = %02X:%02X:%02X:%02X\r\n", key[0], key[1], key[2], key[3]);
|
|
|
|
|
|
|
|
EEPROM.write(start, (uint8_t)top); // ulozime delku retezce (pouzite pr kontrolu pri vycitani)
|
|
|
|
|
|
|
|
for (i = start + 1; i < start + top + 1; ++i)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
c = string[si];
|
|
|
|
|
|
|
|
c ^= key[enciphidx];
|
|
|
|
|
|
|
|
++enciphidx;
|
|
|
|
|
|
|
|
enciphidx %= sizeof(key);
|
|
|
|
|
|
|
|
EEPROM.write(i, c);
|
|
|
|
|
|
|
|
++si;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
c = 0 ^ key[enciphidx];
|
|
|
|
|
|
|
|
EEPROM.write(i, c); // ukoncovaci a kontrolni nula
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Testovani, zda se modul pripojil k AP
|
|
|
|
// Testovani, zda se modul pripojil k AP
|
|
|
|
bool WiFiConfig::_testWifi(wificonfig_cb cb)
|
|
|
|
bool WiFiConfig::_testWifi(wificonfig_cb cb)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -846,10 +759,8 @@ bool WiFiConfig::_testWifi(wificonfig_cb cb)
|
|
|
|
// nakonfigurujeme ESP dle nove nastavenych parametru
|
|
|
|
// nakonfigurujeme ESP dle nove nastavenych parametru
|
|
|
|
WiFi.disconnect(); // vsechno odpojime
|
|
|
|
WiFi.disconnect(); // vsechno odpojime
|
|
|
|
|
|
|
|
|
|
|
|
String s = _readString(configBase + offsetof(wificonfigarea_t, devname), elementSize(wificonfigarea_t, devname));
|
|
|
|
s = EES_readString(configBase + offsetof(wificonfigarea_t, ssid), elementSize(wificonfigarea_t, ssid));
|
|
|
|
strcpy(WiFiDeviceName, s.c_str());
|
|
|
|
String pass = EES_readString(configBase + offsetof(wificonfigarea_t, pass), elementSize(wificonfigarea_t, pass));
|
|
|
|
s = _readString(configBase + offsetof(wificonfigarea_t, ssid), elementSize(wificonfigarea_t, ssid));
|
|
|
|
|
|
|
|
String pass = _readString(configBase + offsetof(wificonfigarea_t, pass), elementSize(wificonfigarea_t, pass));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (EEPROM.read(configBase + offsetof(wificonfigarea_t, mode)))
|
|
|
|
switch (EEPROM.read(configBase + offsetof(wificonfigarea_t, mode)))
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -947,9 +858,6 @@ wificonfigresult_t WiFiConfig::begin(int configarea, int forceConfigure, wificon
|
|
|
|
else
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
{
|
|
|
|
String s = _readString(configBase + offsetof(wificonfigarea_t, devname), elementSize(wificonfigarea_t, devname));
|
|
|
|
|
|
|
|
strcpy(WiFiDeviceName, s.c_str());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (EEPROM.read(configBase + offsetof(wificonfigarea_t, mode)))
|
|
|
|
switch (EEPROM.read(configBase + offsetof(wificonfigarea_t, mode)))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
case WIFIMODE_STA:
|
|
|
|
case WIFIMODE_STA:
|
|
|
|