From da0cfeda9689aa64cfce0aa209f51803dcb11c21 Mon Sep 17 00:00:00 2001 From: scipio Date: Thu, 13 Sep 2007 23:10:14 +0000 Subject: [PATCH] The big interface switchover for Packet, Send, Receive, and AMSend. --- apps/AntiTheft/Nodes/AntiTheftC.nc | 11 ++-- apps/AntiTheft/Root/AntiTheftRootC.nc | 11 ++-- apps/MViz/MVizC.nc | 10 ++-- .../MultihopOscilloscopeC.nc | 17 ++++-- .../MultihopOscilloscopeC.nc | 17 ++++-- apps/Oscilloscope/OscilloscopeC.nc | 4 +- apps/RadioCountToLeds/RadioCountToLedsC.nc | 4 +- apps/RadioSenseToLeds/RadioSenseToLedsC.nc | 4 +- apps/tests/RadioStress/RadioStressC.nc | 2 +- apps/tests/TestLocalTime/TestLocalTimeC.nc | 2 +- .../TestMultihopLqi/MultihopOscilloscopeC.nc | 14 +++-- apps/tests/TestNetwork/TestNetworkC.nc | 4 +- .../MultihopOscilloscopeC.nc | 14 +++-- apps/tests/TestSerial/TestSerialC.nc | 3 +- apps/tests/TestSerialBandwidth/TestSerialC.nc | 9 ++-- .../RadioCountToLedsC.nc | 2 +- .../TestPeriodicP.nc | 2 +- .../TestPeriodicP.nc | 2 +- .../cc2420/RssiToSerial/RssiToSerialP.nc | 2 +- .../cc2420/TestPacketLink/TestPacketLinkP.nc | 8 +-- .../cc2420/TxThroughput/TxThroughputP.nc | 2 +- .../RadioCountToFlash/RadioCountToFlashC.nc | 4 +- apps/tests/mica2/mts300/TestMts300P.nc | 6 ++- apps/tests/mts300/PhotoTemp/OscilloscopeC.nc | 2 +- apps/tests/storage/Block/RandRWC.nc | 2 +- apps/tests/storage/CircularLog/RandRWC.nc | 2 +- apps/tests/storage/Config/RandRWC.nc | 2 +- apps/tests/storage/SyncLog/SyncLogC.nc | 2 +- apps/tutorials/BlinkToRadio/BlinkToRadioC.nc | 5 +- tos/chips/cc1000/CC1000ActiveMessageP.nc | 20 +------ tos/chips/cc1000/CC1000SendReceiveP.nc | 24 +++------ tos/chips/cc2420/CC2420ActiveMessageP.nc | 27 ++-------- tos/chips/cc2420/csma/CC2420CsmaP.nc | 9 +++- tos/chips/cc2420/link/PacketLinkP.nc | 4 +- tos/chips/cc2420/lpl/DefaultLplP.nc | 13 +---- tos/chips/cc2420/receive/CC2420ReceiveP.nc | 14 ----- tos/chips/cc2420/unique/UniqueReceiveP.nc | 19 ------- tos/chips/cc2420/unique/UniqueSendP.nc | 4 +- tos/chips/tda5250/Tda5250ActiveMessageP.nc | 20 +------ tos/chips/tda5250/mac/CsmaMacP.nc | 2 +- tos/chips/xe1205/XE1205ActiveMessageP.nc | 19 +------ tos/chips/xe1205/XE1205SendReceiveP.nc | 20 +++---- tos/interfaces/AMSend.nc | 7 ++- tos/interfaces/Packet.nc | 12 ++--- tos/interfaces/Receive.nc | 22 -------- tos/interfaces/Send.nc | 12 ++--- tos/lib/byte_radio/LinkLayerP.nc | 13 ++--- tos/lib/byte_radio/PacketSerializerP.nc | 10 ++-- tos/lib/net/Deluge/DelugePageTransferP.nc | 15 ++++-- .../FlashVolumeManager/FlashVolumeManagerP.nc | 22 ++++++-- tos/lib/net/Deluge/ObjectTransferP.nc | 6 ++- tos/lib/net/DisseminationEngineImplP.nc | 52 ++++++++++--------- tos/lib/net/SendVirtualizerP.nc | 4 +- tos/lib/net/UARTDebugSenderP.nc | 26 ++++++++-- tos/lib/net/ctp/CtpForwardingEngineP.nc | 48 +++++------------ tos/lib/net/ctp/CtpRoutingEngineP.nc | 4 +- tos/lib/net/le/LinkEstimatorP.nc | 41 +++++++-------- tos/lib/net/lqi/CollectionSenderP.nc | 4 +- tos/lib/net/lqi/LqiForwardingEngineP.nc | 31 +++-------- tos/lib/net/lqi/LqiRoutingEngineP.nc | 6 +-- tos/lib/printf/PrintfP.nc | 2 +- tos/lib/serial/SerialActiveMessageP.nc | 25 ++++----- tos/lib/serial/SerialDispatcherP.nc | 19 +++---- tos/lib/tossim/SerialActiveMessageC.nc | 28 +++------- tos/lib/tossim/TossimActiveMessageC.nc | 30 +++-------- tos/platforms/eyesIFX/ActiveMessageFilterC.nc | 6 +-- tos/system/AMQueueEntryP.nc | 4 +- tos/system/AMQueueImplP.nc | 4 +- 68 files changed, 333 insertions(+), 484 deletions(-) diff --git a/apps/AntiTheft/Nodes/AntiTheftC.nc b/apps/AntiTheft/Nodes/AntiTheftC.nc index 8696be00..6245b6d9 100644 --- a/apps/AntiTheft/Nodes/AntiTheftC.nc +++ b/apps/AntiTheft/Nodes/AntiTheftC.nc @@ -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)); + } } } diff --git a/apps/AntiTheft/Root/AntiTheftRootC.nc b/apps/AntiTheft/Root/AntiTheftRootC.nc index 7a9a2630..896bc812 100644 --- a/apps/AntiTheft/Root/AntiTheftRootC.nc +++ b/apps/AntiTheft/Root/AntiTheftRootC.nc @@ -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; } diff --git a/apps/MViz/MVizC.nc b/apps/MViz/MVizC.nc index 6719d8f0..82f39986 100644 --- a/apps/MViz/MVizC.nc +++ b/apps/MViz/MVizC.nc @@ -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; diff --git a/apps/MultihopOscilloscope/MultihopOscilloscopeC.nc b/apps/MultihopOscilloscope/MultihopOscilloscopeC.nc index fff54d7c..fab09903 100644 --- a/apps/MultihopOscilloscope/MultihopOscilloscopeC.nc +++ b/apps/MultihopOscilloscope/MultihopOscilloscopeC.nc @@ -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; diff --git a/apps/MultihopOscilloscopeLqi/MultihopOscilloscopeC.nc b/apps/MultihopOscilloscopeLqi/MultihopOscilloscopeC.nc index fff54d7c..17edb6b7 100644 --- a/apps/MultihopOscilloscopeLqi/MultihopOscilloscopeC.nc +++ b/apps/MultihopOscilloscopeLqi/MultihopOscilloscopeC.nc @@ -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; diff --git a/apps/Oscilloscope/OscilloscopeC.nc b/apps/Oscilloscope/OscilloscopeC.nc index a198db8f..77cca210 100644 --- a/apps/Oscilloscope/OscilloscopeC.nc +++ b/apps/Oscilloscope/OscilloscopeC.nc @@ -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; } diff --git a/apps/RadioCountToLeds/RadioCountToLedsC.nc b/apps/RadioCountToLeds/RadioCountToLedsC.nc index d5f926f2..fcc3c7c6 100644 --- a/apps/RadioCountToLeds/RadioCountToLedsC.nc +++ b/apps/RadioCountToLeds/RadioCountToLedsC.nc @@ -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; } diff --git a/apps/RadioSenseToLeds/RadioSenseToLedsC.nc b/apps/RadioSenseToLeds/RadioSenseToLedsC.nc index fab38b13..2762d59d 100644 --- a/apps/RadioSenseToLeds/RadioSenseToLedsC.nc +++ b/apps/RadioSenseToLeds/RadioSenseToLedsC.nc @@ -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; diff --git a/apps/tests/RadioStress/RadioStressC.nc b/apps/tests/RadioStress/RadioStressC.nc index 30bc6592..e03a9b26 100644 --- a/apps/tests/RadioStress/RadioStressC.nc +++ b/apps/tests/RadioStress/RadioStressC.nc @@ -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) { diff --git a/apps/tests/TestLocalTime/TestLocalTimeC.nc b/apps/tests/TestLocalTime/TestLocalTimeC.nc index a0093345..f2053570 100644 --- a/apps/tests/TestLocalTime/TestLocalTimeC.nc +++ b/apps/tests/TestLocalTime/TestLocalTimeC.nc @@ -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; diff --git a/apps/tests/TestMultihopLqi/MultihopOscilloscopeC.nc b/apps/tests/TestMultihopLqi/MultihopOscilloscopeC.nc index 55351c52..aed5a437 100644 --- a/apps/tests/TestMultihopLqi/MultihopOscilloscopeC.nc +++ b/apps/tests/TestMultihopLqi/MultihopOscilloscopeC.nc @@ -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"); diff --git a/apps/tests/TestNetwork/TestNetworkC.nc b/apps/tests/TestNetwork/TestNetworkC.nc index 9785967b..cc05e47b 100644 --- a/apps/tests/TestNetwork/TestNetworkC.nc +++ b/apps/tests/TestNetwork/TestNetworkC.nc @@ -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 { diff --git a/apps/tests/TestOscilloscopeLQI/MultihopOscilloscopeC.nc b/apps/tests/TestOscilloscopeLQI/MultihopOscilloscopeC.nc index 9e9e8aae..ad51c6ee 100644 --- a/apps/tests/TestOscilloscopeLQI/MultihopOscilloscopeC.nc +++ b/apps/tests/TestOscilloscopeLQI/MultihopOscilloscopeC.nc @@ -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; diff --git a/apps/tests/TestSerial/TestSerialC.nc b/apps/tests/TestSerial/TestSerialC.nc index 3ced9c32..8278c589 100644 --- a/apps/tests/TestSerial/TestSerialC.nc +++ b/apps/tests/TestSerial/TestSerialC.nc @@ -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; } diff --git a/apps/tests/TestSerialBandwidth/TestSerialC.nc b/apps/tests/TestSerialBandwidth/TestSerialC.nc index b361e3ab..671210b3 100644 --- a/apps/tests/TestSerialBandwidth/TestSerialC.nc +++ b/apps/tests/TestSerialBandwidth/TestSerialC.nc @@ -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(); diff --git a/apps/tests/cc2420/LplBroadcastCountToLeds/RadioCountToLedsC.nc b/apps/tests/cc2420/LplBroadcastCountToLeds/RadioCountToLedsC.nc index 00321487..34576fd1 100644 --- a/apps/tests/cc2420/LplBroadcastCountToLeds/RadioCountToLedsC.nc +++ b/apps/tests/cc2420/LplBroadcastCountToLeds/RadioCountToLedsC.nc @@ -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; } diff --git a/apps/tests/cc2420/LplBroadcastPeriodicDelivery/TestPeriodicP.nc b/apps/tests/cc2420/LplBroadcastPeriodicDelivery/TestPeriodicP.nc index fa5c1917..1e58382d 100644 --- a/apps/tests/cc2420/LplBroadcastPeriodicDelivery/TestPeriodicP.nc +++ b/apps/tests/cc2420/LplBroadcastPeriodicDelivery/TestPeriodicP.nc @@ -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) { diff --git a/apps/tests/cc2420/LplUnicastPeriodicDelivery/TestPeriodicP.nc b/apps/tests/cc2420/LplUnicastPeriodicDelivery/TestPeriodicP.nc index ddb17abb..b6b33489 100644 --- a/apps/tests/cc2420/LplUnicastPeriodicDelivery/TestPeriodicP.nc +++ b/apps/tests/cc2420/LplUnicastPeriodicDelivery/TestPeriodicP.nc @@ -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) { diff --git a/apps/tests/cc2420/RssiToSerial/RssiToSerialP.nc b/apps/tests/cc2420/RssiToSerial/RssiToSerialP.nc index 0b662ff5..0ee4bf3b 100644 --- a/apps/tests/cc2420/RssiToSerial/RssiToSerialP.nc +++ b/apps/tests/cc2420/RssiToSerial/RssiToSerialP.nc @@ -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; diff --git a/apps/tests/cc2420/TestPacketLink/TestPacketLinkP.nc b/apps/tests/cc2420/TestPacketLink/TestPacketLinkP.nc index 8c604921..abb08d2b 100644 --- a/apps/tests/cc2420/TestPacketLink/TestPacketLinkP.nc +++ b/apps/tests/cc2420/TestPacketLink/TestPacketLinkP.nc @@ -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(); diff --git a/apps/tests/cc2420/TxThroughput/TxThroughputP.nc b/apps/tests/cc2420/TxThroughput/TxThroughputP.nc index 31580cd6..2c91487a 100644 --- a/apps/tests/cc2420/TxThroughput/TxThroughputP.nc +++ b/apps/tests/cc2420/TxThroughput/TxThroughputP.nc @@ -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(); } diff --git a/apps/tests/eyesIFX/RadioCountToFlash/RadioCountToFlashC.nc b/apps/tests/eyesIFX/RadioCountToFlash/RadioCountToFlashC.nc index 0ec35e67..bbbabc77 100644 --- a/apps/tests/eyesIFX/RadioCountToFlash/RadioCountToFlashC.nc +++ b/apps/tests/eyesIFX/RadioCountToFlash/RadioCountToFlashC.nc @@ -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; diff --git a/apps/tests/mica2/mts300/TestMts300P.nc b/apps/tests/mica2/mts300/TestMts300P.nc index 334c032f..f0d011da 100644 --- a/apps/tests/mica2/mts300/TestMts300P.nc +++ b/apps/tests/mica2/mts300/TestMts300P.nc @@ -98,7 +98,11 @@ implementation sending_packet = FALSE; packet_ready = FALSE; state = STATE_IDLE; - pMsg = (Mts300Msg*)call RadioPacket.getPayload(&packet, NULL); + pMsg = (Mts300Msg*)call RadioPacket.getPayload(&packet, sizeof(Mts300Msg)); + if (pMsg == NULL) { + call Leds.led0On(); + return; + } // Zero out the accelerometer, chrl@20070213 accel_ave_x = 0; diff --git a/apps/tests/mts300/PhotoTemp/OscilloscopeC.nc b/apps/tests/mts300/PhotoTemp/OscilloscopeC.nc index 277fb031..6ba42ce0 100644 --- a/apps/tests/mts300/PhotoTemp/OscilloscopeC.nc +++ b/apps/tests/mts300/PhotoTemp/OscilloscopeC.nc @@ -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; } diff --git a/apps/tests/storage/Block/RandRWC.nc b/apps/tests/storage/Block/RandRWC.nc index 1744f061..d3afad7f 100644 --- a/apps/tests/storage/Block/RandRWC.nc +++ b/apps/tests/storage/Block/RandRWC.nc @@ -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) diff --git a/apps/tests/storage/CircularLog/RandRWC.nc b/apps/tests/storage/CircularLog/RandRWC.nc index 58ce0b03..db69deab 100644 --- a/apps/tests/storage/CircularLog/RandRWC.nc +++ b/apps/tests/storage/CircularLog/RandRWC.nc @@ -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) diff --git a/apps/tests/storage/Config/RandRWC.nc b/apps/tests/storage/Config/RandRWC.nc index d55ddb76..829c99ce 100644 --- a/apps/tests/storage/Config/RandRWC.nc +++ b/apps/tests/storage/Config/RandRWC.nc @@ -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) diff --git a/apps/tests/storage/SyncLog/SyncLogC.nc b/apps/tests/storage/SyncLog/SyncLogC.nc index 8a8aad60..3bd9b1ff 100644 --- a/apps/tests/storage/SyncLog/SyncLogC.nc +++ b/apps/tests/storage/SyncLog/SyncLogC.nc @@ -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) diff --git a/apps/tutorials/BlinkToRadio/BlinkToRadioC.nc b/apps/tutorials/BlinkToRadio/BlinkToRadioC.nc index 11869665..8dfcd0e9 100644 --- a/apps/tutorials/BlinkToRadio/BlinkToRadioC.nc +++ b/apps/tutorials/BlinkToRadio/BlinkToRadioC.nc @@ -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, diff --git a/tos/chips/cc1000/CC1000ActiveMessageP.nc b/tos/chips/cc1000/CC1000ActiveMessageP.nc index a7a02da3..118c8a81 100644 --- a/tos/chips/cc1000/CC1000ActiveMessageP.nc +++ b/tos/chips/cc1000/CC1000ActiveMessageP.nc @@ -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(); } diff --git a/tos/chips/cc1000/CC1000SendReceiveP.nc b/tos/chips/cc1000/CC1000SendReceiveP.nc index e4e4d77d..31a2fc2c 100644 --- a/tos/chips/cc1000/CC1000SendReceiveP.nc +++ b/tos/chips/cc1000/CC1000SendReceiveP.nc @@ -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) { diff --git a/tos/chips/cc2420/CC2420ActiveMessageP.nc b/tos/chips/cc2420/CC2420ActiveMessageP.nc index 0f934404..2cd35c88 100644 --- a/tos/chips/cc2420/CC2420ActiveMessageP.nc +++ b/tos/chips/cc2420/CC2420ActiveMessageP.nc @@ -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); } diff --git a/tos/chips/cc2420/csma/CC2420CsmaP.nc b/tos/chips/cc2420/csma/CC2420CsmaP.nc index fe497824..9dada4ca 100644 --- a/tos/chips/cc2420/csma/CC2420CsmaP.nc +++ b/tos/chips/cc2420/csma/CC2420CsmaP.nc @@ -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() { diff --git a/tos/chips/cc2420/link/PacketLinkP.nc b/tos/chips/cc2420/link/PacketLinkP.nc index a54645f7..fef6c2bf 100644 --- a/tos/chips/cc2420/link/PacketLinkP.nc +++ b/tos/chips/cc2420/link/PacketLinkP.nc @@ -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); } diff --git a/tos/chips/cc2420/lpl/DefaultLplP.nc b/tos/chips/cc2420/lpl/DefaultLplP.nc index 95c77ed5..1a68ec15 100644 --- a/tos/chips/cc2420/lpl/DefaultLplP.nc +++ b/tos/chips/cc2420/lpl/DefaultLplP.nc @@ -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 ***************/ /** diff --git a/tos/chips/cc2420/receive/CC2420ReceiveP.nc b/tos/chips/cc2420/receive/CC2420ReceiveP.nc index b82e8935..19239df6 100644 --- a/tos/chips/cc2420/receive/CC2420ReceiveP.nc +++ b/tos/chips/cc2420/receive/CC2420ReceiveP.nc @@ -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 diff --git a/tos/chips/cc2420/unique/UniqueReceiveP.nc b/tos/chips/cc2420/unique/UniqueReceiveP.nc index bc3faf07..69aabcb8 100644 --- a/tos/chips/cc2420/unique/UniqueReceiveP.nc +++ b/tos/chips/cc2420/unique/UniqueReceiveP.nc @@ -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) { diff --git a/tos/chips/cc2420/unique/UniqueSendP.nc b/tos/chips/cc2420/unique/UniqueSendP.nc index 1611c45f..7b68edfe 100644 --- a/tos/chips/cc2420/unique/UniqueSendP.nc +++ b/tos/chips/cc2420/unique/UniqueSendP.nc @@ -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 ****************/ diff --git a/tos/chips/tda5250/Tda5250ActiveMessageP.nc b/tos/chips/tda5250/Tda5250ActiveMessageP.nc index c44da61d..5c1a41b6 100644 --- a/tos/chips/tda5250/Tda5250ActiveMessageP.nc +++ b/tos/chips/tda5250/Tda5250ActiveMessageP.nc @@ -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(); } diff --git a/tos/chips/tda5250/mac/CsmaMacP.nc b/tos/chips/tda5250/mac/CsmaMacP.nc index a04e223b..bba168f6 100644 --- a/tos/chips/tda5250/mac/CsmaMacP.nc +++ b/tos/chips/tda5250/mac/CsmaMacP.nc @@ -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); } diff --git a/tos/chips/xe1205/XE1205ActiveMessageP.nc b/tos/chips/xe1205/XE1205ActiveMessageP.nc index 09039d76..4e69fc4d 100644 --- a/tos/chips/xe1205/XE1205ActiveMessageP.nc +++ b/tos/chips/xe1205/XE1205ActiveMessageP.nc @@ -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); - } } diff --git a/tos/chips/xe1205/XE1205SendReceiveP.nc b/tos/chips/xe1205/XE1205SendReceiveP.nc index 77bfff4a..2d5f67ff 100644 --- a/tos/chips/xe1205/XE1205SendReceiveP.nc +++ b/tos/chips/xe1205/XE1205SendReceiveP.nc @@ -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) { diff --git a/tos/interfaces/AMSend.nc b/tos/interfaces/AMSend.nc index 6ccc5af8..27c93d22 100644 --- a/tos/interfaces/AMSend.nc +++ b/tos/interfaces/AMSend.nc @@ -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 Packet.getPayload (minus the - * length parameter) and is included in this interface + * This command behaves identically to Packet.getPayload + * (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); } diff --git a/tos/interfaces/Packet.nc b/tos/interfaces/Packet.nc index 14d4e3e6..2e61a5fb 100644 --- a/tos/interfaces/Packet.nc +++ b/tos/interfaces/Packet.nc @@ -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); } diff --git a/tos/interfaces/Receive.nc b/tos/interfaces/Receive.nc index 91a8d6a8..d6a488cf 100644 --- a/tos/interfaces/Receive.nc +++ b/tos/interfaces/Receive.nc @@ -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 Packet.getPayload, 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 Packet.payloadLength, 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); } diff --git a/tos/interfaces/Send.nc b/tos/interfaces/Send.nc index 897f1dac..a211460c 100644 --- a/tos/interfaces/Send.nc +++ b/tos/interfaces/Send.nc @@ -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 Packet.getPayload (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 Packet.getPayload 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); } diff --git a/tos/lib/byte_radio/LinkLayerP.nc b/tos/lib/byte_radio/LinkLayerP.nc index 84361ec9..abb01636 100644 --- a/tos/lib/byte_radio/LinkLayerP.nc +++ b/tos/lib/byte_radio/LinkLayerP.nc @@ -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 ***********/ diff --git a/tos/lib/byte_radio/PacketSerializerP.nc b/tos/lib/byte_radio/PacketSerializerP.nc index 48615c5c..9ddbcce2 100644 --- a/tos/lib/byte_radio/PacketSerializerP.nc +++ b/tos/lib/byte_radio/PacketSerializerP.nc @@ -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. diff --git a/tos/lib/net/Deluge/DelugePageTransferP.nc b/tos/lib/net/Deluge/DelugePageTransferP.nc index e47a6750..2ceb3ed0 100644 --- a/tos/lib/net/Deluge/DelugePageTransferP.nc +++ b/tos/lib/net/Deluge/DelugePageTransferP.nc @@ -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; diff --git a/tos/lib/net/Deluge/FlashVolumeManager/FlashVolumeManagerP.nc b/tos/lib/net/Deluge/FlashVolumeManager/FlashVolumeManagerP.nc index 110833bb..5c03b0ab 100644 --- a/tos/lib/net/Deluge/FlashVolumeManager/FlashVolumeManagerP.nc +++ b/tos/lib/net/Deluge/FlashVolumeManager/FlashVolumeManagerP.nc @@ -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: diff --git a/tos/lib/net/Deluge/ObjectTransferP.nc b/tos/lib/net/Deluge/ObjectTransferP.nc index d2c2d820..8c6b4996 100644 --- a/tos/lib/net/Deluge/ObjectTransferP.nc +++ b/tos/lib/net/Deluge/ObjectTransferP.nc @@ -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; diff --git a/tos/lib/net/DisseminationEngineImplP.nc b/tos/lib/net/DisseminationEngineImplP.nc index 6ee3e366..16be42f0 100644 --- a/tos/lib/net/DisseminationEngineImplP.nc +++ b/tos/lib/net/DisseminationEngineImplP.nc @@ -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 ) { diff --git a/tos/lib/net/SendVirtualizerP.nc b/tos/lib/net/SendVirtualizerP.nc index 1e291bb3..01ea6878 100644 --- a/tos/lib/net/SendVirtualizerP.nc +++ b/tos/lib/net/SendVirtualizerP.nc @@ -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) { diff --git a/tos/lib/net/UARTDebugSenderP.nc b/tos/lib/net/UARTDebugSenderP.nc index b339d87b..ebce09bb 100644 --- a/tos/lib/net/UARTDebugSenderP.nc +++ b/tos/lib/net/UARTDebugSenderP.nc @@ -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; diff --git a/tos/lib/net/ctp/CtpForwardingEngineP.nc b/tos/lib/net/ctp/CtpForwardingEngineP.nc index b436c668..e7cb53ce 100644 --- a/tos/lib/net/ctp/CtpForwardingEngineP.nc +++ b/tos/lib/net/ctp/CtpForwardingEngineP.nc @@ -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;} diff --git a/tos/lib/net/ctp/CtpRoutingEngineP.nc b/tos/lib/net/ctp/CtpRoutingEngineP.nc index fb8aad78..7c881030 100644 --- a/tos/lib/net/ctp/CtpRoutingEngineP.nc +++ b/tos/lib/net/ctp/CtpRoutingEngineP.nc @@ -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()); } diff --git a/tos/lib/net/le/LinkEstimatorP.nc b/tos/lib/net/le/LinkEstimatorP.nc index ebfa4430..3689b407 100644 --- a/tos/lib/net/le/LinkEstimatorP.nc +++ b/tos/lib/net/le/LinkEstimatorP.nc @@ -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; } } diff --git a/tos/lib/net/lqi/CollectionSenderP.nc b/tos/lib/net/lqi/CollectionSenderP.nc index 708085ae..f8395944 100644 --- a/tos/lib/net/lqi/CollectionSenderP.nc +++ b/tos/lib/net/lqi/CollectionSenderP.nc @@ -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() { diff --git a/tos/lib/net/lqi/LqiForwardingEngineP.nc b/tos/lib/net/lqi/LqiForwardingEngineP.nc index 59917f95..45cba9dc 100644 --- a/tos/lib/net/lqi/LqiForwardingEngineP.nc +++ b/tos/lib/net/lqi/LqiForwardingEngineP.nc @@ -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; } diff --git a/tos/lib/net/lqi/LqiRoutingEngineP.nc b/tos/lib/net/lqi/LqiRoutingEngineP.nc index 89ede9dc..d9e76cbf 100644 --- a/tos/lib/net/lqi/LqiRoutingEngineP.nc +++ b/tos/lib/net/lqi/LqiRoutingEngineP.nc @@ -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++; diff --git a/tos/lib/printf/PrintfP.nc b/tos/lib/printf/PrintfP.nc index c69c809a..5f4ae231 100644 --- a/tos/lib/printf/PrintfP.nc +++ b/tos/lib/printf/PrintfP.nc @@ -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); diff --git a/tos/lib/serial/SerialActiveMessageP.nc b/tos/lib/serial/SerialActiveMessageP.nc index 793899bf..0eb5e685 100644 --- a/tos/lib/serial/SerialActiveMessageP.nc +++ b/tos/lib/serial/SerialActiveMessageP.nc @@ -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() { diff --git a/tos/lib/serial/SerialDispatcherP.nc b/tos/lib/serial/SerialDispatcherP.nc index fdcb5b6f..5f1a9b6b 100644 --- a/tos/lib/serial/SerialDispatcherP.nc +++ b/tos/lib/serial/SerialDispatcherP.nc @@ -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; diff --git a/tos/lib/tossim/SerialActiveMessageC.nc b/tos/lib/tossim/SerialActiveMessageC.nc index d436e355..9b0fe461 100644 --- a/tos/lib/tossim/SerialActiveMessageC.nc +++ b/tos/lib/tossim/SerialActiveMessageC.nc @@ -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) { diff --git a/tos/lib/tossim/TossimActiveMessageC.nc b/tos/lib/tossim/TossimActiveMessageC.nc index 47a29214..eb9f49b2 100644 --- a/tos/lib/tossim/TossimActiveMessageC.nc +++ b/tos/lib/tossim/TossimActiveMessageC.nc @@ -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) { diff --git a/tos/platforms/eyesIFX/ActiveMessageFilterC.nc b/tos/platforms/eyesIFX/ActiveMessageFilterC.nc index ebb9a38c..26a83e27 100644 --- a/tos/platforms/eyesIFX/ActiveMessageFilterC.nc +++ b/tos/platforms/eyesIFX/ActiveMessageFilterC.nc @@ -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;} diff --git a/tos/system/AMQueueEntryP.nc b/tos/system/AMQueueEntryP.nc index c1c0f380..2f96c394 100644 --- a/tos/system/AMQueueEntryP.nc +++ b/tos/system/AMQueueEntryP.nc @@ -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); } } diff --git a/tos/system/AMQueueImplP.nc b/tos/system/AMQueueImplP.nc index 51cd2aec..a2998d01 100644 --- a/tos/system/AMQueueImplP.nc +++ b/tos/system/AMQueueImplP.nc @@ -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) { -- 2.39.2