9 this->eeprom_amount_of_rules = 0;
10 this->eeprom_rules_head = 1;
11 this->eeprom_size = this->max_rules *
sizeof(firewall_rule_t) + eeprom_rules_head;
12 EEPROM.begin(this->eeprom_size);
21 uint16_t Storage::eeprom_rule_position(uint8_t key)
23 return eeprom_rules_head + (key - 1) *
sizeof(firewall_rule_t);
27 uint8_t Storage::retrieve_amount_of_rules()
30 uint8_t amount_of_rules = EEPROM.read(this->eeprom_amount_of_rules);
32 if (amount_of_rules > this->max_rules)
35 this->memory.begin(
"settings",
true);
36 const uint8_t amount_of_rules = memory.getUChar(
"amount_of_rules", 0);
39 return amount_of_rules;
42 void Storage::store_amount_of_rules(
const uint8_t new_amount)
45 EEPROM.put(this->eeprom_amount_of_rules, new_amount);
48 this->memory.begin(
"settings",
false);
49 this->memory.putUChar(
"amount_of_rules", new_amount);
54 firewall_rule_t *Storage::retrieve_firewall_rule(
const uint8_t key)
56 firewall_rule_t *rule_ptr = (firewall_rule_t *)malloc(
sizeof(firewall_rule_t));
59 uint16_t eeprom_position = eeprom_rule_position(key);
61 EEPROM.get(eeprom_position, rule_ptr->ip);
62 EEPROM.get(eeprom_position +=
sizeof(rule_ptr->ip), rule_ptr->port_from);
63 EEPROM.get(eeprom_position +=
sizeof(rule_ptr->port_from), rule_ptr->port_to);
64 EEPROM.get(eeprom_position +=
sizeof(rule_ptr->port_to), rule_ptr->protocol);
65 EEPROM.get(eeprom_position +=
sizeof(rule_ptr->protocol), rule_ptr->target);
68 sprintf(rulename,
"fwRule%i", key);
70 this->memory.begin(rulename,
true);
71 strncpy(rule_ptr->ip, this->memory.getString(firewall_fields[IP],
"0.0.0.0").c_str(),
sizeof(rule_ptr->ip));
72 rule_ptr->port_from = this->memory.getUShort(firewall_fields[PORT_FROM], 0);
73 rule_ptr->port_to = this->memory.getUShort(firewall_fields[PORT_TO], 0);
74 rule_ptr->protocol =
static_cast<firewall_protocol_t
>(this->memory.getUChar(firewall_fields[PROTOCOL], PROTOCOL_ALL));
75 rule_ptr->target =
static_cast<firewall_target_t
>(this->memory.getUChar(firewall_fields[TARGET], TARGET_ACCEPT));
81 void Storage::store_all_firewall_rules(firewall_rule_t *rule_head)
83 firewall_rule_t *temp = rule_head;
86 store_firewall_rule(temp);
91 void Storage::store_firewall_rule(firewall_rule_t *rule_ptr)
94 uint16_t eeprom_position = eeprom_rule_position(rule_ptr->key);
96 EEPROM.put(eeprom_position, rule_ptr->ip);
97 EEPROM.put(eeprom_position +=
sizeof(rule_ptr->ip), rule_ptr->port_from);
98 EEPROM.put(eeprom_position +=
sizeof(rule_ptr->port_from), rule_ptr->port_to);
99 EEPROM.put(eeprom_position +=
sizeof(rule_ptr->port_to), rule_ptr->protocol);
100 EEPROM.put(eeprom_position +=
sizeof(rule_ptr->protocol), rule_ptr->target);
105 sprintf(rulename,
"fwRule%i", rule_ptr->key);
107 this->memory.begin(rulename,
false);
108 this->memory.putString(firewall_fields[IP], rule_ptr->ip);
109 this->memory.putUShort(firewall_fields[PORT_FROM], rule_ptr->port_from);
110 this->memory.putUShort(firewall_fields[PORT_TO], rule_ptr->port_to);
111 this->memory.putUChar(firewall_fields[PROTOCOL], rule_ptr->protocol);
112 this->memory.putUChar(firewall_fields[TARGET], rule_ptr->target);