Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TOSSIM receive serial bug #12

Closed
tinyos-issues opened this issue Dec 21, 2012 · 4 comments
Closed

TOSSIM receive serial bug #12

tinyos-issues opened this issue Dec 21, 2012 · 4 comments

Comments

@tinyos-issues
Copy link
Member

Original author: mortenthansen (November 24, 2010 00:41:45)

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: http://code.google.com/p/tinyos-main/issues/detail?id=9

@tinyos-issues
Copy link
Member Author

From philip.l...@gmail.com on December 16, 2010 23:51:26
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

@tinyos-issues
Copy link
Member Author

From mortenthansen on December 17, 2010 01:44:33
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.

@tinyos-issues
Copy link
Member Author

From philip.l...@gmail.com on December 18, 2010 01:42:30
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.

@tinyos-issues
Copy link
Member Author

From philip.l...@gmail.com on December 22, 2010 00:30:50
I applied your fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant