diff --git a/tools/cooja/java/se/sics/cooja/plugins/RadioLogger.java b/tools/cooja/java/se/sics/cooja/plugins/RadioLogger.java
index b1825a370..4c2fdf79d 100644
--- a/tools/cooja/java/se/sics/cooja/plugins/RadioLogger.java
+++ b/tools/cooja/java/se/sics/cooja/plugins/RadioLogger.java
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: RadioLogger.java,v 1.29 2010/03/03 12:45:39 nifi Exp $
+ * $Id: RadioLogger.java,v 1.30 2010/03/07 19:53:07 joxe Exp $
*/
package se.sics.cooja.plugins;
@@ -421,8 +421,7 @@ public class RadioLogger extends VisPlugin {
analyze = false;
for (int i = 0; i < analyzers.size(); i++) {
PacketAnalyzer analyzer = analyzers.get(i);
- if (analyzer.matchPacket(packet)) {
- analyzer.analyzePacket(packet, brief, verbose);
+ if (analyzer.matchPacket(packet) && analyzer.analyzePacket(packet, brief, verbose)) {
/* continue another round if more bytes left */
analyze = packet.hasMoreData();
brief.append('|');
diff --git a/tools/cooja/java/se/sics/cooja/plugins/analyzers/IEEE802154Analyzer.java b/tools/cooja/java/se/sics/cooja/plugins/analyzers/IEEE802154Analyzer.java
index 464480bb7..b46ac4df3 100644
--- a/tools/cooja/java/se/sics/cooja/plugins/analyzers/IEEE802154Analyzer.java
+++ b/tools/cooja/java/se/sics/cooja/plugins/analyzers/IEEE802154Analyzer.java
@@ -42,7 +42,7 @@ public class IEEE802154Analyzer extends PacketAnalyzer {
/* create a 802.15.4 packet of the bytes and "dispatch" to the
* next handler
*/
- public void analyzePacket(Packet packet, StringBuffer brief, StringBuffer verbose) {
+ public boolean analyzePacket(Packet packet, StringBuffer brief, StringBuffer verbose) {
int pos = packet.pos;
int type = packet.data[pos + 0] & 7;
// int security = (packet.data[pos + 0] >> 3) & 1;
@@ -108,29 +108,33 @@ public class IEEE802154Analyzer extends PacketAnalyzer {
verbose.append("IEEE 802.15.4 ")
.append(type < typeVerbose.length ? typeVerbose[type] : "?")
- .append(' ').append(seqNumber)
- .append("
From ");
- if (srcPanID != 0) {
- verbose.append(StringUtils.toHex((byte)(srcPanID >> 8)))
- .append(StringUtils.toHex((byte)(srcPanID & 0xff)))
- .append('/');
+ .append(' ').append(seqNumber);
+ if (type != ACKFRAME) {
+ verbose.append("
From ");
+ if (srcPanID != 0) {
+ verbose.append(StringUtils.toHex((byte)(srcPanID >> 8)))
+ .append(StringUtils.toHex((byte)(srcPanID & 0xff)))
+ .append('/');
+ }
+ printAddress(verbose, srcAddrMode, sourceAddress);
+ verbose.append(" to ");
+ if (destPanID != 0) {
+ verbose.append(StringUtils.toHex((byte)(destPanID >> 8)))
+ .append(StringUtils.toHex((byte)(destPanID & 0xff)))
+ .append('/');
+ }
+ printAddress(verbose, destAddrMode, destAddress);
}
- printAddress(verbose, srcAddrMode, sourceAddress);
- verbose.append(" to ");
- if (destPanID != 0) {
- verbose.append(StringUtils.toHex((byte)(destPanID >> 8)))
- .append(StringUtils.toHex((byte)(destPanID & 0xff)))
- .append('/');
- }
- printAddress(verbose, destAddrMode, destAddress);
- // verbose.append("
Payload len: ").append(payloadLen);
/* update packet */
packet.pos = pos;
packet.level = NETWORK_LEVEL;
+ /* remove CRC from the packet */
+ packet.consumeBytesEnd(2);
packet.llsender = sourceAddress;
packet.llreceiver = destAddress;
+ return true;
}
private void printAddress(StringBuffer sb, int type, byte[] addr) {
diff --git a/tools/cooja/java/se/sics/cooja/plugins/analyzers/IPHCPacketAnalyzer.java b/tools/cooja/java/se/sics/cooja/plugins/analyzers/IPHCPacketAnalyzer.java
index a6ec2dfbb..53a683591 100644
--- a/tools/cooja/java/se/sics/cooja/plugins/analyzers/IPHCPacketAnalyzer.java
+++ b/tools/cooja/java/se/sics/cooja/plugins/analyzers/IPHCPacketAnalyzer.java
@@ -64,9 +64,12 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer {
return (packet.get(0) & 0xe0) == IPHC_DISPATCH;
}
- public void analyzePacket(Packet packet, StringBuffer brief,
+ public boolean analyzePacket(Packet packet, StringBuffer brief,
StringBuffer verbose) {
+ /* if packet has less than 3 bytes it is not interesting ... */
+ if (packet.size() < 3) return false;
+
int tf = (packet.get(0) >> 3) & 0x03;
int nh = (packet.get(0) >> 2) & 0x01;
int hlim = (packet.get(0) & 0x03);
@@ -372,7 +375,7 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer {
break;
default:
// PRINTF("sicslowpan uncompress_hdr: error unsupported UDP compression\n");
- return;
+ return false;
}
}
}
@@ -410,8 +413,8 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer {
verbose.append(" to ");
printAddress(verbose, destAddress);
-// packet.pos = packet.data.length;
packet.level = NETWORK_LEVEL;
+ return true;
}
public static void printAddress(StringBuffer out, byte[] address) {
diff --git a/tools/cooja/java/se/sics/cooja/plugins/analyzers/PacketAnalyzer.java b/tools/cooja/java/se/sics/cooja/plugins/analyzers/PacketAnalyzer.java
index d1d1309e4..a4762754e 100644
--- a/tools/cooja/java/se/sics/cooja/plugins/analyzers/PacketAnalyzer.java
+++ b/tools/cooja/java/se/sics/cooja/plugins/analyzers/PacketAnalyzer.java
@@ -10,7 +10,9 @@ public abstract class PacketAnalyzer {
byte[] data;
int pos;
int level;
-
+ /* size = length - consumed bytes at tail */
+ int size;
+
/* L2 addresseses */
byte[] llsender;
byte[] llreceiver;
@@ -18,13 +20,29 @@ public abstract class PacketAnalyzer {
public Packet(byte[] data, int level) {
this.level = level;
this.data = data;
+ this.size = data.length;
}
+
+ public void consumeBytesStart(int bytes) {
+ pos += bytes;
+ }
+
+ public void consumeBytesEnd(int bytes) {
+ size -= bytes;
+ }
+
+
public boolean hasMoreData() {
- return data.length > pos;
+ return size > pos;
+ }
+
+ public int size() {
+ return size - pos;
}
public byte get(int index) {
+ if (index >= size) return 0;
return data[pos + index];
}
@@ -38,7 +56,7 @@ public abstract class PacketAnalyzer {
public byte[] getPayload() {
- byte[] pload = new byte[data.length - pos];
+ byte[] pload = new byte[size - pos];
System.arraycopy(data, pos, pload, 0, pload.length);
return pload;
}
@@ -60,5 +78,5 @@ public abstract class PacketAnalyzer {
public abstract boolean matchPacket(Packet packet);
- public abstract void analyzePacket(Packet packet, StringBuffer brief, StringBuffer verbose);
+ public abstract boolean analyzePacket(Packet packet, StringBuffer brief, StringBuffer verbose);
}
\ No newline at end of file