📄 zdprofile.c
字号:
*
* @return afStatus_t
*/
afStatus_t ZDP_PowerDescMsg( zdoIncomingMsg_t *inMsg,
uint16 nwkAddr, NodePowerDescriptorFormat_t *pPowerDesc )
{
uint8 *pBuf = ZDP_TmpBuf;
byte len = 1 + 2 + 2; // Status + nwkAddr + Node Power descriptor.
*pBuf++ = ZDP_SUCCESS;
*pBuf++ = LO_UINT16( nwkAddr );
*pBuf++ = HI_UINT16( nwkAddr );
*pBuf++ = (byte)((pPowerDesc->AvailablePowerSources << 4)
| (pPowerDesc->PowerMode & 0x0F));
*pBuf++ = (byte)((pPowerDesc->CurrentPowerSourceLevel << 4)
| (pPowerDesc->CurrentPowerSource & 0x0F));
return fillAndSend( &(inMsg->TransSeq), &(inMsg->srcAddr), Power_Desc_rsp, len );
}
/*********************************************************************
* @fn ZDP_SimpleDescMsg
*
* @brief Builds and sends a Simple Descriptor message, unicast to the
* specified device.
*
* @param inMsg - incoming message (request)
* @param Status - message status (ZDP_SUCCESS or other)
* @param pSimpleDesc - pointer to the node descriptor
*
* @return afStatus_t
*/
afStatus_t ZDP_SimpleDescMsg( zdoIncomingMsg_t *inMsg, byte Status,
SimpleDescriptionFormat_t *pSimpleDesc )
{
uint8 *pBuf = ZDP_TmpBuf;
uint8 i, len;
if ( Status == ZDP_SUCCESS && pSimpleDesc )
{
// Status + NWKAddrOfInterest + desc length + empty simple descriptor.
len = 1 + 2 + 1 + 8;
len += (pSimpleDesc->AppNumInClusters + pSimpleDesc->AppNumOutClusters) * sizeof ( uint16 );
}
else
{
len = 1 + 2 + 1; // Status + desc length
}
if ( len >= ZDP_BUF_SZ-1 )
{
return afStatus_MEM_FAIL;
}
*pBuf++ = Status;
*pBuf++ = LO_UINT16( ZDAppNwkAddr.addr.shortAddr );
*pBuf++ = HI_UINT16( ZDAppNwkAddr.addr.shortAddr );
if ( len > 4 )
{
*pBuf++ = len - 4; // Simple descriptor length
*pBuf++ = pSimpleDesc->EndPoint;
*pBuf++ = LO_UINT16( pSimpleDesc->AppProfId );
*pBuf++ = HI_UINT16( pSimpleDesc->AppProfId );
*pBuf++ = LO_UINT16( pSimpleDesc->AppDeviceId );
*pBuf++ = HI_UINT16( pSimpleDesc->AppDeviceId );
*pBuf++ = (byte)(pSimpleDesc->AppDevVer << 4);
*pBuf++ = pSimpleDesc->AppNumInClusters;
if ( pSimpleDesc->AppNumInClusters )
{
for (i=0; i<pSimpleDesc->AppNumInClusters; ++i)
{
*pBuf++ = LO_UINT16( pSimpleDesc->pAppInClusterList[i] );
*pBuf++ = HI_UINT16( pSimpleDesc->pAppInClusterList[i] );
}
}
*pBuf++ = pSimpleDesc->AppNumOutClusters;
if ( pSimpleDesc->AppNumOutClusters )
{
for (i=0; i<pSimpleDesc->AppNumOutClusters; ++i)
{
*pBuf++ = LO_UINT16( pSimpleDesc->pAppOutClusterList[i] );
*pBuf++ = HI_UINT16( pSimpleDesc->pAppOutClusterList[i] );
}
}
}
else
{
*pBuf = 0; // Description Length = 0;
}
return fillAndSend( &(inMsg->TransSeq), &(inMsg->srcAddr), Simple_Desc_rsp, len );
}
/*********************************************************************
* @fn ZDP_EPRsp
*
* @brief This builds and send an endpoint list. Used in
* Active_EP_rsp and Match_Desc_Rsp
* message. This function sends unicast message to the
* requesting device.
*
* @param MsgType - either Active_EP_rsp or Match_Desc_Rsp
* @param dstAddr - destination address
* @param Status - message status (ZDP_SUCCESS or other)
* @param nwkAddr - Device's short address that this response describes
* @param Count - number of endpoint/interfaces in list
* @param pEPIntfList - Array of Endpoint/Interfaces
* @param SecurityEnable - Security Options
*
* @return afStatus_t
*/
afStatus_t ZDP_EPRsp( uint16 MsgType, byte TransSeq, zAddrType_t *dstAddr,
byte Status, uint16 nwkAddr, byte Count,
uint8 *pEPList,
byte SecurityEnable )
{
uint8 *pBuf = ZDP_TmpBuf;
byte len = 1 + 2 + 1; // Status + nwkAddr + endpoint/interface count.
byte txOptions;
if ( MsgType == Match_Desc_rsp )
txOptions = AF_MSG_ACK_REQUEST;
else
txOptions = 0;
*pBuf++ = Status;
*pBuf++ = LO_UINT16( nwkAddr );
*pBuf++ = HI_UINT16( nwkAddr );
*pBuf++ = Count; // Endpoint/Interface count
if ( Count )
{
len += Count;
osal_memcpy( pBuf, pEPList, Count );
}
FillAndSendTxOptions( &TransSeq, dstAddr, MsgType, len, txOptions );
}
/*********************************************************************
* @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 )
{
uint8 *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 );
}
/*********************************************************************
* @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.
uint8 *pBuf = ZDP_TmpBuf;
*pBuf++ = status;
*pBuf++ = LO_UINT16( serverMask );
*pBuf++ = HI_UINT16( serverMask );
return (ZStatus_t)fillAndSend( &transID, dstAddr, Server_Discovery_rsp, len );
}
/*********************************************************************
* @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
/*********************************************************************
* @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,
uint8 *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 );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -