Skip to content

Commit 07b6230

Browse files
committed
[NXP][platform][common] Update RemoveNetwork and Disconnect functions and enable CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION for all NXP WiFi platforms
1 parent b050cb4 commit 07b6230

File tree

6 files changed

+66
-36
lines changed

6 files changed

+66
-36
lines changed

examples/platform/nxp/common/app_task/source/AppTaskBase.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@
6262
#include <app/clusters/ota-requestor/OTATestEventTriggerDelegate.h>
6363
#endif
6464

65+
#ifdef ENABLE_CHIP_SHELL
66+
#include <lib/shell/commands/WiFi.h>
67+
#endif
68+
6569
using namespace chip;
6670
using namespace chip::TLV;
6771
using namespace ::chip::Credentials;
@@ -202,6 +206,9 @@ CHIP_ERROR chip::NXP::App::AppTaskBase::Init()
202206

203207
#if CONFIG_CHIP_WIFI || CHIP_DEVICE_CONFIG_ENABLE_WPA
204208
sNetworkCommissioningInstance.Init();
209+
#ifdef ENABLE_CHIP_SHELL
210+
Shell::SetWiFiDriver(chip::NXP::App::GetAppTask().GetWifiDriverInstance());
211+
#endif
205212
#endif
206213
#if CONFIG_CHIP_OTA_REQUESTOR
207214
if (err == CHIP_NO_ERROR)

src/platform/nxp/common/ConnectivityManagerImpl.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,34 @@ void ConnectivityManagerImpl::ConnectNetworkTimerHandler(::chip::System::Layer *
590590
PlatformMgr().UnlockChipStack();
591591
}
592592
}
593+
594+
/* Can be used to disconnect from WiFi network.
595+
*/
596+
CHIP_ERROR ConnectivityManagerImpl::_DisconnectNetwork(void)
597+
{
598+
int ret = 0;
599+
CHIP_ERROR err = CHIP_NO_ERROR;
600+
601+
if (ConnectivityMgrImpl().IsWiFiStationConnected())
602+
{
603+
ChipLogProgress(NetworkProvisioning, "Disconnecting from WiFi network.");
604+
605+
ret = wlan_disconnect();
606+
607+
if (ret != WM_SUCCESS)
608+
{
609+
ChipLogError(NetworkProvisioning, "Failed to disconnect from network with error: %u", (uint8_t) ret);
610+
err = CHIP_ERROR_UNEXPECTED_EVENT;
611+
}
612+
}
613+
else
614+
{
615+
ChipLogError(NetworkProvisioning, "Error: WiFi not connected!");
616+
err = CHIP_ERROR_INCORRECT_STATE;
617+
}
618+
619+
return err;
620+
}
593621
#endif
594622

595623
} // namespace DeviceLayer

src/platform/nxp/common/ConnectivityManagerImpl.h

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class ConnectivityManagerImpl final : public ConnectivityManager,
115115
bool _IsWiFiStationEnabled();
116116
bool _IsWiFiStationConnected();
117117
bool _IsWiFiStationApplicationControlled();
118+
CHIP_ERROR _DisconnectNetwork(void);
118119
#endif /* CHIP_DEVICE_CONFIG_ENABLE_WPA */
119120

120121
// ===== Members for internal use by the following friends.

src/platform/nxp/common/NetworkCommissioningDriver.h

-4
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ class NXPWiFiDriver final : public WiFiDriver
7272
Status ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCharSpan & outDebugText) override;
7373
void ConnectNetwork(ByteSpan networkId, ConnectCallback * callback) override;
7474

75-
/* Can be used to disconnect from WiFi network.
76-
*/
77-
int DisconnectNetwork();
78-
7975
/* Returns the network SSID. User needs to allocate a buffer of size >= DeviceLayer::Internal::kMaxWiFiSSIDLength.
8076
* ssid - pointer to the returned SSID
8177
*/

src/platform/nxp/common/NetworkCommissioningWiFiDriver.cpp

+29-27
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,39 @@ Status NXPWiFiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials, Mu
142142

143143
Status NXPWiFiDriver::RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex)
144144
{
145+
int err_code = 0;
146+
145147
outDebugText.reduce_size(0);
146148
outNetworkIndex = 0;
147149
VerifyOrReturnError(NetworkMatch(mStagingNetwork, networkId), Status::kNetworkIDNotFound);
148150

149-
// Use empty ssid for representing invalid network
150-
mStagingNetwork.ssidLen = 0;
151-
memset(mStagingNetwork.ssid, 0, DeviceLayer::Internal::kMaxWiFiSSIDLength);
152-
memset(mStagingNetwork.credentials, 0, DeviceLayer::Internal::kMaxWiFiKeyLength);
151+
err_code = wlan_remove_network((char *)networkId.data());
152+
153+
switch (err_code)
154+
{
155+
case -WM_E_INVAL:
156+
ChipLogError(DeviceLayer, "Error: Network not found");
157+
break;
158+
159+
case WM_SUCCESS:
160+
/* Use empty ssid for representing invalid network */
161+
mStagingNetwork.ssidLen = 0;
162+
memset(mStagingNetwork.ssid, 0, DeviceLayer::Internal::kMaxWiFiSSIDLength);
163+
memset(mStagingNetwork.credentials, 0, DeviceLayer::Internal::kMaxWiFiKeyLength);
164+
/* Save to persistent memory */
165+
CommitConfiguration();
166+
ChipLogProgress(DeviceLayer, "Successfully removed network");
167+
break;
168+
169+
case WLAN_ERROR_STATE:
170+
ChipLogError(DeviceLayer, "Error: Can't remove network in this state");
171+
break;
172+
173+
default:
174+
ChipLogError(DeviceLayer, "Error: Unable to remove network");
175+
break;
176+
}
177+
153178
return Status::kSuccess;
154179
}
155180

@@ -238,29 +263,6 @@ void NXPWiFiDriver::ConnectNetwork(ByteSpan networkId, ConnectCallback * callbac
238263
}
239264
}
240265

241-
int NXPWiFiDriver::DisconnectNetwork(void)
242-
{
243-
int ret = 0;
244-
245-
if (ConnectivityMgrImpl().IsWiFiStationConnected())
246-
{
247-
ChipLogProgress(NetworkProvisioning, "Disconnecting from WiFi network.");
248-
249-
ret = wlan_disconnect();
250-
251-
if (ret != WM_SUCCESS)
252-
{
253-
ChipLogError(NetworkProvisioning, "Failed to disconnect from network with error: %u", (uint8_t) ret);
254-
}
255-
}
256-
else
257-
{
258-
ChipLogError(NetworkProvisioning, "Error: WiFi not connected!");
259-
}
260-
261-
return ret;
262-
}
263-
264266
CHIP_ERROR NXPWiFiDriver::StartScanWiFiNetworks(ByteSpan ssid)
265267
{
266268
wlan_scan_params_v2_t wlan_scan_param;

third_party/nxp/rt_sdk/rt_sdk.gni

+1-5
Original file line numberDiff line numberDiff line change
@@ -562,11 +562,7 @@ template("rt_sdk") {
562562
}
563563

564564
if (chip_enable_wifi) {
565-
if (!w8801_transceiver) {
566-
defines += [ "CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION=1" ]
567-
} else {
568-
defines += [ "CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION=0" ]
569-
}
565+
defines += [ "CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION=1" ]
570566
}
571567

572568
# Now add our "system-header" include dirs

0 commit comments

Comments
 (0)