📄 zdprofile.c
字号:
/**************************************************************************************************
Filename: ZDProfile.c
Revised: $Date: 2007-10-28 18:43:04 -0700 (Sun, 28 Oct 2007) $
Revision: $Revision: 15800 $
Description: This is the Zigbee Device Profile.
Copyright 2004-2007 Texas Instruments Incorporated. All rights reserved.
IMPORTANT: Your use of this Software is limited to those specific rights
granted under the terms of a software license agreement between the user
who downloaded the software, his/her employer (which must be your employer)
and Texas Instruments Incorporated (the "License"). You may not use this
Software unless you agree to abide by the terms of the License. The License
limits your use, and you acknowledge, that the Software may not be modified,
copied or distributed unless embedded on a Texas Instruments microcontroller
or used solely and exclusively in conjunction with a Texas Instruments radio
frequency transceiver, which is integrated into your product. Other than for
the foregoing purpose, you may not use, reproduce, copy, prepare derivative
works of, modify, distribute, perform, display or sell this Software and/or
its documentation for any purpose.
YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
PROVIDED 揂S IS?WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
Should you have any questions regarding your right to use this Software,
contact Texas Instruments Incorporated at www.TI.com.
**************************************************************************************************/
/*********************************************************************
* INCLUDES
*/
#include "ZComdef.h"
#include "OSAL.h"
#include "AF.h"
#include "NLMEDE.h"
#include "nwk_util.h"
#include "APS.h"
#include "AddrMgr.h"
#include "ZDConfig.h"
#include "ZDProfile.h"
#include "ZDObject.h"
#if defined( LCD_SUPPORTED )
#include "OnBoard.h"
#endif
#include "nwk_util.h"
#if defined( MT_ZDO_FUNC )
#include "MT_ZDO.h"
#endif
/*********************************************************************
* MACROS
*/
#define ZADDR_TO_AFADDR( pZADDR, AFADDR ) { \
(AFADDR).endPoint = ZDP_AF_ENDPOINT; \
(AFADDR).addrMode = (afAddrMode_t)(pZADDR)->addrMode; \
(AFADDR).addr.shortAddr = (pZADDR)->addr.shortAddr; \
}
#define FillAndSendBuffer( TRANSSEQ, ADDR, ID, LEN, BUF ) { \
afStatus_t stat; \
ZDP_TmpBuf = (BUF)+1; \
stat = fillAndSend( (TRANSSEQ), (ADDR), (ID), (LEN) ); \
osal_mem_free( (BUF) ); \
ZDP_TmpBuf = ZDP_Buf+1; \
return stat; \
}
#define FillAndSendTxOptions( TRANSSEQ, ADDR, ID, LEN, TxO ) { \
afStatus_t stat; \
ZDP_TxOptions = (TxO); \
stat = fillAndSend( (TRANSSEQ), (ADDR), (ID), (LEN) ); \
ZDP_TxOptions = AF_TX_OPTIONS_NONE; \
return stat; \
}
/*********************************************************************
* CONSTANTS
*/
#define ZDP_BUF_SZ 80
CONST byte ZDP_AF_ENDPOINT = 0;
/*********************************************************************
* TYPEDEFS
*/
typedef struct
{
void *next;
uint8 taskID;
uint16 clusterID;
} ZDO_MsgCB_t;
/*********************************************************************
* GLOBAL VARIABLES
*/
byte ZDP_TransID = 0;
/*********************************************************************
* EXTERNAL VARIABLES
*/
extern endPointDesc_t ZDApp_epDesc;
/*********************************************************************
* EXTERNAL FUNCTIONS
*/
/*********************************************************************
* LOCAL FUNCTIONS
*/
static afStatus_t fillAndSend( uint8 *transSeq, zAddrType_t *addr, cId_t clusterID, byte len );
uint8 ZDO_SendMsgCBs( zdoIncomingMsg_t *inMsg );
void zdpProcessAddrReq( zdoIncomingMsg_t *inMsg );
/*********************************************************************
* LOCAL VARIABLES
*/
static uint8 ZDP_Buf[ ZDP_BUF_SZ ];
static uint8 *ZDP_TmpBuf = ZDP_Buf+1;
static byte ZDP_TxOptions = AF_TX_OPTIONS_NONE;
ZDO_MsgCB_t *zdoMsgCBs = (ZDO_MsgCB_t *)NULL;
/*********************************************************************
* ZDO Message Processing table
*/
typedef void (*pfnZDPMsgProcessor)( zdoIncomingMsg_t *inMsg );
typedef struct
{
uint16 clusterID;
pfnZDPMsgProcessor pFn;
} zdpMsgProcItem_t;
CONST zdpMsgProcItem_t zdpMsgProcs[] =
{
{ NWK_addr_req, zdpProcessAddrReq },
{ IEEE_addr_req, zdpProcessAddrReq },
{ Node_Desc_req, ZDO_ProcessNodeDescReq },
{ Power_Desc_req, ZDO_ProcessPowerDescReq },
{ Simple_Desc_req, ZDO_ProcessSimpleDescReq },
{ Active_EP_req, ZDO_ProcessActiveEPReq },
{ Match_Desc_req, ZDO_ProcessMatchDescReq },
#if defined ( ZDO_MGMT_NWKDISC_RESPONSE )
{ Mgmt_NWK_Disc_req, ZDO_ProcessMgmtNwkDiscReq },
#endif
#if defined ( ZDO_MGMT_LQI_RESPONSE ) && defined ( RTR_NWK )
{ Mgmt_Lqi_req, ZDO_ProcessMgmtLqiReq },
#endif
#if defined ( ZDO_MGMT_RTG_RESPONSE ) && defined ( RTR_NWK )
{ Mgmt_Rtg_req, ZDO_ProcessMgmtRtgReq },
#endif
#if defined ( ZDO_MGMT_BIND_RESPONSE ) && defined ( REFLECTOR )
{ Mgmt_Bind_req, ZDO_ProcessMgmtBindReq },
#endif
#if defined ( ZDO_MGMT_JOINDIRECT_RESPONSE ) && defined ( RTR_NWK )
{ Mgmt_Direct_Join_req, ZDO_ProcessMgmtDirectJoinReq },
#endif
#if defined ( ZDO_MGMT_LEAVE_RESPONSE )
{ Mgmt_Leave_req, ZDO_ProcessMgmtLeaveReq },
#endif
#if defined ( ZDO_MGMT_PERMIT_JOIN_RESPONSE ) && defined ( RTR_NWK )
{ Mgmt_Permit_Join_req, ZDO_ProcessMgmtPermitJoinReq },
#endif
#if defined ( ZDO_USERDESC_RESPONSE )
{ User_Desc_req, ZDO_ProcessUserDescReq },
#endif
#if defined ( ZDO_USERDESCSET_RESPONSE )
{ User_Desc_set, ZDO_ProcessUserDescSet },
#endif
#if defined ( ZDO_SERVERDISC_RESPONSE )
{ Server_Discovery_req, ZDO_ProcessServerDiscReq },
#endif
#if defined ( ZDO_ENDDEVICE_ANNCE ) && defined ( RTR_NWK )
{ End_Device_annce, ZDO_ProcessEndDeviceAnnce },
#endif
{0xFFFF, NULL} // Last
};
/*********************************************************************
* @fn fillAndSend
*
* @brief Combined to reduce space
*
* @param
* @param
*
* @return afStatus_t
*/
static afStatus_t fillAndSend( uint8 *transSeq, zAddrType_t *addr, cId_t clusterID, byte len )
{
afAddrType_t afAddr;
ZADDR_TO_AFADDR( addr, afAddr );
*(ZDP_TmpBuf-1) = *transSeq;
return AF_DataRequest( &afAddr, &ZDApp_epDesc, clusterID,
(uint16)(len+1), (uint8*)(ZDP_TmpBuf-1),
transSeq, ZDP_TxOptions, AF_DEFAULT_RADIUS );
}
/*********************************************************************
* @fn ZDP_SendData
*
* @brief This builds and send a request message that has
* NWKAddrOfInterest as its only parameter.
*
* @param dstAddr - destination address
* @param cmd - clusterID
* @param dataLen - number of bytes of data
* @param data - pointer to the data
* @param SecurityEnable - Security Options
*
* @return afStatus_t
*/
afStatus_t ZDP_SendData( byte *TransSeq, zAddrType_t *dstAddr, uint16 cmd,
byte len, byte *buf, byte SecurityEnable )
{
byte *pBuf = ZDP_TmpBuf;
byte cnt = len;
while ( cnt-- )
{
*pBuf++ = *buf++;
}
FillAndSendTxOptions( TransSeq, dstAddr, cmd, len,
(AF_DEFAULT_RADIUS | ((SecurityEnable) ? AF_EN_SECURITY : 0)) );
}
#if defined ( ZDO_NODEDESC_REQUEST ) || defined ( ZDO_POWERDESC_REQUEST ) ||\
defined ( ZDO_ACTIVEEP_REQUEST ) || defined ( ZDO_COMPLEXDESC_REQUEST ) ||\
defined ( ZDO_USERDESC_REQUEST )
/*********************************************************************
* @fn ZDP_NWKAddrOfInterestReq
*
* @brief This builds and send a request message that has
* NWKAddrOfInterest as its only parameter.
*
* @param dstAddr - destination address
* @param nwkAddr - 16 bit address
* @param SecurityEnable - Security Options
*
* @return afStatus_t
*/
afStatus_t ZDP_NWKAddrOfInterestReq( zAddrType_t *dstAddr, uint16 nwkAddr,
byte cmd, byte SecurityEnable )
{
ZDP_TmpBuf[0] = LO_UINT16( nwkAddr );
ZDP_TmpBuf[1] = HI_UINT16( nwkAddr );
return fillAndSend( &ZDP_TransID, dstAddr, cmd, 2 );
}
#endif // ZDO_NODEDESC_REQUEST ZDO_POWERDESC_REQUEST ZDO_ACTIVEEP_REQUEST ZDO_COMPLEXDESC_REQUEST ZDO_USERDESC_REQUEST
/*********************************************************************
* Address Requests
*/
#if defined ( ZDO_NWKADDR_REQUEST )
/*********************************************************************
* @fn ZDP_NwkAddrReq
*
* @brief This builds and send a NWK_addr_req message. This
* function sends a broadcast message looking for a 16
* bit address with a 64 bit address as bait.
*
* @param IEEEAddress - looking for this device
* @param SecurityEnable - Security Options
*
* @return afStatus_t
*/
afStatus_t ZDP_NwkAddrReq( byte *IEEEAddress, byte ReqType,
byte StartIndex, byte SecurityEnable )
{
byte *pBuf = ZDP_TmpBuf;
byte len = Z_EXTADDR_LEN + 1 + 1; // IEEEAddress + ReqType + StartIndex.
zAddrType_t dstAddr;
if ( osal_ExtAddrEqual( saveExtAddr, IEEEAddress ) == FALSE )
{
dstAddr.addrMode = AddrBroadcast;
dstAddr.addr.shortAddr = NWK_BROADCAST_SHORTADDR;
}
else
{
dstAddr.addrMode = Addr16Bit;
dstAddr.addr.shortAddr = ZDAppNwkAddr.addr.shortAddr;
}
pBuf = osal_cpyExtAddr( pBuf, IEEEAddress );
*pBuf++ = ReqType;
*pBuf++ = StartIndex;
return fillAndSend( &ZDP_TransID, &dstAddr, NWK_addr_req, len );
}
#endif
#if defined ( ZDO_IEEEADDR_REQUEST )
/*********************************************************************
* @fn ZDP_IEEEAddrReq
*
* @brief This builds and send a IEEE_addr_req message. This
* function sends a unicast message looking for a 64
* bit IEEE address with a 16 bit address as bait.
*
* @param ReqType - ZDP_IEEEADDR_REQTYPE_SINGLE or
* ZDP_IEEEADDR_REQTYPE_EXTENDED
* @param SecurityEnable - Security Options
*
* @return afStatus_t
*/
afStatus_t ZDP_IEEEAddrReq( uint16 shortAddr, byte ReqType,
byte StartIndex, byte SecurityEnable )
{
byte *pBuf = ZDP_TmpBuf;
byte len = 2 + 1 + 1; // shortAddr + ReqType + StartIndex.
zAddrType_t dstAddr;
dstAddr.addrMode = (afAddrMode_t)Addr16Bit;
dstAddr.addr.shortAddr = shortAddr;
*pBuf++ = LO_UINT16( shortAddr );
*pBuf++ = HI_UINT16( shortAddr );
*pBuf++ = ReqType;
*pBuf++ = StartIndex;
return fillAndSend( &ZDP_TransID, &dstAddr, IEEE_addr_req, len );
}
#endif
#if defined ( ZDO_MATCH_REQUEST )
/*********************************************************************
* @fn ZDP_MatchDescReq
*
* @brief This builds and send a Match_Desc_req message. This
* function sends a broadcast or unicast message
* requesting the list of endpoint/interfaces that
* match profile ID and cluster IDs.
*
* @param dstAddr - destination address
* @param ProfileID - Profile ID
* @param NumInClusters - number of input clusters
* @param InClusterList - input cluster ID list
* @param NumOutClusters - number of output clusters
* @param OutClusterList - output cluster ID list
* @param SecurityEnable - Security Options
*
* @return afStatus_t
*/
afStatus_t ZDP_MatchDescReq( zAddrType_t *dstAddr, uint16 nwkAddr,
uint16 ProfileID,
byte NumInClusters, cId_t *InClusterList,
byte NumOutClusters, cId_t *OutClusterList,
byte SecurityEnable )
{
byte *pBuf = ZDP_TmpBuf;
// nwkAddr+ProfileID+NumInClusters+NumOutClusters.
byte i, len = 2 + 2 + 1 + 1; // nwkAddr+ProfileID+NumInClusters+NumOutClusters.
len += (NumInClusters + NumOutClusters) * sizeof(uint16);
if ( len >= ZDP_BUF_SZ-1 )
{
return afStatus_MEM_FAIL;
}
*pBuf++ = LO_UINT16( nwkAddr ); // NWKAddrOfInterest
*pBuf++ = HI_UINT16( nwkAddr );
*pBuf++ = LO_UINT16( ProfileID ); // Profile ID
*pBuf++ = HI_UINT16( ProfileID );
*pBuf++ = NumInClusters; // Input cluster list
if ( NumInClusters )
{
for (i=0; i<NumInClusters; ++i) {
*pBuf++ = LO_UINT16( InClusterList[i] );
*pBuf++ = HI_UINT16( InClusterList[i] );
}
}
*pBuf++ = NumOutClusters; // Output cluster list
if ( NumOutClusters )
{
for (i=0; i<NumOutClusters; ++i) {
*pBuf++ = LO_UINT16( OutClusterList[i] );
*pBuf++ = HI_UINT16( OutClusterList[i] );
}
}
return fillAndSend( &ZDP_TransID, dstAddr, Match_Desc_req, len );
}
#endif // ZDO_MATCH_REQUEST
#if defined ( ZDO_SIMPLEDESC_REQUEST )
/*********************************************************************
* @fn ZDP_SimpleDescReq
*
* @brief This builds and send a NWK_Simple_Desc_req
* message. This function sends unicast message to the
* destination device.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -