├── doc └── wisec2022.pdf ├── tools ├── esptool.exe └── mkspiffs.exe ├── resources ├── logos │ ├── Tim.png │ ├── Huawei.png │ ├── Netis.png │ ├── Tplink.png │ ├── Wind.png │ ├── Fastweb.png │ ├── Skywifi.png │ ├── Vodafone.png │ └── generic.png └── favicon │ └── admin_favicon.png ├── lib ├── libpcap │ ├── CMakeLists.txt │ ├── README.md │ └── src │ │ └── libpcap.h ├── libwifi │ ├── utils │ │ ├── pcaps │ │ │ ├── auth.pcap │ │ │ ├── deauth.pcap │ │ │ ├── assoc_req.pcap │ │ │ ├── disassoc.pcap │ │ │ ├── probe_req.pcap │ │ │ ├── assoc_resp.pcap │ │ │ ├── reassoc_req.pcap │ │ │ ├── reassoc_resp.pcap │ │ │ ├── beacons_with_221.pcap │ │ │ ├── deauth_with_221.pcap │ │ │ └── probe_resp_with_221.pcap │ │ ├── .clang-format │ │ ├── CMakeLists.txt │ │ └── src │ │ │ ├── test_misc.c │ │ │ ├── helpers.c │ │ │ └── helpers.h │ ├── .clang-format │ ├── AUTHORS │ ├── .gitignore │ ├── src │ │ ├── libwifi │ │ │ ├── core │ │ │ │ ├── radiotap │ │ │ │ │ ├── COPYING │ │ │ │ │ └── platform.h │ │ │ │ ├── misc │ │ │ │ │ ├── epoch.c │ │ │ │ │ ├── epoch.h │ │ │ │ │ ├── llc.h │ │ │ │ │ ├── byteswap.h │ │ │ │ │ └── radiotap.h │ │ │ │ ├── frame │ │ │ │ │ ├── data │ │ │ │ │ │ └── data.h │ │ │ │ │ ├── management │ │ │ │ │ │ ├── atim.h │ │ │ │ │ │ ├── probe_request.h │ │ │ │ │ │ ├── assoc_request.h │ │ │ │ │ │ ├── deauthentication.h │ │ │ │ │ │ ├── disassociation.h │ │ │ │ │ │ ├── beacon.h │ │ │ │ │ │ ├── probe_response.h │ │ │ │ │ │ ├── authentication.h │ │ │ │ │ │ ├── reassoc_request.h │ │ │ │ │ │ ├── assoc_response.h │ │ │ │ │ │ ├── reassoc_response.h │ │ │ │ │ │ ├── action.h │ │ │ │ │ │ └── timing_ad.h │ │ │ │ │ ├── control │ │ │ │ │ │ ├── cts.h │ │ │ │ │ │ └── rts.h │ │ │ │ │ ├── tag_iterator.h │ │ │ │ │ ├── crc.h │ │ │ │ │ ├── tag_iterator.c │ │ │ │ │ └── crc.c │ │ │ │ ├── core.c │ │ │ │ └── core.h │ │ │ ├── parse │ │ │ │ ├── data │ │ │ │ │ ├── data.h │ │ │ │ │ ├── data.c │ │ │ │ │ └── eapol.h │ │ │ │ ├── management │ │ │ │ │ ├── deauthentication.h │ │ │ │ │ ├── disassociation.h │ │ │ │ │ ├── probe_request.h │ │ │ │ │ ├── assoc_request.h │ │ │ │ │ ├── reassoc_request.h │ │ │ │ │ ├── beacon.h │ │ │ │ │ ├── probe_response.h │ │ │ │ │ ├── assoc_response.h │ │ │ │ │ ├── reassoc_response.h │ │ │ │ │ ├── common.h │ │ │ │ │ ├── probe_request.c │ │ │ │ │ ├── assoc_request.c │ │ │ │ │ ├── reassoc_request.c │ │ │ │ │ ├── disassociation.c │ │ │ │ │ └── deauthentication.c │ │ │ │ └── misc │ │ │ │ │ └── radiotap.h │ │ │ └── gen │ │ │ │ ├── control │ │ │ │ ├── cts.c │ │ │ │ ├── cts.h │ │ │ │ ├── rts.c │ │ │ │ └── rts.h │ │ │ │ ├── misc │ │ │ │ └── radiotap.h │ │ │ │ └── management │ │ │ │ ├── atim.c │ │ │ │ ├── atim.h │ │ │ │ ├── common.h │ │ │ │ ├── deauthentication.h │ │ │ │ ├── disassociation.h │ │ │ │ ├── assoc_request.h │ │ │ │ ├── probe_request.h │ │ │ │ ├── authentication.h │ │ │ │ ├── reassoc_request.h │ │ │ │ ├── assoc_response.h │ │ │ │ └── reassoc_response.h │ │ └── libwifi.h │ ├── test │ │ ├── src │ │ │ ├── atim_tests.c │ │ │ ├── timing_ad_tests.c │ │ │ ├── action_tests.c │ │ │ ├── auth_tests.c │ │ │ ├── deauth_tests.c │ │ │ ├── disassoc_tests.c │ │ │ ├── assoc_req_tests.c │ │ │ ├── probe_req_tests.c │ │ │ ├── assoc_resp_tests.c │ │ │ ├── probe_resp_tests.c │ │ │ ├── reassoc_req_tests.c │ │ │ └── reassoc_resp_tests.c │ │ └── README.md │ └── README.md └── README ├── screenshots ├── elivtwin_page.png ├── settings_page.png └── phishing_page_example.png ├── CMakeLists.txt ├── .gitignore ├── include ├── dns.h ├── admin_server.h ├── server.h ├── nvs_keys.h ├── wifiMng.h ├── aircrack.h ├── evil_twin.h ├── vendors.h ├── passwordMng.h ├── config.h ├── utils.h └── web │ ├── loader.h │ └── passwords.h ├── src ├── CMakeLists.txt ├── vendors.c ├── main.c └── dns.c ├── partition.csv ├── .vscode ├── extensions.json └── settings.json ├── scripts ├── custom_tasks.py ├── merge_bins.py └── spiffs_tool.py ├── test └── README ├── sdkconfig.defaults ├── platformio.ini └── performance.txt /doc/wisec2022.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexxdal/ESP32WifiPhisher/HEAD/doc/wisec2022.pdf -------------------------------------------------------------------------------- /tools/esptool.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexxdal/ESP32WifiPhisher/HEAD/tools/esptool.exe -------------------------------------------------------------------------------- /tools/mkspiffs.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexxdal/ESP32WifiPhisher/HEAD/tools/mkspiffs.exe -------------------------------------------------------------------------------- /resources/logos/Tim.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexxdal/ESP32WifiPhisher/HEAD/resources/logos/Tim.png -------------------------------------------------------------------------------- /resources/logos/Huawei.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexxdal/ESP32WifiPhisher/HEAD/resources/logos/Huawei.png -------------------------------------------------------------------------------- /resources/logos/Netis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexxdal/ESP32WifiPhisher/HEAD/resources/logos/Netis.png -------------------------------------------------------------------------------- /resources/logos/Tplink.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexxdal/ESP32WifiPhisher/HEAD/resources/logos/Tplink.png -------------------------------------------------------------------------------- /resources/logos/Wind.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexxdal/ESP32WifiPhisher/HEAD/resources/logos/Wind.png -------------------------------------------------------------------------------- /resources/logos/Fastweb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexxdal/ESP32WifiPhisher/HEAD/resources/logos/Fastweb.png -------------------------------------------------------------------------------- /resources/logos/Skywifi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexxdal/ESP32WifiPhisher/HEAD/resources/logos/Skywifi.png -------------------------------------------------------------------------------- /resources/logos/Vodafone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexxdal/ESP32WifiPhisher/HEAD/resources/logos/Vodafone.png -------------------------------------------------------------------------------- /resources/logos/generic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexxdal/ESP32WifiPhisher/HEAD/resources/logos/generic.png -------------------------------------------------------------------------------- /lib/libpcap/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "pcap_serializer.c" 2 | INCLUDE_DIRS "interface") -------------------------------------------------------------------------------- /screenshots/elivtwin_page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexxdal/ESP32WifiPhisher/HEAD/screenshots/elivtwin_page.png -------------------------------------------------------------------------------- /screenshots/settings_page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexxdal/ESP32WifiPhisher/HEAD/screenshots/settings_page.png -------------------------------------------------------------------------------- /lib/libwifi/utils/pcaps/auth.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexxdal/ESP32WifiPhisher/HEAD/lib/libwifi/utils/pcaps/auth.pcap -------------------------------------------------------------------------------- /lib/libwifi/utils/pcaps/deauth.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexxdal/ESP32WifiPhisher/HEAD/lib/libwifi/utils/pcaps/deauth.pcap -------------------------------------------------------------------------------- /resources/favicon/admin_favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexxdal/ESP32WifiPhisher/HEAD/resources/favicon/admin_favicon.png -------------------------------------------------------------------------------- /lib/libwifi/utils/pcaps/assoc_req.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexxdal/ESP32WifiPhisher/HEAD/lib/libwifi/utils/pcaps/assoc_req.pcap -------------------------------------------------------------------------------- /lib/libwifi/utils/pcaps/disassoc.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexxdal/ESP32WifiPhisher/HEAD/lib/libwifi/utils/pcaps/disassoc.pcap -------------------------------------------------------------------------------- /lib/libwifi/utils/pcaps/probe_req.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexxdal/ESP32WifiPhisher/HEAD/lib/libwifi/utils/pcaps/probe_req.pcap -------------------------------------------------------------------------------- /screenshots/phishing_page_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexxdal/ESP32WifiPhisher/HEAD/screenshots/phishing_page_example.png -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.11.0) 2 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 3 | project(WifiPhisher) 4 | -------------------------------------------------------------------------------- /lib/libwifi/utils/pcaps/assoc_resp.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexxdal/ESP32WifiPhisher/HEAD/lib/libwifi/utils/pcaps/assoc_resp.pcap -------------------------------------------------------------------------------- /lib/libwifi/utils/pcaps/reassoc_req.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexxdal/ESP32WifiPhisher/HEAD/lib/libwifi/utils/pcaps/reassoc_req.pcap -------------------------------------------------------------------------------- /lib/libwifi/utils/pcaps/reassoc_resp.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexxdal/ESP32WifiPhisher/HEAD/lib/libwifi/utils/pcaps/reassoc_resp.pcap -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | .vscode/.browse.c_cpp.db* 3 | .vscode/c_cpp_properties.json 4 | .vscode/launch.json 5 | .vscode/ipch 6 | spiffs_dump.bin 7 | build/ -------------------------------------------------------------------------------- /lib/libwifi/utils/pcaps/beacons_with_221.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexxdal/ESP32WifiPhisher/HEAD/lib/libwifi/utils/pcaps/beacons_with_221.pcap -------------------------------------------------------------------------------- /lib/libwifi/utils/pcaps/deauth_with_221.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexxdal/ESP32WifiPhisher/HEAD/lib/libwifi/utils/pcaps/deauth_with_221.pcap -------------------------------------------------------------------------------- /lib/libwifi/utils/pcaps/probe_resp_with_221.pcap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alexxdal/ESP32WifiPhisher/HEAD/lib/libwifi/utils/pcaps/probe_resp_with_221.pcap -------------------------------------------------------------------------------- /include/dns.h: -------------------------------------------------------------------------------- 1 | #ifndef _DNS_H 2 | #define _DNS_H 3 | 4 | /** 5 | * @brief Start dns server to mimic captive portal 6 | * 7 | */ 8 | void dns_server_start(void); 9 | 10 | #endif -------------------------------------------------------------------------------- /lib/libwifi/.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | BasedOnStyle: LLVM 3 | IndentWidth: '4' 4 | SpaceAfterCStyleCast: 'true' 5 | ColumnLimit: 110 6 | AllowShortFunctionsOnASingleLine: None 7 | IndentCaseLabels: 'true' 8 | ... 9 | -------------------------------------------------------------------------------- /lib/libwifi/utils/.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | BasedOnStyle: LLVM 3 | IndentWidth: '4' 4 | SpaceAfterCStyleCast: 'true' 5 | ColumnLimit: 400 6 | AllowShortFunctionsOnASingleLine: None 7 | IndentCaseLabels: 'true' 8 | ... 9 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file was automatically generated for projects 2 | # without default 'CMakeLists.txt' file. 3 | 4 | FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/src/*.*) 5 | 6 | idf_component_register(SRCS ${app_sources}) 7 | -------------------------------------------------------------------------------- /partition.csv: -------------------------------------------------------------------------------- 1 | # ESP-IDF Partition Table 2 | # Name, Type, SubType, Offset, Size, Flags 3 | nvs, data, nvs, 0x9000, 0x6000, 4 | phy_init, data, phy, 0xf000, 0x1000, 5 | factory, app, factory, 0x10000, 3M, 6 | spiffs, data, spiffs, 0x310000, 512K, -------------------------------------------------------------------------------- /include/admin_server.h: -------------------------------------------------------------------------------- 1 | #ifndef _ADMIN_SERVER_H 2 | #define _ADMIN_SERVER_H 3 | 4 | /** 5 | * @brief Start http server task 6 | * 7 | */ 8 | void http_admin_server_start(void); 9 | 10 | 11 | /** 12 | * @brief Stop the http admin server 13 | * 14 | */ 15 | void http_admin_server_stop(void); 16 | 17 | #endif -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "platformio.platformio-ide" 6 | ], 7 | "unwantedRecommendations": [ 8 | "ms-vscode.cpptools-extension-pack" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /scripts/custom_tasks.py: -------------------------------------------------------------------------------- 1 | Import("env") 2 | 3 | def run_python_script(source, target, env): 4 | env.Execute("python scripts/spiffs_tool.py") 5 | 6 | env.AddCustomTarget( 7 | name="RunPythonScript", 8 | dependencies=None, 9 | actions=[run_python_script], 10 | title="Extract Saved Passwords", 11 | description=None, 12 | ) -------------------------------------------------------------------------------- /include/server.h: -------------------------------------------------------------------------------- 1 | #ifndef _SERVER_H 2 | #define _SERVER_H 3 | 4 | #include "wifi_attacks.h" 5 | 6 | /** 7 | * @brief Start http server task 8 | * 9 | */ 10 | void http_attack_server_start(target_info_t *_target_info); 11 | 12 | 13 | /** 14 | * @brief Stop http server 15 | * 16 | */ 17 | void http_attack_server_stop(void); 18 | 19 | #endif -------------------------------------------------------------------------------- /lib/libwifi/AUTHORS: -------------------------------------------------------------------------------- 1 | # This is the list of libwifi's significant contributors. 2 | # 3 | # This does not necessarily list everyone who has contributed code, 4 | # especially since many employees of one corporation may be contributing. 5 | # To see the full list of contributors, see the revision history in 6 | # source control. 7 | Marc Egerton 8 | Sebastian Kinne 9 | Henry Pitcairn 10 | Hak5 LLC 11 | Google LLC -------------------------------------------------------------------------------- /include/nvs_keys.h: -------------------------------------------------------------------------------- 1 | #ifndef _NVS_KEYS_H 2 | #define _NVS_KEYS_H 3 | 4 | /** 5 | * @brief Key for storage on wifi ssid 6 | * 7 | */ 8 | #define WIFI_SSID_KEY "wifi_ssid" 9 | 10 | /** 11 | * @brief Key for storage on wifi password 12 | * 13 | */ 14 | #define WIFI_PASS_KEY "wifi_pass" 15 | 16 | /** 17 | * @brief Key for storage on wifi channel 18 | * 19 | */ 20 | #define WIFI_CHAN_KEY "wifi_chan" 21 | 22 | #endif -------------------------------------------------------------------------------- /lib/libwifi/.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries 2 | *.a 3 | *.o 4 | *.so* 5 | *.dylib 6 | 7 | # Build 8 | CMakeLists.txt.user 9 | CMakeCache.txt 10 | CMakeFiles 11 | CMakeScripts 12 | Testing 13 | Makefile 14 | cmake_install.cmake 15 | install_manifest.txt 16 | compile_commands.json 17 | CTestTestfile.cmake 18 | _deps 19 | CMakeUserPresets.json 20 | *-prefix/ 21 | 22 | # Output 23 | build/ 24 | test/build/ 25 | test/*_tests 26 | utils/test_* 27 | 28 | # Temporary Patches 29 | *.patch 30 | -------------------------------------------------------------------------------- /include/wifiMng.h: -------------------------------------------------------------------------------- 1 | #ifndef _WIFI_MNG_H 2 | #define _WIFI_MNG_H 3 | 4 | #include "esp_wifi.h" 5 | 6 | /** 7 | * @brief Init Wifi interface 8 | * 9 | */ 10 | esp_err_t wifi_init(void); 11 | 12 | 13 | /** 14 | * @brief Start wifi in AP mode 15 | * 16 | */ 17 | void wifi_start_softap(void); 18 | 19 | 20 | /** 21 | * @brief Start wifi AP with given settings 22 | * 23 | * @param wifi_config 24 | * @param bssid 25 | */ 26 | void wifi_ap_clone(wifi_config_t *wifi_config, uint8_t *bssid); 27 | 28 | #endif -------------------------------------------------------------------------------- /test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PlatformIO Test Runner and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PlatformIO Unit Testing: 11 | - https://docs.platformio.org/en/latest/advanced/unit-testing/index.html 12 | -------------------------------------------------------------------------------- /lib/libwifi/utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.18) 2 | 3 | project(libwifi_tests VERSION 0.1) 4 | 5 | set(CMAKE_CXX_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD_REQUIRED True) 7 | 8 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb -O0") 9 | 10 | link_directories(AFTER "/usr/local/lib") 11 | include_directories(AFTER "/usr/local/include") 12 | 13 | add_executable(test_misc src/helpers.c src/test_misc.c) 14 | add_executable(test_generation src/helpers.c src/test_generation.c) 15 | add_executable(test_parsing src/helpers.c src/test_parsing.c) 16 | target_link_libraries(test_misc wifi) 17 | target_link_libraries(test_generation wifi pcap) 18 | target_link_libraries(test_parsing wifi pcap) 19 | -------------------------------------------------------------------------------- /include/aircrack.h: -------------------------------------------------------------------------------- 1 | #ifndef _AIRCRACK_H 2 | #define _AIRCRACK_H 3 | 4 | #include 5 | 6 | 7 | bool verify_password(const char *passphrase, const char *ssid, size_t ssid_len, 8 | const uint8_t *mac_ap, const uint8_t *mac_sta, 9 | const uint8_t *anonce, const uint8_t *snonce, 10 | const uint8_t *eapol, size_t eapol_len, 11 | const uint8_t *expected_mic, uint8_t key_descriptor); 12 | 13 | 14 | bool verify_pmkid(const char *passphrase, const char *ssid, size_t ssid_len, 15 | const uint8_t *mac_ap, const uint8_t *mac_sta, 16 | const uint8_t *expected_pmkid); 17 | 18 | 19 | #endif -------------------------------------------------------------------------------- /lib/libpcap/README.md: -------------------------------------------------------------------------------- 1 | # ESP32 Wi-Fi Penetration Tool 2 | ## PCAP Serializer component 3 | 4 | This component formats provided frames into PCAP binary format. 5 | 6 | It's based on [Wiresharks LibPCAP file format referenc](https://gitlab.com/wireshark/wireshark/-/wikis/Development/LibpcapFileFormat). 7 | It simply appends new frames to a structured buffer and it can be obtained on demand. 8 | 9 | ## Usage 10 | 1. First initialise new PCAP file buffer by calling `pcap_serializer_init()`. 11 | 1. Then `pcap_serializer_append_frame()` is used to append more frames into the file. 12 | 1. To get the buffer, call `pcap_serializer_get_buffer()` and `pcap_serializer_get_size()`. 13 | 14 | ## Reference 15 | Doxygen API reference available -------------------------------------------------------------------------------- /include/evil_twin.h: -------------------------------------------------------------------------------- 1 | #ifndef _EVIL_TWIN_H 2 | #define _EVIL_TWIN_H 3 | 4 | #include "esp_wifi.h" 5 | #include "esp_system.h" 6 | #include "vendors.h" 7 | #include "wifi_attacks.h" 8 | 9 | 10 | typedef enum 11 | { 12 | FIRMWARE_UPGRADE = 0, 13 | WEB_NET_MANAGER, 14 | PLUGIN_UPDATE, 15 | OAUTH_LOGIN 16 | } attack_scheme_t; 17 | 18 | 19 | /** 20 | * @brief Start EVIL TWIN attack, before lauching be sure to fill target struct 21 | * 22 | */ 23 | void evil_twin_start_attack(target_info_t *targe_info); 24 | 25 | 26 | /** 27 | * @brief Stop EVIL TWIN attack. 28 | * 29 | */ 30 | void evil_twin_stop_attack(void); 31 | 32 | 33 | /** 34 | * @brief Check the user input password 35 | * 36 | * @param password 37 | * @return bool 38 | */ 39 | bool evil_twin_check_password(char *password); 40 | 41 | #endif -------------------------------------------------------------------------------- /lib/libwifi/utils/src/test_misc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void gen_macs() { 6 | printf("Getting 10 random MAC addresses:\n"); 7 | for(int i = 0; i < 10; i++) { 8 | unsigned char mac[6] = {0}; 9 | libwifi_random_mac(mac, NULL); 10 | printf(MACSTR "\n", MAC2STR(mac)); 11 | } 12 | 13 | printf("Generating 10 random MAC addresses with 00:20:91 OUI:\n"); 14 | for(int i = 0; i < 10; i++) { 15 | unsigned char mac[6] = {0}; 16 | libwifi_random_mac(mac, (unsigned char *) "\x00\x20\x91"); 17 | printf(MACSTR "\n", MAC2STR(mac)); 18 | } 19 | printf("\n"); 20 | } 21 | 22 | int main() { 23 | libwifi_dummy(); 24 | 25 | printf("libwifi version: %s\n\n", libwifi_get_version()); 26 | 27 | gen_macs(); 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /include/vendors.h: -------------------------------------------------------------------------------- 1 | #ifndef _VENDORS_H 2 | #define _VENDORS_H 3 | 4 | 5 | #include "esp_system.h" 6 | 7 | typedef enum { 8 | GENERIC = 0x00, 9 | VODAFONE, 10 | FASTWEB, 11 | TPLINK, 12 | TIM, 13 | DLINK, 14 | SKYWIFI, 15 | WIND, 16 | LINKEM, 17 | HUAWEI, 18 | NETGER, 19 | TISCALI, 20 | FRITZBOX, 21 | NETIS 22 | } vendors_t; 23 | 24 | 25 | typedef struct { 26 | const char *uri; 27 | const char *logo; 28 | size_t logo_size; 29 | } logo_entry_t; 30 | 31 | 32 | /** 33 | * @brief Get vendor from ssid 34 | * 35 | * @param ssid 36 | * @return vendors_t 37 | */ 38 | vendors_t getVendor(char *ssid); 39 | 40 | 41 | /** 42 | * @brief Return the vendor string 43 | * 44 | * @param vendor 45 | * @return const char* 46 | */ 47 | const char * vendorToString(vendors_t vendor); 48 | 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/core/radiotap/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2007-2009 Andy Green 2 | Copyright (c) 2007-2009 Johannes Berg 3 | 4 | Permission to use, copy, modify, and/or distribute this software for any 5 | purpose with or without fee is hereby granted, provided that the above 6 | copyright notice and this permission notice appear in all copies. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | -------------------------------------------------------------------------------- /lib/libwifi/test/src/atim_tests.c: -------------------------------------------------------------------------------- 1 | #include "../../src/libwifi.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #define BCAST_MAC "\xff\xff\xff\xff\xff\xff" 8 | #define TO_MAC "\x00\x20\x91\xAA\xBB\xCC" 9 | const unsigned char to[] = TO_MAC; 10 | const unsigned char bcast[] = BCAST_MAC; 11 | 12 | int test_atim_gen_full() { 13 | struct libwifi_atim atim = {0}; 14 | 15 | int ret = libwifi_create_atim(&atim, bcast, to, to); 16 | if (ret != 0) { 17 | fprintf(stderr, "Failed to create atim: %s\n", strerror(ret)); 18 | return ret; 19 | } 20 | 21 | return 0; 22 | } 23 | 24 | int main(int argc, char **argv) { 25 | if (argc < 2) { 26 | printf("Specify test\n"); 27 | return -1; 28 | } 29 | 30 | if (strcmp(argv[1], "--atim-gen-full") == 0) { 31 | return test_atim_gen_full(); 32 | } 33 | 34 | return -1; 35 | } 36 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/core/misc/epoch.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #include "epoch.h" 17 | #include 18 | 19 | unsigned long long libwifi_get_epoch(void) { 20 | struct timespec spec; 21 | clock_gettime(CLOCK_REALTIME, &spec); 22 | return spec.tv_sec * 1000 + spec.tv_nsec / 1000; 23 | } 24 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/core/misc/epoch.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_CORE_EPOCH_H 17 | #define LIBWIFI_CORE_EPOCH_H 18 | 19 | /** 20 | * Get the current system time in epoch. 21 | * 22 | * @return current time in unix epoch. 23 | */ 24 | unsigned long long libwifi_get_epoch(void); 25 | 26 | #endif /* LIBWIFI_CORE_EPOCH_H */ 27 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/parse/data/data.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_PARSE_DATA_H 17 | #define LIBWIFI_PARSE_DATA_H 18 | 19 | #include "../../core/frame/data/data.h" 20 | #include "../../core/frame/frame.h" 21 | 22 | int libwifi_parse_data(struct libwifi_data *data, struct libwifi_frame *frame); 23 | 24 | void libwifi_free_data(struct libwifi_data *data); 25 | 26 | #endif /* LIBWIFI_PARSE_DATA_H */ 27 | -------------------------------------------------------------------------------- /sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | 2 | CONFIG_LWIP_MAX_SOCKETS=16 3 | CONFIG_LWIP_TCP_PCB_NUM=16 4 | CONFIG_LWIP_UDP_PCB_NUM=16 5 | CONFIG_HTTPD_MAX_REQ_HDR_LEN=1024 6 | CONFIG_HTTPD_MAX_URI_LEN=512 7 | 8 | CONFIG_ESP_WIFI_SOFTAP_BEACON_MAX_LEN=1024 9 | CONFIG_ESP_WIFI_CSI_ENABLED=n 10 | CONFIG_ESP_WIFI_MBO_SUPPORT=n 11 | CONFIG_ESP_WIFI_DPP_SUPPORT=n 12 | CONFIG_ESP_WIFI_NAN_ENABLE=n 13 | CONFIG_ESP_WIFI_11R_SUPPORT=n 14 | CONFIG_ESP_WIFI_11KV_SUPPORT=n 15 | CONFIG_ESP_WIFI_AMPDU_TX_ENABLED=y 16 | CONFIG_ESP_WIFI_TX_BA_WIN=16 17 | CONFIG_ESP_WIFI_AMPDU_RX_ENABLED=y 18 | CONFIG_ESP_WIFI_RX_BA_WIN=16 19 | CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM=16 20 | CONFIG_ESP_WIFI_DYNAMIC_RX_BUFFER_NUM=64 21 | CONFIG_ESP_WIFI_DYNAMIC_TX_BUFFER_NUM=64 22 | 23 | 24 | # Bluetooth 25 | CONFIG_BT_ENABLED is not set 26 | CONFIG_BT_BLUEDROID_ENABLED is not set 27 | CONFIG_BT_NIMBLE_ENABLED is not set 28 | CONFIG_BT_CONTROLLER_ENABLED is not set 29 | CONFIG_IEEE802154_ENABLED is not set 30 | 31 | # Support for aircrack 32 | CONFIG_MBEDTLS_CMAC_C=y 33 | CONFIG_MBEDTLS_AES_C=y 34 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/parse/management/deauthentication.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_PARSE_DEAUTH_H 17 | #define LIBWIFI_PARSE_DEAUTH_H 18 | 19 | #include "../../core/frame/frame.h" 20 | #include "../../core/frame/management/common.h" 21 | #include "../../core/frame/management/deauthentication.h" 22 | 23 | int libwifi_parse_deauth(struct libwifi_parsed_deauth *deauth, struct libwifi_frame *frame); 24 | 25 | #endif /* LIBWIFI_PARSE_DEAUTH_H */ 26 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/parse/management/disassociation.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_PARSE_DISASSOC_H 17 | #define LIBWIFI_PARSE_DISASSOC_H 18 | 19 | #include "../../core/frame/frame.h" 20 | #include "../../core/frame/management/common.h" 21 | #include "../../core/frame/management/disassociation.h" 22 | 23 | int libwifi_parse_disassoc(struct libwifi_parsed_disassoc *disassoc, struct libwifi_frame *frame); 24 | 25 | #endif /* LIBWIFI_PARSE_DISASSOC_H */ 26 | -------------------------------------------------------------------------------- /lib/libwifi/utils/src/helpers.c: -------------------------------------------------------------------------------- 1 | #include "helpers.h" 2 | #include 3 | 4 | void hexdump(void *data, size_t size) { 5 | char ascii[17]; 6 | size_t i, j; 7 | ascii[16] = '\0'; 8 | for (i = 0; i < size; ++i) { 9 | printf("%02X ", ((unsigned char *) data)[i]); 10 | if (((unsigned char *) data)[i] >= ' ' && ((unsigned char *) data)[i] <= '~') { 11 | ascii[i % 16] = ((unsigned char *) data)[i]; 12 | } else { 13 | ascii[i % 16] = '.'; 14 | } 15 | if ((i + 1) % 8 == 0 || i + 1 == size) { 16 | printf(" "); 17 | if ((i + 1) % 16 == 0) { 18 | printf("| %s \n", ascii); 19 | } else if (i + 1 == size) { 20 | ascii[(i + 1) % 16] = '\0'; 21 | if ((i + 1) % 16 <= 8) { 22 | printf(" "); 23 | } 24 | for (j = (i + 1) % 16; j < 16; ++j) { 25 | printf(" "); 26 | } 27 | printf("| %s \n", ascii); 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/core/misc/llc.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_CORE_LLC_H 17 | #define LIBWIFI_CORE_LLC_H 18 | 19 | #include 20 | 21 | #define XEROX_OUI "\x00\x00\x00" 22 | 23 | #define LLC_TYPE_AUTH 0x888E 24 | 25 | struct libwifi_logical_link_ctrl { 26 | uint8_t dsap; 27 | uint8_t ssap; 28 | uint8_t control; 29 | unsigned char oui[3]; 30 | uint16_t type; 31 | } __attribute__((packed)); 32 | 33 | #endif /* LIBWIFI_CORE_LLC_H */ 34 | -------------------------------------------------------------------------------- /include/passwordMng.h: -------------------------------------------------------------------------------- 1 | #ifndef _PASSWORD_MNG_H 2 | #define _PASSWORD_MNG_H 3 | 4 | #include "esp_system.h" 5 | #include "libwifi.h" 6 | #include "esp_http_server.h" 7 | 8 | /** 9 | * @brief Initialize password manager 10 | * 11 | * @return esp_err_t 12 | */ 13 | esp_err_t password_manager_init(void); 14 | 15 | 16 | /** 17 | * @brief Save the input string 18 | * 19 | * @param text 20 | */ 21 | void password_manager_save(char *text); 22 | 23 | 24 | /** 25 | * @brief Erase all file content 26 | * 27 | */ 28 | void password_manager_clean(void); 29 | 30 | 31 | /** 32 | * @brief Append new frame to pcap buffer 33 | * 34 | * @param buffer 35 | * @param len 36 | * @param us 37 | */ 38 | void password_manager_append_frame(const uint8_t *buffer, int len, int us); 39 | 40 | 41 | /** 42 | * @brief Save pcap file to SPIFFS 43 | * 44 | */ 45 | void password_manager_pcap_finalize(void); 46 | 47 | 48 | /** 49 | * @brief Read password file and put output directly on web response 50 | * 51 | * @param req 52 | */ 53 | void password_manager_read_passwords(httpd_req_t *req); 54 | 55 | 56 | #endif -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/core/frame/data/data.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_CORE_DATA_H 17 | #define LIBWIFI_CORE_DATA_H 18 | 19 | #include 20 | 21 | /** 22 | * Data Frame Layout 23 | * ─────────────────────────────────── 24 | */ 25 | struct libwifi_data { 26 | unsigned char transmitter[6]; 27 | unsigned char receiver[6]; 28 | unsigned char *body; 29 | size_t body_len; 30 | }; 31 | 32 | #endif /* LIBWIFI_CORE_DATA_H */ 33 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/gen/control/cts.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #include "cts.h" 17 | 18 | #include 19 | 20 | int libwifi_create_cts(struct libwifi_cts *cts, const unsigned char receiver[6], uint16_t duration) { 21 | memset(cts, 0, sizeof(struct libwifi_cts)); 22 | 23 | cts->frame_header.frame_control.type = TYPE_CONTROL; 24 | cts->frame_header.frame_control.subtype = SUBTYPE_CTS; 25 | cts->frame_header.duration = duration; 26 | 27 | memcpy(cts->receiver_addr, receiver, 6); 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/gen/control/cts.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_GEN_CTS_H 17 | #define LIBWIFI_GEN_CTS_H 18 | 19 | #include "../../core/frame/control/cts.h" 20 | 21 | /** 22 | * Create a CTS Control frame 23 | * 24 | * @param cts A fresh libwifi_cts struct 25 | * @param receiver The receiver MAC address 26 | * @param duration The duration of the clear-to-send 27 | */ 28 | int libwifi_create_cts(struct libwifi_cts *cts, const unsigned char receiver[6], uint16_t duration); 29 | 30 | #endif /* LIBWIFI_GEN_CTS_H */ 31 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/core/frame/management/atim.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_CORE_ATIM_H 17 | #define LIBWIFI_CORE_ATIM_H 18 | 19 | #include "../frame.h" 20 | 21 | /** 22 | * ATIM Frame Layout 23 | * ───────────────────────────────── 24 | * ┌─────────────────────────────────┐ 25 | * │ Header │ Bytes: 24 26 | * └─────────────────────────────────┘ 27 | */ 28 | 29 | struct libwifi_atim { 30 | struct libwifi_mgmt_unordered_frame_header frame_header; 31 | }; 32 | 33 | #endif /* LIBWIFI_CORE_ATIM_H */ 34 | -------------------------------------------------------------------------------- /include/config.h: -------------------------------------------------------------------------------- 1 | #ifndef _CONFIG_H 2 | #define _CONFIG_H 3 | 4 | #include 5 | #include "nvs_keys.h" 6 | 7 | /* WIFI CONFIGURATION */ 8 | #define DEFAULT_WIFI_SSID "MagicWifi" 9 | #define DEFAULT_WIFI_PASS "MagicWifi1234" 10 | #define DEFAULT_WIFI_MAX_CONN 5 11 | #define DEFAULT_WIFI_CHAN 1 12 | #define DEFAULT_WIFI_AUTH WIFI_AUTH_WPA_WPA2_PSK 13 | 14 | 15 | /** 16 | * @brief Save string value to flash 17 | * 18 | * @param key 19 | * @param value 20 | */ 21 | void save_string_to_flash(const char* key, const char* value); 22 | 23 | 24 | /** 25 | * @brief Read string value from flash 26 | * 27 | * @param key 28 | */ 29 | esp_err_t read_string_from_flash(const char* key, char* value); 30 | 31 | 32 | /** 33 | * @brief Save int32 to flash 34 | * 35 | * @param key 36 | * @param value 37 | */ 38 | void save_int_to_flash(const char* key, int32_t value); 39 | 40 | 41 | /** 42 | * @brief Read int32_ from Flash 43 | * 44 | * @param key 45 | * @param value 46 | * @return esp_err_t 47 | */ 48 | esp_err_t read_int_from_flash(const char* key, int32_t *value); 49 | 50 | 51 | #endif -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "*.embeddedhtml": "html", 4 | "*.json": "cpp", 5 | "esp_event_loop.h": "c", 6 | "esp_log.h": "c", 7 | "event_groups.h": "c", 8 | "esp_spi_flash.h": "c", 9 | "esp_wifi.h": "c", 10 | "nvs_flash.h": "c", 11 | "string.h": "c", 12 | "esp_http_server.h": "c", 13 | "server.h": "c", 14 | "sstream": "c", 15 | "vendors.h": "c", 16 | "evil_twin.h": "c", 17 | "wifimng.h": "c", 18 | "stdint.h": "c", 19 | "functional": "c", 20 | "admin_server.h": "c", 21 | "wifi_attacks.h": "c", 22 | "esp_task_wdt.h": "c", 23 | "array": "c", 24 | "string": "c", 25 | "string_view": "c", 26 | "bootstrap_min_css.h": "c", 27 | "index.h": "c", 28 | "esp_spiffs.h": "c", 29 | "queue.h": "c", 30 | "pkcs5.h": "c", 31 | "build_info.h": "c", 32 | "byteswap.h": "c", 33 | "passwordmng.h": "c", 34 | "libpcap.h": "c", 35 | "utils.h": "c", 36 | "esp_system.h": "c", 37 | "esp_random.h": "c", 38 | "huawei.h": "c", 39 | "web_net_manager.h": "c" 40 | } 41 | } -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/parse/management/probe_request.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_PARSE_PROBEREQ_H 17 | #define LIBWIFI_PARSE_PROBEREQ_H 18 | 19 | #include "../../core/frame/frame.h" 20 | #include "../../core/frame/management/common.h" 21 | #include "../../core/frame/management/probe_request.h" 22 | 23 | /** 24 | * Parse a probe request into a libwifi_sta. 25 | * 26 | * @param sta A libwifi_sta 27 | * @param frame A libwifi_frame 28 | * @return 0 if successful, a negative number if not 29 | */ 30 | int libwifi_parse_probe_req(struct libwifi_sta *sta, struct libwifi_frame *frame); 31 | 32 | #endif /* LIBWIFI_PARSE_PROBEREQ_H */ 33 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/parse/management/assoc_request.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_PARSE_ASSOCREQ_H 17 | #define LIBWIFI_PARSE_ASSOCREQ_H 18 | 19 | #include "../../core/frame/frame.h" 20 | #include "../../core/frame/management/assoc_request.h" 21 | #include "../../core/frame/management/common.h" 22 | 23 | /** 24 | * Parse a association request into a libwifi_sta. 25 | * 26 | * @param sta A libwifi_sta 27 | * @param frame A libwifi_frame 28 | * @return 0 if successful, a negative number if not 29 | */ 30 | int libwifi_parse_assoc_req(struct libwifi_sta *sta, struct libwifi_frame *frame); 31 | 32 | #endif /* LIBWIFI_PARSE_ASSOCREQ_H */ 33 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/gen/control/rts.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #include "rts.h" 17 | 18 | #include 19 | 20 | int libwifi_create_rts(struct libwifi_rts *rts, const unsigned char transmitter[6], 21 | const unsigned char receiver[6], uint16_t duration) { 22 | memset(rts, 0, sizeof(struct libwifi_rts)); 23 | 24 | rts->frame_header.frame_control.type = TYPE_CONTROL; 25 | rts->frame_header.frame_control.subtype = SUBTYPE_RTS; 26 | rts->frame_header.duration = duration; 27 | 28 | memcpy(rts->transmitter_addr, transmitter, 6); 29 | memcpy(rts->receiver_addr, receiver, 6); 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /lib/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link into executable file. 4 | 5 | The source code of each library should be placed in a an own separate directory 6 | ("lib/your_library_name/[here are source files]"). 7 | 8 | For example, see a structure of the following two libraries `Foo` and `Bar`: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- README --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/gen/control/rts.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_GEN_RTS_H 17 | #define LIBWIFI_GEN_RTS_H 18 | 19 | #include "../../core/frame/control/rts.h" 20 | 21 | /** 22 | * Create a RTS Control frame 23 | * 24 | * @param rts A fresh libwifi_rts struct 25 | * @param transmitter The transmitter MAC address 26 | * @param receiver The receiver MAC address 27 | * @param duration The duration of the clear-to-send 28 | */ 29 | int libwifi_create_rts(struct libwifi_rts *rts, const unsigned char transmitter[6], 30 | const unsigned char receiver[6], uint16_t duration); 31 | 32 | #endif /* LIBWIFI_GEN_RTS_H */ 33 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/parse/management/reassoc_request.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_PARSE_REASSOCREQ_H 17 | #define LIBWIFI_PARSE_REASSOCREQ_H 18 | 19 | #include "../../core/frame/frame.h" 20 | #include "../../core/frame/management/common.h" 21 | #include "../../core/frame/management/reassoc_request.h" 22 | 23 | /** 24 | * Parse a reassociation request into a libwifi_sta. 25 | * 26 | * @param sta A libwifi_sta 27 | * @param frame A libwifi_frame 28 | * @return 0 if successful, a negative number if not 29 | */ 30 | int libwifi_parse_reassoc_req(struct libwifi_sta *sta, struct libwifi_frame *frame); 31 | 32 | #endif /* LIBWIFI_PARSE_REASSOCREQ_H */ 33 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/core/frame/control/cts.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_CORE_CTS_H 17 | #define LIBWIFI_CORE_CTS_H 18 | 19 | #include "../frame.h" 20 | 21 | /** 22 | * Clear-to-Send Layout 23 | * ─────────────────────────────────── 24 | * ┌─────────────────────────────────┐ 25 | * │ Header │ Bytes: 4 26 | * ├─────────────────────────────────┤ 27 | * │ Receiver Address │ Bytes: 6 28 | * └─────────────────────────────────┘ 29 | */ 30 | struct libwifi_cts { 31 | struct libwifi_ctrl_frame_header frame_header; 32 | unsigned char receiver_addr[6]; 33 | }; 34 | 35 | #endif /* LIBWIFI_CORE_CTS_H */ 36 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/gen/misc/radiotap.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_GEN_RADIOTAP_H 17 | #define LIBWIFI_GEN_RADIOTAP_H 18 | 19 | #include "../../core/misc/radiotap.h" 20 | #include 21 | 22 | /* 23 | * Generate a customised radiotap header based on the input provided in info. 24 | * 25 | * @param info A libwifi_radiotap_info struct with desired radiotap data. 26 | * @param radiotap_header Buffer to write the radiotap header into. 27 | * @return Length of the generated radiotap header. 28 | */ 29 | size_t libwifi_create_radiotap(struct libwifi_radiotap_info *info, char *radiotap_header); 30 | 31 | #endif /* LIBWIFI_GEN_RADIOTAP_H */ 32 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/parse/management/beacon.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_PARSE_BEACON_H 17 | #define LIBWIFI_PARSE_BEACON_H 18 | 19 | #include 20 | #include 21 | 22 | #include "../../core/frame/frame.h" 23 | #include "../../core/frame/management/common.h" 24 | #include "../../core/misc/security.h" 25 | 26 | /** 27 | * Parse useful properties from a beacon frame into a libwifi_bss. 28 | * 29 | * @param bss A libwifi_bss 30 | * @param frame A libwifi_frame 31 | * @return 0 if successful, a negative number if not. 32 | */ 33 | int libwifi_parse_beacon(struct libwifi_bss *bss, struct libwifi_frame *frame); 34 | 35 | #endif /* LIBWIFI_PARSE_BEACON_H */ 36 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/parse/management/probe_response.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_PARSE_PROBERESP_H 17 | #define LIBWIFI_PARSE_PROBERESP_H 18 | 19 | #include 20 | #include 21 | 22 | #include "../../core/frame/frame.h" 23 | #include "../../core/frame/management/common.h" 24 | #include "../../core/misc/security.h" 25 | 26 | /** 27 | * Parse a probe response frame into a libwifi_bss. 28 | * 29 | * @param bss A libwifi_bss 30 | * @param frame A libwifi_frame 31 | * @return 0 if successful, a negative number if not. 32 | */ 33 | int libwifi_parse_probe_resp(struct libwifi_bss *bss, struct libwifi_frame *frame); 34 | 35 | #endif /* LIBWIFI_PARSE_PROBERESP_H */ 36 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/parse/management/assoc_response.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_PARSE_ASSOCRESP_H 17 | #define LIBWIFI_PARSE_ASSOCRESP_H 18 | 19 | #include 20 | #include 21 | 22 | #include "../../core/frame/frame.h" 23 | #include "../../core/frame/management/common.h" 24 | #include "../../core/misc/security.h" 25 | 26 | /** 27 | * Parse an association response frame into a libwifi_bss. 28 | * 29 | * @param bss A libwifi_bss 30 | * @param frame A libwifi_frame 31 | * @return 0 if successful, a negative number if not. 32 | */ 33 | int libwifi_parse_assoc_resp(struct libwifi_bss *bss, struct libwifi_frame *frame); 34 | 35 | #endif /* LIBWIFI_PARSE_ASSOCRESP_H */ 36 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/parse/management/reassoc_response.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_PARSE_REASSOCRESP_H 17 | #define LIBWIFI_PARSE_REASSOCRESP_H 18 | 19 | #include 20 | #include 21 | 22 | #include "../../core/frame/frame.h" 23 | #include "../../core/frame/management/common.h" 24 | #include "../../core/misc/security.h" 25 | 26 | /** 27 | * Parse a reassociation response frame into a libwifi_bss. 28 | * 29 | * @param bss A libwifi_bss 30 | * @param frame A libwifi_frame 31 | * @return 0 if successful, a negative number if not. 32 | */ 33 | int libwifi_parse_reassoc_resp(struct libwifi_bss *bss, struct libwifi_frame *frame); 34 | 35 | #endif /* LIBWIFI_PARSE_REASSOCRESP_H */ 36 | -------------------------------------------------------------------------------- /src/vendors.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "vendors.h" 5 | 6 | 7 | static const char *vendor_string[] = 8 | { 9 | "Generic", 10 | "Vodafone", 11 | "Fastweb", 12 | "TP-Link", 13 | "TIM", 14 | "D-Link", 15 | "Skywifi", 16 | "Wind", 17 | "Linkem", 18 | "Huawei", 19 | "Netgear", 20 | "Tiscali", 21 | "FritzBox", 22 | "Netis" 23 | }; 24 | 25 | 26 | static void to_lowercase(char *input, char *output) { 27 | for (int i = 0; i < strlen(input); i++) { 28 | output[i] = tolower(input[i]); 29 | } 30 | output[strlen(input)] = '\0'; 31 | } 32 | 33 | 34 | vendors_t getVendor(char *ssid) 35 | { 36 | if( ssid == NULL ) 37 | { 38 | return GENERIC; 39 | } 40 | 41 | char ssid_lower[34] = { 0 }; 42 | char temp_lower[34] = { 0 }; 43 | to_lowercase((char *)ssid, (char *)&ssid_lower); 44 | for(uint8_t i = 0; i < sizeof(vendor_string)/sizeof(vendor_string[0]); i++ ) 45 | { 46 | to_lowercase((char *)vendor_string[i], (char *)&temp_lower); 47 | if( strstr((char *)&ssid_lower, (char *)&temp_lower) != NULL ) 48 | { 49 | return (vendors_t)i; 50 | } 51 | } 52 | return GENERIC; 53 | } 54 | 55 | 56 | const char * vendorToString(vendors_t vendor) 57 | { 58 | return vendor_string[vendor]; 59 | } -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/core/frame/management/probe_request.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_CORE_PROBEREQ_H 17 | #define LIBWIFI_CORE_PROBEREQ_H 18 | 19 | #include "../frame.h" 20 | #include "../tag.h" 21 | #include 22 | 23 | /** 24 | * Probe Request Layout 25 | * ────────────────────────── 26 | * ┌──────────────────────────┐ 27 | * │ Header │ Bytes: 24 28 | * ├──────────────────────────┤ 29 | * │ Tagged Parameters │ Bytes: Variable 30 | * └──────────────────────────┘ 31 | */ 32 | 33 | struct libwifi_probe_req { 34 | struct libwifi_mgmt_unordered_frame_header frame_header; 35 | struct libwifi_tagged_parameters tags; 36 | } __attribute__((packed)); 37 | 38 | #endif /* LIBWIFI_CORE_PROBEREQ_H */ 39 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/gen/management/atim.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #include "atim.h" 17 | 18 | #include 19 | #include 20 | 21 | int libwifi_create_atim(struct libwifi_atim *atim, 22 | const unsigned char transmitter[6], 23 | const unsigned char receiver[6], 24 | const unsigned char address3[6]) { 25 | memset(atim, 0, sizeof(struct libwifi_atim)); 26 | 27 | atim->frame_header.frame_control.type = TYPE_MANAGEMENT; 28 | atim->frame_header.frame_control.subtype = SUBTYPE_ATIM; 29 | memcpy(&atim->frame_header.addr1, transmitter, 6); 30 | memcpy(&atim->frame_header.addr2, receiver, 6); 31 | memcpy(&atim->frame_header.addr3, address3, 6); 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/core/frame/control/rts.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_CORE_RTS_H 17 | #define LIBWIFI_CORE_RTS_H 18 | 19 | #include "../frame.h" 20 | 21 | /** 22 | * Request-to-Send Layout 23 | * ─────────────────────────────────── 24 | * ┌─────────────────────────────────┐ 25 | * │ Header │ Bytes: 4 26 | * ├─────────────────────────────────┤ 27 | * │ Receiver Address │ Bytes: 6 28 | * ├─────────────────────────────────┤ 29 | * │ Transmitter Address │ Bytes: 4 30 | * └─────────────────────────────────┘ 31 | */ 32 | struct libwifi_rts { 33 | struct libwifi_ctrl_frame_header frame_header; 34 | unsigned char receiver_addr[6]; 35 | unsigned char transmitter_addr[6]; 36 | }; 37 | 38 | #endif /* LIBWIFI_CORE_RTS_H */ 39 | -------------------------------------------------------------------------------- /platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [platformio] 12 | default_envs = esp32s3 13 | 14 | [common] 15 | platform = espressif32@^6.5.0 16 | framework = espidf 17 | monitor_speed = 115200 18 | board_build.partitions = partition.csv 19 | extra_scripts = scripts/custom_tasks.py 20 | build_flags = 21 | -D APP_VERSION=\"1.0.0\" 22 | 23 | 24 | [env:esp32] 25 | extends = common 26 | board = esp32dev 27 | build_type = release 28 | 29 | 30 | [env:esp32s2] 31 | extends = common 32 | board = esp32-s2-saola-1 33 | 34 | 35 | [env:esp32s3] 36 | extends = common 37 | board = esp32-s3-devkitc-1 38 | build_flags = 39 | ${common.build_flags} 40 | -D ARDUINO_USB_CDC_ON_BOOT=1 41 | 42 | 43 | [env:esp32c3] 44 | extends = common 45 | board = esp32-c3-devkitm-1 46 | build_flags = 47 | ${common.build_flags} 48 | -zmuldefs 49 | 50 | 51 | [env:esp32c6] 52 | extends = common 53 | board = esp32-c6-devkitc-1 54 | board_upload.flash_size = 4MB 55 | build_flags = 56 | ${common.build_flags} 57 | -zmuldefs 58 | -D ARDUINO_USB_CDC_ON_BOOT=1 -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/gen/management/atim.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_GEN_ATIM_H 17 | #define LIBWIFI_GEN_ATIM_H 18 | 19 | #include "../../core/frame/management/atim.h" 20 | 21 | /** 22 | * Generate a populated ATIM frame. 23 | * 24 | * @param atim A new libwifi_atim struct 25 | * @param transmitter The transmitter address, aka address 1 26 | * @param receiver The receiver address, aka address 2 27 | * @param address3 The address 3 frame value, typically the BSSID 28 | * @return Zero on success, or negative error 29 | */ 30 | int libwifi_create_atim(struct libwifi_atim *atim, 31 | const unsigned char transmitter[6], 32 | const unsigned char receiver[6], 33 | const unsigned char address3[6]); 34 | 35 | #endif /* LIBWIFI_GEN_ATIM_H */ 36 | -------------------------------------------------------------------------------- /include/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef _UTILS_H 2 | #define _UTILS_H 3 | 4 | #include 5 | #include "libwifi.h" 6 | #include "wifi_attacks.h" 7 | 8 | 9 | /** 10 | * @brief Check if a MAC Address is broadcast 11 | * 12 | * @param mac 13 | * @return true 14 | * @return false 15 | */ 16 | bool isMacBroadcast(const uint8_t *mac); 17 | 18 | 19 | /** 20 | * @brief Check if a MAC Address is Zero 21 | * 22 | * @param mac 23 | * @return true 24 | * @return false 25 | */ 26 | bool isMacZero(uint8_t *mac); 27 | 28 | 29 | /** 30 | * @brief Print packet bytes 31 | * 32 | * @param data 33 | * @param len 34 | */ 35 | void print_packet(uint8_t *data, size_t len); 36 | 37 | 38 | /** 39 | * @brief Print buffer data 40 | * 41 | * @param buffer 42 | * @param len 43 | */ 44 | void print_buffer(uint8_t *buffer, size_t len); 45 | 46 | 47 | /** 48 | * @brief Print handshake information 49 | * 50 | * @param handshake 51 | */ 52 | void print_handshake(handshake_info_t *handshake); 53 | 54 | 55 | /** 56 | * @brief Dump wifi auth data into buffer 57 | * 58 | * @param auth_data 59 | * @param buffer 60 | * @param buffer_len 61 | * @return size_t 62 | */ 63 | size_t libwifi_dump_wpa_auth_data(struct libwifi_wpa_auth_data *auth_data, uint8_t *buffer, size_t buffer_len); 64 | 65 | 66 | /** 67 | * @brief Get the Next Channel 68 | * 69 | * @param current_channel 70 | * @return uint8_t 71 | */ 72 | uint8_t getNextChannel(uint8_t current_channel); 73 | 74 | 75 | #endif -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/parse/misc/radiotap.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_PARSE_RADIOTAP_H 17 | #define LIBWIFI_PARSE_RADIOTAP_H 18 | 19 | #include "../../core/misc/radiotap.h" 20 | #include 21 | #include 22 | 23 | /** 24 | * Parse the radiotap information out of a raw frame into a 25 | * libwifi_radiotap_info. 26 | * 27 | * @param info A libwifi_radiotap_info 28 | * @param frame A raw 802.11 frame 29 | * @param frame_len Length of the given 802.11 frame 30 | * @returns Negative errno on error, 0 on success 31 | */ 32 | int libwifi_parse_radiotap_info(struct libwifi_radiotap_info *info, const unsigned char *frame, size_t frame_len); 33 | 34 | /** 35 | * Retrieve the signal strength from a raw frame via radiotap header. 36 | * 37 | * @param frame A raw 802.11 frame 38 | * @return signal strength in dBm 39 | */ 40 | int8_t libwifi_parse_radiotap_rssi(const unsigned char *frame); 41 | 42 | #endif /* LIBWIFI_PARSE_RADIOTAP_H */ 43 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/core/core.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #include "core.h" 17 | #include 18 | #include 19 | #include 20 | 21 | /** 22 | * Random MAC addresses, achieved by obtaining 6 bytes of /dev/urandom via getrandom() 23 | */ 24 | void libwifi_random_mac(unsigned char buf[6], unsigned char prefix[3]) { 25 | memset(buf, 0, 6); 26 | if (prefix != NULL) { 27 | memcpy(buf, prefix, 3); 28 | #if __APPLE__ 29 | arc4random_buf(buf + 3, 3); 30 | #else 31 | getrandom(buf + 3, 3, 0); 32 | #endif /* __APPLE__ */ 33 | } else { 34 | #if __APPLE__ 35 | arc4random_buf(buf, 6); 36 | #else 37 | getrandom(buf, 6, 0); 38 | #endif /* __APPLE__ */ 39 | } 40 | } 41 | 42 | /** 43 | * Dummy linker test function 44 | */ 45 | void libwifi_dummy(void) { 46 | return; 47 | } 48 | 49 | /** 50 | * Version 51 | */ 52 | const char *libwifi_get_version(void) { 53 | return LIBWIFI_VERSION; 54 | } 55 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/gen/management/common.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_GEN_COMMON_H 17 | #define LIBWIFI_GEN_COMMON_H 18 | 19 | /** 20 | * A sane default for an AP-side capabilities information field. 21 | * 22 | * 0x0001 = Transmitter is an AP 23 | */ 24 | #define LIBWIFI_DEFAULT_AP_CAPABS 0x0001 25 | 26 | /** 27 | * A sane default for an STA-side capabilities information field. 28 | * 29 | * 0x0000 = None 30 | */ 31 | #define LIBWIFI_DEFAULT_STA_CAPABS 0x0000 32 | 33 | /** 34 | * A sane default for the listen_interval field. 35 | * 36 | * 0x0001 = 1 Beacon Interval 37 | */ 38 | #define LIBWIFI_DEFAULT_LISTEN_INTERVAL 0x0001 39 | 40 | /** 41 | * A sane default for a beacon_interval field. 42 | * 43 | * 0x0064 = 0.1024 Seconds 44 | */ 45 | #define LIBWIFI_DEFAULT_BEACON_INTERVAL 0x0064 46 | 47 | /** 48 | * A sane default for the supported rates frame field. 49 | * 50 | * 1, 2, 5.5, 11, 18, 24, 36, 54 Mbit/s 51 | */ 52 | #define LIBWIFI_DEFAULT_SUPP_RATES "\x82\x84\x8b\x96\x24\x30\x48\x6c" 53 | 54 | #endif /* LIBWIFI_GEN_COMMON_H */ 55 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/parse/data/data.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #include "data.h" 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | int libwifi_parse_data(struct libwifi_data *data, struct libwifi_frame *frame) { 23 | if (frame->frame_control.type != TYPE_DATA) { 24 | return -EINVAL; 25 | } 26 | 27 | if (frame->flags & LIBWIFI_FLAGS_IS_QOS) { 28 | memcpy(data->receiver, frame->header.data_qos.addr1, 6); 29 | memcpy(data->transmitter, frame->header.data_qos.addr2, 6); 30 | } else { 31 | memcpy(data->receiver, frame->header.data.addr1, 6); 32 | memcpy(data->transmitter, frame->header.data.addr2, 6); 33 | } 34 | 35 | data->body_len = frame->len - frame->header_len; 36 | 37 | data->body = malloc(data->body_len); 38 | if (data->body == NULL) { 39 | return -ENOMEM; 40 | } 41 | memcpy(data->body, frame->body, data->body_len); 42 | 43 | return 0; 44 | } 45 | 46 | void libwifi_free_data(struct libwifi_data *data) { 47 | free(data->body); 48 | } 49 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/core/core.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_CORE_H 17 | #define LIBWIFI_CORE_H 18 | 19 | #ifndef LIBWIFI_VERSION 20 | #define LIBWIFI_VERSION "UNSET_VERSION" 21 | #endif 22 | 23 | /** 24 | * Commonly used fixed fields 25 | */ 26 | #define LIBWIFI_BCAST_MAC "\xFF\xFF\xFF\xFF\xFF\xFF" 27 | #define LIBWIFI_ZERO_MAC "\x00\x00\x00\x00\x00\x00" 28 | 29 | /** 30 | * Helpers for MAC Addresses 31 | */ 32 | #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] 33 | #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x" 34 | 35 | /** 36 | * Function to randomly generate a MAC address. 37 | * 38 | * @param buf A buffer for the generated MAC to be written to 39 | * @param prefix An optional OUI prefix 40 | */ 41 | void libwifi_random_mac(unsigned char buf[6], unsigned char prefix[3]); 42 | 43 | /** 44 | * Dummy function for linker testing purposes. 45 | */ 46 | void libwifi_dummy(void); 47 | 48 | /** 49 | * Obtain the version of libwifi. 50 | * 51 | * @return The version of the installed libwifi. 52 | */ 53 | const char *libwifi_get_version(void); 54 | 55 | #endif /* LIBWIFI_CORE_H */ 56 | -------------------------------------------------------------------------------- /lib/libwifi/utils/src/helpers.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] 5 | #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x" 6 | 7 | static const uint8_t radiotap_data[] = { 8 | 0x00, 9 | 0x00, // <-- radiotap version (ignore this) 10 | 0x18, 11 | 0x00, // <-- number of bytes in our header (count the number of "0x"s) 12 | 13 | /** 14 | * The next field is a bitmap of which options we are including. 15 | * The full list of which field is which option is in ieee80211_radiotap.h, 16 | * but I've chosen to include: 17 | * 0x00 0x01: timestamp 18 | * 0x00 0x02: flags 19 | * 0x00 0x03: rate 20 | * 0x00 0x04: channel 21 | * 0x80 0x00: tx flags (seems silly to have this AND flags, but oh well) 22 | */ 23 | 0x0f, 24 | 0x80, 25 | 0x00, 26 | 0x00, 27 | 28 | 0x00, 29 | 0x00, 30 | 0x00, 31 | 0x00, 32 | 0x00, 33 | 0x00, 34 | 0x00, 35 | 0x00, // <-- timestamp 36 | 37 | /** 38 | * This is the first set of flags, and we've set the bit corresponding to 39 | * IEEE80211_RADIOTAP_F_FCS, meaning we want the card to add a FCS at the 40 | * end of our buffer for us. 41 | */ 42 | 0x10, 43 | 44 | 0x00, // <-- rate 45 | 0x00, 46 | 0x00, 47 | 0x00, 48 | 0x00, // <-- channel 49 | 50 | /** 51 | * This is the second set of flags, specifically related to transmissions. 52 | * The bit we've set is IEEE80211_RADIOTAP_F_TX_NOACK, which means the card 53 | * won't wait for an ACK for this frame, and that it won't retry if it 54 | * doesn't get one. 55 | */ 56 | 0x08, 57 | 0x00, 58 | }; 59 | 60 | void hexdump(void *data, size_t size); 61 | -------------------------------------------------------------------------------- /lib/libwifi/test/src/timing_ad_tests.c: -------------------------------------------------------------------------------- 1 | #include "../../src/libwifi.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #define BCAST_MAC "\xff\xff\xff\xff\xff\xff" 8 | #define TO_MAC "\x00\x20\x91\xAA\xBB\xCC" 9 | const unsigned char to[] = TO_MAC; 10 | const unsigned char bcast[] = BCAST_MAC; 11 | 12 | int test_timing_ad_gen_full() { 13 | struct libwifi_timing_advert time_ad = {0}; 14 | struct libwifi_timing_advert_fields ad_fields = {0}; 15 | 16 | ad_fields.timing_capabilities = 2; 17 | memcpy(ad_fields.time_error, "\xCC\xCC\xCC\xCC\xCC", 5); 18 | memcpy(ad_fields.time_update, "\xBB", 1); 19 | memcpy(ad_fields.time_value, 20 | "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA", 10); 21 | 22 | int ret = libwifi_create_timing_advert(&time_ad, bcast, to, to, &ad_fields, "GB", -56, -56, -30, -20); 23 | if (ret != 0) { 24 | fprintf(stderr, "Failed to create timing advert\n"); 25 | return ret; 26 | } 27 | 28 | unsigned char *buf = NULL; 29 | size_t buf_len = libwifi_get_timing_advert_length(&time_ad); 30 | buf = malloc(buf_len); 31 | if (buf == NULL) { 32 | fprintf(stderr, "Failed to create buffer\n"); 33 | return -1; 34 | } 35 | printf("buf_len: %zu\n", buf_len); 36 | 37 | ret = libwifi_dump_timing_advert(&time_ad, buf, buf_len); 38 | if (ret < 0) { 39 | fprintf(stderr, "Failed to dump advert"); 40 | return ret; 41 | } 42 | 43 | return 0; 44 | } 45 | 46 | int main(int argc, char **argv) { 47 | if (argc < 2) { 48 | printf("Specify test\n"); 49 | return -1; 50 | } 51 | 52 | if (strcmp(argv[1], "--timing_ad-gen-full") == 0) { 53 | return test_timing_ad_gen_full(); 54 | } 55 | 56 | return -1; 57 | } 58 | -------------------------------------------------------------------------------- /include/web/loader.h: -------------------------------------------------------------------------------- 1 | 2 | const char loader_html[] = 3 | "\n" 4 | "\n" 5 | "\n" 6 | " \n" 7 | " \n" 8 | " \n" 48 | "\n" 49 | "\n" 50 | "
\n" 51 | "\t\n" 53 | "\n" 54 | ""; -------------------------------------------------------------------------------- /src/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "freertos/FreeRTOS.h" 3 | #include "freertos/task.h" 4 | #include "esp_task_wdt.h" 5 | #include "esp_log.h" 6 | #include "nvs_flash.h" 7 | #include "server.h" 8 | #include "admin_server.h" 9 | #include "wifiMng.h" 10 | #include "dns.h" 11 | #include "passwordMng.h" 12 | 13 | 14 | /** 15 | * @brief Block system when an unrecoverable error accurs. 16 | * 17 | */ 18 | static void fatal_error_handler(void) 19 | { 20 | while(true) 21 | { 22 | ESP_LOGE("FATAL_ERROR:", "Fatal error occurs, system is blocked."); 23 | vTaskDelay(pdMS_TO_TICKS(5000)); 24 | } 25 | } 26 | 27 | 28 | void app_main() 29 | { 30 | esp_err_t ret = ESP_OK; 31 | 32 | /* Initialize NVS */ 33 | ret = nvs_flash_init(); 34 | if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { 35 | ESP_ERROR_CHECK(nvs_flash_erase()); 36 | ret = nvs_flash_init(); 37 | } 38 | ESP_ERROR_CHECK(ret); 39 | 40 | /* Config wdt */ 41 | const esp_task_wdt_config_t wdt_conf = { 42 | .idle_core_mask = 0x3, 43 | .timeout_ms = 10000, 44 | .trigger_panic = false 45 | }; 46 | /* Deinit first bugfix for S3 */ 47 | esp_task_wdt_deinit(); 48 | esp_task_wdt_init(&wdt_conf); 49 | 50 | /* Init password manager */ 51 | if(password_manager_init()) 52 | { 53 | fatal_error_handler(); 54 | } 55 | 56 | /* Init wifi */ 57 | if(wifi_init()) 58 | { 59 | fatal_error_handler(); 60 | } 61 | 62 | /* Start wifi AP */ 63 | wifi_start_softap(); 64 | 65 | /* Start dns server */ 66 | dns_server_start(); 67 | 68 | /* Start admin http server */ 69 | http_admin_server_start(); 70 | } -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/core/misc/byteswap.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_CORE_BYTESWAP_H 17 | #define LIBWIFI_CORE_BYTESWAP_H 18 | 19 | #if __APPLE__ 20 | #include 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 41 | #include "byteswap.h" 42 | 43 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 44 | #define BYTESWAP16(x) x 45 | #define BYTESWAP32(x) x 46 | #define BYTESWAP64(x) x 47 | #else 48 | #define BYTESWAP16(x) (__bswap_16(x)) 49 | #define BYTESWAP32(x) (__bswap_32(x)) 50 | #define BYTESWAP64(x) (__bswap_32(x)) 51 | #endif /* __BYTE_ORDER__ */ 52 | #endif /* __APPLE__ */ 53 | 54 | #endif /* LIBWIFI_CORE_BYTESWAP_H */ 55 | -------------------------------------------------------------------------------- /performance.txt: -------------------------------------------------------------------------------- 1 | Suggerimenti per migliorare le prestazioni 2 | Buffer RX e TX 3 | 4 | Aumenta il numero di buffer RX e TX per gestire meglio i pacchetti: 5 | 6 | CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM=16 7 | CONFIG_ESP_WIFI_DYNAMIC_RX_BUFFER_NUM=64 8 | CONFIG_ESP_WIFI_DYNAMIC_TX_BUFFER_NUM=64 9 | 10 | Supporto AMPDU 11 | 12 | Abilita e aumenta la finestra AMPDU per migliorare il throughput: 13 | 14 | CONFIG_ESP_WIFI_AMPDU_TX_ENABLED=y 15 | CONFIG_ESP_WIFI_TX_BA_WIN=16 16 | CONFIG_ESP_WIFI_AMPDU_RX_ENABLED=y 17 | CONFIG_ESP_WIFI_RX_BA_WIN=16 18 | 19 | Ottimizzazioni di memoria (IRAM e DRAM) 20 | 21 | Ottimizza l'allocazione di memoria per ridurre la latenza: 22 | 23 | CONFIG_ESP_WIFI_IRAM_OPT=y 24 | CONFIG_ESP_WIFI_RX_IRAM_OPT=y 25 | CONFIG_ESP_WIFI_DYNAMIC_TX_BUFFER=y 26 | CONFIG_ESP_WIFI_TASK_PINNED_TO_CORE_0=y 27 | 28 | Sicurezza 29 | 30 | WPA3 può introdurre overhead. Se non necessario, considera di utilizzare WPA2: 31 | 32 | CONFIG_ESP_WIFI_ENABLE_WPA3_SAE=n 33 | CONFIG_ESP_WIFI_ENABLE_WPA3_OWE_STA=n 34 | 35 | Beacon SoftAP 36 | 37 | Imposta una lunghezza massima del beacon per una maggiore stabilità con il SoftAP: 38 | 39 | CONFIG_ESP_WIFI_SOFTAP_BEACON_MAX_LEN=1024 40 | 41 | Configurazioni opzionali 42 | 43 | Se non stai utilizzando la modalità a basso consumo (Power Management), disabilitala: 44 | 45 | CONFIG_ESP_WIFI_STA_DISCONNECTED_PM_ENABLE=n 46 | 47 | Disattiva funzionalità non necessarie per ridurre l'overhead: 48 | 49 | CONFIG_ESP_WIFI_CSI_ENABLED=n 50 | CONFIG_ESP_WIFI_MBO_SUPPORT=n 51 | CONFIG_ESP_WIFI_DPP_SUPPORT=n 52 | CONFIG_ESP_WIFI_NAN_ENABLE=n 53 | CONFIG_ESP_WIFI_11R_SUPPORT=n 54 | CONFIG_ESP_WIFI_11KV_SUPPORT=n 55 | 56 | Task prioritization 57 | 58 | Assegna priorità più alta al task Wi-Fi per garantire la gestione rapida dei pacchetti: 59 | 60 | CONFIG_ESP_WIFI_HIGH_PRIORITY_TASK=n -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/core/frame/tag_iterator.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_CORE_TAGITERATOR_H 17 | #define LIBWIFI_CORE_TAGITERATOR_H 18 | 19 | #include "../misc/byteswap.h" 20 | #include "frame.h" 21 | #include "tag.h" 22 | #include 23 | 24 | /** 25 | * A libwifi_tag_iterator is used to iterate through a list of tagged parameters 26 | * in a wifi frame. 27 | */ 28 | struct libwifi_tag_iterator { 29 | struct libwifi_tag_header *tag_header; 30 | const unsigned char *tag_data; 31 | struct libwifi_tag_header *_next_tag_header; 32 | const unsigned char *_frame_end; 33 | }; 34 | 35 | /** 36 | * Initialise a libwifi frame tag iterator. 37 | * 38 | * @param it A libwifi tag iterator struct 39 | * @param tags_start The beginning of a frame's tag data 40 | * @param data_len The total length of the frame's tag data 41 | * @return negative number on error, zero on success 42 | */ 43 | int libwifi_tag_iterator_init(struct libwifi_tag_iterator *it, const void *tags_start, size_t data_len); 44 | 45 | /** 46 | * Iterate towards the next tagged parameter in a libwifi tag iterator. 47 | * 48 | * @param A libwifi tag iterator sturct, after being initalised 49 | * @return The tag number of the next tag 50 | */ 51 | int libwifi_tag_iterator_next(struct libwifi_tag_iterator *it); 52 | 53 | #endif /* LIBWIFI_CORE_TAGITERATOR_H */ 54 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/core/frame/management/assoc_request.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_CORE_ASSOCREQ_H 17 | #define LIBWIFI_CORE_ASSOCREQ_H 18 | 19 | #include "../frame.h" 20 | #include "../tag.h" 21 | #include 22 | 23 | /** 24 | * Association Request Layout 25 | * ───────────────────────────────── 26 | * ┌─────────────────────────────────┐ 27 | * │ Header │ Bytes: 24 28 | * ├─────────────────────────────────┤ 29 | * │ Fixed Parameters │ Bytes: 4 30 | * │┌───────────────────────────────┐│ 31 | * ││ capabilities ││ Bytes: 2 32 | * │├───────────────────────────────┤│ 33 | * ││ listen interval ││ Bytes: 2 34 | * │└───────────────────────────────┘│ 35 | * ├─────────────────────────────────┤ 36 | * │ Tagged Parameters │ Bytes: Variable 37 | * └─────────────────────────────────┘ 38 | */ 39 | 40 | struct libwifi_assoc_req_fixed_parameters { 41 | uint16_t capabilities_information; 42 | uint16_t listen_interval; 43 | } __attribute__((packed)); 44 | 45 | struct libwifi_assoc_req { 46 | struct libwifi_mgmt_unordered_frame_header frame_header; 47 | struct libwifi_assoc_req_fixed_parameters fixed_parameters; 48 | struct libwifi_tagged_parameters tags; 49 | } __attribute__((packed)); 50 | 51 | #endif /* LIBWIFI_CORE_ASSOCREQ_H */ 52 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/core/frame/management/deauthentication.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_CORE_DEAUTH_H 17 | #define LIBWIFI_CORE_DEAUTH_H 18 | 19 | #include "../frame.h" 20 | #include "../tag.h" 21 | #include 22 | 23 | /** 24 | * Deauthentication Layout 25 | * ────────────────────────── 26 | * ┌──────────────────────────┐ 27 | * │ Header │ Bytes: 24 28 | * ├──────────────────────────┤ 29 | * │ Fixed Parameters │ Bytes: 2 30 | * │┌────────────────────────┐│ 31 | * ││ reason code ││ Bytes: 2 32 | * │└────────────────────────┘│ 33 | * ├──────────────────────────┤ 34 | * │ Tagged Parameters │ Bytes: Variable 35 | * └──────────────────────────┘ 36 | */ 37 | 38 | struct libwifi_deauth_fixed_parameters { 39 | uint16_t reason_code; 40 | } __attribute__((packed)); 41 | 42 | struct libwifi_deauth { 43 | struct libwifi_mgmt_unordered_frame_header frame_header; 44 | struct libwifi_deauth_fixed_parameters fixed_parameters; 45 | struct libwifi_tagged_parameters tags; 46 | } __attribute__((packed)); 47 | 48 | struct libwifi_parsed_deauth { 49 | int ordered; 50 | union libwifi_mgmt_frame_header frame_header; 51 | struct libwifi_deauth_fixed_parameters fixed_parameters; 52 | struct libwifi_tagged_parameters tags; 53 | } __attribute__((packed)); 54 | 55 | #endif /* LIBWIFI_CORE_DEAUTH_H */ 56 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/core/frame/management/disassociation.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_CORE_DISASSOC_H 17 | #define LIBWIFI_CORE_DISASSOC_H 18 | 19 | #include "../frame.h" 20 | #include "../tag.h" 21 | #include 22 | 23 | /** 24 | * Disassociation Layout 25 | * ────────────────────────── 26 | * ┌──────────────────────────┐ 27 | * │ Header │ Bytes: 24 28 | * ├──────────────────────────┤ 29 | * │ Fixed Parameters │ Bytes: 2 30 | * │┌────────────────────────┐│ 31 | * ││ reason code ││ Bytes: 2 32 | * │└────────────────────────┘│ 33 | * ├──────────────────────────┤ 34 | * │ Tagged Parameters │ Bytes: Variable 35 | * └──────────────────────────┘ 36 | */ 37 | 38 | struct libwifi_disassoc_fixed_parameters { 39 | uint16_t reason_code; 40 | } __attribute__((packed)); 41 | 42 | struct libwifi_disassoc { 43 | struct libwifi_mgmt_unordered_frame_header frame_header; 44 | struct libwifi_disassoc_fixed_parameters fixed_parameters; 45 | struct libwifi_tagged_parameters tags; 46 | } __attribute__((packed)); 47 | 48 | struct libwifi_parsed_disassoc { 49 | int ordered; 50 | union libwifi_mgmt_frame_header frame_header; 51 | struct libwifi_disassoc_fixed_parameters fixed_parameters; 52 | struct libwifi_tagged_parameters tags; 53 | } __attribute__((packed)); 54 | 55 | #endif /* LIBWIFI_CORE_DISASSOC_H */ 56 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/core/frame/management/beacon.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_CORE_BEACON_H 17 | #define LIBWIFI_CORE_BEACON_H 18 | 19 | #include "../frame.h" 20 | #include "../tag.h" 21 | #include 22 | 23 | /** 24 | * Beacon Layout 25 | * ────────────────────────────── 26 | * ┌──────────────────────────────┐ 27 | * │ Header │ Bytes: 24 28 | * ├──────────────────────────────┤ 29 | * │ Fixed Parameters │ Bytes: 12 30 | * │┌────────────────────────────┐│ 31 | * ││ timestamp ││ Bytes: 4 32 | * │├────────────────────────────┤│ 33 | * ││ interval ││ Bytes: 2 34 | * │├────────────────────────────┤│ 35 | * ││ capabilities ││ Bytes: 2 36 | * │└────────────────────────────┘│ 37 | * ├──────────────────────────────┤ 38 | * │ Tagged Parameters │ Bytes: Variable 39 | * └──────────────────────────────┘ 40 | */ 41 | 42 | struct libwifi_beacon_fixed_parameters { 43 | uint64_t timestamp; 44 | uint16_t beacon_interval; 45 | uint16_t capabilities_information; 46 | } __attribute__((packed)); 47 | 48 | struct libwifi_beacon { 49 | struct libwifi_mgmt_unordered_frame_header frame_header; 50 | struct libwifi_beacon_fixed_parameters fixed_parameters; 51 | struct libwifi_tagged_parameters tags; 52 | } __attribute__((packed)); 53 | 54 | #endif /* LIBWIFI_CORE_BEACON_H */ 55 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/core/frame/crc.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_CORE_CRC_H 17 | #define LIBWIFI_CORE_CRC_H 18 | 19 | #include 20 | #include 21 | 22 | /** 23 | * Calculate the CRC32 sum of a given buffer. 24 | * 25 | * @param message Buffer of data 26 | * @param message_len Length of the data buffer 27 | * @return CRC32 sum of the given buffer 28 | */ 29 | uint32_t libwifi_crc32(const unsigned char *message, int message_len); 30 | 31 | /** 32 | * Calculate the frame checksum for an 802.11 frame. 33 | * 34 | * @param frame An 802.11 frame 35 | * @param frame_len Length of the frame 36 | * @return frame checksum of the frame 37 | */ 38 | uint32_t libwifi_calculate_fcs(const unsigned char *frame, size_t frame_len); 39 | 40 | /** 41 | * Check if the given raw 802.11 frame has a valid FCS. 42 | * 43 | * This function relies on an assumption that the last 4 bytes of the supplied 44 | * frame is the CRC, as stated in the Radiotap specification. 45 | * 46 | * You can check if the frame data has this field by using libwifi_get_wifi_frame() 47 | * and then checking if the libwifi_frame's flags has the LIBWIFI_FLAGS_FCS_PRESENT 48 | * bit set. 49 | * 50 | * @param frame An 802.11 frame with an FCS 51 | * @param frame_len Length of the frame 52 | * @return 1 if verified, 0 if not 53 | */ 54 | int libwifi_frame_verify(void *frame, size_t frame_len); 55 | 56 | #endif /* LIBWIFI_CORE_CRC_H */ 57 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/core/frame/management/probe_response.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_CORE_PROBERESP_H 17 | #define LIBWIFI_CORE_PROBERESP_H 18 | 19 | #include "../frame.h" 20 | #include "../tag.h" 21 | #include 22 | 23 | /** 24 | * Probe Response Layout 25 | * ────────────────────────────── 26 | * ┌──────────────────────────────┐ 27 | * │ Header │ Bytes: 24 28 | * ├──────────────────────────────┤ 29 | * │ Fixed Parameters │ Bytes: 12 30 | * │┌────────────────────────────┐│ 31 | * ││ timestamp ││ Bytes: 4 32 | * │├────────────────────────────┤│ 33 | * ││ interval ││ Bytes: 2 34 | * │├────────────────────────────┤│ 35 | * ││ capabilities ││ Bytes: 2 36 | * │└────────────────────────────┘│ 37 | * ├──────────────────────────────┤ 38 | * │ Tagged Parameters │ Bytes: Variable 39 | * └──────────────────────────────┘ 40 | */ 41 | 42 | struct libwifi_probe_resp_fixed_parameters { 43 | uint64_t timestamp; 44 | uint16_t probe_resp_interval; 45 | uint16_t capabilities_information; 46 | } __attribute__((packed)); 47 | 48 | struct libwifi_probe_resp { 49 | struct libwifi_mgmt_unordered_frame_header frame_header; 50 | struct libwifi_probe_resp_fixed_parameters fixed_parameters; 51 | struct libwifi_tagged_parameters tags; 52 | } __attribute__((packed)); 53 | 54 | #endif /* LIBWIFI_CORE_PROBERESP_H */ 55 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/core/frame/management/authentication.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_CORE_AUTH_H 17 | #define LIBWIFI_CORE_AUTH_H 18 | 19 | #include "../frame.h" 20 | #include "../tag.h" 21 | #include 22 | 23 | /** 24 | * Authentication Layout 25 | * ───────────────────────────────── 26 | * ┌─────────────────────────────────┐ 27 | * │ Header │ Bytes: 24 28 | * ├─────────────────────────────────┤ 29 | * │ Fixed Parameters │ Bytes: 6 30 | * │┌───────────────────────────────┐│ 31 | * ││ algorithm ││ Bytes: 2 32 | * │├───────────────────────────────┤│ 33 | * ││ transaction ││ Bytes: 2 34 | * │├───────────────────────────────┤│ 35 | * ││ status ││ Bytes: 2 36 | * │└───────────────────────────────┘│ 37 | * ├─────────────────────────────────┤ 38 | * │ Tagged Parameters │ Bytes: Variable 39 | * └─────────────────────────────────┘ 40 | */ 41 | 42 | struct libwifi_auth_fixed_parameters { 43 | uint16_t algorithm_number; 44 | uint16_t transaction_sequence; 45 | uint16_t status_code; 46 | } __attribute__((packed)); 47 | 48 | struct libwifi_auth { 49 | struct libwifi_mgmt_unordered_frame_header frame_header; 50 | struct libwifi_auth_fixed_parameters fixed_parameters; 51 | struct libwifi_tagged_parameters tags; 52 | } __attribute__((packed)); 53 | 54 | #endif /* LIBWIFI_CORE_AUTH_H */ 55 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/core/frame/tag_iterator.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #include "tag_iterator.h" 17 | 18 | #include 19 | #include 20 | 21 | int libwifi_tag_iterator_init(struct libwifi_tag_iterator *it, const void *tags_start, size_t data_len) { 22 | if (data_len <= 0) { 23 | return -EINVAL; 24 | } 25 | 26 | it->tag_header = (struct libwifi_tag_header *) tags_start; 27 | it->tag_data = (unsigned char *) tags_start + sizeof(struct libwifi_tag_header); 28 | it->_next_tag_header = (struct libwifi_tag_header *) (it->tag_data + it->tag_header->tag_len); 29 | it->_frame_end = (unsigned char *) (tags_start) + data_len - 1; 30 | 31 | return 0; 32 | } 33 | 34 | int libwifi_tag_iterator_next(struct libwifi_tag_iterator *it) { 35 | unsigned char *next_th = (unsigned char *) it->_next_tag_header; 36 | if (next_th >= it->_frame_end) { 37 | return -1; 38 | } 39 | 40 | it->tag_header = it->_next_tag_header; 41 | if (it->tag_header->tag_len <= 0) { 42 | return -1; 43 | } 44 | 45 | unsigned long bytes_left = (char *) it->_frame_end - (char *) it->tag_header; 46 | if (it->tag_header->tag_len >= bytes_left) { 47 | return -1; 48 | } 49 | 50 | it->tag_data = ((unsigned char *) (it->tag_header)) + sizeof(struct libwifi_tag_header); 51 | it->_next_tag_header = (struct libwifi_tag_header *) (it->tag_data + it->tag_header->tag_len); 52 | 53 | return it->tag_header->tag_num; 54 | } 55 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/core/frame/management/reassoc_request.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_CORE_REASSOCREQ_H 17 | #define LIBWIFI_CORE_REASSOCREQ_H 18 | 19 | #include "../frame.h" 20 | #include "../tag.h" 21 | #include 22 | 23 | /** 24 | * Reassociation Request Layout 25 | * ─────────────────────────────── 26 | * ┌───────────────────────────────┐ 27 | * │ Header │ Bytes: 24 28 | * ├───────────────────────────────┤ 29 | * │ Fixed Parameters │ Bytes: 10 30 | * │┌─────────────────────────────┐│ 31 | * ││ capabilities ││ Bytes: 2 32 | * │├─────────────────────────────┤│ 33 | * ││ interval ││ Bytes: 2 34 | * │├─────────────────────────────┤│ 35 | * ││ current AP address ││ Bytes: 6 36 | * │└─────────────────────────────┘│ 37 | * ├───────────────────────────────┤ 38 | * │ Tagged Parameters │ Bytes: Variable 39 | * └───────────────────────────────┘ 40 | */ 41 | 42 | struct libwifi_reassoc_req_fixed_parameters { 43 | uint16_t capabilities_information; 44 | uint16_t listen_interval; 45 | unsigned char current_ap_address[6]; 46 | } __attribute__((packed)); 47 | 48 | struct libwifi_reassoc_req { 49 | struct libwifi_mgmt_unordered_frame_header frame_header; 50 | struct libwifi_reassoc_req_fixed_parameters fixed_parameters; 51 | struct libwifi_tagged_parameters tags; 52 | } __attribute__((packed)); 53 | 54 | #endif /* LIBWIFI_CORE_REASSOCREQ_H */ 55 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/core/frame/management/assoc_response.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_CORE_ASSOCRESP_H 17 | #define LIBWIFI_CORE_ASSOCRESP_H 18 | 19 | #include "../frame.h" 20 | #include "../tag.h" 21 | #include 22 | 23 | /** 24 | * Association Response Layout 25 | * ───────────────────────────────── 26 | * ┌─────────────────────────────────┐ 27 | * │ Header │ Bytes: 24 28 | * ├─────────────────────────────────┤ 29 | * │ Fixed Parameters │ Bytes: 6 30 | * │┌───────────────────────────────┐│ 31 | * ││ capabilities ││ Bytes: 2 32 | * │├───────────────────────────────┤│ 33 | * ││ status ││ Bytes: 2 34 | * │├───────────────────────────────┤│ 35 | * ││ association id ││ Bytes: 2 36 | * │└───────────────────────────────┘│ 37 | * ├─────────────────────────────────┤ 38 | * │ Tagged Parameters │ Bytes: Variable 39 | * └─────────────────────────────────┘ 40 | */ 41 | 42 | struct libwifi_assoc_resp_fixed_parameters { 43 | uint16_t capabilities_information; 44 | uint16_t status_code; 45 | uint16_t association_id; 46 | } __attribute__((packed)); 47 | 48 | struct libwifi_assoc_resp { 49 | struct libwifi_mgmt_unordered_frame_header frame_header; 50 | struct libwifi_assoc_resp_fixed_parameters fixed_parameters; 51 | struct libwifi_tagged_parameters tags; 52 | } __attribute__((packed)); 53 | 54 | #endif /* LIBWIFI_CORE_ASSOCRESP_H */ 55 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/core/frame/management/reassoc_response.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_CORE_REASSOCRESP_H 17 | #define LIBWIFI_CORE_REASSOCRESP_H 18 | 19 | #include "../frame.h" 20 | #include "../tag.h" 21 | #include 22 | 23 | /** 24 | * Reassociation Response Layout 25 | * ────────────────────────────────── 26 | * ┌──────────────────────────────────┐ 27 | * │ Header │ Bytes: 24 28 | * ├──────────────────────────────────┤ 29 | * │ Fixed Parameters │ Bytes: 6 30 | * │┌────────────────────────────────┐│ 31 | * ││ capabilities ││ Bytes: 2 32 | * │├────────────────────────────────┤│ 33 | * ││ status ││ Bytes: 2 34 | * │├────────────────────────────────┤│ 35 | * ││ association id ││ Bytes: 2 36 | * │└────────────────────────────────┘│ 37 | * ├──────────────────────────────────┤ 38 | * │ Tagged Parameters │ Bytes: Variable 39 | * └──────────────────────────────────┘ 40 | */ 41 | 42 | struct libwifi_reassoc_resp_fixed_parameters { 43 | uint16_t capabilities_information; 44 | uint16_t status_code; 45 | uint16_t association_id; 46 | } __attribute__((packed)); 47 | 48 | struct libwifi_reassoc_resp { 49 | struct libwifi_mgmt_unordered_frame_header frame_header; 50 | struct libwifi_reassoc_resp_fixed_parameters fixed_parameters; 51 | struct libwifi_tagged_parameters tags; 52 | } __attribute__((packed)); 53 | 54 | #endif /* LIBWIFI_CORE_REASSOCRESP_H */ 55 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/core/frame/crc.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #include "crc.h" 17 | #include "../misc/byteswap.h" 18 | 19 | #include 20 | #include 21 | 22 | /* 23 | * Basic CRC32 implementation for getting the frame check sum of 24 | * a supplied message, usually frame data. 25 | */ 26 | uint32_t libwifi_crc32(const unsigned char *message, int message_len) { 27 | int i, j; 28 | unsigned int byte, crc, mask; 29 | i = 0; 30 | crc = 0xFFFFFFFF; 31 | while (i < message_len) { 32 | byte = message[i]; 33 | crc = crc ^ byte; 34 | for (j = 7; j >= 0; j--) { 35 | mask = -(crc & 1); 36 | crc = (crc >> 1) ^ (0xEDB88320 & mask); 37 | } 38 | i = i + 1; 39 | } 40 | return ~crc; 41 | } 42 | 43 | /* 44 | * Specific function for calculating a frame FCS, byteswapped for the 45 | * host endianess. 46 | */ 47 | uint32_t libwifi_calculate_fcs(const unsigned char *frame, size_t frame_len) { 48 | return BYTESWAP32(libwifi_crc32(frame, frame_len)); 49 | } 50 | 51 | /* 52 | * Verify a raw frame containing a FCS at the end to the FCS calculated 53 | * by libwifi. 54 | */ 55 | int libwifi_frame_verify(void *frame, size_t frame_len) { 56 | // A frame with a CRC will have the CRC placed at the end, and is 4 bytes long. 57 | uint32_t oCRC = *((uint32_t *) ((char *) frame + (frame_len - 4))); 58 | uint32_t rCRC = libwifi_calculate_fcs(frame, frame_len); 59 | 60 | if (rCRC == oCRC) { 61 | return 1; 62 | } 63 | 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /scripts/merge_bins.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import shutil 4 | import subprocess 5 | 6 | # Define the PlatformIO build environment (change if needed) 7 | BUILD_ENV = "esp32-s3-n16r8" # Adjust based on your PlatformIO environment 8 | BUILD_DIR = os.path.join(".pio", "build", BUILD_ENV) 9 | 10 | # Path to esptool.exe (modify if stored in a different location) 11 | ESPTOOL_PATH = os.path.join(os.getcwd(), "tools/esptool.exe") 12 | 13 | # Output merged binary path 14 | MERGED_BIN = os.path.join(BUILD_DIR, "release.bin") 15 | 16 | # Locate required binary files 17 | bootloader_bin = os.path.join(BUILD_DIR, "bootloader.bin") 18 | partition_table_bin = os.path.join(BUILD_DIR, "partitions.bin") 19 | 20 | # Automatically find the firmware binary 21 | application_bin = None 22 | for file in os.listdir(BUILD_DIR): 23 | if file.endswith(".bin") and "bootloader" not in file and "partitions" not in file: 24 | application_bin = os.path.join(BUILD_DIR, file) 25 | break 26 | 27 | # Verify that all required binaries exist 28 | if not all(os.path.exists(f) for f in [bootloader_bin, partition_table_bin, application_bin]): 29 | print("❌ Error: One or more binary files are missing! Ensure the build is completed.") 30 | sys.exit(1) 31 | 32 | # Flash memory addresses (check your sdkconfig if using custom values) 33 | bootloader_addr = 0x0 34 | partition_table_addr = 0x8000 35 | application_addr = 0x10000 36 | 37 | try: 38 | print("\n🔄 Merging binaries into release.bin using esptool.exe...\n") 39 | 40 | # Build the merge command 41 | merge_command = [ 42 | ESPTOOL_PATH, "--chip", "esp32s3", "merge_bin", 43 | "-o", MERGED_BIN, 44 | hex(bootloader_addr), bootloader_bin, 45 | hex(partition_table_addr), partition_table_bin, 46 | hex(application_addr), application_bin 47 | ] 48 | 49 | # Execute esptool.exe with the merge command 50 | subprocess.run(merge_command, check=True) 51 | 52 | print("✅ Merge completed successfully!") 53 | 54 | # Copy merged firmware to project root for easy access 55 | shutil.copy(MERGED_BIN, "release.bin") 56 | print("📂 Merged firmware copied to the project root.") 57 | 58 | print("\n✅ Done! You can now flash it using:") 59 | print(f" {ESPTOOL_PATH} --chip esp32s3 write_flash 0x1000 release.bin") 60 | 61 | except subprocess.CalledProcessError as e: 62 | print(f"❌ Error merging binaries: {e}") 63 | sys.exit(1) -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/gen/management/deauthentication.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_GEN_DEAUTH_H 17 | #define LIBWIFI_GEN_DEAUTH_H 18 | 19 | #include 20 | 21 | #include "../../core/frame/management/deauthentication.h" 22 | 23 | /** 24 | * Calculate the length of a given libwifi_deauth 25 | * 26 | * @param deauth A libwifi_deauth 27 | * @return The length of the given deauth 28 | */ 29 | size_t libwifi_get_deauth_length(struct libwifi_deauth *deauth); 30 | 31 | /** 32 | * Generate a populated libwifi deauth. 33 | * 34 | * A generated libwifi deauth can be "dumped" into a buffer for packet injection 35 | * via the libwifi_dump_deauth. 36 | * 37 | * @param deauth A libwifi_deauth 38 | * @param receiver The receiver MAC address, aka address 1 39 | * @param transmitter The source MAC address, aka address 2 40 | * @param address3 The address 3 frame field value, typically the BSSID 41 | * @param reason_code The deauth reason code 42 | * @return Zero on success, or negative error 43 | */ 44 | int libwifi_create_deauth(struct libwifi_deauth *deauth, 45 | const unsigned char receiver[6], 46 | const unsigned char transmitter[6], 47 | const unsigned char address3[6], 48 | uint16_t reason_code); 49 | 50 | /** 51 | * Dump a libwifi_deauth into a raw format for packet injection. 52 | * 53 | * @param deauth A libwifi_deauth 54 | * @param buf The output buffer for the frame data 55 | * @param buf_len The length of the output buffer 56 | * @return The length of the dumped deauth, or negative error 57 | */ 58 | size_t libwifi_dump_deauth(struct libwifi_deauth *deauth, unsigned char *buf, size_t buf_len); 59 | 60 | /** 61 | * Free any memory claimed by a libwifi_deauth back to the system. 62 | * 63 | * @param deauth A libwifi_deauth 64 | */ 65 | void libwifi_free_deauth(struct libwifi_deauth *deauth); 66 | 67 | #endif /* LIBWIFI_GEN_DEAUTH_H */ 68 | -------------------------------------------------------------------------------- /lib/libwifi/test/src/action_tests.c: -------------------------------------------------------------------------------- 1 | #include "../../src/libwifi.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #define BCAST_MAC "\xff\xff\xff\xff\xff\xff" 8 | #define TO_MAC "\x00\x20\x91\xAA\xBB\xCC" 9 | const unsigned char to[] = TO_MAC; 10 | const unsigned char bcast[] = BCAST_MAC; 11 | 12 | int test_action_gen_full() { 13 | struct libwifi_action action = {0}; 14 | 15 | int ret = libwifi_create_action(&action, bcast, to, to, ACTION_HT); 16 | if (ret != 0) { 17 | fprintf(stderr, "Failed to create action: %s\n", strerror(ret)); 18 | return ret; 19 | } 20 | 21 | int action_len = libwifi_get_action_length(&action); 22 | if (action_len <= 0) { 23 | fprintf(stderr, "Invalid action length: %d\n", action_len); 24 | return action_len; 25 | } 26 | 27 | unsigned char *buf = malloc(action_len); 28 | if (buf == NULL) { 29 | fprintf(stderr, "Failed to allocate buffer\n"); 30 | return -1; 31 | } 32 | 33 | int dump_len = libwifi_dump_action(&action, buf, action_len); 34 | if (dump_len <= 0) { 35 | fprintf(stderr, "Failed to dump action\n"); 36 | return ret; 37 | } 38 | 39 | return 0; 40 | } 41 | 42 | int test_action_add_detail() { 43 | struct libwifi_action action = {0}; 44 | 45 | int ret = libwifi_create_action(&action, bcast, to, to, ACTION_HT); 46 | if (ret != 0) { 47 | fprintf(stderr, "Failed to create action: %s\n", strerror(ret)); 48 | return ret; 49 | } 50 | 51 | ret = libwifi_add_action_detail(&action.fixed_parameters.details, (const unsigned char *) "HELLO WORLD", strlen("HELLO WORLD")); 52 | 53 | int action_len = libwifi_get_action_length(&action); 54 | if (action_len <= 0) { 55 | fprintf(stderr, "Invalid action length: %d\n", action_len); 56 | return action_len; 57 | } 58 | 59 | unsigned char *buf = malloc(action_len); 60 | if (buf == NULL) { 61 | fprintf(stderr, "Failed to allocate buffer\n"); 62 | return -1; 63 | } 64 | 65 | int dump_len = libwifi_dump_action(&action, buf, action_len); 66 | if (dump_len <= 0) { 67 | fprintf(stderr, "Failed to dump action\n"); 68 | return ret; 69 | } 70 | 71 | return 0; 72 | } 73 | 74 | int main(int argc, char **argv) { 75 | if (argc < 2) { 76 | printf("Specify test\n"); 77 | return -1; 78 | } 79 | 80 | if (strcmp(argv[1], "--action-gen-full") == 0) { 81 | return test_action_gen_full(); 82 | } else if (strcmp(argv[1], "--action-gen-details") == 0) { 83 | return test_action_add_detail(); 84 | } 85 | 86 | return -1; 87 | } 88 | -------------------------------------------------------------------------------- /include/web/passwords.h: -------------------------------------------------------------------------------- 1 | 2 | const char password_page[] = 3 | "\n" 4 | "\n" 5 | "\n" 6 | " \n" 7 | " \n" 8 | " Password Viewer\n" 9 | " \n" 45 | "\n" 46 | "\n" 47 | "

Saved Passwords

\n" 48 | " \n" 49 | " \n" 50 | " \n" 75 | "\n" 76 | ""; -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/gen/management/disassociation.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_GEN_DISASSOC_H 17 | #define LIBWIFI_GEN_DISASSOC_H 18 | 19 | #include 20 | 21 | #include "../../core/frame/management/disassociation.h" 22 | 23 | /** 24 | * Calculate the length of a given libwifi_disassoc 25 | * 26 | * @param disassoc A libwifi_disassoc 27 | * @return The length of the given disassoc, or negative error 28 | */ 29 | size_t libwifi_get_disassoc_length(struct libwifi_disassoc *disassoc); 30 | 31 | /** 32 | * Generate a populated libwifi disassoc. 33 | * 34 | * A generated libwifi disassoc can be "dumped" into a buffer for packet injection 35 | * via the libwifi_dump_disassoc. 36 | * 37 | * @param disassoc A libwifi_disassoc 38 | * @param receiver The receiver MAC address, aka address 1 39 | * @param transmitter The source MAC address, aka address 2 40 | * @param address3 The address 3 frame field value, typically the BSSID 41 | * @param reason_code The disassoc reason code 42 | * @return Zero on success, or negative error 43 | */ 44 | int libwifi_create_disassoc(struct libwifi_disassoc *disassoc, 45 | const unsigned char receiver[6], 46 | const unsigned char transmitter[6], 47 | const unsigned char address3[6], 48 | uint16_t reason_code); 49 | 50 | /** 51 | * Dump a libwifi_disassoc into a raw format for packet injection. 52 | * 53 | * @param disassoc A libwifi_disassoc 54 | * @param buf The output buffer for the frame data 55 | * @param buf_len The length of the output buffer 56 | * @return The length of the dumped disassoc, or negative error 57 | */ 58 | size_t libwifi_dump_disassoc(struct libwifi_disassoc *disassoc, unsigned char *buf, size_t buf_len); 59 | 60 | /** 61 | * Free any memory claimed by a libwifi_disassoc back to the system. 62 | * 63 | * @param disassoc A libwifi_disassoc 64 | */ 65 | void libwifi_free_disassoc(struct libwifi_disassoc *disassoc); 66 | 67 | #endif /* LIBWIFI_GEN_DISASSOC_H */ 68 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/parse/management/common.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_PARSE_MGMT_COMMON_H 17 | #define LIBWIFI_PARSE_MGMT_COMMON_H 18 | 19 | #include "../../core/frame/management/common.h" 20 | #include "../../core/frame/tag_iterator.h" 21 | #include "../../core/misc/security.h" 22 | 23 | /** 24 | * A helper function to set the SSID of a libwifi_bss, as well as check 25 | * if it is hidden or not. 26 | * 27 | * @param target A libwifi_bss or libwifi_sta 28 | * @param target_type LIBWIFI_BSS or LIBWIFI_STA 29 | * @param ssid The SSID to set 30 | * @param ssid_len The length of the supplied SSID 31 | */ 32 | void libwifi_handle_ssid_tag(void *target, int target_type, const char *ssid, int ssid_len); 33 | 34 | /** 35 | * A helper function to handle the parsing of the RSN IE. 36 | * 37 | * @param bss A libwifi_bss 38 | * @param rsn_data The RSN tag data 39 | * @param rsn_len The length of the RSN tag data 40 | */ 41 | int libwifi_bss_handle_rsn_tag(struct libwifi_bss *bss, const unsigned char *rsn_data, int rsn_len); 42 | 43 | /** 44 | * A helper function to handle the parsing of the Microsoft Vendor IE. 45 | * 46 | * @param bss A libwifi_bss 47 | * @param msft_data The Microsoft vendor tag data 48 | * @param msft_len The length of the Microsoft tag data 49 | */ 50 | int libwifi_bss_handle_msft_tag(struct libwifi_bss *bss, const unsigned char *msft_data, int msft_len); 51 | 52 | /** 53 | * A helper function to iterate through common tags found in a libwifi_bss. 54 | * 55 | * @param bss A libwifi_bss 56 | * @param it A libwifi_tag_iterator 57 | * @return 0 if successful, a negative number if not 58 | */ 59 | int libwifi_bss_tag_parser(struct libwifi_bss *bss, struct libwifi_tag_iterator *it); 60 | 61 | /** 62 | * A helper function to iterate through common tags found in a libwifi_sta. 63 | * 64 | * @param sta A libwifi_sta 65 | * @param it A libwifi_tag_iterator 66 | * @return 0 if successful, a negative number if not 67 | */ 68 | int libwifi_sta_tag_parser(struct libwifi_sta *sta, struct libwifi_tag_iterator *it); 69 | 70 | #endif /* LIBWIFI_PARSE_MGMT_COMMON_H */ 71 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/gen/management/assoc_request.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_GEN_ASSOCREQUEST_H 17 | #define LIBWIFI_GEN_ASSOCREQUEST_H 18 | 19 | #include "../../core/frame/frame.h" 20 | #include "../../core/frame/management/assoc_request.h" 21 | #include "../../core/frame/management/common.h" 22 | 23 | /** 24 | * Create a new association request 25 | * 26 | * @param assoc_req A new libwifi_assoc_req struct 27 | * @param receiver The receiver MAC address 28 | * @param transmitter The transmitter MAC address 29 | * @param address3 The address 3 frame field value, typically the BSSID 30 | * @param ssid The desired BSS SSID 31 | * @param channel The desired channel 32 | * @param Zero on success, or negative error 33 | */ 34 | int libwifi_create_assoc_req(struct libwifi_assoc_req *assoc_req, 35 | const unsigned char receiver[6], 36 | const unsigned char transmitter[6], 37 | const unsigned char address3[6], 38 | const char *ssid, 39 | uint8_t channel); 40 | 41 | /** 42 | * Get the length of a given libwifi_assoc_req 43 | * 44 | * @param assoc_req A libwifi_assoc_req struct 45 | * @return Length of the given libwifi_assoc_req 46 | */ 47 | size_t libwifi_get_assoc_req_length(struct libwifi_assoc_req *assoc_req); 48 | 49 | /** 50 | * Dump a libwifi_assoc_req into a raw format for packet injection. 51 | * 52 | * @param assoc_req A libwifi_assoc_req struct 53 | * @param buf The buffer to dump into 54 | * @param buf_len The length of the supplied buffer 55 | * @param The amount of bytes dumped, or negative error 56 | */ 57 | size_t libwifi_dump_assoc_req(struct libwifi_assoc_req *assoc_req, unsigned char *buf, size_t buf_len); 58 | 59 | 60 | /** 61 | * Free any memory claimed by a libwifi_assoc_req back to the system. 62 | * 63 | * @param assoc_req A libwifi_assoc_req 64 | */ 65 | void libwifi_free_assoc_req(struct libwifi_assoc_req *assoc_req); 66 | 67 | #endif /* LIBWIFI_GEN_ASSOCREQUEST_H */ 68 | -------------------------------------------------------------------------------- /lib/libwifi/test/src/auth_tests.c: -------------------------------------------------------------------------------- 1 | #include "../../src/libwifi.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #define BCAST_MAC "\xff\xff\xff\xff\xff\xff" 8 | #define TO_MAC "\x00\x20\x91\xAA\xBB\xCC" 9 | const unsigned char to[] = TO_MAC; 10 | const unsigned char bcast[] = BCAST_MAC; 11 | 12 | int test_auth_gen_full() { 13 | struct libwifi_auth auth = {0}; 14 | 15 | int ret = libwifi_create_auth(&auth, bcast, to, to, 0, 100, STATUS_SUCCESS); 16 | if (ret != 0) { 17 | fprintf(stderr, "Failed to create auth: %s\n", strerror(ret)); 18 | return ret; 19 | } 20 | 21 | int auth_len = libwifi_get_auth_length(&auth); 22 | if (auth_len <= 0) { 23 | fprintf(stderr, "Invalid auth length: %d\n", auth_len); 24 | return auth_len; 25 | } 26 | 27 | unsigned char *buf = malloc(auth_len); 28 | if (buf == NULL) { 29 | fprintf(stderr, "Failed to allocate buffer\n"); 30 | return -1; 31 | } 32 | 33 | int dump_len = libwifi_dump_auth(&auth, buf, auth_len); 34 | if (dump_len <= 0) { 35 | fprintf(stderr, "Failed to dump auth\n"); 36 | return ret; 37 | } 38 | 39 | return 0; 40 | } 41 | 42 | int test_auth_add_tag() { 43 | struct libwifi_auth auth = {0}; 44 | 45 | int ret = libwifi_create_auth(&auth, bcast, to, to, 0, 100, STATUS_SUCCESS); 46 | if (ret != 0) { 47 | fprintf(stderr, "Failed to create auth: %s\n", strerror(ret)); 48 | return ret; 49 | } 50 | 51 | ret = libwifi_quick_add_tag(&auth.tags, TAG_VENDOR_SPECIFIC, (const unsigned char *) "\x00\x11\x22\xAAHello World", 15); 52 | if (ret != 0) { 53 | fprintf(stderr, "Failed to add auth tagged parameter: %s\n", strerror(ret)); 54 | return ret; 55 | } 56 | 57 | int auth_len = libwifi_get_auth_length(&auth); 58 | if (auth_len <= 0) { 59 | fprintf(stderr, "Invalid auth length: %d\n", auth_len); 60 | return auth_len; 61 | } 62 | 63 | unsigned char *buf = malloc(auth_len); 64 | if (buf == NULL) { 65 | fprintf(stderr, "Failed to allocate buffer\n"); 66 | return -1; 67 | } 68 | 69 | int dump_len = libwifi_dump_auth(&auth, buf, auth_len); 70 | if (dump_len <= 0) { 71 | fprintf(stderr, "Failed to dump auth\n"); 72 | return ret; 73 | } 74 | 75 | return 0; 76 | } 77 | 78 | int main(int argc, char **argv) { 79 | if (argc < 2) { 80 | printf("Specify test\n"); 81 | return -1; 82 | } 83 | 84 | if (strcmp(argv[1], "--auth-gen-full") == 0) { 85 | return test_auth_gen_full(); 86 | } else if (strcmp(argv[1], "--auth-gen-tags") == 0) { 87 | return test_auth_add_tag(); 88 | } 89 | 90 | return -1; 91 | } 92 | -------------------------------------------------------------------------------- /lib/libpcap/src/libpcap.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file pcap_serializer.h 3 | * @author risinek (risinek@gmail.com) 4 | * @date 2021-04-05 5 | * @copyright Copyright (c) 2021 6 | * 7 | * @brief Provides interface to generate PCAP formatted binary from raw frame bytes 8 | */ 9 | #ifndef PCAP_SERIALIZER_H 10 | #define PCAP_SERIALIZER_H 11 | 12 | #include 13 | 14 | /** 15 | * @brief PCAP global header 16 | * 17 | * @see Ref: https://gitlab.com/wireshark/wireshark/-/wikis/Development/LibpcapFileFormat#global-header 18 | */ 19 | typedef struct { 20 | uint32_t magic_number; /* magic number */ 21 | uint16_t version_major; /* major version number */ 22 | uint16_t version_minor; /* minor version number */ 23 | int32_t thiszone; /* GMT to local correction */ 24 | uint32_t sigfigs; /* accuracy of timestamps */ 25 | uint32_t snaplen; /* max length of captured packets, in octets */ 26 | uint32_t network; /* data link type */ 27 | } pcap_global_header_t; 28 | 29 | /** 30 | * @brief PCAP record header 31 | * 32 | * @see Ref: https://gitlab.com/wireshark/wireshark/-/wikis/Development/LibpcapFileFormat 33 | */ 34 | typedef struct { 35 | uint32_t ts_sec; /* timestamp seconds */ 36 | uint32_t ts_usec; /* timestamp microseconds */ 37 | uint32_t incl_len; /* number of octets of packet saved in file */ 38 | uint32_t orig_len; /* actual length of packet */ 39 | } pcap_record_header_t; 40 | 41 | /** 42 | * @brief Prepares new empty buffer for PCAP formatted binary data. 43 | * 44 | * Has always to be called before pcap_serializer_append_frame() 45 | * @return uint8_t* pointer to newly allocated PCAP buffer. 46 | * @return \c NULL initialisation failed 47 | */ 48 | uint8_t *pcap_serializer_init(); 49 | 50 | /** 51 | * @brief Appends new frame to existing PCAP buffer. 52 | * 53 | * Expects pcap_serializer_append_frame() was already called. 54 | * @param buffer frame buffer that should be appended to PCAP 55 | * @param size size of frame buffer 56 | * @param ts_usec timestamp of captured frame in microseconds 57 | */ 58 | void pcap_serializer_append_frame(const uint8_t *buffer, unsigned size, unsigned ts_usec); 59 | 60 | /** 61 | * @brief Frees PCAP buffer and resets all values. 62 | * 63 | * After calling this function, you have to call pcap_serializer_init() to append new frames again. 64 | * 65 | */ 66 | void pcap_serializer_deinit(); 67 | 68 | /** 69 | * @brief Returns size of PCAP buffer in bytes 70 | * 71 | * @return unsigned 72 | */ 73 | unsigned pcap_serializer_get_size(); 74 | 75 | /** 76 | * @brief Return pointer to PCAP buffer 77 | * 78 | * @return uint8_t* 79 | */ 80 | uint8_t *pcap_serializer_get_buffer(); 81 | 82 | #endif -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/parse/management/probe_request.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #include "probe_request.h" 17 | #include "../../core/frame/tag_iterator.h" 18 | #include "common.h" 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | /** 25 | * libwifi_parse_probe_req will parse useful fields into a struct libwifi_sta. 26 | * 27 | * This function also checks to see if the transmitter address can be ANDed 28 | * with 0x02, to determine a likelihood of randomized addresses. 29 | * 30 | * ┌─────────────────────────────────────────────┐ 31 | * │ Header (Ordered or Unordered) │ ── Probe Request Header 32 | * ├─────────────────────────────────────────────┤ 33 | * │ Tagged Parameters │ ── Probe Request Body 34 | * └─────────────────────────────────────────────┘ 35 | */ 36 | int libwifi_parse_probe_req(struct libwifi_sta *sta, struct libwifi_frame *frame) { 37 | memset(sta, 0, sizeof(struct libwifi_sta)); 38 | 39 | if (frame->frame_control.type != TYPE_MANAGEMENT || frame->frame_control.subtype != SUBTYPE_PROBE_REQ) { 40 | return -EINVAL; 41 | } 42 | 43 | if (frame->frame_control.flags.ordered) { 44 | memcpy(sta->transmitter, frame->header.mgmt_ordered.addr2, 6); 45 | memcpy(sta->bssid, frame->header.mgmt_ordered.addr3, 6); 46 | } else { 47 | memcpy(sta->transmitter, frame->header.mgmt_unordered.addr2, 6); 48 | memcpy(sta->bssid, frame->header.mgmt_unordered.addr3, 6); 49 | } 50 | 51 | if (sta->transmitter[0] & 0x02) { 52 | sta->randomized = 1; 53 | } else { 54 | sta->randomized = 0; 55 | } 56 | 57 | sta->tags.length = (frame->len - frame->header_len); 58 | const unsigned char *tagged_params = frame->body; 59 | sta->tags.parameters = malloc(sta->tags.length); 60 | memcpy(sta->tags.parameters, tagged_params, sta->tags.length); 61 | 62 | struct libwifi_tag_iterator it; 63 | if (libwifi_tag_iterator_init(&it, sta->tags.parameters, sta->tags.length) != 0) { 64 | return -EINVAL; 65 | } 66 | 67 | if (libwifi_sta_tag_parser(sta, &it) != 0) { 68 | return -EINVAL; 69 | } 70 | 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /lib/libwifi/test/src/deauth_tests.c: -------------------------------------------------------------------------------- 1 | #include "../../src/libwifi.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #define BCAST_MAC "\xff\xff\xff\xff\xff\xff" 8 | #define TO_MAC "\x00\x20\x91\xAA\xBB\xCC" 9 | const unsigned char to[] = TO_MAC; 10 | const unsigned char bcast[] = BCAST_MAC; 11 | 12 | int test_deauth_gen_full() { 13 | struct libwifi_deauth deauth = {0}; 14 | 15 | int ret = libwifi_create_deauth(&deauth, bcast, to, to, REASON_STA_LEAVING); 16 | if (ret != 0) { 17 | fprintf(stderr, "Failed to create deauth: %s\n", strerror(ret)); 18 | return ret; 19 | } 20 | 21 | int deauth_len = libwifi_get_deauth_length(&deauth); 22 | if (deauth_len <= 0) { 23 | fprintf(stderr, "Invalid deauth length: %d\n", deauth_len); 24 | return deauth_len; 25 | } 26 | 27 | unsigned char *buf = malloc(deauth_len); 28 | if (buf == NULL) { 29 | fprintf(stderr, "Failed to allocate buffer\n"); 30 | return -1; 31 | } 32 | 33 | int dump_len = libwifi_dump_deauth(&deauth, buf, deauth_len); 34 | if (dump_len <= 0) { 35 | fprintf(stderr, "Failed to dump deauth\n"); 36 | return ret; 37 | } 38 | 39 | return 0; 40 | } 41 | 42 | int test_deauth_add_tag() { 43 | struct libwifi_deauth deauth = {0}; 44 | 45 | int ret = libwifi_create_deauth(&deauth, bcast, to, to, REASON_STA_LEAVING); 46 | if (ret != 0) { 47 | fprintf(stderr, "Failed to create deauth: %s\n", strerror(ret)); 48 | return ret; 49 | } 50 | 51 | ret = libwifi_quick_add_tag(&deauth.tags, TAG_VENDOR_SPECIFIC, (const unsigned char *) "\x00\x11\x22\xAAHello World", 15); 52 | if (ret != 0) { 53 | fprintf(stderr, "Failed to add deauth tagged parameter: %s\n", strerror(ret)); 54 | return ret; 55 | } 56 | 57 | int deauth_len = libwifi_get_deauth_length(&deauth); 58 | if (deauth_len <= 0) { 59 | fprintf(stderr, "Invalid deauth length: %d\n", deauth_len); 60 | return deauth_len; 61 | } 62 | 63 | unsigned char *buf = malloc(deauth_len); 64 | if (buf == NULL) { 65 | fprintf(stderr, "Failed to allocate buffer\n"); 66 | return -1; 67 | } 68 | 69 | int dump_len = libwifi_dump_deauth(&deauth, buf, deauth_len); 70 | if (dump_len <= 0) { 71 | fprintf(stderr, "Failed to dump deauth\n"); 72 | return ret; 73 | } 74 | 75 | return 0; 76 | } 77 | 78 | int main(int argc, char **argv) { 79 | if (argc < 2) { 80 | printf("Specify test\n"); 81 | return -1; 82 | } 83 | 84 | if (strcmp(argv[1], "--deauth-gen-full") == 0) { 85 | return test_deauth_gen_full(); 86 | } else if (strcmp(argv[1], "--deauth-gen-tags") == 0) { 87 | return test_deauth_add_tag(); 88 | } 89 | 90 | return -1; 91 | } 92 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/gen/management/probe_request.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_GEN_PROBEREQ_H 17 | #define LIBWIFI_GEN_PROBEREQ_H 18 | 19 | #include 20 | 21 | #include "../../core/frame/management/probe_request.h" 22 | 23 | /** 24 | * Calculate the length of a given libwifi_probe_req 25 | * 26 | * @param probe_req A libwifi_probe_req 27 | * @return The length of the given probe_req, or negative error 28 | */ 29 | size_t libwifi_get_probe_req_length(struct libwifi_probe_req *probe_req); 30 | 31 | /** 32 | * Generate a populated libwifi probe_req. 33 | * 34 | * A generated libwifi probe_req can be "dumped" into a buffer for packet injection 35 | * via the libwifi_dump_probe_req. 36 | * 37 | * @param probe_req A libwifi_probe_req 38 | * @param receiver The receiver MAC address, aka address 1 39 | * @param transmitter The source MAC address, aka address 2 40 | * @param address3 The address 3 frame field value, typically the BSSID 41 | * @param ssid The probe request SSID 42 | * @param channel The probe request channel 43 | * @return Zero on success, or negative error 44 | */ 45 | int libwifi_create_probe_req(struct libwifi_probe_req *probe_req, 46 | const unsigned char receiver[6], 47 | const unsigned char transmitter[6], 48 | const unsigned char address3[6], 49 | const char *ssid, 50 | uint8_t channel); 51 | 52 | /** 53 | * Dump a libwifi_probe_req into a raw format for packet injection. 54 | * 55 | * @param probe_req A libwifi_probe_req 56 | * @param buf The output buffer for the frame data 57 | * @param buf_len The length of the output buffer 58 | * @return The length of the dumped probe_req, or negative error 59 | */ 60 | size_t libwifi_dump_probe_req(struct libwifi_probe_req *probe_req, unsigned char *buf, size_t buf_len); 61 | 62 | /** 63 | * Free any memory claimed by a libwifi_probe_req back to the system. 64 | * 65 | * @param probe_req A libwifi_probe_req 66 | */ 67 | void libwifi_free_probe_req(struct libwifi_probe_req *probe_req); 68 | 69 | #endif /* LIBWIFI_GEN_PROBEREQ_H */ 70 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/gen/management/authentication.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_GEN_AUTH_H 17 | #define LIBWIFI_GEN_AUTH_H 18 | 19 | #include 20 | 21 | #include "../../core/frame/management/authentication.h" 22 | 23 | /** 24 | * Calculate the length of a given libwifi_auth 25 | * 26 | * @param auth A libwifi_auth 27 | * @return The length of the given auth 28 | */ 29 | size_t libwifi_get_auth_length(struct libwifi_auth *auth); 30 | 31 | /** 32 | * Generate a populated libwifi auth. 33 | * 34 | * A generated libwifi auth can be "dumped" into a buffer for packet injection 35 | * via the libwifi_dump_auth. 36 | * 37 | * @param auth A libwifi_auth 38 | * @param receiver The receiver MAC address, aka address 1 39 | * @param transmitter The source MAC address, aka address 2 40 | * @param address3 The address 3 frame field value, typically the BSSID 41 | * @param algorithm_number Algorithm type to use, as defined in the IEEE802.11 spec 42 | * @param transaction_sequence Transaction sequence value to use 43 | * @param status_code Status code to use, as defined in the IEEE802.11 spec 44 | * @return Zero on success, or negative error 45 | */ 46 | int libwifi_create_auth(struct libwifi_auth *auth, 47 | const unsigned char receiver[6], 48 | const unsigned char transmitter[6], 49 | const unsigned char address3[6], 50 | uint16_t algorithm_number, 51 | uint16_t transaction_sequence, 52 | uint16_t status_code); 53 | 54 | /** 55 | * Dump a libwifi_auth into a raw format for packet injection. 56 | * 57 | * @param auth A libwifi_auth 58 | * @param buf The output buffer for the frame data 59 | * @param buf_len The length of the output buffer 60 | * @return The length of the dumped auth, or negative error 61 | */ 62 | size_t libwifi_dump_auth(struct libwifi_auth *auth, unsigned char *buf, size_t buf_len); 63 | 64 | /** 65 | * Free any memory claimed by a libwifi_auth back to the system. 66 | * 67 | * @param auth A libwifi_auth 68 | */ 69 | void libwifi_free_auth(struct libwifi_auth *auth); 70 | 71 | #endif /* LIBWIFI_GEN_AUTH_H */ 72 | -------------------------------------------------------------------------------- /lib/libwifi/test/src/disassoc_tests.c: -------------------------------------------------------------------------------- 1 | #include "../../src/libwifi.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #define BCAST_MAC "\xff\xff\xff\xff\xff\xff" 8 | #define TO_MAC "\x00\x20\x91\xAA\xBB\xCC" 9 | const unsigned char to[] = TO_MAC; 10 | const unsigned char bcast[] = BCAST_MAC; 11 | 12 | int test_disassoc_gen_full() { 13 | struct libwifi_disassoc disassoc = {0}; 14 | 15 | int ret = libwifi_create_disassoc(&disassoc, bcast, to, to, REASON_STA_LEAVING); 16 | if (ret != 0) { 17 | fprintf(stderr, "Failed to create disassoc: %s\n", strerror(ret)); 18 | return ret; 19 | } 20 | 21 | int disassoc_len = libwifi_get_disassoc_length(&disassoc); 22 | if (disassoc_len <= 0) { 23 | fprintf(stderr, "Invalid disassoc length: %d\n", disassoc_len); 24 | return disassoc_len; 25 | } 26 | 27 | unsigned char *buf = malloc(disassoc_len); 28 | if (buf == NULL) { 29 | fprintf(stderr, "Failed to allocate buffer\n"); 30 | return -1; 31 | } 32 | 33 | int dump_len = libwifi_dump_disassoc(&disassoc, buf, disassoc_len); 34 | if (dump_len <= 0) { 35 | fprintf(stderr, "Failed to dump disassoc\n"); 36 | return ret; 37 | } 38 | 39 | return 0; 40 | } 41 | 42 | int test_disassoc_add_tag() { 43 | struct libwifi_disassoc disassoc = {0}; 44 | 45 | int ret = libwifi_create_disassoc(&disassoc, bcast, to, to, REASON_STA_LEAVING); 46 | if (ret != 0) { 47 | fprintf(stderr, "Failed to create disassoc: %s\n", strerror(ret)); 48 | return ret; 49 | } 50 | 51 | ret = libwifi_quick_add_tag(&disassoc.tags, TAG_VENDOR_SPECIFIC, (const unsigned char *) "\x00\x11\x22\xAAHello World", 15); 52 | if (ret != 0) { 53 | fprintf(stderr, "Failed to add disassoc tagged parameter: %s\n", strerror(ret)); 54 | return ret; 55 | } 56 | 57 | int disassoc_len = libwifi_get_disassoc_length(&disassoc); 58 | if (disassoc_len <= 0) { 59 | fprintf(stderr, "Invalid disassoc length: %d\n", disassoc_len); 60 | return disassoc_len; 61 | } 62 | 63 | unsigned char *buf = malloc(disassoc_len); 64 | if (buf == NULL) { 65 | fprintf(stderr, "Failed to allocate buffer\n"); 66 | return -1; 67 | } 68 | 69 | int dump_len = libwifi_dump_disassoc(&disassoc, buf, disassoc_len); 70 | if (dump_len <= 0) { 71 | fprintf(stderr, "Failed to dump disassoc\n"); 72 | return ret; 73 | } 74 | 75 | return 0; 76 | } 77 | 78 | int main(int argc, char **argv) { 79 | if (argc < 2) { 80 | printf("Specify test\n"); 81 | return -1; 82 | } 83 | 84 | if (strcmp(argv[1], "--disassoc-gen-full") == 0) { 85 | return test_disassoc_gen_full(); 86 | } else if (strcmp(argv[1], "--disassoc-gen-tags") == 0) { 87 | return test_disassoc_add_tag(); 88 | } 89 | 90 | return -1; 91 | } 92 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/core/misc/radiotap.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_CORE_RADIOTAP_H 17 | #define LIBWIFI_CORE_RADIOTAP_H 18 | 19 | #include 20 | 21 | #define LIBWIFI_MAX_RADIOTAP_LEN 128 22 | #define LIBWIFI_MAX_RADIOTAP_ANTENNAS 16 23 | 24 | #define LIBWIFI_RADIOTAP_BAND_2GHZ (1 << 0) 25 | #define LIBWIFI_RADIOTAP_BAND_5GHZ (1 << 1) 26 | #define LIBWIFI_RADIOTAP_BAND_6GHZ (1 << 2) 27 | #define LIBWIFI_RADIOTAP_BAND_900MHZ (1 << 3) 28 | 29 | /** 30 | * A channel field in radiotap consists of a 2-byte wide flags 31 | * sub-field and a 2-byte wide frequency field. 32 | * 33 | * libwifi will also calculate the band and center channel. 34 | */ 35 | struct libwifi_radiotap_channel { 36 | uint16_t flags; 37 | uint16_t freq; 38 | uint8_t center; 39 | uint8_t band; 40 | } __attribute__((packed)); 41 | 42 | /** 43 | * The radiotap antenna field consists of an antenna number and signal in dBm 44 | */ 45 | struct libwifi_radiotap_antenna { 46 | uint8_t antenna_number; 47 | int8_t signal; 48 | } __attribute__((packed)); 49 | 50 | /** 51 | * The radiotap MCS field is made up of 3 2-byte fields. 52 | */ 53 | struct libwifi_radiotap_mcs { 54 | uint8_t known; 55 | uint8_t flags; 56 | uint8_t mcs; 57 | } __attribute__((packed)); 58 | 59 | /** 60 | * The radiotap timestamp field consists of a timestamp field, accuracy, unit and flags. 61 | */ 62 | struct libwifi_radiotap_timestamp { 63 | uint64_t timestamp; 64 | uint16_t accuracy; 65 | uint8_t unit; 66 | uint8_t flags; 67 | } __attribute__((packed)); 68 | 69 | struct libwifi_radiotap_info { 70 | // Header 71 | uint32_t present; 72 | // Body 73 | struct libwifi_radiotap_channel channel; 74 | int8_t rate_raw; 75 | float rate; 76 | uint8_t antenna_count; 77 | struct libwifi_radiotap_antenna antennas[LIBWIFI_MAX_RADIOTAP_ANTENNAS]; 78 | int8_t signal; 79 | uint8_t flags; 80 | uint32_t extended_flags; 81 | uint16_t rx_flags; 82 | uint16_t tx_flags; 83 | struct libwifi_radiotap_mcs mcs; 84 | int8_t tx_power; 85 | struct libwifi_radiotap_timestamp timestamp; 86 | uint8_t rts_retries; 87 | uint8_t data_retries; 88 | // Other 89 | uint8_t length; 90 | } __attribute__((packed)); 91 | 92 | #endif /* LIBWIFI_CORE_RADIOTAP_H */ 93 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/gen/management/reassoc_request.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_GEN_REASSOCREQUEST_H 17 | #define LIBWIFI_GEN_REASSOCREQUEST_H 18 | 19 | #include "../../core/frame/frame.h" 20 | #include "../../core/frame/management/common.h" 21 | #include "../../core/frame/management/reassoc_request.h" 22 | 23 | /** 24 | * Create a new libwifi reassociation request 25 | * 26 | * @param reassoc_req A new libwifi_reassoc_req struct 27 | * @param receiver The receiver MAC address 28 | * @param transmitter The transmitter MAC address 29 | * @param address3 The address 3 frame field value, typically the BSSID 30 | * @param current_ap The current AP BSSID 31 | * @param ssid The desired BSS SSID 32 | * @param channel The desired channel 33 | * @return Zero on success, or negative error 34 | */ 35 | int libwifi_create_reassoc_req(struct libwifi_reassoc_req *reassoc_req, 36 | const unsigned char receiver[6], 37 | const unsigned char transmitter[6], 38 | const unsigned char address3[6], 39 | const unsigned char current_ap[6], 40 | const char *ssid, uint8_t channel); 41 | 42 | /** 43 | * Get the length of a given libwifi_reassoc_req 44 | * 45 | * @param reassoc_req A libwifi_reassoc_req struct 46 | * @return The length of the given libwifi_reassoc_req, or negative error 47 | */ 48 | size_t libwifi_get_reassoc_req_length(struct libwifi_reassoc_req *reassoc_req); 49 | 50 | /** 51 | * Dump a libwifi_reassoc_req into a raw format for packet injection. 52 | * 53 | * @param reassoc_req A libwifi_reassoc_req struct 54 | * @param buf The buffer to dump into 55 | * @param buf_len The length of the supplied buffer 56 | * @return The amount of bytes dumped, or negative error 57 | */ 58 | size_t libwifi_dump_reassoc_req(struct libwifi_reassoc_req *reassoc_req, unsigned char *buf, size_t buf_len); 59 | 60 | /** 61 | * Free any memory claimed by a libwifi_reassoc_req back to the system. 62 | * 63 | * @param reassoc_req A libwifi_reassoc_req 64 | */ 65 | void libwifi_free_reassoc_req(struct libwifi_reassoc_req *reassoc_req); 66 | 67 | #endif /* LIBWIFI_GEN_REASSOCREQUEST_H */ 68 | -------------------------------------------------------------------------------- /lib/libwifi/test/src/assoc_req_tests.c: -------------------------------------------------------------------------------- 1 | #include "../../src/libwifi.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #define BCAST_MAC "\xff\xff\xff\xff\xff\xff" 8 | #define TO_MAC "\x00\x20\x91\xAA\xBB\xCC" 9 | const unsigned char to[] = TO_MAC; 10 | const unsigned char bcast[] = BCAST_MAC; 11 | 12 | int test_assoc_req_gen_full() { 13 | struct libwifi_assoc_req assoc_req = {0}; 14 | 15 | int ret = libwifi_create_assoc_req(&assoc_req, bcast, to, to, "Some SSID", 11); 16 | if (ret != 0) { 17 | fprintf(stderr, "Failed to create assoc_req: %s\n", strerror(ret)); 18 | return ret; 19 | } 20 | 21 | int assoc_req_len = libwifi_get_assoc_req_length(&assoc_req); 22 | if (assoc_req_len <= 0) { 23 | fprintf(stderr, "Invalid assoc_req length: %d\n", assoc_req_len); 24 | return assoc_req_len; 25 | } 26 | 27 | unsigned char *buf = malloc(assoc_req_len); 28 | if (buf == NULL) { 29 | fprintf(stderr, "Failed to allocate buffer\n"); 30 | return -1; 31 | } 32 | 33 | int dump_len = libwifi_dump_assoc_req(&assoc_req, buf, assoc_req_len); 34 | if (dump_len <= 0) { 35 | fprintf(stderr, "Failed to dump assoc_req\n"); 36 | return ret; 37 | } 38 | 39 | return 0; 40 | } 41 | 42 | int test_assoc_req_add_tag() { 43 | struct libwifi_assoc_req assoc_req = {0}; 44 | 45 | int ret = libwifi_create_assoc_req(&assoc_req, bcast, to, to, "Some SSID", 11); 46 | if (ret != 0) { 47 | fprintf(stderr, "Failed to create assoc_req: %s\n", strerror(ret)); 48 | return ret; 49 | } 50 | 51 | ret = libwifi_quick_add_tag(&assoc_req.tags, TAG_VENDOR_SPECIFIC, (const unsigned char *) "\x00\x11\x22\xAAHello World", 15); 52 | if (ret != 0) { 53 | fprintf(stderr, "Failed to add assoc_req tagged parameter: %s\n", strerror(ret)); 54 | return ret; 55 | } 56 | 57 | int assoc_req_len = libwifi_get_assoc_req_length(&assoc_req); 58 | if (assoc_req_len <= 0) { 59 | fprintf(stderr, "Invalid assoc_req length: %d\n", assoc_req_len); 60 | return assoc_req_len; 61 | } 62 | 63 | unsigned char *buf = malloc(assoc_req_len); 64 | if (buf == NULL) { 65 | fprintf(stderr, "Failed to allocate buffer\n"); 66 | return -1; 67 | } 68 | 69 | int dump_len = libwifi_dump_assoc_req(&assoc_req, buf, assoc_req_len); 70 | if (dump_len <= 0) { 71 | fprintf(stderr, "Failed to dump assoc_req\n"); 72 | return ret; 73 | } 74 | 75 | return 0; 76 | } 77 | 78 | int main(int argc, char **argv) { 79 | if (argc < 2) { 80 | printf("Specify test\n"); 81 | return -1; 82 | } 83 | 84 | if (strcmp(argv[1], "--assoc_req-gen-full") == 0) { 85 | return test_assoc_req_gen_full(); 86 | } else if (strcmp(argv[1], "--assoc_req-gen-tags") == 0) { 87 | return test_assoc_req_add_tag(); 88 | } 89 | 90 | return -1; 91 | } 92 | -------------------------------------------------------------------------------- /lib/libwifi/test/src/probe_req_tests.c: -------------------------------------------------------------------------------- 1 | #include "../../src/libwifi.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #define BCAST_MAC "\xff\xff\xff\xff\xff\xff" 8 | #define TO_MAC "\x00\x20\x91\xAA\xBB\xCC" 9 | const unsigned char to[] = TO_MAC; 10 | const unsigned char bcast[] = BCAST_MAC; 11 | 12 | int test_probe_req_gen_full() { 13 | struct libwifi_probe_req probe_req = {0}; 14 | 15 | int ret = libwifi_create_probe_req(&probe_req, bcast, to, to, "Some SSID", 11); 16 | if (ret != 0) { 17 | fprintf(stderr, "Failed to create probe_req: %s\n", strerror(ret)); 18 | return ret; 19 | } 20 | 21 | int probe_req_len = libwifi_get_probe_req_length(&probe_req); 22 | if (probe_req_len <= 0) { 23 | fprintf(stderr, "Invalid probe_req length: %d\n", probe_req_len); 24 | return probe_req_len; 25 | } 26 | 27 | unsigned char *buf = malloc(probe_req_len); 28 | if (buf == NULL) { 29 | fprintf(stderr, "Failed to allocate buffer\n"); 30 | return -1; 31 | } 32 | 33 | int dump_len = libwifi_dump_probe_req(&probe_req, buf, probe_req_len); 34 | if (dump_len <= 0) { 35 | fprintf(stderr, "Failed to dump probe_req\n"); 36 | return ret; 37 | } 38 | 39 | return 0; 40 | } 41 | 42 | int test_probe_req_add_tag() { 43 | struct libwifi_probe_req probe_req = {0}; 44 | 45 | int ret = libwifi_create_probe_req(&probe_req, bcast, to, to, "Some SSID", 11); 46 | if (ret != 0) { 47 | fprintf(stderr, "Failed to create probe_req: %s\n", strerror(ret)); 48 | return ret; 49 | } 50 | 51 | ret = libwifi_quick_add_tag(&probe_req.tags, TAG_VENDOR_SPECIFIC, (const unsigned char *) "\x00\x11\x22\xAAHello World", 15); 52 | if (ret != 0) { 53 | fprintf(stderr, "Failed to add probe_req tagged parameter: %s\n", strerror(ret)); 54 | return ret; 55 | } 56 | 57 | int probe_req_len = libwifi_get_probe_req_length(&probe_req); 58 | if (probe_req_len <= 0) { 59 | fprintf(stderr, "Invalid probe_req length: %d\n", probe_req_len); 60 | return probe_req_len; 61 | } 62 | 63 | unsigned char *buf = malloc(probe_req_len); 64 | if (buf == NULL) { 65 | fprintf(stderr, "Failed to allocate buffer\n"); 66 | return -1; 67 | } 68 | 69 | int dump_len = libwifi_dump_probe_req(&probe_req, buf, probe_req_len); 70 | if (dump_len <= 0) { 71 | fprintf(stderr, "Failed to dump probe_req\n"); 72 | return ret; 73 | } 74 | 75 | return 0; 76 | } 77 | 78 | int main(int argc, char **argv) { 79 | if (argc < 2) { 80 | printf("Specify test\n"); 81 | return -1; 82 | } 83 | 84 | if (strcmp(argv[1], "--probe_req-gen-full") == 0) { 85 | return test_probe_req_gen_full(); 86 | } else if (strcmp(argv[1], "--probe_req-gen-tags") == 0) { 87 | return test_probe_req_add_tag(); 88 | } 89 | 90 | return -1; 91 | } 92 | -------------------------------------------------------------------------------- /lib/libwifi/test/src/assoc_resp_tests.c: -------------------------------------------------------------------------------- 1 | #include "../../src/libwifi.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #define BCAST_MAC "\xff\xff\xff\xff\xff\xff" 8 | #define TO_MAC "\x00\x20\x91\xAA\xBB\xCC" 9 | const unsigned char to[] = TO_MAC; 10 | const unsigned char bcast[] = BCAST_MAC; 11 | 12 | int test_assoc_resp_gen_full() { 13 | struct libwifi_assoc_resp assoc_resp = {0}; 14 | 15 | int ret = libwifi_create_assoc_resp(&assoc_resp, bcast, to, to, 11); 16 | if (ret != 0) { 17 | fprintf(stderr, "Failed to create assoc_resp: %s\n", strerror(ret)); 18 | return ret; 19 | } 20 | 21 | int assoc_resp_len = libwifi_get_assoc_resp_length(&assoc_resp); 22 | if (assoc_resp_len <= 0) { 23 | fprintf(stderr, "Invalid assoc_resp length: %d\n", assoc_resp_len); 24 | return assoc_resp_len; 25 | } 26 | 27 | unsigned char *buf = malloc(assoc_resp_len); 28 | if (buf == NULL) { 29 | fprintf(stderr, "Failed to allocate buffer\n"); 30 | return -1; 31 | } 32 | 33 | int dump_len = libwifi_dump_assoc_resp(&assoc_resp, buf, assoc_resp_len); 34 | if (dump_len <= 0) { 35 | fprintf(stderr, "Failed to dump assoc_resp\n"); 36 | return ret; 37 | } 38 | 39 | return 0; 40 | } 41 | 42 | int test_assoc_resp_add_tag() { 43 | struct libwifi_assoc_resp assoc_resp = {0}; 44 | 45 | int ret = libwifi_create_assoc_resp(&assoc_resp, bcast, to, to, 11); 46 | if (ret != 0) { 47 | fprintf(stderr, "Failed to create assoc_resp: %s\n", strerror(ret)); 48 | return ret; 49 | } 50 | 51 | ret = libwifi_quick_add_tag(&assoc_resp.tags, TAG_VENDOR_SPECIFIC, (const unsigned char *) "\x00\x11\x22\xAAHello World", 15); 52 | if (ret != 0) { 53 | fprintf(stderr, "Failed to add assoc_resp tagged parameter: %s\n", strerror(ret)); 54 | return ret; 55 | } 56 | 57 | int assoc_resp_len = libwifi_get_assoc_resp_length(&assoc_resp); 58 | if (assoc_resp_len <= 0) { 59 | fprintf(stderr, "Invalid assoc_resp length: %d\n", assoc_resp_len); 60 | return assoc_resp_len; 61 | } 62 | 63 | unsigned char *buf = malloc(assoc_resp_len); 64 | if (buf == NULL) { 65 | fprintf(stderr, "Failed to allocate buffer\n"); 66 | return -1; 67 | } 68 | 69 | int dump_len = libwifi_dump_assoc_resp(&assoc_resp, buf, assoc_resp_len); 70 | if (dump_len <= 0) { 71 | fprintf(stderr, "Failed to dump assoc_resp\n"); 72 | return ret; 73 | } 74 | 75 | return 0; 76 | } 77 | 78 | int main(int argc, char **argv) { 79 | if (argc < 2) { 80 | printf("Specify test\n"); 81 | return -1; 82 | } 83 | 84 | if (strcmp(argv[1], "--assoc_resp-gen-full") == 0) { 85 | return test_assoc_resp_gen_full(); 86 | } else if (strcmp(argv[1], "--assoc_resp-gen-tags") == 0) { 87 | return test_assoc_resp_add_tag(); 88 | } 89 | 90 | return -1; 91 | } 92 | -------------------------------------------------------------------------------- /lib/libwifi/README.md: -------------------------------------------------------------------------------- 1 | # libwifi 2 | 802.11 Parsing / Generation library 3 | 4 | | Build Status | OS | 5 | |---------------------------------------------------------------------------------------|-------| 6 | |![linux](https://github.com/libwifi/libwifi/actions/workflows/linux_x86.yml/badge.svg) | Linux | 7 | |![macOS](https://github.com/libwifi/libwifi/actions/workflows/macos_x86.yml/badge.svg) | macOS | 8 | 9 | ## What is this? 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). 11 | 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. 13 | 14 | The library is fully documented with code comments in both the headers files and the code files. 15 | 16 | ## Building and Installing 17 | ### Building as Release 18 | ``` 19 | $ mkdir build 20 | $ cd build 21 | $ cmake .. 22 | $ make 23 | $ sudo make install 24 | ``` 25 | ### Building as Debug 26 | You can also specify `-DCMAKE_BUILD_TYPE=Debug` to CMake, to generate a library with debug symbols present. This also sets the library version number to `dev-BRANCHNAME-COMMITHASH`. 27 | ``` 28 | $ mkdir build 29 | $ cd build 30 | $ cmake .. -DCMAKE_BUILD_TYPE=Debug 31 | $ make 32 | $ sudo make install 33 | ``` 34 | ``` 35 | $ ./test_misc 36 | libwifi version: dev-fixup-7909700 37 | ``` 38 | 39 | ## Examples 40 | Some examples are available in the [examples](https://github.com/libwifi/libwifi/tree/main/examples) directory, which show the general flow of how libwifi is used to generate and parse different types of 802.11 frame. 41 | 42 | ## Running Tests 43 | Using ctest, you can run the tests for the parse and generation functions of libwifi. 44 | ``` 45 | $ cd test/ 46 | $ mkdir build 47 | $ cd build 48 | $ cmake .. 49 | $ make && make test 50 | ``` 51 | 52 | ## Using Utilities 53 | Included in the source are some utilities that use libwifi, and serve as references or examples if you need them. 54 | ``` 55 | $ cd utils/ 56 | $ mkdir build 57 | $ cd build 58 | $ cmake .. 59 | $ make 60 | ``` 61 | 62 | ## ESP32 63 | This project has been configured to be easily applicable as ESP-IDF component 64 | 65 | ### Steps to include (Example) 66 | 67 | 1. Put `libwifi` folder in `components/` 68 | 2. Open `main/CMakeLists.txt` and add `libwifi` to `COMPONENT_REQUIRES` 69 | 3. In `main/main.c` add `#include "libwifi.h"` 70 | 4. Test by running following code: 71 | ```C 72 | void app_main(void){ 73 | printf("libwifi version: %s", libwifi_get_version()); 74 | } 75 | ``` 76 | -------------------------------------------------------------------------------- /lib/libwifi/test/src/probe_resp_tests.c: -------------------------------------------------------------------------------- 1 | #include "../../src/libwifi.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #define BCAST_MAC "\xff\xff\xff\xff\xff\xff" 8 | #define TO_MAC "\x00\x20\x91\xAA\xBB\xCC" 9 | const unsigned char to[] = TO_MAC; 10 | const unsigned char bcast[] = BCAST_MAC; 11 | 12 | int test_probe_resp_gen_full() { 13 | struct libwifi_probe_resp probe_resp = {0}; 14 | 15 | int ret = libwifi_create_probe_resp(&probe_resp, bcast, to, to, "Some SSID", 11); 16 | if (ret != 0) { 17 | fprintf(stderr, "Failed to create probe_resp: %s\n", strerror(ret)); 18 | return ret; 19 | } 20 | 21 | int probe_resp_len = libwifi_get_probe_resp_length(&probe_resp); 22 | if (probe_resp_len <= 0) { 23 | fprintf(stderr, "Invalid probe_resp length: %d\n", probe_resp_len); 24 | return probe_resp_len; 25 | } 26 | 27 | unsigned char *buf = malloc(probe_resp_len); 28 | if (buf == NULL) { 29 | fprintf(stderr, "Failed to allocate buffer\n"); 30 | return -1; 31 | } 32 | 33 | int dump_len = libwifi_dump_probe_resp(&probe_resp, buf, probe_resp_len); 34 | if (dump_len <= 0) { 35 | fprintf(stderr, "Failed to dump probe_resp\n"); 36 | return ret; 37 | } 38 | 39 | return 0; 40 | } 41 | 42 | int test_probe_resp_add_tag() { 43 | struct libwifi_probe_resp probe_resp = {0}; 44 | 45 | int ret = libwifi_create_probe_resp(&probe_resp, bcast, to, to, "Some SSID", 11); 46 | if (ret != 0) { 47 | fprintf(stderr, "Failed to create probe_resp: %s\n", strerror(ret)); 48 | return ret; 49 | } 50 | 51 | ret = libwifi_quick_add_tag(&probe_resp.tags, TAG_VENDOR_SPECIFIC, (const unsigned char *) "\x00\x11\x22\xAAHello World", 15); 52 | if (ret != 0) { 53 | fprintf(stderr, "Failed to add probe_resp tagged parameter: %s\n", strerror(ret)); 54 | return ret; 55 | } 56 | 57 | int probe_resp_len = libwifi_get_probe_resp_length(&probe_resp); 58 | if (probe_resp_len <= 0) { 59 | fprintf(stderr, "Invalid probe_resp length: %d\n", probe_resp_len); 60 | return probe_resp_len; 61 | } 62 | 63 | unsigned char *buf = malloc(probe_resp_len); 64 | if (buf == NULL) { 65 | fprintf(stderr, "Failed to allocate buffer\n"); 66 | return -1; 67 | } 68 | 69 | int dump_len = libwifi_dump_probe_resp(&probe_resp, buf, probe_resp_len); 70 | if (dump_len <= 0) { 71 | fprintf(stderr, "Failed to dump probe_resp\n"); 72 | return ret; 73 | } 74 | 75 | return 0; 76 | } 77 | 78 | int main(int argc, char **argv) { 79 | if (argc < 2) { 80 | printf("Specify test\n"); 81 | return -1; 82 | } 83 | 84 | if (strcmp(argv[1], "--probe_resp-gen-full") == 0) { 85 | return test_probe_resp_gen_full(); 86 | } else if (strcmp(argv[1], "--probe_resp-gen-tags") == 0) { 87 | return test_probe_resp_add_tag(); 88 | } 89 | 90 | return -1; 91 | } 92 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/gen/management/assoc_response.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_GEN_ASSOCRESP_H 17 | #define LIBWIFI_GEN_ASSOCRESP_H 18 | 19 | #include "../../core/frame/management/assoc_response.h" 20 | 21 | /** 22 | * Set the channel of a libwifi_assoc_resp. 23 | * 24 | * @param assoc_resp A libwifi_assoc_resp 25 | * @param channel The new channel 26 | * @return Zero on success, or negative error 27 | */ 28 | int libwifi_set_assoc_resp_channel(struct libwifi_assoc_resp *assoc_resp, uint8_t channel); 29 | 30 | /** 31 | * Calculate the length of a given libwifi_assoc_resp 32 | * 33 | * @param assoc_resp A libwifi_assoc_resp 34 | * @return The length of the given assoc_resp, or negative error 35 | */ 36 | size_t libwifi_get_assoc_resp_length(struct libwifi_assoc_resp *assoc_resp); 37 | 38 | /** 39 | * Generate a populated libwifi assoc_resp. 40 | * 41 | * A generated libwifi assoc_resp can be "dumped" into a buffer for packet injection 42 | * via the libwifi_dump_assoc_resp. 43 | * 44 | * @param assoc_resp A libwifi_assoc_resp 45 | * @param receiver The receiver MAC address, aka address 1 46 | * @param transmitter The source MAC address, aka address 2 47 | * @param address3 The address 3 frame field value, typically the BSSID 48 | * @param channel The desired channel of the assoc_resp 49 | * @return Zero on success, or negative error 50 | */ 51 | int libwifi_create_assoc_resp(struct libwifi_assoc_resp *assoc_resp, 52 | const unsigned char receiver[6], 53 | const unsigned char transmitter[6], 54 | const unsigned char address3[6], 55 | uint8_t channel); 56 | 57 | /** 58 | * Dump a libwifi_assoc_resp into a raw format for packet injection. 59 | * 60 | * @param assoc_resp A libwifi_assoc_resp 61 | * @param buf The output buffer for the frame data 62 | * @param buf_len The length of the output buffer 63 | * @return The length of the dumped assoc_resp, or negative error 64 | */ 65 | size_t libwifi_dump_assoc_resp(struct libwifi_assoc_resp *assoc_resp, unsigned char *buf, size_t buf_len); 66 | 67 | /** 68 | * Free any memory claimed by a libwifi_assoc_resp back to the system. 69 | * 70 | * @param assoc_resp A libwifi_assoc_resp 71 | */ 72 | void libwifi_free_assoc_resp(struct libwifi_assoc_resp *assoc_resp); 73 | 74 | #endif /* LIBWIFI_GEN_ASSOCRESP_H */ 75 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/parse/management/assoc_request.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #include "assoc_request.h" 17 | #include "../../core/frame/tag_iterator.h" 18 | #include "common.h" 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | /** 25 | * libwifi_parse_assoc_req will parse useful fields into a struct libwifi_sta. 26 | * 27 | * This function also checks to see if the transmitter address can be ANDed 28 | * with 0x02, to determine a likelihood of randomized addresses. 29 | * 30 | * ┌─────────────────────────────────────────────┐ 31 | * │ Header (Ordered or Unordered) │ ── Association Request Header 32 | * ├─────────────────────────────────────────────┤ 33 | * │ Fixed Parameters │ ─┐ 34 | * ├─────────────────────────────────────────────┤ ├── Association Request Body 35 | * │ Tagged Parameters │ ─┘ 36 | * └─────────────────────────────────────────────┘ 37 | */ 38 | int libwifi_parse_assoc_req(struct libwifi_sta *sta, struct libwifi_frame *frame) { 39 | memset(sta, 0, sizeof(struct libwifi_sta)); 40 | 41 | if (frame->frame_control.type != TYPE_MANAGEMENT || frame->frame_control.subtype != SUBTYPE_ASSOC_REQ) { 42 | return -EINVAL; 43 | } 44 | 45 | if (frame->frame_control.flags.ordered) { 46 | memcpy(sta->transmitter, frame->header.mgmt_ordered.addr2, 6); 47 | memcpy(sta->bssid, frame->header.mgmt_ordered.addr3, 6); 48 | } else { 49 | memcpy(sta->transmitter, frame->header.mgmt_unordered.addr2, 6); 50 | memcpy(sta->bssid, frame->header.mgmt_unordered.addr3, 6); 51 | } 52 | 53 | if (sta->transmitter[0] & 0x02) { 54 | sta->randomized = 1; 55 | } else { 56 | sta->randomized = 0; 57 | } 58 | 59 | // Fixed Parameters must be present 60 | if (frame->len <= (frame->header_len + sizeof(struct libwifi_assoc_req_fixed_parameters))) { 61 | return -EINVAL; 62 | } 63 | 64 | sta->tags.length = (frame->len - frame->header_len); 65 | const unsigned char *tagged_params = frame->body; 66 | sta->tags.parameters = malloc(sta->tags.length); 67 | memcpy(sta->tags.parameters, tagged_params, sta->tags.length); 68 | 69 | struct libwifi_tag_iterator it; 70 | if (libwifi_tag_iterator_init(&it, sta->tags.parameters, sta->tags.length) != 0) { 71 | return -EINVAL; 72 | } 73 | 74 | if (libwifi_sta_tag_parser(sta, &it) != 0) { 75 | return -EINVAL; 76 | } 77 | 78 | return 0; 79 | } 80 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/parse/management/reassoc_request.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #include "reassoc_request.h" 17 | #include "../../core/frame/tag_iterator.h" 18 | #include "common.h" 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | /** 25 | * libwifi_parse_reassoc_req will parse useful fields into a struct libwifi_sta. 26 | * 27 | * This function also checks to see if the transmitter address can be ANDed 28 | * with 0x02, to determine a likelihood of randomized addresses. 29 | * 30 | * ┌─────────────────────────────────────────────┐ 31 | * │ Header (Ordered or Unordered) │ ── Ressociation Request Header 32 | * ├─────────────────────────────────────────────┤ 33 | * │ Fixed Parameters │ ─┐ 34 | * ├─────────────────────────────────────────────┤ |── Ressociation Request Body 35 | * │ Tagged Parameters │ ─┘ 36 | * └─────────────────────────────────────────────┘ 37 | */ 38 | int libwifi_parse_reassoc_req(struct libwifi_sta *sta, struct libwifi_frame *frame) { 39 | memset(sta, 0, sizeof(struct libwifi_sta)); 40 | 41 | if (frame->frame_control.type != TYPE_MANAGEMENT || frame->frame_control.subtype != SUBTYPE_REASSOC_REQ) { 42 | return -EINVAL; 43 | } 44 | 45 | if (frame->frame_control.flags.ordered) { 46 | memcpy(sta->transmitter, frame->header.mgmt_ordered.addr2, 6); 47 | memcpy(sta->bssid, frame->header.mgmt_ordered.addr3, 6); 48 | } else { 49 | memcpy(sta->transmitter, frame->header.mgmt_unordered.addr2, 6); 50 | memcpy(sta->bssid, frame->header.mgmt_unordered.addr3, 6); 51 | } 52 | 53 | if (sta->transmitter[0] & 0x02) { 54 | sta->randomized = 1; 55 | } else { 56 | sta->randomized = 0; 57 | } 58 | 59 | // Fixed Parameters must be present 60 | if (frame->len <= (frame->header_len + sizeof(struct libwifi_reassoc_req_fixed_parameters))) { 61 | return -EINVAL; 62 | } 63 | 64 | sta->tags.length = (frame->len - frame->header_len); 65 | const unsigned char *tagged_params = frame->body; 66 | sta->tags.parameters = malloc(sta->tags.length); 67 | memcpy(sta->tags.parameters, tagged_params, sta->tags.length); 68 | 69 | struct libwifi_tag_iterator it; 70 | if (libwifi_tag_iterator_init(&it, sta->tags.parameters, sta->tags.length) != 0) { 71 | return -EINVAL; 72 | } 73 | 74 | if (libwifi_sta_tag_parser(sta, &it) != 0) { 75 | return -EINVAL; 76 | } 77 | 78 | return 0; 79 | } 80 | -------------------------------------------------------------------------------- /lib/libwifi/test/src/reassoc_req_tests.c: -------------------------------------------------------------------------------- 1 | #include "../../src/libwifi.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #define BCAST_MAC "\xff\xff\xff\xff\xff\xff" 8 | #define TO_MAC "\x00\x20\x91\xAA\xBB\xCC" 9 | #define CURRENT_AP "\x00\x20\x91\x00\x11\x22" 10 | const unsigned char to[] = TO_MAC; 11 | const unsigned char bcast[] = BCAST_MAC; 12 | const unsigned char current_ap[] = CURRENT_AP; 13 | 14 | int test_reassoc_req_gen_full() { 15 | struct libwifi_reassoc_req reassoc_req = {0}; 16 | 17 | int ret = libwifi_create_reassoc_req(&reassoc_req, bcast, to, to, current_ap, "Some SSID", 11); 18 | if (ret != 0) { 19 | fprintf(stderr, "Failed to create reassoc_req: %s\n", strerror(ret)); 20 | return ret; 21 | } 22 | 23 | int reassoc_req_len = libwifi_get_reassoc_req_length(&reassoc_req); 24 | if (reassoc_req_len <= 0) { 25 | fprintf(stderr, "Invalid reassoc_req length: %d\n", reassoc_req_len); 26 | return reassoc_req_len; 27 | } 28 | 29 | unsigned char *buf = malloc(reassoc_req_len); 30 | if (buf == NULL) { 31 | fprintf(stderr, "Failed to allocate buffer\n"); 32 | return -1; 33 | } 34 | 35 | int dump_len = libwifi_dump_reassoc_req(&reassoc_req, buf, reassoc_req_len); 36 | if (dump_len <= 0) { 37 | fprintf(stderr, "Failed to dump reassoc_req\n"); 38 | return ret; 39 | } 40 | 41 | return 0; 42 | } 43 | 44 | int test_reassoc_req_add_tag() { 45 | struct libwifi_reassoc_req reassoc_req = {0}; 46 | 47 | int ret = libwifi_create_reassoc_req(&reassoc_req, bcast, to, to, current_ap, "Some SSID", 11); 48 | if (ret != 0) { 49 | fprintf(stderr, "Failed to create reassoc_req: %s\n", strerror(ret)); 50 | return ret; 51 | } 52 | 53 | ret = libwifi_quick_add_tag(&reassoc_req.tags, TAG_VENDOR_SPECIFIC, (const unsigned char *) "\x00\x11\x22\xAAHello World", 15); 54 | if (ret != 0) { 55 | fprintf(stderr, "Failed to add reassoc_req tagged parameter: %s\n", strerror(ret)); 56 | return ret; 57 | } 58 | 59 | int reassoc_req_len = libwifi_get_reassoc_req_length(&reassoc_req); 60 | if (reassoc_req_len <= 0) { 61 | fprintf(stderr, "Invalid reassoc_req length: %d\n", reassoc_req_len); 62 | return reassoc_req_len; 63 | } 64 | 65 | unsigned char *buf = malloc(reassoc_req_len); 66 | if (buf == NULL) { 67 | fprintf(stderr, "Failed to allocate buffer\n"); 68 | return -1; 69 | } 70 | 71 | int dump_len = libwifi_dump_reassoc_req(&reassoc_req, buf, reassoc_req_len); 72 | if (dump_len <= 0) { 73 | fprintf(stderr, "Failed to dump reassoc_req\n"); 74 | return ret; 75 | } 76 | 77 | return 0; 78 | } 79 | 80 | int main(int argc, char **argv) { 81 | if (argc < 2) { 82 | printf("Specify test\n"); 83 | return -1; 84 | } 85 | 86 | if (strcmp(argv[1], "--reassoc_req-gen-full") == 0) { 87 | return test_reassoc_req_gen_full(); 88 | } else if (strcmp(argv[1], "--reassoc_req-gen-tags") == 0) { 89 | return test_reassoc_req_add_tag(); 90 | } 91 | 92 | return -1; 93 | } 94 | -------------------------------------------------------------------------------- /src/dns.c: -------------------------------------------------------------------------------- 1 | #include "lwip/sockets.h" 2 | #include "lwip/inet.h" 3 | #include "esp_log.h" 4 | 5 | 6 | #define DNS_PORT 53 7 | #define RESPONSE_IP_ADDR {192, 168, 4, 1} 8 | static const char *TAG= "DNS_SERVER:"; 9 | 10 | static void dns_server_task(void *pvParameters) 11 | { 12 | struct sockaddr_in server_addr, client_addr; 13 | socklen_t client_addr_len = sizeof(client_addr); 14 | char buf[512]; 15 | int sock; 16 | 17 | if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { 18 | printf("Errore nella creazione del socket DNS\n"); 19 | vTaskDelete(NULL); 20 | return; 21 | } 22 | 23 | server_addr.sin_family = AF_INET; 24 | server_addr.sin_addr.s_addr = htonl(INADDR_ANY); 25 | server_addr.sin_port = htons(DNS_PORT); 26 | 27 | if (bind(sock, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) { 28 | ESP_LOGE(TAG, "Errore nel bind del socket DNS\n"); 29 | close(sock); 30 | vTaskDelete(NULL); 31 | return; 32 | } 33 | ESP_LOGD(TAG, "Server DNS in ascolto sulla porta %d\n", DNS_PORT); 34 | 35 | uint8_t response_template[] = { 36 | 0x00, 0x00, // ID (verrà copiato dalla richiesta) 37 | 0x81, 0x80, // Flag: risposta, senza errori 38 | 0x00, 0x01, // QDCOUNT (1 query) 39 | 0x00, 0x01, // ANCOUNT (1 risposta) 40 | 0x00, 0x00, // NSCOUNT 41 | 0x00, 0x00, // ARCOUNT 42 | // Risposta dinamica aggiunta qui sotto 43 | }; 44 | uint8_t ip_address[] = RESPONSE_IP_ADDR; 45 | 46 | while (1) 47 | { 48 | int len = recvfrom(sock, buf, sizeof(buf), 0, (struct sockaddr *)&client_addr, &client_addr_len); 49 | if (len < 0) { 50 | ESP_LOGE(TAG, "Errore nella ricezione dei dati DNS\n"); 51 | continue; 52 | } 53 | 54 | // Copia l'ID dalla richiesta 55 | response_template[0] = buf[0]; 56 | response_template[1] = buf[1]; 57 | 58 | // Prepara una risposta DNS dinamica 59 | uint8_t response[512]; 60 | memcpy(response, response_template, sizeof(response_template)); 61 | int response_len = sizeof(response_template); 62 | 63 | // Copia la query originale 64 | memcpy(&response[response_len], &buf[12], len - 12); // Copia la query 65 | response_len += (len - 12); 66 | 67 | uint8_t answer[] = { 68 | 0xC0, 0x0C, // Puntatore al nome della query 69 | 0x00, 0x01, // Tipo: A (host address) 70 | 0x00, 0x01, // Classe: IN (Internet) 71 | 0x00, 0x00, 0x00, 0x3C, // TTL: 60 secondi 72 | 0x00, 0x04, // Lunghezza dati: 4 byte (IPv4) 73 | ip_address[0], ip_address[1], ip_address[2], ip_address[3] // Indirizzo IP 74 | }; 75 | 76 | memcpy(&response[response_len], answer, sizeof(answer)); 77 | response_len += sizeof(answer); 78 | sendto(sock, response, response_len, 0, (struct sockaddr *)&client_addr, client_addr_len); 79 | } 80 | } 81 | 82 | 83 | void dns_server_start(void) 84 | { 85 | // Avvia il server DNS (come task separato) 86 | xTaskCreate(dns_server_task, "dns_server_task", 4096, NULL, 5, NULL); 87 | } -------------------------------------------------------------------------------- /lib/libwifi/test/src/reassoc_resp_tests.c: -------------------------------------------------------------------------------- 1 | #include "../../src/libwifi.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #define BCAST_MAC "\xff\xff\xff\xff\xff\xff" 8 | #define TO_MAC "\x00\x20\x91\xAA\xBB\xCC" 9 | #define CURRENT_AP "\x00\x20\x91\x00\x11\x22" 10 | const unsigned char to[] = TO_MAC; 11 | const unsigned char bcast[] = BCAST_MAC; 12 | const unsigned char current_ap[] = CURRENT_AP; 13 | 14 | int test_reassoc_resp_gen_full() { 15 | struct libwifi_reassoc_resp reassoc_resp = {0}; 16 | 17 | int ret = libwifi_create_reassoc_resp(&reassoc_resp, bcast, to, current_ap, 11); 18 | if (ret != 0) { 19 | fprintf(stderr, "Failed to create reassoc_resp: %s\n", strerror(ret)); 20 | return ret; 21 | } 22 | 23 | int reassoc_resp_len = libwifi_get_reassoc_resp_length(&reassoc_resp); 24 | if (reassoc_resp_len <= 0) { 25 | fprintf(stderr, "Invalid reassoc_resp length: %d\n", reassoc_resp_len); 26 | return reassoc_resp_len; 27 | } 28 | 29 | unsigned char *buf = malloc(reassoc_resp_len); 30 | if (buf == NULL) { 31 | fprintf(stderr, "Failed to allocate buffer\n"); 32 | return -1; 33 | } 34 | 35 | int dump_len = libwifi_dump_reassoc_resp(&reassoc_resp, buf, reassoc_resp_len); 36 | if (dump_len <= 0) { 37 | fprintf(stderr, "Failed to dump reassoc_resp\n"); 38 | return ret; 39 | } 40 | 41 | return 0; 42 | } 43 | 44 | int test_reassoc_resp_add_tag() { 45 | struct libwifi_reassoc_resp reassoc_resp = {0}; 46 | 47 | int ret = libwifi_create_reassoc_resp(&reassoc_resp, bcast, to, current_ap, 11); 48 | if (ret != 0) { 49 | fprintf(stderr, "Failed to create reassoc_resp: %s\n", strerror(ret)); 50 | return ret; 51 | } 52 | 53 | ret = libwifi_quick_add_tag(&reassoc_resp.tags, TAG_VENDOR_SPECIFIC, (const unsigned char *) "\x00\x11\x22\xAAHello World", 15); 54 | if (ret != 0) { 55 | fprintf(stderr, "Failed to add reassoc_resp tagged parameter: %s\n", strerror(ret)); 56 | return ret; 57 | } 58 | 59 | int reassoc_resp_len = libwifi_get_reassoc_resp_length(&reassoc_resp); 60 | if (reassoc_resp_len <= 0) { 61 | fprintf(stderr, "Invalid reassoc_resp length: %d\n", reassoc_resp_len); 62 | return reassoc_resp_len; 63 | } 64 | 65 | unsigned char *buf = malloc(reassoc_resp_len); 66 | if (buf == NULL) { 67 | fprintf(stderr, "Failed to allocate buffer\n"); 68 | return -1; 69 | } 70 | 71 | int dump_len = libwifi_dump_reassoc_resp(&reassoc_resp, buf, reassoc_resp_len); 72 | if (dump_len <= 0) { 73 | fprintf(stderr, "Failed to dump reassoc_resp\n"); 74 | return ret; 75 | } 76 | 77 | return 0; 78 | } 79 | 80 | int main(int argc, char **argv) { 81 | if (argc < 2) { 82 | printf("Specify test\n"); 83 | return -1; 84 | } 85 | 86 | if (strcmp(argv[1], "--reassoc_resp-gen-full") == 0) { 87 | return test_reassoc_resp_gen_full(); 88 | } else if (strcmp(argv[1], "--reassoc_resp-gen-tags") == 0) { 89 | return test_reassoc_resp_add_tag(); 90 | } 91 | 92 | return -1; 93 | } 94 | -------------------------------------------------------------------------------- /scripts/spiffs_tool.py: -------------------------------------------------------------------------------- 1 | import os 2 | import csv 3 | import subprocess 4 | 5 | 6 | def parse_size(size_str): 7 | size_str = size_str.strip().upper() 8 | if size_str.endswith("K"): 9 | return int(size_str[:-1]) * 1024 10 | elif size_str.endswith("M"): 11 | return int(size_str[:-1]) * 1024 * 1024 12 | else: 13 | return int(size_str, 16) 14 | 15 | 16 | def get_partition_info(partition_file, partition_name): 17 | with open(partition_file, "r") as f: 18 | reader = csv.reader(f) 19 | for row in reader: 20 | if row and row[0] == partition_name: 21 | partition_offset = int(row[3], 16) 22 | partition_size = parse_size(row[4]) 23 | return partition_offset, partition_size 24 | return None, None 25 | 26 | 27 | def get_serial_port(): 28 | try: 29 | output = subprocess.check_output(["platformio", "device", "list"], text=True) 30 | for line in output.splitlines(): 31 | if "USB" in line or "COM" in line and "COM1" not in line: 32 | if line.startswith("/dev") or "COM" in line: 33 | return line.split()[0] 34 | except subprocess.CalledProcessError as e: 35 | print("Impossibile trovare la porta seriale:", e) 36 | return None 37 | 38 | 39 | def dump_spiffs(esptool_path, port, baud, offset, size, output_file): 40 | command = [ 41 | esptool_path, 42 | "-p", port, 43 | "-b 921600", 44 | "read_flash", 45 | f"0x{offset:X}", 46 | f"0x{size:X}", 47 | output_file 48 | ] 49 | subprocess.run(command, check=True) 50 | 51 | 52 | def extract_spiffs_with_mkspiffs(dump_file, output_dir, mkspiffs_path, target_file="passwords.txt"): 53 | if not os.path.exists(dump_file): 54 | print(f"Errore: il file {dump_file} non esiste.") 55 | return 56 | 57 | os.makedirs(output_dir, exist_ok=True) 58 | command = [ 59 | mkspiffs_path.replace("\\", "/"), 60 | "-u", output_dir.replace("\\", "/"), 61 | dump_file.replace("\\", "/") 62 | ] 63 | subprocess.run(command, check=True) 64 | 65 | 66 | if __name__ == "__main__": 67 | partition_file = os.path.join(os.getcwd(), "partition.csv") 68 | partition_name = "spiffs" 69 | dump_file = os.path.join(os.getcwd(), "spiffs_dump.bin") 70 | output_dir = os.path.join(os.getcwd(), "data") 71 | baud = 115200 72 | 73 | esptool_path = os.path.join(os.getcwd(), "tools", "esptool.exe") 74 | mkspiffs_path = os.path.join(os.getcwd(), "tools", "mkspiffs.exe") 75 | 76 | port = get_serial_port() 77 | if not port: 78 | print("Errore: impossibile trovare la porta seriale.") 79 | exit(1) 80 | 81 | offset, size = get_partition_info(partition_file, partition_name) 82 | if offset is None or size is None: 83 | print(f"Errore: partizione '{partition_name}' non trovata nel file {partition_file}.") 84 | exit(1) 85 | 86 | dump_spiffs(esptool_path, port, baud, offset, size, dump_file) 87 | extract_spiffs_with_mkspiffs(dump_file, output_dir, mkspiffs_path, target_file="passwords.txt") 88 | 89 | # os.remove(dump_file) -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/parse/management/disassociation.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #include "disassociation.h" 17 | #include "common.h" 18 | 19 | #include 20 | #include 21 | 22 | /** 23 | * TODO: potentally write a parsed_to_gen function that converts a parsed disassoc back into 24 | * something that can be passed directly into the interface? 25 | */ 26 | 27 | /** 28 | * Disassociation frames can originate from the BSS or the STA, with no way to know 29 | * who sent the frame by looking at just the frame alone. Because of this, they are 30 | * parsed into a struct libwifi_parsed_deauth instead of a libwifi_bss or libwifi_sta. 31 | * 32 | * ┌─────────────────────────────────────────────┐ 33 | * │ Header (Ordered or Unordered) │ ── Disassociation Header 34 | * ├─────────────────────────────────────────────┤ 35 | * │ Fixed Parameters │ ─┐ 36 | * ├─────────────────────────────────────────────┤ ├── Disassociation Body 37 | * │ Tagged Parameters │ ─┘ 38 | * └─────────────────────────────────────────────┘ 39 | */ 40 | int libwifi_parse_disassoc(struct libwifi_parsed_disassoc *disassoc, struct libwifi_frame *frame) { 41 | memset(disassoc, 0, sizeof(struct libwifi_parsed_disassoc)); 42 | 43 | int tags_len = 0; 44 | 45 | if (frame->frame_control.type != TYPE_MANAGEMENT || frame->frame_control.subtype != SUBTYPE_DISASSOC) { 46 | return -EINVAL; 47 | } 48 | 49 | disassoc->ordered = frame->frame_control.flags.ordered; 50 | 51 | if (disassoc->ordered) { 52 | memcpy(&disassoc->frame_header.ordered, &frame->header.mgmt_ordered, 53 | sizeof(struct libwifi_mgmt_ordered_frame_header)); 54 | tags_len = (frame->len - sizeof(struct libwifi_mgmt_ordered_frame_header) - 55 | sizeof(struct libwifi_disassoc_fixed_parameters)); 56 | } else { 57 | memcpy(&disassoc->frame_header.unordered, &frame->header.mgmt_unordered, 58 | sizeof(struct libwifi_mgmt_unordered_frame_header)); 59 | tags_len = (frame->len - sizeof(struct libwifi_mgmt_unordered_frame_header) - 60 | sizeof(struct libwifi_disassoc_fixed_parameters)); 61 | } 62 | 63 | unsigned char *body = (unsigned char *) frame->body; 64 | 65 | memcpy(&disassoc->fixed_parameters, body, sizeof(struct libwifi_disassoc_fixed_parameters)); 66 | body += sizeof(struct libwifi_disassoc_fixed_parameters); 67 | 68 | memcpy(&disassoc->tags, body, tags_len); 69 | body += tags_len; 70 | 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/gen/management/reassoc_response.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_GEN_REASSOCRESP_H 17 | #define LIBWIFI_GEN_REASSOCRESP_H 18 | 19 | #include "../../core/frame/management/reassoc_response.h" 20 | 21 | /** 22 | * Set the channel of a libwifi_reassoc_resp. 23 | * 24 | * @param reassoc_resp A libwifi_reassoc_resp 25 | * @param channel The desired channel 26 | * @return Zero on success, or negative error 27 | */ 28 | int libwifi_set_reassoc_resp_channel(struct libwifi_reassoc_resp *reassoc_resp, uint8_t channel); 29 | 30 | /** 31 | * Calculate the length of a given libwifi_reassoc_resp 32 | * 33 | * @param reassoc_resp A libwifi_reassoc_resp 34 | * @return The length of the given reassoc_resp, or negative error 35 | */ 36 | size_t libwifi_get_reassoc_resp_length(struct libwifi_reassoc_resp *reassoc_resp); 37 | 38 | /** 39 | * Generate a populated libwifi reassoc_resp. 40 | * 41 | * A generated libwifi reassoc_resp can be "dumped" into a buffer for packet injection 42 | * via the libwifi_dump_reassoc_resp. 43 | * 44 | * @param reassoc_resp A libwifi_reassoc_resp 45 | * @param receiver The receiver MAC address, aka address 1 46 | * @param transmitter The source MAC address, aka address 2 47 | * @param address3 The address 3 frame field value, typically the BSSID 48 | * @param channel The desired channel of the reassoc_resp 49 | * @return Zero on success, or negative error 50 | */ 51 | int libwifi_create_reassoc_resp(struct libwifi_reassoc_resp *reassoc_resp, 52 | const unsigned char receiver[6], 53 | const unsigned char transmitter[6], 54 | const unsigned char address3[6], 55 | uint8_t channel); 56 | 57 | /** 58 | * Dump a libwifi_reassoc_resp into a raw format for packet injection. 59 | * 60 | * @param reassoc_resp A libwifi_reassoc_resp 61 | * @param buf The output buffer for the frame data 62 | * @param buf_len The length of the output buffer 63 | * @return The length of the dumped reassoc_resp, or negative error 64 | */ 65 | size_t libwifi_dump_reassoc_resp(struct libwifi_reassoc_resp *reassoc_resp, unsigned char *buf, 66 | size_t buf_len); 67 | 68 | /** 69 | * Free any memory claimed by a libwifi_reassoc_resp back to the system. 70 | * 71 | * @param reassoc_resp A libwifi_reassoc_resp struct 72 | */ 73 | void libwifi_free_reassoc_resp(struct libwifi_reassoc_resp *reassoc_resp); 74 | 75 | #endif /* LIBWIFI_GEN_REASSOCRESP_H */ 76 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/core/frame/management/action.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_CORE_ACTIONS_H 17 | #define LIBWIFI_CORE_ACTIONS_H 18 | 19 | #include "../frame.h" 20 | #include 21 | 22 | /* Defined action fixed parameter values */ 23 | enum libwifi_actions { 24 | ACTION_SPECTRUM_MGMT = 0, 25 | ACTION_QOS = 1, 26 | // Reserved 2 27 | ACTION_BLOCK_ACK = 3, 28 | ACTION_PUBLIC = 4, 29 | ACTION_RADIO_MEASUREMENT = 5, 30 | ACTION_FAST_BSS_TRANSITION = 6, 31 | ACTION_HT = 7, 32 | ACTION_SA_QUERY = 8, 33 | ACTION_PROTECTED_DOPA = 9, 34 | ACTION_WNM = 10, 35 | ACTION_UNSUPPORTED_WNM = 11, 36 | ACTION_TDLS = 12, 37 | ACTION_MESH = 13, 38 | ACTION_MULTIHOP = 14, 39 | ACTION_SELF_PROTECTED = 15, 40 | ACTION_DMG = 16, 41 | // Reserved 17 42 | ACTION_FAST_SESSION_TRANSFER = 18, 43 | ACTION_ROBUST_AV_STREAM = 19, 44 | ACTION_UNPROTECTED_DMG = 20, 45 | ACTION_VHT = 21, 46 | ACTION_UNPROTECTED_SIG = 22, 47 | ACTION_SIG = 23, 48 | ACTION_FLOW_CONTROL = 24, 49 | ACTION_CTRL_MCS_NEG = 25, 50 | ACTION_FILS = 26, 51 | ACTION_CDMG = 27, 52 | ACTION_CMMG = 28, 53 | ACTION_GLK = 29, 54 | // Reserved 30-125 55 | ACTION_VENDOR_PROTECTED = 126, 56 | ACTION_VENDOR = 127, 57 | // Error 128-255 58 | }; 59 | 60 | /** 61 | * Action Layout 62 | * ───────────────────────────────────── 63 | * ┌─────────────────────────────────────┐ 64 | * │ Header │ Bytes: 24 65 | * ├─────────────────────────────────────┤ 66 | * │ Fixed Parameters │ Bytes: Variable 67 | * │┌───────────────────────────────────┐│ 68 | * ││ category ││ Bytes: 1 69 | * │├───────────────────────────────────┤│ 70 | * ││ detail ││ Bytes: Variable 71 | * ││┌─────────────────────────────────┐││ 72 | * │││ tagged parameters │││ 73 | * ││└─────────────────────────────────┘││ 74 | * │└───────────────────────────────────┘│ 75 | * └─────────────────────────────────────┘ 76 | */ 77 | 78 | struct libwifi_action_detail { 79 | uint8_t detail_length; 80 | char *detail; 81 | } __attribute__((packed)); 82 | 83 | struct libwifi_action_fixed_parameters { 84 | uint8_t category; 85 | struct libwifi_action_detail details; 86 | } __attribute__((packed)); 87 | 88 | struct libwifi_action { 89 | struct libwifi_mgmt_unordered_frame_header frame_header; 90 | struct libwifi_action_fixed_parameters fixed_parameters; 91 | } __attribute__((packed)); 92 | 93 | #endif /* LIBWIFI_CORE_ACTIONS_H */ 94 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/parse/data/eapol.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_PARSE_EAPOL_H 17 | #define LIBWIFI_PARSE_EAPOL_H 18 | 19 | #include "../../core/frame/frame.h" 20 | #include "../../core/misc/security.h" 21 | 22 | enum WPA_HANDSHAKE_PART { 23 | HANDSHAKE_M1 = 1, 24 | HANDSHAKE_M2 = 2, 25 | HANDSHAKE_M3 = 4, 26 | HANDSHAKE_M4 = 8, 27 | HANDSHAKE_INVALID = 16 28 | }; 29 | 30 | /** 31 | * Check if a libwifi_frame contains a WPA1/2 handshake message. 32 | * 33 | * @param libwifi_frame A libwifi_frame 34 | * @return 1 if a handshake is detected, 0 if not. 35 | */ 36 | int libwifi_check_wpa_handshake(struct libwifi_frame *frame); 37 | 38 | /** 39 | * Check what message of the WPA1/2 handshake is in the given frame. 40 | * 41 | * The returned value can be used with the WPA_HANDSHAKE_PART enum, 42 | * such as: 43 | * 44 | * part = libwifi_check_wpa_message(frame); 45 | * if (part & HANDSHAKE_M1) { 46 | * // This is EAPOL Message 1 47 | * } 48 | * 49 | * @param libwifi_frame A libwifi_frame 50 | * @return A bitmask of parts. 51 | */ 52 | int libwifi_check_wpa_message(struct libwifi_frame *frame); 53 | 54 | /** 55 | * Get a string describing the WPA handshake message inside a supplied libwifi_frame. 56 | * 57 | * @param libwifi_frame A libwifi_frame 58 | * @return A string describing the WPA handshake message found 59 | */ 60 | const char *libwifi_get_wpa_message_string(struct libwifi_frame *frame); 61 | 62 | /** 63 | * Get the length of the key data, if any, present at the end of an EAPOL frame. 64 | * 65 | * @param libwifi_frame A libwifi_frame 66 | * @return The length of the key data 67 | */ 68 | int libwifi_get_wpa_key_data_length(struct libwifi_frame *frame); 69 | 70 | /** 71 | * Get the EAPOL/WPA information from a given libwifi_frame. 72 | * 73 | * As the values in the frame below and including the logical link control layer will be in 74 | * network byte order, the values will be automatically byte swapped if necessary to match 75 | * the host systems byte order. 76 | * 77 | * @param libwifi_frame A libwifi_frame 78 | * @param data A pointer to a libwifi_wpa_auth_data struct 79 | * @return 0 on success, -1 on failure 80 | */ 81 | int libwifi_get_wpa_data(struct libwifi_frame *frame, struct libwifi_wpa_auth_data *data); 82 | 83 | /** 84 | * Free any memory allocated inside of a libwifi_wpa_auth data, such as a buffer 85 | * for WPA key data allocated by the library. 86 | * 87 | * @param data A pointer to a libwifi_wpa_auth_data struct 88 | */ 89 | void libwifi_free_wpa_data(struct libwifi_wpa_auth_data *data); 90 | 91 | #endif /* LIBWIFI_PARSE_EAPOL_H */ 92 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/core/frame/management/timing_ad.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef LIBWIFI_CORE_TIMINGAD_H 17 | #define LIBWIFI_CORE_TIMINGAD_H 18 | 19 | #include 20 | #include "../frame.h" 21 | #include "../tag.h" 22 | 23 | /** 24 | * Timing Advertisement Layout 25 | * ────────────────────────────────── 26 | * ┌──────────────────────────────────┐ 27 | * │ Header │ Bytes: 24 28 | * ├──────────────────────────────────┤ 29 | * │ Fixed Parameters │ Bytes: 6 30 | * │┌────────────────────────────────┐│ 31 | * ││ timestamp ││ Bytes: 8 32 | * │├────────────────────────────────┤│ 33 | * ││ measurement pilot interval ││ Bytes: 1 34 | * │├────────────────────────────────┤│ 35 | * ││ beacon interval ││ Bytes: 2 36 | * │├────────────────────────────────┤│ 37 | * ││ capabilities information ││ Bytes: 2 38 | * │├────────────────────────────────┤│ 39 | * ││ country code ││ Bytes: 3 40 | * │├────────────────────────────────┤│ 41 | * ││ maxmimum regulatory power ││ Bytes: 2 42 | * │├────────────────────────────────┤│ 43 | * ││ maximum transmit power ││ Bytes: 1 44 | * │├────────────────────────────────┤│ 45 | * ││ transmit power used ││ Bytes: 1 46 | * │├────────────────────────────────┤│ 47 | * ││ noise floor ││ Bytes: 1 48 | * │└────────────────────────────────┘│ 49 | * ├──────────────────────────────────┤ 50 | * │ Tagged Parameters │ Bytes: Variable 51 | * │┌────────────────────────────────┐│ 52 | * ││ timing advert fields ││ Bytes: 17 53 | * │└────────────────────────────────┘│ 54 | * └──────────────────────────────────┘ 55 | */ 56 | 57 | struct libwifi_timing_advert_fields { 58 | uint8_t timing_capabilities; 59 | unsigned char time_value[10]; 60 | unsigned char time_error[5]; 61 | unsigned char time_update[1]; 62 | } __attribute__((packed)); 63 | 64 | struct libwifi_timing_advert_fixed_params { 65 | uint64_t timestamp; 66 | uint8_t measurement_pilot_interval; 67 | uint16_t beacon_interval; 68 | uint16_t capabilities_information; 69 | char country[3]; 70 | uint16_t max_reg_power; 71 | uint8_t max_tx_power; 72 | uint8_t tx_power_used; 73 | uint8_t noise_floor; 74 | } __attribute__((packed)); 75 | 76 | struct libwifi_timing_advert { 77 | struct libwifi_mgmt_unordered_frame_header frame_header; 78 | struct libwifi_timing_advert_fixed_params fixed_parameters; 79 | struct libwifi_tagged_parameters tags; 80 | } __attribute__((packed)); 81 | 82 | #endif /* LIBWIFI_CORE_TIMINGAD_H */ 83 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/parse/management/deauthentication.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2021 The libwifi Authors 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #include "deauthentication.h" 17 | #include "common.h" 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | /** 24 | * TODO: potentally write a parsed_to_gen function that converts a parsed deauth back into 25 | * something that can be passed directly into the interface? 26 | */ 27 | 28 | /** 29 | * Deauthentication frames can originate from the BSS or the STA, with no way to know 30 | * who sent the frame by looking at just the frame alone. Because of this, they are 31 | * parsed into a struct libwifi_parsed_deauth instead of a libwifi_bss or libwifi_sta. 32 | * 33 | * ┌─────────────────────────────────────────────┐ 34 | * │ Header (Ordered or Unordered) │ ── Deauthentication Header 35 | * ├─────────────────────────────────────────────┤ 36 | * │ Fixed Parameters │ ─┐ 37 | * ├─────────────────────────────────────────────┤ ├── Deauthentication Body 38 | * │ Tagged Parameters │ ─┘ 39 | * └─────────────────────────────────────────────┘ 40 | */ 41 | int libwifi_parse_deauth(struct libwifi_parsed_deauth *deauth, struct libwifi_frame *frame) { 42 | memset(deauth, 0, sizeof(struct libwifi_parsed_deauth)); 43 | 44 | int tags_len = 0; 45 | 46 | if (frame->frame_control.type != TYPE_MANAGEMENT || frame->frame_control.subtype != SUBTYPE_DEAUTH) { 47 | return -EINVAL; 48 | } 49 | 50 | deauth->ordered = frame->frame_control.flags.ordered; 51 | 52 | if (deauth->ordered) { 53 | memcpy(&deauth->frame_header.ordered, &frame->header.mgmt_ordered, 54 | sizeof(struct libwifi_mgmt_ordered_frame_header)); 55 | tags_len = (frame->len - sizeof(struct libwifi_mgmt_ordered_frame_header) - 56 | sizeof(struct libwifi_deauth_fixed_parameters)); 57 | } else { 58 | memcpy(&deauth->frame_header.unordered, &frame->header.mgmt_unordered, 59 | sizeof(struct libwifi_mgmt_unordered_frame_header)); 60 | tags_len = (frame->len - sizeof(struct libwifi_mgmt_unordered_frame_header) - 61 | sizeof(struct libwifi_deauth_fixed_parameters)); 62 | } 63 | 64 | unsigned char *body = (unsigned char *) frame->body; 65 | 66 | memcpy(&deauth->fixed_parameters, body, sizeof(struct libwifi_deauth_fixed_parameters)); 67 | body += sizeof(struct libwifi_deauth_fixed_parameters); 68 | 69 | deauth->tags.parameters = malloc(tags_len); 70 | memcpy(&deauth->tags.parameters, body, tags_len); 71 | memcpy(&deauth->tags.length, &tags_len, sizeof(tags_len)); 72 | 73 | return 0; 74 | } 75 | -------------------------------------------------------------------------------- /lib/libwifi/test/README.md: -------------------------------------------------------------------------------- 1 | # libwifi Tests 2 | libwifi uses CMakes testing functionalities. The tests are in the `src/` directory, and can be used with `make test`. 3 | 4 | ## Running Tests 5 | ``` 6 | >> mkdir build 7 | >> cd build 8 | >> cmake .. 9 | >> make && make test 10 | ``` 11 | 12 | ## Expected Output 13 | ``` 14 | >> make test 15 | Running tests... 16 | Test project libwifi/test/build 17 | Start 1: test_action_gen_full 18 | 1/24 Test #1: test_action_gen_full ............. Passed 0.00 sec 19 | Start 2: test_action_gen_details 20 | 2/24 Test #2: test_action_gen_details .......... Passed 0.00 sec 21 | Start 3: test_assoc_req_gen_full 22 | 3/24 Test #3: test_assoc_req_gen_full .......... Passed 0.00 sec 23 | Start 4: test_assoc_req_gen_tags 24 | 4/24 Test #4: test_assoc_req_gen_tags .......... Passed 0.00 sec 25 | Start 5: test_assoc_resp_gen_full 26 | 5/24 Test #5: test_assoc_resp_gen_full ......... Passed 0.00 sec 27 | Start 6: test_assoc_resp_gen_tags 28 | 6/24 Test #6: test_assoc_resp_gen_tags ......... Passed 0.00 sec 29 | Start 7: test_atim_gen_full 30 | 7/24 Test #7: test_atim_gen_full ............... Passed 0.00 sec 31 | Start 8: test_auth_gen_full 32 | 8/24 Test #8: test_auth_gen_full ............... Passed 0.00 sec 33 | Start 9: test_auth_gen_tags 34 | 9/24 Test #9: test_auth_gen_tags ............... Passed 0.00 sec 35 | Start 10: test_beacon_gen_full 36 | 10/24 Test #10: test_beacon_gen_full ............. Passed 0.00 sec 37 | Start 11: test_beacon_gen_tags 38 | 11/24 Test #11: test_beacon_gen_tags ............. Passed 0.00 sec 39 | Start 12: test_deauth_gen_full 40 | 12/24 Test #12: test_deauth_gen_full ............. Passed 0.00 sec 41 | Start 13: test_deauth_gen_tags 42 | 13/24 Test #13: test_deauth_gen_tags ............. Passed 0.00 sec 43 | Start 14: test_disassoc_gen_full 44 | 14/24 Test #14: test_disassoc_gen_full ........... Passed 0.00 sec 45 | Start 15: test_disassoc_gen_tags 46 | 15/24 Test #15: test_disassoc_gen_tags ........... Passed 0.00 sec 47 | Start 16: test_probe_req_gen_full 48 | 16/24 Test #16: test_probe_req_gen_full .......... Passed 0.00 sec 49 | Start 17: test_probe_req_gen_tags 50 | 17/24 Test #17: test_probe_req_gen_tags .......... Passed 0.00 sec 51 | Start 18: test_probe_resp_gen_full 52 | 18/24 Test #18: test_probe_resp_gen_full ......... Passed 0.00 sec 53 | Start 19: test_probe_resp_gen_tags 54 | 19/24 Test #19: test_probe_resp_gen_tags ......... Passed 0.00 sec 55 | Start 20: test_reassoc_req_gen_full 56 | 20/24 Test #20: test_reassoc_req_gen_full ........ Passed 0.00 sec 57 | Start 21: test_reassoc_req_gen_tags 58 | 21/24 Test #21: test_reassoc_req_gen_tags ........ Passed 0.00 sec 59 | Start 22: test_reassoc_resp_gen_full 60 | 22/24 Test #22: test_reassoc_resp_gen_full ....... Passed 0.00 sec 61 | Start 23: test_reassoc_resp_gen_tags 62 | 23/24 Test #23: test_reassoc_resp_gen_tags ....... Passed 0.00 sec 63 | Start 24: test_timing_ad_gen_tags 64 | 24/24 Test #24: test_timing_ad_gen_tags .......... Passed 0.00 sec 65 | 66 | 100% tests passed, 0 tests failed out of 24 67 | 68 | Total Test time (real) = 0.06 sec 69 | ``` 70 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBWIFI_H 2 | #define LIBWIFI_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "libwifi/core/core.h" 9 | #include "libwifi/core/frame/control/cts.h" 10 | #include "libwifi/core/frame/control/rts.h" 11 | #include "libwifi/core/frame/crc.h" 12 | #include "libwifi/core/frame/data/data.h" 13 | #include "libwifi/core/frame/frame.h" 14 | #include "libwifi/core/frame/management/action.h" 15 | #include "libwifi/core/frame/management/assoc_request.h" 16 | #include "libwifi/core/frame/management/assoc_response.h" 17 | #include "libwifi/core/frame/management/atim.h" 18 | #include "libwifi/core/frame/management/authentication.h" 19 | #include "libwifi/core/frame/management/beacon.h" 20 | #include "libwifi/core/frame/management/common.h" 21 | #include "libwifi/core/frame/management/deauthentication.h" 22 | #include "libwifi/core/frame/management/disassociation.h" 23 | #include "libwifi/core/frame/management/probe_request.h" 24 | #include "libwifi/core/frame/management/probe_response.h" 25 | #include "libwifi/core/frame/management/reassoc_request.h" 26 | #include "libwifi/core/frame/management/reassoc_response.h" 27 | #include "libwifi/core/frame/management/timing_ad.h" 28 | #include "libwifi/core/frame/tag.h" 29 | #include "libwifi/core/frame/tag_iterator.h" 30 | #include "libwifi/core/misc/byteswap.h" 31 | #include "libwifi/core/misc/epoch.h" 32 | #include "libwifi/core/misc/llc.h" 33 | #include "libwifi/core/misc/radiotap.h" 34 | #include "libwifi/core/misc/security.h" 35 | #include "libwifi/core/misc/types.h" 36 | #include "libwifi/core/radiotap/platform.h" 37 | #include "libwifi/core/radiotap/radiotap.h" 38 | #include "libwifi/core/radiotap/radiotap_iter.h" 39 | #include "libwifi/gen/control/cts.h" 40 | #include "libwifi/gen/control/rts.h" 41 | #include "libwifi/gen/management/action.h" 42 | #include "libwifi/gen/management/assoc_request.h" 43 | #include "libwifi/gen/management/assoc_response.h" 44 | #include "libwifi/gen/management/atim.h" 45 | #include "libwifi/gen/management/authentication.h" 46 | #include "libwifi/gen/management/beacon.h" 47 | #include "libwifi/gen/management/common.h" 48 | #include "libwifi/gen/management/deauthentication.h" 49 | #include "libwifi/gen/management/disassociation.h" 50 | #include "libwifi/gen/management/probe_request.h" 51 | #include "libwifi/gen/management/probe_response.h" 52 | #include "libwifi/gen/management/reassoc_request.h" 53 | #include "libwifi/gen/management/reassoc_response.h" 54 | #include "libwifi/gen/management/timing_ad.h" 55 | #include "libwifi/gen/misc/radiotap.h" 56 | #include "libwifi/parse/data/data.h" 57 | #include "libwifi/parse/data/eapol.h" 58 | #include "libwifi/parse/management/assoc_request.h" 59 | #include "libwifi/parse/management/assoc_response.h" 60 | #include "libwifi/parse/management/beacon.h" 61 | #include "libwifi/parse/management/common.h" 62 | #include "libwifi/parse/management/deauthentication.h" 63 | #include "libwifi/parse/management/disassociation.h" 64 | #include "libwifi/parse/management/probe_request.h" 65 | #include "libwifi/parse/management/probe_response.h" 66 | #include "libwifi/parse/management/reassoc_request.h" 67 | #include "libwifi/parse/management/reassoc_response.h" 68 | #include "libwifi/parse/misc/radiotap.h" 69 | #include "libwifi/parse/misc/security.h" 70 | 71 | #ifdef __cplusplus 72 | } 73 | #endif 74 | 75 | #endif /* LIBWIFI_H */ 76 | -------------------------------------------------------------------------------- /lib/libwifi/src/libwifi/core/radiotap/platform.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #if defined(linux) || defined(Linux) || defined(__linux__) || defined(__linux) || defined(__gnu_linux__) 6 | #include 7 | #if defined(__UCLIBC__) 8 | #include 9 | #ifndef le16toh 10 | #define le16toh __le16_to_cpu 11 | #endif 12 | #ifndef le32toh 13 | #define le32toh __le32_to_cpu 14 | #endif 15 | #endif 16 | #endif 17 | 18 | #if defined(__CYGWIN32__) || defined(CYGWIN) 19 | #include 20 | #include 21 | #endif 22 | 23 | #if defined(__APPLE__) 24 | #include 25 | #endif 26 | 27 | #if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) || defined(__MidnightBSD__) || \ 28 | defined(__NetBSD__) 29 | #include 30 | #include 31 | #endif 32 | 33 | #if defined(__SVR4) && defined(__sun__) 34 | #include 35 | #include 36 | #endif 37 | 38 | #if defined(ESP_PLATFORM) 39 | #include "endian.h" 40 | #endif 41 | 42 | #ifndef le16_to_cpu 43 | #define le16_to_cpu le16toh 44 | #endif 45 | 46 | #ifndef le32_to_cpu 47 | #define le32_to_cpu le32toh 48 | #endif 49 | 50 | #if defined(_MSC_VER) 51 | // Microsoft 52 | #define EXPORT __declspec(dllexport) 53 | #define IMPORT __declspec(dllimport) 54 | #elif defined(__GNUC__) || defined(__llvm__) || defined(__clang__) || defined(__INTEL_COMPILER) 55 | #define EXPORT __attribute__((visibility("default"))) 56 | #define IMPORT 57 | #else 58 | // do nothing and hope for the best? 59 | #define EXPORT 60 | #define IMPORT 61 | #pragma warning Unknown dynamic link import / export semantics. 62 | #endif 63 | 64 | #if defined(RADIOTAP_FAST_UNALIGNED_ACCESS) 65 | #define get_unaligned(p) \ 66 | __extension__({ \ 67 | struct packed_dummy_struct { \ 68 | typeof(*(p)) __val; \ 69 | } __attribute__((packed)) *__ptr = (void *) (p); \ 70 | \ 71 | __ptr->__val; \ 72 | }) 73 | #else 74 | #define get_unaligned(p) \ 75 | __extension__({ \ 76 | typeof(*(p)) __tmp; \ 77 | memmove(&__tmp, (p), sizeof(*(p))); \ 78 | __tmp; \ 79 | }) 80 | #endif 81 | 82 | #define get_unaligned_le16(p) le16_to_cpu(get_unaligned((uint16_t *) (p))) 83 | #define get_unaligned_le32(p) le32_to_cpu(get_unaligned((uint32_t *) (p))) 84 | 85 | #define UNALIGNED_ADDRESS(x) ((void *) (x)) 86 | --------------------------------------------------------------------------------