1 //! These are strongly-typed identifiers representing the various objects
2 //! interacted with, mostly over FFI
3 
4 /// The ID of a connection at the GATT layer.
5 /// A ConnectionId is logically a (TransportIndex, ServerId) tuple,
6 /// where each contribute 8 bits to the 16-bit value.
7 #[derive(Debug, Copy, Clone, PartialEq, Hash, Eq, PartialOrd, Ord)]
8 pub struct ConnectionId(pub u16);
9 
10 impl ConnectionId {
11     /// Create a ConnectionId from a TransportIndex and ServerId
new(tcb_idx: TransportIndex, server_id: ServerId) -> ConnectionId12     pub const fn new(tcb_idx: TransportIndex, server_id: ServerId) -> ConnectionId {
13         ConnectionId(((tcb_idx.0 as u16) << 8) + (server_id.0 as u16))
14     }
15 
16     /// Extract the TransportIndex from a ConnectionId (upper 8 bits)
get_tcb_idx(&self) -> TransportIndex17     pub fn get_tcb_idx(&self) -> TransportIndex {
18         TransportIndex((self.0 >> 8) as u8)
19     }
20 
21     /// Extract the ServerId from a ConnectionId (lower 8 bits)
get_server_id(&self) -> ServerId22     pub fn get_server_id(&self) -> ServerId {
23         ServerId((self.0 & (u8::MAX as u16)) as u8)
24     }
25 }
26 
27 /// The server_if of a GATT server registered in legacy
28 #[derive(Debug, Copy, Clone, PartialEq, Hash, Eq)]
29 pub struct ServerId(pub u8);
30 
31 /// An arbitrary id representing a GATT transaction (request/response)
32 #[derive(Debug, Copy, Clone, PartialEq, Hash, Eq)]
33 pub struct TransactionId(pub u32);
34 
35 /// The TCB index in legacy GATT
36 #[derive(Debug, Copy, Clone, PartialEq, Hash, Eq)]
37 pub struct TransportIndex(pub u8);
38 
39 /// An advertising set ID (zero-based)
40 #[derive(Debug, Copy, Clone, PartialEq, Hash, Eq)]
41 pub struct AdvertiserId(pub u8);
42 
43 /// The handle of a given ATT attribute
44 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
45 pub struct AttHandle(pub u16);
46 
47 impl AttHandle {
48     /// The (only) reserved AttHandle
49     pub const RESERVED: Self = AttHandle(0);
50     /// The smallest valid AttHandle
51     pub const MIN: Self = AttHandle(1);
52     /// The largest valid AttHandle
53     pub const MAX: Self = AttHandle(0xFFFF);
54 }
55