bluetooth-host 0.2.0

A Bluetooth host stack over raw HCI: observer, broadcaster, central and peripheral, L2CAP, ATT and GATT, SMP pairing and bonding, privacy
Documentation

bluetooth-host

crates.io docs.rs

A Bluetooth host stack over raw HCI.

cargo add bluetooth-host

It talks to a controller directly, over the Linux HCI user channel, H4 on a serial port, or H4 over TCP, so the same features work on every board with no BlueZ or D-Bus. HCI commands and events are encoded and decoded by the bt_hci crate; everything above HCI is here:

  • controller capability discovery, so features degrade cleanly on old chips;
  • the observer: passive and active scanning, legacy and extended reports, the coded PHY, periodic advertising sync, duplicate filtering, and private addresses resolved to identities;
  • the broadcaster: legacy, extended and periodic advertising sets;
  • central and peripheral connections, parameter, PHY and data length updates;
  • L2CAP signaling and LE credit-based channels;
  • ATT, a GATT client, and a GATT server built at run time;
  • SMP: legacy and Secure Connections pairing, every association model, bonding with a persistent key store, and privacy.
# async fn demo() -> bluetooth_host::Result<()> {
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);
}
# Ok(()) }

Part of bluetooth-bridge, maintained by Pulzar. See the user guide, the library guide and the API documentation.

License: MIT.