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

[zephyr] Fix Network Commissioning after switching to new API #14891

Merged
merged 1 commit into from
Feb 8, 2022
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
3 changes: 1 addition & 2 deletions src/lib/support/ThreadOperationalDataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,7 @@ void OperationalDataset::UnsetPSKc(void)

bool OperationalDataset::IsCommissioned(void) const
{
return Has(ThreadTLV::kNetworkName) && Has(ThreadTLV::kPanId) && Has(ThreadTLV::kMasterKey) && Has(ThreadTLV::kExtendedPanId) &&
Has(ThreadTLV::kChannel);
return Has(ThreadTLV::kPanId) && Has(ThreadTLV::kMasterKey) && Has(ThreadTLV::kExtendedPanId) && Has(ThreadTLV::kChannel);
}

const ThreadTLV * OperationalDataset::Locate(uint8_t aType) const
Expand Down
26 changes: 18 additions & 8 deletions src/platform/Zephyr/ThreadStackManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ CHIP_ERROR ThreadStackManagerImpl::_InitThreadStack()
return CHIP_NO_ERROR;
}

CHIP_ERROR ThreadStackManagerImpl::_StartThreadTask()
{
// Intentionally empty.
return CHIP_NO_ERROR;
}

void ThreadStackManagerImpl::_LockThreadStack()
{
openthread_api_mutex_lock(openthread_get_default_context());
Expand All @@ -83,9 +77,25 @@ void ThreadStackManagerImpl::_UnlockThreadStack()
openthread_api_mutex_unlock(openthread_get_default_context());
}

void ThreadStackManagerImpl::_ProcessThreadActivity()
void ThreadStackManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event)
{
// Intentionally empty.
Internal::GenericThreadStackManagerImpl_OpenThread<ThreadStackManagerImpl>::_OnPlatformEvent(event);

if (event->Type == DeviceEventType::kThreadStateChange && event->ThreadStateChange.RoleChanged)
{
const bool isAttached = IsThreadAttached();
VerifyOrReturn(isAttached != mIsAttached);

ChipDeviceEvent attachEvent;
attachEvent.Type = DeviceEventType::kThreadConnectivityChange;
attachEvent.ThreadConnectivityChange.Result = isAttached ? kConnectivity_Established : kConnectivity_Lost;

CHIP_ERROR error = PlatformMgr().PostEvent(&attachEvent);
VerifyOrReturn(error == CHIP_NO_ERROR,
ChipLogError(DeviceLayer, "Failed to post Thread connectivity change: %" CHIP_ERROR_FORMAT, error.Format()));

mIsAttached = isAttached;
}
}

} // namespace DeviceLayer
Expand Down
7 changes: 4 additions & 3 deletions src/platform/Zephyr/ThreadStackManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,15 @@ class ThreadStackManagerImpl final : public ThreadStackManager,
protected:
// ===== Methods that implement the ThreadStackManager abstract interface.

CHIP_ERROR _StartThreadTask();
CHIP_ERROR _StartThreadTask() { return CHIP_NO_ERROR; }
void _LockThreadStack();
bool _TryLockThreadStack();
void _UnlockThreadStack();

// ===== Methods that override the GenericThreadStackManagerImpl_OpenThread abstract interface.

void _ProcessThreadActivity();
void _ProcessThreadActivity() {}
void _OnPlatformEvent(const ChipDeviceEvent * event);

//} // namespace Internal

Expand All @@ -85,7 +86,7 @@ class ThreadStackManagerImpl final : public ThreadStackManager,

// ===== Private members for use by this class only.

ThreadStackManagerImpl() = default;
bool mIsAttached = false;
};

/**
Expand Down