webbluetooth_linux/lib.rs
1//! Linux BLE from pure Rust, with no dependencies.
2//!
3//! Two ways to reach a controller, because Linux offers two:
4//!
5//! * **`bluez`** — the supported path, over `dbus` to `org.bluez`. Pairing,
6//! bonding and agents are the daemon's problem.
7//! * **`hci` + `gatt`** — no daemon at all. ATT over an L2CAP socket for
8//! GATT, a raw HCI socket for scanning.
9//!
10//! Neither binds a C library. D-Bus is a wire protocol over a Unix socket and
11//! is spoken as one; ATT, HCI and L2CAP are kernel sockets reached through
12//! `sys`.
13//!
14//! [`dbus::codec`], [`dbus::value`] and `att` are pure byte manipulation and
15//! build everywhere, so the parts where the bugs live — alignment, truncation,
16//! signature-directed decoding — are unit-tested on any host rather than only
17//! inside a container.
18//!
19//! ## License
20//! MIT — Copyright © 2025 [Eugene Hauptmann](https://github.com/eugenehp)
21
22pub mod att;
23pub mod dbus;
24
25/// LE scanning. The advertising-data parser is portable; only the raw socket
26/// inside it is Linux-only.
27pub mod hci;
28// LE Audio's ISO packets go through the same raw socket as ACL and SCO.
29#[cfg(all(
30 target_os = "linux",
31 any(feature = "raw-acl", feature = "raw-sco", feature = "le-audio")
32))]
33pub mod raw_hci;
34
35// The adapter: BlueZ expressed as the portable model.
36#[cfg(target_os = "linux")]
37// Public so `webbluetooth` can reach it, and not an API anyone else
38// should call: the facade is what a caller holds. Hidden from the docs
39// for the same reason, which also keeps the same 38 adapter methods from
40// being documented six times over.
41#[doc(hidden)]
42pub mod backend;
43// The peripheral-role adapter: a GATT server expressed as the portable model.
44#[cfg(target_os = "linux")]
45pub mod peripheral_backend;
46
47// The same adapter without BlueZ: ATT over an L2CAP socket for GATT, a raw
48// HCI socket for scanning.
49//
50// Compiled whenever the other one is, rather than behind the `linux-hci`
51// feature that selects it. Two adapters that are only ever built one at a
52// time are two adapters that drift, and this one is the one almost nobody
53// builds.
54#[cfg(all(feature = "profiles", feature = "classic-l2cap", target_os = "linux"))]
55pub mod a2dp;
56#[cfg(all(feature = "profiles", feature = "rfcomm", target_os = "linux"))]
57pub mod avrcp;
58#[cfg(target_os = "linux")]
59// Public so `webbluetooth` can reach it, and not an API anyone else
60// should call: the facade is what a caller holds. Hidden from the docs
61// for the same reason, which also keeps the same 38 adapter methods from
62// being documented six times over.
63#[doc(hidden)]
64pub mod backend_hci;
65#[cfg(target_os = "linux")]
66pub mod bluez;
67#[cfg(all(
68 target_os = "linux",
69 feature = "classic",
70 any(feature = "rfcomm", feature = "classic-l2cap")
71))]
72pub mod classic_profile;
73#[cfg(all(feature = "profiles", feature = "rfcomm", target_os = "linux"))]
74pub mod dun;
75#[cfg(target_os = "linux")]
76pub mod gatt;
77#[cfg(all(feature = "profiles", feature = "rfcomm", target_os = "linux"))]
78pub mod hfp;
79#[cfg(all(target_os = "linux", feature = "profiles", feature = "classic-l2cap"))]
80pub mod hid_host;
81#[cfg(target_os = "linux")]
82pub mod l2cap;
83#[cfg(all(target_os = "linux", feature = "classic-l2cap"))]
84pub mod l2cap_classic;
85#[cfg(all(feature = "profiles", feature = "rfcomm", target_os = "linux"))]
86pub mod obex;
87#[cfg(all(feature = "profiles", feature = "classic-l2cap", target_os = "linux"))]
88pub mod pan;
89#[cfg(target_os = "linux")]
90#[cfg(feature = "classic")]
91#[cfg(feature = "rfcomm")]
92#[cfg(feature = "rfcomm")]
93pub mod rfcomm;
94#[cfg(all(feature = "classic", target_os = "linux"))]
95pub mod sdp;
96#[cfg(target_os = "linux")]
97pub mod sys;