[Tinyos-2-commits] CVS: tinyos-2.x/tos/lib/mac/tkn154 DebugC.nc, NONE, 1.1 DebugP.nc, NONE, 1.1 SlottedFrameDispatchP.nc, NONE, 1.1 TKN154BeaconEnabledP.nc, NONE, 1.1 TKN154NonBeaconEnabledP.nc, NONE, 1.1 UnslottedFrameDispatchP.nc, NONE, 1.1 AssociateP.nc, 1.4, 1.5 BeaconSynchronizeP.nc, 1.7, 1.8 BeaconTransmitP.nc, 1.6, 1.7 CoordBroadcastP.nc, 1.3, 1.4 CoordRealignmentP.nc, 1.1, 1.2 DataP.nc, 1.2, 1.3 DisassociateP.nc, 1.2, 1.3 FrameDispatchQueueP.nc, 1.1, 1.2 IndirectTxP.nc, 1.3, 1.4 PibP.nc, 1.4, 1.5 PollP.nc, 1.2, 1.3 PromiscuousModeP.nc, 1.2, 1.3 RadioClientC.nc, 1.2, 1.3 RadioControlImplP.nc, 1.2, 1.3 RadioControlP.nc, 1.1, 1.2 README.txt, 1.4, 1.5 RxEnableP.nc, 1.4, 1.5 ScanP.nc, 1.2, 1.3 SimpleTransferArbiterP.nc, 1.2, 1.3 TKN154_MAC.h, 1.3, 1.4 TKN154_PIB.h, 1.2, 1.3 TransferClientP.nc, 1.3, 1.4 FrameDispatchP.nc, 1.3, NONE TKN154_DEBUG.h, 1.4, NONE TKN154P.nc, 1.6, NONE
Jan-Hinrich Hauer
janhauer at users.sourceforge.net
Wed Mar 4 10:32:11 PST 2009
Update of /cvsroot/tinyos/tinyos-2.x/tos/lib/mac/tkn154
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv17605/tos/lib/mac/tkn154
Modified Files:
AssociateP.nc BeaconSynchronizeP.nc BeaconTransmitP.nc
CoordBroadcastP.nc CoordRealignmentP.nc DataP.nc
DisassociateP.nc FrameDispatchQueueP.nc IndirectTxP.nc PibP.nc
PollP.nc PromiscuousModeP.nc RadioClientC.nc
RadioControlImplP.nc RadioControlP.nc README.txt RxEnableP.nc
ScanP.nc SimpleTransferArbiterP.nc TKN154_MAC.h TKN154_PIB.h
TransferClientP.nc
Added Files:
DebugC.nc DebugP.nc SlottedFrameDispatchP.nc
TKN154BeaconEnabledP.nc TKN154NonBeaconEnabledP.nc
UnslottedFrameDispatchP.nc
Removed Files:
FrameDispatchP.nc TKN154_DEBUG.h TKN154P.nc
Log Message:
- re-designed the radio driver interfaces, restructured/improved the CC2420 radio driver
- split the main MAC configuration (was TKN154P.nc) in two: one for beacon-enabled mode the other for nonbeacon-enabled mode (this decision has to be made at compile time now)
- added (serial) debugging functions (compile with "TKN154_DEBUG=1 make telosb" and use the java PrintfClient, see tinyos-2.x/apps/tests/TestPrintf/README.txt)
- improved readability, added comments
--- NEW FILE: DebugC.nc ---
/*
* 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: 1.1 $
* $Date: 2009/03/04 18:31:22 $
* @author: Jan Hauer <hauer at tkn.tu-berlin.de>
* ========================================================================
*/
configuration DebugC {
}
implementation {
components DebugP, LedsC;
DebugP.Leds -> LedsC;
}
--- NEW FILE: DebugP.nc ---
/*
* 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: 1.1 $
* $Date: 2009/03/04 18:31:22 $
* @author: Jan Hauer <hauer at tkn.tu-berlin.de>
* ========================================================================
*/
#include "printf.h"
#include <stdio.h>
#ifdef __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif
module DebugP {
uses interface Leds;
}
implementation {
enum {
MAX_LEN_FUNNAME = 50,
MAX_LEN_FILENAME = 50,
NUM_LIST_ENTRIES = 20,
};
typedef struct {
const char *filename;
uint16_t line;
const char *format;
uint32_t param[2];
} debug_list_entry_t;
norace debug_list_entry_t m_list[NUM_LIST_ENTRIES];
norace uint8_t m_head;
norace uint8_t m_tail;
norace bool m_overflow;
uint16_t m_assertCounter;
norace uint16_t m_assertLine;
norace char m_assertFilename[MAX_LEN_FILENAME];
norace char m_assertFunction[MAX_LEN_FUNNAME];
task void assertFailTask()
{
if (m_assertCounter == 0) {
printf("Assert failed: File: %s, line: %d, function: %s.\n", m_assertFilename, m_assertLine, m_assertFunction);
printfflush();
}
if (m_assertCounter++ < 3000) {
call Leds.led0On();
call Leds.led1On();
call Leds.led2On();
} else {
call Leds.led0Off();
call Leds.led1Off();
call Leds.led2Off();
}
if (m_assertCounter > 6000)
m_assertCounter = 0;
post assertFailTask();
}
void tkn154_assert(bool val, const char *filename, uint16_t line, const char *func) @C() @spontaneous()
{
if (!val) {
if (m_assertLine == 0) {
// only catch the first failure, output it periodically
m_assertLine = line;
strncpy(m_assertFilename, filename, MAX_LEN_FILENAME);
strncpy(m_assertFunction, func, MAX_LEN_FILENAME);
post assertFailTask();
}
}
}
void tkn154_dbg_serial(const char *filename, uint16_t line, ...) @C() @spontaneous()
{
// This function must be fast: we just copy the strings and
// output them later in the flush-function
if ((m_head + 1) % NUM_LIST_ENTRIES != m_tail) {
va_list argp;
m_list[m_head].filename = filename;
m_list[m_head].line = line;
va_start(argp, line);
m_list[m_head].format = va_arg(argp, char*);
m_list[m_head].param[0] = va_arg(argp, uint32_t);
m_list[m_head].param[1] = va_arg(argp, uint32_t);
va_end(argp);
m_head = (m_head + 1) % NUM_LIST_ENTRIES;
} else
m_overflow = TRUE;
}
task void serialFlushTask()
{
if (m_overflow)
printf("SERIAL OVERFLOW!\n");
if (m_head != m_tail) {
printf("%s:%d:", m_list[m_tail].filename, m_list[m_tail].line);
printf(m_list[m_tail].format, m_list[m_tail].param[0], m_list[m_tail].param[1]);
atomic {
if (++m_tail >= NUM_LIST_ENTRIES)
m_tail = 0;
}
}
if (m_head != m_tail)
post serialFlushTask();
printfflush();
}
void tkn154_dbg_serial_flush() @C() @spontaneous()
{
post serialFlushTask();
}
}
--- NEW FILE: SlottedFrameDispatchP.nc ---
/*
* 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: 1.1 $
* $Date: 2009/03/04 18:31:32 $
* @author Jan Hauer <hauer at tkn.tu-berlin.de>
* ========================================================================
*/
#include "TKN154_PHY.h"
#include "TKN154_MAC.h"
/**
* This module is responsible for the transmission/reception of DATA and
* COMMAND frames in the CAP of beacon-enabled PANs. Its main tasks are
* initialization of the parameters of the slotted CSMA-CA algorithm (NB, BE,
* etc.), initiating retransmissions and dealing with broadcast transmissions.
* It does not implement the actual CSMA-CA algorithm, because due to its
* timing requirements the CSMA-CA algorithm is not part of the MAC
* implementation but of the chip-specific radio driver.
*
* This module does slightly different things depending on whether it is the
* CAP for an outgoing superframe (sfDirection = OUTGOING_SUPERFRAME), i.e. the
* CAP from the perspective of a coordinator after it has transmitted its own
* beacon; or for an incoming superframe (sfDirection = INCOMING_SUPERFRAME),
* i.e. the CAP from the perspective of a device after it has received a
* beacon from its coordinator. For example, in the CAP a coordinator will
* typically listen for incoming frames from the devices, and a device will
* typically switch the radio off unless it has a frame to transmit.
*/
#ifndef IEEE154_BEACON_ENABLED_PAN
#error "The IEEE154_BEACON_ENABLED_PAN macro MUST be defined when using this component!"
#endif
generic module SlottedFrameDispatchP(uint8_t sfDirection)
{
provides
{
interface Init as Reset;
interface FrameTx as FrameTx;
interface FrameRx as FrameRx[uint8_t frameType];
interface FrameExtracted as FrameExtracted[uint8_t frameType];
interface FrameTxNow as BroadcastTx;
interface Notify<bool> as WasRxEnabled;
}
uses
{
interface Alarm<TSymbolIEEE802154,uint32_t> as CapEndAlarm;
interface Alarm<TSymbolIEEE802154,uint32_t> as BLEAlarm;
interface Alarm<TSymbolIEEE802154,uint32_t> as IndirectTxWaitAlarm;
interface Alarm<TSymbolIEEE802154,uint32_t> as BroadcastAlarm;
interface Resource as Token;
interface GetNow<bool> as IsTokenRequested;
interface ResourceTransfer as TokenToCfp;
interface ResourceTransferred as TokenTransferred;
interface SuperframeStructure;
interface GetNow<bool> as IsRxEnableActive;
interface Get<ieee154_txframe_t*> as GetIndirectTxFrame;
interface Notify<bool> as RxEnableStateChange;
interface GetNow<bool> as IsTrackingBeacons;
interface FrameUtility;
interface SlottedCsmaCa;
interface RadioRx;
interface RadioOff;
interface MLME_GET;
interface MLME_SET;
interface TimeCalc;
interface Leds;
interface SetNow<ieee154_cap_frame_backup_t*> as FrameBackup;
interface GetNow<ieee154_cap_frame_backup_t*> as FrameRestore;
interface StdControl as TrackSingleBeacon;
}
}
implementation
{
typedef enum {
SWITCH_OFF,
WAIT_FOR_RXDONE,
WAIT_FOR_TXDONE,
DO_NOTHING,
} next_state_t;
typedef enum {
INDIRECT_TX_ALARM,
BROADCAST_ALARM,
NO_ALARM,
} rx_alarm_t;
enum {
COORD_ROLE = (sfDirection == OUTGOING_SUPERFRAME),
DEVICE_ROLE = !COORD_ROLE,
};
/* state / frame management */
norace bool m_lock;
norace bool m_resume;
norace ieee154_txframe_t *m_currentFrame;
norace ieee154_txframe_t *m_bcastFrame;
norace ieee154_txframe_t *m_lastFrame;
norace uint16_t m_remainingBackoff;
/* variables for the slotted CSMA-CA */
norace ieee154_csma_t m_csma;
norace ieee154_macMaxBE_t m_BE;
norace ieee154_macMaxCSMABackoffs_t m_macMaxCSMABackoffs;
norace ieee154_macMaxBE_t m_macMaxBE;
norace ieee154_macMaxFrameRetries_t m_macMaxFrameRetries;
norace ieee154_status_t m_txStatus;
norace uint32_t m_transactionTime;
norace bool m_indirectTxPending = FALSE;
norace bool m_broadcastRxPending;
norace ieee154_macMaxFrameTotalWaitTime_t m_macMaxFrameTotalWaitTime;
/* function / task prototypes */
void stopAllAlarms();
next_state_t tryReceive(rx_alarm_t alarmType);
next_state_t tryTransmit();
next_state_t trySwitchOff();
void backupCurrentFrame();
void restoreFrameFromBackup();
void updateState();
void setCurrentFrame(ieee154_txframe_t *frame);
void signalTxBroadcastDone(ieee154_txframe_t *frame, ieee154_status_t error);
task void signalTxDoneTask();
task void setupTxBroadcastTask();
task void wasRxEnabledTask();
#ifdef TKN154_DEBUG
enum {
HEADER_STR_LEN = 27,
DBG_STR_SIZE = 250,
};
norace uint16_t m_dbgNumEntries;
norace char m_dbgStr[HEADER_STR_LEN + DBG_STR_SIZE] = "updateState() transitions: ";
void dbg_push_state(uint8_t state) {
if (m_dbgNumEntries < DBG_STR_SIZE-3)
m_dbgStr[HEADER_STR_LEN + m_dbgNumEntries++] = '0' + state;
}
void dbg_flush_state() {
m_dbgStr[HEADER_STR_LEN + m_dbgNumEntries++] = '\n';
m_dbgStr[HEADER_STR_LEN + m_dbgNumEntries++] = 0;
dbg_serial("SlottedFrameDispatchP",m_dbgStr);
m_dbgNumEntries = 0;
}
#else
#define dbg_push_state(X)
#define dbg_flush_state()
#endif
command error_t Reset.init()
{
if (m_currentFrame)
signal FrameTx.transmitDone(m_currentFrame, IEEE154_TRANSACTION_OVERFLOW);
if (m_lastFrame)
signal FrameTx.transmitDone(m_lastFrame, IEEE154_TRANSACTION_OVERFLOW);
if (m_bcastFrame)
signalTxBroadcastDone(m_bcastFrame, IEEE154_TRANSACTION_OVERFLOW);
m_currentFrame = m_lastFrame = m_bcastFrame = NULL;
stopAllAlarms();
return SUCCESS;
}
async event void TokenTransferred.transferred()
{
// we got the token, i.e. CAP has just started
uint32_t capDuration = (uint32_t) call SuperframeStructure.numCapSlots() *
(uint32_t) call SuperframeStructure.sfSlotDuration();
uint16_t guardTime = call SuperframeStructure.guardTime();
dbg_serial("SlottedFrameDispatchP", "Got token, remaining CAP time: %lu\n",
call SuperframeStructure.sfStartTime() + capDuration - guardTime - call CapEndAlarm.getNow());
if (DEVICE_ROLE && !call IsTrackingBeacons.getNow()) {
// very rare case:
// this can only happen, if we're on a beacon-enabled PAN, not tracking beacons,
// and searched but didn't find a beacon for aBaseSuperframeDuration*(2n+1) symbols
// we'd actually have to transmit the current frame using unslotted CSMA-CA
// but we don't have that functionality available... signal FAIL...
m_lastFrame = m_currentFrame;
m_currentFrame = NULL;
m_txStatus = IEEE154_NO_BEACON;
dbg_serial("SlottedFrameDispatchP", "CAP component got token, remaining time: %lu\n");
post signalTxDoneTask();
return;
} else if (capDuration < guardTime) {
// CAP is too short to do anything practical
dbg_serial("SlottedFrameDispatchP", "CAP too short!\n");
call TokenToCfp.transfer();
return;
} else {
capDuration -= guardTime;
if (DEVICE_ROLE)
m_broadcastRxPending = call SuperframeStructure.isBroadcastPending();
else {
// COORD_ROLE
if (m_bcastFrame != NULL) {
// we have to transmit a broadcast frame immediately; this
// may require to a backup of the previously active frame
// and a reinitializing the CSMA parameters -> will do it
// in task context and then continue
m_lock = TRUE;
post setupTxBroadcastTask();
dbg_serial("SlottedFrameDispatchP", "Preparing broadcast.\n");
}
}
call CapEndAlarm.startAt(call SuperframeStructure.sfStartTime(), capDuration);
if (call SuperframeStructure.battLifeExtDuration() > 0)
call BLEAlarm.startAt(call SuperframeStructure.sfStartTime(), call SuperframeStructure.battLifeExtDuration());
}
updateState();
}
command ieee154_status_t FrameTx.transmit(ieee154_txframe_t *frame)
{
if (m_currentFrame != NULL) {
// we've not finished transmitting the current frame yet
dbg_serial("SlottedFrameDispatchP", "Overflow\n");
return IEEE154_TRANSACTION_OVERFLOW;
} else {
setCurrentFrame(frame);
dbg("SlottedFrameDispatchP", "New frame to transmit, DSN: %lu\n", (uint32_t) MHR(frame)[MHR_INDEX_SEQNO]);
// a beacon must be found before transmitting in a beacon-enabled PAN
if (DEVICE_ROLE && !call IsTrackingBeacons.getNow()) {
call TrackSingleBeacon.start();
dbg_serial("SlottedFrameDispatchP", "Tracking single beacon now\n");
// we'll receive the Token after a beacon was found or after
// aBaseSuperframeDuration*(2n+1) symbols if none was found
}
updateState();
return IEEE154_SUCCESS;
}
}
task void setupTxBroadcastTask()
{
ieee154_macDSN_t tmp;
ieee154_txframe_t *oldFrame = m_currentFrame;
if (COORD_ROLE) {
if (m_bcastFrame != NULL) {
// broadcasts should be transmitted *immediately* after the beacon,
// which may interrupt a pending transmit operation from the previous
// CAP; back up the last active frame configuration (may be none)
// and restore it after the broadcast frame has been transmitted;
// do this through interfaces and don't wire them for DEVICE_ROLE,
// so we don't waste the RAM of devices
backupCurrentFrame();
setCurrentFrame(m_bcastFrame);
if (oldFrame) {
// now the sequence number are out of order... swap them back
tmp = m_bcastFrame->header->mhr[MHR_INDEX_SEQNO];
m_bcastFrame->header->mhr[MHR_INDEX_SEQNO] =
oldFrame->header->mhr[MHR_INDEX_SEQNO];
oldFrame->header->mhr[MHR_INDEX_SEQNO] = tmp;
}
}
}
m_lock = FALSE;
updateState();
}
void setCurrentFrame(ieee154_txframe_t *frame)
{
ieee154_macDSN_t dsn = call MLME_GET.macDSN();
frame->header->mhr[MHR_INDEX_SEQNO] = dsn++;
call MLME_SET.macDSN(dsn);
m_csma.NB = 0;
m_csma.macMaxCsmaBackoffs = m_macMaxCSMABackoffs = call MLME_GET.macMaxCSMABackoffs();
m_csma.macMaxBE = m_macMaxBE = call MLME_GET.macMaxBE();
m_csma.BE = call MLME_GET.macMinBE();
if (call MLME_GET.macBattLifeExt() && m_csma.BE > 2)
m_csma.BE = 2;
m_BE = m_csma.BE;
if (COORD_ROLE && call GetIndirectTxFrame.get() == frame)
m_macMaxFrameRetries = 0; // this is an indirect transmissions (never retransmit)
else
m_macMaxFrameRetries = call MLME_GET.macMaxFrameRetries();
m_transactionTime = IEEE154_SHR_DURATION +
(frame->headerLen + frame->payloadLen + 2) * IEEE154_SYMBOLS_PER_OCTET; // extra 2 for CRC
if (frame->header->mhr[MHR_INDEX_FC1] & FC1_ACK_REQUEST)
m_transactionTime += (IEEE154_aTurnaroundTime + IEEE154_aUnitBackoffPeriod +
11 * IEEE154_SYMBOLS_PER_OCTET); // 11 byte for the ACK PPDU
// if (frame->headerLen + frame->payloadLen > IEEE154_aMaxSIFSFrameSize)
// m_transactionTime += call MLME_GET.macMinLIFSPeriod();
// else
// m_transactionTime += call MLME_GET.macMinSIFSPeriod();
m_macMaxFrameTotalWaitTime = call MLME_GET.macMaxFrameTotalWaitTime();
m_currentFrame = frame;
}
void stopAllAlarms()
{
call CapEndAlarm.stop();
if (DEVICE_ROLE) {
call IndirectTxWaitAlarm.stop();
call BroadcastAlarm.stop();
}
call BLEAlarm.stop();
}
/**
* The updateState() function is called whenever something happened that
* might require a state transition; it implements a lock mechanism (m_lock)
* to prevent race conditions. Whenever the lock is set a "done"-event (from
* the SlottedCsmaCa/RadioRx/RadioOff interface) is pending and will "soon"
* unset the lock (and then updateState() will called again). The
* updateState() function decides about the next state by checking a list of
* possible current states ordered by priority, e.g. it first always checks
* whether the CAP is still active. Calling this function more than necessary
* can do no harm.
*/
void updateState()
{
uint32_t capDuration;
next_state_t next;
atomic {
// long atomics are bad... but in this block, once the/ current state has
// been determined only one branch will/ be taken (there are no loops)
if (m_lock || !call Token.isOwner())
return;
m_lock = TRUE; // lock
capDuration = (uint32_t) call SuperframeStructure.numCapSlots() *
(uint32_t) call SuperframeStructure.sfSlotDuration();
// Check 1: has the CAP finished?
if ((COORD_ROLE || call IsTrackingBeacons.getNow()) &&
(call TimeCalc.hasExpired(call SuperframeStructure.sfStartTime(),
capDuration - call SuperframeStructure.guardTime()) ||
!call CapEndAlarm.isRunning())) {
dbg_push_state(1);
if (call RadioOff.isOff()) {
stopAllAlarms(); // may still fire, but is locked through isOwner()
if (DEVICE_ROLE && m_indirectTxPending)
signal IndirectTxWaitAlarm.fired();
m_broadcastRxPending = FALSE;
if (COORD_ROLE && m_bcastFrame) {
// didn't manage to transmit a broadcast
restoreFrameFromBackup();
signalTxBroadcastDone(m_bcastFrame, IEEE154_CHANNEL_ACCESS_FAILURE);
m_bcastFrame = NULL;
}
m_lock = FALSE; // unlock
dbg_flush_state();
dbg_serial("SlottedFrameDispatchP", "Handing over to CFP.\n");
call TokenToCfp.transfer();
return;
} else
next = SWITCH_OFF;
}
// Check 2: should a broadcast frame be received/transmitted
// immediately at the start of CAP?
else if (DEVICE_ROLE && m_broadcastRxPending) {
// receive a broadcast from coordinator
dbg_push_state(2);
next = tryReceive(BROADCAST_ALARM);
} else if (COORD_ROLE && m_bcastFrame) {
dbg_push_state(2);
next = tryTransmit();
}
// Check 3: was an indirect transmission successfully started
// and are we now waiting for a frame from the coordinator?
else if (DEVICE_ROLE && m_indirectTxPending) {
dbg_push_state(3);
next = tryReceive(INDIRECT_TX_ALARM);
}
// Check 4: is some other operation (like MLME-SCAN or MLME-RESET) pending?
else if (call IsTokenRequested.getNow()) {
dbg_push_state(4);
if (call RadioOff.isOff()) {
stopAllAlarms(); // may still fire, but is locked through isOwner()
// nothing more to do... just release the Token
m_lock = FALSE; // unlock
dbg_serial("SlottedFrameDispatchP", "Token requested: Handing over to CFP.\n");
call TokenToCfp.transfer();
return;
} else
next = SWITCH_OFF;
}
// Check 5: is battery life extension (BLE) active and
// has the BLE period expired?
else if (call SuperframeStructure.battLifeExtDuration() > 0 &&
call TimeCalc.hasExpired(call SuperframeStructure.sfStartTime(),
call SuperframeStructure.battLifeExtDuration()) &&
!call IsRxEnableActive.getNow()) {
dbg_push_state(5);
next = trySwitchOff();
}
// Check 6: is there a frame ready to transmit?
else if (m_currentFrame != NULL) {
dbg_push_state(6);
next = tryTransmit();
}
// Check 7: should we be in receive mode?
else if (COORD_ROLE || call IsRxEnableActive.getNow()) {
dbg_push_state(7);
next = tryReceive(NO_ALARM);
if (next == DO_NOTHING) {
// this means there is an active MLME_RX_ENABLE.request
// and the radio was just switched to Rx mode - signal
// a notify event to inform the respective component
post wasRxEnabledTask();
}
}
// Check 8: just make sure the radio is switched off
else {
dbg_push_state(8);
next = trySwitchOff();
if (next == DO_NOTHING && (DEVICE_ROLE && capDuration == 0)) {
// nothing more to do... just release the Token
stopAllAlarms(); // may still fire, but is locked through isOwner()
m_lock = FALSE; // unlock
dbg_serial("SlottedFrameDispatchP", "Releasing token\n");
call Token.release();
return;
}
}
// if there is nothing to do, then we must clear the lock
if (next == DO_NOTHING)
m_lock = FALSE;
} // atomic
// put next state in operation (possibly keeping the lock)
switch (next)
{
case SWITCH_OFF: ASSERT(call RadioOff.off() == SUCCESS); break;
case WAIT_FOR_RXDONE: break;
case WAIT_FOR_TXDONE: break;
case DO_NOTHING: break;
}
}
next_state_t tryTransmit()
{
// tries to transmit m_currentFrame
uint32_t capDuration = (uint32_t) call SuperframeStructure.numCapSlots() *
(uint32_t) call SuperframeStructure.sfSlotDuration();
next_state_t next;
if (!call RadioOff.isOff())
next = SWITCH_OFF;
else {
uint32_t dtMax = capDuration - call SuperframeStructure.guardTime() - m_transactionTime;
// round to backoff boundary
dtMax = dtMax + (IEEE154_aUnitBackoffPeriod - (dtMax % IEEE154_aUnitBackoffPeriod));
if (dtMax > capDuration)
dtMax = 0;
if (call SuperframeStructure.battLifeExtDuration() > 0) {
// battery life extension
uint16_t bleLen = call SuperframeStructure.battLifeExtDuration();
if (bleLen < dtMax)
dtMax = bleLen;
}
if (call TimeCalc.hasExpired(call SuperframeStructure.sfStartTime(), dtMax))
next = DO_NOTHING; // frame doesn't fit in the remaining CAP
else {
error_t res;
res = call SlottedCsmaCa.transmit(m_currentFrame, &m_csma,
call SuperframeStructure.sfStartTimeRef(), dtMax, m_resume, m_remainingBackoff);
dbg("SlottedFrameDispatchP", "SlottedCsmaCa.transmit() -> %lu\n", (uint32_t) res);
next = WAIT_FOR_TXDONE; // this will NOT clear the lock
}
}
return next;
}
next_state_t tryReceive(rx_alarm_t alarmType)
{
next_state_t next;
if (call RadioRx.isReceiving())
next = DO_NOTHING;
else if (!call RadioOff.isOff())
next = SWITCH_OFF;
else {
call RadioRx.enableRx(0, 0);
switch (alarmType)
{
case INDIRECT_TX_ALARM: call IndirectTxWaitAlarm.start(m_macMaxFrameTotalWaitTime); break;
case BROADCAST_ALARM: call BroadcastAlarm.start(m_macMaxFrameTotalWaitTime); break;
case NO_ALARM: break;
}
next = WAIT_FOR_RXDONE;
}
return next;
}
next_state_t trySwitchOff()
{
next_state_t next;
if (call RadioOff.isOff())
next = DO_NOTHING;
else
next = SWITCH_OFF;
return next;
}
async event void RadioOff.offDone() { m_lock = FALSE; updateState();}
async event void RadioRx.enableRxDone() { m_lock = FALSE; updateState();}
async event void CapEndAlarm.fired() {
dbg_serial("SlottedFrameDispatchP", "CapEndAlarm.fired()\n");
updateState();
}
async event void BLEAlarm.fired() { updateState();}
event void RxEnableStateChange.notify(bool whatever) { updateState();}
async event void BroadcastAlarm.fired() { m_broadcastRxPending = FALSE; updateState();}
async event void IndirectTxWaitAlarm.fired()
{
atomic {
if (m_indirectTxPending) {
m_indirectTxPending = FALSE;
post signalTxDoneTask();
}
}
}
async event void SlottedCsmaCa.transmitDone(ieee154_txframe_t *frame, ieee154_csma_t *csma,
bool ackPendingFlag, uint16_t remainingBackoff, error_t result)
{
bool done = TRUE;
dbg("SlottedFrameDispatchP", "SlottedCsmaCa.transmitDone() -> %lu\n", (uint32_t) result);
m_resume = FALSE;
switch (result)
{
case SUCCESS:
// frame was successfully transmitted, if ACK was requested
// then a matching ACK was successfully received as well
m_txStatus = IEEE154_SUCCESS;
if (DEVICE_ROLE && frame->payload[0] == CMD_FRAME_DATA_REQUEST &&
((frame->header->mhr[MHR_INDEX_FC1]) & FC1_FRAMETYPE_MASK) == FC1_FRAMETYPE_CMD) {
// this was a data request frame
m_txStatus = IEEE154_NO_DATA; // pessimistic
if (ackPendingFlag) {
// the coordinator has data for us; switch to Rx
// to complete the indirect transmission
m_indirectTxPending = TRUE;
m_lastFrame = m_currentFrame;
m_currentFrame = NULL;
ASSERT(call RadioRx.enableRx(0, 0) == SUCCESS);
return;
}
}
break;
case FAIL:
// The CSMA-CA algorithm failed: the frame was not transmitted,
// because channel was never idle
m_txStatus = IEEE154_CHANNEL_ACCESS_FAILURE;
break;
case ENOACK:
// frame was transmitted, but we didn't receive an ACK (although
// we requested an one). note: coordinator never retransmits an
// indirect transmission (see above)
if (m_macMaxFrameRetries > 0) {
// retransmit: reinitialize CSMA-CA parameters
done = FALSE;
m_csma.NB = 0;
m_csma.macMaxCsmaBackoffs = m_macMaxCSMABackoffs;
m_csma.macMaxBE = m_macMaxBE;
m_csma.BE = m_BE;
m_macMaxFrameRetries -= 1;
} else
m_txStatus = IEEE154_NO_ACK;
break;
case EINVAL: // DEBUG!!!
dbg_serial("SlottedFrameDispatchP", "EINVAL returned by transmitDone()!\n");
// fall through
case ERETRY:
// frame was not transmitted, because the transaction does not
// fit in the remaining CAP (in beacon-enabled PANs only)
dbg_serial("SlottedFrameDispatchP", "Transaction didn't fit, current BE: %lu\n", (uint32_t) csma->BE);
m_resume = TRUE;
m_remainingBackoff = remainingBackoff;
done = FALSE;
m_lock = FALSE; // debug! problem: if CAP endalarm has fired it's a deadlock!
if (!call CapEndAlarm.isRunning())
updateState();
return;
break;
default:
ASSERT(0);
break;
}
if (COORD_ROLE && frame == m_bcastFrame) {
// always signal result of broadcast transmissions immediately
restoreFrameFromBackup();
signalTxBroadcastDone(m_bcastFrame, (!done) ? IEEE154_CHANNEL_ACCESS_FAILURE : m_txStatus);
m_bcastFrame = NULL;
} else if (done) {
m_lastFrame = m_currentFrame;
m_currentFrame = NULL;
post signalTxDoneTask();
}
m_lock = FALSE;
updateState();
}
task void signalTxDoneTask()
{
ieee154_txframe_t *lastFrame = m_lastFrame;
ieee154_status_t status = m_txStatus;
m_indirectTxPending = FALSE;
m_lastFrame = NULL; // only now can the next transmission can begin
if (lastFrame) {
dbg("SlottedFrameDispatchP", "Transmit done, DSN: %lu, result: 0x%lx\n",
(uint32_t) MHR(lastFrame)[MHR_INDEX_SEQNO], (uint32_t) status);
signal FrameTx.transmitDone(lastFrame, status);
}
updateState();
}
event message_t* RadioRx.received(message_t* frame, const ieee154_timestamp_t *timestamp)
{
// received a frame -> find out frame type and
// signal it to responsible client component
uint8_t *payload = (uint8_t *) frame->data;
uint8_t *mhr = MHR(frame);
uint8_t frameType = mhr[MHR_INDEX_FC1] & FC1_FRAMETYPE_MASK;
if (frameType == FC1_FRAMETYPE_CMD)
frameType += payload[0];
atomic {
if (DEVICE_ROLE && m_indirectTxPending) {
message_t* frameBuf;
call IndirectTxWaitAlarm.stop();
// TODO: check!
//if (frame->payloadLen)
// is this frame from our coordinator? hmm... we cannot say/ with
// certainty, because we might only know either the coordinator
// extended or short address (and the frame could/ have been sent
// with the other addressing mode) ??
m_txStatus = IEEE154_SUCCESS;
frameBuf = signal FrameExtracted.received[frameType](frame, m_lastFrame);
signal IndirectTxWaitAlarm.fired();
return frameBuf;
} else
return signal FrameRx.received[frameType](frame);
}
}
void backupCurrentFrame()
{
ieee154_cap_frame_backup_t backup = {m_currentFrame, m_csma, m_transactionTime};
call FrameBackup.setNow(&backup);
}
void restoreFrameFromBackup()
{
ieee154_cap_frame_backup_t *backup = call FrameRestore.getNow();
if (backup != NULL) {
m_currentFrame = backup->frame;
memcpy(&m_csma, &backup->csma, sizeof(ieee154_csma_t));
m_transactionTime = backup->transactionTime;
}
}
async command ieee154_status_t BroadcastTx.transmitNow(ieee154_txframe_t *frame)
{
// if this command is called then it is (MUST be) called only just before
// the token is transferred to this component and it is then called
// only once per CAP (max. one broadcast is allowed after a beacon
// transmission)
atomic {
if (!call Token.isOwner() && m_bcastFrame == NULL) {
m_bcastFrame = frame;
return IEEE154_SUCCESS;
} else {
ASSERT(0);
return IEEE154_TRANSACTION_OVERFLOW;
}
}
}
void signalTxBroadcastDone(ieee154_txframe_t *frame, ieee154_status_t error)
{
signal BroadcastTx.transmitNowDone(frame, error);
}
task void wasRxEnabledTask()
{
signal WasRxEnabled.notify(TRUE);
}
event void Token.granted()
{
ASSERT(0); // should never happen
}
default event void FrameTx.transmitDone(ieee154_txframe_t *data, ieee154_status_t status) {}
default event message_t* FrameRx.received[uint8_t client](message_t* data) {return data;}
default async command bool IsRxEnableActive.getNow() {return FALSE;}
default async command void IndirectTxWaitAlarm.start(uint32_t dt) {ASSERT(0);}
default async command void IndirectTxWaitAlarm.stop() {ASSERT(0);}
default async command void IndirectTxWaitAlarm.startAt(uint32_t t0, uint32_t dt) {ASSERT(0);}
default async command void BroadcastAlarm.start(uint32_t dt) {ASSERT(0);}
default async command void BroadcastAlarm.stop() {ASSERT(0);}
default async command void BroadcastAlarm.startAt(uint32_t t0, uint32_t dt) {ASSERT(0);}
default async command bool SuperframeStructure.isBroadcastPending() { return FALSE;}
default async event void BroadcastTx.transmitNowDone(ieee154_txframe_t *frame, ieee154_status_t status) {}
default event message_t* FrameExtracted.received[uint8_t client](message_t* msg, ieee154_txframe_t *txFrame) {return msg;}
default async command error_t FrameBackup.setNow(ieee154_cap_frame_backup_t* val) {return FAIL;}
default async command ieee154_cap_frame_backup_t* FrameRestore.getNow() {return NULL;}
default command error_t TrackSingleBeacon.start() {return FAIL;}
command error_t WasRxEnabled.enable() {return FAIL;}
command error_t WasRxEnabled.disable() {return FAIL;}
}
--- NEW FILE: TKN154BeaconEnabledP.nc ---
/*
* 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: 1.1 $
* $Date: 2009/03/04 18:31:32 $
* @author Jan Hauer <hauer at tkn.tu-berlin.de>
* ========================================================================
*/
#include "TKN154_PHY.h"
#include "TKN154_MAC.h"
#include "TKN154_PIB.h"
#define IEEE154_BEACON_ENABLED_PAN TRUE
configuration TKN154BeaconEnabledP
{
provides
{
/* MCPS-SAP */
interface MCPS_DATA;
interface MCPS_PURGE;
interface Packet;
/* MLME-SAP */
interface MLME_ASSOCIATE;
interface MLME_BEACON_NOTIFY;
interface MLME_COMM_STATUS;
interface MLME_DISASSOCIATE;
interface MLME_GET;
/* interface MLME_GTS;*/
interface MLME_ORPHAN;
interface MLME_POLL;
interface MLME_RESET;
interface MLME_RX_ENABLE;
interface MLME_SCAN;
interface MLME_SET;
interface MLME_START;
interface MLME_SYNC;
interface MLME_SYNC_LOSS;
interface Notify<const void*> as PIBUpdate[uint8_t attributeID];
interface IEEE154Frame;
interface IEEE154BeaconFrame;
interface IEEE154TxBeaconPayload;
interface SplitControl as PromiscuousMode;
interface Get<uint64_t> as GetLocalExtendedAddress;
interface TimeCalc;
interface FrameUtility;
} uses {
interface RadioRx;
interface RadioTx;
interface RadioOff;
interface SlottedCsmaCa;
interface EnergyDetection;
interface SplitControl as PhySplitControl;
interface Set<bool> as RadioPromiscuousMode;
interface Alarm<TSymbolIEEE802154,uint32_t> as Alarm1;
interface Alarm<TSymbolIEEE802154,uint32_t> as Alarm2;
interface Alarm<TSymbolIEEE802154,uint32_t> as Alarm3;
interface Alarm<TSymbolIEEE802154,uint32_t> as Alarm4;
interface Alarm<TSymbolIEEE802154,uint32_t> as Alarm5;
interface Alarm<TSymbolIEEE802154,uint32_t> as Alarm6;
interface Alarm<TSymbolIEEE802154,uint32_t> as Alarm7;
interface Alarm<TSymbolIEEE802154,uint32_t> as Alarm8;
interface Alarm<TSymbolIEEE802154,uint32_t> as Alarm9;
interface Alarm<TSymbolIEEE802154,uint32_t> as Alarm10;
interface Alarm<TSymbolIEEE802154,uint32_t> as Alarm11;
interface Alarm<TSymbolIEEE802154,uint32_t> as Alarm12;
interface Timer<TSymbolIEEE802154> as Timer1;
interface Timer<TSymbolIEEE802154> as Timer2;
interface Timer<TSymbolIEEE802154> as Timer3;
interface Timer<TSymbolIEEE802154> as Timer4;
interface Timer<TSymbolIEEE802154> as Timer5;
interface LocalTime<TSymbolIEEE802154>;
interface Random;
interface Leds;
}
}
implementation
{
components DataP,
PibP,
RadioControlP,
IndirectTxP,
PollP,
#ifndef IEEE154_SCAN_DISABLED
ScanP,
#else
NoScanP as ScanP,
#endif
#ifndef IEEE154_ASSOCIATION_DISABLED
AssociateP,
#else
NoAssociateP as AssociateP,
#endif
#ifndef IEEE154_DISASSOCIATION_DISABLED
DisassociateP,
#else
NoDisassociateP as DisassociateP,
#endif
#ifndef IEEE154_BEACON_SYNC_DISABLED
BeaconSynchronizeP,
new FrameDispatchQueueP() as DeviceCapQueue,
new SlottedFrameDispatchP(INCOMING_SUPERFRAME) as DeviceCap,
#else
NoBeaconSynchronizeP as BeaconSynchronizeP,
new NoFrameDispatchQueueP() as DeviceCapQueue,
new NoSlottedFrameDispatchP(INCOMING_SUPERFRAME) as DeviceCap,
#endif
NoDeviceCfpP as DeviceCfp,
#ifndef IEEE154_BEACON_TX_DISABLED
BeaconTransmitP,
new FrameDispatchQueueP() as CoordCapQueue,
new SlottedFrameDispatchP(OUTGOING_SUPERFRAME) as CoordCap,
#else
NoBeaconTransmitP as BeaconTransmitP,
new NoFrameDispatchQueueP() as CoordCapQueue,
new NoSlottedFrameDispatchP(OUTGOING_SUPERFRAME) as CoordCap,
#endif
NoCoordCfpP as CoordCfp,
#ifndef IEEE154_RXENABLE_DISABLED
RxEnableP,
#else
NoRxEnableP as RxEnableP,
#endif
#ifndef IEEE154_PROMISCUOUS_MODE_DISABLED
PromiscuousModeP,
#else
NoPromiscuousModeP as PromiscuousModeP,
#endif
#ifndef IEEE154_COORD_REALIGNMENT_DISABLED
CoordRealignmentP,
#else
NoCoordRealignmentP as CoordRealignmentP,
#endif
#ifndef IEEE154_COORD_BROADCAST_DISABLED
CoordBroadcastP,
#else
NoCoordBroadcastP as CoordBroadcastP,
#endif
new PoolC(ieee154_txframe_t, TXFRAME_POOL_SIZE) as TxFramePoolP,
new PoolC(ieee154_txcontrol_t, TXCONTROL_POOL_SIZE) as TxControlPoolP,
new QueueC(ieee154_txframe_t*, CAP_TX_QUEUE_SIZE) as DeviceCapQueueC,
new QueueC(ieee154_txframe_t*, CAP_TX_QUEUE_SIZE) as CoordCapQueueC,
new QueueC(ieee154_txframe_t*, CAP_TX_QUEUE_SIZE) as BroadcastQueueC;
components MainC;
/* MCPS */
MCPS_DATA = DataP;
MCPS_PURGE = DataP;
/* MLME */
MLME_START = BeaconTransmitP;
MLME_ASSOCIATE = AssociateP;
MLME_DISASSOCIATE = DisassociateP;
MLME_BEACON_NOTIFY = BeaconSynchronizeP;
MLME_BEACON_NOTIFY = ScanP;
MLME_COMM_STATUS = AssociateP;
MLME_COMM_STATUS = CoordRealignmentP;
MLME_GET = PibP;
MLME_ORPHAN = CoordRealignmentP;
/* MLME_GTS = CfpTransmitP;*/
MLME_POLL = PollP;
MLME_RESET = PibP;
MLME_RX_ENABLE = RxEnableP;
MLME_SCAN = ScanP;
MLME_SET = PibP;
MLME_SYNC = BeaconSynchronizeP;
MLME_SYNC_LOSS = BeaconSynchronizeP;
IEEE154Frame = PibP;
IEEE154BeaconFrame = PibP;
PromiscuousMode = PromiscuousModeP;
GetLocalExtendedAddress = PibP.GetLocalExtendedAddress;
IEEE154TxBeaconPayload = BeaconTransmitP;
Packet = PibP;
TimeCalc = PibP;
FrameUtility = PibP;
/* ----------------------- Scanning (MLME-SCAN) ----------------------- */
components new RadioClientC() as ScanRadioClient;
PibP.MacReset -> ScanP;
ScanP.MLME_GET -> PibP;
ScanP.MLME_SET -> PibP.MLME_SET;
ScanP.EnergyDetection = EnergyDetection;
ScanP.RadioRx -> ScanRadioClient;
ScanP.RadioTx -> ScanRadioClient;
ScanP.Frame -> PibP;
ScanP.BeaconFrame -> PibP;
ScanP.RadioOff -> ScanRadioClient;
ScanP.ScanTimer = Timer1;
ScanP.TxFramePool -> TxFramePoolP;
ScanP.TxControlPool -> TxControlPoolP;
ScanP.Token -> ScanRadioClient;
ScanP.Leds = Leds;
ScanP.FrameUtility -> PibP;
/* ----------------- Beacon Transmission (MLME-START) ----------------- */
components new RadioClientC() as BeaconTxRadioClient;
PibP.MacReset -> BeaconTransmitP;
BeaconTransmitP.PIBUpdate[IEEE154_macAssociationPermit] -> PibP.PIBUpdate[IEEE154_macAssociationPermit];
BeaconTransmitP.PIBUpdate[IEEE154_macGTSPermit] -> PibP.PIBUpdate[IEEE154_macGTSPermit];
BeaconTransmitP.BeaconSendAlarm = Alarm1;
BeaconTransmitP.BeaconPayloadUpdateTimer = Timer2;
BeaconTransmitP.RadioOff -> BeaconTxRadioClient;
BeaconTransmitP.BeaconTx -> BeaconTxRadioClient;
BeaconTransmitP.MLME_SET -> PibP.MLME_SET;
BeaconTransmitP.MLME_GET -> PibP;
BeaconTransmitP.SetMacSuperframeOrder -> PibP.SetMacSuperframeOrder;
BeaconTransmitP.SetMacBeaconTxTime -> PibP.SetMacBeaconTxTime;
BeaconTransmitP.SetMacPanCoordinator -> PibP.SetMacPanCoordinator;
BeaconTransmitP.Token -> BeaconTxRadioClient;
BeaconTransmitP.IsTokenRequested -> BeaconTxRadioClient;
BeaconTransmitP.TokenTransferred -> BeaconTxRadioClient;
BeaconTransmitP.TokenToBroadcast -> BeaconTxRadioClient;
BeaconTransmitP.RealignmentBeaconEnabledTx -> CoordBroadcastP.RealignmentTx;
BeaconTransmitP.RealignmentNonBeaconEnabledTx -> CoordCapQueue.FrameTx[unique(CAP_TX_CLIENT)];
BeaconTransmitP.BeaconRequestRx -> CoordCap.FrameRx[FC1_FRAMETYPE_CMD + CMD_FRAME_BEACON_REQUEST];
BeaconTransmitP.GtsInfoWrite -> CoordCfp.GtsInfoWrite;
BeaconTransmitP.PendingAddrSpecUpdated -> IndirectTxP.PendingAddrSpecUpdated;
BeaconTransmitP.PendingAddrWrite -> IndirectTxP.PendingAddrWrite;
BeaconTransmitP.FrameUtility -> PibP.FrameUtility;
BeaconTransmitP.IsTrackingBeacons -> BeaconSynchronizeP.IsTrackingBeacons;
BeaconTransmitP.IncomingSF -> BeaconSynchronizeP.IncomingSF;
BeaconTransmitP.GetSetRealignmentFrame -> CoordRealignmentP;
BeaconTransmitP.IsBroadcastReady -> CoordBroadcastP.IsBroadcastReady;
BeaconTransmitP.TimeCalc -> PibP;
BeaconTransmitP.Leds = Leds;
BeaconTxRadioClient.TransferTo -> CoordBroadcastRadioClient.TransferFrom;
/* ------------------ Beacon Tracking (MLME-SYNC) ------------------ */
components new RadioClientC() as SyncRadioClient;
PibP.MacReset -> BeaconSynchronizeP;
BeaconSynchronizeP.MLME_SET -> PibP.MLME_SET;
BeaconSynchronizeP.MLME_GET -> PibP;
BeaconSynchronizeP.TrackAlarm = Alarm2;
BeaconSynchronizeP.FrameUtility -> PibP;
BeaconSynchronizeP.Frame -> PibP;
BeaconSynchronizeP.BeaconFrame -> PibP;
BeaconSynchronizeP.BeaconRx -> SyncRadioClient;
BeaconSynchronizeP.RadioOff -> SyncRadioClient;
BeaconSynchronizeP.DataRequest -> PollP.DataRequest[SYNC_POLL_CLIENT];
BeaconSynchronizeP.Token -> SyncRadioClient;
BeaconSynchronizeP.IsTokenRequested -> SyncRadioClient;
BeaconSynchronizeP.TokenTransferred -> SyncRadioClient;
BeaconSynchronizeP.TokenToCap -> SyncRadioClient;
BeaconSynchronizeP.TimeCalc -> PibP;
BeaconSynchronizeP.CoordRealignmentRx -> DeviceCap.FrameRx[FC1_FRAMETYPE_CMD + CMD_FRAME_COORDINATOR_REALIGNMENT];
BeaconSynchronizeP.Leds = Leds;
SyncRadioClient.TransferTo -> DeviceCapRadioClient.TransferFrom;
/* -------------------- Association (MLME-ASSOCIATE) -------------------- */
PibP.MacReset -> AssociateP;
AssociateP.AssociationRequestRx -> CoordCap.FrameRx[FC1_FRAMETYPE_CMD + CMD_FRAME_ASSOCIATION_REQUEST];
AssociateP.AssociationRequestTx -> DeviceCapQueue.FrameTx[unique(CAP_TX_CLIENT)];
AssociateP.AssociationResponseExtracted -> DeviceCap.FrameExtracted[FC1_FRAMETYPE_CMD + CMD_FRAME_ASSOCIATION_RESPONSE];
AssociateP.AssociationResponseTx -> IndirectTxP.FrameTx[unique(INDIRECT_TX_CLIENT)];
AssociateP.DataRequest -> PollP.DataRequest[ASSOCIATE_POLL_CLIENT];
AssociateP.ResponseTimeout = Timer3;
AssociateP.TxFramePool -> TxFramePoolP;
AssociateP.TxControlPool -> TxControlPoolP;
AssociateP.MLME_GET -> PibP;
AssociateP.MLME_SET -> PibP.MLME_SET;
AssociateP.FrameUtility -> PibP;
AssociateP.Frame -> PibP;
AssociateP.LocalExtendedAddress -> PibP.GetLocalExtendedAddress;
/* --------------- Disassociation (MLME-DISASSOCIATE) --------------- */
PibP.MacReset -> DisassociateP;
DisassociateP.DisassociationIndirectTx -> IndirectTxP.FrameTx[unique(INDIRECT_TX_CLIENT)];
DisassociateP.DisassociationDirectTx -> CoordCapQueue.FrameTx[unique(CAP_TX_CLIENT)];
DisassociateP.DisassociationToCoord -> DeviceCapQueue.FrameTx[unique(CAP_TX_CLIENT)];
DisassociateP.DisassociationDirectRxFromCoord ->
DeviceCap.FrameRx[FC1_FRAMETYPE_CMD + CMD_FRAME_DISASSOCIATION_NOTIFICATION];
DisassociateP.DisassociationExtractedFromCoord ->
DeviceCap.FrameExtracted[FC1_FRAMETYPE_CMD + CMD_FRAME_DISASSOCIATION_NOTIFICATION];
DisassociateP.DisassociationRxFromDevice ->
CoordCap.FrameRx[FC1_FRAMETYPE_CMD + CMD_FRAME_DISASSOCIATION_NOTIFICATION];
DisassociateP.TxFramePool -> TxFramePoolP;
DisassociateP.TxControlPool -> TxControlPoolP;
DisassociateP.MLME_GET -> PibP;
DisassociateP.FrameUtility -> PibP;
DisassociateP.Frame -> PibP;
DisassociateP.LocalExtendedAddress -> PibP.GetLocalExtendedAddress;
/* ------------------ Data Transmission (MCPS-DATA) ------------------- */
DataP.IsSendingBeacons -> BeaconTransmitP.IsSendingBeacons;
DataP.CoordCapRx -> CoordCap.FrameRx[FC1_FRAMETYPE_DATA];
DataP.DeviceCapTx -> DeviceCapQueue.FrameTx[unique(CAP_TX_CLIENT)];
DataP.CoordCapTx -> CoordCapQueue.FrameTx[unique(CAP_TX_CLIENT)];
DataP.DeviceCapRx -> PollP.DataRx;
DataP.DeviceCapRx -> PromiscuousModeP.FrameRx;
DataP.DeviceCapRx -> DeviceCap.FrameRx[FC1_FRAMETYPE_DATA];
DataP.TxFramePool -> TxFramePoolP;
DataP.BroadcastTx -> CoordBroadcastP.BroadcastDataFrame;
DataP.DeviceCfpTx -> DeviceCfp.CfpTx;
DataP.IndirectTx -> IndirectTxP.FrameTx[unique(INDIRECT_TX_CLIENT)];
DataP.FrameUtility -> PibP;
DataP.Frame -> PibP;
DataP.PurgeDirect -> DeviceCapQueue;
DataP.PurgeIndirect -> IndirectTxP;
DataP.PurgeGtsDevice -> DeviceCfp;
DataP.PurgeGtsCoord -> CoordCfp;
DataP.MLME_GET -> PibP;
DataP.Packet -> PibP;
DataP.Leds = Leds;
/* ------------------------ Polling (MLME-POLL) ----------------------- */
PibP.MacReset -> PollP;
PollP.PollTx -> DeviceCapQueue.FrameTx[unique(CAP_TX_CLIENT)];
PollP.DataExtracted -> DeviceCap.FrameExtracted[FC1_FRAMETYPE_DATA];
PollP.FrameUtility -> PibP;
PollP.TxFramePool -> TxFramePoolP;
PollP.TxControlPool -> TxControlPoolP;
PollP.MLME_GET -> PibP;
PollP.LocalExtendedAddress -> PibP.GetLocalExtendedAddress;
/* ---------------------- Indirect transmission ----------------------- */
PibP.MacReset -> IndirectTxP;
IndirectTxP.CoordCapTx -> CoordCapQueue.FrameTx[unique(CAP_TX_CLIENT)];
IndirectTxP.DataRequestRx -> CoordCap.FrameRx[FC1_FRAMETYPE_CMD + CMD_FRAME_DATA_REQUEST];
IndirectTxP.MLME_GET -> PibP;
IndirectTxP.FrameUtility -> PibP;
IndirectTxP.IndirectTxTimeout = Timer4;
IndirectTxP.TimeCalc -> PibP;
IndirectTxP.Leds = Leds;
/* ---------------------------- Realignment --------------------------- */
PibP.MacReset -> CoordRealignmentP;
CoordRealignmentP.CoordRealignmentTx -> CoordCapQueue.FrameTx[unique(CAP_TX_CLIENT)];
CoordRealignmentP.OrphanNotificationRx -> CoordCap.FrameRx[FC1_FRAMETYPE_CMD + CMD_FRAME_ORPHAN_NOTIFICATION];
CoordRealignmentP.FrameUtility -> PibP;
CoordRealignmentP.Frame -> PibP;
CoordRealignmentP.TxFramePool -> TxFramePoolP;
CoordRealignmentP.TxControlPool -> TxControlPoolP;
CoordRealignmentP.MLME_GET -> PibP;
CoordRealignmentP.LocalExtendedAddress -> PibP.GetLocalExtendedAddress;
/* ---------------------------- Broadcasts ---------------------------- */
components new RadioClientC() as CoordBroadcastRadioClient;
PibP.MacReset -> CoordBroadcastP;
CoordBroadcastP.TokenTransferred -> CoordBroadcastRadioClient;
CoordBroadcastP.TokenToCap -> CoordBroadcastRadioClient;
CoordBroadcastRadioClient.TransferTo -> CoordCapRadioClient.TransferFrom;
CoordBroadcastP.OutgoingSF -> BeaconTransmitP.OutgoingSF;
CoordBroadcastP.CapTransmitNow -> CoordCap.BroadcastTx;
CoordBroadcastP.Queue -> BroadcastQueueC;
CoordBroadcastP.Leds = Leds;
/* --------------------- CAP (incoming superframe) -------------------- */
PibP.FrameDispatchQueueReset -> DeviceCapQueue;
DeviceCapQueue.Queue -> DeviceCapQueueC;
DeviceCapQueue.FrameTxCsma -> DeviceCap;
PibP.FrameDispatchQueueReset -> CoordCapQueue;
CoordCapQueue.Queue -> CoordCapQueueC;
CoordCapQueue.FrameTxCsma -> CoordCap;
components new RadioClientC() as DeviceCapRadioClient;
PibP.FrameDispatchReset -> DeviceCap;
DeviceCap.CapEndAlarm = Alarm3;
DeviceCap.BLEAlarm = Alarm4;
DeviceCap.IndirectTxWaitAlarm = Alarm5;
DeviceCap.BroadcastAlarm = Alarm6;
DeviceCap.Token -> DeviceCapRadioClient;
DeviceCap.IsTokenRequested -> DeviceCapRadioClient;
DeviceCap.TokenToCfp -> DeviceCapRadioClient;
DeviceCap.TokenTransferred -> DeviceCapRadioClient;
DeviceCap.SuperframeStructure -> BeaconSynchronizeP.IncomingSF;
DeviceCap.IsRxEnableActive -> RxEnableP.IsRxEnableActive;
DeviceCap.GetIndirectTxFrame -> IndirectTxP;
DeviceCap.RxEnableStateChange -> RxEnableP.RxEnableStateChange;
DeviceCap.IsTrackingBeacons -> BeaconSynchronizeP.IsTrackingBeacons;
DeviceCap.FrameUtility -> PibP;
DeviceCap.SlottedCsmaCa -> DeviceCapRadioClient;
DeviceCap.RadioRx -> DeviceCapRadioClient;
DeviceCap.RadioOff -> DeviceCapRadioClient;
DeviceCap.MLME_GET -> PibP;
DeviceCap.MLME_SET -> PibP.MLME_SET;
DeviceCap.TimeCalc -> PibP;
DeviceCap.Leds = Leds;
DeviceCap.TrackSingleBeacon -> BeaconSynchronizeP.TrackSingleBeacon;
DeviceCapRadioClient.TransferTo -> DeviceCfpRadioClient.TransferFrom;
/* ---------------------- CAP (outgoing superframe) ------------------- */
components new RadioClientC() as CoordCapRadioClient,
new BackupP(ieee154_cap_frame_backup_t);
PibP.FrameDispatchReset -> CoordCap;
CoordCap.CapEndAlarm = Alarm7;
CoordCap.BLEAlarm = Alarm8;
CoordCap.Token -> CoordCapRadioClient;
CoordCap.TokenToCfp -> CoordCapRadioClient;
CoordCap.TokenTransferred -> CoordCapRadioClient;
CoordCap.IsTokenRequested -> CoordCapRadioClient;
CoordCap.SuperframeStructure -> BeaconTransmitP.OutgoingSF;
CoordCap.IsRxEnableActive -> RxEnableP.IsRxEnableActive;
CoordCap.GetIndirectTxFrame -> IndirectTxP;
CoordCap.RxEnableStateChange -> RxEnableP.RxEnableStateChange;
CoordCap.IsTrackingBeacons -> BeaconSynchronizeP.IsTrackingBeacons;
CoordCap.FrameUtility -> PibP;
CoordCap.SlottedCsmaCa -> CoordCapRadioClient;
CoordCap.RadioRx -> CoordCapRadioClient;
CoordCap.RadioOff -> CoordCapRadioClient;
CoordCap.MLME_GET -> PibP;
CoordCap.MLME_SET -> PibP.MLME_SET;
CoordCap.TimeCalc -> PibP;
CoordCap.Leds = Leds;
CoordCapRadioClient.TransferTo -> CoordCfpRadioClient.TransferFrom;
CoordCap.FrameBackup -> BackupP;
CoordCap.FrameRestore -> BackupP;
/* -------------------- GTS (incoming superframe) --------------------- */
components new RadioClientC() as DeviceCfpRadioClient;
PibP.MacReset -> DeviceCfp;
DeviceCfp.TokenTransferred -> DeviceCfpRadioClient;
DeviceCfp.TokenRequested -> DeviceCfpRadioClient;
DeviceCfp.TokenToBeaconSync -> DeviceCfpRadioClient;
DeviceCfp.IncomingSF -> BeaconSynchronizeP.IncomingSF;
DeviceCfp.CfpSlotAlarm = Alarm9;
DeviceCfp.CfpEndAlarm = Alarm10;
DeviceCfp.RadioTx -> DeviceCfpRadioClient;
DeviceCfp.RadioRx -> DeviceCfpRadioClient;
DeviceCfp.RadioOff -> DeviceCfpRadioClient;
DeviceCfp.MLME_GET -> PibP;
DeviceCfp.MLME_SET -> PibP.MLME_SET;
DeviceCfpRadioClient.TransferTo -> SyncRadioClient.TransferFrom;
/* -------------------- GTS (outgoing superframe) --------------------- */
components new RadioClientC() as CoordCfpRadioClient;
PibP.MacReset -> CoordCfp;
CoordCfp.TokenTransferred -> CoordCfpRadioClient;
CoordCfp.TokenRequested -> CoordCfpRadioClient;
CoordCfp.TokenToBeaconTransmit -> CoordCfpRadioClient;
CoordCfp.OutgoingSF -> BeaconTransmitP.OutgoingSF;
CoordCfp.CfpSlotAlarm = Alarm11;
CoordCfp.CfpEndAlarm = Alarm12;
CoordCfp.RadioTx -> CoordCfpRadioClient;
CoordCfp.RadioRx -> CoordCfpRadioClient;
CoordCfp.RadioOff -> CoordCfpRadioClient;
CoordCfp.MLME_GET -> PibP;
CoordCfp.MLME_SET -> PibP.MLME_SET;
CoordCfpRadioClient.TransferTo -> BeaconTxRadioClient.TransferFrom;
/* -------------------------- promiscuous mode ------------------------ */
components new RadioClientC() as PromiscuousModeRadioClient;
PibP.MacReset -> PromiscuousModeP;
PromiscuousModeP.Token -> PromiscuousModeRadioClient;
PromiscuousModeP.PromiscuousRx -> PromiscuousModeRadioClient;
PromiscuousModeP.RadioOff -> PromiscuousModeRadioClient;
PromiscuousModeP.RadioPromiscuousMode = RadioPromiscuousMode;
/* --------------------------- MLME-RX-ENABLE ------------------------ */
PibP.MacReset -> RxEnableP;
RxEnableP.IncomingSuperframeStructure -> BeaconSynchronizeP;
RxEnableP.OutgoingSuperframeStructure -> BeaconTransmitP;
RxEnableP.IsTrackingBeacons -> BeaconSynchronizeP.IsTrackingBeacons;
RxEnableP.IsSendingBeacons-> BeaconTransmitP.IsSendingBeacons;
RxEnableP.TimeCalc -> PibP.TimeCalc;
RxEnableP.WasRxEnabled -> DeviceCap.WasRxEnabled;
RxEnableP.WasRxEnabled -> CoordCap.WasRxEnabled;
RxEnableP.RxEnableTimer = Timer5;
/* ------------------------------- PIB -------------------------------- */
components new RadioClientC() as PibRadioClient;
PIBUpdate = PibP;
MainC.SoftwareInit -> PibP.LocalInit;
PibP.RadioControl = PhySplitControl;
PibP.Random = Random;
PibP.PromiscuousModeGet -> PromiscuousModeP;
PibP.LocalTime = LocalTime;
PibP.Token -> PibRadioClient;
PibP.RadioOff -> PibRadioClient;
/* ------------------------- Radio Control ---------------------------- */
RadioControlP.PhyTx = RadioTx;
RadioControlP.PhySlottedCsmaCa = SlottedCsmaCa;
RadioControlP.PhyRx = RadioRx;
RadioControlP.PhyRadioOff = RadioOff;
RadioControlP.RadioPromiscuousMode -> PromiscuousModeP;
RadioControlP.Leds = Leds;
}
--- NEW FILE: TKN154NonBeaconEnabledP.nc ---
/*
* 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: 1.1 $
* $Date: 2009/03/04 18:31:37 $
* @author Jan Hauer <hauer at tkn.tu-berlin.de>
* ========================================================================
*/
#include "TKN154_PHY.h"
#include "TKN154_MAC.h"
#include "TKN154_PIB.h"
#define IEEE154_BEACON_ENABLED_PAN FALSE
// TODO: check the wiring!!
configuration TKN154NonBeaconEnabledP
{
provides
{
/* MCPS-SAP */
interface MCPS_DATA;
interface MCPS_PURGE;
interface Packet;
/* MLME-SAP */
interface MLME_ASSOCIATE;
interface MLME_BEACON_NOTIFY;
interface MLME_COMM_STATUS;
interface MLME_DISASSOCIATE;
interface MLME_GET;
interface MLME_ORPHAN;
interface MLME_POLL;
interface MLME_RESET;
interface MLME_RX_ENABLE;
interface MLME_SCAN;
interface MLME_SET;
interface MLME_START;
interface Notify<const void*> as PIBUpdate[uint8_t attributeID];
interface IEEE154Frame;
interface IEEE154BeaconFrame;
interface SplitControl as PromiscuousMode;
interface Get<uint64_t> as GetLocalExtendedAddress;
interface TimeCalc;
interface FrameUtility;
} uses {
interface RadioRx;
interface RadioTx;
interface RadioOff;
interface UnslottedCsmaCa;
interface EnergyDetection;
interface SplitControl as PhySplitControl;
interface Set<bool> as RadioPromiscuousMode;
interface Timer<TSymbolIEEE802154> as Timer1;
interface Timer<TSymbolIEEE802154> as Timer2;
interface Timer<TSymbolIEEE802154> as Timer3;
interface Timer<TSymbolIEEE802154> as Timer4;
interface Timer<TSymbolIEEE802154> as Timer5;
interface LocalTime<TSymbolIEEE802154>;
interface Random;
interface Leds;
}
}
implementation
{
components DataP,
PibP,
RadioControlP,
IndirectTxP,
PollP,
#ifndef IEEE154_SCAN_DISABLED
ScanP,
#else
NoScanP as ScanP,
#endif
#ifndef IEEE154_ASSOCIATION_DISABLED
AssociateP,
#else
NoAssociateP as AssociateP,
#endif
#ifndef IEEE154_DISASSOCIATION_DISABLED
DisassociateP,
#else
NoDisassociateP as DisassociateP,
#endif
new FrameDispatchQueueP() as FrameDispatchQueueP,
UnslottedFrameDispatchP as FrameDispatchP,
#ifndef IEEE154_RXENABLE_DISABLED
RxEnableP,
#else
NoRxEnableP as RxEnableP,
#endif
#ifndef IEEE154_PROMISCUOUS_MODE_DISABLED
PromiscuousModeP,
#else
NoPromiscuousModeP as PromiscuousModeP,
#endif
#ifndef IEEE154_COORD_REALIGNMENT_DISABLED
CoordRealignmentP,
#else
NoCoordRealignmentP as CoordRealignmentP,
#endif
new PoolC(ieee154_txframe_t, TXFRAME_POOL_SIZE) as TxFramePoolP,
new PoolC(ieee154_txcontrol_t, TXCONTROL_POOL_SIZE) as TxControlPoolP,
new QueueC(ieee154_txframe_t*, CAP_TX_QUEUE_SIZE) as FrameDispatchQueueC;
components MainC;
/* MCPS */
MCPS_DATA = DataP;
MCPS_PURGE = DataP;
/* MLME */
MLME_START = FrameDispatchP;
MLME_ASSOCIATE = AssociateP;
MLME_DISASSOCIATE = DisassociateP;
MLME_BEACON_NOTIFY = ScanP;
MLME_COMM_STATUS = AssociateP;
MLME_COMM_STATUS = CoordRealignmentP;
MLME_GET = PibP;
MLME_ORPHAN = CoordRealignmentP;
MLME_POLL = PollP;
MLME_RESET = PibP;
MLME_RX_ENABLE = RxEnableP;
MLME_SCAN = ScanP;
MLME_SET = PibP;
IEEE154Frame = PibP;
IEEE154BeaconFrame = PibP;
PromiscuousMode = PromiscuousModeP;
GetLocalExtendedAddress = PibP.GetLocalExtendedAddress;
Packet = PibP;
TimeCalc = PibP;
FrameUtility = PibP;
/* ----------------------- Scanning (MLME-SCAN) ----------------------- */
components new RadioClientC() as ScanRadioClient;
PibP.MacReset -> ScanP;
ScanP.MLME_GET -> PibP;
ScanP.MLME_SET -> PibP.MLME_SET;
ScanP.EnergyDetection = EnergyDetection;
ScanP.RadioRx -> ScanRadioClient;
ScanP.RadioTx -> ScanRadioClient;
ScanP.Frame -> PibP;
ScanP.BeaconFrame -> PibP;
ScanP.RadioOff -> ScanRadioClient;
ScanP.ScanTimer = Timer1;
ScanP.TxFramePool -> TxFramePoolP;
ScanP.TxControlPool -> TxControlPoolP;
ScanP.Token -> ScanRadioClient;
ScanP.Leds = Leds;
ScanP.FrameUtility -> PibP;
/* -------------------- Association (MLME-ASSOCIATE) -------------------- */
PibP.MacReset -> AssociateP;
AssociateP.AssociationRequestRx -> FrameDispatchP.FrameRx[FC1_FRAMETYPE_CMD + CMD_FRAME_ASSOCIATION_REQUEST];
AssociateP.AssociationRequestTx -> FrameDispatchQueueP.FrameTx[unique(CAP_TX_CLIENT)];
AssociateP.AssociationResponseExtracted -> FrameDispatchP.FrameExtracted[FC1_FRAMETYPE_CMD + CMD_FRAME_ASSOCIATION_RESPONSE];
AssociateP.AssociationResponseTx -> IndirectTxP.FrameTx[unique(INDIRECT_TX_CLIENT)];
AssociateP.DataRequest -> PollP.DataRequest[ASSOCIATE_POLL_CLIENT];
AssociateP.ResponseTimeout = Timer2;
AssociateP.TxFramePool -> TxFramePoolP;
AssociateP.TxControlPool -> TxControlPoolP;
AssociateP.MLME_GET -> PibP;
AssociateP.MLME_SET -> PibP.MLME_SET;
AssociateP.FrameUtility -> PibP;
AssociateP.Frame -> PibP;
AssociateP.LocalExtendedAddress -> PibP.GetLocalExtendedAddress;
/* --------------- Disassociation (MLME-DISASSOCIATE) --------------- */
PibP.MacReset -> DisassociateP;
DisassociateP.DisassociationIndirectTx -> IndirectTxP.FrameTx[unique(INDIRECT_TX_CLIENT)];
DisassociateP.DisassociationDirectTx -> FrameDispatchQueueP.FrameTx[unique(CAP_TX_CLIENT)];
DisassociateP.DisassociationToCoord -> FrameDispatchQueueP.FrameTx[unique(CAP_TX_CLIENT)];
DisassociateP.DisassociationExtractedFromCoord ->
FrameDispatchP.FrameExtracted[FC1_FRAMETYPE_CMD + CMD_FRAME_DISASSOCIATION_NOTIFICATION];
DisassociateP.DisassociationRxFromDevice ->
FrameDispatchP.FrameRx[FC1_FRAMETYPE_CMD + CMD_FRAME_DISASSOCIATION_NOTIFICATION];
DisassociateP.TxFramePool -> TxFramePoolP;
DisassociateP.TxControlPool -> TxControlPoolP;
DisassociateP.MLME_GET -> PibP;
DisassociateP.FrameUtility -> PibP;
DisassociateP.Frame -> PibP;
DisassociateP.LocalExtendedAddress -> PibP.GetLocalExtendedAddress;
/* ------------------ Data Transmission (MCPS-DATA) ------------------- */
DataP.DeviceCapTx -> FrameDispatchQueueP.FrameTx[unique(CAP_TX_CLIENT)];
DataP.CoordCapTx -> FrameDispatchQueueP.FrameTx[unique(CAP_TX_CLIENT)];
DataP.DeviceCapRx -> PollP.DataRx;
DataP.DeviceCapRx -> PromiscuousModeP.FrameRx;
DataP.TxFramePool -> TxFramePoolP;
DataP.IndirectTx -> IndirectTxP.FrameTx[unique(INDIRECT_TX_CLIENT)];
DataP.FrameUtility -> PibP;
DataP.Frame -> PibP;
DataP.PurgeDirect -> FrameDispatchQueueP;
DataP.PurgeIndirect -> IndirectTxP;
DataP.MLME_GET -> PibP;
DataP.Packet -> PibP;
DataP.Leds = Leds;
/* ------------------------ Polling (MLME-POLL) ----------------------- */
PibP.MacReset -> PollP;
PollP.PollTx -> FrameDispatchQueueP.FrameTx[unique(CAP_TX_CLIENT)];
PollP.DataExtracted -> FrameDispatchP.FrameExtracted[FC1_FRAMETYPE_DATA];
PollP.FrameUtility -> PibP;
PollP.TxFramePool -> TxFramePoolP;
PollP.TxControlPool -> TxControlPoolP;
PollP.MLME_GET -> PibP;
PollP.LocalExtendedAddress -> PibP.GetLocalExtendedAddress;
/* ---------------------- Indirect transmission ----------------------- */
PibP.MacReset -> IndirectTxP;
IndirectTxP.CoordCapTx -> FrameDispatchQueueP.FrameTx[unique(CAP_TX_CLIENT)];
IndirectTxP.DataRequestRx -> FrameDispatchP.FrameRx[FC1_FRAMETYPE_CMD + CMD_FRAME_DATA_REQUEST];
IndirectTxP.MLME_GET -> PibP;
IndirectTxP.FrameUtility -> PibP;
IndirectTxP.IndirectTxTimeout = Timer3;
IndirectTxP.TimeCalc -> PibP;
IndirectTxP.Leds = Leds;
/* ---------------------------- Realignment --------------------------- */
PibP.MacReset -> CoordRealignmentP;
CoordRealignmentP.CoordRealignmentTx -> FrameDispatchQueueP.FrameTx[unique(CAP_TX_CLIENT)];
CoordRealignmentP.OrphanNotificationRx -> FrameDispatchP.FrameRx[FC1_FRAMETYPE_CMD + CMD_FRAME_ORPHAN_NOTIFICATION];
CoordRealignmentP.FrameUtility -> PibP;
CoordRealignmentP.Frame -> PibP;
CoordRealignmentP.TxFramePool -> TxFramePoolP;
CoordRealignmentP.TxControlPool -> TxControlPoolP;
CoordRealignmentP.MLME_GET -> PibP;
CoordRealignmentP.LocalExtendedAddress -> PibP.GetLocalExtendedAddress;
/* --------------------- FrameDispatchP -------------------- */
PibP.FrameDispatchReset -> FrameDispatchP;
PibP.FrameDispatchQueueReset -> FrameDispatchQueueP;
FrameDispatchQueueP.Queue -> FrameDispatchQueueC;
FrameDispatchQueueP.FrameTxCsma -> FrameDispatchP;
components new RadioClientC() as FrameDispatchRadioClient;
PibP.FrameDispatchReset -> FrameDispatchP;
FrameDispatchP.IndirectTxWaitTimer = Timer4;
FrameDispatchP.Token -> FrameDispatchRadioClient;
FrameDispatchP.SetMacSuperframeOrder -> PibP.SetMacSuperframeOrder;
FrameDispatchP.SetMacPanCoordinator -> PibP.SetMacPanCoordinator;
FrameDispatchP.IsTokenRequested -> FrameDispatchRadioClient;
FrameDispatchP.IsRxEnableActive -> RxEnableP.IsRxEnableActive;
FrameDispatchP.GetIndirectTxFrame -> IndirectTxP;
FrameDispatchP.RxEnableStateChange -> RxEnableP.RxEnableStateChange;
FrameDispatchP.FrameUtility -> PibP;
FrameDispatchP.UnslottedCsmaCa -> FrameDispatchRadioClient;
FrameDispatchP.RadioRx -> FrameDispatchRadioClient;
FrameDispatchP.RadioOff -> FrameDispatchRadioClient;
FrameDispatchP.MLME_GET -> PibP;
FrameDispatchP.MLME_SET -> PibP.MLME_SET;
FrameDispatchP.TimeCalc -> PibP;
FrameDispatchP.Leds = Leds;
/* -------------------------- promiscuous mode ------------------------ */
components new RadioClientC() as PromiscuousModeRadioClient;
PibP.MacReset -> PromiscuousModeP;
PromiscuousModeP.Token -> PromiscuousModeRadioClient;
PromiscuousModeP.PromiscuousRx -> PromiscuousModeRadioClient;
PromiscuousModeP.RadioOff -> PromiscuousModeRadioClient;
PromiscuousModeP.RadioPromiscuousMode = RadioPromiscuousMode;
/* --------------------------- MLME-RX-ENABLE ------------------------ */
PibP.MacReset -> RxEnableP;
RxEnableP.TimeCalc -> PibP.TimeCalc;
RxEnableP.WasRxEnabled -> FrameDispatchP.WasRxEnabled;
RxEnableP.WasRxEnabled -> FrameDispatchP.WasRxEnabled;
RxEnableP.RxEnableTimer = Timer5;
/* ------------------------------- PIB -------------------------------- */
components new RadioClientC() as PibRadioClient;
PIBUpdate = PibP;
MainC.SoftwareInit -> PibP.LocalInit;
PibP.RadioControl = PhySplitControl;
PibP.Random = Random;
PibP.PromiscuousModeGet -> PromiscuousModeP;
PibP.LocalTime = LocalTime;
PibP.Token -> PibRadioClient;
PibP.RadioOff -> PibRadioClient;
/* ------------------------- Radio Control ---------------------------- */
RadioControlP.PhyTx = RadioTx;
RadioControlP.PhyUnslottedCsmaCa = UnslottedCsmaCa;
RadioControlP.PhyRx = RadioRx;
RadioControlP.PhyRadioOff = RadioOff;
RadioControlP.RadioPromiscuousMode -> PromiscuousModeP;
RadioControlP.Leds = Leds;
}
--- NEW FILE: UnslottedFrameDispatchP.nc ---
/*
* 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: 1.1 $
* $Date: 2009/03/04 18:31:39 $
* @author Jan Hauer <hauer at tkn.tu-berlin.de>
* ========================================================================
*/
#include "TKN154_PHY.h"
#include "TKN154_MAC.h"
/**
* This module is responsible for the transmission/reception of DATA and
* COMMAND frames in a nonbeacon-enabled PAN. Its main tasks are initialization
* of the parameters of the unslotted CSMA-CA algorithm (NB, BE, etc.),
* initiating retransmissions and managing requests for enabling the receiver
* for a finite period of time. It does not implement the actual CSMA-CA
* algorithm, because due to its timing requirements the CSMA-CA algorithm is
* not part of the MAC implementation but of the chip-specific radio driver.
*/
#if IEEE154_BEACON_ENABLED_PAN
#error "The IEEE154_BEACON_ENABLED_PAN macro MUST NOT be set when using this component!"
#endif
module UnslottedFrameDispatchP
{
provides
{
interface Init as Reset;
interface MLME_START;
interface FrameTx as FrameTx;
interface FrameRx as FrameRx[uint8_t frameType];
interface FrameExtracted as FrameExtracted[uint8_t frameType];
interface Notify<bool> as WasRxEnabled;
}
uses
{
interface Timer<TSymbolIEEE802154> as IndirectTxWaitTimer;
interface Resource as Token;
interface GetNow<bool> as IsTokenRequested;
interface GetNow<bool> as IsRxEnableActive;
interface Set<ieee154_macSuperframeOrder_t> as SetMacSuperframeOrder;
interface Set<ieee154_macPanCoordinator_t> as SetMacPanCoordinator;
interface Get<ieee154_txframe_t*> as GetIndirectTxFrame;
interface Notify<bool> as RxEnableStateChange;
interface FrameUtility;
interface UnslottedCsmaCa;
interface RadioRx;
interface RadioOff;
interface MLME_GET;
interface MLME_SET;
interface TimeCalc;
interface Leds;
}
}
implementation
{
typedef enum {
SWITCH_OFF,
WAIT_FOR_RXDONE,
WAIT_FOR_TXDONE,
DO_NOTHING,
} next_state_t;
typedef enum {
INDIRECT_TX_ALARM,
NO_ALARM,
} rx_alarm_t;
/* state / frame management */
norace bool m_lock;
norace bool m_resume;
norace ieee154_txframe_t *m_currentFrame;
norace ieee154_txframe_t *m_lastFrame;
/* variables for the unslotted CSMA-CA */
norace ieee154_csma_t m_csma;
norace ieee154_macMaxBE_t m_BE;
norace ieee154_macMaxCSMABackoffs_t m_macMaxCSMABackoffs;
norace ieee154_macMaxBE_t m_macMaxBE;
norace ieee154_macMaxFrameRetries_t m_macMaxFrameRetries;
norace ieee154_status_t m_txStatus;
norace uint32_t m_transactionTime;
norace bool m_indirectTxPending = FALSE;
norace ieee154_macMaxFrameTotalWaitTime_t m_macMaxFrameTotalWaitTime;
/* function / task prototypes */
next_state_t tryReceive(bool startIndirectTxTimer);
next_state_t tryTransmit();
next_state_t trySwitchOff();
void backupCurrentFrame();
void restoreFrameFromBackup();
void updateState();
void setCurrentFrame(ieee154_txframe_t *frame);
void signalTxBroadcastDone(ieee154_txframe_t *frame, ieee154_status_t error);
task void signalTxDoneTask();
task void wasRxEnabledTask();
task void startIndirectTxTimerTask();
task void signalStartConfirmTask();
command error_t Reset.init()
{
if (m_currentFrame)
signal FrameTx.transmitDone(m_currentFrame, IEEE154_TRANSACTION_OVERFLOW);
if (m_lastFrame)
signal FrameTx.transmitDone(m_lastFrame, IEEE154_TRANSACTION_OVERFLOW);
m_currentFrame = m_lastFrame = NULL;
call IndirectTxWaitTimer.stop();
return SUCCESS;
}
command ieee154_status_t MLME_START.request (
uint16_t panID,
uint8_t logicalChannel,
uint8_t channelPage,
uint32_t startTime,
uint8_t beaconOrder,
uint8_t superframeOrder,
bool panCoordinator,
bool batteryLifeExtension,
bool coordRealignment,
ieee154_security_t *coordRealignSecurity,
ieee154_security_t *beaconSecurity)
{
ieee154_status_t status;
ieee154_macShortAddress_t shortAddress = call MLME_GET.macShortAddress();
// check parameters
if ((coordRealignSecurity && coordRealignSecurity->SecurityLevel) ||
(beaconSecurity && beaconSecurity->SecurityLevel))
status = IEEE154_UNSUPPORTED_SECURITY;
else if (shortAddress == 0xFFFF)
status = IEEE154_NO_SHORT_ADDRESS;
else if (logicalChannel > 26 ||
(channelPage != IEEE154_SUPPORTED_CHANNELPAGE) ||
!(IEEE154_SUPPORTED_CHANNELS & ((uint32_t) 1 << logicalChannel)))
status = IEEE154_INVALID_PARAMETER;
else if (beaconOrder != 15)
status = IEEE154_INVALID_PARAMETER;
else {
call MLME_SET.macPANId(panID);
call MLME_SET.phyCurrentChannel(logicalChannel);
call MLME_SET.macBeaconOrder(beaconOrder);
call SetMacSuperframeOrder.set(superframeOrder);
call SetMacPanCoordinator.set(panCoordinator);
//TODO: check realignment
post signalStartConfirmTask();
status = IEEE154_SUCCESS;
}
return status;
}
task void signalStartConfirmTask()
{
signal MLME_START.confirm(IEEE154_SUCCESS);
}
command ieee154_status_t FrameTx.transmit(ieee154_txframe_t *frame)
{
if (m_currentFrame != NULL) {
// we've not finished transmitting the current frame yet
dbg_serial("UnslottedFrameDispatchP", "Overflow\n");
return IEEE154_TRANSACTION_OVERFLOW;
} else {
setCurrentFrame(frame);
call Token.request();
return IEEE154_SUCCESS;
}
}
event void Token.granted()
{
updateState();
}
void setCurrentFrame(ieee154_txframe_t *frame)
{
ieee154_macDSN_t dsn = call MLME_GET.macDSN();
frame->header->mhr[MHR_INDEX_SEQNO] = dsn++;
call MLME_SET.macDSN(dsn);
m_csma.NB = 0;
m_csma.macMaxCsmaBackoffs = m_macMaxCSMABackoffs = call MLME_GET.macMaxCSMABackoffs();
m_csma.macMaxBE = m_macMaxBE = call MLME_GET.macMaxBE();
m_csma.BE = call MLME_GET.macMinBE();
if (call MLME_GET.macBattLifeExt() && m_csma.BE > 2)
m_csma.BE = 2;
m_BE = m_csma.BE;
if (call GetIndirectTxFrame.get() == frame)
m_macMaxFrameRetries = 0; // this is an indirect transmissions (never retransmit)
else
m_macMaxFrameRetries = call MLME_GET.macMaxFrameRetries();
m_transactionTime = IEEE154_SHR_DURATION +
(frame->headerLen + frame->payloadLen + 2) * IEEE154_SYMBOLS_PER_OCTET; // extra 2 for CRC
if (frame->header->mhr[MHR_INDEX_FC1] & FC1_ACK_REQUEST)
m_transactionTime += (IEEE154_aTurnaroundTime + IEEE154_aUnitBackoffPeriod +
11 * IEEE154_SYMBOLS_PER_OCTET); // 11 byte for the ACK PPDU
// if (frame->headerLen + frame->payloadLen > IEEE154_aMaxSIFSFrameSize)
// m_transactionTime += call MLME_GET.macMinLIFSPeriod();
// else
// m_transactionTime += call MLME_GET.macMinSIFSPeriod();
m_macMaxFrameTotalWaitTime = call MLME_GET.macMaxFrameTotalWaitTime();
m_currentFrame = frame;
}
/**
* The updateState() function is called whenever some event happened that
* might require a state transition; it implements a lock mechanism (m_lock)
* to prevent race conditions. Whenever the lock is set a "done"-event (from
* a RadioTx/RadioRx/RadioOff interface) is pending and will "soon" unset the
* lock (and then updateState() will called again). The updateState()
* function decides about the next state by checking a list of possible
* current states ordered by priority. Calling this function more than
* necessary can do no harm.
*/
void updateState()
{
next_state_t next;
atomic {
// long atomics are bad... but in this block, once the
// current state has been determined only one branch will
// be taken (there are no loops)
if (m_lock || !call Token.isOwner())
return;
m_lock = TRUE; // lock
// Check 1: was an indirect transmission successfully started
// and are we now waiting for a frame from the coordinator?
if (m_indirectTxPending) {
next = tryReceive(TRUE);
}
// Check 2: is some other operation (like MLME-SCAN or MLME-RESET) pending?
else if (call IsTokenRequested.getNow()) {
if (call RadioOff.isOff()) {
// nothing more to do... just release the Token
m_lock = FALSE; // unlock
dbg_serial("UnslottedFrameDispatchP", "Token requested: releasing it.\n");
call Token.release();
return;
} else
next = SWITCH_OFF;
}
// Check 3: is there a frame ready to transmit?
else if (m_currentFrame != NULL) {
next = tryTransmit();
}
// Check 4: should we be in receive mode?
else if (call IsRxEnableActive.getNow()) {
next = tryReceive(FALSE);
if (next == DO_NOTHING) {
// this means there is an active MLME_RX_ENABLE.request
// and the radio was just switched to Rx mode - signal
// a notify event to inform the next higher layer
post wasRxEnabledTask();
}
}
// Check 6: just make sure the radio is switched off
else {
next = trySwitchOff();
if (next == DO_NOTHING) {
// nothing more to do... just release the Token
m_lock = FALSE; // unlock
dbg_serial("UnslottedFrameDispatchP", "Releasing token\n");
call Token.release();
return;
}
}
// if there is nothing to do, then we must clear the lock
if (next == DO_NOTHING)
m_lock = FALSE;
} // atomic
// put next state in operation (possibly keeping the lock)
switch (next)
{
case SWITCH_OFF: ASSERT(call RadioOff.off() == SUCCESS); break;
case WAIT_FOR_RXDONE: break;
case WAIT_FOR_TXDONE: break;
case DO_NOTHING: break;
}
}
next_state_t tryTransmit()
{
// tries to transmit m_currentFrame
next_state_t next;
if (!call RadioOff.isOff())
next = SWITCH_OFF;
else {
error_t res;
res = call UnslottedCsmaCa.transmit(m_currentFrame, &m_csma);
dbg("UnslottedFrameDispatchP", "UnslottedCsmaCa.transmit() -> %lu\n", (uint32_t) res);
next = WAIT_FOR_TXDONE; // this will NOT clear the lock
}
return next;
}
next_state_t tryReceive(bool startIndirectTxTimer)
{
next_state_t next;
if (call RadioRx.isReceiving())
next = DO_NOTHING;
else if (!call RadioOff.isOff())
next = SWITCH_OFF;
else {
call RadioRx.enableRx(0, 0);
if (startIndirectTxTimer)
post startIndirectTxTimerTask();
next = WAIT_FOR_RXDONE;
}
return next;
}
next_state_t trySwitchOff()
{
next_state_t next;
if (call RadioOff.isOff())
next = DO_NOTHING;
else
next = SWITCH_OFF;
return next;
}
async event void RadioOff.offDone() { m_lock = FALSE; updateState();}
async event void RadioRx.enableRxDone() { m_lock = FALSE; updateState();}
event void RxEnableStateChange.notify(bool whatever) { updateState();}
event void IndirectTxWaitTimer.fired()
{
atomic {
if (m_indirectTxPending) {
m_indirectTxPending = FALSE;
post signalTxDoneTask();
}
}
}
task void startIndirectTxTimerTask()
{
call IndirectTxWaitTimer.startOneShot(m_macMaxFrameTotalWaitTime);
}
async event void UnslottedCsmaCa.transmitDone(ieee154_txframe_t *frame,
ieee154_csma_t *csma, bool ackPendingFlag, error_t result)
{
bool done = TRUE;
dbg("UnslottedFrameDispatchP", "UnslottedCsmaCa.transmitDone() -> %lu\n", (uint32_t) result);
m_resume = FALSE;
switch (result)
{
case SUCCESS:
// frame was successfully transmitted, if ACK was requested
// then a matching ACK was successfully received as well
m_txStatus = IEEE154_SUCCESS;
if (frame->payload[0] == CMD_FRAME_DATA_REQUEST &&
((frame->header->mhr[MHR_INDEX_FC1]) & FC1_FRAMETYPE_MASK) == FC1_FRAMETYPE_CMD) {
// this was a data request frame
m_txStatus = IEEE154_NO_DATA; // pessimistic
if (ackPendingFlag) {
// the coordinator has data for us; switch to Rx
// to complete the indirect transmission
m_indirectTxPending = TRUE;
m_lastFrame = m_currentFrame;
m_currentFrame = NULL;
ASSERT(call RadioRx.enableRx(0, 0) == SUCCESS);
return;
}
}
break;
case FAIL:
// The CSMA-CA algorithm failed: the frame was not transmitted,
// because channel was never idle
m_txStatus = IEEE154_CHANNEL_ACCESS_FAILURE;
break;
case ENOACK:
// frame was transmitted, but we didn't receive an ACK (although
// we requested an one). note: coordinator never retransmits an
// indirect transmission (see above)
if (m_macMaxFrameRetries > 0) {
// retransmit: reinitialize CSMA-CA parameters
done = FALSE;
m_csma.NB = 0;
m_csma.macMaxCsmaBackoffs = m_macMaxCSMABackoffs;
m_csma.macMaxBE = m_macMaxBE;
m_csma.BE = m_BE;
m_macMaxFrameRetries -= 1;
} else
m_txStatus = IEEE154_NO_ACK;
break;
default:
ASSERT(0);
break;
}
if (done) {
m_lastFrame = m_currentFrame;
m_currentFrame = NULL;
post signalTxDoneTask();
}
m_lock = FALSE;
updateState();
}
task void signalTxDoneTask()
{
ieee154_txframe_t *lastFrame = m_lastFrame;
ieee154_status_t status = m_txStatus;
m_indirectTxPending = FALSE;
m_lastFrame = NULL; // only now the next transmission can begin
if (lastFrame) {
dbg("UnslottedFrameDispatchP", "Transmit done, DSN: %lu, result: 0x%lx\n",
(uint32_t) MHR(lastFrame)[MHR_INDEX_SEQNO], (uint32_t) status);
signal FrameTx.transmitDone(lastFrame, status);
}
updateState();
}
event message_t* RadioRx.received(message_t* frame, const ieee154_timestamp_t *timestamp)
{
// received a frame -> find out frame type and
// signal it to responsible client component
uint8_t *payload = (uint8_t *) frame->data;
uint8_t *mhr = MHR(frame);
uint8_t frameType = mhr[MHR_INDEX_FC1] & FC1_FRAMETYPE_MASK;
if (frameType == FC1_FRAMETYPE_CMD)
frameType += payload[0];
atomic {
if (m_indirectTxPending) {
message_t* frameBuf;
call IndirectTxWaitTimer.stop();
// TODO: check!
//if (frame->payloadLen)
// is this frame from our coordinator? hmm... we cannot say
// with certainty, because we might only know either the
// coordinator extended or short address (and the frame could
// have been sent with the other addressing mode) ??
m_txStatus = IEEE154_SUCCESS;
frameBuf = signal FrameExtracted.received[frameType](frame, m_lastFrame);
signal IndirectTxWaitTimer.fired();
return frameBuf;
} else
return signal FrameRx.received[frameType](frame);
}
}
task void wasRxEnabledTask()
{
signal WasRxEnabled.notify(TRUE);
}
default event void FrameTx.transmitDone(ieee154_txframe_t *data, ieee154_status_t status) {}
default event message_t* FrameRx.received[uint8_t client](message_t* data) {return data;}
default async command bool IsRxEnableActive.getNow() {return FALSE;}
default event message_t* FrameExtracted.received[uint8_t client](message_t* msg, ieee154_txframe_t *txFrame) {return msg;}
command error_t WasRxEnabled.enable() {return FAIL;}
command error_t WasRxEnabled.disable() {return FAIL;}
default event void MLME_START.confirm(ieee154_status_t status) {}
}
Index: AssociateP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/mac/tkn154/AssociateP.nc,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** AssociateP.nc 25 Nov 2008 09:35:08 -0000 1.4
--- AssociateP.nc 4 Mar 2009 18:31:12 -0000 1.5
***************
*** 61,65 ****
interface IEEE154Frame as Frame;
interface Get<uint64_t> as LocalExtendedAddress;
- interface Ieee802154Debug as Debug;
}
}
--- 61,64 ----
***************
*** 88,92 ****
}
! /* ------------------- MLME_ASSOCIATE Request ------------------- */
command ieee154_status_t MLME_ASSOCIATE.request (
--- 87,91 ----
}
! /* ------------------- MLME_ASSOCIATE Request ------------------- */
command ieee154_status_t MLME_ASSOCIATE.request (
***************
*** 97,102 ****
ieee154_address_t CoordAddress,
ieee154_CapabilityInformation_t CapabilityInformation,
! ieee154_security_t *security
! )
{
ieee154_status_t status = IEEE154_SUCCESS;
--- 96,100 ----
ieee154_address_t CoordAddress,
ieee154_CapabilityInformation_t CapabilityInformation,
! ieee154_security_t *security)
{
ieee154_status_t status = IEEE154_SUCCESS;
***************
*** 113,121 ****
else if (m_associationOngoing || !(txFrame = call TxFramePool.get()))
status = IEEE154_TRANSACTION_OVERFLOW;
! else if (!(txControl = call TxControlPool.get())){
call TxFramePool.put(txFrame);
status = IEEE154_TRANSACTION_OVERFLOW;
}
! if (status == IEEE154_SUCCESS){
m_assocRespStatus = IEEE154_NO_DATA;
m_shortAddress = 0xFFFF;
--- 111,119 ----
else if (m_associationOngoing || !(txFrame = call TxFramePool.get()))
status = IEEE154_TRANSACTION_OVERFLOW;
! else if (!(txControl = call TxControlPool.get())) {
call TxFramePool.put(txFrame);
status = IEEE154_TRANSACTION_OVERFLOW;
}
! if (status == IEEE154_SUCCESS) {
m_assocRespStatus = IEEE154_NO_DATA;
m_shortAddress = 0xFFFF;
***************
*** 147,151 ****
txFrame->payloadLen = 2;
m_associationOngoing = TRUE;
! if ((status = call AssociationRequestTx.transmit(txFrame)) != IEEE154_SUCCESS){
m_associationOngoing = FALSE;
call TxFramePool.put(txFrame);
--- 145,149 ----
txFrame->payloadLen = 2;
m_associationOngoing = TRUE;
! if ((status = call AssociationRequestTx.transmit(txFrame)) != IEEE154_SUCCESS) {
m_associationOngoing = FALSE;
call TxFramePool.put(txFrame);
***************
*** 153,157 ****
}
}
! call Debug.log(DEBUG_LEVEL_INFO, AssociateP_REQUEST, status, 0, 0);
return status;
}
--- 151,155 ----
}
}
! dbg_serial("AssociationP", "MLME_ASSOCIATE.request -> result: %lu\n", (uint32_t) status);
return status;
}
***************
*** 161,173 ****
call TxControlPool.put((ieee154_txcontrol_t*) ((uint8_t*) txFrame->header - offsetof(ieee154_txcontrol_t, header)));
call TxFramePool.put(txFrame);
! if (status != IEEE154_SUCCESS){
m_associationOngoing = FALSE;
signal MLME_ASSOCIATE.confirm(0xFFFF, status, 0);
} else {
call ResponseTimeout.startOneShot(call MLME_GET.macResponseWaitTime()*IEEE154_aBaseSuperframeDuration);
! call Debug.log(DEBUG_LEVEL_INFO, AssociateP_SETTIMER,
! call MLME_GET.macResponseWaitTime()*IEEE154_aBaseSuperframeDuration, 0, 0);
}
- call Debug.log(DEBUG_LEVEL_INFO, AssociateP_TXDONE, status, 0, 0);
}
--- 159,171 ----
call TxControlPool.put((ieee154_txcontrol_t*) ((uint8_t*) txFrame->header - offsetof(ieee154_txcontrol_t, header)));
call TxFramePool.put(txFrame);
! if (status != IEEE154_SUCCESS) {
! dbg_serial("AssociationP", "transmitDone() failed!\n");
m_associationOngoing = FALSE;
signal MLME_ASSOCIATE.confirm(0xFFFF, status, 0);
} else {
call ResponseTimeout.startOneShot(call MLME_GET.macResponseWaitTime()*IEEE154_aBaseSuperframeDuration);
! dbg_serial("AssociationP", "transmitDone() ok, waiting for %lu\n",
! (uint32_t) (call MLME_GET.macResponseWaitTime() * IEEE154_aBaseSuperframeDuration));
}
}
***************
*** 183,187 ****
call FrameUtility.copyCoordExtendedAddressLE(coordAddress);
if (call DataRequest.poll(m_coordAddrMode, call MLME_GET.macPANId(),
! coordAddress, ADDR_MODE_EXTENDED_ADDRESS) != IEEE154_SUCCESS){
m_shortAddress = 0xFFFF;
m_assocRespStatus = IEEE154_TRANSACTION_OVERFLOW;
--- 181,185 ----
call FrameUtility.copyCoordExtendedAddressLE(coordAddress);
if (call DataRequest.poll(m_coordAddrMode, call MLME_GET.macPANId(),
! coordAddress, ADDR_MODE_EXTENDED_ADDRESS) != IEEE154_SUCCESS) {
m_shortAddress = 0xFFFF;
m_assocRespStatus = IEEE154_TRANSACTION_OVERFLOW;
***************
*** 193,197 ****
{
uint8_t *payload = (uint8_t *) &frame->data;
! if (m_associationOngoing){
m_shortAddress = *((nxle_uint16_t*) (payload + 1));
m_assocRespStatus = *(payload + 3);
--- 191,195 ----
{
uint8_t *payload = (uint8_t *) &frame->data;
! if (m_associationOngoing) {
m_shortAddress = *((nxle_uint16_t*) (payload + 1));
m_assocRespStatus = *(payload + 3);
***************
*** 202,214 ****
event void DataRequest.pollDone()
{
! if (m_associationOngoing){
! call Debug.log(DEBUG_LEVEL_INFO, AssociateP_POLL_DONE, m_payloadAssocRequest[0], m_assocRespStatus, 0);
call ResponseTimeout.stop();
m_associationOngoing = FALSE;
signal MLME_ASSOCIATE.confirm(m_shortAddress, m_assocRespStatus, 0);
}
}
! /* ------------------- MLME_ASSOCIATE Response ------------------- */
event message_t* AssociationRequestRx.received(message_t* frame)
--- 200,213 ----
event void DataRequest.pollDone()
{
! if (m_associationOngoing) {
call ResponseTimeout.stop();
m_associationOngoing = FALSE;
signal MLME_ASSOCIATE.confirm(m_shortAddress, m_assocRespStatus, 0);
+ dbg_serial("AssociationP", "confirm: %lx, %lu\n",
+ (uint32_t) m_shortAddress, (uint32_t) m_assocRespStatus);
}
}
! /* ------------------- MLME_ASSOCIATE Response ------------------- */
event message_t* AssociationRequestRx.received(message_t* frame)
***************
*** 227,232 ****
uint16_t assocShortAddress,
ieee154_association_status_t status,
! ieee154_security_t *security
! )
{
uint8_t i;
--- 226,230 ----
uint16_t assocShortAddress,
ieee154_association_status_t status,
! ieee154_security_t *security)
{
uint8_t i;
***************
*** 241,245 ****
if (i == MAX_PENDING_ASSOC_RESPONSES || !(txFrame = call TxFramePool.get()))
txStatus = IEEE154_TRANSACTION_OVERFLOW;
! else if (!(txControl = call TxControlPool.get())){
call TxFramePool.put(txFrame);
txStatus = IEEE154_TRANSACTION_OVERFLOW;
--- 239,243 ----
if (i == MAX_PENDING_ASSOC_RESPONSES || !(txFrame = call TxFramePool.get()))
txStatus = IEEE154_TRANSACTION_OVERFLOW;
! else if (!(txControl = call TxControlPool.get())) {
call TxFramePool.put(txFrame);
txStatus = IEEE154_TRANSACTION_OVERFLOW;
***************
*** 264,268 ****
txFrame->payload[3] = status;
txFrame->payloadLen = 4;
! if ((txStatus = call AssociationResponseTx.transmit(txFrame)) != IEEE154_SUCCESS){
txFrame->payload[0] = S_IDLE;
call TxFramePool.put(txFrame);
--- 262,266 ----
txFrame->payload[3] = status;
txFrame->payloadLen = 4;
! if ((txStatus = call AssociationResponseTx.transmit(txFrame)) != IEEE154_SUCCESS) {
txFrame->payload[0] = S_IDLE;
call TxFramePool.put(txFrame);
***************
*** 289,304 ****
}
! /* ------------------- Defaults ------------------- */
default event void MLME_ASSOCIATE.indication (
uint64_t DeviceAddress,
ieee154_CapabilityInformation_t CapabilityInformation,
! ieee154_security_t *security
! ){}
default event void MLME_ASSOCIATE.confirm (
uint16_t AssocShortAddress,
uint8_t status,
! ieee154_security_t *security
! ){}
default event void MLME_COMM_STATUS.indication (
uint16_t PANId,
--- 287,300 ----
}
! /* ------------------- Defaults ------------------- */
default event void MLME_ASSOCIATE.indication (
uint64_t DeviceAddress,
ieee154_CapabilityInformation_t CapabilityInformation,
! ieee154_security_t *security) {}
default event void MLME_ASSOCIATE.confirm (
uint16_t AssocShortAddress,
uint8_t status,
! ieee154_security_t *security) {}
default event void MLME_COMM_STATUS.indication (
uint16_t PANId,
***************
*** 308,312 ****
ieee154_address_t DstAddr,
ieee154_status_t status,
! ieee154_security_t *security
! ){}
}
--- 304,307 ----
ieee154_address_t DstAddr,
ieee154_status_t status,
! ieee154_security_t *security) {}
}
Index: BeaconSynchronizeP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/mac/tkn154/BeaconSynchronizeP.nc,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** BeaconSynchronizeP.nc 25 Nov 2008 09:35:08 -0000 1.7
--- BeaconSynchronizeP.nc 4 Mar 2009 18:31:14 -0000 1.8
***************
*** 34,40 ****
*/
#include "TKN154_MAC.h"
- #include "TKN154_DEBUG.h"
module BeaconSynchronizeP
--- 34,43 ----
*/
+ /**
+ * This module is responsible for periodic beacon tracking in a
+ * beacon-enabled PAN.
+ */
#include "TKN154_MAC.h"
module BeaconSynchronizeP
***************
*** 46,64 ****
interface MLME_BEACON_NOTIFY;
interface MLME_SYNC_LOSS;
interface GetNow<bool> as IsTrackingBeacons;
! interface GetNow<uint32_t> as CapStart;
! interface GetNow<ieee154_reftime_t*> as CapStartRefTime;
! interface GetNow<uint32_t> as CapLen;
! interface GetNow<uint32_t> as CapEnd;
! interface GetNow<uint32_t> as CfpEnd;
! interface GetNow<uint32_t> as CfpLen;
! interface GetNow<uint32_t> as BeaconInterval;
! interface GetNow<bool> as IsBLEActive;
! interface GetNow<uint16_t> as BLELen;
! interface GetNow<uint8_t*> as GtsField;
! interface GetNow<uint32_t> as SfSlotDuration;
! interface GetNow<uint8_t> as FinalCapSlot;
! interface GetNow<uint8_t> as NumGtsSlots;
! interface GetNow<bool> as IsRxBroadcastPending;
}
uses
--- 49,55 ----
interface MLME_BEACON_NOTIFY;
interface MLME_SYNC_LOSS;
+ interface SuperframeStructure as IncomingSF;
interface GetNow<bool> as IsTrackingBeacons;
! interface StdControl as TrackSingleBeacon;
}
uses
***************
*** 67,76 ****
interface MLME_SET;
interface FrameUtility;
- interface Notify<bool> as FindBeacon;
interface IEEE154BeaconFrame as BeaconFrame;
interface Alarm<TSymbolIEEE802154,uint32_t> as TrackAlarm;
interface RadioRx as BeaconRx;
interface RadioOff;
- interface GetNow<bool> as IsBeaconEnabledPAN;
interface DataRequest;
interface FrameRx as CoordRealignmentRx;
--- 58,65 ----
***************
*** 82,135 ****
interface IEEE154Frame as Frame;
interface Leds;
- interface Ieee802154Debug as Debug;
}
}
implementation
{
! enum {
! S_PREPARE = 0,
! S_RXNOW = 1,
! S_RADIO_OFF = 2,
! S_FIRST_SCAN= 3,
!
! RX_DURATION = 1000, // listen for a beacon for RX_DURATION symbols
! RX_LAG = 100, // start to listen for a RX_LAG before expected arrival
! };
!
! norace bool m_tracking = FALSE;
! norace bool m_updatePending = FALSE;
uint8_t m_updateLogicalChannel;
bool m_updateTrackBeacon;
- bool m_stopTracking = FALSE;
- bool m_internalRequest = FALSE;
! norace uint8_t m_numBeaconsLost;
! message_t m_beaconBuffer;
! norace message_t *m_beaconBufferPtr = &m_beaconBuffer;
! norace bool m_beaconSwapBufferReady = TRUE;
norace uint32_t m_beaconInterval;
norace uint32_t m_dt;
norace uint32_t m_lastBeaconRxTime;
! norace ieee154_reftime_t m_lastBeaconRxRefTime;
! norace uint8_t m_state;
norace uint8_t m_beaconOrder;
norace uint32_t m_sfSlotDuration;
! norace uint8_t m_finalCapSlot;
norace uint8_t m_numGtsSlots;
! norace uint16_t m_BLELen;
! norace bool m_broadcastPending;
uint8_t m_gtsField[1+1+3*7];
task void processBeaconTask();
! void getNextBeacon();
task void signalGrantedTask();
command error_t Reset.init()
{
! if (call Token.isOwner()){
! call Leds.led0On(); // internal error
! return FAIL;
! }
if (m_tracking || m_updatePending)
signal MLME_SYNC_LOSS.indication(
--- 71,125 ----
interface IEEE154Frame as Frame;
interface Leds;
}
}
implementation
{
+ /* state variables */
+ norace bool m_tracking;
+ bool m_stopTracking ;
+ norace uint8_t m_numBeaconsLost;
+ norace uint8_t m_state;
+ norace bool m_bufferBusy;
! /* buffers for the parameters of the MLME-SYNC request */
! norace bool m_updatePending;
uint8_t m_updateLogicalChannel;
bool m_updateTrackBeacon;
! /* variables that describe the current configuration */
norace uint32_t m_beaconInterval;
norace uint32_t m_dt;
norace uint32_t m_lastBeaconRxTime;
! norace ieee154_timestamp_t m_lastBeaconRxRefTime;
norace uint8_t m_beaconOrder;
+ message_t m_beacon;
+ norace message_t *m_beaconPtr = &m_beacon;
+
+ /* variables that describe the latest superframe */
norace uint32_t m_sfSlotDuration;
! norace bool m_framePendingBit;
! norace uint8_t m_numCapSlots;
norace uint8_t m_numGtsSlots;
! norace uint16_t m_battLifeExtDuration;
uint8_t m_gtsField[1+1+3*7];
+
+ enum {
+ S_PREPARE = 0,
+ S_RECEIVING = 1,
+ S_RADIO_OFF = 2,
+ S_INITIAL_SCAN= 3,
+
+ };
+
+ /* function/task prototypes */
task void processBeaconTask();
! void trackNextBeacon();
task void signalGrantedTask();
command error_t Reset.init()
{
! // reset this component. will only be called
! // while we're not owning the token
if (m_tracking || m_updatePending)
signal MLME_SYNC_LOSS.indication(
***************
*** 143,150 ****
}
! /* ----------------------- MLME-SYNC ----------------------- */
! /*
! * Allows to synchronize with a coordinator.
! */
command ieee154_status_t MLME_SYNC.request (
--- 133,140 ----
}
! /* ----------------------- MLME-SYNC ----------------------- */
! /*
! * Allows to synchronize with the beacons from a coordinator.
! */
command ieee154_status_t MLME_SYNC.request (
***************
*** 153,156 ****
--- 143,147 ----
bool trackBeacon)
{
+ error_t status = IEEE154_SUCCESS;
uint32_t supportedChannels = IEEE154_SUPPORTED_CHANNELS;
uint32_t currentChannelBit = 1;
***************
*** 158,205 ****
currentChannelBit <<= logicalChannel;
if (!(currentChannelBit & supportedChannels) || (call MLME_GET.macPANId() == 0xFFFF) ||
! (channelPage != IEEE154_SUPPORTED_CHANNELPAGE) || !call IsBeaconEnabledPAN.getNow())
! return IEEE154_INVALID_PARAMETER;
!
! call Debug.log(DEBUG_LEVEL_INFO,0, logicalChannel, channelPage, trackBeacon);
! if (!trackBeacon && m_tracking){
! // stop tracking after next received beacon
! m_stopTracking = TRUE;
! } else {
! m_stopTracking = FALSE;
! m_updateLogicalChannel = logicalChannel;
! m_updateTrackBeacon = trackBeacon;
! m_internalRequest = FALSE;
! m_updatePending = TRUE;
! call Debug.log(DEBUG_LEVEL_INFO,1, 0, 0, 0);
! atomic {
! // if we are tracking then we'll get the Token automatically,
! // otherwise request it now
! if (!m_tracking && !call Token.isOwner())
! call Token.request();
}
}
! call Debug.flush();
! return IEEE154_SUCCESS;
! }
!
! event void FindBeacon.notify( bool val )
! {
! call Debug.log(DEBUG_LEVEL_IMPORTANT,20, m_tracking, m_updatePending, 0);
! if (!m_tracking && !m_updatePending && !call Token.isOwner()){
! // find a single beacon now (treat this like a user request)
! m_updateLogicalChannel = call MLME_GET.phyCurrentChannel();
! m_updateTrackBeacon = FALSE;
! m_updatePending = TRUE;
! m_internalRequest = TRUE;
! call Token.request();
! }
}
event void Token.granted()
{
! call Debug.log(DEBUG_LEVEL_INFO,2, m_lastBeaconRxTime+m_beaconInterval,
! m_beaconInterval, (m_updatePending<<1)+m_tracking);
! if (m_updatePending){
! m_state = S_FIRST_SCAN;
m_updatePending = FALSE;
m_beaconOrder = call MLME_GET.macBeaconOrder();
--- 149,182 ----
currentChannelBit <<= logicalChannel;
if (!(currentChannelBit & supportedChannels) || (call MLME_GET.macPANId() == 0xFFFF) ||
! (channelPage != IEEE154_SUPPORTED_CHANNELPAGE) || !IEEE154_BEACON_ENABLED_PAN)
! status = IEEE154_INVALID_PARAMETER;
! else {
! if (!trackBeacon && m_tracking) {
! // stop tracking after next received beacon
! m_stopTracking = TRUE;
! } else {
! m_stopTracking = FALSE;
! m_updateLogicalChannel = logicalChannel;
! m_updateTrackBeacon = trackBeacon;
! m_updatePending = TRUE;
! atomic {
! // if we are tracking then we'll get the Token automatically,
! // otherwise request it now
! if (!m_tracking && !call Token.isOwner())
! call Token.request();
! }
}
}
! dbg_serial("BeaconSynchronizeP", "MLME_SYNC.request -> result: %lu\n", (uint32_t) status);
! return status;
}
event void Token.granted()
{
! dbg_serial("BeaconSynchronizeP","Got token, expecting beacon in %lu\n",
! (uint32_t) ((m_lastBeaconRxTime + m_dt) - call TrackAlarm.getNow()));
! if (m_updatePending) {
! dbg_serial("BeaconSynchronizeP", "Preparing initial scan\n");
! m_state = S_INITIAL_SCAN;
m_updatePending = FALSE;
m_beaconOrder = call MLME_GET.macBeaconOrder();
***************
*** 211,329 ****
m_dt = m_beaconInterval;
m_numBeaconsLost = IEEE154_aMaxLostBeacons; // will be reset when beacon is received
- call Debug.log(DEBUG_LEVEL_INFO,3, call MLME_GET.macCoordShortAddress(),
- call MLME_GET.macPANId(), m_updateLogicalChannel);
}
! getNextBeacon();
! call Debug.flush();
}
! void getNextBeacon()
{
bool missed = FALSE;
! if (m_state != S_FIRST_SCAN){
// we have received at least one previous beacon
m_state = S_PREPARE;
! if (!m_tracking){
// nothing to do, just give up the token
! call Debug.log(DEBUG_LEVEL_INFO,4, 0, 0, 0);
call Token.release();
return;
}
! while (call TimeCalc.hasExpired(m_lastBeaconRxTime, m_dt)){ // missed a beacon!
missed = TRUE;
- call Debug.log(DEBUG_LEVEL_IMPORTANT,5, m_lastBeaconRxTime, m_dt, missed);
m_dt += m_beaconInterval;
m_numBeaconsLost++;
}
! if (m_numBeaconsLost >= IEEE154_aMaxLostBeacons){
! call Debug.log(DEBUG_LEVEL_IMPORTANT,19, m_numBeaconsLost, m_dt, missed);
post processBeaconTask();
return;
}
! if (missed){
call Token.request();
! call Debug.log(DEBUG_LEVEL_IMPORTANT,6, m_lastBeaconRxTime, m_dt, missed);
call Token.release();
return;
}
}
! if (!call RadioOff.isOff())
! call RadioOff.off();
! else
signal RadioOff.offDone();
- }
-
- async event void TokenTransferred.transferred()
- {
- if (call IsTokenRequested.getNow()){
- // some other component needs the token - we give it up for now,
- // but make another request to get it back later
- call Token.request();
- call Token.release();
- } else if (m_updatePending)
- post signalGrantedTask();
else
! getNextBeacon();
}
! task void signalGrantedTask()
{
! signal Token.granted();
}
! async event void TrackAlarm.fired()
{
- call Debug.log(DEBUG_LEVEL_INFO,7, m_state,m_lastBeaconRxTime,m_dt);
switch (m_state)
{
case S_PREPARE:
! call BeaconRx.prepare();
break;
! case S_RADIO_OFF:
! call RadioOff.off();
break;
}
}
! async event void BeaconRx.prepareDone()
{
! error_t result;
! if (m_state == S_FIRST_SCAN){
! m_state = S_RADIO_OFF;
! atomic {
! call BeaconRx.receive(NULL, 0);
! call TrackAlarm.start((((uint32_t) 1 << m_beaconOrder) + (uint32_t) 1) *
! (uint32_t) IEEE154_aBaseSuperframeDuration * (uint32_t) IEEE154_aMaxLostBeacons);
! }
} else {
! m_state = S_RADIO_OFF;
! result = call BeaconRx.receive(&m_lastBeaconRxRefTime, m_dt-RX_LAG);
! //__nesc_enable_interrupt();
! call Debug.log(DEBUG_LEVEL_INFO,8, m_lastBeaconRxTime, 0,(m_lastBeaconRxTime+m_dt) - call TrackAlarm.getNow());
! if (result != SUCCESS)
! call Debug.log(DEBUG_LEVEL_CRITICAL,9, result, 0, 0);
! call TrackAlarm.startAt(m_lastBeaconRxTime, m_dt + RX_DURATION);
}
}
! event message_t* BeaconRx.received(message_t *frame, ieee154_reftime_t *timestamp)
{
! uint8_t *mhr = MHR(frame);
! call Debug.log(DEBUG_LEVEL_INFO,10,*((nxle_uint32_t*) &mhr[MHR_INDEX_ADDRESS]),
! mhr[MHR_INDEX_FC1] & FC1_FRAMETYPE_MASK,mhr[MHR_INDEX_SEQNO]);
! if (!m_beaconSwapBufferReady || !call FrameUtility.isBeaconFromCoord(frame))
{
! call Debug.log(DEBUG_LEVEL_IMPORTANT,11, m_beaconSwapBufferReady, 0, 0);
return frame;
} else {
! error_t resultOff;
! message_t *tmp = m_beaconBufferPtr;
! call TrackAlarm.stop();
! m_beaconSwapBufferReady = FALSE;
! m_beaconBufferPtr = frame;
! resultOff = call RadioOff.off();
! if (timestamp != NULL){
! memcpy(&m_lastBeaconRxRefTime, timestamp, sizeof(ieee154_reftime_t));
! call Debug.log(DEBUG_LEVEL_INFO,23,0, 0, resultOff);
}
return tmp;
--- 188,324 ----
m_dt = m_beaconInterval;
m_numBeaconsLost = IEEE154_aMaxLostBeacons; // will be reset when beacon is received
}
! trackNextBeacon();
}
! async event void TokenTransferred.transferred()
! {
! dbg_serial("BeaconSynchronizeP","Token.transferred(), expecting beacon in %lu symbols.\n",
! (uint32_t) ((m_lastBeaconRxTime + m_dt) - call TrackAlarm.getNow()));
! if (call IsTokenRequested.getNow()) {
! // some other component needs the token - we give it up for now,
! // but make another request to get it back later
! dbg_serial("BeaconSynchronizeP", "Token is requested, releasing it now.\n");
! call Token.request();
! call Token.release();
! } else if (m_updatePending)
! post signalGrantedTask();
! else
! trackNextBeacon();
! }
!
!
! task void signalGrantedTask()
! {
! signal Token.granted();
! }
!
! void trackNextBeacon()
{
bool missed = FALSE;
!
! if (m_state != S_INITIAL_SCAN) {
// we have received at least one previous beacon
m_state = S_PREPARE;
! if (!m_tracking) {
// nothing to do, just give up the token
! dbg_serial("BeaconSynchronizeP", "Stop tracking.\n");
call Token.release();
return;
}
! while (call TimeCalc.hasExpired(m_lastBeaconRxTime, m_dt)) { // missed a beacon!
! dbg_serial("BeaconSynchronizeP", "Missed a beacon, expected it: %lu, now: %lu\n",
! m_lastBeaconRxTime + m_dt, call TrackAlarm.getNow());
missed = TRUE;
m_dt += m_beaconInterval;
m_numBeaconsLost++;
}
! if (m_numBeaconsLost >= IEEE154_aMaxLostBeacons) {
! dbg_serial("BeaconSynchronizeP", "Missed too many beacons.\n");
post processBeaconTask();
return;
}
! if (missed) {
! // let other components get a chance to use the radio
call Token.request();
! dbg_serial("BeaconSynchronizeP", "Allowing other components to get the token.\n");
call Token.release();
return;
}
}
! if (call RadioOff.isOff())
signal RadioOff.offDone();
else
! ASSERT(call RadioOff.off() == SUCCESS);
}
! async event void RadioOff.offDone()
{
! uint32_t delay = IEEE154_RADIO_RX_DELAY + IEEE154_MAX_BEACON_JITTER(m_beaconOrder);
!
! if (m_state == S_INITIAL_SCAN) {
! // initial scan
! call BeaconRx.enableRx(0, 0);
! } else if (m_state == S_PREPARE) {
! if (!call TimeCalc.hasExpired(m_lastBeaconRxTime - delay, m_dt))
! call TrackAlarm.startAt(m_lastBeaconRxTime - delay, m_dt);
! else
! signal TrackAlarm.fired();
! } else {
! post processBeaconTask();
! }
}
! async event void BeaconRx.enableRxDone()
{
switch (m_state)
{
+ case S_INITIAL_SCAN:
+ m_state = S_RECEIVING;
+ call TrackAlarm.start((((uint32_t) 1 << m_beaconOrder) + (uint32_t) 1) *
+ (uint32_t) IEEE154_aBaseSuperframeDuration * (uint32_t) IEEE154_aMaxLostBeacons);
+ break;
case S_PREPARE:
! m_state = S_RECEIVING;
! dbg_serial("BeaconSynchronizeP","Rx enabled, expecting beacon in %lu symbols.\n",
! (uint32_t) ((m_lastBeaconRxTime + m_dt) - call TrackAlarm.getNow()));
! call TrackAlarm.startAt(m_lastBeaconRxTime, m_dt + IEEE154_MAX_BEACON_LISTEN_TIME(m_beaconOrder));
break;
! default:
! ASSERT(0);
break;
}
}
! async event void TrackAlarm.fired()
{
! if (m_state == S_PREPARE) {
! uint32_t maxBeaconJitter = IEEE154_MAX_BEACON_JITTER(m_beaconOrder);
! if (maxBeaconJitter > m_dt)
! maxBeaconJitter = m_dt; // receive immediately
! call BeaconRx.enableRx(m_lastBeaconRxTime, m_dt - maxBeaconJitter);
} else {
! ASSERT(m_state == S_RECEIVING && call RadioOff.off() == SUCCESS);
}
}
! event message_t* BeaconRx.received(message_t *frame, const ieee154_timestamp_t *timestamp)
{
! if (m_bufferBusy || !call FrameUtility.isBeaconFromCoord(frame))
{
! if (m_bufferBusy) {
! dbg_serial("BeaconSynchronizeP", "Got another beacon, dropping it.\n");}
! else
! dbg_serial("BeaconSynchronizeP", "Got a beacon, but not from my coordinator.\n");
return frame;
} else {
! message_t *tmp = m_beaconPtr;
! m_bufferBusy = TRUE;
! m_beaconPtr = frame;
! if (timestamp != NULL)
! memcpy(&m_lastBeaconRxRefTime, timestamp, sizeof(ieee154_timestamp_t));
! if (m_state == S_RECEIVING) {
! call TrackAlarm.stop(); // may fail
! call RadioOff.off(); // may fail
}
return tmp;
***************
*** 331,426 ****
}
- async event void RadioOff.offDone()
- {
- if (m_state == S_FIRST_SCAN)
- call BeaconRx.prepare();
- else if (m_state == S_PREPARE){
- if (!call TimeCalc.hasExpired(m_lastBeaconRxTime, m_dt - IEEE154_RADIO_RX_PREPARE_DELAY))
- call TrackAlarm.startAt(m_lastBeaconRxTime, m_dt - IEEE154_RADIO_RX_PREPARE_DELAY);
- else
- signal TrackAlarm.fired();
- } else {
- post processBeaconTask();
- }
- }
-
task void processBeaconTask()
{
! // valid beacon timestamp is pre-condition for slotted CSMA-CA
! if (m_beaconSwapBufferReady || !call Frame.isTimestampValid(m_beaconBufferPtr)){
! // missed a beacon!
! if (!m_beaconSwapBufferReady)
! call Debug.log(DEBUG_LEVEL_IMPORTANT, 21,m_numBeaconsLost,m_beaconSwapBufferReady,m_lastBeaconRxTime);
else
! call Debug.log(DEBUG_LEVEL_IMPORTANT, 12,m_numBeaconsLost,m_beaconSwapBufferReady,m_lastBeaconRxTime);
! m_sfSlotDuration = 0; // CAP len will be 0
! m_numBeaconsLost++;
m_dt += m_beaconInterval;
! m_beaconSwapBufferReady = TRUE;
! if (m_numBeaconsLost >= IEEE154_aMaxLostBeacons){
m_tracking = FALSE;
! call Debug.log(DEBUG_LEVEL_IMPORTANT, 13,m_internalRequest,0,0);
! call Leds.led2Off();
! if (m_internalRequest){
! call TokenToCap.transfer();
! return;
! } else
! signal MLME_SYNC_LOSS.indication(
IEEE154_BEACON_LOSS,
call MLME_GET.macPANId(),
call MLME_GET.phyCurrentChannel(),
call MLME_GET.phyCurrentPage(),
! NULL // security
! );
} else
call Token.request(); // make another request again (before giving the token up)
! call Debug.log(DEBUG_LEVEL_INFO,14, 0, 0, 0);
call Token.release();
} else {
// got the beacon!
! uint8_t *payload = (uint8_t *) m_beaconBufferPtr->data;
ieee154_macAutoRequest_t autoRequest = call MLME_GET.macAutoRequest();
uint8_t pendAddrSpecOffset = 3 + (((payload[2] & 7) > 0) ? 1 + (payload[2] & 7) * 3: 0); // skip GTS
uint8_t pendAddrSpec = payload[pendAddrSpecOffset];
uint8_t *beaconPayload = payload + pendAddrSpecOffset + 1;
! uint8_t beaconPayloadSize = call BeaconFrame.getBeaconPayloadLength(m_beaconBufferPtr);
uint8_t pendingAddrMode = ADDR_MODE_NOT_PRESENT;
uint8_t coordBeaconOrder;
! uint8_t *mhr = MHR(m_beaconBufferPtr);
! uint8_t frameLen = ((uint8_t*) m_beaconBufferPtr)[0] & FRAMECTL_LENGTH_MASK;
uint8_t gtsFieldLength;
! uint32_t timestamp = call Frame.getTimestamp(m_beaconBufferPtr);
- call Debug.log(DEBUG_LEVEL_INFO, 15, m_lastBeaconRxTime, timestamp, mhr[2]);
m_numGtsSlots = (payload[2] & 7);
gtsFieldLength = 1 + ((m_numGtsSlots > 0) ? 1 + m_numGtsSlots * 3: 0);
m_lastBeaconRxTime = timestamp;
! m_finalCapSlot = (payload[1] & 0x0F);
m_sfSlotDuration = (((uint32_t) 1) << ((payload[0] & 0xF0) >> 4)) * IEEE154_aBaseSlotDuration;
memcpy(m_gtsField, &payload[2], gtsFieldLength);
// check for battery life extension
! if (payload[1] & 0x10){
// BLE is active; calculate the time offset from slot0
! m_BLELen = IEEE154_SHR_DURATION + frameLen * IEEE154_SYMBOLS_PER_OCTET;
if (frameLen > IEEE154_aMaxSIFSFrameSize)
! m_BLELen += call MLME_GET.macMinLIFSPeriod();
else
! m_BLELen += call MLME_GET.macMinSIFSPeriod();
! m_BLELen = m_BLELen + call MLME_GET.macBattLifeExtPeriods() * 20;
} else
! m_BLELen = 0;
! m_broadcastPending = mhr[MHR_INDEX_FC1] & FC1_FRAME_PENDING ? TRUE : FALSE;
coordBeaconOrder = (payload[0] & 0x0F);
m_dt = m_beaconInterval = ((uint32_t) 1 << coordBeaconOrder) * (uint32_t) IEEE154_aBaseSuperframeDuration;
! if (m_stopTracking){
m_tracking = FALSE;
! call Debug.log(DEBUG_LEVEL_INFO,16, 0, 0, 0);
! if (m_updatePending) // there is already a new request pending...
call Token.request();
call Token.release();
} else {
! call Debug.log(DEBUG_LEVEL_INFO,17, 0, 0, 0);
! call TokenToCap.transfer(); // borrow Token to CAP/CFP module, we'll get it back afterwards
}
--- 326,407 ----
}
task void processBeaconTask()
{
! // if we received a beacon from our coordinator then it is processed now
! if (!m_bufferBusy || !call Frame.isTimestampValid(m_beaconPtr)) {
! // missed a beacon or received a beacon with invalid timestamp
! if (!m_bufferBusy)
! dbg_serial("BeaconSynchronizeP", "No beacon received!\n");
else
! dbg_serial("BeaconSynchronizeP", "Beacon has invalid timestamp!\n");
!
! m_numBeaconsLost += 1;
m_dt += m_beaconInterval;
! m_bufferBusy = FALSE;
!
! if (m_numBeaconsLost >= IEEE154_aMaxLostBeacons) {
! // lost too many beacons, give up!
m_tracking = FALSE;
! dbg_serial("BeaconSynchronizeP", "MLME_SYNC_LOSS!\n");
! signal MLME_SYNC_LOSS.indication(
IEEE154_BEACON_LOSS,
call MLME_GET.macPANId(),
call MLME_GET.phyCurrentChannel(),
call MLME_GET.phyCurrentPage(),
! NULL);
} else
call Token.request(); // make another request again (before giving the token up)
!
call Token.release();
} else {
// got the beacon!
! uint8_t *payload = (uint8_t *) m_beaconPtr->data;
ieee154_macAutoRequest_t autoRequest = call MLME_GET.macAutoRequest();
uint8_t pendAddrSpecOffset = 3 + (((payload[2] & 7) > 0) ? 1 + (payload[2] & 7) * 3: 0); // skip GTS
uint8_t pendAddrSpec = payload[pendAddrSpecOffset];
uint8_t *beaconPayload = payload + pendAddrSpecOffset + 1;
! uint8_t beaconPayloadSize = call BeaconFrame.getBeaconPayloadLength(m_beaconPtr);
uint8_t pendingAddrMode = ADDR_MODE_NOT_PRESENT;
uint8_t coordBeaconOrder;
! uint8_t *mhr = MHR(m_beaconPtr);
! uint8_t frameLen = ((uint8_t*) m_beaconPtr)[0] & FRAMECTL_LENGTH_MASK;
uint8_t gtsFieldLength;
! uint32_t timestamp = call Frame.getTimestamp(m_beaconPtr);
!
! dbg_serial("BeaconSynchronizeP", "Got beacon, timestamp: %lu, offset to previous: %lu\n",
! (uint32_t) timestamp, (uint32_t) (timestamp - m_lastBeaconRxTime));
m_numGtsSlots = (payload[2] & 7);
gtsFieldLength = 1 + ((m_numGtsSlots > 0) ? 1 + m_numGtsSlots * 3: 0);
m_lastBeaconRxTime = timestamp;
! m_numCapSlots = (payload[1] & 0x0F) + 1;
m_sfSlotDuration = (((uint32_t) 1) << ((payload[0] & 0xF0) >> 4)) * IEEE154_aBaseSlotDuration;
memcpy(m_gtsField, &payload[2], gtsFieldLength);
// check for battery life extension
! if (payload[1] & 0x10) {
// BLE is active; calculate the time offset from slot0
! m_battLifeExtDuration = IEEE154_SHR_DURATION + frameLen * IEEE154_SYMBOLS_PER_OCTET;
if (frameLen > IEEE154_aMaxSIFSFrameSize)
! m_battLifeExtDuration += call MLME_GET.macMinLIFSPeriod();
else
! m_battLifeExtDuration += call MLME_GET.macMinSIFSPeriod();
! m_battLifeExtDuration = m_battLifeExtDuration + call MLME_GET.macBattLifeExtPeriods() * 20;
} else
! m_battLifeExtDuration = 0;
!
! m_framePendingBit = mhr[MHR_INDEX_FC1] & FC1_FRAME_PENDING ? TRUE : FALSE;
coordBeaconOrder = (payload[0] & 0x0F);
m_dt = m_beaconInterval = ((uint32_t) 1 << coordBeaconOrder) * (uint32_t) IEEE154_aBaseSuperframeDuration;
!
! if (m_stopTracking) {
m_tracking = FALSE;
! dbg_serial("BeaconSynchronizeP", "Stop tracking.\n");
! if (m_updatePending) // there is already a new request ...
call Token.request();
call Token.release();
} else {
! dbg_serial("BeaconSynchronizeP", "Handing over to CAP.\n");
! call TokenToCap.transfer();
}
***************
*** 429,437 ****
if (pendAddrSpec & PENDING_ADDRESS_EXT_MASK)
beaconPayload += ((pendAddrSpec & PENDING_ADDRESS_EXT_MASK) >> 4) * 8;
// check for pending data (once we signal MLME_BEACON_NOTIFY we cannot
! // touch the frame anymore)
if (autoRequest)
! pendingAddrMode = call BeaconFrame.isLocalAddrPending(m_beaconBufferPtr);
! if (pendingAddrMode != ADDR_MODE_NOT_PRESENT){
// the coord has pending data
uint8_t CoordAddrMode;
--- 410,419 ----
if (pendAddrSpec & PENDING_ADDRESS_EXT_MASK)
beaconPayload += ((pendAddrSpec & PENDING_ADDRESS_EXT_MASK) >> 4) * 8;
+
// check for pending data (once we signal MLME_BEACON_NOTIFY we cannot
! // touch this frame anymore!)
if (autoRequest)
! pendingAddrMode = call BeaconFrame.isLocalAddrPending(m_beaconPtr);
! if (pendingAddrMode != ADDR_MODE_NOT_PRESENT) {
// the coord has pending data
uint8_t CoordAddrMode;
***************
*** 447,499 ****
call DataRequest.poll(CoordAddrMode, CoordPANId, CoordAddress, SrcAddrMode);
}
// Beacon Tracking: update state
- call Debug.log(DEBUG_LEVEL_INFO, 18, m_lastBeaconRxTime, m_beaconInterval, 0);
m_numBeaconsLost = 0;
// TODO: check PAN ID conflict here?
if (!autoRequest || beaconPayloadSize)
! m_beaconBufferPtr = signal MLME_BEACON_NOTIFY.indication(m_beaconBufferPtr);
! m_beaconSwapBufferReady = TRUE;
}
}
! async command bool IsTrackingBeacons.getNow(){ return m_tracking;}
!
! default event message_t* MLME_BEACON_NOTIFY.indication (message_t* frame){return frame;}
! default event void MLME_SYNC_LOSS.indication (
! ieee154_status_t lossReason,
! uint16_t panID,
! uint8_t logicalChannel,
! uint8_t channelPage,
! ieee154_security_t *security){}
! event void DataRequest.pollDone(){}
! async command uint8_t* GtsField.getNow() { return m_gtsField; }
! async command uint32_t SfSlotDuration.getNow() { return m_sfSlotDuration; }
! async command uint8_t FinalCapSlot.getNow() { return m_finalCapSlot; }
! async command uint32_t CapStart.getNow() { return m_lastBeaconRxTime; }
! async command ieee154_reftime_t* CapStartRefTime.getNow() { return &m_lastBeaconRxRefTime; }
! async command uint32_t CapLen.getNow() { return call SfSlotDuration.getNow() * (call FinalCapSlot.getNow() + 1);}
! async command uint32_t CapEnd.getNow()
{
! return call CapStart.getNow() + call CapLen.getNow();
}
! async command uint32_t CfpEnd.getNow()
{
! return call CapStart.getNow() + call SfSlotDuration.getNow() * IEEE154_aNumSuperframeSlots;
}
! async command uint32_t CfpLen.getNow()
{
! return call SfSlotDuration.getNow() * (15 - call FinalCapSlot.getNow());
}
! async command uint32_t BeaconInterval.getNow()
{
! return m_beaconInterval;
}
! async command uint8_t NumGtsSlots.getNow() { return m_numGtsSlots; }
! async command bool IsBLEActive.getNow(){ return m_BLELen>0;}
! async command uint16_t BLELen.getNow(){ return m_BLELen;}
! async command bool IsRxBroadcastPending.getNow() { return m_broadcastPending; }
event message_t* CoordRealignmentRx.received(message_t* frame)
--- 429,524 ----
call DataRequest.poll(CoordAddrMode, CoordPANId, CoordAddress, SrcAddrMode);
}
+
// Beacon Tracking: update state
m_numBeaconsLost = 0;
// TODO: check PAN ID conflict here?
if (!autoRequest || beaconPayloadSize)
! m_beaconPtr = signal MLME_BEACON_NOTIFY.indication(m_beaconPtr);
! m_bufferBusy = FALSE;
}
+ dbg_serial_flush();
}
! command error_t TrackSingleBeacon.start()
! {
! // Track a single beacon now
! if (!m_tracking && !m_updatePending && !call Token.isOwner()) {
! // find a single beacon now (treat this like a user request)
! m_updateLogicalChannel = call MLME_GET.phyCurrentChannel();
! m_updateTrackBeacon = FALSE;
! m_stopTracking = TRUE;
! m_updatePending = TRUE;
! call Token.request();
! }
! return SUCCESS;
! }
! command error_t TrackSingleBeacon.stop()
! {
! // will stop automatically after beacon was tracked/not found
! return FAIL;
! }
! /* ----------------------- SF Structure, etc. ----------------------- */
! async command uint32_t IncomingSF.sfStartTime()
! {
! return m_lastBeaconRxTime;
! }
!
! async command uint16_t IncomingSF.sfSlotDuration()
! {
! return m_sfSlotDuration;
! }
!
! async command uint8_t IncomingSF.numCapSlots()
{
! return m_numCapSlots;
}
!
! async command uint8_t IncomingSF.numGtsSlots()
{
! return m_numGtsSlots;
}
!
! async command uint16_t IncomingSF.battLifeExtDuration()
{
! return m_battLifeExtDuration;
}
!
! async command const uint8_t* IncomingSF.gtsFields()
{
! return m_gtsField;
}
!
! async command uint16_t IncomingSF.guardTime()
! {
! return IEEE154_MAX_BEACON_JITTER(m_beaconOrder) + IEEE154_RADIO_RX_DELAY;
! }
!
! async command const ieee154_timestamp_t* IncomingSF.sfStartTimeRef()
! {
! return &m_lastBeaconRxRefTime;
! }
!
! async command bool IncomingSF.isBroadcastPending()
! {
! return m_framePendingBit;
! }
!
! async command bool IsTrackingBeacons.getNow()
! {
! return m_tracking;
! }
!
! event void DataRequest.pollDone() {}
!
! default event message_t* MLME_BEACON_NOTIFY.indication (message_t* frame) {return frame;}
! default event void MLME_SYNC_LOSS.indication (
! ieee154_status_t lossReason,
! uint16_t panID,
! uint8_t logicalChannel,
! uint8_t channelPage,
! ieee154_security_t *security) {}
event message_t* CoordRealignmentRx.received(message_t* frame)
***************
*** 507,512 ****
payload[5], // LogicalChannel,
call Frame.getPayloadLength(frame) == 9 ? payload[8] : call MLME_GET.phyCurrentPage(),
! NULL
! );
return frame;
}
--- 532,536 ----
payload[5], // LogicalChannel,
call Frame.getPayloadLength(frame) == 9 ? payload[8] : call MLME_GET.phyCurrentPage(),
! NULL);
return frame;
}
Index: BeaconTransmitP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/mac/tkn154/BeaconTransmitP.nc,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** BeaconTransmitP.nc 25 Nov 2008 09:35:08 -0000 1.6
--- BeaconTransmitP.nc 4 Mar 2009 18:31:17 -0000 1.7
***************
*** 34,37 ****
--- 34,42 ----
*/
+ /**
+ * This module is responsible for periodic beacon transmission in a
+ * beacon-enabled PAN.
+ */
+
#include "TKN154_MAC.h"
#include "TKN154_PHY.h"
[...1198 lines suppressed...]
! return &m_lastBeaconTxRefTime;
! }
! async command bool OutgoingSF.isBroadcastPending()
! {
! return m_framePendingBit;
! }
! async command bool IsSendingBeacons.getNow()
! {
! return (m_beaconOrder < 15) || ((m_requestBitmap & REQUEST_CONFIRM_PENDING) && m_updateBeaconOrder < 15);
! }
! default event void MLME_START.confirm(ieee154_status_t status) {}
! default event void IEEE154TxBeaconPayload.setBeaconPayloadDone(void *beaconPayload, uint8_t length) {}
! default event void IEEE154TxBeaconPayload.modifyBeaconPayloadDone(uint8_t offset, void *buffer, uint8_t bufferLength) {}
! default event void IEEE154TxBeaconPayload.aboutToTransmit() {}
! default event void IEEE154TxBeaconPayload.beaconTransmitted() {}
}
Index: CoordBroadcastP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/mac/tkn154/CoordBroadcastP.nc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** CoordBroadcastP.nc 21 Oct 2008 17:29:00 -0000 1.3
--- CoordBroadcastP.nc 4 Mar 2009 18:31:18 -0000 1.4
***************
*** 52,56 ****
interface ResourceTransfer as TokenToCap;
interface ResourceTransferred as TokenTransferred;
! interface GetNow<bool> as BeaconFramePendingBit;
interface Leds;
}
--- 52,56 ----
interface ResourceTransfer as TokenToCap;
interface ResourceTransferred as TokenTransferred;
! interface SuperframeStructure as OutgoingSF;
interface Leds;
}
***************
*** 91,95 ****
{
atomic {
! if (!m_realignmentFrame){
m_realignmentFrame = frame;
return IEEE154_SUCCESS;
--- 91,95 ----
{
atomic {
! if (!m_realignmentFrame) {
m_realignmentFrame = frame;
return IEEE154_SUCCESS;
***************
*** 110,122 ****
{
// CAP has started - are there any broadcast frames to be transmitted?
! if (call BeaconFramePendingBit.getNow()){
ieee154_txframe_t *broadcastFrame = m_realignmentFrame;
if (broadcastFrame == NULL)
broadcastFrame = m_queueHead;
! if (broadcastFrame){
! m_lock = TRUE;
! call CapTransmitNow.transmitNow(broadcastFrame);
! } else
! call Leds.led0On(); // internal error!
}
call TokenToCap.transfer();
--- 110,120 ----
{
// CAP has started - are there any broadcast frames to be transmitted?
! if (call OutgoingSF.isBroadcastPending()) {
ieee154_txframe_t *broadcastFrame = m_realignmentFrame;
if (broadcastFrame == NULL)
broadcastFrame = m_queueHead;
! ASSERT(broadcastFrame != NULL);
! m_lock = TRUE;
! call CapTransmitNow.transmitNow(broadcastFrame);
}
call TokenToCap.transfer();
***************
*** 134,141 ****
if (!m_lock)
return;
! if (m_transmittedFrame == m_realignmentFrame){
m_realignmentFrame = NULL;
signal RealignmentTx.transmitDone(m_transmittedFrame, m_status);
! } else if (m_transmittedFrame == m_queueHead){
call Queue.dequeue();
m_queueHead = call Queue.head();
--- 132,139 ----
if (!m_lock)
return;
! if (m_transmittedFrame == m_realignmentFrame) {
m_realignmentFrame = NULL;
signal RealignmentTx.transmitDone(m_transmittedFrame, m_status);
! } else if (m_transmittedFrame == m_queueHead) {
call Queue.dequeue();
m_queueHead = call Queue.head();
Index: CoordRealignmentP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/mac/tkn154/CoordRealignmentP.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** CoordRealignmentP.nc 16 Jun 2008 18:00:27 -0000 1.1
--- CoordRealignmentP.nc 4 Mar 2009 18:31:22 -0000 1.2
***************
*** 68,71 ****
--- 68,72 ----
BEACON_REALIGNMENT,
};
+
uint8_t m_payload[9];
bool m_busy = FALSE;
***************
*** 97,102 ****
signal MLME_ORPHAN.indication (
srcAddress.extendedAddress,
! NULL // security
! );
return frame;
}
--- 98,102 ----
signal MLME_ORPHAN.indication (
srcAddress.extendedAddress,
! NULL);
return frame;
}
***************
*** 106,111 ****
uint16_t ShortAddress,
bool AssociatedMember,
! ieee154_security_t *security
! )
{
ieee154_txframe_t *txFrame;
--- 106,110 ----
uint16_t ShortAddress,
bool AssociatedMember,
! ieee154_security_t *security)
{
ieee154_txframe_t *txFrame;
***************
*** 126,130 ****
*((nxle_uint16_t*) &txFrame->payload[6]) = ShortAddress;
txFrame->payloadLen = 8;
! if ((txStatus = call CoordRealignmentTx.transmit(txFrame)) != IEEE154_SUCCESS){
m_busy = FALSE;
destroyRealignmentFrame(txFrame);
--- 125,129 ----
*((nxle_uint16_t*) &txFrame->payload[6]) = ShortAddress;
txFrame->payloadLen = 8;
! if ((txStatus = call CoordRealignmentTx.transmit(txFrame)) != IEEE154_SUCCESS) {
m_busy = FALSE;
destroyRealignmentFrame(txFrame);
***************
*** 141,146 ****
ieee154_address_t srcAddress;
! if ((txFrame = call TxFramePool.get()) != NULL){
! if ((txControl = call TxControlPool.get()) == NULL){
call TxFramePool.put(txFrame);
txFrame = NULL;
--- 140,145 ----
ieee154_address_t srcAddress;
! if ((txFrame = call TxFramePool.get()) != NULL) {
! if ((txControl = call TxControlPool.get()) == NULL) {
call TxFramePool.put(txFrame);
txFrame = NULL;
***************
*** 151,155 ****
txFrame->header->mhr[MHR_INDEX_FC1] = FC1_FRAMETYPE_CMD;
txFrame->header->mhr[MHR_INDEX_FC2] = FC2_SRC_MODE_EXTENDED;
! if (type == ORPHAN_RESPONSE){
txFrame->header->mhr[MHR_INDEX_FC2] |= FC2_DEST_MODE_EXTENDED;
dstAddrMode = ADDR_MODE_EXTENDED_ADDRESS;
--- 150,154 ----
txFrame->header->mhr[MHR_INDEX_FC1] = FC1_FRAMETYPE_CMD;
txFrame->header->mhr[MHR_INDEX_FC2] = FC2_SRC_MODE_EXTENDED;
! if (type == ORPHAN_RESPONSE) {
txFrame->header->mhr[MHR_INDEX_FC2] |= FC2_DEST_MODE_EXTENDED;
dstAddrMode = ADDR_MODE_EXTENDED_ADDRESS;
***************
*** 186,190 ****
ieee154_address_t dstAddr;
ieee154_address_t srcAddr;
! if (m_busy){
call FrameUtility.convertToNative(&dstAddr.extendedAddress, &mhr[MHR_INDEX_ADDRESS+2]);
call FrameUtility.convertToNative(&srcAddr.extendedAddress, &mhr[MHR_INDEX_ADDRESS+2+8+2]);
--- 185,190 ----
ieee154_address_t dstAddr;
ieee154_address_t srcAddr;
!
! if (m_busy) {
call FrameUtility.convertToNative(&dstAddr.extendedAddress, &mhr[MHR_INDEX_ADDRESS+2]);
call FrameUtility.convertToNative(&srcAddr.extendedAddress, &mhr[MHR_INDEX_ADDRESS+2+8+2]);
***************
*** 196,201 ****
dstAddr,
status,
! NULL //security
! );
call TxControlPool.put((ieee154_txcontrol_t*) ((uint8_t*) txFrame->header - offsetof(ieee154_txcontrol_t, header)));
call TxFramePool.put(txFrame);
--- 196,200 ----
dstAddr,
status,
! NULL);
call TxControlPool.put((ieee154_txcontrol_t*) ((uint8_t*) txFrame->header - offsetof(ieee154_txcontrol_t, header)));
call TxFramePool.put(txFrame);
***************
*** 211,220 ****
ieee154_address_t DstAddr,
ieee154_status_t status,
! ieee154_security_t *security
! ){}
default event void MLME_ORPHAN.indication (
uint64_t OrphanAddress,
! ieee154_security_t *security
! ){}
}
--- 210,217 ----
ieee154_address_t DstAddr,
ieee154_status_t status,
! ieee154_security_t *security) {}
default event void MLME_ORPHAN.indication (
uint64_t OrphanAddress,
! ieee154_security_t *security) {}
}
Index: DataP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/mac/tkn154/DataP.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** DataP.nc 21 Oct 2008 17:29:00 -0000 1.2
--- DataP.nc 4 Mar 2009 18:31:22 -0000 1.3
***************
*** 81,86 ****
uint8_t payloadLen,
uint8_t msduHandle,
! uint8_t txOptions
! )
{
uint8_t srcAddrMode = call Frame.getSrcAddrMode(frame);
--- 81,85 ----
uint8_t payloadLen,
uint8_t msduHandle,
! uint8_t txOptions)
{
uint8_t srcAddrMode = call Frame.getSrcAddrMode(frame);
***************
*** 124,133 ****
// sent in the incoming sf otherwise in the outgoing sf
call Frame.getDstAddr(frame, &dstAddr);
! if (dstAddrMode == ADDR_MODE_SHORT_ADDRESS){
if (dstAddr.shortAddress == call MLME_GET.macCoordShortAddress())
sfType = INCOMING_SUPERFRAME;
else
sfType = OUTGOING_SUPERFRAME;
! } else if (dstAddrMode == ADDR_MODE_EXTENDED_ADDRESS){
if (dstAddr.extendedAddress == call MLME_GET.macCoordExtendedAddress())
sfType = INCOMING_SUPERFRAME;
--- 123,132 ----
// sent in the incoming sf otherwise in the outgoing sf
call Frame.getDstAddr(frame, &dstAddr);
! if (dstAddrMode == ADDR_MODE_SHORT_ADDRESS) {
if (dstAddr.shortAddress == call MLME_GET.macCoordShortAddress())
sfType = INCOMING_SUPERFRAME;
else
sfType = OUTGOING_SUPERFRAME;
! } else if (dstAddrMode == ADDR_MODE_EXTENDED_ADDRESS) {
if (dstAddr.extendedAddress == call MLME_GET.macCoordExtendedAddress())
sfType = INCOMING_SUPERFRAME;
***************
*** 138,142 ****
// GTS?
! if (txOptions & TX_OPTIONS_GTS){
if (sfType == INCOMING_SUPERFRAME)
txStatus = call DeviceCfpTx.transmit(txFrame);
--- 137,141 ----
// GTS?
! if (txOptions & TX_OPTIONS_GTS) {
if (sfType == INCOMING_SUPERFRAME)
txStatus = call DeviceCfpTx.transmit(txFrame);
***************
*** 147,152 ****
} else if ((txOptions & TX_OPTIONS_INDIRECT) &&
call IsSendingBeacons.getNow() &&
! (dstAddrMode >= ADDR_MODE_SHORT_ADDRESS)){
! if (dstAddrMode == ADDR_MODE_SHORT_ADDRESS && dstAddr.shortAddress == 0xFFFF){
mhr[MHR_INDEX_FC1] &= ~FC1_ACK_REQUEST;
txStatus = call BroadcastTx.transmit(txFrame);
--- 146,151 ----
} else if ((txOptions & TX_OPTIONS_INDIRECT) &&
call IsSendingBeacons.getNow() &&
! (dstAddrMode >= ADDR_MODE_SHORT_ADDRESS)) {
! if (dstAddrMode == ADDR_MODE_SHORT_ADDRESS && dstAddr.shortAddress == 0xFFFF) {
mhr[MHR_INDEX_FC1] &= ~FC1_ACK_REQUEST;
txStatus = call BroadcastTx.transmit(txFrame);
***************
*** 161,165 ****
txStatus = call CoordCapTx.transmit(txFrame);
! if (txStatus != IEEE154_SUCCESS){
call TxFramePool.put(txFrame);
}
--- 160,164 ----
txStatus = call CoordCapTx.transmit(txFrame);
! if (txStatus != IEEE154_SUCCESS) {
call TxFramePool.put(txFrame);
}
***************
*** 169,174 ****
command ieee154_status_t MCPS_PURGE.request (
! uint8_t msduHandle
! )
{
if (call PurgeDirect.purge(msduHandle) == IEEE154_SUCCESS ||
--- 168,172 ----
command ieee154_status_t MCPS_PURGE.request (
! uint8_t msduHandle)
{
if (call PurgeDirect.purge(msduHandle) == IEEE154_SUCCESS ||
***************
*** 223,227 ****
message_t* dataReceived(message_t* frame)
{
! return signal MCPS_DATA.indication( frame );
}
--- 221,225 ----
message_t* dataReceived(message_t* frame)
{
! return signal MCPS_DATA.indication(frame);
}
***************
*** 231,234 ****
--- 229,233 ----
uint32_t txTime = txFrame->metadata->timestamp;
message_t *msg = (message_t*) ((uint8_t*) txFrame->header - offsetof(message_t, header));
+
call TxFramePool.put(txFrame);
signal MCPS_DATA.confirm(msg, handle, status, txTime);
***************
*** 270,278 ****
uint8_t msduHandle,
ieee154_status_t status,
! uint32_t Timestamp
! ){}
! default event message_t* MCPS_DATA.indication ( message_t* frame ){ return frame; }
! default command ieee154_status_t DeviceCfpTx.transmit(ieee154_txframe_t *data){return IEEE154_INVALID_GTS;}
! default command ieee154_status_t CoordCfpTx.transmit(ieee154_txframe_t *data){return IEEE154_INVALID_GTS;}
}
--- 269,276 ----
uint8_t msduHandle,
ieee154_status_t status,
! uint32_t Timestamp) {}
! default event message_t* MCPS_DATA.indication(message_t* frame) { return frame; }
! default command ieee154_status_t DeviceCfpTx.transmit(ieee154_txframe_t *data) {return IEEE154_INVALID_GTS;}
! default command ieee154_status_t CoordCfpTx.transmit(ieee154_txframe_t *data) {return IEEE154_INVALID_GTS;}
}
Index: DisassociateP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/mac/tkn154/DisassociateP.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** DisassociateP.nc 25 Nov 2008 09:35:08 -0000 1.2
--- DisassociateP.nc 4 Mar 2009 18:31:22 -0000 1.3
***************
*** 59,63 ****
interface IEEE154Frame as Frame;
interface Get<uint64_t> as LocalExtendedAddress;
- interface Ieee802154Debug as Debug;
}
}
--- 59,62 ----
***************
*** 79,83 ****
}
! /* ------------------- MLME_DISASSOCIATE (initiating) ------------------- */
command ieee154_status_t MLME_DISASSOCIATE.request (
--- 78,82 ----
}
! /* ------------------- MLME_DISASSOCIATE (initiating) ------------------- */
command ieee154_status_t MLME_DISASSOCIATE.request (
***************
*** 87,92 ****
ieee154_disassociation_reason_t DisassociateReason,
bool TxIndirect,
! ieee154_security_t *security
! )
{
ieee154_status_t status = IEEE154_SUCCESS;
--- 86,90 ----
ieee154_disassociation_reason_t DisassociateReason,
bool TxIndirect,
! ieee154_security_t *security)
{
ieee154_status_t status = IEEE154_SUCCESS;
***************
*** 102,110 ****
else if (m_disAssociationOngoing || !(txFrame = call TxFramePool.get()))
status = IEEE154_TRANSACTION_OVERFLOW;
! else if (!(txControl = call TxControlPool.get())){
call TxFramePool.put(txFrame);
status = IEEE154_TRANSACTION_OVERFLOW;
}
! if (status == IEEE154_SUCCESS){
txFrame->header = &txControl->header;
txFrame->metadata = &txControl->metadata;
--- 100,108 ----
else if (m_disAssociationOngoing || !(txFrame = call TxFramePool.get()))
status = IEEE154_TRANSACTION_OVERFLOW;
! else if (!(txControl = call TxControlPool.get())) {
call TxFramePool.put(txFrame);
status = IEEE154_TRANSACTION_OVERFLOW;
}
! if (status == IEEE154_SUCCESS) {
txFrame->header = &txControl->header;
txFrame->metadata = &txControl->metadata;
***************
*** 130,134 ****
DeviceAddress.shortAddress == call MLME_GET.macCoordShortAddress()) ||
(DeviceAddrMode == ADDR_MODE_EXTENDED_ADDRESS &&
! DeviceAddress.extendedAddress == call MLME_GET.macCoordExtendedAddress())){
status = call DisassociationToCoord.transmit(txFrame);
} else if (TxIndirect) {
--- 128,132 ----
DeviceAddress.shortAddress == call MLME_GET.macCoordShortAddress()) ||
(DeviceAddrMode == ADDR_MODE_EXTENDED_ADDRESS &&
! DeviceAddress.extendedAddress == call MLME_GET.macCoordExtendedAddress())) {
status = call DisassociationToCoord.transmit(txFrame);
} else if (TxIndirect) {
***************
*** 137,141 ****
status = call DisassociationDirectTx.transmit(txFrame);
}
! if (status != IEEE154_SUCCESS){
m_disAssociationOngoing = FALSE;
call TxFramePool.put(txFrame);
--- 135,139 ----
status = call DisassociationDirectTx.transmit(txFrame);
}
! if (status != IEEE154_SUCCESS) {
m_disAssociationOngoing = FALSE;
call TxFramePool.put(txFrame);
***************
*** 143,147 ****
}
}
! call Debug.log(DEBUG_LEVEL_INFO, DISSASSOCIATE_REQUEST, status, 0, 0);
return status;
}
--- 141,145 ----
}
}
! dbg_serial("DisassociateP", "MLME_DISASSOCIATE.request -> result: %lu\n", (uint32_t) status);
return status;
}
***************
*** 159,163 ****
call TxControlPool.put((ieee154_txcontrol_t*) ((uint8_t*) data->header - offsetof(ieee154_txcontrol_t, header)));
call TxFramePool.put(data);
! call Debug.log(DEBUG_LEVEL_INFO, DISSASSOCIATE_TXDONE, status, 2, 0);
m_disAssociationOngoing = FALSE;
signal MLME_DISASSOCIATE.confirm(status, DeviceAddrMode, DevicePANID, DeviceAddress);
--- 157,161 ----
call TxControlPool.put((ieee154_txcontrol_t*) ((uint8_t*) data->header - offsetof(ieee154_txcontrol_t, header)));
call TxFramePool.put(data);
! dbg_serial("DisassociateP", "transmitDone() -> result: %lu\n", (uint32_t) status);
m_disAssociationOngoing = FALSE;
signal MLME_DISASSOCIATE.confirm(status, DeviceAddrMode, DevicePANID, DeviceAddress);
***************
*** 177,189 ****
ieee154_address_t DeviceAddress;
call FrameUtility.convertToNative(&DeviceAddress.extendedAddress, &mhr[dstAddrOffset]);
- call Debug.log(DEBUG_LEVEL_INFO, DISSASSOCIATE_TXDONE, status, 1, 0);
call TxControlPool.put((ieee154_txcontrol_t*) ((uint8_t*) data->header - offsetof(ieee154_txcontrol_t, header)));
call TxFramePool.put(data);
! call Debug.log(DEBUG_LEVEL_INFO, DISSASSOCIATE_TXDONE, status, 2, 0);
m_disAssociationOngoing = FALSE;
signal MLME_DISASSOCIATE.confirm(status, DeviceAddrMode, DevicePANID, DeviceAddress);
}
! /* ------------------- MLME_DISASSOCIATE (receiving) ------------------- */
event message_t* DisassociationDirectRxFromCoord.received(message_t* frame)
--- 175,186 ----
ieee154_address_t DeviceAddress;
call FrameUtility.convertToNative(&DeviceAddress.extendedAddress, &mhr[dstAddrOffset]);
call TxControlPool.put((ieee154_txcontrol_t*) ((uint8_t*) data->header - offsetof(ieee154_txcontrol_t, header)));
call TxFramePool.put(data);
! dbg_serial("DisassociateP", "transmitDone() -> result: %lu\n", (uint32_t) status);
m_disAssociationOngoing = FALSE;
signal MLME_DISASSOCIATE.confirm(status, DeviceAddrMode, DevicePANID, DeviceAddress);
}
! /* ------------------- MLME_DISASSOCIATE (receiving) ------------------- */
event message_t* DisassociationDirectRxFromCoord.received(message_t* frame)
***************
*** 206,229 ****
// received a disassociation notification from the device
ieee154_address_t address;
- call Debug.log(DEBUG_LEVEL_INFO, DISSASSOCIATE_RX, 0, 0, 0);
if (call Frame.getSrcAddrMode(frame) == ADDR_MODE_EXTENDED_ADDRESS &&
call Frame.getSrcAddr(frame, &address) == SUCCESS)
signal MLME_DISASSOCIATE.indication(address.extendedAddress, frame->data[1], NULL);
return frame;
}
! /* ------------------- Defaults ------------------- */
default event void MLME_DISASSOCIATE.indication (
uint64_t DeviceAddress,
ieee154_disassociation_reason_t DisassociateReason,
! ieee154_security_t *security
! ){}
default event void MLME_DISASSOCIATE.confirm (
ieee154_status_t status,
uint8_t DeviceAddrMode,
uint16_t DevicePANID,
! ieee154_address_t DeviceAddress
! ){}
}
--- 203,225 ----
// received a disassociation notification from the device
ieee154_address_t address;
if (call Frame.getSrcAddrMode(frame) == ADDR_MODE_EXTENDED_ADDRESS &&
call Frame.getSrcAddr(frame, &address) == SUCCESS)
signal MLME_DISASSOCIATE.indication(address.extendedAddress, frame->data[1], NULL);
+ dbg_serial("DisassociateP", "Received disassociation request from %lx\n", (uint32_t) address.shortAddress);
return frame;
}
! /* ------------------- Defaults ------------------- */
default event void MLME_DISASSOCIATE.indication (
uint64_t DeviceAddress,
ieee154_disassociation_reason_t DisassociateReason,
! ieee154_security_t *security) {}
!
default event void MLME_DISASSOCIATE.confirm (
ieee154_status_t status,
uint8_t DeviceAddrMode,
uint16_t DevicePANID,
! ieee154_address_t DeviceAddress) {}
}
Index: FrameDispatchQueueP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/mac/tkn154/FrameDispatchQueueP.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** FrameDispatchQueueP.nc 25 Nov 2008 09:35:08 -0000 1.1
--- FrameDispatchQueueP.nc 4 Mar 2009 18:31:24 -0000 1.2
***************
*** 55,59 ****
command error_t Reset.init()
{
! while (call Queue.size()){
ieee154_txframe_t *txFrame = call Queue.dequeue();
signal FrameTx.transmitDone[txFrame->client](txFrame, IEEE154_TRANSACTION_OVERFLOW);
--- 55,59 ----
command error_t Reset.init()
{
! while (call Queue.size()) {
ieee154_txframe_t *txFrame = call Queue.dequeue();
signal FrameTx.transmitDone[txFrame->client](txFrame, IEEE154_TRANSACTION_OVERFLOW);
***************
*** 76,82 ****
task void txTask()
{
! if (!m_busy && call Queue.size()){
ieee154_txframe_t *txFrame = call Queue.head();
! if (txFrame->headerLen == 0){
// was purged
call Queue.dequeue();
--- 76,82 ----
task void txTask()
{
! if (!m_busy && call Queue.size()) {
ieee154_txframe_t *txFrame = call Queue.head();
! if (txFrame->headerLen == 0) {
// was purged
call Queue.dequeue();
***************
*** 85,89 ****
}
m_client = txFrame->client;
! if (call FrameTxCsma.transmit(txFrame) == IEEE154_SUCCESS){
m_busy = TRUE;
}
--- 85,89 ----
}
m_client = txFrame->client;
! if (call FrameTxCsma.transmit(txFrame) == IEEE154_SUCCESS) {
m_busy = TRUE;
}
***************
*** 107,120 ****
}
! default event void FrameTx.transmitDone[uint8_t client](ieee154_txframe_t *txFrame, ieee154_status_t status){}
command ieee154_status_t Purge.purge(uint8_t msduHandle)
{
uint8_t qSize = call Queue.size(), i;
! if (qSize > 1){
! for (i=0; i<qSize-1; i++){
ieee154_txframe_t *txFrame = call Queue.element(i);
if (((txFrame->header->mhr[MHR_INDEX_FC1] & FC1_FRAMETYPE_MASK) == FC1_FRAMETYPE_DATA) &&
! txFrame->handle == msduHandle){
txFrame->headerLen = 0; // mark as invalid
return IEEE154_SUCCESS;
--- 107,120 ----
}
! default event void FrameTx.transmitDone[uint8_t client](ieee154_txframe_t *txFrame, ieee154_status_t status) {}
command ieee154_status_t Purge.purge(uint8_t msduHandle)
{
uint8_t qSize = call Queue.size(), i;
! if (qSize > 1) {
! for (i=0; i<qSize-1; i++) {
ieee154_txframe_t *txFrame = call Queue.element(i);
if (((txFrame->header->mhr[MHR_INDEX_FC1] & FC1_FRAMETYPE_MASK) == FC1_FRAMETYPE_DATA) &&
! txFrame->handle == msduHandle) {
txFrame->headerLen = 0; // mark as invalid
return IEEE154_SUCCESS;
***************
*** 125,128 ****
}
! default event void Purge.purgeDone(ieee154_txframe_t *txFrame, ieee154_status_t status){}
}
--- 125,128 ----
}
! default event void Purge.purgeDone(ieee154_txframe_t *txFrame, ieee154_status_t status) {}
}
Index: IndirectTxP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/mac/tkn154/IndirectTxP.nc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** IndirectTxP.nc 25 Nov 2008 09:35:09 -0000 1.3
--- IndirectTxP.nc 4 Mar 2009 18:31:24 -0000 1.4
***************
*** 54,58 ****
interface TimeCalc;
interface Leds;
- interface Ieee802154Debug as Debug;
}
}
--- 54,57 ----
***************
*** 118,126 ****
pendingAddrField[0] = 0;
adrPtr = (nxle_uint16_t *) &pendingAddrField[1];
! for (i=0; i<NUM_MAX_PENDING; i++){
if (!m_txFrameTable[i])
continue;
txFrame = m_txFrameTable[i];
! if ((txFrame->header->mhr[MHR_INDEX_FC2] & FC2_DEST_MODE_MASK) == FC2_DEST_MODE_SHORT){
*adrPtr++ = *((nxle_uint16_t*) &txFrame->header->mhr[MHR_INDEX_ADDRESS + sizeof(ieee154_macPANId_t)]);
} else if ((txFrame->header->mhr[MHR_INDEX_FC2] & FC2_DEST_MODE_MASK) == FC2_DEST_MODE_EXTENDED)
--- 117,125 ----
pendingAddrField[0] = 0;
adrPtr = (nxle_uint16_t *) &pendingAddrField[1];
! for (i=0; i<NUM_MAX_PENDING; i++) {
if (!m_txFrameTable[i])
continue;
txFrame = m_txFrameTable[i];
! if ((txFrame->header->mhr[MHR_INDEX_FC2] & FC2_DEST_MODE_MASK) == FC2_DEST_MODE_SHORT) {
*adrPtr++ = *((nxle_uint16_t*) &txFrame->header->mhr[MHR_INDEX_ADDRESS + sizeof(ieee154_macPANId_t)]);
} else if ((txFrame->header->mhr[MHR_INDEX_FC2] & FC2_DEST_MODE_MASK) == FC2_DEST_MODE_EXTENDED)
***************
*** 131,135 ****
pendingAddrField[1 + 2*m_numShortPending + i*8 + j] = longAdrPtr[i][j];
pendingAddrField[0] = m_numShortPending | (m_numExtPending << 4);
- call Debug.log(DEBUG_LEVEL_INFO, IndirectTxP_BEACON_ASSEMBLY, len,0,0);
return len;
}
--- 130,133 ----
***************
*** 144,149 ****
// send a frame through indirect transmission
uint8_t i;
! if (m_numTableEntries >= NUM_MAX_PENDING){
! call Debug.log(DEBUG_LEVEL_IMPORTANT, IndirectTxP_OVERFLOW, 0,0,0);
return IEEE154_TRANSACTION_OVERFLOW;
}
--- 142,147 ----
// send a frame through indirect transmission
uint8_t i;
! if (m_numTableEntries >= NUM_MAX_PENDING) {
! dbg_serial("IndirectTxP", "Overflow\n");
return IEEE154_TRANSACTION_OVERFLOW;
}
***************
*** 161,165 ****
if (!call IndirectTxTimeout.isRunning())
call IndirectTxTimeout.startOneShot(getPersistenceTime());
! call Debug.log(DEBUG_LEVEL_INFO, IndirectTxP_NOTIFIED, 0,0,0);
signal PendingAddrSpecUpdated.notify(TRUE);
return IEEE154_SUCCESS;
--- 159,163 ----
if (!call IndirectTxTimeout.isRunning())
call IndirectTxTimeout.startOneShot(getPersistenceTime());
! dbg_serial("IndirectTxP", "Preparing a transmission.\n");
signal PendingAddrSpecUpdated.notify(TRUE);
return IEEE154_SUCCESS;
***************
*** 186,190 ****
if (!((mhr[0] & FC1_PAN_ID_COMPRESSION) && (mhr[1] & FC2_DEST_MODE_SHORT)))
src += 2;
! for (i=0; i<NUM_MAX_PENDING; i++){
if (!m_txFrameTable[i])
continue;
--- 184,188 ----
if (!((mhr[0] & FC1_PAN_ID_COMPRESSION) && (mhr[1] & FC2_DEST_MODE_SHORT)))
src += 2;
! for (i=0; i<NUM_MAX_PENDING; i++) {
if (!m_txFrameTable[i])
continue;
***************
*** 205,210 ****
}
}
! call Debug.log(DEBUG_LEVEL_INFO, IndirectTxP_REQUESTED, NUM_MAX_PENDING-i,i,*src);
! if (i != NUM_MAX_PENDING){
// found a matching frame, mark it for transmission
m_txFrameTable[i]->client |= SEND_THIS_FRAME;
--- 203,209 ----
}
}
! dbg_serial("IndirectTxP", "Received a request, i=%lu, MAX=%lu\n",
! (uint32_t) i,(uint32_t) NUM_MAX_PENDING);
! if (i != NUM_MAX_PENDING) {
// found a matching frame, mark it for transmission
m_txFrameTable[i]->client |= SEND_THIS_FRAME;
***************
*** 221,232 ****
// (if they are marked for transmission)
uint8_t i;
! if (m_pendingTxFrame == NULL && m_numTableEntries){
for (i=0; i<NUM_MAX_PENDING; i++)
! if (m_txFrameTable[i] && (m_txFrameTable[i]->client & SEND_THIS_FRAME)){
// TODO: set frame pending bit, if there's more data for this destination
m_pendingTxFrame = m_txFrameTable[i];
m_client = m_txFrameTable[i]->client;
! if (call CoordCapTx.transmit(m_txFrameTable[i]) == IEEE154_SUCCESS){
! call Debug.log(DEBUG_LEVEL_INFO, IndirectTxP_SEND_NOW, 0,0,0);
} else {
m_pendingTxFrame = NULL;
--- 220,231 ----
// (if they are marked for transmission)
uint8_t i;
! if (m_pendingTxFrame == NULL && m_numTableEntries) {
for (i=0; i<NUM_MAX_PENDING; i++)
! if (m_txFrameTable[i] && (m_txFrameTable[i]->client & SEND_THIS_FRAME)) {
// TODO: set frame pending bit, if there's more data for this destination
m_pendingTxFrame = m_txFrameTable[i];
m_client = m_txFrameTable[i]->client;
! if (call CoordCapTx.transmit(m_txFrameTable[i]) == IEEE154_SUCCESS) {
! dbg_serial("IndirectTxP", "Started a transmission.\n");
} else {
m_pendingTxFrame = NULL;
***************
*** 251,256 ****
for (i=0; i<NUM_MAX_PENDING; i++)
! if (m_txFrameTable[i] && m_txFrameTable[i] != m_pendingTxFrame){
! if (call TimeCalc.hasExpired(m_txFrameTable[i]->metadata->timestamp, persistenceTime)){
ieee154_txframe_t *txFrame = m_txFrameTable[i];
txFrame->client &= ~SEND_THIS_FRAME;
--- 250,255 ----
for (i=0; i<NUM_MAX_PENDING; i++)
! if (m_txFrameTable[i] && m_txFrameTable[i] != m_pendingTxFrame) {
! if (call TimeCalc.hasExpired(m_txFrameTable[i]->metadata->timestamp, persistenceTime)) {
ieee154_txframe_t *txFrame = m_txFrameTable[i];
txFrame->client &= ~SEND_THIS_FRAME;
***************
*** 263,271 ****
signal FrameTx.transmitDone[txFrame->client](txFrame, IEEE154_TRANSACTION_EXPIRED);
signal PendingAddrSpecUpdated.notify(TRUE);
! } else if (call TimeCalc.timeElapsed(m_txFrameTable[i]->metadata->timestamp, now) > dt){
dt = call TimeCalc.timeElapsed(m_txFrameTable[i]->metadata->timestamp, now);
}
}
! if (dt != 0){
if (dt > persistenceTime)
dt = persistenceTime;
--- 262,270 ----
signal FrameTx.transmitDone[txFrame->client](txFrame, IEEE154_TRANSACTION_EXPIRED);
signal PendingAddrSpecUpdated.notify(TRUE);
! } else if (call TimeCalc.timeElapsed(m_txFrameTable[i]->metadata->timestamp, now) > dt) {
dt = call TimeCalc.timeElapsed(m_txFrameTable[i]->metadata->timestamp, now);
}
}
! if (dt != 0) {
if (dt > persistenceTime)
dt = persistenceTime;
***************
*** 279,283 ****
// TODO: if CSMA-CA algorithm failed, then frame shall still remain in transaction queue
for (i=0; i<NUM_MAX_PENDING; i++)
! if (m_txFrameTable[i] == txFrame){
m_txFrameTable[i] = NULL; // slot is now empty
break;
--- 278,282 ----
// TODO: if CSMA-CA algorithm failed, then frame shall still remain in transaction queue
for (i=0; i<NUM_MAX_PENDING; i++)
! if (m_txFrameTable[i] == txFrame) {
m_txFrameTable[i] = NULL; // slot is now empty
break;
***************
*** 294,303 ****
signal FrameTx.transmitDone[txFrame->client](txFrame, status);
post tryCoordCapTxTask();
! call Debug.log(DEBUG_LEVEL_INFO, IndirectTxP_SEND_DONE, status,m_numTableEntries,0);
}
! command ieee154_txframe_t* GetIndirectTxFrame.get(){ return m_pendingTxFrame;}
! command error_t PendingAddrSpecUpdated.enable(){return FAIL;}
! command error_t PendingAddrSpecUpdated.disable(){return FAIL;}
! default event void FrameTx.transmitDone[uint8_t client](ieee154_txframe_t *txFrame, ieee154_status_t status){}
}
--- 293,303 ----
signal FrameTx.transmitDone[txFrame->client](txFrame, status);
post tryCoordCapTxTask();
! dbg_serial("IndirectTxP", "transmitDone()\n");
}
! command ieee154_txframe_t* GetIndirectTxFrame.get() { return m_pendingTxFrame;}
! command error_t PendingAddrSpecUpdated.enable() {return FAIL;}
! command error_t PendingAddrSpecUpdated.disable() {return FAIL;}
! default event void PendingAddrSpecUpdated.notify( bool val ) {return;}
! default event void FrameTx.transmitDone[uint8_t client](ieee154_txframe_t *txFrame, ieee154_status_t status) {}
}
Index: PibP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/mac/tkn154/PibP.nc,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** PibP.nc 23 Oct 2008 16:09:28 -0000 1.4
--- PibP.nc 4 Mar 2009 18:31:24 -0000 1.5
***************
*** 33,38 ****
*/
! /* This component maintains the PIB (PAN Information Base) attributes and
! * provides interfaces for accessing fields in a MAC frame. */
#include "TKN154.h"
--- 33,40 ----
*/
! /**
[...1007 lines suppressed...]
***************
*** 1050,1060 ****
}
! async command bool IsBeaconEnabledPAN.getNow()
! {
! return (m_panType == BEACON_ENABLED_PAN);
! }
!
! default event void PIBUpdate.notify[uint8_t PIBAttributeID](const void* PIBAttributeValue){}
! command error_t PIBUpdate.enable[uint8_t PIBAttributeID](){return FAIL;}
! command error_t PIBUpdate.disable[uint8_t PIBAttributeID](){return FAIL;}
}
--- 1050,1055 ----
}
! default event void PIBUpdate.notify[uint8_t PIBAttributeID](const void* PIBAttributeValue) {}
! command error_t PIBUpdate.enable[uint8_t PIBAttributeID]() {return FAIL;}
! command error_t PIBUpdate.disable[uint8_t PIBAttributeID]() {return FAIL;}
}
Index: PollP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/mac/tkn154/PollP.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** PollP.nc 25 Nov 2008 09:35:09 -0000 1.2
--- PollP.nc 4 Mar 2009 18:31:26 -0000 1.3
***************
*** 53,57 ****
interface Pool<ieee154_txframe_t> as TxFramePool;
interface Pool<ieee154_txcontrol_t> as TxControlPool;
- interface Ieee802154Debug as Debug;
interface MLME_GET;
interface Get<uint64_t> as LocalExtendedAddress;
--- 53,56 ----
***************
*** 79,101 ****
uint16_t coordPANID,
ieee154_address_t coordAddress,
! ieee154_security_t *security
! )
{
ieee154_txframe_t *txFrame;
ieee154_txcontrol_t *txControl;
uint8_t srcAddrMode = 2;
! ieee154_status_t txStatus = IEEE154_SUCCESS;
uint8_t coordAddressLE[8]; // little endian is what we want
if (security && security->SecurityLevel)
! txStatus = IEEE154_UNSUPPORTED_SECURITY;
else if (coordAddrMode < 2 || coordAddrMode > 3 || coordPANID == 0xFFFF)
! txStatus = IEEE154_INVALID_PARAMETER;
else if (!(txFrame = call TxFramePool.get()))
// none of the predefined return value really fits
! txStatus = IEEE154_TRANSACTION_OVERFLOW;
! else if (!(txControl = call TxControlPool.get())){
call TxFramePool.put(txFrame);
! txStatus = IEEE154_TRANSACTION_OVERFLOW;
} else {
txFrame->header = &txControl->header;
--- 78,99 ----
uint16_t coordPANID,
ieee154_address_t coordAddress,
! ieee154_security_t *security)
{
ieee154_txframe_t *txFrame;
ieee154_txcontrol_t *txControl;
uint8_t srcAddrMode = 2;
! ieee154_status_t status = IEEE154_SUCCESS;
uint8_t coordAddressLE[8]; // little endian is what we want
if (security && security->SecurityLevel)
! status = IEEE154_UNSUPPORTED_SECURITY;
else if (coordAddrMode < 2 || coordAddrMode > 3 || coordPANID == 0xFFFF)
! status = IEEE154_INVALID_PARAMETER;
else if (!(txFrame = call TxFramePool.get()))
// none of the predefined return value really fits
! status = IEEE154_TRANSACTION_OVERFLOW;
! else if (!(txControl = call TxControlPool.get())) {
call TxFramePool.put(txFrame);
! status = IEEE154_TRANSACTION_OVERFLOW;
} else {
txFrame->header = &txControl->header;
***************
*** 109,120 ****
srcAddrMode = 3;
buildDataRequestFrame(coordAddrMode, coordPANID, coordAddressLE, srcAddrMode, txFrame);
! if ((txStatus = call PollTx.transmit(txFrame)) != IEEE154_SUCCESS){
call TxFramePool.put(txFrame);
call TxControlPool.put(txControl);
! call Debug.log(DEBUG_LEVEL_IMPORTANT, PollP_ALLOC_FAIL1, 0, 0, 0);
} else
m_numPending++;
}
! return txStatus;
}
--- 107,120 ----
srcAddrMode = 3;
buildDataRequestFrame(coordAddrMode, coordPANID, coordAddressLE, srcAddrMode, txFrame);
! if ((status = call PollTx.transmit(txFrame)) != IEEE154_SUCCESS) {
call TxFramePool.put(txFrame);
call TxControlPool.put(txControl);
! status = IEEE154_TRANSACTION_OVERFLOW;
} else
m_numPending++;
}
!
! dbg_serial("PollP", "MLME_POLL.request -> result: %lu\n", (uint32_t) status);
! return status;
}
***************
*** 125,134 ****
ieee154_txcontrol_t *txControl;
ieee154_status_t status = IEEE154_TRANSACTION_OVERFLOW;
! call Debug.log(DEBUG_LEVEL_INFO, PollP_INTERNAL_POLL, CoordAddrMode, client, m_numPending);
! if (client == SYNC_POLL_CLIENT && m_numPending != 0){
// no point in auto-requesting if user request is pending
signal DataRequest.pollDone[client]();
return IEEE154_SUCCESS;
! } else if ((txFrame = call TxFramePool.get())){
if (!(txControl = call TxControlPool.get()))
call TxFramePool.put(txFrame);
--- 125,135 ----
ieee154_txcontrol_t *txControl;
ieee154_status_t status = IEEE154_TRANSACTION_OVERFLOW;
!
! dbg_serial("PollP", "InternalPoll\n");
! if (client == SYNC_POLL_CLIENT && m_numPending != 0) {
// no point in auto-requesting if user request is pending
signal DataRequest.pollDone[client]();
return IEEE154_SUCCESS;
! } else if ((txFrame = call TxFramePool.get())) {
if (!(txControl = call TxControlPool.get()))
call TxFramePool.put(txFrame);
***************
*** 139,146 ****
buildDataRequestFrame(CoordAddrMode, CoordPANId,
CoordAddressLE, srcAddrMode, txFrame);
! if ((status = call PollTx.transmit(txFrame)) != IEEE154_SUCCESS){
call TxControlPool.put(txControl);
call TxFramePool.put(txFrame);
! call Debug.log(DEBUG_LEVEL_IMPORTANT, PollP_ALLOC_FAIL2, 0, 0, 0);
} else
m_numPending++;
--- 140,147 ----
buildDataRequestFrame(CoordAddrMode, CoordPANId,
CoordAddressLE, srcAddrMode, txFrame);
! if ((status = call PollTx.transmit(txFrame)) != IEEE154_SUCCESS) {
call TxControlPool.put(txControl);
call TxFramePool.put(txFrame);
! dbg_serial("PollP", "Overflow\n");
} else
m_numPending++;
***************
*** 188,196 ****
event message_t* DataExtracted.received(message_t* frame, ieee154_txframe_t *txFrame)
{
! if (!txFrame){
! call Debug.log(DEBUG_LEVEL_CRITICAL, PollP_INTERNAL_ERROR, 0, 0, 0);
return frame;
} else
! call Debug.log(DEBUG_LEVEL_INFO, PollP_SUCCESS, 0, 0, 0);
if (txFrame->handle == HANDLE_MLME_POLL_REQUEST)
signal MLME_POLL.confirm(IEEE154_SUCCESS);
--- 189,197 ----
event message_t* DataExtracted.received(message_t* frame, ieee154_txframe_t *txFrame)
{
! if (!txFrame) {
! dbg_serial("PollP", "Internal error\n");
return frame;
} else
! dbg_serial("PollP", "Extracted data successfully\n");
if (txFrame->handle == HANDLE_MLME_POLL_REQUEST)
signal MLME_POLL.confirm(IEEE154_SUCCESS);
***************
*** 199,203 ****
txFrame->handle = HANDLE_MLME_POLL_SUCCESS; // mark as processed
// TODO: check if pending bit is set (then initiate another POLL)
- call Debug.log(DEBUG_LEVEL_IMPORTANT, PollP_RX, txFrame->handle, 0, 0);
return signal DataRx.received(frame);
}
--- 200,203 ----
***************
*** 205,211 ****
event void PollTx.transmitDone(ieee154_txframe_t *txFrame, ieee154_status_t status)
{
! call Debug.log(DEBUG_LEVEL_IMPORTANT, PollP_TXDONE, status, txFrame->handle, 0);
m_numPending--;
! if (txFrame->handle != HANDLE_MLME_POLL_SUCCESS){
// didn't receive a DATA frame from the coordinator
if (status == IEEE154_SUCCESS) // TODO: can this happen if a frame other than DATA was extracted?
--- 205,211 ----
event void PollTx.transmitDone(ieee154_txframe_t *txFrame, ieee154_status_t status)
{
! dbg_serial("PollP", "transmitDone()\n");
m_numPending--;
! if (txFrame->handle != HANDLE_MLME_POLL_SUCCESS) {
// didn't receive a DATA frame from the coordinator
if (status == IEEE154_SUCCESS) // TODO: can this happen if a frame other than DATA was extracted?
***************
*** 219,223 ****
call TxFramePool.put(txFrame);
}
! default event void MLME_POLL.confirm(ieee154_status_t status){}
! default event void DataRequest.pollDone[uint8_t client](){}
}
--- 219,223 ----
call TxFramePool.put(txFrame);
}
! default event void MLME_POLL.confirm(ieee154_status_t status) {}
! default event void DataRequest.pollDone[uint8_t client]() {}
}
Index: PromiscuousModeP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/mac/tkn154/PromiscuousModeP.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** PromiscuousModeP.nc 25 Nov 2008 09:35:09 -0000 1.2
--- PromiscuousModeP.nc 4 Mar 2009 18:31:26 -0000 1.3
***************
*** 48,125 ****
interface RadioOff;
interface Set<bool> as RadioPromiscuousMode;
- interface Ieee802154Debug as Debug;
}
}
implementation
{
! enum promiscuous_state {
! S_IDLE,
S_STARTING,
S_STARTED,
! S_STOPPING,
! } m_promiscuousState;
!
! task void prepareDoneTask();
! task void radioOffDoneTask();
command error_t Init.init()
{
! m_promiscuousState = S_IDLE;
return SUCCESS;
}
! /* ----------------------- Promiscuous Mode ----------------------- */
command bool PromiscuousModeGet.get()
{
! return (m_promiscuousState == S_STARTED);
}
command error_t PromiscuousMode.start()
{
! if (m_promiscuousState != S_IDLE)
! return FAIL;
! m_promiscuousState = S_STARTING;
! call Token.request();
! call Debug.log(DEBUG_LEVEL_INFO, EnableRxP_PROMISCUOUS_REQUEST, m_promiscuousState, 0, 0);
! call Debug.flush();
! return SUCCESS;
}
event void Token.granted()
{
- if (m_promiscuousState != S_STARTING){
- call Token.release();
- return;
- }
call RadioPromiscuousMode.set(TRUE);
! if (call PromiscuousRx.prepare() != IEEE154_SUCCESS){
! m_promiscuousState = S_IDLE;
! call Token.release();
! call Debug.log(DEBUG_LEVEL_IMPORTANT, EnableRxP_RADIORX_ERROR, 0, 0, 0);
! signal PromiscuousMode.startDone(FAIL);
! }
}
! async event void PromiscuousRx.prepareDone()
{
! post prepareDoneTask();
}
! task void prepareDoneTask()
{
! if (m_promiscuousState != S_STARTING){
! call Token.release();
! return;
! }
! m_promiscuousState = S_STARTED;
! call PromiscuousRx.receive(NULL, 0);
! signal PromiscuousMode.startDone(SUCCESS);
! call Debug.log(DEBUG_LEVEL_INFO, EnableRxP_PROMISCUOUS_ON, m_promiscuousState, 0, 0);
}
! event message_t* PromiscuousRx.received(message_t *frame, ieee154_reftime_t *timestamp)
{
! if (m_promiscuousState == S_STARTED){
((ieee154_header_t*) frame->header)->length |= FRAMECTL_PROMISCUOUS;
return signal FrameRx.received(frame);
--- 48,111 ----
interface RadioOff;
interface Set<bool> as RadioPromiscuousMode;
}
}
implementation
{
! norace enum promiscuous_state {
! S_STOPPING,
! S_STOPPED,
S_STARTING,
S_STARTED,
! } m_state;
command error_t Init.init()
{
! m_state = S_STOPPED;
return SUCCESS;
}
! /* ----------------------- Promiscuous Mode ----------------------- */
command bool PromiscuousModeGet.get()
{
! return (m_state == S_STARTED);
}
command error_t PromiscuousMode.start()
{
! error_t result = FAIL;
! if (m_state == S_STOPPED) {
! m_state = S_STARTING;
! call Token.request();
! result = SUCCESS;
! }
! dbg_serial("PromiscuousModeP", "PromiscuousMode.start -> result: %lu\n", (uint32_t) result);
! return result;
}
event void Token.granted()
{
call RadioPromiscuousMode.set(TRUE);
! if (call RadioOff.isOff())
! signal RadioOff.offDone();
! else
! call RadioOff.off();
}
! task void signalStartDoneTask()
{
! m_state = S_STARTED;
! dbg_serial("PromiscuousModeP", "Promiscuous mode enabled.\n");
! signal PromiscuousMode.startDone(SUCCESS);
}
! async event void PromiscuousRx.enableRxDone()
{
! post signalStartDoneTask();
}
! event message_t* PromiscuousRx.received(message_t *frame, const ieee154_timestamp_t *timestamp)
{
! if (m_state == S_STARTED) {
((ieee154_header_t*) frame->header)->length |= FRAMECTL_PROMISCUOUS;
return signal FrameRx.received(frame);
***************
*** 130,159 ****
command error_t PromiscuousMode.stop()
{
! if (m_promiscuousState != S_STARTED)
! return FAIL;
! m_promiscuousState = S_STOPPING;
! call RadioOff.off();
! return SUCCESS;
! }
!
! async event void RadioOff.offDone()
! {
! post radioOffDoneTask();
}
! task void radioOffDoneTask()
{
- if (m_promiscuousState != S_STOPPING){
- call Token.release();
- return;
- }
- m_promiscuousState = S_IDLE;
call RadioPromiscuousMode.set(FALSE);
call Token.release();
signal PromiscuousMode.stopDone(SUCCESS);
- call Debug.log(DEBUG_LEVEL_INFO, EnableRxP_PROMISCUOUS_OFF, m_promiscuousState, 0, 0);
}
! default event void PromiscuousMode.startDone(error_t error){}
! default event void PromiscuousMode.stopDone(error_t error){}
}
--- 116,147 ----
command error_t PromiscuousMode.stop()
{
! error_t result = FAIL;
! if (m_state == S_STARTED) {
! m_state = S_STOPPING;
! call RadioOff.off();
! result = SUCCESS;
! }
! dbg_serial("PromiscuousModeP", "PromiscuousMode.stop -> result: %lu\n", (uint32_t) result);
! return result;
}
! task void continueStopTask()
{
call RadioPromiscuousMode.set(FALSE);
+ m_state = S_STOPPED;
call Token.release();
+ dbg_serial("PromiscuousModeP", "Promiscuous mode disabled.\n");
signal PromiscuousMode.stopDone(SUCCESS);
}
! async event void RadioOff.offDone()
! {
! if (m_state == S_STARTING) {
! call PromiscuousRx.enableRx(0, 0);
! } else
! post continueStopTask();
! }
!
! default event void PromiscuousMode.startDone(error_t error) {}
! default event void PromiscuousMode.stopDone(error_t error) {}
}
Index: RadioClientC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/mac/tkn154/RadioClientC.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** RadioClientC.nc 2 Aug 2008 16:56:21 -0000 1.2
--- RadioClientC.nc 4 Mar 2009 18:31:26 -0000 1.3
***************
*** 33,36 ****
--- 33,37 ----
* ========================================================================
*/
+
#include "TKN154_MAC.h"
generic configuration RadioClientC()
***************
*** 38,44 ****
provides
{
interface RadioRx;
interface RadioTx;
! interface RadioOff;
interface Resource as Token;
interface ResourceRequested as TokenRequested;
--- 39,47 ----
provides
{
+ interface RadioOff;
interface RadioRx;
interface RadioTx;
! interface SlottedCsmaCa;
! interface UnslottedCsmaCa;
interface Resource as Token;
interface ResourceRequested as TokenRequested;
***************
*** 61,64 ****
--- 64,69 ----
RadioTx = RadioControlP.RadioTx[CLIENT];
RadioOff = RadioControlP.RadioOff[CLIENT];
+ SlottedCsmaCa = RadioControlP.SlottedCsmaCa[CLIENT];
+ UnslottedCsmaCa = RadioControlP.UnslottedCsmaCa[CLIENT];
Token = RadioControlP.Token[CLIENT];
IsResourceRequested = RadioControlP.IsResourceRequested;
Index: RadioControlImplP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/mac/tkn154/RadioControlImplP.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** RadioControlImplP.nc 25 Nov 2008 09:35:09 -0000 1.2
--- RadioControlImplP.nc 4 Mar 2009 18:31:28 -0000 1.3
***************
*** 33,38 ****
* ========================================================================
*/
#include "TKN154_MAC.h"
! #include "TKN154_DEBUG.h"
module RadioControlImplP
{
--- 33,39 ----
* ========================================================================
*/
+
#include "TKN154_MAC.h"
!
module RadioControlImplP
{
***************
*** 41,44 ****
--- 42,47 ----
interface RadioRx as MacRx[uint8_t client];
interface RadioTx as MacTx[uint8_t client];
+ interface SlottedCsmaCa as SlottedCsmaCa[uint8_t client];
+ interface UnslottedCsmaCa as UnslottedCsmaCa[uint8_t client];
interface RadioOff as MacRadioOff[uint8_t client];
} uses {
***************
*** 46,53 ****
interface RadioRx as PhyRx;
interface RadioTx as PhyTx;
interface RadioOff as PhyRadioOff;
interface Get<bool> as RadioPromiscuousMode;
interface Leds;
- interface Ieee802154Debug as Debug;
}
}
--- 49,57 ----
interface RadioRx as PhyRx;
interface RadioTx as PhyTx;
+ interface SlottedCsmaCa as PhySlottedCsmaCa;
+ interface UnslottedCsmaCa as PhyUnslottedCsmaCa;
interface RadioOff as PhyRadioOff;
interface Get<bool> as RadioPromiscuousMode;
interface Leds;
}
}
***************
*** 55,96 ****
{
! /* ----------------------- RadioRx ----------------------- */
!
! async command error_t MacRx.prepare[uint8_t client]()
! {
! if (client == call ArbiterInfo.userId())
! return call PhyRx.prepare();
! else {
! call Leds.led0On();
! return FAIL;
! }
! }
!
! async event void PhyRx.prepareDone()
! {
! signal MacRx.prepareDone[call ArbiterInfo.userId()]();
! }
!
! async command bool MacRx.isPrepared[uint8_t client]()
! {
! if (client == call ArbiterInfo.userId())
! return call PhyRx.isPrepared();
! else {
! call Leds.led0On();
! return FAIL;
! }
! }
! async command error_t MacRx.receive[uint8_t client](ieee154_reftime_t *t0, uint32_t dt)
{
if (client == call ArbiterInfo.userId())
! return call PhyRx.receive(t0, dt);
else {
! call Leds.led0On();
return IEEE154_TRANSACTION_OVERFLOW;
}
}
! event message_t* PhyRx.received(message_t *msg, ieee154_reftime_t *timestamp)
{
uint8_t *mhr = MHR(msg);
--- 59,80 ----
{
! /* ----------------------- RadioRx ----------------------- */
! async command error_t MacRx.enableRx[uint8_t client](uint32_t t0, uint32_t dt)
{
if (client == call ArbiterInfo.userId())
! return call PhyRx.enableRx(t0, dt);
else {
! ASSERT(0);
return IEEE154_TRANSACTION_OVERFLOW;
}
}
! async event void PhyRx.enableRxDone()
! {
! signal MacRx.enableRxDone[call ArbiterInfo.userId()]();
! }
!
! event message_t* PhyRx.received(message_t *msg, const ieee154_timestamp_t *timestamp)
{
uint8_t *mhr = MHR(msg);
***************
*** 111,197 ****
return call PhyRx.isReceiving();
else {
! call Leds.led0On();
return FAIL;
}
}
! /* ----------------------- RadioTx ----------------------- */
! async command error_t MacTx.load[uint8_t client](ieee154_txframe_t *frame)
{
if (client == call ArbiterInfo.userId())
! return call PhyTx.load(frame);
else {
! call Leds.led0On();
return IEEE154_TRANSACTION_OVERFLOW;
}
}
!
! async event void PhyTx.loadDone()
{
! signal MacTx.loadDone[call ArbiterInfo.userId()]();
}
! async command ieee154_txframe_t* MacTx.getLoadedFrame[uint8_t client]()
{
! if (client == call ArbiterInfo.userId())
! return call PhyTx.getLoadedFrame();
! else {
! call Leds.led0On();
! return NULL;
! }
}
! async command error_t MacTx.transmit[uint8_t client](ieee154_reftime_t *t0, uint32_t dt)
{
if (client == call ArbiterInfo.userId())
! return call PhyTx.transmit(t0, dt);
else {
! call Leds.led0On();
return IEEE154_TRANSACTION_OVERFLOW;
}
}
-
- async event void PhyTx.transmitDone(ieee154_txframe_t *frame, ieee154_reftime_t *txTime)
- {
- signal MacTx.transmitDone[call ArbiterInfo.userId()](frame, txTime);
- }
! async command error_t MacTx.transmitUnslottedCsmaCa[uint8_t client](ieee154_csma_t *csmaParams)
{
! if (client == call ArbiterInfo.userId())
! return call PhyTx.transmitUnslottedCsmaCa(csmaParams);
! else {
! call Leds.led0On();
! return IEEE154_TRANSACTION_OVERFLOW;
! }
}
! async event void PhyTx.transmitUnslottedCsmaCaDone(ieee154_txframe_t *frame,
! bool ackPendingFlag, ieee154_csma_t *csmaParams, error_t result)
{
! signal MacTx.transmitUnslottedCsmaCaDone[call ArbiterInfo.userId()](
! frame, ackPendingFlag, csmaParams, result);
}
! async command error_t MacTx.transmitSlottedCsmaCa[uint8_t client](ieee154_reftime_t *slot0Time, uint32_t dtMax,
! bool resume, uint16_t remainingBackoff, ieee154_csma_t *csmaParams)
{
if (client == call ArbiterInfo.userId())
! return call PhyTx.transmitSlottedCsmaCa(slot0Time, dtMax, resume, remainingBackoff, csmaParams);
else {
! call Leds.led0On();
return IEEE154_TRANSACTION_OVERFLOW;
}
}
! async event void PhyTx.transmitSlottedCsmaCaDone(ieee154_txframe_t *frame, ieee154_reftime_t *txTime,
! bool ackPendingFlag, uint16_t remainingBackoff, ieee154_csma_t *csmaParams, error_t result)
{
! signal MacTx.transmitSlottedCsmaCaDone[call ArbiterInfo.userId()](
! frame, txTime, ackPendingFlag, remainingBackoff, csmaParams, result);
}
! /* ----------------------- RadioOff ----------------------- */
async command error_t MacRadioOff.off[uint8_t client]()
--- 95,188 ----
return call PhyRx.isReceiving();
else {
! ASSERT(0);
return FAIL;
}
}
! default async event void MacRx.enableRxDone[uint8_t client]() { ASSERT(0); }
! default event message_t* MacRx.received[uint8_t client](message_t *frame, const ieee154_timestamp_t *timestamp)
! {
! ASSERT(0);
! return frame;
! }
!
! /* ----------------------- RadioTx ----------------------- */
!
! async command error_t MacTx.transmit[uint8_t client](ieee154_txframe_t *frame,
! const ieee154_timestamp_t *t0, uint32_t dt)
{
if (client == call ArbiterInfo.userId())
! return call PhyTx.transmit(frame, t0, dt);
else {
! ASSERT(0);
return IEEE154_TRANSACTION_OVERFLOW;
}
}
!
! async event void PhyTx.transmitDone(ieee154_txframe_t *frame,
! const ieee154_timestamp_t *timestamp, error_t result)
{
! signal MacTx.transmitDone[call ArbiterInfo.userId()](frame, timestamp, result);
}
! default async event void MacTx.transmitDone[uint8_t client](ieee154_txframe_t *frame,
! const ieee154_timestamp_t *timestamp, error_t result)
{
! ASSERT(0);
}
! /* ----------------------- Unslotted CSMA ----------------------- */
!
! async command error_t UnslottedCsmaCa.transmit[uint8_t client](ieee154_txframe_t *frame, ieee154_csma_t *csma)
{
if (client == call ArbiterInfo.userId())
! return call PhyUnslottedCsmaCa.transmit(frame, csma);
else {
! ASSERT(0);
return IEEE154_TRANSACTION_OVERFLOW;
}
}
! async event void PhyUnslottedCsmaCa.transmitDone(ieee154_txframe_t *frame, ieee154_csma_t *csma, bool ackPendingFlag, error_t result)
{
! signal UnslottedCsmaCa.transmitDone[call ArbiterInfo.userId()](
! frame, csma, ackPendingFlag, result);
}
! default async event void UnslottedCsmaCa.transmitDone[uint8_t client](
! ieee154_txframe_t *frame, ieee154_csma_t *csma, bool ackPendingFlag, error_t result)
{
! ASSERT(0);
}
! /* ----------------------- Slotted CSMA ----------------------- */
!
! async command error_t SlottedCsmaCa.transmit[uint8_t client](ieee154_txframe_t *frame, ieee154_csma_t *csma,
! const ieee154_timestamp_t *slot0Time, uint32_t dtMax, bool resume, uint16_t remainingBackoff)
{
if (client == call ArbiterInfo.userId())
! return call PhySlottedCsmaCa.transmit(frame, csma, slot0Time, dtMax, resume, remainingBackoff);
else {
! ASSERT(0);
return IEEE154_TRANSACTION_OVERFLOW;
}
}
! async event void PhySlottedCsmaCa.transmitDone(ieee154_txframe_t *frame, ieee154_csma_t *csma,
! bool ackPendingFlag, uint16_t remainingBackoff, error_t result)
{
! signal SlottedCsmaCa.transmitDone[call ArbiterInfo.userId()](
! frame, csma, ackPendingFlag, remainingBackoff, result);
}
! default async event void SlottedCsmaCa.transmitDone[uint8_t client](
! ieee154_txframe_t *frame, ieee154_csma_t *csma,
! bool ackPendingFlag, uint16_t remainingBackoff, error_t result)
! {
! ASSERT(0);
! }
!
! /* ----------------------- RadioOff ----------------------- */
async command error_t MacRadioOff.off[uint8_t client]()
***************
*** 200,204 ****
return call PhyRadioOff.off();
else {
! call Leds.led0On();
return EBUSY;
}
--- 191,195 ----
return call PhyRadioOff.off();
else {
! ASSERT(0);
return EBUSY;
}
***************
*** 219,255 ****
}
- /* ----------------------- Defaults ----------------------- */
-
- default async event void MacTx.loadDone[uint8_t client]()
- {
- call Debug.log(DEBUG_LEVEL_CRITICAL, 0, 0, 0, 0);
- }
- default async event void MacTx.transmitDone[uint8_t client](ieee154_txframe_t *frame, ieee154_reftime_t *txTime)
- {
- call Debug.log(DEBUG_LEVEL_CRITICAL, 1, 0, 0, 0);
- }
- default async event void MacRx.prepareDone[uint8_t client]()
- {
- call Debug.log(DEBUG_LEVEL_CRITICAL, 2, 0, 0, 0);
- }
- default event message_t* MacRx.received[uint8_t client](message_t *frame, ieee154_reftime_t *timestamp)
- {
- call Debug.log(DEBUG_LEVEL_IMPORTANT, 3, client, call ArbiterInfo.userId(), 0xff);
- return frame;
- }
default async event void MacRadioOff.offDone[uint8_t client]()
{
! call Debug.log(DEBUG_LEVEL_CRITICAL, 4, 0, 0, 0);
! }
! default async event void MacTx.transmitUnslottedCsmaCaDone[uint8_t client](ieee154_txframe_t *frame,
! bool ackPendingFlag, ieee154_csma_t *csmaParams, error_t result)
! {
! call Debug.log(DEBUG_LEVEL_CRITICAL, 5, 0, 0, 0);
! }
! default async event void MacTx.transmitSlottedCsmaCaDone[uint8_t client](ieee154_txframe_t *frame,
! ieee154_reftime_t *txTime, bool ackPendingFlag, uint16_t remainingBackoff,
! ieee154_csma_t *csmaParams, error_t result)
! {
! call Debug.log(DEBUG_LEVEL_CRITICAL, 6, 0, 0, 0);
}
}
--- 210,216 ----
}
default async event void MacRadioOff.offDone[uint8_t client]()
{
! ASSERT(0);
}
}
Index: RadioControlP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/mac/tkn154/RadioControlP.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** RadioControlP.nc 2 Aug 2008 16:56:21 -0000 1.1
--- RadioControlP.nc 4 Mar 2009 18:31:28 -0000 1.2
***************
*** 40,43 ****
--- 40,45 ----
interface RadioRx as RadioRx[uint8_t client];
interface RadioTx as RadioTx[uint8_t client];
+ interface SlottedCsmaCa as SlottedCsmaCa[uint8_t client];
+ interface UnslottedCsmaCa as UnslottedCsmaCa[uint8_t client];
interface RadioOff as RadioOff[uint8_t client];
interface Resource as Token[uint8_t client];
***************
*** 49,56 ****
interface RadioRx as PhyRx;
interface RadioTx as PhyTx;
interface RadioOff as PhyRadioOff;
interface Get<bool> as RadioPromiscuousMode;
interface Leds;
- interface Ieee802154Debug as Debug;
}
}
--- 51,59 ----
interface RadioRx as PhyRx;
interface RadioTx as PhyTx;
+ interface SlottedCsmaCa as PhySlottedCsmaCa;
+ interface UnslottedCsmaCa as PhyUnslottedCsmaCa;
interface RadioOff as PhyRadioOff;
interface Get<bool> as RadioPromiscuousMode;
interface Leds;
}
}
***************
*** 60,70 ****
RadioRx = RadioControlImplP.MacRx;
RadioTx = RadioControlImplP.MacTx;
RadioOff = RadioControlImplP.MacRadioOff;
PhyRx = RadioControlImplP.PhyRx;
PhyTx = RadioControlImplP.PhyTx;
PhyRadioOff = RadioControlImplP.PhyRadioOff;
RadioPromiscuousMode = RadioControlImplP;
Leds = RadioControlImplP;
- Debug = RadioControlImplP;
LedsRadioClient = Leds;
--- 63,76 ----
RadioRx = RadioControlImplP.MacRx;
RadioTx = RadioControlImplP.MacTx;
+ SlottedCsmaCa = RadioControlImplP.SlottedCsmaCa;
+ UnslottedCsmaCa = RadioControlImplP.UnslottedCsmaCa;
RadioOff = RadioControlImplP.MacRadioOff;
PhyRx = RadioControlImplP.PhyRx;
PhyTx = RadioControlImplP.PhyTx;
+ PhySlottedCsmaCa = RadioControlImplP.PhySlottedCsmaCa;
+ PhyUnslottedCsmaCa = RadioControlImplP.PhyUnslottedCsmaCa;
PhyRadioOff = RadioControlImplP.PhyRadioOff;
RadioPromiscuousMode = RadioControlImplP;
Leds = RadioControlImplP;
LedsRadioClient = Leds;
Index: README.txt
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/mac/tkn154/README.txt,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** README.txt 2 Aug 2008 16:56:21 -0000 1.4
--- README.txt 4 Mar 2009 18:31:28 -0000 1.5
***************
*** 1,17 ****
This directory contains "TKN15.4", a platform-independent IEEE 802.15.4-2006
! MAC implementation. The code is in alpha state, under active development, but
! most of the functionality described in the standard is implemented (and
! cursorily tested). The MAC itself is platform-independent, but it requires
! (1) a suitable radio driver, (2) Alarms/Timers with symbol precision and (3)
! some "platform glue" code (defining guard times, etc.). Currently the only
! supported platform is TelosB (however: without additional hardware support on
! TelosB the timing in beacon-enabled mode is not standard compliant).
! Status 6/16/08
! --------------
Missing functionality:
! - security (not planned)
! - GTS (not planned)
- PAN ID conflict resolution
- multiple indirect transmissions to the same destination
--- 1,20 ----
This directory contains "TKN15.4", a platform-independent IEEE 802.15.4-2006
! MAC implementation. The code is under active development, but most of the
! functionality described in the standard is implemented (and cursorily tested).
! The MAC itself is platform-independent, but it requires (1) a suitable radio
! driver, (2) Alarms/Timers with symbol precision and (3) some "platform glue"
! code (defining guard times, etc.). Currently the only supported platform is
! TelosB (but without additional hardware support on TelosB the timing in
! beacon-enabled mode is not standard compliant).
! This code is the basis for the implementation of the TinyOS 15.4 WG:
! http://tinyos.stanford.edu:8000/15.4_WG
!
! Status 3/4/09
! -------------
Missing functionality:
! - security
! - GTS
- PAN ID conflict resolution
- multiple indirect transmissions to the same destination
Index: RxEnableP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/mac/tkn154/RxEnableP.nc,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** RxEnableP.nc 23 Oct 2008 16:09:28 -0000 1.4
--- RxEnableP.nc 4 Mar 2009 18:31:29 -0000 1.5
***************
*** 40,44 ****
provides
{
! interface Init;
interface MLME_RX_ENABLE;
interface GetNow<bool> as IsRxEnableActive;
--- 40,44 ----
provides
{
! interface Init as Reset;
interface MLME_RX_ENABLE;
interface GetNow<bool> as IsRxEnableActive;
***************
*** 47,60 ****
uses
{
- interface Ieee802154Debug as Debug;
interface Timer<TSymbolIEEE802154> as RxEnableTimer;
- interface GetNow<bool> as IsBeaconEnabledPAN;
interface Get<ieee154_macPanCoordinator_t> as IsMacPanCoordinator;
interface GetNow<bool> as IsTrackingBeacons;
- interface GetNow<uint32_t> as IncomingSfStart;
- interface GetNow<uint32_t> as IncomingBeaconInterval;
interface GetNow<bool> as IsSendingBeacons;
- interface GetNow<uint32_t> as OutgoingSfStart;
- interface GetNow<uint32_t> as OutgoingBeaconInterval;
interface Notify<bool> as WasRxEnabled;
interface TimeCalc;
--- 47,56 ----
uses
{
interface Timer<TSymbolIEEE802154> as RxEnableTimer;
interface Get<ieee154_macPanCoordinator_t> as IsMacPanCoordinator;
+ interface SuperframeStructure as IncomingSuperframeStructure;
+ interface SuperframeStructure as OutgoingSuperframeStructure;
interface GetNow<bool> as IsTrackingBeacons;
interface GetNow<bool> as IsSendingBeacons;
interface Notify<bool> as WasRxEnabled;
interface TimeCalc;
***************
*** 68,77 ****
uint32_t m_rxOnAnchor;
norace bool m_isRxEnabled;
! bool m_isRxEnableConfirmPending;
! command error_t Init.init()
{
! if (m_isRxEnableConfirmPending){
! m_isRxEnableConfirmPending = FALSE;
signal MLME_RX_ENABLE.confirm(IEEE154_SUCCESS);
}
--- 64,73 ----
uint32_t m_rxOnAnchor;
norace bool m_isRxEnabled;
! bool m_confirmPending;
! command error_t Reset.init()
{
! if (m_confirmPending) {
! m_confirmPending = FALSE;
signal MLME_RX_ENABLE.confirm(IEEE154_SUCCESS);
}
***************
*** 81,116 ****
}
! /* ----------------------- MLME-RX-ENABLE ----------------------- */
command ieee154_status_t MLME_RX_ENABLE.request (
bool DeferPermit,
uint32_t RxOnTime,
! uint32_t RxOnDuration
! )
{
uint32_t lastBeaconTime=0;
uint32_t beaconInterval=0;
! if (m_isRxEnableConfirmPending)
! return IEEE154_TRANSACTION_OVERFLOW;
! if (RxOnTime > 0xFFFFFF || RxOnDuration > 0xFFFFFF)
! return IEEE154_INVALID_PARAMETER;
! if (call IsBeaconEnabledPAN.getNow()){
! if (call IsSendingBeacons.getNow() && call IsMacPanCoordinator.get()){
// for OUTGOING SUPERFRAME
! lastBeaconTime = call OutgoingSfStart.getNow();
! beaconInterval = call OutgoingBeaconInterval.getNow();
! } else if (call IsTrackingBeacons.getNow()){
// for INCOMING SUPERFRAME
! lastBeaconTime = call IncomingSfStart.getNow();
! beaconInterval = call IncomingBeaconInterval.getNow();
}
if (beaconInterval == 0)
! return IEEE154_PAST_TIME; // we're not even sending/receiving beacons
! if (RxOnTime+RxOnDuration >= beaconInterval)
! return IEEE154_ON_TIME_TOO_LONG;
! if (call TimeCalc.hasExpired(lastBeaconTime, RxOnTime - IEEE154_aTurnaroundTime)){
if (!DeferPermit)
! return IEEE154_PAST_TIME;
else {
// defer to next beacon
--- 77,114 ----
}
! /* ----------------------- MLME-RX-ENABLE ----------------------- */
command ieee154_status_t MLME_RX_ENABLE.request (
bool DeferPermit,
uint32_t RxOnTime,
! uint32_t RxOnDuration)
{
+ ieee154_status_t status = IEEE154_SUCCESS;
uint32_t lastBeaconTime=0;
uint32_t beaconInterval=0;
! if (m_confirmPending)
! status = IEEE154_TRANSACTION_OVERFLOW;
! else if (IEEE154_BEACON_ENABLED_PAN && RxOnTime > 0xFFFFFF)
! status = IEEE154_INVALID_PARAMETER;
! else if (RxOnDuration > 0xFFFFFF)
! status = IEEE154_INVALID_PARAMETER;
! else if (IEEE154_BEACON_ENABLED_PAN) {
! if (call IsSendingBeacons.getNow() && call IsMacPanCoordinator.get()) {
// for OUTGOING SUPERFRAME
! lastBeaconTime = call OutgoingSuperframeStructure.sfStartTime();
! beaconInterval = call OutgoingSuperframeStructure.sfSlotDuration() * 16;
! } else if (call IsTrackingBeacons.getNow()) {
// for INCOMING SUPERFRAME
! lastBeaconTime = call IncomingSuperframeStructure.sfStartTime();
! beaconInterval = call IncomingSuperframeStructure.sfSlotDuration() * 16;
}
if (beaconInterval == 0)
! status = IEEE154_PAST_TIME; // we're not even sending/receiving beacons
! else if (RxOnTime+RxOnDuration >= beaconInterval)
! status = IEEE154_ON_TIME_TOO_LONG;
! else if (call TimeCalc.hasExpired(lastBeaconTime, RxOnTime - IEEE154_aTurnaroundTime)) {
if (!DeferPermit)
! status = IEEE154_PAST_TIME;
else {
// defer to next beacon
***************
*** 118,148 ****
}
}
! m_rxOnAnchor = lastBeaconTime;
! m_rxOnOffset = RxOnTime;
} else {
m_rxOnAnchor = call RxEnableTimer.getNow();
m_rxOnOffset = 0;
}
! m_rxOnDuration = RxOnDuration;
! m_isRxEnabled = FALSE;
! m_isRxEnableConfirmPending = TRUE;
! call RxEnableTimer.startOneShotAt(m_rxOnAnchor, m_rxOnOffset);
! signal RxEnableStateChange.notify(TRUE);
! return IEEE154_SUCCESS;
}
event void RxEnableTimer.fired()
{
! if (!m_isRxEnabled){
m_isRxEnabled = TRUE;
call RxEnableTimer.startOneShotAt(m_rxOnAnchor, m_rxOnOffset + m_rxOnDuration);
} else {
m_isRxEnabled = FALSE;
! if (m_isRxEnableConfirmPending){
! // this means we tried to enable rx, but never
! // succeeded, because there were "other
! // responsibilities" - but is SUCCESS really
// an appropriate error code in this case?
! m_isRxEnableConfirmPending = FALSE;
signal MLME_RX_ENABLE.confirm(IEEE154_SUCCESS);
}
--- 116,153 ----
}
}
! if (status == IEEE154_SUCCESS) {
! m_rxOnAnchor = lastBeaconTime;
! m_rxOnOffset = RxOnTime;
! }
} else {
+ // this is a nonbeacon-enabled PAN
m_rxOnAnchor = call RxEnableTimer.getNow();
m_rxOnOffset = 0;
}
!
! if (status == IEEE154_SUCCESS) {
! m_rxOnDuration = RxOnDuration;
! m_isRxEnabled = FALSE;
! m_confirmPending = TRUE;
! call RxEnableTimer.startOneShotAt(m_rxOnAnchor, m_rxOnOffset);
! signal RxEnableStateChange.notify(TRUE);
! }
! dbg_serial("RxEnableP", "MLME_RX_ENABLE.request -> result: %lu\n", (uint32_t) status);
! return status;
}
event void RxEnableTimer.fired()
{
! if (!m_isRxEnabled) {
m_isRxEnabled = TRUE;
call RxEnableTimer.startOneShotAt(m_rxOnAnchor, m_rxOnOffset + m_rxOnDuration);
} else {
m_isRxEnabled = FALSE;
! if (m_confirmPending) {
! // this means we tried to enable rx, but never succeeded, because
! // there were "other responsibilities" - but is SUCCESS really
// an appropriate error code in this case?
! m_confirmPending = FALSE;
! dbg_serial("RxEnableP", "never actually managed to switch to Rx mode\n");
signal MLME_RX_ENABLE.confirm(IEEE154_SUCCESS);
}
***************
*** 156,169 ****
}
! event void WasRxEnabled.notify( bool val )
{
! if (m_isRxEnabled && m_isRxEnableConfirmPending){
! m_isRxEnableConfirmPending = FALSE;
signal MLME_RX_ENABLE.confirm(IEEE154_SUCCESS);
}
}
! command error_t RxEnableStateChange.enable(){return FAIL;}
! command error_t RxEnableStateChange.disable(){return FAIL;}
! default event void MLME_RX_ENABLE.confirm(ieee154_status_t status){}
}
--- 161,182 ----
}
! event void WasRxEnabled.notify(bool val)
{
! if (m_isRxEnabled && m_confirmPending) {
! m_confirmPending = FALSE;
! dbg_serial("RxEnableP", "MLME_RX_ENABLE.confirm, radio is now in Rx mode\n");
signal MLME_RX_ENABLE.confirm(IEEE154_SUCCESS);
}
}
! command error_t RxEnableStateChange.enable() {return FAIL;}
! command error_t RxEnableStateChange.disable() {return FAIL;}
! default event void MLME_RX_ENABLE.confirm(ieee154_status_t status) {}
! default async command uint32_t IncomingSuperframeStructure.sfStartTime() {return 0;}
! default async command uint16_t IncomingSuperframeStructure.sfSlotDuration() {return 0;}
! default async command uint32_t OutgoingSuperframeStructure.sfStartTime() {return 0;}
! default async command uint16_t OutgoingSuperframeStructure.sfSlotDuration() {return 0;}
! default async command bool IsTrackingBeacons.getNow() { return FALSE;}
! default async command bool IsSendingBeacons.getNow() { return FALSE;}
! default command ieee154_macPanCoordinator_t IsMacPanCoordinator.get() { return FALSE;}
}
Index: ScanP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/mac/tkn154/ScanP.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** ScanP.nc 25 Nov 2008 09:35:09 -0000 1.2
--- ScanP.nc 4 Mar 2009 18:31:31 -0000 1.3
***************
*** 34,37 ****
--- 34,41 ----
*/
+ /**
+ * This module is responsible for channel scanning.
+ */
+
#include "TKN154_MAC.h"
module ScanP
***************
*** 83,86 ****
--- 87,91 ----
void nextIteration();
+ void continueScanRequest();
task void startTimerTask();
task void nextIterationTask();
***************
*** 90,96 ****
// triggered by MLME_RESET; remember: Init will not be called
// while this component owns the Token, so the worst case is
! // that a MLME_SCAN was accepted (returned IEEE154_SUCCESS)
! // but the Token.granted() has not been signalled
! if (m_busy){
m_currentChannelNum = 27;
nextIteration(); // signals confirm and resets state
--- 95,101 ----
// triggered by MLME_RESET; remember: Init will not be called
// while this component owns the Token, so the worst case is
! // that a MLME_SCAN was accepted (returned IEEE154_SUCCESS)
! // but the Token.granted() has not been signalled
! if (m_busy) {
m_currentChannelNum = 27;
nextIteration(); // signals confirm and resets state
***************
*** 99,109 ****
}
! /* ----------------------- MLME-SCAN ----------------------- */
! /* "The MLME-SCAN.request primitive is used to initiate a channel scan over a
! * given list of channels. A device can use a channel scan to measure the
! * energy on the channel, search for the coordinator with which it associated,
! * or search for all coordinators transmitting beacon frames within the POS of
! * the scanning device." (IEEE 802.15.4-2006 Sect. 7.1.11.1)
! **/
command ieee154_status_t MLME_SCAN.request (
--- 104,114 ----
}
! /* ----------------------- MLME-SCAN ----------------------- */
! /* "The MLME-SCAN.request primitive is used to initiate a channel scan over a
! * given list of channels. A device can use a channel scan to measure the
! * energy on the channel, search for the coordinator with which it associated,
! * or search for all coordinators transmitting beacon frames within the POS of
! * the scanning device." (IEEE 802.15.4-2006 Sect. 7.1.11.1)
! **/
command ieee154_status_t MLME_SCAN.request (
***************
*** 116,121 ****
uint8_t PANDescriptorListNumEntries,
ieee154_PANDescriptor_t* PANDescriptorList,
! ieee154_security_t *security
! )
{
ieee154_status_t status = IEEE154_SUCCESS;
--- 121,125 ----
uint8_t PANDescriptorListNumEntries,
ieee154_PANDescriptor_t* PANDescriptorList,
! ieee154_security_t *security)
{
ieee154_status_t status = IEEE154_SUCCESS;
***************
*** 123,137 ****
ieee154_txcontrol_t *txControl = NULL;
! if (m_busy){
status = IEEE154_SCAN_IN_PROGRESS;
! } else if (security && security->SecurityLevel){
status = IEEE154_UNSUPPORTED_SECURITY;
! } if ( (ScanType > 3) || (ScanType < 3 && ScanDuration > 14) ||
! (ChannelPage != IEEE154_SUPPORTED_CHANNELPAGE) ||
! !(supportedChannels & ScanChannels) ||
! (EnergyDetectListNumEntries && PANDescriptorListNumEntries) ||
! (EnergyDetectList != NULL && PANDescriptorList != NULL) ||
! (EnergyDetectListNumEntries && EnergyDetectList == NULL) ||
! (PANDescriptorListNumEntries && PANDescriptorList == NULL)) {
status = IEEE154_INVALID_PARAMETER;
} else if (ScanType != ENERGY_DETECTION_SCAN &&
--- 127,141 ----
ieee154_txcontrol_t *txControl = NULL;
! if (m_busy) {
status = IEEE154_SCAN_IN_PROGRESS;
! } else if (security && security->SecurityLevel) {
status = IEEE154_UNSUPPORTED_SECURITY;
! } if ((ScanType > 3) || (ScanType < 3 && ScanDuration > 14) ||
! (ChannelPage != IEEE154_SUPPORTED_CHANNELPAGE) ||
! !(supportedChannels & ScanChannels) ||
! (EnergyDetectListNumEntries && PANDescriptorListNumEntries) ||
! (EnergyDetectList != NULL && PANDescriptorList != NULL) ||
! (EnergyDetectListNumEntries && EnergyDetectList == NULL) ||
! (PANDescriptorListNumEntries && PANDescriptorList == NULL)) {
status = IEEE154_INVALID_PARAMETER;
} else if (ScanType != ENERGY_DETECTION_SCAN &&
***************
*** 157,161 ****
m_currentChannelNum = 0;
m_resultIndex = 0;
! if (ScanType == ENERGY_DETECTION_SCAN){
m_resultList = EnergyDetectList;
m_resultListNumEntries = EnergyDetectListNumEntries;
--- 161,165 ----
m_currentChannelNum = 0;
m_resultIndex = 0;
! if (ScanType == ENERGY_DETECTION_SCAN) {
m_resultList = EnergyDetectList;
m_resultListNumEntries = EnergyDetectListNumEntries;
***************
*** 168,171 ****
--- 172,176 ----
call Token.request();
}
+ dbg_serial("ScanP", "MLME_SCAN.request -> result: %lu\n", (uint32_t) status);
return status;
}
***************
*** 173,185 ****
event void Token.granted()
{
uint8_t i;
ieee154_macPANId_t bcastPANID = 0xFFFF;
ieee154_macDSN_t dsn = call MLME_GET.macDSN();
! if (!m_busy){
call Token.release();
return;
}
! switch (m_scanType){
case ACTIVE_SCAN:
// beacon request frame
--- 178,204 ----
event void Token.granted()
{
+ if (call RadioOff.isOff())
+ continueScanRequest();
+ else
+ ASSERT(call RadioOff.off() == SUCCESS);
+ // will continue in continueScanRequest()
+ }
+
+ task void continueScanRequestTask()
+ {
+ continueScanRequest();
+ }
+
+ void continueScanRequest()
+ {
uint8_t i;
ieee154_macPANId_t bcastPANID = 0xFFFF;
ieee154_macDSN_t dsn = call MLME_GET.macDSN();
! if (!m_busy) {
call Token.release();
return;
}
! switch (m_scanType) {
case ACTIVE_SCAN:
// beacon request frame
***************
*** 220,224 ****
uint32_t supportedChannels = IEEE154_SUPPORTED_CHANNELS;
atomic {
! while (!(m_scanChannels & m_currentChannelBit & supportedChannels) && m_currentChannelNum < 27){
m_unscannedChannels |= m_currentChannelBit;
m_currentChannelBit <<= 1;
--- 239,243 ----
uint32_t supportedChannels = IEEE154_SUPPORTED_CHANNELS;
atomic {
! while (!(m_scanChannels & m_currentChannelBit & supportedChannels) && m_currentChannelNum < 27) {
m_unscannedChannels |= m_currentChannelBit;
m_currentChannelBit <<= 1;
***************
*** 228,238 ****
if (m_currentChannelNum < 27) {
call MLME_SET.phyCurrentChannel(m_currentChannelNum);
! switch (m_scanType){
case PASSIVE_SCAN:
! radioStatus = call RadioRx.prepare();
break;
! case ACTIVE_SCAN:
case ORPHAN_SCAN:
! radioStatus = call RadioTx.load(m_txFrame);
break;
case ENERGY_DETECTION_SCAN:
--- 247,258 ----
if (m_currentChannelNum < 27) {
call MLME_SET.phyCurrentChannel(m_currentChannelNum);
! dbg_serial("ScanP", "Scanning channel %lu...\n", (uint32_t) m_currentChannelNum);
! switch (m_scanType) {
case PASSIVE_SCAN:
! radioStatus = call RadioRx.enableRx(0, 0);
break;
! case ACTIVE_SCAN: // fall through
case ORPHAN_SCAN:
! radioStatus = call RadioTx.transmit(m_txFrame, NULL, 0);
break;
case ENERGY_DETECTION_SCAN:
***************
*** 240,251 ****
break;
}
! if (radioStatus != SUCCESS){
! call Leds.led0On();
! }
} else {
- ieee154_status_t result = IEEE154_SUCCESS;
// we're done
m_currentChannelBit <<= 1;
! while (m_currentChannelBit){
m_unscannedChannels |= m_currentChannelBit;
m_currentChannelBit <<= 1;
--- 260,269 ----
break;
}
! ASSERT(radioStatus == SUCCESS);
} else {
// we're done
+ ieee154_status_t result = IEEE154_SUCCESS;
m_currentChannelBit <<= 1;
! while (m_currentChannelBit) {
m_unscannedChannels |= m_currentChannelBit;
m_currentChannelBit <<= 1;
***************
*** 256,260 ****
if (m_scanType == PASSIVE_SCAN || m_scanType == ACTIVE_SCAN)
call MLME_SET.macPANId(m_PANID);
! if (m_txFrame != NULL){
call TxControlPool.put((ieee154_txcontrol_t*) ((uint8_t*) m_txFrame->header - offsetof(ieee154_txcontrol_t, header)));
call TxFramePool.put(m_txFrame);
--- 274,278 ----
if (m_scanType == PASSIVE_SCAN || m_scanType == ACTIVE_SCAN)
call MLME_SET.macPANId(m_PANID);
! if (m_txFrame != NULL) {
call TxControlPool.put((ieee154_txcontrol_t*) ((uint8_t*) m_txFrame->header - offsetof(ieee154_txcontrol_t, header)));
call TxFramePool.put(m_txFrame);
***************
*** 264,267 ****
--- 282,286 ----
call Token.release();
m_busy = FALSE;
+ dbg_serial("ScanP", "MLME_SCAN.confirm()\n");
signal MLME_SCAN.confirm (
result,
***************
*** 274,283 ****
m_scanType == PASSIVE_SCAN) && m_macAutoRequest) ? m_resultIndex : 0,
((m_scanType == ACTIVE_SCAN ||
! m_scanType == PASSIVE_SCAN) && m_macAutoRequest) ? (ieee154_PANDescriptor_t*) m_resultList : NULL
! );
}
}
! /* ----------------------- EnergyDetection ----------------------- */
event void EnergyDetection.done(error_t status, int8_t EnergyLevel)
--- 293,306 ----
m_scanType == PASSIVE_SCAN) && m_macAutoRequest) ? m_resultIndex : 0,
((m_scanType == ACTIVE_SCAN ||
! m_scanType == PASSIVE_SCAN) && m_macAutoRequest) ? (ieee154_PANDescriptor_t*) m_resultList : NULL);
}
}
+
+ async event void RadioRx.enableRxDone()
+ {
+ post startTimerTask();
+ }
! /* ----------------------- EnergyDetection ----------------------- */
event void EnergyDetection.done(error_t status, int8_t EnergyLevel)
***************
*** 294,328 ****
}
! /* ----------------------- Active/Orphan scan ----------------------- */
!
! async event void RadioTx.loadDone()
! {
! call RadioTx.transmit(NULL, 0); // transmit immediately
! }
! async event void RadioTx.transmitDone(ieee154_txframe_t *frame, ieee154_reftime_t *txTime)
{
! if (call RadioRx.prepare() != SUCCESS) // must succeed
! call Leds.led0On();
}
! /* -------- Receive events (for Active/Passive/Orphan scan) -------- */
!
! async event void RadioRx.prepareDone()
! {
! call RadioRx.receive(NULL, 0);
! post startTimerTask();
! }
! event message_t* RadioRx.received(message_t *frame, ieee154_reftime_t *timestamp)
{
atomic {
if (!m_busy)
return frame;
! if (m_scanType == ORPHAN_SCAN){
if (!m_resultIndex)
if ((MHR(frame)[0] & FC1_FRAMETYPE_MASK) == FC1_FRAMETYPE_CMD &&
! ((uint8_t*)call Frame.getPayload(frame))[0] == CMD_FRAME_COORDINATOR_REALIGNMENT){
m_resultIndex++;
m_currentChannelNum = 27; // terminate scan
call RadioOff.off();
--- 317,340 ----
}
! /* ----------------------- Active/Orphan scan ----------------------- */
! async event void RadioTx.transmitDone(ieee154_txframe_t *frame, const ieee154_timestamp_t *timestamp, error_t result)
{
! ASSERT(call RadioRx.enableRx(0, 0) == SUCCESS);
}
! /* -------- Receive events (for Active/Passive/Orphan scan) -------- */
! event message_t* RadioRx.received(message_t *frame, const ieee154_timestamp_t *timestamp)
{
atomic {
if (!m_busy)
return frame;
! if (m_scanType == ORPHAN_SCAN) {
if (!m_resultIndex)
if ((MHR(frame)[0] & FC1_FRAMETYPE_MASK) == FC1_FRAMETYPE_CMD &&
! ((uint8_t*)call Frame.getPayload(frame))[0] == CMD_FRAME_COORDINATOR_REALIGNMENT) {
m_resultIndex++;
+ dbg_serial("ScanP", "Received coordinator realignment frame.\n");
m_currentChannelNum = 27; // terminate scan
call RadioOff.off();
***************
*** 337,368 ****
m_currentChannelNum,
IEEE154_SUPPORTED_CHANNELPAGE,
! &((ieee154_PANDescriptor_t*) m_resultList)[m_resultIndex]) == SUCCESS){
// check uniqueness: both PAN ID and source address must not be in a previously received beacon
uint8_t i;
if (m_resultIndex)
for (i=0; i<m_resultIndex; i++)
! if ( ((ieee154_PANDescriptor_t*) m_resultList)[i].CoordPANId ==
! ((ieee154_PANDescriptor_t*) m_resultList)[m_resultIndex].CoordPANId &&
! ((ieee154_PANDescriptor_t*) m_resultList)[i].CoordAddrMode ==
! ((ieee154_PANDescriptor_t*) m_resultList)[m_resultIndex].CoordAddrMode)
! if ( (((ieee154_PANDescriptor_t*) m_resultList)[i].CoordAddrMode == ADDR_MODE_SHORT_ADDRESS &&
! ((ieee154_PANDescriptor_t*) m_resultList)[i].CoordAddress.shortAddress ==
! ((ieee154_PANDescriptor_t*) m_resultList)[m_resultIndex].CoordAddress.shortAddress) ||
! (((ieee154_PANDescriptor_t*) m_resultList)[i].CoordAddrMode == ADDR_MODE_EXTENDED_ADDRESS &&
! ((ieee154_PANDescriptor_t*) m_resultList)[i].CoordAddress.extendedAddress ==
! ((ieee154_PANDescriptor_t*) m_resultList)[m_resultIndex].CoordAddress.extendedAddress) )
return frame; // not unique
m_resultIndex++;
! if (m_resultIndex == m_resultListNumEntries){
m_currentChannelNum = 27; // terminate scan
call RadioOff.off();
}
}
! }
}
return frame;
}
! /* ----------------------- Common ----------------------- */
task void startTimerTask()
--- 349,382 ----
m_currentChannelNum,
IEEE154_SUPPORTED_CHANNELPAGE,
! &((ieee154_PANDescriptor_t*) m_resultList)[m_resultIndex]) == SUCCESS) {
!
// check uniqueness: both PAN ID and source address must not be in a previously received beacon
uint8_t i;
+ ieee154_PANDescriptor_t* descriptor = (ieee154_PANDescriptor_t*) m_resultList;
if (m_resultIndex)
for (i=0; i<m_resultIndex; i++)
! if (descriptor[i].CoordPANId == descriptor[m_resultIndex].CoordPANId &&
! descriptor[i].CoordAddrMode == descriptor[m_resultIndex].CoordAddrMode)
! if ((descriptor[i].CoordAddrMode == ADDR_MODE_SHORT_ADDRESS &&
! descriptor[i].CoordAddress.shortAddress ==
! descriptor[m_resultIndex].CoordAddress.shortAddress) ||
! (descriptor[i].CoordAddrMode == ADDR_MODE_EXTENDED_ADDRESS &&
! descriptor[i].CoordAddress.extendedAddress ==
! descriptor[m_resultIndex].CoordAddress.extendedAddress))
return frame; // not unique
+ dbg_serial("ScanP", "Received beacon, source: 0x%lx, channel: %lu.\n",
+ (uint32_t) descriptor[m_resultIndex].CoordAddress.shortAddress, (uint32_t) m_currentChannelNum);
m_resultIndex++;
! if (m_resultIndex == m_resultListNumEntries) {
m_currentChannelNum = 27; // terminate scan
call RadioOff.off();
}
}
! } // PASSIVE_SCAN / ACTIVE_SCAN
}
return frame;
}
! /* ----------------------- Common ----------------------- */
task void startTimerTask()
***************
*** 378,384 ****
async event void RadioOff.offDone()
{
! m_currentChannelBit <<= 1;
! m_currentChannelNum++;
! post nextIterationTask();
}
--- 392,402 ----
async event void RadioOff.offDone()
{
! if (m_currentChannelNum == 0)
! post continueScanRequestTask();
! else {
! m_currentChannelBit <<= 1;
! m_currentChannelNum++;
! post nextIterationTask();
! }
}
***************
*** 388,398 ****
}
! async event void RadioTx.transmitUnslottedCsmaCaDone(ieee154_txframe_t *frame,
! bool ackPendingFlag, ieee154_csma_t *csmaParams, error_t result){}
!
! async event void RadioTx.transmitSlottedCsmaCaDone(ieee154_txframe_t *frame, ieee154_reftime_t *txTime,
! bool ackPendingFlag, uint16_t remainingBackoff, ieee154_csma_t *csmaParams, error_t result){}
!
! default event message_t* MLME_BEACON_NOTIFY.indication ( message_t *beaconFrame ){return beaconFrame;}
default event void MLME_SCAN.confirm (
ieee154_status_t status,
--- 406,410 ----
}
! default event message_t* MLME_BEACON_NOTIFY.indication (message_t *beaconFrame) {return beaconFrame;}
default event void MLME_SCAN.confirm (
ieee154_status_t status,
***************
*** 403,407 ****
int8_t* EnergyDetectList,
uint8_t PANDescriptorListNumEntries,
! ieee154_PANDescriptor_t* PANDescriptorList
! ){}
}
--- 415,418 ----
int8_t* EnergyDetectList,
uint8_t PANDescriptorListNumEntries,
! ieee154_PANDescriptor_t* PANDescriptorList) {}
}
Index: SimpleTransferArbiterP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/mac/tkn154/SimpleTransferArbiterP.nc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** SimpleTransferArbiterP.nc 23 Oct 2008 16:09:28 -0000 1.2
--- SimpleTransferArbiterP.nc 4 Mar 2009 18:31:32 -0000 1.3
***************
*** 129,133 ****
{
atomic {
! if (call ArbiterInfo.userId() == fromClient){
call ResourceConfigure.unconfigure[fromClient]();
call ResourceConfigure.configure[resId]();
--- 129,133 ----
{
atomic {
! if (call ArbiterInfo.userId() == fromClient) {
call ResourceConfigure.unconfigure[fromClient]();
call ResourceConfigure.configure[resId]();
Index: TKN154_MAC.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/mac/tkn154/TKN154_MAC.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** TKN154_MAC.h 25 Nov 2008 09:35:09 -0000 1.3
--- TKN154_MAC.h 4 Mar 2009 18:31:32 -0000 1.4
***************
*** 38,41 ****
--- 38,42 ----
#include "TKN154.h"
#include "TKN154_PHY.h"
+ #include "TKN154_platform.h"
/****************************************************
***************
*** 75,81 ****
IEEE154_macMaxFrameRetries = 0x59,
IEEE154_macMinBE = 0x4F,
- // no identifier defined in standard
IEEE154_macMinLIFSPeriod = 0xA0,
- // no identifier defined in standard
IEEE154_macMinSIFSPeriod = 0xA1,
IEEE154_macPANId = 0x50,
--- 76,80 ----
***************
*** 90,94 ****
IEEE154_macTransactionPersistenceTime = 0x55,
! // attributes not present in the standard PIB:
IEEE154_macPanCoordinator = 0xF0,
};
--- 89,93 ----
IEEE154_macTransactionPersistenceTime = 0x55,
! // custom attributes (not present in the standard PIB)
IEEE154_macPanCoordinator = 0xF0,
};
***************
*** 129,132 ****
--- 128,132 ----
};
+ /** some unique strings */
#define SYNC_POLL_CLIENT unique("PollP.client")
#define ASSOCIATE_POLL_CLIENT unique("PollP.client")
***************
*** 140,143 ****
--- 140,161 ----
};
+ /****************************************************
+ * Default time-related constants for beacon-enabled PANs,
+ * these may be overridden by platform-specific constants.
+ * */
+
+ #ifndef IEEE154_MAX_BEACON_JITTER
+ // will start to listen for a beacon MAX_BEACON_JITTER_TIME(BO) symbols
+ // before its expected arrival, where BO is the current beacon order
+ // (here --by default-- BO is ignored)
+ #define IEEE154_MAX_BEACON_JITTER(BO) 20
+ #endif
+
+ #ifndef IEEE154_MAX_BEACON_LISTEN_TIME
+ // maximum time to listen for a beacon after its expected arrival,
+ // before it is declared as missed
+ #define IEEE154_MAX_BEACON_LISTEN_TIME(BO) (128 * IEEE154_SYMBOLS_PER_OCTET + IEEE154_MAX_BEACON_JITTER(BO))
+ #endif
+
typedef struct {
uint8_t length; // top bit denotes -> promiscuous mode
***************
*** 167,171 ****
ieee154_metadata_t metadata;
} ieee154_txcontrol_t;
!
typedef struct ieee154_csma {
uint8_t BE; // initial backoff exponent
--- 185,189 ----
ieee154_metadata_t metadata;
} ieee154_txcontrol_t;
!
typedef struct ieee154_csma {
uint8_t BE; // initial backoff exponent
***************
*** 177,181 ****
typedef struct {
ieee154_txframe_t *frame;
! ieee154_csma_t csmaParams;
uint32_t transactionTime;
} ieee154_cap_frame_backup_t;
--- 195,199 ----
typedef struct {
ieee154_txframe_t *frame;
! ieee154_csma_t csma;
uint32_t transactionTime;
} ieee154_cap_frame_backup_t;
***************
*** 218,223 ****
IEEE154_aTurnaroundTime = 12,
! FRAMECTL_LENGTH_MASK = 0x7F, // "length" member in ieee154_frame_t
! FRAMECTL_PROMISCUOUS = 0x80, // "length" member in ieee154_frame_t
};
#define IEEE154_SUPPORTED_CHANNELPAGE (IEEE154_SUPPORTED_CHANNELS >> 27)
--- 236,241 ----
IEEE154_aTurnaroundTime = 12,
! FRAMECTL_LENGTH_MASK = 0x7F, // "length" member in ieee154_header_t
! FRAMECTL_PROMISCUOUS = 0x80, // "length" member in ieee154_header_t
};
#define IEEE154_SUPPORTED_CHANNELPAGE (IEEE154_SUPPORTED_CHANNELS >> 27)
***************
*** 241,244 ****
--- 259,304 ----
};
+ #ifdef TKN154_DEBUG
+
+ /******************************************************************
+ * ATTENTION! Debugging over serial is a lot of overhead. To
+ * keep it simple, here are the rules you have to follow when
+ * using the dbg_serial() command:
+ *
+ * - dbg_serial() is used like dbg(), i.e. you pass it at least
+ * two strings, the first one describing the component/file,
+ * the second is a format string (like in printf())
+ * - following the second string, there may be zero up to
+ * two parameters -- these must be (cast to) uint32_t!
+ * - both strings must be constants (pointers always valid)
+ * - no data is sent over serial, unless dbg_serial_flush() is
+ * called; try to call it when the system is idle or at least
+ * when no time-critical operations are pending
+ * - on the PC use the printf java client to display the text
+ * (see tinyos-2.x/apps/tests/TestPrintf/README.txt)
+ *
+ * The ASSERT(X) macro is used to test for errors. If X evaluates
+ * to zero, then 3 leds start blinking simulataneously (about 2Hz)
+ * and the node *continuously* outputs over serial the filename+line
+ * where the (first) ASSERT has failed. This means, even if your
+ * TelosB was not attached to your PC while the ASSERT failed you
+ * can still pull the information out later.
+ *
+ * All dbg_serial() and ASSERT() statements are removed, if
+ * TKN154_DEBUG is not defined (which is the default).
+ **/
+
+ /* -> functions are defined in DebugP.nc */
+ void tkn154_assert(bool val, const char *filename, uint16_t line, const char *func);
+ void tkn154_dbg_serial(const char *filename, uint16_t line, ...);
+ void tkn154_dbg_serial_flush();
+ #define ASSERT(X) tkn154_assert(X, __FILE__,__LINE__,__FUNCTION__)
+ #define dbg_serial(m, ...) tkn154_dbg_serial(m, __LINE__,__VA_ARGS__)
+ #define dbg_serial_flush() tkn154_dbg_serial_flush()
+ #else
+ #define ASSERT(X) if ((X)==0){}
+ #define dbg_serial(m, ...) dbg(m, __VA_ARGS__)
+ #define dbg_serial_flush()
+ #endif
#endif // __TKN154_MAC_H
Index: TKN154_PIB.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/mac/tkn154/TKN154_PIB.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** TKN154_PIB.h 21 Oct 2008 17:29:00 -0000 1.2
--- TKN154_PIB.h 4 Mar 2009 18:31:37 -0000 1.3
***************
*** 42,50 ****
! typedef struct ieee154_PIB_t {
! /**************/
! /* bool types */
! /**************/
// 0x41
--- 42,48 ----
! typedef struct ieee154_PIB {
! /** bool types */
// 0x41
***************
*** 64,72 ****
// 0x5D
ieee154_macSecurityEnabled_t macSecurityEnabled;
! // no standard attribute
ieee154_macPanCoordinator_t macPanCoordinator;
! /*****************/
! /* uint8_t types */
! /*****************/
// 0x00
--- 62,69 ----
// 0x5D
ieee154_macSecurityEnabled_t macSecurityEnabled;
! // custom attribute
ieee154_macPanCoordinator_t macPanCoordinator;
!
! /** uint8_t types */
// 0x00
***************
*** 101,107 ****
ieee154_macResponseWaitTime_t macResponseWaitTime;
! /*****************************/
! /* larger than uint8_t types */
! /*****************************/
// 0x4B
--- 98,102 ----
ieee154_macResponseWaitTime_t macResponseWaitTime;
! /** larger than uint8_t types */
// 0x4B
Index: TransferClientP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/mac/tkn154/TransferClientP.nc,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** TransferClientP.nc 21 Oct 2008 17:29:00 -0000 1.3
--- TransferClientP.nc 4 Mar 2009 18:31:37 -0000 1.4
***************
*** 60,64 ****
}
! async command uint8_t TransferredFrom.getUserId(){ return myUserId;}
async command void TransferredFrom.transfer()
--- 60,64 ----
}
! async command uint8_t TransferredFrom.getUserId() { return myUserId;}
async command void TransferredFrom.transfer()
***************
*** 66,71 ****
signal ResourceTransferred.transferred();
}
! default async command uint8_t TransferTo.getUserId(){ call Leds.led0On(); return 0xFF;}
! default async command void TransferTo.transfer(){ call Leds.led0On(); }
! default async event void ResourceTransferred.transferred(){}
}
--- 66,71 ----
signal ResourceTransferred.transferred();
}
! default async command uint8_t TransferTo.getUserId() { ASSERT(0); return 0xFF;}
! default async command void TransferTo.transfer() { ASSERT(0); }
! default async event void ResourceTransferred.transferred() {}
}
--- FrameDispatchP.nc DELETED ---
--- TKN154_DEBUG.h DELETED ---
--- TKN154P.nc DELETED ---
More information about the Tinyos-2-commits
mailing list