83 lines
1.9 KiB
C++
83 lines
1.9 KiB
C++
#ifndef UTILS_HPP
|
|
#define UTILS_HPP
|
|
|
|
#include "Arduino.h"
|
|
#include "WString.h"
|
|
|
|
namespace fw
|
|
{
|
|
typedef enum firewall_targets : uint8_t
|
|
{
|
|
TARGET_REJECT = 0,
|
|
TARGET_DROP = 1,
|
|
TARGET_ACCEPT = 2,
|
|
} firewall_target_t;
|
|
|
|
typedef enum firewall_protocols : uint8_t
|
|
{
|
|
PROTOCOL_TCP = 0,
|
|
PROTOCOL_UDP = 1,
|
|
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 source[IPV4ADDRESS_LENGTH];
|
|
char destination[IPV4ADDRESS_LENGTH];
|
|
uint16_t port_from; // port is max 65565
|
|
uint16_t port_to;
|
|
firewall_protocol_t protocol;
|
|
firewall_target_t target;
|
|
struct firewall_rules *next;
|
|
} firewall_rule_t;
|
|
|
|
const byte numChars = 12;
|
|
const char firewall_fields[][numChars] = {
|
|
"key",
|
|
"source",
|
|
"destination",
|
|
"port_from",
|
|
"port_to",
|
|
"protocol",
|
|
"target",
|
|
};
|
|
|
|
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[40];
|
|
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();
|
|
}
|
|
|
|
#endif
|