/**************************************************************************************************
Filename: zcl.c
Revised: $Date: 2009-04-06 09:08:36 -0700 (Mon, 06 Apr 2009) $
Revision: $Revision: 19702 $
Description: This file contains the Zigbee Cluster Library Foundation functions.
Copyright 2006-2009 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 �AS 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 "OSAL_Tasks.h"
#include "AF.h"
#include "ZDConfig.h"
#include "zcl.h"
#include "zcl_general.h"
#if defined ( INTER_PAN )
#include "stub_aps.h"
#endif
/*********************************************************************
* MACROS
*/
/*** Frame Control ***/
#define zcl_FCType( a ) ( (a) & ZCL_FRAME_CONTROL_TYPE )
#define zcl_FCManuSpecific( a ) ( (a) & ZCL_FRAME_CONTROL_MANU_SPECIFIC )
#define zcl_FCDirection( a ) ( (a) & ZCL_FRAME_CONTROL_DIRECTION )
#define zcl_FCDisableDefaultRsp( a ) ( (a) & ZCL_FRAME_CONTROL_DISABLE_DEFAULT_RSP )
/*** Attribute Access Control ***/
#define zcl_AccessCtrlRead( a ) ( (a) & ACCESS_CONTROL_READ )
#define zcl_AccessCtrlWrite( a ) ( (a) & ACCESS_CONTROL_WRITE )
#define zcl_AccessCtrlCmd( a ) ( (a) & ACCESS_CONTROL_CMD )
#define zclParseCmd( a, b ) zclCmdTable[(a)].pfnParseInProfile( (b) )
#define zclProcessCmd( a, b ) zclCmdTable[(a)].pfnProcessInProfile( (b) )
#define zcl_DefaultRspCmd( zclHdr ) ( zcl_ProfileCmd( (zclHdr).fc.type ) && \
(zclHdr).fc.manuSpecific == 0 && \
(zclHdr).commandID == ZCL_CMD_DEFAULT_RSP )
// Commands that have corresponding responses
#define CMD_HAS_RSP( cmd ) ( (cmd) == ZCL_CMD_READ || \
(cmd) == ZCL_CMD_WRITE || \
(cmd) == ZCL_CMD_WRITE_UNDIVIDED || \
(cmd) == ZCL_CMD_CONFIG_REPORT || \
(cmd) == ZCL_CMD_READ_REPORT_CFG || \
(cmd) == ZCL_CMD_DISCOVER || \
(cmd) == ZCL_CMD_DEFAULT_RSP ) // exception
/*********************************************************************
* CONSTANTS
*/
/*********************************************************************
* TYPEDEFS
*/
typedef struct zclLibPlugin
{
struct zclLibPlugin *next;
uint16 startClusterID; // starting cluster ID
uint16 endClusterID; // ending cluster ID
zclInHdlr_t pfnIncomingHdlr; // function to handle incoming message
} zclLibPlugin_t;
// Attribute record list item
typedef struct zclAttrRecsList
{
struct zclAttrRecsList *next;
uint8 endpoint; // Used to link it into the endpoint descriptor
uint8 numAttributes; // Number of the following records
CONST zclAttrRec_t *attrs; // attribute records
} zclAttrRecsList;
// Cluster option list item
typedef struct zclClusterOptionList
{
struct zclClusterOptionList *next;
uint8 endpoint; // Used to link it into the endpoint descriptor
uint8 numOptions; // Number of the following records
zclOptionRec_t *options; // option records
} zclClusterOptionList;
typedef void *(*zclParseInProfileCmd_t)( zclParseCmd_t *pCmd );
typedef uint8 (*zclProcessInProfileCmd_t)( zclIncoming_t *pInMsg );
typedef struct
{
zclParseInProfileCmd_t pfnParseInProfile;
zclProcessInProfileCmd_t pfnProcessInProfile;
} zclCmdItems_t;
/*********************************************************************
* GLOBAL VARIABLES
*/
uint8 zcl_TaskID;
// The task Id of the Application where the unprocessed Foundation
// Command/Response messages will be sent to.
uint8 zcl_RegisteredMsgTaskID = TASK_NO_TASK;
// The Application should register its attribute data validation function
zclValidateAttrData_t zcl_ValidateAttrDataCB = NULL;
// ZCL Sequence number
uint8 zcl_SeqNum = 0x00;
/*********************************************************************
* EXTERNAL VARIABLES
*/
/*********************************************************************
* EXTERNAL FUNCTIONS
*/
/*********************************************************************
* LOCAL VARIABLES
*/
static zclLibPlugin_t *plugins;
static zclAttrRecsList *attrList;
static zclClusterOptionList *clusterOptionList;
static uint8 zcl_TransID = 0; // This is the unique message ID (counter)
/*********************************************************************
* LOCAL FUNCTIONS
*/
static void zclProcessMessageMSG( afIncomingMSGPacket_t *pkt );
static uint8 *zclBuildHdr( zclFrameHdr_t *hdr, uint8 *pData );
static uint8 zclCalcHdrSize( zclFrameHdr_t *hdr );
static zclLibPlugin_t *zclFindPlugin( uint16 clusterID, uint16 profileID );
static zclOptionRec_t *zclFindClusterOption( uint8 endpoint, uint16 clusterID );
static uint8 zclGetClusterOption( uint8 endpoint, uint16 clusterID );
static void zclSetSecurityOption( uint8 endpoint, uint16 clusterID, uint8 enable );
static uint8 zcl_DeviceOperational( uint8 srcEP, uint16 clusterID, uint8 frameType, uint8 cmd, uint16 profileID );
#if defined(ZCL_READ) || defined(ZCL_WRITE) || defined(ZCL_REPORT)
static void zclSerializeData( uint8 dataType, void *attrData, uint8 *buf );
#endif // ZCL_READ || ZCL_WRITE || ZCL_REPORT
#ifdef ZCL_READ
static void *zclParseInReadRspCmd( zclParseCmd_t *pCmd );
static uint8 zclProcessInReadCmd( zclIncoming_t *pInMsg );
#endif // ZCL_READ
#ifdef ZCL_WRITE
static uint8 zclWriteAttrData( zclAttrRec_t *pAttr, zclWriteRec_t *pWriteRec );
static voi
- 1
- 2
前往页