diff --git a/src/platform/portduino/SimRadio.cpp b/src/platform/portduino/SimRadio.cpp index 14465a09f..eb970df48 100644 --- a/src/platform/portduino/SimRadio.cpp +++ b/src/platform/portduino/SimRadio.cpp @@ -252,7 +252,14 @@ void SimRadio::startSend(meshtastic_MeshPacket *txp) // pb_encode_to_bytes writes into decoded.payload, which aliases `encrypted` in the union, so all // reads of p->encrypted above must be complete before this point. - p->decoded = meshtastic_Data_init_zero; + if (carryEncrypted) { + // On the encrypted path, `decoded` aliases the ciphertext we just copied into c.data; + // the remaining `Data` fields hold ciphertext bytes that would serialize as spurious + // wire fields, so clear the struct. + p->decoded = meshtastic_Data_init_zero; + } + // On the decoded path, `p->decoded` is already a valid Data from perhapsDecode(), + // so retain the existing fields (want_response, request_id, bitfield, etc.) p->which_payload_variant = meshtastic_MeshPacket_decoded_tag; p->decoded.payload.size = pb_encode_to_bytes(p->decoded.payload.bytes, sizeof(p->decoded.payload.bytes), &meshtastic_Compressed_msg, &c); @@ -409,4 +416,4 @@ int16_t SimRadio::getCurrentRSSI() { // Simulated radio - return a reasonable default noise floor return -120; -} \ No newline at end of file +}