--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+
+#include "TKN154_MAC.h"
+
+module AssociateP
+{
+ provides
+ {
+ interface Init;
+ interface MLME_ASSOCIATE;
+ interface MLME_DISASSOCIATE;
+ interface MLME_COMM_STATUS;
+ }
+ uses
+ {
+ interface FrameRx as AssociationRequestRx;
+ interface FrameTx as AssociationRequestTx;
+ interface FrameExtracted as AssociationResponseExtracted;
+ interface FrameTx as AssociationResponseTx;
+
+ interface FrameTx as DisassociationIndirectTx;
+ interface FrameTx as DisassociationDirectTx;
+ interface FrameTx as DisassociationToCoord;
+
+ interface FrameRx as DisassociationDirectRxFromCoord;
+ interface FrameExtracted as DisassociationExtractedFromCoord;
+ interface FrameRx as DisassociationRxFromDevice;
+
+ interface DataRequest;
+ interface Timer<TSymbolIEEE802154> as ResponseTimeout;
+ interface Get<bool> as IsTrackingBeacons;
+ interface Pool<ieee154_txframe_t> as TxFramePool;
+ interface Pool<ieee154_txcontrol_t> as TxControlPool;
+ interface MLME_GET;
+ interface MLME_SET;
+ interface FrameUtility;
+ interface IEEE154Frame as Frame;
+ interface Leds;
+ interface Get<uint64_t> as LocalExtendedAddress;
+ interface Ieee802154Debug as Debug;
+ }
+}
+implementation
+{
+ enum {
+ S_IDLE = 0xFF,
+ };
+ uint8_t m_payloadAssocRequest[2];
+ uint8_t m_payloadDisassocRequest[2];
+ uint8_t m_payloadAssocResponse[MAX_PENDING_ASSOC_RESPONSES][4];
+ uint8_t m_coordAddrMode;
+ uint8_t m_assocRespStatus;
+ uint16_t m_shortAddress;
+ bool m_associationOngoing;
+ bool m_disAssociationOngoing;
+
+ command error_t Init.init()
+ {
+ uint8_t i;
+ call ResponseTimeout.stop();
+ m_payloadAssocRequest[0] = S_IDLE;
+ m_payloadDisassocRequest[0] = S_IDLE;
+ m_coordAddrMode = 0;
+ m_associationOngoing = FALSE;
+ m_disAssociationOngoing = FALSE;
+ for (i=0; i<MAX_PENDING_ASSOC_RESPONSES; i++)
+ m_payloadAssocResponse[i][0] = S_IDLE;
+ return SUCCESS;
+ }
+
+/* ------------------- MLME_ASSOCIATE Request ------------------- */
+
+ command ieee154_status_t MLME_ASSOCIATE.request (
+ uint8_t LogicalChannel,
+ uint8_t ChannelPage,
+ uint8_t CoordAddrMode,
+ uint16_t CoordPANID,
+ ieee154_address_t CoordAddress,
+ ieee154_CapabilityInformation_t CapabilityInformation,
+ ieee154_security_t *security
+ )
+ {
+ ieee154_status_t status = IEEE154_SUCCESS;
+ ieee154_txframe_t *txFrame=0;
+ ieee154_txcontrol_t *txControl=0;
+ ieee154_address_t srcAddress;
+
+ if (security && security->SecurityLevel)
+ status = IEEE154_UNSUPPORTED_SECURITY;
+ else if (ChannelPage != IEEE154_SUPPORTED_CHANNELPAGE || LogicalChannel > 26 ||
+ !(IEEE154_SUPPORTED_CHANNELS & ((uint32_t) 1 << LogicalChannel)) ||
+ (CoordAddrMode != ADDR_MODE_SHORT_ADDRESS && CoordAddrMode != ADDR_MODE_EXTENDED_ADDRESS))
+ status = IEEE154_INVALID_PARAMETER;
+ 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;
+ call MLME_SET.phyCurrentChannel(LogicalChannel);
+ call MLME_SET.macPANId(CoordPANID);
+ m_coordAddrMode = CoordAddrMode;
+ if (CoordAddrMode == ADDR_MODE_SHORT_ADDRESS)
+ call MLME_SET.macCoordShortAddress(CoordAddress.shortAddress);
+ else
+ call MLME_SET.macCoordExtendedAddress(CoordAddress.extendedAddress);
+ txFrame->header = &txControl->header;
+ txFrame->metadata = &txControl->metadata;
+ srcAddress.extendedAddress = call LocalExtendedAddress.get();
+ txFrame->headerLen = call FrameUtility.writeHeader(
+ txFrame->header->mhr,
+ CoordAddrMode,
+ CoordPANID,
+ &CoordAddress,
+ ADDR_MODE_EXTENDED_ADDRESS,
+ 0xFFFF,
+ &srcAddress,
+ 0);
+ txFrame->header->mhr[MHR_INDEX_FC1] = FC1_ACK_REQUEST | FC1_FRAMETYPE_CMD;
+ txFrame->header->mhr[MHR_INDEX_FC2] = FC2_SRC_MODE_EXTENDED |
+ (CoordAddrMode == ADDR_MODE_SHORT_ADDRESS ? FC2_DEST_MODE_SHORT : FC2_DEST_MODE_EXTENDED);
+ m_payloadAssocRequest[0] = CMD_FRAME_ASSOCIATION_REQUEST;
+ m_payloadAssocRequest[1] = *((uint8_t*) &CapabilityInformation);
+ txFrame->payload = m_payloadAssocRequest;
+ txFrame->payloadLen = 2;
+ m_associationOngoing = TRUE;
+ if ((status = call AssociationRequestTx.transmit(txFrame)) != IEEE154_SUCCESS){
+ m_associationOngoing = FALSE;
+ call TxFramePool.put(txFrame);
+ call TxControlPool.put(txControl);
+ }
+ }
+ call Debug.log(LEVEL_INFO, AssociateP_REQUEST, status, 0, 0);
+ return status;
+ }
+
+ event void AssociationRequestTx.transmitDone(ieee154_txframe_t *txFrame, ieee154_status_t status)
+ {
+ 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(LEVEL_INFO, AssociateP_SETTIMER,
+ call MLME_GET.macResponseWaitTime()*IEEE154_aBaseSuperframeDuration, 0, 0);
+ }
+ call Debug.log(LEVEL_INFO, AssociateP_TXDONE, status, 0, 0);
+ }
+
+ event void ResponseTimeout.fired()
+ {
+ uint8_t coordAddress[8];
+ if (!m_associationOngoing)
+ return;
+ // have not received an AssociationResponse yet, poll the coordinator now
+ if (m_coordAddrMode == ADDR_MODE_SHORT_ADDRESS)
+ *((nxle_uint16_t*) &coordAddress) = call MLME_GET.macCoordShortAddress();
+ else
+ 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;
+ signal DataRequest.pollDone();
+ }
+ }
+
+ event message_t* AssociationResponseExtracted.received(message_t* frame, ieee154_txframe_t *txFrame)
+ {
+ uint8_t *payload = (uint8_t *) &frame->data;
+ if (m_associationOngoing){
+ m_shortAddress = *((nxle_uint16_t*) (payload + 1));
+ m_assocRespStatus = *(payload + 3);
+ }
+ return frame;
+ }
+
+ event void DataRequest.pollDone()
+ {
+ if (m_associationOngoing){
+ call Debug.log(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)
+ {
+ uint8_t *payload = (uint8_t *) &frame->data;
+ ieee154_address_t srcAddress;
+ if (call Frame.getSrcAddrMode(frame) == ADDR_MODE_EXTENDED_ADDRESS &&
+ call Frame.getSrcAddr(frame, &srcAddress) == SUCCESS)
+ signal MLME_ASSOCIATE.indication(srcAddress.extendedAddress,
+ *((ieee154_CapabilityInformation_t*) (payload + 1)), 0);
+ return frame;
+ }
+
+ command ieee154_status_t MLME_ASSOCIATE.response (
+ uint64_t deviceAddress,
+ uint16_t assocShortAddress,
+ ieee154_association_status_t status,
+ ieee154_security_t *security
+ )
+ {
+ uint8_t i;
+ ieee154_status_t txStatus = IEEE154_SUCCESS;
+ ieee154_txframe_t *txFrame;
+ ieee154_txcontrol_t *txControl;
+ ieee154_address_t srcAddress;
+
+ for (i=0; i<MAX_PENDING_ASSOC_RESPONSES;i++)
+ if (m_payloadAssocResponse[i][0] == S_IDLE)
+ break;
+ 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;
+ } else {
+ txFrame->header = &txControl->header;
+ txFrame->metadata = &txControl->metadata;
+ txFrame->payload = m_payloadAssocResponse[i];
+ srcAddress.extendedAddress = call LocalExtendedAddress.get();
+ txFrame->headerLen = call FrameUtility.writeHeader(
+ txFrame->header->mhr,
+ ADDR_MODE_EXTENDED_ADDRESS,
+ call MLME_GET.macPANId(),
+ (ieee154_address_t*) &deviceAddress,
+ ADDR_MODE_EXTENDED_ADDRESS,
+ call MLME_GET.macPANId(),
+ &srcAddress,
+ 1);
+ txFrame->header->mhr[MHR_INDEX_FC1] = FC1_ACK_REQUEST | FC1_FRAMETYPE_CMD | FC1_PAN_ID_COMPRESSION;
+ txFrame->header->mhr[MHR_INDEX_FC2] = FC2_SRC_MODE_EXTENDED | FC2_DEST_MODE_EXTENDED;
+ txFrame->payload[0] = CMD_FRAME_ASSOCIATION_RESPONSE;
+ *((nxle_uint16_t*) &txFrame->payload[1]) = assocShortAddress;
+ txFrame->payload[3] = status;
+ txFrame->payloadLen = 4;
+ if ((txStatus = call AssociationResponseTx.transmit(txFrame)) != IEEE154_SUCCESS){
+ txFrame->payload[0] = S_IDLE;
+ call TxFramePool.put(txFrame);
+ call TxControlPool.put(txControl);
+ }
+ }
+ return txStatus;
+ }
+
+ event void AssociationResponseTx.transmitDone(ieee154_txframe_t *txFrame, ieee154_status_t status)
+ {
+ ieee154_address_t srcAddress, deviceAddress;
+ srcAddress.extendedAddress = call LocalExtendedAddress.get();
+ if ((txFrame->header->mhr[MHR_INDEX_FC2] & FC2_DEST_MODE_MASK) == FC2_DEST_MODE_SHORT)
+ deviceAddress.shortAddress = *((nxle_uint16_t*) (&(txFrame->header->mhr[MHR_INDEX_ADDRESS]) + 2));
+ else
+ call FrameUtility.convertToNative(&deviceAddress.extendedAddress, (&(txFrame->header->mhr[MHR_INDEX_ADDRESS]) + 2));
+ txFrame->payload[0] = S_IDLE;
+ call TxControlPool.put((ieee154_txcontrol_t*) ((uint8_t*) txFrame->header - offsetof(ieee154_txcontrol_t, header)));
+ call TxFramePool.put(txFrame);
+ signal MLME_COMM_STATUS.indication(call MLME_GET.macPANId(), ADDR_MODE_EXTENDED_ADDRESS,
+ srcAddress, ADDR_MODE_EXTENDED_ADDRESS, deviceAddress,
+ status, 0);
+ }
+
+
+/* ------------------- MLME_DISASSOCIATE (initiating) ------------------- */
+
+ command ieee154_status_t MLME_DISASSOCIATE.request (
+ uint8_t DeviceAddrMode,
+ uint16_t DevicePANID,
+ ieee154_address_t DeviceAddress,
+ ieee154_disassociation_reason_t DisassociateReason,
+ bool TxIndirect,
+ ieee154_security_t *security
+ )
+ {
+ ieee154_status_t status = IEEE154_SUCCESS;
+ ieee154_txframe_t *txFrame=0;
+ ieee154_txcontrol_t *txControl=0;
+ ieee154_address_t srcAddress;
+
+ if (security && security->SecurityLevel)
+ status = IEEE154_UNSUPPORTED_SECURITY;
+ else if (call MLME_GET.macPANId() != DevicePANID ||
+ (DeviceAddrMode != ADDR_MODE_SHORT_ADDRESS && DeviceAddrMode != ADDR_MODE_EXTENDED_ADDRESS))
+ status = IEEE154_INVALID_PARAMETER;
+ 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;
+ srcAddress.extendedAddress = call LocalExtendedAddress.get();
+ txFrame->headerLen = call FrameUtility.writeHeader(
+ txFrame->header->mhr,
+ DeviceAddrMode,
+ call MLME_GET.macPANId(),
+ &DeviceAddress,
+ ADDR_MODE_EXTENDED_ADDRESS,
+ call MLME_GET.macPANId(),
+ &srcAddress,
+ TRUE);
+ txFrame->header->mhr[MHR_INDEX_FC1] = FC1_ACK_REQUEST | FC1_FRAMETYPE_CMD | FC1_PAN_ID_COMPRESSION;
+ txFrame->header->mhr[MHR_INDEX_FC2] = FC2_SRC_MODE_EXTENDED |
+ (DeviceAddrMode == ADDR_MODE_SHORT_ADDRESS ? FC2_DEST_MODE_SHORT : FC2_DEST_MODE_EXTENDED);
+ m_payloadDisassocRequest[0] = CMD_FRAME_DISASSOCIATION_NOTIFICATION;
+ m_payloadDisassocRequest[1] = DisassociateReason;
+ txFrame->payload = m_payloadDisassocRequest;
+ txFrame->payloadLen = 2;
+ m_disAssociationOngoing = TRUE;
+ if ((DeviceAddrMode == ADDR_MODE_SHORT_ADDRESS &&
+ 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) {
+ status = call DisassociationIndirectTx.transmit(txFrame);
+ } else {
+ status = call DisassociationDirectTx.transmit(txFrame);
+ }
+ if (status != IEEE154_SUCCESS){
+ m_disAssociationOngoing = FALSE;
+ call TxFramePool.put(txFrame);
+ call TxControlPool.put(txControl);
+ }
+ }
+ call Debug.log(LEVEL_INFO, DISSASSOCIATE_REQUEST, status, 0, 0);
+ return status;
+ }
+
+ event void DisassociationToCoord.transmitDone(ieee154_txframe_t *data, ieee154_status_t status)
+ {
+ // transmitted a disassociation notification to our coordinator
+ uint8_t *mhr = MHR(data), srcAddrOffset = 7;
+ uint8_t DeviceAddrMode = (mhr[MHR_INDEX_FC2] & FC2_SRC_MODE_MASK) >> FC2_SRC_MODE_OFFSET;
+ uint16_t DevicePANID = *((nxle_uint16_t*) (&(mhr[MHR_INDEX_ADDRESS])));
+ ieee154_address_t DeviceAddress;
+ if ((mhr[MHR_INDEX_FC2] & FC2_DEST_MODE_MASK) == FC2_DEST_MODE_EXTENDED)
+ srcAddrOffset += 6;
+ call FrameUtility.convertToNative(&DeviceAddress.extendedAddress, &mhr[srcAddrOffset]);
+ call TxControlPool.put((ieee154_txcontrol_t*) ((uint8_t*) data->header - offsetof(ieee154_txcontrol_t, header)));
+ call TxFramePool.put(data);
+ call Debug.log(LEVEL_INFO, DISSASSOCIATE_TXDONE, status, 2, 0);
+ m_disAssociationOngoing = FALSE;
+ signal MLME_DISASSOCIATE.confirm(status, DeviceAddrMode, DevicePANID, DeviceAddress);
+ }
+
+ event void DisassociationIndirectTx.transmitDone(ieee154_txframe_t *data, ieee154_status_t status)
+ {
+ signal DisassociationDirectTx.transmitDone(data, status);
+ }
+
+ event void DisassociationDirectTx.transmitDone(ieee154_txframe_t *data, ieee154_status_t status)
+ {
+ // transmitted a disassociation notification to a device
+ uint8_t *mhr = MHR(data), dstAddrOffset = 5;
+ uint8_t DeviceAddrMode = (mhr[1] & FC2_DEST_MODE_MASK) >> FC2_DEST_MODE_OFFSET;
+ uint16_t DevicePANID = *((nxle_uint16_t*) (&(mhr[MHR_INDEX_ADDRESS])));
+ ieee154_address_t DeviceAddress;
+ call FrameUtility.convertToNative(&DeviceAddress.extendedAddress, &mhr[dstAddrOffset]);
+ call Debug.log(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(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)
+ {
+ // received a disassociation notification from the coordinator (direct tx)
+ ieee154_address_t address;
+ address.extendedAddress = call LocalExtendedAddress.get();
+ signal MLME_DISASSOCIATE.indication(address.extendedAddress, frame->data[1], NULL);
+ return frame;
+ }
+
+ event message_t* DisassociationExtractedFromCoord.received(message_t* frame, ieee154_txframe_t *txFrame)
+ {
+ // received a disassociation notification from the coordinator (indirect transmission)
+ return signal DisassociationDirectRxFromCoord.received(frame);
+ }
+
+ event message_t* DisassociationRxFromDevice.received(message_t* frame)
+ {
+ // received a disassociation notification from the device
+ ieee154_address_t address;
+ call Debug.log(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
+ ){}
+ 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,
+ uint8_t SrcAddrMode,
+ ieee154_address_t SrcAddr,
+ uint8_t DstAddrMode,
+ ieee154_address_t DstAddr,
+ ieee154_status_t status,
+ ieee154_security_t *security
+ ){}
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+generic module BackupP(typedef backup_t)
+{
+ provides
+ {
+ interface SetNow<backup_t*> as Store;
+ interface GetNow<backup_t*> as Retrieve;
+ }
+}
+implementation
+{
+ backup_t m_backup;
+ async command error_t Store.setNow(backup_t* backup)
+ {
+ memcpy(&m_backup, backup, sizeof(backup_t));
+ return SUCCESS;
+ }
+
+ async command backup_t* Retrieve.getNow()
+ {
+ return &m_backup;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+
+#include "TKN154_MAC.h"
+#include "TKN154_DEBUG.h"
+
+module BeaconSynchronizeP
+{
+ provides
+ {
+ interface Init as Reset;
+ interface MLME_SYNC;
+ interface MLME_BEACON_NOTIFY;
+ interface MLME_SYNC_LOSS;
+ interface Get<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
+ {
+ interface MLME_GET;
+ interface MLME_SET;
+ interface FrameUtility;
+ interface IEEE154BeaconFrame as BeaconFrame;
+ interface Alarm<TSymbolIEEE802154,uint32_t> as TrackAlarm;
+ interface RadioRx as BeaconRx;
+ interface RadioOff;
+ interface Get<bool> as IsBeaconEnabledPAN;
+ interface DataRequest;
+ interface FrameRx as CoordRealignmentRx;
+ interface Resource as Token;
+ interface ResourceTransfer as TokenToCap;
+ interface TimeCalc;
+ 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;
+
+ norace uint8_t m_numBeaconsLost;
+ uint8_t m_coordAddress[8];
+ 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();
+
+ 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(
+ IEEE154_BEACON_LOSS,
+ call MLME_GET.macPANId(),
+ call MLME_GET.phyCurrentChannel(),
+ call MLME_GET.phyCurrentPage(),
+ NULL);
+ m_updatePending = m_stopTracking = m_tracking = FALSE;
+ return SUCCESS;
+ }
+
+/* ----------------------- MLME-SYNC ----------------------- */
+/*
+ * Allows to synchronize with a coordinator.
+ */
+
+ command ieee154_status_t MLME_SYNC.request (
+ uint8_t logicalChannel,
+ uint8_t channelPage,
+ bool trackBeacon)
+ {
+ uint32_t supportedChannels = IEEE154_SUPPORTED_CHANNELS;
+ uint32_t currentChannelBit = 1;
+
+ currentChannelBit <<= logicalChannel;
+ if (!(currentChannelBit & supportedChannels) || (call MLME_GET.macPANId() == 0xFFFF) ||
+ (channelPage != IEEE154_SUPPORTED_CHANNELPAGE) || !call IsBeaconEnabledPAN.get())
+ return IEEE154_INVALID_PARAMETER;
+
+ call Debug.log(LEVEL_INFO,SyncP_REQUEST, 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;
+ atomic m_updatePending = TRUE;
+ call Debug.log(LEVEL_INFO,SyncP_RESOURCE_REQUEST, 0, 0, 0);
+ call Token.request();
+ }
+ call Debug.flush();
+ return IEEE154_SUCCESS;
+ }
+
+ event void Token.granted()
+ {
+ bool missed = FALSE;
+ call Debug.log(LEVEL_INFO,SyncP_GOT_RESOURCE, 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();
+ if (m_beaconOrder >= 15)
+ m_beaconOrder = 14;
+ call MLME_SET.phyCurrentChannel(m_updateLogicalChannel);
+ m_tracking = m_updateTrackBeacon;
+ m_beaconInterval = ((uint32_t) 1 << m_beaconOrder) * (uint32_t) IEEE154_aBaseSuperframeDuration;
+ m_dt = m_beaconInterval;
+ m_numBeaconsLost = IEEE154_aMaxLostBeacons; // will be reset when beacon is received
+ call Debug.log(LEVEL_INFO,SyncP_UPDATING, call MLME_GET.macCoordShortAddress(),
+ call MLME_GET.macPANId(), m_updateLogicalChannel);
+ } else {
+ m_state = S_PREPARE;
+ if (!m_tracking){
+ call Debug.log(LEVEL_INFO,SyncP_RELEASE_RESOURCE, 0, 0, 0);
+ call Token.release();
+ return;
+ }
+ while (call TimeCalc.hasExpired(m_lastBeaconRxTime, m_dt)){ // missed a beacon
+ call Debug.log(LEVEL_INFO,SyncP_BEACON_MISSED_1, m_lastBeaconRxTime, m_dt, missed);
+ m_dt += m_beaconInterval;
+ m_numBeaconsLost++;
+ missed = TRUE;
+ }
+ if (m_numBeaconsLost >= IEEE154_aMaxLostBeacons){
+ post processBeaconTask();
+ return;
+ }
+ if (missed){
+ call Token.request();
+ call Debug.log(LEVEL_INFO,SyncP_RELEASE_RESOURCE, m_lastBeaconRxTime, m_dt, missed);
+ call Token.release();
+ return;
+ }
+ }
+ if (!call RadioOff.isOff())
+ call RadioOff.off();
+ else
+ signal RadioOff.offDone();
+ }
+
+ async event void TrackAlarm.fired()
+ {
+ call Debug.log(LEVEL_IMPORTANT,SyncP_SWITCHOFF, 0,0,0);
+ atomic {
+ switch (m_state)
+ {
+ case S_PREPARE:
+ call BeaconRx.prepare();
+ break;
+ case S_RADIO_OFF:
+ call Debug.log(LEVEL_INFO, SyncP_SWITCHOFF, 0, 0,0);
+ call RadioOff.off();
+ break;
+ }
+ }
+ }
+
+ async event void BeaconRx.prepareDone()
+ {
+ 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;
+ call BeaconRx.receive(&m_lastBeaconRxRefTime, m_dt-RX_LAG);
+ call Debug.log(LEVEL_IMPORTANT,SyncP_RX_ON, call TrackAlarm.getNow(),m_lastBeaconRxTime+m_dt,RX_LAG);
+ 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(LEVEL_INFO,SyncP_RX_PACKET,*((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))
+ {
+ return frame;
+ } else {
+ message_t *tmp = m_beaconBufferPtr;
+ call TrackAlarm.stop();
+ m_beaconSwapBufferReady = FALSE;
+ m_beaconBufferPtr = frame;
+ if (timestamp != NULL)
+ memcpy(&m_lastBeaconRxRefTime, timestamp, sizeof(ieee154_reftime_t));
+ call RadioOff.off();
+ return tmp;
+ }
+ }
+
+ async event void RadioOff.offDone()
+ {
+ if (m_state == S_FIRST_SCAN)
+ call BeaconRx.prepare();
+ else if (m_state == S_PREPARE)
+ call TrackAlarm.startAt(m_lastBeaconRxTime, m_dt - IEEE154_RADIO_RX_PREPARE_DELAY);
+ 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!
+ m_numBeaconsLost++;
+ m_dt += m_beaconInterval;
+ call Debug.log(LEVEL_IMPORTANT, SyncP_BEACON_MISSED_3,m_numBeaconsLost,0,m_lastBeaconRxTime);
+ if (m_numBeaconsLost >= IEEE154_aMaxLostBeacons){
+ m_tracking = FALSE;
+ call Debug.log(LEVEL_IMPORTANT, SyncP_LOST_SYNC,0,0,0);
+ call Leds.led2Off();
+ 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(LEVEL_INFO,SyncP_RELEASE_RESOURCE, 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(LEVEL_INFO, SyncP_BEACON_RX, m_lastBeaconRxTime, timestamp, mhr[2]);
+ m_numGtsSlots = (payload[2] & 7);
+ gtsFieldLength = 1 + ((m_numGtsSlots > 0) ? 1 + m_numGtsSlots * 3: 0);
+ m_lastBeaconRxTime = timestamp + IEEE154_SYNC_SYMBOL_OFFSET - IEEE154_SYMBOLS_PER_OCTET - IEEE154_PREAMBLE_LENGTH;
+ 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 += call MLME_GET.macBattLifeExtPeriods();
+ } 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(LEVEL_INFO,SyncP_RELEASE_RESOURCE, 0, 0, 0);
+ call Token.release();
+ } else {
+ error_t req = call Token.request();
+ call Debug.log(LEVEL_INFO,SyncP_TRANSFER_RESOURCE, req, 0, 0);
+ call TokenToCap.transfer();
+ }
+
+ if (pendAddrSpec & PENDING_ADDRESS_SHORT_MASK)
+ beaconPayload += (pendAddrSpec & PENDING_ADDRESS_SHORT_MASK) * 2;
+ 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;
+ uint16_t CoordPANId;
+ uint8_t *CoordAddress;
+ uint8_t SrcAddrMode = pendingAddrMode;
+ if ((mhr[MHR_INDEX_FC2] & FC2_SRC_MODE_MASK) == FC2_SRC_MODE_SHORT)
+ CoordAddrMode = ADDR_MODE_SHORT_ADDRESS;
+ else
+ CoordAddrMode = ADDR_MODE_EXTENDED_ADDRESS;
+ CoordAddress = &(mhr[MHR_INDEX_ADDRESS+2]);
+ CoordPANId = *((nxle_uint16_t*) &(mhr[MHR_INDEX_ADDRESS]));
+ call DataRequest.poll(CoordAddrMode, CoordPANId, CoordAddress, SrcAddrMode);
+ }
+ // Beacon Tracking: update state
+ call Debug.log(LEVEL_INFO, SyncP_NEXT_RX_TIME, 0, timestamp, m_beaconInterval);
+ m_numBeaconsLost = 0;
+ // TODO: check PAN ID conflict here?
+ if (!autoRequest || beaconPayloadSize)
+ m_beaconBufferPtr = signal MLME_BEACON_NOTIFY.indication(m_beaconBufferPtr);
+ m_beaconSwapBufferReady = TRUE;
+ }
+ }
+
+ command bool IsTrackingBeacons.get(){ 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)
+ {
+ uint8_t *payload = call Frame.getPayload(frame);
+ ieee154_macPANId_t panID = *(nxle_uint16_t*) &payload[1];
+ if (panID == call MLME_GET.macPANId())
+ signal MLME_SYNC_LOSS.indication(
+ IEEE154_REALIGNMENT, // LossReason
+ panID, // PANId
+ payload[5], // LogicalChannel,
+ call Frame.getPayloadLength(frame) == 9 ? payload[8] : call MLME_GET.phyCurrentPage(),
+ NULL
+ );
+ return frame;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#include "TKN154_MAC.h"
+#include "TKN154_PHY.h"
+module BeaconTransmitP
+{
+ provides
+ {
+ interface Init as Reset;
+ interface MLME_START;
+ interface WriteBeaconField as SuperframeSpecWrite;
+ interface Get<bool> as IsSendingBeacons;
+ 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<bool> as IsBLEActive;
+ interface GetNow<uint16_t> as BLELen;
+ interface GetNow<uint8_t*> as GtsField;
+ interface GetNow<uint32_t> as SfSlotDuration;
+ interface GetNow<uint32_t> as BeaconInterval;
+ interface GetNow<uint8_t> as FinalCapSlot;
+ interface GetNow<uint8_t> as NumGtsSlots;
+ interface GetNow<bool> as BeaconFramePendingBit;
+ interface IEEE154TxBeaconPayload;
+ } uses {
+ interface Notify<bool> as GtsSpecUpdated;
+ interface Notify<bool> as PendingAddrSpecUpdated;
+ interface Notify<const void*> as PIBUpdate[uint8_t attributeID];
+ interface Alarm<TSymbolIEEE802154,uint32_t> as BeaconTxAlarm;
+ interface Timer<TSymbolIEEE802154> as BeaconPayloadUpdateTimer;
+ interface RadioOff;
+ interface Get<bool> as IsBeaconEnabledPAN;
+ interface RadioTx as BeaconTx;
+ interface MLME_GET;
+ interface MLME_SET;
+ interface Resource as Token;
+ interface ResourceTransfer as TokenToBroadcast;
+ interface FrameTx as RealignmentBeaconEnabledTx;
+ interface FrameTx as RealignmentNonBeaconEnabledTx;
+ interface FrameRx as BeaconRequestRx;
+ interface WriteBeaconField as GtsInfoWrite;
+ interface WriteBeaconField as PendingAddrWrite;
+ interface FrameUtility;
+ interface Get<bool> as IsTrackingBeacons;
+ interface GetNow<uint32_t> as LastBeaconRxTime;
+ interface GetNow<ieee154_reftime_t*> as LastBeaconRxRefTime;
+ interface Ieee802154Debug as Debug;
+ interface Set<ieee154_macSuperframeOrder_t> as SetMacSuperframeOrder;
+ interface Set<ieee154_macBeaconTxTime_t> as SetMacBeaconTxTime;
+ interface Set<ieee154_macPanCoordinator_t> as SetMacPanCoordinator;
+ interface GetSet<ieee154_txframe_t*> as GetSetRealignmentFrame;
+ interface GetNow<bool> as IsBroadcastReady;
+ interface TimeCalc;
+ interface Leds;
+ }
+}
+implementation
+{
+
+ enum {
+ MAX_BEACON_PAYLOAD_SIZE = IEEE154_aMaxBeaconOverhead + IEEE154_aMaxBeaconPayloadLength,
+
+ REQUEST_UPDATE_SF = 0x01,
+ REQUEST_REALIGNMENT = 0x02,
+ REQUEST_CONFIRM_PENDING = 0x04,
+ REQUEST_REALIGNMENT_DONE_PENDING = 0x08,
+
+ MODIFIED_SF_SPEC = 0x01,
+ MODIFIED_GTS_FIELD = 0x02,
+ MODIFIED_PENDING_ADDR_FIELD = 0x04,
+ MODIFIED_SPECS_MASK = 0x0F,
+
+ MODIFIED_BEACON_PAYLOAD = 0x10,
+ MODIFIED_BEACON_PAYLOAD_NEW = 0x20,
+ MODIFIED_BEACON_PAYLOAD_MASK = 0xF0,
+
+ S_TX_IDLE = 0,
+ S_TX_LOCKED = 1,
+ S_TX_WAITING = 2,
+ };
+
+ norace ieee154_txframe_t m_beaconFrame;
+ ieee154_header_t m_header;
+ uint8_t m_payload[MAX_BEACON_PAYLOAD_SIZE];
+ ieee154_metadata_t m_metadata;
+ uint8_t m_gtsField[1+1+3*7];
+
+ void *m_updateBeaconPayload;
+ uint8_t m_updateBeaconOffset;
+ uint8_t m_updateBeaconLength;
+ uint8_t m_beaconPayloadLen;
+ uint8_t m_pendingAddrLen;
+ uint8_t m_pendingGtsLen;
+
+ norace uint8_t m_requests; // TODO: check why norace?
+ norace uint8_t m_txState;
+ uint8_t m_payloadState;
+ norace bool m_txOneBeaconImmediately;
+
+ uint16_t m_PANId;
+ norace uint32_t m_startTime;
+ uint8_t m_logicalChannel;
+ norace uint8_t m_beaconOrder;
+ norace uint8_t m_superframeOrder;
+ ieee154_macBattLifeExt_t m_batteryLifeExtension;
+ bool m_PANCoordinator;
+ norace uint32_t m_beaconInterval;
+ norace uint32_t m_previousBeaconInterval;
+ norace uint32_t m_dt;
+ norace uint8_t m_bsn;
+ norace uint32_t m_lastBeaconTxTime;
+ norace ieee154_reftime_t m_lastBeaconTxRefTime;
+ norace uint32_t m_coordCapLen;
+ norace uint32_t m_coordCfpEnd;
+ norace uint32_t m_sfSlotDuration;
+ norace uint8_t m_finalCAPSlot;
+ norace uint8_t m_numGtsSlots;
+ norace uint16_t m_BLELen;
+ norace ieee154_macBattLifeExtPeriods_t m_battLifeExtPeriods;
+ norace bool m_framePendingBit;
+
+ uint16_t m_updatePANId;
+ uint8_t m_updateLogicalChannel;
+ uint32_t m_updateStartTime;
+ uint8_t m_updateBeaconOrder;
+ uint8_t m_updateSuperframeOrder;
+ bool m_updatePANCoordinator;
+ bool m_updateBatteryLifeExtension;
+
+ task void txDoneTask();
+ task void signalStartConfirmSuccessTask();
+ void prepareNextBeaconTransmission();
+ void continueStartRequest();
+ void finishRealignment(ieee154_txframe_t *frame, ieee154_status_t status);
+
+ command error_t Reset.init()
+ {
+ m_beaconFrame.header = &m_header;
+ m_beaconFrame.headerLen = 0;
+ m_beaconFrame.payload = m_payload;
+ m_beaconFrame.payloadLen = 0;
+ m_beaconFrame.metadata = &m_metadata;
+ m_updateBeaconPayload = 0;
+ m_updateBeaconLength = 0;
+ m_requests = m_payloadState = m_txState = 0;
+ m_PANCoordinator = FALSE;
+ m_beaconPayloadLen = m_pendingAddrLen = m_pendingGtsLen = 0;
+ m_gtsField[0] = 0;
+ m_finalCAPSlot = 15;
+ m_beaconOrder = 15;
+ call BeaconPayloadUpdateTimer.stop();
+ call BeaconTxAlarm.stop();
+ return SUCCESS;
+ }
+
+/* ----------------------- MLME-START ----------------------- */
+/* "The MLME-START.request primitive allows the PAN coordinator to initiate a
+ * new PAN or to begin using a new superframe configuration. This primitive may
+ * also be used by a device already associated with an existing PAN to begin
+ * using a new superframe configuration." (IEEE 802.15.4-2006 Sect. 7.1.14.1)
+ **/
+
+ 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_macShortAddress_t shortAddress = call MLME_GET.macShortAddress();
+ ieee154_status_t status = IEEE154_SUCCESS;
+
+ if ((coordRealignSecurity && coordRealignSecurity->SecurityLevel) ||
+ (beaconSecurity && beaconSecurity->SecurityLevel))
+ status = IEEE154_UNSUPPORTED_SECURITY;
+ else if (shortAddress == 0xFFFF)
+ status = IEEE154_NO_SHORT_ADDRESS;
+ else if (logicalChannel > 26 || beaconOrder > 15 ||
+ (channelPage != IEEE154_SUPPORTED_CHANNELPAGE) ||
+ !(IEEE154_SUPPORTED_CHANNELS & ((uint32_t) 1 << logicalChannel)) ||
+ (superframeOrder > beaconOrder))
+ status = IEEE154_INVALID_PARAMETER;
+ else if (startTime && !call IsTrackingBeacons.get())
+ status = IEEE154_TRACKING_OFF;
+ else if (startTime && 0xFF000000)
+ status = IEEE154_INVALID_PARAMETER;
+ else if (m_requests & (REQUEST_CONFIRM_PENDING | REQUEST_UPDATE_SF))
+ status = IEEE154_TRANSACTION_OVERFLOW;
+ else if ((call IsBeaconEnabledPAN.get() && beaconOrder > 14) ||
+ (!call IsBeaconEnabledPAN.get() && beaconOrder < 15))
+ status = IEEE154_INVALID_PARAMETER;
+ else {
+ // new configuration *will* be put in operation
+ status = IEEE154_SUCCESS;
+ if (panCoordinator)
+ startTime = 0; // start immediately
+ call Debug.log(LEVEL_INFO, StartP_REQUEST, logicalChannel, beaconOrder, superframeOrder);
+ if (beaconOrder == 15){
+ // beaconless PAN
+ superframeOrder = 15;
+ }
+ m_updatePANId = panID;
+ m_updateLogicalChannel = logicalChannel;
+ m_updateStartTime = startTime;
+ m_updateBeaconOrder = beaconOrder;
+ m_updateSuperframeOrder = superframeOrder;
+ m_updatePANCoordinator = panCoordinator;
+ m_updateBatteryLifeExtension = batteryLifeExtension;
+ m_requests = (REQUEST_CONFIRM_PENDING | REQUEST_UPDATE_SF); // lock
+ if (coordRealignment)
+ m_requests |= REQUEST_REALIGNMENT;
+ if (!call IsSendingBeacons.get())
+ call Token.request();
+ }
+ return status;
+ }
+
+ void continueStartRequest()
+ {
+ uint8_t offset;
+ ieee154_macShortAddress_t shortAddress;
+ bool isShortAddr;
+
+ // (1) coord realignment?
+ if (m_requests & REQUEST_REALIGNMENT){
+ ieee154_txframe_t *realignmentFrame = call GetSetRealignmentFrame.get();
+ m_requests &= ~REQUEST_REALIGNMENT;
+ if (realignmentFrame == NULL){
+ // allocation failed!
+ m_requests = 0;
+ signal MLME_START.confirm(IEEE154_TRANSACTION_OVERFLOW);
+ return;
+ }
+ // set the payload portion of the realignmentFrame
+ // (the header fields are already set correctly)
+ realignmentFrame->payload[0] = CMD_FRAME_COORDINATOR_REALIGNMENT;
+ *((nxle_uint16_t*) &realignmentFrame->payload[1]) = m_updatePANId;
+ *((nxle_uint16_t*) &realignmentFrame->payload[3]) = call MLME_GET.macShortAddress();
+ realignmentFrame->payload[5] = m_updateLogicalChannel;
+ *((nxle_uint16_t*) &realignmentFrame->payload[6]) = 0xFFFF;
+ realignmentFrame->payloadLen = 8;
+
+ if (call IsSendingBeacons.get()){
+ // we're already transmitting beacons; the realignment frame
+ // must be sent (broadcast) after the next beacon
+ if (call RealignmentBeaconEnabledTx.transmit(realignmentFrame) != IEEE154_SUCCESS){
+ m_requests = 0;
+ call GetSetRealignmentFrame.set(realignmentFrame);
+ signal MLME_START.confirm(IEEE154_TRANSACTION_OVERFLOW);
+ } else {
+ // The realignment frame will be transmitted immediately after
+ // the next beacon - the result will be signalled in
+ // RealignmentBeaconEnabledTx.transmitDone(). Only then the superframe
+ // structure is updated and MLME_START.confirm signalled.
+ m_requests |= REQUEST_REALIGNMENT_DONE_PENDING; // lock
+ }
+ } else {
+ // send realignment frame in unslotted csma-ca now
+ if (call RealignmentNonBeaconEnabledTx.transmit(realignmentFrame) != IEEE154_SUCCESS){
+ m_requests = 0;
+ call GetSetRealignmentFrame.set(realignmentFrame);
+ signal MLME_START.confirm(IEEE154_TRANSACTION_OVERFLOW);
+ } else {
+ // A realignment frame will be transmitted now, the result will
+ // be signalled in RealignmentNonBeaconEnabledTx.transmitDone(). Only
+ // then the superframe structure is updated and MLME_START.confirm
+ // signalled.
+ m_requests |= REQUEST_REALIGNMENT_DONE_PENDING; // lock
+ }
+ }
+ return;
+ }
+
+ // (2) update internal state
+ m_startTime = m_updateStartTime;
+ m_txOneBeaconImmediately = FALSE;
+ m_previousBeaconInterval = 0;
+ if (m_startTime){
+ m_lastBeaconTxRefTime = *call LastBeaconRxRefTime.getNow();
+ m_lastBeaconTxTime = call LastBeaconRxTime.getNow();
+ } else {
+ // no StartTime defined by next higher layer - but
+ // if a realignment frame was transmitted, the next
+ // beacon tx time must take the old BI into consideration
+ if (m_requests & REQUEST_REALIGNMENT_DONE_PENDING)
+ m_previousBeaconInterval = m_beaconInterval;
+ else
+ m_txOneBeaconImmediately = TRUE;
+ }
+ m_PANId = m_updatePANId;
+ m_logicalChannel = m_updateLogicalChannel;
+ m_beaconOrder = m_updateBeaconOrder;
+ m_superframeOrder = m_updateSuperframeOrder;
+ m_PANCoordinator = m_updatePANCoordinator;
+ if (m_beaconOrder < 15){
+ m_batteryLifeExtension = m_updateBatteryLifeExtension;
+ m_beaconInterval = ((uint32_t) 1 << m_updateBeaconOrder) * IEEE154_aBaseSuperframeDuration;
+ } else {
+ m_batteryLifeExtension = FALSE;
+ m_beaconInterval = 0;
+ }
+ m_txState = S_TX_IDLE;
+ m_bsn = call MLME_GET.macBSN()+1;
+ m_battLifeExtPeriods = call MLME_GET.macBattLifeExtPeriods();
+
+ // (3) update PIB
+ call MLME_SET.macBeaconOrder(m_beaconOrder);
+ call SetMacSuperframeOrder.set(m_superframeOrder);
+ call MLME_SET.macPANId(m_PANId);
+ call MLME_SET.phyCurrentChannel(m_logicalChannel);
+ if (m_beaconOrder < 15)
+ call MLME_SET.macBattLifeExt(m_batteryLifeExtension);
+ call SetMacPanCoordinator.set(m_PANCoordinator);
+
+ // (4) assemble beacon header and payload
+ 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]) = m_PANId;
+ 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;
+ m_payloadState |= MODIFIED_SPECS_MASK; // update beacon payload
+ signal BeaconPayloadUpdateTimer.fired(); // assemble initial beacon payload
+
+ if (m_beaconOrder < 15){
+ // beacon-enabled PAN, signal confirm after next
+ // beacon has been transmitted (see MSC, Fig. 38)
+ m_requests = REQUEST_CONFIRM_PENDING;
+ } else {
+ // beaconless PAN, we're done
+ m_requests = 0;
+ signal MLME_START.confirm(IEEE154_SUCCESS);
+ }
+ }
+
+ task void grantedTask()
+ {
+ signal Token.granted();
+ }
+
+ event void Token.granted()
+ {
+ call Debug.log(LEVEL_INFO, StartP_GOT_RESOURCE, m_lastBeaconTxTime, m_beaconInterval, m_requests);
+ if (m_requests & REQUEST_REALIGNMENT_DONE_PENDING){
+ // unlikely to occur: we have not yet received a done()
+ // event after sending out a realignment frame
+ post grantedTask(); // spin
+ return;
+ }
+ if (m_requests & REQUEST_UPDATE_SF){
+ m_requests &= ~REQUEST_UPDATE_SF;
+ continueStartRequest();
+ call Debug.log(LEVEL_INFO, StartP_UPDATE_STATE, 0, 0, 0);
+ }
+ if (call RadioOff.isOff())
+ prepareNextBeaconTransmission();
+ else
+ call RadioOff.off();
+ }
+
+ async event void RadioOff.offDone()
+ {
+ prepareNextBeaconTransmission();
+ }
+
+ void prepareNextBeaconTransmission()
+ {
+ if (m_txState == S_TX_LOCKED){
+ // have not had time to finish processing the last sent beacon
+ post grantedTask();
+ call Debug.log(LEVEL_CRITICAL, StartP_OWNER_TOO_FAST, 0, 0, 0);
+ return;
+ } else if (m_beaconOrder > 14){
+ call Token.release();
+ } else {
+ atomic {
+ m_txState = S_TX_WAITING;
+ if (m_txOneBeaconImmediately){
+ signal BeaconTxAlarm.fired();
+ return;
+ } else if (m_startTime != 0){
+ // a new sf spec was put into operation, with a user-defined StartTime
+ // here m_lastBeaconTxTime is actually the last time a beacon was received
+ m_dt = m_startTime;
+ m_startTime = 0;
+ } else if (m_previousBeaconInterval != 0){
+ // a new sf spec was put into operation, after a realignment frame was
+ // broadcast; the next beacon time should still be calculated using the
+ // old BI (one last time)
+ m_dt = m_previousBeaconInterval;
+ m_previousBeaconInterval = 0;
+ if (m_requests & REQUEST_CONFIRM_PENDING){
+ // only now the next higher layer is to be informed
+ m_requests &= ~REQUEST_CONFIRM_PENDING;
+ post signalStartConfirmSuccessTask();
+ }
+ } else {
+ // the usual case: next beacon tx time = last time + BI
+ m_dt = m_beaconInterval;
+ }
+ while (call TimeCalc.hasExpired(m_lastBeaconTxTime, m_dt)){ // missed sending a beacon
+ call Debug.log(LEVEL_INFO, StartP_SKIPPED_BEACON, m_lastBeaconTxTime, m_dt, 0);
+ m_dt += m_beaconInterval;
+ }
+ if (m_dt < IEEE154_RADIO_TX_PREPARE_DELAY)
+ m_dt = IEEE154_RADIO_TX_PREPARE_DELAY;
+ // don't call BeaconTx.load just yet, otherwise the next
+ // higher layer cannot modify the beacon payload anymore;
+ // rather, set an alarm
+ call BeaconTxAlarm.startAt(m_lastBeaconTxTime, m_dt - IEEE154_RADIO_TX_PREPARE_DELAY);
+ }
+ }
+ }
+
+ async event void BeaconTxAlarm.fired()
+ {
+ atomic {
+ switch (m_txState)
+ {
+ case S_TX_WAITING:
+ m_txState = S_TX_LOCKED;
+ if (call IsBroadcastReady.getNow())
+ m_beaconFrame.header->mhr[MHR_INDEX_FC1] |= FC1_FRAME_PENDING;
+ else
+ m_beaconFrame.header->mhr[MHR_INDEX_FC1] &= ~FC1_FRAME_PENDING;
+ m_beaconFrame.header->mhr[MHR_INDEX_SEQNO] = m_bsn; // update beacon seqno
+ call Debug.log(LEVEL_INFO, StartP_PREPARE_TX, 0, m_lastBeaconTxTime, 0);
+ call BeaconTx.load(&m_beaconFrame);
+ break;
+ case S_TX_LOCKED:
+ call Debug.log(LEVEL_INFO, StartP_TRANSMIT, m_lastBeaconTxTime, m_dt, ((uint32_t)m_lastBeaconTxRefTime));
+ call BeaconTx.transmit(&m_lastBeaconTxRefTime, m_dt, 0, FALSE);
+ break;
+ }
+ }
+ }
+
+ async event void BeaconTx.loadDone()
+ {
+ atomic {
+ call Debug.log(LEVEL_INFO, StartP_PREPARE_TXDONE, 0, m_lastBeaconTxTime, 0);
+ if (m_txOneBeaconImmediately){
+ m_txOneBeaconImmediately = FALSE;
+ call BeaconTx.transmit(0, 0, 0, FALSE); // now!
+ } else
+ call BeaconTxAlarm.startAt(m_lastBeaconTxTime, m_dt - IEEE154_RADIO_TX_SEND_DELAY);
+ }
+ }
+
+ async event void BeaconTx.transmitDone(ieee154_txframe_t *frame,
+ ieee154_reftime_t *referenceTime, bool pendingFlag, error_t error)
+ {
+ // Coord CAP has just started...
+ uint8_t gtsFieldLength;
+ // Sec. 7.5.1.1: "start of slot 0 is defined as the point at which
+ // the first symbol of the beacon PPDU is transmitted"
+ call Debug.log(LEVEL_INFO, StartP_BEACON_TRANSMITTED, frame->metadata->timestamp, m_lastBeaconTxTime, m_dt);
+ m_lastBeaconTxTime = frame->metadata->timestamp;
+ memcpy(&m_lastBeaconTxRefTime, referenceTime, sizeof(ieee154_reftime_t));
+ m_numGtsSlots = (frame->payload[2] & 0x07);
+ gtsFieldLength = 1 + ((m_numGtsSlots > 0) ? 1 + m_numGtsSlots * 3: 0);
+ m_finalCAPSlot = (frame->payload[1] & 0x0F);
+ m_sfSlotDuration = (((uint32_t) 1) << ((frame->payload[0] & 0xF0) >> 4)) * IEEE154_aBaseSlotDuration;
+ if (frame->header->mhr[0] & FC1_FRAME_PENDING)
+ m_framePendingBit = TRUE;
+ else
+ m_framePendingBit = FALSE;
+ memcpy(m_gtsField, &frame->payload[0], gtsFieldLength);
+ if (frame->payload[1] & 0x10){
+ // BLE is active; calculate the time offset from slot0
+ m_BLELen = IEEE154_SHR_DURATION +
+ (frame->headerLen + frame->payloadLen) * IEEE154_SYMBOLS_PER_OCTET;
+ if (frame->headerLen + frame->payloadLen > IEEE154_aMaxSIFSFrameSize)
+ m_BLELen += IEEE154_MIN_LIFS_PERIOD;
+ else
+ m_BLELen += IEEE154_MIN_SIFS_PERIOD;
+ m_BLELen += m_battLifeExtPeriods;
+ } else
+ m_BLELen = 0;
+ call Token.request(); // register another request, before ...
+ call TokenToBroadcast.transfer(); // ... we let Broadcast module take over
+ post txDoneTask();
+ }
+
+ task void txDoneTask()
+ {
+ call MLME_SET.macBSN(m_bsn++);
+ call SetMacBeaconTxTime.set(m_lastBeaconTxTime); // start of slot0, ie. first preamble byte of beacon
+ call BeaconPayloadUpdateTimer.startOneShotAt(m_lastBeaconTxTime,
+ (m_beaconInterval>BEACON_PAYLOAD_UPDATE_INTERVAL) ? (m_beaconInterval - BEACON_PAYLOAD_UPDATE_INTERVAL): 0);
+ if (m_requests & REQUEST_CONFIRM_PENDING){
+ m_requests &= ~REQUEST_CONFIRM_PENDING;
+ signal MLME_START.confirm(IEEE154_SUCCESS);
+ }
+ m_txState = S_TX_IDLE;
+ signal IEEE154TxBeaconPayload.beaconTransmitted();
+ call Debug.flush();
+ }
+
+
+/* ----------------------- Beacon Payload ----------------------- */
+/*
+ * All access to the payload fields in the beacon happen
+ * through a set of temporary variables/flags, and just before
+ * the frame is loaded into the radio these changes are
+ * propagated into the actual payload portion of the beacon frame.
+ */
+
+ command error_t IEEE154TxBeaconPayload.setBeaconPayload(void *beaconPayload, uint8_t length)
+ {
+ if (length > IEEE154_aMaxBeaconPayloadLength)
+ return ESIZE;
+ else {
+ if (m_payloadState & MODIFIED_BEACON_PAYLOAD)
+ return EBUSY;
+ m_updateBeaconPayload = beaconPayload;
+ m_updateBeaconLength = length;
+ m_updateBeaconOffset = 0;
+ m_payloadState |= (MODIFIED_BEACON_PAYLOAD | MODIFIED_BEACON_PAYLOAD_NEW);
+ }
+ return SUCCESS;
+ }
+
+ command const void* IEEE154TxBeaconPayload.getBeaconPayload()
+ {
+ return &m_payload[IEEE154_aMaxBeaconOverhead];
+ }
+
+ command uint8_t IEEE154TxBeaconPayload.getBeaconPayloadLength()
+ {
+ return m_beaconFrame.payloadLen - (m_pendingAddrLen + m_pendingGtsLen + 2);
+ }
+
+ 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 {
+ if (m_payloadState & MODIFIED_BEACON_PAYLOAD)
+ return EBUSY;
+ m_updateBeaconPayload = buffer;
+ m_updateBeaconOffset = offset;
+ m_updateBeaconLength = bufferLength;
+ m_payloadState |= MODIFIED_BEACON_PAYLOAD;
+ }
+ return SUCCESS;
+ }
+
+ event void PIBUpdate.notify[uint8_t attributeID](const void* attributeValue)
+ {
+ switch (attributeID)
+ {
+ case IEEE154_macAssociationPermit:
+ atomic m_payloadState |= MODIFIED_SF_SPEC;
+ break;
+ case IEEE154_macGTSPermit:
+ atomic m_payloadState |= MODIFIED_GTS_FIELD;
+ break;
+ default:
+ break;
+ }
+ }
+
+ event void PendingAddrSpecUpdated.notify(bool val)
+ {
+ atomic m_payloadState |= MODIFIED_PENDING_ADDR_FIELD;
+ }
+
+ event void GtsSpecUpdated.notify(bool val)
+ {
+ atomic m_payloadState |= MODIFIED_GTS_FIELD;
+ }
+
+ uint8_t getNumGtsSlots(uint8_t *gtsInfoField)
+ {
+ uint8_t i, num=0;
+ for (i=0; i<(gtsInfoField[0] & GTS_DESCRIPTOR_COUNT_MASK); i++)
+ num += ((gtsInfoField[4+i*3] & GTS_LENGTH_MASK) >> GTS_LENGTH_OFFSET);
+ return num;
+ }
+
+ event void BeaconPayloadUpdateTimer.fired()
+ {
+ // in this order the MAC payload is updated:
+ // (1) pending addresses
+ // (2) GTS spec
+ // (3) sf spec
+ // (4) beacon payload (if there's enough time)
+ uint8_t len=0, *beaconSpecs = &m_payload[IEEE154_aMaxBeaconOverhead]; // going backwards
+ uint8_t beaconPayloadUpdated = 0, numGtsSlots = 15 - m_finalCAPSlot;
+
+ atomic {
+ if (m_txState == S_TX_LOCKED)
+ {
+ call Debug.log(LEVEL_INFO, StartP_BEACON_UPDATE, 0, 0, m_txState);
+ return; // too late !
+ }
+ if (m_payloadState & MODIFIED_PENDING_ADDR_FIELD){
+ len = call PendingAddrWrite.getLength();
+ beaconSpecs -= len;
+ call PendingAddrWrite.write(beaconSpecs, len);
+ if (len != m_pendingAddrLen){
+ m_pendingAddrLen = len;
+ m_payloadState |= MODIFIED_SPECS_MASK; // need to rewrite specs before
+ }
+ } else
+ beaconSpecs -= m_pendingAddrLen;
+ if (m_payloadState & MODIFIED_GTS_FIELD){
+ len = call GtsInfoWrite.getLength();
+ beaconSpecs -= len;
+ call GtsInfoWrite.write(beaconSpecs, len);
+ numGtsSlots = getNumGtsSlots(beaconSpecs);
+ if (len != m_pendingGtsLen || ((15-numGtsSlots) != m_finalCAPSlot)){
+ m_pendingGtsLen = len;
+ m_payloadState |= MODIFIED_SPECS_MASK; // need to rewrite specs before
+ }
+ } else
+ beaconSpecs -= m_pendingGtsLen;
+ beaconSpecs -= 2; // sizeof SF Spec
+ if (m_payloadState & MODIFIED_SF_SPEC){
+ call SuperframeSpecWrite.write(beaconSpecs, 2);
+ beaconSpecs[1] &= 0xF0; // clear FinalCAPSlot field
+ beaconSpecs[1] |= ((15-numGtsSlots) & 0x0F); // update FinalCAPSlot field
+ }
+ m_beaconFrame.payloadLen = (m_pendingAddrLen + m_pendingGtsLen + 2) + m_beaconPayloadLen;
+ m_beaconFrame.payload = beaconSpecs;
+ m_payloadState &= ~MODIFIED_SPECS_MASK; // clear flags
+ } // end atomic (give BeaconTxAlarm.fired() the chance to execute)
+ signal IEEE154TxBeaconPayload.aboutToTransmit();
+ atomic {
+ if (m_txState == S_TX_LOCKED)
+ {
+ call Debug.log(LEVEL_INFO, StartP_BEACON_UPDATE_2, 0, 0, m_txState);
+ return; // too late !
+ }
+ if (m_payloadState & MODIFIED_BEACON_PAYLOAD){
+ memcpy(&m_payload[IEEE154_aMaxBeaconOverhead + m_updateBeaconOffset],
+ m_updateBeaconPayload, m_updateBeaconLength);
+ beaconPayloadUpdated = (m_payloadState & MODIFIED_BEACON_PAYLOAD_MASK);
+ if (beaconPayloadUpdated & MODIFIED_BEACON_PAYLOAD_NEW)
+ m_beaconPayloadLen = m_updateBeaconOffset + m_updateBeaconLength;
+ }
+ m_beaconFrame.payloadLen = (m_pendingAddrLen + m_pendingGtsLen + 2) + m_beaconPayloadLen;
+ m_payloadState &= ~MODIFIED_BEACON_PAYLOAD_MASK;
+ }
+ if (beaconPayloadUpdated){
+ if ((beaconPayloadUpdated & MODIFIED_BEACON_PAYLOAD_NEW))
+ signal IEEE154TxBeaconPayload.setBeaconPayloadDone(m_updateBeaconPayload, m_updateBeaconLength);
+ else
+ signal IEEE154TxBeaconPayload.modifyBeaconPayloadDone(m_updateBeaconOffset,
+ m_updateBeaconPayload, m_updateBeaconLength);
+ }
+ }
+
+/* ----------------------- SuperframeSpec ----------------------- */
+
+ command uint8_t SuperframeSpecWrite.write(uint8_t *superframeSpecField, uint8_t maxlen)
+ {
+ if (call SuperframeSpecWrite.getLength() > maxlen)
+ return 0;
+ superframeSpecField[0] = m_beaconOrder | (m_superframeOrder << 4);
+ superframeSpecField[1] = m_finalCAPSlot;
+ if (m_PANCoordinator)
+ superframeSpecField[1] |= SF_SPEC2_PAN_COORD;
+ if (call MLME_GET.macAssociationPermit())
+ superframeSpecField[1] |= SF_SPEC2_ASSOCIATION_PERMIT;
+ return 2;
+ }
+
+ command uint8_t SuperframeSpecWrite.getLength()
+ {
+ return 2;
+ }
+
+/* ----------------------- Realignment ----------------------- */
+/* In beacon-enabled mode a realignment frame was broadcast in the CAP
+ * immediately after the beacon was transmitted. In non-beacon-enabled mode a
+ * realignment frame was sent using unslotted CSMA. In both cases, if the
+ * transmission was successful, the superframe spec must be updated now.
+ **/
+
+ event void RealignmentBeaconEnabledTx.transmitDone(ieee154_txframe_t *frame, ieee154_status_t status)
+ {
+ finishRealignment(frame, status);
+ }
+
+ event void RealignmentNonBeaconEnabledTx.transmitDone(ieee154_txframe_t *frame, ieee154_status_t status)
+ {
+ finishRealignment(frame, status);
+ }
+
+ void finishRealignment(ieee154_txframe_t *frame, ieee154_status_t status)
+ {
+ call GetSetRealignmentFrame.set(frame);
+ if (status == IEEE154_SUCCESS){
+ continueStartRequest();
+ m_requests &= ~REQUEST_REALIGNMENT_DONE_PENDING; // unlock
+ // signal confirm where we calculate the next beacon transmission time
+ } else {
+ m_requests = 0;
+ signal MLME_START.confirm(status);
+ }
+ }
+
+/* ----------------------- BeaconRequest ----------------------- */
+
+ event message_t* BeaconRequestRx.received(message_t* frame)
+ {
+ if (!call IsSendingBeacons.get()){
+ // transmit the beacon frame using unslotted CSMA-CA
+ // TODO
+ }
+ return frame;
+ }
+
+/* ----------------------- Defaults, etc. ----------------------- */
+
+ task void signalStartConfirmSuccessTask()
+ {
+ signal MLME_START.confirm(SUCCESS);
+ }
+
+ command bool IsSendingBeacons.get(){ return m_beaconOrder < 15;}
+
+ async command uint32_t BeaconInterval.getNow() { return m_beaconInterval; }
+ async command uint32_t CapStart.getNow() { return m_lastBeaconTxTime; }
+ async command ieee154_reftime_t* CapStartRefTime.getNow() { return &m_lastBeaconTxRefTime; }
+ 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 bool IsBLEActive.getNow(){ return m_BLELen>0;}
+ async command uint16_t BLELen.getNow(){ return m_BLELen;}
+ async command bool BeaconFramePendingBit.getNow(){ return m_framePendingBit;}
+
+ 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 uint8_t NumGtsSlots.getNow() { return m_numGtsSlots; }
+
+ 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(){}
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#include "TKN154_PHY.h"
+#include "TKN154_MAC.h"
+
+/**
+ * This module is responsible for sending/receiving frames during the
+ * contention access period (CAP in beacon-enabled mode). It does slightly
+ * different things depending on whether it is the CAP for an outgoing
+ * superframe (superframeDirection = OUTGOING_SUPERFRAME), i.e. the CAP from
+ * the perspective of a coordinator after it has transmitted its own beacon; or
+ * for an incoming superframe (superframeDirection = INCOMING_SUPERFRAME), i.e.
+ * the CAP from the perspective of a device after it has received a beacon from
+ * its coordinator (e.g. in the CAP a coordinator will usually listen for
+ * incoming frames from the devices, and a device will usually switch the
+ * radio off unless it has a frame to transmit).
+ */
+
+generic module CapP(uint8_t superframeDirection)
+{
+ provides
+ {
+ interface Init as Reset;
+ interface FrameTx as CapTx;
+ 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 Random;
+ 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 ResourceTransfer as TokenToCfp;
+ interface ResourceTransferred as TokenTransferred;
+ interface ResourceRequested as TokenRequested;
+ interface GetNow<bool> as IsTokenRequested;
+ interface GetNow<uint32_t> as CapStart;
+ interface GetNow<ieee154_reftime_t*> as CapStartRefTime;
+ interface GetNow<uint32_t> as CapLen;
+ interface GetNow<bool> as IsBLEActive;
+ interface GetNow<uint16_t> as BLELen;
+ interface GetNow<bool> as IsRxBroadcastPending;
+ interface GetNow<bool> as IsRxEnableActive;
+ interface Notify<bool> as RxEnableStateChange;
+ interface FrameUtility;
+ interface RadioTx;
+ interface RadioRx;
+ interface RadioOff;
+ interface Get<bool> as IsBeaconEnabledPAN;
+ interface MLME_GET;
+ interface MLME_SET;
+ interface Ieee802154Debug as Debug;
+ interface TimeCalc;
+ interface Leds;
+ interface SetNow<ieee154_cap_frame_backup_t*> as FrameBackup;
+ interface GetNow<ieee154_cap_frame_backup_t*> as FrameRestore;
+ }
+}
+implementation
+{
+ typedef enum {
+ SWITCH_OFF,
+ LOAD_TX,
+ PREPARE_RX,
+ DO_NOTHING,
+ WAIT_FOR_TXDONE,
+ } next_state_t;
+
+ typedef enum {
+ INDIRECT_TX_ALARM,
+ BROADCAST_ALARM,
+ NO_ALARM,
+ } rx_alarm_t;
+
+ enum {
+ COORD_ROLE = (superframeDirection == OUTGOING_SUPERFRAME),
+ DEVICE_ROLE = !COORD_ROLE,
+ };
+
+ norace bool m_lock;
+ norace ieee154_txframe_t *m_currentFrame;
+ norace ieee154_txframe_t *m_bcastFrame;
+ norace ieee154_txframe_t *m_lastFrame;
+ norace ieee154_macMaxBE_t m_BE;
+ norace ieee154_macMaxCSMABackoffs_t m_allowedBackoffs;
+ norace ieee154_macMaxBE_t m_macMaxBE;
+ norace uint16_t m_backoff;
+ norace uint16_t m_backoffElapsed;
+ norace ieee154_status_t m_result;
+ norace uint32_t m_transactionTime;
+ norace bool m_indirectTxPending = FALSE;
+ norace bool m_broadcastRxPending;
+ norace ieee154_macMaxFrameTotalWaitTime_t m_macMaxFrameTotalWaitTime;
+
+ uint16_t generateRandomBackoff(uint8_t BE);
+ 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();
+
+ command error_t Reset.init()
+ {
+ if (call Token.isOwner()){
+ call Leds.led0On(); // internal error
+ return FAIL;
+ }
+ if (m_currentFrame)
+ signal CapTx.transmitDone(m_currentFrame, IEEE154_TRANSACTION_OVERFLOW);
+ if (m_lastFrame)
+ signal CapTx.transmitDone(m_lastFrame, IEEE154_TRANSACTION_OVERFLOW);
+ if (m_bcastFrame)
+ signalTxBroadcastDone(m_bcastFrame, IEEE154_TRANSACTION_OVERFLOW);
+ m_currentFrame = m_lastFrame = m_bcastFrame = NULL;
+ m_macMaxFrameTotalWaitTime = call MLME_GET.macMaxFrameTotalWaitTime();
+ stopAllAlarms();
+ return SUCCESS;
+ }
+
+ async event void TokenTransferred.transferred()
+ {
+ // we got the token, i.e. CAP has just started
+ uint32_t actualCapLen = call CapLen.getNow();
+ if (actualCapLen < IEEE154_RADIO_GUARD_TIME){
+ call Debug.log(LEVEL_IMPORTANT, CapP_TOO_SHORT, superframeDirection, actualCapLen, IEEE154_RADIO_GUARD_TIME);
+ call TokenToCfp.transfer();
+ return;
+ } else {
+ actualCapLen -= IEEE154_RADIO_GUARD_TIME;
+ if (DEVICE_ROLE)
+ m_broadcastRxPending = call IsRxBroadcastPending.getNow();
+ else {
+ // COORD_ROLE
+ if (m_bcastFrame != NULL) {
+ // we have to transmit a broadcast frame immediately; this
+ // (possibly) requires 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();
+ }
+ }
+ call CapEndAlarm.startAt(call CapStart.getNow(), actualCapLen);
+ if (call IsBLEActive.getNow())
+ call BLEAlarm.startAt(call CapStart.getNow(), call BLELen.getNow());
+ call Debug.log(LEVEL_IMPORTANT, CapP_SET_CAP_END, call CapStart.getNow(), actualCapLen, call CapStart.getNow()+ actualCapLen);
+ }
+ updateState();
+ }
+
+ command ieee154_status_t CapTx.transmit(ieee154_txframe_t *frame)
+ {
+ // this frame (DATA or COMMAND) should be transmitted in the CAP
+ if (m_currentFrame != NULL)
+ return IEEE154_TRANSACTION_OVERFLOW;
+ else {
+ setCurrentFrame(frame);
+ 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_allowedBackoffs will be decreased in every iteration (at zero the transmission failed)
+ m_allowedBackoffs = call MLME_GET.macMaxCSMABackoffs();
+ m_macMaxBE = call MLME_GET.macMaxBE();
+ m_BE = call MLME_GET.macMinBE();
+ if (call MLME_GET.macBattLifeExt() && m_BE > 2)
+ m_BE = 2;
+ m_transactionTime = IEEE154_SHR_DURATION +
+ (frame->headerLen + frame->payloadLen) * IEEE154_SYMBOLS_PER_OCTET;
+ if (frame->header->mhr[0] & FC1_ACK_REQUEST)
+ m_transactionTime += (IEEE154_aTurnaroundTime + IEEE154_aUnitBackoffPeriod +
+ 11 * IEEE154_SYMBOLS_PER_OCTET);
+ if (frame->headerLen + frame->payloadLen > IEEE154_aMaxSIFSFrameSize)
+ m_transactionTime += call MLME_GET.macMinLIFSPeriod();
+ else
+ m_transactionTime += call MLME_GET.macMinSIFSPeriod();
+ m_backoff = generateRandomBackoff(m_BE) * IEEE154_aUnitBackoffPeriod; // initial backoff
+ m_macMaxFrameTotalWaitTime = call MLME_GET.macMaxFrameTotalWaitTime();
+ m_backoffElapsed = 0;
+ m_currentFrame = frame;
+ }
+
+ uint16_t generateRandomBackoff(uint8_t BE)
+ {
+ // return random number from [0,(2^BE) - 1] (uniform distr.)
+ uint16_t res = call Random.rand16();
+ uint16_t mask = 0xFFFF;
+ mask <<= BE;
+ mask = ~mask;
+ res &= mask;
+ return res;
+ }
+
+ void stopAllAlarms()
+ {
+ call CapEndAlarm.stop();
+ if (DEVICE_ROLE){
+ call IndirectTxWaitAlarm.stop();
+ call BroadcastAlarm.stop();
+ }
+ call BLEAlarm.stop();
+ }
+
+ /**
+ * The updateState() function is called whenever some event happened that
+ * might require a state change; 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, e.g. it first always checks whether
+ * the CAP is still active. Calling this function more than necessary can do
+ * no harm, but it SHOULD be called whenever an event happened that might
+ * lead to a state change.
+ */
+
+ void updateState()
+ {
+ error_t result = SUCCESS;
+ 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 (no loops, etc.)
+ if (m_lock || !call Token.isOwner())
+ return;
+ m_lock = TRUE; // lock
+
+ // Check 1: has the CAP finished?
+ if (call TimeCalc.hasExpired(call CapStart.getNow(), call CapLen.getNow()-IEEE154_RADIO_GUARD_TIME) ||
+ !call CapEndAlarm.isRunning()){
+ if (call RadioOff.isOff()) {
+ stopAllAlarms(); // may still fire, 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
+ 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
+ next = tryReceive(BROADCAST_ALARM);
+ } else if (COORD_ROLE && m_bcastFrame){
+ 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) {
+ next = tryReceive(INDIRECT_TX_ALARM);
+ }
+
+ // Check 4: is some other operation (like MLME-SCAN or MLME-RESET) pending?
+ else if (call IsTokenRequested.getNow()) {
+ if (call RadioOff.isOff()) {
+ stopAllAlarms(); // may still fire, locked through isOwner()
+ call Token.release();
+ next = DO_NOTHING;
+ } else
+ next = SWITCH_OFF;
+ }
+
+ // Check 5: is battery life extension (BLE) active and
+ // has the BLE period expired?
+ else if (call IsBLEActive.getNow() &&
+ call TimeCalc.hasExpired(call CapStart.getNow(), call BLELen.getNow()) &&
+ !call IsRxEnableActive.getNow()) {
+ next = trySwitchOff();
+ }
+
+ // Check 6: is there a frame ready to transmit?
+ else if (m_currentFrame != NULL) {
+ next = tryTransmit();
+ }
+
+ // Check 7: should we be in receive mode?
+ else if (COORD_ROLE || call IsRxEnableActive.getNow()) {
+ next = tryReceive(NO_ALARM);
+ if (next == DO_NOTHING && call IsRxEnableActive.getNow()){
+ // 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 8: just make sure the radio is switched off
+ else {
+ next = trySwitchOff();
+ }
+
+ // 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: result = call RadioOff.off(); break;
+ case LOAD_TX: result = call RadioTx.load(m_currentFrame); break;
+ case PREPARE_RX: result = call RadioRx.prepare(); break;
+ case WAIT_FOR_TXDONE: break;
+ case DO_NOTHING: break;
+ }
+ if (result != SUCCESS)
+ call Leds.led0On(); // internal error: could not update state !!!
+ }
+
+ next_state_t tryTransmit()
+ {
+ // tries to transmit m_currentFrame using the configuration stored
+ // in other module variables (m_backoff, etc.)
+ next_state_t next;
+ if (call RadioTx.getLoadedFrame() == m_currentFrame){
+ // the frame is already loaded -> transmit it now (if there's enough time)
+ uint32_t capLen = call CapLen.getNow(), capStart = call CapStart.getNow();
+ uint32_t elapsed, totalTime;
+ totalTime = IEEE154_RADIO_TX_SEND_DELAY +
+ m_backoff - m_backoffElapsed + m_transactionTime + IEEE154_RADIO_GUARD_TIME;
+ if (totalTime > capLen)
+ totalTime = capLen; // CAP is too short
+ elapsed = call TimeCalc.timeElapsed(capStart, call CapEndAlarm.getNow());
+ elapsed += (20 - (elapsed % 20)); // round to backoff boundary
+ if (!call TimeCalc.hasExpired(capStart, capLen - totalTime)){
+ call RadioTx.transmit(call CapStartRefTime.getNow(),
+ elapsed + IEEE154_RADIO_TX_SEND_DELAY + m_backoff - m_backoffElapsed,
+ 2,
+ m_currentFrame->header->mhr[0] & FC1_ACK_REQUEST ? TRUE : FALSE);
+ next = WAIT_FOR_TXDONE; // ATTENTION: this will NOT clear the lock
+ } else {
+ // frame does not fit in remaing portion of the CAP
+ if (elapsed < call CapLen.getNow()){
+ m_backoffElapsed += call CapLen.getNow() - elapsed;
+ if (m_backoffElapsed > m_backoff)
+ m_backoffElapsed = m_backoff;
+ }
+ next = SWITCH_OFF;
+ }
+ } else {
+ // the frame to transmit has not yet been loaded -> load it now
+ if (!call RadioOff.isOff())
+ next = SWITCH_OFF;
+ else {
+ if (m_lastFrame){
+ // we just transmitted a frame and have not yet
+ // signalled the done to the upper layer -> wait
+ next = DO_NOTHING;
+ } else
+ next = LOAD_TX;
+ }
+ }
+ return next;
+ }
+
+ next_state_t tryReceive(rx_alarm_t alarmType)
+ {
+ next_state_t next;
+ if (call RadioRx.isReceiving()){
+ next = DO_NOTHING;
+ } else if (call RadioRx.isPrepared()){
+ call RadioRx.receive(NULL, 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 = DO_NOTHING;
+ } else if (call RadioOff.isOff())
+ next = PREPARE_RX;
+ else
+ next = SWITCH_OFF;
+ 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 RadioTx.loadDone(){ m_lock = FALSE; updateState();}
+ async event void RadioOff.offDone(){ m_lock = FALSE; updateState();}
+ async event void RadioRx.prepareDone(){ m_lock = FALSE; updateState();}
+
+ async event void CapEndAlarm.fired(){
+ call Debug.log(LEVEL_IMPORTANT, CapP_CAP_END_FIRED, superframeDirection, 0, 0);
+ 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 RadioTx.transmitDone(ieee154_txframe_t *frame,
+ ieee154_reftime_t *referenceTime, bool ackPendingFlag, error_t error)
+ {
+ switch (error)
+ {
+ case SUCCESS:
+ m_result = IEEE154_SUCCESS;
+ if (DEVICE_ROLE && frame->payload[0] == CMD_FRAME_DATA_REQUEST &&
+ ((frame->header->mhr[MHR_INDEX_FC1]) & FC1_FRAMETYPE_MASK) == FC1_FRAMETYPE_CMD){
+ // just transmitted a data request frame
+ m_result = 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;
+ if (call RadioRx.prepare() != SUCCESS) // SHOULD succeed
+ call RadioOff.off();
+ return;
+ }
+ }
+ break;
+ case EBUSY:
+ m_result = IEEE154_CHANNEL_ACCESS_FAILURE;
+ if (m_allowedBackoffs > 0){
+ m_allowedBackoffs -= 1;
+ m_BE += 1;
+ if (m_BE > m_macMaxBE)
+ m_BE = m_macMaxBE;
+ m_backoff = generateRandomBackoff(m_BE) * IEEE154_aUnitBackoffPeriod; // next backoff
+ m_backoffElapsed = 0;
+ m_lock = FALSE;
+ updateState();
+ return;
+ }
+ break;
+ case ENOACK:
+ m_result = IEEE154_NO_ACK;
+ break;
+ default: break;
+ }
+ if (COORD_ROLE && frame == m_bcastFrame){
+ // signal result of broadcast transmissions immediately
+ restoreFrameFromBackup();
+ signalTxBroadcastDone(m_bcastFrame, m_result);
+ m_bcastFrame = NULL;
+ } else {
+ m_lastFrame = m_currentFrame;
+ m_currentFrame = NULL;
+ post signalTxDoneTask();
+ }
+ m_lock = FALSE;
+ updateState();
+ }
+
+ task void signalTxDoneTask()
+ {
+ ieee154_txframe_t *lastFrame = m_lastFrame;
+ m_lastFrame = NULL; // only now can a next transmission begin
+ m_indirectTxPending = FALSE;
+ if (lastFrame)
+ signal CapTx.transmitDone(lastFrame, m_result);
+ updateState();
+ }
+
+ event message_t* RadioRx.received(message_t* frame, ieee154_reftime_t *timestamp)
+ {
+ // received a frame during CAP - find out frame type and
+ // signal it to corresponding 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_result = 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_BE, m_allowedBackoffs,
+ m_macMaxBE, m_backoff, m_backoffElapsed, m_transactionTime};
+ call FrameBackup.setNow(&backup);
+ }
+
+ void restoreFrameFromBackup()
+ {
+ ieee154_cap_frame_backup_t *backup = call FrameRestore.getNow();
+ if (backup != NULL){
+ m_currentFrame = backup->frame;
+ m_BE = backup->BE;
+ m_allowedBackoffs = backup->allowedBackoffs;
+ m_macMaxBE = backup->macMaxBE;
+ m_backoff = backup->backoff;
+ m_backoffElapsed = backup->backoffElapsed;
+ 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 be 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 {
+ call Leds.led0On();
+ 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);
+ }
+
+ async event void TokenRequested.requested() {}
+ async event void TokenRequested.immediateRequested() {}
+ event void Token.granted(){}
+
+ default event void CapTx.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){call Leds.led0On();}
+ default async command void IndirectTxWaitAlarm.stop(){call Leds.led0On();}
+ default async command void IndirectTxWaitAlarm.startAt(uint32_t t0, uint32_t dt){call Leds.led0On();}
+
+ default async command void BroadcastAlarm.start(uint32_t dt){call Leds.led0On();}
+ default async command void BroadcastAlarm.stop(){call Leds.led0On();}
+ default async command void BroadcastAlarm.startAt(uint32_t t0, uint32_t dt){call Leds.led0On();}
+
+ default async command bool IsRxBroadcastPending.getNow(){ 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;}
+
+ command error_t WasRxEnabled.enable(){return FAIL;}
+ command error_t WasRxEnabled.disable(){return FAIL;}
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+#include "TKN154_MAC.h"
+generic module CapQueueP() {
+ provides
+ {
+ interface Init as Reset;
+ interface FrameTx[uint8_t client];
+ interface FrameRx as FrameExtracted[uint8_t client];
+ interface Purge;
+ } uses {
+ interface Queue<ieee154_txframe_t*>;
+ interface FrameTx as CapTx;
+ interface FrameRx as SubFrameExtracted;
+ }
+}
+implementation
+{
+ task void tryCapTxTask();
+ bool m_busy;
+ uint8_t m_client;
+
+ 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);
+ }
+ m_busy = FALSE;
+ return SUCCESS;
+ }
+
+ command ieee154_status_t FrameTx.transmit[uint8_t client](ieee154_txframe_t *txFrame)
+ {
+ txFrame->client = client;
+ if (call Queue.enqueue(txFrame) != SUCCESS)
+ return IEEE154_TRANSACTION_OVERFLOW;
+ else {
+ post tryCapTxTask();
+ return IEEE154_SUCCESS;
+ }
+ }
+
+ task void tryCapTxTask()
+ {
+ if (!m_busy && call Queue.size()){
+ ieee154_txframe_t *txFrame = call Queue.head();
+ if (txFrame->headerLen == 0){
+ // was purged
+ call Queue.dequeue();
+ signal Purge.purgeDone(txFrame, IEEE154_SUCCESS);
+ post tryCapTxTask();
+ }
+ m_client = txFrame->client;
+ if (call CapTx.transmit(txFrame) == IEEE154_SUCCESS){
+ m_busy = TRUE;
+ }
+ }
+ }
+
+ event void CapTx.transmitDone(ieee154_txframe_t *txFrame, ieee154_status_t status)
+ {
+ call Queue.dequeue();
+ m_busy = FALSE;
+ signal FrameTx.transmitDone[txFrame->client](txFrame, status);
+ post tryCapTxTask();
+ }
+
+ event message_t* SubFrameExtracted.received(message_t* frame)
+ {
+ // this event is signalled when a frame has been received
+ // in response to a data request command frame. The transmitDone
+ // event will be signalled later
+ return signal FrameExtracted.received[m_client](frame);
+ }
+
+ 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;
+ }
+ }
+ }
+ return IEEE154_INVALID_HANDLE;
+ }
+
+ default event void Purge.purgeDone(ieee154_txframe_t *txFrame, ieee154_status_t status){}
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+/* This component is responsible for sending broadcast frames from
+ * a coordinator to devices.
+ **/
+
+#include "TKN154_MAC.h"
+module CoordBroadcastP
+{
+ provides
+ {
+ interface Init as Reset;
+ interface FrameTx as BroadcastDataFrame;
+ interface FrameTx as RealignmentTx;
+ interface GetNow<bool> as IsBroadcastReady;
+ } uses {
+ interface Queue<ieee154_txframe_t*>;
+ interface FrameTxNow as CapTransmitNow;
+ interface ResourceTransfer as TokenToCap;
+ interface ResourceTransferred as TokenTransferred;
+ interface GetNow<bool> as BeaconFramePendingBit;
+ interface Leds;
+ }
+}
+implementation
+{
+ norace bool m_lock;
+ norace ieee154_txframe_t *m_realignmentFrame;
+ norace ieee154_txframe_t *m_queueHead;
+ norace ieee154_txframe_t *m_transmittedFrame;
+ norace ieee154_status_t m_status;
+
+ task void transmitNowDoneTask();
+
+ command error_t Reset.init()
+ {
+ while (call Queue.size())
+ signal BroadcastDataFrame.transmitDone(call Queue.dequeue(), IEEE154_TRANSACTION_OVERFLOW);
+ if (m_realignmentFrame)
+ signal RealignmentTx.transmitDone(m_realignmentFrame, IEEE154_TRANSACTION_OVERFLOW);
+ m_realignmentFrame = m_queueHead = m_transmittedFrame = NULL;
+ m_lock = FALSE;
+ return SUCCESS;
+ }
+
+ command ieee154_status_t BroadcastDataFrame.transmit(ieee154_txframe_t *txFrame)
+ {
+ if (call Queue.enqueue(txFrame) != SUCCESS)
+ return IEEE154_TRANSACTION_OVERFLOW;
+ atomic {
+ if (m_queueHead == NULL)
+ m_queueHead = call Queue.head();
+ }
+ return IEEE154_SUCCESS;
+ }
+
+ command ieee154_status_t RealignmentTx.transmit(ieee154_txframe_t *frame)
+ {
+ atomic {
+ if (!m_realignmentFrame){
+ m_realignmentFrame = frame;
+ return IEEE154_SUCCESS;
+ } else
+ return IEEE154_TRANSACTION_OVERFLOW;
+ }
+ }
+
+ async command bool IsBroadcastReady.getNow()
+ {
+ if (m_lock)
+ return FALSE;
+ else
+ return (m_realignmentFrame != NULL || m_queueHead != NULL);
+ }
+
+ async event void TokenTransferred.transferred()
+ {
+ // 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();
+ }
+
+ async event void CapTransmitNow.transmitNowDone(ieee154_txframe_t *txFrame, ieee154_status_t status)
+ {
+ m_transmittedFrame = txFrame;
+ m_status = status;
+ post transmitNowDoneTask();
+ }
+
+ task void transmitNowDoneTask()
+ {
+ 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();
+ signal BroadcastDataFrame.transmitDone(m_transmittedFrame, m_status);
+ }
+ m_lock = FALSE;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+/* "The coordinator realignment command is sent by the PAN coordinator or a
+ * coordinator either following the reception of an orphan notification command
+ * from a device that is recognized to be on its PAN or when any of its PAN
+ * configuration attributes change due to the receipt of an MLME-START.request
+ * primitive." IEEE 802.15.4-2006, Sec. 7.3.8 **/
+
+#include "TKN154_MAC.h"
+module CoordRealignmentP
+{
+ provides
+ {
+ interface Init;
+ interface MLME_ORPHAN;
+ interface MLME_COMM_STATUS;
+ interface GetSet<ieee154_txframe_t*> as GetSetRealignmentFrame;
+ }
+ uses
+ {
+ interface FrameTx as CoordRealignmentTx;
+ interface FrameRx as OrphanNotificationRx;
+ interface FrameUtility;
+ interface MLME_GET;
+ interface IEEE154Frame as Frame;
+ interface Pool<ieee154_txframe_t> as TxFramePool;
+ interface Pool<ieee154_txcontrol_t> as TxControlPool;
+ interface Get<uint64_t> as LocalExtendedAddress;
+ }
+}
+implementation
+{
+ enum {
+ ORPHAN_RESPONSE,
+ BEACON_REALIGNMENT,
+ };
+ uint8_t m_payload[9];
+ bool m_busy = FALSE;
+ void destroyRealignmentFrame(ieee154_txframe_t *frame);
+ ieee154_txframe_t *newRealignmentFrame(uint8_t type, ieee154_address_t *dstAddress);
+
+ command error_t Init.init()
+ {
+ return SUCCESS;
+ }
+
+ command ieee154_txframe_t* GetSetRealignmentFrame.get()
+ {
+ ieee154_address_t bcastAddr;
+ bcastAddr.shortAddress = 0xFFFF;
+ return newRealignmentFrame(BEACON_REALIGNMENT, &bcastAddr);
+ }
+
+ command void GetSetRealignmentFrame.set(ieee154_txframe_t* frame)
+ {
+ destroyRealignmentFrame(frame);
+ }
+
+ event message_t* OrphanNotificationRx.received(message_t* frame)
+ {
+ ieee154_address_t srcAddress;
+ if (call Frame.getSrcAddrMode(frame) == ADDR_MODE_EXTENDED_ADDRESS &&
+ call Frame.getSrcAddr(frame, &srcAddress) == SUCCESS)
+ signal MLME_ORPHAN.indication (
+ srcAddress.extendedAddress,
+ NULL // security
+ );
+ return frame;
+ }
+
+ command ieee154_status_t MLME_ORPHAN.response (
+ uint64_t OrphanAddress,
+ uint16_t ShortAddress,
+ bool AssociatedMember,
+ ieee154_security_t *security
+ )
+ {
+ ieee154_txframe_t *txFrame;
+ ieee154_status_t txStatus;
+ ieee154_address_t dstAddress;
+
+ dstAddress.extendedAddress = OrphanAddress;
+ if (!AssociatedMember)
+ txStatus = IEEE154_SUCCESS;
+ else if (m_busy || (txFrame = newRealignmentFrame(ORPHAN_RESPONSE, &dstAddress)) != NULL)
+ txStatus = IEEE154_TRANSACTION_OVERFLOW;
+ else {
+ m_busy = TRUE;
+ txFrame->payload[0] = CMD_FRAME_COORDINATOR_REALIGNMENT;
+ *((nxle_uint16_t*) &txFrame->payload[1]) = call MLME_GET.macPANId();
+ *((nxle_uint16_t*) &txFrame->payload[3]) = call MLME_GET.macShortAddress();
+ txFrame->payload[5] = call MLME_GET.phyCurrentChannel();
+ *((nxle_uint16_t*) &txFrame->payload[6]) = ShortAddress;
+ txFrame->payloadLen = 8;
+ if ((txStatus = call CoordRealignmentTx.transmit(txFrame)) != IEEE154_SUCCESS){
+ m_busy = FALSE;
+ destroyRealignmentFrame(txFrame);
+ }
+ }
+ return txStatus;
+ }
+
+ ieee154_txframe_t *newRealignmentFrame(uint8_t type, ieee154_address_t *dstAddress)
+ {
+ ieee154_txframe_t *txFrame = NULL;
+ ieee154_txcontrol_t *txControl;
+ uint8_t dstAddrMode;
+ ieee154_address_t srcAddress;
+
+ if ((txFrame = call TxFramePool.get()) != NULL){
+ if ((txControl = call TxControlPool.get()) == NULL){
+ call TxFramePool.put(txFrame);
+ txFrame = NULL;
+ } else {
+ txFrame->header = &txControl->header;
+ txFrame->metadata = &txControl->metadata;
+ txFrame->payload = m_payload;
+ 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;
+ txFrame->header->mhr[MHR_INDEX_FC1] |= FC1_ACK_REQUEST;
+ } else {
+ txFrame->header->mhr[MHR_INDEX_FC2] |= FC2_DEST_MODE_SHORT;
+ dstAddrMode = ADDR_MODE_SHORT_ADDRESS;
+ }
+ srcAddress.extendedAddress = call LocalExtendedAddress.get();
+ txFrame->headerLen = call FrameUtility.writeHeader(
+ txFrame->header->mhr,
+ dstAddrMode,
+ 0xFFFF,
+ dstAddress,
+ ADDR_MODE_EXTENDED_ADDRESS,
+ call MLME_GET.macPANId(),
+ &srcAddress,
+ FALSE);
+ }
+ }
+ return txFrame;
+ }
+
+ void destroyRealignmentFrame(ieee154_txframe_t *frame)
+ {
+ call TxControlPool.put((ieee154_txcontrol_t*) ((uint8_t*) frame->header - offsetof(ieee154_txcontrol_t, header)));
+ call TxFramePool.put(frame);
+ }
+
+
+ event void CoordRealignmentTx.transmitDone(ieee154_txframe_t *txFrame, ieee154_status_t status)
+ {
+ uint8_t *mhr = MHR(txFrame);
+ 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]);
+ signal MLME_COMM_STATUS.indication (
+ *((nxle_uint16_t*) &txFrame->payload[1]), // PANId
+ ADDR_MODE_EXTENDED_ADDRESS, // SrcAddrMode
+ srcAddr,
+ ADDR_MODE_EXTENDED_ADDRESS, // DstAddrMode
+ dstAddr,
+ status,
+ NULL //security
+ );
+ call TxControlPool.put((ieee154_txcontrol_t*) ((uint8_t*) txFrame->header - offsetof(ieee154_txcontrol_t, header)));
+ call TxFramePool.put(txFrame);
+ m_busy = FALSE;
+ }
+ }
+
+ default event void MLME_COMM_STATUS.indication (
+ uint16_t PANId,
+ uint8_t SrcAddrMode,
+ ieee154_address_t SrcAddr,
+ uint8_t DstAddrMode,
+ ieee154_address_t DstAddr,
+ ieee154_status_t status,
+ ieee154_security_t *security
+ ){}
+
+ default event void MLME_ORPHAN.indication (
+ uint64_t OrphanAddress,
+ ieee154_security_t *security
+ ){}
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+#include "TKN154_MAC.h"
+
+module DataP
+{
+ provides
+ {
+ interface Init;
+ interface MCPS_DATA;
+ interface MCPS_PURGE;
+ } uses {
+ interface Get<bool> as IsSendingBeacons;
+ interface FrameRx as CoordCapRx;
+ interface FrameTx as DeviceCapTx;
+ interface FrameTx as CoordCapTx;
+ interface FrameTx as BroadcastTx;
+ interface FrameRx as DeviceCapRx;
+ interface Pool<ieee154_txframe_t> as TxFramePool;
+ interface FrameTx as DeviceCfpTx;
+ interface FrameTx as CoordCfpTx;
+ interface FrameTx as IndirectTx;
+ interface FrameRx as CoordCfpRx;
+ interface FrameRx as DeviceCfpRx;
+ interface FrameUtility;
+ interface Purge as PurgeDirect;
+ interface Purge as PurgeIndirect;
+ interface Purge as PurgeGtsDevice;
+ interface Purge as PurgeGtsCoord;
+ interface MLME_GET;
+ interface Leds;
+ interface Packet;
+ interface IEEE154Frame as Frame;
+ interface Get<uint64_t> as LocalExtendedAddress;
+ }
+}
+implementation
+{
+ message_t* dataReceived(message_t* frame);
+ void finishTxTransaction(ieee154_txframe_t *txFrame, ieee154_status_t status);
+
+ command error_t Init.init()
+ {
+ return SUCCESS;
+ }
+
+ command ieee154_status_t MCPS_DATA.request (
+ message_t *frame,
+ uint8_t payloadLen,
+ uint8_t msduHandle,
+ uint8_t txOptions
+ )
+ {
+ uint8_t srcAddrMode = call Frame.getSrcAddrMode(frame);
+ uint8_t dstAddrMode = call Frame.getDstAddrMode(frame);
+ ieee154_address_t dstAddr;
+ ieee154_status_t txStatus;
+ ieee154_txframe_t *txFrame;
+ uint8_t sfType=0;
+ uint8_t *mhr;
+
+ if (payloadLen > call Packet.maxPayloadLength())
+ txStatus = IEEE154_INVALID_PARAMETER;
+ else if ((!srcAddrMode && !dstAddrMode) ||
+ (srcAddrMode > ADDR_MODE_EXTENDED_ADDRESS || dstAddrMode > ADDR_MODE_EXTENDED_ADDRESS) ||
+ (srcAddrMode == ADDR_MODE_RESERVED || dstAddrMode == ADDR_MODE_RESERVED))
+ txStatus = IEEE154_INVALID_ADDRESS;
+ else if (!(txFrame = call TxFramePool.get()))
+ txStatus = IEEE154_TRANSACTION_OVERFLOW;
+ else {
+ // construct the DATA frame
+ txFrame->header = &((message_header_t*) frame->header)->ieee154;
+ txFrame->payload = (uint8_t*) frame->data;
+ txFrame->metadata = &((message_metadata_t*) frame->metadata)->ieee154;
+ txFrame->payloadLen = payloadLen;
+ mhr = txFrame->header->mhr;
+ txFrame->headerLen = call Frame.getHeaderLength(frame);
+ mhr[MHR_INDEX_FC1] &= ~(FC1_FRAMETYPE_MASK | FC1_FRAME_PENDING | FC1_ACK_REQUEST);
+ mhr[MHR_INDEX_FC1] |= FC1_FRAMETYPE_DATA;
+ if (txOptions & TX_OPTIONS_ACK)
+ mhr[MHR_INDEX_FC1] |= FC1_ACK_REQUEST;
+ mhr[MHR_INDEX_FC2] &= ~FC2_FRAME_VERSION_MASK;
+ if (payloadLen > IEEE154_aMaxMACSafePayloadSize)
+ mhr[MHR_INDEX_FC2] |= FC2_FRAME_VERSION_1;
+ txFrame->handle = msduHandle;
+
+ // in case a node is both, coordinator and device (e.g. in a
+ // cluster-tree topology), it has to be decided whether the frame
+ // is to be sent in the incoming or outgoing superframe (sf);
+ // we do this by comparing the destination address to the
+ // coordinator address in the PIB, if they match the frame is
+ // 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;
+ else
+ sfType = OUTGOING_SUPERFRAME;
+ } else if (dstAddrMode == ADDR_MODE_NOT_PRESENT) // to PAN Coord
+ sfType = INCOMING_SUPERFRAME;
+
+ // GTS?
+ if (txOptions & TX_OPTIONS_GTS){
+ if (sfType == INCOMING_SUPERFRAME)
+ txStatus = call DeviceCfpTx.transmit(txFrame);
+ else
+ txStatus = call CoordCfpTx.transmit(txFrame);
+
+ // indirect transmission?
+ } else if ((txOptions & TX_OPTIONS_INDIRECT) &&
+ call IsSendingBeacons.get() &&
+ (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);
+ } else
+ txStatus = call IndirectTx.transmit(txFrame);
+
+ // transmission in the CAP
+ } else
+ if (sfType == INCOMING_SUPERFRAME)
+ txStatus = call DeviceCapTx.transmit(txFrame);
+ else
+ txStatus = call CoordCapTx.transmit(txFrame);
+
+ if (txStatus != IEEE154_SUCCESS){
+ call TxFramePool.put(txFrame);
+ }
+ }
+ return txStatus;
+ }
+
+ command ieee154_status_t MCPS_PURGE.request (
+ uint8_t msduHandle
+ )
+ {
+ if (call PurgeDirect.purge(msduHandle) == IEEE154_SUCCESS ||
+ call PurgeIndirect.purge(msduHandle) == IEEE154_SUCCESS ||
+ call PurgeGtsDevice.purge(msduHandle) == IEEE154_SUCCESS ||
+ call PurgeGtsCoord.purge(msduHandle) == IEEE154_SUCCESS)
+ return IEEE154_SUCCESS;
+ else
+ return IEEE154_INVALID_HANDLE;
+ }
+
+ event void PurgeDirect.purgeDone(ieee154_txframe_t *data, ieee154_status_t status)
+ {
+ finishTxTransaction(data, status);
+ }
+
+ event void PurgeIndirect.purgeDone(ieee154_txframe_t *data, ieee154_status_t status)
+ {
+ finishTxTransaction(data, status);
+ }
+
+ event void PurgeGtsDevice.purgeDone(ieee154_txframe_t *data, ieee154_status_t status)
+ {
+ finishTxTransaction(data, status);
+ }
+
+ event void PurgeGtsCoord.purgeDone(ieee154_txframe_t *data, ieee154_status_t status)
+ {
+ finishTxTransaction(data, status);
+ }
+
+ event message_t* CoordCfpRx.received(message_t* frame)
+ {
+ return dataReceived(frame);
+ }
+
+ event message_t* DeviceCfpRx.received(message_t* frame)
+ {
+ return dataReceived(frame);
+ }
+
+ event message_t* CoordCapRx.received(message_t* frame)
+ {
+ return dataReceived(frame);
+ }
+
+ event message_t* DeviceCapRx.received(message_t* frame)
+ {
+ return dataReceived(frame);
+ }
+
+ message_t* dataReceived(message_t* frame)
+ {
+ return signal MCPS_DATA.indication( frame );
+ }
+
+ void finishTxTransaction(ieee154_txframe_t *txFrame, ieee154_status_t status)
+ {
+ uint8_t handle = txFrame->handle;
+ 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);
+ }
+
+ event void BroadcastTx.transmitDone(ieee154_txframe_t *txFrame, ieee154_status_t status)
+ {
+ finishTxTransaction(txFrame, status);
+ }
+
+ event void DeviceCapTx.transmitDone(ieee154_txframe_t *txFrame, ieee154_status_t status)
+ {
+ finishTxTransaction(txFrame, status);
+ }
+
+ event void CoordCapTx.transmitDone(ieee154_txframe_t *txFrame, ieee154_status_t status)
+ {
+ finishTxTransaction(txFrame, status);
+ }
+
+ event void DeviceCfpTx.transmitDone(ieee154_txframe_t *txFrame, ieee154_status_t status)
+ {
+ finishTxTransaction(txFrame, status);
+ }
+
+ event void CoordCfpTx.transmitDone(ieee154_txframe_t *txFrame, ieee154_status_t status)
+ {
+ finishTxTransaction(txFrame, status);
+ }
+
+
+ event void IndirectTx.transmitDone(ieee154_txframe_t *txFrame, ieee154_status_t status)
+ {
+ finishTxTransaction(txFrame, status);
+ }
+
+ default event void MCPS_DATA.confirm(
+ message_t *msg,
+ 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;}
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+#include "TKN154_MAC.h"
+#include "TKN154_DEBUG.h"
+module FrameDispatchImplP
+{
+ provides
+ {
+ interface RadioRx as MacRx[uint8_t client];
+ interface RadioTx as MacTx[uint8_t client];
+ interface RadioOff as MacRadioOff[uint8_t client];
+ } uses {
+ interface ArbiterInfo;
+ interface RadioRx as PhyRx;
+ interface RadioTx as PhyTx;
+ interface RadioOff as PhyRadioOff;
+ interface Get<bool> as RadioPromiscuousMode;
+ interface Leds;
+ interface Ieee802154Debug as Debug;
+ }
+}
+implementation
+{
+
+/* ----------------------- 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);
+ if (((mhr[1] & FC2_FRAME_VERSION_MASK) > FC2_FRAME_VERSION_1)
+ && (!call RadioPromiscuousMode.get()))
+ return msg;
+#ifndef IEEE154_SECURITY_ENABLED
+ if ((mhr[0] & FC1_SECURITY_ENABLED)
+ && (!call RadioPromiscuousMode.get()))
+ return msg;
+#endif
+ return signal MacRx.received[call ArbiterInfo.userId()](msg, timestamp);
+ }
+
+ async command bool MacRx.isReceiving[uint8_t client]()
+ {
+ if (client == call ArbiterInfo.userId())
+ 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 *referenceTime,
+ uint32_t timeOffset, uint8_t numCCA, bool ackRequest)
+ {
+ if (client == call ArbiterInfo.userId())
+ return call PhyTx.transmit(referenceTime, timeOffset, numCCA, ackRequest);
+ else {
+ call Leds.led0On();
+ return IEEE154_TRANSACTION_OVERFLOW;
+ }
+ }
+
+ async event void PhyTx.transmitDone(ieee154_txframe_t *frame,
+ ieee154_reftime_t *referenceTime, bool ackPendingFlag, error_t error)
+ {
+ signal MacTx.transmitDone[call ArbiterInfo.userId()](frame, referenceTime, ackPendingFlag, error);
+ }
+
+/* ----------------------- RadioOff ----------------------- */
+
+ async command error_t MacRadioOff.off[uint8_t client]()
+ {
+ if (client == call ArbiterInfo.userId())
+ return call PhyRadioOff.off();
+ else {
+ call Leds.led0On();
+ return EBUSY;
+ }
+ }
+
+ async event void PhyRadioOff.offDone()
+ {
+ signal MacRadioOff.offDone[call ArbiterInfo.userId()]();
+ }
+
+
+ async command bool MacRadioOff.isOff[uint8_t client]()
+ {
+ if (client == call ArbiterInfo.userId())
+ return call PhyRadioOff.isOff();
+ else
+ return EBUSY;
+ }
+
+/* ----------------------- Defaults ----------------------- */
+
+ default async event void MacTx.loadDone[uint8_t client]()
+ {
+ call Debug.log(LEVEL_CRITICAL, RadioRxTxP_DEFAULT_PREPARE_TX_DONE, 0, 0, 0);
+ }
+ default async event void MacTx.transmitDone[uint8_t client](ieee154_txframe_t *frame,
+ ieee154_reftime_t *referenceTime, bool ackPendingFlag, error_t error)
+ {
+ call Debug.log(LEVEL_CRITICAL, RadioRxTxP_DEFAULT_TX_DONE, 0, 0, 0);
+ }
+ default async event void MacRx.prepareDone[uint8_t client]()
+ {
+ call Debug.log(LEVEL_CRITICAL, RadioRxTxP_DEFAULT_PREPARE_RX_DONE, 0, 0, 0);
+ }
+ default event message_t* MacRx.received[uint8_t client](message_t *frame, ieee154_reftime_t *timestamp)
+ {
+ call Debug.log(LEVEL_INFO, RadioRxTxP_DEFAULT_RECEIVED, client, call ArbiterInfo.userId(), 0xff);
+ return frame;
+ }
+ default async event void MacRadioOff.offDone[uint8_t client]()
+ {
+ call Debug.log(LEVEL_CRITICAL, RadioRxTxP_DEFAULT_OFFDONE, 0, 0, 0);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+#include "TKN154_MAC.h"
+configuration FrameDispatchP
+{
+ provides
+ {
+ interface RadioRx as RadioRx[uint8_t client];
+ interface RadioTx as RadioTx[uint8_t client];
+ interface RadioOff as RadioOff[uint8_t client];
+ interface Resource as Token[uint8_t client];
+ interface ResourceRequested as TokenRequested[uint8_t client];
+ interface ResourceTransferControl as TokenTransferControl;
+ interface GetNow<bool> as IsResourceRequested;
+ interface Leds as LedsRadioClient;
+ } uses {
+ interface RadioRx as PhyRx;
+ interface RadioTx as PhyTx;
+ interface RadioOff as PhyRadioOff;
+ interface Get<bool> as RadioPromiscuousMode;
+ interface Leds;
+ interface Ieee802154Debug as Debug;
+ }
+}
+implementation
+{
+ components FrameDispatchImplP;
+ RadioRx = FrameDispatchImplP.MacRx;
+ RadioTx = FrameDispatchImplP.MacTx;
+ RadioOff = FrameDispatchImplP.MacRadioOff;
+ PhyRx = FrameDispatchImplP.PhyRx;
+ PhyTx = FrameDispatchImplP.PhyTx;
+ PhyRadioOff = FrameDispatchImplP.PhyRadioOff;
+ RadioPromiscuousMode = FrameDispatchImplP;
+ Leds = FrameDispatchImplP;
+ Debug = FrameDispatchImplP;
+ LedsRadioClient = Leds;
+
+ components new SimpleRoundRobinTransferArbiterC(IEEE802154_RADIO_RESOURCE) as Arbiter;
+ Token = Arbiter;
+ TokenRequested = Arbiter;
+ TokenTransferControl = Arbiter;
+ IsResourceRequested = Arbiter;
+ FrameDispatchImplP.ArbiterInfo -> Arbiter;
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+module IndirectTxP
+{
+ provides
+ {
+ interface Init as Reset;
+ interface FrameTx[uint8_t client];
+ interface WriteBeaconField as PendingAddrWrite;
+ interface Notify<bool> as PendingAddrSpecUpdated;
+ interface Purge;
+ }
+ uses
+ {
+ interface FrameTx as CoordCapTx;
+ interface FrameRx as DataRequestRx;
+ interface MLME_GET;
+ interface FrameUtility;
+ interface Timer<TSymbolIEEE802154> as IndirectTxTimeout;
+ interface TimeCalc;
+ interface Leds;
+ interface Ieee802154Debug as Debug;
+ }
+}
+implementation
+{
+ enum {
+ SEND_THIS_FRAME = 0x80,
+ NUM_MAX_PENDING = 7,
+ };
+
+ ieee154_txframe_t *m_txFrameTable[NUM_MAX_PENDING];
+ ieee154_txframe_t *m_pendingTxFrame;
+ uint8_t m_client;
+ uint8_t m_numTableEntries;
+ uint8_t m_numShortPending;
+ uint8_t m_numExtPending;
+ task void tryCoordCapTxTask();
+ void tryCoordCapTx();
+
+ command error_t Reset.init()
+ {
+ uint8_t i;
+ // CAP/Queue component is always reset first, i.e. there
+ // should be no outstanding frames
+ call IndirectTxTimeout.stop();
+ for (i=0; i<NUM_MAX_PENDING; i++)
+ if (m_txFrameTable[i] != NULL)
+ signal FrameTx.transmitDone[m_txFrameTable[i]->client](m_txFrameTable[i], IEEE154_TRANSACTION_OVERFLOW);
+ for (i=0; i<NUM_MAX_PENDING; i++)
+ m_txFrameTable[i] = NULL; // empty slot
+ m_pendingTxFrame = NULL;
+ m_numTableEntries = 0;
+ m_numShortPending = 0;
+ m_numExtPending = 0;
+ return SUCCESS;
+ }
+
+ uint32_t getPersistenceTime()
+ {
+ uint32_t persistenceTime;
+ persistenceTime = call MLME_GET.macTransactionPersistenceTime();
+ persistenceTime *= IEEE154_aBaseSuperframeDuration;
+ persistenceTime *= ((uint16_t) 1) << call MLME_GET.macBeaconOrder();
+ return persistenceTime;
+ }
+
+ command ieee154_status_t Purge.purge(uint8_t msduHandle)
+ {
+ return IEEE154_INVALID_HANDLE; // TODO
+ }
+
+ command uint8_t PendingAddrWrite.write(uint8_t *pendingAddrField, uint8_t maxlen)
+ {
+ // write the pending addr field (inside the beacon frame)
+ uint8_t i, j, k=0;
+ uint8_t *longAdrPtr[NUM_MAX_PENDING];
+ nxle_uint16_t *adrPtr;
+ ieee154_txframe_t *txFrame;
+ uint8_t len = call PendingAddrWrite.getLength();
+
+ if (len > maxlen)
+ return 0;
+ 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)
+ longAdrPtr[k++] = &(txFrame->header->mhr[MHR_INDEX_ADDRESS + sizeof(ieee154_macPANId_t)]);
+ }
+ for (i=0; i<m_numExtPending; i++)
+ for (j=0; j<8; j++)
+ pendingAddrField[1 + 2*m_numShortPending + i*8 + j] = longAdrPtr[i][j];
+ pendingAddrField[0] = m_numShortPending | (m_numExtPending << 4);
+ call Debug.log(LEVEL_INFO, IndirectTxP_BEACON_ASSEMBLY, len,0,0);
+ return len;
+ }
+
+ command uint8_t PendingAddrWrite.getLength()
+ {
+ return 1 + m_numShortPending * 2 + m_numExtPending * 8;
+ }
+
+ command ieee154_status_t FrameTx.transmit[uint8_t client](ieee154_txframe_t *txFrame)
+ {
+ // send a frame through indirect transmission
+ uint8_t i;
+ if (m_numTableEntries >= NUM_MAX_PENDING){
+ call Debug.log(LEVEL_IMPORTANT, IndirectTxP_OVERFLOW, 0,0,0);
+ return IEEE154_TRANSACTION_OVERFLOW;
+ }
+ txFrame->client = client;
+ txFrame->metadata->timestamp = call IndirectTxTimeout.getNow();
+ for (i=0; i<NUM_MAX_PENDING; i++)
+ if (!m_txFrameTable[i]) // there must be an empty slot
+ break;
+ m_txFrameTable[i] = txFrame;
+ m_numTableEntries += 1;
+ if ((txFrame->header->mhr[MHR_INDEX_FC2] & FC2_DEST_MODE_MASK) == FC2_DEST_MODE_SHORT)
+ m_numShortPending++;
+ else if ((txFrame->header->mhr[MHR_INDEX_FC2] & FC2_DEST_MODE_MASK) == FC2_DEST_MODE_EXTENDED)
+ m_numExtPending++;
+ if (!call IndirectTxTimeout.isRunning())
+ call IndirectTxTimeout.startOneShot(getPersistenceTime());
+ call Debug.log(LEVEL_INFO, IndirectTxP_NOTIFIED, 0,0,0);
+ signal PendingAddrSpecUpdated.notify(TRUE);
+ return IEEE154_SUCCESS;
+ }
+
+ event message_t* DataRequestRx.received(message_t* frame)
+ {
+ uint8_t i, j, srcAddressMode, dstAddressMode, *src;
+ uint8_t *mhr = MHR(frame);
+ uint8_t destMode = (mhr[1] & FC2_DEST_MODE_MASK);
+
+ // received a data request frame from a device
+ // have we got some pending data for it ?
+ if (!m_numTableEntries)
+ return frame;
+ srcAddressMode = (mhr[1] & FC2_SRC_MODE_MASK);
+ if (!(srcAddressMode & FC2_SRC_MODE_SHORT))
+ return frame; // no source address
+ src = mhr + MHR_INDEX_ADDRESS;
+ if (destMode == FC2_DEST_MODE_SHORT)
+ src += 4;
+ else if (destMode == FC2_DEST_MODE_EXTENDED)
+ src += 10;
+ 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;
+ else {
+ dstAddressMode = (m_txFrameTable[i]->header->mhr[1] & FC2_DEST_MODE_MASK);
+ if ((dstAddressMode << 4) != srcAddressMode)
+ continue;
+ else {
+ // we know: dstAddressMode IN [2,3]
+ uint8_t *dst = &(m_txFrameTable[i]->header->mhr[MHR_INDEX_ADDRESS]) + 2;
+ uint8_t len = ((srcAddressMode == FC2_SRC_MODE_SHORT) ? 2 : 8);
+ for (j=0; j<len; j++)
+ if (*dst != *src)
+ break;
+ if (j==len)
+ break; // match! break from outer loop
+ }
+ }
+ }
+ call Debug.log(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;
+ post tryCoordCapTxTask();
+ } else {
+ // TODO: send an empty data frame to the device
+ }
+ return frame;
+ }
+
+ void tryCoordCapTx()
+ {
+ // iterate over the queued frames and transmit them in the CAP
+ // (if they are marked for transmission)
+ uint8_t i;
+ if (!m_pendingTxFrame && 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(LEVEL_INFO, IndirectTxP_SEND_NOW, 0,0,0);
+ } else {
+ m_pendingTxFrame = 0;
+ post tryCoordCapTxTask();
+ }
+ return; // done - wait for txDone
+ }
+ }
+ }
+
+ task void tryCoordCapTxTask()
+ {
+ tryCoordCapTx();
+ }
+
+ event void IndirectTxTimeout.fired()
+ {
+ // a transaction has expired
+ uint32_t now = call IndirectTxTimeout.getNow(), dt=0;
+ uint32_t persistenceTime = getPersistenceTime();
+ uint8_t i;
+
+ 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;
+ m_txFrameTable[i] = NULL;
+ m_numTableEntries -= 1;
+ if ((txFrame->header->mhr[MHR_INDEX_FC2] & FC2_DEST_MODE_MASK) == FC2_DEST_MODE_SHORT)
+ m_numShortPending--;
+ else if ((txFrame->header->mhr[MHR_INDEX_FC2] & FC2_DEST_MODE_MASK) == FC2_DEST_MODE_EXTENDED)
+ m_numExtPending--;
+ 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;
+ call IndirectTxTimeout.startOneShot(persistenceTime - dt);
+ }
+ }
+
+ event void CoordCapTx.transmitDone(ieee154_txframe_t *txFrame, ieee154_status_t status)
+ {
+ uint8_t i;
+ for (i=0; i<NUM_MAX_PENDING; i++)
+ if (m_txFrameTable[i] == txFrame){
+ m_txFrameTable[i] = NULL; // slot is now empty
+ break;
+ }
+ signal PendingAddrSpecUpdated.notify(TRUE);
+ m_pendingTxFrame = NULL;
+ txFrame->client = m_client;
+ txFrame->client &= ~SEND_THIS_FRAME;
+ m_numTableEntries -= 1;
+ if ((txFrame->header->mhr[MHR_INDEX_FC2] & FC2_DEST_MODE_MASK) == FC2_DEST_MODE_SHORT)
+ m_numShortPending--;
+ else if ((txFrame->header->mhr[MHR_INDEX_FC2] & FC2_DEST_MODE_MASK) == FC2_DEST_MODE_EXTENDED)
+ m_numExtPending--;
+ signal FrameTx.transmitDone[txFrame->client](txFrame, status);
+ post tryCoordCapTxTask();
+ call Debug.log(LEVEL_INFO, IndirectTxP_SEND_DONE, status,m_numTableEntries,0);
+ }
+
+ 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){}
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+/* This component maintains the PIB (PAN Information Base) attributes and
+ * provides interfaces for accessing fields in a MAC frame. */
+
+#include "TKN154.h"
+#include "TKN154_PIB.h"
+#include "TKN154_PHY.h"
+
+module PibP {
+ provides
+ {
+ interface Init as LocalInit;
+ interface MLME_RESET;
+ interface MLME_GET;
+ interface MLME_SET;
+ interface Set<ieee154_macSuperframeOrder_t> as SetMacSuperframeOrder;
+ interface Set<ieee154_macBeaconTxTime_t> as SetMacBeaconTxTime;
+ interface Set<ieee154_macPanCoordinator_t> as SetMacPanCoordinator;
+ interface Get<ieee154_macPanCoordinator_t> as IsMacPanCoordinator;
+ interface Get<bool> as IsBeaconEnabledPAN;
+ interface FrameUtility;
+ interface IEEE154Frame as Frame;
+ interface IEEE154BeaconFrame as BeaconFrame;
+ interface Get<uint64_t> as GetLocalExtendedAddress;
+ interface Notify<const void*> as PIBUpdate[uint8_t PIBAttributeID];
+ interface Packet;
+ interface TimeCalc;
+ }
+ uses
+ {
+ interface Get<bool> as PromiscuousModeGet;
+ interface Init as CapReset;
+ interface Init as CapQueueReset;
+ interface Init as MacReset;
+ interface SplitControl as RadioControl;
+ interface Random;
+ interface Resource as Token;
+ interface RadioOff;
+ interface LocalTime<TSymbolIEEE802154>;
+ }
+}
+implementation
+{
+ ieee154_PIB_t m_pib;
+ uint8_t m_numResetClientPending;
+ bool m_setDefaultPIB;
+ uint8_t m_panType;
+ uint8_t m_resetSpin;
+
+#ifdef IEEE154_EXTENDED_ADDRESS
+ const uint64_t m_aExtendedAddressLE = IEEE154_EXTENDED_ADDRESS;
+#else
+ norace uint64_t m_aExtendedAddressLE;
+#endif
+ task void radioControlStopTask();
+ void updateMacMaxFrameTotalWaitTime();
+ void resetAttributesToDefault();
+ bool isLocalExtendedAddress(uint8_t *addrLE);
+ bool isCoordExtendedAddress(uint8_t *addrLE);
+ uint8_t getPendAddrSpecOffset(uint8_t *macPayloadField);
+ task void resetSpinTask();
+
+ command error_t LocalInit.init()
+ {
+#ifndef IEEE154_EXTENDED_ADDRESS
+ uint32_t *p = (uint32_t*) &m_aExtendedAddressLE;
+ *p++ = call Random.rand32();
+ *p = call Random.rand32();
+#endif
+ resetAttributesToDefault();
+ return SUCCESS;
+ }
+
+ void resetAttributesToDefault() {
+ m_pib.phyCurrentChannel = IEEE154_DEFAULT_CURRENTCHANNEL;
+ m_pib.phyTransmitPower = (IEEE154_TXPOWER_TOLERANCE | (IEEE154_DEFAULT_TRANSMITPOWER_dBm & 0x3F));
+ m_pib.phyCCAMode = IEEE154_DEFAULT_CCAMODE;
+ m_pib.phyCurrentPage = IEEE154_DEFAULT_CURRENTPAGE;
+
+ m_pib.macAssociatedPANCoord = IEEE154_DEFAULT_ASSOCIATEDPANCOORD;
+ m_pib.macAssociationPermit = IEEE154_DEFAULT_ASSOCIATIONPERMIT;
+ m_pib.macAutoRequest = IEEE154_DEFAULT_AUTOREQUEST;
+ m_pib.macBattLifeExt = IEEE154_DEFAULT_BATTLIFEEXT;
+ m_pib.macBeaconPayloadLength = IEEE154_DEFAULT_BEACONPAYLOADLENGTH;
+ m_pib.macBeaconOrder = IEEE154_DEFAULT_BEACONORDER;
+ m_pib.macBeaconTxTime = IEEE154_DEFAULT_BEACONTXTIME;
+ m_pib.macBSN = 0xFF & (call Random.rand16());
+ // macCoordExtendedAddress: default is undefined
+ m_pib.macCoordShortAddress = IEEE154_DEFAULT_COORDSHORTADDRESS;
+ m_pib.macDSN = 0xFF & (call Random.rand16());
+ m_pib.macGTSPermit = IEEE154_DEFAULT_GTSPERMIT;
+ m_pib.macMaxBE = IEEE154_DEFAULT_MAXBE;
+ m_pib.macMaxCSMABackoffs = IEEE154_DEFAULT_MAXCSMABACKOFFS;
+ m_pib.macMaxFrameRetries = IEEE154_DEFAULT_MAXFRAMERETRIES;
+ m_pib.macMinBE = IEEE154_DEFAULT_MINBE;
+ m_pib.macPANId = IEEE154_DEFAULT_PANID;
+ m_pib.macPromiscuousMode = IEEE154_DEFAULT_PROMISCUOUSMODE;
+ m_pib.macResponseWaitTime = IEEE154_DEFAULT_RESPONSEWAITTIME;
+ m_pib.macRxOnWhenIdle = IEEE154_DEFAULT_RXONWHENIDLE;
+ m_pib.macSecurityEnabled = IEEE154_DEFAULT_SECURITYENABLED;
+ m_pib.macShortAddress = IEEE154_DEFAULT_SHORTADDRESS;
+ m_pib.macSuperframeOrder = IEEE154_DEFAULT_SUPERFRAMEORDER;
+ m_pib.macTransactionPersistenceTime = IEEE154_DEFAULT_TRANSACTIONPERSISTENCETIME;
+ updateMacMaxFrameTotalWaitTime();
+ }
+
+ void updateMacMaxFrameTotalWaitTime()
+ {
+ // using equation 14 on page 160
+ ieee154_macMinBE_t macMinBE = m_pib.macMinBE;
+ ieee154_macMaxBE_t macMaxBE = m_pib.macMaxBE;
+ ieee154_macMaxCSMABackoffs_t macMaxCSMABackoffs = m_pib.macMaxCSMABackoffs;
+ uint8_t m = macMaxBE - macMinBE, k;
+ uint32_t waitTime = 0;
+
+ if (macMaxCSMABackoffs < m)
+ m = macMaxCSMABackoffs;
+ waitTime = (((uint16_t) 1 << macMaxBE) - 1) * (macMaxCSMABackoffs - m);
+ if (m) {
+ k = 0;
+ while (k != m){
+ waitTime += ((uint16_t) 1 << (macMaxBE+k));
+ k += 1;
+ }
+ }
+ waitTime *= IEEE154_aUnitBackoffPeriod;
+ waitTime += IEEE154_SHR_DURATION;
+ m_pib.macMaxFrameTotalWaitTime = waitTime;
+ }
+
+ command ieee154_status_t MLME_RESET.request(bool SetDefaultPIB, uint8_t PANType)
+ {
+ // resetting the complete stack is not so easy...
+ // first we acquire the Token (get exclusive radio access), then we switch off
+ // the radio and reset all MAC components, starting from the ones that might
+ // still have any frames queued / allocated to get them flushed out. While we
+ // own the Token all other components are "inactive" (and there are no pending
+ // Alarms!), but there can still be pending Timers/tasks -> we stop all Timers
+ // through MacReset.init() and then spin a few tasks in between to get
+ // everything "flushed out"
+ if (PANType != BEACON_ENABLED_PAN && PANType != NONBEACON_ENABLED_PAN)
+ return IEEE154_INVALID_PARAMETER;
+ if (call PromiscuousModeGet.get())
+ return IEEE154_TRANSACTION_OVERFLOW; // must first cancel promiscuous mode!
+
+ // nonbeacon-enabled mode is not yet implemented!
+ if (PANType != BEACON_ENABLED_PAN)
+ return IEEE154_INVALID_PARAMETER;
+
+ m_setDefaultPIB = SetDefaultPIB;
+ m_panType = PANType; // TODO: set this later?
+ if (!call Token.isOwner())
+ call Token.request();
+ return IEEE154_SUCCESS;
+ }
+
+ event void Token.granted()
+ {
+ error_t error = call RadioOff.off();
+ if (error != SUCCESS) // either it is already off or driver has not been started
+ signal RadioOff.offDone();
+ }
+
+ async event void RadioOff.offDone()
+ {
+ post radioControlStopTask();
+ }
+
+ task void radioControlStopTask()
+ {
+ if (call RadioControl.stop() == EALREADY)
+ signal RadioControl.stopDone(SUCCESS);
+ }
+
+ event void RadioControl.stopDone(error_t error)
+ {
+ call CapReset.init(); // resets the CAP component(s)
+ call CapQueueReset.init(); // resets the CAP queue component(s)
+ call MacReset.init(); // resets the remaining components
+ m_resetSpin = 5;
+ post resetSpinTask();
+ }
+
+ task void resetSpinTask()
+ {
+ if (m_resetSpin == 2){
+ // just to be safe...
+ call CapReset.init();
+ call CapQueueReset.init();
+ call MacReset.init();
+ }
+ if (m_resetSpin--){
+ post resetSpinTask();
+ return;
+ }
+ if (call RadioControl.start() == EALREADY)
+ signal RadioControl.startDone(SUCCESS);
+ }
+
+ event void RadioControl.startDone(error_t error)
+ {
+ if (m_setDefaultPIB)
+ resetAttributesToDefault();
+ else {
+ // restore previous PHY attributes
+ signal PIBUpdate.notify[IEEE154_phyCurrentChannel](&m_pib.phyCurrentChannel);
+ signal PIBUpdate.notify[IEEE154_phyTransmitPower](&m_pib.phyTransmitPower);
+ signal PIBUpdate.notify[IEEE154_phyCCAMode](&m_pib.phyCCAMode);
+ signal PIBUpdate.notify[IEEE154_phyCurrentPage](&m_pib.phyCurrentPage);
+ signal PIBUpdate.notify[IEEE154_macPANId](&m_pib.macPANId);
+ signal PIBUpdate.notify[IEEE154_macShortAddress](&m_pib.macShortAddress);
+ signal PIBUpdate.notify[IEEE154_macPanCoordinator](&m_pib.macPanCoordinator);
+ }
+ call Token.release();
+ signal MLME_RESET.confirm(IEEE154_SUCCESS);
+ }
+
+/* ----------------------- MLME-GET ----------------------- */
+
+ command ieee154_phyCurrentChannel_t MLME_GET.phyCurrentChannel(){ return m_pib.phyCurrentChannel;}
+
+ command ieee154_phyChannelsSupported_t MLME_GET.phyChannelsSupported(){ return IEEE154_SUPPORTED_CHANNELS;}
+
+ command ieee154_phyTransmitPower_t MLME_GET.phyTransmitPower(){ return m_pib.phyTransmitPower;}
+
+ command ieee154_phyCCAMode_t MLME_GET.phyCCAMode(){ return m_pib.phyCCAMode;}
+
+ command ieee154_phyCurrentPage_t MLME_GET.phyCurrentPage(){ return m_pib.phyCurrentPage;}
+
+ command ieee154_phyMaxFrameDuration_t MLME_GET.phyMaxFrameDuration(){ return IEEE154_MAX_FRAME_DURATION;}
+
+ command ieee154_phySHRDuration_t MLME_GET.phySHRDuration(){ return IEEE154_SHR_DURATION;}
+
+ command ieee154_phySymbolsPerOctet_t MLME_GET.phySymbolsPerOctet(){ return IEEE154_SYMBOLS_PER_OCTET;}
+
+ command ieee154_macAckWaitDuration_t MLME_GET.macAckWaitDuration(){ return IEEE154_ACK_WAIT_DURATION;}
+
+ command ieee154_macAssociationPermit_t MLME_GET.macAssociationPermit(){ return m_pib.macAssociationPermit;}
+
+ command ieee154_macAutoRequest_t MLME_GET.macAutoRequest(){ return m_pib.macAutoRequest;}
+
+ command ieee154_macBattLifeExt_t MLME_GET.macBattLifeExt(){ return m_pib.macBattLifeExt;}
+
+ command ieee154_macBattLifeExtPeriods_t MLME_GET.macBattLifeExtPeriods(){ return IEEE154_BATT_LIFE_EXT_PERIODS;}
+
+ command ieee154_macBeaconOrder_t MLME_GET.macBeaconOrder(){ return m_pib.macBeaconOrder;}
+
+ command ieee154_macBeaconTxTime_t MLME_GET.macBeaconTxTime(){ return m_pib.macBeaconTxTime;}
+
+ command ieee154_macBSN_t MLME_GET.macBSN(){ return m_pib.macBSN;}
+
+ command ieee154_macCoordExtendedAddress_t MLME_GET.macCoordExtendedAddress(){ return m_pib.macCoordExtendedAddress;}
+
+ command ieee154_macCoordShortAddress_t MLME_GET.macCoordShortAddress(){ return m_pib.macCoordShortAddress;}
+
+ command ieee154_macDSN_t MLME_GET.macDSN(){ return m_pib.macDSN;}
+
+ command ieee154_macGTSPermit_t MLME_GET.macGTSPermit(){ return m_pib.macGTSPermit;}
+
+ command ieee154_macMaxCSMABackoffs_t MLME_GET.macMaxCSMABackoffs(){ return m_pib.macMaxCSMABackoffs;}
+
+ command ieee154_macMinBE_t MLME_GET.macMinBE(){ return m_pib.macMinBE;}
+
+ command ieee154_macPANId_t MLME_GET.macPANId(){ return m_pib.macPANId;}
+
+ command ieee154_macPromiscuousMode_t MLME_GET.macPromiscuousMode(){ return call PromiscuousModeGet.get();}
+
+ command ieee154_macRxOnWhenIdle_t MLME_GET.macRxOnWhenIdle(){ return m_pib.macRxOnWhenIdle;}
+
+ command ieee154_macShortAddress_t MLME_GET.macShortAddress(){ return m_pib.macShortAddress;}
+
+ command ieee154_macSuperframeOrder_t MLME_GET.macSuperframeOrder(){ return m_pib.macSuperframeOrder;}
+
+ command ieee154_macTransactionPersistenceTime_t MLME_GET.macTransactionPersistenceTime(){ return m_pib.macTransactionPersistenceTime;}
+
+ command ieee154_macAssociatedPANCoord_t MLME_GET.macAssociatedPANCoord(){ return m_pib.macAssociatedPANCoord;}
+
+ command ieee154_macMaxBE_t MLME_GET.macMaxBE(){ return m_pib.macMaxBE;}
+
+ command ieee154_macMaxFrameTotalWaitTime_t MLME_GET.macMaxFrameTotalWaitTime(){ return m_pib.macMaxFrameTotalWaitTime;}
+
+ command ieee154_macMaxFrameRetries_t MLME_GET.macMaxFrameRetries(){ return m_pib.macMaxFrameRetries;}
+
+ command ieee154_macResponseWaitTime_t MLME_GET.macResponseWaitTime(){ return m_pib.macResponseWaitTime;}
+
+ command ieee154_macSyncSymbolOffset_t MLME_GET.macSyncSymbolOffset(){ return IEEE154_SYNC_SYMBOL_OFFSET;}
+
+ command ieee154_macTimestampSupported_t MLME_GET.macTimestampSupported(){ return IEEE154_TIMESTAMP_SUPPORTED;}
+
+ command ieee154_macSecurityEnabled_t MLME_GET.macSecurityEnabled(){ return m_pib.macSecurityEnabled;}
+
+ command ieee154_macMinLIFSPeriod_t MLME_GET.macMinLIFSPeriod(){ return IEEE154_MIN_LIFS_PERIOD;}
+
+ command ieee154_macMinSIFSPeriod_t MLME_GET.macMinSIFSPeriod(){ return IEEE154_MIN_SIFS_PERIOD;}
+
+/* ----------------------- MLME-SET ----------------------- */
+
+ command ieee154_status_t MLME_SET.phyCurrentChannel(ieee154_phyCurrentChannel_t value){
+ uint32_t i = 1;
+ uint8_t k = value;
+ while (i && k){
+ i <<= 1;
+ k -= 1;
+ }
+ if (!(IEEE154_SUPPORTED_CHANNELS & i))
+ return IEEE154_INVALID_PARAMETER;
+ m_pib.phyCurrentChannel = value;
+ signal PIBUpdate.notify[IEEE154_phyCurrentChannel](&m_pib.phyCurrentChannel);
+ return IEEE154_SUCCESS;
+ }
+
+ command ieee154_status_t MLME_SET.phyTransmitPower(ieee154_phyTransmitPower_t value){
+ m_pib.phyTransmitPower = (value & 0x3F);
+ signal PIBUpdate.notify[IEEE154_phyTransmitPower](&m_pib.phyTransmitPower);
+ return IEEE154_SUCCESS;
+ }
+
+ command ieee154_status_t MLME_SET.phyCCAMode(ieee154_phyCCAMode_t value){
+ if (value < 1 || value > 3)
+ return IEEE154_INVALID_PARAMETER;
+ m_pib.phyCCAMode = value;
+ signal PIBUpdate.notify[IEEE154_phyCCAMode](&m_pib.phyCCAMode);
+ return IEEE154_SUCCESS;
+ }
+
+ command ieee154_status_t MLME_SET.phyCurrentPage(ieee154_phyCurrentPage_t value){
+ if (value > 31)
+ return IEEE154_INVALID_PARAMETER;
+ m_pib.phyCurrentPage = value;
+ signal PIBUpdate.notify[IEEE154_phyCurrentPage](&m_pib.phyCurrentPage);
+ return IEEE154_SUCCESS;
+ }
+
+ command ieee154_status_t MLME_SET.macAssociationPermit(ieee154_macAssociationPermit_t value){
+ m_pib.macAssociationPermit = value;
+ signal PIBUpdate.notify[IEEE154_macAssociationPermit](&m_pib.macAssociationPermit);
+ return IEEE154_SUCCESS;
+ }
+
+ command ieee154_status_t MLME_SET.macAutoRequest(ieee154_macAutoRequest_t value){
+ m_pib.macAutoRequest = value;
+ signal PIBUpdate.notify[IEEE154_macAutoRequest](&m_pib.macAutoRequest);
+ return IEEE154_SUCCESS;
+ }
+
+ command ieee154_status_t MLME_SET.macBattLifeExt(ieee154_macBattLifeExt_t value){
+ m_pib.macBattLifeExt = value;
+ signal PIBUpdate.notify[IEEE154_macBattLifeExt](&m_pib.macBattLifeExt);
+ return IEEE154_SUCCESS;
+ }
+
+ command ieee154_status_t MLME_SET.macBattLifeExtPeriods(ieee154_macBattLifeExtPeriods_t value){
+ if (value < 6 || value > 41)
+ return IEEE154_INVALID_PARAMETER;
+ m_pib.macBattLifeExtPeriods = value;
+ signal PIBUpdate.notify[IEEE154_macBattLifeExtPeriods](&m_pib.macBattLifeExtPeriods);
+ return IEEE154_SUCCESS;
+ }
+
+ command ieee154_status_t MLME_SET.macBeaconOrder(ieee154_macBeaconOrder_t value){
+ if (value > 15)
+ return IEEE154_INVALID_PARAMETER;
+ m_pib.macBeaconOrder = value;
+ signal PIBUpdate.notify[IEEE154_macBeaconOrder](&m_pib.macBeaconOrder);
+ return IEEE154_SUCCESS;
+ }
+
+ command ieee154_status_t MLME_SET.macBSN(ieee154_macBSN_t value){
+ m_pib.macBSN = value;
+ signal PIBUpdate.notify[IEEE154_macBSN](&m_pib.macBSN);
+ return IEEE154_SUCCESS;
+ }
+
+ command ieee154_status_t MLME_SET.macCoordExtendedAddress(ieee154_macCoordExtendedAddress_t value){
+ m_pib.macCoordExtendedAddress = value;
+ signal PIBUpdate.notify[IEEE154_macCoordExtendedAddress](&m_pib.macCoordExtendedAddress);
+ return IEEE154_SUCCESS;
+ }
+
+ command ieee154_status_t MLME_SET.macCoordShortAddress(ieee154_macCoordShortAddress_t value){
+ m_pib.macCoordShortAddress = value;
+ signal PIBUpdate.notify[IEEE154_macCoordShortAddress](&m_pib.macCoordShortAddress);
+ return IEEE154_SUCCESS;
+ }
+
+ command ieee154_status_t MLME_SET.macDSN(ieee154_macDSN_t value){
+ m_pib.macDSN = value;
+ signal PIBUpdate.notify[IEEE154_macDSN](&m_pib.macDSN);
+ return IEEE154_SUCCESS;
+ }
+
+ command ieee154_status_t MLME_SET.macGTSPermit(ieee154_macGTSPermit_t value){
+ m_pib.macGTSPermit = value;
+ signal PIBUpdate.notify[IEEE154_macGTSPermit](&m_pib.macGTSPermit);
+ return IEEE154_SUCCESS;
+ }
+
+ command ieee154_status_t MLME_SET.macMaxCSMABackoffs(ieee154_macMaxCSMABackoffs_t value){
+ if (value > 5)
+ return IEEE154_INVALID_PARAMETER;
+ m_pib.macMaxCSMABackoffs = value;
+ updateMacMaxFrameTotalWaitTime();
+ signal PIBUpdate.notify[IEEE154_macMaxCSMABackoffs](&m_pib.macMaxCSMABackoffs);
+ return IEEE154_SUCCESS;
+ }
+
+ command ieee154_status_t MLME_SET.macMinBE(ieee154_macMinBE_t value){
+ if (value > m_pib.macMaxBE)
+ return IEEE154_INVALID_PARAMETER;
+ m_pib.macMinBE = value;
+ updateMacMaxFrameTotalWaitTime();
+ signal PIBUpdate.notify[IEEE154_macMinBE](&m_pib.macMinBE);
+ return IEEE154_SUCCESS;
+ }
+
+ command ieee154_status_t MLME_SET.macPANId(ieee154_macPANId_t value){
+ m_pib.macPANId = value;
+ signal PIBUpdate.notify[IEEE154_macPANId](&m_pib.macPANId);
+ return IEEE154_SUCCESS;
+ }
+
+ command ieee154_status_t MLME_SET.macRxOnWhenIdle(ieee154_macRxOnWhenIdle_t value){
+ m_pib.macRxOnWhenIdle = value;
+ signal PIBUpdate.notify[IEEE154_macRxOnWhenIdle](&m_pib.macRxOnWhenIdle);
+ return IEEE154_SUCCESS;
+ }
+
+ command ieee154_status_t MLME_SET.macShortAddress(ieee154_macShortAddress_t value){
+ m_pib.macShortAddress = value;
+ signal PIBUpdate.notify[IEEE154_macShortAddress](&m_pib.macShortAddress);
+ return IEEE154_SUCCESS;
+ }
+
+ command ieee154_status_t MLME_SET.macTransactionPersistenceTime(ieee154_macTransactionPersistenceTime_t value){
+ m_pib.macTransactionPersistenceTime = value;
+ signal PIBUpdate.notify[IEEE154_macTransactionPersistenceTime](&m_pib.macTransactionPersistenceTime);
+ return IEEE154_SUCCESS;
+ }
+
+ command ieee154_status_t MLME_SET.macAssociatedPANCoord(ieee154_macAssociatedPANCoord_t value){
+ m_pib.macAssociatedPANCoord = value;
+ signal PIBUpdate.notify[IEEE154_macAssociatedPANCoord](&m_pib.macAssociatedPANCoord);
+ return IEEE154_SUCCESS;
+ }
+
+ command ieee154_status_t MLME_SET.macMaxBE(ieee154_macMaxBE_t value){
+ if (value < 3 || value > 8)
+ return IEEE154_INVALID_PARAMETER;
+ m_pib.macMaxBE = value;
+ updateMacMaxFrameTotalWaitTime();
+ signal PIBUpdate.notify[IEEE154_macMaxBE](&m_pib.macMaxBE);
+ return IEEE154_SUCCESS;
+ }
+
+ command ieee154_status_t MLME_SET.macMaxFrameTotalWaitTime(ieee154_macMaxFrameTotalWaitTime_t value){
+ // equation 14 on page 160 defines how macMaxFrameTotalWaitTime is calculated;
+ // its value depends only on other PIB attributes and constants - why does the standard
+ // allow setting it by the next higher layer ??
+ m_pib.macMaxFrameTotalWaitTime = value;
+ signal PIBUpdate.notify[IEEE154_macMaxFrameTotalWaitTime](&m_pib.macMaxFrameTotalWaitTime);
+ return IEEE154_SUCCESS;
+ }
+
+ command ieee154_status_t MLME_SET.macMaxFrameRetries(ieee154_macMaxFrameRetries_t value){
+ if (value > 7)
+ return IEEE154_INVALID_PARAMETER;
+ m_pib.macMaxFrameRetries = value;
+ signal PIBUpdate.notify[IEEE154_macMaxFrameRetries](&m_pib.macMaxFrameRetries);
+ return IEEE154_SUCCESS;
+ }
+
+ command ieee154_status_t MLME_SET.macResponseWaitTime(ieee154_macResponseWaitTime_t value){
+ if (value < 2 || value > 64)
+ return IEEE154_INVALID_PARAMETER;
+ m_pib.macResponseWaitTime = value;
+ signal PIBUpdate.notify[IEEE154_macResponseWaitTime](&m_pib.macResponseWaitTime);
+ return IEEE154_SUCCESS;
+ }
+
+ command ieee154_status_t MLME_SET.macSecurityEnabled(ieee154_macSecurityEnabled_t value){
+ return IEEE154_UNSUPPORTED_ATTRIBUTE;
+ }
+
+ // Read-only attributes (writable only by MAC components)
+ command void SetMacSuperframeOrder.set( ieee154_macSuperframeOrder_t value ){
+ m_pib.macSuperframeOrder = value;
+ signal PIBUpdate.notify[IEEE154_macSuperframeOrder](&m_pib.macSuperframeOrder);
+ }
+
+ command void SetMacBeaconTxTime.set( ieee154_macBeaconTxTime_t value ){
+ m_pib.macBeaconTxTime = value;
+ signal PIBUpdate.notify[IEEE154_macBeaconTxTime](&m_pib.macBeaconTxTime);
+ }
+
+ command void SetMacPanCoordinator.set( ieee154_macPanCoordinator_t value ){
+ m_pib.macPanCoordinator = value;
+ signal PIBUpdate.notify[IEEE154_macPanCoordinator](&m_pib.macPanCoordinator);
+ }
+
+ command ieee154_macPanCoordinator_t IsMacPanCoordinator.get(){
+ return m_pib.macPanCoordinator;
+ }
+
+/* ----------------------- TimeCalc ----------------------- */
+
+ async command uint32_t TimeCalc.timeElapsed(uint32_t t0, uint32_t t1)
+ {
+ // t0 occured before t1, what is the delta?
+ if (t0 <= t1)
+ return t1 - t0;
+ else
+ return ~(t0 - t1) + 1;
+ }
+
+ async command bool TimeCalc.hasExpired(uint32_t t0, uint32_t dt)
+ {
+ // t0 is in the past, what about t0+dt?
+ uint32_t now = call LocalTime.get(), elapsed;
+ if (now >= t0)
+ elapsed = now - t0;
+ else
+ elapsed = ~(t0 - now) + 1;
+ return (elapsed >= dt);
+ }
+
+/* ----------------------- Frame Access ----------------------- */
+
+ command void Packet.clear(message_t* msg)
+ {
+ uint8_t i;
+ memset(msg->header, 0, sizeof(message_header_t));
+ memset(msg->metadata, 0, sizeof(message_metadata_t));
+ }
+
+ command uint8_t Packet.payloadLength(message_t* msg)
+ {
+ return ((message_header_t*) msg->header)->ieee154.length;
+ }
+
+ command void Packet.setPayloadLength(message_t* msg, uint8_t len)
+ {
+ ((message_header_t*) msg->header)->ieee154.length = len;
+ }
+
+ command uint8_t Packet.maxPayloadLength()
+ {
+#if TOSH_DATA_LENGTH < 118
+#warning Payload portion in message_t is smaller than required (TOSH_DATA_LENGTH < IEEE154_aMaxMACPayloadSize). This means that larger packets cannot be sent/received.
+#endif
+ return TOSH_DATA_LENGTH;
+ }
+
+ command void* Packet.getPayload(message_t* msg, uint8_t len)
+ {
+ return msg->data;
+ }
+
+ async command uint8_t FrameUtility.writeHeader(
+ uint8_t* mhr,
+ uint8_t DstAddrMode,
+ uint16_t DstPANId,
+ ieee154_address_t* DstAddr,
+ uint8_t SrcAddrMode,
+ uint16_t SrcPANId,
+ const ieee154_address_t* SrcAddr,
+ bool PANIDCompression)
+ {
+ uint8_t offset = MHR_INDEX_ADDRESS;
+ if (DstAddrMode == ADDR_MODE_SHORT_ADDRESS || DstAddrMode == ADDR_MODE_EXTENDED_ADDRESS){
+ *((nxle_uint16_t*) &mhr[offset]) = DstPANId;
+ offset += 2;
+ if (DstAddrMode == ADDR_MODE_SHORT_ADDRESS){
+ *((nxle_uint16_t*) &mhr[offset]) = DstAddr->shortAddress;
+ offset += 2;
+ } else {
+ call FrameUtility.convertToLE(&mhr[offset], &DstAddr->extendedAddress);
+ offset += 8;
+ }
+ }
+ if (SrcAddrMode == ADDR_MODE_SHORT_ADDRESS || SrcAddrMode == ADDR_MODE_EXTENDED_ADDRESS){
+ if (DstPANId != SrcPANId || !PANIDCompression){
+ *((nxle_uint16_t*) &mhr[offset]) = SrcPANId;
+ offset += 2;
+ }
+ if (SrcAddrMode == ADDR_MODE_SHORT_ADDRESS){
+ *((nxle_uint16_t*) &mhr[offset]) = SrcAddr->shortAddress;
+ offset += 2;
+ } else {
+ call FrameUtility.convertToLE(&mhr[offset], &SrcAddr->extendedAddress);
+ offset += 8;
+ }
+ }
+ return offset;
+ }
+
+ command bool FrameUtility.isBeaconFromCoord(message_t *frame)
+ {
+ uint8_t offset = MHR_INDEX_ADDRESS;
+ uint8_t *mhr = MHR(frame);
+
+ if ((mhr[MHR_INDEX_FC1] & FC1_FRAMETYPE_MASK) != FC1_FRAMETYPE_BEACON)
+ return FALSE; // not a beacon frame
+ if (!(mhr[MHR_INDEX_FC2] & FC2_SRC_MODE_MASK))
+ return FALSE; // source address information missing
+ if (mhr[MHR_INDEX_FC2] & FC2_DEST_MODE_MASK)
+ return FALSE; // beacons don't include dest address
+ if ((*(nxle_uint16_t*) (&mhr[offset])) != m_pib.macPANId)
+ return FALSE; // wrong PAN ID
+ offset += 2;
+ if ((mhr[MHR_INDEX_FC2] & FC2_SRC_MODE_MASK) == FC2_SRC_MODE_SHORT){
+ if ((*(nxle_uint16_t*) (&mhr[offset])) != m_pib.macCoordShortAddress)
+ return FALSE;
+ } else if ((mhr[MHR_INDEX_FC2] & FC2_SRC_MODE_MASK) == FC2_SRC_MODE_EXTENDED){
+ if (!isCoordExtendedAddress(mhr + offset))
+ return FALSE;
+ }
+ return TRUE;
+ }
+
+ async command error_t FrameUtility.getMHRLength(uint8_t fcf1, uint8_t fcf2, uint8_t *len)
+ {
+ uint8_t idCompression;
+ uint8_t offset = MHR_INDEX_ADDRESS;
+
+ if (fcf1 & FC1_SECURITY_ENABLED)
+ return FAIL; // not supported
+ idCompression = (fcf1 & FC1_PAN_ID_COMPRESSION);
+ if (fcf2 & 0x08){ // short or ext. address
+ offset += 4; // pan id + short address
+ if (fcf2 & 0x04) // ext. address
+ offset += 6; // diff to short address
+ }
+ if (fcf2 & 0x80){ // short or ext. address
+ offset += 2;
+ if (!idCompression)
+ offset += 2;
+ if (fcf2 & 0x40) // ext. address
+ offset += 6; // diff to short address
+ }
+ *len = offset;
+ return SUCCESS;
+ }
+
+
+ command error_t Frame.setAddressingFields(message_t* frame,
+ uint8_t srcAddrMode,
+ uint8_t dstAddrMode,
+ uint16_t dstPANId,
+ ieee154_address_t *dstAddr,
+ ieee154_security_t *security)
+ {
+ uint8_t *mhr = MHR(frame);
+ ieee154_address_t srcAddress;
+ ieee154_macPANId_t srcPANId = call MLME_GET.macPANId();
+
+ if (security && security->SecurityLevel)
+ return FAIL; // not implemented
+ mhr[MHR_INDEX_FC2] &= (FC2_DEST_MODE_MASK | FC2_SRC_MODE_MASK);
+ mhr[MHR_INDEX_FC2] |= dstAddrMode << FC2_DEST_MODE_OFFSET;
+ mhr[MHR_INDEX_FC2] |= srcAddrMode << FC2_SRC_MODE_OFFSET;
+ if (srcAddrMode == ADDR_MODE_SHORT_ADDRESS)
+ srcAddress.shortAddress = call MLME_GET.macShortAddress();
+ else
+ srcAddress.extendedAddress = call GetLocalExtendedAddress.get();
+ if (dstAddrMode >= ADDR_MODE_SHORT_ADDRESS &&
+ srcAddrMode >= ADDR_MODE_SHORT_ADDRESS &&
+ dstPANId == srcPANId)
+ mhr[MHR_INDEX_FC1] |= FC1_PAN_ID_COMPRESSION;
+ else
+ mhr[MHR_INDEX_FC1] &= ~FC1_PAN_ID_COMPRESSION;
+ call FrameUtility.writeHeader(
+ mhr,
+ dstAddrMode,
+ dstPANId,
+ dstAddr,
+ srcAddrMode,
+ srcPANId,
+ &srcAddress,
+ (mhr[MHR_INDEX_FC1] & FC1_PAN_ID_COMPRESSION) ? TRUE: FALSE);
+ return SUCCESS;
+ }
+
+ command uint8_t Frame.getFrameType(message_t* frame)
+ {
+ uint8_t *mhr = MHR(frame);
+ return (mhr[MHR_INDEX_FC1] & FC1_FRAMETYPE_MASK);
+ }
+
+ command void* Frame.getHeader(message_t* frame)
+ {
+ uint8_t *mhr = MHR(frame);
+ return (void*) &(mhr[MHR_INDEX_FC1]);
+ }
+
+ command uint8_t Frame.getHeaderLength(message_t* frame)
+ {
+ uint8_t len;
+ uint8_t *mhr = MHR(frame);
+ call FrameUtility.getMHRLength(mhr[0], mhr[1], &len);
+ return len;
+ }
+
+ command void* Frame.getPayload(message_t* frame)
+ {
+ uint8_t *payload = (uint8_t *) frame->data;
+ return payload;
+ }
+
+ command uint8_t Frame.getPayloadLength(message_t* frame)
+ {
+ uint8_t len = ((ieee154_header_t*) frame->header)->length & FRAMECTL_LENGTH_MASK;
+ return len;
+ }
+
+ command uint32_t Frame.getTimestamp(message_t* frame)
+ {
+ ieee154_metadata_t *metadata = (ieee154_metadata_t*) frame->metadata;
+ return metadata->timestamp;
+ }
+
+ command bool Frame.isTimestampValid(message_t* frame)
+ {
+ ieee154_metadata_t *metadata = (ieee154_metadata_t*) frame->metadata;
+ if (metadata->timestamp == IEEE154_INVALID_TIMESTAMP)
+ return FALSE;
+ else
+ return TRUE;
+ }
+
+ command uint8_t Frame.getDSN(message_t* frame)
+ {
+ uint8_t *mhr = MHR(frame);
+ return mhr[MHR_INDEX_SEQNO];
+ }
+
+ command uint8_t Frame.getLinkQuality(message_t* frame)
+ {
+ ieee154_metadata_t *metadata = (ieee154_metadata_t*) frame->metadata;
+ return metadata->linkQuality;
+ }
+
+ command uint8_t Frame.getSrcAddrMode(message_t* frame)
+ {
+ uint8_t *mhr = MHR(frame);
+ return (mhr[MHR_INDEX_FC2] & FC2_SRC_MODE_MASK) >> FC2_SRC_MODE_OFFSET;
+ }
+
+ command error_t Frame.getSrcAddr(message_t* frame, ieee154_address_t *address)
+ {
+ uint8_t *mhr = MHR(frame);
+ uint8_t offset = MHR_INDEX_ADDRESS;
+ uint8_t destMode = (mhr[MHR_INDEX_FC2] & FC2_DEST_MODE_MASK);
+ if (!(mhr[MHR_INDEX_FC2] & FC2_SRC_MODE_SHORT))
+ return FAIL;
+ if (destMode == FC2_DEST_MODE_SHORT)
+ offset += 4;
+ else if (destMode == FC2_DEST_MODE_EXTENDED)
+ offset += 10;
+ if (!((mhr[MHR_INDEX_FC1] & FC1_PAN_ID_COMPRESSION) && (mhr[MHR_INDEX_FC2] & FC2_DEST_MODE_SHORT)))
+ offset += 2;
+ if ((mhr[MHR_INDEX_FC2] & FC2_SRC_MODE_MASK) == FC2_SRC_MODE_SHORT)
+ address->shortAddress = *((nxle_uint16_t*) (&(mhr[offset])));
+ else
+ call FrameUtility.convertToNative(&address->extendedAddress, (&(mhr[offset]) ));
+ return SUCCESS;
+ }
+
+ command error_t Frame.getSrcPANId(message_t* frame, uint16_t *PANID)
+ {
+ uint8_t *mhr = MHR(frame);
+ uint8_t offset = MHR_INDEX_ADDRESS;
+ uint8_t destMode = (mhr[1] & FC2_DEST_MODE_MASK);
+ if (!(mhr[MHR_INDEX_FC2] & FC2_SRC_MODE_SHORT))
+ return FAIL;
+ if (destMode == FC2_DEST_MODE_SHORT)
+ offset += 4;
+ else if (destMode == FC2_DEST_MODE_EXTENDED)
+ offset += 10;
+ if ((mhr[MHR_INDEX_FC1] & FC1_PAN_ID_COMPRESSION) && (mhr[MHR_INDEX_FC2] & FC2_DEST_MODE_SHORT))
+ *PANID = *((nxle_uint16_t*) (&(mhr[MHR_INDEX_ADDRESS])));
+ else if ((mhr[MHR_INDEX_FC2] & FC2_SRC_MODE_MASK) == FC2_SRC_MODE_SHORT)
+ *PANID = *((nxle_uint16_t*) (&(mhr[offset])));
+ else
+ *PANID = *((nxle_uint16_t*) (&(mhr[offset])));
+ return SUCCESS;
+ }
+
+ command uint8_t Frame.getDstAddrMode(message_t* frame)
+ {
+ uint8_t *mhr = MHR(frame);
+ return (mhr[MHR_INDEX_FC2] & FC2_DEST_MODE_MASK) >> FC2_DEST_MODE_OFFSET;
+ }
+
+ command error_t Frame.getDstAddr(message_t* frame, ieee154_address_t *address)
+ {
+ uint8_t *mhr = MHR(frame);
+ if (!(mhr[MHR_INDEX_FC2] & FC2_DEST_MODE_SHORT))
+ return FAIL;
+ if ((mhr[MHR_INDEX_FC2] & FC2_DEST_MODE_MASK) == FC2_DEST_MODE_SHORT)
+ address->shortAddress = *((nxle_uint16_t*) (&(mhr[MHR_INDEX_ADDRESS]) + 2));
+ else
+ call FrameUtility.convertToNative(&address->extendedAddress, (&(mhr[MHR_INDEX_ADDRESS]) + 2));
+ return SUCCESS;
+ }
+
+ command error_t Frame.getDstPANId(message_t* frame, uint16_t *PANID)
+ {
+ uint8_t *mhr = MHR(frame);
+ if (!(mhr[MHR_INDEX_FC2] & FC2_DEST_MODE_SHORT))
+ return FAIL;
+ *PANID = *((nxle_uint16_t*) (&(mhr[MHR_INDEX_ADDRESS])));
+ return SUCCESS;
+ }
+
+ command bool Frame.wasPromiscuousModeEnabled(message_t* frame)
+ {
+ return (((ieee154_header_t*) frame->header)->length & FRAMECTL_PROMISCUOUS) ? TRUE : FALSE;
+ }
+
+ command bool Frame.hasStandardCompliantHeader(message_t* frame)
+ {
+ uint8_t *mhr = MHR(frame);
+ if ( ((mhr[0] & FC1_FRAMETYPE_MASK) > 0x03) ||
+ ((mhr[MHR_INDEX_FC2] & FC2_DEST_MODE_MASK) == 0x04) ||
+ ((mhr[MHR_INDEX_FC2] & FC2_SRC_MODE_MASK) == 0x40) ||
+#ifndef IEEE154_SECURITY_ENABLED
+ ((mhr[0] & FC1_SECURITY_ENABLED)) ||
+#endif
+ (mhr[MHR_INDEX_FC2] & FC2_FRAME_VERSION_2)
+ )
+ return FALSE;
+ else
+ return TRUE;
+ }
+
+/* ----------------------- Beacon Frame Access ----------------------- */
+
+ uint8_t getPendAddrSpecOffset(uint8_t *macPayloadField)
+ {
+ uint8_t gtsDescriptorCount = macPayloadField[BEACON_INDEX_GTS_SPEC] & GTS_DESCRIPTOR_COUNT_MASK;
+ return BEACON_INDEX_GTS_SPEC + 1 + ((gtsDescriptorCount > 0) ? 1 + gtsDescriptorCount * 3: 0);
+ }
+
+ command error_t BeaconFrame.getPendAddrSpec(message_t* frame, uint8_t* pendAddrSpec)
+ {
+ uint8_t *mhr = MHR(frame);
+ if (((mhr[MHR_INDEX_FC1] & FC1_FRAMETYPE_MASK) != FC1_FRAMETYPE_BEACON))
+ return FAIL;
+ else {
+ uint8_t *payload = (uint8_t *) frame->data;
+ uint8_t pendAddrSpecOffset = getPendAddrSpecOffset(payload);
+ *pendAddrSpec = payload[pendAddrSpecOffset];
+ return SUCCESS;
+ }
+ }
+
+ command error_t BeaconFrame.getPendAddr(message_t* frame, uint8_t addrMode,
+ ieee154_address_t buffer[], uint8_t bufferSize)
+ {
+ uint8_t *mhr = MHR(frame);
+ uint8_t *payload = (uint8_t *) frame->data;
+ uint8_t pendAddrSpecOffset = getPendAddrSpecOffset(payload);
+ uint8_t pendAddrSpec = payload[pendAddrSpecOffset], i;
+ if (((mhr[MHR_INDEX_FC1] & FC1_FRAMETYPE_MASK) != FC1_FRAMETYPE_BEACON))
+ return FAIL;
+ if (addrMode == ADDR_MODE_SHORT_ADDRESS){
+ for (i=0; i<(pendAddrSpec & PENDING_ADDRESS_SHORT_MASK) && i<bufferSize; i++)
+ buffer[i].shortAddress = *((nxle_uint16_t*) (payload + pendAddrSpecOffset + 1 + 2*i));
+ return SUCCESS;
+ } else if (addrMode == ADDR_MODE_EXTENDED_ADDRESS){
+ for (i=0; i<((pendAddrSpec & PENDING_ADDRESS_EXT_MASK) >> 4) && i<bufferSize; i++)
+ call FrameUtility.convertToNative(&(buffer[i].extendedAddress),
+ ((payload + pendAddrSpecOffset +
+ 1 + (pendAddrSpec & PENDING_ADDRESS_SHORT_MASK)*2 + 8*i)));
+ return SUCCESS;
+ }
+ return EINVAL;
+ }
+
+ command uint8_t BeaconFrame.isLocalAddrPending(message_t* frame)
+ {
+ uint8_t *mhr = MHR(frame);
+ uint8_t *payload = (uint8_t *) frame->data;
+ uint8_t pendAddrSpecOffset = getPendAddrSpecOffset(payload);
+ uint8_t pendAddrSpec = payload[pendAddrSpecOffset], i;
+ ieee154_macShortAddress_t shortAddress = call MLME_GET.macShortAddress();
+ if (((mhr[MHR_INDEX_FC1] & FC1_FRAMETYPE_MASK) != FC1_FRAMETYPE_BEACON))
+ return ADDR_MODE_NOT_PRESENT;
+ for (i=0; i<(pendAddrSpec & PENDING_ADDRESS_SHORT_MASK); i++)
+ if (*((nxle_uint16_t*) (payload + pendAddrSpecOffset + 1 + 2*i)) == shortAddress)
+ return ADDR_MODE_SHORT_ADDRESS;
+ for (i=0; i<((pendAddrSpec & PENDING_ADDRESS_EXT_MASK) >> 4); i++)
+ if (isLocalExtendedAddress(((payload + pendAddrSpecOffset +
+ 1 + (pendAddrSpec & PENDING_ADDRESS_SHORT_MASK)*2 + 8*i))))
+ return ADDR_MODE_EXTENDED_ADDRESS;
+ return ADDR_MODE_NOT_PRESENT;
+ }
+
+ command void* BeaconFrame.getBeaconPayload(message_t* frame)
+ {
+ uint8_t *mhr = MHR(frame);
+ uint8_t *payload = (uint8_t *) frame->data;
+ if ((mhr[MHR_INDEX_FC1] & FC1_FRAMETYPE_MASK) == FC1_FRAMETYPE_BEACON){
+ uint8_t pendAddrSpecOffset = getPendAddrSpecOffset(payload);
+ uint8_t pendAddrSpec = payload[pendAddrSpecOffset];
+ payload += (pendAddrSpecOffset + 1);
+ if (pendAddrSpec & PENDING_ADDRESS_SHORT_MASK)
+ payload += (pendAddrSpec & PENDING_ADDRESS_SHORT_MASK) * 2;
+ if (pendAddrSpec & PENDING_ADDRESS_EXT_MASK)
+ payload += ((pendAddrSpec & PENDING_ADDRESS_EXT_MASK) >> 4) * 8;
+ }
+ return payload;
+ }
+
+ command uint8_t BeaconFrame.getBeaconPayloadLength(message_t* frame)
+ {
+ uint8_t *mhr = MHR(frame);
+ uint8_t len = ((ieee154_header_t*) frame->header)->length & FRAMECTL_LENGTH_MASK;
+ if ((mhr[MHR_INDEX_FC1] & FC1_FRAMETYPE_MASK) == FC1_FRAMETYPE_BEACON){
+ uint8_t *payload = call Frame.getPayload(frame);
+ len = len - (payload - (uint8_t *) frame->data);
+ }
+ return len;
+ }
+
+ command uint8_t BeaconFrame.getBSN(message_t* frame)
+ {
+ return call Frame.getDSN(frame);
+ }
+
+ command error_t BeaconFrame.parsePANDescriptor(
+ message_t *frame,
+ uint8_t LogicalChannel,
+ uint8_t ChannelPage,
+ ieee154_PANDescriptor_t *PANDescriptor
+ )
+ {
+ uint8_t *mhr = MHR(frame);
+ uint8_t offset;
+ ieee154_metadata_t *metadata = (ieee154_metadata_t*) frame->metadata;
+
+ if ( (mhr[MHR_INDEX_FC1] & FC1_FRAMETYPE_MASK) != FC1_FRAMETYPE_BEACON ||
+ (((mhr[MHR_INDEX_FC2] & FC2_SRC_MODE_MASK) != FC2_SRC_MODE_SHORT) &&
+ ((mhr[MHR_INDEX_FC2] & FC2_SRC_MODE_MASK) != FC2_SRC_MODE_EXTENDED)) )
+ return FAIL;
+ PANDescriptor->CoordAddrMode = (mhr[MHR_INDEX_FC2] & FC2_SRC_MODE_MASK) >> FC2_SRC_MODE_OFFSET;
+ offset = MHR_INDEX_ADDRESS;
+ PANDescriptor->CoordPANId = *((nxle_uint16_t*) &mhr[offset]);
+ offset += sizeof(ieee154_macPANId_t);
+ if ((mhr[MHR_INDEX_FC2] & FC2_SRC_MODE_MASK) == FC2_SRC_MODE_SHORT)
+ PANDescriptor->CoordAddress.shortAddress = *((nxle_uint16_t*) &mhr[offset]);
+ else
+ call FrameUtility.convertToNative(&PANDescriptor->CoordAddress.extendedAddress, &mhr[offset]);
+ PANDescriptor->LogicalChannel = LogicalChannel;
+ PANDescriptor->ChannelPage = ChannelPage;
+ ((uint8_t*) &PANDescriptor->SuperframeSpec)[0] = frame->data[BEACON_INDEX_SF_SPEC1]; // little endian
+ ((uint8_t*) &PANDescriptor->SuperframeSpec)[1] = frame->data[BEACON_INDEX_SF_SPEC2];
+ PANDescriptor->GTSPermit = (frame->data[BEACON_INDEX_GTS_SPEC] & GTS_SPEC_PERMIT) ? 1 : 0;
+ PANDescriptor->LinkQuality = metadata->linkQuality;
+ PANDescriptor->TimeStamp = metadata->timestamp;
+#ifndef IEEE154_SECURITY_ENABLED
+ PANDescriptor->SecurityFailure = IEEE154_SUCCESS;
+ PANDescriptor->SecurityLevel = 0;
+ PANDescriptor->KeyIdMode = 0;
+ PANDescriptor->KeySource = 0;
+ PANDescriptor->KeyIndex = 0;
+#else
+#error Implementation of BeaconFrame.parsePANDescriptor() needs adaptation !
+#endif
+ return SUCCESS;
+ }
+
+/* ----------------------- FrameUtility, etc. ----------------------- */
+
+ command uint64_t GetLocalExtendedAddress.get()
+ {
+ return m_aExtendedAddressLE;
+ }
+
+ async command void FrameUtility.convertToLE(uint8_t *destLE, const uint64_t *src)
+ {
+ uint8_t i;
+ uint64_t srcCopy = *src;
+ for (i=0; i<8; i++){
+ destLE[i] = srcCopy;
+ srcCopy >>= 8;
+ }
+ }
+
+ async command void FrameUtility.convertToNative(uint64_t *dest, const uint8_t *srcLE)
+ {
+ // on msp430 nxle_uint64_t doesn't work, this is a workaround
+ uint32_t lower = *((nxle_uint32_t*) srcLE);
+ uint64_t upper = *((nxle_uint32_t*) (srcLE+4));
+ *dest = (upper << 32) + lower;
+
+ }
+
+ async command void FrameUtility.copyLocalExtendedAddressLE(uint8_t *destLE)
+ {
+ call FrameUtility.convertToLE(destLE, &m_aExtendedAddressLE);
+ }
+
+ command void FrameUtility.copyCoordExtendedAddressLE(uint8_t *destLE)
+ {
+ call FrameUtility.convertToLE(destLE, &m_pib.macCoordExtendedAddress);
+ }
+
+ bool isLocalExtendedAddress(uint8_t *addrLE)
+ {
+ uint64_t dest;
+ call FrameUtility.convertToNative(&dest, addrLE);
+ return dest == m_aExtendedAddressLE;
+ }
+
+ bool isCoordExtendedAddress(uint8_t *addrLE)
+ {
+ uint64_t dest;
+ call FrameUtility.convertToNative(&dest, addrLE);
+ return dest == m_pib.macCoordExtendedAddress;
+ }
+
+ command bool IsBeaconEnabledPAN.get()
+ {
+ 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;}
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+
+#include "TKN154_MAC.h"
+
+module PollP
+{
+ provides
+ {
+ interface Init;
+ interface MLME_POLL;
+ interface FrameRx as DataRx;
+ interface DataRequest as DataRequest[uint8_t client];
+ }
+ uses
+ {
+ interface FrameTx as PollTx;
+ interface FrameExtracted as DataExtracted;
+ interface FrameUtility;
+ 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;
+ }
+}
+implementation
+{
+ enum {
+ HANDLE_MLME_POLL_REQUEST = 0xFF,
+ HANDLE_MLME_POLL_SUCCESS = 0xFE,
+ };
+ int m_numPending;
+ uint8_t m_dataRequestCmdID = CMD_FRAME_DATA_REQUEST;
+ void buildDataRequestFrame( uint8_t destAddrMode, uint16_t destPANId,
+ uint8_t* DstAddr, uint8_t srcAddrMode, ieee154_txframe_t *txFrame);
+
+ command error_t Init.init()
+ {
+ m_numPending = 0;
+ return SUCCESS;
+ }
+
+ command ieee154_status_t MLME_POLL.request (
+ uint8_t coordAddrMode,
+ 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;
+ txFrame->metadata = &txControl->metadata;
+ if (coordAddrMode == ADDR_MODE_SHORT_ADDRESS)
+ *((nxle_uint16_t*) &coordAddressLE) = coordAddress.shortAddress;
+ else
+ call FrameUtility.convertToLE(coordAddressLE, &coordAddress.extendedAddress);
+ txFrame->handle = HANDLE_MLME_POLL_REQUEST;
+ if (call MLME_GET.macShortAddress() >= 0xFFFE)
+ 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(LEVEL_IMPORTANT, PollP_ALLOC_FAIL1, 0, 0, 0);
+ } else
+ m_numPending++;
+ }
+ return txStatus;
+ }
+
+ command ieee154_status_t DataRequest.poll[uint8_t client](uint8_t CoordAddrMode,
+ uint16_t CoordPANId, uint8_t *CoordAddressLE, uint8_t srcAddrMode)
+ {
+ ieee154_txframe_t *txFrame;
+ ieee154_txcontrol_t *txControl;
+ ieee154_status_t status = IEEE154_TRANSACTION_OVERFLOW;
+ call Debug.log(LEVEL_INFO, PollP_INTERNAL_POLL, CoordAddrMode, client, m_numPending);
+ if (client == SYNC_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);
+ else {
+ txFrame->header = &txControl->header;
+ txFrame->metadata = &txControl->metadata;
+ txFrame->handle = client;
+ 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(LEVEL_IMPORTANT, PollP_ALLOC_FAIL2, 0, 0, 0);
+ } else
+ m_numPending++;
+ }
+ }
+ if (status != IEEE154_SUCCESS)
+ signal DataRequest.pollDone[client]();
+ return status;
+ }
+
+ void buildDataRequestFrame(uint8_t destAddrMode, uint16_t destPANId,
+ uint8_t* destAddrPtrLE, uint8_t srcAddrMode, ieee154_txframe_t *txFrame)
+ {
+ // destAddrPtrLE points to an address in little-endian format !
+ ieee154_address_t srcAddress;
+ uint8_t *mhr;
+ uint16_t srcPANId;
+ ieee154_address_t DstAddr;
+ srcPANId = call MLME_GET.macPANId();
+
+ memcpy(&DstAddr, destAddrPtrLE, destAddrMode == 2 ? 2 : 8);
+ mhr = txFrame->header->mhr;
+ mhr[MHR_INDEX_FC1] = FC1_FRAMETYPE_CMD | FC1_ACK_REQUEST;
+ if (destAddrMode >= 2 && srcAddrMode >= 2 && destPANId == srcPANId)
+ mhr[MHR_INDEX_FC1] |= FC1_PAN_ID_COMPRESSION;
+ mhr[MHR_INDEX_FC2] = destAddrMode << FC2_DEST_MODE_OFFSET;
+ mhr[MHR_INDEX_FC2] |= srcAddrMode << FC2_SRC_MODE_OFFSET;
+ if (srcAddrMode == 2)
+ srcAddress.shortAddress = call MLME_GET.macShortAddress();
+ else
+ srcAddress.extendedAddress = call LocalExtendedAddress.get();
+ txFrame->headerLen = call FrameUtility.writeHeader(
+ txFrame->header->mhr,
+ destAddrMode,
+ destPANId,
+ &DstAddr,
+ srcAddrMode,
+ srcPANId,
+ &srcAddress,
+ (mhr[MHR_INDEX_FC1] & FC1_PAN_ID_COMPRESSION) ? TRUE: FALSE);
+ txFrame->payload = &m_dataRequestCmdID;
+ txFrame->payloadLen = 1;
+ }
+
+ event message_t* DataExtracted.received(message_t* frame, ieee154_txframe_t *txFrame)
+ {
+ if (!txFrame){
+ call Debug.log(LEVEL_CRITICAL, PollP_INTERNAL_ERROR, 0, 0, 0);
+ return frame;
+ } else
+ call Debug.log(LEVEL_INFO, PollP_SUCCESS, 0, 0, 0);
+ if (txFrame->handle == HANDLE_MLME_POLL_REQUEST)
+ signal MLME_POLL.confirm(IEEE154_SUCCESS);
+ else
+ signal DataRequest.pollDone[txFrame->handle]();
+ txFrame->handle = HANDLE_MLME_POLL_SUCCESS; // mark as processed
+ // TODO: check if pending bit is set (then initiate another POLL)
+ call Debug.log(LEVEL_IMPORTANT, PollP_RX, txFrame->handle, 0, 0);
+ return signal DataRx.received(frame);
+ }
+
+ event void PollTx.transmitDone(ieee154_txframe_t *txFrame, ieee154_status_t status)
+ {
+ call Debug.log(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?
+ status = IEEE154_NO_DATA;
+ if (txFrame->handle == HANDLE_MLME_POLL_REQUEST)
+ signal MLME_POLL.confirm(status);
+ else
+ signal DataRequest.pollDone[txFrame->handle]();
+ }
+ call TxControlPool.put((ieee154_txcontrol_t*) ((uint8_t*) txFrame->header - offsetof(ieee154_txcontrol_t, header)));
+ call TxFramePool.put(txFrame);
+ }
+ default event void MLME_POLL.confirm(ieee154_status_t status){}
+ default event void DataRequest.pollDone[uint8_t client](){}
+}
--- /dev/null
+This directory contains "TKN15.4", a platform-independent IEEE 802.15.4-2006
+MAC implementation. The code is still under active development, but most of the
+functionality described in the standard is implemented. 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 the timing is not standard compliant).
+
+Status 6/16/08
+--------------
+
+missing functionality:
+
+- security (not planned)
+- GTS (not planned)
+- non-beacon-enabled mode
+- PAN ID conflict resolution
+- multiple indirect transmissions to the same destination
+- documentation
+
+Implementation
+--------------
+
+MAC implementation: tinyos-2.x/tos/lib/mac/tkn154
+MAC interfaces: tinyos-2.x/tos/lib/mac/tkn154/interfaces
+CC2420 driver: tinyos-2.x/tos/chips/cc2420_tkn154
+TelosB "platform glue" code: tinyos-2.x/tos/platforms/telosb/mac/tkn154
+Example applications: tinyos-2.x/apps/tests/tkn154
+
+Copyright
+---------
+
+This work was supported by the the European Commision within the 6th Framework
+Project 2005-IST-5-033406-STP (ANGEL project)
+
+Author: Jan-Hinrich Hauer <hauer@tkn.tu-berlin.de>
+
+/*
+ * 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.
+ */
+
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+#include "TKN154_MAC.h"
+generic configuration RadioClientC()
+{
+ provides
+ {
+ interface RadioRx;
+ interface RadioTx;
+ interface RadioOff;
+ interface Resource as Token;
+ interface ResourceRequested as TokenRequested;
+ interface ResourceTransfer;
+ interface ResourceTransferred;
+ interface ResourceTransferConnector as TransferFrom;
+ interface GetNow<bool> as IsResourceRequested;
+ } uses {
+ interface ResourceTransferConnector as TransferTo;
+ }
+}
+implementation
+{
+ enum {
+ CLIENT = unique(IEEE802154_RADIO_RESOURCE),
+ };
+
+ components FrameDispatchP;
+ RadioRx = FrameDispatchP.RadioRx[CLIENT];
+ RadioTx = FrameDispatchP.RadioTx[CLIENT];
+ RadioOff = FrameDispatchP.RadioOff[CLIENT];
+ Token = FrameDispatchP.Token[CLIENT];
+ IsResourceRequested = FrameDispatchP.IsResourceRequested;
+ TokenRequested = FrameDispatchP.TokenRequested[CLIENT];
+
+ components new TransferClientP(CLIENT);
+ ResourceTransfer = TransferClientP;
+ ResourceTransferred = TransferClientP;
+ TransferTo = TransferClientP;
+ TransferFrom = TransferClientP;
+ TransferClientP.ResourceTransferControl -> FrameDispatchP;
+ TransferClientP.Leds -> FrameDispatchP;
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#include "TKN154_PHY.h"
+#include "TKN154_MAC.h"
+module RxEnableP
+{
+ provides
+ {
+ interface Init;
+ interface MLME_RX_ENABLE;
+ interface SplitControl as PromiscuousMode;
+ interface FrameRx;
+ interface Get<bool> as PromiscuousModeGet;
+ interface GetNow<bool> as IsRxEnableActive;
+ interface Notify<bool> as RxEnableStateChange;
+ }
+ uses
+ {
+ interface Resource as Token;
+ interface RadioRx as PromiscuousRx;
+ interface RadioOff;
+ interface Set<bool> as RadioPromiscuousMode;
+ interface Ieee802154Debug as Debug;
+ interface Timer<TSymbolIEEE802154> as RxEnableTimer;
+ interface Get<bool> as IsBeaconEnabledPAN;
+ interface Get<ieee154_macPanCoordinator_t> as IsMacPanCoordinator;
+ interface Get<bool> as IsTrackingBeacons;
+ interface GetNow<uint32_t> as IncomingSfStart;
+ interface GetNow<uint32_t> as IncomingBeaconInterval;
+ interface Get<bool> as IsSendingBeacons;
+ interface GetNow<uint32_t> as OutgoingSfStart;
+ interface GetNow<uint32_t> as OutgoingBeaconInterval;
+ interface Notify<bool> as WasRxEnabled;
+ interface TimeCalc;
+ }
+}
+implementation
+{
+ enum promiscuous_state {
+ S_IDLE,
+ S_STARTING,
+ S_STARTED,
+ S_STOPPING,
+ } m_promiscuousState;
+
+ uint32_t m_rxOnDuration;
+ uint32_t m_rxOnOffset;
+ uint32_t m_rxOnAnchor;
+ norace bool m_isRxEnabled;
+ bool m_isRxEnableConfirmPending;
+
+ task void prepareDoneTask();
+ task void radioOffDoneTask();
+
+ command error_t Init.init()
+ {
+ if (m_isRxEnableConfirmPending){
+ m_isRxEnableConfirmPending = FALSE;
+ signal MLME_RX_ENABLE.confirm(IEEE154_SUCCESS);
+ }
+ m_isRxEnabled = FALSE;
+ call RxEnableTimer.stop();
+ return SUCCESS;
+ }
+
+/* ----------------------- 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.get()){
+ if (call IsSendingBeacons.get() && call IsMacPanCoordinator.get()){
+ // for OUTGOING SUPERFRAME
+ lastBeaconTime = call OutgoingSfStart.getNow();
+ beaconInterval = call OutgoingBeaconInterval.getNow();
+ } else if (call IsTrackingBeacons.get()){
+ // 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
+ RxOnTime += beaconInterval;
+ }
+ }
+ 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);
+ }
+ }
+ signal RxEnableStateChange.notify(TRUE);
+ }
+
+ async command bool IsRxEnableActive.getNow()
+ {
+ return m_isRxEnabled;
+ }
+
+ 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;}
+
+/* ----------------------- 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(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(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(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);
+ } else
+ return frame;
+ }
+
+ 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(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){}
+ default event void MLME_RX_ENABLE.confirm(ieee154_status_t status){}
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#include "TKN154_MAC.h"
+module ScanP
+{
+ provides
+ {
+ interface Init;
+ interface MLME_SCAN;
+ interface MLME_BEACON_NOTIFY;
+ }
+ uses
+ {
+ interface MLME_GET;
+ interface MLME_SET;
+ interface EnergyDetection;
+ interface RadioOff;
+ interface RadioRx;
+ interface RadioTx;
+ interface IEEE154Frame as Frame;
+ interface IEEE154BeaconFrame as BeaconFrame;
+ interface Timer<TSymbolIEEE802154> as ScanTimer;
+ interface Pool<ieee154_txframe_t> as TxFramePool;
+ interface Pool<ieee154_txcontrol_t> as TxControlPool;
+ interface Resource as Token;
+ interface FrameUtility;
+ interface Leds;
+ }
+}
+implementation
+{
+ enum {
+ MAX_PAYLOAD_SIZE = 1,
+ };
+
+ ieee154_txframe_t *m_txFrame = NULL;
+ uint8_t m_payload[MAX_PAYLOAD_SIZE];
+ uint8_t m_scanType;
+ uint32_t m_scanChannels;
+ uint32_t m_unscannedChannels;
+ ieee154_macAutoRequest_t m_macAutoRequest;
+ norace uint32_t m_currentChannelBit;
+ norace uint8_t m_currentChannelNum;
+ void* m_resultList;
+ uint8_t m_resultListNumEntries;
+ uint8_t m_resultIndex;
+ ieee154_macPANId_t m_PANID;
+ norace uint32_t m_scanDuration;
+ bool m_busy = FALSE;
+
+ void nextIteration();
+ task void startTimerTask();
+ task void nextIterationTask();
+
+ command error_t Init.init()
+ {
+ // 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
+ }
+ return SUCCESS;
+ }
+
+/* ----------------------- 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 (
+ uint8_t ScanType,
+ uint32_t ScanChannels,
+ uint8_t ScanDuration,
+ uint8_t ChannelPage,
+ uint8_t EnergyDetectListNumEntries,
+ int8_t* EnergyDetectList,
+ uint8_t PANDescriptorListNumEntries,
+ ieee154_PANDescriptor_t* PANDescriptorList,
+ ieee154_security_t *security
+ )
+ {
+ ieee154_status_t status = IEEE154_SUCCESS;
+ ieee154_phyChannelsSupported_t supportedChannels = call MLME_GET.phyChannelsSupported();
+ 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 &&
+ !(m_txFrame = call TxFramePool.get())) {
+ status = IEEE154_TRANSACTION_OVERFLOW;
+ } else if (ScanType != ENERGY_DETECTION_SCAN &&
+ !(txControl = call TxControlPool.get())) {
+ call TxFramePool.put(m_txFrame);
+ m_txFrame = NULL;
+ status = IEEE154_TRANSACTION_OVERFLOW;
+ } else {
+ m_txFrame->header = &txControl->header;
+ m_txFrame->payload = m_payload;
+ m_txFrame->metadata = &txControl->metadata;
+ m_busy = TRUE;
+ m_scanType = ScanType;
+ m_scanChannels = ScanChannels;
+ m_scanDuration = (((uint32_t) 1 << ScanDuration) + 1) * IEEE154_aBaseSuperframeDuration;
+ m_macAutoRequest = call MLME_GET.macAutoRequest();
+ m_PANID = call MLME_GET.macPANId();
+ m_unscannedChannels = 0;
+ m_currentChannelBit = 1;
+ m_currentChannelNum = 0;
+ m_resultIndex = 0;
+ if (ScanType == ENERGY_DETECTION_SCAN){
+ m_resultList = EnergyDetectList;
+ m_resultListNumEntries = EnergyDetectListNumEntries;
+ } else {
+ m_resultList = PANDescriptorList;
+ m_resultListNumEntries = PANDescriptorListNumEntries;
+ }
+ if (m_resultList == NULL)
+ m_resultListNumEntries = 0;
+ call Token.request();
+ }
+ return status;
+ }
+
+ 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
+ m_txFrame->header->mhr[MHR_INDEX_FC1] = FC1_FRAMETYPE_CMD;
+ m_txFrame->header->mhr[MHR_INDEX_FC2] = FC2_DEST_MODE_SHORT;
+ m_txFrame->header->mhr[MHR_INDEX_SEQNO] = dsn;
+ call MLME_SET.macDSN(dsn+1);
+ for (i=0; i<4; i++) // broadcast dest PAN ID + broadcast dest addr
+ m_txFrame->header->mhr[MHR_INDEX_ADDRESS + i] = 0xFF;
+ m_txFrame->headerLen = 7;
+ m_payload[0] = CMD_FRAME_BEACON_REQUEST;
+ m_txFrame->payloadLen = 1;
+ // fall through
+ case PASSIVE_SCAN:
+ call MLME_SET.macPANId(bcastPANID);
+ break;
+ case ORPHAN_SCAN:
+ // orphan notification frame
+ m_scanDuration = call MLME_GET.macResponseWaitTime();
+ m_txFrame->header->mhr[MHR_INDEX_FC1] = FC1_FRAMETYPE_CMD | FC1_PAN_ID_COMPRESSION;
+ m_txFrame->header->mhr[MHR_INDEX_FC2] = FC2_SRC_MODE_EXTENDED | FC2_DEST_MODE_SHORT;
+ m_txFrame->header->mhr[MHR_INDEX_SEQNO] = dsn;
+ call MLME_SET.macDSN(dsn+1);
+ for (i=0; i<4; i++) // broadcast dest PAN ID + broadcast dest addr
+ m_txFrame->header->mhr[MHR_INDEX_ADDRESS + i] = 0xFF;
+ call FrameUtility.copyLocalExtendedAddressLE((uint8_t*) &(m_txFrame->header[MHR_INDEX_ADDRESS + i]));
+ m_txFrame->headerLen = 15;
+ m_payload[0] = CMD_FRAME_ORPHAN_NOTIFICATION;
+ m_txFrame->payloadLen = 1;
+ break;
+ }
+ nextIteration();
+ }
+
+ void nextIteration()
+ {
+ error_t radioStatus = SUCCESS;
+ uint32_t supportedChannels = IEEE154_SUPPORTED_CHANNELS;
+ atomic {
+ while (!(m_scanChannels & m_currentChannelBit & supportedChannels) && m_currentChannelNum < 27){
+ m_unscannedChannels |= m_currentChannelBit;
+ m_currentChannelBit <<= 1;
+ m_currentChannelNum++;
+ }
+ }
+ 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:
+ radioStatus = call EnergyDetection.start(m_scanDuration);
+ 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;
+ }
+ m_unscannedChannels &= m_scanChannels; // only channels that were requested
+ if (m_scanType != ENERGY_DETECTION_SCAN && !m_resultIndex)
+ result = IEEE154_NO_BEACON;
+ 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);
+ }
+ m_txFrame = NULL;
+ if (call Token.isOwner())
+ call Token.release();
+ m_busy = FALSE;
+ signal MLME_SCAN.confirm (
+ result,
+ m_scanType,
+ IEEE154_SUPPORTED_CHANNELPAGE,
+ m_unscannedChannels,
+ (m_scanType == ENERGY_DETECTION_SCAN) ? m_resultIndex : 0,
+ (m_scanType == ENERGY_DETECTION_SCAN) ? (uint8_t*) m_resultList : NULL,
+ ((m_scanType == ACTIVE_SCAN ||
+ 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)
+ {
+ if (status == SUCCESS && m_resultListNumEntries)
+ ((uint8_t*) m_resultList)[m_resultIndex++] = EnergyLevel;
+ else
+ m_unscannedChannels |= m_currentChannelBit;
+ if (m_resultIndex == m_resultListNumEntries)
+ m_currentChannelNum = 27; // done
+ else
+ m_currentChannelNum++;
+ call RadioOff.off();
+ }
+
+/* ----------------------- Active/Orphan scan ----------------------- */
+
+ async event void RadioTx.loadDone()
+ {
+ call RadioTx.transmit(0, 0, 0, FALSE);
+ }
+
+ async event void RadioTx.transmitDone(ieee154_txframe_t *frame,
+ ieee154_reftime_t *referenceTime, bool ackPendingFlag, error_t error)
+ {
+ 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();
+ }
+ } else if ((((ieee154_header_t*) frame->header)->mhr[0] & FC1_FRAMETYPE_MASK) == FC1_FRAMETYPE_BEACON) {
+ // PASSIVE_SCAN / ACTIVE_SCAN
+ if (!m_macAutoRequest)
+ return signal MLME_BEACON_NOTIFY.indication (frame);
+ else if (m_resultListNumEntries && m_resultIndex < m_resultListNumEntries &&
+ call BeaconFrame.parsePANDescriptor(
+ frame,
+ 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()
+ {
+ call ScanTimer.startOneShot(m_scanDuration);
+ }
+
+ event void ScanTimer.fired()
+ {
+ call RadioOff.off();
+ }
+
+ async event void RadioOff.offDone()
+ {
+ m_currentChannelBit <<= 1;
+ m_currentChannelNum++;
+ post nextIterationTask();
+ }
+
+ task void nextIterationTask()
+ {
+ nextIteration();
+ }
+
+ default event message_t* MLME_BEACON_NOTIFY.indication ( message_t *beaconFrame ){return beaconFrame;}
+ default event void MLME_SCAN.confirm (
+ ieee154_status_t status,
+ uint8_t ScanType,
+ uint8_t ChannelPage,
+ uint32_t UnscannedChannels,
+ uint8_t EnergyDetectListNumEntries,
+ int8_t* EnergyDetectList,
+ uint8_t PANDescriptorListNumEntries,
+ ieee154_PANDescriptor_t* PANDescriptorList
+ ){}
+}
--- /dev/null
+/*
+ * "Copyright (c) 2005 Washington University in St. Louis.
+ * All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose, without fee, and without written agreement is
+ * hereby granted, provided that the above copyright notice, the following
+ * two paragraphs and the author appear in all copies of this software.
+ *
+ * IN NO EVENT SHALL WASHINGTON UNIVERSITY IN ST. LOUIS BE LIABLE TO ANY PARTY
+ * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
+ * OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF WASHINGTON
+ * UNIVERSITY IN ST. LOUIS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * WASHINGTON UNIVERSITY IN ST. LOUIS SPECIFICALLY DISCLAIMS ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
+ * ON AN "AS IS" BASIS, AND WASHINGTON UNIVERSITY IN ST. LOUIS HAS NO
+ * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
+ * MODIFICATIONS."
+ */
+
+/*
+ * Copyright (c) 2004, Technische Universitat 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 Universitat 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.
+*/
+
+/**
+ * Please refer to TEP 108 for more information about this component and its
+ * intended use.<br><br>
+ *
+ * This component provides the Resource, ArbiterInfo, and Resource
+ * Controller interfaces and uses the ResourceConfigure interface as
+ * described in TEP 108. It provides arbitration to a shared resource in
+ * an FCFS fashion. An array is used to keep track of which users have put
+ * in requests for the resource. Upon the release of the resource by one
+ * of these users, the array is checked and the next user (in FCFS order)
+ * that has a pending request will ge granted control of the resource. If
+ * there are no pending requests, then the resource becomes idle and any
+ * user can put in a request and immediately receive access to the
+ * Resource.
+ *
+ * @param <b>resourceName</b> -- The name of the Resource being shared
+ *
+ * @author Kevin Klues (klues@tkn.tu-berlin.de)
+ * @author Philip Levis
+ */
+
+generic configuration SimpleRoundRobinTransferArbiterC(char resourceName[]) {
+ provides {
+ interface Resource[uint8_t id];
+ interface ResourceRequested[uint8_t id];
+ interface ResourceTransferControl;
+ interface ArbiterInfo;
+ interface GetNow<bool> as IsResourceRequested;
+ }
+ uses interface ResourceConfigure[uint8_t id];
+}
+implementation {
+ components MainC;
+ components new RoundRobinResourceQueueC(uniqueCount(resourceName)) as Queue;
+ components new SimpleTransferArbiterP() as Arbiter;
+
+ MainC.SoftwareInit -> Queue;
+
+ Resource = Arbiter;
+ ResourceRequested = Arbiter;
+ ArbiterInfo = Arbiter;
+ ResourceConfigure = Arbiter;
+ ResourceTransferControl = Arbiter;
+ IsResourceRequested = Arbiter;
+
+ Arbiter.Queue -> Queue;
+}
--- /dev/null
+/*
+ * Copyright (c) 2004, Technische Universitat 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 Universitat 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.
+*/
+
+/**
+ * Please refer to TEP 108 for more information about this component and its
+ * intended use.<br><br>
+ *
+ * This component provides the Resource, ArbiterInfo, and ResourceRequested
+ * interfaces and uses the ResourceConfigure interface as
+ * described in TEP 108. It provides arbitration to a shared resource.
+ * An queue is used to keep track of which users have put
+ * in requests for the resource. Upon the release of the resource by one
+ * of these users, the queue is checked and the next user
+ * that has a pending request will ge granted control of the resource. If
+ * there are no pending requests, then the resource becomes idle and any
+ * user can put in a request and immediately receive access to the
+ * Resource.
+ *
+ * @author Kevin Klues (klues@tkn.tu-berlin.de)
+ * @author Philip Levis
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de> (added resource transfer)
+ */
+
+generic module SimpleTransferArbiterP() {
+ provides {
+ interface Resource[uint8_t id];
+ interface ResourceRequested[uint8_t id];
+ interface ResourceTransferControl;
+ interface ArbiterInfo;
+ interface GetNow<bool> as IsResourceRequested;
+ }
+ uses {
+ interface ResourceConfigure[uint8_t id];
+ interface ResourceQueue as Queue;
+ }
+}
+implementation {
+
+ enum {RES_IDLE = 0, RES_GRANTING = 1, RES_BUSY = 2};
+ enum {NO_RES = 0xFF};
+
+ uint8_t state = RES_IDLE;
+ norace uint8_t resId = NO_RES;
+ norace uint8_t reqResId;
+ norace uint8_t numTransfers;
+ norace bool reqWhileTransferred;
+
+ task void grantedTask();
+ task void checkResourceRequestedTask();
+
+ async command error_t Resource.request[uint8_t id]() {
+ signal ResourceRequested.requested[resId]();
+ atomic {
+ if (numTransfers > 0)
+ reqWhileTransferred = TRUE;
+ if(state == RES_IDLE) {
+ state = RES_GRANTING;
+ reqResId = id;
+ post grantedTask();
+ return SUCCESS;
+ }
+ return call Queue.enqueue(id);
+ }
+ }
+
+ async command error_t Resource.immediateRequest[uint8_t id]() {
+ signal ResourceRequested.immediateRequested[resId]();
+ atomic {
+ if(state == RES_IDLE) {
+ state = RES_BUSY;
+ resId = id;
+ call ResourceConfigure.configure[resId]();
+ return SUCCESS;
+ }
+ return FAIL;
+ }
+ }
+
+ async command error_t Resource.release[uint8_t id]() {
+ bool released = FALSE;
+ atomic {
+ if(state == RES_BUSY && resId == id) {
+ numTransfers = 0;
+ reqWhileTransferred = FALSE;
+ if(call Queue.isEmpty() == FALSE) {
+ reqResId = call Queue.dequeue();
+ state = RES_GRANTING;
+ post grantedTask();
+ }
+ else {
+ resId = NO_RES;
+ state = RES_IDLE;
+ }
+ released = TRUE;
+ }
+ }
+ if(released == TRUE) {
+ call ResourceConfigure.unconfigure[id]();
+ return SUCCESS;
+ }
+ return FAIL;
+ }
+
+ async command bool IsResourceRequested.getNow()
+ {
+ return reqWhileTransferred;
+ }
+
+ task void checkResourceRequestedTask()
+ {
+ if (numTransfers && reqWhileTransferred)
+ signal ResourceRequested.requested[resId]();
+ }
+
+ async command error_t ResourceTransferControl.transfer(uint8_t fromClient, uint8_t toClient)
+ {
+ atomic {
+ if (call ArbiterInfo.userId() == fromClient){
+ numTransfers += 1;
+ call ResourceConfigure.unconfigure[fromClient]();
+ call ResourceConfigure.configure[resId]();
+ resId = toClient;
+ post checkResourceRequestedTask();
+ return SUCCESS;
+ }
+ }
+ return FAIL;
+ }
+
+ async command error_t ResourceTransferControl.release(uint8_t client)
+ {
+ return call Resource.release[client]();
+ }
+
+ /**
+ Check if the Resource is currently in use
+ */
+ async command bool ArbiterInfo.inUse() {
+ atomic {
+ if (state == RES_IDLE)
+ return FALSE;
+ }
+ return TRUE;
+ }
+
+ /**
+ Returns the current user of the Resource.
+ If there is no current user, the return value
+ will be 0xFF
+ */
+ async command uint8_t ArbiterInfo.userId() {
+ atomic {
+ if(state != RES_BUSY)
+ return NO_RES;
+ return resId;
+ }
+ }
+
+ /**
+ * Returns whether you are the current owner of the resource or not
+ */
+ async command uint8_t Resource.isOwner[uint8_t id]() {
+ atomic {
+ if(resId == id && state == RES_BUSY) return TRUE;
+ else return FALSE;
+ }
+ }
+
+ task void grantedTask() {
+ atomic {
+ resId = reqResId;
+ state = RES_BUSY;
+ }
+ call ResourceConfigure.configure[resId]();
+ signal Resource.granted[resId]();
+ }
+
+ //Default event/command handlers
+ default event void Resource.granted[uint8_t id]() {
+ }
+ default async event void ResourceRequested.requested[uint8_t id]() {
+ }
+ default async event void ResourceRequested.immediateRequested[uint8_t id]() {
+ }
+ default async command void ResourceConfigure.configure[uint8_t id]() {
+ }
+ default async command void ResourceConfigure.unconfigure[uint8_t id]() {
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#ifndef __TKN154_H
+#define __TKN154_H
+
+
+/****************************************************
+ * IEEE 802.15.4 Enumerations
+ */
+
+typedef enum ieee154_status
+{
+ IEEE154_SUCCESS = 0x00,
+ IEEE154_BEACON_LOSS = 0xE0,
+ IEEE154_CHANNEL_ACCESS_FAILURE = 0xE1,
+ IEEE154_COUNTER_ERROR = 0xDB,
+ IEEE154_DENIED = 0xE2,
+ IEEE154_DISABLE_TRX_FAILURE = 0xE3,
+ IEEE154_FRAME_TOO_LONG = 0xE5,
+ IEEE154_IMPROPER_KEY_TYPE = 0xDC,
+ IEEE154_IMPROPER_SECURITY_LEVEL = 0xDD,
+ IEEE154_INVALID_ADDRESS = 0xF5,
+ IEEE154_INVALID_GTS = 0xE6,
+ IEEE154_INVALID_HANDLE = 0xE7,
+ IEEE154_INVALID_INDEX = 0xF9,
+ IEEE154_INVALID_PARAMETER = 0xE8,
+ IEEE154_LIMIT_REACHED = 0xFA,
+ IEEE154_NO_ACK = 0xE9,
+ IEEE154_NO_BEACON = 0xEA,
+ IEEE154_NO_DATA = 0xEB,
+ IEEE154_NO_SHORT_ADDRESS = 0xEC,
+ IEEE154_ON_TIME_TOO_LONG = 0xF6,
+ IEEE154_OUT_OF_CAP = 0xED,
+ IEEE154_PAN_ID_CONFLICT = 0xEE,
+ IEEE154_PAST_TIME = 0xF7,
+ IEEE154_READ_ONLY = 0xFB,
+ IEEE154_REALIGNMENT = 0xEF,
+ IEEE154_SCAN_IN_PROGRESS = 0xFC,
+ IEEE154_SECURITY_ERROR = 0xE4, //FAILED_SECURITY_CHECK = 0xE4 //802.15.4_2003
+ IEEE154_SUPERFRAME_OVERLAP = 0xFD,
+ IEEE154_TRACKING_OFF = 0xF8,
+ IEEE154_TRANSACTION_EXPIRED = 0xF0,
+ IEEE154_TRANSACTION_OVERFLOW = 0xF1,
+ IEEE154_TX_ACTIVE = 0xF2,
+ IEEE154_UNAVAILABLE_KEY = 0xF3,
+ IEEE154_UNSUPPORTED_ATTRIBUTE = 0xF4,
+ IEEE154_UNSUPPORTED_LEGACY = 0xDE,
+ IEEE154_UNSUPPORTED_SECURITY = 0xDF,
+} ieee154_status_t;
+
+typedef enum ieee154_association_status
+{
+ IEEE154_ASSOCIATION_SUCCESSFUL = 0x00,
+ IEEE154_PAN_AT_CAPACITY = 0x01,
+ IEEE154_ACCESS_DENIED = 0x02
+} ieee154_association_status_t;
+
+typedef enum ieee154_disassociation_reason
+{
+ IEEE154_COORDINATOR_WISHES_DEVICE_TO_LEAVE = 0x01,
+ IEEE154_DEVICE_WISHES_TO_LEAVE = 0x02
+} ieee154_disassociation_reason_t;
+
+typedef union ieee154_address {
+ // Whether this is a short or extended address
+ // depends on the respective addressing mode
+ uint16_t shortAddress;
+ uint64_t extendedAddress;
+} ieee154_address_t;
+
+typedef struct ieee154_security {
+ // Whether the first 0, 4 or 8 byte of KeySource
+ // are valid depends on the KeyIdMode parameter
+ uint8_t SecurityLevel;
+ uint8_t KeyIdMode;
+ uint8_t KeySource[8];
+ uint8_t KeyIndex;
+} ieee154_security_t;
+
+typedef nx_struct
+{
+ nxle_uint8_t AlternatePANCoordinator :1;
+ nxle_uint8_t DeviceType :1;
+ nxle_uint8_t PowerSource :1;
+ nxle_uint8_t ReceiverOnWhenIdle :1;
+ nxle_uint8_t Reserved :2;
+ nxle_uint8_t SecurityCapability :1;
+ nxle_uint8_t AllocateAddress :1;
+} ieee154_CapabilityInformation_t;
+
+typedef nx_struct
+{
+ nxle_uint8_t BeaconOrder :4;
+ nxle_uint8_t SuperframeOrder :4;
+ nxle_uint8_t FinalCAPSlot :4;
+ nxle_uint8_t BatteryLifeExtension :1;
+ nxle_uint8_t Reserved :1;
+ nxle_uint8_t PANCoordinator :1;
+ nxle_uint8_t AssociationPermit :1;
+} ieee154_SuperframeSpec_t;
+
+typedef struct ieee154_PANDescriptor {
+ uint8_t CoordAddrMode;
+ uint16_t CoordPANId;
+ ieee154_address_t CoordAddress;
+ uint8_t LogicalChannel;
+ uint8_t ChannelPage;
+ ieee154_SuperframeSpec_t SuperframeSpec;
+ bool GTSPermit;
+ uint8_t LinkQuality;
+ uint32_t TimeStamp;
+ ieee154_status_t SecurityFailure;
+ uint8_t SecurityLevel;
+ uint8_t KeyIdMode;
+ uint64_t KeySource;
+ uint8_t KeyIndex;
+} ieee154_PANDescriptor_t;
+
+enum {
+ // Values for the PANType parameter of the MLME_RESET.request primitive
+ BEACON_ENABLED_PAN,
+ NONBEACON_ENABLED_PAN,
+
+ // Values for the TxOptions parameter of MCPS_DATA.request()
+ TX_OPTIONS_ACK = 0x01,
+ TX_OPTIONS_GTS = 0x02,
+ TX_OPTIONS_INDIRECT = 0x04,
+
+ // Values for Destination/Source Addressing Mode (MCPS_DATA.request(), etc.)
+ ADDR_MODE_NOT_PRESENT = 0x00,
+ ADDR_MODE_RESERVED = 0x01,
+ ADDR_MODE_SHORT_ADDRESS = 0x02,
+ ADDR_MODE_EXTENDED_ADDRESS = 0x03,
+
+ // ScanType parameter for MLME-SCAN primitive
+ ENERGY_DETECTION_SCAN = 0x00,
+ ACTIVE_SCAN = 0x01,
+ PASSIVE_SCAN = 0x02,
+ ORPHAN_SCAN = 0x03,
+
+ // Frame types
+ FRAMETYPE_BEACON = 0x00,
+ FRAMETYPE_DATA = 0x01,
+ FRAMETYPE_ACK = 0x02,
+ FRAMETYPE_CMD = 0x03,
+};
+
+/****************************************************
+ * typedefs PIB value types
+ */
+
+typedef uint8_t ieee154_phyCurrentChannel_t;
+typedef uint32_t ieee154_phyChannelsSupported_t;
+typedef uint8_t ieee154_phyTransmitPower_t;
+typedef uint8_t ieee154_phyCCAMode_t;
+typedef uint8_t ieee154_phyCurrentPage_t;
+typedef uint16_t ieee154_phyMaxFrameDuration_t;
+typedef uint8_t ieee154_phySHRDuration_t;
+typedef uint8_t ieee154_phySymbolsPerOctet_t;
+
+typedef uint8_t ieee154_macAckWaitDuration_t;
+typedef bool ieee154_macAssociatedPANCoord_t;
+typedef bool ieee154_macAssociationPermit_t;
+typedef bool ieee154_macAutoRequest_t;
+typedef bool ieee154_macBattLifeExt_t;
+typedef uint8_t ieee154_macBattLifeExtPeriods_t;
+typedef uint8_t* ieee154_macBeaconPayload_t;
+typedef uint8_t ieee154_macBeaconPayloadLength_t;
+typedef uint8_t ieee154_macBeaconOrder_t;
+typedef uint32_t ieee154_macBeaconTxTime_t;
+typedef uint8_t ieee154_macBSN_t;
+typedef uint64_t ieee154_macCoordExtendedAddress_t;
+typedef uint16_t ieee154_macCoordShortAddress_t;
+typedef uint8_t ieee154_macDSN_t;
+typedef bool ieee154_macGTSPermit_t;
+typedef uint8_t ieee154_macMaxBE_t;
+typedef uint8_t ieee154_macMaxCSMABackoffs_t;
+typedef uint32_t ieee154_macMaxFrameTotalWaitTime_t;
+typedef uint8_t ieee154_macMaxFrameRetries_t;
+typedef uint8_t ieee154_macMinBE_t;
+typedef uint8_t ieee154_macMinLIFSPeriod_t;
+typedef uint8_t ieee154_macMinSIFSPeriod_t;
+typedef uint16_t ieee154_macPANId_t;
+typedef bool ieee154_macPromiscuousMode_t;
+typedef uint8_t ieee154_macResponseWaitTime_t;
+typedef bool ieee154_macRxOnWhenIdle_t;
+typedef bool ieee154_macSecurityEnabled_t;
+typedef uint16_t ieee154_macShortAddress_t;
+typedef uint8_t ieee154_macSuperframeOrder_t;
+typedef uint16_t ieee154_macSyncSymbolOffset_t;
+typedef bool ieee154_macTimestampSupported_t;
+typedef uint16_t ieee154_macTransactionPersistenceTime_t;
+
+// own typedefs
+typedef bool ieee154_macPanCoordinator_t;
+
+// When security is implemented the following line should be commented out
+#define IEEE154_SECURITY_DISABLED
+
+/****************************************************
+ * Static memory allocation for Queue/Pool
+ */
+
+#ifndef TXFRAME_POOL_SIZE
+#define TXFRAME_POOL_SIZE 5
+#endif
+
+#ifndef TXCONTROL_POOL_SIZE
+#define TXCONTROL_POOL_SIZE 5
+#endif
+
+#ifndef CAP_TX_QUEUE_SIZE
+#define CAP_TX_QUEUE_SIZE 10
+#endif
+
+#ifndef INDIRECT_TX_QUEUE_SIZE
+#define INDIRECT_TX_QUEUE_SIZE 7
+#endif
+
+#ifndef MAX_PENDING_ASSOC_RESPONSES
+#define MAX_PENDING_ASSOC_RESPONSES INDIRECT_TX_QUEUE_SIZE
+#endif
+
+enum {
+ // PHY sublayer constant needed to calculate mpdu size
+ IEEE154_aMaxPHYPacketSize = 127,
+};
+
+#endif // __TKN154_H
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#include "TKN154_PHY.h"
+#include "TKN154_MAC.h"
+#include "TKN154_PIB.h"
+#include "TKN154_DEBUG.h"
+
+configuration TKN154P
+{
+ 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 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 Ieee802154Debug[uint8_t client];
+ interface LocalTime<TSymbolIEEE802154>;
+ interface Random;
+ interface Leds;
+ }
+}
+implementation
+{
+ components
+#ifndef IEEE154_SCAN_DISABLED
+ ScanP,
+#else
+ NoScanP as ScanP,
+#endif
+ DataP,
+ AssociateP,
+ PollP,
+ RxEnableP,
+ IndirectTxP,
+ PibP,
+ FrameDispatchP,
+
+#ifndef IEEE154_BEACON_SYNC_DISABLED
+ BeaconSynchronizeP,
+ new CapQueueP() as DeviceCapQueue,
+ new CapP(INCOMING_SUPERFRAME) as DeviceCap,
+#else
+ NoBeaconSynchronizeP as BeaconSynchronizeP,
+ new NoCapQueueP() as DeviceCapQueue,
+ new NoCapP() as DeviceCap,
+#endif
+ NoDeviceCfpP as DeviceCfp,
+
+#ifndef IEEE154_BEACON_TX_DISABLED
+ BeaconTransmitP,
+ new CapQueueP() as CoordCapQueue,
+ new CapP(OUTGOING_SUPERFRAME) as CoordCap,
+#else
+ NoBeaconTransmitP as BeaconTransmitP,
+ new NoCapQueueP() as CoordCapQueue,
+ new NoCapP() as CoordCap,
+#endif
+ NoCoordCfpP as CoordCfp,
+
+ CoordRealignmentP,
+ CoordBroadcastP,
+ 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_BEACON_NOTIFY = BeaconSynchronizeP;
+ MLME_BEACON_NOTIFY = ScanP;
+ MLME_COMM_STATUS = AssociateP;
+ MLME_COMM_STATUS = CoordRealignmentP;
+ MLME_DISASSOCIATE = AssociateP;
+ 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 = RxEnableP;
+ 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.FrameUtility -> PibP;
+ ScanP.Leds = Leds;
+
+/* ----------------- Beacon Transmission (MLME-START) ----------------- */
+
+ components new RadioClientC() as StartRadioClient;
+ PibP.MacReset -> BeaconTransmitP;
+ BeaconTransmitP.PIBUpdate[IEEE154_macAssociationPermit] -> PibP.PIBUpdate[IEEE154_macAssociationPermit];
+ BeaconTransmitP.PIBUpdate[IEEE154_macGTSPermit] -> PibP.PIBUpdate[IEEE154_macGTSPermit];
+ BeaconTransmitP.BeaconTxAlarm = Alarm1;
+ BeaconTransmitP.BeaconPayloadUpdateTimer = Timer2;
+ BeaconTransmitP.RadioOff -> StartRadioClient;
+ BeaconTransmitP.IsBeaconEnabledPAN -> PibP.IsBeaconEnabledPAN;
+ BeaconTransmitP.BeaconTx -> StartRadioClient;
+ BeaconTransmitP.MLME_SET -> PibP.MLME_SET;
+ BeaconTransmitP.MLME_GET -> PibP;
+ BeaconTransmitP.SetMacSuperframeOrder -> PibP.SetMacSuperframeOrder;
+ BeaconTransmitP.SetMacBeaconTxTime -> PibP.SetMacBeaconTxTime;
+ BeaconTransmitP.SetMacPanCoordinator -> PibP.SetMacPanCoordinator;
+ BeaconTransmitP.Token -> StartRadioClient;
+ BeaconTransmitP.TokenToBroadcast -> StartRadioClient;
+ 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.LastBeaconRxRefTime -> BeaconSynchronizeP.CapStartRefTime;
+ BeaconTransmitP.LastBeaconRxTime -> BeaconSynchronizeP.CapStart;
+ BeaconTransmitP.GetSetRealignmentFrame -> CoordRealignmentP;
+ BeaconTransmitP.IsBroadcastReady -> CoordBroadcastP.IsBroadcastReady;
+ BeaconTransmitP.TimeCalc -> PibP;
+ BeaconTransmitP.Leds = Leds;
+ BeaconTransmitP.Debug = Ieee802154Debug[START_CLIENT];
+ StartRadioClient.TransferTo -> CoordBroadcastRadioClient.TransferFrom;
+
+/* ---------------- Beacon Synchronization (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.IsBeaconEnabledPAN -> PibP.IsBeaconEnabledPAN;
+ BeaconSynchronizeP.DataRequest -> PollP.DataRequest[SYNC_CLIENT];
+ BeaconSynchronizeP.Token -> SyncRadioClient;
+ BeaconSynchronizeP.TokenToCap -> SyncRadioClient;
+ BeaconSynchronizeP.TimeCalc -> PibP;
+ BeaconSynchronizeP.CoordRealignmentRx -> DeviceCap.FrameRx[FC1_FRAMETYPE_CMD + CMD_FRAME_COORDINATOR_REALIGNMENT];
+ BeaconSynchronizeP.Leds = Leds;
+ BeaconSynchronizeP.Debug = Ieee802154Debug[SYNC_CLIENT];
+ SyncRadioClient.TransferTo -> DeviceCapRadioClient.TransferFrom;
+
+/* --------------- Dis/Association (MLME-DIS/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.DisassociationIndirectTx -> IndirectTxP.FrameTx[unique(INDIRECT_TX_CLIENT)];
+ AssociateP.DisassociationDirectTx -> CoordCapQueue.FrameTx[unique(CAP_TX_CLIENT)];
+ AssociateP.DisassociationToCoord -> DeviceCapQueue.FrameTx[unique(CAP_TX_CLIENT)];
+ AssociateP.DisassociationDirectRxFromCoord ->
+ DeviceCap.FrameRx[FC1_FRAMETYPE_CMD + CMD_FRAME_DISASSOCIATION_NOTIFICATION];
+ AssociateP.DisassociationExtractedFromCoord ->
+ DeviceCap.FrameExtracted[FC1_FRAMETYPE_CMD + CMD_FRAME_DISASSOCIATION_NOTIFICATION];
+ AssociateP.DisassociationRxFromDevice ->
+ CoordCap.FrameRx[FC1_FRAMETYPE_CMD + CMD_FRAME_DISASSOCIATION_NOTIFICATION];
+ AssociateP.DataRequest -> PollP.DataRequest[ASSOCIATE_CLIENT];
+ AssociateP.ResponseTimeout = Timer3;
+ AssociateP.IsTrackingBeacons -> BeaconSynchronizeP.IsTrackingBeacons;
+ AssociateP.TxFramePool -> TxFramePoolP;
+ AssociateP.TxControlPool -> TxControlPoolP;
+ AssociateP.MLME_GET -> PibP;
+ AssociateP.MLME_SET -> PibP.MLME_SET;
+ AssociateP.FrameUtility -> PibP;
+ AssociateP.Frame -> PibP;
+ AssociateP.Leds = Leds;
+ AssociateP.LocalExtendedAddress -> PibP.GetLocalExtendedAddress;
+ AssociateP.Debug = Ieee802154Debug[ASSOCIATE_CLIENT];
+
+/* ------------------ Data Transmission (MCPS-DATA) ------------------- */
+
+ PibP.MacReset -> DataP;
+ 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; // indirect
+ DataP.DeviceCapRx -> RxEnableP.FrameRx; // promiscuous
+ DataP.DeviceCapRx -> DeviceCap.FrameRx[FC1_FRAMETYPE_DATA]; // broadcast
+ 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.LocalExtendedAddress -> PibP.GetLocalExtendedAddress;
+ 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.Debug = Ieee802154Debug[POLL_CLIENT];
+ 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;
+ IndirectTxP.Debug = Ieee802154Debug[INDIRECTTX_DEBUG_CLIENT];
+
+/* ---------------------------- 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.BeaconFramePendingBit -> BeaconTransmitP.BeaconFramePendingBit;
+ CoordBroadcastP.CapTransmitNow -> CoordCap.BroadcastTx;
+ CoordBroadcastP.Queue -> BroadcastQueueC;
+ CoordBroadcastP.Leds = Leds;
+
+/* --------------------- CAP (incoming superframe) -------------------- */
+
+ PibP.CapQueueReset -> DeviceCapQueue;
+ DeviceCapQueue.Queue -> DeviceCapQueueC;
+ DeviceCapQueue.CapTx -> DeviceCap;
+
+ PibP.CapQueueReset -> CoordCapQueue;
+ CoordCapQueue.Queue -> CoordCapQueueC;
+ CoordCapQueue.CapTx -> CoordCap;
+
+ components new RadioClientC() as DeviceCapRadioClient;
+ PibP.CapReset -> DeviceCap;
+ DeviceCap.Random = Random;
+ DeviceCap.CapEndAlarm = Alarm3;
+ DeviceCap.BLEAlarm = Alarm4;
+ DeviceCap.IndirectTxWaitAlarm = Alarm5;
+ DeviceCap.BroadcastAlarm = Alarm6;
+ DeviceCap.Token -> DeviceCapRadioClient;
+ DeviceCap.TokenToCfp -> DeviceCapRadioClient;
+ DeviceCap.TokenTransferred -> DeviceCapRadioClient;
+ DeviceCap.TokenRequested -> DeviceCapRadioClient;
+ DeviceCap.IsTokenRequested -> DeviceCapRadioClient;
+ DeviceCap.CapStart -> BeaconSynchronizeP.CapStart;
+ DeviceCap.CapStartRefTime -> BeaconSynchronizeP.CapStartRefTime;
+ DeviceCap.CapLen -> BeaconSynchronizeP.CapLen;
+ DeviceCap.IsBLEActive -> BeaconSynchronizeP.IsBLEActive;
+ DeviceCap.BLELen -> BeaconSynchronizeP.BLELen;
+ DeviceCap.IsRxBroadcastPending -> BeaconSynchronizeP.IsRxBroadcastPending;
+ DeviceCap.IsRxEnableActive -> RxEnableP.IsRxEnableActive;
+ DeviceCap.RxEnableStateChange -> RxEnableP.RxEnableStateChange;
+ DeviceCap.FrameUtility -> PibP;
+ DeviceCap.RadioTx -> DeviceCapRadioClient;
+ DeviceCap.RadioRx -> DeviceCapRadioClient;
+ DeviceCap.RadioOff -> DeviceCapRadioClient;
+ DeviceCap.IsBeaconEnabledPAN -> PibP.IsBeaconEnabledPAN;
+ DeviceCap.MLME_GET -> PibP;
+ DeviceCap.MLME_SET -> PibP.MLME_SET;
+ DeviceCap.Debug = Ieee802154Debug[DEVICE_CAP_CLIENT];
+ DeviceCap.TimeCalc -> PibP;
+ DeviceCap.Leds = Leds;
+ DeviceCapRadioClient.TransferTo -> DeviceCfpRadioClient.TransferFrom;
+
+/* ---------------------- CAP (outgoing superframe) ------------------- */
+
+ components new RadioClientC() as CoordCapRadioClient,
+ new BackupP(ieee154_cap_frame_backup_t);
+ PibP.CapReset -> CoordCap;
+ CoordCap.Random = Random;
+ CoordCap.CapEndAlarm = Alarm7;
+ CoordCap.BLEAlarm = Alarm8;
+ CoordCap.Token -> CoordCapRadioClient;
+ CoordCap.TokenToCfp -> CoordCapRadioClient;
+ CoordCap.TokenTransferred -> CoordCapRadioClient;
+ CoordCap.TokenRequested -> CoordCapRadioClient;
+ CoordCap.IsTokenRequested -> CoordCapRadioClient;
+ CoordCap.CapStart -> BeaconTransmitP.CapStart;
+ CoordCap.CapStartRefTime -> BeaconTransmitP.CapStartRefTime;
+ CoordCap.CapLen -> BeaconTransmitP.CapLen;
+ CoordCap.IsBLEActive -> BeaconTransmitP.IsBLEActive;
+ CoordCap.BLELen -> BeaconTransmitP.BLELen;
+ CoordCap.IsRxEnableActive -> RxEnableP.IsRxEnableActive;
+ CoordCap.RxEnableStateChange -> RxEnableP.RxEnableStateChange;
+ CoordCap.FrameUtility -> PibP;
+ CoordCap.RadioTx -> CoordCapRadioClient;
+ CoordCap.RadioRx -> CoordCapRadioClient;
+ CoordCap.RadioOff -> CoordCapRadioClient;
+ CoordCap.IsBeaconEnabledPAN -> PibP.IsBeaconEnabledPAN;
+ CoordCap.MLME_GET -> PibP;
+ CoordCap.MLME_SET -> PibP.MLME_SET;
+ CoordCap.Debug = Ieee802154Debug[COORD_CAP_CLIENT];
+ 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.Token -> DeviceCfpRadioClient;
+ DeviceCfp.TokenTransferred -> DeviceCfpRadioClient;
+ DeviceCfp.TokenRequested -> DeviceCfpRadioClient;
+ DeviceCfp.CapStartRefTime -> BeaconSynchronizeP.CapStartRefTime;
+ DeviceCfp.CfpEnd -> BeaconSynchronizeP.CfpEnd;
+ DeviceCfp.GtsField -> BeaconSynchronizeP.GtsField;
+ DeviceCfp.SfSlotDuration -> BeaconSynchronizeP.SfSlotDuration;
+ DeviceCfp.FinalCapSlot -> BeaconSynchronizeP.FinalCapSlot;
+ 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;
+
+/* -------------------- GTS (outgoing superframe) --------------------- */
+
+ components new RadioClientC() as CoordCfpRadioClient;
+ PibP.MacReset -> CoordCfp;
+ CoordCfp.Token -> CoordCfpRadioClient;
+ CoordCfp.TokenTransferred -> CoordCfpRadioClient;
+ CoordCfp.TokenRequested -> CoordCfpRadioClient;
+ CoordCfp.CfpEnd -> BeaconTransmitP.CfpEnd;
+ CoordCfp.GtsField -> BeaconTransmitP.GtsField;
+ CoordCfp.SfSlotDuration -> BeaconTransmitP.SfSlotDuration;
+ CoordCfp.FinalCapSlot -> BeaconTransmitP.FinalCapSlot;
+ 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;
+
+/* ------------------ MLME-RX-ENABLE / promiscuous mode --------------- */
+
+ components new RadioClientC() as RxEnableRadioClient;
+ PibP.MacReset -> RxEnableP;
+ RxEnableP.Token -> RxEnableRadioClient;
+ RxEnableP.PromiscuousRx -> RxEnableRadioClient;
+ RxEnableP.IncomingSfStart -> BeaconSynchronizeP.CapStart;
+ RxEnableP.OutgoingSfStart -> BeaconTransmitP.CapStart;
+ RxEnableP.IncomingBeaconInterval -> BeaconSynchronizeP.BeaconInterval;
+ RxEnableP.OutgoingBeaconInterval -> BeaconTransmitP.BeaconInterval;
+ RxEnableP.IsTrackingBeacons -> BeaconSynchronizeP.IsTrackingBeacons;
+ RxEnableP.IsSendingBeacons-> BeaconTransmitP.IsSendingBeacons;
+ RxEnableP.IsMacPanCoordinator -> PibP.IsMacPanCoordinator;
+ RxEnableP.IsBeaconEnabledPAN -> PibP.IsBeaconEnabledPAN;
+ RxEnableP.TimeCalc -> PibP.TimeCalc;
+ RxEnableP.RadioOff -> RxEnableRadioClient;
+ RxEnableP.RadioPromiscuousMode = RadioPromiscuousMode;
+ RxEnableP.WasRxEnabled -> DeviceCap;
+ RxEnableP.WasRxEnabled -> CoordCap;
+ RxEnableP.RxEnableTimer = Timer5;
+ RxEnableP.Debug = Ieee802154Debug[RXENABLE_CLIENT];
+
+/* ------------------------------- PIB -------------------------------- */
+
+ components new RadioClientC() as PibRadioClient;
+ PIBUpdate = PibP;
+ MainC.SoftwareInit -> PibP.LocalInit;
+ PibP.RadioControl = PhySplitControl;
+ PibP.Random = Random;
+ PibP.PromiscuousModeGet -> RxEnableP;
+ PibP.LocalTime = LocalTime;
+ PibP.Token -> PibRadioClient;
+ PibP.RadioOff -> PibRadioClient;
+
+/* ---------------------------- Dispatcher ---------------------------- */
+
+ FrameDispatchP.PhyTx = RadioTx;
+ FrameDispatchP.PhyRx = RadioRx;
+ FrameDispatchP.PhyRadioOff = RadioOff;
+ FrameDispatchP.RadioPromiscuousMode -> RxEnableP;
+ FrameDispatchP.Leds = Leds;
+ FrameDispatchP.Debug = Ieee802154Debug[RADIORXTX_CLIENT];
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#ifndef __TKN154_DEBUG_H
+#define __TKN154_DEBUG_H
+
+#define LEVEL_INFO 0
+#define LEVEL_IMPORTANT 50
+#define LEVEL_CRITICAL 100
+
+#define RadioRxTxP_ACQUIRED 0
+#define RadioRxTxP_NOT_ACQUIRED 1
+#define RadioRxTxP_TRANSFERRED 2
+#define RadioRxTxP_NOT_TRANSFERRED 3
+#define RadioRxTxP_RELEASED 4
+#define RadioRxTxP_NOT_RELEASED 5
+#define RadioRxTxP_TRANSFER_REQUEST 6
+#define RadioRxTxP_DEFAULT_PREPARE_TX_DONE 7
+#define RadioRxTxP_DEFAULT_TX_DONE 8
+#define RadioRxTxP_DEFAULT_PREPARE_RX_DONE 9
+#define RadioRxTxP_DEFAULT_RECEIVED 10
+#define RadioRxTxP_DEFAULT_OFFDONE 11
+#define RadioRxTxP_DEFAULT_TRANSFERRED 12
+#define RadioRxTxP_DEFAULT_TRANSFERREQUEST 13
+#define RadioRxTxP_ASK_ISOWNER 14
+#define RadioRxTxP_RX_NOOWNER 15
+#define RadioRxTxP_DEFAULT_CANCEL_TX_DONE 16
+#define RadioRxTxP_DEFAULT_CANCEL_RX_DONE 17
+
+#define SyncP_BEACON_MISSED_1 0
+#define SyncP_BEACON_MISSED_2 1
+#define SyncP_BEACON_MISSED_3 2
+#define SyncP_TRACK_ALARM 3
+#define SyncP_INVALID_PARAM 4
+#define SyncP_RX_ON 5
+#define SyncP_INTERNAL_ERROR 6
+#define SyncP_BEACON_RX 7
+#define SyncP_RADIO_BUSY 8
+#define SyncP_LOST_SYNC 9
+#define SyncP_RX_PACKET 10
+#define SyncP_NEXT_RX_TIME 11
+#define SyncP_SWITCHOFF 12
+#define SyncP_RX_GARBAGE 13
+#define SyncP_GOT_RESOURCE 14
+#define SyncP_RELEASE_RESOURCE 15
+#define SyncP_RESOURCE_REQUEST 16
+#define SyncP_TRANSFER_RESOURCE 17
+#define SyncP_PREPARE_RX 18
+#define SyncP_REQUEST 19
+#define SyncP_UPDATING 20
+#define SyncP_PREPARE_RX_DONE 21
+#define SyncP_INVALID_TIMESTAMP 22
+#define SyncP_RX_BEACON SyncP_RX_PACKET
+
+#define StartP_BEACON_TRANSMITTED 0
+#define StartP_UPDATE_STATE 1
+#define StartP_REQUEST 2
+#define StartP_OWNER_TOO_FAST 3
+#define StartP_BEACON_UPDATE 4
+#define StartP_BEACON_UPDATE_2 5
+#define StartP_PREPARE_TX 6
+#define StartP_PREPARE_TXDONE 7
+#define StartP_SKIPPED_BEACON 8
+#define StartP_GOT_RESOURCE 9
+#define StartP_TRANSMIT 10
+
+#define PollP_ALLOC_FAIL1 0
+#define PollP_ALLOC_FAIL2 1
+#define PollP_INTERNAL_POLL 2
+#define PollP_SUCCESS 3
+#define PollP_TXDONE 4
+#define PollP_WRONG_FORMAT 5
+#define PollP_INTERNAL_ERROR 6
+#define PollP_RX 7
+
+#define IndirectTxP_OVERFLOW 0
+#define IndirectTxP_NOTIFIED 1
+#define IndirectTxP_REQUESTED 2
+#define IndirectTxP_BUSY 3
+#define IndirectTxP_DATA_REQUEST 4
+#define IndirectTxP_SEND_NOW 5
+#define IndirectTxP_SEND_NOW_FAIL 6
+#define IndirectTxP_SEND_DONE 7
+#define IndirectTxP_BEACON_ASSEMBLY 8
+
+#define EnableRxP_RADIORX_ERROR 0
+#define EnableRxP_PROMISCUOUS_REQUEST 1
+#define EnableRxP_PROMISCUOUS_ON 2
+#define EnableRxP_PROMISCUOUS_OFF 3
+
+#define AssociateP_REQUEST 0
+#define AssociateP_TXDONE 1
+#define AssociateP_TIMEOUT 2
+#define AssociateP_RX 3
+#define AssociateP_SETTIMER 4
+#define AssociateP_POLL_DONE 5
+
+#define DISSASSOCIATE_REQUEST 50
+#define DISSASSOCIATE_TXDONE 51
+#define DISSASSOCIATE_RX 52
+
+#define CapP_TOO_SHORT 0
+#define CapP_SET_CAP_END 1
+#define CapP_CAP_END_FIRED 2
+
+#define DeviceCapTransmitP_CONTINUE 0
+#define DeviceCapTransmitP_TOVERFLOW 1
+#define DeviceCapTransmitP_RADIO_RESERVE 2
+#define DeviceCapTransmitP_CCA_FAIL 3
+#define DeviceCapTransmitP_NO_ACK 4
+#define DeviceCapTransmitP_TX_DONE 5
+#define DeviceCapTransmitP_TX_PREPARE 6
+#define DeviceCapTransmitP_TX_NOW 7
+#define DeviceCapTransmitP_TX_CANCEL 8
+#define DeviceCapTransmitP_TX_PREPARE_DONE 9
+#define DeviceCapTransmitP_CAP_END_ALARM 10
+#define DeviceCapTransmitP_RADIO_OFF 11
+#define DeviceCapTransmitP_RADIO_RX 12
+#define DeviceCapTransmitP_TX_CANCEL_DONE 13
+#define DeviceCapTransmitP_TX_DONE_UNKNOWN 14
+#define DeviceCapTransmitP_RESOURCE_REQ 15
+#define DeviceCapTransmitP_GOT_RESOURCE 16
+
+#define CoordCapTransmitP_RADIO_RESERVE 0
+#define CoordCapTransmitP_TX_CANCEL 1
+#define CoordCapTransmitP_CCA_FAIL 2
+#define CoordCapTransmitP_CAP_END_ALARM 3
+#define CoordCapTransmitP_OFF_DONE 4
+#define CoordCapTransmitP_FINISH_TX 5
+#define CoordCapTransmitP_RADIO_RX 6
+
+#define Phy_RX_CANCEL 0
+#define Phy_RX_NOW 1
+#define Phy_LOAD_TX_FIFO 2
+#define Phy_LOAD_TX_FIFO_DONE 3
+#define Phy_LOAD_TX_CANCEL 4
+#define Phy_LOAD_TX_NOW 5
+#define Phy_LOAD_TX_RX_NOW 6
+#define Phy_SEND_DONE 7
+#define Phy_SPI_GRANTED 8
+#define Phy_RADIO_OFF 9
+#define Phy_RADIO_OFF_DONE 10
+#define Phy_RADIO_PREPARE_RX 11
+#define Phy_RADIO_PREPARE_TX 12
+#define Phy_RADIO_TX_DONE 13
+#define Phy_RADIO_RECEIVED 14
+
+#define PhyRx_START 0
+#define PhyRx_STOP 1
+#define PhyRx_FIFOP 2
+#define PhyRx_RXON 3
+
+enum {
+ // IDs assigned for debugging
+ START_CLIENT = 0,
+ COORD_CAP_CLIENT = 1,
+ COORD_CFP_CLIENT = 2,
+
+ SYNC_CLIENT = 3,
+ DEVICE_CAP_CLIENT = 4,
+ DEVICE_CFP_CLIENT = 5,
+
+ SCAN_CLIENT = 6,
+
+ RADIORXTX_CLIENT = 7,
+ PIBDATABASE_CLIENT = 8,
+ ASSOCIATE_CLIENT = 9,
+ DEVICECAPQUEUE_CLIENT = 10,
+ INDIRECTTX_DEBUG_CLIENT = 11,
+ DATA_CLIENT = 12,
+ POLL_CLIENT = 13,
+ DISASSOCIATE_CLIENT = 14,
+ RXENABLE_CLIENT = 15,
+
+ PHY_CLIENT = 16,
+ PHY_TXCLIENT = 17,
+ PHY_RXCLIENT = 18,
+};
+
+typedef nx_struct serial_debug_msg {
+ nx_uint8_t client;
+ nx_uint8_t eventID;
+ nx_uint8_t seqno;
+ nx_uint8_t priority;
+ nx_uint32_t timestamp;
+ nx_uint32_t param1;
+ nx_uint32_t param2;
+ nx_uint32_t param3;
+} serial_debug_msg_t;
+
+#ifndef SERIAL_DBG_MSGBUF_SIZE
+#define SERIAL_DBG_MSGBUF_SIZE 25
+#endif
+
+enum {
+ AM_SERIAL_DEBUG_MSG = 222,
+};
+
+#endif // __TKN154_DEBUG_H
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#ifndef __TKN154_MAC_H
+#define __TKN154_MAC_H
+
+#include "TKN154.h"
+#include "TKN154_PHY.h"
+
+/****************************************************
+ * IEEE 802.15.4 PAN information base identifiers
+ **/
+
+enum {
+ // PHY Sublayer PIB
+ IEEE154_phyCurrentChannel = 0x00,
+ IEEE154_phyChannelsSupported = 0x01,
+ IEEE154_phyTransmitPower = 0x02,
+ IEEE154_phyCCAMode = 0x03,
+ IEEE154_phyCurrentPage = 0x04,
+ IEEE154_phyMaxFrameDuration = 0x05,
+ IEEE154_phySHRDuration = 0x06,
+ IEEE154_phySymbolsPerOctet = 0x07,
+
+ // MAC Sublayer PIB
+ IEEE154_macAckWaitDuration = 0x40,
+ IEEE154_macAssociatedPANCoord = 0x56,
+ IEEE154_macAssociationPermit = 0x41,
+ IEEE154_macAutoRequest = 0x42,
+ IEEE154_macBattLifeExt = 0x43,
+ IEEE154_macBattLifeExtPeriods = 0x44,
+ IEEE154_macBeaconPayload = 0x45,
+ IEEE154_macBeaconPayloadLength = 0x46,
+ IEEE154_macBeaconOrder = 0x47,
+ IEEE154_macBeaconTxTime = 0x48,
+ IEEE154_macBSN = 0x49,
+ IEEE154_macCoordExtendedAddress = 0x4A,
+ IEEE154_macCoordShortAddress = 0x4B,
+ IEEE154_macDSN = 0x4C,
+ IEEE154_macGTSPermit = 0x4D,
+ IEEE154_macMaxBE = 0x57,
+ IEEE154_macMaxCSMABackoffs = 0x4E,
+ IEEE154_macMaxFrameTotalWaitTime = 0x58,
+ 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,
+ IEEE154_macPromiscuousMode = 0x51,
+ IEEE154_macResponseWaitTime = 0x5A,
+ IEEE154_macRxOnWhenIdle = 0x52,
+ IEEE154_macSecurityEnabled = 0x5D,
+ IEEE154_macShortAddress = 0x53,
+ IEEE154_macSuperframeOrder = 0x54,
+ IEEE154_macSyncSymbolOffset = 0x5B,
+ IEEE154_macTimestampSupported = 0x5C,
+ IEEE154_macTransactionPersistenceTime = 0x55,
+
+// attributes not present in the standard PIB:
+ IEEE154_macPanCoordinator = 0xF0,
+};
+
+enum {
+ // MAC header indices
+ MHR_INDEX_FC1 = 0,
+ MHR_INDEX_FC2 = 1,
+ MHR_INDEX_SEQNO = 2,
+ MHR_INDEX_ADDRESS = 3,
+ MHR_MAX_LEN = 23,
+
+ // Frame Control field in MHR
+ FC1_FRAMETYPE_BEACON = 0x00,
+ FC1_FRAMETYPE_DATA = 0x01,
+ FC1_FRAMETYPE_ACK = 0x02,
+ FC1_FRAMETYPE_CMD = 0x03,
+ FC1_FRAMETYPE_MASK = 0x07,
+
+ FC1_SECURITY_ENABLED = 0x08,
+ FC1_FRAME_PENDING = 0x10,
+ FC1_ACK_REQUEST = 0x20,
+ FC1_PAN_ID_COMPRESSION = 0x40,
+
+ FC2_DEST_MODE_SHORT = 0x08,
+ FC2_DEST_MODE_EXTENDED = 0x0c,
+ FC2_DEST_MODE_MASK = 0x0c,
+ FC2_DEST_MODE_OFFSET = 2,
+
+ FC2_SRC_MODE_SHORT = 0x80,
+ FC2_SRC_MODE_EXTENDED = 0xc0,
+ FC2_SRC_MODE_MASK = 0xc0,
+ FC2_SRC_MODE_OFFSET = 6,
+
+ FC2_FRAME_VERSION_1 = 0x10,
+ FC2_FRAME_VERSION_2 = 0x20,
+ FC2_FRAME_VERSION_MASK = 0x30,
+};
+
+#define CAP_TX_CLIENT "CapQueueP.FrameTx.client"
+#define INDIRECT_TX_CLIENT "IndirectTx.client"
+#define IEEE802154_RADIO_RESOURCE "RadioRxTxP.resource"
+
+enum {
+ OUTGOING_SUPERFRAME,
+ INCOMING_SUPERFRAME,
+};
+
+typedef struct {
+ uint8_t length; // top bit denotes -> promiscuous mode
+ uint8_t mhr[MHR_MAX_LEN];
+} ieee154_header_t;
+
+typedef struct {
+ uint8_t rssi;
+ uint8_t linkQuality;
+ uint32_t timestamp;
+} ieee154_metadata_t;
+
+typedef struct
+{
+ uint8_t client;
+ uint8_t handle;
+ ieee154_header_t *header;
+ uint8_t headerLen;
+ uint8_t *payload;
+ uint8_t payloadLen;
+ ieee154_metadata_t *metadata;
+} ieee154_txframe_t;
+
+typedef struct
+{
+ ieee154_header_t header;
+ ieee154_metadata_t metadata;
+} ieee154_txcontrol_t;
+
+typedef struct {
+ ieee154_txframe_t *frame;
+ ieee154_macMaxBE_t BE;
+ ieee154_macMaxCSMABackoffs_t allowedBackoffs;
+ ieee154_macMaxBE_t macMaxBE;
+ uint16_t backoff;
+ uint16_t backoffElapsed;
+ uint32_t transactionTime;
+} ieee154_cap_frame_backup_t;
+
+#define MHR(x) (((ieee154_header_t*) (x)->header)->mhr)
+
+// COMMAND frames
+enum {
+ CMD_FRAME_ASSOCIATION_REQUEST = 1,
+ CMD_FRAME_ASSOCIATION_RESPONSE = 2,
+ CMD_FRAME_DISASSOCIATION_NOTIFICATION = 3,
+ CMD_FRAME_DATA_REQUEST = 4,
+ CMD_FRAME_PAN_ID_CONFLICT_NOTIFICATION = 5,
+ CMD_FRAME_ORPHAN_NOTIFICATION = 6,
+ CMD_FRAME_BEACON_REQUEST = 7,
+ CMD_FRAME_COORDINATOR_REALIGNMENT = 8,
+ CMD_FRAME_GTS_REQUEST = 9
+};
+
+enum {
+ // MAC payload fields inside a beacon frame
+ BEACON_INDEX_SF_SPEC1 = 0,
+ BEACON_INDEX_SF_SPEC2 = 1,
+ BEACON_INDEX_GTS_SPEC = 2,
+
+ SF_SPEC2_PAN_COORD = 0x40,
+ SF_SPEC2_ASSOCIATION_PERMIT = 0x80,
+
+ GTS_DESCRIPTOR_COUNT_MASK = 0x07,
+ GTS_LENGTH_MASK = 0xF0,
+ GTS_LENGTH_OFFSET = 4,
+ GTS_SPEC_PERMIT = 0x80,
+
+ PENDING_ADDRESS_SHORT_MASK = 0x07,
+ PENDING_ADDRESS_EXT_MASK = 0x70,
+};
+
+enum {
+ // PHY sublayer constants
+ 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)
+
+enum {
+ // MAC sublayer constants
+ IEEE154_aNumSuperframeSlots = 16,
+ IEEE154_aMaxMPDUUnsecuredOverhead = 25,
+ IEEE154_aMinMPDUOverhead = 9,
+ IEEE154_aBaseSlotDuration = 60,
+ IEEE154_aBaseSuperframeDuration = (IEEE154_aBaseSlotDuration * IEEE154_aNumSuperframeSlots),
+ IEEE154_aGTSDescPersistenceTime = 4,
+ IEEE154_aMaxBeaconOverhead = 75,
+ IEEE154_aMaxBeaconPayloadLength = (IEEE154_aMaxPHYPacketSize - IEEE154_aMaxBeaconOverhead),
+ IEEE154_aMaxLostBeacons = 4,
+ IEEE154_aMaxMACSafePayloadSize = (IEEE154_aMaxPHYPacketSize - IEEE154_aMaxMPDUUnsecuredOverhead),
+ IEEE154_aMaxMACPayloadSize = (IEEE154_aMaxPHYPacketSize - IEEE154_aMinMPDUOverhead),
+ IEEE154_aMaxSIFSFrameSize = 18,
+ IEEE154_aMinCAPLength = 440,
+ IEEE154_aUnitBackoffPeriod = 20,
+};
+
+
+#endif // __TKN154_MAC_H
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Date$
+ * @author Torsten Halbhuebner <hhuebner.tu-berlin.de>
+ * ========================================================================
+ */
+
+#ifndef __TKN154_PIB_H
+#define __TKN154_PIB_H
+
+/****************************************************
+ * IEEE 802.15.4 PAN information base (PIB)
+ */
+
+
+typedef struct ieee154_PIB_t {
+
+ /**************/
+ /* bool types */
+ /**************/
+
+ // 0x41
+ ieee154_macAssociationPermit_t macAssociationPermit;
+ // 0x42
+ ieee154_macAutoRequest_t macAutoRequest;
+ // 0x43
+ ieee154_macBattLifeExt_t macBattLifeExt;
+ // 0x4D
+ ieee154_macGTSPermit_t macGTSPermit;
+ // 0x51
+ ieee154_macPromiscuousMode_t macPromiscuousMode;
+ // 0x52
+ ieee154_macRxOnWhenIdle_t macRxOnWhenIdle;
+ // 0x56
+ ieee154_macAssociatedPANCoord_t macAssociatedPANCoord;
+ // 0x5D
+ ieee154_macSecurityEnabled_t macSecurityEnabled;
+ // no standard attribute
+ ieee154_macPanCoordinator_t macPanCoordinator;
+ /*****************/
+ /* uint8_t types */
+ /*****************/
+
+ // 0x00
+ ieee154_phyCurrentChannel_t phyCurrentChannel;
+ // 0x02
+ ieee154_phyTransmitPower_t phyTransmitPower;
+ // 0x03
+ ieee154_phyCCAMode_t phyCCAMode;
+ // 0x04
+ ieee154_phyCurrentPage_t phyCurrentPage;
+ // 0x44
+ ieee154_macBattLifeExtPeriods_t macBattLifeExtPeriods;
+ // 0x46
+ ieee154_macBeaconPayloadLength_t macBeaconPayloadLength;
+ // 0x47
+ ieee154_macBeaconOrder_t macBeaconOrder;
+ // 0x49
+ ieee154_macBSN_t macBSN;
+ // 0x4C
+ ieee154_macDSN_t macDSN;
+ // 0x4E
+ ieee154_macMaxCSMABackoffs_t macMaxCSMABackoffs;
+ // 0x4F
+ ieee154_macMinBE_t macMinBE;
+ // 0x54
+ ieee154_macSuperframeOrder_t macSuperframeOrder;
+ // 0x57
+ ieee154_macMaxBE_t macMaxBE;
+ // 0x59
+ ieee154_macMaxFrameRetries_t macMaxFrameRetries;
+ // 0x5a
+ ieee154_macResponseWaitTime_t macResponseWaitTime;
+
+ /*****************************/
+ /* larger than uint8_t types */
+ /*****************************/
+
+ // 0x4B
+ ieee154_macCoordShortAddress_t macCoordShortAddress;
+ // 0x50
+ ieee154_macPANId_t macPANId;
+ // 0x53
+ ieee154_macShortAddress_t macShortAddress;
+ // 0x55
+ ieee154_macTransactionPersistenceTime_t macTransactionPersistenceTime;
+
+ // TODO: check type
+ ieee154_macMaxFrameTotalWaitTime_t macMaxFrameTotalWaitTime;
+
+ ieee154_macBeaconTxTime_t macBeaconTxTime;
+ // 0x4A
+ ieee154_macCoordExtendedAddress_t macCoordExtendedAddress;
+
+} ieee154_PIB_t;
+
+// PHY PIB default attributes
+
+#define IEEE154_DEFAULT_CURRENTCHANNEL 26
+#define IEEE154_DEFAULT_CHANNELSSUPPORTED_PAGE0 0x07FFF800
+#define IEEE154_DEFAULT_CHANNELSSUPPORTED_PAGE1 0
+#define IEEE154_DEFAULT_CHANNELSSUPPORTED_PAGE2 0
+#define IEEE154_DEFAULT_CCAMODE 3
+#define IEEE154_DEFAULT_CURRENTPAGE 0
+#define IEEE154_DEFAULT_TRANSMITPOWER_dBm 0
+
+// MAC PIB default attributes
+#define IEEE154_DEFAULT_ASSOCIATEDPANCOORD FALSE
+#define IEEE154_DEFAULT_ASSOCIATIONPERMIT FALSE
+#define IEEE154_DEFAULT_AUTOREQUEST TRUE
+#define IEEE154_DEFAULT_BATTLIFEEXT FALSE
+#define IEEE154_DEFAULT_BATTLIFEEXTPERIODS 6
+#define IEEE154_DEFAULT_BEACONPAYLOAD NULL
+#define IEEE154_DEFAULT_BEACONPAYLOADLENGTH 0
+#define IEEE154_DEFAULT_BEACONORDER 15
+#define IEEE154_DEFAULT_BEACONTXTIME 0
+#define IEEE154_DEFAULT_COORDSHORTADDRESS 0xFFFF
+#define IEEE154_DEFAULT_GTSPERMIT TRUE
+#define IEEE154_DEFAULT_MAXBE 5
+#define IEEE154_DEFAULT_MAXCSMABACKOFFS 4
+#define IEEE154_DEFAULT_MAXFRAMETOTALWAITTIME 2626
+#define IEEE154_DEFAULT_MAXFRAMERETRIES 3
+#define IEEE154_DEFAULT_MINBE 3
+#define IEEE154_DEFAULT_MINLIFSPERIOD 40
+#define IEEE154_DEFAULT_MINSIFSPERIOD 12
+#define IEEE154_DEFAULT_PANID 0xFFFF
+#define IEEE154_DEFAULT_PROMISCUOUSMODE FALSE
+#define IEEE154_DEFAULT_RESPONSEWAITTIME 32
+#define IEEE154_DEFAULT_RXONWHENIDLE FALSE
+#define IEEE154_DEFAULT_SECURITYENABLED FALSE
+#define IEEE154_DEFAULT_SHORTADDRESS 0xFFFF
+
+#define IEEE154_DEFAULT_SUPERFRAMEORDER 15
+#define IEEE154_DEFAULT_SYNCSYMBOLOFFSET 0
+#define IEEE154_DEFAULT_TIMESTAMPSUPPORTED TRUE
+#define IEEE154_DEFAULT_TRANSACTIONPERSISTENCETIME 0x01F4
+
+#define IEEE154_INVALID_TIMESTAMP (0xffffffff)
+
+#endif // __TKN154_PIB_H
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+generic module TransferClientP(uint8_t myUserId)
+{
+ provides
+ {
+ interface ResourceTransfer;
+ interface ResourceTransferred;
+ interface ResourceTransferConnector as TransferredFrom;
+ } uses {
+ interface ResourceTransferConnector as TransferTo;
+ interface ResourceTransferControl;
+ interface Leds;
+ }
+}
+implementation
+{
+ async command error_t ResourceTransfer.transfer()
+ {
+ error_t result;
+ uint8_t toClient = call TransferTo.getUserId();
+ atomic {
+ result = call ResourceTransferControl.transfer(myUserId, toClient);
+ if (result == SUCCESS)
+ call TransferTo.transfer();
+ }
+ return result;
+ }
+
+ async command uint8_t TransferredFrom.getUserId(){ return myUserId;}
+
+ async command void TransferredFrom.transfer()
+ {
+ signal ResourceTransferred.transferred();
+ }
+
+ async command error_t ResourceTransferred.release()
+ {
+ return call ResourceTransferControl.release(myUserId);
+ }
+ default async command uint8_t TransferTo.getUserId(){ call Leds.led0On(); return 0xFF;}
+ default async command void TransferTo.transfer(){ call Leds.led0On(); }
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+
+#include "TKN154_MAC.h"
+
+module NoBeaconSynchronizeP
+{
+ provides
+ {
+ interface Init;
+ interface MLME_SYNC;
+ interface MLME_BEACON_NOTIFY;
+ interface MLME_SYNC_LOSS;
+ interface Get<bool> as IsTrackingBeacons;
+ interface Get<uint32_t> as GetLastBeaconRxTime;
+ 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
+ {
+ interface MLME_GET;
+ interface MLME_SET;
+ interface FrameUtility;
+ interface IEEE154BeaconFrame as BeaconFrame;
+ interface Alarm<TSymbolIEEE802154,uint32_t> as TrackAlarm;
+ interface RadioRx as BeaconRx;
+ interface RadioOff;
+ interface Get<bool> as IsBeaconEnabledPAN;
+ interface DataRequest;
+ interface FrameRx as CoordRealignmentRx;
+ interface Resource as Token;
+ interface ResourceTransfer as TokenToCap;
+ interface ResourceTransferred as TokenTransferred;
+ interface GetNow<bool> as IsSendingBeacons;
+ interface TimeCalc;
+ interface IEEE154Frame as Frame;
+ interface Leds;
+ interface Ieee802154Debug as Debug;
+ }
+}
+implementation
+{
+
+ command error_t Init.init() { return SUCCESS; }
+
+ command ieee154_status_t MLME_SYNC.request (
+ uint8_t logicalChannel,
+ uint8_t channelPage,
+ bool trackBeacon
+ )
+ {
+ return IEEE154_TRANSACTION_OVERFLOW;
+ }
+
+ event void Token.granted() { }
+
+ async event void TokenTransferred.transferred() { call Token.release(); }
+
+ async event void TrackAlarm.fired() {}
+
+ async event void BeaconRx.prepareDone() {}
+
+ event message_t* BeaconRx.received(message_t* frame, ieee154_reftime_t *timestamp) { return frame;}
+
+ async event void RadioOff.offDone() {}
+
+ command bool IsTrackingBeacons.get(){ return FALSE;}
+ command uint32_t GetLastBeaconRxTime.get(){ return 0;}
+ async command uint8_t* GtsField.getNow() { return 0; }
+ async command uint32_t SfSlotDuration.getNow() { return 0; }
+ async command uint8_t FinalCapSlot.getNow() { return 0; }
+
+ event void DataRequest.pollDone(){}
+ async command uint32_t CapEnd.getNow() { return 0; }
+ async command uint32_t CapStart.getNow() { return 0; }
+ async command uint32_t CapLen.getNow() { return 0; }
+ async command uint32_t CfpEnd.getNow() { return 0; }
+ async command ieee154_reftime_t* CapStartRefTime.getNow() { return NULL; }
+ async command uint32_t CfpLen.getNow(){ return 0;}
+ async command uint32_t BeaconInterval.getNow(){ return 0;}
+ async command bool IsBLEActive.getNow(){ return 0;}
+ async command uint16_t BLELen.getNow(){ return 0;}
+ async command uint8_t NumGtsSlots.getNow() { return 0; }
+ async command bool IsRxBroadcastPending.getNow() { return FALSE; }
+ event message_t* CoordRealignmentRx.received(message_t* frame) {return frame;}
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#include "TKN154_MAC.h"
+#include "TKN154_PHY.h"
+module NoBeaconTransmitP
+{
+ provides
+ {
+ interface Init;
+ interface MLME_START;
+ interface WriteBeaconField as SuperframeSpecWrite;
+ interface Get<bool> as IsSendingBeacons;
+ 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<bool> as IsBLEActive;
+ interface GetNow<uint16_t> as BLELen;
+ interface GetNow<uint8_t*> as GtsField;
+ interface GetNow<uint32_t> as SfSlotDuration;
+ interface GetNow<uint32_t> as BeaconInterval;
+ interface GetNow<uint8_t> as FinalCapSlot;
+ interface GetNow<uint8_t> as NumGtsSlots;
+ interface GetNow<bool> as BeaconFramePendingBit;
+ interface IEEE154TxBeaconPayload;
+ } uses {
+ interface Notify<bool> as GtsSpecUpdated;
+ interface Notify<bool> as PendingAddrSpecUpdated;
+ interface Notify<const void*> as PIBUpdate[uint8_t attributeID];
+ interface Alarm<TSymbolIEEE802154,uint32_t> as BeaconTxAlarm;
+ interface Timer<TSymbolIEEE802154> as BeaconPayloadUpdateTimer;
+ interface RadioOff;
+ interface Get<bool> as IsBeaconEnabledPAN;
+ interface RadioTx as BeaconTx;
+ interface MLME_GET;
+ interface MLME_SET;
+ interface Resource as Token;
+ interface ResourceTransfer as TokenToBroadcast;
+ interface FrameTx as RealignmentBeaconEnabledTx;
+ interface FrameTx as RealignmentNonBeaconEnabledTx;
+ interface FrameRx as BeaconRequestRx;
+ interface WriteBeaconField as GtsInfoWrite;
+ interface WriteBeaconField as PendingAddrWrite;
+ interface FrameUtility;
+ interface Get<bool> as IsTrackingBeacons;
+ interface GetNow<uint32_t> as LastBeaconRxTime;
+ interface GetNow<ieee154_reftime_t*> as LastBeaconRxRefTime;
+ interface Ieee802154Debug as Debug;
+ interface Set<ieee154_macSuperframeOrder_t> as SetMacSuperframeOrder;
+ interface Set<ieee154_macBeaconTxTime_t> as SetMacBeaconTxTime;
+ interface Set<ieee154_macPanCoordinator_t> as SetMacPanCoordinator;
+ interface GetSet<ieee154_txframe_t*> as GetSetRealignmentFrame;
+ interface GetNow<bool> as IsBroadcastReady;
+ interface TimeCalc;
+ interface Leds;
+ }
+}
+implementation
+{
+ command error_t Init.init()
+ {
+ 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)
+ {
+ return IEEE154_TRANSACTION_OVERFLOW;
+ }
+
+ event void Token.granted() { }
+
+ async event void RadioOff.offDone() { }
+
+ async event void BeaconTxAlarm.fired() {}
+
+ async event void BeaconTx.loadDone() {}
+
+ async event void BeaconTx.transmitDone(ieee154_txframe_t *frame,
+ ieee154_reftime_t *referenceTime, bool pendingFlag, error_t error) { }
+
+ command error_t IEEE154TxBeaconPayload.setBeaconPayload(void *beaconPayload, uint8_t length) { return ESIZE; }
+
+ command const void* IEEE154TxBeaconPayload.getBeaconPayload() { return NULL; }
+
+ command uint8_t IEEE154TxBeaconPayload.getBeaconPayloadLength() {return 0; }
+
+ command error_t IEEE154TxBeaconPayload.modifyBeaconPayload(uint8_t offset, void *buffer, uint8_t bufferLength)
+ {
+ return ESIZE;
+ }
+
+ event void PIBUpdate.notify[uint8_t attributeID](const void* attributeValue)
+ {
+ }
+
+ event void PendingAddrSpecUpdated.notify(bool val)
+ {
+ }
+
+ event void GtsSpecUpdated.notify(bool val)
+ {
+ }
+
+ event void BeaconPayloadUpdateTimer.fired()
+ {
+ }
+
+ command uint8_t SuperframeSpecWrite.write(uint8_t *superframeSpecField, uint8_t maxlen)
+ {
+ return 0;
+ }
+
+ command uint8_t SuperframeSpecWrite.getLength()
+ {
+ return 0;
+ }
+
+ event void RealignmentBeaconEnabledTx.transmitDone(ieee154_txframe_t *frame, ieee154_status_t status)
+ {
+ }
+
+ event void RealignmentNonBeaconEnabledTx.transmitDone(ieee154_txframe_t *frame, ieee154_status_t status)
+ {
+ }
+
+ event message_t* BeaconRequestRx.received(message_t* frame)
+ {
+ return frame;
+ }
+
+ command bool IsSendingBeacons.get(){ return FALSE;}
+
+ async command uint32_t CapStart.getNow() { return 0; }
+ async command ieee154_reftime_t* CapStartRefTime.getNow() { return NULL; }
+ async command uint32_t CapLen.getNow() { return 0;}
+ async command uint32_t CapEnd.getNow()
+ {
+ return 0;
+ }
+ async command uint32_t CfpEnd.getNow()
+ {
+ return 0;
+ }
+ async command uint32_t CfpLen.getNow()
+ {
+ return 0;
+ }
+ async command bool IsBLEActive.getNow(){ return FALSE;}
+ async command uint16_t BLELen.getNow(){ return 0;}
+ async command bool BeaconFramePendingBit.getNow(){ return FALSE;}
+
+ async command uint8_t* GtsField.getNow() { return NULL; }
+ async command uint32_t SfSlotDuration.getNow() { return 0; }
+ async command uint32_t BeaconInterval.getNow() { return 0; }
+ async command uint8_t FinalCapSlot.getNow() { return 0; }
+ async command uint8_t NumGtsSlots.getNow() { return 0; }
+
+ 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(){}
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#include "TKN154_PHY.h"
+#include "TKN154_MAC.h"
+
+generic module NoCapP()
+{
+ provides
+ {
+ interface Init as Reset;
+ interface FrameTx as CapTx;
+ 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 Random;
+ 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 ResourceTransfer as TokenToCfp;
+ interface ResourceTransferred as TokenTransferred;
+ interface ResourceRequested as TokenRequested;
+ interface GetNow<bool> as IsTokenRequested;
+ interface GetNow<uint32_t> as CapStart;
+ interface GetNow<ieee154_reftime_t*> as CapStartRefTime;
+ interface GetNow<uint32_t> as CapLen;
+ interface GetNow<bool> as IsBLEActive;
+ interface GetNow<uint16_t> as BLELen;
+ interface GetNow<bool> as IsRxEnableActive;
+ interface GetNow<bool> as IsRxBroadcastPending;
+ interface Notify<bool> as RxEnableStateChange;
+ interface FrameUtility;
+ interface RadioTx;
+ interface RadioRx;
+ interface RadioOff;
+ interface Get<bool> as IsBeaconEnabledPAN;
+ interface MLME_GET;
+ interface MLME_SET;
+ interface Ieee802154Debug as Debug;
+ interface TimeCalc;
+ interface Leds;
+ interface SetNow<ieee154_cap_frame_backup_t*> as FrameBackup;
+ interface GetNow<ieee154_cap_frame_backup_t*> as FrameRestore;
+ }
+}
+implementation
+{
+ command error_t Reset.init()
+ {
+ return SUCCESS;
+ }
+
+ async event void TokenTransferred.transferred()
+ {
+ call TokenToCfp.transfer();
+ }
+
+ command ieee154_status_t CapTx.transmit(ieee154_txframe_t *frame)
+ {
+ return IEEE154_TRANSACTION_OVERFLOW;
+ }
+
+ async event void RadioTx.loadDone(){ }
+ async event void RadioOff.offDone(){ }
+ async event void RadioRx.prepareDone(){ }
+
+ async event void CapEndAlarm.fired(){ }
+ async event void BLEAlarm.fired(){ }
+ event void RxEnableStateChange.notify(bool x){ }
+ async event void BroadcastAlarm.fired(){ }
+
+ async event void IndirectTxWaitAlarm.fired() { }
+
+ async event void RadioTx.transmitDone(ieee154_txframe_t *frame, ieee154_reftime_t
+ *referenceTime, bool ackPendingFlag, error_t error) { }
+
+ event message_t* RadioRx.received(message_t* frame, ieee154_reftime_t* referenceTime) { return frame; }
+ async command ieee154_status_t BroadcastTx.transmitNow(ieee154_txframe_t *frame){ return IEEE154_TRANSACTION_OVERFLOW; }
+
+ async event void TokenRequested.requested() {}
+ async event void TokenRequested.immediateRequested() {}
+ event void Token.granted(){}
+ command error_t WasRxEnabled.enable(){return FAIL;}
+ command error_t WasRxEnabled.disable(){return FAIL;}
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+#include "TKN154_MAC.h"
+generic module NoCapQueueP()
+{
+ provides
+ {
+ interface Init;
+ interface FrameTx[uint8_t client];
+ interface FrameRx as FrameExtracted[uint8_t client];
+ interface Purge;
+ }
+ uses
+ {
+ interface Queue<ieee154_txframe_t*>;
+ interface FrameTx as CapTx;
+ interface FrameRx as SubFrameExtracted;
+ }
+}
+implementation
+{
+ command error_t Init.init()
+ {
+ return SUCCESS;
+ }
+
+ command ieee154_status_t FrameTx.transmit[uint8_t client](ieee154_txframe_t *data)
+ {
+ return IEEE154_TRANSACTION_OVERFLOW;
+ }
+
+ event void CapTx.transmitDone(ieee154_txframe_t *data, ieee154_status_t status) { }
+
+ event message_t* SubFrameExtracted.received(message_t* frame) { return frame; }
+
+ command ieee154_status_t Purge.purge(uint8_t msduHandle) { return IEEE154_INVALID_HANDLE; }
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+/**
+ * The contention free period (CFP) in beacon mode, a.k.a. GTS, is not yet
+ * implemented - this is only an empty placeholder. In contrast to the CAP
+ * component the GTS component for an incoming superframe will probably be very
+ * different from the GTS for an outgoing superframe. That is why there are two
+ * separate placeholder components (DeviceCfpP and CoordCfpP) instead of one
+ * generic CfpP component. This component would deal with the GTS for an
+ * outgoing superframe, i.e. from the perspective of a coordinator.
+ */
+
+#include "TKN154_MAC.h"
+module NoCoordCfpP
+{
+ provides {
+ interface Init;
+ interface WriteBeaconField as GtsInfoWrite;
+ interface FrameTx as CfpTx;
+ interface Purge;
+ } uses {
+ interface Resource as Token;
+ interface ResourceTransferred as TokenTransferred;
+ interface ResourceRequested as TokenRequested;
+ interface GetNow<uint32_t> as CfpEnd;
+ interface GetNow<ieee154_reftime_t*> as CapStartRefTime;
+ interface GetNow<uint8_t*> as GtsField;
+ interface GetNow<uint32_t> as SfSlotDuration;
+ interface GetNow<uint8_t> as FinalCapSlot;
+ interface Alarm<TSymbolIEEE802154,uint32_t> as CfpSlotAlarm;
+ interface Alarm<TSymbolIEEE802154,uint32_t> as CfpEndAlarm;
+ interface RadioTx;
+ interface RadioRx;
+ interface RadioOff;
+ interface MLME_GET;
+ interface MLME_SET;
+ }
+}
+implementation
+{
+ command error_t Init.init()
+ {
+ // initialize any module variables
+ return SUCCESS;
+ }
+
+ command ieee154_status_t CfpTx.transmit(ieee154_txframe_t *data)
+ {
+ // send a frame in a GTS slot (triggered by MCPS_DATA.request())
+ return IEEE154_INVALID_GTS;
+ }
+
+ command ieee154_status_t Purge.purge(uint8_t msduHandle)
+ {
+ // request to purge a frame (triggered by MCPS_DATA.purge())
+ return IEEE154_INVALID_HANDLE;
+ }
+
+ async event void TokenTransferred.transferred()
+ {
+ // the CFP has started, this component now owns the token -
+ // because GTS is not implemented we release the token
+ // immediately; the general rule is: as long as a component
+ // owns the token it has exclusive access to the radio
+ call Token.release();
+ }
+
+ async event void CfpEndAlarm.fired() { }
+
+ async event void CfpSlotAlarm.fired() {}
+
+ async event void RadioOff.offDone()
+ {
+ call Token.release();
+ }
+
+ command uint8_t GtsInfoWrite.write(uint8_t *gtsSpecField, uint8_t maxlen)
+ {
+ // write the current GTS spec at the given address
+ if (call GtsInfoWrite.getLength() > maxlen)
+ return 0;
+ gtsSpecField[0] = 0;
+ return 1;
+ }
+
+ command uint8_t GtsInfoWrite.getLength()
+ {
+ // returns the length of the current GTS spec
+ // must return the same value as GtsInfoWrite.write
+ return 1;
+ }
+
+ async event void RadioTx.loadDone(){}
+ async event void RadioTx.transmitDone(ieee154_txframe_t *frame,
+ ieee154_reftime_t *referenceTime, bool ackPendingFlag, error_t error){}
+
+ async event void RadioRx.prepareDone(){}
+ event message_t* RadioRx.received(message_t *frame, ieee154_reftime_t *timestamp){return frame;}
+
+ async event void TokenRequested.requested()
+ {
+ // someone (e.g. SCAN component) requested access to the radio,
+ // you might want to release the token...
+ }
+
+ async event void TokenRequested.immediateRequested(){ }
+ event void Token.granted(){ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+#include "TKN154_DEBUG.h"
+module NoDebugP
+{
+ provides
+ {
+ interface Ieee802154Debug[uint8_t client];
+ }
+}
+implementation
+{
+ async command void Ieee802154Debug.log[uint8_t client](
+ uint8_t priority,
+ uint8_t eventID,
+ uint32_t param1,
+ uint32_t param2,
+ uint32_t param3)
+ {
+ }
+ command void Ieee802154Debug.flush[uint8_t client](){}
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+#include "TKN154_MAC.h"
+module NoDeviceCapQueueP
+{
+ provides
+ {
+ interface Init;
+ interface FrameTx[uint8_t client];
+ interface FrameRx as FrameExtracted[uint8_t client];
+ interface Purge;
+ }
+ uses
+ {
+ interface Queue<ieee154_txframe_t*>;
+ interface FrameTx as DeviceCapTx;
+ interface FrameRx as SubFrameExtracted;
+ }
+}
+implementation
+{
+ command error_t Init.init() { return SUCCESS; }
+
+ command ieee154_status_t FrameTx.tx[uint8_t client](ieee154_txframe_t *data) { return TRANSACTION_OVERFLOW; }
+
+ event void DeviceCapTx.transmitDone(ieee154_txframe_t *data, ieee154_status_t status) { }
+
+ event message_t* SubFrameExtracted.received(message_t* data) { return data; }
+
+ command ieee154_status_t Purge.purge(uint8_t msduHandle) { return INVALID_HANDLE; }
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+/**
+ * The contention free period (CFP) in beacon mode, a.k.a. GTS, is not yet
+ * implemented - this is only an empty placeholder. In contrast to the CAP
+ * component the GTS component for an incoming superframe will probably be very
+ * different from the GTS for an outgoing superframe. That is why there are two
+ * separate placeholder components (DeviceCfpP and CoordCfpP) instead of one
+ * generic CfpP component. This component would deal with the GTS for an
+ * incoming superframe, i.e. from the perspective of a device.
+ */
+
+#include "TKN154_MAC.h"
+module NoDeviceCfpP
+{
+ provides {
+ interface Init;
+ interface FrameTx as CfpTx;
+ interface Purge;
+ } uses {
+ interface Resource as Token;
+ interface ResourceTransferred as TokenTransferred;
+ interface ResourceRequested as TokenRequested;
+ interface GetNow<ieee154_reftime_t*> as CapStartRefTime;
+ interface GetNow<uint32_t> as CfpEnd;
+ interface GetNow<uint8_t*> as GtsField;
+ interface GetNow<uint32_t> as SfSlotDuration;
+ interface GetNow<uint8_t> as FinalCapSlot;
+ interface Alarm<TSymbolIEEE802154,uint32_t> as CfpSlotAlarm;
+ interface Alarm<TSymbolIEEE802154,uint32_t> as CfpEndAlarm;
+ interface RadioTx;
+ interface RadioRx;
+ interface RadioOff;
+ interface MLME_GET;
+ interface MLME_SET;
+ }
+}
+implementation
+{
+ command error_t Init.init()
+ {
+ // initialize any module variables
+ return SUCCESS;
+ }
+
+ command ieee154_status_t CfpTx.transmit(ieee154_txframe_t *data)
+ {
+ // request to send a frame in a GTS slot (triggered by MCPS_DATA.request())
+ return IEEE154_INVALID_GTS;
+ }
+
+ command ieee154_status_t Purge.purge(uint8_t msduHandle)
+ {
+ // request to purge a frame (triggered by MCPS_DATA.purge())
+ return IEEE154_INVALID_HANDLE;
+ }
+
+ async event void TokenTransferred.transferred()
+ {
+ // the CFP has started, this component now owns the token -
+ // because GTS is not implemented we release the token
+ // immediately; the general rule is: as long as a component
+ // owns the token it has exclusive access to the radio
+ call Token.release();
+ }
+
+ async event void CfpEndAlarm.fired() { }
+
+ async event void CfpSlotAlarm.fired() {}
+
+ async event void RadioOff.offDone()
+ {
+ call Token.release();
+ }
+
+ async event void RadioTx.loadDone(){}
+ async event void RadioTx.transmitDone(ieee154_txframe_t *frame,
+ ieee154_reftime_t *referenceTime, bool ackPendingFlag, error_t error){}
+
+ async event void RadioRx.prepareDone(){}
+ event message_t* RadioRx.received(message_t *frame, ieee154_reftime_t *timestamp){return frame;}
+
+ async event void TokenRequested.requested()
+ {
+ // someone requested access to the radio, you might
+ // consider releasing it...
+ }
+
+ async event void TokenRequested.immediateRequested(){ }
+ event void Token.granted(){ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#include "TKN154_MAC.h"
+
+module NoScanP
+{
+ provides
+ {
+ interface Init;
+ interface MLME_SCAN;
+ interface MLME_BEACON_NOTIFY;
+ }
+ uses
+ {
+ interface MLME_GET;
+ interface MLME_SET;
+ interface EnergyDetection;
+ interface RadioOff;
+ interface RadioRx;
+ interface RadioTx;
+ interface IEEE154Frame as Frame;
+ interface IEEE154BeaconFrame as BeaconFrame;
+ interface Timer<TSymbolIEEE802154> as ScanTimer;
+ interface Pool<ieee154_txframe_t> as TxFramePool;
+ interface Pool<ieee154_txcontrol_t> as TxControlPool;
+ interface Resource as Token;
+ interface FrameUtility;
+ interface Leds;
+ }
+}
+implementation
+{
+
+ command error_t Init.init() { return SUCCESS;}
+
+ command ieee154_status_t MLME_SCAN.request (
+ uint8_t ScanType,
+ uint32_t ScanChannels,
+ uint8_t ScanDuration,
+ uint8_t ChannelPage,
+ uint8_t EnergyDetectListNumEntries,
+ int8_t* EnergyDetectList,
+ uint8_t PANDescriptorListNumEntries,
+ ieee154_PANDescriptor_t* PANDescriptorList,
+ ieee154_security_t *security
+ )
+ {
+ return IEEE154_TRANSACTION_OVERFLOW;
+ }
+
+ event void Token.granted()
+ {
+ call Token.release();
+ }
+
+ event void EnergyDetection.done(error_t status, int8_t EnergyLevel){}
+
+ async event void RadioRx.prepareDone() { }
+
+ event message_t* RadioRx.received(message_t *frame, ieee154_reftime_t *time)
+ {
+ return frame;
+ }
+
+ async event void RadioTx.loadDone() { }
+
+ async event void RadioTx.transmitDone(ieee154_txframe_t *frame, ieee154_reftime_t *t0,
+ bool ackPendingFlag, error_t error){}
+
+ event void ScanTimer.fired() { }
+
+ async event void RadioOff.offDone() { }
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#include "TKN154.h"
+#include <message.h>
+
+interface MCPS_DATA
+{
+
+ /**
+ * "The MCPS-DATA.request primitive requests the transfer of a data
+ * SPDU (i.e., MSDU) from a local SSCS entity to a single peer SSCS
+ * entity." (IEEE 802.15.4-2006, Sec. 7.1.1.1)
+ *
+ * The MSDU is the payload portion of a message_t (<code>frame<\code>
+ * parameter) and can be accessed through the <code>IEEE154Frame<\code>
+ * interface. In contrast to the standard interface definition address
+ * information is not passed as separate parameters; instead, the
+ * address information is already part of the <code>frame<\code>,
+ * i.e. it must have been set (through the <code>IEEE154Frame<\code>
+ * interface) before this command is called.
+ *
+ * If this command returns IEEE154_SUCCESS, then the confirm event
+ * will be signalled in the future; otherwise, the confirm event
+ * will not be signalled.
+ *
+ * @param frame The frame to send
+ * @param payloadLen The length of the frame payload
+ * @param msduHandle Handle associated with the frame to be transmitted
+ * @param TxOptions Bitwised OR transmission options
+ *
+ * @return IEEE154_SUCCESS if the request succeeded and a confirm event
+ * will be signalled, an appropriate error code otherwise
+ * (no confirm event will be signalled in this case)
+ * @see confirm
+ */
+
+ command ieee154_status_t request (
+ message_t *frame,
+ uint8_t payloadLen,
+ uint8_t msduHandle,
+ uint8_t TxOptions
+ );
+
+ /**
+ * Confirm reports the results of a request to transfer a frame to a
+ * peer SSCS entity.
+ *
+ * @param frame The frame which was requested to send
+ * @param msduHandle The handle associated with the frame
+ * @param status The status of the last MSDU transmission
+ * @param timestamp Time of transmission (invalid if status is
+ * not IEEE154_SUCCESS)
+ */
+ event void confirm (
+ message_t *frame,
+ uint8_t msduHandle,
+ ieee154_status_t status,
+ uint32_t Timestamp
+ );
+
+ /**
+ * Indicates the arrival of a frame. Address information can be accessed
+ * through the <code>IEEE154Frame<\code> interface.
+ *
+ * @return A frame buffer for the stack to use for the next received frame
+ */
+ event message_t* indication ( message_t* frame );
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#include "TKN154.h"
+
+interface MCPS_PURGE {
+
+ /**
+ * Request to purge a frame from the transaction queue.
+ * The result will be returned immediately (there
+ * is no confirm event for this command).
+ *
+ * @param msduHandle The handle of the frame to be purged from the
+ * transaction queue
+ * @return IEEE154_SUCCESS if the request succeeded, an
+ * appropriate error code otherwise
+ */
+ command ieee154_status_t request (
+ uint8_t msduHandle
+ );
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#include "TKN154.h"
+
+interface MLME_ASSOCIATE {
+
+ /**
+ * Requests to associate with a PAN.
+ *
+ * @param LogicalChannel The logical channel on which to attempt
+ * association
+ * @param ChannelPage The channel page on which to attempt association
+ * @param CoordAddrMode The coordinator addressing mode
+ * @param CoordPANID The 16 bit PAN identifier of the coordinator
+ * @param CoordAddress Individual device address of the coordinator as
+ * per the CoordAddrMode
+ * @param CapabilityInformation Specifies the operational capabilities
+ * of the associating device
+ * @param security The security options (NULL means security is
+ * disabled)
+ * @return IEEE154_SUCCESS if the request succeeded and a confirm event
+ * will be signalled, an appropriate error code otherwise
+ * (no confirm event will be signalled in this case)
+ * @see confirm
+ */
+ command ieee154_status_t request (
+ uint8_t LogicalChannel,
+ uint8_t ChannelPage,
+ uint8_t CoordAddrMode,
+ uint16_t CoordPANID,
+ ieee154_address_t CoordAddress,
+ ieee154_CapabilityInformation_t CapabilityInformation,
+ ieee154_security_t *security
+ );
+
+ /**
+ * Notification that a device has requested to associate with a PAN.
+ *
+ * @param DeviceAddress the 64-bit address of the requesting device
+ * @param CapabilityInformation Specifies the operational capabilities
+ * of the associating device
+ * @param security The security options (NULL means security is
+ * disabled)
+ */
+ event void indication (
+ uint64_t DeviceAddress,
+ ieee154_CapabilityInformation_t CapabilityInformation,
+ ieee154_security_t *security
+ );
+
+ /**
+ * Send a response to a device's request to associate
+ *
+ * @param DeviceAddress The 64-bit address of the device to respond to
+ * @param AssocShortAddress The short device address allocated by the
+ * coordinator on successful allocation.
+ * @param status The status of the association attempt
+ * @param security The security options (NULL means security is
+ * disabled)
+ * @return IEEE154_SUCCESS if the request succeeded and an indication event
+ * will be signalled through the MLME_COMM_STATUS interface later,
+ * otherwise an appropriate error code (no MLME_COMM_STATUS.indication
+ * event will be signalled in this case)
+ */
+ command ieee154_status_t response (
+ uint64_t DeviceAddress,
+ uint16_t AssocShortAddress,
+ ieee154_association_status_t status,
+ ieee154_security_t *security
+ );
+
+ /**
+ * Confirmation of the association attempt.
+ *
+ * @param AssocShortAddress The short device address allocated by the
+ * coordinator on successful association
+ * @param status The status of the association attempt
+ * @param security The security options, NULL means security is
+ * disabled
+ */
+ event void confirm (
+ uint16_t AssocShortAddress,
+ uint8_t status,
+ ieee154_security_t *security
+ );
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#include "TKN154.h"
+#include <message.h>
+interface MLME_BEACON_NOTIFY {
+
+ /**
+ * A beacon frame has been received. This event is signalled only if
+ * either the PIB attribute macAutoRequest is set to FALSE or the
+ * beacon payload is not empty.
+ *
+ * The beacon parameters can be accessed through the
+ * <code>IEEE154BeaconFrame<\code> interface. The
+ * <code>IEEE154Frame<\code> interface can be used to
+ * inspect the addressing fields in the MAC header.
+ *
+ * @param beacon The beacon frame
+ * @return A frame buffer for the stack to use for the next received frame
+ */
+ event message_t* indication ( message_t *beaconFrame );
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#include "TKN154.h"
+interface MLME_COMM_STATUS {
+
+ /**
+ * Allows the MLME to indicate a communications status.
+ *
+ * @param PanID The 16-bit PAN identifier of the device from which the
+ * frame was received or to which the frame was being sent
+ * @param SrcAddrMode The source addressing mode
+ * @param SrcAddr Individual device address of the source as per SrcAddrMode
+ * @param DstAddrMode The destination addressing mode
+ * @param DstAddr Individual device address of the destination
+ * as per DstAddrMode
+ * @param status The communications status
+ * @param security The security options, NULL means security is
+ * disabled
+ */
+ event void indication (
+ uint16_t PANId,
+ uint8_t SrcAddrMode,
+ ieee154_address_t SrcAddr,
+ uint8_t DstAddrMode,
+ ieee154_address_t DstAddr,
+ ieee154_status_t status,
+ ieee154_security_t *security
+ );
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author: Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#include "TKN154.h"
+interface MLME_DISASSOCIATE {
+
+ /**
+ * Request disassociation from a PAN.
+ *
+ * @param DeviceAddrMode The addressing mode of the device to which to send
+ * the disassociation notification command.
+ * @param DevicePANID The PAN identifier of the device to which to send the
+ * disassociation notification command.
+ * @param DeviceAddress The address of the device to which to send the
+ * disassociation notification command
+ * @param DisassociateReason The reason for the disassociation
+ * @param TxIndirect TRUE if disassociation notification command is to be sent
+ * indirectly
+ * @param security The security options (NULL means security is
+ * disabled)
+ * @return IEEE154_SUCCESS if the request succeeded and a confirm event
+ * will be signalled, an appropriate error code otherwise
+ * (no confirm event will be signalled in this case)
+ * @see confirm
+ */
+ command ieee154_status_t request (
+ uint8_t DeviceAddrMode,
+ uint16_t DevicePANID,
+ ieee154_address_t DeviceAddress,
+ ieee154_disassociation_reason_t DisassociateReason,
+ bool TxIndirect,
+ ieee154_security_t *security
+ );
+
+ /**
+ * Signals that a device has requested disassociation.
+ *
+ * @param DeviceAddress the 64-bit address of the requesting device
+ * @param DisassociateReason Reason for the disassociation
+ * @param security The security options (NULL means security is
+ * disabled)
+ */
+ event void indication (
+ uint64_t DeviceAddress,
+ ieee154_disassociation_reason_t DisassociateReason,
+ ieee154_security_t *security
+ );
+
+ /**
+ * Confirmation of the disassociation attempt.
+ *
+ * @param status The status of the disassociation attempt
+ * @param DeviceAddrMode The addressing mode of the device that has either
+ * requested disassociation or been instructed to
+ * disassociate by its coordinator.
+ * @param DevicePANID The PAN identifier of the device that has either
+ * requested disassociation or been instructed to
+ * disassociate by its coordinator.
+ * @param DeviceAddress The address of the device that has either requested
+ * disassociation or been instructed to disassociate
+ * by its coordinator.
+ */
+ event void confirm (
+ ieee154_status_t status,
+ uint8_t DeviceAddrMode,
+ uint16_t DevicePANID,
+ ieee154_address_t DeviceAddress
+ );
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+/**
+ * This interface can be used to read attribute values from the PHY/MAC PIB.
+ * Instead of passing the PIB attribute identifier, there is a separate
+ * command per attribute (and there are no confirm events).
+ *
+ * NOTE: for the attributes macBeaconPayload (0x45) and
+ * macBeaconPayloadLength (0x46) use the <code>IEEE154TxBeaconPayload <\code>
+ * interface; for promiscuous mode there is a separate (SplitControl)
+ * interface.
+ **/
+
+#include "TKN154.h"
+interface MLME_GET {
+
+ /** @return PIB attribute phyCurrentChannel (0x00) */
+ command ieee154_phyCurrentChannel_t phyCurrentChannel();
+
+ /** @return PIB attribute phyChannelsSupported (0x01) */
+ command ieee154_phyChannelsSupported_t phyChannelsSupported();
+
+ /** @return PIB attribute phyTransmitPower (0x02) */
+ command ieee154_phyTransmitPower_t phyTransmitPower();
+
+ /** @return PIB attribute phyCCAMode (0x03) */
+ command ieee154_phyCCAMode_t phyCCAMode();
+
+ /** @return PIB attribute phyCurrentPage (0x04) */
+ command ieee154_phyCurrentPage_t phyCurrentPage();
+
+ /** @return PIB attribute phyMaxFrameDuration (0x05) */
+ command ieee154_phyMaxFrameDuration_t phyMaxFrameDuration();
+
+ /** @return PIB attribute phySHRDuration (0x06) */
+ command ieee154_phySHRDuration_t phySHRDuration();
+
+ /** @return PIB attribute phySymbolsPerOctet (0x07) */
+ command ieee154_phySymbolsPerOctet_t phySymbolsPerOctet();
+
+ /** @return PIB attribute macAckWaitDuration (0x40) */
+ command ieee154_macAckWaitDuration_t macAckWaitDuration();
+
+ /** @return PIB attribute macAssociationPermit (0x41) */
+ command ieee154_macAssociationPermit_t macAssociationPermit();
+
+ /** @return PIB attribute macAutoRequest (0x42) */
+ command ieee154_macAutoRequest_t macAutoRequest();
+
+ /** @return PIB attribute macBattLifeExt (0x43) */
+ command ieee154_macBattLifeExt_t macBattLifeExt();
+
+ /** @return PIB attribute macBattLifeExtPeriods (0x44) */
+ command ieee154_macBattLifeExtPeriods_t macBattLifeExtPeriods();
+
+ /* macBeaconPayload (0x45) and macBeaconPayloadLength (0x46) are read
+ * through the <code>IEEE154TxBeaconPayload<\code> interface. */
+
+ /** @return PIB attribute macBeaconOrder (0x47) */
+ command ieee154_macBeaconOrder_t macBeaconOrder();
+
+ /** @return PIB attribute macBeaconTxTime (0x48) */
+ command ieee154_macBeaconTxTime_t macBeaconTxTime();
+
+ /** @return PIB attribute macBSN (0x49) */
+ command ieee154_macBSN_t macBSN();
+
+ /** @return PIB attribute macCoordExtendedAddress (0x4A) */
+ command ieee154_macCoordExtendedAddress_t macCoordExtendedAddress();
+
+ /** @return PIB attribute macCoordShortAddress (0x4B) */
+ command ieee154_macCoordShortAddress_t macCoordShortAddress();
+
+ /** @return PIB attribute macDSN (0x4C) */
+ command ieee154_macDSN_t macDSN();
+
+ /** @return PIB attribute macGTSPermit (0x4D) */
+ command ieee154_macGTSPermit_t macGTSPermit();
+
+ /** @return PIB attribute macMaxCSMABackoffs (0x4E) */
+ command ieee154_macMaxCSMABackoffs_t macMaxCSMABackoffs();
+
+ /** @return PIB attribute macMinBE (0x4F) */
+ command ieee154_macMinBE_t macMinBE();
+
+ /** @return PIB attribute macPANId (0x50) */
+ command ieee154_macPANId_t macPANId();
+
+ /** @return PIB attribute macPromiscuousMode (0x51) */
+ command ieee154_macPromiscuousMode_t macPromiscuousMode();
+
+ /** @return PIB attribute macRxOnWhenIdle (0x52) */
+ command ieee154_macRxOnWhenIdle_t macRxOnWhenIdle();
+
+ /** @return PIB attribute macShortAddress (0x53) */
+ command ieee154_macShortAddress_t macShortAddress();
+
+ /** @return PIB attribute macSuperframeOrder (0x54) */
+ command ieee154_macSuperframeOrder_t macSuperframeOrder();
+
+ /** @return PIB attribute macTransactionPersistenceTime (0x55) */
+ command ieee154_macTransactionPersistenceTime_t macTransactionPersistenceTime();
+
+ /** @return PIB attribute macAssociatedPANCoord (0x56) */
+ command ieee154_macAssociatedPANCoord_t macAssociatedPANCoord();
+
+ /** @return PIB attribute macMaxBE (0x57) */
+ command ieee154_macMaxBE_t macMaxBE();
+
+ /** @return PIB attribute macMaxFrameTotalWaitTime (0x58) */
+ command ieee154_macMaxFrameTotalWaitTime_t macMaxFrameTotalWaitTime();
+
+ /** @return PIB attribute macMaxFrameRetries (0x59) */
+ command ieee154_macMaxFrameRetries_t macMaxFrameRetries();
+
+ /** @return PIB attribute macResponseWaitTime (0x5A) */
+ command ieee154_macResponseWaitTime_t macResponseWaitTime();
+
+ /** @return PIB attribute macSyncSymbolOffset (0x5B) */
+ command ieee154_macSyncSymbolOffset_t macSyncSymbolOffset();
+
+ /** @return PIB attribute macTimestampSupported (0x5C) */
+ command ieee154_macTimestampSupported_t macTimestampSupported();
+
+ /** @return PIB attribute macSecurityEnabled (0x5D) */
+ command ieee154_macSecurityEnabled_t macSecurityEnabled();
+
+ /** @return PIB attribute macMinLIFSPeriod */
+ command ieee154_macMinLIFSPeriod_t macMinLIFSPeriod();
+
+ /** @return PIB attribute macMinSIFSPeriod */
+ command ieee154_macMinSIFSPeriod_t macMinSIFSPeriod();
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#include "TKN154.h"
+interface MLME_GTS {
+
+ /**
+ * Request allocation of a new GTS or deallocation from the PAN
+ * coordinator.
+ *
+ * @param GtsCharacteristics The characteristics of the GTS request
+ * @param security The security options (NULL means security is
+ * disabled)
+ * @return IEEE154_SUCCESS if the request succeeded and a confirm event
+ * will be signalled, an appropriate error code otherwise
+ * (no confirm event will be signalled in this case)
+ * @see confirm
+ */
+ command ieee154_status_t request (
+ uint8_t GtsCharacteristics,
+ ieee154_security_t *security
+ );
+
+ /**
+ * Reports the results of a request to allocated a new GTS or
+ * deallocate an existing GTS
+ *
+ * @param GtsCharacteristics The characteristics of the GTS request
+ * @param status The status of the GTS request
+ */
+ event void confirm (
+ uint8_t GtsCharacteristics,
+ ieee154_status_t status
+ );
+
+ /**
+ * Indicates that a GTS has been allocated or that a previously allocated
+ * GTS has been deallocated
+ *
+ * All pointers are valid only until the return of this event.
+ *
+ * @param DeviceAddress Short address of the device that has been allocated
+ * or deallocated a GTS
+ * @param GtsCharacteristics The characteristics of the GTS request
+ * @param security The security options, NULL means security is
+ * disabled
+ */
+ event void indication (
+ uint16_t DeviceAddress,
+ uint8_t GtsCharacteristics,
+ ieee154_security_t *security
+ );
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#include "TKN154.h"
+interface MLME_ORPHAN {
+
+ /**
+ * Allows the MLME of a coordinator to notify the next higher layer of the
+ * presence of an orphaned device
+ *
+ * @param OrphanAddress The 64-bit extended address of the orphaned device
+ * @param security The security options (NULL means security is
+ * disabled)
+ */
+ event void indication (
+ uint64_t OrphanAddress,
+ ieee154_security_t *security
+ );
+
+ /**
+ * Allows the next higher layer of a coordinator to respond to the
+ * indication primitive
+ *
+ * @param OrphanAddres The 64-bit extended address of the orphaned device
+ * @param ShortAddress The 16-bit short address allocated to the orphaned
+ * device if it is associated with this coordinator. The
+ * special short address 0xfffe indicates that no short
+ * address was allocated, and the device will use its
+ * 64-bit extended address in all communications. If the
+ * device was not associated with this coordinator, this
+ * field will contain the value 0xffff and be ignored on
+ * receipt.
+ * @param AssociatedMember TRUE if the orphaned device is associated
+ * with this coordinator
+ * @param security The security options (NULL means security is
+ * disabled)
+ * @return IEEE154_SUCCESS if the request succeeded and an indication event
+ * will be signalled through the MLME_COMM_STATUS interface later,
+ * otherwise an appropriate error code (no MLME_COMM_STATUS.indication
+ * event will be signalled in this case)
+ */
+ command ieee154_status_t response (
+ uint64_t OrphanAddres,
+ uint16_t ShortAddress,
+ bool AssociatedMember,
+ ieee154_security_t *security
+ );
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+#include "TKN154.h"
+
+interface MLME_POLL {
+
+ /**
+ * Prompts the device to request data from the coordinator.
+ *
+ * @param CoordAddrMode The addressing mode of the coordinator to which
+ * the poll is intended
+ * @param CoordPANID The PAN identifier of the coordinator to which the
+ * poll is intended
+ * @param CoordAddress The address of the coordinator to which the
+ * poll is intended
+ * @param security The security options (NULL means security is
+ * disabled)
+ * @return IEEE154_SUCCESS if the request succeeded and a confirm event
+ * will be signalled, an appropriate error code otherwise
+ * (no confirm event will be signalled in this case)
+ * @see confirm
+ */
+ command ieee154_status_t request (
+ uint8_t CoordAddrMode,
+ uint16_t CoordPANID,
+ ieee154_address_t CoordAddress,
+ ieee154_security_t *security
+ );
+
+ /**
+ * Reports the results of a request to poll the coordinator for data
+ *
+ * @param status The status of the data request
+ */
+ event void confirm (
+ ieee154_status_t status
+ );
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#include "TKN154.h"
+interface MLME_RESET {
+
+ /**
+ * Allows the next higher layer to request that the MLME performs a
+ * reset operation. This command initializes the MAC and must be called
+ * before calling any other MAC primitive. It extends the standard
+ * interface definition by a parameter <tt>PANType</tt>, which defines
+ * whether the device/coordinator will operate on a beacon-enabled PAN
+ * or on a nonbeacon-enabled PAN.
+ *
+ * Two things are important:
+ * (1) This command will fail while promiscuous mode is enabled
+ * (promiscuous mode is controlled through a separate SplitControl
+ * interface). (2) While the MLME_RESET.confirm is pending the next
+ * higher layer MUST NOT call any MAC commands; if there are any
+ * other pending request the MAC will signal their corresponding confirm
+ * events before MLME_RESET.confirm is signalled (with a status code of
+ * IEEE154_TRANSACTION_OVERFLOW).
+ *
+ * @param SetDefaultPIB If TRUE, the MAC sublayer is reset and all MAC PIB
+ * attributes are set to their default values. If
+ * FALSE, the MAC sublayer is reset but all MAC PIB
+ * attributes retain their values prior to the
+ * generation of the reset primitive.
+ * @param PANType Either BEACON_ENABLED_PAN for beacon-enabled PANs
+ * or NONBEACON_ENABLED_PAN for nonbeacon-enabled PANs
+ *
+ * @return IEEE154_SUCCESS if the request succeeded and a confirm event
+ * will be signalled, an appropriate error code otherwise
+ * (no confirm event will be signalled in this case)
+ *
+ */
+ command ieee154_status_t request (
+ bool SetDefaultPIB,
+ uint8_t PANType
+ );
+
+ /**
+ * Reports the results of the reset operation
+ *
+ * @param status The status of the reset operation
+ */
+ event void confirm (
+ ieee154_status_t status
+ );
+
+}
--- /dev/null
+
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#include "TKN154.h"
+interface MLME_RX_ENABLE {
+
+ /**
+ * Allows the next higher layer to request that the receiver is
+ * enabled for a finite period of time
+ *
+ * @param DeferPermit TRUE if the receiver enable can be deferred until
+ * during the next superframe if the requested time has
+ * already passed
+ * @param RxOnTime The number of symbols from the start of the superframe
+ * before the receiver is to be enabled. The precision
+ * of this value is a minimum of 20 bits. This parameter
+ * is ignored for nonbeacon-enabled PANs
+ * @param RxOnDuration The number of symbols for which the receiver
+ * is to be enabled
+ * @return IEEE154_SUCCESS if the request succeeded and a confirm event
+ * will be signalled, an appropriate error code otherwise
+ * (no confirm event will be signalled in this case)
+ * @see confirm
+ */
+ command ieee154_status_t request (
+ bool DeferPermit,
+ uint32_t RxOnTime,
+ uint32_t RxOnDuration
+ );
+
+ /**
+ * Reports the results of the attempt to enable the receiver
+ *
+ * @param status The status of the receiver enable request
+ */
+ event void confirm (
+ ieee154_status_t status
+ );
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#include "TKN154.h"
+interface MLME_SCAN
+{
+
+ /**
+ * Initializes a channel scan over a given list of channels.
+ *
+ * If the PIB attribute <tt>macAutoRequest</tt> is set to FALSE, then
+ * for each received beacon a PAN descriptor is signalled to the next higher
+ * layer through a separate <tt>MLME_BEACON_NOTIFY.indication()</tt>
+ * event; otherwise the result of the channel scan is stored in a user
+ * allocated buffer, either <tt>EnergyDetectList</tt> or
+ * <tt>PANDescriptorList</tt> depending on <tt>ScanType</tt>, and the
+ * buffer is returned when the scan is completed.
+ *
+ * Both of the parameters <tt>EnergyDetectList</tt> and
+ * <tt>PANDescriptorList</tt> may be NULL, but at least one of them
+ * must be NULL.
+ *
+ * @param ScanType The type of scan performed: ENERGY_DETECTION_SCAN,
+ * ACTIVE_SCAN, PASSIVE_SCAN or ORPHAN_SCAN
+ * @param ScanChannels The 27 LSBs indicate which channels are to be
+ * scanned (1 = scan, 0 = don't scan)
+ * @param ScanDuration Value used to calculate the length of time to
+ * spend scanning each channel for ED, active, and
+ * passive scans. This parameter is ignored for
+ * orphan scans.
+ * @param ChannelPage The channel page on which to perform the scan
+ * @param EnergyDetectListNumEntries The number of entries in the
+ * <tt>EnergyDetectList</tt>.
+ * @param EnergyDetectList An empty buffer (allocated by the caller)
+ * to store the result of the energy measurements
+ * or NULL if the result should not be stored
+ * @param PANDescriptorListNumEntries The number of entries in the
+ * <tt>PANDescriptorList</tt>.
+ * @param PANDescriptorList An empty buffer (allocated by the caller)
+ * to store the result of the active/passive scan
+ * or NULL if the result should not be stored
+ * @param security The security options (NULL means security is
+ * disabled)
+ * @return IEEE154_SUCCESS if the request succeeded and a confirm event
+ * will be signalled, an appropriate error code otherwise
+ * (no confirm event will be signalled in this case)
+ * @see confirm
+ */
+ command ieee154_status_t request (
+ uint8_t ScanType,
+ uint32_t ScanChannels,
+ uint8_t ScanDuration,
+ uint8_t ChannelPage,
+ uint8_t EnergyDetectListNumEntries,
+ int8_t* EnergyDetectList,
+ uint8_t PANDescriptorListNumEntries,
+ ieee154_PANDescriptor_t* PANDescriptorList,
+ ieee154_security_t *security
+ );
+
+ /**
+ * Reports the results of the channel scan request, returning
+ * the buffers passed in the <tt>request</tt> command.
+ *
+ * @param status The status of the scan request
+ * @param ScanType The type of scan performed
+ * @param ChannelPage The channel page on which the scan
+ * was performed (see 6.1.2).
+ * @param UnscannedChannels The 27 LSBs indicate which channels are not
+ * scanned (0 = scanned, 1 = not scanned)
+ * @param EnergyDetectNumResults The number of valid entries in the
+ * <tt>EnergyDetectList</tt>.
+ * @param EnergyDetectList The buffer list of energy measurements, one for
+ * each channel searched during an ED scan
+ @param PANDescriptorListNumResults The number of valid entries in the
+ * <tt>PANDescriptorList</tt>.
+ * @param PANDescriptorList The list of PAN descriptors, one for each
+ * unique beacon found during an active or passive scan
+ */
+ event void confirm (
+ ieee154_status_t status,
+ uint8_t ScanType,
+ uint8_t ChannelPage,
+ uint32_t UnscannedChannels,
+ uint8_t EnergyDetectNumResults,
+ int8_t* EnergyDetectList,
+ uint8_t PANDescriptorListNumResults,
+ ieee154_PANDescriptor_t* PANDescriptorList
+ );
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+
+/**
+ * This interface can be used to set attribute values in the PHY/MAC PIB.
+ * Instead of passing the PIB attribute identifier, there is a separate
+ * command per attribute (and there are no confirm events).
+ *
+ * NOTE: for the attributes macBeaconPayload (0x45) and
+ * macBeaconPayloadLength (0x46) use the <code>IEEE154TxBeaconPayload <\code>
+ * interface; for promiscuous mode there is a separate (SplitControl)
+ * interface.
+ **/
+
+#include "TKN154.h"
+interface MLME_SET {
+
+ /** @param value new PIB attribute value for phyCurrentChannel (0x00)
+ * @returns IEEE154_SUCCESS if PIB attribute was updated, INVALID_PARAMETER if
+ * parameter value is out of valid range and PIB was not updated */
+ command ieee154_status_t phyCurrentChannel(ieee154_phyCurrentChannel_t value);
+
+ /** @param value new PIB attribute value for phyTransmitPower (0x02)
+ * (2 MSBs are ignored)
+ * @returns IEEE154_SUCCESS if PIB attribute was updated, INVALID_PARAMETER if
+ * parameter value is out of valid range and PIB was not updated */
+ command ieee154_status_t phyTransmitPower(ieee154_phyTransmitPower_t value);
+
+ /** @param value new PIB attribute value for phyCCAMode (0x03)
+ * @returns IEEE154_SUCCESS if PIB attribute was updated, INVALID_PARAMETER if
+ * parameter value is out of valid range and PIB was not updated */
+ command ieee154_status_t phyCCAMode(ieee154_phyCCAMode_t value);
+
+ /** @param value new PIB attribute value for phyCurrentPage (0x04)
+ * @returns IEEE154_SUCCESS if PIB attribute was updated, INVALID_PARAMETER if
+ * parameter value is out of valid range and PIB was not updated */
+ command ieee154_status_t phyCurrentPage(ieee154_phyCurrentPage_t value);
+
+ /** @param value new PIB attribute value for macAssociationPermit (0x41)
+ * @returns IEEE154_SUCCESS if PIB attribute was updated, INVALID_PARAMETER if
+ * parameter value is out of valid range and PIB was not updated */
+ command ieee154_status_t macAssociationPermit(ieee154_macAssociationPermit_t value);
+
+ /** @param value new PIB attribute value for macAutoRequest (0x42)
+ * @returns IEEE154_SUCCESS if PIB attribute was updated, INVALID_PARAMETER if
+ * parameter value is out of valid range and PIB was not updated */
+ command ieee154_status_t macAutoRequest(ieee154_macAutoRequest_t value);
+
+ /** @param value new PIB attribute value for macBattLifeExt (0x43)
+ * @returns IEEE154_SUCCESS if PIB attribute was updated, INVALID_PARAMETER if
+ * parameter value is out of valid range and PIB was not updated */
+ command ieee154_status_t macBattLifeExt(ieee154_macBattLifeExt_t value);
+
+ /** @param value new PIB attribute value for macBattLifeExtPeriods (0x44)
+ * @returns IEEE154_SUCCESS if PIB attribute was updated, INVALID_PARAMETER if
+ * parameter value is out of valid range and PIB was not updated */
+ command ieee154_status_t macBattLifeExtPeriods(ieee154_macBattLifeExtPeriods_t value);
+
+ /* macBeaconPayload (0x45) and macBeaconPayloadLength (0x46) are set
+ * through the <code>IEEE154TxBeaconPayload<\code> interface. */
+
+ /** @param value new PIB attribute value for macBeaconOrder (0x47)
+ * @returns IEEE154_SUCCESS if PIB attribute was updated, INVALID_PARAMETER if
+ * parameter value is out of valid range and PIB was not updated */
+ command ieee154_status_t macBeaconOrder(ieee154_macBeaconOrder_t value);
+
+ /** @param value new PIB attribute value for macBSN (0x49)
+ * @returns IEEE154_SUCCESS if PIB attribute was updated, INVALID_PARAMETER if
+ * parameter value is out of valid range and PIB was not updated */
+ command ieee154_status_t macBSN(ieee154_macBSN_t value);
+
+ /** @param value new PIB attribute value for macCoordExtendedAddress (0x4A)
+ * @returns IEEE154_SUCCESS if PIB attribute was updated, INVALID_PARAMETER if
+ * parameter value is out of valid range and PIB was not updated */
+ command ieee154_status_t macCoordExtendedAddress(ieee154_macCoordExtendedAddress_t value);
+
+ /** @param value new PIB attribute value for macCoordShortAddress (0x4B)
+ * @returns IEEE154_SUCCESS if PIB attribute was updated, INVALID_PARAMETER if
+ * parameter value is out of valid range and PIB was not updated */
+ command ieee154_status_t macCoordShortAddress(ieee154_macCoordShortAddress_t value);
+
+ /** @param value new PIB attribute value for macDSN (0x4C)
+ * @returns IEEE154_SUCCESS if PIB attribute was updated, INVALID_PARAMETER if
+ * parameter value is out of valid range and PIB was not updated */
+ command ieee154_status_t macDSN(ieee154_macDSN_t value);
+
+ /** @param value new PIB attribute value for macGTSPermit (0x4D)
+ * @returns IEEE154_SUCCESS if PIB attribute was updated, INVALID_PARAMETER if
+ * parameter value is out of valid range and PIB was not updated */
+ command ieee154_status_t macGTSPermit(ieee154_macGTSPermit_t value);
+
+ /** @param value new PIB attribute value for macMaxCSMABackoffs (0x4E)
+ * @returns IEEE154_SUCCESS if PIB attribute was updated, INVALID_PARAMETER if
+ * parameter value is out of valid range and PIB was not updated */
+ command ieee154_status_t macMaxCSMABackoffs(ieee154_macMaxCSMABackoffs_t value);
+
+ /** @param value new PIB attribute value for macMinBE (0x4F)
+ * @returns IEEE154_SUCCESS if PIB attribute was updated, INVALID_PARAMETER if
+ * parameter value is out of valid range and PIB was not updated */
+ command ieee154_status_t macMinBE(ieee154_macMinBE_t value);
+
+ /** @param value new PIB attribute value for macPANId (0x50)
+ * @returns IEEE154_SUCCESS if PIB attribute was updated, INVALID_PARAMETER if
+ * parameter value is out of valid range and PIB was not updated */
+ command ieee154_status_t macPANId(ieee154_macPANId_t value);
+
+ /* macPromiscuousMode (0x51) is (re-)set through the
+ * <code>PromiscuousMode<\code> (SplitControl) interface. */
+
+ /** @param value new PIB attribute value for macRxOnWhenIdle (0x52)
+ * @returns IEEE154_SUCCESS if PIB attribute was updated, INVALID_PARAMETER if
+ * parameter value is out of valid range and PIB was not updated */
+ command ieee154_status_t macRxOnWhenIdle(ieee154_macRxOnWhenIdle_t value);
+
+ /** @param value new PIB attribute value for macShortAddress (0x53)
+ * @returns IEEE154_SUCCESS if PIB attribute was updated, INVALID_PARAMETER if
+ * parameter value is out of valid range and PIB was not updated */
+ command ieee154_status_t macShortAddress(ieee154_macShortAddress_t value);
+
+ /** @param value new PIB attribute value for macTransactionPersistenceTime (0x55)
+ * @returns IEEE154_SUCCESS if PIB attribute was updated, INVALID_PARAMETER if
+ * parameter value is out of valid range and PIB was not updated */
+ command ieee154_status_t macTransactionPersistenceTime(ieee154_macTransactionPersistenceTime_t value);
+
+ /** @param value new PIB attribute value for macAssociatedPANCoord (0x56)
+ * @returns IEEE154_SUCCESS if PIB attribute was updated, INVALID_PARAMETER if
+ * parameter value is out of valid range and PIB was not updated */
+ command ieee154_status_t macAssociatedPANCoord(ieee154_macAssociatedPANCoord_t value);
+
+ /** @param value new PIB attribute value for macMaxBE (0x57)
+ * @returns IEEE154_SUCCESS if PIB attribute was updated, INVALID_PARAMETER if
+ * parameter value is out of valid range and PIB was not updated */
+ command ieee154_status_t macMaxBE(ieee154_macMaxBE_t value);
+
+ /** @param value new PIB attribute value for macMaxFrameTotalWaitTime (0x58)
+ * @returns IEEE154_SUCCESS if PIB attribute was updated, INVALID_PARAMETER if
+ * parameter value is out of valid range and PIB was not updated */
+ command ieee154_status_t macMaxFrameTotalWaitTime(ieee154_macMaxFrameTotalWaitTime_t value);
+
+ /** @param value new PIB attribute value for macMaxFrameRetries (0x59)
+ * @returns IEEE154_SUCCESS if PIB attribute was updated, INVALID_PARAMETER if
+ * parameter value is out of valid range and PIB was not updated */
+ command ieee154_status_t macMaxFrameRetries(ieee154_macMaxFrameRetries_t value);
+
+ /** @param value new PIB attribute value for macResponseWaitTime (0x5A)
+ * @returns IEEE154_SUCCESS if PIB attribute was updated, INVALID_PARAMETER if
+ * parameter value is out of valid range and PIB was not updated */
+ command ieee154_status_t macResponseWaitTime(ieee154_macResponseWaitTime_t value);
+
+ /** @param value new PIB attribute value for macSecurityEnabled (0x5D)
+ * @returns IEEE154_SUCCESS if PIB attribute was updated, INVALID_PARAMETER if
+ * parameter value is out of valid range and PIB was not updated */
+ command ieee154_status_t macSecurityEnabled(ieee154_macSecurityEnabled_t value);
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#include "TKN154.h"
+interface MLME_START {
+
+ /**
+ * Requests to start using a new superframe configuration.
+ *
+ * @param PANId The PAN identifier to be used by the device
+ * @param LogicalChannel The logical channel on which to start transmitting
+ * beacons
+ * @param ChannelPage The channel page on which to begin using the new
+ * superframe configuration.
+ * @param StartTime The time at which to begin transmitting beacons. If this
+ * parameter is equal to 0x000000, beacon transmissions
+ * will begin immediately. Otherwise, the specified time is
+ * relative to the received beacon of the coordinator with
+ * which the device synchronizes.
+ * This parameter is ignored if either the beaconOrder
+ * parameter has a value of 15 or the panCoordinator
+ * parameter is TRUE.The time is specified in symbols and
+ * is rounded to a backoff slot boundary. This is a 24-bit
+ * value, and the precision of this value shall be a
+ * minimum of 20 bits, with the lowest 4 bits being the
+ * least significant.
+ * @param BeaconOrder The beacon order of the superframe
+ * @param SuperframeOrder The superframe order of the superframe
+ * @param PanCoordinator If TRUE, the device will become the PAN coordinator
+ * of a new PAN. If FALSE, the device will begin
+ * transmitting beacons on the PAN with which it
+ * is associated
+ * @param BatteryLifeExtension If TRUE, the receiver of the beaconing
+ * device is disabled after the IFS period
+ * @param CoordRealignment TRUE if a coordinator realignment command is to
+ * be transmitted prior to changing the superframe
+ * configuration
+ * @param coordRealignSecurity The security options for the coordinator
+ * realignment command (NULL means security
+ * is disabled)
+ * @param coordRealignSecurity The security options for beacon frames
+ * (NULL means security is disabled)
+ *
+ * @return IEEE154_SUCCESS if the request succeeded and a confirm event
+ * will be signalled, an appropriate error code otherwise
+ * (no confirm event will be signalled in this case)
+ * @see confirm
+ */
+ command ieee154_status_t 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
+ );
+
+ /**
+ * Signalled in response to a successful request.
+ * Reports the results of the attempt to start using a new superframe
+ * configuration
+ *
+ * @param status The result of the attempt to start using an
+ * updated superframe configuration
+ */
+ event void confirm (
+ ieee154_status_t status
+ );
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+interface MLME_SYNC {
+
+ /**
+ * Requests to synchronize with the coordinator by acquiring and, if
+ * specified, tracking its beacons.
+ *
+ * @param LogicalChannel Logical channel on which to attempt coordinator
+ * synchronization
+ * @param ChannelPage The channel page on which to attempt coordinator
+ * synchronization.
+ * @param TrackBeacon TRUE if the MLME is to synchronize with the next
+ * beacon and attempt to track all future beacons.
+ * FALSE if the MLME is to synchronize with only the
+ * next beacon.
+ * @return IEEE154_SUCCESS if the request succeeded and the device
+ * is now trying to acquire synchronization with the coordinator.
+ * Note: the MLME_SYNC_LOSS interface is used to signal
+ * when synchronization was lost (or never acquired)
+ */
+ command ieee154_status_t request (
+ uint8_t LogicalChannel,
+ uint8_t ChannelPage,
+ bool TrackBeacon
+ );
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+#include "TKN154.h"
+interface MLME_SYNC_LOSS {
+
+ /**
+ * Indicates the loss of synchronization with a coordinator
+ *
+ * @param lossReason The reason that synchronization was lost
+ * @param PANId The PAN identifier with which the device lost
+ * synchronization or to which it was realigned.
+ * @param LogicalChannel The logical channel on which the device lost
+ synchronization or to which it was realigned.
+ * @param ChannelPage The channel page on which the device lost
+ * synchronization or to which it was realigned.
+ * @param security The security options, NULL means security is
+ * disabled.
+ */
+ event void indication (
+ ieee154_status_t lossReason,
+ uint16_t PANId,
+ uint8_t LogicalChannel,
+ uint8_t ChannelPage,
+ ieee154_security_t *security
+ );
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer. - Redistributions in
+ * binary form must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution. - Neither the name of the
+ * Technische Universitaet Berlin nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+interface DataRequest
+{
+ /**
+ * Sends a data request frame to the coordinator.
+ *
+ * @param CoordAddrMode coordinator address mode
+ * @param CoordPANId coordinator PAN ID
+ * @param CoordAddressLE points to coordinator address stored in
+ * little endian format
+ * @param SrcAddrMode source address mode
+ * @returns IEEE154_SUCCESS if a data request frame will be transmitted and
+ * only then pollDone will be signalled.
+ **/
+ command ieee154_status_t poll(uint8_t CoordAddrMode, uint16_t CoordPANId, uint8_t *CoordAddressLE, uint8_t SrcAddrMode);
+
+
+ /**
+ * Signalled in response to a successful poll command
+ **/
+ event void pollDone();
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+#include "TKN154_MAC.h"
+interface EnergyDetection
+{
+ /**
+ * Requests to measure the energy level on the current channel; the
+ * measurement should last for <code>duration<\code> symbols and the
+ * maximum energy level is signalled through the <code>done<\code>
+ * event.
+ *
+ * @param duration Duration of the energy detection measurement
+ * (in symbol time)
+ * @return SUCCESS if the request was accepted and only then
+ * the <code>done<\code> event will be signalled, FAIL otherwise
+ **/
+ command error_t start(uint32_t duration);
+
+ /**
+ * Signalled in response to a call to <code>start<\code>;
+ * returns the maximum energy measured on the channel over the
+ * specified period of time.
+ *
+ * @param status SUCCESS if the measurement succeeded
+ * and only then <code>EnergyLevel<\code> is valid, FAIL
+ * otherwise
+ * @param EnergyLevel The maximum energy on the channel
+ **/
+ event void done(error_t status, int8_t EnergyLevel);
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer. - Redistributions in
+ * binary form must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution. - Neither the name of the
+ * Technische Universitaet Berlin nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+#include "TKN154_MAC.h"
+interface FrameExtracted
+{
+ /**
+ * A frame was extracted from the coordinator.
+ *
+ * @param rxFrame The frame received from the coordinator
+ * @param txFrame The data request frame sent to the coordinator
+ * @return A frame buffer for the stack to use for the next received frame
+ **/
+ event message_t* received(message_t* rxFrame, ieee154_txframe_t *txFrame);
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer. - Redistributions in
+ * binary form must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution. - Neither the name of the
+ * Technische Universitaet Berlin nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+#include "TKN154_MAC.h"
+interface FrameRx
+{
+ /**
+ * Received a frame buffer, returning a buffer for the signaling
+ * component to use for the next reception.
+ *
+ * @param frame the received frame
+ * @return a buffer to be used by the stack for the next
+ * incoming frame
+ */
+ event message_t* received(message_t* frame);
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer. - Redistributions in
+ * binary form must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution. - Neither the name of the
+ * Technische Universitaet Berlin nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+#include "TKN154_MAC.h"
+interface FrameTx
+{
+ /**
+ * Transmits a frame buffer.
+ *
+ * @param txFrame the frame to transmit
+ * @return IEEE154_SUCCESS if the request was accepted and
+ * only then <code>transmitDone()</code> will be signalled
+ */
+ command ieee154_status_t transmit(ieee154_txframe_t *txFrame);
+
+ /**
+ * Signals the completion of the transmission of a frame buffer.
+ *
+ * @param txFrame the frame that was transmitted
+ * @param status the result of the transmission
+ */
+ event void transmitDone(ieee154_txframe_t *txFrame, ieee154_status_t status);
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer. - Redistributions in
+ * binary form must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution. - Neither the name of the
+ * Technische Universitaet Berlin nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+#include "TKN154_MAC.h"
+interface FrameTxNow
+{
+ /**
+ * Transmits a frame buffer.
+ *
+ * @param txFrame the frame to transmit
+ * @return IEEE154_SUCCESS if the request was accepted and
+ * only then <code>transmitDone()</code> will be signalled
+ */
+ async command ieee154_status_t transmitNow(ieee154_txframe_t *frame);
+
+
+ /**
+ * Signals the completion of the transmission of a frame buffer.
+ *
+ * @param txFrame the frame that was transmitted
+ * @param status the result of the transmission
+ */
+
+ async event void transmitNowDone(ieee154_txframe_t *frame, ieee154_status_t status);
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer. - Redistributions in
+ * binary form must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution. - Neither the name of the
+ * Technische Universitaet Berlin nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$ $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+#include "TKN154.h"
+interface FrameUtility
+{
+ /* Writes the addressing fields in the MAC header of a frame
+ * and returns number of bytes in the MAC header.*/
+ async command uint8_t writeHeader(
+ uint8_t* mhr,
+ uint8_t DstAddrMode,
+ uint16_t DstPANId,
+ ieee154_address_t* DstAddr,
+ uint8_t SrcAddrMode,
+ uint16_t SrcPANId,
+ const ieee154_address_t* SrcAddr,
+ bool PANIDCompression);
+
+ /* Determines the lenght of the MAC header depending on the frame control field*/
+ async command error_t getMHRLength(uint8_t fcf1, uint8_t fcf2, uint8_t *len);
+
+ /* Returns TRUE if source address is the current coordinator and
+ * src PAN is current PAN */
+ command bool isBeaconFromCoord(message_t *frame);
+
+ /* writes the local extended address in little endian format */
+ async command void copyLocalExtendedAddressLE(uint8_t *destLE);
+
+ /* writes the coordinator's extended address in little endian format */
+ command void copyCoordExtendedAddressLE(uint8_t *destLE);
+
+ /* converts a uint64_t to little endian */
+ async command void convertToLE(uint8_t *destLE, const uint64_t *srcNative);
+
+ /* converts little endian to a uint64_t */
+ async command void convertToNative(uint64_t *destNative, const uint8_t *srcLE);
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+interface Ieee802154Debug
+{
+ async command void log(uint8_t priority, uint8_t eventID, uint32_t param1, uint32_t param2, uint32_t param3);
+ command void flush();
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer. - Redistributions in
+ * binary form must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution. - Neither the name of the
+ * Technische Universitaet Berlin nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+#include "TKN154.h"
+interface Purge {
+ /* purges a frame from the transaction queue */
+ command ieee154_status_t purge(uint8_t msduHandle);
+ event void purgeDone(ieee154_txframe_t *txFrame, ieee154_status_t status);
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+interface RadioOff
+{
+
+ /**
+ * Switches the radio off and changes the radio state to RADIO_OFF. This
+ * command will succeed only if the current state of the radio is either
+ * TX_LOADED, RX_PREPARED or RECEIVING.
+ *
+ * @return EALREADY if radio is already switched off <br> FAIL if radio the
+ * current radio state is neither TX_LOADED, RX_PREPARED nor RECEIVING <br>
+ * SUCCESS if the command was accepted and the <tt>offDone()</tt> event will
+ * be signalled.
+ */
+ async command error_t off();
+
+ /**
+ * Signalled in response to a successful call to <tt>off()</tt>. The radio is
+ * now in the state RADIO_OFF.
+ **/
+ async event void offDone();
+
+ /** @return TRUE if the radio is in the state RADIO_OFF, FALSE otherwise */
+ async command bool isOff();
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+#include "TKN154_platform.h"
+interface RadioRx
+{
+
+ /**
+ * Prepares the radio for receive mode. This command will fail, if the radio
+ * is not in the state RADIO_OFF. The actual receive operation will be
+ * triggered through a call to <tt>receive()</tt>.
+ *
+ * @return SUCCESS if the command was accepted and <tt>prepareDone()</tt>
+ * will be signalled; EALREADY if the radio is already in state RX_PREPARED,
+ * FAIL otherwise
+ **/
+ async command error_t prepare();
+
+ /**
+ * Signalled in response to a successful call to <tt>prepare()</tt>. This
+ * event is completing the preparation of a receive operation, the radio is
+ * now in the state RX_PREPARED. The actual receive operation will be
+ * triggered through a call to <tt>receive()</tt>.
+ **/
+ async event void prepareDone();
+
+ /** @return TRUE if the radio is in the state RX_PREPARED, FALSE otherwise */
+ async command bool isPrepared();
+
+ /**
+ * Switches the radio to receive mode at time <tt>t0 + dt</tt>. If
+ * <tt>t0</tt> is NULL, then the callee interprets <tt>t0</tt> as the current
+ * time.
+ *
+ * @param t0 Reference time for receive operation (NULL means now)
+ *
+ * @param dt A positive offset relative to <tt>t0</tt>.
+ *
+ * @return SUCCESS if the the command was accepted and the radio will be
+ * switched to receive mode; FAIL, if the radio is not in the state
+ * RX_PREPARED
+ */
+ async command error_t receive(ieee154_reftime_t *t0, uint32_t dt);
+
+ /** @return TRUE if the radio is in the state RECEIVING, FALSE otherwise */
+ async command bool isReceiving();
+
+ /**
+ * A frame was received and passed the filters described in
+ * IEEE 802.15.4-2006 Sec. 7.5.6.2 ("Reception and rejection").
+ *
+ * @param timestamp The point in time when the first bit of the PPDU
+ * was received or NULL if timestamp is not available.
+ *
+ * @param frame The received frame
+ *
+ * @return a buffer to be used by the driver for the next
+ * incoming frame
+ */
+ event message_t* received(message_t *frame, ieee154_reftime_t *timestamp);
+}
+
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+#include "TKN154_MAC.h"
+#include "TKN154_PHY.h"
+
+interface RadioTx
+{
+
+ /**
+ * Prepares the transmission of a frame. This command will fail, if the
+ * radio is neither in state RADIO_OFF nor in state TX_LOADED. The actual
+ * transmission will be triggered through a call to <tt>transmit()</tt>. Any
+ * frame that was previously prepared for transmission ("loaded") will be
+ * overwritten. The <tt>loadDone()</tt> event signals the completion of the
+ * <tt>load()</tt> command.
+ *
+ * The frame will be loaded (and the radio will stay in the state
+ * TX_LOADED) until either the transmission was successful, i.e.
+ * <tt>transmitDone()</tt> was signalled with a status IEEE154_SUCCESS, or
+ * the radio is explicitly switched off through the <tt>RadioOff</tt>
+ * interface. Until then the callee might have to reserve certain resources
+ * (e.g. the bus connected to the radio), so the caller should keep the time
+ * while a frame is loaded as short as possible.
+ *
+ * @param frame The frame to transmit.
+ *
+ * @return SUCCESS if the command was accepted and <tt>loadDone()</tt> will
+ * be signalled; FAIL otherwise
+ **/
+ async command error_t load(ieee154_txframe_t *frame);
+
+ /**
+ * Signalled in response to a successful call to <tt>load()</tt>. This
+ * event is completing the preparation of a transmission, the radio is
+ * now in the state TX_LOADED. The actual transmission is triggered
+ * through a call to <tt>transmit()</tt>.
+ **/
+ async event void loadDone();
+
+ /**
+ * If the radio is in state TX_LOADED then this commands returns the
+ * the frame that was loaded last; it returns NULL otherwise.
+ *
+ * @return last frame loaded if radio is in the state TX_LOADED,
+ * NULL otherwise
+ **/
+ async command ieee154_txframe_t* getLoadedFrame();
+
+ /**
+ * Transmits the frame whose transmission has previously been prepared
+ * through a call to <tt>load()</tt>. The actual time of transmission -- the
+ * point in time when the first symbol of the PPDU is transmitted -- is
+ * defined by: <tt>t0 + dt</tt>. The data type of the <tt>t0</tt> parameter
+ * is platform-specific (symbol precision or better) while <tt>dt</tt> is
+ * expressed in 802.15.4 symbols. If <tt>t0</tt> is NULL, then the callee
+ * interprets <tt>t0</tt> as the current time. The caller guarantees (through
+ * platform-specific guard times and by calling <tt>transmit</tt> in an
+ * atomic block) that the callee can start the transmission on time, taking
+ * any prior clear channel assesment(s) into consideration.
+ *
+ * A transmission may require 0, 1 or 2 prior clear channel assesments
+ * (<tt>numCCA</tt> parameter) to be performed 0, 20 or 40 symbols,
+ * respectively, before the actual transmission. If a CCA determines a busy
+ * channel, then the frame will not be transmitted.
+ *
+ * A successful transmission may also require an acknowledgement from the
+ * destination (indicated through the <tt>ackRequest</tt> parameter); then,
+ * the callee has to perform the necessary steps for receiving that
+ * acknowledgement (switching the radio to Rx mode immediately after
+ * transmission, etc.; for details see IEEE 802.15.4-2006).
+ *
+ * The <tt>transmit()</tt> command will succeed iff the radio is in state
+ * TX_LOADED. The <tt>transmitDone()</tt> event will then signal the result
+ * of the transmission.
+ *
+ * @param t0 Reference time for transmission (NULL means now)
+ *
+ * @param dt A positive offset relative to <tt>t0</tt>.
+ *
+ * @param numCCA Number of clear channel assesments.
+ *
+ * @param ackRequest TRUE means an acknowledgement is required, FALSE means
+ * no acknowledgement is not required
+ *
+ * @return SUCCESS if the transmission was triggered successfully and only
+ * then <tt>transmitDone()</tt> will be signalled; FAIL, if the transmission
+ * was not triggered because no frame was loaded.
+ */
+ async command error_t transmit(ieee154_reftime_t *t0, uint32_t dt,
+ uint8_t numCCA, bool ackRequest);
+
+ /**
+ * Signalled in response to a call to <tt>transmit()</tt>. Depending on the
+ * <tt>error</tt> parameter the radio is now in state RADIO_OFF
+ * (<tt>error</tt> == IEEE154_SUCCESS) or still in state TX_LOADED
+ * (<tt>error</tt> != IEEE154_SUCCESS). If the transmission succeeded then
+ * the time of transmission -- the point in time when the first symbol of the
+ * PPDU was transmitted -- will be stored in the metadata field of the frame.
+ * In addition, the <tt>t0</tt> parameter will hold a platform-specific
+ * representation of the same point in time (possibly with higher precision)
+ * to be used as future reference time in a <tt>transmit()</tt> command. If
+ * the transmission did not succeed no timestamp will be stored in the
+ * metadata portion, but <tt>t0</tt> will still represent the hypothetical
+ * transmission time.
+ *
+ * If <tt>error</tt> has a value other than IEEE154_SUCCESS the frame will
+ * stay loaded and a subsequent call to <tt>transmit</tt> will (re-)transmit
+ * the same <tt>frame</tt> again. If <tt>error</tt> has a value of
+ * IEEE154_SUCCESS then the frame was automatically un-loaded and a new frame
+ * has to be loaded before the <tt>transmit()</tt> command will succeed.
+ *
+ * When the <tt>transmit()</tt> command was called with an
+ * <tt>ackRequest</tt> parameter with value TRUE, and <tt>error</tt> has a
+ * value of IEEE154_SUCCESS, then this means that a corresponding
+ * acknowledgement was successfully received. In this case, the
+ * <tt>ackPendingFlag</tt> represents the "pending" flag in the header of the
+ * acknowledgement frame (TRUE means set, FALSE means reset).
+ *
+ * @param frame The frame that was transmitted.
+ *
+ * @param t0 The (hypothetical) transmission time; the pointer is only valid
+ * until the eventhandler returns.
+ *
+ * @param ackPendingFlag TRUE if an acknowledgement was received and the
+ * "pending" flag is set in the header of the ACK frame, FALSE otherwise
+ *
+ * @param error SUCCESS if the transmission succeeded (including successful
+ * CCA and acknowledgement reception, if requested); EBUSY if CCA was
+ * unsuccessful (frame was not transmitted); ENOACK if frame was transmitted
+ * but no matching acknowledgement was received.
+ **/
+ async event void transmitDone(ieee154_txframe_t *frame, ieee154_reftime_t *t0,
+ bool ackPendingFlag, error_t error);
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer. - Redistributions in
+ * binary form must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution. - Neither the name of the
+ * Technische Universitaet Berlin nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+interface ResourceTransfer
+{
+
+ /**
+ * Transfer control of a resource to another client. Conceptually, this
+ * command is similar to calling Resource.release() and then forcing the
+ * arbiter to signal the Resource.granted() event to the target client. But
+ * there is one difference: when a resource that was transferred through this
+ * command is released, it is released on behalf of the "original" client,
+ * i.e. who was last signalled the Resource.granted() event. Releasing a
+ * transferred resource is thus equivalent to first transferring it back to
+ * the original client and then forcing the latter to release the resource
+ * through a call to Resource.release() -- this ensures that the arbitration
+ * policy can continue properly (and avoids possible starvation).
+ *
+ * Note that a resource may be transferred multiple times, before it is
+ * released. Then the current owner will change, but the "original" client
+ * will stay the same.
+ *
+ * @return SUCCESS If ownership has been transferred.<br> FAIL ownership has
+ * not been transferred, because the caller is not owner of the resource
+ */
+
+ async command error_t transfer();
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer. - Redistributions in
+ * binary form must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution. - Neither the name of the
+ * Technische Universitaet Berlin nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+interface ResourceTransferConnector
+{
+ async command uint8_t getUserId();
+ async command void transfer();
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer. - Redistributions in
+ * binary form must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution. - Neither the name of the
+ * Technische Universitaet Berlin nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+interface ResourceTransferControl
+{
+ async command error_t transfer(uint8_t fromClient, uint8_t toClient);
+ async command error_t release(uint8_t client);
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer. - Redistributions in
+ * binary form must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution. - Neither the name of the
+ * Technische Universitaet Berlin nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+interface ResourceTransferred
+{
+
+ /**
+ * Control of a resource was transferred to this component from another
+ * client. This event is similar to the Resource.granted() event, but when a
+ * the resource is released, it is released on behalf of the client who was
+ * last signalled the Resource.granted() event.
+ *
+ * @see ResourceTransfer interface
+ */
+ async event void transferred();
+
+ /**
+ *
+ * Release control of a resource - this command is equivalent to calling
+ * Resource.release() and included for convenience.
+ *
+ * @return SUCCESS The resource has been released <br> FAIL You tried to
+ * release but you are not the owner of the resource
+ *
+ * @see ResourceTransfer interface
+ */
+
+ async command error_t release();
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer. - Redistributions in
+ * binary form must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution. - Neither the name of the
+ * Technische Universitaet Berlin nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+interface TimeCalc
+{
+ /**
+ * Returns the interval between time t1 and time t0 assuming
+ * that t0 happened before t1.
+ * @return interval between t1 and t0
+ */
+ async command uint32_t timeElapsed(uint32_t t0, uint32_t t1);
+
+ /**
+ * Assuming that t0 lies in the past, this command returns TRUE
+ * iff t0+dt lies also in the past.
+ * @return TRUE if t0+dt is later than "now"
+ */
+ async command bool hasExpired(uint32_t t0, uint32_t dt);
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer. - Redistributions in
+ * binary form must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution. - Neither the name of the
+ * Technische Universitaet Berlin nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+interface WriteBeaconField
+{
+ // returns length of bytes written
+ command uint8_t write(uint8_t *dest, uint8_t maxlen);
+ // *current* length in byte
+ command uint8_t getLength();
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+
+#include <TKN154.h>
+
+interface IEEE154BeaconFrame
+{
+
+ /**
+ * Reads the Pending Address Specification of a beacon frame.
+ *
+ * @param frame the beacon frame
+ * @param pendAddrSpec a pointer to where the Pending Address
+ * Specification should be written
+ * @return FAIL if the frame is not a beacon frame,
+ * SUCCESS otherwise
+ */
+ command error_t getPendAddrSpec(message_t* frame, uint8_t* pendAddrSpec);
+
+ /**
+ * Reads the Pending Addresses of a given type (short or extended) from a
+ * beacon frame.
+ *
+ * @param frame the beacon frame
+ * @param addrMode the address mode of the sought addresses, either
+ * ADDR_MODE_SHORT_ADDRESS or ADDR_MODE_EXTENDED_ADDRESS
+ * @param buffer a pointer to an array of "bufferSize" addresses
+ * @param bufferSize number of address entries in the buffer
+ *
+ * @return FAIL if the frame is not a beacon frame,
+ * SUCCESS otherwise
+ */
+ command error_t getPendAddr(message_t* frame, uint8_t addrMode,
+ ieee154_address_t buffer[], uint8_t bufferSize);
+
+ /**
+ * Determines whether the local macShortAddress or aExtendedAddress
+ * (as currently registered in the PIB) is part of the pending
+ * address list of a beacon.
+ *
+ * @param frame the beacon frame
+ *
+ * @return ADDR_MODE_NOT_PRESENT if the frame is not a beacon
+ * beacon frame, or the local address is not part of
+ * the pending address list,
+ * ADDR_MODE_SHORT_ADDRESS if the local macShortAddress
+ * is part of the pending address list,
+ * ADDR_MODE_EXTENDED_ADDRESS if the local aExtendedAddress
+ * is part of the pending address list
+ */
+ command uint8_t isLocalAddrPending(message_t* frame);
+
+ /**
+ * Parses the PAN Descriptor of a beacon frame. Since a frame
+ * does not include information about the channel that it was
+ * received on this information must be provided by the caller.
+ *
+ * @param frame the beacon frame
+ * @param LogicalChannel will be written to PANDescriptor->LogicalChannel
+ * @param ChannelPage will be written to PANDescriptor->ChannelPage
+ * @param PANDescriptor a pointer to a PAN Descriptor, that will hold
+ * the PAN Descriptor as parsed of the beacon frame
+ * @param bufferSize number of address entries in the buffer
+ *
+ * @return SUCCESS if the frame is a valid beacon frame and the
+ * PANDescriptor was successfully parsed, FAIL
+ * otherwise
+ */
+ command error_t parsePANDescriptor(message_t *frame, uint8_t LogicalChannel,
+ uint8_t ChannelPage, ieee154_PANDescriptor_t *PANDescriptor);
+
+ /**
+ * Returns a pointer to the beacon payload.
+ *
+ * @param frame the beacon frame
+ * @return a pointer to the beacon payload, or, if the
+ * frame is not a beacon frame, a pointer to
+ * the MAC payload. If the frame was received
+ * while in promiscuous mode, then this command
+ * returns a pointer to the first byte of the MHR.
+ */
+ command void* getBeaconPayload(message_t* frame);
+
+ /**
+ * Returns the length of the beacon payload portion of the frame
+ * (in byte).
+ *
+ * @param frame the frame
+ * @return the length (in byte) of the frame's beacon payload
+ * portion, or, if the frame is not a beacon frame
+ * the length of the MAC payload. If the frame
+ * was received while in promiscuous mode, then
+ * this command returns the length of MHR + MAC Payload.
+ */
+ command uint8_t getBeaconPayloadLength(message_t* frame);
+
+ /**
+ * Returns the (beacon) sequence number of the frame.
+ *
+ * @param frame the frame
+ * @return sequence number of the frame
+ */
+ command uint8_t getBSN(message_t* frame);
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+
+#include <TKN154.h>
+#include <message.h>
+
+interface IEEE154Frame
+{
+
+ /**
+ * Returns the source addressing mode of the frame.
+ *
+ * @param frame the frame
+ * @return source addressing mode of the frame; either
+ * ADDR_MODE_NOT_PRESENT, ADDR_MODE_RESERVED,
+ * ADDR_MODE_SHORT_ADDRESS or ADDR_MODE_EXTENDED_ADDRESS
+ */
+ command uint8_t getSrcAddrMode(message_t* frame);
+
+ /**
+ * Reads the source address (to be interpreted
+ * as specified by the source addressing mode) of the frame.
+ *
+ * @param frame the frame
+ * @param address a pointer to where the source address
+ * will be written
+ * @return SUCCESS, if the source address is present
+ * and was written to "address",
+ * FAIL otherwise (source address remains
+ * unmodified)
+ */
+ command error_t getSrcAddr(message_t* frame, ieee154_address_t *address);
+
+ /**
+ * Reads the source PAN identifier of the frame.
+ *
+ * @param frame the frame
+ * @param PANID a pointer to where the source PAN identifier
+ * will be written
+ * @return SUCCESS, if the source PAN identifier is present
+ * and was written to "PANID",
+ * FAIL otherwise (PANID remains unmodified)
+ */
+ command error_t getSrcPANId(message_t* frame, uint16_t* PANID);
+
+ /**
+ * Returns the destination addressing mode of the frame.
+ *
+ * @param frame the frame
+ * @return destination addressing mode of the frame; either
+ * ADDR_MODE_NOT_PRESENT, ADDR_MODE_RESERVED,
+ * ADDR_MODE_SHORT_ADDRESS or ADDR_MODE_EXTENDED_ADDRESS
+ */
+ command uint8_t getDstAddrMode(message_t* frame);
+
+ /**
+ * Reads the destination address (to be interpreted
+ * as specified by the destination addressing mode) of the frame.
+ *
+ * @param frame the frame
+ * @param address a pointer to where the destination address
+ * will be written
+ * @return SUCCESS, if the destination address is present
+ * and was written to "address",
+ * FAIL otherwise (destination address
+ * remains unmodified)
+ */
+ command error_t getDstAddr(message_t* frame, ieee154_address_t *address);
+
+ /**
+ * Reads the destination PAN identifier of the frame.
+ *
+ * @param PANID a pointer to where the destination
+ * PAN identifier should be written
+ * @param frame the frame
+ * @return SUCCESS, if the destination PAN identifier
+ * is present and was copied to "PANID",
+ * FAIL otherwise (PANID remains unmodified)
+ */
+ command error_t getDstPANId(message_t* frame, uint16_t* PANID);
+
+ /**
+ * Sets the addressing fields in the MAC header of a frame. The source
+ * PAN identifier and the source address will be set automatically, their
+ * values depend on the <code>SrcAddrMode</code> parameter: if
+ * <code>SrcAddrMode</code> is a short or extended address, then
+ * the current PIB attributes <code>macShortAddress</code> or
+ * <code>aExtendedAddress</code> and <code>macPANId</code> are used.
+ *
+ * @param frame the frame
+ * @param srcAddrMode the source addressing mode
+ * @param dstAddrMode the destination addressing mode
+ * @param dstPANID the 16 bit PAN identifier of the destination
+ * @param dstAddr individual device address of the destination as per
+ * the dstAddrMode
+ * @param security the security options (NULL means security is
+ * disabled)
+ *
+ * @return SUCCESS if the addressing fields where written,
+ * FAIL if a wrong addressing mode was specified
+ */
+ command error_t setAddressingFields(message_t* frame,
+ uint8_t SrcAddrMode,
+ uint8_t DstAddrMode,
+ uint16_t DstPANID,
+ ieee154_address_t *DstAddr,
+ ieee154_security_t *security);
+
+ /**
+ * Returns a pointer to the MAC payload portion of a frame.
+ *
+ * @param frame the frame
+ * @return a pointer to the frame's payload
+ */
+ command void* getPayload(message_t* frame);
+
+ /**
+ * Returns the length of the MAC payload portion of the frame (in byte).
+ *
+ * @param frame the frame
+ * @return the length of the frame's payload (in byte)
+ */
+ command uint8_t getPayloadLength(message_t* frame);
+
+ /**
+ * Returns the point in time when the frame was received. If
+ * <code>isTimestampValid()<\code> returns FALSE then the
+ * timestamp is not valid and must be ignored.
+ *
+ * @param frame the frame
+ * @return timestamp of the frame
+ */
+ command uint32_t getTimestamp(message_t* frame);
+
+ /**
+ * Tells whether the timestamp is valid.
+ *
+ * @return TRUE if timestamp is valid, FALSE otherwise.
+ */
+ command bool isTimestampValid(message_t* frame);
+
+ /**
+ * Returns the sequence number of the frame.
+ *
+ * @param frame the frame
+ * @return sequence number of the frame
+ */
+ command uint8_t getDSN(message_t* frame);
+
+ /**
+ * Returns the link quality level at which the frame was received.
+ *
+ * @param frame the frame
+ * @return link quality level
+ */
+ command uint8_t getLinkQuality(message_t* frame);
+
+ /**
+ * Returns the type of the frame
+ * BEACON=0, DATA=1, ACK=2, COMMAND=3.
+ *
+ * Note: For beacon frames one can use the <code>IEEE154BeaconFrame<\code>
+ * interface to inspect additional fields of the frame.
+ *
+ * @param frame the frame
+ * @return the type of the frame
+ */
+ command uint8_t getFrameType(message_t* frame);
+
+ /**
+ * Returns a pointer to the MAC header (i.e. to the first byte of
+ * the Frame Control field).
+ *
+ * @param frame the frame
+ * @return a pointer to the frame's header
+ */
+ command void* getHeader(message_t* frame);
+
+ /**
+ * Returns the length of the MAC header.
+ *
+ * @param frame the frame
+ * @return the length of the MAC header (in byte)
+ */
+ command uint8_t getHeaderLength(message_t* frame);
+
+ /**
+ * Tells whether or not the frame was received while
+ * promiscuous mode was enabled.
+ *
+ * @param frame the frame
+ * @return TRUE if frame was received while in promiscuous
+ * mode, FALSE otherwise
+ */
+ command bool wasPromiscuousModeEnabled(message_t* frame);
+
+ /**
+ * Tells whether or not the frame has a standard compliant
+ * IEEE 802.15.4 header - this will only be relevant for frames
+ * received while in promiscuous mode, because then no filtering
+ * (except CRC check) was applied. Note: if this command returns
+ * FALSE, then all other commands in this interface (except
+ * <code>wasPromiscuousModeEnabled()</code>) and the
+ * <code>IEEE154BeaconFrame</code> interface return undefined values!
+ *
+ * @param frame the frame
+ * @return TRUE if frame has a standard compliant header,
+ * FALSE otherwise
+ */
+ command bool hasStandardCompliantHeader(message_t* frame);
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2008, Technische Universitaet Berlin
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Technische Universitaet Berlin nor the names
+ * of its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * - Revision -------------------------------------------------------------
+ * $Revision$
+ * $Date$
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de>
+ * ========================================================================
+ */
+
+
+#include <TKN154.h>
+
+interface IEEE154TxBeaconPayload
+{
+ /**
+ * Sets the beacon payload portion for all subsequently transmitted beacons.
+ * This command replaces the MLME-SET command for the PIB attribute values
+ * 0x45 (macBeaconPayload) and 0x46 (macBeaconPayloadLength). The
+ * <code>setBeaconPayloadDone()<\code> event will be signalled when the
+ * beacon payload has been set -- until then <code>beaconPayload<\code> must
+ * not be modified.
+ *
+ * @param beaconPayload the new beacon payload
+ * @param length the length of the new beacon payload (in byte)
+ *
+ * @return EBUSY if another transaction is pending, ESIZE if length is too big,
+ * SUCCESS otherwise (and only then the <code>setBeaconPayloadDone<\code> event
+ * will be signalled)
+ */
+ command error_t setBeaconPayload(void *beaconPayload, uint8_t length);
+
+ /**
+ * Signalled in response to a <code>setBeaconPayload()<\code> request.
+ * Indicates that the beacon payload has been copied and returns the
+ * ownership of the buffer to the next higher layer.
+ *
+ * @param beaconPayload the <code>beaconPayload<\code> passed in the
+ * <code>setBeaconPayload()<\code> command
+ * @param length the <code>length<\code> passed in the
+ * <code>setBeaconPayload()<\code> command
+ */
+ event void setBeaconPayloadDone(void *beaconPayload, uint8_t length);
+
+ /**
+ * Returns a pointer to the current beacon payload.
+ *
+ * @return the current beacon payload
+ */
+ command const void* getBeaconPayload();
+
+ /**
+ * Returns the length of the current beacon payload (in byte).
+ *
+ * @return length of the current beacon payload
+ */
+ command uint8_t getBeaconPayloadLength();
+
+ /**
+ * Replaces (overwrites) a portion of the current beacon payload. Whenever
+ * possible, to minimize overhead, the next higher layer should prefer this
+ * command over the <code>setBeaconPayload()<\code> command. The
+ * <code>modifyBeaconPayloadDone()<\code> event will be signalled when the
+ * beacon payload has been updated -- until then <code>buffer<\code> must
+ * not be modified.
+ *
+ * @param offset offset into the current beacon payload
+ * @param buffer the buffer to be written
+ * @param length the length of the buffer
+ *
+ * @return EBUSY if another transaction is pending, ESIZE if offset+length is too big,
+ * SUCCESS otherwise (and only then the <code>modifyBeaconPayloadDone<\code> event
+ * will be signalled)
+ */
+ command error_t modifyBeaconPayload(uint8_t offset, void *buffer, uint8_t bufferLength);
+
+ /**
+ * Signalled in response to a <code>modifyBeaconPayload()<\code> request.
+ * Indicates that the beacon payload has been updated.
+ *
+ * @param offset the <code>offset<\code> passed in the
+ * <code>modifyBeaconPayload()<\code> command
+ * @param buffer the <code>buffer<\code> passed in the
+ * <code>modifyBeaconPayload()<\code> command
+ * @param bufferLength the <code>bufferLength<\code> passed in the
+ * <code>modifyBeaconPayload()<\code> command
+ */
+ event void modifyBeaconPayloadDone(uint8_t offset, void *buffer, uint8_t bufferLength);
+
+ /**
+ * Indicates that a beacon frame will be transmitted "soon" and now is a good
+ * time to update the beacon payload (if desired).
+ *
+ * The usual policy is that (1) this event is signalled before every beacon
+ * transmission, and (2) that a subsequent call to <code>setPayload<\code>
+ * will update the beacon payload portion of this beacon. However,
+ * because of tight timing constraints in beacon-enabled mode neither can be
+ * guaranteed!
+ */
+ event void aboutToTransmit();
+
+ /**
+ * Indicates that a beacon frame has been transmitted (the
+ * <code>getBeaconPayload<\code> command can be used to inspect the
+ * beacon payload).
+ */
+ event void beaconTransmitted();
+}