Full Network Commissioning Cluster w/ Linux Implementation (#12931)

* Linux network commissioning

* Rename network-commissioning -> network-commissioning-old in existing apps

* Update python test script

* Enable NetworkCommissioningCluster on Endpoint 0 and Endpoint 1

* Run Codegen
diff --git a/src/platform/Linux/NetworkCommissioningDriver.h b/src/platform/Linux/NetworkCommissioningDriver.h
new file mode 100644
index 0000000..41daa19
--- /dev/null
+++ b/src/platform/Linux/NetworkCommissioningDriver.h
@@ -0,0 +1,159 @@
+/*
+ *
+ *    Copyright (c) 2021 Project CHIP Authors
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#pragma once
+
+#include <platform/NetworkCommissioning.h>
+#include <vector>
+
+namespace chip {
+namespace DeviceLayer {
+namespace NetworkCommissioning {
+
+template <typename T>
+class LinuxScanResponseIterator : public Iterator<T>
+{
+public:
+    LinuxScanResponseIterator(std::vector<T> * apScanResponse) : mpScanResponse(apScanResponse) {}
+    size_t Count() override { return mpScanResponse != nullptr ? mpScanResponse->size() : 0; }
+    bool Next(T & item) override
+    {
+        if (mpScanResponse == nullptr || currentIterating >= mpScanResponse->size())
+        {
+            return false;
+        }
+        item = (*mpScanResponse)[currentIterating];
+        currentIterating++;
+        return true;
+    }
+    void Release() override
+    { /* nothing to do, we don't hold the ownership of the vector, and users is not expected to hold the ownership in OnFinished for
+         scan. */
+    }
+
+private:
+    size_t currentIterating = 0;
+    // Note: We cannot post a event in ScheduleLambda since std::vector is not trivial copiable.
+    std::vector<T> * mpScanResponse;
+};
+
+#if CHIP_DEVICE_CONFIG_ENABLE_WPA
+class LinuxWiFiDriver final : public WiFiDriver
+{
+public:
+    class WiFiNetworkIterator final : public NetworkIterator
+    {
+    public:
+        WiFiNetworkIterator(LinuxWiFiDriver * aDriver) : driver(aDriver) {}
+        size_t Count() override;
+        bool Next(Network & item) override;
+        void Release() override { delete this; }
+        ~WiFiNetworkIterator() = default;
+
+    private:
+        LinuxWiFiDriver * driver;
+        bool exhausted = false;
+    };
+
+    struct WiFiNetwork
+    {
+        uint8_t ssid[DeviceLayer::Internal::kMaxWiFiSSIDLength];
+        uint8_t ssidLen = 0;
+        uint8_t credentials[DeviceLayer::Internal::kMaxWiFiKeyLength];
+        uint8_t credentialsLen = 0;
+    };
+
+    // BaseDriver
+    NetworkIterator * GetNetworks() override { return new WiFiNetworkIterator(this); }
+    CHIP_ERROR Init() override;
+    CHIP_ERROR Shutdown() override { return CHIP_NO_ERROR; } // Nothing to do on linux for shutdown.
+
+    // WirelessDriver
+    uint8_t GetMaxNetworks() override { return 1; }
+    uint8_t GetScanNetworkTimeoutSeconds() override { return 10; }
+    uint8_t GetConnectNetworkTimeoutSeconds() override { return 20; }
+
+    CHIP_ERROR CommitConfiguration() override;
+    CHIP_ERROR RevertConfiguration() override;
+
+    Status RemoveNetwork(ByteSpan networkId) override;
+    Status ReorderNetwork(ByteSpan networkId, uint8_t index) override;
+    void ConnectNetwork(ByteSpan networkId, ConnectCallback * callback) override;
+
+    // WiFiDriver
+    Status AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials) override;
+    void ScanNetworks(ByteSpan ssid, ScanCallback * callback) override;
+
+private:
+    bool NetworkMatch(const WiFiNetwork & network, ByteSpan networkId);
+
+    WiFiNetworkIterator mWiFiIterator = WiFiNetworkIterator(this);
+    WiFiNetwork mSavedNetwork;
+    WiFiNetwork mStagingNetwork;
+};
+#endif // CHIP_DEVICE_CONFIG_ENABLE_WPA
+
+#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
+class LinuxThreadDriver final : public ThreadDriver
+{
+public:
+    class ThreadNetworkIterator final : public NetworkIterator
+    {
+    public:
+        ThreadNetworkIterator(LinuxThreadDriver * aDriver) : driver(aDriver) {}
+        size_t Count() override;
+        bool Next(Network & item) override;
+        void Release() override { delete this; }
+        ~ThreadNetworkIterator() = default;
+
+    private:
+        LinuxThreadDriver * driver;
+        bool exhausted = false;
+    };
+
+    // BaseDriver
+    NetworkIterator * GetNetworks() override { return new ThreadNetworkIterator(this); }
+    CHIP_ERROR Init() override;
+    CHIP_ERROR Shutdown() override { return CHIP_NO_ERROR; } // Nothing to do on linux for shutdown.
+
+    // WirelessDriver
+    uint8_t GetMaxNetworks() override { return 1; }
+    uint8_t GetScanNetworkTimeoutSeconds() override { return 10; }
+    uint8_t GetConnectNetworkTimeoutSeconds() override { return 20; }
+
+    CHIP_ERROR CommitConfiguration() override;
+    CHIP_ERROR RevertConfiguration() override;
+
+    Status RemoveNetwork(ByteSpan networkId) override;
+    Status ReorderNetwork(ByteSpan networkId, uint8_t index) override;
+    void ConnectNetwork(ByteSpan networkId, ConnectCallback * callback) override;
+
+    // ThreadDriver
+    Status AddOrUpdateNetwork(ByteSpan operationalDataset) override;
+    void ScanNetworks(ScanCallback * callback) override;
+
+private:
+    ThreadNetworkIterator mThreadIterator = ThreadNetworkIterator(this);
+    Thread::OperationalDataset mSavedNetwork;
+    Thread::OperationalDataset mStagingNetwork;
+};
+
+#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD
+
+} // namespace NetworkCommissioning
+} // namespace DeviceLayer
+} // namespace chip