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

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

?? nwk.c

?? 語言為C語言
?? 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一区二区三区免费野_久草精品视频
国产白丝网站精品污在线入口| 亚洲影视资源网| 精品国产青草久久久久福利| 欧美日韩亚洲国产综合| 国产成a人无v码亚洲福利| 麻豆91在线观看| 国产在线精品一区在线观看麻豆| 亚洲国产一区在线观看| 亚洲精品在线观看网站| 国产精品二三区| 一级中文字幕一区二区| 日韩一区二区电影在线| 成人动漫av在线| 成人app软件下载大全免费| 99re这里只有精品首页| 91蜜桃视频在线| 日本乱人伦一区| 欧美日韩一本到| 精品91自产拍在线观看一区| 久久精品综合网| 亚洲精品久久久久久国产精华液| 亚洲三级电影网站| 日本女人一区二区三区| 日本欧洲一区二区| 国内外成人在线| av一二三不卡影片| 欧美一区二区三区在线视频| 久久久五月婷婷| 天天色综合天天| 麻豆久久久久久| 色婷婷综合久久久中文字幕| 日韩欧美色综合| 亚洲欧美日韩在线| 激情综合网最新| 成人激情开心网| 在线精品视频免费观看| 久久精品一区二区三区不卡牛牛 | 69堂精品视频| 日韩一区二区在线观看视频| 国产欧美一区二区在线| 免费看黄色91| 欧美日韩国产首页| 夜夜亚洲天天久久| 老鸭窝一区二区久久精品| 色噜噜狠狠色综合中国| 国产精品久久一级| 99精品在线免费| 国产亚洲成aⅴ人片在线观看| 日韩精品乱码av一区二区| 色婷婷久久综合| 亚洲激情图片小说视频| 色综合久久中文字幕综合网| 国产精品久久久久四虎| 国产在线视频一区二区三区| 久久久综合视频| 国产精品资源网站| 日韩一卡二卡三卡四卡| 天天影视色香欲综合网老头| 欧美精品高清视频| 麻豆极品一区二区三区| 久久亚洲一区二区三区四区| 国产精品一级黄| 亚洲激情一二三区| 一本色道a无线码一区v| 日本不卡123| 久久久久九九视频| 日本韩国一区二区三区视频| 亚洲久本草在线中文字幕| 成人av动漫网站| 欧美中文字幕一区二区三区| 国产精品丝袜一区| 色偷偷成人一区二区三区91| 国产精品狼人久久影院观看方式| 成人99免费视频| 久久久高清一区二区三区| 99久久伊人精品| 一区二区三区日本| 日韩视频免费观看高清在线视频| 国产精品99久| 亚洲日本中文字幕区| 久久噜噜亚洲综合| 3d成人h动漫网站入口| 97精品电影院| 国产电影一区二区三区| 亚洲成人在线免费| 中文字幕一区二区视频| 久久综合久久99| 欧美精品久久天天躁| 成人永久aaa| 国产在线播放一区二区三区| 亚洲一区二区三区精品在线| 亚洲综合成人在线| 午夜视频在线观看一区二区三区| 亚洲国产视频直播| 免费在线一区观看| 国产成人在线免费观看| 成人a级免费电影| 欧美日韩久久不卡| 337p粉嫩大胆噜噜噜噜噜91av | 亚洲欧美在线aaa| 一区二区三区欧美日| 日本伊人色综合网| 福利一区在线观看| 欧美色区777第一页| 久久久久九九视频| 亚洲午夜国产一区99re久久| 五月激情六月综合| 看电视剧不卡顿的网站| youjizz国产精品| 欧美日韩国产高清一区二区| 精品美女在线播放| 亚洲一二三四区| 成人影视亚洲图片在线| 91精品国产高清一区二区三区蜜臀| 2020日本不卡一区二区视频| 亚洲综合色噜噜狠狠| 成人白浆超碰人人人人| 精品久久一二三区| 日本欧美一区二区三区乱码| 99久久精品免费| 欧美经典三级视频一区二区三区| 日韩影院在线观看| 99久久综合狠狠综合久久| 国产日韩欧美麻豆| 国产麻豆视频一区| 久久免费美女视频| 国产在线播放一区二区三区| 日韩亚洲欧美成人一区| 日本亚洲天堂网| 欧美一区二区在线观看| 日韩高清不卡在线| 日韩一区二区电影| 国产一区二区按摩在线观看| 精品国产伦理网| 国产成人小视频| 中文字幕一区免费在线观看| 99精品久久久久久| 亚洲综合色成人| 欧美疯狂性受xxxxx喷水图片| 日韩精品一级二级 | 91麻豆文化传媒在线观看| 久久久美女艺术照精彩视频福利播放| 毛片一区二区三区| 国产亚洲精品精华液| 91色九色蝌蚪| 毛片不卡一区二区| 亚洲免费观看高清完整版在线| 一本一本大道香蕉久在线精品| 亚洲国产一二三| 久久久久久久久久久久久夜| 成人手机电影网| 亚洲成年人影院| 日本一区二区成人| 日韩一区二区三区四区五区六区| 国产不卡在线视频| 免费成人结看片| 亚洲美女视频在线| 久久久www成人免费无遮挡大片| 91老师国产黑色丝袜在线| 蜜臀91精品一区二区三区| 国产色一区二区| 91精品视频网| 91极品视觉盛宴| 懂色av一区二区在线播放| 亚洲国产aⅴ成人精品无吗| 欧美国产亚洲另类动漫| 欧美一区二区三区视频在线观看| 成人一道本在线| 大尺度一区二区| 国产在线视频精品一区| 丝袜诱惑亚洲看片| 午夜精品免费在线观看| 亚洲午夜免费福利视频| 亚洲激情图片一区| 亚洲一级在线观看| 视频一区中文字幕国产| 亚洲精品少妇30p| 一区二区三区四区亚洲| 樱桃国产成人精品视频| 亚洲乱码一区二区三区在线观看| 亚洲欧洲国产日本综合| 最新国产精品久久精品| 欧美激情一区三区| 亚洲色图在线看| 亚洲午夜视频在线| 久久精品国产久精国产| 久久av中文字幕片| 成人福利视频在线看| 欧美羞羞免费网站| 欧美成人一区二区三区片免费| 日韩精品在线网站| 国产精品九色蝌蚪自拍| 天堂久久一区二区三区| 韩国精品主播一区二区在线观看| 丁香网亚洲国际| 欧美另类久久久品| 国产免费成人在线视频| 婷婷综合五月天| 色综合天天视频在线观看| 91麻豆精品国产91|