From 0c8c10869a1f6ecde78af2aeb4410e10da06bd54 Mon Sep 17 00:00:00 2001 From: WanqQixiang Date: Thu, 25 May 2023 15:15:53 +0800 Subject: [PATCH] ESP32: Update managed mdns component version to v1.1.x --- .../esp32/components/chip/idf_component.yml | 2 +- src/platform/ESP32/WiFiDnssdImpl.cpp | 37 +++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/config/esp32/components/chip/idf_component.yml b/config/esp32/components/chip/idf_component.yml index b9ce7591b88dd6..0fa26e3c85b2a2 100644 --- a/config/esp32/components/chip/idf_component.yml +++ b/config/esp32/components/chip/idf_component.yml @@ -1,7 +1,7 @@ ## IDF Component Manager Manifest File dependencies: espressif/mdns: - version: "^1.0.3" + version: "^1.1.0" rules: - if: "idf_version >=5.0" - if: "target != esp32h2" diff --git a/src/platform/ESP32/WiFiDnssdImpl.cpp b/src/platform/ESP32/WiFiDnssdImpl.cpp index 4900bf08b37002..79c839b27ecc2f 100644 --- a/src/platform/ESP32/WiFiDnssdImpl.cpp +++ b/src/platform/ESP32/WiFiDnssdImpl.cpp @@ -282,10 +282,26 @@ static CHIP_ERROR OnBrowseDone(BrowseContext * ctx) CHIP_ERROR error = CHIP_NO_ERROR; mdns_result_t * currentResult = nullptr; size_t servicesIndex = 0; +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) + mdns_result_t * delegatedResults = nullptr; +#endif VerifyOrExit(ctx && ctx->mBrowseCb, error = CHIP_ERROR_INVALID_ARGUMENT); - if (ctx->mPtrQueryResult) + ctx->mServiceSize = GetResultSize(ctx->mPtrQueryResult); +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) + mdns_lookup_delegated_service(NULL, ctx->mType, GetProtocolString(ctx->mProtocol), kMaxResults - ctx->mServiceSize, + &delegatedResults); + while (delegatedResults) + { + mdns_result_t * tmp = delegatedResults->next; + delegatedResults->next = ctx->mPtrQueryResult; + ctx->mPtrQueryResult = delegatedResults; + delegatedResults = tmp; + ctx->mServiceSize++; + } +#endif // ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) + + if (ctx->mPtrQueryResult && ctx->mServiceSize > 0) { - ctx->mServiceSize = GetResultSize(ctx->mPtrQueryResult); if (ctx->mServiceSize > 0) { ctx->mService = static_cast(chip::Platform::MemoryCalloc(ctx->mServiceSize, sizeof(DnssdService))); @@ -484,7 +500,14 @@ static void MdnsQueryDone(intptr_t context) ResolveContext * resolveCtx = reinterpret_cast(ctx); if (resolveCtx->mSrvQueryHandle == queryHandle) { - // No result found. +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) + // No result found, look up delegated services. + if (!result) + { + mdns_lookup_delegated_service(resolveCtx->mInstanceName, resolveCtx->mType, + GetProtocolString(resolveCtx->mProtocol), kMaxResults, &result); + } +#endif if (!result) { resolveCtx->mResolveCb(ctx->mCbContext, nullptr, Span(nullptr, 0), CHIP_ERROR_INVALID_ARGUMENT); @@ -529,6 +552,14 @@ static void MdnsQueryDone(intptr_t context) } else if (resolveCtx->mTxtQueryHandle == queryHandle) { +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) + // No result found, look up delegated services. + if (!result) + { + mdns_lookup_delegated_service(resolveCtx->mInstanceName, resolveCtx->mType, + GetProtocolString(resolveCtx->mProtocol), kMaxResults, &result); + } +#endif resolveCtx->mTxtQueryResult = result; resolveCtx->mTxtQueryFinished = true; }