mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-12-22 10:30:13 +00:00
Add a CRC checksum to all collect packets to ensure that they are valid, even if they are running on top of a radio link with bit errors
This commit is contained in:
parent
144927c12b
commit
9f08d7c6de
@ -28,7 +28,7 @@
|
|||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
* $Id: shell-rime.c,v 1.6 2008/07/04 08:23:00 adamdunkels Exp $
|
* $Id: shell-rime.c,v 1.7 2008/07/07 23:22:59 adamdunkels Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,6 +44,7 @@
|
|||||||
|
|
||||||
#include "dev/leds.h"
|
#include "dev/leds.h"
|
||||||
|
|
||||||
|
#include "lib/crc16.h"
|
||||||
#include "lib/random.h"
|
#include "lib/random.h"
|
||||||
|
|
||||||
#include "net/rime.h"
|
#include "net/rime.h"
|
||||||
@ -74,9 +75,10 @@ struct trickle_msg {
|
|||||||
uint8_t type;
|
uint8_t type;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define COLLECT_MSG_HDRSIZE 2
|
#define COLLECT_MSG_HDRSIZE 4
|
||||||
struct collect_msg {
|
struct collect_msg {
|
||||||
uint16_t timestamp;
|
uint16_t timestamp;
|
||||||
|
uint16_t crc;
|
||||||
uint8_t data[1];
|
uint8_t data[1];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -376,6 +378,7 @@ PROCESS_THREAD(shell_send_process, ev, data)
|
|||||||
#else
|
#else
|
||||||
msg->timestamp = 0;
|
msg->timestamp = 0;
|
||||||
#endif
|
#endif
|
||||||
|
msg->crc = crc16_data(msg->data, len, 0);
|
||||||
/* printf("Sending %d bytes\n", len);*/
|
/* printf("Sending %d bytes\n", len);*/
|
||||||
collect_send(&collect, COLLECT_REXMITS);
|
collect_send(&collect, COLLECT_REXMITS);
|
||||||
}
|
}
|
||||||
@ -388,6 +391,7 @@ recv_collect(const rimeaddr_t *originator, u8_t seqno, u8_t hops)
|
|||||||
{
|
{
|
||||||
struct collect_msg *collect_msg;
|
struct collect_msg *collect_msg;
|
||||||
rtimer_clock_t latency;
|
rtimer_clock_t latency;
|
||||||
|
int len;
|
||||||
|
|
||||||
collect_msg = rimebuf_dataptr();
|
collect_msg = rimebuf_dataptr();
|
||||||
|
|
||||||
@ -406,17 +410,22 @@ recv_collect(const rimeaddr_t *originator, u8_t seqno, u8_t hops)
|
|||||||
uint16_t latency;
|
uint16_t latency;
|
||||||
} msg;
|
} msg;
|
||||||
|
|
||||||
|
if(rimebuf_datalen() >= COLLECT_MSG_HDRSIZE) {
|
||||||
msg.len = 5 + (rimebuf_datalen() - COLLECT_MSG_HDRSIZE) / 2;
|
len = rimebuf_datalen() - COLLECT_MSG_HDRSIZE;
|
||||||
rimeaddr_copy((rimeaddr_t *)&msg.originator, originator);
|
|
||||||
msg.seqno = seqno;
|
if(collect_msg->crc == crc16_data(collect_msg->data, len, 0)) {
|
||||||
msg.hops = hops;
|
msg.len = 5 + (rimebuf_datalen() - COLLECT_MSG_HDRSIZE) / 2;
|
||||||
msg.latency = latency;
|
rimeaddr_copy((rimeaddr_t *)&msg.originator, originator);
|
||||||
/* printf("recv_collect datalen %d\n", rimebuf_datalen());*/
|
msg.seqno = seqno;
|
||||||
|
msg.hops = hops;
|
||||||
shell_output(&collect_command,
|
msg.latency = latency;
|
||||||
&msg, sizeof(msg),
|
/* printf("recv_collect datalen %d\n", rimebuf_datalen());*/
|
||||||
collect_msg->data, rimebuf_datalen() - COLLECT_MSG_HDRSIZE);
|
|
||||||
|
shell_output(&collect_command,
|
||||||
|
&msg, sizeof(msg),
|
||||||
|
collect_msg->data, rimebuf_datalen() - COLLECT_MSG_HDRSIZE);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if(waiting_for_nodes) {
|
} else if(waiting_for_nodes) {
|
||||||
char buf[40];
|
char buf[40];
|
||||||
snprintf(buf, sizeof(buf), "%d.%d, %d hops, latency %lu ms",
|
snprintf(buf, sizeof(buf), "%d.%d, %d hops, latency %lu ms",
|
||||||
|
Loading…
Reference in New Issue
Block a user