mirror of
https://github.com/espressif/openthread.git
synced 2026-07-28 22:57:47 +00:00
[mac] enable Beacon Payload in outgoing beacons (#7767)
This commit enables beacon payloads on outgoing beacons to prevent backward compatibility issues with existing devices in the market.
This commit is contained in:
@@ -90,6 +90,7 @@ build_all_features()
|
||||
"-DOPENTHREAD_CONFIG_TMF_NETWORK_DIAG_MTD_ENABLE=1"
|
||||
"-DOPENTHREAD_CONFIG_UDP_FORWARD_ENABLE=1"
|
||||
"-DOPENTHREAD_CONFIG_MAC_BEACON_PAYLOAD_PARSING_ENABLE=1"
|
||||
"-DOPENTHREAD_CONFIG_MAC_OUTGOING_BEACON_PAYLOAD_ENABLE=1"
|
||||
)
|
||||
|
||||
local options_1_2=(
|
||||
|
||||
@@ -510,4 +510,15 @@
|
||||
#define OPENTHREAD_CONFIG_MAC_BEACON_PAYLOAD_PARSING_ENABLE 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_MAC_OUTGOING_BEACON_PAYLOAD_ENABLE
|
||||
*
|
||||
* This setting configures if the beacon payload needs to be enabled in outgoing beacon frames. This is optional and is
|
||||
* disabled by default because Thread 1.2.1 has removed support for beacon payloads.
|
||||
*
|
||||
*/
|
||||
#ifndef OPENTHREAD_CONFIG_MAC_OUTGOING_BEACON_PAYLOAD_ENABLE
|
||||
#define OPENTHREAD_CONFIG_MAC_OUTGOING_BEACON_PAYLOAD_ENABLE 0
|
||||
#endif
|
||||
|
||||
#endif // CONFIG_MAC_H_
|
||||
|
||||
@@ -737,6 +737,10 @@ TxFrame *Mac::PrepareBeacon(void)
|
||||
TxFrame *frame;
|
||||
uint16_t fcf;
|
||||
Beacon * beacon = nullptr;
|
||||
#if OPENTHREAD_CONFIG_MAC_OUTGOING_BEACON_PAYLOAD_ENABLE
|
||||
uint8_t beaconLength;
|
||||
BeaconPayload *beaconPayload = nullptr;
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_CONFIG_MULTI_RADIO
|
||||
OT_ASSERT(!mTxBeaconRadioLinks.IsEmpty());
|
||||
@@ -754,6 +758,30 @@ TxFrame *Mac::PrepareBeacon(void)
|
||||
beacon = reinterpret_cast<Beacon *>(frame->GetPayload());
|
||||
beacon->Init();
|
||||
|
||||
#if OPENTHREAD_CONFIG_MAC_OUTGOING_BEACON_PAYLOAD_ENABLE
|
||||
beaconLength = sizeof(*beacon);
|
||||
|
||||
beaconPayload = reinterpret_cast<BeaconPayload *>(beacon->GetPayload());
|
||||
|
||||
beaconPayload->Init();
|
||||
|
||||
if (IsJoinable())
|
||||
{
|
||||
beaconPayload->SetJoiningPermitted();
|
||||
}
|
||||
else
|
||||
{
|
||||
beaconPayload->ClearJoiningPermitted();
|
||||
}
|
||||
|
||||
beaconPayload->SetNetworkName(Get<MeshCoP::NetworkNameManager>().GetNetworkName().GetAsData());
|
||||
beaconPayload->SetExtendedPanId(Get<MeshCoP::ExtendedPanIdManager>().GetExtPanId());
|
||||
|
||||
beaconLength += sizeof(*beaconPayload);
|
||||
|
||||
frame->SetPayloadLength(beaconLength);
|
||||
#endif
|
||||
|
||||
LogBeacon("Sending");
|
||||
|
||||
return frame;
|
||||
|
||||
+63
-10
@@ -43,6 +43,7 @@
|
||||
#include "common/const_cast.hpp"
|
||||
#include "common/encoding.hpp"
|
||||
#include "mac/mac_types.hpp"
|
||||
#include "meshcop/network_name.hpp"
|
||||
|
||||
namespace ot {
|
||||
namespace Mac {
|
||||
@@ -1482,7 +1483,6 @@ private:
|
||||
uint8_t mPendingAddressSpec;
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
#if OPENTHREAD_CONFIG_MAC_BEACON_PAYLOAD_PARSING_ENABLE
|
||||
/**
|
||||
* This class implements IEEE 802.15.4 Beacon Payload generation and parsing.
|
||||
*
|
||||
@@ -1491,16 +1491,22 @@ OT_TOOL_PACKED_BEGIN
|
||||
class BeaconPayload
|
||||
{
|
||||
public:
|
||||
static constexpr uint8_t kProtocolId = 3; ///< Thread Protocol ID.
|
||||
static constexpr uint8_t kVersionOffset = 4; ///< Version field bit offset.
|
||||
static constexpr uint8_t kNativeFlag = 1 << 3; ///< Native Commissioner flag.
|
||||
static constexpr uint8_t kJoiningFlag = 1 << 0; ///< Joining Permitted flag.
|
||||
static constexpr uint8_t kProtocolId = 3; ///< Thread Protocol ID.
|
||||
static constexpr uint8_t kProtocolVersion = 2; ///< Thread Protocol version.
|
||||
static constexpr uint8_t kVersionOffset = 4; ///< Version field bit offset.
|
||||
static constexpr uint8_t kVersionMask = 0xf << kVersionOffset; ///< Version field mask.
|
||||
static constexpr uint8_t kNativeFlag = 1 << 3; ///< Native Commissioner flag.
|
||||
static constexpr uint8_t kJoiningFlag = 1 << 0; ///< Joining Permitted flag.
|
||||
|
||||
/**
|
||||
* This constant specified the maximum number of chars in Network Name (excludes null char).
|
||||
* This method initializes the Beacon Payload.
|
||||
*
|
||||
*/
|
||||
static constexpr uint8_t kMaxSize = OT_NETWORK_NAME_MAX_SIZE;
|
||||
void Init(void)
|
||||
{
|
||||
mProtocolId = kProtocolId;
|
||||
mFlags = kProtocolVersion << kVersionOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method indicates whether or not the beacon appears to be a valid Thread Beacon Payload.
|
||||
@@ -1536,6 +1542,18 @@ public:
|
||||
*/
|
||||
bool IsNative(void) const { return (mFlags & kNativeFlag) != 0; }
|
||||
|
||||
/**
|
||||
* This method clears the Native Commissioner flag.
|
||||
*
|
||||
*/
|
||||
void ClearNative(void) { mFlags &= ~kNativeFlag; }
|
||||
|
||||
/**
|
||||
* This method sets the Native Commissioner flag.
|
||||
*
|
||||
*/
|
||||
void SetNative(void) { mFlags |= kNativeFlag; }
|
||||
|
||||
/**
|
||||
* This method indicates whether or not the Joining Permitted flag is set.
|
||||
*
|
||||
@@ -1545,13 +1563,41 @@ public:
|
||||
*/
|
||||
bool IsJoiningPermitted(void) const { return (mFlags & kJoiningFlag) != 0; }
|
||||
|
||||
/**
|
||||
* This method clears the Joining Permitted flag.
|
||||
*
|
||||
*/
|
||||
void ClearJoiningPermitted(void) { mFlags &= ~kJoiningFlag; }
|
||||
|
||||
/**
|
||||
* This method sets the Joining Permitted flag.
|
||||
*
|
||||
*/
|
||||
void SetJoiningPermitted(void)
|
||||
{
|
||||
mFlags |= kJoiningFlag;
|
||||
|
||||
#if OPENTHREAD_CONFIG_MAC_JOIN_BEACON_VERSION != 2 // check against kProtocolVersion
|
||||
mFlags &= ~kVersionMask;
|
||||
mFlags |= OPENTHREAD_CONFIG_MAC_JOIN_BEACON_VERSION << kVersionOffset;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets the Network Name field.
|
||||
*
|
||||
* @returns The Network Name field as `NameData`.
|
||||
*
|
||||
*/
|
||||
const char *GetNetworkName(void) const { return mNetworkName; }
|
||||
MeshCoP::NameData GetNetworkName(void) const { return MeshCoP::NameData(mNetworkName, sizeof(mNetworkName)); }
|
||||
|
||||
/**
|
||||
* This method sets the Network Name field.
|
||||
*
|
||||
* @param[in] aNameData The Network Name (as a `NameData`).
|
||||
*
|
||||
*/
|
||||
void SetNetworkName(const MeshCoP::NameData &aNameData) { aNameData.CopyTo(mNetworkName, sizeof(mNetworkName)); }
|
||||
|
||||
/**
|
||||
* This method returns the Extended PAN ID field.
|
||||
@@ -1561,13 +1607,20 @@ public:
|
||||
*/
|
||||
const otExtendedPanId &GetExtendedPanId(void) const { return mExtendedPanId; }
|
||||
|
||||
/**
|
||||
* This method sets the Extended PAN ID field.
|
||||
*
|
||||
* @param[in] aExtPanId An Extended PAN ID.
|
||||
*
|
||||
*/
|
||||
void SetExtendedPanId(const otExtendedPanId &aExtPanId) { mExtendedPanId = aExtPanId; }
|
||||
|
||||
private:
|
||||
uint8_t mProtocolId;
|
||||
uint8_t mFlags;
|
||||
char mNetworkName[kMaxSize];
|
||||
char mNetworkName[MeshCoP::NetworkName::kMaxSize];
|
||||
otExtendedPanId mExtendedPanId;
|
||||
} OT_TOOL_PACKED_END;
|
||||
#endif // OPENTHREAD_CONFIG_MAC_BEACON_PAYLOAD_PARSING_ENABLE
|
||||
|
||||
/**
|
||||
* This class implements CSL IE data structure.
|
||||
|
||||
Reference in New Issue
Block a user