From 0021eed07624cc54a79ccf253b1181c56c329f63 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 6 Jul 2026 02:12:48 -0400 Subject: [PATCH] Fix config-read chunk cap to cover full MAX_CONFIG_SIZE (MJ-14) The read-config chunk loop used a hardcoded cap of 10 chunks. Because the cap was a magic number decoupled from MAX_CONFIG_SIZE, a config larger than the cap's reach could never be fully read: the client loops until it has `total` bytes and the firmware simply stops sending, so the client retries/times out forever. Derive the cap from MAX_CONFIG_SIZE instead, using the smallest per-chunk payload (MAX_RESPONSE_DATA_SIZE - 6, the chunk-0 size) so it is always sufficient and scales automatically if MAX_CONFIG_SIZE changes. Per-chunk size and framing are unchanged. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_012g2e8mr132vcizx92WsgiR --- opendisplay_pipe.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/opendisplay_pipe.c b/opendisplay_pipe.c index 720d15c..a1dfb0e 100644 --- a/opendisplay_pipe.c +++ b/opendisplay_pipe.c @@ -660,7 +660,13 @@ static void handle_config_read(uint8_t connection) { static uint8_t config_data[MAX_CONFIG_SIZE]; uint32_t config_len = MAX_CONFIG_SIZE; - const uint16_t max_chunks = 10u; + /* Chunk 0 carries a 4-byte header plus a 2-byte length prefix; later chunks + * carry only the 4-byte header. Sizing the cap against the smallest per-chunk + * payload (MAX_RESPONSE_DATA_SIZE - 6) guarantees enough chunks to read a + * full MAX_CONFIG_SIZE config, and scales automatically with MAX_CONFIG_SIZE. */ + const uint16_t max_chunks = + (uint16_t)((MAX_CONFIG_SIZE + (MAX_RESPONSE_DATA_SIZE - 6u) - 1u) / + (MAX_RESPONSE_DATA_SIZE - 6u)); if (!initConfigStorage()) { uint8_t err[] = { 0xFFu, RESP_CONFIG_READ, 0x00u, 0x00u };