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

[NXP][platform][common] Call OnScanWiFiNetworkDone function in the context of the Matter stack to avoid chipDie issue #33873

Merged
merged 2 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading