]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
separate the IEEE 802.15.4 packet and message handling
authormmaroti <mmaroti>
Fri, 18 Sep 2009 12:47:50 +0000 (12:47 +0000)
committermmaroti <mmaroti>
Fri, 18 Sep 2009 12:47:50 +0000 (12:47 +0000)
tos/chips/rf2xx/layers/Ieee154PacketLayer.h [new file with mode: 0644]
tos/chips/rf2xx/layers/Ieee154PacketLayer.nc [new file with mode: 0644]
tos/chips/rf2xx/layers/Ieee154PacketLayerC.nc [new file with mode: 0644]
tos/chips/rf2xx/layers/Ieee154PacketLayerP.nc [new file with mode: 0644]

diff --git a/tos/chips/rf2xx/layers/Ieee154PacketLayer.h b/tos/chips/rf2xx/layers/Ieee154PacketLayer.h
new file mode 100644 (file)
index 0000000..b7b14a6
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2007, Vanderbilt University
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ * 
+ * IN NO EVENT SHALL THE VANDERBILT UNIVERSITY BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE VANDERBILT
+ * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ * THE VANDERBILT UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ * Author: Miklos Maroti
+ */
+
+#ifndef __IEEE154PACKETLAYER_H__
+#define __IEEE154PACKETLAYER_H__
+
+typedef nx_struct ieee154_header_t
+{
+       nxle_uint16_t fcf;
+       nxle_uint8_t dsn;
+       nxle_uint16_t destpan;
+       nxle_uint16_t dest;
+       nxle_uint16_t src;
+} ieee154_header_t;
+
+enum ieee154_fcf_enums {
+       IEEE154_FCF_FRAME_TYPE = 0,
+       IEEE154_FCF_SECURITY_ENABLED = 3,
+       IEEE154_FCF_FRAME_PENDING = 4,
+       IEEE154_FCF_ACK_REQ = 5,
+       IEEE154_FCF_INTRAPAN = 6,
+       IEEE154_FCF_DEST_ADDR_MODE = 10,
+       IEEE154_FCF_SRC_ADDR_MODE = 14,
+};
+
+enum ieee154_fcf_type_enums {
+       IEEE154_TYPE_BEACON = 0,
+       IEEE154_TYPE_DATA = 1,
+       IEEE154_TYPE_ACK = 2,
+       IEEE154_TYPE_MAC_CMD = 3,
+       IEEE154_TYPE_MASK = 7,
+};
+
+enum iee154_fcf_addr_mode_enums {
+       IEEE154_ADDR_NONE = 0,
+       IEEE154_ADDR_SHORT = 2,
+       IEEE154_ADDR_EXT = 3,
+       IEEE154_ADDR_MASK = 3,
+};
+
+#endif//__IEEE154PACKETLAYER_H__
diff --git a/tos/chips/rf2xx/layers/Ieee154PacketLayer.nc b/tos/chips/rf2xx/layers/Ieee154PacketLayer.nc
new file mode 100644 (file)
index 0000000..140cb1b
--- /dev/null
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 2007, Vanderbilt University
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ * 
+ * IN NO EVENT SHALL THE VANDERBILT UNIVERSITY BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE VANDERBILT
+ * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ * THE VANDERBILT UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ * Author: Miklos Maroti
+ */
+
+#include <Ieee154PacketLayer.h>
+#include <message.h>
+
+/**
+ * This interface encapsulates IEEE 802.15.4 intrapan data frames with 
+ * 16-bit destination pan, source and destination addresses. It also 
+ * supports 6LowPan interoperability mode, and acknowledgement frames.
+ * Note, that this interface does not support the CRC-16 value, which
+ * should be verified before the data can be trusted.
+ */
+interface Ieee154PacketLayer
+{
+       /**
+        * Returns the frame control field. This method should not be used, 
+        * isDataFrame and isAckFrame should be used instead.
+        */
+       async command uint16_t getFCF(message_t* msg);
+
+       /**
+        * Sets the frame control field. This method should not be used, 
+        * createDataFrame and createAckFrame should be used instead.
+        */
+       async command void setFCF(message_t* msg, uint16_t fcf);
+
+       /**
+        * Returns TRUE if the message is a data frame supported by 
+        * this interface (based on the value of the FCF).
+        */
+       async command bool isDataFrame(message_t* msg);
+
+       /**
+        * Sets the FCF to create a data frame supported by this interface.
+        * You may call setAckRequired and setFramePending commands after this.
+        */
+       async command void createDataFrame(message_t* msg);
+
+       /**
+        * Returns TRUE if the message is an acknowledgement frame supported
+        * by this interface (based on the value of the FCF).
+        */
+       async command bool isAckFrame(message_t* msg);
+
+       /**
+        * Sets the FCF to create an acknowledgement frame supported by
+        * this interface. You may call setFramePending after this.
+        */
+       async command void createAckFrame(message_t* msg);
+
+       /**
+        * Creates an acknowledgement packet for the given data packet.
+        * This also sets the DSN value. The data message must be a 
+        * data frame, the ack message will be overwritten.
+        */
+       async command void createAckReply(message_t* data, message_t* ack);
+
+       /**
+        * Returns TRUE if the acknowledgement packet corresponds to the
+        * data packet. The data message must be a data packet.
+        */
+       async command bool verifyAckReply(message_t* data, message_t* ack);
+
+       /**
+        * Returns TRUE if the ACK required field is set in the FCF.
+        */
+       async command bool getAckRequired(message_t* msg);
+
+       /**
+        * Sets the ACK required field in the FCF, should never be set
+        * for acknowledgement frames.
+        */
+       async command void setAckRequired(message_t* msg, bool ack);
+
+       /**
+        * Returns TRUE if the frame pending field is set in the FCF.
+        */
+       async command bool getFramePending(message_t* msg);
+
+       /**
+        * Sets the frame pending field in the FCF.
+        */
+       async command void setFramePending(message_t* msg, bool pending);
+
+       /**
+        * Returns the data sequence number
+        */
+       async command uint8_t getDSN(message_t* msg);
+
+       /**
+        * Sets the data sequence number
+        */
+       async command void setDSN(message_t* msg, uint8_t dsn);
+
+       /**
+        * returns the destination PAN id, values <= 255 are tinyos groups,
+        * valid only for data frames
+        */
+       async command uint16_t getDestPan(message_t* msg);
+
+       /**
+        * Sets the destination PAN id, valid only for data frames
+        */
+       async command void setDestPan(message_t* msg, uint16_t pan);
+
+       /**
+        * Returns the destination address, valid only for data frames
+        */
+       async command uint16_t getDestAddr(message_t* msg);
+
+       /**
+        * Sets the destination address, valid only for data frames
+        */
+       async command void setDestAddr(message_t* msg, uint16_t addr);
+
+       /**
+        * Returns the source address, valid only for data frames
+        */
+       async command uint16_t getSrcAddr(message_t* msg);
+
+       /**
+        * Sets the source address, valid only for data frames
+        */
+       async command void setSrcAddr(message_t* msg, uint16_t addr);
+
+       /**
+        * Returns TRUE if the packet is a data packet, the ACK_REQ field
+        * is set and the destination address is not the broadcast address.
+        */
+       async command bool requiresAckWait(message_t* msg);
+
+       /**
+        * Returns TRUE if the packet is a data packet, the ACK_REQ field
+        * is set and the destionation address is this node.
+        */
+       async command bool requiresAckReply(message_t* msg);
+}
diff --git a/tos/chips/rf2xx/layers/Ieee154PacketLayerC.nc b/tos/chips/rf2xx/layers/Ieee154PacketLayerC.nc
new file mode 100644 (file)
index 0000000..acf89c8
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2007, Vanderbilt University
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ * 
+ * IN NO EVENT SHALL THE VANDERBILT UNIVERSITY BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE VANDERBILT
+ * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ * THE VANDERBILT UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ * Author: Miklos Maroti
+ */
+
+configuration Ieee154PacketLayerC
+{
+       provides
+       {
+               interface Ieee154PacketLayer;
+               interface Ieee154Packet;
+               interface RadioPacket;
+       }
+
+       uses
+       {
+               interface RadioPacket as SubPacket;
+       }
+}
+
+implementation
+{
+       components Ieee154PacketLayerP, ActiveMessageAddressC;
+       Ieee154PacketLayerP.ActiveMessageAddress -> ActiveMessageAddressC;
+
+       Ieee154PacketLayer = Ieee154PacketLayerP;
+       Ieee154Packet = Ieee154PacketLayerP;
+       RadioPacket = Ieee154PacketLayerP;
+       SubPacket = Ieee154PacketLayerP;
+}
diff --git a/tos/chips/rf2xx/layers/Ieee154PacketLayerP.nc b/tos/chips/rf2xx/layers/Ieee154PacketLayerP.nc
new file mode 100644 (file)
index 0000000..29f4647
--- /dev/null
@@ -0,0 +1,285 @@
+/*
+ * Copyright (c) 2007, Vanderbilt University
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ * 
+ * IN NO EVENT SHALL THE VANDERBILT UNIVERSITY BE LIABLE TO ANY PARTY FOR
+ * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
+ * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE VANDERBILT
+ * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ * THE VANDERBILT UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND THE VANDERBILT UNIVERSITY HAS NO OBLIGATION TO
+ * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+ *
+ * Author: Miklos Maroti
+ */
+
+#include <Ieee154PacketLayer.h>
+
+module Ieee154PacketLayerP
+{
+       provides 
+       {
+               interface Ieee154PacketLayer;
+               interface Ieee154Packet;
+               interface RadioPacket;
+       }
+
+       uses
+       {
+               interface ActiveMessageAddress;
+               interface RadioPacket as SubPacket;
+       }
+}
+
+implementation
+{
+/*----------------- Ieee154Packet -----------------*/
+
+       enum
+       {
+               IEEE154_DATA_FRAME_MASK = (IEEE154_TYPE_MASK << IEEE154_FCF_FRAME_TYPE) 
+                       | (1 << IEEE154_FCF_INTRAPAN) 
+                       | (IEEE154_ADDR_MASK << IEEE154_FCF_DEST_ADDR_MODE) 
+                       | (IEEE154_ADDR_MASK << IEEE154_FCF_SRC_ADDR_MODE),
+
+               IEEE154_DATA_FRAME_VALUE = (IEEE154_TYPE_DATA << IEEE154_FCF_FRAME_TYPE) 
+                       | (1 << IEEE154_FCF_INTRAPAN) 
+                       | (IEEE154_ADDR_SHORT << IEEE154_FCF_DEST_ADDR_MODE) 
+                       | (IEEE154_ADDR_SHORT << IEEE154_FCF_SRC_ADDR_MODE),
+
+               IEEE154_ACK_FRAME_LENGTH = 3,   // includes the FCF, DSN
+               IEEE154_ACK_FRAME_MASK = (IEEE154_TYPE_MASK << IEEE154_FCF_FRAME_TYPE), 
+               IEEE154_ACK_FRAME_VALUE = (IEEE154_TYPE_ACK << IEEE154_FCF_FRAME_TYPE),
+       };
+
+       ieee154_header_t* getHeader(message_t* msg)
+       {
+               return ((void*)msg) + call SubPacket.headerLength(msg);
+       }
+
+       void* getPayload(message_t* msg)
+       {
+               return ((void*)msg) + call RadioPacket.headerLength(msg);
+       }
+
+       async command uint16_t Ieee154PacketLayer.getFCF(message_t* msg)
+       {
+               return getHeader(msg)->fcf;
+       }
+
+       async command void Ieee154PacketLayer.setFCF(message_t* msg, uint16_t fcf)
+       {
+               getHeader(msg)->fcf = fcf;
+       }
+
+       async command bool Ieee154PacketLayer.isDataFrame(message_t* msg)
+       {
+               return (getHeader(msg)->fcf & IEEE154_DATA_FRAME_MASK) == IEEE154_DATA_FRAME_VALUE;
+       }
+
+       async command void Ieee154PacketLayer.createDataFrame(message_t* msg)
+       {
+               getHeader(msg)->fcf = IEEE154_DATA_FRAME_VALUE;
+       }
+
+       async command bool Ieee154PacketLayer.isAckFrame(message_t* msg)
+       {
+               return (getHeader(msg)->fcf & IEEE154_ACK_FRAME_MASK) == IEEE154_ACK_FRAME_VALUE;
+       }
+
+       async command void Ieee154PacketLayer.createAckFrame(message_t* msg)
+       {
+               call SubPacket.setPayloadLength(msg, IEEE154_ACK_FRAME_LENGTH);
+               getHeader(msg)->fcf = IEEE154_ACK_FRAME_VALUE;
+       }
+
+       async command void Ieee154PacketLayer.createAckReply(message_t* data, message_t* ack)
+       {
+               ieee154_header_t* header = getHeader(ack);
+               call SubPacket.setPayloadLength(ack, IEEE154_ACK_FRAME_LENGTH);
+
+               header->fcf = IEEE154_ACK_FRAME_VALUE;
+               header->dsn = getHeader(data)->dsn;
+       }
+
+       async command bool Ieee154PacketLayer.verifyAckReply(message_t* data, message_t* ack)
+       {
+               ieee154_header_t* header = getHeader(ack);
+
+               return header->dsn == getHeader(data)->dsn
+                       && (header->fcf & IEEE154_ACK_FRAME_MASK) == IEEE154_ACK_FRAME_VALUE;
+       }
+
+       async command bool Ieee154PacketLayer.getAckRequired(message_t* msg)
+       {
+               return getHeader(msg)->fcf & (1 << IEEE154_FCF_ACK_REQ);
+       }
+
+       async command void Ieee154PacketLayer.setAckRequired(message_t* msg, bool ack)
+       {
+               if( ack )
+                       getHeader(msg)->fcf |= (1 << IEEE154_FCF_ACK_REQ);
+               else
+                       getHeader(msg)->fcf &= ~(uint16_t)(1 << IEEE154_FCF_ACK_REQ);
+       }
+
+       async command bool Ieee154PacketLayer.getFramePending(message_t* msg)
+       {
+               return getHeader(msg)->fcf & (1 << IEEE154_FCF_FRAME_PENDING);
+       }
+
+       async command void Ieee154PacketLayer.setFramePending(message_t* msg, bool pending)
+       {
+               if( pending )
+                       getHeader(msg)->fcf |= (1 << IEEE154_FCF_FRAME_PENDING);
+               else
+                       getHeader(msg)->fcf &= ~(uint16_t)(1 << IEEE154_FCF_FRAME_PENDING);
+       }
+
+       async command uint8_t Ieee154PacketLayer.getDSN(message_t* msg)
+       {
+               return getHeader(msg)->dsn;
+       }
+
+       async command void Ieee154PacketLayer.setDSN(message_t* msg, uint8_t dsn)
+       {
+               getHeader(msg)->dsn = dsn;
+       }
+
+       async command uint16_t Ieee154PacketLayer.getDestPan(message_t* msg)
+       {
+               return getHeader(msg)->destpan;
+       }
+
+       async command void Ieee154PacketLayer.setDestPan(message_t* msg, uint16_t pan)
+       {
+               getHeader(msg)->destpan = pan;
+       }
+
+       async command uint16_t Ieee154PacketLayer.getDestAddr(message_t* msg)
+       {
+               return getHeader(msg)->dest;
+       }
+
+       async command void Ieee154PacketLayer.setDestAddr(message_t* msg, uint16_t addr)
+       {
+               getHeader(msg)->dest = addr;
+       }
+
+       async command uint16_t Ieee154PacketLayer.getSrcAddr(message_t* msg)
+       {
+               return getHeader(msg)->src;
+       }
+
+       async command void Ieee154PacketLayer.setSrcAddr(message_t* msg, uint16_t addr)
+       {       
+               getHeader(msg)->src = addr;
+       }
+
+       async command bool Ieee154PacketLayer.requiresAckWait(message_t* msg)
+       {
+               return call Ieee154PacketLayer.getAckRequired(msg)
+                       && call Ieee154PacketLayer.isDataFrame(msg)
+                       && call Ieee154PacketLayer.getDestAddr(msg) != 0xFFFF;
+       }
+
+       async command bool Ieee154PacketLayer.requiresAckReply(message_t* msg)
+       {
+               return call Ieee154PacketLayer.getAckRequired(msg)
+                       && call Ieee154PacketLayer.isDataFrame(msg)
+                       && call Ieee154PacketLayer.getDestAddr(msg) == call ActiveMessageAddress.amAddress();
+       }
+
+       async event void ActiveMessageAddress.changed()
+       {
+       }
+
+/*----------------- Ieee154Packet -----------------*/
+
+       command ieee154_saddr_t Ieee154Packet.address()
+       {
+               return call ActiveMessageAddress.amAddress();
+       }
+
+       command ieee154_saddr_t Ieee154Packet.destination(message_t* msg)
+       {
+               return call Ieee154PacketLayer.getDestAddr(msg);
+       }
+       command ieee154_saddr_t Ieee154Packet.source(message_t* msg)
+       {
+               return call Ieee154PacketLayer.getSrcAddr(msg);
+       }
+
+       command void Ieee154Packet.setDestination(message_t* msg, ieee154_saddr_t addr)
+       {
+               call Ieee154PacketLayer.setDestAddr(msg, addr);
+       }
+
+       command void Ieee154Packet.setSource(message_t* msg, ieee154_saddr_t addr)
+       {
+               call Ieee154PacketLayer.setSrcAddr(msg, addr);
+       }
+
+       command bool Ieee154Packet.isForMe(message_t* msg)
+       {
+               ieee154_saddr_t addr = call Ieee154Packet.destination(msg);
+               return addr == call Ieee154Packet.address() || addr == IEEE154_BROADCAST_ADDR;
+       }
+
+       command ieee154_panid_t Ieee154Packet.pan(message_t* msg)
+       {
+               return call Ieee154PacketLayer.getDestPan(msg);
+       }
+
+       command void Ieee154Packet.setPan(message_t* msg, ieee154_panid_t grp)
+       {
+               call Ieee154PacketLayer.setDestPan(msg, grp);
+       }
+
+       command ieee154_panid_t Ieee154Packet.localPan()
+       {
+               return call ActiveMessageAddress.amGroup();
+       }
+
+/*----------------- RadioPacket -----------------*/
+
+       async command uint8_t RadioPacket.headerLength(message_t* msg)
+       {
+               return call SubPacket.headerLength(msg) + sizeof(ieee154_header_t);
+       }
+
+       async command uint8_t RadioPacket.payloadLength(message_t* msg)
+       {
+               return call SubPacket.payloadLength(msg) - sizeof(ieee154_header_t);
+       }
+
+       async command void RadioPacket.setPayloadLength(message_t* msg, uint8_t length)
+       {
+               call SubPacket.setPayloadLength(msg, length + sizeof(ieee154_header_t));
+       }
+
+       async command uint8_t RadioPacket.maxPayloadLength()
+       {
+               return call SubPacket.maxPayloadLength() - sizeof(ieee154_header_t);
+       }
+
+       async command uint8_t RadioPacket.metadataLength(message_t* msg)
+       {
+               return call SubPacket.metadataLength(msg);
+       }
+
+       async command void RadioPacket.clear(message_t* msg)
+       {
+               call Ieee154PacketLayer.createDataFrame(msg);
+               call SubPacket.clear(msg);
+       }
+}