[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:
Abtin Keshavarzian
2026-06-22 13:46:52 -07:00
committed by GitHub
parent 5f9fe671e9
commit 4394c0944b
4 changed files with 56 additions and 56 deletions
+2 -4
View File
@@ -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);