From 8f436715cf9ad3bf07dd3c4a40b19114f2d97554 Mon Sep 17 00:00:00 2001 From: Sharad Binjola <31142146+sharadb-amazon@users.noreply.github.com> Date: Fri, 25 Aug 2023 14:55:22 -0700 Subject: [PATCH 1/8] Android tv-casting-app: refactored Initialization (#28875) * Android tv-casting-app: refactored Initialization --- .../com/chip/casting/app/MainActivity.java | 9 +- .../casting/util/GlobalCastingConstants.java | 2 + .../com/matter/casting/DACProviderStub.java | 99 +++++++++++ .../matter/casting/InitializationExample.java | 102 +++++++++++ .../com/matter/casting/core/CastingApp.java | 163 ++++++++++++++++++ .../matter/casting/core/CastingAppState.java | 8 + .../matter/casting/support/AppParameters.java | 81 +++++++++ .../casting/support/CommissionableData.java | 71 ++++++++ .../matter/casting/support/DACProvider.java | 39 +++++ .../matter/casting/support/DataProvider.java | 36 ++++ .../matter/casting/support/MatterError.java | 76 ++++++++ .../src/main/jni/cpp/core/CastingApp-JNI.cpp | 132 ++++++++++++++ .../src/main/jni/cpp/core/CastingApp-JNI.h | 41 +++++ .../jni/cpp/support/ErrorConverter-JNI.cpp | 43 +++++ .../main/jni/cpp/support/ErrorConverter-JNI.h | 31 ++++ .../RotatingDeviceIdUniqueIdProvider-JNI.cpp | 94 ++++++++++ .../RotatingDeviceIdUniqueIdProvider-JNI.h | 44 +++++ examples/tv-casting-app/android/BUILD.gn | 21 +++ .../tv-casting-common/core/CastingApp.cpp | 2 +- .../tv-casting-common/core/CastingApp.h | 16 +- .../tv-casting-common/core/Types.h | 4 +- 21 files changed, 1100 insertions(+), 14 deletions(-) create mode 100644 examples/tv-casting-app/android/App/app/src/main/java/com/matter/casting/DACProviderStub.java create mode 100644 examples/tv-casting-app/android/App/app/src/main/java/com/matter/casting/InitializationExample.java create mode 100644 examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/core/CastingApp.java create mode 100644 examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/core/CastingAppState.java create mode 100644 examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/support/AppParameters.java create mode 100644 examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/support/CommissionableData.java create mode 100644 examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/support/DACProvider.java create mode 100644 examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/support/DataProvider.java create mode 100644 examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/support/MatterError.java create mode 100644 examples/tv-casting-app/android/App/app/src/main/jni/cpp/core/CastingApp-JNI.cpp create mode 100644 examples/tv-casting-app/android/App/app/src/main/jni/cpp/core/CastingApp-JNI.h create mode 100644 examples/tv-casting-app/android/App/app/src/main/jni/cpp/support/ErrorConverter-JNI.cpp create mode 100644 examples/tv-casting-app/android/App/app/src/main/jni/cpp/support/ErrorConverter-JNI.h create mode 100644 examples/tv-casting-app/android/App/app/src/main/jni/cpp/support/RotatingDeviceIdUniqueIdProvider-JNI.cpp create mode 100644 examples/tv-casting-app/android/App/app/src/main/jni/cpp/support/RotatingDeviceIdUniqueIdProvider-JNI.h diff --git a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/MainActivity.java b/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/MainActivity.java index 864f993544c760..de1b547f929dd5 100644 --- a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/MainActivity.java +++ b/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/MainActivity.java @@ -8,9 +8,9 @@ import com.chip.casting.AppParameters; import com.chip.casting.DiscoveredNodeData; import com.chip.casting.TvCastingApp; -import com.chip.casting.util.DACProviderStub; import com.chip.casting.util.GlobalCastingConstants; import com.chip.casting.util.PreferencesConfigurationManager; +import com.matter.casting.InitializationExample; import java.util.Random; public class MainActivity extends AppCompatActivity @@ -27,7 +27,10 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - boolean ret = initJni(); + boolean ret = + GlobalCastingConstants.ChipCastingSimplified + ? InitializationExample.initAndStart(this.getApplicationContext()).hasNoError() + : initJni(); if (!ret) { Log.e(TAG, "Failed to initialize Matter TV casting library"); return; @@ -78,7 +81,7 @@ public void handleDisconnect() { private boolean initJni() { tvCastingApp = TvCastingApp.getInstance(); - tvCastingApp.setDACProvider(new DACProviderStub()); + tvCastingApp.setDACProvider(new com.chip.casting.util.DACProviderStub()); AppParameters appParameters = new AppParameters(); appParameters.setConfigurationManager( diff --git a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/util/GlobalCastingConstants.java b/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/util/GlobalCastingConstants.java index 4bd6d25a08364c..d063cc7e6f78c5 100644 --- a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/util/GlobalCastingConstants.java +++ b/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/util/GlobalCastingConstants.java @@ -5,4 +5,6 @@ public class GlobalCastingConstants { public static final int CommissioningWindowDurationSecs = 3 * 60; public static final int SetupPasscode = 20202021; public static final int Discriminator = 0xF00; + public static final boolean ChipCastingSimplified = + false; // set this flag to true to demo simplified casting APIs } diff --git a/examples/tv-casting-app/android/App/app/src/main/java/com/matter/casting/DACProviderStub.java b/examples/tv-casting-app/android/App/app/src/main/java/com/matter/casting/DACProviderStub.java new file mode 100644 index 00000000000000..37bc17dd59ca6f --- /dev/null +++ b/examples/tv-casting-app/android/App/app/src/main/java/com/matter/casting/DACProviderStub.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * 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. + */ +package com.matter.casting; + +import android.util.Base64; +import com.matter.casting.support.DACProvider; +import java.math.BigInteger; +import java.security.AlgorithmParameters; +import java.security.KeyFactory; +import java.security.PrivateKey; +import java.security.Signature; +import java.security.spec.ECGenParameterSpec; +import java.security.spec.ECParameterSpec; +import java.security.spec.ECPrivateKeySpec; + +public class DACProviderStub implements DACProvider { + + private String kDevelopmentDAC_Cert_FFF1_8001 = + "MIIB5zCCAY6gAwIBAgIIac3xDenlTtEwCgYIKoZIzj0EAwIwPTElMCMGA1UEAwwcTWF0dGVyIERldiBQQUkgMHhGRkYxIG5vIFBJRDEUMBIGCisGAQQBgqJ8AgEMBEZGRjEwIBcNMjIwMjA1MDAwMDAwWhgPOTk5OTEyMzEyMzU5NTlaMFMxJTAjBgNVBAMMHE1hdHRlciBEZXYgREFDIDB4RkZGMS8weDgwMDExFDASBgorBgEEAYKifAIBDARGRkYxMRQwEgYKKwYBBAGConwCAgwEODAwMTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABEY6xpNCkQoOVYj8b/Vrtj5i7M7LFI99TrA+5VJgFBV2fRalxmP3k+SRIyYLgpenzX58/HsxaznZjpDSk3dzjoKjYDBeMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgeAMB0GA1UdDgQWBBSI3eezADgpMs/3NMBGJIEPRBaKbzAfBgNVHSMEGDAWgBRjVA5H9kscONE4hKRi0WwZXY/7PDAKBggqhkjOPQQDAgNHADBEAiABJ6J7S0RhDuL83E0reIVWNmC8D3bxchntagjfsrPBzQIga1ngr0Xz6yqFuRnTVzFSjGAoxBUjlUXhCOTlTnCXE1M="; + + private String kDevelopmentDAC_PrivateKey_FFF1_8001 = + "qrYAroroqrfXNifCF7fCBHCcppRq9fL3UwgzpStE+/8="; + + private String kDevelopmentDAC_PublicKey_FFF1_8001 = + "BEY6xpNCkQoOVYj8b/Vrtj5i7M7LFI99TrA+5VJgFBV2fRalxmP3k+SRIyYLgpenzX58/HsxaznZjpDSk3dzjoI="; + + private String KPAI_FFF1_8000_Cert_Array = + "MIIByzCCAXGgAwIBAgIIVq2CIq2UW2QwCgYIKoZIzj0EAwIwMDEYMBYGA1UEAwwPTWF0dGVyIFRlc3QgUEFBMRQwEgYKKwYBBAGConwCAQwERkZGMTAgFw0yMjAyMDUwMDAwMDBaGA85OTk5MTIzMTIzNTk1OVowPTElMCMGA1UEAwwcTWF0dGVyIERldiBQQUkgMHhGRkYxIG5vIFBJRDEUMBIGCisGAQQBgqJ8AgEMBEZGRjEwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAARBmpMVwhc+DIyHbQPM/JRIUmR/f+xeUIL0BZko7KiUxZQVEwmsYx5MsDOSr2hLC6+35ls7gWLC9Sv5MbjneqqCo2YwZDASBgNVHRMBAf8ECDAGAQH/AgEAMA4GA1UdDwEB/wQEAwIBBjAdBgNVHQ4EFgQUY1QOR/ZLHDjROISkYtFsGV2P+zwwHwYDVR0jBBgwFoAUav0idx9RH+y/FkGXZxDc3DGhcX4wCgYIKoZIzj0EAwIDSAAwRQIhALLvJ/Sa6bUPuR7qyUxNC9u415KcbLiPrOUpNo0SBUwMAiBlXckrhr2QmIKmxiF3uCXX0F7b58Ivn+pxIg5+pwP4kQ=="; + + /** + * format_version = 1 vendor_id = 0xFFF1 product_id_array = [ 0x8000,0x8001...0x8063] + * device_type_id = 0x1234 certificate_id = "ZIG20141ZB330001-24" security_level = 0 + * security_information = 0 version_number = 0x2694 certification_type = 0 dac_origin_vendor_id is + * not present dac_origin_product_id is not present + */ + private String kCertificationDeclaration = + "MIICGQYJKoZIhvcNAQcCoIICCjCCAgYCAQMxDTALBglghkgBZQMEAgEwggFxBgkqhkiG9w0BBwGgggFiBIIBXhUkAAElAfH/NgIFAIAFAYAFAoAFA4AFBIAFBYAFBoAFB4AFCIAFCYAFCoAFC4AFDIAFDYAFDoAFD4AFEIAFEYAFEoAFE4AFFIAFFYAFFoAFF4AFGIAFGYAFGoAFG4AFHIAFHYAFHoAFH4AFIIAFIYAFIoAFI4AFJIAFJYAFJoAFJ4AFKIAFKYAFKoAFK4AFLIAFLYAFLoAFL4AFMIAFMYAFMoAFM4AFNIAFNYAFNoAFN4AFOIAFOYAFOoAFO4AFPIAFPYAFPoAFP4AFQIAFQYAFQoAFQ4AFRIAFRYAFRoAFR4AFSIAFSYAFSoAFS4AFTIAFTYAFToAFT4AFUIAFUYAFUoAFU4AFVIAFVYAFVoAFV4AFWIAFWYAFWoAFW4AFXIAFXYAFXoAFX4AFYIAFYYAFYoAFY4AYJAMWLAQTWklHMjAxNDJaQjMzMDAwMy0yNCQFACQGACUHlCYkCAAYMX0wewIBA4AUYvqCM1ms+qmWPhz6FArd9QTzcWAwCwYJYIZIAWUDBAIBMAoGCCqGSM49BAMCBEcwRQIgJOXR9Hp9ew0gaibvaZt8l1e3LUaQid4xkuZ4x0Xn9gwCIQD4qi+nEfy3m5fjl87aZnuuRk4r0//fw8zteqjKX0wafA=="; + + @Override + public byte[] GetCertificationDeclaration() { + return Base64.decode(kCertificationDeclaration, Base64.DEFAULT); + } + + @Override + public byte[] GetFirmwareInformation() { + return new byte[0]; + } + + @Override + public byte[] GetDeviceAttestationCert() { + return Base64.decode(kDevelopmentDAC_Cert_FFF1_8001, Base64.DEFAULT); + } + + @Override + public byte[] GetProductAttestationIntermediateCert() { + return Base64.decode(KPAI_FFF1_8000_Cert_Array, Base64.DEFAULT); + } + + @Override + public byte[] SignWithDeviceAttestationKey(byte[] message) { + + try { + byte[] privateKeyBytes = Base64.decode(kDevelopmentDAC_PrivateKey_FFF1_8001, Base64.DEFAULT); + + AlgorithmParameters algorithmParameters = AlgorithmParameters.getInstance("EC"); + algorithmParameters.init(new ECGenParameterSpec("secp256r1")); + ECParameterSpec parameterSpec = algorithmParameters.getParameterSpec(ECParameterSpec.class); + ECPrivateKeySpec ecPrivateKeySpec = + new ECPrivateKeySpec(new BigInteger(1, privateKeyBytes), parameterSpec); + + KeyFactory keyFactory = KeyFactory.getInstance("EC"); + PrivateKey privateKey = keyFactory.generatePrivate(ecPrivateKeySpec); + + Signature signature = Signature.getInstance("SHA256withECDSA"); + signature.initSign(privateKey); + + signature.update(message); + + return signature.sign(); + + } catch (Exception e) { + return null; + } + } +} diff --git a/examples/tv-casting-app/android/App/app/src/main/java/com/matter/casting/InitializationExample.java b/examples/tv-casting-app/android/App/app/src/main/java/com/matter/casting/InitializationExample.java new file mode 100644 index 00000000000000..0d2135e1a7bc66 --- /dev/null +++ b/examples/tv-casting-app/android/App/app/src/main/java/com/matter/casting/InitializationExample.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * 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. + */ +package com.matter.casting; + +import android.content.Context; +import android.util.Log; +import chip.platform.ConfigurationManager; +import com.chip.casting.util.PreferencesConfigurationManager; +import com.matter.casting.core.CastingApp; +import com.matter.casting.support.AppParameters; +import com.matter.casting.support.CommissionableData; +import com.matter.casting.support.DACProvider; +import com.matter.casting.support.DataProvider; +import com.matter.casting.support.MatterError; + +public class InitializationExample { + private static final String TAG = InitializationExample.class.getSimpleName(); + + /** + * DataProvider implementation for the Unique ID that is used by the SDK to generate the Rotating + * Device ID + */ + private static final DataProvider rotatingDeviceIdUniqueIdProvider = + new DataProvider() { + private static final String ROTATING_DEVICE_ID_UNIQUE_ID = + "EXAMPLE_ID"; // dummy value for demonstration only + + @Override + public byte[] get() { + return ROTATING_DEVICE_ID_UNIQUE_ID.getBytes(); + } + }; + + /** + * DataProvider implementation for the Commissioning Data used by the SDK when the CastingApp goes + * through commissioning + */ + private static final DataProvider commissionableDataProvider = + new DataProvider() { + @Override + public CommissionableData get() { + // dummy values for demonstration only + return new CommissionableData(20202021, 3874); + } + }; + + /** + * DACProvider implementation for the Device Attestation Credentials required at the time of + * commissioning + * + *

Using the DACProviderStub which provides dummy values for demonstration only + */ + private static final DACProvider dacProvider = new DACProviderStub(); + + /** + * @param applicationContext Given android.content.Context, initialize and start the CastingApp + */ + public static MatterError initAndStart(Context applicationContext) { + // Create an AppParameters object to pass in global casting parameters to the SDK + final AppParameters appParameters = + new AppParameters( + applicationContext, + new DataProvider() { + @Override + public ConfigurationManager get() { + return new PreferencesConfigurationManager( + applicationContext, "chip.platform.ConfigurationManager"); + } + }, + rotatingDeviceIdUniqueIdProvider, + commissionableDataProvider, + dacProvider); + + // Initialize the SDK using the appParameters and check if it returns successfully + MatterError err = CastingApp.getInstance().initialize(appParameters); + if (err.hasError()) { + Log.e(TAG, "Failed to initialize Matter CastingApp"); + return err; + } + + err = CastingApp.getInstance().start(); + if (err.hasError()) { + Log.e(TAG, "Failed to start Matter CastingApp"); + return err; + } + return err; + } +} diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/core/CastingApp.java b/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/core/CastingApp.java new file mode 100644 index 00000000000000..0823920503d9db --- /dev/null +++ b/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/core/CastingApp.java @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * 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. + */ + +package com.matter.casting.core; + +import android.content.Context; +import android.util.Log; +import chip.appserver.ChipAppServer; +import chip.platform.AndroidBleManager; +import chip.platform.AndroidChipPlatform; +import chip.platform.ChipMdnsCallbackImpl; +import chip.platform.DiagnosticDataProviderImpl; +import chip.platform.NsdManagerServiceBrowser; +import chip.platform.NsdManagerServiceResolver; +import chip.platform.PreferencesKeyValueStoreManager; +import com.matter.casting.support.AppParameters; +import com.matter.casting.support.CommissionableData; +import com.matter.casting.support.MatterError; + +/** + * CastingApp represents an app that can cast content to a Casting Player. This class is a + * singleton. + */ +public final class CastingApp { + private static final String TAG = CastingApp.class.getSimpleName(); + + private static CastingApp sInstance; + + private CastingAppState mState = CastingAppState.UNINITIALIZED; + private AppParameters appParameters; + private NsdManagerServiceResolver.NsdManagerResolverAvailState nsdManagerResolverAvailState; + private ChipAppServer chipAppServer; + + private CastingApp() {} + + public static CastingApp getInstance() { + if (sInstance == null) { + sInstance = new CastingApp(); + } + return sInstance; + } + + /** + * Initializes the CastingApp with appParameters + * + * @param appParameters + */ + public MatterError initialize(AppParameters appParameters) { + Log.i(TAG, "CastingApp.initialize called"); + if (mState != CastingAppState.UNINITIALIZED) { + return MatterError.CHIP_ERROR_INCORRECT_STATE; + } + + this.appParameters = appParameters; + this.nsdManagerResolverAvailState = + new NsdManagerServiceResolver.NsdManagerResolverAvailState(); + + Context applicationContext = appParameters.getApplicationContext(); + AndroidChipPlatform chipPlatform = + new AndroidChipPlatform( + new AndroidBleManager(), + new PreferencesKeyValueStoreManager(appParameters.getApplicationContext()), + appParameters.getConfigurationManagerProvider().get(), + new NsdManagerServiceResolver(applicationContext, nsdManagerResolverAvailState), + new NsdManagerServiceBrowser(applicationContext), + new ChipMdnsCallbackImpl(), + new DiagnosticDataProviderImpl(applicationContext)); + + CommissionableData commissionableData = appParameters.getCommissionableDataProvider().get(); + boolean updated = + chipPlatform.updateCommissionableDataProviderData( + commissionableData.getSpake2pVerifierBase64(), + commissionableData.getSpake2pSaltBase64(), + commissionableData.getSpake2pIterationCount(), + commissionableData.getSetupPasscode(), + commissionableData.getDiscriminator()); + if (!updated) { + Log.e( + TAG, "CastingApp.initApp failed to updateCommissionableDataProviderData on chipPlatform"); + return MatterError.CHIP_ERROR_INVALID_ARGUMENT; + } + + MatterError err = finishInitialization(appParameters); + + if (err.hasNoError()) { + chipAppServer = new ChipAppServer(); // get a reference to the Matter server now + mState = CastingAppState.NOT_RUNNING; // initialization done, set state to NOT_RUNNING + } + return err; + } + + /** + * Starts the Matter server that the CastingApp runs on and registers all the necessary delegates + */ + public MatterError start() { + Log.i(TAG, "CastingApp.start called"); + if (mState != CastingAppState.NOT_RUNNING) { + return MatterError.CHIP_ERROR_INCORRECT_STATE; + } + + boolean serverStarted = chipAppServer.startApp(); + if (!serverStarted) { + Log.e(TAG, "CastingApp.start failed to start Matter server"); + return MatterError.CHIP_ERROR_INCORRECT_STATE; + } + + MatterError err = finishStartup(); + if (err.hasNoError()) { + mState = CastingAppState.RUNNING; // CastingApp started successfully, set state to RUNNING + } + return err; + } + + /** + * Stops the Matter server that the CastingApp runs on + * + * @return + */ + public MatterError stop() { + Log.i(TAG, "CastingApp.stop called"); + if (mState != CastingAppState.RUNNING) { + return MatterError.CHIP_ERROR_INCORRECT_STATE; + } + + boolean serverStopped = chipAppServer.stopApp(); + if (!serverStopped) { + Log.e(TAG, "CastingApp.stop failed to stop Matter server"); + return MatterError.CHIP_ERROR_INCORRECT_STATE; + } + mState = + CastingAppState.NOT_RUNNING; // CastingApp stopped successfully, set state to NOT_RUNNING + + return MatterError.NO_ERROR; + } + + /** + * Sets DeviceAttestationCrdentials provider and RotatingDeviceIdUniqueId + * + * @param appParameters + */ + private native MatterError finishInitialization(AppParameters appParameters); + + /** Performs post Matter server startup registrations */ + private native MatterError finishStartup(); + + static { + System.loadLibrary("TvCastingApp"); + } +} diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/core/CastingAppState.java b/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/core/CastingAppState.java new file mode 100644 index 00000000000000..89ddef7aa0dbf6 --- /dev/null +++ b/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/core/CastingAppState.java @@ -0,0 +1,8 @@ +package com.matter.casting.core; + +/** Represents the state of the CastingApp */ +enum CastingAppState { + UNINITIALIZED, // Before Initialize() success + NOT_RUNNING, // After Initialize() success before Start()ing, OR After stop() success + RUNNING, // After Start() success +} diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/support/AppParameters.java b/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/support/AppParameters.java new file mode 100644 index 00000000000000..0734271ca89b88 --- /dev/null +++ b/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/support/AppParameters.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * 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. + */ + +package com.matter.casting.support; + +import android.content.Context; +import androidx.annotation.NonNull; +import chip.platform.ConfigurationManager; + +public class AppParameters { + @NonNull private final Context applicationContext; + + @NonNull private final DataProvider configurationManagerProvider; + + @NonNull private final DataProvider rotatingDeviceIdUniqueIdProvider; + + @NonNull private final DataProvider commissionableDataProvider; + + @NonNull private final DACProvider dacProvider; + + /** + * @param applicationContext the Android app's android.content.Context + * @param configurationManagerProvider Implementation of chip.platform.ConfigurationManager + * @param rotatingDeviceIdUniqueIdProvider Provides values of the uniqueID used to generate the + * RotatingDeviceId of the CastingApp + * @param commissionableDataProvider Provides CommissionableData (such as setupPasscode, + * discriminator, etc) used to get the CastingApp commissioned + * @param dacProvider Provides DeviceAttestationCredentials of the CastingApp during commissioning + */ + public AppParameters( + @NonNull Context applicationContext, + @NonNull DataProvider configurationManagerProvider, + @NonNull DataProvider rotatingDeviceIdUniqueIdProvider, + @NonNull DataProvider commissionableDataProvider, + @NonNull DACProvider dacProvider) { + this.applicationContext = applicationContext; + this.configurationManagerProvider = configurationManagerProvider; + this.rotatingDeviceIdUniqueIdProvider = rotatingDeviceIdUniqueIdProvider; + this.commissionableDataProvider = commissionableDataProvider; + this.dacProvider = dacProvider; + } + + @NonNull + public Context getApplicationContext() { + return applicationContext; + } + + @NonNull + public DataProvider getConfigurationManagerProvider() { + return configurationManagerProvider; + } + + @NonNull + public DataProvider getRotatingDeviceIdUniqueIdProvider() { + return rotatingDeviceIdUniqueIdProvider; + } + + @NonNull + public DataProvider getCommissionableDataProvider() { + return commissionableDataProvider; + } + + @NonNull + public DACProvider getDacProvider() { + return dacProvider; + } +} diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/support/CommissionableData.java b/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/support/CommissionableData.java new file mode 100644 index 00000000000000..b436c98c533786 --- /dev/null +++ b/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/support/CommissionableData.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * 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. + */ + +package com.matter.casting.support; + +import androidx.annotation.Nullable; + +public class CommissionableData { + private long setupPasscode; + + private int discriminator; + + @Nullable private String spake2pVerifierBase64; + + @Nullable private String spake2pSaltBase64; + + private int spake2pIterationCount; + + public CommissionableData(long setupPasscode, int discriminator) { + this.setupPasscode = setupPasscode; + this.discriminator = discriminator; + } + + public long getSetupPasscode() { + return setupPasscode; + } + + public int getDiscriminator() { + return discriminator; + } + + @Nullable + public String getSpake2pVerifierBase64() { + return spake2pVerifierBase64; + } + + public void setSpake2pVerifierBase64(@Nullable String spake2pVerifierBase64) { + this.spake2pVerifierBase64 = spake2pVerifierBase64; + } + + @Nullable + public String getSpake2pSaltBase64() { + return spake2pSaltBase64; + } + + public void setSpake2pSaltBase64(@Nullable String spake2pSaltBase64) { + this.spake2pSaltBase64 = spake2pSaltBase64; + } + + public int getSpake2pIterationCount() { + return spake2pIterationCount; + } + + public void setSpake2pIterationCount(int spake2pIterationCount) { + this.spake2pIterationCount = spake2pIterationCount; + } +} diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/support/DACProvider.java b/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/support/DACProvider.java new file mode 100644 index 00000000000000..3fdca947e3b035 --- /dev/null +++ b/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/support/DACProvider.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * 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. + * + */ +package com.matter.casting.support; + +public interface DACProvider { + byte[] GetCertificationDeclaration(); + + byte[] GetFirmwareInformation(); + + byte[] GetDeviceAttestationCert(); + + byte[] GetProductAttestationIntermediateCert(); + + /** + * Sign a mesage with the device attestation key. + * + *

The signature should be a SHA256withECDSA Signature that's returned in the ECDSA X9.62 Asn1 + * format. This is the default behavior when using java.security.Signature with an EC P-256 curve. + * + * @param message The message to sign + * @return The signature in ECDSA X9.62 Asn1 format. + */ + byte[] SignWithDeviceAttestationKey(byte[] message); +} diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/support/DataProvider.java b/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/support/DataProvider.java new file mode 100644 index 00000000000000..eb701413bcd477 --- /dev/null +++ b/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/support/DataProvider.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * 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. + */ + +package com.matter.casting.support; + +import android.util.Log; + +public abstract class DataProvider { + private static final String TAG = DataProvider.class.getSimpleName(); + + protected T _get() { + T val = null; + try { + val = get(); + } catch (Throwable t) { + Log.e(TAG, "DataProvider::Caught an unhandled Throwable from the client: " + t); + } + return val; + } + + public abstract T get(); +} diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/support/MatterError.java b/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/support/MatterError.java new file mode 100644 index 00000000000000..c570cf60e7f70c --- /dev/null +++ b/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/support/MatterError.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * 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. + */ + +package com.matter.casting.support; + +import java.util.Objects; + +public class MatterError { + private long errorCode; + private String errorMessage; + + public static final MatterError NO_ERROR = new MatterError(0, null); + + public static final MatterError CHIP_ERROR_INVALID_ARGUMENT = + new MatterError(0x2f, "CHIP_ERROR_INVALID_ARGUMENT"); + + public static final MatterError CHIP_ERROR_INCORRECT_STATE = + new MatterError(0x03, "CHIP_ERROR_INCORRECT_STATE"); + + public MatterError(long errorCode, String errorMessage) { + this.errorCode = errorCode; + this.errorMessage = errorMessage; + } + + public boolean hasError() { + return !this.equals(NO_ERROR); + } + + public boolean hasNoError() { + return this.equals(NO_ERROR); + } + + public long getErrorCode() { + return errorCode; + } + + public String getErrorMessage() { + return errorMessage; + } + + @Override + public String toString() { + return "MatterError{" + + (hasNoError() + ? "No error" + : "errorCode=" + errorCode + ", errorMessage='" + errorMessage + '\'') + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + MatterError matterError = (MatterError) o; + return errorCode == matterError.getErrorCode(); + } + + @Override + public int hashCode() { + return Objects.hash(errorCode); + } +} diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/core/CastingApp-JNI.cpp b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/core/CastingApp-JNI.cpp new file mode 100644 index 00000000000000..984287af8c30fd --- /dev/null +++ b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/core/CastingApp-JNI.cpp @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * 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. + * + */ + +#include "CastingApp-JNI.h" + +#include "../JNIDACProvider.h" +#include "../support/ErrorConverter-JNI.h" +#include "../support/RotatingDeviceIdUniqueIdProvider-JNI.h" +#include "core/CastingApp.h" // from tv-casting-common + +#include +#include +#include +#include +#include + +using namespace chip; + +#define JNI_METHOD(RETURN, METHOD_NAME) extern "C" JNIEXPORT RETURN JNICALL Java_com_matter_casting_core_CastingApp_##METHOD_NAME + +namespace matter { +namespace casting { +namespace core { + +CastingAppJNI CastingAppJNI::sInstance; + +jobject extractJAppParameter(jobject jAppParameters, const char * methodName, const char * methodSig); + +JNI_METHOD(jobject, finishInitialization)(JNIEnv *, jobject, jobject jAppParameters) +{ + chip::DeviceLayer::StackLock lock; + ChipLogProgress(AppServer, "JNI_METHOD CastingAppJNI.finishInitialization called"); + VerifyOrReturnValue(jAppParameters != nullptr, support::createJMatterError(CHIP_ERROR_INVALID_ARGUMENT)); + CHIP_ERROR err = CHIP_NO_ERROR; + + jobject jUniqueIdProvider = + extractJAppParameter(jAppParameters, "getRotatingDeviceIdUniqueIdProvider", "()Lcom/matter/casting/support/DataProvider;"); + VerifyOrReturnValue(jUniqueIdProvider != nullptr, support::createJMatterError(CHIP_ERROR_INCORRECT_STATE)); + support::RotatingDeviceIdUniqueIdProviderJNI * uniqueIdProvider = new support::RotatingDeviceIdUniqueIdProviderJNI(); + err = uniqueIdProvider->Initialize(jUniqueIdProvider); + VerifyOrReturnValue(err == CHIP_NO_ERROR, support::createJMatterError(CHIP_ERROR_INVALID_ARGUMENT)); + + // set the RotatingDeviceIdUniqueId +#if CHIP_ENABLE_ROTATING_DEVICE_ID + chip::MutableByteSpan * uniqueId = uniqueIdProvider->Get(); + if (uniqueId != nullptr) + { + chip::DeviceLayer::ConfigurationMgr().SetRotatingDeviceIdUniqueId(*uniqueId); + } +#endif // CHIP_ENABLE_ROTATING_DEVICE_ID + + // get the DACProvider + jobject jDACProvider = extractJAppParameter(jAppParameters, "getDacProvider", "()Lcom/matter/casting/support/DACProvider;"); + VerifyOrReturnValue(jDACProvider != nullptr, support::createJMatterError(CHIP_ERROR_INCORRECT_STATE)); + + // set the DACProvider + JNIDACProvider * dacProvider = new JNIDACProvider(jDACProvider); + chip::Credentials::SetDeviceAttestationCredentialsProvider(dacProvider); + + return support::createJMatterError(CHIP_NO_ERROR); +} + +JNI_METHOD(jobject, finishStartup)(JNIEnv *, jobject) +{ + chip::DeviceLayer::StackLock lock; + ChipLogProgress(AppServer, "JNI_METHOD CastingAppJNI.finishStartup called"); + auto & server = chip::Server::GetInstance(); + + // TODO: Set AppDelegate + // &server.GetCommissioningWindowManager().SetAppDelegate(??); + + // Initialize binding handlers + chip::BindingManager::GetInstance().Init( + { &server.GetFabricTable(), server.GetCASESessionManager(), &server.GetPersistentStorage() }); + + // TODO: Set FabricDelegate + // chip::Server::GetInstance().GetFabricTable().AddFabricDelegate(&mPersistenceManager); + + // TODO: Add DeviceEvent Handler + // ReturnErrorOnFailure(DeviceLayer::PlatformMgrImpl().AddEventHandler(DeviceEventCallback, 0)); + + return support::createJMatterError(CHIP_NO_ERROR); +} + +jobject extractJAppParameter(jobject jAppParameters, const char * methodName, const char * methodSig) +{ + ChipLogProgress(AppServer, "JNI_METHOD extractJAppParameter called"); + JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread(); + + jclass jAppParametersClass; + CHIP_ERROR err = + chip::JniReferences::GetInstance().GetClassRef(env, "com/matter/casting/support/AppParameters", jAppParametersClass); + VerifyOrReturnValue(err == CHIP_NO_ERROR, nullptr); + + // get the RotatingDeviceIdUniqueIdProvider + jmethodID getMethod = env->GetMethodID(jAppParametersClass, methodName, methodSig); + if (env->ExceptionCheck()) + { + env->ExceptionDescribe(); + env->ExceptionClear(); + return nullptr; + } + + jobject jParameter = (jobject) env->CallObjectMethod(jAppParameters, getMethod); + if (env->ExceptionCheck()) + { + env->ExceptionDescribe(); + env->ExceptionClear(); + return nullptr; + } + + return jParameter; +} + +}; // namespace core +}; // namespace casting +}; // namespace matter diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/core/CastingApp-JNI.h b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/core/CastingApp-JNI.h new file mode 100644 index 00000000000000..668ab78fdcfccd --- /dev/null +++ b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/core/CastingApp-JNI.h @@ -0,0 +1,41 @@ +/* + * + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * 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 + +namespace matter { +namespace casting { +namespace core { + +class CastingAppJNI +{ +public: +private: + friend CastingAppJNI & CastingAppJNIMgr(); + static CastingAppJNI sInstance; +}; + +inline class CastingAppJNI & CastingAppJNIMgr() +{ + return CastingAppJNI::sInstance; +} +}; // namespace core +}; // namespace casting +}; // namespace matter diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/support/ErrorConverter-JNI.cpp b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/support/ErrorConverter-JNI.cpp new file mode 100644 index 00000000000000..171a44dc793f9f --- /dev/null +++ b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/support/ErrorConverter-JNI.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * 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. + * + */ + +#include "ErrorConverter-JNI.h" +#include + +namespace matter { +namespace casting { +namespace support { + +using namespace chip; + +jobject createJMatterError(CHIP_ERROR inErr) +{ + JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread(); + jclass jMatterErrorClass; + CHIP_ERROR err = + chip::JniReferences::GetInstance().GetClassRef(env, "com/matter/casting/support/MatterError", jMatterErrorClass); + VerifyOrReturnValue(err == CHIP_NO_ERROR, nullptr); + + jmethodID jMatterErrorConstructor = env->GetMethodID(jMatterErrorClass, "", "(JLjava/lang/String;)V"); + + return env->NewObject(jMatterErrorClass, jMatterErrorConstructor, err.AsInteger(), nullptr); +} + +}; // namespace support +}; // namespace casting +}; // namespace matter diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/support/ErrorConverter-JNI.h b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/support/ErrorConverter-JNI.h new file mode 100644 index 00000000000000..e11523397db4f3 --- /dev/null +++ b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/support/ErrorConverter-JNI.h @@ -0,0 +1,31 @@ +/* + * + * Copyright (c) 2023 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 + +#include + +namespace matter { +namespace casting { +namespace support { + +jobject createJMatterError(CHIP_ERROR inErr); + +}; // namespace support +}; // namespace casting +}; // namespace matter diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/support/RotatingDeviceIdUniqueIdProvider-JNI.cpp b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/support/RotatingDeviceIdUniqueIdProvider-JNI.cpp new file mode 100644 index 00000000000000..e010b56da36b28 --- /dev/null +++ b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/support/RotatingDeviceIdUniqueIdProvider-JNI.cpp @@ -0,0 +1,94 @@ +/* + * + * Copyright (c) 2023 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. + */ + +#include "RotatingDeviceIdUniqueIdProvider-JNI.h" +#include "lib/support/logging/CHIPLogging.h" +#include +#include +#include +#include +#include +#include + +using namespace chip; + +namespace matter { +namespace casting { +namespace support { + +CHIP_ERROR RotatingDeviceIdUniqueIdProviderJNI::Initialize(jobject provider) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + VerifyOrReturnValue(env != nullptr, CHIP_ERROR_INCORRECT_STATE, + ChipLogError(AppServer, "Failed to GetEnvForCurrentThread for RotatingDeviceIdUniqueIdProviderJNI")); + + mJNIProviderObject = env->NewGlobalRef(provider); + VerifyOrReturnValue(mJNIProviderObject != nullptr, CHIP_ERROR_INCORRECT_STATE, + ChipLogError(AppServer, "Failed to NewGlobalRef JNIProvider")); + + jclass JNIProviderClass = env->GetObjectClass(provider); + VerifyOrReturnValue(JNIProviderClass != nullptr, CHIP_ERROR_INCORRECT_STATE, + ChipLogError(AppServer, "Failed to get JNIProvider Java class")); + + mGetMethod = env->GetMethodID(JNIProviderClass, "_get", "()Ljava/lang/Object;"); + if (mGetMethod == nullptr) + { + ChipLogError(AppServer, "Failed to access JNIProvider '_get' method"); + env->ExceptionClear(); + } + return CHIP_NO_ERROR; +} + +CHIP_ERROR RotatingDeviceIdUniqueIdProviderJNI::GetJavaByteByMethod(jmethodID method, MutableByteSpan & out_buffer) +{ + JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread(); + VerifyOrReturnLogError(mJNIProviderObject != nullptr, CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturnLogError(method != nullptr, CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturnLogError(env != nullptr, CHIP_JNI_ERROR_NO_ENV); + + jbyteArray outArray = (jbyteArray) env->CallObjectMethod(mJNIProviderObject, method); + if (env->ExceptionCheck()) + { + ChipLogError(AppServer, "Java exception in get Method"); + env->ExceptionDescribe(); + env->ExceptionClear(); + return CHIP_ERROR_INCORRECT_STATE; + } + + if (outArray == nullptr || env->GetArrayLength(outArray) <= 0) + { + out_buffer.reduce_size(0); + return CHIP_NO_ERROR; + } + + JniByteArray JniOutArray(env, outArray); + return CopySpanToMutableSpan(JniOutArray.byteSpan(), out_buffer); +} + +MutableByteSpan * RotatingDeviceIdUniqueIdProviderJNI::Get() +{ + ChipLogProgress(AppServer, "RotatingDeviceIdUniqueIdProviderJNI.Get() called"); + mRotatingDeviceIdUniqueIdSpan = MutableByteSpan(mRotatingDeviceIdUniqueId); + CHIP_ERROR err = GetJavaByteByMethod(mGetMethod, mRotatingDeviceIdUniqueIdSpan); + VerifyOrReturnValue(err != CHIP_NO_ERROR, nullptr, + ChipLogError(AppServer, "Error calling GetJavaByteByMethod %" CHIP_ERROR_FORMAT, err.Format())); + return &mRotatingDeviceIdUniqueIdSpan; +} + +}; // namespace support +}; // namespace casting +}; // namespace matter diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/support/RotatingDeviceIdUniqueIdProvider-JNI.h b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/support/RotatingDeviceIdUniqueIdProvider-JNI.h new file mode 100644 index 00000000000000..fdec7744684834 --- /dev/null +++ b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/support/RotatingDeviceIdUniqueIdProvider-JNI.h @@ -0,0 +1,44 @@ +/* + * + * Copyright (c) 2023 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 "core/Types.h" + +#include + +namespace matter { +namespace casting { +namespace support { + +class RotatingDeviceIdUniqueIdProviderJNI : public MutableByteSpanDataProvider +{ +public: + CHIP_ERROR Initialize(jobject provider); + chip::MutableByteSpan * Get() override; + +private: + CHIP_ERROR GetJavaByteByMethod(jmethodID method, chip::MutableByteSpan & out_buffer); + jobject mJNIProviderObject = nullptr; + jmethodID mGetMethod = nullptr; + + chip::MutableByteSpan mRotatingDeviceIdUniqueIdSpan; + uint8_t mRotatingDeviceIdUniqueId[chip::DeviceLayer::ConfigurationManager::kRotatingDeviceIDUniqueIDLength]; +}; + +}; // namespace support +}; // namespace casting +}; // namespace matter diff --git a/examples/tv-casting-app/android/BUILD.gn b/examples/tv-casting-app/android/BUILD.gn index d072dd4c088e95..ae349bce337efe 100644 --- a/examples/tv-casting-app/android/BUILD.gn +++ b/examples/tv-casting-app/android/BUILD.gn @@ -34,6 +34,16 @@ shared_library("jni") { "App/app/src/main/jni/cpp/TvCastingApp-JNI.cpp", ] + # add simplified casting API files here + sources += [ + "App/app/src/main/jni/cpp/core/CastingApp-JNI.cpp", + "App/app/src/main/jni/cpp/core/CastingApp-JNI.h", + "App/app/src/main/jni/cpp/support/ErrorConverter-JNI.cpp", + "App/app/src/main/jni/cpp/support/ErrorConverter-JNI.h", + "App/app/src/main/jni/cpp/support/RotatingDeviceIdUniqueIdProvider-JNI.cpp", + "App/app/src/main/jni/cpp/support/RotatingDeviceIdUniqueIdProvider-JNI.h", + ] + deps = [ "${chip_root}/examples/tv-casting-app/tv-casting-common", "${chip_root}/src/app/server/java:jni", @@ -83,6 +93,17 @@ android_library("java") { "App/app/src/main/jni/com/chip/casting/VideoPlayer.java", ] + # add simplified casting API files here + sources += [ + "App/app/src/main/jni/com/matter/casting/core/CastingApp.java", + "App/app/src/main/jni/com/matter/casting/core/CastingAppState.java", + "App/app/src/main/jni/com/matter/casting/support/AppParameters.java", + "App/app/src/main/jni/com/matter/casting/support/CommissionableData.java", + "App/app/src/main/jni/com/matter/casting/support/DACProvider.java", + "App/app/src/main/jni/com/matter/casting/support/DataProvider.java", + "App/app/src/main/jni/com/matter/casting/support/MatterError.java", + ] + javac_flags = [ "-Xlint:deprecation" ] # TODO: add classpath support (we likely need to add something like diff --git a/examples/tv-casting-app/tv-casting-common/core/CastingApp.cpp b/examples/tv-casting-app/tv-casting-common/core/CastingApp.cpp index cc21c29c9b5f30..3dd42d91d293bb 100644 --- a/examples/tv-casting-app/tv-casting-common/core/CastingApp.cpp +++ b/examples/tv-casting-app/tv-casting-common/core/CastingApp.cpp @@ -118,7 +118,7 @@ CHIP_ERROR CastingApp::Stop() // Shutdown the Matter server chip::Server::GetInstance().Shutdown(); - mState = NOT_RUNNING; // CastingApp started successfully, set state to RUNNING + mState = NOT_RUNNING; // CastingApp stopped successfully, set state to NOT_RUNNING return CHIP_ERROR_NOT_IMPLEMENTED; } diff --git a/examples/tv-casting-app/tv-casting-common/core/CastingApp.h b/examples/tv-casting-app/tv-casting-common/core/CastingApp.h index 1f122e1153c3ab..eed69e728d4358 100644 --- a/examples/tv-casting-app/tv-casting-common/core/CastingApp.h +++ b/examples/tv-casting-app/tv-casting-common/core/CastingApp.h @@ -53,20 +53,13 @@ class CastingApp CHIP_ERROR Initialize(const matter::casting::support::AppParameters & appParameters); /** - * @brief Starts the Matter server that the CastingApp runs on and calls PostStartRegistrations() to finish starting up the + * @brief Starts the Matter server that the CastingApp runs on and registers all the necessary delegates * CastingApp. * * @return CHIP_ERROR - CHIP_NO_ERROR if Matter server started successfully, specific error code otherwise. */ CHIP_ERROR Start(); - /** - * @brief Perform post Matter server startup registrations - * - * @return CHIP_ERROR - CHIP_NO_ERROR if all registrations succeeded, specific error code otherwise - */ - CHIP_ERROR PostStartRegistrations(); - /** * @brief Stops the Matter server that the CastingApp runs on * @@ -81,6 +74,13 @@ class CastingApp CastingApp(CastingApp & other) = delete; void operator=(const CastingApp &) = delete; + /** + * @brief Perform post Matter server startup registrations + * + * @return CHIP_ERROR - CHIP_NO_ERROR if all registrations succeeded, specific error code otherwise + */ + CHIP_ERROR PostStartRegistrations(); + const matter::casting::support::AppParameters * mAppParameters; CastingAppState mState = UNINITIALIZED; diff --git a/examples/tv-casting-app/tv-casting-common/core/Types.h b/examples/tv-casting-app/tv-casting-common/core/Types.h index a5dce75d60d181..691fc3d2b36944 100644 --- a/examples/tv-casting-app/tv-casting-common/core/Types.h +++ b/examples/tv-casting-app/tv-casting-common/core/Types.h @@ -37,11 +37,11 @@ using Strong = std::shared_ptr; } // namespace memory -namespace app { +namespace core { class CastingApp; -}; +}; // namespace core namespace support { From c02ad95a881df4dacb57b2e3a1ac89bbd6c42427 Mon Sep 17 00:00:00 2001 From: Ricardo Casallas <77841255+rcasallas-silabs@users.noreply.github.com> Date: Fri, 25 Aug 2023 18:00:32 -0400 Subject: [PATCH 2/8] [Silabs] Fix SiWx917 compilation error due to attestation provider implementation. (#28895) --- examples/platform/silabs/SilabsDeviceAttestationCreds.cpp | 4 ++++ third_party/silabs/SiWx917_sdk.gni | 1 + 2 files changed, 5 insertions(+) diff --git a/examples/platform/silabs/SilabsDeviceAttestationCreds.cpp b/examples/platform/silabs/SilabsDeviceAttestationCreds.cpp index 53590ff2b7672d..dac4081ff35e12 100644 --- a/examples/platform/silabs/SilabsDeviceAttestationCreds.cpp +++ b/examples/platform/silabs/SilabsDeviceAttestationCreds.cpp @@ -100,6 +100,9 @@ class DeviceAttestationCredsSilabs : public DeviceAttestationCredentialsProvider if (SilabsConfig::ConfigValueExists(SilabsConfig::kConfigKey_Creds_KeyId)) { // Provisioned DAC key +#ifdef SIWX_917 + return CHIP_ERROR_NOT_IMPLEMENTED; +#else uint32_t key_id = SILABS_CREDENTIALS_DAC_KEY_ID; uint8_t signature[64] = { 0 }; size_t signature_size = sizeof(signature); @@ -114,6 +117,7 @@ class DeviceAttestationCredsSilabs : public DeviceAttestationCredentialsProvider VerifyOrReturnError(!err, CHIP_ERROR_INTERNAL); return CopySpanToMutableSpan(ByteSpan(signature, signature_size), out_span); +#endif } else { diff --git a/third_party/silabs/SiWx917_sdk.gni b/third_party/silabs/SiWx917_sdk.gni index b138ef10c57537..d2e8fd731dbe65 100644 --- a/third_party/silabs/SiWx917_sdk.gni +++ b/third_party/silabs/SiWx917_sdk.gni @@ -44,6 +44,7 @@ template("siwx917_sdk") { # Treat these includes as system includes, so warnings in them are not fatal. _include_dirs = [ + "${chip_root}", "${chip_root}/examples/platform/silabs/SiWx917/SiWx917", "${sdk_support_root}/matter/si91x/siwx917/BRD4325x/support/hal", "${efr32_sdk_root}/platform/emdrv/nvm3/inc", From f09fce83835b1cd46350471000379c743bcaff2e Mon Sep 17 00:00:00 2001 From: Wang Qixiang <43193572+wqx6@users.noreply.github.com> Date: Sat, 26 Aug 2023 09:19:31 +0800 Subject: [PATCH 3/8] ICD: fix expect response count issue (#28887) Co-authored-by: Boris Zbarsky --- src/messaging/ExchangeContext.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/messaging/ExchangeContext.cpp b/src/messaging/ExchangeContext.cpp index cac98cd95017f0..bb8fe2d993da32 100644 --- a/src/messaging/ExchangeContext.cpp +++ b/src/messaging/ExchangeContext.cpp @@ -156,7 +156,7 @@ CHIP_ERROR ExchangeContext::SendMessage(Protocols::Id protocolId, uint8_t msgTyp bool reliableTransmissionRequested = GetSessionHandle()->RequireMRP() && !sendFlags.Has(SendMessageFlags::kNoAutoRequestAck) && !IsGroupExchangeContext(); - bool startedResponseTimer = false; + bool currentMessageExpectResponse = false; // If a response message is expected... if (sendFlags.Has(SendMessageFlags::kExpectResponse) && !IsGroupExchangeContext()) { @@ -178,7 +178,7 @@ CHIP_ERROR ExchangeContext::SendMessage(Protocols::Id protocolId, uint8_t msgTyp SetResponseExpected(false); return err; } - startedResponseTimer = true; + currentMessageExpectResponse = true; } } @@ -222,9 +222,9 @@ CHIP_ERROR ExchangeContext::SendMessage(Protocols::Id protocolId, uint8_t msgTyp #endif if (err != CHIP_NO_ERROR) { - // We should only cancel the response timer if the ExchangeContext fails to send the message that starts the response - // timer. - if (startedResponseTimer) + // We should only cancel the response timer if the ExchangeContext fails to send the message that expects a + // response. + if (currentMessageExpectResponse) { CancelResponseTimer(); SetResponseExpected(false); @@ -243,7 +243,7 @@ CHIP_ERROR ExchangeContext::SendMessage(Protocols::Id protocolId, uint8_t msgTyp #if CONFIG_DEVICE_LAYER && CHIP_CONFIG_ENABLE_ICD_SERVER DeviceLayer::ChipDeviceEvent event; event.Type = DeviceLayer::DeviceEventType::kChipMsgSentEvent; - event.MessageSent.ExpectResponse = IsResponseExpected(); + event.MessageSent.ExpectResponse = currentMessageExpectResponse; CHIP_ERROR status = DeviceLayer::PlatformMgr().PostEvent(&event); if (status != CHIP_NO_ERROR) { From b79b797008270c4f39bfc63c9b1a2496a4aa1a3a Mon Sep 17 00:00:00 2001 From: C Freeman Date: Fri, 25 Aug 2023 21:33:11 -0400 Subject: [PATCH 4/8] Timesync: fix TC-11, fix DSTStatus, add to CI (#28850) --- .github/workflows/tests.yaml | 14 ++++++++- .../time-synchronization-server.cpp | 13 ++++++-- src/python_testing/TC_TIMESYNC_2_11.py | 31 +++++++------------ 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index ea421b96afccc3..2571c6410d4432 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -418,8 +418,20 @@ jobs: scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TC_ACE_1_3.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"' scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TC_CGEN_2_4.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"' scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TC_DA_1_2.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --PICS src/app/tests/suites/certification/ci-pics-values --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"' + scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --script "src/python_testing/TC_TIMESYNC_2_1.py" --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --PICS src/app/tests/suites/certification/ci-pics-values --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"' + scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --script "src/python_testing/TC_TIMESYNC_2_2.py" --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --PICS src/app/tests/suites/certification/ci-pics-values --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"' + scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --script "src/python_testing/TC_TIMESYNC_2_4.py" --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --PICS src/app/tests/suites/certification/ci-pics-values --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"' + scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --script "src/python_testing/TC_TIMESYNC_2_5.py" --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --PICS src/app/tests/suites/certification/ci-pics-values --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"' + scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --script "src/python_testing/TC_TIMESYNC_2_6.py" --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --PICS src/app/tests/suites/certification/ci-pics-values --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"' + scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --script "src/python_testing/TC_TIMESYNC_2_7.py" --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --PICS src/app/tests/suites/certification/ci-pics-values --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"' + scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --script "src/python_testing/TC_TIMESYNC_2_8.py" --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --PICS src/app/tests/suites/certification/ci-pics-values --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"' + scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --script "src/python_testing/TC_TIMESYNC_2_9.py" --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --PICS src/app/tests/suites/certification/ci-pics-values --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"' + scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --script "src/python_testing/TC_TIMESYNC_2_10.py" --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --PICS src/app/tests/suites/certification/ci-pics-values --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"' + scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --script "src/python_testing/TC_TIMESYNC_2_11.py" --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --PICS src/app/tests/suites/certification/ci-pics-values --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"' + scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --script "src/python_testing/TC_TIMESYNC_2_12.py" --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --PICS src/app/tests/suites/certification/ci-pics-values --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"' + scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --script "src/python_testing/TC_TIMESYNC_2_13.py" --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --PICS src/app/tests/suites/certification/ci-pics-values --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"' + scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --script "src/python_testing/TC_TIMESYNC_3_1.py" --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"' scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TC_ICDM_2_1.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --PICS src/app/tests/suites/certification/ci-pics-values --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"' - scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TC_TIMESYNC_3_1.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"' scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TC_DA_1_5.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --PICS src/app/tests/suites/certification/ci-pics-values --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"' scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TC_IDM_1_2.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"' scripts/run_in_python_env.sh out/venv './scripts/tests/run_python_test.py --app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app --factoryreset --app-args "--discriminator 1234 --KVS kvs1 --trace-to json:out/trace_data/app-{SCRIPT_BASE_NAME}.json" --script "src/python_testing/TC_FAN_3_3.py" --script-args "--storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --trace-to json:out/trace_data/test-{SCRIPT_BASE_NAME}.json --trace-to perfetto:out/trace_data/test-{SCRIPT_BASE_NAME}.perfetto"' diff --git a/src/app/clusters/time-synchronization-server/time-synchronization-server.cpp b/src/app/clusters/time-synchronization-server/time-synchronization-server.cpp index b34c0f157c905c..c7c79f3d1fc499 100644 --- a/src/app/clusters/time-synchronization-server/time-synchronization-server.cpp +++ b/src/app/clusters/time-synchronization-server/time-synchronization-server.cpp @@ -807,7 +807,8 @@ CHIP_ERROR TimeSynchronizationServer::GetLocalTime(EndpointId ep, DataModel::Nul { return CHIP_ERROR_INVALID_TIME; } - VerifyOrReturnError(TimeState::kInvalid != UpdateDSTOffsetState(), CHIP_ERROR_INVALID_TIME); + TimeState newState = UpdateDSTOffsetState(); + VerifyOrReturnError(TimeState::kInvalid != newState, CHIP_ERROR_INVALID_TIME); ReturnErrorOnFailure(System::SystemClock().GetClock_RealTime(utcTime)); VerifyOrReturnError(UnixEpochToChipEpochMicro(utcTime.count(), chipEpochTime), CHIP_ERROR_INVALID_TIME); if (TimeState::kChanged == UpdateTimeZoneState()) @@ -829,6 +830,10 @@ CHIP_ERROR TimeSynchronizationServer::GetLocalTime(EndpointId ep, DataModel::Nul uint64_t localTimeSec = static_cast(static_cast(chipEpochTime) + timeZoneOffset + dstOffset); localTime.SetNonNull((localTimeSec * chip::kMicrosecondsPerSecond) + usRemainder); + if (newState == TimeState::kChanged) + { + emitDSTStatusEvent(0, dstOffset != 0); + } return CHIP_NO_ERROR; } @@ -910,8 +915,12 @@ TimeState TimeSynchronizationServer::UpdateDSTOffsetState() VerifyOrReturnValue(ClearDSTOffset() == CHIP_NO_ERROR, TimeState::kInvalid); return TimeState::kInvalid; } + int32_t previousOffset = dstList[activeDstIndex].offset; dstList[activeDstIndex].offset = 0; // not using dst and last DST item in the list is not active yet - return TimeState::kStopped; + // TODO: This enum mixes state and transitions in a way that's very confusing. This should return either an active, an + // inactive or an invalid and the caller should make the judgement about whether that has changed OR this function should + // just return a bool indicating whether a change happened + return previousOffset == 0 ? TimeState::kStopped : TimeState::kChanged; } if (activeDstIndex > 0) { diff --git a/src/python_testing/TC_TIMESYNC_2_11.py b/src/python_testing/TC_TIMESYNC_2_11.py index 5d9258044df9d6..3e0a4e070c1ca2 100644 --- a/src/python_testing/TC_TIMESYNC_2_11.py +++ b/src/python_testing/TC_TIMESYNC_2_11.py @@ -108,14 +108,17 @@ async def test_TC_TIMESYNC_2_11(self): self.print_step(8, "TH waits for DSTStatus event until th_utc + 5s") self.wait_for_dst_status(th_utc, 5, True) - self.print_step(9, "TH waits until th_utc + 15s") - time.sleep(get_wait_seconds_from_set_time(th_utc, 15)) + self.print_step(9, "If dst_list_size > 1, TH waits until th_utc + 15s") + if dst_list_size > 1: + time.sleep(get_wait_seconds_from_set_time(th_utc, 15)) - self.print_step(10, "TH reads LocalTime") - await self.read_single_attribute_check_success(cluster=Clusters.TimeSynchronization, attribute=Clusters.TimeSynchronization.Attributes.LocalTime) + self.print_step(10, "If dst_list_size > 1, TH reads LocalTime") + if dst_list_size > 1: + await self.read_single_attribute_check_success(cluster=Clusters.TimeSynchronization, attribute=Clusters.TimeSynchronization.Attributes.LocalTime) - self.print_step(11, "TH waits for DSTStatus event until th_utc + 20s") - self.wait_for_dst_status(th_utc, 20, False) + self.print_step(11, "If dst_list_size > 1, TH waits for DSTStatus event until th_utc + 20s") + if dst_list_size > 1: + self.wait_for_dst_status(th_utc, 20, False) self.print_step(12, "If dst_list_size > 1, TH waits until th_utc + 30s") if dst_list_size > 1: @@ -129,24 +132,12 @@ async def test_TC_TIMESYNC_2_11(self): if dst_list_size > 1: self.wait_for_dst_status(th_utc, 35, True) - self.print_step(15, "If dst_list_size > 1, TH waits until th_utc + 45s") - if dst_list_size > 1: - time.sleep(get_wait_seconds_from_set_time(th_utc, 45)) - - self.print_step(16, "If dst_list_size > 1, TH reads the LocalTime") - if dst_list_size > 1: - await self.read_single_attribute_check_success(cluster=Clusters.TimeSynchronization, attribute=Clusters.TimeSynchronization.Attributes.LocalTime) - - self.print_step(17, "If dst_list_size > 1, TH waits for a DSTStatus event until th_utc + 50s") - if dst_list_size > 1: - self.wait_for_dst_status(th_utc, 50, False) - - self.print_step(18, "Set time zone back to 0") + self.print_step(15, "Set time zone back to 0") tz = [tz_struct(offset=0, validAt=0)] ret = await self.send_set_time_zone_cmd(tz) asserts.assert_true(ret.DSTOffsetRequired, "DSTOffsetRequired not set to true") - self.print_step(19, "Set DST back to 0") + self.print_step(16, "Set DST back to 0") dst = [dst_struct(offset=0, validStarting=0, validUntil=NullValue)] await self.send_set_dst_cmd(dst) From caf66ecd79f885dfd48c486bf3c50b09334fbbb2 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 25 Aug 2023 23:09:57 -0400 Subject: [PATCH 5/8] Remove some unused defines from project configs. (#28906) The following macros were never actually used anywhere: * CHIP_DEVICE_CONFIG_USE_TEST_PAIRING_CODE * CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY * CHIP_CONFIG_REQUIRE_AUTH --- .../asr/include/CHIPProjectConfig.h | 1 - .../main/include/CHIPProjectConfig.h | 3 --- .../cc13x4_26x4/main/include/CHIPProjectConfig.h | 3 --- .../nxp/mw320/include/CHIPProjectConfig.h | 15 --------------- .../asr/include/CHIPProjectConfig.h | 1 - .../bridge-app/asr/include/CHIPProjectConfig.h | 10 ---------- examples/chip-tool/include/CHIPProjectAppConfig.h | 2 -- .../nxp/k32w/k32w0/include/CHIPProjectConfig.h | 3 --- .../asr/include/CHIPProjectConfig.h | 10 ---------- .../include/CHIPProjectAppConfig.h | 2 -- .../genio/include/CHIPProjectConfig.h | 1 - .../infineon/cyw30739/include/CHIPProjectConfig.h | 2 -- .../lighting-app/asr/include/CHIPProjectConfig.h | 10 ---------- .../bouffalolab/bl602/CHIPProjectConfig.h | 10 ---------- .../bouffalolab/bl702/CHIPProjectConfig.h | 11 ----------- .../bouffalolab/bl702l/CHIPProjectConfig.h | 11 ----------- .../cc13x2x7_26x2x7/include/CHIPProjectConfig.h | 3 --- .../cc13x4_26x4/include/CHIPProjectConfig.h | 3 --- .../genio/include/CHIPProjectConfig.h | 1 - .../infineon/cyw30739/include/CHIPProjectConfig.h | 2 -- .../infineon/psoc6/include/CHIPProjectConfig.h | 10 ---------- .../nxp/k32w/k32w0/include/CHIPProjectConfig.h | 3 --- examples/lock-app/asr/include/CHIPProjectConfig.h | 10 ---------- .../cc13x2x7_26x2x7/include/CHIPProjectConfig.h | 3 --- .../main/include/CHIPProjectConfig.h | 3 --- .../cc13x4_26x4/include/CHIPProjectConfig.h | 3 --- .../cc32xx/main/include/CHIPProjectConfig.h | 15 --------------- .../lock-app/genio/include/CHIPProjectConfig.h | 1 - .../infineon/cyw30739/include/CHIPProjectConfig.h | 2 -- .../nxp/k32w/k32w0/include/CHIPProjectConfig.h | 3 --- .../lock-app/silabs/include/CHIPProjectConfig.h | 1 - .../asr/include/CHIPProjectConfig.h | 10 ---------- .../genio/include/CHIPProjectConfig.h | 1 - .../infineon/cyw30739/include/CHIPProjectConfig.h | 2 -- .../cc13x2x7_26x2x7/include/CHIPProjectConfig.h | 3 --- .../infineon/psoc6/include/CHIPProjectConfig.h | 10 ---------- .../main/include/CHIPProjectConfig.h | 3 --- .../cc13x4_26x4/main/include/CHIPProjectConfig.h | 3 --- .../main/include/CHIPProjectConfig.h | 3 --- .../cc13x4_26x4/main/include/CHIPProjectConfig.h | 3 --- .../cc13x2x7_26x2x7/include/CHIPProjectConfig.h | 3 --- .../shell/cc13x4_26x4/include/CHIPProjectConfig.h | 3 --- examples/shell/genio/include/CHIPProjectConfig.h | 1 - .../nxp/k32w/k32w0/include/CHIPProjectConfig.h | 3 --- .../asr/include/CHIPProjectConfig.h | 10 ---------- .../thermostat/asr/include/CHIPProjectConfig.h | 10 ---------- 46 files changed, 226 deletions(-) diff --git a/examples/all-clusters-app/asr/include/CHIPProjectConfig.h b/examples/all-clusters-app/asr/include/CHIPProjectConfig.h index 6a81ee6517aedb..dba0febabcd20d 100755 --- a/examples/all-clusters-app/asr/include/CHIPProjectConfig.h +++ b/examples/all-clusters-app/asr/include/CHIPProjectConfig.h @@ -43,7 +43,6 @@ // including message encryption. Because of this they MUST NEVER BE ENABLED IN PRODUCTION BUILDS. // #define CHIP_CONFIG_SECURITY_TEST_MODE 0 -#define CHIP_CONFIG_REQUIRE_AUTH 1 /** * CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION diff --git a/examples/all-clusters-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h b/examples/all-clusters-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h index b4f9ba2b737c86..97357823332342 100644 --- a/examples/all-clusters-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h +++ b/examples/all-clusters-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h @@ -36,9 +36,6 @@ #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 -// Use a default pairing code if one hasn't been provisioned in flash. -#define CHIP_DEVICE_CONFIG_USE_TEST_PAIRING_CODE "CHIPUS" - /** * CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER * diff --git a/examples/all-clusters-app/cc13x4_26x4/main/include/CHIPProjectConfig.h b/examples/all-clusters-app/cc13x4_26x4/main/include/CHIPProjectConfig.h index 939f01d93b8e6c..f42469c54a5880 100644 --- a/examples/all-clusters-app/cc13x4_26x4/main/include/CHIPProjectConfig.h +++ b/examples/all-clusters-app/cc13x4_26x4/main/include/CHIPProjectConfig.h @@ -36,9 +36,6 @@ #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 -// Use a default pairing code if one hasn't been provisioned in flash. -#define CHIP_DEVICE_CONFIG_USE_TEST_PAIRING_CODE "CHIPUS" - /** * CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER * diff --git a/examples/all-clusters-app/nxp/mw320/include/CHIPProjectConfig.h b/examples/all-clusters-app/nxp/mw320/include/CHIPProjectConfig.h index bce9f09d3cbee2..5e4a6b1e4f5419 100644 --- a/examples/all-clusters-app/nxp/mw320/include/CHIPProjectConfig.h +++ b/examples/all-clusters-app/nxp/mw320/include/CHIPProjectConfig.h @@ -31,7 +31,6 @@ // Security and Authentication enabled for release build. #define CHIP_CONFIG_SECURITY_TEST_MODE 0 -#define CHIP_CONFIG_REQUIRE_AUTH 1 #else // development build @@ -41,20 +40,6 @@ // WARNING: These options make it possible to circumvent basic CHIP security functionality, // including message encryption. Because of this they MUST NEVER BE ENABLED IN PRODUCTION BUILDS. #define CHIP_CONFIG_SECURITY_TEST_MODE 0 -#define CHIP_CONFIG_REQUIRE_AUTH 1 - -/** - * CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY - * - * Enables the use of a hard-coded default CHIP device id and credentials if no device id - * is found in CHIP NV storage. - * - * This option is for testing only and should be disabled in production releases. - */ -#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 34 - -// Use a default pairing code if one hasn't been provisioned in flash. -#define CHIP_DEVICE_CONFIG_USE_TEST_PAIRING_CODE "CHIPUS" /** * CHIP_DEVICE_CONFIG_USE_TEST_SERIAL_NUMBER diff --git a/examples/all-clusters-minimal-app/asr/include/CHIPProjectConfig.h b/examples/all-clusters-minimal-app/asr/include/CHIPProjectConfig.h index 6a81ee6517aedb..dba0febabcd20d 100755 --- a/examples/all-clusters-minimal-app/asr/include/CHIPProjectConfig.h +++ b/examples/all-clusters-minimal-app/asr/include/CHIPProjectConfig.h @@ -43,7 +43,6 @@ // including message encryption. Because of this they MUST NEVER BE ENABLED IN PRODUCTION BUILDS. // #define CHIP_CONFIG_SECURITY_TEST_MODE 0 -#define CHIP_CONFIG_REQUIRE_AUTH 1 /** * CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION diff --git a/examples/bridge-app/asr/include/CHIPProjectConfig.h b/examples/bridge-app/asr/include/CHIPProjectConfig.h index 6b159a670b5ed7..4520ec75b28c33 100755 --- a/examples/bridge-app/asr/include/CHIPProjectConfig.h +++ b/examples/bridge-app/asr/include/CHIPProjectConfig.h @@ -27,16 +27,6 @@ #pragma once -/** - * CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY - * - * Enables the use of a hard-coded default Chip device id and credentials if no device id - * is found in Chip NV storage. - * - * This option is for testing only and should be disabled in production releases. - */ -#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 34 - // Use a default pairing code if one hasn't been provisioned in flash. #ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 diff --git a/examples/chip-tool/include/CHIPProjectAppConfig.h b/examples/chip-tool/include/CHIPProjectAppConfig.h index bc8ee25a03645e..eef6466aa1a510 100644 --- a/examples/chip-tool/include/CHIPProjectAppConfig.h +++ b/examples/chip-tool/include/CHIPProjectAppConfig.h @@ -56,8 +56,6 @@ #define CHIP_CONFIG_DATA_MANAGEMENT_CLIENT_EXPERIMENTAL 1 -#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 1 - #define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY 1 // Enable some test-only interaction model APIs. diff --git a/examples/contact-sensor-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h b/examples/contact-sensor-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h index 03e638f54cbf13..7d435215252b0e 100644 --- a/examples/contact-sensor-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h +++ b/examples/contact-sensor-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h @@ -97,9 +97,6 @@ #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 -// Use a default pairing code if one hasn't been provisioned in flash. -#define CHIP_DEVICE_CONFIG_USE_TEST_PAIRING_CODE "CHIPUS" - /** * CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER * diff --git a/examples/dishwasher-app/asr/include/CHIPProjectConfig.h b/examples/dishwasher-app/asr/include/CHIPProjectConfig.h index 38ba84fe10f85a..9a69f8227a7187 100755 --- a/examples/dishwasher-app/asr/include/CHIPProjectConfig.h +++ b/examples/dishwasher-app/asr/include/CHIPProjectConfig.h @@ -27,16 +27,6 @@ #pragma once -/** - * CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY - * - * Enables the use of a hard-coded default Chip device id and credentials if no device id - * is found in Chip NV storage. - * - * This option is for testing only and should be disabled in production releases. - */ -#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 34 - // Use a default pairing code if one hasn't been provisioned in flash. #ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 diff --git a/examples/java-matter-controller/include/CHIPProjectAppConfig.h b/examples/java-matter-controller/include/CHIPProjectAppConfig.h index dd3a009f81d785..5805016d714427 100644 --- a/examples/java-matter-controller/include/CHIPProjectAppConfig.h +++ b/examples/java-matter-controller/include/CHIPProjectAppConfig.h @@ -53,8 +53,6 @@ #define CHIP_CONFIG_DATA_MANAGEMENT_CLIENT_EXPERIMENTAL 1 -#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 1 - #define CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY 1 // Enable some test-only interaction model APIs. diff --git a/examples/light-switch-app/genio/include/CHIPProjectConfig.h b/examples/light-switch-app/genio/include/CHIPProjectConfig.h index c314ebba41e617..fec05c1ed66a48 100644 --- a/examples/light-switch-app/genio/include/CHIPProjectConfig.h +++ b/examples/light-switch-app/genio/include/CHIPProjectConfig.h @@ -44,7 +44,6 @@ // including message encryption. Because of this they MUST NEVER BE ENABLED IN PRODUCTION BUILDS. // #define CHIP_CONFIG_SECURITY_TEST_MODE 0 -#define CHIP_CONFIG_REQUIRE_AUTH 1 /** * CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID diff --git a/examples/light-switch-app/infineon/cyw30739/include/CHIPProjectConfig.h b/examples/light-switch-app/infineon/cyw30739/include/CHIPProjectConfig.h index 522e40755f8bca..82ea3f0e71d7a4 100644 --- a/examples/light-switch-app/infineon/cyw30739/include/CHIPProjectConfig.h +++ b/examples/light-switch-app/infineon/cyw30739/include/CHIPProjectConfig.h @@ -58,8 +58,6 @@ #define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN" // -------------------- Test Configuration -------------------- -#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 1 - #define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1 // ------------------------- Debug use ------------------------- diff --git a/examples/lighting-app/asr/include/CHIPProjectConfig.h b/examples/lighting-app/asr/include/CHIPProjectConfig.h index 4ff8cbed869e34..458aeb605534e9 100755 --- a/examples/lighting-app/asr/include/CHIPProjectConfig.h +++ b/examples/lighting-app/asr/include/CHIPProjectConfig.h @@ -28,16 +28,6 @@ #pragma once -/** - * CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY - * - * Enables the use of a hard-coded default Chip device id and credentials if no device id - * is found in Chip NV storage. - * - * This option is for testing only and should be disabled in production releases. - */ -#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 34 - // Use a default pairing code if one hasn't been provisioned in flash. #ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 diff --git a/examples/lighting-app/bouffalolab/bl602/CHIPProjectConfig.h b/examples/lighting-app/bouffalolab/bl602/CHIPProjectConfig.h index 24dd8a2c395383..d265e16693b9b2 100644 --- a/examples/lighting-app/bouffalolab/bl602/CHIPProjectConfig.h +++ b/examples/lighting-app/bouffalolab/bl602/CHIPProjectConfig.h @@ -27,16 +27,6 @@ #pragma once -/** - * CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY - * - * Enables the use of a hard-coded default Chip device id and credentials if no device id - * is found in Chip NV storage. - * - * This option is for testing only and should be disabled in production releases. - */ -#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 34 - // Use a default pairing code if one hasn't been provisioned in flash. #ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 diff --git a/examples/lighting-app/bouffalolab/bl702/CHIPProjectConfig.h b/examples/lighting-app/bouffalolab/bl702/CHIPProjectConfig.h index 19ff4f3eaf13f4..137b0aff6e8ee8 100644 --- a/examples/lighting-app/bouffalolab/bl702/CHIPProjectConfig.h +++ b/examples/lighting-app/bouffalolab/bl702/CHIPProjectConfig.h @@ -27,16 +27,6 @@ #pragma once -/** - * CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY - * - * Enables the use of a hard-coded default Chip device id and credentials if no device id - * is found in Chip NV storage. - * - * This option is for testing only and should be disabled in production releases. - */ -#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 34 - // Use a default pairing code if one hasn't been provisioned in flash. #ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 @@ -53,7 +43,6 @@ // including message encryption. Because of this they MUST NEVER BE ENABLED IN PRODUCTION BUILDS. // #define CHIP_CONFIG_SECURITY_TEST_MODE 0 -#define CHIP_CONFIG_REQUIRE_AUTH 1 /** * CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID diff --git a/examples/lighting-app/bouffalolab/bl702l/CHIPProjectConfig.h b/examples/lighting-app/bouffalolab/bl702l/CHIPProjectConfig.h index 19ff4f3eaf13f4..137b0aff6e8ee8 100644 --- a/examples/lighting-app/bouffalolab/bl702l/CHIPProjectConfig.h +++ b/examples/lighting-app/bouffalolab/bl702l/CHIPProjectConfig.h @@ -27,16 +27,6 @@ #pragma once -/** - * CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY - * - * Enables the use of a hard-coded default Chip device id and credentials if no device id - * is found in Chip NV storage. - * - * This option is for testing only and should be disabled in production releases. - */ -#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 34 - // Use a default pairing code if one hasn't been provisioned in flash. #ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 @@ -53,7 +43,6 @@ // including message encryption. Because of this they MUST NEVER BE ENABLED IN PRODUCTION BUILDS. // #define CHIP_CONFIG_SECURITY_TEST_MODE 0 -#define CHIP_CONFIG_REQUIRE_AUTH 1 /** * CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID diff --git a/examples/lighting-app/cc13x2x7_26x2x7/include/CHIPProjectConfig.h b/examples/lighting-app/cc13x2x7_26x2x7/include/CHIPProjectConfig.h index 0f5090d7d9f320..88e08c63321770 100644 --- a/examples/lighting-app/cc13x2x7_26x2x7/include/CHIPProjectConfig.h +++ b/examples/lighting-app/cc13x2x7_26x2x7/include/CHIPProjectConfig.h @@ -36,9 +36,6 @@ #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 -// Use a default pairing code if one hasn't been provisioned in flash. -#define CHIP_DEVICE_CONFIG_USE_TEST_PAIRING_CODE "CHIPUS" - /** * CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER * diff --git a/examples/lighting-app/cc13x4_26x4/include/CHIPProjectConfig.h b/examples/lighting-app/cc13x4_26x4/include/CHIPProjectConfig.h index 0f5090d7d9f320..88e08c63321770 100644 --- a/examples/lighting-app/cc13x4_26x4/include/CHIPProjectConfig.h +++ b/examples/lighting-app/cc13x4_26x4/include/CHIPProjectConfig.h @@ -36,9 +36,6 @@ #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 -// Use a default pairing code if one hasn't been provisioned in flash. -#define CHIP_DEVICE_CONFIG_USE_TEST_PAIRING_CODE "CHIPUS" - /** * CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER * diff --git a/examples/lighting-app/genio/include/CHIPProjectConfig.h b/examples/lighting-app/genio/include/CHIPProjectConfig.h index dbdd8fcdbe350d..00e00a63256185 100644 --- a/examples/lighting-app/genio/include/CHIPProjectConfig.h +++ b/examples/lighting-app/genio/include/CHIPProjectConfig.h @@ -44,7 +44,6 @@ // including message encryption. Because of this they MUST NEVER BE ENABLED IN PRODUCTION BUILDS. // #define CHIP_CONFIG_SECURITY_TEST_MODE 0 -#define CHIP_CONFIG_REQUIRE_AUTH 1 /** * CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID diff --git a/examples/lighting-app/infineon/cyw30739/include/CHIPProjectConfig.h b/examples/lighting-app/infineon/cyw30739/include/CHIPProjectConfig.h index 233ffd19da1e59..26d7e65bcca57e 100644 --- a/examples/lighting-app/infineon/cyw30739/include/CHIPProjectConfig.h +++ b/examples/lighting-app/infineon/cyw30739/include/CHIPProjectConfig.h @@ -58,6 +58,4 @@ #define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN" // -------------------- Test Configuration -------------------- -#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 1 - #define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1 diff --git a/examples/lighting-app/infineon/psoc6/include/CHIPProjectConfig.h b/examples/lighting-app/infineon/psoc6/include/CHIPProjectConfig.h index fe4ba5c8fe87e4..ab00f26adecb76 100644 --- a/examples/lighting-app/infineon/psoc6/include/CHIPProjectConfig.h +++ b/examples/lighting-app/infineon/psoc6/include/CHIPProjectConfig.h @@ -28,16 +28,6 @@ #pragma once -/** - * CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY - * - * Enables the use of a hard-coded default Chip device id and credentials if no device id - * is found in Chip NV storage. - * - * This option is for testing only and should be disabled in production releases. - */ -#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 34 - // Use a default pairing code if one hasn't been provisioned in flash. #ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 diff --git a/examples/lighting-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h b/examples/lighting-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h index f56764b2cb731b..63abce6c8c0682 100644 --- a/examples/lighting-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h +++ b/examples/lighting-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h @@ -111,9 +111,6 @@ #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 -// Use a default pairing code if one hasn't been provisioned in flash. -#define CHIP_DEVICE_CONFIG_USE_TEST_PAIRING_CODE "CHIPUS" - /** * CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER * diff --git a/examples/lock-app/asr/include/CHIPProjectConfig.h b/examples/lock-app/asr/include/CHIPProjectConfig.h index fbaf9ea3c7c9be..866db6b5836475 100755 --- a/examples/lock-app/asr/include/CHIPProjectConfig.h +++ b/examples/lock-app/asr/include/CHIPProjectConfig.h @@ -28,16 +28,6 @@ #pragma once -/** - * CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY - * - * Enables the use of a hard-coded default Chip device id and credentials if no device id - * is found in Chip NV storage. - * - * This option is for testing only and should be disabled in production releases. - */ -#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 34 - // Use a default pairing code if one hasn't been provisioned in flash. #ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 diff --git a/examples/lock-app/cc13x2x7_26x2x7/include/CHIPProjectConfig.h b/examples/lock-app/cc13x2x7_26x2x7/include/CHIPProjectConfig.h index a808f37a72d7b5..6e6a2562178da4 100644 --- a/examples/lock-app/cc13x2x7_26x2x7/include/CHIPProjectConfig.h +++ b/examples/lock-app/cc13x2x7_26x2x7/include/CHIPProjectConfig.h @@ -36,9 +36,6 @@ #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 -// Use a default pairing code if one hasn't been provisioned in flash. -#define CHIP_DEVICE_CONFIG_USE_TEST_PAIRING_CODE "CHIPUS" - /** * CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER * diff --git a/examples/lock-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h b/examples/lock-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h index 5e4fd0215c517a..424e38a29f7766 100644 --- a/examples/lock-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h +++ b/examples/lock-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h @@ -36,9 +36,6 @@ #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 -// Use a default pairing code if one hasn't been provisioned in flash. -#define CHIP_DEVICE_CONFIG_USE_TEST_PAIRING_CODE "CHIPUS" - /** * CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER * diff --git a/examples/lock-app/cc13x4_26x4/include/CHIPProjectConfig.h b/examples/lock-app/cc13x4_26x4/include/CHIPProjectConfig.h index a808f37a72d7b5..6e6a2562178da4 100644 --- a/examples/lock-app/cc13x4_26x4/include/CHIPProjectConfig.h +++ b/examples/lock-app/cc13x4_26x4/include/CHIPProjectConfig.h @@ -36,9 +36,6 @@ #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 -// Use a default pairing code if one hasn't been provisioned in flash. -#define CHIP_DEVICE_CONFIG_USE_TEST_PAIRING_CODE "CHIPUS" - /** * CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER * diff --git a/examples/lock-app/cc32xx/main/include/CHIPProjectConfig.h b/examples/lock-app/cc32xx/main/include/CHIPProjectConfig.h index 4268330033b485..a7d35339632e4f 100644 --- a/examples/lock-app/cc32xx/main/include/CHIPProjectConfig.h +++ b/examples/lock-app/cc32xx/main/include/CHIPProjectConfig.h @@ -32,7 +32,6 @@ // Security and Authentication enabled for release build. #define CHIP_CONFIG_SECURITY_TEST_MODE 0 -#define CHIP_CONFIG_REQUIRE_AUTH 1 #else // development build @@ -42,25 +41,11 @@ // WARNING: These options make it possible to circumvent basic CHIP security functionality, // including message encryption. Because of this they MUST NEVER BE ENABLED IN PRODUCTION BUILDS. #define CHIP_CONFIG_SECURITY_TEST_MODE 0 -#define CHIP_CONFIG_REQUIRE_AUTH 0 - -/** - * CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY - * - * Enables the use of a hard-coded default CHIP device id and credentials if no device id - * is found in CHIP NV storage. - * - * This option is for testing only and should be disabled in production releases. - */ -#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 34 // Use a default pairing code if one hasn't been provisioned in flash. #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 -// Use a default pairing code if one hasn't been provisioned in flash. -#define CHIP_DEVICE_CONFIG_USE_TEST_PAIRING_CODE "CHIPUS" - /** * CHIP_DEVICE_CONFIG_USE_TEST_SERIAL_NUMBER * diff --git a/examples/lock-app/genio/include/CHIPProjectConfig.h b/examples/lock-app/genio/include/CHIPProjectConfig.h index 65333f8b2b82d7..d0066caae603d1 100644 --- a/examples/lock-app/genio/include/CHIPProjectConfig.h +++ b/examples/lock-app/genio/include/CHIPProjectConfig.h @@ -44,7 +44,6 @@ // including message encryption. Because of this they MUST NEVER BE ENABLED IN PRODUCTION BUILDS. // #define CHIP_CONFIG_SECURITY_TEST_MODE 0 -#define CHIP_CONFIG_REQUIRE_AUTH 1 /** * CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID diff --git a/examples/lock-app/infineon/cyw30739/include/CHIPProjectConfig.h b/examples/lock-app/infineon/cyw30739/include/CHIPProjectConfig.h index 40eedf4771147d..ffe889f725d909 100644 --- a/examples/lock-app/infineon/cyw30739/include/CHIPProjectConfig.h +++ b/examples/lock-app/infineon/cyw30739/include/CHIPProjectConfig.h @@ -58,6 +58,4 @@ #define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN" // -------------------- Test Configuration -------------------- -#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 1 - #define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1 diff --git a/examples/lock-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h b/examples/lock-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h index 0e087ffa3f3a1b..046b005f78da73 100644 --- a/examples/lock-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h +++ b/examples/lock-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h @@ -97,9 +97,6 @@ #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 -// Use a default pairing code if one hasn't been provisioned in flash. -#define CHIP_DEVICE_CONFIG_USE_TEST_PAIRING_CODE "CHIPUS" - /** * CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER * diff --git a/examples/lock-app/silabs/include/CHIPProjectConfig.h b/examples/lock-app/silabs/include/CHIPProjectConfig.h index 1cfb6e7b0ac82c..87d7485558c659 100644 --- a/examples/lock-app/silabs/include/CHIPProjectConfig.h +++ b/examples/lock-app/silabs/include/CHIPProjectConfig.h @@ -44,7 +44,6 @@ // including message encryption. Because of this they MUST NEVER BE ENABLED IN PRODUCTION BUILDS. // #define CHIP_CONFIG_SECURITY_TEST_MODE 0 -#define CHIP_CONFIG_REQUIRE_AUTH 1 /** * CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID diff --git a/examples/ota-requestor-app/asr/include/CHIPProjectConfig.h b/examples/ota-requestor-app/asr/include/CHIPProjectConfig.h index 9f21f281471076..7ee063f0924661 100755 --- a/examples/ota-requestor-app/asr/include/CHIPProjectConfig.h +++ b/examples/ota-requestor-app/asr/include/CHIPProjectConfig.h @@ -28,16 +28,6 @@ #pragma once -/** - * CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY - * - * Enables the use of a hard-coded default Chip device id and credentials if no device id - * is found in Chip NV storage. - * - * This option is for testing only and should be disabled in production releases. - */ -#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 34 - // Use a default pairing code if one hasn't been provisioned in flash. #ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 diff --git a/examples/ota-requestor-app/genio/include/CHIPProjectConfig.h b/examples/ota-requestor-app/genio/include/CHIPProjectConfig.h index 79395c5bb88a32..28ec12d1e86248 100644 --- a/examples/ota-requestor-app/genio/include/CHIPProjectConfig.h +++ b/examples/ota-requestor-app/genio/include/CHIPProjectConfig.h @@ -44,7 +44,6 @@ // including message encryption. Because of this they MUST NEVER BE ENABLED IN PRODUCTION BUILDS. // #define CHIP_CONFIG_SECURITY_TEST_MODE 0 -#define CHIP_CONFIG_REQUIRE_AUTH 1 /** * CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID diff --git a/examples/ota-requestor-app/infineon/cyw30739/include/CHIPProjectConfig.h b/examples/ota-requestor-app/infineon/cyw30739/include/CHIPProjectConfig.h index f3f4c57bc244a3..82a889907606bd 100644 --- a/examples/ota-requestor-app/infineon/cyw30739/include/CHIPProjectConfig.h +++ b/examples/ota-requestor-app/infineon/cyw30739/include/CHIPProjectConfig.h @@ -58,6 +58,4 @@ #define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN" // -------------------- Test Configuration -------------------- -#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 1 - #define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1 diff --git a/examples/persistent-storage/cc13x2x7_26x2x7/include/CHIPProjectConfig.h b/examples/persistent-storage/cc13x2x7_26x2x7/include/CHIPProjectConfig.h index 2a15a30a7f4c02..2bcf489732b312 100644 --- a/examples/persistent-storage/cc13x2x7_26x2x7/include/CHIPProjectConfig.h +++ b/examples/persistent-storage/cc13x2x7_26x2x7/include/CHIPProjectConfig.h @@ -46,9 +46,6 @@ #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 -// Use a default pairing code if one hasn't been provisioned in flash. -#define CHIP_DEVICE_CONFIG_USE_TEST_PAIRING_CODE "CHIPUS" - /** * CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER * diff --git a/examples/persistent-storage/infineon/psoc6/include/CHIPProjectConfig.h b/examples/persistent-storage/infineon/psoc6/include/CHIPProjectConfig.h index 900b0d10ef8ca6..83435a2c574e34 100644 --- a/examples/persistent-storage/infineon/psoc6/include/CHIPProjectConfig.h +++ b/examples/persistent-storage/infineon/psoc6/include/CHIPProjectConfig.h @@ -28,16 +28,6 @@ #pragma once -/** - * CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY - * - * Enables the use of a hard-coded default Chip device id and credentials if no device id - * is found in Chip NV storage. - * - * This option is for testing only and should be disabled in production releases. - */ -#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 34 - // Use a default pairing code if one hasn't been provisioned in flash. #ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 diff --git a/examples/pump-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h b/examples/pump-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h index f99523c278db0c..e10a37616e6360 100644 --- a/examples/pump-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h +++ b/examples/pump-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h @@ -39,9 +39,6 @@ #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 -// Use a default pairing code if one hasn't been provisioned in flash. -#define CHIP_DEVICE_CONFIG_USE_TEST_PAIRING_CODE "CHIPUS" - /** * CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION * diff --git a/examples/pump-app/cc13x4_26x4/main/include/CHIPProjectConfig.h b/examples/pump-app/cc13x4_26x4/main/include/CHIPProjectConfig.h index 49a0e036a33181..44fb94d6161543 100644 --- a/examples/pump-app/cc13x4_26x4/main/include/CHIPProjectConfig.h +++ b/examples/pump-app/cc13x4_26x4/main/include/CHIPProjectConfig.h @@ -39,9 +39,6 @@ #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 -// Use a default pairing code if one hasn't been provisioned in flash. -#define CHIP_DEVICE_CONFIG_USE_TEST_PAIRING_CODE "CHIPUS" - /** * CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION * diff --git a/examples/pump-controller-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h b/examples/pump-controller-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h index 97dac7bf1fe313..e8329c75ae9e29 100644 --- a/examples/pump-controller-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h +++ b/examples/pump-controller-app/cc13x2x7_26x2x7/main/include/CHIPProjectConfig.h @@ -39,9 +39,6 @@ #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 -// Use a default pairing code if one hasn't been provisioned in flash. -#define CHIP_DEVICE_CONFIG_USE_TEST_PAIRING_CODE "CHIPUS" - /** * CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION * diff --git a/examples/pump-controller-app/cc13x4_26x4/main/include/CHIPProjectConfig.h b/examples/pump-controller-app/cc13x4_26x4/main/include/CHIPProjectConfig.h index 2b2c3370763af8..cbf68cae5508d3 100644 --- a/examples/pump-controller-app/cc13x4_26x4/main/include/CHIPProjectConfig.h +++ b/examples/pump-controller-app/cc13x4_26x4/main/include/CHIPProjectConfig.h @@ -39,9 +39,6 @@ #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 -// Use a default pairing code if one hasn't been provisioned in flash. -#define CHIP_DEVICE_CONFIG_USE_TEST_PAIRING_CODE "CHIPUS" - /** * CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION * diff --git a/examples/shell/cc13x2x7_26x2x7/include/CHIPProjectConfig.h b/examples/shell/cc13x2x7_26x2x7/include/CHIPProjectConfig.h index 1e8f718031e90f..0464c9d043027e 100644 --- a/examples/shell/cc13x2x7_26x2x7/include/CHIPProjectConfig.h +++ b/examples/shell/cc13x2x7_26x2x7/include/CHIPProjectConfig.h @@ -30,9 +30,6 @@ #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 -// Use a default pairing code if one hasn't been provisioned in flash. -#define CHIP_DEVICE_CONFIG_USE_TEST_PAIRING_CODE "CHIPUS" - /** * CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER * diff --git a/examples/shell/cc13x4_26x4/include/CHIPProjectConfig.h b/examples/shell/cc13x4_26x4/include/CHIPProjectConfig.h index bec2bc08625272..d362c297d07f14 100644 --- a/examples/shell/cc13x4_26x4/include/CHIPProjectConfig.h +++ b/examples/shell/cc13x4_26x4/include/CHIPProjectConfig.h @@ -30,9 +30,6 @@ #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 -// Use a default pairing code if one hasn't been provisioned in flash. -#define CHIP_DEVICE_CONFIG_USE_TEST_PAIRING_CODE "CHIPUS" - /** * CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER * diff --git a/examples/shell/genio/include/CHIPProjectConfig.h b/examples/shell/genio/include/CHIPProjectConfig.h index 013d86f0b00708..30b02be9b67d81 100644 --- a/examples/shell/genio/include/CHIPProjectConfig.h +++ b/examples/shell/genio/include/CHIPProjectConfig.h @@ -41,7 +41,6 @@ // including message encryption. Because of this they MUST NEVER BE ENABLED IN PRODUCTION BUILDS. // #define CHIP_CONFIG_SECURITY_TEST_MODE 0 -#define CHIP_CONFIG_REQUIRE_AUTH 1 /** * CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID diff --git a/examples/shell/nxp/k32w/k32w0/include/CHIPProjectConfig.h b/examples/shell/nxp/k32w/k32w0/include/CHIPProjectConfig.h index bcb7d017560dc2..f7ef2f6c352cce 100644 --- a/examples/shell/nxp/k32w/k32w0/include/CHIPProjectConfig.h +++ b/examples/shell/nxp/k32w/k32w0/include/CHIPProjectConfig.h @@ -38,9 +38,6 @@ #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 -// Use a default pairing code if one hasn't been provisioned in flash. -#define CHIP_DEVICE_CONFIG_USE_TEST_PAIRING_CODE "CHIPUS" - /** * CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER * diff --git a/examples/temperature-measurement-app/asr/include/CHIPProjectConfig.h b/examples/temperature-measurement-app/asr/include/CHIPProjectConfig.h index 00af1a3364eb3e..fbb3fbe96eca91 100755 --- a/examples/temperature-measurement-app/asr/include/CHIPProjectConfig.h +++ b/examples/temperature-measurement-app/asr/include/CHIPProjectConfig.h @@ -28,16 +28,6 @@ #pragma once -/** - * CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY - * - * Enables the use of a hard-coded default Chip device id and credentials if no device id - * is found in Chip NV storage. - * - * This option is for testing only and should be disabled in production releases. - */ -#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 37 - // Use a default pairing code if one hasn't been provisioned in flash. #ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 diff --git a/examples/thermostat/asr/include/CHIPProjectConfig.h b/examples/thermostat/asr/include/CHIPProjectConfig.h index 00af1a3364eb3e..fbb3fbe96eca91 100755 --- a/examples/thermostat/asr/include/CHIPProjectConfig.h +++ b/examples/thermostat/asr/include/CHIPProjectConfig.h @@ -28,16 +28,6 @@ #pragma once -/** - * CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY - * - * Enables the use of a hard-coded default Chip device id and credentials if no device id - * is found in Chip NV storage. - * - * This option is for testing only and should be disabled in production releases. - */ -#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 37 - // Use a default pairing code if one hasn't been provisioned in flash. #ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE #define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 From 7e3c820fb391d8bdf0909a6e116092eee0f9982a Mon Sep 17 00:00:00 2001 From: mideayanghui <106149377+mideayanghui@users.noreply.github.com> Date: Sat, 26 Aug 2023 22:34:40 +0800 Subject: [PATCH 6/8] update cluster-revision in thermostat cluster (#28908) --- .../all-clusters-app.matter | 2 +- .../all-clusters-common/all-clusters-app.zap | 10 +++---- .../rootnode_thermostat_bm3fb8dhYi.matter | 2 +- .../rootnode_thermostat_bm3fb8dhYi.zap | 30 +++++++++---------- .../thermostat-common/thermostat.matter | 2 +- .../thermostat-common/thermostat.zap | 30 +++++++++---------- 6 files changed, 38 insertions(+), 38 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 13caede03b2814..693491520da45e 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 @@ -7050,7 +7050,7 @@ endpoint 1 { callback attribute acceptedCommandList; callback attribute attributeList; ram attribute featureMap default = 0x0023; - ram attribute clusterRevision default = 5; + ram attribute clusterRevision default = 6; } server cluster FanControl { diff --git a/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap b/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap index 9ab2cbb930fb48..6a05673a0de74e 100644 --- a/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap +++ b/examples/all-clusters-app/all-clusters-common/all-clusters-app.zap @@ -33,7 +33,7 @@ ], "endpointTypes": [ { - "id": 13, + "id": 1, "name": "MA-rootdevice", "deviceTypeRef": { "id": 3, @@ -10512,7 +10512,7 @@ ] }, { - "id": 14, + "id": 2, "name": "MA-onofflight", "deviceTypeRef": { "id": 8, @@ -21228,7 +21228,7 @@ "storageOption": "RAM", "singleton": 0, "bounded": 0, - "defaultValue": "5", + "defaultValue": "6", "reportable": 1, "minInterval": 0, "maxInterval": 65344, @@ -30613,7 +30613,7 @@ ] }, { - "id": 15, + "id": 3, "name": "MA-onofflight", "deviceTypeRef": { "id": 8, @@ -34897,7 +34897,7 @@ ] }, { - "id": 16, + "id": 4, "name": "Anonymous Endpoint Type", "deviceTypeRef": { "id": 53, diff --git a/examples/chef/devices/rootnode_thermostat_bm3fb8dhYi.matter b/examples/chef/devices/rootnode_thermostat_bm3fb8dhYi.matter index be7bf99502b438..93b04f141025b3 100644 --- a/examples/chef/devices/rootnode_thermostat_bm3fb8dhYi.matter +++ b/examples/chef/devices/rootnode_thermostat_bm3fb8dhYi.matter @@ -1686,7 +1686,7 @@ endpoint 1 { callback attribute acceptedCommandList default = 0; callback attribute attributeList default = 0; ram attribute featureMap default = 0x3f; - ram attribute clusterRevision default = 3; + ram attribute clusterRevision default = 6; } server cluster ThermostatUserInterfaceConfiguration { diff --git a/examples/chef/devices/rootnode_thermostat_bm3fb8dhYi.zap b/examples/chef/devices/rootnode_thermostat_bm3fb8dhYi.zap index c296ec43258019..22f3247af489bf 100644 --- a/examples/chef/devices/rootnode_thermostat_bm3fb8dhYi.zap +++ b/examples/chef/devices/rootnode_thermostat_bm3fb8dhYi.zap @@ -16,6 +16,12 @@ } ], "package": [ + { + "pathRelativity": "relativeToZap", + "path": "../../../src/app/zap-templates/app-templates.json", + "type": "gen-templates-json", + "version": "chip-v1" + }, { "pathRelativity": "relativeToZap", "path": "../../../src/app/zap-templates/zcl/zcl.json", @@ -23,20 +29,14 @@ "category": "matter", "version": 1, "description": "Matter SDK ZCL data" - }, - { - "pathRelativity": "relativeToZap", - "path": "../../../src/app/zap-templates/app-templates.json", - "type": "gen-templates-json", - "version": "chip-v1" } ], "endpointTypes": [ { - "id": 2, + "id": 7, "name": "MA-rootdevice", "deviceTypeRef": { - "id": 2, + "id": 55, "code": 22, "profileId": 259, "label": "MA-rootdevice", @@ -44,7 +44,7 @@ }, "deviceTypes": [ { - "id": 2, + "id": 55, "code": 22, "profileId": 259, "label": "MA-rootdevice", @@ -52,7 +52,7 @@ } ], "deviceTypeRefs": [ - 2 + 55 ], "deviceVersions": [ 1 @@ -5468,10 +5468,10 @@ ] }, { - "id": 1, + "id": 8, "name": "Anonymous Endpoint Type", "deviceTypeRef": { - "id": 34, + "id": 87, "code": 769, "profileId": 259, "label": "MA-thermostat", @@ -5479,7 +5479,7 @@ }, "deviceTypes": [ { - "id": 34, + "id": 87, "code": 769, "profileId": 259, "label": "MA-thermostat", @@ -5487,7 +5487,7 @@ } ], "deviceTypeRefs": [ - 34 + 87 ], "deviceVersions": [ 1 @@ -7523,7 +7523,7 @@ "storageOption": "RAM", "singleton": 0, "bounded": 0, - "defaultValue": "3", + "defaultValue": "6", "reportable": 1, "minInterval": 1, "maxInterval": 65534, diff --git a/examples/thermostat/thermostat-common/thermostat.matter b/examples/thermostat/thermostat-common/thermostat.matter index 05c0e0d8e2b08c..67be1476e76796 100644 --- a/examples/thermostat/thermostat-common/thermostat.matter +++ b/examples/thermostat/thermostat-common/thermostat.matter @@ -1993,7 +1993,7 @@ endpoint 1 { callback attribute acceptedCommandList; callback attribute attributeList; ram attribute featureMap default = 0x23; - ram attribute clusterRevision default = 5; + ram attribute clusterRevision default = 6; } server cluster ThermostatUserInterfaceConfiguration { diff --git a/examples/thermostat/thermostat-common/thermostat.zap b/examples/thermostat/thermostat-common/thermostat.zap index b15be332da2516..0a6a637d51fb2a 100644 --- a/examples/thermostat/thermostat-common/thermostat.zap +++ b/examples/thermostat/thermostat-common/thermostat.zap @@ -16,6 +16,12 @@ } ], "package": [ + { + "pathRelativity": "relativeToZap", + "path": "../../../src/app/zap-templates/app-templates.json", + "type": "gen-templates-json", + "version": "chip-v1" + }, { "pathRelativity": "relativeToZap", "path": "../../../src/app/zap-templates/zcl/zcl.json", @@ -23,20 +29,14 @@ "category": "matter", "version": 1, "description": "Matter SDK ZCL data" - }, - { - "pathRelativity": "relativeToZap", - "path": "../../../src/app/zap-templates/app-templates.json", - "type": "gen-templates-json", - "version": "chip-v1" } ], "endpointTypes": [ { - "id": 1, + "id": 5, "name": "MA-rootdevice", "deviceTypeRef": { - "id": 2, + "id": 55, "code": 22, "profileId": 259, "label": "MA-rootdevice", @@ -44,7 +44,7 @@ }, "deviceTypes": [ { - "id": 2, + "id": 55, "code": 22, "profileId": 259, "label": "MA-rootdevice", @@ -52,7 +52,7 @@ } ], "deviceTypeRefs": [ - 2 + 55 ], "deviceVersions": [ 1 @@ -7655,10 +7655,10 @@ ] }, { - "id": 2, + "id": 6, "name": "MA-thermostat", "deviceTypeRef": { - "id": 34, + "id": 87, "code": 769, "profileId": 259, "label": "MA-thermostat", @@ -7666,7 +7666,7 @@ }, "deviceTypes": [ { - "id": 34, + "id": 87, "code": 769, "profileId": 259, "label": "MA-thermostat", @@ -7674,7 +7674,7 @@ } ], "deviceTypeRefs": [ - 34 + 87 ], "deviceVersions": [ 1 @@ -11678,7 +11678,7 @@ "storageOption": "RAM", "singleton": 0, "bounded": 0, - "defaultValue": "5", + "defaultValue": "6", "reportable": 1, "minInterval": 0, "maxInterval": 65344, From 2d5fe2ce434f5d0f7714d55e67914e3e8ebf5827 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Sat, 26 Aug 2023 10:36:54 -0400 Subject: [PATCH 7/8] Split JSON log tracing line by line for better alignment (#28897) * Better tracing (split log lines, make decoder resilient, fix protocol typo * Restyle * Fix more list formats --------- Co-authored-by: Andrei Litvin --- .../matter_chip_tool_adapter/decoder.py | 2 +- src/lib/format/protocol_messages.matter | 8 ++++---- src/tracing/json/json_tracing.cpp | 11 ++++++++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/examples/chip-tool/py_matter_chip_tool_adapter/matter_chip_tool_adapter/decoder.py b/examples/chip-tool/py_matter_chip_tool_adapter/matter_chip_tool_adapter/decoder.py index 0ee564203ba86a..ec9b4702de0a3d 100644 --- a/examples/chip-tool/py_matter_chip_tool_adapter/matter_chip_tool_adapter/decoder.py +++ b/examples/chip-tool/py_matter_chip_tool_adapter/matter_chip_tool_adapter/decoder.py @@ -133,7 +133,7 @@ def __init__(self, log): base64_message = log["message"].encode('utf-8') decoded_message_bytes = base64.b64decode(base64_message) # TODO We do assume utf-8 encoding is used, it may not be true though. - self.message = decoded_message_bytes.decode('utf-8') + self.message = decoded_message_bytes.decode('utf-8', 'replace') def decode_logs(logs): return list(map(MatterLog, logs)) diff --git a/src/lib/format/protocol_messages.matter b/src/lib/format/protocol_messages.matter index 786c50d85dffb0..30ffa0e1d7704e 100644 --- a/src/lib/format/protocol_messages.matter +++ b/src/lib/format/protocol_messages.matter @@ -174,12 +174,12 @@ client cluster IMProtocol = 0xFFFF0001 { boolean keep_subscriptions = 0; int16u min_minterval_floor = 1; int16u max_minterval_ceiling = 2; - optional AttributePathIB attribute_requests = 3; - optional EventPathIB event_requests = 4; - optional EventFilterIB event_filters = 5; + optional AttributePathIB attribute_requests[] = 3; + optional EventPathIB event_requests[] = 4; + optional EventFilterIB event_filters[] = 5; // NOTE: 6 is missing here ... boolean fabric_filtered = 7; - optional DataVersionFilterIB data_version_filters = 8; + optional DataVersionFilterIB data_version_filters[] = 8; // 10.2.2.2. Context Tag Encoded Action Information int8u interaction_model_revison = 0xFF; diff --git a/src/tracing/json/json_tracing.cpp b/src/tracing/json/json_tracing.cpp index 9750378df29ea7..204ca8fa742aa6 100644 --- a/src/tracing/json/json_tracing.cpp +++ b/src/tracing/json/json_tracing.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -444,7 +445,15 @@ void JsonBackend::OutputValue(::Json::Value & value) { std::stringstream output; writer->write(value, &output); - ChipLogProgress(Automation, "%s", output.str().c_str()); + // For pretty-printing, output each log line individually. + std::string data_string = output.str(); + chip::StringSplitter splitter(data_string.c_str(), '\n'); + + chip::CharSpan line; + while (splitter.Next(line)) + { + ChipLogProgress(Automation, "%.*s", static_cast(line.size()), line.data()); + } } } From 1084dd53d50b54e52cc0d91a0f39f84dc68b7039 Mon Sep 17 00:00:00 2001 From: Karsten Sperling <113487422+ksperling-apple@users.noreply.github.com> Date: Mon, 28 Aug 2023 21:15:43 +1200 Subject: [PATCH 8/8] Stop the SetupCodePairer when StopPairing is called (#28881) Prior to this change the SetupCodePairer was left running, and in particular its discovery timeout timer was not correctly cancelled. --- src/controller/CHIPDeviceController.cpp | 14 +++++++--- src/controller/SetUpCodePairer.cpp | 35 ++++++++++++++----------- src/controller/SetUpCodePairer.h | 14 +++++----- 3 files changed, 37 insertions(+), 26 deletions(-) diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index e37b058f7a67e4..ee2c36d8bd761e 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -477,7 +477,7 @@ void DeviceCommissioner::Shutdown() ChipLogDetail(Controller, "Shutting down the commissioner"); - mSetUpCodePairer.CommissionerShuttingDown(); + mSetUpCodePairer.StopPairing(); // Check to see if pairing in progress before shutting down CommissioneeDeviceProxy * device = mDeviceInPASEEstablishment; @@ -916,12 +916,18 @@ DeviceCommissioner::ContinueCommissioningAfterDeviceAttestation(DeviceProxy * de CHIP_ERROR DeviceCommissioner::StopPairing(NodeId remoteDeviceId) { VerifyOrReturnError(mState == State::Initialized, CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturnError(remoteDeviceId != kUndefinedNodeId, CHIP_ERROR_INVALID_ARGUMENT); + + bool stopped = mSetUpCodePairer.StopPairing(remoteDeviceId); CommissioneeDeviceProxy * device = FindCommissioneeDevice(remoteDeviceId); - VerifyOrReturnError(device != nullptr, CHIP_ERROR_INVALID_DEVICE_DESCRIPTOR); + if (device != nullptr) + { + ReleaseCommissioneeDevice(device); + stopped = true; + } - ReleaseCommissioneeDevice(device); - return CHIP_NO_ERROR; + return (stopped) ? CHIP_NO_ERROR : CHIP_ERROR_INVALID_DEVICE_DESCRIPTOR; } CHIP_ERROR DeviceCommissioner::UnpairDevice(NodeId remoteDeviceId) diff --git a/src/controller/SetUpCodePairer.cpp b/src/controller/SetUpCodePairer.cpp index e1ab5e778dd6df..db09d91fd74441 100644 --- a/src/controller/SetUpCodePairer.cpp +++ b/src/controller/SetUpCodePairer.cpp @@ -60,6 +60,7 @@ CHIP_ERROR SetUpCodePairer::PairDevice(NodeId remoteId, const char * setUpCode, DiscoveryType discoveryType, Optional resolutionData) { VerifyOrReturnError(mSystemLayer != nullptr, CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturnError(remoteId != kUndefinedNodeId, CHIP_ERROR_INVALID_ARGUMENT); SetupPayload payload; ReturnErrorOnFailure(GetPayload(setUpCode, payload)); @@ -405,9 +406,19 @@ void SetUpCodePairer::NotifyCommissionableDeviceDiscovered(const Dnssd::CommonRe ConnectToDiscoveredDevice(); } -void SetUpCodePairer::CommissionerShuttingDown() +bool SetUpCodePairer::StopPairing(NodeId remoteId) { + VerifyOrReturnValue(mRemoteId != kUndefinedNodeId, false); + VerifyOrReturnValue(remoteId == kUndefinedNodeId || remoteId == mRemoteId, false); + + if (mWaitingForPASE) + { + PASEEstablishmentComplete(); + } + ResetDiscoveryState(); + mRemoteId = kUndefinedNodeId; + return true; } bool SetUpCodePairer::TryNextRendezvousParameters() @@ -452,32 +463,26 @@ void SetUpCodePairer::ResetDiscoveryState() waiting = false; } - while (!mDiscoveredParameters.empty()) - { - mDiscoveredParameters.pop_front(); - } - + mDiscoveredParameters.clear(); mCurrentPASEParameters.ClearValue(); mLastPASEError = CHIP_NO_ERROR; + + mSystemLayer->CancelTimer(OnDeviceDiscoveredTimeoutCallback, this); } void SetUpCodePairer::ExpectPASEEstablishment() { + VerifyOrDie(!mWaitingForPASE); mWaitingForPASE = true; auto * delegate = mCommissioner->GetPairingDelegate(); - if (this == delegate) - { - // This should really not happen, but if it does, do nothing, to avoid - // delegate loops. - return; - } - + VerifyOrDie(delegate != this); mPairingDelegate = delegate; mCommissioner->RegisterPairingDelegate(this); } void SetUpCodePairer::PASEEstablishmentComplete() { + VerifyOrDie(mWaitingForPASE); mWaitingForPASE = false; mCommissioner->RegisterPairingDelegate(mPairingDelegate); mPairingDelegate = nullptr; @@ -524,9 +529,9 @@ void SetUpCodePairer::OnPairingComplete(CHIP_ERROR error) if (CHIP_NO_ERROR == error) { - mSystemLayer->CancelTimer(OnDeviceDiscoveredTimeoutCallback, this); - + ChipLogProgress(Controller, "Pairing with commissionee successful, stopping discovery"); ResetDiscoveryState(); + mRemoteId = kUndefinedNodeId; if (pairingDelegate != nullptr) { pairingDelegate->OnPairingComplete(error); diff --git a/src/controller/SetUpCodePairer.h b/src/controller/SetUpCodePairer.h index 04177ec313182a..f9dc542f4258a0 100644 --- a/src/controller/SetUpCodePairer.h +++ b/src/controller/SetUpCodePairer.h @@ -76,7 +76,7 @@ enum class DiscoveryType : uint8_t class DLL_EXPORT SetUpCodePairer : public DevicePairingDelegate { public: - SetUpCodePairer(DeviceCommissioner * commissioner) : mCommissioner(commissioner) { ResetDiscoveryState(); } + SetUpCodePairer(DeviceCommissioner * commissioner) : mCommissioner(commissioner) {} virtual ~SetUpCodePairer() {} CHIP_ERROR PairDevice(chip::NodeId remoteId, const char * setUpCode, @@ -93,9 +93,9 @@ class DLL_EXPORT SetUpCodePairer : public DevicePairingDelegate void SetBleLayer(Ble::BleLayer * bleLayer) { mBleLayer = bleLayer; }; #endif // CONFIG_NETWORK_LAYER_BLE - // Called to notify us that the DeviceCommissioner is shutting down and we - // should not try to do any more new work. - void CommissionerShuttingDown(); + // Stop ongoing discovery / pairing of the specified node, or of + // whichever node we're pairing if kUndefinedNodeId is passed. + bool StopPairing(NodeId remoteId = kUndefinedNodeId); private: // DevicePairingDelegate implementation. @@ -177,9 +177,9 @@ class DLL_EXPORT SetUpCodePairer : public DevicePairingDelegate uint16_t mPayloadVendorID = kNotAvailable; uint16_t mPayloadProductID = kNotAvailable; - DeviceCommissioner * mCommissioner = nullptr; - System::Layer * mSystemLayer = nullptr; - chip::NodeId mRemoteId; + DeviceCommissioner * mCommissioner = nullptr; + System::Layer * mSystemLayer = nullptr; + chip::NodeId mRemoteId = kUndefinedNodeId; uint32_t mSetUpPINCode = 0; SetupCodePairerBehaviour mConnectionType = SetupCodePairerBehaviour::kCommission; DiscoveryType mDiscoveryType = DiscoveryType::kAll;