[Tinyos-contrib-commits] CVS: tinyos-1.x/contrib/diku/evb13192/tos/lib/ieee802154/mac CallbackServiceM.nc, NONE, 1.1 Ieee802154MacC.nc, 1.13, 1.14 mac.h, 1.12, 1.13 DataM.nc, 1.6, 1.7 BeaconTrackerM.nc, 1.13, 1.14 SuperframeM.nc, 1.9, 1.10 IndirectTxM.nc, 1.1, 1.2 MacConst.h, 1.1, 1.2 CfpControlM.nc, 1.1, 1.2 Ieee802154Adts.h, 1.10, 1.11 StartM.nc, 1.6, 1.7 AssociateM.nc, 1.8, 1.9 BeaconGeneratorM.nc, 1.1, 1.2 CapControlM.nc, 1.7, 1.8 GetSetM.nc, 1.4, 1.5 MacStateControlM.nc, 1.2, NONE

Jan Flora janflora at users.sourceforge.net
Sat Sep 16 10:52:28 PDT 2006


Update of /cvsroot/tinyos/tinyos-1.x/contrib/diku/evb13192/tos/lib/ieee802154/mac
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv10095/tos/lib/ieee802154/mac

Modified Files:
	Ieee802154MacC.nc mac.h DataM.nc BeaconTrackerM.nc 
	SuperframeM.nc IndirectTxM.nc MacConst.h CfpControlM.nc 
	Ieee802154Adts.h StartM.nc AssociateM.nc BeaconGeneratorM.nc 
	CapControlM.nc GetSetM.nc 
Added Files:
	CallbackServiceM.nc 
Removed Files:
	MacStateControlM.nc 
Log Message:
802.15.4 GTS functionality updates

--- NEW FILE: CallbackServiceM.nc ---
/* Copyright (c) 2006, Jan Flora <janflora at diku.dk>
 * 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 University of Copenhagen 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.
 */

/*
  @author Jan Flora <janflora at diku.dk>
*/

module CallbackServiceM
{
	provides
	{
		interface StdControl;
		interface CallbackService;
	}
	uses
	{
		interface FIFOQueue as Queue;
		interface Debug;
	}
}
implementation
{
	#define DBG_LEVEL 1
	#include "Debug.h"
	
	// Primitive queues.
	uint8_t *primitiveBuffer[10];
	FIFOQueue_t primitiveQueue;
	uint8_t *primitiveFuncBuffer[10];
	FIFOQueue_t primitiveFuncQueue;
	
	bool serviceTaskPosted = FALSE;
	
	task void serviceQueueTask();
	
	command result_t StdControl.init()
	{
		call Queue.initQueue(&primitiveQueue, primitiveBuffer, 10);
		call Queue.initQueue(&primitiveFuncQueue, primitiveFuncBuffer, 10);
		return SUCCESS;
	}

	command result_t StdControl.start()
	{
		return SUCCESS;
	}
 
	command result_t StdControl.stop()
	{
		return SUCCESS;
	}
	
	command void CallbackService.enqueue(uint8_t *primitive, void(*callback)(uint8_t*))
	{
			call Queue.enqueue(&primitiveQueue, primitive);
			call Queue.enqueue(&primitiveFuncQueue, (uint8_t*)callback);
			if (!serviceTaskPosted) {
				serviceTaskPosted = TRUE;
				post serviceQueueTask();
			}
	}
	
	task void serviceQueueTask()
	{
		uint8_t *primitive = NULL, *fp = NULL;
		void (*func)(uint8_t*);
		
		while (!(call Queue.isEmpty(&primitiveQueue))) {
			// Dequeue function and primitive.
			call Queue.dequeue(&primitiveQueue, &primitive);
			call Queue.dequeue(&primitiveFuncQueue, &fp);
			func = (void(*)(uint8_t*))fp;
			// Call to signal the right event.
			func(primitive);
		}
		serviceTaskPosted = FALSE;
	}
	
}

Index: Ieee802154MacC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/diku/evb13192/tos/lib/ieee802154/mac/Ieee802154MacC.nc,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** Ieee802154MacC.nc	23 Aug 2006 09:54:56 -0000	1.13
--- Ieee802154MacC.nc	16 Sep 2006 17:52:23 -0000	1.14
***************
*** 111,117 ****
--- 111,122 ----
  		interface AsyncAlarm<time_t> as TimeoutAlarm1;
  		interface AsyncAlarm<time_t> as TimeoutAlarm2;
+ 		interface AsyncAlarm<time_t> as CfpAlarm;
+ 		interface AsyncAlarm<time_t> as CfpAlarm2;
  	
  		interface LocalTime;
  		
+ 		// Fifo queueing support.
+ 		interface FIFOQueue;
+ 		
  		// Buffer Management.
  		interface IeeeBufferManagement as BufferMng;
***************
*** 137,140 ****
--- 142,146 ----
  	           BeaconTrackerM,
  	           CapControlM,
+ 	           CfpControlM,
  	           CsmaM,
  	           DataM,
***************
*** 148,151 ****
--- 154,158 ----
  	           SuperframeM,
  	           TimingServiceM,
+ 	           CallbackServiceM,
  	           DummyM,
  	           
***************
*** 182,185 ****
--- 189,193 ----
  	StdControl = ScanM.StdControl;
  	StdControl = CapControlM.StdControl;
+ 	StdControl = CallbackServiceM.StdControl;
  
  
***************
*** 206,211 ****
  	
  
! 	MlmeIndicationGts = DummyM.MlmeIndicationGts;
! 	MlmeRequestConfirmGts = DummyM.MlmeRequestConfirmGts;
  
  	MlmeRequestConfirmGet = GetSetM.MlmeRequestConfirmGet;
--- 214,219 ----
  	
  
! 	MlmeIndicationGts = CfpControlM.MlmeIndicationGts;
! 	MlmeRequestConfirmGts = CfpControlM.MlmeRequestConfirmGts;
  
  	MlmeRequestConfirmGet = GetSetM.MlmeRequestConfirmGet;
***************
*** 299,302 ****
--- 307,314 ----
  	StartM.BufferMng = BufferMng;
  	IndirectTxM.BufferMng = BufferMng;
+ 	CfpControlM.BufferMng = BufferMng;
+ 	
+ 	// Wire fifo queue interface
+ 	CallbackServiceM.Queue = FIFOQueue;
  	
  	// Wire the reset function.
***************
*** 319,329 ****
--- 331,345 ----
  	TimingServiceM.ResponseWaitAlarm = TimeoutAlarm1;
  	TimingServiceM.FrameResponseAlarm = TimeoutAlarm2;
+ 	CfpControlM.CfpAlarm = CfpAlarm;
+ 	CfpControlM.RxOffAlarm = CfpAlarm2;
  	
  	SuperframeM.LocalTime = LocalTime;
  	CsmaM.LocalTime = LocalTime;
  	CapControlM.LocalTime = LocalTime;
+ 	CfpControlM.LocalTime = LocalTime;
  	RxEnableM.LocalTime = LocalTime;
  	BeaconGeneratorM.LocalTime = LocalTime;
  	
+ 	
  	// Wire random number generator
  	MacPibDatabaseM.Random = Random;
***************
*** 344,352 ****
  	IndirectTxM.MacAddress -> MacAddressM.MacAddress;
  	OrphanHandlerM.MacAddress -> MacAddressM.MacAddress;
  	
  	// Inter-MAC wiring
  	ScanServiceM.BeaconFrame -> FrameRxM.ScanBeaconFrame;
  	ScanServiceM.CoordRealignFrame -> FrameRxM.CoordRealignFrame;
- 	ScanServiceM.FrameTx -> FrameTxM.FrameTx[0];
  	ScanServiceM.FrameRx -> FrameRxM.FrameRx;
  	ScanServiceM.Ed -> EdM.Ed;
--- 360,377 ----
  	IndirectTxM.MacAddress -> MacAddressM.MacAddress;
  	OrphanHandlerM.MacAddress -> MacAddressM.MacAddress;
+ 	CfpControlM.MacAddress -> MacAddressM.MacAddress;
+ 	
+ 	// Wire the application callback service.
+ 	AssociateM.CallbackService -> CallbackServiceM.CallbackService;
+ 	CfpControlM.CallbackService -> CallbackServiceM.CallbackService;
+ 	DataM.CallbackService -> CallbackServiceM.CallbackService;
+ 	BeaconTrackerM.CallbackService -> CallbackServiceM.CallbackService;
+ 	GetSetM.CallbackService -> CallbackServiceM.CallbackService;
+ 	IndirectTxM.CallbackService -> CallbackServiceM.CallbackService;
+ 	StartM.CallbackService -> CallbackServiceM.CallbackService;
  	
  	// Inter-MAC wiring
  	ScanServiceM.BeaconFrame -> FrameRxM.ScanBeaconFrame;
  	ScanServiceM.CoordRealignFrame -> FrameRxM.CoordRealignFrame;
  	ScanServiceM.FrameRx -> FrameRxM.FrameRx;
  	ScanServiceM.Ed -> EdM.Ed;
***************
*** 356,359 ****
--- 381,385 ----
  	BeaconTrackerM.Superframe -> SuperframeM.Superframe;
  	BeaconTrackerM.PollService -> PollServiceM.PollService[1];
+ 	BeaconTrackerM.BeaconGtsService -> CfpControlM.BeaconGtsService;
  	GetSetM.PibDatabase -> MacPibDatabaseM.PibDatabase;
  	AssociateM.AssocReqFrame -> FrameRxM.AssocReqFrame;
***************
*** 364,367 ****
--- 390,395 ----
  	AssociateM.DeviceTx -> CapControlM.DeviceTx[0];
  	PollServiceM.DeviceTx -> CapControlM.DeviceTx[1];
+ 	DataM.DeviceTx -> CapControlM.DeviceTx[2];
+ 	CfpControlM.DeviceTx -> CapControlM.DeviceTx[3];
  	PollServiceM.DeviceRx -> CapControlM.DeviceRx;
  	PollServiceM.TimingService -> TimingServiceM.TimingService[1];
***************
*** 372,380 ****
  	CapControlM.DeviceCap -> BeaconTrackerM.DeviceCap;
  	CapControlM.CoordinatorCap -> BeaconGeneratorM.CoordinatorCap;
  	CsmaM.FrameTx -> FrameTxM.FrameTx[1];
  	CsmaM.Superframe -> SuperframeM.Superframe;
  	PollM.PollService -> PollServiceM.PollService[2];
  	DataM.DataFrame -> FrameRxM.DataFrame;
! 	DataM.DeviceTx -> CapControlM.DeviceTx[2];
  	GetSetM.FrameRx -> FrameRxM.FrameRx;
  	RxEnableM.DeviceRx -> CapControlM.DeviceRx;
--- 400,416 ----
  	CapControlM.DeviceCap -> BeaconTrackerM.DeviceCap;
  	CapControlM.CoordinatorCap -> BeaconGeneratorM.CoordinatorCap;
+ 	CfpControlM.GtsReqFrame -> FrameRxM.GtsReqFrame;
+ 	CfpControlM.Superframe -> SuperframeM.Superframe;
+ 	CfpControlM.FrameRx -> FrameRxM.FrameRx;
+ 	CfpControlM.DeviceCfp -> BeaconTrackerM.DeviceCfp;
+ 	CfpControlM.CoordinatorCfp -> BeaconGeneratorM.CoordinatorCfp;
+ 	ScanServiceM.FrameTx -> FrameTxM.FrameTx[0];
  	CsmaM.FrameTx -> FrameTxM.FrameTx[1];
+ 	BeaconGeneratorM.FrameTx -> FrameTxM.FrameTx[2];
+ 	CfpControlM.FrameTx -> FrameTxM.FrameTx[3];
  	CsmaM.Superframe -> SuperframeM.Superframe;
  	PollM.PollService -> PollServiceM.PollService[2];
  	DataM.DataFrame -> FrameRxM.DataFrame;
! 	DataM.CfpTx -> CfpControlM.CfpTx;
  	GetSetM.FrameRx -> FrameRxM.FrameRx;
  	RxEnableM.DeviceRx -> CapControlM.DeviceRx;
***************
*** 382,389 ****
  	RxEnableM.Superframe -> SuperframeM.Superframe;
  	BeaconGeneratorM.Superframe -> SuperframeM.Superframe;
- 	BeaconGeneratorM.FrameTx -> FrameTxM.FrameTx[2];
  	BeaconGeneratorM.BeaconDataService -> IndirectTxM.BeaconDataService;
  	BeaconGeneratorM.BeaconReqFrame -> FrameRxM.BeaconReqFrame;
  	BeaconGeneratorM.CoordinatorTx -> CapControlM.CoordinatorTx[0];
  	StartM.BeaconGenerator -> BeaconGeneratorM.BeaconGenerator;
  	StartM.CoordinatorTx -> CapControlM.CoordinatorTx[1];
--- 418,425 ----
  	RxEnableM.Superframe -> SuperframeM.Superframe;
  	BeaconGeneratorM.Superframe -> SuperframeM.Superframe;
  	BeaconGeneratorM.BeaconDataService -> IndirectTxM.BeaconDataService;
  	BeaconGeneratorM.BeaconReqFrame -> FrameRxM.BeaconReqFrame;
  	BeaconGeneratorM.CoordinatorTx -> CapControlM.CoordinatorTx[0];
+ 	BeaconGeneratorM.BeaconGtsService -> CfpControlM.BeaconGtsService;
  	StartM.BeaconGenerator -> BeaconGeneratorM.BeaconGenerator;
  	StartM.CoordinatorTx -> CapControlM.CoordinatorTx[1];
***************
*** 412,415 ****
--- 448,452 ----
  	TimingServiceM.Debug = Debug;
  	CapControlM.Debug = Debug;
+ 	CfpControlM.Debug = Debug;
  	CsmaM.Debug = Debug;
  	PollServiceM.Debug = Debug;

Index: mac.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/diku/evb13192/tos/lib/ieee802154/mac/mac.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** mac.h	23 Aug 2006 09:54:56 -0000	1.12
--- mac.h	16 Sep 2006 17:52:23 -0000	1.13
***************
*** 88,91 ****
--- 88,92 ----
  	uint8_t beaconPublishCount; // Used for publish timeout in coordinator GTSs.
  	                            // Used for publish wait timeout in device GTSs.
+ 	uint16_t timeout; // Coordinator GTS slot timeout.
  } gtsDescriptor_t;
  

Index: DataM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/diku/evb13192/tos/lib/ieee802154/mac/DataM.nc,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** DataM.nc	23 Aug 2006 09:54:56 -0000	1.6
--- DataM.nc	16 Sep 2006 17:52:23 -0000	1.7
***************
*** 39,44 ****
--- 39,46 ----
  	{
  		interface CapTx as DeviceTx;
+ 		interface CfpTx;
  		interface IndirectTx;
  		interface RxFrame as DataFrame;
+ 		interface CallbackService;
  		interface IeeeBufferManagement as BufferMng;
  		interface Debug;
***************
*** 49,57 ****
  	#define DBG_LEVEL 1
  	#include "Debug.h"
- 	
- 	Mcps_DataIndication dataIndication;
  
  	void doDataConfirm(txHeader_t *header);
! 	task void indicateData();
  
  	command result_t McpsRequestConfirmData.request(Mcps_DataRequestConfirm request)
--- 51,57 ----
  	#define DBG_LEVEL 1
  	#include "Debug.h"
  
  	void doDataConfirm(txHeader_t *header);
! 	void indicateData(uint8_t *dataIndication);
  
  	command result_t McpsRequestConfirmData.request(Mcps_DataRequestConfirm request)
***************
*** 88,94 ****
  		if (txOptions & 0x02) {
  			// GTS transfer.
! 			// TODO: If destination is myCoordinator check device CFP for transmit slot.
! 			// TODO: If localCoordinator, check coordinator CFP for device receive slot.
! 			return FAIL;
  		} else if ((txOptions & 0x04) && macCoordinator) {
  			// Indirect transfer.
--- 88,92 ----
  		if (txOptions & 0x02) {
  			// GTS transfer.
! 			call CfpTx.sendFrame(myTxHeader);
  		} else if ((txOptions & 0x04) && macCoordinator) {
  			// Indirect transfer.
***************
*** 105,108 ****
--- 103,110 ----
  	{
  		uint8_t *newBuffer;
+ 		Mcps_DataIndication dataIndication;
+ 		
+ 		// Data reception is indicated to CFP control.
+ 		call CfpTx.dataReceived();
  		
  		// Just build an indication primitive containing the data.
***************
*** 130,135 ****
  		dataIndication->msg.indication.mpduLinkQuality = data->linkQuality;
  		dataIndication->msg.indication.ACLEntry = 0x08; // TODO: Support security at some point.
! 		
! 		post indicateData();
  		return newBuffer;
  	}
--- 132,136 ----
  		dataIndication->msg.indication.mpduLinkQuality = data->linkQuality;
  		dataIndication->msg.indication.ACLEntry = 0x08; // TODO: Support security at some point.
! 		call CallbackService.enqueue((uint8_t*)dataIndication, indicateData);
  		return newBuffer;
  	}
***************
*** 145,151 ****
  	}
  	
! 	task void indicateData()
  	{
! 		signal McpsIndicationData.indication(dataIndication);
  	}
  	
--- 146,157 ----
  	}
  	
! 	event void CfpTx.done(txHeader_t *header)
  	{
! 		doDataConfirm(header);
! 	}
! 	
! 	void indicateData(uint8_t *dataIndication)
! 	{
! 		signal McpsIndicationData.indication((Mcps_DataIndication)dataIndication);
  	}
  	

Index: BeaconTrackerM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/diku/evb13192/tos/lib/ieee802154/mac/BeaconTrackerM.nc,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** BeaconTrackerM.nc	23 Aug 2006 12:21:48 -0000	1.13
--- BeaconTrackerM.nc	16 Sep 2006 17:52:23 -0000	1.14
***************
*** 41,44 ****
--- 41,45 ----
  		interface IeeeIndication<Mlme_SyncLossIndication> as MlmeIndicationSyncLoss;
  		interface CapEvents as DeviceCap;
+ 		interface CapEvents as DeviceCfp;
  		interface Reset;
  	}
***************
*** 57,60 ****
--- 58,62 ----
  		interface MacAddress;
  		interface BeaconGtsService;
+ 		interface CallbackService;
  		interface Debug;
  	}
***************
*** 68,73 ****
  	void disableBeaconMode();
  	void beaconNotify(rxdata_t *data);
  	
- 	task void signalBeaconNotify();
  	task void poll();
  	task void missedBeacon();
--- 70,75 ----
  	void disableBeaconMode();
  	void beaconNotify(rxdata_t *data);
+ 	void signalBeaconNotify(uint8_t *beaconNotifyInd);
  	
  	task void poll();
  	task void missedBeacon();
***************
*** 76,81 ****
  	bool pollPosted = FALSE;
  	bool pollExt;
! 	
! 	mlmeBeaconNotifyIndication_t *beaconNotifyInd;
  	bool listening = FALSE;
  	bool tracking = FALSE;
--- 78,82 ----
  	bool pollPosted = FALSE;
  	bool pollExt;
! 
  	bool listening = FALSE;
  	bool tracking = FALSE;
***************
*** 182,191 ****
  			uint8_t gtsDirections = msduGTSDirectionMask(data->frame);
  			msduGTSList_t *gtsList = msduGTSList(data->frame);
! 			
  			for (i=0;i<numGtsDesc;i++) {
  				if (gtsList->DeviceShortAddress == macShortAddress) {
  					// We have a GTS update.
! 					// TODO: Connect and enable.
! 					//call BeaconGtsService.gtsUpdate(gtsList->GTSStartingSlot, gtsList->GTSLength, gtsDirections & i);
  				}
  				gtsList += sizeof(msduGTSList_t);
--- 183,191 ----
  			uint8_t gtsDirections = msduGTSDirectionMask(data->frame);
  			msduGTSList_t *gtsList = msduGTSList(data->frame);
! 
  			for (i=0;i<numGtsDesc;i++) {
  				if (gtsList->DeviceShortAddress == macShortAddress) {
  					// We have a GTS update.
! 					call BeaconGtsService.gtsUpdate(gtsList->GTSStartingSlot, gtsList->GTSLength, gtsDirections & (1<<i));
  				}
  				gtsList += sizeof(msduGTSList_t);
***************
*** 247,252 ****
  		// Set up the track alarm to fire just before next beacon
  		call TrackAlarm.armAlarmClock(nextCommence-50);
! 		// TODO: Connect and enable.
! 		//call BeaconGtsService.beaconReceived();
  		
  		//DBG_STRINT("Cap end is:",capEnd,1);
--- 247,251 ----
  		// Set up the track alarm to fire just before next beacon
  		call TrackAlarm.armAlarmClock(nextCommence-50);
! 		call BeaconGtsService.beaconReceived();
  		
  		//DBG_STRINT("Cap end is:",capEnd,1);
***************
*** 262,265 ****
--- 261,265 ----
  		// TODO: Do we always copy the beacon primitive here? What about deallocation sizes?
  		uint8_t *myBeacon;
+ 		mlmeBeaconNotifyIndication_t *beaconNotifyInd;
  		// create a beacon notify primitive
  		if (SUCCESS != call BufferMng.claim(sizeof(mlmeBeaconNotifyIndication_t),(uint8_t**)(&beaconNotifyInd))){
***************
*** 279,285 ****
  			beaconNotifyInd->msg.indication.ACLEntry = 0x08; // TODO
  			beaconNotifyInd->msg.indication.securityFailure = FALSE; // TODO
! 			// post a task to notify upper layer with beacon
! 			// TODO: ensure only one beaconNotify task posted at a time
! 			post signalBeaconNotify();
  		}
  	}
--- 279,284 ----
  			beaconNotifyInd->msg.indication.ACLEntry = 0x08; // TODO
  			beaconNotifyInd->msg.indication.securityFailure = FALSE; // TODO
! 			// Notify upper layer with beacon
! 			call CallbackService.enqueue((uint8_t*)beaconNotifyInd, signalBeaconNotify);
  		}
  	}
***************
*** 297,301 ****
  			if (call Superframe.cfpExists(&deviceSuperframe)) {
  				// We start up the device CFP.
! 				//signal DeviceCfp.startNotification();
  				cfpEnd = call Superframe.getCfpEnd(&deviceSuperframe);
  				if (cfpEnd < nextCommence) {
--- 296,300 ----
  			if (call Superframe.cfpExists(&deviceSuperframe)) {
  				// We start up the device CFP.
! 				signal DeviceCfp.startNotification();
  				cfpEnd = call Superframe.getCfpEnd(&deviceSuperframe);
  				if (cfpEnd < nextCommence) {
***************
*** 402,409 ****
  	}
  	
! 	task void signalBeaconNotify()
  	{
  		DBG_STR("beaconNotify",2);
! 		signal MlmeIndicationBeaconNotify.indication(beaconNotifyInd);
  	}
  
--- 401,408 ----
  	}
  	
! 	void signalBeaconNotify(uint8_t *beaconNotifyInd)
  	{
  		DBG_STR("beaconNotify",2);
! 		signal MlmeIndicationBeaconNotify.indication((Mlme_BeaconNotifyIndication)beaconNotifyInd);
  	}
  

Index: SuperframeM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/diku/evb13192/tos/lib/ieee802154/mac/SuperframeM.nc,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** SuperframeM.nc	23 Aug 2006 12:21:48 -0000	1.9
--- SuperframeM.nc	16 Sep 2006 17:52:24 -0000	1.10
***************
*** 33,36 ****
--- 33,38 ----
  */
  
+ #include "mac.h"
+ 
  module SuperframeM
  {
***************
*** 65,71 ****
  			return TRUE;
  		}
  		calculateTransactionTime(header);
! 		return header->transactionTime + 
! 		       sf->beaconLength*aUnitBackoffPeriod
  		       < sf->capLength*sf->slotLength;
  	}
--- 67,74 ----
  			return TRUE;
  		}
+ 		// TODO: What do we do, when superframe isn't updated yet?
  		calculateTransactionTime(header);
! 		return (header->transactionTime + 
! 		       sf->beaconLength*aUnitBackoffPeriod)
  		       < sf->capLength*sf->slotLength;
  	}
***************
*** 85,89 ****
  	command time_t Superframe.getSlotStartTime(superframe_t *sf, uint8_t slot)
  	{
! 		return sf->startTime + (sf->slotLength*(slot-1));
  	}
  	
--- 88,97 ----
  	command time_t Superframe.getSlotStartTime(superframe_t *sf, uint8_t slot)
  	{
! 		return sf->startTime + (sf->slotLength*slot);
! 	}
! 	
! 	command uint8_t Superframe.getCurrentSlot(superframe_t *sf)
! 	{
! 		return getElapsedSymbols(sf)/sf->slotLength;
  	}
  	
***************
*** 96,99 ****
--- 104,118 ----
  	}
  	
+ 	command uint16_t Superframe.gtsTimeout(superframe_t *sf)
+ 	{
+ 		uint32_t beaconOrderExp = sf->beaconInterval;
+ 		beaconOrderExp /= aBaseSuperframeDuration;
+ 		if (beaconOrderExp >= 512) {
+ 			return 2;
+ 		} else {
+ 			return 512/beaconOrderExp;
+ 		}
+ 	}
+ 	
  	// Checks if a timeout (wait for frame or response) fits inside the current cap.
  	// Returns 0 if we just wait in the current cap or returns remaining time otherwise.

Index: IndirectTxM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/diku/evb13192/tos/lib/ieee802154/mac/IndirectTxM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** IndirectTxM.nc	23 Aug 2006 09:54:56 -0000	1.1
--- IndirectTxM.nc	16 Sep 2006 17:52:24 -0000	1.2
***************
*** 43,46 ****
--- 43,47 ----
  		interface CapTx as CoordinatorTx;
  		interface MacAddress;
+ 		interface CallbackService;
  		interface Debug;
  	}
***************
*** 51,56 ****
  	#include "Debug.h"
  
- 	Mcps_PurgeRequestConfirm purgePrimitive;
- 
  	indirectTxQueue_t myQueue[NUMINDIRECTSLOTS];
  	txDoneEntry_t doneQueue[NUMINDIRECTDONESLOTS];
--- 52,55 ----
***************
*** 61,66 ****
  	bool matchEntry(uint8_t entry, uint8_t *address);
  	uint8_t getAddresses(uint8_t mode, uint8_t *dest);
  	task void txDoneTask();
- 	task void confirmPurge();
  	
  	command result_t McpsRequestConfirmPurge.request(Mcps_PurgeRequestConfirm request)
--- 60,66 ----
  	bool matchEntry(uint8_t entry, uint8_t *address);
  	uint8_t getAddresses(uint8_t mode, uint8_t *dest);
+ 	void confirmPurge(uint8_t *primitive);
+ 	
  	task void txDoneTask();
  	
  	command result_t McpsRequestConfirmPurge.request(Mcps_PurgeRequestConfirm request)
***************
*** 68,72 ****
  		uint8_t i;
  		uint8_t myHandle = request->msg.request.msduHandle;
! 		// This is called once each superframe.
  		for (i=0;i<NUMINDIRECTSLOTS;i++) {
  			if (myQueue[i].status == SLOT_PENDING && myQueue[i].data->isData &&
--- 68,72 ----
  		uint8_t i;
  		uint8_t myHandle = request->msg.request.msduHandle;
! 		
  		for (i=0;i<NUMINDIRECTSLOTS;i++) {
  			if (myQueue[i].status == SLOT_PENDING && myQueue[i].data->isData &&
***************
*** 78,83 ****
  				myQueue[i].status = SLOT_EMPTY;
  				request->msg.confirm.status = IEEE802154_SUCCESS;
! 				purgePrimitive = request;
! 				post confirmPurge();
  				return SUCCESS;
  			}
--- 78,82 ----
  				myQueue[i].status = SLOT_EMPTY;
  				request->msg.confirm.status = IEEE802154_SUCCESS;
! 				call CallbackService.enqueue((uint8_t*)request, confirmPurge);
  				return SUCCESS;
  			}
***************
*** 240,246 ****
  	}
  	
! 	task void confirmPurge()
  	{
! 		signal McpsRequestConfirmPurge.confirm(purgePrimitive);
  	}
  	
--- 239,245 ----
  	}
  	
! 	void confirmPurge(uint8_t *primitive)
  	{
! 		signal McpsRequestConfirmPurge.confirm((Mcps_PurgeRequestConfirm)primitive);
  	}
  	

Index: MacConst.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/diku/evb13192/tos/lib/ieee802154/mac/MacConst.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** MacConst.h	23 Aug 2006 09:54:56 -0000	1.1
--- MacConst.h	16 Sep 2006 17:52:24 -0000	1.2
***************
*** 46,52 ****
  #define NUMINDIRECTDONESLOTS   2
  
- // Associate module
- #define ASSOCQUEUESIZE         4
- 
  // RxEnable module
  #define RXENABLEQUEUESIZE      3
--- 46,49 ----

Index: CfpControlM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/diku/evb13192/tos/lib/ieee802154/mac/CfpControlM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** CfpControlM.nc	23 Aug 2006 09:54:56 -0000	1.1
--- CfpControlM.nc	16 Sep 2006 17:52:24 -0000	1.2
***************
*** 35,38 ****
--- 35,39 ----
  		interface IeeeIndication<Mlme_GtsIndication> as MlmeIndicationGts;		
  		interface IeeeRequestConfirm<Mlme_GtsRequestConfirm> as MlmeRequestConfirmGts;
+ 		interface CfpTx;
  		interface BeaconGtsService;
  	}
***************
*** 40,44 ****
--- 41,56 ----
  	{
  		interface CapTx as DeviceTx;
+ 		interface CapEvents as CoordinatorCfp;
+ 		interface CapEvents as DeviceCfp;
+ 		interface RxFrame as GtsReqFrame;
+ 		interface FrameRx;
+ 		interface FrameTx;
+ 		interface AsyncAlarm<time_t> as CfpAlarm;
+ 		interface AsyncAlarm<time_t> as RxOffAlarm;
+ 		interface MacAddress;
+ 		interface LocalTime;
+ 		interface Superframe;
  		interface IeeeBufferManagement as BufferMng;
+ 		interface CallbackService;
  		interface Debug;
  	}
***************
*** 49,58 ****
  	#include "Debug.h"
  
  	// Only one GTS request can be processed at a time.
  	Mlme_GtsRequestConfirm gtsConfirm;
  
  	// First two descriptors are for device operation.
! 	// Descriptor 0 = device receive
! 	// Descriptor 1 = device transmit
  	// Descriptor 2-8 = coordinator GTS's
  	gtsDescriptor_t descriptorSlots[9];
--- 61,77 ----
  	#include "Debug.h"
  
+ 	// Global variables.	
+ 	#define COORDCFP    1
+ 	#define DEVICECFP   2
+ 	
+ 	#define TXDIRECTION 0
+ 	#define RXDIRECTION 1
+ 
  	// Only one GTS request can be processed at a time.
  	Mlme_GtsRequestConfirm gtsConfirm;
  
  	// First two descriptors are for device operation.
! 	// Descriptor 0 = device transmit
! 	// Descriptor 1 = device receive
  	// Descriptor 2-8 = coordinator GTS's
  	gtsDescriptor_t descriptorSlots[9];
***************
*** 63,66 ****
--- 82,89 ----
  	bool donePosted = FALSE;
  	txdata_t myTxData;
+ 	uint8_t pendingDataSlot;
+ 	uint8_t curCfp = DEVICECFP;
+ 	uint8_t nextActiveSlot;
+ 	bool cfpTimerArmed = FALSE;
  
  	// Timeout variables.
***************
*** 69,82 ****
  
  	task void txDoneTask();
  
! 	command void BeaconGtsService.gtsUpdate(uint8_t start, uint8_t length, bool deviceTxSlot)
  	{
! 		uint8_t mySlot = (deviceTxSlot?1:0);
! 		
  		if (start != 0) {
  			// If start != 0 this is either an allocation or reallocation.
  			// Just update the slot.
  			descriptorSlots[mySlot].startSlot = start;
  			descriptorSlots[mySlot].duration = length;
  			descriptorSlots[mySlot].valid = TRUE;
  			if (waitingForGtsUpdate) {
--- 92,109 ----
  
  	task void txDoneTask();
+ 	void tendDataSlots(uint8_t sfSlot);
+ 	void createGtsIndication(uint8_t slot);
+ 	void indicateGts(uint8_t *gtsIndication);
  
! 	command void BeaconGtsService.gtsUpdate(uint8_t start, uint8_t length, bool deviceRxSlot)
  	{
! 		uint8_t mySlot = (deviceRxSlot?RXDIRECTION:TXDIRECTION);
  		if (start != 0) {
  			// If start != 0 this is either an allocation or reallocation.
  			// Just update the slot.
+ 			descriptorSlots[mySlot].shortAddr = macShortAddress;
  			descriptorSlots[mySlot].startSlot = start;
  			descriptorSlots[mySlot].duration = length;
+ 			descriptorSlots[mySlot].direction = mySlot;
  			descriptorSlots[mySlot].valid = TRUE;
  			if (waitingForGtsUpdate) {
***************
*** 87,119 ****
  		} else {
  			// Else we have a failed allocation or a deallocation.
- 			// Just invalidate the entry.
- 			descriptorSlots[mySlot].valid = FALSE;
- 			// TODO: if deviceTxSlot, fail all entries in the data queue.
  			if (waitingForGtsUpdate) {
  				gtsConfirm->msg.confirm.status = IEEE802154_DENIED;
  				signal MlmeRequestConfirmGts.confirm(gtsConfirm);
  			} else {
! 				// TODO: signal GTS indication.
  			}
  		}
  	}
  
! 	command void GtsTx.sendFrame(txHeader_t *header, uint16_t shortAddr)
  	{
  		uint8_t myDescriptor;
  		bool descriptorFound = FALSE;
! 		if (shortAddr == macCoordShortAddress) {
  			// Check if we have a valid device GTS
! 			if (descriptorSlots[1].valid) {
  				// We have a valid descriptor.
! 				myDescriptor = 1;
  				descriptorFound = TRUE;
  			}
! 		} else if (macCoordinator) {
  			uint8_t i;
  			// Check if we have a valid coordinator GTS
  			for (i=2;i<9;i++) {
  				if (descriptorSlots[i].valid && descriptorSlots[i].shortAddr == shortAddr
! 				    && descriptorSlots[i].direction == 1) {
  					// We have a valid descriptor.
  					myDescriptor = i;
--- 114,238 ----
  		} else {
  			// Else we have a failed allocation or a deallocation.
  			if (waitingForGtsUpdate) {
  				gtsConfirm->msg.confirm.status = IEEE802154_DENIED;
  				signal MlmeRequestConfirmGts.confirm(gtsConfirm);
  			} else {
! 				if (descriptorSlots[mySlot].valid) {
! 					// Just invalidate the entry.
! 					descriptorSlots[mySlot].valid = FALSE;
! 					// Signal a gts indication.
! 					createGtsIndication(mySlot);
! 					// TODO: if deviceTxSlot, fail all entries in the data queue.
! 				}
  			}
  		}
  	}
  
! 	command void BeaconGtsService.beaconReceived()
! 	{
! 		// Check if we were waiting for a GTS update.
! 		if (waitingForGtsUpdate) {
! 			if (--waitCount == 0) {
! 				// Timeout!
! 				waitingForGtsUpdate = FALSE;
! 				gtsConfirm->msg.confirm.status = IEEE802154_NO_DATA;
! 				signal MlmeRequestConfirmGts.confirm(gtsConfirm);
! 			}
! 		}
! 	}
! 
! 	command void BeaconGtsService.getPublishedGts(uint8_t *descriptorCount, uint8_t *data)
! 	{
! 		uint8_t i;
! 		msduGTSList_t *gtsList = (msduGTSList_t*)(data + 1);
! 		uint8_t gtsDirections = 0;
! 		uint8_t gtsCount = 0;
! 		// Check if we have coordinator GTS's that should be published.
! 		for (i=2;i<9;i++) {
! 			// We check if the GTS has timed out!
! 			if (descriptorSlots[i].valid && !(descriptorSlots[i].timeout--)) {
! 				descriptorSlots[i].valid = FALSE;
! 				descriptorSlots[i].startSlot = 0;
! 				
! 				// CAP length is increased and GTS's are reorganised if necessary.
! 				coordinatorSuperframe.capLength += descriptorSlots[i].duration;
! 				// TODO: Reorganise gts's.
! 				descriptorSlots[i].beaconPublishCount = aGTSDescPersistenceTime;
! 				createGtsIndication(i);
! 			}
! 			if (descriptorSlots[i].beaconPublishCount) {
! 				// We have a valid descriptor to be published.
! 				// Remember that directions are "reversed" on coordinator side.
! 				gtsDirections += !(descriptorSlots[i].direction) << gtsCount;
! 				gtsList->DeviceShortAddress = descriptorSlots[i].shortAddr;
! 				gtsList->GTSStartingSlot = descriptorSlots[i].startSlot;
! 				gtsList->GTSLength = descriptorSlots[i].duration;
! 				// Decrement publish count.
! 				descriptorSlots[i].beaconPublishCount--;
! 				gtsList++;
! 				gtsCount++;
! 			}
! 		}
! 		if (gtsCount) {
! 			*(data) = gtsDirections;
! 		}
! 		*(descriptorCount) = gtsCount;
! 	}
! 
! 	command void CfpTx.dataReceived()
! 	{
! 		uint8_t curSlot, cfpStartSlot, i;
! 		
! 		if (curCfp == DEVICECFP) {
! 			// Devices does not keep track of slot timeouts.
! 			return;
! 		}
! 		
! 		curSlot = call Superframe.getCurrentSlot(&coordinatorSuperframe);
! 		cfpStartSlot = coordinatorSuperframe.capLength-1;
! 		
! 		if (curSlot < cfpStartSlot || curSlot > 0xF) {
! 			return;
! 		}
! 		
! 		// We have a data reception in cfp.
! 		for (i=2;i<9;i++) {
! 			if (descriptorSlots[i].valid && descriptorSlots[i].direction == RXDIRECTION
! 			    && descriptorSlots[i].startSlot <= curSlot
! 			    && (descriptorSlots[i].startSlot + descriptorSlots[i].duration - 1) >= curSlot) {
! 				// We have a winner :-)
! 				// Reset the descriptor timeout.
! 				descriptorSlots[i].timeout = call Superframe.gtsTimeout(&coordinatorSuperframe);
! 				break;
! 			}
! 		}
! 	}
! 
! 	/* Transmit a frame in CFP. */
! 	command void CfpTx.sendFrame(txHeader_t *header)
  	{
  		uint8_t myDescriptor;
  		bool descriptorFound = FALSE;
! 		ieeeAddress_t dstAddr;
! 		
! 		DBG_STR("Trying to enqueue data for GTS transmission",1);
! 		
! 		// Check destination address.
! 		call MacAddress.getDstAddr(header->frame, &dstAddr);
! 		if ((dstAddr.mode == 2 && *((uint16_t*)dstAddr.address) == macCoordShortAddress)
! 		    || (dstAddr.mode == 3 && int64Compare(dstAddr.address, macCoordExtendedAddress))) {
  			// Check if we have a valid device GTS
! 			if (descriptorSlots[TXDIRECTION].valid) {
  				// We have a valid descriptor.
! 				myDescriptor = TXDIRECTION;
  				descriptorFound = TRUE;
  			}
! 		} else if (macCoordinator && dstAddr.mode == 2) {
  			uint8_t i;
+ 			uint16_t shortAddr = *((uint16_t*)dstAddr.address);
  			// Check if we have a valid coordinator GTS
  			for (i=2;i<9;i++) {
  				if (descriptorSlots[i].valid && descriptorSlots[i].shortAddr == shortAddr
! 				    && descriptorSlots[i].direction == TXDIRECTION) {
  					// We have a valid descriptor.
  					myDescriptor = i;
***************
*** 122,128 ****
  				}
  			}
- 		} else {
- 			// Invalid request. No available GTS.
- 			header->status = IEEE802154_INVALID_GTS;
  		}
  		
--- 241,244 ----
***************
*** 135,138 ****
--- 251,257 ----
  					dataQueue[i].header = header;
  					dataQueue[i].gtsIndex = myDescriptor;
+ 					// TODO: Check if we can transmit the frame at once, by running
+ 					//       the tend command.
+ 					DBG_STRINT("Data enqueued for transmission in data slot:",i,1);
  					return;
  				}
***************
*** 140,143 ****
--- 259,267 ----
  			// If this point is reached, no queue space is left.
  			header->status = IEEE802154_TRANSACTION_OVERFLOW;
+ 			DBG_STR("Transaction overflow",1);
+ 		} else {
+ 			// Invalid request. No available GTS.
+ 			header->status = IEEE802154_INVALID_GTS;
+ 			DBG_STR("Invalid GTS request",1);
  		}
  		// If we get here, we need to report an error back.
***************
*** 145,148 ****
--- 269,273 ----
  		if (!donePosted) {
  			donePosted = post txDoneTask();
+ 			DBG_STR("Send failed :-(",1);
  		}
  	}
***************
*** 150,159 ****
  	event void CoordinatorCfp.startNotification()
  	{
! 	
  	}
  	
  	event void DeviceCfp.startNotification()
  	{
! 		
  	}
  	
--- 275,297 ----
  	event void CoordinatorCfp.startNotification()
  	{
! //		time_t temp = call LocalTime.getTime();
! //		time_t capEnd = call Superframe.getCapEnd(&coordinatorSuperframe);
! //		DBG_STRINT("CAP ends at:",capEnd,1);
! //		DBG_STRINT("CFP started at:",temp,1);
! 		uint8_t slot = call Superframe.getCurrentSlot(&coordinatorSuperframe);
! 		curCfp = COORDCFP;
! 		tendDataSlots(slot+1);
  	}
  	
  	event void DeviceCfp.startNotification()
  	{
! //		time_t temp = call LocalTime.getTime();
! //		time_t capEnd = call Superframe.getCapEnd(&deviceSuperframe);
! //		DBG_STRINT("CAP ends at:",capEnd,1);
! //		DBG_STRINT("CFP started at:",temp,1);
! 		uint8_t slot = call Superframe.getCurrentSlot(&deviceSuperframe);
! 		//DBG_STRINT("Current superframe slot is:",slot,1);
! 		curCfp = DEVICECFP;
! 		tendDataSlots(slot+1);
  	}
  	
***************
*** 164,168 ****
  		
  		// If no short address is assigned, we fail.
! 		if (macShortAddr == aBcastShortAddr || macShortAddr == aNoShortAddr) {
  			request->msg.confirm.status = IEEE802154_NO_SHORT_ADDRESS;
  			return FAIL;
--- 302,306 ----
  		
  		// If no short address is assigned, we fail.
! 		if (macShortAddress == aBcastShortAddr || macShortAddress == aNoShortAddr) {
  			request->msg.confirm.status = IEEE802154_NO_SHORT_ADDRESS;
  			return FAIL;
***************
*** 179,183 ****
  		// Build the txHeader.
  		myTxHeader->addDsn = TRUE;
! 		myTxHeader->frame = frame;
  		myTxHeader->length = 9;
  		myTxHeader->isData = FALSE;
--- 317,321 ----
  		// Build the txHeader.
  		myTxHeader->addDsn = TRUE;
! 		myTxHeader->frame = request->msg.request.GTSRequestFrame;
  		myTxHeader->length = 9;
  		myTxHeader->isData = FALSE;
***************
*** 200,223 ****
  		}
  		
! 		if (gtsConfirm->msg.confirm.status == IEEE802154_SUCCESS) {
  			waitingForGtsUpdate = TRUE;
  			waitCount = aGTSDescPersistenceTime;
  		} else {
! 			// An error was encountered while sending the GTS request.
! 			signal MlmeRequestConfirmGts.confirm(gtsConfirm);
! 		}
! 	}
! 	
! 	command void BeaconGtsService.beaconReceived()
! 	{
! 		// Check if we were waiting for a GTS update.
! 		if (waitingForGtsUpdate) {
! 			waitCount--;
! 			if (--waitCount == 0) {
! 				// Timeout!
! 				waitingForGtsUpdate = FALSE;
! 				gtsConfirm->msg.confirm.status = IEEE802154_NO_DATA;
! 				signal MlmeRequestConfirmGts.confirm(gtsConfirm);
  			}
  		}
  	}
--- 338,353 ----
  		}
  		
! 		if (gtsConfirm->msg.confirm.status == IEEE802154_SUCCESS && gtsConfirm->msg.confirm.gtsType) {
  			waitingForGtsUpdate = TRUE;
  			waitCount = aGTSDescPersistenceTime;
+ 			// TODO: Handle sync loss!
  		} else {
! 			// An error was encountered while sending the GTS request
! 			// or the request was a deallocation.
! 			if (gtsConfirm->msg.confirm.gtsType == 0) {
! 				// If deallocation, invalidate the descriptor slot.
! 				descriptorSlots[gtsConfirm->msg.confirm.gtsDirection].valid = FALSE;
  			}
+ 			signal MlmeRequestConfirmGts.confirm(gtsConfirm);
  		}
  	}
***************
*** 227,230 ****
--- 357,366 ----
  		msduGtsCharacteristics_t *myGtsChar = msduGtsRequestGtsCharacteristics(data->frame);
  		uint16_t deviceAddr = *((uint16_t*)mhrSrcAddr(data->frame));
+ 		bool indicateEvent = FALSE;
+ 		DBG_STR("Received GTS request frame",1);
+ 		if (!macGtsPermit) {
+ 			// We do not permit allocation of GTS slots. Just ignore the request.
+ 			return data->frame;
+ 		}
  		if (myGtsChar->CharType == 1) {
  			// Try to allocate GTS.
***************
*** 232,235 ****
--- 368,372 ----
  			bool descriptorFound = FALSE;
  			uint8_t i;
+ 			DBG_STR("Try to allocate GTS",1);
  			// Find an available descriptor slot.
  			for (i=2;i<9;i++) {
***************
*** 243,246 ****
--- 380,384 ----
  			if (!descriptorFound) {
  				// We have no free descriptors...
+ 				DBG_STR("No free descriptors..",1);
  				// TODO: Can we just ignore this and let the requesting device fail
  				//       with status NO_DATA?
***************
*** 250,260 ****
  			    < aMinCAPLength) {
  				// We can't allocate this GTS without making the CAP too small.
  				descriptorSlots[i].valid = FALSE;
  				descriptorSlots[i].startSlot = 0;
  				descriptorSlots[i].duration = aNumSuperframeSlots;
! 				descriptorSlots[i].direction = myGtsChar->GTSDirection;
  				descriptorSlots[i].shortAddr = deviceAddr;
  				descriptorSlots[i].beaconPublishCount = aGTSDescPersistenceTime;
  			} else {
  				// Update the coordinator superframe cap.
  				coordinatorSuperframe.capLength -= myGtsChar->GTSLength;
--- 388,401 ----
  			    < aMinCAPLength) {
  				// We can't allocate this GTS without making the CAP too small.
+ 				DBG_STR("GTS allocation makes CAP too small",1);
  				descriptorSlots[i].valid = FALSE;
  				descriptorSlots[i].startSlot = 0;
  				descriptorSlots[i].duration = aNumSuperframeSlots;
! 				// Remember that GTS directions are "reversed" on coordinator side.
! 				descriptorSlots[i].direction = !(myGtsChar->GTSDirection);
  				descriptorSlots[i].shortAddr = deviceAddr;
  				descriptorSlots[i].beaconPublishCount = aGTSDescPersistenceTime;
  			} else {
+ 				DBG_STR("We allocate the GTS",1);
  				// Update the coordinator superframe cap.
  				coordinatorSuperframe.capLength -= myGtsChar->GTSLength;
***************
*** 265,285 ****
  				descriptorSlots[i].startSlot = coordinatorSuperframe.capLength;
  				descriptorSlots[i].duration = myGtsChar->GTSLength;
! 				descriptorSlots[i].direction = myGtsChar->GTSDirection;
  				descriptorSlots[i].shortAddr = deviceAddr;
  				descriptorSlots[i].beaconPublishCount = aGTSDescPersistenceTime;
! 				// TODO: Notify upper layer
  			}
  		} else {
  			// Try to deallocate GTS.
  			uint8_t i;
  			// Find GTS to deallocate.
  			for (i=2;i<9;i++) {
  				if (descriptorSlots[i].valid && descriptorSlots[i].shortAddr == deviceAddr
! 				    && descriptorSlots[i].direction == myGtsChar->GTSDirection) {
  					// We have match. Invalidate descriptor.
  					descriptorSlots[i].valid = FALSE;
! 					// TODO: Notify upper layer
! 					// Publish in beacon.
! 					descriptorSlots[i].beaconPublishCount = aGTSDescPersistenceTime;
  					break;
  				}
--- 406,433 ----
  				descriptorSlots[i].startSlot = coordinatorSuperframe.capLength;
  				descriptorSlots[i].duration = myGtsChar->GTSLength;
! 				// Remember that GTS directions are "reversed" on coordinator side.
! 				descriptorSlots[i].direction = !(myGtsChar->GTSDirection);
  				descriptorSlots[i].shortAddr = deviceAddr;
  				descriptorSlots[i].beaconPublishCount = aGTSDescPersistenceTime;
! 				descriptorSlots[i].timeout = call Superframe.gtsTimeout(&coordinatorSuperframe);
! 				createGtsIndication(i);
  			}
  		} else {
  			// Try to deallocate GTS.
  			uint8_t i;
+ 			DBG_STR("Try to deallocate GTS",1);
  			// Find GTS to deallocate.
  			for (i=2;i<9;i++) {
  				if (descriptorSlots[i].valid && descriptorSlots[i].shortAddr == deviceAddr
! 				    && descriptorSlots[i].direction == !(myGtsChar->GTSDirection)) {
  					// We have match. Invalidate descriptor.
+ 					DBG_STR("Got a matching descriptor",1);
  					descriptorSlots[i].valid = FALSE;
! 					// CAP length is increased and GTS's are reorganised if necessary.
! 					coordinatorSuperframe.capLength += descriptorSlots[i].duration;
! 					// TODO: Reorganise gts's.
! 					// NOTE: Deallocation is not publish in the beacon.
! 					descriptorSlots[i].beaconPublishCount = 0;
! 					createGtsIndication(i);
  					break;
  				}
***************
*** 292,331 ****
  	{
  		while(doneQueueCount) {
! 			signal GtsTx.done(doneQueue[--doneQueueCount].header);
  		}
  		donePosted = FALSE;
  	}
! 	
! 	void tendDeviceSlots(uint8_t sfSlot)
  	{
! 		time_t slotStart = call Superframe.getSlotStartTime(&deviceSuperframe, sfSlot);
! 		// Device is easy
! 		if (descriptorSlots[0].valid && descriptorSlots[0].startSlot == sfSlot) {
! 			// Start the receiver at the slot boundary.
! 			if (PHY_SUCCESS != call FrameRx.rxOn(slotStart)) {
! 				DBG_STR("Warning: CfpControl, could not enable receiver!",1);
  			}
! 		} else if (descriptorSlots[1].valid &&
! 		           descriptorSlots[1].startSlot <= sfSlot &&
! 		           (descriptorSlots[1].startSlot + descriptorSlots[1].duration - 1) >= sfSlot) {
! 			// Check if we have something to send.
! 			uint8_t i;
! 			for (i=0; i<CFPTXQUEUESIZE;i++) {
! 				if (dataQueue[i].gtsIndex == 1 && dataQueue[i].status == TX_PENDING) {
! 					// We send the data if it fits in the current gts.
! 					myTxData.frame = dataQueue[i].header->frame;
! 					myTxData.length = dataQueue[i].header->length;
! 					myTxData.cca = FALSE;
! 					
! 					// Check time.
! 					if (slotStart < call LocalTime.getTime()) {
! 						myTxData.immediateCommence = TRUE;
! 					} else {
! 						myTxData.immediateCommence = FALSE;
! 						myTxData.commenceTime = slotStart;
  					}
  				}
  			}
  		}
  	}
  	
--- 440,639 ----
  	{
  		while(doneQueueCount) {
! 			signal CfpTx.done(doneQueue[--doneQueueCount].header);
  		}
  		donePosted = FALSE;
  	}
! 
! 	void tendDataSlots(uint8_t sfSlot)
  	{
! 		time_t slotStart;
! 		uint8_t i, myMin, myMax;
! 		superframe_t *mySuperframe;
! 		bool activeDescriptorFound = FALSE;
! 		
! 		if (sfSlot > 0xF) {
! 			return;
! 		}
! 		
! 		if (curCfp == DEVICECFP) {
! 			myMin = 0;
! 			myMax = 2;
! 			mySuperframe = &deviceSuperframe;
! 		} else {
! 			// Assume coordinator cfp.
! 			myMin = 2;
! 			myMax = 9;
! 			mySuperframe = &coordinatorSuperframe;
! 		}
! 		
! 		// We arm the timer for the next relevant GTS slot.
! 		if (!cfpTimerArmed) {
! 			uint8_t nextSlot = 0;
! 			nextActiveSlot = 0;
! 			// Find next active slot.
! 			for (i = myMin; i < myMax; i++) {
! 				if (descriptorSlots[i].valid && descriptorSlots[i].startSlot > sfSlot
! 				    && descriptorSlots[i].startSlot < nextSlot) {
! 					nextSlot = descriptorSlots[i].startSlot;
! 				}
  			}
! 			if (nextSlot) {
! 				// Arm the alarm to fire just before we reach the next active slot.
! 				time_t nextSlotStart = call Superframe.getSlotStartTime(mySuperframe, nextSlot);
! 				nextActiveSlot = nextSlot;
! 				call CfpAlarm.armAlarmClock(nextSlotStart-82);
! 				cfpTimerArmed = TRUE;
! 			}
! 		}
! 		
! 		slotStart = call Superframe.getSlotStartTime(mySuperframe, sfSlot);
! 		
! 		// Find GTS active in current superframe slot.
! 		for (i=myMin;i<myMax;i++) {
! 			if (descriptorSlots[i].valid) {
! 				if (descriptorSlots[i].direction == RXDIRECTION) {
! 					// We have a receive GTS.
! 					if (descriptorSlots[i].startSlot == sfSlot) {
! 						uint8_t endSlot = sfSlot + descriptorSlots[i].duration - 1;
! 						// Start the receiver at the slot boundary.
! 						if (PHY_SUCCESS != call FrameRx.rxOn(slotStart-12)) {
! 							DBG_STR("Warning: CfpControl, could not enable receiver!",1);
! 						}
! 						// Turn of receiver at the end of the GTS if not followed by an active slot.
! 						if (endSlot != nextActiveSlot-1 && endSlot < 0xF) {
! 							// Turn off receiver at end of GTS.
! 							time_t offTime = call Superframe.getSlotStartTime(mySuperframe, endSlot+1);
! 							call RxOffAlarm.armAlarmClock(offTime);
! 							DBG_STRINT("Need to turn off receiver in end of slot:",endSlot,1);
! 						}
! 						//DBG_STRINT("Found active rx slot in descriptor:",i,1);
! 						activeDescriptorFound = TRUE;
! 						break;
! 					}
! 				} else {
! 					// Must be a transmit GTS.
! 					if (descriptorSlots[i].startSlot <= sfSlot && (descriptorSlots[i].startSlot + descriptorSlots[i].duration - 1) >= sfSlot) {
! 						// Check if we have something to send.
! 						uint8_t j;
! 						//DBG_STR("Check if we have something to transmit",1);
! 						for (j=0;j<CFPTXQUEUESIZE;j++) {
! 							if (dataQueue[j].gtsIndex == i && dataQueue[j].status == SLOT_PENDING) {
! 								// We send the data if it fits in the current gts.
! 								// TODO: Check that tx fits in gts.
! 								
! 								// We have data. Reset timeout interval.
! 								descriptorSlots[i].timeout = call Superframe.gtsTimeout(mySuperframe);
! 								//DBG_STRINT("Valid data in queue index:",i,1);
! 								myTxData.frame = dataQueue[j].header->frame;
! 								myTxData.length = dataQueue[j].header->length;
! 								myTxData.cca = FALSE;
! 								
! 								// Check time.
! 								// TODO: Use isPast command in localtime.
! 								if (slotStart < call LocalTime.getTime()) {
! 									myTxData.immediateCommence = TRUE;
! 									//DBG_STR("Sending at once!",1);
! 								} else {
! 									myTxData.immediateCommence = FALSE;
! 									myTxData.commenceTime = slotStart;
! 									//DBG_STR("Sending in future!",1);
! 								}
! 								pendingDataSlot = j;
! 								call FrameTx.tx(&myTxData);
! 								activeDescriptorFound = TRUE;
! 								//DBG_STRINT("Sending data in data slot:",j,1);
! 								break;
! 							}
! 						}
! 						// Active slot found.. No need to search further.
! 						//DBG_STRINT("Found active tx slot in descriptor:",i,1);
! 						break;
  					}
  				}
  			}
  		}
+ 		if (!activeDescriptorFound) {
+ 			// Disable the transciever.
+ 			call FrameRx.trxOff(TRUE);
+ 		}
+ 	}
+ 	
+ 	async event void FrameTx.txDone(phy_error_t error)
+ 	{
+ 		DBG_STRINT("Send done with status",error,1);
+ 		if (error == PHY_SUCCESS) {
+ 			dataQueue[pendingDataSlot].header->status = TX_SUCCESS;
+ 			doneQueue[doneQueueCount++].header = dataQueue[pendingDataSlot].header;
+ 			dataQueue[pendingDataSlot].status = SLOT_EMPTY;
+ 		} else if (error == PHY_ACK_FAIL) {
+ 			if (dataQueue[pendingDataSlot].header->txRetries) {
+ 				// Retry transmission.
+ 				dataQueue[pendingDataSlot].header->txRetries--;
+ 				dataQueue[pendingDataSlot].status = SLOT_PENDING;
+ 				// TODO: Call tend operation once more.
+ 				return;
+ 			} else {
+ 				// Entry failed ack too many times.
+ 				dataQueue[pendingDataSlot].header->status = TX_NO_ACK;
+ 				doneQueue[doneQueueCount++].header = dataQueue[pendingDataSlot].header;
+ 				dataQueue[pendingDataSlot].status = SLOT_EMPTY;
+ 			}
+ 		}
+ 		
+ 		// Tend the pending enties in the done queue.
+ 		if (!donePosted) {
+ 			donePosted = post txDoneTask();
+ 		}
+ 		post txDoneTask();
+ 	}
+ 	
+ 	void createGtsIndication(uint8_t slot)
+ 	{
+ 		// Signal a gts indication.
+ 		mlmeGTSIndication_t *myGtsIndication;
+ 		msduGtsCharacteristics_t *myChars;
+ 		if (SUCCESS != call BufferMng.claim(sizeof(mlmeGTSIndication_t),(uint8_t**)(&myGtsIndication))){
+ 			DBG_STR("WARNING: CfpControl, Unable to claim buffer for gts indication!",1);
+ 			return;
+ 		}
+ 		myGtsIndication->msg.indication.address = descriptorSlots[slot].shortAddr;
+ 		myChars = (msduGtsCharacteristics_t*)&(myGtsIndication->msg.indication.gtsCharacteristics);
+ 		
+ 		if (slot < 2) {
+ 			myChars->GTSDirection = descriptorSlots[slot].direction;
+ 		} else {
+ 			// Directions are "reversed" on coordinator side.
+ 			myChars->GTSDirection = !(descriptorSlots[slot].direction);
+ 		}
+ 		if (descriptorSlots[slot].valid) {
+ 			myChars->GTSLength = descriptorSlots[slot].duration;
+ 			myChars->CharType = 1;
+ 		} else {
+ 			myChars->GTSLength = 0;
+ 			myChars->CharType = 0;
+ 		}
+ 		// Support security some day.
+ 		myGtsIndication->msg.indication.securityUse = FALSE;
+ 		myGtsIndication->msg.indication.ACLEntry = 0x08;
+ 		call CallbackService.enqueue((uint8_t*)myGtsIndication, indicateGts);
+ 	}
+ 	
+ 	async event result_t RxOffAlarm.alarm()
+ 	{
+ 		// Turn off the receiver.
+ 		call FrameRx.trxOff(TRUE);
+ 	}
+ 	
+ 	async event result_t CfpAlarm.alarm()
+ 	{
+ 		cfpTimerArmed = FALSE;
+ 		tendDataSlots(nextActiveSlot);
+ 		return SUCCESS;
+ 	}
+ 	
+ 	// Gts indication callback.
+ 	void indicateGts(uint8_t *gtsIndication)
+ 	{
+ 		signal MlmeIndicationGts.indication((Mlme_GtsIndication)gtsIndication);
  	}
  	
***************
*** 339,341 ****
  		DBG_STR("WARNING: Unhandled MlmeIndicationGts.indication",1);
  	}
! }
\ No newline at end of file
--- 647,649 ----
  		DBG_STR("WARNING: Unhandled MlmeIndicationGts.indication",1);
  	}
! }

Index: Ieee802154Adts.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/diku/evb13192/tos/lib/ieee802154/mac/Ieee802154Adts.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** Ieee802154Adts.h	23 Aug 2006 09:54:56 -0000	1.10
--- Ieee802154Adts.h	16 Sep 2006 17:52:24 -0000	1.11
***************
*** 210,217 ****
--- 210,221 ----
  
  typedef struct {
+ 	uint8_t gtsType;
+ 	uint8_t gtsDirection;
  	uint8_t *GTSRequestFrame;
  } mlmeGTSRequestMsg_t;
  
  typedef struct {
+ 	uint8_t gtsType;
+ 	uint8_t gtsDirection;
  	uint8_t *GTSRequestFrame;
  	Ieee_Status status;
***************
*** 219,223 ****
  
  typedef struct {
! 	uint8_t *GTSRequestFrame;
  	uint8_t ACLEntry;
  } mlmeGTSIndicationMsg_t;
--- 223,229 ----
  
  typedef struct {
! 	uint16_t address;
! 	uint8_t gtsCharacteristics;
! 	bool securityUse;
  	uint8_t ACLEntry;
  } mlmeGTSIndicationMsg_t;

Index: StartM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/diku/evb13192/tos/lib/ieee802154/mac/StartM.nc,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** StartM.nc	23 Aug 2006 09:54:56 -0000	1.6
--- StartM.nc	16 Sep 2006 17:52:24 -0000	1.7
***************
*** 42,45 ****
--- 42,46 ----
  		interface BeaconGenerator;
  		interface PhyAttributes;
+ 		interface CallbackService;
  		interface Debug;
  	}
***************
*** 49,56 ****
  	#define DBG_LEVEL 1
  	#include "Debug.h"
- 	
- 	Mlme_StartRequestConfirm startPrimitive;
  
! 	task void startConfirm();
  	
  	command result_t MlmeRequestConfirmStart.request(Mlme_StartRequestConfirm request)
--- 50,55 ----
  	#define DBG_LEVEL 1
  	#include "Debug.h"
  
! 	void confirmStart(uint8_t *primitive);
  	
  	command result_t MlmeRequestConfirmStart.request(Mlme_StartRequestConfirm request)
***************
*** 59,64 ****
  		mlmeStartConfirmMsg_t *conf = &(request->msg.confirm);
  		
- 		startPrimitive = request;
- 		
  		// If any parameters in primitive are not supported or out of range,
  		// signal confirm with status INVALID_PARAMETER.
--- 58,61 ----
***************
*** 148,152 ****
  		// We are done, confirm the request.
  		conf->status = IEEE802154_SUCCESS;
! 		post startConfirm();
  
  		DBG_STR("MlmeRequestConfirmStart.request",1);
--- 145,149 ----
  		// We are done, confirm the request.
  		conf->status = IEEE802154_SUCCESS;
! 		call CallbackService.enqueue((uint8_t*)request, confirmStart);
  
  		DBG_STR("MlmeRequestConfirmStart.request",1);
***************
*** 161,167 ****
  	}
  
! 	task void startConfirm()
  	{
! 		signal MlmeRequestConfirmStart.confirm(startPrimitive);
  	}
  
--- 158,164 ----
  	}
  
! 	void confirmStart(uint8_t *primitive)
  	{
! 		signal MlmeRequestConfirmStart.confirm((Mlme_StartRequestConfirm)primitive);
  	}
  

Index: AssociateM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/diku/evb13192/tos/lib/ieee802154/mac/AssociateM.nc,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** AssociateM.nc	23 Aug 2006 09:54:56 -0000	1.8
--- AssociateM.nc	16 Sep 2006 17:52:24 -0000	1.9
***************
*** 56,59 ****
--- 56,60 ----
  		interface MacAddress;
  		
+ 		interface CallbackService;
  		interface IeeeBufferManagement as BufferMng;
  		
***************
*** 72,91 ****
  	Mlme_AssociateRequestConfirm assocPrimitive;
  	
- 	// confirm/indication queue.
- 	uint8_t *confirmIndicationQueue[ASSOCQUEUESIZE];
- 	uint8_t queueHead = 0;
- 	uint8_t queueLength = 0;
- 	
  	bool waitAssocResponse = FALSE;
  	bool waitingToPoll = FALSE;
  	
! 	bool isPosted = FALSE;
! 	
! 	task void confirmAssociation();
! 	task void confirmIndicationTask();
! 
  	void confirmDisassoc(txHeader_t *header);
- 	void enqueuePrimitive(uint8_t *primitive);
- 	uint8_t *dequeuePrimitive();
  	
  	command void Reset.reset()
--- 73,82 ----
  	Mlme_AssociateRequestConfirm assocPrimitive;
  	
  	bool waitAssocResponse = FALSE;
  	bool waitingToPoll = FALSE;
  	
! 	void confirmAssociation(uint8_t *primitive);
! 	void indicateDisassoc(uint8_t *primitive);
  	void confirmDisassoc(txHeader_t *header);
  	
  	command void Reset.reset()
***************
*** 225,229 ****
  			} else {
  				assocPrimitive->msg.confirm.status = header->status;
! 				post confirmAssociation();
  			}
  		} else if (operation == macCommandDisassocNot) {
--- 216,220 ----
  			} else {
  				assocPrimitive->msg.confirm.status = header->status;
! 				call CallbackService.enqueue((uint8_t*)assocPrimitive, confirmAssociation);
  			}
  		} else if (operation == macCommandDisassocNot) {
***************
*** 268,272 ****
  			if (SUCCESS != call PollService.pollCoordinator(FALSE)) {
  				assocPrimitive->msg.confirm.status = IEEE802154_CHANNEL_ACCESS_FAILURE;
! 				post confirmAssociation();
  			}
  		}
--- 259,263 ----
  			if (SUCCESS != call PollService.pollCoordinator(FALSE)) {
  				assocPrimitive->msg.confirm.status = IEEE802154_CHANNEL_ACCESS_FAILURE;
! 				call CallbackService.enqueue((uint8_t*)assocPrimitive, confirmAssociation);
  			}
  		}
***************
*** 280,284 ****
  			waitAssocResponse = FALSE;
  			assocPrimitive->msg.confirm.status = status;
! 			post confirmAssociation();
  		}
  	}
--- 271,275 ----
  			waitAssocResponse = FALSE;
  			assocPrimitive->msg.confirm.status = status;
! 			call CallbackService.enqueue((uint8_t*)assocPrimitive, confirmAssociation);
  		}
  	}
***************
*** 306,310 ****
  			assocPrimitive->msg.confirm.assocShortAddr = shortAddr;
  			assocPrimitive->msg.confirm.status = status;
! 			post confirmAssociation();
  		}
  		return data->frame;
--- 297,301 ----
  			assocPrimitive->msg.confirm.assocShortAddr = shortAddr;
  			assocPrimitive->msg.confirm.status = status;
! 			call CallbackService.enqueue((uint8_t*)assocPrimitive, confirmAssociation);
  		}
  		return data->frame;
***************
*** 322,325 ****
--- 313,317 ----
  
  		assocIndication->msg.indication.assocIndicationFrame = data->frame;
+ 		// This is time critical and therefore signalled in async
  		signal MlmeIndicationResponseAssociate.indication(assocIndication);
  		
***************
*** 328,332 ****
  			DBG_STR("FATAL: Associate, could not claim memory for new receive buffer",1);
  		}
! 		
  		return newBuffer;
  	}
--- 320,324 ----
  			DBG_STR("FATAL: Associate, could not claim memory for new receive buffer",1);
  		}
! 
  		return newBuffer;
  	}
***************
*** 343,347 ****
  		disassocIndication->type = MLME_Disassociate_Indication;
  		disassocIndication->msg.indication.disassocNotificationFrame = data->frame;
! 		enqueuePrimitive((uint8_t*)disassocIndication);
  		
  		if (SUCCESS != call BufferMng.claim(126, &newBuffer)) {
--- 335,339 ----
  		disassocIndication->type = MLME_Disassociate_Indication;
  		disassocIndication->msg.indication.disassocNotificationFrame = data->frame;
! 		call CallbackService.enqueue((uint8_t*)disassocIndication, indicateDisassoc);
  		
  		if (SUCCESS != call BufferMng.claim(126, &newBuffer)) {
***************
*** 353,373 ****
  
  
! 	task void confirmAssociation()
  	{
! 		signal MlmeRequestConfirmAssociate.confirm(assocPrimitive);
  	}
  	
! 	task void confirmIndicationTask()
  	{
! 		uint8_t *primitive;
! 		uint8_t type;
! 		while (queueLength) {
! 			primitive = dequeuePrimitive();
! 			type = *(primitive);
! 			if (type == MLME_Disassociate_Indication) {
! 				signal MlmeIndicationDisassociate.indication((mlmeDisassociateIndication_t*)primitive);
! 			}
! 		}
! 		atomic isPosted = FALSE;
  	}
  
--- 345,356 ----
  
  
! 	void confirmAssociation(uint8_t *primitive)
  	{
! 		signal MlmeRequestConfirmAssociate.confirm((Mlme_AssociateRequestConfirm)primitive);
  	}
  	
! 	void indicateDisassoc(uint8_t *primitive)
  	{
! 		signal MlmeIndicationDisassociate.indication((mlmeDisassociateIndication_t*)primitive);
  	}
  
***************
*** 386,411 ****
  		signal MlmeRequestConfirmDisassociate.confirm(disassocConfirm);
  	}
- 	
- 	void enqueuePrimitive(uint8_t *primitive)
- 	{
- 		bool wasPosted = FALSE;
- 		confirmIndicationQueue[(queueHead+queueLength)%ASSOCQUEUESIZE] = primitive;
- 		queueLength++;
- 		atomic {
- 			wasPosted = isPosted;
- 			isPosted = TRUE;
- 		}
- 		if (!wasPosted) {
- 			post confirmIndicationTask();
- 		}
- 	}
- 	
- 	uint8_t *dequeuePrimitive()
- 	{
- 		uint8_t *res = confirmIndicationQueue[queueHead];
- 		queueLength--;
- 		queueHead = (queueHead + 1)%ASSOCQUEUESIZE;
- 		return res;
- 	}
  
  	default async event void MlmeIndicationResponseAssociate.indication(Mlme_AssociateIndicationResponse indication)
--- 369,372 ----

Index: BeaconGeneratorM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/diku/evb13192/tos/lib/ieee802154/mac/BeaconGeneratorM.nc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** BeaconGeneratorM.nc	23 Aug 2006 09:54:56 -0000	1.1
--- BeaconGeneratorM.nc	16 Sep 2006 17:52:24 -0000	1.2
***************
*** 40,43 ****
--- 40,44 ----
  		interface BeaconGenerator;
  		interface CapEvents as CoordinatorCap;
+ 		interface CapEvents as CoordinatorCfp;
  		//interface Reset;
  	}
***************
*** 50,53 ****
--- 51,55 ----
  		interface AsyncAlarm<time_t> as CfpAlarm;
  		interface BeaconDataService;
+ 		interface BeaconGtsService;
  		interface FrameTx;
  		interface LocalTime;
***************
*** 83,86 ****
--- 85,89 ----
  		if (macPanCoordinator) {
  			firstBeacon = TRUE;
+ 			coordinatorSuperframe.capLength = 16;
  			generateBeacon();
  			transmitBeacon();
***************
*** 131,134 ****
--- 134,138 ----
  		// Here we generate a beacon msg.
  		msduGTSSpec_t *gtsSpec;
+ 		uint8_t descriptorCount;
  		msduPendingAddrSpec_t *pendingSpec;
  		uint8_t numShortAddrs;
***************
*** 150,168 ****
  		mhrSeqNumber(myBeacon) = macBsn;
  		macBsn++;
  		// Fill in superframe spec.
! 		msduLength = 2;
  		sfSpec = msduGetSuperframeSpec(myBeacon);
  		sfSpec->BeaconOrder = macBeaconOrder;
  		sfSpec->SuperframeOrder = macSuperframeOrder;
! 		sfSpec->FinalCAPSlot = 15;
  		sfSpec->BatteryLifeExtension = macBattLifeExt;
  		sfSpec->PANCoordinator = macPanCoordinator;
  		sfSpec->AssociationPermit = macAssociationPermit;
! 		// Fill GTS spec.
! 		// TODO: Fill in the right GTS count, direction mask and GTS list.
! 		gtsSpec = msduGetGTSSpec(myBeacon);
! 		gtsSpec->GTSDescriptorCount = 0;
! 		gtsSpec->GTSPermit = macGtsPermit;
! 		msduLength += 1;
  		// Fill pending addresses.
  		pendingSpec = msduPendingAddrSpec(myBeacon);
--- 154,184 ----
  		mhrSeqNumber(myBeacon) = macBsn;
  		macBsn++;
+ 		
+ 		// Create the beacon msdu content.
+ 		msduLength = 0;
+ 		
+ 		// Fill GTS spec.
+ 		// NOTE: GTS specs needs to be set first, because the GTS publishing can
+ 		//       alter the capLength;
+ 		gtsSpec = msduGetGTSSpec(myBeacon);
+ 		call BeaconGtsService.getPublishedGts(&descriptorCount, (uint8_t*)(gtsSpec+1));
+ 		gtsSpec->GTSDescriptorCount = descriptorCount;
+ 		gtsSpec->GTSPermit = macGtsPermit;
+ 		if (descriptorCount) {
+ 			msduLength += 2 + descriptorCount*3;
+ 		} else {
+ 			msduLength += 1;
+ 		}
+ 		
  		// Fill in superframe spec.
! 		msduLength += 2;
  		sfSpec = msduGetSuperframeSpec(myBeacon);
  		sfSpec->BeaconOrder = macBeaconOrder;
  		sfSpec->SuperframeOrder = macSuperframeOrder;
! 		sfSpec->FinalCAPSlot = coordinatorSuperframe.capLength - 1;
  		sfSpec->BatteryLifeExtension = macBattLifeExt;
  		sfSpec->PANCoordinator = macPanCoordinator;
  		sfSpec->AssociationPermit = macAssociationPermit;
! 		
  		// Fill pending addresses.
  		pendingSpec = msduPendingAddrSpec(myBeacon);
***************
*** 173,176 ****
--- 189,193 ----
  		pendingSpec->NumExtAddrsPending = numExtAddrs;
  		msduLength += 1 + 2*numShortAddrs + 8*numExtAddrs;
+ 		
  		// TODO: Append beacon payload.
  	}
***************
*** 247,251 ****
  			if (call Superframe.cfpExists(&coordinatorSuperframe)) {
  				// We start up the device CFP.
! 				//signal CoordinatorCfp.startNotification();
  				cfpEnd = call Superframe.getCfpEnd(&coordinatorSuperframe);
  				if (cfpEnd < nextCommence) {
--- 264,268 ----
  			if (call Superframe.cfpExists(&coordinatorSuperframe)) {
  				// We start up the device CFP.
! 				signal CoordinatorCfp.startNotification();
  				cfpEnd = call Superframe.getCfpEnd(&coordinatorSuperframe);
  				if (cfpEnd < nextCommence) {

Index: CapControlM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/diku/evb13192/tos/lib/ieee802154/mac/CapControlM.nc,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** CapControlM.nc	23 Aug 2006 09:54:56 -0000	1.7
--- CapControlM.nc	16 Sep 2006 17:52:24 -0000	1.8
***************
*** 183,186 ****
--- 183,187 ----
  		    pendingEntry->header->txRetries) {
  			DBG_STR("No ack was received!",1);
+ 			DBG_STRINT("Retries left: ",pendingEntry->header->txRetries,1);
  			// No ack was received. We just retry the frame.
  			pendingEntry->status = SLOT_PENDING;

Index: GetSetM.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/diku/evb13192/tos/lib/ieee802154/mac/GetSetM.nc,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** GetSetM.nc	23 Aug 2006 09:54:56 -0000	1.4
--- GetSetM.nc	16 Sep 2006 17:52:24 -0000	1.5
***************
*** 43,46 ****
--- 43,47 ----
  		interface PhyReset;
  		interface FrameRx;
+ 		interface CallbackService;
  		interface Debug;
  	}
***************
*** 51,70 ****
  	#include "Debug.h"
  
! 	Mlme_SetRequestConfirm setPrimitive;
! 	Mlme_GetRequestConfirm getPrimitive;
! 	Mlme_ResetRequestConfirm resetPrimitive;
! 
! 	task void getConfirm();
! 	task void setConfirm();
! 	task void resetConfirm();
  
  	command Mlme_SetRequestConfirm MlmeRequestConfirmSet.request(Mlme_SetRequestConfirm request)
  	{
  		request->msg.confirm.status = call PibDatabase.set(request->msg.request.pibAttribute->value, request->msg.request.pibAttribute->attribute);
! 		setPrimitive = request;
! 		post setConfirm();
! 
! 		DBG_STR("MlmeRequestConfirmSet.request",1);
! 		return setPrimitive;
  	}
  
--- 52,64 ----
  	#include "Debug.h"
  
! 	void confirmSet(uint8_t *setPrimitive);
! 	void confirmGet(uint8_t *getPrimitive);
! 	void confirmReset(uint8_t *resetPrimitive);
  
  	command Mlme_SetRequestConfirm MlmeRequestConfirmSet.request(Mlme_SetRequestConfirm request)
  	{
  		request->msg.confirm.status = call PibDatabase.set(request->msg.request.pibAttribute->value, request->msg.request.pibAttribute->attribute);
! 		call CallbackService.enqueue((uint8_t*)request, confirmSet);
! 		return request;
  	}
  
***************
*** 72,80 ****
  	{
  		request->msg.confirm.status = call PibDatabase.get(request->msg.confirm.pibAttribute->value, request->msg.request.pibAttribute->attribute);
! 		getPrimitive = request;
! 		post getConfirm();
! 		
! 		DBG_STR("MlmeRequestConfirmGet.request",1);
! 		return getPrimitive;
  	}
  	
--- 66,71 ----
  	{
  		request->msg.confirm.status = call PibDatabase.get(request->msg.confirm.pibAttribute->value, request->msg.request.pibAttribute->attribute);
! 		call CallbackService.enqueue((uint8_t*)request, confirmGet);
! 		return request;
  	}
  	
***************
*** 86,90 ****
  			return FAIL;
  		}
! 		resetPrimitive = request;
  		call PhyReset.reset();
  		call Reset.reset();
--- 77,81 ----
  			return FAIL;
  		}
! 
  		call PhyReset.reset();
  		call Reset.reset();
***************
*** 93,113 ****
  		}
  		request->msg.confirm.status = IEEE802154_SUCCESS;
! 		post resetConfirm();
  		return SUCCESS;
  	}
  	
! 	task void getConfirm()
  	{
! 		signal MlmeRequestConfirmGet.confirm(getPrimitive);
  	}
  	
! 	task void setConfirm()
  	{
! 		signal MlmeRequestConfirmSet.confirm(setPrimitive);
  	}
  	
! 	task void resetConfirm()
  	{
! 		signal MlmeRequestConfirmReset.confirm(resetPrimitive);
  	}
  	
--- 84,104 ----
  		}
  		request->msg.confirm.status = IEEE802154_SUCCESS;
! 		call CallbackService.enqueue((uint8_t*)request, confirmReset);
  		return SUCCESS;
  	}
  	
! 	void confirmGet(uint8_t *getPrimitive)
  	{
! 		signal MlmeRequestConfirmGet.confirm((Mlme_GetRequestConfirm)getPrimitive);
  	}
  	
! 	void confirmSet(uint8_t *setPrimitive)
  	{
! 		signal MlmeRequestConfirmSet.confirm((Mlme_SetRequestConfirm)setPrimitive);
  	}
  	
! 	void confirmReset(uint8_t *resetPrimitive)
  	{
! 		signal MlmeRequestConfirmReset.confirm((Mlme_ResetRequestConfirm)resetPrimitive);
  	}
  	

--- MacStateControlM.nc DELETED ---



More information about the Tinyos-contrib-commits mailing list