[Tinyos-2-commits] CVS: tinyos-2.x/tos/lib/mac/tkn154 BeaconRequestRxP.nc, NONE, 1.1 DispatchUnslottedCsmaP.nc, 1.9, 1.10 TKN154NonBeaconEnabledP.nc, 1.7, 1.8
Jan-Hinrich Hauer
janhauer at users.sourceforge.net
Mon May 18 05:54:13 PDT 2009
Update of /cvsroot/tinyos/tinyos-2.x/tos/lib/mac/tkn154
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv27767/tos/lib/mac/tkn154
Modified Files:
DispatchUnslottedCsmaP.nc TKN154NonBeaconEnabledP.nc
Added Files:
BeaconRequestRxP.nc
Log Message:
Added a component that accepts beacon request frames and responds with a beacon (written by Jasper Buesch).
--- NEW FILE: BeaconRequestRxP.nc ---
/*
* Copyright (c) 2009, 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/05/18 12:54:10 $
* @author: Jasper Buesch <buesch at tkn.tu-berlin.de>
* ========================================================================
*/
#include "TKN154_MAC.h"
#include "TKN154.h"
module BeaconRequestRxP
{
provides
{
interface Init as Reset;
interface IEEE154TxBeaconPayload;
}
uses
{
interface FrameRx as BeaconRequestRx;
interface FrameTx as BeaconRequestResponseTx;
interface MLME_GET;
interface FrameUtility;
interface IEEE154Frame as Frame;
}
}
implementation
{
/* variables that describe the beacon (payload) */
norace ieee154_txframe_t m_beaconFrame;
ieee154_header_t m_header;
ieee154_metadata_t m_metadata;
uint8_t m_beaconPayloadLen;
uint8_t m_payload[IEEE154_aMaxBeaconPayloadLength];
/* ------------------- Init ------------------- */
command error_t Reset.init()
{
m_beaconPayloadLen = 0;
m_beaconFrame.header = &m_header;
m_beaconFrame.headerLen = 0;
m_beaconFrame.payload = m_payload;
m_beaconFrame.payloadLen = 4; // first 4 bytes belong to superframe- & gts-fields
m_beaconFrame.metadata = &m_metadata;
dbg_serial("BeaconRequestResponderP","Init()\n");
return SUCCESS;
}
/* ------------------- Beacon-Request Response ------------------- */
task void sendBeaconTask(){
call BeaconRequestResponseTx.transmit(&m_beaconFrame);
}
event message_t* BeaconRequestRx.received(message_t* frame)
{
uint8_t offset = 0;
ieee154_macShortAddress_t shortAddress = call MLME_GET.macShortAddress();
bool isShortAddr;
shortAddress = call MLME_GET.macShortAddress();
isShortAddr = (shortAddress != 0xFFFE);
m_beaconFrame.header->mhr[MHR_INDEX_FC1] = FC1_FRAMETYPE_BEACON;
m_beaconFrame.header->mhr[MHR_INDEX_FC2] = isShortAddr ? FC2_SRC_MODE_SHORT : FC2_SRC_MODE_EXTENDED;
offset = MHR_INDEX_ADDRESS;
*((nxle_uint16_t*) &m_beaconFrame.header->mhr[offset]) = PAN_ID;
offset += sizeof(ieee154_macPANId_t);
if (isShortAddr) {
*((nxle_uint16_t*) &m_beaconFrame.header->mhr[offset]) = shortAddress;
offset += sizeof(ieee154_macShortAddress_t);
} else {
call FrameUtility.copyLocalExtendedAddressLE(&m_beaconFrame.header->mhr[offset]);
offset += 8;
}
m_beaconFrame.headerLen = offset;
// Superframe-spec
m_payload[0] = 0xff; // beacon- and superframe order always 15 in non-beaconenabled mode
m_payload[1] = 0x00;
if (call MLME_GET.macPanCoordinator() == TRUE)
m_payload[1] |= 0x40;
if (call MLME_GET.macAssociationPermit() == TRUE)
m_payload[1] |= 0x80;
if (call MLME_GET.macBattLifeExt() == TRUE)
m_payload[1] |= 0x10;
// GTS-spec
m_payload[2] = 0;
// Pending-Address-spec
m_payload[3] = 0;
signal IEEE154TxBeaconPayload.aboutToTransmit();
post sendBeaconTask();
return frame;
}
event void BeaconRequestResponseTx.transmitDone(ieee154_txframe_t *txFrame, ieee154_status_t status){
signal IEEE154TxBeaconPayload.beaconTransmitted();
}
/* ----------------------- Beacon Payload ----------------------- */
command error_t IEEE154TxBeaconPayload.setBeaconPayload(void *beaconPayload, uint8_t length) {
dbg_serial("BeaconRequestResponderP","IEEE154TxBeaconPayload.setBeaconPayload\n\n");
if (length < IEEE154_aMaxBeaconPayloadLength){
memcpy(&m_payload[4], beaconPayload, length);
m_beaconFrame.payloadLen = 4 + length;
signal IEEE154TxBeaconPayload.setBeaconPayloadDone(beaconPayload, length);
return SUCCESS;
} else
return ESIZE;
}
command const void* IEEE154TxBeaconPayload.getBeaconPayload(){
return &m_payload[4]; // the first four bytes are non-user bytes
}
command uint8_t IEEE154TxBeaconPayload.getBeaconPayloadLength(){
return m_beaconFrame.payloadLen - 4; // Beacon-Payload in NonBeaconed mode at least 4 bytes (non-user payload)
}
command error_t IEEE154TxBeaconPayload.modifyBeaconPayload(uint8_t offset, void *buffer, uint8_t bufferLength){
uint16_t totalLen = offset + bufferLength;
if (totalLen > IEEE154_aMaxBeaconPayloadLength ||
call IEEE154TxBeaconPayload.getBeaconPayloadLength() < totalLen)
return ESIZE;
else {
memcpy(&m_payload[4+offset], buffer, bufferLength);
signal IEEE154TxBeaconPayload.modifyBeaconPayloadDone(offset, buffer , bufferLength);
}
return SUCCESS;
}
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: DispatchUnslottedCsmaP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/mac/tkn154/DispatchUnslottedCsmaP.nc,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** DispatchUnslottedCsmaP.nc 14 May 2009 13:20:35 -0000 1.9
--- DispatchUnslottedCsmaP.nc 18 May 2009 12:54:10 -0000 1.10
***************
*** 205,211 ****
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();
--- 205,219 ----
void setCurrentFrame(ieee154_txframe_t *frame)
{
! if (frame->header->mhr[MHR_INDEX_FC1] != FC1_FRAMETYPE_BEACON) {
! // set the sequence number for command/data frame
! ieee154_macDSN_t dsn = call MLME_GET.macDSN();
! frame->header->mhr[MHR_INDEX_SEQNO] = dsn++;
! call MLME_SET.macDSN(dsn);
! } else {
! // set the sequence number for beacon frame
! ieee154_macBSN_t bsn = call MLME_GET.macBSN();
! frame->header->mhr[MHR_INDEX_SEQNO] = bsn++;
! call MLME_SET.macBSN(bsn);
! }
m_csma.NB = 0;
m_csma.macMaxCsmaBackoffs = m_macMaxCSMABackoffs = call MLME_GET.macMaxCSMABackoffs();
Index: TKN154NonBeaconEnabledP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/mac/tkn154/TKN154NonBeaconEnabledP.nc,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** TKN154NonBeaconEnabledP.nc 14 May 2009 13:20:35 -0000 1.7
--- TKN154NonBeaconEnabledP.nc 18 May 2009 12:54:10 -0000 1.8
***************
*** 66,69 ****
--- 66,70 ----
interface IEEE154Frame;
interface IEEE154BeaconFrame;
+ interface IEEE154TxBeaconPayload;
interface SplitControl as PromiscuousMode;
interface Get<uint64_t> as GetLocalExtendedAddress;
***************
*** 99,102 ****
--- 100,104 ----
IndirectTxP,
PollP,
+ BeaconRequestRxP,
#ifndef IEEE154_SCAN_DISABLED
***************
*** 165,168 ****
--- 167,171 ----
IEEE154Frame = PibP;
IEEE154BeaconFrame = PibP;
+ IEEE154TxBeaconPayload = BeaconRequestRxP;
PromiscuousMode = PromiscuousModeP;
GetLocalExtendedAddress = PibP.GetLocalExtendedAddress;
***************
*** 170,174 ****
TimeCalc = PibP;
FrameUtility = PibP;
!
/* ----------------------- Scanning (MLME-SCAN) ----------------------- */
--- 173,177 ----
TimeCalc = PibP;
FrameUtility = PibP;
!
/* ----------------------- Scanning (MLME-SCAN) ----------------------- */
***************
*** 190,193 ****
--- 193,205 ----
ScanP.FrameUtility -> PibP;
+ /* -------------------- Responding to Active Scans --------------------- */
+
+ PibP.MacReset -> BeaconRequestRxP;
+ BeaconRequestRxP.BeaconRequestRx -> DispatchP.FrameRx[FC1_FRAMETYPE_CMD + CMD_FRAME_BEACON_REQUEST];
+ BeaconRequestRxP.BeaconRequestResponseTx -> DispatchQueueP.FrameTx[unique(CAP_TX_CLIENT)];
+ BeaconRequestRxP.MLME_GET -> PibP;
+ BeaconRequestRxP.FrameUtility -> PibP;
+ BeaconRequestRxP.Frame -> PibP;
+
/* -------------------- Association (MLME-ASSOCIATE) -------------------- */
More information about the Tinyos-2-commits
mailing list