diff --git a/src/lr-wpan/model/lr-wpan-capability-information.cc b/src/lr-wpan/model/lr-wpan-capability-information.cc new file mode 100644 --- /dev/null +++ b/src/lr-wpan/model/lr-wpan-capability-information.cc @@ -0,0 +1,201 @@ + +#include "lr-wpan-capability-information.h" + +namespace ns3 { + +//NS_OBJECT_ENSURE_REGISTERED (LrWpanCapabilityInformation); + + +LrWpanCapabilityInformation::LrWpanCapabilityInformation () +{ + SetNoAltrPanCoord (); // Assume the device can't become a PAN coordinator + SetNoFfdDevType (); // Assume the Device is RFD + SetNoPwrSrc (); // Assume the device don't receive power from the alternating current mains + SetRcvOnWhenIdleDisable (); // Assume the receiver is disable during idle periods + SetCapRes (0); // Initialize the 2reserved bits to 0 + SetNoSecCap (); // Assume the device isn't capable of sending or receiving protected MAC frames + SetNoAllocAddr (); // Allocate a 64-bit extended address + +}; + +LrWpanCapabilityInformation::~LrWpanCapabilityInformation () +{ +} + + +uint16_t LrWpanCapabilityInformation::GetCapability (void) const +{ + uint16_t val; + val = m_capInfAltPanCoord & 0x01; // Bit 0 + val |= (m_capInfDevType << 1) & (0x01 << 1); // Bit 1 + val |= (m_capInfPwrSrc<< 2) & (0x01 << 2); // Bit 2 + val |= (m_capInfRcvOnWhenIdle << 3) & (0x01 << 3); // Bit 3 + val |= (m_capInfReserved << 4) & (0x03 << 3); // Bit 4-5 + val |= (m_capInfSecCap << 6) & (0x01 << 6); // Bit 6 + val |= (m_capInfAllocAddr << 7) & (0x01 << 7); // Bit 7 + return val; +} + +bool +LrWpanCapabilityInformation::IsAltrPanCoord (void) const +{ + return (m_capInfAltPanCoord == 1); +} + +bool +LrWpanCapabilityInformation::IsNoAltrPanCoord (void) const +{ + return (m_capInfAltPanCoord == 0); +} + +bool +LrWpanCapabilityInformation::IsFfdDevType (void) const +{ + return (m_capInfDevType == 1); +} + +bool +LrWpanCapabilityInformation::IsNoFfdDevType (void) const +{ + return (m_capInfDevType == 0); +} + +bool +LrWpanCapabilityInformation::IsPwrSrc (void) const +{ + return (m_capInfPwrSrc == 1); +} + +bool +LrWpanCapabilityInformation::IsNoPwrSrc (void) const +{ + return (m_capInfPwrSrc == 0); +} + +bool +LrWpanCapabilityInformation::IsRcvOnWhenIdleEnable (void) const +{ + return (m_capInfRcvOnWhenIdle == 1); +} + +bool +LrWpanCapabilityInformation::IsRcvOnWhenIdleDisable (void) const +{ + return (m_capInfRcvOnWhenIdle == 0); +} + +bool +LrWpanCapabilityInformation::IsSecCap (void) const +{ + return (m_capInfSecCap == 1); +} + +bool +LrWpanCapabilityInformation::IsNoSecCap (void) const +{ + return (m_capInfSecCap == 0); +} + +bool +LrWpanCapabilityInformation::IsAllocAddr (void) const +{ + return (m_capInfAllocAddr == 1); +} + +bool +LrWpanCapabilityInformation::IsNoAllocAddr (void) const +{ + return (m_capInfAllocAddr == 0); +} + +void +LrWpanCapabilityInformation::SetCapability (uint16_t Capability) +{ + m_capInfAltPanCoord = Capability & 0x01; // Bit 0 + m_capInfDevType |= (Capability >> 1) & (0x01); // Bit 1 + m_capInfPwrSrc |= (Capability >> 2) & (0x01); // Bit 2 + m_capInfRcvOnWhenIdle |= (Capability >> 3) & (0x01); // Bit 3 + m_capInfReserved |= (Capability >> 4) & (0x03); // Bit 4-5 + m_capInfSecCap |= (Capability >> 6) & (0x01); // Bit 6 + m_capInfAllocAddr |= (Capability >> 7) & (0x01); // Bit 7 +} + +void +LrWpanCapabilityInformation::SetAltrPanCoord (void) +{ + m_capInfAltPanCoord = 1; +} + +void +LrWpanCapabilityInformation::SetNoAltrPanCoord (void) +{ + m_capInfAltPanCoord = 0; +} + +void +LrWpanCapabilityInformation::SetFfdDevType (void) +{ + m_capInfDevType = 1; +} + +void +LrWpanCapabilityInformation::SetNoFfdDevType (void) +{ + m_capInfDevType = 0; +} + +void +LrWpanCapabilityInformation::SetPwrSrc (void) +{ + m_capInfPwrSrc = 1; +} + +void +LrWpanCapabilityInformation::SetNoPwrSrc (void) +{ + m_capInfPwrSrc = 0; +} + +void +LrWpanCapabilityInformation::SetRcvOnWhenIdleEnable (void) +{ + m_capInfRcvOnWhenIdle = 1; +} + +void +LrWpanCapabilityInformation::SetRcvOnWhenIdleDisable (void) +{ + m_capInfRcvOnWhenIdle = 0; +} + +void +LrWpanCapabilityInformation::SetCapRes (uint8_t res) +{ + m_capInfReserved = res; +} + +void +LrWpanCapabilityInformation::SetSecCap (void) +{ + m_capInfSecCap = 1; +} + +void +LrWpanCapabilityInformation::SetNoSecCap (void) +{ + m_capInfSecCap = 0; +} + +void +LrWpanCapabilityInformation::SetAllocAddr (void) +{ + m_capInfAllocAddr = 1; +} + +void +LrWpanCapabilityInformation::SetNoAllocAddr (void) +{ + m_capInfAllocAddr = 0; +} + +} // namespace ns3 diff --git a/src/lr-wpan/model/lr-wpan-capability-information.h b/src/lr-wpan/model/lr-wpan-capability-information.h new file mode 100644 --- /dev/null +++ b/src/lr-wpan/model/lr-wpan-capability-information.h @@ -0,0 +1,70 @@ +#ifndef LR_WPAN_CAPABILITY_INFORMATION_H +#define LR_WPAN_CAPABILITY_INFORMATION_H + +#include +#include + +namespace ns3 { + +class Packet; + +/* + * \ingroup lr-wpan + * Represent the Capability Information + */ +class LrWpanCapabilityInformation +{ +public: + + LrWpanCapabilityInformation (void); + ~LrWpanCapabilityInformation (void); + + uint16_t GetCapability(void) const; + bool IsAltrPanCoord (void) const; + bool IsNoAltrPanCoord (void) const; + bool IsFfdDevType (void) const; + bool IsNoFfdDevType (void) const; + bool IsPwrSrc (void) const; + bool IsNoPwrSrc (void) const; + bool IsRcvOnWhenIdleEnable (void) const; + bool IsRcvOnWhenIdleDisable (void) const; + bool IsSecCap (void) const; + bool IsNoSecCap (void) const; + bool IsAllocAddr (void) const; + bool IsNoAllocAddr (void) const; + + void SetCapability (uint16_t Capability); + void SetAltrPanCoord (void); + void SetNoAltrPanCoord (void); + void SetFfdDevType (void); + void SetNoFfdDevType (void); + void SetPwrSrc (void); + void SetNoPwrSrc (void); + void SetRcvOnWhenIdleEnable (void); + void SetRcvOnWhenIdleDisable (void); + void SetCapRes (uint8_t res); + void SetSecCap (void); + void SetNoSecCap (void); + void SetAllocAddr (void); + void SetNoAllocAddr (void); + + std::string GetName(void) const; + void PrintCapabilityInformation (std::ostream &os) const; + void Print (std::ostream &os) const; + //void Serialize (Buffer::Iterator start) const; + //uint32_t Deserialize (Buffer::Iterator start); + +private: + /* Capability Information 1 Octet */ + /* Capability Information fields */ + uint8_t m_capInfAltPanCoord; // Bit 0 = 0 - Not capable of becoming the PAN coordinator, 1 - Capable of becoming the PAN coordinator + uint8_t m_capInfDevType; // Bit 1 = 0 - RFD Device, 1 - FFD Device + uint8_t m_capInfPwrSrc; // Bit 2 = 0 - No receiving power from the alternating current mains, 1- receiving power from the alternating current mains + uint8_t m_capInfRcvOnWhenIdle; // Bit 3 = 0 - Disable receiver during idle periods, 1 - Enable receiver during idle periods + uint8_t m_capInfReserved; // Bit 4-5 + uint8_t m_capInfSecCap; // Bit 6 = 0 - No sending and receiving cryptographically protected MAC frames, 1 - Can sending and receiving cryptographically protected MAC frames + uint8_t m_capInfAllocAddr; // Bit 7 = 0 - No 16-bit short address, 1 - 16-bit short address + +}; // LrWpanCapabilityInformation +}; // namespace ns-3 +#endif /* LR_WPAN_CAPABILITY_INFORMATION_H */ diff --git a/src/lr-wpan/model/lr-wpan-mac.cc b/src/lr-wpan/model/lr-wpan-mac.cc --- a/src/lr-wpan/model/lr-wpan-mac.cc +++ b/src/lr-wpan/model/lr-wpan-mac.cc @@ -26,6 +26,7 @@ #include "lr-wpan-csmaca.h" #include "lr-wpan-mac-header.h" #include "lr-wpan-mac-trailer.h" +#include "lr-wpan-capability-information.h" #include #include #include @@ -203,6 +204,82 @@ NS_LOG_FUNCTION (this); return m_selfExt; } + +void +LrWpanMac::MlmeAssociateRequest (MlmeAssociateRequestParams params, Ptr p) +{ + NS_LOG_FUNCTION (this << p); + + //Create a MAC Header + //Type: Command Frame + LrWpanMacHeader macHdr (LrWpanMacHeader::LRWPAN_MAC_COMMAND, (uint8_t)m_macDsn.GetValue ()); + + //Create a Capability Information Header + LrWpanCapabilityInformation capInf; + + m_macDsn++; + if (m_macDsn > SequenceNumber16 (255)) + { + m_macDsn = m_macDsn - SequenceNumber16 (255); + } + + if (params.m_coordAddrMode != SHORT_ADDR || params.m_coordAddrMode != EXT_ADDR) + { + NS_LOG_ERROR (this << " Invalid Address field" ); + return; + } + SetPanId(params.m_coordPanId); + //extract the last 4 bits in Capability Information Field and map to macHdr + // Section 7.3.1.2; Figure 56 + int b0 = params.m_capability & CAPABILITY_ALTERNATE_PAN_COORD; + int b1 = params.m_capability & CAPABILITY_DEVICE_TYPE; + int b2 = params.m_capability & CAPABILITY_POWER_SOURCE; + int b3 = params.m_capability & CAPABILITY_RECEIVER_ON_WHEN_IDLE; + + // TODO: The Alternate PAN Coordinator is set to 1 if the device is capable of becoming the PAN coordinator + // else the Alternate PAN Coordinator subfield shall be set to zero. + if (b0 == CAPABILITY_ALTERNATE_PAN_COORD) + { + capInf.SetAltrPanCoord(); + } + else if(b0 == 0) + { + capInf.SetNoAltrPanCoord(); + } + // TODO: The Device Type is set to 1 if the device is an FFD + // else the Device type is set be zero to indicate an RFD + if (b1 == CAPABILITY_DEVICE_TYPE) + { + capInf.SetFfdDevType(); + } + else if (b1 == 0) + { + capInf.SetNoFfdDevType(); + } + // TODO: The Power Source is set to 1 if the device is receiving power from the alternating current mains + // else the Power Source is set to zero + if (b2 == CAPABILITY_POWER_SOURCE) + { + capInf.SetPwrSrc(); + } + else if (b2 == 0) + { + capInf.SetNoPwrSrc(); + } + //TODO: The Receiver On When Idle subfield is set to 1 if the device does not disable its receiver + // to conserve power during idle periods + // else the receiver subfield is set to 0 + if (b3 == CAPABILITY_RECEIVER_ON_WHEN_IDLE) + { + capInf.SetRcvOnWhenIdleEnable(); + } + else if (b3 == 0) + { + capInf.SetRcvOnWhenIdleDisable(); + } + +} + void LrWpanMac::McpsDataRequest (McpsDataRequestParams params, Ptr p) { @@ -980,4 +1057,5 @@ m_macMaxFrameRetries = retries; } + } // namespace ns3 diff --git a/src/lr-wpan/model/lr-wpan-mac.h b/src/lr-wpan/model/lr-wpan-mac.h --- a/src/lr-wpan/model/lr-wpan-mac.h +++ b/src/lr-wpan/model/lr-wpan-mac.h @@ -104,6 +104,17 @@ IEEE_802_15_4_INVALID_PARAMETER = 11 } LrWpanMcpsDataConfirmStatus; +typedef enum +{ + CAPABILITY_ALTERNATE_PAN_COORD = 0, //alternate PAN coordinator + CAPABILITY_DEVICE_TYPE = 1, //device type (1=FFD,0=RFD) + CAPABILITY_POWER_SOURCE = 2, //power source (1=mains powered,0=non mains powered) + CAPABILITY_RECEIVER_ON_WHEN_IDLE = 3, //receiver on when idle + CAPABILITY_RESERVED = 4, //reserved + CAPABILITY_SECURITY_CAPABILITY = 6, //security capability + CAPABILITY_ALLOCATE_ADDRESS = 7 //allocate address (asking for allocation of a short address during association) +} LrWpanCapabilityInformationOption; + struct McpsDataRequestParams { McpsDataRequestParams () : @@ -118,6 +129,18 @@ uint8_t m_txOptions; // bitmap }; +struct MlmeAssociateRequestParams +{ + MlmeAssociateRequestParams () : + m_coordAddrMode (SHORT_ADDR), m_coordPanId (0),m_coordAddr (), + m_capability (0) + { }; + LrWpanAddressMode m_coordAddrMode; + uint16_t m_coordPanId; + Mac16Address m_coordAddr; + uint8_t m_capability; // bitmap +}; + struct McpsDataConfirmParams { uint8_t m_msduHandle; @@ -257,7 +280,15 @@ */ void PlmeSetAttributeConfirm (LrWpanPhyEnumeration status, LrWpanPibAttributeIdentifier id); - + /** + * Added By Abdelwahed + * IEEE 802.15.4-2006 section 7.1.3.1 + * PLME-GET.confirm + * MLME-ASSOCIATE.request + * Set attributes per definition from Table 47 in section 7.1.3.1.1 + * @param p the packet to send + */ + void MlmeAssociateRequest (MlmeAssociateRequestParams params, Ptr p); /** * CSMA-CA algorithm calls back the MAC after executing channel assessment @@ -293,6 +324,7 @@ uint8_t GetMacMaxFrameRetries (void) const; void SetMacMaxFrameRetries (uint8_t retries); + protected: virtual void DoInitialize (void); virtual void DoDispose (void); diff --git a/src/lr-wpan/wscript b/src/lr-wpan/wscript --- a/src/lr-wpan/wscript +++ b/src/lr-wpan/wscript @@ -13,6 +13,7 @@ 'model/lr-wpan-spectrum-value-helper.cc', 'model/lr-wpan-spectrum-signal-parameters.cc', 'model/lr-wpan-lqi-tag.cc', + 'model/lr-wpan-capability-information.cc', 'helper/lr-wpan-helper.cc', ] @@ -37,6 +38,7 @@ 'model/lr-wpan-spectrum-value-helper.h', 'model/lr-wpan-spectrum-signal-parameters.h', 'model/lr-wpan-lqi-tag.h', + 'model/lr-wpan-capability-information.h', 'helper/lr-wpan-helper.h', ]