亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? nwk.c

?? ZIGBEE2006協議棧
?? C
?? 第 1 頁 / 共 2 頁
字號:
	--phy_pib.currentTxFrm;
	*phy_pib.currentTxFrm = (BYTE) (a_nwk_tx_data.dstSADDR);

	//frame control
	--phy_pib.currentTxFrm;
	*phy_pib.currentTxFrm = a_nwk_tx_data.fcfmsb;
	--phy_pib.currentTxFrm;
	*phy_pib.currentTxFrm = a_nwk_tx_data.fcflsb;

	//network header is fixed size
	phy_pib.currentTxFlen +=  8;

nwkTxData_addmac:
	//fill in the MAC fields. For now, we don't support inter-PAN
	// so the PANID has to be our mac PANID
	a_mac_tx_data.DestPANID = mac_pib.macPANID;
	a_mac_tx_data.SrcPANID = mac_pib.macPANID;

	if (a_nwk_tx_data.dstSADDR == LRWPAN_SADDR_USE_LADDR ){
		//long address is specified from above.  We assume they know where
		//they are going no routing necessary
		a_mac_tx_data.fcfmsb = LRWPAN_FCF_DSTMODE_LADDR|LRWPAN_FCF_SRCMODE_LADDR;
		//copy in the long address
		halUtilMemCopy(&a_mac_tx_data.DestAddr.laddr.bytes[0], a_nwk_tx_data.dstLADDR, 8);
	} else {
		//lets do some routing
#ifdef LRWPAN_RFD
		//RFD's are easy. Always send to parent, our SRC address is always long
		//so that parent can confirm that the RFD is still in their neighbor table
		//will use the parent short address
		a_mac_tx_data.fcfmsb = LRWPAN_FCF_DSTMODE_SADDR|LRWPAN_FCF_SRCMODE_LADDR;
		a_mac_tx_data.DestAddr.saddr = mac_pib.macCoordShortAddress;
#else
		{
			SADDR newDstSADDR;
			//this is router. need to determine the new dstSADDR
			newDstSADDR = a_nwk_tx_data.dstSADDR; //default
			DEBUG_STRING(DBG_INFO,"Routing pkt to: ");
            DEBUG_UINT16(DBG_INFO,newDstSADDR);
			if (a_nwk_tx_data.dstSADDR != LRWPAN_BCAST_SADDR) {
				//not broadcast address
				newDstSADDR = ntFindNewDst(a_nwk_tx_data.dstSADDR);
				DEBUG_STRING(DBG_INFO," through: ");
                DEBUG_UINT16(DBG_INFO,newDstSADDR);
				if (newDstSADDR == LRWPAN_BCAST_SADDR) {
					DEBUG_STRING(DBG_INFO,", UNROUTABLE, error!\n ");
					//error indicator. An unroutable packet from here.
					a_mac_service.args.error.status = LRWPAN_STATUS_NWK_PACKET_UNROUTABLE;
					a_mac_service.cmd = LRWPAN_SVC_MAC_ERROR;
					goto nwkTxData_sendit;
				}
				DEBUG_STRING(DBG_INFO,"\n");
			}

			//fill it in.
			a_mac_tx_data.fcfmsb = LRWPAN_FCF_DSTMODE_SADDR|LRWPAN_FCF_SRCMODE_LADDR;
			a_mac_tx_data.DestAddr.saddr = newDstSADDR;
		}
#endif

	}


	//for data frames, we want a MAC level ACK, unless it is a broadcast.
	if ( ((LRWPAN_GET_DST_ADDR(a_mac_tx_data.fcfmsb)) == LRWPAN_ADDRMODE_SADDR) &&
		a_mac_tx_data.DestAddr.saddr == LRWPAN_BCAST_SADDR) {
			//no MAC ACK
			a_mac_tx_data.fcflsb = LRWPAN_FRAME_TYPE_DATA|LRWPAN_FCF_INTRAPAN_MASK ;
		}else {
			a_mac_tx_data.fcflsb = LRWPAN_FRAME_TYPE_DATA|LRWPAN_FCF_INTRAPAN_MASK |LRWPAN_FCF_ACKREQ_MASK;
		}

		//send it.
		a_mac_service.cmd = LRWPAN_SVC_MAC_GENERIC_TX;



nwkTxData_sendit:

		macDoService();

}



static void nwkRxFSM(void) {
	BYTE *ptr;

nwkRxFSM_start:

	switch(nwkRxState) {
		case NWK_RXSTATE_IDLE:
			break;
		case NWK_RXSTATE_START:
			//we have a packet, lets check it out.
			ptr = a_nwk_rx_data.orgpkt.data + a_nwk_rx_data.nwkOffset;
			if (NWK_IS_CMD(*ptr)) {
				//currently don't handle CMD packets. Discard.
				DEBUG_STRING(DBG_INFO,"NWK: Received NWK CMD packet, discarding.\n");
				//MAC resource already free; need to free the MEM resource
				MemFree(a_nwk_rx_data.orgpkt.data);
				nwkRxState = NWK_RXSTATE_IDLE;
				break;
			}
			//this is a data packet. do more parsing.
			nwkParseHdr(ptr);

			//see if this is for us.
			if ((a_nwk_rx_data.dstSADDR == LRWPAN_BCAST_SADDR) ||
				(a_nwk_rx_data.dstSADDR == LRWPAN_SADDR_USE_LADDR) ||
				(a_nwk_rx_data.dstSADDR == macGetShortAddr())) {
					//hand this off to the APS layer
					nwkRxState = NWK_RXSTATE_APS_HANDOFF;
				} else {
					//have to route this packet
					nwkRxState = NWK_RXSTATE_DOROUTE;
				}
				goto nwkRxFSM_start;

		case NWK_RXSTATE_APS_HANDOFF:
			if (apsRxBusy()) break;    //apsRX is still busy
			//handoff the current packet
			apsRxHandoff();
			//we are finished with this packet.
			//we don't need to do anything to free this resource other
			// than to change state
			nwkRxState = NWK_RXSTATE_IDLE;
			break;


		case NWK_RXSTATE_DOROUTE:
#ifdef LRWPAN_RFD
			//RFD somehow got a data packet not intended for it.
			//should never happen, but put code here anyway to discard it.
			DEBUG_STRING(DBG_INFO,"NWK: RFD received spurious datapacket, discarding.\n");
			MemFree(a_nwk_rx_data.orgpkt.data);
			nwkRxState = NWK_RXSTATE_IDLE;
#else
			//first, check the radius, if zero, then discard.
			if (!(*(ptr+6))) {
				DEBUG_STRING(DBG_INFO,"NWK: Data packet is out of hops for dest: ");
				DEBUG_UINT16(DBG_INFO,a_nwk_rx_data.dstSADDR);
                DEBUG_STRING(DBG_INFO,", discarding...\n");
				MemFree(a_nwk_rx_data.orgpkt.data);
				nwkRxState = NWK_RXSTATE_IDLE;
				break;
			}
			DEBUG_STRING(DBG_INFO,"NWK: Routing NWK Packet to: ");
			DEBUG_UINT16(DBG_INFO,a_nwk_rx_data.dstSADDR);
			DEBUG_STRING(DBG_INFO,"\n");
			//this packet requires routing, not destined for us.
			if (nwkRxBuffFull()) {
				//no more room. discard this packet
				DEBUG_STRING(DBG_INFO,"NWK: FWD buffer full, discarding pkt.\n");
				DEBUG_STRING(DBG_INFO,"NWK state: ");
				DEBUG_UINT8(DBG_INFO,nwkState);
				DEBUG_STRING(DBG_INFO,"MAC state: ");
				DEBUG_UINT8(DBG_INFO,macState);
				DEBUG_STRING(DBG_INFO,"\n");
				MemFree(a_nwk_rx_data.orgpkt.data);
				nwkRxState = NWK_RXSTATE_IDLE;
			}else {
				//ok, add this pkt to the buffer
				nwk_pib.rxHead++;
				if (nwk_pib.rxHead == NWK_RXBUFF_SIZE) nwk_pib.rxHead = 0;
				//save it.
				nwk_pib.rxBuff[nwk_pib.rxHead].data = a_nwk_rx_data.orgpkt.data;
				nwk_pib.rxBuff[nwk_pib.rxHead].nwkOffset = a_nwk_rx_data.nwkOffset;
				nwkRxState = NWK_RXSTATE_IDLE;
				//this packet will be retransmitted by nwkFSM
			}

#endif

			break;

		default:
			break;

	}


}



//Callback from MAC Layer
//Returns TRUE if nwk is still busy with last RX packet.

BOOL nwkRxBusy(void){
	return(nwkRxState != NWK_RXSTATE_IDLE);
}

//Callback from MAC Layer
//Hands off parsed packet from MAC layer, frees MAC for parsing
//next packet.
void nwkRxHandoff(void){

	a_nwk_rx_data.orgpkt.data = a_mac_rx_data.orgpkt->data;
	a_nwk_rx_data.orgpkt.rssi = a_mac_rx_data.orgpkt->rssi;
	a_nwk_rx_data.nwkOffset = a_mac_rx_data.pload_offset;
	nwkRxState = NWK_RXSTATE_START;
}

static void nwkParseHdr(BYTE *ptr) {

	//ptr is pointing at nwk header. Get the SRC/DST nodes.
	ptr= ptr+2;
	//get Dst SADDR
	a_nwk_rx_data.dstSADDR = *ptr;
	ptr++;
	a_nwk_rx_data.dstSADDR += (((UINT16)*ptr) << 8);
	ptr++;

	//get Src SADDR
	a_nwk_rx_data.srcSADDR = *ptr;
	ptr++;
	a_nwk_rx_data.srcSADDR += (((UINT16)*ptr) << 8);
	ptr++;


}

#ifdef LRWPAN_FFD

//copies packet to forward from heap space to TXbuffer space
void nwkCopyFwdPkt(void){
	BYTE *srcptr, len;
	NWK_FWD_PKT *pkt;

	phy_pib.currentTxFrm = &tmpTxBuff[LRWPAN_MAX_FRAME_SIZE];
	//get next PKT
	pkt = nwkGetRxPacket();
	
	srcptr = pkt->data;  //points at original packet in heapspace

	//compute bytes to copy.
	//nwkoffset is the offset of the nwkheader in the original packet
	len = *(srcptr) - pkt->nwkOffset - PACKET_FOOTER_SIZE + 1 ;


	//point this one byte past the end of the packet
	srcptr = srcptr
		+ *(srcptr) //length of original packet, not including this byte
		+ 1         //add one for first byte which contains packet length
		- PACKET_FOOTER_SIZE; //subtract footer bytes, don't want to copy these.
	//save length
	phy_pib.currentTxFlen = len;
	//copy from heap space to TXBuffer space
	do {
		srcptr--; phy_pib.currentTxFrm--;
		*phy_pib.currentTxFrm = *srcptr;
		len--;
	}while(len);
	nwkFreeRxPacket(TRUE);  //free this packet
	//some final steps
	//get the dstSADDR, needed for routing.
	a_nwk_tx_data.dstSADDR = *(phy_pib.currentTxFrm+2);
	a_nwk_tx_data.dstSADDR += (((UINT16)*(phy_pib.currentTxFrm+3)) << 8);

	//decrement the radius before sending it on.
	*(phy_pib.currentTxFrm+6)= *(phy_pib.currentTxFrm+6)- 1;
	a_nwk_tx_data.radius = *(phy_pib.currentTxFrm+6);

	
	//leave the SADDR unchanged as we want to know where this originated from!
#if 0
	//replace the SADDR with our SADDR
	*(phy_pib.currentTxFrm+4) = (BYTE) macGetShortAddr();
	*(phy_pib.currentTxFrm+5) = (BYTE) (macGetShortAddr() >>8);
#endif

}

static BOOL nwkRxBuffFull(void){
	BYTE tmp;
	//if next write would go to where Tail is, then buffer is full
	tmp = nwk_pib.rxHead+1;
	if (tmp == NWK_RXBUFF_SIZE) tmp = 0;
	return(tmp == nwk_pib.rxTail);
}

static BOOL nwkRxBuffEmpty(void){
	return(nwk_pib.rxTail == nwk_pib.rxHead);
}

//this does NOT remove the packet from the buffer
static NWK_FWD_PKT *nwkGetRxPacket(void) {
	BYTE tmp;
	if (nwk_pib.rxTail == nwk_pib.rxHead) return(NULL);
	tmp = nwk_pib.rxTail+1;
	if (tmp == NWK_RXBUFF_SIZE) tmp = 0;
	return(&nwk_pib.rxBuff[tmp]);
}

//frees the first packet in the buffer.
static void nwkFreeRxPacket(BOOL freemem) {
	nwk_pib.rxTail++;
	if (nwk_pib.rxTail == NWK_RXBUFF_SIZE) nwk_pib.rxTail = 0;
	if (freemem) MemFree(nwk_pib.rxBuff[nwk_pib.rxTail].data);
}

#endif

//given a router child SADDR, find the parent router SADDR
UINT16 nwkFindParentSADDR(SADDR childSADDR) {

	UINT8 currentDepth;
	SADDR currentParent;
	SADDR currentRouter;
	SADDR maxSADDR;
	UINT8 i;


	currentDepth = 1;
	currentParent = 0;
	do {
		for (i=0; i<LRWPAN_MAX_ROUTERS_PER_PARENT; i++) {
			if (i==0) currentRouter = currentParent+1;
			else currentRouter += ntGetCskip(currentDepth);
			if (childSADDR == currentRouter) return(currentRouter);
			maxSADDR = ntGetMaxSADDR(currentRouter,currentDepth+1);
			if ((childSADDR > currentRouter) && (childSADDR <= maxSADDR))
				break; //must go further down the tree
		}
		currentDepth++;
		currentParent = currentRouter;
	}
	while (currentDepth < LRWPAN_MAX_DEPTH-1);
	//if we reach here, could not find an address. Return 0 as an error
	return(0);
}

UINT16 nwkGetHopsToDest(SADDR dstSADDR){

	UINT16 numHops;
	SADDR currentParent, maxSADDR;
	UINT8 currentDepth;
	UINT8 i;
	SADDR currentRouter;

	numHops = 1;            //return a minimum value of 1

	currentDepth = 0;
	//first compute hops up the tree then down the tree
	if ( macGetShortAddr() == 0) goto nwkGetHopsToDest_down;  //this is the coordinator
	if (macGetShortAddr() == dstSADDR) return(1);  //to myself, should not happen, but return min value
	currentParent = mac_pib.macCoordShortAddress; //start with my parent address
	currentDepth = mac_pib.depth - 1; //depth of my parent.
	do {
		if (currentParent == dstSADDR) return(numHops);  //destination is one of my parent nodes.
		if (currentParent == 0) break;         //at coordinator.
		//compute the max SADDR address range of parent

		maxSADDR = ntGetMaxSADDR(currentParent,currentDepth+1);  //depth of parent's children
		if ((dstSADDR > currentParent) &&  (dstSADDR <= maxSADDR)) {
			//this address is in this router's range, stop going up.
			break;
		}
		//go up a level
		currentDepth--;
		numHops++;
		if (currentDepth == 0 ) currentParent =0;
		else { currentParent = nwkFindParentSADDR(currentParent);
		if (!currentParent) {
			//could not find, set numHops to maximum and return
			return(LRWPAN_MAX_DEPTH<<1);
		}
		}
	}while(1);

nwkGetHopsToDest_down:
	currentDepth++; //increment depth, as this should reflect my current children
	//now search going down.
	do {
		//destination is in the current parent's range
		//see if it is one of the routers or children.
		//first see if it is one of the children of current parent
		numHops++;
		maxSADDR = ntGetMaxSADDR(currentParent,currentDepth);
		if (dstSADDR > (maxSADDR-LRWPAN_MAX_NON_ROUTER_CHILDREN) &&
			dstSADDR <= maxSADDR) break;  //it is one of the children nodes
		for (i=0; i<LRWPAN_MAX_ROUTERS_PER_PARENT; i++) {
			if (i==0) currentRouter = currentParent+1;
			else currentRouter += ntGetCskip(currentDepth);

			if (dstSADDR == currentRouter) return(currentRouter);
			maxSADDR = ntGetMaxSADDR(currentRouter,currentDepth+1);
			if ((dstSADDR > currentRouter) && (dstSADDR <= maxSADDR))
				break; //must go further down the tree
		}
		if (i == LRWPAN_MAX_ROUTERS_PER_PARENT) {
			//must be one of my non-router children, increment hops, return
			return(numHops);
		}
		currentDepth++;
		currentParent = currentRouter;

	}while(currentDepth < LRWPAN_MAX_DEPTH-1);

	if (numHops > LRWPAN_NWK_MAX_RADIUS) {
		DEBUG_STRING(DBG_ERR,"nwkGetHopsToDest: Error in hop calculation: ");
		DEBUG_UINT8(DBG_ERR,numHops);
		DEBUG_STRING(DBG_ERR,"\n");
		numHops = LRWPAN_NWK_MAX_RADIUS-1;
	}
	return(numHops);
}







?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产中文字幕精品| 亚洲男人的天堂在线观看| 日产精品久久久久久久性色| 欧美久久久一区| 久久精品国产999大香线蕉| 日韩精品一区二区三区视频| 国模一区二区三区白浆| 国产精品网站一区| 一本到不卡精品视频在线观看| 亚洲一区在线观看视频| 欧美一区二区精品在线| 国产老妇另类xxxxx| 日韩精品一二三| 欧美一区二区三区婷婷月色| 国内成人自拍视频| 中文字幕中文字幕一区| 欧美无砖专区一中文字| 蜜桃精品视频在线观看| 中文字幕高清不卡| 日本道在线观看一区二区| 蜜臀av在线播放一区二区三区| 精品国产乱子伦一区| 91丝袜呻吟高潮美腿白嫩在线观看| 夜夜精品视频一区二区| 亚洲精品一区二区三区在线观看| 成人国产精品免费观看| 亚洲国产三级在线| 国产亚洲福利社区一区| 欧美视频在线一区| 国产精品1024| 午夜精品久久久| 国产欧美精品一区二区三区四区| 在线看日韩精品电影| 韩国女主播成人在线观看| 亚洲免费在线视频| 精品99999| 欧美精品色综合| 99精品视频一区二区三区| 久久99精品国产.久久久久久| 亚洲欧洲国产日本综合| 欧美mv和日韩mv国产网站| 日本二三区不卡| 国产成人免费视频一区| 日本少妇一区二区| 一区二区在线电影| 国产精品第13页| 精品国产乱码久久久久久图片| 欧美午夜精品久久久久久孕妇| 国产精品综合二区| 日本不卡视频在线| 一区二区三区四区在线免费观看| 久久久天堂av| 日韩欧美电影在线| 欧美日韩亚洲国产综合| 色哟哟亚洲精品| 成人一级片在线观看| 狠狠色丁香九九婷婷综合五月| 午夜精品福利在线| 亚洲一区二区三区四区不卡| 国产精品国产三级国产普通话蜜臀 | 在线播放/欧美激情| zzijzzij亚洲日本少妇熟睡| 国产美女娇喘av呻吟久久| 美女视频一区二区| 免费成人美女在线观看| 视频一区视频二区在线观看| 亚洲成a人v欧美综合天堂| 亚洲另类在线制服丝袜| 亚洲天堂福利av| 亚洲欧洲精品成人久久奇米网| 欧美韩国一区二区| 国产精品色婷婷久久58| 国产精品欧美一区二区三区| 亚洲第一福利一区| 亚洲va欧美va人人爽| 悠悠色在线精品| 亚洲午夜激情av| 亚洲va韩国va欧美va精品| 亚洲bt欧美bt精品777| 视频一区二区欧美| 日韩高清不卡一区二区三区| 青青草国产精品亚洲专区无| 麻豆传媒一区二区三区| 精彩视频一区二区| 国产乱人伦精品一区二区在线观看 | 亚洲黄色性网站| 亚洲精品成人a在线观看| 亚洲一区二区三区自拍| 日韩专区欧美专区| 久久成人免费网| 国产盗摄女厕一区二区三区| 国产91色综合久久免费分享| 99精品视频一区| 欧美日韩高清在线| 日韩女优制服丝袜电影| 欧美经典三级视频一区二区三区| 国产精品久久久久久亚洲毛片 | 欧美一区二区三区播放老司机| 欧美精品日韩精品| 精品国产亚洲一区二区三区在线观看| 精品国产一区二区亚洲人成毛片| 国产婷婷色一区二区三区在线| 国产精品美女久久久久久久久| 国产精品毛片久久久久久| 亚洲精品国产一区二区三区四区在线 | 日韩欧美在线不卡| 欧美韩国日本不卡| 亚洲二区在线视频| 国产精品一二三四五| 2019国产精品| 亚洲精品视频在线| 美女视频网站久久| 91在线视频18| 精品日韩一区二区三区| 亚洲国产精品二十页| 亚洲综合一二区| 国产主播一区二区| 欧美午夜精品一区| 中文字幕不卡三区| 天天av天天翘天天综合网色鬼国产| 国产自产v一区二区三区c| 日本久久一区二区| 久久噜噜亚洲综合| 亚洲二区在线视频| 不卡av电影在线播放| 91精品国产日韩91久久久久久| 国产精品久久久久四虎| 蜜臀av一区二区在线免费观看| 粉嫩aⅴ一区二区三区四区| 欧美男男青年gay1069videost| 国产精品视频免费看| 日韩av中文字幕一区二区三区| 9l国产精品久久久久麻豆| 日韩免费一区二区三区在线播放| 国产精品初高中害羞小美女文| 日本va欧美va瓶| 在线观看亚洲专区| 国产精品福利一区二区三区| 久久99久久久欧美国产| 欧美日韩成人在线| 亚洲欧美日韩在线| 成人免费视频视频| 精品久久久久香蕉网| 无吗不卡中文字幕| 欧美在线小视频| 亚洲欧洲三级电影| 成人综合在线视频| www久久精品| 精品一区二区三区欧美| 91麻豆精品国产91久久久资源速度| 最新久久zyz资源站| 国产精品123区| 亚洲精品在线免费播放| 久久精品二区亚洲w码| 91精品午夜视频| 午夜激情一区二区| 欧美丝袜自拍制服另类| 亚洲欧美二区三区| 99国产精品久| 国产精品久久久久久久久免费相片 | 日韩欧美电影在线| 日本va欧美va精品发布| 在线不卡一区二区| 日本三级韩国三级欧美三级| 欧美日韩不卡视频| 日韩中文字幕区一区有砖一区| 欧美一区在线视频| 青青草伊人久久| 日韩精品资源二区在线| 久久成人av少妇免费| 日韩欧美电影在线| 极品美女销魂一区二区三区免费 | 久久嫩草精品久久久精品一| 国精品**一区二区三区在线蜜桃| 日韩免费电影一区| 激情五月婷婷综合网| 久久久噜噜噜久久中文字幕色伊伊| 久久精品国产99久久6| 亚洲精品在线一区二区| 懂色av一区二区三区蜜臀| 国产精品国产三级国产aⅴ无密码| 一本久道中文字幕精品亚洲嫩| 18涩涩午夜精品.www| 91农村精品一区二区在线| 国产精品国产三级国产专播品爱网| 99久久精品99国产精品| 亚洲男人的天堂av| 欧美精品自拍偷拍动漫精品| 美国欧美日韩国产在线播放| 久久午夜羞羞影院免费观看| 成人黄色国产精品网站大全在线免费观看 | 欧美一区二区三区成人| 国内一区二区在线| 国产精品每日更新| 欧美色网站导航| 激情综合亚洲精品| 中文字幕一区不卡| 51精品秘密在线观看| 国产91丝袜在线观看| 一区二区不卡在线视频 午夜欧美不卡在|