diff --git a/bin/XZG_20240507.full.bin b/bin/XZG_20240509.full.bin similarity index 54% rename from bin/XZG_20240507.full.bin rename to bin/XZG_20240509.full.bin index fde8f1e..46cb163 100644 Binary files a/bin/XZG_20240507.full.bin and b/bin/XZG_20240509.full.bin differ diff --git a/bin/XZG_20240507.ota.bin b/bin/XZG_20240509.ota.bin similarity index 51% rename from bin/XZG_20240507.ota.bin rename to bin/XZG_20240509.ota.bin index 260c3a3..2c9f18d 100644 Binary files a/bin/XZG_20240507.ota.bin and b/bin/XZG_20240509.ota.bin differ diff --git a/lib/CCTools/src/CCTools.cpp b/lib/CCTools/src/CCTools.cpp index fcc5487..fe63b6f 100644 --- a/lib/CCTools/src/CCTools.cpp +++ b/lib/CCTools/src/CCTools.cpp @@ -13,6 +13,22 @@ #endif #endif +namespace +{ + uint16_t findTableEnd(uint16_t value) + { + for (int i = 0; i < sizeof(NWK_NVID_TABLES) / sizeof(NWK_NVID_TABLES[0]); ++i) + { + if (value == NWK_NVID_TABLES[i].first) + { + return NWK_NVID_TABLES[i].second; + } + } + return false; + } + +} + CommandInterface::CommandInterface(Stream &serial) : _stream(serial) {} void CommandInterface::_cleanBuffer() @@ -58,6 +74,39 @@ bool CommandInterface::_wait_for_ack(unsigned long timeout = 1) return false; } +byte *CommandInterface::_receive_SRSP(unsigned long timeout = 500) +{ + unsigned long startMillis = millis(); + while (millis() - startMillis < timeout) + { + if (_stream.available() >= 1) + { + if (_stream.read() == cmdFrameStart) + { + uint8_t size = _stream.read(); + byte *data = new byte[size + 3]; + if (!_stream.readBytes(data, size + 3)) + { + delete[] data; + return nullptr; + } + else + { + // DEBUG_PRINT("Success "); + return data; + } + } + else + { + DEBUG_PRINT("Wrong answer "); + return nullptr; + } + } + } + DEBUG_PRINT("Timeout "); + return nullptr; +} + uint32_t CommandInterface::_cmdGetChipId() { const u_int32_t cmd = 0x28; @@ -423,6 +472,155 @@ bool CommandInterface::_ledToggle(bool ledState) return false; } +bool CommandInterface::_nvram_osal_delete(uint16_t nvid) +{ + // DEBUG_PRINT("Checking OsalNvIds ID: "); + // Serial.print(nvid, HEX); + // DEBUG_PRINT(" - "); + + const uint8_t cmd1 = 0x21; + uint8_t cmd2 = 0x13; + uint8_t lng = 0x02; + + uint8_t highByte = (nvid >> 8) & 0xFF; // Старший байт (верхние 8 бит) + uint8_t lowByte = nvid & 0xFF; // Младший байт (нижние 8 бит) + + uint8_t fcs = 0; + + _stream.write(cmdFrameStart); + + _stream.write(lng); + fcs ^= lng; + _stream.write(cmd1); + fcs ^= cmd1; + _stream.write(cmd2); + fcs ^= cmd2; + _stream.write(lowByte); + fcs ^= lowByte; + _stream.write(highByte); + fcs ^= highByte; + + _stream.write(fcs); + + _stream.flush(); + + // Serial.println(""); + // Serial.println("> " + String(cmd1, HEX) + " " + String(cmd2, HEX) + " " + String(lowByte, HEX) + " " + String(highByte, HEX) + " " + String(fcs, HEX)); + + std::unique_ptr data(_receive_SRSP()); + if (!data) + { + return false; + } + // Serial.println("< " + String(data[0], HEX) + " " + String(data[1], HEX) + " " + String(data[2], HEX) + " " + String(data[3], HEX) + " " + String(data[4], HEX)); + + if (data[2] > 0 || data[3] > 0) + { + /* + DEBUG_PRINT("* Deleting OsalNvIds ID: "); + Serial.print(nvid, HEX); + DEBUG_PRINT(" - "); + */ + + fcs = 0; + cmd2 = 0x12; + lng = 0x04; + + _stream.write(cmdFrameStart); + + _stream.write(lng); + fcs ^= lng; + _stream.write(cmd1); + fcs ^= cmd1; + _stream.write(cmd2); + fcs ^= cmd2; + _stream.write(lowByte); + fcs ^= lowByte; + _stream.write(highByte); + fcs ^= highByte; + _stream.write(data[2]); + fcs ^= data[2]; + _stream.write(data[3]); + fcs ^= data[3]; + + _stream.write(fcs); + + _stream.flush(); + + // Serial.println(""); + // Serial.println("> " + String(cmd1, HEX) + " " + String(cmd2, HEX) + " " + String(lowByte, HEX) + " " + String(highByte, HEX) + " " + String(data[2], HEX) + " " + String(data[3], HEX) + " " + String(fcs, HEX)); + + std::unique_ptr data(_receive_SRSP()); + if (!data) + { + return false; + } + // Serial.println("< " + String(data[0], HEX) + " " + String(data[1], HEX) + " " + String(data[2], HEX) + " " + String(data[3], HEX)); + } + return true; +} + +bool CommandInterface::_nvram_ex_delete(uint16_t nvid, uint16_t subID) +{ + /* + DEBUG_PRINT("Deleting ExNvIds sub ID: "); + + Serial.print(nvid, HEX); + DEBUG_PRINT(" "); + Serial.print(subID, HEX); + DEBUG_PRINT(" - "); + */ + const uint8_t cmd1 = 0x21; + uint8_t cmd2 = 0x31; + uint8_t lng = 0x05; + const uint8_t sysID = 1; + + uint8_t highByte = (nvid >> 8) & 0xFF; + uint8_t lowByte = nvid & 0xFF; + + uint8_t subIDhighByte = (subID >> 8) & 0xFF; + uint8_t subIDlowByte = subID & 0xFF; + + uint8_t fcs = 0; + + _stream.write(cmdFrameStart); + + _stream.write(lng); + fcs ^= lng; + _stream.write(cmd1); + fcs ^= cmd1; + _stream.write(cmd2); + fcs ^= cmd2; + _stream.write(sysID); + fcs ^= sysID; + _stream.write(lowByte); + fcs ^= lowByte; + _stream.write(highByte); + fcs ^= highByte; + _stream.write(subIDlowByte); + fcs ^= subIDlowByte; + _stream.write(subIDhighByte); + fcs ^= subIDhighByte; + + _stream.write(fcs); + + _stream.flush(); + + std::unique_ptr data(_receive_SRSP()); + if (!data) + { + return false; + } + // Serial.println(String(data[2], HEX)); + + if (data[2] == 0x0A) + { // error + return false; + } + + return true; +} + CommandInterface::zbInfoStruct CommandInterface::_checkFwVer() { zbInfoStruct chip; @@ -492,13 +690,13 @@ void CCTools::enterBSL() digitalWrite(_CC_RST_PIN, LOW); digitalWrite(_CC_BSL_PIN, LOW); // DEBUG_PRINTLN(F("Zigbee RST & BSL pin ON")); - delay(250); + delay(50); digitalWrite(_CC_RST_PIN, HIGH); // DEBUG_PRINTLN(F("Zigbee RST pin OFF")); - delay(1000); + delay(500); digitalWrite(_CC_BSL_PIN, HIGH); // DEBUG_PRINTLN(F("Zigbee BSL pin OFF")); - delay(1000); + delay(500); } bslActive = 1; } @@ -507,10 +705,10 @@ void CCTools::restart() { digitalWrite(_CC_RST_PIN, LOW); // DEBUG_PRINTLN(F("Zigbee RST pin ON")); - delay(250); + delay(50); digitalWrite(_CC_RST_PIN, HIGH); // DEBUG_PRINTLN(F("Zigbee RST pin OFF")); - delay(1000); + delay(500); bslActive = 0; } @@ -599,9 +797,9 @@ bool CCTools::detectChipInfo() String chip_str; if (protocols & PROTO_MASK_IEEE == PROTO_MASK_IEEE) - { + { uint32_t test = 360372; - //Serial.print(test, HEX); + // Serial.print(test, HEX); byte *b_val = _cmdMemRead(test); chip.hwRev = _getChipDescription(chip_id, wafer_id, pg_rev, b_val[1]); @@ -703,4 +901,73 @@ bool CCTools::ledToggle() return true; } return false; +} + +bool CCTools::nvram_reset(void (*logFunction)(String)) +{ + bool success = true; + + // The legacy items are shared by all Z-Stack versions + bool tableFinish = false; + for (int i = 0; i < sizeof(keys) / sizeof(keys[0]); ++i) + { + uint16_t table_end = findTableEnd(keys[i]); + if (table_end != 0) + { + tableFinish = true; + uint16_t table_start = keys[i]; + for (uint16_t id = table_start; id <= table_end; id++) + { + String msg = "Nv [T] ID: " + String(id, HEX); + logFunction(msg); + + if (!_nvram_osal_delete(id)) + { + success = false; + break; + } + } + } + else + { + if (!tableFinish) + { + String msg = "Nv [K] ID:" + String(keys[i], HEX); + logFunction(msg); + + if (!_nvram_osal_delete(keys[i])) + { + success = false; + } + } + else + { + tableFinish = false; + } + } + } + + // znp.version >= 3.30: + for (int i = 0; i < sizeof(exIds) / sizeof(exIds[0]); ++i) + { + if (exIds[i] != ExNvIds::LEGACY) // Skip the LEGACY items, we did them above + { + for (uint16_t sub_id = 0; sub_id < 65536; ++sub_id) + { + String msg = "Nv [E] ID: " + String(exIds[i], HEX) + ", sub: " + String(sub_id, HEX); + logFunction(msg); + + if (!_nvram_ex_delete(exIds[i], sub_id)) + { + break; + } + } + } + } + + logFunction("NVRAM erase finish. Restarting..."); + + restart(); + + return success; } \ No newline at end of file diff --git a/lib/CCTools/src/CCTools.h b/lib/CCTools/src/CCTools.h index c89326d..fdea4fe 100644 --- a/lib/CCTools/src/CCTools.h +++ b/lib/CCTools/src/CCTools.h @@ -13,6 +13,390 @@ enum class ChipId }; #endif +enum OsalNvIds +{ + // Introduced by zigbeer/zigbee-shepherd and now used by Zigbee2MQTT, + HAS_CONFIGURED_ZSTACK1 = 0x0F00, + HAS_CONFIGURED_ZSTACK3 = 0x0060, + + // Although the docs say "IDs reserved for applications range from 0x0401 to 0x0FFF",, + // no OSAL NVID beyond 0x03FF is writable with the MT interface when using Z-Stack 3., + ZIGPY_ZNP_MIGRATION_ID = 0x005F, + + // OSAL NV item IDs, + EXTADDR = 0x0001, + BOOTCOUNTER = 0x0002, + STARTUP_OPTION = 0x0003, + START_DELAY = 0x0004, + + // NWK Layer NV item IDs, + NIB = 0x0021, + DEVICE_LIST = 0x0022, + ADDRMGR = 0x0023, + POLL_RATE_OLD16 = 0x0024, // Deprecated when poll rate changed from 16 to 32 bits, + QUEUED_POLL_RATE = 0x0025, + RESPONSE_POLL_RATE = 0x0026, + REJOIN_POLL_RATE = 0x0027, + DATA_RETRIES = 0x0028, + POLL_FAILURE_RETRIES = 0x0029, + STACK_PROFILE = 0x002A, + INDIRECT_MSG_TIMEOUT = 0x002B, + ROUTE_EXPIRY_TIME = 0x002C, + EXTENDED_PAN_ID = 0x002D, + BCAST_RETRIES = 0x002E, + PASSIVE_ACK_TIMEOUT = 0x002F, + BCAST_DELIVERY_TIME = 0x0030, + NWK_MODE = 0x0031, // Deprecated, as this will always be Mesh, + CONCENTRATOR_ENABLE = 0x0032, + CONCENTRATOR_DISCOVERY = 0x0033, + CONCENTRATOR_RADIUS = 0x0034, + POLL_RATE = 0x0035, + CONCENTRATOR_RC = 0x0036, + NWK_MGR_MODE = 0x0037, + SRC_RTG_EXPIRY_TIME = 0x0038, + ROUTE_DISCOVERY_TIME = 0x0039, + NWK_ACTIVE_KEY_INFO = 0x003A, + NWK_ALTERN_KEY_INFO = 0x003B, + ROUTER_OFF_ASSOC_CLEANUP = 0x003C, + NWK_LEAVE_REQ_ALLOWED = 0x003D, + NWK_CHILD_AGE_ENABLE = 0x003E, + DEVICE_LIST_KA_TIMEOUT = 0x003F, + + // APS Layer NV item IDs, + BINDING_TABLE = 0x0041, + GROUP_TABLE = 0x0042, + APS_FRAME_RETRIES = 0x0043, + APS_ACK_WAIT_DURATION = 0x0044, + APS_ACK_WAIT_MULTIPLIER = 0x0045, + BINDING_TIME = 0x0046, + APS_USE_EXT_PANID = 0x0047, + APS_USE_INSECURE_JOIN = 0x0048, + COMMISSIONED_NWK_ADDR = 0x0049, + + APS_NONMEMBER_RADIUS = 0x004B, // Multicast non_member radius, + APS_LINK_KEY_TABLE = 0x004C, + APS_DUPREJ_TIMEOUT_INC = 0x004D, + APS_DUPREJ_TIMEOUT_COUNT = 0x004E, + APS_DUPREJ_TABLE_SIZE = 0x004F, + + // System statistics and metrics NV ID, + DIAGNOSTIC_STATS = 0x0050, + + // Additional NWK Layer NV item IDs, + NWK_PARENT_INFO = 0x0051, + NWK_ENDDEV_TIMEOUT_DEF = 0x0052, + END_DEV_TIMEOUT_VALUE = 0x0053, + END_DEV_CONFIGURATION = 0x0054, + + BDBNODEISONANETWORK = 0x0055, // bdbNodeIsOnANetwork attribute, + BDBREPORTINGCONFIG = 0x0056, + + // Security NV Item IDs, + SECURITY_LEVEL = 0x0061, + PRECFGKEY = 0x0062, + PRECFGKEYS_ENABLE = 0x0063, + // Deprecated Item as there is only one security mode supported now Z3.0, + SECURITY_MODE = 0x0064, + SECURE_PERMIT_JOIN = 0x0065, + APS_LINK_KEY_TYPE = 0x0066, + APS_ALLOW_R19_SECURITY = 0x0067, + DISTRIBUTED_KEY = 0x0068, // Default distributed nwk key Id. Nv ID not in use, + + IMPLICIT_CERTIFICATE = 0x0069, + DEVICE_PRIVATE_KEY = 0x006A, + CA_PUBLIC_KEY = 0x006B, + KE_MAX_DEVICES = 0x006C, + + USE_DEFAULT_TCLK = 0x006D, + // deprecated: TRUSTCENTER_ADDR (16-bit) 0x006E, + RNG_COUNTER = 0x006F, + RANDOM_SEED = 0x0070, + TRUSTCENTER_ADDR = 0x0071, + + CERT_283 = 0x0072, + PRIVATE_KEY_283 = 0x0073, + PUBLIC_KEY_283 = 0x0074, + + LEGACY_NWK_SEC_MATERIAL_TABLE_START = 0x0075, + LEGACY_NWK_SEC_MATERIAL_TABLE_END = 0x0080, + + // ZDO NV Item IDs, + USERDESC = 0x0081, + NWKKEY = 0x0082, + PANID = 0x0083, + CHANLIST = 0x0084, + LEAVE_CTRL = 0x0085, + SCAN_DURATION = 0x0086, + LOGICAL_TYPE = 0x0087, + NWKMGR_MIN_TX = 0x0088, + NWKMGR_ADDR = 0x0089, + + ZDO_DIRECT_CB = 0x008F, + + // ZCL NV item IDs, + SCENE_TABLE = 0x0091, + MIN_FREE_NWK_ADDR = 0x0092, + MAX_FREE_NWK_ADDR = 0x0093, + MIN_FREE_GRP_ID = 0x0094, + MAX_FREE_GRP_ID = 0x0095, + MIN_GRP_IDS = 0x0096, + MAX_GRP_IDS = 0x0097, + OTA_BLOCK_REQ_DELAY = 0x0098, + + // Non-standard NV item IDs, + SAPI_ENDPOINT = 0x00A1, + + // NV Items Reserved for Commissioning Cluster Startup Attribute Set (SAS):, + // 0x00B1 - 0x00BF: Parameters related to APS and NWK layers, + SAS_SHORT_ADDR = 0x00B1, + SAS_EXT_PANID = 0x00B2, + SAS_PANID = 0x00B3, + SAS_CHANNEL_MASK = 0x00B4, + SAS_PROTOCOL_VER = 0x00B5, + SAS_STACK_PROFILE = 0x00B6, + SAS_STARTUP_CTRL = 0x00B7, + + // 0x00C1 - 0x00CF: Parameters related to Security, + SAS_TC_ADDR = 0x00C1, + SAS_TC_MASTER_KEY = 0x00C2, + SAS_NWK_KEY = 0x00C3, + SAS_USE_INSEC_JOIN = 0x00C4, + SAS_PRECFG_LINK_KEY = 0x00C5, + SAS_NWK_KEY_SEQ_NUM = 0x00C6, + SAS_NWK_KEY_TYPE = 0x00C7, + SAS_NWK_MGR_ADDR = 0x00C8, + + // 0x00D1 - 0x00DF: Current key parameters, + SAS_CURR_TC_MASTER_KEY = 0x00D1, + SAS_CURR_NWK_KEY = 0x00D2, + SAS_CURR_PRECFG_LINK_KEY = 0x00D3, + + USE_NVOCMP = 0x00FF, + + // NV Items Reserved for Trust Center Link Key Table entries, + // 0x0101 - 0x01FF, + TCLK_SEED = 0x0101, // Seed, + TCLK_JOIN_DEV = 0x0102, // Nv Id where Joining device store their APS key. Key is in plain text., + + TCLK_DEFAULT = 0x0103, // Not accually a Nv Item but Id used by SecMgr, + + LEGACY_TCLK_IC_TABLE_START = 0x0104, // Deprecated. Refer to EX_TCLK_IC_TABLE, + LEGACY_TCLK_IC_TABLE_END = 0x0110, // IC keys, referred with shift byte, + + LEGACY_TCLK_TABLE_START = 0x0111, // Deprecated. Refer to EX_TCLK_TABLE, + LEGACY_TCLK_TABLE_END = 0x01FF, + + // NV Items Reserved for APS Link Key Table entries, + // 0x0201 - 0x02FF, + LEGACY_APS_LINK_KEY_DATA_START = 0x0201, // Deprecated. Refer to EX_APS_KEY_TABLE, + LEGACY_APS_LINK_KEY_DATA_END = 0x02FF, + + // NV items used to duplicate system elements, + DUPLICATE_BINDING_TABLE = 0x0300, + DUPLICATE_DEVICE_LIST = 0x0301, + DUPLICATE_DEVICE_LIST_KA_TIMEOUT = 0x0302, + + // NV Items Reserved for Proxy Table entries, + // 0x0310 - 0x031F, + LEGACY_PROXY_TABLE_START = 0x0310, // Deprecated. Refer to EX_GP_PROXY_TABLE, + LEGACY_PROXY_TABLE_END = 0x031F, + + // NV Items Reserved for Sink Table entries, + // 0x0320 - 0x032F, + LEGACY_SINK_TABLE_START = 0x0320, // Deprecated. Refer to EX_GP_SINK_TABLE, + LEGACY_SINK_TABLE_END = 0x032F, + + APP_ITEM_1 = 0x0F01, + APP_ITEM_2 = 0x0F02, + APP_ITEM_3 = 0x0F03, + APP_ITEM_4 = 0x0F04, + APP_ITEM_5 = 0x0F05, + APP_ITEM_6 = 0x0F06, + + RF_TEST_PARMS = 0x0F07, + + UNKNOWN = 0x0F08, + + INVALID_INDEX = 0xFFFF +}; + +const OsalNvIds keys[] = + { + OsalNvIds::HAS_CONFIGURED_ZSTACK1, + OsalNvIds::HAS_CONFIGURED_ZSTACK3, + OsalNvIds::ZIGPY_ZNP_MIGRATION_ID, + OsalNvIds::EXTADDR, + OsalNvIds::BOOTCOUNTER, + OsalNvIds::STARTUP_OPTION, + OsalNvIds::START_DELAY, + OsalNvIds::NIB, + OsalNvIds::DEVICE_LIST, + OsalNvIds::ADDRMGR, + OsalNvIds::POLL_RATE_OLD16, + OsalNvIds::QUEUED_POLL_RATE, + OsalNvIds::RESPONSE_POLL_RATE, + OsalNvIds::REJOIN_POLL_RATE, + OsalNvIds::DATA_RETRIES, + OsalNvIds::POLL_FAILURE_RETRIES, + OsalNvIds::STACK_PROFILE, + OsalNvIds::INDIRECT_MSG_TIMEOUT, + OsalNvIds::ROUTE_EXPIRY_TIME, + OsalNvIds::EXTENDED_PAN_ID, + OsalNvIds::BCAST_RETRIES, + OsalNvIds::PASSIVE_ACK_TIMEOUT, + OsalNvIds::BCAST_DELIVERY_TIME, + OsalNvIds::NWK_MODE, + OsalNvIds::CONCENTRATOR_ENABLE, + OsalNvIds::CONCENTRATOR_DISCOVERY, + OsalNvIds::CONCENTRATOR_RADIUS, + OsalNvIds::POLL_RATE, + OsalNvIds::CONCENTRATOR_RC, + OsalNvIds::NWK_MGR_MODE, + OsalNvIds::SRC_RTG_EXPIRY_TIME, + OsalNvIds::ROUTE_DISCOVERY_TIME, + OsalNvIds::NWK_ACTIVE_KEY_INFO, + OsalNvIds::NWK_ALTERN_KEY_INFO, + OsalNvIds::ROUTER_OFF_ASSOC_CLEANUP, + OsalNvIds::NWK_LEAVE_REQ_ALLOWED, + OsalNvIds::NWK_CHILD_AGE_ENABLE, + OsalNvIds::DEVICE_LIST_KA_TIMEOUT, + OsalNvIds::BINDING_TABLE, + OsalNvIds::GROUP_TABLE, + OsalNvIds::APS_FRAME_RETRIES, + OsalNvIds::APS_ACK_WAIT_DURATION, + OsalNvIds::APS_ACK_WAIT_MULTIPLIER, + OsalNvIds::BINDING_TIME, + OsalNvIds::APS_USE_EXT_PANID, + OsalNvIds::APS_USE_INSECURE_JOIN, + OsalNvIds::COMMISSIONED_NWK_ADDR, + OsalNvIds::APS_NONMEMBER_RADIUS, + OsalNvIds::APS_LINK_KEY_TABLE, + OsalNvIds::APS_DUPREJ_TIMEOUT_INC, + OsalNvIds::APS_DUPREJ_TIMEOUT_COUNT, + OsalNvIds::APS_DUPREJ_TABLE_SIZE, + OsalNvIds::DIAGNOSTIC_STATS, + OsalNvIds::NWK_PARENT_INFO, + OsalNvIds::NWK_ENDDEV_TIMEOUT_DEF, + OsalNvIds::END_DEV_TIMEOUT_VALUE, + OsalNvIds::END_DEV_CONFIGURATION, + OsalNvIds::BDBNODEISONANETWORK, + OsalNvIds::BDBREPORTINGCONFIG, + OsalNvIds::SECURITY_LEVEL, + OsalNvIds::PRECFGKEY, + OsalNvIds::PRECFGKEYS_ENABLE, + OsalNvIds::SECURITY_MODE, + OsalNvIds::SECURE_PERMIT_JOIN, + OsalNvIds::APS_LINK_KEY_TYPE, + OsalNvIds::APS_ALLOW_R19_SECURITY, + OsalNvIds::DISTRIBUTED_KEY, + OsalNvIds::IMPLICIT_CERTIFICATE, + OsalNvIds::DEVICE_PRIVATE_KEY, + OsalNvIds::CA_PUBLIC_KEY, + OsalNvIds::KE_MAX_DEVICES, + OsalNvIds::USE_DEFAULT_TCLK, + OsalNvIds::RNG_COUNTER, + OsalNvIds::RANDOM_SEED, + OsalNvIds::TRUSTCENTER_ADDR, + OsalNvIds::CERT_283, + OsalNvIds::PRIVATE_KEY_283, + OsalNvIds::PUBLIC_KEY_283, + OsalNvIds::LEGACY_NWK_SEC_MATERIAL_TABLE_START, + OsalNvIds::LEGACY_NWK_SEC_MATERIAL_TABLE_END, + OsalNvIds::USERDESC, + OsalNvIds::NWKKEY, + OsalNvIds::PANID, + OsalNvIds::CHANLIST, + OsalNvIds::LEAVE_CTRL, + OsalNvIds::SCAN_DURATION, + OsalNvIds::LOGICAL_TYPE, + OsalNvIds::NWKMGR_MIN_TX, + OsalNvIds::NWKMGR_ADDR, + OsalNvIds::ZDO_DIRECT_CB, + OsalNvIds::SCENE_TABLE, + OsalNvIds::MIN_FREE_NWK_ADDR, + OsalNvIds::MAX_FREE_NWK_ADDR, + OsalNvIds::MIN_FREE_GRP_ID, + OsalNvIds::MAX_FREE_GRP_ID, + OsalNvIds::MIN_GRP_IDS, + OsalNvIds::MAX_GRP_IDS, + OsalNvIds::OTA_BLOCK_REQ_DELAY, + OsalNvIds::SAPI_ENDPOINT, + OsalNvIds::SAS_SHORT_ADDR, + OsalNvIds::SAS_EXT_PANID, + OsalNvIds::SAS_PANID, + OsalNvIds::SAS_CHANNEL_MASK, + OsalNvIds::SAS_PROTOCOL_VER, + OsalNvIds::SAS_STACK_PROFILE, + OsalNvIds::SAS_STARTUP_CTRL, + OsalNvIds::SAS_TC_ADDR, + OsalNvIds::SAS_TC_MASTER_KEY, + OsalNvIds::SAS_NWK_KEY, + OsalNvIds::SAS_USE_INSEC_JOIN, + OsalNvIds::SAS_PRECFG_LINK_KEY, + OsalNvIds::SAS_NWK_KEY_SEQ_NUM, + OsalNvIds::SAS_NWK_KEY_TYPE, + OsalNvIds::SAS_NWK_MGR_ADDR, + OsalNvIds::SAS_CURR_TC_MASTER_KEY, + OsalNvIds::SAS_CURR_NWK_KEY, + OsalNvIds::SAS_CURR_PRECFG_LINK_KEY, + OsalNvIds::USE_NVOCMP, + OsalNvIds::TCLK_SEED, + OsalNvIds::TCLK_JOIN_DEV, + OsalNvIds::TCLK_DEFAULT, + OsalNvIds::LEGACY_TCLK_IC_TABLE_START, + OsalNvIds::LEGACY_TCLK_IC_TABLE_END, + OsalNvIds::LEGACY_TCLK_TABLE_START, + OsalNvIds::LEGACY_TCLK_TABLE_END, + OsalNvIds::LEGACY_APS_LINK_KEY_DATA_START, + OsalNvIds::LEGACY_APS_LINK_KEY_DATA_END, + OsalNvIds::DUPLICATE_BINDING_TABLE, + OsalNvIds::DUPLICATE_DEVICE_LIST, + OsalNvIds::DUPLICATE_DEVICE_LIST_KA_TIMEOUT, + OsalNvIds::LEGACY_PROXY_TABLE_START, + OsalNvIds::LEGACY_PROXY_TABLE_END, + OsalNvIds::LEGACY_SINK_TABLE_START, + OsalNvIds::LEGACY_SINK_TABLE_END, + OsalNvIds::APP_ITEM_1, + OsalNvIds::APP_ITEM_2, + OsalNvIds::APP_ITEM_3, + OsalNvIds::APP_ITEM_4, + OsalNvIds::APP_ITEM_5, + OsalNvIds::APP_ITEM_6, + OsalNvIds::RF_TEST_PARMS, + OsalNvIds::UNKNOWN, + OsalNvIds::INVALID_INDEX}; + +enum ExNvIds +{ + LEGACY = 0x0000, + ADDRMGR_EX = 0x0001, + BINDING_TABLE_EX = 0x0002, + DEVICE_LIST_EX = 0x0003, + TCLK_TABLE = 0x0004, + TCLK_IC_TABLE = 0x0005, + APS_KEY_DATA_TABLE = 0x0006, + NWK_SEC_MATERIAL_TABLE = 0x0007 +}; + +const ExNvIds exIds[] = + { + ExNvIds::LEGACY, + ExNvIds::ADDRMGR_EX, + ExNvIds::BINDING_TABLE_EX, + ExNvIds::DEVICE_LIST_EX, + ExNvIds::TCLK_TABLE, + ExNvIds::TCLK_IC_TABLE, + ExNvIds::APS_KEY_DATA_TABLE, + ExNvIds::NWK_SEC_MATERIAL_TABLE}; + +const std::pair NWK_NVID_TABLES[] = { + {static_cast(OsalNvIds::LEGACY_NWK_SEC_MATERIAL_TABLE_START), static_cast(OsalNvIds::LEGACY_NWK_SEC_MATERIAL_TABLE_END)}, + {static_cast(OsalNvIds::LEGACY_TCLK_IC_TABLE_START), static_cast(OsalNvIds::LEGACY_TCLK_IC_TABLE_END)}, + {static_cast(OsalNvIds::LEGACY_TCLK_TABLE_START), static_cast(OsalNvIds::LEGACY_TCLK_TABLE_END)}, + {static_cast(OsalNvIds::LEGACY_APS_LINK_KEY_DATA_START), static_cast(OsalNvIds::LEGACY_APS_LINK_KEY_DATA_END)}, + {static_cast(OsalNvIds::LEGACY_PROXY_TABLE_START), static_cast(OsalNvIds::LEGACY_PROXY_TABLE_END)}, + {static_cast(OsalNvIds::LEGACY_SINK_TABLE_START), static_cast(OsalNvIds::LEGACY_SINK_TABLE_END)}}; + #define BEGIN_ZB_ADDR 0x00000000 class CommandInterface @@ -169,6 +553,7 @@ class CommandInterface bool _sendSynch(); bool _wait_for_ack(unsigned long timeout); + byte *_receive_SRSP(unsigned long timeout); uint32_t _cmdGetChipId(); byte *_cmdGetStatus(); bool _checkLastCmd(); @@ -185,6 +570,8 @@ class CommandInterface byte *_cmdMemRead(uint32_t address); bool _ledToggle(bool ledState); zbInfoStruct _checkFwVer(); + bool _nvram_osal_delete(uint16_t nvid); + bool _nvram_ex_delete(uint16_t nvid, uint16_t subID); }; class CCTools : public CommandInterface @@ -226,6 +613,7 @@ class CCTools : public CommandInterface void processFlash(byte *data, int size); bool checkFirmwareVersion(); bool ledToggle(); + bool nvram_reset(void (*logFunction)(String)); }; #endif // CCTools_DETECT_H \ No newline at end of file diff --git a/src/version.h b/src/version.h index 46291e0..e11c1c0 100644 --- a/src/version.h +++ b/src/version.h @@ -1,4 +1,4 @@ // AUTO GENERATED FILE #ifndef VERSION - #define VERSION "20240508" + #define VERSION "20240509" #endif diff --git a/src/web.cpp b/src/web.cpp index 96ea362..bb68558 100644 --- a/src/web.cpp +++ b/src/web.cpp @@ -587,7 +587,8 @@ void handleApi() CMD_ZB_CHK_FW, CMD_ZB_CHK_HW, CMD_ZB_LED_TOG, - CMD_ESP_FAC_RES + CMD_ESP_FAC_RES, + CMD_ZB_ERASE_NVRAM }; String result = wrongArgs; const char *argCmd = "cmd"; @@ -613,6 +614,9 @@ void handleApi() case CMD_ZB_BSL: zigbeeEnableBSL(); break; + case CMD_ZB_ERASE_NVRAM: + xTaskCreate(zbEraseNV, "zbEraseNV", 2048, NULL, 5, NULL); + break; case CMD_ESP_RES: serverWeb.send(HTTP_CODE_OK, contTypeText, result); delay(250); diff --git a/src/websrc/html/PAGE_TOOLS.html b/src/websrc/html/PAGE_TOOLS.html index dcdfe59..af7c7a5 100644 --- a/src/websrc/html/PAGE_TOOLS.html +++ b/src/websrc/html/PAGE_TOOLS.html @@ -105,6 +105,8 @@ data-i18n="p.to.czc"> + @@ -248,7 +250,8 @@
- +
diff --git a/src/websrc/json/en.json b/src/websrc/json/en.json index 2163339..69f8463 100644 --- a/src/websrc/json/en.json +++ b/src/websrc/json/en.json @@ -254,7 +254,8 @@ "zfu": "Zigbee file update", "clzv": "Check the latest Zigbee firmware", "saf": "Show available firmware", - "zgu": "Git CC2652 update" + "zgu": "Git CC2652 update", + "eznr": "Erase NVRAM" }, "lo": { "pt": "Login - XZG", diff --git a/src/zb.cpp b/src/zb.cpp index 364ff8a..3f99847 100644 --- a/src/zb.cpp +++ b/src/zb.cpp @@ -104,6 +104,12 @@ bool zigbeeErase() return false; } +void zbEraseNV(void *pvParameters) +{ + CCTool.nvram_reset(printLogMsg); + vTaskDelete(NULL); +} + void flashZbUrl(String url) { diff --git a/src/zb.h b/src/zb.h index 27b3a55..636d965 100644 --- a/src/zb.h +++ b/src/zb.h @@ -2,6 +2,7 @@ bool zbFwCheck(); void zbHwCheck(); bool zbLedToggle(); bool zigbeeErase(); +void zbEraseNV(void *pvParameters); void flashZbUrl(String url); bool eraseWriteZbUrl(const char *url, std::function progressShow, CCTools &CCTool); bool eraseWriteZbFile(const char *filePath, std::function progressShow, CCTools &CCTool);