mirror of https://github.com/arendst/Tasmota.git
Fix configuration restore regression from 5.13.1
5.13.1a * Fix configuration restore regression from 5.13.1
This commit is contained in:
parent
0c0f2236bd
commit
b9acfe000c
|
@ -1,5 +1,6 @@
|
||||||
/* 5.13.1a
|
/* 5.13.1a
|
||||||
* Change user_config.h otaurl to http://sonoff.maddox.co.uk/tasmota/sonoff.bin (#2588, #2602)
|
* Change user_config.h otaurl to http://sonoff.maddox.co.uk/tasmota/sonoff.bin (#2588, #2602)
|
||||||
|
* Fix configuration restore regression from 5.13.1
|
||||||
* Fix compile error when ADC is enabled and Rules are disabled (#2608)
|
* Fix compile error when ADC is enabled and Rules are disabled (#2608)
|
||||||
* Fix rule power trigger when no backlog command is used (#2613)
|
* Fix rule power trigger when no backlog command is used (#2613)
|
||||||
* Fix several timer data input and output errors (#2597, #2620)
|
* Fix several timer data input and output errors (#2597, #2620)
|
||||||
|
|
|
@ -330,6 +330,8 @@ uint8_t upload_file_type;
|
||||||
uint8_t upload_progress_dot_count;
|
uint8_t upload_progress_dot_count;
|
||||||
uint8_t config_block_count = 0;
|
uint8_t config_block_count = 0;
|
||||||
uint8_t config_xor_on = 0;
|
uint8_t config_xor_on = 0;
|
||||||
|
uint8_t config_xor_on_set = CONFIG_FILE_XOR;
|
||||||
|
uint8_t *settings_new = NULL;
|
||||||
|
|
||||||
// Helper function to avoid code duplication (saves 4k Flash)
|
// Helper function to avoid code duplication (saves 4k Flash)
|
||||||
static void WebGetArg(const char* arg, char* out, size_t max)
|
static void WebGetArg(const char* arg, char* out, size_t max)
|
||||||
|
@ -977,10 +979,10 @@ void HandleBackupConfiguration()
|
||||||
WebServer->send(200, FPSTR(HDR_CTYPE_STREAM), "");
|
WebServer->send(200, FPSTR(HDR_CTYPE_STREAM), "");
|
||||||
memcpy(buffer, &Settings, sizeof(buffer));
|
memcpy(buffer, &Settings, sizeof(buffer));
|
||||||
buffer[0] = CONFIG_FILE_SIGN;
|
buffer[0] = CONFIG_FILE_SIGN;
|
||||||
buffer[1] = (!CONFIG_FILE_XOR)?0:1;
|
buffer[1] = (!config_xor_on_set) ? 0 : 1;
|
||||||
if (buffer[1]) {
|
if (buffer[1]) {
|
||||||
for (uint16_t i = 2; i < sizeof(buffer); i++) {
|
for (uint16_t i = 2; i < sizeof(buffer); i++) {
|
||||||
buffer[i] ^= (CONFIG_FILE_XOR +i);
|
buffer[i] ^= (config_xor_on_set +i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
myClient.write((const char*)buffer, sizeof(buffer));
|
myClient.write((const char*)buffer, sizeof(buffer));
|
||||||
|
@ -1236,6 +1238,14 @@ void HandleUpgradeFirmwareStart()
|
||||||
ExecuteCommand(svalue);
|
ExecuteCommand(svalue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SettingsNewFree()
|
||||||
|
{
|
||||||
|
if (settings_new != NULL) {
|
||||||
|
free(settings_new);
|
||||||
|
settings_new = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void HandleUploadDone()
|
void HandleUploadDone()
|
||||||
{
|
{
|
||||||
if (HttpUser()) { return; }
|
if (HttpUser()) { return; }
|
||||||
|
@ -1275,6 +1285,7 @@ void HandleUploadDone()
|
||||||
page += FPSTR(HTTP_MSG_RSTRT);
|
page += FPSTR(HTTP_MSG_RSTRT);
|
||||||
restart_flag = 2;
|
restart_flag = 2;
|
||||||
}
|
}
|
||||||
|
SettingsNewFree();
|
||||||
page += F("</div><br/>");
|
page += F("</div><br/>");
|
||||||
page += FPSTR(HTTP_BTN_MAIN);
|
page += FPSTR(HTTP_BTN_MAIN);
|
||||||
ShowPage(page);
|
ShowPage(page);
|
||||||
|
@ -1302,7 +1313,13 @@ void HandleUploadLoop()
|
||||||
SettingsSave(1); // Free flash for upload
|
SettingsSave(1); // Free flash for upload
|
||||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_UPLOAD D_FILE " %s ..."), upload.filename.c_str());
|
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_UPLOAD D_FILE " %s ..."), upload.filename.c_str());
|
||||||
AddLog(LOG_LEVEL_INFO);
|
AddLog(LOG_LEVEL_INFO);
|
||||||
if (!upload_file_type) {
|
if (upload_file_type) {
|
||||||
|
SettingsNewFree();
|
||||||
|
if (!(settings_new = (uint8_t *)malloc(sizeof(Settings)))) {
|
||||||
|
upload_error = 2;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
MqttRetryCounter(60);
|
MqttRetryCounter(60);
|
||||||
#ifdef USE_EMULATION
|
#ifdef USE_EMULATION
|
||||||
UdpDisconnect();
|
UdpDisconnect();
|
||||||
|
@ -1347,18 +1364,7 @@ void HandleUploadLoop()
|
||||||
upload_error = 9;
|
upload_error = 9;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (config_xor_on) {
|
memcpy(settings_new + (config_block_count * HTTP_UPLOAD_BUFLEN), upload.buf, upload.currentSize);
|
||||||
for (uint16_t i = 2; i < upload.currentSize; i++) {
|
|
||||||
upload.buf[i] ^= (CONFIG_FILE_XOR +i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (0 == config_block_count) {
|
|
||||||
SettingsDefaultSet2();
|
|
||||||
memcpy((char*)&Settings +16, upload.buf +16, upload.currentSize -16);
|
|
||||||
memcpy((char*)&Settings +8, upload.buf +8, 4); // Restore version and auto upgrade
|
|
||||||
} else {
|
|
||||||
memcpy((char*)&Settings +(config_block_count * HTTP_UPLOAD_BUFLEN), upload.buf, upload.currentSize);
|
|
||||||
}
|
|
||||||
config_block_count++;
|
config_block_count++;
|
||||||
}
|
}
|
||||||
} else { // firmware
|
} else { // firmware
|
||||||
|
@ -1376,7 +1382,17 @@ void HandleUploadLoop()
|
||||||
if (_serialoutput && (upload_progress_dot_count % 80)) {
|
if (_serialoutput && (upload_progress_dot_count % 80)) {
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
if (!upload_file_type) {
|
if (upload_file_type) {
|
||||||
|
if (config_xor_on) {
|
||||||
|
for (uint16_t i = 2; i < sizeof(Settings); i++) {
|
||||||
|
settings_new[i] ^= (config_xor_on_set +i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SettingsDefaultSet2();
|
||||||
|
memcpy((char*)&Settings +16, settings_new +16, sizeof(Settings) -16);
|
||||||
|
memcpy((char*)&Settings +8, settings_new +8, 4); // Restore version and auto upgrade
|
||||||
|
SettingsNewFree();
|
||||||
|
} else {
|
||||||
if (!Update.end(true)) { // true to set the size to the current progress
|
if (!Update.end(true)) { // true to set the size to the current progress
|
||||||
if (_serialoutput) { Update.printError(Serial); }
|
if (_serialoutput) { Update.printError(Serial); }
|
||||||
upload_error = 6;
|
upload_error = 6;
|
||||||
|
|
Loading…
Reference in New Issue