Hello everyone,
Today we are going to unlock some interesting capabilities of the ESP32-S3, ESP32-S2, and ESP32.
What is written below will most likely work on other ESP32 models as well, but everything here was tested only on ESP32-S3.
INTRODUCTION TO THE PROBLEM
In short: starting from a certain version of their SDK, Espressif exposed a previously hidden function:
esp_err_t esp_wifi_80211_tx(
wifi_interface_t ifx,
const void *buffer,
int len,
bool en_sys_seq
);
Yes, exactly what you think - a function for sending a raw WiFi frame.
However, since such a tool can be potentially dangerous in capable hands, Espressif engineers restricted the types of WiFi packets that can be sent using this function to a rather uninteresting set:
“Attention Currently only support for sending beacon/probe request/probe response/action and non-QoS data frame”
We are going to get rid of this limitation in the Arduino environment, to turn our ESP32 into versatile WiFi testing tool.
HOW LIMITATION WORKS
The WiFi stack that makes Espressif chips so popular contains both open and precompiled parts. As usual, the most interesting pieces are in the closed-source part.
The functions we are interested in are mainly located in the library libnet80211.a (it is installed together with ESP32 board support in Arduino IDE).
That is where we are going to dig.
2025-09-23 06:24 PM 4,848 libcore.a
2025-09-23 06:24 PM 62,174 libespnow.a
2025-09-23 06:24 PM 995,432 libmesh.a
2025-09-23 06:24 PM 1,387,762 libnet80211.a <-- This one
2025-09-23 06:24 PM 706,754 libpp.a
2025-09-23 06:24 PM 196,186 libsmartconfig.a
2025-09-23 06:24 PM 52,466 libwapi.a
First, let’s unpack the library using:
ar x libnet80211.a
(if you are on Linux or Windows + Cygwin)
A lot of files should appear. Among them, we need the one that contains:
esp_wifi_80211_tx()
This will be the file:
ieee80211_output.o
Inside it, locate the function esp_wifi_80211_tx.
You should see something approximately like this (not directly visible. requires some processing):
/**
* @brief Send raw ieee80211 data
*
* @attention Currently only support for sending beacon/probe request/probe response/action and non-QoS
* data frame
*
* @param ifx interface if the Wi-Fi mode is Station, the ifx should be WIFI_IF_STA. If the Wi-Fi
* mode is SoftAP, the ifx should be WIFI_IF_AP. If the Wi-Fi mode is Station+SoftAP, the
* ifx should be WIFI_IF_STA or WIFI_IF_AP. If the ifx is wrong, the API returns ESP_ERR_WIFI_IF.
* @param buffer raw ieee80211 buffer
* @param len the length of raw buffer, the len must be <= 1500 Bytes and >= 24 Bytes
* @param en_sys_seq indicate whether use the internal sequence number. If en_sys_seq is false, the
* sequence in raw buffer is unchanged, otherwise it will be overwritten by WiFi driver with
* the system sequence number.
* Generally, if esp_wifi_80211_tx is called before the Wi-Fi connection has been set up, both
* en_sys_seq==true and en_sys_seq==false are fine. However, if the API is called after the Wi-Fi
* connection has been set up, en_sys_seq must be true, otherwise ESP_ERR_INVALID_ARG is returned.
*
* @return
* - ESP_OK: success
* - ESP_ERR_WIFI_IF: Invalid interface
* - ESP_ERR_INVALID_ARG: Invalid parameter
* - ESP_ERR_WIFI_NO_MEM: out of memory
*/
esp_err_t esp_wifi_80211_tx(wifi_interface_t ifx, const void *buffer, int len, bool en_sys_seq) {
int err;
ic_ebuf_t *ebuf;
....
....
....
// Check if user frame is OK to send. Check hw addresses and other frame field.
// In order to send an arbitrary frame one needs to wrap this call via
// -Wl,wrap=ieee80211_raw_frame_sanity_check
// and implement "always ok"
//
err = ieee80211_raw_frame_sanity_check(ifx,buffer,length,sys_seq_en);
if (err == ESP_OK) {
OSI_MUTEX_LOCK(g_wifi_global_lock);
// allocate ebuf and copy data into it
//
ebuf = (ic_ebuf_t *)ic_ebuf_alloc(buffer,1,length);
if (ebuf == NULL) {
OSI_UNLOCK(g_wifi_global_lock);
err = ESP_ERR_WIFI_NO_MEM;
} else {
....
.... // Configure TX descriptors
....
// Enqueue our frame for transmission.
//
ieee80211_post_hmac_tx(ebuf);
OSI_MUTEX_UNLOCK(g_wifi_global_lock);
}
}
return err;
}
Right at the beginning of the code, we can see the check itself - the call to:
ieee80211_raw_frame_sanity_check()
This function performs many checks on the provided buffer, filtering out packets it considers “invalid”.
For example, it validates header addresses, so that:
- STA cannot send a frame with a spoofed Source Address
- AP mode cannot send packets to arbitrary MAC addresses, only to connected stations
We need to bypass this check.
BYPASSING SANITY CHECKS
Now we need to make sanity_check always return 0, i.e. “check passed successfully”. This can be done in several ways, including patching Espressif blobs or other modification to the existing code base.
We will do it in the most direct and fully official way - we will ask the linker to replace the original check function with our own implementation.
This method does not modify Espressif’s binary code, so it does not violate their license terms.
Our new “check” function will be delightfully simple:
int ieee80211_raw_frame_sanity_check(...) {
return 0;
}
LINKER SETUP
Find the ld_flags file in the ESP32 Arduino Core installation
(there are several of them, one for each CPU).
There you will see one long line of linker options.
Add:
-Wl,--wrap=ieee80211_raw_frame_sanity_check
You can put it at the beginning or somewhere in the middle - it does not matter.
ADD A C FILE TO YOUR PROJECT
Create a C file in your Arduino project, for example:
wifi_bypass.c
// Bypassing WiFi frame checks
//
#include <Arduino.h> // :)
#include <stdbool.h>
// "It's fine"
//
int __wrap_ieee80211_raw_frame_sanity_check(
int ifx,
const void *buffer,
int len,
bool auto_seq
) {
ifx = ifx;
buffer = buffer;
len = len;
auto_seq = auto_seq;
return 0;
}
#include "esp_wifi.h"
#include <stdio.h>
#include <inttypes.h>
#include <string.h>
// Simple IEEE 802.11 frame with type=data and random MAC addresses
// https://en.wikipedia.org/wiki/802.11_frame_types
//
uint8_t ieee80211header[] = {
0x48, 0x00, 0x00, 0x00, // Frame control and Duration
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // Addr1
0x10, 0x22, 0x33, 0x44, 0x55, 0x66, // Addr2
0x10, 0x22, 0x33, 0x44, 0x55, 0x66, // Addr3
0x00, 0x00, // Seq No
};
uint8_t data_you_want_to_send[] = {
0x12, 0x34, 0x56, 0x78
};
// WiFi must be initialized in STA or AP+STA mode
// No connection needs to be made
//
void send_packet() {
char buf[sizeof(ieee80211header) + sizeof(data_you_want_to_send)];
memcpy(buf, &ieee80211header, sizeof(ieee80211header));
memcpy(buf + sizeof(ieee80211header),
&data_you_want_to_send,
sizeof(data_you_want_to_send));
int err = esp_wifi_80211_tx(WIFI_IF_STA, buf, sizeof(buf), false);
if (err != ESP_OK) {
printf("error while sending packet");
}
}
IMPORTANT FINAL TOUCH
Make the original function an unresolved external.
Add this:
extern "C" int ieee80211_raw_frame_sanity_check(int,const void *,int,bool);
to the file where you plan to use:
esp_wifi_80211_tx()
for example, your .ino file.
HOW IT WORKS
During linking, all calls to:
ieee80211_raw_frame_sanity_check()
are replaced with calls to:
__wrap_ieee80211_raw_frame_sanity_check()
This replacement is global, meaning it also applies inside precompiled closed-source libraries.
So code that previously called the original function will now call our wrapper.
And our wrapper simply returns:
0
meaning “everything is OK”.
If absolutely necessary, the original function is still available via:
__real_ieee80211_raw_frame_sanity_check(int,const void *,int,bool);
This way the check will always return success and the packet will be transmitted.
Final Note
Happy WiFi experiments!
Please stay within the law and only test on networks you own or are authorized to use.