Hello, everybody!
I have a question about how to implement user deauthentication in such a way that the client does not immediately try to reconnect. ESP32 is in SoftAP mode.
Right now I am using the standard deauth procedure, but a Windows client reconnects almost instantly.
What I would like to do is make the decision whether the connection is allowed or not at the event level. For example, when the `STA_CONNECTED` event is received, the callback checks some condition and performs a deauth if the client should not be allowed to connect.
If it were possible to specify the disconnect reason code sent to the remote side, this problem could be solved by returning a code similar to *"password incorrect"*. In my experience Windows usually stops retrying after such an error. However, I couldn't find a way to set the disconnect reason.
At the moment I implemented a workaround where I maintain my own blacklist with a timer, but this does not feel like a proper solution.
Is there a way in ESP-IDF to control the deauth/disconnect reason code sent to the station?
Controlled WiFi deauth / Disconnect reason question
Re: Controlled WiFi deauth / Disconnect reason question
I looked into Espressif code and found that disconnect reason is hardcoded to be "2".
The solution is to
1) modify ld_flags file and add "-lW,wrap=ieee80211_send_mgmt"
2) add to your code
This code intercepts calls to ieee80211_send_mgmt() and replaces reason code when it is required. 0xa0 and 0xc0 are DISASSOC and DEAUTH. These are sent together wehn esp_wifi_deauth_sta() is called
3) Recompile everything
The solution is to
1) modify ld_flags file and add "-lW,wrap=ieee80211_send_mgmt"
2) add to your code
Code: Select all
extern "C" int ieee80211_send_mgmt(int, int, int);
int __wrap_ieee80211_send_mgmt(int a, int code, int reason) {
if (code == 0xa0 || code == 0xc0)
reason = 17; // or another appropriate reason
return __real_ieee80211_send_mgmt(a, code, reason);
}
3) Recompile everything
Thanks!
Slava.
Slava.
Who is online
Users browsing this forum: akashgaur0001, Bing [Bot], ChatGPT-User, Google [Bot], Qwantbot and 3 guests