diff --git a/examples/java-matter-controller/BUILD.gn b/examples/java-matter-controller/BUILD.gn index 83aea5b0e000ff..76eb438d5377a2 100644 --- a/examples/java-matter-controller/BUILD.gn +++ b/examples/java-matter-controller/BUILD.gn @@ -36,29 +36,6 @@ java_library("java") { "java/src/com/matter/controller/commands/common/IPAddress.java", "java/src/com/matter/controller/commands/common/MatterCommand.java", "java/src/com/matter/controller/commands/common/RealResult.java", - "java/src/com/matter/controller/commands/pairing/CloseSessionCommand.java", - "java/src/com/matter/controller/commands/pairing/DiscoveryFilterType.java", - "java/src/com/matter/controller/commands/pairing/PairAddressPaseCommand.java", - "java/src/com/matter/controller/commands/pairing/PairAlreadyDiscoveredCommand.java", - "java/src/com/matter/controller/commands/pairing/PairCodeCommand.java", - "java/src/com/matter/controller/commands/pairing/PairCodePaseCommand.java", - "java/src/com/matter/controller/commands/pairing/PairCodeThreadCommand.java", - "java/src/com/matter/controller/commands/pairing/PairCodeWifiCommand.java", - "java/src/com/matter/controller/commands/pairing/PairOnNetworkCommand.java", - "java/src/com/matter/controller/commands/pairing/PairOnNetworkCommissionerCommand.java", - "java/src/com/matter/controller/commands/pairing/PairOnNetworkCommissioningModeCommand.java", - "java/src/com/matter/controller/commands/pairing/PairOnNetworkDeviceTypeCommand.java", - "java/src/com/matter/controller/commands/pairing/PairOnNetworkFabricCommand.java", - "java/src/com/matter/controller/commands/pairing/PairOnNetworkInstanceNameCommand.java", - "java/src/com/matter/controller/commands/pairing/PairOnNetworkLongCommand.java", - "java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImInvokeCommand.java", - "java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImWriteCommand.java", - "java/src/com/matter/controller/commands/pairing/PairOnNetworkShortCommand.java", - "java/src/com/matter/controller/commands/pairing/PairOnNetworkVendorCommand.java", - "java/src/com/matter/controller/commands/pairing/PairingCommand.java", - "java/src/com/matter/controller/commands/pairing/PairingModeType.java", - "java/src/com/matter/controller/commands/pairing/PairingNetworkType.java", - "java/src/com/matter/controller/commands/pairing/UnpairCommand.java", ] javac_flags = [ "-Xlint:deprecation" ] @@ -76,6 +53,29 @@ kotlin_binary("java-matter-controller") { "java/src/com/matter/controller/commands/discover/DiscoverCommand.kt", "java/src/com/matter/controller/commands/discover/DiscoverCommissionablesCommand.kt", "java/src/com/matter/controller/commands/discover/DiscoverCommissionersCommand.kt", + "java/src/com/matter/controller/commands/pairing/CloseSessionCommand.kt", + "java/src/com/matter/controller/commands/pairing/DiscoveryFilterType.kt", + "java/src/com/matter/controller/commands/pairing/PairAddressPaseCommand.kt", + "java/src/com/matter/controller/commands/pairing/PairAlreadyDiscoveredCommand.kt", + "java/src/com/matter/controller/commands/pairing/PairCodeCommand.kt", + "java/src/com/matter/controller/commands/pairing/PairCodePaseCommand.kt", + "java/src/com/matter/controller/commands/pairing/PairCodeThreadCommand.kt", + "java/src/com/matter/controller/commands/pairing/PairCodeWifiCommand.kt", + "java/src/com/matter/controller/commands/pairing/PairOnNetworkCommand.kt", + "java/src/com/matter/controller/commands/pairing/PairOnNetworkCommissionerCommand.kt", + "java/src/com/matter/controller/commands/pairing/PairOnNetworkCommissioningModeCommand.kt", + "java/src/com/matter/controller/commands/pairing/PairOnNetworkDeviceTypeCommand.kt", + "java/src/com/matter/controller/commands/pairing/PairOnNetworkFabricCommand.kt", + "java/src/com/matter/controller/commands/pairing/PairOnNetworkInstanceNameCommand.kt", + "java/src/com/matter/controller/commands/pairing/PairOnNetworkLongCommand.kt", + "java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImInvokeCommand.kt", + "java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImWriteCommand.kt", + "java/src/com/matter/controller/commands/pairing/PairOnNetworkShortCommand.kt", + "java/src/com/matter/controller/commands/pairing/PairOnNetworkVendorCommand.kt", + "java/src/com/matter/controller/commands/pairing/PairingCommand.kt", + "java/src/com/matter/controller/commands/pairing/PairingModeType.kt", + "java/src/com/matter/controller/commands/pairing/PairingNetworkType.kt", + "java/src/com/matter/controller/commands/pairing/UnpairCommand.kt", ] kotlinc_flags = [ "-Xlint:deprecation" ] diff --git a/examples/java-matter-controller/java/src/com/matter/controller/Main.kt b/examples/java-matter-controller/java/src/com/matter/controller/Main.kt index 49cbea1ae65794..3aad410c3ddbf1 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/Main.kt +++ b/examples/java-matter-controller/java/src/com/matter/controller/Main.kt @@ -81,11 +81,13 @@ fun main(args: Array) { commandManager.register("discover", getDiscoveryCommands(controller, credentialsIssuer)) commandManager.register("pairing", getPairingCommands(controller, credentialsIssuer)) commandManager.register("im", getImCommands(controller, credentialsIssuer)) + try { commandManager.run(args) } catch (e: Exception) { println("Run command failed with exception: " + e.message) System.exit(1) } + controller.shutdownCommissioning() } diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/common/Command.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/common/Command.java index fe33e2459c2c31..cca9fc6c384918 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/common/Command.java +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/common/Command.java @@ -156,6 +156,22 @@ public final void addArgument( addArgumentToList(arg, optional); } + /** + * @brief Add a long Integer command argument + * @param name The name that will be displayed in the command help + * @param min The minimum value of the argv value + * @param max The minimum value of the argv value + * @param out A pointer to a MutableInteger where the argv value will be stored + * @param desc The description of the argument that will be displayed in the command help + * @param optional Indicate if an optional argument + * @return The number of arguments currently added to the command + */ + public final void addArgument( + String name, short min, short max, AtomicLong out, @Nullable String desc, boolean optional) { + Argument arg = new Argument(name, min, max, out, desc, optional); + addArgumentToList(arg, optional); + } + /** * @brief Add a long Integer command argument * @param name The name that will be displayed in the command help diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommissionablesCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommissionablesCommand.kt index 6eef21ba8c01e0..8475510b433d01 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommissionablesCommand.kt +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/discover/DiscoverCommissionablesCommand.kt @@ -23,13 +23,9 @@ import com.matter.controller.commands.common.CredentialsIssuer import com.matter.controller.commands.common.MatterCommand import java.util.concurrent.TimeUnit -private const val MAX_DISCOVERED_DEVICES = 10 -private const val TIME_TO_WAIT_FOR_RESULTS_SECONDS = 7L - class DiscoverCommissionablesCommand( controller: ChipDeviceController, credsIssuer: CredentialsIssuer? ) : MatterCommand(controller, "commissionables", credsIssuer) { - override fun runCommand() { currentCommissioner().discoverCommissionableNodes() @@ -55,4 +51,9 @@ class DiscoverCommissionablesCommand( System.out.format("\tDiscriminator: %d", device.discriminator) System.out.format("\tIP Address : %s%n", device.ipAddress) } + + companion object { + private const val MAX_DISCOVERED_DEVICES = 10 + private const val TIME_TO_WAIT_FOR_RESULTS_SECONDS = 7L + } } diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/CloseSessionCommand.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/CloseSessionCommand.java deleted file mode 100644 index f8b911217594ec..00000000000000 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/CloseSessionCommand.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2022 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.controller.commands.pairing; - -import chip.devicecontroller.ChipDeviceController; -import com.matter.controller.commands.common.CredentialsIssuer; -import com.matter.controller.commands.common.MatterCommand; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicLong; - -public final class CloseSessionCommand extends MatterCommand { - private final AtomicLong mDestinationId = new AtomicLong(); - private final AtomicInteger mTimeoutSecs = new AtomicInteger(); - - public CloseSessionCommand(ChipDeviceController controller, CredentialsIssuer credsIssuer) { - super(controller, "close-session", credsIssuer); - addArgument("destination-id", 0, Long.MAX_VALUE, mDestinationId, null, false); - addArgument( - "timeout", - (short) 0, - Short.MAX_VALUE, - mTimeoutSecs, - "Time, in seconds, before this command is considered to have timed out.", - false); - } - - @Override - protected final void runCommand() {} -} diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/CloseSessionCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/CloseSessionCommand.kt new file mode 100644 index 00000000000000..60fd5ef3bf86ea --- /dev/null +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/CloseSessionCommand.kt @@ -0,0 +1,42 @@ +/* + * 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.controller.commands.pairing + +import chip.devicecontroller.ChipDeviceController +import com.matter.controller.commands.common.CredentialsIssuer +import com.matter.controller.commands.common.MatterCommand +import java.util.concurrent.atomic.AtomicInteger +import java.util.concurrent.atomic.AtomicLong + +class CloseSessionCommand(controller: ChipDeviceController, credsIssuer: CredentialsIssuer?) : + MatterCommand(controller, "close-session", credsIssuer) { + private val destinationId: AtomicLong = AtomicLong() + private val timeoutSecs: AtomicInteger = AtomicInteger() + + init { + addArgument("destination-id", 0, Long.MAX_VALUE, destinationId, null, false) + addArgument( + "timeout", 0.toShort(), Short.MAX_VALUE, + timeoutSecs, + "Time, in seconds, before this command is considered to have timed out.", + false + ) + } + + override fun runCommand() {} +} \ No newline at end of file diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/DiscoveryFilterType.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/DiscoveryFilterType.kt similarity index 80% rename from examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/DiscoveryFilterType.java rename to examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/DiscoveryFilterType.kt index 1d614eb5b462d2..055271dd275208 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/DiscoveryFilterType.java +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/DiscoveryFilterType.kt @@ -1,31 +1,30 @@ -/* - * Copyright (c) 2022 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.controller.commands.pairing; - -public enum DiscoveryFilterType { - NONE, - SHORT_DISCRIMINATOR, - LONG_DISCRIMINATOR, - VENDOR_ID, - DEVICE_TYPE, - COMMISSIONING_MODE, - INSTANCE_NAME, - COMMISSIONER, - COMPRESSED_FABRIC_ID, -} +/* + * 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.controller.commands.pairing + +enum class DiscoveryFilterType { + NONE, + SHORT_DISCRIMINATOR, + LONG_DISCRIMINATOR, + VENDOR_ID, + DEVICE_TYPE, + COMMISSIONING_MODE, + INSTANCE_NAME, + COMMISSIONER, + COMPRESSED_FABRIC_ID +} \ No newline at end of file diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairAddressPaseCommand.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairAddressPaseCommand.java deleted file mode 100644 index 29d4e2c58622a7..00000000000000 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairAddressPaseCommand.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.matter.controller.commands.pairing; - -import chip.devicecontroller.ChipDeviceController; -import com.matter.controller.commands.common.CredentialsIssuer; -import java.util.logging.Level; -import java.util.logging.Logger; - -public final class PairAddressPaseCommand extends PairingCommand { - private static Logger logger = Logger.getLogger(PairAddressPaseCommand.class.getName()); - - public PairAddressPaseCommand(ChipDeviceController controller, CredentialsIssuer credsIssue) { - super( - controller, - "address-paseonly", - PairingModeType.ADDRESS_PASE_ONLY, - PairingNetworkType.NONE, - credsIssue); - } - - @Override - public void onPairingComplete(int errorCode) { - logger.log(Level.INFO, "onPairingComplete with error code: " + errorCode); - if (errorCode == 0) { - setSuccess(); - } else { - setFailure("onPairingComplete failure"); - } - } - - @Override - protected void runCommand() { - currentCommissioner() - .establishPaseConnection( - getNodeId(), getRemoteAddr().getHostAddress(), getRemotePort(), getSetupPINCode()); - - currentCommissioner().setCompletionListener(this); - waitCompleteMs(getTimeoutMillis()); - } -} diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairAddressPaseCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairAddressPaseCommand.kt new file mode 100644 index 00000000000000..c8e643677e8a4d --- /dev/null +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairAddressPaseCommand.kt @@ -0,0 +1,56 @@ +/* + * 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.controller.commands.pairing + +import chip.devicecontroller.ChipDeviceController +import com.matter.controller.commands.common.CredentialsIssuer +import java.util.logging.Level +import java.util.logging.Logger + +class PairAddressPaseCommand(controller: ChipDeviceController, credsIssue: CredentialsIssuer?) : PairingCommand( + controller, + "address-paseonly", + credsIssue, + PairingModeType.ADDRESS_PASE_ONLY, + PairingNetworkType.NONE +) { + override fun onPairingComplete(errorCode: Int) { + logger.log(Level.INFO, "onPairingComplete with error code: $errorCode") + if (errorCode == 0) { + setSuccess() + } else { + setFailure("onPairingComplete failure") + } + } + + override fun runCommand() { + currentCommissioner() + .establishPaseConnection( + getNodeId(), + getRemoteAddr().getHostAddress(), + getRemotePort(), + getSetupPINCode() + ) + currentCommissioner().setCompletionListener(this) + waitCompleteMs(getTimeoutMillis()) + } + + companion object { + private val logger = Logger.getLogger(PairAddressPaseCommand::class.java.name) + } +} \ No newline at end of file diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairAlreadyDiscoveredCommand.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairAlreadyDiscoveredCommand.java deleted file mode 100644 index 259bc61629a630..00000000000000 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairAlreadyDiscoveredCommand.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.matter.controller.commands.pairing; - -import chip.devicecontroller.ChipDeviceController; -import com.matter.controller.commands.common.CredentialsIssuer; - -public final class PairAlreadyDiscoveredCommand extends PairingCommand { - public PairAlreadyDiscoveredCommand( - ChipDeviceController controller, CredentialsIssuer credsIssue) { - super( - controller, - "already-discovered", - PairingModeType.ALREADY_DISCOVERED, - PairingNetworkType.NONE, - credsIssue); - } - - @Override - protected void runCommand() { - currentCommissioner() - .pairDeviceWithAddress( - getNodeId(), - getRemoteAddr().getHostAddress(), - getRemotePort(), - getDiscriminator(), - getSetupPINCode(), - null); - currentCommissioner().setCompletionListener(this); - waitCompleteMs(getTimeoutMillis()); - } -} diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairAlreadyDiscoveredCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairAlreadyDiscoveredCommand.kt new file mode 100644 index 00000000000000..f638a2a0ca159c --- /dev/null +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairAlreadyDiscoveredCommand.kt @@ -0,0 +1,45 @@ +/* + * 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.controller.commands.pairing + +import chip.devicecontroller.ChipDeviceController +import com.matter.controller.commands.common.CredentialsIssuer + +class PairAlreadyDiscoveredCommand( + controller: ChipDeviceController, credsIssue: CredentialsIssuer? +) : PairingCommand( + controller, + "already-discovered", + credsIssue, + PairingModeType.ALREADY_DISCOVERED, + PairingNetworkType.NONE +) { + override fun runCommand() { + currentCommissioner() + .pairDeviceWithAddress( + getNodeId(), + getRemoteAddr().getHostAddress(), + getRemotePort(), + getDiscriminator(), + getSetupPINCode(), + null + ) + currentCommissioner().setCompletionListener(this) + waitCompleteMs(getTimeoutMillis()) + } +} \ No newline at end of file diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairCodeCommand.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairCodeCommand.java deleted file mode 100644 index a95237b1c89a1f..00000000000000 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairCodeCommand.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.matter.controller.commands.pairing; - -import chip.devicecontroller.ChipDeviceController; -import com.matter.controller.commands.common.CredentialsIssuer; - -public final class PairCodeCommand extends PairingCommand { - public PairCodeCommand(ChipDeviceController controller, CredentialsIssuer credsIssue) { - super(controller, "code", PairingModeType.CODE, PairingNetworkType.NONE, credsIssue); - } - - @Override - protected void runCommand() {} -} diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairCodeCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairCodeCommand.kt new file mode 100644 index 00000000000000..7f2bc51e5ffb4a --- /dev/null +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairCodeCommand.kt @@ -0,0 +1,26 @@ +/* + * 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.controller.commands.pairing + +import chip.devicecontroller.ChipDeviceController +import com.matter.controller.commands.common.CredentialsIssuer + +class PairCodeCommand(controller: ChipDeviceController, credsIssue: CredentialsIssuer?) : + PairingCommand(controller, "code", credsIssue, PairingModeType.CODE, PairingNetworkType.NONE) { + override fun runCommand() {} +} \ No newline at end of file diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairCodePaseCommand.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairCodePaseCommand.java deleted file mode 100644 index b56ce3a96b4b5a..00000000000000 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairCodePaseCommand.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.matter.controller.commands.pairing; - -import chip.devicecontroller.ChipDeviceController; -import com.matter.controller.commands.common.CredentialsIssuer; - -public final class PairCodePaseCommand extends PairingCommand { - public PairCodePaseCommand(ChipDeviceController controller, CredentialsIssuer credsIssue) { - super( - controller, - "code-paseonly", - PairingModeType.CODE_PASE_ONLY, - PairingNetworkType.NONE, - credsIssue); - } - - @Override - protected void runCommand() {} -} diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairCodePaseCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairCodePaseCommand.kt new file mode 100644 index 00000000000000..e4041b9648e5f1 --- /dev/null +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairCodePaseCommand.kt @@ -0,0 +1,31 @@ +/* + * 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.controller.commands.pairing + +import chip.devicecontroller.ChipDeviceController +import com.matter.controller.commands.common.CredentialsIssuer + +class PairCodePaseCommand(controller: ChipDeviceController, credsIssue: CredentialsIssuer?) : PairingCommand( + controller, + "code-paseonly", + credsIssue, + PairingModeType.CODE_PASE_ONLY, + PairingNetworkType.NONE +) { + override fun runCommand() {} +} \ No newline at end of file diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairCodeThreadCommand.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairCodeThreadCommand.java deleted file mode 100644 index 150ca17e8a42a9..00000000000000 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairCodeThreadCommand.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.matter.controller.commands.pairing; - -import chip.devicecontroller.ChipDeviceController; -import com.matter.controller.commands.common.CredentialsIssuer; - -public final class PairCodeThreadCommand extends PairingCommand { - public PairCodeThreadCommand(ChipDeviceController controller, CredentialsIssuer credsIssue) { - super(controller, "code-thread", PairingModeType.CODE, PairingNetworkType.THREAD, credsIssue); - } - - @Override - protected void runCommand() {} -} diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairCodeThreadCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairCodeThreadCommand.kt new file mode 100644 index 00000000000000..2cd822e32d467f --- /dev/null +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairCodeThreadCommand.kt @@ -0,0 +1,26 @@ +/* + * 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.controller.commands.pairing + +import chip.devicecontroller.ChipDeviceController +import com.matter.controller.commands.common.CredentialsIssuer + +class PairCodeThreadCommand(controller: ChipDeviceController, credsIssue: CredentialsIssuer?) : + PairingCommand(controller, "code-thread", credsIssue, PairingModeType.CODE, PairingNetworkType.THREAD) { + override fun runCommand() {} +} \ No newline at end of file diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairCodeWifiCommand.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairCodeWifiCommand.java deleted file mode 100644 index 2aa764026a3303..00000000000000 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairCodeWifiCommand.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.matter.controller.commands.pairing; - -import chip.devicecontroller.ChipDeviceController; -import com.matter.controller.commands.common.CredentialsIssuer; - -public final class PairCodeWifiCommand extends PairingCommand { - public PairCodeWifiCommand(ChipDeviceController controller, CredentialsIssuer credsIssue) { - super(controller, "code-wifi", PairingModeType.CODE, PairingNetworkType.WIFI, credsIssue); - } - - @Override - protected void runCommand() {} -} diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairCodeWifiCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairCodeWifiCommand.kt new file mode 100644 index 00000000000000..66f90fd7214cf9 --- /dev/null +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairCodeWifiCommand.kt @@ -0,0 +1,26 @@ +/* + * 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.controller.commands.pairing + +import chip.devicecontroller.ChipDeviceController +import com.matter.controller.commands.common.CredentialsIssuer + +class PairCodeWifiCommand(controller: ChipDeviceController, credsIssue: CredentialsIssuer?) : + PairingCommand(controller, "code-wifi", credsIssue, PairingModeType.CODE, PairingNetworkType.WIFI) { + override fun runCommand() {} +} \ No newline at end of file diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkCommand.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkCommand.java deleted file mode 100644 index de03adcd7e6850..00000000000000 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkCommand.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.matter.controller.commands.pairing; - -import chip.devicecontroller.ChipDeviceController; -import com.matter.controller.commands.common.CredentialsIssuer; - -public final class PairOnNetworkCommand extends PairingCommand { - public PairOnNetworkCommand(ChipDeviceController controller, CredentialsIssuer credsIssue) { - super(controller, "onnetwork", PairingModeType.ON_NETWORK, PairingNetworkType.NONE, credsIssue); - } - - @Override - protected void runCommand() {} -} diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkCommand.kt new file mode 100644 index 00000000000000..9c18eff8b9602f --- /dev/null +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkCommand.kt @@ -0,0 +1,26 @@ +/* + * 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.controller.commands.pairing + +import chip.devicecontroller.ChipDeviceController +import com.matter.controller.commands.common.CredentialsIssuer + +class PairOnNetworkCommand(controller: ChipDeviceController, credsIssue: CredentialsIssuer?) : + PairingCommand(controller, "onnetwork", credsIssue, PairingModeType.ON_NETWORK, PairingNetworkType.NONE) { + override fun runCommand() {} +} \ No newline at end of file diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkCommissionerCommand.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkCommissionerCommand.java deleted file mode 100644 index 2a737503d8e345..00000000000000 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkCommissionerCommand.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.matter.controller.commands.pairing; - -import chip.devicecontroller.ChipDeviceController; -import com.matter.controller.commands.common.CredentialsIssuer; - -public final class PairOnNetworkCommissionerCommand extends PairingCommand { - public PairOnNetworkCommissionerCommand( - ChipDeviceController controller, CredentialsIssuer credsIssue) { - super( - controller, - "onnetwork-commissioner", - PairingModeType.ON_NETWORK, - PairingNetworkType.NONE, - credsIssue, - DiscoveryFilterType.COMMISSIONER); - } - - @Override - protected void runCommand() {} -} diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkCommissionerCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkCommissionerCommand.kt new file mode 100644 index 00000000000000..618f032dd02917 --- /dev/null +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkCommissionerCommand.kt @@ -0,0 +1,34 @@ +/* + * 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.controller.commands.pairing + +import chip.devicecontroller.ChipDeviceController +import com.matter.controller.commands.common.CredentialsIssuer + +class PairOnNetworkCommissionerCommand( + controller: ChipDeviceController, credsIssue: CredentialsIssuer? +) : PairingCommand( + controller, + "onnetwork-commissioner", + credsIssue, + PairingModeType.ON_NETWORK, + PairingNetworkType.NONE, + DiscoveryFilterType.COMMISSIONER +) { + override fun runCommand() {} +} \ No newline at end of file diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkCommissioningModeCommand.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkCommissioningModeCommand.java deleted file mode 100644 index 62a3c14213bc86..00000000000000 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkCommissioningModeCommand.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.matter.controller.commands.pairing; - -import chip.devicecontroller.ChipDeviceController; -import com.matter.controller.commands.common.CredentialsIssuer; - -public final class PairOnNetworkCommissioningModeCommand extends PairingCommand { - public PairOnNetworkCommissioningModeCommand( - ChipDeviceController controller, CredentialsIssuer credsIssue) { - super( - controller, - "onnetwork-commissioning-mode", - PairingModeType.ON_NETWORK, - PairingNetworkType.NONE, - credsIssue, - DiscoveryFilterType.COMMISSIONING_MODE); - } - - @Override - protected void runCommand() {} -} diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkCommissioningModeCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkCommissioningModeCommand.kt new file mode 100644 index 00000000000000..2fd5b795052fc1 --- /dev/null +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkCommissioningModeCommand.kt @@ -0,0 +1,34 @@ +/* + * 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.controller.commands.pairing + +import chip.devicecontroller.ChipDeviceController +import com.matter.controller.commands.common.CredentialsIssuer + +class PairOnNetworkCommissioningModeCommand( + controller: ChipDeviceController, credsIssue: CredentialsIssuer? +) : PairingCommand( + controller, + "onnetwork-commissioning-mode", + credsIssue, + PairingModeType.ON_NETWORK, + PairingNetworkType.NONE, + DiscoveryFilterType.COMMISSIONING_MODE +) { + override fun runCommand() {} +} \ No newline at end of file diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkDeviceTypeCommand.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkDeviceTypeCommand.java deleted file mode 100644 index 5a16ae3daf908e..00000000000000 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkDeviceTypeCommand.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.matter.controller.commands.pairing; - -import chip.devicecontroller.ChipDeviceController; -import com.matter.controller.commands.common.CredentialsIssuer; - -public final class PairOnNetworkDeviceTypeCommand extends PairingCommand { - public PairOnNetworkDeviceTypeCommand( - ChipDeviceController controller, CredentialsIssuer credsIssue) { - super( - controller, - "onnetwork-device-type", - PairingModeType.ON_NETWORK, - PairingNetworkType.NONE, - credsIssue, - DiscoveryFilterType.DEVICE_TYPE); - } - - @Override - protected void runCommand() {} -} diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkDeviceTypeCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkDeviceTypeCommand.kt new file mode 100644 index 00000000000000..6a597c676a8918 --- /dev/null +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkDeviceTypeCommand.kt @@ -0,0 +1,34 @@ +/* + * 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.controller.commands.pairing + +import chip.devicecontroller.ChipDeviceController +import com.matter.controller.commands.common.CredentialsIssuer + +class PairOnNetworkDeviceTypeCommand( + controller: ChipDeviceController, credsIssue: CredentialsIssuer? +) : PairingCommand( + controller, + "onnetwork-device-type", + credsIssue, + PairingModeType.ON_NETWORK, + PairingNetworkType.NONE, + DiscoveryFilterType.DEVICE_TYPE +) { + override fun runCommand() {} +} \ No newline at end of file diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkFabricCommand.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkFabricCommand.java deleted file mode 100644 index c0db4cdc008f77..00000000000000 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkFabricCommand.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.matter.controller.commands.pairing; - -import chip.devicecontroller.ChipDeviceController; -import com.matter.controller.commands.common.CredentialsIssuer; -import java.net.UnknownHostException; - -public final class PairOnNetworkFabricCommand extends PairingCommand { - public PairOnNetworkFabricCommand(ChipDeviceController controller, CredentialsIssuer credsIssue) - throws UnknownHostException { - super( - controller, - "onnetwork-fabric", - PairingModeType.ON_NETWORK, - PairingNetworkType.NONE, - credsIssue, - DiscoveryFilterType.COMPRESSED_FABRIC_ID); - } - - @Override - protected void runCommand() {} -} diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkFabricCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkFabricCommand.kt new file mode 100644 index 00000000000000..1b08e74d689409 --- /dev/null +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkFabricCommand.kt @@ -0,0 +1,32 @@ +/* + * 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.controller.commands.pairing + +import chip.devicecontroller.ChipDeviceController +import com.matter.controller.commands.common.CredentialsIssuer + +class PairOnNetworkFabricCommand(controller: ChipDeviceController, credsIssue: CredentialsIssuer?) : PairingCommand( + controller, + "onnetwork-fabric", + credsIssue, + PairingModeType.ON_NETWORK, + PairingNetworkType.NONE, + DiscoveryFilterType.COMPRESSED_FABRIC_ID +) { + override fun runCommand() {} +} \ No newline at end of file diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkInstanceNameCommand.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkInstanceNameCommand.java deleted file mode 100644 index 45d91665dd3671..00000000000000 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkInstanceNameCommand.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.matter.controller.commands.pairing; - -import chip.devicecontroller.ChipDeviceController; -import com.matter.controller.commands.common.CredentialsIssuer; - -public final class PairOnNetworkInstanceNameCommand extends PairingCommand { - public PairOnNetworkInstanceNameCommand( - ChipDeviceController controller, CredentialsIssuer credsIssue) { - super( - controller, - "onnetwork-instance-name", - PairingModeType.ON_NETWORK, - PairingNetworkType.NONE, - credsIssue, - DiscoveryFilterType.INSTANCE_NAME); - } - - @Override - protected void runCommand() {} -} diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkInstanceNameCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkInstanceNameCommand.kt new file mode 100644 index 00000000000000..9b8d392050ddb4 --- /dev/null +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkInstanceNameCommand.kt @@ -0,0 +1,34 @@ +/* + * 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.controller.commands.pairing + +import chip.devicecontroller.ChipDeviceController +import com.matter.controller.commands.common.CredentialsIssuer + +class PairOnNetworkInstanceNameCommand( + controller: ChipDeviceController, credsIssue: CredentialsIssuer? +) : PairingCommand( + controller, + "onnetwork-instance-name", + credsIssue, + PairingModeType.ON_NETWORK, + PairingNetworkType.NONE, + DiscoveryFilterType.INSTANCE_NAME +) { + override fun runCommand() {} +} \ No newline at end of file diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongCommand.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongCommand.java deleted file mode 100644 index a75b36a991bd0a..00000000000000 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongCommand.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.matter.controller.commands.pairing; - -import chip.devicecontroller.ChipDeviceController; -import com.matter.controller.commands.common.CredentialsIssuer; - -public final class PairOnNetworkLongCommand extends PairingCommand { - private static final int MATTER_PORT = 5540; - - public PairOnNetworkLongCommand(ChipDeviceController controller, CredentialsIssuer credsIssue) { - super( - controller, - "onnetwork-long", - PairingModeType.ON_NETWORK, - PairingNetworkType.NONE, - credsIssue, - DiscoveryFilterType.LONG_DISCRIMINATOR); - } - - @Override - protected void runCommand() { - currentCommissioner() - .pairDeviceWithAddress( - getNodeId(), - getRemoteAddr().getHostAddress(), - MATTER_PORT, - getDiscriminator(), - getSetupPINCode(), - null); - currentCommissioner().setCompletionListener(this); - waitCompleteMs(getTimeoutMillis()); - } -} diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongCommand.kt new file mode 100644 index 00000000000000..04955082732378 --- /dev/null +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongCommand.kt @@ -0,0 +1,46 @@ +/* + * 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.controller.commands.pairing + +import chip.devicecontroller.ChipDeviceController +import com.matter.controller.commands.common.CredentialsIssuer + +private const val MATTER_PORT = 5540 + +class PairOnNetworkLongCommand(controller: ChipDeviceController, credsIssue: CredentialsIssuer?) : PairingCommand( + controller, + "onnetwork-long", + credsIssue, + PairingModeType.ON_NETWORK, + PairingNetworkType.NONE, + DiscoveryFilterType.LONG_DISCRIMINATOR +) { + override fun runCommand() { + currentCommissioner() + .pairDeviceWithAddress( + getNodeId(), + getRemoteAddr().getHostAddress(), + MATTER_PORT, + getDiscriminator(), + getSetupPINCode(), + null + ) + currentCommissioner().setCompletionListener(this) + waitCompleteMs(getTimeoutMillis()) + } +} \ No newline at end of file diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImInvokeCommand.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImInvokeCommand.java deleted file mode 100644 index 6195b8fff690fa..00000000000000 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImInvokeCommand.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.matter.controller.commands.pairing; - -import chip.devicecontroller.ChipDeviceController; -import chip.devicecontroller.GetConnectedDeviceCallbackJni.GetConnectedDeviceCallback; -import chip.devicecontroller.InvokeCallback; -import chip.devicecontroller.model.InvokeElement; -import com.matter.controller.commands.common.CredentialsIssuer; -import java.util.logging.Level; -import java.util.logging.Logger; - -public final class PairOnNetworkLongImInvokeCommand extends PairingCommand { - private static final Logger logger = - Logger.getLogger(PairOnNetworkLongImInvokeCommand.class.getName()); - private static final int MATTER_PORT = 5540; - private static final int CLUSTER_ID_IDENTIFY = 0x0003; - private static final int IDENTIFY_COMMAND = 0; - private long devicePointer; - - private void setDevicePointer(long devicePointer) { - this.devicePointer = devicePointer; - } - - private class InternalInvokeCallback implements InvokeCallback { - @Override - public void onError(Exception e) { - logger.log(Level.INFO, "Invoke receive onError" + e.getMessage()); - setFailure("write failure"); - } - - @Override - public void onResponse(InvokeElement element, long successCode) { - logger.log(Level.INFO, "Invoke receive OnResponse on "); - if (element != null) { - logger.log(Level.INFO, element.toString()); - } - logger.log(Level.INFO, "success code is" + String.valueOf(successCode)); - setSuccess(); - } - } - - private class InternalGetConnectedDeviceCallback implements GetConnectedDeviceCallback { - @Override - public void onDeviceConnected(long devicePointer) { - setDevicePointer(devicePointer); - logger.log(Level.INFO, "onDeviceConnected"); - } - - @Override - public void onConnectionFailure(long nodeId, Exception error) { - logger.log(Level.INFO, "onConnectionFailure"); - } - } - - public PairOnNetworkLongImInvokeCommand( - ChipDeviceController controller, CredentialsIssuer credsIssue) { - super( - controller, - "onnetwork-long-im-invoke", - PairingModeType.ON_NETWORK, - PairingNetworkType.NONE, - credsIssue, - DiscoveryFilterType.LONG_DISCRIMINATOR); - } - - @Override - protected void runCommand() { - // tlv structure with tag 0, unsigned integer 1 inside, {0: 1} - byte[] intTLV = {0x15, 0x24, 0x00, 0x01, 0x18}; - InvokeElement element = - InvokeElement.newInstance( - /* endpointId= */ 0, CLUSTER_ID_IDENTIFY, IDENTIFY_COMMAND, intTLV, null); - - currentCommissioner() - .pairDeviceWithAddress( - getNodeId(), - getRemoteAddr().getHostAddress(), - MATTER_PORT, - getDiscriminator(), - getSetupPINCode(), - null); - currentCommissioner().setCompletionListener(this); - waitCompleteMs(getTimeoutMillis()); - currentCommissioner() - .getConnectedDevicePointer(getNodeId(), new InternalGetConnectedDeviceCallback()); - clear(); - - currentCommissioner().invoke(new InternalInvokeCallback(), devicePointer, element, 0, 0); - - waitCompleteMs(getTimeoutMillis()); - } -} diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImInvokeCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImInvokeCommand.kt new file mode 100644 index 00000000000000..a3cfd72d94d1af --- /dev/null +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImInvokeCommand.kt @@ -0,0 +1,105 @@ +/* + * 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.controller.commands.pairing + +import chip.devicecontroller.ChipDeviceController +import chip.devicecontroller.GetConnectedDeviceCallbackJni.GetConnectedDeviceCallback +import chip.devicecontroller.InvokeCallback +import chip.devicecontroller.model.InvokeElement +import com.matter.controller.commands.common.CredentialsIssuer +import java.util.logging.Level +import java.util.logging.Logger + +class PairOnNetworkLongImInvokeCommand( + controller: ChipDeviceController, credsIssue: CredentialsIssuer? +) : PairingCommand( + controller, + "onnetwork-long-im-invoke", + credsIssue, + PairingModeType.ON_NETWORK, + PairingNetworkType.NONE, + DiscoveryFilterType.LONG_DISCRIMINATOR +) { + private var devicePointer: Long = 0 + private fun setDevicePointer(devicePointer: Long) { + this.devicePointer = devicePointer + } + + private inner class InternalInvokeCallback : InvokeCallback { + override fun onError(e: Exception) { + logger.log(Level.INFO, "Invoke receive onError" + e.message) + setFailure("write failure") + } + + override fun onResponse(element: InvokeElement?, successCode: Long) { + logger.log(Level.INFO, "Invoke receive OnResponse on ") + if (element != null) { + logger.log(Level.INFO, element.toString()) + } + logger.log(Level.INFO, "success code is$successCode") + setSuccess() + } + } + + private inner class InternalGetConnectedDeviceCallback : GetConnectedDeviceCallback { + override fun onDeviceConnected(devicePointer: Long) { + setDevicePointer(devicePointer) + logger.log(Level.INFO, "onDeviceConnected") + } + + override fun onConnectionFailure(nodeId: Long, error: Exception) { + logger.log(Level.INFO, "onConnectionFailure") + } + } + + override fun runCommand() { + // tlv structure with tag 0, unsigned integer 1 inside, {0: 1} + val intTLV = byteArrayOf(0x15, 0x24, 0x00, 0x01, 0x18) + + val element: InvokeElement = InvokeElement.newInstance( /* endpointId= */ + 0L, CLUSTER_ID_IDENTIFY, IDENTIFY_COMMAND, intTLV, null + ) + + currentCommissioner() + .pairDeviceWithAddress( + getNodeId(), + getRemoteAddr().getHostAddress(), + MATTER_PORT, + getDiscriminator(), + getSetupPINCode(), + null + ) + currentCommissioner().setCompletionListener(this) + waitCompleteMs(getTimeoutMillis()) + currentCommissioner() + .getConnectedDevicePointer(getNodeId(), InternalGetConnectedDeviceCallback()) + clear() + currentCommissioner().invoke(InternalInvokeCallback(), devicePointer, element, 0, 0) + waitCompleteMs(getTimeoutMillis()) + } + + companion object { + private val logger = Logger.getLogger( + PairOnNetworkLongImInvokeCommand::class.java.name + ) + + private const val MATTER_PORT = 5540 + private const val CLUSTER_ID_IDENTIFY = 0x0003L + private const val IDENTIFY_COMMAND = 0L + } +} \ No newline at end of file diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImWriteCommand.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImWriteCommand.java deleted file mode 100644 index f63b995610ec38..00000000000000 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImWriteCommand.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.matter.controller.commands.pairing; - -import chip.devicecontroller.ChipDeviceController; -import chip.devicecontroller.GetConnectedDeviceCallbackJni.GetConnectedDeviceCallback; -import chip.devicecontroller.WriteAttributesCallback; -import chip.devicecontroller.model.AttributeWriteRequest; -import chip.devicecontroller.model.ChipAttributePath; -import com.matter.controller.commands.common.CredentialsIssuer; -import java.util.ArrayList; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.annotation.Nullable; - -public final class PairOnNetworkLongImWriteCommand extends PairingCommand { - private static final int MATTER_PORT = 5540; - private long devicePointer; - private static final int CLUSTER_ID_BASIC = 0x0028; - private static final int ATTR_ID_LOCAL_CONFIG_DISABLED = 16; - private static Logger logger = Logger.getLogger(PairOnNetworkLongImWriteCommand.class.getName()); - - private void setDevicePointer(long devicePointer) { - this.devicePointer = devicePointer; - } - - private class InternalWriteAttributesCallback implements WriteAttributesCallback { - @Override - public void onError(@Nullable ChipAttributePath attributePath, Exception e) { - logger.log(Level.INFO, "Write receive onError on "); - if (attributePath != null) { - logger.log(Level.INFO, attributePath.toString()); - } - - setFailure("write failure"); - } - - @Override - public void onResponse(ChipAttributePath attributePath) { - logger.log(Level.INFO, "Write receve OnResponse on "); - if (attributePath != null) { - logger.log(Level.INFO, attributePath.toString()); - } - setSuccess(); - } - } - - private class InternalGetConnectedDeviceCallback implements GetConnectedDeviceCallback { - @Override - public void onDeviceConnected(long devicePointer) { - setDevicePointer(devicePointer); - logger.log(Level.INFO, "onDeviceConnected"); - } - - @Override - public void onConnectionFailure(long nodeId, Exception error) { - logger.log(Level.INFO, "onConnectionFailure"); - } - } - - public PairOnNetworkLongImWriteCommand( - ChipDeviceController controller, CredentialsIssuer credsIssue) { - super( - controller, - "onnetwork-long-im-write", - PairingModeType.ON_NETWORK, - PairingNetworkType.NONE, - credsIssue, - DiscoveryFilterType.LONG_DISCRIMINATOR); - } - - @Override - protected void runCommand() { - // boolean true for tlv - byte[] booleanTLV = {0x09}; - AttributeWriteRequest attribute = - AttributeWriteRequest.newInstance( - /* endpointId= */ 0, CLUSTER_ID_BASIC, ATTR_ID_LOCAL_CONFIG_DISABLED, booleanTLV); - ArrayList attributeList = new ArrayList<>(); - attributeList.add(attribute); - - currentCommissioner() - .pairDeviceWithAddress( - getNodeId(), - getRemoteAddr().getHostAddress(), - MATTER_PORT, - getDiscriminator(), - getSetupPINCode(), - null); - currentCommissioner().setCompletionListener(this); - waitCompleteMs(getTimeoutMillis()); - currentCommissioner() - .getConnectedDevicePointer(getNodeId(), new InternalGetConnectedDeviceCallback()); - clear(); - - currentCommissioner() - .write(new InternalWriteAttributesCallback(), devicePointer, attributeList, 0, 0); - - waitCompleteMs(getTimeoutMillis()); - } -} diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImWriteCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImWriteCommand.kt new file mode 100644 index 00000000000000..46f65fb39d1087 --- /dev/null +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkLongImWriteCommand.kt @@ -0,0 +1,111 @@ +/* + * 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.controller.commands.pairing + +import chip.devicecontroller.ChipDeviceController +import chip.devicecontroller.GetConnectedDeviceCallbackJni.GetConnectedDeviceCallback +import chip.devicecontroller.WriteAttributesCallback +import chip.devicecontroller.model.AttributeWriteRequest +import chip.devicecontroller.model.ChipAttributePath +import com.matter.controller.commands.common.CredentialsIssuer +import java.util.logging.Level +import java.util.logging.Logger +import javax.annotation.Nullable + +class PairOnNetworkLongImWriteCommand( + controller: ChipDeviceController, credsIssue: CredentialsIssuer? +) : PairingCommand( + controller, + "onnetwork-long-im-write", + credsIssue, + PairingModeType.ON_NETWORK, + PairingNetworkType.NONE, + DiscoveryFilterType.LONG_DISCRIMINATOR +) { + private var devicePointer: Long = 0 + + private inner class InternalWriteAttributesCallback : WriteAttributesCallback { + override fun onError(attributePath: ChipAttributePath?, e: Exception) { + logger.log(Level.INFO, "Write receive onError on ") + if (attributePath != null) { + logger.log(Level.INFO, attributePath.toString()) + } + setFailure("write failure") + } + + override fun onResponse(attributePath: ChipAttributePath?) { + logger.log(Level.INFO, "Write receve OnResponse on ") + if (attributePath != null) { + logger.log(Level.INFO, attributePath.toString()) + } + setSuccess() + } + } + + private inner class InternalGetConnectedDeviceCallback : GetConnectedDeviceCallback { + override fun onDeviceConnected(devicePointer: Long) { + this@PairOnNetworkLongImWriteCommand.devicePointer = devicePointer + logger.log(Level.INFO, "onDeviceConnected") + } + + override fun onConnectionFailure(nodeId: Long, error: Exception?) { + logger.log(Level.INFO, "onConnectionFailure") + } + } + + override fun runCommand() { + // boolean true for tlv + val booleanTLV = byteArrayOf(0x09) + val attributeList = listOf( + AttributeWriteRequest.newInstance( + /* endpointId= */ 0, + CLUSTER_ID_BASIC, + ATTR_ID_LOCAL_CONFIG_DISABLED, + booleanTLV, + ) + ) + + currentCommissioner() + .pairDeviceWithAddress( + getNodeId(), + getRemoteAddr().getHostAddress(), + MATTER_PORT, + getDiscriminator(), + getSetupPINCode(), + null + ) + currentCommissioner().setCompletionListener(this) + waitCompleteMs(getTimeoutMillis()) + currentCommissioner() + .getConnectedDevicePointer(getNodeId(), InternalGetConnectedDeviceCallback()) + clear() + currentCommissioner() + .write(InternalWriteAttributesCallback(), devicePointer, attributeList, 0, 0) + waitCompleteMs(getTimeoutMillis()) + } + + companion object { + private val logger = Logger.getLogger( + PairOnNetworkLongImWriteCommand::class.java.name + ) + + private const val MATTER_PORT = 5540 + private const val CLUSTER_ID_BASIC = 0x0028L + private const val ATTR_ID_LOCAL_CONFIG_DISABLED = 16L + } +} \ No newline at end of file diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkShortCommand.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkShortCommand.java deleted file mode 100644 index 135694632863d1..00000000000000 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkShortCommand.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.matter.controller.commands.pairing; - -import chip.devicecontroller.ChipDeviceController; -import com.matter.controller.commands.common.CredentialsIssuer; - -public final class PairOnNetworkShortCommand extends PairingCommand { - public PairOnNetworkShortCommand(ChipDeviceController controller, CredentialsIssuer credsIssue) { - super( - controller, - "onnetwork-short", - PairingModeType.ON_NETWORK, - PairingNetworkType.NONE, - credsIssue, - DiscoveryFilterType.SHORT_DISCRIMINATOR); - } - - @Override - protected void runCommand() {} -} diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkShortCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkShortCommand.kt new file mode 100644 index 00000000000000..ca294852776786 --- /dev/null +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkShortCommand.kt @@ -0,0 +1,32 @@ +/* + * 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.controller.commands.pairing + +import chip.devicecontroller.ChipDeviceController +import com.matter.controller.commands.common.CredentialsIssuer + +class PairOnNetworkShortCommand(controller: ChipDeviceController, credsIssue: CredentialsIssuer?) : PairingCommand( + controller, + "onnetwork-short", + credsIssue, + PairingModeType.ON_NETWORK, + PairingNetworkType.NONE, + DiscoveryFilterType.SHORT_DISCRIMINATOR +) { + override fun runCommand() {} +} \ No newline at end of file diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkVendorCommand.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkVendorCommand.java deleted file mode 100644 index 65bdfc57c3cd94..00000000000000 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkVendorCommand.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.matter.controller.commands.pairing; - -import chip.devicecontroller.ChipDeviceController; -import com.matter.controller.commands.common.CredentialsIssuer; - -public final class PairOnNetworkVendorCommand extends PairingCommand { - public PairOnNetworkVendorCommand(ChipDeviceController controller, CredentialsIssuer credsIssue) { - super( - controller, - "onnetwork-vendor", - PairingModeType.ON_NETWORK, - PairingNetworkType.NONE, - credsIssue, - DiscoveryFilterType.VENDOR_ID); - } - - @Override - protected void runCommand() {} -} diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkVendorCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkVendorCommand.kt new file mode 100644 index 00000000000000..6316bffb9057e1 --- /dev/null +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairOnNetworkVendorCommand.kt @@ -0,0 +1,32 @@ +/* + * 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.controller.commands.pairing + +import chip.devicecontroller.ChipDeviceController +import com.matter.controller.commands.common.CredentialsIssuer + +class PairOnNetworkVendorCommand(controller: ChipDeviceController, credsIssue: CredentialsIssuer?) : PairingCommand( + controller, + "onnetwork-vendor", + credsIssue, + PairingModeType.ON_NETWORK, + PairingNetworkType.NONE, + DiscoveryFilterType.VENDOR_ID +) { + override fun runCommand() {} +} \ No newline at end of file diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairingCommand.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairingCommand.java deleted file mode 100644 index 4aa95356a05f54..00000000000000 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairingCommand.java +++ /dev/null @@ -1,249 +0,0 @@ -/* - * Copyright (c) 2022 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.controller.commands.pairing; - -import chip.devicecontroller.ChipDeviceController; -import com.matter.controller.commands.common.CredentialsIssuer; -import com.matter.controller.commands.common.IPAddress; -import com.matter.controller.commands.common.MatterCommand; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicLong; -import java.util.logging.Level; -import java.util.logging.Logger; - -public abstract class PairingCommand extends MatterCommand - implements ChipDeviceController.CompletionListener { - private PairingModeType mPairingMode = PairingModeType.NONE; - private PairingNetworkType mNetworkType = PairingNetworkType.NONE; - private DiscoveryFilterType mFilterType = DiscoveryFilterType.NONE; - private final IPAddress mRemoteAddr; - private final AtomicLong mNodeId = new AtomicLong(); - private final AtomicLong mDiscoveryFilterCode = new AtomicLong(); - private final AtomicLong mTimeoutMillis = new AtomicLong(); - private final AtomicBoolean mDiscoverOnce = new AtomicBoolean(); - private final AtomicBoolean mUseOnlyOnNetworkDiscovery = new AtomicBoolean(); - private final AtomicInteger mRemotePort = new AtomicInteger(); - private final AtomicInteger mDiscriminator = new AtomicInteger(); - private final AtomicInteger mSetupPINCode = new AtomicInteger(); - private final StringBuffer mOperationalDataset = new StringBuffer(); - private final StringBuffer mSSID = new StringBuffer(); - private final StringBuffer mPassword = new StringBuffer(); - private final StringBuffer mOnboardingPayload = new StringBuffer(); - private final StringBuffer mDiscoveryFilterInstanceName = new StringBuffer(); - private static Logger logger = Logger.getLogger(PairingCommand.class.getName()); - - @Override - public void onConnectDeviceComplete() { - logger.log(Level.INFO, "onConnectDeviceComplete"); - } - - @Override - public void onStatusUpdate(int status) { - logger.log(Level.INFO, "onStatusUpdate with status: " + status); - } - - @Override - public void onPairingComplete(int errorCode) { - logger.log(Level.INFO, "onPairingComplete with error code: " + errorCode); - if (errorCode != 0) { - setFailure("onPairingComplete failure"); - } - } - - @Override - public void onPairingDeleted(int errorCode) { - logger.log(Level.INFO, "onPairingDeleted with error code: " + errorCode); - } - - @Override - public void onCommissioningComplete(long nodeId, int errorCode) { - logger.log(Level.INFO, "onCommissioningComplete with error code: " + errorCode); - if (errorCode == 0) { - setSuccess(); - } else { - setFailure("onCommissioningComplete failure"); - } - } - - @Override - public void onReadCommissioningInfo( - int vendorId, int productId, int wifiEndpointId, int threadEndpointId) { - logger.log(Level.INFO, "onReadCommissioningInfo"); - } - - @Override - public void onCommissioningStatusUpdate(long nodeId, String stage, int errorCode) { - logger.log(Level.INFO, "onCommissioningStatusUpdate"); - } - - @Override - public void onNotifyChipConnectionClosed() { - logger.log(Level.INFO, "onNotifyChipConnectionClosed"); - } - - @Override - public void onCloseBleComplete() { - logger.log(Level.INFO, "onCloseBleComplete"); - } - - @Override - public void onError(Throwable error) { - setFailure(error.toString()); - logger.log(Level.INFO, "onError with error: " + error.toString()); - } - - @Override - public void onOpCSRGenerationComplete(byte[] csr) { - logger.log(Level.INFO, "onOpCSRGenerationComplete"); - for (int i = 0; i < csr.length; i++) { - System.out.print(csr[i] + " "); - } - } - - public long getNodeId() { - return mNodeId.get(); - } - - public IPAddress getRemoteAddr() { - return mRemoteAddr; - } - - public int getRemotePort() { - return mRemotePort.get(); - } - - public int getSetupPINCode() { - return mSetupPINCode.get(); - } - - public int getDiscriminator() { - return mDiscriminator.get(); - } - - public long getTimeoutMillis() { - return mTimeoutMillis.get(); - } - - public PairingCommand( - ChipDeviceController controller, - String commandName, - PairingModeType mode, - PairingNetworkType networkType, - CredentialsIssuer credsIssuer) { - this(controller, commandName, mode, networkType, credsIssuer, DiscoveryFilterType.NONE); - } - - public PairingCommand( - ChipDeviceController controller, - String commandName, - PairingModeType mode, - PairingNetworkType networkType, - CredentialsIssuer credsIssuer, - DiscoveryFilterType filterType) { - super(controller, commandName, credsIssuer); - this.mPairingMode = mode; - this.mNetworkType = networkType; - this.mFilterType = filterType; - - try { - this.mRemoteAddr = new IPAddress(InetAddress.getByName("::1")); - } catch (UnknownHostException e) { - throw new RuntimeException(e); - } - - addArgument("node-id", 0, Long.MAX_VALUE, mNodeId, null, false); - - switch (networkType) { - case NONE: - break; - case WIFI: - addArgument("ssid", mSSID, null, false); - addArgument("password", mPassword, null, false); - break; - case THREAD: - addArgument("operationalDataset", mOperationalDataset, null, false); - break; - } - - switch (mode) { - case NONE: - break; - case CODE: - case CODE_PASE_ONLY: - addArgument("payload", mOnboardingPayload, null, false); - addArgument("discover-once", mDiscoverOnce, null, false); - addArgument("use-only-onnetwork-discovery", mUseOnlyOnNetworkDiscovery, null, false); - break; - case ADDRESS_PASE_ONLY: - addArgument("setup-pin-code", 0, 134217727, mSetupPINCode, null, false); - addArgument("device-remote-ip", mRemoteAddr, false); - addArgument("device-remote-port", (short) 0, Short.MAX_VALUE, mRemotePort, null, false); - break; - case BLE: - addArgument("setup-pin-code", 0, 134217727, mSetupPINCode, null, false); - addArgument("discriminator", (short) 0, (short) 4096, mDiscriminator, null, false); - break; - case ON_NETWORK: - addArgument("setup-pin-code", 0, 134217727, mSetupPINCode, null, false); - break; - case SOFT_AP: - addArgument("setup-pin-code", 0, 134217727, mSetupPINCode, null, false); - addArgument("discriminator", (short) 0, (short) 4096, mDiscriminator, null, false); - addArgument("device-remote-ip", mRemoteAddr, false); - addArgument("device-remote-port", (short) 0, Short.MAX_VALUE, mRemotePort, null, false); - break; - case ALREADY_DISCOVERED: - addArgument("setup-pin-code", 0, 134217727, mSetupPINCode, null, false); - addArgument("device-remote-ip", mRemoteAddr, false); - addArgument("device-remote-port", (short) 0, Short.MAX_VALUE, mRemotePort, null, false); - break; - } - - switch (filterType) { - case NONE: - break; - case SHORT_DISCRIMINATOR: - addArgument("discriminator", (short) 0, (short) 4096, mDiscriminator, null, false); - break; - case LONG_DISCRIMINATOR: - addArgument("discriminator", (short) 0, (short) 4096, mDiscriminator, null, false); - break; - case VENDOR_ID: - addArgument("vendor-id", (short) 0, Short.MAX_VALUE, mDiscoveryFilterCode, null, false); - break; - case COMPRESSED_FABRIC_ID: - addArgument("fabric-id", 0, Long.MAX_VALUE, mDiscoveryFilterCode, null, false); - break; - case COMMISSIONING_MODE: - case COMMISSIONER: - break; - case DEVICE_TYPE: - addArgument("device-type", (short) 0, Short.MAX_VALUE, mDiscoveryFilterCode, null, false); - break; - case INSTANCE_NAME: - addArgument("name", mDiscoveryFilterInstanceName, null, false); - break; - } - - addArgument("timeout", (long) 0, Long.MAX_VALUE, mTimeoutMillis, null, false); - } -} diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairingCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairingCommand.kt new file mode 100644 index 00000000000000..2c73c78a7af75a --- /dev/null +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairingCommand.kt @@ -0,0 +1,233 @@ +/* + * 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.controller.commands.pairing + +import chip.devicecontroller.ChipDeviceController +import com.matter.controller.commands.common.CredentialsIssuer +import com.matter.controller.commands.common.IPAddress +import com.matter.controller.commands.common.MatterCommand +import java.net.InetAddress +import java.net.UnknownHostException +import java.util.concurrent.atomic.AtomicBoolean +import java.util.concurrent.atomic.AtomicInteger +import java.util.concurrent.atomic.AtomicLong +import java.util.logging.Level +import java.util.logging.Logger + +abstract class PairingCommand( + controller: ChipDeviceController, + commandName: String?, + credsIssuer: CredentialsIssuer?, + private val pairingMode: PairingModeType = PairingModeType.NONE, + private val networkType: PairingNetworkType = PairingNetworkType.NONE, + private val filterType: DiscoveryFilterType = DiscoveryFilterType.NONE +) : MatterCommand(controller, commandName, credsIssuer), ChipDeviceController.CompletionListener { + private val remoteAddr: IPAddress = IPAddress(InetAddress.getByName("::1")) + private val nodeId = AtomicLong() + private val discoveryFilterCode = AtomicLong() + private val timeoutMillis = AtomicLong() + private val discoverOnce = AtomicBoolean() + private val useOnlyOnNetworkDiscovery = AtomicBoolean() + private val remotePort = AtomicInteger() + private val discriminator = AtomicInteger() + private val setupPINCode = AtomicLong() + private val operationalDataset = StringBuffer() + private val ssid = StringBuffer() + private val password = StringBuffer() + private val onboardingPayload = StringBuffer() + private val discoveryFilterInstanceName = StringBuffer() + + init { + addArgument("node-id", 0, Long.MAX_VALUE, nodeId, null, false) + + when (networkType) { + PairingNetworkType.NONE -> {} + PairingNetworkType.WIFI -> { + addArgument("ssid", ssid, null, false) + addArgument("password", password, null, false) + } + + PairingNetworkType.THREAD -> addArgument("operationalDataset", operationalDataset, null, false) + } + + when (pairingMode) { + PairingModeType.NONE -> {} + PairingModeType.CODE, PairingModeType.CODE_PASE_ONLY -> { + addArgument("payload", onboardingPayload, null, false) + addArgument("discover-once", discoverOnce, null, false) + addArgument("use-only-onnetwork-discovery", useOnlyOnNetworkDiscovery, null, false) + } + + PairingModeType.ADDRESS_PASE_ONLY -> { + addArgument("setup-pin-code", 0, 134217727, setupPINCode, null, false) + addArgument("device-remote-ip", remoteAddr, false) + addArgument("device-remote-port", 0.toShort(), Short.MAX_VALUE, remotePort, null, false) + } + + PairingModeType.BLE -> { + addArgument("setup-pin-code", 0, 134217727, setupPINCode, null, false) + addArgument("discriminator", 0.toShort(), 4096.toShort(), discriminator, null, false) + } + + PairingModeType.ON_NETWORK -> addArgument("setup-pin-code", 0, 134217727, setupPINCode, null, false) + PairingModeType.SOFT_AP -> { + addArgument("setup-pin-code", 0, 134217727, setupPINCode, null, false) + addArgument("discriminator", 0.toShort(), 4096.toShort(), discriminator, null, false) + addArgument("device-remote-ip", remoteAddr, false) + addArgument("device-remote-port", 0.toShort(), Short.MAX_VALUE, remotePort, null, false) + } + + PairingModeType.ALREADY_DISCOVERED -> { + addArgument("setup-pin-code", 0, 134217727, setupPINCode, null, false) + addArgument("device-remote-ip", remoteAddr, false) + addArgument("device-remote-port", 0.toShort(), Short.MAX_VALUE, remotePort, null, false) + } + } + + when (filterType) { + DiscoveryFilterType.NONE -> {} + DiscoveryFilterType.SHORT_DISCRIMINATOR, + DiscoveryFilterType.LONG_DISCRIMINATOR -> addArgument( + "discriminator", + 0.toShort(), + 4096.toShort(), + discriminator, + null, + false + ) + + DiscoveryFilterType.VENDOR_ID -> addArgument( + "vendor-id", + 1.toShort(), + Short.MAX_VALUE, + discoveryFilterCode, + null, + false + ) + + DiscoveryFilterType.COMPRESSED_FABRIC_ID -> addArgument( + "fabric-id", + 0L, + Long.MAX_VALUE, + discoveryFilterCode, + null, + false + ) + + DiscoveryFilterType.COMMISSIONING_MODE, DiscoveryFilterType.COMMISSIONER -> {} + DiscoveryFilterType.DEVICE_TYPE -> addArgument( + "device-type", + 0.toShort(), + Short.MAX_VALUE, + discoveryFilterCode, + null, + false + ) + + DiscoveryFilterType.INSTANCE_NAME -> addArgument("name", discoveryFilterInstanceName, null, false) + } + + addArgument("timeout", 0L, Long.MAX_VALUE, timeoutMillis, null, false) + } + + override fun onConnectDeviceComplete() { + logger.log(Level.INFO, "onConnectDeviceComplete") + } + + override fun onStatusUpdate(status: Int) { + logger.log(Level.INFO, "onStatusUpdate with status: $status") + } + + override fun onPairingComplete(errorCode: Int) { + logger.log(Level.INFO, "onPairingComplete with error code: $errorCode") + if (errorCode != 0) { + setFailure("onPairingComplete failure") + } + } + + override fun onPairingDeleted(errorCode: Int) { + logger.log(Level.INFO, "onPairingDeleted with error code: $errorCode") + } + + override fun onCommissioningComplete(nodeId: Long, errorCode: Int) { + logger.log(Level.INFO, "onCommissioningComplete with error code: $errorCode") + if (errorCode == 0) { + setSuccess() + } else { + setFailure("onCommissioningComplete failure") + } + } + + override fun onReadCommissioningInfo( + vendorId: Int, productId: Int, wifiEndpointId: Int, threadEndpointId: Int + ) { + logger.log(Level.INFO, "onReadCommissioningInfo") + } + + override fun onCommissioningStatusUpdate(nodeId: Long, stage: String?, errorCode: Int) { + logger.log(Level.INFO, "onCommissioningStatusUpdate") + } + + override fun onNotifyChipConnectionClosed() { + logger.log(Level.INFO, "onNotifyChipConnectionClosed") + } + + override fun onCloseBleComplete() { + logger.log(Level.INFO, "onCloseBleComplete") + } + + override fun onError(error: Throwable) { + setFailure(error.toString()) + logger.log(Level.INFO, "onError with error: $error") + } + + override fun onOpCSRGenerationComplete(csr: ByteArray) { + logger.log(Level.INFO, "onOpCSRGenerationComplete") + for (i in csr.indices) { + print(csr[i].toString() + " ") + } + } + + fun getNodeId(): Long { + return nodeId.get() + } + + fun getRemoteAddr(): IPAddress { + return remoteAddr + } + + fun getRemotePort(): Int { + return remotePort.get() + } + + fun getSetupPINCode(): Long { + return setupPINCode.get() + } + + fun getDiscriminator(): Int { + return discriminator.get() + } + + fun getTimeoutMillis(): Long { + return timeoutMillis.get() + } + + companion object { + private val logger = Logger.getLogger(PairingCommand::class.java.name) + } +} \ No newline at end of file diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairingModeType.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairingModeType.kt similarity index 80% rename from examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairingModeType.java rename to examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairingModeType.kt index 63556f7b3bfe82..7c8430edbe3eaf 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairingModeType.java +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairingModeType.kt @@ -1,30 +1,29 @@ -/* - * Copyright (c) 2022 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.controller.commands.pairing; - -public enum PairingModeType { - NONE, - CODE, - CODE_PASE_ONLY, - ADDRESS_PASE_ONLY, - BLE, - SOFT_AP, - ALREADY_DISCOVERED, - ON_NETWORK; -} +/* + * 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.controller.commands.pairing + +enum class PairingModeType { + NONE, + CODE, + CODE_PASE_ONLY, + ADDRESS_PASE_ONLY, + BLE, + SOFT_AP, + ALREADY_DISCOVERED, + ON_NETWORK +} \ No newline at end of file diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairingNetworkType.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairingNetworkType.kt similarity index 77% rename from examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairingNetworkType.java rename to examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairingNetworkType.kt index 650fad5f887552..0056b29af67065 100644 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairingNetworkType.java +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairingNetworkType.kt @@ -1,25 +1,22 @@ -/* - * Copyright (c) 2022 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.controller.commands.pairing; - -public enum PairingNetworkType { - NONE, - WIFI, - THREAD, -} +/* + * 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.controller.commands.pairing + +enum class PairingNetworkType { + NONE, WIFI, THREAD +} \ No newline at end of file diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/UnpairCommand.java b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/UnpairCommand.java deleted file mode 100644 index 2c33c8dc551a1b..00000000000000 --- a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/UnpairCommand.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.matter.controller.commands.pairing; - -import chip.devicecontroller.ChipDeviceController; -import com.matter.controller.commands.common.CredentialsIssuer; - -public final class UnpairCommand extends PairingCommand { - public UnpairCommand(ChipDeviceController controller, CredentialsIssuer credsIssue) { - super(controller, "unpair", PairingModeType.NONE, PairingNetworkType.NONE, credsIssue); - } - - @Override - protected void runCommand() {} -} diff --git a/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/UnpairCommand.kt b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/UnpairCommand.kt new file mode 100644 index 00000000000000..4e10ba1edd7b6c --- /dev/null +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/UnpairCommand.kt @@ -0,0 +1,26 @@ +/* + * 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.controller.commands.pairing + +import chip.devicecontroller.ChipDeviceController +import com.matter.controller.commands.common.CredentialsIssuer + +class UnpairCommand(controller: ChipDeviceController, credsIssue: CredentialsIssuer?) : + PairingCommand(controller, "unpair", credsIssue, PairingModeType.NONE, PairingNetworkType.NONE) { + override fun runCommand() {} +} \ No newline at end of file