📄 zdprofile.c
字号:
FillAndSendTxOptions( &ZDP_TransID, dstAddr, BindOrUnbind, len, AF_MSG_ACK_REQUEST );
}
/*********************************************************************
* Network Management
*/
#if defined ( ZDO_MGMT_NWKDISC_REQUEST )
/*********************************************************************
* @fn ZDP_MgmtNwkDiscReq
*
* @brief This builds and send a Mgmt_NWK_Disc_req message. This
* function sends a unicast message.
*
* @param dstAddr - destination address of the message
* @param ScanChannels - 32 bit address bit map
* @param StartIndex - Starting index within the reporting network
* list
* @param SecurityEnable - Security Options
*
* @return afStatus_t
*/
afStatus_t ZDP_MgmtNwkDiscReq( zAddrType_t *dstAddr,
uint32 ScanChannels,
byte ScanDuration,
byte StartIndex,
byte SecurityEnable )
{
uint8 *pBuf = ZDP_TmpBuf;
byte len = sizeof( uint32 )+1+1; // ScanChannels + ScanDuration + StartIndex.
pBuf = osal_buffer_uint32( pBuf, ScanChannels );
*pBuf++ = ScanDuration;
*pBuf = StartIndex;
return fillAndSend( &ZDP_TransID, dstAddr, Mgmt_NWK_Disc_req, len );
}
#endif // ZDO_MGMT_NWKDISC_REQUEST
#if defined ( ZDO_MGMT_JOINDIRECT_REQUEST )
/*********************************************************************
* @fn ZDP_MgmtDirectJoinReq
*
* @brief This builds and send a Mgmt_Direct_Join_req message. This
* function sends a unicast message.
*
* @param dstAddr - destination address of the message
* @param deviceAddr - 64 bit IEEE Address
* @param SecurityEnable - Security Options
*
* @return afStatus_t
*/
afStatus_t ZDP_MgmtDirectJoinReq( zAddrType_t *dstAddr,
uint8 *deviceAddr,
byte capInfo,
byte SecurityEnable )
{
osal_cpyExtAddr( ZDP_TmpBuf, deviceAddr );
ZDP_TmpBuf[Z_EXTADDR_LEN] = capInfo;
return fillAndSend( &ZDP_TransID, dstAddr, Mgmt_Direct_Join_req, (Z_EXTADDR_LEN + 1) );
}
#endif // ZDO_MGMT_JOINDIRECT_REQUEST
#if defined ( ZDO_MGMT_PERMIT_JOIN_REQUEST )
/*********************************************************************
* @fn ZDP_MgmtPermitJoinReq
*
* @brief This builds and send a Mgmt_Permit_Join_req message.
*
* @param dstAddr - destination address of the message
* @param duration - Permit duration
* @param TcSignificance - Trust Center Significance
*
* @return afStatus_t
*/
afStatus_t ZDP_MgmtPermitJoinReq( zAddrType_t *dstAddr, byte duration,
byte TcSignificance, byte SecurityEnable )
{
// Build buffer
ZDP_TmpBuf[ZDP_MGMT_PERMIT_JOIN_REQ_DURATION] = duration;
ZDP_TmpBuf[ZDP_MGMT_PERMIT_JOIN_REQ_TC_SIG] = TcSignificance;
// Send the message
return fillAndSend( &ZDP_TransID, dstAddr, Mgmt_Permit_Join_req,
ZDP_MGMT_PERMIT_JOIN_REQ_SIZE );
}
#endif // ZDO_MGMT_PERMIT_JOIN_REQUEST
#if defined ( ZDO_MGMT_LEAVE_REQUEST )
/*********************************************************************
* @fn ZDP_MgmtLeaveReq
*
* @brief This builds and send a Mgmt_Leave_req message.
*
* @param dstAddr - destination address of the message
* IEEEAddr - IEEE adddress of device that is removed
* RemoveChildren - set to 1 to remove the children of the
* device as well. 0 otherwise.
* Rejoin - set to 1 if the removed device should rejoin
afterwards. 0 otherwise.
*
* @return afStatus_t
*/
afStatus_t ZDP_MgmtLeaveReq( zAddrType_t *dstAddr, uint8 *IEEEAddr, uint8 RemoveChildren,
uint8 Rejoin, uint8 SecurityEnable )
{
osal_cpyExtAddr( ZDP_TmpBuf, IEEEAddr );
ZDP_TmpBuf[Z_EXTADDR_LEN] = 0;
if ( RemoveChildren == TRUE )
{
ZDP_TmpBuf[Z_EXTADDR_LEN] |= ZDP_MGMT_LEAVE_REQ_RC;
}
if ( Rejoin == TRUE )
{
ZDP_TmpBuf[Z_EXTADDR_LEN] |= ZDP_MGMT_LEAVE_REQ_REJOIN;
}
return fillAndSend( &ZDP_TransID, dstAddr, Mgmt_Leave_req, (Z_EXTADDR_LEN + 1) );
}
#endif
/*********************************************************************
* @fn ZDP_MgmtNwkUpdateReq
*
* @brief This builds and send a Mgmt_NWK_Update_req message. This
* function sends a unicast or broadcast message.
*
* @param dstAddr - destination address of the message
* @param ChannelMask - 32 bit address bit map
* @param ScanDuration - length of time to spend scanning each channel
* @param ScanCount - number of energy scans to be conducted
* @param NwkUpdateId - NWk Update Id value
* @param NwkManagerAddr - NWK address for device with Network Manager
* bit set in its Node Descriptor
*
* @return afStatus_t
*/
afStatus_t ZDP_MgmtNwkUpdateReq( zAddrType_t *dstAddr,
uint32 ChannelMask,
uint8 ScanDuration,
uint8 ScanCount,
uint8 NwkUpdateId,
uint16 NwkManagerAddr )
{
uint8 *pBuf = ZDP_TmpBuf;
byte len = sizeof( uint32 ) + 1; // ChannelMask + ScanDuration
pBuf = osal_buffer_uint32( pBuf, ChannelMask );
*pBuf++ = ScanDuration;
if ( ScanDuration <= 0x05 )
{
// Request is to scan over channelMask
len += sizeof( uint8 );
*pBuf++ = ScanCount;
}
else if ( ( ScanDuration == 0xFE ) || ( ScanDuration == 0xFF ) )
{
// Request is to change Channel (0xFE) or apsChannelMask and NwkManagerAddr (0xFF)
len += sizeof( uint8 );
*pBuf++ = NwkUpdateId;
if ( ScanDuration == 0xFF )
{
len += sizeof( uint16 );
*pBuf++ = LO_UINT16( NwkManagerAddr );
*pBuf++ = HI_UINT16( NwkManagerAddr );
}
}
return fillAndSend( &ZDP_TransID, dstAddr, Mgmt_NWK_Update_req, len );
}
/*********************************************************************
* Network Management Responses
*/
#if defined ( ZDO_MGMT_NWKDISC_RESPONSE )
/*********************************************************************
* @fn ZDP_MgmtNwkDiscRsp
*
* @brief This builds and send a Mgmt_NWK_Disc_rsp message. This
* function sends a unicast message.
*
* @param dstAddr - destination address of the message
* @param Status - message status (ZDP_SUCCESS or other)
* @param NetworkCount - Total number of networks found
* @param StartIndex - Starting index within the reporting network
* list
* @param NetworkListCount - number of network lists included
* in this message
* @param NetworkList - List of network descriptors
* @param SecurityEnable - Security Options
*
* @return afStatus_t
*/
afStatus_t ZDP_MgmtNwkDiscRsp( byte TransSeq, zAddrType_t *dstAddr,
byte Status,
byte NetworkCount,
byte StartIndex,
byte NetworkListCount,
networkDesc_t *NetworkList,
byte SecurityEnable )
{
uint8 *buf;
uint8 *pBuf;
byte len = 1+1+1+1; // Status + NetworkCount + StartIndex + NetworkCountList.
byte idx;
//len += ((NetworkListCount - StartIndex) * ( ZDP_NETWORK_EXTENDED_DISCRIPTOR_SIZE - 2 ));
len += (NetworkListCount * ( ZDP_NETWORK_EXTENDED_DISCRIPTOR_SIZE - 2 ));
buf = osal_mem_alloc( len+1 );
if ( buf == NULL )
{
return afStatus_MEM_FAIL;
}
pBuf = buf+1;
*pBuf++ = Status;
*pBuf++ = NetworkCount;
*pBuf++ = StartIndex;
*pBuf++ = NetworkListCount;
//for ( idx = StartIndex; idx < (NetworkListCount - StartIndex); idx++ )
for ( idx = 0; idx < NetworkListCount; idx++ )
{
osal_cpyExtAddr( pBuf, NetworkList->extendedPANID);
pBuf += Z_EXTADDR_LEN;
*pBuf++ = NetworkList->logicalChannel; // LogicalChannel
*pBuf = NetworkList->stackProfile; // Stack profile
*pBuf++ |= (byte)(NetworkList->version << 4); // ZigBee Version
*pBuf = NetworkList->beaconOrder; // Beacon Order
*pBuf++ |= (byte)(NetworkList->superFrameOrder << 4); // Superframe Order
if ( NetworkList->chosenRouter != INVALID_NODE_ADDR )
{
*pBuf++ = TRUE; // Permit Joining
}
else
{
*pBuf++ = FALSE;
}
NetworkList = NetworkList->nextDesc; // Move to next list entry
}
FillAndSendBuffer( &TransSeq, dstAddr, Mgmt_NWK_Disc_rsp, len, buf );
}
#endif // ZDO_MGMT_NWKDISC_RESPONSE
/*********************************************************************
* @fn ZDP_MgmtLqiRsp
*
* @brief This builds and send a Mgmt_Lqi_rsp message. This
* function sends a unicast message.
*
* @param dstAddr - destination address of the message
* @param Status - message status (ZDP_SUCCESS or other)
* @param NeighborLqiEntries - Total number of entries found
* @param StartIndex - Starting index within the reporting list
* @param NeighborLqiCount - number of lists included
* in this message
* @param NeighborLqiList - List of NeighborLqiItems. This list
* is the list to be sent, not the entire list
* @param SecurityEnable - true if secure
*
* @return ZStatus_t
*/
ZStatus_t ZDP_MgmtLqiRsp( byte TransSeq, zAddrType_t *dstAddr,
byte Status,
byte NeighborLqiEntries,
byte StartIndex,
byte NeighborLqiCount,
ZDP_MgmtLqiItem_t* NeighborList,
byte SecurityEnable )
{
ZDP_MgmtLqiItem_t* list = NeighborList;
uint8 *buf, *pBuf;
byte len, x;
if ( ZSuccess != Status )
{
ZDP_TmpBuf[0] = Status;
return fillAndSend( &TransSeq, dstAddr, Mgmt_Lqi_rsp, 1 );
}
// (Status + NeighborLqiEntries + StartIndex + NeighborLqiCount) +
// neighbor LQI data.
len = (1 + 1 + 1 + 1) + (NeighborLqiCount * ZDP_MGMTLQI_EXTENDED_SIZE);
buf = osal_mem_alloc( len+1 );
if ( buf == NULL )
{
return afStatus_MEM_FAIL;
}
pBuf = buf+1;
*pBuf++ = Status;
*pBuf++ = NeighborLqiEntries;
*pBuf++ = StartIndex;
*pBuf++ = NeighborLqiCount;
for ( x = 0; x < NeighborLqiCount; x++ )
{
osal_cpyExtAddr( pBuf, list->extPanID); // Extended PanID
pBuf += Z_EXTADDR_LEN;
// EXTADDR
pBuf = osal_cpyExtAddr( pBuf, list->extAddr );
// NWKADDR
*pBuf++ = LO_UINT16( list->nwkAddr );
*pBuf++ = HI_UINT16( list->nwkAddr );
// DEVICETYPE
*pBuf = list->devType;
// RXONIDLE
*pBuf |= (uint8)(list->rxOnIdle << 2);
// RELATIONSHIP
*pBuf++ |= (uint8)(list->relation << 4);
// PERMITJOINING
*pBuf++ = (uint8)(list->permit);
// DEPTH
*pBuf++ = list->depth;
// LQI
*pBuf++ = list->lqi;
list++; // next list entry
}
FillAndSendBuffer( &TransSeq, dstAddr, Mgmt_Lqi_rsp, len, buf );
}
/*********************************************************************
* @fn ZDP_MgmtRtgRsp
*
* @brief This builds and send a Mgmt_Rtg_rsp message. This
* function sends a unicast message.
*
* @param dstAddr - destination address of the message
* @param Status - message status (ZDP_SUCCESS or other)
* @param RoutingTableEntries - Total number of entries
* @param StartIndex - Starting index within the reporting list
* @param RoutingTableListCount - number of entries included
* in this message
* @param RoutingTableList - List of Routing Table entries
* @param SecurityEnable - true to enable security for this message
*
* @return ZStatus_t
*/
ZStatus_t ZDP_MgmtRtgRsp( byte TransSeq, zAddrType_t *dstAddr,
byte Status,
byte RoutingTableEntries,
byte StartIndex,
byte RoutingListCount,
rtgItem_t *RoutingTableList,
byte SecurityEnable )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -