diff options
-rw-r--r-- | .github/workflows/linux_x86.yml (renamed from .github/workflows/x86_64.yml) | 8 | ||||
-rw-r--r-- | .github/workflows/macos_x86.yml | 64 | ||||
-rw-r--r-- | .gitignore | 8 | ||||
-rw-r--r-- | CMakeLists.txt | 14 | ||||
-rw-r--r-- | README.md | 11 | ||||
-rw-r--r-- | src/libwifi/core/core.c | 10 | ||||
-rw-r--r-- | src/libwifi/core/misc/byteswap.h | 25 | ||||
-rw-r--r-- | src/libwifi/parse/misc/radiotap.c | 8 | ||||
-rw-r--r-- | test/CMakeLists.txt | 3 | ||||
-rw-r--r-- | utils/CMakeLists.txt | 3 | ||||
-rw-r--r-- | utils/src/test_parsing.c | 2 |
11 files changed, 135 insertions, 21 deletions
diff --git a/.github/workflows/x86_64.yml b/.github/workflows/linux_x86.yml index cc90e1d..f9d536c 100644 --- a/.github/workflows/x86_64.yml +++ b/.github/workflows/linux_x86.yml | |||
@@ -1,4 +1,4 @@ | |||
1 | name: libwifi (64-Bit) | 1 | name: libwifi (Linux) (64-Bit) |
2 | 2 | ||
3 | on: [push] | 3 | on: [push] |
4 | 4 | ||
@@ -21,7 +21,7 @@ jobs: | |||
21 | working-directory: ${{github.workspace}}/build | 21 | working-directory: ${{github.workspace}}/build |
22 | run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE | 22 | run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE |
23 | 23 | ||
24 | - name: Build X86_64 | 24 | - name: Build Linux X86_64 |
25 | shell: bash | 25 | shell: bash |
26 | working-directory: ${{github.workspace}}/build | 26 | working-directory: ${{github.workspace}}/build |
27 | run: cmake --build . --config $BUILD_TYPE | 27 | run: cmake --build . --config $BUILD_TYPE |
@@ -40,7 +40,7 @@ jobs: | |||
40 | working-directory: ${{github.workspace}}/build | 40 | working-directory: ${{github.workspace}}/build |
41 | run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE | 41 | run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE |
42 | 42 | ||
43 | - name: Build X86_64 | 43 | - name: Build Linux X86_64 |
44 | shell: bash | 44 | shell: bash |
45 | working-directory: ${{github.workspace}}/build | 45 | working-directory: ${{github.workspace}}/build |
46 | run: cmake --build . --config $BUILD_TYPE | 46 | run: cmake --build . --config $BUILD_TYPE |
@@ -58,7 +58,7 @@ jobs: | |||
58 | working-directory: ${{github.workspace}}/test/build | 58 | working-directory: ${{github.workspace}}/test/build |
59 | run: cmake --build . | 59 | run: cmake --build . |
60 | 60 | ||
61 | - name: Test X86_64 | 61 | - name: Test Linux X86_64 |
62 | shell: bash | 62 | shell: bash |
63 | working-directory: ${{github.workspace}}/test/build | 63 | working-directory: ${{github.workspace}}/test/build |
64 | run: ctest --output-on-failure | 64 | run: ctest --output-on-failure |
diff --git a/.github/workflows/macos_x86.yml b/.github/workflows/macos_x86.yml new file mode 100644 index 0000000..abdb664 --- /dev/null +++ b/.github/workflows/macos_x86.yml | |||
@@ -0,0 +1,64 @@ | |||
1 | name: libwifi (MacOS) (64-Bit) | ||
2 | |||
3 | on: [push] | ||
4 | |||
5 | env: | ||
6 | # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) | ||
7 | BUILD_TYPE: Release | ||
8 | |||
9 | jobs: | ||
10 | build: | ||
11 | runs-on: macos-latest | ||
12 | |||
13 | steps: | ||
14 | - uses: actions/checkout@v2 | ||
15 | |||
16 | - name: Create Build Environment | ||
17 | run: cmake -E make_directory ${{github.workspace}}/build | ||
18 | |||
19 | - name: Configure CMake | ||
20 | shell: bash | ||
21 | working-directory: ${{github.workspace}}/build | ||
22 | run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE | ||
23 | |||
24 | - name: Build MacOS X86_64 | ||
25 | shell: bash | ||
26 | working-directory: ${{github.workspace}}/build | ||
27 | run: cmake --build . --config $BUILD_TYPE | ||
28 | |||
29 | test: | ||
30 | runs-on: macos-latest | ||
31 | |||
32 | steps: | ||
33 | - uses: actions/checkout@v2 | ||
34 | |||
35 | - name: Create Build Environment | ||
36 | run: cmake -E make_directory ${{github.workspace}}/build | ||
37 | |||
38 | - name: Configure CMake | ||
39 | shell: bash | ||
40 | working-directory: ${{github.workspace}}/build | ||
41 | run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE | ||
42 | |||
43 | - name: Build MacOS X86_64 | ||
44 | shell: bash | ||
45 | working-directory: ${{github.workspace}}/build | ||
46 | run: cmake --build . --config $BUILD_TYPE | ||
47 | |||
48 | - name: Create Test Environment | ||
49 | run: cmake -E make_directory ${{github.workspace}}/test/build | ||
50 | |||
51 | - name: Configure CMake | ||
52 | shell: bash | ||
53 | working-directory: ${{github.workspace}}/test/build | ||
54 | run: cmake ${{github.workspace}}/test | ||
55 | |||
56 | - name: Build Tests | ||
57 | shell: bash | ||
58 | working-directory: ${{github.workspace}}/test/build | ||
59 | run: cmake --build . | ||
60 | |||
61 | - name: Test MacOS X86_64 | ||
62 | shell: bash | ||
63 | working-directory: ${{github.workspace}}/test/build | ||
64 | run: ctest --output-on-failure | ||
diff --git a/.gitignore b/.gitignore index dbbe0da..7ee9e2d 100644 --- a/.gitignore +++ b/.gitignore | |||
@@ -2,6 +2,7 @@ | |||
2 | *.a | 2 | *.a |
3 | *.o | 3 | *.o |
4 | *.so* | 4 | *.so* |
5 | *.dylib | ||
5 | 6 | ||
6 | # Build | 7 | # Build |
7 | CMakeLists.txt.user | 8 | CMakeLists.txt.user |
@@ -20,4 +21,9 @@ CMakeUserPresets.json | |||
20 | 21 | ||
21 | # Output | 22 | # Output |
22 | build/ | 23 | build/ |
23 | tests/build/ | 24 | test/build/ |
25 | test/*_tests | ||
26 | utils/test_* | ||
27 | |||
28 | # Temporary Patches | ||
29 | *.patch | ||
diff --git a/CMakeLists.txt b/CMakeLists.txt index a0d9809..1b5304c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
@@ -5,7 +5,7 @@ project(wifi DESCRIPTION "802.11 Parsing / Generation library" VERSION 0.1) | |||
5 | execute_process(COMMAND git rev-parse --abbrev-ref HEAD OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE GITBRANCH) | 5 | execute_process(COMMAND git rev-parse --abbrev-ref HEAD OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE GITBRANCH) |
6 | execute_process(COMMAND git log -1 --pretty=format:%h OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE GITHASH) | 6 | execute_process(COMMAND git log -1 --pretty=format:%h OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE GITHASH) |
7 | execute_process(COMMAND date OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE BUILDTIME) | 7 | execute_process(COMMAND date OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE BUILDTIME) |
8 | set(LIBWIFI_VERSION "0.0.6") | 8 | set(LIBWIFI_VERSION "0.0.7") |
9 | 9 | ||
10 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu17") | 10 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu17") |
11 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra") | 11 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra") |
@@ -13,6 +13,8 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic -Wno-language-extension-token") | |||
13 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-prototypes -Wstrict-prototypes") | 13 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-prototypes -Wstrict-prototypes") |
14 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-strong") | 14 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-strong") |
15 | 15 | ||
16 | set(CMAKE_MACOSX_RPATH 1) | ||
17 | |||
16 | message(" ") | 18 | message(" ") |
17 | message(" _ _ _ _ __ _ ") | 19 | message(" _ _ _ _ __ _ ") |
18 | message("| |(_)| | (_) / _|(_) ") | 20 | message("| |(_)| | (_) / _|(_) ") |
@@ -48,9 +50,9 @@ set_target_properties(wifi PROPERTIES VERSION ${LIBWIFI_VERSION}) | |||
48 | set_target_properties(wifi PROPERTIES SOVERSION 0) | 50 | set_target_properties(wifi PROPERTIES SOVERSION 0) |
49 | set_target_properties(wifi PROPERTIES PUBLIC_HEADER src/libwifi.h) | 51 | set_target_properties(wifi PROPERTIES PUBLIC_HEADER src/libwifi.h) |
50 | 52 | ||
51 | install(DIRECTORY src/libwifi/core/ DESTINATION /usr/include/libwifi/core FILES_MATCHING PATTERN "*.h") | 53 | install(DIRECTORY src/libwifi/core/ DESTINATION /usr/local/include/libwifi/core FILES_MATCHING PATTERN "*.h") |
52 | install(DIRECTORY src/libwifi/parse/ DESTINATION /usr/include/libwifi/parse FILES_MATCHING PATTERN "*.h") | 54 | install(DIRECTORY src/libwifi/parse/ DESTINATION /usr/local/include/libwifi/parse FILES_MATCHING PATTERN "*.h") |
53 | install(DIRECTORY src/libwifi/gen/ DESTINATION /usr/include/libwifi/gen FILES_MATCHING PATTERN "*.h") | 55 | install(DIRECTORY src/libwifi/gen/ DESTINATION /usr/local/include/libwifi/gen FILES_MATCHING PATTERN "*.h") |
54 | install(TARGETS wifi LIBRARY DESTINATION /usr/lib PUBLIC_HEADER DESTINATION /usr/include) | 56 | install(TARGETS wifi LIBRARY DESTINATION /usr/local/lib PUBLIC_HEADER DESTINATION /usr/local/include) |
55 | 57 | ||
56 | add_custom_target(uninstall COMMAND rm -rf /usr/include/libwifi; rm -rf /usr/include/libwifi.h) | 58 | add_custom_target(uninstall COMMAND rm -rf /usr/local/include/libwifi; rm -rf /usr/local/include/libwifi.h; rm -rf /usr/local/lib/libwifi*) |
diff --git a/README.md b/README.md index bd036d8..542c061 100644 --- a/README.md +++ b/README.md | |||
@@ -1,14 +1,15 @@ | |||
1 | # libwifi | 1 | # libwifi |
2 | 802.11 Parsing / Generation library | 2 | 802.11 Parsing / Generation library |
3 | 3 | ||
4 | | Build Status | OS | Architecture | | 4 | | Build Status | OS | |
5 | | ---------------------------------------------------------------------------------- | ------| ------------ | | 5 | |---------------------------------------------------------------------------------------|-------| |
6 | | | Linux | x86_64 | | 6 | | | Linux | |
7 | | | macOS | | ||
7 | 8 | ||
8 | ## What is this? | 9 | ## What is this? |
9 | libwifi is a C library with a permissive license for generating and parsing a wide variety of 802.11 wireless frames (see the [Feature Checklist](https://libwifi.so/features)) on Linux with a few lines of straight forward code (see the [Examples section](#examples) below). | 10 | libwifi is a C library with a permissive license for generating and parsing a wide variety of 802.11 wireless frames (see the [Feature Checklist](https://libwifi.so/features)) on Linux and macOS with a few lines of straight forward code (see the [Examples section](#examples) below). |
10 | 11 | ||
11 | It is written with a simple-to-use approach while also exposing features that allow more advanced use, with clean and readable code being a priority. Other goals of the library include cross-architecture support, clean compilation without warnings and strict error checking. | 12 | libwifi has been tested across Linux and macOS, on x86, MIPS and ARM, and is written with a simple-to-use approach while also exposing features that allow more advanced use, with clean and readable code being a priority. Other goals of the library include cross-architecture support, clean compilation without warnings and strict error checking. |
12 | 13 | ||
13 | The library is fully documented with code comments in both the headers files and the code files. | 14 | The library is fully documented with code comments in both the headers files and the code files. |
14 | 15 | ||
diff --git a/src/libwifi/core/core.c b/src/libwifi/core/core.c index 0340a82..863e58f 100644 --- a/src/libwifi/core/core.c +++ b/src/libwifi/core/core.c | |||
@@ -25,9 +25,17 @@ void libwifi_random_mac(unsigned char buf[6], unsigned char prefix[3]) { | |||
25 | memset(buf, 0, 6); | 25 | memset(buf, 0, 6); |
26 | if (prefix != NULL) { | 26 | if (prefix != NULL) { |
27 | memcpy(buf, prefix, 3); | 27 | memcpy(buf, prefix, 3); |
28 | getrandom(buf + 3, 3, 0); | 28 | #if __APPLE__ |
29 | arc4random_buf(buf + 3, 3); | ||
30 | #else | ||
31 | getrandom(buf + 3, 3, 0); | ||
32 | #endif /* __APPLE__ */ | ||
29 | } else { | 33 | } else { |
34 | #if __APPLE__ | ||
35 | arc4random_buf(buf, 6); | ||
36 | #else | ||
30 | getrandom(buf, 6, 0); | 37 | getrandom(buf, 6, 0); |
38 | #endif /* __APPLE__ */ | ||
31 | } | 39 | } |
32 | } | 40 | } |
33 | 41 | ||
diff --git a/src/libwifi/core/misc/byteswap.h b/src/libwifi/core/misc/byteswap.h index cab264f..aa91a37 100644 --- a/src/libwifi/core/misc/byteswap.h +++ b/src/libwifi/core/misc/byteswap.h | |||
@@ -16,6 +16,28 @@ | |||
16 | #ifndef LIBWIFI_CORE_BYTESWAP_H | 16 | #ifndef LIBWIFI_CORE_BYTESWAP_H |
17 | #define LIBWIFI_CORE_BYTESWAP_H | 17 | #define LIBWIFI_CORE_BYTESWAP_H |
18 | 18 | ||
19 | #if __APPLE__ | ||
20 | #include <libkern/OSByteOrder.h> | ||
21 | |||
22 | #define BYTESWAP16(x) OSSwapInt16(x) | ||
23 | #define BYTESWAP32(x) OSSwapInt32(x) | ||
24 | #define BYTESWAP64(x) OSSwapInt64(x) | ||
25 | |||
26 | #define htobe16(x) OSSwapHostToBigInt16(x) | ||
27 | #define htole16(x) OSSwapHostToLittleInt16(x) | ||
28 | #define be16toh(x) OSSwapBigToHostInt16(x) | ||
29 | #define le16toh(x) OSSwapLittleToHostInt16(x) | ||
30 | |||
31 | #define htobe32(x) OSSwapHostToBigInt32(x) | ||
32 | #define htole32(x) OSSwapHostToLittleInt32(x) | ||
33 | #define be32toh(x) OSSwapBigToHostInt32(x) | ||
34 | #define le32toh(x) OSSwapLittleToHostInt32(x) | ||
35 | |||
36 | #define htobe64(x) OSSwapHostToBigInt64(x) | ||
37 | #define htole64(x) OSSwapHostToLittleInt64(x) | ||
38 | #define be64toh(x) OSSwapBigToHostInt64(x) | ||
39 | #define le64toh(x) OSSwapLittleToHostInt64(x) | ||
40 | #else | ||
19 | #include <byteswap.h> | 41 | #include <byteswap.h> |
20 | 42 | ||
21 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ | 43 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ |
@@ -26,6 +48,7 @@ | |||
26 | #define BYTESWAP16(x) (__bswap_16(x)) | 48 | #define BYTESWAP16(x) (__bswap_16(x)) |
27 | #define BYTESWAP32(x) (__bswap_32(x)) | 49 | #define BYTESWAP32(x) (__bswap_32(x)) |
28 | #define BYTESWAP64(x) (__bswap_32(x)) | 50 | #define BYTESWAP64(x) (__bswap_32(x)) |
29 | #endif | 51 | #endif /* __BYTE_ORDER__ */ |
52 | #endif /* __APPLE__ */ | ||
30 | 53 | ||
31 | #endif /* LIBWIFI_CORE_BYTESWAP_H */ | 54 | #endif /* LIBWIFI_CORE_BYTESWAP_H */ |
diff --git a/src/libwifi/parse/misc/radiotap.c b/src/libwifi/parse/misc/radiotap.c index 80ddced..faf6009 100644 --- a/src/libwifi/parse/misc/radiotap.c +++ b/src/libwifi/parse/misc/radiotap.c | |||
@@ -17,14 +17,18 @@ | |||
17 | #include "../../core/radiotap/radiotap_iter.h" | 17 | #include "../../core/radiotap/radiotap_iter.h" |
18 | 18 | ||
19 | #include <errno.h> | 19 | #include <errno.h> |
20 | #include <endian.h> | ||
21 | #include <stdint.h> | 20 | #include <stdint.h> |
22 | 21 | ||
22 | #if !(__APPLE__) | ||
23 | #include <endian.h> | ||
24 | #endif | ||
25 | |||
23 | /** | 26 | /** |
24 | * The libwifi radiotap parser uses the usual ieee80211_radiotap_iterator to parse incoming | 27 | * The libwifi radiotap parser uses the usual ieee80211_radiotap_iterator to parse incoming |
25 | * radiotap headers into a consumable libwifi_radiotap_info struct. | 28 | * radiotap headers into a consumable libwifi_radiotap_info struct. |
26 | */ | 29 | */ |
27 | int libwifi_parse_radiotap_info(struct libwifi_radiotap_info *info, const unsigned char *frame, size_t frame_len) { | 30 | int libwifi_parse_radiotap_info(struct libwifi_radiotap_info *info, const unsigned char *frame, |
31 | size_t frame_len) { | ||
28 | memset(info, 0, sizeof(struct libwifi_radiotap_info)); | 32 | memset(info, 0, sizeof(struct libwifi_radiotap_info)); |
29 | 33 | ||
30 | if (frame_len < sizeof(struct ieee80211_radiotap_header)) { | 34 | if (frame_len < sizeof(struct ieee80211_radiotap_header)) { |
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 64f8f36..19729df 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt | |||
@@ -9,6 +9,9 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb -O0") | |||
9 | 9 | ||
10 | link_directories("../build/") | 10 | link_directories("../build/") |
11 | 11 | ||
12 | link_directories(AFTER "/usr/local/lib") | ||
13 | include_directories(AFTER "/usr/local/include") | ||
14 | |||
12 | add_executable(action_tests src/action_tests.c) | 15 | add_executable(action_tests src/action_tests.c) |
13 | target_link_libraries(action_tests wifi) | 16 | target_link_libraries(action_tests wifi) |
14 | add_executable(assoc_req_tests src/assoc_req_tests.c) | 17 | add_executable(assoc_req_tests src/assoc_req_tests.c) |
diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index bdf7227..f3c9824 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt | |||
@@ -7,6 +7,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED True) | |||
7 | 7 | ||
8 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb -O0") | 8 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb -O0") |
9 | 9 | ||
10 | link_directories(AFTER "/usr/local/lib") | ||
11 | include_directories(AFTER "/usr/local/include") | ||
12 | |||
10 | add_executable(test_misc src/helpers.c src/test_misc.c) | 13 | add_executable(test_misc src/helpers.c src/test_misc.c) |
11 | add_executable(test_generation src/helpers.c src/test_generation.c) | 14 | add_executable(test_generation src/helpers.c src/test_generation.c) |
12 | add_executable(test_parsing src/helpers.c src/test_parsing.c) | 15 | add_executable(test_parsing src/helpers.c src/test_parsing.c) |
diff --git a/utils/src/test_parsing.c b/utils/src/test_parsing.c index 339816e..b9f9dbc 100644 --- a/utils/src/test_parsing.c +++ b/utils/src/test_parsing.c | |||
@@ -370,7 +370,7 @@ void parse_data_eapol(struct libwifi_frame frame, unsigned char *args, const str | |||
370 | printf("EAPOL: Descriptor: %d\n", data.descriptor); | 370 | printf("EAPOL: Descriptor: %d\n", data.descriptor); |
371 | printf("EAPOL: Key Info: Information: 0x%04x\n", data.key_info.information); | 371 | printf("EAPOL: Key Info: Information: 0x%04x\n", data.key_info.information); |
372 | printf("EAPOL: Key Info: Key Length: %d\n", data.key_info.key_length); | 372 | printf("EAPOL: Key Info: Key Length: %d\n", data.key_info.key_length); |
373 | printf("EAPOL: Key Info: Replay Counter: %lu\n", data.key_info.replay_counter); | 373 | printf("EAPOL: Key Info: Replay Counter: %llu\n", data.key_info.replay_counter); |
374 | printf("EAPOL: Key Info: Nonce: "); | 374 | printf("EAPOL: Key Info: Nonce: "); |
375 | for (size_t i = 0; i < sizeof(data.key_info.nonce); ++i) printf("%02x ", data.key_info.nonce[i]); | 375 | for (size_t i = 0; i < sizeof(data.key_info.nonce); ++i) printf("%02x ", data.key_info.nonce[i]); |
376 | printf("\n"); | 376 | printf("\n"); |