removed previous workaround for already fixed bug in CC2420 CRC

This commit is contained in:
fros4943 2010-03-26 13:33:40 +00:00
parent 9508d2c4d7
commit 90f174509b

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: CC2420RadioPacketConverter.java,v 1.15 2010/03/09 10:37:47 nifi Exp $ * $Id: CC2420RadioPacketConverter.java,v 1.16 2010/03/26 13:33:40 fros4943 Exp $
*/ */
package se.sics.cooja.mspmote.interfaces; package se.sics.cooja.mspmote.interfaces;
@ -54,7 +54,7 @@ public class CC2420RadioPacketConverter {
int pos = 0; int pos = 0;
byte packetData[] = packet.getPacketData(); byte packetData[] = packet.getPacketData();
byte len; /* total packet minus preamble(4), synch(1) and length(1) */ byte len; /* total packet minus preamble(4), synch(1) and length(1) */
WrapperCC2420CRC cc2420CRC = new WrapperCC2420CRC(); CCITT_CRC cc2420CRC = new CCITT_CRC();
short contikiCRC = 0; short contikiCRC = 0;
/* 4 bytes preamble */ /* 4 bytes preamble */
@ -90,29 +90,29 @@ public class CC2420RadioPacketConverter {
/* 4 byte X-MAC: not implemented */ /* 4 byte X-MAC: not implemented */
if (WITH_XMAC) { if (WITH_XMAC) {
cc2420Data[pos++] = 1; /* TYPE_DATA */ cc2420Data[pos++] = 1; /* TYPE_DATA */
cc2420CRC.add(1); cc2420CRC.addBitrev(1);
contikiCRC = CRCCoder.crc16Add((byte)0, contikiCRC); contikiCRC = CRCCoder.crc16Add((byte)0, contikiCRC);
cc2420Data[pos++] = 0; cc2420Data[pos++] = 0;
cc2420CRC.add(0); cc2420CRC.addBitrev(0);
contikiCRC = CRCCoder.crc16Add((byte)0, contikiCRC); contikiCRC = CRCCoder.crc16Add((byte)0, contikiCRC);
cc2420Data[pos++] = 0; /* XXX sender: 0.0 */ cc2420Data[pos++] = 0; /* XXX sender: 0.0 */
cc2420CRC.add(0); cc2420CRC.addBitrev(0);
contikiCRC = CRCCoder.crc16Add((byte)0, contikiCRC); contikiCRC = CRCCoder.crc16Add((byte)0, contikiCRC);
cc2420Data[pos++] = 0; cc2420Data[pos++] = 0;
cc2420CRC.add(0); cc2420CRC.addBitrev(0);
contikiCRC = CRCCoder.crc16Add((byte)0, contikiCRC); contikiCRC = CRCCoder.crc16Add((byte)0, contikiCRC);
cc2420Data[pos++] = 0; /* XXX receiver: 0.0 */ cc2420Data[pos++] = 0; /* XXX receiver: 0.0 */
cc2420CRC.add(0); cc2420CRC.addBitrev(0);
contikiCRC = CRCCoder.crc16Add((byte)0, contikiCRC); contikiCRC = CRCCoder.crc16Add((byte)0, contikiCRC);
cc2420Data[pos++] = 0; cc2420Data[pos++] = 0;
cc2420CRC.add(0); cc2420CRC.addBitrev(0);
contikiCRC = CRCCoder.crc16Add((byte)0, contikiCRC); contikiCRC = CRCCoder.crc16Add((byte)0, contikiCRC);
} }
/* Payload */ /* Payload */
for (byte b : packetData) { for (byte b : packetData) {
contikiCRC = CRCCoder.crc16Add(b, contikiCRC); contikiCRC = CRCCoder.crc16Add(b, contikiCRC);
cc2420CRC.add(b & 0xFF); cc2420CRC.addBitrev(b & 0xFF);
} }
System.arraycopy(packetData, 0, cc2420Data, pos, packetData.length); System.arraycopy(packetData, 0, cc2420Data, pos, packetData.length);
pos += packetData.length; pos += packetData.length;
@ -120,28 +120,25 @@ public class CC2420RadioPacketConverter {
/* 2 bytes checksum */ /* 2 bytes checksum */
if (WITH_CHECKSUM) { if (WITH_CHECKSUM) {
cc2420Data[pos++] = (byte) (contikiCRC & 0xff); cc2420Data[pos++] = (byte) (contikiCRC & 0xff);
cc2420CRC.add(contikiCRC & 0xFF); cc2420CRC.addBitrev(contikiCRC & 0xFF);
cc2420Data[pos++] = (byte) ((contikiCRC >> 8) & 0xff); cc2420Data[pos++] = (byte) ((contikiCRC >> 8) & 0xff);
cc2420CRC.add((contikiCRC >> 8) & 0xFF); cc2420CRC.addBitrev((contikiCRC >> 8) & 0xFF);
} }
/* (TODO) 3 bytes timestamp */ /* (TODO) 3 bytes timestamp */
if (WITH_TIMESTAMP) { if (WITH_TIMESTAMP) {
cc2420Data[pos++] = 0; cc2420Data[pos++] = 0;
cc2420CRC.add(0); cc2420CRC.addBitrev(0);
cc2420Data[pos++] = 0; cc2420Data[pos++] = 0;
cc2420CRC.add(0); cc2420CRC.addBitrev(0);
cc2420Data[pos++] = 0; cc2420Data[pos++] = 0;
cc2420CRC.add(0); cc2420CRC.addBitrev(0);
} }
/* 2 bytes footer: CC2420's CRC */ /* 2 bytes footer: CC2420's CRC */
if (WITH_FOOTER) { if (WITH_FOOTER) {
/* TODO XXX Workaround for (potential) CC2420 bug: cc2420Data[pos++] = (byte) cc2420CRC.getCRCHi();
* it excludes the last byte in the CRC */ cc2420Data[pos++] = (byte) cc2420CRC.getCRCLow();
int crc = cc2420CRC.getPreviousCRC();
cc2420Data[pos++] = (byte) ((crc >> 8) & 0xff);
cc2420Data[pos++] = (byte) (crc & 0xff);
} }
byte cc2420DataStripped[] = new byte[pos]; byte cc2420DataStripped[] = new byte[pos];
@ -209,18 +206,4 @@ public class CC2420RadioPacketConverter {
return new ConvertedRadioPacket(convertedData, originalData); return new ConvertedRadioPacket(convertedData, originalData);
} }
private static class WrapperCC2420CRC extends CCITT_CRC {
int previous = 0;
public WrapperCC2420CRC() {
super();
}
public int add(int data) {
previous = getCRC();
return super.add(data);
}
public int getPreviousCRC() {
return previous;
}
}
} }