maauto: set CONTROL on encrypted channel-0 sends
- Commit
6f4c103a8a02ee35277d70dee7718d51b97c4cbe- Author
- vayun-mathur <[email protected]>
- When
- 2026-09-12 14:57 UTC (2 months ago)
- Parents
25d0ad0
Diff
auto/protocol/src/main/java/com/vayunmathur/auto/protocol/GalConnection.kt
diff --git a/auto/protocol/src/main/java/com/vayunmathur/auto/protocol/GalConnection.kt b/auto/protocol/src/main/java/com/vayunmathur/auto/protocol/GalConnection.ktindex 844909e2a2..d3d6ccd497 100644--- a/auto/protocol/src/main/java/com/vayunmathur/auto/protocol/GalConnection.kt+++ b/auto/protocol/src/main/java/com/vayunmathur/auto/protocol/GalConnection.kt@@ -107,8 +107,16 @@ class GalConnection( write( channelId = CONTROL_CHANNEL, payload = MessageCodec.encode(message.type, message.payload),- // Never set on channel 0; see isChannelControlMessage.- isControl = false,+ // Set on encrypted channel-0 messages, clear on the plaintext+ // version/handshake frames. Dalvik ground truth (`Ljbe.i` flag+ // assembly): every `jbj.k` send builds `Lizm.f = true`, which ORs+ // in 0x04 -- so gearhead's 0x5/0x7/ping-responses go out as+ // FIRST|LAST|CONTROL|ENCRYPTED = 0x0F. DHU 2.0 accepts a+ // CONTROL-less 0x5 (discovery path doesn't check) but answers a+ // CONTROL-less 0x7 with an empty 0xff and no 0x8 (Run 5: every+ // service refused). Version/handshake stay clear: those were+ // accepted as-is and they ride pre-TLS.+ isControl = message.encrypted, encrypted = message.encrypted, ) }
auto/protocol/src/test/java/com/vayunmathur/auto/protocol/GalConnectionTest.kt
diff --git a/auto/protocol/src/test/java/com/vayunmathur/auto/protocol/GalConnectionTest.kt b/auto/protocol/src/test/java/com/vayunmathur/auto/protocol/GalConnectionTest.ktindex 1cba60cd37..af26f576b7 100644--- a/auto/protocol/src/test/java/com/vayunmathur/auto/protocol/GalConnectionTest.kt+++ b/auto/protocol/src/test/java/com/vayunmathur/auto/protocol/GalConnectionTest.kt@@ -107,6 +107,46 @@ class GalConnectionTest { assertTrue(transport.written.size() > 0, "the head unit should have been answered") } + @Test+ fun `an encrypted control message carries the CONTROL bit`() {+ // Dalvik ground truth (`Ljbe.i`): every `jbj.k` send builds Lizm.f=true,+ // which ORs 0x04 into the flags -- encrypted channel-0 messages go out+ // as FIRST|LAST|CONTROL|ENCRYPTED = 0x0F. DHU 2.0 answers a+ // CONTROL-less 0x7 with an empty 0xff and no 0x8 (Run 5).+ val transport = FakeTransport()+ val connection = connection(transport)+ connection.send(+ OutboundMessage(+ type = GalMessage.Control.CHANNEL_OPEN_REQUEST,+ payload = byteArrayOf(0x08, 0x00, 0x10, 0x02),+ encrypted = true,+ ),+ )++ val written = transport.written.toByteArray()+ assertEquals(0x00, written[0])+ assertEquals(0x0F, written[1].toInt() and 0xFF)+ }++ @Test+ fun `a plaintext control message leaves the CONTROL bit clear`() {+ // Version negotiation rides pre-TLS and was accepted as-is; only+ // encrypted channel-0 messages get the bit.+ val transport = FakeTransport()+ val connection = connection(transport)+ connection.send(+ OutboundMessage(+ type = GalMessage.Control.VERSION_RESPONSE,+ payload = byteArrayOf(0x00, 0x01, 0x00, 0x06, 0x00, 0x00),+ encrypted = false,+ ),+ )++ val written = transport.written.toByteArray()+ assertEquals(0x00, written[0])+ assertEquals(0x03, written[1].toInt() and 0xFF)+ }+ @Test fun `pump reports end of stream when the head unit goes away`() { val transport = FakeTransport()