From e38be2fe4f4bf839b055afc85ca1ce4cb0ca8f70 Mon Sep 17 00:00:00 2001 From: Alberto Gallegos Date: Fri, 12 May 2023 10:58:53 +0900 Subject: [PATCH] lr-wpan: small fixes in MAC orphan scan --- CHANGES.md | 3 ++ RELEASE_NOTES.md | 1 + src/lr-wpan/model/lr-wpan-mac.cc | 67 ++++++++++++++++++++++---------- src/lr-wpan/model/lr-wpan-mac.h | 5 +++ 4 files changed, 56 insertions(+), 20 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 8d70e2036..2f2b2e8e0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -57,6 +57,9 @@ Changes from ns-3.38 to ns-3-dev * (olsr) The defines `OLSR_WILL_*` have been replaced by enum `Willingness`. * (wifi) The `WifiCodeRate` typedef was converted to an enum. * (internet) `InternetStackHelper` can be now used on nodes with an `InternetStack` already installed (it will not install IPv[4,6] twice). +* (lr-wpan) Block the reception of orphan notification commands to devices other than PAN coordinators or coordinators. +* (lr-wpan) Block the reception of broadcast messages in the same device that issues it. This is done in both cases when the src address is either short or extended address. +* (lr-wpan) Adds a new variable flag `m_coor` to the MAC to differentiate between coordinators and PAN coordinators. ### Changes to build system diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index fb1afdc33..2f2dfff15 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -38,6 +38,7 @@ Release 3-dev - (wifi) UL MU CS shall be evaluated a SIFS after end of MU-RTS - (wifi) Fix crash when changing operating channel after configuration but before initialization - (wifi) Fix assert when non-HE STAs receive CTS frames sent using non-HT duplicate following a MU-RTS frame +- (lr-wpan) !1481 Small fixes in MAC orphan scan Release 3.38 ------------ diff --git a/src/lr-wpan/model/lr-wpan-mac.cc b/src/lr-wpan/model/lr-wpan-mac.cc index 7fb4fd334..94cd8d45a 100644 --- a/src/lr-wpan/model/lr-wpan-mac.cc +++ b/src/lr-wpan/model/lr-wpan-mac.cc @@ -189,6 +189,7 @@ LrWpanMac::LrWpanMac() m_macSIFSPeriod = 12; m_panCoor = false; + m_coor = false; m_macBeaconOrder = 15; m_macSuperframeOrder = 15; m_macTransactionPersistenceTime = 500; // 0x01F5 @@ -498,9 +499,8 @@ LrWpanMac::McpsDataRequest(McpsDataRequestParams params, Ptr p) // A DEVICE must be tracking beacons (MLME-SYNC.request is running) before attempting // request data from the coordinator. - // TODO: Check if the current device is coordinator (not just pan coordinator) // Indirect Transmission can only be done by PAN coordinator or coordinators. - NS_ASSERT(m_panCoor); + NS_ASSERT(m_coor); p->AddHeader(macHdr); LrWpanMacTrailer macTrailer; @@ -1294,9 +1294,11 @@ LrWpanMac::EndStartRequest() if (m_startParams.m_panCoor) { m_panCoor = true; - m_macPanId = m_startParams.m_PanId; } + m_coor = true; + m_macPanId = m_startParams.m_PanId; + NS_ASSERT(m_startParams.m_PanId != 0xffff); m_macBeaconOrder = m_startParams.m_bcnOrd; @@ -1692,9 +1694,7 @@ LrWpanMac::CheckQueue() // Pull a packet from the queue and start sending if we are not already sending. if (m_lrWpanMacState == MAC_IDLE && !m_txQueue.empty() && !m_setMacState.IsRunning()) { - // TODO: this should check if the node is a coordinator and using the outcoming superframe - // not just the PAN coordinator - if (m_csmaCa->IsUnSlottedCsmaCa() || (m_outSuperframeStatus == CAP && m_panCoor) || + if (m_csmaCa->IsUnSlottedCsmaCa() || (m_outSuperframeStatus == CAP && m_coor) || m_incSuperframeStatus == CAP) { // check MAC is not in a IFS @@ -1963,11 +1963,11 @@ LrWpanMac::PdDataIndication(uint32_t psduLength, Ptr p, uint8_t lqi) if (acceptFrame && (receivedMacHdr.GetDstAddrMode() > 1)) { - // Accept frame if: + // Accept frame if one of the following is true: // 1) Have the same macPanId - // 2) Or is Message to all PANs - // 3) Or Is a beacon and the macPanId is not present (bootstrap) + // 2) Is Message to all PANs + // 3) Is a beacon or command frame and the macPanId is not present (bootstrap) acceptFrame = ((receivedMacHdr.GetDstPanId() == m_macPanId || receivedMacHdr.GetDstPanId() == 0xffff) || (m_macPanId == 0xffff && receivedMacHdr.IsBeacon())) || @@ -1976,10 +1976,17 @@ LrWpanMac::PdDataIndication(uint32_t psduLength, Ptr p, uint8_t lqi) if (acceptFrame && (receivedMacHdr.GetShortDstAddr() == Mac16Address("FF:FF"))) { - // A broadcast message (e.g. beacons) should not be received by the device who - // issues it. - acceptFrame = (receivedMacHdr.GetShortSrcAddr() != GetShortAddress()); // TODO: shouldn't this be filtered by the PHY? + // A broadcast message (e.g. beacons, orphan notifications) should not be received + // by the device who issues it. + if (receivedMacHdr.GetSrcAddrMode() == EXT_ADDR) + { + acceptFrame = (receivedMacHdr.GetExtSrcAddr() != GetExtendedAddress()); + } + else + { + acceptFrame = (receivedMacHdr.GetShortSrcAddr() != GetShortAddress()); + } } if (acceptFrame && (receivedMacHdr.GetDstAddrMode() == SHORT_ADDR)) @@ -2038,7 +2045,7 @@ LrWpanMac::PdDataIndication(uint32_t psduLength, Ptr p, uint8_t lqi) if (receivedMacPayload.GetCommandFrameType() == CommandPayloadHeader::ASSOCIATION_REQ && - !(m_macAssociationPermit && m_panCoor)) + !(m_macAssociationPermit && m_coor)) { acceptFrame = false; } @@ -2348,8 +2355,7 @@ LrWpanMac::PdDataIndication(uint32_t psduLength, Ptr p, uint8_t lqi) switch (receivedMacPayload.GetCommandFrameType()) { case CommandPayloadHeader::BEACON_REQ: - // TODO: check that node is any coordinator not just pan coordinator - if (m_csmaCa->IsUnSlottedCsmaCa() && m_panCoor) + if (m_csmaCa->IsUnSlottedCsmaCa() && m_coor) { SendOneBeacon(); } @@ -2361,9 +2367,12 @@ LrWpanMac::PdDataIndication(uint32_t psduLength, Ptr p, uint8_t lqi) case CommandPayloadHeader::ORPHAN_NOTIF: if (!m_mlmeOrphanIndicationCallback.IsNull()) { - MlmeOrphanIndicationParams orphanParams; - orphanParams.m_orphanAddr = receivedMacHdr.GetExtSrcAddr(); - m_mlmeOrphanIndicationCallback(orphanParams); + if (m_coor) + { + MlmeOrphanIndicationParams orphanParams; + orphanParams.m_orphanAddr = receivedMacHdr.GetExtSrcAddr(); + m_mlmeOrphanIndicationCallback(orphanParams); + } } break; case CommandPayloadHeader::COOR_REALIGN: @@ -2498,6 +2507,24 @@ LrWpanMac::PdDataIndication(uint32_t psduLength, Ptr p, uint8_t lqi) break; } + case CommandPayloadHeader::COOR_REALIGN: { + // ACK of coordinator realigment commands is not specified in the + // standard, in here, we assume they are required as in other + // commands. + if (!m_mlmeCommStatusIndicationCallback.IsNull()) + { + MlmeCommStatusIndicationParams commStatusParams; + commStatusParams.m_panId = m_macPanId; + commStatusParams.m_srcAddrMode = LrWpanMacHeader::EXTADDR; + commStatusParams.m_srcExtAddr = macHdr.GetExtSrcAddr(); + commStatusParams.m_dstAddrMode = LrWpanMacHeader::EXTADDR; + commStatusParams.m_dstExtAddr = macHdr.GetExtDstAddr(); + commStatusParams.m_status = + LrWpanMlmeCommStatus::MLMECOMMSTATUS_SUCCESS; + m_mlmeCommStatusIndicationCallback(commStatusParams); + } + } + default: { // TODO: add response to other request commands (e.g. Orphan) break; @@ -3844,9 +3871,9 @@ LrWpanMac::isCoordDest() LrWpanMacHeader macHdr; m_txPkt->PeekHeader(macHdr); - if (m_panCoor) + if (m_coor) { - // The device is the PAN coordinator and the packet is not to itself + // The device is its coordinator and the packet is not to itself return false; } else if (m_macCoordShortAddress == macHdr.GetShortDstAddr() || diff --git a/src/lr-wpan/model/lr-wpan-mac.h b/src/lr-wpan/model/lr-wpan-mac.h index 9becb4380..02022f19e 100644 --- a/src/lr-wpan/model/lr-wpan-mac.h +++ b/src/lr-wpan/model/lr-wpan-mac.h @@ -1468,6 +1468,11 @@ class LrWpanMac : public Object */ bool m_panCoor; + /** + * Indicates if the current device is a coordinator type + */ + bool m_coor; + /** * Indication of the Interval used by the coordinator to transmit beacon frames * expressed in symbols.