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

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

?? nwk.c

?? zigbee 2004協議棧
?? 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一区二区三区免费野_久草精品视频
国产成人精品1024| 亚洲综合一二区| 国产精品一品视频| 久久精品亚洲一区二区三区浴池| 久久av老司机精品网站导航| 久久久久久电影| www.亚洲在线| 一二三四区精品视频| 欧美福利视频导航| 精品一区二区久久久| 中文字幕第一区二区| 91免费视频网| 日本vs亚洲vs韩国一区三区| 26uuu亚洲综合色| 色婷婷av一区二区三区之一色屋| 91精品在线麻豆| 欧美精品日韩精品| 亚洲第一av色| 国产中文一区二区三区| 久久蜜桃一区二区| 色一区在线观看| 美女诱惑一区二区| 中文字幕+乱码+中文字幕一区| 日本大香伊一区二区三区| 免费在线视频一区| 国产精品福利一区二区| 欧美日韩一区二区在线视频| 国产乱妇无码大片在线观看| 亚洲黄色免费电影| 久久嫩草精品久久久精品一| 欧美综合在线视频| 国产99一区视频免费| 亚洲午夜精品网| 国产精品麻豆视频| 欧美一级高清片| 91免费看`日韩一区二区| 精品综合久久久久久8888| 亚洲黄色片在线观看| 国产三级精品三级| 欧美成人女星排名| 在线国产亚洲欧美| 成人app在线| 激情综合色综合久久综合| 一区二区在线观看不卡| 日本一区二区三区四区在线视频| 555夜色666亚洲国产免| 色欧美片视频在线观看| 成人小视频免费在线观看| 秋霞电影一区二区| 亚洲韩国精品一区| 日韩理论电影院| 午夜久久久久久久久| ...av二区三区久久精品| 精品国产1区二区| 欧美日韩国产大片| 色999日韩国产欧美一区二区| 国产乱码精品1区2区3区| 美女一区二区三区在线观看| 性久久久久久久久| 亚洲二区在线观看| 亚洲精品网站在线观看| 国产精品久久久久久久第一福利| 精品国产伦一区二区三区免费| 欧美精选在线播放| 欧美亚洲日本一区| 在线看不卡av| 欧洲色大大久久| 在线精品亚洲一区二区不卡| 色综合久久中文字幕综合网| 97精品国产露脸对白| 成+人+亚洲+综合天堂| 成人涩涩免费视频| 国产91精品久久久久久久网曝门| 国产在线精品免费av| 久久国产精品无码网站| 蜜芽一区二区三区| 久久精品国产一区二区三区免费看| 日韩综合一区二区| 蜜臀99久久精品久久久久久软件| 青青草97国产精品免费观看 | 久久久www免费人成精品| 欧美一区二区在线免费播放| 7777精品伊人久久久大香线蕉超级流畅| 日本韩国欧美国产| 欧洲av一区二区嗯嗯嗯啊| 欧美日韩视频在线第一区| 8x8x8国产精品| 日韩一区二区三区在线| 亚洲精品在线免费播放| 国产日本一区二区| 中文字幕一区二区日韩精品绯色| 亚洲天堂免费看| 午夜精品久久久久影视| 免费看欧美美女黄的网站| 久久99国产精品麻豆| 高清国产午夜精品久久久久久| 成人美女视频在线看| 欧美优质美女网站| 欧美一级一区二区| 国产夜色精品一区二区av| 欧美高清在线视频| 一区二区在线观看视频| 日产国产欧美视频一区精品 | 国产一区二区导航在线播放| 国产高清不卡一区二区| 一本到高清视频免费精品| 欧美老人xxxx18| 久久综合色一综合色88| 亚洲欧洲日韩一区二区三区| 亚洲综合一区二区三区| 激情六月婷婷久久| fc2成人免费人成在线观看播放| 欧洲在线/亚洲| 精品国产一区二区三区不卡| 国产精品久久久久一区| 日韩中文字幕亚洲一区二区va在线 | 日本vs亚洲vs韩国一区三区二区| 国产大陆a不卡| 在线观看日韩高清av| 精品理论电影在线观看| 亚洲乱码日产精品bd| 美女精品一区二区| 色老综合老女人久久久| 精品人在线二区三区| 综合久久综合久久| 日本午夜一本久久久综合| 成人av在线影院| 日韩一区二区三区电影在线观看 | 日韩欧美国产一区二区三区| 国产精品久久久久久久久免费樱桃 | 日韩精品一级二级| 99久久777色| wwwwww.欧美系列| 亚洲成人av免费| 不卡一区二区在线| 精品精品欲导航| 亚洲福利视频导航| 不卡欧美aaaaa| 亚洲精品一区二区精华| 亚洲香肠在线观看| proumb性欧美在线观看| 精品福利一区二区三区| 午夜伦欧美伦电影理论片| www.亚洲精品| 日本一区二区三级电影在线观看| 免费一区二区视频| 欧美亚洲一区三区| 亚洲三级视频在线观看| 国产精品亚洲专一区二区三区| 欧美裸体一区二区三区| 亚洲精品日日夜夜| 99视频有精品| 欧美国产精品中文字幕| 久久 天天综合| 欧美精品电影在线播放| 一区二区三区在线播| a4yy欧美一区二区三区| 国产精品免费丝袜| 国产一区免费电影| 欧美白人最猛性xxxxx69交| 日产欧产美韩系列久久99| 欧美日韩dvd在线观看| 亚洲成人av中文| 欧美三级一区二区| 一区二区三区不卡视频| 在线中文字幕不卡| 亚洲人成精品久久久久久| 91视频.com| 一区二区三区欧美| 日本道在线观看一区二区| 一区二区三区在线视频播放| 欧美三区在线观看| 婷婷中文字幕综合| 91精品国产一区二区三区蜜臀| 日韩不卡在线观看日韩不卡视频| 欧美日本韩国一区二区三区视频 | 精品国产一区二区三区久久影院| 蜜桃视频第一区免费观看| 91精品国产日韩91久久久久久| 丝袜美腿亚洲一区| 日韩午夜激情av| 国产老妇另类xxxxx| 欧美激情一区二区三区在线| 成人黄色av网站在线| 亚洲视频 欧洲视频| 欧美影院一区二区| 狂野欧美性猛交blacked| 久久精品免视看| 色综合亚洲欧洲| 亚洲777理论| 精品国产区一区| 不卡的电视剧免费网站有什么| 一区二区三区四区在线| 91麻豆精品国产91久久久使用方法 | 在线观看国产日韩| 久久国产日韩欧美精品| 国产精品久久久久久久久晋中| 日本久久电影网| 久久精品72免费观看| 欧美激情艳妇裸体舞|