From 971af2b2495089e7f26166513c7a2d0cd74364c1 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Wed, 10 Feb 2016 12:02:50 +0200 Subject: [PATCH] cc2520: packetbuf attributes were set using wrong pointer The buf pointer in cc2520_read() points to memory that will hold the received data. It must not be used to set RSSI and link quality values. Very difficult to find memory corruption was seen as we were overwriting memory in other part of the system. The fix was to set the RSSI and link quality variables in read_packet() where the buf pointer points to proper memory. Change-Id: I49bfe37f4c7ccc0f582f3aecdf73d5b3ea6bb4e5 Signed-off-by: Jukka Rissanen --- drivers/802.15.4/cc2520.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/802.15.4/cc2520.c b/drivers/802.15.4/cc2520.c index 8dfddfca69d..2492999df73 100644 --- a/drivers/802.15.4/cc2520.c +++ b/drivers/802.15.4/cc2520.c @@ -866,11 +866,6 @@ static int cc2520_read(void *buf, unsigned short bufsize) if (footer[1] & FOOTER1_CRC_OK) { cc2520_last_rssi = footer[0]; cc2520_last_correlation = footer[1] & FOOTER1_CORRELATION; - - packetbuf_set_attr(buf, PACKETBUF_ATTR_RSSI, cc2520_last_rssi); - packetbuf_set_attr(buf, PACKETBUF_ATTR_LINK_QUALITY, - cc2520_last_correlation); - } else { goto error; } @@ -916,6 +911,9 @@ static void read_packet(void) goto out; } + packetbuf_set_attr(buf, PACKETBUF_ATTR_RSSI, cc2520_last_rssi); + packetbuf_set_attr(buf, PACKETBUF_ATTR_LINK_QUALITY, + cc2520_last_correlation); packetbuf_set_datalen(buf, len); DBG("%s: received %d bytes\n", __func__, len);