Skip to content

Commit

Permalink
[NXP][platform][common] Call OnScanWiFiNetworkDone function in the co…
Browse files Browse the repository at this point in the history
…ntext of the Matter stack to avoid chipDie issue (#33873)

Signed-off-by: Martin Girardot <[email protected]>
Co-authored-by: Gatien Chapon <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Dec 12, 2024
1 parent 6670e82 commit 2486928
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/platform/nxp/common/CHIPDevicePlatformEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ enum InternalPlatformSpecificEventTypes
kPlatformNxpWlanEvent,
kPlatformNxpIpChangeEvent,
kPlatformNxpStartWlanConnectEvent,
kPlatformNxpScanWiFiNetworkDoneEvent,
};

} // namespace DeviceEventType
Expand Down Expand Up @@ -116,6 +117,7 @@ struct ChipDevicePlatformEvent final
#if CHIP_DEVICE_CONFIG_ENABLE_WPA
enum wlan_event_reason WlanEventReason;
struct wlan_network * pNetworkDataEvent;
unsigned int ScanWiFiNetworkCount;
#endif
};
};
Expand Down
5 changes: 5 additions & 0 deletions src/platform/nxp/common/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ void ConnectivityManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event)
free(event->Platform.pNetworkDataEvent);
}
}
else if (event->Type == kPlatformNxpScanWiFiNetworkDoneEvent)
{
NetworkCommissioning::NXPWiFiDriver::GetInstance().ScanWiFINetworkDoneFromMatterTaskContext(
event->Platform.ScanWiFiNetworkCount);
}
#endif
}

Expand Down
3 changes: 2 additions & 1 deletion src/platform/nxp/common/NetworkCommissioningDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ class NXPWiFiDriver final : public WiFiDriver

CHIP_ERROR ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen, const char * key, uint8_t keyLen);
void OnConnectWiFiNetwork(Status commissioningError, CharSpan debugText, int32_t connectStatus);
static int OnScanWiFiNetworkDone(unsigned int count);
int ScanWiFINetworkDoneFromMatterTaskContext(unsigned int count);
static int _OnScanWiFiNetworkDoneCallBack(unsigned int count);
static NXPWiFiDriver & GetInstance()
{
static NXPWiFiDriver instance;
Expand Down
21 changes: 18 additions & 3 deletions src/platform/nxp/common/NetworkCommissioningWiFiDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ CHIP_ERROR NXPWiFiDriver::StartScanWiFiNetworks(ByteSpan ssid)
ChipLogProgress(DeviceLayer, "Scan for WiFi network(s) requested");

(void) memset(&wlan_scan_param, 0, sizeof(wlan_scan_params_v2_t));
wlan_scan_param.cb = &NXPWiFiDriver::OnScanWiFiNetworkDone;
wlan_scan_param.cb = &NXPWiFiDriver::_OnScanWiFiNetworkDoneCallBack;

if ((ssid.size() > 0) && (ssid.size() < MLAN_MAX_SSID_LENGTH))
{
Expand All @@ -291,8 +291,23 @@ CHIP_ERROR NXPWiFiDriver::StartScanWiFiNetworks(ByteSpan ssid)
return CHIP_NO_ERROR;
}

// TODO should be modified to do it in the context of the Matter stack
int NXPWiFiDriver::OnScanWiFiNetworkDone(unsigned int count)
int NXPWiFiDriver::_OnScanWiFiNetworkDoneCallBack(unsigned int count)
{
ChipDeviceEvent event;
event.Type = DeviceEventType::kPlatformNxpScanWiFiNetworkDoneEvent;
event.Platform.ScanWiFiNetworkCount = count;
CHIP_ERROR err = PlatformMgr().PostEvent(&event);
if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "Failed to schedule work: %" CHIP_ERROR_FORMAT, err.Format());
return WM_FAIL;
}
return WM_SUCCESS;
}

// The processing of the scan callback should be done in the context of the Matter stack, as the scan callback will call Matter
// stack APIs
int NXPWiFiDriver::ScanWiFINetworkDoneFromMatterTaskContext(unsigned int count)
{
ChipLogProgress(DeviceLayer, "Scan for WiFi network(s) done, found: %u", count);

Expand Down

0 comments on commit 2486928

Please sign in to comment.