135u5 / tinyos-main

Automatically exported from code.google.com/p/tinyos-main
1 stars 0 forks source link

TOSSIM receive serial bug #9

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
When receiving a packet from the serial in TOSSIM the current code assumes that 
the incoming serial packet is aligned with the message_t structure.  As the 
message_header_t structure is a union of the tossim_header_t and 
serial_header_t this is not the case when 
sizeof(tossim_header_t)>sizeof(serial_header_t).

Thus when the tossim/sf/sim/SerialActiveMessageC receives a packet from the 
serial it needs to be copied into the message_t at the correct offset.  The 
diff of the tossim/sf/sim/SerialActiveMessageC below fixes this issue:

@@ -276,8 +276,9 @@ implementation {

     sim_event_t* allocate_serial_deliver_event(int node, message_t* msg, sim_time_t t) {
         sim_event_t* evt = (sim_event_t*)malloc(sizeof(sim_event_t));
-       memcpy(newMsg, msg, sizeof(message_t));
+        uint8_t payloadLength = ((serial_header_t*)msg->header)->length;
+        memcpy(getHeader(newMsg), msg, sizeof(serial_header_t)+payloadLength);

         evt->mote = node;
         evt->time = t;

Original issue reported on code.google.com by mortenthansen on 24 Nov 2010 at 12:41

GoogleCodeExporter commented 8 years ago
Doesn't the above fix repeat the problem on msg? Shouldn't it be

-       memcpy(newMsg, msg, sizeof(message_t));
+        uint8_t payloadLength = getHeader(msg)->length;
+        memcpy(getHeader(newMsg), msg, sizeof(serial_header_t)+payloadLength);

Phil

Original comment by philip.l...@gmail.com on 16 Dec 2010 at 11:51

GoogleCodeExporter commented 8 years ago
I doubt your version will work.  

The incomming packet (message_t* msg) is always from a serial forwarder which 
have no idea about the header alignment of TOSSIM messages and will then be 
aligned with msg->header.  The new packet (message_t* newMsg) should have the 
prober alignment so on this message_t we should use getHeader(newMsg).

Does this make sense?

Morten.

Original comment by mortenthansen on 17 Dec 2010 at 1:44

GoogleCodeExporter commented 8 years ago
It does. Sorry, it's been a long time since I saw this code; I forgot that the 
message coming in will be aligned at the beginning of the struct, not the 
proper header position. This actually suggests the typing of the functions is 
wrong, as technically it's not a message_t being passed in. But oh well.

I'll test your fix on Monday and check it in if it works for me.

Original comment by philip.l...@gmail.com on 18 Dec 2010 at 1:42

GoogleCodeExporter commented 8 years ago
I applied your fix.

Original comment by philip.l...@gmail.com on 22 Dec 2010 at 12:30