/*********************************************************************
Filename: ZDApp.c
Revised: $Date: 2007-05-31 15:56:04 -0700 (Thu, 31 May 2007) $
Revision: $Revision: 14490 $
Description:
This file contains the interface to the Zigbee Device Application.
This is the Application part that the use can change. This also
contains the Task functions.
Notes:
Copyright (c) 2006 by Texas Instruments, Inc.
All Rights Reserved. Permission to use, reproduce, copy, prepare
derivative works, modify, distribute, perform, display or sell this
software and/or its documentation for any purpose is prohibited
without the express written consent of Texas Instruments, Inc.
*********************************************************************/
/*********************************************************************
* INCLUDES
*/
#include "ZComDef.h"
#include "ZMac.h"
#include "OSAL.h"
#include "OSAL_Tasks.h"
#include "OSAL_PwrMgr.h"
#include "OSAL_Nv.h"
#include "AF.h"
#include "APSMEDE.h"
#include "NLMEDE.h"
#include "AddrMgr.h"
#include "ZDCache.h"
#include "ZDProfile.h"
#include "ZDObject.h"
#include "ZDConfig.h"
#include "ZDSecMgr.h"
#include "ZDApp.h"
#include "DebugTrace.h"
#include "nwk_util.h"
#include "OnBoard.h"
#include "ZGlobals.h"
#if ( SECURE != 0 )
#include "ssp.h"
#endif
#if defined( MT_ZDO_FUNC )
#include "MT_ZDO.h"
#endif
#include "string.h"
#include "stdio.h"
#include "stdlib.h"
/* HAL */
#include "hal_led.h"
#include "hal_lcd.h"
#include "hal_key.h"
#if defined( MT_MAC_FUNC ) || defined( MT_MAC_CB_FUNC )
#error "ERROR! MT_MAC functionalities should be disabled on ZDO devices"
#endif
/*********************************************************************
* MACROS
*/
/*********************************************************************
* CONSTANTS
*/
#if !defined( NWK_START_DELAY )
#define NWK_START_DELAY 100 // in milliseconds
#endif
#if !defined( EXTENDED_JOINING_RANDOM_MASK )
#define EXTENDED_JOINING_RANDOM_MASK 0x007F
#endif
#if !defined( BEACON_REQUEST_DELAY )
#define BEACON_REQUEST_DELAY 100 // in milliseconds
#endif
#if !defined( BEACON_REQ_DELAY_MASK )
#define BEACON_REQ_DELAY_MASK 0x007F
#endif
#if defined (AUTO_SOFT_START)
#define MAX_RESUME_RETRY 3
#define NUM_DISC_ATTEMPTS 3
#else
#define MAX_RESUME_RETRY 1
#endif
#define MAX_DEVICE_UNAUTH_TIMEOUT 5000 // 5 seconds
// Beacon Order Settings (see NLMEDE.h)
#define DEFAULT_BEACON_ORDER BEACON_ORDER_NO_BEACONS
#define DEFAULT_SUPERFRAME_ORDER DEFAULT_BEACON_ORDER
#if ( SECURE != 0 )
#if !defined( MAX_NWK_FRAMECOUNTER_CHANGES )
// The number of times the frame counter can change before
// saving to NV
#define MAX_NWK_FRAMECOUNTER_CHANGES 1000
#endif
#endif
// Leave control bits
#define ZDAPP_LEAVE_CTRL_INIT 0
#define ZDAPP_LEAVE_CTRL_SET 1
#define ZDAPP_LEAVE_CTRL_RA 2
// Standard time to update NWK NV data
#define ZDAPP_UPDATE_NWK_NV_TIME 100
// Address Manager Stub Implementation
#define ZDApp_NwkWriteNVRequest AddrMgrWriteNVRequest
/*********************************************************************
* TYPEDEFS
*/
/*********************************************************************
* GLOBAL VARIABLES
*/
#if defined( LCD_SUPPORTED )
byte MatchRsps = 0;
#endif
byte zdoDiscCounter = 1;
zAddrType_t ZDAppNwkAddr;
#if defined ( ZDO_MGMT_NWKDISC_RESPONSE )
byte zdappMgmtNwkDiscRspTransSeq;
byte zdappMgmtNwkDiscReqInProgress = FALSE;
zAddrType_t zdappMgmtNwkDiscRspAddr;
byte zdappMgmtNwkDiscStartIndex;
byte zdappMgmtSavedNwkState;
#endif
#if ( SECURE != 0 )
uint16 nwkFrameCounterChanges = 0;
#endif
#if defined ( SOFT_START )
static uint8 softStartAllowCoord = TRUE;
#endif
uint8 continueJoining = TRUE;
byte _tmpRejoinState;
/*********************************************************************
* EXTERNAL VARIABLES
*/
/*********************************************************************
* EXTERNAL FUNCTIONS
*/
/*********************************************************************
* LOCAL FUNCTIONS
*/
void ZDApp_NetworkStartEvt( void );
void ZDApp_DeviceAuthEvt( void );
void ZDApp_SaveNetworkStateEvt( void );
uint8 ZDApp_ReadNetworkRestoreState( void );
uint8 ZDApp_RestoreNetworkState( void );
void ZDAppDetermineDeviceType( void );
void ZDAppSetupProtoVersion( void );
void ZDApp_InitUserDesc( void );
void ZDAppCheckForHoldKey( void );
void ZDApp_ProcessOSALMsg( osal_event_hdr_t *msgPtr );
void ZDApp_ProcessNetworkJoin( void );
void ZDApp_SetCoordAddress( byte endPoint, byte dstEP );
void ZDApp_SendNewDstAddr( byte dstEP, zAddrType_t *dstAddr,
cId_t clusterID, byte removeFlag, byte task_id, byte endpoint );
#if ( SECURE != 0 )
void ZDApp_SaveNwkKey( void );
byte ZDApp_RestoreNwkKey( void );
#endif
void ZDApp_SendMsg( byte taskID, byte cmd, byte len, byte *buf );
#if defined ( ZDO_BIND_UNBIND_RESPONSE ) && !defined ( REFLECTOR )
extern void ZDApp_AppBindReq( byte TransSeq, zAddrType_t *SrcAddr, byte *SrcAddress,
byte SrcEndPoint, cId_t ClusterID, byte *DstAddress,
byte DstEndPoint, byte SecurityUse, uint8 Type );
#endif
void ZDApp_ResetTimerStart( uint16 delay );
void ZDApp_ResetTimerCancel( void );
void ZDApp_LeaveCtrlInit( void );
void ZDApp_LeaveCtrlSet( uint8 ra );
uint8 ZDApp_LeaveCtrlBypass( void );
void ZDApp_LeaveCtrlStartup( devStates_t* state, uint16* startDelay );
void ZDApp_LeaveReset( uint8 ra );
void ZDApp_LeaveUpdate( uint16 nwkAddr, uint8* extAddr,
uint8 removeChildren );
void ZDApp_NodeProfileSync( ZDO_NetworkDiscoveryCfm_t* cfm );
/*********************************************************************
* LOCAL VARIABLES
*/
byte ZDAppTaskID;
byte nwkStatus;
endPointDesc_t *ZDApp_AutoFindMode_epDesc = (endPointDesc_t *)NULL;
uint8 ZDApp_LeaveCtrl;
#if defined( HOLD_AUTO_START )
devStates_t devState = DEV_HOLD;
#else
devStates_t devState = DEV_INIT;
#endif
#if defined( ZDO_COORDINATOR ) && !defined( SOFT_START )
// Set the default to coodinator
devStartModes_t devStartMode = MODE_HARD;
#else
devStartModes_t devStartMode = MODE_JOIN; // Assume joining
//devStartModes_t devStartMode = MODE_RESUME; // if already "directly joined"
// to parent. Set to make the device do an Orphan scan.
#endif
#if defined ( ZDO_IEEEADDR_REQUEST )
static byte ZDApp_IEEEAddrRsp_TaskID = 0; // Initialized to NO TASK
#endif
#if defined ( ZDO_NWKADDR_REQUEST )
static byte ZDApp_NwkAddrRsp_TaskID = 0; // Initialized to NO TASK
#endif
static byte ZDApp_MatchDescRsp_TaskID = 0; // Initialized to NO TASK
static byte ZDApp_EndDeviceAnnounce_TaskID = 0; // Initialized to NO TASK
#if defined ( ZDO_BIND_UNBIND_REQUEST )
static byte ZDApp_BindUnbindRsp_TaskID = TASK_NO_TASK;
#endif
#if defined ( ZDO_BIND_UNBIND_RESPONSE ) && !defined ( REFLECTOR )
static byte ZDApp_BindReq_TaskID = 0; // Initialized to NO TASK
#endif
#if defined ( ZDO_MGMT_BIND_RESPONSE ) && !defined ( REFLECTOR )
static byte ZDApp_MgmtBindReq_TaskID = 0; // Initialized to NO TASK
#endif
#if !defined( ZDO_COORDINATOR ) || defined( SOFT_START )
static uint8 retryCnt;
#endif
// a little awkward -- this is will hold the list of versions that are legal given other
// constraints such as NV value, macro values etc. list used in ZDO_NetworkDiscoveryConfirmCB()
// when a joining device is deciding which network to join.
static byte sPVerList[] = {ZB_PROT_V1_1, ZB_PROT_V1_0};
endPointDesc_t ZDApp_epDesc =
{
ZDO_EP,
&ZDAppTaskID,
(SimpleDescriptionFormat_t *)NULL, // N
评论3
最新资源