1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
use enumflags2::BitFlags;
use super::interact::{address_bytes, address_callback};
use super::*;
use crate::util::BufExt2;
impl<'a> BlueZClient<'a> {
pub async fn read_local_oob_data(&mut self, controller: Controller) -> Result<OutOfBandData> {
self.exec_command(Command::ReadLocalOutOfBand, controller, None, |_, param| {
let mut param = param.unwrap();
Ok(OutOfBandData {
hash_192: param.get_u8x16(),
randomizer_192: param.get_u8x16(),
hash_256: if param.has_remaining() {
Some(param.get_u8x16())
} else {
None
},
randomizer_256: if param.has_remaining() {
Some(param.get_u8x16())
} else {
None
},
})
})
.await
}
pub async fn read_local_oob_ext_data(
&mut self,
controller: Controller,
address_types: BitFlags<AddressTypeFlag>,
) -> Result<(BitFlags<AddressTypeFlag>, Bytes)> {
self.exec_command(
Command::ReadLocalOutOfBandExtended,
controller,
Some(BytesMut::from([address_types.bits() as u8].as_ref() as &[u8]).to_bytes()),
|_, param| {
let mut param = param.unwrap();
Ok((
param.get_flags_u8(),
{
let eir_data_len = param.get_u16_le();
param.split_to(eir_data_len as usize)
},
))
},
)
.await
}
pub async fn add_remote_oob_data(
&mut self,
controller: Controller,
address: Address,
address_type: AddressType,
data: OutOfBandData,
) -> Result<(Address, AddressType)> {
let mut param = BytesMut::with_capacity(39);
param.put_slice(address.as_ref());
param.put_u8(address_type as u8);
param.put_slice(&data.hash_192[..]);
param.put_slice(&data.randomizer_192[..]);
if let Some(hash_256) = data.hash_256 {
param.put_slice(&hash_256[..]);
}
if let Some(randomizer_256) = data.randomizer_256 {
param.put_slice(&randomizer_256[..]);
}
self.exec_command(
Command::AddRemoteOutOfBand,
controller,
Some(param.to_bytes()),
address_callback,
)
.await
}
pub async fn remove_remote_oob_data(
&mut self,
controller: Controller,
address: Address,
address_type: AddressType,
) -> Result<(Address, AddressType)> {
self.exec_command(
Command::RemoveRemoteOutOfBand,
controller,
Some(address_bytes(address, address_type)),
address_callback,
)
.await
}
}
#[derive(Debug)]
pub struct OutOfBandData {
pub hash_192: [u8; 16],
pub randomizer_192: [u8; 16],
pub hash_256: Option<[u8; 16]>,
pub randomizer_256: Option<[u8; 16]>,
}