Compile for the correct device

This commit is contained in:
Florian Hoss 2022-07-29 10:36:46 +02:00
parent c43dd6121a
commit 9ecda70764
16 changed files with 18 additions and 154 deletions

View file

@ -1,3 +1,4 @@
#ifdef ESP32
#include "API.hpp"
namespace fw
@ -283,3 +284,4 @@ namespace fw
return serialized_string;
}
}
#endif

View file

@ -4,7 +4,7 @@
#include "WebServer.h"
#include "uri/UriBraces.h"
#include "Firewall.hpp"
#include "Utils.hpp"
#include "../Utils.hpp"
namespace fw
{

View file

@ -1,3 +1,4 @@
#ifdef ESP32
#include "Firewall.hpp"
namespace fw
@ -179,3 +180,4 @@ namespace fw
return false;
}
}
#endif

View file

@ -1,7 +1,7 @@
#ifndef ESP32_FIREWALL_HPP
#define ESP32_FIREWALL_HPP
#include "Utils.hpp"
#include "../Utils.hpp"
#include "Storage.hpp"
#include "WiFiClient.h"
#include "lwip/netif.h"

View file

@ -1,3 +1,4 @@
#ifdef ESP32
#include "Storage.hpp"
namespace fw
@ -68,3 +69,4 @@ namespace fw
this->memory.end();
}
}
#endif

View file

@ -2,7 +2,7 @@
#define ESP32_STORAGE_HPP
#include "Preferences.h"
#include "Utils.hpp"
#include "../Utils.hpp"
namespace fw
{

View file

@ -1,3 +1,4 @@
#ifdef ESP8266
#include "API.hpp"
namespace fw
@ -285,3 +286,4 @@ namespace fw
return serialized_string;
}
}
#endif

View file

@ -4,7 +4,7 @@
#include "ESP8266WebServerSecure.h"
#include "uri/UriBraces.h"
#include "Firewall.hpp"
#include "Utils.hpp"
#include "../Utils.hpp"
namespace fw
{

View file

@ -1,3 +1,4 @@
#ifdef ESP8266
#include "Firewall.hpp"
namespace fw
@ -179,3 +180,4 @@ namespace fw
return false;
}
}
#endif

View file

@ -1,7 +1,7 @@
#ifndef ESP8266_FIREWALL_HPP
#define ESP8266_FIREWALL_HPP
#include "Utils.hpp"
#include "../Utils.hpp"
#include "Storage.hpp"
#include "WiFiClient.h"
#include "lwip/netif.h"

View file

@ -1,3 +1,4 @@
#ifdef ESP8266
#include "Storage.hpp"
namespace fw
@ -72,3 +73,4 @@ namespace fw
EEPROM.commit();
}
}
#endif

View file

@ -2,7 +2,7 @@
#define ESP8266_STORAGE_HPP
#include "EEPROM.h"
#include "Utils.hpp"
#include "../Utils.hpp"
namespace fw
{

View file

@ -1,58 +0,0 @@
#include "Utils.hpp"
namespace fw
{
String protocol_to_string(firewall_protocol_t &protocol)
{
switch (protocol)
{
case PROTOCOL_TCP:
return "TCP";
case PROTOCOL_UDP:
return "UDP";
default:
return "ALL";
}
}
firewall_protocol_t string_to_protocol(String &protocol)
{
if (protocol.equals("TCP"))
return PROTOCOL_TCP;
else if (protocol.equals("UDP"))
return PROTOCOL_UDP;
else
return PROTOCOL_ALL;
}
String target_to_string(firewall_target_t &target)
{
switch (target)
{
case TARGET_DROP:
return "DROP";
default:
return "ACCEPT";
}
}
firewall_target_t string_to_target(String &target)
{
if (target.equals("DROP"))
return TARGET_DROP;
else
return TARGET_ACCEPT;
}
void endless_loop()
{
Serial.printf("Something went wrong. Running endless loop until fixed...");
while (true)
delay(500);
}
bool is_in_range(const uint16_t number, const uint16_t lower, const uint16_t upper)
{
return lower <= number && number <= upper;
}
}

View file

@ -1,90 +0,0 @@
#ifndef UTILS_HPP
#define UTILS_HPP
#include "Arduino.h"
#include "WString.h"
namespace fw
{
typedef enum firewall_targets : uint8_t
{
TARGET_DROP = 1,
TARGET_ACCEPT = 2,
} firewall_target_t;
typedef enum firewall_protocols : uint8_t
{
PROTOCOL_TCP = 6,
PROTOCOL_UDP = 17,
PROTOCOL_ALL = 255,
} firewall_protocol_t;
typedef enum ok : uint8_t
{
SUCCESS = 0,
ERROR = 1,
NO_ACTION = 2,
} ok_t;
typedef enum auth : uint8_t
{
AUTHENTICATED = 0,
DENIED = 1,
} auth_t;
static const uint8_t IPV4ADDRESS_LENGTH = 16;
typedef struct firewall_rules
{
uint8_t key;
char ip[IPV4ADDRESS_LENGTH];
uint16_t port_from;
uint16_t port_to;
firewall_protocol_t protocol;
firewall_target_t target;
struct firewall_rules *next;
} firewall_rule_t;
typedef struct my_packet
{
char ip[IPV4ADDRESS_LENGTH];
firewall_protocol_t protocol;
uint16_t port;
} my_packet_t;
static const uint8_t firewall_fields_amount = 6;
const char firewall_fields[firewall_fields_amount][10] = {"key", "ip", "port_from", "port_to", "protocol", "target"};
typedef enum firewall_fields : uint8_t
{
KEY,
IP,
PORT_FROM,
PORT_TO,
PROTOCOL,
TARGET,
} firewall_fields_t;
static const uint8_t CREDENTIALS_LENGTH = 32;
typedef struct credentials
{
char password[CREDENTIALS_LENGTH];
char username[CREDENTIALS_LENGTH];
} credential_t;
typedef struct api_endpoints
{
char uri[60];
char method[7];
char description[30];
struct api_endpoints *next;
} api_endpoint_t;
String protocol_to_string(firewall_protocol_t &protocol);
firewall_protocol_t string_to_protocol(String &protocol);
String target_to_string(firewall_target_t &target);
firewall_target_t string_to_target(String &target);
String response_code_to_string(const uint16_t response_code);
void endless_loop();
bool is_in_range(const uint16_t number, const uint16_t lower, const uint16_t upper);
}
#endif