1
2
3 /*
4 * Copyright 2022 The Android Open Source Project
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 #include <gtest/gtest.h>
20
21 #include "model/controller/link_layer_controller.h"
22 #include "test_helpers.h"
23
24 namespace rootcanal {
25
26 using namespace bluetooth::hci;
27
28 class LeExtendedCreateConnectionTest : public ::testing::Test {
29 public:
30 LeExtendedCreateConnectionTest() = default;
31 ~LeExtendedCreateConnectionTest() override = default;
32
33 protected:
34 Address address_{0};
35 ControllerProperties properties_{};
36 LinkLayerController controller_{address_, properties_};
37 };
38
TEST_F(LeExtendedCreateConnectionTest,ConnectUsingPublicAddress)39 TEST_F(LeExtendedCreateConnectionTest, ConnectUsingPublicAddress) {
40 ASSERT_EQ(
41 controller_.LeExtendedCreateConnection(
42 InitiatorFilterPolicy::USE_PEER_ADDRESS,
43 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
44 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1,
45 {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010,
46 0x0c80, 0x0, 0x0)}),
47 ErrorCode::SUCCESS);
48 }
49
TEST_F(LeExtendedCreateConnectionTest,ConnectUsingRandomAddress)50 TEST_F(LeExtendedCreateConnectionTest, ConnectUsingRandomAddress) {
51 ASSERT_EQ(controller_.LeSetRandomAddress(Address{1}), ErrorCode::SUCCESS);
52 ASSERT_EQ(
53 controller_.LeExtendedCreateConnection(
54 InitiatorFilterPolicy::USE_PEER_ADDRESS,
55 OwnAddressType::RANDOM_DEVICE_ADDRESS,
56 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1,
57 {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010,
58 0x0c80, 0x0, 0x0)}),
59 ErrorCode::SUCCESS);
60 }
61
TEST_F(LeExtendedCreateConnectionTest,ConnectUsingResolvableAddress)62 TEST_F(LeExtendedCreateConnectionTest, ConnectUsingResolvableAddress) {
63 ASSERT_EQ(controller_.LeSetRandomAddress(Address{1}), ErrorCode::SUCCESS);
64 ASSERT_EQ(
65 controller_.LeExtendedCreateConnection(
66 InitiatorFilterPolicy::USE_PEER_ADDRESS,
67 OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS,
68 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1,
69 {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010,
70 0x0c80, 0x0, 0x0)}),
71 ErrorCode::SUCCESS);
72 }
73
TEST_F(LeExtendedCreateConnectionTest,InitiatingActive)74 TEST_F(LeExtendedCreateConnectionTest, InitiatingActive) {
75 ASSERT_EQ(
76 controller_.LeExtendedCreateConnection(
77 InitiatorFilterPolicy::USE_PEER_ADDRESS,
78 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
79 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1,
80 {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010,
81 0x0c80, 0x0, 0x0)}),
82 ErrorCode::SUCCESS);
83
84 ASSERT_EQ(
85 controller_.LeExtendedCreateConnection(
86 InitiatorFilterPolicy::USE_PEER_ADDRESS,
87 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
88 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1,
89 {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010,
90 0x0c80, 0x0, 0x0)}),
91 ErrorCode::COMMAND_DISALLOWED);
92 }
93
TEST_F(LeExtendedCreateConnectionTest,NoPhy)94 TEST_F(LeExtendedCreateConnectionTest, NoPhy) {
95 ASSERT_EQ(controller_.LeExtendedCreateConnection(
96 InitiatorFilterPolicy::USE_PEER_ADDRESS,
97 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
98 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS},
99 0x0, {}),
100 ErrorCode::INVALID_HCI_COMMAND_PARAMETERS);
101 }
102
TEST_F(LeExtendedCreateConnectionTest,ReservedPhy)103 TEST_F(LeExtendedCreateConnectionTest, ReservedPhy) {
104 ASSERT_EQ(
105 controller_.LeExtendedCreateConnection(
106 InitiatorFilterPolicy::USE_PEER_ADDRESS,
107 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
108 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x8,
109 {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010,
110 0x0c80, 0x0, 0x0)}),
111 ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
112 }
113
TEST_F(LeExtendedCreateConnectionTest,InvalidPhyParameters)114 TEST_F(LeExtendedCreateConnectionTest, InvalidPhyParameters) {
115 ASSERT_EQ(controller_.LeExtendedCreateConnection(
116 InitiatorFilterPolicy::USE_PEER_ADDRESS,
117 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
118 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS},
119 0x1, {}),
120 ErrorCode::INVALID_HCI_COMMAND_PARAMETERS);
121
122 ASSERT_EQ(
123 controller_.LeExtendedCreateConnection(
124 InitiatorFilterPolicy::USE_PEER_ADDRESS,
125 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
126 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1,
127 {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010,
128 0x0c80, 0x0, 0x0),
129 MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010,
130 0x0c80, 0x0, 0x0)}),
131 ErrorCode::INVALID_HCI_COMMAND_PARAMETERS);
132 }
133
TEST_F(LeExtendedCreateConnectionTest,InvalidScanInterval)134 TEST_F(LeExtendedCreateConnectionTest, InvalidScanInterval) {
135 ASSERT_EQ(
136 controller_.LeExtendedCreateConnection(
137 InitiatorFilterPolicy::USE_PEER_ADDRESS,
138 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
139 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1,
140 {MakeInitiatingPhyParameters(0x3, 0x200, 0x100, 0x200, 0x010, 0x0c80,
141 0x0, 0x0)}),
142 ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
143
144 ASSERT_EQ(
145 controller_.LeExtendedCreateConnection(
146 InitiatorFilterPolicy::USE_PEER_ADDRESS,
147 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
148 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1,
149 {MakeInitiatingPhyParameters(0x4001, 0x200, 0x100, 0x200, 0x010,
150 0x0c80, 0x0, 0x0)}),
151 ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
152 }
153
TEST_F(LeExtendedCreateConnectionTest,InvalidScanWindow)154 TEST_F(LeExtendedCreateConnectionTest, InvalidScanWindow) {
155 ASSERT_EQ(
156 controller_.LeExtendedCreateConnection(
157 InitiatorFilterPolicy::USE_PEER_ADDRESS,
158 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
159 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1,
160 {MakeInitiatingPhyParameters(0x200, 0x3, 0x100, 0x200, 0x010, 0x0c80,
161 0x0, 0x0)}),
162 ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
163
164 ASSERT_EQ(
165 controller_.LeExtendedCreateConnection(
166 InitiatorFilterPolicy::USE_PEER_ADDRESS,
167 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
168 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1,
169 {MakeInitiatingPhyParameters(0x200, 0x4001, 0x100, 0x200, 0x010,
170 0x0c80, 0x0, 0x0)}),
171 ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
172
173 ASSERT_EQ(
174 controller_.LeExtendedCreateConnection(
175 InitiatorFilterPolicy::USE_PEER_ADDRESS,
176 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
177 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1,
178 {MakeInitiatingPhyParameters(0x100, 0x200, 0x100, 0x200, 0x010,
179 0x0c80, 0x0, 0x0)}),
180 ErrorCode::INVALID_HCI_COMMAND_PARAMETERS);
181 }
182
TEST_F(LeExtendedCreateConnectionTest,InvalidConnectionInterval)183 TEST_F(LeExtendedCreateConnectionTest, InvalidConnectionInterval) {
184 ASSERT_EQ(
185 controller_.LeExtendedCreateConnection(
186 InitiatorFilterPolicy::USE_PEER_ADDRESS,
187 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
188 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1,
189 {MakeInitiatingPhyParameters(0x200, 0x200, 0x5, 0x200, 0x010, 0x0c80,
190 0x0, 0x0)}),
191 ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
192
193 ASSERT_EQ(
194 controller_.LeExtendedCreateConnection(
195 InitiatorFilterPolicy::USE_PEER_ADDRESS,
196 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
197 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1,
198 {MakeInitiatingPhyParameters(0x200, 0x200, 0x0c81, 0x200, 0x010,
199 0x0c80, 0x0, 0x0)}),
200 ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
201
202 ASSERT_EQ(
203 controller_.LeExtendedCreateConnection(
204 InitiatorFilterPolicy::USE_PEER_ADDRESS,
205 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
206 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1,
207 {MakeInitiatingPhyParameters(0x200, 0x200, 0x200, 0x5, 0x010, 0x0c80,
208 0x0, 0x0)}),
209 ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
210
211 ASSERT_EQ(
212 controller_.LeExtendedCreateConnection(
213 InitiatorFilterPolicy::USE_PEER_ADDRESS,
214 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
215 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1,
216 {MakeInitiatingPhyParameters(0x200, 0x200, 0x200, 0x0c81, 0x010,
217 0x0c80, 0x0, 0x0)}),
218 ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
219
220 ASSERT_EQ(
221 controller_.LeExtendedCreateConnection(
222 InitiatorFilterPolicy::USE_PEER_ADDRESS,
223 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
224 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1,
225 {MakeInitiatingPhyParameters(0x200, 0x200, 0x200, 0x100, 0x010,
226 0x0c80, 0x0, 0x0)}),
227 ErrorCode::INVALID_HCI_COMMAND_PARAMETERS);
228 }
229
TEST_F(LeExtendedCreateConnectionTest,InvalidMaxLatency)230 TEST_F(LeExtendedCreateConnectionTest, InvalidMaxLatency) {
231 ASSERT_EQ(
232 controller_.LeExtendedCreateConnection(
233 InitiatorFilterPolicy::USE_PEER_ADDRESS,
234 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
235 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1,
236 {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x01f4,
237 0x0c80, 0x0, 0x0)}),
238 ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
239 }
240
TEST_F(LeExtendedCreateConnectionTest,InvalidSupervisionTimeout)241 TEST_F(LeExtendedCreateConnectionTest, InvalidSupervisionTimeout) {
242 ASSERT_EQ(
243 controller_.LeExtendedCreateConnection(
244 InitiatorFilterPolicy::USE_PEER_ADDRESS,
245 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
246 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1,
247 {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010, 0x9,
248 0x0, 0x0)}),
249 ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
250
251 ASSERT_EQ(
252 controller_.LeExtendedCreateConnection(
253 InitiatorFilterPolicy::USE_PEER_ADDRESS,
254 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
255 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1,
256 {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010,
257 0x0c81, 0x0, 0x0)}),
258 ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE);
259
260 ASSERT_EQ(
261 controller_.LeExtendedCreateConnection(
262 InitiatorFilterPolicy::USE_PEER_ADDRESS,
263 OwnAddressType::PUBLIC_DEVICE_ADDRESS,
264 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1,
265 {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x1f3,
266 0x0c80, 0x0, 0x0)}),
267 ErrorCode::INVALID_HCI_COMMAND_PARAMETERS);
268 }
269
TEST_F(LeExtendedCreateConnectionTest,NoRandomAddress)270 TEST_F(LeExtendedCreateConnectionTest, NoRandomAddress) {
271 ASSERT_EQ(
272 controller_.LeExtendedCreateConnection(
273 InitiatorFilterPolicy::USE_PEER_ADDRESS,
274 OwnAddressType::RANDOM_DEVICE_ADDRESS,
275 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1,
276 {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010,
277 0x0c80, 0x0, 0x0)}),
278 ErrorCode::INVALID_HCI_COMMAND_PARAMETERS);
279
280 ASSERT_EQ(
281 controller_.LeExtendedCreateConnection(
282 InitiatorFilterPolicy::USE_PEER_ADDRESS,
283 OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS,
284 AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1,
285 {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010,
286 0x0c80, 0x0, 0x0)}),
287 ErrorCode::INVALID_HCI_COMMAND_PARAMETERS);
288 }
289
290 } // namespace rootcanal
291