/****************************************************************************** * @fn modbus_single_write */ void modbus_single_write( uint8 *data_buffer, uint8 len) { uint8 address; address = BUILD_UINT16( data_buffer[3], data_buffer[2]); if( address == MODBUS_PANID) { zgConfigPANID = BUILD_UINT16( data_buffer[5], data_buffer[4]); osal_nv_write( ZCD_NV_PANID, 0, sizeof(zgConfigPANID), &zgConfigPANID); } else if( address == MODBUS_DEVICE_TYPE) { zgDeviceLogicalType = data_buffer[5]; osal_nv_write( ZCD_NV_LOGICAL_TYPE, 0, sizeof(zgDeviceLogicalType), &zgDeviceLogicalType); restore_factory_setting(); } else if( address == MODBUS_CHANNEL_LIST_HI) { zgDefaultChannelList = BUILD_UINT32( 0, 0, data_buffer[5], data_buffer[4]); } else if( address == MODBUS_CHANNEL_LIST_LO) { zgDefaultChannelList = BUILD_UINT32( data_buffer[5], data_buffer[4], 0, 0 ); osal_nv_write( ZCD_NV_CHANLIST, 0, sizeof(zgDefaultChannelList), &zgDefaultChannelList); } else if( address == MODBUS_FACTORY_RESTORE) { if(data_buffer[5] == 1) { restore_factory_setting(); } } }
/**************************************************************************** * @fn ZDiagsClearStats * * @brief Clears the statistics table in RAM and NV if option flag set. * * @param clearNV - Option flag to clear NV data. * * @return System Clock. */ uint32 ZDiagsClearStats( bool clearNV ) { uint32 retValue = 0; #if defined ( FEATURE_SYSTEM_STATS ) // clears statistics table osal_memset( &DiagsStatsTable, 0, sizeof( DiagStatistics_t ) ); // saves System Clock when statistics were cleared retValue = DiagsStatsTable.SysClock = osal_GetSystemClock(); if ( clearNV ) { uint16 bootCnt = 0; // Boot count is not part of DiagsStatsTable, it has to be initialized separately osal_nv_write( ZCD_NV_BOOTCOUNTER, 0, sizeof(bootCnt), &bootCnt ); // Clears values in NV and saves the system clock for the last time stats were cleared osal_nv_write( ZCD_NV_DIAGNOSTIC_STATS, 0, sizeof( DiagStatistics_t ), &DiagsStatsTable ); } #endif // FEATURE_SYSTEM_STATS return ( retValue ); }
/********************************************************************* * @fn BindWriteNV * * @brief Save the Binding Table in NV * * @param none * * @return none */ void BindWriteNV( void ) { BindingEntry_t *pBind; BindingEntry_t bind; nvBindingHdr_t hdr; bindTableIndex_t x; hdr.numRecs = 0; for ( x = 0; x < gNWK_MAX_BINDING_ENTRIES; x++ ) { pBind = &BindingTable[x]; osal_memcpy( &bind, pBind, gBIND_REC_SIZE ); // Save the record to NV osal_nv_write( ZCD_NV_BINDING_TABLE, (uint16)((sizeof(nvBindingHdr_t)) + (x * NV_BIND_REC_SIZE)), NV_BIND_REC_SIZE, &bind ); if ( pBind->srcEP != NV_BIND_EMPTY ) { hdr.numRecs++; } } // Save off the header osal_nv_write( ZCD_NV_BINDING_TABLE, 0, sizeof(nvBindingHdr_t), &hdr ); }
/********************************************************************* * @fn zllSampleBridge_BasicResetCB * * @brief Callback from the ZCL General Cluster Library * to set all the Basic Cluster attributes to default values. * * @param none * * @return none */ static void zllSampleBridge_BasicResetCB( void ) { // Reset all attributes to default values linkedAddrNum = 0; linkedAddrNextIdx = 0; linkedAddrSelIdx = 0; osal_memset( &linkedTargets, 0xFF, sizeof(linkedTargets)); osal_memset( &controlledGroups, 0x00, sizeof(controlledGroups)); #if defined ( NV_RESTORE ) osal_nv_write( ZCD_NV_ZLL_BRIDGE_LINK_TARGETS, 0, sizeof( linkedTargets ), &linkedTargets ); osal_nv_write( ZCD_NV_ZLL_BRIDGE_CTRL_GROUPS, 0, sizeof( controlledGroups ), &controlledGroups ); #endif }
/********************************************************************* * @fn zclCCServer_ReadWriteCB * * @brief Read/write attribute data. This callback function should * only be called for the Network Security Key attributes. * * Note: This function is only required when the attribute data * format is unknown to ZCL. This function gets called * when the pointer 'dataPtr' to the attribute value is * NULL in the attribute database registered with the ZCL. * * @param clusterId - cluster that attribute belongs to * @param attrId - attribute to be read or written * @param oper - ZCL_OPER_LEN, ZCL_OPER_READ, or ZCL_OPER_WRITE * @param pValue - pointer to attribute value * @param pLen - length of attribute value read * * @return ZStatus_t */ static ZStatus_t zclCCServer_ReadWriteCB( uint16 clusterId, uint16 attrId, uint8 oper, uint8 *pValue, uint16 *pLen ) { ZStatus_t status = ZCL_STATUS_SUCCESS; switch ( oper ) { case ZCL_OPER_LEN: *pLen = SEC_KEY_LEN; break; case ZCL_OPER_READ: osal_nv_read( NvIdFromAttrId( attrId ), 0, SEC_KEY_LEN, pValue ); if ( pLen != NULL ) { *pLen = SEC_KEY_LEN; } break; case ZCL_OPER_WRITE: osal_nv_write( NvIdFromAttrId( attrId ), 0, SEC_KEY_LEN, pValue ); break; default: status = ZCL_STATUS_SOFTWARE_FAILURE; // Should never get here! break; } return ( status ); }
void ID_Init(void) { uint16 Init_ID=0x1234; //默认PANID,自己可以任意修改 uint16 preID; //这个是指向ZCD_NV_PANID的值 uint16 ID; //这个想ZCD_NV_PANID1的值 osal_nv_read(ZCD_NV_ID,0,2,&preID); osal_nv_read(ZCD_NV_ID1,0,2,&ID); //如果用串口调试助手修改了,则同时修改ZCD_NV_PANID和ZCD_NV_PANID1 //并且这两个值是相同的,所以当修改后则不会进入下面这个条件语句中 //而在修改之前通过下面的语句将默认PANIDID存入NV中,使得设备启动的 //时候有一个固定的PANID if(preID!=ID) { if ( osal_nv_item_init( ZCD_NV_ID, 2, &Init_ID ) == ZSUCCESS ) { osal_nv_write(ZCD_NV_ID,0,2,&Init_ID); osal_nv_read(ZCD_NV_ID,0,2,&Init_ID); zgID=Init_ID; } } }
/********************************************************************* * @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 ); }
void SaveDisplaySeconds(void) { osal_nv_write(NVID_DISPLAY_SECONDS, NV_ZERO_OFFSET, sizeof(nvDisplaySeconds), &nvDisplaySeconds); }
/**************************************************************************** * @fn ZDiagsSaveStatsToNV * * @brief Saves the statistics table from RAM to NV. * * @param none. * * @return System Time. */ uint32 ZDiagsSaveStatsToNV( void ) { uint32 sysClock = 0; #if defined ( FEATURE_SYSTEM_STATS ) // call this function to update the DiagsStatsTable with MAC values, // the return value does not need to be saved because the function // is updating the value in DiagsStatsTable (void)ZDiagsGetStatsAttr( ZDIAGS_MAC_RX_CRC_PASS ); (void)ZDiagsGetStatsAttr( ZDIAGS_MAC_RX_CRC_FAIL ); (void)ZDiagsGetStatsAttr( ZDIAGS_MAC_RX_BCAST ); (void)ZDiagsGetStatsAttr( ZDIAGS_MAC_TX_BCAST ); (void)ZDiagsGetStatsAttr( ZDIAGS_MAC_RX_UCAST ); (void)ZDiagsGetStatsAttr( ZDIAGS_MAC_TX_UCAST ); (void)ZDiagsGetStatsAttr( ZDIAGS_MAC_TX_UCAST_RETRY ); (void)ZDiagsGetStatsAttr( ZDIAGS_MAC_TX_UCAST_FAIL ); // System Clock when statistics were saved sysClock = DiagsStatsTable.SysClock = osal_GetSystemClock(); // save the statistics table from RAM to NV osal_nv_write( ZCD_NV_DIAGNOSTIC_STATS, 0, sizeof( DiagStatistics_t ), &DiagsStatsTable ); #endif // returns the System Time return ( sysClock ); }
/********************************************************************* * @fn zclSampleSw_Init * * @brief Initialization function for the zclGeneral layer. * * @param none * * @return none */ void zclSampleSw_Init( byte task_id ) { osal_nv_write(ZCD_NV_EXTADDR, 0, Z_EXTADDR_LEN, ieeeAddr); zclSampleSw_TaskID = task_id; // Set destination address to indirect zclSampleSw_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent; zclSampleSw_DstAddr.endPoint = 0; zclSampleSw_DstAddr.addr.shortAddr = 0; // This app is part of the Home Automation Profile zclHA_Init( &zclSampleSw_SimpleDesc ); // Register the ZCL General Cluster Library callback functions zclGeneral_RegisterCmdCallbacks( SAMPLESW_ENDPOINT, &zclSampleSw_CmdCallbacks ); // Register the application's attribute list zcl_registerAttrList( SAMPLESW_ENDPOINT, SAMPLESW_MAX_ATTRIBUTES, zclSampleSw_Attrs ); // Register the Application to receive the unprocessed Foundation command/response messages zcl_registerForMsg( zclSampleSw_TaskID ); // Register for all key events - This app will handle all key events RegisterForKeys( zclSampleSw_TaskID ); // Register for a test endpoint afRegister( &sampleSw_TestEp ); ZDO_RegisterForZDOMsg( zclSampleSw_TaskID, End_Device_Bind_rsp ); ZDO_RegisterForZDOMsg( zclSampleSw_TaskID, Match_Desc_rsp ); }
void addDevice( ZDO_DeviceAnnce_t * add){ uint16 nwkAddr; uint16 offset; ZDO_DeviceAnnce_t * iter, *end; end = table +TABLE_SIZE; if (AddrMgrNwkAddrLookup(add->extAddr, &nwkAddr)==TRUE){ return; } for(iter=table; iter != end; iter++){ if (iter->nwkAddr != INVALID && sAddrExtCmp(iter->extAddr, add->extAddr)==TRUE){ return; } } for(iter=table,offset=0; iter != end; iter++,offset+=sizeof(ZDO_DeviceAnnce_t)){ if (iter->nwkAddr==INVALID){ iter->capabilities = add->capabilities; iter->nwkAddr = add->nwkAddr; sAddrExtCpy(iter->extAddr, add->extAddr); osal_nv_write(NV_ID,offset, sizeof(ZDO_DeviceAnnce_t), iter); return; } } }
//********************************************* static void restart_to_other_type(void) { NLME_InitNV(); NLME_SetDefaultNV(); osal_nv_write( ZCD_NV_LOGICAL_TYPE, 0, sizeof(zgDeviceLogicalType), &zgDeviceLogicalType); SystemReset(); }
/********************************************************************* * @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 defined ( FEATURE_SYSTEM_STATS ) // This sections tracks the number of resets 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 // FEATURE_SYSTEM_STATS // 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 znpBasicCfg * * @brief Process the Conglomerate Basic Configuration command. * * input parameters * * @param pBuf - Pointer to the MT buffer containing the conglomerated configuration. * * output parameters * * None. * * @return None. */ static void znpBasicCfg(uint8 *pBuf) { uint32 t32 = osal_build_uint32( &pBuf[0], 4 ); if (MT_PeriodicMsgRate != t32) { MT_PeriodicMsgRate = t32; (void)osal_start_reload_timer(MT_TaskID, MT_PERIODIC_MSG_EVENT, t32); } t32 = osal_build_uint32( &pBuf[4], 4 ); if (osal_memcmp(&zgDefaultChannelList, &t32, 4) == FALSE) { (void)osal_nv_write(ZCD_NV_CHANLIST, 0, 4, &t32); } uint16 t16 = osal_build_uint16( &pBuf[8] ); if (osal_memcmp(&zgConfigPANID, &t16, 2) == FALSE) { (void)osal_nv_write(ZCD_NV_PANID, 0, 2, &t16); } if (zgDeviceLogicalType != pBuf[10]) { (void)osal_nv_write(ZCD_NV_LOGICAL_TYPE, 0, 1, pBuf+10); } if (pBuf[11] & MT_ZNP_CMD_DISC_RESET_NWK) { pBuf[0] = ZCD_STARTOPT_DEFAULT_NETWORK_STATE; (void)osal_nv_write(ZCD_NV_STARTUP_OPTION, 0, 1, pBuf); #if defined CC2531ZNP SystemResetSoft(); #else SystemReset(); #endif } else if (pBuf[11] & MT_ZNP_CMD_DISC_ZDO_START) { if (devState == DEV_HOLD) { ZDOInitDevice(0); } } }
/************************************************************************************************** * @fn znpTestRF * * @brief This function initializes and checks the ZNP RF Test Mode NV items. It is designed * to be invoked before/instead of MAC radio initialization. * * input parameters * * None. * * output parameters * * None. * * @return None. */ void znpTestRF(void) { uint8 rfTestParms[4] = { 0, 0, 0, 0 }; if ((SUCCESS != osal_nv_item_init(ZNP_NV_RF_TEST_PARMS, 4, rfTestParms)) || (SUCCESS != osal_nv_read(ZNP_NV_RF_TEST_PARMS, 0, 4, rfTestParms)) || (rfTestParms[0] == 0)) { return; } // Settings from SmartRF Studio MDMCTRL0 = 0x85; RXCTRL = 0x3F; FSCTRL = 0x5A; FSCAL1 = 0x2B; AGCCTRL1 = 0x11; ADCTEST0 = 0x10; ADCTEST1 = 0x0E; ADCTEST2 = 0x03; FRMCTRL0 = 0x43; FRMCTRL1 = 0x00; MAC_RADIO_RXTX_OFF(); MAC_RADIO_SET_CHANNEL(rfTestParms[1]); MAC_RADIO_SET_TX_POWER(rfTestParms[2]); TX_PWR_TONE_SET(rfTestParms[3]); switch (rfTestParms[0]) { case 1: // Rx promiscuous mode. MAC_RADIO_RX_ON(); break; case 2: // Un-modulated Tx. TX_PWR_MOD__SET(1); // no break; case 3: // Modulated Tx. // Modulated is default register setting, so no special action. // Now turn on Tx power for either mod or un-modulated Tx test. MAC_RADIO_TX_ON(); break; default: // Not expected. break; } // Clear the RF test mode. (void)osal_memset(rfTestParms, 0, 4); (void)osal_nv_write(ZNP_NV_RF_TEST_PARMS, 0, 4, rfTestParms); while (1); // Spin in RF test mode until a hard reset. }
/********************************************************************* * @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 i = 0; 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 ); #ifndef NONWK // Initialize the Pre-Configured Key to the default key osal_memcpy( zgPreConfigKey, defaultKey, SEC_KEY_LEN ); // Do NOT Change!!! #endif // NONWK 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++; } // Clear the Config State default if ( setDefault ) { zgWriteStartupOptions( ZG_STARTUP_CLEAR, ZCD_STARTOPT_DEFAULT_CONFIG_STATE ); } return ( ZSUCCESS ); }
/********************************************************************* * @fn zclCCServer_UseStartupParameters * * @brief Set the network parameters to the current Startup Parameters. * * @param none * * @return none */ static void zclCCServer_UseStartupParameters( void ) { if ( zclCCServer_StartUpControl == CC_STARTUP_CONTROL_OPTION_1 ) { uint8 networkKey[SEC_KEY_LEN]; // Form the Commissioning network and become the Coordinator for that network // Required attributes: Extended PAN ID osal_nv_write( ZCD_NV_EXTENDED_PAN_ID, 0, Z_EXTADDR_LEN, zclCCServer_ExtendedPanId ); osal_nv_write( ZCD_NV_APS_USE_EXT_PANID, 0, Z_EXTADDR_LEN, zclCCServer_ExtendedPanId ); // Optional attributes: PAN ID, Channel Mask, Network Manager Address, // Network Key, Network Key Type (only KEY_TYPE_NWK is currently supported), // and Trust Center Address (which is used with Preconfigured Link Key). osal_nv_write( ZCD_NV_PANID, 0, sizeof( zclCCServer_PanId ), &zclCCServer_PanId ); osal_nv_write( ZCD_NV_CHANLIST, 0, sizeof( zclCCServer_ChannelMask ), &zclCCServer_ChannelMask ); osal_nv_write( ZCD_NV_NWKMGR_ADDR, 0, sizeof( zclCCServer_NwkManagerAddr ), &zclCCServer_NwkManagerAddr ); osal_nv_read( ZCD_NV_SAS_CURR_NWK_KEY, 0, SEC_KEY_LEN, networkKey ); if ( !nullKey( networkKey ) ) { // Save the Network Key as the Pre-Configured Key in NV osal_nv_write( ZCD_NV_PRECFGKEY, 0, SEC_KEY_LEN, networkKey ); // Clear copy of key in RAM osal_memset( networkKey, 0x00, SEC_KEY_LEN ); } } else if ( zclCCServer_StartUpControl == CC_STARTUP_CONTROL_OPTION_3 ) { // Join the Commissioning network // Required attributes: none // Optional attributes: Extended PAN ID, Channel Mask, and // Preconfigured Link Key osal_nv_write( ZCD_NV_EXTENDED_PAN_ID, 0, Z_EXTADDR_LEN, zclCCServer_ExtendedPanId ); osal_nv_write( ZCD_NV_CHANLIST, 0, sizeof( zclCCServer_ChannelMask ), &zclCCServer_ChannelMask ); zclCCServer_SavePreconfigLinkKey(); } }
/********************************************************************* * @fn BindSetDefaultNV * * @brief Write the defaults to NV * * @param none * * @return none */ void BindSetDefaultNV( void ) { nvBindingHdr_t hdr; // Initialize the header hdr.numRecs = 0; // Save off the header osal_nv_write( ZCD_NV_BINDING_TABLE, 0, sizeof( nvBindingHdr_t ), &hdr ); }
static void start_dev(void) { #if defined ( HOLD_AUTO_START ) ZDOInitDevice(0); osal_nv_item_init( 0x0201, sizeof(start_flag), &start_flag); start_flag = 1; osal_nv_write(0x0201,0, sizeof(start_flag), &start_flag); #endif }
/********************************************************************* * @fn zclCCServer_RestoreStartupParametersInNV * * @brief Restore the Startup Parameters from NV * * @param none * * @return none */ static void zclCCServer_RestoreStartupParametersInNV( void ) { uint8 key[SEC_KEY_LEN]; for ( uint8 i = 0; nvItemTable[i].id != 0x00; i++ ) { // Read the item osal_nv_read( nvItemTable[i].id, 0, nvItemTable[i].len, nvItemTable[i].buf ); } // Update the current keys in the NV osal_nv_read( ZCD_NV_SAS_TC_MASTER_KEY, 0, SEC_KEY_LEN, key ); osal_nv_write( ZCD_NV_SAS_CURR_TC_MASTER_KEY, 0, SEC_KEY_LEN, key ); osal_nv_read( ZCD_NV_SAS_NWK_KEY, 0, SEC_KEY_LEN, key ); osal_nv_write( ZCD_NV_SAS_CURR_NWK_KEY, 0, SEC_KEY_LEN, key ); osal_nv_read( ZCD_NV_SAS_PRECFG_LINK_KEY, 0, SEC_KEY_LEN, key ); osal_nv_write( ZCD_NV_SAS_CURR_PRECFG_LINK_KEY, 0, SEC_KEY_LEN, key ); // Clear copy of key in RAM osal_memset( key, 0x00, SEC_KEY_LEN ); }
/*************************************************************************************************** * @fn MT_UtilSetPreCfgKey * * @brief Set Pre Cfg Key * * @param pBuf - pointer to the data * * @return void ***************************************************************************************************/ void MT_UtilSetPreCfgKey(uint8 *pBuf) { uint8 retValue = ZFailure; uint8 cmdId; /* parse header */ cmdId = pBuf[MT_RPC_POS_CMD1]; pBuf += MT_RPC_FRAME_HDR_SZ; retValue = osal_nv_write( ZCD_NV_PRECFGKEY, 0, osal_nv_item_len( ZCD_NV_PRECFGKEY ), pBuf); /* Build and send back the response */ MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_UTIL), cmdId, 1, &retValue ); }
/********************************************************************* * @fn restore_factory_setting * * @brief Restore the device to factory settings. * * @param none * * @return none * *********************************************************************/ void restore_factory_setting( void) { uint8 startOptions; NLME_InitNV(); NLME_SetDefaultNV(); zgWriteStartupOptions( ZG_STARTUP_SET,ZCD_STARTOPT_DEFAULT_NETWORK_STATE ); startOptions = ZCD_STARTOPT_CLEAR_STATE | ZCD_STARTOPT_CLEAR_CONFIG; osal_nv_write(ZCD_NV_STARTUP_OPTION, 0, sizeof(uint8),&startOptions); SystemReset(); }
void set_coordi(void) { uint8 logicalType; osal_nv_item_init( ZCD_NV_LOGICAL_TYPE, sizeof(logicalType), &logicalType ); logicalType = ZG_DEVICETYPE_COORDINATOR; if( osal_nv_write( ZCD_NV_LOGICAL_TYPE, 0 ,sizeof(logicalType), &logicalType) != ZSUCCESS) { uprint("set device to coordi failed"); }else { zgWriteStartupOptions (ZG_STARTUP_SET, ZCD_STARTOPT_DEFAULT_NETWORK_STATE); uprint("set device to coordi,restart it"); } return; }
/*************************************************************************************************** * @fn MT_UtilSetChannels * * @brief Set Channels * * @param pBuf - pointer to the data * * @return void ***************************************************************************************************/ void MT_UtilSetChannels(uint8 *pBuf) { uint32 tmp32; uint8 retValue = ZFailure; uint8 cmdId; /* parse header */ cmdId = pBuf[MT_RPC_POS_CMD1]; pBuf += MT_RPC_FRAME_HDR_SZ; tmp32 = BUILD_UINT32(pBuf[0], pBuf[1], pBuf[2], pBuf[3]); retValue = osal_nv_write(ZCD_NV_CHANLIST, 0, osal_nv_item_len( ZCD_NV_CHANLIST ), &tmp32); /* Build and send back the response */ MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_UTIL), cmdId, 1, &retValue); }
/*************************************************************************************************** * @fn MT_UtilSetPanID * * @brief Set PanID message * * @param pBuf - pointer to the data * * @return void ***************************************************************************************************/ void MT_UtilSetPanID(uint8 *pBuf) { uint16 temp16; uint8 retValue = ZFailure; uint8 cmdId; /* parse header */ cmdId = pBuf[MT_RPC_POS_CMD1]; pBuf += MT_RPC_FRAME_HDR_SZ; temp16 = BUILD_UINT16(pBuf[0], pBuf[1]); pBuf += sizeof(uint16); retValue = osal_nv_write(ZCD_NV_PANID, 0, osal_nv_item_len( ZCD_NV_PANID ), &temp16); /* Build and send back the response */ MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_UTIL), cmdId, 1, &retValue); }
/********************************************************************* * @fn zllSampleBridge_addControlledGroup * * @brief Add group ID to the controlled groups list. * * @param groupId - the groupID to add. * * @return TRUE if added or already exists, FALSE if no space left */ static uint8 zllSampleBridge_addControlledGroup( uint16 groupId ) { for (uint8 i = 0; i < MAX_LINKED_GROUPS; i++) { if ( controlledGroups.arr[i] == groupId ) { return TRUE; } else if ( controlledGroups.arr[i] == 0 ) { controlledGroups.arr[i] = groupId; #if defined ( NV_RESTORE ) osal_nv_write( ZCD_NV_ZLL_BRIDGE_CTRL_GROUPS, 0, sizeof( controlledGroups ), &controlledGroups ); #endif return TRUE; } } return FALSE; }
void set_panid( uint16 u16NewPanid) { uint8 u8BackCode; _NIB.nwkPanId = u16NewPanid; macRadioSetPanID ( _NIB.nwkPanId); ZMacSetReq( ZMacPanId, (byte *)& _NIB.nwkPanId); u8BackCode = osal_nv_write(ZCD_NV_PANID, 0, 2, &u16NewPanid); if( u8BackCode == ZSUCCESS) { NLME_UpdateNV(0x01); // HAL_SYSTEM_RESET(); } else { uprint("set_panid failed"); } }
void set_router(void) { uint8 logicalType; osal_nv_item_init( ZCD_NV_LOGICAL_TYPE, sizeof(logicalType), &logicalType ); logicalType = ZG_DEVICETYPE_ROUTER; if( osal_nv_write( ZCD_NV_LOGICAL_TYPE, 0 ,sizeof(logicalType), &logicalType) != ZSUCCESS) { uprint("set device to router failed"); }else { zgWriteStartupOptions (ZG_STARTUP_SET, ZCD_STARTOPT_DEFAULT_NETWORK_STATE); uprint("set device to router,restart it"); } // zgWriteStartupOptions (ZG_STARTUP_SET, 0x02); // zgInit(); // ZDOInitDevice( 0 ); // SystemReset(); return; }
/*************************************************************************************************** * @fn MT_SysSetExtAddr * * @brief Set the Extended Address * * @param pBuf * * @return None ***************************************************************************************************/ void MT_SysSetExtAddr(uint8 *pBuf) { uint8 retValue = ZFailure; uint8 cmdId; /* parse header */ cmdId = pBuf[MT_RPC_POS_CMD1]; pBuf += MT_RPC_FRAME_HDR_SZ; if ( ZMacSetReq(ZMacExtAddr, pBuf) == ZMacSuccess ) { // CC253X MAC Network Processor does not have NV support #if !defined(CC253X_MACNP) retValue = osal_nv_write(ZCD_NV_EXTADDR, 0, Z_EXTADDR_LEN, pBuf); #endif } /* Build and send back the response */ MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_SYS), cmdId, 1, &retValue); }
/********************************************************************* * @fn zllSampleBridge_UpdateLinkedTarget * * @brief Add or update target in linked targets list * * @param pRec - Target's enpoint information record * * @return status */ static ZStatus_t zllSampleBridge_UpdateLinkedTarget( epInfoRec_t *pRec ) { uint8 idx; ZStatus_t status = ZSuccess; for ( idx = 0; idx < MAX_LINKED_TARGETS; idx++ ) { if ( ( linkedTargets.arr[idx].Addr == pRec->nwkAddr ) && ( linkedTargets.arr[idx].EP == pRec->endpoint ) ) { break; // found existing entry, overwrite. } } //this target is not in our records if ( idx == MAX_LINKED_TARGETS ) { idx = linkedAddrNextIdx; linkedAddrNextIdx++; if( linkedAddrNextIdx > (MAX_LINKED_TARGETS-1) ) { //wrap around and overwrite previous address linkedAddrNextIdx = 0; } if ( linkedAddrNum < MAX_LINKED_TARGETS ) { linkedAddrNum++; } } linkedTargets.arr[idx].Addr = pRec->nwkAddr; linkedTargets.arr[idx].profileID = pRec->profileID; linkedTargets.arr[idx].deviceID = pRec->deviceID; linkedTargets.arr[idx].deviceVersion = pRec->version; linkedTargets.arr[idx].EP = pRec->endpoint; linkedAddrSelIdx = idx; // update linkedAddr in NV #if defined ( NV_RESTORE ) osal_nv_write( ZCD_NV_ZLL_BRIDGE_LINK_TARGETS, 0, sizeof( linkedTargets ), &linkedTargets ); #endif return status; }