Skip to content

Commit 4393123

Browse files
jwhuipull[bot]
authored andcommitted
openthread: enable SRP Client auto host address mode (#19981)
This commit enables "auto host address mode" in SRP client. When enabled, host IPv6 addresses are automatically set by SRP client using all the unicast addresses on Thread netif excluding the link-local and mesh-local addresses. If there is no valid address, then Mesh Local EID address is added. The SRP client will automatically re-register when/if addresses on Thread netif are updated (e.g., new addresses are added or existing addresses are removed).
1 parent 2d8180f commit 4393123

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ void GenericThreadStackManagerImpl_OpenThread<ImplClass>::_OnPlatformEvent(const
190190
{
191191
if (event->Type == DeviceEventType::kThreadStateChange)
192192
{
193-
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
193+
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT && (OPENTHREAD_API_VERSION < 218)
194194
if (event->ThreadStateChange.AddressChanged)
195195
{
196196
const otSrpClientHostInfo * hostInfo = otSrpClientGetHostInfo(Impl()->OTInstance());
@@ -2301,7 +2301,9 @@ template <class ImplClass>
23012301
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_SetupSrpHost(const char * aHostName)
23022302
{
23032303
CHIP_ERROR error = CHIP_NO_ERROR;
2304+
#if OPENTHREAD_API_VERSION < 218
23042305
Inet::IPAddress hostAddress;
2306+
#endif
23052307

23062308
VerifyOrReturnError(mSrpClient.mIsInitialized, CHIP_ERROR_WELL_UNINITIALIZED);
23072309

@@ -2316,15 +2318,21 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_SetupSrpHost(co
23162318
strcpy(mSrpClient.mHostName, aHostName);
23172319
error = MapOpenThreadError(otSrpClientSetHostName(mOTInst, mSrpClient.mHostName));
23182320
SuccessOrExit(error);
2321+
2322+
#if OPENTHREAD_API_VERSION >= 218
2323+
error = MapOpenThreadError(otSrpClientEnableAutoHostAddress(mOTInst));
2324+
#endif
23192325
}
23202326

2327+
#if OPENTHREAD_API_VERSION < 218
23212328
// Check if device has any external IPv6 assigned. If not, host will be set without IPv6 addresses
23222329
// and updated later on.
23232330
if (ThreadStackMgr().GetExternalIPv6Address(hostAddress) == CHIP_NO_ERROR)
23242331
{
23252332
memcpy(&mSrpClient.mHostAddress.mFields.m32, hostAddress.Addr, sizeof(hostAddress.Addr));
23262333
error = MapOpenThreadError(otSrpClientSetHostAddresses(mOTInst, &mSrpClient.mHostAddress, 1));
23272334
}
2335+
#endif
23282336

23292337
exit:
23302338
Impl()->UnlockThreadStack();

0 commit comments

Comments
 (0)