]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/lib/mac/tkn154/DisassociateP.nc
- macShortAddress PIB attribute is now updated automatically after a successful assoc...
[tinyos-2.x.git] / tos / lib / mac / tkn154 / DisassociateP.nc
index a229f50a092d949863c3947536a4b9ddaa697528..ad9404ed9b2323814063ff84cfb639e5b2ff0f1d 100644 (file)
@@ -55,10 +55,10 @@ 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;
-    interface Ieee802154Debug as Debug;
   }
 }
 implementation
@@ -69,6 +69,7 @@ implementation
   uint8_t m_payloadDisassocRequest[2];
   uint8_t m_coordAddrMode;
   bool m_disAssociationOngoing;
+  void resetPanValuesInPib();
 
   command error_t Init.init()
   {
@@ -78,7 +79,7 @@ implementation
     return SUCCESS;
   }
 
-/* ------------------- MLME_DISASSOCIATE (initiating) ------------------- */
+  /* ------------------- MLME_DISASSOCIATE (initiating) ------------------- */
 
   command ieee154_status_t MLME_DISASSOCIATE.request  (
                           uint8_t DeviceAddrMode,
@@ -86,8 +87,7 @@ implementation
                           ieee154_address_t DeviceAddress,
                           ieee154_disassociation_reason_t DisassociateReason,
                           bool TxIndirect,
-                          ieee154_security_t *security
-                        )
+                          ieee154_security_t *security)
   {
     ieee154_status_t status = IEEE154_SUCCESS;
     ieee154_txframe_t *txFrame=0;
@@ -101,11 +101,11 @@ implementation
       status = IEEE154_INVALID_PARAMETER;
     else if (m_disAssociationOngoing || !(txFrame = call TxFramePool.get()))
       status = IEEE154_TRANSACTION_OVERFLOW;
-    else if (!(txControl = call TxControlPool.get())){
+    else if (!(txControl = call TxControlPool.get())) {
       call TxFramePool.put(txFrame);
       status = IEEE154_TRANSACTION_OVERFLOW;
     } 
-    if (status == IEEE154_SUCCESS){
+    if (status == IEEE154_SUCCESS) {
       txFrame->header = &txControl->header;
       txFrame->metadata = &txControl->metadata;
       srcAddress.extendedAddress = call LocalExtendedAddress.get();
@@ -129,20 +129,20 @@ implementation
       if ((DeviceAddrMode == ADDR_MODE_SHORT_ADDRESS &&
             DeviceAddress.shortAddress == call MLME_GET.macCoordShortAddress()) ||
           (DeviceAddrMode == ADDR_MODE_EXTENDED_ADDRESS &&
-           DeviceAddress.extendedAddress == call MLME_GET.macCoordExtendedAddress())){
+           DeviceAddress.extendedAddress == call MLME_GET.macCoordExtendedAddress())) {
         status = call DisassociationToCoord.transmit(txFrame);
       } else if (TxIndirect) {
         status = call DisassociationIndirectTx.transmit(txFrame);
       } else {
         status = call DisassociationDirectTx.transmit(txFrame);
       }
-      if (status != IEEE154_SUCCESS){
+      if (status != IEEE154_SUCCESS) {
         m_disAssociationOngoing = FALSE;
         call TxFramePool.put(txFrame);
         call TxControlPool.put(txControl);
       }
     }
-    call Debug.log(DEBUG_LEVEL_INFO, DISSASSOCIATE_REQUEST, status, 0, 0);
+    dbg_serial("DisassociateP", "MLME_DISASSOCIATE.request -> result: %lu\n", (uint32_t) status);
     return status;
   }
 
@@ -153,13 +153,19 @@ 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]);
     call TxControlPool.put((ieee154_txcontrol_t*) ((uint8_t*) data->header - offsetof(ieee154_txcontrol_t, header)));
     call TxFramePool.put(data);
-    call Debug.log(DEBUG_LEVEL_INFO, DISSASSOCIATE_TXDONE, status, 2, 0);
+    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);
   }
 
@@ -175,21 +181,27 @@ 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 Debug.log(DEBUG_LEVEL_INFO, DISSASSOCIATE_TXDONE, status, 1, 0);
     call TxControlPool.put((ieee154_txcontrol_t*) ((uint8_t*) data->header - offsetof(ieee154_txcontrol_t, header)));
     call TxFramePool.put(data);
-    call Debug.log(DEBUG_LEVEL_INFO, DISSASSOCIATE_TXDONE, status, 2, 0);
+    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);
   }
 
-/* ------------------- MLME_DISASSOCIATE (receiving) ------------------- */
+  /* ------------------- MLME_DISASSOCIATE (receiving) ------------------- */
 
   event message_t* DisassociationDirectRxFromCoord.received(message_t* frame)
   {
     // 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;
@@ -205,25 +217,38 @@ implementation
   {
     // received a disassociation notification from the device
     ieee154_address_t address;
-    call Debug.log(DEBUG_LEVEL_INFO, DISSASSOCIATE_RX, 0, 0, 0);
+
     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);
+    dbg_serial("DisassociateP", "Received disassociation request from %lx\n", (uint32_t) address.shortAddress);
     return frame;
   }
 
-/* ------------------- Defaults ------------------- */
+  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 (
                           uint64_t DeviceAddress,
                           ieee154_disassociation_reason_t DisassociateReason,
-                          ieee154_security_t *security
-                        ){}
+                          ieee154_security_t *security) {}
+
   default event void MLME_DISASSOCIATE.confirm    (
                           ieee154_status_t status,
                           uint8_t DeviceAddrMode,
                           uint16_t DevicePANID,
-                          ieee154_address_t DeviceAddress
-                        ){}
+                          ieee154_address_t DeviceAddress) {}
 
 }