]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/lib/mac/tkn154/DataP.nc
Merge TinyOS 2.1.1 into master.
[tinyos-2.x.git] / tos / lib / mac / tkn154 / DataP.nc
index 4e951b0ea9398495eb46c5481c10ac92c99c9c11..146c3b47fabffd4581670ff853956e64596b2e05 100644 (file)
@@ -42,7 +42,6 @@ module DataP
     interface MCPS_DATA; 
     interface MCPS_PURGE;
   } uses {
-    interface Get<bool> as IsSendingBeacons;
     interface FrameRx as CoordCapRx;
     interface FrameTx as DeviceCapTx;
     interface FrameTx as CoordCapTx;
@@ -80,8 +79,7 @@ implementation
                           message_t *frame,
                           uint8_t payloadLen,
                           uint8_t msduHandle,
-                          uint8_t txOptions
-                        )
+                          uint8_t txOptions)
   {
     uint8_t srcAddrMode = call Frame.getSrcAddrMode(frame);
     uint8_t dstAddrMode = call Frame.getDstAddrMode(frame);
@@ -89,9 +87,10 @@ implementation
     ieee154_status_t txStatus;
     ieee154_txframe_t *txFrame;
     uint8_t sfType=0;
-    uint8_t *mhr;
+    uint8_t *mhr, mhrLen = call Frame.getHeaderLength(frame);
 
-    if (payloadLen > call Packet.maxPayloadLength())
+    if (payloadLen > call Packet.maxPayloadLength() || 
+        mhrLen + payloadLen + 2 > IEEE154_aMaxPHYPacketSize) // extra 2 for MAC footer (CRC)
       txStatus = IEEE154_INVALID_PARAMETER;
     else if ((!srcAddrMode && !dstAddrMode) || 
         (srcAddrMode > ADDR_MODE_EXTENDED_ADDRESS || dstAddrMode > ADDR_MODE_EXTENDED_ADDRESS) ||
@@ -106,7 +105,7 @@ implementation
       txFrame->metadata = &((message_metadata_t*) frame->metadata)->ieee154;
       txFrame->payloadLen = payloadLen;
       mhr = txFrame->header->mhr;
-      txFrame->headerLen = call Frame.getHeaderLength(frame);
+      txFrame->headerLen = mhrLen;
       mhr[MHR_INDEX_FC1] &= ~(FC1_FRAMETYPE_MASK | FC1_FRAME_PENDING | FC1_ACK_REQUEST);
       mhr[MHR_INDEX_FC1] |= FC1_FRAMETYPE_DATA;
       if (txOptions & TX_OPTIONS_ACK)
@@ -123,12 +122,12 @@ implementation
       // coordinator address in the PIB, if they match the frame is
       // sent in the incoming sf otherwise in the outgoing sf
       call Frame.getDstAddr(frame, &dstAddr);
-      if (dstAddrMode == ADDR_MODE_SHORT_ADDRESS){
+      if (dstAddrMode == ADDR_MODE_SHORT_ADDRESS) {
         if (dstAddr.shortAddress == call MLME_GET.macCoordShortAddress())
           sfType = INCOMING_SUPERFRAME;
         else
           sfType = OUTGOING_SUPERFRAME;
-      } else if (dstAddrMode == ADDR_MODE_EXTENDED_ADDRESS){
+      } else if (dstAddrMode == ADDR_MODE_EXTENDED_ADDRESS) {
         if (dstAddr.extendedAddress == call MLME_GET.macCoordExtendedAddress())
           sfType = INCOMING_SUPERFRAME;
         else
@@ -137,7 +136,7 @@ implementation
         sfType = INCOMING_SUPERFRAME;
 
       // GTS?
-      if (txOptions & TX_OPTIONS_GTS){
+      if (txOptions & TX_OPTIONS_GTS) {
         if (sfType == INCOMING_SUPERFRAME)
           txStatus = call DeviceCfpTx.transmit(txFrame);
         else
@@ -145,9 +144,8 @@ implementation
 
       // indirect transmission?
       } else if ((txOptions & TX_OPTIONS_INDIRECT) && 
-          call IsSendingBeacons.get() && 
-          (dstAddrMode >= ADDR_MODE_SHORT_ADDRESS)){
-        if (dstAddrMode == ADDR_MODE_SHORT_ADDRESS && dstAddr.shortAddress == 0xFFFF){
+          (dstAddrMode >= ADDR_MODE_SHORT_ADDRESS)) {
+        if (dstAddrMode == ADDR_MODE_SHORT_ADDRESS && dstAddr.shortAddress == 0xFFFF) {
           mhr[MHR_INDEX_FC1] &= ~FC1_ACK_REQUEST;
           txStatus = call BroadcastTx.transmit(txFrame);
         } else
@@ -160,7 +158,7 @@ implementation
         else
           txStatus = call CoordCapTx.transmit(txFrame);
 
-      if (txStatus != IEEE154_SUCCESS){
+      if (txStatus != IEEE154_SUCCESS) {
         call TxFramePool.put(txFrame);
       }
     }
@@ -168,8 +166,7 @@ implementation
   }
 
   command ieee154_status_t MCPS_PURGE.request  (
-                          uint8_t msduHandle
-                        )
+                          uint8_t msduHandle)
   {
     if (call PurgeDirect.purge(msduHandle) == IEEE154_SUCCESS ||
         call PurgeIndirect.purge(msduHandle) == IEEE154_SUCCESS ||
@@ -222,7 +219,7 @@ implementation
 
   message_t* dataReceived(message_t* frame)
   {
-    return signal MCPS_DATA.indication( frame );
+    return signal MCPS_DATA.indication(frame);
   }
 
   void finishTxTransaction(ieee154_txframe_t *txFrame, ieee154_status_t status)
@@ -230,6 +227,7 @@ implementation
     uint8_t handle = txFrame->handle;
     uint32_t txTime = txFrame->metadata->timestamp;
     message_t *msg = (message_t*) ((uint8_t*) txFrame->header - offsetof(message_t, header));
+
     call TxFramePool.put(txFrame);
     signal MCPS_DATA.confirm(msg, handle, status, txTime);
   }
@@ -269,10 +267,10 @@ implementation
                           message_t *msg,
                           uint8_t msduHandle,
                           ieee154_status_t status,
-                          uint32_t Timestamp
-                        ){}
+                          uint32_t Timestamp) {}
 
-  default event message_t* MCPS_DATA.indication ( message_t* frame ){ return frame; }
-  default command ieee154_status_t DeviceCfpTx.transmit(ieee154_txframe_t *data){return IEEE154_INVALID_GTS;}
-  default command ieee154_status_t CoordCfpTx.transmit(ieee154_txframe_t *data){return IEEE154_INVALID_GTS;}
+  default event message_t* MCPS_DATA.indication(message_t* frame) { return frame; }
+  default command ieee154_status_t DeviceCfpTx.transmit(ieee154_txframe_t *data) {return IEEE154_INVALID_GTS;}
+  default command ieee154_status_t BroadcastTx.transmit(ieee154_txframe_t *data) {return IEEE154_INVALID_PARAMETER;}
+  default command ieee154_status_t CoordCfpTx.transmit(ieee154_txframe_t *data) {return IEEE154_INVALID_GTS;}
 }