]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
- macShortAddress PIB attribute is now updated automatically after a successful assoc...
authorjanhauer <janhauer>
Fri, 16 Oct 2009 12:25:45 +0000 (12:25 +0000)
committerjanhauer <janhauer>
Fri, 16 Oct 2009 12:25:45 +0000 (12:25 +0000)
- all PAN-related attributes are removed automatically from PIB after successful disassociation
- added some debug output

tos/lib/mac/tkn154/AssociateP.nc
tos/lib/mac/tkn154/BeaconSynchronizeP.nc
tos/lib/mac/tkn154/DisassociateP.nc
tos/lib/mac/tkn154/TKN154BeaconEnabledP.nc
tos/lib/mac/tkn154/TKN154NonBeaconEnabledP.nc

index d5296c8706a381b63938b8a0005cd43964f1f0bf..3d697f65d474fbe0f8717ff43471373f6d3c078b 100644 (file)
@@ -204,6 +204,8 @@ implementation
     if (m_associationOngoing) {
       call ResponseTimeout.stop();
       m_associationOngoing = FALSE;
+      if (m_assocRespStatus == IEEE154_ASSOCIATION_SUCCESSFUL)
+        call MLME_SET.macShortAddress(m_shortAddress);
       signal MLME_ASSOCIATE.confirm(m_shortAddress, m_assocRespStatus, 0);
       dbg_serial("AssociationP", "confirm: %lx, %lu\n", 
           (uint32_t) m_shortAddress, (uint32_t) m_assocRespStatus);
index 779a81f41bcf3904ecae0948378fcb95f3266363..57f4faeb753ec26a7649801071bcbf3718cf18e4 100644 (file)
@@ -244,8 +244,8 @@ implementation
 
     if (call RadioOff.isOff())
       signal RadioOff.offDone();
-    else
-      ASSERT(call RadioOff.off() == SUCCESS);
+    else if (call RadioOff.off() != SUCCESS) 
+      ASSERT(0);
   }
 
   async event void RadioOff.offDone()
@@ -267,18 +267,29 @@ implementation
 
   async event void BeaconRx.enableRxDone()
   {
+    uint32_t dt;
+
     switch (m_state)
     {
       case S_INITIAL_SCAN: 
+        // "To acquire beacon synchronization, a device shall enable its 
+        // receiver and search for at most [aBaseSuperframeDuration * (2^n + 1)]
+        // symbols, where n is the value of macBeaconOrder [...] Once the number
+        // of missed beacons reaches aMaxLostBeacons, the MLME shall notify the 
+        // next higher layer." (Sect. 7.5.4.1)
         m_state = S_RECEIVING;
-        call TrackAlarm.start((((uint32_t) 1 << m_beaconOrder) + (uint32_t) 1) * 
-          (uint32_t) IEEE154_aBaseSuperframeDuration * (uint32_t) IEEE154_aMaxLostBeacons);
+        dt = (((uint32_t) 1 << m_beaconOrder) + (uint32_t) 1) * 
+          (uint32_t) IEEE154_aBaseSuperframeDuration * 
+          (uint32_t) IEEE154_aMaxLostBeacons;
+        call TrackAlarm.start(dt);
+        dbg_serial("BeaconSynchronizeP","Rx enabled, expecting beacon within %lu symbols.\n", dt);
         break;
       case S_PREPARE:
         m_state = S_RECEIVING;
-        dbg_serial("BeaconSynchronizeP","Rx enabled, expecting beacon in %lu symbols.\n",
-            (uint32_t) ((m_lastBeaconRxTime + m_dt) - call TrackAlarm.getNow())); 
-        call TrackAlarm.startAt(m_lastBeaconRxTime, m_dt + IEEE154_MAX_BEACON_LISTEN_TIME(m_beaconOrder));
+        dt = m_dt + IEEE154_MAX_BEACON_LISTEN_TIME(m_beaconOrder);
+        call TrackAlarm.startAt(m_lastBeaconRxTime, dt);
+        dbg_serial("BeaconSynchronizeP","Rx enabled, expecting beacon within %lu symbols.\n",
+            (uint32_t) ((m_lastBeaconRxTime + dt) - call TrackAlarm.getNow())); 
         break;
       default:
         ASSERT(0);
index dbc58a99cc15d10154fd92483f9783de38bdaff2..ad9404ed9b2323814063ff84cfb639e5b2ff0f1d 100644 (file)
@@ -55,6 +55,7 @@ module DisassociateP
     interface Pool<ieee154_txframe_t> as TxFramePool;
     interface Pool<ieee154_txcontrol_t> as TxControlPool;
     interface MLME_GET;
+    interface MLME_SET;
     interface FrameUtility;
     interface IEEE154Frame as Frame;
     interface Get<uint64_t> as LocalExtendedAddress;
@@ -68,6 +69,7 @@ implementation
   uint8_t m_payloadDisassocRequest[2];
   uint8_t m_coordAddrMode;
   bool m_disAssociationOngoing;
+  void resetPanValuesInPib();
 
   command error_t Init.init()
   {
@@ -151,6 +153,7 @@ implementation
     uint8_t DeviceAddrMode = (mhr[MHR_INDEX_FC2] & FC2_SRC_MODE_MASK) >> FC2_SRC_MODE_OFFSET;
     uint16_t DevicePANID = *((nxle_uint16_t*) (&(mhr[MHR_INDEX_ADDRESS])));
     ieee154_address_t DeviceAddress;
+
     if ((mhr[MHR_INDEX_FC2] & FC2_DEST_MODE_MASK) == FC2_DEST_MODE_EXTENDED)
       srcAddrOffset += 6;
     call FrameUtility.convertToNative(&DeviceAddress.extendedAddress, &mhr[srcAddrOffset]);
@@ -158,6 +161,11 @@ implementation
     call TxFramePool.put(data);
     dbg_serial("DisassociateP", "transmitDone() -> result: %lu\n", (uint32_t) status);
     m_disAssociationOngoing = FALSE;
+
+    // "[...] even if the acknowledgment is not received, 
+    // the device should consider itself disassociated."  (Sect. 7.5.3.2)
+    if (status == IEEE154_SUCCESS || status == IEEE154_NO_ACK)
+      resetPanValuesInPib();  
     signal MLME_DISASSOCIATE.confirm(status, DeviceAddrMode, DevicePANID, DeviceAddress);
   }
 
@@ -173,11 +181,17 @@ implementation
     uint8_t DeviceAddrMode = (mhr[1] & FC2_DEST_MODE_MASK) >> FC2_DEST_MODE_OFFSET;
     uint16_t DevicePANID = *((nxle_uint16_t*) (&(mhr[MHR_INDEX_ADDRESS])));
     ieee154_address_t DeviceAddress;
+
     call FrameUtility.convertToNative(&DeviceAddress.extendedAddress, &mhr[dstAddrOffset]);
     call TxControlPool.put((ieee154_txcontrol_t*) ((uint8_t*) data->header - offsetof(ieee154_txcontrol_t, header)));
     call TxFramePool.put(data);
     dbg_serial("DisassociateP", "transmitDone() -> result: %lu\n", (uint32_t) status);
     m_disAssociationOngoing = FALSE;
+
+    // "[...] even if the acknowledgment is not received, 
+    // the device should consider itself disassociated." (Sect. 7.5.3.2)
+    if (status == IEEE154_SUCCESS || status == IEEE154_NO_ACK)
+      resetPanValuesInPib();      
     signal MLME_DISASSOCIATE.confirm(status, DeviceAddrMode, DevicePANID, DeviceAddress);
   }
 
@@ -187,6 +201,7 @@ implementation
   {
     // received a disassociation notification from the coordinator (direct tx)
     ieee154_address_t address;
+
     address.extendedAddress = call LocalExtendedAddress.get();
     signal MLME_DISASSOCIATE.indication(address.extendedAddress, frame->data[1], NULL);
     return frame;
@@ -202,6 +217,7 @@ implementation
   {
     // received a disassociation notification from the device
     ieee154_address_t address;
+
     if (call Frame.getSrcAddrMode(frame) == ADDR_MODE_EXTENDED_ADDRESS && 
         call Frame.getSrcAddr(frame, &address) == SUCCESS)
       signal MLME_DISASSOCIATE.indication(address.extendedAddress, frame->data[1], NULL);
@@ -209,6 +225,19 @@ implementation
     return frame;
   }
 
+  void resetPanValuesInPib()
+  {
+    // "An associated device shall disassociate itself by removing 
+    // all references to the PAN; the MLME shall set macPANId, 
+    // macShortAddress, macAssociatedPANCoord, macCoordShortAddress 
+    // and macCoordExtended- Address to the default values." (Sect. 7.5.3.2) 
+    call MLME_SET.macPANId(IEEE154_DEFAULT_PANID);
+    call MLME_SET.macShortAddress(IEEE154_DEFAULT_SHORTADDRESS);
+    call MLME_SET.macAssociatedPANCoord(IEEE154_DEFAULT_ASSOCIATEDPANCOORD);
+    call MLME_SET.macCoordShortAddress(IEEE154_DEFAULT_COORDSHORTADDRESS);
+    call MLME_SET.macCoordExtendedAddress(0);
+  }
+
   /* ------------------- Defaults ------------------- */
 
   default event void MLME_DISASSOCIATE.indication (
index a2fe497251505603aeebeaf884350433993edcec..474995d74f70c70b3ad79002d7be20e254b7f547 100644 (file)
@@ -318,6 +318,7 @@ implementation
   DisassociateP.TxFramePool -> TxFramePoolP;
   DisassociateP.TxControlPool -> TxControlPoolP;
   DisassociateP.MLME_GET -> PibP;
+  DisassociateP.MLME_SET -> PibP;
   DisassociateP.FrameUtility -> PibP;
   DisassociateP.Frame -> PibP;
   DisassociateP.LocalExtendedAddress -> PibP.GetLocalExtendedAddress;
index f553f715031bbc03d8708d74e0e160b20f95a45b..dea2bdce5aae87c115f43e064fb28dcf126b9628 100644 (file)
@@ -231,6 +231,7 @@ implementation
   DisassociateP.TxFramePool -> TxFramePoolP;
   DisassociateP.TxControlPool -> TxControlPoolP;
   DisassociateP.MLME_GET -> PibP;
+  DisassociateP.MLME_SET -> PibP;
   DisassociateP.FrameUtility -> PibP;
   DisassociateP.Frame -> PibP;
   DisassociateP.LocalExtendedAddress -> PibP.GetLocalExtendedAddress;