From 5a587e5fcdba695c9a6456f70623e16814ef5f61 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sun, 5 Jul 2026 17:32:48 -0400 Subject: [PATCH] Fix config parser dropping packets after unknown TLV types The TLV config parser aborted on the first packet ID it did not recognize by jumping straight to the CRC (offset = configLen - 2), silently dropping every packet that followed. nRF had no case for packet IDs 0x28 (touch), 0x29 (buzzer), 0x2A (nfc), 0x2B (flash) or 0x2C (data_extended), so any config containing one of these (e.g. touch emitted before other packets) truncated parsing. Add cases that skip these unused packet types by their correct on-wire size and continue, so subsequent packets are still parsed. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_012g2e8mr132vcizx92WsgiR --- config_parser.c | 34 ++++++++++++++++++++++++++++++++++ constants.h | 5 +++++ 2 files changed, 39 insertions(+) diff --git a/config_parser.c b/config_parser.c index d6dd56b..d036481 100644 --- a/config_parser.c +++ b/config_parser.c @@ -364,6 +364,40 @@ bool parseConfigBytes(uint8_t* configData, uint32_t configLen, struct GlobalConf } break; + // Packet types nRF does not functionally use. Skip past them by their + // correct on-wire size so subsequent packets are still parsed, instead + // of aborting the whole config on the first one seen. + case CONFIG_PKT_TOUCH: // touch_controller (0x28), 32 bytes + case CONFIG_PKT_BUZZER: // passive_buzzer (0x29), 32 bytes + case CONFIG_PKT_NFC: // nfc_config (0x2A), 32 bytes + case CONFIG_PKT_FLASH: // flash_config (0x2B), 32 bytes + if (offset > configLen) { + NRF_LOG_ERROR("Offset overflow before pkt 0x%02X", packetId); + globalConfig->loaded = false; + return false; + } + if (offset + 32 <= configLen - 2) { + NRF_LOG_DEBUG("Skipping unused pkt 0x%02X (32 bytes)", packetId); + offset += 32; + } else { + offset = configLen - 2; // Skip to CRC + } + break; + + case CONFIG_PKT_DATA_EXTENDED: // data_extended (0x2C), 288 bytes + if (offset > configLen) { + NRF_LOG_ERROR("Offset overflow before data_extended"); + globalConfig->loaded = false; + return false; + } + if (offset + 288 <= configLen - 2) { + NRF_LOG_DEBUG("Skipping unused pkt 0x2C (288 bytes)"); + offset += 288; + } else { + offset = configLen - 2; // Skip to CRC + } + break; + default: NRF_LOG_WARNING("Unknown pkt 0x%02X @%d", packetId, offset - 2); offset = configLen - 2; // Skip to CRC diff --git a/constants.h b/constants.h index 513d1fa..0fc0ed3 100644 --- a/constants.h +++ b/constants.h @@ -56,6 +56,11 @@ #define CONFIG_PKT_BINARY_INPUT 0x25 #define CONFIG_PKT_WIFI 0x26 #define CONFIG_PKT_SECURITY 0x27 +#define CONFIG_PKT_TOUCH 0x28 +#define CONFIG_PKT_BUZZER 0x29 +#define CONFIG_PKT_NFC 0x2A +#define CONFIG_PKT_FLASH 0x2B +#define CONFIG_PKT_DATA_EXTENDED 0x2C #define GPIO_PIN_UNUSED 0xFF