@@ -88,12 +88,16 @@ struct mDnsQueryCtx
8888
8989 mDnsQueryCtx (void * context, DnsBrowseCallback aBrowseCallback)
9090 {
91+ link.next = nullptr ;
92+ link.list = nullptr ;
9193 matterCtx = context;
9294 mDnsBrowseCallback = aBrowseCallback;
9395 error = CHIP_NO_ERROR;
9496 }
9597 mDnsQueryCtx (void * context, DnsResolveCallback aResolveCallback)
9698 {
99+ link.next = nullptr ;
100+ link.list = nullptr ;
97101 matterCtx = context;
98102 mDnsResolveCallback = aResolveCallback;
99103 error = CHIP_NO_ERROR;
@@ -127,6 +131,7 @@ static void DispatchBrowse(intptr_t context);
127131static void DispatchTxtResolve (intptr_t context);
128132static void DispatchAddressResolve (intptr_t context);
129133static void DispatchResolve (intptr_t context);
134+ static void DispatchResolveSrp (intptr_t context);
130135static void DispatchResolveError (intptr_t context);
131136
132137static void HandleResolveCleanup (mDnsQueryCtx & resolveContext, ResolveStep stepType);
@@ -186,7 +191,6 @@ void NxpChipDnssdShutdown()
186191 // Stop all browse operations and clean the browse list
187192 otInstance * thrInstancePtr = ThreadStackMgrImpl ().OTInstance ();
188193 mDnsQueryCtx * pQueryContext = reinterpret_cast <mDnsQueryCtx *>(LIST_GetHead (&mBrowseList ));
189- ;
190194
191195 while (pQueryContext)
192196 {
@@ -609,7 +613,7 @@ CHIP_ERROR ResolveBySrp(otInstance * thrInstancePtr, char * serviceName, mDnsQue
609613 error = FromSrpCacheToMdnsData (service, host, mdnsReq, context->mMdnsService , context->mServiceTxtEntry );
610614 if (error == CHIP_NO_ERROR)
611615 {
612- DeviceLayer::PlatformMgr ().ScheduleWork (DispatchResolve , reinterpret_cast <intptr_t >(context));
616+ DeviceLayer::PlatformMgr ().ScheduleWork (DispatchResolveSrp , reinterpret_cast <intptr_t >(context));
613617 }
614618 break ;
615619 }
@@ -878,7 +882,8 @@ static void OtTxtCallback(otInstance * aInstance, const otMdnsTxtResult * aResul
878882
879883 if (alloc.AnyAllocFailed ())
880884 {
881- bSendDispatch = false ;
885+ bSendDispatch = false ;
886+ pResolveContext->error = CHIP_ERROR_NO_MEMORY;
882887 }
883888 else
884889 {
@@ -992,6 +997,24 @@ static void DispatchResolve(intptr_t context)
992997 Platform::Delete<mDnsQueryCtx >(pResolveContext);
993998}
994999
1000+ static void DispatchResolveSrp (intptr_t context)
1001+ {
1002+ mDnsQueryCtx * pResolveContext = reinterpret_cast <mDnsQueryCtx *>(context);
1003+ Dnssd::DnssdService & service = pResolveContext->mMdnsService ;
1004+ Span<Inet::IPAddress> ipAddrs;
1005+
1006+ // Address resolver was not started and the resolve context was not added to the resolve list
1007+ // when the result came directly from SRP.
1008+
1009+ if (service.mAddress .has_value ())
1010+ {
1011+ ipAddrs = Span<Inet::IPAddress>(&*service.mAddress , 1 );
1012+ }
1013+
1014+ pResolveContext->mDnsResolveCallback (pResolveContext->matterCtx , &service, ipAddrs, pResolveContext->error );
1015+ Platform::Delete<mDnsQueryCtx >(pResolveContext);
1016+ }
1017+
9951018static void DispatchResolveError (intptr_t context)
9961019{
9971020 mDnsQueryCtx * pResolveContext = reinterpret_cast <mDnsQueryCtx *>(context);
@@ -1021,7 +1044,11 @@ static void HandleResolveCleanup(mDnsQueryCtx & resolveContext, ResolveStep step
10211044 break ;
10221045 }
10231046
1024- DeviceLayer::PlatformMgr ().ScheduleWork (DispatchResolve, reinterpret_cast <intptr_t >(&resolveContext));
1047+ // In this case the resolve operation could not be completed successfully so we need to call
1048+ // DispatchResolveError to handle the Matter callback with an error case. No IP address is reported and
1049+ // the address resolve operation doesn’t need to be stopped again as was not started in the first place
1050+ // or it's already handled by HandleResolveCleanup.
1051+ DeviceLayer::PlatformMgr ().ScheduleWork (DispatchResolveError, reinterpret_cast <intptr_t >(&resolveContext));
10251052}
10261053
10271054static mDnsQueryCtx * GetResolveElement (const char * aName, NameType aType)
0 commit comments