Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit a640fe8

Browse files
committed
[Thread] Add Log, use VerifyOrExit, do thread BR advitisement only when being a router
1 parent 5a2255b commit a640fe8

File tree

2 files changed

+59
-10
lines changed

2 files changed

+59
-10
lines changed

src/adaptations/device-layer/LwIP/WarmSupport.cpp

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ namespace Platform {
5858

5959
WEAVE_ERROR Init(WarmFabricStateDelegate * inFabricStateDelegate)
6060
{
61-
#if WARM_CONFIG_SUPPORT_THREAD_ROUTING
62-
// Inform Warm of current state of thread router.
63-
Warm::ThreadRoutingStateChange(kInterfaceStateUp);
64-
#endif // WARM_CONFIG_SUPPORT_THREAD_ROUTING
61+
// Nothing to do.
6562
return WEAVE_NO_ERROR;
6663
}
6764

@@ -370,9 +367,8 @@ PlatformResult StartStopThreadAdvertisement(InterfaceType inInterfaceType, const
370367
otError otErr;
371368
otBorderRouterConfig brConfig;
372369

373-
if (inInterfaceType != kInterfaceTypeThread) { err = WEAVE_ERROR_INVALID_ARGUMENT; }
374-
if ((inPrefix.Length & 7) != 0) { err = WEAVE_ERROR_INVALID_ADDRESS; }
375-
SuccessOrExit(err);
370+
VerifyOrExit(inInterfaceType == kInterfaceTypeThread, err = WEAVE_ERROR_INVALID_ARGUMENT);
371+
VerifyOrExit((inPrefix.Length & 7) == 0, err = WEAVE_ERROR_INVALID_ADDRESS);
376372

377373
ThreadStackMgrImpl().LockThreadStack();
378374

@@ -407,6 +403,21 @@ PlatformResult StartStopThreadAdvertisement(InterfaceType inInterfaceType, const
407403
err = MapOpenThreadError(otErr);
408404

409405
exit:
406+
if (err == WEAVE_NO_ERROR)
407+
{
408+
#if WEAVE_PROGRESS_LOGGING
409+
char ipAddrStr[INET6_ADDRSTRLEN];
410+
inPrefix.IPAddr.ToString(ipAddrStr, sizeof(ipAddrStr));
411+
WeaveLogProgress(DeviceLayer, "OpenThread OnMesh Prefix %s: %s/%d",
412+
(inStart) ? "Added" : "Removed",
413+
ipAddrStr, inPrefix.Length);
414+
#endif // WEAVE_PROGRESS_LOGGING
415+
}
416+
else
417+
{
418+
WeaveLogError(DeviceLayer, "StartStopThreadAdvertisement() failed: %s", ::nl::ErrorStr(err));
419+
}
420+
410421
return (err == WEAVE_NO_ERROR) ? kPlatformResultSuccess : kPlatformResultFailure;
411422
}
412423

@@ -416,7 +427,6 @@ PlatformResult StartStopThreadAdvertisement(InterfaceType inInterfaceType, const
416427

417428
PlatformResult AddRemoveThreadRoute(InterfaceType inInterfaceType, const Inet::IPPrefix &inPrefix, RoutePriority inPriority, bool inAdd)
418429
{
419-
WEAVE_ERROR err = WEAVE_NO_ERROR;
420430
otError otErr;
421431
otExternalRouteConfig routeConfig;
422432

@@ -454,9 +464,24 @@ PlatformResult AddRemoveThreadRoute(InterfaceType inInterfaceType, const Inet::I
454464
otErr = otBorderRouterRemoveRoute(ThreadStackMgrImpl().OTInstance(), &routeConfig.mPrefix);
455465
}
456466

457-
err = MapOpenThreadError(otErr);
458467
ThreadStackMgrImpl().UnlockThreadStack();
459-
return (err == WEAVE_NO_ERROR) ? kPlatformResultSuccess : kPlatformResultFailure;
468+
469+
if (otErr == OT_ERROR_NONE)
470+
{
471+
#if WEAVE_PROGRESS_LOGGING
472+
char ipAddrStr[INET6_ADDRSTRLEN];
473+
inPrefix.IPAddr.ToString(ipAddrStr, sizeof(ipAddrStr));
474+
WeaveLogProgress(DeviceLayer, "OpenThread Border Router Route %s: %s/%d",
475+
(inAdd) ? "Added" : "Removed",
476+
ipAddrStr, inPrefix.Length);
477+
#endif // WEAVE_PROGRESS_LOGGING
478+
}
479+
else
480+
{
481+
WeaveLogError(DeviceLayer, "AddRemoveThreadRoute() failed: %s", ::nl::ErrorStr(MapOpenThreadError(otErr)));
482+
}
483+
484+
return (otErr == OT_ERROR_NONE) ? kPlatformResultSuccess : kPlatformResultFailure;
460485
}
461486

462487
PlatformResult SetThreadRoutePriority(InterfaceType inInterfaceType, const Inet::IPPrefix &inPrefix, RoutePriority inPriority)

src/adaptations/device-layer/include/Weave/DeviceLayer/internal/GenericConnectivityManagerImpl_Thread.ipp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
#include <Weave/DeviceLayer/internal/GenericConnectivityManagerImpl_Thread.h>
3030
#include <Warm/Warm.h>
3131

32+
#if WARM_CONFIG_SUPPORT_THREAD_ROUTING
33+
#include <openthread/thread.h>
34+
#endif // WARM_CONFIG_SUPPORT_THREAD_ROUTING
35+
3236
namespace nl {
3337
namespace Weave {
3438
namespace DeviceLayer {
@@ -62,6 +66,26 @@ void GenericConnectivityManagerImpl_Thread<ImplClass>::_OnPlatformEvent(const We
6266
{
6367
UpdateServiceConnectivity();
6468
}
69+
70+
#if WARM_CONFIG_SUPPORT_THREAD_ROUTING
71+
const bool threadRoleChanged = (event->Type == DeviceEventType::kThreadStateChange &&
72+
event->ThreadStateChange.RoleChanged);
73+
if (threadRoleChanged)
74+
{
75+
otDeviceRole role;
76+
ThreadStackMgrImpl().LockThreadStack();
77+
role = otThreadGetDeviceRole(ThreadStackMgrImpl().OTInstance());
78+
ThreadStackMgrImpl().UnlockThreadStack();
79+
80+
bool isThreadRouter = (role == OT_DEVICE_ROLE_LEADER || role == OT_DEVICE_ROLE_ROUTER);
81+
82+
nl::Weave::Warm::InterfaceState interfaceState = isThreadRouter
83+
? nl::Weave::Warm::kInterfaceStateUp
84+
: nl::Weave::Warm::kInterfaceStateDown;
85+
Warm::ThreadRoutingStateChange(interfaceState);
86+
}
87+
#endif // WARM_CONFIG_SUPPORT_THREAD_ROUTING
88+
6589
}
6690

6791
template<class ImplClass>

0 commit comments

Comments
 (0)