--- /dev/null
+README for TestAssociate
+Author/Contact: tinyos-help@millennium.berkeley.edu
+
+Description:
+
+In this application one node takes the role of a PAN coordinator in a
+beacon-enabled 802.15.4 PAN; it transmits periodic beacons and waits for
+devices to request association to its PAN. Whenever a device tries to
+associate, the PAN coordinator allows association and assigns to the device a
+unique short address (starting from zero, incremented for every device
+requesting association).
+
+A second node acts as a device; it first scans the pre-defined channel for
+beacons from the coordinator and once it finds a beacon it tries to associate
+to the PAN and synchronize to and track all future beacons. A short time after
+association the device then disassociates from the PAN.
+
+The third LED (Telos: blue) is toggled whenever the coordinator has transmitted
+a beacon or whenever a device has received a beacon. On the coordinator the
+second LED (Telos: green) is switched on whenever an association request was
+successful and it is switched off, whenever a disassociation request was
+received. On a device the second LED is switched on while the device is
+associated to the PAN, i.e. it is switched off after disassociation. The first
+LED (Telos: red) is used for debugging, it denotes an error in the protocol
+stack and should never be on.
+
+Tools: NONE
+
+Usage:
+
+1. Install the coordinator:
+
+ $ cd coordinator; make <platform> install
+
+2. Install one (or more) devices:
+
+ $ cd device; make <platform> install
+
+You can change some of the configuration parameters in app_profile.h
+
+Known bugs/limitations:
+
+- Many TinyOS 2 platforms do not have a clock that satisfies the
+ precision/accuracy requirements of the IEEE 802.15.4 standard (e.g.
+ 62.500 Hz, +-40 ppm in the 2.4 GHz band); in this case the MAC timing
+ is not standard compliant
+
+$Id$o
+
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * 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 Technische Universitaet Berlin 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 COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#ifndef __APP_PROFILE_H
+#define __APP_PROFILE_H
+
+enum {
+ RADIO_CHANNEL = 26,
+ PAN_ID = 0x1238,
+ COORDINATOR_ADDRESS = 0x9182,
+ BEACON_ORDER = 6,
+ SUPERFRAME_ORDER = 6,
+};
+
+#endif
--- /dev/null
+COMPONENT=TestAssociateAppC
+CFLAGS += -I$(shell pwd)/..
+include ../../../Makefile.include
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * 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 Technische Universitaet Berlin 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 COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+configuration TestAssociateAppC
+{
+} implementation {
+ components MainC, LedsC, Ieee802154BeaconEnabledC as MAC;
+ components TestCoordC as App;
+
+ MainC.Boot <- App;
+ App.Leds -> LedsC;
+ App.MLME_RESET -> MAC;
+ App.MLME_SET -> MAC;
+ App.MLME_GET -> MAC;
+
+ App.MLME_START -> MAC;
+ App.MLME_ASSOCIATE -> MAC;
+ App.MLME_DISASSOCIATE -> MAC;
+ App.MLME_COMM_STATUS -> MAC;
+ App.Frame -> MAC;
+ App.IEEE154TxBeaconPayload -> MAC;
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * 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 Technische Universitaet Berlin 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 COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#include "TKN154.h"
+#include "app_profile.h"
+module TestCoordC
+{
+ uses {
+ interface Boot;
+ interface MLME_RESET;
+ interface MLME_START;
+ interface MLME_ASSOCIATE;
+ interface MLME_DISASSOCIATE;
+ interface MLME_COMM_STATUS;
+ interface MLME_SET;
+ interface MLME_GET;
+ interface IEEE154Frame as Frame;
+ interface IEEE154TxBeaconPayload;
+ interface Leds;
+ }
+} implementation {
+
+ ieee154_address_t m_lastDevice;
+ uint16_t m_shortAddress;
+
+ event void Boot.booted() {
+ call MLME_RESET.request(TRUE);
+ }
+
+ event void MLME_RESET.confirm(ieee154_status_t status)
+ {
+ if (status != IEEE154_SUCCESS)
+ return;
+ call MLME_SET.macShortAddress(COORDINATOR_ADDRESS);
+ call MLME_SET.macAssociationPermit(TRUE);
+ call MLME_START.request(
+ PAN_ID, // PANId
+ RADIO_CHANNEL, // LogicalChannel
+ 0, // ChannelPage,
+ 0, // StartTime,
+ BEACON_ORDER, // BeaconOrder
+ SUPERFRAME_ORDER, // SuperframeOrder
+ TRUE, // PANCoordinator
+ FALSE, // BatteryLifeExtension
+ FALSE, // CoordRealignment
+ 0, // no realignment security
+ 0 // no beacon security
+ );
+ }
+
+ event void MLME_START.confirm(ieee154_status_t status) { }
+
+ event void MLME_ASSOCIATE.indication (
+ uint64_t DeviceAddress,
+ ieee154_CapabilityInformation_t CapabilityInformation,
+ ieee154_security_t *security
+ )
+ {
+ call MLME_ASSOCIATE.response(DeviceAddress, m_shortAddress++, IEEE154_ASSOCIATION_SUCCESSFUL, 0);
+ }
+
+ event void MLME_DISASSOCIATE.indication (
+ uint64_t DeviceAddress,
+ ieee154_disassociation_reason_t DisassociateReason,
+ ieee154_security_t *security
+ )
+ {
+ call Leds.led1Off();
+ }
+
+
+ event void MLME_COMM_STATUS.indication (
+ uint16_t PANId,
+ uint8_t SrcAddrMode,
+ ieee154_address_t SrcAddr,
+ uint8_t DstAddrMode,
+ ieee154_address_t DstAddr,
+ ieee154_status_t status,
+ ieee154_security_t *security
+ )
+ {
+ if (status == IEEE154_SUCCESS){
+ // association was successful
+ call Leds.led1On();
+ m_lastDevice.extendedAddress = DstAddr.extendedAddress;
+ } else {
+ call Leds.led1Off();
+ }
+ }
+
+ event void MLME_DISASSOCIATE.confirm (
+ ieee154_status_t status,
+ uint8_t DeviceAddrMode,
+ uint16_t DevicePANID,
+ ieee154_address_t DeviceAddress
+ ){}
+
+ event void MLME_ASSOCIATE.confirm (
+ uint16_t AssocShortAddress,
+ uint8_t status,
+ ieee154_security_t *security
+ ){}
+
+ event void IEEE154TxBeaconPayload.aboutToTransmit() { }
+
+ event void IEEE154TxBeaconPayload.setBeaconPayloadDone(void *beaconPayload, uint8_t length) { }
+
+ event void IEEE154TxBeaconPayload.modifyBeaconPayloadDone(uint8_t offset, void *buffer, uint8_t bufferLength) { }
+
+ event void IEEE154TxBeaconPayload.beaconTransmitted()
+ {
+ ieee154_macBSN_t beaconSequenceNumber = call MLME_GET.macBSN();
+ if (beaconSequenceNumber & 1)
+ call Leds.led2On();
+ else
+ call Leds.led2Off();
+ }
+}
--- /dev/null
+COMPONENT=TestAssociateAppC
+CFLAGS += -I$(shell pwd)/..
+include ../../../Makefile.include
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * 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 Technische Universitaet Berlin 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 COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+configuration TestAssociateAppC
+{
+} implementation {
+ components MainC, LedsC, Ieee802154BeaconEnabledC as MAC,
+ new Timer62500C() as Timer;
+ components TestDeviceC as App;
+
+ MainC.Boot <- App;
+ App.Leds -> LedsC;
+ App.MLME_RESET -> MAC;
+ App.MLME_SET -> MAC;
+ App.MLME_GET -> MAC;
+ App.DisassociateTimer -> Timer;
+ App.MLME_SCAN -> MAC;
+ App.MLME_SYNC -> MAC;
+ App.MLME_BEACON_NOTIFY -> MAC;
+ App.MLME_SYNC_LOSS -> MAC;
+ App.MLME_ASSOCIATE -> MAC;
+ App.MLME_DISASSOCIATE -> MAC;
+ App.MLME_COMM_STATUS -> MAC;
+ App.BeaconFrame -> MAC;
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * 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 Technische Universitaet Berlin 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 COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+#include "TKN154.h"
+#include "app_profile.h"
+module TestDeviceC
+{
+ uses {
+ interface Boot;
+ interface MLME_RESET;
+ interface MLME_SET;
+ interface MLME_GET;
+ interface MLME_SCAN;
+ interface MLME_SYNC;
+ interface MLME_ASSOCIATE;
+ interface MLME_DISASSOCIATE;
+ interface MLME_COMM_STATUS;
+ interface MLME_BEACON_NOTIFY;
+ interface MLME_SYNC_LOSS;
+ interface Leds;
+ interface IEEE154BeaconFrame as BeaconFrame;
+ interface Timer<T62500hz> as DisassociateTimer;
+ }
+} implementation {
+
+ ieee154_CapabilityInformation_t m_capabilityInformation;
+ ieee154_PANDescriptor_t m_PANDescriptor;
+ bool m_isPANDescriptorValid;
+ void startApp();
+
+ event void Boot.booted() {
+ m_capabilityInformation.AlternatePANCoordinator = 0;
+ m_capabilityInformation.DeviceType = 0;
+ m_capabilityInformation.PowerSource = 0;
+ m_capabilityInformation.ReceiverOnWhenIdle = 0;
+ m_capabilityInformation.Reserved = 0;
+ m_capabilityInformation.SecurityCapability = 0;
+ m_capabilityInformation.AllocateAddress = 1;
+ call MLME_RESET.request(TRUE);
+ }
+
+ event void MLME_RESET.confirm(ieee154_status_t status)
+ {
+ if (status == IEEE154_SUCCESS)
+ startApp();
+ }
+
+ void startApp()
+ {
+ ieee154_phyChannelsSupported_t channel;
+ uint8_t scanDuration = BEACON_ORDER;
+
+ m_isPANDescriptorValid = FALSE;
+
+ // scan only one channel
+ channel = ((uint32_t) 1) << RADIO_CHANNEL;
+
+ // we want all received beacons to be signalled
+ // through the MLME_BEACON_NOTIFY interface, i.e.
+ // we set the macAutoRequest attribute to FALSE
+ call MLME_SET.macAutoRequest(FALSE);
+ m_isPANDescriptorValid = FALSE;
+ call MLME_SCAN.request (
+ PASSIVE_SCAN, // ScanType
+ channel, // ScanChannels
+ scanDuration, // ScanDuration
+ 0x00, // ChannelPage
+ 0, // EnergyDetectListNumEntries
+ NULL, // EnergyDetectList
+ 0, // PANDescriptorListNumEntries
+ NULL, // PANDescriptorList
+ NULL // security
+ );
+ }
+
+ event message_t* MLME_BEACON_NOTIFY.indication (message_t* frame)
+ {
+ // received a beacon frame
+ ieee154_phyCurrentPage_t page = call MLME_GET.phyCurrentPage();
+ ieee154_macBSN_t beaconSequenceNumber = call BeaconFrame.getBSN(frame);
+
+ if (beaconSequenceNumber & 1)
+ call Leds.led2On();
+ else
+ call Leds.led2Off();
+ if (!m_isPANDescriptorValid && call BeaconFrame.parsePANDescriptor(
+ frame, RADIO_CHANNEL, page, &m_PANDescriptor) == SUCCESS){
+ // let's see if the beacon is from the coordinator we expect...
+ if (m_PANDescriptor.CoordAddrMode == ADDR_MODE_SHORT_ADDRESS &&
+ m_PANDescriptor.CoordPANId == PAN_ID &&
+ m_PANDescriptor.CoordAddress.shortAddress == COORDINATOR_ADDRESS){
+ // yes - wait until SCAN is finished, then syncronize to beacons
+ m_isPANDescriptorValid = TRUE;
+ }
+ }
+ return frame;
+ }
+
+ event void MLME_SCAN.confirm (
+ ieee154_status_t status,
+ uint8_t ScanType,
+ uint8_t ChannelPage,
+ uint32_t UnscannedChannels,
+ uint8_t EnergyDetectListNumEntries,
+ int8_t* EnergyDetectList,
+ uint8_t PANDescriptorListNumEntries,
+ ieee154_PANDescriptor_t* PANDescriptorList
+ )
+ {
+ if (m_isPANDescriptorValid){
+ call MLME_SET.macPANId(m_PANDescriptor.CoordPANId);
+ call MLME_SET.macCoordShortAddress(m_PANDescriptor.CoordAddress.shortAddress);
+ call MLME_SYNC.request(m_PANDescriptor.LogicalChannel, m_PANDescriptor.ChannelPage, TRUE);
+ call MLME_ASSOCIATE.request(
+ m_PANDescriptor.LogicalChannel,
+ m_PANDescriptor.ChannelPage,
+ m_PANDescriptor.CoordAddrMode,
+ m_PANDescriptor.CoordPANId,
+ m_PANDescriptor.CoordAddress,
+ m_capabilityInformation,
+ NULL // security
+ );
+ } else
+ startApp();
+ }
+
+ event void MLME_ASSOCIATE.confirm (
+ uint16_t AssocShortAddress,
+ uint8_t status,
+ ieee154_security_t *security
+ )
+ {
+ if ( status == IEEE154_SUCCESS ){
+ // we are now associated - set a timer for disassociation
+ call Leds.led1On();
+ call DisassociateTimer.startOneShot(312500U);
+ } else {
+ call MLME_ASSOCIATE.request(
+ m_PANDescriptor.LogicalChannel,
+ m_PANDescriptor.ChannelPage,
+ m_PANDescriptor.CoordAddrMode,
+ m_PANDescriptor.CoordPANId,
+ m_PANDescriptor.CoordAddress,
+ m_capabilityInformation,
+ NULL // security
+ );
+ }
+ }
+
+ event void DisassociateTimer.fired()
+ {
+ if (call MLME_DISASSOCIATE.request (
+ m_PANDescriptor.CoordAddrMode,
+ m_PANDescriptor.CoordPANId,
+ m_PANDescriptor.CoordAddress,
+ IEEE154_DEVICE_WISHES_TO_LEAVE,
+ FALSE,
+ NULL
+ ) != IEEE154_SUCCESS)
+ call DisassociateTimer.startOneShot(312500U);
+ }
+
+ event void MLME_DISASSOCIATE.confirm (
+ ieee154_status_t status,
+ uint8_t DeviceAddrMode,
+ uint16_t DevicePANID,
+ ieee154_address_t DeviceAddress
+ )
+ {
+ if (status == IEEE154_SUCCESS){
+ call Leds.led1Off();
+ } else {
+ call DisassociateTimer.startOneShot(312500U);
+ }
+ }
+
+ event void MLME_ASSOCIATE.indication (
+ uint64_t DeviceAddress,
+ ieee154_CapabilityInformation_t CapabilityInformation,
+ ieee154_security_t *security
+ ){}
+
+ event void MLME_SYNC_LOSS.indication(
+ ieee154_status_t lossReason,
+ uint16_t PANId,
+ uint8_t LogicalChannel,
+ uint8_t ChannelPage,
+ ieee154_security_t *security)
+ {
+ startApp();
+ }
+
+ event void MLME_DISASSOCIATE.indication (
+ uint64_t DeviceAddress,
+ ieee154_disassociation_reason_t DisassociateReason,
+ ieee154_security_t *security
+ ){}
+
+
+ event void MLME_COMM_STATUS.indication (
+ uint16_t PANId,
+ uint8_t SrcAddrMode,
+ ieee154_address_t SrcAddr,
+ uint8_t DstAddrMode,
+ ieee154_address_t DstAddr,
+ ieee154_status_t status,
+ ieee154_security_t *security
+ )
+ {
+ }
+}
--- /dev/null
+README for TestData
+Author/Contact: tinyos-help@millennium.berkeley.edu
+
+Description:
+
+In this application one node takes the role of a PAN coordinator in a
+beacon-enabled 802.15.4 PAN; it transmits periodic beacons and waits for
+incoming DATA frames. A second node acts as a device; it first scans the
+pre-defined channel for beacons from the coordinator and once it finds a beacon
+it tries to synchronize to and track all future beacons. It then starts to
+transmit DATA frames to the coordinator as fast as possible (direct
+transmission in the contention access period, CAP).
+
+The third LED (Telos: blue) is toggled whenever the coordinator has transmitted
+a beacon or whenever a device has received a beacon. On the coordinator the
+second LED (Telos: green) is toggled for every 20 received DATA frames. On a
+device the second LED is toggled for every 20 transmitted (and acknowledged)
+DATA frames. The first LED (Telos: red) is used for debugging, it denotes an
+error in the protocol stack and should never be on.
+
+Tools: NONE
+
+Usage:
+
+1. Install the coordinator:
+
+ $ cd coordinator; make <platform> install
+
+2. Install one or more devices
+
+ $ cd device; make <platform> install,X
+
+ where X is a pre-assigned short address and should be different
+ for every device.
+
+You can change some of the configuration parameters in app_profile.h
+
+Known bugs/limitations:
+
+- Many TinyOS 2 platforms do not have a clock that satisfies the
+ precision/accuracy requirements of the IEEE 802.15.4 standard (e.g.
+ 62.500 Hz, +-40 ppm in the 2.4 GHz band); in this case the MAC timing
+ is not standard compliant
+
+$Id$o
+
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * 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 Technische Universitaet Berlin 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 COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#ifndef __APP_PROFILE_H
+#define __APP_PROFILE_H
+
+enum {
+ RADIO_CHANNEL = 26,
+ PAN_ID = 0x8172,
+ COORDINATOR_ADDRESS = 0x4331,
+ BEACON_ORDER = 5,
+ SUPERFRAME_ORDER = 5,
+};
+//#define IEEE154_DEFAULT_TRANSMITPOWER_dBm -25
+
+#endif
--- /dev/null
+COMPONENT=TestDataAppC
+CFLAGS += -I$(shell pwd)/..
+include ../../../Makefile.include
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * 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 Technische Universitaet Berlin 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 COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#include "TKN154.h"
+#include "app_profile.h"
+module TestCoordReceiverC
+{
+ uses {
+ interface Boot;
+ interface MCPS_DATA;
+ interface MLME_RESET;
+ interface MLME_START;
+ interface MLME_SET;
+ interface MLME_GET;
+ interface IEEE154Frame as Frame;
+ interface IEEE154TxBeaconPayload;
+ interface Leds;
+ }
+} implementation {
+
+ bool m_ledCount;
+
+ event void Boot.booted() {
+ call MLME_RESET.request(TRUE);
+ }
+
+ event void MLME_RESET.confirm(ieee154_status_t status)
+ {
+ if (status != IEEE154_SUCCESS)
+ return;
+ call MLME_SET.macShortAddress(COORDINATOR_ADDRESS);
+ call MLME_SET.macAssociationPermit(FALSE);
+ call MLME_START.request(
+ PAN_ID, // PANId
+ RADIO_CHANNEL, // LogicalChannel
+ 0, // ChannelPage,
+ 0, // StartTime,
+ BEACON_ORDER, // BeaconOrder
+ SUPERFRAME_ORDER, // SuperframeOrder
+ TRUE, // PANCoordinator
+ FALSE, // BatteryLifeExtension
+ FALSE, // CoordRealignment
+ 0, // CoordRealignSecurity,
+ 0 // BeaconSecurity
+ );
+ }
+
+ event message_t* MCPS_DATA.indication ( message_t* frame )
+ {
+ if (m_ledCount++ == 20){
+ m_ledCount = 0;
+ call Leds.led1Toggle();
+ }
+ return frame;
+ }
+
+ event void MLME_START.confirm(ieee154_status_t status) {}
+
+ event void MCPS_DATA.confirm(
+ message_t *msg,
+ uint8_t msduHandle,
+ ieee154_status_t status,
+ uint32_t Timestamp
+ ){}
+
+ event void IEEE154TxBeaconPayload.aboutToTransmit() { }
+
+ event void IEEE154TxBeaconPayload.setBeaconPayloadDone(void *beaconPayload, uint8_t length) { }
+
+ event void IEEE154TxBeaconPayload.modifyBeaconPayloadDone(uint8_t offset, void *buffer, uint8_t bufferLength) { }
+
+ event void IEEE154TxBeaconPayload.beaconTransmitted()
+ {
+ ieee154_macBSN_t beaconSequenceNumber = call MLME_GET.macBSN();
+ if (beaconSequenceNumber & 1)
+ call Leds.led2On();
+ else
+ call Leds.led2Off();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * 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 Technische Universitaet Berlin 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 COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+#include "app_profile.h"
+configuration TestDataAppC
+{
+} implementation {
+ components MainC, LedsC, Ieee802154BeaconEnabledC as MAC;
+
+ components TestCoordReceiverC as App;
+ App.MLME_START -> MAC;
+ App.MCPS_DATA -> MAC;
+ App.Frame -> MAC;
+
+ MainC.Boot <- App;
+ App.Leds -> LedsC;
+ App.MLME_RESET -> MAC;
+ App.MLME_SET -> MAC;
+ App.MLME_GET -> MAC;
+ App.IEEE154TxBeaconPayload -> MAC;
+}
--- /dev/null
+COMPONENT=TestDataAppC
+PFLAGS += -DIEEE154_BEACON_TX_DISABLED
+CFLAGS += -I$(shell pwd)/..
+include ../../../Makefile.include
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * 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 Technische Universitaet Berlin 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 COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+#include "app_profile.h"
+configuration TestDataAppC
+{
+} implementation {
+ components MainC, LedsC, Ieee802154BeaconEnabledC as MAC;
+
+ components TestDeviceSenderC as App;
+ App.MLME_SCAN -> MAC;
+ App.MLME_SYNC -> MAC;
+ App.MLME_BEACON_NOTIFY -> MAC;
+ App.MLME_SYNC_LOSS -> MAC;
+ App.MCPS_DATA -> MAC;
+ App.Frame -> MAC;
+ App.BeaconFrame -> MAC;
+ App.Packet -> MAC;
+
+ MainC.Boot <- App;
+ App.Leds -> LedsC;
+ App.MLME_RESET -> MAC;
+ App.MLME_SET -> MAC;
+ App.MLME_GET -> MAC;
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * 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 Technische Universitaet Berlin 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 COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#include "TKN154.h"
+#include "app_profile.h"
+module TestDeviceSenderC
+{
+ uses {
+ interface Boot;
+ interface MCPS_DATA;
+ interface MLME_RESET;
+ interface MLME_SET;
+ interface MLME_GET;
+ interface MLME_SCAN;
+ interface MLME_SYNC;
+ interface MLME_BEACON_NOTIFY;
+ interface MLME_SYNC_LOSS;
+ interface IEEE154Frame as Frame;
+ interface IEEE154BeaconFrame as BeaconFrame;
+ interface Leds;
+ interface Packet;
+ }
+} implementation {
+
+ message_t m_frame;
+ uint8_t m_payloadLen;
+ ieee154_PANDescriptor_t m_PANDescriptor;
+ bool m_ledCount;
+ bool m_isPANDescriptorValid;
+ bool m_sending;
+
+ void startApp();
+ task void packetSendTask();
+
+
+ event void Boot.booted() {
+ char payload[] = "Hello Coordinator!";
+ uint8_t *payloadRegion;
+
+ m_payloadLen = strlen(payload);
+ payloadRegion = call Packet.getPayload(&m_frame, m_payloadLen);
+ if (m_payloadLen <= call Packet.maxPayloadLength()){
+ memcpy(payloadRegion, payload, m_payloadLen);
+ call MLME_RESET.request(TRUE);
+ }
+ }
+
+ event void MLME_RESET.confirm(ieee154_status_t status)
+ {
+ if (status == IEEE154_SUCCESS)
+ startApp();
+ }
+
+ void startApp()
+ {
+ ieee154_phyChannelsSupported_t channelMask;
+ uint8_t scanDuration = BEACON_ORDER;
+
+ m_isPANDescriptorValid = FALSE;
+ call MLME_SET.macShortAddress(TOS_NODE_ID);
+
+ // scan only one channel
+ channelMask = ((uint32_t) 1) << RADIO_CHANNEL;
+
+ // we want all received beacons to be signalled
+ // through the MLME_BEACON_NOTIFY interface, i.e.
+ // we set the macAutoRequest attribute to FALSE
+ call MLME_SET.macAutoRequest(FALSE);
+ call MLME_SCAN.request (
+ PASSIVE_SCAN, // ScanType
+ channelMask, // ScanChannels
+ scanDuration, // ScanDuration
+ 0x00, // ChannelPage
+ 0, // EnergyDetectListNumEntries
+ NULL, // EnergyDetectList
+ 0, // PANDescriptorListNumEntries
+ NULL, // PANDescriptorList
+ 0 // security
+ );
+ }
+ bool m_ready;
+
+ event message_t* MLME_BEACON_NOTIFY.indication (message_t* frame)
+ {
+ // received a beacon frame
+ ieee154_phyCurrentPage_t page = call MLME_GET.phyCurrentPage();
+ ieee154_macBSN_t beaconSequenceNumber = call BeaconFrame.getBSN(frame);
+
+ if (m_ready)
+ post packetSendTask();
+ if (beaconSequenceNumber & 1)
+ call Leds.led2On();
+ else
+ call Leds.led2Off();
+ if (!m_isPANDescriptorValid && call BeaconFrame.parsePANDescriptor(
+ frame, RADIO_CHANNEL, page, &m_PANDescriptor) == SUCCESS){
+ // let's see if the beacon is from our coordinator...
+ if (m_PANDescriptor.CoordAddrMode == ADDR_MODE_SHORT_ADDRESS &&
+ m_PANDescriptor.CoordPANId == PAN_ID &&
+ m_PANDescriptor.CoordAddress.shortAddress == COORDINATOR_ADDRESS){
+ // yes! wait until SCAN is finished, then syncronize to the beacons
+ m_isPANDescriptorValid = TRUE;
+ }
+ }
+ return frame;
+ }
+
+ event void MLME_SCAN.confirm (
+ ieee154_status_t status,
+ uint8_t ScanType,
+ uint8_t ChannelPage,
+ uint32_t UnscannedChannels,
+ uint8_t EnergyDetectListNumEntries,
+ int8_t* EnergyDetectList,
+ uint8_t PANDescriptorListNumEntries,
+ ieee154_PANDescriptor_t* PANDescriptorList
+ )
+ {
+ if (m_isPANDescriptorValid){
+ call MLME_SET.macCoordShortAddress(m_PANDescriptor.CoordAddress.shortAddress);
+ call MLME_SET.macPANId(m_PANDescriptor.CoordPANId);
+ call MLME_SYNC.request(m_PANDescriptor.LogicalChannel, m_PANDescriptor.ChannelPage, TRUE);
+ call Frame.setAddressingFields(
+ &m_frame,
+ ADDR_MODE_SHORT_ADDRESS, // SrcAddrMode,
+ ADDR_MODE_SHORT_ADDRESS, // DstAddrMode,
+ m_PANDescriptor.CoordPANId, // DstPANId,
+ &m_PANDescriptor.CoordAddress, // DstAddr,
+ NULL // security
+ );
+ post packetSendTask();
+ m_ready = TRUE;
+ } else
+ startApp();
+ }
+
+ task void packetSendTask()
+ {
+ if (!m_sending && m_isPANDescriptorValid &&
+ call MCPS_DATA.request (
+ &m_frame, // frame,
+ m_payloadLen, // payloadLength,
+ 0, // msduHandle,
+ TX_OPTIONS_ACK // TxOptions,
+ ) == IEEE154_SUCCESS)
+ m_sending = TRUE;
+ }
+
+ uint8_t m_useLeds = TRUE;
+ event void MCPS_DATA.confirm (
+ message_t *msg,
+ uint8_t msduHandle,
+ ieee154_status_t status,
+ uint32_t timestamp
+ )
+ {
+ m_sending = FALSE;
+ if (status == IEEE154_SUCCESS && m_ledCount++ == 20){
+ m_ledCount = 0;
+ if (m_useLeds)
+ call Leds.led1Toggle();
+ }
+ post packetSendTask();
+ }
+
+ event void MLME_SYNC_LOSS.indication(
+ ieee154_status_t lossReason,
+ uint16_t PANId,
+ uint8_t LogicalChannel,
+ uint8_t ChannelPage,
+ ieee154_security_t *security)
+ {
+ m_useLeds = FALSE;
+ call Leds.led1Off();
+ //startApp();
+ }
+
+ event message_t* MCPS_DATA.indication (message_t* frame)
+ {
+ // we don't expect data
+ return frame;
+ }
+
+}
--- /dev/null
+README for TestIndirect
+Author/Contact: tinyos-help@millennium.berkeley.edu
+
+Description:
+
+In this application one node takes the role of a PAN coordinator in a
+beacon-enabled 802.15.4 PAN; it transmits periodic beacons and additionally in
+every beacon interval it tries to transmit one DATA frame to a device using
+indirect tranmission. A second node that takes the role of a device first scans
+the pre-defined channel for beacons from the coordinator and once it finds a
+beacon it tries to synchronize to and track all future beacons. Whenever the
+coordinator has data to send (indicated in the beacon), the device extracts the
+DATA frame from the coordinator.
+
+The third LED (Telos: blue) is toggled whenever the coordinator has transmitted
+a beacon, it is not used on the device. On the coordinator the second LED
+(Telos: green) is toggled for every transmitted DATA frames. On a device the
+second LED is toggled for every received DATA frame. The first LED (Telos: red)
+is used for debugging, it denotes an error in the protocol stack and should
+never be on.
+
+Tools: NONE
+
+Usage:
+
+1. Install the coordinator:
+
+ $ cd coordinator; make <platform> install
+
+2. Install one device
+
+ $ cd device; make <platform> install
+
+You can change some of the configuration parameters in app_profile.h
+
+Known bugs/limitations:
+
+- Many TinyOS 2 platforms do not have a clock that satisfies the
+ precision/accuracy requirements of the IEEE 802.15.4 standard (e.g.
+ 62.500 Hz, +-40 ppm in the 2.4 GHz band); in this case the MAC timing
+ is not standard compliant
+
+$Id$
+
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * 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 Technische Universitaet Berlin 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 COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#ifndef __APP_PROFILE_H
+#define __APP_PROFILE_H
+
+enum {
+ RADIO_CHANNEL = 26,
+ PAN_ID = 0x1152,
+ DEVICE_ADDRESS = 0x4342,
+ COORDINATOR_ADDRESS = 0x5341,
+ BEACON_ORDER = 5,
+ SUPERFRAME_ORDER = 5,
+};
+
+#endif
--- /dev/null
+COMPONENT=TestIndirectAppC
+PFLAGS += -DIEEE154_BEACON_SYNC_DISABLED -DIEEE154_SCAN_DISABLED
+CFLAGS += -I$(shell pwd)/..
+include ../../../Makefile.include
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * 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 Technische Universitaet Berlin 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 COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#include "TKN154.h"
+#include "app_profile.h"
+module TestCoordSenderC
+{
+ uses {
+ interface Boot;
+ interface MCPS_DATA;
+ interface MLME_RESET;
+ interface MLME_START;
+ interface MLME_SET;
+ interface MLME_GET;
+ interface Leds;
+ interface IEEE154Frame as Frame;
+ interface IEEE154TxBeaconPayload;
+ interface Packet;
+ }
+} implementation {
+
+ message_t m_frame;
+ uint8_t m_payloadLen;
+
+ event void Boot.booted() {
+ char payload[] = "Hello Device!";
+ uint8_t *payloadRegion;
+ ieee154_address_t deviceShortAddress;
+
+ // construct the frame
+ m_payloadLen = strlen(payload);
+ payloadRegion = call Packet.getPayload(&m_frame, m_payloadLen);
+ deviceShortAddress.shortAddress = DEVICE_ADDRESS; // destination
+ if (m_payloadLen <= call Packet.maxPayloadLength()){
+ memcpy(payloadRegion, payload, m_payloadLen);
+ call Frame.setAddressingFields(
+ &m_frame,
+ ADDR_MODE_SHORT_ADDRESS, // SrcAddrMode,
+ ADDR_MODE_SHORT_ADDRESS, // DstAddrMode,
+ PAN_ID, // DstPANId,
+ &deviceShortAddress, // DstAddr,
+ NULL // security
+ );
+ call MLME_RESET.request(TRUE);
+ }
+ }
+
+ event void MLME_RESET.confirm(ieee154_status_t status)
+ {
+ if (status != IEEE154_SUCCESS)
+ return;
+ call MLME_SET.macShortAddress(COORDINATOR_ADDRESS);
+ call MLME_SET.macAssociationPermit(FALSE);
+ call MLME_START.request(
+ PAN_ID, // PANId
+ RADIO_CHANNEL, // LogicalChannel
+ 0, // ChannelPage,
+ 0, // StartTime,
+ BEACON_ORDER, // BeaconOrder
+ SUPERFRAME_ORDER, // SuperframeOrder
+ TRUE, // PANCoordinator
+ FALSE, // BatteryLifeExtension
+ FALSE, // CoordRealignment
+ 0, // CoordRealignSecurity
+ 0 // BeaconSecurity
+ );
+ }
+
+ void dataRequest()
+ {
+ call MCPS_DATA.request (
+ &m_frame, // msdu,
+ m_payloadLen, // payloadLength,
+ 0, // msduHandle,
+ TX_OPTIONS_ACK | TX_OPTIONS_INDIRECT // TxOptions,
+ );
+ }
+
+ event void MLME_START.confirm(ieee154_status_t status)
+ {
+ if (status == IEEE154_SUCCESS)
+ dataRequest();
+ }
+
+ event void MCPS_DATA.confirm(
+ message_t *msg,
+ uint8_t msduHandle,
+ ieee154_status_t status,
+ uint32_t Timestamp
+ )
+ {
+ if (status == IEEE154_SUCCESS)
+ call Leds.led1Toggle();
+ dataRequest();
+ }
+
+ event message_t* MCPS_DATA.indication ( message_t* frame)
+ {
+ return frame;
+ }
+
+ event void IEEE154TxBeaconPayload.aboutToTransmit() { }
+
+ event void IEEE154TxBeaconPayload.setBeaconPayloadDone(void *beaconPayload, uint8_t length) { }
+
+ event void IEEE154TxBeaconPayload.modifyBeaconPayloadDone(uint8_t offset, void *buffer, uint8_t bufferLength) { }
+
+ event void IEEE154TxBeaconPayload.beaconTransmitted()
+ {
+ ieee154_macBSN_t beaconSequenceNumber = call MLME_GET.macBSN();
+ if (beaconSequenceNumber & 1)
+ call Leds.led2On();
+ else
+ call Leds.led2Off();
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * 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 Technische Universitaet Berlin 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 COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+configuration TestIndirectAppC
+{
+} implementation {
+ components MainC, LedsC, Ieee802154BeaconEnabledC as MAC;
+ components TestCoordSenderC as App;
+
+ MainC.Boot <- App;
+ App.Leds -> LedsC;
+ App.MLME_RESET -> MAC;
+ App.MLME_SET -> MAC;
+ App.MLME_GET -> MAC;
+ App.MLME_START -> MAC;
+ App.MCPS_DATA -> MAC;
+ App.Frame -> MAC;
+ App.IEEE154TxBeaconPayload -> MAC;
+ App.Packet -> MAC;
+
+}
--- /dev/null
+COMPONENT=TestIndirectAppC
+PFLAGS += -DIEEE154_BEACON_TX_DISABLED
+CFLAGS += -I$(shell pwd)/..
+include ../../../Makefile.include
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * 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 Technische Universitaet Berlin 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 COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+#include "TKN154.h"
+#include "app_profile.h"
+module TestDeviceReceiverC
+{
+ uses {
+ interface Boot;
+ interface MCPS_DATA;
+ interface MLME_RESET;
+ interface MLME_SET;
+ interface MLME_GET;
+ interface MLME_SCAN;
+ interface MLME_SYNC;
+ interface MLME_BEACON_NOTIFY;
+ interface MLME_SYNC_LOSS;
+ interface IEEE154BeaconFrame as BeaconFrame;
+ interface Leds;
+ }
+} implementation {
+
+ ieee154_address_t m_coordAddress;
+ uint8_t m_coordAddressMode;
+ ieee154_macPANId_t m_coordPANID;
+ ieee154_PANDescriptor_t m_PANDescriptor;
+ bool m_isPANDescriptorValid;
+ void startApp();
+
+ event void Boot.booted() {
+ call MLME_RESET.request(TRUE);
+ }
+
+ event void MLME_RESET.confirm(ieee154_status_t status)
+ {
+ if (status == IEEE154_SUCCESS)
+ startApp();
+ }
+
+ void startApp()
+ {
+ ieee154_phyChannelsSupported_t channel;
+ uint8_t scanDuration = BEACON_ORDER;
+
+ // in this application the coordinator assumes that
+ // the device has a certain short address
+ call MLME_SET.macShortAddress(DEVICE_ADDRESS);
+ channel = ((uint32_t) 1) << RADIO_CHANNEL;
+
+ // we want all received beacons to be signalled
+ // through the MLME_BEACON_NOTIFY interface, i.e.
+ // we set the macAutoRequest attribute to FALSE
+ call MLME_SET.macAutoRequest(FALSE);
+ call MLME_SCAN.request (
+ PASSIVE_SCAN, // ScanType
+ channel, // ScanChannels
+ scanDuration, // ScanDuration
+ 0x00, // ChannelPage
+ 0, // EnergyDetectListNumEntries
+ NULL, // EnergyDetectList
+ 0, // PANDescriptorListNumEntries
+ NULL, // PANDescriptorList
+ 0 // security
+ );
+ }
+
+ event message_t* MLME_BEACON_NOTIFY.indication (message_t* frame)
+ {
+ // received a beacon frame during SCAN
+ ieee154_phyCurrentPage_t page = call MLME_GET.phyCurrentPage();
+ ieee154_macBSN_t beaconSequenceNumber = call BeaconFrame.getBSN(frame);
+
+ if (beaconSequenceNumber & 1)
+ call Leds.led2On();
+ else
+ call Leds.led2Off();
+
+ if (!m_isPANDescriptorValid && call BeaconFrame.parsePANDescriptor(
+ frame, RADIO_CHANNEL, page, &m_PANDescriptor) == SUCCESS){
+ // let's see if the beacon is from our coordinator...
+ if (m_PANDescriptor.CoordAddrMode == ADDR_MODE_SHORT_ADDRESS &&
+ m_PANDescriptor.CoordPANId == PAN_ID &&
+ m_PANDescriptor.CoordAddress.shortAddress == COORDINATOR_ADDRESS){
+ // wait until SCAN is finished, then syncronize to beacons
+ m_isPANDescriptorValid = TRUE;
+ }
+ }
+ return frame;
+ }
+
+ event void MLME_SCAN.confirm (
+ ieee154_status_t status,
+ uint8_t ScanType,
+ uint8_t ChannelPage,
+ uint32_t UnscannedChannels,
+ uint8_t EnergyDetectListNumEntries,
+ int8_t* EnergyDetectList,
+ uint8_t PANDescriptorListNumEntries,
+ ieee154_PANDescriptor_t* PANDescriptorList
+ )
+ {
+ if (m_isPANDescriptorValid){
+ // set the macAutoRequest attribute to TRUE, so indirect
+ // transmissions are automatically carried through
+ call MLME_SET.macAutoRequest(TRUE);
+ call MLME_SET.macCoordShortAddress(m_PANDescriptor.CoordAddress.shortAddress);
+ call MLME_SET.macPANId(m_PANDescriptor.CoordPANId);
+ call MLME_SYNC.request(m_PANDescriptor.LogicalChannel, m_PANDescriptor.ChannelPage, TRUE);
+ } else
+ startApp();
+ }
+
+ event void MCPS_DATA.confirm(
+ message_t *msg,
+ uint8_t msduHandle,
+ ieee154_status_t status,
+ uint32_t Timestamp
+ )
+ {
+ }
+
+ event void MLME_SYNC_LOSS.indication(
+ ieee154_status_t lossReason,
+ uint16_t PANId,
+ uint8_t LogicalChannel,
+ uint8_t ChannelPage,
+ ieee154_security_t *security)
+ {
+ call Leds.led1Off();
+ startApp();
+ }
+
+ event message_t* MCPS_DATA.indication (message_t* frame)
+ {
+ call Leds.led1Toggle();
+ return frame;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * 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 Technische Universitaet Berlin 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 COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+configuration TestIndirectAppC
+{
+} implementation {
+ components MainC, LedsC, Ieee802154BeaconEnabledC as MAC;
+ components TestDeviceReceiverC as App;
+
+ MainC.Boot <- App;
+ App.Leds -> LedsC;
+ App.MLME_RESET -> MAC;
+ App.MLME_SET -> MAC;
+ App.MLME_GET -> MAC;
+ App.MLME_SCAN -> MAC;
+ App.MLME_SYNC -> MAC;
+ App.MLME_BEACON_NOTIFY -> MAC;
+ App.MLME_SYNC_LOSS -> MAC;
+ App.MCPS_DATA -> MAC;
+ App.BeaconFrame -> MAC;
+}
--- /dev/null
+COMPONENT=TestPromiscuousAppC
+PFLAGS += -DPRINTF_BUFFER_SIZE=1000
+CFLAGS += -I$(TOSDIR)/lib/printf
+CFLAGS += -DIEEE154_SCAN_DISABLED -DIEEE154_BEACON_SYNC_DISABLED -DIEEE154_BEACON_TX_DISABLED -DIEEE154_RXENABLE_DISABLED -DIEEE154_ASSOCIATION_DISABLED -DIEEE154_DISASSOCIATION_DISABLED -DIEEE154_COORD_REALIGNMENT_DISABLED -DIEEE154_COORD_BROADCAST_DISABLED
+include ../../Makefile.include
--- /dev/null
+README for TestPromiscuous
+Author/Contact: tinyos-help@millennium.berkeley.edu
+
+Description:
+
+In this application the node enables promiscuous mode, i.e. its radio is
+switched to receive mode and all incoming frames that pass the CRC check are
+signalled to the upper layer. The application uses the TinyOS printf library
+(tos/lib/printf) to output information on the MAC header fields and payload for
+every received frame over the serial port. The second (TelosB: green) LED is
+toggled whenever a frame is received.
+
+Tools: The printf java client in $TOSDIR/../apps/tests/TestPrintf
+
+Usage:
+
+Install the application on a node
+
+ $ make <platform> install
+
+Start the printf client, e.g.
+
+ $ java net.tinyos.tools.PrintfClient -comm serial@/dev/ttyUSBXXX:<platform>
+
+(http://docs.tinyos.net/ has a section on how to use the TinyOS printf library)
+
+Known bugs/limitations:
+
+- The timestamps for ACKs are incorrect
+
+$Id$
+
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * 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 Technische Universitaet Berlin 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 COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+configuration TestPromiscuousAppC
+{
+} implementation {
+ components MainC, TestPromiscuousC as App, LedsC,
+ Ieee802154BeaconEnabledC as MAC;
+
+ MainC.Boot <- App;
+ App.Leds -> LedsC;
+
+ App.MLME_RESET -> MAC;
+ App.MLME_SET -> MAC;
+ App.MLME_GET -> MAC;
+ App.MCPS_DATA -> MAC;
+ App.Frame -> MAC;
+ App.BeaconFrame -> MAC;
+ App.PromiscuousMode -> MAC;
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * 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 Technische Universitaet Berlin 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 COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+#include "TKN154.h"
+module TestPromiscuousC
+{
+ uses {
+ interface Boot;
+ interface MLME_RESET;
+ interface MLME_SET;
+ interface MLME_GET;
+ interface MCPS_DATA;
+ interface Leds;
+ interface IEEE154Frame as Frame;
+ interface IEEE154BeaconFrame as BeaconFrame;
+ interface SplitControl as PromiscuousMode;
+ }
+} implementation {
+
+ const char *m_frametype[] = {"Beacon", "Data","Acknowledgement","MAC command", "Unknown"};
+ const char *m_cmdframetype[] = {"unknown command", "Association request","Association response",
+ "Disassociation notification","Data request","PAN ID conflict notification",
+ "Orphan notification", "Beacon request", "Coordinator realignment", "GTS request"};
+
+ enum {
+ RADIO_CHANNEL = 26,
+ };
+
+ event void Boot.booted() {
+ call MLME_RESET.request(TRUE);
+ }
+
+ event void MLME_RESET.confirm(ieee154_status_t status)
+ {
+ call MLME_SET.phyCurrentChannel(RADIO_CHANNEL);
+ call PromiscuousMode.start();
+ }
+
+ event message_t* MCPS_DATA.indication (message_t* frame)
+ {
+ uint8_t i;
+ uint8_t *payload = call Frame.getPayload(frame);
+ uint8_t payloadLen = call Frame.getPayloadLength(frame);
+ uint8_t *header = call Frame.getHeader(frame);
+ uint8_t headerLen = call Frame.getHeaderLength(frame);
+ uint8_t SrcAddrMode, DstAddrMode;
+ uint8_t frameType, cmdFrameType;
+ ieee154_address_t SrcAddress, DstAddress;
+ uint16_t SrcPANId=0, DstPANId=0;
+
+ if (call Frame.hasStandardCompliantHeader(frame)){
+ frameType = call Frame.getFrameType(frame);
+ if (frameType > FRAMETYPE_CMD)
+ frameType = 4;
+ call Frame.getSrcPANId(frame, &SrcPANId);
+ call Frame.getDstPANId(frame, &DstPANId);
+ call Frame.getSrcAddr(frame, &SrcAddress);
+ call Frame.getDstAddr(frame, &DstAddress);
+ SrcAddrMode = call Frame.getSrcAddrMode(frame);
+ DstAddrMode = call Frame.getDstAddrMode(frame);
+
+ printf("\n");
+ printf("Frametype: %s", m_frametype[frameType]);
+ if (frameType == FRAMETYPE_CMD){
+ cmdFrameType = payload[0];
+ if (cmdFrameType > 9)
+ cmdFrameType = 0;
+ printf(" (%s)", m_cmdframetype[cmdFrameType]);
+ }
+ printf("\n");
+ printf("SrcAddrMode: %d\n", SrcAddrMode);
+ printf("SrcAddr: ");
+ if (SrcAddrMode == ADDR_MODE_SHORT_ADDRESS){
+ printf("0x%02X\n", SrcAddress.shortAddress);
+ printf("SrcPANId: 0x%02X\n", SrcPANId);
+ } else if (SrcAddrMode == ADDR_MODE_EXTENDED_ADDRESS){
+ for (i=0; i<8; i++)
+ printf("0x%02X ", ((uint8_t*) &(SrcAddress.extendedAddress))[i]);
+ printf("\n");
+ printf("SrcPANId: 0x%02X\n", SrcPANId);
+ } else printf("\n");
+ printf("DstAddrMode: %d\n", DstAddrMode);
+ printf("DstAddr: ");
+ if ( DstAddrMode == ADDR_MODE_SHORT_ADDRESS){
+ printf("0x%02X\n", DstAddress.shortAddress);
+ printf("DestPANId: 0x%02X\n", DstPANId);
+ } else if ( DstAddrMode == ADDR_MODE_EXTENDED_ADDRESS) {
+ for (i=0; i<8; i++)
+ printf("0x%02X ", ((uint8_t*) &(DstAddress.extendedAddress))[i]);
+ printf("\n");
+ printf("DestPANId: 0x%02X\n", DstPANId);
+ } else printf("\n");
+
+ printf("DSN: %d\n", call Frame.getDSN(frame));
+ printf("MHRLen: %d\n", headerLen);
+ printf("MHR: ");
+ for (i=0; i<headerLen; i++){
+ printf("0x%02X ", header[i]);
+ }
+ printf("\n");
+ printf("PayloadLen: %d\n", payloadLen);
+ printf("Payload: ");
+ for (i=0; i<payloadLen; i++){
+ printf("0x%02X ", payload[i]);
+ }
+ printf("\n");
+ printf("MpduLinkQuality: %d\n", call Frame.getLinkQuality(frame));
+
+ printf("Timestamp: ");
+ if (call Frame.isTimestampValid(frame))
+ printf("%ld\n", call Frame.getTimestamp(frame));
+ else
+ printf("INVALID\n");
+ printfflush();
+ }
+ call Leds.led1Toggle();
+ return frame;
+ }
+
+ event void MCPS_DATA.confirm( message_t *msg, uint8_t msduHandle, ieee154_status_t status, uint32_t Timestamp){}
+ event void PromiscuousMode.startDone(error_t error)
+ {
+ printf("\n*** Radio is now in promiscuous mode, listening on channel %d ***\n", RADIO_CHANNEL);
+ printfflush();
+ }
+ event void PromiscuousMode.stopDone(error_t error) {}
+}
--- /dev/null
+README for TestStartSync
+Author/Contact: tinyos-help@millennium.berkeley.edu
+
+Description:
+
+In this application one node takes the role of a PAN coordinator in a
+beacon-enabled 802.15.4 PAN; it transmits periodic beacons with a frequency
+defined in the app_profile.h file. A second node acts as a device; it first
+scans all available channels for beacons from the coordinator and once it finds
+a beacon it tries to synchronize to and track all future beacons.
+
+The third LED (Telos: blue) is toggled whenever the coordinator has transmitted
+a beacon or whenever a device has received a beacon. On the coordinator the
+second LED (Telos: green) is switched on after it has started transmitting
+beacons. On a device the second LED is switched on whenever the device is
+synchronized to the coordinator's beacons. The first LED (Telos: red) is used
+for debugging, it denotes an error in the protocol stack and should never be
+on.
+
+Tools: NONE
+
+Usage:
+
+1. Install the coordinator:
+
+ $ cd coordinator; make <platform> install
+
+2. Install one (or more) devices:
+
+ $ cd device; make <platform> install
+
+You can change some of the configuration parameters in app_profile.h
+
+Known bugs/limitations:
+
+- Many TinyOS 2 platforms do not have a clock that satisfies the
+ precision/accuracy requirements of the IEEE 802.15.4 standard (e.g.
+ 62.500 Hz, +-40 ppm in the 2.4 GHz band); in this case the MAC timing
+ is not standard compliant
+
+$Id$
+
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * 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 Technische Universitaet Berlin 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 COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#ifndef __APP_PROFILE_H
+#define __APP_PROFILE_H
+
+enum {
+ RADIO_CHANNEL = 26,
+ PAN_ID = 0x7761,
+ COORDINATOR_ADDRESS = 0x1832,
+ BEACON_ORDER = 5,
+ SUPERFRAME_ORDER = 5,
+};
+
+#endif
--- /dev/null
+COMPONENT=TestStartSyncAppC
+CFLAGS += -I$(shell pwd)/..
+CFLAGS += -DIEEE154_SCAN_DISABLED -DIEEE154_BEACON_SYNC_DISABLED
+include ../../../Makefile.include
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * 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 Technische Universitaet Berlin 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 COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#include "TKN154.h"
+#include "app_profile.h"
+module TestCoordC
+{
+ uses {
+ interface Boot;
+ interface MLME_RESET;
+ interface MLME_START;
+ interface MLME_SET;
+ interface MLME_GET;
+ interface Leds;
+ interface IEEE154TxBeaconPayload;
+ }
+} implementation {
+
+ uint8_t m_beaconPayload[] = {0x01, 0x02, 0x03, 0x04, 0x05};
+
+ event void Boot.booted() {
+ call MLME_RESET.request(TRUE);
+ }
+
+ event void MLME_RESET.confirm(ieee154_status_t status)
+ {
+ if (status == IEEE154_SUCCESS){
+ call MLME_SET.macShortAddress(COORDINATOR_ADDRESS);
+ call MLME_SET.macAssociationPermit(FALSE);
+ call MLME_START.request(
+ PAN_ID, // PANId
+ RADIO_CHANNEL, // LogicalChannel
+ 0, // ChannelPage,
+ 0, // StartTime,
+ BEACON_ORDER, // BeaconOrder
+ SUPERFRAME_ORDER, // SuperframeOrder
+ TRUE, // PANCoordinator
+ FALSE, // BatteryLifeExtension
+ FALSE, // CoordRealignment
+ 0, // no realignment security
+ 0 // no beacon security
+ );
+ }
+ }
+
+ event void MLME_START.confirm(ieee154_status_t status)
+ {
+ if (status == IEEE154_SUCCESS){
+ call IEEE154TxBeaconPayload.setBeaconPayload(m_beaconPayload, sizeof(m_beaconPayload));
+ call Leds.led1On();
+ }
+ }
+
+ event void IEEE154TxBeaconPayload.aboutToTransmit() { }
+
+ event void IEEE154TxBeaconPayload.setBeaconPayloadDone(void *beaconPayload, uint8_t length) { }
+
+ event void IEEE154TxBeaconPayload.modifyBeaconPayloadDone(uint8_t offset, void *buffer, uint8_t bufferLength) { }
+
+ event void IEEE154TxBeaconPayload.beaconTransmitted()
+ {
+ ieee154_macBSN_t beaconSequenceNumber = call MLME_GET.macBSN();
+ if (beaconSequenceNumber & 1)
+ call Leds.led2On();
+ else
+ call Leds.led2Off();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * 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 Technische Universitaet Berlin 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 COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+configuration TestStartSyncAppC
+{
+} implementation {
+
+ components MainC, LedsC, Ieee802154BeaconEnabledC as MAC;
+ components TestCoordC as App;
+
+ MainC.Boot <- App;
+ App.MLME_START -> MAC;
+ App.IEEE154TxBeaconPayload -> MAC;
+ App.Leds -> LedsC;
+ App.MLME_RESET -> MAC;
+ App.MLME_SET -> MAC;
+ App.MLME_GET -> MAC;
+}
--- /dev/null
+COMPONENT=TestStartSyncAppC
+PFLAGS += -DIEEE154_BEACON_TX_DISABLED
+CFLAGS += -I$(shell pwd)/..
+include ../../../Makefile.include
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * 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 Technische Universitaet Berlin 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 COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#include "TKN154.h"
+#include "app_profile.h"
+module TestDeviceC
+{
+ uses {
+ interface Boot;
+ interface MLME_RESET;
+ interface MLME_SET;
+ interface MLME_GET;
+ interface MLME_SCAN;
+ interface MLME_SYNC;
+ interface MLME_BEACON_NOTIFY;
+ interface MLME_SYNC_LOSS;
+ interface Leds;
+ interface IEEE154BeaconFrame as BeaconFrame;
+ }
+} implementation {
+
+ enum {
+ NUM_PAN_DESCRIPTORS = 10,
+ };
+ ieee154_PANDescriptor_t m_PANDescriptor[NUM_PAN_DESCRIPTORS];
+ void startApp();
+
+ event void Boot.booted() {
+ call MLME_RESET.request(TRUE);
+ }
+
+ event void MLME_RESET.confirm(ieee154_status_t status)
+ {
+ if (status == IEEE154_SUCCESS)
+ startApp();
+ }
+
+ void startApp()
+ {
+ ieee154_phyChannelsSupported_t scanChannels;
+ uint8_t scanDuration = BEACON_ORDER;
+
+ // set the short address to whatever was passed
+ // as a parameter to make system ("make install,X")
+ call MLME_SET.macShortAddress(TOS_NODE_ID);
+ scanChannels = call MLME_GET.phyChannelsSupported();
+ //scanChannels = (uint32_t) 1 << RADIO_CHANNEL;
+
+ // setting the macAutoRequest attribute to TRUE means
+ // that during the scan beacons will not be signalled
+ // through MLME_BEACON_NOTIFY
+ call MLME_SET.macAutoRequest(TRUE);
+ call MLME_SCAN.request (
+ PASSIVE_SCAN, // ScanType
+ scanChannels, // ScanChannels
+ scanDuration, // ScanDuration
+ 0x00, // ChannelPage
+ 0, // EnergyDetectListNumEntries
+ NULL, // EnergyDetectList
+ NUM_PAN_DESCRIPTORS, // PANDescriptorListNumEntries
+ m_PANDescriptor, // PANDescriptorList
+ 0 // security
+ );
+ }
+
+ event void MLME_SCAN.confirm (
+ ieee154_status_t status,
+ uint8_t ScanType,
+ uint8_t ChannelPage,
+ uint32_t UnscannedChannels,
+ uint8_t EnergyDetectListNumEntries,
+ int8_t* EnergyDetectList,
+ uint8_t PANDescriptorListNumEntries,
+ ieee154_PANDescriptor_t* PANDescriptorList
+ )
+ {
+ uint8_t i;
+ switch (status){
+ case IEEE154_NO_BEACON:
+ startApp();
+ break;
+ case IEEE154_SUCCESS:
+ if (PANDescriptorListNumEntries > 0){
+ for (i=0; i<PANDescriptorListNumEntries; i++)
+ if (PANDescriptorList[i].CoordAddrMode == ADDR_MODE_SHORT_ADDRESS &&
+ PANDescriptorList[i].CoordPANId == PAN_ID &&
+ PANDescriptorList[i].CoordAddress.shortAddress == COORDINATOR_ADDRESS)
+ break;
+ if (i == PANDescriptorListNumEntries){
+ // found no matching entry
+ startApp();
+ } else {
+ call MLME_SET.macAutoRequest(FALSE); // from now on: give me the beacons
+ call MLME_SET.macPANId(PANDescriptorList[i].CoordPANId);
+ call MLME_SET.macCoordShortAddress(PANDescriptorList[i].CoordAddress.shortAddress);
+ call MLME_SYNC.request(PANDescriptorList[i].LogicalChannel, ChannelPage, TRUE);
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ event message_t* MLME_BEACON_NOTIFY.indication (
+ message_t* frame
+ )
+ {
+ ieee154_macBSN_t beaconSequenceNumber = call BeaconFrame.getBSN(frame);
+ if (beaconSequenceNumber & 1)
+ call Leds.led2On();
+ else
+ call Leds.led2Off();
+ call Leds.led1On();
+ return frame;
+ }
+
+ event void MLME_SYNC_LOSS.indication(
+ ieee154_status_t lossReason,
+ uint16_t PANId,
+ uint8_t LogicalChannel,
+ uint8_t ChannelPage,
+ ieee154_security_t *security)
+ {
+ call Leds.led1Off();
+ startApp();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * 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 Technische Universitaet Berlin 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 COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+configuration TestStartSyncAppC
+{
+} implementation {
+
+ components MainC, LedsC, Ieee802154BeaconEnabledC as MAC;
+ components TestDeviceC as App;
+
+ App.MLME_SCAN -> MAC;
+ App.MLME_SYNC -> MAC;
+ App.MLME_BEACON_NOTIFY -> MAC;
+ App.MLME_SYNC_LOSS -> MAC;
+ App.BeaconFrame -> MAC;
+
+ MainC.Boot <- App;
+ App.Leds -> LedsC;
+ App.MLME_RESET -> MAC;
+ App.MLME_SET -> MAC;
+ App.MLME_GET -> MAC;
+
+#ifdef PRINTF_ENABLED
+ components PrintfC;
+ App.PrintfControl -> PrintfC;
+ App.PrintfFlush -> PrintfC;
+#endif
+}