Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RSDK-10288] sta disconnect events log #452

6 changes: 6 additions & 0 deletions micro-rdk/src/esp32/conn/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,12 @@ impl Esp32ExternallyManagedNetwork {
&& ev_id == esp_idf_svc::sys::wifi_event_t_WIFI_EVENT_STA_DISCONNECTED
{
data.connected.store(false, Ordering::Release);
if !ev_data.is_null() {
let disconn: *const esp_idf_svc::sys::wifi_event_sta_disconnected_t =
unsafe { core::mem::transmute(ev_data) };
let reason: super::wifi_error::WifiErrReason = (*disconn).reason.into();
log::error!("sta disconnected: {:?}", reason);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that the intention of this ticket (which was admittedly light on details) was to actually inspect the internal structure of the StaConnected and StaDisconnected events up around line 200 and report interesting context around these events (probably disconnection is generally more interesting).

Copy link
Member Author

@mattjperez mattjperez Mar 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's probably a better place than where I found originally, yeah.
I shifted the logging to there if you'd like to take a look.

So does that mean we want to look deeper into StaConnected as well for this ticket? It seems we would be able to log the ssid but not much else, https://docs.esp-rs.org/esp-idf-svc/esp_idf_svc/wifi/struct.StaConnectedRef.html.

I guess it could make sense given we now support multiple wifi, but need to test to see what the output is currently so we're not adding 'duplicate' logs

}
}

if ev_base == esp_idf_svc::sys::ETH_EVENT
Expand Down
171 changes: 171 additions & 0 deletions micro-rdk/src/esp32/conn/wifi_error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
#![allow(non_snake_case)]
use esp_idf_svc::sys::*;
use core::ffi::c_uint;

impl From<u8> for WifiErrReason {
fn from(value: u8) -> Self {
(value as c_uint).into()
}
}

impl From<c_uint> for WifiErrReason {
fn from(v: c_uint) -> Self {
match v {
wifi_err_reason_t_WIFI_REASON_UNSPECIFIED => Self::Unspecified(v),
wifi_err_reason_t_WIFI_REASON_AUTH_EXPIRE => Self::AuthExpire(v),
wifi_err_reason_t_WIFI_REASON_AUTH_LEAVE => Self::AuthLeave(v),
wifi_err_reason_t_WIFI_REASON_ASSOC_EXPIRE => Self::AssocExpire(v),
wifi_err_reason_t_WIFI_REASON_ASSOC_TOOMANY => Self::AssocTooMany(v),
wifi_err_reason_t_WIFI_REASON_NOT_AUTHED => Self::NotAuthed(v),
wifi_err_reason_t_WIFI_REASON_NOT_ASSOCED => Self::NotAssoced(v),
wifi_err_reason_t_WIFI_REASON_ASSOC_LEAVE => Self::AssocLeave(v),
wifi_err_reason_t_WIFI_REASON_ASSOC_NOT_AUTHED => Self::AssocNotAuthed(v),
wifi_err_reason_t_WIFI_REASON_DISASSOC_PWRCAP_BAD => Self::DisassocPwrCapBad(v),
wifi_err_reason_t_WIFI_REASON_DISASSOC_SUPCHAN_BAD => Self::DisassocSupchanBad(v),
wifi_err_reason_t_WIFI_REASON_BSS_TRANSITION_DISASSOC => Self::BssTransitionDisassoc(v),
wifi_err_reason_t_WIFI_REASON_IE_INVALID => Self::IeInvalid(v),
wifi_err_reason_t_WIFI_REASON_MIC_FAILURE => Self::MicFailure(v),
wifi_err_reason_t_WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT => {
Self::FourWayHandshakeTimeout(v)
}
wifi_err_reason_t_WIFI_REASON_GROUP_KEY_UPDATE_TIMEOUT => {
Self::GroupKeyUpdateTimeout(v)
}
wifi_err_reason_t_WIFI_REASON_IE_IN_4WAY_DIFFERS => Self::IeInFourWayDiffers(v),
wifi_err_reason_t_WIFI_REASON_GROUP_CIPHER_INVALID => Self::GroupCipherInvalid(v),
wifi_err_reason_t_WIFI_REASON_PAIRWISE_CIPHER_INVALID => Self::PairwiseCipherInvalid(v),
wifi_err_reason_t_WIFI_REASON_AKMP_INVALID => Self::AkmpInvalid(v),
wifi_err_reason_t_WIFI_REASON_UNSUPP_RSN_IE_VERSION => Self::UnsuppRsnIeVersion(v),

wifi_err_reason_t_WIFI_REASON_INVALID_RSN_IE_CAP => Self::InvalidRsnIeCap(v),
wifi_err_reason_t_WIFI_REASON_802_1X_AUTH_FAILED => Self::AuthFailed802_1x(v),
wifi_err_reason_t_WIFI_REASON_CIPHER_SUITE_REJECTED => Self::CipherSuiteRejected(v),
wifi_err_reason_t_WIFI_REASON_TDLS_PEER_UNREACHABLE => Self::TDlsPeerUnreachable(v),
wifi_err_reason_t_WIFI_REASON_TDLS_UNSPECIFIED => Self::TDlsUnspecified(v),

wifi_err_reason_t_WIFI_REASON_SSP_REQUESTED_DISASSOC => Self::SspRequestedDisassoc(v),
wifi_err_reason_t_WIFI_REASON_NO_SSP_ROAMING_AGREEMENT => {
Self::NoSspRoamingAgreement(v)
}
wifi_err_reason_t_WIFI_REASON_BAD_CIPHER_OR_AKM => Self::BadCipherOrAkm(v),
wifi_err_reason_t_WIFI_REASON_NOT_AUTHORIZED_THIS_LOCATION => {
Self::NotAuthorizedThisLocation(v)
}
wifi_err_reason_t_WIFI_REASON_SERVICE_CHANGE_PERCLUDES_TS => {
Self::ServiceChangePrecludesTs(v)
}
wifi_err_reason_t_WIFI_REASON_UNSPECIFIED_QOS => Self::UnspecifiedQos(v),
wifi_err_reason_t_WIFI_REASON_NOT_ENOUGH_BANDWIDTH => Self::NotEnoughBandwidth(v),
wifi_err_reason_t_WIFI_REASON_MISSING_ACKS => Self::MissingAcks(v),
wifi_err_reason_t_WIFI_REASON_EXCEEDED_TXOP => Self::ExceededTxOp(v),
wifi_err_reason_t_WIFI_REASON_STA_LEAVING => Self::StaLeaving(v),
wifi_err_reason_t_WIFI_REASON_END_BA => Self::EndBA(v),
wifi_err_reason_t_WIFI_REASON_UNKNOWN_BA => Self::UnknownBA(v),

wifi_err_reason_t_WIFI_REASON_TIMEOUT => Self::Timeout(v),
wifi_err_reason_t_WIFI_REASON_PEER_INITIATED => Self::PeerInitiated(v),
wifi_err_reason_t_WIFI_REASON_AP_INITIATED => Self::ApInitiated(v),
wifi_err_reason_t_WIFI_REASON_INVALID_FT_ACTION_FRAME_COUNT => {
Self::InvalidFtActionFrameCount(v)
}
wifi_err_reason_t_WIFI_REASON_INVALID_PMKID => Self::InvalidPmkid(v),
wifi_err_reason_t_WIFI_REASON_INVALID_MDE => Self::InvalidMde(v),
wifi_err_reason_t_WIFI_REASON_INVALID_FTE => Self::InvalidFte(v),

wifi_err_reason_t_WIFI_REASON_TRANSMISSION_LINK_ESTABLISH_FAILED => {
Self::TransmissionLinkEstablishFailed(v)
}
wifi_err_reason_t_WIFI_REASON_ALTERATIVE_CHANNEL_OCCUPIED => {
Self::AlternativeChannelOccupied(v)
}
wifi_err_reason_t_WIFI_REASON_BEACON_TIMEOUT => Self::BeaconTimeout(v),
wifi_err_reason_t_WIFI_REASON_NO_AP_FOUND => Self::NoApFound(v),
wifi_err_reason_t_WIFI_REASON_AUTH_FAIL => Self::AuthFail(v),
wifi_err_reason_t_WIFI_REASON_ASSOC_FAIL => Self::AssocFail(v),
wifi_err_reason_t_WIFI_REASON_HANDSHAKE_TIMEOUT => Self::HandshakeTimeout(v),
wifi_err_reason_t_WIFI_REASON_CONNECTION_FAIL => Self::ConnectionFail(v),
wifi_err_reason_t_WIFI_REASON_AP_TSF_RESET => Self::ApTsfReset(t),
wifi_err_reason_t_WIFI_REASON_ROAMING => Self::Roaming(v),
wifi_err_reason_t_WIFI_REASON_ASSOC_COMEBACK_TIME_TOO_LONG => {
Self::AssocComebackTimeTooLong(v)
}
wifi_err_reason_t_WIFI_REASON_SA_QUERY_TIMEOUT => Self::SaQueryTimeout(v),

wifi_err_reason_t_WIFI_REASON_NO_AP_FOUND_W_COMPATIBLE_SECURITY => {
Self::NoApFoundWithCompatibleSecurity(v)
}
wifi_err_reason_t_WIFI_REASON_NO_AP_FOUND_IN_AUTHMODE_THRESHOLD => {
Self::NoApFoundInAuthModeThreshold(v)
}
wifi_err_reason_t_WIFI_REASON_NO_AP_FOUND_IN_RSSI_THRESHOLD => {
Self::NoApFoundInRssiThreshold(v)
}
_ => Self::Unrecognized(v),
}
}
}

#[derive(Debug)]
pub enum WifiErrReason {
Unspecified(c_uint),
AuthExpire(c_uint),
AuthLeave(c_uint),
AssocExpire(c_uint),
AssocTooMany(c_uint),
NotAuthed(c_uint),
NotAssoced(c_uint),
AssocLeave(c_uint),
AssocNotAuthed(c_uint),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to wonder if there isn't some macro crate out there that can emit this kind of boilerplate for us given a C enum.

Also surprised that esp-idf-{svc,sys} doesn't do this for us.

DisassocPwrCapBad(c_uint),
DisassocSupchanBad(c_uint),
BssTransitionDisassoc(c_uint),
IeInvalid(c_uint),
MicFailure(c_uint),
FourWayHandshakeTimeout(c_uint),
GroupKeyUpdateTimeout(c_uint),
IeInFourWayDiffers(c_uint),
GroupCipherInvalid(c_uint),
PairwiseCipherInvalid(c_uint),
AkmpInvalid(c_uint),
UnsuppRsnIeVersion(c_uint),
InvalidRsnIeCap(c_uint),
AuthFailed802_1x(c_uint),
CipherSuiteRejected(c_uint),
TDlsPeerUnreachable(c_uint),
TDlsUnspecified(c_uint),
SspRequestedDisassoc(c_uint),
NoSspRoamingAgreement(c_uint),
BadCipherOrAkm(c_uint),
NotAuthorizedThisLocation(c_uint),
ServiceChangePrecludesTs(c_uint),
UnspecifiedQos(c_uint),
NotEnoughBandwidth(c_uint),
MissingAcks(c_uint),
ExceededTxOp(c_uint),
StaLeaving(c_uint),
EndBA(c_uint),
UnknownBA(c_uint),
Timeout(c_uint),
PeerInitiated(c_uint),
ApInitiated(c_uint),
InvalidFtActionFrameCount(c_uint),
InvalidPmkid(c_uint),
InvalidMde(c_uint),
InvalidFte(c_uint),
TransmissionLinkEstablishFailed(c_uint),
AlternativeChannelOccupied(c_uint),
BeaconTimeout(c_uint),
NoApFound(c_uint),
AuthFail(c_uint),
AssocFail(c_uint),
HandshakeTimeout(c_uint),
ConnectionFail(c_uint),
ApTsfReset(c_uint),
Roaming(c_uint),
AssocComebackTimeTooLong(c_uint),
SaQueryTimeout(c_uint),
NoApFoundWithCompatibleSecurity(c_uint),
NoApFoundInAuthModeThreshold(c_uint),
NoApFoundInRssiThreshold(c_uint),
Unrecognized(c_uint),
}
1 change: 1 addition & 0 deletions micro-rdk/src/esp32/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub mod utils;
pub mod conn {
pub mod mdns;
pub mod network;
pub mod wifi_error;
}
pub mod coredump;
pub mod nvs_storage;