X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=tos%2Fchips%2Fcc2420%2FCC2420ActiveMessageP.nc;h=0db2423c7b83167d7bf41b4797e85c117b52cb8f;hb=42b450d2e6d5eda17245d38f4d2bceb6b60e5400;hp=d6a6fbd09466c775e56b74a8b92295d260370179;hpb=12235829757689b4afb8f04001109a452d2b35d2;p=tinyos-2.x.git diff --git a/tos/chips/cc2420/CC2420ActiveMessageP.nc b/tos/chips/cc2420/CC2420ActiveMessageP.nc index d6a6fbd0..0db2423c 100644 --- a/tos/chips/cc2420/CC2420ActiveMessageP.nc +++ b/tos/chips/cc2420/CC2420ActiveMessageP.nc @@ -1,4 +1,4 @@ -/* tab:4 +/* * "Copyright (c) 2005 Stanford University. All rights reserved. * * Permission to use, copy, modify, and distribute this software and @@ -34,7 +34,7 @@ #include "CC2420.h" -module CC2420ActiveMessageP { +module CC2420ActiveMessageP @safe() { provides { interface AMSend[am_id_t id]; interface Receive[am_id_t id]; @@ -57,15 +57,16 @@ module CC2420ActiveMessageP { } implementation { - enum { - CC2420_SIZE = MAC_HEADER_SIZE + MAC_FOOTER_SIZE, - }; - /***************** AMSend Commands ****************/ command error_t AMSend.send[am_id_t id](am_addr_t addr, message_t* msg, uint8_t len) { cc2420_header_t* header = call CC2420PacketBody.getHeader( msg ); + + if (len > call Packet.maxPayloadLength()) { + return ESIZE; + } + header->type = id; header->dest = addr; header->destpan = call CC2420Config.getPanAddr(); @@ -73,7 +74,7 @@ implementation { signal SendNotifier.aboutToSend[id](addr, msg); - return call SubSend.send( msg, len + CC2420_SIZE ); + return call SubSend.send( msg, len ); } command error_t AMSend.cancel[am_id_t id](message_t* msg) { @@ -179,10 +180,10 @@ implementation { } if (call AMPacket.isForMe(msg)) { - return signal Receive.receive[call AMPacket.type(msg)](msg, payload, len - CC2420_SIZE); + return signal Receive.receive[call AMPacket.type(msg)](msg, payload, len); } else { - return signal Snoop.receive[call AMPacket.type(msg)](msg, payload, len - CC2420_SIZE); + return signal Snoop.receive[call AMPacket.type(msg)](msg, payload, len); } } @@ -199,18 +200,18 @@ implementation { /***************** RadioBackoff ***********************/ async event void SubBackoff.requestInitialBackoff(message_t *msg) { - signal RadioBackoff.requestInitialBackoff[((cc2420_header_t*)(msg->data - - sizeof(cc2420_header_t)))->type](msg); + signal RadioBackoff.requestInitialBackoff[(TCAST(cc2420_header_t* ONE, + (uint8_t*)msg + offsetof(message_t, data) - sizeof(cc2420_header_t)))->type](msg); } async event void SubBackoff.requestCongestionBackoff(message_t *msg) { - signal RadioBackoff.requestCongestionBackoff[((cc2420_header_t*)(msg->data - - sizeof(cc2420_header_t)))->type](msg); + signal RadioBackoff.requestCongestionBackoff[(TCAST(cc2420_header_t* ONE, + (uint8_t*)msg + offsetof(message_t, data) - sizeof(cc2420_header_t)))->type](msg); } async event void SubBackoff.requestCca(message_t *msg) { // Lower layers than this do not configure the CCA settings - signal RadioBackoff.requestCca[((cc2420_header_t*)(msg->data - - sizeof(cc2420_header_t)))->type](msg); + signal RadioBackoff.requestCca[(TCAST(cc2420_header_t* ONE, + (uint8_t*)msg + offsetof(message_t, data) - sizeof(cc2420_header_t)))->type](msg); } async command void RadioBackoff.setInitialBackoff[am_id_t amId](uint16_t backoffTime) {