From 7b7e77b71449f76c262dc247785c15c6220cf890 Mon Sep 17 00:00:00 2001 From: Zduniusz <31253374+Zduniusz@users.noreply.github.com> Date: Sat, 15 Apr 2023 04:42:28 +0200 Subject: Add support for ESP32 (#17) * Add support for ESP32 * core: Check length of body before allocating Frames with no body may be worth parsing, but should avoid the allocation of zero-length bodies. Instead, we'll check if the body exists in the parsed data and if that length is zero, return early with success. Fixes #16 * misc: Run GitHub build actions on pull requests * Add support for ESP32 --------- Co-authored-by: Zduniusz Co-authored-by: Marc --- CMakeLists.txt | 12 ++++++++++++ README.md | 14 ++++++++++++++ src/libwifi/core/misc/byteswap.h | 2 +- src/libwifi/core/radiotap/platform.h | 4 ++++ src/libwifi/parse/data/eapol.c | 4 ++++ 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e33a5fd..acedf75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,17 @@ cmake_minimum_required(VERSION 3.18) +if (DEFINED ESP_PLATFORM) + file(GLOB_RECURSE libwifi_src + "src/libwifi/*.h" + "src/libwifi/*.c" + ) + idf_component_register( + SRCS ${libwifi_src} + INCLUDE_DIRS "src/" + ) + return() +endif() + project(wifi DESCRIPTION "802.11 Parsing / Generation library" VERSION 0.1) execute_process(COMMAND git rev-parse --abbrev-ref HEAD OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE GITBRANCH) diff --git a/README.md b/README.md index 542c061..0f5f6c4 100644 --- a/README.md +++ b/README.md @@ -59,3 +59,17 @@ $ cmake .. $ make ``` +## ESP32 +This project has been configured to be easily applicable as ESP-IDF component + +### Steps to include (Example) + +1. Put `libwifi` folder in `components/` +2. Open `main/CMakeLists.txt` and add `libwifi` to `COMPONENT_REQUIRES` +3. In `main/main.c` add `#include "libwifi.h"` +4. Test by running following code: ``` +```C +void app_main(void){ + printf("libwifi version: %s", libwifi_get_version()); +} +``` \ No newline at end of file diff --git a/src/libwifi/core/misc/byteswap.h b/src/libwifi/core/misc/byteswap.h index aa91a37..9a7d263 100644 --- a/src/libwifi/core/misc/byteswap.h +++ b/src/libwifi/core/misc/byteswap.h @@ -38,7 +38,7 @@ #define be64toh(x) OSSwapBigToHostInt64(x) #define le64toh(x) OSSwapLittleToHostInt64(x) #else -#include +#include "byteswap.h" #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #define BYTESWAP16(x) x diff --git a/src/libwifi/core/radiotap/platform.h b/src/libwifi/core/radiotap/platform.h index e0ad99f..fd92481 100644 --- a/src/libwifi/core/radiotap/platform.h +++ b/src/libwifi/core/radiotap/platform.h @@ -35,6 +35,10 @@ #include #endif +#if defined(ESP_PLATFORM) +#include "endian.h" +#endif + #ifndef le16_to_cpu #define le16_to_cpu le16toh #endif diff --git a/src/libwifi/parse/data/eapol.c b/src/libwifi/parse/data/eapol.c index b8e3d18..5f4a588 100644 --- a/src/libwifi/parse/data/eapol.c +++ b/src/libwifi/parse/data/eapol.c @@ -25,6 +25,10 @@ #include #include +#if defined(ESP_PLATFORM) +#include "endian.h" +#endif + /** * A libwifi_frame is deemed to be an EAPOL handshake if the following criteria is met: * - The frame is of type TYPE_DATA, and -- cgit 1.4.1