📄 zdprofile.c
字号:
*pBuf++ = HI_UINT16( nwkAddr );
*pBuf++ = Count; // Endpoint/Interface count
if ( Count )
{
len += Count;
osal_memcpy( pBuf, pEPList, Count );
}
FillAndSendTxOptions( &TransSeq, dstAddr, MsgType, len, txOptions );
}
#if defined ( ZDO_USERDESC_RESPONSE )
/*********************************************************************
* @fn ZDP_UserDescRsp
*
* @brief Build and send the User Decriptor Response.
*
*
* @param dstAddr - destination address
* @param nwkAddrOfInterest -
* @param userDesc -
* @param SecurityEnable - Security Options
*
* @return ZStatus_t
*/
ZStatus_t ZDP_UserDescRsp( byte TransSeq, zAddrType_t *dstAddr,
uint16 nwkAddrOfInterest, UserDescriptorFormat_t *userDesc,
byte SecurityEnable )
{
byte *pBuf = ZDP_TmpBuf;
byte len = 1 + 2 + 1; // Status + nwkAddr + descriptor length.
len += userDesc->len;
*pBuf++ = ZSUCCESS;
*pBuf++ = LO_UINT16( nwkAddrOfInterest );
*pBuf++ = HI_UINT16( nwkAddrOfInterest );
*pBuf++ = userDesc->len;
osal_memcpy( pBuf, userDesc->desc, userDesc->len );
return (ZStatus_t)fillAndSend( &TransSeq, dstAddr, User_Desc_rsp, len );
}
#endif // ZDO_USERDESC_RESPONSE
#if defined ( ZDO_SERVERDISC_RESPONSE )
/*********************************************************************
* @fn ZDP_ServerDiscRsp
*
* @brief Build and send the Server_Discovery_rsp response.
*
* @param transID - Transaction sequence number of request.
* @param dstAddr - Network Destination Address.
* @param status - Status of response to request.
* @param aoi - Network Address of Interest of request.
* @param serverMask - Bit map of service(s) being sought.
* @param SecurityEnable - Security Options
*
* @return ZStatus_t
*/
ZStatus_t ZDP_ServerDiscRsp( byte transID, zAddrType_t *dstAddr, byte status,
uint16 aoi, uint16 serverMask, byte SecurityEnable )
{
const byte len = 1 + 2; // status + aoi + mask.
byte *pBuf = ZDP_TmpBuf;
*pBuf++ = status;
*pBuf++ = LO_UINT16( serverMask );
*pBuf++ = HI_UINT16( serverMask );
return (ZStatus_t)fillAndSend( &transID, dstAddr, Server_Discovery_rsp, len );
}
#endif // ZDO_USERDESC_RESPONSE
/*********************************************************************
* @fn ZDP_GenericRsp
*
* @brief Sends a response message with only the parameter status
* byte and the addr of interest for data.
* This function sends unicast message to the
* requesting device.
*
* @param dstAddr - destination address
* @param status - generic status for response
* @param aoi - address of interest
* @param dstAddr - destination address
* @param rspId - response cluster ID
* @param SecurityEnable - Security Options
*
* @return afStatus_t
*/
afStatus_t ZDP_GenericRsp( byte TransSeq, zAddrType_t *dstAddr,
byte status, uint16 aoi, uint16 rspID, byte SecurityEnable )
{
uint8 len;
ZDP_TmpBuf[0] = status;
ZDP_TmpBuf[1] = LO_UINT16( aoi );
ZDP_TmpBuf[2] = HI_UINT16( aoi );
// Length byte
ZDP_TmpBuf[3] = 0;
len = 4;
return fillAndSend( &TransSeq, dstAddr, rspID, len );
}
/*********************************************************************
* Binding
*/
#if defined ( ZDO_ENDDEVICEBIND_REQUEST )
/*********************************************************************
* @fn ZDP_EndDeviceBindReq
*
* @brief This builds and sends a End_Device_Bind_req message.
* This function sends a unicast message.
*
* @param dstAddr - destination address
* @param LocalCoordinator - short address of local coordinator
* @param epIntf - Endpoint/Interface of Simple Desc
* @param ProfileID - Profile ID
*
* The Input cluster list is the opposite of what you would think.
* This is the output cluster list of this device
* @param NumInClusters - number of input clusters
* @param InClusterList - input cluster ID list
*
* The Output cluster list is the opposite of what you would think.
* This is the input cluster list of this device
* @param NumOutClusters - number of output clusters
* @param OutClusterList - output cluster ID list
*
* @param SecurityEnable - Security Options
*
* @return afStatus_t
*/
afStatus_t ZDP_EndDeviceBindReq( zAddrType_t *dstAddr,
uint16 LocalCoordinator,
byte endPoint,
uint16 ProfileID,
byte NumInClusters, cId_t *InClusterList,
byte NumOutClusters, cId_t *OutClusterList,
byte SecurityEnable )
{
uint8 *pBuf = ZDP_TmpBuf;
uint8 i, len;
uint8 *ieeeAddr;
// LocalCoordinator + SrcExtAddr + ep + ProfileID + NumInClusters + NumOutClusters.
len = 2 + Z_EXTADDR_LEN + 1 + 2 + 1 + 1;
len += (NumInClusters + NumOutClusters) * sizeof ( uint16 );
if ( len >= ZDP_BUF_SZ-1 )
{
return afStatus_MEM_FAIL;
}
if ( LocalCoordinator != NLME_GetShortAddr() )
{
return afStatus_INVALID_PARAMETER;
}
*pBuf++ = LO_UINT16( LocalCoordinator );
*pBuf++ = HI_UINT16( LocalCoordinator );
ieeeAddr = NLME_GetExtAddr();
pBuf = osal_cpyExtAddr( pBuf, ieeeAddr );
*pBuf++ = endPoint;
*pBuf++ = LO_UINT16( ProfileID ); // Profile ID
*pBuf++ = HI_UINT16( ProfileID );
*pBuf++ = NumInClusters; // Input cluster list
for ( i = 0; i < NumInClusters; ++i )
{
*pBuf++ = LO_UINT16(InClusterList[i]);
*pBuf++ = HI_UINT16(InClusterList[i]);
}
*pBuf++ = NumOutClusters; // Output cluster list
for ( i = 0; i < NumOutClusters; ++i )
{
*pBuf++ = LO_UINT16(OutClusterList[i]);
*pBuf++ = HI_UINT16(OutClusterList[i]);
}
return fillAndSend( &ZDP_TransID, dstAddr, End_Device_Bind_req, len );
}
#endif // ZDO_ENDDEVICEBIND_REQUEST
#if defined ( ZDO_BIND_UNBIND_REQUEST ) || defined ( ZDO_COORDINATOR )
/*********************************************************************
* @fn ZDP_BindUnbindReq
*
* @brief This builds and send a Bind_req or Unbind_req message
* Depending on the ClusterID. This function
* sends a unicast message to the local coordinator.
*
* @param BindOrUnbind - either Bind_req or Unbind_req
* @param dstAddr - destination address of the message
* @param SourceAddr - source 64 bit address of the binding
* @param SrcEPIntf - Source endpoint/interface
* @param ClusterID - Binding cluster ID
* @param DestinationAddr - destination 64 bit addr of binding
* @param DstEPIntf - destination endpoint/interface
* @param SecurityEnable - Security Options
*
* @return afStatus_t
*/
afStatus_t ZDP_BindUnbindReq( uint16 BindOrUnbind, zAddrType_t *dstAddr,
byte *SourceAddr, byte SrcEndPoint,
cId_t ClusterID,
zAddrType_t *destinationAddr, byte DstEndPoint,
byte SecurityEnable )
{
uint8 *pBuf = ZDP_TmpBuf;
byte len;
// SourceAddr + SrcEPIntf + ClusterID + addrMode.
len = Z_EXTADDR_LEN + 1 + sizeof( cId_t ) + sizeof( uint8 );
if ( destinationAddr->addrMode == Addr64Bit )
len += Z_EXTADDR_LEN + 1; // +1 for DstEPIntf
else if ( destinationAddr->addrMode == AddrGroup )
len += sizeof ( uint16 );
pBuf = osal_cpyExtAddr( pBuf, SourceAddr );
*pBuf++ = SrcEndPoint;
*pBuf++ = LO_UINT16( ClusterID );
*pBuf++ = HI_UINT16( ClusterID );
*pBuf++ = destinationAddr->addrMode;
if ( destinationAddr->addrMode == Addr64Bit )
{
pBuf = osal_cpyExtAddr( pBuf, destinationAddr->addr.extAddr );
*pBuf = DstEndPoint;
}
else if ( destinationAddr->addrMode == AddrGroup )
{
*pBuf++ = LO_UINT16( destinationAddr->addr.shortAddr );
*pBuf++ = HI_UINT16( destinationAddr->addr.shortAddr );
}
FillAndSendTxOptions( &ZDP_TransID, dstAddr, BindOrUnbind, len, AF_MSG_ACK_REQUEST );
}
#endif // ZDO_BIND_UNBIND_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 )
{
byte *pBuf = ZDP_TmpBuf;
byte len = sizeof( uint32 )+1+1; // ScanChannels + ScanDuration + StartIndex.
*pBuf++ = BREAK_UINT32( ScanChannels, 0 );
*pBuf++ = BREAK_UINT32( ScanChannels, 1 );
*pBuf++ = BREAK_UINT32( ScanChannels, 2 );
*pBuf++ = BREAK_UINT32( ScanChannels, 3 );
*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,
byte *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
/*********************************************************************
* 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 )
{
byte *buf;
byte *pBuf;
byte len = 1+1+1+1; // Status + NetworkCount + StartIndex + NetworkCountList.
byte idx;
len += ((NetworkListCount - StartIndex) * ( 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++ )
{
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
#if defined ( ZDO_MGMT_LQI_RESPONSE ) && defined ( RTR_NWK )
/*********************************************************************
* @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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -