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

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

?? mac.c

?? ZIGBEE2006協議棧
?? C
?? 第 1 頁 / 共 4 頁
字號:

macRxFSM_start:

  switch(macRxState)  {
  case MAC_RXSTATE_IDLE:
    if (macRxBuffEmpty()) break;   //no data, break
    //buffer not empty, start decode
    pkt = macGetRxPacket();
    //dbgPrintPacket(pkt->data+1, *(pkt->data));
    //must be either a DATA, BCN, or MAC packet
    //at this point, we throw away BCN packets if are not waiting
    //for a beacon response
    if ((LRWPAN_IS_BCN(*(pkt->data+1))) &&
        !mac_pib.flags.bits.WaitingForBeaconResponse) {
          DEBUG_STRING(DBG_INFO,"MAC: Received BCN pkt, discarding.\n");
          macFreeRxPacket(TRUE);
          break;
        }
    if (LRWPAN_IS_ACK(*(pkt->data+1))) {
      //This should not happen. ACK packets should be parsed
      //in the HAL layer that copies ACK packets to temp storage.
      //will keep this for completeness.
      DEBUG_STRING(DBG_INFO,"MAC: Received ACK pkt in macStartRxDecode, discarding, check ack packet parsing..\n");
      macFreeRxPacket(TRUE);
      break;
    }
    //at this point, we have a DATA, MAC CMD, or BCN packet.. do something with it.
    //need to parse the header information get to the payload.
    a_mac_rx_data.orgpkt = pkt;
    macParseHdr();
    if ((LRWPAN_IS_BCN(*(pkt->data+1)))){
      DEBUG_STRING(DBG_INFO,"MAC: Parsing BCN pkt.\n");
      //now finished with it.
      macParseBeacon();
      macFreeRxPacket(TRUE);
      break;
    }

    if (LRWPAN_IS_DATA(*(pkt->data+1))){
		//this is a data packet, check if we should reject it
        if (!macCheckDataRejection()) {
            //we need to reject this packet.
            DEBUG_STRING(DBG_INFO,"MAC: Rejecting Data packet from unassociated node, rejecting.\n");
            macFreeRxPacket(TRUE);
            break;
        }
       mac_pib.last_data_rx_time = halGetMACTimer();  //time of last data or mac command
      //at this point, will accept packet, indicate this to network layer
      //set a flag, and pass the nwkStart offset to the NWK layer
      //RX buffer.
      macRxState = MAC_RXSTATE_NWK_HANDOFF;
      goto macRxFSM_start;
    }

    //at this point, we have a MAC command packet, lets do something with it.
    DEBUG_STRING(DBG_INFO,"MAC: Received MAC cmd packet, proceeding.\n");

    //there are some MAC CMDs that we can handle right here.
    //If it is a response, we handle it here. If it is a request,
    //that has to be handled in the main FSM.
    cmd = *(a_mac_rx_data.orgpkt->data + a_mac_rx_data.pload_offset);
    switch(cmd) {
    case LRWPAN_MACCMD_ASSOC_RSP:
#ifndef LRWPAN_COORDINATOR
      if (mac_pib.flags.bits.WaitingForAssocResponse){
        macParseAssocResponse();
      }					
#endif				
      //free this packet, we are finished with it.
      macFreeRxPacket(TRUE);
      break;

	case LRWPAN_MACCMD_COORD_REALIGN:
#ifndef LRWPAN_COORDINATOR
      if (mac_pib.flags.bits.WaitingForOrphanResponse){
        macParseOrphanResponse();
      }					
#endif				
      //free this packet, we are finished with it.
      macFreeRxPacket(TRUE);
      break;



#ifdef LRWPAN_FFD
      //only FFDs handle this
    case LRWPAN_MACCMD_BCN_REQ:
    case LRWPAN_MACCMD_ASSOC_REQ:
	case LRWPAN_MACCMD_ORPHAN:
      //requests must be handled in the main FSM. We need to signal that a MAC
      //CMD packet is packet is pending, and freeze the RX FSM until the
      //main FSM has taken care of it.
      mac_pib.flags.bits.macPending = 1;
      macRxState = MAC_RXSTATE_CMD_PENDING;
      break;
#endif

    default:
      //unhandled MAC packets
      DEBUG_STRING(DBG_INFO,"MAC: Received MAC CMD that is not implemented or not handled by this node, discarding.\n");
      DEBUG_STRING(DBG_INFO,"Cmd is: ");
      DEBUG_UINT8(DBG_INFO,cmd);
      DEBUG_STRING(DBG_INFO,"\n");
      macFreeRxPacket(TRUE);
      break;

    }			

    break;
  case MAC_RXSTATE_NWK_HANDOFF:
		  if (nwkRxBusy()) break;    //nwkRX is still busy
                  //handoff the current packet
                  nwkRxHandoff();
                  //we are finished with this packet.
                  //free the MAC resource, but not the memory. The NWK layer
                  // or above has to free the memory
                  macFreeRxPacket(FALSE);
                  macRxState = MAC_RXSTATE_IDLE;
                  break;
  case MAC_RXSTATE_CMD_PENDING:
    if (mac_pib.flags.bits.macPending ) break;
			 //when macPending is cleared, this means main FSM is finished with packet.
			 //So free the packet, and start parsing new packets again
			 macFreeRxPacket(TRUE);
                         macRxState = MAC_RXSTATE_IDLE;
                         break;


  default: break;

  }

}

//parse the header currently in a_mac_rx_data
//return the offset to the network header.

static void macParseHdr() {
  BYTE *ptr;
  BYTE len,i;
  BYTE srcmode, dstmode;

  ptr = a_mac_rx_data.orgpkt->data;

  //skip first byte since the first byte in the a_mac_rx_data.orgpkt is the
  //packet length
  len = 1;ptr++;


  a_mac_rx_data.fcflsb = *ptr; ptr++;
  a_mac_rx_data.fcfmsb = *ptr; ptr++;
  dstmode = LRWPAN_GET_DST_ADDR(a_mac_rx_data.fcfmsb);
  srcmode = LRWPAN_GET_SRC_ADDR(a_mac_rx_data.fcfmsb);

  //skip DSN
  ptr++;
  len = len +3;

  if (dstmode != LRWPAN_ADDRMODE_NOADDR){
    //get the DEST PANDID
    a_mac_rx_data.DestPANID = *ptr;
    ptr++;
    a_mac_rx_data.DestPANID += (((UINT16)*ptr) << 8);
    ptr++;
    len = len + 2;
  }
  //DST address
  if (dstmode == LRWPAN_ADDRMODE_SADDR) {
    a_mac_rx_data.DestAddr.saddr = *ptr;
    ptr++;
    a_mac_rx_data.DestAddr.saddr += (((UINT16)*ptr) << 8);
    ptr++;
    len = len + 2;

  }else if (dstmode == LRWPAN_ADDRMODE_LADDR) {
    for (i=0;i<8;i++) {
      a_mac_rx_data.DestAddr.laddr.bytes[i] = *ptr;
      ptr++;
    }
    len = len + 8;
  }


  if ( !LRWPAN_GET_INTRAPAN(a_mac_rx_data.fcflsb) &&
      srcmode != LRWPAN_ADDRMODE_NOADDR
        ) {
          //PANID present if INTRAPAN is zero, and src is nonzero
          a_mac_rx_data.SrcPANID = *ptr;
          ptr++;
          a_mac_rx_data.SrcPANID += (((UINT16)*ptr) << 8);
          ptr++;
          len = len + 2;
        }
  //SRC address
  if (srcmode == LRWPAN_ADDRMODE_SADDR) {
    a_mac_rx_data.SrcAddr.saddr = *ptr;
    ptr++;
    a_mac_rx_data.SrcAddr.saddr += (((UINT16)*ptr) << 8);
    ptr++;
    len = len + 2;

  }else if (srcmode == LRWPAN_ADDRMODE_LADDR) {
    for (i=0;i<8;i++) {
      a_mac_rx_data.SrcAddr.laddr.bytes[i] = *ptr;
      ptr++;
    }
    len = len + 8;
  }
  //save offset.
  a_mac_rx_data.pload_offset = len;
}

#ifdef LRWPAN_FFD
//Beacon payload format
// nwk magic number ( 4 bytes) | mac depth
static void macFormatBeacon(void){
  BYTE i;

  //fill in the beacon payload, we have the TX buffer lock
  phy_pib.currentTxFrm = &tmpTxBuff[LRWPAN_MAX_FRAME_SIZE];
#ifndef LRWPAN_ZIGBEE_BEACON_COMPLY
  //fill in the magic number
  --phy_pib.currentTxFrm;
  *phy_pib.currentTxFrm = LRWPAN_NWK_MAGICNUM_B3;
  --phy_pib.currentTxFrm;
  *phy_pib.currentTxFrm = LRWPAN_NWK_MAGICNUM_B2;
  --phy_pib.currentTxFrm;
  *phy_pib.currentTxFrm = LRWPAN_NWK_MAGICNUM_B1;
  --phy_pib.currentTxFrm;
  *phy_pib.currentTxFrm = LRWPAN_NWK_MAGICNUM_B0;
#endif

  //next three bytes are zero for timestep difference
  //for multi-hop beaconing networks. This is currently filled in
  //as zero
  --phy_pib.currentTxFrm;
  *phy_pib.currentTxFrm =0;
  --phy_pib.currentTxFrm;
  *phy_pib.currentTxFrm =0;
  --phy_pib.currentTxFrm;
  *phy_pib.currentTxFrm =0;

  //see if I have space for an END device
  --phy_pib.currentTxFrm;
  if (mac_pib.ChildRFDs == LRWPAN_MAX_NON_ROUTER_CHILDREN) {
	  *phy_pib.currentTxFrm =0; //no room
  } else {
      *phy_pib.currentTxFrm =1;  //have space.
  }

  //fill in my depth
  --phy_pib.currentTxFrm;
  *phy_pib.currentTxFrm = mac_pib.depth;

  //see if I have space for a ROUTER device
  --phy_pib.currentTxFrm;
  if (mac_pib.ChildRouters == LRWPAN_MAX_ROUTERS_PER_PARENT) {
	  *phy_pib.currentTxFrm =0; //no room
  } else {
      *phy_pib.currentTxFrm =1;  //have space.
  }

   //network protocol version
  --phy_pib.currentTxFrm;
  *phy_pib.currentTxFrm =LRWPAN_ZIGBEE_PROTOCOL_VER;

   //stack protocol
   --phy_pib.currentTxFrm;
   *phy_pib.currentTxFrm =LRWPAN_STACK_PROFILE;

   //Zigbee protocol ID
   --phy_pib.currentTxFrm;
   *phy_pib.currentTxFrm =LRWPAN_ZIGBEE_PROTOCOL_ID;

  //pending address field
  --phy_pib.currentTxFrm;
  *phy_pib.currentTxFrm = 0;  //makes this a NOP

  //GTS directions field
  --phy_pib.currentTxFrm;
  *phy_pib.currentTxFrm = 0;  //makes this a NOP

  //2 bytes of superframe
#ifdef LRWPAN_COORDINATOR
  i = LRWPAN_BEACON_SF_PAN_COORD_MASK;
#else
  i = 0;
#endif
  if (mac_pib.flags.bits.macAssociationPermit) {
    i = i | LRWPAN_BEACON_SF_ASSOC_PERMIT_MASK;
  }
  --phy_pib.currentTxFrm;
  *phy_pib.currentTxFrm = i;  //MSB of superframe

  --phy_pib.currentTxFrm;
  *phy_pib.currentTxFrm = 0xFF; //LSB of superframe

  phy_pib.currentTxFlen = LRWPAN_NWK_BEACON_SIZE;

}

#endif

//parse the beacon
static void macParseBeacon(void){
  BYTE *ptr;
  BYTE depth;

  if ( (*(a_mac_rx_data.orgpkt->data)-a_mac_rx_data.pload_offset-PACKET_FOOTER_SIZE +1)
      != LRWPAN_NWK_BEACON_SIZE  ) {
        return; //wrong length
      }

  ptr = a_mac_rx_data.orgpkt->data + a_mac_rx_data.pload_offset;
  //check association bit in MSB of superframe
  if (!LRWPAN_GET_BEACON_SF_ASSOC_PERMIT(*(ptr+1))) {
    //cannot associate with this node. reject
    return;
  }
  // point at payload (skip four bytes of header)
  ptr = ptr + 4;
  //skip if any mismatches on protocol ID/Ver, stack profile, etc.
  //check protocol ID
  if (*ptr != LRWPAN_ZIGBEE_PROTOCOL_ID) return;
  ptr++;
  //check stack profile
  if (*ptr != LRWPAN_STACK_PROFILE) return;
  ptr++;
  //check protocol version
  if (*ptr != LRWPAN_ZIGBEE_PROTOCOL_VER) return;
  ptr++;

  //check router capacity
  //for right now, if I am a router, I have to join as a router.
  //no option as of now for a router joining as an end-device
#ifdef LRWPAN_FFD
  //only routers have to check this
  if (*ptr == 0) return;  //no room to join as router
#endif

  ptr++;

  //get the depth
  depth = *ptr;
  ptr++;

  //check end device capacity
#ifdef LRWPAN_RFD
  //only end devices have to check this.
  if (*ptr == 0) return;  //no room to join as end device
#endif
  ptr++;

  //skip the next three bytes, only for beaconing.
  ptr = ptr + 3;

#ifndef LRWPAN_ZIGBEE_BEACON_COMPLY
  //check the magic number
  if (*ptr != LRWPAN_NWK_MAGICNUM_B0) return;
  ptr++;
  if (*ptr != LRWPAN_NWK_MAGICNUM_B1) return;
  ptr++;
  if (*ptr != LRWPAN_NWK_MAGICNUM_B2) return;
  ptr++;
  if (*ptr != LRWPAN_NWK_MAGICNUM_B3) return;
  ptr++;
#endif

  //at this point, we could accept this node as a parent
  if ((mac_pib.bcnDepth == 0xFF) ||
      (a_mac_rx_data.orgpkt->rssi > mac_pib.bcnRSSI)) {
        //either our first response, or from a closer node
        //save this information.
        //use value with higher RSSI.
        //the RSSI byte is assumed to be formatted as HIGHER IS BETTER
        //the HAL layer converts any native signed RSSI to an unsigned value

        mac_pib.bcnDepth = depth;  //get depth
        mac_pib.bcnRSSI = a_mac_rx_data.orgpkt->rssi;
        mac_pib.bcnSADDR = a_mac_rx_data.SrcAddr.saddr;
        mac_pib.bcnPANID = a_mac_rx_data.SrcPANID;
        DEBUG_STRING(DBG_INFO,"MAC: Bcn rsp is Panid: ");
        DEBUG_UINT16(DBG_INFO, mac_pib.bcnPANID);
         DEBUG_STRING(DBG_INFO,", Saddr: ");
       DEBUG_UINT16(DBG_INFO, mac_pib.bcnSADDR);
        DEBUG_STRING(DBG_INFO,", LQI: ");
       DEBUG_UINT8(DBG_INFO, mac_pib.bcnRSSI);
          DEBUG_STRING(DBG_INFO,", Dpth: ");
       DEBUG_UINT8(DBG_INFO, mac_pib.bcnDepth);
       DEBUG_STRING(DBG_INFO,"\n");
      }
  mac_pib.flags.bits.GotBeaconResponse = 1;
}


static void macFormatAssocRequest(void){
  //fill in payload of request
  phy_pib.currentTxFrm = &tmpTxBuff[LRWPAN_MAX_FRAME_SIZE];

#ifndef IEEE_802_COMPLY
  //put the magic number in the association request
  phy_pib.currentTxFrm--;
  *phy_pib.currentTxFrm = LRWPAN_NWK_MAGICNUM_B3;

  phy_pib.currentTxFrm--;
  *phy_pib.currentTxFrm = LRWPAN_NWK_MAGICNUM_B2;

  phy_pib.currentTxFrm--;
  *phy_pib.currentTxFrm = LRWPAN_NWK_MAGICNUM_B1;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美专区亚洲专区| 4hu四虎永久在线影院成人| 亚洲bdsm女犯bdsm网站| 亚洲精品第一国产综合野| 国产精品日韩成人| 国产日韩三级在线| 国产欧美精品区一区二区三区 | 91精品蜜臀在线一区尤物| 色综合视频一区二区三区高清| 东方aⅴ免费观看久久av| 国产在线播精品第三| 激情五月播播久久久精品| 精品一区二区三区久久久| 久久99久久精品| 国产激情精品久久久第一区二区 | 亚洲美女偷拍久久| 亚洲精品久久久久久国产精华液| 国产精品久久一级| 亚洲素人一区二区| 亚洲精品老司机| 午夜激情综合网| 精品一区在线看| 97精品国产97久久久久久久久久久久| 一本色道久久综合亚洲aⅴ蜜桃 | 久久99精品久久久久久| 国产成人一区在线| 欧美视频你懂的| 久久亚洲影视婷婷| 亚洲欧美激情插| 久久激五月天综合精品| caoporn国产精品| 欧美高清视频不卡网| 国产亚洲欧美色| 一级做a爱片久久| 狠狠狠色丁香婷婷综合激情| 99久久婷婷国产综合精品电影 | 国产亚洲污的网站| 亚洲一级电影视频| 粉嫩欧美一区二区三区高清影视 | 日韩欧美国产系列| 亚洲色图都市小说| 国模少妇一区二区三区| 91精品福利视频| 国产清纯美女被跳蛋高潮一区二区久久w| 亚洲欧美另类小说视频| 久久不见久久见免费视频7| 色婷婷国产精品久久包臀| 26uuu国产电影一区二区| 一区二区三区高清在线| 国产精品1区2区| 91麻豆精品国产91久久久资源速度| 国产三级欧美三级日产三级99| 亚洲高清在线精品| 91看片淫黄大片一级| 亚洲国产精品二十页| 精品一区二区在线观看| 欧美区在线观看| 亚洲一区二区三区四区在线免费观看| 国产在线视频一区二区三区| 欧美日韩电影在线播放| 亚洲免费在线观看| eeuss鲁片一区二区三区在线观看 eeuss鲁片一区二区三区在线看 | 国产女人18毛片水真多成人如厕| 欧美高清在线精品一区| 韩国av一区二区三区四区| 欧美一区二区美女| 亚洲国产欧美另类丝袜| 在线视频亚洲一区| 樱桃国产成人精品视频| 91丨九色丨蝌蚪富婆spa| 中文字幕一区二区三区在线不卡 | 国产色产综合产在线视频| 老司机精品视频在线| 日韩一级黄色片| 美腿丝袜亚洲一区| 日韩欧美国产小视频| 日韩和欧美的一区| 欧美视频在线一区二区三区| 亚洲国产中文字幕| 欧美一区二区三区在线视频| 视频一区二区中文字幕| 欧美一级国产精品| 男人操女人的视频在线观看欧美| 欧美精品丝袜中出| 日韩av一区二区在线影视| 日韩一区二区精品在线观看| 裸体在线国模精品偷拍| 久久奇米777| 国产1区2区3区精品美女| 国产精品麻豆一区二区| 国产69精品久久久久毛片| 国产午夜三级一区二区三| 成人黄动漫网站免费app| 亚洲欧美另类久久久精品| 欧美日韩精品免费观看视频| 久久69国产一区二区蜜臀| 国产农村妇女精品| 欧美色图在线观看| 激情图片小说一区| 亚洲人123区| 欧美一级精品在线| 99久久久精品| 奇米亚洲午夜久久精品| 久久九九久久九九| 色女孩综合影院| 精品一区二区三区免费毛片爱| 国产性做久久久久久| 欧美做爰猛烈大尺度电影无法无天| 美女脱光内衣内裤视频久久影院| 亚洲国产精品99久久久久久久久| 欧美最猛性xxxxx直播| 国产精品一级片在线观看| 亚洲综合清纯丝袜自拍| 久久天天做天天爱综合色| 在线精品观看国产| 成人在线综合网站| 美女在线一区二区| 亚洲制服丝袜一区| 久久精品亚洲精品国产欧美kt∨| 欧美又粗又大又爽| 成人视屏免费看| 蜜臀久久99精品久久久久久9| 国产精品入口麻豆九色| 精品国产乱子伦一区| eeuss鲁片一区二区三区在线看| 日韩高清在线一区| 夜夜嗨av一区二区三区网页| ww久久中文字幕| 91精品在线观看入口| 日本韩国欧美三级| www.日韩精品| 国产大片一区二区| 国产尤物一区二区| 日本亚洲最大的色成网站www| 日韩美女视频19| 国产三级精品三级在线专区| 欧美xxx久久| 欧美精品一级二级三级| 色欧美88888久久久久久影院| jiyouzz国产精品久久| 国产99久久久国产精品免费看 | 成人精品一区二区三区中文字幕| 日韩精彩视频在线观看| 亚洲一二三专区| 一区二区三区在线免费观看| 国产精品免费aⅴ片在线观看| 国产亚洲精品7777| 久久久无码精品亚洲日韩按摩| 日韩美女一区二区三区| 欧美成人一区二区三区在线观看| 91精品国产乱码久久蜜臀| 51久久夜色精品国产麻豆| 欧美一区二区久久| 欧美精品一区二区精品网| 久久综合色8888| 国产欧美一区二区三区在线看蜜臀| 精品成人一区二区三区四区| 亚洲精品一区二区三区影院| 久久噜噜亚洲综合| 亚洲国产高清在线| 亚洲天堂网中文字| 一区二区三区日韩欧美| 亚洲国产精品精华液网站| 亚洲国产另类av| 六月婷婷色综合| 国产成人精品免费| 91在线播放网址| 欧美日韩一区三区| 精品国产一二三区| 国产精品三级在线观看| 亚洲黄色片在线观看| 日本vs亚洲vs韩国一区三区二区 | 国产精品另类一区| 亚洲精品第一国产综合野| 日韩国产一区二| 国产精品888| 欧美三级欧美一级| 精品国产凹凸成av人导航| 国产精品色婷婷久久58| 亚洲电影第三页| 国产一区91精品张津瑜| av一区二区三区黑人| 欧美精品乱人伦久久久久久| 欧美精品一区二区三区蜜桃 | 中文字幕av不卡| 亚洲国产一区二区视频| 韩国视频一区二区| 91成人免费电影| 久久九九久久九九| 午夜a成v人精品| 成人av在线观| 欧美videos中文字幕| 亚洲欧美日本韩国| 国产一区二区三区四区五区美女 | 国产精品久久看| 日韩专区欧美专区| 99久久久无码国产精品| 日韩欧美不卡在线观看视频| 国产精品国产三级国产普通话蜜臀| 日日夜夜精品视频免费|