Skip to content
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
15 changes: 0 additions & 15 deletions examples/chip-tool/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ import("${chip_root}/src/crypto/crypto.gni")

assert(chip_build_tools)

# Thread Commissioner is using newer version of mbedtls
_enable_thread_meshcop = chip_device_platform == "linux" &&
chip_enable_ot_commissioner && chip_crypto != "mbedtls"

config("config") {
include_dirs = [
".",
Expand All @@ -55,12 +51,6 @@ config("config") {
defines += [ "CONFIG_ENABLE_HTTPS_REQUESTS" ]
}

if (_enable_thread_meshcop) {
defines += [ "CHIP_ENABLE_OT_COMMISSIONER=1" ]
} else {
defines += [ "CHIP_ENABLE_OT_COMMISSIONER=0" ]
}

cflags = [ "-Wconversion" ]
}

Expand Down Expand Up @@ -155,11 +145,6 @@ static_library("chip-tool-utils") {
[ "${chip_root}/examples/common/tracing:trace_handlers_decoder" ]
}

if (_enable_thread_meshcop) {
sources += [ "commands/pairing/CommissionProxy.cpp" ]
public_deps += [ "${chip_root}/third_party/ot-commissioner" ]
}

output_dir = root_out_dir
}

Expand Down
1 change: 1 addition & 0 deletions examples/chip-tool/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ matter_log_json_payload_decode_full = true
# make chip-tool very strict by default
chip_tlv_validate_char_string_on_read = true
chip_tlv_validate_char_string_on_write = true
chip_support_thread_meshcop = true
3 changes: 0 additions & 3 deletions examples/chip-tool/chip-tool.gni
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,4 @@ declare_args() {
config_enable_yaml_tests = true
config_use_local_storage = true
config_enable_https_requests = true

# Disable OpenThread Commissioner if cross-compiling by default.
chip_enable_ot_commissioner = current_cpu == host_cpu && current_os == host_os
}
13 changes: 13 additions & 0 deletions examples/chip-tool/commands/pairing/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ class PairCodePase : public PairingCommand
{}
};

#if CHIP_SUPPORT_THREAD_MESHCOP
class PairThreadMeshcop : public PairingCommand
{
public:
PairThreadMeshcop(CredentialIssuerCommands * credsIssuerConfig) :
PairingCommand("thread-meshcop", PairingMode::ThreadMeshcop, PairingNetworkType::Thread, credsIssuerConfig)
{}
};
#endif

class PairCodeWifi : public PairingCommand
{
public:
Expand Down Expand Up @@ -277,6 +287,9 @@ void registerCommandsPairing(Commands & commands, CredentialIssuerCommands * cre
make_unique<PairSoftAP>(credsIssuerConfig),
#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
make_unique<PairWiFiPAF>(credsIssuerConfig),
#endif
#if CHIP_SUPPORT_THREAD_MESHCOP
make_unique<PairThreadMeshcop>(credsIssuerConfig),
#endif
make_unique<PairAlreadyDiscovered>(credsIssuerConfig),
make_unique<PairAlreadyDiscoveredByIndex>(credsIssuerConfig),
Expand Down
102 changes: 40 additions & 62 deletions examples/chip-tool/commands/pairing/PairingCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,6 @@ CHIP_ERROR PairingCommand::RunInternal(NodeId remoteId)
err = Unpair(remoteId);
break;
case PairingMode::Code:
#if CHIP_ENABLE_OT_COMMISSIONER
if (mThreadBaHost.HasValue() && mThreadBaPort.HasValue())
{
err = PairWithMeshCoP();
break;
}
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
chip::DeviceLayer::ConnectivityMgr().WiFiPafSetApFreq(
mApFreqStr.HasValue() ? static_cast<uint16_t>(std::stol(mApFreqStr.Value())) : 0);
Expand Down Expand Up @@ -148,6 +141,17 @@ CHIP_ERROR PairingCommand::RunInternal(NodeId remoteId)
mApFreqStr.HasValue() ? static_cast<uint16_t>(std::stol(mApFreqStr.Value())) : 0);
err = Pair(remoteId, PeerAddress::WiFiPAF(remoteId));
break;
#endif
#if CHIP_SUPPORT_THREAD_MESHCOP
case PairingMode::ThreadMeshcop: {
Inet::IPAddress ipAddr;

Comment thread
bukepo marked this conversation as resolved.
VerifyOrReturnError(mThreadBaHost.HasValue(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(mThreadBaPort.HasValue(), CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(Inet::IPAddress::FromString(mThreadBaHost.Value(), ipAddr), CHIP_ERROR_INVALID_ADDRESS);
err = Pair(remoteId, PeerAddress::ThreadMeshcop(ipAddr, mThreadBaPort.Value()));
Comment thread
bukepo marked this conversation as resolved.
Comment thread
bukepo marked this conversation as resolved.
break;
}
#endif
case PairingMode::AlreadyDiscovered:
err = Pair(remoteId, PeerAddress::UDP(mRemoteAddr.address, mRemotePort, mRemoteAddr.interfaceId));
Expand Down Expand Up @@ -303,12 +307,37 @@ CHIP_ERROR PairingCommand::PairWithCode(NodeId remoteId)

CHIP_ERROR PairingCommand::Pair(NodeId remoteId, PeerAddress address)
{
VerifyOrDieWithMsg(mSetupPINCode.has_value(), chipTool, "Using mSetupPINCode in a mode when we have not gotten one");
auto params = RendezvousParameters().SetSetupPINCode(mSetupPINCode.value()).SetPeerAddress(address);
if (mDiscriminator.has_value())
auto params = RendezvousParameters().SetPeerAddress(address);
if (mOnboardingPayload != nullptr)
{
SetupPayload payload;

ReturnErrorOnFailure(ParseSetupPayload(payload, mOnboardingPayload));
params.SetSetupPINCode(payload.setUpPINCode);
params.SetSetupDiscriminator(payload.discriminator);
}
else
{
VerifyOrDieWithMsg(mSetupPINCode.has_value(), chipTool, "Using mSetupPINCode in a mode when we have not gotten one");
params.SetSetupPINCode(mSetupPINCode.value());
if (mDiscriminator.has_value())
{
params.SetDiscriminator(mDiscriminator.value());
}
}

#if CHIP_SUPPORT_THREAD_MESHCOP
if (address.GetTransportType() == Transport::Type::kThreadMeshcop)
{
params.SetDiscriminator(mDiscriminator.value());
CurrentCommissioner().RegisterDeviceDiscoveryDelegate(this);
CommissioningParameters commissioningParams = GetCommissioningParameters();

commissioningParams.SetThreadOperationalDataset(mOperationalDataset);
auto error = CurrentCommissioner().PairDevice(remoteId, params, commissioningParams);
CurrentCommissioner().RegisterDeviceDiscoveryDelegate(nullptr);
return error;
}
#endif // CHIP_SUPPORT_THREAD_MESHCOP

CHIP_ERROR err = CHIP_NO_ERROR;
if (mPaseOnly.ValueOr(false))
Expand Down Expand Up @@ -419,57 +448,6 @@ CHIP_ERROR PairingCommand::PairWithMdns(NodeId remoteId)
return CurrentCommissioner().DiscoverCommissionableNodes(filter);
}

#if CHIP_ENABLE_OT_COMMISSIONER
Comment thread
bukepo marked this conversation as resolved.
CHIP_ERROR PairingCommand::PairWithMeshCoP()
{
SetupPayload payload;

ReturnErrorOnFailure(ParseSetupPayload(payload, mOnboardingPayload));

if (payload.rendezvousInformation.HasValue() && !payload.rendezvousInformation.Value().Has(RendezvousInformationFlag::kThread))
{
// Proceed even if the device doesn't claim rendezvous over Thread MeshCoP because in-market devices may not
// be able to update their QR Code.
ChipLogProgress(chipTool, "WARNING: device may not support commissioning over Thread meshcop");
}

mSetupPINCode.emplace(payload.setUpPINCode);

Thread::DiscoveryCode code;
if (payload.discriminator.IsShortDiscriminator())
{
code = Thread::DiscoveryCode(payload.discriminator.GetShortValue());
ChipLogProgress(chipTool, "Discovery code from short discriminator: 0x%" PRIx64, code.AsUInt64());
}
else
{
code = Thread::DiscoveryCode(payload.discriminator.GetLongValue());
ChipLogProgress(chipTool, "Discovery code from long discriminator: 0x%" PRIx64, code.AsUInt64());
}

uint8_t pskc[Thread::kSizePSKc];

{
Thread::OperationalDatasetView dataset;
ReturnErrorAndLogOnFailure(dataset.Init(mOperationalDataset), chipTool, "Failed to parse Thread dataset");

ReturnErrorAndLogOnFailure(dataset.GetPSKc(pskc), chipTool, "Failed to retrieve PSKc");
}

{
Dnssd::DiscoveredNodeData discoveredNodeData;
ReturnErrorOnFailure(mCommissionProxy.Discover(pskc, mThreadBaHost.Value(), mThreadBaPort.Value(), code,
payload.discriminator, discoveredNodeData, mTimeout.ValueOr(30)));

CurrentCommissioner().RegisterDeviceDiscoveryDelegate(this);
CurrentCommissioner().OnNodeDiscovered(discoveredNodeData);
}

ChipLogProgress(chipTool, "Joiner discovered");
return CHIP_NO_ERROR;
}
#endif // CHIP_ENABLE_OT_COMMISSIONER

CHIP_ERROR PairingCommand::Unpair(NodeId remoteId)
{
mCurrentFabricRemover = Platform::MakeUnique<Controller::CurrentFabricRemover>(&CurrentCommissioner());
Expand Down
22 changes: 10 additions & 12 deletions examples/chip-tool/commands/pairing/PairingCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
#pragma once

#include "../common/CHIPCommand.h"
#if CHIP_ENABLE_OT_COMMISSIONER
#include "CommissionProxy.h"
#endif
#include <controller/CommissioningDelegate.h>
#include <controller/CurrentFabricRemover.h>

Expand All @@ -47,6 +44,9 @@ enum class PairingMode
AlreadyDiscoveredByIndexWithCode,
OnNetwork,
Nfc,
#if CHIP_SUPPORT_THREAD_MESHCOP
ThreadMeshcop,
#endif
};

enum class PairingNetworkType
Expand Down Expand Up @@ -109,6 +109,12 @@ class PairingCommand : public CHIPCommand,
{
case PairingMode::None:
break;
#if CHIP_SUPPORT_THREAD_MESHCOP
case PairingMode::ThreadMeshcop:
AddArgument("thread-ba-host", &mThreadBaHost, "Thread Border Agent host");
AddArgument("thread-ba-port", 0, UINT16_MAX, &mThreadBaPort, "Thread Border Agent port");
FALLTHROUGH;
Comment thread
bukepo marked this conversation as resolved.
#endif
case PairingMode::Code:
AddArgument("skip-commissioning-complete", 0, 1, &mSkipCommissioningComplete);
AddArgument("dcl-hostname", &mDCLHostName,
Expand All @@ -119,10 +125,6 @@ class PairingCommand : public CHIPCommand,
case PairingMode::CodePaseOnly:
AddArgument("payload", &mOnboardingPayload);
AddArgument("discover-once", 0, 1, &mDiscoverOnce);
#if CHIP_ENABLE_OT_COMMISSIONER
AddArgument("thread-ba-host", &mThreadBaHost, "Thread Border Agent host");
AddArgument("thread-ba-port", 0, UINT16_MAX, &mThreadBaPort, "Thread Border Agent port");
#endif
AddArgument("use-only-onnetwork-discovery", 0, 1, &mUseOnlyOnNetworkDiscovery,
"Whether to only use DNS-SD for discovery. The default is true if no network credentials are provided, "
"false otherwise.");
Expand Down Expand Up @@ -270,9 +272,6 @@ class PairingCommand : public CHIPCommand,
CHIP_ERROR RunInternal(NodeId remoteId);
CHIP_ERROR Pair(NodeId remoteId, PeerAddress address);
CHIP_ERROR PairWithMdns(NodeId remoteId);
#if CHIP_ENABLE_OT_COMMISSIONER
CHIP_ERROR PairWithMeshCoP();
#endif
CHIP_ERROR PairWithCode(NodeId remoteId);
CHIP_ERROR PaseWithCode(NodeId remoteId);
CHIP_ERROR PairWithMdnsOrBleByIndex(NodeId remoteId, uint16_t index);
Expand Down Expand Up @@ -341,10 +340,9 @@ class PairingCommand : public CHIPCommand,
static void OnCurrentFabricRemove(void * context, NodeId remoteNodeId, CHIP_ERROR status);
void PersistIcdInfo();

#if CHIP_ENABLE_OT_COMMISSIONER
#if CHIP_SUPPORT_THREAD_MESHCOP
chip::Optional<char *> mThreadBaHost;
chip::Optional<uint16_t> mThreadBaPort;
CommissionProxy mCommissionProxy;
#endif

std::optional<std::thread> mPrompterThread;
Expand Down
1 change: 1 addition & 0 deletions examples/jf-control-app/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ chip_tlv_validate_char_string_on_write = true
# enable Joint Fabric features in the core SDK code
# (e.g.: commissioner related code from src/controller)
chip_device_config_enable_joint_fabric = true
chip_support_thread_meshcop = false
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ RUN apt-get update \
libavahi-client3 \
libcairo2-dev \
libdbus-1-dev \
libevent-dev \
libgif-dev \
libgirepository1.0-dev \
libglib2.0-dev \
Expand Down
16 changes: 16 additions & 0 deletions scripts/build_python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Input Options:
-b, --enable_ble <true/false> Enable BLE in the controller (default=$enable_ble)
-p, --enable_wifi_paf <true/false> Enable Wi-Fi PAF discovery in the controller (default=SDK default behavior)
-4, --enable_ipv4 <true/false> Enable IPv4 in the controller (default=$enable_ipv4)
-M, --enable_thread_meshcop <true/false> Enable Thread Meshcop support.
-d, --chip_detail_logging <true/false> Specify ChipDetailLoggingValue as true or false.
By default it is $chip_detail_logging.
-m, --chip_mdns ChipMDNSValue Specify ChipMDNSValue as platform or minimal.
Expand Down Expand Up @@ -127,6 +128,15 @@ while (($#)); do
wifi_paf_config="chip_device_config_enable_wifipaf=$wifi_paf_arg"
shift
;;
--enable_thread_meshcop | -M)
declare thread_meshcop_arg="$2"
if [[ "$thread_meshcop_arg" != "true" && "$thread_meshcop_arg" != "false" ]]; then
echo "Error: --enable_thread_meshcop/-M should have a true/false value, not '$thread_meshcop_arg'" >&2
exit 1
fi
thread_meshcop_config="chip_support_thread_meshcop=$thread_meshcop_arg"
shift
;;
--enable_ipv4 | -4)
enable_ipv4=$2
if [[ "$enable_ipv4" != "true" && "$enable_ipv4" != "false" ]]; then
Expand Down Expand Up @@ -233,6 +243,9 @@ echo " enable_nfc=\"$enable_nfc\""
if [[ -n $wifi_paf_config ]]; then
echo " $wifi_paf_config"
fi
if [[ -n $thread_meshcop_config ]]; then
echo " $thread_meshcop_config"
fi
echo " enable_ipv4=\"$enable_ipv4\""
echo " chip_build_controller_dynamic_server=\"$chip_build_controller_dynamic_server\""
echo " chip_support_webrtc_python_bindings=\"$enable_webrtc\""
Expand Down Expand Up @@ -309,6 +322,9 @@ fi
if [[ -n $wifi_paf_config ]]; then
gn_args+=("$wifi_paf_config")
fi
if [[ -n $thread_meshcop_config ]]; then
gn_args+=("$thread_meshcop_config")
fi
# Append extra arguments provided by the user.
gn_args+=("${extra_gn_args[@]}")

Expand Down
5 changes: 3 additions & 2 deletions scripts/tests/chiptest/test_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,8 @@ def _RunImpl(self, target: TestTarget, runner: Runner, apps_register: AppsRegist
if op_network == 'Thread':
# The node id must not conflict with ThreadBorderRouter.NODE_ID
subproc = subproc.with_args("--thread-node-id=2")
elif ble_controller_app is not None:

if ble_controller_app is not None:
subproc = subproc.with_args("--ble-controller", str(ble_controller_app))
if op_network == 'WiFi':
subproc = subproc.with_args("--wifi")
Expand Down Expand Up @@ -576,7 +577,7 @@ def _RunImpl(self, target: TestTarget, runner: Runner, apps_register: AppsRegist
pairing_server_args = ["--ble-controller", str(ble_controller_tool)]
elif op_network == 'Thread' and thread_ba_host is not None and thread_ba_port is not None:
pairing_cmd = pairing_cmd.with_args(
"pairing", "code-thread", TEST_NODE_ID, f"hex:{TEST_THREAD_DATASET}", setupCode,
"pairing", "thread-meshcop", TEST_NODE_ID, f"hex:{TEST_THREAD_DATASET}", setupCode,
"--thread-ba-host", thread_ba_host, "--thread-ba-port", str(thread_ba_port))
else:
pairing_cmd = pairing_cmd.with_args('pairing', 'code', TEST_NODE_ID, setupCode)
Expand Down
12 changes: 12 additions & 0 deletions src/controller/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import("//build_overrides/chip.gni")
import("${chip_root}/src/app/common_flags.gni")
import("${chip_root}/src/controller/flags.gni")
import("${chip_root}/src/crypto/crypto.gni")
import("${chip_root}/src/lib/lib.gni")
import("${chip_root}/src/platform/device.gni")

Expand Down Expand Up @@ -123,5 +124,16 @@ static_library("controller") {
public_deps += [ "${chip_root}/src/controller/webrtc:chip_webrtc" ]
}

if (chip_device_platform == "linux" && chip_crypto != "mbedtls" &&
chip_support_thread_meshcop && current_cpu == host_cpu &&
current_os == host_os) {
sources += [
"ThreadMeshcopCommissionProxy.cpp",
"ThreadMeshcopCommissionProxy.h",
]
deps += [ "${chip_root}/src/lib/dnssd/minimal_mdns:minimal_mdns" ]
public_deps += [ "${chip_root}/third_party/ot-commissioner" ]
}

public_configs = [ "${chip_root}/src:includes" ]
}
Loading
Loading