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

Implement a Generic Network commissioning Thread Driver #14713

Merged
2 changes: 1 addition & 1 deletion examples/light-switch-app/efr32/build_for_wifi_gnfile.gn
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ check_system_includes = true
default_args = {
target_cpu = "arm"
target_os = "freertos"
use_thread = false
chip_enable_wifi = true
import("//build_for_wifi_args.gni")
}
1 change: 1 addition & 0 deletions examples/lighting-app/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ target_sources(app PRIVATE
${CHIP_ROOT}/src/app/clusters/level-control/level-control.cpp
${CHIP_ROOT}/src/app/clusters/color-control-server/color-control-server.cpp
${CHIP_ROOT}/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp
${CHIP_ROOT}/src/app/clusters/network-commissioning/network-commissioning.cpp
${CHIP_ROOT}/src/app/clusters/network-commissioning-old/network-commissioning-ember.cpp
${CHIP_ROOT}/src/app/clusters/network-commissioning-old/network-commissioning-old.cpp
${CHIP_ROOT}/src/app/clusters/ota-requestor/ota-requestor-server.cpp
Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/efr32/build_for_wifi_gnfile.gn
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ check_system_includes = true
default_args = {
target_cpu = "arm"
target_os = "freertos"
use_thread = false
chip_enable_wifi = true
import("//build_for_wifi_args.gni")
}
1 change: 1 addition & 0 deletions examples/persistent-storage/qpg/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ import("//build_overrides/chip.gni")

import("${chip_root}/examples/platform/qpg/args.gni")
qpg_sdk_target = get_label_info(":sdk", "label_no_toolchain")
chip_enable_openthread = false
1 change: 0 additions & 1 deletion examples/shell/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ efr32_sdk("sdk") {
defines = [
"BOARD_ID=${efr32_board}",
"OPENTHREAD_CONFIG_CLI_TRANSPORT=OT_CLI_TRANSPORT_CONSOLE",
"ENABLE_CHIP_SHELL",
]
}

Expand Down
1 change: 1 addition & 0 deletions examples/shell/efr32/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ pw_log_BACKEND = "${chip_root}/src/lib/support/pw_log_chip"
pw_assert_BACKEND = "$dir_pw_assert_log"
chip_enable_openthread = true
chip_openthread_ftd = true
chip_build_libshell = true
2 changes: 2 additions & 0 deletions examples/shell/efr32/include/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,5 @@
* A size, in bytes, of the individual debug event logging buffer.
*/
#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE (512)

#define _NO_NETWORK_COMMISSIONING_DRIVER_
1 change: 1 addition & 0 deletions examples/shell/mbed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ include(${MBED_PATH}/tools/cmake/app.cmake)

project(${APP_TARGET})


add_subdirectory(${MBED_PATH} ./mbed_build)
add_subdirectory(${MBED_OS_POSIX_SOCKET_PATH} ./mbed_os_posix_socket_build)

Expand Down
4 changes: 4 additions & 0 deletions examples/shell/mbed/main/include/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@
// Use a default pairing code if one hasn't been provisioned in flash.
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021
#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00

// shell app use openthread but do not have the NETWORK_COMMISSIONING cluster or zap config
jmartinez-silabs marked this conversation as resolved.
Show resolved Hide resolved
// Do not instanciate the NETWORK_COMMISSIONING thread driver
jmartinez-silabs marked this conversation as resolved.
Show resolved Hide resolved
#define _NO_NETWORK_COMMISSIONING_DRIVER_
4 changes: 4 additions & 0 deletions examples/shell/nrfconnect/CHIPProjectConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@
* 0x4E53: nrfconnect shell
*/
#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID 0x4E53

// shell app use openthread but do not have the NETWORK_COMMISSIONING cluster or zap config
jmartinez-silabs marked this conversation as resolved.
Show resolved Hide resolved
// Do not instanciate the NETWORK_COMMISSIONING thread driver
jmartinez-silabs marked this conversation as resolved.
Show resolved Hide resolved
#define _NO_NETWORK_COMMISSIONING_DRIVER_
6 changes: 5 additions & 1 deletion examples/shell/nxp/k32w/k32w0/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ k32w0_sdk("sdk") {
"${k32w0_platform_dir}/util/include",
]

defines = []
defines = [
# shell app use openthread but do not have the NETWORK_COMMISSIONING cluster or zap config.
jmartinez-silabs marked this conversation as resolved.
Show resolved Hide resolved
"_NO_NETWORK_COMMISSIONING_DRIVER_",
]

if (is_debug) {
defines += [ "BUILD_RELEASE=0" ]
} else {
Expand Down
2 changes: 1 addition & 1 deletion examples/window-app/efr32/build_for_wifi_gnfile.gn
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ check_system_includes = true
default_args = {
target_cpu = "arm"
target_os = "freertos"
use_thread = false
chip_enable_wifi = true
import("//build_for_wifi_args.gni")
}
27 changes: 24 additions & 3 deletions src/include/platform/ThreadStackManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <app/AttributeAccessInterface.h>
#include <app/util/basic-types.h>
#include <lib/support/Span.h>
#include <platform/NetworkCommissioning.h>

namespace chip {

Expand Down Expand Up @@ -88,6 +89,9 @@ class ThreadStackManager
bool TryLockThreadStack();
void UnlockThreadStack();
bool HaveRouteToAddress(const chip::Inet::IPAddress & destAddr);
bool IsThreadEnabled();
bool IsThreadProvisioned();
bool IsThreadAttached();
CHIP_ERROR GetThreadProvision(ByteSpan & netInfo);
CHIP_ERROR GetAndLogThreadStatsCounters();
CHIP_ERROR GetAndLogThreadTopologyMinimal();
Expand All @@ -99,6 +103,9 @@ class ThreadStackManager
CHIP_ERROR JoinerStart();
CHIP_ERROR SetThreadProvision(ByteSpan aDataset);
CHIP_ERROR SetThreadEnabled(bool val);
CHIP_ERROR AttachToThreadNetwork(ByteSpan netInfo, NetworkCommissioning::Internal::WirelessDriver::ConnectCallback * callback);
CHIP_ERROR StartThreadScan(NetworkCommissioning::ThreadDriver::ScanCallback * callback);
void OnThreadAttachFinished(void);

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
CHIP_ERROR AddSrpService(const char * aInstanceName, const char * aName, uint16_t aPort,
Expand Down Expand Up @@ -145,9 +152,6 @@ class ThreadStackManager
friend class Internal::GenericThreadStackManagerImpl_FreeRTOS;

void OnPlatformEvent(const ChipDeviceEvent * event);
bool IsThreadEnabled();
bool IsThreadProvisioned();
bool IsThreadAttached();
void ErasePersistentInfo();
ConnectivityManager::ThreadDeviceType GetThreadDeviceType();
CHIP_ERROR SetThreadDeviceType(ConnectivityManager::ThreadDeviceType threadRole);
Expand Down Expand Up @@ -347,6 +351,23 @@ inline CHIP_ERROR ThreadStackManager::SetThreadProvision(ByteSpan netInfo)
return static_cast<ImplClass *>(this)->_SetThreadProvision(netInfo);
}

inline CHIP_ERROR
ThreadStackManager::AttachToThreadNetwork(ByteSpan netInfo,
NetworkCommissioning::Internal::WirelessDriver::ConnectCallback * callback)
{
return static_cast<ImplClass *>(this)->_AttachToThreadNetwork(netInfo, callback);
}

inline void ThreadStackManager::OnThreadAttachFinished(void)
{
static_cast<ImplClass *>(this)->_OnThreadAttachFinished();
}

inline CHIP_ERROR ThreadStackManager::StartThreadScan(NetworkCommissioning::ThreadDriver::ScanCallback * callback)
{
return static_cast<ImplClass *>(this)->_StartThreadScan(callback);
}

inline void ThreadStackManager::ErasePersistentInfo()
{
static_cast<ImplClass *>(this)->_ErasePersistentInfo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ void GenericConnectivityManagerImpl_Thread<ImplClass>::_OnPlatformEvent(const Ch
(event->Type == DeviceEventType::kThreadStateChange && event->ThreadStateChange.NetDataChanged);
const bool fabricMembershipChanged = (event->Type == DeviceEventType::kFabricMembershipChange);

if (threadConnChanged && event->ThreadConnectivityChange.Result == kConnectivity_Established)
{
ThreadStackMgrImpl().OnThreadAttachFinished();
}

// If any of the above events has occurred, assess whether there's been a change in
// service connectivity via Thread.
if (threadConnChanged || threadAddrChanged || threadNetDataChanged || fabricMembershipChanged)
Expand Down
8 changes: 8 additions & 0 deletions src/platform/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,14 @@ if (chip_device_platform != "none") {
"PlatformEventSupport.cpp",
]

# Linux has his own NetworkCommissioningThreadDriver
jmartinez-silabs marked this conversation as resolved.
Show resolved Hide resolved
if (chip_enable_openthread && chip_device_platform != "linux") {
sources += [
"OpenThread/GenericNetworkCommissioningThreadDriver.cpp",
"OpenThread/GenericNetworkCommissioningThreadDriver.h",
]
}

if (chip_enable_ota_requestor) {
sources += [
"GenericOTARequestorDriver.cpp",
Expand Down
4 changes: 3 additions & 1 deletion src/platform/EFR32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ static_library("EFR32") {
sources += [ "../OpenThread/DnssdImpl.cpp" ]
deps += [ "${chip_root}/src/lib/dnssd:platform_header" ]
}
} else {
}

if (chip_enable_wifi) {
sources += [
"ConnectivityManagerImpl_WIFI.cpp",
"ServiceProvisioning.cpp",
Expand Down
5 changes: 3 additions & 2 deletions src/platform/EFR32/CHIPDevicePlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@
#define CHIP_DEVICE_CONFIG_EFR32_NVM3_ERROR_MIN 0xB00000
#define CHIP_DEVICE_CONFIG_EFR32_BLE_ERROR_MIN 0xC00000

#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION 0
#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP 0

#if defined(SL_WIFI)
#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION 1
#elif CHIP_ENABLE_OPENTHREAD

#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION 0
#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP 0
#define CHIP_DEVICE_CONFIG_ENABLE_THREAD 1
#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT 1
#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT 1
Expand Down
1 change: 0 additions & 1 deletion src/platform/EFR32/ThreadStackManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

#include <platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.cpp>
#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.cpp>

#include <platform/OpenThread/OpenThreadUtils.h>
#include <platform/ThreadStackManager.h>

Expand Down
10 changes: 5 additions & 5 deletions src/platform/Linux/ThreadStackManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ CHIP_ERROR ThreadStackManagerImpl::_SetThreadEnabled(bool val)
VerifyOrReturnError(mProxy, CHIP_ERROR_INCORRECT_STATE);
if (val)
{
openthread_io_openthread_border_router_call_attach(mProxy.get(), nullptr, _OnThreadAttachFinished, this);
openthread_io_openthread_border_router_call_attach(mProxy.get(), nullptr, _OnThreadBrAttachFinished, this);
}
else
{
Expand All @@ -311,7 +311,7 @@ CHIP_ERROR ThreadStackManagerImpl::_SetThreadEnabled(bool val)
return CHIP_NO_ERROR;
}

void ThreadStackManagerImpl::_OnThreadAttachFinished(GObject * source_object, GAsyncResult * res, gpointer user_data)
void ThreadStackManagerImpl::_OnThreadBrAttachFinished(GObject * source_object, GAsyncResult * res, gpointer user_data)
{
ThreadStackManagerImpl * this_ = reinterpret_cast<ThreadStackManagerImpl *>(user_data);
std::unique_ptr<GVariant, GVariantDeleter> attachRes;
Expand Down Expand Up @@ -507,7 +507,7 @@ CHIP_ERROR ThreadStackManagerImpl::_JoinerStart()
return CHIP_ERROR_NOT_IMPLEMENTED;
}

CHIP_ERROR ThreadStackManagerImpl::StartThreadScan(ThreadDriver::ScanCallback * callback)
CHIP_ERROR ThreadStackManagerImpl::_StartThreadScan(ThreadDriver::ScanCallback * callback)
{
// There is another ongoing scan request, reject the new one.
VerifyOrReturnError(mpScanCallback == nullptr, CHIP_ERROR_INCORRECT_STATE);
Expand Down Expand Up @@ -637,8 +637,8 @@ CHIP_ERROR ThreadStackManagerImpl::_WriteThreadNetworkDiagnosticAttributeToTlv(A
}

CHIP_ERROR
ThreadStackManagerImpl::AttachToThreadNetwork(ByteSpan netInfo,
NetworkCommissioning::Internal::WirelessDriver::ConnectCallback * callback)
ThreadStackManagerImpl::_AttachToThreadNetwork(ByteSpan netInfo,
NetworkCommissioning::Internal::WirelessDriver::ConnectCallback * callback)
{
// There is another ongoing connect request, reject the new one.
VerifyOrReturnError(mpConnectCallback == nullptr, CHIP_ERROR_INCORRECT_STATE);
Expand Down
14 changes: 11 additions & 3 deletions src/platform/Linux/ThreadStackManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,13 @@ class ThreadStackManagerImpl : public ThreadStackManager

bool _IsThreadAttached();

CHIP_ERROR AttachToThreadNetwork(ByteSpan netInfo, NetworkCommissioning::Internal::WirelessDriver::ConnectCallback * callback);
CHIP_ERROR _AttachToThreadNetwork(ByteSpan netInfo, NetworkCommissioning::Internal::WirelessDriver::ConnectCallback * callback);

CHIP_ERROR _SetThreadEnabled(bool val);
static void _OnThreadAttachFinished(GObject * source_object, GAsyncResult * res, gpointer user_data);

void _OnThreadAttachFinished(void);

static void _OnThreadBrAttachFinished(GObject * source_object, GAsyncResult * res, gpointer user_data);

ConnectivityManager::ThreadDeviceType _GetThreadDeviceType();

Expand Down Expand Up @@ -100,7 +103,7 @@ class ThreadStackManagerImpl : public ThreadStackManager

CHIP_ERROR _WriteThreadNetworkDiagnosticAttributeToTlv(AttributeId attributeId, app::AttributeValueEncoder & encoder);

CHIP_ERROR StartThreadScan(NetworkCommissioning::ThreadDriver::ScanCallback * callback);
CHIP_ERROR _StartThreadScan(NetworkCommissioning::ThreadDriver::ScanCallback * callback);

~ThreadStackManagerImpl() = default;

Expand Down Expand Up @@ -145,5 +148,10 @@ class ThreadStackManagerImpl : public ThreadStackManager
bool mAttached;
};

inline void ThreadStackManagerImpl::_OnThreadAttachFinished(void)
{
// stub for ThreadStackManager.h
}

} // namespace DeviceLayer
} // namespace chip
Loading