123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670 |
- /**************************************************************************************************
- Filename: ZGlobals.c
- Revised: $Date: 2012-04-02 17:02:19 -0700 (Mon, 02 Apr 2012) $
- Revision: $Revision: 29996 $
- Description: User definable Z-Stack parameters.
- Copyright 2007-2011 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_Nv.h"
- #include "ZDObject.h"
- #include "ZGlobals.h"
- #include "ZDNwkMgr.h"
- #include "OnBoard.h"
- #include "ZDSecMgr.h"
- /*********************************************************************
- * MACROS
- */
- /*********************************************************************
- * CONSTANTS
- */
- /*********************************************************************
- * TYPEDEFS
- */
- typedef struct zgItem
- {
- uint16 id;
- uint16 len;
- void *buf;
- } zgItem_t;
- /*********************************************************************
- * NWK GLOBAL VARIABLES
- */
- // Polling values
- uint16 zgPollRate = POLL_RATE;
- uint16 zgQueuedPollRate = QUEUED_POLL_RATE;
- uint16 zgResponsePollRate = RESPONSE_POLL_RATE;
- uint16 zgRejoinPollRate = REJOIN_POLL_RATE;
- // Transmission retries numbers
- uint8 zgMaxDataRetries = NWK_MAX_DATA_RETRIES;
- uint8 zgMaxPollFailureRetries = MAX_POLL_FAILURE_RETRIES;
- // Default channel list
- uint32 zgDefaultChannelList = DEFAULT_CHANLIST;
- // Default starting scan duration
- uint8 zgDefaultStartingScanDuration = STARTING_SCAN_DURATION;
- // Stack profile Id
- uint8 zgStackProfile = STACK_PROFILE_ID;
- // Default indirect message holding timeout
- uint8 zgIndirectMsgTimeout = NWK_INDIRECT_MSG_TIMEOUT;
- // Security mode
- uint8 zgSecurityMode = ZG_SECURITY_MODE;
- // Secure permit join
- uint8 zgSecurePermitJoin = true;
- // Trust center address
- uint16 zgTrustCenterAddr = ZG_TRUSTCENTER_ADDR;
- // Route Discovery Time - amount of time that a route request lasts
- uint8 zgRouteDiscoveryTime = ROUTE_DISCOVERY_TIME;
- // Route expiry
- uint8 zgRouteExpiryTime = ROUTE_EXPIRY_TIME;
- // Extended PAN Id
- uint8 zgExtendedPANID[Z_EXTADDR_LEN];
- // Broadcast parameters
- uint8 zgMaxBcastRetires = MAX_BCAST_RETRIES;
- uint8 zgPassiveAckTimeout = PASSIVE_ACK_TIMEOUT;
- uint8 zgBcastDeliveryTime = BCAST_DELIVERY_TIME;
- // Network mode
- uint8 zgNwkMode = NWK_MODE;
- // Many-to-one values
- uint8 zgConcentratorEnable = CONCENTRATOR_ENABLE;
- uint8 zgConcentratorDiscoveryTime = CONCENTRATOR_DISCOVERY_TIME;
- uint8 zgConcentratorRadius = CONCENTRATOR_RADIUS;
- uint8 zgConcentratorRC = CONCENTRATOR_ROUTE_CACHE; // concentrator with route cache (no memory constraints)
- uint8 zgNwkSrcRtgExpiryTime = SRC_RTG_EXPIRY_TIME;
- // Cleanup Child Table according to routing traffic
- uint8 zgRouterOffAssocCleanup = FALSE;
- /*********************************************************************
- * APS GLOBAL VARIABLES
- */
- // The maximum number of retries allowed after a transmission failure
- uint8 zgApscMaxFrameRetries = APSC_MAX_FRAME_RETRIES;
- // The maximum number of seconds (milliseconds) to wait for an
- // acknowledgement to a transmitted frame.
- // This number is used by polled devices.
- uint16 zgApscAckWaitDurationPolled = APSC_ACK_WAIT_DURATION_POLLED;
- // This number is used by non-polled devices in the following formula:
- // (100 mSec) * (_NIB.MaxDepth * zgApsAckWaitMultiplier)
- uint8 zgApsAckWaitMultiplier = 2;
- // The maximum number of milliseconds for the end device binding
- uint16 zgApsDefaultMaxBindingTime = APS_DEFAULT_MAXBINDING_TIME;
- // The 64-big identifier of the network to join or form.
- // Default set to all zeros
- uint8 zgApsUseExtendedPANID[Z_EXTADDR_LEN] = {00,00,00,00,00,00,00,00};
- // A boolean flag that indicates whether it is OK to use insecure join
- // on startup. Default set to true
- uint8 zgApsUseInsecureJoin = TRUE;
- // The radius of broadcast multicast transmissions
- uint8 zgApsNonMemberRadius = APS_DEFAULT_NONMEMBER_RADIUS;
- /*********************************************************************
- * SECURITY GLOBAL VARIABLES
- */
- // If true, preConfigKey should be configured on all devices on the network
- // If false, it is configured only on the coordinator and sent to other
- // devices upon joining.
- uint8 zgPreConfigKeys = FALSE;// TRUE;
- // If true, defaultTCLinkKey should be configured on all devices on the
- // network. If false, individual trust center link key between each device and
- // the trust center should be manually configured via MT_WRITE_NV
- uint8 zgUseDefaultTCLK = TRUE; // FALSE
- /*********************************************************************
- * ZDO GLOBAL VARIABLES
- */
- // Configured PAN ID
- uint16 zgConfigPANID = ZDAPP_CONFIG_PAN_ID;
- // Device Logical Type
- uint8 zgDeviceLogicalType = DEVICE_LOGICAL_TYPE;
- // Startup Delay
- uint8 zgStartDelay = START_DELAY;
- #if !defined MT_TASK
- // Flag to use verbose (i.e. "cc2480-style") direct MT callbacks in ZDProfile.c, ZDP_IncomingData().
- uint8 zgZdoDirectCB = FALSE;
- #endif
- // Min number of attempted transmissions for Channel Interference detection
- uint8 zgNwkMgrMinTransmissions = ZDNWKMGR_MIN_TRANSMISSIONS;
- /*********************************************************************
- * APPLICATION GLOBAL VARIABLES
- */
- // Network Manager Mode
- uint8 zgNwkMgrMode = ZDNWKMGR_ENABLE;
- /*********************************************************************
- * NON-STANDARD GLOBAL VARIABLES
- */
- // Simple API Endpoint
- uint8 zgSapiEndpoint = SAPI_ENDPOINT;
- /*********************************************************************
- * LOCAL VARIABLES
- */
- /*********************************************************************
- * ZGlobal Item Table
- */
- static CONST zgItem_t zgItemTable[] =
- {
- #if defined ( NV_INIT )
- #if !defined MT_TASK
- {
- ZCD_NV_ZDO_DIRECT_CB, sizeof(zgZdoDirectCB), &zgZdoDirectCB
- },
- #endif
- {
- ZCD_NV_LOGICAL_TYPE, sizeof(zgDeviceLogicalType), &zgDeviceLogicalType
- },
- {
- ZCD_NV_POLL_RATE, sizeof(zgPollRate), &zgPollRate
- },
- {
- ZCD_NV_QUEUED_POLL_RATE, sizeof(zgQueuedPollRate), &zgQueuedPollRate
- },
- {
- ZCD_NV_RESPONSE_POLL_RATE, sizeof(zgResponsePollRate), &zgResponsePollRate
- },
- {
- ZCD_NV_REJOIN_POLL_RATE, sizeof(zgRejoinPollRate), &zgRejoinPollRate
- },
- {
- ZCD_NV_DATA_RETRIES, sizeof(zgMaxDataRetries), &zgMaxDataRetries
- },
- {
- ZCD_NV_POLL_FAILURE_RETRIES, sizeof(zgMaxPollFailureRetries), &zgMaxPollFailureRetries
- },
- {
- ZCD_NV_CHANLIST, sizeof(zgDefaultChannelList), &zgDefaultChannelList
- },
- {
- ZCD_NV_SCAN_DURATION, sizeof(zgDefaultStartingScanDuration), &zgDefaultStartingScanDuration
- },
- {
- ZCD_NV_STACK_PROFILE, sizeof(zgStackProfile), &zgStackProfile
- },
- {
- ZCD_NV_INDIRECT_MSG_TIMEOUT, sizeof(zgIndirectMsgTimeout), &zgIndirectMsgTimeout
- },
- {
- ZCD_NV_ROUTE_EXPIRY_TIME, sizeof(zgRouteExpiryTime), &zgRouteExpiryTime
- },
- {
- ZCD_NV_EXTENDED_PAN_ID, Z_EXTADDR_LEN, zgExtendedPANID
- },
- {
- ZCD_NV_BCAST_RETRIES, sizeof(zgMaxBcastRetires), &zgMaxBcastRetires
- },
- {
- ZCD_NV_PASSIVE_ACK_TIMEOUT, sizeof(zgPassiveAckTimeout), &zgPassiveAckTimeout
- },
- {
- ZCD_NV_BCAST_DELIVERY_TIME, sizeof(zgBcastDeliveryTime), &zgBcastDeliveryTime
- },
- {
- ZCD_NV_NWK_MODE, sizeof(zgNwkMode), &zgNwkMode
- },
- {
- ZCD_NV_CONCENTRATOR_ENABLE, sizeof(zgConcentratorEnable), &zgConcentratorEnable
- },
- {
- ZCD_NV_CONCENTRATOR_DISCOVERY, sizeof(zgConcentratorDiscoveryTime), &zgConcentratorDiscoveryTime
- },
- {
- ZCD_NV_CONCENTRATOR_RADIUS, sizeof(zgConcentratorRadius), &zgConcentratorRadius
- },
- {
- ZCD_NV_CONCENTRATOR_RC, sizeof(zgConcentratorRC), &zgConcentratorRC
- },
- {
- ZCD_NV_SRC_RTG_EXPIRY_TIME, sizeof(zgNwkSrcRtgExpiryTime), &zgNwkSrcRtgExpiryTime
- },
- {
- ZCD_NV_ROUTE_DISCOVERY_TIME, sizeof(zgRouteDiscoveryTime), &zgRouteDiscoveryTime
- },
- #ifndef NONWK
- {
- ZCD_NV_PANID, sizeof(zgConfigPANID), &zgConfigPANID
- },
- {
- ZCD_NV_PRECFGKEYS_ENABLE, sizeof(zgPreConfigKeys), &zgPreConfigKeys
- },
- {
- ZCD_NV_SECURITY_MODE, sizeof(zgSecurityMode), &zgSecurityMode
- },
- {
- ZCD_NV_SECURE_PERMIT_JOIN, sizeof(zgSecurePermitJoin), &zgSecurePermitJoin
- },
- {
- ZCD_NV_USE_DEFAULT_TCLK, sizeof(zgUseDefaultTCLK), &zgUseDefaultTCLK
- },
- {
- ZCD_NV_TRUSTCENTER_ADDR, sizeof(zgTrustCenterAddr), &zgTrustCenterAddr
- },
- #endif // NONWK
- {
- ZCD_NV_APS_FRAME_RETRIES, sizeof(zgApscMaxFrameRetries), &zgApscMaxFrameRetries
- },
- {
- ZCD_NV_APS_ACK_WAIT_DURATION, sizeof(zgApscAckWaitDurationPolled), &zgApscAckWaitDurationPolled
- },
- {
- ZCD_NV_APS_ACK_WAIT_MULTIPLIER, sizeof(zgApsAckWaitMultiplier), &zgApsAckWaitMultiplier
- },
- {
- ZCD_NV_BINDING_TIME, sizeof(zgApsDefaultMaxBindingTime), &zgApsDefaultMaxBindingTime
- },
- {
- ZCD_NV_APS_USE_EXT_PANID, Z_EXTADDR_LEN, zgApsUseExtendedPANID
- },
- {
- ZCD_NV_APS_USE_INSECURE_JOIN, sizeof(zgApsUseInsecureJoin), &zgApsUseInsecureJoin
- },
- {
- ZCD_NV_APS_NONMEMBER_RADIUS, sizeof(zgApsNonMemberRadius), &zgApsNonMemberRadius
- },
- {
- ZCD_NV_START_DELAY, sizeof(zgStartDelay), &zgStartDelay
- },
- {
- ZCD_NV_SAPI_ENDPOINT, sizeof(zgSapiEndpoint), &zgSapiEndpoint
- },
- {
- ZCD_NV_NWK_MGR_MODE, sizeof(zgNwkMgrMode), &zgNwkMgrMode
- },
- {
- ZCD_NV_NWKMGR_MIN_TX, sizeof(zgNwkMgrMinTransmissions), &zgNwkMgrMinTransmissions
- },
- {
- ZCD_NV_ROUTER_OFF_ASSOC_CLEANUP, sizeof(zgRouterOffAssocCleanup), &zgRouterOffAssocCleanup
- },
- #endif // NV_INIT
- // Last item -- DO NOT MOVE IT!
- {
- 0x00, 0, NULL
- }
- };
- /*********************************************************************
- * LOCAL FUNCTIONS
- */
- static uint8 zgItemInit( uint16 id, uint16 len, void *buf, uint8 setDefault );
- #ifndef NONWK
- static uint8 zgPreconfigKeyInit( uint8 setDefault );
- #endif
- /*********************************************************************
- * @fn zgItemInit()
- *
- * @brief
- *
- * Initialize a global item. If the item doesn't exist in NV memory,
- * write the system default (value passed in) into NV memory. But if
- * it exists, set the item to the value stored in NV memory.
- *
- * Also, if setDefault is TRUE and the item exists, we will write
- * the default value to NV space.
- *
- * @param id - item id
- * @param len - item len
- * @param buf - pointer to the item
- * @param setDefault - TRUE to set default, not read
- *
- * @return ZSUCCESS if successful, NV_ITEM_UNINIT if item did not
- * exist in NV, NV_OPER_FAILED if failure.
- */
- static uint8 zgItemInit( uint16 id, uint16 len, void *buf, uint8 setDefault )
- {
- uint8 status;
- // If the item doesn't exist in NV memory, create and initialize
- // it with the value passed in.
- status = osal_nv_item_init( id, len, buf );
- if ( status == ZSUCCESS )
- {
- if ( setDefault )
- {
- // Write the default value back to NV
- status = osal_nv_write( id, 0, len, buf );
- }
- else
- {
- // The item exists in NV memory, read it from NV memory
- status = osal_nv_read( id, 0, len, buf );
- }
- }
- return (status);
- }
- /*********************************************************************
- * API FUNCTIONS
- */
- /*********************************************************************
- * @fn zgInit
- *
- * @brief
- *
- * Initialize the Z-Stack Globals. If an item doesn't exist in
- * NV memory, write the system default into NV memory. But if
- * it exists, set the item to the value stored in NV memory.
- *
- * NOTE: The Startup Options (ZCD_NV_STARTUP_OPTION) indicate
- * that the Config state items (zgItemTable) need to be
- * set to defaults (ZCD_STARTOPT_DEFAULT_CONFIG_STATE). The
- *
- * @param none
- *
- * @return ZSUCCESS if successful, NV_ITEM_UNINIT if item did not
- * exist in NV, NV_OPER_FAILED if failure.
- */
- uint8 zgInit( void )
- {
- uint8 setDefault = FALSE;
- // Do we want to default the Config state values
- if ( zgReadStartupOptions() & ZCD_STARTOPT_DEFAULT_CONFIG_STATE )
- {
- setDefault = TRUE;
- }
- #if 0
- // Enable this section if you need to track the number of resets
- // This section is normally disabled to minimize "wear" on NV memory
- uint16 bootCnt = 0;
- // Update the Boot Counter
- if ( osal_nv_item_init( ZCD_NV_BOOTCOUNTER, sizeof(bootCnt), &bootCnt ) == ZSUCCESS )
- {
- // Get the old value from NV memory
- osal_nv_read( ZCD_NV_BOOTCOUNTER, 0, sizeof(bootCnt), &bootCnt );
- }
- // Increment the Boot Counter and store it into NV memory
- if ( setDefault )
- bootCnt = 0;
- else
- bootCnt++;
- osal_nv_write( ZCD_NV_BOOTCOUNTER, 0, sizeof(bootCnt), &bootCnt );
- #endif
- // Initialize the Extended PAN ID as my own extended address
- ZMacGetReq( ZMacExtAddr, zgExtendedPANID );
- // Initialize the items table
- zgInitItems( setDefault );
- #ifndef NONWK
- if ( ZG_SECURE_ENABLED )
- {
- // Initialize the Pre-Configured Key to the default key
- zgPreconfigKeyInit( setDefault );
- // Initialize NV items for all Keys: NWK, APS, TCLK and Master
- ZDSecMgrInitNVKeyTables( setDefault );
- }
- #endif // NONWK
- // Clear the Config State default
- if ( setDefault )
- {
- zgWriteStartupOptions( ZG_STARTUP_CLEAR, ZCD_STARTOPT_DEFAULT_CONFIG_STATE );
- }
- return ( ZSUCCESS );
- }
- /*********************************************************************
- * @fn zgInitItems
- *
- * @brief Initializes RAM variables from NV. If NV items don't
- * exist, then the NV is initialize with what is in RAM
- * variables.
- *
- * @param none
- *
- * @return none
- */
- void zgInitItems( uint8 setDefault )
- {
- uint8 i = 0;
- while ( zgItemTable[i].id != 0x00 )
- {
- // Initialize the item
- zgItemInit( zgItemTable[i].id, zgItemTable[i].len, zgItemTable[i].buf, setDefault );
- // Move on to the next item
- i++;
- }
- }
- /*********************************************************************
- * @fn zgReadStartupOptions
- *
- * @brief Reads the ZCD_NV_STARTUP_OPTION NV Item.
- *
- * @param none
- *
- * @return the ZCD_NV_STARTUP_OPTION NV item
- */
- uint8 zgReadStartupOptions( void )
- {
- // Default to Use Config State and Use Network State
- uint8 startupOption = 0;
- // This should have been done in ZMain.c, but just in case.
- if ( osal_nv_item_init( ZCD_NV_STARTUP_OPTION,
- sizeof(startupOption),
- &startupOption ) == ZSUCCESS )
- {
- // Read saved startup control
- osal_nv_read( ZCD_NV_STARTUP_OPTION,
- 0,
- sizeof( startupOption ),
- &startupOption);
- }
- return ( startupOption );
- }
- /*********************************************************************
- * @fn zgWriteStartupOptions
- *
- * @brief Writes bits into the ZCD_NV_STARTUP_OPTION NV Item.
- *
- * @param action - ZG_STARTUP_SET set bit, ZG_STARTUP_CLEAR to
- * clear bit. The set bit is an OR operation, and the
- * clear bit is an AND ~(bitOptions) operation.
- *
- * @param bitOptions - which bits to perform action on:
- * ZCD_STARTOPT_DEFAULT_CONFIG_STATE
- * ZCD_STARTOPT_DEFAULT_NETWORK_STATE
- *
- * @return ZSUCCESS if successful
- */
- uint8 zgWriteStartupOptions( uint8 action, uint8 bitOptions )
- {
- uint8 status;
- uint8 startupOptions = 0;
- status = osal_nv_read( ZCD_NV_STARTUP_OPTION,
- 0,
- sizeof( startupOptions ),
- &startupOptions );
- if ( status == ZSUCCESS )
- {
- if ( action == ZG_STARTUP_SET )
- {
- // Set bits
- startupOptions |= bitOptions;
- }
- else
- {
- // Clear bits
- startupOptions &= (bitOptions ^ 0xFF);
- }
- // Changed?
- status = osal_nv_write( ZCD_NV_STARTUP_OPTION,
- 0,
- sizeof( startupOptions ),
- &startupOptions );
- }
- return ( status );
- }
- /*********************************************************************
- * @fn zgSetItem
- *
- * @brief Set RAM variables from set-NV, if it exist in the zgItemTable
- *
- * @param id - NV ID
- * len - NV item length
- * buf - pointer to the input buffer
- *
- * @return none
- */
- void zgSetItem( uint16 id, uint16 len, void *buf )
- {
- uint8 i = 0;
- // Look up the NV item table
- while ( zgItemTable[i].id != 0x00 )
- {
- if( zgItemTable[i].id == id )
- {
- if ( zgItemTable[i].len == len )
- {
- osal_memcpy( zgItemTable[i].buf, buf, len );
- }
- break;
- }
- // Move on to the next item
- i++;
- }
- }
- #ifndef NONWK
- /*********************************************************************
- * @fn zgPreconfigKeyInit()
- *
- * @brief
- *
- * Initialize ZCD_NV_PRECFGKEY NV item. If the item doesn't exist in NV memory,
- * write the system default (value passed in) into NV memory. But if
- * it exists do not overwrite it.
- *
- * Also, if setDefault is TRUE and the item exists, we will write
- * the default value to NV space.
- *
- * @param setDefault - TRUE to set default
- *
- * @return ZSUCCESS if successful, NV_ITEM_UNINIT if item did not
- * exist in NV, NV_OPER_FAILED if failure.
- */
- static uint8 zgPreconfigKeyInit( uint8 setDefault )
- {
- uint8 zgPreConfigKey[SEC_KEY_LEN];
- uint8 status;
- // Initialize the Pre-Configured Key to the default key
- osal_memcpy( zgPreConfigKey, defaultKey, SEC_KEY_LEN );
- // If the item doesn't exist in NV memory, create and initialize it
- status = osal_nv_item_init( ZCD_NV_PRECFGKEY, SEC_KEY_LEN, zgPreConfigKey );
- if ( status == ZSUCCESS )
- {
- if ( setDefault )
- {
- // Write the default value back to NV
- status = osal_nv_write( ZCD_NV_PRECFGKEY, 0, SEC_KEY_LEN, zgPreConfigKey );
- }
- }
- // clear local copy of default key
- osal_memset(zgPreConfigKey, 0x00, SEC_KEY_LEN);
- return (status);
- }
- #endif
- /*********************************************************************
- *********************************************************************/
|