From 286830508e981be8018f2c2e8831a472056ebf87 Mon Sep 17 00:00:00 2001 From: Song GUO Date: Wed, 30 Mar 2022 23:43:46 +0800 Subject: [PATCH] [nwprov] Add missing debugText and index to some synchronous commands (#16676) * [nwprov] Add missing debugText and index to some synchronous commands * string search / replace for platform code * Run codegen * Address comments * Update examples * Fix * Fix * Fix * Fix * Run Codegen --- .../all-clusters-app.matter | 3 +- .../bridge-common/bridge-app.matter | 3 +- .../door-lock-common/door-lock-app.matter | 3 +- .../light-switch-app.matter | 3 +- .../lighting-common/lighting-app.matter | 3 +- examples/lock-app/lock-common/lock-app.matter | 3 +- .../log-source-common/log-source-app.matter | 3 +- .../ota-provider-app.matter | 3 +- .../ota-requestor-app.matter | 3 +- .../placeholder/linux/apps/app1/config.matter | 3 +- .../placeholder/linux/apps/app2/config.matter | 3 +- examples/pump-app/pump-common/pump-app.matter | 3 +- .../pump-controller-app.matter | 3 +- .../esp32/main/temperature-measurement.matter | 3 +- .../thermostat-common/thermostat.matter | 3 +- examples/tv-app/tv-common/tv-app.matter | 6 ++- .../tv-casting-common/tv-casting-app.matter | 3 +- examples/window-app/common/window-app.matter | 3 +- .../network-commissioning.cpp | 53 +++++++++++++++++-- .../zcl/data-model/chip/commissioning.xml | 3 +- .../data_model/controller-clusters.matter | 3 +- .../zap-generated/CHIPInvokeCallbacks.cpp | 33 ++++++++++-- .../chip/devicecontroller/ChipClusters.java | 3 +- .../devicecontroller/ClusterInfoMapping.java | 9 +++- .../python/chip/clusters/Objects.py | 6 ++- .../test_scripts/network_commissioning.py | 6 +++ .../CHIP/zap-generated/CHIPCallbackBridge.mm | 17 ++++-- .../zap-generated/CHIPCommandPayloadsObjc.h | 3 +- .../zap-generated/CHIPCommandPayloadsObjc.mm | 4 +- src/include/platform/NetworkCommissioning.h | 45 ++++++++++++++-- src/lib/core/CHIPConfig.h | 12 ++++- .../Ameba/NetworkCommissioningDriver.h | 7 +-- .../Ameba/NetworkCommissioningWiFiDriver.cpp | 12 +++-- .../EFR32/NetworkCommissioningWiFiDriver.cpp | 12 +++-- .../EFR32/NetworkCommissioningWiFiDriver.h | 7 +-- .../ESP32/NetworkCommissioningDriver.cpp | 13 +++-- .../ESP32/NetworkCommissioningDriver.h | 7 +-- .../Linux/NetworkCommissioningDriver.h | 13 ++--- .../NetworkCommissioningThreadDriver.cpp | 12 +++-- .../Linux/NetworkCommissioningWiFiDriver.cpp | 12 +++-- ...enericNetworkCommissioningThreadDriver.cpp | 13 +++-- .../GenericNetworkCommissioningThreadDriver.h | 6 +-- src/platform/P6/NetworkCommissioningDriver.h | 7 +-- .../P6/NetworkCommissioningWiFiDriver.cpp | 12 +++-- .../Tizen/NetworkCommissioningDriver.h | 7 +-- .../Tizen/NetworkCommissioningWiFiDriver.cpp | 12 +++-- .../mbed/ConnectivityManagerImpl_WiFi.cpp | 5 +- .../DeviceNetworkProvisioningDelegateImpl.cpp | 5 +- .../mbed/NetworkCommissioningDriver.h | 7 +-- .../mbed/NetworkCommissioningWiFiDriver.cpp | 12 +++-- .../app-common/zap-generated/callback.h | 3 +- .../zap-generated/cluster-objects.cpp | 4 ++ .../zap-generated/cluster-objects.h | 7 ++- .../cluster/logging/DataModelLogger.cpp | 1 + 54 files changed, 346 insertions(+), 104 deletions(-) diff --git a/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter b/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter index 9f07b140e72d3b..a696d3a23ba6c3 100644 --- a/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter +++ b/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter @@ -2108,7 +2108,8 @@ server cluster NetworkCommissioning = 49 { response struct NetworkConfigResponse { NetworkCommissioningStatus networkingStatus = 0; - CHAR_STRING debugText = 1; + optional CHAR_STRING debugText = 1; + optional INT8U networkIndex = 2; } response struct ConnectNetworkResponse { diff --git a/examples/bridge-app/bridge-common/bridge-app.matter b/examples/bridge-app/bridge-common/bridge-app.matter index 680859503ceb7e..dbe5435d7c2c5a 100644 --- a/examples/bridge-app/bridge-common/bridge-app.matter +++ b/examples/bridge-app/bridge-common/bridge-app.matter @@ -628,7 +628,8 @@ server cluster NetworkCommissioning = 49 { response struct NetworkConfigResponse { NetworkCommissioningStatus networkingStatus = 0; - CHAR_STRING debugText = 1; + optional CHAR_STRING debugText = 1; + optional INT8U networkIndex = 2; } response struct ConnectNetworkResponse { diff --git a/examples/door-lock-app/door-lock-common/door-lock-app.matter b/examples/door-lock-app/door-lock-common/door-lock-app.matter index bb962dfbbe3248..151e3b37b8cd7d 100644 --- a/examples/door-lock-app/door-lock-common/door-lock-app.matter +++ b/examples/door-lock-app/door-lock-common/door-lock-app.matter @@ -1025,7 +1025,8 @@ server cluster NetworkCommissioning = 49 { response struct NetworkConfigResponse { NetworkCommissioningStatus networkingStatus = 0; - CHAR_STRING debugText = 1; + optional CHAR_STRING debugText = 1; + optional INT8U networkIndex = 2; } response struct ConnectNetworkResponse { diff --git a/examples/light-switch-app/light-switch-common/light-switch-app.matter b/examples/light-switch-app/light-switch-common/light-switch-app.matter index b1696aaaf0eb10..76a3554d342085 100644 --- a/examples/light-switch-app/light-switch-common/light-switch-app.matter +++ b/examples/light-switch-app/light-switch-common/light-switch-app.matter @@ -917,7 +917,8 @@ server cluster NetworkCommissioning = 49 { response struct NetworkConfigResponse { NetworkCommissioningStatus networkingStatus = 0; - CHAR_STRING debugText = 1; + optional CHAR_STRING debugText = 1; + optional INT8U networkIndex = 2; } response struct ConnectNetworkResponse { diff --git a/examples/lighting-app/lighting-common/lighting-app.matter b/examples/lighting-app/lighting-common/lighting-app.matter index 948f84ab2f3854..5461c33414c223 100644 --- a/examples/lighting-app/lighting-common/lighting-app.matter +++ b/examples/lighting-app/lighting-common/lighting-app.matter @@ -988,7 +988,8 @@ server cluster NetworkCommissioning = 49 { response struct NetworkConfigResponse { NetworkCommissioningStatus networkingStatus = 0; - CHAR_STRING debugText = 1; + optional CHAR_STRING debugText = 1; + optional INT8U networkIndex = 2; } response struct ConnectNetworkResponse { diff --git a/examples/lock-app/lock-common/lock-app.matter b/examples/lock-app/lock-common/lock-app.matter index 04368bc3032d03..72830635b56ed0 100644 --- a/examples/lock-app/lock-common/lock-app.matter +++ b/examples/lock-app/lock-common/lock-app.matter @@ -481,7 +481,8 @@ server cluster NetworkCommissioning = 49 { response struct NetworkConfigResponse { NetworkCommissioningStatus networkingStatus = 0; - CHAR_STRING debugText = 1; + optional CHAR_STRING debugText = 1; + optional INT8U networkIndex = 2; } response struct ConnectNetworkResponse { diff --git a/examples/log-source-app/log-source-common/log-source-app.matter b/examples/log-source-app/log-source-common/log-source-app.matter index 17bf6728a5b6be..54bf0ff43b089a 100644 --- a/examples/log-source-app/log-source-common/log-source-app.matter +++ b/examples/log-source-app/log-source-common/log-source-app.matter @@ -272,7 +272,8 @@ server cluster NetworkCommissioning = 49 { response struct NetworkConfigResponse { NetworkCommissioningStatus networkingStatus = 0; - CHAR_STRING debugText = 1; + optional CHAR_STRING debugText = 1; + optional INT8U networkIndex = 2; } response struct ConnectNetworkResponse { diff --git a/examples/ota-provider-app/ota-provider-common/ota-provider-app.matter b/examples/ota-provider-app/ota-provider-common/ota-provider-app.matter index 804504050e73f6..7e8f0243f2ceec 100644 --- a/examples/ota-provider-app/ota-provider-common/ota-provider-app.matter +++ b/examples/ota-provider-app/ota-provider-common/ota-provider-app.matter @@ -345,7 +345,8 @@ server cluster NetworkCommissioning = 49 { response struct NetworkConfigResponse { NetworkCommissioningStatus networkingStatus = 0; - CHAR_STRING debugText = 1; + optional CHAR_STRING debugText = 1; + optional INT8U networkIndex = 2; } response struct ConnectNetworkResponse { diff --git a/examples/ota-requestor-app/ota-requestor-common/ota-requestor-app.matter b/examples/ota-requestor-app/ota-requestor-common/ota-requestor-app.matter index 03275f68698589..3d2f863c86c21a 100644 --- a/examples/ota-requestor-app/ota-requestor-common/ota-requestor-app.matter +++ b/examples/ota-requestor-app/ota-requestor-common/ota-requestor-app.matter @@ -318,7 +318,8 @@ server cluster NetworkCommissioning = 49 { response struct NetworkConfigResponse { NetworkCommissioningStatus networkingStatus = 0; - CHAR_STRING debugText = 1; + optional CHAR_STRING debugText = 1; + optional INT8U networkIndex = 2; } response struct ConnectNetworkResponse { diff --git a/examples/placeholder/linux/apps/app1/config.matter b/examples/placeholder/linux/apps/app1/config.matter index ac66e224a4e2dd..0ac5d8029825f1 100644 --- a/examples/placeholder/linux/apps/app1/config.matter +++ b/examples/placeholder/linux/apps/app1/config.matter @@ -1175,7 +1175,8 @@ server cluster NetworkCommissioning = 49 { response struct NetworkConfigResponse { NetworkCommissioningStatus networkingStatus = 0; - CHAR_STRING debugText = 1; + optional CHAR_STRING debugText = 1; + optional INT8U networkIndex = 2; } response struct ConnectNetworkResponse { diff --git a/examples/placeholder/linux/apps/app2/config.matter b/examples/placeholder/linux/apps/app2/config.matter index ac66e224a4e2dd..0ac5d8029825f1 100644 --- a/examples/placeholder/linux/apps/app2/config.matter +++ b/examples/placeholder/linux/apps/app2/config.matter @@ -1175,7 +1175,8 @@ server cluster NetworkCommissioning = 49 { response struct NetworkConfigResponse { NetworkCommissioningStatus networkingStatus = 0; - CHAR_STRING debugText = 1; + optional CHAR_STRING debugText = 1; + optional INT8U networkIndex = 2; } response struct ConnectNetworkResponse { diff --git a/examples/pump-app/pump-common/pump-app.matter b/examples/pump-app/pump-common/pump-app.matter index 481b4f38b41c83..2db1ef56b4b972 100644 --- a/examples/pump-app/pump-common/pump-app.matter +++ b/examples/pump-app/pump-common/pump-app.matter @@ -728,7 +728,8 @@ server cluster NetworkCommissioning = 49 { response struct NetworkConfigResponse { NetworkCommissioningStatus networkingStatus = 0; - CHAR_STRING debugText = 1; + optional CHAR_STRING debugText = 1; + optional INT8U networkIndex = 2; } response struct ConnectNetworkResponse { diff --git a/examples/pump-controller-app/pump-controller-common/pump-controller-app.matter b/examples/pump-controller-app/pump-controller-common/pump-controller-app.matter index 2970870ceef26e..5f98655bba5a93 100644 --- a/examples/pump-controller-app/pump-controller-common/pump-controller-app.matter +++ b/examples/pump-controller-app/pump-controller-common/pump-controller-app.matter @@ -639,7 +639,8 @@ server cluster NetworkCommissioning = 49 { response struct NetworkConfigResponse { NetworkCommissioningStatus networkingStatus = 0; - CHAR_STRING debugText = 1; + optional CHAR_STRING debugText = 1; + optional INT8U networkIndex = 2; } response struct ConnectNetworkResponse { diff --git a/examples/temperature-measurement-app/esp32/main/temperature-measurement.matter b/examples/temperature-measurement-app/esp32/main/temperature-measurement.matter index 41787faba07523..adcc8102620338 100644 --- a/examples/temperature-measurement-app/esp32/main/temperature-measurement.matter +++ b/examples/temperature-measurement-app/esp32/main/temperature-measurement.matter @@ -474,7 +474,8 @@ server cluster NetworkCommissioning = 49 { response struct NetworkConfigResponse { NetworkCommissioningStatus networkingStatus = 0; - CHAR_STRING debugText = 1; + optional CHAR_STRING debugText = 1; + optional INT8U networkIndex = 2; } response struct ConnectNetworkResponse { diff --git a/examples/thermostat/thermostat-common/thermostat.matter b/examples/thermostat/thermostat-common/thermostat.matter index 64c92f2445f131..36ec3d69735d18 100644 --- a/examples/thermostat/thermostat-common/thermostat.matter +++ b/examples/thermostat/thermostat-common/thermostat.matter @@ -649,7 +649,8 @@ server cluster NetworkCommissioning = 49 { response struct NetworkConfigResponse { NetworkCommissioningStatus networkingStatus = 0; - CHAR_STRING debugText = 1; + optional CHAR_STRING debugText = 1; + optional INT8U networkIndex = 2; } response struct ConnectNetworkResponse { diff --git a/examples/tv-app/tv-common/tv-app.matter b/examples/tv-app/tv-common/tv-app.matter index c297c0bc0cb9b1..970411654a30d9 100644 --- a/examples/tv-app/tv-common/tv-app.matter +++ b/examples/tv-app/tv-common/tv-app.matter @@ -1187,7 +1187,8 @@ client cluster NetworkCommissioning = 49 { response struct NetworkConfigResponse { NetworkCommissioningStatus networkingStatus = 0; - CHAR_STRING debugText = 1; + optional CHAR_STRING debugText = 1; + optional INT8U networkIndex = 2; } response struct ConnectNetworkResponse { @@ -1312,7 +1313,8 @@ server cluster NetworkCommissioning = 49 { response struct NetworkConfigResponse { NetworkCommissioningStatus networkingStatus = 0; - CHAR_STRING debugText = 1; + optional CHAR_STRING debugText = 1; + optional INT8U networkIndex = 2; } response struct ConnectNetworkResponse { diff --git a/examples/tv-casting-app/tv-casting-common/tv-casting-app.matter b/examples/tv-casting-app/tv-casting-common/tv-casting-app.matter index ae6b188c18f73a..2b1c4a3f202ebd 100644 --- a/examples/tv-casting-app/tv-casting-common/tv-casting-app.matter +++ b/examples/tv-casting-app/tv-casting-common/tv-casting-app.matter @@ -1338,7 +1338,8 @@ server cluster NetworkCommissioning = 49 { response struct NetworkConfigResponse { NetworkCommissioningStatus networkingStatus = 0; - CHAR_STRING debugText = 1; + optional CHAR_STRING debugText = 1; + optional INT8U networkIndex = 2; } response struct ConnectNetworkResponse { diff --git a/examples/window-app/common/window-app.matter b/examples/window-app/common/window-app.matter index f07ad114602d28..3cae0107771397 100644 --- a/examples/window-app/common/window-app.matter +++ b/examples/window-app/common/window-app.matter @@ -494,7 +494,8 @@ server cluster NetworkCommissioning = 49 { response struct NetworkConfigResponse { NetworkCommissioningStatus networkingStatus = 0; - CHAR_STRING debugText = 1; + optional CHAR_STRING debugText = 1; + optional INT8U networkIndex = 2; } response struct ConnectNetworkResponse { diff --git a/src/app/clusters/network-commissioning/network-commissioning.cpp b/src/app/clusters/network-commissioning/network-commissioning.cpp index f9695cd761a544..56eab8edd4142f 100644 --- a/src/app/clusters/network-commissioning/network-commissioning.cpp +++ b/src/app/clusters/network-commissioning/network-commissioning.cpp @@ -286,11 +286,35 @@ void Instance::HandleScanNetworks(HandlerContext & ctx, const Commands::ScanNetw } } +namespace { + +void FillDebugTextAndNetworkIndex(Commands::NetworkConfigResponse::Type & response, MutableCharSpan debugText, uint8_t networkIndex) +{ + if (debugText.size() > 0) + { + response.debugText.SetValue(CharSpan(debugText.data(), debugText.size())); + } + if (response.networkingStatus == NetworkCommissioningStatus::kSuccess) + { + response.networkIndex.SetValue(networkIndex); + } +} + +} // namespace + void Instance::HandleAddOrUpdateWiFiNetwork(HandlerContext & ctx, const Commands::AddOrUpdateWiFiNetwork::DecodableType & req) { MATTER_TRACE_EVENT_SCOPE("HandleAddOrUpdateWiFiNetwork", "NetworkCommissioning"); Commands::NetworkConfigResponse::Type response; - response.networkingStatus = ToClusterObjectEnum(mpDriver.Get()->AddOrUpdateNetwork(req.ssid, req.credentials)); + MutableCharSpan debugText; +#if CHIP_CONFIG_NETWORK_COMMISSIONING_DEBUG_TEXT_BUFFER_SIZE + char debugTextBuffer[CHIP_CONFIG_NETWORK_COMMISSIONING_DEBUG_TEXT_BUFFER_SIZE]; + debugText = MutableCharSpan(debugTextBuffer); +#endif + uint8_t outNetworkIndex = 0; + response.networkingStatus = ToClusterObjectEnum( + mpDriver.Get()->AddOrUpdateNetwork(req.ssid, req.credentials, debugText, outNetworkIndex)); + FillDebugTextAndNetworkIndex(response, debugText, outNetworkIndex); ctx.mCommandHandler.AddResponse(ctx.mRequestPath, response); } @@ -298,7 +322,15 @@ void Instance::HandleAddOrUpdateThreadNetwork(HandlerContext & ctx, const Comman { MATTER_TRACE_EVENT_SCOPE("HandleAddOrUpdateThreadNetwork", "NetworkCommissioning"); Commands::NetworkConfigResponse::Type response; - response.networkingStatus = ToClusterObjectEnum(mpDriver.Get()->AddOrUpdateNetwork(req.operationalDataset)); + MutableCharSpan debugText; +#if CHIP_CONFIG_NETWORK_COMMISSIONING_DEBUG_TEXT_BUFFER_SIZE + char debugTextBuffer[CHIP_CONFIG_NETWORK_COMMISSIONING_DEBUG_TEXT_BUFFER_SIZE]; + debugText = MutableCharSpan(debugTextBuffer); +#endif + uint8_t outNetworkIndex = 0; + response.networkingStatus = + ToClusterObjectEnum(mpDriver.Get()->AddOrUpdateNetwork(req.operationalDataset, debugText, outNetworkIndex)); + FillDebugTextAndNetworkIndex(response, debugText, outNetworkIndex); ctx.mCommandHandler.AddResponse(ctx.mRequestPath, response); } @@ -306,7 +338,14 @@ void Instance::HandleRemoveNetwork(HandlerContext & ctx, const Commands::RemoveN { MATTER_TRACE_EVENT_SCOPE("HandleRemoveNetwork", "NetworkCommissioning"); Commands::NetworkConfigResponse::Type response; - response.networkingStatus = ToClusterObjectEnum(mpWirelessDriver->RemoveNetwork(req.networkID)); + MutableCharSpan debugText; +#if CHIP_CONFIG_NETWORK_COMMISSIONING_DEBUG_TEXT_BUFFER_SIZE + char debugTextBuffer[CHIP_CONFIG_NETWORK_COMMISSIONING_DEBUG_TEXT_BUFFER_SIZE]; + debugText = MutableCharSpan(debugTextBuffer); +#endif + uint8_t outNetworkIndex = 0; + response.networkingStatus = ToClusterObjectEnum(mpWirelessDriver->RemoveNetwork(req.networkID, debugText, outNetworkIndex)); + FillDebugTextAndNetworkIndex(response, debugText, outNetworkIndex); ctx.mCommandHandler.AddResponse(ctx.mRequestPath, response); } @@ -330,7 +369,13 @@ void Instance::HandleReorderNetwork(HandlerContext & ctx, const Commands::Reorde { MATTER_TRACE_EVENT_SCOPE("HandleReorderNetwork", "NetworkCommissioning"); Commands::NetworkConfigResponse::Type response; - response.networkingStatus = ToClusterObjectEnum(mpWirelessDriver->ReorderNetwork(req.networkID, req.networkIndex)); + MutableCharSpan debugText; +#if CHIP_CONFIG_NETWORK_COMMISSIONING_DEBUG_TEXT_BUFFER_SIZE + char debugTextBuffer[CHIP_CONFIG_NETWORK_COMMISSIONING_DEBUG_TEXT_BUFFER_SIZE]; + debugText = MutableCharSpan(debugTextBuffer); +#endif + response.networkingStatus = ToClusterObjectEnum(mpWirelessDriver->ReorderNetwork(req.networkID, req.networkIndex, debugText)); + FillDebugTextAndNetworkIndex(response, debugText, req.networkIndex); ctx.mCommandHandler.AddResponse(ctx.mRequestPath, response); } diff --git a/src/app/zap-templates/zcl/data-model/chip/commissioning.xml b/src/app/zap-templates/zcl/data-model/chip/commissioning.xml index 687525d9034a3a..5218ae198c118e 100644 --- a/src/app/zap-templates/zcl/data-model/chip/commissioning.xml +++ b/src/app/zap-templates/zcl/data-model/chip/commissioning.xml @@ -122,7 +122,8 @@ limitations under the License. TODO - + + TODO diff --git a/src/controller/data_model/controller-clusters.matter b/src/controller/data_model/controller-clusters.matter index 87cb839d7528fc..a39c5ee34de2b8 100644 --- a/src/controller/data_model/controller-clusters.matter +++ b/src/controller/data_model/controller-clusters.matter @@ -2505,7 +2505,8 @@ client cluster NetworkCommissioning = 49 { response struct NetworkConfigResponse { NetworkCommissioningStatus networkingStatus = 0; - CHAR_STRING debugText = 1; + optional CHAR_STRING debugText = 1; + optional INT8U networkIndex = 2; } response struct ConnectNetworkResponse { diff --git a/src/controller/java/zap-generated/CHIPInvokeCallbacks.cpp b/src/controller/java/zap-generated/CHIPInvokeCallbacks.cpp index 4a5bbbd08eb7fe..5bfce2a682bf08 100644 --- a/src/controller/java/zap-generated/CHIPInvokeCallbacks.cpp +++ b/src/controller/java/zap-generated/CHIPInvokeCallbacks.cpp @@ -2038,8 +2038,8 @@ void CHIPNetworkCommissioningClusterNetworkConfigResponseCallback::CallbackFn( // Java callback is allowed to be null, exit early if this is the case. VerifyOrReturn(javaCallbackRef != nullptr); - err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;Ljava/lang/String;)V", - &javaMethod); + err = JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", + "(Ljava/lang/Integer;Ljava/util/Optional;Ljava/util/Optional;)V", &javaMethod); VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error invoking Java callback: %s", ErrorStr(err))); jobject NetworkingStatus; @@ -2049,9 +2049,34 @@ void CHIPNetworkCommissioningClusterNetworkConfigResponseCallback::CallbackFn( NetworkingStatusClassName.c_str(), NetworkingStatusCtorSignature.c_str(), static_cast(dataResponse.networkingStatus), NetworkingStatus); jobject DebugText; - DebugText = env->NewStringUTF(std::string(dataResponse.debugText.data(), dataResponse.debugText.size()).c_str()); + if (!dataResponse.debugText.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, DebugText); + } + else + { + jobject DebugTextInsideOptional; + DebugTextInsideOptional = + env->NewStringUTF(std::string(dataResponse.debugText.Value().data(), dataResponse.debugText.Value().size()).c_str()); + chip::JniReferences::GetInstance().CreateOptional(DebugTextInsideOptional, DebugText); + } + jobject NetworkIndex; + if (!dataResponse.networkIndex.HasValue()) + { + chip::JniReferences::GetInstance().CreateOptional(nullptr, NetworkIndex); + } + else + { + jobject NetworkIndexInsideOptional; + std::string NetworkIndexInsideOptionalClassName = "java/lang/Integer"; + std::string NetworkIndexInsideOptionalCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject( + NetworkIndexInsideOptionalClassName.c_str(), NetworkIndexInsideOptionalCtorSignature.c_str(), + dataResponse.networkIndex.Value(), NetworkIndexInsideOptional); + chip::JniReferences::GetInstance().CreateOptional(NetworkIndexInsideOptional, NetworkIndex); + } - env->CallVoidMethod(javaCallbackRef, javaMethod, NetworkingStatus, DebugText); + env->CallVoidMethod(javaCallbackRef, javaMethod, NetworkingStatus, DebugText, NetworkIndex); } CHIPNetworkCommissioningClusterScanNetworksResponseCallback::CHIPNetworkCommissioningClusterScanNetworksResponseCallback( jobject javaCallback) : diff --git a/src/controller/java/zap-generated/chip/devicecontroller/ChipClusters.java b/src/controller/java/zap-generated/chip/devicecontroller/ChipClusters.java index 16d342275cc298..a30019270f699b 100644 --- a/src/controller/java/zap-generated/chip/devicecontroller/ChipClusters.java +++ b/src/controller/java/zap-generated/chip/devicecontroller/ChipClusters.java @@ -11471,7 +11471,8 @@ public interface ConnectNetworkResponseCallback { } public interface NetworkConfigResponseCallback { - void onSuccess(Integer networkingStatus, String debugText); + void onSuccess( + Integer networkingStatus, Optional debugText, Optional networkIndex); void onError(Exception error); } diff --git a/src/controller/java/zap-generated/chip/devicecontroller/ClusterInfoMapping.java b/src/controller/java/zap-generated/chip/devicecontroller/ClusterInfoMapping.java index f4ac7600e500e2..40c5a26c9e1cb9 100644 --- a/src/controller/java/zap-generated/chip/devicecontroller/ClusterInfoMapping.java +++ b/src/controller/java/zap-generated/chip/devicecontroller/ClusterInfoMapping.java @@ -4161,13 +4161,18 @@ public void setCallbackDelegate(ClusterCommandCallback callback) { } @Override - public void onSuccess(Integer NetworkingStatus, String DebugText) { + public void onSuccess( + Integer NetworkingStatus, Optional DebugText, Optional NetworkIndex) { Map responseValues = new LinkedHashMap<>(); CommandResponseInfo NetworkingStatusResponseValue = new CommandResponseInfo("NetworkingStatus", "Integer"); responseValues.put(NetworkingStatusResponseValue, NetworkingStatus); - CommandResponseInfo DebugTextResponseValue = new CommandResponseInfo("DebugText", "String"); + CommandResponseInfo DebugTextResponseValue = + new CommandResponseInfo("DebugText", "Optional"); responseValues.put(DebugTextResponseValue, DebugText); + CommandResponseInfo NetworkIndexResponseValue = + new CommandResponseInfo("NetworkIndex", "Optional"); + responseValues.put(NetworkIndexResponseValue, NetworkIndex); callback.onSuccess(responseValues); } diff --git a/src/controller/python/chip/clusters/Objects.py b/src/controller/python/chip/clusters/Objects.py index 64c763c56e3d8e..a0229cc266d2d1 100644 --- a/src/controller/python/chip/clusters/Objects.py +++ b/src/controller/python/chip/clusters/Objects.py @@ -9706,11 +9706,13 @@ def descriptor(cls) -> ClusterObjectDescriptor: return ClusterObjectDescriptor( Fields = [ ClusterObjectFieldDescriptor(Label="networkingStatus", Tag=0, Type=NetworkCommissioning.Enums.NetworkCommissioningStatus), - ClusterObjectFieldDescriptor(Label="debugText", Tag=1, Type=str), + ClusterObjectFieldDescriptor(Label="debugText", Tag=1, Type=typing.Optional[str]), + ClusterObjectFieldDescriptor(Label="networkIndex", Tag=2, Type=typing.Optional[uint]), ]) networkingStatus: 'NetworkCommissioning.Enums.NetworkCommissioningStatus' = 0 - debugText: 'str' = "" + debugText: 'typing.Optional[str]' = None + networkIndex: 'typing.Optional[uint]' = None @dataclass class ConnectNetwork(ClusterCommand): diff --git a/src/controller/python/test/test_scripts/network_commissioning.py b/src/controller/python/test/test_scripts/network_commissioning.py index baf8a6da32a851..a9115e0ee3bfd2 100644 --- a/src/controller/python/test/test_scripts/network_commissioning.py +++ b/src/controller/python/test/test_scripts/network_commissioning.py @@ -142,6 +142,9 @@ async def test_wifi(self, endpointId): logger.info(f"Received response: {res}") if res.networkingStatus != Clusters.NetworkCommissioning.Enums.NetworkCommissioningStatus.kSuccess: raise AssertionError(f"Unexpected result: {res.networkingStatus}") + if res.networkIndex != 0: + raise AssertionError( + f"Unexpected result: {res.networkIndex} (should be 0)") logger.info(f"Check network list") res = await self._devCtrl.ReadAttribute(nodeid=self._nodeid, attributes=[(endpointId, Clusters.NetworkCommissioning.Attributes.Networks)], returnClusterObject=True) @@ -240,6 +243,9 @@ async def test_thread(self, endpointId): logger.info(f"Received response: {res}") if res.networkingStatus != Clusters.NetworkCommissioning.Enums.NetworkCommissioningStatus.kSuccess: raise AssertionError(f"Unexpected result: {res.networkingStatus}") + if res.networkIndex != 0: + raise AssertionError( + f"Unexpected result: {res.networkIndex} (should be 0)") logger.info(f"Check network list") res = await self._devCtrl.ReadAttribute(nodeid=self._nodeid, attributes=[(endpointId, Clusters.NetworkCommissioning.Attributes.Networks)], returnClusterObject=True) diff --git a/src/darwin/Framework/CHIP/zap-generated/CHIPCallbackBridge.mm b/src/darwin/Framework/CHIP/zap-generated/CHIPCallbackBridge.mm index 12b53d4db03400..1f2e36e9248a4c 100644 --- a/src/darwin/Framework/CHIP/zap-generated/CHIPCallbackBridge.mm +++ b/src/darwin/Framework/CHIP/zap-generated/CHIPCallbackBridge.mm @@ -11073,9 +11073,20 @@ response.networkingStatus = [NSNumber numberWithUnsignedChar:chip::to_underlying(data.networkingStatus)]; } { - response.debugText = [[NSString alloc] initWithBytes:data.debugText.data() - length:data.debugText.size() - encoding:NSUTF8StringEncoding]; + if (data.debugText.HasValue()) { + response.debugText = [[NSString alloc] initWithBytes:data.debugText.Value().data() + length:data.debugText.Value().size() + encoding:NSUTF8StringEncoding]; + } else { + response.debugText = nil; + } + } + { + if (data.networkIndex.HasValue()) { + response.networkIndex = [NSNumber numberWithUnsignedChar:data.networkIndex.Value()]; + } else { + response.networkIndex = nil; + } } DispatchSuccess(context, response); }; diff --git a/src/darwin/Framework/CHIP/zap-generated/CHIPCommandPayloadsObjc.h b/src/darwin/Framework/CHIP/zap-generated/CHIPCommandPayloadsObjc.h index c26dc1428dcd4c..d8c6d832446f27 100644 --- a/src/darwin/Framework/CHIP/zap-generated/CHIPCommandPayloadsObjc.h +++ b/src/darwin/Framework/CHIP/zap-generated/CHIPCommandPayloadsObjc.h @@ -682,7 +682,8 @@ NS_ASSUME_NONNULL_BEGIN @interface CHIPNetworkCommissioningClusterNetworkConfigResponseParams : NSObject @property (strong, nonatomic) NSNumber * _Nonnull networkingStatus; -@property (strong, nonatomic) NSString * _Nonnull debugText; +@property (strong, nonatomic) NSString * _Nullable debugText; +@property (strong, nonatomic) NSNumber * _Nullable networkIndex; - (instancetype)init; @end diff --git a/src/darwin/Framework/CHIP/zap-generated/CHIPCommandPayloadsObjc.mm b/src/darwin/Framework/CHIP/zap-generated/CHIPCommandPayloadsObjc.mm index 008a1b12fcf19c..250eb841eefab4 100644 --- a/src/darwin/Framework/CHIP/zap-generated/CHIPCommandPayloadsObjc.mm +++ b/src/darwin/Framework/CHIP/zap-generated/CHIPCommandPayloadsObjc.mm @@ -1436,7 +1436,9 @@ - (instancetype)init _networkingStatus = @(0); - _debugText = @""; + _debugText = nil; + + _networkIndex = nil; } return self; } diff --git a/src/include/platform/NetworkCommissioning.h b/src/include/platform/NetworkCommissioning.h index 7661216e0612c6..8a91874b2e19aa 100644 --- a/src/include/platform/NetworkCommissioning.h +++ b/src/include/platform/NetworkCommissioning.h @@ -231,8 +231,26 @@ class WirelessDriver : public Internal::BaseDriver virtual uint8_t GetScanNetworkTimeoutSeconds() = 0; virtual uint8_t GetConnectNetworkTimeoutSeconds() = 0; - virtual Status RemoveNetwork(ByteSpan networkId) = 0; - virtual Status ReorderNetwork(ByteSpan networkId, uint8_t index) = 0; + /** + * @brief Remove a network from the device. The driver should fill the outDebugText field to pass any human-readable messages to + * the client. The driver should reduce the size of outDebugText to 0 to omit it from the response when no debug text needs to + * be delivered. On success, the driver should set outNetworkIndex to the index of the network just removed. The value of + * network index is discarded on failure. + * + * Note: The capacity of outDebugText passed by network commissioning cluster can be configured via + * CHIP_CONFIG_NETWORK_COMMISSIONING_DEBUG_TEXT_BUFFER_SIZE. + */ + virtual Status RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex) = 0; + + /** + * @brief Reorder the networks on the device. The driver should fill the outDebugText field to pass any human-readable messages + * to the client. The driver should reduce the size of outDebugText to 0 to omit it from the response when no debug text needs + * to be delivered. + * + * Note: The capacity of outDebugText passed by network commissioning cluster can be configured via + * CHIP_CONFIG_NETWORK_COMMISSIONING_DEBUG_TEXT_BUFFER_SIZE. + */ + virtual Status ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCharSpan & outDebugText) = 0; /** * @brief Initializes a network join. callback->OnResult must be called, on both success and error. Callback can be @@ -261,7 +279,17 @@ class WiFiDriver : public Internal::WirelessDriver virtual ~ScanCallback() = default; }; - virtual Status AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials) = 0; + /** + * @brief Adds or updates a WiFi network on the device. The driver should fill the outDebugText field to pass any human-readable + * messages to the client. The driver should reduce the size of outDebugText to 0 to omit it from the response when no debug + * text needs to be delivered. On success, the driver should set outNetworkIndex to the index of the network just added or + * updated. The value of network index is discarded on failure. + * + * Note: The capacity of outDebugText passed by network commissioning cluster can be configured via + * CHIP_CONFIG_NETWORK_COMMISSIONING_DEBUG_TEXT_BUFFER_SIZE. + */ + virtual Status AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials, MutableCharSpan & outDebugText, + uint8_t & outNetworkIndex) = 0; /** * @brief Initializes a WiFi network scan. callback->OnFinished must be called, on both success and error. Callback can @@ -294,7 +322,16 @@ class ThreadDriver : public Internal::WirelessDriver virtual ~ScanCallback() = default; }; - virtual Status AddOrUpdateNetwork(ByteSpan operationalDataset) = 0; + /** + * @brief Adds or updates a Thread network on the device. The driver should fill the outDebugText field to pass any + * human-readable messages to the client. The driver should reduce the size of outDebugText to 0 to omit it from the response + * when no debug text needs to be delivered. On success, the driver should set outNetworkIndex to the index of the network just + * added or updated. The value of the network index is discarded on failure. + * + * Note: The capacity of outDebugText passed by network commissioning cluster can be configured via + * CHIP_CONFIG_NETWORK_COMMISSIONING_DEBUG_TEXT_BUFFER_SIZE. + */ + virtual Status AddOrUpdateNetwork(ByteSpan operationalDataset, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex) = 0; /** * @brief Initializes a Thread network scan. callback->OnFinished must be called, on both success and error. Callback can diff --git a/src/lib/core/CHIPConfig.h b/src/lib/core/CHIPConfig.h index a256a0e3fc5123..1e9c53c4289e7a 100644 --- a/src/lib/core/CHIPConfig.h +++ b/src/lib/core/CHIPConfig.h @@ -43,7 +43,7 @@ #include /* COMING SOON: making the INET Layer optional entails making this inclusion optional. */ -//#include "InetConfig.h" +// #include "InetConfig.h" /* #if INET_CONFIG_ENABLE_TCP_ENDPOINT && INET_TCP_IDLE_CHECK_INTERVAL <= 0 #error "chip SDK requires INET_TCP_IDLE_CHECK_INTERVAL > 0" @@ -1785,6 +1785,16 @@ extern const char CHIP_NON_PRODUCTION_MARKER[]; #define CHIP_CONFIG_MINMDNS_DYNAMIC_OPERATIONAL_RESPONDER_LIST 0 #endif // CHIP_CONFIG_MINMDNS_DYNAMIC_OPERATIONAL_RESPONDER_LIST +/* + * @def CHIP_CONFIG_NETWORK_COMMISSIONING_DEBUG_TEXT_BUFFER_SIZE + * + * @brief This buffer will used for holding debug text when handling synchronous invokes (AddOrUpdate / Reorder / Remove). Since we + * don't set this value for most cases and on most platforms, this value can be 0 to always ignore such field. + */ +#ifndef CHIP_CONFIG_NETWORK_COMMISSIONING_DEBUG_TEXT_BUFFER_SIZE +#define CHIP_CONFIG_NETWORK_COMMISSIONING_DEBUG_TEXT_BUFFER_SIZE 64 +#endif // CHIP_CONFIG_NETWORK_COMMISSIONING_DEBUG_TEXT_BUFFER_SIZE + /** * @} */ diff --git a/src/platform/Ameba/NetworkCommissioningDriver.h b/src/platform/Ameba/NetworkCommissioningDriver.h index 0d8c4cb431eae1..aae2afa13dfff1 100644 --- a/src/platform/Ameba/NetworkCommissioningDriver.h +++ b/src/platform/Ameba/NetworkCommissioningDriver.h @@ -100,12 +100,13 @@ class AmebaWiFiDriver final : public WiFiDriver CHIP_ERROR CommitConfiguration() override; CHIP_ERROR RevertConfiguration() override; - Status RemoveNetwork(ByteSpan networkId) override; - Status ReorderNetwork(ByteSpan networkId, uint8_t index) override; + Status RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex) override; + Status ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCharSpan & outDebugText) override; void ConnectNetwork(ByteSpan networkId, ConnectCallback * callback) override; // WiFiDriver - Status AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials) override; + Status AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials, MutableCharSpan & outDebugText, + uint8_t & outNetworkIndex) override; void ScanNetworks(ByteSpan ssid, ScanCallback * callback) override; CHIP_ERROR ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen, const char * key, uint8_t keyLen); diff --git a/src/platform/Ameba/NetworkCommissioningWiFiDriver.cpp b/src/platform/Ameba/NetworkCommissioningWiFiDriver.cpp index 30f07d2564f3fb..9c057fd3954053 100644 --- a/src/platform/Ameba/NetworkCommissioningWiFiDriver.cpp +++ b/src/platform/Ameba/NetworkCommissioningWiFiDriver.cpp @@ -87,8 +87,11 @@ bool AmebaWiFiDriver::NetworkMatch(const WiFiNetwork & network, ByteSpan network return networkId.size() == network.ssidLen && memcmp(networkId.data(), network.ssid, network.ssidLen) == 0; } -Status AmebaWiFiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials) +Status AmebaWiFiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials, MutableCharSpan & outDebugText, + uint8_t & outNetworkIndex) { + outDebugText.reduce_size(0); + outNetworkIndex = 0; VerifyOrReturnError(mStagingNetwork.ssidLen == 0 || NetworkMatch(mStagingNetwork, ssid), Status::kBoundsExceeded); VerifyOrReturnError(credentials.size() <= sizeof(mStagingNetwork.credentials), Status::kOutOfRange); VerifyOrReturnError(ssid.size() <= sizeof(mStagingNetwork.ssid), Status::kOutOfRange); @@ -102,8 +105,10 @@ Status AmebaWiFiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials) return Status::kSuccess; } -Status AmebaWiFiDriver::RemoveNetwork(ByteSpan networkId) +Status AmebaWiFiDriver::RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex) { + outDebugText.reduce_size(0); + outNetworkIndex = 0; VerifyOrReturnError(NetworkMatch(mStagingNetwork, networkId), Status::kNetworkIDNotFound); // Use empty ssid for representing invalid network @@ -111,8 +116,9 @@ Status AmebaWiFiDriver::RemoveNetwork(ByteSpan networkId) return Status::kSuccess; } -Status AmebaWiFiDriver::ReorderNetwork(ByteSpan networkId, uint8_t index) +Status AmebaWiFiDriver::ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCharSpan & outDebugText) { + outDebugText.reduce_size(0); // Only one network is supported now VerifyOrReturnError(index == 0, Status::kOutOfRange); VerifyOrReturnError(NetworkMatch(mStagingNetwork, networkId), Status::kNetworkIDNotFound); diff --git a/src/platform/EFR32/NetworkCommissioningWiFiDriver.cpp b/src/platform/EFR32/NetworkCommissioningWiFiDriver.cpp index 1401b418318499..e742e8d612e250 100644 --- a/src/platform/EFR32/NetworkCommissioningWiFiDriver.cpp +++ b/src/platform/EFR32/NetworkCommissioningWiFiDriver.cpp @@ -83,8 +83,11 @@ bool SlWiFiDriver::NetworkMatch(const WiFiNetwork & network, ByteSpan networkId) return networkId.size() == network.ssidLen && memcmp(networkId.data(), network.ssid, network.ssidLen) == 0; } -Status SlWiFiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials) +Status SlWiFiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials, MutableCharSpan & outDebugText, + uint8_t & outNetworkIndex) { + outDebugText.reduce_size(0); + outNetworkIndex = 0; VerifyOrReturnError(mStagingNetwork.ssidLen == 0 || NetworkMatch(mStagingNetwork, ssid), Status::kBoundsExceeded); VerifyOrReturnError(credentials.size() <= sizeof(mStagingNetwork.credentials), Status::kOutOfRange); VerifyOrReturnError(ssid.size() <= sizeof(mStagingNetwork.ssid), Status::kOutOfRange); @@ -100,8 +103,10 @@ Status SlWiFiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials) return Status::kSuccess; } -Status SlWiFiDriver::RemoveNetwork(ByteSpan networkId) +Status SlWiFiDriver::RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex) { + outDebugText.reduce_size(0); + outNetworkIndex = 0; VerifyOrReturnError(NetworkMatch(mStagingNetwork, networkId), Status::kNetworkIDNotFound); // Use empty ssid for representing invalid network @@ -109,8 +114,9 @@ Status SlWiFiDriver::RemoveNetwork(ByteSpan networkId) return Status::kSuccess; } -Status SlWiFiDriver::ReorderNetwork(ByteSpan networkId, uint8_t index) +Status SlWiFiDriver::ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCharSpan & outDebugText) { + outDebugText.reduce_size(0); // Only one network is supported for now VerifyOrReturnError(index == 0, Status::kOutOfRange); VerifyOrReturnError(NetworkMatch(mStagingNetwork, networkId), Status::kNetworkIDNotFound); diff --git a/src/platform/EFR32/NetworkCommissioningWiFiDriver.h b/src/platform/EFR32/NetworkCommissioningWiFiDriver.h index 9a98a1057f11a1..773e8454f55b04 100644 --- a/src/platform/EFR32/NetworkCommissioningWiFiDriver.h +++ b/src/platform/EFR32/NetworkCommissioningWiFiDriver.h @@ -142,12 +142,13 @@ class SlWiFiDriver final : public WiFiDriver CHIP_ERROR CommitConfiguration() override; CHIP_ERROR RevertConfiguration() override; - Status RemoveNetwork(ByteSpan networkId) override; - Status ReorderNetwork(ByteSpan networkId, uint8_t index) override; + Status RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex) override; + Status ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCharSpan & outDebugText) override; void ConnectNetwork(ByteSpan networkId, ConnectCallback * callback) override; // WiFiDriver - Status AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials) override; + Status AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials, MutableCharSpan & outDebugText, + uint8_t & outNetworkIndex) override; void ScanNetworks(ByteSpan ssid, ScanCallback * callback) override; CHIP_ERROR ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen, const char * key, uint8_t keyLen); diff --git a/src/platform/ESP32/NetworkCommissioningDriver.cpp b/src/platform/ESP32/NetworkCommissioningDriver.cpp index b1dda184f2900d..8098e6bea55f4d 100644 --- a/src/platform/ESP32/NetworkCommissioningDriver.cpp +++ b/src/platform/ESP32/NetworkCommissioningDriver.cpp @@ -92,8 +92,11 @@ bool ESPWiFiDriver::NetworkMatch(const WiFiNetwork & network, ByteSpan networkId return networkId.size() == network.ssidLen && memcmp(networkId.data(), network.ssid, network.ssidLen) == 0; } -Status ESPWiFiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials) +Status ESPWiFiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials, MutableCharSpan & outDebugText, + uint8_t & outNetworkIndex) { + outDebugText.reduce_size(0); + outNetworkIndex = 0; // If device is already connected to WiFi, then disconnect the WiFi, // clear the WiFi configurations and add the newly provided WiFi configurations. if (chip::DeviceLayer::Internal::ESP32Utils::IsStationProvisioned()) @@ -125,8 +128,10 @@ Status ESPWiFiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials) return Status::kSuccess; } -Status ESPWiFiDriver::RemoveNetwork(ByteSpan networkId) +Status ESPWiFiDriver::RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex) { + outDebugText.reduce_size(0); + outNetworkIndex = 0; VerifyOrReturnError(NetworkMatch(mStagingNetwork, networkId), Status::kNetworkIDNotFound); // Use empty ssid for representing invalid network @@ -134,8 +139,10 @@ Status ESPWiFiDriver::RemoveNetwork(ByteSpan networkId) return Status::kSuccess; } -Status ESPWiFiDriver::ReorderNetwork(ByteSpan networkId, uint8_t index) +Status ESPWiFiDriver::ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCharSpan & outDebugText) { + outDebugText.reduce_size(0); + // Only one network is supported now VerifyOrReturnError(index == 0, Status::kOutOfRange); VerifyOrReturnError(NetworkMatch(mStagingNetwork, networkId), Status::kNetworkIDNotFound); diff --git a/src/platform/ESP32/NetworkCommissioningDriver.h b/src/platform/ESP32/NetworkCommissioningDriver.h index 0370ef4396f4c8..e40a39dfbae5ca 100644 --- a/src/platform/ESP32/NetworkCommissioningDriver.h +++ b/src/platform/ESP32/NetworkCommissioningDriver.h @@ -98,12 +98,13 @@ class ESPWiFiDriver final : public WiFiDriver CHIP_ERROR CommitConfiguration() override; CHIP_ERROR RevertConfiguration() override; - Status RemoveNetwork(ByteSpan networkId) override; - Status ReorderNetwork(ByteSpan networkId, uint8_t index) override; + Status RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex) override; + Status ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCharSpan & outDebugText) override; void ConnectNetwork(ByteSpan networkId, ConnectCallback * callback) override; // WiFiDriver - Status AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials) override; + Status AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials, MutableCharSpan & outDebugText, + uint8_t & outNetworkIndex) override; void ScanNetworks(ByteSpan ssid, ScanCallback * callback) override; CHIP_ERROR ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen, const char * key, uint8_t keyLen); diff --git a/src/platform/Linux/NetworkCommissioningDriver.h b/src/platform/Linux/NetworkCommissioningDriver.h index 948de0e19ce64a..a474535cd2e3ff 100644 --- a/src/platform/Linux/NetworkCommissioningDriver.h +++ b/src/platform/Linux/NetworkCommissioningDriver.h @@ -90,12 +90,13 @@ class LinuxWiFiDriver final : public WiFiDriver CHIP_ERROR CommitConfiguration() override; CHIP_ERROR RevertConfiguration() override; - Status RemoveNetwork(ByteSpan networkId) override; - Status ReorderNetwork(ByteSpan networkId, uint8_t index) override; + Status RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex) override; + Status ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCharSpan & outDebugText) override; void ConnectNetwork(ByteSpan networkId, ConnectCallback * callback) override; // WiFiDriver - Status AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials) override; + Status AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials, MutableCharSpan & outDebugText, + uint8_t & outNetworkIndex) override; void ScanNetworks(ByteSpan ssid, ScanCallback * callback) override; private: @@ -139,12 +140,12 @@ class LinuxThreadDriver final : public ThreadDriver CHIP_ERROR CommitConfiguration() override; CHIP_ERROR RevertConfiguration() override; - Status RemoveNetwork(ByteSpan networkId) override; - Status ReorderNetwork(ByteSpan networkId, uint8_t index) override; + Status RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex) override; + Status ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCharSpan & outDebugText) override; void ConnectNetwork(ByteSpan networkId, ConnectCallback * callback) override; // ThreadDriver - Status AddOrUpdateNetwork(ByteSpan operationalDataset) override; + Status AddOrUpdateNetwork(ByteSpan operationalDataset, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex) override; void ScanNetworks(ThreadDriver::ScanCallback * callback) override; private: diff --git a/src/platform/Linux/NetworkCommissioningThreadDriver.cpp b/src/platform/Linux/NetworkCommissioningThreadDriver.cpp index e8f079e1ae0e7e..74c071bc509e2d 100644 --- a/src/platform/Linux/NetworkCommissioningThreadDriver.cpp +++ b/src/platform/Linux/NetworkCommissioningThreadDriver.cpp @@ -75,12 +75,13 @@ CHIP_ERROR LinuxThreadDriver::RevertConfiguration() return CHIP_NO_ERROR; } -Status LinuxThreadDriver::AddOrUpdateNetwork(ByteSpan operationalDataset) +Status LinuxThreadDriver::AddOrUpdateNetwork(ByteSpan operationalDataset, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex) { uint8_t extpanid[kSizeExtendedPanId]; uint8_t newExtpanid[kSizeExtendedPanId]; Thread::OperationalDataset newDataset; - + outDebugText.reduce_size(0); + outNetworkIndex = 0; newDataset.Init(operationalDataset); VerifyOrReturnError(newDataset.IsCommissioned(), Status::kOutOfRange); @@ -91,8 +92,10 @@ Status LinuxThreadDriver::AddOrUpdateNetwork(ByteSpan operationalDataset) return Status::kSuccess; } -Status LinuxThreadDriver::RemoveNetwork(ByteSpan networkId) +Status LinuxThreadDriver::RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex) { + outDebugText.reduce_size(0); + outNetworkIndex = 0; uint8_t extpanid[kSizeExtendedPanId]; if (!mStagingNetwork.IsCommissioned()) { @@ -109,8 +112,9 @@ Status LinuxThreadDriver::RemoveNetwork(ByteSpan networkId) return Status::kSuccess; } -Status LinuxThreadDriver::ReorderNetwork(ByteSpan networkId, uint8_t index) +Status LinuxThreadDriver::ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCharSpan & outDebugText) { + outDebugText.reduce_size(0); uint8_t extpanid[kSizeExtendedPanId]; if (!mStagingNetwork.IsCommissioned()) { diff --git a/src/platform/Linux/NetworkCommissioningWiFiDriver.cpp b/src/platform/Linux/NetworkCommissioningWiFiDriver.cpp index 47ae49833c483d..ff9b95ab1d9e9a 100644 --- a/src/platform/Linux/NetworkCommissioningWiFiDriver.cpp +++ b/src/platform/Linux/NetworkCommissioningWiFiDriver.cpp @@ -105,8 +105,11 @@ bool LinuxWiFiDriver::NetworkMatch(const WiFiNetwork & network, ByteSpan network return networkId.size() == network.ssidLen && memcmp(networkId.data(), network.ssid, network.ssidLen) == 0; } -Status LinuxWiFiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials) +Status LinuxWiFiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials, MutableCharSpan & outDebugText, + uint8_t & outNetworkIndex) { + outDebugText.reduce_size(0); + outNetworkIndex = 0; VerifyOrReturnError(mStagingNetwork.ssidLen == 0 || NetworkMatch(mStagingNetwork, ssid), Status::kBoundsExceeded); static_assert(sizeof(WiFiNetwork::ssid) <= std::numeric_limits::max(), @@ -127,8 +130,10 @@ Status LinuxWiFiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials) return Status::kSuccess; } -Status LinuxWiFiDriver::RemoveNetwork(ByteSpan networkId) +Status LinuxWiFiDriver::RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex) { + outDebugText.reduce_size(0); + outNetworkIndex = 0; VerifyOrReturnError(NetworkMatch(mStagingNetwork, networkId), Status::kNetworkIDNotFound); // Use empty ssid for representing invalid network @@ -136,8 +141,9 @@ Status LinuxWiFiDriver::RemoveNetwork(ByteSpan networkId) return Status::kSuccess; } -Status LinuxWiFiDriver::ReorderNetwork(ByteSpan networkId, uint8_t index) +Status LinuxWiFiDriver::ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCharSpan & outDebugText) { + outDebugText.reduce_size(0); VerifyOrReturnError(NetworkMatch(mStagingNetwork, networkId), Status::kNetworkIDNotFound); // We only support one network, so reorder is actually no-op. diff --git a/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp b/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp index 717bc02264bc44..153c37e055768f 100644 --- a/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp +++ b/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.cpp @@ -70,12 +70,16 @@ CHIP_ERROR GenericThreadDriver::RevertConfiguration() return CHIP_NO_ERROR; } -Status GenericThreadDriver::AddOrUpdateNetwork(ByteSpan operationalDataset) +Status GenericThreadDriver::AddOrUpdateNetwork(ByteSpan operationalDataset, MutableCharSpan & outDebugText, + uint8_t & outNetworkIndex) { uint8_t extpanid[kSizeExtendedPanId]; uint8_t newExtpanid[kSizeExtendedPanId]; Thread::OperationalDataset newDataset; + outDebugText.reduce_size(0); + outNetworkIndex = 0; + newDataset.Init(operationalDataset); VerifyOrReturnError(newDataset.IsCommissioned(), Status::kOutOfRange); @@ -91,8 +95,10 @@ Status GenericThreadDriver::AddOrUpdateNetwork(ByteSpan operationalDataset) return Status::kSuccess; } -Status GenericThreadDriver::RemoveNetwork(ByteSpan networkId) +Status GenericThreadDriver::RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex) { + outDebugText.reduce_size(0); + outNetworkIndex = 0; uint8_t extpanid[kSizeExtendedPanId]; if (!mStagingNetwork.IsCommissioned()) { @@ -109,8 +115,9 @@ Status GenericThreadDriver::RemoveNetwork(ByteSpan networkId) return Status::kSuccess; } -Status GenericThreadDriver::ReorderNetwork(ByteSpan networkId, uint8_t index) +Status GenericThreadDriver::ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCharSpan & outDebugText) { + outDebugText.reduce_size(0); uint8_t extpanid[kSizeExtendedPanId]; if (!mStagingNetwork.IsCommissioned()) { diff --git a/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.h b/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.h index ec801c997bda43..1fc1f1cb49eb30 100644 --- a/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.h +++ b/src/platform/OpenThread/GenericNetworkCommissioningThreadDriver.h @@ -95,12 +95,12 @@ class GenericThreadDriver final : public ThreadDriver CHIP_ERROR CommitConfiguration() override; CHIP_ERROR RevertConfiguration() override; - Status RemoveNetwork(ByteSpan networkId) override; - Status ReorderNetwork(ByteSpan networkId, uint8_t index) override; + Status RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex) override; + Status ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCharSpan & outDebugText) override; void ConnectNetwork(ByteSpan networkId, ConnectCallback * callback) override; // ThreadDriver - Status AddOrUpdateNetwork(ByteSpan operationalDataset) override; + Status AddOrUpdateNetwork(ByteSpan operationalDataset, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex) override; void ScanNetworks(ThreadDriver::ScanCallback * callback) override; private: diff --git a/src/platform/P6/NetworkCommissioningDriver.h b/src/platform/P6/NetworkCommissioningDriver.h index 54302bd2410aa8..15d46fcff48487 100644 --- a/src/platform/P6/NetworkCommissioningDriver.h +++ b/src/platform/P6/NetworkCommissioningDriver.h @@ -102,12 +102,13 @@ class P6WiFiDriver final : public WiFiDriver CHIP_ERROR CommitConfiguration() override; CHIP_ERROR RevertConfiguration() override; - Status RemoveNetwork(ByteSpan networkId) override; - Status ReorderNetwork(ByteSpan networkId, uint8_t index) override; + Status RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex) override; + Status ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCharSpan & outDebugText) override; void ConnectNetwork(ByteSpan networkId, ConnectCallback * callback) override; // WiFiDriver - Status AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials) override; + Status AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials, MutableCharSpan & outDebugText, + uint8_t & outNetworkIndex) override; void ScanNetworks(ByteSpan ssid, ScanCallback * callback) override; CHIP_ERROR ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen, const char * key, uint8_t keyLen); diff --git a/src/platform/P6/NetworkCommissioningWiFiDriver.cpp b/src/platform/P6/NetworkCommissioningWiFiDriver.cpp index c4b2a826ae4a27..c98442ca486926 100644 --- a/src/platform/P6/NetworkCommissioningWiFiDriver.cpp +++ b/src/platform/P6/NetworkCommissioningWiFiDriver.cpp @@ -91,8 +91,11 @@ bool P6WiFiDriver::NetworkMatch(const WiFiNetwork & network, ByteSpan networkId) return networkId.size() == network.ssidLen && memcmp(networkId.data(), network.ssid, network.ssidLen) == 0; } -Status P6WiFiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials) +Status P6WiFiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials, MutableCharSpan & outDebugText, + uint8_t & outNetworkIndex) { + outDebugText.reduce_size(0); + outNetworkIndex = 0; VerifyOrReturnError(mStagingNetwork.ssidLen == 0 || NetworkMatch(mStagingNetwork, ssid), Status::kBoundsExceeded); VerifyOrReturnError(credentials.size() <= sizeof(mStagingNetwork.credentials), Status::kOutOfRange); VerifyOrReturnError(ssid.size() <= sizeof(mStagingNetwork.ssid), Status::kOutOfRange); @@ -108,8 +111,10 @@ Status P6WiFiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials) return Status::kSuccess; } -Status P6WiFiDriver::RemoveNetwork(ByteSpan networkId) +Status P6WiFiDriver::RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex) { + outDebugText.reduce_size(0); + outNetworkIndex = 0; VerifyOrReturnError(NetworkMatch(mStagingNetwork, networkId), Status::kNetworkIDNotFound); // Use empty ssid for representing invalid network @@ -117,8 +122,9 @@ Status P6WiFiDriver::RemoveNetwork(ByteSpan networkId) return Status::kSuccess; } -Status P6WiFiDriver::ReorderNetwork(ByteSpan networkId, uint8_t index) +Status P6WiFiDriver::ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCharSpan & outDebugText) { + outDebugText.reduce_size(0); // Only one network is supported now VerifyOrReturnError(index == 0, Status::kOutOfRange); VerifyOrReturnError(NetworkMatch(mStagingNetwork, networkId), Status::kNetworkIDNotFound); diff --git a/src/platform/Tizen/NetworkCommissioningDriver.h b/src/platform/Tizen/NetworkCommissioningDriver.h index 5c00f8bc8028d1..3ad328955617d0 100644 --- a/src/platform/Tizen/NetworkCommissioningDriver.h +++ b/src/platform/Tizen/NetworkCommissioningDriver.h @@ -63,12 +63,13 @@ class TizenWiFiDriver final : public WiFiDriver CHIP_ERROR CommitConfiguration() override; CHIP_ERROR RevertConfiguration() override; - Status RemoveNetwork(ByteSpan networkId) override; - Status ReorderNetwork(ByteSpan networkId, uint8_t index) override; + Status RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex) override; + Status ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCharSpan & outDebugText) override; void ConnectNetwork(ByteSpan networkId, ConnectCallback * callback) override; // WiFiDriver - Status AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials) override; + Status AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials, MutableCharSpan & outDebugText, + uint8_t & outNetworkIndex) override; void ScanNetworks(ByteSpan ssid, ScanCallback * callback) override; private: diff --git a/src/platform/Tizen/NetworkCommissioningWiFiDriver.cpp b/src/platform/Tizen/NetworkCommissioningWiFiDriver.cpp index fa444f99bef2ee..584135266e378a 100644 --- a/src/platform/Tizen/NetworkCommissioningWiFiDriver.cpp +++ b/src/platform/Tizen/NetworkCommissioningWiFiDriver.cpp @@ -96,8 +96,11 @@ bool TizenWiFiDriver::NetworkMatch(const WiFiNetwork & network, ByteSpan network return true; } -Status TizenWiFiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials) +Status TizenWiFiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials, MutableCharSpan & outDebugText, + uint8_t & outNetworkIndex) { + outDebugText.reduce_size(0); + outNetworkIndex = 0; VerifyOrReturnError(mStagingNetwork.ssidLen == 0 || NetworkMatch(mStagingNetwork, ssid), Status::kBoundsExceeded); VerifyOrReturnError(credentials.size() <= sizeof(mStagingNetwork.credentials), Status::kOutOfRange); VerifyOrReturnError(ssid.size() <= sizeof(mStagingNetwork.ssid), Status::kOutOfRange); @@ -111,8 +114,10 @@ Status TizenWiFiDriver::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials) return Status::kSuccess; } -Status TizenWiFiDriver::RemoveNetwork(ByteSpan networkId) +Status TizenWiFiDriver::RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex) { + outDebugText.reduce_size(0); + outNetworkIndex = 0; VerifyOrReturnError(NetworkMatch(mStagingNetwork, networkId), Status::kNetworkIDNotFound); // Use empty ssid for representing invalid network @@ -120,8 +125,9 @@ Status TizenWiFiDriver::RemoveNetwork(ByteSpan networkId) return Status::kSuccess; } -Status TizenWiFiDriver::ReorderNetwork(ByteSpan networkId, uint8_t index) +Status TizenWiFiDriver::ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCharSpan & outDebugText) { + outDebugText.reduce_size(0); VerifyOrReturnError(NetworkMatch(mStagingNetwork, networkId), Status::kNetworkIDNotFound); // We only support one network, so reorder is actually no-op. diff --git a/src/platform/mbed/ConnectivityManagerImpl_WiFi.cpp b/src/platform/mbed/ConnectivityManagerImpl_WiFi.cpp index 38799727266686..6c9f7c5306086a 100644 --- a/src/platform/mbed/ConnectivityManagerImpl_WiFi.cpp +++ b/src/platform/mbed/ConnectivityManagerImpl_WiFi.cpp @@ -153,12 +153,15 @@ void ConnectivityManagerImpl::_ClearWiFiStationProvision(void) NetworkCommissioning::Network network; for (; networks != nullptr && networks->Next(network);) { + MutableCharSpan emptyBufferForDebugText; + uint8_t outNetworkIndex; if (network.connected) { NetworkCommissioning::WiFiDriverImpl::GetInstance().DisconnectNetwork( ByteSpan(network.networkID, network.networkIDLen)); } - NetworkCommissioning::WiFiDriverImpl::GetInstance().RemoveNetwork(ByteSpan(network.networkID, network.networkIDLen)); + NetworkCommissioning::WiFiDriverImpl::GetInstance().RemoveNetwork(ByteSpan(network.networkID, network.networkIDLen), + emptyBufferForDebugText, outNetworkIndex); } if (networks != nullptr) { diff --git a/src/platform/mbed/DeviceNetworkProvisioningDelegateImpl.cpp b/src/platform/mbed/DeviceNetworkProvisioningDelegateImpl.cpp index 282c9cd9ef8ec0..26eec34b4e5eb3 100644 --- a/src/platform/mbed/DeviceNetworkProvisioningDelegateImpl.cpp +++ b/src/platform/mbed/DeviceNetworkProvisioningDelegateImpl.cpp @@ -28,8 +28,11 @@ namespace DeviceLayer { CHIP_ERROR DeviceNetworkProvisioningDelegateImpl::_ProvisionWiFiNetwork(const char * ssid, const char * key) { #if CHIP_DEVICE_CONFIG_ENABLE_WIFI + MutableCharSpan emptyBufferForDebugText; + uint8_t outNetworkIndex; auto err = WiFiDriverImpl::GetInstance().AddOrUpdateNetwork(ByteSpan(Uint8::from_const_char(ssid), strlen(ssid)), - ByteSpan(Uint8::from_const_char(key), strlen(key))); + ByteSpan(Uint8::from_const_char(key), strlen(key)), + emptyBufferForDebugText, outNetworkIndex); if (err != Status::kSuccess) { ChipLogError(NetworkProvisioning, "Failed to add WiFi network: 0x%" PRIx16, int(err)); diff --git a/src/platform/mbed/NetworkCommissioningDriver.h b/src/platform/mbed/NetworkCommissioningDriver.h index c7424469460acc..c72b654954923e 100644 --- a/src/platform/mbed/NetworkCommissioningDriver.h +++ b/src/platform/mbed/NetworkCommissioningDriver.h @@ -104,13 +104,14 @@ class WiFiDriverImpl final : public WiFiDriver CHIP_ERROR CommitConfiguration() override; CHIP_ERROR RevertConfiguration() override; - Status RemoveNetwork(ByteSpan networkId) override; - Status ReorderNetwork(ByteSpan networkId, uint8_t index) override; + Status RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex) override; + Status ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCharSpan & outDebugText) override; void ConnectNetwork(ByteSpan networkId, ConnectCallback * callback) override; void DisconnectNetwork(ByteSpan networkId); // WiFiDriver - Status AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials) override; + Status AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials, MutableCharSpan & outDebugText, + uint8_t & outNetworkIndex) override; void ScanNetworks(ByteSpan ssid, ScanCallback * callback) override; static WiFiDriverImpl & GetInstance() diff --git a/src/platform/mbed/NetworkCommissioningWiFiDriver.cpp b/src/platform/mbed/NetworkCommissioningWiFiDriver.cpp index 50d3548bfa58e8..a598b866786e5b 100644 --- a/src/platform/mbed/NetworkCommissioningWiFiDriver.cpp +++ b/src/platform/mbed/NetworkCommissioningWiFiDriver.cpp @@ -137,8 +137,11 @@ bool WiFiDriverImpl::NetworkMatch(const WiFiNetwork & network, ByteSpan networkI return networkId.size() == network.ssidLen && memcmp(networkId.data(), network.ssid, network.ssidLen) == 0; } -Status WiFiDriverImpl::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials) +Status WiFiDriverImpl::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials, MutableCharSpan & outDebugText, + uint8_t & outNetworkIndex) { + outDebugText.reduce_size(0); + outNetworkIndex = 0; VerifyOrReturnError(mStagingNetwork.ssidLen == 0 || NetworkMatch(mStagingNetwork, ssid), Status::kBoundsExceeded); VerifyOrReturnError(credentials.size() <= sizeof(mStagingNetwork.credentials), Status::kOutOfRange); VerifyOrReturnError(ssid.size() <= sizeof(mStagingNetwork.ssid), Status::kOutOfRange); @@ -152,8 +155,10 @@ Status WiFiDriverImpl::AddOrUpdateNetwork(ByteSpan ssid, ByteSpan credentials) return Status::kSuccess; } -Status WiFiDriverImpl::RemoveNetwork(ByteSpan networkId) +Status WiFiDriverImpl::RemoveNetwork(ByteSpan networkId, MutableCharSpan & outDebugText, uint8_t & outNetworkIndex) { + outDebugText.reduce_size(0); + outNetworkIndex = 0; VerifyOrReturnError(NetworkMatch(mStagingNetwork, networkId), Status::kNetworkIDNotFound); // Use empty ssid for representing invalid network @@ -161,8 +166,9 @@ Status WiFiDriverImpl::RemoveNetwork(ByteSpan networkId) return Status::kSuccess; } -Status WiFiDriverImpl::ReorderNetwork(ByteSpan networkId, uint8_t index) +Status WiFiDriverImpl::ReorderNetwork(ByteSpan networkId, uint8_t index, MutableCharSpan & outDebugText) { + outDebugText.reduce_size(0); // Only one network is supported now VerifyOrReturnError(index == 0, Status::kOutOfRange); VerifyOrReturnError(NetworkMatch(mStagingNetwork, networkId), Status::kNetworkIDNotFound); diff --git a/zzz_generated/app-common/app-common/zap-generated/callback.h b/zzz_generated/app-common/app-common/zap-generated/callback.h index 958462e24aea5b..c5312c57e82cbb 100644 --- a/zzz_generated/app-common/app-common/zap-generated/callback.h +++ b/zzz_generated/app-common/app-common/zap-generated/callback.h @@ -13948,7 +13948,8 @@ bool emberAfNetworkCommissioningClusterRemoveNetworkCallback( */ bool emberAfNetworkCommissioningClusterNetworkConfigResponseCallback(chip::EndpointId endpoint, chip::app::CommandSender * commandObj, - uint8_t NetworkingStatus, chip::CharSpan DebugText); + uint8_t NetworkingStatus, chip::CharSpan DebugText, + uint8_t NetworkIndex); /** * @brief Network Commissioning Cluster ConnectNetwork Command callback (from client) */ diff --git a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp index 9bb9e4aa96ba8f..14665698d0936c 100644 --- a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp +++ b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.cpp @@ -7760,6 +7760,7 @@ CHIP_ERROR Type::Encode(TLV::TLVWriter & writer, TLV::Tag tag) const ReturnErrorOnFailure(writer.StartContainer(tag, TLV::kTLVType_Structure, outer)); ReturnErrorOnFailure(DataModel::Encode(writer, TLV::ContextTag(to_underlying(Fields::kNetworkingStatus)), networkingStatus)); ReturnErrorOnFailure(DataModel::Encode(writer, TLV::ContextTag(to_underlying(Fields::kDebugText)), debugText)); + ReturnErrorOnFailure(DataModel::Encode(writer, TLV::ContextTag(to_underlying(Fields::kNetworkIndex)), networkIndex)); ReturnErrorOnFailure(writer.EndContainer(outer)); return CHIP_NO_ERROR; } @@ -7781,6 +7782,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) case to_underlying(Fields::kDebugText): ReturnErrorOnFailure(DataModel::Decode(reader, debugText)); break; + case to_underlying(Fields::kNetworkIndex): + ReturnErrorOnFailure(DataModel::Decode(reader, networkIndex)); + break; default: break; } diff --git a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h index eb14da02073d8b..1b5ca3ff2203e4 100644 --- a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h +++ b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h @@ -11002,6 +11002,7 @@ enum class Fields { kNetworkingStatus = 0, kDebugText = 1, + kNetworkIndex = 2, }; struct Type @@ -11012,7 +11013,8 @@ struct Type static constexpr ClusterId GetClusterId() { return Clusters::NetworkCommissioning::Id; } NetworkCommissioningStatus networkingStatus = static_cast(0); - chip::CharSpan debugText; + Optional debugText; + Optional networkIndex; CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const; @@ -11028,7 +11030,8 @@ struct DecodableType static constexpr ClusterId GetClusterId() { return Clusters::NetworkCommissioning::Id; } NetworkCommissioningStatus networkingStatus = static_cast(0); - chip::CharSpan debugText; + Optional debugText; + Optional networkIndex; CHIP_ERROR Decode(TLV::TLVReader & reader); }; }; // namespace NetworkConfigResponse diff --git a/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp b/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp index 9d9eac50d44b31..55d1f482dec63f 100644 --- a/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp +++ b/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp @@ -3897,6 +3897,7 @@ CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, DataModelLogger::LogString(label, indent, "{"); ReturnErrorOnFailure(DataModelLogger::LogValue("networkingStatus", indent + 1, value.networkingStatus)); ReturnErrorOnFailure(DataModelLogger::LogValue("debugText", indent + 1, value.debugText)); + ReturnErrorOnFailure(DataModelLogger::LogValue("networkIndex", indent + 1, value.networkIndex)); DataModelLogger::LogString(indent, "}"); return CHIP_NO_ERROR; }