mirror of
https://github.com/espressif/openthread.git
synced 2026-08-08 03:37:46 +00:00
[message] track received ThreadLinkInfo in Message metadata (#9878)
This commit changes how the link information is tracked for a received message over Thread radio. It removes the `const void *mLinkInfo` field in `otMessageInfo`. Instead a new public API `otMessageGetThreadLinkInfo()` is added to retrieve the `otThreadLinkInfo` from an `otMessage`. All the `ThreadLinkInfo` properties are now directly tracked in `Message` as part its `Metadata`. The `Message::Clone()` method is updated to properly copy the link info from the original message to its clones. This change helps simplify the code, avoid passing `ThreadLinkInfo` references. More importantly, it prevents potential errors due to incorrect use of a pointer to stack-allocated `ThreadLinkInfo` object. This is especially important for modules that save/enqueue `Message` and its `Ip6::MessageInfo` for later use, ensuring link information remains valid.
This commit is contained in:
@@ -53,7 +53,7 @@ extern "C" {
|
||||
* @note This number versions both OpenThread platform and user APIs.
|
||||
*
|
||||
*/
|
||||
#define OPENTHREAD_API_VERSION (397)
|
||||
#define OPENTHREAD_API_VERSION (398)
|
||||
|
||||
/**
|
||||
* @addtogroup api-instance
|
||||
|
||||
@@ -236,7 +236,6 @@ typedef struct otMessageInfo
|
||||
otIp6Address mPeerAddr; ///< The peer IPv6 address.
|
||||
uint16_t mSockPort; ///< The local transport-layer port.
|
||||
uint16_t mPeerPort; ///< The peer transport-layer port.
|
||||
const void *mLinkInfo; ///< A pointer to link-specific information.
|
||||
uint8_t mHopLimit; ///< The IPv6 Hop Limit value. Only applies if `mAllowZeroHopLimit` is FALSE.
|
||||
///< If `0`, IPv6 Hop Limit is default value `OPENTHREAD_CONFIG_IP6_HOP_LIMIT_DEFAULT`.
|
||||
///< Otherwise, specifies the IPv6 Hop Limit.
|
||||
|
||||
@@ -54,27 +54,6 @@ extern "C" {
|
||||
*/
|
||||
#define OT_US_PER_TEN_SYMBOLS OT_RADIO_TEN_SYMBOLS_TIME ///< Time for 10 symbols in units of microseconds
|
||||
|
||||
/**
|
||||
* Represents link-specific information for messages received from the Thread radio.
|
||||
*
|
||||
*/
|
||||
typedef struct otThreadLinkInfo
|
||||
{
|
||||
uint16_t mPanId; ///< Source PAN ID
|
||||
uint8_t mChannel; ///< 802.15.4 Channel
|
||||
int8_t mRss; ///< Received Signal Strength in dBm.
|
||||
uint8_t mLqi; ///< Link Quality Indicator for a received message.
|
||||
bool mLinkSecurity : 1; ///< Indicates whether or not link security is enabled.
|
||||
bool mIsDstPanIdBroadcast : 1; ///< Indicates whether or not destination PAN ID is broadcast.
|
||||
|
||||
// Applicable/Required only when time sync feature (`OPENTHREAD_CONFIG_TIME_SYNC_ENABLE`) is enabled.
|
||||
uint8_t mTimeSyncSeq; ///< The time sync sequence.
|
||||
int64_t mNetworkTimeOffset; ///< The time offset to the Thread network time, in microseconds.
|
||||
|
||||
// Applicable only when OPENTHREAD_CONFIG_MULTI_RADIO feature is enabled.
|
||||
uint8_t mRadioType; ///< Radio link type.
|
||||
} otThreadLinkInfo;
|
||||
|
||||
/**
|
||||
* Used to indicate no fixed received signal strength was set
|
||||
*
|
||||
|
||||
@@ -90,6 +90,27 @@ typedef struct otMessageSettings
|
||||
uint8_t mPriority; ///< Priority level (MUST be a `OT_MESSAGE_PRIORITY_*` from `otMessagePriority`).
|
||||
} otMessageSettings;
|
||||
|
||||
/**
|
||||
* Represents link-specific information for messages received from the Thread radio.
|
||||
*
|
||||
*/
|
||||
typedef struct otThreadLinkInfo
|
||||
{
|
||||
uint16_t mPanId; ///< Source PAN ID
|
||||
uint8_t mChannel; ///< 802.15.4 Channel
|
||||
int8_t mRss; ///< Received Signal Strength in dBm (averaged over fragments)
|
||||
uint8_t mLqi; ///< Average Link Quality Indicator (averaged over fragments)
|
||||
bool mLinkSecurity : 1; ///< Indicates whether or not link security is enabled.
|
||||
bool mIsDstPanIdBroadcast : 1; ///< Indicates whether or not destination PAN ID is broadcast.
|
||||
|
||||
// Applicable/Required only when time sync feature (`OPENTHREAD_CONFIG_TIME_SYNC_ENABLE`) is enabled.
|
||||
uint8_t mTimeSyncSeq; ///< The time sync sequence.
|
||||
int64_t mNetworkTimeOffset; ///< The time offset to the Thread network time, in microseconds.
|
||||
|
||||
// Applicable only when OPENTHREAD_CONFIG_MULTI_RADIO feature is enabled.
|
||||
uint8_t mRadioType; ///< Radio link type.
|
||||
} otThreadLinkInfo;
|
||||
|
||||
/**
|
||||
* Free an allocated message buffer.
|
||||
*
|
||||
@@ -266,11 +287,25 @@ void otMessageSetDirectTransmission(otMessage *aMessage, bool aEnabled);
|
||||
/**
|
||||
* Returns the average RSS (received signal strength) associated with the message.
|
||||
*
|
||||
* @param[in] aMessage A pointer to a message buffer.
|
||||
*
|
||||
* @returns The average RSS value (in dBm) or OT_RADIO_RSSI_INVALID if no average RSS is available.
|
||||
*
|
||||
*/
|
||||
int8_t otMessageGetRss(const otMessage *aMessage);
|
||||
|
||||
/**
|
||||
* Retrieves the link-specific information for a message received over Thread radio.
|
||||
*
|
||||
* @param[in] aMessage The message from which to retrieve `otThreadLinkInfo`.
|
||||
* @pram[out] aLinkInfo A pointer to an `otThreadLinkInfo` to populate.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully retrieved the link info, @p `aLinkInfo` is updated.
|
||||
* @retval OT_ERROR_NOT_FOUND Message origin is not `OT_MESSAGE_ORIGIN_THREAD_NETIF`.
|
||||
*
|
||||
*/
|
||||
otError otMessageGetThreadLinkInfo(const otMessage *aMessage, otThreadLinkInfo *aLinkInfo);
|
||||
|
||||
/**
|
||||
* Append bytes to a message.
|
||||
*
|
||||
|
||||
@@ -90,6 +90,11 @@ void otMessageSetDirectTransmission(otMessage *aMessage, bool aEnabled)
|
||||
|
||||
int8_t otMessageGetRss(const otMessage *aMessage) { return AsCoreType(aMessage).GetAverageRss(); }
|
||||
|
||||
otError otMessageGetThreadLinkInfo(const otMessage *aMessage, otThreadLinkInfo *aLinkInfo)
|
||||
{
|
||||
return AsCoreType(aMessage).GetLinkInfo(AsCoreType(aLinkInfo));
|
||||
}
|
||||
|
||||
otError otMessageAppend(otMessage *aMessage, const void *aBuf, uint16_t aLength)
|
||||
{
|
||||
AssertPointerIsNotNull(aBuf);
|
||||
|
||||
@@ -770,12 +770,19 @@ Message *Message::Clone(uint16_t aLength) const
|
||||
SuccessOrExit(error = messageCopy->AppendBytesFromMessage(*this, 0, aLength));
|
||||
|
||||
// Copy selected message information.
|
||||
|
||||
offset = Min(GetOffset(), aLength);
|
||||
messageCopy->SetOffset(offset);
|
||||
|
||||
messageCopy->SetSubType(GetSubType());
|
||||
messageCopy->SetLoopbackToHostAllowed(IsLoopbackToHostAllowed());
|
||||
messageCopy->SetOrigin(GetOrigin());
|
||||
messageCopy->SetTimestamp(GetTimestamp());
|
||||
messageCopy->SetMeshDest(GetMeshDest());
|
||||
messageCopy->SetPanId(GetPanId());
|
||||
messageCopy->SetChannel(GetChannel());
|
||||
messageCopy->SetRssAverager(GetRssAverager());
|
||||
messageCopy->SetLqiAverager(GetLqiAverager());
|
||||
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
|
||||
messageCopy->SetTimeSync(IsTimeSync());
|
||||
#endif
|
||||
@@ -795,18 +802,48 @@ void Message::SetChildMask(uint16_t aChildIndex) { GetMetadata().mChildMask.Set(
|
||||
bool Message::IsChildPending(void) const { return GetMetadata().mChildMask.HasAny(); }
|
||||
#endif
|
||||
|
||||
void Message::SetLinkInfo(const ThreadLinkInfo &aLinkInfo)
|
||||
Error Message::GetLinkInfo(ThreadLinkInfo &aLinkInfo) const
|
||||
{
|
||||
SetLinkSecurityEnabled(aLinkInfo.mLinkSecurity);
|
||||
SetPanId(aLinkInfo.mPanId);
|
||||
AddRss(aLinkInfo.mRss);
|
||||
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
|
||||
AddLqi(aLinkInfo.mLqi);
|
||||
Error error = kErrorNone;
|
||||
|
||||
VerifyOrExit(IsOriginThreadNetif(), error = kErrorNotFound);
|
||||
|
||||
aLinkInfo.Clear();
|
||||
|
||||
aLinkInfo.mPanId = GetPanId();
|
||||
aLinkInfo.mChannel = GetChannel();
|
||||
aLinkInfo.mRss = GetAverageRss();
|
||||
aLinkInfo.mLqi = GetAverageLqi();
|
||||
aLinkInfo.mLinkSecurity = IsLinkSecurityEnabled();
|
||||
aLinkInfo.mIsDstPanIdBroadcast = IsDstPanIdBroadcast();
|
||||
|
||||
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
|
||||
aLinkInfo.mTimeSyncSeq = GetTimeSyncSeq();
|
||||
aLinkInfo.mNetworkTimeOffset = GetNetworkTimeOffset();
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_MULTI_RADIO
|
||||
aLinkInfo.mRadioType = GetRadioType();
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void Message::UpdateLinkInfoFrom(const ThreadLinkInfo &aLinkInfo)
|
||||
{
|
||||
SetPanId(aLinkInfo.mPanId);
|
||||
SetChannel(aLinkInfo.mChannel);
|
||||
AddRss(aLinkInfo.mRss);
|
||||
AddLqi(aLinkInfo.mLqi);
|
||||
SetLinkSecurityEnabled(aLinkInfo.mLinkSecurity);
|
||||
GetMetadata().mIsDstPanIdBroadcast = aLinkInfo.IsDstPanIdBroadcast();
|
||||
|
||||
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
|
||||
SetTimeSyncSeq(aLinkInfo.mTimeSyncSeq);
|
||||
SetNetworkTimeOffset(aLinkInfo.mNetworkTimeOffset);
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_MULTI_RADIO
|
||||
SetRadioType(static_cast<Mac::RadioType>(aLinkInfo.mRadioType));
|
||||
#endif
|
||||
|
||||
+45
-10
@@ -200,9 +200,7 @@ protected:
|
||||
uint16_t mPanId; // PAN ID (used for MLE Discover Request and Response).
|
||||
uint8_t mChannel; // The message channel (used for MLE Announce).
|
||||
RssAverager mRssAverager; // The averager maintaining the received signal strength (RSS) average.
|
||||
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
|
||||
LqiAverager mLqiAverager; // The averager maintaining the Link quality indicator (LQI) average.
|
||||
#endif
|
||||
LqiAverager mLqiAverager; // The averager maintaining the Link quality indicator (LQI) average.
|
||||
#if OPENTHREAD_FTD
|
||||
ChildMask mChildMask; // ChildMask to indicate which sleepy children need to receive this.
|
||||
#endif
|
||||
@@ -218,7 +216,9 @@ protected:
|
||||
bool mMulticastLoop : 1; // Whether this multicast message may be looped back.
|
||||
bool mResolvingAddress : 1; // Whether the message is pending an address query resolution.
|
||||
bool mAllowLookbackToHost : 1; // Whether the message is allowed to be looped back to host.
|
||||
uint8_t mOrigin : 2; // The origin of the message.
|
||||
bool mIsDstPanIdBroadcast : 1; // IWhether the dest PAN ID is broadcast.
|
||||
uint8_t mOrigin : 2;
|
||||
// The origin of the message.
|
||||
#if OPENTHREAD_CONFIG_MULTI_RADIO
|
||||
uint8_t mRadioType : 2; // The radio link type the message was received on, or should be sent on.
|
||||
bool mIsRadioTypeSet : 1; // Whether the radio type is set.
|
||||
@@ -1015,11 +1015,15 @@ public:
|
||||
void SetMeshDest(uint16_t aMeshDest) { GetMetadata().mMeshDest = aMeshDest; }
|
||||
|
||||
/**
|
||||
* Returns the IEEE 802.15.4 Destination PAN ID.
|
||||
* Returns the IEEE 802.15.4 Source or Destination PAN ID.
|
||||
*
|
||||
* @note Only use this when sending MLE Discover Request or Response messages.
|
||||
* For a message received over the Thread radio, specifies the Source PAN ID when present in MAC header, otherwise
|
||||
* specifies the Destination PAN ID.
|
||||
*
|
||||
* @returns The IEEE 802.15.4 Destination PAN ID.
|
||||
* For a message to be sent over the Thread radio, this is set and used for MLE Discover Request or Response
|
||||
* messages.
|
||||
*
|
||||
* @returns The IEEE 802.15.4 PAN ID.
|
||||
*
|
||||
*/
|
||||
uint16_t GetPanId(void) const { return GetMetadata().mPanId; }
|
||||
@@ -1034,6 +1038,17 @@ public:
|
||||
*/
|
||||
void SetPanId(uint16_t aPanId) { GetMetadata().mPanId = aPanId; }
|
||||
|
||||
/**
|
||||
* Indicates whether the Destination PAN ID is broadcast.
|
||||
*
|
||||
* This is applicable for messages received over Thread radio.
|
||||
*
|
||||
* @retval TRUE The Destination PAN ID is broadcast.
|
||||
* @retval FALSE The Destination PAN ID is not broadcast.
|
||||
*
|
||||
*/
|
||||
bool IsDstPanIdBroadcast(void) const { return GetMetadata().mIsDstPanIdBroadcast; }
|
||||
|
||||
/**
|
||||
* Returns the IEEE 802.15.4 Channel to use for transmission.
|
||||
*
|
||||
@@ -1255,7 +1270,6 @@ public:
|
||||
*/
|
||||
const RssAverager &GetRssAverager(void) const { return GetMetadata().mRssAverager; }
|
||||
|
||||
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
|
||||
/**
|
||||
* Updates the average LQI (Link Quality Indicator) associated with the message.
|
||||
*
|
||||
@@ -1282,7 +1296,25 @@ public:
|
||||
*
|
||||
*/
|
||||
uint8_t GetPsduCount(void) const { return GetMetadata().mLqiAverager.GetCount(); }
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Returns a const reference to LqiAverager of the message.
|
||||
*
|
||||
* @returns A const reference to the LqiAverager of the message.
|
||||
*
|
||||
*/
|
||||
const LqiAverager &GetLqiAverager(void) const { return GetMetadata().mLqiAverager; }
|
||||
|
||||
/**
|
||||
* Retrieves `ThreadLinkInfo` from the message if received over Thread radio with origin `kOriginThreadNetif`.
|
||||
*
|
||||
* @pram[out] aLinkInfo A reference to a `ThreadLinkInfo` to populate.
|
||||
*
|
||||
* @retval kErrorNone Successfully retrieved the link info, @p `aLinkInfo` is updated.
|
||||
* @retval kErrorNotFound Message origin is not `kOriginThreadNetif`.
|
||||
*
|
||||
*/
|
||||
Error GetLinkInfo(ThreadLinkInfo &aLinkInfo) const;
|
||||
|
||||
/**
|
||||
* Sets the message's link info properties (PAN ID, link security, RSS) from a given `ThreadLinkInfo`.
|
||||
@@ -1290,7 +1322,7 @@ public:
|
||||
* @param[in] aLinkInfo The `ThreadLinkInfo` instance from which to set message's related properties.
|
||||
*
|
||||
*/
|
||||
void SetLinkInfo(const ThreadLinkInfo &aLinkInfo);
|
||||
void UpdateLinkInfoFrom(const ThreadLinkInfo &aLinkInfo);
|
||||
|
||||
/**
|
||||
* Returns a pointer to the message queue (if any) where this message is queued.
|
||||
@@ -1489,6 +1521,9 @@ private:
|
||||
void SetMessageQueue(MessageQueue *aMessageQueue);
|
||||
void SetPriorityQueue(PriorityQueue *aPriorityQueue);
|
||||
|
||||
void SetRssAverager(const RssAverager &aRssAverager) { GetMetadata().mRssAverager = aRssAverager; }
|
||||
void SetLqiAverager(const LqiAverager &aLqiAverager) { GetMetadata().mLqiAverager = aLqiAverager; }
|
||||
|
||||
Message *&Next(void) { return GetMetadata().mNext; }
|
||||
Message *const &Next(void) const { return GetMetadata().mNext; }
|
||||
Message *&Prev(void) { return GetMetadata().mPrev; }
|
||||
|
||||
+6
-11
@@ -616,7 +616,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error Ip6::HandleFragment(Message &aMessage, MessageInfo &aMessageInfo)
|
||||
Error Ip6::HandleFragment(Message &aMessage)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
Header header, headerBuffer;
|
||||
@@ -703,8 +703,7 @@ Error Ip6::HandleFragment(Message &aMessage, MessageInfo &aMessageInfo)
|
||||
|
||||
mReassemblyList.Dequeue(*message);
|
||||
|
||||
IgnoreError(HandleDatagram(OwnedPtr<Message>(message), aMessageInfo.mLinkInfo,
|
||||
/* aIsReassembled */ true));
|
||||
IgnoreError(HandleDatagram(OwnedPtr<Message>(message), /* aIsReassembled */ true));
|
||||
}
|
||||
|
||||
exit:
|
||||
@@ -766,7 +765,6 @@ void Ip6::SendIcmpError(Message &aMessage, Icmp::Header::Type aIcmpType, Icmp::H
|
||||
messageInfo.SetPeerAddr(header.GetSource());
|
||||
messageInfo.SetSockAddr(header.GetDestination());
|
||||
messageInfo.SetHopLimit(header.GetHopLimit());
|
||||
messageInfo.SetLinkInfo(nullptr);
|
||||
|
||||
error = mIcmp.SendError(aIcmpType, aIcmpCode, messageInfo, aMessage);
|
||||
|
||||
@@ -788,10 +786,8 @@ Error Ip6::FragmentDatagram(Message &aMessage, uint8_t aIpProto)
|
||||
return kErrorNone;
|
||||
}
|
||||
|
||||
Error Ip6::HandleFragment(Message &aMessage, MessageInfo &aMessageInfo)
|
||||
Error Ip6::HandleFragment(Message &aMessage)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aMessageInfo);
|
||||
|
||||
Error error = kErrorNone;
|
||||
FragmentHeader fragmentHeader;
|
||||
|
||||
@@ -829,7 +825,7 @@ Error Ip6::HandleExtensionHeaders(OwnedPtr<Message> &aMessagePtr,
|
||||
case kProtoFragment:
|
||||
IgnoreError(PassToHost(aMessagePtr, aMessageInfo, aNextHeader,
|
||||
/* aApplyFilter */ false, aReceive, Message::kCopyToUse));
|
||||
SuccessOrExit(error = HandleFragment(*aMessagePtr, aMessageInfo));
|
||||
SuccessOrExit(error = HandleFragment(*aMessagePtr));
|
||||
break;
|
||||
|
||||
case kProtoDstOpts:
|
||||
@@ -1094,7 +1090,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error Ip6::HandleDatagram(OwnedPtr<Message> aMessagePtr, const void *aLinkMessageInfo, bool aIsReassembled)
|
||||
Error Ip6::HandleDatagram(OwnedPtr<Message> aMessagePtr, bool aIsReassembled)
|
||||
{
|
||||
Error error;
|
||||
MessageInfo messageInfo;
|
||||
@@ -1115,7 +1111,6 @@ Error Ip6::HandleDatagram(OwnedPtr<Message> aMessagePtr, const void *aLinkMessag
|
||||
messageInfo.SetSockAddr(header.GetDestination());
|
||||
messageInfo.SetHopLimit(header.GetHopLimit());
|
||||
messageInfo.SetEcn(header.GetEcn());
|
||||
messageInfo.SetLinkInfo(aLinkMessageInfo);
|
||||
|
||||
// Determine `forwardThread`, `forwardHost` and `receive`
|
||||
// based on the destination address.
|
||||
@@ -1203,7 +1198,7 @@ Error Ip6::HandleDatagram(OwnedPtr<Message> aMessagePtr, const void *aLinkMessag
|
||||
|
||||
Get<MeshForwarder>().LogMessage(MeshForwarder::kMessageReceive, *messagePtr);
|
||||
|
||||
IgnoreError(HandleDatagram(messagePtr.PassOwnership(), aLinkMessageInfo, aIsReassembled));
|
||||
IgnoreError(HandleDatagram(messagePtr.PassOwnership(), aIsReassembled));
|
||||
|
||||
receive = false;
|
||||
forwardHost = false;
|
||||
|
||||
@@ -207,7 +207,6 @@ public:
|
||||
* Processes a received IPv6 datagram.
|
||||
*
|
||||
* @param[in] aMessage An owned pointer to a message.
|
||||
* @param[in] aLinkMessageInfo A pointer to link-specific message information.
|
||||
*
|
||||
* @retval kErrorNone Successfully processed the message.
|
||||
* @retval kErrorDrop Message was well-formed but not fully processed due to packet processing rules.
|
||||
@@ -216,9 +215,7 @@ public:
|
||||
* @retval kErrorParse Encountered a malformed header when processing the message.
|
||||
*
|
||||
*/
|
||||
Error HandleDatagram(OwnedPtr<Message> aMessagePtr,
|
||||
const void *aLinkMessageInfo = nullptr,
|
||||
bool aIsReassembled = false);
|
||||
Error HandleDatagram(OwnedPtr<Message> aMessagePtr, bool aIsReassembled = false);
|
||||
|
||||
/**
|
||||
* Registers a callback to provide received raw IPv6 datagrams.
|
||||
@@ -378,7 +375,7 @@ private:
|
||||
uint8_t &aNextHeader,
|
||||
bool &aReceive);
|
||||
Error FragmentDatagram(Message &aMessage, uint8_t aIpProto);
|
||||
Error HandleFragment(Message &aMessage, MessageInfo &aMessageInfo);
|
||||
Error HandleFragment(Message &aMessage);
|
||||
#if OPENTHREAD_CONFIG_IP6_FRAGMENTATION_ENABLE
|
||||
void CleanupFragmentationBuffer(void);
|
||||
void HandleTimeTick(void);
|
||||
|
||||
@@ -180,30 +180,6 @@ public:
|
||||
*/
|
||||
void SetMulticastLoop(bool aMulticastLoop) { mMulticastLoop = aMulticastLoop; }
|
||||
|
||||
/**
|
||||
* Returns a pointer to the link-specific information object.
|
||||
*
|
||||
* @returns A pointer to the link-specific information object.
|
||||
*
|
||||
*/
|
||||
const void *GetLinkInfo(void) const { return mLinkInfo; }
|
||||
|
||||
/**
|
||||
* Sets the pointer to the link-specific information object.
|
||||
*
|
||||
* @param[in] aLinkInfo A pointer to the link-specific information object.
|
||||
*
|
||||
*/
|
||||
void SetLinkInfo(const void *aLinkInfo) { mLinkInfo = aLinkInfo; }
|
||||
|
||||
/**
|
||||
* Returns a pointer to the link-specific information as a `ThreadLinkInfo`.
|
||||
*
|
||||
* @returns A pointer to to the link-specific information object as `ThreadLinkInfo`.
|
||||
*
|
||||
*/
|
||||
const ThreadLinkInfo *GetThreadLinkInfo(void) const { return reinterpret_cast<const ThreadLinkInfo *>(mLinkInfo); }
|
||||
|
||||
/**
|
||||
* Gets the ECN status.
|
||||
*
|
||||
|
||||
@@ -308,8 +308,7 @@ exit:
|
||||
|
||||
void DiscoverScanner::HandleDiscoveryResponse(Mle::RxInfo &aRxInfo) const
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
const ThreadLinkInfo *linkInfo = aRxInfo.mMessageInfo.GetThreadLinkInfo();
|
||||
Error error = kErrorNone;
|
||||
MeshCoP::Tlv meshcopTlv;
|
||||
MeshCoP::DiscoveryResponseTlv discoveryResponse;
|
||||
MeshCoP::NetworkNameTlv networkName;
|
||||
@@ -327,10 +326,10 @@ void DiscoverScanner::HandleDiscoveryResponse(Mle::RxInfo &aRxInfo) const
|
||||
|
||||
ClearAllBytes(result);
|
||||
result.mDiscover = true;
|
||||
result.mPanId = linkInfo->mPanId;
|
||||
result.mChannel = linkInfo->mChannel;
|
||||
result.mRssi = linkInfo->mRss;
|
||||
result.mLqi = linkInfo->mLqi;
|
||||
result.mPanId = aRxInfo.mMessage.GetPanId();
|
||||
result.mChannel = aRxInfo.mMessage.GetChannel();
|
||||
result.mRssi = aRxInfo.mMessage.GetAverageRss();
|
||||
result.mLqi = aRxInfo.mMessage.GetAverageLqi();
|
||||
|
||||
aRxInfo.mMessageInfo.GetPeerAddr().GetIid().ConvertToExtAddress(AsCoreType(&result.mExtAddress));
|
||||
|
||||
|
||||
@@ -1477,7 +1477,7 @@ void MeshForwarder::HandleFragment(FrameData &aFrameData,
|
||||
|
||||
message->SetDatagramTag(fragmentHeader.GetDatagramTag());
|
||||
message->SetTimestampToNow();
|
||||
message->SetLinkInfo(aLinkInfo);
|
||||
message->UpdateLinkInfoFrom(aLinkInfo);
|
||||
|
||||
VerifyOrExit(Get<Ip6::Filter>().Accept(*message), error = kErrorDrop);
|
||||
|
||||
@@ -1530,9 +1530,7 @@ void MeshForwarder::HandleFragment(FrameData &aFrameData,
|
||||
message->WriteData(message->GetOffset(), aFrameData);
|
||||
message->MoveOffset(aFrameData.GetLength());
|
||||
message->AddRss(aLinkInfo.GetRss());
|
||||
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
|
||||
message->AddLqi(aLinkInfo.GetLqi());
|
||||
#endif
|
||||
message->SetTimestampToNow();
|
||||
}
|
||||
|
||||
@@ -1543,7 +1541,7 @@ exit:
|
||||
if (message->GetOffset() >= message->GetLength())
|
||||
{
|
||||
mReassemblyList.Dequeue(*message);
|
||||
IgnoreError(HandleDatagram(*message, aLinkInfo, aMacAddrs.mSource));
|
||||
IgnoreError(HandleDatagram(*message, aMacAddrs.mSource));
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1643,7 +1641,7 @@ void MeshForwarder::HandleLowpanHC(const FrameData &aFrameData,
|
||||
|
||||
SuccessOrExit(error = FrameToMessage(aFrameData, 0, aMacAddrs, message));
|
||||
|
||||
message->SetLinkInfo(aLinkInfo);
|
||||
message->UpdateLinkInfoFrom(aLinkInfo);
|
||||
|
||||
VerifyOrExit(Get<Ip6::Filter>().Accept(*message), error = kErrorDrop);
|
||||
|
||||
@@ -1655,7 +1653,7 @@ exit:
|
||||
|
||||
if (error == kErrorNone)
|
||||
{
|
||||
IgnoreError(HandleDatagram(*message, aLinkInfo, aMacAddrs.mSource));
|
||||
IgnoreError(HandleDatagram(*message, aMacAddrs.mSource));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1664,7 +1662,7 @@ exit:
|
||||
}
|
||||
}
|
||||
|
||||
Error MeshForwarder::HandleDatagram(Message &aMessage, const ThreadLinkInfo &aLinkInfo, const Mac::Address &aMacSource)
|
||||
Error MeshForwarder::HandleDatagram(Message &aMessage, const Mac::Address &aMacSource)
|
||||
{
|
||||
#if OPENTHREAD_CONFIG_HISTORY_TRACKER_ENABLE
|
||||
Get<Utils::HistoryTracker>().RecordRxMessage(aMessage, aMacSource);
|
||||
@@ -1680,7 +1678,7 @@ Error MeshForwarder::HandleDatagram(Message &aMessage, const ThreadLinkInfo &aLi
|
||||
aMessage.SetLoopbackToHostAllowed(true);
|
||||
aMessage.SetOrigin(Message::kOriginThreadNetif);
|
||||
|
||||
return Get<Ip6::Ip6>().HandleDatagram(OwnedPtr<Message>(&aMessage), &aLinkInfo);
|
||||
return Get<Ip6::Ip6>().HandleDatagram(OwnedPtr<Message>(&aMessage));
|
||||
}
|
||||
|
||||
Error MeshForwarder::GetFramePriority(const FrameData &aFrameData,
|
||||
|
||||
@@ -550,7 +550,7 @@ private:
|
||||
uint16_t aFragmentLength,
|
||||
uint16_t aSrcRloc16,
|
||||
Message::Priority aPriority);
|
||||
Error HandleDatagram(Message &aMessage, const ThreadLinkInfo &aLinkInfo, const Mac::Address &aMacSource);
|
||||
Error HandleDatagram(Message &aMessage, const Mac::Address &aMacSource);
|
||||
void ClearReassemblyList(void);
|
||||
void EvictMessage(Message &aMessage);
|
||||
void HandleDiscoverComplete(void);
|
||||
|
||||
@@ -706,13 +706,7 @@ void MeshForwarder::HandleMesh(FrameData &aFrameData, const Mac::Address &aMacSo
|
||||
SuccessOrExit(error = meshHeader.AppendTo(*messagePtr));
|
||||
SuccessOrExit(error = messagePtr->AppendData(aFrameData));
|
||||
|
||||
messagePtr->SetLinkInfo(aLinkInfo);
|
||||
|
||||
#if OPENTHREAD_CONFIG_MULTI_RADIO
|
||||
// We set the received radio type on the message in order for it
|
||||
// to be logged correctly from LogMessage().
|
||||
messagePtr->SetRadioType(static_cast<Mac::RadioType>(aLinkInfo.mRadioType));
|
||||
#endif
|
||||
messagePtr->UpdateLinkInfoFrom(aLinkInfo);
|
||||
|
||||
LogMessage(kMessageReceive, *messagePtr, kErrorNone, &aMacSource);
|
||||
|
||||
|
||||
@@ -1093,7 +1093,7 @@ void Mle::InitNeighbor(Neighbor &aNeighbor, const RxInfo &aRxInfo)
|
||||
{
|
||||
aRxInfo.mMessageInfo.GetPeerAddr().GetIid().ConvertToExtAddress(aNeighbor.GetExtAddress());
|
||||
aNeighbor.GetLinkInfo().Clear();
|
||||
aNeighbor.GetLinkInfo().AddRss(aRxInfo.mMessageInfo.GetThreadLinkInfo()->GetRss());
|
||||
aNeighbor.GetLinkInfo().AddRss(aRxInfo.mMessage.GetAverageRss());
|
||||
aNeighbor.ResetLinkFailures();
|
||||
aNeighbor.SetLastHeard(TimerMilli::GetNow());
|
||||
}
|
||||
@@ -2431,7 +2431,7 @@ void Mle::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageIn
|
||||
|
||||
LogDebg("Receive MLE message");
|
||||
|
||||
VerifyOrExit(aMessageInfo.GetLinkInfo() != nullptr);
|
||||
VerifyOrExit(aMessage.GetOrigin() == Message::kOriginThreadNetif);
|
||||
VerifyOrExit(aMessageInfo.GetHopLimit() == kMleHopLimit, error = kErrorParse);
|
||||
|
||||
SuccessOrExit(error = aMessage.Read(aMessage.GetOffset(), securitySuite));
|
||||
@@ -2699,7 +2699,7 @@ exit:
|
||||
// We skip logging failures for broadcast MLE messages since it
|
||||
// can be common to receive such messages from adjacent Thread
|
||||
// networks.
|
||||
if (!aMessageInfo.GetSockAddr().IsMulticast() || !aMessageInfo.GetThreadLinkInfo()->IsDstPanIdBroadcast())
|
||||
if (!aMessageInfo.GetSockAddr().IsMulticast() || !aMessage.IsDstPanIdBroadcast())
|
||||
{
|
||||
LogProcessError(kTypeGenericUdp, error);
|
||||
}
|
||||
@@ -3132,7 +3132,7 @@ exit:
|
||||
void Mle::HandleParentResponse(RxInfo &aRxInfo)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
int8_t rss = aRxInfo.mMessageInfo.GetThreadLinkInfo()->GetRss();
|
||||
int8_t rss = aRxInfo.mMessage.GetAverageRss();
|
||||
RxChallenge response;
|
||||
uint16_t version;
|
||||
uint16_t sourceAddress;
|
||||
|
||||
@@ -748,16 +748,16 @@ void MleRouter::HandleLinkRequest(RxInfo &aRxInfo)
|
||||
aRxInfo.mClass = RxInfo::kPeerMessage;
|
||||
ProcessKeySequence(aRxInfo);
|
||||
|
||||
SuccessOrExit(error = SendLinkAccept(aRxInfo.mMessageInfo, neighbor, requestedTlvList, challenge));
|
||||
SuccessOrExit(error = SendLinkAccept(aRxInfo, neighbor, requestedTlvList, challenge));
|
||||
|
||||
exit:
|
||||
LogProcessError(kTypeLinkRequest, error);
|
||||
}
|
||||
|
||||
Error MleRouter::SendLinkAccept(const Ip6::MessageInfo &aMessageInfo,
|
||||
Neighbor *aNeighbor,
|
||||
const TlvList &aRequestedTlvList,
|
||||
const RxChallenge &aChallenge)
|
||||
Error MleRouter::SendLinkAccept(const RxInfo &aRxInfo,
|
||||
Neighbor *aNeighbor,
|
||||
const TlvList &aRequestedTlvList,
|
||||
const RxChallenge &aChallenge)
|
||||
{
|
||||
static const uint8_t kRouterTlvs[] = {Tlv::kLinkMargin};
|
||||
|
||||
@@ -776,7 +776,7 @@ Error MleRouter::SendLinkAccept(const Ip6::MessageInfo &aMessageInfo,
|
||||
SuccessOrExit(error = message->AppendMleFrameCounterTlv());
|
||||
|
||||
// always append a link margin, regardless of whether or not it was requested
|
||||
linkMargin = Get<Mac::Mac>().ComputeLinkMargin(aMessageInfo.GetThreadLinkInfo()->GetRss());
|
||||
linkMargin = Get<Mac::Mac>().ComputeLinkMargin(aRxInfo.mMessage.GetAverageRss());
|
||||
|
||||
SuccessOrExit(error = message->AppendLinkMarginTlv(linkMargin));
|
||||
|
||||
@@ -823,20 +823,20 @@ Error MleRouter::SendLinkAccept(const Ip6::MessageInfo &aMessageInfo,
|
||||
}
|
||||
#endif
|
||||
|
||||
if (aMessageInfo.GetSockAddr().IsMulticast())
|
||||
if (aRxInfo.mMessageInfo.GetSockAddr().IsMulticast())
|
||||
{
|
||||
SuccessOrExit(error = message->SendAfterDelay(aMessageInfo.GetPeerAddr(),
|
||||
SuccessOrExit(error = message->SendAfterDelay(aRxInfo.mMessageInfo.GetPeerAddr(),
|
||||
1 + Random::NonCrypto::GetUint16InRange(0, kMaxLinkAcceptDelay)));
|
||||
|
||||
Log(kMessageDelay, (command == kCommandLinkAccept) ? kTypeLinkAccept : kTypeLinkAcceptAndRequest,
|
||||
aMessageInfo.GetPeerAddr());
|
||||
aRxInfo.mMessageInfo.GetPeerAddr());
|
||||
}
|
||||
else
|
||||
{
|
||||
SuccessOrExit(error = message->SendTo(aMessageInfo.GetPeerAddr()));
|
||||
SuccessOrExit(error = message->SendTo(aRxInfo.mMessageInfo.GetPeerAddr()));
|
||||
|
||||
Log(kMessageSend, (command == kCommandLinkAccept) ? kTypeLinkAccept : kTypeLinkAcceptAndRequest,
|
||||
aMessageInfo.GetPeerAddr());
|
||||
aRxInfo.mMessageInfo.GetPeerAddr());
|
||||
}
|
||||
|
||||
exit:
|
||||
@@ -1062,7 +1062,7 @@ Error MleRouter::HandleLinkAccept(RxInfo &aRxInfo, bool aRequest)
|
||||
ExitNow(error = kErrorParse);
|
||||
}
|
||||
|
||||
SuccessOrExit(error = SendLinkAccept(aRxInfo.mMessageInfo, router, requestedTlvList, challenge));
|
||||
SuccessOrExit(error = SendLinkAccept(aRxInfo, router, requestedTlvList, challenge));
|
||||
}
|
||||
|
||||
exit:
|
||||
@@ -1178,7 +1178,7 @@ Error MleRouter::HandleAdvertisement(RxInfo &aRxInfo, uint16_t aSourceAddress, c
|
||||
// - `aLeaderData` is the read value from `LeaderDataTlv`.
|
||||
|
||||
Error error = kErrorNone;
|
||||
uint8_t linkMargin = Get<Mac::Mac>().ComputeLinkMargin(aRxInfo.mMessageInfo.GetThreadLinkInfo()->GetRss());
|
||||
uint8_t linkMargin = Get<Mac::Mac>().ComputeLinkMargin(aRxInfo.mMessage.GetAverageRss());
|
||||
RouteTlv routeTlv;
|
||||
Router *router;
|
||||
uint8_t routerId;
|
||||
@@ -2118,7 +2118,7 @@ void MleRouter::HandleChildIdRequest(RxInfo &aRxInfo)
|
||||
child->SetKeySequence(aRxInfo.mKeySequence);
|
||||
child->SetDeviceMode(mode);
|
||||
child->SetVersion(version);
|
||||
child->GetLinkInfo().AddRss(aRxInfo.mMessageInfo.GetThreadLinkInfo()->GetRss());
|
||||
child->GetLinkInfo().AddRss(aRxInfo.mMessage.GetAverageRss());
|
||||
child->SetTimeout(timeout);
|
||||
child->SetSupervisionInterval(supervisionInterval);
|
||||
#if OPENTHREAD_CONFIG_MULTI_RADIO
|
||||
@@ -2533,7 +2533,7 @@ void MleRouter::HandleChildUpdateResponse(RxInfo &aRxInfo)
|
||||
SetChildStateToValid(*child);
|
||||
child->SetLastHeard(TimerMilli::GetNow());
|
||||
child->SetKeySequence(aRxInfo.mKeySequence);
|
||||
child->GetLinkInfo().AddRss(aRxInfo.mMessageInfo.GetThreadLinkInfo()->GetRss());
|
||||
child->GetLinkInfo().AddRss(aRxInfo.mMessage.GetAverageRss());
|
||||
|
||||
aRxInfo.mClass = response.IsEmpty() ? RxInfo::kPeerMessage : RxInfo::kAuthoritativeMessage;
|
||||
|
||||
|
||||
@@ -666,10 +666,10 @@ private:
|
||||
const Ip6::MessageInfo &aMessageInfo);
|
||||
void SendAddressRelease(void);
|
||||
void SendAdvertisement(void);
|
||||
Error SendLinkAccept(const Ip6::MessageInfo &aMessageInfo,
|
||||
Neighbor *aNeighbor,
|
||||
const TlvList &aRequestedTlvList,
|
||||
const RxChallenge &aChallenge);
|
||||
Error SendLinkAccept(const RxInfo &aRxInfo,
|
||||
Neighbor *aNeighbor,
|
||||
const TlvList &aRequestedTlvList,
|
||||
const RxChallenge &aChallenge);
|
||||
void SendParentResponse(Child *aChild, const RxChallenge &aChallenge, bool aRoutersOnlyRequest);
|
||||
Error SendChildIdResponse(Child &aChild);
|
||||
Error SendChildUpdateRequest(Child &aChild);
|
||||
|
||||
Reference in New Issue
Block a user