From 51b365b6cb1df293dac98e285ae4856c2dccba2b Mon Sep 17 00:00:00 2001 From: mmaroti Date: Sat, 4 Apr 2009 00:43:55 +0000 Subject: [PATCH] reorganized packet header handling --- tos/chips/rf2xx/layers/ActiveMessageConfig.nc | 25 ++ tos/chips/rf2xx/layers/ActiveMessageLayer.h | 32 ++ tos/chips/rf2xx/layers/ActiveMessageLayerC.nc | 84 +---- tos/chips/rf2xx/layers/ActiveMessageLayerP.nc | 171 ++++++++++ .../rf2xx/layers/IEEE154MessageConfig.nc | 32 ++ ...154PacketLayer.h => IEEE154MessageLayer.h} | 13 +- ...4PacketLayer.nc => IEEE154MessageLayer.nc} | 33 +- ...acketLayerC.nc => IEEE154MessageLayerC.nc} | 18 +- .../rf2xx/layers/IEEE154MessageLayerP.nc | 258 +++++++++++++++ tos/chips/rf2xx/layers/IEEE154PacketLayerP.nc | 294 ------------------ .../rf2xx/layers/LowPowerListeningConfig.nc | 44 +++ .../rf2xx/layers/LowPowerListeningLayerC.nc | 6 +- .../rf2xx/layers/LowPowerListeningLayerP.nc | 13 +- ...etworkLayerC.nc => LowpanNetworkConfig.nc} | 33 +- tos/chips/rf2xx/layers/LowpanNetworkLayer.h | 32 ++ ...etworkLayerP.nc => LowpanNetworkLayerC.nc} | 10 +- tos/chips/rf2xx/rf212/RF212ActiveMessage.h | 13 +- tos/chips/rf2xx/rf212/RF212ActiveMessageC.nc | 33 +- tos/chips/rf2xx/rf212/RF212ActiveMessageP.nc | 145 ++++++--- tos/chips/rf2xx/rf230/RF230ActiveMessage.h | 13 +- tos/chips/rf2xx/rf230/RF230ActiveMessageC.nc | 33 +- tos/chips/rf2xx/rf230/RF230ActiveMessageP.nc | 145 ++++++--- tos/chips/rf2xx/util/IEEE802154.h | 74 +++++ tos/chips/rf2xx/util/Ieee154Packet.nc | 44 +++ tos/chips/rf2xx/util/Ieee154Send.nc | 108 +++++++ 25 files changed, 1142 insertions(+), 564 deletions(-) create mode 100644 tos/chips/rf2xx/layers/ActiveMessageLayer.h create mode 100644 tos/chips/rf2xx/layers/ActiveMessageLayerP.nc create mode 100644 tos/chips/rf2xx/layers/IEEE154MessageConfig.nc rename tos/chips/rf2xx/layers/{IEEE154PacketLayer.h => IEEE154MessageLayer.h} (89%) rename tos/chips/rf2xx/layers/{IEEE154PacketLayer.nc => IEEE154MessageLayer.nc} (88%) rename tos/chips/rf2xx/layers/{IEEE154PacketLayerC.nc => IEEE154MessageLayerC.nc} (77%) create mode 100644 tos/chips/rf2xx/layers/IEEE154MessageLayerP.nc delete mode 100644 tos/chips/rf2xx/layers/IEEE154PacketLayerP.nc create mode 100644 tos/chips/rf2xx/layers/LowPowerListeningConfig.nc rename tos/chips/rf2xx/layers/{IEEE154NetworkLayerC.nc => LowpanNetworkConfig.nc} (67%) create mode 100644 tos/chips/rf2xx/layers/LowpanNetworkLayer.h rename tos/chips/rf2xx/layers/{IEEE154NetworkLayerP.nc => LowpanNetworkLayerC.nc} (91%) create mode 100644 tos/chips/rf2xx/util/IEEE802154.h create mode 100644 tos/chips/rf2xx/util/Ieee154Packet.nc create mode 100644 tos/chips/rf2xx/util/Ieee154Send.nc diff --git a/tos/chips/rf2xx/layers/ActiveMessageConfig.nc b/tos/chips/rf2xx/layers/ActiveMessageConfig.nc index e47f0e8b..d3dadd42 100755 --- a/tos/chips/rf2xx/layers/ActiveMessageConfig.nc +++ b/tos/chips/rf2xx/layers/ActiveMessageConfig.nc @@ -21,6 +21,8 @@ * Author: Miklos Maroti */ +#include + interface ActiveMessageConfig { /** @@ -29,4 +31,27 @@ interface ActiveMessageConfig * forgot to do so (or return EINVAL to be strict). */ command error_t checkPacket(message_t* msg); + + /** + * Returns a pointer to the ActiveMessage header field in the message + */ + command activemessage_header_t* getHeader(message_t* msg); + + /** Same as AMPacket.destination */ + command am_addr_t destination(message_t* msg); + + /** Same as AMPacket.setDestination */ + command void setDestination(message_t* msg, am_addr_t addr); + + /** Same as AMPacket.source */ + command am_addr_t source(message_t* msg); + + /** Same as AMPacket.setSource */ + command void setSource(message_t* msg, am_addr_t addr); + + /** Same as AMPacket.group */ + command am_group_t group(message_t* msg); + + /** Same as AMPacket.setGroup */ + command void setGroup(message_t* msg, am_group_t grp); } diff --git a/tos/chips/rf2xx/layers/ActiveMessageLayer.h b/tos/chips/rf2xx/layers/ActiveMessageLayer.h new file mode 100644 index 00000000..1a6d5afe --- /dev/null +++ b/tos/chips/rf2xx/layers/ActiveMessageLayer.h @@ -0,0 +1,32 @@ +/* + * 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 __ACTIVEMESSAGELAYER_H__ +#define __ACTIVEMESSAGELAYER_H__ + +typedef nx_struct activemessage_header_t +{ + nxle_uint8_t type; +} activemessage_header_t; + +#endif//__ACTIVEMESSAGELAYER_H__ diff --git a/tos/chips/rf2xx/layers/ActiveMessageLayerC.nc b/tos/chips/rf2xx/layers/ActiveMessageLayerC.nc index f635a9c6..055aaa72 100755 --- a/tos/chips/rf2xx/layers/ActiveMessageLayerC.nc +++ b/tos/chips/rf2xx/layers/ActiveMessageLayerC.nc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, Vanderbilt University + * Copyright (c) 2009, Vanderbilt University * All rights reserved. * * Permission to use, copy, modify, and distribute this software and its @@ -21,87 +21,37 @@ * Author: Miklos Maroti */ -module ActiveMessageLayerC +#include + +configuration ActiveMessageLayerC { provides { + interface AMPacket; interface AMSend[am_id_t id]; interface Receive[am_id_t id]; interface Receive as Snoop[am_id_t id]; } + uses { interface Send as SubSend; interface Receive as SubReceive; - interface AMPacket; interface ActiveMessageConfig as Config; } } implementation { -/*----------------- Send -----------------*/ - - command error_t AMSend.send[am_id_t id](am_addr_t addr, message_t* msg, uint8_t len) - { - error_t error; - - error = call Config.checkPacket(msg); - if( error != SUCCESS ) - return error; - - call AMPacket.setSource(msg, call AMPacket.address()); - call AMPacket.setGroup(msg, call AMPacket.localGroup()); - call AMPacket.setType(msg, id); - call AMPacket.setDestination(msg, addr); - - return call SubSend.send(msg, len); - } - - inline event void SubSend.sendDone(message_t* msg, error_t error) - { - signal AMSend.sendDone[call AMPacket.type(msg)](msg, error); - } - - inline command error_t AMSend.cancel[am_id_t id](message_t* msg) - { - return call SubSend.cancel(msg); - } - - default event void AMSend.sendDone[am_id_t id](message_t* msg, error_t error) - { - } - - inline command uint8_t AMSend.maxPayloadLength[am_id_t id]() - { - return call SubSend.maxPayloadLength(); - } - - inline command void* AMSend.getPayload[am_id_t id](message_t* msg, uint8_t len) - { - return call SubSend.getPayload(msg, len); - } - -/*----------------- Receive -----------------*/ - - event message_t* SubReceive.receive(message_t* msg, void* payload, uint8_t len) - { - am_id_t type = call AMPacket.type(msg); - - msg = call AMPacket.isForMe(msg) - ? signal Receive.receive[type](msg, payload, len) - : signal Snoop.receive[type](msg, payload, len); - - return msg; - } - - default event message_t* Receive.receive[am_id_t id](message_t* msg, void* payload, uint8_t len) - { - return msg; - } - - default event message_t* Snoop.receive[am_id_t id](message_t* msg, void* payload, uint8_t len) - { - return msg; - } + components ActiveMessageLayerP, ActiveMessageAddressC; + ActiveMessageLayerP.ActiveMessageAddress -> ActiveMessageAddressC; + + AMPacket = ActiveMessageLayerP; + AMSend = ActiveMessageLayerP; + Receive = ActiveMessageLayerP.Receive; + Snoop = ActiveMessageLayerP.Snoop; + + SubSend = ActiveMessageLayerP; + SubReceive = ActiveMessageLayerP; + Config = ActiveMessageLayerP; } diff --git a/tos/chips/rf2xx/layers/ActiveMessageLayerP.nc b/tos/chips/rf2xx/layers/ActiveMessageLayerP.nc new file mode 100644 index 00000000..90406a94 --- /dev/null +++ b/tos/chips/rf2xx/layers/ActiveMessageLayerP.nc @@ -0,0 +1,171 @@ +/* + * 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 + */ + +module ActiveMessageLayerP +{ + provides + { + interface AMPacket; + interface AMSend[am_id_t id]; + interface Receive[am_id_t id]; + interface Receive as Snoop[am_id_t id]; + } + + uses + { + interface Send as SubSend; + interface Receive as SubReceive; + interface ActiveMessageConfig as Config; + interface ActiveMessageAddress; + } +} + +implementation +{ +/*----------------- Send -----------------*/ + + command error_t AMSend.send[am_id_t id](am_addr_t addr, message_t* msg, uint8_t len) + { + error_t error; + + error = call Config.checkPacket(msg); + if( error != SUCCESS ) + return error; + + call AMPacket.setSource(msg, call AMPacket.address()); + call AMPacket.setGroup(msg, call AMPacket.localGroup()); + call AMPacket.setType(msg, id); + call AMPacket.setDestination(msg, addr); + + return call SubSend.send(msg, len); + } + + inline event void SubSend.sendDone(message_t* msg, error_t error) + { + signal AMSend.sendDone[call AMPacket.type(msg)](msg, error); + } + + inline command error_t AMSend.cancel[am_id_t id](message_t* msg) + { + return call SubSend.cancel(msg); + } + + default event void AMSend.sendDone[am_id_t id](message_t* msg, error_t error) + { + } + + inline command uint8_t AMSend.maxPayloadLength[am_id_t id]() + { + return call SubSend.maxPayloadLength(); + } + + inline command void* AMSend.getPayload[am_id_t id](message_t* msg, uint8_t len) + { + return call SubSend.getPayload(msg, len); + } + +/*----------------- Receive -----------------*/ + + event message_t* SubReceive.receive(message_t* msg, void* payload, uint8_t len) + { + am_id_t type = call AMPacket.type(msg); + + msg = call AMPacket.isForMe(msg) + ? signal Receive.receive[type](msg, payload, len) + : signal Snoop.receive[type](msg, payload, len); + + return msg; + } + + default event message_t* Receive.receive[am_id_t id](message_t* msg, void* payload, uint8_t len) + { + return msg; + } + + default event message_t* Snoop.receive[am_id_t id](message_t* msg, void* payload, uint8_t len) + { + return msg; + } + +/*----------------- AMPacket -----------------*/ + + inline command am_addr_t AMPacket.address() + { + return call ActiveMessageAddress.amAddress(); + } + + inline command am_group_t AMPacket.localGroup() + { + return call ActiveMessageAddress.amGroup(); + } + + inline command bool AMPacket.isForMe(message_t* msg) + { + am_addr_t addr = call AMPacket.destination(msg); + return addr == call AMPacket.address() || addr == AM_BROADCAST_ADDR; + } + + inline command am_addr_t AMPacket.destination(message_t* msg) + { + return call Config.destination(msg); + } + + inline command void AMPacket.setDestination(message_t* msg, am_addr_t addr) + { + call Config.setDestination(msg, addr); + } + + inline command am_addr_t AMPacket.source(message_t* msg) + { + return call Config.source(msg); + } + + inline command void AMPacket.setSource(message_t* msg, am_addr_t addr) + { + call Config.setSource(msg, addr); + } + + inline command am_id_t AMPacket.type(message_t* msg) + { + return (call Config.getHeader(msg))->type; + } + + inline command void AMPacket.setType(message_t* msg, am_id_t type) + { + (call Config.getHeader(msg))->type = type; + } + + inline command am_group_t AMPacket.group(message_t* msg) + { + return call Config.group(msg); + } + + inline command void AMPacket.setGroup(message_t* msg, am_group_t grp) + { + call Config.setGroup(msg, grp); + } + + inline async event void ActiveMessageAddress.changed() + { + } +} diff --git a/tos/chips/rf2xx/layers/IEEE154MessageConfig.nc b/tos/chips/rf2xx/layers/IEEE154MessageConfig.nc new file mode 100644 index 00000000..c02bca44 --- /dev/null +++ b/tos/chips/rf2xx/layers/IEEE154MessageConfig.nc @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2009, 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 + +interface IEEE154MessageConfig +{ + /** + * Returns a pointer to the IEEE 802.15.4 header fields in the message + */ + async command ieee154_header_t* getHeader(message_t* msg); +} diff --git a/tos/chips/rf2xx/layers/IEEE154PacketLayer.h b/tos/chips/rf2xx/layers/IEEE154MessageLayer.h similarity index 89% rename from tos/chips/rf2xx/layers/IEEE154PacketLayer.h rename to tos/chips/rf2xx/layers/IEEE154MessageLayer.h index 721d96d8..9748012d 100644 --- a/tos/chips/rf2xx/layers/IEEE154PacketLayer.h +++ b/tos/chips/rf2xx/layers/IEEE154MessageLayer.h @@ -21,8 +21,8 @@ * Author: Miklos Maroti */ -#ifndef __IEEE154PACKETLAYER_H__ -#define __IEEE154PACKETLAYER_H__ +#ifndef __IEEE154MESSAGELAYER_H__ +#define __IEEE154MESSAGELAYER_H__ typedef nx_struct ieee154_header_t { @@ -32,13 +32,6 @@ typedef nx_struct ieee154_header_t nxle_uint16_t destpan; nxle_uint16_t dest; nxle_uint16_t src; - -// I-Frame 6LowPAN interoperability byte -#ifndef TFRAMES_ENABLED - nxle_uint8_t network; -#endif - - nxle_uint8_t type; } ieee154_header_t; // the actual radio driver might not use this @@ -72,4 +65,4 @@ enum iee154_fcf_addr_mode_enums { IEEE154_ADDR_MASK = 3, }; -#endif//__IEEE154PACKETLAYER_H__ +#endif//__IEEE154MESSAGELAYER_H__ diff --git a/tos/chips/rf2xx/layers/IEEE154PacketLayer.nc b/tos/chips/rf2xx/layers/IEEE154MessageLayer.nc similarity index 88% rename from tos/chips/rf2xx/layers/IEEE154PacketLayer.nc rename to tos/chips/rf2xx/layers/IEEE154MessageLayer.nc index 896b9cd9..f1e34fd6 100644 --- a/tos/chips/rf2xx/layers/IEEE154PacketLayer.nc +++ b/tos/chips/rf2xx/layers/IEEE154MessageLayer.nc @@ -21,7 +21,7 @@ * Author: Miklos Maroti */ -#include +#include #include /** @@ -31,13 +31,8 @@ * Note, that this interface does not support the CRC-16 value, which * should be verified before the data can be trusted. */ -interface IEEE154PacketLayer +interface IEEE154MessageLayer { - /** - * Returns the IEEE 802.15.4 header including the length field. - */ - async command ieee154_header_t* getHeader(message_t* msg); - /** * Returns the raw value (unadjusted) of the length field */ @@ -159,30 +154,6 @@ interface IEEE154PacketLayer */ async command void setSrcAddr(message_t* msg, uint16_t addr); -#ifndef TFRAMES_ENABLED - - /** - * Returns the value of the 6LowPan network field. - */ - async command uint8_t get6LowPan(message_t* msg); - - /** - * Sets the value of the 6LowPan network field. - */ - async command void set6LowPan(message_t* msg, uint8_t network); - -#endif - - /** - * Returns the active message type of the message - */ - async command am_id_t getType(message_t* msg); - - /** - * Sets the active message type - */ - async command void setType(message_t* msg, am_id_t type); - /** * Returns TRUE if the packet is a data packet, the ACK_REQ field * is set and the destination address is not the broadcast address. diff --git a/tos/chips/rf2xx/layers/IEEE154PacketLayerC.nc b/tos/chips/rf2xx/layers/IEEE154MessageLayerC.nc similarity index 77% rename from tos/chips/rf2xx/layers/IEEE154PacketLayerC.nc rename to tos/chips/rf2xx/layers/IEEE154MessageLayerC.nc index a0768a9e..2040739f 100644 --- a/tos/chips/rf2xx/layers/IEEE154PacketLayerC.nc +++ b/tos/chips/rf2xx/layers/IEEE154MessageLayerC.nc @@ -21,20 +21,24 @@ * Author: Miklos Maroti */ -configuration IEEE154PacketLayerC +configuration IEEE154MessageLayerC { provides { - interface IEEE154PacketLayer; - interface AMPacket; + interface IEEE154MessageLayer; + } + + uses + { + interface IEEE154MessageConfig as Config; } } implementation { - components IEEE154PacketLayerP, ActiveMessageAddressC; - IEEE154PacketLayerP.ActiveMessageAddress -> ActiveMessageAddressC; + components IEEE154MessageLayerP, ActiveMessageAddressC; + IEEE154MessageLayerP.ActiveMessageAddress -> ActiveMessageAddressC; - IEEE154PacketLayer = IEEE154PacketLayerP; - AMPacket = IEEE154PacketLayerP; + IEEE154MessageLayer = IEEE154MessageLayerP; + Config = IEEE154MessageLayerP; } diff --git a/tos/chips/rf2xx/layers/IEEE154MessageLayerP.nc b/tos/chips/rf2xx/layers/IEEE154MessageLayerP.nc new file mode 100644 index 00000000..a9a82bb0 --- /dev/null +++ b/tos/chips/rf2xx/layers/IEEE154MessageLayerP.nc @@ -0,0 +1,258 @@ +/* + * 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 + +module IEEE154MessageLayerP +{ + provides + { + interface IEEE154MessageLayer; + interface Ieee154Packet; + } + + uses + { + interface ActiveMessageAddress; + interface IEEE154MessageConfig as Config; + } +} + +implementation +{ +/*----------------- IEEE154Message -----------------*/ + + 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 = 5, // includes the FCF, DSN and FCS + 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 call Config.getHeader(msg); + } + + async command uint8_t IEEE154MessageLayer.getLength(message_t* msg) + { + return getHeader(msg)->length; + } + + async command void IEEE154MessageLayer.setLength(message_t* msg, uint8_t length) + { + getHeader(msg)->length = length; + } + + async command uint16_t IEEE154MessageLayer.getFCF(message_t* msg) + { + return getHeader(msg)->fcf; + } + + async command void IEEE154MessageLayer.setFCF(message_t* msg, uint16_t fcf) + { + getHeader(msg)->fcf = fcf; + } + + async command bool IEEE154MessageLayer.isDataFrame(message_t* msg) + { + return (getHeader(msg)->fcf & IEEE154_DATA_FRAME_MASK) == IEEE154_DATA_FRAME_VALUE; + } + + async command void IEEE154MessageLayer.createDataFrame(message_t* msg) + { + getHeader(msg)->fcf = IEEE154_DATA_FRAME_VALUE; + } + + async command bool IEEE154MessageLayer.isAckFrame(message_t* msg) + { + return (getHeader(msg)->fcf & IEEE154_ACK_FRAME_MASK) == IEEE154_ACK_FRAME_VALUE; + } + + async command void IEEE154MessageLayer.createAckFrame(message_t* msg) + { + ieee154_header_t* header = getHeader(msg); + + header->length = IEEE154_ACK_FRAME_LENGTH; + header->fcf = IEEE154_ACK_FRAME_VALUE; + } + + async command void IEEE154MessageLayer.createAckReply(message_t* data, message_t* ack) + { + ieee154_header_t* header = getHeader(ack); + + header->length = IEEE154_ACK_FRAME_LENGTH; + header->fcf = IEEE154_ACK_FRAME_VALUE; + header->dsn = getHeader(data)->dsn; + } + + async command bool IEEE154MessageLayer.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 IEEE154MessageLayer.getAckRequired(message_t* msg) + { + return getHeader(msg)->fcf & (1 << IEEE154_FCF_ACK_REQ); + } + + async command void IEEE154MessageLayer.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 IEEE154MessageLayer.getFramePending(message_t* msg) + { + return getHeader(msg)->fcf & (1 << IEEE154_FCF_FRAME_PENDING); + } + + async command void IEEE154MessageLayer.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 IEEE154MessageLayer.getDSN(message_t* msg) + { + return getHeader(msg)->dsn; + } + + async command void IEEE154MessageLayer.setDSN(message_t* msg, uint8_t dsn) + { + getHeader(msg)->dsn = dsn; + } + + async command uint16_t IEEE154MessageLayer.getDestPan(message_t* msg) + { + return getHeader(msg)->destpan; + } + + async command void IEEE154MessageLayer.setDestPan(message_t* msg, uint16_t pan) + { + getHeader(msg)->destpan = pan; + } + + async command uint16_t IEEE154MessageLayer.getDestAddr(message_t* msg) + { + return getHeader(msg)->dest; + } + + async command void IEEE154MessageLayer.setDestAddr(message_t* msg, uint16_t addr) + { + getHeader(msg)->dest = addr; + } + + async command uint16_t IEEE154MessageLayer.getSrcAddr(message_t* msg) + { + return getHeader(msg)->src; + } + + async command void IEEE154MessageLayer.setSrcAddr(message_t* msg, uint16_t addr) + { + getHeader(msg)->src = addr; + } + + async command bool IEEE154MessageLayer.requiresAckWait(message_t* msg) + { + return call IEEE154MessageLayer.getAckRequired(msg) + && call IEEE154MessageLayer.isDataFrame(msg) + && call IEEE154MessageLayer.getDestAddr(msg) != 0xFFFF; + } + + async command bool IEEE154MessageLayer.requiresAckReply(message_t* msg) + { + return call IEEE154MessageLayer.getAckRequired(msg) + && call IEEE154MessageLayer.isDataFrame(msg) + && call IEEE154MessageLayer.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 IEEE154MessageLayer.getDestAddr(msg); + } + + command ieee154_saddr_t Ieee154Packet.source(message_t* msg) + { + return call IEEE154MessageLayer.getSrcAddr(msg); + } + + command void Ieee154Packet.setDestination(message_t* msg, ieee154_saddr_t addr) + { + call IEEE154MessageLayer.setDestAddr(msg, addr); + } + + command void Ieee154Packet.setSource(message_t* msg, ieee154_saddr_t addr) + { + call IEEE154MessageLayer.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 IEEE154MessageLayer.getDestPan(msg); + } + + command void Ieee154Packet.setPan(message_t* msg, ieee154_panid_t grp) + { + call IEEE154MessageLayer.setDestPan(msg, grp); + } + + command ieee154_panid_t Ieee154Packet.localPan() + { + return call ActiveMessageAddress.amGroup(); + } +} diff --git a/tos/chips/rf2xx/layers/IEEE154PacketLayerP.nc b/tos/chips/rf2xx/layers/IEEE154PacketLayerP.nc deleted file mode 100644 index 58573657..00000000 --- a/tos/chips/rf2xx/layers/IEEE154PacketLayerP.nc +++ /dev/null @@ -1,294 +0,0 @@ -/* - * 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 - -module IEEE154PacketLayerP -{ - provides - { - interface IEEE154PacketLayer; - interface AMPacket; - } - - uses interface ActiveMessageAddress; -} - -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 = 5, // includes the FCF, DSN and FCS - IEEE154_ACK_FRAME_MASK = (IEEE154_TYPE_MASK << IEEE154_FCF_FRAME_TYPE), - IEEE154_ACK_FRAME_VALUE = (IEEE154_TYPE_ACK << IEEE154_FCF_FRAME_TYPE), - }; - - inline ieee154_header_t* getHeader(message_t* msg) - { - return (ieee154_header_t*)(msg->data - sizeof(ieee154_header_t)); - } - - inline async command ieee154_header_t* IEEE154PacketLayer.getHeader(message_t* msg) - { - return getHeader(msg); - } - - inline async command uint8_t IEEE154PacketLayer.getLength(message_t* msg) - { - return getHeader(msg)->length; - } - - inline async command void IEEE154PacketLayer.setLength(message_t* msg, uint8_t length) - { - getHeader(msg)->length = length; - } - - inline async command uint16_t IEEE154PacketLayer.getFCF(message_t* msg) - { - return getHeader(msg)->fcf; - } - - inline async command void IEEE154PacketLayer.setFCF(message_t* msg, uint16_t fcf) - { - getHeader(msg)->fcf = fcf; - } - - inline async command bool IEEE154PacketLayer.isDataFrame(message_t* msg) - { - return (getHeader(msg)->fcf & IEEE154_DATA_FRAME_MASK) == IEEE154_DATA_FRAME_VALUE; - } - - inline async command void IEEE154PacketLayer.createDataFrame(message_t* msg) - { - getHeader(msg)->fcf = IEEE154_DATA_FRAME_VALUE; - } - - inline async command bool IEEE154PacketLayer.isAckFrame(message_t* msg) - { - return (getHeader(msg)->fcf & IEEE154_ACK_FRAME_MASK) == IEEE154_ACK_FRAME_VALUE; - } - - inline async command void IEEE154PacketLayer.createAckFrame(message_t* msg) - { - ieee154_header_t* header = getHeader(msg); - - header->length = IEEE154_ACK_FRAME_LENGTH; - header->fcf = IEEE154_ACK_FRAME_VALUE; - } - - inline async command void IEEE154PacketLayer.createAckReply(message_t* data, message_t* ack) - { - ieee154_header_t* header = getHeader(ack); - - header->length = IEEE154_ACK_FRAME_LENGTH; - header->fcf = IEEE154_ACK_FRAME_VALUE; - header->dsn = getHeader(data)->dsn; - } - - inline 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; - } - - inline async command bool IEEE154PacketLayer.getAckRequired(message_t* msg) - { - return getHeader(msg)->fcf & (1 << IEEE154_FCF_ACK_REQ); - } - - inline 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); - } - - inline async command bool IEEE154PacketLayer.getFramePending(message_t* msg) - { - return getHeader(msg)->fcf & (1 << IEEE154_FCF_FRAME_PENDING); - } - - inline 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); - } - - inline async command uint8_t IEEE154PacketLayer.getDSN(message_t* msg) - { - return getHeader(msg)->dsn; - } - - inline async command void IEEE154PacketLayer.setDSN(message_t* msg, uint8_t dsn) - { - getHeader(msg)->dsn = dsn; - } - - inline async command uint16_t IEEE154PacketLayer.getDestPan(message_t* msg) - { - return getHeader(msg)->destpan; - } - - inline async command void IEEE154PacketLayer.setDestPan(message_t* msg, uint16_t pan) - { - getHeader(msg)->destpan = pan; - } - - inline async command uint16_t IEEE154PacketLayer.getDestAddr(message_t* msg) - { - return getHeader(msg)->dest; - } - - inline async command void IEEE154PacketLayer.setDestAddr(message_t* msg, uint16_t addr) - { - getHeader(msg)->dest = addr; - } - - inline async command uint16_t IEEE154PacketLayer.getSrcAddr(message_t* msg) - { - return getHeader(msg)->src; - } - - inline async command void IEEE154PacketLayer.setSrcAddr(message_t* msg, uint16_t addr) - { - getHeader(msg)->src = addr; - } - -#ifndef TFRAMES_ENABLED - - inline async command uint8_t IEEE154PacketLayer.get6LowPan(message_t* msg) - { - return getHeader(msg)->network; - } - - inline async command void IEEE154PacketLayer.set6LowPan(message_t* msg, uint8_t network) - { - getHeader(msg)->network = network; - } - -#endif - - inline async command am_id_t IEEE154PacketLayer.getType(message_t* msg) - { - return getHeader(msg)->type; - } - - inline async command void IEEE154PacketLayer.setType(message_t* msg, am_id_t type) - { - getHeader(msg)->type = type; - } - - 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(); - } - - inline async event void ActiveMessageAddress.changed() - { - } - -/*----------------- AMPacket -----------------*/ - - inline command am_addr_t AMPacket.address() - { - return call ActiveMessageAddress.amAddress(); - } - - inline command am_group_t AMPacket.localGroup() - { - // TODO: check if this is correct - return call ActiveMessageAddress.amGroup(); - } - - inline command am_addr_t AMPacket.destination(message_t* msg) - { - return call IEEE154PacketLayer.getDestAddr(msg); - } - - inline command am_addr_t AMPacket.source(message_t* msg) - { - return call IEEE154PacketLayer.getSrcAddr(msg); - } - - inline command void AMPacket.setDestination(message_t* msg, am_addr_t addr) - { - call IEEE154PacketLayer.setDestAddr(msg, addr); - } - - inline command void AMPacket.setSource(message_t* msg, am_addr_t addr) - { - call IEEE154PacketLayer.setSrcAddr(msg, addr); - } - - inline command bool AMPacket.isForMe(message_t* msg) - { - am_addr_t addr = call AMPacket.destination(msg); - return addr == call AMPacket.address() || addr == AM_BROADCAST_ADDR; - } - - inline command am_id_t AMPacket.type(message_t* msg) - { - return call IEEE154PacketLayer.getType(msg); - } - - inline command void AMPacket.setType(message_t* msg, am_id_t type) - { - call IEEE154PacketLayer.setType(msg, type); - } - - inline command am_group_t AMPacket.group(message_t* msg) - { - return call IEEE154PacketLayer.getDestPan(msg); - } - - inline command void AMPacket.setGroup(message_t* msg, am_group_t grp) - { - call IEEE154PacketLayer.setDestPan(msg, grp); - } -} diff --git a/tos/chips/rf2xx/layers/LowPowerListeningConfig.nc b/tos/chips/rf2xx/layers/LowPowerListeningConfig.nc new file mode 100644 index 00000000..c0f2157a --- /dev/null +++ b/tos/chips/rf2xx/layers/LowPowerListeningConfig.nc @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2009, 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 + +interface LowPowerListeningConfig +{ + /** + * Returns a pointer to the low power listening metadata fields in + * the message + */ + async command lpl_metadata_t* metadata(message_t* msg); + + /** + * Clears the low power listening metadata fields in order to disable + * low power listening for the message + */ + async event void clear(message_t* msg); + + /** + * Returns TRUE if an acknowledgement is requested for this message. + */ + async command bool getAckRequired(message_t* msg); +} diff --git a/tos/chips/rf2xx/layers/LowPowerListeningLayerC.nc b/tos/chips/rf2xx/layers/LowPowerListeningLayerC.nc index 0c6898bf..ddb2a38a 100644 --- a/tos/chips/rf2xx/layers/LowPowerListeningLayerC.nc +++ b/tos/chips/rf2xx/layers/LowPowerListeningLayerC.nc @@ -41,8 +41,7 @@ configuration LowPowerListeningLayerC interface Send as SubSend; interface Receive as SubReceive; - interface PacketData as PacketLplMetadata; - interface IEEE154PacketLayer; + interface LowPowerListeningConfig as Config; interface PacketAcknowledgements; } } @@ -59,8 +58,7 @@ implementation SubControl = LowPowerListeningLayerP; SubSend = LowPowerListeningLayerP; SubReceive = LowPowerListeningLayerP; - PacketLplMetadata = LowPowerListeningLayerP; - IEEE154PacketLayer = LowPowerListeningLayerP; + Config = LowPowerListeningLayerP; PacketAcknowledgements = LowPowerListeningLayerP; LowPowerListeningLayerP.Timer -> TimerMilliC; diff --git a/tos/chips/rf2xx/layers/LowPowerListeningLayerP.nc b/tos/chips/rf2xx/layers/LowPowerListeningLayerP.nc index 22619223..4bdd79ee 100644 --- a/tos/chips/rf2xx/layers/LowPowerListeningLayerP.nc +++ b/tos/chips/rf2xx/layers/LowPowerListeningLayerP.nc @@ -41,9 +41,8 @@ module LowPowerListeningLayerP interface Send as SubSend; interface Receive as SubReceive; - interface PacketData as PacketLplMetadata; - interface IEEE154PacketLayer; interface PacketAcknowledgements; + interface LowPowerListeningConfig as Config; interface Timer; } } @@ -336,7 +335,7 @@ implementation if( error != SUCCESS || call LowPowerListening.getRxSleepInterval(msg) == 0 || state == SEND_SUBSEND_DONE_LAST - || (call IEEE154PacketLayer.getAckRequired(msg) && call PacketAcknowledgements.wasAcked(msg)) ) + || (call Config.getAckRequired(msg) && call PacketAcknowledgements.wasAcked(msg)) ) { call Timer.stop(); state = SEND_DONE; @@ -419,12 +418,12 @@ implementation else if( interval > MAX_SLEEP ) interval = MAX_SLEEP; - (call PacketLplMetadata.get(msg))->sleepint = interval; + (call Config.metadata(msg))->sleepint = interval; } command uint16_t LowPowerListening.getRxSleepInterval(message_t *msg) { - uint16_t sleepint = (call PacketLplMetadata.get(msg))->sleepint; + uint16_t sleepint = (call Config.metadata(msg))->sleepint; return sleepint != 0 ? sleepint : sleepInterval; } @@ -441,8 +440,8 @@ implementation call LowPowerListening.getRxSleepInterval(msg)); } - async event void PacketLplMetadata.clear(message_t* msg) + async event void Config.clear(message_t* msg) { - (call PacketLplMetadata.get(msg))->sleepint = 0; + (call Config.metadata(msg))->sleepint = 0; } } diff --git a/tos/chips/rf2xx/layers/IEEE154NetworkLayerC.nc b/tos/chips/rf2xx/layers/LowpanNetworkConfig.nc similarity index 67% rename from tos/chips/rf2xx/layers/IEEE154NetworkLayerC.nc rename to tos/chips/rf2xx/layers/LowpanNetworkConfig.nc index 64cb933b..9159a1e3 100644 --- a/tos/chips/rf2xx/layers/IEEE154NetworkLayerC.nc +++ b/tos/chips/rf2xx/layers/LowpanNetworkConfig.nc @@ -21,33 +21,12 @@ * Author: Miklos Maroti */ -configuration IEEE154NetworkLayerC -{ - provides - { - interface SplitControl; - interface Send; - interface Receive; - } - uses - { - interface SplitControl as SubControl; - interface Send as SubSend; - interface Receive as SubReceive; - } -} +#include -implementation +interface LowpanNetworkConfig { - components IEEE154NetworkLayerP, IEEE154PacketLayerC; - - SplitControl = SubControl; - - Send = IEEE154NetworkLayerP; - Receive = IEEE154NetworkLayerP; - - SubSend = IEEE154NetworkLayerP; - SubReceive = IEEE154NetworkLayerP; - - IEEE154NetworkLayerP.IEEE154PacketLayer -> IEEE154PacketLayerC; + /** + * Returns a pointer to the 6LowPAN header field in the message + */ + command lowpan_header_t* getHeader(message_t* msg); } diff --git a/tos/chips/rf2xx/layers/LowpanNetworkLayer.h b/tos/chips/rf2xx/layers/LowpanNetworkLayer.h new file mode 100644 index 00000000..96111bd7 --- /dev/null +++ b/tos/chips/rf2xx/layers/LowpanNetworkLayer.h @@ -0,0 +1,32 @@ +/* + * 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 __LOWPANNETWORKLAYER_H__ +#define __LOWPANNETWORKLAYER_H__ + +typedef nx_struct lowpan_header_t +{ + nxle_uint8_t network; +} lowpan_header_t; + +#endif//__LOWPANNETWORKLAYER_H__ diff --git a/tos/chips/rf2xx/layers/IEEE154NetworkLayerP.nc b/tos/chips/rf2xx/layers/LowpanNetworkLayerC.nc similarity index 91% rename from tos/chips/rf2xx/layers/IEEE154NetworkLayerP.nc rename to tos/chips/rf2xx/layers/LowpanNetworkLayerC.nc index d5b33bf7..f52c4d89 100644 --- a/tos/chips/rf2xx/layers/IEEE154NetworkLayerP.nc +++ b/tos/chips/rf2xx/layers/LowpanNetworkLayerC.nc @@ -21,12 +21,13 @@ * Author: Miklos Maroti */ -module IEEE154NetworkLayerP +module LowpanNetworkLayerC { provides { interface Send; interface Receive; + interface Receive as NonTinyosReceive[uint8_t network]; } @@ -34,8 +35,7 @@ module IEEE154NetworkLayerP { interface Send as SubSend; interface Receive as SubReceive; - - interface IEEE154PacketLayer; + interface LowpanNetworkConfig as Config; } } @@ -47,7 +47,7 @@ implementation command error_t Send.send(message_t* msg, uint8_t len) { - call IEEE154PacketLayer.set6LowPan(msg, TINYOS_6LOWPAN_NETWORK_ID); + (call Config.getHeader(msg))->network = TINYOS_6LOWPAN_NETWORK_ID; return call SubSend.send(msg, len); } @@ -73,7 +73,7 @@ implementation event message_t *SubReceive.receive(message_t *msg, void *payload, uint8_t len) { - uint8_t network = call IEEE154PacketLayer.get6LowPan(msg); + uint8_t network = (call Config.getHeader(msg))->network; if( network == TINYOS_6LOWPAN_NETWORK_ID ) return signal Receive.receive(msg, payload, len); else diff --git a/tos/chips/rf2xx/rf212/RF212ActiveMessage.h b/tos/chips/rf2xx/rf212/RF212ActiveMessage.h index e13bba98..1f789e85 100644 --- a/tos/chips/rf2xx/rf212/RF212ActiveMessage.h +++ b/tos/chips/rf2xx/rf212/RF212ActiveMessage.h @@ -24,14 +24,23 @@ #ifndef __RF212ACTIVEMESSAGE_H__ #define __RF212ACTIVEMESSAGE_H__ -#include +#include +#include +#include #include #include #include #include #include -typedef ieee154_header_t rf212packet_header_t; +typedef nx_struct rf212packet_header_t +{ + ieee154_header_t ieee154; +#ifndef TFRAMES_ENABLED + lowpan_header_t lowpan; +#endif + activemessage_header_t am; +} rf212packet_header_t; typedef nx_struct rf212packet_footer_t { diff --git a/tos/chips/rf2xx/rf212/RF212ActiveMessageC.nc b/tos/chips/rf2xx/rf212/RF212ActiveMessageC.nc index bd5fe3c0..18ffdf6a 100644 --- a/tos/chips/rf2xx/rf212/RF212ActiveMessageC.nc +++ b/tos/chips/rf2xx/rf212/RF212ActiveMessageC.nc @@ -56,39 +56,43 @@ configuration RF212ActiveMessageC implementation { - components RF212ActiveMessageP, IEEE154PacketLayerC, RadioAlarmC; + components RF212ActiveMessageP, RadioAlarmC; #ifdef RADIO_DEBUG components AssertC; #endif - RF212ActiveMessageP.IEEE154PacketLayer -> IEEE154PacketLayerC; + RF212ActiveMessageP.IEEE154MessageLayer -> IEEE154MessageLayerC; RF212ActiveMessageP.RadioAlarm -> RadioAlarmC.RadioAlarm[unique("RadioAlarm")]; RF212ActiveMessageP.PacketTimeStamp -> TimeStampingLayerC; - Packet = RF212ActiveMessageP; -// -------- ActiveMessage +// -------- Active Message components ActiveMessageLayerC; ActiveMessageLayerC.Config -> RF212ActiveMessageP; - ActiveMessageLayerC.AMPacket -> IEEE154PacketLayerC; - ActiveMessageLayerC.SubSend -> IEEE154NetworkLayerC; - ActiveMessageLayerC.SubReceive -> IEEE154NetworkLayerC; + ActiveMessageLayerC.SubSend -> LowpanNetworkLayerC; + ActiveMessageLayerC.SubReceive -> LowpanNetworkLayerC; AMSend = ActiveMessageLayerC; Receive = ActiveMessageLayerC.Receive; Snoop = ActiveMessageLayerC.Snoop; - AMPacket = IEEE154PacketLayerC; + AMPacket = ActiveMessageLayerC; -// -------- IEEE154Network +// -------- Lowpan Network #ifdef TFRAMES_ENABLED - components new DummyLayerC() as IEEE154NetworkLayerC; + components new DummyLayerC() as LowpanNetworkLayerC; #else - components IEEE154NetworkLayerC; + components LowpanNetworkLayerC; + LowpanNetworkLayerC.Config -> RF212ActiveMessageP; #endif - IEEE154NetworkLayerC.SubSend -> UniqueLayerC; - IEEE154NetworkLayerC.SubReceive -> LowPowerListeningLayerC; + LowpanNetworkLayerC.SubSend -> UniqueLayerC; + LowpanNetworkLayerC.SubReceive -> LowPowerListeningLayerC; + +// -------- IEEE154 Packet + + components IEEE154MessageLayerC; + IEEE154MessageLayerC.Config -> RF212ActiveMessageP; // -------- UniqueLayer Send part (wired twice) @@ -100,8 +104,7 @@ implementation #ifdef LOW_POWER_LISTENING components LowPowerListeningLayerC; - LowPowerListeningLayerC.PacketLplMetadata -> RF212ActiveMessageP; - LowPowerListeningLayerC.IEEE154PacketLayer -> IEEE154PacketLayerC; + LowPowerListeningLayerC.Config -> RF212ActiveMessageP; LowPowerListeningLayerC.PacketAcknowledgements -> SoftwareAckLayerC; #else components LowPowerListeningDummyC as LowPowerListeningLayerC; diff --git a/tos/chips/rf2xx/rf212/RF212ActiveMessageP.nc b/tos/chips/rf2xx/rf212/RF212ActiveMessageP.nc index e9f4cfcb..f304b53c 100644 --- a/tos/chips/rf2xx/rf212/RF212ActiveMessageP.nc +++ b/tos/chips/rf2xx/rf212/RF212ActiveMessageP.nc @@ -37,6 +37,8 @@ module RF212ActiveMessageP interface RandomCollisionConfig; interface SlottedCollisionConfig; interface ActiveMessageConfig; + interface LowpanNetworkConfig; + interface IEEE154MessageConfig; interface DummyConfig; interface Packet; @@ -46,7 +48,7 @@ module RF212ActiveMessageP interface PacketData as PacketTimeStampMetadata; #ifdef LOW_POWER_LISTENING - interface PacketData as PacketLplMetadata; + interface LowPowerListeningConfig; #endif #ifdef PACKET_LINK interface PacketData as PacketLinkMetadata; @@ -55,7 +57,7 @@ module RF212ActiveMessageP uses { - interface IEEE154PacketLayer; + interface IEEE154MessageLayer; interface RadioAlarm; interface PacketTimeStamp; @@ -64,21 +66,31 @@ module RF212ActiveMessageP implementation { + rf212packet_header_t* getHeader(message_t* msg) + { + return (rf212packet_header_t*)(msg->data - sizeof(rf212packet_header_t)); + } + + rf212packet_metadata_t* getMeta(message_t* msg) + { + return (rf212packet_metadata_t*)(msg->metadata); + } + /*----------------- RF212DriverConfig -----------------*/ async command uint8_t RF212DriverConfig.getLength(message_t* msg) { - return call IEEE154PacketLayer.getLength(msg); + return call IEEE154MessageLayer.getLength(msg); } async command void RF212DriverConfig.setLength(message_t* msg, uint8_t len) { - call IEEE154PacketLayer.setLength(msg, len); + call IEEE154MessageLayer.setLength(msg, len); } async command uint8_t* RF212DriverConfig.getPayload(message_t* msg) { - return ((uint8_t*)(call IEEE154PacketLayer.getHeader(msg))) + 1; + return ((uint8_t*)(call IEEE154MessageConfig.getHeader(msg))) + 1; } async command uint8_t RF212DriverConfig.getHeaderLength() @@ -95,39 +107,39 @@ implementation async command bool RF212DriverConfig.requiresRssiCca(message_t* msg) { - return call IEEE154PacketLayer.isDataFrame(msg); + return call IEEE154MessageLayer.isDataFrame(msg); } /*----------------- SoftwareAckConfig -----------------*/ async command bool SoftwareAckConfig.requiresAckWait(message_t* msg) { - return call IEEE154PacketLayer.requiresAckWait(msg); + return call IEEE154MessageLayer.requiresAckWait(msg); } async command bool SoftwareAckConfig.isAckPacket(message_t* msg) { - return call IEEE154PacketLayer.isAckFrame(msg); + return call IEEE154MessageLayer.isAckFrame(msg); } async command bool SoftwareAckConfig.verifyAckPacket(message_t* data, message_t* ack) { - return call IEEE154PacketLayer.verifyAckReply(data, ack); + return call IEEE154MessageLayer.verifyAckReply(data, ack); } async command void SoftwareAckConfig.setAckRequired(message_t* msg, bool ack) { - call IEEE154PacketLayer.setAckRequired(msg, ack); + call IEEE154MessageLayer.setAckRequired(msg, ack); } async command bool SoftwareAckConfig.requiresAckReply(message_t* msg) { - return call IEEE154PacketLayer.requiresAckReply(msg); + return call IEEE154MessageLayer.requiresAckReply(msg); } async command void SoftwareAckConfig.createAckPacket(message_t* data, message_t* ack) { - call IEEE154PacketLayer.createAckReply(data, ack); + call IEEE154MessageLayer.createAckReply(data, ack); } async command uint16_t SoftwareAckConfig.getAckTimeout() @@ -144,17 +156,17 @@ implementation async command uint8_t UniqueConfig.getSequenceNumber(message_t* msg) { - return call IEEE154PacketLayer.getDSN(msg); + return call IEEE154MessageLayer.getDSN(msg); } async command void UniqueConfig.setSequenceNumber(message_t* msg, uint8_t dsn) { - call IEEE154PacketLayer.setDSN(msg, dsn); + call IEEE154MessageLayer.setDSN(msg, dsn); } async command am_addr_t UniqueConfig.getSender(message_t* msg) { - return call IEEE154PacketLayer.getSrcAddr(msg); + return call IEEE154MessageLayer.getSrcAddr(msg); } tasklet_async command void UniqueConfig.reportChannelError() @@ -167,17 +179,52 @@ implementation command error_t ActiveMessageConfig.checkPacket(message_t* msg) { // the user forgot to call clear, we should return EINVAL - if( ! call IEEE154PacketLayer.isDataFrame(msg) ) + if( ! call IEEE154MessageLayer.isDataFrame(msg) ) call Packet.clear(msg); return SUCCESS; } + command activemessage_header_t* ActiveMessageConfig.getHeader(message_t* msg) + { + return &(getHeader(msg)->am); + } + + command am_addr_t ActiveMessageConfig.destination(message_t* msg) + { + return call IEEE154MessageLayer.getDestAddr(msg); + } + + command void ActiveMessageConfig.setDestination(message_t* msg, am_addr_t addr) + { + call IEEE154MessageLayer.setDestAddr(msg, addr); + } + + command am_addr_t ActiveMessageConfig.source(message_t* msg) + { + return call IEEE154MessageLayer.getSrcAddr(msg); + } + + command void ActiveMessageConfig.setSource(message_t* msg, am_addr_t addr) + { + call IEEE154MessageLayer.setSrcAddr(msg, addr); + } + + command am_group_t ActiveMessageConfig.group(message_t* msg) + { + return call IEEE154MessageLayer.getDestPan(msg); + } + + command void ActiveMessageConfig.setGroup(message_t* msg, am_group_t grp) + { + call IEEE154MessageLayer.setDestPan(msg, grp); + } + /*----------------- CsmaConfig -----------------*/ async command bool CsmaConfig.requiresSoftwareCCA(message_t* msg) { - return call IEEE154PacketLayer.isDataFrame(msg); + return call IEEE154MessageLayer.isDataFrame(msg); } /*----------------- TrafficMonitorConfig -----------------*/ @@ -202,13 +249,13 @@ implementation * ack required: 8-16 byte separation, 11 bytes airtime, 5-10 bytes separation */ - uint8_t len = call IEEE154PacketLayer.getLength(msg); - return call IEEE154PacketLayer.getAckRequired(msg) ? len + 6 + 16 + 11 + 10 : len + 6 + 10; + uint8_t len = call IEEE154MessageLayer.getLength(msg); + return call IEEE154MessageLayer.getAckRequired(msg) ? len + 6 + 16 + 11 + 10 : len + 6 + 10; } async command am_addr_t TrafficMonitorConfig.getSender(message_t* msg) { - return call IEEE154PacketLayer.getSrcAddr(msg); + return call IEEE154MessageLayer.getSrcAddr(msg); } tasklet_async command void TrafficMonitorConfig.timerTick() @@ -250,7 +297,7 @@ implementation time = call RadioAlarm.getNow(); // estimated response time (download the message, etc) is 5-8 bytes - if( call IEEE154PacketLayer.requiresAckReply(msg) ) + if( call IEEE154MessageLayer.requiresAckReply(msg) ) time += (uint16_t)(32 * (-5 + 16 + 11 + 5) * RADIO_ALARM_MICROSEC); else time += (uint16_t)(32 * (-5 + 5) * RADIO_ALARM_MICROSEC); @@ -258,7 +305,9 @@ implementation return time; } - tasklet_async event void RadioAlarm.fired() { } + tasklet_async event void RadioAlarm.fired() + { + } /*----------------- SlottedCollisionConfig -----------------*/ @@ -297,13 +346,38 @@ implementation { } -/*----------------- Metadata -----------------*/ +/*----------------- LowpanNetwork -----------------*/ - inline rf212packet_metadata_t* getMeta(message_t* msg) + command lowpan_header_t* LowpanNetworkConfig.getHeader(message_t* msg) { - return (rf212packet_metadata_t*)(msg->metadata); + return &(getHeader(msg)->lowpan); + } + +/*----------------- IEEE154Message -----------------*/ + + async command ieee154_header_t* IEEE154MessageConfig.getHeader(message_t* msg) + { + return &(getHeader(msg)->ieee154); } +/*----------------- LowPowerListening -----------------*/ + +#ifdef LOW_POWER_LISTENING + + async command lpl_metadata_t* LowPowerListeningConfig.metadata(message_t* msg) + { + return &(getMeta(msg)->lpl); + } + + async command bool LowPowerListeningConfig.getAckRequired(message_t* msg) + { + return call IEEE154MessageLayer.getAckRequired(msg); + } + +#endif + +/*----------------- Headers and Metadata -----------------*/ + async command flags_metadata_t* PacketFlagsMetadata.get(message_t* msg) { return &(getMeta(msg)->flags); @@ -319,13 +393,6 @@ implementation return &(getMeta(msg)->timestamp); } -#ifdef LOW_POWER_LISTENING - async command lpl_metadata_t* PacketLplMetadata.get(message_t* msg) - { - return &(getMeta(msg)->lpl); - } -#endif - #ifdef PACKET_LINK async command link_metadata_t* PacketLinkMetadata.get(message_t* msg) { @@ -348,25 +415,25 @@ implementation signal PacketRF212Metadata.clear(msg); signal PacketTimeStampMetadata.clear(msg); #ifdef LOW_POWER_LISTENING - signal PacketLplMetadata.clear(msg); + signal LowPowerListeningConfig.clear(msg); #endif #ifdef PACKET_LINK signal PacketLinkMetadata.clear(msg); #endif - call IEEE154PacketLayer.createDataFrame(msg); + call IEEE154MessageLayer.createDataFrame(msg); } - inline command void Packet.setPayloadLength(message_t* msg, uint8_t len) + command void Packet.setPayloadLength(message_t* msg, uint8_t len) { - call IEEE154PacketLayer.setLength(msg, len + PACKET_LENGTH_INCREASE); + call IEEE154MessageLayer.setLength(msg, len + PACKET_LENGTH_INCREASE); } - inline command uint8_t Packet.payloadLength(message_t* msg) + command uint8_t Packet.payloadLength(message_t* msg) { - return call IEEE154PacketLayer.getLength(msg) - PACKET_LENGTH_INCREASE; + return call IEEE154MessageLayer.getLength(msg) - PACKET_LENGTH_INCREASE; } - inline command uint8_t Packet.maxPayloadLength() + command uint8_t Packet.maxPayloadLength() { return TOSH_DATA_LENGTH; } diff --git a/tos/chips/rf2xx/rf230/RF230ActiveMessage.h b/tos/chips/rf2xx/rf230/RF230ActiveMessage.h index e219b7cf..940da723 100644 --- a/tos/chips/rf2xx/rf230/RF230ActiveMessage.h +++ b/tos/chips/rf2xx/rf230/RF230ActiveMessage.h @@ -24,14 +24,23 @@ #ifndef __RF230ACTIVEMESSAGE_H__ #define __RF230ACTIVEMESSAGE_H__ -#include +#include +#include +#include #include #include #include #include #include -typedef ieee154_header_t rf230packet_header_t; +typedef nx_struct rf230packet_header_t +{ + ieee154_header_t ieee154; +#ifndef TFRAMES_ENABLED + lowpan_header_t lowpan; +#endif + activemessage_header_t am; +} rf230packet_header_t; typedef nx_struct rf230packet_footer_t { diff --git a/tos/chips/rf2xx/rf230/RF230ActiveMessageC.nc b/tos/chips/rf2xx/rf230/RF230ActiveMessageC.nc index b11d0e23..aa5cffe0 100644 --- a/tos/chips/rf2xx/rf230/RF230ActiveMessageC.nc +++ b/tos/chips/rf2xx/rf230/RF230ActiveMessageC.nc @@ -56,39 +56,43 @@ configuration RF230ActiveMessageC implementation { - components RF230ActiveMessageP, IEEE154PacketLayerC, RadioAlarmC; + components RF230ActiveMessageP, RadioAlarmC; #ifdef RADIO_DEBUG components AssertC; #endif - RF230ActiveMessageP.IEEE154PacketLayer -> IEEE154PacketLayerC; + RF230ActiveMessageP.IEEE154MessageLayer -> IEEE154MessageLayerC; RF230ActiveMessageP.RadioAlarm -> RadioAlarmC.RadioAlarm[unique("RadioAlarm")]; RF230ActiveMessageP.PacketTimeStamp -> TimeStampingLayerC; - Packet = RF230ActiveMessageP; -// -------- ActiveMessage +// -------- Active Message components ActiveMessageLayerC; ActiveMessageLayerC.Config -> RF230ActiveMessageP; - ActiveMessageLayerC.AMPacket -> IEEE154PacketLayerC; - ActiveMessageLayerC.SubSend -> IEEE154NetworkLayerC; - ActiveMessageLayerC.SubReceive -> IEEE154NetworkLayerC; + ActiveMessageLayerC.SubSend -> LowpanNetworkLayerC; + ActiveMessageLayerC.SubReceive -> LowpanNetworkLayerC; AMSend = ActiveMessageLayerC; Receive = ActiveMessageLayerC.Receive; Snoop = ActiveMessageLayerC.Snoop; - AMPacket = IEEE154PacketLayerC; + AMPacket = ActiveMessageLayerC; -// -------- IEEE154Network +// -------- Lowpan Network #ifdef TFRAMES_ENABLED - components new DummyLayerC() as IEEE154NetworkLayerC; + components new DummyLayerC() as LowpanNetworkLayerC; #else - components IEEE154NetworkLayerC; + components LowpanNetworkLayerC; + LowpanNetworkLayerC.Config -> RF230ActiveMessageP; #endif - IEEE154NetworkLayerC.SubSend -> UniqueLayerC; - IEEE154NetworkLayerC.SubReceive -> LowPowerListeningLayerC; + LowpanNetworkLayerC.SubSend -> UniqueLayerC; + LowpanNetworkLayerC.SubReceive -> LowPowerListeningLayerC; + +// -------- IEEE154 Packet + + components IEEE154MessageLayerC; + IEEE154MessageLayerC.Config -> RF230ActiveMessageP; // -------- UniqueLayer Send part (wired twice) @@ -100,8 +104,7 @@ implementation #ifdef LOW_POWER_LISTENING components LowPowerListeningLayerC; - LowPowerListeningLayerC.PacketLplMetadata -> RF230ActiveMessageP; - LowPowerListeningLayerC.IEEE154PacketLayer -> IEEE154PacketLayerC; + LowPowerListeningLayerC.Config -> RF230ActiveMessageP; LowPowerListeningLayerC.PacketAcknowledgements -> SoftwareAckLayerC; #else components LowPowerListeningDummyC as LowPowerListeningLayerC; diff --git a/tos/chips/rf2xx/rf230/RF230ActiveMessageP.nc b/tos/chips/rf2xx/rf230/RF230ActiveMessageP.nc index 0842b5af..3f1100a2 100644 --- a/tos/chips/rf2xx/rf230/RF230ActiveMessageP.nc +++ b/tos/chips/rf2xx/rf230/RF230ActiveMessageP.nc @@ -37,6 +37,8 @@ module RF230ActiveMessageP interface RandomCollisionConfig; interface SlottedCollisionConfig; interface ActiveMessageConfig; + interface LowpanNetworkConfig; + interface IEEE154MessageConfig; interface DummyConfig; interface Packet; @@ -46,7 +48,7 @@ module RF230ActiveMessageP interface PacketData as PacketTimeStampMetadata; #ifdef LOW_POWER_LISTENING - interface PacketData as PacketLplMetadata; + interface LowPowerListeningConfig; #endif #ifdef PACKET_LINK interface PacketData as PacketLinkMetadata; @@ -55,7 +57,7 @@ module RF230ActiveMessageP uses { - interface IEEE154PacketLayer; + interface IEEE154MessageLayer; interface RadioAlarm; interface PacketTimeStamp; @@ -64,21 +66,31 @@ module RF230ActiveMessageP implementation { + rf230packet_header_t* getHeader(message_t* msg) + { + return (rf230packet_header_t*)(msg->data - sizeof(rf230packet_header_t)); + } + + rf230packet_metadata_t* getMeta(message_t* msg) + { + return (rf230packet_metadata_t*)(msg->metadata); + } + /*----------------- RF230DriverConfig -----------------*/ async command uint8_t RF230DriverConfig.getLength(message_t* msg) { - return call IEEE154PacketLayer.getLength(msg); + return call IEEE154MessageLayer.getLength(msg); } async command void RF230DriverConfig.setLength(message_t* msg, uint8_t len) { - call IEEE154PacketLayer.setLength(msg, len); + call IEEE154MessageLayer.setLength(msg, len); } async command uint8_t* RF230DriverConfig.getPayload(message_t* msg) { - return ((uint8_t*)(call IEEE154PacketLayer.getHeader(msg))) + 1; + return ((uint8_t*)(call IEEE154MessageConfig.getHeader(msg))) + 1; } async command uint8_t RF230DriverConfig.getHeaderLength() @@ -95,39 +107,39 @@ implementation async command bool RF230DriverConfig.requiresRssiCca(message_t* msg) { - return call IEEE154PacketLayer.isDataFrame(msg); + return call IEEE154MessageLayer.isDataFrame(msg); } /*----------------- SoftwareAckConfig -----------------*/ async command bool SoftwareAckConfig.requiresAckWait(message_t* msg) { - return call IEEE154PacketLayer.requiresAckWait(msg); + return call IEEE154MessageLayer.requiresAckWait(msg); } async command bool SoftwareAckConfig.isAckPacket(message_t* msg) { - return call IEEE154PacketLayer.isAckFrame(msg); + return call IEEE154MessageLayer.isAckFrame(msg); } async command bool SoftwareAckConfig.verifyAckPacket(message_t* data, message_t* ack) { - return call IEEE154PacketLayer.verifyAckReply(data, ack); + return call IEEE154MessageLayer.verifyAckReply(data, ack); } async command void SoftwareAckConfig.setAckRequired(message_t* msg, bool ack) { - call IEEE154PacketLayer.setAckRequired(msg, ack); + call IEEE154MessageLayer.setAckRequired(msg, ack); } async command bool SoftwareAckConfig.requiresAckReply(message_t* msg) { - return call IEEE154PacketLayer.requiresAckReply(msg); + return call IEEE154MessageLayer.requiresAckReply(msg); } async command void SoftwareAckConfig.createAckPacket(message_t* data, message_t* ack) { - call IEEE154PacketLayer.createAckReply(data, ack); + call IEEE154MessageLayer.createAckReply(data, ack); } async command uint16_t SoftwareAckConfig.getAckTimeout() @@ -144,17 +156,17 @@ implementation async command uint8_t UniqueConfig.getSequenceNumber(message_t* msg) { - return call IEEE154PacketLayer.getDSN(msg); + return call IEEE154MessageLayer.getDSN(msg); } async command void UniqueConfig.setSequenceNumber(message_t* msg, uint8_t dsn) { - call IEEE154PacketLayer.setDSN(msg, dsn); + call IEEE154MessageLayer.setDSN(msg, dsn); } async command am_addr_t UniqueConfig.getSender(message_t* msg) { - return call IEEE154PacketLayer.getSrcAddr(msg); + return call IEEE154MessageLayer.getSrcAddr(msg); } tasklet_async command void UniqueConfig.reportChannelError() @@ -167,17 +179,52 @@ implementation command error_t ActiveMessageConfig.checkPacket(message_t* msg) { // the user forgot to call clear, we should return EINVAL - if( ! call IEEE154PacketLayer.isDataFrame(msg) ) + if( ! call IEEE154MessageLayer.isDataFrame(msg) ) call Packet.clear(msg); return SUCCESS; } + command activemessage_header_t* ActiveMessageConfig.getHeader(message_t* msg) + { + return &(getHeader(msg)->am); + } + + command am_addr_t ActiveMessageConfig.destination(message_t* msg) + { + return call IEEE154MessageLayer.getDestAddr(msg); + } + + command void ActiveMessageConfig.setDestination(message_t* msg, am_addr_t addr) + { + call IEEE154MessageLayer.setDestAddr(msg, addr); + } + + command am_addr_t ActiveMessageConfig.source(message_t* msg) + { + return call IEEE154MessageLayer.getSrcAddr(msg); + } + + command void ActiveMessageConfig.setSource(message_t* msg, am_addr_t addr) + { + call IEEE154MessageLayer.setSrcAddr(msg, addr); + } + + command am_group_t ActiveMessageConfig.group(message_t* msg) + { + return call IEEE154MessageLayer.getDestPan(msg); + } + + command void ActiveMessageConfig.setGroup(message_t* msg, am_group_t grp) + { + call IEEE154MessageLayer.setDestPan(msg, grp); + } + /*----------------- CsmaConfig -----------------*/ async command bool CsmaConfig.requiresSoftwareCCA(message_t* msg) { - return call IEEE154PacketLayer.isDataFrame(msg); + return call IEEE154MessageLayer.isDataFrame(msg); } /*----------------- TrafficMonitorConfig -----------------*/ @@ -202,13 +249,13 @@ implementation * ack required: 8-16 byte separation, 11 bytes airtime, 5-10 bytes separation */ - uint8_t len = call IEEE154PacketLayer.getLength(msg); - return call IEEE154PacketLayer.getAckRequired(msg) ? len + 6 + 16 + 11 + 10 : len + 6 + 10; + uint8_t len = call IEEE154MessageLayer.getLength(msg); + return call IEEE154MessageLayer.getAckRequired(msg) ? len + 6 + 16 + 11 + 10 : len + 6 + 10; } async command am_addr_t TrafficMonitorConfig.getSender(message_t* msg) { - return call IEEE154PacketLayer.getSrcAddr(msg); + return call IEEE154MessageLayer.getSrcAddr(msg); } tasklet_async command void TrafficMonitorConfig.timerTick() @@ -250,7 +297,7 @@ implementation time = call RadioAlarm.getNow(); // estimated response time (download the message, etc) is 5-8 bytes - if( call IEEE154PacketLayer.requiresAckReply(msg) ) + if( call IEEE154MessageLayer.requiresAckReply(msg) ) time += (uint16_t)(32 * (-5 + 16 + 11 + 5) * RADIO_ALARM_MICROSEC); else time += (uint16_t)(32 * (-5 + 5) * RADIO_ALARM_MICROSEC); @@ -258,7 +305,9 @@ implementation return time; } - tasklet_async event void RadioAlarm.fired() { } + tasklet_async event void RadioAlarm.fired() + { + } /*----------------- SlottedCollisionConfig -----------------*/ @@ -297,13 +346,38 @@ implementation { } -/*----------------- Metadata -----------------*/ +/*----------------- LowpanNetwork -----------------*/ - inline rf230packet_metadata_t* getMeta(message_t* msg) + command lowpan_header_t* LowpanNetworkConfig.getHeader(message_t* msg) { - return (rf230packet_metadata_t*)(msg->metadata); + return &(getHeader(msg)->lowpan); + } + +/*----------------- IEEE154Message -----------------*/ + + async command ieee154_header_t* IEEE154MessageConfig.getHeader(message_t* msg) + { + return &(getHeader(msg)->ieee154); } +/*----------------- LowPowerListening -----------------*/ + +#ifdef LOW_POWER_LISTENING + + async command lpl_metadata_t* LowPowerListeningConfig.metadata(message_t* msg) + { + return &(getMeta(msg)->lpl); + } + + async command bool LowPowerListeningConfig.getAckRequired(message_t* msg) + { + return call IEEE154MessageLayer.getAckRequired(msg); + } + +#endif + +/*----------------- Headers and Metadata -----------------*/ + async command flags_metadata_t* PacketFlagsMetadata.get(message_t* msg) { return &(getMeta(msg)->flags); @@ -319,13 +393,6 @@ implementation return &(getMeta(msg)->timestamp); } -#ifdef LOW_POWER_LISTENING - async command lpl_metadata_t* PacketLplMetadata.get(message_t* msg) - { - return &(getMeta(msg)->lpl); - } -#endif - #ifdef PACKET_LINK async command link_metadata_t* PacketLinkMetadata.get(message_t* msg) { @@ -348,25 +415,25 @@ implementation signal PacketRF230Metadata.clear(msg); signal PacketTimeStampMetadata.clear(msg); #ifdef LOW_POWER_LISTENING - signal PacketLplMetadata.clear(msg); + signal LowPowerListeningConfig.clear(msg); #endif #ifdef PACKET_LINK signal PacketLinkMetadata.clear(msg); #endif - call IEEE154PacketLayer.createDataFrame(msg); + call IEEE154MessageLayer.createDataFrame(msg); } - inline command void Packet.setPayloadLength(message_t* msg, uint8_t len) + command void Packet.setPayloadLength(message_t* msg, uint8_t len) { - call IEEE154PacketLayer.setLength(msg, len + PACKET_LENGTH_INCREASE); + call IEEE154MessageLayer.setLength(msg, len + PACKET_LENGTH_INCREASE); } - inline command uint8_t Packet.payloadLength(message_t* msg) + command uint8_t Packet.payloadLength(message_t* msg) { - return call IEEE154PacketLayer.getLength(msg) - PACKET_LENGTH_INCREASE; + return call IEEE154MessageLayer.getLength(msg) - PACKET_LENGTH_INCREASE; } - inline command uint8_t Packet.maxPayloadLength() + command uint8_t Packet.maxPayloadLength() { return TOSH_DATA_LENGTH; } diff --git a/tos/chips/rf2xx/util/IEEE802154.h b/tos/chips/rf2xx/util/IEEE802154.h new file mode 100644 index 00000000..028bdb65 --- /dev/null +++ b/tos/chips/rf2xx/util/IEEE802154.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2005-2006 Arch Rock Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * - 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. + * - Neither the name of the Arch Rock Corporation 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 COPYRIGHT HOLDERS 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 + * ARCHED ROCK OR ITS 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 + * + * @author Jonathan Hui + * @version $Revision$ $Date$ + */ + +#ifndef __IEEE802154_H__ +#define __IEEE802154_H__ + +/* + * Define an address representation. + * Only short addresses are currently used in this stack. + */ +typedef uint16_t ieee154_panid_t; +typedef uint16_t ieee154_saddr_t; + +enum { + IEEE154_BROADCAST_ADDR = 0xffff, +}; + +#if 0 +// some ideas of how to represent long addresses +typedef enum { + IEEE154_SHORT_ADDR, + IEEE154_LONG_ADDR, +} ieee154_atype_t; + +typedef union { + uint8_t u_addr[8]; + uint16_t u_addr16[4]; + uint32_t u_addr32[2]; +} ieee154_laddr_t; + +typedef struct { + ieee154_atype_t type; + union { + ieee154_saddr_t s_addr; + ieee154_laddr_t l_addr; + } addr; +#define addr addr.l_addr.u_addr +#define addr16 addr.l_addr.u_addr16 +#define addr32 addr.l_addr.u_addr32 +} ieee154_addr_t; +#endif + +#endif diff --git a/tos/chips/rf2xx/util/Ieee154Packet.nc b/tos/chips/rf2xx/util/Ieee154Packet.nc new file mode 100644 index 00000000..7b9352f6 --- /dev/null +++ b/tos/chips/rf2xx/util/Ieee154Packet.nc @@ -0,0 +1,44 @@ +/* + * "Copyright (c) 2008 The Regents of the University of California. + * 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 UNIVERSITY OF CALIFORNIA 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 UNIVERSITY OF + * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF CALIFORNIA 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 UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + */ + +#include + +interface Ieee154Packet { + + command ieee154_saddr_t address(); + + command ieee154_saddr_t destination(message_t* msg); + + command ieee154_saddr_t source(message_t* msg); + + command void setDestination(message_t* msg, ieee154_saddr_t addr); + + command void setSource(message_t* msg, ieee154_saddr_t addr); + + command bool isForMe(message_t* msg); + + command ieee154_panid_t pan(message_t* msg); + + command void setPan(message_t* msg, ieee154_panid_t grp); + + command ieee154_panid_t localPan(); +} diff --git a/tos/chips/rf2xx/util/Ieee154Send.nc b/tos/chips/rf2xx/util/Ieee154Send.nc new file mode 100644 index 00000000..3728c72b --- /dev/null +++ b/tos/chips/rf2xx/util/Ieee154Send.nc @@ -0,0 +1,108 @@ +/* + * "Copyright (c) 2008 The Regents of the University of California. + * 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 UNIVERSITY OF CALIFORNIA 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 UNIVERSITY OF + * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF CALIFORNIA 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 UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + */ + +#include +#include +#include + +/* + * + * The only change from the AMSend interface is that instead of + * sending to an AMID, we now send to a ieee154_saddr_t. + * + */ + +interface Ieee154Send { + + /** + * Send a packet with a data payload of len to address + * addr. To determine the maximum available size, use the + * Packet interface of the component providing AMSend. If send + * returns SUCCESS, then the component will signal the sendDone + * event in the future; if send returns an error, it will not + * signal the event. Note that a component may accept a send + * request which it later finds it cannot satisfy; in this case, it + * will signal sendDone with error code. + * + * @param addr address to which to send the packet + * @param msg the packet + * @param len the length of the data in the packet payload + * @return SUCCESS if the request to send succeeded and a + * sendDone will be signaled later, EBUSY if the + * abstraction cannot send now but will be able to + * later, or FAIL if the communication layer is not + * in a state that can send (e.g., off). + * @see sendDone + */ + command error_t send(ieee154_saddr_t addr, message_t* msg, uint8_t len); + + /** + * Cancel a requested transmission. Returns SUCCESS if the + * transmission was canceled properly (not sent in its + * entirety). Note that the component may not know + * if the send was successfully canceled, if the radio is + * handling much of the logic; in this case, a component + * should be conservative and return an appropriate error code. + * A successful call to cancel must always result in a + * sendFailed event, and never a sendSucceeded event. + * + * @param msg the packet whose transmission should be cancelled. + * @return SUCCESS if the transmission was cancelled, FAIL otherwise. + * @see sendDone + */ + command error_t cancel(message_t* msg); + + /** + * Signaled in response to an accepted send request. msg is + * the message buffer sent, and error indicates whether + * the send was successful. + * + * @param msg the packet which was submitted as a send request + * @param error SUCCESS if it was sent successfully, FAIL if it was not, + * ECANCEL if it was cancelled + * @see send + * @see cancel + */ + event void sendDone(message_t* msg, error_t error); + + + /** + * Return the maximum payload length that this communication layer + * can provide. This command behaves identically to + * Packet.maxPayloadLength and is included in this + * interface as a convenience. + * + * @return the maximum payload length + */ + command uint8_t maxPayloadLength(); + + /** + * Return a pointer to a protocol's payload region in a packet. + * This command behaves identically to Packet.getPayload + * (minus the length parameter) and is included in this interface + * as a convenience. + * + * @param msg the packet + * @return the payload of the packet + */ + command void* getPayload(message_t* msg, uint8_t len); +} -- 2.39.2