Skip to content

Commit 819938d

Browse files
authored
[core] move ThreadLinkInfo to its own header and source files (openthread#11444)
This commit refactors the `ThreadLinkInfo` definition by moving it into its own dedicated header (`thread_link_info.hpp`) and source (`.cpp`) files. Previously, this definition was part of `mesh_forwarder.hpp`. This change simplifies the overall code structure. It also allows the new `thread_link_info.hpp` header to be included by other modules, such as `message.hpp`, thereby avoiding the need for forward declarations.
1 parent 49352a1 commit 819938d

7 files changed

Lines changed: 218 additions & 127 deletions

File tree

src/core/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,8 @@ openthread_core_files = [
703703
"thread/router_table.hpp",
704704
"thread/src_match_controller.cpp",
705705
"thread/src_match_controller.hpp",
706+
"thread/thread_link_info.cpp",
707+
"thread/thread_link_info.hpp",
706708
"thread/thread_netif.cpp",
707709
"thread/thread_netif.hpp",
708710
"thread/thread_tlvs.hpp",

src/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ set(COMMON_SOURCES
246246
thread/router.cpp
247247
thread/router_table.cpp
248248
thread/src_match_controller.cpp
249+
thread/thread_link_info.cpp
249250
thread/thread_netif.cpp
250251
thread/time_sync_service.cpp
251252
thread/tmf.cpp

src/core/common/message.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#include "mac/mac_types.hpp"
6060
#include "thread/child_mask.hpp"
6161
#include "thread/link_quality.hpp"
62+
#include "thread/thread_link_info.hpp"
6263

6364
/**
6465
* Represents an opaque (and empty) type for an OpenThread message buffer.
@@ -147,7 +148,6 @@ class Message;
147148
class MessagePool;
148149
class MessageQueue;
149150
class PriorityQueue;
150-
class ThreadLinkInfo;
151151

152152
/**
153153
* Represents the link security mode indicating whether to use MAC (layer two) security.

src/core/thread/mesh_forwarder.cpp

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -40,56 +40,6 @@ namespace ot {
4040

4141
RegisterLogModule("MeshForwarder");
4242

43-
void ThreadLinkInfo::SetFrom(const Mac::RxFrame &aFrame)
44-
{
45-
Clear();
46-
47-
if (kErrorNone != aFrame.GetSrcPanId(mPanId))
48-
{
49-
IgnoreError(aFrame.GetDstPanId(mPanId));
50-
}
51-
52-
{
53-
Mac::PanId dstPanId;
54-
55-
if (kErrorNone != aFrame.GetDstPanId(dstPanId))
56-
{
57-
dstPanId = mPanId;
58-
}
59-
60-
mIsDstPanIdBroadcast = (dstPanId == Mac::kPanIdBroadcast);
61-
}
62-
63-
if (aFrame.GetSecurityEnabled())
64-
{
65-
uint8_t keyIdMode;
66-
67-
// MAC Frame Security was already validated at the MAC
68-
// layer. As a result, `GetKeyIdMode()` will never return
69-
// failure here.
70-
IgnoreError(aFrame.GetKeyIdMode(keyIdMode));
71-
72-
mLinkSecurity = (keyIdMode == Mac::Frame::kKeyIdMode0) || (keyIdMode == Mac::Frame::kKeyIdMode1);
73-
}
74-
else
75-
{
76-
mLinkSecurity = false;
77-
}
78-
mChannel = aFrame.GetChannel();
79-
mRss = aFrame.GetRssi();
80-
mLqi = aFrame.GetLqi();
81-
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
82-
if (aFrame.GetTimeIe() != nullptr)
83-
{
84-
mNetworkTimeOffset = aFrame.ComputeNetworkTimeOffset();
85-
mTimeSyncSeq = aFrame.ReadTimeSyncSeq();
86-
}
87-
#endif
88-
#if OPENTHREAD_CONFIG_MULTI_RADIO
89-
mRadioType = static_cast<uint8_t>(aFrame.GetRadioType());
90-
#endif
91-
}
92-
9343
void MeshForwarder::Counters::UpdateOnTxDone(const Message &aMessage, bool aTxSuccess)
9444
{
9545
if (aMessage.GetType() == Message::kTypeIp6)

src/core/thread/mesh_forwarder.hpp

Lines changed: 1 addition & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include "thread/indirect_sender.hpp"
5656
#include "thread/lowpan.hpp"
5757
#include "thread/network_data_leader.hpp"
58+
#include "thread/thread_link_info.hpp"
5859

5960
namespace ot {
6061

@@ -75,80 +76,6 @@ class HistoryTracker;
7576
* @{
7677
*/
7778

78-
/**
79-
* Represents link-specific information for messages received from the Thread radio.
80-
*/
81-
class ThreadLinkInfo : public otThreadLinkInfo, public Clearable<ThreadLinkInfo>
82-
{
83-
public:
84-
/**
85-
* Returns the IEEE 802.15.4 Source PAN ID.
86-
*
87-
* @returns The IEEE 802.15.4 Source PAN ID.
88-
*/
89-
Mac::PanId GetPanId(void) const { return mPanId; }
90-
91-
/**
92-
* Returns the IEEE 802.15.4 Channel.
93-
*
94-
* @returns The IEEE 802.15.4 Channel.
95-
*/
96-
uint8_t GetChannel(void) const { return mChannel; }
97-
98-
/**
99-
* Returns whether the Destination PAN ID is broadcast.
100-
*
101-
* @retval TRUE If Destination PAN ID is broadcast.
102-
* @retval FALSE If Destination PAN ID is not broadcast.
103-
*/
104-
bool IsDstPanIdBroadcast(void) const { return mIsDstPanIdBroadcast; }
105-
106-
/**
107-
* Indicates whether or not link security is enabled.
108-
*
109-
* @retval TRUE If link security is enabled.
110-
* @retval FALSE If link security is not enabled.
111-
*/
112-
bool IsLinkSecurityEnabled(void) const { return mLinkSecurity; }
113-
114-
/**
115-
* Returns the Received Signal Strength (RSS) in dBm.
116-
*
117-
* @returns The Received Signal Strength (RSS) in dBm.
118-
*/
119-
int8_t GetRss(void) const { return mRss; }
120-
121-
/**
122-
* Returns the frame/radio Link Quality Indicator (LQI) value.
123-
*
124-
* @returns The Link Quality Indicator value.
125-
*/
126-
uint8_t GetLqi(void) const { return mLqi; }
127-
128-
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
129-
/**
130-
* Returns the Time Sync Sequence.
131-
*
132-
* @returns The Time Sync Sequence.
133-
*/
134-
uint8_t GetTimeSyncSeq(void) const { return mTimeSyncSeq; }
135-
136-
/**
137-
* Returns the time offset to the Thread network time (in microseconds).
138-
*
139-
* @returns The time offset to the Thread network time (in microseconds).
140-
*/
141-
int64_t GetNetworkTimeOffset(void) const { return mNetworkTimeOffset; }
142-
#endif
143-
144-
/**
145-
* Sets the `ThreadLinkInfo` from a given received frame.
146-
*
147-
* @param[in] aFrame A received frame.
148-
*/
149-
void SetFrom(const Mac::RxFrame &aFrame);
150-
};
151-
15279
/**
15380
* Implements mesh forwarding within Thread.
15481
*/
@@ -679,8 +606,6 @@ class MeshForwarder : public InstanceLocator, private NonCopyable
679606
* @}
680607
*/
681608

682-
DefineCoreType(otThreadLinkInfo, ThreadLinkInfo);
683-
684609
} // namespace ot
685610

686611
#endif // MESH_FORWARDER_HPP_
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright (c) 2025, The OpenThread Authors.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
* 1. Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
* 3. Neither the name of the copyright holder nor the
13+
* names of its contributors may be used to endorse or promote products
14+
* derived from this software without specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
*/
28+
29+
/**
30+
* @file
31+
* This file implements `ThreadLinkInfo`
32+
*/
33+
34+
#include "thread_link_info.hpp"
35+
36+
namespace ot {
37+
38+
void ThreadLinkInfo::SetFrom(const Mac::RxFrame &aFrame)
39+
{
40+
Clear();
41+
42+
if (kErrorNone != aFrame.GetSrcPanId(mPanId))
43+
{
44+
IgnoreError(aFrame.GetDstPanId(mPanId));
45+
}
46+
47+
{
48+
Mac::PanId dstPanId;
49+
50+
if (kErrorNone != aFrame.GetDstPanId(dstPanId))
51+
{
52+
dstPanId = mPanId;
53+
}
54+
55+
mIsDstPanIdBroadcast = (dstPanId == Mac::kPanIdBroadcast);
56+
}
57+
58+
if (aFrame.GetSecurityEnabled())
59+
{
60+
uint8_t keyIdMode;
61+
62+
// MAC Frame Security was already validated at the MAC
63+
// layer. As a result, `GetKeyIdMode()` will never return
64+
// failure here.
65+
IgnoreError(aFrame.GetKeyIdMode(keyIdMode));
66+
67+
mLinkSecurity = (keyIdMode == Mac::Frame::kKeyIdMode0) || (keyIdMode == Mac::Frame::kKeyIdMode1);
68+
}
69+
else
70+
{
71+
mLinkSecurity = false;
72+
}
73+
mChannel = aFrame.GetChannel();
74+
mRss = aFrame.GetRssi();
75+
mLqi = aFrame.GetLqi();
76+
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
77+
if (aFrame.GetTimeIe() != nullptr)
78+
{
79+
mNetworkTimeOffset = aFrame.ComputeNetworkTimeOffset();
80+
mTimeSyncSeq = aFrame.ReadTimeSyncSeq();
81+
}
82+
#endif
83+
#if OPENTHREAD_CONFIG_MULTI_RADIO
84+
mRadioType = static_cast<uint8_t>(aFrame.GetRadioType());
85+
#endif
86+
}
87+
88+
} // namespace ot

0 commit comments

Comments
 (0)