fixed 6lowpan analyzer
This commit is contained in:
parent
8ca206aa6b
commit
577056c452
4 changed files with 50 additions and 26 deletions
|
@ -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('|');
|
||||
|
|
|
@ -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,8 +108,9 @@ public class IEEE802154Analyzer extends PacketAnalyzer {
|
|||
|
||||
verbose.append("<html><b>IEEE 802.15.4 ")
|
||||
.append(type < typeVerbose.length ? typeVerbose[type] : "?")
|
||||
.append(' ').append(seqNumber)
|
||||
.append("</b><br>From ");
|
||||
.append(' ').append(seqNumber);
|
||||
if (type != ACKFRAME) {
|
||||
verbose.append("</b><br>From ");
|
||||
if (srcPanID != 0) {
|
||||
verbose.append(StringUtils.toHex((byte)(srcPanID >> 8)))
|
||||
.append(StringUtils.toHex((byte)(srcPanID & 0xff)))
|
||||
|
@ -123,14 +124,17 @@ public class IEEE802154Analyzer extends PacketAnalyzer {
|
|||
.append('/');
|
||||
}
|
||||
printAddress(verbose, destAddrMode, destAddress);
|
||||
// verbose.append("<br>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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -10,6 +10,8 @@ public abstract class PacketAnalyzer {
|
|||
byte[] data;
|
||||
int pos;
|
||||
int level;
|
||||
/* size = length - consumed bytes at tail */
|
||||
int size;
|
||||
|
||||
/* L2 addresseses */
|
||||
byte[] llsender;
|
||||
|
@ -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);
|
||||
}
|
Loading…
Reference in a new issue