[SL-UP] Refactor Platform WiFi events - #1191
Rohan Sahay (rosahay-silabs) wants to merge 40 commits into
Conversation
…improved error handling and clarity. Simplify exit logic by removing unnecessary exit label.
…instead of hardcoded.
… handling to streamline the connection process.
…tials if the station is provisioned before connecting to a new network. Add comments for clarity on the connection process.
…essages for WiFi events and streamline state transitions by removing unnecessary checks. Enhance error handling in setting WiFi station mode and improve clarity in DriveStationState logic.
…itialize mLastDisconnectionReason to kUnknownError for improved error tracking.
Map join/disconnect failures to disconnection reasons and let ConnectivityManager drive station state.
Map join/disconnect failures to disconnection reasons and let ConnectivityManager drive station state.
…ation state management
…e-based handling and disconnection logic
…NetworkCommissioningStatusEnum and enhance disconnection notification logic
| WifiInterfaceImpl & self = WifiInterfaceImpl::GetInstance(); | ||
| self.mLastDisconnectionReason = reason; | ||
| self.NotifyDisconnection(self.mLastDisconnectionReason); |
There was a problem hiding this comment.
would this. work here or is this a static function? If so, does it need to be static?
| WifiInterfaceImpl & self = WifiInterfaceImpl::GetInstance(); | |
| self.mLastDisconnectionReason = reason; | |
| self.NotifyDisconnection(self.mLastDisconnectionReason); | |
| this.mLastDisconnectionReason = reason; | |
| this.NotifyDisconnection(self.mLastDisconnectionReason); |
| CHIP_ERROR WifiInterfaceImpl::EnableStationMode() | ||
| { | ||
| wfx_rsi.dev_state.Set(WifiState::kStationMode); | ||
| return CHIP_NO_ERROR; |
There was a problem hiding this comment.
if it can't fail why do we need a return code?
There was a problem hiding this comment.
Typically going by implementation of us and peers, we should have a way to enable and disable station mode, which should be a platform API call and not just setting a state, hence changing it to a CHIP_ERROR return instead of a void, we do have an API on SiWx917 platform as well but I have not explored that yet.
| return CHIP_NO_ERROR; | ||
| } | ||
|
|
||
| chip::app::Clusters::NetworkCommissioning::NetworkCommissioningStatusEnum |
There was a problem hiding this comment.
you have a using namespace chip::app::Clusters::NetworkCommissioning; in this file. You should be able to shorthen this to
| chip::app::Clusters::NetworkCommissioning::NetworkCommissioningStatusEnum | |
| NetworkCommissioningStatusEnum |
| kIPBindFailed | ||
| kUnknownError | ||
| */ | ||
| using Status = chip::app::Clusters::NetworkCommissioning::NetworkCommissioningStatusEnum; |
There was a problem hiding this comment.
For the same reason stated above. I think
NetworkCommissioningStatusEnum::kSuccess;
NetworkCommissioningStatusEnum::kNetworkNotFound;
...
would work if you want to keep the using Status it can be shortened too
| GetWiFiStationMode(); | ||
| // if the station mode is application controlled or disabled, return | ||
| VerifyOrReturn(stationMode != kWiFiStationMode_ApplicationControlled, | ||
| ChipLogError(DeviceLayer, "WiFi station mode is application controlled")); |
There was a problem hiding this comment.
similar comment than before. Is this an Error? Also it seems this would be printed a lot. DriveStationState runs often no?
| WifiInterface::GetInstance().TriggerDisconnection(); | ||
| ChangeWiFiStationState(kWiFiStationState_Disconnecting); |
There was a problem hiding this comment.
like i mentioned before. Should be regrouped.
| // Cannot use the driver if the instance is not initialized. | ||
| VerifyOrDie(nwDriver != nullptr); // should never be null | ||
| nwDriver->UpdateNetworkingStatus(); | ||
| case kWiFiStationState_Connecting_Succeeded: |
There was a problem hiding this comment.
Why is kWiFiStationState_Connecting_Succeeded needed? Can't just go to Connected?
There was a problem hiding this comment.
Yes I have the same doubt kWiFiStationState_Connecting_Succeeded vs kWiFiStationState_Connected, but I did not find any concrete documentation for the differences in those states.
My initial impressions were that maybe kWiFiStationState_Connecting_Succeeded would be for the WiFi connection on the access point level, where we are connected but the IP stack is negotiating, but that logic fails since we have a connectivity event to track that state.
I will look into how others are using it and infer from there.
| break; | ||
|
|
||
| default: | ||
| ChipLogDetail(DeviceLayer, "WiFi station state not driving: %s", WiFiStationStateToStr(newState)); |
There was a problem hiding this comment.
We will still schedule a DriveStationState for an unkown state
There was a problem hiding this comment.
Added this log to verify that we are scheduling for all known state, more of a verification log rather than anything else.
| ChipLogDetail(DeviceLayer, "WiFi station state not driving: %s", WiFiStationStateToStr(newState)); | ||
| break; | ||
| } | ||
| TEMPORARY_RETURN_IGNORED DeviceLayer::SystemLayer().ScheduleWork(DriveStationState, NULL); |
There was a problem hiding this comment.
The sequence seems odd to me.
DriveStationState calls ChangeWiFiStationState in most situation. And ChangeWiFiStationState will then call DriveStationState again.
There was a problem hiding this comment.
Right now, we are doing it for the TriggerDisconnection is not having a callback to show the disconnecting state, same for the connecting state, adding the ChangeWiFiStationState instead of a mStationState because the former would not process the same state twice. The only place I have prefer not doing this is the reconnection logic, where though it will work, we will end of queuing the DriveStationState twice, once by ChangeWiFiStationState another time with the delay of timer.
The retry logic is the only place I would not call ChangeWiFiStationState, other places I would still prefer invoking the ChangeWiFiStationState.
…thod to streamline reconnection logic in WiFi station state management
…ect status in notifications and improving reason retrieval
…disconnection handling into a single method
…use direct enum references for improved clarity
…ods for WiFi driver
Co-authored-by: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com>
…ed method for improved clarity and maintainability
…hance connection state checks
e488796 to
9c97214
Compare
Summary
WifiInterfaceintoConnectivityManagerImpl, so station connect/disconnect/reconnect is driven by one state machine.kWFXSystemEvent→kPlatformSLEvent, add publickSLSystemEvent) and replaceConfigureStationMode()withEnableStationMode().NetworkCommissioningStatusEnum(NC status reporting still has TODOs to use it).Related issues
N/A
Testing