<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to correctly implement HDLC frame fragmentation, CRC-16 FCS validation, and AES-GCM deciphering pipeline in DLMS Green Book?]]></title><description><![CDATA[<blockquote>
<p dir="auto">[!WARNING]<br />
<strong>Technical Redaction &amp; Safe Harbor Notice</strong>:<br />
All communication captures, system titles, and cryptographic parameters in this thread have been sanitized and neutralized. Real utility meter identifiers, production encryption keys (GUEK/GAK/MK), SIM IMSIs, and proprietary network envelopes have been substituted with standard IEC 62056 synthetic test vectors. Do not post unredacted production captures or live cryptographic keys.</p>
</blockquote>
<p dir="auto">We are developing a high-performance optical handheld unit (IEC 62056-21 Mode E, 9600 baud) communicating over IEC 62056-46 HDLC with smart meters running Security Suite 1 (<code>General-Glo-Ciphering</code> <code>0xDB</code> with AES-GCM-128). When reading a large multi-tariff historical billing record (OBIS <code>1.0.98.1.0.255</code>, Class 7), the meter responds with a 320-byte encrypted APDU split across 3 HDLC segmented I-Frames.</p>
<p dir="auto">Our embedded parser continuously throws <code>deciphering-failed: invalid-tag</code> or corrupt ASN.1 structure on the continuation segments.</p>
<p dir="auto">Here is the sanitized 3-segment HDLC capture from the optical probe:</p>
<ul>
<li><strong>Segment 1 (S=1, Frame Length 132B)</strong>:</li>
</ul>
<pre><code class="language-hex">7E A8 84 03 21 10 94 E4 E6 E6 00 DB 08 53 48 41 00 00 00 00 01 30 00 00 00 0A 4F 12 A9 88 BC 11 02 33 44 55 66 77 88 99 AA BB CC DD EE FF 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF 00 11 22 33 44 55 66 77 88 99 AA BB CC DD 1E 2B 7E
</code></pre>
<ul>
<li><strong>Segment 2 (S=1, Frame Length 128B)</strong>:</li>
</ul>
<pre><code class="language-hex">7E A8 80 03 21 30 B2 14 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF 00 11 22 33 44 55 66 77 88 99 AA BB CC DD 4F 9A 7E
</code></pre>
<ul>
<li><strong>Segment 3 (S=0, Last Segment, Frame Length 66B)</strong>:</li>
</ul>
<pre><code class="language-hex">7E A0 42 03 21 50 D8 70 88 99 AA BB CC DD EE FF 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF 00 11 22 33 44 55 66 77 9B E1 4C 8D 23 AA 12 90 77 1B C0 44 C2 8F 7E
</code></pre>
<p dir="auto">We initially attempted to feed each segment directly into the AES-GCM stream decryptor as it arrived over UART to save RAM. Why is GMAC verification failing completely?</p>
]]></description><link>https://dlms.sharur.org/topic/55/how-to-correctly-implement-hdlc-frame-fragmentation-crc-16-fcs-validation-and-aes-gcm-deciphering-pipeline-in-dlms-green-book</link><generator>RSS for Node</generator><lastBuildDate>Fri, 16 Oct 2026 19:20:25 GMT</lastBuildDate><atom:link href="https://dlms.sharur.org/topic/55.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 22 Aug 2026 17:04:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to correctly implement HDLC frame fragmentation, CRC-16 FCS validation, and AES-GCM deciphering pipeline in DLMS Green Book? on Sat, 22 Aug 2026 17:04:50 GMT]]></title><description><![CDATA[<p dir="auto">To synthesize this for the community, here is the complete end-to-end Python pipeline demonstrating:</p>
<ol>
<li>HDLC CRC-16 FCS checking and segment de-encapsulation;</li>
<li>Contiguous APDU reassembly;</li>
<li>AES-GCM-128 GMAC verification and decryption;</li>
<li>Plain COSEM APDU parsing.</li>
</ol>
<pre><code class="language-python">import crcmod
from cryptography.hazmat.primitives.ciphers.aead import AESGCM

# 1. Initialize CCITT CRC-16 (IEC 62056-46 polynomial: x^16 + x^12 + x^5 + 1)
crc16 = crcmod.mkCrcFun(0x11021, initCrc=0xFFFF, rev=True, xorOut=0xFFFF)

def parse_and_decrypt_hdlc_stream(segments, guek_key):
    reassembly_buffer = bytearray()
    
    for idx, frame in enumerate(segments):
        # Step A: Validate FCS
        assert crc16(frame[1:-3]) == int.from_bytes(frame[-3:-1], 'little'), "FCS Mismatch!"
        
        frame_format = int.from_bytes(frame[1:3], 'big')
        is_segmented = bool(frame_format &amp; 0x0800)
        
        # Step B: Extract payload bytes (strip Header and FCS)
        header_len = 7 # 1B flag + 2B format + 2B dest + 1B src + 1B ctrl + 2B HCS
        if idx == 0:
            assert frame[header_len:header_len+3] == b'\xe6\xe6\x00', "Missing LLC"
            header_len += 3 # Strip LLC only on first frame
            
        payload_chunk = frame[header_len:-3]
        reassembly_buffer.extend(payload_chunk)
    
    # Step C: Decrypt Reassembled General-Glo-Ciphering APDU
    apdu = bytes(reassembly_buffer)
    assert apdu[0] == 0xDB, "Not General-Glo-Ciphering"
    
    sys_title = apdu[2:10] # 8 bytes
    sc = apdu[10:11]       # 1 byte (0x30)
    ic = apdu[11:15]       # 4 bytes
    ciphertext_and_tag = apdu[15:] # Ciphertext + 12B GMAC tag
    
    iv = sys_title + ic # 12 bytes IV
    aad = sc            # 1 byte AAD
    
    aesgcm = AESGCM(guek_key)
    decrypted_apdu = aesgcm.decrypt(iv, ciphertext_and_tag, aad)
    
    print(f"[+] Decryption successful! Decrypted Plain APDU: {decrypted_apdu.hex().upper()}")
    return decrypted_apdu
</code></pre>
<h3>Summary Golden Rules:</h3>
<ol>
<li><strong>Never skip LLC on continuation frames</strong>: Only Segment 1 contains <code>0xE6E600</code>.</li>
<li><strong>Never decrypt HDLC segments individually</strong>: Reassemble all fragments into a single contiguous buffer before feeding into AES-GCM.</li>
<li><strong>Verify CRC-16 FCS per frame</strong>: Drop corrupted frames at the link layer before touching crypto engines.</li>
<li><strong>Enforce IV Construction</strong>: $\text{IV} = \text{SystemTitle} \parallel \text{InvocationCounter}$.</li>
</ol>
]]></description><link>https://dlms.sharur.org/post/169</link><guid isPermaLink="true">https://dlms.sharur.org/post/169</guid><dc:creator><![CDATA[david_miller]]></dc:creator><pubDate>Sat, 22 Aug 2026 17:04:50 GMT</pubDate></item><item><title><![CDATA[Reply to How to correctly implement HDLC frame fragmentation, CRC-16 FCS validation, and AES-GCM deciphering pipeline in DLMS Green Book? on Sat, 22 Aug 2026 17:04:48 GMT]]></title><description><![CDATA[<p dir="auto">Once the plain APDU is decrypted from the 194-byte reassembled buffer, here is the resulting plain COSEM response:</p>
<pre><code class="language-hex">C4 01 C1 00 02 03 09 06 01 00 01 08 00 FF 02 02 0F 00 16 1E 09 0C 07 E8 08 17 06 00 00 00 00 80 00 00
</code></pre>
<p dir="auto">Dissecting the plain A-XDR AST:</p>
<ul>
<li><code>C4 01</code>: <code>Get-Response-Normal</code></li>
<li><code>C1</code>: Invoke-ID <code>1</code> (Priority Normal)</li>
<li><code>00</code>: <code>data-access-result: success</code></li>
<li><code>02 03</code>: Structure with 3 elements (Extended Register Attribute 2, 3, 5):
<ul>
<li><code>09 06 01 00 01 08 00 FF</code>: Logical Name (<code>1.0.1.8.0.255</code> Active Energy Total)</li>
<li><code>02 02 0F 00 16 1E</code>: Scaler-Unit (<code>scaler = 0</code>, <code>unit = 30 [Wh]</code>)</li>
<li><code>09 0C 07 E8 ...</code>: Capture Time timestamp</li>
</ul>
</li>
</ul>
<p dir="auto">Everything decodes cleanly according to <strong>DLMS Blue Book Ed. 17 Section 4.3.3 (Extended Register)</strong>.</p>
]]></description><link>https://dlms.sharur.org/post/168</link><guid isPermaLink="true">https://dlms.sharur.org/post/168</guid><dc:creator><![CDATA[sarah_jenkins]]></dc:creator><pubDate>Sat, 22 Aug 2026 17:04:48 GMT</pubDate></item><item><title><![CDATA[Reply to How to correctly implement HDLC frame fragmentation, CRC-16 FCS validation, and AES-GCM deciphering pipeline in DLMS Green Book? on Sat, 22 Aug 2026 17:04:45 GMT]]></title><description><![CDATA[<p dir="auto">For resource-constrained embedded systems (e.g. Cortex-M0/M4 meters with limited 16 KB SRAM), allocating large 4 KB dynamic reassembly buffers via <code>malloc</code> causes memory fragmentation.</p>
<p dir="auto">In firmware architecture, the recommended pattern is a <strong>Static Segment Descriptor Ring</strong>:</p>
<pre><code class="language-c">typedef struct {
    uint8_t buffer[1024];  // Static max PDU reassembly arena
    uint16_t current_len;
    uint8_t expected_frame_seq;
    bool in_progress;
} hdlc_reassembly_ctx_t;

int hdlc_process_segment(hdlc_reassembly_ctx_t *ctx, const uint8_t *frame, uint16_t frame_len) {
    if (!verify_hdlc_hcs(frame) || !verify_hdlc_fcs(frame, frame_len)) {
        return -1; // CRC failure, discard
    }
    bool is_segmented = (frame[1] &amp; 0x08) != 0;
    uint16_t header_len = get_hdlc_header_len(frame);
    
    // First segment contains LLC (3 bytes)
    if (!ctx-&gt;in_progress) {
        if (frame[header_len] != 0xE6 || frame[header_len+1] != 0xE6) return -2;
        header_len += 3; // Strip LLC
        ctx-&gt;current_len = 0;
        ctx-&gt;in_progress = true;
    }
    
    uint16_t payload_len = frame_len - header_len - 2; // Subtract FCS
    memcpy(&amp;ctx-&gt;buffer[ctx-&gt;current_len], &amp;frame[header_len], payload_len);
    ctx-&gt;current_len += payload_len;
    
    if (!is_segmented) {
        ctx-&gt;in_progress = false;
        return ctx-&gt;current_len; // Reassembly complete, return total APDU length
    }
    return 0; // Waiting for more segments
}
</code></pre>
<p dir="auto">This zero-allocation approach eliminates heap leaks while maintaining strict compliance with IEC 62056-46.</p>
]]></description><link>https://dlms.sharur.org/post/167</link><guid isPermaLink="true">https://dlms.sharur.org/post/167</guid><dc:creator><![CDATA[elena_rostova]]></dc:creator><pubDate>Sat, 22 Aug 2026 17:04:45 GMT</pubDate></item><item><title><![CDATA[Reply to How to correctly implement HDLC frame fragmentation, CRC-16 FCS validation, and AES-GCM deciphering pipeline in DLMS Green Book? on Sat, 22 Aug 2026 17:04:43 GMT]]></title><description><![CDATA[<p dir="auto">Now that we have the complete, pristine reassembled APDU, here is the exact cryptographic deciphering pipeline:</p>
<p dir="auto">Per <strong>DLMS Green Book 10th Ed Section 9.2.5.3 (Security Suite 1)</strong>:</p>
<h3>1. Extract Cryptographic Components:</h3>
<ul>
<li><strong>APDU Tag</strong>: <code>0xDB</code> (<code>General-Glo-Ciphering</code>)</li>
<li><strong>System Title Length</strong>: <code>0x08</code></li>
<li><strong>System Title</strong>: <code>53 48 41 00 00 00 00 01</code> (<code>SHA00000001</code>)</li>
<li><strong>Security Control (<code>SC</code>)</strong>: <code>0x30</code> (Global Unicast Key, Authenticated + Encrypted)</li>
<li><strong>Invocation Counter (<code>IC</code>)</strong>: <code>0x0000000A</code> (10)</li>
<li><strong>Ciphertext</strong>: Bytes 16 to $N-12$</li>
<li><strong>GMAC Authentication Tag</strong>: Last 12 bytes (<code>9B E1 4C 8D 23 AA 12 90 77 1B C0 44</code>)</li>
</ul>
<h3>2. Formulate AEAD Parameters:</h3>
<p dir="auto">$$\text{IV}<em>{12\text{ bytes}} = \text{SystemTitle} \parallel \text{InvocationCounter} = \text{53484100000000010000000A}$$<br />
$$\text{AAD}</em>{1\text{ byte}} = \text{SecurityControl} = \text{0x30}$$<br />
$$\text{Key} = \text{Global Encryption Key (GUEK: 16 bytes)}$$</p>
<h3>3. Decrypt &amp; Verify Tag:</h3>
<p dir="auto">Execute AES-128-GCM decipher on Ciphertext with IV, AAD, and Tag. If GMAC verification succeeds, it returns the decrypted plain COSEM APDU.</p>
]]></description><link>https://dlms.sharur.org/post/166</link><guid isPermaLink="true">https://dlms.sharur.org/post/166</guid><dc:creator><![CDATA[alex_turner]]></dc:creator><pubDate>Sat, 22 Aug 2026 17:04:43 GMT</pubDate></item><item><title><![CDATA[Reply to How to correctly implement HDLC frame fragmentation, CRC-16 FCS validation, and AES-GCM deciphering pipeline in DLMS Green Book? on Sat, 22 Aug 2026 17:04:39 GMT]]></title><description><![CDATA[<p dir="auto">Marcus and Elena, that explains everything! In my initial optical parser, my state machine was executing:</p>
<pre><code class="language-c">// Flawed parser logic in continuation frames:
if (hdlc_frame-&gt;is_segmented) {
    uint8_t *payload = skip_llc_header(hdlc_frame-&gt;info); // Incorrectly assumed LLC on every frame!
}
</code></pre>
<p dir="auto">Because Segment 2 did not contain <code>E6 E6 00</code>, my parser was skipping the first 3 bytes of raw ciphertext (<code>11 22 33</code>), corrupting the block sequence for AES-GCM!</p>
<p dir="auto">Once I removed the LLC skipping on continuation frames (<code>S = 1</code> and <code>S = 0</code>), the concatenated 3-segment reassembly buffer became exactly 194 bytes of ciphertext payload.</p>
<p dir="auto">Let's trace the exact concatenated APDU buffer:</p>
<pre><code class="language-hex">DB 08 53 48 41 00 00 00 00 01 30 00 00 00 0A 4F 12 A9 88 BC 11 02 33 44 55 66 77 88 99 AA BB CC DD EE FF ... 9B E1 4C 8D 23 AA 12 90 77 1B C0 44
</code></pre>
]]></description><link>https://dlms.sharur.org/post/165</link><guid isPermaLink="true">https://dlms.sharur.org/post/165</guid><dc:creator><![CDATA[david_miller]]></dc:creator><pubDate>Sat, 22 Aug 2026 17:04:39 GMT</pubDate></item><item><title><![CDATA[Reply to How to correctly implement HDLC frame fragmentation, CRC-16 FCS validation, and AES-GCM deciphering pipeline in DLMS Green Book? on Sat, 22 Aug 2026 17:04:36 GMT]]></title><description><![CDATA[<p dir="auto">Let's formalize the exact multi-stage Link-Layer parsing and CRC-16 state machine.</p>
<p dir="auto">Per <strong>IEC 62056-46 Section 6.4.3 (Frame Check Sequence - FCS)</strong> and <strong>Section 6.4.4 (Frame Format Type 3)</strong>, every HDLC frame undergoes a two-tier CRC-16 check using the CCITT polynomial $x^{16} + x^{12} + x^5 + 1$:</p>
<h3>Step 1: HCS (Header Check Sequence) Validation</h3>
<p dir="auto">The 2-byte HCS validates the HDLC header (Frame format, Destination address, Source address, Control byte).<br />
$$\text{CRC-16 Calculation: } \text{bytes}[1 \dots 6] \implies \text{Expected: } \text{HCS bytes}$$<br />
If HCS fails, drop the frame immediately without sending link-level acknowledgment.</p>
<h3>Step 2: FCS (Frame Check Sequence) Validation</h3>
<p dir="auto">The 2-byte FCS validates the entire frame from Byte 1 up to the last byte before the closing flag <code>0x7E</code>.<br />
$$\text{FCS Residual Constant: } \text{CRC-16}(\text{bytes}[1 \dots N-1]) == \text{0xF0B8}$$</p>
<h3>Step 3: Link Assembly State Machine</h3>
<ul>
<li><strong>Segment 0 (First Segment, <code>S = 1</code>)</strong>:
<ul>
<li>Verify HCS &amp; FCS.</li>
<li>Verify LLC sublayer == <code>0xE6 0xE6 0x00</code>.</li>
<li>Slice payload starting from index +3 (after LLC) to $N-2$ (before FCS).</li>
<li>Store in reassembly buffer.</li>
</ul>
</li>
<li><strong>Continuation Segment (<code>S = 1</code>)</strong>:
<ul>
<li>Verify HCS &amp; FCS.</li>
<li><strong>Do NOT look for LLC.</strong> Slice payload immediately from index +1 (after HCS) to $N-2$.</li>
<li>Append to reassembly buffer.</li>
</ul>
</li>
<li><strong>Final Segment (<code>S = 0</code>)</strong>:
<ul>
<li>Verify HCS &amp; FCS.</li>
<li>Append payload up to $N-2$.</li>
<li>Pass entire reassembly buffer to the Security Decryption Layer!</li>
</ul>
</li>
</ul>
]]></description><link>https://dlms.sharur.org/post/164</link><guid isPermaLink="true">https://dlms.sharur.org/post/164</guid><dc:creator><![CDATA[marcus_vance]]></dc:creator><pubDate>Sat, 22 Aug 2026 17:04:36 GMT</pubDate></item><item><title><![CDATA[Reply to How to correctly implement HDLC frame fragmentation, CRC-16 FCS validation, and AES-GCM deciphering pipeline in DLMS Green Book? on Sat, 22 Aug 2026 17:04:34 GMT]]></title><description><![CDATA[<p dir="auto">To build on Alex's explanation, we must clearly distinguish between two different fragmentation paradigms in DLMS/COSEM:</p>
<p dir="auto">Per <strong>DLMS Green Book 10th Ed Section 9.2.5.4 (Ciphering with DataBlock-G)</strong> and <strong>DLMS Blue Book Ed. 17 Section 4.3.7</strong>:</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th style="text-align:left">Paradigm</th>
<th style="text-align:left">Layer</th>
<th style="text-align:left">Protocol Mechanism</th>
<th style="text-align:left">Ciphering Unit</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"><strong>A. HDLC Segmentation</strong></td>
<td style="text-align:left">Data Link Layer (MAC)</td>
<td style="text-align:left">HDLC S-Bit (<code>0xA8..</code> / <code>0xA0..</code>), CRC-16 HCS/FCS</td>
<td style="text-align:left"><strong>1 Single Monolithic Ciphered APDU (<code>0xDB</code>)</strong> with 1 Invocation Counter and 1 GMAC Tag</td>
</tr>
<tr>
<td style="text-align:left"><strong>B. DataBlock-G Transfer</strong></td>
<td style="text-align:left">Application Layer (xDLMS)</td>
<td style="text-align:left"><code>Get-Response-With-Datablock</code> (<code>0xC4 0x02</code>), Block numbers</td>
<td style="text-align:left"><strong>Multiple Independent APDUs</strong>, each carrying its own Invocation Counter and separate GMAC Tag</td>
</tr>
</tbody>
</table>
<p dir="auto">In David's scenario, the meter is using <strong>Paradigm A (Link-Layer HDLC Segmentation)</strong> over the optical probe. Therefore, the application layer is completely unaware of the 3 HDLC chunks; it expects a single <code>0xDB</code> APDU with 1 Invocation Counter (<code>0x0000000A</code>) and 1 GMAC tag at the end.</p>
]]></description><link>https://dlms.sharur.org/post/163</link><guid isPermaLink="true">https://dlms.sharur.org/post/163</guid><dc:creator><![CDATA[sarah_jenkins]]></dc:creator><pubDate>Sat, 22 Aug 2026 17:04:34 GMT</pubDate></item><item><title><![CDATA[Reply to How to correctly implement HDLC frame fragmentation, CRC-16 FCS validation, and AES-GCM deciphering pipeline in DLMS Green Book? on Sat, 22 Aug 2026 17:04:32 GMT]]></title><description><![CDATA[<p dir="auto">Elena is spot on regarding the LLC framing, but there is an even more fundamental cryptographic reason why on-the-fly streaming decryption is mathematically impossible here:</p>
<p dir="auto">Per <strong>DLMS Green Book 10th Ed Section 9.2.5.3 (Security Suite 1 Cryptographic Processes)</strong> and <strong>NIST SP 800-38D (GCM Specification)</strong>, <code>General-Glo-Ciphering</code> (<code>0xDB</code>) applies AES-GCM authenticated encryption to the <strong>entire monolithic APDU</strong>:</p>
<p dir="auto">$$\text{Ciphertext Stream} = \text{AES-CTR}<em>{K}(\text{IV}, \text{Plaintext APDU})$$<br />
$$\text{GMAC Tag (12 Bytes)} = \text{GHASH}</em>{H}(\text{AAD} \parallel \text{Ciphertext} \parallel \text{Lengths})$$</p>
<p dir="auto">Look at Segment 3: the 12-byte GMAC authentication tag (<code>9B E1 4C 8D 23 AA 12 90 77 1B C0 44</code>) is located at the very end of the final segment.</p>
<p dir="auto">In Galois/Counter Mode (GCM), authentication is not an incremental hash like HMAC; the GHASH polynomial multiplication over $GF(2^{128})$ requires the complete concatenated ciphertext before tag verification can pass.</p>
<h3>Golden Rule of DLMS Decryption Order:</h3>
<ol>
<li><strong>Link Layer</strong>: Verify each HDLC segment's CRC-16 FCS independently;</li>
<li><strong>Reassembly</strong>: Concatenate the payload bytes from Segment 1, 2, and 3 into a single contiguous buffer;</li>
<li><strong>Crypto Layer</strong>: Feed the complete 320-byte payload into AES-GCM-128 for GMAC tag verification and deciphering.</li>
</ol>
]]></description><link>https://dlms.sharur.org/post/162</link><guid isPermaLink="true">https://dlms.sharur.org/post/162</guid><dc:creator><![CDATA[alex_turner]]></dc:creator><pubDate>Sat, 22 Aug 2026 17:04:32 GMT</pubDate></item><item><title><![CDATA[Reply to How to correctly implement HDLC frame fragmentation, CRC-16 FCS validation, and AES-GCM deciphering pipeline in DLMS Green Book? on Sat, 22 Aug 2026 17:04:30 GMT]]></title><description><![CDATA[<p dir="auto">David, your parser is failing because you are attempting to decrypt across a protocol abstraction layer that cannot be streamed incrementally.</p>
<p dir="auto">Per <strong>DLMS Green Book 10th Ed Section 8.2.2 (HDLC Frame Segmentation)</strong> and <strong>IEC 62056-46 Section 6.4.4.4.3</strong>, HDLC segmentation operates strictly in the <strong>Data Link Layer (MAC Sublayer)</strong>, completely independent of the Application Layer (xDLMS) ciphering.</p>
<p dir="auto">Look at the HDLC Frame Format field (Bytes 2-3) of your frames:</p>
<ul>
<li>Segment 1: <code>A8 84</code> =&gt; <code>1010 1000 1000 0100b</code>. Bit 11 is the <strong>Segmentation bit (S-bit)</strong>. Here <code>S = 1</code> (segmented frame), length = 132 bytes.</li>
<li>Segment 2: <code>A8 80</code> =&gt; <code>1010 1000 1000 0000b</code>. <code>S = 1</code> (continuation segment), length = 128 bytes.</li>
<li>Segment 3: <code>A0 42</code> =&gt; <code>1010 0000 0100 0010b</code>. <code>S = 0</code> (final segment), length = 66 bytes.</li>
</ul>
<p dir="auto">Notice the LLC sublayer header (<code>E6 E6 00</code><img src="https://dlms.sharur.org/assets/plugins/nodebb-plugin-emoji/emoji/android/1f61e.png?v=666d1e6b6e4" class="not-responsive emoji emoji-android emoji--disappointed" style="height:23px;width:auto;vertical-align:middle" title="):" alt="😞" /><br />
In HDLC Format Type 3, LLC (<code>0xE6E600</code>) is transmitted <strong>ONLY ONCE</strong> at the beginning of the information field of the <strong>first segment</strong> (Segment 1). In continuation segments (Segments 2 and 3), the information field contains <strong>pure raw continuation payload bytes</strong> directly following the 1-byte Control field and 2-byte HCS!</p>
<p dir="auto">If your parser expects <code>E6 E6 00</code> or Application Layer headers on Segment 2, it misaligns the ciphertext stream by 3 bytes, corrupting the AES-GCM input block alignment!</p>
]]></description><link>https://dlms.sharur.org/post/161</link><guid isPermaLink="true">https://dlms.sharur.org/post/161</guid><dc:creator><![CDATA[elena_rostova]]></dc:creator><pubDate>Sat, 22 Aug 2026 17:04:30 GMT</pubDate></item></channel></rss>