⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 p802_15_4mac.cc

📁 802.15.4 mac 协议源程序
💻 CC
📖 第 1 页 / 共 5 页
字号:
	macBeaconOrder3 = 15;	macSuperframeOrder3 = def_macBeaconOrder;	if (mpib.macBeaconOrder == 15)		//non-beacon mode		mpib.macRxOnWhenIdle = true;	//default is false, but should be true in non-beacon mode	numLostBeacons = 0;	phy = NULL;	txOverT = new macTxOverTimer(this);	assert(txOverT);	txT = new macTxTimer(this);	assert(txT);	extractT = new macExtractTimer(this);	assert(extractT);	assoRspWaitT = new macAssoRspWaitTimer(this);	assert(assoRspWaitT);	dataWaitT = new macDataWaitTimer(this);	assert(dataWaitT);	rxEnableT = new macRxEnableTimer(this);	assert(rxEnableT);	scanT = new macScanTimer(this);	assert(scanT);	bcnTxT = new macBeaconTxTimer(this);	assert(bcnTxT);	bcnRxT = new macBeaconRxTimer(this);	assert(bcnRxT);	bcnSearchT = new macBeaconSearchTimer(this);	assert(bcnSearchT);	sscs = new SSCS802_15_4(this);	assert(sscs);	nam = new Nam802_15_4((isPANCoor)?Nam802_15_4::def_PANCoor_clr:"black","black",this);	assert(nam);	chkAddMacLink(index_,this);	init();}Mac802_15_4::~Mac802_15_4(){	/*for some reason,this function sometimes is called with <index_> beyond the scope (ns2 bug?)	delete txOverT;	delete txT;	delete extractT;	delete assoRspWaitT;	delete dataWaitT;	delete rxEnableT;	delete scanT;	delete bcnTxT;	delete bcnRxT;	delete bcnSearchT;	delete csmaca;	delete sscs;	delete nam;	*/}void Mac802_15_4::init(bool reset){	secuBeacon = false;	beaconWaiting = false;	txBeacon = 0;	txAck = 0;	txBcnCmd = 0;	txBcnCmd2 = 0;	txData = 0;	rxData = 0;	rxCmd = 0;	if (reset)	{		emptyHListLink(&hlistBLink1,&hlistBLink2);		emptyHListLink(&hlistDLink1,&hlistDLink2);		emptyDeviceLink(&deviceLink1,&deviceLink2);		emptyTransacLink(&transacLink1,&transacLink2);	}	else	{		hlistBLink1 = NULL;		hlistBLink2 = NULL;		hlistDLink1 = NULL;		hlistDLink2 = NULL;		deviceLink1 = NULL;		deviceLink2 = NULL;		transacLink1 = NULL;		transacLink2 = NULL;	}	taskP.init();}void Mac802_15_4::PD_DATA_confirm(PHYenum status){	inTransmission = false;	if (txOverT->busy())		txOverT->stop();	if (backoffStatus == 1)		backoffStatus = 0;			if (status == p_SUCCESS)	{		dispatch(status,__FUNCTION__);	}	else if (txPkt == txBeacon)	{		beaconWaiting = false;		Packet::free(txBeacon);		txBeacon = 0;	}	else if (txPkt == txAck)			{		Packet::free(txAck);		txAck = 0;	}	else	//RX_ON/TRX_OFF -- possible if the transmisstion is terminated by a FORCE_TRX_OFF or change of channel, or due to energy depletion	{}	//nothing to do -- it is the process that terminated the transmisstion to provide a way to resume the transmission}void Mac802_15_4::PLME_CCA_confirm(PHYenum status){	if (taskP.taskStatus(TP_CCA_csmaca))	{		taskP.taskStatus(TP_CCA_csmaca) = false;		csmaca->CCA_confirm(status);	}}void Mac802_15_4::PLME_ED_confirm(PHYenum status,UINT_8 EnergyLevel){	energyLevel = EnergyLevel;	dispatch(status,__FUNCTION__);}void Mac802_15_4::PLME_GET_confirm(PHYenum status,PPIBAenum PIBAttribute,PHY_PIB *PIBAttributeValue){	if (status == p_SUCCESS)	switch(PIBAttribute)	{		case phyCurrentChannel:			tmp_ppib.phyCurrentChannel = PIBAttributeValue->phyCurrentChannel;			break;		case phyChannelsSupported:			tmp_ppib.phyChannelsSupported = PIBAttributeValue->phyChannelsSupported;			break;		case phyTransmitPower:			tmp_ppib.phyTransmitPower = PIBAttributeValue->phyTransmitPower;			break;		case phyCCAMode:			tmp_ppib.phyCCAMode = PIBAttributeValue->phyCCAMode;			break;		default:			break;	}}void Mac802_15_4::PLME_SET_TRX_STATE_confirm(PHYenum status){	hdr_lrwpan *wph;	FrameCtrl frmCtrl;	double delay;	if (status == p_SUCCESS) status = trx_state_req;	if (backoffStatus == 99)	{		if (trx_state_req == p_RX_ON)		{			if (taskP.taskStatus(TP_RX_ON_csmaca))			{				taskP.taskStatus(TP_RX_ON_csmaca) = false;				csmaca->RX_ON_confirm(status);			}		}	}	else		dispatch(status,__FUNCTION__,trx_state_req);	if (status != p_TX_ON) return;	//transmit the packet	if (beaconWaiting)	{		/* to synchronize better, we don't transmit the beacon here#ifdef DEBUG802_15_4		fprintf(stdout,"[%s::%s][%f](node %d) transmit BEACON to %d: SN = %d, uid = %d, mac_uid = %ld\n",__FILE__,__FUNCTION__,CURRENT_TIME,index_,p802_15_4macDA(txBeacon),HDR_LRWPAN(txBeacon)->MHR_BDSN,HDR_CMN(txBeacon)->uid(),HDR_LRWPAN(txBeacon)->uid);#endif		if (!taskP.taskStatus(TP_mlme_start_request))	//not first beacon			assert((!txAck)&&(!txCsmaca));		//all tasks should be done before next beacon		txPkt = txBeacon;		HDR_CMN(txBeacon)->direction() = hdr_cmn::DOWN;		sendDown(txBeacon->refcopy(),this);		*/	}	else if (txAck)	{		//although no CSMA-CA required for the transmission of ack., 		//but we still need to locate the backoff period boundary if beacon enabled		//(refer to page 157, line 25-31)		if ((mpib.macBeaconOrder == 15)&&(macBeaconOrder2 == 15))	//non-beacon enabled			delay = 0.0;		else								//beacon enabled			delay  = locateBoundary((p802_15_4macDA(txAck) == mpib.macCoordShortAddress),0.0);		if (delay == 0.0)			backoffBoundHandler();		else			Scheduler::instance().schedule(&backoffBoundH, &(backoffBoundH.nullEvent), delay);	}	else		transmitCmdData();}void Mac802_15_4::PLME_SET_confirm(PHYenum status,PPIBAenum PIBAttribute){	if ((PIBAttribute == phyCurrentChannel)&&(status == p_SUCCESS))		dispatch(status,__FUNCTION__);}void Mac802_15_4::MCPS_DATA_request(UINT_8 SrcAddrMode,UINT_16 SrcPANId,IE3ADDR SrcAddr,				    UINT_8 DstAddrMode,UINT_16 DstPANId,IE3ADDR DstAddr,				    UINT_8 msduLength,Packet *msdu,UINT_8 msduHandle,UINT_8 TxOptions){	mcps_data_request(SrcAddrMode,SrcPANId,SrcAddr,DstAddrMode,DstPANId,DstAddr,msduLength,msdu,msduHandle,TxOptions,true);}void Mac802_15_4::MCPS_DATA_indication(UINT_8 SrcAddrMode,UINT_16 SrcPANId,IE3ADDR SrcAddr,				       UINT_8 DstAddrMode,UINT_16 DstPANId,IE3ADDR DstAddr,				       UINT_8 msduLength,Packet *msdu,UINT_8 mpduLinkQuality,				       bool SecurityUse,UINT_8 ACLEntry){	HDR_CMN(msdu)->num_forwards() += 1;	if (HDR_LRWPAN(msdu)->msduHandle != 0)	//from peer SSCS	{		log(msdu->refcopy());		sscs->MCPS_DATA_indication(SrcAddrMode,SrcPANId,SrcAddr,DstAddrMode,DstPANId,DstAddr,msduLength,msdu,mpduLinkQuality,SecurityUse,ACLEntry);	}	else		uptarget_->recv(msdu,(Handler*) 0);}void Mac802_15_4::MCPS_PURGE_request(UINT_8 msduHandle){		int i;	MACenum t_status;	i = updateTransacLinkByPktOrHandle(tr_oper_del,&transacLink1,&transacLink2,NULL,msduHandle);	t_status = (i == 0)?m_SUCCESS:m_INVALID_HANDLE;	sscs->MCPS_PURGE_confirm(msduHandle,t_status);}void Mac802_15_4::MLME_ASSOCIATE_request(UINT_8 LogicalChannel,UINT_8 CoordAddrMode,UINT_16 CoordPANId,IE3ADDR CoordAddress,					 UINT_8 CapabilityInformation,bool SecurityEnable){	mlme_associate_request(LogicalChannel,CoordAddrMode,CoordPANId,CoordAddress,CapabilityInformation,SecurityEnable,true);}void Mac802_15_4::MLME_ASSOCIATE_response(IE3ADDR DeviceAddress,UINT_16 AssocShortAddress,MACenum status,bool SecurityEnable){	mlme_associate_response(DeviceAddress,AssocShortAddress,status,SecurityEnable,true);}void Mac802_15_4::MLME_DISASSOCIATE_request(IE3ADDR DeviceAddress,UINT_8 DisassociateReason,bool SecurityEnable){	mlme_disassociate_request(DeviceAddress,DisassociateReason,SecurityEnable,true);}void Mac802_15_4::MLME_DISASSOCIATE_indication(IE3ADDR DeviceAddress,UINT_8 DisassociateReason,bool SecurityUse,UINT_8 ACLEntry){}void Mac802_15_4::MLME_GET_request(MPIBAenum PIBAttribute){	MACenum t_status;		switch(PIBAttribute)	{		case macAckWaitDuration:		case macAssociationPermit:		case macAutoRequest:		case macBattLifeExt:		case macBattLifeExtPeriods:		case macBeaconPayload:		case macBeaconPayloadLength:		case macBeaconOrder:				case macBeaconTxTime:		case macBSN:		case macCoordExtendedAddress:		case macCoordShortAddress:		case macDSN:		case macGTSPermit:		case macMaxCSMABackoffs:		case macMinBE:		case macPANId:		case macPromiscuousMode:		case macRxOnWhenIdle:		case macShortAddress:		case macSuperframeOrder:		case macTransactionPersistenceTime:		case macACLEntryDescriptorSet:		case macACLEntryDescriptorSetSize:		case macDefaultSecurity:		case macACLDefaultSecurityMaterialLength:		case macDefaultSecurityMaterial:		case macDefaultSecuritySuite:		case macSecurityMode:			t_status = m_SUCCESS;			break;		default:			t_status = m_UNSUPPORTED_ATTRIBUTE;			break;	}	sscs->MLME_GET_confirm(t_status,PIBAttribute,&mpib);}void Mac802_15_4::MLME_GTS_request(UINT_8 GTSCharacteristics,bool SecurityEnable){}void Mac802_15_4::MLME_GTS_confirm(UINT_8 GTSCharacteristics,MACenum status){}void Mac802_15_4::MLME_GTS_indication(UINT_16 DevAddress,UINT_8 GTSCharacteristics,				      bool SecurityUse, UINT_8 ACLEntry){}void Mac802_15_4::MLME_ORPHAN_response(IE3ADDR OrphanAddress,UINT_16 ShortAddress,bool AssociatedMember,bool SecurityEnable){	mlme_orphan_response(OrphanAddress,ShortAddress,AssociatedMember,SecurityEnable,true);}void Mac802_15_4::MLME_RESET_request(bool SetDefaultPIB){	mlme_reset_request(SetDefaultPIB,true);}void Mac802_15_4::MLME_RX_ENABLE_request(bool DeferPermit,UINT_32 RxOnTime,UINT_32 RxOnDuration){	mlme_rx_enable_request(DeferPermit,RxOnTime,RxOnDuration,true);}void Mac802_15_4::MLME_SCAN_request(UINT_8 ScanType,UINT_32 ScanChannels,UINT_8 ScanDuration){	mlme_scan_request(ScanType,ScanChannels,ScanDuration,true);}void Mac802_15_4::MLME_SET_request(MPIBAenum PIBAttribute,MAC_PIB *PIBAttributeValue){	PHYenum p_state;	MACenum t_status;	t_status = m_SUCCESS;	switch(PIBAttribute)	{		case macAckWaitDuration:			phy->PLME_GET_request(phyCurrentChannel);	//value will be returned in tmp_ppib			if ((tmp_ppib.phyCurrentChannel <= 10)&&(PIBAttributeValue->macAckWaitDuration != 120)			 || (tmp_ppib.phyCurrentChannel > 10)&&(PIBAttributeValue->macAckWaitDuration != 54))				t_status = m_INVALID_PARAMETER;			else				mpib.macAckWaitDuration = PIBAttributeValue->macAckWaitDuration;			break;		case macAssociationPermit:				mpib.macAssociationPermit = PIBAttributeValue->macAssociationPermit;			break;		case macAutoRequest:				mpib.macAutoRequest = PIBAttributeValue->macAutoRequest;			break;		case macBattLifeExt:				mpib.macBattLifeExt = PIBAttributeValue->macBattLifeExt;			break;		case macBattLifeExtPeriods:			phy->PLME_GET_request(phyCurrentChannel);	//value will be returned in tmp_ppib			if ((tmp_ppib.phyCurrentChannel <= 10)&&(PIBAttributeValue->macBattLifeExtPeriods != 8)			 || (tmp_ppib.phyCurrentChannel > 10)&&(PIBAttributeValue->macBattLifeExtPeriods != 6))				t_status = m_INVALID_PARAMETER;			else				mpib.macBattLifeExtPeriods = PIBAttributeValue->macBattLifeExtPeriods;			break;		case macBeaconPayload:				//<macBeaconPayloadLength> should be set first				memcpy(mpib.macBeaconPayload,PIBAttributeValue->macBeaconPayload,mpib.macBeaconPayloadLength);			break;		case macBeaconPayloadLength:			if (PIBAttributeValue->macBeaconPayloadLength > aMaxBeaconPayloadLength)				t_status = m_INVALID_PARAMETER;			else				mpib.macBeaconPayloadLength = PIBAttributeValue->macBeaconPayloadLength;			break;		case macBeaconOrder:			if (PIBAttributeValue->macBeaconOrder > 15)				t_status = m_INVALID_PARAMETER;			else				mpib.macBeaconOrder = PIBAttributeValue->macBeaconOrder;			break;		case macBeaconTxTime:			mpib.macBeaconTxTime = PIBAttributeValue->macBeaconTxTime;			break;		case macBSN:			mpib.macBSN = PIBAttributeValue->macBSN;			break;		case macCoordExtendedAddress:			mpib.macCoordExtendedAddress = PIBAttributeValue->macCoordExtendedAddress;			break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -