[NXP][Zephyr] Use common wifi port for Zephyr (#32143)

* [NXP][Zephyr] Use common wifi port for Zephyr

Move current NXP Zephyr wifi port to a common place, to be shared with other zephyr platforms.

Signed-off-by: Axel Le Bourhis <axel.lebourhis@nxp.com>

* Restyled by gn

* [NXP][platform][zephyr] Lower CHIP task priority

Lower CHIP task priority to give margin for higher priority system tasks.

Signed-off-by: Axel Le Bourhis <axel.lebourhis@nxp.com>

---------

Signed-off-by: Axel Le Bourhis <axel.lebourhis@nxp.com>
Co-authored-by: Restyled.io <commits@restyled.io>
diff --git a/src/platform/nxp/zephyr/wifi/ConnectivityManagerImplWiFi.cpp b/src/platform/Zephyr/wifi/ConnectivityManagerImplWiFi.cpp
similarity index 100%
rename from src/platform/nxp/zephyr/wifi/ConnectivityManagerImplWiFi.cpp
rename to src/platform/Zephyr/wifi/ConnectivityManagerImplWiFi.cpp
diff --git a/src/platform/nxp/zephyr/wifi/ConnectivityManagerImplWiFi.h b/src/platform/Zephyr/wifi/ConnectivityManagerImplWiFi.h
similarity index 100%
rename from src/platform/nxp/zephyr/wifi/ConnectivityManagerImplWiFi.h
rename to src/platform/Zephyr/wifi/ConnectivityManagerImplWiFi.h
diff --git a/src/platform/nxp/zephyr/wifi/WiFiManager.cpp b/src/platform/Zephyr/wifi/WiFiManager.cpp
similarity index 100%
rename from src/platform/nxp/zephyr/wifi/WiFiManager.cpp
rename to src/platform/Zephyr/wifi/WiFiManager.cpp
diff --git a/src/platform/nxp/zephyr/wifi/WiFiManager.h b/src/platform/Zephyr/wifi/WiFiManager.h
similarity index 100%
rename from src/platform/nxp/zephyr/wifi/WiFiManager.h
rename to src/platform/Zephyr/wifi/WiFiManager.h
diff --git a/src/platform/nxp/zephyr/wifi/NxpWifiDriver.cpp b/src/platform/Zephyr/wifi/ZephyrWifiDriver.cpp
similarity index 85%
rename from src/platform/nxp/zephyr/wifi/NxpWifiDriver.cpp
rename to src/platform/Zephyr/wifi/ZephyrWifiDriver.cpp
index f3969a5..53b7fa6 100644
--- a/src/platform/nxp/zephyr/wifi/NxpWifiDriver.cpp
+++ b/src/platform/Zephyr/wifi/ZephyrWifiDriver.cpp
@@ -15,7 +15,7 @@
  *    limitations under the License.
  */
 
-#include "NxpWifiDriver.h"
+#include "ZephyrWifiDriver.h"
 
 #include <platform/KeyValueStoreManager.h>
 
@@ -32,13 +32,13 @@
 namespace DeviceLayer {
 namespace NetworkCommissioning {
 
-size_t NxpWifiDriver::WiFiNetworkIterator::Count()
+size_t ZephyrWifiDriver::WiFiNetworkIterator::Count()
 {
     VerifyOrReturnValue(mDriver != nullptr, 0);
     return mDriver->mStagingNetwork.IsConfigured() ? 1 : 0;
 }
 
-bool NxpWifiDriver::WiFiNetworkIterator::Next(Network & item)
+bool ZephyrWifiDriver::WiFiNetworkIterator::Next(Network & item)
 {
     // we assume only one network is actually supported
     // TODO: verify if this can be extended
@@ -67,7 +67,7 @@
     return true;
 }
 
-bool NxpWifiScanResponseIterator::Next(WiFiScanResponse & item)
+bool ZephyrWifiScanResponseIterator::Next(WiFiScanResponse & item)
 {
     if (mResultId < mResultCount)
     {
@@ -77,14 +77,14 @@
     return false;
 }
 
-void NxpWifiScanResponseIterator::Release()
+void ZephyrWifiScanResponseIterator::Release()
 {
     mResultId = mResultCount = 0;
     Platform::MemoryFree(mResults);
     mResults = nullptr;
 }
 
-void NxpWifiScanResponseIterator::Add(const WiFiScanResponse & result)
+void ZephyrWifiScanResponseIterator::Add(const WiFiScanResponse & result)
 {
     void * newResults = Platform::MemoryRealloc(mResults, (mResultCount + 1) * sizeof(WiFiScanResponse));
 
@@ -95,7 +95,7 @@
     }
 }
 
-CHIP_ERROR NxpWifiDriver::Init(NetworkStatusChangeCallback * networkStatusChangeCallback)
+CHIP_ERROR ZephyrWifiDriver::Init(NetworkStatusChangeCallback * networkStatusChangeCallback)
 {
     mpNetworkStatusChangeCallback = networkStatusChangeCallback;
 
@@ -113,7 +113,7 @@
     return CHIP_NO_ERROR;
 }
 
-void NxpWifiDriver::OnNetworkStatusChanged(Status status)
+void ZephyrWifiDriver::OnNetworkStatusChanged(Status status)
 {
     if (status == Status::kSuccess)
     {
@@ -132,12 +132,12 @@
     }
 }
 
-void NxpWifiDriver::Shutdown()
+void ZephyrWifiDriver::Shutdown()
 {
     mpNetworkStatusChangeCallback = nullptr;
 }
 
-CHIP_ERROR NxpWifiDriver::CommitConfiguration()
+CHIP_ERROR ZephyrWifiDriver::CommitConfiguration()
 {
     ReturnErrorOnFailure(KeyValueStoreMgr().Put(kPassKey, mStagingNetwork.pass, mStagingNetwork.passLen));
     ReturnErrorOnFailure(KeyValueStoreMgr().Put(kSsidKey, mStagingNetwork.ssid, mStagingNetwork.ssidLen));
@@ -145,7 +145,7 @@
     return CHIP_NO_ERROR;
 }
 
-CHIP_ERROR NxpWifiDriver::RevertConfiguration()
+CHIP_ERROR ZephyrWifiDriver::RevertConfiguration()
 {
     LoadFromStorage();
 
@@ -172,8 +172,8 @@
     return CHIP_NO_ERROR;
 }
 
-Status NxpWifiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials, MutableCharSpan & outDebugText,
-                                         uint8_t & outNetworkIndex)
+Status ZephyrWifiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials, MutableCharSpan & outDebugText,
+                                            uint8_t & outNetworkIndex)
 {
     outDebugText    = {};
     outNetworkIndex = 0;
@@ -191,7 +191,7 @@
     return Status::kSuccess;
 }
 
-Status NxpWifiDriver::RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex)
+Status ZephyrWifiDriver::RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex)
 {
     outDebugText    = {};
     outNetworkIndex = 0;
@@ -202,7 +202,7 @@
     return Status::kSuccess;
 }
 
-Status NxpWifiDriver::ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCharSpan & outDebugText)
+Status ZephyrWifiDriver::ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCharSpan & outDebugText)
 {
     outDebugText = {};
 
@@ -213,7 +213,7 @@
     return Status::kSuccess;
 }
 
-void NxpWifiDriver::ConnectNetwork(ByteSpan networkId, ConnectCallback * callback)
+void ZephyrWifiDriver::ConnectNetwork(ByteSpan networkId, ConnectCallback * callback)
 {
     Status status = Status::kSuccess;
     WiFiManager::StationStatus stationStatus;
@@ -252,7 +252,7 @@
     }
 }
 
-void NxpWifiDriver::LoadFromStorage()
+void ZephyrWifiDriver::LoadFromStorage()
 {
     WiFiManager::WiFiNetwork network;
 
@@ -262,7 +262,7 @@
     mStagingNetwork = network;
 }
 
-void NxpWifiDriver::OnScanWiFiNetworkDone(WiFiManager::WiFiRequestStatus status)
+void ZephyrWifiDriver::OnScanWiFiNetworkDone(WiFiManager::WiFiRequestStatus status)
 {
     VerifyOrReturn(mScanCallback != nullptr);
     mScanCallback->OnFinished(status == WiFiManager::WiFiRequestStatus::SUCCESS ? Status::kSuccess : Status::kUnknownError,
@@ -270,12 +270,12 @@
     mScanCallback = nullptr;
 }
 
-void NxpWifiDriver::OnScanWiFiNetworkResult(const WiFiScanResponse & response)
+void ZephyrWifiDriver::OnScanWiFiNetworkResult(const WiFiScanResponse & response)
 {
     mScanResponseIterator.Add(response);
 }
 
-void NxpWifiDriver::ScanNetworks(ByteSpan ssid, WiFiDriver::ScanCallback * callback)
+void ZephyrWifiDriver::ScanNetworks(ByteSpan ssid, WiFiDriver::ScanCallback * callback)
 {
     mScanCallback    = callback;
     CHIP_ERROR error = WiFiManager::Instance().Scan(
diff --git a/src/platform/nxp/zephyr/wifi/NxpWifiDriver.h b/src/platform/Zephyr/wifi/ZephyrWifiDriver.h
similarity index 90%
rename from src/platform/nxp/zephyr/wifi/NxpWifiDriver.h
rename to src/platform/Zephyr/wifi/ZephyrWifiDriver.h
index 01e4964..9096aa4 100644
--- a/src/platform/nxp/zephyr/wifi/NxpWifiDriver.h
+++ b/src/platform/Zephyr/wifi/ZephyrWifiDriver.h
@@ -29,7 +29,7 @@
 constexpr uint8_t kWiFiScanNetworksTimeOutSeconds   = 10;
 constexpr uint8_t kWiFiConnectNetworkTimeoutSeconds = 35;
 
-class NxpWifiScanResponseIterator : public Iterator<WiFiScanResponse>
+class ZephyrWifiScanResponseIterator : public Iterator<WiFiScanResponse>
 {
 public:
     size_t Count() override { return mResultCount; }
@@ -43,7 +43,7 @@
     WiFiScanResponse * mResults = nullptr;
 };
 
-class NxpWifiDriver final : public WiFiDriver
+class ZephyrWifiDriver final : public WiFiDriver
 {
 public:
     // Define non-volatile storage keys for SSID and password.
@@ -54,14 +54,14 @@
     class WiFiNetworkIterator final : public NetworkIterator
     {
     public:
-        WiFiNetworkIterator(NxpWifiDriver * aDriver) : mDriver(aDriver) {}
+        WiFiNetworkIterator(ZephyrWifiDriver * aDriver) : mDriver(aDriver) {}
         size_t Count() override;
         bool Next(Network & item) override;
         void Release() override { delete this; }
         ~WiFiNetworkIterator() = default;
 
     private:
-        NxpWifiDriver * mDriver;
+        ZephyrWifiDriver * mDriver;
         bool mExhausted{ false };
     };
 
@@ -87,9 +87,9 @@
                               uint8_t & outNetworkIndex) override;
     void ScanNetworks(ByteSpan ssid, ScanCallback * callback) override;
 
-    static NxpWifiDriver & Instance()
+    static ZephyrWifiDriver & Instance()
     {
-        static NxpWifiDriver sInstance;
+        static ZephyrWifiDriver sInstance;
         return sInstance;
     }
 
@@ -103,7 +103,7 @@
     ConnectCallback * mpConnectCallback{ nullptr };
     NetworkStatusChangeCallback * mpNetworkStatusChangeCallback{ nullptr };
     WiFiManager::WiFiNetwork mStagingNetwork;
-    NxpWifiScanResponseIterator mScanResponseIterator;
+    ZephyrWifiScanResponseIterator mScanResponseIterator;
     ScanCallback * mScanCallback{ nullptr };
 };
 
diff --git a/src/platform/nxp/zephyr/BUILD.gn b/src/platform/nxp/zephyr/BUILD.gn
index 1c37075..bdf1f2b 100644
--- a/src/platform/nxp/zephyr/BUILD.gn
+++ b/src/platform/nxp/zephyr/BUILD.gn
@@ -87,12 +87,12 @@
     sources += [
       "../../Zephyr/InetUtils.cpp",
       "../../Zephyr/InetUtils.h",
-      "wifi/ConnectivityManagerImplWiFi.cpp",
-      "wifi/ConnectivityManagerImplWiFi.h",
-      "wifi/NxpWifiDriver.cpp",
-      "wifi/NxpWifiDriver.h",
-      "wifi/WiFiManager.cpp",
-      "wifi/WiFiManager.h",
+      "../../Zephyr/wifi/ConnectivityManagerImplWiFi.cpp",
+      "../../Zephyr/wifi/ConnectivityManagerImplWiFi.h",
+      "../../Zephyr/wifi/WiFiManager.cpp",
+      "../../Zephyr/wifi/WiFiManager.h",
+      "../../Zephyr/wifi/ZephyrWifiDriver.cpp",
+      "../../Zephyr/wifi/ZephyrWifiDriver.h",
     ]
   }
 
diff --git a/src/platform/nxp/zephyr/CHIPDevicePlatformConfig.h b/src/platform/nxp/zephyr/CHIPDevicePlatformConfig.h
index 7a80a39..900aa84 100644
--- a/src/platform/nxp/zephyr/CHIPDevicePlatformConfig.h
+++ b/src/platform/nxp/zephyr/CHIPDevicePlatformConfig.h
@@ -105,7 +105,7 @@
 // ========== Platform-specific Configuration Overrides =========
 
 #ifndef CHIP_DEVICE_CONFIG_CHIP_TASK_PRIORITY
-#define CHIP_DEVICE_CONFIG_CHIP_TASK_PRIORITY (K_PRIO_PREEMPT(1))
+#define CHIP_DEVICE_CONFIG_CHIP_TASK_PRIORITY (K_PRIO_PREEMPT(5))
 #endif // CHIP_DEVICE_CONFIG_CHIP_TASK_PRIORITY
 
 #ifndef CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE
diff --git a/src/platform/nxp/zephyr/ConnectivityManagerImpl.h b/src/platform/nxp/zephyr/ConnectivityManagerImpl.h
index 6d7a717..c43d6a3 100644
--- a/src/platform/nxp/zephyr/ConnectivityManagerImpl.h
+++ b/src/platform/nxp/zephyr/ConnectivityManagerImpl.h
@@ -36,7 +36,7 @@
 #endif
 
 #if CHIP_DEVICE_CONFIG_ENABLE_WIFI
-#include "wifi/ConnectivityManagerImplWiFi.h"
+#include <platform/Zephyr/wifi/ConnectivityManagerImplWiFi.h>
 #else
 #include <platform/internal/GenericConnectivityManagerImpl_NoWiFi.h>
 #endif
diff --git a/src/platform/nxp/zephyr/DiagnosticDataProviderImplNxp.cpp b/src/platform/nxp/zephyr/DiagnosticDataProviderImplNxp.cpp
index b7f0e25..6c3481d 100644
--- a/src/platform/nxp/zephyr/DiagnosticDataProviderImplNxp.cpp
+++ b/src/platform/nxp/zephyr/DiagnosticDataProviderImplNxp.cpp
@@ -24,7 +24,7 @@
 #include "DiagnosticDataProviderImplNxp.h"
 
 #ifdef CONFIG_WIFI_NXP
-#include <platform/nxp/zephyr/wifi/WiFiManager.h>
+#include <platform/Zephyr/wifi/WiFiManager.h>
 #endif
 
 namespace chip {