Add HCI user channel support#56
Merged
Merged
Conversation
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
Adds support for the HCI user channel (
HCI_CHANNEL_USER), which grants a process exclusive access to a Bluetooth controller while detaching the kernel's host stack:HCIUserChannel— actor bound to a specific controller on the user channel. While open, all HCI traffic (commands, events, ACL and SCO data) flows through the socket.HCIUserChannel.open(device:)powers the controller off first, since the kernel requires the device to be down before the channel can be opened. RequiresCAP_NET_ADMIN(root).Packettype (packet type prefix plus payload) with wire decoding, andsend/receivefor arbitrary HCI traffic.send(_:parameter:)fires a command without waiting;request(_:parameter:)sends a command and waits for the matching Command Complete event (returning its parameters) or Command Status event (throwing the typedHCIErroron failure), skipping unrelated packets. Socket filters do not apply on the user channel, so matching is done in the receive loop.HCIPacketTypenow conforms toSendable(required for the packet type under strict concurrency checking).This enables exclusive-access use cases such as broadcasting beacons from a fully controlled adapter, controller bring-up and testing, and future packet capture tooling.
Test plan
HCIError, truncated packet rejection, and ignoring of ACL data and LE meta events in response matchingswift buildsucceeds with no new warningsCAP_NET_ADMIN(root)