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

OpenThread: added Thread interface enabled support #33860

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ CHIP_ERROR GenericThreadDriver::RevertConfiguration()
// since the fail-safe was armed, so return with no error.
ReturnErrorCodeIf(error == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND, CHIP_NO_ERROR);

if (!GetEnabled())
{
// If backup is found, set InterfaceEnabled to default value (true).
ReturnErrorOnFailure(PersistedStorage::KeyValueStoreMgr().Delete(kInterfaceEnabled));
}

ChipLogProgress(NetworkProvisioning, "Reverting Thread operational dataset");

if (error == CHIP_NO_ERROR)
Expand Down Expand Up @@ -166,6 +172,12 @@ void GenericThreadDriver::ConnectNetwork(ByteSpan networkId, ConnectCallback * c
{
NetworkCommissioning::Status status = MatchesNetworkId(mStagingNetwork, networkId);

if (!GetEnabled())
{
// Set InterfaceEnabled to default value (true).
ReturnOnFailure(PersistedStorage::KeyValueStoreMgr().Delete(kInterfaceEnabled));
}

if (status == Status::kSuccess && BackupConfiguration() != CHIP_NO_ERROR)
{
status = Status::kUnknownError;
Expand All @@ -183,6 +195,31 @@ void GenericThreadDriver::ConnectNetwork(ByteSpan networkId, ConnectCallback * c
}
}

CHIP_ERROR GenericThreadDriver::SetEnabled(bool enabled)
{
if (enabled == GetEnabled())
{
return CHIP_NO_ERROR;
}

ReturnErrorOnFailure(PersistedStorage::KeyValueStoreMgr().Put(kInterfaceEnabled, &enabled, sizeof(enabled)));

if ((!enabled && DeviceLayer::ThreadStackMgrImpl().IsThreadEnabled()) ||
(enabled && DeviceLayer::ThreadStackMgrImpl().IsThreadProvisioned()))
{
ReturnErrorOnFailure(DeviceLayer::ThreadStackMgrImpl().SetThreadEnabled(enabled));
}
return CHIP_NO_ERROR;
}

bool GenericThreadDriver::GetEnabled()
{
bool value;
// InterfaceEnabled default value is true.
VerifyOrReturnValue(PersistedStorage::KeyValueStoreMgr().Get(kInterfaceEnabled, &value, sizeof(value)) == CHIP_NO_ERROR, true);
return value;
}

void GenericThreadDriver::ScanNetworks(ThreadDriver::ScanCallback * callback)
{
if (DeviceLayer::ThreadStackMgrImpl().StartThreadScan(callback) != CHIP_NO_ERROR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class GenericThreadDriver final : public ThreadDriver
// BaseDriver
NetworkIterator * GetNetworks() override { return new ThreadNetworkIterator(this); }
CHIP_ERROR Init(Internal::BaseDriver::NetworkStatusChangeCallback * statusChangeCallback) override;
CHIP_ERROR SetEnabled(bool enabled) override;
bool GetEnabled() override;
void Shutdown() override;

// WirelessDriver
Expand All @@ -114,6 +116,7 @@ class GenericThreadDriver final : public ThreadDriver
void ScanNetworks(ThreadDriver::ScanCallback * callback) override;

private:
static constexpr const char * kInterfaceEnabled = "g/gtd/en";
uint8_t scanNetworkTimeoutSeconds;
uint8_t connectNetworkTimeout;
static void OnThreadStateChangeHandler(const ChipDeviceEvent * event, intptr_t arg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,9 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::DoInit(otInstanc
CHIP_ERROR err = CHIP_NO_ERROR;
otError otErr = OT_ERROR_NONE;

// If InterfaceEnabled is false, do not start Thread
bool InterfaceEnabled = true;

// Arrange for OpenThread errors to be translated to text.
RegisterOpenThreadErrorFormatter();

Expand Down Expand Up @@ -1131,8 +1134,12 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::DoInit(otInstanc
memset(&mSrpClient, 0, sizeof(mSrpClient));
#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT

#ifndef _NO_NETWORK_COMMISSIONING_DRIVER_
InterfaceEnabled = sGenericThreadDriver.GetEnabled();
#endif

// If the Thread stack has been provisioned, but is not currently enabled, enable it now.
if (otThreadGetDeviceRole(mOTInst) == OT_DEVICE_ROLE_DISABLED && otDatasetIsCommissioned(otInst))
if (InterfaceEnabled && otThreadGetDeviceRole(mOTInst) == OT_DEVICE_ROLE_DISABLED && otDatasetIsCommissioned(otInst))
{
// Enable the Thread IPv6 interface.
otErr = otIp6SetEnabled(otInst, true);
Expand Down
Loading