Skip to content

Commit

Permalink
zigbee: Fix valgrind variables initialization errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Gallegos Ramonet committed Dec 5, 2024
1 parent 50c9e94 commit 1f208a0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
18 changes: 10 additions & 8 deletions src/lr-wpan/model/lr-wpan-mac-base.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,13 @@ enum MacPibAttributeIdentifier
*/
struct MacPibAttributes : public SimpleRefCount<MacPibAttributes>
{
std::vector<uint8_t> macBeaconPayload; //!< The set with the contents of the beacon payload.
uint8_t macBeaconPayloadLength{0}; //!< The length in octets of the beacon payload.
Mac16Address macShortAddress; //!< The 16 bit mac short address
Mac64Address macExtendedAddress; //!< The EUI-64 bit address
uint16_t macPanId{0xffff}; //!< The identifier of the PAN
bool macAssociationPermit{true}; //!< Indication of whether the coordinator is allowing
//!< association.
std::vector<uint8_t> macBeaconPayload{}; //!< The set with the contents of the beacon payload.
uint8_t macBeaconPayloadLength{0}; //!< The length in octets of the beacon payload.
Mac16Address macShortAddress; //!< The 16 bit mac short address
Mac64Address macExtendedAddress; //!< The EUI-64 bit address
uint16_t macPanId{0xffff}; //!< The identifier of the PAN
bool macAssociationPermit{true}; //!< Indication of whether the coordinator is allowing
//!< association.
bool macRxOnWhenIdle{true}; //!< Indication of whether the MAC is enabled during idle periods.
bool macPromiscuousMode{false}; //!< Indication of whether the mac is in promiscuous mode
//!< (Receive all mode).
Expand Down Expand Up @@ -502,7 +502,9 @@ struct MlmeSetConfirmParams
MacStatus m_status{MacStatus::UNSUPPORTED_ATTRIBUTE}; //!< The result of
//!< the request to write
//!< the PIB attribute.
MacPibAttributeIdentifier id; //!< The id of the PIB attribute that was written.
MacPibAttributeIdentifier id{
MacPibAttributeIdentifier::unsupported}; //!< The id of the
//!< PIB attribute that was written.
};

/**
Expand Down
38 changes: 22 additions & 16 deletions src/zigbee/model/zigbee-nwk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,21 @@ ZigbeeNwk::GetTypeId()

ZigbeeNwk::ZigbeeNwk()
{
// Collects the values from Attributes before initializing
// objects in the constructor (Requires GetInstanceTypeId and GetTypeId)
ObjectBase::ConstructSelf(AttributeConstructionList());
NS_LOG_FUNCTION(this);
}

void
ZigbeeNwk::NotifyConstructionCompleted()
{
NS_LOG_FUNCTION(this);

m_pendPrimitiveNwk = PendingPrimitiveNwk::NLDE_NLME_NONE;
m_uniformRandomVariable = CreateObject<UniformRandomVariable>();
m_uniformRandomVariable->SetAttribute("Min", DoubleValue(0.0));
m_uniformRandomVariable->SetAttribute("Max", DoubleValue(255.0));

m_scanEnergyThreshold = 127;
m_pendPrimitiveNwk = NLDE_NLME_NONE;

m_netFormParams = {};
m_netFormParamsGen = nullptr;
m_nwkNetworkAddress = Mac16Address("ff:ff");
Expand Down Expand Up @@ -138,9 +147,6 @@ ZigbeeNwk::ZigbeeNwk()
// TODO, set according to equation 3.5.2.1?
m_nwkNetworkBroadcastDeliveryTime = Seconds(9);

m_uniformRandomVariable = CreateObject<UniformRandomVariable>();
m_uniformRandomVariable->SetAttribute("Min", DoubleValue(0.0));
m_uniformRandomVariable->SetAttribute("Max", DoubleValue(255.0));
m_nwkSequenceNumber = SequenceNumber8(m_uniformRandomVariable->GetValue());
m_routeRequestId = SequenceNumber8(m_uniformRandomVariable->GetValue());
m_macHandle = SequenceNumber8(m_uniformRandomVariable->GetValue());
Expand All @@ -155,17 +161,20 @@ ZigbeeNwk::ZigbeeNwk()

ZigbeeNwk::~ZigbeeNwk()
{
NS_LOG_FUNCTION(this);
}

void
ZigbeeNwk::DoInitialize()
{
NS_LOG_FUNCTION(this);
Object::DoInitialize();
}

void
ZigbeeNwk::DoDispose()
{
NS_LOG_FUNCTION(this);
m_panIdTable.Dispose();
m_nwkNeighborTable.Dispose();
m_nwkRoutingTable.Dispose();
Expand Down Expand Up @@ -1535,7 +1544,7 @@ ZigbeeNwk::MlmeGetConfirm(MacStatus status,
MacPibAttributeIdentifier id,
Ptr<MacPibAttributes> attribute)
{
if (m_pendPrimitiveNwk == NLME_NETWORK_FORMATION)
if (m_pendPrimitiveNwk == PendingPrimitiveNwk::NLME_NETWORK_FORMATION)
{
if (id == MacPibAttributeIdentifier::macExtendedAddress && status == MacStatus::SUCCESS)
{
Expand Down Expand Up @@ -1569,7 +1578,7 @@ ZigbeeNwk::MlmeGetConfirm(MacStatus status,
}
}
}
else if (m_pendPrimitiveNwk == NLME_JOIN && status == MacStatus::SUCCESS)
else if (m_pendPrimitiveNwk == PendingPrimitiveNwk::NLME_JOIN && status == MacStatus::SUCCESS)
{
if (id == MacPibAttributeIdentifier::macShortAddress)
{
Expand Down Expand Up @@ -3032,14 +3041,11 @@ ZigbeeNwk::UpdateBeaconPayload()
Ptr<Packet> payload = Create<Packet>();
payload->AddHeader(beaconPayloadHeader);
// Extract octets from payload
auto octetsPtr = new uint8_t[payload->GetSize()];
payload->CopyData(octetsPtr, payload->GetSize());
// Add octets to macBeaconPayload vector
// Extract octets from payload and copy them into the macBeaconPayload attribute
Ptr<MacPibAttributes> pibAttr = Create<MacPibAttributes>();
pibAttr->macBeaconPayload = std::vector<uint8_t>(octetsPtr, octetsPtr + payload->GetSize());
// pibAttr->macBeaconPayloadLength = payload->GetSize();
pibAttr->macBeaconPayload.resize(payload->GetSize());
payload->CopyData(pibAttr->macBeaconPayload.data(), payload->GetSize());
m_mac->MlmeSetRequest(MacPibAttributeIdentifier::macBeaconPayload, pibAttr);
}
Expand Down
3 changes: 2 additions & 1 deletion src/zigbee/model/zigbee-nwk.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static constexpr uint32_t ALL_CHANNELS = 0x07FFF800; //!< Bitmap representing al
*
* Indicates a pending NWK primitive
*/
enum PendingPrimitiveNwk
enum PendingPrimitiveNwk : std::uint8_t
{
NLDE_NLME_NONE = 0, //!< No pending primitive
NLME_NETWORK_FORMATION = 1, //!< Pending NLME-NETWORK-FORMATION.request primitive
Expand Down Expand Up @@ -1046,6 +1046,7 @@ class ZigbeeNwk : public Object
protected:
void DoInitialize() override;
void DoDispose() override;
void NotifyConstructionCompleted() override;

private:
Ptr<lrwpan::LrWpanMacBase> m_mac; //!< Pointer to the underlying MAC
Expand Down

0 comments on commit 1f208a0

Please sign in to comment.