Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java-matter-controller] Add pairing already-discovered command #24916

Merged
merged 3 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ jobs:
--tool-args "commissionables" \
--factoryreset \
'
- name: Run Pairing over Onnetwork Test
- name: Run Pairing Onnetwork Test
timeout-minutes: 10
run: |
scripts/run_in_build_env.sh \
Expand All @@ -532,9 +532,21 @@ jobs:
--app-args "--discriminator 3840 --interface-id -1" \
--tool-path out/linux-x64-java-matter-controller \
--tool-cluster "pairing" \
--tool-args "onnetwork-long --nodeid 1 --setup-payload 20202021 --discriminator 3840 -t 1000" \
--tool-args "onnetwork-long --nodeid 1 --setup-pin-code 20202021 --discriminator 3840 -t 1000" \
--factoryreset \
'
- name: Run Pairing AlreadyDiscovered Test
timeout-minutes: 10
run: |
scripts/run_in_build_env.sh \
'./scripts/tests/run_java_test.py \
--app out/linux-x64-all-clusters-ipv6only-no-ble-no-wifi-tsan-clang-test/chip-all-clusters-app \
--app-args "--discriminator 3840 --interface-id -1" \
--tool-path out/linux-x64-java-matter-controller \
--tool-cluster "pairing" \
--tool-args "already-discovered --nodeid 1 --setup-pin-code 20202021 --address ::1 --port 5540 -t 1000" \
--factoryreset \
'
- name: Uploading core files
uses: actions/upload-artifact@v3
if: ${{ failure() && !env.ACT }}
Expand Down
1 change: 1 addition & 0 deletions examples/java-matter-controller/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ java_binary("java-matter-controller") {
"java/src/com/matter/controller/commands/discover/DiscoverCommissionersCommand.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/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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ private static void registerCommandsPairing(
new PairCodeWifiCommand(controller, credentialsIssuer);
PairCodeThreadCommand pairCodeThreadCommand =
new PairCodeThreadCommand(controller, credentialsIssuer);
PairAlreadyDiscoveredCommand pairAlreadyDiscoveredCommand =
new PairAlreadyDiscoveredCommand(controller, credentialsIssuer);
PairOnNetworkCommand pairOnNetworkCommand =
new PairOnNetworkCommand(controller, credentialsIssuer);
PairOnNetworkShortCommand pairOnNetworkShortCommand =
Expand All @@ -81,6 +83,7 @@ private static void registerCommandsPairing(
clusterCommands.add(pairCodePaseCommand);
clusterCommands.add(pairCodeWifiCommand);
clusterCommands.add(pairCodeThreadCommand);
clusterCommands.add(pairAlreadyDiscoveredCommand);
clusterCommands.add(pairOnNetworkCommand);
clusterCommands.add(pairOnNetworkShortCommand);
clusterCommands.add(pairOnNetworkLongCommand);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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(),
yufengwangca marked this conversation as resolved.
Show resolved Hide resolved
getSetupPINCode(),
null);
currentCommissioner().setCompletionListener(this);
waitCompleteMs(getTimeoutMillis());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,6 @@ public abstract class PairingCommand extends MatterCommand
private final StringBuffer mDiscoveryFilterInstanceName = new StringBuffer();
private static Logger logger = Logger.getLogger(PairingCommand.class.getName());

public long getNodeId() {
return mNodeId.get();
}

public int getSetupPINCode() {
return mSetupPINCode.get();
}

public int getDiscriminator() {
return mDiscriminator.get();
}

public long getTimeoutMillis() {
return mTimeoutMillis.get();
}

@Override
public void onConnectDeviceComplete() {
logger.log(Level.INFO, "onConnectDeviceComplete");
Expand Down Expand Up @@ -135,10 +119,30 @@ public void onOpCSRGenerationComplete(byte[] csr) {
}
}

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,
Expand Down Expand Up @@ -170,7 +174,6 @@ public PairingCommand(

switch (networkType) {
case NONE:
case ETHERNET:
break;
case WIFI:
addArgument("ssid", mSSID, null, false);
Expand Down Expand Up @@ -205,6 +208,11 @@ public PairingCommand(
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ public enum PairingModeType {
CODE_PASE_ONLY,
BLE,
SOFT_AP,
ALREADY_DISCOVERED,
ON_NETWORK;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ public enum PairingNetworkType {
NONE,
WIFI,
THREAD,
ETHERNET;
}
27 changes: 23 additions & 4 deletions scripts/tests/java/commissioning_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,24 @@ def __init__(self, thread_list: typing.List[threading.Thread], queue: queue.Queu
parser.add_argument('command', help="Command name")
parser.add_argument('-t', '--timeout', help="The program will return with timeout after specified seconds", default='200')
parser.add_argument('-a', '--address', help="Address of the device")
parser.add_argument('-p', '--port', help="Port of the remote device", default='5540')
parser.add_argument('-s', '--setup-payload', dest='setup_payload',
help="Setup Payload (manual pairing code or QR code content)")
parser.add_argument('-c', '--setup-pin-code', dest='setup_pin_code',
help="Setup PIN code which can be used for password-authenticated session establishment (PASE) with the Commissionee")
parser.add_argument('-n', '--nodeid', help="The Node ID issued to the device", default='1')
parser.add_argument('-d', '--discriminator', help="Discriminator of the device", default='3840')
parser.add_argument('-p', '--paa-trust-store-path', dest='paa_trust_store_path',
parser.add_argument('-u', '--paa-trust-store-path', dest='paa_trust_store_path',
yufengwangca marked this conversation as resolved.
Show resolved Hide resolved
help="Path that contains valid and trusted PAA Root Certificates")

args = parser.parse_args(args.split())

self.command_name = args.command
self.nodeid = args.nodeid
self.address = args.address
self.port = args.port
self.setup_payload = args.setup_payload
self.setup_pin_code = args.setup_pin_code
self.discriminator = args.discriminator
self.timeout = args.timeout

Expand All @@ -67,11 +73,24 @@ def TestCmdOnnetworkLong(self, nodeid, setuppin, discriminator, timeout):
DumpProgramOutputToQueue(self.thread_list, Fore.GREEN + "JAVA " + Style.RESET_ALL, java_process, self.queue)
return java_process.wait()

def TestCmdAlreadyDiscovered(self, nodeid, setuppin, address, port, timeout):
java_command = self.command + ['pairing', 'already-discovered', nodeid, setuppin, address, port, timeout]
logging.info(f"Execute: {java_command}")
java_process = subprocess.Popen(
java_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
DumpProgramOutputToQueue(self.thread_list, Fore.GREEN + "JAVA " + Style.RESET_ALL, java_process, self.queue)
return java_process.wait()

def RunTest(self):
if self.command_name == 'onnetwork-long':
logging.info("Testing pairing over onnetwork-long")
code = self.TestCmdOnnetworkLong(self.nodeid, self.setup_payload, self.discriminator, self.timeout)
logging.info("Testing pairing onnetwork-long")
code = self.TestCmdOnnetworkLong(self.nodeid, self.setup_pin_code, self.discriminator, self.timeout)
if code != 0:
raise Exception(f"Testing pairing onnetwork-long failed with error {code}")
elif self.command_name == 'already-discovered':
logging.info("Testing pairing already-discovered")
code = self.TestCmdAlreadyDiscovered(self.nodeid, self.setup_pin_code, self.address, self.port, self.timeout)
if code != 0:
raise Exception(f"Testing onnetwork-long pairing failed with error {code}")
raise Exception(f"Testing pairing already-discovered failed with error {code}")
else:
raise Exception(f"Unsupported command {self.command_name}")