mirror of
https://github.com/espressif/openthread.git
synced 2026-07-29 23:27:46 +00:00
[mac] simplify implementation of ENABLE_BEACON_RSP_WHEN_JOINABLE feature (#3216)
This commit is contained in:
committed by
Jonathan Hui
parent
980097c2ef
commit
bbd8b3466f
+30
-26
@@ -946,6 +946,35 @@ void Mac::SendBeacon(Frame &aFrame)
|
||||
LogBeacon("Sending", *beaconPayload);
|
||||
}
|
||||
|
||||
bool Mac::ShouldSendBeacon(void) const
|
||||
{
|
||||
bool shouldSend = false;
|
||||
|
||||
VerifyOrExit(mEnabled);
|
||||
|
||||
shouldSend = IsBeaconEnabled();
|
||||
|
||||
#if OPENTHREAD_CONFIG_ENABLE_BEACON_RSP_WHEN_JOINABLE
|
||||
if (!shouldSend)
|
||||
{
|
||||
// When `ENABLE_BEACON_RSP_WHEN_JOINABLE` feature is enabled,
|
||||
// the device should transmit IEEE 802.15.4 Beacons in response
|
||||
// to IEEE 802.15.4 Beacon Requests even while the device is not
|
||||
// router capable and detached (i.e., `IsBeaconeEnabled()` is
|
||||
// false) but only if it is in joinable state (unsecure port
|
||||
// list is not empty).
|
||||
|
||||
uint8_t numUnsecurePorts;
|
||||
|
||||
GetNetif().GetIp6Filter().GetUnsecurePorts(numUnsecurePorts);
|
||||
shouldSend = (numUnsecurePorts != 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
exit:
|
||||
return shouldSend;
|
||||
}
|
||||
|
||||
void Mac::ProcessTransmitAesCcm(Frame &aFrame, const ExtAddress *aExtAddress)
|
||||
{
|
||||
uint32_t frameCounter = 0;
|
||||
@@ -2198,11 +2227,7 @@ otError Mac::HandleMacCommand(Frame &aFrame)
|
||||
mCounters.mRxBeaconRequest++;
|
||||
otLogInfoMac("Received Beacon Request");
|
||||
|
||||
if (mEnabled && (mBeaconsEnabled
|
||||
#if OPENTHREAD_CONFIG_ENABLE_BEACON_RSP_WHEN_JOINABLE
|
||||
|| IsBeaconJoinable()
|
||||
#endif // OPENTHREAD_CONFIG_ENABLE_BEACON_RSP_WHEN_JOINABLE
|
||||
))
|
||||
if (ShouldSendBeacon())
|
||||
{
|
||||
StartOperation(kOperationTransmitBeacon);
|
||||
}
|
||||
@@ -2289,27 +2314,6 @@ int8_t Mac::GetNoiseFloor(void)
|
||||
return otPlatRadioGetReceiveSensitivity(&GetInstance());
|
||||
}
|
||||
|
||||
#if OPENTHREAD_CONFIG_ENABLE_BEACON_RSP_WHEN_JOINABLE
|
||||
bool Mac::IsBeaconJoinable(void)
|
||||
{
|
||||
uint8_t numUnsecurePorts;
|
||||
bool joinable = false;
|
||||
|
||||
GetNetif().GetIp6Filter().GetUnsecurePorts(numUnsecurePorts);
|
||||
|
||||
if (numUnsecurePorts)
|
||||
{
|
||||
joinable = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
joinable = false;
|
||||
}
|
||||
|
||||
return joinable;
|
||||
}
|
||||
#endif // OPENTHREAD_CONFIG_ENABLE_BEACON_RSP_WHEN_JOINABLE
|
||||
|
||||
const char *Mac::OperationToString(Operation aOperation)
|
||||
{
|
||||
const char *retval = "";
|
||||
|
||||
+1
-11
@@ -832,17 +832,6 @@ public:
|
||||
*/
|
||||
void ResetCounters(void);
|
||||
|
||||
#if OPENTHREAD_CONFIG_ENABLE_BEACON_RSP_WHEN_JOINABLE
|
||||
/**
|
||||
* This method indicates if the device is in joinable state or not.
|
||||
*
|
||||
* @retval true Device is joinable.
|
||||
* @retval false Device is non-joinable.
|
||||
*
|
||||
*/
|
||||
bool IsBeaconJoinable(void);
|
||||
#endif // OPENTHREAD_CONFIG_ENABLE_BEACON_RSP_WHEN_JOINABLE
|
||||
|
||||
/**
|
||||
* This method returns the MAC counter.
|
||||
*
|
||||
@@ -973,6 +962,7 @@ private:
|
||||
void FinishOperation(void);
|
||||
void SendBeaconRequest(Frame &aFrame);
|
||||
void SendBeacon(Frame &aFrame);
|
||||
bool ShouldSendBeacon(void) const;
|
||||
void StartBackoff(void);
|
||||
void BeginTransmit(void);
|
||||
otError HandleMacCommand(Frame &aFrame);
|
||||
|
||||
Reference in New Issue
Block a user