bluetooth-host
The Bluetooth host stack, over raw HCI. crates.io, docs.rs, API docs for main.
What it does
Section titled “What it does”- Transports: the Linux HCI user channel, H4 on a serial port, H4 over
TCP (
TransportSpecparseshci0,serial:PATH:BAUD,tcp:HOST:PORT). - Capability discovery: everything the controller supports, read at start; every feature checks before it asks.
- Observer: passive and active scanning, legacy and extended reports, the coded PHY, fragmented report reassembly, periodic advertising sync, duplicate filtering in the host, and private addresses resolved to identities.
- Broadcaster: legacy, extended and periodic advertising sets.
- Connections as central and peripheral, with parameter, PHY and data length updates.
- L2CAP signaling and LE credit-based channels.
- ATT and GATT: a client with every procedure, and a server built at run time with per-attribute security.
- SMP: legacy and Secure Connections pairing, every association model, bonding with a persistent key store, and privacy.
- Probe: identify a controller with read-only commands.
Example: scanning
Section titled “Example: scanning”use bluetooth_host::{Host, HostConfig, HostEvent, ScanConfig};let host = Host::open(&"hci0".parse().unwrap(), HostConfig::default()).await?;let mut events = host.events();host.start_scan(ScanConfig::default()).await?;while let Ok(HostEvent::Advertisement(r)) = events.recv().await { println!("{} {} dBm {:?}", r.device(), r.rssi, r.advertisement().local_name);}Host::open opens the transport and initializes the controller;
events() is a broadcast receiver of HostEvents, so several tasks can
listen. This example is compiled in CI.
The main types
Section titled “The main types”| Type | What it is |
|---|---|
Host |
the stack; cheap to clone, methods take &self |
HostConfig |
data directory for bonds, device name and appearance, pairing (IO capability, an Agent for passkeys and confirmations, bonding, MITM) |
HostEvent |
advertisements, connections, pairing, GATT server activity, periodic reports |
ScanConfig, AdvertisingParams |
how to scan and advertise |
Connection |
one connection: parameters, PHY, L2CAP channels, gatt(), pair() |
Address |
a device address with its type |
Features
Section titled “Features”| Feature | Default | What |
|---|---|---|
serial |
yes | H4 over serial ports |
schema |
no | JSON Schema for configuration types |