Fix /pairings handler rejecting ListPairings with "tlv8: EOF"#67
Open
hughobrien wants to merge 71 commits into
Open
Fix /pairings handler rejecting ListPairings with "tlv8: EOF"#67hughobrien wants to merge 71 commits into
hughobrien wants to merge 71 commits into
Conversation
Fix error handling
Changes to a single style for all accessories setup, including using AddS() rather than a manual append(). Also cleans up spacing and formatting.
Improve consistency for Accessories
Some control points require that the response be returned after a write, as opposed to write-then-read. If the SetValueRequestFunc returns a value and has the WriteResponse permission, then the response is relayed back to the client on return. Status code must be explicitly returned in this case, via a MultiStatus return.
Implement WriteResponse characteristics
HomeKit expects an application/pairing+tlv8 content type for responses from /pairings, and fails to add the accessory if it gets something different. You can reproduce the error by attempting to add an accessory as a user who is an admin but not the owner of the home. This will result in a flow that will attempt to use the AddPairing method. On all my devices this fails unless the content type is application/pairing+tlv8.
use correct content-type for /pairings
feat: add motion and contact sensor accessories
fix: wrong bytes written for conn when encrypting
You can now specify an id for a service and characteristic. Since this ids have to be unique within an accessory, a check was added to make sure that the ids are actually unique.
Author
The /pairings handler decoded the request into a struct that marked
Identifier (tag 1) as required. A ListPairings request carries only
Method (tag 0) and State (tag 6) — no Identifier — so the tag-keyed
reader returned io.EOF for the missing required field and the handler
rejected the request (HTTP 400, "tlv8: EOF").
iOS uses ListPairings to reconcile a home's controllers (resident
HomePods/Apple TVs, additional devices). Because the request always
failed, iOS could never converge: it retried endlessly, re-attempting
RemovePairing for controllers it wanted to drop and leaving others
looping on pair-verify ("not paired with <id> yet").
Mark Identifier optional, completing the partial fix in 340cbe4 (brutella#21)
which made PublicKey and Permission optional but left Identifier
required. Resolves the unmarshal failure reported in brutella#21 and brutella#44.
Added a handler-level regression test using request bodies captured
from a real iOS controller.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
bd1f7e7 to
78932fb
Compare
This was referenced Jun 19, 2026
78932fb to
ae235b3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
/pairingshandler decodes requests into a struct that marksIdentifier(tag 1) as required. A ListPairings request contains onlyMethod(tag 0) andState(tag 6); it has noIdentifier. The tag-keyed reader returnsio.EOFfor the missing required field, sotlv8.UnmarshalReaderfails and the handler responds HTTP 400, loggingtlv8: EOF.iOS issues ListPairings to enumerate an accessory's paired controllers. With the request always failing, the controller set never reconciles; ListPairings, RemovePairing, and pair-verify are retried indefinitely.
Change
Mark
Identifieroptional. 340cbe4 (#21) previously madePublicKeyandPermissionoptional but leftIdentifierrequired, so ListPairings still failed. Fixes #21 and #44.Captured requests
pairings()was instrumented to logContentLength, the read body length and error, and the raw bytes immediately beforetlv8.UnmarshalReader. Observed during pairing with a real controller:The failing body is fully read (
bodyLen=6,readErr=<nil>); it is not empty or truncated. Decoding000105060101:Test
TestPairingsHandlerRequestsreplays the captured bodies against the handler.master:
this PR: