]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
The big interface switchover for Packet, Send, Receive, and AMSend.
authorscipio <scipio>
Thu, 13 Sep 2007 23:10:14 +0000 (23:10 +0000)
committerscipio <scipio>
Thu, 13 Sep 2007 23:10:14 +0000 (23:10 +0000)
68 files changed:
apps/AntiTheft/Nodes/AntiTheftC.nc
apps/AntiTheft/Root/AntiTheftRootC.nc
apps/MViz/MVizC.nc
apps/MultihopOscilloscope/MultihopOscilloscopeC.nc
apps/MultihopOscilloscopeLqi/MultihopOscilloscopeC.nc
apps/Oscilloscope/OscilloscopeC.nc
apps/RadioCountToLeds/RadioCountToLedsC.nc
apps/RadioSenseToLeds/RadioSenseToLedsC.nc
apps/tests/RadioStress/RadioStressC.nc
apps/tests/TestLocalTime/TestLocalTimeC.nc
apps/tests/TestMultihopLqi/MultihopOscilloscopeC.nc
apps/tests/TestNetwork/TestNetworkC.nc
apps/tests/TestOscilloscopeLQI/MultihopOscilloscopeC.nc
apps/tests/TestSerial/TestSerialC.nc
apps/tests/TestSerialBandwidth/TestSerialC.nc
apps/tests/cc2420/LplBroadcastCountToLeds/RadioCountToLedsC.nc
apps/tests/cc2420/LplBroadcastPeriodicDelivery/TestPeriodicP.nc
apps/tests/cc2420/LplUnicastPeriodicDelivery/TestPeriodicP.nc
apps/tests/cc2420/RssiToSerial/RssiToSerialP.nc
apps/tests/cc2420/TestPacketLink/TestPacketLinkP.nc
apps/tests/cc2420/TxThroughput/TxThroughputP.nc
apps/tests/eyesIFX/RadioCountToFlash/RadioCountToFlashC.nc
apps/tests/mica2/mts300/TestMts300P.nc
apps/tests/mts300/PhotoTemp/OscilloscopeC.nc
apps/tests/storage/Block/RandRWC.nc
apps/tests/storage/CircularLog/RandRWC.nc
apps/tests/storage/Config/RandRWC.nc
apps/tests/storage/SyncLog/SyncLogC.nc
apps/tutorials/BlinkToRadio/BlinkToRadioC.nc
tos/chips/cc1000/CC1000ActiveMessageP.nc
tos/chips/cc1000/CC1000SendReceiveP.nc
tos/chips/cc2420/CC2420ActiveMessageP.nc
tos/chips/cc2420/csma/CC2420CsmaP.nc
tos/chips/cc2420/link/PacketLinkP.nc
tos/chips/cc2420/lpl/DefaultLplP.nc
tos/chips/cc2420/receive/CC2420ReceiveP.nc
tos/chips/cc2420/unique/UniqueReceiveP.nc
tos/chips/cc2420/unique/UniqueSendP.nc
tos/chips/tda5250/Tda5250ActiveMessageP.nc
tos/chips/tda5250/mac/CsmaMacP.nc
tos/chips/xe1205/XE1205ActiveMessageP.nc
tos/chips/xe1205/XE1205SendReceiveP.nc
tos/interfaces/AMSend.nc
tos/interfaces/Packet.nc
tos/interfaces/Receive.nc
tos/interfaces/Send.nc
tos/lib/byte_radio/LinkLayerP.nc
tos/lib/byte_radio/PacketSerializerP.nc
tos/lib/net/Deluge/DelugePageTransferP.nc
tos/lib/net/Deluge/FlashVolumeManager/FlashVolumeManagerP.nc
tos/lib/net/Deluge/ObjectTransferP.nc
tos/lib/net/DisseminationEngineImplP.nc
tos/lib/net/SendVirtualizerP.nc
tos/lib/net/UARTDebugSenderP.nc
tos/lib/net/ctp/CtpForwardingEngineP.nc
tos/lib/net/ctp/CtpRoutingEngineP.nc
tos/lib/net/le/LinkEstimatorP.nc
tos/lib/net/lqi/CollectionSenderP.nc
tos/lib/net/lqi/LqiForwardingEngineP.nc
tos/lib/net/lqi/LqiRoutingEngineP.nc
tos/lib/printf/PrintfP.nc
tos/lib/serial/SerialActiveMessageP.nc
tos/lib/serial/SerialDispatcherP.nc
tos/lib/tossim/SerialActiveMessageC.nc
tos/lib/tossim/TossimActiveMessageC.nc
tos/platforms/eyesIFX/ActiveMessageFilterC.nc
tos/system/AMQueueEntryP.nc
tos/system/AMQueueImplP.nc

index 8696be00e094e332c7102c47b7b619bf02578151..6245b6d9de6a9d4771b2c2ba14df21dfc060ceea 100644 (file)
@@ -103,11 +103,12 @@ implementation
        /* Report the identity of this node, using the collection protocol */
 
        /* Get the payload part of alertMsg and fill in our data */
-       alert_t *newAlert = call AlertRoot.getPayload(&alertMsg);
-       newAlert->stolenId = TOS_NODE_ID;
-
-       /* and send it... */
-       check(call AlertRoot.send(&alertMsg, sizeof *newAlert));
+       alert_t *newAlert = call AlertRoot.getPayload(&alertMsg, sizeof(alert_t));
+       if (newAlert != NULL) {
+         newAlert->stolenId = TOS_NODE_ID;
+         /* and send it... */
+         check(call AlertRoot.send(&alertMsg, sizeof *newAlert));
+       }
       }
   }
 
index 7a9a2630a5f1943de48676fb9dd22847e2bb3cbc..896bc812a89d332afbeda66a391cc993f026316a 100644 (file)
@@ -93,11 +93,12 @@ implementation
       {
        /* Copy payload (newAlert) from collection system to our serial
           message buffer (fwdAlert), then send our serial message */
-       alert_t *fwdAlert = call AlertsForward.getPayload(&fwdMsg);
-
-       *fwdAlert = *newAlert;
-       if (call AlertsForward.send(AM_BROADCAST_ADDR, &fwdMsg, sizeof *fwdAlert) == SUCCESS)
-         fwdBusy = TRUE;
+       alert_t *fwdAlert = call AlertsForward.getPayload(&fwdMsg, sizeof(alert_t));
+       if (fwdAlert != NULL) {
+         *fwdAlert = *newAlert;
+         if (call AlertsForward.send(AM_BROADCAST_ADDR, &fwdMsg, sizeof *fwdAlert) == SUCCESS)
+           fwdBusy = TRUE;
+       }
       }
     return msg;
   }
index 6719d8f0fe8ae49fd1322fc9b6a213d7d1f61fd6..82f39986de91ab96cbc999904790bb7f1bf99a75 100644 (file)
@@ -125,8 +125,8 @@ implementation {
   Receive.receive(message_t* msg, void *payload, uint8_t len) {
     if (uartbusy == FALSE) {
       mviz_msg_t* in = (mviz_msg_t*)payload;
-      mviz_msg_t* out = (mviz_msg_t*)call SerialSend.getPayload(&uartbuf);
-      if (len != sizeof(mviz_msg_t)) {
+      mviz_msg_t* out = (mviz_msg_t*)call SerialSend.getPayload(&uartbuf, sizeof(mviz_msg_t));
+      if (out == NULL) {
        return msg;
       }
       else {
@@ -177,7 +177,11 @@ implementation {
   */
   event void Timer.fired() {
     if (!sendbusy) {
-      mviz_msg_t *o = (mviz_msg_t *)call Send.getPayload(&sendbuf);
+      mviz_msg_t *o = (mviz_msg_t *)call Send.getPayload(&sendbuf, sizeof(mviz_msg_t));
+      if (o == NULL) {
+       fatal_problem();
+       return;
+      }
       memcpy(o, &local, sizeof(local));
       if (call Send.send(&sendbuf, sizeof(local)) == SUCCESS)
        sendbusy = TRUE;
index fff54d7ca7bc5f9988dd17022332573ed6845f9d..fab099031e6077b7c5f6c489762187276c11c7cf 100644 (file)
@@ -128,8 +128,8 @@ implementation {
     oscilloscope_t* in = (oscilloscope_t*)payload;
     oscilloscope_t* out;
     if (uartbusy == FALSE) {
-      out = (oscilloscope_t*)call SerialSend.getPayload(&uartbuf);
-      if (len != sizeof(oscilloscope_t)) {
+      out = (oscilloscope_t*)call SerialSend.getPayload(&uartbuf, sizeof(oscilloscope_t));
+      if (len != sizeof(oscilloscope_t) || out == NULL) {
        return msg;
       }
       else {
@@ -147,8 +147,11 @@ implementation {
         return msg;
       }
 
-      //Prepare message to be sent over the uart
-      out = (oscilloscope_t*)call SerialSend.getPayload(newmsg);
+      //Serial port busy, so enqueue.
+      out = (oscilloscope_t*)call SerialSend.getPayload(newmsg, sizeof(oscilloscope_t));
+      if (out == NULL) {
+       return msg;
+      }
       memcpy(out, in, sizeof(oscilloscope_t));
 
       if (call UARTQueue.enqueue(newmsg) != SUCCESS) {
@@ -224,7 +227,11 @@ implementation {
   event void Timer.fired() {
     if (reading == NREADINGS) {
       if (!sendbusy) {
-       oscilloscope_t *o = (oscilloscope_t *)call Send.getPayload(&sendbuf);
+       oscilloscope_t *o = (oscilloscope_t *)call Send.getPayload(&sendbuf, sizeof(oscilloscope_t));
+       if (o == NULL) {
+         fatal_problem();
+         return;
+       }
        memcpy(o, &local, sizeof(local));
        if (call Send.send(&sendbuf, sizeof(local)) == SUCCESS)
          sendbusy = TRUE;
index fff54d7ca7bc5f9988dd17022332573ed6845f9d..17edb6b78c6c8d50c5a27e19f47c04039981a63c 100644 (file)
@@ -128,8 +128,9 @@ implementation {
     oscilloscope_t* in = (oscilloscope_t*)payload;
     oscilloscope_t* out;
     if (uartbusy == FALSE) {
-      out = (oscilloscope_t*)call SerialSend.getPayload(&uartbuf);
-      if (len != sizeof(oscilloscope_t)) {
+      out = (oscilloscope_t*)call SerialSend.getPayload(&uartbuf, sizeof(oscilloscope_t));
+      if (out == NULL) {
+       fatal_problem();
        return msg;
       }
       else {
@@ -148,7 +149,11 @@ implementation {
       }
 
       //Prepare message to be sent over the uart
-      out = (oscilloscope_t*)call SerialSend.getPayload(newmsg);
+      out = (oscilloscope_t*)call SerialSend.getPayload(newmsg, sizeof(oscilloscope_t));
+      if (out == NULL) {
+       fatal_problem();
+       return msg;
+      }
       memcpy(out, in, sizeof(oscilloscope_t));
 
       if (call UARTQueue.enqueue(newmsg) != SUCCESS) {
@@ -224,7 +229,11 @@ implementation {
   event void Timer.fired() {
     if (reading == NREADINGS) {
       if (!sendbusy) {
-       oscilloscope_t *o = (oscilloscope_t *)call Send.getPayload(&sendbuf);
+       oscilloscope_t *o = (oscilloscope_t *)call Send.getPayload(&sendbuf, sizeof(oscilloscope_t));
+       if (o == NULL) {
+         fatal_problem();
+         return;
+       }
        memcpy(o, &local, sizeof(local));
        if (call Send.send(&sendbuf, sizeof(local)) == SUCCESS)
          sendbusy = TRUE;
index a198db8f8d8b4a5218be9d838aeedd8c791b1405..77cca21055c5c7adbd9a62104bf3e034744e47c1 100644 (file)
@@ -101,7 +101,9 @@ implementation
       {
        if (!sendbusy && sizeof local <= call AMSend.maxPayloadLength())
          {
-           memcpy(call AMSend.getPayload(&sendbuf), &local, sizeof local);
+           // Don't need to check for null because we've already checked length
+           // above
+           memcpy(call AMSend.getPayload(&sendbuf, sizeof(local)), &local, sizeof local);
            if (call AMSend.send(AM_BROADCAST_ADDR, &sendbuf, sizeof local) == SUCCESS)
              sendbusy = TRUE;
          }
index d5f926f224cfdb7d15108f3b69d5ccbdb90755cb..fcc3c7c69ef5846b761cdc612cf891f511d672fe 100644 (file)
@@ -85,8 +85,8 @@ implementation {
       return;
     }
     else {
-      radio_count_msg_t* rcm = (radio_count_msg_t*)call Packet.getPayload(&packet, NULL);
-      if (call Packet.maxPayloadLength() < sizeof(radio_count_msg_t)) {
+      radio_count_msg_t* rcm = (radio_count_msg_t*)call Packet.getPayload(&packet, sizeof(radio_count_msg_t));
+      if (rcm == NULL) {
        return;
       }
 
index fab38b1392884aa4a1f2dd27c3c933adcea00ef1..2762d59da96f001707dec14efdd11ff18d77c63e 100644 (file)
@@ -82,8 +82,8 @@ implementation {
     else {
       radio_sense_msg_t* rsm;
 
-      rsm = (radio_sense_msg_t*)call Packet.getPayload(&packet, NULL);
-      if (call Packet.maxPayloadLength() < sizeof(radio_sense_msg_t)) {
+      rsm = (radio_sense_msg_t*)call Packet.getPayload(&packet, sizeof(radio_sense_msg_t));
+      if (rsm == NULL) {
        return;
       }
       rsm->error = result;
index 30bc6592dc24c03b68c9484309c43ae234568a7c..e03a9b261206bcad782d145f4deec0267502c9ea 100644 (file)
@@ -75,7 +75,7 @@ implementation {
   task void sendTask();
 
   void sendPacket() {
-    RadioCountMsg* rcm = (RadioCountMsg*)call Packet.getPayload(&packet, NULL);
+    RadioCountMsg* rcm = (RadioCountMsg*)call Packet.getPayload(&packet, sizeof(RadioCountMsg));
     if (locked) {return;}
     rcm->counter = txCounter;
     if (call AMSend.send(AM_BROADCAST_ADDR, &packet, 2) == SUCCESS) {
index a0093345d2fd923e4581e488d8e67d74d04427e3..f2053570c04f6ec6bbc5c9c6849596fa88635976 100644 (file)
@@ -73,7 +73,7 @@ implementation {
   event void MilliTimer.fired() {
     if (!locked)
       {
-       test_localtime_msg_t* rcm = (test_localtime_msg_t*)call AMSend.getPayload(&packet);
+       test_localtime_msg_t* rcm = (test_localtime_msg_t*)call AMSend.getPayload(&packet, sizeof(test_localtime_msg_t));
        if (call AMSend.maxPayloadLength() < sizeof(test_localtime_msg_t))
          return;
 
index 55351c5207936726babb6fb34cd5700020ac2085..aed5a437752e7f584b622876e5987174bd93eb2d 100644 (file)
@@ -136,8 +136,8 @@ implementation {
       dbg_clear("App", "\n");
     }
     if (uartbusy == FALSE) {
-      out = (oscilloscope_t*)call SerialSend.getPayload(&uartbuf);
-      if (len != sizeof(oscilloscope_t)) {
+      out = (oscilloscope_t*)call SerialSend.getPayload(&uartbuf, sizeof(oscilloscope_t));
+      if (out == NULL || call Packet.payloadLength(&uartbuf) != sizeof(oscilloscope_t)) {
        return msg;
       }
       else {
@@ -156,7 +156,10 @@ implementation {
       }
 
       //Prepare message to be sent over the uart
-      out = (oscilloscope_t*)call SerialSend.getPayload(newmsg);
+      out = (oscilloscope_t*)call SerialSend.getPayload(newmsg, sizeof(oscilloscope_t));
+      if (out == NULL) {
+       return;
+      }
       memcpy(out, in, sizeof(oscilloscope_t));
 
       if (call UARTQueue.enqueue(newmsg) != SUCCESS) {
@@ -232,7 +235,10 @@ implementation {
   event void Timer.fired() {
     if (reading == NREADINGS) {
       if (!sendbusy) {
-       oscilloscope_t *o = (oscilloscope_t *)call Send.getPayload(&sendbuf);
+       oscilloscope_t *o = (oscilloscope_t *)call Send.getPayload(&sendbuf, sizeof(oscilloscope_t));
+       if (o == NULL) {
+         return;
+       }
        memcpy(o, &local, sizeof(local));
        if (call Send.send(&sendbuf, sizeof(local)) == SUCCESS) {
           dbg("App", "Sending a packet.\n");
index 9785967b87e802168e3864a79db396636092fd15..cc05e47bd100fcacede570191cc630b029f8e6a8 100644 (file)
@@ -84,7 +84,7 @@ implementation {
 
    
   void sendMessage() {
-    TestNetworkMsg* msg = (TestNetworkMsg*)call Send.getPayload(&packet);
+    TestNetworkMsg* msg = (TestNetworkMsg*)call Send.getPayload(&packet, sizeof(TestNetworkMsg));
     uint16_t metric;
     am_addr_t parent;
 
@@ -162,7 +162,7 @@ implementation {
    else if (!uartbusy) {
      message_t* msg = call Queue.dequeue();
      dbg("Traffic", "Sending packet to UART.\n");
-     if (call UARTSend.send(0xffff, msg, call Receive.payloadLength(msg)) == SUCCESS) {
+     if (call UARTSend.send(0xffff, msg, call Packet.payloadLength(msg)) == SUCCESS) {
        uartbusy = TRUE;
      }
      else {
index 9e9e8aae1ef07eea07c9ed8205da39d035d90ae3..ad51c6ee9e96c711bb5d1affda520d04d002cf84 100644 (file)
@@ -129,8 +129,8 @@ implementation {
     oscilloscope_t* out;
     call Leds.led1Toggle();
     if (uartbusy == FALSE) {
-      out = (oscilloscope_t*)call SerialSend.getPayload(&uartbuf);
-      if (len != sizeof(oscilloscope_t)) {
+      out = (oscilloscope_t*)call SerialSend.getPayload(&uartbuf, sizeof(oscilloscope_t));
+      if (call Packet.payloadLength(msg) != sizeof(oscilloscope_t)) {
        return msg;
       }
       else {
@@ -149,7 +149,10 @@ implementation {
       }
 
       //Prepare message to be sent over the uart
-      out = (oscilloscope_t*)call SerialSend.getPayload(newmsg);
+      out = (oscilloscope_t*)call SerialSend.getPayload(newmsg, sizeof(oscilloscope_t));
+      if (out == NULL) {
+       return msg;
+      }
       memcpy(out, in, sizeof(oscilloscope_t));
 
       if (call UARTQueue.enqueue(newmsg) != SUCCESS) {
@@ -226,7 +229,10 @@ implementation {
     if (TOS_NODE_ID % 500 == 0) {return;}
     if (reading == NREADINGS) {
       if (!sendbusy) {
-       oscilloscope_t *o = (oscilloscope_t *)call Send.getPayload(&sendbuf);
+       oscilloscope_t *o = (oscilloscope_t *)call Send.getPayload(&sendbuf, sizeof(oscilloscope_t));
+       if (o == NULL) {
+         return;
+       }
        memcpy(o, &local, sizeof(local));
        if (call Send.send(&sendbuf, sizeof(local)) == SUCCESS)
          sendbusy = TRUE;
index 3ced9c32c711515ec94d931aa5de485666983db7..8278c5894250a34d1cf2ef3140913b636fb5af7b 100644 (file)
@@ -71,7 +71,8 @@ implementation {
       return;
     }
     else {
-      test_serial_msg_t* rcm = (test_serial_msg_t*)call Packet.getPayload(&packet, NULL);
+      test_serial_msg_t* rcm = (test_serial_msg_t*)call Packet.getPayload(&packet, sizeof(test_serial_msg_t));
+      if (rcm == NULL) {return;}
       if (call Packet.maxPayloadLength() < sizeof(test_serial_msg_t)) {
        return;
       }
index b361e3ab62066a75ef28e45dcab562ce7e4121f7..671210b3846bdcf395fd46e8eb632b01878dd71b 100644 (file)
@@ -83,8 +83,8 @@ implementation {
       return;
     }
     else {
-      TestSerialMsg* rcm = (TestSerialMsg*)call Packet.getPayload(&packet, NULL);
-      if (call Packet.maxPayloadLength() < sizeof(TestSerialMsg)) {
+      TestSerialMsg* rcm = (TestSerialMsg*)call Packet.getPayload(&packet, sizeof(TestSerialMsg));
+      if (rcm == NULL || call Packet.maxPayloadLength() < sizeof(TestSerialMsg)) {
        return;
       }
 
@@ -128,7 +128,10 @@ implementation {
       locked = FALSE;
       // as fast as possible
       if (afap){
-        TestSerialMsg* rcm = (TestSerialMsg*)call Packet.getPayload(&packet,NULL);
+        TestSerialMsg* rcm = (TestSerialMsg*)call Packet.getPayload(&packet, sizeof(TestSerialMsg));
+       if (rcm == NULL || call Packet.payloadLength(&packet) != sizeof(TestSerialMsg)) {
+         return;
+       }
         counter++;
         rcm->counter = counter;
         call Leds.led0Toggle();
index 0032148769c0feba76470dbe91193c71a77097db..34576fd14a3090d9f2d66f8c0c535a26633ba7e8 100644 (file)
@@ -88,7 +88,7 @@ implementation {
       return;
     }
     else {
-      radio_count_msg_t* rcm = (radio_count_msg_t*)call Packet.getPayload(&packet, NULL);
+      radio_count_msg_t* rcm = (radio_count_msg_t*)call Packet.getPayload(&packet, sizeof(radio_count_msg_t));
       if (call Packet.maxPayloadLength() < sizeof(radio_count_msg_t)) {
         return;
       }
index fa5c1917f6629f7c14c1a105b0e594c100683389..1e58382d53071ddd40c7f48860f303ab7dfeea48 100644 (file)
@@ -118,7 +118,7 @@ implementation {
   
   /**************** Tasks ****************/
   task void send() {
-    TestPeriodicMsg *periodicMsg = (TestPeriodicMsg *) call Packet.getPayload(&fullMsg, NULL);
+    TestPeriodicMsg *periodicMsg = (TestPeriodicMsg *) call Packet.getPayload(&fullMsg, sizeof(TestPeriodicMsg));
     periodicMsg->count = count;
     call LowPowerListening.setRxSleepInterval(&fullMsg, 1000);
     if(call AMSend.send(AM_BROADCAST_ADDR, &fullMsg, sizeof(TestPeriodicMsg)) != SUCCESS) {
index ddb17abb5e6ab4f243c0129bdc24fb8691d8abd9..b6b33489aa75e081934baeb149744005e039d0f2 100644 (file)
@@ -104,7 +104,7 @@ implementation {
   
   /**************** Tasks ****************/
   task void send() {
-    TestPeriodicMsg *periodicMsg = (TestPeriodicMsg *) call Packet.getPayload(&fullMsg, NULL);
+    TestPeriodicMsg *periodicMsg = (TestPeriodicMsg *) call Packet.getPayload(&fullMsg, sizeof(TestPeriodicMsg));
     periodicMsg->count = count;
     call LowPowerListening.setRxSleepInterval(&fullMsg, 1000);
     if(call AMSend.send(0, &fullMsg, sizeof(TestPeriodicMsg)) != SUCCESS) {
index 0b662ff5300bea7db66b60bd9179241299f19ea1..0ee4bf3b037d8f7150f44894806843e9fb0238c1 100644 (file)
@@ -154,7 +154,7 @@ implementation {
       return;
     }
     else {
-      rssi_serial_msg_t* rsm = (rssi_serial_msg_t*)call Packet.getPayload(&packet, NULL);
+      rssi_serial_msg_t* rsm = (rssi_serial_msg_t*)call Packet.getPayload(&packet, sizeof(rssi_serial_msg_t));
       
       if (call Packet.maxPayloadLength() < sizeof(rssi_serial_msg_t)) {
            return;
index 8c6049211372a6713fc333e53ce9a6e45c84e262..abb08d2bf970a659886fd5c5ff7567b230564b5d 100644 (file)
@@ -148,7 +148,7 @@ implementation {
       call Leds.led0Toggle();
     }
     
-    ((PacketLinkMsg *) call AMSend.getPayload(&myMsg))->count = count[0];
+    ((PacketLinkMsg *) call AMSend.getPayload(&myMsg, sizeof(PacketLinkMsg)))->count = count[0];
     call Timer.startOneShot(50);
   }
   
@@ -166,11 +166,11 @@ implementation {
     }
     
     if(linkMsg->count != count[source]) {
-      ((PacketLinkMsg *) (call SerialAMSend.getPayload(&serialMsg)))->src = source;
+      ((PacketLinkMsg *) (call SerialAMSend.getPayload(&serialMsg, sizeof(PacketLinkMsg))))->src = source;
       if(linkMsg->count > count[source]) {
-        ((PacketLinkMsg *) (call SerialAMSend.getPayload(&serialMsg)))->cmd = CMD_DROPPED_PACKET;
+        ((PacketLinkMsg *) (call SerialAMSend.getPayload(&serialMsg, sizeof(PacketLinkMsg))))->cmd = CMD_DROPPED_PACKET;
       } else {
-        ((PacketLinkMsg *) (call SerialAMSend.getPayload(&serialMsg)))->cmd = CMD_DUPLICATE_PACKET;
+        ((PacketLinkMsg *) (call SerialAMSend.getPayload(&serialMsg, sizeof(PacketLinkMsg))))->cmd = CMD_DUPLICATE_PACKET;
       }
       post sendSerial();
       
index 31580cd674ee40b15e8196ee2f19a683fec5de27..2c91487a5328ff5295e7db3b890b3f486829485d 100644 (file)
@@ -105,7 +105,7 @@ implementation {
   
   /***************** Timer Events ***************/
   event void Timer.fired() {
-    ((ThroughputMsg *) call SerialAMSend.getPayload(&serialMsg))->packetsPerSecond = packetsPerSecond;
+    ((ThroughputMsg *) call SerialAMSend.getPayload(&serialMsg, sizeof(ThroughputMsg)))->packetsPerSecond = packetsPerSecond;
     packetsPerSecond = 0;
     post sendSerial();
   }
index 0ec35e6769e8f5c59ad39fc3e5855a2423e08c52..bbbabc77da61fff912b33887826d3df10fc6fcbb 100644 (file)
@@ -115,8 +115,8 @@ implementation {
       return;
     }
     else {
-      RadioCountMsg* rcm = (RadioCountMsg*)call Packet.getPayload(&packet, NULL);
-      if (call Packet.maxPayloadLength() < sizeof(RadioCountMsg)) {
+      RadioCountMsg* rcm = (RadioCountMsg*)call Packet.getPayload(&packet, sizeof(rcm));
+      if (rcm == NULL || call Packet.maxPayloadLength() < sizeof(RadioCountMsg)) {
         return;
       }
       ++sendingCounter;
index 334c032f95108db32f2a12de64a5583566d96925..f0d011da0fd4fc96564f33fdba3ffe62008eb313 100644 (file)
@@ -98,7 +98,11 @@ implementation
     sending_packet = FALSE;\r
     packet_ready = FALSE;\r
     state = STATE_IDLE;\r
-    pMsg = (Mts300Msg*)call RadioPacket.getPayload(&packet, NULL);\r
+    pMsg = (Mts300Msg*)call RadioPacket.getPayload(&packet, sizeof(Mts300Msg));\r
+    if (pMsg == NULL) {\r
+      call Leds.led0On();\r
+      return;\r
+    }\r
 \r
     // Zero out the accelerometer, chrl@20070213\r
     accel_ave_x = 0;\r
index 277fb0314405af4199f947f54a9fbea1169f478a..6ba42ce04dfdfbe3b230db6321f5f1a86ef47411 100644 (file)
@@ -102,7 +102,7 @@ implementation
       {
        if (!sendbusy && sizeof local <= call AMSend.maxPayloadLength())
          {
-           memcpy(call AMSend.getPayload(&sendbuf), &local, sizeof local);
+           memcpy(call AMSend.getPayload(&sendbuf, sizeof(local)), &local, sizeof local);
            if (call AMSend.send(AM_BROADCAST_ADDR, &sendbuf, sizeof local) == SUCCESS)
              sendbusy = TRUE;
          }
index 1744f0611d60318f10816955103bd44fed0a21f5..d3afad7f87a3697ab4c132f5031e52e3011c3352 100644 (file)
@@ -65,7 +65,7 @@ implementation {
   void done();
 
   void report(error_t e) {
-    uint8_t *msg = call AMSend.getPayload(&reportmsg);
+    uint8_t *msg = call AMSend.getPayload(&reportmsg, 1);
 
     msg[0] = e;
     if (call AMSend.send(AM_BROADCAST_ADDR, &reportmsg, 1) != SUCCESS)
index 58ce0b03dfbac8a8dede375fdac759c33d22832e..db69deab546d652256a2eef5e6b84b068983fecf 100644 (file)
@@ -65,7 +65,7 @@ implementation {
   message_t reportmsg;
 
   void report(error_t e) {
-    uint8_t *msg = call AMSend.getPayload(&reportmsg);
+    uint8_t *msg = call AMSend.getPayload(&reportmsg, 1);
 
     msg[0] = e;
     if (call AMSend.send(AM_BROADCAST_ADDR, &reportmsg, 1) != SUCCESS)
index d55ddb7630916d642fef0c5b20035e84a773baa2..829c99ced7fb9a2421553afc12cf837a6203a3ca 100644 (file)
@@ -70,7 +70,7 @@ implementation {
   }
   
   void report(error_t e) {
-    uint8_t *msg = call AMSend.getPayload(&reportmsg);
+    uint8_t *msg = call AMSend.getPayload(&reportmsg, 1);
 
     msg[0] = e;
     if (call AMSend.send(AM_BROADCAST_ADDR, &reportmsg, 1) != SUCCESS)
index 8a8aad602d96149312abe2bec20e6c5693e61a9c..3bd9b1ffdce21e46197795138ebb94fc8527dcfc 100644 (file)
@@ -101,7 +101,7 @@ implementation {
     if (!busy)
       {
        SenseStoreRadioMsg* ssrpkt =
-         (SenseStoreRadioMsg*)(call AMSend.getPayload(&pkt));
+         (SenseStoreRadioMsg*)(call AMSend.getPayload(&pkt, sizeof(SenseStoreRadioMsg)));
        ssrpkt->nodeid = TOS_NODE_ID;
        ssrpkt->payloadData = data;
        if (call AMSend.send(AM_BROADCAST_ADDR, &pkt, sizeof(SenseStoreRadioMsg)) == SUCCESS)
index 118696656233d963e69326a1521680cfb1476b83..8dfcd0e91d8e151d3bff974c5b640405fa830d6c 100644 (file)
@@ -90,7 +90,10 @@ implementation {
     counter++;
     if (!busy) {
       BlinkToRadioMsg* btrpkt = 
-       (BlinkToRadioMsg*)(call Packet.getPayload(&pkt, NULL));
+       (BlinkToRadioMsg*)(call Packet.getPayload(&pkt, sizeof(BlinkToRadioMsg)));
+      if (btrpkt == NULL) {
+       return;
+      }
       btrpkt->nodeid = TOS_NODE_ID;
       btrpkt->counter = counter;
       if (call AMSend.send(AM_BROADCAST_ADDR, 
index a7a02da337a678d3ee34b02391bc041bb7176898..118c8a810fb8667f2a168a65d650c15f8c28a1a2 100644 (file)
@@ -78,8 +78,8 @@ implementation {
     return call Packet.maxPayloadLength();
   }
 
-  command void* AMSend.getPayload[am_id_t id](message_t* m) {
-    return call Packet.getPayload(m, NULL);
+  command void* AMSend.getPayload[am_id_t id](message_t* m, uint8_t len) {
+    return call Packet.getPayload(m, len);
   }
 
   /* Receiving a packet */
@@ -93,22 +93,6 @@ implementation {
     }
   }
   
-  command void* Receive.getPayload[am_id_t id](message_t* m, uint8_t* len) {
-    return call Packet.getPayload(m, len);
-  }
-
-  command uint8_t Receive.payloadLength[am_id_t id](message_t* m) {
-    return call Packet.payloadLength(m);
-  }
-  
-  command void* Snoop.getPayload[am_id_t id](message_t* m, uint8_t* len) {
-    return call Packet.getPayload(m, len);
-  }
-
-  command uint8_t Snoop.payloadLength[am_id_t id](message_t* m) {
-    return call Packet.payloadLength(m);
-  }
-
   command am_addr_t AMPacket.address() {
     return call amAddress();
   }
index e4e4d77d9d95ac26eefc87d5682404fb74615e62..31a2fc2c634a255efabffcdecf1221b778ebb62c 100644 (file)
@@ -632,13 +632,13 @@ implementation
     return TOSH_DATA_LENGTH;
   }
 
-  command void* Packet.getPayload(message_t *msg, uint8_t *len) {
-    if (len != NULL) {
-      cc1000_header_t *header = getHeader(msg);
-
-      *len = header->length;
+  command void* Packet.getPayload(message_t *msg, uint8_t len) {
+    if (len <= TOSH_DATA_LENGTH) {
+      return (void*)msg->data;
+    }
+    else {
+      return NULL;
     }
-    return (void*)msg->data;
   }
 
   async command error_t PacketAcknowledgements.requestAck(message_t *msg) {
@@ -649,20 +649,12 @@ implementation
     return FAIL;               /* We always ack */
   }
 
-  command void* Receive.getPayload(message_t *m, uint8_t *len) {
-    return call Packet.getPayload(m, len);
-  }
-
-  command uint8_t Receive.payloadLength(message_t *m) {
-    return call Packet.payloadLength(m);
-  }
-
   command uint8_t Send.maxPayloadLength() {
     return call Packet.maxPayloadLength();
   }
 
-  command void* Send.getPayload(message_t *m) {
-    return call Packet.getPayload(m, NULL);
+  command void* Send.getPayload(message_t *m, uint8_t len) {
+    return call Packet.getPayload(m, len);
   }
 
   async command bool PacketAcknowledgements.wasAcked(message_t *msg) {
index 0f93440446d7611663f45547d5c9500d215fee88..2cd35c88ef38e5f1e77f21d5f826b26bca7ce746 100644 (file)
@@ -77,28 +77,10 @@ implementation {
     return call Packet.maxPayloadLength();
   }
 
-  command void* AMSend.getPayload[am_id_t id](message_t* m) {
-    return call Packet.getPayload(m, NULL);
-  }
-
-  /***************** Receive Commands ****************/
-  command void* Receive.getPayload[am_id_t id](message_t* m, uint8_t* len) {
-    return call Packet.getPayload(m, len);
-  }
-
-  command uint8_t Receive.payloadLength[am_id_t id](message_t* m) {
-    return call Packet.payloadLength(m);
-  }
-  
-  /***************** Snoop Commands ****************/
-  command void* Snoop.getPayload[am_id_t id](message_t* m, uint8_t* len) {
+  command void* AMSend.getPayload[am_id_t id](message_t* m, uint8_t len) {
     return call Packet.getPayload(m, len);
   }
 
-  command uint8_t Snoop.payloadLength[am_id_t id](message_t* m) {
-    return call Packet.payloadLength(m);
-  }
-
   /***************** AMPacket Commands ****************/
   command am_addr_t AMPacket.address() {
     return call ActiveMessageAddress.amAddress();
@@ -169,11 +151,8 @@ implementation {
     return TOSH_DATA_LENGTH;
   }
   
-  command void* Packet.getPayload(message_t* msg, uint8_t* len) {
-    if (len != NULL) {
-      *len = call Packet.payloadLength(msg);
-    }
-    return msg->data;
+  command void* Packet.getPayload(message_t* msg, uint8_t len) {
+    return call SubSend.getPayload(msg, len);
   }
 
   
index fe497824af3b4d4040c4aab3a4f5ee48211b14e2..9dada4cae5bacfa9ae302ffb80791bad03da1e61 100644 (file)
@@ -155,8 +155,13 @@ implementation {
 
   }
 
-  command void* Send.getPayload(message_t* m) {
-    return m->data;
+  command void* Send.getPayload(message_t* m, uint8_t len) {
+    if (len <= call Send.maxPayloadLength()) {
+      return m->data;
+    }
+    else {
+      return NULL;
+    }
   }
 
   command uint8_t Send.maxPayloadLength() {
index a54645f7fa692a321da84cb5693cb41cfbce7448..fef6c2bf21319875071874da366c9e5914e25645 100644 (file)
@@ -163,8 +163,8 @@ implementation {
     return call SubSend.maxPayloadLength();
   }
 
-  command void *Send.getPayload(message_t* msg) {
-    return call SubSend.getPayload(msg);
+  command void *Send.getPayload(message_t* msg, uint8_t len) {
+    return call SubSend.getPayload(msg, len);
   }
   
   
index 95c77ed56fb0785b413f99b873037e268599a02f..1a68ec15c03a5699739e79a64f2dbeb843622caf 100644 (file)
@@ -302,8 +302,8 @@ implementation {
     return call SubSend.maxPayloadLength();
   }
 
-  command void *Send.getPayload(message_t* msg) {
-    return call SubSend.getPayload(msg);
+  command void *Send.getPayload(message_t* msg, uint8_t len) {
+    return call SubSend.getPayload(msg, len);
   }
   
   
@@ -327,15 +327,6 @@ implementation {
   async event void RadioBackoff.requestCca[am_id_t amId](message_t *msg) {
   }
   
-  /***************** Receive Commands ***************/
-  command void *Receive.getPayload(message_t* msg, uint8_t* len) {
-    return call SubReceive.getPayload(msg, len);
-  }
-
-  command uint8_t Receive.payloadLength(message_t* msg) {
-    return call SubReceive.payloadLength(msg);
-  }
-
 
   /***************** DutyCycle Events ***************/
   /**
index b82e893513b89fd4004dfa6a4576308f1637a66e..19239df6e1dc12dd82c9bdbf8e35a65768f91757 100644 (file)
@@ -135,20 +135,6 @@ implementation {
     return SUCCESS;
   }
 
-  /***************** Receive Commands ****************/
-  command void* Receive.getPayload(message_t* m, uint8_t* len) {
-    if (len != NULL) {
-      *len = ((uint8_t*) (call CC2420PacketBody.getHeader( m_p_rx_buf )))[0];
-    }
-    return m->data;
-  }
-
-  command uint8_t Receive.payloadLength(message_t* m) {
-    uint8_t* buf = (uint8_t*)(call CC2420PacketBody.getHeader( m_p_rx_buf ));
-    return buf[0];
-  }
-  
-  
   /***************** CC2420Receive Commands ****************/
   /**
    * Start frame delimiter signifies the beginning/end of a packet
index bc3faf07762ae126302a9fc312991e4b6cd0d225..69aabcb8059dd9a85afd1478aaee0d9d4a5c61a2 100644 (file)
@@ -81,25 +81,6 @@ implementation {
   bool hasSeen(uint16_t msgSource, uint8_t msgDsn);
   void insert(uint16_t msgSource, uint8_t msgDsn);
   
-  /***************** Receive Commands ***************/
-  command void *Receive.getPayload(message_t* msg, uint8_t* len) {
-    return call SubReceive.getPayload(msg, len);
-  }
-
-  command uint8_t Receive.payloadLength(message_t* msg) {
-    return call SubReceive.payloadLength(msg);
-  }
-  
-  
-  /***************** DuplicateReceive Commands ****************/
-  command void *DuplicateReceive.getPayload(message_t* msg, uint8_t* len) {
-    return call SubReceive.getPayload(msg, len);
-  }
-
-  command uint8_t DuplicateReceive.payloadLength(message_t* msg) {
-    return call SubReceive.payloadLength(msg);
-  }
-  
   /***************** SubReceive Events *****************/
   event message_t *SubReceive.receive(message_t* msg, void* payload, 
       uint8_t len) {
index 1611c45f102d0be596b532cf4451b4482f7a720c..7b68edfe2a1efc41dbdf7df1310585b1cf332d10 100644 (file)
@@ -96,8 +96,8 @@ implementation {
     return call SubSend.maxPayloadLength();
   }
 
-  command void *Send.getPayload(message_t* msg) {
-    return call SubSend.getPayload(msg);
+  command void *Send.getPayload(message_t* msg, uint8_t len) {
+    return call SubSend.getPayload(msg, len);
   }
   
   /***************** SubSend Events ****************/
index c44da61dbef1143de55303f40c97b3af1c96fdc9..5c1a41b6680f86ab1e779e2d8aa8988123c12a13 100644 (file)
@@ -87,8 +87,8 @@ implementation {
     return call SubPacket.maxPayloadLength();
   }
 
-  command void* AMSend.getPayload[am_id_t id](message_t* m) {
-    return call SubPacket.getPayload(m, NULL);
+  command void* AMSend.getPayload[am_id_t id](message_t* m, uint8_t len) {
+    return call SubPacket.getPayload(m, len);
   }
 
   /* Receiving a packet */
@@ -102,22 +102,6 @@ implementation {
     }
   }
 
-  command void* Receive.getPayload[am_id_t id](message_t* m, uint8_t* len) {
-    return call SubPacket.getPayload(m, len);
-  }
-
-  command uint8_t Receive.payloadLength[am_id_t id](message_t* m) {
-    return call SubPacket.payloadLength(m);
-  }
-
-  command void* Snoop.getPayload[am_id_t id](message_t* m, uint8_t* len) {
-    return call SubPacket.getPayload(m, len);
-  }
-
-  command uint8_t Snoop.payloadLength[am_id_t id](message_t* m) {
-    return call SubPacket.payloadLength(m);
-  }
-
   command am_addr_t AMPacket.address() {
     return call amAddress();
   }
index a04e223bc21b1434a8a3b3ba65394370af6199ff..bba168f6c382dee51c4b1fba0c4fe7d509e2d900 100644 (file)
@@ -562,7 +562,7 @@ implementation
         return call SubPacket.maxPayloadLength();
     }
     
-    command void* Packet.getPayload(message_t* msg, uint8_t* len) {
+    command void* Packet.getPayload(message_t* msg, uint8_t len) {
         return call SubPacket.getPayload(msg, len);
     }
    
index 09039d76ea512d23185ff166412b9d8ba4fccd84..4e69fc4dbd7cc07ff43ed39447610d82198e603c 100644 (file)
@@ -110,8 +110,8 @@ implementation {
     return call Packet.maxPayloadLength();
   }
 
-  command void* AMSend.getPayload[am_id_t id](message_t* m) {
-    return call Packet.getPayload(m, NULL);
+  command void* AMSend.getPayload[am_id_t id](message_t* m, uint8_t len) {
+    return call Packet.getPayload(m, len);
   }
 
   command error_t AMSend.send[am_id_t id](am_addr_t addr, 
@@ -153,21 +153,6 @@ implementation {
     return msg;
   }
 
-  command void* Receive.getPayload[am_id_t id](message_t* m, uint8_t* len) {
-    return call Packet.getPayload(m, len);
-  }
-
-  command uint8_t Receive.payloadLength[am_id_t id](message_t* m) {
-    return call Packet.payloadLength(m);
-  }
-  
-  command void* Snoop.getPayload[am_id_t id](message_t* m, uint8_t* len) {
-    return call Packet.getPayload(m, len);
-  }
-
-  command uint8_t Snoop.payloadLength[am_id_t id](message_t* m) {
-    return call Packet.payloadLength(m);
-  }
   
 }
 
index 77bfff4aa7113c69c4f832f098c458c2e540cb42..2d5f67ff8a638d228eb9e03ce9427ad4700b6769 100644 (file)
@@ -133,18 +133,10 @@ implementation {
        return call Packet.maxPayloadLength();
     }
 
-    command void* Send.getPayload(message_t* m) {
-       return call Packet.getPayload(m, NULL);
-    }
-
-    command void* Receive.getPayload(message_t* m, uint8_t* len) {
+    command void* Send.getPayload(message_t* m, uint8_t len) {
        return call Packet.getPayload(m, len);
     }
 
-    command uint8_t Receive.payloadLength(message_t* m) {
-       return call Packet.payloadLength(m);
-    }
-
    task void sendDoneTask() {
        txMsgSendDonePtr = txMsgPtr;
        txMsgPtr=NULL;
@@ -386,11 +378,13 @@ implementation {
        return TOSH_DATA_LENGTH;
     }
 
-    command void* Packet.getPayload(message_t* msg, uint8_t* len) {
-       if (len != NULL) {
-           *len = getMetadata(msg)->length;
-       }
+    command void* Packet.getPayload(message_t* msg, uint8_t len) {
+      if (len <= TOSH_DATA_LENGTH) {
        return (void*)msg->data;
+      }
+      else {
+       return NULL;
+      }
     }
 
     async command error_t PacketAcknowledgements.requestAck(message_t* msg) {
index 6ccc5af86e5a88688edfa77d266262096ded4a0b..27c93d226ed7e23ec0efa4a8b83fd29e62464669 100644 (file)
@@ -114,15 +114,14 @@ interface AMSend {
 
    /**
     * Return a pointer to a protocol's payload region in a packet.
-    * The length of this region is maxPayloadLength(). This command
-    * behaves similarly to <tt>Packet.getPayload</tt> (minus the
-    * length parameter) and is included in this interface
+    * This command behaves identically to <tt>Packet.getPayload</tt>
+    * (minus the length parameter) and is included in this interface
     * as a convenience.
     *
     * @param  msg    the packet
     * @return        the payload of the packet
     */
-  command void* getPayload(message_t* msg);
+  command void* getPayload(message_t* msg, uint8_t len);
 
   
 }
index 14d4e3e642728099044b5c28e01a1bcf5c51c1d4..2e61a5fb1b7cca08d1cbc04bd289c86805a79888 100644 (file)
@@ -95,16 +95,14 @@ interface Packet {
   command uint8_t maxPayloadLength();
 
  /**
-   * Return a pointer to a protocol's payload region in a packet.  If
-   * len is not NULL, getPayload will return the length of the payload
-   * in it, which is the same as the return value from
-   * payloadLength(). If a protocol does not support variable length
-   * packets, then *len is equal to maxPayloadLength().
+   * Return a pointer to a protocol's payload region in a packet which
+   * at least a certain length.  If the payload region is smaller than
+   * the len parameter, then getPayload returns NULL.
    *
    * @param msg   the packet
-   * @param len   pointer to where the current payload length should be stored.
+   * @param len   the length of payload required
    * @return      a pointer to the packet's data payload for this layer
    */
-  command void* getPayload(message_t* msg, uint8_t* len);
+  command void* getPayload(message_t* msg, uint8_t len);
 
 }
index 91a8d6a865df37aa6c1ee08a4f7b37e52f97f9e1..d6a488cf6ed32c1d2a019f083b23d1ec7ca64f54 100644 (file)
@@ -65,27 +65,5 @@ interface Receive {
    */
   
   event message_t* receive(message_t* msg, void* payload, uint8_t len);
-
-  /**
-   * Return point to a protocol's payload region in a packet.  If len
-   * is not NULL, getPayload will return the length of the payload in
-   * it. This call is identical to <TT>Packet.getPayload</TT>, and is
-   * included in Receive as a convenience.
-   *
-   * @param  msg      the packet
-   * @param  len      a pointer to where to store the payload length
-   * @return          a pointer to the payload of the packet
-   */
-  command void* getPayload(message_t* msg, uint8_t* len);
-
-  /**
-   * Return the length of the payload of msg. This call is identical
-   * to <TT>Packet.payloadLength</TT>, and is included in Receive as a
-   * convenience.
-   *
-   * @param  msg      the packet
-   * @return          the length of the packet's payload
-   */
-  command uint8_t payloadLength(message_t* msg);
   
 }
index 897f1dac3c688e5e3170d7dd051ed4138289ad88..a211460c298a68550af4b06d5bcab4b4f6e6aaef 100644 (file)
@@ -102,15 +102,15 @@ interface Send {
 
 
    /**
-    * Return a pointer to a protocol's payload region in a packet.
-    * The length of this region is maxPayloadLength(). This command
-    * behaves similarly to <tt>Packet.getPayload</tt> (minus the
-    * length parameter) and is included in this interface
-    * as a convenience.
+    * Return a pointer to a protocol's payload region in a packet which
+    * at least a certain length.  If the payload region is smaller than
+    * the len parameter, then getPayload returns NULL. This command
+    * behaves identicallt to <tt>Packet.getPayload</tt> and is
+    * included in this interface as a convenience.
     *
     * @param   msg    the packet
     * @return         a pointer to the packet's payload
     */
-  command void* getPayload(message_t* msg);
+  command void* getPayload(message_t* msg, uint8_t len);
 
 }
index 84361ec9d8b80f72aeda620e78b8a57f4d1a6193..abb016369626e87bb9918a77e824185398b54189 100644 (file)
@@ -172,8 +172,8 @@ implementation
       return call Packet.maxPayloadLength();
     }
 
-    command void* Send.getPayload(message_t* msg) {
-      return call Packet.getPayload(msg, (uint8_t*) (call Packet.payloadLength(msg)) );
+    command void* Send.getPayload(message_t* msg, uint8_t len) {
+      return call Packet.getPayload(msg, len);
     }
     
     async event void SendDown.sendDone(message_t* msg, error_t error) { 
@@ -196,7 +196,7 @@ implementation
       message_t* tmpMsgPtr;
       atomic {
         len = call Packet.payloadLength(rxBufPtr);
-        payload = call Packet.getPayload(rxBufPtr, &len);
+        payload = call Packet.getPayload(rxBufPtr, len);
         tmpMsgPtr = rxBufPtr;
       }
       tmpMsgPtr = signal Receive.receive(tmpMsgPtr, payload , len);
@@ -222,13 +222,6 @@ implementation
       return msgPtr;
     }
 
-    command void* Receive.getPayload(message_t* msg, uint8_t* len) {
-      return call Packet.getPayload(msg, len);
-    }
-
-    command uint8_t Receive.payloadLength(message_t* msg) {
-      return call Packet.payloadLength(msg);
-    }
 
     /*************** default events ***********/
 
index 48615c5c34dd92a057992f0d8471123cb6cab610..9ddbcce2b46f270cf8abf65373a7371538c9b2e8 100644 (file)
@@ -203,11 +203,13 @@ implementation {
     return TOSH_DATA_LENGTH;
   }
 
-  command void* Packet.getPayload(message_t* msg, uint8_t* len) {
-    if (len != NULL) {
-      *len = (getHeader(msg))->length;
+  command void* Packet.getPayload(message_t* msg, uint8_t len) {
+    if (len <= TOSH_DATA_LENGTH) {
+      return (void*)msg->data;
+    }
+    else {
+      return NULL;
     }
-    return (void*)msg->data;
   }
   
   // Default events for radio send/receive coordinators do nothing.
index e47a67506208b0aad67ca8e2d0824ed500693d19..2ceb3ed0c1e44c751eed687cf7d83dc5947b78c4 100644 (file)
@@ -101,8 +101,10 @@ implementation
   
   void setupReqMsg()
   {
-    DelugeReqMsg *pReqMsg = (DelugeReqMsg *)(call SendReqMsg.getPayload(&pMsgBuf));
-    
+    DelugeReqMsg *pReqMsg = (DelugeReqMsg *)(call SendReqMsg.getPayload(&pMsgBuf, sizeof(DelugeReqMsg)));
+    if (pReqMsg == NULL) {
+      return;
+    }
     if (state == S_RX_LOCKING) {
       if (isBusy_pMsgBuf) {
         return;
@@ -151,7 +153,7 @@ implementation
   
   void setupDataMsg()
   {
-    DelugeDataMsg *pDataMsg = (DelugeDataMsg *)(call SendDataMsg.getPayload(&pMsgBuf));
+    DelugeDataMsg *pDataMsg = (DelugeDataMsg *)(call SendDataMsg.getPayload(&pMsgBuf, sizeof(DelugeDataMsg)));
     uint16_t nextPkt;
     
     if (state != S_SENDING && state != S_TX_LOCKING) {
@@ -363,7 +365,10 @@ implementation
   
   event void SendDataMsg.sendDone(message_t* msg, error_t error)
   {
-    DelugeDataMsg *pDataMsg = (DelugeDataMsg *)(call SendDataMsg.getPayload(&pMsgBuf));
+    DelugeDataMsg *pDataMsg = (DelugeDataMsg *)(call SendDataMsg.getPayload(&pMsgBuf, sizeof (DelugeDataMsg)));
+    if (pDataMsg == NULL) {
+      return;
+    }
     BITVEC_CLEAR(pktsToSend, pDataMsg->pktNum);
     call Timer.startOneShot(2);
     
@@ -417,7 +422,7 @@ call Leds.led1Toggle();
   
   event void BlockRead.readDone[uint8_t img_num](storage_addr_t addr, void* buf, storage_len_t len, error_t error)
   {
-    DelugeDataMsg *pDataMsg = (DelugeDataMsg *)(call SendDataMsg.getPayload(&pMsgBuf));
+    DelugeDataMsg *pDataMsg = (DelugeDataMsg *)(call SendDataMsg.getPayload(&pMsgBuf, sizeof(DelugeDataMsg)));
     // make sure this event for us
     if (buf != pDataMsg->data) {
       return;
index 110833bba5affd0a752a33fca19bcd000fd9bdf4..5c03b0ab13b1b679d6cfd72462f33b2bc7968cee 100644 (file)
@@ -71,7 +71,10 @@ implementation
    */
   void sendReply(error_t error, storage_len_t len)
   {
-    SerialReplyPacket *srpkt = (SerialReplyPacket *)call SerialAMSender.getPayload(&serialMsg);
+    SerialReplyPacket *srpkt = (SerialReplyPacket *)call SerialAMSender.getPayload(&serialMsg, sizeof(SerialReplyPacket));
+    if (srpkt == NULL) {
+      return;
+    }
     if (error == SUCCESS) {
       srpkt->error = SERIALMSG_SUCCESS;
     } else {
@@ -86,7 +89,10 @@ implementation
                                error_t error)
   {
     if (state == S_READ) {
-      SerialReplyPacket *serialMsg_payload = (SerialReplyPacket *)call SerialAMSender.getPayload(&serialMsg);
+      SerialReplyPacket *serialMsg_payload = (SerialReplyPacket *)call SerialAMSender.getPayload(&serialMsg, sizeof(SerialReplyPacket));
+      if (serialMsg_payload == NULL) {
+       return;
+      }
       if (buf == serialMsg_payload->data) {
         state = S_IDLE;
         sendReply(error, len + sizeof(SerialReplyPacket));
@@ -103,7 +109,10 @@ implementation
       state = S_IDLE;
       
       if (error == SUCCESS) {
-        SerialReplyPacket *srpkt = (SerialReplyPacket *)call SerialAMSender.getPayload(&serialMsg);
+        SerialReplyPacket *srpkt = (SerialReplyPacket *)call SerialAMSender.getPayload(&serialMsg, sizeof(SerialReplyPacket));
+       if (srpkt == NULL) {
+         return;
+       }
         srpkt->data[1] = crc & 0xFF;
         srpkt->data[0] = (crc >> 8) & 0xFF;
       }
@@ -144,9 +153,12 @@ implementation
     error_t error = SUCCESS;
     SerialReqPacket *srpkt = (SerialReqPacket *)payload;
     SerialReplyPacket *serialMsg_payload =
-                              (SerialReplyPacket *)call SerialAMSender.getPayload(&serialMsg);
+      (SerialReplyPacket *)call SerialAMSender.getPayload(&serialMsg, sizeof(SerialReplyPacket));
     uint8_t img_num = 0xFF;
-    
+
+    if (serialMsg_payload == NULL) {
+      return msg;
+    }
     // Converts the image number that the user wants to the real image number
     switch (srpkt->img_num) {
       case 0:
index d2c2d820cfd1ee3d6f4020f6f0c094c6e1d42d55..8c6b499625c900260150a483b29cb3a44835816b 100644 (file)
@@ -130,8 +130,10 @@ implementation
   
   void sendAdvMsg(uint16_t addr)
   {
-    DelugeAdvMsg *pMsg = (DelugeAdvMsg *)(call SendAdvMsg.getPayload(&pMsgBuf));
-    
+    DelugeAdvMsg *pMsg = (DelugeAdvMsg *)(call SendAdvMsg.getPayload(&pMsgBuf, sizeof(DelugeAdvMsg)));
+    if (pMsg == NULL) {
+      return;
+    }
     if (isBusy_pMsgBuf == FALSE) {
       pMsg->sourceAddr = TOS_NODE_ID;
       pMsg->version = DELUGE_VERSION;
index 6ee3e36627af8f2b489661dae1b10da7678482d8..16be42f0aeb5c0703e16b14f150c6a692905b416 100644 (file)
@@ -116,14 +116,15 @@ implementation {
 
   void sendProbe( uint16_t key ) {
     dissemination_probe_message_t* dpMsg = 
-      (dissemination_probe_message_t*) call ProbeAMSend.getPayload( &m_buf );
-    
-    m_bufBusy = TRUE;
-    
-    dpMsg->key = key;
-    
-    call ProbeAMSend.send( AM_BROADCAST_ADDR, &m_buf,
-                          sizeof( dissemination_probe_message_t ) );
+      (dissemination_probe_message_t*) call ProbeAMSend.getPayload( &m_buf, sizeof(dissemination_probe_message_t));
+    if (dpMsg != NULL) {
+      m_bufBusy = TRUE;
+      
+      dpMsg->key = key;
+      
+      call ProbeAMSend.send( AM_BROADCAST_ADDR, &m_buf,
+                            sizeof( dissemination_probe_message_t ) );
+    }
   }
 
   void sendObject( uint16_t key ) {
@@ -131,23 +132,24 @@ implementation {
     uint8_t objectSize = 0;
     
     dissemination_message_t* dMsg = 
-      (dissemination_message_t*) call AMSend.getPayload( &m_buf );
-    
-    m_bufBusy = TRUE;
-    
-    dMsg->key = key;
-    dMsg->seqno = call DisseminationCache.requestSeqno[ key ]();
-
-    if ( dMsg->seqno != DISSEMINATION_SEQNO_UNKNOWN ) {
-      object = call DisseminationCache.requestData[ key ]( &objectSize );
-      if ((objectSize + sizeof(dissemination_message_t)) > 
-           call AMSend.maxPayloadLength()) {
-        objectSize = call AMSend.maxPayloadLength() - sizeof(dissemination_message_t);
-      }
-      memcpy( dMsg->data, object, objectSize );
-    }      
-    call AMSend.send( AM_BROADCAST_ADDR,
-                     &m_buf, sizeof( dissemination_message_t ) + objectSize );
+      (dissemination_message_t*) call AMSend.getPayload( &m_buf, sizeof(dissemination_message_t) );
+    if (dMsg != NULL) {
+      m_bufBusy = TRUE;
+      
+      dMsg->key = key;
+      dMsg->seqno = call DisseminationCache.requestSeqno[ key ]();
+      
+      if ( dMsg->seqno != DISSEMINATION_SEQNO_UNKNOWN ) {
+       object = call DisseminationCache.requestData[ key ]( &objectSize );
+       if ((objectSize + sizeof(dissemination_message_t)) > 
+           call AMSend.maxPayloadLength()) {
+         objectSize = call AMSend.maxPayloadLength() - sizeof(dissemination_message_t);
+       }
+       memcpy( dMsg->data, object, objectSize );
+      }      
+      call AMSend.send( AM_BROADCAST_ADDR,
+                       &m_buf, sizeof( dissemination_message_t ) + objectSize );
+    }
   }
 
   event void ProbeAMSend.sendDone( message_t* msg, error_t error ) {
index 1e291bb320a68fcc6e0bf8a12fa3c885b3a64201..01ea6878939c303e333469cfb739bce9bf46eb28 100644 (file)
@@ -182,8 +182,8 @@ implementation {
         return call SubSend.maxPayloadLength();
     }
 
-    command void* Send.getPayload[uint8_t id](message_t* m) {
-        return call SubSend.getPayload(m);
+    command void* Send.getPayload[uint8_t id](message_t* m, uint8_t len) {
+      return call SubSend.getPayload(m, len);
     }
 
     default event void Send.sendDone[uint8_t id](message_t* msg, error_t err) {
index b339d87b80b5d0b2f80c7afa93368d7ac071e106..ebce09bb6a3c9a740bfb6564e2d334e3bc011fd1 100644 (file)
@@ -79,7 +79,11 @@ implementation {
             return FAIL;
         } else {
             message_t* msg = call MessagePool.get();
-            CollectionDebugMsg* dbg_msg = call UARTSend.getPayload(msg);
+            CollectionDebugMsg* dbg_msg = call UARTSend.getPayload(msg, sizeof(CollectionDebugMsg));
+           if (dbg_msg == NULL) {
+             return FAIL;
+           }
+           
             memset(dbg_msg, 0, len);
 
             dbg_msg->type = type;
@@ -102,7 +106,10 @@ implementation {
             return FAIL;
         } else {
             message_t* msg = call MessagePool.get();
-            CollectionDebugMsg* dbg_msg = call UARTSend.getPayload(msg);
+            CollectionDebugMsg* dbg_msg = call UARTSend.getPayload(msg, sizeof(CollectionDebugMsg));
+           if (dbg_msg == NULL) {
+             return FAIL;
+           }
             memset(dbg_msg, 0, len);
 
             dbg_msg->type = type;
@@ -128,7 +135,10 @@ implementation {
             return FAIL;
         } else {
             message_t* msg = call MessagePool.get();
-            CollectionDebugMsg* dbg_msg = call UARTSend.getPayload(msg);
+            CollectionDebugMsg* dbg_msg = call UARTSend.getPayload(msg, sizeof(CollectionDebugMsg));
+           if (dbg_msg == NULL) {
+             return FAIL;
+           }
             memset(dbg_msg, 0, len);
 
             dbg_msg->type = type;
@@ -154,7 +164,10 @@ implementation {
             return FAIL;
         } else {
             message_t* msg = call MessagePool.get();
-            CollectionDebugMsg* dbg_msg = call UARTSend.getPayload(msg);
+            CollectionDebugMsg* dbg_msg = call UARTSend.getPayload(msg, sizeof(CollectionDebugMsg));
+           if (dbg_msg == NULL) {
+             return FAIL;
+           }
             memset(dbg_msg, 0, len);
 
             dbg_msg->type = type;
@@ -178,7 +191,10 @@ implementation {
             return FAIL;
         } else {
             message_t* msg = call MessagePool.get();
-            CollectionDebugMsg* dbg_msg = call UARTSend.getPayload(msg);
+            CollectionDebugMsg* dbg_msg = call UARTSend.getPayload(msg, sizeof(CollectionDebugMsg));
+           if (dbg_msg == NULL) {
+             return FAIL;
+           }
             memset(dbg_msg, 0, len);
 
             dbg_msg->type = type;
index b436c668d87b45df449e95ef94f92c5cb1c6c5e6..e7cb53cee2fd75c785d2da1b8f0d07a6f5c5fa5e 100644 (file)
@@ -292,7 +292,7 @@ implementation {
   }
 
   ctp_data_header_t* getHeader(message_t* m) {
-    return (ctp_data_header_t*)call SubPacket.getPayload(m, NULL);
+    return (ctp_data_header_t*)call SubPacket.getPayload(m, sizeof(ctp_data_header_t));
   }
  
   /*
@@ -358,8 +358,8 @@ implementation {
     return call Packet.maxPayloadLength();
   }
 
-  command void* Send.getPayload[uint8_t client](message_t* msg) {
-    return call Packet.getPayload(msg, NULL);
+  command void* Send.getPayload[uint8_t client](message_t* msg, uint8_t len) {
+    return call Packet.getPayload(msg, len);
   }
 
   /*
@@ -459,8 +459,8 @@ implementation {
        
         dbg("Forwarder", "%s: I'm a root, so loopback and signal receive.\n", __FUNCTION__);
         loopbackMsgPtr = signal Receive.receive[collectid](loopbackMsgPtr,
-                                                         call Packet.getPayload(loopbackMsgPtr, NULL), 
-                                                         call Packet.payloadLength(loopbackMsgPtr));
+                                                          call Packet.getPayload(loopbackMsgPtr, call Packet.payloadLength(loopbackMsgPtr)), 
+                                                          call Packet.payloadLength(loopbackMsgPtr));
         signal SubSend.sendDone(qe->msg, SUCCESS);
         return;
       }
@@ -727,7 +727,6 @@ implementation {
    */ 
   event message_t* 
   SubReceive.receive(message_t* msg, void* payload, uint8_t len) {
-    uint8_t netlen;
     collection_id_t collectid;
     bool duplicate = FALSE;
     fe_queue_entry_t* qe;
@@ -775,13 +774,13 @@ implementation {
     // If I'm the root, signal receive. 
     else if (call RootControl.isRoot())
       return signal Receive.receive[collectid](msg, 
-                        call Packet.getPayload(msg, &netlen), 
-                        call Packet.payloadLength(msg));
+                                              call Packet.getPayload(msg, call Packet.payloadLength(msg)), 
+                                              call Packet.payloadLength(msg));
     // I'm on the routing path and Intercept indicates that I
     // should not forward the packet.
     else if (!signal Intercept.forward[collectid](msg, 
-                        call Packet.getPayload(msg, &netlen), 
-                        call Packet.payloadLength(msg)))
+                                                 call Packet.getPayload(msg, call Packet.payloadLength(msg)), 
+                                                 call Packet.payloadLength(msg)))
       return msg;
     else {
       dbg("Route", "Forwarding packet from %hu.\n", getHeader(msg)->origin);
@@ -789,25 +788,6 @@ implementation {
     }
   }
 
-  command void* 
-  Receive.getPayload[collection_id_t id](message_t* msg, uint8_t* len) {
-    return call Packet.getPayload(msg, NULL);
-  }
-
-  command uint8_t
-  Receive.payloadLength[collection_id_t id](message_t *msg) {
-    return call Packet.payloadLength(msg);
-  }
-
-  command void *
-  Snoop.getPayload[collection_id_t id](message_t *msg, uint8_t *len) {
-    return call Packet.getPayload(msg, NULL);
-  }
-
-  command uint8_t Snoop.payloadLength[collection_id_t id](message_t *msg) {
-    return call Packet.payloadLength(msg);
-  }
-
   event message_t* 
   SubSnoop.receive(message_t* msg, void *payload, uint8_t len) {
     //am_addr_t parent = call UnicastNameFreeRouting.nextHop();
@@ -870,12 +850,12 @@ implementation {
     return call SubPacket.maxPayloadLength() - sizeof(ctp_data_header_t);
   }
 
-  command void* Packet.getPayload(message_t* msg, uint8_t* len) {
-    uint8_t* payload = call SubPacket.getPayload(msg, len);
-    if (len != NULL) {
-      *len -= sizeof(ctp_data_header_t);
+  command void* Packet.getPayload(message_t* msg, uint8_t len) {
+    uint8_t* payload = call SubPacket.getPayload(msg, len + sizeof(ctp_data_header_t));
+    if (payload != NULL) {
+      payload += sizeof(ctp_data_header_t);
     }
-    return payload + sizeof(ctp_data_header_t);
+    return payload;
   }
 
   command am_addr_t       CollectionPacket.getOrigin(message_t* msg) {return getHeader(msg)->origin;}
index fb8aad78ff98ca9fba238a9c897b96cbd710185f..7c8810302b35322bda842609ddf59ae6532f7414 100644 (file)
@@ -207,7 +207,7 @@ implementation {
         routeInfoInit(&routeInfo);
         routingTableInit();
         my_ll_addr = call AMPacket.address();
-        beaconMsg = call BeaconSend.getPayload(&beaconMsgBuffer);
+        beaconMsg = call BeaconSend.getPayload(&beaconMsgBuffer, call BeaconSend.maxPayloadLength());
         maxLength = call BeaconSend.maxPayloadLength();
         dbg("TreeRoutingCtl","TreeRouting initialized. (used payload:%d max payload:%d!\n", 
               sizeof(beaconMsg), maxLength);
@@ -454,7 +454,7 @@ implementation {
 
 
     ctp_routing_header_t* getHeader(message_t* m) {
-      return (ctp_routing_header_t*)call BeaconReceive.getPayload(m, NULL);
+      return (ctp_routing_header_t*)call BeaconSend.getPayload(m, call BeaconSend.maxPayloadLength());
     }
     
     
index ebfa4430fa6741a593fbbcbeafce36b732fd75e3..3689b407e723d869d15d0746f2d07c4b7029d21e 100644 (file)
@@ -91,12 +91,13 @@ implementation {
 
   // get the link estimation header in the packet
   linkest_header_t* getHeader(message_t* m) {
-    return (linkest_header_t*)call SubPacket.getPayload(m, NULL);
+    return (linkest_header_t*)call SubPacket.getPayload(m, sizeof(linkest_header_t));
   }
 
   // get the link estimation footer (neighbor entries) in the packet
   linkest_footer_t* getFooter(message_t* m, uint8_t len) {
-    return (linkest_footer_t*)(len + (uint8_t *)call Packet.getPayload(m,NULL));
+    // To get a footer at offset "len", the payload must be len + sizeof large.
+    return (linkest_footer_t*)(len + (uint8_t *)call Packet.getPayload(m,len + sizeof(linkest_footer_t)));
   }
 
   // add the link estimation header (seq no) and link estimation
@@ -585,8 +586,8 @@ implementation {
     return call Packet.maxPayloadLength();
   }
 
-  command void* Send.getPayload(message_t* msg) {
-    return call Packet.getPayload(msg, NULL);
+  command void* Send.getPayload(message_t* msg, uint8_t len) {
+    return call Packet.getPayload(msg, len);
   }
 
   // called when link estimator generator packet or
@@ -649,10 +650,12 @@ implementation {
       }
 
       if ((nidx != INVALID_RVAL) && (num_entries > 0)) {
+       uint8_t payloadLen = call SubPacket.payloadLength(msg);
+       void* subPayload = call SubPacket.getPayload(msg, payloadLen);
+       void* payloadEnd = subPayload + payloadLen;
        dbg("LI", "Number of footer entries: %d\n", num_entries);
-       footer = (linkest_footer_t*) ((uint8_t *)call SubPacket.getPayload(msg, NULL)
-                                     + call SubPacket.payloadLength(msg)
-                                     - num_entries*sizeof(linkest_footer_t));
+       
+       footer = (linkest_footer_t*) (payloadEnd - (num_entries*sizeof(linkest_footer_t)));
        {
          uint8_t i, my_ll_addr;
          my_ll_addr = call SubAMPacket.address();
@@ -681,18 +684,10 @@ implementation {
     dbg("LI", "Received upper packet. Will signal up\n");
     processReceivedMessage(msg, payload, len);
     return signal Receive.receive(msg,
-                                 call Packet.getPayload(msg, NULL),
+                                 call Packet.getPayload(msg, call Packet.payloadLength(msg)),
                                  call Packet.payloadLength(msg));
   }
 
-  command void* Receive.getPayload(message_t* msg, uint8_t* len) {
-    return call Packet.getPayload(msg, len);
-  }
-
-  command uint8_t Receive.payloadLength(message_t* msg) {
-    return call Packet.payloadLength(msg);
-  }
-
   command void Packet.clear(message_t* msg) {
     call SubPacket.clear(msg);
   }
@@ -723,14 +718,14 @@ implementation {
   }
 
   // application payload pointer is just past the link estimation header
-  command void* Packet.getPayload(message_t* msg, uint8_t* len) {
-    uint8_t* payload = call SubPacket.getPayload(msg, len);
-    linkest_header_t *hdr;
-    hdr = getHeader(msg);
-    if (len != NULL) {
-      *len = *len - sizeof(linkest_header_t) - sizeof(linkest_footer_t)*(NUM_ENTRIES_FLAG & hdr->flags);
+  command void* Packet.getPayload(message_t* msg, uint8_t len) {
+    linkest_header_t *hdr = getHeader(msg);
+    uint8_t footerLen = (hdr->flags & NUM_ENTRIES_FLAG) * sizeof(linkest_header_t);
+    void* payload = call SubPacket.getPayload(msg, len + footerLen);
+    if (payload != NULL) {
+      payload += sizeof(linkest_header_t);
     }
-    return payload + sizeof(linkest_header_t);
+    return payload;
   }
 }
 
index 708085ae49e8ca5743840c78ee3d2e13fd4a2851..f83959444b9fc70a6e39e1bec1724a8e2f917942 100644 (file)
@@ -47,8 +47,8 @@ implementation {
     return call SubSend.cancel(msg);
   }
 
-  command void* Send.getPayload(message_t* m) {
-    return call SubSend.getPayload(m);
+  command void* Send.getPayload(message_t* m, uint8_t len) {
+    return call SubSend.getPayload(m, len);
   }
 
   command uint8_t Send.maxPayloadLength() {
index 59917f95bdb947ac55fbc82f67cbfa3927ea0bef..45cba9dc0816c7eab1961f746ce9982dacbf13d1 100644 (file)
@@ -124,7 +124,7 @@ implementation {
   int fwdbusy = 0;
   
   lqi_header_t* getHeader(message_t* msg) {
-    return (lqi_header_t*) call SubPacket.getPayload(msg, NULL);
+    return (lqi_header_t*) call SubPacket.getPayload(msg, sizeof(lqi_header_t));
   }
   
   /***********************************************************************
@@ -435,8 +435,8 @@ implementation {
     
   }
 
-  command void* Send.getPayload(message_t* m) {
-    return call Packet.getPayload(m, NULL);
+  command void* Send.getPayload(message_t* m, uint8_t len) {
+    return call Packet.getPayload(m, len);
   }
 
   command uint8_t Send.maxPayloadLength() {
@@ -448,22 +448,6 @@ implementation {
   }
 
   
-  command void* Receive.getPayload[collection_id_t id](message_t* msg, uint8_t* len) {
-    return call Packet.getPayload(msg, len);
-  }
-  
-  command uint8_t Receive.payloadLength[collection_id_t id](message_t* m) {
-    return call Packet.payloadLength(m);
-  }
-
-  command void* Snoop.getPayload[collection_id_t id](message_t* msg, uint8_t* len) {
-    return call Packet.getPayload(msg, len);
-  }
-  
-  command uint8_t Snoop.payloadLength[collection_id_t id](message_t* m) {
-    return call Packet.payloadLength(m);
-  }
-  
   command uint8_t Packet.payloadLength(message_t* msg) {
     return call SubPacket.payloadLength(msg) - sizeof(lqi_header_t);
   }
@@ -473,12 +457,11 @@ implementation {
   command uint8_t Packet.maxPayloadLength() {
     return (call SubPacket.maxPayloadLength() - sizeof(lqi_header_t));
   }
-  command void* Packet.getPayload(message_t* msg, uint8_t* len) {
-    void* rval = call SubPacket.getPayload(msg, len);
-    if (len != NULL) {
-      *len -= sizeof(lqi_header_t);
+  command void* Packet.getPayload(message_t* msg, uint8_t len) {
+    void* rval = call SubPacket.getPayload(msg, len + sizeof(lqi_header_t));
+    if (rval != NULL) {
+      rval += sizeof(lqi_header_t);
     }
-    rval += sizeof(lqi_header_t);
     return rval;
   }
 
index 89ede9dcc265c2340ef94d3030ff24e646953967..d9e76cbf4f2a1b6b491de1fdffa889679e7fa1bb 100644 (file)
@@ -108,11 +108,11 @@ implementation {
   }
 
   lqi_header_t* getHeader(message_t* msg) {
-    return (lqi_header_t*)call Packet.getPayload(msg, NULL);
+    return (lqi_header_t*)call Packet.getPayload(msg, sizeof(lqi_header_t));
   }
   
   lqi_beacon_msg_t* getBeacon(message_t* msg) {
-    return (lqi_beacon_msg_t*)call Packet.getPayload(msg, NULL);
+    return (lqi_beacon_msg_t*)call Packet.getPayload(msg, sizeof(lqi_beacon_msg_t));
   }
 
   task void SendRouteTask() {
@@ -277,7 +277,7 @@ implementation {
   }
 
   command error_t RouteSelect.initializeFields(message_t* msg) {
-    lqi_header_t* header = (lqi_header_t*)call Packet.getPayload(msg, NULL);
+    lqi_header_t* header = getHeader(msg);
 
     header->originaddr = TOS_NODE_ID;
     header->originseqno = gOriginSeqNo++;
index c69c809a5975bba0d22b5a48b0546172c718c143..5f4ae23110d7587cd358de7dd79c4e229f2a6be4 100644 (file)
@@ -83,7 +83,7 @@ implementation {
   }
   
   void sendNext() {
-    printf_msg_t* m = (printf_msg_t*)call Packet.getPayload(&printfMsg, NULL);
+    printf_msg_t* m = (printf_msg_t*)call Packet.getPayload(&printfMsg, sizeof(printf_msg_t));
     length_to_send = (bytes_left_to_flush < sizeof(printf_msg_t)) ? bytes_left_to_flush : sizeof(printf_msg_t);
     memset(m->buffer, 0, sizeof(printf_msg_t));
     memcpy(m->buffer, (nx_uint8_t*)next_byte, length_to_send);
index 793899bf1083b060da307bb1de6050bde7c16211..0eb5e685ab8dd1b8198761515fcd14cd8fe846cf 100644 (file)
@@ -74,8 +74,8 @@ implementation {
     return call Packet.maxPayloadLength();
   }
 
-  command void* AMSend.getPayload[am_id_t id](message_t* m) {
-    return call Packet.getPayload(m, NULL);
+  command void* AMSend.getPayload[am_id_t id](message_t* m, uint8_t len) {
+    return call Packet.getPayload(m, len);
   }
   
   event void SubSend.sendDone(message_t* msg, error_t result) {
@@ -90,16 +90,7 @@ implementation {
    return msg;
  }
  
-  
-  command void* Receive.getPayload[am_id_t id](message_t* m, uint8_t* len) {
-    return call Packet.getPayload(m, len);
-  }
-
-  command uint8_t Receive.payloadLength[am_id_t id](message_t* m) {
-    return call Packet.payloadLength(m);
-  }
-  
-  event message_t* SubReceive.receive(message_t* msg, void* payload, uint8_t len) {
+ event message_t* SubReceive.receive(message_t* msg, void* payload, uint8_t len) {
     return signal Receive.receive[call AMPacket.type(msg)](msg, msg->data, len);
   }
 
@@ -120,11 +111,13 @@ implementation {
     return TOSH_DATA_LENGTH;
   }
   
-  command void* Packet.getPayload(message_t* msg, uint8_t* len) {
-    if (len != NULL) { 
-      *len = call Packet.payloadLength(msg);
+  command void* Packet.getPayload(message_t* msg, uint8_t len) {
+    if (len > call Packet.maxPayloadLength()) {
+      return NULL;
+    }
+    else {
+      return msg->data;
     }
-    return msg->data;
   }
 
   command am_addr_t AMPacket.address() {
index fdcb5b6fe0548bcdc809b5039d253a6846dd3432..5f1a9b6badae105959668534a25d22f25964d16c 100644 (file)
@@ -134,21 +134,16 @@ implementation {
     return (sizeof(message_t));
   }
 
-  command void* Send.getPayload[uint8_t id](message_t* m) {
-    return m;
-  }
-
-  command void* Receive.getPayload[uint8_t id](message_t* m, uint8_t* len) {
-    if (len != NULL) {
-      *len = 0;
+  command void* Send.getPayload[uint8_t id](message_t* m, uint8_t len) {
+    if (len > sizeof(message_t)) {
+      return NULL;
+    }
+    else {
+      return m;
     }
-    return m;
-  }
-
-  command uint8_t Receive.payloadLength[uint8_t id](message_t* m) {
-    return 0;
   }
 
+    
   task void signalSendDone(){
     error_t error;
 
index d436e355216b8dfb1ca4482d41dd573efd47aa57..9b0fe461ecc12154f3ce90006d2ff0e36df025db 100644 (file)
@@ -85,26 +85,10 @@ implementation {
     return call Packet.maxPayloadLength();
   }
 
-  command void* AMSend.getPayload[am_id_t id](message_t* m) {
-    return call Packet.getPayload(m, NULL);
-  }
-
-  command void* Receive.getPayload[am_id_t id](message_t* m, uint8_t* len) {
-    return call Packet.getPayload(m, len);
-  }
-
-  command uint8_t Receive.payloadLength[am_id_t id](message_t* m) {
-    return call Packet.payloadLength(m);
-  }
-  
-  command void* Snoop.getPayload[am_id_t id](message_t* m, uint8_t* len) {
+  command void* AMSend.getPayload[am_id_t id](message_t* m, uint8_t len) {
     return call Packet.getPayload(m, len);
   }
 
-  command uint8_t Snoop.payloadLength[am_id_t id](message_t* m) {
-    return call Packet.payloadLength(m);
-  }
-  
   command am_addr_t AMPacket.address() {
     return call amAddress();
   }
@@ -171,11 +155,13 @@ implementation {
     return TOSH_DATA_LENGTH;
   }
   
-  command void* Packet.getPayload(message_t* msg, uint8_t* len) {
-    if (len != NULL) {
-      *len = call Packet.payloadLength(msg);
+  command void* Packet.getPayload(message_t* msg, uint8_t len) {
+    if (len <= TOSH_DATA_LENGTH) {
+      return msg->data;
+    }
+    else {
+      return NULL;
     }
-    return msg->data;
   }
 
   async command error_t Acks.requestAck(message_t* msg) {
index 47a29214ab43a2e5214f77e11862bef746030883..eb9f49b234f9421e528161eab3b6e844583e4632 100644 (file)
@@ -84,26 +84,10 @@ implementation {
     return call Packet.maxPayloadLength();
   }
 
-  command void* AMSend.getPayload[am_id_t id](message_t* m) {
-    return call Packet.getPayload(m, NULL);
-  }
-
-  command void* Receive.getPayload[am_id_t id](message_t* m, uint8_t* len) {
+  command void* AMSend.getPayload[am_id_t id](message_t* m, uint8_t len) {
     return call Packet.getPayload(m, len);
   }
 
-  command uint8_t Receive.payloadLength[am_id_t id](message_t* m) {
-    return call Packet.payloadLength(m);
-  }
-  
-  command void* Snoop.getPayload[am_id_t id](message_t* m, uint8_t* len) {
-    return call Packet.getPayload(m, len);
-  }
-
-  command uint8_t Snoop.payloadLength[am_id_t id](message_t* m) {
-    return call Packet.payloadLength(m);
-  }
-  
   command int8_t TossimPacket.strength(message_t* msg) {
     return getMetadata(msg)->strength;
   }
@@ -119,7 +103,7 @@ implementation {
     void* payload;
 
     memcpy(bufferPointer, msg, sizeof(message_t));
-    payload = call Packet.getPayload(bufferPointer, &len);
+    payload = call Packet.getPayload(bufferPointer, call Packet.maxPayloadLength());
 
     if (call AMPacket.isForMe(msg)) {
       dbg("AM", "Received active message (%p) of type %hhu and length %hhu for me @ %s.\n", bufferPointer, call AMPacket.type(bufferPointer), len, sim_time_string());
@@ -193,11 +177,13 @@ implementation {
     return TOSH_DATA_LENGTH;
   }
   
-  command void* Packet.getPayload(message_t* msg, uint8_t* len) {
-    if (len != NULL) {
-      *len = call Packet.payloadLength(msg);
+  command void* Packet.getPayload(message_t* msg, uint8_t len) {
+    if (len <= TOSH_DATA_LENGTH) {
+      return msg->data;
+    }
+    else {
+      return NULL;
     }
-    return msg->data;
   }
 
   command am_group_t AMPacket.group(message_t* amsg) {
index ebb9a38c9e455dc23f9adf32b06e80b12ff011a2..26a83e27cd1c43fac8ba9ce6d07e89ead5753845 100644 (file)
@@ -56,17 +56,13 @@ module ActiveMessageFilterC {
   command error_t AMSend.send[am_id_t id](am_addr_t addr, message_t* msg, uint8_t len){ return call SubAMSend.send[id](addr, msg, len);}
   command error_t AMSend.cancel[am_id_t id](message_t* msg){ return call SubAMSend.cancel[id](msg);}
   command uint8_t AMSend.maxPayloadLength[am_id_t id](){ return call SubAMSend.maxPayloadLength[id]();}
-  command void* AMSend.getPayload[am_id_t id](message_t* msg){ return call SubAMSend.getPayload[id](msg);}
+  command void* AMSend.getPayload[am_id_t id](message_t* msg, uint8_t len){ return call SubAMSend.getPayload[id](msg, len);}
   event void SubAMSend.sendDone[am_id_t id](message_t* msg, error_t error) { signal AMSend.sendDone[id](msg, error); }
   default event void AMSend.sendDone[am_id_t id](message_t* msg, error_t error) { return; }
 
-  command void* Receive.getPayload[am_id_t id](message_t* msg, uint8_t* len){ return call SubReceive.getPayload[id](msg, len);}
-  command uint8_t Receive.payloadLength[am_id_t id](message_t* msg){ return call SubReceive.payloadLength[id](msg);}
   event message_t* SubReceive.receive[am_id_t id](message_t* msg, void* payload, uint8_t len) { return signal Receive.receive[id](msg, payload, len); }
   default event message_t* Receive.receive[am_id_t id](message_t* msg, void* payload, uint8_t len){ return msg;}
   
-  command void* Snoop.getPayload[am_id_t id](message_t* msg, uint8_t* len){ return call SubSnoop.getPayload[id](msg, len);}
-  command uint8_t Snoop.payloadLength[am_id_t id](message_t* msg){ return call SubSnoop.payloadLength[id](msg);}
   event message_t* SubSnoop.receive[am_id_t id](message_t* msg, void* payload, uint8_t len) { return signal Snoop.receive[id](msg, payload, len);
   }
   default event message_t* Snoop.receive[am_id_t id](message_t* msg, void* payload, uint8_t len){return msg;}
index c1c0f3809b2ea6c6e6a8073cd27593f5d2044cba..2f96c3941778a0029547d8a16e578c98306a6454 100644 (file)
@@ -62,8 +62,8 @@ implementation {
     return call Send.maxPayloadLength();
   }
 
-  command void* AMSend.getPayload(message_t* m) {
-    return call Send.getPayload(m);
+  command void* AMSend.getPayload(message_t* m, uint8_t len) {
+    return call Send.getPayload(m, len);
   }
   
 }
index 51cd2aece1c3f83eee2531e2b3a4a925db67e151..a2998d011dbe991c1ce4ae7fef737de2efdf74b9 100644 (file)
@@ -200,8 +200,8 @@ implementation {
         return call AMSend.maxPayloadLength[0]();
     }
 
-    command void* Send.getPayload[uint8_t id](message_t* m) {
-        return call AMSend.getPayload[0](m);
+    command void* Send.getPayload[uint8_t id](message_t* m, uint8_t len) {
+      return call AMSend.getPayload[0](m, len);
     }
 
     default event void Send.sendDone[uint8_t id](message_t* msg, error_t err) {