att/
lib.rs

1#![doc(html_root_url = "https://docs.rs/att/0.2.1")]
2//! Bluetooth Low Energy Attribute Protocol Library.
3//!
4//! ref BLUETOOTH CORE SPECIFICATION Version 5.1 | Vol 3, Part F
5//!     Attribute Protocol (ATT)
6//!
7//! ## Example
8//!
9//! ```
10//! use att::packet as pkt;
11//! use att::server::*;
12//!
13//! /// GAP / GATT Service only (with no Characteristics)
14//! #[derive(Debug)]
15//! struct MyHandler;
16//!
17//! impl Handler for MyHandler {
18//!     fn handle_read_by_group_type_request(
19//!         &mut self,
20//!         item: &pkt::ReadByGroupTypeRequest,
21//!     ) -> Result<pkt::ReadByGroupTypeResponse, ErrorResponse> {
22//!         match (
23//!             item.starting_handle().clone().into(),
24//!             item.ending_handle().clone().into(),
25//!         ) {
26//!             (0x0001, 0xFFFF) => {
27//!                 Ok(vec![
28//!                     (0x0001.into(), 0x000B.into(), vec![0x00, 0x18].into()), // Generic Access
29//!                     (0x000C.into(), 0x000F.into(), vec![0x01, 0x18].into()), // Generic Attribute
30//!                 ]
31//!                 .into_iter()
32//!                 .collect())
33//!             }
34//!             (x, _) => Err(ErrorResponse::new(
35//!                 x.clone().into(),
36//!                 pkt::ErrorCode::AttributeNotFound,
37//!             )),
38//!         }
39//!     }
40//! }
41//!
42//! #[tokio::main(flavor = "current_thread")]
43//! async fn main() -> anyhow::Result<()> {
44//!     let server = Server::new()?;
45//!     // let connection = server.accept().await?;
46//!     // connection.run(MyHandler).await?;
47//!     Ok(())
48//! }
49//! ```
50//!
51//! # Supported target
52//!
53//! - x86_64-unknown-linux-gnu
54//!
55//! Tested on Linux 5.9 (Arch Linux)
56//!
57//! ## License
58//!
59//! Licensed under either of
60//! * Apache License, Version 2.0
61//!   ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
62//! * MIT license
63//!   ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
64//! at your option.
65//!
66//! ## Contribution
67//!
68//! Unless you explicitly state otherwise, any contribution intentionally submitted
69//! for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
70//! dual licensed as above, without any additional terms or conditions.!
71
72pub use crate::uuid::Uuid;
73pub use bdaddr::Address;
74pub use handle::Handle;
75pub use handler::{ErrorResponse, Handler};
76pub use server::Server;
77
78#[macro_use]
79mod macros;
80
81mod handle;
82mod handler;
83pub mod packet;
84pub mod server;
85mod size;
86mod sock;
87pub mod uuid;