Skip to content

Commit ceda4a7

Browse files
committed
06/01 addressing additional stack PR reviews
1 parent 9e8d938 commit ceda4a7

21 files changed

Lines changed: 255 additions & 216 deletions

examples/platforms/simulation/radio.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,17 +1168,23 @@ void otPlatRadioSetWakeKey(otInstance *aInstance, uint8_t aKeyIndex, const otMac
11681168
OT_UNUSED_VARIABLE(aKeyIndex);
11691169
OT_UNUSED_VARIABLE(aWakeKey);
11701170
}
1171+
#endif
1172+
1173+
#if OPENTHREAD_CONFIG_THREAD_DIRECT_WAKE_INITIATOR_ENABLE
1174+
static uint32_t sWakeFrameCounter;
11711175

11721176
void otPlatRadioSetWakeFrameCounter(otInstance *aInstance, uint32_t aWakeFrameCounter)
11731177
{
11741178
OT_UNUSED_VARIABLE(aInstance);
1175-
OT_UNUSED_VARIABLE(aWakeFrameCounter);
1179+
1180+
sWakeFrameCounter = aWakeFrameCounter;
11761181
}
11771182

11781183
uint32_t otPlatRadioGetWakeFrameCounter(otInstance *aInstance)
11791184
{
11801185
OT_UNUSED_VARIABLE(aInstance);
1181-
return 0;
1186+
1187+
return sWakeFrameCounter;
11821188
}
11831189
#endif
11841190

include/openthread/thread_direct.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ typedef void (*otThreadDirectEventCallback)(otThreadDirectEvent aEvent
116116
* Valid for both WI and WL roles. A subsequent call replaces any previously
117117
* registered callback. Pass NULL to clear.
118118
*
119+
* Requires `OPENTHREAD_CONFIG_THREAD_DIRECT_WAKE_INITIATOR_ENABLE` or
120+
* `OPENTHREAD_CONFIG_THREAD_DIRECT_WAKE_LISTENER_ENABLE`.
121+
*
119122
* @param[in] aInstance The OpenThread instance.
120123
* @param[in] aCallback The callback function pointer, or NULL to clear.
121124
* @param[in] aContext Application-specific context pointer passed to @p aCallback.
@@ -164,6 +167,8 @@ typedef enum
164167
* or @p aKeyIndex is out of range.
165168
* @retval OT_ERROR_INVALID_STATE A wake burst is already in progress, or @p aKeyIndex is a
166169
* guest index for which no key has been provisioned.
170+
*
171+
* Requires `OPENTHREAD_CONFIG_THREAD_DIRECT_WAKE_INITIATOR_ENABLE`.
167172
*/
168173
otError otThreadDirectWakeup(otInstance *aInstance,
169174
const otExtAddress *aExtAddress,
@@ -194,14 +199,17 @@ otError otThreadDirectUnlink(otInstance *aInstance, const otExtAddress *aExtAddr
194199
* @param[in] aInstance The OpenThread instance.
195200
* @param[in] aEnable TRUE to enable WL listen mode; FALSE to disable.
196201
*
197-
* @retval OT_ERROR_NONE Mode updated.
198-
* @retval OT_ERROR_NOT_IMPLEMENTED Feature is not implemented.
202+
* @retval OT_ERROR_NONE Mode updated.
203+
*
204+
* Requires `OPENTHREAD_CONFIG_THREAD_DIRECT_WAKE_LISTENER_ENABLE`.
199205
*/
200206
otError otThreadDirectWakeListenerEnable(otInstance *aInstance, bool aEnable);
201207

202208
/**
203209
* Returns whether WL wake channel listening is currently active.
204210
*
211+
* Requires `OPENTHREAD_CONFIG_THREAD_DIRECT_WAKE_LISTENER_ENABLE`.
212+
*
205213
* @param[in] aInstance The OpenThread instance.
206214
*
207215
* @returns TRUE if the WL is listening for TD Wake Commands, FALSE otherwise.
@@ -215,6 +223,8 @@ bool otThreadDirectIsWakeListenerEnabled(otInstance *aInstance);
215223
* immediately follows, during which the WI waits for a TD Link Command from
216224
* the WL.
217225
*
226+
* Requires `OPENTHREAD_CONFIG_THREAD_DIRECT_WAKE_INITIATOR_ENABLE`.
227+
*
218228
* @param[in] aInstance The OpenThread instance.
219229
*
220230
* @returns TRUE if a wake burst or connection window is active, FALSE otherwise.
@@ -225,6 +235,9 @@ bool otThreadDirectIsWakeBurstActive(otInstance *aInstance);
225235
* Configures the Scheduled Listen Window (SLW) period this device advertises to
226236
* its peer in the SCA LTV. Both WI and WL may call this function.
227237
*
238+
* Requires `OPENTHREAD_CONFIG_THREAD_DIRECT_WAKE_INITIATOR_ENABLE` or
239+
* `OPENTHREAD_CONFIG_THREAD_DIRECT_WAKE_LISTENER_ENABLE`.
240+
*
228241
* Phase is a dynamic, stack-computed value (time until the next SLW window at
229242
* frame-build time) and is not configurable by the application.
230243
*
@@ -282,7 +295,8 @@ typedef struct otThreadDirectLocalSca
282295
*
283296
* @retval OT_ERROR_NONE Parameters stored.
284297
* @retval OT_ERROR_INVALID_ARGS @p aParams is NULL, @p aParams->mDuration is 0,
285-
* or @p aParams->mDuration is outside [1, 31].
298+
* @p aParams->mDuration is outside [1, 31], or
299+
* @p aParams->mOffsetUs is outside [-1024, 1023].
286300
*/
287301
otError otThreadDirectSetRamOverride(otInstance *aInstance, const otThreadDirectRamParams *aParams);
288302

src/cli/cli_td.cpp

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,16 @@ namespace Cli {
4747

4848
// clang-format off
4949
const ThreadDirect::Command ThreadDirect::sCommands[] = {
50-
{"channel", &ThreadDirect::ProcessChannel},
51-
{"help", &ThreadDirect::ProcessHelp},
52-
{"link", &ThreadDirect::ProcessLink},
53-
{"unlink", &ThreadDirect::ProcessUnlink},
54-
{"wake", &ThreadDirect::ProcessWake},
50+
{"channel", &ThreadDirect::ProcessChannel},
51+
{"help", &ThreadDirect::ProcessHelp},
52+
{"link", &ThreadDirect::ProcessLink},
53+
{"unlink", &ThreadDirect::ProcessUnlink},
54+
#if OPENTHREAD_CONFIG_THREAD_DIRECT_WAKE_INITIATOR_ENABLE
55+
{"wake", &ThreadDirect::ProcessWake},
56+
#endif
57+
#if OPENTHREAD_CONFIG_THREAD_DIRECT_WAKE_LISTENER_ENABLE
5558
{"wakelisten", &ThreadDirect::ProcessWakeListen},
59+
#endif
5660
};
5761
// clang-format on
5862

@@ -128,12 +132,6 @@ otError ThreadDirect::ProcessWake(Arg aArgs[])
128132
exit:
129133
return error;
130134
}
131-
#else
132-
otError ThreadDirect::ProcessWake(Arg aArgs[])
133-
{
134-
OT_UNUSED_VARIABLE(aArgs);
135-
return OT_ERROR_NOT_IMPLEMENTED;
136-
}
137135
#endif // OPENTHREAD_CONFIG_THREAD_DIRECT_WAKE_INITIATOR_ENABLE
138136

139137
void ThreadDirect::HandleDirectEvent(otThreadDirectEvent aEvent,
@@ -175,9 +173,9 @@ void ThreadDirect::HandleDirectEvent(otThreadDirectEvent aEvent, const otThreadD
175173
}
176174
}
177175

176+
#if OPENTHREAD_CONFIG_THREAD_DIRECT_WAKE_LISTENER_ENABLE
178177
otError ThreadDirect::ProcessWakeListen(Arg aArgs[])
179178
{
180-
#if OPENTHREAD_CONFIG_THREAD_DIRECT_WAKE_LISTENER_ENABLE
181179
otError error = OT_ERROR_NONE;
182180

183181
if (aArgs[0].IsEmpty() || aArgs[0] == "enable" || aArgs[0] == "disable")
@@ -210,11 +208,8 @@ otError ThreadDirect::ProcessWakeListen(Arg aArgs[])
210208

211209
exit:
212210
return error;
213-
#else
214-
OT_UNUSED_VARIABLE(aArgs);
215-
return OT_ERROR_NOT_IMPLEMENTED;
216-
#endif
217211
}
212+
#endif // OPENTHREAD_CONFIG_THREAD_DIRECT_WAKE_LISTENER_ENABLE
218213

219214
otError ThreadDirect::ProcessLink(Arg aArgs[])
220215
{
@@ -315,19 +310,19 @@ otError ThreadDirect::ProcessLinkRam(Arg aArgs[])
315310
{
316311
otThreadDirectRamParams params;
317312
uint8_t duration;
318-
int32_t offsetRaw;
313+
int16_t offsetUs;
319314
uint8_t hexBuf[4];
320315
uint16_t hexLen = sizeof(hexBuf);
321316

322317
memset(&params, 0, sizeof(params));
323318

324319
SuccessOrExit(error = aArgs[1].ParseAsHexString(hexLen, hexBuf));
325-
SuccessOrExit(error = aArgs[2].ParseAsInt32(offsetRaw));
320+
SuccessOrExit(error = aArgs[2].ParseAsInt16(offsetUs));
326321
SuccessOrExit(error = aArgs[3].ParseAsUint8(duration));
327322
VerifyOrExit(aArgs[4].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
328323

329324
memcpy(params.mBits, hexBuf, hexLen);
330-
params.mOffsetUs = static_cast<int16_t>(offsetRaw);
325+
params.mOffsetUs = offsetUs;
331326
params.mDuration = duration;
332327

333328
error = otThreadDirectSetRamOverride(GetInstancePtr(), &params);

src/cli/cli_td.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,12 @@ class ThreadDirect : private Utils
6262

6363
otError ProcessHelp(Arg aArgs[]);
6464
otError ProcessChannel(Arg aArgs[]);
65+
#if OPENTHREAD_CONFIG_THREAD_DIRECT_WAKE_INITIATOR_ENABLE
6566
otError ProcessWake(Arg aArgs[]);
67+
#endif
68+
#if OPENTHREAD_CONFIG_THREAD_DIRECT_WAKE_LISTENER_ENABLE
6669
otError ProcessWakeListen(Arg aArgs[]);
70+
#endif
6771
otError ProcessLink(Arg aArgs[]);
6872
otError ProcessUnlink(Arg aArgs[]);
6973

src/core/api/thread_direct_api.cpp

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@
4343
#include "mac/mac_frame.hpp"
4444
#include "mac/mac_types.hpp"
4545
#include "mac/sub_mac.hpp"
46+
47+
#if OPENTHREAD_CONFIG_THREAD_DIRECT_WAKE_INITIATOR_ENABLE
4648
#include "mac/wakeup_tx_scheduler.hpp"
4749
#include "meshcop/dataset_manager.hpp"
50+
#endif
4851

4952
#if OPENTHREAD_CONFIG_THREAD_DIRECT_WAKE_INITIATOR_ENABLE || OPENTHREAD_CONFIG_THREAD_DIRECT_WAKE_LISTENER_ENABLE
5053

@@ -55,14 +58,15 @@ void otThreadDirectSetEventCallback(otInstance *aInstance, otThreadDirectEventCa
5558
AsCoreType(aInstance).Get<Mac::Mac>().SetDirectEventCallback(aCallback, aContext);
5659
}
5760

61+
#if OPENTHREAD_CONFIG_THREAD_DIRECT_WAKE_INITIATOR_ENABLE
62+
5863
otError otThreadDirectWakeup(otInstance *aInstance,
5964
const otExtAddress *aExtAddress,
6065
otThreadDirectWakeType aWakeType,
6166
uint16_t aIntervalUs,
6267
uint16_t aDurationMs,
6368
uint8_t aKeyIndex)
6469
{
65-
#if OPENTHREAD_CONFIG_THREAD_DIRECT_WAKE_INITIATOR_ENABLE
6670
otError error = OT_ERROR_NONE;
6771

6872
VerifyOrExit(aExtAddress != nullptr, error = OT_ERROR_INVALID_ARGS);
@@ -98,18 +102,15 @@ otError otThreadDirectWakeup(otInstance *aInstance,
98102

99103
exit:
100104
return error;
101-
#else
102-
OT_UNUSED_VARIABLE(aInstance);
103-
OT_UNUSED_VARIABLE(aExtAddress);
104-
OT_UNUSED_VARIABLE(aWakeType);
105-
OT_UNUSED_VARIABLE(aIntervalUs);
106-
OT_UNUSED_VARIABLE(aDurationMs);
107-
OT_UNUSED_VARIABLE(aKeyIndex);
105+
}
108106

109-
return OT_ERROR_NOT_IMPLEMENTED;
110-
#endif
107+
bool otThreadDirectIsWakeBurstActive(otInstance *aInstance)
108+
{
109+
return AsCoreType(aInstance).Get<WakeupTxScheduler>().IsRunning();
111110
}
112111

112+
#endif // OPENTHREAD_CONFIG_THREAD_DIRECT_WAKE_INITIATOR_ENABLE
113+
113114
otError otThreadDirectUnlink(otInstance *aInstance, const otExtAddress *aExtAddress)
114115
{
115116
OT_UNUSED_VARIABLE(aInstance);
@@ -118,37 +119,19 @@ otError otThreadDirectUnlink(otInstance *aInstance, const otExtAddress *aExtAddr
118119
return OT_ERROR_NOT_IMPLEMENTED;
119120
}
120121

122+
#if OPENTHREAD_CONFIG_THREAD_DIRECT_WAKE_LISTENER_ENABLE
123+
121124
otError otThreadDirectWakeListenerEnable(otInstance *aInstance, bool aEnable)
122125
{
123-
#if OPENTHREAD_CONFIG_THREAD_DIRECT_WAKE_LISTENER_ENABLE
124126
return AsCoreType(aInstance).Get<Mac::Mac>().SetWakeupListenEnabled(aEnable);
125-
#else
126-
OT_UNUSED_VARIABLE(aInstance);
127-
OT_UNUSED_VARIABLE(aEnable);
128-
129-
return OT_ERROR_NOT_IMPLEMENTED;
130-
#endif
131127
}
132128

133129
bool otThreadDirectIsWakeListenerEnabled(otInstance *aInstance)
134130
{
135-
#if OPENTHREAD_CONFIG_THREAD_DIRECT_WAKE_LISTENER_ENABLE
136131
return AsCoreType(aInstance).Get<Mac::Mac>().IsWakeupListenEnabled();
137-
#else
138-
OT_UNUSED_VARIABLE(aInstance);
139-
return false;
140-
#endif
141132
}
142133

143-
bool otThreadDirectIsWakeBurstActive(otInstance *aInstance)
144-
{
145-
#if OPENTHREAD_CONFIG_THREAD_DIRECT_WAKE_INITIATOR_ENABLE
146-
return AsCoreType(aInstance).Get<WakeupTxScheduler>().IsRunning();
147-
#else
148-
OT_UNUSED_VARIABLE(aInstance);
149-
return false;
150-
#endif
151-
}
134+
#endif // OPENTHREAD_CONFIG_THREAD_DIRECT_WAKE_LISTENER_ENABLE
152135

153136
otError otThreadDirectSetSlwSchedule(otInstance *aInstance, uint16_t aSlwPeriodSlots)
154137
{
@@ -165,6 +148,9 @@ otError otThreadDirectSetRamOverride(otInstance *aInstance, const otThreadDirect
165148
// a stored state since it has no meaning outside of a per-frame codec context.
166149
VerifyOrExit(aParams->mDuration >= 1 && aParams->mDuration <= Mac::ScaParams::kRamDurationMax,
167150
error = OT_ERROR_INVALID_ARGS);
151+
VerifyOrExit(aParams->mOffsetUs >= Mac::ScaParams::kRamOffsetUsMin &&
152+
aParams->mOffsetUs <= Mac::ScaParams::kRamOffsetUsMax,
153+
error = OT_ERROR_INVALID_ARGS);
168154

169155
params.mRamDuration = aParams->mDuration;
170156
params.mRamOffsetUs = aParams->mOffsetUs;

src/core/config/mac.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
* @{
4444
*/
4545

46-
#include "config/thread_direct.h"
4746
#include "config/time_sync.h"
4847

4948
/**

src/core/mac/direct_handler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ Error DirectHandler::SetRamMask(const Mac::ScaParams &aParams)
7676
Error error = kErrorNone;
7777

7878
VerifyOrExit(aParams.mRamDuration <= Mac::ScaParams::kRamDurationMax, error = kErrorInvalidArgs);
79+
VerifyOrExit(aParams.mRamOffsetUs >= Mac::ScaParams::kRamOffsetUsMin &&
80+
aParams.mRamOffsetUs <= Mac::ScaParams::kRamOffsetUsMax,
81+
error = kErrorInvalidArgs);
7982

8083
mLocalSca.mRamDuration = aParams.mRamDuration;
8184
mLocalSca.mRamOffsetUs = aParams.mRamOffsetUs;

src/core/mac/direct_handler.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ class DirectHandler : public InstanceLocator, private NonCopyable
7979
* @param[in] aParams RAM parameters to store.
8080
*
8181
* @retval kErrorNone Parameters stored.
82-
* @retval kErrorInvalidArgs @p aParams.mRamDuration is outside [0, 31].
82+
* @retval kErrorInvalidArgs @p aParams.mRamDuration is outside [0, 31] or
83+
* @p aParams.mRamOffsetUs is outside [-1024, 1023].
8384
*/
8485
Error SetRamMask(const Mac::ScaParams &aParams);
8586

src/core/mac/mac_header_ie.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ struct ScaParams
313313
static constexpr uint8_t kRamDurationNoChange = 0; ///< RAM Duration: no change to prior RAM.
314314
static constexpr uint8_t kRamDurationNoConstraints = 1; ///< RAM Duration: device has no CoEx constraints.
315315
static constexpr uint8_t kRamDurationMax = 31; ///< Maximum valid RAM Duration value.
316+
static constexpr int16_t kRamOffsetUsMin = -1024;
317+
static constexpr int16_t kRamOffsetUsMax = 1023;
316318

317319
uint16_t mSlwPeriodSlots; ///< SLW Period in 160 us slots (0 = no SLW schedule configured).
318320
uint16_t mSlwPhaseSlots; ///< SLW Phase in 160 us slots.

src/core/mac/mac_types.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ struct WakeupInfo
976976
{
977977
ExtAddress mExtAddress; ///< Extended address of the Wake Initiator.
978978
uint32_t mAttachDelayUs; ///< Rendezvous Time converted to us offset before sending TD Link Command.
979-
uint8_t mRetryInterval : 2; ///< Retry Interval (RI field from Wake Frame, 4-bit wire value).
979+
uint8_t mRetryInterval : 4; ///< Retry Interval (RI field from Wake Frame, 4-bit wire value).
980980
uint8_t mRetryCount : 4; ///< Retry Count (RC field from Wake Frame, 4-bit wire value).
981981
};
982982
#endif

0 commit comments

Comments
 (0)