mirror of
https://github.com/espressif/openthread.git
synced 2026-09-05 16:50:05 +00:00
[mle] implement alternate RLOC16 usage during role transition (#10006)
This commit introduces a mechanism for a device transitioning from child to router role to keep receiving frames addressed to its previous short address for a brief period. A new radio platform API, `otPlatRadioSetAlternateShortAddress()`, is introduced. This allows the OT stack to configure an alternate short address. Radio platform support for this function is indicated by the `OT_RADIO_CAPS_ALT_SHORT_ADDR` capability in `otPlatRadioGetCaps()` The same function can be used with `OT_RADIO_INVALID_SHORT_ADDR` (`0xfffe`) to clear a previously set alternate short address. Support for the new API is implemented in RCP and `RadioSpinel`, ensuring backward compatibility by dynamically checking supported radio capabilities. MLE code is updated to instruct the radio to use the old child RLOC16 as an alternate address upon role transition. The MLE layer will automatically clear the alternate address after eight seconds, or if other state/mode changes occur. This eight-second window ensures the new router can transmit four MLE Advertisement messages.
This commit is contained in:
@@ -382,6 +382,15 @@ void otPlatRadioSetShortAddress(otInstance *aInstance, otShortAddress aShortAddr
|
||||
sRadioContext.mShortAddress = aShortAddress;
|
||||
}
|
||||
|
||||
void otPlatRadioSetAlternateShortAddress(otInstance *aInstance, otShortAddress aShortAddress)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
assert(aInstance != NULL);
|
||||
|
||||
sRadioContext.mAlternateShortAddress = aShortAddress;
|
||||
}
|
||||
|
||||
void otPlatRadioSetPromiscuous(otInstance *aInstance, bool aEnable)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
@@ -849,9 +858,9 @@ void radioProcessFrame(otInstance *aInstance)
|
||||
|
||||
otEXPECT(sPromiscuous == false);
|
||||
|
||||
otEXPECT_ACTION(
|
||||
otMacFrameDoesAddrMatch(&sReceiveFrame, sPanid, sRadioContext.mShortAddress, &sRadioContext.mExtAddress),
|
||||
error = OT_ERROR_ABORT);
|
||||
otEXPECT_ACTION(otMacFrameDoesAddrMatchAny(&sReceiveFrame, sPanid, sRadioContext.mShortAddress,
|
||||
sRadioContext.mAlternateShortAddress, &sRadioContext.mExtAddress),
|
||||
error = OT_ERROR_ABORT);
|
||||
|
||||
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
|
||||
otEXPECT_ACTION(otMacFrameGetSrcAddr(&sReceiveFrame, &macAddress) == OT_ERROR_NONE, error = OT_ERROR_PARSE);
|
||||
|
||||
@@ -41,6 +41,15 @@ bool otMacFrameDoesAddrMatch(const otRadioFrame *aFrame,
|
||||
otPanId aPanId,
|
||||
otShortAddress aShortAddress,
|
||||
const otExtAddress *aExtAddress)
|
||||
{
|
||||
return otMacFrameDoesAddrMatchAny(aFrame, aPanId, aShortAddress, Mac::kShortAddrInvalid, aExtAddress);
|
||||
}
|
||||
|
||||
bool otMacFrameDoesAddrMatchAny(const otRadioFrame *aFrame,
|
||||
otPanId aPanId,
|
||||
otShortAddress aShortAddress,
|
||||
otShortAddress aAltShortAddress,
|
||||
const otExtAddress *aExtAddress)
|
||||
{
|
||||
const Mac::Frame &frame = *static_cast<const Mac::Frame *>(aFrame);
|
||||
bool rval = true;
|
||||
@@ -52,7 +61,9 @@ bool otMacFrameDoesAddrMatch(const otRadioFrame *aFrame,
|
||||
switch (dst.GetType())
|
||||
{
|
||||
case Mac::Address::kTypeShort:
|
||||
VerifyOrExit(dst.GetShort() == Mac::kShortAddrBroadcast || dst.GetShort() == aShortAddress, rval = false);
|
||||
VerifyOrExit(dst.GetShort() == Mac::kShortAddrBroadcast || dst.GetShort() == aShortAddress ||
|
||||
(aAltShortAddress != Mac::kShortAddrInvalid && dst.GetShort() == aAltShortAddress),
|
||||
rval = false);
|
||||
break;
|
||||
|
||||
case Mac::Address::kTypeExtended:
|
||||
|
||||
@@ -132,6 +132,25 @@ bool otMacFrameDoesAddrMatch(const otRadioFrame *aFrame,
|
||||
otShortAddress aShortAddress,
|
||||
const otExtAddress *aExtAddress);
|
||||
|
||||
/**
|
||||
* Check if @p aFrame matches the @p aPandId and @p aShortAddress, or @p aAltShortAddress or @p aExtAddress.
|
||||
*
|
||||
* @param[in] aFrame A pointer to the frame.
|
||||
* @param[in] aPanId The PAN id to match with.
|
||||
* @param[in] aShortAddress The short address to match with.
|
||||
* @param[in] aAltShortAddress The alternate short address to match with. Can be `OT_RADIO_INVALID_SHORT_ADDR` if
|
||||
* there is no alternate address.
|
||||
* @param[in] aExtAddress The extended address to match with.
|
||||
*
|
||||
* @retval true It is a broadcast or matches with the PAN id and one of the addresses.
|
||||
* @retval false It doesn't match.
|
||||
*/
|
||||
bool otMacFrameDoesAddrMatchAny(const otRadioFrame *aFrame,
|
||||
otPanId aPanId,
|
||||
otShortAddress aShortAddress,
|
||||
otShortAddress aAltShortAddress,
|
||||
const otExtAddress *aExtAddress);
|
||||
|
||||
/**
|
||||
* Get source MAC address.
|
||||
*
|
||||
@@ -319,6 +338,7 @@ typedef struct otRadioContext
|
||||
uint32_t mCslSampleTime; ///< The sample time based on the microsecond timer.
|
||||
uint16_t mCslPeriod; ///< In unit of 10 symbols.
|
||||
otShortAddress mShortAddress;
|
||||
otShortAddress mAlternateShortAddress;
|
||||
otRadioKeyType mKeyType;
|
||||
uint8_t mKeyId;
|
||||
otMacKeyMaterial mPrevKey;
|
||||
|
||||
Reference in New Issue
Block a user