* ========================================================================
*/
-/* This component maintains the PIB (PAN Information Base) attributes and
- * provides interfaces for accessing fields in a MAC frame. */
+/**
+ * This component maintains the PIB (PAN Information Base) attributes and
+ * provides interfaces for accessing fields in a MAC frame.
+ */
#include "TKN154.h"
#include "TKN154_PIB.h"
interface Set<ieee154_macSuperframeOrder_t> as SetMacSuperframeOrder;
interface Set<ieee154_macBeaconTxTime_t> as SetMacBeaconTxTime;
interface Set<ieee154_macPanCoordinator_t> as SetMacPanCoordinator;
- interface Get<ieee154_macPanCoordinator_t> as IsMacPanCoordinator;
- interface Get<bool> as IsBeaconEnabledPAN;
interface FrameUtility;
interface IEEE154Frame as Frame;
interface IEEE154BeaconFrame as BeaconFrame;
interface Get<uint64_t> as GetLocalExtendedAddress;
+ interface GetNow<token_requested_t> as IsRadioTokenRequested;
interface Notify<const void*> as PIBUpdate[uint8_t PIBAttributeID];
interface Packet;
interface TimeCalc;
uses
{
interface Get<bool> as PromiscuousModeGet;
- interface Init as CapReset;
- interface Init as CapQueueReset;
+ interface Init as DispatchReset;
+ interface Init as DispatchQueueReset;
interface Init as MacReset;
interface SplitControl as RadioControl;
interface Random;
- interface Resource as Token;
+ interface TransferableResource as RadioToken;
interface RadioOff;
interface LocalTime<TSymbolIEEE802154>;
}
ieee154_PIB_t m_pib;
uint8_t m_numResetClientPending;
bool m_setDefaultPIB;
- uint8_t m_panType;
- uint8_t m_resetSpin;
+ norace uint8_t m_resetSpin;
#ifdef IEEE154_EXTENDED_ADDRESS
const uint64_t m_aExtendedAddressLE = IEEE154_EXTENDED_ADDRESS;
command error_t LocalInit.init()
{
#ifndef IEEE154_EXTENDED_ADDRESS
- uint32_t *p = (uint32_t*) &m_aExtendedAddressLE;
- *p++ = call Random.rand32();
- *p = call Random.rand32();
+ m_aExtendedAddressLE = (((uint64_t) call Random.rand32() ) << 32 ) | call Random.rand32();
#endif
resetAttributesToDefault();
return SUCCESS;
m_pib.macAssociationPermit = IEEE154_DEFAULT_ASSOCIATIONPERMIT;
m_pib.macAutoRequest = IEEE154_DEFAULT_AUTOREQUEST;
m_pib.macBattLifeExt = IEEE154_DEFAULT_BATTLIFEEXT;
+ m_pib.macBattLifeExtPeriods = IEEE154_DEFAULT_BATTLIFEEXTPERIODS;
m_pib.macBeaconPayloadLength = IEEE154_DEFAULT_BEACONPAYLOADLENGTH;
m_pib.macBeaconOrder = IEEE154_DEFAULT_BEACONORDER;
m_pib.macBeaconTxTime = IEEE154_DEFAULT_BEACONTXTIME;
waitTime = (((uint16_t) 1 << macMaxBE) - 1) * (macMaxCSMABackoffs - m);
if (m) {
k = 0;
- while (k != m){
- waitTime += ((uint16_t) 1 << (macMaxBE+k));
+ while (k != m) {
+ waitTime += ((uint16_t) 1 << (macMinBE+k));
k += 1;
}
}
waitTime *= IEEE154_aUnitBackoffPeriod;
- waitTime += IEEE154_SHR_DURATION;
+ waitTime += call MLME_GET.phyMaxFrameDuration();
m_pib.macMaxFrameTotalWaitTime = waitTime;
}
- command ieee154_status_t MLME_RESET.request(bool SetDefaultPIB, uint8_t PANType)
+ command ieee154_status_t MLME_RESET.request(bool SetDefaultPIB)
{
// resetting the complete stack is not so easy...
// first we acquire the Token (get exclusive radio access), then we switch off
// Alarms!), but there can still be pending Timers/tasks -> we stop all Timers
// through MacReset.init() and then spin a few tasks in between to get
// everything "flushed out"
- if (PANType != BEACON_ENABLED_PAN && PANType != NONBEACON_ENABLED_PAN)
- return IEEE154_INVALID_PARAMETER;
+ ieee154_status_t status = IEEE154_SUCCESS;
if (call PromiscuousModeGet.get())
- return IEEE154_TRANSACTION_OVERFLOW; // must first cancel promiscuous mode!
- m_setDefaultPIB = SetDefaultPIB;
- m_panType = PANType;
- if (!call Token.isOwner())
- call Token.request();
- return IEEE154_SUCCESS;
+ status = IEEE154_TRANSACTION_OVERFLOW; // must first cancel promiscuous mode!
+ else {
+ m_setDefaultPIB = SetDefaultPIB;
+ m_resetSpin = 5;
+ call RadioToken.request();
+ }
+ dbg_serial("PibP", "MLME_RESET.request(%lu) -> result: %lu\n",
+ (uint32_t) SetDefaultPIB, (uint32_t) status);
+ return status;
}
- event void Token.granted()
+ event void RadioToken.granted()
{
- error_t error = call RadioOff.off();
- if (error != SUCCESS) // either it is already off or driver has not been started
+ if (call RadioOff.off() != SUCCESS)
signal RadioOff.offDone();
}
task void radioControlStopTask()
{
- if (call RadioControl.stop() == EALREADY)
+ error_t result = call RadioControl.stop();
+ if (result == EALREADY)
signal RadioControl.stopDone(SUCCESS);
+ else
+ ASSERT(result == SUCCESS);
}
- event void RadioControl.stopDone(error_t error)
+ event void RadioControl.stopDone(error_t result)
{
- call CapReset.init(); // resets the CAP component(s)
- call CapQueueReset.init(); // resets the CAP queue component(s)
- call MacReset.init(); // resets the remaining components
- m_resetSpin = 5;
+ ASSERT(result == SUCCESS);
+ call DispatchReset.init(); // resets the dispatch component(s), spools out frames
+ call DispatchQueueReset.init(); // resets the dispatch queue component(s), spools out frames
+ call MacReset.init(); // resets the remaining components
post resetSpinTask();
}
task void resetSpinTask()
{
- if (m_resetSpin == 2){
- // just to be safe...
- call CapReset.init();
- call CapQueueReset.init();
- call MacReset.init();
- }
- if (m_resetSpin--){
+ m_resetSpin -= 1;
+ if (m_resetSpin != 0) {
post resetSpinTask();
return;
}
- if (call RadioControl.start() == EALREADY)
- signal RadioControl.startDone(SUCCESS);
+ ASSERT(call RadioControl.start() == SUCCESS);
}
+ async command token_requested_t IsRadioTokenRequested.getNow(){ return m_resetSpin != 0; }
+
event void RadioControl.startDone(error_t error)
{
if (m_setDefaultPIB)
signal PIBUpdate.notify[IEEE154_macShortAddress](&m_pib.macShortAddress);
signal PIBUpdate.notify[IEEE154_macPanCoordinator](&m_pib.macPanCoordinator);
}
- call Token.release();
+ call RadioToken.release();
signal MLME_RESET.confirm(IEEE154_SUCCESS);
}
-/* ----------------------- MLME-GET ----------------------- */
+ /* ----------------------- MLME-GET ----------------------- */
+
+ command ieee154_phyCurrentChannel_t MLME_GET.phyCurrentChannel() { return m_pib.phyCurrentChannel;}
- command ieee154_phyCurrentChannel_t MLME_GET.phyCurrentChannel(){ return m_pib.phyCurrentChannel;}
+ command ieee154_phyChannelsSupported_t MLME_GET.phyChannelsSupported() { return IEEE154_SUPPORTED_CHANNELS;}
- command ieee154_phyChannelsSupported_t MLME_GET.phyChannelsSupported(){ return IEEE154_SUPPORTED_CHANNELS;}
+ command ieee154_phyTransmitPower_t MLME_GET.phyTransmitPower() { return m_pib.phyTransmitPower;}
- command ieee154_phyTransmitPower_t MLME_GET.phyTransmitPower(){ return m_pib.phyTransmitPower;}
+ command ieee154_phyCCAMode_t MLME_GET.phyCCAMode() { return m_pib.phyCCAMode;}
- command ieee154_phyCCAMode_t MLME_GET.phyCCAMode(){ return m_pib.phyCCAMode;}
+ command ieee154_phyCurrentPage_t MLME_GET.phyCurrentPage() { return m_pib.phyCurrentPage;}
- command ieee154_phyCurrentPage_t MLME_GET.phyCurrentPage(){ return m_pib.phyCurrentPage;}
+ command ieee154_phyMaxFrameDuration_t MLME_GET.phyMaxFrameDuration() { return IEEE154_MAX_FRAME_DURATION;}
- command ieee154_phyMaxFrameDuration_t MLME_GET.phyMaxFrameDuration(){ return IEEE154_MAX_FRAME_DURATION;}
+ command ieee154_phySHRDuration_t MLME_GET.phySHRDuration() { return IEEE154_SHR_DURATION;}
- command ieee154_phySHRDuration_t MLME_GET.phySHRDuration(){ return IEEE154_SHR_DURATION;}
+ command ieee154_phySymbolsPerOctet_t MLME_GET.phySymbolsPerOctet() { return IEEE154_SYMBOLS_PER_OCTET;}
- command ieee154_phySymbolsPerOctet_t MLME_GET.phySymbolsPerOctet(){ return IEEE154_SYMBOLS_PER_OCTET;}
+ command ieee154_macAckWaitDuration_t MLME_GET.macAckWaitDuration() { return IEEE154_ACK_WAIT_DURATION;}
- command ieee154_macAckWaitDuration_t MLME_GET.macAckWaitDuration(){ return IEEE154_ACK_WAIT_DURATION;}
+ command ieee154_macAssociationPermit_t MLME_GET.macAssociationPermit() { return m_pib.macAssociationPermit;}
- command ieee154_macAssociationPermit_t MLME_GET.macAssociationPermit(){ return m_pib.macAssociationPermit;}
+ command ieee154_macAutoRequest_t MLME_GET.macAutoRequest() { return m_pib.macAutoRequest;}
- command ieee154_macAutoRequest_t MLME_GET.macAutoRequest(){ return m_pib.macAutoRequest;}
+ command ieee154_macBattLifeExt_t MLME_GET.macBattLifeExt() { return m_pib.macBattLifeExt;}
- command ieee154_macBattLifeExt_t MLME_GET.macBattLifeExt(){ return m_pib.macBattLifeExt;}
+ command ieee154_macBattLifeExtPeriods_t MLME_GET.macBattLifeExtPeriods() { return m_pib.macBattLifeExtPeriods;}
- command ieee154_macBattLifeExtPeriods_t MLME_GET.macBattLifeExtPeriods(){ return IEEE154_BATT_LIFE_EXT_PERIODS;}
+ command ieee154_macBeaconOrder_t MLME_GET.macBeaconOrder() { return m_pib.macBeaconOrder;}
- command ieee154_macBeaconOrder_t MLME_GET.macBeaconOrder(){ return m_pib.macBeaconOrder;}
+ command ieee154_macBeaconTxTime_t MLME_GET.macBeaconTxTime() { return m_pib.macBeaconTxTime;}
- command ieee154_macBeaconTxTime_t MLME_GET.macBeaconTxTime(){ return m_pib.macBeaconTxTime;}
+ command ieee154_macBSN_t MLME_GET.macBSN() { return m_pib.macBSN;}
- command ieee154_macBSN_t MLME_GET.macBSN(){ return m_pib.macBSN;}
+ command ieee154_macCoordExtendedAddress_t MLME_GET.macCoordExtendedAddress() { return m_pib.macCoordExtendedAddress;}
- command ieee154_macCoordExtendedAddress_t MLME_GET.macCoordExtendedAddress(){ return m_pib.macCoordExtendedAddress;}
+ command ieee154_macCoordShortAddress_t MLME_GET.macCoordShortAddress() { return m_pib.macCoordShortAddress;}
- command ieee154_macCoordShortAddress_t MLME_GET.macCoordShortAddress(){ return m_pib.macCoordShortAddress;}
+ command ieee154_macDSN_t MLME_GET.macDSN() { return m_pib.macDSN;}
- command ieee154_macDSN_t MLME_GET.macDSN(){ return m_pib.macDSN;}
+ command ieee154_macGTSPermit_t MLME_GET.macGTSPermit() { return m_pib.macGTSPermit;}
- command ieee154_macGTSPermit_t MLME_GET.macGTSPermit(){ return m_pib.macGTSPermit;}
+ command ieee154_macMaxCSMABackoffs_t MLME_GET.macMaxCSMABackoffs() { return m_pib.macMaxCSMABackoffs;}
- command ieee154_macMaxCSMABackoffs_t MLME_GET.macMaxCSMABackoffs(){ return m_pib.macMaxCSMABackoffs;}
+ command ieee154_macMinBE_t MLME_GET.macMinBE() { return m_pib.macMinBE;}
- command ieee154_macMinBE_t MLME_GET.macMinBE(){ return m_pib.macMinBE;}
+ command ieee154_macPANId_t MLME_GET.macPANId() { return m_pib.macPANId;}
- command ieee154_macPANId_t MLME_GET.macPANId(){ return m_pib.macPANId;}
+ command ieee154_macPromiscuousMode_t MLME_GET.macPromiscuousMode() { return call PromiscuousModeGet.get();}
- command ieee154_macPromiscuousMode_t MLME_GET.macPromiscuousMode(){ return call PromiscuousModeGet.get();}
+ command ieee154_macRxOnWhenIdle_t MLME_GET.macRxOnWhenIdle() { return m_pib.macRxOnWhenIdle;}
- command ieee154_macRxOnWhenIdle_t MLME_GET.macRxOnWhenIdle(){ return m_pib.macRxOnWhenIdle;}
+ command ieee154_macShortAddress_t MLME_GET.macShortAddress() { return m_pib.macShortAddress;}
- command ieee154_macShortAddress_t MLME_GET.macShortAddress(){ return m_pib.macShortAddress;}
+ command ieee154_macSuperframeOrder_t MLME_GET.macSuperframeOrder() { return m_pib.macSuperframeOrder;}
- command ieee154_macSuperframeOrder_t MLME_GET.macSuperframeOrder(){ return m_pib.macSuperframeOrder;}
+ command ieee154_macTransactionPersistenceTime_t MLME_GET.macTransactionPersistenceTime() { return m_pib.macTransactionPersistenceTime;}
- command ieee154_macTransactionPersistenceTime_t MLME_GET.macTransactionPersistenceTime(){ return m_pib.macTransactionPersistenceTime;}
+ command ieee154_macAssociatedPANCoord_t MLME_GET.macAssociatedPANCoord() { return m_pib.macAssociatedPANCoord;}
- command ieee154_macAssociatedPANCoord_t MLME_GET.macAssociatedPANCoord(){ return m_pib.macAssociatedPANCoord;}
+ command ieee154_macMaxBE_t MLME_GET.macMaxBE() { return m_pib.macMaxBE;}
- command ieee154_macMaxBE_t MLME_GET.macMaxBE(){ return m_pib.macMaxBE;}
+ command ieee154_macMaxFrameTotalWaitTime_t MLME_GET.macMaxFrameTotalWaitTime() { return m_pib.macMaxFrameTotalWaitTime;}
- command ieee154_macMaxFrameTotalWaitTime_t MLME_GET.macMaxFrameTotalWaitTime(){ return m_pib.macMaxFrameTotalWaitTime;}
+ command ieee154_macMaxFrameRetries_t MLME_GET.macMaxFrameRetries() { return m_pib.macMaxFrameRetries;}
- command ieee154_macMaxFrameRetries_t MLME_GET.macMaxFrameRetries(){ return m_pib.macMaxFrameRetries;}
+ command ieee154_macResponseWaitTime_t MLME_GET.macResponseWaitTime() { return m_pib.macResponseWaitTime;}
- command ieee154_macResponseWaitTime_t MLME_GET.macResponseWaitTime(){ return m_pib.macResponseWaitTime;}
+ command ieee154_macSyncSymbolOffset_t MLME_GET.macSyncSymbolOffset() { return IEEE154_SYNC_SYMBOL_OFFSET;}
- command ieee154_macSyncSymbolOffset_t MLME_GET.macSyncSymbolOffset(){ return IEEE154_SYNC_SYMBOL_OFFSET;}
+ command ieee154_macTimestampSupported_t MLME_GET.macTimestampSupported() { return IEEE154_TIMESTAMP_SUPPORTED;}
- command ieee154_macTimestampSupported_t MLME_GET.macTimestampSupported(){ return IEEE154_TIMESTAMP_SUPPORTED;}
+ command ieee154_macSecurityEnabled_t MLME_GET.macSecurityEnabled() { return m_pib.macSecurityEnabled;}
- command ieee154_macSecurityEnabled_t MLME_GET.macSecurityEnabled(){ return m_pib.macSecurityEnabled;}
+ command ieee154_macMinLIFSPeriod_t MLME_GET.macMinLIFSPeriod() { return IEEE154_MIN_LIFS_PERIOD;}
- command ieee154_macMinLIFSPeriod_t MLME_GET.macMinLIFSPeriod(){ return IEEE154_MIN_LIFS_PERIOD;}
+ command ieee154_macMinSIFSPeriod_t MLME_GET.macMinSIFSPeriod() { return IEEE154_MIN_SIFS_PERIOD;}
- command ieee154_macMinSIFSPeriod_t MLME_GET.macMinSIFSPeriod(){ return IEEE154_MIN_SIFS_PERIOD;}
+ command ieee154_macPanCoordinator_t MLME_GET.macPanCoordinator() { return m_pib.macPanCoordinator;}
-/* ----------------------- MLME-SET ----------------------- */
+ /* ----------------------- MLME-SET ----------------------- */
- command ieee154_status_t MLME_SET.phyCurrentChannel(ieee154_phyCurrentChannel_t value){
+ command ieee154_status_t MLME_SET.phyCurrentChannel(ieee154_phyCurrentChannel_t value) {
uint32_t i = 1;
uint8_t k = value;
- while (i && k){
+ while (i && k) {
i <<= 1;
k -= 1;
}
return IEEE154_SUCCESS;
}
- command ieee154_status_t MLME_SET.phyTransmitPower(ieee154_phyTransmitPower_t value){
+ command ieee154_status_t MLME_SET.phyTransmitPower(ieee154_phyTransmitPower_t value) {
m_pib.phyTransmitPower = (value & 0x3F);
signal PIBUpdate.notify[IEEE154_phyTransmitPower](&m_pib.phyTransmitPower);
return IEEE154_SUCCESS;
}
- command ieee154_status_t MLME_SET.phyCCAMode(ieee154_phyCCAMode_t value){
+ command ieee154_status_t MLME_SET.phyCCAMode(ieee154_phyCCAMode_t value) {
if (value < 1 || value > 3)
return IEEE154_INVALID_PARAMETER;
m_pib.phyCCAMode = value;
return IEEE154_SUCCESS;
}
- command ieee154_status_t MLME_SET.phyCurrentPage(ieee154_phyCurrentPage_t value){
+ command ieee154_status_t MLME_SET.phyCurrentPage(ieee154_phyCurrentPage_t value) {
if (value > 31)
return IEEE154_INVALID_PARAMETER;
m_pib.phyCurrentPage = value;
return IEEE154_SUCCESS;
}
- command ieee154_status_t MLME_SET.macAssociationPermit(ieee154_macAssociationPermit_t value){
+ command ieee154_status_t MLME_SET.macAssociationPermit(ieee154_macAssociationPermit_t value) {
m_pib.macAssociationPermit = value;
signal PIBUpdate.notify[IEEE154_macAssociationPermit](&m_pib.macAssociationPermit);
return IEEE154_SUCCESS;
}
- command ieee154_status_t MLME_SET.macAutoRequest(ieee154_macAutoRequest_t value){
+ command ieee154_status_t MLME_SET.macAutoRequest(ieee154_macAutoRequest_t value) {
m_pib.macAutoRequest = value;
signal PIBUpdate.notify[IEEE154_macAutoRequest](&m_pib.macAutoRequest);
return IEEE154_SUCCESS;
}
- command ieee154_status_t MLME_SET.macBattLifeExt(ieee154_macBattLifeExt_t value){
+ command ieee154_status_t MLME_SET.macBattLifeExt(ieee154_macBattLifeExt_t value) {
m_pib.macBattLifeExt = value;
signal PIBUpdate.notify[IEEE154_macBattLifeExt](&m_pib.macBattLifeExt);
return IEEE154_SUCCESS;
}
- command ieee154_status_t MLME_SET.macBattLifeExtPeriods(ieee154_macBattLifeExtPeriods_t value){
+ command ieee154_status_t MLME_SET.macBattLifeExtPeriods(ieee154_macBattLifeExtPeriods_t value) {
if (value < 6 || value > 41)
return IEEE154_INVALID_PARAMETER;
m_pib.macBattLifeExtPeriods = value;
return IEEE154_SUCCESS;
}
- command ieee154_status_t MLME_SET.macBeaconOrder(ieee154_macBeaconOrder_t value){
+ command ieee154_status_t MLME_SET.macBeaconOrder(ieee154_macBeaconOrder_t value) {
if (value > 15)
return IEEE154_INVALID_PARAMETER;
m_pib.macBeaconOrder = value;
return IEEE154_SUCCESS;
}
- command ieee154_status_t MLME_SET.macBSN(ieee154_macBSN_t value){
+ command ieee154_status_t MLME_SET.macBSN(ieee154_macBSN_t value) {
m_pib.macBSN = value;
signal PIBUpdate.notify[IEEE154_macBSN](&m_pib.macBSN);
return IEEE154_SUCCESS;
}
- command ieee154_status_t MLME_SET.macCoordExtendedAddress(ieee154_macCoordExtendedAddress_t value){
+ command ieee154_status_t MLME_SET.macCoordExtendedAddress(ieee154_macCoordExtendedAddress_t value) {
m_pib.macCoordExtendedAddress = value;
signal PIBUpdate.notify[IEEE154_macCoordExtendedAddress](&m_pib.macCoordExtendedAddress);
return IEEE154_SUCCESS;
}
- command ieee154_status_t MLME_SET.macCoordShortAddress(ieee154_macCoordShortAddress_t value){
+ command ieee154_status_t MLME_SET.macCoordShortAddress(ieee154_macCoordShortAddress_t value) {
m_pib.macCoordShortAddress = value;
signal PIBUpdate.notify[IEEE154_macCoordShortAddress](&m_pib.macCoordShortAddress);
return IEEE154_SUCCESS;
}
- command ieee154_status_t MLME_SET.macDSN(ieee154_macDSN_t value){
+ command ieee154_status_t MLME_SET.macDSN(ieee154_macDSN_t value) {
m_pib.macDSN = value;
signal PIBUpdate.notify[IEEE154_macDSN](&m_pib.macDSN);
return IEEE154_SUCCESS;
}
- command ieee154_status_t MLME_SET.macGTSPermit(ieee154_macGTSPermit_t value){
+ command ieee154_status_t MLME_SET.macGTSPermit(ieee154_macGTSPermit_t value) {
m_pib.macGTSPermit = value;
signal PIBUpdate.notify[IEEE154_macGTSPermit](&m_pib.macGTSPermit);
return IEEE154_SUCCESS;
}
- command ieee154_status_t MLME_SET.macMaxCSMABackoffs(ieee154_macMaxCSMABackoffs_t value){
+ command ieee154_status_t MLME_SET.macMaxCSMABackoffs(ieee154_macMaxCSMABackoffs_t value) {
if (value > 5)
return IEEE154_INVALID_PARAMETER;
m_pib.macMaxCSMABackoffs = value;
return IEEE154_SUCCESS;
}
- command ieee154_status_t MLME_SET.macMinBE(ieee154_macMinBE_t value){
+ command ieee154_status_t MLME_SET.macMinBE(ieee154_macMinBE_t value) {
if (value > m_pib.macMaxBE)
return IEEE154_INVALID_PARAMETER;
m_pib.macMinBE = value;
return IEEE154_SUCCESS;
}
- command ieee154_status_t MLME_SET.macPANId(ieee154_macPANId_t value){
+ command ieee154_status_t MLME_SET.macPANId(ieee154_macPANId_t value) {
m_pib.macPANId = value;
signal PIBUpdate.notify[IEEE154_macPANId](&m_pib.macPANId);
return IEEE154_SUCCESS;
}
- command ieee154_status_t MLME_SET.macRxOnWhenIdle(ieee154_macRxOnWhenIdle_t value){
+ command ieee154_status_t MLME_SET.macRxOnWhenIdle(ieee154_macRxOnWhenIdle_t value) {
m_pib.macRxOnWhenIdle = value;
signal PIBUpdate.notify[IEEE154_macRxOnWhenIdle](&m_pib.macRxOnWhenIdle);
return IEEE154_SUCCESS;
}
- command ieee154_status_t MLME_SET.macShortAddress(ieee154_macShortAddress_t value){
+ command ieee154_status_t MLME_SET.macShortAddress(ieee154_macShortAddress_t value) {
m_pib.macShortAddress = value;
signal PIBUpdate.notify[IEEE154_macShortAddress](&m_pib.macShortAddress);
return IEEE154_SUCCESS;
}
- command ieee154_status_t MLME_SET.macTransactionPersistenceTime(ieee154_macTransactionPersistenceTime_t value){
+ command ieee154_status_t MLME_SET.macTransactionPersistenceTime(ieee154_macTransactionPersistenceTime_t value) {
m_pib.macTransactionPersistenceTime = value;
signal PIBUpdate.notify[IEEE154_macTransactionPersistenceTime](&m_pib.macTransactionPersistenceTime);
return IEEE154_SUCCESS;
}
- command ieee154_status_t MLME_SET.macAssociatedPANCoord(ieee154_macAssociatedPANCoord_t value){
+ command ieee154_status_t MLME_SET.macAssociatedPANCoord(ieee154_macAssociatedPANCoord_t value) {
m_pib.macAssociatedPANCoord = value;
signal PIBUpdate.notify[IEEE154_macAssociatedPANCoord](&m_pib.macAssociatedPANCoord);
return IEEE154_SUCCESS;
}
- command ieee154_status_t MLME_SET.macMaxBE(ieee154_macMaxBE_t value){
+ command ieee154_status_t MLME_SET.macMaxBE(ieee154_macMaxBE_t value) {
if (value < 3 || value > 8)
return IEEE154_INVALID_PARAMETER;
m_pib.macMaxBE = value;
return IEEE154_SUCCESS;
}
- command ieee154_status_t MLME_SET.macMaxFrameTotalWaitTime(ieee154_macMaxFrameTotalWaitTime_t value){
+ command ieee154_status_t MLME_SET.macMaxFrameTotalWaitTime(ieee154_macMaxFrameTotalWaitTime_t value) {
// equation 14 on page 160 defines how macMaxFrameTotalWaitTime is calculated;
// its value depends only on other PIB attributes and constants - why does the standard
// allow setting it by the next higher layer ??
return IEEE154_SUCCESS;
}
- command ieee154_status_t MLME_SET.macMaxFrameRetries(ieee154_macMaxFrameRetries_t value){
+ command ieee154_status_t MLME_SET.macMaxFrameRetries(ieee154_macMaxFrameRetries_t value) {
if (value > 7)
return IEEE154_INVALID_PARAMETER;
m_pib.macMaxFrameRetries = value;
return IEEE154_SUCCESS;
}
- command ieee154_status_t MLME_SET.macResponseWaitTime(ieee154_macResponseWaitTime_t value){
+ command ieee154_status_t MLME_SET.macResponseWaitTime(ieee154_macResponseWaitTime_t value) {
if (value < 2 || value > 64)
return IEEE154_INVALID_PARAMETER;
m_pib.macResponseWaitTime = value;
return IEEE154_SUCCESS;
}
- command ieee154_status_t MLME_SET.macSecurityEnabled(ieee154_macSecurityEnabled_t value){
+ command ieee154_status_t MLME_SET.macSecurityEnabled(ieee154_macSecurityEnabled_t value) {
return IEEE154_UNSUPPORTED_ATTRIBUTE;
}
// Read-only attributes (writable only by MAC components)
- command void SetMacSuperframeOrder.set( ieee154_macSuperframeOrder_t value ){
+ command void SetMacSuperframeOrder.set( ieee154_macSuperframeOrder_t value) {
m_pib.macSuperframeOrder = value;
signal PIBUpdate.notify[IEEE154_macSuperframeOrder](&m_pib.macSuperframeOrder);
}
- command void SetMacBeaconTxTime.set( ieee154_macBeaconTxTime_t value ){
+ command void SetMacBeaconTxTime.set( ieee154_macBeaconTxTime_t value) {
m_pib.macBeaconTxTime = value;
signal PIBUpdate.notify[IEEE154_macBeaconTxTime](&m_pib.macBeaconTxTime);
}
- command void SetMacPanCoordinator.set( ieee154_macPanCoordinator_t value ){
+ command void SetMacPanCoordinator.set( ieee154_macPanCoordinator_t value) {
m_pib.macPanCoordinator = value;
signal PIBUpdate.notify[IEEE154_macPanCoordinator](&m_pib.macPanCoordinator);
}
- command ieee154_macPanCoordinator_t IsMacPanCoordinator.get(){
- return m_pib.macPanCoordinator;
- }
-
-/* ----------------------- TimeCalc ----------------------- */
+ /* ----------------------- TimeCalc ----------------------- */
async command uint32_t TimeCalc.timeElapsed(uint32_t t0, uint32_t t1)
{
return (elapsed >= dt);
}
-/* ----------------------- Frame Access ----------------------- */
+ /* ----------------------- Frame Access ----------------------- */
command void Packet.clear(message_t* msg)
{
- uint8_t i;
memset(msg->header, 0, sizeof(message_header_t));
memset(msg->metadata, 0, sizeof(message_metadata_t));
}
command uint8_t Packet.maxPayloadLength()
{
-#if TOSH_DATA_LENGTH < 118
+#if TOSH_DATA_LENGTH < IEEE154_aMaxMACPayloadSize
#warning Payload portion in message_t is smaller than required (TOSH_DATA_LENGTH < IEEE154_aMaxMACPayloadSize). This means that larger packets cannot be sent/received.
#endif
return TOSH_DATA_LENGTH;
bool PANIDCompression)
{
uint8_t offset = MHR_INDEX_ADDRESS;
- if (DstAddrMode == ADDR_MODE_SHORT_ADDRESS || DstAddrMode == ADDR_MODE_EXTENDED_ADDRESS){
+ if (DstAddrMode == ADDR_MODE_SHORT_ADDRESS || DstAddrMode == ADDR_MODE_EXTENDED_ADDRESS) {
*((nxle_uint16_t*) &mhr[offset]) = DstPANId;
offset += 2;
- if (DstAddrMode == ADDR_MODE_SHORT_ADDRESS){
+ if (DstAddrMode == ADDR_MODE_SHORT_ADDRESS) {
*((nxle_uint16_t*) &mhr[offset]) = DstAddr->shortAddress;
offset += 2;
} else {
offset += 8;
}
}
- if (SrcAddrMode == ADDR_MODE_SHORT_ADDRESS || SrcAddrMode == ADDR_MODE_EXTENDED_ADDRESS){
- if (DstPANId != SrcPANId || !PANIDCompression){
+ if (SrcAddrMode == ADDR_MODE_SHORT_ADDRESS || SrcAddrMode == ADDR_MODE_EXTENDED_ADDRESS) {
+ if (DstPANId != SrcPANId || !PANIDCompression) {
*((nxle_uint16_t*) &mhr[offset]) = SrcPANId;
offset += 2;
}
- if (SrcAddrMode == ADDR_MODE_SHORT_ADDRESS){
+ if (SrcAddrMode == ADDR_MODE_SHORT_ADDRESS) {
*((nxle_uint16_t*) &mhr[offset]) = SrcAddr->shortAddress;
offset += 2;
} else {
if ((*(nxle_uint16_t*) (&mhr[offset])) != m_pib.macPANId)
return FALSE; // wrong PAN ID
offset += 2;
- if ((mhr[MHR_INDEX_FC2] & FC2_SRC_MODE_MASK) == FC2_SRC_MODE_SHORT){
+ if ((mhr[MHR_INDEX_FC2] & FC2_SRC_MODE_MASK) == FC2_SRC_MODE_SHORT) {
if ((*(nxle_uint16_t*) (&mhr[offset])) != m_pib.macCoordShortAddress)
return FALSE;
- } else if ((mhr[MHR_INDEX_FC2] & FC2_SRC_MODE_MASK) == FC2_SRC_MODE_EXTENDED){
+ } else if ((mhr[MHR_INDEX_FC2] & FC2_SRC_MODE_MASK) == FC2_SRC_MODE_EXTENDED) {
if (!isCoordExtendedAddress(mhr + offset))
return FALSE;
}
if (fcf1 & FC1_SECURITY_ENABLED)
return FAIL; // not supported
idCompression = (fcf1 & FC1_PAN_ID_COMPRESSION);
- if (fcf2 & 0x08){ // short or ext. address
+ if (fcf2 & 0x08) { // short or ext. address
offset += 4; // pan id + short address
if (fcf2 & 0x04) // ext. address
offset += 6; // diff to short address
}
- if (fcf2 & 0x80){ // short or ext. address
+ if (fcf2 & 0x80) { // short or ext. address
offset += 2;
if (!idCompression)
offset += 2;
if ((mhr[MHR_INDEX_FC2] & FC2_SRC_MODE_MASK) == FC2_SRC_MODE_SHORT)
address->shortAddress = *((nxle_uint16_t*) (&(mhr[offset])));
else
- call FrameUtility.convertToNative(&address->extendedAddress, (&(mhr[offset]) ));
+ call FrameUtility.convertToNative(&address->extendedAddress, (&(mhr[offset])));
return SUCCESS;
}
command bool Frame.hasStandardCompliantHeader(message_t* frame)
{
uint8_t *mhr = MHR(frame);
- if ( ((mhr[0] & FC1_FRAMETYPE_MASK) > 0x03) ||
+ if (((mhr[0] & FC1_FRAMETYPE_MASK) > 0x03) ||
((mhr[MHR_INDEX_FC2] & FC2_DEST_MODE_MASK) == 0x04) ||
((mhr[MHR_INDEX_FC2] & FC2_SRC_MODE_MASK) == 0x40) ||
#ifndef IEEE154_SECURITY_ENABLED
((mhr[0] & FC1_SECURITY_ENABLED)) ||
#endif
- (mhr[MHR_INDEX_FC2] & FC2_FRAME_VERSION_2)
- )
+ (mhr[MHR_INDEX_FC2] & FC2_FRAME_VERSION_2))
return FALSE;
else
return TRUE;
}
-/* ----------------------- Beacon Frame Access ----------------------- */
+ /* ----------------------- Beacon Frame Access ----------------------- */
uint8_t getPendAddrSpecOffset(uint8_t *macPayloadField)
{
uint8_t pendAddrSpec = payload[pendAddrSpecOffset], i;
if (((mhr[MHR_INDEX_FC1] & FC1_FRAMETYPE_MASK) != FC1_FRAMETYPE_BEACON))
return FAIL;
- if (addrMode == ADDR_MODE_SHORT_ADDRESS){
+ if (addrMode == ADDR_MODE_SHORT_ADDRESS) {
for (i=0; i<(pendAddrSpec & PENDING_ADDRESS_SHORT_MASK) && i<bufferSize; i++)
buffer[i].shortAddress = *((nxle_uint16_t*) (payload + pendAddrSpecOffset + 1 + 2*i));
return SUCCESS;
- } else if (addrMode == ADDR_MODE_EXTENDED_ADDRESS){
+ } else if (addrMode == ADDR_MODE_EXTENDED_ADDRESS) {
for (i=0; i<((pendAddrSpec & PENDING_ADDRESS_EXT_MASK) >> 4) && i<bufferSize; i++)
call FrameUtility.convertToNative(&(buffer[i].extendedAddress),
((payload + pendAddrSpecOffset +
{
uint8_t *mhr = MHR(frame);
uint8_t *payload = (uint8_t *) frame->data;
- if ((mhr[MHR_INDEX_FC1] & FC1_FRAMETYPE_MASK) == FC1_FRAMETYPE_BEACON){
+ if ((mhr[MHR_INDEX_FC1] & FC1_FRAMETYPE_MASK) == FC1_FRAMETYPE_BEACON) {
uint8_t pendAddrSpecOffset = getPendAddrSpecOffset(payload);
uint8_t pendAddrSpec = payload[pendAddrSpecOffset];
payload += (pendAddrSpecOffset + 1);
{
uint8_t *mhr = MHR(frame);
uint8_t len = ((ieee154_header_t*) frame->header)->length & FRAMECTL_LENGTH_MASK;
- if ((mhr[MHR_INDEX_FC1] & FC1_FRAMETYPE_MASK) == FC1_FRAMETYPE_BEACON){
- uint8_t *payload = call Frame.getPayload(frame);
+ if ((mhr[MHR_INDEX_FC1] & FC1_FRAMETYPE_MASK) == FC1_FRAMETYPE_BEACON) {
+ uint8_t *payload = call BeaconFrame.getBeaconPayload(frame);
len = len - (payload - (uint8_t *) frame->data);
}
return len;
message_t *frame,
uint8_t LogicalChannel,
uint8_t ChannelPage,
- ieee154_PANDescriptor_t *PANDescriptor
- )
+ ieee154_PANDescriptor_t *pdescriptor)
{
uint8_t *mhr = MHR(frame);
uint8_t offset;
ieee154_metadata_t *metadata = (ieee154_metadata_t*) frame->metadata;
- if ( (mhr[MHR_INDEX_FC1] & FC1_FRAMETYPE_MASK) != FC1_FRAMETYPE_BEACON ||
+ if ((mhr[MHR_INDEX_FC1] & FC1_FRAMETYPE_MASK) != FC1_FRAMETYPE_BEACON ||
(((mhr[MHR_INDEX_FC2] & FC2_SRC_MODE_MASK) != FC2_SRC_MODE_SHORT) &&
- ((mhr[MHR_INDEX_FC2] & FC2_SRC_MODE_MASK) != FC2_SRC_MODE_EXTENDED)) )
+ ((mhr[MHR_INDEX_FC2] & FC2_SRC_MODE_MASK) != FC2_SRC_MODE_EXTENDED)))
return FAIL;
- PANDescriptor->CoordAddrMode = (mhr[MHR_INDEX_FC2] & FC2_SRC_MODE_MASK) >> FC2_SRC_MODE_OFFSET;
+
+ pdescriptor->CoordAddrMode = (mhr[MHR_INDEX_FC2] & FC2_SRC_MODE_MASK) >> FC2_SRC_MODE_OFFSET;
offset = MHR_INDEX_ADDRESS;
- PANDescriptor->CoordPANId = *((nxle_uint16_t*) &mhr[offset]);
+ pdescriptor->CoordPANId = *((nxle_uint16_t*) &mhr[offset]);
offset += sizeof(ieee154_macPANId_t);
+
if ((mhr[MHR_INDEX_FC2] & FC2_SRC_MODE_MASK) == FC2_SRC_MODE_SHORT)
- PANDescriptor->CoordAddress.shortAddress = *((nxle_uint16_t*) &mhr[offset]);
+ pdescriptor->CoordAddress.shortAddress = *((nxle_uint16_t*) &mhr[offset]);
else
- call FrameUtility.convertToNative(&PANDescriptor->CoordAddress.extendedAddress, &mhr[offset]);
- PANDescriptor->LogicalChannel = LogicalChannel;
- PANDescriptor->ChannelPage = ChannelPage;
- ((uint8_t*) &PANDescriptor->SuperframeSpec)[0] = frame->data[BEACON_INDEX_SF_SPEC1]; // little endian
- ((uint8_t*) &PANDescriptor->SuperframeSpec)[1] = frame->data[BEACON_INDEX_SF_SPEC2];
- PANDescriptor->GTSPermit = (frame->data[BEACON_INDEX_GTS_SPEC] & GTS_SPEC_PERMIT) ? 1 : 0;
- PANDescriptor->LinkQuality = metadata->linkQuality;
- PANDescriptor->TimeStamp = metadata->timestamp;
+ call FrameUtility.convertToNative(&pdescriptor->CoordAddress.extendedAddress, &mhr[offset]);
+
+ pdescriptor->LogicalChannel = LogicalChannel;
+ pdescriptor->ChannelPage = ChannelPage;
+ ((uint8_t*) &pdescriptor->SuperframeSpec)[0] = frame->data[BEACON_INDEX_SF_SPEC1]; // little endian
+ ((uint8_t*) &pdescriptor->SuperframeSpec)[1] = frame->data[BEACON_INDEX_SF_SPEC2];
+ pdescriptor->GTSPermit = (frame->data[BEACON_INDEX_GTS_SPEC] & GTS_SPEC_PERMIT) ? 1 : 0;
+ pdescriptor->LinkQuality = metadata->linkQuality;
+ pdescriptor->TimeStamp = metadata->timestamp;
#ifndef IEEE154_SECURITY_ENABLED
- PANDescriptor->SecurityFailure = IEEE154_SUCCESS;
- PANDescriptor->SecurityLevel = 0;
- PANDescriptor->KeyIdMode = 0;
- PANDescriptor->KeySource = 0;
- PANDescriptor->KeyIndex = 0;
+ pdescriptor->SecurityFailure = IEEE154_SUCCESS;
+ pdescriptor->SecurityLevel = 0;
+ pdescriptor->KeyIdMode = 0;
+ pdescriptor->KeySource = 0;
+ pdescriptor->KeyIndex = 0;
#else
-#error Implementation of BeaconFrame.parsePANDescriptor() needs adaptation !
+#error Implementation of BeaconFrame.parsePANDescriptor() needs to be adapted!
#endif
return SUCCESS;
}
-/* ----------------------- FrameUtility, etc. ----------------------- */
+ /* ----------------------- FrameUtility, etc. ----------------------- */
command uint64_t GetLocalExtendedAddress.get()
{
{
uint8_t i;
uint64_t srcCopy = *src;
- for (i=0; i<8; i++){
+ for (i=0; i<8; i++) {
destLE[i] = srcCopy;
srcCopy >>= 8;
}
return dest == m_pib.macCoordExtendedAddress;
}
- command bool IsBeaconEnabledPAN.get()
- {
- return (m_panType == BEACON_ENABLED_PAN);
- }
-
- default event void PIBUpdate.notify[uint8_t PIBAttributeID](const void* PIBAttributeValue){}
- command error_t PIBUpdate.enable[uint8_t PIBAttributeID](){return FAIL;}
- command error_t PIBUpdate.disable[uint8_t PIBAttributeID](){return FAIL;}
+ default event void PIBUpdate.notify[uint8_t PIBAttributeID](const void* PIBAttributeValue) {}
+ command error_t PIBUpdate.enable[uint8_t PIBAttributeID]() {return FAIL;}
+ command error_t PIBUpdate.disable[uint8_t PIBAttributeID]() {return FAIL;}
+ async event void RadioToken.transferredFrom(uint8_t fromClient){ASSERT(0);}
}