An 802.11 Frame Generation and Parsing Library in C

libwifi

802.11 Parsing / Generation library

Build Status OS Architecture
X86_64 Linux x86_64

What is this?

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) on Linux with a few lines of straight forward code (see the Examples section below).

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.

The library is fully documented with code comments in both the headers files and the code files, and also has doxygen HTML documentation in docs/html.

Building and Installing

Linux

$ mkdir build
$ cd build
$ cmake ..
$ make
$ sudo make install

Examples

Some examples are available in the examples/ directory, which show the general flow of how libwifi is used to generate and parse different types of 802.11 frame.

Running Tests

$ cd test/
$ mkdir build
$ cd build
$ cmake ..
$ make
$ sudo iw <interface> set type monitor && sudo ip link set dev <interface> up
$ ./test-program
Comments
  • Fix radiotap padding

    Fix radiotap padding

    According to the section "Alignment in Radiotap" on the radiotap website, the radiotap header fields must be padded. 8-bit fields must be 8-bit aligned, 16-bit must be 16-bit aligned, etc. In the current implementation, libwifi_create_radiotap with RATE, CHANNEL, and DBM_TX_POWER fields will be generated incorrectly, due to misalignment from the RATE field. This PR adds the appropriate padding.

  • 802.1X_FT auth key suite ends up being parsed (?) as 802.1X

    802.1X_FT auth key suite ends up being parsed (?) as 802.1X

    I am not sure of what I am seeing here, but it seems to me that, I don't know why, beacon frame with an Auth key Suites of 802.1X_FT (3) ends up being shown as 802.1X.

    I found this because of my tests, but using the examples/parse_beacon/parse_beacon.c on the same .pcap file gives the same problem:

     $ ./parse_beacon/parse_beacon --file beacons.pcap
    [...]
    ESSID: DEMOWIFI
    BSSID: 22:18:0a:6f:5a:ea
    Receiver: ff:ff:ff:ff:ff:ff
    Transmitter: 22:18:0a:6f:5a:ea
    Channel: 11
    WPS: No
    Encryption: WPA2, WPA
    	Group Ciphers: TKIP
    	Pairwise Ciphers: TKIP, CCMP128
    	Auth Key Suites: 802.1X
    Tagged Parameters:
    [...]
    

    Shouldn't there be a 802.1X_FT in Auth Key Suites line ?

    beacons.pcap.gz

  • Examples missing Makefiles

    Examples missing Makefiles

    The documentation states that you should be able to cd into the various example directories and run make in their readmes but there are no Makefiles in them.

  • Add support for 6GHz and initial extension tag parsing

    Add support for 6GHz and initial extension tag parsing

    This PR adds support for 6GHz by looking at the Radiotap header of a supplied frame.

    From commit 7c2b373b:

    Radiotap information is now stored in the libwifi_frame struct, and will be kept automatically in libwifi_frame.radiotap_info for the lifecycle of said frame, if it is present.

    A new flag has been added for the frame for use with libwifi_frame.flags to detect if the radiotap info is present: LIBWIFI_FLAGS_RADIOTAP_PRESENT.

    The frame parser will now automatically calculate the band and center channel from radiotap data, and will store them in libwifi_radiotap_info.channel.center and libwifi_radiotap_info.channel.band.

    Four new flags have been added for use with the new radiotap band field:

    • LIBWIFI_RADIOTAP_BAND_2GHZ
    • LIBWIFI_RADIOTAP_BAND_5GHZ
    • LIBWIFI_RADIOTAP_BAND_6GHZ
    • LIBWIFI_RADIOTAP_BAND_900MHZ

    These can be used with a binary AND: if (rtap.channel.band & LIBWIFI_RADIOTAP_BAND_6GHZ) { }

  • Tagged Parameter Improvements

    Tagged Parameter Improvements

    This PR adds

    • A bug fix for parsing tagged parameters with a length of zero
    • A function to check if a tagged parameter is present via tag number (libwifi_check_tag(...))
    • A function to get the tagged parameter name via a tag number (libwifi_get_tag_name(...))
  • test: Add ctests for parse and generate functions.

    test: Add ctests for parse and generate functions.

    This commit also enforces error code checking on functions inside of the generation functions, such as for libwifi_quick_add_tag.

    • [X] Generation Tests
    • [ ] Parser Tests
    • [ ] Update comment doc for new generation function returns
  • Minor compilation error on armv6 (32 bits)

    Minor compilation error on armv6 (32 bits)

    In a very specific build setup (using meson+ninja and gcc only), on armv6l, I came across that build error:

    [112/132] Compiling C object subprojects/libwifi-0.0.6/examples/parse_eapol.p/parse_eapol_parse_eapol.c.o
    FAILED: subprojects/libwifi-0.0.6/examples/parse_eapol.p/parse_eapol_parse_eapol.c.o 
    cc -Isubprojects/libwifi-0.0.6/examples/parse_eapol.p -Isubprojects/libwifi-0.0.6/examples -I../subprojects/libwifi-0.0.6/examples -I../subprojects/libwifi-0.0.6/src -I/usr/local/include -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -g -Wall -Werror -O3 -MD -MQ subprojects/libwifi-0.0.6/examples/parse_eapol.p/parse_eapol_parse_eapol.c.o -MF subprojects/libwifi-0.0.6/examples/parse_eapol.p/parse_eapol_parse_eapol.c.o.d -o subprojects/libwifi-0.0.6/examples/parse_eapol.p/parse_eapol_parse_eapol.c.o -c ../subprojects/libwifi-0.0.6/examples/parse_eapol/parse_eapol.c
    ../subprojects/libwifi-0.0.6/examples/parse_eapol/parse_eapol.c: In function ‘handle_pkt’:
    ../subprojects/libwifi-0.0.6/examples/parse_eapol/parse_eapol.c:41:56: error: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 2 has type ‘uint64_t’ {aka ‘long long unsigned int’} [-Werror=format=]
       41 |             printf("EAPOL: Key Info: Replay Counter: %lu\n", data.key_info.replay_counter);
          |                                                      ~~^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          |                                                        |                  |
          |                                                        long unsigned int  uint64_t {aka long long unsigned int}
          |                                                      %llu
    cc1: all warnings being treated as errors
    [113/132] Compiling C object subprojects/libwifi-0.0.6/utils/test_misc.p/src_helpers.c.o
    ninja: build stopped: subcommand failed.
    

    This is easly fixed with that patch:

    diff --git a/examples/parse_eapol/parse_eapol.c b/examples/parse_eapol/parse_eapol.c
    index cf35a6f..f36685b 100644
    --- a/examples/parse_eapol/parse_eapol.c
    +++ b/examples/parse_eapol/parse_eapol.c
    @@ -38,7 +38,7 @@ void handle_pkt(unsigned char *args, const struct pcap_pkthdr *header, const uns
                 printf("EAPOL: Descriptor: %d\n", data.descriptor);
                 printf("EAPOL: Key Info: Information: 0x%04x\n", data.key_info.information);
                 printf("EAPOL: Key Info: Key Length: %d\n", data.key_info.key_length);
    -            printf("EAPOL: Key Info: Replay Counter: %lu\n", data.key_info.replay_counter);
    +            printf("EAPOL: Key Info: Replay Counter: %"PRIu64"\n", data.key_info.replay_counter);
                 printf("EAPOL: Key Info: Nonce: ");
                 for (size_t i = 0; i < sizeof(data.key_info.nonce); ++i) {
                     printf("%02x ", data.key_info.nonce[i]);
    diff --git a/utils/src/test_parsing.c b/utils/src/test_parsing.c
    index b9f9dbc..84a1bde 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
                 printf("EAPOL: Descriptor: %d\n", data.descriptor);
                 printf("EAPOL: Key Info: Information: 0x%04x\n", data.key_info.information);
                 printf("EAPOL: Key Info: Key Length: %d\n", data.key_info.key_length);
    -            printf("EAPOL: Key Info: Replay Counter: %llu\n", data.key_info.replay_counter);
    +            printf("EAPOL: Key Info: Replay Counter: %"PRIu64"\n", data.key_info.replay_counter);
                 printf("EAPOL: Key Info: Nonce: ");
                 for (size_t i = 0; i < sizeof(data.key_info.nonce); ++i) printf("%02x ", data.key_info.nonce[i]);
    
    

    The second snippet avoids a warning

Arduino library for basic aerial navigation functions used for processing Euler angles, direction cosine matrices, quaternions, frame conversions, and more.

navduino Arduino library for basic aerial navigation functions used for Euler angles Direction cosine matrices Quaternions Rodrigues Rotation Vectors

Oct 24, 2022
this is very basic version for our dataset validation, only change the path, and align the frame of vio and Groundtruth
this is very basic version for our dataset validation, only change the path, and align the frame of vio and Groundtruth

VINS-Fusion for UrbanNavDataset Evaluation 1. Prerequisites please refer to VINS-Fusion Github 2. Build mkdir catkin/src cd catkin/src mkdir result cd

Dec 9, 2022
Icopack - A simple command line tool to create multi-frame ICO files from PNG source images
Icopack - A simple command line tool to create multi-frame ICO files from PNG source images

Optidash is a modern, AI-powered image optimization and processing API. We will drastically speed-up your websites and save you money on bandwidth and

Jul 27, 2022
The frame work for WhaleMarket C-Beginner Project.
The frame work for WhaleMarket C-Beginner Project.

The frame work for WhaleMarket C-Beginner Project.

Nov 11, 2022
A procedural geometry generation library for C++11
A procedural geometry generation library for C++11

Generator - A procedural geometry generation library. The purpose of this library is to easily generate procedural meshes of geometric primitives such

Dec 26, 2022
A static C++ library for the generation of discrete functions on a box-shaped domain
A static C++ library for the generation of discrete functions on a box-shaped domain

A static C++ library for the generation of discrete functions on a box-shaped domain. This is especially suited for the discretization of signed distance fields.

Nov 29, 2022
A single-header C/C++ library for parsing and evaluation of arithmetic expressions

ceval A C/C++ header for parsing and evaluation of arithmetic expressions. [README file is almost identical to that of the ceval library] Functions ac

Oct 10, 2022
A single-header C/C++ library for parsing and evaluation of arithmetic expressions

ceval A C/C++ header for parsing and evaluation of arithmetic expressions. [README file is almost identical to that of the ceval library] Functions ac

Oct 10, 2022
Just a basic mini library for parsing simple files that only have variables written and with Lua extension.

C++ Parser Lua file config Just a basic mini library for parsing simple files that only have variables written and with Lua extension. Note: At the mo

Dec 26, 2021
ZSV/lib: a fast CSV parsing library and standalone utility
ZSV/lib: a fast CSV parsing library and standalone utility

Please note: this code is still alpha / pre-production. Everything here should be considered preliminary. If you like ZSVlib, please give it a star! Z

Dec 30, 2022
A C/C++ library for parsing and evaluation of arithmetic expressions.

ceval A C/C++ header for parsing and evaluation of arithmetic expressions. Functions accessibe from main() Function Argument(s) Return Value ceval_res

Nov 8, 2022
This project contains a library for C++ AST parsing, metaprogramming and reflection

Meta C++ This project contains a library for C++ AST parsing, metaprogramming and reflection. Also included is a tool for generating the necessary met

Dec 15, 2022
A model checker for the Dynamic Logic of Propositional Assignments (DL-PA) with solving and parameterized random formula generation functionalities.

A model checker for the Dynamic Logic of Propositional Assignments (DL-PA) with solving and parameterized random formula generation functionalities.

Dec 31, 2021
Light probe generation and BRDF authoring for physically based shading.
Light probe generation and BRDF authoring for physically based shading.

IBLBaker About IBLBaker is provided under the MIT License(MIT) Copyright(c) 2015 Matt Davidson. Please see the LICENSE file for full details. Feel fre

Dec 28, 2022
Parsing Expression Grammar Template Library
Parsing Expression Grammar Template Library

Welcome to the PEGTL The Parsing Expression Grammar Template Library (PEGTL) is a zero-dependency C++ header-only parser combinator library for creati

Jan 8, 2023
A lightweight C++14 parsing library for tmx map files created with the Tiled map editor

tmxlite Description A lightweight C++14 parsing library for tmx map files created with the Tiled map editor. Requires no external linking, all depende

Dec 26, 2022
Stack-based texture generation tool written in C99!
Stack-based texture generation tool written in C99!

Stack-based texture generation tool written in C99! Brought to you by @zaklaus and contributors Introduction zpl.texed is a cross-platform stack-based

Dec 20, 2022
FluidNC - The next generation of motion control firmware
FluidNC - The next generation of motion control firmware

FluidNC (CNC Controller) For ESP32 Introduction FluidNC is the next generation of Grbl_ESP32. It has a lot of improvements over Grbl_ESP32 as listed b

Jan 3, 2023
🎻 Automatic Exploit Generation using symbolic execution

S2E Library This repository contains all the necessary components to build libs2e.so. This shared library is preloaded in QEMU to enable symbolic exec

Jan 10, 2022