increase storage

This commit is contained in:
Florian Hoss 2022-05-02 20:49:05 +02:00
parent 84991434ec
commit 09a04b60a9
2 changed files with 20 additions and 25 deletions

View file

@ -4,10 +4,7 @@ namespace fw
{
Storage::Storage()
{
#ifdef ESP32
if (this->mount_spiffs() == ERROR)
endless_loop();
#elif defined(ESP8266)
#ifdef ESP8266
this->setup_eeprom();
#endif
}
@ -16,23 +13,6 @@ namespace fw
{
}
ok_t Storage::mount_spiffs()
{
#ifdef ESP32
if (!SPIFFS.begin(false))
{
if (!SPIFFS.begin(true))
{
Serial.println("SPIFFS cannot be mounted");
return ERROR;
};
}
return SUCCESS;
#elif defined(ESP8266)
return NO_ACTION;
#endif
}
void Storage::setup_eeprom()
{
#ifdef ESP8266
@ -47,6 +27,8 @@ namespace fw
uint8_t total_space_needed = 0;
total_space_needed += sizeof(rule.source);
total_space_needed += sizeof(rule.destination);
total_space_needed += sizeof(rule.port_from);
total_space_needed += sizeof(rule.port_to);
total_space_needed += sizeof(rule.target);
total_space_needed += sizeof(rule.protocol);
// key-1 because key will be in range 1-255, but we need 1 less for multiplication
@ -107,6 +89,8 @@ namespace fw
this->memory.begin(rulename, true);
strncpy(rule_ptr->source, this->memory.getString("source", "0.0.0.0").c_str(), sizeof(rule_ptr->source));
strncpy(rule_ptr->destination, this->memory.getString("destination", "0.0.0.0").c_str(), sizeof(rule_ptr->source));
rule_ptr->port_from = this->memory.getUChar("port_from", 0);
rule_ptr->port_to = this->memory.getUChar("port_to", 0);
rule_ptr->protocol = static_cast<firewall_protocol_t>(this->memory.getUChar("protocol", PROTOCOL_ALL));
rule_ptr->target = static_cast<firewall_target_t>(this->memory.getUChar("target", TARGET_REJECT));
this->memory.end();
@ -124,6 +108,12 @@ namespace fw
strncpy(rule_ptr->destination, destination, sizeof(rule_ptr->destination));
eespom_position += sizeof(rule_ptr->destination);
rule_ptr->port_from = EEPROM.read(eespom_position);
eespom_position += sizeof(rule_ptr->port_from);
rule_ptr->port_to = EEPROM.read(eespom_position);
eespom_position += sizeof(rule_ptr->port_to);
rule_ptr->protocol = static_cast<firewall_protocol_t>(EEPROM.read(eespom_position));
eespom_position += sizeof(rule_ptr->protocol);
@ -153,6 +143,8 @@ namespace fw
this->memory.begin(rulename, false);
this->memory.putString("source", rule_ptr->source);
this->memory.putString("destination", rule_ptr->destination);
this->memory.putUChar("port_from", rule_ptr->port_from);
this->memory.putUChar("port_to", rule_ptr->port_to);
this->memory.putUChar("protocol", rule_ptr->protocol);
this->memory.putUChar("target", rule_ptr->target);
@ -164,6 +156,10 @@ namespace fw
eespom_position += sizeof(rule_ptr->source);
EEPROM.put(eespom_position, rule_ptr->destination);
eespom_position += sizeof(rule_ptr->destination);
EEPROM.put(eespom_position, rule_ptr->port_from);
eespom_position += sizeof(rule_ptr->port_from);
EEPROM.put(eespom_position, rule_ptr->port_to);
eespom_position += sizeof(rule_ptr->port_to);
EEPROM.put(eespom_position, rule_ptr->protocol);
eespom_position += sizeof(rule_ptr->protocol);
EEPROM.put(eespom_position, rule_ptr->target);

View file

@ -18,16 +18,15 @@ namespace fw
#ifdef ESP32
Preferences memory;
#elif defined(ESP8266)
// Storage per firewall rule is 34 Byte
// Space for 15 Rules is 510 Byte
// Storage per firewall rule is 42 Byte
// Space for 15 Rules is 630 Byte
// plus 10 byte for settings
const uint16_t eeprom_size = 520;
const uint16_t eeprom_size = 640;
const uint8_t security_number = 93;
const uint16_t eeprom_settings_head = 0;
const uint16_t eeprom_amout_of_rules_head = eeprom_settings_head + 1;
const uint16_t eeprom_rules_head = 10;
#endif
ok_t mount_spiffs();
void setup_eeprom();
uint16_t eeprom_rule_position(uint8_t);