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

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

?? mac.c

?? zigbee 2004協議棧
?? 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一区二区三区免费野_久草精品视频
欧美性感一区二区三区| 亚洲午夜在线电影| 亚洲高清免费在线| 97久久超碰国产精品| wwwwxxxxx欧美| 九九**精品视频免费播放| 欧美色偷偷大香| 亚洲特级片在线| 91丨porny丨最新| 综合精品久久久| 9人人澡人人爽人人精品| 国产精品天干天干在线综合| 国产综合久久久久影院| 日韩免费性生活视频播放| 久久精品免费看| 欧美成人性战久久| 成人动漫一区二区在线| 日韩美女视频一区| 欧美日韩国产一级片| 蜜臀va亚洲va欧美va天堂| 国产亚洲欧美日韩日本| 9i看片成人免费高清| 天堂午夜影视日韩欧美一区二区| 在线不卡a资源高清| 国产精品资源在线看| 国产精品美女久久久久aⅴ | 欧美一区二区三区在线视频| 天堂va蜜桃一区二区三区漫画版| 日韩欧美久久一区| 91免费观看视频| 国产又粗又猛又爽又黄91精品| 亚洲国产成人一区二区三区| 欧美日韩aaa| 91一区二区三区在线观看| 日本中文在线一区| 亚洲激情欧美激情| 久久久久国产一区二区三区四区| 日本韩国欧美国产| 国产精品综合av一区二区国产馆| 亚洲久本草在线中文字幕| 久久人人爽爽爽人久久久| 欧美日韩精品高清| 欧美日韩在线免费视频| www..com久久爱| 国产精品888| 免费成人在线观看| 国产精品卡一卡二| 91精品黄色片免费大全| 99久久国产免费看| 精品一区二区三区免费毛片爱| 国产精品美女久久久久久久| 91精品国产综合久久婷婷香蕉 | 成人av中文字幕| 全国精品久久少妇| 国产丝袜欧美中文另类| 日韩黄色免费网站| 久久久久久久久久久久久久久99| 色婷婷国产精品| 国产91富婆露脸刺激对白| 男女视频一区二区| 亚洲六月丁香色婷婷综合久久| 欧美极品xxx| 日韩免费高清av| 欧美一区二区久久久| 欧美日本视频在线| 欧美精品亚洲一区二区在线播放| 国产精品99久| 99国内精品久久| 99久久99久久免费精品蜜臀| 国产一区二区三区免费观看| 久久99九九99精品| 丁香啪啪综合成人亚洲小说| 国产成人亚洲综合a∨婷婷 | 日本一区二区免费在线观看视频 | 亚洲国产精品一区二区久久恐怖片 | 91黄色激情网站| 91超碰这里只有精品国产| 3751色影院一区二区三区| 2022国产精品视频| 亚洲图片激情小说| 日韩专区中文字幕一区二区| 麻豆91在线观看| 成人免费三级在线| 国产一区二区三区在线观看免费 | 亚洲精品久久久蜜桃| 午夜精品影院在线观看| 经典一区二区三区| 色乱码一区二区三区88| 精品久久久久香蕉网| 1区2区3区国产精品| 图片区小说区区亚洲影院| 国产精品羞羞答答xxdd| 欧美丝袜自拍制服另类| 久久伊99综合婷婷久久伊| 久久午夜电影网| 精彩视频一区二区三区| 在线视频你懂得一区| 欧美国产精品中文字幕| 免费在线观看精品| av一区二区久久| 欧美精品一区二区三区蜜臀| 亚洲一区二区影院| 99热这里都是精品| 精品伦理精品一区| 美女视频黄a大片欧美| 欧美日本一道本| 亚洲免费资源在线播放| jvid福利写真一区二区三区| 精品免费视频一区二区| 日本v片在线高清不卡在线观看| 一区二区三区色| 天堂影院一区二区| 9191精品国产综合久久久久久| 亚洲欧美日韩国产手机在线| 97se亚洲国产综合自在线| 中文字幕中文字幕在线一区| 免费观看日韩av| 欧美成人a在线| 日韩在线一二三区| 日韩欧美亚洲国产另类| 日本欧美久久久久免费播放网| 日韩欧美国产午夜精品| 成人一区二区在线观看| 2023国产精品| 99久久久国产精品| 亚洲电影视频在线| 欧美一区二区三区不卡| 顶级嫩模精品视频在线看| 国产欧美一二三区| 欧美日韩国产一区| 国产精品白丝jk黑袜喷水| 国产精品福利一区二区| 在线成人午夜影院| 成人自拍视频在线观看| 亚洲精品视频一区二区| 日韩欧美色综合网站| 粉嫩av一区二区三区在线播放| 亚洲精品美腿丝袜| 欧美体内she精高潮| 不卡一区在线观看| 蜜桃视频在线观看一区| 中文字幕亚洲一区二区av在线| 51精品国自产在线| voyeur盗摄精品| 国产精品一区二区无线| 亚洲不卡在线观看| 久久久国产一区二区三区四区小说| 欧美精品在线观看播放| 一本一道久久a久久精品综合蜜臀 一本一道综合狠狠老 | 国产欧美日韩不卡免费| 欧美一级精品在线| 色综合久久综合| 色欧美日韩亚洲| 成人午夜免费视频| 国产一区 二区| 国产在线播精品第三| 日韩精品高清不卡| 午夜日韩在线电影| 五月开心婷婷久久| 一区二区三区国产精品| 国产精品第13页| 亚洲免费在线视频一区 二区| 国产女主播一区| 国产精品美女久久久久aⅴ国产馆 国产精品美女久久久久av爽李琼 国产精品美女久久久久高潮 | 欧美成人激情免费网| 欧美三级韩国三级日本一级| 91小视频在线观看| 欧美日韩亚洲不卡| 一本久久综合亚洲鲁鲁五月天| 欧美在线视频日韩| 欧美一区二区三区四区五区| 欧美电影一区二区三区| 精品粉嫩aⅴ一区二区三区四区| 欧美xxx久久| 亚洲天堂免费看| 亚洲综合丁香婷婷六月香| 一区二区三区四区在线| 首页国产丝袜综合| 国产一区二区三区精品视频| 成人黄色网址在线观看| 天天综合天天综合色| 亚洲欧美色一区| 日精品一区二区| 免费观看一级特黄欧美大片| 国产成人av一区二区三区在线 | 国产欧美精品区一区二区三区 | 一区二区三区不卡在线观看| 日韩电影在线观看一区| 免费成人美女在线观看.| 色婷婷av一区二区三区软件 | 欧美精品第1页| 亚洲国产精品国自产拍av| 性做久久久久久免费观看| 国产精品88888| 911国产精品| 亚洲一区视频在线观看视频| 国产精品正在播放| 日韩欧美一区二区久久婷婷| 午夜视频在线观看一区二区| 成人理论电影网|