You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(21) |
Nov
(12) |
Dec
(41) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(25) |
Feb
(54) |
Mar
(63) |
Apr
(52) |
May
(17) |
Jun
(3) |
Jul
(3) |
Aug
(5) |
Sep
(49) |
Oct
(50) |
Nov
(34) |
Dec
(14) |
2009 |
Jan
(9) |
Feb
(15) |
Mar
(38) |
Apr
(12) |
May
(35) |
Jun
(20) |
Jul
(2) |
Aug
(7) |
Sep
(36) |
Oct
(24) |
Nov
(2) |
Dec
(2) |
2010 |
Jan
(14) |
Feb
(1) |
Mar
(36) |
Apr
(2) |
May
(4) |
Jun
(6) |
Jul
(35) |
Aug
(11) |
Sep
(8) |
Oct
(3) |
Nov
|
Dec
(1) |
2011 |
Jan
(11) |
Feb
(12) |
Mar
(3) |
Apr
(7) |
May
(12) |
Jun
(8) |
Jul
|
Aug
(3) |
Sep
(4) |
Oct
|
Nov
(2) |
Dec
(4) |
2012 |
Jan
(2) |
Feb
(1) |
Mar
(14) |
Apr
(5) |
May
(28) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(21) |
Nov
(4) |
Dec
(1) |
2013 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2014 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <jo...@us...> - 2009-04-20 16:16:01
|
Revision: 512 http://mspsim.svn.sourceforge.net/mspsim/?rev=512&view=rev Author: joxe Date: 2009-04-20 16:15:46 +0000 (Mon, 20 Apr 2009) Log Message: ----------- minor bugfix Modified Paths: -------------- mspsim/se/sics/mspsim/util/ELF.java Modified: mspsim/se/sics/mspsim/util/ELF.java =================================================================== --- mspsim/se/sics/mspsim/util/ELF.java 2009-04-20 15:44:29 UTC (rev 511) +++ mspsim/se/sics/mspsim/util/ELF.java 2009-04-20 16:15:46 UTC (rev 512) @@ -103,7 +103,8 @@ } } } catch(IOException ioe) { - // ignore... + // ignore and return false - this is not an elf. + return false; } finally { if (input != null) { try { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-04-20 15:44:38
|
Revision: 511 http://mspsim.svn.sourceforge.net/mspsim/?rev=511&view=rev Author: joxe Date: 2009-04-20 15:44:29 +0000 (Mon, 20 Apr 2009) Log Message: ----------- added verification of MAGIC in ELF files Modified Paths: -------------- mspsim/firmware/sky/blink.firmware mspsim/se/sics/mspsim/chip/CC2420.java mspsim/se/sics/mspsim/util/ELF.java Added Paths: ----------- mspsim/se/sics/mspsim/util/ELFException.java Modified: mspsim/firmware/sky/blink.firmware =================================================================== (Binary files differ) Modified: mspsim/se/sics/mspsim/chip/CC2420.java =================================================================== --- mspsim/se/sics/mspsim/chip/CC2420.java 2009-04-10 15:57:37 UTC (rev 510) +++ mspsim/se/sics/mspsim/chip/CC2420.java 2009-04-20 15:44:29 UTC (rev 511) @@ -246,7 +246,7 @@ /* RSSI is an externally set value of the RSSI for this CC2420 */ /* low RSSI => CCA = true in normal mode */ - private int rssi = 0; + private int rssi = -100; private static int RSSI_OFFSET = -45; /* cc2420 datasheet */ /* current CCA value */ private boolean cca = false; Modified: mspsim/se/sics/mspsim/util/ELF.java =================================================================== --- mspsim/se/sics/mspsim/util/ELF.java 2009-04-10 15:57:37 UTC (rev 510) +++ mspsim/se/sics/mspsim/util/ELF.java 2009-04-20 15:44:29 UTC (rev 511) @@ -42,17 +42,22 @@ package se.sics.mspsim.util; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; +import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; public class ELF { - public static final int EI_NIDENT = 16; - public static final int EI_ENCODING = 5; - + private static final int EI_NIDENT = 16; + private static final int EI_ENCODING = 5; + private static final int[] MAGIC = new int[] {0x7f, 'E', 'L', 'F'}; + public static final boolean DEBUG = false; - + + boolean encMSB = true; int type; int machine; @@ -87,14 +92,44 @@ pos = 0; } - public void readHeader() { + /* check if the file exists and is an ELF file */ + public static boolean isELF(File file) { + InputStream input = null; + try { + input = new FileInputStream(file); + for (int i = 0; i < MAGIC.length; i++) { + if (MAGIC[i] != input.read()) { + return false; + } + } + } catch(IOException ioe) { + // ignore... + } finally { + if (input != null) { + try { + input.close(); + } catch (Exception e) { + } + } + } + return true; + } + + private void readHeader() throws ELFException { + for (int i = 0; i < MAGIC.length; i++) { + if (elfData[i] != (byte) (MAGIC[i] & 0xff)) { + throw new ELFException("Not an elf file"); + } + } + if (elfData[EI_ENCODING] == 2) { encMSB = true; } else if (elfData[EI_ENCODING] == 1) { encMSB = false; } else { - System.out.println("ERROR: Wroing encoding???"); + throw new ELFException("Illegal encoding: " + elfData[EI_ENCODING]); } + pos += 16; type = readElf16(); machine = readElf16(); @@ -128,7 +163,7 @@ } } - public ELFSection readSectionHeader() { + private ELFSection readSectionHeader() { ELFSection sec = new ELFSection(); sec.name = readElf32(); sec.type = readElf32(); @@ -144,7 +179,7 @@ return sec; } - public ELFProgram readProgramHeader() { + private ELFProgram readProgramHeader() { ELFProgram pHeader = new ELFProgram(); pHeader.type = readElf32(); pHeader.offset = readElf32(); @@ -243,7 +278,7 @@ } } - public void readAll() { + public void readAll() throws ELFException { readHeader(); readPrograms(); readSections(); Added: mspsim/se/sics/mspsim/util/ELFException.java =================================================================== --- mspsim/se/sics/mspsim/util/ELFException.java (rev 0) +++ mspsim/se/sics/mspsim/util/ELFException.java 2009-04-20 15:44:29 UTC (rev 511) @@ -0,0 +1,9 @@ +package se.sics.mspsim.util; + +import java.io.IOException; + +public class ELFException extends IOException { + ELFException(String message) { + super(message); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-04-10 15:57:55
|
Revision: 510 http://mspsim.svn.sourceforge.net/mspsim/?rev=510&view=rev Author: joxe Date: 2009-04-10 15:57:37 +0000 (Fri, 10 Apr 2009) Log Message: ----------- added cli command for resetting window stored positions Modified Paths: -------------- mspsim/se/sics/mspsim/cli/WindowCommands.java Modified: mspsim/se/sics/mspsim/cli/WindowCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/WindowCommands.java 2009-04-06 23:22:36 UTC (rev 509) +++ mspsim/se/sics/mspsim/cli/WindowCommands.java 2009-04-10 15:57:37 UTC (rev 510) @@ -42,6 +42,7 @@ import java.util.Hashtable; +import se.sics.mspsim.ui.WindowUtils; import se.sics.mspsim.util.ComponentRegistry; public class WindowCommands implements CommandBundle { @@ -85,5 +86,11 @@ } } }); + handler.registerCommand("wclear", new BasicCommand("resets stored window positions", "") { + public int executeCommand(CommandContext context) { + WindowUtils.clearState(); + return 0; + } + }); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-04-06 23:22:55
|
Revision: 509 http://mspsim.svn.sourceforge.net/mspsim/?rev=509&view=rev Author: joxe Date: 2009-04-06 23:22:36 +0000 (Mon, 06 Apr 2009) Log Message: ----------- fixed minor bug in net code Modified Paths: -------------- mspsim/se/sics/mspsim/net/AbstractPacket.java mspsim/se/sics/mspsim/net/AbstractPacketHandler.java mspsim/se/sics/mspsim/net/ICMP6PacketHandler.java mspsim/se/sics/mspsim/net/IEEE802154Packet.java mspsim/se/sics/mspsim/net/IPv6Packet.java mspsim/se/sics/mspsim/net/LoWPANHandler.java mspsim/se/sics/mspsim/net/LoWPANPacket.java mspsim/se/sics/mspsim/net/Packet.java Modified: mspsim/se/sics/mspsim/net/AbstractPacket.java =================================================================== --- mspsim/se/sics/mspsim/net/AbstractPacket.java 2009-04-05 20:52:08 UTC (rev 508) +++ mspsim/se/sics/mspsim/net/AbstractPacket.java 2009-04-06 23:22:36 UTC (rev 509) @@ -53,13 +53,36 @@ return payload; } + public byte[] getSourceAddress() { + return null; + } + + public byte[] getDestinationAddress() { + return null; + } + public void setPayloadPacket(Packet packet) { payloadPacket = packet; + if (packet.getContainerPacket() != this) { + packet.setContainerPacket(this); + } } public void setContainerPacket(Packet packet) { containerPacket = packet; + if (packet.getPayloadPacket() != this) { + packet.setPayloadPacket(this); + } } + + public Packet getPayloadPacket() { + return payloadPacket; + } + + public Packet getContainerPacket() { + return containerPacket; + } + public AbstractPacket createReply() { return null; Modified: mspsim/se/sics/mspsim/net/AbstractPacketHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/AbstractPacketHandler.java 2009-04-05 20:52:08 UTC (rev 508) +++ mspsim/se/sics/mspsim/net/AbstractPacketHandler.java 2009-04-06 23:22:36 UTC (rev 509) @@ -43,11 +43,15 @@ import java.util.ArrayList; public abstract class AbstractPacketHandler implements PacketHandler { - + ArrayList<PacketHandlerDispatch> upperLayers = new ArrayList<PacketHandlerDispatch>(); PacketHandler lowerLayer; + public PacketHandler getLowerLayerHandler() { + return lowerLayer; + } + public void addUpperLayerHandler(int protoID, PacketHandler handler) { PacketHandlerDispatch layer = new PacketHandlerDispatch(); layer.dispatch = protoID; Modified: mspsim/se/sics/mspsim/net/ICMP6PacketHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/ICMP6PacketHandler.java 2009-04-05 20:52:08 UTC (rev 508) +++ mspsim/se/sics/mspsim/net/ICMP6PacketHandler.java 2009-04-06 23:22:36 UTC (rev 509) @@ -24,6 +24,8 @@ ipp.flowLabel = 0; ipp.setPayloadPacket(p); ipp.nextHeader = IPv6Packet.ICMP6_DISPATCH; + + // ipp.destAddress = ???; break; } Modified: mspsim/se/sics/mspsim/net/IEEE802154Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/IEEE802154Packet.java 2009-04-05 20:52:08 UTC (rev 508) +++ mspsim/se/sics/mspsim/net/IEEE802154Packet.java 2009-04-06 23:22:36 UTC (rev 509) @@ -70,9 +70,25 @@ setPacketData(container, payload, payload.length); } + public IEEE802154Packet() { + } + public byte[] getDestinationAddress() { return destAddress; } + + public void setDestinationAddress(byte[] destAddress) { + for (int i = 0; i < destAddress.length; i++) { + this.destAddress[i] = destAddress[i]; + } + } + + public void setSourceAddress(byte[] srcAddress) { + for (int i = 0; i < srcAddress.length; i++) { + this.sourceAddress[i] = srcAddress[i]; + } + } + public byte[] getSourceAddress() { return sourceAddress; Modified: mspsim/se/sics/mspsim/net/IPv6Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/IPv6Packet.java 2009-04-05 20:52:08 UTC (rev 508) +++ mspsim/se/sics/mspsim/net/IPv6Packet.java 2009-04-06 23:22:36 UTC (rev 509) @@ -59,6 +59,19 @@ byte[] sourceAddress = new byte[16]; byte[] destAddress = new byte[16]; + public IPv6Packet() { + version = 6; + flowLabel = 0; + } + + public byte[] getSourceAddress() { + return sourceAddress; + } + + public byte[] getDestinationAddress() { + return destAddress; + } + public void printPacket(PrintStream out) { out.printf("IPv6: from "); printAddress(out, sourceAddress); @@ -121,7 +134,7 @@ } public static int checkSum(int sum, byte[] data, int size) { - for (int i = 0; i < size; i+= 2) { + for (int i = 0; i < size - 1; i+= 2) { int dsum = ((data[i] & 0xff) << 8) | (data[i + 1] & 0xff); sum = (sum + dsum) & 0xffff; if (sum < dsum) sum++; @@ -142,10 +155,21 @@ return 3; } - public boolean isSourceMACBased() { - // TODO Auto-generated method stub + public static boolean isMACBased(byte[] address, byte[] macAddress) { + if (address[8] == (macAddress[0] ^ 0x02)) { + for (int i = 1; i < macAddress.length; i++) { + if (address[8 + i] != macAddress[i]) + return false; + } + return true; + } return false; } + + public boolean isSourceMACBased() { + byte[] macAddress = containerPacket.getSourceAddress(); + return isMACBased(sourceAddress, macAddress); + } public boolean isMulticastDestination() { // TODO Auto-generated method stub @@ -154,8 +178,8 @@ /* how can we check this before we know the MAC address??? */ public boolean isDestinationMACBased() { - // TODO Auto-generated method stub - return false; + byte[] macAddress = containerPacket.getDestinationAddress(); + return isMACBased(destAddress, macAddress); } } Modified: mspsim/se/sics/mspsim/net/LoWPANHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/LoWPANHandler.java 2009-04-05 20:52:08 UTC (rev 508) +++ mspsim/se/sics/mspsim/net/LoWPANHandler.java 2009-04-06 23:22:36 UTC (rev 509) @@ -49,6 +49,12 @@ } public void sendPacket(Packet payload) { + /* LoWPANHandler is for IP over 802.15.4 */ + + if (payload instanceof IPv6Packet) { + // Assume HC01 compression for now... + IEEE802154Packet p = new IEEE802154Packet(); + } } } \ No newline at end of file Modified: mspsim/se/sics/mspsim/net/LoWPANPacket.java =================================================================== --- mspsim/se/sics/mspsim/net/LoWPANPacket.java 2009-04-05 20:52:08 UTC (rev 508) +++ mspsim/se/sics/mspsim/net/LoWPANPacket.java 2009-04-06 23:22:36 UTC (rev 509) @@ -5,12 +5,23 @@ public class LoWPANPacket extends AbstractPacket { int dispatch = 0; + + public LoWPANPacket() { + } public LoWPANPacket(byte[] data) { dispatch = data[0]; setPayload(data, 1, data.length - 1); } + public byte[] getSourceAddress() { + return containerPacket.getSourceAddress(); + } + + public byte[] getDestinationAddress() { + return containerPacket.getDestinationAddress(); + } + public void printPacket(PrintStream out) { out.println("6LoWPAN Dispatch: " + dispatch); if (payloadPacket != null) { Modified: mspsim/se/sics/mspsim/net/Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/Packet.java 2009-04-05 20:52:08 UTC (rev 508) +++ mspsim/se/sics/mspsim/net/Packet.java 2009-04-06 23:22:36 UTC (rev 509) @@ -49,8 +49,13 @@ * @return payload of the packet */ public byte[] getPayload(); + public byte[] getSourceAddress(); + public byte[] getDestinationAddress(); void setPayloadPacket(Packet packet); void setContainerPacket(Packet packet); + Packet getPayloadPacket(); + Packet getContainerPacket(); + public void printPacket(PrintStream out); } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-04-05 20:52:30
|
Revision: 508 http://mspsim.svn.sourceforge.net/mspsim/?rev=508&view=rev Author: joxe Date: 2009-04-05 20:52:08 +0000 (Sun, 05 Apr 2009) Log Message: ----------- added compression of HC01 Modified Paths: -------------- mspsim/se/sics/mspsim/net/AbstractPacket.java mspsim/se/sics/mspsim/net/AbstractPacketHandler.java mspsim/se/sics/mspsim/net/HC01PacketHandler.java mspsim/se/sics/mspsim/net/ICMP6Packet.java mspsim/se/sics/mspsim/net/ICMP6PacketHandler.java mspsim/se/sics/mspsim/net/IPv6Packet.java Modified: mspsim/se/sics/mspsim/net/AbstractPacket.java =================================================================== --- mspsim/se/sics/mspsim/net/AbstractPacket.java 2009-04-02 10:57:59 UTC (rev 507) +++ mspsim/se/sics/mspsim/net/AbstractPacket.java 2009-04-05 20:52:08 UTC (rev 508) @@ -61,9 +61,33 @@ containerPacket = packet; } + public AbstractPacket createReply() { + return null; + } + void setPayload(byte[] data, int startPos, int len) { payloadLen = len; payload = new byte[payloadLen]; System.arraycopy(data, startPos, payload, 0, payloadLen); - } + } + + static int get32(byte[] data, int pos) { + if (data.length > pos + 3) + return ((data[pos] & 0xff) << 24) | ((data[pos++] & 0xff) << 16) | + ((data[pos] & 0xff) << 8) | (data[pos + 1] & 0xff); + return 0; + } + + static int get16(byte[] data, int pos) { + if (data.length > pos + 1) + return ((data[pos] & 0xff) << 8) | data[pos + 1] & 0xff; + return 0; + } + + static byte[] getAddress(byte[] data, int pos) { + byte[] targetAddress = new byte[16]; + System.arraycopy(data, pos, targetAddress, 0, 16); + return targetAddress; + } + } \ No newline at end of file Modified: mspsim/se/sics/mspsim/net/AbstractPacketHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/AbstractPacketHandler.java 2009-04-02 10:57:59 UTC (rev 507) +++ mspsim/se/sics/mspsim/net/AbstractPacketHandler.java 2009-04-05 20:52:08 UTC (rev 508) @@ -59,6 +59,7 @@ lowerLayer = handler; } + /* incoming packets ... */ void dispatch(int dispatch, Packet container) { byte[] payload = container.getPayload(); if (dispatch != -1) { Modified: mspsim/se/sics/mspsim/net/HC01PacketHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/HC01PacketHandler.java 2009-04-02 10:57:59 UTC (rev 507) +++ mspsim/se/sics/mspsim/net/HC01PacketHandler.java 2009-04-05 20:52:08 UTC (rev 508) @@ -34,6 +34,8 @@ * AbstractPacket * * Author : Joakim Eriksson + * Original Authors (Contiki Code): + * * Created : mar 2009 * Updated : $Date:$ * $Revision:$ @@ -41,9 +43,19 @@ package se.sics.mspsim.net; +import org.jfree.util.ArrayUtilities; + import se.sics.mspsim.util.Utils; +import sun.java2d.SunGraphicsEnvironment.TTFilter; public class HC01PacketHandler extends AbstractPacketHandler { + /* + * Values of fields within the IPHC encoding first byte + * (C stands for compressed and I for inline) + */ + public final static int IPHC_TC_C = 0x80; + public final static int IPHC_VF_C = 0x40; + public final static int IPHC_NH_C = 0x20; public final static int IPHC_TTL_1 = 0x08; public final static int IPHC_TTL_64 = 0x10; public final static int IPHC_TTL_255 = 0x18; @@ -63,21 +75,35 @@ public final static int NHC_UDP_C = 0xFB; public final static int NHC_UDP_I = 0xF8; + /* Link local context number */ + public final static int IPHC_ADDR_CONTEXT_LL = 0; + /* 16-bit multicast addresses compression */ + public final static int IPHC_MCAST_RANGE = 0xA0; + /* Min and Max compressible UDP ports */ public final static int UDP_PORT_MIN = 0xF0B0; public final static int UDP_PORT_MAX = 0xF0BF; /* F0B0 + 15 */ public static final int HC01_DISPATCH = 0x03; + /* move these to IPv6 Packet !! */ public final static int PROTO_ICMP = 1; public final static int PROTO_TCP = 6; public final static int PROTO_UDP = 17; public final static int PROTO_ICMP6 = 58; - + private static class AddrContext { int used; int number; byte[] prefix = new byte[8]; + + public boolean matchPrefix(byte[] address) { + for (int i = 0; i < prefix.length; i++) { + if (prefix[i] != address[i]) + return false; + } + return true; + } } private AddrContext[] contexts = new AddrContext[4]; @@ -101,6 +127,49 @@ } + + /** + * \brief check whether we can compress the IID in + * address to 16 bits. + * This is used for unicast addresses only, and is true + * if first 49 bits of IID are 0 + * @return + */ + private boolean is16bitCompressable(byte[] address) { + return ((address[8] | address[9] | address[10] | address[11] | + address[12] | address[13]) == 0) && + (address[14] & 0x80) == 0; + } + + /** + * \brief check whether the 9-bit group-id of the + * compressed multicast address is known. It is true + * if the 9-bit group is the all nodes or all routers + * group. + * \param a is typed u8_t * + */ +// #define sicslowpan_is_mcast_addr_decompressable(a) \ +// (((*a & 0x01) == 0) && \ +// ((*(a + 1) == 0x01) || (*(a + 1) == 0x02))) + + /** + * \brief check whether the 112-bit group-id of the + * multicast address is mappable to a 9-bit group-id + * It is true if the group is the all nodes or all + * routers group. + */ +// #define sicslowpan_is_mcast_addr_compressable(a) \ +// ((((a)->u16[1]) == 0) && \ +// (((a)->u16[2]) == 0) && \ +// (((a)->u16[3]) == 0) && \ +// (((a)->u16[4]) == 0) && \ +// (((a)->u16[5]) == 0) && \ +// (((a)->u16[6]) == 0) && \ +// (((a)->u8[14]) == 0) && \ +// ((((a)->u8[15]) == 1) || (((a)->u8[15]) == 2))) + + + public void packetReceived(Packet container) { byte[] payload = container.getPayload(); IPv6Packet packet = new IPv6Packet(); @@ -110,6 +179,8 @@ dispatch(packet.nextHeader, packet); } + /* this is used for sending packets! */ + /* we need lots of more info here !!! target, reply-of-packet, etc */ public void sendPacket(Packet payload) { } @@ -133,6 +204,133 @@ return null; } + /* HC01 header compression from 40 bytes to less... */ + public byte[] getPacketData(IPv6Packet packet) { + int enc1 = 0, enc2 = 0; + byte[] data = new byte[40]; + int pos = 3; + + if (packet.flowLabel == 0) { + /* compress version and flow label! */ + enc1 |= IPHC_VF_C; + } + if (packet.trafficClass == 0) { + enc1 |= IPHC_TC_C; + } + + /* write version and flow if needed */ + if ((enc1 & IPHC_VF_C) == 0) { + pos += packet.writeVFlow(data, pos); + } + /* write traffic class if needed */ + if ((enc1 & IPHC_TC_C) == 0) { + data[pos++] = (byte) (packet.trafficClass & 0xff); + } + + /* Note that the payload length is always compressed */ + + /* TODO: compress UDP!!! */ + data[pos++] = (byte) (packet.nextHeader & 0xff); + + switch (packet.hopLimit) { + case 1: + enc1 |= IPHC_TTL_1; + break; + case 64: + enc1 |= IPHC_TTL_64; + break; + case 255: + enc1 |= IPHC_TTL_255; + break; + default: + data[pos++] = (byte) (packet.hopLimit & 0xff); + } + + int context; + if ((context = lookupContext(packet.sourceAddress)) != -1) { + /* elide the prefix */ + enc2 |= context << 4; + if (packet.isSourceMACBased()) { + /* elide the IID */ + enc2 |= IPHC_SAM_0; + } else if (is16bitCompressable(packet.sourceAddress)){ + enc2 |= IPHC_SAM_16; + data[pos++] = packet.sourceAddress[14]; + data[pos++] = packet.sourceAddress[15]; + } else { + enc2 |= IPHC_SAM_64; + System.arraycopy(packet.sourceAddress, 8, data, pos, 8); + pos += 8; + } + } else { + enc2 |= IPHC_SAM_I; + System.arraycopy(packet.sourceAddress, 0, data, pos, 16); + pos += 16; + } + + /* destination compression */ + if(packet.isMulticastDestination()) { + /* Address is multicast, try to compress */ + if(isMulticastCompressable(packet.destAddress)) { + enc2 |= IPHC_DAM_16; + /* 3 first bits = 101 */ + data[pos] = (byte) IPHC_MCAST_RANGE; + /* bits 3-6 = scope = bits 8-11 in 128 bits address */ + data[pos++] |= (packet.destAddress[1] & 0x0F) << 1; + /* + * bits 7 - 15 = 9-bit group + * We just copy the last byte because it works + * with currently supported groups + */ + data[pos++] = packet.destAddress[15]; + } else { + /* send the full address */ + enc2 |= IPHC_DAM_I; + System.arraycopy(packet.destAddress, 0, data, pos, 16); + pos += 16; + } + } else { + /* Address is unicast, try to compress */ + if((context = lookupContext(packet.destAddress)) != -1) { + /* elide the prefix */ + enc2 |= context; + if(packet.isDestinationMACBased()) { + /* elide the IID */ + enc2 |= IPHC_DAM_0; + } else { + if(is16bitCompressable(packet.destAddress)) { + /* compress IID to 16 bits */ + enc2 |= IPHC_DAM_16; + data[pos++] = packet.destAddress[14]; + data[pos++] = packet.destAddress[15]; + } else { + /* do not compress IID */ + enc2 |= IPHC_DAM_64; + System.arraycopy(data, pos, packet.destAddress, 8, 8); + pos += 8; + } + } + } else { + /* send the full address */ + enc2 |= IPHC_DAM_I; + System.arraycopy(data, pos, packet.destAddress, 0, 16); + pos += 16; + } + } + + // uncomp_hdr_len = UIP_IPH_LEN; + // TODO: add udp header compression!!! + + data[0] = HC01_DISPATCH; + data[1] = (byte) (enc1 & 0xff); + data[2] = (byte) (enc2 & 0xff); + + System.out.println("HC01 Header compression: size " + pos); + + byte[] dataPacket = new byte[pos]; + System.arraycopy(data, 0, dataPacket, 0, pos); + return dataPacket; + } public void setPacketData(IPv6Packet packet, byte[] data, int len) { /* first two is ... */ @@ -273,11 +471,11 @@ pos += 2; } else { /* [ignore] multicast address check the 9-bit group-id is known */ - System.out.println("*** Multicast address!!! HC01"); + System.out.println("*** Multicast address!!! HC01: " + data[pos] + "," + data[pos + 1]); java.util.Arrays.fill(packet.destAddress, 0, 16, (byte)0); - packet.destAddress[0] = (byte)0xff; + packet.destAddress[0] = (byte) 0xff; packet.destAddress[1] = (byte)(((data[pos] & 0xff) >> 1) & 0x0F); - packet.destAddress[15] = data[pos + 1]; + packet.destAddress[15] = (byte) (data[pos + 1] & 0xff); pos += 2; } break; @@ -302,6 +500,7 @@ if ((data[0] & 0x20) != 0) { /* The next header is compressed, NHC is following */ if ((data[pos] & 0xfc) == NHC_UDP_ID) { + System.out.println("HC01: Next header UDP!"); packet.nextHeader = PROTO_UDP; int srcPort = 0; int destPort = 0; @@ -351,10 +550,24 @@ System.out.println(); // packet.setPayload(data, 40, ???); } - + + private boolean isMulticastCompressable(byte[] address) { + return false; + } + + private AddrContext lookupContext(int index) { if (index < contexts.length) return contexts[index]; return null; } + + private int lookupContext(byte[] address) { + for (int i = 0; i < contexts.length; i++) { + if (contexts[i] != null && contexts[i].matchPrefix(address)) { + return i; + } + } + return -1; + } } \ No newline at end of file Modified: mspsim/se/sics/mspsim/net/ICMP6Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/ICMP6Packet.java 2009-04-02 10:57:59 UTC (rev 507) +++ mspsim/se/sics/mspsim/net/ICMP6Packet.java 2009-04-05 20:52:08 UTC (rev 508) @@ -14,6 +14,10 @@ public static final int NEIGHBOR_SOLICITATION = 135; public static final int NEIGHBOR_ADVERTISEMENT = 136; + public static final int FLAG_ROUTER = 0x80; + public static final int FLAG_SOLICITED = 0x40; + public static final int FLAG_OVERRIDE = 0x20; + public static final String[] TYPE_NAME = new String[] { "ECHO_REQUEST", "ECHO_REPLY", "GROUP_QUERY", "GROUP_REPORT", "GROUP_REDUCTION", @@ -23,8 +27,13 @@ int type; int code; int checksum; + byte[] targetAddress; + int id; + int seqNo; + IPv6Packet ip; + int flags; public void printPacket(PrintStream out) { String typeS = "" + type; @@ -34,9 +43,13 @@ typeS = TYPE_NAME[tS]; } } - out.printf("ICMPv6 Type: %d (%s) Code: %d Chk: %04x \n", type, typeS, - code, checksum); - + out.printf("ICMPv6 Type: %d (%s) Code: %d id: %04x seq: %04x\n", type, typeS, + code, id, seqNo); + if (targetAddress != null) { + out.print("ICMPv6 Target address: "); + IPv6Packet.printAddress(out, targetAddress); + out.println(); + } /* ICMP can not have payload ?! */ } @@ -51,9 +64,30 @@ /* test the checksum ... - set checksum to zero*/ data[2] = 0; data[3] = 0; + + switch (type) { + case ECHO_REQUEST: + case ECHO_REPLY: + id = get16(data, 4); + seqNo = get16(data, 6); + break; + case NEIGHBOR_SOLICITATION: + case NEIGHBOR_ADVERTISEMENT: + if (type == NEIGHBOR_ADVERTISEMENT) { + flags = data[4] & 0xff; + } + targetAddress = getAddress(data, 8); + break; + } + int sum = ip.upperLayerHeaderChecksum(); - System.out.printf("*** Checksum: %04x == My Checksum: %04x \n", - checksum, (~IPv6Packet.checkSum(sum, data, len)) & 0xffff); + sum = IPv6Packet.checkSum(sum, data, data.length); + sum = (~sum) & 0xffff; + if (sum == checksum) { + System.out.println("ICMPv6: Checksum matches!!!"); + } else { + System.out.printf("ICMPv6: Checksum error: %04x <?> %04x", checksum, sum); + } } } Modified: mspsim/se/sics/mspsim/net/ICMP6PacketHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/ICMP6PacketHandler.java 2009-04-02 10:57:59 UTC (rev 507) +++ mspsim/se/sics/mspsim/net/ICMP6PacketHandler.java 2009-04-05 20:52:08 UTC (rev 508) @@ -4,13 +4,33 @@ public void packetReceived(Packet container) { ICMP6Packet icmpPacket = new ICMP6Packet(); + IPv6Packet ipv6 = (IPv6Packet) container; container.setPayloadPacket(icmpPacket); icmpPacket.containerPacket = container; icmpPacket.setPacketData(container, container.getPayload(), container.getPayload().length); + + /* handle packet - just a test for now */ + switch (icmpPacket.type) { + case ICMP6Packet.NEIGHBOR_SOLICITATION: + ICMP6Packet p = new ICMP6Packet(); + p.targetAddress = icmpPacket.targetAddress; + p.type = ICMP6Packet.NEIGHBOR_ADVERTISEMENT; + p.flags = ICMP6Packet.FLAG_SOLICITED | + ICMP6Packet.FLAG_OVERRIDE; + + IPv6Packet ipp = new IPv6Packet(); + ipp.version = 6; + ipp.flowLabel = 0; + ipp.setPayloadPacket(p); + ipp.nextHeader = IPv6Packet.ICMP6_DISPATCH; + // ipp.destAddress = ???; + break; + } } - public void sendPacket(Packet payload) { + public void sendPacket(Packet payload) { + /* ICMP does not carry payload ?? */ } - + } Modified: mspsim/se/sics/mspsim/net/IPv6Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/IPv6Packet.java 2009-04-02 10:57:59 UTC (rev 507) +++ mspsim/se/sics/mspsim/net/IPv6Packet.java 2009-04-05 20:52:08 UTC (rev 508) @@ -135,4 +135,27 @@ return sum; } + public int writeVFlow(byte[] data, int pos) { + data[pos++] = (byte) (0x60 | (flowLabel >> 16) & 0x0f); + data[pos++] = (byte)((flowLabel >> 8) & 0xff); + data[pos++] = (byte) (flowLabel & 0xff); + return 3; + } + + public boolean isSourceMACBased() { + // TODO Auto-generated method stub + return false; + } + + public boolean isMulticastDestination() { + // TODO Auto-generated method stub + return false; + } + + /* how can we check this before we know the MAC address??? */ + public boolean isDestinationMACBased() { + // TODO Auto-generated method stub + return false; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-04-02 10:58:06
|
Revision: 507 http://mspsim.svn.sourceforge.net/mspsim/?rev=507&view=rev Author: joxe Date: 2009-04-02 10:57:59 +0000 (Thu, 02 Apr 2009) Log Message: ----------- fixed autoconf ip addr in HC01 Modified Paths: -------------- mspsim/Makefile mspsim/se/sics/mspsim/chip/DS2411.java mspsim/se/sics/mspsim/net/HC01PacketHandler.java Modified: mspsim/Makefile =================================================================== --- mspsim/Makefile 2009-03-25 22:39:18 UTC (rev 506) +++ mspsim/Makefile 2009-04-02 10:57:59 UTC (rev 507) @@ -68,7 +68,7 @@ SCRIPTS := ${addprefix scripts/,autorun.sc duty.sc} BINARY := README.txt license.txt CHANGE_LOG.txt images/*.jpg firmware/*/*.firmware ${SCRIPTS} -PACKAGES := se/sics/mspsim ${addprefix se/sics/mspsim/,core platform platform/esb platform/sky cli ui util chip extutil/highlight extutil/jfreechart} +PACKAGES := se/sics/mspsim ${addprefix se/sics/mspsim/,core platform platform/esb platform/sky cli ui util chip net extutil/highlight extutil/jfreechart} SOURCES := ${wildcard *.java $(addsuffix /*.java,$(PACKAGES))} Modified: mspsim/se/sics/mspsim/chip/DS2411.java =================================================================== --- mspsim/se/sics/mspsim/chip/DS2411.java 2009-03-25 22:39:18 UTC (rev 506) +++ mspsim/se/sics/mspsim/chip/DS2411.java 2009-04-02 10:57:59 UTC (rev 507) @@ -71,7 +71,7 @@ private int writePos = 0; /* max 10 bytes to write back */ private int[] writeBuf = new int[10]; - private int[] macID = new int[]{0, 1, 2, 3, 4, 5}; + private int[] macID = new int[]{1, 2, 3, 4, 5, 6}; private TimeEvent stateEvent = new TimeEvent(0) { public void execute(long t) { Modified: mspsim/se/sics/mspsim/net/HC01PacketHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/HC01PacketHandler.java 2009-03-25 22:39:18 UTC (rev 506) +++ mspsim/se/sics/mspsim/net/HC01PacketHandler.java 2009-04-02 10:57:59 UTC (rev 507) @@ -197,6 +197,8 @@ /* infer IID from L2 address */ byte[] linkAddress = getLinkSourceAddress(packet); System.arraycopy(linkAddress, 0, packet.sourceAddress, 8, 8); + /* TODO: clean autoconf stuff up */ + packet.sourceAddress[8] ^= 0x02; break; case IPHC_SAM_16: if((data[pos] & 0x80) == 0) { @@ -254,6 +256,8 @@ /* figure out a way to pick this up from link-layer !!! */ byte[] destAddress = getLinkDestinationAddress(packet); System.arraycopy(destAddress, 0, packet.destAddress, 8, 8); + /* cleanup autoconf stuff later ... */ + packet.destAddress[8] ^= 0x02; break; case IPHC_DAM_16: if((data[pos] & 0x80) == 0) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-03-25 22:39:39
|
Revision: 506 http://mspsim.svn.sourceforge.net/mspsim/?rev=506&view=rev Author: joxe Date: 2009-03-25 22:39:18 +0000 (Wed, 25 Mar 2009) Log Message: ----------- added flash write/read support in Core Modified Paths: -------------- mspsim/se/sics/mspsim/core/MSP430Core.java Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2009-03-25 21:41:23 UTC (rev 505) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2009-03-25 22:39:18 UTC (rev 506) @@ -127,6 +127,7 @@ private ArrayList<Chip> chips = new ArrayList<Chip>(); Profiler profiler; + private Flash flash; public MSP430Core(int type) { // Ignore type for now... @@ -148,6 +149,15 @@ Watchdog wdt = new Watchdog(this); memOut[0x120] = wdt; memIn[0x120] = wdt; + + /* TODO: this range is only valid for the F1611 series (Sky, etc) */ + flash = new Flash(this, memory, + new FlashRange(0x4000, 0x10000, 512, 64), + new FlashRange(0x1000, 0x01100, 128, 64)); + for (int i = 0x128; i < 0x12e; i++) { + memOut[i] = flash; + memIn[i] = flash; + } sfr = new SFR(this, memory); for (int i = 0, n = 0x10; i < n; i++) { @@ -617,6 +627,11 @@ val = memIn[address].read(address, word, cycles); } else { address &= 0xffff; + + if (flash.addressInFlash(address)) { + flash.notifyRead(address); + } + val = memory[address] & 0xff; if (word) { val |= (memory[(address + 1) & 0xffff] << 8); @@ -632,7 +647,8 @@ } public void write(int dstAddress, int dst, boolean word) throws EmulationException { - // TODO: optimize memory usage by tagging memory's higher bits. + // TODO: optimize memory usage by tagging memory's higher bits. + // will also affect below flash write stuff!!! if (breakPoints[dstAddress] != null) { breakPoints[dstAddress].cpuAction(CPUMonitor.MEMORY_WRITE, dstAddress, dst); } @@ -640,9 +656,21 @@ // Only word writes at 0x1fe which is highest address... if (dstAddress < 0x1ff && memOut[dstAddress] != null) { if (!word) dst &= 0xff; - memOut[dstAddress].write(dstAddress, dst, word, cycles); + memOut[dstAddress].write(dstAddress, dst, word, cycles); + // } else { + // // TODO: add check for Flash / RAM! + // memory[dstAddress] = dst & 0xff; + // if (word) { + // memory[dstAddress + 1] = (dst >> 8) & 0xff; + // if ((dstAddress & 1) != 0) { + // printWarning(MISALIGNED_WRITE, dstAddress); + // } + // } + // check for Flash + } else if (flash.addressInFlash(dstAddress)) { + flash.flashWrite(dstAddress, dst, word); } else { - // TODO: add check for Flash / RAM! + // assume RAM memory[dstAddress] = dst & 0xff; if (word) { memory[dstAddress + 1] = (dst >> 8) & 0xff; @@ -684,6 +712,12 @@ if (profiler != null) { profiler.profileInterrupt(interruptMax, cycles); } + + if (flash.blocksCPU()) { + /* TODO: how should this error/warning be handled ?? */ + throw new IllegalStateException( + "Got interrupt while flash controller blocks CPU. CPU CRASHED."); + } // Only store stuff on irq except reset... - not sure if this is correct... // TODO: Check what to do if reset is called! @@ -763,7 +797,7 @@ } /* Did not execute any instructions */ - if (cpuOff) { + if (cpuOff || flash.blocksCPU()) { // System.out.println("Jumping: " + (nextIOTickCycles - cycles)); // nextEventCycles must exist, otherwise CPU can not wake up!? if (maxCycles >= 0 && maxCycles < nextEventCycles) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-03-25 21:41:26
|
Revision: 505 http://mspsim.svn.sourceforge.net/mspsim/?rev=505&view=rev Author: joxe Date: 2009-03-25 21:41:23 +0000 (Wed, 25 Mar 2009) Log Message: ----------- added flash support files Added Paths: ----------- mspsim/se/sics/mspsim/core/Flash.java mspsim/se/sics/mspsim/core/FlashRange.java Added: mspsim/se/sics/mspsim/core/Flash.java =================================================================== --- mspsim/se/sics/mspsim/core/Flash.java (rev 0) +++ mspsim/se/sics/mspsim/core/Flash.java 2009-03-25 21:41:23 UTC (rev 505) @@ -0,0 +1,614 @@ +/* + * Copyright (c) 2009, Friedrich-Alexander University Erlangen, Germany + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of mspsim. + * + */ +/** + * @author Klaus Stengel <sik...@in...> + */ +package se.sics.mspsim.core; + +import se.sics.mspsim.util.Utils; + +public class Flash extends IOUnit { + private static final boolean DEBUG = true; + + private static final int FCTL1 = 0x0128; + private static final int FCTL2 = 0x012a; + private static final int FCTL3 = 0x012c; + + private static final int FRKEY = 0x9600; + private static final int FWKEY = 0xA500; + private static final int KEYMASK = 0xff00; + private static final int CMDMASK = 0x00ff; + + private static final int BLKWRT = 0x80; + private static final int WRT = 0x40; + + private static final int ERASE_SHIFT = 1; + private static final int ERASE_MASK = 0x06; + + private enum EraseMode { + ERASE_NONE, + ERASE_SEGMENT, + ERASE_MAIN, + ERASE_ALL + }; + + private enum WriteMode { + WRITE_NONE, + WRITE_SINGLE, + WRITE_BLOCK, + WRITE_BLOCK_FINISH + } + + private static final int EMEX = 0x20; + private static final int LOCK = 0x10; + private static final int WAIT = 0x08; + private static final int ACCVIFG = 0x04; + private static final int KEYV = 0x02; + private static final int BUSY = 0x01; + + private static final int FSSEL_SHIFT = 6; + private static final int FSSEL_MASK = 0xc0; + + private static final int RESET_VECTOR = 15; + private static final int NMI_VECTOR = 14; + private static final int ACCVIE = 1 << 5; + + private enum ClockSource { + ACLK, + MCLK, + SMCLK + }; + + private static final int MASS_ERASE_TIME = 5297; + private static final int SEGMENT_ERASE_TIME = 4819; + + private static final int WRITE_TIME = 35; + + private static final int BLOCKWRITE_FIRST_TIME = 30; + private static final int BLOCKWRITE_TIME = 21; + private static final int BLOCKWRITE_END_TIME = 6; + + private static final int FN_MASK = 0x3f; + + private MSP430Core cpu; + private SFR sfr; + private FlashRange main_range; + private FlashRange info_range; + private int[] memory; + + private int mode; /* FCTL1 */ + private int clockcfg; /* FCTL2 */ + private int statusreg; /* FCTL3 */ + + private boolean locked; + private boolean busy; + private boolean wait; + private boolean blocked_cpu; + private EraseMode current_erase; + + private WriteMode current_write_mode; + private int blockwrite_count; + + private TimeEvent end_process = new TimeEvent(0) { + public void execute(long t) { + blocked_cpu = false; + + switch(current_erase) { + case ERASE_NONE: + break; + + case ERASE_SEGMENT: + case ERASE_MAIN: + case ERASE_ALL: + mode = 0; + current_erase = EraseMode.ERASE_NONE; + busy = false; + break; + } + + switch(current_write_mode) { + case WRITE_NONE: + break; + + case WRITE_SINGLE: + mode = 0; + busy = false; + current_write_mode = WriteMode.WRITE_NONE; + break; + + case WRITE_BLOCK: + blockwrite_count++; + if (blockwrite_count == 64) { + // FIXME: What happens if we try to write more than 64 bytes + // on real hardware??? + System.out.printf("Last access in block mode. Forced exit?"); + current_write_mode = WriteMode.WRITE_BLOCK_FINISH; + } +/* if (DEBUG) { + System.out.println("Write cycle complete, flagged WAIT."); + } */ + wait = true; + break; + + case WRITE_BLOCK_FINISH: + if (DEBUG) { + System.out.println("Programming voltage dropped, " + + "write mode disabled."); + } + current_write_mode = WriteMode.WRITE_NONE; + busy = false; + wait = true; + mode = 0; + break; + } + } + }; + + public Flash(MSP430Core cpu, int[] memory, FlashRange main_range, + FlashRange info_range) { + super(memory, FCTL1); + this.cpu = cpu; + this.memory = memory; + this.main_range = main_range; + this.info_range = info_range; + this.sfr = cpu.getSFR(); + locked = true; + + reset(MSP430.RESET_POR); + } + + public boolean blocksCPU() { + return blocked_cpu; + } + + public String getName() { + return "Flash"; + } + + public void interruptServiced(int vector) { + cpu.flagInterrupt(vector, this, false); + } + + public boolean addressInFlash(int address) { + if (main_range.isInRange(address)) { + return true; + } + if (info_range.isInRange(address)) { + return true; + } + + return false; + } + + private int getFlashClockDiv() { + return (clockcfg & FN_MASK) + 1; + } + + private void waitFlashProcess(int time) { + int instr_addr = cpu.readRegister(MSP430.PC); + int freqdiv = getFlashClockDiv(); + int myfreq; + double finish_msec; + + busy = true; + if (addressInFlash(instr_addr)) { + blocked_cpu = true; + } + + switch(getClockSource()) { + case ACLK: + myfreq = cpu.aclkFrq / freqdiv; + finish_msec = ((double)time * freqdiv * 1000) / cpu.aclkFrq; + if (DEBUG) + System.out.println("Flash: Using ACLK source with f=" + myfreq + + " Hz\nFlasg: Time required=" + finish_msec + " ms"); + cpu.scheduleTimeEventMillis(end_process, finish_msec); + break; + + case SMCLK: + myfreq = cpu.smclkFrq / freqdiv; + finish_msec = ((double)time * freqdiv * 1000) / cpu.smclkFrq; + /* if (DEBUG) + System.out.println("Flash: Using SMCLK source with f=" + myfreq + + " Hz\nFlash: Time required=" + finish_msec + " ms"); */ + cpu.scheduleTimeEventMillis(end_process, finish_msec); + break; + + + case MCLK: + if (DEBUG) + System.out.println("Flash: Using MCLK source with div=" + freqdiv); + cpu.scheduleCycleEvent(end_process, (long)time * freqdiv); + break; + } + } + + public boolean needsTick() { + return false; + } + + public void flashWrite(int address, int data, boolean word) { + int wait_time = -1; + + if (locked) { + if (DEBUG) { + System.out.println("Write to flash blocked because of LOCK flag."); + } + return; + } + + if (busy || wait == false) { + if (!((mode & BLKWRT) != 0 && wait)) { + triggerAccessViolation("Flash write prohbited while BUSY=1 or WAIT=0"); + return; + } + } + + switch(current_erase) { + case ERASE_SEGMENT: + int a_area_start[] = new int[1]; + int a_area_end[] = new int[1]; + getSegmentRange(address, a_area_start, a_area_end); + int area_start = a_area_start[0]; + int area_end = a_area_end[0]; + + if (DEBUG) { + System.out.println("Segment erase @" + Utils.hex16(address) + + ": erasing area " + Utils.hex16(area_start) + "-" + + Utils.hex16(area_end)); + } + for (int i = area_start; i < area_end; i++) { + memory[i] = 0xff; + } + waitFlashProcess(SEGMENT_ERASE_TIME); + return; + + case ERASE_MAIN: + if (! main_range.isInRange(address)) { + return; + } + for (int i = main_range.start; i < main_range.end; i++) { + memory[i] = 0xff; + } + waitFlashProcess(MASS_ERASE_TIME); + return; + + case ERASE_ALL: + for (int i = main_range.start; i < main_range.end; i++) { + memory[i] = 0xff; + } + for (int i = info_range.start; i < main_range.end; i++) { + memory[i] = 0xff; + } + waitFlashProcess(MASS_ERASE_TIME); + return; + } + + switch(current_write_mode) { + case WRITE_BLOCK: + wait = false; + // TODO: Register target block and verify all writes stay in the same + // block. What does the real hardware on random writes?!? + if (blockwrite_count == 0) { + wait_time = BLOCKWRITE_FIRST_TIME; + if (DEBUG) { + System.out.println("Flash write in block mode started @" + + Utils.hex16(address)); + } + if (addressInFlash(cpu.readRegister(MSP430.PC))) { + System.out.println("Oops. Block write access only allowed when" + + " executing from RAM."); + } + } else { + wait_time = BLOCKWRITE_TIME; + } + break; + + case WRITE_SINGLE: + wait_time = WRITE_TIME; + break; + } + + /* Flash memory allows clearing bits only */ + memory[address] &= data & 0xff; + if (word) { + memory[address + 1] &= (data >> 8) & 0xff; + } + + if (wait_time < 0) { + throw new RuntimeException("Wait time not properly initialized"); + } + waitFlashProcess(wait_time); + } + + public void notifyRead(int address) { + if (busy) { + triggerAccessViolation("Flash read not allowed while BUSY flag set"); + return; + } + if (DEBUG) { + if (wait == false && current_write_mode == WriteMode.WRITE_BLOCK) { + System.out.println("Reading flash prohibited. Would read 0x3fff!!!\n" + + "CPU PC=" + Utils.hex16(cpu.readRegister(MSP430.PC)) + + " read address=" + Utils.hex16(address)); + } + } + } + + private FlashRange getFlashRange(int address) { + if (main_range.isInRange(address)) { + return main_range; + } + if (info_range.isInRange(address)) { + return info_range; + } + return null; + } + + private void getSegmentRange(int address, int[] start, int[] end) { + FlashRange addr_type = getFlashRange(address); + int segsize, ioffset; + + if (addr_type == null) { + throw new RuntimeException("Address not in flash"); + } + + segsize = addr_type.segment_size; + ioffset = address - addr_type.start; + + ioffset /= segsize; + ioffset *= segsize; + + start[0] = addr_type.start + ioffset; + end[0] = start[0] + segsize; + } + + public int read(int address, boolean word, long cycles) { + if (address == FCTL1) { + return mode | FRKEY; + } + if (address == FCTL2) { + return clockcfg | FRKEY; + } + if (address == FCTL3) { + int retval = statusreg | FRKEY; + + if (busy) + retval |= BUSY; + + if (locked) + retval |= LOCK; + + if (wait) + retval |= WAIT; + + return retval; + } + + return 0; + } + + private ClockSource getClockSource() { + switch((clockcfg & FSSEL_MASK) >> FSSEL_SHIFT) { + case 0: + return ClockSource.ACLK; + case 1: + return ClockSource.MCLK; + case 2: + case 3: + return ClockSource.SMCLK; + } + throw new RuntimeException("Bad clock source"); + } + + private boolean checkKey(int value) { + if ((value & KEYMASK) == FWKEY) + return true; + + System.out.println("Bad key accessing flash controller --> reset"); + statusreg |= KEYV; + cpu.flagInterrupt(RESET_VECTOR, this, true); + return false; + } + + private void triggerEmergencyExit() { + mode = 0; + busy = false; + wait = true; + locked = true; + current_erase = EraseMode.ERASE_NONE; + current_write_mode = WriteMode.WRITE_NONE; + + } + + private EraseMode getEraseMode(int regdata) { + int idx = (regdata & ERASE_MASK) >> ERASE_SHIFT; + + for(EraseMode em : EraseMode.values()) { + if (em.ordinal() == idx) + return em; + } + throw new RuntimeException("Invalid erase mode"); + } + + private void triggerErase(int newmode) { + current_erase = getEraseMode(newmode); + } + + private void triggerLockFlash() { + locked = true; + } + + private void triggerUnlockFlash() { + locked = false; + } + + private void triggerAccessViolation(String reason) { + if (DEBUG) + System.out.println("Flash access violation: " + reason + + "\nPC=" + Utils.hex16(cpu.readRegister(MSP430.PC))); + + statusreg |= ACCVIFG; + if (sfr.isIEBitsSet(SFR.IE1, ACCVIE)) { + cpu.flagInterrupt(NMI_VECTOR, this, true); + } + } + + private void triggerSingleWrite() { + /*if (DEBUG) { + System.out.println("Single write triggered"); + }*/ + current_write_mode = WriteMode.WRITE_SINGLE; + } + + private void triggerBlockWrite() { + if (DEBUG) { + System.out.println("Block write triggered"); + } + current_write_mode = WriteMode.WRITE_BLOCK; + blockwrite_count = 0; + } + + private void triggerEndBlockWrite() { + if (DEBUG) { + System.out.println("Got end of flash block write"); + } + current_write_mode = WriteMode.WRITE_BLOCK_FINISH; + waitFlashProcess(BLOCKWRITE_END_TIME); + } + + public void write(int address, int value, boolean word, long cycles) { + if (!word) { + System.out.println("Invalid access type to flash controller"); + return; + } + + if (!(address == FCTL1 || address == FCTL2 || address == FCTL3)) { + return; + } + + if (!checkKey(value)) { + return; + } + + int regdata = value & CMDMASK; + switch (address) { + case FCTL1: + // access violation while erase/write in progress + // exception: block write mode and WAIT==1 + if ((mode & ERASE_MASK) != 0 || (mode & WRT) != 0) { + if (!((mode & BLKWRT) != 0 && wait)) { + triggerAccessViolation( + "FCTL1 write not allowed while erase/write active."); + return; + } + } + + if ((mode & ERASE_MASK) != (regdata & ERASE_MASK)) { + if ((mode & ERASE_MASK) == 0) { + triggerErase(regdata); + } + mode &= ~ERASE_MASK; + mode |= regdata & ERASE_MASK; + } + + if ((mode & WRT) != (regdata & WRT)) { + if ((regdata & WRT) != 0) { + if ((regdata & BLKWRT) != 0) { + triggerBlockWrite(); + mode |= BLKWRT; + } else { + triggerSingleWrite(); + } + mode &= ~WRT; + mode |= regdata & WRT; + } + } + + if ((mode & BLKWRT) != 0 && (regdata & BLKWRT) == 0) { + triggerEndBlockWrite(); + mode &= ~BLKWRT; + } + break; + + case FCTL2: + // access violation if BUSY==1 + if (busy) { + triggerAccessViolation( + "Register write to FCTL2 not allowed when busy"); + return; + } + clockcfg = regdata; + break; + + case FCTL3: + if ((statusreg & EMEX) == 0 && (regdata & EMEX) == 1) { + triggerEmergencyExit(); + } + + if (locked && (regdata & LOCK) == 0) { + triggerUnlockFlash(); + } else { + if (!locked && (regdata & LOCK) != 0) { + triggerLockFlash(); + } + } + + if (((statusreg ^ regdata) & KEYV) != 0) { + statusreg ^= KEYV; + } + if (((statusreg ^ regdata) & ACCVIFG) != 0) { + statusreg ^= ACCVIFG; + } + + break; + } + } + + public void reset(int type) { + if (DEBUG) { + System.out.println("Flash got reset!"); + } + + if (type == MSP430.RESET_POR) + statusreg = 0; + + mode = 0; + clockcfg = 0x42; + busy = false; + wait = true; + locked = true; + current_erase = EraseMode.ERASE_NONE; + current_write_mode = WriteMode.WRITE_NONE; + } +} Property changes on: mspsim/se/sics/mspsim/core/Flash.java ___________________________________________________________________ Added: svn:executable + * Added: mspsim/se/sics/mspsim/core/FlashRange.java =================================================================== --- mspsim/se/sics/mspsim/core/FlashRange.java (rev 0) +++ mspsim/se/sics/mspsim/core/FlashRange.java 2009-03-25 21:41:23 UTC (rev 505) @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2009, Friedrich-Alexander University Erlangen, Germany + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of mspsim. + * + */ +/** + * @author Klaus Stengel <sik...@in...> + */ +package se.sics.mspsim.core; + +public class FlashRange { + public int start; + public int end; + public int segment_size; + public int blocksize; + + public FlashRange(int start, int end, int segment_size, int blocksize) { + this.start = start; + this.end = end; + this.segment_size = segment_size; + this.blocksize = blocksize; + } + + public boolean isInRange(int address) { + if (address >= start && address < end) { + return true; + } + return false; + } +} + Property changes on: mspsim/se/sics/mspsim/core/FlashRange.java ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-03-25 11:29:42
|
Revision: 504 http://mspsim.svn.sourceforge.net/mspsim/?rev=504&view=rev Author: joxe Date: 2009-03-25 11:29:23 +0000 (Wed, 25 Mar 2009) Log Message: ----------- added speed factor Modified Paths: -------------- mspsim/se/sics/mspsim/cli/DebugCommands.java Modified: mspsim/se/sics/mspsim/cli/DebugCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/DebugCommands.java 2009-03-25 09:30:22 UTC (rev 503) +++ mspsim/se/sics/mspsim/cli/DebugCommands.java 2009-03-25 11:29:23 UTC (rev 504) @@ -61,15 +61,15 @@ private ELF getELF() { return (ELF) registry.getComponent(ELF.class); } - + public void setupCommands(ComponentRegistry registry, CommandHandler ch) { this.registry = registry; final MSP430 cpu = (MSP430) registry.getComponent(MSP430.class); final GenericNode node = (GenericNode) registry.getComponent("node"); if (cpu != null) { ch.registerCommand("break", new BasicAsyncCommand("add a breakpoint to a given address or symbol", - "<address or symbol>") { - int address = 0; + "<address or symbol>") { + int address = 0; public int executeCommand(final CommandContext context) { int baddr = context.getArgumentAsAddress(0); if (baddr < 0) { @@ -97,7 +97,7 @@ public int executeCommand(final CommandContext context) { int baddr = context.getArgumentAsAddress(0); if (baddr == -1) { - context.err.println("unknown symbol: " + context.getArgument(0)); + context.err.println("unknown symbol: " + context.getArgument(0)); return -1; } if (context.getArgumentCount() > 1) { @@ -175,7 +175,7 @@ context.out.println("Watch set for register " + getRegisterName(register)); return 0; } - + public void stopCommand(CommandContext context) { cpu.clearBreakPoint(register); } @@ -211,7 +211,7 @@ return 0; } }); - + ch.registerCommand("line", new BasicCommand("print line number of address/symbol", "<addres or symbol>") { public int executeCommand(final CommandContext context) { int adr = context.getArgumentAsAddress(0); @@ -224,8 +224,8 @@ } return 0; } - }); - + }); + if (node != null) { ch.registerCommand("stop", new BasicCommand("stop the CPU", "") { public int executeCommand(CommandContext context) { @@ -245,7 +245,7 @@ int nr = context.getArgumentCount() > 0 ? context.getArgumentAsInt(0) : 1; long cyc = cpu.cycles; try { - node.step(nr); + node.step(nr); } catch (Exception e) { e.printStackTrace(context.out); } @@ -299,14 +299,16 @@ ch.registerCommand("time", new BasicCommand("print the elapse time and cycles", "") { public int executeCommand(CommandContext context) { long time = ((long)(cpu.getTimeMillis())); + long wallDiff = System.currentTimeMillis() - lastWall; context.out.println("Emulated time elapsed: " + time + "(ms) since last: " + (time - lastCall) + " ms" + " wallTime: " + - (System.currentTimeMillis() - lastWall) + " ms"); + wallDiff + " ms speed factor: " + + (wallDiff == 0 ? "N/A" : "" + (time - lastCall) / wallDiff)); lastCall = time; lastWall = System.currentTimeMillis(); return 0; } }); - + ch.registerCommand("mem", new BasicCommand("dump memory", "<start address> <num_emtries> [type]") { public int executeCommand(final CommandContext context) { int start = context.getArgumentAsAddress(0); @@ -350,9 +352,9 @@ } return 0; }}); - + /****************************************************** - * handle external memory (flash, etc). + * handle external memory (flash, etc). ******************************************************/ ch.registerCommand("xmem", new BasicCommand("dump flash memory", "<start address> <num_emtries> [type]") { public int executeCommand(final CommandContext context) { @@ -389,7 +391,7 @@ return 0; } }); - + ch.registerCommand("xset", new BasicCommand("set memory", "<address> <value> [type]") { public int executeCommand(final CommandContext context) { Memory xmem = (Memory) DebugCommands.this.registry.getComponent("xmem"); @@ -422,7 +424,7 @@ return 0; } }); - + ch.registerCommand("loggable", new BasicCommand("list loggable objects", "") { @Override public int executeCommand(CommandContext context) { @@ -433,7 +435,7 @@ return 0; } }); - + ch.registerCommand("log", new BasicAsyncCommand("log a loggable object", "<loggable>" ) { Chip chip = null; @Override @@ -450,7 +452,7 @@ chip.clearLogStream(); } }); - + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-03-25 09:30:37
|
Revision: 503 http://mspsim.svn.sourceforge.net/mspsim/?rev=503&view=rev Author: joxe Date: 2009-03-25 09:30:22 +0000 (Wed, 25 Mar 2009) Log Message: ----------- applied bugfix-patch for MSP430 core Modified Paths: -------------- mspsim/se/sics/mspsim/core/MSP430Core.java mspsim/se/sics/mspsim/net/HC01PacketHandler.java Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2009-03-24 23:03:24 UTC (rev 502) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2009-03-25 09:30:22 UTC (rev 503) @@ -891,7 +891,7 @@ // Indicate write to memory!! write = true; // Set the next carry! - writeRegister(SR, (readRegister(SR) & ~CARRY) | nxtCarry); + writeRegister(SR, (readRegister(SR) & ~(CARRY | OVERFLOW)) | nxtCarry); break; case SWPB: int tmp = dst; @@ -906,13 +906,19 @@ dst = (dst & 0x80) | (dst >> 1); } write = true; - writeRegister(SR, (readRegister(SR) & ~CARRY) | nxtCarry); + writeRegister(SR, (readRegister(SR) & ~(CARRY | OVERFLOW)) | nxtCarry); break; case SXT: - // Extend Sign (bit 8-15 => same as bit 7) - dst = (dst & 0x80) > 0 ? dst | 0xff00 : dst & 0x7f; - write = true; - break; + // Extend Sign (bit 8-15 => same as bit 7) + sr = readRegister(SR); + dst = (dst & 0x80) > 0 ? dst | 0xff00 : dst & 0x7f; + write = true; + sr = sr & ~(CARRY | OVERFLOW); + if (dst != 0) { + sr |= CARRY; + } + writeRegister(SR, sr); + break; case PUSH: if (word) { // Put lo & hi on stack! @@ -1028,6 +1034,7 @@ if (jump) { writeRegister(PC, pc + jmpOffset); } + updateStatus = false; break; default: // --------------------------------------------------------------- @@ -1236,13 +1243,28 @@ updateStatus = false; break; case XOR: // XOR - dst = src ^ dst; - write = true; - break; + sr = readRegister(SR); + sr = sr & ~(CARRY | OVERFLOW); + if ((src & (word ? 0x8000 : 0x80)) != 0 && (dst & (word ? 0x8000 : 0x80)) != 0) { + sr |= OVERFLOW; + } + dst = src ^ dst; + if (dst != 0) { + sr |= CARRY; + } + write = true; + writeRegister(SR, sr); + break; case AND: // AND - dst = src & dst; - write = true; - break; + sr = readRegister(SR); + sr = sr & ~(CARRY | OVERFLOW); + dst = src & dst; + if (dst != 0) { + sr |= CARRY; + } + write = true; + writeRegister(SR, sr); + break; default: System.out.println("DoubleOperand not implemented: " + op + " at " + pc); if (EXCEPTION_ON_BAD_OPERATION) { Modified: mspsim/se/sics/mspsim/net/HC01PacketHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/HC01PacketHandler.java 2009-03-24 23:03:24 UTC (rev 502) +++ mspsim/se/sics/mspsim/net/HC01PacketHandler.java 2009-03-25 09:30:22 UTC (rev 503) @@ -305,9 +305,9 @@ switch(data[pos] & 0xff) { case NHC_UDP_C: /* 1 byte for NHC, 1 byte for ports, 2 bytes chksum */ - srcPort = UDP_PORT_MIN + (data[pos + 1] >> 4); + srcPort = UDP_PORT_MIN + ((data[pos + 1] & 0xff) >> 4); destPort = UDP_PORT_MIN + (data[pos + 1] & 0x0F); - checkSum = (data[pos + 2] << 8) + data[pos + 3]; + checkSum = ((data[pos + 2] & 0xff) << 8) + (data[pos + 3] & 0xff); pos += 4; break; case NHC_UDP_I: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-03-24 23:03:27
|
Revision: 502 http://mspsim.svn.sourceforge.net/mspsim/?rev=502&view=rev Author: joxe Date: 2009-03-24 23:03:24 +0000 (Tue, 24 Mar 2009) Log Message: ----------- almost working checksum Modified Paths: -------------- mspsim/se/sics/mspsim/net/ICMP6Packet.java mspsim/se/sics/mspsim/net/IEEE802154Packet.java Modified: mspsim/se/sics/mspsim/net/ICMP6Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/ICMP6Packet.java 2009-03-24 21:21:42 UTC (rev 501) +++ mspsim/se/sics/mspsim/net/ICMP6Packet.java 2009-03-24 23:03:24 UTC (rev 502) @@ -52,9 +52,8 @@ data[2] = 0; data[3] = 0; int sum = ip.upperLayerHeaderChecksum(); - System.out.printf("*** Checksum: %04x == My Checksum: %04x", - checksum, IPv6Packet.checkSum(sum, data, len)); - + System.out.printf("*** Checksum: %04x == My Checksum: %04x \n", + checksum, (~IPv6Packet.checkSum(sum, data, len)) & 0xffff); } } Modified: mspsim/se/sics/mspsim/net/IEEE802154Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/IEEE802154Packet.java 2009-03-24 21:21:42 UTC (rev 501) +++ mspsim/se/sics/mspsim/net/IEEE802154Packet.java 2009-03-24 23:03:24 UTC (rev 502) @@ -150,8 +150,7 @@ pos += 8; } } - /* two bytes in the end that are not included in payload! */ - setPayload(data, pos, len - pos - 2); + setPayload(data, pos, len - pos); } private void printAddress(PrintStream out, int type, long addr) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-03-24 21:21:46
|
Revision: 501 http://mspsim.svn.sourceforge.net/mspsim/?rev=501&view=rev Author: joxe Date: 2009-03-24 21:21:42 +0000 (Tue, 24 Mar 2009) Log Message: ----------- removed two last bytes from the 802154 payload Modified Paths: -------------- mspsim/se/sics/mspsim/net/CC2420PacketHandler.java mspsim/se/sics/mspsim/net/HC01PacketHandler.java mspsim/se/sics/mspsim/net/IEEE802154Packet.java Modified: mspsim/se/sics/mspsim/net/CC2420PacketHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/CC2420PacketHandler.java 2009-03-24 19:48:55 UTC (rev 500) +++ mspsim/se/sics/mspsim/net/CC2420PacketHandler.java 2009-03-24 21:21:42 UTC (rev 501) @@ -76,7 +76,7 @@ if (pos == packetLen + PREAMBLE.length + 1) { /* the packet is in!!! */ CC2420Packet packet = new CC2420Packet(); - packet.setPayload(packetBuffer, PREAMBLE.length + 1, packetLen); + packet.setPayload(packetBuffer, PREAMBLE.length + 1, packetLen - 2); dispatch(-1, packet); System.out.println("Packet received"); packet.printPacket(System.out); Modified: mspsim/se/sics/mspsim/net/HC01PacketHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/HC01PacketHandler.java 2009-03-24 19:48:55 UTC (rev 500) +++ mspsim/se/sics/mspsim/net/HC01PacketHandler.java 2009-03-24 21:21:42 UTC (rev 501) @@ -208,15 +208,15 @@ /* set hi address as prefix from context */ System.arraycopy(context.prefix, 0, packet.sourceAddress, 0, 8); /* copy 6 NULL bytes then 2 last bytes of IID */ - java.util.Arrays.fill(packet.sourceAddress, 8, 16, (byte)0); + java.util.Arrays.fill(packet.sourceAddress, 8, 14, (byte)0); packet.sourceAddress[14] = data[pos]; packet.sourceAddress[15] = data[pos + 1]; pos += 2; } else { /* [ignore] multicast address check the 9-bit group-id is known */ java.util.Arrays.fill(packet.sourceAddress, 0, 16, (byte)0); - packet.sourceAddress[0] = (byte)0xff; - packet.sourceAddress[1] = (byte)(((data[pos] & 0xff) >> 1) & 0x0F); + packet.sourceAddress[0] = (byte)0xff; + packet.sourceAddress[1] = (byte)(((data[pos] & 0xff) >> 1) & 0x0f); packet.sourceAddress[15] = data[pos + 1]; pos += 2; } @@ -269,6 +269,7 @@ pos += 2; } else { /* [ignore] multicast address check the 9-bit group-id is known */ + System.out.println("*** Multicast address!!! HC01"); java.util.Arrays.fill(packet.destAddress, 0, 16, (byte)0); packet.destAddress[0] = (byte)0xff; packet.destAddress[1] = (byte)(((data[pos] & 0xff) >> 1) & 0x0F); Modified: mspsim/se/sics/mspsim/net/IEEE802154Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/IEEE802154Packet.java 2009-03-24 19:48:55 UTC (rev 500) +++ mspsim/se/sics/mspsim/net/IEEE802154Packet.java 2009-03-24 21:21:42 UTC (rev 501) @@ -48,6 +48,7 @@ public static final int SHORT_ADDRESS = 2; public static final int LONG_ADDRESS = 3; + // TODO: remove long addresses... private int type = 0; private int security = 0; private int pending = 0; @@ -149,7 +150,8 @@ pos += 8; } } - setPayload(data, pos, len - pos); + /* two bytes in the end that are not included in payload! */ + setPayload(data, pos, len - pos - 2); } private void printAddress(PrintStream out, int type, long addr) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-03-24 19:49:18
|
Revision: 500 http://mspsim.svn.sourceforge.net/mspsim/?rev=500&view=rev Author: joxe Date: 2009-03-24 19:48:55 +0000 (Tue, 24 Mar 2009) Log Message: ----------- fixed hc01 address resolution from 802154 layer Modified Paths: -------------- mspsim/se/sics/mspsim/net/HC01PacketHandler.java mspsim/se/sics/mspsim/net/ICMP6Packet.java mspsim/se/sics/mspsim/net/IEEE802154Packet.java Modified: mspsim/se/sics/mspsim/net/HC01PacketHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/HC01PacketHandler.java 2009-03-24 18:37:24 UTC (rev 499) +++ mspsim/se/sics/mspsim/net/HC01PacketHandler.java 2009-03-24 19:48:55 UTC (rev 500) @@ -89,9 +89,16 @@ contexts[2] = new AddrContext(); contexts[3] = new AddrContext(); - for (int i = 0; i < contexts.length; i++) { - java.util.Arrays.fill(contexts[i].prefix, (byte)(i + 1)); - } + contexts[0].used = 1; + contexts[0].number = 0; + contexts[0].prefix[0] = (byte) 0xfe; + contexts[0].prefix[1] = (byte) 0x80; + + contexts[1].used = 1; + contexts[1].number = 1; + contexts[1].prefix[0] = (byte) 0xaa; + contexts[1].prefix[1] = (byte) 0xaa; + } public void packetReceived(Packet container) { @@ -106,6 +113,27 @@ public void sendPacket(Packet payload) { } + private byte[] getLinkSourceAddress(AbstractPacket packet) { + while (packet != null && !(packet instanceof IEEE802154Packet)) + packet = (AbstractPacket) packet.containerPacket; + if (packet != null) { + IEEE802154Packet ieeePacket = (IEEE802154Packet) packet; + return ieeePacket.getSourceAddress(); + } + return null; + } + + private byte[] getLinkDestinationAddress(AbstractPacket packet) { + while (packet != null && !(packet instanceof IEEE802154Packet)) + packet = (AbstractPacket) packet.containerPacket; + if (packet != null) { + IEEE802154Packet ieeePacket = (IEEE802154Packet) packet; + return ieeePacket.getDestinationAddress(); + } + return null; + } + + public void setPacketData(IPv6Packet packet, byte[] data, int len) { /* first two is ... */ int pos = 2; @@ -157,166 +185,166 @@ /* 0, 1, 2, 3 as source address ??? */ int srcAddress = (data[1] & 0x30) >> 4; - AddrContext context = lookupContext(srcAddress); - switch (data[1] & 0xc0) { - case IPHC_SAM_0: - if(context == null) { - System.out.println("sicslowpan uncompress_hdr: error context not found\n"); - return; - } - /* set hi address as prefix from context */ - System.arraycopy(context.prefix, 0, packet.sourceAddress, 0, 8); - /* infer IID from L2 address */ + AddrContext context = lookupContext(srcAddress); + switch (data[1] & 0xc0) { + case IPHC_SAM_0: + if(context == null) { + System.out.println("sicslowpan uncompress_hdr: error context not found\n"); + return; + } + /* set hi address as prefix from context */ + System.arraycopy(context.prefix, 0, packet.sourceAddress, 0, 8); + /* infer IID from L2 address */ + byte[] linkAddress = getLinkSourceAddress(packet); + System.arraycopy(linkAddress, 0, packet.sourceAddress, 8, 8); + break; + case IPHC_SAM_16: + if((data[pos] & 0x80) == 0) { + /* unicast address */ + if(context == null) { + System.out.println("sicslowpan uncompress_hdr: error context not found\n"); + return; + } + /* set hi address as prefix from context */ + System.arraycopy(context.prefix, 0, packet.sourceAddress, 0, 8); + /* copy 6 NULL bytes then 2 last bytes of IID */ + java.util.Arrays.fill(packet.sourceAddress, 8, 16, (byte)0); + packet.sourceAddress[14] = data[pos]; + packet.sourceAddress[15] = data[pos + 1]; + pos += 2; + } else { + /* [ignore] multicast address check the 9-bit group-id is known */ + java.util.Arrays.fill(packet.sourceAddress, 0, 16, (byte)0); + packet.sourceAddress[0] = (byte)0xff; + packet.sourceAddress[1] = (byte)(((data[pos] & 0xff) >> 1) & 0x0F); + packet.sourceAddress[15] = data[pos + 1]; + pos += 2; + } + break; + case IPHC_SAM_64: + if(context == null) { + System.out.println("sicslowpan uncompress_hdr: error context not found\n"); + return; + } + /* copy prefix from context */ + System.arraycopy(context.prefix, 0, packet.sourceAddress, 0, 8); + /* copy IID from packet */ + System.arraycopy(data, pos, packet.sourceAddress, 8, 8); + pos += 8; + break; + case IPHC_SAM_I: + /* copy whole address from packet */ + System.arraycopy(data, pos, packet.sourceAddress, 0, 16); + pos += 16; + break; + } - /* should figure out a way to get the link layer address here!!! */ - // packet.sourceAddressLo = 0; - break; - case IPHC_SAM_16: - if((data[pos] & 0x80) == 0) { - /* unicast address */ - if(context == null) { - System.out.println("sicslowpan uncompress_hdr: error context not found\n"); - return; - } - /* set hi address as prefix from context */ - System.arraycopy(context.prefix, 0, packet.sourceAddress, 0, 8); - /* copy 6 NULL bytes then 2 last bytes of IID */ - java.util.Arrays.fill(packet.sourceAddress, 8, 16, (byte)0); - packet.sourceAddress[14] = data[pos]; - packet.sourceAddress[15] = data[pos + 1]; - pos += 2; - } else { - /* [ignore] multicast address check the 9-bit group-id is known */ - java.util.Arrays.fill(packet.sourceAddress, 0, 16, (byte)0); - packet.sourceAddress[0] = (byte)0xff; - packet.sourceAddress[1] = (byte)(((data[pos] & 0xff) >> 1) & 0x0F); - packet.sourceAddress[15] = data[pos + 1]; - pos += 2; - } - break; - case IPHC_SAM_64: - if(context == null) { - System.out.println("sicslowpan uncompress_hdr: error context not found\n"); - return; - } - /* copy prefix from context */ - System.arraycopy(context.prefix, 0, packet.sourceAddress, 0, 8); - /* copy IID from packet */ - System.arraycopy(data, pos, packet.sourceAddress, 8, 8); - pos += 8; - break; - case IPHC_SAM_I: - /* copy whole address from packet */ - System.arraycopy(data, pos, packet.sourceAddress, 0, 16); - pos += 16; - break; + /* Destination address */ + context = lookupContext(data[2] & 0x03); + + switch(data[1] & 0x0C) { + case IPHC_DAM_0: + if(context == null) { + System.out.println("sicslowpan uncompress_hdr: error context not found\n"); + return; + } + /* copy prefix from context */ + System.arraycopy(context.prefix, 0, packet.destAddress, 0, 8); + /* infer IID from L2 address */ + /* figure out a way to pick this up from link-layer !!! */ + byte[] destAddress = getLinkDestinationAddress(packet); + System.arraycopy(destAddress, 0, packet.destAddress, 8, 8); + break; + case IPHC_DAM_16: + if((data[pos] & 0x80) == 0) { + /* unicast address */ + if(context == null) { + System.out.println("sicslowpan uncompress_hdr: error context not found\n"); + return; } + System.arraycopy(context.prefix, 0, packet.destAddress, 0, 8); + /* copy 6 NULL bytes then 2 last bytes of IID */ + packet.destAddress[14] = data[pos]; + packet.destAddress[15] = data[pos + 1]; + pos += 2; + } else { + /* [ignore] multicast address check the 9-bit group-id is known */ + java.util.Arrays.fill(packet.destAddress, 0, 16, (byte)0); + packet.destAddress[0] = (byte)0xff; + packet.destAddress[1] = (byte)(((data[pos] & 0xff) >> 1) & 0x0F); + packet.destAddress[15] = data[pos + 1]; + pos += 2; + } + break; + case IPHC_DAM_64: + if(context == null) { + System.out.println("sicslowpan uncompress_hdr: error context not found\n"); + return; + } + /* copy prefix from context */ + System.arraycopy(context.prefix, 0, packet.destAddress, 0, 8); + /* copy IID from packet */ + System.arraycopy(data, pos, packet.destAddress, 8, 8); + pos += 8; + break; + case IPHC_DAM_I: + /* copy whole address from packet */ + System.arraycopy(data, pos, packet.destAddress, 0, 16); + pos += 16; + break; + } - /* Destination address */ - context = lookupContext(data[2] & 0x03); - - switch(data[1] & 0x0C) { - case IPHC_DAM_0: - if(context == null) { - System.out.println("sicslowpan uncompress_hdr: error context not found\n"); - return; - } - /* copy prefix from context */ - System.arraycopy(context.prefix, 0, packet.destAddress, 0, 8); - /* infer IID from L2 address */ - /* figure out a way to pick this up from link-layer !!! */ - // TODO: get low from config + if ((data[0] & 0x20) != 0) { + /* The next header is compressed, NHC is following */ + if ((data[pos] & 0xfc) == NHC_UDP_ID) { + packet.nextHeader = PROTO_UDP; + int srcPort = 0; + int destPort = 0; + int checkSum = 0; + switch(data[pos] & 0xff) { + case NHC_UDP_C: + /* 1 byte for NHC, 1 byte for ports, 2 bytes chksum */ + srcPort = UDP_PORT_MIN + (data[pos + 1] >> 4); + destPort = UDP_PORT_MIN + (data[pos + 1] & 0x0F); + checkSum = (data[pos + 2] << 8) + data[pos + 3]; + pos += 4; break; - case IPHC_DAM_16: - if((data[pos] & 0x80) == 0) { - /* unicast address */ - if(context == null) { - System.out.println("sicslowpan uncompress_hdr: error context not found\n"); - return; - } - System.arraycopy(context.prefix, 0, packet.destAddress, 0, 8); - /* copy 6 NULL bytes then 2 last bytes of IID */ - packet.destAddress[14] = data[pos]; - packet.destAddress[15] = data[pos + 1]; - pos += 2; - } else { - /* [ignore] multicast address check the 9-bit group-id is known */ - java.util.Arrays.fill(packet.destAddress, 0, 16, (byte)0); - packet.destAddress[0] = (byte)0xff; - packet.destAddress[1] = (byte)(((data[pos] & 0xff) >> 1) & 0x0F); - packet.destAddress[15] = data[pos + 1]; - pos += 2; - } + case NHC_UDP_I: + /* 1 byte for NHC, 4 byte for ports, 2 bytes chksum */ + srcPort = ((data[pos + 1] & 0xff)<< 8) + (data[pos + 2] & 0xff); + destPort = ((data[pos + 3] & 0xff)<< 8) + (data[pos + 4] & 0xff); + checkSum = ((data[pos + 5] & 0xff)<< 8) + (data[pos + 6] & 0xff); + pos += 7; break; - case IPHC_DAM_64: - if(context == null) { - System.out.println("sicslowpan uncompress_hdr: error context not found\n"); - return; - } - /* copy prefix from context */ - System.arraycopy(context.prefix, 0, packet.destAddress, 0, 8); - /* copy IID from packet */ - System.arraycopy(data, pos, packet.destAddress, 8, 8); - pos += 8; - break; - case IPHC_DAM_I: - /* copy whole address from packet */ - System.arraycopy(data, pos, packet.destAddress, 0, 16); - pos += 16; - break; + default: + System.out.println("sicslowpan uncompress_hdr: error unsupported UDP compression\n"); + return; } + System.out.println("DestPort: " + destPort); + System.out.println("SourcePort: " + srcPort); + System.out.println("Checksum: " + srcPort); + } + } - if ((data[0] & 0x20) != 0) { - /* The next header is compressed, NHC is following */ - if ((data[pos] & 0xfc) == NHC_UDP_ID) { - packet.nextHeader = PROTO_UDP; - int srcPort = 0; - int destPort = 0; - int checkSum = 0; - switch(data[pos] & 0xff) { - case NHC_UDP_C: - /* 1 byte for NHC, 1 byte for ports, 2 bytes chksum */ - srcPort = UDP_PORT_MIN + (data[pos + 1] >> 4); - destPort = UDP_PORT_MIN + (data[pos + 1] & 0x0F); - checkSum = (data[pos + 2] << 8) + data[pos + 3]; - pos += 4; - break; - case NHC_UDP_I: - /* 1 byte for NHC, 4 byte for ports, 2 bytes chksum */ - srcPort = ((data[pos + 1] & 0xff)<< 8) + (data[pos + 2] & 0xff); - destPort = ((data[pos + 3] & 0xff)<< 8) + (data[pos + 4] & 0xff); - checkSum = ((data[pos + 5] & 0xff)<< 8) + (data[pos + 6] & 0xff); - pos += 7; - break; - default: - System.out.println("sicslowpan uncompress_hdr: error unsupported UDP compression\n"); - return; - } - System.out.println("DestPort: " + destPort); - System.out.println("SourcePort: " + srcPort); - System.out.println("Checksum: " + srcPort); - } - } + boolean frag = false; + /* fragment handling ... */ + if (!frag) { + /* this does not handle the UDP header compression yet... */ + int plen = len - pos; + packet.setPayload(data, pos, plen); + } else { + } - boolean frag = false; - /* fragment handling ... */ - if (!frag) { - /* this does not handle the UDP header compression yet... */ - int plen = len - pos; - packet.setPayload(data, pos, plen); - } else { - } - - System.out.println("Encoding 0: " + Utils.hex8(data[0]) + - " Encoding 1: " + Utils.hex8(data[1])); + System.out.println("Encoding 0: " + Utils.hex8(data[0]) + + " Encoding 1: " + Utils.hex8(data[1])); - System.out.println("TTL: " + packet.hopLimit); - System.out.print("Src Addr: "); - IPv6Packet.printAddress(System.out, packet.sourceAddress); - System.out.print(" Dest Addr: "); - IPv6Packet.printAddress(System.out, packet.destAddress); - System.out.println(); - // packet.setPayload(data, 40, ???); + System.out.println("TTL: " + packet.hopLimit); + System.out.print("Src Addr: "); + IPv6Packet.printAddress(System.out, packet.sourceAddress); + System.out.print(" Dest Addr: "); + IPv6Packet.printAddress(System.out, packet.destAddress); + System.out.println(); + // packet.setPayload(data, 40, ???); } private AddrContext lookupContext(int index) { Modified: mspsim/se/sics/mspsim/net/ICMP6Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/ICMP6Packet.java 2009-03-24 18:37:24 UTC (rev 499) +++ mspsim/se/sics/mspsim/net/ICMP6Packet.java 2009-03-24 19:48:55 UTC (rev 500) @@ -48,10 +48,12 @@ type = data[0] & 0xff; code = data[1] & 0xff; checksum = ((data[2] & 0xff) << 8) | data[3] & 0xff; - /* test the checksum ... */ -// int sum = ip.upperLayerHeaderChecksum(); -// System.out.printf("*** My Checksum: %04x", -// IPv6Packet.checkSum(sum, data, len)); + /* test the checksum ... - set checksum to zero*/ + data[2] = 0; + data[3] = 0; + int sum = ip.upperLayerHeaderChecksum(); + System.out.printf("*** Checksum: %04x == My Checksum: %04x", + checksum, IPv6Packet.checkSum(sum, data, len)); } } Modified: mspsim/se/sics/mspsim/net/IEEE802154Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/IEEE802154Packet.java 2009-03-24 18:37:24 UTC (rev 499) +++ mspsim/se/sics/mspsim/net/IEEE802154Packet.java 2009-03-24 19:48:55 UTC (rev 500) @@ -60,13 +60,23 @@ private int destPanID; private long destAddr; private long srcAddr; + private byte[] destAddress = new byte[8]; + private byte[] sourceAddress = new byte[8]; private int srcPanID; public IEEE802154Packet(Packet container) { byte[] payload = container.getPayload(); setPacketData(container, payload, payload.length); } + + public byte[] getDestinationAddress() { + return destAddress; + } + public byte[] getSourceAddress() { + return sourceAddress; + } + public void printPacket(PrintStream out) { out.printf("802.15.4 from %4x/", srcPanID); printAddress(out, srcAddrMode, srcAddr); @@ -98,12 +108,19 @@ pos += 2; if (destAddrMode == SHORT_ADDRESS) { destAddr = (data[pos] & 0xff) + ((data[pos + 1] & 0xff) << 8); + destAddress[1] = data[pos]; + destAddress[0] = data[pos + 1]; pos += 2; } else if (destAddrMode == LONG_ADDRESS) { destAddr = data[pos] + ((data[pos + 1] & 0xffL) << 8) + ((data[pos + 2] & 0xffL) << 16) + ((data[pos + 3] & 0xffL) << 24) + ((data[pos + 4] & 0xffL) << 32) + ((data[pos + 5] & 0xffL)<< 40) + ((data[pos + 6] & 0xffL) << 48) + ((data[pos + 7] & 0xffL) << 56); + + for (int i = 0; i < 8; i++) { + destAddress[i] = data[pos + 7 - i]; + } + pos += 8; } } @@ -117,12 +134,18 @@ } if (srcAddrMode == SHORT_ADDRESS) { srcAddr = (data[pos] & 0xff) + ((data[pos + 1] & 0xff) << 8); + sourceAddress[1] = data[pos]; + sourceAddress[0] = data[pos + 1]; pos += 2; } else if (srcAddrMode == LONG_ADDRESS) { srcAddr = data[pos] + ((data[pos + 1] & 0xffL) << 8) + ((data[pos + 2] & 0xffL) << 16) + ((data[pos + 3] & 0xffL) << 24) + ((data[pos + 4] & 0xffL) << 32) + ((data[pos + 5] & 0xffL)<< 40) + ((data[pos + 6] & 0xffL) << 48) + ((data[pos + 7] & 0xffL) << 56); + + for (int i = 0; i < 8; i++) { + sourceAddress[i] = data[pos + 7 - i]; + } pos += 8; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-03-24 18:37:33
|
Revision: 499 http://mspsim.svn.sourceforge.net/mspsim/?rev=499&view=rev Author: joxe Date: 2009-03-24 18:37:24 +0000 (Tue, 24 Mar 2009) Log Message: ----------- changed ipv6addr to be 16 bytes instead of 2 longs Modified Paths: -------------- mspsim/se/sics/mspsim/net/HC01PacketHandler.java mspsim/se/sics/mspsim/net/IPv6Packet.java Modified: mspsim/se/sics/mspsim/net/HC01PacketHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/HC01PacketHandler.java 2009-03-23 23:31:25 UTC (rev 498) +++ mspsim/se/sics/mspsim/net/HC01PacketHandler.java 2009-03-24 18:37:24 UTC (rev 499) @@ -77,7 +77,7 @@ private static class AddrContext { int used; int number; - long prefix; + byte[] prefix = new byte[8]; } private AddrContext[] contexts = new AddrContext[4]; @@ -90,7 +90,7 @@ contexts[3] = new AddrContext(); for (int i = 0; i < contexts.length; i++) { - contexts[i].prefix = 0xaaaa000000000000L | ((i + 1)<< 8) | i + 1; + java.util.Arrays.fill(contexts[i].prefix, (byte)(i + 1)); } } @@ -165,11 +165,11 @@ return; } /* set hi address as prefix from context */ - packet.sourceAddressHi = context.prefix; + System.arraycopy(context.prefix, 0, packet.sourceAddress, 0, 8); /* infer IID from L2 address */ /* should figure out a way to get the link layer address here!!! */ - packet.sourceAddressLo = 0; + // packet.sourceAddressLo = 0; break; case IPHC_SAM_16: if((data[pos] & 0x80) == 0) { @@ -179,15 +179,18 @@ return; } /* set hi address as prefix from context */ - packet.sourceAddressHi = context.prefix; + System.arraycopy(context.prefix, 0, packet.sourceAddress, 0, 8); /* copy 6 NULL bytes then 2 last bytes of IID */ - packet.sourceAddressLo = (data[pos] & 0xff) << 8+ data[pos + 1]; + java.util.Arrays.fill(packet.sourceAddress, 8, 16, (byte)0); + packet.sourceAddress[14] = data[pos]; + packet.sourceAddress[15] = data[pos + 1]; pos += 2; } else { /* [ignore] multicast address check the 9-bit group-id is known */ - packet.sourceAddressHi = (0xff << 56) + - ((((data[pos] & 0xff) >> 1) & 0x0F) << 48); - packet.sourceAddressLo = data[pos + 1] & 0xff; + java.util.Arrays.fill(packet.sourceAddress, 0, 16, (byte)0); + packet.sourceAddress[0] = (byte)0xff; + packet.sourceAddress[1] = (byte)(((data[pos] & 0xff) >> 1) & 0x0F); + packet.sourceAddress[15] = data[pos + 1]; pos += 2; } break; @@ -197,17 +200,15 @@ return; } /* copy prefix from context */ - packet.sourceAddressHi = context.prefix; + System.arraycopy(context.prefix, 0, packet.sourceAddress, 0, 8); /* copy IID from packet */ - packet.sourceAddressLo = IPv6Packet.getLong(data, pos); + System.arraycopy(data, pos, packet.sourceAddress, 8, 8); pos += 8; break; case IPHC_SAM_I: /* copy whole address from packet */ - packet.sourceAddressHi = IPv6Packet.getLong(data, pos); - pos += 8; - packet.sourceAddressLo = IPv6Packet.getLong(data, pos); - pos += 8; + System.arraycopy(data, pos, packet.sourceAddress, 0, 16); + pos += 16; break; } @@ -221,10 +222,10 @@ return; } /* copy prefix from context */ - packet.destAddressHi = context.prefix; + System.arraycopy(context.prefix, 0, packet.destAddress, 0, 8); /* infer IID from L2 address */ /* figure out a way to pick this up from link-layer !!! */ - packet.destAddressLo = 0; + // TODO: get low from config break; case IPHC_DAM_16: if((data[pos] & 0x80) == 0) { @@ -233,15 +234,17 @@ System.out.println("sicslowpan uncompress_hdr: error context not found\n"); return; } - packet.destAddressHi = context.prefix; + System.arraycopy(context.prefix, 0, packet.destAddress, 0, 8); /* copy 6 NULL bytes then 2 last bytes of IID */ - packet.destAddressLo = ((data[pos] & 0xff) << 8) + data[pos + 1] & 0xff; + packet.destAddress[14] = data[pos]; + packet.destAddress[15] = data[pos + 1]; pos += 2; } else { - /* multicast address check the 9-bit group-id is known */ - packet.sourceAddressHi = (0xff << 56) + - ((((data[pos] & 0xff) >> 1) & 0x0F) << 48); - packet.sourceAddressLo = data[pos + 1] & 0xff; + /* [ignore] multicast address check the 9-bit group-id is known */ + java.util.Arrays.fill(packet.destAddress, 0, 16, (byte)0); + packet.destAddress[0] = (byte)0xff; + packet.destAddress[1] = (byte)(((data[pos] & 0xff) >> 1) & 0x0F); + packet.destAddress[15] = data[pos + 1]; pos += 2; } break; @@ -251,17 +254,15 @@ return; } /* copy prefix from context */ - packet.destAddressHi = context.prefix; + System.arraycopy(context.prefix, 0, packet.destAddress, 0, 8); /* copy IID from packet */ - packet.destAddressLo = IPv6Packet.getLong(data, pos); + System.arraycopy(data, pos, packet.destAddress, 8, 8); pos += 8; break; case IPHC_DAM_I: /* copy whole address from packet */ - packet.destAddressHi = IPv6Packet.getLong(data, pos); - pos += 8; - packet.destAddressLo = IPv6Packet.getLong(data, pos); - pos += 8; + System.arraycopy(data, pos, packet.destAddress, 0, 16); + pos += 16; break; } @@ -311,13 +312,10 @@ System.out.println("TTL: " + packet.hopLimit); System.out.print("Src Addr: "); - IPv6Packet.printAddress(System.out, packet.sourceAddressHi, - packet.sourceAddressLo); + IPv6Packet.printAddress(System.out, packet.sourceAddress); System.out.print(" Dest Addr: "); - IPv6Packet.printAddress(System.out, packet.destAddressHi, - packet.destAddressLo); + IPv6Packet.printAddress(System.out, packet.destAddress); System.out.println(); - // packet.setPayload(data, 40, ???); } Modified: mspsim/se/sics/mspsim/net/IPv6Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/IPv6Packet.java 2009-03-23 23:31:25 UTC (rev 498) +++ mspsim/se/sics/mspsim/net/IPv6Packet.java 2009-03-24 18:37:24 UTC (rev 499) @@ -56,30 +56,31 @@ int flowLabel; int nextHeader; int hopLimit; - long sourceAddressHi; - long sourceAddressLo; - long destAddressHi; - long destAddressLo; + byte[] sourceAddress = new byte[16]; + byte[] destAddress = new byte[16]; public void printPacket(PrintStream out) { out.printf("IPv6: from "); - printAddress(out, sourceAddressHi, sourceAddressLo); + printAddress(out, sourceAddress); out.print(" to "); - printAddress(out, destAddressHi, destAddressLo); + printAddress(out, destAddress); out.printf(" NxHdr: %d\n", nextHeader); if (payloadPacket != null) { payloadPacket.printPacket(out); } } - public static void printAddress(PrintStream out, long hi, long lo) { - out.printf("%04x:%04x:%04x:%04x:", (hi >> 48) & 0xffff, - (hi >> 32) & 0xffff, (hi >> 16) & 0xffff, hi & 0xffff); - out.printf("%04x:%04x:%04x:%04x", (lo >> 48) & 0xffff, - (lo >> 32) & 0xffff, (lo >> 16) & 0xffff, lo & 0xffff); + public static void printAddress(PrintStream out, byte[] address) { + for (int i = 0; i < 16; i+=2) { + out.printf("%04x", (((address[i] & 0xff) << 8) | address[i + 1] & 0xff)); + if (i < 14) { + out.print(":"); + } + } + out.println(); } - + /* this is for setting raw packet data */ public void setPacketData(Packet container, byte[] data, int len) { version = (data[0] & 0xff) >> 4; if (version != 6) { @@ -91,10 +92,8 @@ payloadLen = ((data[4] & 0xff) << 8) + data[5]; nextHeader = data[6]; hopLimit = data[7]; - sourceAddressHi = getLong(data, 8); - sourceAddressLo = getLong(data, 16); - destAddressHi = getLong(data, 24); - destAddressLo = getLong(data, 32); + System.arraycopy(data, 8, sourceAddress, 0, 16); + System.arraycopy(data, 24, destAddress, 0, 16); setPayload(data, 40, payloadLen); } @@ -112,10 +111,8 @@ /* IP protocol and length fields. This addition cannot carry. */ int sum = payloadLen + nextHeader; /* Sum IP source and destination addresses. */ - sum = checkSum(sum, sourceAddressHi); - sum = checkSum(sum, sourceAddressLo); - sum = checkSum(sum, destAddressHi); - sum = checkSum(sum, destAddressLo); + sum = checkSum(sum, sourceAddress, 16); + sum = checkSum(sum, destAddress, 16); /* Sum upper layer header and data is done separately.... */ /* -- needs to get hold of uncompressed payload for that ... */ @@ -123,19 +120,6 @@ return sum; } - public static int checkSum(int sum, long data) { - int roll = 48; - for (int i = 0; i < 4; i++) { - int dsum = (int) ((data >> roll) & 0xffff); - System.out.print("Summing: " + sum + " + " + dsum + " = "); - sum = (sum + dsum) & 0xffff; - if (sum < dsum) sum++; - System.out.println(sum); - roll = roll - 16; - } - return sum; - } - public static int checkSum(int sum, byte[] data, int size) { for (int i = 0; i < size; i+= 2) { int dsum = ((data[i] & 0xff) << 8) | (data[i + 1] & 0xff); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-03-23 23:31:34
|
Revision: 498 http://mspsim.svn.sourceforge.net/mspsim/?rev=498&view=rev Author: joxe Date: 2009-03-23 23:31:25 +0000 (Mon, 23 Mar 2009) Log Message: ----------- removed unused class Removed Paths: ------------- mspsim/se/sics/mspsim/net/HC01Packet.java Deleted: mspsim/se/sics/mspsim/net/HC01Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/HC01Packet.java 2009-03-23 22:25:52 UTC (rev 497) +++ mspsim/se/sics/mspsim/net/HC01Packet.java 2009-03-23 23:31:25 UTC (rev 498) @@ -1,277 +0,0 @@ -package se.sics.mspsim.net; - -import java.awt.print.Printable; - -import se.sics.mspsim.util.Utils; - -public class HC01Packet extends IPv6Packet { - public final static int IPHC_TTL_1 = 0x08; - public final static int IPHC_TTL_64 = 0x10; - public final static int IPHC_TTL_255 = 0x18; - public final static int IPHC_TTL_I = 0x00; - - /* Values of fields within the IPHC encoding second byte */ - public final static int IPHC_SAM_I = 0x00; - public final static int IPHC_SAM_64 = 0x40; - public final static int IPHC_SAM_16 = 0x80; - public final static int IPHC_SAM_0 = 0xC0; - public final static int IPHC_DAM_I = 0x00; - public final static int IPHC_DAM_64 = 0x04; - public final static int IPHC_DAM_16 = 0x08; - public final static int IPHC_DAM_0 = 0x0C; - - public final static int NHC_UDP_ID = 0xF8; - public final static int NHC_UDP_C = 0xFB; - public final static int NHC_UDP_I = 0xF8; - - /* Min and Max compressible UDP ports */ - public final static int UDP_PORT_MIN = 0xF0B0; - public final static int UDP_PORT_MAX = 0xF0BF; /* F0B0 + 15 */ - - public static final int HC01_DISPATCH = 0x03; - - public final static int PROTO_ICMP = 1; - public final static int PROTO_TCP = 6; - public final static int PROTO_UDP = 17; - public final static int PROTO_ICMP6 = 58; - - - private static class AddrContext { - int used; - int number; - long prefix; - } - - private AddrContext[] contexts = new AddrContext[4]; - - public HC01Packet() { - // setut some fake contexts just to get started... - contexts[0] = new AddrContext(); - contexts[1] = new AddrContext(); - contexts[2] = new AddrContext(); - contexts[3] = new AddrContext(); - - for (int i = 0; i < contexts.length; i++) { - contexts[i].prefix = 0xaaaa000000000000L | ((i + 1)<< 8) | i + 1; - } - } - - public void setPacketData(Packet packet, byte[] data, int len) { - int pos = 3; - if (data[0] != HC01_DISPATCH) return; - if ((data[1] & 0x40) == 0) { - if ((data[1] & 0x80) == 0) { - version = (data[pos] & 0xf0) >> 4; - trafficClass = ((data[pos] & 0x0f)<<4) + ((data[pos + 1] & 0xff) >> 4); - flowLabel = (data[pos + 1] & 0x0f) << 16 + (data[pos + 2] & 0xff) << 8 + - data[pos + 3] & 0xff; - pos += 4; - } else { - version = 6; - trafficClass = 0; - flowLabel = (data[pos] & 0x0f) << 16 - + (data[pos + 1] & 0xff) << 8 + data[pos + 2] & 0xff;; - pos += 3; - } - } else { - version = 6; - flowLabel = 0; - if ((data[1] & 0x80) == 0) { - trafficClass = (data[pos] & 0xff); - pos++; - } else { - trafficClass = 0; - } - } - - /* next header not compressed -> get it */ - if ((data[1] & 0x20) == 0) { - nextHeader = data[pos++]; - } - - /* encoding of TTL */ - switch (data[1] & 0x18) { - case IPHC_TTL_1: - hopLimit = 1; - break; - case IPHC_TTL_64: - hopLimit = 64; - break; - case IPHC_TTL_255: - hopLimit = 0xff; - break; - case IPHC_TTL_I: - hopLimit = data[pos++]; - break; - } - - /* 0, 1, 2, 3 as source address ??? */ - int srcAddress = (data[2] & 0x30) >> 4; - AddrContext context = lookupContext(srcAddress); - switch (data[2] & 0xc0) { - case IPHC_SAM_0: - if(context == null) { - System.out.println("sicslowpan uncompress_hdr: error context not found\n"); - return; - } - /* set hi address as prefix from context */ - sourceAddressHi = context.prefix; - /* infer IID from L2 address */ - - /* should figure out a way to get the link layer address here!!! */ - sourceAddressLo = 0; - break; - case IPHC_SAM_16: - if((data[pos] & 0x80) == 0) { - /* unicast address */ - if(context == null) { - System.out.println("sicslowpan uncompress_hdr: error context not found\n"); - return; - } - /* set hi address as prefix from context */ - sourceAddressHi = context.prefix; - /* copy 6 NULL bytes then 2 last bytes of IID */ - sourceAddressLo = (data[pos] & 0xff) << 8+ data[pos + 1]; - pos += 2; - } else { - /* [ignore] multicast address check the 9-bit group-id is known */ - sourceAddressHi = (0xff << 56) + - ((((data[pos] & 0xff) >> 1) & 0x0F) << 48); - sourceAddressLo = data[pos + 1] & 0xff; - pos += 2; - } - break; - case IPHC_SAM_64: - if(context == null) { - System.out.println("sicslowpan uncompress_hdr: error context not found\n"); - return; - } - /* copy prefix from context */ - sourceAddressHi = context.prefix; - /* copy IID from packet */ - sourceAddressLo = getLong(data, pos); - pos += 8; - break; - case IPHC_SAM_I: - /* copy whole address from packet */ - sourceAddressHi = getLong(data, pos); - pos += 8; - sourceAddressLo = getLong(data, pos); - pos += 8; - break; - } - - /* Destination address */ - context = lookupContext(data[2] & 0x03); - - switch(data[2] & 0x0C) { - case IPHC_DAM_0: - if(context == null) { - System.out.println("sicslowpan uncompress_hdr: error context not found\n"); - return; - } - /* copy prefix from context */ - destAddressHi = context.prefix; - /* infer IID from L2 address */ - /* figure out a way to pick this up from link-layer !!! */ - destAddressLo = 0; - break; - case IPHC_DAM_16: - if((data[pos] & 0x80) == 0) { - /* unicast address */ - if(context == null) { - System.out.println("sicslowpan uncompress_hdr: error context not found\n"); - return; - } - destAddressHi = context.prefix; - /* copy 6 NULL bytes then 2 last bytes of IID */ - destAddressLo = ((data[pos] & 0xff) << 8) + data[pos + 1] & 0xff; - pos += 2; - } else { - /* multicast address check the 9-bit group-id is known */ - sourceAddressHi = (0xff << 56) + - ((((data[pos] & 0xff) >> 1) & 0x0F) << 48); - sourceAddressLo = data[pos + 1] & 0xff; - pos += 2; - } - break; - case IPHC_DAM_64: - if(context == null) { - System.out.println("sicslowpan uncompress_hdr: error context not found\n"); - return; - } - /* copy prefix from context */ - destAddressHi = context.prefix; - /* copy IID from packet */ - destAddressLo = getLong(data, pos); - pos += 8; - break; - case IPHC_DAM_I: - /* copy whole address from packet */ - destAddressHi = getLong(data, pos); - pos += 8; - destAddressLo = getLong(data, pos); - pos += 8; - break; - } - - if ((data[1] & 0x20) != 0) { - /* The next header is compressed, NHC is following */ - if ((data[pos] & 0xfc) == NHC_UDP_ID) { - nextHeader = PROTO_UDP; - int srcPort = 0; - int destPort = 0; - int checkSum = 0; - switch(data[pos] & 0xff) { - case NHC_UDP_C: - /* 1 byte for NHC, 1 byte for ports, 2 bytes chksum */ - srcPort = UDP_PORT_MIN + (data[pos + 1] >> 4); - destPort = UDP_PORT_MIN + (data[pos + 1] & 0x0F); - checkSum = (data[pos + 2] << 8) + data[pos + 3]; - pos += 4; - break; - case NHC_UDP_I: - /* 1 byte for NHC, 4 byte for ports, 2 bytes chksum */ - srcPort = ((data[pos + 1] & 0xff)<< 8) + (data[pos + 2] & 0xff); - destPort = ((data[pos + 3] & 0xff)<< 8) + (data[pos + 4] & 0xff); - checkSum = ((data[pos + 5] & 0xff)<< 8) + (data[pos + 6] & 0xff); - pos += 7; - break; - default: - System.out.println("sicslowpan uncompress_hdr: error unsupported UDP compression\n"); - return; - } - System.out.println("DestPort: " + destPort); - System.out.println("SourcePort: " + srcPort); - System.out.println("Checksum: " + srcPort); - } - } - - boolean frag = false; - /* fragment handling ... */ - if (!frag) { - /* this does not handle the UDP header compression yet... */ - int plen = len - pos; - setPayload(data, pos, plen); - } else { - } - - System.out.println("Data[1]: " + Utils.hex8(data[1]) + - " Data[2]: " + Utils.hex8(data[2])); - - System.out.println("TTL: " + hopLimit); - System.out.print("Src Addr: "); - printAddress(System.out, sourceAddressHi, sourceAddressLo); - System.out.print(" Dest Addr: "); - printAddress(System.out, destAddressHi, destAddressLo); - System.out.println(); - - setPayload(data, 40, payloadLen); - } - - private AddrContext lookupContext(int index) { - if (index < contexts.length) - return contexts[index]; - return null; - } -} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-03-23 22:26:19
|
Revision: 497 http://mspsim.svn.sourceforge.net/mspsim/?rev=497&view=rev Author: joxe Date: 2009-03-23 22:25:52 +0000 (Mon, 23 Mar 2009) Log Message: ----------- changed model for network packet management Modified Paths: -------------- mspsim/se/sics/mspsim/cli/MiscCommands.java mspsim/se/sics/mspsim/net/AbstractPacket.java mspsim/se/sics/mspsim/net/CC2420Packet.java mspsim/se/sics/mspsim/net/ICMP6Packet.java mspsim/se/sics/mspsim/net/IEEE802154Packet.java mspsim/se/sics/mspsim/net/IPv6Packet.java mspsim/se/sics/mspsim/net/Packet.java Added Paths: ----------- mspsim/se/sics/mspsim/net/AbstractPacketHandler.java mspsim/se/sics/mspsim/net/CC2420PacketHandler.java mspsim/se/sics/mspsim/net/HC01PacketHandler.java mspsim/se/sics/mspsim/net/ICMP6PacketHandler.java mspsim/se/sics/mspsim/net/IEEE802154Handler.java mspsim/se/sics/mspsim/net/LoWPANHandler.java mspsim/se/sics/mspsim/net/LoWPANPacket.java mspsim/se/sics/mspsim/net/PacketHandler.java Modified: mspsim/se/sics/mspsim/cli/MiscCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/MiscCommands.java 2009-03-22 17:57:32 UTC (rev 496) +++ mspsim/se/sics/mspsim/cli/MiscCommands.java 2009-03-23 22:25:52 UTC (rev 497) @@ -55,8 +55,14 @@ import se.sics.mspsim.core.MSP430; import se.sics.mspsim.core.TimeEvent; import se.sics.mspsim.net.CC2420Packet; -import se.sics.mspsim.net.HC01Packet; +import se.sics.mspsim.net.CC2420PacketHandler; +import se.sics.mspsim.net.HC01PacketHandler; +import se.sics.mspsim.net.ICMP6Packet; +import se.sics.mspsim.net.ICMP6PacketHandler; +import se.sics.mspsim.net.IEEE802154Handler; import se.sics.mspsim.net.IEEE802154Packet; +import se.sics.mspsim.net.IPv6Packet; +import se.sics.mspsim.net.LoWPANHandler; import se.sics.mspsim.util.ComponentRegistry; import se.sics.mspsim.util.Utils; @@ -311,15 +317,21 @@ } }); handler.registerCommand("rfanalyzer", new BasicLineCommand("analyze radio packets", "") { - CC2420Packet listener; + CC2420PacketHandler listener; CommandContext context; public int executeCommand(CommandContext context) { this.context = context; - listener = new CC2420Packet(); - IEEE802154Packet ieeePacket = new IEEE802154Packet(); - listener.addInnerPacketHandler(ieeePacket); - HC01Packet pan = new HC01Packet(); - ieeePacket.addInnerPacketHandler(pan); + listener = new CC2420PacketHandler(); + IEEE802154Handler ieeeHandler = new IEEE802154Handler(); + listener.addUpperLayerHandler(0, ieeeHandler); + LoWPANHandler lowpanHandler = new LoWPANHandler(); + ieeeHandler.addUpperLayerHandler(0, lowpanHandler); + HC01PacketHandler hc01Handler = new HC01PacketHandler(); + + lowpanHandler.addUpperLayerHandler(0x03, hc01Handler); + hc01Handler.addUpperLayerHandler(IPv6Packet.ICMP6_DISPATCH, + new ICMP6PacketHandler()); + return 0; } public void lineRead(String line) { @@ -327,11 +339,8 @@ byte[] data = Utils.hexconv(line); for (int i = 0; i < data.length; i++) { //context.out.println("Byte " + i + " = " + ((int) data[i] & 0xff)); + // Currently it will autoprint when packet is ready... listener.receivedByte(data[i]); - if (listener.validPacket()) { - listener.printPacketStack(context.out); - listener.clear(); - } } } } Modified: mspsim/se/sics/mspsim/net/AbstractPacket.java =================================================================== --- mspsim/se/sics/mspsim/net/AbstractPacket.java 2009-03-22 17:57:32 UTC (rev 496) +++ mspsim/se/sics/mspsim/net/AbstractPacket.java 2009-03-23 22:25:52 UTC (rev 497) @@ -41,55 +41,29 @@ package se.sics.mspsim.net; -import java.io.PrintStream; -import java.util.ArrayList; - public abstract class AbstractPacket implements Packet { byte[] payload; int payloadLen; - ArrayList<AbstractPacket> packetHandlers = new ArrayList<AbstractPacket>(); - boolean valid = false; + Packet containerPacket; + Packet payloadPacket; - public void addInnerPacketHandler(AbstractPacket packet) { - packetHandlers.add(packet); + public byte[] getPayload() { + return payload; } - - public boolean validPacket() { - return valid; - } - public void clear() { - valid = false; + public void setPayloadPacket(Packet packet) { + payloadPacket = packet; } - - public byte[] getPayload() { - return payload; + + public void setContainerPacket(Packet packet) { + containerPacket = packet; } void setPayload(byte[] data, int startPos, int len) { payloadLen = len; payload = new byte[payloadLen]; System.arraycopy(data, startPos, payload, 0, payloadLen); - valid = true; - notifyPacketHandlers(payload, payloadLen); - } - - public void notifyPacketHandlers(byte[] payload, int len) { - for (int i = 0; i < packetHandlers.size(); i++) { - try { - packetHandlers.get(i).setPacketData(this, payload, len); - } catch (Exception e) { - } - } - } - - public void printPacketStack(PrintStream out) { - printPacket(out); - for (int i = 0; i < packetHandlers.size(); i++) { - /* only the valid packets should print anything... */ - packetHandlers.get(i).printPacketStack(out); - } - } -} + } +} \ No newline at end of file Added: mspsim/se/sics/mspsim/net/AbstractPacketHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/AbstractPacketHandler.java (rev 0) +++ mspsim/se/sics/mspsim/net/AbstractPacketHandler.java 2009-03-23 22:25:52 UTC (rev 497) @@ -0,0 +1,85 @@ +/** + * Copyright (c) 2009, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of MSPSim. + * + * $Id: $ + * + * ----------------------------------------------------------------- + * + * + * Author : Joakim Eriksson + * Created : mar 2009 + * Updated : $Date:$ + * $Revision:$ + */ + +package se.sics.mspsim.net; + +import java.util.ArrayList; + +public abstract class AbstractPacketHandler implements PacketHandler { + + ArrayList<PacketHandlerDispatch> upperLayers = + new ArrayList<PacketHandlerDispatch>(); + PacketHandler lowerLayer; + + public void addUpperLayerHandler(int protoID, PacketHandler handler) { + PacketHandlerDispatch layer = new PacketHandlerDispatch(); + layer.dispatch = protoID; + layer.packetHandler = handler; + upperLayers.add(layer); + } + + public void setLowerLayerHandler(PacketHandler handler) { + lowerLayer = handler; + } + + void dispatch(int dispatch, Packet container) { + byte[] payload = container.getPayload(); + if (dispatch != -1) { + for (int i = 0; i < upperLayers.size(); i++) { + if (upperLayers.get(i).dispatch == dispatch) { + upperLayers.get(i).packetHandler.packetReceived(container); + return; + } + } + System.out.println("**** no dispatch handler for " + dispatch + " found..."); + } else if (upperLayers.size() > 0){ + upperLayers.get(0).packetHandler.packetReceived(container); + } + } + + public abstract void packetReceived(Packet container); + + public abstract void sendPacket(Packet payload); + + private static class PacketHandlerDispatch { + int dispatch; + PacketHandler packetHandler; + } +} \ No newline at end of file Modified: mspsim/se/sics/mspsim/net/CC2420Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/CC2420Packet.java 2009-03-22 17:57:32 UTC (rev 496) +++ mspsim/se/sics/mspsim/net/CC2420Packet.java 2009-03-23 22:25:52 UTC (rev 497) @@ -1,170 +1,20 @@ -/** - * Copyright (c) 2008, Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Institute nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * This file is part of MSPSim. - * - * $Id: $ - * - * ----------------------------------------------------------------- - * - * CC2420Packet - * - * Author : Joakim Eriksson - * Created : mar 2009 - * Updated : $Date:$ - * $Revision:$ - */ - package se.sics.mspsim.net; import java.io.PrintStream; -import se.sics.mspsim.chip.RFListener; -public class CC2420Packet extends AbstractPacket implements RFListener { +public class CC2420Packet extends AbstractPacket { - private static final int SFD_SEARCH = 1; - private static final int LEN = 2; - private static final int PACKET = 3; - - private static final byte[] PREAMBLE = {0, 0, 0, 0, 0x7a}; - private int len; - private byte[] payload; - - public byte[] getDataField(String name) { - return null; - } - - public int getIntField(String name) { - return 0; - } - - public byte[] getPayload() { - return null; - } - - public int getSize() { - return len; - } - - /* should this be the interface??? or only RF_LIST ???*/ - /* maybe this is default and CC2420 is "special" */ - public void setPacketData(Packet container, byte[] data, int plen) { - if (data.length > PREAMBLE.length) { - int pos = 0; - for (int i = 0; i < PREAMBLE.length; i++) { - if (data[i] != PREAMBLE[i]) { - throw new IllegalStateException("Illegal packet data"); - } - pos++; - } - len = data[pos] & 0xff; - - /* this will have RSSI and other junk last in the packet */ - if (len + 5 <= plen) { - payload = new byte[len & 0xff]; - System.arraycopy(data, pos + 1, payload, 0, len); - /* ignore RSSI, etc for now */ - System.out.println("Valid CC2420 packet received..."); - valid = true; - notifyPacketHandlers(payload, payload.length); - return; - } else { - throw new IllegalStateException("Illegal packet data"); - } - } - } - - public void clear() { - pos = 0; - mode = SFD_SEARCH; - valid = false; - } - - byte[] packetBuffer = new byte[256]; - int mode = SFD_SEARCH; - int pos; - int packetLen; - int sfdSearch = 0; - - public void receivedByte(byte data) { - packetBuffer[pos++] = data; - switch (mode) { - case SFD_SEARCH: - if (sfdSearch < 4 && data == 0) - sfdSearch++; - if (sfdSearch == 4 && data == 0x7a) { - mode = LEN; - sfdSearch = 0; - } - break; - case LEN: - mode = PACKET; - packetLen = data & 0xff; - System.out.println("Packet len: " + packetLen); - break; - case PACKET: - if (pos == packetLen + PREAMBLE.length + 1) { - /* the packet is in!!! */ - setPacketData(this, packetBuffer, pos); - mode = SFD_SEARCH; - } - break; - } - } - public void printPacket(PrintStream out) { - if (valid) { - out.print("CC2420 | len:" + len + " | "); - for (int i = 0; i < len; i++) { - out.printf("%02x", payload[i] & 0xff); - if ((i & 3) == 3) { - out.print(" "); - } + out.print("CC2420 | len:" + payload.length + " | "); + for (int i = 0; i < payload.length; i++) { + out.printf("%02x", payload[i] & 0xff); + if ((i & 3) == 3) { + out.print(" "); } - out.println(); } - } - - - public static void main(String[] args) { - CC2420Packet p = new CC2420Packet(); - IEEE802154Packet p2 = new IEEE802154Packet(); - p.addInnerPacketHandler(p2); - p2.addInnerPacketHandler(new HC01Packet()); - int[] data = new int[] {0,0,0,0,0x7a,48, - 0x41, 0xCC, 0x74, 0xCD, 0xAB, 0x55, 0x44, 0x33, - 0xFE, 0xFF, 0x22, 0x11, 0x02, 0x16, 0x15, 0x14, - 0xFE, 0xFF, 0x13, 0x12, 0x02, 0x03, 0xC0, 0x9D, - 0x06, 0x80, 0x00, 0x01, 0xAD, 0x39, 0x00, 0x50, - 0xAE, 0xC4, 0x9D, 0xC6, 0x00, 0x00, 0x00, 0x01, - 0x50, 0x10, 0x13, 0x10, 0xE7, 0xBF, 0x00, 0x00}; - for (int i = 0; i < data.length; i++) { - p.receivedByte((byte) (data[i] & 0xff)); + out.println(); + if (payloadPacket != null) { + payloadPacket.printPacket(out); } - p.printPacketStack(System.out); } } Added: mspsim/se/sics/mspsim/net/CC2420PacketHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/CC2420PacketHandler.java (rev 0) +++ mspsim/se/sics/mspsim/net/CC2420PacketHandler.java 2009-03-23 22:25:52 UTC (rev 497) @@ -0,0 +1,99 @@ +/** + * Copyright (c) 2009, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of MSPSim. + * + * $Id: $ + * + * ----------------------------------------------------------------- + * + * + * Author : Joakim Eriksson + * Created : mar 2009 + * Updated : $Date:$ + * $Revision:$ + */ + +package se.sics.mspsim.net; + +import se.sics.mspsim.chip.RFListener; + +public class CC2420PacketHandler extends AbstractPacketHandler implements RFListener { + + private static final int SFD_SEARCH = 1; + private static final int LEN = 2; + private static final int PACKET = 3; + + private static final byte[] PREAMBLE = {0, 0, 0, 0, 0x7a}; + + byte[] packetBuffer = new byte[256]; + int mode = SFD_SEARCH; + int pos; + int packetLen; + int sfdSearch = 0; + + public void receivedByte(byte data) { + packetBuffer[pos++] = data; + switch (mode) { + case SFD_SEARCH: + if (sfdSearch < 4 && data == 0) + sfdSearch++; + if (sfdSearch == 4 && data == 0x7a) { + mode = LEN; + sfdSearch = 0; + } + break; + case LEN: + mode = PACKET; + packetLen = data & 0xff; + System.out.println("Packet len: " + packetLen); + break; + case PACKET: + if (pos == packetLen + PREAMBLE.length + 1) { + /* the packet is in!!! */ + CC2420Packet packet = new CC2420Packet(); + packet.setPayload(packetBuffer, PREAMBLE.length + 1, packetLen); + dispatch(-1, packet); + System.out.println("Packet received"); + packet.printPacket(System.out); + /* this is a packet that has passed the stack! */ + mode = SFD_SEARCH; + pos = 0; + } + break; + } + } + + + public void packetReceived(Packet container) { + // Never any packets received here... + } + + public void sendPacket(Packet payload) { + // give to radio!!! + } +} Added: mspsim/se/sics/mspsim/net/HC01PacketHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/HC01PacketHandler.java (rev 0) +++ mspsim/se/sics/mspsim/net/HC01PacketHandler.java 2009-03-23 22:25:52 UTC (rev 497) @@ -0,0 +1,329 @@ +/** + * Copyright (c) 2009, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of MSPSim. + * + * $Id: $ + * + * ----------------------------------------------------------------- + * + * AbstractPacket + * + * Author : Joakim Eriksson + * Created : mar 2009 + * Updated : $Date:$ + * $Revision:$ + */ + +package se.sics.mspsim.net; + +import se.sics.mspsim.util.Utils; + +public class HC01PacketHandler extends AbstractPacketHandler { + public final static int IPHC_TTL_1 = 0x08; + public final static int IPHC_TTL_64 = 0x10; + public final static int IPHC_TTL_255 = 0x18; + public final static int IPHC_TTL_I = 0x00; + + /* Values of fields within the IPHC encoding second byte */ + public final static int IPHC_SAM_I = 0x00; + public final static int IPHC_SAM_64 = 0x40; + public final static int IPHC_SAM_16 = 0x80; + public final static int IPHC_SAM_0 = 0xC0; + public final static int IPHC_DAM_I = 0x00; + public final static int IPHC_DAM_64 = 0x04; + public final static int IPHC_DAM_16 = 0x08; + public final static int IPHC_DAM_0 = 0x0C; + + public final static int NHC_UDP_ID = 0xF8; + public final static int NHC_UDP_C = 0xFB; + public final static int NHC_UDP_I = 0xF8; + + /* Min and Max compressible UDP ports */ + public final static int UDP_PORT_MIN = 0xF0B0; + public final static int UDP_PORT_MAX = 0xF0BF; /* F0B0 + 15 */ + + public static final int HC01_DISPATCH = 0x03; + + public final static int PROTO_ICMP = 1; + public final static int PROTO_TCP = 6; + public final static int PROTO_UDP = 17; + public final static int PROTO_ICMP6 = 58; + + private static class AddrContext { + int used; + int number; + long prefix; + } + + private AddrContext[] contexts = new AddrContext[4]; + + public HC01PacketHandler() { + // set-up some fake contexts just to get started... + contexts[0] = new AddrContext(); + contexts[1] = new AddrContext(); + contexts[2] = new AddrContext(); + contexts[3] = new AddrContext(); + + for (int i = 0; i < contexts.length; i++) { + contexts[i].prefix = 0xaaaa000000000000L | ((i + 1)<< 8) | i + 1; + } + } + + public void packetReceived(Packet container) { + byte[] payload = container.getPayload(); + IPv6Packet packet = new IPv6Packet(); + container.setPayloadPacket(packet); + packet.containerPacket = container; + setPacketData(packet, payload, payload.length); + dispatch(packet.nextHeader, packet); + } + + public void sendPacket(Packet payload) { + } + + public void setPacketData(IPv6Packet packet, byte[] data, int len) { + /* first two is ... */ + int pos = 2; + if ((data[0] & 0x40) == 0) { + if ((data[0] & 0x80) == 0) { + packet.version = (data[pos] & 0xf0) >> 4; + packet.trafficClass = ((data[pos] & 0x0f)<<4) + ((data[pos + 1] & 0xff) >> 4); + packet.flowLabel = (data[pos + 1] & 0x0f) << 16 + (data[pos + 2] & 0xff) << 8 + + data[pos + 3] & 0xff; + pos += 4; + } else { + packet.version = 6; + packet.trafficClass = 0; + packet.flowLabel = (data[pos] & 0x0f) << 16 + + (data[pos + 1] & 0xff) << 8 + data[pos + 2] & 0xff;; + pos += 3; + } + } else { + packet.version = 6; + packet.flowLabel = 0; + if ((data[0] & 0x80) == 0) { + packet.trafficClass = (data[pos] & 0xff); + pos++; + } else { + packet.trafficClass = 0; + } + } + + /* next header not compressed -> get it */ + if ((data[0] & 0x20) == 0) { + packet.nextHeader = data[pos++]; + } + + /* encoding of TTL */ + switch (data[0] & 0x18) { + case IPHC_TTL_1: + packet.hopLimit = 1; + break; + case IPHC_TTL_64: + packet.hopLimit = 64; + break; + case IPHC_TTL_255: + packet.hopLimit = 0xff; + break; + case IPHC_TTL_I: + packet.hopLimit = data[pos++]; + break; + } + + /* 0, 1, 2, 3 as source address ??? */ + int srcAddress = (data[1] & 0x30) >> 4; + AddrContext context = lookupContext(srcAddress); + switch (data[1] & 0xc0) { + case IPHC_SAM_0: + if(context == null) { + System.out.println("sicslowpan uncompress_hdr: error context not found\n"); + return; + } + /* set hi address as prefix from context */ + packet.sourceAddressHi = context.prefix; + /* infer IID from L2 address */ + + /* should figure out a way to get the link layer address here!!! */ + packet.sourceAddressLo = 0; + break; + case IPHC_SAM_16: + if((data[pos] & 0x80) == 0) { + /* unicast address */ + if(context == null) { + System.out.println("sicslowpan uncompress_hdr: error context not found\n"); + return; + } + /* set hi address as prefix from context */ + packet.sourceAddressHi = context.prefix; + /* copy 6 NULL bytes then 2 last bytes of IID */ + packet.sourceAddressLo = (data[pos] & 0xff) << 8+ data[pos + 1]; + pos += 2; + } else { + /* [ignore] multicast address check the 9-bit group-id is known */ + packet.sourceAddressHi = (0xff << 56) + + ((((data[pos] & 0xff) >> 1) & 0x0F) << 48); + packet.sourceAddressLo = data[pos + 1] & 0xff; + pos += 2; + } + break; + case IPHC_SAM_64: + if(context == null) { + System.out.println("sicslowpan uncompress_hdr: error context not found\n"); + return; + } + /* copy prefix from context */ + packet.sourceAddressHi = context.prefix; + /* copy IID from packet */ + packet.sourceAddressLo = IPv6Packet.getLong(data, pos); + pos += 8; + break; + case IPHC_SAM_I: + /* copy whole address from packet */ + packet.sourceAddressHi = IPv6Packet.getLong(data, pos); + pos += 8; + packet.sourceAddressLo = IPv6Packet.getLong(data, pos); + pos += 8; + break; + } + + /* Destination address */ + context = lookupContext(data[2] & 0x03); + + switch(data[1] & 0x0C) { + case IPHC_DAM_0: + if(context == null) { + System.out.println("sicslowpan uncompress_hdr: error context not found\n"); + return; + } + /* copy prefix from context */ + packet.destAddressHi = context.prefix; + /* infer IID from L2 address */ + /* figure out a way to pick this up from link-layer !!! */ + packet.destAddressLo = 0; + break; + case IPHC_DAM_16: + if((data[pos] & 0x80) == 0) { + /* unicast address */ + if(context == null) { + System.out.println("sicslowpan uncompress_hdr: error context not found\n"); + return; + } + packet.destAddressHi = context.prefix; + /* copy 6 NULL bytes then 2 last bytes of IID */ + packet.destAddressLo = ((data[pos] & 0xff) << 8) + data[pos + 1] & 0xff; + pos += 2; + } else { + /* multicast address check the 9-bit group-id is known */ + packet.sourceAddressHi = (0xff << 56) + + ((((data[pos] & 0xff) >> 1) & 0x0F) << 48); + packet.sourceAddressLo = data[pos + 1] & 0xff; + pos += 2; + } + break; + case IPHC_DAM_64: + if(context == null) { + System.out.println("sicslowpan uncompress_hdr: error context not found\n"); + return; + } + /* copy prefix from context */ + packet.destAddressHi = context.prefix; + /* copy IID from packet */ + packet.destAddressLo = IPv6Packet.getLong(data, pos); + pos += 8; + break; + case IPHC_DAM_I: + /* copy whole address from packet */ + packet.destAddressHi = IPv6Packet.getLong(data, pos); + pos += 8; + packet.destAddressLo = IPv6Packet.getLong(data, pos); + pos += 8; + break; + } + + if ((data[0] & 0x20) != 0) { + /* The next header is compressed, NHC is following */ + if ((data[pos] & 0xfc) == NHC_UDP_ID) { + packet.nextHeader = PROTO_UDP; + int srcPort = 0; + int destPort = 0; + int checkSum = 0; + switch(data[pos] & 0xff) { + case NHC_UDP_C: + /* 1 byte for NHC, 1 byte for ports, 2 bytes chksum */ + srcPort = UDP_PORT_MIN + (data[pos + 1] >> 4); + destPort = UDP_PORT_MIN + (data[pos + 1] & 0x0F); + checkSum = (data[pos + 2] << 8) + data[pos + 3]; + pos += 4; + break; + case NHC_UDP_I: + /* 1 byte for NHC, 4 byte for ports, 2 bytes chksum */ + srcPort = ((data[pos + 1] & 0xff)<< 8) + (data[pos + 2] & 0xff); + destPort = ((data[pos + 3] & 0xff)<< 8) + (data[pos + 4] & 0xff); + checkSum = ((data[pos + 5] & 0xff)<< 8) + (data[pos + 6] & 0xff); + pos += 7; + break; + default: + System.out.println("sicslowpan uncompress_hdr: error unsupported UDP compression\n"); + return; + } + System.out.println("DestPort: " + destPort); + System.out.println("SourcePort: " + srcPort); + System.out.println("Checksum: " + srcPort); + } + } + + boolean frag = false; + /* fragment handling ... */ + if (!frag) { + /* this does not handle the UDP header compression yet... */ + int plen = len - pos; + packet.setPayload(data, pos, plen); + } else { + } + + System.out.println("Encoding 0: " + Utils.hex8(data[0]) + + " Encoding 1: " + Utils.hex8(data[1])); + + System.out.println("TTL: " + packet.hopLimit); + System.out.print("Src Addr: "); + IPv6Packet.printAddress(System.out, packet.sourceAddressHi, + packet.sourceAddressLo); + System.out.print(" Dest Addr: "); + IPv6Packet.printAddress(System.out, packet.destAddressHi, + packet.destAddressLo); + System.out.println(); + + // packet.setPayload(data, 40, ???); + } + + private AddrContext lookupContext(int index) { + if (index < contexts.length) + return contexts[index]; + return null; + } +} \ No newline at end of file Modified: mspsim/se/sics/mspsim/net/ICMP6Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/ICMP6Packet.java 2009-03-22 17:57:32 UTC (rev 496) +++ mspsim/se/sics/mspsim/net/ICMP6Packet.java 2009-03-23 22:25:52 UTC (rev 497) @@ -26,18 +26,6 @@ IPv6Packet ip; - public byte[] getDataField(String name) { - return null; - } - - public int getIntField(String name) { - return 0; - } - - public int getSize() { - return 0; - } - public void printPacket(PrintStream out) { String typeS = "" + type; if (type >= 128) { @@ -46,14 +34,13 @@ typeS = TYPE_NAME[tS]; } } - - out.printf("ICMPv6 Type: %d (%s) Code: %d Chk: %04x \n", type, typeS, code, checksum); + + /* ICMP can not have payload ?! */ } public void setPacketData(Packet packet, byte[] data, int len) { - valid = false; if (packet instanceof IPv6Packet) { ip = (IPv6Packet) packet; @@ -61,7 +48,6 @@ type = data[0] & 0xff; code = data[1] & 0xff; checksum = ((data[2] & 0xff) << 8) | data[3] & 0xff; - valid = true; /* test the checksum ... */ // int sum = ip.upperLayerHeaderChecksum(); // System.out.printf("*** My Checksum: %04x", Added: mspsim/se/sics/mspsim/net/ICMP6PacketHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/ICMP6PacketHandler.java (rev 0) +++ mspsim/se/sics/mspsim/net/ICMP6PacketHandler.java 2009-03-23 22:25:52 UTC (rev 497) @@ -0,0 +1,16 @@ +package se.sics.mspsim.net; + +public class ICMP6PacketHandler extends AbstractPacketHandler { + + public void packetReceived(Packet container) { + ICMP6Packet icmpPacket = new ICMP6Packet(); + container.setPayloadPacket(icmpPacket); + icmpPacket.containerPacket = container; + icmpPacket.setPacketData(container, container.getPayload(), + container.getPayload().length); + } + + public void sendPacket(Packet payload) { + } + +} Added: mspsim/se/sics/mspsim/net/IEEE802154Handler.java =================================================================== --- mspsim/se/sics/mspsim/net/IEEE802154Handler.java (rev 0) +++ mspsim/se/sics/mspsim/net/IEEE802154Handler.java 2009-03-23 22:25:52 UTC (rev 497) @@ -0,0 +1,57 @@ +/** + * Copyright (c) 2009, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of MSPSim. + * + * $Id: $ + * + * ----------------------------------------------------------------- + * + * + * Author : Joakim Eriksson + * Created : mar 2009 + * Updated : $Date:$ + * $Revision:$ + */ + +package se.sics.mspsim.net; + +public class IEEE802154Handler extends AbstractPacketHandler { + /* create a 802.15.4 packet with the given packet as payload, and + * deliver to the lower layer handler */ + public void sendPacket(Packet payload) { + } + + /* create a 802.15.4 packet of the bytes and "dispatch" to the + * next handler + */ + public void packetReceived(Packet packet) { + IEEE802154Packet newPacket = new IEEE802154Packet(packet); + /* no dispatch at this level ?! */ + dispatch(-1, newPacket); + } +} Modified: mspsim/se/sics/mspsim/net/IEEE802154Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/IEEE802154Packet.java 2009-03-22 17:57:32 UTC (rev 496) +++ mspsim/se/sics/mspsim/net/IEEE802154Packet.java 2009-03-23 22:25:52 UTC (rev 497) @@ -62,30 +62,26 @@ private long srcAddr; private int srcPanID; - public byte[] getDataField(String name) { - return null; + public IEEE802154Packet(Packet container) { + byte[] payload = container.getPayload(); + setPacketData(container, payload, payload.length); } - - public int getIntField(String name) { - // TODO Auto-generated method stub - return 0; - } - - public int getSize() { - // TODO Auto-generated method stub - return 0; - } - + public void printPacket(PrintStream out) { out.printf("802.15.4 from %4x/", srcPanID); printAddress(out, srcAddrMode, srcAddr); out.printf(" to %4x/", destPanID); printAddress(out, destAddrMode, destAddr); out.printf(" seqNo: %d len: %d\n", seqNumber, payloadLen); + if (payloadPacket != null) { + payloadPacket.printPacket(out); + } } public void setPacketData(Packet container, byte[] data, int len) { - valid = false; + container.setPayloadPacket(this); + containerPacket = container; + type = data[0] & 7; security = (data[0] >> 3) & 1; pending = (data[0] >> 4) & 1; @@ -130,18 +126,7 @@ pos += 8; } } - - setPayload(data, pos, len - pos); - -// System.out.println("Type: " + type + " secure: " + security + -// " ack: " + ackRequired + " panComp: " + panCompression + -// " dst: " + destAddrMode + " src: " + srcAddrMode + -// " seq: " + seqNumber + " Len: " + payloadLen); -// System.out.printf(" SrcPAN: %4x SrcAdr: ", srcPanID); -// printAddress(System.out, srcAddrMode, srcAddr); -// System.out.printf(" Dst PAN: %4x DstAdr: ", destPanID); -// printAddress(System.out, destAddrMode, destAddr); -// System.out.println(""); + setPayload(data, pos, len - pos); } private void printAddress(PrintStream out, int type, long addr) { @@ -151,4 +136,4 @@ out.printf("%04x:%04x:%04x:%04x", (addr >> 48) & 0xffff, (addr >> 32) & 0xffff, (addr >> 16) & 0xffff, addr & 0xffff); } } -} +} \ No newline at end of file Modified: mspsim/se/sics/mspsim/net/IPv6Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/IPv6Packet.java 2009-03-22 17:57:32 UTC (rev 496) +++ mspsim/se/sics/mspsim/net/IPv6Packet.java 2009-03-23 22:25:52 UTC (rev 497) @@ -49,6 +49,8 @@ */ public class IPv6Packet extends AbstractPacket { + public static final int ICMP6_DISPATCH = 58; + int version; int trafficClass; int flowLabel; @@ -59,25 +61,15 @@ long destAddressHi; long destAddressLo; - public byte[] getDataField(String name) { - return null; - } - - public int getIntField(String name) { - return 0; - } - - public int getSize() { - // TODO Auto-generated method stub - return 0; - } - public void printPacket(PrintStream out) { out.printf("IPv6: from "); printAddress(out, sourceAddressHi, sourceAddressLo); out.print(" to "); printAddress(out, destAddressHi, destAddressLo); out.printf(" NxHdr: %d\n", nextHeader); + if (payloadPacket != null) { + payloadPacket.printPacket(out); + } } public static void printAddress(PrintStream out, long hi, long lo) { Added: mspsim/se/sics/mspsim/net/LoWPANHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/LoWPANHandler.java (rev 0) +++ mspsim/se/sics/mspsim/net/LoWPANHandler.java 2009-03-23 22:25:52 UTC (rev 497) @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2009, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of MSPSim. + * + * $Id: $ + * + * ----------------------------------------------------------------- + * + * + * Author : Joakim Eriksson + * Created : mar 2009 + * Updated : $Date:$ + * $Revision:$ + */ +package se.sics.mspsim.net; + +public class LoWPANHandler extends AbstractPacketHandler { + + public void packetReceived(Packet container) { + LoWPANPacket packet = new LoWPANPacket(container.getPayload()); + container.setPayloadPacket(packet); + packet.containerPacket = container; + dispatch(packet.dispatch, packet); + } + + public void sendPacket(Packet payload) { + } + +} \ No newline at end of file Added: mspsim/se/sics/mspsim/net/LoWPANPacket.java =================================================================== --- mspsim/se/sics/mspsim/net/LoWPANPacket.java (rev 0) +++ mspsim/se/sics/mspsim/net/LoWPANPacket.java 2009-03-23 22:25:52 UTC (rev 497) @@ -0,0 +1,20 @@ +package se.sics.mspsim.net; + +import java.io.PrintStream; + +public class LoWPANPacket extends AbstractPacket { + + int dispatch = 0; + + public LoWPANPacket(byte[] data) { + dispatch = data[0]; + setPayload(data, 1, data.length - 1); + } + + public void printPacket(PrintStream out) { + out.println("6LoWPAN Dispatch: " + dispatch); + if (payloadPacket != null) { + payloadPacket.printPacket(out); + } + } +} Modified: mspsim/se/sics/mspsim/net/Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/Packet.java 2009-03-22 17:57:32 UTC (rev 496) +++ mspsim/se/sics/mspsim/net/Packet.java 2009-03-23 22:25:52 UTC (rev 497) @@ -45,19 +45,12 @@ public interface Packet { - public void setPacketData(Packet packet, byte[] data, int len); - /** - * @return size of packet in bytes - */ - public int getSize(); - - /** * @return payload of the packet */ public byte[] getPayload(); - - public int getIntField(String name); - public byte[] getDataField(String name); + void setPayloadPacket(Packet packet); + void setContainerPacket(Packet packet); public void printPacket(PrintStream out); + } \ No newline at end of file Added: mspsim/se/sics/mspsim/net/PacketHandler.java =================================================================== --- mspsim/se/sics/mspsim/net/PacketHandler.java (rev 0) +++ mspsim/se/sics/mspsim/net/PacketHandler.java 2009-03-23 22:25:52 UTC (rev 497) @@ -0,0 +1,10 @@ +package se.sics.mspsim.net; + +public interface PacketHandler { + + public void addUpperLayerHandler(int protoID,PacketHandler handler); + public void setLowerLayerHandler(PacketHandler handler); + public void packetReceived(Packet container); + public void sendPacket(Packet payload); + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-03-22 17:57:52
|
Revision: 496 http://mspsim.svn.sourceforge.net/mspsim/?rev=496&view=rev Author: joxe Date: 2009-03-22 17:57:32 +0000 (Sun, 22 Mar 2009) Log Message: ----------- fixed bug in HC01 packet and added ICMPv6 parsing Modified Paths: -------------- mspsim/se/sics/mspsim/net/AbstractPacket.java mspsim/se/sics/mspsim/net/CC2420Packet.java mspsim/se/sics/mspsim/net/HC01Packet.java mspsim/se/sics/mspsim/net/IEEE802154Packet.java mspsim/se/sics/mspsim/net/IPv6Packet.java mspsim/se/sics/mspsim/net/Packet.java Added Paths: ----------- mspsim/se/sics/mspsim/net/ICMP6Packet.java Modified: mspsim/se/sics/mspsim/net/AbstractPacket.java =================================================================== --- mspsim/se/sics/mspsim/net/AbstractPacket.java 2009-03-17 15:06:53 UTC (rev 495) +++ mspsim/se/sics/mspsim/net/AbstractPacket.java 2009-03-22 17:57:32 UTC (rev 496) @@ -79,7 +79,7 @@ public void notifyPacketHandlers(byte[] payload, int len) { for (int i = 0; i < packetHandlers.size(); i++) { try { - packetHandlers.get(i).setPacketData(payload, len); + packetHandlers.get(i).setPacketData(this, payload, len); } catch (Exception e) { } } Modified: mspsim/se/sics/mspsim/net/CC2420Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/CC2420Packet.java 2009-03-17 15:06:53 UTC (rev 495) +++ mspsim/se/sics/mspsim/net/CC2420Packet.java 2009-03-22 17:57:32 UTC (rev 496) @@ -72,7 +72,7 @@ /* should this be the interface??? or only RF_LIST ???*/ /* maybe this is default and CC2420 is "special" */ - public void setPacketData(byte[] data, int plen) { + public void setPacketData(Packet container, byte[] data, int plen) { if (data.length > PREAMBLE.length) { int pos = 0; for (int i = 0; i < PREAMBLE.length; i++) { @@ -129,7 +129,7 @@ case PACKET: if (pos == packetLen + PREAMBLE.length + 1) { /* the packet is in!!! */ - setPacketData(packetBuffer, pos); + setPacketData(this, packetBuffer, pos); mode = SFD_SEARCH; } break; @@ -138,14 +138,23 @@ public void printPacket(PrintStream out) { if (valid) { - out.println("CC2420 | len:" + len + "|"); + out.print("CC2420 | len:" + len + " | "); + for (int i = 0; i < len; i++) { + out.printf("%02x", payload[i] & 0xff); + if ((i & 3) == 3) { + out.print(" "); + } + } + out.println(); } } public static void main(String[] args) { CC2420Packet p = new CC2420Packet(); - p.addInnerPacketHandler(new IEEE802154Packet()); + IEEE802154Packet p2 = new IEEE802154Packet(); + p.addInnerPacketHandler(p2); + p2.addInnerPacketHandler(new HC01Packet()); int[] data = new int[] {0,0,0,0,0x7a,48, 0x41, 0xCC, 0x74, 0xCD, 0xAB, 0x55, 0x44, 0x33, 0xFE, 0xFF, 0x22, 0x11, 0x02, 0x16, 0x15, 0x14, Modified: mspsim/se/sics/mspsim/net/HC01Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/HC01Packet.java 2009-03-17 15:06:53 UTC (rev 495) +++ mspsim/se/sics/mspsim/net/HC01Packet.java 2009-03-22 17:57:32 UTC (rev 496) @@ -2,6 +2,8 @@ import java.awt.print.Printable; +import se.sics.mspsim.util.Utils; + public class HC01Packet extends IPv6Packet { public final static int IPHC_TTL_1 = 0x08; public final static int IPHC_TTL_64 = 0x10; @@ -9,204 +11,267 @@ public final static int IPHC_TTL_I = 0x00; /* Values of fields within the IPHC encoding second byte */ - public final static int IPHC_SAM_I = 0x00; - public final static int IPHC_SAM_64 = 0x40; - public final static int IPHC_SAM_16 = 0x80; - public final static int IPHC_SAM_0 = 0xC0; - public final static int IPHC_DAM_I = 0x00; - public final static int IPHC_DAM_64 = 0x04; - public final static int IPHC_DAM_16 = 0x08; - public final static int IPHC_DAM_0 = 0x0C; + public final static int IPHC_SAM_I = 0x00; + public final static int IPHC_SAM_64 = 0x40; + public final static int IPHC_SAM_16 = 0x80; + public final static int IPHC_SAM_0 = 0xC0; + public final static int IPHC_DAM_I = 0x00; + public final static int IPHC_DAM_64 = 0x04; + public final static int IPHC_DAM_16 = 0x08; + public final static int IPHC_DAM_0 = 0x0C; + public final static int NHC_UDP_ID = 0xF8; + public final static int NHC_UDP_C = 0xFB; + public final static int NHC_UDP_I = 0xF8; - public static final int HC01_DISPATCH = 0x03; + /* Min and Max compressible UDP ports */ + public final static int UDP_PORT_MIN = 0xF0B0; + public final static int UDP_PORT_MAX = 0xF0BF; /* F0B0 + 15 */ + + public static final int HC01_DISPATCH = 0x03; + public final static int PROTO_ICMP = 1; + public final static int PROTO_TCP = 6; + public final static int PROTO_UDP = 17; + public final static int PROTO_ICMP6 = 58; + + private static class AddrContext { int used; int number; long prefix; } - private AddrContext[] contexts = new AddrContext[4]; + private AddrContext[] contexts = new AddrContext[4]; - public HC01Packet() { - // setut some fake contexts just to get started... - contexts[0] = new AddrContext(); - contexts[1] = new AddrContext(); - contexts[2] = new AddrContext(); - contexts[3] = new AddrContext(); - - for (int i = 0; i < contexts.length; i++) { - contexts[i].prefix = 0xaaaa000000000000L | ((i + 1)<< 8) | i + 1; - } - } - - public void setPacketData(byte[] data, int len) { - int pos = 3; - if (data[0] != HC01_DISPATCH) return; - if ((data[1] & 0x40) == 0) { - if ((data[1] & 0x80) == 0) { - version = (data[pos] & 0xf0) >> 4; - trafficClass = ((data[pos] & 0x0f)<<4) + ((data[pos + 1] & 0xff) >> 4); - flowLabel = (data[pos + 1] & 0x0f) << 16 + (data[pos + 2] & 0xff) << 8 + - data[pos + 3] & 0xff; - pos += 4; - } else { - version = 6; - trafficClass = 0; - flowLabel = (data[pos] & 0x0f) << 16 - + (data[pos + 1] & 0xff) << 8 + data[pos + 2] & 0xff;; - pos += 3; - } - } else { - version = 6; - flowLabel = 0; - if ((data[1] & 0x80) == 0) { - trafficClass = (data[pos] & 0xff); - pos++; - } else { - trafficClass = 0; - } - } - /* encoding of TTL */ - switch (data[1] & 0x18) { - case IPHC_TTL_1: - hopLimit = 1; - break; - case IPHC_TTL_64: - hopLimit = 64; - break; - case IPHC_TTL_255: - hopLimit = 0xff; - break; - case IPHC_TTL_I: - hopLimit = data[pos++]; - break; - } + public HC01Packet() { + // setut some fake contexts just to get started... + contexts[0] = new AddrContext(); + contexts[1] = new AddrContext(); + contexts[2] = new AddrContext(); + contexts[3] = new AddrContext(); - /* 0, 1, 2, 3 as source address ??? */ - int srcAddress = (data[2] & 0x30) >> 4; - AddrContext context = lookupContext(srcAddress); - switch (data[2] & 0xc0) { - case IPHC_SAM_0: - if(context == null) { - System.out.println("sicslowpan uncompress_hdr: error context not found\n"); - return; - } - /* set hi address as prefix from context */ - sourceAddressHi = context.prefix; - /* infer IID from L2 address */ + for (int i = 0; i < contexts.length; i++) { + contexts[i].prefix = 0xaaaa000000000000L | ((i + 1)<< 8) | i + 1; + } + } - /* should figure out a way to get the link layer address here!!! */ - sourceAddressLo = 0; - break; - case IPHC_SAM_16: - if((data[pos] & 0x80) == 0) { - /* unicast address */ - if(context == null) { - System.out.println("sicslowpan uncompress_hdr: error context not found\n"); - return; - } - /* set hi address as prefix from context */ - sourceAddressHi = context.prefix; - /* copy 6 NULL bytes then 2 last bytes of IID */ - sourceAddressLo = (data[pos] & 0xff) << 8+ data[pos + 1]; - pos += 2; - } else { - /* [ignore] multicast address check the 9-bit group-id is known */ - sourceAddressHi = (0xff << 56) + - ((((data[pos] & 0xff) >> 1) & 0x0F) << 48); - sourceAddressLo = data[pos + 1] & 0xff; - pos += 2; - } - break; - case IPHC_SAM_64: - if(context == null) { - System.out.println("sicslowpan uncompress_hdr: error context not found\n"); - return; - } - /* copy prefix from context */ - sourceAddressHi = context.prefix; - /* copy IID from packet */ - sourceAddressLo = getLong(data, pos); - pos += 8; - break; - case IPHC_SAM_I: - /* copy whole address from packet */ - sourceAddressHi = getLong(data, pos); - pos += 8; - sourceAddressLo = getLong(data, pos); - pos += 8; - break; - } + public void setPacketData(Packet packet, byte[] data, int len) { + int pos = 3; + if (data[0] != HC01_DISPATCH) return; + if ((data[1] & 0x40) == 0) { + if ((data[1] & 0x80) == 0) { + version = (data[pos] & 0xf0) >> 4; + trafficClass = ((data[pos] & 0x0f)<<4) + ((data[pos + 1] & 0xff) >> 4); + flowLabel = (data[pos + 1] & 0x0f) << 16 + (data[pos + 2] & 0xff) << 8 + + data[pos + 3] & 0xff; + pos += 4; + } else { + version = 6; + trafficClass = 0; + flowLabel = (data[pos] & 0x0f) << 16 + + (data[pos + 1] & 0xff) << 8 + data[pos + 2] & 0xff;; + pos += 3; + } + } else { + version = 6; + flowLabel = 0; + if ((data[1] & 0x80) == 0) { + trafficClass = (data[pos] & 0xff); + pos++; + } else { + trafficClass = 0; + } + } + + /* next header not compressed -> get it */ + if ((data[1] & 0x20) == 0) { + nextHeader = data[pos++]; + } + + /* encoding of TTL */ + switch (data[1] & 0x18) { + case IPHC_TTL_1: + hopLimit = 1; + break; + case IPHC_TTL_64: + hopLimit = 64; + break; + case IPHC_TTL_255: + hopLimit = 0xff; + break; + case IPHC_TTL_I: + hopLimit = data[pos++]; + break; + } - /* Destination address */ - context = lookupContext(data[2] & 0x03); + /* 0, 1, 2, 3 as source address ??? */ + int srcAddress = (data[2] & 0x30) >> 4; + AddrContext context = lookupContext(srcAddress); + switch (data[2] & 0xc0) { + case IPHC_SAM_0: + if(context == null) { + System.out.println("sicslowpan uncompress_hdr: error context not found\n"); + return; + } + /* set hi address as prefix from context */ + sourceAddressHi = context.prefix; + /* infer IID from L2 address */ - switch(data[2] & 0x0C) { - case IPHC_DAM_0: - if(context == null) { - System.out.println("sicslowpan uncompress_hdr: error context not found\n"); - return; - } - /* copy prefix from context */ - destAddressHi = context.prefix; - /* infer IID from L2 address */ - /* figure out a way to pick this up from link-layer !!! */ - destAddressLo = 0; - break; - case IPHC_DAM_16: - if((data[pos] & 0x80) == 0) { - /* unicast address */ - if(context == null) { - System.out.println("sicslowpan uncompress_hdr: error context not found\n"); - return; - } - destAddressHi = context.prefix; - /* copy 6 NULL bytes then 2 last bytes of IID */ - destAddressLo = ((data[pos] & 0xff) << 8) + data[pos + 1] & 0xff; - pos += 2; - } else { - /* multicast address check the 9-bit group-id is known */ - sourceAddressHi = (0xff << 56) + - ((((data[pos] & 0xff) >> 1) & 0x0F) << 48); - sourceAddressLo = data[pos + 1] & 0xff; - pos += 2; - } - break; - case IPHC_DAM_64: - if(context == null) { - System.out.println("sicslowpan uncompress_hdr: error context not found\n"); - return; - } - /* copy prefix from context */ - destAddressHi = context.prefix; - /* copy IID from packet */ - destAddressLo = getLong(data, pos); - pos += 8; - break; - case IPHC_DAM_I: - /* copy whole address from packet */ - destAddressHi = getLong(data, pos); - pos += 8; - destAddressLo = getLong(data, pos); - pos += 8; - break; - } - - - System.out.println("TTL: " + hopLimit); - System.out.print("Src Addr: "); - printAddress(System.out, sourceAddressHi, sourceAddressLo); - System.out.print(" Dest Addr: "); - printAddress(System.out, destAddressHi, destAddressLo); - System.out.println(); - } - + /* should figure out a way to get the link layer address here!!! */ + sourceAddressLo = 0; + break; + case IPHC_SAM_16: + if((data[pos] & 0x80) == 0) { + /* unicast address */ + if(context == null) { + System.out.println("sicslowpan uncompress_hdr: error context not found\n"); + return; + } + /* set hi address as prefix from context */ + sourceAddressHi = context.prefix; + /* copy 6 NULL bytes then 2 last bytes of IID */ + sourceAddressLo = (data[pos] & 0xff) << 8+ data[pos + 1]; + pos += 2; + } else { + /* [ignore] multicast address check the 9-bit group-id is known */ + sourceAddressHi = (0xff << 56) + + ((((data[pos] & 0xff) >> 1) & 0x0F) << 48); + sourceAddressLo = data[pos + 1] & 0xff; + pos += 2; + } + break; + case IPHC_SAM_64: + if(context == null) { + System.out.println("sicslowpan uncompress_hdr: error context not found\n"); + return; + } + /* copy prefix from context */ + sourceAddressHi = context.prefix; + /* copy IID from packet */ + sourceAddressLo = getLong(data, pos); + pos += 8; + break; + case IPHC_SAM_I: + /* copy whole address from packet */ + sourceAddressHi = getLong(data, pos); + pos += 8; + sourceAddressLo = getLong(data, pos); + pos += 8; + break; + } + + /* Destination address */ + context = lookupContext(data[2] & 0x03); + + switch(data[2] & 0x0C) { + case IPHC_DAM_0: + if(context == null) { + System.out.println("sicslowpan uncompress_hdr: error context not found\n"); + return; + } + /* copy prefix from context */ + destAddressHi = context.prefix; + /* infer IID from L2 address */ + /* figure out a way to pick this up from link-layer !!! */ + destAddressLo = 0; + break; + case IPHC_DAM_16: + if((data[pos] & 0x80) == 0) { + /* unicast address */ + if(context == null) { + System.out.println("sicslowpan uncompress_hdr: error context not found\n"); + return; + } + destAddressHi = context.prefix; + /* copy 6 NULL bytes then 2 last bytes of IID */ + destAddressLo = ((data[pos] & 0xff) << 8) + data[pos + 1] & 0xff; + pos += 2; + } else { + /* multicast address check the 9-bit group-id is known */ + sourceAddressHi = (0xff << 56) + + ((((data[pos] & 0xff) >> 1) & 0x0F) << 48); + sourceAddressLo = data[pos + 1] & 0xff; + pos += 2; + } + break; + case IPHC_DAM_64: + if(context == null) { + System.out.println("sicslowpan uncompress_hdr: error context not found\n"); + return; + } + /* copy prefix from context */ + destAddressHi = context.prefix; + /* copy IID from packet */ + destAddressLo = getLong(data, pos); + pos += 8; + break; + case IPHC_DAM_I: + /* copy whole address from packet */ + destAddressHi = getLong(data, pos); + pos += 8; + destAddressLo = getLong(data, pos); + pos += 8; + break; + } + + if ((data[1] & 0x20) != 0) { + /* The next header is compressed, NHC is following */ + if ((data[pos] & 0xfc) == NHC_UDP_ID) { + nextHeader = PROTO_UDP; + int srcPort = 0; + int destPort = 0; + int checkSum = 0; + switch(data[pos] & 0xff) { + case NHC_UDP_C: + /* 1 byte for NHC, 1 byte for ports, 2 bytes chksum */ + srcPort = UDP_PORT_MIN + (data[pos + 1] >> 4); + destPort = UDP_PORT_MIN + (data[pos + 1] & 0x0F); + checkSum = (data[pos + 2] << 8) + data[pos + 3]; + pos += 4; + break; + case NHC_UDP_I: + /* 1 byte for NHC, 4 byte for ports, 2 bytes chksum */ + srcPort = ((data[pos + 1] & 0xff)<< 8) + (data[pos + 2] & 0xff); + destPort = ((data[pos + 3] & 0xff)<< 8) + (data[pos + 4] & 0xff); + checkSum = ((data[pos + 5] & 0xff)<< 8) + (data[pos + 6] & 0xff); + pos += 7; + break; + default: + System.out.println("sicslowpan uncompress_hdr: error unsupported UDP compression\n"); + return; + } + System.out.println("DestPort: " + destPort); + System.out.println("SourcePort: " + srcPort); + System.out.println("Checksum: " + srcPort); + } + } + + boolean frag = false; + /* fragment handling ... */ + if (!frag) { + /* this does not handle the UDP header compression yet... */ + int plen = len - pos; + setPayload(data, pos, plen); + } else { + } + + System.out.println("Data[1]: " + Utils.hex8(data[1]) + + " Data[2]: " + Utils.hex8(data[2])); + + System.out.println("TTL: " + hopLimit); + System.out.print("Src Addr: "); + printAddress(System.out, sourceAddressHi, sourceAddressLo); + System.out.print(" Dest Addr: "); + printAddress(System.out, destAddressHi, destAddressLo); + System.out.println(); + + setPayload(data, 40, payloadLen); + } + private AddrContext lookupContext(int index) { if (index < contexts.length) return contexts[index]; return null; } - -} +} \ No newline at end of file Added: mspsim/se/sics/mspsim/net/ICMP6Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/ICMP6Packet.java (rev 0) +++ mspsim/se/sics/mspsim/net/ICMP6Packet.java 2009-03-22 17:57:32 UTC (rev 496) @@ -0,0 +1,73 @@ +package se.sics.mspsim.net; + +import java.io.PrintStream; + +public class ICMP6Packet extends AbstractPacket { + + public static final int ECHO_REQUEST = 128; + public static final int ECHO_REPLY = 129; + public static final int GROUP_QUERY = 130; + public static final int GROUP_REPORT = 131; + public static final int GROUP_REDUCTION = 132; + public static final int ROUTER_SOLICITATION = 133; + public static final int ROUTER_ADVERTISEMENT = 134; + public static final int NEIGHBOR_SOLICITATION = 135; + public static final int NEIGHBOR_ADVERTISEMENT = 136; + + public static final String[] TYPE_NAME = new String[] { + "ECHO_REQUEST", "ECHO_REPLY", + "GROUP_QUERY", "GROUP_REPORT", "GROUP_REDUCTION", + "ROUTER_SOLICITATION", "ROUTER_ADVERTISEMENT", + "NEIGHBOR_SOLICITATION", "NEIGHBOR_ADVERTISEMENT"}; + + int type; + int code; + int checksum; + + IPv6Packet ip; + + public byte[] getDataField(String name) { + return null; + } + + public int getIntField(String name) { + return 0; + } + + public int getSize() { + return 0; + } + + public void printPacket(PrintStream out) { + String typeS = "" + type; + if (type >= 128) { + int tS = type - 128; + if (tS < TYPE_NAME.length) { + typeS = TYPE_NAME[tS]; + } + } + + + out.printf("ICMPv6 Type: %d (%s) Code: %d Chk: %04x \n", type, typeS, + code, checksum); + } + + public void setPacketData(Packet packet, byte[] data, int len) { + valid = false; + if (packet instanceof IPv6Packet) { + ip = (IPv6Packet) packet; + + if (ip.nextHeader == 58) + type = data[0] & 0xff; + code = data[1] & 0xff; + checksum = ((data[2] & 0xff) << 8) | data[3] & 0xff; + valid = true; + /* test the checksum ... */ +// int sum = ip.upperLayerHeaderChecksum(); +// System.out.printf("*** My Checksum: %04x", +// IPv6Packet.checkSum(sum, data, len)); + + } + } + +} Modified: mspsim/se/sics/mspsim/net/IEEE802154Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/IEEE802154Packet.java 2009-03-17 15:06:53 UTC (rev 495) +++ mspsim/se/sics/mspsim/net/IEEE802154Packet.java 2009-03-22 17:57:32 UTC (rev 496) @@ -61,9 +61,6 @@ private long destAddr; private long srcAddr; private int srcPanID; - private int payloadLen; - private boolean valid; - private byte[] payload; public byte[] getDataField(String name) { return null; @@ -87,7 +84,7 @@ out.printf(" seqNo: %d len: %d\n", seqNumber, payloadLen); } - public void setPacketData(byte[] data, int len) { + public void setPacketData(Packet container, byte[] data, int len) { valid = false; type = data[0] & 7; security = (data[0] >> 3) & 1; @@ -139,7 +136,7 @@ // System.out.println("Type: " + type + " secure: " + security + // " ack: " + ackRequired + " panComp: " + panCompression + // " dst: " + destAddrMode + " src: " + srcAddrMode + -// " seq: " + seqNumber + " payloadLen: " + payloadLen); +// " seq: " + seqNumber + " Len: " + payloadLen); // System.out.printf(" SrcPAN: %4x SrcAdr: ", srcPanID); // printAddress(System.out, srcAddrMode, srcAddr); // System.out.printf(" Dst PAN: %4x DstAdr: ", destPanID); Modified: mspsim/se/sics/mspsim/net/IPv6Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/IPv6Packet.java 2009-03-17 15:06:53 UTC (rev 495) +++ mspsim/se/sics/mspsim/net/IPv6Packet.java 2009-03-22 17:57:32 UTC (rev 496) @@ -77,7 +77,7 @@ printAddress(out, sourceAddressHi, sourceAddressLo); out.print(" to "); printAddress(out, destAddressHi, destAddressLo); - out.printf(" NxHdr: %d", nextHeader); + out.printf(" NxHdr: %d\n", nextHeader); } public static void printAddress(PrintStream out, long hi, long lo) { @@ -88,7 +88,7 @@ } - public void setPacketData(byte[] data, int len) { + public void setPacketData(Packet container, byte[] data, int len) { version = (data[0] & 0xff) >> 4; if (version != 6) { return; @@ -113,5 +113,50 @@ ((data[pos + 6] & 0xffL) << 48) + ((data[pos + 7] & 0xffL) << 56); return lval; } + + /* not yet working checksum code... */ + public int upperLayerHeaderChecksum() { + /* First sum pseudoheader. */ + /* IP protocol and length fields. This addition cannot carry. */ + int sum = payloadLen + nextHeader; + /* Sum IP source and destination addresses. */ + sum = checkSum(sum, sourceAddressHi); + sum = checkSum(sum, sourceAddressLo); + sum = checkSum(sum, destAddressHi); + sum = checkSum(sum, destAddressLo); + + /* Sum upper layer header and data is done separately.... */ + /* -- needs to get hold of uncompressed payload for that ... */ + + return sum; + } + public static int checkSum(int sum, long data) { + int roll = 48; + for (int i = 0; i < 4; i++) { + int dsum = (int) ((data >> roll) & 0xffff); + System.out.print("Summing: " + sum + " + " + dsum + " = "); + sum = (sum + dsum) & 0xffff; + if (sum < dsum) sum++; + System.out.println(sum); + roll = roll - 16; + } + return sum; + } + + public static int checkSum(int sum, byte[] data, int size) { + for (int i = 0; i < size; i+= 2) { + int dsum = ((data[i] & 0xff) << 8) | (data[i + 1] & 0xff); + sum = (sum + dsum) & 0xffff; + if (sum < dsum) sum++; + } + /* final byte - if any*/ + if ((size & 1) > 0) { + int dsum = ((data[size - 1] & 0xff) << 8); + sum = (sum + dsum) & 0xffff; + if (sum < dsum) sum++; + } + return sum; + } + } Modified: mspsim/se/sics/mspsim/net/Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/Packet.java 2009-03-17 15:06:53 UTC (rev 495) +++ mspsim/se/sics/mspsim/net/Packet.java 2009-03-22 17:57:32 UTC (rev 496) @@ -45,7 +45,7 @@ public interface Packet { - public void setPacketData(byte[] data, int len); + public void setPacketData(Packet packet, byte[] data, int len); /** * @return size of packet in bytes This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-03-17 15:07:09
|
Revision: 495 http://mspsim.svn.sourceforge.net/mspsim/?rev=495&view=rev Author: joxe Date: 2009-03-17 15:06:53 +0000 (Tue, 17 Mar 2009) Log Message: ----------- minor fixes Modified Paths: -------------- mspsim/se/sics/mspsim/net/HC01Packet.java mspsim/se/sics/mspsim/net/IPv6Packet.java Modified: mspsim/se/sics/mspsim/net/HC01Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/HC01Packet.java 2009-03-17 15:03:54 UTC (rev 494) +++ mspsim/se/sics/mspsim/net/HC01Packet.java 2009-03-17 15:06:53 UTC (rev 495) @@ -77,7 +77,7 @@ hopLimit = 64; break; case IPHC_TTL_255: - hopLimit = (byte) 0xff; + hopLimit = 0xff; break; case IPHC_TTL_I: hopLimit = data[pos++]; @@ -198,8 +198,8 @@ System.out.println("TTL: " + hopLimit); System.out.print("Src Addr: "); printAddress(System.out, sourceAddressHi, sourceAddressLo); - System.out.print("Dest Addr: "); - printAddress(System.out, sourceAddressHi, sourceAddressLo); + System.out.print(" Dest Addr: "); + printAddress(System.out, destAddressHi, destAddressLo); System.out.println(); } Modified: mspsim/se/sics/mspsim/net/IPv6Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/IPv6Packet.java 2009-03-17 15:03:54 UTC (rev 494) +++ mspsim/se/sics/mspsim/net/IPv6Packet.java 2009-03-17 15:06:53 UTC (rev 495) @@ -52,8 +52,8 @@ int version; int trafficClass; int flowLabel; - byte nextHeader; - byte hopLimit; + int nextHeader; + int hopLimit; long sourceAddressHi; long sourceAddressLo; long destAddressHi; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-03-17 15:04:11
|
Revision: 494 http://mspsim.svn.sourceforge.net/mspsim/?rev=494&view=rev Author: joxe Date: 2009-03-17 15:03:54 +0000 (Tue, 17 Mar 2009) Log Message: ----------- some more hc01 functionality Modified Paths: -------------- mspsim/se/sics/mspsim/cli/MiscCommands.java mspsim/se/sics/mspsim/net/HC01Packet.java mspsim/se/sics/mspsim/net/IPv6Packet.java Modified: mspsim/se/sics/mspsim/cli/MiscCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/MiscCommands.java 2009-03-17 14:02:13 UTC (rev 493) +++ mspsim/se/sics/mspsim/cli/MiscCommands.java 2009-03-17 15:03:54 UTC (rev 494) @@ -371,8 +371,6 @@ } } }); - - } } Modified: mspsim/se/sics/mspsim/net/HC01Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/HC01Packet.java 2009-03-17 14:02:13 UTC (rev 493) +++ mspsim/se/sics/mspsim/net/HC01Packet.java 2009-03-17 15:03:54 UTC (rev 494) @@ -1,58 +1,212 @@ package se.sics.mspsim.net; +import java.awt.print.Printable; + public class HC01Packet extends IPv6Packet { -public final static int IPHC_TTL_1 = 0x08; -public final static int IPHC_TTL_64 = 0x10; -public final static int IPHC_TTL_255 = 0x18; -public final static int IPHC_TTL_I = 0x00; + public final static int IPHC_TTL_1 = 0x08; + public final static int IPHC_TTL_64 = 0x10; + public final static int IPHC_TTL_255 = 0x18; + public final static int IPHC_TTL_I = 0x00; - public static final int HC01_DISPATCH = 0x03; + /* Values of fields within the IPHC encoding second byte */ + public final static int IPHC_SAM_I = 0x00; + public final static int IPHC_SAM_64 = 0x40; + public final static int IPHC_SAM_16 = 0x80; + public final static int IPHC_SAM_0 = 0xC0; + public final static int IPHC_DAM_I = 0x00; + public final static int IPHC_DAM_64 = 0x04; + public final static int IPHC_DAM_16 = 0x08; + public final static int IPHC_DAM_0 = 0x0C; + + + public static final int HC01_DISPATCH = 0x03; + + private static class AddrContext { + int used; + int number; + long prefix; + } + + private AddrContext[] contexts = new AddrContext[4]; + + public HC01Packet() { + // setut some fake contexts just to get started... + contexts[0] = new AddrContext(); + contexts[1] = new AddrContext(); + contexts[2] = new AddrContext(); + contexts[3] = new AddrContext(); - public void setPacketData(byte[] data, int len) { - int pos = 3; - if (data[0] != HC01_DISPATCH) return; - if ((data[1] & 0x40) == 0) { - if ((data[1] & 0x80) == 0) { - version = (data[pos] & 0xf0) >> 4; - trafficClass = ((data[pos] & 0x0f)<<4) + ((data[pos + 1] & 0xff) >> 4); - flowLabel = (data[pos + 1] & 0x0f) << 16 + (data[pos + 2] & 0xff) << 8 + - data[pos + 3] & 0xff; - pos += 4; - } else { - version = 6; - trafficClass = 0; - flowLabel = (data[pos] & 0x0f) << 16 - + (data[pos + 1] & 0xff) << 8 + data[pos + 2] & 0xff;; - pos += 3; - } - } else { - version = 6; - flowLabel = 0; - if ((data[1] & 0x80) == 0) { - trafficClass = (data[pos] & 0xff); - pos++; - } else { - trafficClass = 0; - } - } - /* encoding of TTL */ - switch (data[1] & 0x18) { - case IPHC_TTL_1: - hopLimit = 1; - break; - case IPHC_TTL_64: - hopLimit = 64; - break; - case IPHC_TTL_255: - hopLimit = (byte) 0xff; - break; - case IPHC_TTL_I: - hopLimit = data[pos++]; - break; - } - - - + for (int i = 0; i < contexts.length; i++) { + contexts[i].prefix = 0xaaaa000000000000L | ((i + 1)<< 8) | i + 1; + } + } + + public void setPacketData(byte[] data, int len) { + int pos = 3; + if (data[0] != HC01_DISPATCH) return; + if ((data[1] & 0x40) == 0) { + if ((data[1] & 0x80) == 0) { + version = (data[pos] & 0xf0) >> 4; + trafficClass = ((data[pos] & 0x0f)<<4) + ((data[pos + 1] & 0xff) >> 4); + flowLabel = (data[pos + 1] & 0x0f) << 16 + (data[pos + 2] & 0xff) << 8 + + data[pos + 3] & 0xff; + pos += 4; + } else { + version = 6; + trafficClass = 0; + flowLabel = (data[pos] & 0x0f) << 16 + + (data[pos + 1] & 0xff) << 8 + data[pos + 2] & 0xff;; + pos += 3; + } + } else { + version = 6; + flowLabel = 0; + if ((data[1] & 0x80) == 0) { + trafficClass = (data[pos] & 0xff); + pos++; + } else { + trafficClass = 0; + } + } + /* encoding of TTL */ + switch (data[1] & 0x18) { + case IPHC_TTL_1: + hopLimit = 1; + break; + case IPHC_TTL_64: + hopLimit = 64; + break; + case IPHC_TTL_255: + hopLimit = (byte) 0xff; + break; + case IPHC_TTL_I: + hopLimit = data[pos++]; + break; + } + + /* 0, 1, 2, 3 as source address ??? */ + int srcAddress = (data[2] & 0x30) >> 4; + AddrContext context = lookupContext(srcAddress); + switch (data[2] & 0xc0) { + case IPHC_SAM_0: + if(context == null) { + System.out.println("sicslowpan uncompress_hdr: error context not found\n"); + return; + } + /* set hi address as prefix from context */ + sourceAddressHi = context.prefix; + /* infer IID from L2 address */ + + /* should figure out a way to get the link layer address here!!! */ + sourceAddressLo = 0; + break; + case IPHC_SAM_16: + if((data[pos] & 0x80) == 0) { + /* unicast address */ + if(context == null) { + System.out.println("sicslowpan uncompress_hdr: error context not found\n"); + return; + } + /* set hi address as prefix from context */ + sourceAddressHi = context.prefix; + /* copy 6 NULL bytes then 2 last bytes of IID */ + sourceAddressLo = (data[pos] & 0xff) << 8+ data[pos + 1]; + pos += 2; + } else { + /* [ignore] multicast address check the 9-bit group-id is known */ + sourceAddressHi = (0xff << 56) + + ((((data[pos] & 0xff) >> 1) & 0x0F) << 48); + sourceAddressLo = data[pos + 1] & 0xff; + pos += 2; + } + break; + case IPHC_SAM_64: + if(context == null) { + System.out.println("sicslowpan uncompress_hdr: error context not found\n"); + return; + } + /* copy prefix from context */ + sourceAddressHi = context.prefix; + /* copy IID from packet */ + sourceAddressLo = getLong(data, pos); + pos += 8; + break; + case IPHC_SAM_I: + /* copy whole address from packet */ + sourceAddressHi = getLong(data, pos); + pos += 8; + sourceAddressLo = getLong(data, pos); + pos += 8; + break; + } + + /* Destination address */ + context = lookupContext(data[2] & 0x03); + + switch(data[2] & 0x0C) { + case IPHC_DAM_0: + if(context == null) { + System.out.println("sicslowpan uncompress_hdr: error context not found\n"); + return; + } + /* copy prefix from context */ + destAddressHi = context.prefix; + /* infer IID from L2 address */ + /* figure out a way to pick this up from link-layer !!! */ + destAddressLo = 0; + break; + case IPHC_DAM_16: + if((data[pos] & 0x80) == 0) { + /* unicast address */ + if(context == null) { + System.out.println("sicslowpan uncompress_hdr: error context not found\n"); + return; + } + destAddressHi = context.prefix; + /* copy 6 NULL bytes then 2 last bytes of IID */ + destAddressLo = ((data[pos] & 0xff) << 8) + data[pos + 1] & 0xff; + pos += 2; + } else { + /* multicast address check the 9-bit group-id is known */ + sourceAddressHi = (0xff << 56) + + ((((data[pos] & 0xff) >> 1) & 0x0F) << 48); + sourceAddressLo = data[pos + 1] & 0xff; + pos += 2; + } + break; + case IPHC_DAM_64: + if(context == null) { + System.out.println("sicslowpan uncompress_hdr: error context not found\n"); + return; + } + /* copy prefix from context */ + destAddressHi = context.prefix; + /* copy IID from packet */ + destAddressLo = getLong(data, pos); + pos += 8; + break; + case IPHC_DAM_I: + /* copy whole address from packet */ + destAddressHi = getLong(data, pos); + pos += 8; + destAddressLo = getLong(data, pos); + pos += 8; + break; + } + + + System.out.println("TTL: " + hopLimit); + System.out.print("Src Addr: "); + printAddress(System.out, sourceAddressHi, sourceAddressLo); + System.out.print("Dest Addr: "); + printAddress(System.out, sourceAddressHi, sourceAddressLo); + System.out.println(); + } + + private AddrContext lookupContext(int index) { + if (index < contexts.length) + return contexts[index]; + return null; } - + } Modified: mspsim/se/sics/mspsim/net/IPv6Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/IPv6Packet.java 2009-03-17 14:02:13 UTC (rev 493) +++ mspsim/se/sics/mspsim/net/IPv6Packet.java 2009-03-17 15:03:54 UTC (rev 494) @@ -80,7 +80,7 @@ out.printf(" NxHdr: %d", nextHeader); } - private void printAddress(PrintStream out, long hi, long lo) { + public static void printAddress(PrintStream out, long hi, long lo) { out.printf("%04x:%04x:%04x:%04x:", (hi >> 48) & 0xffff, (hi >> 32) & 0xffff, (hi >> 16) & 0xffff, hi & 0xffff); out.printf("%04x:%04x:%04x:%04x", (lo >> 48) & 0xffff, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ni...@us...> - 2009-03-17 14:02:21
|
Revision: 493 http://mspsim.svn.sourceforge.net/mspsim/?rev=493&view=rev Author: nifi Date: 2009-03-17 14:02:13 +0000 (Tue, 17 Mar 2009) Log Message: ----------- fixed call stack to grow on demand Modified Paths: -------------- mspsim/se/sics/mspsim/util/SimpleProfiler.java Modified: mspsim/se/sics/mspsim/util/SimpleProfiler.java =================================================================== --- mspsim/se/sics/mspsim/util/SimpleProfiler.java 2009-03-17 13:56:24 UTC (rev 492) +++ mspsim/se/sics/mspsim/util/SimpleProfiler.java 2009-03-17 14:02:13 UTC (rev 493) @@ -78,7 +78,7 @@ startTags = new HashMap<String, TagEntry>(); endTags = new HashMap<String, TagEntry>(); ignoreFunctions = new HashMap<String, String>(); - callStack = new CallEntry[2048]; + callStack = new CallEntry[64]; servicedInterrupt = -1; } @@ -95,6 +95,11 @@ } public void profileCall(MapEntry entry, long cycles) { + if (cSP == callStack.length) { + CallEntry[] tmp = new CallEntry[cSP + 64]; + System.arraycopy(callStack, 0, tmp, 0, cSP); + callStack = tmp; + } if (callStack[cSP] == null) { callStack[cSP] = new CallEntry(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-03-17 13:57:28
|
Revision: 492 http://mspsim.svn.sourceforge.net/mspsim/?rev=492&view=rev Author: joxe Date: 2009-03-17 13:56:24 +0000 (Tue, 17 Mar 2009) Log Message: ----------- added HC01 IPv6 Packets Added Paths: ----------- mspsim/se/sics/mspsim/net/HC01Packet.java mspsim/se/sics/mspsim/net/IPv6Packet.java Added: mspsim/se/sics/mspsim/net/HC01Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/HC01Packet.java (rev 0) +++ mspsim/se/sics/mspsim/net/HC01Packet.java 2009-03-17 13:56:24 UTC (rev 492) @@ -0,0 +1,58 @@ +package se.sics.mspsim.net; + +public class HC01Packet extends IPv6Packet { +public final static int IPHC_TTL_1 = 0x08; +public final static int IPHC_TTL_64 = 0x10; +public final static int IPHC_TTL_255 = 0x18; +public final static int IPHC_TTL_I = 0x00; + + public static final int HC01_DISPATCH = 0x03; + + public void setPacketData(byte[] data, int len) { + int pos = 3; + if (data[0] != HC01_DISPATCH) return; + if ((data[1] & 0x40) == 0) { + if ((data[1] & 0x80) == 0) { + version = (data[pos] & 0xf0) >> 4; + trafficClass = ((data[pos] & 0x0f)<<4) + ((data[pos + 1] & 0xff) >> 4); + flowLabel = (data[pos + 1] & 0x0f) << 16 + (data[pos + 2] & 0xff) << 8 + + data[pos + 3] & 0xff; + pos += 4; + } else { + version = 6; + trafficClass = 0; + flowLabel = (data[pos] & 0x0f) << 16 + + (data[pos + 1] & 0xff) << 8 + data[pos + 2] & 0xff;; + pos += 3; + } + } else { + version = 6; + flowLabel = 0; + if ((data[1] & 0x80) == 0) { + trafficClass = (data[pos] & 0xff); + pos++; + } else { + trafficClass = 0; + } + } + /* encoding of TTL */ + switch (data[1] & 0x18) { + case IPHC_TTL_1: + hopLimit = 1; + break; + case IPHC_TTL_64: + hopLimit = 64; + break; + case IPHC_TTL_255: + hopLimit = (byte) 0xff; + break; + case IPHC_TTL_I: + hopLimit = data[pos++]; + break; + } + + + + } + +} Added: mspsim/se/sics/mspsim/net/IPv6Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/IPv6Packet.java (rev 0) +++ mspsim/se/sics/mspsim/net/IPv6Packet.java 2009-03-17 13:56:24 UTC (rev 492) @@ -0,0 +1,117 @@ +/** + * Copyright (c) 2009, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of MSPSim. + * + * $Id: $ + * + * ----------------------------------------------------------------- + * + * IPv6Packet + * + * Author : Joakim Eriksson + * Created : mar 2009 + * Updated : $Date:$ + * $Revision:$ + */ + +package se.sics.mspsim.net; + +import java.io.PrintStream; + +/** + * @author joakim + * + */ +public class IPv6Packet extends AbstractPacket { + + int version; + int trafficClass; + int flowLabel; + byte nextHeader; + byte hopLimit; + long sourceAddressHi; + long sourceAddressLo; + long destAddressHi; + long destAddressLo; + + public byte[] getDataField(String name) { + return null; + } + + public int getIntField(String name) { + return 0; + } + + public int getSize() { + // TODO Auto-generated method stub + return 0; + } + + public void printPacket(PrintStream out) { + out.printf("IPv6: from "); + printAddress(out, sourceAddressHi, sourceAddressLo); + out.print(" to "); + printAddress(out, destAddressHi, destAddressLo); + out.printf(" NxHdr: %d", nextHeader); + } + + private void printAddress(PrintStream out, long hi, long lo) { + out.printf("%04x:%04x:%04x:%04x:", (hi >> 48) & 0xffff, + (hi >> 32) & 0xffff, (hi >> 16) & 0xffff, hi & 0xffff); + out.printf("%04x:%04x:%04x:%04x", (lo >> 48) & 0xffff, + (lo >> 32) & 0xffff, (lo >> 16) & 0xffff, lo & 0xffff); + } + + + public void setPacketData(byte[] data, int len) { + version = (data[0] & 0xff) >> 4; + if (version != 6) { + return; + } + trafficClass = ((data[0] & 0x0f)<<4) + ((data[1] & 0xff) >> 4); + flowLabel = (data[1] & 0x0f) << 16 + (data[2] & 0xff) << 8 + + data[3] & 0xff; + payloadLen = ((data[4] & 0xff) << 8) + data[5]; + nextHeader = data[6]; + hopLimit = data[7]; + sourceAddressHi = getLong(data, 8); + sourceAddressLo = getLong(data, 16); + destAddressHi = getLong(data, 24); + destAddressLo = getLong(data, 32); + setPayload(data, 40, payloadLen); + } + + public static long getLong(byte[] data, int pos) { + long lval = data[pos] + ((data[pos + 1] & 0xffL) << 8) + + ((data[pos + 2] & 0xffL) << 16) + ((data[pos + 3] & 0xffL) << 24) + + ((data[pos + 4] & 0xffL) << 32) + ((data[pos + 5] & 0xffL)<< 40) + + ((data[pos + 6] & 0xffL) << 48) + ((data[pos + 7] & 0xffL) << 56); + return lval; + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-03-17 13:55:58
|
Revision: 491 http://mspsim.svn.sourceforge.net/mspsim/?rev=491&view=rev Author: joxe Date: 2009-03-17 13:55:38 +0000 (Tue, 17 Mar 2009) Log Message: ----------- fixed profiler to be faster and cleared at reset Modified Paths: -------------- mspsim/se/sics/mspsim/cli/MiscCommands.java mspsim/se/sics/mspsim/core/MSP430.java mspsim/se/sics/mspsim/core/MSP430Core.java mspsim/se/sics/mspsim/net/AbstractPacket.java mspsim/se/sics/mspsim/net/IEEE802154Packet.java Modified: mspsim/se/sics/mspsim/cli/MiscCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/MiscCommands.java 2009-03-17 11:43:32 UTC (rev 490) +++ mspsim/se/sics/mspsim/cli/MiscCommands.java 2009-03-17 13:55:38 UTC (rev 491) @@ -55,6 +55,7 @@ import se.sics.mspsim.core.MSP430; import se.sics.mspsim.core.TimeEvent; import se.sics.mspsim.net.CC2420Packet; +import se.sics.mspsim.net.HC01Packet; import se.sics.mspsim.net.IEEE802154Packet; import se.sics.mspsim.util.ComponentRegistry; import se.sics.mspsim.util.Utils; @@ -309,13 +310,16 @@ context.executeCommand(command); } }); - handler.registerCommand("rfanalyzer", new BasicLineCommand("blaha", "blaha") { + handler.registerCommand("rfanalyzer", new BasicLineCommand("analyze radio packets", "") { CC2420Packet listener; CommandContext context; public int executeCommand(CommandContext context) { this.context = context; listener = new CC2420Packet(); - listener.addInnerPacketHandler(new IEEE802154Packet()); + IEEE802154Packet ieeePacket = new IEEE802154Packet(); + listener.addInnerPacketHandler(ieeePacket); + HC01Packet pan = new HC01Packet(); + ieeePacket.addInnerPacketHandler(pan); return 0; } public void lineRead(String line) { Modified: mspsim/se/sics/mspsim/core/MSP430.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430.java 2009-03-17 11:43:32 UTC (rev 490) +++ mspsim/se/sics/mspsim/core/MSP430.java 2009-03-17 13:55:38 UTC (rev 491) @@ -65,7 +65,6 @@ private long instCtr = 0; private DisAsm disAsm; - private MapTable map; private SimEventListener[] simEventListeners; @@ -92,7 +91,7 @@ throw new IllegalStateException("already running"); } setRunning(true); - // ??? - power-up reset should be executed?! + // ??? - power-up should be executed?! time = System.currentTimeMillis(); run(); } @@ -121,19 +120,6 @@ if (execCounter != null) { execCounter[reg[PC]]++; } - - if (profiler != null) { - if ((instruction & 0xff80) == CALL) { - /* The profiling should only be made on actual cpuCycles */ - MapEntry function = map.getEntry(reg[PC]); - if (function == null) { - function = getFunction(map, reg[PC]); - } - profiler.profileCall(function, cpuCycles); - } else if (instruction == RETURN) { - profiler.profileReturn(cpuCycles); - } - } } /* Just a test to see if it gets down to a reasonable speed */ @@ -181,19 +167,6 @@ if (execCounter != null) { execCounter[reg[PC]]++; } - - if (profiler != null) { - if ((instruction & 0xff80) == CALL) { - /* The profiling should only be made on actual cpuCycles */ - MapEntry function = map.getEntry(reg[PC]); - if (function == null) { - function = getFunction(map, reg[PC]); - } - profiler.profileCall(function, cpuCycles); - } else if (instruction == RETURN) { - profiler.profileReturn(cpuCycles); - } - } } } setRunning(false); @@ -240,31 +213,10 @@ if (execCounter != null) { execCounter[reg[PC]]++; } - - if (profiler != null) { - if ((instruction & 0xff80) == CALL) { - /* The profiling should only be made on actual cpuCycles */ - MapEntry function = map.getEntry(reg[PC]); - if (function == null) { - function = getFunction(map, reg[PC]); - } - profiler.profileCall(function, cpuCycles); - } else if (instruction == RETURN) { - profiler.profileReturn(cpuCycles); - } - } } - return cycles; } - private MapEntry getFunction(MapTable map, int address) { - MapEntry function = new MapEntry(MapEntry.TYPE.function, address, - "fkn at $" + Utils.hex16(address), null, true); - map.setEntry(function); - return function; - } - public void stop() { setRunning(false); } Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2009-03-17 11:43:32 UTC (rev 490) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2009-03-17 13:55:38 UTC (rev 491) @@ -42,6 +42,9 @@ package se.sics.mspsim.core; import java.io.PrintStream; import java.util.ArrayList; + +import se.sics.mspsim.util.MapEntry; +import se.sics.mspsim.util.MapTable; import se.sics.mspsim.util.Utils; /** @@ -49,6 +52,8 @@ */ public class MSP430Core extends Chip implements MSP430Constants { + public static final int RETURN = 0x4130; + public static final boolean DEBUG = false; public static final boolean debugInterrupts = false; @@ -74,6 +79,7 @@ public int memory[] = new int[MAX_MEM]; public long cycles = 0; public long cpuCycles = 0; + MapTable map; // Most HW needs only notify write and clocking, others need also read... // For notify write... @@ -531,7 +537,8 @@ bcs.reset(); // Needs to be last since these can add events... resetIOUnits(); - + + profiler.clearProfile(); } public void setWarningMode(EmulationLogger.WarningMode mode) { @@ -921,8 +928,8 @@ write = false; updateStatus = false; break; - case CALL: - // store current PC on stack... (current PC points to next instr.) + case CALL: + // store current PC on stack... (current PC points to next instr.) sp = readRegister(SP) - 2; writeRegister(SP, sp); @@ -933,6 +940,15 @@ /* Additional cycles: REG => 3, AM_IND_AUTO => 2, other => 1 */ cycles += (ad == AM_REG) ? 3 : (ad == AM_IND_AUTOINC) ? 2 : 1; + + /* profiler will be called during calls */ + if (profiler != null) { + MapEntry function = map.getEntry(dst); + if (function == null) { + function = getFunction(map, dst); + } + profiler.profileCall(function, cpuCycles); + } write = false; updateStatus = false; @@ -1127,6 +1143,11 @@ dst = src; write = true; updateStatus = false; + + if (instruction == RETURN && profiler != null) { + profiler.profileReturn(cpuCycles); + } + break; // FIX THIS!!! - make SUB a separate operation so that // it is clear that overflow flag is correct... @@ -1269,4 +1290,10 @@ return MODE_MAX; } + MapEntry getFunction(MapTable map, int address) { + MapEntry function = new MapEntry(MapEntry.TYPE.function, address, + "fkn at $" + Utils.hex16(address), null, true); + map.setEntry(function); + return function; + } } Modified: mspsim/se/sics/mspsim/net/AbstractPacket.java =================================================================== --- mspsim/se/sics/mspsim/net/AbstractPacket.java 2009-03-17 11:43:32 UTC (rev 490) +++ mspsim/se/sics/mspsim/net/AbstractPacket.java 2009-03-17 13:55:38 UTC (rev 491) @@ -1,3 +1,44 @@ +/** + * Copyright (c) 2009, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of MSPSim. + * + * $Id: $ + * + * ----------------------------------------------------------------- + * + * AbstractPacket + * + * Author : Joakim Eriksson + * Created : mar 2009 + * Updated : $Date:$ + * $Revision:$ + */ + package se.sics.mspsim.net; import java.io.PrintStream; @@ -5,6 +46,9 @@ public abstract class AbstractPacket implements Packet { + byte[] payload; + int payloadLen; + ArrayList<AbstractPacket> packetHandlers = new ArrayList<AbstractPacket>(); boolean valid = false; @@ -20,6 +64,18 @@ valid = false; } + public byte[] getPayload() { + return payload; + } + + void setPayload(byte[] data, int startPos, int len) { + payloadLen = len; + payload = new byte[payloadLen]; + System.arraycopy(data, startPos, payload, 0, payloadLen); + valid = true; + notifyPacketHandlers(payload, payloadLen); + } + public void notifyPacketHandlers(byte[] payload, int len) { for (int i = 0; i < packetHandlers.size(); i++) { try { Modified: mspsim/se/sics/mspsim/net/IEEE802154Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/IEEE802154Packet.java 2009-03-17 11:43:32 UTC (rev 490) +++ mspsim/se/sics/mspsim/net/IEEE802154Packet.java 2009-03-17 13:55:38 UTC (rev 491) @@ -1,3 +1,44 @@ +/** + * Copyright (c) 2009, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of MSPSim. + * + * $Id: $ + * + * ----------------------------------------------------------------- + * + * IEEE802154Packet + * + * Author : Joakim Eriksson + * Created : mar 2009 + * Updated : $Date:$ + * $Revision:$ + */ + package se.sics.mspsim.net; import java.io.PrintStream; @@ -33,11 +74,6 @@ return 0; } - public byte[] getPayload() { - // TODO Auto-generated method stub - return null; - } - public int getSize() { // TODO Auto-generated method stub return 0; @@ -97,15 +133,9 @@ pos += 8; } } - - payloadLen = len - pos; - payload = new byte[payloadLen]; - System.arraycopy(data, pos, payload, 0, payloadLen); - valid = true; + setPayload(data, pos, len - pos); - notifyPacketHandlers(payload, payloadLen); - // System.out.println("Type: " + type + " secure: " + security + // " ack: " + ackRequired + " panComp: " + panCompression + // " dst: " + destAddrMode + " src: " + srcAddrMode + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-03-17 11:44:16
|
Revision: 490 http://mspsim.svn.sourceforge.net/mspsim/?rev=490&view=rev Author: joxe Date: 2009-03-17 11:43:32 +0000 (Tue, 17 Mar 2009) Log Message: ----------- added CLI command for printing RF packets and fixed address printout of 802.15.4 packets Modified Paths: -------------- mspsim/se/sics/mspsim/cli/MiscCommands.java mspsim/se/sics/mspsim/net/AbstractPacket.java mspsim/se/sics/mspsim/net/CC2420Packet.java mspsim/se/sics/mspsim/net/IEEE802154Packet.java Modified: mspsim/se/sics/mspsim/cli/MiscCommands.java =================================================================== --- mspsim/se/sics/mspsim/cli/MiscCommands.java 2009-03-16 23:13:44 UTC (rev 489) +++ mspsim/se/sics/mspsim/cli/MiscCommands.java 2009-03-17 11:43:32 UTC (rev 490) @@ -54,6 +54,8 @@ import se.sics.mspsim.core.Chip; import se.sics.mspsim.core.MSP430; import se.sics.mspsim.core.TimeEvent; +import se.sics.mspsim.net.CC2420Packet; +import se.sics.mspsim.net.IEEE802154Packet; import se.sics.mspsim.util.ComponentRegistry; import se.sics.mspsim.util.Utils; @@ -307,9 +309,31 @@ context.executeCommand(command); } }); + handler.registerCommand("rfanalyzer", new BasicLineCommand("blaha", "blaha") { + CC2420Packet listener; + CommandContext context; + public int executeCommand(CommandContext context) { + this.context = context; + listener = new CC2420Packet(); + listener.addInnerPacketHandler(new IEEE802154Packet()); + return 0; + } + public void lineRead(String line) { + if (listener != null) { + byte[] data = Utils.hexconv(line); + for (int i = 0; i < data.length; i++) { + //context.out.println("Byte " + i + " = " + ((int) data[i] & 0xff)); + listener.receivedByte(data[i]); + if (listener.validPacket()) { + listener.printPacketStack(context.out); + listener.clear(); + } + } + } + } + }); handler.registerCommand("rflistener", new BasicLineCommand("an rflisteer", "[input|output] <rf-chip>") { - String command = null; CommandContext context; RFListener listener; final MSP430 cpu = (MSP430) registry.getComponent(MSP430.class); @@ -344,7 +368,6 @@ } }); - } Modified: mspsim/se/sics/mspsim/net/AbstractPacket.java =================================================================== --- mspsim/se/sics/mspsim/net/AbstractPacket.java 2009-03-16 23:13:44 UTC (rev 489) +++ mspsim/se/sics/mspsim/net/AbstractPacket.java 2009-03-17 11:43:32 UTC (rev 490) @@ -6,11 +6,20 @@ public abstract class AbstractPacket implements Packet { ArrayList<AbstractPacket> packetHandlers = new ArrayList<AbstractPacket>(); + boolean valid = false; public void addInnerPacketHandler(AbstractPacket packet) { packetHandlers.add(packet); } + public boolean validPacket() { + return valid; + } + + public void clear() { + valid = false; + } + public void notifyPacketHandlers(byte[] payload, int len) { for (int i = 0; i < packetHandlers.size(); i++) { try { Modified: mspsim/se/sics/mspsim/net/CC2420Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/CC2420Packet.java 2009-03-16 23:13:44 UTC (rev 489) +++ mspsim/se/sics/mspsim/net/CC2420Packet.java 2009-03-17 11:43:32 UTC (rev 490) @@ -42,11 +42,10 @@ package se.sics.mspsim.net; import java.io.PrintStream; - import se.sics.mspsim.chip.RFListener; public class CC2420Packet extends AbstractPacket implements RFListener { - + private static final int SFD_SEARCH = 1; private static final int LEN = 2; private static final int PACKET = 3; @@ -54,8 +53,7 @@ private static final byte[] PREAMBLE = {0, 0, 0, 0, 0x7a}; private int len; private byte[] payload; - private boolean valid = false; - + public byte[] getDataField(String name) { return null; } @@ -100,6 +98,12 @@ } } + public void clear() { + pos = 0; + mode = SFD_SEARCH; + valid = false; + } + byte[] packetBuffer = new byte[256]; int mode = SFD_SEARCH; int pos; Modified: mspsim/se/sics/mspsim/net/IEEE802154Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/IEEE802154Packet.java 2009-03-16 23:13:44 UTC (rev 489) +++ mspsim/se/sics/mspsim/net/IEEE802154Packet.java 2009-03-17 11:43:32 UTC (rev 490) @@ -121,8 +121,7 @@ if (type == SHORT_ADDRESS) { out.printf("%04x", addr & 0xffff); } else if (type == LONG_ADDRESS) { - out.printf("%016x", addr); + out.printf("%04x:%04x:%04x:%04x", (addr >> 48) & 0xffff, (addr >> 32) & 0xffff, (addr >> 16) & 0xffff, addr & 0xffff); } } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jo...@us...> - 2009-03-16 23:14:20
|
Revision: 489 http://mspsim.svn.sourceforge.net/mspsim/?rev=489&view=rev Author: joxe Date: 2009-03-16 23:13:44 +0000 (Mon, 16 Mar 2009) Log Message: ----------- added initial packet classes Modified Paths: -------------- mspsim/se/sics/mspsim/util/NetworkPacket.java Added Paths: ----------- mspsim/se/sics/mspsim/net/ mspsim/se/sics/mspsim/net/AbstractPacket.java mspsim/se/sics/mspsim/net/CC2420Packet.java mspsim/se/sics/mspsim/net/IEEE802154Packet.java mspsim/se/sics/mspsim/net/Packet.java Added: mspsim/se/sics/mspsim/net/AbstractPacket.java =================================================================== --- mspsim/se/sics/mspsim/net/AbstractPacket.java (rev 0) +++ mspsim/se/sics/mspsim/net/AbstractPacket.java 2009-03-16 23:13:44 UTC (rev 489) @@ -0,0 +1,30 @@ +package se.sics.mspsim.net; + +import java.io.PrintStream; +import java.util.ArrayList; + +public abstract class AbstractPacket implements Packet { + + ArrayList<AbstractPacket> packetHandlers = new ArrayList<AbstractPacket>(); + + public void addInnerPacketHandler(AbstractPacket packet) { + packetHandlers.add(packet); + } + + public void notifyPacketHandlers(byte[] payload, int len) { + for (int i = 0; i < packetHandlers.size(); i++) { + try { + packetHandlers.get(i).setPacketData(payload, len); + } catch (Exception e) { + } + } + } + + public void printPacketStack(PrintStream out) { + printPacket(out); + for (int i = 0; i < packetHandlers.size(); i++) { + /* only the valid packets should print anything... */ + packetHandlers.get(i).printPacketStack(out); + } + } +} Added: mspsim/se/sics/mspsim/net/CC2420Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/CC2420Packet.java (rev 0) +++ mspsim/se/sics/mspsim/net/CC2420Packet.java 2009-03-16 23:13:44 UTC (rev 489) @@ -0,0 +1,157 @@ +/** + * Copyright (c) 2008, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of MSPSim. + * + * $Id: $ + * + * ----------------------------------------------------------------- + * + * CC2420Packet + * + * Author : Joakim Eriksson + * Created : mar 2009 + * Updated : $Date:$ + * $Revision:$ + */ + +package se.sics.mspsim.net; + +import java.io.PrintStream; + +import se.sics.mspsim.chip.RFListener; + +public class CC2420Packet extends AbstractPacket implements RFListener { + + private static final int SFD_SEARCH = 1; + private static final int LEN = 2; + private static final int PACKET = 3; + + private static final byte[] PREAMBLE = {0, 0, 0, 0, 0x7a}; + private int len; + private byte[] payload; + private boolean valid = false; + + public byte[] getDataField(String name) { + return null; + } + + public int getIntField(String name) { + return 0; + } + + public byte[] getPayload() { + return null; + } + + public int getSize() { + return len; + } + + /* should this be the interface??? or only RF_LIST ???*/ + /* maybe this is default and CC2420 is "special" */ + public void setPacketData(byte[] data, int plen) { + if (data.length > PREAMBLE.length) { + int pos = 0; + for (int i = 0; i < PREAMBLE.length; i++) { + if (data[i] != PREAMBLE[i]) { + throw new IllegalStateException("Illegal packet data"); + } + pos++; + } + len = data[pos] & 0xff; + + /* this will have RSSI and other junk last in the packet */ + if (len + 5 <= plen) { + payload = new byte[len & 0xff]; + System.arraycopy(data, pos + 1, payload, 0, len); + /* ignore RSSI, etc for now */ + System.out.println("Valid CC2420 packet received..."); + valid = true; + notifyPacketHandlers(payload, payload.length); + return; + } else { + throw new IllegalStateException("Illegal packet data"); + } + } + } + + byte[] packetBuffer = new byte[256]; + int mode = SFD_SEARCH; + int pos; + int packetLen; + int sfdSearch = 0; + + public void receivedByte(byte data) { + packetBuffer[pos++] = data; + switch (mode) { + case SFD_SEARCH: + if (sfdSearch < 4 && data == 0) + sfdSearch++; + if (sfdSearch == 4 && data == 0x7a) { + mode = LEN; + sfdSearch = 0; + } + break; + case LEN: + mode = PACKET; + packetLen = data & 0xff; + System.out.println("Packet len: " + packetLen); + break; + case PACKET: + if (pos == packetLen + PREAMBLE.length + 1) { + /* the packet is in!!! */ + setPacketData(packetBuffer, pos); + mode = SFD_SEARCH; + } + break; + } + } + + public void printPacket(PrintStream out) { + if (valid) { + out.println("CC2420 | len:" + len + "|"); + } + } + + + public static void main(String[] args) { + CC2420Packet p = new CC2420Packet(); + p.addInnerPacketHandler(new IEEE802154Packet()); + int[] data = new int[] {0,0,0,0,0x7a,48, + 0x41, 0xCC, 0x74, 0xCD, 0xAB, 0x55, 0x44, 0x33, + 0xFE, 0xFF, 0x22, 0x11, 0x02, 0x16, 0x15, 0x14, + 0xFE, 0xFF, 0x13, 0x12, 0x02, 0x03, 0xC0, 0x9D, + 0x06, 0x80, 0x00, 0x01, 0xAD, 0x39, 0x00, 0x50, + 0xAE, 0xC4, 0x9D, 0xC6, 0x00, 0x00, 0x00, 0x01, + 0x50, 0x10, 0x13, 0x10, 0xE7, 0xBF, 0x00, 0x00}; + for (int i = 0; i < data.length; i++) { + p.receivedByte((byte) (data[i] & 0xff)); + } + p.printPacketStack(System.out); + } +} Added: mspsim/se/sics/mspsim/net/IEEE802154Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/IEEE802154Packet.java (rev 0) +++ mspsim/se/sics/mspsim/net/IEEE802154Packet.java 2009-03-16 23:13:44 UTC (rev 489) @@ -0,0 +1,128 @@ +package se.sics.mspsim.net; + +import java.io.PrintStream; + +public class IEEE802154Packet extends AbstractPacket { + + public static final int SHORT_ADDRESS = 2; + public static final int LONG_ADDRESS = 3; + + private int type = 0; + private int security = 0; + private int pending = 0; + private int ackRequired = 0; + private int panCompression = 0; + private int destAddrMode; + private int frameVersion; + private int srcAddrMode; + private byte seqNumber; + private int destPanID; + private long destAddr; + private long srcAddr; + private int srcPanID; + private int payloadLen; + private boolean valid; + private byte[] payload; + + public byte[] getDataField(String name) { + return null; + } + + public int getIntField(String name) { + // TODO Auto-generated method stub + return 0; + } + + public byte[] getPayload() { + // TODO Auto-generated method stub + return null; + } + + public int getSize() { + // TODO Auto-generated method stub + return 0; + } + + public void printPacket(PrintStream out) { + out.printf("802.15.4 from %4x/", srcPanID); + printAddress(out, srcAddrMode, srcAddr); + out.printf(" to %4x/", destPanID); + printAddress(out, destAddrMode, destAddr); + out.printf(" seqNo: %d len: %d\n", seqNumber, payloadLen); + } + + public void setPacketData(byte[] data, int len) { + valid = false; + type = data[0] & 7; + security = (data[0] >> 3) & 1; + pending = (data[0] >> 4) & 1; + ackRequired = (data[0] >> 5) & 1; + panCompression = (data[0]>> 6) & 1; + destAddrMode = (data[1] >> 2) & 3; + frameVersion = (data[1] >> 4) & 3; + srcAddrMode = (data[1] >> 6) & 3; + seqNumber = data[2]; + + int pos = 3; + if (destAddrMode > 0) { + destPanID = (data[pos] & 0xff) + ((data[pos + 1] & 0xff) << 8); + pos += 2; + if (destAddrMode == SHORT_ADDRESS) { + destAddr = (data[pos] & 0xff) + ((data[pos + 1] & 0xff) << 8); + pos += 2; + } else if (destAddrMode == LONG_ADDRESS) { + destAddr = data[pos] + ((data[pos + 1] & 0xffL) << 8) + + ((data[pos + 2] & 0xffL) << 16) + ((data[pos + 3] & 0xffL) << 24) + + ((data[pos + 4] & 0xffL) << 32) + ((data[pos + 5] & 0xffL)<< 40) + + ((data[pos + 6] & 0xffL) << 48) + ((data[pos + 7] & 0xffL) << 56); + pos += 8; + } + } + + if (srcAddrMode > 0) { + if (panCompression == 0){ + srcPanID = (data[pos] & 0xff) + ((data[pos + 1] & 0xff) << 8); + pos += 2; + } else { + srcPanID = destPanID; + } + if (srcAddrMode == SHORT_ADDRESS) { + srcAddr = (data[pos] & 0xff) + ((data[pos + 1] & 0xff) << 8); + pos += 2; + } else if (srcAddrMode == LONG_ADDRESS) { + srcAddr = data[pos] + ((data[pos + 1] & 0xffL) << 8) + + ((data[pos + 2] & 0xffL) << 16) + ((data[pos + 3] & 0xffL) << 24) + + ((data[pos + 4] & 0xffL) << 32) + ((data[pos + 5] & 0xffL)<< 40) + + ((data[pos + 6] & 0xffL) << 48) + ((data[pos + 7] & 0xffL) << 56); + pos += 8; + } + } + + payloadLen = len - pos; + + payload = new byte[payloadLen]; + System.arraycopy(data, pos, payload, 0, payloadLen); + valid = true; + + notifyPacketHandlers(payload, payloadLen); + +// System.out.println("Type: " + type + " secure: " + security + +// " ack: " + ackRequired + " panComp: " + panCompression + +// " dst: " + destAddrMode + " src: " + srcAddrMode + +// " seq: " + seqNumber + " payloadLen: " + payloadLen); +// System.out.printf(" SrcPAN: %4x SrcAdr: ", srcPanID); +// printAddress(System.out, srcAddrMode, srcAddr); +// System.out.printf(" Dst PAN: %4x DstAdr: ", destPanID); +// printAddress(System.out, destAddrMode, destAddr); +// System.out.println(""); + } + + private void printAddress(PrintStream out, int type, long addr) { + if (type == SHORT_ADDRESS) { + out.printf("%04x", addr & 0xffff); + } else if (type == LONG_ADDRESS) { + out.printf("%016x", addr); + } + } + +} Added: mspsim/se/sics/mspsim/net/Packet.java =================================================================== --- mspsim/se/sics/mspsim/net/Packet.java (rev 0) +++ mspsim/se/sics/mspsim/net/Packet.java 2009-03-16 23:13:44 UTC (rev 489) @@ -0,0 +1,63 @@ +/** + * Copyright (c) 2008, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of MSPSim. + * + * $Id: $ + * + * ----------------------------------------------------------------- + * + * Packet + * + * Author : Joakim Eriksson + * Created : mar 2009 + * Updated : $Date:$ + * $Revision:$ + */ + +package se.sics.mspsim.net; + +import java.io.PrintStream; + +public interface Packet { + + public void setPacketData(byte[] data, int len); + + /** + * @return size of packet in bytes + */ + public int getSize(); + + /** + * @return payload of the packet + */ + public byte[] getPayload(); + + public int getIntField(String name); + public byte[] getDataField(String name); + public void printPacket(PrintStream out); +} \ No newline at end of file Modified: mspsim/se/sics/mspsim/util/NetworkPacket.java =================================================================== --- mspsim/se/sics/mspsim/util/NetworkPacket.java 2009-03-13 16:23:08 UTC (rev 488) +++ mspsim/se/sics/mspsim/util/NetworkPacket.java 2009-03-16 23:13:44 UTC (rev 489) @@ -138,7 +138,7 @@ return data.length; } - public int getIntBits(byte[] data, int startBit, int endBit) { + public static int getIntBits(byte[] data, int startBit, int endBit) { int startByte = startBit >> 8; int endByte = endBit >> 8; startBit = startBit & 7; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fro...@us...> - 2009-03-13 16:23:27
|
Revision: 488 http://mspsim.svn.sourceforge.net/mspsim/?rev=488&view=rev Author: fros4943 Date: 2009-03-13 16:23:08 +0000 (Fri, 13 Mar 2009) Log Message: ----------- optionally throw exception on bad (or unknown) operation Modified Paths: -------------- mspsim/se/sics/mspsim/core/MSP430Core.java Modified: mspsim/se/sics/mspsim/core/MSP430Core.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430Core.java 2009-03-13 15:53:07 UTC (rev 487) +++ mspsim/se/sics/mspsim/core/MSP430Core.java 2009-03-13 16:23:08 UTC (rev 488) @@ -52,6 +52,8 @@ public static final boolean DEBUG = false; public static final boolean debugInterrupts = false; + public static final boolean EXCEPTION_ON_BAD_OPERATION = true; + // Try it out with 64 k memory public static final int MAX_MEM = 64*1024; public static final int MAX_MEM_IO = 0x200; @@ -1221,8 +1223,12 @@ write = true; break; default: - System.out.println("DoubleOperand not implemented: " + op + - " at " + pc); + System.out.println("DoubleOperand not implemented: " + op + " at " + pc); + if (EXCEPTION_ON_BAD_OPERATION) { + EmulationException ex = new EmulationException("Bad operation: " + op + " at " + pc); + ex.initCause(new Throwable("" + pc)); + throw ex; + } } } if (word) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |