mirror of
https://github.com/oliverschmidt/contiki.git
synced 2025-01-23 05:29:54 +00:00
fixed 6lowpan analyzer
This commit is contained in:
parent
8ca206aa6b
commit
577056c452
@ -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: 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;
|
package se.sics.cooja.plugins;
|
||||||
@ -421,8 +421,7 @@ public class RadioLogger extends VisPlugin {
|
|||||||
analyze = false;
|
analyze = false;
|
||||||
for (int i = 0; i < analyzers.size(); i++) {
|
for (int i = 0; i < analyzers.size(); i++) {
|
||||||
PacketAnalyzer analyzer = analyzers.get(i);
|
PacketAnalyzer analyzer = analyzers.get(i);
|
||||||
if (analyzer.matchPacket(packet)) {
|
if (analyzer.matchPacket(packet) && analyzer.analyzePacket(packet, brief, verbose)) {
|
||||||
analyzer.analyzePacket(packet, brief, verbose);
|
|
||||||
/* continue another round if more bytes left */
|
/* continue another round if more bytes left */
|
||||||
analyze = packet.hasMoreData();
|
analyze = packet.hasMoreData();
|
||||||
brief.append('|');
|
brief.append('|');
|
||||||
|
@ -42,7 +42,7 @@ public class IEEE802154Analyzer extends PacketAnalyzer {
|
|||||||
/* create a 802.15.4 packet of the bytes and "dispatch" to the
|
/* create a 802.15.4 packet of the bytes and "dispatch" to the
|
||||||
* next handler
|
* 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 pos = packet.pos;
|
||||||
int type = packet.data[pos + 0] & 7;
|
int type = packet.data[pos + 0] & 7;
|
||||||
// int security = (packet.data[pos + 0] >> 3) & 1;
|
// int security = (packet.data[pos + 0] >> 3) & 1;
|
||||||
@ -108,29 +108,33 @@ public class IEEE802154Analyzer extends PacketAnalyzer {
|
|||||||
|
|
||||||
verbose.append("<html><b>IEEE 802.15.4 ")
|
verbose.append("<html><b>IEEE 802.15.4 ")
|
||||||
.append(type < typeVerbose.length ? typeVerbose[type] : "?")
|
.append(type < typeVerbose.length ? typeVerbose[type] : "?")
|
||||||
.append(' ').append(seqNumber)
|
.append(' ').append(seqNumber);
|
||||||
.append("</b><br>From ");
|
if (type != ACKFRAME) {
|
||||||
if (srcPanID != 0) {
|
verbose.append("</b><br>From ");
|
||||||
verbose.append(StringUtils.toHex((byte)(srcPanID >> 8)))
|
if (srcPanID != 0) {
|
||||||
.append(StringUtils.toHex((byte)(srcPanID & 0xff)))
|
verbose.append(StringUtils.toHex((byte)(srcPanID >> 8)))
|
||||||
.append('/');
|
.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("<br>Payload len: ").append(payloadLen);
|
|
||||||
|
|
||||||
/* update packet */
|
/* update packet */
|
||||||
packet.pos = pos;
|
packet.pos = pos;
|
||||||
packet.level = NETWORK_LEVEL;
|
packet.level = NETWORK_LEVEL;
|
||||||
|
/* remove CRC from the packet */
|
||||||
|
packet.consumeBytesEnd(2);
|
||||||
|
|
||||||
packet.llsender = sourceAddress;
|
packet.llsender = sourceAddress;
|
||||||
packet.llreceiver = destAddress;
|
packet.llreceiver = destAddress;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printAddress(StringBuffer sb, int type, byte[] addr) {
|
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;
|
return (packet.get(0) & 0xe0) == IPHC_DISPATCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void analyzePacket(Packet packet, StringBuffer brief,
|
public boolean analyzePacket(Packet packet, StringBuffer brief,
|
||||||
StringBuffer verbose) {
|
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 tf = (packet.get(0) >> 3) & 0x03;
|
||||||
int nh = (packet.get(0) >> 2) & 0x01;
|
int nh = (packet.get(0) >> 2) & 0x01;
|
||||||
int hlim = (packet.get(0) & 0x03);
|
int hlim = (packet.get(0) & 0x03);
|
||||||
@ -372,7 +375,7 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer {
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// PRINTF("sicslowpan uncompress_hdr: error unsupported UDP compression\n");
|
// PRINTF("sicslowpan uncompress_hdr: error unsupported UDP compression\n");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -410,8 +413,8 @@ public class IPHCPacketAnalyzer extends PacketAnalyzer {
|
|||||||
verbose.append(" to ");
|
verbose.append(" to ");
|
||||||
printAddress(verbose, destAddress);
|
printAddress(verbose, destAddress);
|
||||||
|
|
||||||
// packet.pos = packet.data.length;
|
|
||||||
packet.level = NETWORK_LEVEL;
|
packet.level = NETWORK_LEVEL;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void printAddress(StringBuffer out, byte[] address) {
|
public static void printAddress(StringBuffer out, byte[] address) {
|
||||||
|
@ -10,6 +10,8 @@ public abstract class PacketAnalyzer {
|
|||||||
byte[] data;
|
byte[] data;
|
||||||
int pos;
|
int pos;
|
||||||
int level;
|
int level;
|
||||||
|
/* size = length - consumed bytes at tail */
|
||||||
|
int size;
|
||||||
|
|
||||||
/* L2 addresseses */
|
/* L2 addresseses */
|
||||||
byte[] llsender;
|
byte[] llsender;
|
||||||
@ -18,13 +20,29 @@ public abstract class PacketAnalyzer {
|
|||||||
public Packet(byte[] data, int level) {
|
public Packet(byte[] data, int level) {
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
|
this.size = data.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void consumeBytesStart(int bytes) {
|
||||||
|
pos += bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void consumeBytesEnd(int bytes) {
|
||||||
|
size -= bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean hasMoreData() {
|
public boolean hasMoreData() {
|
||||||
return data.length > pos;
|
return size > pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return size - pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte get(int index) {
|
public byte get(int index) {
|
||||||
|
if (index >= size) return 0;
|
||||||
return data[pos + index];
|
return data[pos + index];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +56,7 @@ public abstract class PacketAnalyzer {
|
|||||||
|
|
||||||
|
|
||||||
public byte[] getPayload() {
|
public byte[] getPayload() {
|
||||||
byte[] pload = new byte[data.length - pos];
|
byte[] pload = new byte[size - pos];
|
||||||
System.arraycopy(data, pos, pload, 0, pload.length);
|
System.arraycopy(data, pos, pload, 0, pload.length);
|
||||||
return pload;
|
return pload;
|
||||||
}
|
}
|
||||||
@ -60,5 +78,5 @@ public abstract class PacketAnalyzer {
|
|||||||
|
|
||||||
public abstract boolean matchPacket(Packet packet);
|
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…
x
Reference in New Issue
Block a user