[nrfconnect] Bump nRF Connect SDK to 2.2.0 (#24302)

* [nrfconnect] Bump nRF Connect SDK to 2.2.0

Change the recommended nRF Connect SDK version to v2.2.0.

* Start using Zephyr WiFi net_mgmt API and events

- replace wpa_supplicant API calls with generic Zephyr net_mgmt API
- use net events to manage WiFi connection
- refactoring of the whole platform/nrfconnect/wifi code

Signed-off-by: Marcin Kajor <marcin.kajor@nordicsemi.no>

* Implemented proper handling of WiFi security modes.

With the current net_mgmt API it is necessary to scan networks to get
the security mode supported by an AP which we want to connect with.
Also fixed the invalid handling of net_mgmt event life time.

Signed-off-by: Marcin Kajor <marcin.kajor@nordicsemi.no>

* Aligned Matter SDK to Zephyr 0.15.x revision.

These changes were implied the the recent Zephyr upmerge:
- updates of Zephyr include paths
- removal of disabling of gpio1 in board DTS overlays
- fix for the possible dangling pointer compilation error
  after gcc got more picky about that (v10.3 vs. v12.1)

Signed-off-by: Marcin Kajor <marcin.kajor@nordicsemi.no>

* Increased the max number of BLE connections.

This is a workaround for the non-unreferenced BLE connection object
when restarting advertising in BLE disconnect callback.

Signed-off-by: Marcin Kajor <marcin.kajor@nordicsemi.no>

* WiFi fail-safe related fixes

Make sure the fail-safe works as expected with WiFi networking:
- disconnect when reverting the configuration
- always cleanup the provisioning data structures before connecting
  to avoid dummy buffer overwriting and data length issues

Signed-off-by: Marcin Kajor <marcin.kajor@nordicsemi.no>

* Introduced a workaround to send Router Solicitation after connect

Router Solicitation is not sent after connecting to the Wi-Fi
network by the Wi-Fi driver, so in result Thread Border Router
doesn't send Router Advertisement to the device. As a workaround
sending RS was added in the Matter platform code.

* Forward the channel number and RSSI from WIFiManager.

We can now use this feature in spite of stats still
not being implemented.

Signed-off-by: Marcin Kajor <marcin.kajor@nordicsemi.no>

* Minor fixes for heap usage

Fix build with CHIP_MALLOC_SYS_HEAP Kconfig option that
replaces default malloc/free with alternatives based on
Zephyr's sys_heap.

Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>

* Wi-Fi status handling fixes.

* Increase the SYSTEM_WORKQUEUE_STACK_SIZE to match supplicant needs
* Decrease the connection timeout to be lower than failsafe (35s)
* Adapt WiFiRequestStatus to follow supplicant implementation
* All of above makes the failsafe more robust

Signed-off-by: Marcin Kajor <marcin.kajor@nordicsemi.no>

* wifi: RevertConfiguration optimization.

Do not disconnect/reconnect to the already attached network.

Signed-off-by: Marcin Kajor <marcin.kajor@nordicsemi.no>

* Define _DEFAULT_SOURCE

This commit updates the chip-module build configurations to define
`_DEFAULT_SOURCE` when compiling Matter because it uses non-standard
functions that are only available when `_DEFAULT_SOURCE` is defined.

Note that this used to be not necessary only because of a quirk in the
way Newlib handles the feature test macro, which resulted in Newlib
defining `_DEFAULT_SOURCE` when compiling with `-std=gnu`.

For more details, refer to the issue zephyrproject-rtos/zephyr#52739.

* Align examples with samples included in nRF Connect SDK 2.2.0

* Update remaining Docker images to 0.6.27

* Restyled by clang-format

* Restyled by shellharden

Signed-off-by: Marcin Kajor <marcin.kajor@nordicsemi.no>
Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
Co-authored-by: Marcin Kajor <marcin.kajor@nordicsemi.no>
Co-authored-by: Kamil Kasperczyk <kamil.kasperczyk@nordicsemi.no>
Co-authored-by: Restyled.io <commits@restyled.io>
Co-authored-by: Andrei Litvin <andy314@gmail.com>
diff --git a/src/platform/nrfconnect/wifi/NrfWiFiDriver.h b/src/platform/nrfconnect/wifi/NrfWiFiDriver.h
index 880cce8..7b57607 100644
--- a/src/platform/nrfconnect/wifi/NrfWiFiDriver.h
+++ b/src/platform/nrfconnect/wifi/NrfWiFiDriver.h
@@ -16,6 +16,9 @@
  */
 
 #pragma once
+
+#include "WiFiManager.h"
+
 #include <platform/NetworkCommissioning.h>
 
 namespace chip {
@@ -24,7 +27,7 @@
 
 constexpr uint8_t kMaxWiFiNetworks                  = 1;
 constexpr uint8_t kWiFiScanNetworksTimeOutSeconds   = 10;
-constexpr uint8_t kWiFiConnectNetworkTimeoutSeconds = 120;
+constexpr uint8_t kWiFiConnectNetworkTimeoutSeconds = 35;
 
 class NrfWiFiScanResponseIterator : public Iterator<WiFiScanResponse>
 {
@@ -62,19 +65,6 @@
         bool mExhausted{ false };
     };
 
-    struct WiFiNetwork
-    {
-        uint8_t ssid[DeviceLayer::Internal::kMaxWiFiSSIDLength];
-        size_t ssidLen = 0;
-        uint8_t pass[DeviceLayer::Internal::kMaxWiFiKeyLength];
-        size_t passLen = 0;
-
-        bool IsConfigured() const { return ssidLen > 0; }
-        ByteSpan GetSsidSpan() const { return ByteSpan(ssid, ssidLen); }
-        ByteSpan GetPassSpan() const { return ByteSpan(pass, passLen); }
-        void Clear() { ssidLen = 0; }
-    };
-
     // BaseDriver
     NetworkIterator * GetNetworks() override { return new WiFiNetworkIterator(this); }
     CHIP_ERROR Init(NetworkStatusChangeCallback * networkStatusChangeCallback) override;
@@ -103,17 +93,16 @@
         return sInstance;
     }
 
-    void OnConnectWiFiNetwork();
-    void OnConnectWiFiNetworkFailed();
     void OnNetworkStatusChanged(Status status);
-    void OnScanWiFiNetworkDone(int status, WiFiScanResponse * result);
+    void OnScanWiFiNetworkResult(const WiFiScanResponse & result);
+    void OnScanWiFiNetworkDone(WiFiManager::WiFiRequestStatus status);
 
 private:
     void LoadFromStorage();
 
     ConnectCallback * mpConnectCallback{ nullptr };
     NetworkStatusChangeCallback * mpNetworkStatusChangeCallback{ nullptr };
-    WiFiNetwork mStagingNetwork;
+    WiFiManager::WiFiNetwork mStagingNetwork;
     NrfWiFiScanResponseIterator mScanResponseIterator;
     ScanCallback * mScanCallback{ nullptr };
 };