Transfer data
This commit is contained in:
parent
cac6d98908
commit
c43dd6121a
27 changed files with 3237 additions and 0 deletions
4
esp32example/.gitignore
vendored
Normal file
4
esp32example/.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
.pio
|
||||
.vscode
|
||||
include/theSecrets.h
|
||||
components
|
3
esp32example/CMakeLists.txt
Normal file
3
esp32example/CMakeLists.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
cmake_minimum_required(VERSION 3.16.0)
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(ESP32Firewall)
|
16
esp32example/include/lwip_hooks.h
Normal file
16
esp32example/include/lwip_hooks.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#ifndef _LWIP_HOOKS_H_
|
||||
#define _LWIP_HOOKS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
int lwip_hook_ip4_input(struct pbuf *pbuf, struct netif *input_netif);
|
||||
#define LWIP_HOOK_IP4_INPUT lwip_hook_ip4_input
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _LWIP_HOOKS_H_ */
|
9
esp32example/include/theSecrets-example.h
Normal file
9
esp32example/include/theSecrets-example.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#ifndef _THE_SECRETS_H_
|
||||
#define _THE_SECRETS_H_
|
||||
|
||||
const char *ssid = "Wifi";
|
||||
const char *psk = "password";
|
||||
const char *username = "username";
|
||||
const char *password = "password";
|
||||
|
||||
#endif
|
23
esp32example/platformio.ini
Normal file
23
esp32example/platformio.ini
Normal file
|
@ -0,0 +1,23 @@
|
|||
; PlatformIO Project Configuration File
|
||||
;
|
||||
; Build options: build flags, source filter
|
||||
; Upload options: custom upload port, speed and extra flags
|
||||
; Library options: dependencies, extra library storages
|
||||
; Advanced options: extra scripting
|
||||
;
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[platformio]
|
||||
default_envs = esp32
|
||||
|
||||
[env:esp32]
|
||||
platform = espressif32
|
||||
board = az-delivery-devkit-v4
|
||||
framework = espidf
|
||||
monitor_speed = 115200
|
||||
lib_compat_mode = off
|
||||
build_flags =
|
||||
'-Iinclude'
|
||||
'-DESP_IDF_LWIP_HOOK_FILENAME="lwip_hooks.h"'
|
||||
lib_deps = https://gitlab.hs-esslingen.de/toheer/iot-security-tools.git
|
1439
esp32example/sdkconfig.esp32
Normal file
1439
esp32example/sdkconfig.esp32
Normal file
File diff suppressed because it is too large
Load diff
6
esp32example/src/CMakeLists.txt
Normal file
6
esp32example/src/CMakeLists.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
# This file was automatically generated for projects
|
||||
# without default 'CMakeLists.txt' file.
|
||||
|
||||
FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/src/*.*)
|
||||
|
||||
idf_component_register(SRCS ${app_sources})
|
72
esp32example/src/main.cpp
Normal file
72
esp32example/src/main.cpp
Normal file
|
@ -0,0 +1,72 @@
|
|||
#include "Arduino.h"
|
||||
#include "theSecrets.h"
|
||||
#include "WiFi.h"
|
||||
#include "lwip_hooks.h"
|
||||
|
||||
#include "esp32/Firewall.hpp"
|
||||
#include "esp32/API.hpp"
|
||||
|
||||
fw::Firewall *firewall;
|
||||
fw::API *firewallApi;
|
||||
|
||||
int lwip_hook_ip4_input(struct pbuf *pbuf, struct netif *input_netif)
|
||||
{
|
||||
// Firewall is not setup yet
|
||||
if (firewall != NULL)
|
||||
{
|
||||
if (firewall->is_packet_allowed(pbuf))
|
||||
return 0;
|
||||
else
|
||||
{
|
||||
pbuf_free(pbuf);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void initFirewall(const String ip)
|
||||
{
|
||||
firewall = new fw::Firewall();
|
||||
firewallApi = new fw::API(firewall, username, password, ip);
|
||||
}
|
||||
|
||||
void handle_wifi_events(WiFiEvent_t event, WiFiEventInfo_t info)
|
||||
{
|
||||
switch (event)
|
||||
{
|
||||
case ARDUINO_EVENT_WIFI_STA_START:
|
||||
Serial.println("[WiFi] connecting...");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_CONNECTED:
|
||||
Serial.println("[WiFi] connected");
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
|
||||
Serial.println("[WiFi] disconnected");
|
||||
WiFi.reconnect();
|
||||
break;
|
||||
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
|
||||
initFirewall(WiFi.localIP().toString());
|
||||
break;
|
||||
default:
|
||||
Serial.print("[WiFi] other event: ");
|
||||
Serial.println(event);
|
||||
}
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.onEvent(handle_wifi_events, ARDUINO_EVENT_MAX);
|
||||
WiFi.begin(ssid, psk);
|
||||
|
||||
// fix for https://github.com/espressif/arduino-esp32/issues/4732
|
||||
WiFi.config(((u32_t)0x0UL), ((u32_t)0x0UL), ((u32_t)0x0UL));
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// https://docs.espressif.com/projects/arduino-esp32/en/latest/esp-idf_component.html
|
||||
sleep(1);
|
||||
}
|
Reference in a new issue