diff --git a/examples/java-matter-controller/BUILD.gn b/examples/java-matter-controller/BUILD.gn index 83aea5b0e000ff..66fd077751eaed 100644 --- a/examples/java-matter-controller/BUILD.gn +++ b/examples/java-matter-controller/BUILD.gn @@ -36,29 +36,7 @@ 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 +54,28 @@ 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/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/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 65% 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..a23ed2e0c11a5c 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,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 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..96f853c9c999b3 --- /dev/null +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairAddressPaseCommand.kt @@ -0,0 +1,54 @@ +/* + * 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", + PairingModeType.ADDRESS_PASE_ONLY, + PairingNetworkType.NONE, + credsIssue +) { + private val logger = Logger.getLogger(PairAddressPaseCommand::class.java.name) + + 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()) + } +} \ 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..c95a69099dbe0c --- /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", + PairingModeType.ALREADY_DISCOVERED, + PairingNetworkType.NONE, + credsIssue +) { + 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..efcdd07b7d6746 --- /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", PairingModeType.CODE, PairingNetworkType.NONE, credsIssue) { + 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..e8b180e9972b80 --- /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", + PairingModeType.CODE_PASE_ONLY, + PairingNetworkType.NONE, + credsIssue +) { + 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..c1d7124f092d9d --- /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", PairingModeType.CODE, PairingNetworkType.THREAD, credsIssue) { + 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..5774d4ec45c690 --- /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", PairingModeType.CODE, PairingNetworkType.WIFI, credsIssue) { + 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..39acd7f1011132 --- /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", PairingModeType.ON_NETWORK, PairingNetworkType.NONE, credsIssue) { + 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..bc73bf41a3759d --- /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", + PairingModeType.ON_NETWORK, + PairingNetworkType.NONE, + credsIssue, + 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..7b4cf189ae7ff0 --- /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", + PairingModeType.ON_NETWORK, + PairingNetworkType.NONE, + credsIssue, + 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..36a38f7c39ebd8 --- /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", + PairingModeType.ON_NETWORK, + PairingNetworkType.NONE, + credsIssue, + 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..51f441df4d4616 --- /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", + PairingModeType.ON_NETWORK, + PairingNetworkType.NONE, + credsIssue, + 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..a7e8a5863b2fa3 --- /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", + PairingModeType.ON_NETWORK, + PairingNetworkType.NONE, + credsIssue, + 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..a2532157e0e932 --- /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 + +class PairOnNetworkLongCommand(controller: ChipDeviceController, credsIssue: CredentialsIssuer?) : PairingCommand( + controller, + "onnetwork-long", + PairingModeType.ON_NETWORK, + PairingNetworkType.NONE, + credsIssue, + DiscoveryFilterType.LONG_DISCRIMINATOR +) { + private val MATTER_PORT = 5540 + + 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/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..b1f6cb12711eea --- /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.ArrayList +import java.util.logging.Level +import java.util.logging.Logger +import javax.annotation.Nullable + +private const val MATTER_PORT = 5540 +private const val CLUSTER_ID_BASIC = 0x0028L +private const val ATTR_ID_LOCAL_CONFIG_DISABLED = 16L + +class PairOnNetworkLongImWriteCommand( + controller: ChipDeviceController, credsIssue: CredentialsIssuer? +) : PairingCommand( + controller, + "onnetwork-long-im-write", + PairingModeType.ON_NETWORK, + PairingNetworkType.NONE, + credsIssue, + DiscoveryFilterType.LONG_DISCRIMINATOR +) { + private var devicePointer: Long = 0 + private fun setDevicePointer(devicePointer: Long) { + this.devicePointer = devicePointer + } + + private inner class InternalWriteAttributesCallback : WriteAttributesCallback { + override fun onError(@Nullable 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) { + setDevicePointer(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 attribute: AttributeWriteRequest = AttributeWriteRequest.newInstance( /* endpointId= */ + 0, CLUSTER_ID_BASIC, ATTR_ID_LOCAL_CONFIG_DISABLED, booleanTLV + ) + val attributeList: ArrayList = ArrayList() + attributeList.add(attribute) + 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 + ) + } +} \ 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..b0a7aecadde0e2 --- /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", + PairingModeType.ON_NETWORK, + PairingNetworkType.NONE, + credsIssue, + 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..10e6738f63dc98 --- /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", + PairingModeType.ON_NETWORK, + PairingNetworkType.NONE, + credsIssue, + 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..c899b8b29bf1cf --- /dev/null +++ b/examples/java-matter-controller/java/src/com/matter/controller/commands/pairing/PairingCommand.kt @@ -0,0 +1,253 @@ +/* + * 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?, + mode: PairingModeType, + network: PairingNetworkType, + credsIssuer: CredentialsIssuer?, + filter: DiscoveryFilterType +) : MatterCommand(controller, commandName, credsIssuer), ChipDeviceController.CompletionListener { + private val logger = Logger.getLogger(PairingCommand::class.java.name) + private var pairingMode: PairingModeType = PairingModeType.NONE + private var networkType: PairingNetworkType = PairingNetworkType.NONE + private var filterType = DiscoveryFilterType.NONE + private var remoteAddr: IPAddress? = null + private val nodeId: AtomicLong = AtomicLong() + private val discoveryFilterCode: AtomicLong = AtomicLong() + private val timeoutMillis: AtomicLong = AtomicLong() + private val discoverOnce: AtomicBoolean = AtomicBoolean() + private val useOnlyOnNetworkDiscovery: AtomicBoolean = AtomicBoolean() + private val remotePort: AtomicInteger = AtomicInteger() + private val discriminator: AtomicInteger = AtomicInteger() + private val setupPINCode: AtomicLong = AtomicLong() + private val operationalDataset = StringBuffer() + private val SSID = StringBuffer() + private val password = StringBuffer() + private val onboardingPayload = StringBuffer() + private val discoveryFilterInstanceName = StringBuffer() + + constructor( + controller: ChipDeviceController, + commandName: String?, + mode: PairingModeType, + network: PairingNetworkType, + credsIssuer: CredentialsIssuer? + ) : this(controller, commandName, mode, network, credsIssuer, DiscoveryFilterType.NONE) + + init { + pairingMode = mode + networkType = network + filterType = filter + try { + remoteAddr = IPAddress(InetAddress.getByName("::1")) + } catch (e: UnknownHostException) { + throw RuntimeException(e) + } + 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 (mode) { + 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 -> addArgument( + "discriminator", + 0.toShort(), + 4096.toShort(), + discriminator, + null, + false + ) + + DiscoveryFilterType.LONG_DISCRIMINATOR -> addArgument( + "discriminator", + 0.toShort(), + 4096.toShort(), + discriminator, + null, + false + ) + + DiscoveryFilterType.VENDOR_ID -> addArgument( + "vendor-id", + 0, + Long.MAX_VALUE, + discoveryFilterCode, + null, + false + ) + + DiscoveryFilterType.COMPRESSED_FABRIC_ID -> addArgument( + "fabric-id", + 0, + Long.MAX_VALUE, + discoveryFilterCode, + null, + false + ) + + DiscoveryFilterType.COMMISSIONING_MODE, DiscoveryFilterType.COMMISSIONER -> {} + DiscoveryFilterType.DEVICE_TYPE -> addArgument( + "device-type", + 0, + Long.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() + } +} \ 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 69% 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..20eff038bd3a39 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,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 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..1c0258fcf9f28f --- /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", PairingModeType.NONE, PairingNetworkType.NONE, credsIssue) { + override fun runCommand() {} +} \ No newline at end of file