From 69dd55744f4040213b5db97b5a782b1b3cc2a27b Mon Sep 17 00:00:00 2001 From: Alberto Gallegos Ramonet Date: Thu, 24 Jul 2025 12:10:25 +0900 Subject: [PATCH] zigbee: Add multicast related setters and getters to headers --- src/zigbee/model/zigbee-aps-header.cc | 12 +++++ src/zigbee/model/zigbee-aps-header.h | 14 ++++++ src/zigbee/model/zigbee-nwk-header.cc | 50 ++++++++++++++++--- src/zigbee/model/zigbee-nwk-header.h | 44 +++++++++++++++- src/zigbee/model/zigbee-nwk-payload-header.cc | 12 +++++ src/zigbee/model/zigbee-nwk-payload-header.h | 37 ++++++++++++-- 6 files changed, 157 insertions(+), 12 deletions(-) diff --git a/src/zigbee/model/zigbee-aps-header.cc b/src/zigbee/model/zigbee-aps-header.cc index 562af9aba..1d1305710 100644 --- a/src/zigbee/model/zigbee-aps-header.cc +++ b/src/zigbee/model/zigbee-aps-header.cc @@ -102,6 +102,18 @@ ZigbeeApsHeader::GetDstEndpoint() const return m_dstEndpoint; } +void +ZigbeeApsHeader::SetGroupAddress(uint16_t groupAddress) +{ + m_groupAddress = groupAddress; +} + +uint16_t +ZigbeeApsHeader::GetGroupAddress() const +{ + return m_groupAddress; +} + void ZigbeeApsHeader::SetClusterId(uint16_t clusterId) { diff --git a/src/zigbee/model/zigbee-aps-header.h b/src/zigbee/model/zigbee-aps-header.h index b06ba0b42..75c8ca168 100644 --- a/src/zigbee/model/zigbee-aps-header.h +++ b/src/zigbee/model/zigbee-aps-header.h @@ -171,6 +171,20 @@ class ZigbeeApsHeader : public Header */ uint8_t GetDstEndpoint() const; + /** + * Set the group address in the APS header. + * + * @param groupAddress The group address to set. + */ + void SetGroupAddress(uint16_t groupAddress); + + /** + * Get the group address in the APS header. + * + * @return The group address. + */ + uint16_t GetGroupAddress() const; + /** * Set the cluster id in the APS header. * diff --git a/src/zigbee/model/zigbee-nwk-header.cc b/src/zigbee/model/zigbee-nwk-header.cc index 2027b5b8c..a19677ee6 100644 --- a/src/zigbee/model/zigbee-nwk-header.cc +++ b/src/zigbee/model/zigbee-nwk-header.cc @@ -174,6 +174,42 @@ ZigbeeNwkHeader::GetSrcIeeeAddr() const return (m_srcIeeeAddr); } +void +ZigbeeNwkHeader::SetMulticastMode(MulticastMode mode) +{ + m_mcstMode = mode; +} + +MulticastMode +ZigbeeNwkHeader::GetMulticastMode() const +{ + return m_mcstMode; +} + +void +ZigbeeNwkHeader::SetNonMemberRadius(uint8_t radius) +{ + m_nonMemberRadius = radius; +} + +uint8_t +ZigbeeNwkHeader::GetNonMemberRadius() const +{ + return m_nonMemberRadius; +} + +void +ZigbeeNwkHeader::SetMaxNonMemberRadius(uint8_t radius) +{ + m_maxNonMemberRadius = radius; +} + +uint8_t +ZigbeeNwkHeader::GetMaxNonMemberRadius() const +{ + return m_maxNonMemberRadius; +} + void ZigbeeNwkHeader::SetFrameControl(uint16_t frameControl) { @@ -217,13 +253,13 @@ ZigbeeNwkHeader::SetMulticastControl(uint8_t multicastControl) uint8_t ZigbeeNwkHeader::GetMulticastControl() const { - uint8_t val = 0; + uint8_t mcstCtrl = 0; - val = m_mcstMode & (0x03); // Bit 0-1 - val |= (m_nonMemberRadius << 2) & (0x07 << 2); // Bit 2-4 - val |= (m_maxNonMemberRadius << 5) & (0x07 << 5); // Bit 5-7 + mcstCtrl = m_mcstMode & (0x03); // Bit 0-1 + mcstCtrl |= (m_nonMemberRadius << 2) & (0x07 << 2); // Bit 2-4 + mcstCtrl |= (m_maxNonMemberRadius << 5) & (0x07 << 5); // Bit 5-7 - return val; + return mcstCtrl; } void @@ -280,8 +316,8 @@ ZigbeeNwkHeader::Deserialize(Buffer::Iterator start) if (m_fctrlMcst) { - uint8_t multicastControl = i.ReadU8(); - SetMulticastControl(multicastControl); + uint8_t mcstCtrl = i.ReadU8(); + SetMulticastControl(mcstCtrl); } // TODO: Add Source route subframe when supported diff --git a/src/zigbee/model/zigbee-nwk-header.h b/src/zigbee/model/zigbee-nwk-header.h index 177cc8da7..83ea8c99b 100644 --- a/src/zigbee/model/zigbee-nwk-header.h +++ b/src/zigbee/model/zigbee-nwk-header.h @@ -199,6 +199,48 @@ class ZigbeeNwkHeader : public Header */ Mac64Address GetSrcIeeeAddr() const; + /** + * Set the multicast mode + * + * @param mode The multicast mode (member or non-member) + */ + void SetMulticastMode(MulticastMode mode); + + /** + * Get the multicast mode + * + * @return The multicast mode (member or non-member) + */ + MulticastMode GetMulticastMode() const; + + /** + * Set the non-member radius + * + * @param radius The non-member radius (0-7) + */ + void SetNonMemberRadius(uint8_t radius); + + /** + * Get the non-member radius + * + * @return The non-member radius (0-7) + */ + uint8_t GetNonMemberRadius() const; + + /** + * Set the maximum non-member radius + * + * @param radius The maximum non-member radius (0-7) + */ + void SetMaxNonMemberRadius(uint8_t radius); + + /** + * Get the maximum non-member radius + * + * @return The maximum non-member radius (0-7) + */ + uint8_t GetMaxNonMemberRadius() const; + void Serialize(Buffer::Iterator start) const override; uint32_t Deserialize(Buffer::Iterator start) override; uint32_t GetSerializedSize() const override; @@ -223,7 +265,7 @@ class ZigbeeNwkHeader : public Header */ uint16_t GetFrameControl() const; /** - * Set the Multicast control field + * Set the Multicast control field (mcstMode, nonMemberRadius, maxNonMemberRadius) * @param multicastControl 8 bits representing the multicast control field */ void SetMulticastControl(uint8_t multicastControl); diff --git a/src/zigbee/model/zigbee-nwk-payload-header.cc b/src/zigbee/model/zigbee-nwk-payload-header.cc index e920c1f56..09442c516 100644 --- a/src/zigbee/model/zigbee-nwk-payload-header.cc +++ b/src/zigbee/model/zigbee-nwk-payload-header.cc @@ -300,6 +300,18 @@ ZigbeePayloadRouteRequestCommand::GetDstIeeeAddr() const return (m_dstIeeeAddr); } +void +ZigbeePayloadRouteRequestCommand::SetMulticastField(bool mcst) +{ + m_cmdOptMcst = mcst; +} + +bool +ZigbeePayloadRouteRequestCommand::GetMulticastField() const +{ + return m_cmdOptMcst; +} + void ZigbeePayloadRouteRequestCommand::SetCmdOptionField(uint8_t cmdOptionField) { diff --git a/src/zigbee/model/zigbee-nwk-payload-header.h b/src/zigbee/model/zigbee-nwk-payload-header.h index 0032b8946..21acdd834 100644 --- a/src/zigbee/model/zigbee-nwk-payload-header.h +++ b/src/zigbee/model/zigbee-nwk-payload-header.h @@ -77,11 +77,14 @@ class ZigbeePayloadType : public Header /** * Set the command frame type + * * @param nwkCmd the command frame type */ void SetCmdType(enum NwkCommandType nwkCmd); + /** * Get the command frame type + * * @return The command type from the command payload header */ NwkCommandType GetCmdType() const; @@ -93,7 +96,8 @@ class ZigbeePayloadType : public Header /** * @ingroup zigbee * Represent a variable portion of the zigbee payload header that includes - * the route request command + * the route request command. + * See Zigbee specification r22.1.0, Section 3.4.1 */ class ZigbeePayloadRouteRequestCommand : public Header { @@ -126,36 +130,42 @@ class ZigbeePayloadRouteRequestCommand : public Header /** * Set the Route request identifier + * * @param id the route request identifier */ void SetRouteReqId(uint8_t id); /** * Get the Route request identifier + * * @return the route request identifier */ uint8_t GetRouteReqId() const; /** * Set Destination address + * * @param addr The destination address (16 bit) */ void SetDstAddr(Mac16Address addr); /** * Get the Destination address + * * @return the Destination address (16bits) */ Mac16Address GetDstAddr() const; /** * Set the path cost + * * @param cost the path cost */ void SetPathCost(uint8_t cost); /** * Set the path cost + * * @return the path cost */ uint8_t GetPathCost() const; @@ -168,17 +178,35 @@ class ZigbeePayloadRouteRequestCommand : public Header bool IsDstIeeeAddressPresent() const; /** - * Set the destination IEEE address + * Set the destination IEEE address, also automatically + * sets the command option DstIeeeAddr field + * * @param dst The destination IEEE address (64 bits) */ void SetDstIeeeAddr(Mac64Address dst); /** - * Get the destination IEEE address + * Get the destination IEEE address (64-bit) contained in the + * route request command. + * * @return The destination IEEE address (64bits) */ Mac64Address GetDstIeeeAddr() const; + /** + * Set the command option multicast field + * + * @param mcst True if the command option multicast field is active + */ + void SetMulticastField(bool mcst); + + /** + * Get the command option multicast field + * + * @return True if the command option multicast field is active + */ + bool GetMulticastField() const; + private: /** * Set the complete command option field of the route request command. @@ -208,7 +236,8 @@ class ZigbeePayloadRouteRequestCommand : public Header /** * @ingroup zigbee * Represent a variable portion of the zigbee payload header that includes - * the route reply command + * the route reply command. + * See Zigbee specification r22.1.0, Section 3.4.2 */ class ZigbeePayloadRouteReplyCommand : public Header {