1 use bt_topshim::btif::BtTransport;
2 use bt_topshim::profiles::gatt::LePhy;
3 
4 #[repr(i32)]
5 #[derive(Debug, Copy, Clone)]
6 pub enum AuthReq {
7     // reference to system/stack/include/gatt_api.h
8     NONE = 0,
9     EncNoMitm = 1,
10     EncMitm = 2,
11     SignedNoMitm = 3,
12     SignedMitm = 4,
13 }
14 
15 impl From<AuthReq> for i32 {
from(auth_req: AuthReq) -> Self16     fn from(auth_req: AuthReq) -> Self {
17         auth_req as i32
18     }
19 }
20 
21 /// User preferenece of GATT operations
22 pub(crate) struct GattClientContext {
23     /// If set, the registered GATT client id. None otherwise.
24     pub(crate) client_id: Option<i32>,
25     /// Type of authentication requirement
26     pub(crate) auth_req: AuthReq,
27     /// Is connection going to be directed?
28     pub(crate) is_connect_direct: bool,
29     /// Transport of connection
30     pub(crate) connect_transport: BtTransport,
31     /// Is connection going to be opportunistic?
32     pub(crate) connect_opportunistic: bool,
33     /// Type of connect phy
34     pub(crate) connect_phy: LePhy,
35 }
36 
37 impl GattClientContext {
new() -> Self38     pub(crate) fn new() -> Self {
39         GattClientContext {
40             client_id: None,
41             auth_req: AuthReq::NONE,
42             is_connect_direct: false,
43             connect_transport: BtTransport::Le,
44             connect_opportunistic: false,
45             connect_phy: LePhy::Phy1m,
46         }
47     }
48 
get_auth_req(&self) -> AuthReq49     pub(crate) fn get_auth_req(&self) -> AuthReq {
50         self.auth_req
51     }
52 }
53 
54 /// User preference of GATT server operations
55 pub(crate) struct GattServerContext {
56     /// Is connection going to be directed?
57     pub(crate) is_connect_direct: bool,
58     /// Transport of connection
59     pub(crate) connect_transport: BtTransport,
60 }
61 
62 impl GattServerContext {
new() -> Self63     pub(crate) fn new() -> Self {
64         GattServerContext { is_connect_direct: false, connect_transport: BtTransport::Le }
65     }
66 }
67