[Tinyos-devel] Packet.clear()

Miklos Maroti mmaroti at math.u-szeged.hu
Wed Oct 17 10:22:09 PDT 2007


Hi Guys,

This is a set of recommendations for the use of the Packet.clear
function, that might go eventually into the one of the TEPs. There was
some discussion on this topic, but I would like to get the opinion of
all of you.

Problem: If a message_t is received with the Receive.receive() event
and later reused and sent as a outgoing packet with the Send.send
command, then the metadata contained inside the message_t might be
corrupted and the packet needs to be cleared. This is especially
important if a packet is received over one interface and resent over
the other, such as received over the radio and retransmitted over the
serial interface. In this case, the layout of the metadata is
different (you event use two different structures: cc2420_metadata_t
and serial_metadata_t for example), so even the format of the metadata
might be incorrect and could instruct the communication layer to do
something not intended (for example retrying a packet for 10000
times).

There is no fool-proof solution to this problem, the user must be
aware of this problem. In general, Packet.clear() MUST be called
before Send.send is called. If the outgoing packet requires some
special handling (such as requiring acknowledgements via the
PacketAcknowledgement or setting low power listing duty cycles) then
those MUST be called between the Packet.clear() command and
Send.send() command.

If the message to be sent is statically allocated in a component and
its ownership does not change (other than passing via Send.send), then
Packet.clear need not be called. In this case ALL metadata used for
transmission MUST NOT be changed by the Send implementation.

The implementation of Packet.clear should clear/initialize ALL
metadata, header and footer data except those that are changed by the
Packet interface, such as the length of the packet. Packet.clear MUST
NOT change the payload of the packet or the length of the packet.

Miklos


More information about the Tinyos-devel mailing list