mirror of
https://github.com/espressif/openthread.git
synced 2026-08-03 17:37:46 +00:00
[mac] simplify and enhance Header IE processing (#13261)
This commit refactors `Mac::HeaderIe` generation and parsing to improve code readability, type safety, and bounds checking. Key changes include: - Adds `HeaderIe::GetSize()` and `HeaderIe::GetContent()` to encapsulate pointer arithmetic inside the class and eliminate ad-hoc pointer offset math across `Mac` modules. - Updates `Frame::FindPayloadIndex()`, `Frame::GetHeaderIe()`, `Frame::GetThreadIe()`, and `Frame::GetTimeIe()` to utilize the new helper methods, simplifying boundary checks. - Simplifies `HeaderIe::Init()` by replacing the union with a clearer `mLenIdType` field and updating the internal bitwise operations to use `bit_utils.hpp` helper methods.
This commit is contained in:
@@ -264,8 +264,7 @@ uint8_t otMacFrameGenerateCslIeTemplate(uint8_t *aDest)
|
||||
{
|
||||
assert(aDest != nullptr);
|
||||
|
||||
reinterpret_cast<Mac::HeaderIe *>(aDest)->SetId(Mac::CslIe::kHeaderIeId);
|
||||
reinterpret_cast<Mac::HeaderIe *>(aDest)->SetLength(sizeof(Mac::CslIe));
|
||||
reinterpret_cast<Mac::HeaderIe *>(aDest)->Init(Mac::CslIe::kHeaderIeId, sizeof(Mac::CslIe));
|
||||
|
||||
return sizeof(Mac::HeaderIe) + sizeof(Mac::CslIe);
|
||||
}
|
||||
@@ -278,8 +277,7 @@ uint8_t otMacFrameGenerateEnhAckProbingIe(uint8_t *aDest, const uint8_t *aIeData
|
||||
|
||||
assert(aDest != nullptr);
|
||||
|
||||
reinterpret_cast<Mac::HeaderIe *>(aDest)->SetId(Mac::ThreadIe::kHeaderIeId);
|
||||
reinterpret_cast<Mac::HeaderIe *>(aDest)->SetLength(len);
|
||||
reinterpret_cast<Mac::HeaderIe *>(aDest)->Init(Mac::ThreadIe::kHeaderIeId, len);
|
||||
|
||||
aDest += sizeof(Mac::HeaderIe);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user