]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/lib/mac/tkn154/PibP.nc
Moved a #define
[tinyos-2.x.git] / tos / lib / mac / tkn154 / PibP.nc
index b4e7f6f9a37a64206c3ad0a9a474443008ff8b08..51c41c9061d2de55c7a6e08505083cd7f4be254f 100644 (file)
@@ -55,6 +55,7 @@ module PibP {
     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;
@@ -67,7 +68,7 @@ module PibP {
     interface Init as MacReset;
     interface SplitControl as RadioControl;
     interface Random;
-    interface Resource as Token;
+    interface TransferableResource as RadioToken;
     interface RadioOff;
     interface LocalTime<TSymbolIEEE802154>;
   }
@@ -77,7 +78,7 @@ implementation
   ieee154_PIB_t m_pib;
   uint8_t m_numResetClientPending;
   bool m_setDefaultPIB;
-  uint8_t m_resetSpin;
+  norace uint8_t m_resetSpin;
 
 #ifdef IEEE154_EXTENDED_ADDRESS
   const uint64_t m_aExtendedAddressLE = IEEE154_EXTENDED_ADDRESS;
@@ -95,9 +96,7 @@ implementation
   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;
@@ -113,6 +112,7 @@ implementation
     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;
@@ -151,12 +151,12 @@ implementation
     if (m) {
       k = 0;
       while (k != m) {
-        waitTime += ((uint16_t) 1 << (macMaxBE+k));
+        waitTime += ((uint16_t) 1 << (macMinBE+k));
         k += 1;
       }
     }
     waitTime *= IEEE154_aUnitBackoffPeriod;
-    waitTime += IEEE154_SHR_DURATION;
+    waitTime += call MLME_GET.phyMaxFrameDuration();
     m_pib.macMaxFrameTotalWaitTime = waitTime;
   }
 
@@ -175,15 +175,15 @@ implementation
       status = IEEE154_TRANSACTION_OVERFLOW; // must first cancel promiscuous mode!
     else {
       m_setDefaultPIB = SetDefaultPIB;
-      if (!call Token.isOwner())
-        call Token.request();
+      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()
   {
     if (call RadioOff.off() != SUCCESS)
       signal RadioOff.offDone();
@@ -209,25 +209,21 @@ implementation
     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
-    m_resetSpin = 5;
     post resetSpinTask();
   }
 
   task void resetSpinTask()
   {
-    if (m_resetSpin == 2) {
-      // just to be safe...
-      call DispatchReset.init();       
-      call DispatchQueueReset.init();  
-      call MacReset.init();       
-    }
-    if (m_resetSpin--) {
+    m_resetSpin -= 1;
+    if (m_resetSpin != 0) {
       post resetSpinTask();
       return;
     }
     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)
@@ -242,7 +238,7 @@ implementation
       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);
   }
   
@@ -272,7 +268,7 @@ implementation
 
   command ieee154_macBattLifeExt_t MLME_GET.macBattLifeExt() { return m_pib.macBattLifeExt;}
 
-  command ieee154_macBattLifeExtPeriods_t MLME_GET.macBattLifeExtPeriods() { return IEEE154_BATT_LIFE_EXT_PERIODS;}
+  command ieee154_macBattLifeExtPeriods_t MLME_GET.macBattLifeExtPeriods() { return m_pib.macBattLifeExtPeriods;}
 
   command ieee154_macBeaconOrder_t MLME_GET.macBeaconOrder() { return m_pib.macBeaconOrder;}
 
@@ -572,7 +568,7 @@ implementation
 
   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;
@@ -944,7 +940,7 @@ implementation
     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);
+      uint8_t *payload = call BeaconFrame.getBeaconPayload(frame);
       len = len - (payload - (uint8_t *) frame->data);
     } 
     return len;
@@ -959,7 +955,7 @@ implementation
       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;
@@ -970,29 +966,29 @@ implementation
           ((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 to be adapted!
 #endif
@@ -1052,4 +1048,5 @@ implementation
   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);}
 }