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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? nwk.c

?? zigbee 2004協(xié)議棧
?? C
?? 第 1 頁 / 共 2 頁
字號:
/*

 V0.1 Initial Release   10/July/2006
 *
 */

/*
V0.21 Fixed problem in nwkCopyFwdPkt relating to copying of the radius byte
       27/July/2006
V0.2 added PC-based binding         21/July/2006
V0.1 Initial Release                10/July/2006

*/


/*
Network Layer


*/

#include "compiler.h"
#include "lrwpan_config.h"         //user configurations
#include "lrwpan_common_types.h"   //types common acrosss most files
#include "ieee_lrwpan_defs.h"
#include "console.h"
#include "debug.h"
#include "memalloc.h"
#include "neighbor.h"
#include "hal.h"
#include "halStack.h"
#include "phy.h"
#include "mac.h"
#include "nwk.h"
#include "aps.h"

#include "neighbor.h"



typedef enum _NWK_RXSTATE_ENUM {
	NWK_RXSTATE_IDLE,
	NWK_RXSTATE_START,
	NWK_RXSTATE_APS_HANDOFF,
	NWK_RXSTATE_DOROUTE
} NWK_RXSTATE_ENUM;

static NWK_RXSTATE_ENUM nwkRxState;
static void nwkParseHdr(BYTE *ptr);


NWK_SERVICE a_nwk_service;
NWK_STATE_ENUM nwkState;
NWK_RX_DATA a_nwk_rx_data;

BYTE nwkDSN;

NWK_PIB nwk_pib;

static void nwkRxFSM(void);


//locals
#ifndef LRWPAN_COORDINATOR
static UINT32 nwk_utility_timer;   //utility timer
static UINT8 nwk_retries;       //utility retry counter
#endif

#ifdef LRWPAN_FFD
void nwkCopyFwdPkt(void);
static BOOL nwkRxBuffFull(void);
static BOOL nwkRxBuffEmpty(void);
static NWK_FWD_PKT *nwkGetRxPacket(void);
static void nwkFreeRxPacket(BOOL freemem);
#endif



//there can only be one TX in progress at a time, so
//a_aps_tx_data contains the arguments for that TX on the NWK layer.
NWK_TX_DATA a_nwk_tx_data;

void nwkTxData(BOOL fwdFlag);

void nwkInit(void){
	nwkDSN = 0;
	nwk_pib.flags.val = 0;
	nwkState = NWK_STATE_IDLE;
	nwkRxState= NWK_RXSTATE_IDLE;
#ifdef LRWPAN_FFD
	nwk_pib.rxTail = 0;
	nwk_pib.rxHead = 0;
#endif
}

void nwkFSM(void){



	macFSM();
	nwkRxFSM();

nwkFSM_start:

	switch (nwkState) {
	 case NWK_STATE_IDLE:
#ifdef LRWPAN_FFD
		 //see if we have packets to forward and can grab the TX buffer
		 if (!nwkRxBuffEmpty() && phyTxUnLocked()) {

			 //grab the lock and forward the packet
			 phyGrabTxLock();
			 nwkCopyFwdPkt();
			 //transmit it
			 nwkTxData(TRUE); //use TRUE as this is a forwarded packet
			 nwkState = NWK_STATE_FWD_WAIT;

		 }

#endif
		 break;

	 case NWK_STATE_COMMAND_START:
		 switch(a_nwk_service.cmd) {
	 case LRWPAN_SVC_NWK_GENERIC_TX:
		 //at this point, need to check  if INDIRECT or DIRECT, take action
		 //send a generic packet with arguments specified by upper level
		 //this assumes the upper level has grabbed the TX buffer lock
		 nwkTxData(FALSE);
		 nwkState = NWK_STATE_GENERIC_TX_WAIT;
		 break;
#ifdef LRWPAN_COORDINATOR
	 case LRWPAN_SVC_NWK_FORM_NETWORK:
		 //if forming network, restart everything
		 //if we are forming a network, then we need to restart
		 //the PHY, MAC layers from scratch
		 phyInit();
		 macInit();

		 ntInitTable();  //init neighbor table

		 a_nwk_service.status = macInitRadio();  //turns on the radio
		 if (a_nwk_service.status != LRWPAN_STATUS_SUCCESS) {
			 DEBUG_STRING(DBG_ERR, "NWK Formation failed!\n");
			 nwkState = NWK_STATE_IDLE;
			 break;
		 }

		 //this is where we form a network.
		 nwkState = NWK_STATE_FORM_NETWORK_START;

		 goto nwkFSM_start;
#else

	 case LRWPAN_SVC_NWK_JOIN_NETWORK:
		 // see if this is a rejoin or join
		 if (a_nwk_service.args.join_network.RejoinNetwork) {
			 mac_pib.flags.bits.macIsAssociated = 0; //if doing rejoin, unsure of association, clear it.
			 nwkState = NWK_STATE_REJOIN_NETWORK_START;
			 goto nwkFSM_start;  //do not do any other initialization
		 }
		 else nwkState = NWK_STATE_JOIN_NETWORK_START;
		 //if joining/rejoining network, restart everything
		 //if we are forming a network, then we need to restart
		 //the PHY, MAC layers from scratch
		 phyInit();
		 macInit();
#ifdef LRWPAN_FFD
		 ntInitTable();  //init neighbor table
#endif

		 a_nwk_service.status = macInitRadio();  //turns on the radio
		 if (a_nwk_service.status != LRWPAN_STATUS_SUCCESS) {
			 DEBUG_STRING(DBG_ERR, "NWK JOIN/REJOIN failed!\n");
			 nwkState = NWK_STATE_IDLE;
			 break;
		 }

		 goto nwkFSM_start;
#endif



	 default: break;

		 }//end switch(a_nwk_service.cmd)

	 case NWK_STATE_GENERIC_TX_WAIT:
		 if (macBusy()) break;
		 //mac finished, copy status.
		 a_nwk_service.status = a_mac_service.status;
		 nwkState = NWK_STATE_IDLE;
		 break;


#ifdef LRWPAN_FFD
	 case NWK_STATE_FWD_WAIT:
		 if (macBusy()) break;
		 //mac finished, this is only used for fwding packets
		 //will ignore status for now since there is not much
		 //can do about it. Eventally, with more advanced routing,
		 // will record the status of this link and try an alternate
		 //route on failure.
		 phyReleaseTxLock(); //release the lock
		 nwkState = NWK_STATE_IDLE;
		 break;
#endif

	 case NWK_STATE_REJOIN_NETWORK_START:
		 if (macBusy()) break;
		 //send an orphan notification
		 a_mac_service.cmd = LRWPAN_SVC_MAC_ORPHAN_NOTIFY;
		 nwkState = NWK_STATE_REJOIN_WAIT;
		 macDoService();
		 break;

	 case NWK_STATE_REJOIN_WAIT:
		 if (macBusy()) break;
		 //at this point, rejoin is finished, get status
		 a_nwk_service.status = a_mac_service.status;
		 nwkState = NWK_STATE_IDLE;
		 break;

#ifdef LRWPAN_COORDINATOR
	 case NWK_STATE_FORM_NETWORK_START:

		 //here is where we would scan the channels, etc.
		 //instead, we will just set the channel, and indicate
		 //that the network is formed, and init the neighbor table.
		 macSetPANID(a_nwk_service.args.form_network.PANid);
		 macSetChannel(LRWPAN_DEFAULT_START_CHANNEL);
		 macSetShortAddr(0);
		 //initialize address assignment, must be done after the
		 //short address is set
		 ntInitAddressAssignment();


		 //add ourselves to the
		 nwk_pib.flags.bits.nwkFormed = 1;
		 mac_pib.flags.bits.macIsAssociated = 1; //I am associated with myself!
		 //tell MAC to allow association
		 mac_pib.flags.bits.macAssociationPermit = 1;
		 a_nwk_service.status = LRWPAN_STATUS_SUCCESS;

		 nwkState = NWK_STATE_IDLE;
		 break;

#endif
#ifndef LRWPAN_COORDINATOR
	 case NWK_STATE_JOIN_NETWORK_START:
		 //if trying to join, do not allow association
		 mac_pib.flags.bits.macAssociationPermit = 0;

#ifdef LRWPAN_FORCE_ASSOCIATION_TARGET
		 //if forcing association to particular target, skip beacon request
		 //go to state that will start forced association, selecting channels
		 nwkState = NWK_STATE_JOIN_MAC_ASSOC_CHANSELECT;
#else
		 //select a channel
		 a_mac_service.args.beacon_req.LogicalChannel = LRWPAN_DEFAULT_START_CHANNEL;
		 //set retries
		 //we always send out at least three BEACON req to make
		 //sure that we adequately poll everybody in the region
		 nwk_retries = NWK_GENERIC_RETRIES;
		 mac_pib.bcnDepth = 0xFF;  //initialze the beacon depth response
		 //start the request
		 nwkState = NWK_STATE_JOIN_SEND_BEACON_REQ;
#endif
		 goto nwkFSM_start;

	 case NWK_STATE_JOIN_SEND_BEACON_REQ:
		 //at this point, we would start scanning channels
		 //sending out beacon requests on each channel
		 // we will only send out a beacon on the default channel, instead of scanning
		 if (macBusy()) break;
		 a_mac_service.cmd = LRWPAN_SVC_MAC_BEACON_REQ;
		 nwkState = NWK_STATE_JOIN_NWK_WAIT1_BREQ;
		 macDoService();
		 break;

		 //waits for BCN request TX to finish
	 case NWK_STATE_JOIN_NWK_WAIT1_BREQ:
		 if (macBusy()) break;
		 //at this point, the packet has been sent. Now have
		 //to wait for a response. Record
		 nwk_utility_timer = halGetMACTimer();
		 nwkState =NWK_STATE_JOIN_NWK_WAIT2_BREQ;
		 break;

	 case NWK_STATE_JOIN_NWK_WAIT2_BREQ:
		 //wait for either a BCN response or timeout.
		 if (mac_pib.flags.bits.GotBeaconResponse) {
			 //we have received a BCN response. Try joining this node

			 //for right now just print out debug message
			 DEBUG_STRING(DBG_INFO,"Got BCN Response\n");
			 //keep trying, want to poll everybody in range
			 //and pick the closest one
			 mac_pib.flags.bits.GotBeaconResponse = 0;
		 }else if (halMACTimerNowDelta(nwk_utility_timer)> MSECS_TO_MACTICKS(LRWPAN_NWK_JOIN_WAIT_DURATION) ) {
			 if (nwk_retries) nwk_retries--;
			 if (nwk_retries) {
				 //retry Beacon Request
				 nwkState = NWK_STATE_JOIN_SEND_BEACON_REQ;
				 goto nwkFSM_start;
			 }else
			 {
				 //out of retries, check bcnDepth
				 if ( mac_pib.bcnDepth != 0xFF) {
					 //we got a response, so lets try to join
					 nwkState = NWK_STATE_JOIN_MAC_ASSOC;
					 //use the same channel
					 a_mac_service.args.assoc_req.LogicalChannel  = a_mac_service.args.beacon_req.LogicalChannel;
					 DEBUG_STRING(DBG_INFO,"NWK trying association\n");
				 }else {
					 //indicate failure
					 DEBUG_STRING(DBG_INFO,"NWK Join Timeout\n");
					 a_nwk_service.status = LRWPAN_STATUS_NWK_JOIN_TIMEOUT;
					 nwkState = NWK_STATE_IDLE;
				 }

				 //clear flags
				 mac_pib.flags.bits.GotBeaconResponse = 0;
				 mac_pib.flags.bits.WaitingForBeaconResponse = 0;
			 }
		 }
		 break;

	 case NWK_STATE_JOIN_MAC_ASSOC_CHANSELECT:
		 //this will eventually scan channels, for now, just select default
		 a_mac_service.args.assoc_req.LogicalChannel = LRWPAN_DEFAULT_START_CHANNEL;
		 nwkState = NWK_STATE_JOIN_MAC_ASSOC;
		 goto nwkFSM_start;

	 case NWK_STATE_JOIN_MAC_ASSOC:
		 //do association to PANID discovered by beacon request
		 if (macBusy()) break;
		 a_mac_service.cmd = LRWPAN_SVC_MAC_ASSOC_REQ;
		 nwkState = NWK_STATE_JOIN_MAC_ASSOC_WAIT;
		 macDoService();

		 break;

	 case NWK_STATE_JOIN_MAC_ASSOC_WAIT:
		 if (macBusy()) break;
		 //at this point, association is finished, get status
		 a_nwk_service.status = a_mac_service.status;
#ifdef LRWPAN_FFD
		 if (a_nwk_service.status == LRWPAN_STATUS_SUCCESS) {
			 //as a router, initialize address assignment and
			 //begin allowing association
			 ntInitAddressAssignment();
			 mac_pib.flags.bits.macAssociationPermit = 1;
		 }
#endif
		 nwkState = NWK_STATE_IDLE;
		 break;

#endif


		 //these states for FORM NETWORK
	 default:  break;


	}//end switch(nwkState)


}

//Add the NWK header, then send it to MAC
//if fwdFlag is true, then packet is being forwarded, so nwk header
//is already in place, and assume that currentTxFrm and currentTxPLen
//are correct as well, and that the radius byte has been decremented.
void nwkTxData(BOOL fwdFlag) {



	//if we are not associated, don't bother sending NWK packet
	if (!mac_pib.flags.bits.macIsAssociated) {
		//call a dummy service that just returns an error code
		//have to do it this way since the caller is expecting a
		//mac service call
		a_mac_service.args.error.status = LRWPAN_STATUS_MAC_NOT_ASSOCIATED;
		a_mac_service.cmd = LRWPAN_SVC_MAC_ERROR;
		goto nwkTxData_sendit;
	}

	if (a_nwk_tx_data.radius == 0) {
		DEBUG_STRING(DBG_ERR,"Nwk Radius is zero, discarding packet.\n");
		//can no longer forward this packet.
		a_mac_service.args.error.status =  LRWPAN_STATUS_NWK_RADIUS_EXCEEDED;
		a_mac_service.cmd = LRWPAN_SVC_MAC_ERROR;
		goto nwkTxData_sendit;
	}


	if (fwdFlag) goto nwkTxData_addmac;
	//sequence number
	--phy_pib.currentTxFrm;
	*phy_pib.currentTxFrm = nwkDSN;
	nwkDSN++;

	//radius, decrement before sending, receiver will
	//get a value that is one less than this node.
	--phy_pib.currentTxFrm;
	*phy_pib.currentTxFrm = (--a_nwk_tx_data.radius);

	//src address
	--phy_pib.currentTxFrm;
	*phy_pib.currentTxFrm = (BYTE) (a_nwk_tx_data.srcSADDR >> 8);
	--phy_pib.currentTxFrm;
	*phy_pib.currentTxFrm = (BYTE) (a_nwk_tx_data.srcSADDR);

	//dst address
	--phy_pib.currentTxFrm;
	*phy_pib.currentTxFrm = (BYTE) (a_nwk_tx_data.dstSADDR >> 8);

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美群妇大交群的观看方式| 国产一区二区精品在线观看| 欧美综合亚洲图片综合区| 自拍偷拍欧美激情| 欧美色大人视频| 五月综合激情婷婷六月色窝| 欧美一区二区三区的| 久久国产成人午夜av影院| 久久精品视频在线免费观看| 成人不卡免费av| 亚洲另类一区二区| 777xxx欧美| 国产成人免费视频网站| 国产一区二区三区香蕉| 欧美岛国在线观看| 国产成人av资源| 亚洲视频免费看| 欧美日韩国产精品成人| 国产精品性做久久久久久| 国产精品的网站| 91精品国产综合久久婷婷香蕉| 久久福利资源站| √…a在线天堂一区| 欧美日韩电影在线播放| 国产精品一区二区x88av| 亚洲免费色视频| 日韩一区二区电影网| 丁香亚洲综合激情啪啪综合| 亚洲午夜精品一区二区三区他趣| 日韩免费观看高清完整版| www.亚洲激情.com| 丝袜美腿亚洲色图| 国产精品网站在线播放| 3d成人动漫网站| 波多野结衣91| 久草精品在线观看| 亚洲乱码国产乱码精品精98午夜| 欧美一区二区免费视频| 91视视频在线观看入口直接观看www| 亚洲va中文字幕| 国产精品亲子乱子伦xxxx裸| 欧美一区二区三区视频免费| 91在线视频网址| 激情都市一区二区| 亚洲成av人片在线| 中文字幕日韩av资源站| 精品999在线播放| 欧美三级午夜理伦三级中视频| 国产成人综合亚洲91猫咪| 天堂久久一区二区三区| 自拍偷在线精品自拍偷无码专区| 欧美一个色资源| 欧美亚洲丝袜传媒另类| www.日韩在线| 国产一区二区三区| 麻豆成人91精品二区三区| 亚洲激情一二三区| 中文字幕制服丝袜成人av| 2021国产精品久久精品| 在线成人免费观看| 91黄色免费看| eeuss鲁一区二区三区| 国产主播一区二区| 蜜桃视频一区二区| 亚洲成在线观看| 亚洲一区二区在线免费观看视频| 亚洲欧洲日产国码二区| 中文字幕av不卡| 久久综合成人精品亚洲另类欧美| 亚洲欧美日韩久久| 综合中文字幕亚洲| 自拍偷拍国产亚洲| √…a在线天堂一区| 国产精品美女视频| 国产精品视频一二| 国产精品伦理在线| 国产精品毛片无遮挡高清| 国产欧美一区二区精品性色 | 国产毛片精品一区| 精品一区二区免费视频| 九九视频精品免费| 韩国精品主播一区二区在线观看| 日韩激情视频网站| 久久99精品国产91久久来源| 精东粉嫩av免费一区二区三区| 狠狠色丁香久久婷婷综合_中 | 国产麻豆成人传媒免费观看| 国产激情精品久久久第一区二区 | 欧美一级专区免费大片| 4438成人网| 日韩女同互慰一区二区| 久久一区二区三区国产精品| 国产欧美一区二区精品秋霞影院 | 亚洲欧美日韩久久| 亚洲午夜电影网| 视频一区欧美日韩| 国产一区啦啦啦在线观看| 丁香网亚洲国际| 色av综合在线| 3d成人h动漫网站入口| 2022国产精品视频| 亚洲欧洲另类国产综合| 亚洲精品一二三四区| 日韩高清一区在线| 国产精品性做久久久久久| 91原创在线视频| 69av一区二区三区| 国产免费成人在线视频| 亚洲自拍偷拍九九九| 日本色综合中文字幕| 国产精品一二三四区| 91亚洲精品乱码久久久久久蜜桃| 欧美美女一区二区| 国产亚洲va综合人人澡精品| 亚洲黄一区二区三区| 日本欧美大码aⅴ在线播放| 极品尤物av久久免费看| 91国模大尺度私拍在线视频| 日韩视频一区二区| 日韩码欧中文字| 首页综合国产亚洲丝袜| 粉嫩一区二区三区性色av| 欧美卡1卡2卡| 国产精品视频一二| 老鸭窝一区二区久久精品| 一本一道综合狠狠老| 久久综合九色欧美综合狠狠| 亚洲一区二区精品久久av| 国产精品一线二线三线| 欧美美女喷水视频| 亚洲欧美在线视频观看| 蜜桃传媒麻豆第一区在线观看| www.日韩大片| 久久伊人蜜桃av一区二区| 亚洲综合丝袜美腿| 成人性生交大片免费看在线播放| 宅男在线国产精品| 亚洲精品视频在线观看免费 | 中文字幕日韩精品一区| 久久精品国产精品青草| 欧美日韩国产综合视频在线观看| 国产精品久久久久精k8 | 亚洲国产精品二十页| 美女视频黄久久| 欧美日韩一区三区| 一个色妞综合视频在线观看| 国产suv一区二区三区88区| 日韩三级在线观看| 丝袜美腿亚洲一区二区图片| 在线免费视频一区二区| 中文字幕一区二区三| 风间由美一区二区av101| 精品剧情在线观看| 老司机午夜精品99久久| 91.com视频| 日韩成人免费在线| 欧美精品在线观看播放| 亚洲成人第一页| 欧美日韩综合不卡| 亚洲成av人片在线观看无码| 欧美在线你懂的| 亚洲小说欧美激情另类| 日本久久一区二区三区| 亚洲三级视频在线观看| 99麻豆久久久国产精品免费| 国产精品传媒入口麻豆| 成人性色生活片免费看爆迷你毛片| 精品国产欧美一区二区| 国产一区久久久| 国产色一区二区| av在线综合网| 亚洲毛片av在线| 在线观看日韩精品| 亚洲动漫第一页| 5566中文字幕一区二区电影| 蜜臀国产一区二区三区在线播放| 日韩视频在线一区二区| 精品一区二区三区影院在线午夜 | aaa欧美色吧激情视频| 国产精品国产三级国产aⅴ无密码| 成人深夜在线观看| 亚洲男女一区二区三区| 欧美网站大全在线观看| 偷拍日韩校园综合在线| 欧美变态tickling挠脚心| 国产剧情一区二区| 国产精品久久久久久久久久免费看 | 日韩一级高清毛片| 国产精品自拍一区| 国产精品久久久久四虎| 欧美视频在线观看一区二区| 免费在线视频一区| 久久久噜噜噜久久中文字幕色伊伊| 粉嫩在线一区二区三区视频| 一区二区三区四区精品在线视频 | 色猫猫国产区一区二在线视频| 亚洲午夜羞羞片| 精品乱人伦一区二区三区| 成人av网站在线观看| 午夜伦理一区二区|