]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/lib/mac/tkn154/AssociateP.nc
Added security parameter check to AssociateP; fixed ScanP to signal beacon with non...
[tinyos-2.x.git] / tos / lib / mac / tkn154 / AssociateP.nc
index c420f3201700c61f53f21b63018705e22e5a9d54..d5296c8706a381b63938b8a0005cd43964f1f0bf 100644 (file)
@@ -60,7 +60,6 @@ module AssociateP
     interface FrameUtility;
     interface IEEE154Frame as Frame;
     interface Get<uint64_t> as LocalExtendedAddress;
-    interface Ieee802154Debug as Debug;
   }
 }
 implementation
@@ -87,7 +86,7 @@ implementation
     return SUCCESS;
   }
 
-/* ------------------- MLME_ASSOCIATE Request ------------------- */
+  /* ------------------- MLME_ASSOCIATE Request ------------------- */
 
   command ieee154_status_t MLME_ASSOCIATE.request  (
                           uint8_t LogicalChannel,
@@ -96,8 +95,7 @@ implementation
                           uint16_t CoordPANID,
                           ieee154_address_t CoordAddress,
                           ieee154_CapabilityInformation_t CapabilityInformation,
-                          ieee154_security_t *security
-                        )
+                          ieee154_security_t *security)
   {
     ieee154_status_t status = IEEE154_SUCCESS;
     ieee154_txframe_t *txFrame=0;
@@ -112,11 +110,11 @@ implementation
       status = IEEE154_INVALID_PARAMETER;
     else if (m_associationOngoing || !(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) {
       m_assocRespStatus = IEEE154_NO_DATA;
       m_shortAddress = 0xFFFF;
       call MLME_SET.phyCurrentChannel(LogicalChannel);
@@ -146,13 +144,13 @@ implementation
       txFrame->payload = m_payloadAssocRequest;
       txFrame->payloadLen = 2;
       m_associationOngoing = TRUE;
-      if ((status = call AssociationRequestTx.transmit(txFrame)) != IEEE154_SUCCESS){
+      if ((status = call AssociationRequestTx.transmit(txFrame)) != IEEE154_SUCCESS) {
         m_associationOngoing = FALSE;
         call TxFramePool.put(txFrame);
         call TxControlPool.put(txControl);
       }
     }
-    call Debug.log(LEVEL_INFO, AssociateP_REQUEST, status, 0, 0);
+    dbg_serial("AssociationP", "MLME_ASSOCIATE.request -> result: %lu\n", (uint32_t) status);
     return status;
   }
 
@@ -160,15 +158,15 @@ implementation
   {
     call TxControlPool.put((ieee154_txcontrol_t*) ((uint8_t*) txFrame->header - offsetof(ieee154_txcontrol_t, header)));
     call TxFramePool.put(txFrame);
-    if (status != IEEE154_SUCCESS){
+    if (status != IEEE154_SUCCESS) {
+      dbg_serial("AssociationP", "transmitDone() failed!\n");
       m_associationOngoing = FALSE;
       signal MLME_ASSOCIATE.confirm(0xFFFF, status, 0);
     } else {
       call ResponseTimeout.startOneShot(call MLME_GET.macResponseWaitTime()*IEEE154_aBaseSuperframeDuration);
-      call Debug.log(LEVEL_INFO, AssociateP_SETTIMER
-          call MLME_GET.macResponseWaitTime()*IEEE154_aBaseSuperframeDuration, 0, 0);
+      dbg_serial("AssociationP", "transmitDone() ok, waiting for %lu\n"
+          (uint32_t) (call MLME_GET.macResponseWaitTime() * IEEE154_aBaseSuperframeDuration));
     }
-    call Debug.log(LEVEL_INFO, AssociateP_TXDONE, status, 0, 0);
   }
   
   event void ResponseTimeout.fired()
@@ -177,22 +175,24 @@ implementation
     if (!m_associationOngoing)
       return;
     // have not received an AssociationResponse yet, poll the coordinator now
+    dbg_serial("AssociationP", "Polling the coordinator for an AssociationResponse now...\n");
     if (m_coordAddrMode == ADDR_MODE_SHORT_ADDRESS)
       *((nxle_uint16_t*) &coordAddress) = call MLME_GET.macCoordShortAddress();
     else
       call FrameUtility.copyCoordExtendedAddressLE(coordAddress);
     if (call DataRequest.poll(m_coordAddrMode, call MLME_GET.macPANId(), 
-          coordAddress, ADDR_MODE_EXTENDED_ADDRESS) != IEEE154_SUCCESS){
+          coordAddress, ADDR_MODE_EXTENDED_ADDRESS) != IEEE154_SUCCESS) {
       m_shortAddress = 0xFFFF;
       m_assocRespStatus = IEEE154_TRANSACTION_OVERFLOW;
       signal DataRequest.pollDone();
+      dbg_serial("AssociationP", "Poll failed (locally)...\n");
     }
   }
 
   event message_t* AssociationResponseExtracted.received(message_t* frame, ieee154_txframe_t *txFrame)
   {
     uint8_t *payload = (uint8_t *) &frame->data;
-    if (m_associationOngoing){
+    if (m_associationOngoing) {
       m_shortAddress =  *((nxle_uint16_t*) (payload + 1));
       m_assocRespStatus = *(payload + 3);
     }
@@ -201,15 +201,16 @@ implementation
 
   event void DataRequest.pollDone()
   {
-    if (m_associationOngoing){
-      call Debug.log(LEVEL_INFO, AssociateP_POLL_DONE, m_payloadAssocRequest[0], m_assocRespStatus, 0);
+    if (m_associationOngoing) {
       call ResponseTimeout.stop();
       m_associationOngoing = FALSE;
       signal MLME_ASSOCIATE.confirm(m_shortAddress, m_assocRespStatus, 0);
+      dbg_serial("AssociationP", "confirm: %lx, %lu\n", 
+          (uint32_t) m_shortAddress, (uint32_t) m_assocRespStatus);
     }
   }
 
-/* ------------------- MLME_ASSOCIATE Response ------------------- */
+  /* ------------------- MLME_ASSOCIATE Response ------------------- */
 
   event message_t* AssociationRequestRx.received(message_t* frame)
   {
@@ -226,8 +227,7 @@ implementation
                           uint64_t deviceAddress,
                           uint16_t assocShortAddress,
                           ieee154_association_status_t status,
-                          ieee154_security_t *security
-                        )
+                          ieee154_security_t *security)
   {
     uint8_t i;
     ieee154_status_t txStatus = IEEE154_SUCCESS;
@@ -238,9 +238,11 @@ implementation
     for (i=0; i<MAX_PENDING_ASSOC_RESPONSES;i++)
       if (m_payloadAssocResponse[i][0] == S_IDLE)
         break;    
-    if (i == MAX_PENDING_ASSOC_RESPONSES || !(txFrame = call TxFramePool.get()))
+    if (security && security->SecurityLevel)
+      txStatus = IEEE154_UNSUPPORTED_SECURITY;
+    else if (i == MAX_PENDING_ASSOC_RESPONSES || !(txFrame = call TxFramePool.get()))
       txStatus = IEEE154_TRANSACTION_OVERFLOW;
-    else if (!(txControl = call TxControlPool.get())){
+    else if (!(txControl = call TxControlPool.get())) {
       call TxFramePool.put(txFrame);
       txStatus = IEEE154_TRANSACTION_OVERFLOW;
     } else {
@@ -263,7 +265,7 @@ implementation
       *((nxle_uint16_t*) &txFrame->payload[1]) = assocShortAddress;
       txFrame->payload[3] = status;
       txFrame->payloadLen = 4;
-      if ((txStatus = call AssociationResponseTx.transmit(txFrame)) != IEEE154_SUCCESS){
+      if ((txStatus = call AssociationResponseTx.transmit(txFrame)) != IEEE154_SUCCESS) {
         txFrame->payload[0] = S_IDLE;
         call TxFramePool.put(txFrame);
         call TxControlPool.put(txControl);
@@ -288,18 +290,16 @@ implementation
                           status, 0);
   }
 
-/* ------------------- Defaults ------------------- */
+  /* ------------------- Defaults ------------------- */
 
   default event void MLME_ASSOCIATE.indication (
                           uint64_t DeviceAddress,
                           ieee154_CapabilityInformation_t CapabilityInformation,
-                          ieee154_security_t *security
-                        ){}
+                          ieee154_security_t *security) {}
   default event void MLME_ASSOCIATE.confirm    (
                           uint16_t AssocShortAddress,
                           uint8_t status,
-                          ieee154_security_t *security
-                        ){}
+                          ieee154_security_t *security) {}
   default event void MLME_COMM_STATUS.indication (
                           uint16_t PANId,
                           uint8_t SrcAddrMode,
@@ -307,6 +307,5 @@ implementation
                           uint8_t DstAddrMode,
                           ieee154_address_t DstAddr,
                           ieee154_status_t status,
-                          ieee154_security_t *security
-                        ){}
+                          ieee154_security_t *security) {}
 }