/* 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));
+ }
}
}
{
/* 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;
}
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 {
*/
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;
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 {
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) {
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;
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 {
}
//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) {
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;
{
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;
}
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;
}
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;
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) {
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;
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 {
}
//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) {
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");
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;
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 {
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 {
}
//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) {
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;
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;
}
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;
}
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();
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;
}
/**************** 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) {
/**************** 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) {
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;
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);
}
}
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();
/***************** 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();
}
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;
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
{
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;
}
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)
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)
}
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)
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)
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,
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 */
}
}
- 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();
}
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) {
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) {
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();
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);
}
}
- 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() {
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);
}
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);
}
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 ***************/
/**
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
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) {
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 ****************/
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 */
}
}
- 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();
}
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);
}
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,
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);
- }
}
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;
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) {
/**
* 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);
}
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);
}
*/
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);
}
/**
- * 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);
}
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) {
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);
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 ***********/
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.
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;
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) {
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);
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;
*/
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 {
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));
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;
}
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:
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;
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 ) {
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 ) {
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) {
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;
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;
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;
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;
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;
}
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));
}
/*
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);
}
/*
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;
}
*/
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;
// 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);
}
}
- 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();
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;}
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);
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());
}
// 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
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
}
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();
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);
}
}
// 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;
}
}
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() {
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));
}
/***********************************************************************
}
- 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() {
}
- 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);
}
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;
}
}
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() {
}
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++;
}
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);
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) {
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);
}
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() {
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;
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();
}
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) {
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;
}
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());
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) {
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;}
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);
}
}
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) {