📄 p802_15_4mac.cc
字号:
case macCoordShortAddress: mpib.macCoordShortAddress = PIBAttributeValue->macCoordShortAddress; break; case macDSN: mpib.macDSN = PIBAttributeValue->macDSN; break; case macGTSPermit: mpib.macGTSPermit = PIBAttributeValue->macGTSPermit; break; case macMaxCSMABackoffs: if (PIBAttributeValue->macMaxCSMABackoffs > 5) t_status = m_INVALID_PARAMETER; else mpib.macMaxCSMABackoffs = PIBAttributeValue->macMaxCSMABackoffs; break; case macMinBE: if (PIBAttributeValue->macMinBE > 3) t_status = m_INVALID_PARAMETER; else mpib.macMinBE = PIBAttributeValue->macMinBE; break; case macPANId: mpib.macPANId = PIBAttributeValue->macPANId; break; case macPromiscuousMode: mpib.macPromiscuousMode = PIBAttributeValue->macPromiscuousMode; //some other operations (refer to sec. 7.5.6.6) mpib.macRxOnWhenIdle = PIBAttributeValue->macPromiscuousMode; p_state = mpib.macRxOnWhenIdle?p_RX_ON:p_TRX_OFF; phy->PLME_SET_TRX_STATE_request(p_state); break; case macRxOnWhenIdle: mpib.macRxOnWhenIdle = PIBAttributeValue->macRxOnWhenIdle; break; case macShortAddress: mpib.macShortAddress = PIBAttributeValue->macShortAddress; break; case macSuperframeOrder: if (PIBAttributeValue->macSuperframeOrder > 15) t_status = m_INVALID_PARAMETER; else mpib.macSuperframeOrder = PIBAttributeValue->macSuperframeOrder; break; case macTransactionPersistenceTime: mpib.macTransactionPersistenceTime = PIBAttributeValue->macTransactionPersistenceTime; break; case macACLEntryDescriptorSet: case macACLEntryDescriptorSetSize: case macDefaultSecurity: case macACLDefaultSecurityMaterialLength: case macDefaultSecurityMaterial: case macDefaultSecuritySuite: case macSecurityMode: break; //currently security ignored in simulation default: t_status = m_UNSUPPORTED_ATTRIBUTE; break; } sscs->MLME_SET_confirm(t_status,PIBAttribute);}void Mac802_15_4::MLME_START_request(UINT_16 PANId,UINT_8 LogicalChannel,UINT_8 BeaconOrder, UINT_8 SuperframeOrder,bool PANCoordinator,bool BatteryLifeExtension, bool CoordRealignment,bool SecurityEnable){ mlme_start_request(PANId,LogicalChannel,BeaconOrder,SuperframeOrder,PANCoordinator,BatteryLifeExtension,CoordRealignment,SecurityEnable,true);}void Mac802_15_4::MLME_SYNC_request(UINT_8 LogicalChannel, bool TrackBeacon){ mlme_sync_request(LogicalChannel,TrackBeacon,true);}void Mac802_15_4::MLME_POLL_request(UINT_8 CoordAddrMode,UINT_16 CoordPANId,IE3ADDR CoordAddress,bool SecurityEnable){ mlme_poll_request(CoordAddrMode,CoordPANId,CoordAddress,SecurityEnable,false,true);}inline int Mac802_15_4::hdr_dst(char* hdr, int dst){ return p802_15_4hdr_dst(hdr,dst);}inline int Mac802_15_4::hdr_src(char* hdr, int src){ return p802_15_4hdr_src(hdr,src);}inline int Mac802_15_4::hdr_type(char* hdr, UINT_16 type){ return p802_15_4hdr_type(hdr,type);}void Mac802_15_4::recv(Packet *p, Handler *h){ hdr_lrwpan* wph = HDR_LRWPAN(p); hdr_cmn *ch = HDR_CMN(p); bool noAck; int i; UINT_8 txop; FrameCtrl frmCtrl; SuperframeSpec t_sfSpec; if (!Nam802_15_4::emStatus) Nam802_15_4::emStatus = (netif_->node()->energy_model()?true:false); //is there a better place to do this? if(ch->direction() == hdr_cmn::DOWN) //outgoing packet {#ifdef DEBUG802_15_4 fprintf(stdout,"[%s::%s][%f](node %d) outgoing pkt: type = %s, src = %d, dst = %d, uid = %d, mac_uid = ??, size = %d\n",__FILE__,__FUNCTION__,CURRENT_TIME,index_,wpan_pName(p),p802_15_4macSA(p),p802_15_4macDA(p),ch->uid(),ch->size());#endif //-- Notes for power-saving: // It turns out to be very difficult to apply sleeping model in 802.15.4. // First, a node shouldn't go to sleep if peer2peer transmission mode is // used. Non-peer2peer means that a node only communicates with its parent // and/or children, which requests that pure tree routing be used. // Second, even pure tree routing is used, a node can only go to sleep // if it satisfies both the sleeping condition as a parent (to its children) // and that as a child (to its parent) in a multi-hop environment. To // satisfy both conditions requires efficient scheduling scheme. // Since ns2, by default, treats the power consumption in idle mode same // as that in sleeping mode, it makes no difference at this moment whether // we set sleeping mode or not. //wake up the node if it is in sleep mode (only for legacy applications) EnergyModel *em = netif_->node()->energy_model(); if (em) { if (em->energy() <= 0) { drop(p,"ENE"); return; } if (em->sleep()) { em->set_node_sleep(0); em->set_node_state(EnergyModel::INROUTE); } } /* SSCS should call MCPS_DATA_request() directly if (from SSCS) { MCPS_DATA_request(wph->SrcAddrMode,wph->SrcPANId,wph->SrcAddr, wph->DstAddrMode,wph->DstPANId,wph->DstAddr, ch->size(),p,wph->msduHandle,wph->TxOptions); } else //802.15.4-unaware upper layer app. packet */ { callback_ = h; if (p802_15_4macDA(p) == MAC_BROADCAST) txop = 0; else { if (Mac802_15_4::ack4data) txop = TxOp_Acked; else txop = 0; txop |= Mac802_15_4::txOption; } wph->msduHandle = 0; MCPS_DATA_request(0,0,0,defFrmCtrl_AddrMode16,mpib.macPANId,p802_15_4macDA(p),ch->size(),p,0,txop); //direct transmission w/o security } return; } else //incoming packet {#ifdef DEBUG802_15_4 fprintf(stdout,"[%s::%s][%f](node %d) incoming pkt: type = %s, src = %d, dst = %d, uid = %d, mac_uid = %ld, size = %d\n",__FILE__,__FUNCTION__,CURRENT_TIME,index_,wpan_pName(p),p802_15_4macSA(p),p802_15_4macDA(p),ch->uid(),wph->uid,ch->size());#endif resetCounter(p802_15_4macSA(p)); //if during ED scan, discard all frames received over the PHY layer data service (sec. 7.5.2.1.1) //if during Active/Passive scan, discard all frames received over the PHY layer data service that are not beacon frames (sec. 7.5.2.1.2/7.5.2.1.3) //if during Orphan scan, discard all frames received over the PHY layer data service that are not coordinator realignment command frames (sec. 7.5.2.1.4) frmCtrl.FrmCtrl = wph->MHR_FrmCtrl; frmCtrl.parse(); if (taskP.taskStatus(TP_mlme_scan_request)) if (taskP.mlme_scan_request_ScanType == 0x00) //ED scan {#ifdef DEBUG802_15_4 fprintf(stdout,"[D][ED][%s::%s::%d][%f](node %d) dropping pkt: type = %s, src = %d, dst = %d, uid = %d, mac_uid = %ld, size = %d\n",__FILE__,__FUNCTION__,__LINE__,CURRENT_TIME,index_,wpan_pName(p),p802_15_4macSA(p),p802_15_4macDA(p),ch->uid(),wph->uid,ch->size());#endif drop(p,"ED"); return; } else if (((taskP.mlme_scan_request_ScanType == 0x01) //Active scan ||(taskP.mlme_scan_request_ScanType == 0x02)) //Passive scan && (frmCtrl.frmType != defFrmCtrl_Type_Beacon)) {#ifdef DEBUG802_15_4 fprintf(stdout,"[D][APS][%s::%s::%d][%f](node %d) dropping pkt: type = %s, src = %d, dst = %d, uid = %d, mac_uid = %ld, size = %d\n",__FILE__,__FUNCTION__,__LINE__,CURRENT_TIME,index_,wpan_pName(p),p802_15_4macSA(p),p802_15_4macDA(p),ch->uid(),wph->uid,ch->size());#endif drop(p,"APS"); return; } else if ((taskP.mlme_scan_request_ScanType == 0x03) //Orphan scan && ((frmCtrl.frmType != defFrmCtrl_Type_MacCmd)||(wph->MSDU_CmdType != 0x08))) {#ifdef DEBUG802_15_4 fprintf(stdout,"[D][OPH][%s::%s::%d][%f](node %d) dropping pkt: type = %s, src = %d, dst = %d, uid = %d, mac_uid = %ld, size = %d\n",__FILE__,__FUNCTION__,__LINE__,CURRENT_TIME,index_,wpan_pName(p),p802_15_4macSA(p),p802_15_4macDA(p),ch->uid(),wph->uid,ch->size());#endif drop(p,"OPH"); return; } //drop the packet if corrupted if (ch->error()) {#ifdef DEBUG802_15_4 fprintf(stdout,"[D][ERR][%s::%s::%d][%f](node %d) dropping pkt: type = %s, src = %d, dst = %d, uid = %d, mac_uid = %ld, size = %d\n",__FILE__,__FUNCTION__,__LINE__,CURRENT_TIME,index_,wpan_pName(p),p802_15_4macSA(p),p802_15_4macDA(p),ch->uid(),wph->uid,ch->size());#endif drop(p,"ERR"); return; } //drop the packet if the link quality is too bad (basically, collisions) if ((wph->rxTotPower-p->txinfo_.RxPr) > 0.0) if (p->txinfo_.RxPr/(wph->rxTotPower-p->txinfo_.RxPr) < p->txinfo_.CPThresh) {#ifdef DEBUG802_15_4 fprintf(stdout,"[D][LQI][%s::%s::%d][%f](node %d) dropping pkt: type = %s, src = %d, dst = %d, uid = %d, mac_uid = %ld, size = %d\n",__FILE__,__FUNCTION__,__LINE__,CURRENT_TIME,index_,wpan_pName(p),p802_15_4macSA(p),p802_15_4macDA(p),ch->uid(),wph->uid,ch->size());#endif if (!wph->colFlag) nam->flashNodeColor(CURRENT_TIME); drop(p,"LQI"); return; } if (frmCtrl.frmType == defFrmCtrl_Type_Beacon) { t_sfSpec.SuperSpec = wph->MSDU_SuperSpec; t_sfSpec.parse(); if (t_sfSpec.BO != 15) { //update superframe specification sfSpec3 = t_sfSpec; //calculate the time when we received the first bit of the beacon macBcnOtherRxTime = (CURRENT_TIME - phy->trxTime(p)) * phy->getRate('s'); //update beacon order and superframe order macBeaconOrder3 = sfSpec3.BO; macSuperframeOrder3 = sfSpec3.SO; } } //---perform filtering (refer to sec. 7.5.6.2)--- //drop the packet if FCS is not correct (ignored in simulation) if (ch->ptype() == PT_MAC) //perform further filtering only if it is an 802.15.4 packet if (!mpib.macPromiscuousMode) //perform further filtering only if the PAN is currently not in promiscuous mode { //check packet type if ((frmCtrl.frmType != defFrmCtrl_Type_Beacon) &&(frmCtrl.frmType != defFrmCtrl_Type_Data) &&(frmCtrl.frmType != defFrmCtrl_Type_Ack) &&(frmCtrl.frmType != defFrmCtrl_Type_MacCmd)) {#ifdef DEBUG802_15_4 fprintf(stdout,"[D][TYPE][%s::%s::%d][%f](node %d) dropping pkt: type = %s, src = %d, dst = %d, uid = %d, mac_uid = %ld, size = %d\n",__FILE__,__FUNCTION__,__LINE__,CURRENT_TIME,index_,wpan_pName(p),p802_15_4macSA(p),p802_15_4macDA(p),ch->uid(),wph->uid,ch->size());#endif drop(p,"TYPE"); return; } //check source PAN ID for beacon frame if ((frmCtrl.frmType == defFrmCtrl_Type_Beacon) &&(mpib.macPANId != 0xffff) &&(wph->MHR_SrcAddrInfo.panID != mpib.macPANId)) {#ifdef DEBUG802_15_4 fprintf(stdout,"[D][PAN][%s::%s::%d][%f](node %d) dropping pkt: type = %s, src = %d, dst = %d, uid = %d, mac_uid = %ld, size = %d\n",__FILE__,__FUNCTION__,__LINE__,CURRENT_TIME,index_,wpan_pName(p),p802_15_4macSA(p),p802_15_4macDA(p),ch->uid(),wph->uid,ch->size());#endif drop(p,"PAN"); return; } //check dest. PAN ID if it is included if ((frmCtrl.dstAddrMode == defFrmCtrl_AddrMode16) ||(frmCtrl.dstAddrMode == defFrmCtrl_AddrMode64)) if ((wph->MHR_DstAddrInfo.panID != 0xffff) &&(wph->MHR_DstAddrInfo.panID != mpib.macPANId)) {#ifdef DEBUG802_15_4 fprintf(stdout,"[D][PAN][%s::%s::%d][%f](node %d) dropping pkt: type = %s, src = %d, dst = %d, uid = %d, mac_uid = %ld, size = %d\n",__FILE__,__FUNCTION__,__LINE__,CURRENT_TIME,index_,wpan_pName(p),p802_15_4macSA(p),p802_15_4macDA(p),ch->uid(),wph->uid,ch->size());#endif drop(p,"PAN"); return; } //check dest. address if it is included if (frmCtrl.dstAddrMode == defFrmCtrl_AddrMode16) { if ((wph->MHR_DstAddrInfo.addr_16 != 0xffff) && (wph->MHR_DstAddrInfo.addr_16 != mpib.macShortAddress)) {#ifdef DEBUG802_15_4 fprintf(stdout,"[D][ADR][%s::%s::%d][%f](node %d) dropping pkt: type = %s, src = %d, dst = %d, uid = %d, mac_uid = %ld, size = %d\n",__FILE__,__FUNCTION__,__LINE__,CURRENT_TIME,index_,wpan_pName(p),p802_15_4macSA(p),p802_15_4macDA(p),ch->uid(),wph->uid,ch->size());#endif drop(p,"ADR"); return; } } else if (frmCtrl.dstAddrMode == defFrmCtrl_AddrMode64) { if (wph->MHR_DstAddrInfo.addr_64 != aExtendedAddress) {#ifdef DEBUG802_15_4 fprintf(stdout,"[D][ADR][%s::%s::%d][%f](node %d) dropping pkt: type = %s, src = %d, dst = %d, uid = %d, mac_uid = %ld, size = %d\n",__FILE__,__FUNCTION__,__LINE__,CURRENT_TIME,index_,wpan_pName(p),p802_15_4macSA(p),p802_15_4macDA(p),ch->uid(),wph->uid,ch->size());#endif drop(p,"ADR"); return; } } //check for Data/MacCmd frame only w/ source address if ((frmCtrl.frmType == defFrmCtrl_Type_Data) ||(frmCtrl.frmType == defFrmCtrl_Type_MacCmd)) if (frmCtrl.dstAddrMode == defFrmCtrl_AddrModeNone) { if (((!capability.FFD)||(numberDeviceLink(&deviceLink1) == 0)) //I am not a coordinator ||(wph->MHR_SrcAddrInfo.panID != mpib.macPANId)) {#ifdef DEBUG802_15_4 fprintf(stdout,"[D][PAN][%s::%s::%d][%f](node %d) dropping pkt: type = %s, src = %d, dst = %d, uid = %d, mac_uid = %ld, size = %d\n",__FILE__,__FUNCTION__,__LINE__,CURRENT_TIME,index_,wpan_pName(p),p802_15_4macSA(p),p802_15_4macDA(p),ch->uid(),wph->uid,ch->size());#endif drop(p,"PAN"); return; } } //we need to add one more filter for supporting multi-hop beacon enabled mode (not in the draft) if (frmCtrl.frmType == defFrmCtrl_Type_Beacon) if (wph->MHR_DstAddrInfo.panID != 0xffff) if ((mpib.macCoordExtendedAddress != wph->MHR_SrcAddrInfo.addr_64) //ok even for short address (in simulation) && (mpib.macCoordExtendedAddress != def_macCoordExtendedAddress)) {#ifdef DEBUG802_15_4 fprintf(stdout,"[D][COO][%s::%s::%d][%f](node %d) dropping pkt: type = %s, src = %d, dst = %d, uid = %d, mac_uid = %ld, size = %d\n",__FILE__,__FUNCTION__,__LINE__,CURRENT_TIME,index_,wpan_pName(p),p802_15_4macSA(p),p802_15_4macDA(p),ch->uid(),wph->uid,ch->size());#endif drop(p,"COO"); return; } } //---filtering done--- //perform security task if required (ignored in simulation) //send an acknowledgement if needed (no matter this is a duplicated packet or not) if ((frmCtrl.frmType == defFrmCtrl_Type_Data) ||(frmCtrl.frmType == defFrmCtrl_Type_MacCmd)) if (frmCtrl.ackReq) //acknowledgement required { //association request command will be ignored under following cases if ((frmCtrl.frmType == defFrmCtrl_Type_MacCmd) && (wph->MSDU_CmdType == 0x01)) if ((!capability.FFD) //not an FFD || (mpib.macShortAddress == 0xffff) //not yet joined any PAN || (!macAssociationPermit)) //association not permitted { Packet:free(p); return; } noAck = false; if (frmCtrl.frmType == defFrmCtrl_Type_MacCmd) if ((rxCmd)||(txBcnCmd)) noAck = true; if (!noAck) { constructACK(p); //stop CSMA-CA if it is pending (it will be restored after the transmission of ACK) if (backoffStatus == 99) { backoffStatus = 0; csmaca->cancel(); } plme_set_trx_state_request(p_TX_ON); } } else resetTRX(); if (frmCtrl.frmType == defFrmCtrl_Type_MacCmd) if ((rxCmd)||(txBcnCmd)) {#ifdef DEBUG802_15_4 { fprintf(stdout,"[D][BSY][%s::%s::%d][%f](node %d) dropping pkt: type = %s, src = %d, dst = %d, uid = %d, mac_uid = %ld, size = %d\n",__FILE__,__FUNCTION__,__LINE__,CURRENT_TIME,index_,wpan_pName(p),p802_15_4macSA(p),p802_15_4macDA(p),ch->uid(),wph->uid,ch->size()); if (rxCmd) fprintf(stdout,"\trxCmd pkt: type = %s, src = %d, dst = %d, uid = %d, mac_uid = %ld, size = %d\n",wpan_pName(rxCmd),p802_15_4macSA(rxCmd),p802_15_4macDA(rxCmd),HDR_CMN(rxCmd)->uid(),HDR_LRWPAN(rxCmd)->uid,HDR_CMN(rxCmd)->size()); if (txBcnCmd) fprintf(stdout,"\ttxBcnCmd pkt: type = %s, src = %d, dst = %d, uid = %d, mac_uid = %ld, size = %d\n",wpan_pName(txBcnCmd),p802_15_4macSA(txBcnCmd),p802_15_4macDA(txBcnCmd),HDR_CMN(txBcnCmd)->uid(),HDR_LRWPAN(txBcnCmd)->uid,HDR_CMN(txBcnCmd)->size()); }#endif drop(p,"BSY"); return; } if (frmCtrl.frmType == defFrmCtrl_Type_Data) if (rxData) {#ifdef DEBUG802_15_4 fprintf(stdout,"[D][BSY][%s::%s::%d][%f](node %d) dropping pkt: type = %s, src = %d, dst = %d, uid = %d, mac_uid = %ld, size = %d\n",__FILE__,__FUNCTION__,__LINE__,CURRENT_TIME,index_,wpan_pName(p),p802_15_4macSA(p),p802_15_4macDA(p),ch->uid(),wph->uid,ch->size());#endif drop(p,"BSY"); return; } //check duplication -- must be performed AFTER all drop's if (frmCtrl.frmType == defFrmCtrl_Type_Beacon) i = chkAddUpdHListLink(&hlistBLink1,&hlistBLink2,p802_15_4macSA(p),wph->MHR_BDSN); else if (frmCtrl.frmType != defFrmCtrl_Type_Ack) i = chkAddUpdHListLink(&hlistDLink1,&hlistDLink2,p802_15_4macSA(p),wph->MHR_BDSN);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -