⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zdobject.c

📁 Zigbee2006入门(源代码+文档讲解+系统推荐)
💻 C
📖 第 1 页 / 共 5 页
字号:
}
#endif // ZDO_MGMT_LQI_RESPONSE && RTR_NWK

#if defined ( ZDO_MGMT_LQI_REQUEST )
/*********************************************************************
 * @fn          ZDO_ProcessMgmtLqiRsp
 *
 * @brief       This function handles parsing the incoming Management
 *              LQI response and then generates a callback to the ZD
 *              application.
 *
 * @param       SrcAddr - source of the request
 * @param       msg - buffer holding incoming message to parse
 * @param       SecurityUse -
 *
 * @return      none
 */
void ZDO_ProcessMgmtLqiRsp( zAddrType_t *SrcAddr, byte *msg, byte SecurityUse )
{
  byte x;
  byte status;
  byte startIndex = 0;
  byte neighborLqiCount = 0;
  byte neighborLqiEntries = 0;
  neighborLqiItem_t *list = NULL;
  byte proVer = NLME_GetProtocolVersion();

  status = *msg++;
  if ( status == ZSuccess )
  {
    neighborLqiEntries = *msg++;
    startIndex = *msg++;
    neighborLqiCount = *msg++;

    // Allocate a buffer big enough to handle the list.
    list = (neighborLqiItem_t *)osal_mem_alloc( neighborLqiCount *
                                        sizeof( neighborLqiItem_t ) );
    if ( list )
    {
      neighborLqiItem_t *pList = list;

      for ( x = 0; x < neighborLqiCount; x++ )
      {
        if ( proVer == ZB_PROT_V1_0 )
        {
          pList->PANId = BUILD_UINT16( msg[0], msg[1] );
          msg += 2;
        }
        else
        {
          osal_cpyExtAddr(pList->extPANId, msg);   //Copy extended PAN ID
          msg += Z_EXTADDR_LEN;
        }

        msg += Z_EXTADDR_LEN;  // Throwing away IEEE.
        pList->nwkAddr = BUILD_UINT16( msg[0], msg[1] );
        if ( proVer == ZB_PROT_V1_0 )
          msg += 2 + 1 + 1;          // Skip DeviceType, RxOnIdle, Relationship, PermitJoinging and Depth
        else
          msg += 2 + 1 + 1 + 1;      // Skip DeviceType, RxOnIdle, Rlationship, PermitJoining and Depth

        pList->rxLqi = *msg++;
        pList->txQuality = 0;  // This is not specified OTA by ZigBee 1.1.
        pList++;
      }
    }
  }

  // Call the callback to the application.
  ZDApp_MgmtLqiRspCB( SrcAddr->addr.shortAddr, status, neighborLqiEntries,
                      startIndex, neighborLqiCount, list );

  if ( list )
  {
    osal_mem_free( list );
  }
}
#endif // ZDO_MGMT_LQI_REQUEST

#if defined( ZDO_MGMT_NWKDISC_RESPONSE )
/*********************************************************************
 * @fn          ZDO_ProcessMgmtNwkDiscReq
 *
 * @brief       This function handles parsing the incoming Management
 *              Network Discover request and starts the request.
 *
 * @param       SrcAddr - source of the request
 * @param       msg - pointer to incoming message
 * @param       SecurityUse -
 *
 * @return      none
 */
void ZDO_ProcessMgmtNwkDiscReq( byte TransSeq, zAddrType_t *SrcAddr, byte *msg, byte SecurityUse )
{
  NLME_ScanFields_t scan;
  uint8             index;

  scan.channels = BUILD_UINT32( msg[0], msg[1], msg[2], msg[3] );
  msg += 4;
  scan.duration = *msg++;
  index         = *msg;

  // Save off the information to be used for the response
  zdappMgmtNwkDiscReqInProgress          = true;
  zdappMgmtNwkDiscRspAddr.addrMode       = Addr16Bit;
  zdappMgmtNwkDiscRspAddr.addr.shortAddr = SrcAddr->addr.shortAddr;
  zdappMgmtNwkDiscStartIndex             = index;
  zdappMgmtNwkDiscRspTransSeq            = TransSeq;

  if ( NLME_NwkDiscReq2( &scan ) != ZSuccess )
  {
    NLME_NwkDiscTerm();

    // zdappMgmtNwkDiscReqInProgress will be reset in the confirm callback
  }
}
#endif // ZDO_MGMT_NWKDISC_RESPONSE

#if defined ( ZDO_MGMT_NWKDISC_RESPONSE )
/*********************************************************************
 * @fn          ZDO_FinishProcessingMgmtNwkDiscReq
 *
 * @brief       This function finishes the processing of the Management
 *              Network Discover Request and generates the response.
 *
 *   Note:      This function will limit the number of items returned
 *              to ZDO_MAX_NWKDISC_ITEMS items.
 *
 * @param       ResultCountSrcAddr - source of the request
 * @param       msg - pointer to incoming message
 * @param       SecurityUse -
 *
 * @return      none
 */
void ZDO_FinishProcessingMgmtNwkDiscReq( byte ResultCount,
                                         networkDesc_t *NetworkList )
{
  byte count;

#if defined ( RTR_NWK )
  networkDesc_t *newDesc, *pList = NetworkList;

  // Look for my PanID.
  while ( pList )
  {
    if ( pList->panId == _NIB.nwkPanId )
    {
      break;
    }

    if ( !pList->nextDesc )
    {
      break;
    }
    pList = pList->nextDesc;
  }

  // If my Pan not present (query to a star network ZC or an isolated ZR?),
  // prepend it.
  if ( !pList || (pList->panId != _NIB.nwkPanId) )
  {
    newDesc = (networkDesc_t *)osal_mem_alloc( sizeof( networkDesc_t ) );
    if ( newDesc )
    {
      byte pJoin;

      newDesc->panId = _NIB.nwkPanId;
      newDesc->logicalChannel = _NIB.nwkLogicalChannel;
      newDesc->beaconOrder = _NIB.beaconOrder;
      newDesc->superFrameOrder = _NIB.superFrameOrder;
      newDesc->version = NLME_GetProtocolVersion();
      newDesc->stackProfile = zgStackProfile;
      //Extended PanID
      osal_cpyExtAddr( newDesc->extendedPANID, _NIB.extendedPANID);

      ZMacGetReq( ZMacAssociationPermit, &pJoin );
      newDesc->chosenRouter = ((pJoin) ? ZDAppNwkAddr.addr.shortAddr :
                                         INVALID_NODE_ADDR);

      newDesc->nextDesc = NetworkList;
      NetworkList = newDesc;
      ResultCount++;
    }
  }
#endif

  // Calc the count and apply a max count.
  if ( zdappMgmtNwkDiscStartIndex > ResultCount )
  {
    count = 0;
  }
  else
  {
    count = ResultCount - zdappMgmtNwkDiscStartIndex;
    if ( count > ZDO_MAX_NWKDISC_ITEMS )
    {
      count = ZDO_MAX_NWKDISC_ITEMS;
    }

    // Move the list pointer up to the start index.
    NetworkList += zdappMgmtNwkDiscStartIndex;
  }

  ZDP_MgmtNwkDiscRsp( zdappMgmtNwkDiscRspTransSeq,
                     &zdappMgmtNwkDiscRspAddr, ZSuccess, ResultCount,
                      zdappMgmtNwkDiscStartIndex,
                      count,
                      NetworkList,
                      false );

#if defined ( RTR_NWK )
  if ( newDesc )
  {
    osal_mem_free( newDesc );
  }
#endif

  NLME_NwkDiscTerm();
}
#endif

#if defined ( ZDO_MGMT_NWKDISC_REQUEST )
/*********************************************************************
 * @fn          ZDO_ProcessMgmNwkDiscRsp
 *
 * @brief       This function handles parsing the incoming Management
 *              Network Discover response and then generates a callback
 *              to the ZD application.
 *
 * @param       SrcAddr - source of the request
 * @param       msg - buffer holding incoming message to parse
 * @param       SecurityUse -
 *
 * @return      none
 */
void ZDO_ProcessMgmNwkDiscRsp( zAddrType_t *SrcAddr, byte *msg, byte SecurityUse )
{
  byte x;
  byte status;
  byte networkCount = 0;
  byte startIndex = 0;
  byte networkListCount = 0;
  mgmtNwkDiscItem_t *list = NULL;

  byte proVer = NLME_GetProtocolVersion();

  status = *msg++;
  if ( status == ZSuccess )
  {
    networkCount = *msg++;
    startIndex = *msg++;
    networkListCount = *msg++;

    // Allocate a buffer big enough to handle the list.
    list = (mgmtNwkDiscItem_t *)osal_mem_alloc( networkListCount *
                                        sizeof( mgmtNwkDiscItem_t ) );
    if ( list )
    {
      mgmtNwkDiscItem_t *pList = list;
      for ( x = 0; x < networkListCount; x++ )
      {
        if ( proVer == ZB_PROT_V1_0 )  //Version 1.0
        {
          pList->PANId = BUILD_UINT16( msg[0], msg[1] );
          msg += 2;
        }
        else
        {
          osal_cpyExtAddr(pList->extendedPANID, msg);   //Copy extended PAN ID
          pList->PANId = BUILD_UINT16( msg[0], msg[1] );
          msg += Z_EXTADDR_LEN;

        }
        pList->logicalChannel = *msg++;
        pList->stackProfile = (*msg) & 0x0F;
        pList->version = (*msg++ >> 4) & 0x0F;
        pList->beaconOrder = (*msg) & 0x0F;
        pList->superFrameOrder = (*msg++ >> 4) & 0x0F;
        pList->permitJoining = *msg++;
        pList++;
      }
    }
  }

  // Call the callback to the application.
  ZDApp_MgmtNwkDiscRspCB( SrcAddr->addr.shortAddr, status, networkCount,
                          startIndex, networkListCount, list );

  if ( list )
  {
    osal_mem_free( list );
  }
}
#endif // ZDO_MGMT_NWKDISC_REQUEST

#if defined ( ZDO_MGMT_RTG_RESPONSE ) && defined ( RTR_NWK )
/*********************************************************************
 * @fn          ZDO_ProcessMgmtRtgReq
 *
 * @brief       This function finishes the processing of the Management
 *              Routing Request and generates the response.
 *
 *   Note:      This function will limit the number of items returned
 *              to ZDO_MAX_RTG_ITEMS items.
 *
 * @param       ResultCountSrcAddr - source of the request
 * @param       msg - pointer to incoming message
 * @param       SecurityUse -
 *
 * @return      none
 */
void ZDO_ProcessMgmtRtgReq( byte TransSeq, zAddrType_t *SrcAddr, byte StartIndex, byte SecurityUse )
{
  byte x;
  byte maxNumItems;
  byte numItems;
  byte *pBuf;
  rtgItem_t *pList;

  // Get the number of table items
  NLME_GetRequest( nwkNumRoutingTableEntries, 0, &maxNumItems );

  numItems = maxNumItems - StartIndex;    // Start at the passed in index

  // limit the size of the list
  if ( numItems > ZDO_MAX_RTG_ITEMS )
    numItems = ZDO_MAX_RTG_ITEMS;

  // Allocate the memory to build the table
  pBuf = osal_mem_alloc( (short)(sizeof( rtgItem_t ) * numItems) );

  if ( pBuf )
  {
    // Convert buffer to list
    pList = (rtgItem_t *)pBuf;

    // Loop through items and build list
    for ( x = 0; x < numItems; x++ )
    {
      NLME_GetRequest( nwkRoutingTable, (uint16)(x + StartIndex), (void*)pList );

      // Remap the status to the RoutingTableList Record Format defined in the ZigBee spec
      switch( pList->status )
      {
        case RT_ACTIVE:
          pList->status = ZDO_MGMT_RTG_ENTRY_ACTIVE;
          break;

        case RT_DISC:
          pList->status = ZDO_MGMT_RTG_ENTRY_DISCOVERY_UNDERWAY;
          break;

        case RT_LINK_FAIL:
          pList->status = ZDO_MGMT_RTG_ENTRY_DISCOVERY_FAILED;

        case RT_INIT:
        case RT_REPAIR:
        default:
          pList->status = ZDO_MGMT_RTG_ENTRY_INACTIVE;
          break;
      }

      // Increment pointer to next record
      pList++;
    }

    // Send response
    ZDP_MgmtRtgRsp( TransSeq, SrcAddr, ZSuccess, maxNumItems, StartIndex, numItems,
                          (rtgItem_t *)pBuf, false );

    osal_mem_free( pBuf );
  }
}
#endif // defined(ZDO_MGMT_RTG_RESPONSE)  && defined(RTR_NWK)

#if defined ( ZDO_MGMT_RTG_REQUEST )
/*********************************************************************
 * @fn          ZDO_ProcessMgmtRtgRsp
 *
 * @brief       This function handles parsing the incoming Management
 *              Routing response and then generates a callback
 *              to the ZD application.
 *
 * @param       SrcAddr - source of the request
 * @param       msg - buffer holding incoming message to parse
 * @param       SecurityUse -
 *
 * @return      none
 */
void ZDO_ProcessMgmtRtgRsp( zAddrType_t *SrcAddr, byte *msg, byte SecurityUse )
{
  byte x;
  byte status;
  byte rtgCount = 0;
  byte startIndex = 0;
  byte rtgListCount = 0;
  byte *pBuf = NULL;
  rtgItem_t *pList = NULL;

  status = *msg++;
  if ( status == ZSuccess )
  {
    rtgCount = *msg++;
    startIndex = *msg++;
    rtgListCount = *msg++;

    // Allocate a buffer big enough to handle the list
    pBuf = osal_mem_alloc( rtgListCount * sizeof( rtgItem_t ) );
    if ( pBuf )
    {
      pList = (rtgItem_t *)pBuf;
      for ( x = 0; x < rtgListCount; x++ )
      {
        pList->dstAddress = BUILD_UINT16( msg[0], msg[1] );
        msg += 2;
        pList->status = *msg++;
        pList->nextHopAddress = BUILD_UINT16( msg[0], msg[1] );
        msg += 2;
        pList++;
      }
    }
  }

  // Call the callback to the application.
  ZDApp_MgmtRtgRspCB( SrcAddr->addr.shortAddr, status, rtgCount,
                                 startIndex, rtgListCount, (rtgItem_t *)pBuf );

  if ( pBuf )
  {
    osal_mem_free( pBuf );
  }
}
#endif // ZDO_MGMT_RTG_REQUEST

#if defined ( ZDO_MGMT_BIND_RESPONSE )
/*********************************************************************
 * @fn          ZDO_ProcessMgmtBindReq
 *
 * @brief       This function finishes the processing of the Management
 *              Bind Request and generates the response.
 *
 *   Note:      This function will limit the number of items returned
 *              to ZDO_MAX_BIND_ITEMS items.
 *
 * @param       ResultCountSrcAddr - source of the request
 * @param       msg - pointer to incoming message
 * @param       SecurityUse -
 *
 * @return      none
 */
void ZDO_ProcessMgmtBindReq( byte TransSeq, zAddrType_t *SrcAddr, byte StartIndex, byte SecurityUse )
{
#if defined ( REFLECTOR )
  byte x;
  uint16 maxNumItems;
  uint16 numItems;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -