maauto: scope CONTROL bit to channel-open sends
- Commit
b3f63711b9f0e014f91df8d005d543c66dce69fc- Author
- vayun-mathur <[email protected]>
- When
- 2026-09-12 14:58 UTC (2 months ago)
- Parents
6f4c103
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 d3d6ccd497..3e10fd4813 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,16 +107,10 @@ class GalConnection( write( channelId = CONTROL_CHANNEL, payload = MessageCodec.encode(message.type, message.payload),- // 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,+ // Per-message: only the channel-open request sets CONTROL today.+ // The CONTROL-less 0x5 is live-accepted, so nothing else takes the+ // bit; see OutboundMessage.isControl.+ isControl = message.isControl, encrypted = message.encrypted, ) }
auto/protocol/src/main/java/com/vayunmathur/auto/protocol/GalControlSession.kt
diff --git a/auto/protocol/src/main/java/com/vayunmathur/auto/protocol/GalControlSession.kt b/auto/protocol/src/main/java/com/vayunmathur/auto/protocol/GalControlSession.ktindex bfe19df0ed..6a3d94d8d3 100644--- a/auto/protocol/src/main/java/com/vayunmathur/auto/protocol/GalControlSession.kt+++ b/auto/protocol/src/main/java/com/vayunmathur/auto/protocol/GalControlSession.kt@@ -22,6 +22,15 @@ class OutboundMessage( val payload: ByteArray, /** Whether the frame should be TLS-wrapped and flagged [FrameFlags.ENCRYPTED]. */ val encrypted: Boolean,+ /**+ * Whether to set the frame's [FrameFlags.CONTROL] bit.+ *+ * Only the channel-open request sets this today: DHU 2.0 answers a+ * CONTROL-less 0x7 with an empty 0xff and no 0x8 (Run 5), while a+ * CONTROL-less 0x5 is accepted -- so the bit is scoped to the 0x7 path+ * rather than applied to every encrypted channel-0 send.+ */+ val isControl: Boolean = false, ) /** Where the session has got to. */@@ -140,6 +149,12 @@ class GalControlSession( * STATUS_SUCCESS ([refusedChannels] on anything else). Nothing may be sent * on the channel before that -- gearhead's `jdk.Q()` sends media setup from * `onChannelOpened`.+ *+ * The frame carries the CONTROL bit: Dalvik ground truth (`Ljbe.i` flag+ * assembly) shows every `jbj.k` send builds `Lizm.f = true`, which ORs in+ * 0x04, so gearhead's 0x7 goes out as FIRST|LAST|CONTROL|ENCRYPTED = 0x0F.+ * Scoped to this path only -- the CONTROL-less 0x5 is live-accepted, so no+ * other channel-0 send takes the bit. */ fun openChannel(service: Service, priority: Int = 0): OutboundMessage { pendingChannels += service.id@@ -151,6 +166,7 @@ class GalControlSession( .build() .toByteArray(), encrypted = true,+ isControl = true, ) }
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 af26f576b7..43eee374e5 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@@ -108,11 +108,11 @@ class GalConnectionTest { } @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).+ fun `the channel-open request carries the CONTROL bit`() {+ // Scoped to the 0x7 path only: DHU 2.0 answers a CONTROL-less 0x7 with+ // an empty 0xff and no 0x8 (Run 5), while the CONTROL-less 0x5 is+ // accepted -- so the bit goes on the open, nothing else. Dalvik ground+ // truth (`Ljbe.i`): gearhead's 0x7 goes out as 0x0F. val transport = FakeTransport() val connection = connection(transport) connection.send(@@ -120,6 +120,7 @@ class GalConnectionTest { type = GalMessage.Control.CHANNEL_OPEN_REQUEST, payload = byteArrayOf(0x08, 0x00, 0x10, 0x02), encrypted = true,+ isControl = true, ), ) @@ -129,22 +130,22 @@ class GalConnectionTest { } @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.+ fun `other control messages leave the CONTROL bit clear`() {+ // Discovery (0x5), ping responses and byebye ride CONTROL-less: the 0x5+ // is live-accepted that way, and nothing else has shown a need. 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,+ type = GalMessage.Control.SERVICE_DISCOVERY_REQUEST,+ payload = byteArrayOf(0x2A, 0x0E) + "Google Pixel 8".toByteArray(),+ encrypted = true, ), ) val written = transport.written.toByteArray() assertEquals(0x00, written[0])- assertEquals(0x03, written[1].toInt() and 0xFF)+ assertEquals(0x0B, written[1].toInt() and 0xFF) } @Test