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

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

?? mac.c

?? ZIGBEE2006協議棧
?? C
?? 第 1 頁 / 共 4 頁
字號:
/*
 V0.1 Initial Release   10/July/2006
 *
 */

/*
V0.21 fixed problem in OrphanResponse, was not copying the parent's
long address                         27/July/2006

V0.2  added PC-based binding         21/July/2006
V0.1  Initial Release                10/July/2006

*/


#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 "hal.h"
#include "halStack.h"
#include "phy.h"
#include "mac.h"
#include "nwk.h"

#include "neighbor.h"


typedef enum _MAC_RXSTATE_ENUM {
  MAC_RXSTATE_IDLE,
  MAC_RXSTATE_NWK_HANDOFF,
  MAC_RXSTATE_CMD_PENDING
} MAC_RXSTATE_ENUM;

static MAC_RXSTATE_ENUM macRxState;

MAC_PIB mac_pib;
MAC_SERVICE a_mac_service;
MAC_STATE_ENUM macState;



//there can only be one TX in progress at a time, so
//a_mac_tx_data contains the arguments for that TX.
MAC_TX_DATA a_mac_tx_data;

//this is used for parsing of current packet.
MAC_RX_DATA a_mac_rx_data;

LRWPAN_STATUS_ENUM macTxFSM_status;


//locals
static UINT32 mac_utility_timer;   //utility timer

//local functions
static void macTxData(void);
static void macTxFSM(void);
static void macParseHdr(void);
static void macRxFSM(void);
static void macParseBeacon(void);
static void macFormatAssocRequest(void);
static BOOL macCheckDataRejection(void);
static void macFormatOrphanNotify(void);


#ifndef LRWPAN_COORDINATOR
static void macParseOrphanResponse(void);
#endif


#ifdef LRWPAN_FFD
static void macFormatBeacon(void);
static void macFormatAssociationResponse(void);
static void macFormatCoordRealign(SADDR orphan_saddr);
#endif

#ifndef LRWPAN_COORDINATOR
static void macParseAssocResponse(void);
#endif

//does not turn on radio.
void macInit(void){
  macState = MAC_STATE_IDLE;
  macRxState = MAC_RXSTATE_IDLE;
  mac_pib.macCoordShortAddress = 0;
  mac_pib.flags.val = 0;
  mac_pib.rxTail = 0;
  mac_pib.rxHead = 0;
  mac_pib.macPANID = LRWPAN_DEFAULT_PANID;
  mac_pib.macMaxAckRetries = aMaxFrameRetries;
  ntInitAddressMap();  //init the address map
#ifdef LRWPAN_COORDINATOR
  mac_pib.depth = 0;
#else
  mac_pib.depth = 1; //depth will be at least one
#endif
  mac_pib.bcnDepth = 0xFF; //remembers depth of node that responded to beacon
  //other capability information
  mac_pib.macCapInfo = 0;
#ifdef LRWPAN_ALT_COORDINATOR     //not supported, included for completeness
  LRWPAN_SET_CAPINFO_ALTPAN(mac_pib.macCapInfo);
#endif
#ifdef LRWPAN_FFD
  LRWPAN_SET_CAPINFO_DEVTYPE(mac_pib.macCapInfo);
#endif
#ifdef LRWPAN_ACMAIN_POWERED
  LRWPAN_SET_CAPINFO_PWRSRC(mac_pib.macCapInfo);
#endif
#ifdef LRWPAN_RCVR_ON_WHEN_IDLE
  LRWPAN_SET_CAPINFO_RONIDLE(mac_pib.macCapInfo);
#endif
#ifdef LRWPAN_SECURITY_CAPABLE
  LRWPAN_SET_CAPINFO_SECURITY(mac_pib.macCapInfo);
#endif
  //always allocate a short address
  LRWPAN_SET_CAPINFO_ALLOCADDR(mac_pib.macCapInfo);


}

LRWPAN_STATUS_ENUM macWarmStartRadio(void){
 halWarmstart();
 a_phy_service.cmd = LRWPAN_SVC_PHY_INIT_RADIO; //no args
  a_phy_service.args.phy_init_radio_args.radio_flags.bits.listen_mode = 0;
#ifdef LRWPAN_COORDINATOR
  a_phy_service.args.phy_init_radio_args.radio_flags.bits.pan_coordinator = 1;
#else
  a_phy_service.args.phy_init_radio_args.radio_flags.bits.pan_coordinator = 0;
#endif
  phyDoService();
  halSetChannel(phy_pib.phyCurrentChannel);
  halSetRadioPANID(mac_pib.macPANID); //listen on this PANID
  halSetRadioShortAddr(macGetShortAddr());  //non-broadcast, reserved
  return(a_phy_service.status);
}

//this assumes that phyInit, macInit has previously been called.
//turns on the radio

LRWPAN_STATUS_ENUM macInitRadio(void) {

  phy_pib.phyCurrentFrequency = LRWPAN_DEFAULT_FREQUENCY;
  phy_pib.phyCurrentChannel = LRWPAN_DEFAULT_START_CHANNEL;
  if (phy_pib.phyCurrentChannel < 11){
    mac_pib.macAckWaitDuration = SYMBOLS_TO_MACTICKS(120);
  }
  else {
    mac_pib.macAckWaitDuration = SYMBOLS_TO_MACTICKS(54);
  }

  a_phy_service.cmd = LRWPAN_SVC_PHY_INIT_RADIO; //no args
  a_phy_service.args.phy_init_radio_args.radio_flags.bits.listen_mode = 0;
#ifdef LRWPAN_COORDINATOR
  a_phy_service.args.phy_init_radio_args.radio_flags.bits.pan_coordinator = 1;
#else
  a_phy_service.args.phy_init_radio_args.radio_flags.bits.pan_coordinator = 0;
#endif

  phyDoService();
#ifdef LRWPAN_USE_STATIC_PANID
  halSetRadioPANID(LRWPAN_DEFAULT_PANID); //listen on this PANID
#else
  halSetRadioPANID(0xFFFF);      //broadcast
#endif
  halSetRadioShortAddr(0xFFFE);  //non-broadcast, reserved
  return(a_phy_service.status);
}

void macSetPANID(UINT16 panid){
  mac_pib.macPANID = panid;
  halSetRadioPANID(mac_pib.macPANID);
}


void macSetChannel(BYTE channel){
  phy_pib.phyCurrentChannel = channel;
  halSetChannel(channel);
}

void macSetShortAddr(UINT16 saddr) {
#ifdef LRWPAN_RFD
	//when changing the short address for an RFD, always clear the map first
	//since the short address may have changed.
	//for RFDs, there is only one entry
	ntInitAddressMap();
#endif
  ntAddOurselvesToAddressTable(saddr);
  halSetRadioShortAddr(saddr);
}



void macFSM(void) {

  BYTE cmd;
#ifdef LRWPAN_FFD
  NAYBORENTRY *nt_ptr;
#endif


#ifdef LRWPAN_DEBUG
  //assume 2.4 GHZ
  if (debug_level == 0) {
    mac_pib.macAckWaitDuration = SYMBOLS_TO_MACTICKS(54);
  } else {
    mac_pib.macAckWaitDuration = SYMBOLS_TO_MACTICKS(270);  //give longer due to debug output
  }
#endif

  phyFSM();
  //if TxFSM is busy we need to call it
  if (macTXBusy()) macTxFSM();

  macRxFSM();

#ifdef LRWPAN_FFD
macFSM_start:
#endif

  //check background tasks here

  switch (macState) {
	 case MAC_STATE_IDLE:
           if (mac_pib.flags.bits.macPending ) {
             //there is a MAC CMD packet pending in the RX buffer. Handle it.
             cmd = *(a_mac_rx_data.orgpkt->data + a_mac_rx_data.pload_offset);
             switch (cmd) {
             case LRWPAN_MACCMD_BCN_REQ:
               //Beacon Request
#ifdef LRWPAN_RFD
               //as an RFD, I do not handle this. Release this.
               mac_pib.flags.bits.macPending = 0;
#else
               //as a Coordinator or Router, I will only respond
               //only respond if association permitted
               //as this is the stack's only use of beacons
               if (mac_pib.flags.bits.macAssociationPermit) {
                 //will keep spinning through here until TX buffer unlocked
                 if (phyTxUnLocked()) {
                   phyGrabTxLock(); //grab the lock
                   macState = MAC_STATE_SEND_BEACON_RESPONSE;
                   mac_pib.flags.bits.macPending = 0; //release packet
                   goto macFSM_start;
                 }
               }else {
                 //release packet.
                 mac_pib.flags.bits.macPending = 0;
               }


#endif
               break;

			 case LRWPAN_MACCMD_ORPHAN:
               //Orphan Notify
#ifdef LRWPAN_RFD
               //as an RFD, I do not handle this. Release this.
               mac_pib.flags.bits.macPending = 0;
#else
             //will keep spinning through here until TX buffer unlocked
               if (phyTxUnLocked()) {
                   phyGrabTxLock(); //grab the lock
                   macState = MAC_STATE_HANDLE_ORPHAN_NOTIFY;
                   mac_pib.flags.bits.macPending = 0; //release packet
                   goto macFSM_start;
                }
#endif
             case LRWPAN_MACCMD_ASSOC_REQ:
               //Association Request
#ifdef LRWPAN_RFD
               //as an RFD, I do not handle this. Release this.
               mac_pib.flags.bits.macPending = 0;
#else
               //as a Coordinator or Router, I can respond
               //only respond if association permitted
               if (mac_pib.flags.bits.macAssociationPermit) {
                 //will keep spinning through here until TX buffer unlocked
                 if (phyTxUnLocked()) {
                   phyGrabTxLock(); //grab the lock
                   macState = MAC_STATE_SEND_ASSOC_RESPONSE;
                   mac_pib.flags.bits.macPending = 0; //release packet
                   goto macFSM_start;
                 }
               }else {
                 //release packet.
                 mac_pib.flags.bits.macPending = 0;
               }
#endif

               break;


             default:
               DEBUG_STRING(1,"MAC: Received MAC CMD that is not currently implemented, discarding.\n");
               mac_pib.flags.bits.macPending = 0;

             }



           }//end if(mac_pib.flags.bits.macPending )

           break;
	 case MAC_STATE_COMMAND_START:
           switch(a_mac_service.cmd) {
	        case LRWPAN_SVC_MAC_ERROR:
				//dummy service, just return the status that was passed in
				a_mac_service.status = a_mac_service.args.error.status;
				macState = MAC_STATE_IDLE;
				break;

           case LRWPAN_SVC_MAC_GENERIC_TX:
             //send a generic packet with arguments specified by upper level
             macTxData();
             macState = MAC_STATE_GENERIC_TX_WAIT;
             break;
           case LRWPAN_SVC_MAC_RETRANSMIT:
             //retransmit the last packet
             //used for frames that are only transmitted once because of no ACK request
             //assumes the TX lock is grabbed, and the TX buffer formatted.
             macSetTxBusy();
             macTxFSM_status = LRWPAN_STATUS_MAC_INPROGRESS;
             a_phy_service.cmd = LRWPAN_SVC_PHY_TX_DATA;
             phyDoService();
             macState = MAC_STATE_GENERIC_TX_WAIT;
             break;
			
		  case LRWPAN_SVC_MAC_ORPHAN_NOTIFY:
              if (phyTxLocked()) break;
              phyGrabTxLock();  //Grab the lock
              //no ack, long SRC, short DST, broadcast PAN
			  a_mac_tx_data.fcflsb = LRWPAN_FRAME_TYPE_MAC;
              a_mac_tx_data.fcfmsb = LRWPAN_FCF_DSTMODE_SADDR|LRWPAN_FCF_SRCMODE_LADDR;
			  a_mac_tx_data.DestAddr.saddr = LRWPAN_BCAST_PANID;
			  a_mac_tx_data.DestPANID = LRWPAN_BCAST_PANID;
			  a_mac_tx_data.SrcPANID = LRWPAN_BCAST_PANID;
			  macFormatOrphanNotify();
			  mac_pib.flags.bits.GotOrphanResponse = 0;
			  mac_pib.flags.bits.WaitingForOrphanResponse = 1;
              macTxData();
			  macState = MAC_STATE_ORPHAN_WAIT1;
		      break;

           case LRWPAN_SVC_MAC_BEACON_REQ:
             //clear Beacon Response Flag
             mac_pib.flags.bits.GotBeaconResponse =0;        //will be set when get response
             //wait for TX lock to send the beacon request
             if (phyTxLocked()) break;
             phyGrabTxLock();  //Grab the lock
             mac_pib.flags.bits.WaitingForBeaconResponse = 1;  //will be cleared when get response
             //set the channel
             halSetChannel(a_mac_service.args.beacon_req.LogicalChannel);
             //stuff the MAC BEACON REQ command into the TX buffer
             phy_pib.currentTxFrm = &tmpTxBuff[LRWPAN_MAX_FRAME_SIZE-1];
             *phy_pib.currentTxFrm = LRWPAN_MACCMD_BCN_REQ;
             phy_pib.currentTxFlen = 1;

             //no MAC ack requested
             a_mac_tx_data.fcflsb = LRWPAN_FRAME_TYPE_MAC|LRWPAN_FCF_INTRAPAN_MASK;
             //using no src address, dst address and PAN are both broadcast address
             a_mac_tx_data.fcfmsb = LRWPAN_FCF_DSTMODE_SADDR|LRWPAN_FCF_SRCMODE_NOADDR;
             a_mac_tx_data.DestAddr.saddr = LRWPAN_BCAST_SADDR;
#ifdef LRWPAN_USE_STATIC_PANID
             //we only want to talk to nodes who use this PANID
             //this is not compliant with 802.15.4
             //we do this to reduce the number of responses, only want routers/coord
             //to respond who use this panid
             a_mac_tx_data.DestPANID = LRWPAN_DEFAULT_PANID;
#else
             //talk to any nodes willing to send us a beacon
             a_mac_tx_data.DestPANID = LRWPAN_BCAST_PANID;
#endif
             macTxData();
             macState = MAC_STATE_GENERIC_TX_WAIT_AND_UNLOCK;
             break;

           case LRWPAN_SVC_MAC_ASSOC_REQ:
             //break if the TXBUFFER is locked
             if (phyTxLocked()) break;
             phyGrabTxLock();  //Grab the lock
             //may want to put this in a function
             halSetChannel(a_mac_service.args.assoc_req.LogicalChannel);
             mac_pib.flags.bits.macIsAssociated = 0;  //clear to zero

             macFormatAssocRequest();

             a_mac_tx_data.fcflsb = LRWPAN_FRAME_TYPE_MAC|LRWPAN_FCF_ACKREQ_MASK;
#ifdef LRWPAN_FORCE_ASSOCIATION_TARGET
             //forced association occurs on DEFAULT PANID
             a_mac_tx_data.fcfmsb = LRWPAN_FCF_DSTMODE_LADDR|LRWPAN_FCF_SRCMODE_LADDR;
             a_mac_tx_data.DestPANID = LRWPAN_DEFAULT_PANID;
             a_mac_tx_data.DestAddr.laddr.bytes[0] = parent_addr_B0;
             a_mac_tx_data.DestAddr.laddr.bytes[1] = parent_addr_B1;
             a_mac_tx_data.DestAddr.laddr.bytes[2] = parent_addr_B2;
             a_mac_tx_data.DestAddr.laddr.bytes[3] = parent_addr_B3;
             a_mac_tx_data.DestAddr.laddr.bytes[4] = parent_addr_B4;
             a_mac_tx_data.DestAddr.laddr.bytes[5] = parent_addr_B5;
             a_mac_tx_data.DestAddr.laddr.bytes[6] = parent_addr_B6;
             a_mac_tx_data.DestAddr.laddr.bytes[7] = parent_addr_B7;
#else
             //using short address for DST
             a_mac_tx_data.fcfmsb = LRWPAN_FCF_DSTMODE_SADDR|LRWPAN_FCF_SRCMODE_LADDR;
             //use addressing discovered by beacon request
             a_mac_tx_data.DestAddr.saddr = mac_pib.bcnSADDR;
             a_mac_tx_data.DestPANID = mac_pib.bcnPANID;
#endif

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲少妇30p| 欧美日韩和欧美的一区二区| 日韩精品在线一区| 欧美精品黑人性xxxx| 在线视频亚洲一区| 中文字幕视频一区二区三区久| 日韩av中文字幕一区二区三区 | 久久精品国产一区二区| 国产又黄又大久久| 日韩丝袜情趣美女图片| 午夜精品福利一区二区三区蜜桃| 在线观看成人小视频| 亚洲综合一区在线| 欧美无砖专区一中文字| 亚洲最快最全在线视频| 欧美日韩在线三级| 图片区小说区区亚洲影院| 欧美日韩三级在线| 日韩在线播放一区二区| 欧美一区二区三区视频免费播放| 肉丝袜脚交视频一区二区| 在线不卡一区二区| 日本不卡一区二区三区高清视频| 91精品国产综合久久久久| 精品中文字幕一区二区小辣椒| 日韩一二三区不卡| 国产又黄又大久久| 国产精品免费久久久久| 91免费版在线看| 亚洲va在线va天堂| 欧美成人女星排行榜| 成人综合在线观看| 夜夜夜精品看看| 777亚洲妇女| 国产精品一区二区三区网站| 国产精品久久久久四虎| 一本大道久久精品懂色aⅴ| 亚洲在线免费播放| 欧美一区二区在线免费观看| 精品系列免费在线观看| 欧美激情中文不卡| 欧美伊人久久久久久午夜久久久久| 免费视频最近日韩| 国产嫩草影院久久久久| 色婷婷亚洲婷婷| 久久精品久久久精品美女| 国产精品毛片无遮挡高清| 在线观看视频一区二区| 久久99精品一区二区三区三区| 欧美激情一区二区三区全黄| 91精品福利在线一区二区三区| 欧美中文字幕一区二区三区亚洲| 亚洲电影在线免费观看| 日韩三级视频在线观看| 成人午夜激情片| 日韩专区一卡二卡| 国产欧美一二三区| 欧美日韩在线观看一区二区| 日本在线观看不卡视频| 亚洲天堂成人在线观看| 欧美亚洲愉拍一区二区| 国产精品一区一区| 亚洲免费在线看| 制服丝袜国产精品| 91在线视频播放| 国产精品原创巨作av| 午夜精品视频在线观看| 国产精品第一页第二页第三页| 91精品久久久久久久99蜜桃| 成人福利视频在线| 另类小说欧美激情| 亚洲成人福利片| 久久婷婷成人综合色| 日韩午夜三级在线| 欧美亚洲图片小说| 成人ar影院免费观看视频| 极品少妇xxxx偷拍精品少妇| 亚洲国产欧美日韩另类综合| 亚洲国产精品黑人久久久| 久久亚洲精品国产精品紫薇| 91精品福利在线一区二区三区 | 国产成人综合在线播放| 99久久国产综合精品女不卡| 国产精品一二三区在线| 美女视频免费一区| 亚洲综合男人的天堂| 中文字幕日韩av资源站| 国产日韩欧美综合一区| 久久无码av三级| 日韩三级在线观看| 欧美人xxxx| 欧美色综合网站| 色激情天天射综合网| av午夜一区麻豆| 99国产欧美久久久精品| jlzzjlzz亚洲女人18| 国产精品99久久久久| 久久国产麻豆精品| 久久爱www久久做| 国产一区美女在线| 国产真实乱偷精品视频免| 美洲天堂一区二卡三卡四卡视频| 日韩av一区二区三区四区| 奇米影视一区二区三区| 视频一区二区欧美| 日韩电影免费一区| 蜜桃一区二区三区四区| 精品一区二区三区免费播放 | 欧美精品一区二区在线播放| 欧美日本免费一区二区三区| 欧美精品久久久久久久多人混战 | 国产v综合v亚洲欧| 成人蜜臀av电影| 91尤物视频在线观看| 7777精品伊人久久久大香线蕉完整版 | 欧美日韩一区国产| 欧美日韩激情在线| 日韩天堂在线观看| 日韩精品一区二区三区三区免费| 国产欧美一区二区精品性| 中文字幕不卡在线| 国产精品久久三| 婷婷亚洲久悠悠色悠在线播放 | 日韩欧美久久一区| 3751色影院一区二区三区| 国产视频一区二区在线| 国产精品免费网站在线观看| 日韩欧美第一区| 亚洲女人小视频在线观看| 亚洲午夜激情网页| 国产乱人伦偷精品视频不卡| 91在线小视频| 欧美欧美午夜aⅴ在线观看| 国产欧美1区2区3区| 亚洲福利视频一区二区| 国产成人aaa| 欧美午夜精品免费| www国产精品av| 天堂va蜜桃一区二区三区| 国产精品一级二级三级| 日韩欧美一区二区三区在线| 欧美经典一区二区| 亚洲老妇xxxxxx| 久久99久久久久久久久久久| 91小视频免费观看| 国产人伦精品一区二区| 亚洲第一在线综合网站| 91在线码无精品| 日韩欧美激情一区| 亚洲午夜私人影院| 不卡的av网站| 欧美大度的电影原声| 男女性色大片免费观看一区二区 | 亚洲一二三四久久| 国产成人激情av| 精品国产伦一区二区三区观看方式| 亚洲色图视频免费播放| 国产不卡视频在线播放| 51久久夜色精品国产麻豆| **欧美大码日韩| 麻豆精品在线播放| 欧美日韩中文另类| 亚洲欧洲色图综合| 国产精一品亚洲二区在线视频| 91精品黄色片免费大全| 一区二区在线观看免费| 一本一道久久a久久精品| 国产亚洲精品中文字幕| 国产麻豆日韩欧美久久| 91精品国模一区二区三区| 久久久久国产精品麻豆| 国产成人综合亚洲网站| 日韩欧美中文一区二区| 午夜成人免费视频| 99re这里只有精品6| 亚洲欧美福利一区二区| 成人免费看视频| 亚洲色大成网站www久久九九| 国产精品一区不卡| 国产精品电影院| av激情成人网| 中文字幕免费不卡在线| 国产黄色精品视频| 欧美精品高清视频| 久久99精品网久久| 久久这里只有精品视频网| 国产精品456露脸| 国产日韩欧美制服另类| av资源网一区| 亚洲激情一二三区| 97久久精品人人做人人爽50路| 一区二区三区在线免费播放| 在线一区二区三区四区| 天堂成人国产精品一区| 日韩一卡二卡三卡国产欧美| 国产精品一线二线三线精华| 国产欧美一二三区| 在线免费不卡视频| 午夜日韩在线电影| 91精品国产乱码久久蜜臀|