From 53fcc9d72a8d060baf54ec350a7fcb355f0fe875 Mon Sep 17 00:00:00 2001 From: lezhan Date: Fri, 27 Sep 2024 05:43:55 +0000 Subject: [PATCH] [api] enable DIAG_GET query function into commissioner This PR adds DIAG_GET query command into the commissioner module, allowing users to query one or more diagnostic TLVs from a peer Thread device by setting the device's mesh local address than TLV mask bits flag. Test: config set pskc 445f2b5ca6f2a93a55ce570a70efeecb [done] start 192.168.9.2 49154 [done] diag query ipaddr fdce:bb1d:37f6:6978:0:ff:fe00:cc00 Peer Address: fd74:95e3:6ec:feee:0:ff:fe00:ac00 Content: { "Ipv6 Addresses": [ "fd74:95e3:06ec:feee:0000:00ff:fe00:fc36", "fd74:95e3:06ec:feee:0000:00ff:fe00:fc11", "fd74:95e3:06ec:feee:0000:00ff:fe00:fc10", "fd74:95e3:06ec:feee:0000:00ff:fe00:fc38", "fd11:0022:0000:0000:99e7:cece:d50d:ae6b", "fd74:95e3:06ec:feee:0000:00ff:fe00:fc00", "fd74:95e3:06ec:feee:0000:00ff:fe00:ac00", "fd74:95e3:06ec:feee:6142:033d:b087:2845", "fe80:0000:0000:0000:9cbb:e247:df46:9e70" ] } [done] --- include/commissioner/commissioner.hpp | 1 + src/app/cli/interpreter.cpp | 82 +++++++++++++++++++-------- src/app/commissioner_app.cpp | 10 +++- src/app/commissioner_app.hpp | 6 +- 4 files changed, 71 insertions(+), 28 deletions(-) diff --git a/include/commissioner/commissioner.hpp b/include/commissioner/commissioner.hpp index a7df2d79..2797998b 100644 --- a/include/commissioner/commissioner.hpp +++ b/include/commissioner/commissioner.hpp @@ -269,6 +269,7 @@ class CommissionerHandler */ virtual void OnDiagGetAnswerMessage(const std::string &aDestAddress, const NetDiagTlvs &aDiagAnsMsg) { + (void)aDestAddress; (void)aDiagAnsMsg; } diff --git a/src/app/cli/interpreter.cpp b/src/app/cli/interpreter.cpp index 329e027a..aad2d9a3 100644 --- a/src/app/cli/interpreter.cpp +++ b/src/app/cli/interpreter.cpp @@ -2612,9 +2612,13 @@ Interpreter::Value Interpreter::ProcessDiagJob(CommissionerAppPtr &aCommissioner { SuccessOrExit(value = aCommissioner->CommandDiagGetQuery(dstAddr, flags)); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - tlvs = aCommissioner->GetNetDiagTlvs(); - tlvs.mPresentFlags = flags; - value = NetDiagTlvsToJson(tlvs); + tlvs.mPresentFlags = flags; + DiagAnsDataMap diagAnsDataMaps = aCommissioner->GetNetDiagTlvs(); + for (std::map::iterator it = diagAnsDataMaps.begin(); it != diagAnsDataMaps.end(); + ++it) + { + value = "Peer Address: " + (it->first).ToString() + "\nContent: " + NetDiagTlvsToJson(it->second); + } } } @@ -2625,9 +2629,13 @@ Interpreter::Value Interpreter::ProcessDiagJob(CommissionerAppPtr &aCommissioner { SuccessOrExit(value = aCommissioner->CommandDiagGetQuery(dstAddr, flags)); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - tlvs = aCommissioner->GetNetDiagTlvs(); - tlvs.mPresentFlags = flags; - value = NetDiagTlvsToJson(tlvs); + tlvs.mPresentFlags = flags; + DiagAnsDataMap diagAnsDataMaps = aCommissioner->GetNetDiagTlvs(); + for (std::map::iterator it = diagAnsDataMaps.begin(); it != diagAnsDataMaps.end(); + ++it) + { + value = "Peer Address: " + (it->first).ToString() + "\nContent: " + NetDiagTlvsToJson(it->second); + } } } if (CaseInsensitiveEqual(aExpr[2], "mode")) @@ -2637,9 +2645,13 @@ Interpreter::Value Interpreter::ProcessDiagJob(CommissionerAppPtr &aCommissioner { SuccessOrExit(value = aCommissioner->CommandDiagGetQuery(dstAddr, flags)); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - tlvs = aCommissioner->GetNetDiagTlvs(); - tlvs.mPresentFlags = flags; - value = ModeToJson(tlvs.mMode); + tlvs.mPresentFlags = flags; + DiagAnsDataMap diagAnsDataMaps = aCommissioner->GetNetDiagTlvs(); + for (std::map::iterator it = diagAnsDataMaps.begin(); it != diagAnsDataMaps.end(); + ++it) + { + value = "Peer Address: " + (it->first).ToString() + "\nContent: " + ModeToJson(it->second.mMode); + } } } if (CaseInsensitiveEqual(aExpr[2], "route64")) @@ -2649,9 +2661,13 @@ Interpreter::Value Interpreter::ProcessDiagJob(CommissionerAppPtr &aCommissioner { SuccessOrExit(value = aCommissioner->CommandDiagGetQuery(dstAddr, flags)); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - tlvs = aCommissioner->GetNetDiagTlvs(); - tlvs.mPresentFlags = flags; - value = Route64ToJson(tlvs.mRoute64); + tlvs.mPresentFlags = flags; + DiagAnsDataMap diagAnsDataMaps = aCommissioner->GetNetDiagTlvs(); + for (std::map::iterator it = diagAnsDataMaps.begin(); it != diagAnsDataMaps.end(); + ++it) + { + value = "Peer Address: " + (it->first).ToString() + "\nContent: " + Route64ToJson(it->second.mRoute64); + } } } if (CaseInsensitiveEqual(aExpr[2], "leaderdata")) @@ -2661,9 +2677,14 @@ Interpreter::Value Interpreter::ProcessDiagJob(CommissionerAppPtr &aCommissioner { SuccessOrExit(value = aCommissioner->CommandDiagGetQuery(dstAddr, flags)); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - tlvs = aCommissioner->GetNetDiagTlvs(); - tlvs.mPresentFlags = flags; - value = LeaderDataToJson(tlvs.mLeaderData); + tlvs.mPresentFlags = flags; + DiagAnsDataMap diagAnsDataMaps = aCommissioner->GetNetDiagTlvs(); + for (std::map::iterator it = diagAnsDataMaps.begin(); it != diagAnsDataMaps.end(); + ++it) + { + value = "Peer Address: " + (it->first).ToString() + + "\nContent: " + LeaderDataToJson(it->second.mLeaderData); + } } } if (CaseInsensitiveEqual(aExpr[2], "eui64")) @@ -2673,9 +2694,13 @@ Interpreter::Value Interpreter::ProcessDiagJob(CommissionerAppPtr &aCommissioner { SuccessOrExit(value = aCommissioner->CommandDiagGetQuery(dstAddr, flags)); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - tlvs = aCommissioner->GetNetDiagTlvs(); - tlvs.mPresentFlags = flags; - value = NetDiagTlvsToJson(tlvs); + tlvs.mPresentFlags = flags; + DiagAnsDataMap diagAnsDataMaps = aCommissioner->GetNetDiagTlvs(); + for (std::map::iterator it = diagAnsDataMaps.begin(); it != diagAnsDataMaps.end(); + ++it) + { + value = "Peer Address: " + (it->first).ToString() + "\nContent: " + NetDiagTlvsToJson(it->second); + } } } if (CaseInsensitiveEqual(aExpr[2], "ipaddr")) @@ -2685,8 +2710,14 @@ Interpreter::Value Interpreter::ProcessDiagJob(CommissionerAppPtr &aCommissioner { SuccessOrExit(value = aCommissioner->CommandDiagGetQuery(dstAddr, flags)); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - tlvs = aCommissioner->GetNetDiagTlvs(); - value = Ipv6AddressToJson(tlvs.mIpv6Addresses); + tlvs.mPresentFlags = flags; + DiagAnsDataMap diagAnsDataMaps = aCommissioner->GetNetDiagTlvs(); + for (std::map::iterator it = diagAnsDataMaps.begin(); it != diagAnsDataMaps.end(); + ++it) + { + value = "Peer Address: " + (it->first).ToString() + + "\nContent: " + Ipv6AddressToJson(it->second.mIpv6Addresses); + } } } if (CaseInsensitiveEqual(aExpr[2], "childtable")) @@ -2696,9 +2727,14 @@ Interpreter::Value Interpreter::ProcessDiagJob(CommissionerAppPtr &aCommissioner { SuccessOrExit(value = aCommissioner->CommandDiagGetQuery(dstAddr, flags)); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - tlvs = aCommissioner->GetNetDiagTlvs(); - tlvs.mPresentFlags = flags; - value = ChildTableToJson(tlvs.mChildTable); + tlvs.mPresentFlags = flags; + DiagAnsDataMap diagAnsDataMaps = aCommissioner->GetNetDiagTlvs(); + for (std::map::iterator it = diagAnsDataMaps.begin(); it != diagAnsDataMaps.end(); + ++it) + { + value = "Peer Address: " + (it->first).ToString() + + "\nContent: " + ChildTableToJson(it->second.mChildTable); + } } } exit: diff --git a/src/app/commissioner_app.cpp b/src/app/commissioner_app.cpp index de7702c3..cdecb024 100644 --- a/src/app/commissioner_app.cpp +++ b/src/app/commissioner_app.cpp @@ -1401,12 +1401,16 @@ Error CommissionerApp::CommandDiagGetQuery(const std::string &aAddr, uint64_t aD void CommissionerApp::OnDiagGetAnswerMessage(const std::string &aDestAddress, const NetDiagTlvs &aDiagAnsMsg) { - mNetDiagTlvs = aDiagAnsMsg; + Address addr; + + SuccessOrDie(addr.Set(aDestAddress)); + + mDiagAnsDataMap[addr] = aDiagAnsMsg; } -NetDiagTlvs CommissionerApp::GetNetDiagTlvs() const +DiagAnsDataMap CommissionerApp::GetNetDiagTlvs() const { - return mNetDiagTlvs; + return mDiagAnsDataMap; } } // namespace commissioner diff --git a/src/app/commissioner_app.hpp b/src/app/commissioner_app.hpp index 16ce84ac..30520705 100644 --- a/src/app/commissioner_app.hpp +++ b/src/app/commissioner_app.hpp @@ -64,6 +64,8 @@ struct EnergyReport }; using EnergyReportMap = std::map; +using DiagAnsDataMap = std::map; + /** * @brief Enumeration of Joiner Type for steering. * @@ -280,7 +282,7 @@ class CommissionerApp : public CommissionerHandler MOCKABLE const EnergyReportMap &GetAllEnergyReports() const; const std::string &GetDomainName() const; - NetDiagTlvs GetNetDiagTlvs() const; + DiagAnsDataMap GetNetDiagTlvs() const; protected: CommissionerApp() = default; @@ -331,7 +333,7 @@ class CommissionerApp : public CommissionerHandler PendingOperationalDataset mPendingDataset; CommissionerDataset mCommDataset; BbrDataset mBbrDataset; - NetDiagTlvs mNetDiagTlvs; + DiagAnsDataMap mDiagAnsDataMap; }; Error CommissionerAppCreate(std::shared_ptr &aCommApp, const Config &aConfig);